Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix nav and marketplace

nirholasa1a6c697d790
diff --git a/home.html b/home.html
index 9cbae9f5e..f63c77be3 100644
--- a/home.html
+++ b/home.html
@@ -68,8 +68,6 @@
<div id="nav-container"></div>
</header>
<script src="/nav.js"></script>
- </nav>
- </header>
<main id="main-content" class="home-parallax">
<!-- ── Hero (parallax act) ── -->
@@ -751,78 +749,6 @@
</main>
<script>
- // Auth-aware nav CTA
- (function () {
- try {
- const raw = localStorage.getItem('3dagent:auth-hint');
- if (!raw) return;
- const { authed, name } = JSON.parse(raw);
- if (!authed) return;
- const cta = document.getElementById('home-nav-cta');
- if (cta) {
- cta.textContent = 'Dashboard';
- cta.href = '/dashboard';
- }
- const myAgentsLi = document.getElementById('home-nav-my-agents-li');
- if (myAgentsLi) myAgentsLi.hidden = false;
- const userLi = document.getElementById('home-nav-user-li');
- const userEl = document.getElementById('home-nav-user');
- if (userEl && userLi && name) {
- userEl.textContent = name;
- userLi.hidden = false;
- }
- } catch (_) {}
- })();
-
- // Dropdown nav — click to open, Esc / outside-click to close, arrow keys within menu.
- (function () {
- const triggers = document.querySelectorAll('.home-nav .nav-trigger');
- if (!triggers.length) return;
-
- function closeAll(except) {
- triggers.forEach((t) => {
- if (t !== except) t.setAttribute('aria-expanded', 'false');
- });
- }
-
- triggers.forEach((trigger) => {
- trigger.addEventListener('click', (e) => {
- e.stopPropagation();
- const open = trigger.getAttribute('aria-expanded') === 'true';
- closeAll(open ? null : trigger);
- trigger.setAttribute('aria-expanded', open ? 'false' : 'true');
- if (!open) {
- const first = trigger.nextElementSibling?.querySelector('a');
- first?.focus();
- }
- });
-
- const menu = trigger.nextElementSibling;
- if (!menu) return;
- menu.addEventListener('keydown', (e) => {
- const items = Array.from(menu.querySelectorAll('a'));
- const idx = items.indexOf(document.activeElement);
- if (e.key === 'ArrowDown') {
- e.preventDefault();
- items[(idx + 1) % items.length]?.focus();
- } else if (e.key === 'ArrowUp') {
- e.preventDefault();
- items[(idx - 1 + items.length) % items.length]?.focus();
- } else if (e.key === 'Escape') {
- trigger.setAttribute('aria-expanded', 'false');
- trigger.focus();
- }
- });
- });
-
- document.addEventListener('click', (e) => {
- if (!e.target.closest('.home-nav')) closeAll(null);
- });
- document.addEventListener('keydown', (e) => {
- if (e.key === 'Escape') closeAll(null);
- });
- })();
-
// Scroll reveal — use .home-parallax as root so IntersectionObserver
// fires against the perspective scroll container, not the window.
(function () {
diff --git a/pretext-demo.html b/pretext-demo.html
index ad512f30a..ea77e8282 100644
--- a/pretext-demo.html
+++ b/pretext-demo.html
@@ -3,84 +3,245 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>3D-Agent · Pretext Editorial Demo</title>
+ <title>three.ws — Give Your AI a Body</title>
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap" rel="stylesheet">
+ <script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"></script>
<style>
- * { box-sizing: border-box; margin: 0; }
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
+
+ :root {
+ --gold: #ffd76a;
+ --gold-dim: rgba(255,215,106,0.55);
+ --bg: #07080f;
+ }
+
html, body {
- background: radial-gradient(ellipse at 50% 40%, #0d0f1a 0%, #070810 100%);
- color: #e2ddf5;
- height: 100vh;
+ width: 100%; height: 100%;
+ background: var(--bg);
+ color: rgba(255,255,255,0.72);
+ font-family: 'Inter', sans-serif;
overflow: hidden;
}
- body { font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif; }
- #stage {
- position: relative;
- width: 100vw;
- height: 100vh;
+ /* ── header ── */
+ header {
+ position: fixed;
+ top: 0; left: 0; right: 0;
+ z-index: 200;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
+ background: linear-gradient(to bottom, rgba(7,8,15,0.82) 0%, transparent 100%);
+ backdrop-filter: blur(12px);
+ -webkit-backdrop-filter: blur(12px);
+ }
+
+ .logo {
+ font-family: 'Space Grotesk', 'Inter', sans-serif;
+ font-size: 1.1rem;
+ font-weight: 700;
+ color: #fff;
+ display: flex;
+ align-items: center;
+ gap: 0.45rem;
+ text-decoration: none;
+ }
+
+ .logo-dot {
+ width: 8px; height: 8px;
+ border-radius: 50%;
+ background: linear-gradient(135deg, var(--gold), #ff8f4d);
+ box-shadow: 0 0 12px rgba(255,143,77,0.6);
+ }
+
+ .nav-links {
+ display: flex;
+ gap: 1.5rem;
+ align-items: center;
+ list-style: none;
+ }
+
+ .nav-links a {
+ font-size: 0.85rem;
+ font-weight: 500;
+ color: rgba(255,255,255,0.55);
+ text-decoration: none;
+ transition: color 0.2s;
+ }
+
+ .nav-links a:hover { color: #fff; }
+
+ .nav-cta {
+ background: linear-gradient(135deg, var(--gold), #ff8f4d) !important;
+ color: #000 !important;
+ padding: 0.45rem 1rem;
+ border-radius: 6px;
+ font-weight: 600 !important;
+ }
+
+ /* ── scene ── */
+ #scene {
+ position: fixed;
+ inset: 0;
overflow: hidden;
+ }
+
+ /* background glows */
+ .glow-a {
+ position: absolute;
+ width: 600px; height: 600px;
+ border-radius: 50%;
+ background: radial-gradient(circle, rgba(255,175,60,0.06) 0%, transparent 70%);
+ top: -100px; left: 50%;
+ transform: translateX(-50%);
+ pointer-events: none;
+ }
+ .glow-b {
+ position: absolute;
+ width: 400px; height: 400px;
+ border-radius: 50%;
+ background: radial-gradient(circle, rgba(120,80,220,0.07) 0%, transparent 70%);
+ bottom: 10%; right: 10%;
+ pointer-events: none;
+ }
+ .glow-c {
+ position: absolute;
+ width: 300px; height: 300px;
+ border-radius: 50%;
+ background: radial-gradient(circle, rgba(60,180,220,0.06) 0%, transparent 70%);
+ bottom: 5%; left: 8%;
+ pointer-events: none;
+ }
+
+ /* ── 3D model — centered, tall ── */
+ #mv-wrap {
+ position: absolute;
+ top: 50%; left: 50%;
+ transform: translate(-50%, -50%);
+ /* size set by JS on resize */
+ pointer-events: none;
+ z-index: 5;
+ }
+
+ model-viewer {
+ display: block;
+ width: 100%;
+ height: 100%;
+ background: transparent;
+ --progress-bar-color: transparent;
+ --progress-mask: transparent;
+ }
+
+ /* model glow ring */
+ #mv-glow {
+ position: absolute;
+ inset: 0;
+ border-radius: 50%;
+ background: radial-gradient(ellipse at 50% 80%, rgba(255,175,60,0.12) 0%, transparent 65%);
+ pointer-events: none;
+ z-index: 4;
+ }
+
+ /* ── pretext text stage ── */
+ #text-stage {
+ position: absolute;
+ inset: 0;
+ overflow: hidden;
+ z-index: 6;
+ pointer-events: none;
user-select: none;
-webkit-user-select: none;
}
- .line {
+ .txt-line {
position: absolute;
white-space: pre;
- z-index: 1;
- color: #cdc8e8;
+ font-family: 'Inter', sans-serif;
+ color: rgba(255,255,255,0.55);
pointer-events: none;
+ line-height: 1;
}
- .headline-line {
+
+ .txt-hl {
position: absolute;
white-space: pre;
+ font-family: 'Space Grotesk', 'Inter', sans-serif;
font-weight: 700;
color: #fff;
- letter-spacing: -0.5px;
- z-index: 2;
+ letter-spacing: -0.02em;
pointer-events: none;
+ line-height: 1;
}
- .drop-cap {
+
+ .txt-eyebrow {
position: absolute;
- font-weight: 700;
- color: #7c6fcf;
+ white-space: pre;
+ font-family: 'Space Grotesk', 'Inter', sans-serif;
+ font-weight: 600;
+ color: var(--gold);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
pointer-events: none;
- z-index: 2;
}
- .orb {
- position: absolute;
- border-radius: 50%;
- z-index: 10;
- will-change: transform;
- }
- .pullquote-line {
+
+ .txt-accent {
position: absolute;
white-space: pre;
+ font-family: 'Inter', sans-serif;
+ font-weight: 300;
+ color: rgba(255,215,106,0.5);
font-style: italic;
- color: #9d8fd6;
- z-index: 3;
pointer-events: none;
}
- .pullquote-bar {
+
+ /* ── orbs ── */
+ .orb {
position: absolute;
- background: #4a3e8a;
- width: 3px;
+ border-radius: 50%;
z-index: 3;
- pointer-events: none;
+ will-change: transform;
+ pointer-events: auto;
+ cursor: grab;
}
- .hint {
+
+ /* ── bottom badge ── */
+ .bottom-badge {
position: fixed;
- top: 16px;
+ bottom: 1.5rem;
left: 50%;
transform: translateX(-50%);
- font: 400 13px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
- color: rgba(255,255,255,0.22);
z-index: 100;
- background: rgba(0,0,0,0.45);
- padding: 8px 18px;
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ background: rgba(255,255,255,0.04);
+ border: 1px solid rgba(255,255,255,0.08);
+ backdrop-filter: blur(10px);
+ padding: 0.4rem 0.9rem;
border-radius: 999px;
+ font-size: 0.72rem;
+ color: rgba(255,255,255,0.35);
+ font-family: 'Space Grotesk', 'Inter', sans-serif;
pointer-events: none;
white-space: nowrap;
}
+
+ .bottom-badge-dot {
+ width: 6px; height: 6px;
+ border-radius: 50%;
+ background: var(--gold);
+ box-shadow: 0 0 6px rgba(255,215,106,0.8);
+ animation: pulse 2s ease-in-out infinite;
+ }
+
+ @keyframes pulse {
+ 0%, 100% { opacity: 1; transform: scale(1); }
+ 50% { opacity: 0.5; transform: scale(0.75); }
+ }
+
#err {
position: fixed;
top: 0; left: 0; right: 0;
@@ -92,401 +253,398 @@
white-space: pre-wrap;
display: none;
}
- @media (max-width: 760px) { .hint { display: none; } }
</style>
</head>
<body>
- <div id="err"></div>
- <div id="stage"></div>
- <div class="hint">Drag the orbs &middot; Click to pause &middot; Zero DOM reads</div>
-
- <script type="module">
- function showErr(e) {
- const el = document.getElementById('err');
- el.style.display = 'block';
- el.textContent = String(e?.stack || e);
- }
- window.addEventListener('error', e => showErr(e.error || e.message));
- window.addEventListener('unhandledrejection', e => showErr(e.reason));
-
- try {
-
- import('@chenglou/pretext').then(({
- layoutNextLine,
- layoutWithLines,
- prepareWithSegments,
- walkLineRanges,
- }) => {
- run({ layoutNextLine, layoutWithLines, prepareWithSegments, walkLineRanges });
- }).catch(showErr);
-
- } catch(e) { showErr(e); }
-
- function run({ layoutNextLine, layoutWithLines, prepareWithSegments, walkLineRanges }) {
- const BODY_FONT = '17px "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif';
- const BODY_LINE_HEIGHT = 28;
- const HL_FAMILY = '"Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif';
- const HL_TEXT = 'AUTONOMOUS AGENTS ARE THE NEW INTERFACE';
- const GUTTER = 48;
- const COL_GAP = 40;
- const DROP_LINES = 3;
- const MIN_SLOT = 50;
-
- const BODY = `The history of software interfaces is a history of shrinking distance between human intent and machine action. The command line required you to memorize incantations. The graphical interface gave you objects to click. The touchscreen made those objects physical. Each transition collapsed a layer of indirection, bringing the interface closer to thought itself.
-
-Autonomous agents collapse the remaining distance. You do not click, type, or drag. You describe what you want, and the agent determines how to achieve it. The interface disappears entirely, replaced by a collaborator that understands context, maintains memory, and executes multi-step plans across heterogeneous systems.
-
-On the Solana blockchain, this transformation is happening in real time. Agents are being deployed that can trade tokens, manage liquidity positions, respond to on-chain events, and coordinate with other agents — all without human intervention between steps. The latency of human decision-making is removed from the loop. The agent acts at the speed of the network.
-
-What makes Solana uniquely suited to autonomous agents is the combination of finality speed, fee structure, and programmability. A transaction confirms in four hundred milliseconds. Fees are fractions of a cent. Programs can invoke other programs atomically, allowing agents to compose complex multi-step operations into a single transaction. Either everything succeeds, or nothing does.
-
-The 3D-Agent platform extends this into the visual domain. Agents are not faceless processes running in a datacenter — they are embodied in three-dimensional characters that represent identity, personality, and current state. An agent managing a DeFi position might pace anxiously when its collateral ratio nears a threshold. An agent completing a successful arbitrage might celebrate. The visual representation is not decorative — it is a real-time signal that humans can parse at a glance, the same way a colleague's body language communicates before they say a word.
-
-This matters because the transition to autonomous agents does not eliminate the human. It changes the human's role from operator to supervisor. Instead of executing actions, you observe agents, assess their behavior, and intervene when something deviates from your intent. The 3D representation is an interface optimized for this supervisory role — rich in signal, low in cognitive load, comprehensible in a glance.
-
-The technical substrate is a combination of real-time 3D rendering, Solana's WebSocket RPC, and a model context protocol that allows language models to issue structured commands against on-chain programs. When an agent decides to act, it produces a typed action description. The action is validated against a schema, translated into Solana instructions, and submitted. The result flows back into the agent's context, updating its world model and informing the next decision.
-
-Memory is the missing ingredient in most agent systems. An agent that forgets its previous actions cannot maintain a coherent strategy over time. The 3D-Agent memory system stores compressed episode summaries on Arweave, indexed by agent public key, with recency-weighted retrieval that surfaces relevant past experience when the agent faces analogous situations. The agent that traded a particular token six months ago and lost can retrieve that episode and adjust its strategy accordingly.
-
-Coordination between agents is the frontier. Multiple agents acting in parallel, with shared goals and divided responsibilities, can achieve outcomes no single agent could. On Solana, this coordination can be made explicit and verifiable through on-chain programs that record inter-agent commitments, track task completion, and arbitrate disputes. The blockchain becomes the coordination layer for a society of agents.
-
-The interface is not the command line, the GUI, the touchscreen, or the chat window. The interface is the agent itself, rendered in three dimensions, moving through a persistent space, leaving a trail of actions that a supervisor can audit and a memory system that allows it to learn. The distance between human intent and machine action has never been smaller. We are building the final layer.`;
-
- const PQ_FONT = `italic 17px ${HL_FAMILY}`;
- const PQ_LH = 26;
- const PULLQUOTES = [
- { text: '"An agent that forgets its previous actions cannot maintain a coherent strategy. Memory makes agents learnable — not from gradients, but from experience."', col: 0, yFrac: 0.44, wFrac: 0.52, side: 'right' },
- { text: '"The interface is not the chat window. The interface is the agent itself, rendered in three dimensions."', col: 1, yFrac: 0.28, wFrac: 0.50, side: 'left' },
- ];
-
- const ORB_DEFS = [
- { fx: 0.52, fy: 0.22, r: 105, vx: 22, vy: 15, rgb: [124,111,207] },
- { fx: 0.18, fy: 0.50, r: 80, vx: -18, vy: 25, rgb: [70,130,240] },
- { fx: 0.75, fy: 0.60, r: 90, vx: 15, vy: -20, rgb: [170,70,210] },
- { fx: 0.38, fy: 0.74, r: 70, vx: -24, vy: -13, rgb: [50,175,195] },
- { fx: 0.88, fy: 0.18, r: 60, vx: -12, vy: 18, rgb: [210,90,150] },
- ];
-
- // ── helpers ─────────────────────────────────────────────────────────
- function carveSlots(base, blocked) {
- let slots = [base];
- for (const b of blocked) {
- const next = [];
- for (const s of slots) {
- if (b.right <= s.left || b.left >= s.right) { next.push(s); continue; }
- if (b.left > s.left) next.push({ left: s.left, right: b.left });
- if (b.right < s.right) next.push({ left: b.right, right: s.right });
- }
- slots = next;
+
+<div id="err"></div>
+
+<!-- header -->
+<header>
+ <a class="logo" href="#">
+ <span class="logo-dot"></span>
+ three.ws
+ </a>
+ <nav>
+ <ul class="nav-links">
+ <li><a href="#">Docs</a></li>
+ <li><a href="#">Agents</a></li>
+ <li><a href="#">On-chain</a></li>
+ <li><a href="#" class="nav-cta">Build free →</a></li>
+ </ul>
+ </nav>
+</header>
+
+<!-- scene -->
+<div id="scene">
+ <div class="glow-a"></div>
+ <div class="glow-b"></div>
+ <div class="glow-c"></div>
+ <div id="mv-wrap">
+ <model-viewer
+ id="mv"
+ src="/animations/robotexpressive.glb"
+ auto-rotate
+ auto-rotate-delay="0"
+ rotation-per-second="8deg"
+ interaction-prompt="none"
+ camera-controls="false"
+ disable-zoom
+ shadow-intensity="0.4"
+ exposure="0.9"
+ environment-image="neutral"
+ camera-orbit="0deg 82deg 3.2m"
+ field-of-view="38deg"
+ ></model-viewer>
+ <div id="mv-glow"></div>
+ </div>
+ <div id="text-stage"></div>
+</div>
+
+<div class="bottom-badge">
+ <div class="bottom-badge-dot"></div>
+ pretext · zero DOM reads · text flows around your agent in real time
+</div>
+
+<script type="module">
+ function showErr(e) {
+ const el = document.getElementById('err');
+ el.style.display = 'block';
+ el.textContent = String(e?.stack || e);
+ console.error(e);
+ }
+ window.addEventListener('unhandledrejection', e => showErr(e.reason));
+
+ import('@chenglou/pretext').then(lib => {
+ try { main(lib); } catch(e) { showErr(e); }
+ }).catch(showErr);
+
+ function main({ prepareWithSegments, layoutNextLine, layoutWithLines, walkLineRanges }) {
+
+ // ── copy ──────────────────────────────────────────────────────────────
+ const EYEBROW = 'THE 3D LAYER FOR ONCHAIN AI AGENTS';
+ const HL_LINE1 = 'Give your';
+ const HL_LINE2 = 'AI a body.';
+ const BODY_TEXT = `Born in 3D. Raised on-chain. Yours forever.
+
+Your AI has been a chatbox long enough. Give it a body, a personality, and a permanent home open to every human, app, and agent that comes looking.
+
+Drop any GLB into the browser and your agent appears as a fully rendered 3D avatar — animated, reactive, and ready to embed anywhere you can drop a script tag.
+
+Connect any LLM via MCP or A2A — Claude, GPT, Gemini, or your own. Built-in empathy layer for real-time emotion. No SDK on the consumer side. No vendor lock-in.
+
+Register your agent on 20+ EVM chains via ERC-8004 — a verifiable, CREATE2-deterministic identity discoverable by any A2A or MCP client. Your agent. Your keys.
+
+The interface is not the chatbox. The interface is the agent itself, rendered in three dimensions, moving through a persistent space, leaving a trail of actions a supervisor can audit.
+
+Autonomous agents on Solana act at four hundred milliseconds finality. They swap tokens, manage liquidity, respond to on-chain events — all without human latency in the loop. The 3D body is the signal layer. You watch. You decide when to step in.
+
+This is the final interface. Not a dashboard. Not a feed. A world where your agents live, move, and work — visible, auditable, yours.`;
+
+ const ACCENT_LINES = [
+ 'glTF 2.0 · GLB · ERC-8004 · A2A · MCP',
+ 'Solana · EVM · 20+ chains',
+ ];
+
+ // ── fonts ──────────────────────────────────────────────────────────────
+ const BODY_FONT = '15px "Inter", sans-serif';
+ const BODY_LH = 25;
+ const HL_FAMILY = '"Space Grotesk", "Inter", sans-serif';
+ const EY_FONT = `600 11px ${HL_FAMILY}`;
+ const AC_FONT = `300 13px "Inter", sans-serif`;
+
+ // ── DOM ────────────────────────────────────────────────────────────────
+ const mv = document.getElementById('mv');
+ const mvWrap = document.getElementById('mv-wrap');
+ const stage = document.getElementById('text-stage');
+
+ // ── model viewer sizing ────────────────────────────────────────────────
+ function sizeModel() {
+ const W = window.innerWidth, H = window.innerHeight;
+ const mh = Math.round(H * 0.78);
+ const mw = Math.round(Math.min(mh * 0.58, W * 0.38));
+ mvWrap.style.width = mw + 'px';
+ mvWrap.style.height = mh + 'px';
+ }
+ sizeModel();
+ window.addEventListener('resize', sizeModel);
+
+ // ── orbs ───────────────────────────────────────────────────────────────
+ const ORB_DEFS = [
+ { fx: 0.10, fy: 0.20, r: 55, vx: 18, vy: 12, rgb: [255,175,60] },
+ { fx: 0.85, fy: 0.25, r: 45, vx: -15, vy: 20, rgb: [100,130,255] },
+ { fx: 0.12, fy: 0.70, r: 50, vx: 20, vy: -14, rgb: [160,80,220] },
+ { fx: 0.88, fy: 0.72, r: 40, vx: -18, vy: -16, rgb: [60,200,180] },
+ ];
+
+ const scene = document.getElementById('scene');
+ const orbEls = ORB_DEFS.map(d => {
+ const el = document.createElement('div');
+ el.className = 'orb';
+ const [r,g,b] = d.rgb;
+ el.style.background = `radial-gradient(circle at 35% 35%, rgba(${r},${g},${b},0.28), rgba(${r},${g},${b},0.08) 55%, transparent 72%)`;
+ el.style.boxShadow = `0 0 40px 10px rgba(${r},${g},${b},0.14), 0 0 90px 30px rgba(${r},${g},${b},0.05)`;
+ scene.appendChild(el);
+ return el;
+ });
+
+ const orbs = ORB_DEFS.map(d => ({
+ x: d.fx * window.innerWidth,
+ y: d.fy * window.innerHeight,
+ r: d.r, vx: d.vx, vy: d.vy, paused: false,
+ }));
+
+ // ── drag ───────────────────────────────────────────────────────────────
+ let drag = null, pMove = null, pDown = null;
+
+ scene.addEventListener('pointerdown', e => {
+ const hit = hitOrb(e.clientX, e.clientY);
+ if (hit < 0) return;
+ drag = { i: hit, ox: orbs[hit].x, oy: orbs[hit].y, px: e.clientX, py: e.clientY };
+ orbs[hit].paused = true;
+ e.preventDefault();
+ });
+ window.addEventListener('pointermove', e => { pMove = { x: e.clientX, y: e.clientY }; });
+ window.addEventListener('pointerup', e => {
+ if (!drag) return;
+ orbs[drag.i].paused = false;
+ orbs[drag.i].vx = (e.clientX - drag.px) * 4;
+ orbs[drag.i].vy = (e.clientY - drag.py) * 4;
+ drag = null;
+ });
+
+ function hitOrb(px, py) {
+ for (let i = orbs.length - 1; i >= 0; i--) {
+ const o = orbs[i];
+ const dx = px - o.x, dy = py - o.y;
+ if (dx*dx + dy*dy <= o.r * o.r * 1.2) return i;
+ }
+ return -1;
+ }
+
+ // ── layout helpers ─────────────────────────────────────────────────────
+ const MIN_SLOT = 40;
+
+ function carveSlots(base, blocked) {
+ let slots = [base];
+ for (const b of blocked) {
+ const next = [];
+ for (const s of slots) {
+ if (b.right <= s.left || b.left >= s.right) { next.push(s); continue; }
+ if (b.left > s.left) next.push({ left: s.left, right: b.left });
+ if (b.right < s.right) next.push({ left: b.right, right: s.right });
}
- return slots.filter(s => s.right - s.left >= MIN_SLOT);
+ slots = next;
}
+ return slots.filter(s => s.right - s.left >= MIN_SLOT);
+ }
- function circleInterval(cx, cy, r, top, bot, hPad, vPad) {
- const t = top - vPad, b = bot + vPad;
- if (t >= cy + r || b <= cy - r) return null;
- const minDy = cy >= t && cy <= b ? 0 : cy < t ? t - cy : cy - b;
- if (minDy >= r) return null;
- const dx = Math.sqrt(r * r - minDy * minDy);
- return { left: cx - dx - hPad, right: cx + dx + hPad };
+ // ── column layout ──────────────────────────────────────────────────────
+ function layoutCol(prepared, startCursor, rX, rY, rW, rH, lh, circObs, rectObs) {
+ let cursor = startCursor, y = rY;
+ const lines = [];
+ let done = false;
+ while (y + lh <= rY + rH && !done) {
+ const blocked = [];
+ for (const o of circObs) {
+ const t = y, b = y + lh, vp = 4, hp = 10;
+ const cy = o.cy, cx = o.cx, r = o.r;
+ const top = t - vp, bot = b + vp;
+ if (top >= cy + r || bot <= cy - r) continue;
+ const minDy = cy >= top && cy <= bot ? 0 : cy < top ? top - cy : cy - bot;
+ if (minDy >= r) continue;
+ const dx = Math.sqrt(r*r - minDy*minDy);
+ blocked.push({ left: cx - dx - hp, right: cx + dx + hp });
+ }
+ for (const rect of rectObs) {
+ if (y + lh <= rect.y || y >= rect.y + rect.h) continue;
+ blocked.push({ left: rect.x, right: rect.x + rect.w });
+ }
+ const slots = carveSlots({ left: rX, right: rX + rW }, blocked);
+ if (!slots.length) { y += lh; continue; }
+ for (const slot of slots.sort((a, b) => a.left - b.left)) {
+ const ln = layoutNextLine(prepared, cursor, slot.right - slot.left);
+ if (!ln) { done = true; break; }
+ lines.push({ x: Math.round(slot.left), y: Math.round(y), text: ln.text });
+ cursor = ln.end;
+ }
+ y += lh;
}
+ return { lines, cursor };
+ }
- // ── DOM setup ────────────────────────────────────────────────────────
- const stage = document.getElementById('stage');
- const W0 = window.innerWidth, H0 = window.innerHeight;
+ // ── pools ──────────────────────────────────────────────────────────────
+ const pools = { body: [], hl: [], ey: [], ac: [] };
- function mkOrb([r,g,b]) {
- const el = document.createElement('div');
- el.className = 'orb';
- el.style.background = `radial-gradient(circle at 35% 35%, rgba(${r},${g},${b},0.35), rgba(${r},${g},${b},0.12) 55%, transparent 72%)`;
- el.style.boxShadow = `0 0 60px 15px rgba(${r},${g},${b},0.18), 0 0 120px 40px rgba(${r},${g},${b},0.07)`;
- el.style.cursor = 'grab';
+ function sync(pool, n, tag, cls) {
+ while (pool.length < n) {
+ const el = document.createElement(tag);
+ el.className = cls;
stage.appendChild(el);
- return el;
+ pool.push(el);
}
+ for (let i = 0; i < pool.length; i++) pool[i].style.display = i < n ? '' : 'none';
+ }
- // ── prepare text ─────────────────────────────────────────────────────
- document.fonts.ready.then(() => {
- try { main(); } catch(e) { showErr(e); }
- });
-
- function main() {
- const prepBody = prepareWithSegments(BODY, BODY_FONT);
- const prepPQs = PULLQUOTES.map(q => prepareWithSegments(q.text, PQ_FONT));
- const DROP_SIZE = BODY_LINE_HEIGHT * DROP_LINES - 4;
- const DROP_FONT = `700 ${DROP_SIZE}px ${HL_FAMILY}`;
- const prepDrop = prepareWithSegments(BODY[0], DROP_FONT);
-
- let dropW = 0;
- walkLineRanges(prepDrop, 99999, ln => { dropW = ln.width; });
- const DROP_W = Math.ceil(dropW) + 10;
-
- const dropEl = document.createElement('div');
- dropEl.className = 'drop-cap';
- dropEl.textContent = BODY[0];
- dropEl.style.font = DROP_FONT;
- dropEl.style.lineHeight = `${DROP_SIZE}px`;
- stage.appendChild(dropEl);
-
- const orbEls = ORB_DEFS.map(d => mkOrb(d.rgb));
- const orbs = ORB_DEFS.map(d => ({
- x: d.fx * W0, y: d.fy * H0,
- r: d.r, vx: d.vx, vy: d.vy,
- paused: false,
- }));
-
- // ── headline fit cache ─────────────────────────────────────────────
- let hlCache = null;
- function fitHL(maxW, maxH) {
- if (hlCache && hlCache.maxW === maxW && hlCache.maxH === maxH) return hlCache;
- let lo = 16, hi = 88, best = lo, bestLines = [];
- while (lo <= hi) {
- const sz = (lo + hi) >> 1;
- const font = `700 ${sz}px ${HL_FAMILY}`;
- const lh = Math.round(sz * 0.93);
- const p = prepareWithSegments(HL_TEXT, font);
- let breaks = false, count = 0;
- walkLineRanges(p, maxW, ln => { count++; if (ln.end.graphemeIndex !== 0) breaks = true; });
- if (!breaks && count * lh <= maxH) {
- best = sz;
- const r = layoutWithLines(p, maxW, lh);
- bestLines = r.lines.map((l, i) => ({ x: 0, y: i * lh, text: l.text }));
- lo = sz + 1;
- } else {
- hi = sz - 1;
- }
- }
- hlCache = { maxW, maxH, sz: best, lh: Math.round(best * 0.93), lines: bestLines };
- return hlCache;
- }
+ function applyLines(pool, lines, font, lh) {
+ for (let i = 0; i < lines.length; i++) {
+ const el = pool[i], ln = lines[i];
+ el.textContent = ln.text;
+ el.style.left = ln.x + 'px';
+ el.style.top = ln.y + 'px';
+ el.style.font = font;
+ el.style.lineHeight = lh + 'px';
+ }
+ }
- // ── layout column ─────────────────────────────────────────────────
- function layoutCol(prepared, startCursor, rX, rY, rW, rH, lh, circObs, rectObs) {
- let cursor = startCursor;
- let y = rY;
- const lines = [];
- let done = false;
- while (y + lh <= rY + rH && !done) {
- const blocked = [];
- for (const o of circObs) {
- const iv = circleInterval(o.cx, o.cy, o.r, y, y + lh, o.hPad, o.vPad);
- if (iv) blocked.push(iv);
- }
- for (const rect of rectObs) {
- if (y + lh <= rect.y || y >= rect.y + rect.h) continue;
- blocked.push({ left: rect.x, right: rect.x + rect.w });
- }
- const slots = carveSlots({ left: rX, right: rX + rW }, blocked);
- if (!slots.length) { y += lh; continue; }
- const ordered = slots.slice().sort((a, b) => a.left - b.left);
- for (const slot of ordered) {
- const ln = layoutNextLine(prepared, cursor, slot.right - slot.left);
- if (!ln) { done = true; break; }
- lines.push({ x: Math.round(slot.left), y: Math.round(y), text: ln.text });
- cursor = ln.end;
- }
- y += lh;
- }
- return { lines, cursor };
- }
+ // ── pretext prepare ────────────────────────────────────────────────────
+ const prepBody = prepareWithSegments(BODY_TEXT, BODY_FONT);
+ const prepEy = prepareWithSegments(EYEBROW, EY_FONT);
+ const prepAc = ACCENT_LINES.map(t => prepareWithSegments(t, AC_FONT));
+
+ // ── headline fit (two fixed lines, find largest px that fits left col) ─
+ let hlCache2 = null;
+ function fitHL2(maxW, maxPx) {
+ const key = `${maxW}|${maxPx}`;
+ if (hlCache2?.key === key) return hlCache2;
+ let lo = 20, hi = maxPx, best = lo;
+ while (lo <= hi) {
+ const sz = (lo + hi) >> 1;
+ const font = `700 ${sz}px ${HL_FAMILY}`;
+ const p1 = prepareWithSegments(HL_LINE1, font);
+ const p2 = prepareWithSegments(HL_LINE2, font);
+ let fits = true;
+ walkLineRanges(p1, maxW, ln => { if (ln.end.graphemeIndex !== 0) fits = false; });
+ walkLineRanges(p2, maxW, ln => { if (ln.end.graphemeIndex !== 0) fits = false; });
+ if (fits) { best = sz; lo = sz + 1; } else { hi = sz - 1; }
+ }
+ const lh = Math.round(best * 1.08);
+ hlCache2 = { key, sz: best, lh, font: `700 ${best}px ${HL_FAMILY}` };
+ return hlCache2;
+ }
- // ── element pools ──────────────────────────────────────────────────
- const pools = { hl: [], body: [], pq: [], pqBar: [] };
+ // ── frame loop ─────────────────────────────────────────────────────────
+ let lastT = null;
- function sync(pool, n, tag, cls) {
- while (pool.length < n) {
- const el = document.createElement(tag);
- el.className = cls;
- stage.appendChild(el);
- pool.push(el);
- }
- for (let i = 0; i < pool.length; i++) pool[i].style.display = i < n ? '' : 'none';
- }
+ function frame(now) {
+ requestAnimationFrame(frame);
- function applyLines(pool, lines, font, lh) {
- for (let i = 0; i < lines.length; i++) {
- const el = pool[i], ln = lines[i];
- el.textContent = ln.text;
- el.style.left = ln.x + 'px';
- el.style.top = ln.y + 'px';
- el.style.font = font;
- el.style.lineHeight = lh + 'px';
- }
+ if (pMove) {
+ if (drag) {
+ orbs[drag.i].x = drag.ox + (pMove.x - drag.px);
+ orbs[drag.i].y = drag.oy + (pMove.y - drag.py);
}
+ pMove = null;
+ }
- // ── drag / pointer ─────────────────────────────────────────────────
- let drag = null, lastT = null;
- let pDown = null, pMove = null, pUp = null;
-
- stage.addEventListener('pointerdown', e => {
- pDown = { x: e.clientX, y: e.clientY };
- const hit = hitOrb(e.clientX, e.clientY);
- if (hit >= 0) {
- drag = { i: hit, ox: orbs[hit].x, oy: orbs[hit].y, px: e.clientX, py: e.clientY };
- orbs[hit].paused = true;
- e.preventDefault();
- }
- });
- window.addEventListener('pointermove', e => { pMove = { x: e.clientX, y: e.clientY }; });
- window.addEventListener('pointerup', e => {
- pUp = { x: e.clientX, y: e.clientY };
- if (drag) {
- orbs[drag.i].paused = false;
- const elapsed = lastT ? 0.016 : 0;
- orbs[drag.i].vx = (e.clientX - drag.px) * 5;
- orbs[drag.i].vy = (e.clientY - drag.py) * 5;
- drag = null;
- }
- });
-
- function hitOrb(px, py) {
- for (let i = orbs.length - 1; i >= 0; i--) {
- const o = orbs[i];
- const dx = px - o.x, dy = py - o.y;
- if (dx * dx + dy * dy <= o.r * o.r * 1.1) return i;
+ const dt = lastT === null ? 0 : Math.min((now - lastT) / 1000, 0.05);
+ lastT = now;
+ const W = window.innerWidth, H = window.innerHeight;
+
+ // physics
+ for (let i = 0; i < orbs.length; i++) {
+ const o = orbs[i];
+ if (o.paused || (drag && drag.i === i)) continue;
+ o.x += o.vx * dt; o.y += o.vy * dt;
+ if (o.x - o.r < 0) { o.x = o.r; o.vx = Math.abs(o.vx); }
+ if (o.x + o.r > W) { o.x = W - o.r; o.vx = -Math.abs(o.vx); }
+ if (o.y - o.r < 0) { o.y = o.r; o.vy = Math.abs(o.vy); }
+ if (o.y + o.r > H) { o.y = H - o.r; o.vy = -Math.abs(o.vy); }
+ }
+ for (let i = 0; i < orbs.length; i++) {
+ for (let j = i + 1; j < orbs.length; j++) {
+ const a = orbs[i], b = orbs[j];
+ const dx = b.x - a.x, dy = b.y - a.y;
+ const d = Math.sqrt(dx*dx + dy*dy), min = a.r + b.r;
+ if (d < min && d > 0.01) {
+ const ov = (min - d) / 2, nx = dx/d, ny = dy/d;
+ if (!a.paused) { a.x -= nx*ov; a.y -= ny*ov; }
+ if (!b.paused) { b.x += nx*ov; b.y += ny*ov; }
}
- return -1;
}
+ }
+ for (let i = 0; i < orbs.length; i++) {
+ const o = orbs[i];
+ orbEls[i].style.width = o.r*2 + 'px';
+ orbEls[i].style.height = o.r*2 + 'px';
+ orbEls[i].style.transform = `translate(${Math.round(o.x-o.r)}px,${Math.round(o.y-o.r)}px)`;
+ }
- // ── render loop ────────────────────────────────────────────────────
- function frame(now) {
- requestAnimationFrame(frame);
-
- // pointer
- if (pMove) {
- if (drag) {
- orbs[drag.i].x = drag.ox + (pMove.x - drag.px);
- orbs[drag.i].y = drag.oy + (pMove.y - drag.py);
- }
- pMove = null;
- }
- if (pDown) {
- const hit = hitOrb(pDown.x, pDown.y);
- if (hit >= 0 && !drag) orbs[hit].paused = !orbs[hit].paused;
- pDown = null;
- }
- if (pUp) pUp = null;
-
- // physics
- const dt = lastT === null ? 0 : Math.min((now - lastT) / 1000, 0.05);
- lastT = now;
- const W = window.innerWidth, H = window.innerHeight;
-
- for (let i = 0; i < orbs.length; i++) {
- const o = orbs[i];
- if (o.paused || (drag && drag.i === i)) continue;
- o.x += o.vx * dt; o.y += o.vy * dt;
- if (o.x - o.r < 0) { o.x = o.r; o.vx = Math.abs(o.vx); }
- if (o.x + o.r > W) { o.x = W - o.r; o.vx = -Math.abs(o.vx); }
- if (o.y - o.r < 0) { o.y = o.r; o.vy = Math.abs(o.vy); }
- if (o.y + o.r > H) { o.y = H - o.r; o.vy = -Math.abs(o.vy); }
- }
- // orb-orb separation
- for (let i = 0; i < orbs.length; i++) {
- for (let j = i + 1; j < orbs.length; j++) {
- const a = orbs[i], b = orbs[j];
- const dx = b.x - a.x, dy = b.y - a.y;
- const d = Math.sqrt(dx*dx + dy*dy);
- const min = a.r + b.r;
- if (d < min && d > 0.01) {
- const ov = (min - d) / 2, nx = dx/d, ny = dy/d;
- if (!a.paused) { a.x -= nx*ov; a.y -= ny*ov; }
- if (!b.paused) { b.x += nx*ov; b.y += ny*ov; }
- if (!a.paused && !b.paused) {
- const dot = (a.vx-b.vx)*nx + (a.vy-b.vy)*ny;
- if (dot > 0) { a.vx -= dot*nx; a.vy -= dot*ny; b.vx += dot*nx; b.vy += dot*ny; }
- }
- }
- }
- }
-
- // update orb DOM
- for (let i = 0; i < orbs.length; i++) {
- const o = orbs[i];
- const el = orbEls[i];
- const d = o.r * 2;
- el.style.width = d + 'px';
- el.style.height = d + 'px';
- el.style.transform = `translate(${Math.round(o.x - o.r)}px,${Math.round(o.y - o.r)}px)`;
- }
+ // ── layout ────────────────────────────────────────────────────────────
+ const G = W < 700 ? 16 : 52;
+ const totalW = W - G * 2;
+
+ // model rect — one getBoundingClientRect per frame
+ const mvRect = mvWrap.getBoundingClientRect();
+ const modelPadH = 28, modelPadV = 0;
+ const modelObs = {
+ x: mvRect.left - modelPadH,
+ y: mvRect.top - modelPadV,
+ w: mvRect.width + modelPadH * 2,
+ h: mvRect.height + modelPadV * 2,
+ };
+
+ // orb obstacles (inline circle math)
+ const circObs = orbs.map(o => ({ cx: o.x, cy: o.y, r: o.r }));
+
+ // ── headline: left of model ──────────────────────────────────────────
+ const leftColW = Math.round(mvRect.left - G - 16);
+ const hlMaxW = Math.max(leftColW, 120);
+ const hlFit = fitHL2(hlMaxW, 80);
+ const hlCenterY = Math.round(mvRect.top + mvRect.height * 0.28);
+ const hlTotalH = hlFit.lh * 2;
+ const hlTop = hlCenterY - hlTotalH / 2;
+ const hl1 = { x: G, y: Math.round(hlTop), text: HL_LINE1 };
+ const hl2 = { x: G, y: Math.round(hlTop + hlFit.lh), text: HL_LINE2 };
+
+ // ── eyebrow: above headline ──────────────────────────────────────────
+ const eyTop = Math.round(hlTop - 28);
+ const eyR = layoutWithLines(prepEy, hlMaxW, 14);
+ const eyLines = eyR.lines.map((l, i) => ({ x: G, y: eyTop + i * 16, text: l.text }));
+
+ // ── body: full-width, flows around model + orbs ──────────────────────
+ // Use the entire viewport height (skip header ~60px)
+ const bodyTop = 68;
+ const bodyH = H - bodyTop - 16;
+ const zero = { segmentIndex: 0, graphemeIndex: 0 };
+ const { lines: bodyLines } = layoutCol(
+ prepBody, zero,
+ G, bodyTop, totalW, bodyH,
+ BODY_LH,
+ circObs, [modelObs],
+ );
+
+ // ── accent strip: below model ────────────────────────────────────────
+ const acTop = Math.round(mvRect.bottom + 14);
+ const acLines = [];
+ for (let qi = 0; qi < prepAc.length; qi++) {
+ const r = layoutWithLines(prepAc[qi], totalW, 18);
+ for (const l of r.lines) acLines.push({ x: G, y: acTop + qi * 22, text: l.text });
+ }
- // layout
- const gutter = W < 760 ? 20 : GUTTER;
- const gap = W < 760 ? 20 : COL_GAP;
- const totalW = W - gutter * 2;
- const colW = (totalW - gap) / 2;
-
- // headline
- const hlFit = fitHL(totalW, H * 0.12);
- const hlTop = gutter;
- const hlFont = `700 ${hlFit.sz}px ${HL_FAMILY}`;
- const hlH = hlFit.lines.length * hlFit.lh;
-
- // body region
- const bTop = hlTop + hlH + 20;
- const bH = H - bTop - 20;
-
- // circle obstacles
- const circObs = orbs.map(o => ({ cx: o.x, cy: o.y, r: o.r, hPad: 12, vPad: 4 }));
-
- // pullquote rects
- const pqRects = [];
- const pqLineData = [];
- for (let qi = 0; qi < PULLQUOTES.length; qi++) {
- const q = PULLQUOTES[qi];
- const colX = q.col === 0 ? gutter : gutter + colW + gap;
- const pqW = Math.round(colW * q.wFrac);
- const pqX = q.side === 'left' ? colX : colX + colW - pqW;
- const pqY = Math.round(bTop + bH * q.yFrac);
- const r = layoutWithLines(prepPQs[qi], pqW - 16, PQ_LH);
- const pqH = r.lines.length * PQ_LH + 8;
- pqRects.push({ x: pqX - 3, y: pqY, w: pqW + 3, h: pqH, col: q.col, pqX, pqY, pqW, pqH });
- for (let li = 0; li < r.lines.length; li++) {
- pqLineData.push({ x: pqX + 16, y: pqY + li * PQ_LH, text: r.lines[li].text });
- }
- }
+ // ── commit ───────────────────────────────────────────────────────────
+ sync(pools.hl, 2, 'div', 'txt-hl');
+ sync(pools.body, bodyLines.length, 'div', 'txt-line');
+ sync(pools.ey, eyLines.length, 'div', 'txt-eyebrow');
+ sync(pools.ac, acLines.length, 'div', 'txt-accent');
+
+ // headline — set manually, not via applyLines (different font per line could differ later)
+ for (const [idx, ln] of [[0, hl1], [1, hl2]]) {
+ const el = pools.hl[idx];
+ el.textContent = ln.text;
+ el.style.left = ln.x + 'px';
+ el.style.top = ln.y + 'px';
+ el.style.font = hlFit.font;
+ el.style.lineHeight = hlFit.lh + 'px';
+ }
- // drop cap position
- const dcX = gutter, dcY = bTop;
- dropEl.style.left = dcX + 'px';
- dropEl.style.top = dcY + 'px';
-
- // col 0 obstacles: drop cap + col-0 pullquotes
- const obs0 = pqRects.filter(r => r.col === 0).map(r => ({ x: r.x, y: r.y, w: r.w, h: r.h }));
- obs0.push({ x: dcX, y: dcY, w: DROP_W, h: BODY_LINE_HEIGHT * DROP_LINES });
-
- const obs1 = pqRects.filter(r => r.col === 1).map(r => ({ x: r.x, y: r.y, w: r.w, h: r.h }));
-
- const zero = { segmentIndex: 0, graphemeIndex: 0 };
- const { lines: c0, cursor: c1start } = layoutCol(prepBody, zero, gutter, bTop, colW, bH, BODY_LINE_HEIGHT, circObs, obs0);
- const { lines: c1 } = layoutCol(prepBody, c1start, gutter + colW + gap, bTop, colW, bH, BODY_LINE_HEIGHT, circObs, obs1);
- const bodyLines = [...c0, ...c1];
-
- // render headline
- sync(pools.hl, hlFit.lines.length, 'span', 'headline-line');
- applyLines(pools.hl, hlFit.lines.map(l => ({ ...l, x: l.x + gutter, y: l.y + hlTop })), hlFont, hlFit.lh);
-
- // render body
- sync(pools.body, bodyLines.length, 'span', 'line');
- applyLines(pools.body, bodyLines, BODY_FONT, BODY_LINE_HEIGHT);
-
- // render pullquotes
- sync(pools.pq, pqLineData.length, 'span', 'pullquote-line');
- applyLines(pools.pq, pqLineData, PQ_FONT, PQ_LH);
-
- // pullquote bars (left-border visual)
- sync(pools.pqBar, pqRects.length, 'div', 'pullquote-bar');
- for (let i = 0; i < pqRects.length; i++) {
- const el = pools.pqBar[i], r = pqRects[i];
- el.style.left = r.pqX + 'px';
- el.style.top = r.pqY + 'px';
- el.style.height = r.pqH + 'px';
- }
- }
+ applyLines(pools.body, bodyLines, BODY_FONT, BODY_LH);
+ applyLines(pools.ey, eyLines, EY_FONT, 14);
+ applyLines(pools.ac, acLines, AC_FONT, 18);
+ }
- requestAnimationFrame(frame);
- } // end main()
- } // end run()
- </script>
+ requestAnimationFrame(frame);
+ }
+</script>
</body>
</html>
diff --git a/public/nav.js b/public/nav.js
index 66e884844..e163b4285 100644
--- a/public/nav.js
+++ b/public/nav.js
@@ -1,10 +1,75 @@
document.addEventListener('DOMContentLoaded', () => {
const navContainer = document.getElementById('nav-container');
- if (navContainer) {
- fetch('/nav.html')
- .then(response => response.text())
- .then(data => {
- navContainer.innerHTML = data;
- });
+ if (!navContainer) return;
+ fetch('/nav.html')
+ .then(response => response.text())
+ .then(data => {
+ navContainer.innerHTML = data;
+ initDropdowns(navContainer);
+ });
+});
+
+function initDropdowns(root) {
+ const triggers = root.querySelectorAll('.home-nav .nav-trigger');
+ if (!triggers.length) return;
+
+ function closeAll(except) {
+ triggers.forEach((t) => {
+ if (t !== except) t.setAttribute('aria-expanded', 'false');
+ });
}
-});
\ No newline at end of file
+
+ triggers.forEach((trigger) => {
+ trigger.addEventListener('click', (e) => {
+ e.stopPropagation();
+ const open = trigger.getAttribute('aria-expanded') === 'true';
+ closeAll(open ? null : trigger);
+ trigger.setAttribute('aria-expanded', open ? 'false' : 'true');
+ if (!open) {
+ const first = trigger.nextElementSibling?.querySelector('a');
+ first?.focus();
+ }
+ });
+
+ const menu = trigger.nextElementSibling;
+ if (!menu) return;
+ menu.addEventListener('keydown', (e) => {
+ const items = Array.from(menu.querySelectorAll('a'));
+ const idx = items.indexOf(document.activeElement);
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ items[(idx + 1) % items.length]?.focus();
+ } else if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ items[(idx - 1 + items.length) % items.length]?.focus();
+ } else if (e.key === 'Escape') {
+ trigger.setAttribute('aria-expanded', 'false');
+ trigger.focus();
+ }
+ });
+ });
+
+ document.addEventListener('click', (e) => {
+ if (!e.target.closest('.home-nav')) closeAll(null);
+ });
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Escape') closeAll(null);
+ });
+
+ // Auth-aware CTA
+ try {
+ const raw = localStorage.getItem('3dagent:auth-hint');
+ if (raw) {
+ const { authed, name } = JSON.parse(raw);
+ if (authed) {
+ const cta = root.querySelector('#home-nav-cta');
+ if (cta) { cta.textContent = 'Dashboard'; cta.href = '/dashboard'; }
+ const myAgentsLi = root.querySelector('#home-nav-my-agents-li');
+ if (myAgentsLi) myAgentsLi.hidden = false;
+ const userLi = root.querySelector('#home-nav-user-li');
+ const userEl = root.querySelector('#home-nav-user');
+ if (userEl && userLi && name) { userEl.textContent = name; userLi.hidden = false; }
+ }
+ }
+ } catch (_) {}
+}
diff --git a/src/marketplace.js b/src/marketplace.js
index 317e21591..ef6d964e0 100644
--- a/src/marketplace.js
+++ b/src/marketplace.js
@@ -640,15 +640,19 @@ function getAuthToken() {
// ── Boot ──────────────────────────────────────────────────────────────────
-const { Connection, clusterApiUrl } = solanaWeb3;
-const { PhantomWalletAdapter } = solanaWalletAdapterWallets;
-
let solanaConnection;
-let wallet; // Our single wallet adapter instance
+let wallet;
function initWalletAdapter() {
- solanaConnection = new Connection(clusterApiUrl('mainnet-beta'));
- wallet = new PhantomWalletAdapter(); // We'll specifically use Phantom for simplicity
+ try {
+ const { Connection, clusterApiUrl } = solanaWeb3;
+ const { PhantomWalletAdapter } = solanaWalletAdapterWallets;
+ solanaConnection = new Connection(clusterApiUrl('mainnet-beta'));
+ wallet = new PhantomWalletAdapter();
+ } catch (err) {
+ console.warn('[marketplace] Wallet adapter unavailable:', err.message);
+ return;
+ }
// Listen for connection changes
wallet.on('connect', () => {
@@ -666,6 +670,11 @@ function updateWalletUI() {
const walletArea = $('payment-wallet-area');
const confirmBtn = $('payment-confirm-btn');
+ if (!wallet) {
+ walletArea.innerHTML = '<p>Wallet adapter not available.</p>';
+ return;
+ }
+
if (wallet.connected) {
const pubKey = wallet.publicKey.toBase58();
walletArea.innerHTML = `