an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
blog scene kit: tall stage for phones, title scene, flow labels, board fit
chaitanyagiridfe6cd0d4dd7
diff --git a/blog/MG_KIT.md b/blog/MG_KIT.mdindex cd257942..e2552591 100644--- a/blog/MG_KIT.md+++ b/blog/MG_KIT.md@@ -32,9 +32,15 @@ What the kit does for every scene:* After a reader taps, the story stops on its still frame and a "Play again" button appears.* Sends `blog_scene_view` (first time on screen) and `blog_scene_interact` (first tap) to PostHog with `slug` and `scene`, only when `window.posthog` exists.+## Phones++Under 520 px wide a kit scene draws on a tall stage (540 by 720) instead of the wide one (960 by 540): larger type, the content on top, the host and the bubble below. The timeline runs down the page and a flow uses two columns. The kit picks the stage from the width of the figure and swaps when the window changes. `?mgtall=1` forces the tall stage and `?mgtall=0` the wide one. The still image stays 16 by 9; only the live scene is tall.+## Stills-`?mgstill` freezes every scene on its own still frame. `?mgstill=3.5` freezes on second 3.5. Screenshot the figure at 1600 by 900 for the post still and the title image.+`?mgstill` freezes every scene on its own still frame. `?mgstill=3.5` freezes on second 3.5. Screenshot the figure at 1600 by 900 for the post still.++For the title image use the `title` scene, not the first scene of the post, so the top of the post does not show the same picture twice. It is composed for 1600 by 900 and stays readable as a small card on the blog index: keep the title under about 60 characters.## Scenes and their data@@ -42,11 +48,12 @@ Every scene takes `kicker` (the yellow chip) and `title`. `host` is a cast name;| Scene | Data | The reader can || --- | --- | --- |-| `stage` | `script: [{ who, say, point, carry }]`, optional `board: { label, lines }`. Up to 5 lines. `point`: left, right, up-left, up-right, raise. `carry`: a short sign held at the chest | Tap a character to hear the line again |+| `title` | `title` (up to 3 lines of 27 characters), `sub`, `cast: [names]` (2 or 3, default Michael and Jim), `say` (first cast member, under 40 characters) | Nothing to tap, no hint |+| `stage` | `script: [{ who, say, point, carry }]`, optional `board: { label, lines }`. Up to 5 script lines. A board holds 4 lines of 43 characters; with a board, keep each `say` under 68 characters (two bubble lines) so it stays below the board. `point`: left, right, up-left, up-right, raise. `carry`: a short sign held at the chest | Tap a character to hear the line again || `price-ladder` | `prefix`, `suffix`, `items: [{ label, value, display, note, highlight }]`, up to 6 | Tap or hover a step for its note || `compare` | `cols: [a, b]`, `pick` (0 or 1), `rows: [{ label, a, b, win, note }]`, up to 5. `win` is "a", "b" or "" | Tap a row for its note || `timeline` | `events: [{ when, label, note }]`, up to 6 | Tap a date; the host walks to it |-| `flow` | `nodes: [{ label, note }]`, up to 8 (5 or more wrap to two rows), `labels: [text on arrow i]` | Tap a step or use arrow keys |+| `flow` | `nodes: [{ label, note }]`, up to 8 (5 or more wrap to two rows), `labels: [text on arrow i]`, each up to 16 characters, drawn as a tag above the arrow | Tap a step or use arrow keys || `before-after` | `before: { label, lines }`, `after: { label, lines }` | Tap the card to flip it || `counter` | `from`, `to`, `prefix`, `suffix`, `label`, `note` | Tap the number to count again |@@ -80,6 +87,8 @@ A page script registers its own scene with the same tools the kit uses:</script>```+A custom scene always gets the wide stage. To support phones, set `tall: true` on the scene, pass `api.L` to `MG.stage(svg, data, api.L)` and lay out from the layout it returns (`W`, `H`, `x0`, `x1`, `top`, `bot`, `gy`, `hx`, `tall`); `MG.host(svg, L, name)` places the host and the bubble for both.+`draw(t)` must draw the whole frame from the time alone, so stills and reduced motion work. For a tap target use `MG.hit(parent, label, fn)` then `MG.ring(...)`, and call `api.poke(change, ms)` inside `fn`; read `api.ui.k` (0 to 1) in `draw` for the move.## Rulesdiff --git a/blog/src/assets/mg/demo.html b/blog/src/assets/mg/demo.htmlindex 67eebabb..8ab5f421 100644--- a/blog/src/assets/mg/demo.html+++ b/blog/src/assets/mg/demo.html@@ -15,11 +15,17 @@<body><main class="prose"><h1>Blog scene kit: every scene</h1>-<p>Test page for blog/src/assets/mg. The data here is sample data, not facts. Add ?mgstill to freeze each scene on its still frame. Real posts ship a still image in each figure; this page uses an empty one.</p>+<p>Test page for blog/src/assets/mg. The data here is sample data, not facts. Add ?mgstill to freeze each scene on its still frame, and ?mgtall=1 to force the phone layout. Real posts ship a still image in each figure; this page uses an empty one.</p>++<h2>title</h2>+<figure class="mg" data-scene="title"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Title card. Michael, Jim and Pam stand beside the title of the post."><script type="application/json">{"kicker":"Guide","title":"How to run ten coding agents at once","sub":"A sample title card for this test page","cast":["michael","jim","pam"],"say":"Let us begin."}</script><figcaption>title: the title card of a post. Nothing to tap.</figcaption></figure><h2>stage</h2><figure class="mg" data-scene="stage"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Michael walks in and opens, Jim explains, Dwight gives the rule, Kevin carries the number."><script type="application/json">{"kicker":"The cast","title":"Everyone has one job","script":[{"who":"michael","say":"Welcome to the blog. I open and I close."},{"who":"jim","say":"I explain how it works."},{"who":"dwight","say":"Rule one: no red. Ever.","point":"up-left"},{"who":"kevin","say":"I do the numbers.","carry":"$0"}]}</script><figcaption>stage: cast members walk in, stop, point and speak.</figcaption></figure>+<h2>stage, with a board</h2>+<figure class="mg" data-scene="stage"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Michael and Jim stand under a board with four points."><script type="application/json">{"kicker":"Sample board","title":"Four things to know","board":{"label":"In this post","lines":["One: install the app.","Two: pick an agent.","Three: give it a task.","Four: read the diff."]},"script":[{"who":"michael","say":"Four points. I counted them twice to be sure."},{"who":"jim","say":"He did count twice. It is still four."}]}</script><figcaption>stage with a four line board.</figcaption></figure>+<h2>price-ladder</h2><figure class="mg" data-scene="price-ladder"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Four price steps rise from Free to Team while Kevin points at them."><script type="application/json">{"kicker":"Sample prices","title":"What each plan costs a month","prefix":"$","items":[{"label":"Free","value":0,"display":"Free","note":"Free covers one agent."},{"label":"Solo","value":12,"note":"Solo adds five agents."},{"label":"Pro","value":20,"highlight":true,"note":"Pro is the one most people pick."},{"label":"Team","value":45,"note":"Team is per seat."}],"host":"kevin","say":"Pro is the sweet spot."}</script><figcaption>price-ladder: tap a step for its note.</figcaption></figure>@@ -30,10 +36,10 @@<figure class="mg" data-scene="timeline"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Jim walks along a timeline of four dates and says what happened at each."><script type="application/json">{"kicker":"Sample timeline","title":"How the release went","events":[{"when":"May","label":"First build","note":"One agent, one desk."},{"when":"July","label":"Open source","note":"The repo went public."},{"when":"Sept","label":"Pro","note":"The paid plan shipped."},{"when":"Oct","label":"Halloween","note":"Everyone got a costume."}],"host":"jim"}</script><figcaption>timeline: tap a date and Jim walks to it.</figcaption></figure><h2>flow</h2>-<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A four step flow draws itself from Prompt to Review while Pam points at each step."><script type="application/json">{"kicker":"Sample flow","title":"From a prompt to a merged change","nodes":[{"label":"Prompt","note":"You say what you want."},{"label":"Plan","note":"The agent writes a plan first."},{"label":"Code","note":"It edits files in a worktree."},{"label":"Review","note":"You read the diff and merge."}],"labels":["","ok",""],"host":"pam","say":"Four steps. That is all."}</script><figcaption>flow: tap a step, or use the arrow keys.</figcaption></figure>+<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A four step flow draws itself from Prompt to Review while Pam points at each step."><script type="application/json">{"kicker":"Sample flow","title":"From a prompt to a merged change","nodes":[{"label":"Prompt","note":"You say what you want."},{"label":"Plan","note":"The agent writes a plan first."},{"label":"Code","note":"It edits files in a worktree."},{"label":"Review","note":"You read the diff and merge."}],"labels":["send","approve","open a PR"],"host":"pam","say":"Four steps. That is all."}</script><figcaption>flow: tap a step, or use the arrow keys.</figcaption></figure><h2>flow, six steps</h2>-<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A six step flow in two rows."><script type="application/json">{"title":"Six steps wrap onto two rows","nodes":[{"label":"One"},{"label":"Two"},{"label":"Three"},{"label":"Four"},{"label":"Five"},{"label":"Six"}],"host":"pam"}</script><figcaption>flow with six nodes.</figcaption></figure>+<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A six step flow in two rows."><script type="application/json">{"title":"Six steps wrap onto two rows","nodes":[{"label":"One"},{"label":"Two"},{"label":"Three"},{"label":"Four"},{"label":"Five"},{"label":"Six"}],"labels":["","","if tests pass","","retry"],"host":"pam"}</script><figcaption>flow with six nodes.</figcaption></figure><h2>before-after</h2><figure class="mg" data-scene="before-after"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A card with a long vague prompt flips to a short clear one while Dwight points at it."><script type="application/json">{"kicker":"Sample flip","title":"The same request, written twice","before":{"label":"Before","lines":["Could you maybe take a look at the login thing when you get a chance and see if anything seems off with it?"]},"after":{"label":"After","lines":["Find why login fails on Safari.","Show the failing request.","Do not change code yet."]},"host":"dwight","say":"Short orders. Always."}</script><figcaption>before-after: tap the card to flip it.</figcaption></figure>diff --git a/blog/src/assets/mg/kit.css b/blog/src/assets/mg/kit.cssindex 980d019c..fd4950b6 100644--- a/blog/src/assets/mg/kit.css+++ b/blog/src/assets/mg/kit.css@@ -2,6 +2,7 @@.prose figure.mg { margin: 42px 0; }.prose figure.mg img, .mg .mg-svg { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border: 1px solid #1A1320; border-radius: 16px; background: #1A1320; }.mg figcaption { font: 500 13px/1.5 "Space Grotesk", system-ui, sans-serif; color: #6B5878; padding-top: 10px; text-align: center; }+.mg .mg-svg.mg-tall { aspect-ratio: 3 / 4; }.mg .mg-svg { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }.mg .mg-svg text { -webkit-user-select: none; user-select: none; }.mg .mg-svg image { image-rendering: pixelated; }diff --git a/blog/src/assets/mg/kit.js b/blog/src/assets/mg/kit.jsindex 769c6e30..4d4c6e32 100644--- a/blog/src/assets/mg/kit.js+++ b/blog/src/assets/mg/kit.js@@ -3,12 +3,14 @@<script type="application/json"> with the page's own data. This script swaps the still for a live SVGscene (viewBox 960 by 540) that plays only while on screen. Reduced motion keeps one drawn frame."?mgstill=<seconds>" freezes every scene on that frame, "?mgstill" alone on each scene's still frame.+ Under 520 px wide a kit scene uses a tall stage (540 by 720) with larger type and the host below the content.+ "?mgtall=1" forces the tall stage, "?mgtall=0" the wide one.Custom scenes register with (window.MGQ = window.MGQ || []).push((MG) => MG.scene("name", {...})).Guide: blog/MG_KIT.md. */(() => {const NS = "http://www.w3.org/2000/svg";const C = { ink: "#1A1320", ink2: "#251B2E", ink3: "#3D2E4A", faint: "#8E7B9C", soft: "#D9CFE0", line: "#4A3A58", paper: "#FCFAF0", y: "#FFCA54", sky: "#4ECDC4", lilac: "#B197FC", blue: "#6C8EF5", mint: "#6BCF7F" };- const W = 960, H = 540, GROUND = 500, GROT = '"Space Grotesk", system-ui, sans-serif', MONO = '"JetBrains Mono", ui-monospace, monospace';+ const W = 960, H = 540, GROUND = 500, WIDE = { W: 960, H: 540, x0: 60, x1: 704, top: 140, bot: 452, gy: 500, hx: 856, tall: false }, TALL = { W: 540, H: 720, x0: 28, x1: 512, top: 140, bot: 520, gy: 694, hx: 84, tall: true }, GROT = '"Space Grotesk", system-ui, sans-serif', MONO = '"JetBrains Mono", ui-monospace, monospace';const BASE = (document.currentScript && document.currentScript.src ? document.currentScript.src : "/blog/assets/mg/kit.js").replace(/[^/]*$/, "");const clamp = (v) => Math.max(0, Math.min(1, v));const p = (t, a, b) => clamp((t - a) / (b - a));@@ -41,19 +43,25 @@const decimals = (v) => (String(v).split(".")[1] || "").length;// Stage: deep ink panel, a soft glow, a fine grid, a kicker chip and a title.+ // stage(svg, data, layout, glow) returns the layout it drew on, with "top" moved down when the title wraps.let uid = 0;- function stage(svg, data, glow) {- const id = "mg" + ++uid, d = el("defs", {}, svg), gl = glow || [0.5, 0.35];+ function stage(svg, data, a, b) {+ const L = Object.assign({}, a && !Array.isArray(a) ? a : WIDE), gl = Array.isArray(a) ? a : b || [0.5, 0.35];+ const id = "mg" + ++uid, d = el("defs", {}, svg);const g = el("radialGradient", { id: id + "g", cx: gl[0], cy: gl[1], r: 0.75 }, d);el("stop", { offset: 0, "stop-color": "#3A2A4A" }, g);el("stop", { offset: 1, "stop-color": C.ink }, g);const pt = el("pattern", { id: id + "p", width: 48, height: 48, patternUnits: "userSpaceOnUse" }, d);el("path", { d: "M48 0H0V48", fill: "none", stroke: "#FFFFFF", "stroke-opacity": 0.035, "stroke-width": 1 }, pt);- el("rect", { width: W, height: H, fill: `url(#${id}g)` }, svg);- el("rect", { width: W, height: H, fill: `url(#${id}p)` }, svg);- if (data && data.kicker) chip(svg, 60, 36, String(data.kicker).toUpperCase());- if (data && data.title) lines(svg, 60, data.kicker ? 104 : 70, wrap(data.title, 52).slice(0, 2), 27, C.paper, { "font-weight": 600 });- return d;+ el("rect", { width: L.W, height: L.H, fill: `url(#${id}g)` }, svg);+ el("rect", { width: L.W, height: L.H, fill: `url(#${id}p)` }, svg);+ if (data && data.kicker) chip(svg, L.x0, 36, String(data.kicker).toUpperCase());+ if (data && data.title) {+ const y = data.kicker ? 104 : 70, T = wrap(data.title, L.tall ? 30 : 52).slice(0, L.tall ? 3 : 2);+ lines(svg, L.x0, y, T, L.tall ? 25 : 27, C.paper, { "font-weight": 600 }, 32);+ L.top = y + (T.length - 1) * 32 + 36;+ }+ return L;}function floor(svg, x0, x1, y) {el("rect", { x: x0, y: (y || GROUND) - 2, width: x1 - x0, height: 4, rx: 2, fill: C.line }, svg);@@ -136,28 +144,51 @@const walk = (t, t0, t1, x0, x1) => { const k = p(t, t0, t1); return { x: lerp(x0, x1, k), step: k > 0 && k < 1 ? t : 0 }; };// Speech bubble. draw(x, y, k): the tail tip sits at x, y; k from 0 to 1 pops it.- function bubble(parent, max, size) {- const sz = size || 19, mx = max || 24, g = el("g", { opacity: 0 }, parent);+ // side "right" puts the bubble to the right of the tip (tail points left); the default sits above it.+ function bubble(parent, max, size, layout, side) {+ const sz = size || 19, mx = max || 24, L = layout || WIDE, g = el("g", { opacity: 0 }, parent);const r = el("rect", { rx: 14, fill: C.paper }, g), tail = el("path", { fill: C.paper }, g);let t = null, w = 0, h = 0, cur = null;- return {- g,+ const o = {+ g, maxLines: 4,set(s) {if (s === cur) return; cur = s; if (t) t.remove();- const L = wrap(s, mx).slice(0, 4);- w = Math.max.apply(null, L.map((l) => l.length)) * sz * 0.53 + 34; h = L.length * sz * 1.28 + 20;- t = lines(g, 0, 0, L, sz, C.ink, { "font-weight": 600 });+ const T = wrap(s, mx).slice(0, o.maxLines);+ w = Math.max.apply(null, T.map((l) => l.length)) * sz * 0.53 + 34; h = T.length * sz * 1.28 + 20;+ t = lines(g, 0, 0, T, sz, C.ink, { "font-weight": 600 });set(r, { width: w, height: h });},draw(x, y, k) {if (!(k > 0) || !cur) return g.setAttribute("opacity", 0);- const bx = Math.max(12, Math.min(W - 12 - w, x - w / 2)), by = Math.max(8, y - 13 - h), tx = Math.max(bx + 22, Math.min(bx + w - 22, x));+ let bx, by, px = x, py = y;+ if (side === "right") {+ bx = Math.min(L.W - 12 - w, x + 13); by = Math.max(8, Math.min(L.H - 8 - h, y - h / 2));+ tail.setAttribute("d", `M${bx + 1} ${y - 9}L${bx - 13} ${y}L${bx + 1} ${y + 9}z`); px = bx - 13;+ } else {+ bx = Math.max(12, Math.min(L.W - 12 - w, x - w / 2)); by = Math.max(8, y - 13 - h); px = Math.max(bx + 22, Math.min(bx + w - 22, x)); py = by + h + 13;+ tail.setAttribute("d", `M${px - 9} ${by + h - 1}L${px} ${py}L${px + 9} ${by + h - 1}z`);+ }set(r, { x: bx, y: by });set(t, { y: by + 12 + sz });Array.prototype.forEach.call(t.childNodes, (n) => n.setAttribute("x", bx + 17));- tail.setAttribute("d", `M${tx - 9} ${by + h - 1}L${tx} ${by + h + 13}L${tx + 9} ${by + h - 1}z`);- const sc = back(clamp(k));- set(g, { opacity: Math.min(1, k * 3), transform: `translate(${tx} ${by + h + 13}) scale(${sc}) translate(${-tx} ${-(by + h + 13)})` });+ set(g, { opacity: Math.min(1, k * 3), transform: `translate(${px} ${py}) scale(${back(clamp(k))}) translate(${-px} ${-py})` });+ },+ };+ return o;+ }++ // The host of a data scene: walks in, points at the content and speaks.+ // Wide stage: stands on the right, bubble above. Tall stage: stands below the content, bubble beside.+ function host(svg, L, name) {+ const who = actor(svg, name), bub = bubble(svg, L.tall ? 30 : 18, 19, L, L.tall ? "right" : "");+ return {+ who, bub,+ // o: arm, hop, bob (as actor.draw). line: what the host says. k: bubble pop, 0 to 1.+ draw(t, o, line, k) {+ const wk = walk(t, 0.2, 1.4, L.tall ? -60 : L.W + 50, L.hx), arm = o.arm && o.arm !== "raise" && L.tall ? "up-right" : o.arm;+ who.draw({ x: wk.x, y: L.gy, step: wk.step, arm: wk.step ? "" : arm, hop: o.hop, bob: o.bob });+ bub.set(line || "");+ if (L.tall) bub.draw(L.hx + 44, L.gy - 70, line ? k : 0); else bub.draw(L.hx, L.gy - who.top - 4, line ? k : 0);},};}@@ -175,35 +206,37 @@}// Call after the group has its content: adds the hit area and the focus ring on top.const ring = (g, x, y, w, h, rx) => el("rect", { x, y, width: w, height: h, rx: rx == null ? 12 : rx, fill: "#fff", "fill-opacity": 0, stroke: C.y, "stroke-width": 3, class: "mg-ring" }, g);- const hint = (svg, s) => txt(svg, W - 28, 42, s, 13, C.faint, { "text-anchor": "end", "font-weight": 600, "letter-spacing": "0.08em", class: "mg-hint" });+ const hint = (svg, s, L) => txt(svg, (L || WIDE).W - 28, 42, s, 13, C.faint, { "text-anchor": "end", "font-weight": 600, "letter-spacing": "0.08em", class: "mg-hint" });+ const step = (i, n, key, fwd) => Math.max(0, Math.min(n - 1, i + (fwd.includes(key) ? 1 : -1)));const SCENES = {};/* price-ladder. data: { kicker, title, prefix, suffix, items: [{ label, value, display, note, highlight }], host, say } */SCENES["price-ladder"] = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.4]);+ const L = stage(svg, data, api.L, [0.35, 0.4]);const items = (data.items || []).slice(0, 6), n = items.length || 1, max = Math.max.apply(null, items.map((i) => +i.value || 0)) || 1;- const x0 = 60, x1 = 704, gap = 18, bw = (x1 - x0 - gap * (n - 1)) / n, base = 452, tall = 240, dec = Math.max.apply(null, items.map((i) => decimals(i.value)));- const T = 1.2 + n * 0.28 + 0.6, say0 = data.say || "";+ const x0 = L.x0, x1 = L.x1, gap = L.tall ? 10 : 18, bw = (x1 - x0 - gap * (n - 1)) / n, base = L.bot, tall = Math.min(240, base - L.top - 56), dec = Math.max.apply(null, items.map((i) => decimals(i.value)));+ const T = 1.2 + n * 0.28 + 0.6, hi = items.findIndex((i) => i.highlight);floor(svg, x0, x1, base + 2);- let sel = -1, hi = items.findIndex((i) => i.highlight);+ let sel = -1;const fmt = (it, v) => (it.display != null ? it.display : (data.prefix || "") + num(v, dec) + (data.suffix || ""));const bars = items.map((it, i) => {const x = x0 + i * (bw + gap), h = Math.max(26, (tall * (+it.value || 0)) / max);const g = hit(svg, `${it.label}: ${fmt(it, it.value)}${it.note ? ". " + it.note : ""}`, (key) => {- if (key && key.startsWith("Arrow")) { const j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowUp" ? 1 : -1))); bars[j].g.focus(); return api.poke(() => { sel = j; }); }+ if (key && key.startsWith("Arrow")) { const j = step(i, n, key, ["ArrowRight", "ArrowUp"]); bars[j].g.focus(); return api.poke(() => { sel = j; }); }if (key === "hover" && sel === i) return;api.poke(() => { sel = i; });});const r = el("rect", { x, width: bw, rx: 8 }, g);- const v = txt(g, x + bw / 2, 0, "", 21, C.paper, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });+ const v = txt(g, x + bw / 2, 0, "", Math.min(21, bw / 3.4), C.paper, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });lines(g, x + bw / 2, base + 26, wrap(it.label, Math.max(6, Math.floor(bw / 8.4))).slice(0, 2), 14.5, C.soft, { "text-anchor": "middle", "font-weight": 600 }, 17);ring(g, x - 4, base - tall - 44, bw + 8, tall + 92);return { g, r, v, h, x, it };});- const who = actor(svg, data.host || "kevin"), bub = bubble(svg, 18);- hint(svg, "TAP A STEP");+ const Hs = host(svg, L, data.host || "kevin");+ hint(svg, "TAP A STEP", L);const draw = (t) => {bars.forEach((b, i) => {const k = p(t, 0.5 + i * 0.28, 1.15 + i * 0.28), h = b.h * Math.max(0.02, back(k)), on = sel >= 0 ? sel === i : i === hi && t > T - 0.5;@@ -211,10 +244,8 @@b.v.textContent = fmt(b.it, (+b.it.value || 0) * out(k));set(b.v, { y: base - h - 12, opacity: p(t, 0.5 + i * 0.28, 0.8 + i * 0.28), fill: on ? C.y : C.paper });});- const wk = walk(t, 0.2, 1.5, W + 50, 856), land = sel >= 0 ? api.ui.k : p(t, T, T + 0.4);- who.draw({ x: wk.x, step: wk.step, arm: t > 1.6 ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T - 0.1, T + 0.35), bob: t > T && Math.floor(t * 5) % 2 });- const line = sel >= 0 ? items[sel].note || `${items[sel].label}: ${fmt(items[sel], items[sel].value)}` : say0;- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? land : 0);+ const line = sel >= 0 ? items[sel].note || `${items[sel].label}: ${fmt(items[sel], items[sel].value)}` : data.say;+ Hs.draw(t, { arm: t > 1.6 ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T - 0.1, T + 0.35), bob: t > T && Math.floor(t * 5) % 2 }, line, sel >= 0 ? api.ui.k : p(t, T, T + 0.4));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -222,51 +253,50 @@/* compare. data: { kicker, title, cols: [a, b], pick (0 or 1), rows: [{ label, a, b, win ("a", "b" or ""), note }], host, say } */SCENES.compare = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.3, 0.45]);- const rows = (data.rows || []).slice(0, 5), n = rows.length, cols = data.cols || ["A", "B"], pick = data.pick;- const cx = [60, 282, 494], cw = [214, 204, 204], top = 150, rh = Math.min(58, 290 / Math.max(1, n)), T = 1.0 + n * 0.5 + 0.5;+ const L = stage(svg, data, api.L, [0.3, 0.45]);+ const rows = (data.rows || []).slice(0, 5), n = rows.length, cols = data.cols || ["A", "B"], pick = data.pick, f = L.tall ? 15 : 17;+ const lw = (L.x1 - L.x0) * (L.tall ? 0.3 : 0.34), cw = (L.x1 - L.x0 - lw) / 2, cx = [L.x0, L.x0 + lw, L.x0 + lw + cw], top = L.top + 10;+ const rh = Math.min(L.tall ? 66 : 58, (L.bot - top - 36) / Math.max(1, n)), T = 1.0 + n * 0.5 + 0.5, mc = Math.floor((cw - 30) / (f * 0.56)), cut = (v, m) => String(v == null ? "" : v).slice(0, m);let sel = -1;const heads = cols.slice(0, 2).map((c, i) => {const g = el("g", {}, svg);- el("rect", { x: cx[i + 1], y: top - 14, width: cw[i + 1], height: 40, rx: 10, fill: pick === i ? C.y : C.ink3 }, g);- txt(g, cx[i + 1] + cw[i + 1] / 2, top + 13, String(c).slice(0, 20), 17, pick === i ? C.ink : C.paper, { "text-anchor": "middle", "font-weight": 700 });+ el("rect", { x: cx[i + 1] + 4, y: top - 14, width: cw - 8, height: 40, rx: 10, fill: pick === i ? C.y : C.ink3 }, g);+ txt(g, cx[i + 1] + cw / 2, top + 13, cut(c, mc + 2), f, pick === i ? C.ink : C.paper, { "text-anchor": "middle", "font-weight": 700 });return g;});const R = rows.map((r, i) => {const y = top + 40 + i * rh;const g = hit(svg, `${r.label}. ${cols[0]}: ${r.a}. ${cols[1]}: ${r.b}.${r.note ? " " + r.note : ""}`, (key) => {- if (key && key.startsWith("Arrow")) { const j = Math.max(0, Math.min(n - 1, i + (key === "ArrowDown" || key === "ArrowRight" ? 1 : -1))); R[j].g.focus(); return api.poke(() => { sel = j; }); }+ if (key && key.startsWith("Arrow")) { const j = step(i, n, key, ["ArrowRight", "ArrowDown"]); R[j].g.focus(); return api.poke(() => { sel = j; }); }if (key === "hover" && sel === i) return;api.poke(() => { sel = i; });});- const bg = el("rect", { x: 52, y: y + 3, width: 654, height: rh - 6, rx: 10, fill: C.ink2 }, g);- txt(g, cx[0] + 10, y + rh / 2 + 6, String(r.label).slice(0, 24), 17, C.soft, { "font-weight": 600 });- const cells = ["a", "b"].map((k, j) => {- const won = r.win === k;- const t = txt(g, cx[j + 1] + cw[j + 1] / 2 + (won ? 10 : 0), y + rh / 2 + 6, String(r[k] == null ? "" : r[k]).slice(0, 22), 17, won ? C.y : C.paper, { "text-anchor": "middle", "font-weight": won ? 700 : 500 });- const half = String(r[k] == null ? "" : r[k]).slice(0, 22).length * 4.9 + 4;- const tick = won ? el("path", { d: `M${cx[j + 1] + cw[j + 1] / 2 - half - 16} ${y + rh / 2}l6 6 11-12`, fill: "none", stroke: C.y, "stroke-width": 3.5, "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-dasharray": 26 }, g) : null;- return { t, tick };+ const bg = el("rect", { x: L.x0 - 8, y: y + 3, width: L.x1 - L.x0 + 16, height: rh - 6, rx: 10, fill: C.ink2 }, g);+ const lab = wrap(r.label, Math.floor((lw - 6) / (f * 0.54))).slice(0, 2);+ lines(g, cx[0] + 4, y + rh / 2 + 6 - (lab.length - 1) * f * 0.6, lab, f, C.soft, { "font-weight": 600 }, f * 1.2);+ const ticks = ["a", "b"].map((k, j) => {+ const won = r.win === k, s = cut(r[k], won ? mc - 2 : mc), mid = cx[j + 1] + cw / 2;+ txt(g, mid + (won ? 10 : 0), y + rh / 2 + 6, s, f, won ? C.y : C.paper, { "text-anchor": "middle", "font-weight": won ? 700 : 500 });+ return won ? el("path", { d: `M${mid - s.length * f * 0.29 - 20} ${y + rh / 2}l6 6 11-12`, fill: "none", stroke: C.y, "stroke-width": 3.5, "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-dasharray": 26 }, g) : null;});- ring(g, 52, y + 3, 654, rh - 6, 10);- return { g, bg, cells };+ ring(g, L.x0 - 8, y + 3, L.x1 - L.x0 + 16, rh - 6, 10);+ return { g, bg, ticks };});- const who = actor(svg, data.host || "oscar"), bub = bubble(svg, 18);- hint(svg, "TAP A ROW");+ const Hs = host(svg, L, data.host || "oscar");+ hint(svg, "TAP A ROW", L);const draw = (t) => {heads.forEach((g, i) => { const k = back(p(t, 0.3 + i * 0.15, 0.75 + i * 0.15)); set(g, { opacity: clamp(k * 2), transform: `translate(0 ${(1 - k) * -18})` }); });R.forEach((r, i) => {const a = 1.0 + i * 0.5, k = out(p(t, a, a + 0.4));set(r.g, { opacity: k, transform: `translate(${(1 - k) * -40} 0)` });set(r.bg, { fill: sel === i ? C.ink3 : C.ink2 });- r.cells.forEach((c) => c.tick && set(c.tick, { "stroke-dashoffset": 26 * (1 - out(p(t, a + 0.3, a + 0.6))) }));+ r.ticks.forEach((c) => c && set(c, { "stroke-dashoffset": 26 * (1 - out(p(t, a + 0.3, a + 0.6))) }));});- const wk = walk(t, 0.2, 1.4, W + 50, 856);const cur = Math.min(n - 1, Math.floor((t - 1.0) / 0.5));- who.draw({ x: wk.x, step: wk.step, arm: t > 1.5 && (sel >= 0 || t < T) ? (cur % 2 ? "left" : "up-left") : t >= T ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) });- const line = sel >= 0 ? rows[sel].note || `${rows[sel].label}: ${rows[sel].win === "b" ? cols[1] : rows[sel].win === "a" ? cols[0] : "a tie"}` : data.say || "";- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? (sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5)) : 0);+ const line = sel >= 0 ? rows[sel].note || `${rows[sel].label}: ${rows[sel].win === "b" ? cols[1] : rows[sel].win === "a" ? cols[0] : "a tie"}` : data.say;+ Hs.draw(t, { arm: t > 1.5 ? (sel < 0 && t < T && cur % 2 ? "left" : "up-left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) }, line, sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -274,45 +304,60 @@/* timeline. data: { kicker, title, events: [{ when, label, note }], host } */SCENES.timeline = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.5, 0.6]);- const ev = (data.events || []).slice(0, 6), n = ev.length || 1, y = 392, xa = 100, xb = 860, X = (i) => (n === 1 ? (xa + xb) / 2 : lerp(xa, xb, i / (n - 1)));- const HOP = 0.9, STAY = 1.7, T0 = 1.0, at = (i) => T0 + i * (HOP + STAY) + HOP, T = at(n - 1) + STAY;- el("rect", { x: xa - 30, y: y - 2, width: xb - xa + 60, height: 4, rx: 2, fill: C.line }, svg);- const prog = el("rect", { x: xa - 30, y: y - 2, height: 4, rx: 2, fill: C.y }, svg);+ const L = stage(svg, data, api.L, [0.5, 0.6]);+ const ev = (data.events || []).slice(0, 6), n = ev.length || 1, HOP = 0.9, STAY = 1.7, T0 = 1.0, at = (i) => T0 + i * (HOP + STAY) + HOP, T = at(n - 1) + STAY;+ // a, b: the two ends of the line. wide: across. tall: down.+ const a = L.tall ? L.top + 24 : 100, b = L.tall ? L.bot - 34 : 860, P = (v) => (n === 1 ? (a + b) / 2 + v * 120 : lerp(a, b, v / (n - 1)));+ const y = Math.max(392, L.top + 252), x = L.x0 + 18, gapN = n > 1 ? (b - a) / (n - 1) : 170;+ el("rect", L.tall ? { x: x - 2, y: a - 26, width: 4, height: b - a + 52, rx: 2, fill: C.line } : { x: a - 30, y: y - 2, width: b - a + 60, height: 4, rx: 2, fill: C.line }, svg);+ const prog = el("rect", L.tall ? { x: x - 2, y: a - 26, width: 4, rx: 2, fill: C.y } : { x: a - 30, y: y - 2, height: 4, rx: 2, fill: C.y }, svg);let sel = -1, from = 0;const dots = ev.map((e, i) => {- const x = X(i), cw = Math.min(170, (xb - xa) / Math.max(1, n - 1) - 14 || 170);+ const q = P(i);const g = hit(svg, `${e.when}: ${e.label}${e.note ? ". " + e.note : ""}`, (key) => {let j = i;- if (key && key.startsWith("Arrow")) { j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowDown" ? 1 : -1))); dots[j].g.focus(); }+ if (key && key.startsWith("Arrow")) { j = step(i, n, key, ["ArrowRight", "ArrowDown"]); dots[j].g.focus(); }if (key === "hover") return;- api.poke(() => { from = sel >= 0 ? sel : n - 1; sel = j; }, 500);+ api.poke(() => { from = sel >= 0 ? sel : Math.min(n - 1, 1); sel = j; }, 500);});- const c = el("circle", { cx: x, cy: y, r: 11, stroke: C.ink, "stroke-width": 4 }, g);- const w = txt(g, x, y + 38, String(e.when).slice(0, 14), 15, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });- const l = lines(g, x, y + 62, wrap(e.label, Math.max(8, Math.floor(cw / 8))).slice(0, 3), 15, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 19);- ring(g, x - cw / 2, y - 22, cw, 150);- return { g, c, w, l, x };+ let c, w, l;+ if (L.tall) {+ c = el("circle", { cx: x, cy: q, r: 11, stroke: C.ink, "stroke-width": 4 }, g);+ w = txt(g, x + 30, q - 3, String(e.when).slice(0, 22), 16, C.y, { "font-family": MONO, "font-weight": 700 });+ l = lines(g, x + 30, q + 19, wrap(e.label, 44).slice(0, gapN > 82 ? 2 : 1), 16, C.paper, { "font-weight": 600 }, 20);+ ring(g, L.x0 - 6, q - 24, L.x1 - L.x0 + 12, Math.min(70, gapN - 6));+ } else {+ const cw = Math.min(170, gapN - 14);+ c = el("circle", { cx: q, cy: y, r: 11, stroke: C.ink, "stroke-width": 4 }, g);+ w = txt(g, q, y + 38, String(e.when).slice(0, 14), 15, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });+ l = lines(g, q, y + 62, wrap(e.label, Math.max(8, Math.floor(cw / 8))).slice(0, 3), 15, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 19);+ ring(g, q - cw / 2, y - 22, cw, 150);+ }+ return { g, c, w, l };});- const who = actor(svg, data.host || "jim"), bub = bubble(svg, 26, 18);- hint(svg, "TAP A DATE");+ const mark = L.tall ? el("circle", { cx: x, r: 7, fill: C.paper, stroke: C.ink, "stroke-width": 3 }, svg) : null;+ const Hs = L.tall ? host(svg, L, data.host || "jim") : null, who = L.tall ? null : actor(svg, data.host || "jim"), bub = L.tall ? null : bubble(svg, 26, 18, L);+ hint(svg, "TAP A DATE", L);const draw = (t) => {- let x, step = 0, cur = -1, k = 0;- if (sel >= 0) { const m = io(api.ui.k); x = lerp(X(from), X(sel), m); step = api.ui.k < 1 ? api.ui.k * 0.9 : 0; cur = sel; k = p(api.ui.k, 0.7, 1); }- else {- x = xa - 80;- for (let i = 0; i < n; i++) { const a = at(i) - HOP, w = walk(t, a, at(i), i ? X(i - 1) : xa - 80, X(i)); if (t >= a) { x = w.x; step = w.step; if (t >= at(i)) { cur = i; k = Math.min(p(t, at(i), at(i) + 0.35), 1 - p(t, at(i) + STAY - 0.3, at(i) + STAY - 0.05) * (i < n - 1 ? 1 : 0)); } } }+ let v = -0.6, st = 0, cur = -1, k = 0;+ if (sel >= 0) { v = lerp(from, sel, io(api.ui.k)); st = api.ui.k < 1 ? api.ui.k * 0.9 : 0; cur = sel; k = p(api.ui.k, 0.7, 1); }+ else for (let i = 0; i < n; i++) {+ const s0 = at(i) - HOP; if (t < s0) break;+ const m = p(t, s0, at(i)); v = lerp(i ? i - 1 : -0.6, i, m); st = m > 0 && m < 1 ? t : 0;+ if (t >= at(i)) { cur = i; k = Math.min(p(t, at(i), at(i) + 0.35), 1 - p(t, at(i) + STAY - 0.3, at(i) + STAY - 0.05) * (i < n - 1 ? 1 : 0)); }}- set(prog, { width: Math.max(0, x - (xa - 30)) });+ const q = P(v);+ set(prog, L.tall ? { height: Math.max(0, q - (a - 26)) } : { width: Math.max(0, q - (a - 30)) });dots.forEach((d, i) => {- const seen = sel >= 0 ? true : t >= at(i), pop = sel >= 0 ? 1 : back(p(t, at(i) - 0.1, at(i) + 0.3)), on = cur === i;- set(d.c, { r: 8 + 5 * pop + (on ? 3 : 0), fill: seen ? C.y : C.line });+ const seen = sel >= 0 ? true : t >= at(i), pop = sel >= 0 ? 1 : back(p(t, at(i) - 0.1, at(i) + 0.3));+ set(d.c, { r: 8 + 5 * pop + (cur === i ? 3 : 0), fill: seen ? C.y : C.line });set(d.w, { opacity: seen ? 1 : 0.35 }); set(d.l, { opacity: seen ? 1 : 0.35 });});- who.draw({ x, y: y - 18, step, bob: cur >= 0 && !step && Math.floor(t * 5) % 2 && sel < 0 });- const line = cur >= 0 ? ev[cur].note || ev[cur].label : "";- bub.set(line); bub.draw(x, y - 18 - who.top - 2, line ? k : 0);+ const line = cur >= 0 ? ev[cur].note || ev[cur].label : "", talk = cur >= 0 && !st && sel < 0 && Math.floor(t * 5) % 2;+ if (L.tall) { set(mark, { cy: Math.max(a - 26, q) }); Hs.draw(t, { arm: cur >= 0 ? "up-right" : "", bob: talk, hop: sel >= 0 ? api.ui.k : 0 }, line, k); }+ else { who.draw({ x: q, y: y - 18, step: st, bob: talk }); bub.set(line); bub.draw(q, y - 18 - who.top - 2, line ? k : 0); }};return { draw, dur: T + 1.2, still: at(Math.min(n - 1, 1)) + 0.8 };},@@ -320,42 +365,53 @@/* flow. data: { kicker, title, nodes: [{ label, note }], labels: [text on the arrow after node i], host, say } */SCENES.flow = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.4, 0.5]);- const nodes = (data.nodes || []).slice(0, 8), n = nodes.length || 1, per = n <= 4 ? n : Math.ceil(n / 2), bw = n <= 4 ? Math.min(190, (644 - (n - 1) * 34) / n) : 140, bh = n <= 4 ? 108 : 76, gap = per > 1 ? (644 - per * bw) / (per - 1) : 0;- const pos = nodes.map((_, i) => { const row = i < per ? 0 : 1, col = row ? per - 1 - (i - per) : i; return { x: 60 + col * (bw + gap), y: n <= 4 ? 186 : row ? 330 : 176 }; });+ const L = stage(svg, data, api.L, [0.4, 0.5]);+ const nodes = (data.nodes || []).slice(0, 8), n = nodes.length || 1, Wd = L.x1 - L.x0;+ const per = L.tall ? Math.min(2, n) : n <= 4 ? n : Math.ceil(n / 2), rows = Math.ceil(n / per);+ const bw = L.tall ? (per > 1 ? (Wd - 64) / 2 : Wd) : n <= 4 ? Math.min(190, (Wd - (n - 1) * 34) / n) : 140, bh = rows === 1 ? 108 : L.tall ? 70 : 76;+ const gapX = per > 1 ? (Wd - per * bw) / (per - 1) : 0, y0 = L.top + (rows === 1 ? 46 : 30), stepY = rows > 1 ? Math.min(154, (L.bot - y0 - bh) / (rows - 1)) : 0;+ // rows snake: left to right, then right to left+ const pos = nodes.map((_, i) => { const r = Math.floor(i / per), c = i % per; return { x: L.x0 + (r % 2 ? per - 1 - c : c) * (bw + gapX), y: y0 + r * stepY }; });const STEP = 1.1, T0 = 0.8, T = T0 + n * STEP;let sel = -1, from = 0;const edges = pos.slice(0, -1).map((a, i) => {- const b = pos[i + 1], down = a.y !== b.y, dir = b.x > a.x ? 1 : -1;- const d = down ? `M${a.x + bw / 2} ${a.y + bh}V${b.y - 8}` : `M${dir > 0 ? a.x + bw : a.x} ${a.y + bh / 2}H${dir > 0 ? b.x - 8 : b.x + bw + 8}`;- const path = el("path", { d, fill: "none", stroke: C.paper, "stroke-width": 2.5, "stroke-linecap": "round" }, svg);- const len = down ? b.y - 8 - a.y - bh : Math.abs((dir > 0 ? b.x - 8 : b.x + bw + 8) - (dir > 0 ? a.x + bw : a.x));+ const b = pos[i + 1], down = a.y !== b.y, dir = b.x > a.x ? 1 : -1, xa = dir > 0 ? a.x + bw : a.x, xb = dir > 0 ? b.x - 8 : b.x + bw + 8;+ const path = el("path", { d: down ? `M${a.x + bw / 2} ${a.y + bh}V${b.y - 8}` : `M${xa} ${a.y + bh / 2}H${xb}`, fill: "none", stroke: C.paper, "stroke-width": 2.5, "stroke-linecap": "round" }, svg);+ const len = down ? b.y - 8 - a.y - bh : Math.abs(xb - xa);path.setAttribute("stroke-dasharray", len);- const tip = down ? `M${a.x + bw / 2 - 6} ${b.y - 12}l6 8 6-8z` : dir > 0 ? `M${b.x - 12} ${a.y + bh / 2 - 6}l8 6-8 6z` : `M${b.x + bw + 12} ${a.y + bh / 2 - 6}l-8 6 8 6z`;- const head = el("path", { d: tip, fill: C.paper }, svg);- const lab = (data.labels || [])[i];- const lt = lab ? txt(svg, down ? a.x + bw / 2 + 12 : (a.x + b.x + bw) / 2, down ? (a.y + bh + b.y) / 2 + 5 : a.y + bh / 2 - 12, String(lab).slice(0, 12), 13, C.y, { "text-anchor": down ? "start" : "middle", "font-weight": 700 }) : null;- return { path, head, len, lt };+ const head = el("path", { d: down ? `M${a.x + bw / 2 - 6} ${b.y - 12}l6 8 6-8z` : dir > 0 ? `M${b.x - 12} ${a.y + bh / 2 - 6}l8 6-8 6z` : `M${b.x + bw + 12} ${a.y + bh / 2 - 6}l-8 6 8 6z`, fill: C.paper }, svg);+ return { path, head, len, down, a, b, xa, xb };});const B = nodes.map((nd, i) => {const q = pos[i];const g = hit(svg, `Step ${i + 1} of ${n}: ${nd.label}${nd.note ? ". " + nd.note : ""}`, (key) => {let j = i;- if (key && key.startsWith("Arrow")) { j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowDown" ? 1 : -1))); B[j].g.focus(); }+ if (key && key.startsWith("Arrow")) { j = step(i, n, key, ["ArrowRight", "ArrowDown"]); B[j].g.focus(); }if (key === "hover") return;api.poke(() => { from = sel >= 0 ? sel : n - 1; sel = j; });});const r = el("rect", { x: q.x, y: q.y, width: bw, height: bh, rx: 14, fill: C.ink2, "stroke-width": 2.5 }, g);const no = txt(g, q.x + 12, q.y + 20, String(i + 1), 12, C.faint, { "font-family": MONO, "font-weight": 700 });- const L = wrap(nd.label, Math.max(7, Math.floor(bw / 9.4))).slice(0, 2);- lines(g, q.x + bw / 2, q.y + bh / 2 + (L.length > 1 ? -2 : 7), L, 16.5, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 20);+ const T2 = wrap(nd.label, Math.max(7, Math.floor(bw / 9.4))).slice(0, 2);+ lines(g, q.x + bw / 2, q.y + bh / 2 + (T2.length > 1 ? -2 : 7), T2, 16.5, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 20);ring(g, q.x - 4, q.y - 4, bw + 8, bh + 8, 16);return { g, r, no };});+ // Arrow labels go on last, above the row, so a neighbouring box never covers them.+ edges.forEach((e, i) => {+ const lab = (data.labels || [])[i];+ if (!lab) return;+ const s = String(lab).slice(0, 16), g = (e.lg = el("g", {}, svg)), w = s.length * 7.4 + 14;+ const cx = e.down ? e.a.x + bw / 2 + 12 + w / 2 : (e.xa + e.xb) / 2, cy = e.down ? (e.a.y + bh + e.b.y) / 2 - 2 : e.a.y - 14;+ el("rect", { x: cx - w / 2, y: cy - 11, width: w, height: 22, rx: 11, fill: C.ink, stroke: C.y, "stroke-width": 1.5 }, g);+ txt(g, cx, cy + 4.5, s, 13, C.y, { "text-anchor": "middle", "font-weight": 700 });+ if (!e.down) el("path", { d: `M${cx} ${cy + 11}V${e.a.y + bh / 2 - 6}`, stroke: C.y, "stroke-width": 1.5, "stroke-dasharray": "3 3" }, g);+ });const dot = el("circle", { r: 9, fill: C.y, stroke: C.ink, "stroke-width": 3 }, svg);- const who = actor(svg, data.host || "pam"), bub = bubble(svg, 18);- hint(svg, "TAP A STEP");+ const Hs = host(svg, L, data.host || "pam");+ hint(svg, "TAP A STEP", L);const ctr = (i) => ({ x: pos[i].x + bw / 2, y: pos[i].y - 2 });const draw = (t) => {const cur = sel >= 0 ? sel : Math.min(n - 1, Math.floor((t - T0) / STEP));@@ -366,16 +422,13 @@});edges.forEach((e, i) => {const a = T0 + i * STEP + 0.25, k = sel >= 0 ? 1 : io(p(t, a, a + 0.5));- set(e.path, { "stroke-dashoffset": e.len * (1 - k) }); set(e.head, { opacity: p(k, 0.9, 1) }); if (e.lt) set(e.lt, { opacity: k });+ set(e.path, { "stroke-dashoffset": e.len * (1 - k) }); set(e.head, { opacity: p(k, 0.9, 1) }); if (e.lg) set(e.lg, { opacity: k });});- let dx, dy;- if (sel >= 0) { const a = ctr(from), b = ctr(sel), m = io(api.ui.k); dx = lerp(a.x, b.x, m); dy = lerp(a.y, b.y, m) - hopY(api.ui.k) * 26; }- else { const i = Math.max(0, cur), a = ctr(Math.max(0, i - 1)), b = ctr(i), m = io(p(t, T0 + i * STEP - 0.3, T0 + i * STEP + 0.2)); dx = lerp(a.x, b.x, m); dy = lerp(a.y, b.y, m) - hopY(m) * 26; }- set(dot, { cx: dx, cy: dy, opacity: t >= T0 - 0.2 || sel >= 0 ? 1 : 0 });- const wk = walk(t, 0.1, 1.2, W + 50, 856);- who.draw({ x: wk.x, step: wk.step, arm: t > 1.3 ? (t < T || sel >= 0 ? "up-left" : "left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) });- const line = sel >= 0 ? nodes[sel].note || nodes[sel].label : data.say || "";- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? (sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5)) : 0);+ let A, Bq, m;+ if (sel >= 0) { A = ctr(from); Bq = ctr(sel); m = io(api.ui.k); }+ else { const i = Math.max(0, cur); A = ctr(Math.max(0, i - 1)); Bq = ctr(i); m = io(p(t, T0 + i * STEP - 0.3, T0 + i * STEP + 0.2)); }+ set(dot, { cx: lerp(A.x, Bq.x, m), cy: lerp(A.y, Bq.y, m) - hopY(m) * 22, opacity: t >= T0 - 0.2 || sel >= 0 ? 1 : 0 });+ Hs.draw(t, { arm: t > 1.5 ? (t < T || sel >= 0 ? "up-left" : "left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) }, sel >= 0 ? nodes[sel].note || nodes[sel].label : data.say, sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -383,36 +436,33 @@/* before-after. data: { kicker, title, before: { label, lines: [] }, after: { label, lines: [] }, host, say } */SCENES["before-after"] = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.5]);- const bx = 60, by = 140, bw = 644, bh = 318, mid = bx + bw / 2;+ const L = stage(svg, data, api.L, [0.35, 0.5]);+ const bx = L.x0, by = L.top, bw = L.x1 - L.x0, bh = L.bot - L.top + 6, mid = bx + bw / 2, chars = Math.floor((bw - 56) / 14.6);let side = 1, flips = 0;const card = hit(svg, "Flip between before and after", (key) => { if (key === "hover") return; api.poke(() => { side = 1 - side; flips++; }, 420); });const face = (d, after) => {const g = el("g", {}, card), rows = [];el("rect", { x: bx, y: by, width: bw, height: bh, rx: 18, fill: after ? C.paper : C.ink2, stroke: after ? C.y : C.line, "stroke-width": after ? 4 : 2 }, g);chip(g, bx + 24, by + 22, String((d && d.label) || (after ? "After" : "Before")).toUpperCase(), after ? C.y : C.soft);- ((d && d.lines) || []).forEach((s) => wrap(s, 36).forEach((l) => rows.push(l)));- const lh = Math.min(42, 222 / Math.max(1, rows.length));- lines(g, bx + 28, by + 98, rows.slice(0, 9), Math.min(27, lh * 0.66), after ? C.ink : C.soft, { "font-weight": after ? 600 : 500 }, lh);+ ((d && d.lines) || []).forEach((s) => wrap(s, chars).forEach((l) => rows.push(l)));+ const lh = Math.min(42, (bh - 96) / Math.max(1, rows.length));+ lines(g, bx + 28, by + 98, rows.slice(0, 10), Math.min(27, lh * 0.66), after ? C.ink : C.soft, { "font-weight": after ? 600 : 500 }, lh);return g;};const A = face(data.before, 0), Bf = face(data.after, 1);ring(card, bx, by, bw, bh, 18);- const who = actor(svg, data.host || "dwight"), bub = bubble(svg, 18);- hint(svg, "TAP THE CARD TO FLIP");+ const Hs = host(svg, L, data.host || "dwight");+ hint(svg, L.tall ? "TAP THE CARD" : "TAP THE CARD TO FLIP", L);const F1 = 3.2, F2 = 8.2, D = 0.6;const draw = (t) => {// m runs 0 (before) to 1 (after)- let m;- if (flips) m = lerp(1 - side, side, io(api.ui.k));- else m = io(p(t, F1, F1 + D)) - io(p(t, F2, F2 + D));- const sx = Math.abs(Math.cos(m * Math.PI)), showAfter = m > 0.5;- A.setAttribute("display", showAfter ? "none" : "inline"); Bf.setAttribute("display", showAfter ? "inline" : "none");- set(card, { transform: `translate(${mid} 0) scale(${Math.max(0.02, sx)} 1) translate(${-mid} 0)` });- const wk = walk(t, 0.2, 1.4, W + 50, 856), land = flips ? (side ? api.ui.k : 0) : Math.min(p(t, F1 + D, F1 + D + 0.4), 1 - p(t, F2 - 0.4, F2 - 0.1));- who.draw({ x: wk.x, step: wk.step, arm: t > 1.5 ? (showAfter ? "up-left" : "left") : "", hop: flips ? api.ui.k : p(t, F1 + D - 0.1, F1 + D + 0.35) });- bub.set(data.say || ""); bub.draw(856, GROUND - who.top - 4, data.say ? land : 0);+ const m = flips ? lerp(1 - side, side, io(api.ui.k)) : io(p(t, F1, F1 + D)) - io(p(t, F2, F2 + D)), after = m > 0.5;+ A.setAttribute("display", after ? "none" : "inline"); Bf.setAttribute("display", after ? "inline" : "none");+ set(card, { transform: `translate(${mid} 0) scale(${Math.max(0.02, Math.abs(Math.cos(m * Math.PI)))} 1) translate(${-mid} 0)` });+ const land = flips ? (side ? api.ui.k : 0) : Math.min(p(t, F1 + D, F1 + D + 0.4), 1 - p(t, F2 - 0.4, F2 - 0.1));+ Hs.draw(t, { arm: t > 1.5 ? (after ? "up-left" : "left") : "", hop: flips ? api.ui.k : p(t, F1 + D - 0.1, F1 + D + 0.35) }, data.say, land);};return { draw, dur: F2 + D + 1.2, still: F1 + D + 1 };},@@ -420,29 +470,27 @@/* counter. data: { kicker, title, from, to, prefix, suffix, label, note, host, say } */SCENES.counter = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.55]);+ const L = stage(svg, data, api.L, [0.35, 0.55]);const a = +data.from || 0, b = +data.to || 0, dec = Math.max(decimals(data.from || 0), decimals(data.to || 0)), full = (data.prefix || "") + num(b, dec) + (data.suffix || "");- const size = Math.min(150, 1060 / Math.max(4, full.length)), cx = 382, cy = 330, T0 = 1.0, RUN = 2.2, T = T0 + RUN;+ const Wd = L.x1 - L.x0, size = Math.min(150, (Wd * 1.6) / Math.max(4, full.length)), cx = L.x0 + Wd / 2, cy = L.top + (L.bot - L.top) * 0.55, T0 = 1.0, RUN = 2.2, T = T0 + RUN;let replays = 0;const g = hit(svg, `${full}${data.label ? " " + data.label : ""}. Press to count again.`, (key) => { if (key === "hover") return; api.poke(() => { replays++; }, 1400); });const big = txt(g, cx, cy, "", size, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });- el("rect", { x: 82, y: cy + 34, width: 600, height: 8, rx: 4, fill: C.line }, g);- const bar = el("rect", { x: 82, y: cy + 34, height: 8, rx: 4, fill: C.y }, g);- if (data.label) lines(g, cx, cy + 82, wrap(data.label, 44).slice(0, 2), 23, C.paper, { "text-anchor": "middle", "font-weight": 600 });- if (data.note) txt(g, cx, cy + 142, String(data.note).slice(0, 70), 14, C.faint, { "text-anchor": "middle" });- ring(g, 60, cy - size - 6, 644, size + 170, 18);- const who = actor(svg, data.host || "kevin"), bub = bubble(svg, 18);- hint(svg, "TAP THE NUMBER");+ el("rect", { x: L.x0 + 22, y: cy + 34, width: Wd - 44, height: 8, rx: 4, fill: C.line }, g);+ const bar = el("rect", { x: L.x0 + 22, y: cy + 34, height: 8, rx: 4, fill: C.y }, g);+ if (data.label) lines(g, cx, cy + 82, wrap(data.label, L.tall ? 34 : 44).slice(0, 2), 23, C.paper, { "text-anchor": "middle", "font-weight": 600 });+ if (data.note) lines(g, cx, cy + 142, wrap(data.note, L.tall ? 56 : 76).slice(0, 2), 14, C.faint, { "text-anchor": "middle" });+ ring(g, L.x0, cy - size - 6, Wd, size + 176, 18);+ const Hs = host(svg, L, data.host || "kevin");+ hint(svg, "TAP THE NUMBER", L);const draw = (t) => {const k = replays ? out(p(api.ui.k, 0, 0.8)) : out(p(t, T0, T)), done = replays ? p(api.ui.k, 0.8, 1) : p(t, T, T + 0.35);big.textContent = (data.prefix || "") + num(lerp(a, b, k), dec) + (data.suffix || "");- const sc = 1 + 0.09 * hopY(done);- set(big, { transform: `translate(${cx} ${cy}) scale(${sc}) translate(${-cx} ${-cy})`, opacity: replays ? 1 : p(t, 0.5, 0.9) });- set(bar, { width: 600 * k });- const wk = walk(t, 0.2, 1.4, W + 50, 856);- who.draw({ x: wk.x, step: wk.step, arm: done > 0 ? "raise" : t > 1.5 ? "up-left" : "", hop: done });- bub.set(data.say || ""); bub.draw(856, GROUND - who.top - 4, data.say ? (replays ? done : p(t, T + 0.2, T + 0.6)) : 0);+ set(big, { transform: `translate(${cx} ${cy}) scale(${1 + 0.09 * hopY(done)}) translate(${-cx} ${-cy})`, opacity: replays ? 1 : p(t, 0.5, 0.9) });+ set(bar, { width: (Wd - 44) * k });+ Hs.draw(t, { arm: done > 0 ? "raise" : t > 1.5 ? "up-left" : "", hop: done }, data.say, replays ? done : p(t, T + 0.2, T + 0.6));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -450,22 +498,23 @@/* stage. data: { kicker, title, board: { label, lines: [] }, script: [{ who, say, point ("left", "right", "up-left", "up-right", "raise"), carry }] } */SCENES.stage = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.5, 0.7]);+ const L = stage(svg, data, api.L, [0.5, 0.7]);const sc = (data.script || []).slice(0, 5), names = [];sc.forEach((l) => { if (!names.includes(l.who)) names.push(l.who); });- const n = names.length || 1, X = (i) => (n === 1 ? 480 : lerp(150, 810, i / (n - 1))), SAY = 2.6, IN = 1.0, S = data.board ? 4 : 6;- floor(svg, 40, W - 40);+ const n = names.length || 1, S = data.board ? 4 : L.tall && n > 3 ? 5 : 6, edge = L.tall ? 66 : 150, X = (i) => (n === 1 ? L.W / 2 : lerp(edge, L.W - edge, i / (n - 1))), SAY = 2.6, IN = 1.0, G = L.gy;+ floor(svg, L.tall ? 16 : 40, L.W - (L.tall ? 16 : 40), G);if (data.board) {- const L = [];- (data.board.lines || []).forEach((s) => wrap(s, 40).forEach((l) => L.push(l)));- const bh = 62 + Math.min(4, L.length) * 27, by = data.title ? 128 : 60;- el("rect", { x: 250, y: by, width: 460, height: bh, rx: 16, fill: C.ink2, stroke: C.line, "stroke-width": 2 }, svg);- if (data.board.label) chip(svg, 270, by + 16, String(data.board.label).toUpperCase());- lines(svg, 272, by + (data.board.label ? 76 : 44), L.slice(0, 4), 19, C.paper, { "font-weight": 600 }, 27);+ const bw = Math.min(460, L.W - 56), bx = (L.W - bw) / 2, by = L.top - 22, T = [];+ (data.board.lines || []).forEach((s) => wrap(s, Math.floor((bw - 44) / 9.6)).forEach((l) => T.push(l)));+ const rows = T.slice(0, L.tall ? 7 : 4), ty = by + (data.board.label ? 72 : 36);+ el("rect", { x: bx, y: by, width: bw, height: ty - by + rows.length * 23 - 6, rx: 16, fill: C.ink2, stroke: C.line, "stroke-width": 2 }, svg);+ if (data.board.label) chip(svg, bx + 20, by + 16, String(data.board.label).toUpperCase());+ lines(svg, bx + 22, ty, rows, 17, C.paper, { "font-weight": 600 }, 23);}// each line: its actor walks in on first use, then speaks- let t0 = 0.3; const seen = {}, beats = sc.map((l) => { const first = !seen[l.who]; seen[l.who] = 1; const b = { l, i: names.indexOf(l.who), first, in: t0, at: t0 + (first ? IN : 0.15) }; t0 = b.at + SAY; return b; });+ let t0 = 0.3; const seen = {}, beats = sc.map((l) => { const first = !seen[l.who]; seen[l.who] = 1; const b = { l, i: names.indexOf(l.who), in: t0, at: t0 + (first ? IN : 0.15) }; t0 = b.at + SAY; return b; });const T = t0;let sel = -1;const A = names.map((nm, i) => {@@ -474,10 +523,12 @@const carry = (sc.find((l) => l.who === nm && l.carry) || {}).carry, cg = carry ? el("g", {}, g) : null;if (cg) { const w = Math.max(60, String(carry).length * 10 + 26); el("rect", { x: -w / 2, y: -30, width: w, height: 30, rx: 8, fill: C.y, stroke: C.ink, "stroke-width": 3 }, cg); txt(cg, 0, -9.5, String(carry).slice(0, 14), 15, C.ink, { "text-anchor": "middle", "font-weight": 700 }); }const r = ring(g, -11 * S, -34 * S, 22 * S, 34 * S + 34, 14);- return { g, a, tag, cg, r, x: X(i), from: X(i) < 480 ? -20 * S : W + 20 * S };+ return { g, a, tag, cg, r, x: X(i), from: X(i) < L.W / 2 ? -20 * S : L.W + 20 * S };});- const bub = bubble(svg, 26);- hint(svg, "TAP A CHARACTER");+ // With a board on the wide stage the bubble is wider and two lines at most, so it stays under the board.+ const bub = bubble(svg, L.tall ? 24 : data.board ? 34 : 26, 19, L);+ if (data.board && !L.tall) bub.maxLines = 2;+ hint(svg, "TAP A CHARACTER", L);const lastLine = (i) => { let s = ""; sc.forEach((l) => { if (l.who === names[i]) s = l.say; }); return s; };const draw = (t) => {let talk = -1, k = 0, line = "";@@ -487,22 +538,53 @@const b0 = beats.find((b) => b.i === i), w = b0 ? walk(t, b0.in, b0.in + IN, o.from, o.x) : { x: o.x, step: 0 };const cur = sel < 0 ? beats.filter((b) => b.i === i && t >= b.at).pop() : null, here = talk === i;const carrying = o.cg && (!cur || cur.l.carry || sel >= 0);- const arm = carrying ? "" : here && sel < 0 && cur && cur.l.point ? cur.l.point : t >= T && sel < 0 ? "raise" : here ? (o.x < 480 ? "up-right" : "up-left") : "";+ const arm = carrying ? "" : here && sel < 0 && cur && cur.l.point ? cur.l.point : t >= T && sel < 0 ? "raise" : here ? (o.x < L.W / 2 ? "up-right" : "up-left") : "";const hop = sel === i ? api.ui.k : sel < 0 ? p(t, T + i * 0.08, T + 0.4 + i * 0.08) : 0;- o.a.draw({ x: w.x, step: w.step, arm, hop, bob: here && Math.floor(t * 6) % 2 && sel < 0 });- set(o.r, { transform: `translate(${Math.round(w.x)} ${GROUND})` });- set(o.tag, { x: Math.round(w.x), y: GROUND + 26, fill: here ? C.y : C.faint });- if (o.cg) set(o.cg, { transform: `translate(${Math.round(w.x)} ${GROUND - 5.5 * S - hopY(hop) * 9 * S})`, opacity: carrying ? 1 : 0 });+ o.a.draw({ x: w.x, y: G, step: w.step, arm, hop, bob: here && Math.floor(t * 6) % 2 && sel < 0 });+ set(o.r, { transform: `translate(${Math.round(w.x)} ${G})` });+ set(o.tag, { x: Math.round(w.x), y: G + 22, fill: here ? C.y : C.faint });+ if (o.cg) set(o.cg, { transform: `translate(${Math.round(w.x)} ${G - 5.5 * S - hopY(hop) * 9 * S})`, opacity: carrying ? 1 : 0 });});- bub.set(line); bub.draw(talk >= 0 ? A[talk].x : 0, GROUND - 32 * S - 4, talk >= 0 && line ? k : 0);+ bub.set(line); bub.draw(talk >= 0 ? A[talk].x : 0, G - 32 * S - 4, talk >= 0 && line ? k : 0);};return { draw, dur: T + 1.6, still: beats.length ? beats[Math.min(beats.length - 1, 1)].at + 1.2 : 1 };},};+ /* title. The title card of a post: big title, kicker, two or three cast members, nothing to tap.+ data: { kicker, title, sub, cast: [names], say }. Screenshot it with ?mgstill at 1600 by 900 for the title image. */+ SCENES.title = {+ tall: true,+ build(svg, data, api) {+ const L = stage(svg, { kicker: data.kicker }, api.L, [0.72, 0.8]);+ const cast = (data.cast && data.cast.length ? data.cast : ["michael", "jim"]).slice(0, 3), n = cast.length, S = 6, G = L.gy;+ const T = wrap(data.title || "", L.tall ? 15 : 27).slice(0, L.tall ? 4 : 3), size = L.tall ? 52 : T.length > 2 ? 54 : 60, lh = size * 1.1, y0 = (data.kicker ? 92 : 50) + size;+ el("ellipse", { cx: L.tall ? L.W / 2 : L.W - 70 - (n - 1) * 60, cy: G - 60, rx: 120 + n * 70, ry: 150, fill: C.y, opacity: 0.07 }, svg);+ floor(svg, L.tall ? 16 : 40, L.W - (L.tall ? 16 : 40), G);+ const rows = T.map((s, i) => txt(svg, L.x0, y0 + i * lh, s, size, C.paper, { "font-weight": 700, "letter-spacing": "-0.02em" }));+ const subT = data.sub ? wrap(data.sub, L.tall ? 40 : 38).slice(0, 2) : [], sub = subT.length ? lines(svg, L.x0, L.tall ? y0 + T.length * lh + 4 : G - 44, subT, L.tall ? 19 : 21, C.y, { "font-weight": 600 }, 27) : null;+ const X = (i) => (L.tall ? L.W / 2 + (i - (n - 1) / 2) * 140 : L.W - 96 - (n - 1 - i) * 132);+ const A = cast.map((nm) => actor(svg, nm, S)), bub = bubble(svg, 20, 19, L);+ bub.maxLines = 2;+ const draw = (t) => {+ rows.forEach((r, i) => { const k = out(p(t, 0.2 + i * 0.16, 0.8 + i * 0.16)); set(r, { opacity: k, transform: `translate(0 ${(1 - k) * 26})` }); });+ if (sub) set(sub, { opacity: p(t, 1.0, 1.5) });+ A.forEach((a, i) => {+ const s0 = 0.7 + i * 0.35, w = walk(t, s0, s0 + 1.1, L.W + 80 + i * 60, X(i)), h0 = 2.6 + i * 0.18, h1 = 6.2 + i * 0.18;+ a.draw({ x: w.x, y: G, step: w.step, hop: Math.max(p(t, h0, h0 + 0.4) < 1 ? p(t, h0, h0 + 0.4) : 0, p(t, h1, h1 + 0.4) < 1 ? p(t, h1, h1 + 0.4) : 0), arm: w.step || t < 2.4 ? "" : i === 0 ? "up-left" : i === n - 1 && n > 1 ? "raise" : "" });+ });+ bub.set(data.say || ""); bub.draw(X(0), G - 32 * S - 4, data.say ? Math.min(p(t, 3.0, 3.4), 1 - p(t, 7.2, 7.5)) : 0);+ };+ return { draw, dur: 8, still: 4.2 };+ },+ };+const reduce = () => matchMedia("(prefers-reduced-motion: reduce)").matches;const slug = () => location.pathname.split("/").filter(Boolean).pop() || "";const send = (name, scene) => { try { if (window.posthog && window.posthog.capture) window.posthog.capture(name, { slug: slug(), scene }); } catch (e) { /* analytics never breaks a page */ } };+ const params = new URLSearchParams(location.search);+ // Tall stage for a kit scene in a narrow column. Custom scenes stay wide unless they set tall: true and read api.L.+ const wantTall = (fig, sc) => !!sc.tall && (params.get("mgtall") != null ? params.get("mgtall") !== "0" : fig.clientWidth > 0 && fig.clientWidth < 520);function mount(fig) {const name = fig.dataset.scene, sc = SCENES[name], img = fig.querySelector("img");@@ -510,32 +592,37 @@let data = {};const js = fig.querySelector('script[type="application/json"]');if (js) data = JSON.parse(js.textContent); else if (fig.dataset.mg) data = JSON.parse(fig.dataset.mg);- const svg = el("svg", { viewBox: `0 0 ${W} ${H}`, role: "group", "aria-label": img.alt, class: "mg-svg" });- let t = 0, last = 0, on = false, raf = 0, tw = 0, held = false, obs = null, draw, dur, still;- const q = new URLSearchParams(location.search).get("mgstill"), frozen = q != null;+ const tall = wantTall(fig, sc), L = tall ? TALL : WIDE;+ const svg = el("svg", { viewBox: `0 0 ${L.W} ${L.H}`, role: "group", "aria-label": img.alt, class: "mg-svg" + (tall ? " mg-tall" : "") });+ let t = 0, last = 0, on = false, raf = 0, tw = 0, held = false, obs = null, ro = null, draw, dur, still;+ const q = params.get("mgstill"), frozen = q != null;+ const again = { g: null };const api = {- ui: { k: 1 }, data,+ ui: { k: 1 }, data, L,// A reader did something: stop the story on its still frame, apply the change, and play a short move (ui.k from 0 to 1).poke(change, ms) {if (!fig._mgTouched) { fig._mgTouched = true; send("blog_scene_interact", name); }held = true; cancelAnimationFrame(raf); cancelAnimationFrame(tw);if (change) change();- again.removeAttribute("display"); svg.querySelectorAll(".mg-hint").forEach((n) => n.setAttribute("display", "none"));+ again.g.removeAttribute("display"); svg.querySelectorAll(".mg-hint").forEach((n) => n.setAttribute("display", "none"));if (reduce() || frozen) { api.ui.k = 1; return draw(still); }const a = performance.now(), d = ms || 340;- const step = (now) => { api.ui.k = clamp((now - a) / d); draw(still); if (api.ui.k < 1) tw = requestAnimationFrame(step); };- api.ui.k = 0; tw = requestAnimationFrame(step);+ const tick = (now) => { api.ui.k = clamp((now - a) / d); draw(still); if (api.ui.k < 1) tw = requestAnimationFrame(tick); };+ api.ui.k = 0; tw = requestAnimationFrame(tick);},};const built = sc.build(svg, data, api);draw = built.draw || built; dur = built.dur || sc.dur || 10; still = built.still || sc.still || dur * 0.6;+ const remount = () => { cancelAnimationFrame(raf); cancelAnimationFrame(tw); if (obs) obs.disconnect(); if (ro) ro.disconnect(); delete fig.dataset.mgLive; svg.replaceWith(img); mount(fig); };// Play again: shown once a reader has taken over.- const again = hit(svg, "Play the animation again", (key) => { if (key) return; cancelAnimationFrame(tw); obs && obs.disconnect(); delete fig.dataset.mgLive; svg.replaceWith(img); mount(fig); const b = fig.querySelector(".mg-hit"); if (b) b.focus({ preventScroll: true }); });- el("rect", { x: W - 122, y: 22, width: 98, height: 30, rx: 15, fill: C.ink3 }, again);- txt(again, W - 73, 42, "PLAY AGAIN", 12, C.paper, { "text-anchor": "middle", "font-weight": 700, "letter-spacing": "0.1em" });- ring(again, W - 122, 22, 98, 30, 15);- again.setAttribute("display", "none");+ again.g = hit(svg, "Play the animation again", (key) => { if (key) return; remount(); const b = fig.querySelector(".mg-hit"); if (b) b.focus({ preventScroll: true }); });+ el("rect", { x: L.W - 122, y: 22, width: 98, height: 30, rx: 15, fill: C.ink3 }, again.g);+ txt(again.g, L.W - 73, 42, "PLAY AGAIN", 12, C.paper, { "text-anchor": "middle", "font-weight": 700, "letter-spacing": "0.1em" });+ ring(again.g, L.W - 122, 22, 98, 30, 15);+ again.g.setAttribute("display", "none");img.replaceWith(svg); fig.dataset.mgLive = "1";+ // A phone turned on its side, or a resized window: swap between the tall and the wide stage.+ if (window.ResizeObserver) { ro = new ResizeObserver(() => { if (wantTall(fig, sc) !== tall) remount(); }); ro.observe(fig); }if (frozen || reduce()) return draw(q ? +q : still);const loop = (now) => {if (!on || held) return;@@ -552,8 +639,8 @@}const MG = {- C, W, H, GROUND, GROT, MONO, CAST, el, set, txt, lines, wrap, num, p, io, out, back, lerp, clamp, hopY,- stage, floor, chip, actor, walk, bubble, hit, ring, hint,+ C, W, H, GROUND, WIDE, TALL, GROT, MONO, CAST, el, set, txt, lines, wrap, num, p, io, out, back, lerp, clamp, hopY,+ stage, floor, chip, actor, walk, bubble, host, hit, ring, hint,scene(name, def) { SCENES[name] = def; },mount,};diff --git a/docs/blog/assets/mg/demo.html b/docs/blog/assets/mg/demo.htmlindex 67eebabb..8ab5f421 100644--- a/docs/blog/assets/mg/demo.html+++ b/docs/blog/assets/mg/demo.html@@ -15,11 +15,17 @@<body><main class="prose"><h1>Blog scene kit: every scene</h1>-<p>Test page for blog/src/assets/mg. The data here is sample data, not facts. Add ?mgstill to freeze each scene on its still frame. Real posts ship a still image in each figure; this page uses an empty one.</p>+<p>Test page for blog/src/assets/mg. The data here is sample data, not facts. Add ?mgstill to freeze each scene on its still frame, and ?mgtall=1 to force the phone layout. Real posts ship a still image in each figure; this page uses an empty one.</p>++<h2>title</h2>+<figure class="mg" data-scene="title"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Title card. Michael, Jim and Pam stand beside the title of the post."><script type="application/json">{"kicker":"Guide","title":"How to run ten coding agents at once","sub":"A sample title card for this test page","cast":["michael","jim","pam"],"say":"Let us begin."}</script><figcaption>title: the title card of a post. Nothing to tap.</figcaption></figure><h2>stage</h2><figure class="mg" data-scene="stage"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Michael walks in and opens, Jim explains, Dwight gives the rule, Kevin carries the number."><script type="application/json">{"kicker":"The cast","title":"Everyone has one job","script":[{"who":"michael","say":"Welcome to the blog. I open and I close."},{"who":"jim","say":"I explain how it works."},{"who":"dwight","say":"Rule one: no red. Ever.","point":"up-left"},{"who":"kevin","say":"I do the numbers.","carry":"$0"}]}</script><figcaption>stage: cast members walk in, stop, point and speak.</figcaption></figure>+<h2>stage, with a board</h2>+<figure class="mg" data-scene="stage"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Michael and Jim stand under a board with four points."><script type="application/json">{"kicker":"Sample board","title":"Four things to know","board":{"label":"In this post","lines":["One: install the app.","Two: pick an agent.","Three: give it a task.","Four: read the diff."]},"script":[{"who":"michael","say":"Four points. I counted them twice to be sure."},{"who":"jim","say":"He did count twice. It is still four."}]}</script><figcaption>stage with a four line board.</figcaption></figure>+<h2>price-ladder</h2><figure class="mg" data-scene="price-ladder"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Four price steps rise from Free to Team while Kevin points at them."><script type="application/json">{"kicker":"Sample prices","title":"What each plan costs a month","prefix":"$","items":[{"label":"Free","value":0,"display":"Free","note":"Free covers one agent."},{"label":"Solo","value":12,"note":"Solo adds five agents."},{"label":"Pro","value":20,"highlight":true,"note":"Pro is the one most people pick."},{"label":"Team","value":45,"note":"Team is per seat."}],"host":"kevin","say":"Pro is the sweet spot."}</script><figcaption>price-ladder: tap a step for its note.</figcaption></figure>@@ -30,10 +36,10 @@<figure class="mg" data-scene="timeline"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. Jim walks along a timeline of four dates and says what happened at each."><script type="application/json">{"kicker":"Sample timeline","title":"How the release went","events":[{"when":"May","label":"First build","note":"One agent, one desk."},{"when":"July","label":"Open source","note":"The repo went public."},{"when":"Sept","label":"Pro","note":"The paid plan shipped."},{"when":"Oct","label":"Halloween","note":"Everyone got a costume."}],"host":"jim"}</script><figcaption>timeline: tap a date and Jim walks to it.</figcaption></figure><h2>flow</h2>-<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A four step flow draws itself from Prompt to Review while Pam points at each step."><script type="application/json">{"kicker":"Sample flow","title":"From a prompt to a merged change","nodes":[{"label":"Prompt","note":"You say what you want."},{"label":"Plan","note":"The agent writes a plan first."},{"label":"Code","note":"It edits files in a worktree."},{"label":"Review","note":"You read the diff and merge."}],"labels":["","ok",""],"host":"pam","say":"Four steps. That is all."}</script><figcaption>flow: tap a step, or use the arrow keys.</figcaption></figure>+<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A four step flow draws itself from Prompt to Review while Pam points at each step."><script type="application/json">{"kicker":"Sample flow","title":"From a prompt to a merged change","nodes":[{"label":"Prompt","note":"You say what you want."},{"label":"Plan","note":"The agent writes a plan first."},{"label":"Code","note":"It edits files in a worktree."},{"label":"Review","note":"You read the diff and merge."}],"labels":["send","approve","open a PR"],"host":"pam","say":"Four steps. That is all."}</script><figcaption>flow: tap a step, or use the arrow keys.</figcaption></figure><h2>flow, six steps</h2>-<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A six step flow in two rows."><script type="application/json">{"title":"Six steps wrap onto two rows","nodes":[{"label":"One"},{"label":"Two"},{"label":"Three"},{"label":"Four"},{"label":"Five"},{"label":"Six"}],"host":"pam"}</script><figcaption>flow with six nodes.</figcaption></figure>+<figure class="mg" data-scene="flow"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A six step flow in two rows."><script type="application/json">{"title":"Six steps wrap onto two rows","nodes":[{"label":"One"},{"label":"Two"},{"label":"Three"},{"label":"Four"},{"label":"Five"},{"label":"Six"}],"labels":["","","if tests pass","","retry"],"host":"pam"}</script><figcaption>flow with six nodes.</figcaption></figure><h2>before-after</h2><figure class="mg" data-scene="before-after"><img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" width="1600" height="900" alt="Animation. A card with a long vague prompt flips to a short clear one while Dwight points at it."><script type="application/json">{"kicker":"Sample flip","title":"The same request, written twice","before":{"label":"Before","lines":["Could you maybe take a look at the login thing when you get a chance and see if anything seems off with it?"]},"after":{"label":"After","lines":["Find why login fails on Safari.","Show the failing request.","Do not change code yet."]},"host":"dwight","say":"Short orders. Always."}</script><figcaption>before-after: tap the card to flip it.</figcaption></figure>diff --git a/docs/blog/assets/mg/kit.css b/docs/blog/assets/mg/kit.cssindex 980d019c..fd4950b6 100644--- a/docs/blog/assets/mg/kit.css+++ b/docs/blog/assets/mg/kit.css@@ -2,6 +2,7 @@.prose figure.mg { margin: 42px 0; }.prose figure.mg img, .mg .mg-svg { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border: 1px solid #1A1320; border-radius: 16px; background: #1A1320; }.mg figcaption { font: 500 13px/1.5 "Space Grotesk", system-ui, sans-serif; color: #6B5878; padding-top: 10px; text-align: center; }+.mg .mg-svg.mg-tall { aspect-ratio: 3 / 4; }.mg .mg-svg { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }.mg .mg-svg text { -webkit-user-select: none; user-select: none; }.mg .mg-svg image { image-rendering: pixelated; }diff --git a/docs/blog/assets/mg/kit.js b/docs/blog/assets/mg/kit.jsindex 769c6e30..4d4c6e32 100644--- a/docs/blog/assets/mg/kit.js+++ b/docs/blog/assets/mg/kit.js@@ -3,12 +3,14 @@<script type="application/json"> with the page's own data. This script swaps the still for a live SVGscene (viewBox 960 by 540) that plays only while on screen. Reduced motion keeps one drawn frame."?mgstill=<seconds>" freezes every scene on that frame, "?mgstill" alone on each scene's still frame.+ Under 520 px wide a kit scene uses a tall stage (540 by 720) with larger type and the host below the content.+ "?mgtall=1" forces the tall stage, "?mgtall=0" the wide one.Custom scenes register with (window.MGQ = window.MGQ || []).push((MG) => MG.scene("name", {...})).Guide: blog/MG_KIT.md. */(() => {const NS = "http://www.w3.org/2000/svg";const C = { ink: "#1A1320", ink2: "#251B2E", ink3: "#3D2E4A", faint: "#8E7B9C", soft: "#D9CFE0", line: "#4A3A58", paper: "#FCFAF0", y: "#FFCA54", sky: "#4ECDC4", lilac: "#B197FC", blue: "#6C8EF5", mint: "#6BCF7F" };- const W = 960, H = 540, GROUND = 500, GROT = '"Space Grotesk", system-ui, sans-serif', MONO = '"JetBrains Mono", ui-monospace, monospace';+ const W = 960, H = 540, GROUND = 500, WIDE = { W: 960, H: 540, x0: 60, x1: 704, top: 140, bot: 452, gy: 500, hx: 856, tall: false }, TALL = { W: 540, H: 720, x0: 28, x1: 512, top: 140, bot: 520, gy: 694, hx: 84, tall: true }, GROT = '"Space Grotesk", system-ui, sans-serif', MONO = '"JetBrains Mono", ui-monospace, monospace';const BASE = (document.currentScript && document.currentScript.src ? document.currentScript.src : "/blog/assets/mg/kit.js").replace(/[^/]*$/, "");const clamp = (v) => Math.max(0, Math.min(1, v));const p = (t, a, b) => clamp((t - a) / (b - a));@@ -41,19 +43,25 @@const decimals = (v) => (String(v).split(".")[1] || "").length;// Stage: deep ink panel, a soft glow, a fine grid, a kicker chip and a title.+ // stage(svg, data, layout, glow) returns the layout it drew on, with "top" moved down when the title wraps.let uid = 0;- function stage(svg, data, glow) {- const id = "mg" + ++uid, d = el("defs", {}, svg), gl = glow || [0.5, 0.35];+ function stage(svg, data, a, b) {+ const L = Object.assign({}, a && !Array.isArray(a) ? a : WIDE), gl = Array.isArray(a) ? a : b || [0.5, 0.35];+ const id = "mg" + ++uid, d = el("defs", {}, svg);const g = el("radialGradient", { id: id + "g", cx: gl[0], cy: gl[1], r: 0.75 }, d);el("stop", { offset: 0, "stop-color": "#3A2A4A" }, g);el("stop", { offset: 1, "stop-color": C.ink }, g);const pt = el("pattern", { id: id + "p", width: 48, height: 48, patternUnits: "userSpaceOnUse" }, d);el("path", { d: "M48 0H0V48", fill: "none", stroke: "#FFFFFF", "stroke-opacity": 0.035, "stroke-width": 1 }, pt);- el("rect", { width: W, height: H, fill: `url(#${id}g)` }, svg);- el("rect", { width: W, height: H, fill: `url(#${id}p)` }, svg);- if (data && data.kicker) chip(svg, 60, 36, String(data.kicker).toUpperCase());- if (data && data.title) lines(svg, 60, data.kicker ? 104 : 70, wrap(data.title, 52).slice(0, 2), 27, C.paper, { "font-weight": 600 });- return d;+ el("rect", { width: L.W, height: L.H, fill: `url(#${id}g)` }, svg);+ el("rect", { width: L.W, height: L.H, fill: `url(#${id}p)` }, svg);+ if (data && data.kicker) chip(svg, L.x0, 36, String(data.kicker).toUpperCase());+ if (data && data.title) {+ const y = data.kicker ? 104 : 70, T = wrap(data.title, L.tall ? 30 : 52).slice(0, L.tall ? 3 : 2);+ lines(svg, L.x0, y, T, L.tall ? 25 : 27, C.paper, { "font-weight": 600 }, 32);+ L.top = y + (T.length - 1) * 32 + 36;+ }+ return L;}function floor(svg, x0, x1, y) {el("rect", { x: x0, y: (y || GROUND) - 2, width: x1 - x0, height: 4, rx: 2, fill: C.line }, svg);@@ -136,28 +144,51 @@const walk = (t, t0, t1, x0, x1) => { const k = p(t, t0, t1); return { x: lerp(x0, x1, k), step: k > 0 && k < 1 ? t : 0 }; };// Speech bubble. draw(x, y, k): the tail tip sits at x, y; k from 0 to 1 pops it.- function bubble(parent, max, size) {- const sz = size || 19, mx = max || 24, g = el("g", { opacity: 0 }, parent);+ // side "right" puts the bubble to the right of the tip (tail points left); the default sits above it.+ function bubble(parent, max, size, layout, side) {+ const sz = size || 19, mx = max || 24, L = layout || WIDE, g = el("g", { opacity: 0 }, parent);const r = el("rect", { rx: 14, fill: C.paper }, g), tail = el("path", { fill: C.paper }, g);let t = null, w = 0, h = 0, cur = null;- return {- g,+ const o = {+ g, maxLines: 4,set(s) {if (s === cur) return; cur = s; if (t) t.remove();- const L = wrap(s, mx).slice(0, 4);- w = Math.max.apply(null, L.map((l) => l.length)) * sz * 0.53 + 34; h = L.length * sz * 1.28 + 20;- t = lines(g, 0, 0, L, sz, C.ink, { "font-weight": 600 });+ const T = wrap(s, mx).slice(0, o.maxLines);+ w = Math.max.apply(null, T.map((l) => l.length)) * sz * 0.53 + 34; h = T.length * sz * 1.28 + 20;+ t = lines(g, 0, 0, T, sz, C.ink, { "font-weight": 600 });set(r, { width: w, height: h });},draw(x, y, k) {if (!(k > 0) || !cur) return g.setAttribute("opacity", 0);- const bx = Math.max(12, Math.min(W - 12 - w, x - w / 2)), by = Math.max(8, y - 13 - h), tx = Math.max(bx + 22, Math.min(bx + w - 22, x));+ let bx, by, px = x, py = y;+ if (side === "right") {+ bx = Math.min(L.W - 12 - w, x + 13); by = Math.max(8, Math.min(L.H - 8 - h, y - h / 2));+ tail.setAttribute("d", `M${bx + 1} ${y - 9}L${bx - 13} ${y}L${bx + 1} ${y + 9}z`); px = bx - 13;+ } else {+ bx = Math.max(12, Math.min(L.W - 12 - w, x - w / 2)); by = Math.max(8, y - 13 - h); px = Math.max(bx + 22, Math.min(bx + w - 22, x)); py = by + h + 13;+ tail.setAttribute("d", `M${px - 9} ${by + h - 1}L${px} ${py}L${px + 9} ${by + h - 1}z`);+ }set(r, { x: bx, y: by });set(t, { y: by + 12 + sz });Array.prototype.forEach.call(t.childNodes, (n) => n.setAttribute("x", bx + 17));- tail.setAttribute("d", `M${tx - 9} ${by + h - 1}L${tx} ${by + h + 13}L${tx + 9} ${by + h - 1}z`);- const sc = back(clamp(k));- set(g, { opacity: Math.min(1, k * 3), transform: `translate(${tx} ${by + h + 13}) scale(${sc}) translate(${-tx} ${-(by + h + 13)})` });+ set(g, { opacity: Math.min(1, k * 3), transform: `translate(${px} ${py}) scale(${back(clamp(k))}) translate(${-px} ${-py})` });+ },+ };+ return o;+ }++ // The host of a data scene: walks in, points at the content and speaks.+ // Wide stage: stands on the right, bubble above. Tall stage: stands below the content, bubble beside.+ function host(svg, L, name) {+ const who = actor(svg, name), bub = bubble(svg, L.tall ? 30 : 18, 19, L, L.tall ? "right" : "");+ return {+ who, bub,+ // o: arm, hop, bob (as actor.draw). line: what the host says. k: bubble pop, 0 to 1.+ draw(t, o, line, k) {+ const wk = walk(t, 0.2, 1.4, L.tall ? -60 : L.W + 50, L.hx), arm = o.arm && o.arm !== "raise" && L.tall ? "up-right" : o.arm;+ who.draw({ x: wk.x, y: L.gy, step: wk.step, arm: wk.step ? "" : arm, hop: o.hop, bob: o.bob });+ bub.set(line || "");+ if (L.tall) bub.draw(L.hx + 44, L.gy - 70, line ? k : 0); else bub.draw(L.hx, L.gy - who.top - 4, line ? k : 0);},};}@@ -175,35 +206,37 @@}// Call after the group has its content: adds the hit area and the focus ring on top.const ring = (g, x, y, w, h, rx) => el("rect", { x, y, width: w, height: h, rx: rx == null ? 12 : rx, fill: "#fff", "fill-opacity": 0, stroke: C.y, "stroke-width": 3, class: "mg-ring" }, g);- const hint = (svg, s) => txt(svg, W - 28, 42, s, 13, C.faint, { "text-anchor": "end", "font-weight": 600, "letter-spacing": "0.08em", class: "mg-hint" });+ const hint = (svg, s, L) => txt(svg, (L || WIDE).W - 28, 42, s, 13, C.faint, { "text-anchor": "end", "font-weight": 600, "letter-spacing": "0.08em", class: "mg-hint" });+ const step = (i, n, key, fwd) => Math.max(0, Math.min(n - 1, i + (fwd.includes(key) ? 1 : -1)));const SCENES = {};/* price-ladder. data: { kicker, title, prefix, suffix, items: [{ label, value, display, note, highlight }], host, say } */SCENES["price-ladder"] = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.4]);+ const L = stage(svg, data, api.L, [0.35, 0.4]);const items = (data.items || []).slice(0, 6), n = items.length || 1, max = Math.max.apply(null, items.map((i) => +i.value || 0)) || 1;- const x0 = 60, x1 = 704, gap = 18, bw = (x1 - x0 - gap * (n - 1)) / n, base = 452, tall = 240, dec = Math.max.apply(null, items.map((i) => decimals(i.value)));- const T = 1.2 + n * 0.28 + 0.6, say0 = data.say || "";+ const x0 = L.x0, x1 = L.x1, gap = L.tall ? 10 : 18, bw = (x1 - x0 - gap * (n - 1)) / n, base = L.bot, tall = Math.min(240, base - L.top - 56), dec = Math.max.apply(null, items.map((i) => decimals(i.value)));+ const T = 1.2 + n * 0.28 + 0.6, hi = items.findIndex((i) => i.highlight);floor(svg, x0, x1, base + 2);- let sel = -1, hi = items.findIndex((i) => i.highlight);+ let sel = -1;const fmt = (it, v) => (it.display != null ? it.display : (data.prefix || "") + num(v, dec) + (data.suffix || ""));const bars = items.map((it, i) => {const x = x0 + i * (bw + gap), h = Math.max(26, (tall * (+it.value || 0)) / max);const g = hit(svg, `${it.label}: ${fmt(it, it.value)}${it.note ? ". " + it.note : ""}`, (key) => {- if (key && key.startsWith("Arrow")) { const j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowUp" ? 1 : -1))); bars[j].g.focus(); return api.poke(() => { sel = j; }); }+ if (key && key.startsWith("Arrow")) { const j = step(i, n, key, ["ArrowRight", "ArrowUp"]); bars[j].g.focus(); return api.poke(() => { sel = j; }); }if (key === "hover" && sel === i) return;api.poke(() => { sel = i; });});const r = el("rect", { x, width: bw, rx: 8 }, g);- const v = txt(g, x + bw / 2, 0, "", 21, C.paper, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });+ const v = txt(g, x + bw / 2, 0, "", Math.min(21, bw / 3.4), C.paper, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });lines(g, x + bw / 2, base + 26, wrap(it.label, Math.max(6, Math.floor(bw / 8.4))).slice(0, 2), 14.5, C.soft, { "text-anchor": "middle", "font-weight": 600 }, 17);ring(g, x - 4, base - tall - 44, bw + 8, tall + 92);return { g, r, v, h, x, it };});- const who = actor(svg, data.host || "kevin"), bub = bubble(svg, 18);- hint(svg, "TAP A STEP");+ const Hs = host(svg, L, data.host || "kevin");+ hint(svg, "TAP A STEP", L);const draw = (t) => {bars.forEach((b, i) => {const k = p(t, 0.5 + i * 0.28, 1.15 + i * 0.28), h = b.h * Math.max(0.02, back(k)), on = sel >= 0 ? sel === i : i === hi && t > T - 0.5;@@ -211,10 +244,8 @@b.v.textContent = fmt(b.it, (+b.it.value || 0) * out(k));set(b.v, { y: base - h - 12, opacity: p(t, 0.5 + i * 0.28, 0.8 + i * 0.28), fill: on ? C.y : C.paper });});- const wk = walk(t, 0.2, 1.5, W + 50, 856), land = sel >= 0 ? api.ui.k : p(t, T, T + 0.4);- who.draw({ x: wk.x, step: wk.step, arm: t > 1.6 ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T - 0.1, T + 0.35), bob: t > T && Math.floor(t * 5) % 2 });- const line = sel >= 0 ? items[sel].note || `${items[sel].label}: ${fmt(items[sel], items[sel].value)}` : say0;- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? land : 0);+ const line = sel >= 0 ? items[sel].note || `${items[sel].label}: ${fmt(items[sel], items[sel].value)}` : data.say;+ Hs.draw(t, { arm: t > 1.6 ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T - 0.1, T + 0.35), bob: t > T && Math.floor(t * 5) % 2 }, line, sel >= 0 ? api.ui.k : p(t, T, T + 0.4));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -222,51 +253,50 @@/* compare. data: { kicker, title, cols: [a, b], pick (0 or 1), rows: [{ label, a, b, win ("a", "b" or ""), note }], host, say } */SCENES.compare = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.3, 0.45]);- const rows = (data.rows || []).slice(0, 5), n = rows.length, cols = data.cols || ["A", "B"], pick = data.pick;- const cx = [60, 282, 494], cw = [214, 204, 204], top = 150, rh = Math.min(58, 290 / Math.max(1, n)), T = 1.0 + n * 0.5 + 0.5;+ const L = stage(svg, data, api.L, [0.3, 0.45]);+ const rows = (data.rows || []).slice(0, 5), n = rows.length, cols = data.cols || ["A", "B"], pick = data.pick, f = L.tall ? 15 : 17;+ const lw = (L.x1 - L.x0) * (L.tall ? 0.3 : 0.34), cw = (L.x1 - L.x0 - lw) / 2, cx = [L.x0, L.x0 + lw, L.x0 + lw + cw], top = L.top + 10;+ const rh = Math.min(L.tall ? 66 : 58, (L.bot - top - 36) / Math.max(1, n)), T = 1.0 + n * 0.5 + 0.5, mc = Math.floor((cw - 30) / (f * 0.56)), cut = (v, m) => String(v == null ? "" : v).slice(0, m);let sel = -1;const heads = cols.slice(0, 2).map((c, i) => {const g = el("g", {}, svg);- el("rect", { x: cx[i + 1], y: top - 14, width: cw[i + 1], height: 40, rx: 10, fill: pick === i ? C.y : C.ink3 }, g);- txt(g, cx[i + 1] + cw[i + 1] / 2, top + 13, String(c).slice(0, 20), 17, pick === i ? C.ink : C.paper, { "text-anchor": "middle", "font-weight": 700 });+ el("rect", { x: cx[i + 1] + 4, y: top - 14, width: cw - 8, height: 40, rx: 10, fill: pick === i ? C.y : C.ink3 }, g);+ txt(g, cx[i + 1] + cw / 2, top + 13, cut(c, mc + 2), f, pick === i ? C.ink : C.paper, { "text-anchor": "middle", "font-weight": 700 });return g;});const R = rows.map((r, i) => {const y = top + 40 + i * rh;const g = hit(svg, `${r.label}. ${cols[0]}: ${r.a}. ${cols[1]}: ${r.b}.${r.note ? " " + r.note : ""}`, (key) => {- if (key && key.startsWith("Arrow")) { const j = Math.max(0, Math.min(n - 1, i + (key === "ArrowDown" || key === "ArrowRight" ? 1 : -1))); R[j].g.focus(); return api.poke(() => { sel = j; }); }+ if (key && key.startsWith("Arrow")) { const j = step(i, n, key, ["ArrowRight", "ArrowDown"]); R[j].g.focus(); return api.poke(() => { sel = j; }); }if (key === "hover" && sel === i) return;api.poke(() => { sel = i; });});- const bg = el("rect", { x: 52, y: y + 3, width: 654, height: rh - 6, rx: 10, fill: C.ink2 }, g);- txt(g, cx[0] + 10, y + rh / 2 + 6, String(r.label).slice(0, 24), 17, C.soft, { "font-weight": 600 });- const cells = ["a", "b"].map((k, j) => {- const won = r.win === k;- const t = txt(g, cx[j + 1] + cw[j + 1] / 2 + (won ? 10 : 0), y + rh / 2 + 6, String(r[k] == null ? "" : r[k]).slice(0, 22), 17, won ? C.y : C.paper, { "text-anchor": "middle", "font-weight": won ? 700 : 500 });- const half = String(r[k] == null ? "" : r[k]).slice(0, 22).length * 4.9 + 4;- const tick = won ? el("path", { d: `M${cx[j + 1] + cw[j + 1] / 2 - half - 16} ${y + rh / 2}l6 6 11-12`, fill: "none", stroke: C.y, "stroke-width": 3.5, "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-dasharray": 26 }, g) : null;- return { t, tick };+ const bg = el("rect", { x: L.x0 - 8, y: y + 3, width: L.x1 - L.x0 + 16, height: rh - 6, rx: 10, fill: C.ink2 }, g);+ const lab = wrap(r.label, Math.floor((lw - 6) / (f * 0.54))).slice(0, 2);+ lines(g, cx[0] + 4, y + rh / 2 + 6 - (lab.length - 1) * f * 0.6, lab, f, C.soft, { "font-weight": 600 }, f * 1.2);+ const ticks = ["a", "b"].map((k, j) => {+ const won = r.win === k, s = cut(r[k], won ? mc - 2 : mc), mid = cx[j + 1] + cw / 2;+ txt(g, mid + (won ? 10 : 0), y + rh / 2 + 6, s, f, won ? C.y : C.paper, { "text-anchor": "middle", "font-weight": won ? 700 : 500 });+ return won ? el("path", { d: `M${mid - s.length * f * 0.29 - 20} ${y + rh / 2}l6 6 11-12`, fill: "none", stroke: C.y, "stroke-width": 3.5, "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-dasharray": 26 }, g) : null;});- ring(g, 52, y + 3, 654, rh - 6, 10);- return { g, bg, cells };+ ring(g, L.x0 - 8, y + 3, L.x1 - L.x0 + 16, rh - 6, 10);+ return { g, bg, ticks };});- const who = actor(svg, data.host || "oscar"), bub = bubble(svg, 18);- hint(svg, "TAP A ROW");+ const Hs = host(svg, L, data.host || "oscar");+ hint(svg, "TAP A ROW", L);const draw = (t) => {heads.forEach((g, i) => { const k = back(p(t, 0.3 + i * 0.15, 0.75 + i * 0.15)); set(g, { opacity: clamp(k * 2), transform: `translate(0 ${(1 - k) * -18})` }); });R.forEach((r, i) => {const a = 1.0 + i * 0.5, k = out(p(t, a, a + 0.4));set(r.g, { opacity: k, transform: `translate(${(1 - k) * -40} 0)` });set(r.bg, { fill: sel === i ? C.ink3 : C.ink2 });- r.cells.forEach((c) => c.tick && set(c.tick, { "stroke-dashoffset": 26 * (1 - out(p(t, a + 0.3, a + 0.6))) }));+ r.ticks.forEach((c) => c && set(c, { "stroke-dashoffset": 26 * (1 - out(p(t, a + 0.3, a + 0.6))) }));});- const wk = walk(t, 0.2, 1.4, W + 50, 856);const cur = Math.min(n - 1, Math.floor((t - 1.0) / 0.5));- who.draw({ x: wk.x, step: wk.step, arm: t > 1.5 && (sel >= 0 || t < T) ? (cur % 2 ? "left" : "up-left") : t >= T ? "up-left" : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) });- const line = sel >= 0 ? rows[sel].note || `${rows[sel].label}: ${rows[sel].win === "b" ? cols[1] : rows[sel].win === "a" ? cols[0] : "a tie"}` : data.say || "";- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? (sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5)) : 0);+ const line = sel >= 0 ? rows[sel].note || `${rows[sel].label}: ${rows[sel].win === "b" ? cols[1] : rows[sel].win === "a" ? cols[0] : "a tie"}` : data.say;+ Hs.draw(t, { arm: t > 1.5 ? (sel < 0 && t < T && cur % 2 ? "left" : "up-left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) }, line, sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -274,45 +304,60 @@/* timeline. data: { kicker, title, events: [{ when, label, note }], host } */SCENES.timeline = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.5, 0.6]);- const ev = (data.events || []).slice(0, 6), n = ev.length || 1, y = 392, xa = 100, xb = 860, X = (i) => (n === 1 ? (xa + xb) / 2 : lerp(xa, xb, i / (n - 1)));- const HOP = 0.9, STAY = 1.7, T0 = 1.0, at = (i) => T0 + i * (HOP + STAY) + HOP, T = at(n - 1) + STAY;- el("rect", { x: xa - 30, y: y - 2, width: xb - xa + 60, height: 4, rx: 2, fill: C.line }, svg);- const prog = el("rect", { x: xa - 30, y: y - 2, height: 4, rx: 2, fill: C.y }, svg);+ const L = stage(svg, data, api.L, [0.5, 0.6]);+ const ev = (data.events || []).slice(0, 6), n = ev.length || 1, HOP = 0.9, STAY = 1.7, T0 = 1.0, at = (i) => T0 + i * (HOP + STAY) + HOP, T = at(n - 1) + STAY;+ // a, b: the two ends of the line. wide: across. tall: down.+ const a = L.tall ? L.top + 24 : 100, b = L.tall ? L.bot - 34 : 860, P = (v) => (n === 1 ? (a + b) / 2 + v * 120 : lerp(a, b, v / (n - 1)));+ const y = Math.max(392, L.top + 252), x = L.x0 + 18, gapN = n > 1 ? (b - a) / (n - 1) : 170;+ el("rect", L.tall ? { x: x - 2, y: a - 26, width: 4, height: b - a + 52, rx: 2, fill: C.line } : { x: a - 30, y: y - 2, width: b - a + 60, height: 4, rx: 2, fill: C.line }, svg);+ const prog = el("rect", L.tall ? { x: x - 2, y: a - 26, width: 4, rx: 2, fill: C.y } : { x: a - 30, y: y - 2, height: 4, rx: 2, fill: C.y }, svg);let sel = -1, from = 0;const dots = ev.map((e, i) => {- const x = X(i), cw = Math.min(170, (xb - xa) / Math.max(1, n - 1) - 14 || 170);+ const q = P(i);const g = hit(svg, `${e.when}: ${e.label}${e.note ? ". " + e.note : ""}`, (key) => {let j = i;- if (key && key.startsWith("Arrow")) { j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowDown" ? 1 : -1))); dots[j].g.focus(); }+ if (key && key.startsWith("Arrow")) { j = step(i, n, key, ["ArrowRight", "ArrowDown"]); dots[j].g.focus(); }if (key === "hover") return;- api.poke(() => { from = sel >= 0 ? sel : n - 1; sel = j; }, 500);+ api.poke(() => { from = sel >= 0 ? sel : Math.min(n - 1, 1); sel = j; }, 500);});- const c = el("circle", { cx: x, cy: y, r: 11, stroke: C.ink, "stroke-width": 4 }, g);- const w = txt(g, x, y + 38, String(e.when).slice(0, 14), 15, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });- const l = lines(g, x, y + 62, wrap(e.label, Math.max(8, Math.floor(cw / 8))).slice(0, 3), 15, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 19);- ring(g, x - cw / 2, y - 22, cw, 150);- return { g, c, w, l, x };+ let c, w, l;+ if (L.tall) {+ c = el("circle", { cx: x, cy: q, r: 11, stroke: C.ink, "stroke-width": 4 }, g);+ w = txt(g, x + 30, q - 3, String(e.when).slice(0, 22), 16, C.y, { "font-family": MONO, "font-weight": 700 });+ l = lines(g, x + 30, q + 19, wrap(e.label, 44).slice(0, gapN > 82 ? 2 : 1), 16, C.paper, { "font-weight": 600 }, 20);+ ring(g, L.x0 - 6, q - 24, L.x1 - L.x0 + 12, Math.min(70, gapN - 6));+ } else {+ const cw = Math.min(170, gapN - 14);+ c = el("circle", { cx: q, cy: y, r: 11, stroke: C.ink, "stroke-width": 4 }, g);+ w = txt(g, q, y + 38, String(e.when).slice(0, 14), 15, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });+ l = lines(g, q, y + 62, wrap(e.label, Math.max(8, Math.floor(cw / 8))).slice(0, 3), 15, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 19);+ ring(g, q - cw / 2, y - 22, cw, 150);+ }+ return { g, c, w, l };});- const who = actor(svg, data.host || "jim"), bub = bubble(svg, 26, 18);- hint(svg, "TAP A DATE");+ const mark = L.tall ? el("circle", { cx: x, r: 7, fill: C.paper, stroke: C.ink, "stroke-width": 3 }, svg) : null;+ const Hs = L.tall ? host(svg, L, data.host || "jim") : null, who = L.tall ? null : actor(svg, data.host || "jim"), bub = L.tall ? null : bubble(svg, 26, 18, L);+ hint(svg, "TAP A DATE", L);const draw = (t) => {- let x, step = 0, cur = -1, k = 0;- if (sel >= 0) { const m = io(api.ui.k); x = lerp(X(from), X(sel), m); step = api.ui.k < 1 ? api.ui.k * 0.9 : 0; cur = sel; k = p(api.ui.k, 0.7, 1); }- else {- x = xa - 80;- for (let i = 0; i < n; i++) { const a = at(i) - HOP, w = walk(t, a, at(i), i ? X(i - 1) : xa - 80, X(i)); if (t >= a) { x = w.x; step = w.step; if (t >= at(i)) { cur = i; k = Math.min(p(t, at(i), at(i) + 0.35), 1 - p(t, at(i) + STAY - 0.3, at(i) + STAY - 0.05) * (i < n - 1 ? 1 : 0)); } } }+ let v = -0.6, st = 0, cur = -1, k = 0;+ if (sel >= 0) { v = lerp(from, sel, io(api.ui.k)); st = api.ui.k < 1 ? api.ui.k * 0.9 : 0; cur = sel; k = p(api.ui.k, 0.7, 1); }+ else for (let i = 0; i < n; i++) {+ const s0 = at(i) - HOP; if (t < s0) break;+ const m = p(t, s0, at(i)); v = lerp(i ? i - 1 : -0.6, i, m); st = m > 0 && m < 1 ? t : 0;+ if (t >= at(i)) { cur = i; k = Math.min(p(t, at(i), at(i) + 0.35), 1 - p(t, at(i) + STAY - 0.3, at(i) + STAY - 0.05) * (i < n - 1 ? 1 : 0)); }}- set(prog, { width: Math.max(0, x - (xa - 30)) });+ const q = P(v);+ set(prog, L.tall ? { height: Math.max(0, q - (a - 26)) } : { width: Math.max(0, q - (a - 30)) });dots.forEach((d, i) => {- const seen = sel >= 0 ? true : t >= at(i), pop = sel >= 0 ? 1 : back(p(t, at(i) - 0.1, at(i) + 0.3)), on = cur === i;- set(d.c, { r: 8 + 5 * pop + (on ? 3 : 0), fill: seen ? C.y : C.line });+ const seen = sel >= 0 ? true : t >= at(i), pop = sel >= 0 ? 1 : back(p(t, at(i) - 0.1, at(i) + 0.3));+ set(d.c, { r: 8 + 5 * pop + (cur === i ? 3 : 0), fill: seen ? C.y : C.line });set(d.w, { opacity: seen ? 1 : 0.35 }); set(d.l, { opacity: seen ? 1 : 0.35 });});- who.draw({ x, y: y - 18, step, bob: cur >= 0 && !step && Math.floor(t * 5) % 2 && sel < 0 });- const line = cur >= 0 ? ev[cur].note || ev[cur].label : "";- bub.set(line); bub.draw(x, y - 18 - who.top - 2, line ? k : 0);+ const line = cur >= 0 ? ev[cur].note || ev[cur].label : "", talk = cur >= 0 && !st && sel < 0 && Math.floor(t * 5) % 2;+ if (L.tall) { set(mark, { cy: Math.max(a - 26, q) }); Hs.draw(t, { arm: cur >= 0 ? "up-right" : "", bob: talk, hop: sel >= 0 ? api.ui.k : 0 }, line, k); }+ else { who.draw({ x: q, y: y - 18, step: st, bob: talk }); bub.set(line); bub.draw(q, y - 18 - who.top - 2, line ? k : 0); }};return { draw, dur: T + 1.2, still: at(Math.min(n - 1, 1)) + 0.8 };},@@ -320,42 +365,53 @@/* flow. data: { kicker, title, nodes: [{ label, note }], labels: [text on the arrow after node i], host, say } */SCENES.flow = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.4, 0.5]);- const nodes = (data.nodes || []).slice(0, 8), n = nodes.length || 1, per = n <= 4 ? n : Math.ceil(n / 2), bw = n <= 4 ? Math.min(190, (644 - (n - 1) * 34) / n) : 140, bh = n <= 4 ? 108 : 76, gap = per > 1 ? (644 - per * bw) / (per - 1) : 0;- const pos = nodes.map((_, i) => { const row = i < per ? 0 : 1, col = row ? per - 1 - (i - per) : i; return { x: 60 + col * (bw + gap), y: n <= 4 ? 186 : row ? 330 : 176 }; });+ const L = stage(svg, data, api.L, [0.4, 0.5]);+ const nodes = (data.nodes || []).slice(0, 8), n = nodes.length || 1, Wd = L.x1 - L.x0;+ const per = L.tall ? Math.min(2, n) : n <= 4 ? n : Math.ceil(n / 2), rows = Math.ceil(n / per);+ const bw = L.tall ? (per > 1 ? (Wd - 64) / 2 : Wd) : n <= 4 ? Math.min(190, (Wd - (n - 1) * 34) / n) : 140, bh = rows === 1 ? 108 : L.tall ? 70 : 76;+ const gapX = per > 1 ? (Wd - per * bw) / (per - 1) : 0, y0 = L.top + (rows === 1 ? 46 : 30), stepY = rows > 1 ? Math.min(154, (L.bot - y0 - bh) / (rows - 1)) : 0;+ // rows snake: left to right, then right to left+ const pos = nodes.map((_, i) => { const r = Math.floor(i / per), c = i % per; return { x: L.x0 + (r % 2 ? per - 1 - c : c) * (bw + gapX), y: y0 + r * stepY }; });const STEP = 1.1, T0 = 0.8, T = T0 + n * STEP;let sel = -1, from = 0;const edges = pos.slice(0, -1).map((a, i) => {- const b = pos[i + 1], down = a.y !== b.y, dir = b.x > a.x ? 1 : -1;- const d = down ? `M${a.x + bw / 2} ${a.y + bh}V${b.y - 8}` : `M${dir > 0 ? a.x + bw : a.x} ${a.y + bh / 2}H${dir > 0 ? b.x - 8 : b.x + bw + 8}`;- const path = el("path", { d, fill: "none", stroke: C.paper, "stroke-width": 2.5, "stroke-linecap": "round" }, svg);- const len = down ? b.y - 8 - a.y - bh : Math.abs((dir > 0 ? b.x - 8 : b.x + bw + 8) - (dir > 0 ? a.x + bw : a.x));+ const b = pos[i + 1], down = a.y !== b.y, dir = b.x > a.x ? 1 : -1, xa = dir > 0 ? a.x + bw : a.x, xb = dir > 0 ? b.x - 8 : b.x + bw + 8;+ const path = el("path", { d: down ? `M${a.x + bw / 2} ${a.y + bh}V${b.y - 8}` : `M${xa} ${a.y + bh / 2}H${xb}`, fill: "none", stroke: C.paper, "stroke-width": 2.5, "stroke-linecap": "round" }, svg);+ const len = down ? b.y - 8 - a.y - bh : Math.abs(xb - xa);path.setAttribute("stroke-dasharray", len);- const tip = down ? `M${a.x + bw / 2 - 6} ${b.y - 12}l6 8 6-8z` : dir > 0 ? `M${b.x - 12} ${a.y + bh / 2 - 6}l8 6-8 6z` : `M${b.x + bw + 12} ${a.y + bh / 2 - 6}l-8 6 8 6z`;- const head = el("path", { d: tip, fill: C.paper }, svg);- const lab = (data.labels || [])[i];- const lt = lab ? txt(svg, down ? a.x + bw / 2 + 12 : (a.x + b.x + bw) / 2, down ? (a.y + bh + b.y) / 2 + 5 : a.y + bh / 2 - 12, String(lab).slice(0, 12), 13, C.y, { "text-anchor": down ? "start" : "middle", "font-weight": 700 }) : null;- return { path, head, len, lt };+ const head = el("path", { d: down ? `M${a.x + bw / 2 - 6} ${b.y - 12}l6 8 6-8z` : dir > 0 ? `M${b.x - 12} ${a.y + bh / 2 - 6}l8 6-8 6z` : `M${b.x + bw + 12} ${a.y + bh / 2 - 6}l-8 6 8 6z`, fill: C.paper }, svg);+ return { path, head, len, down, a, b, xa, xb };});const B = nodes.map((nd, i) => {const q = pos[i];const g = hit(svg, `Step ${i + 1} of ${n}: ${nd.label}${nd.note ? ". " + nd.note : ""}`, (key) => {let j = i;- if (key && key.startsWith("Arrow")) { j = Math.max(0, Math.min(n - 1, i + (key === "ArrowRight" || key === "ArrowDown" ? 1 : -1))); B[j].g.focus(); }+ if (key && key.startsWith("Arrow")) { j = step(i, n, key, ["ArrowRight", "ArrowDown"]); B[j].g.focus(); }if (key === "hover") return;api.poke(() => { from = sel >= 0 ? sel : n - 1; sel = j; });});const r = el("rect", { x: q.x, y: q.y, width: bw, height: bh, rx: 14, fill: C.ink2, "stroke-width": 2.5 }, g);const no = txt(g, q.x + 12, q.y + 20, String(i + 1), 12, C.faint, { "font-family": MONO, "font-weight": 700 });- const L = wrap(nd.label, Math.max(7, Math.floor(bw / 9.4))).slice(0, 2);- lines(g, q.x + bw / 2, q.y + bh / 2 + (L.length > 1 ? -2 : 7), L, 16.5, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 20);+ const T2 = wrap(nd.label, Math.max(7, Math.floor(bw / 9.4))).slice(0, 2);+ lines(g, q.x + bw / 2, q.y + bh / 2 + (T2.length > 1 ? -2 : 7), T2, 16.5, C.paper, { "text-anchor": "middle", "font-weight": 600 }, 20);ring(g, q.x - 4, q.y - 4, bw + 8, bh + 8, 16);return { g, r, no };});+ // Arrow labels go on last, above the row, so a neighbouring box never covers them.+ edges.forEach((e, i) => {+ const lab = (data.labels || [])[i];+ if (!lab) return;+ const s = String(lab).slice(0, 16), g = (e.lg = el("g", {}, svg)), w = s.length * 7.4 + 14;+ const cx = e.down ? e.a.x + bw / 2 + 12 + w / 2 : (e.xa + e.xb) / 2, cy = e.down ? (e.a.y + bh + e.b.y) / 2 - 2 : e.a.y - 14;+ el("rect", { x: cx - w / 2, y: cy - 11, width: w, height: 22, rx: 11, fill: C.ink, stroke: C.y, "stroke-width": 1.5 }, g);+ txt(g, cx, cy + 4.5, s, 13, C.y, { "text-anchor": "middle", "font-weight": 700 });+ if (!e.down) el("path", { d: `M${cx} ${cy + 11}V${e.a.y + bh / 2 - 6}`, stroke: C.y, "stroke-width": 1.5, "stroke-dasharray": "3 3" }, g);+ });const dot = el("circle", { r: 9, fill: C.y, stroke: C.ink, "stroke-width": 3 }, svg);- const who = actor(svg, data.host || "pam"), bub = bubble(svg, 18);- hint(svg, "TAP A STEP");+ const Hs = host(svg, L, data.host || "pam");+ hint(svg, "TAP A STEP", L);const ctr = (i) => ({ x: pos[i].x + bw / 2, y: pos[i].y - 2 });const draw = (t) => {const cur = sel >= 0 ? sel : Math.min(n - 1, Math.floor((t - T0) / STEP));@@ -366,16 +422,13 @@});edges.forEach((e, i) => {const a = T0 + i * STEP + 0.25, k = sel >= 0 ? 1 : io(p(t, a, a + 0.5));- set(e.path, { "stroke-dashoffset": e.len * (1 - k) }); set(e.head, { opacity: p(k, 0.9, 1) }); if (e.lt) set(e.lt, { opacity: k });+ set(e.path, { "stroke-dashoffset": e.len * (1 - k) }); set(e.head, { opacity: p(k, 0.9, 1) }); if (e.lg) set(e.lg, { opacity: k });});- let dx, dy;- if (sel >= 0) { const a = ctr(from), b = ctr(sel), m = io(api.ui.k); dx = lerp(a.x, b.x, m); dy = lerp(a.y, b.y, m) - hopY(api.ui.k) * 26; }- else { const i = Math.max(0, cur), a = ctr(Math.max(0, i - 1)), b = ctr(i), m = io(p(t, T0 + i * STEP - 0.3, T0 + i * STEP + 0.2)); dx = lerp(a.x, b.x, m); dy = lerp(a.y, b.y, m) - hopY(m) * 26; }- set(dot, { cx: dx, cy: dy, opacity: t >= T0 - 0.2 || sel >= 0 ? 1 : 0 });- const wk = walk(t, 0.1, 1.2, W + 50, 856);- who.draw({ x: wk.x, step: wk.step, arm: t > 1.3 ? (t < T || sel >= 0 ? "up-left" : "left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) });- const line = sel >= 0 ? nodes[sel].note || nodes[sel].label : data.say || "";- bub.set(line); bub.draw(856, GROUND - who.top - 4, line ? (sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5)) : 0);+ let A, Bq, m;+ if (sel >= 0) { A = ctr(from); Bq = ctr(sel); m = io(api.ui.k); }+ else { const i = Math.max(0, cur); A = ctr(Math.max(0, i - 1)); Bq = ctr(i); m = io(p(t, T0 + i * STEP - 0.3, T0 + i * STEP + 0.2)); }+ set(dot, { cx: lerp(A.x, Bq.x, m), cy: lerp(A.y, Bq.y, m) - hopY(m) * 22, opacity: t >= T0 - 0.2 || sel >= 0 ? 1 : 0 });+ Hs.draw(t, { arm: t > 1.5 ? (t < T || sel >= 0 ? "up-left" : "left") : "", hop: sel >= 0 ? api.ui.k : p(t, T, T + 0.4) }, sel >= 0 ? nodes[sel].note || nodes[sel].label : data.say, sel >= 0 ? api.ui.k : p(t, T + 0.1, T + 0.5));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -383,36 +436,33 @@/* before-after. data: { kicker, title, before: { label, lines: [] }, after: { label, lines: [] }, host, say } */SCENES["before-after"] = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.5]);- const bx = 60, by = 140, bw = 644, bh = 318, mid = bx + bw / 2;+ const L = stage(svg, data, api.L, [0.35, 0.5]);+ const bx = L.x0, by = L.top, bw = L.x1 - L.x0, bh = L.bot - L.top + 6, mid = bx + bw / 2, chars = Math.floor((bw - 56) / 14.6);let side = 1, flips = 0;const card = hit(svg, "Flip between before and after", (key) => { if (key === "hover") return; api.poke(() => { side = 1 - side; flips++; }, 420); });const face = (d, after) => {const g = el("g", {}, card), rows = [];el("rect", { x: bx, y: by, width: bw, height: bh, rx: 18, fill: after ? C.paper : C.ink2, stroke: after ? C.y : C.line, "stroke-width": after ? 4 : 2 }, g);chip(g, bx + 24, by + 22, String((d && d.label) || (after ? "After" : "Before")).toUpperCase(), after ? C.y : C.soft);- ((d && d.lines) || []).forEach((s) => wrap(s, 36).forEach((l) => rows.push(l)));- const lh = Math.min(42, 222 / Math.max(1, rows.length));- lines(g, bx + 28, by + 98, rows.slice(0, 9), Math.min(27, lh * 0.66), after ? C.ink : C.soft, { "font-weight": after ? 600 : 500 }, lh);+ ((d && d.lines) || []).forEach((s) => wrap(s, chars).forEach((l) => rows.push(l)));+ const lh = Math.min(42, (bh - 96) / Math.max(1, rows.length));+ lines(g, bx + 28, by + 98, rows.slice(0, 10), Math.min(27, lh * 0.66), after ? C.ink : C.soft, { "font-weight": after ? 600 : 500 }, lh);return g;};const A = face(data.before, 0), Bf = face(data.after, 1);ring(card, bx, by, bw, bh, 18);- const who = actor(svg, data.host || "dwight"), bub = bubble(svg, 18);- hint(svg, "TAP THE CARD TO FLIP");+ const Hs = host(svg, L, data.host || "dwight");+ hint(svg, L.tall ? "TAP THE CARD" : "TAP THE CARD TO FLIP", L);const F1 = 3.2, F2 = 8.2, D = 0.6;const draw = (t) => {// m runs 0 (before) to 1 (after)- let m;- if (flips) m = lerp(1 - side, side, io(api.ui.k));- else m = io(p(t, F1, F1 + D)) - io(p(t, F2, F2 + D));- const sx = Math.abs(Math.cos(m * Math.PI)), showAfter = m > 0.5;- A.setAttribute("display", showAfter ? "none" : "inline"); Bf.setAttribute("display", showAfter ? "inline" : "none");- set(card, { transform: `translate(${mid} 0) scale(${Math.max(0.02, sx)} 1) translate(${-mid} 0)` });- const wk = walk(t, 0.2, 1.4, W + 50, 856), land = flips ? (side ? api.ui.k : 0) : Math.min(p(t, F1 + D, F1 + D + 0.4), 1 - p(t, F2 - 0.4, F2 - 0.1));- who.draw({ x: wk.x, step: wk.step, arm: t > 1.5 ? (showAfter ? "up-left" : "left") : "", hop: flips ? api.ui.k : p(t, F1 + D - 0.1, F1 + D + 0.35) });- bub.set(data.say || ""); bub.draw(856, GROUND - who.top - 4, data.say ? land : 0);+ const m = flips ? lerp(1 - side, side, io(api.ui.k)) : io(p(t, F1, F1 + D)) - io(p(t, F2, F2 + D)), after = m > 0.5;+ A.setAttribute("display", after ? "none" : "inline"); Bf.setAttribute("display", after ? "inline" : "none");+ set(card, { transform: `translate(${mid} 0) scale(${Math.max(0.02, Math.abs(Math.cos(m * Math.PI)))} 1) translate(${-mid} 0)` });+ const land = flips ? (side ? api.ui.k : 0) : Math.min(p(t, F1 + D, F1 + D + 0.4), 1 - p(t, F2 - 0.4, F2 - 0.1));+ Hs.draw(t, { arm: t > 1.5 ? (after ? "up-left" : "left") : "", hop: flips ? api.ui.k : p(t, F1 + D - 0.1, F1 + D + 0.35) }, data.say, land);};return { draw, dur: F2 + D + 1.2, still: F1 + D + 1 };},@@ -420,29 +470,27 @@/* counter. data: { kicker, title, from, to, prefix, suffix, label, note, host, say } */SCENES.counter = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.35, 0.55]);+ const L = stage(svg, data, api.L, [0.35, 0.55]);const a = +data.from || 0, b = +data.to || 0, dec = Math.max(decimals(data.from || 0), decimals(data.to || 0)), full = (data.prefix || "") + num(b, dec) + (data.suffix || "");- const size = Math.min(150, 1060 / Math.max(4, full.length)), cx = 382, cy = 330, T0 = 1.0, RUN = 2.2, T = T0 + RUN;+ const Wd = L.x1 - L.x0, size = Math.min(150, (Wd * 1.6) / Math.max(4, full.length)), cx = L.x0 + Wd / 2, cy = L.top + (L.bot - L.top) * 0.55, T0 = 1.0, RUN = 2.2, T = T0 + RUN;let replays = 0;const g = hit(svg, `${full}${data.label ? " " + data.label : ""}. Press to count again.`, (key) => { if (key === "hover") return; api.poke(() => { replays++; }, 1400); });const big = txt(g, cx, cy, "", size, C.y, { "text-anchor": "middle", "font-family": MONO, "font-weight": 700 });- el("rect", { x: 82, y: cy + 34, width: 600, height: 8, rx: 4, fill: C.line }, g);- const bar = el("rect", { x: 82, y: cy + 34, height: 8, rx: 4, fill: C.y }, g);- if (data.label) lines(g, cx, cy + 82, wrap(data.label, 44).slice(0, 2), 23, C.paper, { "text-anchor": "middle", "font-weight": 600 });- if (data.note) txt(g, cx, cy + 142, String(data.note).slice(0, 70), 14, C.faint, { "text-anchor": "middle" });- ring(g, 60, cy - size - 6, 644, size + 170, 18);- const who = actor(svg, data.host || "kevin"), bub = bubble(svg, 18);- hint(svg, "TAP THE NUMBER");+ el("rect", { x: L.x0 + 22, y: cy + 34, width: Wd - 44, height: 8, rx: 4, fill: C.line }, g);+ const bar = el("rect", { x: L.x0 + 22, y: cy + 34, height: 8, rx: 4, fill: C.y }, g);+ if (data.label) lines(g, cx, cy + 82, wrap(data.label, L.tall ? 34 : 44).slice(0, 2), 23, C.paper, { "text-anchor": "middle", "font-weight": 600 });+ if (data.note) lines(g, cx, cy + 142, wrap(data.note, L.tall ? 56 : 76).slice(0, 2), 14, C.faint, { "text-anchor": "middle" });+ ring(g, L.x0, cy - size - 6, Wd, size + 176, 18);+ const Hs = host(svg, L, data.host || "kevin");+ hint(svg, "TAP THE NUMBER", L);const draw = (t) => {const k = replays ? out(p(api.ui.k, 0, 0.8)) : out(p(t, T0, T)), done = replays ? p(api.ui.k, 0.8, 1) : p(t, T, T + 0.35);big.textContent = (data.prefix || "") + num(lerp(a, b, k), dec) + (data.suffix || "");- const sc = 1 + 0.09 * hopY(done);- set(big, { transform: `translate(${cx} ${cy}) scale(${sc}) translate(${-cx} ${-cy})`, opacity: replays ? 1 : p(t, 0.5, 0.9) });- set(bar, { width: 600 * k });- const wk = walk(t, 0.2, 1.4, W + 50, 856);- who.draw({ x: wk.x, step: wk.step, arm: done > 0 ? "raise" : t > 1.5 ? "up-left" : "", hop: done });- bub.set(data.say || ""); bub.draw(856, GROUND - who.top - 4, data.say ? (replays ? done : p(t, T + 0.2, T + 0.6)) : 0);+ set(big, { transform: `translate(${cx} ${cy}) scale(${1 + 0.09 * hopY(done)}) translate(${-cx} ${-cy})`, opacity: replays ? 1 : p(t, 0.5, 0.9) });+ set(bar, { width: (Wd - 44) * k });+ Hs.draw(t, { arm: done > 0 ? "raise" : t > 1.5 ? "up-left" : "", hop: done }, data.say, replays ? done : p(t, T + 0.2, T + 0.6));};return { draw, dur: T + 4.5, still: T + 1 };},@@ -450,22 +498,23 @@/* stage. data: { kicker, title, board: { label, lines: [] }, script: [{ who, say, point ("left", "right", "up-left", "up-right", "raise"), carry }] } */SCENES.stage = {+ tall: true,build(svg, data, api) {- stage(svg, data, [0.5, 0.7]);+ const L = stage(svg, data, api.L, [0.5, 0.7]);const sc = (data.script || []).slice(0, 5), names = [];sc.forEach((l) => { if (!names.includes(l.who)) names.push(l.who); });- const n = names.length || 1, X = (i) => (n === 1 ? 480 : lerp(150, 810, i / (n - 1))), SAY = 2.6, IN = 1.0, S = data.board ? 4 : 6;- floor(svg, 40, W - 40);+ const n = names.length || 1, S = data.board ? 4 : L.tall && n > 3 ? 5 : 6, edge = L.tall ? 66 : 150, X = (i) => (n === 1 ? L.W / 2 : lerp(edge, L.W - edge, i / (n - 1))), SAY = 2.6, IN = 1.0, G = L.gy;+ floor(svg, L.tall ? 16 : 40, L.W - (L.tall ? 16 : 40), G);if (data.board) {- const L = [];- (data.board.lines || []).forEach((s) => wrap(s, 40).forEach((l) => L.push(l)));- const bh = 62 + Math.min(4, L.length) * 27, by = data.title ? 128 : 60;- el("rect", { x: 250, y: by, width: 460, height: bh, rx: 16, fill: C.ink2, stroke: C.line, "stroke-width": 2 }, svg);- if (data.board.label) chip(svg, 270, by + 16, String(data.board.label).toUpperCase());- lines(svg, 272, by + (data.board.label ? 76 : 44), L.slice(0, 4), 19, C.paper, { "font-weight": 600 }, 27);+ const bw = Math.min(460, L.W - 56), bx = (L.W - bw) / 2, by = L.top - 22, T = [];+ (data.board.lines || []).forEach((s) => wrap(s, Math.floor((bw - 44) / 9.6)).forEach((l) => T.push(l)));+ const rows = T.slice(0, L.tall ? 7 : 4), ty = by + (data.board.label ? 72 : 36);+ el("rect", { x: bx, y: by, width: bw, height: ty - by + rows.length * 23 - 6, rx: 16, fill: C.ink2, stroke: C.line, "stroke-width": 2 }, svg);+ if (data.board.label) chip(svg, bx + 20, by + 16, String(data.board.label).toUpperCase());+ lines(svg, bx + 22, ty, rows, 17, C.paper, { "font-weight": 600 }, 23);}// each line: its actor walks in on first use, then speaks- let t0 = 0.3; const seen = {}, beats = sc.map((l) => { const first = !seen[l.who]; seen[l.who] = 1; const b = { l, i: names.indexOf(l.who), first, in: t0, at: t0 + (first ? IN : 0.15) }; t0 = b.at + SAY; return b; });+ let t0 = 0.3; const seen = {}, beats = sc.map((l) => { const first = !seen[l.who]; seen[l.who] = 1; const b = { l, i: names.indexOf(l.who), in: t0, at: t0 + (first ? IN : 0.15) }; t0 = b.at + SAY; return b; });const T = t0;let sel = -1;const A = names.map((nm, i) => {@@ -474,10 +523,12 @@const carry = (sc.find((l) => l.who === nm && l.carry) || {}).carry, cg = carry ? el("g", {}, g) : null;if (cg) { const w = Math.max(60, String(carry).length * 10 + 26); el("rect", { x: -w / 2, y: -30, width: w, height: 30, rx: 8, fill: C.y, stroke: C.ink, "stroke-width": 3 }, cg); txt(cg, 0, -9.5, String(carry).slice(0, 14), 15, C.ink, { "text-anchor": "middle", "font-weight": 700 }); }const r = ring(g, -11 * S, -34 * S, 22 * S, 34 * S + 34, 14);- return { g, a, tag, cg, r, x: X(i), from: X(i) < 480 ? -20 * S : W + 20 * S };+ return { g, a, tag, cg, r, x: X(i), from: X(i) < L.W / 2 ? -20 * S : L.W + 20 * S };});- const bub = bubble(svg, 26);- hint(svg, "TAP A CHARACTER");+ // With a board on the wide stage the bubble is wider and two lines at most, so it stays under the board.+ const bub = bubble(svg, L.tall ? 24 : data.board ? 34 : 26, 19, L);+ if (data.board && !L.tall) bub.maxLines = 2;+ hint(svg, "TAP A CHARACTER", L);const lastLine = (i) => { let s = ""; sc.forEach((l) => { if (l.who === names[i]) s = l.say; }); return s; };const draw = (t) => {let talk = -1, k = 0, line = "";@@ -487,22 +538,53 @@const b0 = beats.find((b) => b.i === i), w = b0 ? walk(t, b0.in, b0.in + IN, o.from, o.x) : { x: o.x, step: 0 };const cur = sel < 0 ? beats.filter((b) => b.i === i && t >= b.at).pop() : null, here = talk === i;const carrying = o.cg && (!cur || cur.l.carry || sel >= 0);- const arm = carrying ? "" : here && sel < 0 && cur && cur.l.point ? cur.l.point : t >= T && sel < 0 ? "raise" : here ? (o.x < 480 ? "up-right" : "up-left") : "";+ const arm = carrying ? "" : here && sel < 0 && cur && cur.l.point ? cur.l.point : t >= T && sel < 0 ? "raise" : here ? (o.x < L.W / 2 ? "up-right" : "up-left") : "";const hop = sel === i ? api.ui.k : sel < 0 ? p(t, T + i * 0.08, T + 0.4 + i * 0.08) : 0;- o.a.draw({ x: w.x, step: w.step, arm, hop, bob: here && Math.floor(t * 6) % 2 && sel < 0 });- set(o.r, { transform: `translate(${Math.round(w.x)} ${GROUND})` });- set(o.tag, { x: Math.round(w.x), y: GROUND + 26, fill: here ? C.y : C.faint });- if (o.cg) set(o.cg, { transform: `translate(${Math.round(w.x)} ${GROUND - 5.5 * S - hopY(hop) * 9 * S})`, opacity: carrying ? 1 : 0 });+ o.a.draw({ x: w.x, y: G, step: w.step, arm, hop, bob: here && Math.floor(t * 6) % 2 && sel < 0 });+ set(o.r, { transform: `translate(${Math.round(w.x)} ${G})` });+ set(o.tag, { x: Math.round(w.x), y: G + 22, fill: here ? C.y : C.faint });+ if (o.cg) set(o.cg, { transform: `translate(${Math.round(w.x)} ${G - 5.5 * S - hopY(hop) * 9 * S})`, opacity: carrying ? 1 : 0 });});- bub.set(line); bub.draw(talk >= 0 ? A[talk].x : 0, GROUND - 32 * S - 4, talk >= 0 && line ? k : 0);+ bub.set(line); bub.draw(talk >= 0 ? A[talk].x : 0, G - 32 * S - 4, talk >= 0 && line ? k : 0);};return { draw, dur: T + 1.6, still: beats.length ? beats[Math.min(beats.length - 1, 1)].at + 1.2 : 1 };},};+ /* title. The title card of a post: big title, kicker, two or three cast members, nothing to tap.+ data: { kicker, title, sub, cast: [names], say }. Screenshot it with ?mgstill at 1600 by 900 for the title image. */+ SCENES.title = {+ tall: true,+ build(svg, data, api) {+ const L = stage(svg, { kicker: data.kicker }, api.L, [0.72, 0.8]);+ const cast = (data.cast && data.cast.length ? data.cast : ["michael", "jim"]).slice(0, 3), n = cast.length, S = 6, G = L.gy;+ const T = wrap(data.title || "", L.tall ? 15 : 27).slice(0, L.tall ? 4 : 3), size = L.tall ? 52 : T.length > 2 ? 54 : 60, lh = size * 1.1, y0 = (data.kicker ? 92 : 50) + size;+ el("ellipse", { cx: L.tall ? L.W / 2 : L.W - 70 - (n - 1) * 60, cy: G - 60, rx: 120 + n * 70, ry: 150, fill: C.y, opacity: 0.07 }, svg);+ floor(svg, L.tall ? 16 : 40, L.W - (L.tall ? 16 : 40), G);+ const rows = T.map((s, i) => txt(svg, L.x0, y0 + i * lh, s, size, C.paper, { "font-weight": 700, "letter-spacing": "-0.02em" }));+ const subT = data.sub ? wrap(data.sub, L.tall ? 40 : 38).slice(0, 2) : [], sub = subT.length ? lines(svg, L.x0, L.tall ? y0 + T.length * lh + 4 : G - 44, subT, L.tall ? 19 : 21, C.y, { "font-weight": 600 }, 27) : null;+ const X = (i) => (L.tall ? L.W / 2 + (i - (n - 1) / 2) * 140 : L.W - 96 - (n - 1 - i) * 132);+ const A = cast.map((nm) => actor(svg, nm, S)), bub = bubble(svg, 20, 19, L);+ bub.maxLines = 2;+ const draw = (t) => {+ rows.forEach((r, i) => { const k = out(p(t, 0.2 + i * 0.16, 0.8 + i * 0.16)); set(r, { opacity: k, transform: `translate(0 ${(1 - k) * 26})` }); });+ if (sub) set(sub, { opacity: p(t, 1.0, 1.5) });+ A.forEach((a, i) => {+ const s0 = 0.7 + i * 0.35, w = walk(t, s0, s0 + 1.1, L.W + 80 + i * 60, X(i)), h0 = 2.6 + i * 0.18, h1 = 6.2 + i * 0.18;+ a.draw({ x: w.x, y: G, step: w.step, hop: Math.max(p(t, h0, h0 + 0.4) < 1 ? p(t, h0, h0 + 0.4) : 0, p(t, h1, h1 + 0.4) < 1 ? p(t, h1, h1 + 0.4) : 0), arm: w.step || t < 2.4 ? "" : i === 0 ? "up-left" : i === n - 1 && n > 1 ? "raise" : "" });+ });+ bub.set(data.say || ""); bub.draw(X(0), G - 32 * S - 4, data.say ? Math.min(p(t, 3.0, 3.4), 1 - p(t, 7.2, 7.5)) : 0);+ };+ return { draw, dur: 8, still: 4.2 };+ },+ };+const reduce = () => matchMedia("(prefers-reduced-motion: reduce)").matches;const slug = () => location.pathname.split("/").filter(Boolean).pop() || "";const send = (name, scene) => { try { if (window.posthog && window.posthog.capture) window.posthog.capture(name, { slug: slug(), scene }); } catch (e) { /* analytics never breaks a page */ } };+ const params = new URLSearchParams(location.search);+ // Tall stage for a kit scene in a narrow column. Custom scenes stay wide unless they set tall: true and read api.L.+ const wantTall = (fig, sc) => !!sc.tall && (params.get("mgtall") != null ? params.get("mgtall") !== "0" : fig.clientWidth > 0 && fig.clientWidth < 520);function mount(fig) {const name = fig.dataset.scene, sc = SCENES[name], img = fig.querySelector("img");@@ -510,32 +592,37 @@let data = {};const js = fig.querySelector('script[type="application/json"]');if (js) data = JSON.parse(js.textContent); else if (fig.dataset.mg) data = JSON.parse(fig.dataset.mg);- const svg = el("svg", { viewBox: `0 0 ${W} ${H}`, role: "group", "aria-label": img.alt, class: "mg-svg" });- let t = 0, last = 0, on = false, raf = 0, tw = 0, held = false, obs = null, draw, dur, still;- const q = new URLSearchParams(location.search).get("mgstill"), frozen = q != null;+ const tall = wantTall(fig, sc), L = tall ? TALL : WIDE;+ const svg = el("svg", { viewBox: `0 0 ${L.W} ${L.H}`, role: "group", "aria-label": img.alt, class: "mg-svg" + (tall ? " mg-tall" : "") });+ let t = 0, last = 0, on = false, raf = 0, tw = 0, held = false, obs = null, ro = null, draw, dur, still;+ const q = params.get("mgstill"), frozen = q != null;+ const again = { g: null };const api = {- ui: { k: 1 }, data,+ ui: { k: 1 }, data, L,// A reader did something: stop the story on its still frame, apply the change, and play a short move (ui.k from 0 to 1).poke(change, ms) {if (!fig._mgTouched) { fig._mgTouched = true; send("blog_scene_interact", name); }held = true; cancelAnimationFrame(raf); cancelAnimationFrame(tw);if (change) change();- again.removeAttribute("display"); svg.querySelectorAll(".mg-hint").forEach((n) => n.setAttribute("display", "none"));+ again.g.removeAttribute("display"); svg.querySelectorAll(".mg-hint").forEach((n) => n.setAttribute("display", "none"));if (reduce() || frozen) { api.ui.k = 1; return draw(still); }const a = performance.now(), d = ms || 340;- const step = (now) => { api.ui.k = clamp((now - a) / d); draw(still); if (api.ui.k < 1) tw = requestAnimationFrame(step); };- api.ui.k = 0; tw = requestAnimationFrame(step);+ const tick = (now) => { api.ui.k = clamp((now - a) / d); draw(still); if (api.ui.k < 1) tw = requestAnimationFrame(tick); };+ api.ui.k = 0; tw = requestAnimationFrame(tick);},};const built = sc.build(svg, data, api);draw = built.draw || built; dur = built.dur || sc.dur || 10; still = built.still || sc.still || dur * 0.6;+ const remount = () => { cancelAnimationFrame(raf); cancelAnimationFrame(tw); if (obs) obs.disconnect(); if (ro) ro.disconnect(); delete fig.dataset.mgLive; svg.replaceWith(img); mount(fig); };// Play again: shown once a reader has taken over.- const again = hit(svg, "Play the animation again", (key) => { if (key) return; cancelAnimationFrame(tw); obs && obs.disconnect(); delete fig.dataset.mgLive; svg.replaceWith(img); mount(fig); const b = fig.querySelector(".mg-hit"); if (b) b.focus({ preventScroll: true }); });- el("rect", { x: W - 122, y: 22, width: 98, height: 30, rx: 15, fill: C.ink3 }, again);- txt(again, W - 73, 42, "PLAY AGAIN", 12, C.paper, { "text-anchor": "middle", "font-weight": 700, "letter-spacing": "0.1em" });- ring(again, W - 122, 22, 98, 30, 15);- again.setAttribute("display", "none");+ again.g = hit(svg, "Play the animation again", (key) => { if (key) return; remount(); const b = fig.querySelector(".mg-hit"); if (b) b.focus({ preventScroll: true }); });+ el("rect", { x: L.W - 122, y: 22, width: 98, height: 30, rx: 15, fill: C.ink3 }, again.g);+ txt(again.g, L.W - 73, 42, "PLAY AGAIN", 12, C.paper, { "text-anchor": "middle", "font-weight": 700, "letter-spacing": "0.1em" });+ ring(again.g, L.W - 122, 22, 98, 30, 15);+ again.g.setAttribute("display", "none");img.replaceWith(svg); fig.dataset.mgLive = "1";+ // A phone turned on its side, or a resized window: swap between the tall and the wide stage.+ if (window.ResizeObserver) { ro = new ResizeObserver(() => { if (wantTall(fig, sc) !== tall) remount(); }); ro.observe(fig); }if (frozen || reduce()) return draw(q ? +q : still);const loop = (now) => {if (!on || held) return;@@ -552,8 +639,8 @@}const MG = {- C, W, H, GROUND, GROT, MONO, CAST, el, set, txt, lines, wrap, num, p, io, out, back, lerp, clamp, hopY,- stage, floor, chip, actor, walk, bubble, hit, ring, hint,+ C, W, H, GROUND, WIDE, TALL, GROT, MONO, CAST, el, set, txt, lines, wrap, num, p, io, out, back, lerp, clamp, hopY,+ stage, floor, chip, actor, walk, bubble, host, hit, ring, hint,scene(name, def) { SCENES[name] = def; },mount,};diff --git a/docs/pr-evidence/after-blog-mg-kit-phone.png b/docs/pr-evidence/after-blog-mg-kit-phone.pngnew file mode 100644index 00000000..f0e4c4e8Binary files /dev/null and b/docs/pr-evidence/after-blog-mg-kit-phone.png differdiff --git a/docs/pr-evidence/after-blog-mg-kit.png b/docs/pr-evidence/after-blog-mg-kit.pngindex ae75b3f6..a02dccbb 100644Binary files a/docs/pr-evidence/after-blog-mg-kit.png and b/docs/pr-evidence/after-blog-mg-kit.png differ