3D engine that AI agents drive
Organize documentation and unify package installation
Nguyen Xuan Anc63c538e84d8
diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.mdindex 8ada2a5f..395df693 100644--- a/THIRD-PARTY-NOTICES.md+++ b/THIRD-PARTY-NOTICES.md@@ -19,3 +19,35 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.++## highlight.js 11.12.0 (website syntax highlighting)++BSD 3-Clause License++Copyright (c) 2006, Ivan Sagalaev.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++* Neither the name of the copyright holder nor the names of its+ contributors may be used to endorse or promote products derived from+ this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.diff --git a/docs.html b/docs.htmlindex 1b2fdb71..781fde9c 100644--- a/docs.html+++ b/docs.html@@ -1,9 +1,28 @@<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta name="description" content="67.js documentation: scenes, materials, cameras, animation, GLB assets, CPU/GPU media export and AI agent workflows."/><title>Documentation · 67.js</title><link rel="icon" href="/favicon.svg"/></head>-<body>+<body class="documentation"><a class="skip-link" href="#content">Skip to content</a>-<aside class="navigation"><a class="brand" href="/">67<span>.js</span></a><p class="library-description">By CodePawl</p><span class="version" data-release-version>Loading release</span><nav aria-label="Library"><a href="/">Showcase</a><a href="/docs.html" aria-current="page">Documentation</a><a href="/#downloads">Downloads</a></nav><p class="navigation-note"><a href="https://codepawl.com">A CodePawl project ↗</a></p></aside>-<main id="content" class="docs docs-page"><header><h1>Build with 67.js</h1><p>From your first part to an interactive scene and a finished film.</p></header><label class="docs-search" for="doc-search">Find a topic <input id="doc-search" type="search" placeholder="Materials, memory, agents…" autocomplete="off"/></label><p id="doc-results" role="status"></p><div class="docs-layout"><nav id="doc-toc" aria-label="Documentation topics"></nav><article id="doc-article"></article></div><p class="release-links"><a href="/guide.md" data-icon="book">Download plain-text guide</a></p><noscript><p>Read the <a href="/guide.md">complete plain-text guide</a> with JavaScript disabled.</p></noscript></main>+<aside class="navigation">+ <a class="brand" href="/">67<span>.js</span></a>+ <p class="library-description">By CodePawl</p>+ <span class="version" data-release-version>Loading release</span>+ <nav aria-label="Library"><a href="/">Showcase</a><a href="/docs.html" aria-current="page">Documentation</a><a href="/#downloads">Downloads</a></nav>+ <p class="navigation-note"><a href="https://codepawl.com">A CodePawl project ↗</a></p>+</aside>+<main id="content" class="docs docs-page">+ <aside class="docs-sidebar" aria-label="Documentation navigation">+ <a class="docs-title" href="#install">Documentation</a>+ <label class="docs-search" for="doc-search"><span>Search documentation</span><input id="doc-search" type="search" placeholder="Search topics and code…" autocomplete="off"/></label>+ <p id="doc-results" role="status" aria-live="polite"></p>+ <details id="doc-topic-menu"><summary>Topics <span id="doc-topic-name">Install</span><span aria-hidden="true">⌄</span></summary><nav id="doc-toc" aria-label="Documentation topics"></nav></details>+ </aside>+ <div class="docs-reading">+ <div class="doc-actions"><button id="copy-doc-page" type="button" title="Copy this article as Markdown">Copy page</button></div>+ <p id="doc-copy-status" class="doc-copy-status" role="status" aria-live="polite"></p>+ <article id="doc-article" tabindex="-1" aria-label="Documentation article"></article>+ <noscript><p>Read the <a href="/guide.md">complete plain-text guide</a> with JavaScript disabled.</p></noscript>+ </div>+</main><script type="module" src="/src/documentation.js"></script></body></html>diff --git a/docs/guide.md b/docs/guide.mdindex f97c2cf3..17619ed7 100644--- a/docs/guide.md+++ b/docs/guide.md@@ -68,7 +68,7 @@ window.addEventListener('pagehide', () => {The page displays a rounded green cube in a WebGL2 browser. The observer redraws when its canvas changes size.For a browser import without npm, use the exact `module` URL from [release metadata](/release.json) instead of `67js`.-The bundled ES module includes its dependencies. Serve the HTML over HTTP. The homepage Downloads section provides the module file.+The bundled ES module includes its dependencies. Serve the HTML over HTTP. Release metadata provides its URL for browser-only imports.## Parts and geometrydiff --git a/index.html b/index.htmlindex 67b696d9..c26b7125 100644--- a/index.html+++ b/index.html@@ -11,14 +11,13 @@<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>+ <a class="brand" href="/" aria-label="67.js home">67<span>.js</span></a><p class="library-description">Graphics toolkit by CodePawl</p><span class="version" data-release-version>Loading release</span><nav aria-label="Library">- <a href="#examples" aria-current="page">Examples</a>+ <a href="/#examples" aria-current="page">Showcase</a><a href="./docs.html">Documentation</a>- <a href="#downloads">Downloads</a>- <a data-release-tarball aria-disabled="true">Package source</a>+ <a href="/#downloads">Downloads</a></nav><p class="navigation-note"><a href="https://codepawl.com">A CodePawl project ↗</a></p></aside>@@ -26,27 +25,31 @@<header class="introduction"><div><h1>Your 3D scene,<br />from browser to film</h1><p>67.js brings browser 3D, animation and image/video export into one workflow. Create interactive experiences and export the same scene as images or video</p><div class="hero-actions"><a href="./object.html" data-icon="cube">Try the object studio</a><a href="./docs.html#install" data-icon="code">Build your first scene</a></div></div></header><section class="feature-showcase" aria-label="67.js rendered animation showcase"><video controls playsinline preload="none" poster="./previews/motion.webp" width="960" height="540"><source src="./media/clockwork.mp4" type="video/mp4"/><p>Your browser cannot play this film. <a href="./motion.html">Open the interactive scene</a>.</p></video><div class="showcase-caption"><div><h2>Clockwork orbit</h2><p>A real 67.js render. Open the scene to scrub time and change the frame.</p></div><a href="./motion.html" data-icon="film">Explore the scene</a></div></section><section class="workflow" aria-label="What you can build"><div><span data-icon="cube"></span><h3>Build and inspect</h3><p>Shared meshes, materials and cameras. Pull a machine apart, explore a world, or bring your own GLB.</p></div><div><span data-icon="film"></span><h3>Make it move</h3><p>Sample keyframes at any time. Give visitors controls and keep the same timeline for your film.</p></div><div><span data-icon="image"></span><h3>Export the result</h3><p>Produce images and videos on GPU or CPU with explicit render budgets and one capture frame at a time.</p></div></section>- <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><section id="examples" class="examples" aria-labelledby="examples-title">- <h2 id="examples-title">Try it yourself</h2><p>Each showcase is a working scene with controls you can explore.</p>+ <h2 id="examples-title">Interactive showcase</h2><p>Explore a machine, a world, a film or your own model</p><div class="gallery">- <a class="example" href="./object.html"><img src="./previews/wall-e.webp" 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>Separate 574 parts, inspect the shell and machinery, and save your composition</p></a>+ <a class="example" href="./object.html"><img src="./previews/wall-e.webp" 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 exterior or separate 574 parts to inspect the machinery</p></a><a class="example" href="./nature.html"><img src="./previews/nature.webp" 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.webp" 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.webp" 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>- <a class="example" href="./motion.html"><img src="./previews/motion.webp" alt="A luminous clockwork mechanism animated from keyframes" width="960" height="540" loading="lazy" /><div class="example-caption"><h3>Clockwork orbit</h3><span>Animation <span aria-hidden="true">↗</span></span></div><p>Scrub keyframes, switch compositions and render a short film</p></a><a class="example" href="./view2d.html"><img src="./previews/view2d.webp" alt="A flat orbital poster rendered through an orthographic camera" width="960" height="540" loading="lazy" /><div class="example-caption"><h3>Orbital field</h3><span>2D and views <span aria-hidden="true">↗</span></span></div><p>Pan a vector scene or inspect a model from front, right and top</p></a><a class="example" href="./assets.html"><img src="./previews/assets.webp" alt="An imported geometric study displayed in the asset viewer" width="960" height="540" loading="lazy" /><div class="example-caption"><h3>Your models</h3><span>GLB assets <span aria-hidden="true">↗</span></span></div><p>Open a GLB, inspect its materials and sample node animation</p></a></div></section><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><span class="download-symbol" data-icon="download" aria-hidden="true"></span></a><a class="download" data-release-module aria-disabled="true"><strong>Browser module</strong><span>Bundled ES module</span><span class="download-symbol" data-icon="download" aria-hidden="true"></span></a></div>+ <p>Choose your package manager and install the current release</p>+ <div class="package-install">+ <div class="package-managers" role="group" aria-label="Package manager">+ <button data-package-manager="npm" aria-pressed="true">npm</button>+ <button data-package-manager="pnpm" aria-pressed="false">pnpm</button>+ <button data-package-manager="yarn" aria-pressed="false">Yarn</button>+ <button data-package-manager="bun" aria-pressed="false">Bun</button>+ </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>+ <p class="package-note">The alias keeps imports short: <code>import { Renderer67 } from '67js'</code></p>+ <div class="package-links"><a href="https://www.npmjs.com/package/@codepawlhq/67js" data-icon="package">View on npm</a><a href="https://github.com/anxuanng/67.js" data-icon="github">Source on GitHub</a><a href="/docs.html#getting-started" data-icon="book">Build your first scene</a></div>+ </div><div class="release-links"><a href="./docs.html">Documentation</a><a href="./logo.svg" download>Logo SVG</a><a href="./changelog.md">Changelog</a><span data-release-commit>Release commit</span><a data-release-api aria-disabled="true">API reference ↗</a></div></section></main>diff --git a/package-lock.json b/package-lock.jsonindex f933cccb..6ce249bf 100644--- a/package-lock.json+++ b/package-lock.json@@ -10,6 +10,7 @@"license": "MIT","devDependencies": {"gl-matrix": "3.4.4",+ "highlight.js": "11.12.0","playwright": "1.64.0","three": "0.186.1","vite": "8.3.4",@@ -1658,6 +1659,16 @@"dev": true,"license": "MIT"},+ "node_modules/highlight.js": {+ "version": "11.12.0",+ "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.12.0.tgz",+ "integrity": "sha512-nbfWpyRMcMrPMmDwJB+dhX/eiaPKtc2RB+0QZskqJ3WjRA/FDS0e9hZrx8EC/lbEv8gXy98FcDbNa/dspAaJMg==",+ "dev": true,+ "license": "BSD-3-Clause",+ "engines": {+ "node": ">=12.0.0"+ }+ },"node_modules/kleur": {"version": "4.1.5","resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz",diff --git a/package.json b/package.jsonindex 7b4821b0..1662d25d 100644--- a/package.json+++ b/package.json@@ -56,6 +56,7 @@},"devDependencies": {"gl-matrix": "3.4.4",+ "highlight.js": "11.12.0","playwright": "1.64.0","three": "0.186.1","vite": "8.3.4",diff --git a/public/licenses/highlight-js.txt b/public/licenses/highlight-js.txtnew file mode 100644index 00000000..2250cc7e--- /dev/null+++ b/public/licenses/highlight-js.txt@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2006, Ivan Sagalaev.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++* Neither the name of the copyright holder nor the names of its+ contributors may be used to endorse or promote products derived from+ this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.diff --git a/scripts/smoke-navigation.mjs b/scripts/smoke-navigation.mjsindex 33b6e077..e2698ec6 100644--- a/scripts/smoke-navigation.mjs+++ b/scripts/smoke-navigation.mjs@@ -16,7 +16,7 @@ try {await page.goto(origin + route);for (const width of [320, 390, 580, 1440]) {await page.setViewportSize({ width, height: 1000 });- const contrast = await page.locator('nav a[aria-current]').evaluate(link => {+ const contrast = await page.locator('.navigation nav a[aria-current]').evaluate(link => {const channels = color => color.match(/[\d.]+/g).map(Number);const backgrounds = [];for (let element = link; element; element = element.parentElement) {diff --git a/scripts/smoke-site.mjs b/scripts/smoke-site.mjsindex 51ed6d23..2a0f3914 100644--- a/scripts/smoke-site.mjs+++ b/scripts/smoke-site.mjs@@ -10,6 +10,12 @@ const errors = [];const report = { layouts: [], interactions: [] };try {const page = await browser.newPage({ viewport:{ width:1440,height:1000 }, colorScheme:'dark', reducedMotion:'reduce' });+ await page.addInitScript(() => {+ window.__copiedText = '';+ Object.defineProperty(navigator, 'clipboard', {+ value: { writeText: async text => { window.__copiedText = text; } },+ });+ });page.on('pageerror', error => errors.push(error.message));for (const route of ['/', '/docs.html', '/getting-started.html', '/object.html', '/motion.html', '/nature.html', '/assets.html', '/view2d.html', '/film.html']) {await page.goto(origin + route);@@ -46,31 +52,50 @@ try {assert.equal(await page.locator('.navigation a[href*="getting-started.html"]').count(), 0, 'Getting started still has separate navigation');}if (route === '/') {- assert.equal(await page.locator('.download .icon').count(), 2);- assert.ok(!(await page.locator('.download-links').textContent()).includes('↓'));+ assert.equal(await page.locator('[data-package-manager]').count(), 4);+ assert.equal(await page.locator('[data-release-tarball], [data-release-module]').count(), 0);+ const scenePaths = await page.locator('.gallery .example').evaluateAll(links => links.map(link => new URL(link.href).pathname));+ assert.equal(new Set(scenePaths).size, scenePaths.length, 'Showcase repeats the same scene');+ await page.locator('.navigation a[href="/#downloads"]').click();+ await page.waitForFunction(() => document.querySelector('.navigation a[aria-current]')?.getAttribute('href') === '/#downloads');+ for (const [manager, prefix] of [['npm', 'npm install'], ['pnpm', 'pnpm add'], ['yarn', 'yarn add'], ['bun', 'bun add']]) {+ await page.locator(`[data-package-manager="${manager}"]`).click();+ const expectedCommand = await page.evaluate(prefix => window.__home.state.release.installCommand.replace(/^npm install/, prefix), prefix);+ assert.equal(await page.locator('[data-install-command]').textContent(), expectedCommand);+ assert.equal(await page.locator(`[data-package-manager="${manager}"]`).getAttribute('aria-pressed'), 'true');+ await page.locator('[data-copy-install]').click();+ assert.equal(await page.evaluate(() => window.__copiedText), expectedCommand);+ }+ report.interactions.push('Unified package managers, unique showcase scenes and synchronized Downloads navigation');}if (route === '/getting-started.html') {- assert.match(page.url(), /\/docs\.html#install$/);+ assert.match(page.url(), /\/docs(?:\.html)?#install$/);}if (route === '/docs.html') {- assert.ok(await page.locator('#doc-article section').count() >= 10);- const installGeometry = await page.locator('#install pre').evaluate(block => {- const code = block.querySelector('code').getBoundingClientRect();- const button = block.querySelector('button').getBoundingClientRect();- return { height: block.getBoundingClientRect().height, topDifference: Math.abs(code.top - button.top) };- });- assert.ok(installGeometry.height < 80, 'Install block has excess blank space');- assert.ok(installGeometry.topDifference < 8, 'Copy button is not beside code');- assert.equal(await page.locator('#getting-started ol li').count(), 3);+ assert.ok(await page.locator('#doc-toc a[href^="#"]').count() >= 15);+ assert.equal(await page.locator('#doc-article section:visible').count(), 1);await page.locator('#doc-search').fill('memory');- assert.ok(await page.locator('#doc-article section:visible').count() > 0);+ assert.ok(await page.locator('#doc-toc a:visible').count() > 0);+ await page.locator('#doc-toc a[href="#performance-and-memory"]').click();+ assert.match(await page.locator('#doc-article').textContent(), /Performance and memory/);await page.locator('#doc-search').fill('no-such-topic-1234');- await assert.equal(await page.locator('#doc-article section:visible').count(),0);- assert.match(await page.locator('#doc-results').textContent(),/No matching/);+ assert.equal(await page.locator('#doc-toc a:visible').count(), 0);+ assert.match(await page.locator('#doc-results').textContent(), /No .*match/i);await page.locator('#doc-search').fill('');await page.locator('#doc-toc a[href="#models-and-ai-agents"]').click();assert.match(page.url(),/models-and-ai-agents/);- report.interactions.push('Docs search, empty state and topic links');+ await page.locator('#doc-toc a[href="#getting-started"]').click();+ assert.equal(await page.locator('#getting-started ol li').count(), 3);+ assert.ok(await page.locator('.hljs-keyword').count() > 0);+ assert.ok(await page.locator('.code-block').count() >= 2);+ assert.equal(await page.locator('#copy-doc-page').count(), 1);+ await page.locator('#copy-doc-page').click();+ assert.match(await page.evaluate(() => window.__copiedText), /^## Getting started/);+ assert.ok(!(await page.evaluate(() => window.__copiedText)).includes('## Parts and geometry'));+ const firstCode = page.locator('.code-block').first();+ await firstCode.locator('.copy-code').click();+ assert.equal(await page.evaluate(() => window.__copiedText), await firstCode.locator('code').textContent());+ report.interactions.push('Grouped docs, selected articles, search, deep links and labeled syntax highlighting');}if (route === '/object.html') {await page.locator('[data-view="face"]').click();diff --git a/src/brand.js b/src/brand.jsindex 96ebcca1..0e3aa1ee 100644--- a/src/brand.js+++ b/src/brand.js@@ -18,6 +18,8 @@ const paths = {film:'M3 4h18v16H3V4Zm4 0v16M17 4v16M3 9h4m-4 6h4m10-6h4m-4 6h4',leaf:'M20 3C8 2 2 8 5 15s15 6 15-12ZM4 21 15 10',image:'M3 3h18v18H3V3Zm0 14 6-6 5 5 3-3 4 4M16 8h.01',+ package:'M3 7 12 2l9 5v10l-9 5-9-5V7Zm0 0 9 5 9-5M12 12v10M7.5 4.5l9 5v4',+ github:'M9 19c-4 1-4-2-6-2m12 5v-4a3.5 3.5 0 0 0-1-2.7c3.3-.4 6.7-1.6 6.7-7.3a5.7 5.7 0 0 0-1.5-4 5.3 5.3 0 0 0-.1-4S18 0 15 2a14 14 0 0 0-7 0C5 0 3.9 0 3.9 0a5.3 5.3 0 0 0-.1 4 5.7 5.7 0 0 0-1.5 4c0 5.7 3.4 6.9 6.7 7.3A3.5 3.5 0 0 0 8 18v4',};const labels = { Examples:'cube', Showcase:'cube', Documentation:'book', 'Getting started':'book', Downloads:'download', 'Package source':'code', Object:'cube', Nature:'leaf', Film:'film', Animation:'film', 'Save PNG':'image', 'Export GLB':'download' };for (const element of document.querySelectorAll('nav a, [data-icon], #save-image, #export')) {diff --git a/src/documentation.css b/src/documentation.cssnew file mode 100644index 00000000..ab0105fe--- /dev/null+++ b/src/documentation.css@@ -0,0 +1,81 @@+.documentation { --syntax-string:#9dd1b6; --syntax-keyword:#c8b1ed; --syntax-number:#e8bd88; --syntax-comment:#a0a0a0; --syntax-name:#acc7ed; }+.documentation .docs-page { display:grid; grid-template-columns:244px minmax(0,780px); gap:52px; max-width:1500px; padding:36px 40px 64px; }+.docs-sidebar { position:sticky; top:28px; align-self:start; max-height:calc(100vh - 56px); overflow-y:auto; padding:0 5px 12px; }+.docs-title { display:block; font-size:21px; font-weight:600; letter-spacing:-.5px; margin:5px 0 25px; }+.documentation .docs-search { display:block; margin:0; }+.docs-search > span { display:block; font-size:13px; margin-bottom:9px; color:var(--muted); }+.documentation .docs-search input { min-height:44px; padding:11px 13px; font-size:13px; border-radius:var(--radius); background:var(--bg); }+#doc-results { margin:10px 0 0; font-size:12px; }+#doc-results:empty { display:none; }+.documentation #doc-toc { display:block; position:static; margin:25px 0 0; max-height:none; overflow:visible; }+#doc-topic-menu > summary { display:none; }+/* Desktop topics stay visible; the native disclosure serves mobile. */+@media (min-width:1051px) { #doc-topic-menu:not([open]) > nav { display:block; } }+.doc-topic-group { margin-bottom:26px; }+.documentation .doc-topic-group h2 { display:flex; align-items:center; gap:9px; font-size:13px; font-weight:650; letter-spacing:0; margin:0 0 8px; }+.doc-topic-group h2 .icon { width:17px; height:17px; }+.documentation #doc-toc a { display:block; padding:9px 12px; margin:2px 0 2px 22px; font-size:13px; line-height:1.45; min-height:36px; color:var(--muted); border-radius:var(--radius); }+.documentation #doc-toc a:hover { color:var(--text); background:var(--bg); }+.documentation #doc-toc a[aria-current] { color:var(--text); background-color:var(--surface); background-image:var(--dither); font-weight:550; }+.docs-reading { min-width:0; }+.doc-actions { display:flex; justify-content:flex-end; margin:0 0 4px; min-height:38px; }+#copy-doc-page { display:inline-flex; align-items:center; gap:8px; font-size:12px; padding:9px 13px; min-height:38px; background:var(--bg); }+#copy-doc-page .icon { width:15px; height:15px; margin:0; }+.documentation .doc-copy-status { margin:0 0 12px; font-size:12px; color:var(--muted); }+.doc-copy-status:empty { display:none; }+.doc-copy-fallback { width:100%; min-height:160px; margin-bottom:24px; padding:14px; background:var(--bg); color:var(--text); border:1px solid var(--border); border-radius:var(--radius); font:13px/1.6 ui-monospace,Consolas,monospace; }+.documentation #doc-article section { margin:0; }+.documentation #doc-article h1 { font-size:clamp(30px,3vw,42px); font-weight:600; letter-spacing:-1.2px; margin:0 0 28px; line-height:1.15; }+.documentation #doc-article p { color:var(--text); font-size:15px; line-height:1.8; margin:0 0 23px; }+.documentation #doc-article p code, .documentation #doc-article li code { background:var(--surface); padding:2px 5px; border-radius:5px; font-size:.88em; overflow-wrap:anywhere; }+.documentation #doc-article a { text-underline-offset:3px; }+.documentation #doc-article ol { color:var(--text); margin:0 0 26px; font-size:15px; line-height:1.8; }+.documentation #doc-article li { padding-left:4px; margin:8px 0; }+.code-block { margin:25px 0; border-radius:var(--panel-radius); overflow:hidden; background:var(--bg); }+.code-header { display:flex; align-items:center; justify-content:space-between; gap:14px; padding:12px 18px 0; user-select:none; }+.code-language { font-family:ui-monospace,Consolas,monospace; font-size:12px; color:var(--muted); }+.documentation .copy-code { display:inline-flex; align-items:center; gap:7px; font-size:12px; min-height:34px; padding:7px 10px; background:var(--surface); }+.copy-code .icon { width:14px; height:14px; margin:0; }+.documentation .docs pre { display:block; padding:17px 20px 22px; margin:0; background:transparent; border:0; border-radius:0; overflow:auto; font-size:13px; line-height:1.75; }+.documentation .docs pre code { display:block; overflow:visible; padding:0; color:var(--text); }+.hljs-keyword, .hljs-selector-tag, .hljs-literal { color:var(--syntax-keyword); }+.hljs-string, .hljs-attr, .hljs-template-tag { color:var(--syntax-string); }+.hljs-number, .hljs-symbol { color:var(--syntax-number); }+.hljs-comment { color:var(--syntax-comment); }+.hljs-title, .hljs-built_in, .hljs-tag, .hljs-name { color:var(--syntax-name); }+.documentation table { font-size:13px; margin:4px 0 28px; border-collapse:separate; border-spacing:0 5px; }+.documentation td, .documentation th { border:0; padding:12px 14px; }+.documentation th { font-weight:600; }+.documentation tr:nth-child(even) { background:var(--bg); }+.documentation .doc-pagination { display:flex; flex-direction:row; justify-content:space-between; gap:20px; margin:44px 0 0; }+.documentation .doc-pagination a { display:flex; flex-direction:column; gap:6px; padding:15px 18px; margin:0; background:var(--bg); border-radius:var(--radius); text-decoration:none !important; max-width:50%; }+.doc-pagination span { color:var(--muted); font-size:12px; }+.doc-pagination strong { font-size:14px; font-weight:500; }+.docs-sidebar, .doc-actions, .doc-pagination, .navigation { user-select:none; }+@media (prefers-color-scheme:light) {+ .documentation { --syntax-string:#246a43; --syntax-keyword:#77439b; --syntax-number:#93601e; --syntax-comment:#666; --syntax-name:#245e91; }+}+@media (max-width:1200px) and (min-width:1051px) { .documentation .docs-page { gap:30px; grid-template-columns:220px minmax(0,1fr); padding:30px; } }+@media (max-width:1050px) {+ .documentation .docs-page { display:block; padding:28px 30px 50px; }+ .docs-sidebar { position:static; max-height:none; padding:0; margin-bottom:28px; }+ .docs-title { margin:0 0 18px; }+ .documentation .docs-search { max-width:none; }+ #doc-topic-menu > summary { display:flex; align-items:center; gap:14px; padding:13px 14px; margin:14px 0 0; border-radius:var(--radius); background:var(--bg); cursor:pointer; font-size:13px; user-select:none; }+ #doc-topic-menu > summary > :last-child { margin-left:auto; }+ #doc-topic-name { color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }+ .documentation #doc-toc { margin:22px 0 0; }+ #doc-topic-menu[open] #doc-toc { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:0 18px; }+ .doc-actions { margin-bottom:12px; }+}+@media (max-width:760px) {+ .documentation .docs-page { padding:25px 22px 44px; }+ .documentation .docs-search input { font-size:16px; }+ .documentation #doc-article h1 { font-size:32px; margin-bottom:24px; }+ .documentation #doc-article p { font-size:14px; }+ .documentation .docs pre { font-size:12px; padding:16px; }+ .code-header { padding:10px 12px 0; }+ #doc-topic-menu[open] #doc-toc { display:block; }+ .documentation .doc-pagination { gap:12px; }+ .documentation .doc-pagination a { padding:13px; }+}diff --git a/src/documentation.js b/src/documentation.jsindex 7a2d9182..c92ae58e 100644--- a/src/documentation.js+++ b/src/documentation.js@@ -1,74 +1,233 @@import './home.js';+import './documentation.css';import guide from '../docs/guide.md?raw';+import highlight from 'highlight.js/lib/core';+import javascript from 'highlight.js/lib/languages/javascript';+import xml from 'highlight.js/lib/languages/xml';+import bash from 'highlight.js/lib/languages/bash';++highlight.registerLanguage('javascript', javascript);+highlight.registerLanguage('xml', xml);+highlight.registerLanguage('bash', bash);const article = document.querySelector('#doc-article');-const toc = document.querySelector('#doc-toc');-const escape = value => value.replace(/[&<>"']/g, character => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[character]));-// The source is maintained in this repository, not user-supplied Markdown.+const topicNavigation = document.querySelector('#doc-toc');+const search = document.querySelector('#doc-search');+const results = document.querySelector('#doc-results');+const topicMenu = document.querySelector('#doc-topic-menu');+const copyPage = document.querySelector('#copy-doc-page');+const copyStatus = document.querySelector('#doc-copy-status');+const desktopTopics = matchMedia('(min-width: 1051px)');+topicMenu.open = desktopTopics.matches;+desktopTopics.addEventListener('change', () => { topicMenu.open = desktopTopics.matches; });+const groups = [+ { title: 'Start here', icon: 'start', ids: ['overview', 'install', 'getting-started'] },+ { title: 'Build a scene', icon: 'cube', ids: ['parts-and-geometry', 'materials-and-color', 'renderer-reference', 'cameras-and-framing', 'effects-and-lighting'] },+ { title: 'Animate and interact', icon: 'motion', ids: ['deterministic-animation', 'assemblies-and-interaction'] },+ { title: 'Assets and media', icon: 'image', ids: ['import-and-export-models', 'images-and-films'] },+ { title: 'Reference and workflows', icon: 'book', ids: ['performance-and-memory', 'lifecycle-and-troubleshooting', 'models-and-ai-agents', 'addons-and-limits'] },+];+const iconPaths = {+ start: '<path d="m9 5 10 7-10 7V5Z"/>',+ cube: '<path d="m12 3 9 5v8l-9 5-9-5V8l9-5Z M3 8l9 5 9-5 M12 13v8"/>',+ motion: '<path d="M5 5h14v14H5z M9 9l6 3-6 3V9Z"/>',+ image: '<rect x="3" y="4" width="18" height="16" rx="3"/><path d="m3 16 5-5 4 4 3-3 6 6"/><circle cx="16" cy="8" r="1"/>',+ book: '<path d="M12 6c-3-2-6-2-9-1v14c3-1 6-1 9 1 3-2 6-2 9-1V5c-3-1-6-1-9 1Zm0 0v14"/>',+ copy: '<rect x="8" y="8" width="12" height="13" rx="2"/><path d="M15 8V3H3v12h5"/>',+ arrow: '<path d="M5 12h14m-6-6 6 6-6 6"/>',+ chevron: '<path d="m6 9 6 6 6-6"/>',+};++function icon(name) {+ return `<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">${iconPaths[name]}</svg>`;+}++function escapeHtml(value) {+ return value.replace(/[&<>"']/g, character => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[character]));+}+function inline(value) {- return escape(value).replace(/`([^`]+)`/g, '<code>$1</code>').replace(/\[([^\]]+)\]\((\/[^)]+)\)/g,'<a href="$2">$1</a>');+ return escapeHtml(value).replace(/`([^`]+)`/g, '<code>$1</code>').replace(/\[([^\]]+)\]\((\/[^)]+|#[^)]+)\)/g, '<a href="$2">$1</a>');+}++// Keep exact source slices for Copy page, including the Markdown heading.+const headings = [...guide.matchAll(/^## (.+)\r?$/gm)];+const topics = [+ { id: 'overview', title: 'About 67.js', raw: guide.slice(0, headings[0].index) },+ ...headings.map((heading, index) => ({+ id: heading[1].trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/-$/, ''),+ title: heading[1].trim(),+ raw: guide.slice(heading.index, headings[index + 1]?.index ?? guide.length),+ })),+];+let currentTopic;++async function copyText(button, text, code) {+ try {+ await navigator.clipboard.writeText(text);+ button.innerHTML = `✓ ${code ? 'Copied' : 'Page copied'}`;+ copyStatus.textContent = `✓ ${code ? 'Code' : 'Page Markdown'} copied to clipboard.`;+ } catch {+ if (code) {+ const range = document.createRange();+ range.selectNodeContents(code);+ const selection = getSelection();+ selection.removeAllRanges();+ selection.addRange(range);+ copyStatus.textContent = '⚠ Clipboard unavailable. Copy the selected code.';+ } else {+ const source = document.createElement('textarea');+ source.className = 'doc-copy-fallback';+ source.readOnly = true;+ source.setAttribute('aria-label', 'Page Markdown. Select and copy this text.');+ source.value = text;+ document.querySelector('.doc-copy-fallback')?.remove();+ copyStatus.after(source);+ source.focus();+ source.select();+ copyStatus.textContent = '⚠ Clipboard unavailable. Copy the selected Markdown below.';+ }+ }+ setTimeout(() => {+ button.innerHTML = `${icon('copy')}${code ? 'Copy code' : 'Copy page'}`;+ }, 2000);+}++function codeBlock(block, title) {+ const sourceLanguage = block.match(/^```([^\n\r]*)/)[1].trim();+ const language = { js: 'javascript', javascript: 'javascript', html: 'xml', xml: 'xml', sh: 'bash', bash: 'bash' }[sourceLanguage];+ const label = { javascript: 'JavaScript', xml: 'HTML', bash: 'Shell' }[language] ?? (sourceLanguage || 'Plain text');+ const source = block.replace(/^```[^\n]*\n/, '').replace(/```\s*$/, '').trimEnd();+ const container = document.createElement('div');+ container.className = 'code-block';+ const header = document.createElement('div');+ header.className = 'code-header';+ const languageLabel = document.createElement('span');+ languageLabel.className = 'code-language';+ languageLabel.textContent = label;+ const button = document.createElement('button');+ button.className = 'copy-code';+ button.innerHTML = `${icon('copy')}Copy code`;+ button.setAttribute('aria-label', `Copy ${label} code from ${title}`);+ const pre = document.createElement('pre');+ const code = document.createElement('code');+ code.className = language ? `hljs language-${language}` : 'hljs';+ code.innerHTML = language ? highlight.highlight(source, { language }).value : escapeHtml(source);+ button.addEventListener('click', () => copyText(button, source, code));+ header.append(languageLabel, button);+ pre.append(code);+ container.append(header, pre);+ return container;+}++function renderParagraph(paragraph, section) {+ if (paragraph.startsWith('|')) {+ const table = document.createElement('table');+ const rows = paragraph.split('\n').filter(row => !/^\|[\s:|-]+\|$/.test(row));+ table.innerHTML = rows.map((row, rowIndex) => `<tr>${row.split('|').slice(1, -1).map(cell => `<${rowIndex ? 'td' : 'th'}>${inline(cell.trim())}</${rowIndex ? 'td' : 'th'}>`).join('')}</tr>`).join('');+ const scroll = document.createElement('div');+ scroll.className = 'table-scroll';+ scroll.append(table);+ section.append(scroll);+ } else if (/^\d+\.\s/.test(paragraph)) {+ const list = document.createElement('ol');+ for (const line of paragraph.split('\n')) {+ const item = document.createElement('li');+ item.innerHTML = inline(line.replace(/^\d+\.\s/, ''));+ list.append(item);+ }+ section.append(list);+ } else {+ const element = document.createElement('p');+ element.innerHTML = inline(paragraph);+ section.append(element);+ }+}++function renderNavigation() {+ const words = search.value.toLowerCase().trim().split(/\s+/).filter(Boolean);+ const matching = topics.filter(topic => words.every(word => topic.raw.toLowerCase().includes(word) || topic.title.toLowerCase().includes(word)));+ topicNavigation.replaceChildren();+ for (const group of groups) {+ const members = matching.filter(topic => group.ids.includes(topic.id));+ if (!members.length) continue;+ const region = document.createElement('div');+ region.className = 'doc-topic-group';+ const heading = document.createElement('h2');+ heading.innerHTML = `${icon(group.icon)}${escapeHtml(group.title)}`;+ region.append(heading);+ for (const topic of members) {+ const link = document.createElement('a');+ link.href = `#${topic.id}`;+ link.textContent = topic.title;+ if (topic === currentTopic) link.setAttribute('aria-current', 'page');+ link.addEventListener('click', () => {+ if (!desktopTopics.matches) topicMenu.open = false;+ if (location.hash === link.hash) article.focus();+ });+ region.append(link);+ }+ topicNavigation.append(region);+ }+ results.textContent = words.length ? matching.length ? `${matching.length} ${matching.length === 1 ? 'topic' : 'topics'} found` : '⌕ No matching topics. Try camera, memory, or agents.' : '';}-const sections = guide.split(/^## /m).slice(1).map((text, index) => {- const [title, ...lines] = text.split('\n');- const id = title.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/-$/,'');++function openTopic(focus = false) {+ const requested = location.hash.slice(1);+ currentTopic = topics.find(topic => topic.id === requested) ?? topics.find(topic => topic.id === 'install');+ if (requested !== currentTopic.id) history.replaceState(null, '', `#${currentTopic.id}`);const section = document.createElement('section');- section.id = id;- section.innerHTML = `<h2>${escape(title)}</h2>`;- const blocks = lines.join('\n').trim().split(/(```[^\n]*\n[\s\S]*?```)/g);+ section.id = currentTopic.id;+ const heading = document.createElement('h1');+ heading.textContent = currentTopic.title;+ section.append(heading);+ const content = currentTopic.raw.replace(/^#{1,2} [^\n]*\n/, '').trim().replace(/\r\n/g, '\n');+ const blocks = content.split(/(```[^\n]*\n[\s\S]*?```)/g);for (const block of blocks) {if (block.startsWith('```')) {- const pre = document.createElement('pre');- const code = document.createElement('code');- code.textContent = block.replace(/^```[^\n]*\n/, '').replace(/```$/, '').trimEnd();- pre.append(code);- const button = document.createElement('button');- button.className = 'copy-code';- button.textContent = 'Copy';- button.setAttribute('aria-label', `Copy code from ${title}`);- button.addEventListener('click', async () => {- try { await navigator.clipboard.writeText(code.textContent); button.textContent = 'Copied'; }- catch { button.textContent = 'Select and copy'; const selection = getSelection(); const range = document.createRange(); range.selectNodeContents(code); selection.removeAllRanges(); selection.addRange(range); }- setTimeout(() => { button.textContent = 'Copy'; }, 2000);- });- pre.append(button);- section.append(pre);+ section.append(codeBlock(block, currentTopic.title));} else {for (const paragraph of block.trim().split(/\n\s*\n/)) {- if (!paragraph.trim()) continue;- if (paragraph.startsWith('|')) {- const table = document.createElement('table');- const rows = paragraph.split('\n').filter(row => !/^\|[\s:|-]+\|$/.test(row));- table.innerHTML = rows.map((row, rowIndex) => `<tr>${row.split('|').slice(1,-1).map(cell => `<${rowIndex ? 'td' : 'th'}>${inline(cell.trim())}</${rowIndex ? 'td' : 'th'}>`).join('')}</tr>`).join('');- const scroll = document.createElement('div'); scroll.className = 'table-scroll'; scroll.append(table); section.append(scroll);- } else if (/^\d+\.\s/.test(paragraph)) {- const list = document.createElement('ol');- for (const line of paragraph.split('\n')) {- const item = document.createElement('li');- item.innerHTML = inline(line.replace(/^\d+\.\s/, ''));- list.append(item);- }- section.append(list);- } else {- const p = document.createElement('p'); p.innerHTML = inline(paragraph); section.append(p);- }+ if (paragraph.trim()) renderParagraph(paragraph, section);}}}- const link = document.createElement('a'); link.href = `#${id}`; link.textContent = title;- toc.append(link); article.append(section);- return { section, link, text: text.toLowerCase(), index };-});--if (location.hash) {- document.getElementById(location.hash.slice(1))?.scrollIntoView();-}-document.querySelector('#doc-search').addEventListener('input', event => {- const words = event.target.value.toLowerCase().trim().split(/\s+/).filter(Boolean);- let count = 0;- for (const item of sections) {- const visible = words.every(word => item.text.includes(word));- item.section.hidden = item.link.hidden = !visible;- if (visible) count++;+ article.replaceChildren(section);+ if (currentTopic.id === 'install') {+ const managerLink = document.createElement('p');+ managerLink.innerHTML = `<a href="/#downloads">Choose a package manager and get the current release ${icon('arrow')}</a>`;+ section.append(managerLink);}- document.querySelector('#doc-results').textContent = words.length ? count ? `${count} topics found` : 'No matching topics. Try “camera”, “memory” or “agents”.' : '';+ const index = topics.indexOf(currentTopic);+ const pagination = document.createElement('nav');+ pagination.className = 'doc-pagination';+ pagination.setAttribute('aria-label', 'Adjacent topics');+ for (const [topic, direction] of [[topics[index - 1], 'Previous'], [topics[index + 1], 'Next']]) {+ if (!topic) continue;+ const link = document.createElement('a');+ link.href = `#${topic.id}`;+ link.innerHTML = `<span>${direction}</span><strong>${escapeHtml(topic.title)} ${direction === 'Next' ? icon('arrow') : ''}</strong>`;+ pagination.append(link);+ }+ article.append(pagination);+ document.querySelector('#doc-topic-name').textContent = currentTopic.title;+ document.title = `${currentTopic.title} · 67.js documentation`;+ copyStatus.textContent = '';+ document.querySelector('.doc-copy-fallback')?.remove();+ copyPage.innerHTML = `${icon('copy')}Copy page`;+ renderNavigation();+ if (focus) {+ article.focus({ preventScroll: true });+ window.scrollTo({ top: 0 });+ }+}++copyPage.innerHTML = `${icon('copy')}Copy page`;+document.querySelector('#doc-topic-menu summary > :last-child').innerHTML = icon('chevron');+copyPage.addEventListener('click', () => copyText(copyPage, currentTopic.raw));+search.addEventListener('input', () => {+ if (search.value.trim()) topicMenu.open = true;+ renderNavigation();});+window.addEventListener('hashchange', () => openTopic(true));+openTopic();diff --git a/src/home.css b/src/home.cssindex c492db1c..ab37869a 100644--- a/src/home.css+++ b/src/home.css@@ -107,6 +107,16 @@ button:hover { background:var(--border); }.download { position:relative; padding-right:70px; }.download-symbol { position:absolute; right:22px; top:50%; transform:translateY(-50%); display:flex; align-items:center; justify-content:center; width:36px; height:36px; border-radius:12px; background-color:var(--surface); }.download-symbol .icon { width:20px; height:20px; margin:0; }+.package-install { padding:24px; background-color:var(--bg); background-image:var(--dither); border-radius:var(--panel-radius); }+.package-managers { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:16px; }+.package-managers button { min-height:40px; padding:10px 16px; background:transparent; color:var(--muted); }+.package-managers button[aria-pressed=true] { background:var(--surface); color:var(--text); box-shadow:0 0 0 1px var(--border); }+.package-install .command-row { background:var(--window); border-radius:14px; }+.package-note { margin:18px 0; font-size:13px; }+.package-links { display:flex; flex-wrap:wrap; gap:12px 22px; }+.package-links a { display:inline-flex; align-items:center; gap:8px; font-size:13px; min-height:36px; }+.package-links .icon { margin:0; }+@media (max-width:760px) { .package-install { padding:18px; } .package-managers button { padding:10px 12px; } }.example img { aspect-ratio:16/9; border-radius:var(--panel-radius); border:1px solid var(--border); }.introduction { padding:20px 0 12px; }.introduction h1 { max-width:780px; font-size:clamp(34px,4.6vw,62px); line-height:1.06; letter-spacing:-2px; font-weight:600; }diff --git a/src/home.js b/src/home.jsindex b5c4f2b9..ab3f473f 100644--- a/src/home.js+++ b/src/home.js@@ -1,7 +1,13 @@import './home.css';import './brand.js';-const state = { status: 'loading', release: null };+const state = { status: 'loading', release: null, packageManager: 'npm' };+const packageCommands = { npm: 'npm install', pnpm: 'pnpm add', yarn: 'yarn add', bun: 'bun add' };++function installCommand() {+ if (!state.release) return '';+ return state.release.installCommand.replace(/^npm install/, packageCommands[state.packageManager]);+}function setText(selector, text) {document.querySelectorAll(selector).forEach(element => { element.textContent = text; });@@ -46,7 +52,10 @@ function renderRelease() {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-install-command]', release ? installCommand() : state.status === 'error' ? 'Release information is unavailable' : 'Loading the release command…');+ document.querySelectorAll('[data-package-manager]').forEach(button => {+ button.setAttribute('aria-pressed', String(button.dataset.packageManager === state.packageManager));+ });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');@@ -55,14 +64,6 @@ function renderRelease() {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() {@@ -93,7 +94,7 @@ document.querySelectorAll('[data-copy-install]').forEach(button => {button.addEventListener('click', async () => {if (!state.release) return;try {- await navigator.clipboard.writeText(state.release.installCommand);+ await navigator.clipboard.writeText(installCommand());setText('[data-release-status]', '✓ Install command copied');} catch {selectCommand();@@ -102,6 +103,58 @@ document.querySelectorAll('[data-copy-install]').forEach(button => {});});document.querySelectorAll('[data-release-retry]').forEach(button => button.addEventListener('click', loadRelease));++document.querySelectorAll('[data-package-manager]').forEach(button => {+ button.addEventListener('click', () => {+ state.packageManager = button.dataset.packageManager;+ renderRelease();+ });+});++const downloads = document.querySelector('#downloads');+if (downloads) {+ const libraryLinks = [...document.querySelectorAll('.navigation nav a')];+ let navigationPending = false;+ function updateNavigation() {+ const activeHash = downloads.getBoundingClientRect().top <= innerHeight * 0.6 ? '#downloads' : '#examples';+ for (const link of libraryLinks) {+ if (new URL(link.href).hash === activeHash) {+ link.setAttribute('aria-current', 'location');+ } else {+ link.removeAttribute('aria-current');+ }+ }+ navigationPending = false;+ }+ function scheduleNavigation() {+ if (navigationPending) return;+ navigationPending = true;+ requestAnimationFrame(updateNavigation);+ }+ function openHomeSection() {+ const target = document.getElementById(location.hash.slice(1));+ target?.scrollIntoView();+ scheduleNavigation();+ }+ for (const link of libraryLinks) {+ const targetURL = new URL(link.href);+ if (!['#downloads', '#examples'].includes(targetURL.hash)) continue;+ link.addEventListener('click', event => {+ if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;+ event.preventDefault();+ history.pushState(null, '', `/${targetURL.hash}`);+ openHomeSection();+ const section = document.getElementById(targetURL.hash.slice(1));+ section.setAttribute('tabindex', '-1');+ section.focus({ preventScroll: true });+ });+ }+ window.addEventListener('scroll', scheduleNavigation, { passive: true });+ window.addEventListener('resize', scheduleNavigation);+ window.addEventListener('hashchange', openHomeSection);+ window.addEventListener('popstate', openHomeSection);+ requestAnimationFrame(openHomeSection);+}document.querySelectorAll('.example img').forEach(image => {image.addEventListener('error', () => {image.alt = `${image.alt}. Preview unavailable. Open the example to explore it`;