Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Add library homepage with release-driven installation and examples

Nguyen Xuan An51664cc3ce36
diff --git a/getting-started.html b/getting-started.html
new file mode 100644
index 00000000..fef6f946
--- /dev/null
+++ b/getting-started.html
@@ -0,0 +1,104 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="theme-color" content="#191d22" />
+ <meta name="description" content="Install the current 67.js release and draw a cube with Renderer67." />
+ <title>Getting started · 67.js</title>
+ </head>
+ <body>
+ <a class="skip-link" href="#content">Skip to content</a>
+ <aside class="navigation">
+ <a class="brand" href="./index.html" aria-label="67.js home">67<span>.js</span></a>
+ <p class="library-description">JavaScript 3D library</p>
+ <span class="version" data-release-version>Loading release</span>
+ <nav aria-label="Library">
+ <a href="./index.html#examples">Examples</a>
+ <a href="./getting-started.html" aria-current="page">Getting started</a>
+ <a href="./index.html#downloads">Downloads</a>
+ <a href="https://github.com/anxuanng/67.js" target="_blank" rel="noopener noreferrer">Source on GitHub <span aria-hidden="true">↗</span></a>
+ </nav>
+ <p class="navigation-note">Built with WebGL2<br />Scenes made from geometry</p>
+ </aside>
+ <main id="content" class="docs">
+ <header class="introduction"><div><h1>Draw your first scene</h1><p>Install a release, create a part and give the renderer a camera</p></div></header>
+ <section aria-labelledby="install-title">
+ <h2 id="install-title">Install the current release</h2>
+ <p>Run the command in your project directory. The package exports use the name <code>67js</code>.</p>
+ <div class="install">
+ <div class="install-label"><svg class="npm-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z"/></svg><span>Install with npm</span></div>
+ <div class="command-row"><code data-install-command>Loading the release command…</code><button data-copy-install disabled>Copy command</button></div>
+ <div class="release-feedback"><p data-release-status role="status">◷ Loading release information</p><button data-release-retry hidden>Retry</button></div>
+ </div>
+ <ol><li>Create an HTML page with the canvas below.</li><li>Save the JavaScript example as <code>main.js</code>.</li><li>Serve your project with a tool that resolves package imports, such as Vite.</li></ol>
+ <pre><code>&lt;canvas id="scene" style="width:100vw;height:100vh;display:block"&gt;&lt;/canvas&gt;
+&lt;script type="module" src="./main.js"&gt;&lt;/script&gt;</code></pre>
+ <pre><code id="cube-code">import { Renderer67, box } from '67js';
+
+const canvas = document.querySelector('#scene');
+const parts = [{
+ name: 'My first cube',
+ geometry: box(),
+ matrix: new Float32Array([
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+ ]),
+ material: {
+ tag: 'surface',
+ color: [0.2, 0.55, 0.38],
+ metallic: 0,
+ roughness: 0.55,
+ emission: 0,
+ },
+}];
+
+const renderer = new Renderer67(canvas, parts, {
+ ground: false,
+ pixelRatio: 1.25,
+ samples: 4,
+ memoryBudgetMiB: 256,
+});
+
+function draw() {
+ renderer.render({ eye: [3, 2, 4], target: [0, 0, 0] });
+}
+
+new ResizeObserver(() =&gt; {
+ renderer.resize();
+ draw();
+}).observe(canvas);
+
+draw();</code></pre>
+ <p>The page displays a green cube. You need a browser with WebGL2 support.</p>
+ </section>
+ <section aria-labelledby="browser-title">
+ <h2 id="browser-title">Import directly in your browser</h2>
+ <p>The bundled module includes its dependencies. Save this example as an HTML page and serve it over HTTP.</p>
+ <pre><code id="browser-code">The browser example appears when the current release loads.</code></pre>
+ <a class="start-link" data-release-module aria-disabled="true">Download the browser module ↓</a>
+ </section>
+ <section id="api" aria-labelledby="api-title">
+ <h2 id="api-title">Renderer67</h2>
+ <p><code>new Renderer67(canvas, parts, options)</code> uploads geometry and creates render targets.</p>
+ <p>Each part has a <code>name</code>, <code>geometry</code>, <code>matrix</code> and <code>material</code>.</p>
+ <ul class="api-list">
+ <li><code>geometry</code> contains <code>positions</code> and <code>normals</code> as <code>Float32Array</code>, and <code>indices</code> as <code>Uint32Array</code>.</li>
+ <li><code>matrix</code> is a column-major <code>Float32Array</code> with 16 values.</li>
+ <li><code>material</code> has linear RGB <code>color</code>, <code>metallic</code>, <code>roughness</code>, <code>emission</code> and a <code>tag</code>.</li>
+ </ul>
+ <p>Reuse a geometry object across parts to batch shared meshes.</p>
+ <pre><code>renderer.render({ eye: [3, 2, 4], target: [0, 0, 0] });
+renderer.resize(); // Update targets after the canvas size changes.
+renderer.dispose(); // Release GPU resources when the scene closes.</code></pre>
+ <p>Set <code>samples</code> and <code>memoryBudgetMiB</code> before creating the renderer. The target planner can reduce render dimensions to fit its estimate.</p>
+ <p>The core exports <code>box</code>, <code>cylinder</code>, <code>sphere</code> and <code>torus</code>. Scene modules use separate addon imports.</p>
+ <div class="release-links"><a data-release-api aria-disabled="true">API for this release ↗</a><a data-release-commit aria-disabled="true">Release commit</a></div>
+ </section>
+ </main>
+ <script type="module" src="/src/home.js"></script>
+ </body>
+</html>
+
diff --git a/index.html b/index.html
index ce3280ef..b1a26ef9 100644
--- a/index.html
+++ b/index.html
@@ -3,66 +3,50 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="theme-color" content="#25292d" />
- <meta name="description" content="Explore WALL·E inside and out. An explodable procedural 3D study rendered with 67.js." />
- <title>67.js · Object studio</title>
- <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='15' fill='%2325292d'/%3E%3Ctext x='7' y='45' font-family='sans-serif' font-weight='bold' font-size='38' fill='%23b7eddf'%3E67%3C/text%3E%3C/svg%3E" />
+ <meta name="theme-color" content="#191d22" />
+ <meta name="description" content="67.js is a WebGL2 library for procedural 3D scenes. Explore examples, install a release and build your first scene." />
+ <title>67.js · JavaScript 3D library</title>
</head>
<body>
- <main>
- <canvas id="viewport" tabindex="0" aria-label="3D model. Drag or use arrow keys to orbit. Scroll or use plus and minus to zoom."></canvas>
- <header class="toolbar">
- <a class="brand" href="./" aria-label="67.js home">67<span>.js</span></a>
- <nav class="studio-nav" aria-label="Scenes"><a href="./" aria-current="page">Object</a><a href="./nature.html">Nature</a><a href="./film.html">Film</a></nav>
- <div class="toolbar-actions">
- <button id="reset" title="Reset camera (R)">Reset view</button>
- <button id="export" class="primary">Export GLB <span aria-hidden="true">↗</span></button>
- </div>
+ <a class="skip-link" href="#content">Skip to content</a>
+ <aside class="navigation">
+ <a class="brand" href="./index.html" aria-label="67.js home">67<span>.js</span></a>
+ <p class="library-description">JavaScript 3D library</p>
+ <span class="version" data-release-version>Loading release</span>
+ <nav aria-label="Library">
+ <a href="#examples" aria-current="page">Examples</a>
+ <a href="./getting-started.html">Getting started</a>
+ <a href="#downloads">Downloads</a>
+ <a href="https://github.com/anxuanng/67.js" target="_blank" rel="noopener noreferrer">Source on GitHub <span aria-hidden="true">↗</span></a>
+ </nav>
+ <p class="navigation-note">Built with WebGL2<br />Scenes made from geometry</p>
+ </aside>
+ <main id="content">
+ <header class="introduction">
+ <div><h1>3D scenes, in JavaScript</h1><p>A WebGL2 renderer with procedural geometry, shared meshes and scene controls</p></div>
+ <a class="start-link" href="./getting-started.html">Build your first scene <span aria-hidden="true">↗</span></a>
</header>
- <section class="object-info" aria-labelledby="object-title">
- <h1 id="object-title">WALL·E, <br />inside out.</h1>
- <p id="model-description">Pull apart the shell. Explore the machinery. <br />Slide back to bring him together.</p>
- <div class="object-caption"><span class="status-dot" aria-hidden="true">●</span> <span id="model-name">WALL·E study</span><span class="caption-separator">/</span><span>Procedural geometry</span></div>
+ <section class="install" aria-label="Install the current release">
+ <div class="install-label"><svg class="npm-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z"/></svg><span>Install with npm</span></div>
+ <div class="command-row"><code data-install-command>Loading the release command…</code><button data-copy-install disabled>Copy command</button></div>
+ <div class="release-feedback"><p data-release-status role="status">◷ Loading release information</p><button data-release-retry hidden>Retry</button></div>
</section>
- <aside class="controls" aria-label="Model appearance">
- <div class="assembly-control">
- <label for="assembly">Explode model <output id="assembly-value">0%</output></label>
- <input id="assembly" type="range" min="0" max="100" step="1" value="0" aria-valuetext="Assembled" />
- <div class="assembly-endpoints"><span>Assembled</span><span>Exploded</span></div>
- <div class="layer-actions" role="group" aria-label="Model layers"><button data-layer="all" aria-pressed="true">All</button><button data-layer="exterior" aria-pressed="false">Shell</button><button data-layer="interior" aria-pressed="false">Inside</button></div>
- </div>
- <fieldset>
- <legend>Finish</legend>
- <div class="finishes">
- <button class="swatch selected" data-finish="yellow" aria-label="Yellow finish" aria-pressed="true" style="--swatch:#d8a33c"></button>
- <button class="swatch" data-finish="ceramic" aria-label="Ceramic finish" aria-pressed="false" style="--swatch:#d7e0de"></button>
- <button class="swatch" data-finish="graphite" aria-label="Graphite finish" aria-pressed="false" style="--swatch:#59666e"></button>
- </div>
- <span id="finish-name">Factory yellow</span>
- </fieldset>
- <label class="exposure-label" for="exposure">Exposure <output id="exposure-value">1.0</output></label>
- <input id="exposure" type="range" min="0.5" max="1.8" step="0.1" value="1" />
- <div class="view-actions">
- <button id="rotate" aria-pressed="false">↻ Auto orbit</button>
- <button id="inspect" aria-pressed="false">Surface normals</button>
+ <section id="examples" class="examples" aria-labelledby="examples-title">
+ <h2 id="examples-title">Examples</h2>
+ <div class="gallery">
+ <a class="example" href="./object.html"><img src="./previews/wall-e.png" alt="WALL·E model rendered in 67.js" width="1280" height="720" fetchpriority="high" /><div class="example-caption"><h3>WALL·E</h3><span>Object studio <span aria-hidden="true">↗</span></span></div><p>Explore the model, change its finish and export the geometry</p></a>
+ <a class="example" href="./nature.html"><img src="./previews/nature.png" alt="A winding stream through Silverwater valley" width="1280" height="720" /><div class="example-caption"><h3>Silverwater valley</h3><span>Nature <span aria-hidden="true">↗</span></span></div><p>Move through the landscape and change the light and wind</p></a>
+ <a class="example" href="./film.html"><img src="./previews/film-contact.png" alt="Scenes from CRITICAL, a procedural 3D short film" width="1280" height="720" loading="lazy" /><div class="example-caption"><h3>CRITICAL</h3><span>Short film <span aria-hidden="true">↗</span></span></div><p>Watch a deterministic film with an original synthesized score</p></a>
+ <a class="example" href="./object.html?explosion=1"><img src="./previews/wall-e-exploded.png" alt="WALL·E assemblies separated to reveal the internal mechanisms" width="1280" height="720" loading="lazy" /><div class="example-caption"><h3>Inside the machine</h3><span>Exploded assembly <span aria-hidden="true">↗</span></span></div><p>Separate the assemblies to inspect the electronics and mechanisms</p></a>
</div>
- <label class="quality-label" for="quality">Resolution
- <select id="quality"><option value="1">Performance</option><option value="1.5" selected>Balanced</option><option value="2">High</option></select>
- </label>
- </aside>
- <footer>
- <p class="hint">Drag to orbit <span>·</span> Scroll to zoom</p>
- <div class="metrics" aria-label="Renderer statistics"><span id="parts">Loading geometry…</span><span id="calls"></span><span id="cpu"></span></div>
- <button id="benchmark">Measure performance ↗</button>
- </footer>
- <section id="benchmark-result" class="benchmark-result" hidden aria-label="Performance results">
- <h2>CPU draw submission</h2>
- <p id="benchmark-summary" role="status"></p>
- <p class="benchmark-note">Same geometry, camera, resolution and flat shader. Median of 120 samples, 8 submissions per sample. GPU time and visual quality are separate measurements.</p>
- <button id="dismiss-benchmark">Back to model</button>
</section>
- <p id="notice" class="notice" role="status" hidden></p>
+ <section id="downloads" class="downloads" aria-labelledby="downloads-title">
+ <div class="section-heading"><h2 id="downloads-title">Downloads</h2><span data-release-version>Loading release</span></div>
+ <p>Use the package archive with npm, or import the bundled module directly in your browser</p>
+ <div class="download-links"><a class="download" data-release-tarball aria-disabled="true"><strong>Package archive</strong><span>Install with npm <span aria-hidden="true">↓</span></span></a><a class="download" data-release-module aria-disabled="true"><strong>Browser module</strong><span>Bundled ES module <span aria-hidden="true">↓</span></span></a></div>
+ <div class="release-links"><a href="https://github.com/anxuanng/67.js/blob/main/CHANGELOG.md" target="_blank" rel="noopener noreferrer">Changelog ↗</a><a data-release-commit aria-disabled="true">Release commit</a><a data-release-api aria-disabled="true">API reference ↗</a></div>
+ </section>
</main>
- <script type="module" src="/src/main.js"></script>
+ <script type="module" src="/src/home.js"></script>
</body>
</html>
diff --git a/src/home.css b/src/home.css
new file mode 100644
index 00000000..0fd4bfd1
--- /dev/null
+++ b/src/home.css
@@ -0,0 +1,91 @@
+:root { font-family: system-ui, sans-serif; color: #edf0f2; background: #20252b; font-synthesis: none; color-scheme: dark; }
+* { box-sizing: border-box; }
+html { scroll-behavior: smooth; }
+body { margin: 0; }
+a { color: inherit; text-decoration: none; }
+button { font: inherit; border: 0; color: inherit; cursor: pointer; border-radius: 6px; background: #354047; padding: 10px 14px; }
+button:hover { background: #45515a; }
+button:disabled { cursor: default; opacity: .5; }
+a[aria-disabled='true'] { opacity: .5; pointer-events: none; }
+:focus-visible { outline: 2px solid #a9d7c7; outline-offset: 4px; }
+.skip-link { position: fixed; left: 16px; top: 12px; padding: 12px; z-index: 10; background: #edf0f2; color: #191d22; transform: translateY(-160%); }
+.skip-link:focus { transform: none; }
+.navigation { position: fixed; inset: 0 auto 0 0; width: 218px; padding: 36px 26px; background: #191d22; display: flex; flex-direction: column; align-items: flex-start; }
+.brand { font-size: 37px; font-weight: 650; letter-spacing: -2px; line-height: 1; }
+.brand span { font-weight: 400; color: #b7c1c8; }
+.library-description { margin: 13px 0 17px; font-size: 13px; color: #b8c1c7; }
+.version { font-family: ui-monospace, monospace; font-size: 12px; color: #a9d7c7; }
+nav { display: flex; flex-direction: column; gap: 7px; width: 100%; margin-top: 40px; }
+nav a { font-size: 14px; padding: 11px 12px; margin-left: -12px; border-radius: 6px; }
+nav a:hover, nav a[aria-current] { background: #edf0f20a; }
+nav a[aria-current] { color: #b8e6d2; }
+.navigation-note { margin: auto 0 0; font-size: 12px; line-height: 1.8; color: #a3aeb7; }
+main { max-width: 1500px; margin-left: 218px; padding: 42px 44px 60px; }
+h1, h2, h3, p { margin-top: 0; }
+h1 { font-size: clamp(28px, 3vw, 38px); line-height: 1.2; font-weight: 550; letter-spacing: -1.2px; margin-bottom: 14px; }
+h2 { font-size: 21px; font-weight: 550; letter-spacing: -.5px; margin-bottom: 24px; }
+h3 { font-size: 17px; font-weight: 550; margin: 0; }
+p { line-height: 1.6; color: #b9c4cc; font-size: 14px; }
+.introduction { display: flex; align-items: center; gap: 28px; justify-content: space-between; margin-bottom: 30px; }
+.introduction p { max-width: 570px; margin-bottom: 0; }
+.start-link { white-space: nowrap; font-size: 14px; color: #b8e6d2; }
+.start-link:hover, .release-links a:hover { text-decoration: underline; }
+.install { margin-bottom: 43px; }
+.install-label { display: flex; gap: 9px; align-items: center; font-size: 13px; margin-bottom: 10px; }
+.npm-icon { width: 19px; height: 19px; fill: #dc6262; }
+.command-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 14px 12px 18px; background: #151a1e; border-radius: 8px; }
+code, pre { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
+.command-row code { color: #c5e2d4; font-size: 13px; overflow-wrap: anywhere; line-height: 1.65; }
+.command-row button { flex-shrink: 0; font-size: 12px; }
+.release-feedback { display: flex; gap: 12px; align-items: center; margin-top: 9px; }
+.release-feedback p { margin: 0; font-size: 12px; color: #aebbb6; }
+.release-feedback button { font-size: 12px; padding: 5px 10px; }
+[data-release-status][data-status='error'] { color: #f0b995; }
+.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 33px 26px; }
+.example { display: block; min-width: 0; }
+.example img { width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; background: #171c20; display: block; border-radius: 8px; }
+.example:hover img { filter: brightness(1.06); }
+.example-caption { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 16px 0 7px; }
+.example-caption > span { color: #a9b6c0; font-size: 12px; }
+.example p { font-size: 13px; margin-bottom: 0; }
+.downloads { margin-top: 54px; scroll-margin-top: 30px; }
+.section-heading { display: flex; gap: 16px; align-items: center; }
+.section-heading h2 { margin-bottom: 12px; }
+.section-heading > span { font-size: 12px; color: #a9d7c7; font-family: ui-monospace, monospace; margin-bottom: 12px; }
+.download-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 23px 0; }
+.download { padding: 22px; background: #293139; border-radius: 8px; display: flex; flex-direction: column; gap: 9px; }
+.download:hover { background: #313c43; }
+.download strong { font-size: 15px; font-weight: 550; }
+.download > span { font-size: 13px; color: #bbc7cf; }
+.release-links { display: flex; flex-wrap: wrap; gap: 22px; font-size: 13px; color: #b8e6d2; }
+.docs section { margin-top: 36px; }
+.docs { max-width: 1120px; }
+.docs h2 { margin-bottom: 14px; }
+.docs ol { padding-left: 22px; color: #b9c4cc; font-size: 14px; line-height: 1.9; }
+.docs pre { overflow-x: auto; background: #151a1e; border-radius: 8px; padding: 24px; font-size: 13px; line-height: 1.7; color: #c5e2d4; }
+.docs pre code { color: inherit; }
+.docs .install { margin-top: 24px; margin-bottom: 30px; }
+@media (max-width: 1100px) { main { padding: 34px 30px 50px; } .introduction { align-items: flex-start; flex-direction: column; gap: 18px; } }
+@media (max-width: 760px) {
+ .navigation { position: static; width: auto; padding: 23px 22px 18px; display: grid; grid-template-columns: 1fr auto; gap: 12px; }
+ .brand { font-size: 30px; }
+ .library-description, .navigation-note { display: none; }
+ .version { align-self: center; }
+ nav { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 4px 15px; margin-top: 5px; }
+ nav a { padding: 8px 0; margin-left: 0; font-size: 13px; }
+ nav a[aria-current] { background: transparent; }
+ main { margin-left: 0; padding: 30px 22px 44px; }
+ h1 { font-size: 29px; }
+ .introduction { margin-bottom: 26px; }
+ .gallery { grid-template-columns: 1fr; gap: 28px; }
+ .command-row { align-items: flex-start; padding: 15px; flex-direction: column; gap: 12px; }
+ .command-row button { align-self: flex-end; }
+ .example-caption { margin-top: 13px; }
+ .download-links { grid-template-columns: 1fr; gap: 12px; }
+ .docs pre { font-size: 12px; padding: 18px; }
+}
+@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
+[hidden] { display: none !important; }
+.api-list { padding-left: 22px; color: #b9c4cc; font-size: 14px; line-height: 1.9; }
+.api-list li { margin-bottom: 9px; }
+.docs p code, .docs li code { color: #c5e2d4; }
diff --git a/src/home.js b/src/home.js
new file mode 100644
index 00000000..ae894be3
--- /dev/null
+++ b/src/home.js
@@ -0,0 +1,112 @@
+import './home.css';
+
+const state = { status: 'loading', release: null };
+
+function setText(selector, text) {
+ document.querySelectorAll(selector).forEach(element => { element.textContent = text; });
+}
+
+function releaseURL(value) {
+ const url = new URL(value, location.href);
+ if (url.origin !== location.origin || !['https:', 'http:'].includes(url.protocol)) {
+ throw new Error('Release files must use the current site.');
+ }
+ return url.href;
+}
+
+function validateRelease(release) {
+ for (const key of ['version', 'packageName', 'commit', 'installCommand', 'tarball', 'module', 'api']) {
+ if (typeof release[key] !== 'string' || !release[key].trim()) throw new Error(`Missing release field: ${key}`);
+ }
+ if (typeof release.registryPublished !== 'boolean') throw new Error('Missing publication status.');
+ if (!/^[a-f0-9]{7,40}$/i.test(release.commit)) throw new Error('Invalid release commit.');
+ releaseURL(release.tarball);
+ releaseURL(release.module);
+ releaseURL(release.api);
+ return release;
+}
+
+function setLink(selector, url, download = false) {
+ document.querySelectorAll(selector).forEach(link => {
+ if (url) {
+ link.href = url;
+ link.removeAttribute('aria-disabled');
+ if (download) link.setAttribute('download', '');
+ } else {
+ link.removeAttribute('href');
+ link.setAttribute('aria-disabled', 'true');
+ }
+ });
+}
+
+function renderRelease() {
+ const release = state.release;
+ document.querySelectorAll('[data-copy-install]').forEach(button => { button.disabled = !release; });
+ document.querySelectorAll('[data-release-retry]').forEach(button => { button.hidden = state.status !== 'error'; });
+ document.querySelectorAll('[data-release-status]').forEach(element => { element.dataset.status = state.status; });
+ setText('[data-release-version]', release ? `v${release.version}` : state.status === 'error' ? 'Release unavailable' : 'Loading release');
+ setText('[data-install-command]', release ? release.installCommand : state.status === 'error' ? 'Release information is unavailable' : 'Loading the release command…');
+ setText('[data-release-status]', release
+ ? release.registryPublished ? '✓ Install the current published release' : '✓ Install this release from the package archive'
+ : state.status === 'error' ? '⚠ Release information could not load. Retry to get the current files' : '◷ Loading release information');
+ setLink('[data-release-tarball]', release ? releaseURL(release.tarball) : null, true);
+ setLink('[data-release-module]', release ? releaseURL(release.module) : null, true);
+ setLink('[data-release-api]', release ? releaseURL(release.api) : null);
+ setLink('[data-release-commit]', release ? `https://github.com/anxuanng/67.js/commit/${release.commit}` : null);
+ setText('[data-release-commit]', release ? `Commit ${release.commit.slice(0, 7)} ↗` : 'Release commit');
+ if (release && document.querySelector('#browser-code')) {
+ const cubeCode = document.querySelector('#cube-code').textContent.replace("from '67js'", `from '${releaseURL(release.module)}'`);
+ document.querySelector('#browser-code').textContent = `<canvas id="scene" style="width:100vw;height:100vh;display:block"></canvas>\n<script type="module">\n${cubeCode}\n</script>`;
+ } else if (document.querySelector('#browser-code')) {
+ document.querySelector('#browser-code').textContent = state.status === 'error'
+ ? 'Release information is unavailable. Use Retry above to load the browser example.'
+ : 'The browser example appears when the current release loads.';
+ }
+}
+
+async function loadRelease() {
+ state.status = 'loading';
+ state.release = null;
+ renderRelease();
+ try {
+ const response = await fetch('./release.json', { cache: 'no-store', headers: { Accept: 'application/json' } });
+ if (!response.ok) throw new Error(`Release endpoint returned ${response.status}.`);
+ state.release = validateRelease(await response.json());
+ state.status = 'ready';
+ } catch {
+ state.status = 'error';
+ }
+ renderRelease();
+}
+
+function selectCommand() {
+ const element = document.querySelector('[data-install-command]');
+ const range = document.createRange();
+ range.selectNodeContents(element);
+ const selection = getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+}
+
+document.querySelectorAll('[data-copy-install]').forEach(button => {
+ button.addEventListener('click', async () => {
+ if (!state.release) return;
+ try {
+ await navigator.clipboard.writeText(state.release.installCommand);
+ setText('[data-release-status]', '✓ Install command copied');
+ } catch {
+ selectCommand();
+ setText('[data-release-status]', '⚠ Clipboard unavailable. Copy the selected command');
+ }
+ });
+});
+document.querySelectorAll('[data-release-retry]').forEach(button => button.addEventListener('click', loadRelease));
+document.querySelectorAll('.example img').forEach(image => {
+ image.addEventListener('error', () => {
+ image.alt = `${image.alt}. Preview unavailable. Open the example to explore it`;
+ }, { once: true });
+});
+window.__home = { state, loadRelease };
+loadRelease();
+window.addEventListener('pageshow', event => { if (event.persisted) loadRelease(); });
+