Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

chore: resync Codex mirror

Alex Greenshpun257ed5d87f5e
diff --git a/plugins/anidoodle/skills/anidoodle/SKILL.md b/plugins/anidoodle/skills/anidoodle/SKILL.md
index 5e5c665..6fb3864 100644
--- a/plugins/anidoodle/skills/anidoodle/SKILL.md
+++ b/plugins/anidoodle/skills/anidoodle/SKILL.md
@@ -44,7 +44,7 @@ say why in one line. Write the answers into a short brief before drawing.
- Music: pick a style vocabulary and mood, compose your own harmony, motif and form (references/music/compose.md), then node tools/music.mjs check <score.ts#export> must PASS before a human listens. Styles give sound, never notes.
- Sound effects: references/music/sound-design.md. 14 layered, seeded effects cued by film frame (filmSfx); the score ducks, and every cue must be within 6 dB of it. Effects only on real direction changes, one riser + one impact per film.
-- Launch films: `launchTemplate.ts` renders a product's launch from data: prompts, plates drawn for it, a score composed for it, words, install lines; habits that save tokens are in `references/working-method.md`.
+- Launch films: `launchTemplate.ts` renders a product's launch from data (prompts, plates or its own UI, a score composed for it, words, install lines) in every shape from one timeline; `launch.mjs new|ship`. Habits that save tokens: `references/working-method.md`.
## The seven laws
@@ -102,8 +102,8 @@ draws itself declares `kind: "drawing"` and is judged on a finer floor; a freeze
`engine/` is the portable art core plus the tooling. `engine/src/canvas-core` knows nothing
about the DOM or any backend. `W`, `H`, `fps` and `durationFrames` come from the film's `meta`.
Camera moves (pans, zooms, parallax, shake) come from `engine/src/canvas-core/camera.ts`:
-`references/camera.md`. `render.mjs --blur N` renders with motion blur (N subframes averaged in
-linear light per frame); the default path is untouched.
+`references/camera.md`. `render.mjs --blur auto` renders with motion blur (subframes per frame
+from its measured on-screen speed, averaged in linear light, `--shutter 180`); the default path is untouched.
```bash
node <skill>/engine/tools/scaffold.mjs ~/art --film intro --format 9x16 --duration 12 # seconds
@@ -121,7 +121,8 @@ node tools/emit.mjs intro --out out/intro.html # one self-co
| `gate.mjs` | determinism, contract, dead air, artifact; `--self-test` proves it can fail |
| `registry.mjs` / `gallery.mjs` | the style list from the plates themselves / the gallery sheet |
| `docs-check.mjs` | fails when any doc's style count, length or path disagrees with the code |
-| `verify-export.mjs` | QA on the rendered file: frames, duration, score; opt-in first frame, loop seam, `--delivery` |
+| `verify-export.mjs` | QA on the rendered file: frames, duration, score, A/V sync, true peak after the encode; opt-in first frame, loop seam, `--delivery` |
+| `launch.mjs` | a launch film: `new <name>` scaffolds the spec; `ship <name> --shapes 16x9,9x16` renders, posters, captions, verifies each |
| `test.mjs` (`npm test`) | unit suites in `engine/test/`, no browser |
| `music.mjs` | `vocab` prints a style's vocabulary; `check` gates your composed score; `render`, `meter` |
| `sfx.mjs` | the sound-effects kit: `list`, `one`, `kit <dir>`, `test` |
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/film.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/film.ts
index 493f93b..152f23c 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/film.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/film.ts
@@ -21,7 +21,15 @@ export type Film = { meta: {
// the score as fitted to this film: its tempo and form; render prints it next to the grid's bpm.
// grid: the film's cuts sit on meta.bpm, so the score must play within 0.5 % of it (render refuses otherwise)
score?: { tempo: number; form: string; grid?: boolean };
-}; assets: Assets; shots: Shot[]; audio?: (sampleRate: number) => [Float32Array, Float32Array] };
+ // frame-cued sync points the delivered file is checked against (verify-export: audio-to-video sync), and
+ // the words a viewer reads, for .srt/.vtt captions: both in frames of this film
+ sync?: { frame: number; label: string }[];
+ captions?: { from: number; to: number; text: string }[];
+ // a legible frame for the poster image and the thumbnail (render --poster-frame, launch.mjs ship)
+ poster?: number;
+}; assets: Assets; shots: Shot[]; audio?: (sampleRate: number) => [Float32Array, Float32Array];
+ // the same film composed for another frame shape (launch template films); hosts/page.ts calls it for <film>-<shape>
+ reshape?: (shape: string) => Film };
// Cheap structural checks every adapter runs before frame 0. (The full gate is Phase 2.)
export const validate = (film: Film): string[] => {
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/kinetic.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/kinetic.ts
index 0275fec..3343bdf 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/kinetic.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/kinetic.ts
@@ -385,3 +385,26 @@ export const caption = (ctx: Ctx, env: Env, text: string, x: number, y: number,
}
ctx.restore();
};
+
+// ---------------------------------------------------------------- set type (the clean register)
+// Type as the design: a line SET in a heavy sans, not written. Each word rises into place from
+// behind its own baseline (a mask the size of the line), one after another, on an out-cubic: a
+// gentle move with no bounce and no fade-in. `p` 0..1 is the line's progress. Screen space.
+export type SetOpts = { color?: string; align?: "left" | "center" | "right"; weight?: number; font?: (w: number, px: number) => string; track?: number };
+const SET_FONT = (w: number, px: number) => `${w} ${px}px "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif`;
+export const setWidth = (ctx: Ctx, text: string, size: number, o: SetOpts = {}) => { ctx.font = (o.font ?? SET_FONT)(o.weight ?? 700, size); return ctx.measureText(text).width + Math.max(0, text.length - 1) * (o.track ?? -0.02) * size; };
+export const setType = (ctx: Ctx, env: Env, text: string, x: number, y: number, size: number, p: number, o: SetOpts = {}) => {
+ if (p <= 0) return;
+ screen(ctx, env); ctx.save();
+ ctx.font = (o.font ?? SET_FONT)(o.weight ?? 700, size); ctx.textBaseline = "alphabetic"; ctx.fillStyle = o.color ?? "#111214";
+ const tr = (o.track ?? -0.02) * size, words = text.split(" "), space = ctx.measureText(" ").width;
+ const wOf = (w: string) => ctx.measureText(w).width + Math.max(0, w.length - 1) * tr, total = words.reduce((a, w) => a + wOf(w), 0) + space * (words.length - 1);
+ let cx = o.align === "center" ? x - total / 2 : o.align === "right" ? x - total : x;
+ ctx.beginPath(); ctx.rect(cx - size, y - size * 1.05, total + 2 * size, size * 1.35); ctx.clip(); // the line's own window: words rise into it
+ words.forEach((w, i) => {
+ const q = Math.max(0, Math.min(1, p * (1 + 0.35 * (words.length - 1)) - 0.35 * i)), e = 1 - Math.pow(1 - q, 3);
+ if (q > 0) { const dy = (1 - e) * size * 0.9; let wx = cx; for (const ch of w) { ctx.fillText(ch, wx, y + dy); wx += ctx.measureText(ch).width + tr; } }
+ cx += wOf(w) + space;
+ });
+ ctx.restore();
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchCut.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchCut.ts
index ad01e07..57b17bf 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchCut.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchCut.ts
@@ -51,7 +51,11 @@ export const beatGrid = (bpm: number, fps: number) => {
};
// ---------------------------------------------------------------- the bloom
-export type BloomOpts = { inF?: number; outF?: number; close?: boolean; radius?: number; seed?: number; bg?: string; ink?: string; W?: number; H?: number };
+export type BloomOpts = { inF?: number; outF?: number; close?: boolean; radius?: number; seed?: number; bg?: string; ink?: string; W?: number; H?: number;
+ // where the bloom opens from (default the frame's centre): a match cut opens it from the motif (motif.ts)
+ center?: P;
+ // "circle": a clean round iris instead of the ink blot (the clean preset); rim: the ink edge's width (default 26)
+ shape?: "blot" | "circle"; rim?: number };
// A full-frame page inside an ink bloom. `under` draws the picture the bloom opens over (and closes
// onto); `page` draws the page, in screen coordinates, on an offscreen sheet. With close: false the
// bloom stays open (an end card).
@@ -68,9 +72,11 @@ export const bloomFrame = (ctx: Ctx, env: Env, local: number, len: number, under
const L = selfLayer(env, "sheet", Math.round(W * env.scale), Math.round(H * env.scale)), c = L.ctx;
c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.fillStyle = o.bg ?? C.bg; c.fillRect(0, 0, W, H);
page(c);
- const ctr: P = [W / 2, H / 2], seed = o.seed ?? 88;
+ const ctr: P = o.center ?? [W / 2, H / 2], seed = o.seed ?? 88, rim = o.rim ?? 26;
+ const edge = (r: number) => { if (o.shape === "circle") { ctx.beginPath(); ctx.arc(ctr[0], ctr[1], Math.max(0, r), 0, Math.PI * 2); } else pathOf(ctx, blot(ctr, r, seed)); };
ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.save();
- pathOf(ctx, blot(ctr, R + 26, seed)); ctx.fillStyle = o.ink ?? C.ink; ctx.fill(); pathOf(ctx, blot(ctr, Math.max(0, R - 4), seed)); ctx.clip();
+ if (rim > 0) { edge(R + rim); ctx.fillStyle = o.ink ?? C.ink; ctx.fill(); }
+ edge(Math.max(0, R - (o.shape === "circle" ? 0 : 4))); ctx.clip();
ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.drawImage(L.canvas, 0, 0); ctx.restore();
};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchExampleClean.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchExampleClean.ts
new file mode 100644
index 0000000..a02dd97
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchExampleClean.ts
@@ -0,0 +1,60 @@
+// LAUNCH EXAMPLE, CLEAN. The same template in its second look (preset "clean": a quiet canvas, one
+// accent, type as the design) for a UI-first product, at 60 fps. Three asks of the other kinds:
+// 1 the product's own UI from data: the ask typed into its command bar, its action pressed, every
+// row springing from the before state to the after state;
+// 2 a split feature beat: words in their own column, the live UI beside them (above them on a phone);
+// 3 any film in a card (here the web tour), with its words beside it.
+// Everything here is a PLACEHOLDER for a made-up product; your film's UI data comes from YOUR
+// product (its real screens, its real states), and its score is composed for its brief.
+// node tools/launch.mjs ship launchExampleClean --shapes 16x9,9x16
+import { makeLaunchFilm } from "./launchTemplate";
+import type { ProductUI } from "./productUI";
+import { webTour } from "./webTour";
+
+const inbox: ProductUI = {
+ title: "Tally", nav: ["Inbox", "Books", "Reports"], action: "Match all", command: "Ask Tally…",
+ before: {
+ stats: [{ label: "Unmatched", value: 14 }, { label: "Matched", value: 32 }],
+ items: [
+ { id: "a", label: "Design tool, Sep", value: "$144", tag: "no receipt" },
+ { id: "b", label: "Cloud hosting, Sep", value: "$1,208", tag: "no receipt" },
+ { id: "c", label: "Team lunch, Thu", value: "$86", tag: "no receipt" },
+ { id: "d", label: "Train to Leeds", value: "$42", tag: "no receipt" },
+ ],
+ },
+ after: {
+ stats: [{ label: "Unmatched", value: 0 }, { label: "Matched", value: 46 }],
+ items: [
+ { id: "b", label: "Cloud hosting, Sep", value: "$1,208", tag: "matched", done: true, accent: true },
+ { id: "a", label: "Design tool, Sep", value: "$144", tag: "matched", done: true },
+ { id: "c", label: "Team lunch, Thu", value: "$86", tag: "matched", done: true },
+ { id: "d", label: "Train to Leeds", value: "$42", tag: "matched", done: true },
+ ],
+ },
+};
+const books: ProductUI = {
+ title: "Tally", nav: ["Books", "Reports"], action: "Close month", layout: "cards",
+ before: { items: [
+ { id: "r", label: "Revenue", value: 61, unit: "%", bar: 0.61 }, { id: "c", label: "Costs", value: 48, unit: "%", bar: 0.48 },
+ { id: "p", label: "Payroll", value: 70, unit: "%", bar: 0.7 }, { id: "t", label: "Tax", value: 12, unit: "%", bar: 0.12 },
+ ] },
+ after: { items: [
+ { id: "r", label: "Revenue", value: 100, unit: "%", bar: 1, accent: true }, { id: "c", label: "Costs", value: 100, unit: "%", bar: 1 },
+ { id: "p", label: "Payroll", value: 100, unit: "%", bar: 1 }, { id: "t", label: "Tax", value: 100, unit: "%", bar: 1 },
+ ] },
+};
+
+export const launchExampleClean = makeLaunchFilm({
+ title: "Tally", preset: "clean", fps: 60,
+ asks: [
+ { kind: "ui", ui: inbox, prompt: "match every receipt from September" },
+ { kind: "ui", ui: books, split: [{ text: "Books close", style: "ink", color: "#15161a" }, { text: "themselves.", style: "ink", color: "#2f54eb" }] },
+ { kind: "film", film: webTour, from: 0, to: 359, split: [{ text: "And it shows", style: "ink", color: "#15161a" }, { text: "you where.", style: "ink", color: "#2f54eb" }] },
+ ],
+ words: [[{ text: "ASK ONCE.", style: "ink", color: "#15161a" }, { text: "DONE.", style: "ink", color: "#2f54eb" }]],
+ tagline: "Bookkeeping that does itself",
+ install: ["npm install tally", "tally init"],
+ footer: "tally.example",
+ bpm: 90, askBeats: 6, typeBeats: 4, endBeats: 8, claimBar: 6,
+ score: null, // silent here: compose this product's own score and pass it
+});
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchKit.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchKit.ts
index d9c2a4b..17de213 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchKit.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchKit.ts
@@ -126,41 +126,91 @@ export type ChatState = {
title?: string; subtitle?: string; genLabel?: string; accent?: string;
};
-export const drawChatFrame = (ctx: Ctx, s: ChatState) => {
- ctx.fillStyle = C.bg; ctx.fillRect(-2000, -2000, 6000, 6000);
+// THE CHAT'S GEOMETRY. One chat component, laid out per frame shape (launchLayout.ts): the window,
+// the composer, the button, where the typed text sits, and the type sizes of each role. `k` scales
+// every length that is not a type size (radii, gaps, strokes). `wrap` > 0: the composer holds that
+// many lines and the typed words wrap in it the way a phone composer does (the button sits on the
+// last line); 0 is the one-line desktop composer. `theme` is the palette (default C).
+export type Rect = { x: number; y: number; w: number; h: number };
+export type ChatGeom = {
+ CHAT: Rect & { r: number }; INPUT: Rect & { r: number }; GEN: Rect & { r: number };
+ REPLY: { x: number; y: number; s: number }; TEXT: { x: number; base: number; px: number };
+ k: number; px: { head: number; sub: number; bubble: number; label: number; gen: number }; wrap: number; lineH: number;
+ theme?: Partial<typeof C>;
+ drop?: string; // the ink drop's colour (default the ink): the clean preset's drop is its one accent
+ iris?: boolean; // the answer card opens as a clean round iris instead of an ink bloom (the clean preset)
+};
+export const CHAT_GEOM: ChatGeom = { CHAT, INPUT, GEN, REPLY, TEXT, k: 1, px: { head: 22, sub: 18, bubble: 26, label: 20, gen: 24 }, wrap: 0, lineH: 44 };
+// the same component at any size: derived from the window's rectangle, a length scale and the type
+// sizes. chatGeom(CHAT, 1, CHAT_GEOM.px, TEXT.px, 0) IS CHAT_GEOM (a test holds it to that).
+export const chatGeom = (chat: Rect & { r?: number }, k: number, px: ChatGeom["px"], promptPx: number, wrap = 0, genW = 166 * k): ChatGeom => {
+ const lineH = Math.round(promptPx * 1.3), h = 104 * k + Math.max(0, wrap - 1) * lineH;
+ const CH = { x: chat.x, y: chat.y, w: chat.w, h: chat.h, r: chat.r ?? 34 * k };
+ const IN = { x: CH.x + 60 * k, y: CH.y + CH.h - 36 * k - h, w: CH.w - 120 * k, h, r: 30 * k };
+ const G = { x: IN.x + IN.w - 24 * k - genW, y: IN.y + IN.h - 22 * k - 60 * k, w: genW, h: 60 * k, r: 30 * k };
+ return { CHAT: CH, INPUT: IN, GEN: G, REPLY: { x: CH.x + 100 * k, y: CH.y + 158 * k, s: 600 * k }, TEXT: { x: IN.x + 44 * k, base: IN.y + 64 * k, px: promptPx }, k, px, wrap, lineH };
+};
+const pal = (g: ChatGeom) => (g.theme ? { ...C, ...g.theme } : C);
+// the typed words as they sit in a wrapping composer: whole words per line, a word longer than the
+// line broken where it must. Measured with the real font, so the lines are what the viewer sees.
+export const composerLines = (ctx: Ctx, typed: string, g: ChatGeom): string[] => {
+ const maxW = g.GEN.x - 20 * g.k - g.TEXT.x;
+ ctx.font = SANS(500, g.TEXT.px);
+ const out: string[] = []; let line = "";
+ for (const tok of typed.split(/(?<= )/)) {
+ if (ctx.measureText(line + tok).width <= maxW || !line) line += tok; else { out.push(line); line = tok; }
+ while (ctx.measureText(line.trimEnd()).width > maxW && line.length > 1) { let cut = line.length - 1; while (cut > 1 && ctx.measureText(line.slice(0, cut)).width > maxW) cut--; out.push(line.slice(0, cut)); line = line.slice(cut); }
+ }
+ out.push(line);
+ return out;
+};
+
+export const drawChatFrame = (ctx: Ctx, s: ChatState, g: ChatGeom = CHAT_GEOM) => {
+ const { CHAT, INPUT, GEN, REPLY, TEXT, k, px } = g, P = pal(g);
+ ctx.fillStyle = P.bg; ctx.fillRect(-2000, -2000, 6000, 6000);
softShadow(ctx, CHAT.x, CHAT.y, CHAT.w, CHAT.h, CHAT.r, 1.2);
- ctx.fillStyle = C.card; rr(ctx, CHAT.x, CHAT.y, CHAT.w, CHAT.h, CHAT.r); ctx.fill();
+ ctx.fillStyle = P.card; rr(ctx, CHAT.x, CHAT.y, CHAT.w, CHAT.h, CHAT.r); ctx.fill();
// the thread's head: a small ink dot and a name, nothing that belongs to anyone else
- ctx.fillStyle = C.ink; ctx.beginPath(); ctx.arc(CHAT.x + 58, CHAT.y + 52, 9, 0, Math.PI * 2); ctx.fill();
- ctx.font = SANS(600, 22); ctx.fillStyle = C.ink; ctx.textBaseline = "middle"; ctx.fillText(s.title ?? "anidoodle", CHAT.x + 80, CHAT.y + 53);
- const subX = s.title === undefined ? CHAT.x + 196 : CHAT.x + 80 + ctx.measureText(s.title).width + 16;
- ctx.font = SANS(500, 18); ctx.fillStyle = C.mute; ctx.fillText(s.subtitle ?? "drawn in code", subX, CHAT.y + 54);
- ctx.fillStyle = C.line; ctx.fillRect(CHAT.x + 32, CHAT.y + 98, CHAT.w - 64, 1.5);
+ ctx.fillStyle = P.ink; ctx.beginPath(); ctx.arc(CHAT.x + 58 * k, CHAT.y + 52 * k, 9 * k, 0, Math.PI * 2); ctx.fill();
+ ctx.font = SANS(600, px.head); ctx.fillStyle = P.ink; ctx.textBaseline = "middle"; ctx.fillText(s.title ?? "anidoodle", CHAT.x + 80 * k, CHAT.y + 53 * k);
+ const subX = s.title === undefined ? CHAT.x + 196 * k : CHAT.x + 80 * k + ctx.measureText(s.title).width + 16 * k;
+ ctx.font = SANS(500, px.sub); ctx.fillStyle = P.mute; ctx.fillText(s.subtitle ?? "drawn in code", subX, CHAT.y + 54 * k);
+ ctx.fillStyle = P.line; ctx.fillRect(CHAT.x + 32 * k, CHAT.y + 98 * k, CHAT.w - 64 * k, 1.5 * k);
// the sent message, right aligned
if (s.sent) {
- ctx.globalAlpha = s.sentAlpha ?? 1; ctx.font = SANS(500, 26);
- const tw = ctx.measureText(s.sent).width, pad = 26, bw = tw + pad * 2, bx = CHAT.x + CHAT.w - 60 - bw, by = CHAT.y + 124;
+ ctx.globalAlpha = s.sentAlpha ?? 1; ctx.font = SANS(500, px.bubble);
+ const tw = ctx.measureText(s.sent).width, pad = 26 * k, bw = tw + pad * 2, bx = CHAT.x + CHAT.w - 60 * k - bw, by = CHAT.y + 124 * k;
let ay = by;
- if (s.attach) { const iw = 240, ih = 150; ay = by; ctx.save(); rr(ctx, CHAT.x + CHAT.w - 60 - iw, ay, iw, ih, 16); ctx.clip(); ctx.drawImage(s.attach.img, CHAT.x + CHAT.w - 60 - iw, ay, iw, ih); ctx.restore(); ay += ih + 10; }
- ctx.fillStyle = C.chip; rr(ctx, bx, ay, bw, 56, 22); ctx.fill();
- ctx.fillStyle = C.ink; ctx.textBaseline = "middle"; ctx.fillText(s.sent, bx + pad, ay + 29);
+ if (s.attach) { const iw = 240 * k, ih = 150 * k; ay = by; ctx.save(); rr(ctx, CHAT.x + CHAT.w - 60 * k - iw, ay, iw, ih, 16 * k); ctx.clip(); ctx.drawImage(s.attach.img, CHAT.x + CHAT.w - 60 * k - iw, ay, iw, ih); ctx.restore(); ay += ih + 10 * k; }
+ ctx.fillStyle = P.chip; rr(ctx, bx, ay, bw, 56 * k, 22 * k); ctx.fill();
+ ctx.fillStyle = P.ink; ctx.textBaseline = "middle"; ctx.fillText(s.sent, bx + pad, ay + 29 * k);
ctx.globalAlpha = 1;
}
- if (s.label) { ctx.globalAlpha = s.labelAlpha ?? 1; ctx.fillStyle = C.ink; ctx.beginPath(); ctx.arc(REPLY.x + 9, REPLY.y - 26, 7, 0, Math.PI * 2); ctx.fill(); ctx.font = SANS(600, 20); ctx.textBaseline = "middle"; ctx.fillText(s.label, REPLY.x + 26, REPLY.y - 25); ctx.globalAlpha = 1; }
+ if (s.label) { ctx.globalAlpha = s.labelAlpha ?? 1; ctx.fillStyle = P.ink; ctx.beginPath(); ctx.arc(REPLY.x + 9 * k, REPLY.y - 26 * k, 7 * k, 0, Math.PI * 2); ctx.fill(); ctx.font = SANS(600, px.label); ctx.textBaseline = "middle"; ctx.fillText(s.label, REPLY.x + 26 * k, REPLY.y - 25 * k); ctx.globalAlpha = 1; }
// the composer
- ctx.fillStyle = C.paper; rr(ctx, INPUT.x, INPUT.y, INPUT.w, INPUT.h, INPUT.r); ctx.fill();
- ctx.lineWidth = 2; ctx.strokeStyle = C.line; ctx.stroke();
+ ctx.fillStyle = P.paper; rr(ctx, INPUT.x, INPUT.y, INPUT.w, INPUT.h, INPUT.r); ctx.fill();
+ ctx.lineWidth = 2 * k; ctx.strokeStyle = P.line; ctx.stroke();
ctx.font = SANS(500, TEXT.px); ctx.textBaseline = "alphabetic";
- if (!s.typed && s.placeholder) { ctx.fillStyle = C.mute; ctx.fillText(s.placeholder, TEXT.x, TEXT.base); }
- ctx.fillStyle = C.ink; ctx.fillText(s.typed, TEXT.x, TEXT.base);
- const acc = s.accent ?? C.accent;
- if (s.caret) { const x = TEXT.x + ctx.measureText(s.typed).width + 3; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base - 32, 3, 40); }
+ if (!s.typed && s.placeholder) { ctx.fillStyle = P.mute; ctx.fillText(s.placeholder, TEXT.x, TEXT.base); }
+ const acc = s.accent ?? P.accent;
+ if (g.wrap > 0) {
+ const lines = composerLines(ctx, s.typed, g); ctx.font = SANS(500, TEXT.px); ctx.fillStyle = P.ink;
+ lines.forEach((l, i) => ctx.fillText(l, TEXT.x, TEXT.base + i * g.lineH));
+ if (s.caret) { const i = lines.length - 1, x = TEXT.x + ctx.measureText(lines[i]).width + 3 * k; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base + i * g.lineH - 0.94 * TEXT.px, 3 * k, 1.18 * TEXT.px); }
+ } else {
+ ctx.fillStyle = P.ink; ctx.fillText(s.typed, TEXT.x, TEXT.base);
+ if (s.caret) { const x = TEXT.x + ctx.measureText(s.typed).width + 3; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base - 32, 3, 40); }
+ }
// Generate
- const pr = s.genPress ?? 0, hot = s.genHot ?? 0, k = 1 - 0.07 * pr, gx = GEN.x + (GEN.w * (1 - k)) / 2, gy = GEN.y + (GEN.h * (1 - k)) / 2;
- ctx.fillStyle = hot > 0 ? mixHex(acc, s.accent ? deepen(acc) : C.accentDeep, 0.35 * hot + 0.4 * pr) : acc; rr(ctx, gx, gy, GEN.w * k, GEN.h * k, GEN.r * k); ctx.fill();
- ctx.fillStyle = "#fff"; ctx.font = SANS(600, 24 * k); ctx.textBaseline = "middle"; ctx.textAlign = "center"; ctx.fillText(s.genLabel ?? "Generate", GEN.x + GEN.w / 2, GEN.y + GEN.h / 2 + 1); ctx.textAlign = "left";
+ const pr = s.genPress ?? 0, hot = s.genHot ?? 0, q = 1 - 0.07 * pr, gx = GEN.x + (GEN.w * (1 - q)) / 2, gy = GEN.y + (GEN.h * (1 - q)) / 2;
+ ctx.fillStyle = hot > 0 ? mixHex(acc, s.accent ? deepen(acc) : P.accentDeep, 0.35 * hot + 0.4 * pr) : acc; rr(ctx, gx, gy, GEN.w * q, GEN.h * q, GEN.r * q); ctx.fill();
+ ctx.fillStyle = "#fff"; ctx.font = SANS(600, px.gen * q); ctx.textBaseline = "middle"; ctx.textAlign = "center"; ctx.fillText(s.genLabel ?? "Generate", GEN.x + GEN.w / 2, GEN.y + GEN.h / 2 + 1 * k); ctx.textAlign = "left";
+};
+// where the caret is: the end of the typed words (on their last line in a wrapping composer)
+export const caretAt = (ctx: Ctx, typed: string, g: ChatGeom = CHAT_GEOM): P => {
+ if (g.wrap > 0) { const lines = composerLines(ctx, typed, g), i = lines.length - 1; ctx.font = SANS(500, g.TEXT.px); return [g.TEXT.x + ctx.measureText(lines[i]).width, g.TEXT.base + i * g.lineH - 0.35 * g.TEXT.px]; }
+ ctx.font = SANS(500, g.TEXT.px); return [g.TEXT.x + ctx.measureText(typed).width, g.TEXT.base - 12];
};
-export const caretAt = (ctx: Ctx, typed: string): P => { ctx.font = SANS(500, TEXT.px); return [TEXT.x + ctx.measureText(typed).width, TEXT.base - 12]; };
const hx = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
const deepen = (h: string) => "#" + hx(h).map((v) => Math.round(v * 0.78).toString(16).padStart(2, "0")).join("");
@@ -181,24 +231,36 @@ export const charTimes = (text: string, t0: number, rate: number, seed: number)
export const typedAt = (text: string, f: number, times: number[]) => text.slice(0, times.filter((t) => f >= t).length);
// The drop: a bead of ink lifts off Generate and arcs to where the answer card will land.
export type Drop = { t0: number; land: number; full: number };
-export const inkDrop = (ctx: Ctx, f: number, d: { t0: number; land: number }, to: P) => {
- const GEN_C: P = [GEN.x + GEN.w / 2, GEN.y + GEN.h / 2];
+export const inkDrop = (ctx: Ctx, f: number, d: { t0: number; land: number }, to: P, g: ChatGeom = CHAT_GEOM) => {
+ const { GEN, k } = g, ink = g.drop ?? pal(g).ink, GEN_C: P = [GEN.x + GEN.w / 2, GEN.y + GEN.h / 2];
if (f < d.t0 - 6 || f >= d.land) return;
- if (f < d.t0) { const w = out3(ramp(f, d.t0 - 6, d.t0)); ctx.fillStyle = C.ink; ctx.beginPath(); ctx.arc(GEN_C[0], GEN.y + 6 - w * 22, 30 * (0.3 + 0.7 * w), 0, Math.PI * 2); ctx.fill(); return; }
- const at = (g: number): P => { const u = ramp(g, d.t0, d.land), e = inOut(u); return [lerp(GEN_C[0], to[0], e), lerp(GEN.y - 16, to[1], e) - Math.sin(Math.PI * u) * 150]; };
- for (let k = 24; k >= 0; k--) { const p = at(f - k * 0.1); ctx.fillStyle = C.ink; ctx.globalAlpha = k === 0 ? 1 : 0.22 * (1 - k / 25); ctx.beginPath(); ctx.arc(p[0], p[1], 30 * (1 - k * 0.022), 0, Math.PI * 2); ctx.fill(); }
+ if (f < d.t0) { const w = out3(ramp(f, d.t0 - 6, d.t0)); ctx.fillStyle = ink; ctx.beginPath(); ctx.arc(GEN_C[0], GEN.y + 6 * k - w * 22 * k, 30 * k * (0.3 + 0.7 * w), 0, Math.PI * 2); ctx.fill(); return; }
+ const at = (t: number): P => { const u = ramp(t, d.t0, d.land), e = inOut(u); return [lerp(GEN_C[0], to[0], e), lerp(GEN.y - 16 * k, to[1], e) - Math.sin(Math.PI * u) * 150 * k]; };
+ for (let j = 24; j >= 0; j--) { const p = at(f - j * 0.1); ctx.fillStyle = ink; ctx.globalAlpha = j === 0 ? 1 : 0.22 * (1 - j / 25); ctx.beginPath(); ctx.arc(p[0], p[1], 30 * k * (1 - j * 0.022), 0, Math.PI * 2); ctx.fill(); }
ctx.globalAlpha = 1;
};
+// where the drop is at frame f (null when it is not in flight): the motif's position for a match cut
+export const inkDropAt = (f: number, d: { t0: number; land: number }, to: P, g: ChatGeom = CHAT_GEOM): { p: P; r: number } | null => {
+ const { GEN, k } = g, GEN_C: P = [GEN.x + GEN.w / 2, GEN.y + GEN.h / 2];
+ if (f < d.t0 - 6 || f >= d.land) return null;
+ if (f < d.t0) { const w = out3(ramp(f, d.t0 - 6, d.t0)); return { p: [GEN_C[0], GEN.y + 6 * k - w * 22 * k], r: 30 * k * (0.3 + 0.7 * w) }; }
+ const u = ramp(f, d.t0, d.land), e = inOut(u);
+ return { p: [lerp(GEN_C[0], to[0], e), lerp(GEN.y - 16 * k, to[1], e) - Math.sin(Math.PI * u) * 150 * k], r: 30 * k };
+};
// The answer card in the thread: a byline, then the art, revealed by the landed drop blooming open.
// `art` is any layer (plateLayer gives a live plate); `crop` picks a source rectangle.
-export const inkCard = (ctx: Ctx, x: number, y: number, s: number, f: number, d: Drop, art: Layer, label: string, crop?: [number, number, number, number]) => {
- ctx.fillStyle = C.ink; ctx.globalAlpha = ramp(f, d.land, d.land + 10); ctx.beginPath(); ctx.arc(x + 9, y - 16, 7, 0, Math.PI * 2); ctx.fill();
- ctx.font = SANS(600, 20); ctx.textBaseline = "middle"; ctx.fillText(label, x + 26, y - 15); ctx.globalAlpha = 1;
- const grow = out3(ramp(f, d.land, d.full)), c: P = [x + s / 2, y + s / 2];
- softShadow(ctx, x, y, s, s, 20, grow * 1.3);
- ctx.save(); rr(ctx, x, y, s, s, 20); ctx.clip();
- if (grow < 1) { pathOf(ctx, blot(c, lerp(16, s * 0.8, grow) + 28 * (1 - grow), 77)); ctx.fillStyle = C.ink; ctx.fill(); pathOf(ctx, blot(c, Math.max(0, lerp(16, s * 0.8, grow) - 5), 77)); ctx.clip(); }
- ctx.fillStyle = C.paper; ctx.fillRect(x, y, s, s);
+// `grow` (default an out-cubic from land to full) is how open the card is at frame f: the template
+// passes a spring, so the card lands on the spring's first arrival and its sound cue can sit there
+export const inkCard = (ctx: Ctx, x: number, y: number, s: number, f: number, d: Drop, art: Layer, label: string, crop?: [number, number, number, number], g: ChatGeom = CHAT_GEOM, growAt?: (f: number) => number) => {
+ const k = g.k, P = pal(g);
+ ctx.fillStyle = P.ink; ctx.globalAlpha = ramp(f, d.land, d.land + 10); ctx.beginPath(); ctx.arc(x + 9 * k, y - 16 * k, 7 * k, 0, Math.PI * 2); ctx.fill();
+ ctx.font = SANS(600, g.px.label); ctx.textBaseline = "middle"; ctx.fillText(label, x + 26 * k, y - 15 * k); ctx.globalAlpha = 1;
+ const grow = growAt ? growAt(f) : out3(ramp(f, d.land, d.full)), c: P = [x + s / 2, y + s / 2];
+ softShadow(ctx, x, y, s, s, 20 * k, Math.min(1, grow) * 1.3);
+ ctx.save(); rr(ctx, x, y, s, s, 20 * k); ctx.clip();
+ if (grow < 1 && g.iris) { ctx.beginPath(); ctx.arc(c[0], c[1], Math.max(0, lerp(18 * k, s * 0.72, grow)), 0, Math.PI * 2); ctx.clip(); }
+ else if (grow < 1) { pathOf(ctx, blot(c, lerp(16 * k, s * 0.8, grow) + 28 * k * (1 - grow), 77)); ctx.fillStyle = g.drop ?? P.ink; ctx.fill(); pathOf(ctx, blot(c, Math.max(0, lerp(16 * k, s * 0.8, grow) - 5 * k), 77)); ctx.clip(); }
+ ctx.fillStyle = P.paper; ctx.fillRect(x, y, s, s);
if (crop) ctx.drawImage(art.canvas, ...crop, x, y, s, s); else ctx.drawImage(art.canvas, x, y, s, s);
ctx.restore();
};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchLayout.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchLayout.ts
new file mode 100644
index 0000000..ee38c1e
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchLayout.ts
@@ -0,0 +1,143 @@
+// LAUNCH LAYOUT. One timeline, four frame shapes, and a layout function between them: the chat, the
+// type frames, the cards, the split feature beats and the end card are RE-COMPOSED for each shape,
+// never cropped out of a wide render. 16x9 is the desktop composition (the numbers the template was
+// built on, kept exactly); 1x1, 4x5 and 9x16 are phone compositions with phone-safe type: every line
+// a viewer must read is at least `minPx` tall at the delivered size (32 px at 1080 across is about
+// 11 pt on a 360 pt wide phone, the smallest body size a platform UI uses).
+//
+// const L = launchLayout("9x16", { prompts, install, tagline });
+// L.W, L.H the frame
+// L.chat the chat component's geometry (drawChatFrame, caretAt, inkDrop, inkCard)
+// L.thread / L.cam the thread's rhythm and the camera's rests
+// L.type / L.end the word pages and the end card
+// L.split a feature beat: the words' column and the live UI's, which never overlap
+// L.stage / L.band the picture's area and, with captions burned in, the captions' own band
+// L.roles every text role and its size, which launchLayout checks against minPx
+import { CHAT_GEOM, chatGeom, type ChatGeom, type Rect } from "./launchKit";
+import type { Cam } from "./launchKit";
+import type { P } from "./core";
+
+export type Shape = "16x9" | "1x1" | "4x5" | "9x16";
+export const SHAPES: Record<Shape, { W: number; H: number; use: string }> = {
+ "16x9": { W: 1920, H: 1080, use: "YouTube, the site, the README" },
+ "1x1": { W: 1080, H: 1080, use: "X and LinkedIn feeds" },
+ "4x5": { W: 1080, H: 1350, use: "Instagram and LinkedIn feeds (the tallest feed post)" },
+ "9x16": { W: 1080, H: 1920, use: "Reels, Shorts, TikTok, Stories" },
+};
+export const isShape = (s: string): s is Shape => s in SHAPES;
+export const parseShapes = (s: string): Shape[] => {
+ const out = s.split(",").map((x) => x.trim()).filter(Boolean);
+ const bad = out.filter((x) => !isShape(x));
+ if (bad.length || !out.length) throw new Error(`shapes: '${bad.join(", ") || s}' is not a shape; use ${Object.keys(SHAPES).join(", ")}`);
+ return out as Shape[];
+};
+// phone-safe minimums, px at the delivered size: `read` = a line the viewer must read (a prompt, a
+// label, the words, the install lines); `chrome` = the UI around them (a header, a button's word)
+export const MIN_PX = { phone: { read: 32, chrome: 24, type: 64 }, desk: { read: 18, chrome: 16, type: 80 } };
+
+// A build-time estimate of a sans line's width, deliberately a little wide: layout decisions (how
+// many lines a bubble or a composer needs) are taken before any canvas exists, and an estimate that
+// errs wide wraps one word early instead of running under the button.
+const NARROW = new Set([..."il.,:;'|!ijtf()[] "]), SEMI = new Set([..."rsz-\"*"]), WIDE = new Set([..."mw"]), CAPW = new Set([..."MW"]);
+export const estWidth = (text: string, px: number) => [...text].reduce((a, ch) => a + px * (NARROW.has(ch) ? 0.3 : SEMI.has(ch) ? 0.48 : WIDE.has(ch) ? 0.88 : CAPW.has(ch) ? 0.98 : /[A-Z]/.test(ch) ? 0.72 : /[0-9]/.test(ch) ? 0.6 : 0.6), 0);
+export const monoWidth = (text: string, px: number) => text.length * px * 0.61;
+export const wrapEst = (text: string, px: number, maxW: number): string[] => {
+ const out: string[] = []; let line = "";
+ for (const w of text.split(" ")) { const t = line ? `${line} ${w}` : w; if (!line || estWidth(t, px) <= maxW) line = t; else { out.push(line); line = w; } }
+ out.push(line); return out;
+};
+
+export type Role = { role: string; px: number; min: number };
+export type LaunchLayout = {
+ shape: Shape; W: number; H: number; k: number; phone: boolean;
+ chat: ChatGeom;
+ thread: { top: number; viewBottom: number; clip: [number, number, number, number]; bubbleH: number; bubbleLineH: number; bubblePad: number; bubbleR: number; bubbleMaxW: number; bubbleRad: number; gap: number; card: number; cardX: number; cardDy: number; bubbles: string[][] };
+ cam: { home: Cam; macroZ: number; macroCreep: number; macroX0: number; macroY: number; follow: boolean; leanZ: number; pointerOff: P; pointerS: number; pointerOn: P };
+ bug: { x: number; y: number; px: number };
+ type: { maxW: number; cap1: number; capN: number; minPx: number; cover: number };
+ end: { cx: number; titleY: number; titleMax: number; titleW: number; tagline: string[]; taglineY: number; taglinePx: number; taglineLH: number; panelY: number; monoPx: number; rowH: number; padX: number; lineY0: number; footerPx: number; footerY: number; caret: [number, number] };
+ split: { words: Rect; ui: Rect; vertical: boolean; wordsPx: number };
+ stage: Rect; band: Rect | null;
+ roles: Role[];
+};
+export type LayoutContent = { prompts: string[]; install: string[]; tagline: string; title?: string; band?: boolean };
+
+// the desktop composition: the exact numbers of the 1920x1080 film
+const desk = (c: LayoutContent): LaunchLayout => {
+ const W = 1920, H = 1080, g = CHAT_GEOM, VIEW_BOTTOM = g.INPUT.y - 26, py = 590, n = c.install.length, ph = 60 * n + 50;
+ return {
+ shape: "16x9", W, H, k: 1, phone: false, chat: g,
+ thread: { top: 170, viewBottom: VIEW_BOTTOM, clip: [300, 158, 1320, VIEW_BOTTOM - 158], bubbleH: 58, bubbleLineH: 34, bubblePad: 26, bubbleR: 1560, bubbleMaxW: 1080, bubbleRad: 22, gap: 26, card: 460, cardX: g.REPLY.x, cardDy: 34, bubbles: c.prompts.map((p) => [p]) },
+ cam: { home: { c: [960, 540], z: 1 }, macroZ: 2.4, macroCreep: 0.25, macroX0: 330, macroY: 934, follow: true, leanZ: 1.18, pointerOff: [1780, 1140], pointerS: 1.35, pointerOn: [g.GEN.x + g.GEN.w / 2 + 18, g.GEN.y + g.GEN.h / 2 + 6] },
+ bug: { x: W - 40, y: H - 34, px: 24 },
+ type: { maxW: 1560, cap1: 190, capN: 130, minPx: MIN_PX.desk.type, cover: 1110 },
+ end: { cx: W / 2, titleY: 400, titleMax: 150, titleW: 1300, tagline: [c.tagline], taglineY: 520, taglinePx: 30, taglineLH: 40, panelY: py, monoPx: 30, rowH: 60, padX: 60, lineY0: py + 55, footerPx: 24, footerY: py + ph + 60, caret: [16, 34] },
+ split: { words: { x: 130, y: 150, w: 640, h: 780 }, ui: { x: 840, y: 110, w: 960, h: 860 }, vertical: false, wordsPx: 96 },
+ stage: { x: 0, y: 0, w: W, h: H }, band: null,
+ roles: [],
+ };
+};
+
+// the phone compositions: one column, the chat as tall as the frame allows, type sizes floored at the phone minimums
+const phone = (shape: Exclude<Shape, "16x9">, c: LayoutContent, H0: number): LaunchLayout => {
+ const W = 1080, H = H0, m = 40, k = { "1x1": 1.12, "4x5": 1.22, "9x16": 1.36 }[shape], min = MIN_PX.phone;
+ const px = { head: Math.max(22 * k, min.chrome), sub: Math.max(18 * k, min.chrome), bubble: Math.max(26 * k, min.read), label: Math.max(20 * k, min.read), gen: Math.max(24 * k, min.chrome) };
+ // the window stops above the corner mark's own strip: the mark never sits on the UI
+ const bugPx = Math.max(24 * k, min.chrome), bugStrip = Math.round(bugPx + 34);
+ const promptPx = Math.max(34 * k, min.read), chatR = { x: m, y: m, w: W - 2 * m, h: H - m - bugStrip, r: 34 * k };
+ // the composer holds the longest prompt; the button sits on its last line
+ const base = chatGeom(chatR, k, px, promptPx, 1), textW = base.GEN.x - 20 * k - base.TEXT.x;
+ const lines = Math.min(3, Math.max(1, ...c.prompts.map((p) => wrapEst(p, promptPx, textW).length)));
+ const g = chatGeom(chatR, k, px, promptPx, lines);
+ const top = g.CHAT.y + 114 * k, viewBottom = g.INPUT.y - 26 * k, bubbleMaxW = g.INPUT.w * 0.86, bubbleLineH = Math.round(px.bubble * 1.3);
+ const bubbles = c.prompts.map((p) => wrapEst(p, px.bubble, bubbleMaxW - 52 * k));
+ // the answer card: as wide as the thread allows, and short enough that a card and the prompt above it both fit the view
+ const card = Math.round(Math.min(g.INPUT.w, viewBottom - top - 58 * k - 2 * bubbleLineH - 60 * k));
+ const cardX = g.CHAT.x + (g.CHAT.w - card) / 2;
+ // the end card, stacked and centred in the frame
+ const mono = Math.min(30 * k, ...c.install.map((s) => (W - 2 * 32 - 2 * 36) / (s.length * 0.61)));
+ const taglinePx = Math.max(30 * k, min.read), tagline = wrapEst(c.tagline, taglinePx, W - 2 * m - 60), tLH = Math.round(taglinePx * 1.3);
+ const titleMax = 150 * k, rowH = Math.round(mono * 2), ph = rowH * c.install.length + 50 * k;
+ const block = titleMax + 60 + tagline.length * tLH + 60 + ph + 80, y0 = (H - block) / 2 - 20;
+ const titleY = y0 + titleMax * 0.62, taglineY = y0 + titleMax + 60 + tLH / 2, panelY = taglineY + (tagline.length - 0.5) * tLH + 50;
+ const split = shape === "9x16"
+ ? { words: { x: 90, y: 150, w: W - 180, h: 520 }, ui: { x: m + 20, y: 720, w: W - 2 * m - 40, h: H - 720 - 150 }, vertical: true, wordsPx: 96 }
+ : { words: { x: 80, y: 90, w: W - 160, h: Math.round(H * 0.3) }, ui: { x: m + 20, y: Math.round(H * 0.3) + 130, w: W - 2 * m - 40, h: H - Math.round(H * 0.3) - 130 - 90 }, vertical: true, wordsPx: shape === "1x1" ? 76 : 84 };
+ // the hook: the prompt big, the camera gliding after the caret (and down a line when the words wrap)
+ const macroZ = { "1x1": 1.85, "4x5": 1.95, "9x16": 2.05 }[shape];
+ return {
+ shape, W, H, k, phone: true, chat: g,
+ thread: { top, viewBottom, clip: [g.CHAT.x, g.CHAT.y + 102 * k, g.CHAT.w, viewBottom - (g.CHAT.y + 102 * k)], bubbleH: 58 * k + (px.bubble - 26 * k) * 1.2, bubbleLineH, bubblePad: 26 * k, bubbleR: g.INPUT.x + g.INPUT.w, bubbleMaxW, bubbleRad: 22 * k, gap: 26 * k, card, cardX, cardDy: 34 * k + (px.label - 20 * k), bubbles },
+ cam: { home: { c: [W / 2, H / 2], z: 1 }, macroZ, macroCreep: macroZ * 0.08, macroX0: W / 2 / macroZ - 60 * k, macroY: g.INPUT.y + g.INPUT.h / 2, follow: true, leanZ: 1.1, pointerOff: [W - 110, H + 70], pointerS: 1.35 * k, pointerOn: [g.GEN.x + g.GEN.w / 2 + 18 * k, g.GEN.y + g.GEN.h / 2 + 6 * k] },
+ bug: { x: W - m - 10, y: H - bugStrip / 2 + bugPx * 0.1, px: bugPx },
+ type: { maxW: W - 2 * 90, cap1: 190, capN: 150, minPx: min.type, cover: Math.ceil(Math.hypot(W, H) / 2) + 9 },
+ end: { cx: W / 2, titleY, titleMax, titleW: W - 2 * m - 80, tagline, taglineY, taglinePx, taglineLH: tLH, panelY, monoPx: mono, rowH, padX: 36, lineY0: panelY + 25 * k + rowH / 2, footerPx: Math.max(24 * k, min.read), footerY: panelY + ph + 60, caret: [Math.round(mono * 0.53), Math.round(mono * 1.13)] },
+ split, stage: { x: 0, y: 0, w: W, h: H }, band: null,
+ roles: [],
+ };
+};
+
+// the caption band, when captions are burned in: its own strip under the picture, never over it.
+// The layout is composed for the picture's area (the stage), and the band is drawn below it.
+const BAND = { "16x9": 0, "1x1": 150, "4x5": 170, "9x16": 230 };
+
+/** The layout of a launch film in `shape`, for this content. Throws when a line a viewer must read cannot be phone-safe. */
+export const launchLayout = (shape: Shape, c: LayoutContent): LaunchLayout => {
+ if (!isShape(shape)) throw new Error(`launchLayout: '${shape}' is not a shape; use ${Object.keys(SHAPES).join(", ")}`);
+ const { W, H } = SHAPES[shape], band = c.band ? BAND[shape] : 0;
+ if (c.band && shape === "16x9") throw new Error("launchLayout 16x9: burned-in captions are for the phone shapes (1x1, 4x5, 9x16); a 16x9 film ships its captions as a .srt/.vtt sidecar");
+ // (a wide frame plays where sidecar captions work, YouTube, LinkedIn, the site: its captions ship as .srt/.vtt)
+ const L = shape === "16x9" ? desk(c) : phone(shape, c, H - band);
+ L.H = H; L.stage = { x: 0, y: 0, w: W, h: H - band }; L.band = band ? { x: 0, y: H - band, w: W, h: band } : null;
+ const min = L.phone ? MIN_PX.phone : MIN_PX.desk, g = L.chat;
+ L.roles = [
+ { role: "prompt", px: g.TEXT.px, min: min.read }, { role: "bubble", px: g.px.bubble, min: min.read }, { role: "card label", px: g.px.label, min: min.read },
+ { role: "thread title", px: g.px.head, min: min.chrome }, { role: "thread subtitle", px: g.px.sub, min: min.chrome }, { role: "button", px: g.px.gen, min: min.chrome },
+ { role: "tagline", px: L.end.taglinePx, min: min.read }, { role: "install lines", px: L.end.monoPx, min: min.read }, { role: "footer", px: L.end.footerPx, min: min.chrome },
+ { role: "corner mark", px: L.bug.px, min: min.chrome }, { role: "feature words", px: L.split.wordsPx, min: min.type * 0.75 },
+ ];
+ const small = L.roles.filter((r) => r.px < r.min - 1e-9);
+ if (small.length) throw new Error(`launchLayout ${shape}: ${small.map((r) => `${r.role} would be ${r.px.toFixed(1)} px (phone-safe minimum ${r.min} px)`).join("; ")}${small.some((r) => r.role === "install lines") ? ". Shorten the install line, or ship this shape without it" : ""}`);
+ return L;
+};
+
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchSound.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchSound.ts
new file mode 100644
index 0000000..cb2f360
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchSound.ts
@@ -0,0 +1,58 @@
+// LAUNCH SOUND. The picture's own math, heard. A launch template film knows, frame by frame, when a
+// key is struck, when Generate goes down, when the ink drop lifts and blooms, when a card lands on its
+// spring, and where on screen each happens; these are its sound cues, computed from the same timing
+// that draws the picture, never laid on a grid by hand. The kit is music/sfx (placeSfx, sfxDuck,
+// sfxAudibility); this adds what a film needs on top of it: each cue PANNED to where it happens on
+// screen, and the audibility guarantee made constructive: a cue measured under the score is raised
+// until it is heard (at most +8 dB), then the mix is checked again and a cue still buried throws.
+//
+// Restraint is part of the contract (references/music/sound-design.md): the template emits one riser
+// and one impact, at the big reveal only, and nothing at all on its other cuts.
+import { placeSfx, sfxDuck, sfxAudibility, type SfxCue, type SfxPlan, type SfxAudibility, type PlacedCue } from "./music/sfx";
+import { limiter } from "./music/render";
+import { loudness, truePeak } from "./music/meter";
+
+/** A cue as the template emits it: a kit cue, plus where on screen it happens (px) and what made it. */
+export type LaunchCue = SfxCue & { x?: number; role: "key" | "press" | "drop" | "bloom" | "land" | "arrive" | "riser" | "impact" };
+export type LaunchPlan = Omit<SfxPlan, "cues"> & { cues: LaunchCue[]; W: number; spread?: number };
+/** Stereo position from screen x: -spread at the left edge, +spread at the right (default 0.6: never hard-panned). */
+export const panOf = (x: number | undefined, W: number, spread = 0.6) => (x === undefined ? 0 : Math.max(-1, Math.min(1, (x / W) * 2 - 1)) * spread);
+// equal-power pan of a stereo sound's middle toward p (its width, the side signal, is kept as it is)
+const balance = (L: Float32Array, R: Float32Array, p: number) => {
+ if (!p) return;
+ const a = ((p + 1) * Math.PI) / 4, gl = Math.cos(a) * Math.SQRT2, gr = Math.sin(a) * Math.SQRT2;
+ for (let i = 0; i < L.length; i++) { const m = (L[i] + R[i]) / 2, s = (L[i] - R[i]) / 2; L[i] = m * gl + s; R[i] = m * gr - s; }
+};
+
+export type LaunchMix = { L: Float32Array; R: Float32Array; placed: PlacedCue[]; audibility: SfxAudibility[]; raised: { i: number; role: string; db: number }[]; lufs: number; dbtp: number; ok: boolean };
+/** Score (null = silent) + the film's cues, panned, ducked, every cue heard, one true-peak ceiling (-1 dBTP). */
+export const mixLaunch = (music: [Float32Array, Float32Array] | null, plan: LaunchPlan, sr = 48000, maxRaise = 8): LaunchMix => {
+ const n = Math.round((plan.frames / plan.fps) * sr), cues = plan.cues.map((c) => ({ ...c })), raised = new Map<number, number>();
+ let placed: PlacedCue[] = [], aud: SfxAudibility[] = [], fxL = new Float32Array(n), fxR = new Float32Array(n), mL = new Float32Array(n), mR = new Float32Array(n);
+ for (let pass = 0; pass < 3; pass++) {
+ placed = placeSfx({ ...plan, cues }, sr);
+ fxL = new Float32Array(n); fxR = new Float32Array(n);
+ placed.forEach((pc) => { const c = cues[pc.i], s = pc.sound; balance(s.L, s.R, panOf(c.x, plan.W, plan.spread)); for (let i = 0; i < s.L.length && pc.start + i < n; i++) { fxL[pc.start + i] += s.L[i]; fxR[pc.start + i] += s.R[i]; } });
+ const duck = sfxDuck(placed, n, sr, plan.duck);
+ mL = new Float32Array(n); mR = new Float32Array(n);
+ if (music) { const m = Math.min(n, music[0].length); for (let i = 0; i < m; i++) { mL[i] = music[0][i] * duck[i]; mR[i] = music[1][i] * duck[i]; } }
+ aud = sfxAudibility(placed, [mL, mR], sr, plan);
+ const bad = aud.filter((a) => !a.ok); if (!bad.length) break;
+ let moved = false;
+ for (const a of bad) { const c = cues[a.i], now = raised.get(a.i) ?? 0, up = Math.min(maxRaise - now, a.minDb - a.marginDb + 0.5); if (up > 0.05) { c.gainDb = (c.gainDb ?? 0) + up; raised.set(a.i, now + up); moved = true; } }
+ if (!moved) break;
+ }
+ const L = new Float32Array(n), R = new Float32Array(n);
+ for (let i = 0; i < n; i++) { L[i] = mL[i] + fxL[i]; R[i] = mR[i] + fxR[i]; }
+ limiter(L, R, sr, Math.pow(10, -1.3 / 20));
+ const tp0 = truePeak([L, R]).dbtp; if (tp0 > -1.05) { const g = Math.pow(10, (-1.1 - tp0) / 20); for (let i = 0; i < n; i++) { L[i] *= g; R[i] *= g; } }
+ const fade = Math.min(n, Math.round(0.015 * sr)); for (let i = 0; i < fade; i++) { const g = i / fade; L[n - 1 - i] *= g; R[n - 1 - i] *= g; }
+ const lu = n >= 0.4 * sr ? loudness([L, R], sr).integrated : NaN;
+ return { L, R, placed, audibility: aud, raised: [...raised].map(([i, db]) => ({ i, role: cues[i].role, db })), lufs: lu, dbtp: truePeak([L, R]).dbtp, ok: aud.every((a) => a.ok) };
+};
+/** What a Film's audio(sampleRate) returns; throws when a cue is still buried after raising it. */
+export const launchAudio = (music: ((sr: number) => [Float32Array, Float32Array]) | null, plan: LaunchPlan) => (sr: number): [Float32Array, Float32Array] => {
+ const m = mixLaunch(music ? music(sr) : null, plan, sr);
+ if (!m.ok) throw new Error(`launch sound: ${m.audibility.filter((a) => !a.ok).map((a) => `cue #${a.i} ${a.kind} @ ${a.atS.toFixed(2)} s is ${a.marginDb.toFixed(1)} dB under the score even raised +8 dB`).join("; ")}: thin the score there or move the cue`);
+ return [m.L, m.R];
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
index 4b8a77b..6b4dd99 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
@@ -1,29 +1,39 @@
-// LAUNCH TEMPLATE. Your product's launch film from data: a product name, the prompts a user would
-// type, the plates that answer them, the words for the type frames, and the exact install lines.
-// It is the launch film's grammar (references/workflows/launch-video-kit.md) with nothing of
-// anidoodle's own left in it:
+// LAUNCH TEMPLATE. Your product's launch film from data: a product name, the asks a user would
+// make, the answers, the words for the type frames, and the exact install lines. It is the launch
+// film's grammar (references/workflows/launch-video-kit.md) with nothing of anidoodle's own left in it:
//
-// ask: the prompt is already being typed at frame 0 (a silent-readable hook), the camera eases
-// out from the composer, the pointer presses Generate, an ink drop arcs into the thread and
-// blooms open into a card where the plate draws itself, live. Earlier answers stay and the
+// ask (plate): the prompt is already being typed at frame 0 (a silent-readable hook), the camera
+// eases out from the composer, the pointer presses Generate, an ink drop arcs into the thread
+// and blooms open into a card where the plate draws itself, live. Earlier answers stay and the
// thread scrolls. The camera then leans in on the new card.
+// ask (ui): the product's own interface, drawn from data (productUI.ts): its before state, the
+// ask typed into its command bar (optional), the pointer presses its action, and every item
+// springs to the after state. `split` puts words in their own column beside it.
+// ask (film): any film of this engine (a webTour, a loop) played in a card, `split` as above.
// type: a full-frame word page inside an ink bloom (launchCut.ts). Words never sit on the art.
-// end: the bloom opens onto the end card and stays: the name written on, one line, the install
-// lines in a dark panel, held for `endBeats` (3 s or more).
+// end: the motif relay: an ink drop lifts off Generate (or the product's action) and lands as
+// the dot of the end card's mark, and the page blooms open FROM it and stays: the name, one
+// line, the install lines in a dark panel, held for `endBeats` (3 s or more).
//
-// Everything is timed on a beat grid (bpm from the brief, fps). With `claimBar`, the last ask's length is solved so
-// the end card lands on that bar's downbeat, or the build throws.
+// One timeline, any shape (launchLayout.ts), 30 or 60 fps, two looks (preset "drawn" or "clean"),
+// sound cues from the picture's own timing (launchSound.ts), captions from its words.
+// Everything is timed on a beat grid (bpm from the brief). With `claimBar`, the last ask's length is
+// solved so the end card lands on that bar's downbeat, or the build throws.
//
// export const myLaunch = makeLaunchFilm({ title: "Tally", asks: [...], words: [...], ... });
-// (then a host page, src/hosts/page-myLaunch.ts, and: node tools/render.mjs myLaunch)
+// (or: node tools/launch.mjs new myLaunch; then node tools/launch.mjs ship myLaunch --shapes 16x9,9x16)
import type { Ctx, Env, P } from "./core";
import type { Film } from "./film";
import {
- C, GEN, HOME, INPUT, REPLY, SANS, MONO, TEXT, camLerp, caretAt, charTimes, clamp, drawChatFrame, expo, inOut, inkCard, inkDrop,
- lerp, lerpP, out3, plateLayer, pointer, press, ramp, rr, typedAt, useCam, type Cam, type Drop,
+ C, SANS, MONO, camLerp, caretAt, charTimes, clamp, drawChatFrame, expo, inOut, inkCard, inkDrop,
+ lerp, lerpP, out3, plateLayer, pointer, press, ramp, rr, spring, toScreen, typedAt, useCam, type Cam, type Drop, type ChatGeom, type Rect,
} from "./launchKit";
+import { launchLayout, estWidth, wrapEst, SHAPES, type LaunchLayout, type Shape } from "./launchLayout";
import { beatGrid, bloomFrame, bloomRadius, makeCut, pic, type, typeFrame, type Seg, type TypeLine } from "./launchCut";
-import { measure, writeOn } from "./kinetic";
+import { measure, writeOn, setType } from "./kinetic";
+import { drawProductUI, springLand, uiActionAt, uiCommandAt, uiSettles, uiWindow, type ProductUI, type UiTheme } from "./productUI";
+import { relay, checkRelay, type MotifPose, type Seam } from "./motif";
+import { launchAudio, type LaunchCue } from "./launchSound";
import { fitScore, limiter, renderPiece } from "./music/render";
import { loudness, truePeak } from "./music/meter";
import * as families from "./music/pieces/families";
@@ -36,25 +46,33 @@ import { perform } from "./music/perform";
import { beatsPerBar } from "./music/plan";
import { novelty } from "./music/novelty";
-export type LaunchAsk = {
+/** chat -> Generate -> a plate drawing itself in the answer card (the default kind) */
+export type PlateAsk = {
+ kind?: "plate";
prompt: string; // what the user types, in their words
plate: Film; // the answer: any film of this engine, drawn live into the card
label: string; // the card's byline ("marker comic", "your dashboard, redrawn")
from?: number; to?: number; // the plate frames to play while the card is up (default: all of it)
crop?: [number, number, number, number]; // a source rectangle of the plate, in plate pixels at 1080 across
};
+/** the product's own UI from data: before -> (the ask typed, the action pressed) -> after */
+export type UiAsk = { kind: "ui"; ui: ProductUI; prompt?: string; split?: TypeLine[] };
+/** any film (a webTour, a loop, a plate) in a card */
+export type FilmAsk = { kind: "film"; film: Film; from?: number; to?: number; split?: TypeLine[] };
+export type LaunchAsk = PlateAsk | UiAsk | FilmAsk;
export type LaunchSpec = {
title: string; // the product name: the thread's name, the end card, the corner mark
subtitle?: string; // the thread's subline
placeholder?: string; // the empty composer
genLabel?: string; // the button's word (default "Generate")
- accent?: string; // the button and caret colour, hex
- asks: LaunchAsk[]; // 1 to 3 prompt-to-result beats
+ accent?: string; // the button and caret colour (and the clean preset's one accent), hex
+ asks: LaunchAsk[]; // 1 to 3 beats: prompt-to-plate, product UI, or any film
words?: TypeLine[][]; // words[i] is a type frame after asks[i], for i < asks.length - 1
tagline: string; // the one line under the name on the end card
install: string[]; // the exact lines a viewer copies; held on screen for the whole end card
footer?: string; // small print under the panel (where it runs, the repo)
- bpm: number; fps?: number; // the beat grid: bpm comes from the brief (the score composed for it); a beat is 60 * fps / bpm frames
+ bpm: number; // the beat grid: bpm comes from the brief (the score composed for it)
+ fps?: 30 | 60; // 60 for UI-heavy films (smoother scrolls and springs); the timing is the same
askBeats?: number; typeBeats?: number; endBeats?: number; // default 6, 4, 8
claimBar?: number; // land the end card on this bar's downbeat, counting from bar 0 (solves the last ask)
// The score: a piece COMPOSED for this product's brief (references/music/compose.md), or null for
@@ -62,11 +80,18 @@ export type LaunchSpec = {
// refused: every user's film gets its own music, never ours.
// A Material (what compose.md writes) is composed here; a finished Piece is used as is.
score: (() => Piece | Material) | null;
- audio?: Film["audio"]; // or your own finished mix; wins over score
+ audio?: Film["audio"]; // or your own finished mix; wins over score and sfx
limit?: boolean; // let a look-ahead limiter take the score's last peaks so it reaches -14 LUFS (default off: the peak ceiling wins)
+ shape?: Shape; // the frame: 16x9 (default), 1x1, 4x5, 9x16. Every shape is re-composed by launchLayout, never cropped; film.reshape(s) gives the same film in another shape
+ preset?: "drawn" | "clean"; // the look: ink, blooms and hand lettering (default), or a quiet canvas, one accent and set type
+ sfx?: boolean; // sound cues from the picture's timing (default true; false = the score alone)
+ motif?: boolean; // the relay into the end card (default true): the drop becomes the mark's dot
+ captions?: "sidecar" | "burn"; // .srt/.vtt only (default), or also burned into their own band (phone shapes)
};
-const W = 1920, H = 1080;
+// the clean preset: a quiet canvas, one accent, type as the design. Our own palette, drawn for it.
+export const CLEAN = { bg: "#f3f2ef", card: "#ffffff", ink: "#15161a", soft: "#5b5f68", mute: "#9da1a9", line: "#e4e4e1", chip: "#efefec", accent: "#2f54eb", accentDeep: "#2442bf", paper: "#fbfbf9", shadow: "rgba(20,24,30,0.08)" };
+
// anidoodle's own pieces (the demos and our launch score) are examples of the composer, never a
// user's soundtrack. Refused by identity, by title and by content (the novelty gate), so a thin or
// retitled wrapper does not slip through. `audio` is the caller's own finished mix and is not checked.
@@ -82,155 +107,415 @@ const refuseOurs = (score: () => Piece | Material) => {
if (!v.pass) throw new Error(`launchTemplate: "${score().title}" is too close to anidoodle's own "${v.worst.name.replace(/ #\d+$/, "")}" (similarity ${v.worst.score}, ${v.worst.reusedFragments} reused 6-note fragments); compose a score for this product's brief (references/music/compose.md) or pass score: null`);
};
const TYPE_O = { lead: -4, stagger: 18 }; // the word starts as the bloom closes over the frame; lines run on without a gap
-const TOP = 170, VIEW_BOTTOM = INPUT.y - 26, BUBBLE = 58, CARD = 460;
-const GEN_C: P = [GEN.x + GEN.w / 2, GEN.y + GEN.h / 2];
+const TR = 16; // a bloom-in: frames it takes to open over the previous scene (a seam between kinds, with no word page)
+const DL = 14; // the motif relay: the drop's flight into the end card, in frames (it lands ON the end card's first frame)
+const LIFT = 6; // ...after a bead of ink swells on its source for this many frames
+const isChat = (a: LaunchAsk): a is PlateAsk => !a.kind || a.kind === "plate";
-// the timing inside one ask beat, from its prompt and its length
-const askTiming = (prompt: string, i: number, ASK: number) => {
+// the timing inside one chat ask, from its prompt and its length (`a0` delays the typing past a bloom-in)
+const askTiming = (prompt: string, i: number, ASK: number, a0 = 0) => {
const raw = charTimes(prompt, 0, 1, 7 + i * 4), last = raw[raw.length - 1] || 1;
- const b = Math.round(ASK * 0.25), a = i === 0 ? -Math.round(b * 1.2) : 4; // the first prompt is under way at frame 0
+ const b = Math.round(ASK * 0.25) + a0, a = i === 0 ? -Math.round(b * 1.2) : 4 + a0; // the first prompt is under way at frame 0
const times = raw.map((t) => a + (t / last) * (b - a));
const down = b + 16, up = down + 5, drop: Drop = { t0: up + 5, land: up + 19, full: up + 40 };
return { times, b, down, up, drop };
};
+// a UI ask: the ask typed into the product's command bar (if it has a prompt), then its action pressed
+const uiTiming = (prompt: string | undefined, i: number, ASK: number, a0: number, split = false) => {
+ const b = Math.round(ASK * (prompt ? 0.3 : split ? 0.13 : 0.2)) + a0; // a split beat's words are the wait: its press follows them
+ let times: number[] = [];
+ if (prompt) { const raw = charTimes(prompt, 0, 1, 11 + i * 4), last = raw[raw.length - 1] || 1, a = i === 0 ? -Math.round(b * 0.8) : 6 + a0; times = raw.map((t) => a + (t / last) * (b - a)); }
+ const down = b + 14, up = down + 5;
+ return { times, b, down, up, drop: { t0: up + 2, land: up + 2, full: up + 2 } as Drop };
+};
-export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeof makeCut> } => {
- const fps = spec.fps ?? 30, n = spec.asks.length;
+export type LaunchFilm = Omit<Film, "reshape"> & {
+ cut: ReturnType<typeof makeCut>; layout: LaunchLayout; reshape: (shape: string) => LaunchFilm;
+ cues: LaunchCue[]; // the sound cues the picture emits (frames of this film)
+ seams: Seam[]; // the motif's seams, each checked (checkRelay)
+ timing: { base: number; len: number; tin: number; b: number; down: number; up: number; drop: Drop; times: number[] }[]; // each ask's own timing, content frames at 30 fps
+ captions: { from: number; to: number; text: string }[]; // = meta.captions
+};
+export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {
+ const fps = spec.fps ?? 30, m = fps / 30, n = spec.asks.length, shape = spec.shape ?? "16x9", clean = spec.preset === "clean";
+ if (fps !== 30 && fps !== 60) throw new Error(`launchTemplate: fps ${fps}; a launch film runs at 30, or 60 for a UI-heavy film`);
+ if (!(shape in SHAPES)) throw new Error(`launchTemplate: shape '${shape}' is not one of ${Object.keys(SHAPES).join(", ")}`);
+ if (spec.preset !== undefined && spec.preset !== "drawn" && spec.preset !== "clean") throw new Error(`launchTemplate: preset '${spec.preset}' is not "drawn" or "clean"`);
if (!(spec.bpm > 0)) throw new Error("launchTemplate: set bpm from the brief (the tempo of the score composed for this film)");
if (spec.score === undefined && !spec.audio) throw new Error("launchTemplate: `score` is required: a piece composed for this product (references/music/compose.md), or null for silence");
+ if (n < 1 || n > 3) throw new Error("launchTemplate: 1 to 3 asks; more is a feature list, not a story");
if (spec.score) refuseOurs(spec.score);
- const grid = beatGrid(spec.bpm, fps);
+ const chatIdx = spec.asks.map((a, i) => (isChat(a) ? i : -1)).filter((i) => i >= 0), chatOrd = (i: number) => chatIdx.indexOf(i);
+ const burn = spec.captions === "burn" && shape !== "16x9";
+ const L = launchLayout(shape, { prompts: chatIdx.map((i) => (spec.asks[i] as PlateAsk).prompt), install: spec.install, tagline: spec.tagline, title: spec.title, band: burn });
+ const PAL = clean ? { ...CLEAN, ...(spec.accent ? { accent: spec.accent } : {}) } : C;
+ const ACC = spec.accent ?? (clean ? CLEAN.accent : undefined), INK = clean ? PAL.accent : PAL.ink; // the drop, the motif: ink, or the one accent
+ const G: ChatGeom = clean ? { ...L.chat, theme: CLEAN, drop: INK, iris: true } : L.chat;
+ const W = L.W, H = L.stage.h, TH = L.thread, CAM = L.cam, CARD = TH.card, VIEW_BOTTOM = TH.viewBottom, k = G.k, minPx = L.phone ? 32 : 18;
+ const GEN_C: P = [G.GEN.x + G.GEN.w / 2, G.GEN.y + G.GEN.h / 2];
+ const UI_FULL: Rect = L.phone ? { x: 40, y: Math.round(H * 0.1), w: W - 80, h: Math.round(H * 0.76) } : { x: 250, y: 90, w: 1420, h: 880 };
+ const THEME: UiTheme = { bg: PAL.bg, card: PAL.card, ink: PAL.ink, soft: PAL.soft, mute: PAL.mute, line: PAL.line, chip: PAL.chip, accent: ACC ?? PAL.accent, paper: PAL.paper };
+
+ // ---------------------------------------------------------------- the beat grid and the asks' lengths (30 fps units; 60 fps draws between them)
+ const grid = beatGrid(spec.bpm, 30);
const ASK = Math.round((spec.askBeats ?? 6) * grid.beat), TYPE = Math.round((spec.typeBeats ?? 4) * grid.beat), END0_HOLD = Math.round((spec.endBeats ?? 8) * grid.beat);
let END = END0_HOLD; // the end card is a hold: a scored film sets it so the film is whole bars of its score
- if (n < 1 || n > 3) throw new Error("launchTemplate: 1 to 3 asks; more is a feature list, not a story");
if (ASK < 100) throw new Error(`launchTemplate: an ask beat needs 100 frames or more (it has ${ASK}); raise askBeats`);
- if (END < MIN_END(fps)) throw new Error("launchTemplate: the end card must hold the install lines 3 s or more; raise endBeats");
+ if (END < MIN_END(30)) throw new Error("launchTemplate: the end card must hold the install lines 3 s or more; raise endBeats");
+ const words = spec.words ?? [];
// claimBar solves the last ask's length. A longer ask is really longer (the card holds, the plate
// draws over the extra time); it is never the same ask slowed down, which would repeat frames.
- const typeCount = spec.asks.slice(0, -1).filter((_, i) => spec.words?.[i]?.length).length;
+ const typeCount = spec.asks.slice(0, -1).filter((_, i) => words[i]?.length).length;
const SOLVED = spec.claimBar !== undefined ? grid.solve(spec.claimBar, (n - 1) * ASK + typeCount * TYPE, 60) : ASK;
const LEN = spec.asks.map((_, i) => (i === n - 1 ? Math.max(ASK, SOLVED) : ASK)); // content frames per ask
const BASE = LEN.map((_, i) => LEN.slice(0, i).reduce((a, b) => a + b, 0));
- const T = spec.asks.map((a, i) => ({ ...askTiming(a.prompt, i, ASK), base: BASE[i], len: LEN[i] }));
+ // a seam between two kinds (or into a UI or a film) with no word page on it opens with a bloom-in
+ const TIN = spec.asks.map((a, i) => (i > 0 && !(isChat(a) && isChat(spec.asks[i - 1])) && !words[i - 1]?.length ? TR : 0));
+ const T = spec.asks.map((a, i) => ({ ...(isChat(a) ? askTiming(a.prompt, i, ASK, TIN[i]) : a.kind === "ui" ? uiTiming(a.prompt, i, ASK, TIN[i], !!a.split?.length) : { times: [], b: 0, down: 0, up: 0, drop: { t0: 0, land: 0, full: 0 } }), base: BASE[i], len: LEN[i], tin: TIN[i] }));
const END0 = BASE[n - 1] + LEN[n - 1]; // content frame where the end card starts
+ const askOf = (f: number) => { let i = n - 1; while (i > 0 && T[i].base > f) i--; return i; };
- // ---------------------------------------------------------------- the thread
- type Item = { at: number; h: number; user?: string; card?: number };
+ // ---------------------------------------------------------------- the thread (the chat asks share one)
+ type Item = { at: number; h: number; user?: string; lines?: string[]; card?: number };
const items: Item[] = [];
- T.forEach((t, i) => { items.push({ at: t.base + t.up, h: BUBBLE, user: spec.asks[i].prompt }); items.push({ at: t.base + t.drop.land, h: CARD + 34, card: i }); });
- const ys = (() => { let y = TOP; return items.map((it) => { const r = y; y += it.h + 26; return r; }); })();
+ chatIdx.forEach((i) => { const t = T[i], o = chatOrd(i); items.push({ at: t.base + t.up, h: TH.bubbleH + (TH.bubbles[o].length - 1) * TH.bubbleLineH, user: (spec.asks[i] as PlateAsk).prompt, lines: TH.bubbles[o] }); items.push({ at: t.base + t.drop.land, h: CARD + TH.cardDy, card: i }); });
+ const ys = (() => { let y = TH.top; return items.map((it) => { const r = y; y += it.h + TH.gap; return r; }); })();
const scrollAt = (f: number) => { let s = 0; items.forEach((it, k) => { const want = Math.max(0, ys[k] + it.h - VIEW_BOTTOM); if (want > s) s += (want - s) * expo(ramp(f, it.at - 2, it.at + 16)); }); return s; };
- const cardY = (i: number, f: number) => ys[items.findIndex((it) => it.card === i)] + 34 - scrollAt(f);
- const plateFrame = (i: number, f: number) => { const a = spec.asks[i], t = T[i], from = a.from ?? 0, to = a.to ?? a.plate.meta.durationFrames - 1; return lerp(from, to, ramp(f, t.base + t.drop.land, t.base + t.len - 8)); };
+ const cardY = (i: number, f: number) => ys[items.findIndex((it) => it.card === i)] + TH.cardDy - scrollAt(f);
+ const plateFrame = (i: number, f: number) => { const a = spec.asks[i] as PlateAsk, t = T[i], from = a.from ?? 0, to = a.to ?? a.plate.meta.durationFrames - 1; return lerp(from, to, ramp(f, t.base + t.drop.land, t.base + t.len - 8)); };
+ // the card opens on a spring and lands on its first arrival (its sound sits on that frame)
+ const OMEGA = 4.163 / 21, ZETA = 0.8, arrive = (i: number) => springLand(T[i].base + T[i].drop.land, OMEGA, ZETA);
+ const growAt = (i: number) => (f: number) => (f >= arrive(i) ? 1 : spring(f, T[i].base + T[i].drop.land, OMEGA, ZETA));
- const bug = (c: Ctx, env: Env) => writeOn(c, env, spec.title, W - 40, H - 34, 24, 1, "ink", { color: C.soft, align: "right", seed: 3 });
+ const bug = (c: Ctx, env: Env) => {
+ if (clean) { c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.font = SANS(600, L.bug.px * 0.8); c.fillStyle = PAL.soft; c.textAlign = "right"; c.textBaseline = "alphabetic"; c.fillText(spec.title, L.bug.x, L.bug.y); c.textAlign = "left"; return; }
+ writeOn(c, env, spec.title, L.bug.x, L.bug.y, L.bug.px, 1, "ink", { color: C.soft, align: "right", seed: 3 });
+ };
const chat = (ctx: Ctx, env: Env, f: number, typed: string, caret: boolean, pr: number, hot: number) => {
- drawChatFrame(ctx, { typed, caret, placeholder: spec.placeholder ?? "Describe what you want…", genPress: pr, genHot: hot, title: spec.title, subtitle: spec.subtitle ?? "", genLabel: spec.genLabel, accent: spec.accent });
+ drawChatFrame(ctx, { typed, caret, placeholder: spec.placeholder ?? "Describe what you want…", genPress: pr, genHot: hot, title: spec.title, subtitle: spec.subtitle ?? "", genLabel: spec.genLabel, accent: ACC }, G);
const sc = scrollAt(f);
- ctx.save(); ctx.beginPath(); ctx.rect(300, 158, 1320, VIEW_BOTTOM - 158); ctx.clip();
+ ctx.save(); ctx.beginPath(); ctx.rect(...TH.clip); ctx.clip();
items.forEach((it, k) => {
if (f < it.at) return;
const y = ys[k] - sc; if (y > VIEW_BOTTOM || y + it.h < 100) return;
if (it.user !== undefined) {
- ctx.globalAlpha = ramp(f, it.at, it.at + 8); ctx.font = SANS(500, 26);
- const bw = ctx.measureText(it.user).width + 52; ctx.fillStyle = C.chip; rr(ctx, 1560 - bw, y, bw, BUBBLE - 2, 22); ctx.fill();
- ctx.fillStyle = C.ink; ctx.textBaseline = "middle"; ctx.fillText(it.user, 1560 - bw + 26, y + 29); ctx.globalAlpha = 1;
+ ctx.globalAlpha = ramp(f, it.at, it.at + 8); ctx.font = SANS(500, G.px.bubble);
+ const bw = Math.max(...it.lines!.map((l) => ctx.measureText(l).width)) + 2 * TH.bubblePad; ctx.fillStyle = PAL.chip; rr(ctx, TH.bubbleR - bw, y, bw, it.h - 2, TH.bubbleRad); ctx.fill();
+ ctx.fillStyle = PAL.ink; ctx.textBaseline = "middle"; it.lines!.forEach((l, j) => ctx.fillText(l, TH.bubbleR - bw + TH.bubblePad, y + TH.bubbleH / 2 + j * TH.bubbleLineH)); ctx.globalAlpha = 1;
} else {
- const i = it.card!, a = spec.asks[i];
+ const i = it.card!, a = spec.asks[i] as PlateAsk;
const d = T[i].drop, b = T[i].base;
- inkCard(ctx, REPLY.x, y + 34, CARD, f, { t0: b + d.t0, land: b + d.land, full: b + d.full }, plateLayer(env, `ask${i}`, a.plate, plateFrame(i, f), 1080), a.label, a.crop);
+ inkCard(ctx, TH.cardX, y + TH.cardDy, CARD, f, { t0: b + d.t0, land: b + d.land, full: b + d.full }, plateLayer(env, `ask${i}`, a.plate, plateFrame(i, f), 1080), a.label, a.crop, G, growAt(i));
}
});
ctx.restore();
- T.forEach((t, i) => inkDrop(ctx, f, { t0: t.base + t.drop.t0, land: t.base + t.drop.land }, [REPLY.x + CARD / 2, cardY(i, t.base + t.drop.land) + CARD / 2]));
+ chatIdx.forEach((i) => { const t = T[i]; inkDrop(ctx, f, { t0: t.base + t.drop.t0, land: t.base + t.drop.land }, [TH.cardX + CARD / 2, cardY(i, t.base + t.drop.land) + CARD / 2], G); });
};
// the camera: macro on the composer while typing, out to the room for the press, then a lean in on the new card
- const leanOn = (i: number): Cam => ({ c: lerpP(HOME.c, [REPLY.x + CARD / 2, cardY(i, T[i].base + T[i].len) + CARD / 2], 0.55), z: 1.18 });
+ const HOME = CAM.home;
+ const leanOn = (i: number): Cam => ({ c: lerpP(HOME.c, [TH.cardX + CARD / 2, cardY(i, T[i].base + T[i].len) + CARD / 2], 0.55), z: CAM.leanZ });
+ type CaretFn = (typed: string) => P;
+ // on a phone frame the words wrap, so the caret jumps back a line: the camera follows a smoothed
+ // caret (the mean of its last 10 frames), a glide down to the new line, never a jump
+ const phoneMacro = (caret: CaretFn, i: number, l: number, z: number): P => {
+ const half = W / 2 / z, lo = G.INPUT.x - 24 * k + half, hi = Math.max(lo, G.GEN.x + G.GEN.w + 30 * k - half);
+ let x = 0, y = 0; for (let j = 0; j < 10; j++) { const [cx, cy] = caret(typedAt((spec.asks[i] as PlateAsk).prompt, l - j, T[i].times)); x += clamp(cx - 110 * k, lo, hi); y += cy; }
+ const yLo = G.INPUT.y + H / 2 / z - 90 * k, yHi = G.INPUT.y + G.INPUT.h + 40 * k - H / 2 / z;
+ return [x / 10, clamp(y / 10, Math.min(yLo, yHi), Math.max(yLo, yHi))];
+ };
+ const prevChat = (i: number) => i > 0 && isChat(spec.asks[i - 1]) && T[i].tin === 0;
// `lean` (0..1) is how far the camera leans in; the corner mark steps aside while it does, since
// the lean carries the composer under the corner and type never sits over the UI or the art
- const camAt = (ctx: Ctx, f: number, i: number): { cam: Cam; lean: number } => {
- const t = T[i], l = f - t.base, typed = typedAt(spec.asks[i].prompt, l, t.times), [cx] = caretAt(ctx, typed);
+ const camAt = (caret: CaretFn, f: number, i: number): { cam: Cam; lean: number } => {
+ const t = T[i], l = f - t.base, typed = typedAt((spec.asks[i] as PlateAsk).prompt, l, t.times), [cx] = caret(typed);
// the macro creeps in while the words arrive: the frame is never a still
- const macro: Cam = { c: [Math.max(TEXT.x + 330, cx - 110), 934], z: 2.4 + 0.25 * inOut(ramp(l, t.times[0] - 8, t.b)) };
- if (i > 0 && l < 16) { const k = inOut(ramp(l, 0, 16)); return { cam: camLerp(leanOn(i - 1), macro, k), lean: 1 - k }; }
- if (l > t.drop.full - 10) { const k = inOut(ramp(l, t.drop.full - 10, t.len)); return { cam: camLerp(HOME, leanOn(i), k), lean: k }; }
+ const mz = CAM.macroZ + CAM.macroCreep * inOut(ramp(l, t.times[0] - 8, t.b));
+ const macro: Cam = { c: L.shape === "16x9" ? [Math.max(G.TEXT.x + CAM.macroX0, cx - 110), CAM.macroY] : phoneMacro(caret, i, l, mz), z: mz };
+ if (prevChat(i) && l < 16) { const q = inOut(ramp(l, 0, 16)); return { cam: camLerp(leanOn(i - 1), macro, q), lean: 1 - q }; }
+ if (l > t.drop.full - 10) { const q = inOut(ramp(l, t.drop.full - 10, t.len)); return { cam: camLerp(HOME, leanOn(i), q), lean: q }; }
return { cam: l < t.b - 4 ? macro : camLerp(macro, HOME, expo(ramp(l, t.b - 4, t.down))), lean: 0 };
};
- const askScene = (ctx: Ctx, env: Env, f: number) => {
- let i = n - 1; while (i > 0 && T[i].base > f) i--; const t = T[i], l = f - t.base;
- const { cam, lean } = camAt(ctx, f, i);
+ // the same camera without a canvas (for the sound's pan): the caret from the build-time width estimate
+ const caretEst: CaretFn = (typed) => {
+ if (G.wrap > 0) { const ls = wrapEst(typed, G.TEXT.px, G.GEN.x - 20 * k - G.TEXT.x); return [G.TEXT.x + estWidth(ls[ls.length - 1], G.TEXT.px), G.TEXT.base + (ls.length - 1) * G.lineH - 0.35 * G.TEXT.px]; }
+ return [G.TEXT.x + estWidth(typed, G.TEXT.px), G.TEXT.base - 12];
+ };
+ const pointerPath = (ctx: Ctx, l: number, t: { b: number; down: number; up: number }, on: P, pr: number) => {
+ const off: P = CAM.pointerOff;
+ if (l >= t.b - 4 && l < t.up + 24) pointer(ctx, l < t.up + 4 ? lerpP(off, on, out3(ramp(l, t.b - 4, t.down))) : lerpP(on, off, inOut(ramp(l, t.up + 4, t.up + 24))), pr * 0.8, CAM.pointerS);
+ };
+ const chatScene = (ctx: Ctx, env: Env, f: number, i: number) => {
+ const t = T[i], l = f - t.base, caret: CaretFn = (s) => caretAt(ctx, s, G);
+ const { cam, lean } = camAt(caret, f, i);
useCam(ctx, env, cam);
- const typed = typedAt(spec.asks[i].prompt, l, t.times), pr = press(l, t.down, t.up);
+ const typed = typedAt((spec.asks[i] as PlateAsk).prompt, l, t.times), pr = press(l, t.down, t.up);
chat(ctx, env, f, l < t.up ? typed : "", l < t.up, pr, ramp(l, t.down - 10, t.down - 2));
// the pointer comes in for the press and glides back out; it never pops
- const off: P = [1780, 1140], on: P = [GEN_C[0] + 18, GEN_C[1] + 6];
- if (l >= t.b - 4 && l < t.up + 24) pointer(ctx, l < t.up + 4 ? lerpP(off, on, out3(ramp(l, t.b - 4, t.down))) : lerpP(on, off, inOut(ramp(l, t.up + 4, t.up + 24))), pr * 0.8);
+ pointerPath(ctx, l, t, CAM.pointerOn, pr);
// the mark is gone BEFORE the lean moves the composer under it, and back only once the camera has left
- const show = lean > 0 && l > ASK / 2 ? 1 - ramp(l, t.drop.full - 18, t.drop.full - 10) : i > 0 && l < 24 ? ramp(l, 16, 24) : 1;
+ const show = lean > 0 && l > ASK / 2 ? 1 - ramp(l, t.drop.full - 18, t.drop.full - 10) : prevChat(i) && l < 24 ? ramp(l, 16, 24) : 1;
if (show > 0) { ctx.globalAlpha = show; bug(ctx, env); ctx.globalAlpha = 1; }
};
+ // ---------------------------------------------------------------- the product UI, a film in a card, and a split beat's words
+ const panelOf = (i: number): Rect => ((spec.asks[i] as UiAsk | FilmAsk).split?.length ? L.split.ui : UI_FULL);
+ // never a still: a panel beside its words creeps closer about its own centre all through the ask
+ // (8 %) and leans 4 % more once its items land (it never grows into the words' column)
+ const pushZ = (l: number, len: number, t0: number) => 1 + 0.08 * ramp(l, 0, len) + 0.04 * inOut(ramp(l, t0, len + 30));
+ const push = (ctx: Ctx, env: Env, r: Rect, l: number, len: number, t0 = 0) => { const z = pushZ(l, len, t0 || len), cx = r.x + r.w / 2, cy = r.y + r.h / 2; ctx.setTransform(env.scale * z, 0, 0, env.scale * z, env.scale * cx * (1 - z), env.scale * cy * (1 - z)); };
+ // a full-frame UI ask has the chat's camera grammar: close on the command bar while the ask is typed
+ // (creeping in), out to the whole window for the press, then a lean onto the items as they land
+ const uiCam = (i: number, l: number): Cam => {
+ const a = spec.asks[i] as UiAsk, t = T[i], r = panelOf(i), win = uiWindow(r, a.ui, minPx), cmd = uiCommandAt(r, a.ui, minPx);
+ const lean: Cam = { c: lerpP(HOME.c, [win.x + win.w / 2, win.y + win.h * 0.6], 0.4), z: 1.07 };
+ if (l >= t.drop.t0) return camLerp(HOME, lean, inOut(ramp(l, t.drop.t0, t.len + 40))); // still moving when the ask ends
+ const z0 = cmd && a.prompt ? Math.min(2.2, (W * 0.92) / cmd.w) : 1.04, open: Cam = { c: cmd && a.prompt ? [cmd.x + cmd.w / 2, cmd.y + cmd.h / 2] : HOME.c, z: z0 * (1 + 0.06 * ramp(l, -20, t.b)) }; // already creeping on frame 0
+ return camLerp(open, HOME, expo(ramp(l, t.b - 4, t.down)));
+ };
+ const ground = (ctx: Ctx, env: Env) => { ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = PAL.bg; ctx.fillRect(0, 0, W, H); };
+ const uiScene = (ctx: Ctx, env: Env, f: number, i: number) => {
+ const a = spec.asks[i] as UiAsk, t = T[i], l = f - t.base, r = panelOf(i), pr = press(l, t.down, t.up);
+ ground(ctx, env); if (a.split?.length) push(ctx, env, r, l, t.len, t.drop.t0); else useCam(ctx, env, uiCam(i, l));
+ const typed = a.prompt ? typedAt(a.prompt, l, t.times) : "";
+ drawProductUI(ctx, r, a.ui, { f: l, t0: t.drop.t0 }, THEME, { minPx, typed, caret: !!a.prompt && l < t.down, press: pr, hot: ramp(l, t.down - 10, t.down - 2), accent: ACC });
+ pointerPath(ctx, l, t, (([x, y]) => [x + 14 * k, y + 8 * k] as P)(uiActionAt(r, a.ui, minPx)), pr);
+ if (a.split?.length) splitWords(ctx, env, a.split, l, t.tin);
+ bug(ctx, env);
+ };
+ const filmCard = (i: number): Rect => { const a = spec.asks[i] as FilmAsk, r = panelOf(i), s = Math.min(r.w / a.film.meta.W, r.h / a.film.meta.H), w = a.film.meta.W * s, h = a.film.meta.H * s; return { x: r.x + (r.w - w) / 2, y: r.y + (r.h - h) / 2, w, h }; };
+ const filmScene = (ctx: Ctx, env: Env, f: number, i: number) => {
+ const a = spec.asks[i] as FilmAsk, t = T[i], l = f - t.base, c = filmCard(i), from = a.from ?? 0, to = a.to ?? a.film.meta.durationFrames - 1;
+ ground(ctx, env); push(ctx, env, c, l, t.len);
+ for (let q = 5; q >= 1; q--) { ctx.fillStyle = `rgba(40,30,20,${0.022})`; rr(ctx, c.x - q * 2, c.y + q * 3, c.w + q * 4, c.h + q * 3, 22 * k + q * 2); ctx.fill(); }
+ ctx.save(); rr(ctx, c.x, c.y, c.w, c.h, 22 * k); ctx.clip();
+ ctx.drawImage(plateLayer(env, `film${i}`, a.film, lerp(from, to, ramp(l, 0, t.len - 1)), Math.round(c.w * env.scale)).canvas, c.x, c.y, c.w, c.h);
+ ctx.restore();
+ if (a.split?.length) splitWords(ctx, env, a.split, l, t.tin);
+ bug(ctx, env);
+ };
+ // words in their own column beside the live UI (stacked above it on a phone): sized to the column, written or set on
+ const splitLines = (lines: TypeLine[]) => { const col = L.split.words, out: TypeLine[] = []; for (const ln of lines) { const size = Math.min(L.split.wordsPx, (col.w / measure(ln.text, 100)) * 100); if (size >= L.split.wordsPx * 0.62 || !ln.text.includes(" ")) out.push(ln); else wrapEst(ln.text, L.split.wordsPx, col.w * 1.05).forEach((t) => out.push({ ...ln, text: t })); } return out; };
+ const splitWords = (ctx: Ctx, env: Env, lines0: TypeLine[], l: number, tin: number) => {
+ const col = L.split.words, lines = splitLines(lines0), size = Math.min(L.split.wordsPx, ...lines.map((x) => (col.w / measure(x.text, 100)) * 100)), gap = size * 1.3;
+ const y0 = L.split.vertical ? col.y + size : col.y + col.h / 2 - ((lines.length - 1) * gap) / 2 + size * 0.35;
+ lines.forEach((x, j) => {
+ const p = ramp(l, tin + j * 12, tin + 18 + j * 12);
+ if (clean) setType(ctx, env, x.text, col.x, y0 + j * gap, size * 0.82, p, { color: x.color === C.accent ? THEME.accent : x.color ?? PAL.ink, weight: 800 });
+ else writeOn(ctx, env, x.text, col.x, y0 + j * gap, size, p, x.style, { color: x.color, align: "left", seed: 21 + j });
+ });
+ };
+ // where a UI ask's world point is on screen at content frame f (its camera, or the split panel's push)
+ const uiScreen = (i: number, f: number, p: P): P => { const a = spec.asks[i] as UiAsk, l = f - T[i].base; if (!a.split?.length) return toScreen(uiCam(i, l), p, W, H); const r = panelOf(i), t = T[i], z = pushZ(l, t.len, t.drop.t0), cx = r.x + r.w / 2, cy = r.y + r.h / 2; return [cx + (p[0] - cx) * z, cy + (p[1] - cy) * z]; };
+ const sceneOf = (ctx: Ctx, env: Env, f: number, i: number) => { const a = spec.asks[i]; if (isChat(a)) chatScene(ctx, env, f, i); else if (a.kind === "ui") uiScene(ctx, env, f, i); else filmScene(ctx, env, f, i); };
+ const bloomOpts = clean ? { shape: "circle" as const, rim: 0, bg: PAL.bg } : {};
+ const CLEAN_ST = 12; // a clean word page's lines follow each other closer: set type settles sooner than a brush
+
+ // ---------------------------------------------------------------- the motif: the drop that becomes the mark's dot
+ const MOTIF = spec.motif !== false;
+ const titleSize = clean ? Math.min(L.end.titleMax * 0.8, (L.end.titleW / (estWidth(spec.title, 100) * 1.1)) * 100) : Math.min(L.end.titleMax, (L.end.titleW / measure(spec.title, 100)) * 100);
+ const titleW = clean ? estWidth(spec.title, titleSize) * 1.08 : measure(spec.title, titleSize);
+ const dotR = titleSize * (clean ? 0.1 : 0.085), dotGap = titleSize * 0.1;
+ const P1: P = [L.end.cx + titleW / 2 - (dotGap + 2 * dotR) / 2 + dotGap + dotR, L.end.titleY - dotR * 1.05];
+ const coverFrom = (p: P) => Math.max(...[[0, 0], [W, 0], [0, H], [W, H]].map(([x, y]) => Math.hypot(x - p[0], y - p[1])));
+ const RAD = coverFrom(P1) * 1.14, R0 = bloomRadius(2, 1e6, { inF: 16, close: false, radius: RAD }), RIM = Math.max(1, dotR - R0);
+ // where the drop lifts off: Generate as the viewer sees it on the last chat ask (the card's centre if the lean hid it), the product's action, or the film's card
+ const liftAt = (f: number): P => {
+ const i = n - 1, a = spec.asks[i];
+ if (!isChat(a)) return a.kind === "ui" ? uiScreen(i, f, uiActionAt(panelOf(i), a.ui, minPx)) : ((c) => [c.x + c.w / 2, c.y + c.h / 2] as P)(filmCard(i));
+ const cam = camAt(caretEst, f, i).cam, g = toScreen(cam, GEN_C, W, H), inFrame = g[0] > 60 && g[0] < W - 60 && g[1] > 60 && g[1] < H - 60;
+ return inFrame ? g : toScreen(cam, [TH.cardX + CARD / 2, cardY(i, f) + CARD / 2], W, H);
+ };
+ const S0 = liftAt(END0 - DL), camZ = isChat(spec.asks[n - 1]) ? camAt(caretEst, END0 - DL, n - 1).cam.z : 1;
+ const path = relay([{ at: END0 - DL, p: S0, r: 30 * k * camZ }, { at: END0, p: P1, r: R0 + RIM, arc: 140 * k }]);
+ const motifDrop = (ctx: Ctx, env: Env, f: number) => {
+ if (!MOTIF || f < END0 - DL - LIFT || f >= END0) return;
+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = INK;
+ if (f < END0 - DL) { const w = out3(ramp(f, END0 - DL - LIFT, END0 - DL)); ctx.beginPath(); ctx.arc(S0[0], S0[1], 30 * k * camZ * (0.2 + 0.8 * w), 0, Math.PI * 2); ctx.fill(); return; }
+ for (let j = 24; j >= 0; j--) { const q = path(Math.max(END0 - DL, f - j * 0.1)); if (!q) continue; ctx.globalAlpha = j === 0 ? 1 : 0.22 * (1 - j / 25); ctx.beginPath(); ctx.arc(q.p[0], q.p[1], q.r * (1 - j * 0.02), 0, Math.PI * 2); ctx.fill(); }
+ ctx.globalAlpha = 1;
+ };
+ // the seam, checked: the drop's pose as it lands (the ask's side) is the ink the end card blooms from
+ const seams: Seam[] = MOTIF ? [{ frame: END0, label: "last ask -> end card", out: path(END0) as MotifPose, into: { p: P1, r: R0 + RIM } }] : [];
+ checkRelay(seams);
+
+ const askScene = (ctx: Ctx, env: Env, f: number, withDrop = true) => {
+ const i = askOf(f), t = T[i], l = f - t.base;
+ // a seam between kinds: the new scene blooms open over the last frame of the one before
+ if (t.tin && l < t.tin) bloomFrame(ctx, env, l + 2, 1e6, () => sceneOf(ctx, env, t.base - 1, i - 1), (c) => sceneOf(c, env, f, i), { close: false, inF: 14, W, H, ...bloomOpts });
+ else sceneOf(ctx, env, f, i);
+ if (withDrop) motifDrop(ctx, env, f);
+ };
// ---------------------------------------------------------------- the end card
const endPage = (c: Ctx, env: Env, e: number) => {
- const cx = W / 2, size = Math.min(150, (1300 / measure(spec.title, 100)) * 100);
- writeOn(c, env, spec.title, cx, 400, size, ramp(e, 10, 44), "ink", { color: C.ink, align: "center", seed: 11 });
+ const E = L.end, cx = E.cx, size = titleSize;
+ // (with the motif the page blooms from the dot, wider and sooner: the name starts as it opens, so no frame waits)
+ if (MOTIF) { const tx = P1[0] - dotR - dotGap; if (clean) setType(c, env, spec.title, tx, E.titleY, size, ramp(e, 4, 26), { align: "right", color: PAL.ink, weight: 800 }); else writeOn(c, env, spec.title, tx, E.titleY, size, ramp(e, 4, 40), "ink", { color: C.ink, align: "right", seed: 11 }); c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.fillStyle = INK; c.beginPath(); c.arc(P1[0], P1[1], dotR, 0, Math.PI * 2); c.fill(); }
+ else if (clean) setType(c, env, spec.title, cx, E.titleY, size, ramp(e, 8, 30), { align: "center", color: PAL.ink, weight: 800 });
+ else writeOn(c, env, spec.title, cx, E.titleY, size, ramp(e, 10, 44), "ink", { color: C.ink, align: "center", seed: 11 });
c.setTransform(env.scale, 0, 0, env.scale, 0, 0); c.textAlign = "center"; c.textBaseline = "middle";
- c.globalAlpha = ramp(e, 34, 46); c.fillStyle = C.soft; c.font = SANS(500, 30); c.fillText(spec.tagline, cx, 520);
- c.globalAlpha = ramp(e, 40, 52); c.font = MONO(30);
- const pw = Math.max(...spec.install.map((s) => c.measureText(s).width)) + 120, ph = 60 * spec.install.length + 50, py = 590;
- c.fillStyle = "#1f1c18"; rr(c, cx - pw / 2, py, pw, ph, 22); c.fill();
- c.fillStyle = "#ece4d6"; spec.install.forEach((s, k) => c.fillText(s, cx, py + 55 + k * 60));
+ const Q = clean && MOTIF ? -14 : 0; // the clean name is set in 22 frames, not written in 36: the rest follows it closer
+ // the clean look's lines rise into place as they appear, like its type (the drawn look's fade in under the written name)
+ const rise = (a: number) => (clean ? (1 - out3(ramp(e, a, a + 12))) * 22 * L.k : 0);
+ c.globalAlpha = ramp(e, 34 + Q, 46 + Q); c.fillStyle = PAL.soft; c.font = SANS(500, E.taglinePx); E.tagline.forEach((t, j) => c.fillText(t, cx, E.taglineY + j * E.taglineLH + rise(34 + Q)));
+ c.translate(0, rise(40 + Q));
+ c.globalAlpha = ramp(e, 40 + Q, 52 + Q); c.font = MONO(E.monoPx);
+ const nI = spec.install.length, pw = Math.max(...spec.install.map((s) => c.measureText(s).width)) + 2 * E.padX, ph = E.rowH * nI + 2 * (E.lineY0 - E.panelY) - E.rowH, py = E.panelY;
+ c.fillStyle = clean ? PAL.ink : "#1f1c18"; rr(c, cx - pw / 2, py, pw, ph, 22 * L.k); c.fill();
+ c.fillStyle = clean ? "#ffffff" : "#ece4d6"; spec.install.forEach((s, j) => c.fillText(s, cx, E.lineY0 + j * E.rowH));
// a terminal caret blinks after the last line: the hold reads as live, never as a freeze
- const lastW = c.measureText(spec.install[spec.install.length - 1]).width;
- if (Math.floor((e - 40) / 15) % 2 === 0) c.fillRect(cx + lastW / 2 + 8, py + 55 + (spec.install.length - 1) * 60 - 17, 16, 34);
- if (spec.footer) { c.fillStyle = C.soft; c.font = SANS(500, 24); c.fillText(spec.footer, cx, py + ph + 60); }
- c.globalAlpha = 1; c.textAlign = "left";
+ const lastW = c.measureText(spec.install[nI - 1]).width;
+ if (Math.floor((e - 40 - Q) / 15) % 2 === 0) { if (clean) c.fillStyle = THEME.accent; c.fillRect(cx + lastW / 2 + 8 * (E.monoPx / 30), E.lineY0 + (nI - 1) * E.rowH - E.caret[1] / 2, E.caret[0], E.caret[1]); }
+ if (spec.footer) { c.fillStyle = PAL.soft; c.font = SANS(500, E.footerPx); c.fillText(spec.footer, cx, E.footerY); }
+ c.globalAlpha = 1; c.textAlign = "left"; c.setTransform(env.scale, 0, 0, env.scale, 0, 0);
};
- const content = (ctx: Ctx, env: Env, f: number) => {
- const g = clamp(Math.round(f), 0, END0 + END - 1);
+ const content = (ctx: Ctx, env: Env, f: number, exact: boolean) => {
+ const g = clamp(exact ? Math.round(f) : f, 0, END0 + END - 1);
if (g < END0) return askScene(ctx, env, g);
const e = g - END0;
- bloomFrame(ctx, env, e + 2, END + 2, () => askScene(ctx, env, END0 - 1), (c) => endPage(c, env, e), { close: false, inF: 16 });
+ bloomFrame(ctx, env, e + 2, END + 2, () => askScene(ctx, env, END0 - 1, false), (c) => endPage(c, env, e), { close: false, inF: 16, W, H, ...bloomOpts, ...(MOTIF ? { center: P1, radius: RAD, rim: lerp(RIM, clean ? 0 : 26, out3(ramp(e, 0, 7))), ink: INK } : {}) });
};
// ---------------------------------------------------------------- the cut, as data
- const words = spec.words ?? [];
const segs: Seg[] = [];
spec.asks.forEach((_, i) => {
const last = i === n - 1;
const b = BASE[i], e = b + LEN[i];
segs.push(last && spec.claimBar !== undefined ? pic(b, e, SOLVED) : pic(b, e)); // SOLVED < ASK plays the ask faster; never slower
- if (!last && words[i]?.length) segs.push(type(words[i], TYPE, e - 1, e));
+ if (!last && words[i]?.length) segs.push(type(fitWords(words[i], L), TYPE, e - 1, e));
});
// the score plays at the film's bpm, exactly: the cuts sit on this grid. Sync wins over length, so
// the end-card hold (not the tempo) takes up the difference: the film becomes whole bars of the score.
- const bed = !spec.audio && spec.score ? gridScore(spec.score, spec.bpm, fps, segs.reduce((a, x) => a + x.len, 0), END) : null;
+ const bed = !spec.audio && spec.score ? gridScore(spec.score, spec.bpm, 30, segs.reduce((a, x) => a + x.len, 0), END) : null;
if (bed) END = bed.end;
segs.push(pic(END0, END0 + END));
const cut = makeCut(segs);
- const draw = (ctx: Ctx, F: number, env: Env) => {
- const { s, local } = cut.at(F);
- if (s.kind === "pic") content(ctx, env, cut.contentOf(s, local));
+ // a clean word page: a round iris, the lines SET (heavy sans, left-aligned at the margin, each rising into place)
+ const cleanType = (ctx: Ctx, env: Env, lines: TypeLine[], local: number, len: number, under: (first: boolean) => void) => bloomFrame(ctx, env, local, len, under, (c) => {
+ const nL = lines.length, maxW = L.type.maxW, x0 = (W - maxW) / 2;
+ const size = Math.min(nL === 1 ? 170 : 124, ...lines.map((l) => (maxW / (estWidth(l.text, 100) * 1.12)) * 100)), gap = size * 1.12, y0 = H / 2 - ((nL - 1) * gap) / 2 + size * 0.36;
+ lines.forEach((l, i) => setType(c, env, l.text, x0, y0 + i * gap, size, ramp(local, 14 + TYPE_O.lead + i * CLEAN_ST, 14 + TYPE_O.lead + 18 + i * CLEAN_ST), { color: l.color === C.accent ? THEME.accent : l.color ?? PAL.ink, weight: 800 }));
+ bug(c, env);
+ }, { W, H, ...bloomOpts, rim: 4, ink: THEME.accent, radius: TYPE_R });
+ // a word page's bloom is sized to the frame it covers (the desktop's 1250 px over a 1110 px cover):
+ // on a smaller frame a fixed bloom would cover it before the words start, and two frames would match
+ const TYPE_R = L.shape === "16x9" ? undefined : Math.round((1250 * L.type.cover) / 1110);
+ const TYPE_OPTS = L.shape === "16x9" ? TYPE_O : { ...TYPE_O, W, H, maxW: L.type.maxW, radius: TYPE_R };
+ const drawStage = (ctx: Ctx, env: Env, t: number) => {
+ const { s, local } = cut.at(t), exact = Number.isInteger(t);
+ if (s.kind === "pic") content(ctx, env, cut.contentOf(s, local), exact);
// offset by 2 frames at each end so the bloom is already moving on the first and last frame
- else typeFrame(ctx, env, s.lines, local + 2, s.len + 4, (first) => content(ctx, env, first ? s.before : s.after), (c) => bug(c, env), TYPE_O);
+ else if (clean) cleanType(ctx, env, s.lines, local + 2, s.len + 4, (first) => content(ctx, env, first ? s.before : s.after, true));
+ else typeFrame(ctx, env, s.lines, local + 2, s.len + 4, (first) => content(ctx, env, first ? s.before : s.after, true), (c) => bug(c, env), TYPE_OPTS);
+ };
+
+ // ---------------------------------------------------------------- captions: the words a viewer reads, in cut frames
+ const cutAt = (c: number) => cut.cutOf(c);
+ const caps: { from: number; to: number; text: string }[] = [];
+ spec.asks.forEach((a, i) => {
+ const t = T[i], lo = cut.STARTS[cut.SEGS.findIndex((sg) => sg.kind === "pic" && sg.from === t.base)] ?? 0;
+ if (isChat(a) || (a.kind === "ui" && a.prompt)) { const from = Math.max(lo, cutAt(t.base + Math.max(t.tin, t.times[0] ?? 0))), to = cutAt(t.base + Math.min(t.len - 1, isChat(a) ? t.drop.full : t.drop.t0 + 24)); if (from >= 0 && to > from) caps.push({ from, to, text: isChat(a) ? a.prompt : a.prompt! }); }
+ const split = !isChat(a) ? a.split : undefined;
+ if (split?.length) { const from = cutAt(t.base + t.tin + 4), to = cutAt(t.base + t.len - 1) + 1; caps.push({ from, to, text: split.map((x) => x.text).join(" ") }); }
+ });
+ cut.SEGS.forEach((sg, k) => { if (sg.kind === "type") caps.push({ from: cut.STARTS[k] + 12, to: cut.STARTS[k] + sg.len, text: sg.lines.map((x) => x.text).join(" ") }); });
+ const endAt = cut.STARTS[cut.SEGS.length - 1];
+ caps.push({ from: endAt + 10, to: cut.N, text: `${spec.title}. ${spec.tagline}` });
+ caps.sort((a, b) => a.from - b.from);
+ for (let j = 0; j + 1 < caps.length; j++) caps[j].to = Math.min(caps[j].to, caps[j + 1].from); // one caption at a time
+ const capAt = (t: number) => caps.find((c) => t >= c.from && t < c.to);
+ const band = (ctx: Ctx, env: Env, t: number) => {
+ const B = L.band!; ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);
+ ctx.fillStyle = PAL.card; ctx.fillRect(B.x, B.y, B.w, B.h); ctx.fillStyle = PAL.line; ctx.fillRect(B.x, B.y, B.w, 2);
+ const c = capAt(t); if (!c) return;
+ const px = Math.max(36, Math.round(B.h * 0.2)), lines = wrapEst(c.text, px, B.w - 120).slice(0, 2), a = Math.min(ramp(t, c.from, c.from + 6), 1 - ramp(t, c.to - 6, c.to));
+ ctx.globalAlpha = a; ctx.fillStyle = PAL.ink; ctx.font = SANS(600, px); ctx.textAlign = "center"; ctx.textBaseline = "middle";
+ lines.forEach((l, j) => ctx.fillText(l, B.x + B.w / 2, B.y + B.h / 2 + (j - (lines.length - 1) / 2) * px * 1.25)); ctx.globalAlpha = 1; ctx.textAlign = "left";
+ };
+ const draw = (ctx: Ctx, F: number, env: Env) => {
+ const t = F / m;
+ if (!L.band) return drawStage(ctx, env, t);
+ const stage = { ...env, H }; ctx.save(); ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.beginPath(); ctx.rect(0, 0, W, H); ctx.clip();
+ drawStage(ctx, stage, t); ctx.restore(); band(ctx, env, t);
};
+
// declared holds: the words' reading time on each type frame, and the end card once it is all on
const holds: [number, number][] = [];
cut.SEGS.forEach((s, k) => {
if (s.kind !== "type") return;
- const written = 14 + TYPE_O.lead + 18 + (s.lines.length - 1) * TYPE_O.stagger - 2; // local frame the last line is done
- let open = s.len - 1; while (open > written && bloomRadius(open + 2, s.len + 4) < 1110) open--; // last fully covered frame
+ const written = 14 + TYPE_O.lead + 18 + (s.lines.length - 1) * (clean ? CLEAN_ST : TYPE_O.stagger) - (clean ? 9 : 2); // local frame the last line is done (set type's out-cubic settles to the pixel sooner)
+ // last frame the page still fills the frame (a round iris only clips the corners for its first closing frames: still a still)
+ const cover = clean ? Math.hypot(W, H) / 2 * 0.9 : L.type.cover;
+ let open = s.len - 1; while (open > written && bloomRadius(open + 2, s.len + 4, { radius: TYPE_R }) < cover) open--;
holds.push([cut.STARTS[k] + written + 1, cut.STARTS[k] + open + 1]);
});
// a solved ask longer than the grid's: the finished card rests on screen until the end card blooms
- if (LEN[n - 1] > ASK) { const S = cut.STARTS[cut.SEGS.length - 2]; holds.push([S + LEN[n - 1] - 18, S + LEN[n - 1] + 6]); }
- holds.push([cut.N - END + 53, cut.N]); // the end card, all on: read it, screenshot it
- return {
- meta: { title: `${spec.title} · launch`, W, H, fps, bpm: spec.bpm, durationFrames: cut.N, raster: "cpu", kind: "launch", holds, ...(bed ? { score: { tempo: spec.bpm, form: bed.form, grid: true } } : {}) },
+ // (with the motif the drop is in flight over those frames, so they are not a hold)
+ if (LEN[n - 1] > ASK && isChat(spec.asks[n - 1]) && !MOTIF) { const S = cut.STARTS[cut.SEGS.length - 2]; holds.push([S + LEN[n - 1] - 18, S + LEN[n - 1] + 6]); }
+ holds.push([cut.N - END + (clean && MOTIF ? 39 : 53), cut.N]); // the end card, all on: read it, screenshot it
+
+ // ---------------------------------------------------------------- sound: the picture's own cues
+ const cues: LaunchCue[] = [];
+ const at = (c: number) => { const F = cut.cutOf(c); return F < 0 ? -1 : Math.round(F * m); };
+ const add = (c: number | { F: number }, cue: Omit<LaunchCue, "frame">) => { const fr = typeof c === "number" ? at(c) : Math.round(c.F * m); if (fr >= 0 && fr < cut.N * m) cues.push({ ...cue, frame: fr } as LaunchCue); };
+ const screenX = (i: number, c: number, p: P) => toScreen(camAt(caretEst, c, i).cam, p, W, H)[0];
+ if (!spec.audio && spec.sfx !== false) {
+ spec.asks.forEach((a, i) => {
+ const t = T[i], b = t.base;
+ const prompt = isChat(a) ? a.prompt : a.kind === "ui" ? a.prompt : undefined;
+ // a key for every character typed, a word's first key a touch firmer, the space bar its own sound
+ if (prompt) t.times.forEach((tm, j) => { if (tm < Math.max(0, t.tin)) return; const ch = prompt[j], first = j === 0 || prompt[j - 1] === " ";
+ const x = isChat(a) ? screenX(i, b + tm, caretEst(prompt.slice(0, j + 1))) : ((r) => (r ? r.x + 26 * k + estWidth(prompt.slice(0, j + 1), 26) : W / 2))(uiCommandAt(panelOf(i), (a as UiAsk).ui, minPx));
+ add(b + tm, { kind: "tick", variant: ch === " " ? "space" : "key", gainDb: first && ch !== " " ? 1.5 : 0, x, role: "key", label: `key ${JSON.stringify(ch)}` }); });
+ if (isChat(a)) {
+ const card = (c: number): P => [TH.cardX + CARD / 2, cardY(i, c) + CARD / 2];
+ add(b + t.down, { kind: "press", variant: "thock", x: screenX(i, b + t.down, GEN_C), role: "press", label: "Generate" });
+ add(b + t.drop.t0, { kind: "ink", variant: "plip", x: screenX(i, b + t.drop.t0, GEN_C), role: "drop", label: "the drop lifts" });
+ add(b + t.drop.land, { kind: "ink", variant: "bloom", x: screenX(i, b + t.drop.land, card(b + t.drop.land)), role: "bloom", label: "it blooms into the card" });
+ add(arrive(i), { kind: "pop", variant: "cork", x: screenX(i, arrive(i), card(arrive(i))), role: "land", label: "the card lands (spring)" });
+ } else if (a.kind === "ui") {
+ const r = panelOf(i);
+ add(b + t.down, { kind: "press", variant: "thock", x: uiScreen(i, b + t.down, uiActionAt(r, a.ui, minPx))[0], role: "press", label: a.ui.action });
+ // the items land on their springs: one cue per landing, never two within 4 frames, at most 4
+ let last = -99, count = 0;
+ for (const s of uiSettles(a.ui, { t0: b + t.drop.t0 }).sort((x, y) => x.frame - y.frame)) { if (s.kind === "out" || s.frame - last < 4 || count >= 4) continue; last = s.frame; count++; add(s.frame, { kind: "pop", variant: s.kind === "in" ? "tiny" : "cork", x: r.x + r.w / 2, role: s.kind === "in" ? "arrive" : "land", label: `${s.id} lands` }); }
+ }
+ });
+ // the big reveal, once: a riser that ends as the drop lands on the end card, and one impact there
+ const reveal = { F: endAt }, withKey = !!bed;
+ add(reveal, { kind: "riser", variant: withKey ? "soft" : "air", beats: 4, ...(withKey ? {} : { lengthS: (4 * 60) / spec.bpm }), x: P1[0], role: "riser", label: "into the reveal" });
+ add(reveal, { kind: "impact", variant: withKey ? "bloom" : "boom", x: P1[0], role: "impact", label: "the reveal" });
+ }
+ const plan = { fps, frames: cut.N * m, W, cues, bpm: spec.bpm, seed: 7, ...(bed ? { score: { piece: bed.piece, tempo: spec.bpm } } : {}) };
+ const scoreBed = bed ? musicBed(() => bed.piece, cut.N, 30, -14, { limit: spec.limit, tempo: spec.bpm }) : null;
+ const audio = spec.audio ?? (cues.length ? launchAudio(scoreBed, plan) : scoreBed ?? undefined);
+ const sync = cues.filter((c) => c.role === "press" || c.role === "impact").map((c) => ({ frame: c.frame, label: c.label ?? c.role }));
+
+ let memo: Map<string, LaunchFilm> | null = null;
+ const self: LaunchFilm = {
+ meta: { title: `${spec.title} · launch${shape === "16x9" ? "" : ` · ${shape}`}`, W, H: L.H, fps, bpm: spec.bpm, durationFrames: cut.N * m, raster: "cpu", kind: "launch", holds: holds.map(([a, b]) => [a * m - (m - 1), b * m] as [number, number]), ...(bed ? { score: { tempo: spec.bpm, form: bed.form, grid: true } } : {}),
+ sync, captions: caps.map((c) => ({ from: Math.round(c.from * m), to: Math.round(c.to * m), text: c.text })), poster: Math.round((cut.N - END + 60) * m) },
assets: { images: {} },
- shots: [{ id: "cut", start: 0, end: cut.N, draw }],
- audio: spec.audio ?? (bed ? musicBed(() => bed.piece, cut.N, fps, -14, { limit: spec.limit, tempo: spec.bpm }) : undefined),
- cut,
+ shots: [{ id: "cut", start: 0, end: cut.N * m, draw }],
+ audio,
+ cut, layout: L, cues, seams, timing: T, captions: caps.map((c) => ({ from: Math.round(c.from * m), to: Math.round(c.to * m), text: c.text })),
+ // the same film composed for another frame shape (one timeline: the cut, the timing and the sound do not change)
+ reshape: (s: string) => { if (s === shape) return self; memo ??= new Map(); let f = memo.get(s); if (!f) { f = makeLaunchFilm({ ...spec, shape: s as Shape }); memo.set(s, f); } return f; },
};
+ return self;
+};
+
+// Words sized for the frame: a line that would come out under the phone-safe type size is broken at
+// its middle space (a word page holds at most three lines); one that still cannot is an error.
+export const fitWords = (lines: TypeLine[], L: LaunchLayout): TypeLine[] => {
+ const sizeOf = (ls: TypeLine[]) => Math.min(ls.length === 1 ? 190 : 130, ...ls.map((l) => (L.type.maxW / measure(l.text, 100)) * 100));
+ let out = lines;
+ while (sizeOf(out) < L.type.minPx && out.length < 3) {
+ const k = out.reduce((b, l, i) => (measure(l.text, 100) > measure(out[b].text, 100) ? i : b), 0), words = out[k].text.split(" ");
+ if (words.length < 2) break;
+ let best = 1, bw = Infinity; for (let j = 1; j < words.length; j++) { const w = Math.max(measure(words.slice(0, j).join(" "), 100), measure(words.slice(j).join(" "), 100)); if (w < bw) { bw = w; best = j; } }
+ out = [...out.slice(0, k), { ...out[k], text: words.slice(0, best).join(" ") }, { ...out[k], text: words.slice(best).join(" ") }, ...out.slice(k + 1)];
+ }
+ if (sizeOf(out) < L.type.minPx) throw new Error(`launchTemplate ${L.shape}: the words "${lines.map((l) => l.text).join(" / ")}" would be ${sizeOf(out).toFixed(0)} px on a word page (phone-safe minimum ${L.type.minPx} px): use fewer words`);
+ return out;
};
type Fit = ReturnType<typeof fitScore>;
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/motif.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/motif.ts
new file mode 100644
index 0000000..ae4514d
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/motif.ts
@@ -0,0 +1,32 @@
+// MOTIF. One object that carries the viewer across the film's seams: a match cut is designed, not
+// a transition laid over a join. The rule (references/workflows/launch-video.md, "The motif"):
+// pick ONE object the story already owns (the ink drop, the product's dot), and at every seam it
+// crosses, its screen position and size on the last frame of the outgoing shot equal those on the
+// first frame of the incoming one; the incoming scene opens FROM it (the bloom's centre).
+// A seam is checked, never assumed: seamGap measures it and checkRelay throws past 2 px.
+//
+// const path = relay([{ at: 400, p: [960, 700], r: 30 }, { at: 414, p: [610, 400], r: 18 }]); // cut frames
+// path(407) -> { p, r } between the keys (null outside them): draw the object there
+// checkRelay([{ frame: 414, out: poseOfA(414), into: poseOfB(414) }])
+import type { P } from "./core";
+import { inOut, lerp } from "./launchKit";
+
+export type MotifPose = { p: P; r: number };
+export type MotifKey = MotifPose & { at: number; arc?: number };
+/** A continuous path through keyed poses (cut frames), eased key to key; `arc` lifts the path between two keys (px, up). */
+export const relay = (keys: MotifKey[], ease = inOut) => (F: number): MotifPose | null => {
+ if (!keys.length || F < keys[0].at || F > keys[keys.length - 1].at) return null;
+ let i = 0; while (i < keys.length - 2 && F > keys[i + 1].at) i++;
+ const a = keys[i], b = keys[i + 1] ?? a, u = b.at === a.at ? 1 : (F - a.at) / (b.at - a.at), e = ease(u);
+ return { p: [lerp(a.p[0], b.p[0], e), lerp(a.p[1], b.p[1], e) - Math.sin(Math.PI * u) * (b.arc ?? 0)], r: lerp(a.r, b.r, e) };
+};
+/** How far apart the two sides of a seam put the object: position (px) and size (px of radius). */
+export const seamGap = (out: MotifPose, into: MotifPose) => ({ dp: Math.hypot(out.p[0] - into.p[0], out.p[1] - into.p[1]), dr: Math.abs(out.r - into.r) });
+export type Seam = { frame: number; label?: string; out: MotifPose; into: MotifPose };
+/** Every seam matched within `tol` px, or an error naming the seam and the gap. Returns the gaps. */
+export const checkRelay = (seams: Seam[], tol = 2) => {
+ const gaps = seams.map((s) => ({ ...s, ...seamGap(s.out, s.into) }));
+ const bad = gaps.filter((g) => g.dp > tol || g.dr > tol);
+ if (bad.length) throw new Error(`motif: ${bad.map((g) => `seam ${g.label ?? ""} at frame ${g.frame} jumps ${g.dp.toFixed(1)} px (size ${g.dr.toFixed(1)} px)`).join("; ")}; the object must sit in the same place on both sides of a match cut`);
+ return gaps;
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/productUI.ts b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/productUI.ts
new file mode 100644
index 0000000..a5a7bb6
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/canvas-core/productUI.ts
@@ -0,0 +1,176 @@
+// PRODUCT UI. A product's own interface drawn from DATA, in two states, and the move between them:
+// the launch film's answer to "ground it in the real product" when the product is not a chat. The
+// before state is the problem (a crowded week, a red dashboard); one press of the product's action
+// and every item springs to where the after state puts it: rows move to their new slots, values
+// count to their new numbers, bars fill, new items arrive, old ones leave. Items are matched by id.
+//
+// const ui: ProductUI = { title: "Tally", action: "Reconcile", before: { items: [...] }, after: { items: [...] } };
+// drawProductUI(ctx, rect, ui, { f, t0 }, theme, { minPx: 32 }); f = the frame, t0 = the press
+// uiSettles(ui, { f: 0, t0 }) the frame each item lands (its spring first reaches its target): sound cues
+//
+// Everything is a pure function of the frame. Sizes follow the rectangle, with type floored at minPx
+// (the phone-safe size the layout asks for), so the same UI reads in a 16x9 column and a 9x16 panel.
+import type { Ctx, P } from "./core";
+import { SANS, clamp, lerp, rr, spring, out3, type Rect } from "./launchKit";
+
+export type UiItem = {
+ id: string; label: string;
+ value?: number | string; unit?: string; // a number counts from state to state; a string swaps at the half
+ bar?: number; // 0..1, a progress bar under the label
+ tag?: string; accent?: boolean; done?: boolean;
+};
+export type UiState = { items: UiItem[]; stats?: { label: string; value: number | string; unit?: string }[] };
+export type ProductUI = {
+ title: string; nav?: string[];
+ action: string; // the button the pointer presses: the product doing its one job
+ command?: string; // a command bar's placeholder: the ask is typed there, then the action pressed
+ layout?: "list" | "cards";
+ before: UiState; after: UiState;
+};
+export type UiTheme = { bg: string; card: string; ink: string; soft: string; mute: string; line: string; chip: string; accent: string; paper: string };
+// the move: t0 is the press; items leave one after another, `stagger` frames apart, each on a spring
+export type UiMorph = { f: number; t0: number; stagger?: number; omega?: number; zeta?: number };
+export type UiOpts = { minPx?: number; typed?: string; caret?: boolean; press?: number; hot?: number; accent?: string };
+
+const DEF = { stagger: 3, omega: 0.42, zeta: 0.74 };
+/** The first frame a spring started at t0 reaches its target (it only overshoots after): where a landing sound goes. */
+export const springLand = (t0: number, omega = DEF.omega, zeta = DEF.zeta) => {
+ if (zeta >= 1) return Math.ceil(t0 + Math.log(50) / omega); // no overshoot: within 2 %
+ const wd = omega * Math.sqrt(1 - zeta * zeta);
+ return Math.ceil(t0 + (Math.PI - Math.atan(wd / (zeta * omega))) / wd - 1e-9);
+};
+
+// ---------------------------------------------------------------- geometry
+type Geo = { u: number; win: Rect; px: { title: number; nav: number; row: number; small: number; value: number; stat: number }; head: Rect; action: Rect; command: Rect | null; stats: Rect | null; body: Rect; row: number };
+// the window is fitted to its content (rows at a comfortable height) and centred in the rectangle it is given
+const geo = (r0: Rect, ui: ProductUI, minPx: number): Geo => {
+ const u = clamp(Math.min(r0.w / 880, r0.h / 640), 0.55, 2.4), f = (x: number, lo = minPx) => Math.max(x * u, lo);
+ const px = { title: f(30), nav: f(20, minPx * 0.8), row: f(26), small: f(20, minPx * 0.8), value: f(26), stat: f(46) };
+ const pad = 28 * u, headH = Math.max(76 * u, px.title * 2.1), cmdH = Math.max(66 * u, px.row * 2.3);
+ const nStats = Math.max(ui.before.stats?.length ?? 0, ui.after.stats?.length ?? 0), statH = px.stat * 1.1 + px.small * 1.6 + 30 * u;
+ const top = headH + 18 * u + (ui.command !== undefined ? cmdH + 18 * u : 0) + (nStats ? statH + 18 * u : 0);
+ const n = Math.max(ui.before.items.length, ui.after.items.length, 1), cards = ui.layout === "cards", rows = cards ? Math.ceil(n / 2) : n;
+ const bodyW = r0.w - 2 * pad, room = r0.h - top - pad;
+ const row = cards ? Math.min(room / rows, (bodyW / 2) * 0.62) : clamp(room / rows, px.row * 2.3, px.row * 3.2);
+ const h = Math.min(r0.h, top + rows * row + pad), r = { x: r0.x, y: r0.y + (r0.h - h) / 2, w: r0.w, h };
+ const head = { x: r.x, y: r.y, w: r.w, h: headH };
+ const aw = Math.min(r.w * 0.42, px.row * 0.62 * ui.action.length + 64 * u), ah = Math.max(52 * u, px.row * 1.9);
+ const action = { x: r.x + r.w - pad - aw, y: r.y + (headH - ah) / 2, w: aw, h: ah };
+ let y = r.y + headH + 18 * u;
+ const command = ui.command !== undefined ? { x: r.x + pad, y, w: r.w - 2 * pad, h: cmdH } : null; if (command) y += cmdH + 18 * u;
+ const stats = nStats ? { x: r.x + pad, y, w: r.w - 2 * pad, h: statH } : null; if (stats) y += statH + 18 * u;
+ const body = { x: r.x + pad, y, w: bodyW, h: r.y + r.h - pad - y };
+ return { u, win: r, px, head, action, command, stats, body, row };
+};
+const slot = (g: Geo, ui: ProductUI, i: number): Rect => {
+ if (ui.layout === "cards") { const gap = 16 * g.u, w = (g.body.w - gap) / 2, h = g.row - gap; return { x: g.body.x + (i % 2) * (w + gap), y: g.body.y + Math.floor(i / 2) * g.row, w, h }; }
+ return { x: g.body.x, y: g.body.y + i * g.row, w: g.body.w, h: g.row - 10 * g.u };
+};
+/** The window as drawn inside the rectangle it was given (fitted to its content, centred). */
+export const uiWindow = (r: Rect, ui: ProductUI, minPx = 0): Rect => geo(r, ui, minPx).win;
+/** Where the action button is (its centre), for the pointer and the sound's pan. */
+export const uiActionAt = (r: Rect, ui: ProductUI, minPx = 0): P => { const a = geo(r, ui, minPx).action; return [a.x + a.w / 2, a.y + a.h / 2]; };
+/** Where the command bar's caret starts (its left text edge and centre line), when the UI has one. */
+export const uiCommandAt = (r: Rect, ui: ProductUI, minPx = 0): Rect | null => geo(r, ui, minPx).command;
+
+// ---------------------------------------------------------------- the move
+type Pose = { item: UiItem; from: UiItem | null; to: UiItem | null; a: Rect; b: Rect; p: number; order: number };
+const poses = (g: Geo, ui: ProductUI, m: UiMorph): Pose[] => {
+ const st = m.stagger ?? DEF.stagger, om = m.omega ?? DEF.omega, ze = m.zeta ?? DEF.zeta;
+ const B = new Map(ui.before.items.map((it, i) => [it.id, i])), A = new Map(ui.after.items.map((it, i) => [it.id, i]));
+ const ids = [...new Set([...ui.after.items.map((x) => x.id), ...ui.before.items.map((x) => x.id)])];
+ return ids.map((id, order) => {
+ const bi = B.get(id), ai = A.get(id), from = bi === undefined ? null : ui.before.items[bi], to = ai === undefined ? null : ui.after.items[ai];
+ const p = spring(m.f, m.t0 + order * st, om, ze);
+ return { item: (to ?? from)!, from, to, a: slot(g, ui, bi ?? ai!), b: slot(g, ui, ai ?? bi!), p, order };
+ });
+};
+/** The frame each item lands (first reaches its after-state), and how: moved, arrived or left. */
+export const uiSettles = (ui: ProductUI, m: Omit<UiMorph, "f">) => {
+ const st = m.stagger ?? DEF.stagger, ids = [...new Set([...ui.after.items.map((x) => x.id), ...ui.before.items.map((x) => x.id)])];
+ const B = new Map(ui.before.items.map((it) => [it.id, it])), A = new Map(ui.after.items.map((it) => [it.id, it]));
+ return ids.map((id, order) => {
+ const b = B.get(id), a = A.get(id), kind = !b ? "in" : !a ? "out" : JSON.stringify(b) === JSON.stringify(a) && ui.before.items.indexOf(b) === ui.after.items.indexOf(a) ? "still" : "move";
+ return { id, kind, frame: springLand(m.t0 + order * st, m.omega ?? DEF.omega, m.zeta ?? DEF.zeta) };
+ }).filter((s) => s.kind !== "still");
+};
+const num = (a: number | string | undefined, b: number | string | undefined, p: number, unit = "") => {
+ if (typeof a === "number" && typeof b === "number") { const v = lerp(a, b, clamp(p)), dec = Number.isInteger(a) && Number.isInteger(b) ? 0 : 1; return v.toFixed(dec) + unit; }
+ const v = p < 0.5 ? a ?? b : b ?? a; return v === undefined ? "" : `${v}${unit}`;
+};
+
+// ---------------------------------------------------------------- drawing
+export const drawProductUI = (ctx: Ctx, r0: Rect, ui: ProductUI, m: UiMorph, T: UiTheme, o: UiOpts = {}) => {
+ const g = geo(r0, ui, o.minPx ?? 0), u = g.u, acc = o.accent ?? T.accent, r = g.win;
+ // the window
+ for (let i = 5; i >= 1; i--) { ctx.fillStyle = "rgba(20,24,30,0.022)"; rr(ctx, r.x - i * 2, r.y + i * 3, r.w + i * 4, r.h + i * 3, 24 * u + i * 2); ctx.fill(); }
+ ctx.fillStyle = T.card; rr(ctx, r.x, r.y, r.w, r.h, 24 * u); ctx.fill();
+ ctx.lineWidth = 1.5 * u; ctx.strokeStyle = T.line; ctx.stroke();
+ // the head: the product's name, its sections, the action
+ ctx.textBaseline = "middle"; ctx.font = SANS(700, g.px.title); ctx.fillStyle = T.ink;
+ ctx.fillText(ui.title, r.x + 28 * u, g.head.y + g.head.h / 2);
+ let nx = r.x + 28 * u + ctx.measureText(ui.title).width + 26 * u;
+ ctx.font = SANS(500, g.px.nav);
+ (ui.nav ?? []).forEach((t, i) => { const w = ctx.measureText(t).width; if (nx + w > g.action.x - 20 * u) return; if (i === 0) { ctx.fillStyle = T.chip; rr(ctx, nx - 12 * u, g.head.y + g.head.h / 2 - g.px.nav * 0.95, w + 24 * u, g.px.nav * 1.9, g.px.nav); ctx.fill(); } ctx.fillStyle = i === 0 ? T.ink : T.mute; ctx.fillText(t, nx, g.head.y + g.head.h / 2); nx += w + 36 * u; });
+ const pr = o.press ?? 0, q = 1 - 0.06 * pr, a = g.action;
+ const hot = Math.max(o.hot ?? 0, pr); ctx.fillStyle = hot > 0 ? shade(acc, 1 - 0.18 * hot) : acc;
+ rr(ctx, a.x + (a.w * (1 - q)) / 2, a.y + (a.h * (1 - q)) / 2, a.w * q, a.h * q, (a.h * q) / 2); ctx.fill();
+ ctx.fillStyle = "#fff"; ctx.font = SANS(600, g.px.row * 0.8 * q); ctx.textAlign = "center"; ctx.fillText(ui.action, a.x + a.w / 2, a.y + a.h / 2 + 1); ctx.textAlign = "left";
+ ctx.fillStyle = T.line; ctx.fillRect(r.x, g.head.y + g.head.h, r.w, 1.5 * u);
+ // the command bar
+ if (g.command) {
+ const c = g.command; ctx.fillStyle = T.paper; rr(ctx, c.x, c.y, c.w, c.h, c.h / 2); ctx.fill(); ctx.strokeStyle = T.line; ctx.lineWidth = 1.5 * u; ctx.stroke();
+ ctx.font = SANS(500, g.px.row); ctx.textBaseline = "middle"; const tx = c.x + 26 * u;
+ if (o.typed) { ctx.fillStyle = T.ink; ctx.fillText(fitTail(ctx, o.typed, c.w - 60 * u), tx, c.y + c.h / 2); } else { ctx.fillStyle = T.mute; ctx.fillText(ui.command!, tx, c.y + c.h / 2); }
+ if (o.caret) { const w = o.typed ? ctx.measureText(fitTail(ctx, o.typed, c.w - 60 * u)).width : 0; ctx.fillStyle = acc; ctx.fillRect(tx + w + 3 * u, c.y + c.h / 2 - g.px.row * 0.6, 3 * u, g.px.row * 1.2); }
+ }
+ // the numbers at the top
+ if (g.stats) {
+ const bs = ui.before.stats ?? [], as = ui.after.stats ?? [], n = Math.max(bs.length, as.length), w = g.stats.w / n, p = spring(m.f, m.t0, m.omega ?? DEF.omega, m.zeta ?? DEF.zeta);
+ for (let i = 0; i < n; i++) {
+ const b = bs[i], x = as[i] ?? b, sx = g.stats.x + i * w;
+ ctx.font = SANS(500, g.px.small); ctx.fillStyle = T.soft; ctx.fillText((x ?? b).label, sx, g.stats.y + g.px.small * 0.7);
+ ctx.font = SANS(700, g.px.stat); ctx.fillStyle = T.ink; ctx.fillText(num(b?.value, x?.value, p, x?.unit ?? b?.unit ?? ""), sx, g.stats.y + g.px.small * 1.6 + g.px.stat * 0.62);
+ }
+ }
+ // the items, each on its own spring
+ ctx.save(); rr(ctx, g.body.x - 8 * u, g.body.y - 8 * u, g.body.w + 16 * u, g.body.h + 16 * u, 12 * u); ctx.clip();
+ for (const s of poses(g, ui, m).sort((x, y) => (x.to ? 1 : 0) - (y.to ? 1 : 0))) {
+ const p = s.p, e = clamp(p), alpha = !s.from ? e : !s.to ? 1 - e : 1, k = !s.from ? 0.94 + 0.06 * out3(e) : 1;
+ if (alpha <= 0.002) continue;
+ const box: Rect = { x: lerp(s.a.x, s.b.x, p), y: lerp(s.a.y, s.b.y, p) + (!s.from ? (1 - e) * 14 * u : 0), w: s.a.w, h: s.a.h };
+ const it = e < 0.5 ? s.from ?? s.item : s.to ?? s.item, lift = s.from && s.to && (s.a.y !== s.b.y || s.a.x !== s.b.x) ? Math.sin(Math.PI * e) : 0;
+ ctx.save(); ctx.globalAlpha = alpha; ctx.translate(box.x + box.w / 2, box.y + box.h / 2); ctx.scale(k, k); ctx.translate(-box.w / 2, -box.h / 2);
+ if (lift > 0) { ctx.fillStyle = `rgba(20,24,30,${0.07 * lift})`; rr(ctx, -4 * u, 6 * u, box.w + 8 * u, box.h + 4 * u, 14 * u); ctx.fill(); }
+ ctx.fillStyle = it.accent ? mixA(acc, T.card, 0.9) : ui.layout === "cards" ? T.paper : T.card; rr(ctx, 0, 0, box.w, box.h, 14 * u); ctx.fill();
+ ctx.strokeStyle = it.accent ? mixA(acc, T.card, 0.6) : T.line; ctx.lineWidth = 1.5 * u; ctx.stroke();
+ const cy = ui.layout === "cards" ? g.px.row * 1.1 : box.h / 2 - (it.bar !== undefined ? 7 * u : 0), lx = 22 * u + g.px.row * 0.9;
+ // a status mark: a ring, a filled accent dot, or a tick when done
+ const done = s.from && s.to ? (e < 0.5 ? !!s.from.done : !!s.to.done) : !!it.done, mr = g.px.row * 0.3, mx = 22 * u + mr;
+ ctx.lineWidth = 2.2 * u; ctx.strokeStyle = it.accent || done ? acc : T.mute; ctx.beginPath(); ctx.arc(mx, cy, mr, 0, Math.PI * 2);
+ if (done) { ctx.fillStyle = acc; ctx.fill(); ctx.strokeStyle = "#fff"; ctx.beginPath(); ctx.moveTo(mx - mr * 0.45, cy); ctx.lineTo(mx - mr * 0.1, cy + mr * 0.38); ctx.lineTo(mx + mr * 0.5, cy - mr * 0.35); ctx.stroke(); } else ctx.stroke();
+ ctx.font = SANS(600, g.px.row); ctx.fillStyle = T.ink; ctx.textBaseline = "middle";
+ const val = num(s.from?.value, s.to?.value ?? s.from?.value, s.from && s.to ? p : 1, it.unit ?? "");
+ ctx.font = SANS(700, g.px.value); const vw = val ? ctx.measureText(val).width : 0;
+ ctx.font = SANS(600, g.px.row); ctx.fillText(fitTail(ctx, it.label, box.w - lx - vw - 60 * u, true), lx, cy);
+ if (it.tag) { ctx.font = SANS(600, g.px.small); const tw = ctx.measureText(it.tag).width, tx = ui.layout === "cards" ? lx : Math.min(lx + ctx.measureText(it.label).width * (g.px.row / g.px.small) + 18 * u, box.w - vw - tw - 60 * u); if (tx > lx + 40 * u || ui.layout === "cards") { const ty = ui.layout === "cards" ? cy + g.px.row * 1.25 : cy; ctx.fillStyle = it.accent ? acc : T.chip; rr(ctx, tx - 10 * u, ty - g.px.small * 0.75, tw + 20 * u, g.px.small * 1.5, g.px.small * 0.75); ctx.fill(); ctx.fillStyle = it.accent ? "#fff" : T.soft; ctx.fillText(it.tag, tx, ty); } }
+ if (val) { ctx.font = SANS(700, g.px.value); ctx.fillStyle = it.accent ? acc : T.ink; ctx.textAlign = "right"; ctx.fillText(val, box.w - 22 * u, ui.layout === "cards" ? box.h - g.px.value : cy); ctx.textAlign = "left"; }
+ if (it.bar !== undefined || s.from?.bar !== undefined) {
+ const b0 = s.from?.bar ?? 0, b1 = s.to?.bar ?? b0, bv = clamp(s.from && s.to ? lerp(b0, b1, p) : b1, 0, 1.02), by = ui.layout === "cards" ? box.h - 16 * u : cy + g.px.row * 0.75, bw = box.w - lx - (ui.layout === "cards" ? 22 * u : vw + 60 * u);
+ ctx.fillStyle = T.chip; rr(ctx, lx, by, bw, 6 * u, 3 * u); ctx.fill(); ctx.fillStyle = it.accent ? acc : T.ink; rr(ctx, lx, by, Math.max(6 * u, bw * bv), 6 * u, 3 * u); ctx.fill();
+ }
+ ctx.restore();
+ }
+ ctx.restore();
+ ctx.globalAlpha = 1; ctx.textBaseline = "alphabetic";
+};
+
+// the end of a line when it overflows (a command bar scrolls), or its start with an ellipsis (a label)
+const fitTail = (ctx: Ctx, s: string, w: number, head = false) => {
+ if (ctx.measureText(s).width <= w) return s;
+ if (head) { let t = s; while (t.length > 1 && ctx.measureText(t + "…").width > w) t = t.slice(0, -1); return t + "…"; }
+ let t = s; while (t.length > 1 && ctx.measureText(t).width > w) t = t.slice(1); return t;
+};
+const hx = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
+const shade = (h: string, k: number) => `rgb(${hx(h).map((v) => Math.round(v * k)).join(",")})`;
+const mixA = (a: string, b: string, t: number) => { const x = hx(a), y = hx(b); return `rgb(${x.map((v, i) => Math.round(v + (y[i] - v) * t)).join(",")})`; };
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-launchExampleClean.ts b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-launchExampleClean.ts
new file mode 100644
index 0000000..d4bc013
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page-launchExampleClean.ts
@@ -0,0 +1,4 @@
+import { launchExampleClean } from "../canvas-core/launchExampleClean";
+import { mountFilm } from "./page";
+
+mountFilm(launchExampleClean);
diff --git a/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page.ts b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page.ts
index 628409e..59a511d 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/src/hosts/page.ts
@@ -4,7 +4,7 @@
import type { Ctx, Env, Layer } from "../canvas-core/core";
import { Film, renderFrame, validate } from "../canvas-core/film";
-declare global { interface Window { FILM: unknown; __ASSETS__?: Record<string, string>; __BAKE_SRC__?: Record<string, string>; __ANIDOODLE_SRC__?: WeakMap<object, string> } }
+declare global { interface Window { FILM: unknown; __ASSETS__?: Record<string, string>; __BAKE_SRC__?: Record<string, string>; __ANIDOODLE_SRC__?: WeakMap<object, string>; __SHAPE__?: string } }
// THE BAKE STORE (Env.bake). A finished plate frame, keyed by the hash of the source that draws it
// (build-page.mjs hashes each film module's whole import closure, plus the engine's own renderer),
@@ -32,6 +32,8 @@ const bakeStore = (surface: (w: number, h: number) => Layer) => {
};
export const mountFilm = (film: Film) => {
+ // <film>-<shape> (build-page.mjs sets __SHAPE__): the same film, re-composed for that frame
+ if (window.__SHAPE__) { if (!film.reshape) throw new Error(`${film.meta.title} has one shape; ${window.__SHAPE__} is for launch template films (film.reshape)`); film = film.reshape(window.__SHAPE__); }
const canvas = document.getElementById("film") as HTMLCanvasElement, images = new Map<string, CanvasImageSource>();
let env: Env, ctx: Ctx, current = 0;
// Safari before 16.4 has no 2D OffscreenCanvas: fall back to a detached <canvas>. The core cannot tell the difference.
@@ -60,24 +62,67 @@ export const mountFilm = (film: Film) => {
const toLin = new Float32Array(256);
for (let i = 0; i < 256; i++) { const s = i / 255; toLin[i] = s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4); }
const fromLin = (l: number) => { const v = l <= 0.0031308 ? l * 12.92 : 1.055 * Math.pow(l, 1 / 2.4) - 0.055; return Math.max(0, Math.min(255, Math.round(v * 255))); };
- const blur = (frame: number, samples: number) => {
+ // SHUTTER. `shutter` is the angle in degrees: 360 spreads the subframes over the whole frame
+ // interval, 180 (film's standard, and the default) over half of it, centred on the frame.
+ // ADAPTIVE (samples 0 = auto): how many subframes a frame needs comes from how fast its picture
+ // moves on screen. Two sharp renders at the shutter's two ends are block-matched on a 1/8 luma
+ // grid (8x8 blocks, +-16 cells = +-128 px, textured blocks only); the 98th percentile displacement,
+ // divided by `px` (default 3: subframes at most 3 px apart), is the count, 1 on a still frame (the
+ // sharp frame itself, untouched), at most `max` (default 32). Pure pixels in, a number out:
+ // deterministic like the frames it measures.
+ type BlurSpec = { samples?: number; shutter?: number; max?: number; px?: number };
+ const lumaGrid = (f: number, cell: number) => {
+ renderFrame(film, ctx, f, env); const w = canvas.width, h = canvas.height, d = ctx.getImageData(0, 0, w, h).data, gw = Math.floor(w / cell), gh = Math.floor(h / cell), g = new Float32Array(gw * gh);
+ for (let y = 0; y < gh; y++) for (let x = 0; x < gw; x++) { let s = 0; for (let yy = 0; yy < cell; yy += 2) for (let xx = 0; xx < cell; xx += 2) { const p = ((y * cell + yy) * w + x * cell + xx) * 4, a = d[p + 3] / 255; s += (0.2126 * d[p] + 0.7152 * d[p + 1] + 0.0722 * d[p + 2]) * a; } g[y * gw + x] = s / ((cell * cell) / 4); }
+ return { g, gw, gh };
+ };
+ const speedOf = (t0: number, t1: number) => {
+ const cell = 8, B = 8, R = 16, A = lumaGrid(t0, cell), Z = lumaGrid(t1, cell), { gw, gh } = A, vec = new Map<number, [number, number]>();
+ const cols = Math.floor((gw - 2 * R - B) / B) + 1;
+ for (let by = R, row = 0; by + B + R <= gh; by += B, row++) for (let bx = R, col = 0; bx + B + R <= gw; bx += B, col++) {
+ let mean = 0, v = 0; for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) mean += A.g[(by + y) * gw + bx + x]; mean /= B * B;
+ for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) v += (A.g[(by + y) * gw + bx + x] - mean) ** 2;
+ if (v / (B * B) < 12) continue; // flat: no motion can be read off it
+ const sadAt = (dx: number, dy: number) => { let sad = 0; for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) sad += Math.abs(A.g[(by + y) * gw + bx + x] - Z.g[(by + y + dy) * gw + bx + x + dx]); return sad; };
+ const cost = new Float64Array((2 * R + 1) ** 2); let best = Infinity;
+ for (let dy = -R; dy <= R; dy++) for (let dx = -R; dx <= R; dx++) { const c = sadAt(dx, dy); cost[(dy + R) * (2 * R + 1) + dx + R] = c; if (c < best) best = c; }
+ // content that changes without moving (a stroke drawn, a letter typed) matches nowhere well: not motion
+ if (best / (B * B) > 4) continue;
+ // a periodic texture (halftone, stripes) matches equally well far away: of the near-best offsets take the SMALLEST motion
+ let mx = 0, my = 0, md = Infinity;
+ for (let dy = -R; dy <= R; dy++) for (let dx = -R; dx <= R; dx++) { const c = cost[(dy + R) * (2 * R + 1) + dx + R], d = Math.hypot(dx, dy); if (c <= best * 1.1 + B * B * 0.5 && d < md) { md = d; mx = dx; my = dy; } }
+ const at = (dx: number, dy: number) => (Math.abs(dx) <= R && Math.abs(dy) <= R ? cost[(dy + R) * (2 * R + 1) + dx + R] : Infinity), c0 = at(mx, my);
+ const sub = (m: number, c: number, p: number) => { const d = m - 2 * c + p; return Number.isFinite(d) && d > 0 ? Math.max(-0.5, Math.min(0.5, (0.5 * (m - p)) / d)) : 0; };
+ vec.set(row * cols + col, [mx + (mx || my ? sub(at(mx - 1, my), c0, at(mx + 1, my)) : 0), my + (mx || my ? sub(at(mx, my - 1), c0, at(mx, my + 1)) : 0)]);
+ }
+ // real motion is coherent: a block's vector counts only if two of its neighbours agree with it (within 1.5 cells)
+ const disp: number[] = [];
+ for (const [key, [x, y]] of vec) { const r = Math.floor(key / cols), c = key % cols; let agree = 0; for (let dr = -1; dr <= 1; dr++) for (let dc = -1; dc <= 1; dc++) { if (!dr && !dc) continue; const nb = vec.get((r + dr) * cols + c + dc); if (nb && c + dc >= 0 && c + dc < cols && Math.hypot(nb[0] - x, nb[1] - y) <= 1.5) agree++; } if (agree >= 2) disp.push((Math.hypot(x, y) * cell) / env.scale); }
+ if (!disp.length) return 0;
+ disp.sort((a, b) => a - b); return disp[Math.min(disp.length - 1, Math.floor(disp.length * 0.98))];
+ };
+ const blur = (frame: number, spec: number | BlurSpec) => {
+ const o: BlurSpec = typeof spec === "number" ? { samples: spec, shutter: 360 } : spec, sh = (o.shutter ?? 180) / 360;
const n = Math.max(0, Math.min(film.meta.durationFrames - 1, Math.round(frame))), shot = film.shots.find((s) => n >= s.start && n < s.end);
- if (!shot || samples < 2 || (film.meta.step ?? (film.meta.onTwos ? 2 : 1)) > 1) { const r = seek(n); return { shot: r.shot, ms: r.ms }; }
+ const stepped = (film.meta.step ?? (film.meta.onTwos ? 2 : 1)) > 1, win = (t: number) => Math.min(shot!.end - 1, Math.max(shot!.start, t));
+ let samples = o.samples ?? 0, speed = NaN;
+ if (shot && !stepped && samples === 0) { speed = speedOf(win(n - sh / 2), win(n + sh / 2)); samples = Math.max(1, Math.min(o.max ?? 32, Math.ceil(speed / (o.px ?? 3)))); }
+ if (!shot || samples < 2 || stepped) { const r = seek(n); return { shot: r.shot, ms: r.ms, samples: 1, speed }; }
const t0 = performance.now(), w = canvas.width, h = canvas.height, acc = new Float64Array(w * h * 4);
for (let i = 0; i < samples; i++) {
- const t = Math.min(shot.end - 1, Math.max(shot.start, n + (i + 0.5) / samples - 0.5));
+ const t = win(n + ((i + 0.5) / samples - 0.5) * sh);
renderFrame(film, ctx, t, env);
const d = ctx.getImageData(0, 0, w, h).data;
for (let p = 0; p < d.length; p += 4) { const a = d[p + 3], k = a / 255; acc[p] += toLin[d[p]] * k; acc[p + 1] += toLin[d[p + 1]] * k; acc[p + 2] += toLin[d[p + 2]] * k; acc[p + 3] += a; }
}
- const img = ctx.createImageData(w, h), o = img.data, inv = 1 / samples, full = 255 * samples;
- for (let p = 0; p < o.length; p += 4) {
+ const img = ctx.createImageData(w, h), out = img.data, inv = 1 / samples, full = 255 * samples;
+ for (let p = 0; p < out.length; p += 4) {
const A = acc[p + 3]; if (A === 0) continue; // nothing was ever drawn here: stays transparent black
const c = A === full ? inv : 255 / A; // premultiplied average, un-premultiplied by the mean alpha
- o[p] = fromLin(acc[p] * c); o[p + 1] = fromLin(acc[p + 1] * c); o[p + 2] = fromLin(acc[p + 2] * c); o[p + 3] = Math.round(A * inv);
+ out[p] = fromLin(acc[p] * c); out[p + 1] = fromLin(acc[p + 1] * c); out[p + 2] = fromLin(acc[p + 2] * c); out[p + 3] = Math.round(A * inv);
}
ctx.putImageData(img, 0, 0); current = n;
- return { shot: shot.id, ms: performance.now() - t0 };
+ return { shot: shot.id, ms: performance.now() - t0, samples, speed };
};
const audio = (sr: number) => { if (!film.audio) return null; const [L, R] = film.audio(sr); if (L.length !== R.length) throw new Error("audio channels have different lengths"); const pcm = new Float32Array(L.length * 2); for (let i = 0; i < L.length; i++) { pcm[i * 2] = L[i]; pcm[i * 2 + 1] = R[i]; } return { sampleRate: sr, frames: L.length, float32: b64(new Uint8Array(pcm.buffer)) }; };
const warm = () => film.shots.forEach((s) => { seek(s.start); seek(s.start + ((s.end - s.start) >> 1)); }); // first + middle frame of every shot: builds tiles, pre-allocates the layer pool
@@ -86,16 +131,17 @@ export const mountFilm = (film: Film) => {
// poster frame is drawn once into its own surface; frame n < fade is the real frame n with the
// poster laid over it at 1 - n/fade. Frame 0 IS the poster. Nothing else changes, not the score.
let posterOf: { key: string; img: CanvasImageSource } | null = null;
- const poster = (frame: number, posterFrame: number, fade: number, samples = 1) => {
- const n = Math.round(frame), u = fade > 0 ? 1 - n / fade : n === 0 ? 1 : 0, key = `${posterFrame}/${samples}/${canvas.width}x${canvas.height}`;
+ const poster = (frame: number, posterFrame: number, fade: number, samples: number | BlurSpec = 1) => {
+ const on = typeof samples === "number" ? samples > 1 : true;
+ const n = Math.round(frame), u = fade > 0 ? 1 - n / fade : n === 0 ? 1 : 0, key = `${posterFrame}/${JSON.stringify(samples)}/${canvas.width}x${canvas.height}`;
if (u > 0 && posterOf?.key !== key) {
- samples > 1 ? blur(posterFrame, samples) : seek(posterFrame);
+ on ? blur(posterFrame, samples) : seek(posterFrame);
// the copy lives on the same kind of surface the art uses (surface(): same raster opts). A plain
// GPU <canvas> drawn onto a meta.raster "cpu" canvas flips Chrome's raster path for the rest
// of the session and every later frame comes out different: measured, not guessed.
const c = surface(canvas.width, canvas.height); c.ctx.drawImage(canvas, 0, 0); posterOf = { key, img: c.canvas };
}
- const r = samples > 1 ? blur(n, samples) : seek(n);
+ const r = on ? blur(n, samples) : seek(n);
if (u > 0 && posterOf) { ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = Math.min(1, u); ctx.globalCompositeOperation = "source-over"; if (u >= 1) ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(posterOf.img, 0, 0); ctx.restore(); }
current = n; return r;
};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/avsync.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/avsync.test.ts
new file mode 100644
index 0000000..05a12a1
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/test/avsync.test.ts
@@ -0,0 +1,33 @@
+// AV SYNC TESTS. verify-export measures a delivered file's sound against its master mix and against
+// the picture's own sync frames; these hold the measurements to known answers on synthetic signals.
+// @ts-ignore: a plain ES module shared with the tools
+import { xcorrOffset, onsetNear, toSrt, toVtt } from "../tools/avsync.mjs";
+
+export const name = "avsync";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const sr = 48000, n = sr * 3, ref = new Float32Array(n);
+ let s = 12345; const rnd = () => ((s = (s * 1103515245 + 12345) >>> 0) / 4294967296) * 2 - 1;
+ for (let i = 0; i < n; i++) ref[i] = 0.05 * rnd(); // a noise bed
+ const click = (x: Float32Array, at: number) => { for (let k = 0; k < 480; k++) x[at + k] += 0.8 * Math.exp(-k / 60) * Math.sin(k * 0.9); };
+ click(ref, sr * 1); click(ref, Math.round(sr * 2.2));
+ for (const shift of [0, 7, -13, 96]) {
+ const dec = new Float32Array(n); for (let i = 0; i < n; i++) { const j = i - shift; dec[i] = j >= 0 && j < n ? ref[j] : 0; }
+ const r = xcorrOffset(ref, dec, 1.0, sr);
+ ok(Math.abs(r.lag - shift) < 0.05, `a ${shift}-sample shift (${((shift / sr) * 1000).toFixed(2)} ms) is measured as ${r.lag.toFixed(2)} samples (corr ${r.corr.toFixed(3)})`);
+ }
+ // a half-sample shift (linear interpolation) is found to a fraction of a sample
+ const half = new Float32Array(n); for (let i = 1; i < n; i++) half[i] = 0.5 * (ref[i] + ref[i - 1]);
+ ok(Math.abs(xcorrOffset(ref, half, 1.0, sr).lag - 0.5) < 0.2, `a half-sample delay reads as ${xcorrOffset(ref, half, 1.0, sr).lag.toFixed(2)} samples (sub-sample)`);
+ ok(Number.isNaN(xcorrOffset(new Float32Array(n), ref, 1.0, sr).ms), "silence has no offset to measure (NaN, never a fake zero)");
+ // onsets: the click at 1.000 s is found within a millisecond, and on the decoded copy 7 samples late
+ const t1 = onsetNear(ref, 1.0, sr), late = new Float32Array(n); for (let i = 480; i < n; i++) late[i] = ref[i - 480];
+ ok(Math.abs(t1 - 1.0) <= 0.001, `the onset of a cue at 1.000 s is found at ${t1.toFixed(4)} s`);
+ ok(Math.abs(onsetNear(late, 1.0, sr) - 1.01) <= 0.001, `a cue 10 ms late reads as ${((onsetNear(late, 1.0, sr) - 1) * 1000).toFixed(1)} ms late`);
+ ok(Number.isNaN(onsetNear(ref, 1.6, sr)), "no cue near a frame: NaN, not the nearest noise");
+ // captions
+ const caps = [{ from: 0, to: 45, text: "a lighthouse at sunset, as a print" }, { from: 3600 * 30 + 15, to: 3600 * 30 + 90, text: "One sentence that says what it is, and then a second sentence that wraps" }];
+ const srt = toSrt(caps, 30), vtt = toVtt(caps, 30);
+ ok(srt.startsWith("1\n00:00:00,000 --> 00:00:01,500\na lighthouse at sunset, as a print\n"), "SubRip: numbered cues, comma milliseconds");
+ ok(/01:00:00,500 --> 01:00:03,000\n.{1,42}\n.+\n/.test(srt), "an hour in, and a long line wraps to two");
+ ok(vtt.startsWith("WEBVTT\n\n00:00:00.000 --> 00:00:01.500\n"), "WebVTT: the header and dot milliseconds");
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/launchLayout.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/launchLayout.test.ts
new file mode 100644
index 0000000..e188be6
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/test/launchLayout.test.ts
@@ -0,0 +1,48 @@
+// LAUNCH LAYOUT TESTS. One timeline, four frame shapes: each shape is a composition of its own (the
+// chat, the cards, the word pages, the split beat, the end card), every line a viewer reads is at
+// least the phone-safe size, nothing sits over anything else, and 16x9 is the desktop film exactly.
+import { CHAT_GEOM, chatGeom, CHAT } from "../src/canvas-core/launchKit";
+import { launchLayout, SHAPES, MIN_PX, monoWidth, parseShapes, type Shape } from "../src/canvas-core/launchLayout";
+import { makeLaunchFilm, fitWords } from "../src/canvas-core/launchTemplate";
+import type { Film } from "../src/canvas-core/film";
+
+type R = { x: number; y: number; w: number; h: number };
+const inside = (a: R, b: R, tol = 0.5) => a.x >= b.x - tol && a.y >= b.y - tol && a.x + a.w <= b.x + b.w + tol && a.y + a.h <= b.y + b.h + tol;
+const overlap = (a: R, b: R) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
+
+export const name = "launchLayout";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const g = chatGeom(CHAT, 1, CHAT_GEOM.px, 34, 0);
+ ok(JSON.stringify([g.CHAT, g.INPUT, g.GEN, g.REPLY.x, g.REPLY.y, g.TEXT]) === JSON.stringify([CHAT_GEOM.CHAT, CHAT_GEOM.INPUT, CHAT_GEOM.GEN, CHAT_GEOM.REPLY.x, CHAT_GEOM.REPLY.y, CHAT_GEOM.TEXT]), "the chat derivation at k = 1 IS the desktop chat (one component, not two)");
+ const content = { prompts: ["a lighthouse at sunset, as a print", "now a fox at dusk"], install: ["/plugin marketplace add alexgreensh/anidoodle", "/plugin install anidoodle@alexgreensh-anidoodle"], tagline: "Illustrations, loops and films, drawn in code" };
+ for (const shape of Object.keys(SHAPES) as Shape[]) {
+ const L = launchLayout(shape, content), frame = { x: 0, y: 0, w: L.W, h: L.H }, c = L.chat;
+ ok(L.W === SHAPES[shape].W && L.H === SHAPES[shape].H, `${shape}: the frame is ${L.W}x${L.H}`);
+ const small = L.roles.filter((r) => r.px < r.min);
+ ok(!small.length, `${shape}: every text role is at or over its minimum (${L.roles.map((r) => `${r.role} ${r.px.toFixed(0)}`).join(", ")})`);
+ if (L.phone) ok(L.roles.filter((r) => ["prompt", "bubble", "card label", "tagline", "install lines"].includes(r.role)).every((r) => r.px >= MIN_PX.phone.read), `${shape}: the lines a viewer must read are phone-safe (>= ${MIN_PX.phone.read} px)`);
+ ok(inside(c.CHAT, frame) && inside(c.INPUT, c.CHAT) && inside(c.GEN, c.INPUT), `${shape}: window in frame, composer in window, button in composer`);
+ ok(L.thread.cardX >= c.CHAT.x && L.thread.cardX + L.thread.card <= c.CHAT.x + c.CHAT.w && L.thread.card > 0, `${shape}: the answer card (${L.thread.card} px) sits inside the thread`);
+ ok(L.thread.bubbles.every((ls) => ls.length <= 3), `${shape}: prompts wrap to at most 3 bubble lines (${L.thread.bubbles.map((b) => b.length).join(", ")})`);
+ ok(L.bug.y > c.CHAT.y + c.CHAT.h, `${shape}: the corner mark sits below the chat window, never on it`);
+ const pw = Math.max(...content.install.map((s) => monoWidth(s, L.end.monoPx))) + 2 * L.end.padX;
+ ok(pw <= L.W, `${shape}: the install panel (${pw.toFixed(0)} px at ${L.end.monoPx.toFixed(1)} px mono) fits the frame's width`);
+ ok(L.end.titleY < L.end.taglineY && L.end.taglineY < L.end.panelY && L.end.footerY < L.stage.h, `${shape}: the end card stacks title, line, panel, footer, all in frame`);
+ ok(!overlap(L.split.words, L.split.ui) && inside(L.split.words, L.stage) && inside(L.split.ui, L.stage), `${shape}: a split beat's words and live UI have their own areas (${L.split.vertical ? "stacked" : "side by side"})`);
+ if (L.phone) { const B = launchLayout(shape, { ...content, band: true }); ok(!!B.band && !overlap(B.band, B.stage) && B.band.y + B.band.h === B.H, `${shape}: burned-in captions get their own band under the picture (${B.band?.h} px)`); }
+ }
+ let err = ""; try { launchLayout("16x9", { ...content, band: true }); } catch (e) { err = (e as Error).message; } ok(/sidecar/.test(err), "16x9 refuses a burned-in band: its captions ship as .srt/.vtt");
+ err = ""; try { launchLayout("9x16", { ...content, install: ["npx some-very-long-package-name@latest init --with-every-flag-there-is"] }); } catch (e) { err = (e as Error).message; } ok(/install lines would be/.test(err), `an install line that cannot be phone-safe is an error: ${err.slice(0, 80)}`);
+ ok(parseShapes("16x9, 9x16").join() === "16x9,9x16", "parseShapes reads a --shapes list");
+ err = ""; try { parseShapes("16x10"); } catch (e) { err = (e as Error).message; } ok(/not a shape/.test(err), "parseShapes refuses an unknown shape");
+
+ // one timeline, every shape: the same cut and length, a different composition
+ const plate: Film = { meta: { title: "plate", W: 1080, H: 1080, fps: 30, bpm: 90, durationFrames: 60 }, assets: { images: {} }, shots: [{ id: "p", start: 0, end: 60, draw: () => {} }] };
+ const f = makeLaunchFilm({ title: "Tally", asks: [{ prompt: content.prompts[0], plate, label: "l" }, { prompt: content.prompts[1], plate, label: "l" }], words: [[{ text: "EVERY NUMBER, COUNTED.", style: "ink", color: "#000" }]], tagline: content.tagline, install: ["npm i tally"], bpm: 90, claimBar: 4, score: null });
+ const shapes = (Object.keys(SHAPES) as Shape[]).map((s) => f.reshape(s));
+ ok(shapes.every((x) => x.meta.durationFrames === f.meta.durationFrames && JSON.stringify(x.cut.STARTS) === JSON.stringify(f.cut.STARTS)), `every shape is the same cut (${f.meta.durationFrames} frames, cuts at ${f.cut.STARTS.join(", ")})`);
+ ok(shapes.every((x, i) => x.meta.W === SHAPES[(Object.keys(SHAPES) as Shape[])[i]].W && x.meta.H === SHAPES[(Object.keys(SHAPES) as Shape[])[i]].H), "each shape renders at its own frame size");
+ ok(f.reshape("16x9") === f && f.reshape("9x16") === f.reshape("9x16"), "reshape returns the film itself for its own shape, and one film per shape");
+ const tall = fitWords([{ text: "EVERY NUMBER, COUNTED.", style: "ink", color: "#000" }], f.reshape("9x16").layout), wide = fitWords([{ text: "EVERY NUMBER, COUNTED.", style: "ink", color: "#000" }], f.layout);
+ ok(wide.length === 1 && tall.length === 2, `a word page re-sets its lines for a narrow frame (16x9: ${wide.length} line, 9x16: ${tall.map((l) => l.text).join(" / ")})`);
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/launchSound.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/launchSound.test.ts
new file mode 100644
index 0000000..6f4e4ac
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/test/launchSound.test.ts
@@ -0,0 +1,68 @@
+// LAUNCH SOUND TESTS. The template's sound cues come from the picture's own timing: a key per typed
+// character, the press on the frame Generate goes down, the drop and its bloom, the card landing on
+// its spring's first arrival, each panned to where it happens on screen; one riser and one impact at
+// the big reveal and nothing on the other cuts; every cue heard over a real score.
+import { makeLaunchFilm } from "../src/canvas-core/launchTemplate";
+import { mixLaunch, panOf } from "../src/canvas-core/launchSound";
+import { springLand } from "../src/canvas-core/productUI";
+import type { Material } from "../src/canvas-core/music";
+import type { Film } from "../src/canvas-core/film";
+
+export const name = "launchSound";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const plate: Film = { meta: { title: "plate", W: 1080, H: 1080, fps: 30, bpm: 90, durationFrames: 60 }, assets: { images: {} }, shots: [{ id: "p", start: 0, end: 60, draw: () => {} }] };
+ const mine = (): Material => ({
+ style: "playful", title: "Tally, counted", seed: 5, mood: "curious", bpm: 90, key: "G", mode: "mixolydian",
+ chords: { G: { voicing: "[D4 G4 B4]", bass: "G2:1.5 D3:.5 G2:1 F2:1" }, F: { voicing: "[C4 F4 A4]", bass: "F2:1.5 C3:.5 F2:1 E2:1" } },
+ motifs: { a: "B4:.5 D5:.5 G5:1 r:.5 F5:.25 E5:.25 D5:1", b: "r:1 A4:.5 C5:.5 F5:1 E5:.5 C5:.5" },
+ grooves: { main: { family: "shuffle", density: 0.45, variation: 0.35 } },
+ sections: [{ kind: "groove", bars: 4, harmony: ["G", "F"], lead: ["a", "b", "a", "b"], groove: "main", stretch: true }, { kind: "outro", bars: 1, harmony: ["G"], lead: ["a"] }],
+ });
+ const prompts = ["a lighthouse at sunset", "now a fox at dusk"];
+ const spec = { title: "Tally", asks: prompts.map((p) => ({ prompt: p, plate, label: "l" })), words: [[{ text: "IDEA IN.", style: "ink" as const, color: "#000" }]], tagline: "t", install: ["npm i tally"], bpm: 90, askBeats: 6, endBeats: 8, claimBar: 5, score: mine };
+ const f = makeLaunchFilm(spec), cues = f.cues, at = (c: number) => Math.round(f.cut.cutOf(c));
+ const by = (r: string) => cues.filter((c) => c.role === r);
+
+ // keys: one per character typed on screen (the first prompt is under way at frame 0: only what is typed after it)
+ const typed = f.timing.reduce((a, t) => a + t.times.filter((x) => x >= Math.max(0, t.tin)).length, 0);
+ ok(by("key").length === typed, `a key cue for every character typed on screen (${by("key").length} of ${typed})`);
+ const spaces = prompts.join("").split("").filter((c) => c === " ").length;
+ ok(by("key").filter((c) => c.variant === "space").length <= spaces && by("key").some((c) => c.variant === "space"), "the space bar has its own sound");
+ ok(f.timing.every((t, i) => by("key").filter((c) => c.frame >= at(t.base) && c.frame < at(t.base + t.len)).every((c, j, a) => j === 0 || c.frame >= a[j - 1].frame)), "keys land in typing order");
+ // the press, the drop, the bloom, the landing: on the frames the picture does them
+ f.timing.forEach((t, i) => {
+ ok(by("press")[i]?.frame === at(t.base + t.down), `ask ${i}: the press is on the frame Generate goes down (${by("press")[i]?.frame})`);
+ ok(by("drop")[i]?.frame === at(t.base + t.drop.t0) && by("bloom")[i]?.frame === at(t.base + t.drop.land), `ask ${i}: the drop lifts and blooms on its frames (${by("drop")[i]?.frame}, ${by("bloom")[i]?.frame})`);
+ ok(by("land")[i]?.frame === at(springLand(t.base + t.drop.land, 4.163 / 21, 0.8)), `ask ${i}: the card lands on its spring's first arrival (${by("land")[i]?.frame})`);
+ });
+ // pan by screen x: Generate is right of centre, the answer card left of it (16x9)
+ ok(by("press").every((c) => panOf(c.x, 1920) > 0.1) && by("bloom").every((c) => panOf(c.x, 1920) < -0.1), `panned to where it happens: press ${by("press").map((c) => panOf(c.x, 1920).toFixed(2)).join(", ")}, bloom ${by("bloom").map((c) => panOf(c.x, 1920).toFixed(2)).join(", ")}`);
+ ok(cues.every((c) => c.x === undefined || (c.x >= 0 && c.x <= 1920)), "every cue's screen x is on screen");
+ // restraint: one riser and one impact, at the big reveal only; no whoosh or swish at all; nothing on a type frame's cuts
+ const reveal = f.cut.STARTS[f.cut.SEGS.length - 1];
+ ok(by("riser").length === 1 && by("impact").length === 1 && by("riser")[0].frame === reveal && by("impact")[0].frame === reveal, `one riser and one impact, both at the reveal (frame ${reveal})`);
+ ok(!cues.some((c) => c.kind === "whoosh" || c.kind === "swish"), "no whoosh or swish anywhere");
+ const typeCuts = f.cut.SEGS.flatMap((s, k) => (s.kind === "type" ? [f.cut.STARTS[k], f.cut.STARTS[k] + s.len] : []));
+ ok(typeCuts.length > 0 && !cues.some((c) => typeCuts.some((x) => Math.abs(c.frame - x) <= 2)), `nothing on the cuts into or out of a word page (${typeCuts.join(", ")})`);
+ ok(!cues.some((c) => f.cut.SEGS.some((s, k) => s.kind === "type" && c.frame > f.cut.STARTS[k] && c.frame < f.cut.STARTS[k] + s.len)), "word pages are silent (no cue inside a type frame)");
+
+ // every cue heard over a real score, the mix under -1 dBTP
+ const [L, R] = f.audio!(48000);
+ ok(L.length === Math.round((f.meta.durationFrames / 30) * 48000) && L.length === R.length, `the mix is the film's length (${(L.length / 48000).toFixed(2)} s)`);
+ const bed = makeLaunchFilm({ ...spec, sfx: false }).audio!(48000);
+ const mix = mixLaunch(bed, { fps: 30, frames: f.meta.durationFrames, W: 1920, cues, bpm: 90, seed: 7, key: "G" }, 48000);
+ ok(mix.ok, `every cue audible over the score (${mix.audibility.length} cues, worst margin ${Math.min(...mix.audibility.map((a) => a.marginDb)).toFixed(1)} dB vs floor -6; ${mix.raised.length} raised)`);
+ ok(mix.dbtp <= -1, `the mix's true peak is under the ceiling (${mix.dbtp.toFixed(2)} dBTP)`);
+ const quiet = mixLaunch(bed, { fps: 30, frames: f.meta.durationFrames, W: 1920, cues: cues.map((c) => ({ ...c, gainDb: -30 })), bpm: 90, seed: 7, key: "G" }, 48000, 0);
+ ok(!quiet.ok, "a cue buried 30 dB under the score is caught, not shipped");
+
+ // one timeline at 60 fps: the same cues on the same instants, twice the frames
+ const f60 = makeLaunchFilm({ ...spec, fps: 60 });
+ ok(f60.meta.durationFrames === 2 * f.meta.durationFrames && f60.cues.length === cues.length && f60.cues.every((c, i) => Math.abs(c.frame - 2 * cues[i].frame) <= 1), `60 fps: ${f60.meta.durationFrames} frames, every cue on the same instant (within one 60 fps frame)`);
+ // sync markers: the presses and the impact, for verify-export's audio-to-video check
+ ok(f.meta.sync!.length === 3 && f.meta.sync!.every((s) => cues.some((c) => c.frame === s.frame && (c.role === "press" || c.role === "impact"))), `sync markers are the presses and the impact (${f.meta.sync!.map((s) => s.frame).join(", ")})`);
+ // sfx: false leaves the score alone; a silent film still gets its cues (sound design without music)
+ ok(makeLaunchFilm({ ...spec, sfx: false }).cues.length === 0, "sfx: false emits no cues");
+ const silent = makeLaunchFilm({ ...spec, score: null });
+ ok(silent.cues.some((c) => c.role === "riser" && c.variant === "air") && typeof silent.audio === "function", "a film with no score still has its cues (the riser untuned: air)");
+};
diff --git a/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts b/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts
index 69645ec..66078b8 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts
+++ b/plugins/anidoodle/skills/anidoodle/engine/test/launchTemplate.test.ts
@@ -8,7 +8,8 @@ import type { Film } from "../src/canvas-core/film";
export const name = "launchTemplate";
export const run = (ok: (cond: boolean, label: string) => void) => {
const plate: Film = { meta: { title: "plate", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 60 }, assets: { images: {} }, shots: [{ id: "p", start: 0, end: 60, draw: () => {} }] };
- const base = { title: "Tally", asks: [{ prompt: "draw it", plate, label: "l" }], tagline: "t", install: ["npm i tally"], bpm: 120, askBeats: 8, endBeats: 12 };
+ // sfx: false: these check the score bed alone (the sound cues are launchSound.test.ts)
+ const base = { title: "Tally", asks: [{ prompt: "draw it", plate, label: "l" }], tagline: "t", install: ["npm i tally"], bpm: 120, askBeats: 8, endBeats: 12, sfx: false };
const refused = (score: unknown, re = /anidoodle's own/) => { try { makeLaunchFilm({ ...base, score } as never); return false; } catch (e) { return re.test(String((e as Error).message)); } };
const mine = (): Material => ({
style: "playful", title: "Tally, counted", seed: 5, mood: "curious", bpm: 120, key: "G", mode: "mixolydian",
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs
index 10bdcc3..bd69776 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/adapters/playwright.mjs
@@ -25,7 +25,8 @@ export const open = async ({ pw, browser: found }, pagePath, { scale = 1, worker
frame: async (n, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate((f) => { const s = window.FILM.seek(f); const t = performance.now(); const png = window.FILM.png(); return { ...s, png, enc: performance.now() - t }; }, n); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
hash: (n, w = 0) => pick(w).evaluate((f) => { window.FILM.seek(f); return window.FILM.hash(); }, n),
// motion-blurred frame: `samples` subframes averaged in the page (see hosts/page.ts blur)
- blur: async (n, samples, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, s]) => { const r = window.FILM.blur(f, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
+ // `samples` is a count (a 360-degree shutter, as before) or a spec { samples: N | 0 (auto), shutter, max, px }
+ blur: async (n, samples, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, s]) => { const r = window.FILM.blur(f, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0, samples: r.samples, speed: r.speed }; },
// a frame of the poster dissolve (see hosts/page.ts poster): frame n with poster frame p over it
poster: async (n, p, fade, samples = 1, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, pf, fd, s]) => { const r = window.FILM.poster(f, pf, fd, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, p, fade, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
posterHash: (n, p, fade, samples = 1, w = 0) => pick(w).evaluate(([f, pf, fd, s]) => { window.FILM.poster(f, pf, fd, s); return window.FILM.hash(); }, [n, p, fade, samples]),
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/avsync.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/avsync.mjs
new file mode 100644
index 0000000..c4c3c71
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/avsync.mjs
@@ -0,0 +1,39 @@
+// AV SYNC. The two measurements verify-export makes on a delivered file's sound, as pure functions
+// (no ffmpeg, no browser) so they are unit-tested on synthetic signals:
+// xcorrOffset where the decoded audio sits against the master mix around one sync marker: the lag
+// (samples, sub-sample by a parabola through the peak) that best lines the decoded window
+// up with the master's. An encoder or muxer that shifts the sound shows up here, exactly.
+// onsetNear when a cue actually starts in the delivered audio, near the frame it is meant for:
+// the first 1 ms hop whose energy rises 12 dB over the quiet just before the window.
+// The two answer different questions: the first is "did the file keep the mix's timing", the second
+// "is the sound on its picture frame".
+export const mono = (L, R) => { const m = new Float32Array(L.length); for (let i = 0; i < L.length; i++) m[i] = 0.5 * (L[i] + R[i]); return m; };
+
+/** Lag (in samples; + = the decoded sound is late) of `dec` against `ref` around time `t` (s). */
+export const xcorrOffset = (ref, dec, t, sr, { win = 0.3, maxLagMs = 40 } = {}) => {
+ const W = Math.round(win * sr), a = Math.max(0, Math.round(t * sr - W / 3)), b = Math.min(ref.length, a + W), L = Math.round((maxLagMs / 1000) * sr);
+ let e = 0; for (let i = a; i < b; i++) e += ref[i] * ref[i];
+ if (e < 1e-9) return { lag: NaN, ms: NaN, corr: 0 };
+ const at = (lag) => { let s = 0, d = 0; for (let i = a; i < b; i++) { const j = i + lag; const v = j >= 0 && j < dec.length ? dec[j] : 0; s += ref[i] * v; d += v * v; } return d > 0 ? s / Math.sqrt(e * d) : 0; };
+ let best = 0, bc = -Infinity; const c = new Map();
+ for (let lag = -L; lag <= L; lag++) { const v = at(lag); c.set(lag, v); if (v > bc) { bc = v; best = lag; } }
+ const y0 = c.get(best - 1) ?? bc, y2 = c.get(best + 1) ?? bc, den = y0 - 2 * bc + y2, frac = den < 0 ? (0.5 * (y0 - y2)) / den : 0;
+ const lag = best + Math.max(-0.5, Math.min(0.5, frac));
+ return { lag, ms: (lag / sr) * 1000, corr: bc };
+};
+
+/** The onset time (s) of the sound that starts nearest `t` in [t - before, t + after], or NaN. */
+export const onsetNear = (x, t, sr, { before = 0.05, after = 0.08, riseDb = 12, hopMs = 1 } = {}) => {
+ const hop = Math.max(1, Math.round((hopMs / 1000) * sr)), e = (i) => { let s = 0; for (let k = i; k < Math.min(x.length, i + hop); k++) s += x[k] * x[k]; return s / hop; };
+ const a = Math.max(0, Math.round((t - before) * sr)), b = Math.min(x.length - hop, Math.round((t + after) * sr));
+ const pre = []; for (let i = Math.max(0, a - Math.round(0.06 * sr)); i < a; i += hop) pre.push(e(i));
+ pre.sort((p, q) => p - q); const floor = Math.max(pre[pre.length >> 1] ?? 0, 1e-10), thr = floor * Math.pow(10, riseDb / 10);
+ for (let i = a; i < b; i += hop) if (e(i) > thr) return i / sr;
+ return NaN;
+};
+
+/** WebVTT / SubRip from caption cues in frames: [{ from, to, text }], lines wrapped at `width` characters, two lines at most. */
+const wrap = (s, width = 42) => { const out = []; let line = ""; for (const w of s.split(/\s+/)) { if ((line + " " + w).trim().length > width && line) { out.push(line); line = w; } else line = (line + " " + w).trim(); } out.push(line); return out.length > 2 ? [out[0], out.slice(1).join(" ")] : out; };
+const stamp = (sec, sep) => { const ms = Math.round(sec * 1000), h = Math.floor(ms / 3600000), m = Math.floor(ms / 60000) % 60, s = Math.floor(ms / 1000) % 60; return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}${sep}${String(ms % 1000).padStart(3, "0")}`; };
+export const toSrt = (caps, fps) => caps.map((c, i) => `${i + 1}\n${stamp(c.from / fps, ",")} --> ${stamp(c.to / fps, ",")}\n${wrap(c.text).join("\n")}\n`).join("\n");
+export const toVtt = (caps, fps) => "WEBVTT\n\n" + caps.map((c) => `${stamp(c.from / fps, ".")} --> ${stamp(c.to / fps, ".")}\n${wrap(c.text).join("\n")}\n`).join("\n");
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/build-page.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/build-page.mjs
index 8c5189f..106c404 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/build-page.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/build-page.mjs
@@ -5,7 +5,7 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { createHash } from "node:crypto";
import { extname, join, relative, resolve } from "node:path";
import { overlay, resolveOverlay } from "./overlay.mjs";
-import { requireFilm } from "./names.mjs";
+import { requireFilm, splitShape } from "./names.mjs";
// BAKE KEYS (see Env.bake and hosts/page.ts). Every module that exports `const X: Film` is tagged
// in the bundle with its own path, and each tagged module gets a hash of its WHOLE import closure
@@ -43,6 +43,9 @@ const bakeHashes = (metafile, salt) => {
const MIME = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp", ".woff2": "font/woff2" };
export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {
const plugins = [...extra, overlay]; // extra first: a caller's shim (snap --only) outranks the overlay
+ // <film>-<shape>: the film's own host page, told which shape to compose (hosts/page.ts reshapes it)
+ const { base, shape } = splitShape(title);
+ if (shape) { entry = entry.replace(`page-${title}.ts`, `page-${base}.ts`); title = base; }
if (!existsSync(entry)) entry = resolveOverlay("./" + entry, process.cwd()) ?? entry; // e.g. the example's own host page
if (!existsSync(entry) && title) requireFilm(title, "build", "a film name: src/hosts/page-<film>.ts"); // a clear exit with the known films, not an esbuild trace
const main = await build({ entryPoints: [entry], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", metafile: true, plugins: [...plugins, tagFilms] });
@@ -56,8 +59,9 @@ export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {
const bakeSrc = bakeHashes(main.metafile, salt);
const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${film.meta.title}</title>
<style>html,body{margin:0;height:100%;background:#1b1a1a;display:grid;place-items:center}canvas{max-width:100vw;max-height:100vh;aspect-ratio:${film.meta.W}/${film.meta.H};cursor:pointer;background:#fff}</style></head>
-<body><canvas id="film"></canvas><script>window.__ASSETS__=${JSON.stringify(assets)};window.__BAKE_SRC__=${JSON.stringify(bakeSrc)};</script><script>${js.replace(/<\/script/g, "<\\/script")}</script></body></html>`;
+<body><canvas id="film"></canvas><script>window.__ASSETS__=${JSON.stringify(assets)};window.__BAKE_SRC__=${JSON.stringify(bakeSrc)};${shape ? `window.__SHAPE__=${JSON.stringify(shape)};` : ""}</script><script>${js.replace(/<\/script/g, "<\\/script")}</script></body></html>`;
mkdirSync(join(out, ".."), { recursive: true }); writeFileSync(out, html);
- return { out, bytes: html.length, meta: film.meta, assets: Object.keys(film.assets.images) };
+ const meta = shape ? (film.reshape ? film.reshape(shape).meta : (() => { throw new Error(`${base} has one shape (it has no reshape); ${shape} is for launch template films`); })()) : film.meta;
+ return { out, bytes: html.length, meta, assets: Object.keys(film.assets.images) };
};
if (import.meta.url === `file://${process.argv[1]}`) { const title = requireFilm(process.argv[2], "build-page", "node tools/build-page.mjs <film>"); const r = await buildPage({ entry: `src/hosts/page-${title}.ts`, out: `dist/${title}.html`, title }); console.log(`built ${r.out} (${(r.bytes / 1024).toFixed(0)} KB, self-contained)`); }
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/captions.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/captions.mjs
new file mode 100644
index 0000000..0af1eb0
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/captions.mjs
@@ -0,0 +1,33 @@
+// CAPTIONS. The words a viewer reads in a film, as sidecar caption files: SubRip (.srt) and WebVTT
+// (.vtt), timed in the film's own frames (meta.captions; a launch template film writes them from
+// its prompts, its word pages, its split beats and its end card). Feeds autoplay muted: the captions
+// are the channel most viewers get. A platform that takes a sidecar (YouTube, LinkedIn, the site's
+// <track>) gets these; a feed that does not gets them burned into their own band (captions: "burn").
+// node tools/captions.mjs <film>[-<shape>] [--out out/<film>] writes <out>.srt and <out>.vtt
+import { build } from "esbuild";
+import { mkdirSync, writeFileSync } from "node:fs";
+import { dirname, resolve } from "node:path";
+import { overlay } from "./overlay.mjs";
+import { requireFilm, splitShape } from "./names.mjs";
+import { toSrt, toVtt } from "./avsync.mjs";
+
+export const filmMeta = async (name) => {
+ const { base, shape } = splitShape(name);
+ const js = (await build({ stdin: { contents: `export { ${base} as film } from "./src/canvas-core/${base}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay], logLevel: "error" })).outputFiles[0].text;
+ const { film } = await import("data:text/javascript;base64," + Buffer.from(js).toString("base64"));
+ return (shape ? film.reshape(shape) : film).meta;
+};
+export const writeCaptions = async (name, out = `out/${name}`) => {
+ const meta = await filmMeta(name), caps = meta.captions ?? [];
+ if (!caps.length) return { count: 0, files: [] };
+ mkdirSync(dirname(resolve(out)), { recursive: true });
+ const srt = resolve(`${out}.srt`), vtt = resolve(`${out}.vtt`);
+ writeFileSync(srt, toSrt(caps, meta.fps)); writeFileSync(vtt, toVtt(caps, meta.fps));
+ return { count: caps.length, files: [srt, vtt] };
+};
+if (import.meta.url === `file://${process.argv[1]}`) {
+ const name = requireFilm(process.argv[2], "captions", "node tools/captions.mjs <film>[-<shape>] [--out out/<film>]");
+ const i = process.argv.indexOf("--out"), r = await writeCaptions(name, i > 0 ? process.argv[i + 1] : undefined);
+ if (!r.count) { console.error(`captions: ${name} has no meta.captions (a launch template film writes them; add your own to meta.captions)`); process.exit(1); }
+ console.log(`captions: ${r.count} cues -> ${r.files.join(", ")}`);
+}
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/launch.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/launch.mjs
new file mode 100644
index 0000000..6ba209f
--- /dev/null
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/launch.mjs
@@ -0,0 +1,124 @@
+// LAUNCH. The launch film's two commands: start one, and ship it in every shape.
+//
+// node tools/launch.mjs new <name> [--preset drawn|clean]
+// writes src/canvas-core/<name>.ts (a launch template spec to fill from the brief: every line
+// that must come from the product is marked TODO) and its host page src/hosts/page-<name>.ts.
+// It renders as it is (placeholder plates and UI), so the pipeline can be proved before the art.
+//
+// node tools/launch.mjs ship <name> [--shapes 16x9,1x1,4x5,9x16] [--blur auto] [--shutter 180]
+// [--poster-frame N] [--gate]
+// for each shape, from ONE timeline (launchLayout re-composes it, never a crop):
+// 1 render out/<name>-<shape>.mp4 (render.mjs; --blur/--shutter/--poster-frame pass through)
+// 2 poster out/<name>-<shape>.poster.png, the film's own legible frame (meta.poster: the end card)
+// 3 captions out/<name>-<shape>.srt and .vtt (the sidecar; captions: "burn" also burns them in)
+// 4 verify verify-export --delivery: size, frame count, duration, the score, the sync of every
+// marker, the true peak after the encode, a legible frame 0
+// 5 gate with --gate: gate.mjs (determinism, contract, dead air) on the rendered file
+// then one table. Exit 1 if any shape fails anything.
+import { spawnSync } from "node:child_process";
+import { existsSync, mkdirSync, writeFileSync } from "node:fs";
+import { resolve } from "node:path";
+import { knownFilms, requireFilm, SHAPE_NAMES } from "./names.mjs";
+import { filmMeta, writeCaptions } from "./captions.mjs";
+
+const [cmd, name, ...rest] = process.argv.slice(2);
+const arg = (k, d) => { const i = rest.indexOf(`--${k}`); return i >= 0 ? rest[i + 1] : d; };
+const die = (m) => { console.error(`launch: ${m}`); process.exit(2); };
+const USAGE = "node tools/launch.mjs new <name> [--preset drawn|clean]\n node tools/launch.mjs ship <name> [--shapes 16x9,1x1,4x5,9x16] [--blur auto] [--shutter 180] [--poster-frame N] [--gate]";
+
+const DRAWN = (n) => `// ${n}: a launch film on the template (references/workflows/launch-video-kit.md).
+// Fill every TODO from the sourced brief (references/workflows/launch-video.md, "Ground it in the real
+// product first"): the words on screen quote the brief, never memory. The plates below are STAND-INS
+// (anidoodle's stock plates) so the film renders today; replace each with a plate drawn for YOUR
+// product's subject, in the style the brief chose (references/styles.md).
+// node tools/still.mjs ${n}-9x16 --frames 0,120,330 --sheet out/${n}-9x16.jpg one look per shape, one browser
+// node tools/launch.mjs ship ${n} --shapes 16x9,1x1,9x16
+import { C } from "./launchKit";
+import { makeLaunchFilm } from "./launchTemplate";
+import { lighthouseDraw } from "./lighthouseDraw"; // TODO: your plate
+import { foxDraw } from "./foxDraw"; // TODO: your plate
+
+export const ${n} = makeLaunchFilm({
+ title: "TODO Product", // the exact product name
+ subtitle: "TODO the one line it lives by",
+ placeholder: "Ask for anything…",
+ asks: [
+ { prompt: "TODO what a user types, in their words", plate: lighthouseDraw, label: "TODO the card's byline" },
+ { prompt: "TODO the follow-up", plate: foxDraw, label: "TODO byline" },
+ ],
+ words: [[{ text: "TODO CLAIM.", style: "ink", color: C.ink }, { text: "TODO PROOF.", style: "ink", color: C.accent }]],
+ tagline: "TODO one sentence that says what it is",
+ install: ["TODO the exact install line"], // shown exactly as given, held 3 s or more
+ footer: "TODO where it lives",
+ bpm: 90, // TODO the tempo of the score composed for this brief
+ askBeats: 6, typeBeats: 4, endBeats: 8, claimBar: 4,
+ score: null, // TODO the score composed for this product (references/music/compose.md)
+});
+`;
+const CLEAN = (n) => `// ${n}: a UI-first launch film on the template, in the clean preset (a quiet canvas, one accent,
+// type as the design). Fill every TODO from the sourced brief; the UI data below is a STAND-IN:
+// replace it with your product's real screens and states (references/workflows/launch-video-kit.md).
+// node tools/launch.mjs ship ${n} --shapes 16x9,9x16
+import { makeLaunchFilm } from "./launchTemplate";
+import type { ProductUI } from "./productUI";
+
+const main: ProductUI = { // TODO your product's own UI, its before and after
+ title: "TODO", nav: ["TODO", "TODO"], action: "TODO action", command: "TODO Ask…",
+ before: { items: [{ id: "a", label: "TODO item", value: 3, tag: "TODO" }, { id: "b", label: "TODO item", value: 8 }] },
+ after: { items: [{ id: "b", label: "TODO item", value: 0, done: true, accent: true }, { id: "a", label: "TODO item", value: 0, done: true }] },
+};
+
+export const ${n} = makeLaunchFilm({
+ title: "TODO Product", preset: "clean", fps: 60,
+ asks: [
+ { kind: "ui", ui: main, prompt: "TODO what a user asks the product" },
+ { kind: "ui", ui: main, split: [{ text: "TODO the feature,", style: "ink", color: "#15161a" }, { text: "TODO in five words.", style: "ink", color: "#2f54eb" }] },
+ ],
+ words: [[{ text: "TODO CLAIM.", style: "ink", color: "#15161a" }]],
+ tagline: "TODO one sentence that says what it is",
+ install: ["TODO the exact install line"],
+ footer: "TODO where it lives",
+ bpm: 90, askBeats: 6, typeBeats: 4, endBeats: 8, claimBar: 4,
+ score: null, // TODO the score composed for this product
+});
+`;
+
+if (cmd === "new") {
+ if (!name || !/^[A-Za-z_$][\w$]*$/.test(name)) die(`'${name ?? ""}' is not a film name (a JS identifier, e.g. myLaunch)\nusage: ${USAGE}`);
+ const src = resolve(`src/canvas-core/${name}.ts`), host = resolve(`src/hosts/page-${name}.ts`), preset = arg("preset", "drawn");
+ if (!["drawn", "clean"].includes(preset)) die(`--preset is drawn or clean, got '${preset}'`);
+ if (existsSync(src) || existsSync(host) || knownFilms().includes(name)) die(`${name} already exists; pick another name (never overwritten)`);
+ writeFileSync(src, (preset === "clean" ? CLEAN : DRAWN)(name));
+ writeFileSync(host, `import { ${name} } from "../canvas-core/${name}";\nimport { mountFilm } from "./page";\n\nmountFilm(${name});\n`);
+ console.log(`new launch film: ${src}\n host: ${host}\nnext: fill the TODOs from the brief, then\n node tools/still.mjs ${name} --frames 0,120,330 --sheet out/${name}.jpg\n node tools/launch.mjs ship ${name} --shapes 16x9,9x16`);
+ process.exit(0);
+}
+if (cmd !== "ship") die(`unknown command '${cmd ?? ""}'\nusage: ${USAGE}`);
+
+const film = requireFilm(name, "launch ship", USAGE);
+const shapes = String(arg("shapes", "16x9")).split(",").map((s) => s.trim()).filter(Boolean);
+const bad = shapes.filter((s) => !SHAPE_NAMES.includes(s)); if (bad.length || !shapes.length) die(`--shapes wants ${SHAPE_NAMES.join(", ")}, got '${arg("shapes")}'`);
+const pass = ["blur", "shutter", "poster-frame", "blur-max", "blur-px"].flatMap((k) => (arg(k) !== undefined ? [`--${k}`, arg(k)] : []));
+const node = (args) => spawnSync(process.execPath, args, { stdio: "inherit" }).status === 0;
+const quiet = (args) => { const r = spawnSync(process.execPath, args, { encoding: "utf8", maxBuffer: 1 << 26 }); return { ok: r.status === 0, out: (r.stdout ?? "") + (r.stderr ?? "") }; };
+mkdirSync(resolve("out"), { recursive: true });
+const rows = [];
+for (const sh of shapes) {
+ const f = `${film}-${sh}`, mp4 = `out/${f}.mp4`, row = { shape: sh, mp4, render: false, poster: "", captions: 0, verify: "", gate: "" };
+ console.log(`\n==================== ${f} ====================`);
+ row.render = node(["tools/render.mjs", f, ...pass]);
+ if (row.render) {
+ const meta = await filmMeta(f), pf = meta.poster ?? Math.max(0, meta.durationFrames - 1), png = `out/${f}.poster.png`;
+ row.poster = quiet(["tools/still.mjs", f, "--frame", String(pf), "--out", png]).ok ? `${png} (frame ${pf})` : "FAIL";
+ row.captions = (await writeCaptions(f)).count;
+ const v = quiet(["tools/verify-export.mjs", f, "--file", mp4, "--delivery"]); console.log(v.out.split("\n").filter((l) => /FAIL|PASS (frame|true peak|decoded)|VERIFY-EXPORT/.test(l)).join("\n"));
+ row.verify = (v.out.match(/VERIFY-EXPORT: (PASS|FAIL)[^\n]*/) ?? ["", "FAIL"])[0].replace("VERIFY-EXPORT: ", "");
+ if (rest.includes("--gate")) { const g = quiet(["tools/gate.mjs", f, "--mp4", mp4]); row.gate = (g.out.match(/GATE: (PASS|FAIL)[^\n]*/) ?? [g.ok ? "PASS" : "FAIL"])[0]; if (!g.ok) console.log(g.out.split("\n").filter((l) => /FAIL/.test(l)).join("\n")); }
+ }
+ rows.push(row);
+}
+console.log(`\nSHIP ${film}`);
+for (const r of rows) console.log(` ${r.shape.padEnd(5)} ${r.render ? r.mp4 : "RENDER FAILED"}\n verify ${r.verify || "-"}${r.gate ? ` gate ${r.gate}` : ""}\n poster ${r.poster || "-"} captions ${r.captions} cues -> out/${film}-${r.shape}.srt/.vtt`);
+const ok = rows.every((r) => r.render && /^PASS/.test(r.verify) && r.poster !== "FAIL" && (!r.gate || /PASS/.test(r.gate)));
+console.log(ok ? `\nSHIP: PASS ${rows.length} shape(s)` : "\nSHIP: FAIL");
+process.exit(ok ? 0 : 1);
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/names.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/names.mjs
index 2d3a5c7..375402b 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/names.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/names.mjs
@@ -5,15 +5,20 @@ import { ROOTS } from "./overlay.mjs";
export const defaultOutput = (film) => `out/${film}.mp4`;
+// A film in another frame shape: <film>-<shape> (launchExample-9x16). The host page is the film's own;
+// the page reshapes the film (film.reshape, which a launch template film has). One timeline, many shapes.
+export const SHAPE_NAMES = ["16x9", "1x1", "4x5", "9x16"];
+export const splitShape = (film) => { const m = /^(.+)-(16x9|1x1|4x5|9x16)$/.exec(film ?? ""); return m ? { base: m[1], shape: m[2] } : { base: film, shape: null }; };
+
/** Every film this project can build: one host page, src/hosts/page-<film>.ts (the worked example's too). */
export const knownFilms = () => [...new Set([join(process.cwd(), "src"), ...ROOTS].flatMap((r) => { const d = join(r, "hosts"); return existsSync(d) ? readdirSync(d).filter((f) => /^page-.+\.ts$/.test(f)).map((f) => f.slice(5, -3)) : []; }))].sort();
-const hostOf = (film) => [join(process.cwd(), "src"), ...ROOTS].map((r) => join(r, "hosts", `page-${film}.ts`)).find((f) => existsSync(f));
+const hostOf = (film) => [join(process.cwd(), "src"), ...ROOTS].map((r) => join(r, "hosts", `page-${splitShape(film).base}.ts`)).find((f) => existsSync(f));
/** The film named on the command line, or a clear exit: the usage when none is given, the known films when it is not one. */
export const requireFilm = (film, tool, usage) => {
const list = () => { const k = knownFilms(); return `known films (${k.length}): ${k.join(", ")}`; };
if (!film || film.startsWith("--")) { console.error(`usage: ${usage}\n${list()}`); process.exit(2); }
- if (!/^[A-Za-z_$][\w$]*$/.test(film) || !hostOf(film)) {
+ if (!/^[A-Za-z_$][\w$]*$/.test(splitShape(film).base) || !hostOf(film)) {
const path = /[\\/.]/.test(film) ? `: '${film}' looks like a file path; ${tool} takes a film name (the module src/canvas-core/<film>.ts with its host page src/hosts/page-<film>.ts)` : `: no host page src/hosts/page-${film}.ts`;
console.error(`${tool}: unknown film '${film}'${path}\n${list()}`); process.exit(2);
}
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/render.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/render.mjs
index 3b2448a..ebbdf63 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/render.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/render.mjs
@@ -1,10 +1,16 @@
// node tools/render.mjs <film> [--scale 1] [--workers 4] [--out out/x.mp4|.gif|.webm|.apng] [--gif-fps 15] [--width 640]
// [--blur N] [--from F] [--to F]
-// --blur N motion blur (N an integer >= 1): every output frame is the average of N subframes over
-// a one-frame shutter, integrated in linear light and weighted by alpha inside the page.
-// Fast pans and dolly moves stop juddering; held frames come out unchanged because their
-// subframes are identical. Stepped art (meta.step > 1 or onTwos) is NOT blurred: the
-// shutter would straddle two drawings. Costs N times the draw time. --blur 1 is untouched.
+// --blur N|auto motion blur: every output frame is the average of subframes spread over the shutter,
+// integrated in linear light and weighted by alpha inside the page. Fast pans and dolly
+// moves stop juddering. Stepped art (meta.step > 1 or onTwos) is NOT blurred: the shutter
+// would straddle two drawings. --blur 1 is untouched.
+// N: N subframes on every frame (costs N times the draw time).
+// auto: as many as the frame's own on-screen speed needs, measured per frame by block-
+// matching two sharp renders at the shutter's ends: subframes at most --blur-px apart
+// (default 3 px), 1 on a still frame (the sharp frame, untouched), at most --blur-max (32).
+// Deterministic: the count is a function of the frame's pixels.
+// --shutter DEG the shutter angle: 180 (default, film's standard: half the frame interval) to 360
+// (the whole interval, the old --blur behaviour). 180-240 reads as natural motion.
// --from/--to render only frames [from, to): for checking a passage, not for shipping. A range
// render is silent (the score would not line up), says so, and by default writes
// out/<film>.<from>-<to>.<ext> so it can never overwrite the finished film.
@@ -22,7 +28,10 @@
// whatever sits behind the page shows through
// .apng animated PNG, alpha kept, loops forever, plays in every browser
// --width only applies to the silent formats; the MP4 is always the film's own size.
-import { spawn, execFileSync } from "node:child_process";
+// --shapes 16x9,1x1,4x5,9x16 a launch template film in several frame shapes from ONE timeline: each
+// shape is re-composed by its layout (launchLayout.ts), never cropped, and rendered as the
+// film <film>-<shape> to out/<film>-<shape>.mp4, one after another, with the other flags.
+import { spawn, spawnSync, execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdirSync, writeFileSync } from "node:fs";
import { cpus } from "node:os";
@@ -35,9 +44,21 @@ import { float32Wav } from "./audio.mjs";
import { firstFrameBlank } from "./thumb.mjs";
const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; };
+if (process.argv.includes("--shapes")) {
+ const { SHAPE_NAMES, splitShape } = await import("./names.mjs");
+ const shapes = String(arg("shapes", "")).split(",").map((x) => x.trim()).filter(Boolean), bad = shapes.filter((x) => !SHAPE_NAMES.includes(x));
+ if (!shapes.length || bad.length) { console.error(`--shapes wants a list of ${SHAPE_NAMES.join(", ")}, got '${arg("shapes", "")}'`); process.exit(2); }
+ if (process.argv.includes("--out")) { console.error("--shapes writes out/<film>-<shape>.<ext> for each shape; drop --out"); process.exit(2); }
+ const base = splitShape(process.argv[2]).base, rest = process.argv.slice(3).filter((a, i, all) => a !== "--shapes" && all[i - 1] !== "--shapes");
+ for (const sh of shapes) { console.log(`\n==== ${base}-${sh} ====`); const r = spawnSync(process.execPath, [process.argv[1], `${base}-${sh}`, ...rest], { stdio: "inherit" }); if (r.status) process.exit(r.status); }
+ process.exit(0);
+}
const film = requireFilm(process.argv[2], "render", "node tools/render.mjs <film> [--scale 1] [--out out/x.mp4|.gif|.webm|.apng] [--from F] [--to F] [--poster-frame N] [--blur N]");
-const BLUR = Number(arg("blur", 1));
-if (!Number.isInteger(BLUR) || BLUR < 1) { console.error(`--blur wants a whole number of subframes >= 1, got '${arg("blur")}'`); process.exit(2); }
+const BLUR = arg("blur", "1") === "auto" ? "auto" : Number(arg("blur", 1)), SHUTTER = Number(arg("shutter", 180)), BMAX = Number(arg("blur-max", 32)), BPX = Number(arg("blur-px", 3));
+if (BLUR !== "auto" && (!Number.isInteger(BLUR) || BLUR < 1)) { console.error(`--blur wants a whole number of subframes >= 1 or 'auto', got '${arg("blur")}'`); process.exit(2); }
+if (!(SHUTTER > 0 && SHUTTER <= 360)) { console.error(`--shutter wants an angle in (0, 360] degrees, got '${arg("shutter")}'`); process.exit(2); }
+if (!Number.isInteger(BMAX) || BMAX < 2 || !(BPX > 0)) { console.error(`--blur-max wants a whole number >= 2 and --blur-px a number > 0`); process.exit(2); }
+const BLURRED = BLUR === "auto" || BLUR > 1, BSPEC = BLUR === "auto" ? { samples: 0, shutter: SHUTTER, max: BMAX, px: BPX } : { samples: BLUR, shutter: SHUTTER };
const scale = Number(arg("scale", 1)), fmt = (arg("out", "").match(/\.(gif|webm|apng)$/i)?.[1] ?? "mp4").toLowerCase(), workers = Number(arg("workers", Math.max(1, Math.min(4, Math.floor(cpus().length / 2)))));
const HASHES = arg("hashes", null) ? new Map() : null;
const RANGE_ASKED = process.argv.includes("--from") || process.argv.includes("--to");
@@ -67,11 +88,11 @@ if (RANGE_ASKED && !ranged) console.log("range covers the whole film: rendering
if (POSTER !== null && POSTER >= N) { console.error(`--poster-frame ${POSTER} is outside the film; this film has frames 0-${N - 1}`); process.exit(2); }
if (POSTER !== null) console.log(`poster: frame 0 is frame ${POSTER}, dissolving into the opening by frame ${Math.max(1, FADE)}`);
const posterAt = (n) => POSTER !== null && n < Math.max(1, FADE); // frames the poster dissolve touches
-const drawAt = (n, w) => (posterAt(n) ? session.poster(n, POSTER, FADE, BLUR, w) : BLUR > 1 ? session.blur(n, BLUR, w) : session.frame(n, w));
+const drawAt = (n, w) => (posterAt(n) ? session.poster(n, POSTER, FADE, BLURRED ? BSPEC : 1, w) : BLURRED ? session.blur(n, BSPEC, w) : session.frame(n, w));
// a film whose cuts sit on its beat grid (meta.score.grid) must hear its score at that grid's tempo
if (meta.score?.grid && Math.abs(meta.score.tempo / meta.bpm - 1) > 0.005) { console.error(`render: the score plays at ${meta.score.tempo.toFixed(2)} bpm but this film's cuts sit on a ${meta.bpm} bpm grid (${((meta.score.tempo / meta.bpm - 1) * 100).toFixed(1)} %, limit 0.5 %): the cuts would drift off the downbeats. Play the score at the film's bpm and make the film whole bars of it (launchTemplate does), or compose a 1-bar stretch section`); process.exit(2); }
console.log(`film: "${meta.title}" ${meta.W}x${meta.H} @ ${meta.fps} fps, ${N} frames, ${meta.bpm} bpm, scale ${scale}, ${session.workers} page(s)`);
-if (BLUR > 1) console.log(`motion blur: ${BLUR} subframes per frame, one-frame shutter, linear light`);
+if (BLURRED) console.log(`motion blur: ${BLUR === "auto" ? `adaptive (subframes <= ${BPX} px apart, max ${BMAX})` : `${BLUR} subframes per frame`}, ${SHUTTER}-degree shutter, linear light`);
if (ranged) console.log(`range render: frames [${FROM}, ${TO}) of ${N}, silent by design`);
// audio: pure JS in the page -> WAV here (skipped for a range render: the score would not line up)
@@ -107,7 +128,7 @@ const done = new Promise((res, rej) => ff.on("close", (c) => (c ? rej(new Error(
const cost = [], pending = new Map(); let next, write;
const pump = async () => { while (pending.has(write)) { const b = pending.get(write); pending.delete(write); if (!ff.stdin.write(b)) await new Promise((r) => ff.stdin.once("drain", r)); write++; } };
next = FROM; write = FROM;
-await Promise.all(Array.from({ length: session.workers }, async (_, w) => { while (next < TO) { const n = next++; while (n - write > session.workers * 3) await new Promise((r) => setTimeout(r, 5)); const f = await drawAt(n, w); if (HASHES) HASHES.set(n, createHash("md5").update(f.png).digest("hex")); cost.push({ n, shot: f.shot, draw: f.drawMs, enc: f.encodeMs, rt: f.roundTripMs }); pending.set(n, f.png); await pump(); } }));
+await Promise.all(Array.from({ length: session.workers }, async (_, w) => { while (next < TO) { const n = next++; while (n - write > session.workers * 3) await new Promise((r) => setTimeout(r, 5)); const f = await drawAt(n, w); if (HASHES) HASHES.set(n, createHash("md5").update(f.png).digest("hex")); cost.push({ n, shot: f.shot, draw: f.drawMs, enc: f.encodeMs, rt: f.roundTripMs, samples: f.samples ?? 1 }); pending.set(n, f.png); await pump(); } }));
await pump(); ff.stdin.end(); await done;
const wall = (Date.now() - t0) / 1000;
if (HASHES) { const hf = resolve(arg("hashes")); mkdirSync(join(hf, ".."), { recursive: true }); writeFileSync(hf, [...HASHES].sort((a, b) => a[0] - b[0]).map(([n, h]) => `${n} ${h}`).join("\n") + "\n"); console.log(`frame hashes -> ${hf}`); }
@@ -118,15 +139,16 @@ console.log("\nframe cost (ms), draw = art core only, png = canvas PNG encode in
for (const id of [...new Set(cost.map((c) => c.shot))]) { const c = cost.filter((x) => x.shot === id), d = stat(c.map((x) => x.draw)), e = stat(c.map((x) => x.enc)); console.log(` ${id.padEnd(12)} draw median ${d.med.toFixed(0)} p95 ${d.p95.toFixed(0)} max ${d.max.toFixed(0)} | png median ${e.med.toFixed(0)} (${c.length} frames)`); }
const slow = [...cost].sort((a, b) => b.draw - a.draw).slice(0, 3).map((c) => `#${c.n} ${c.shot} ${c.draw.toFixed(0)}ms`).join(", ");
console.log(` slowest: ${slow}\n budget: 150 ms draw per frame -> ${cost.every((c) => c.draw <= 150) ? "PASS" : "OVER on " + cost.filter((c) => c.draw > 150).length + " frames"}`);
+if (BLUR === "auto") { const hist = {}; cost.forEach((c) => { const b = c.samples <= 1 ? "1" : c.samples <= 4 ? "2-4" : c.samples <= 8 ? "5-8" : c.samples <= 16 ? "9-16" : "17+"; hist[b] = (hist[b] ?? 0) + 1; }); console.log(` adaptive blur: subframes per frame ${Object.entries(hist).map(([k, v]) => `${k}: ${v}`).join(", ")} (mean ${(cost.reduce((a, c) => a + c.samples, 0) / cost.length).toFixed(1)}, max ${Math.max(...cost.map((c) => c.samples))})`); }
console.log(` wall clock: ${wall.toFixed(1)} s for ${TO - FROM} frames = ${((TO - FROM) / wall).toFixed(1)} fps end to end (build + launch + render + encode)`);
// ---- verify: same frame, different order, different page. Standard = visually identical; hash equality is the cheap first test.
const probe = [...new Set([0, ...meta.shots.flatMap((s) => [s.start, s.end - 1]), ...((k) => Array.from({ length: k }, (_, i) => Math.round(i * (N - 1) / (k - 1 || 1))))(Math.min(6, N)), N - 1])].filter((n) => n >= FROM && n < TO).sort((a, b) => a - b), fwd = [], rev = [];
if (!probe.length) probe.push(FROM);
-const hashOf = (n, w) => (posterAt(n) ? session.posterHash(n, POSTER, FADE, BLUR, w) : BLUR > 1 ? session.blurHash(n, BLUR, w) : session.hash(n, w)); // probe what was WRITTEN: poster dissolve, blurred frame
+const hashOf = (n, w) => (posterAt(n) ? session.posterHash(n, POSTER, FADE, BLURRED ? BSPEC : 1, w) : BLURRED ? session.blurHash(n, BSPEC, w) : session.hash(n, w)); // probe what was WRITTEN: poster dissolve, blurred frame
for (const n of probe) fwd.push(await hashOf(n, 0)); for (const n of [...probe].reverse()) rev.unshift(await hashOf(n, session.workers - 1));
const same = probe.filter((_, i) => fwd[i] === rev[i]).length;
-console.log(`\ndeterminism: ${same}/${probe.length} probe frames${BLUR > 1 ? ` (blurred, ${BLUR} subframes)` : ""} hash-identical (forward on page 0 vs reversed on page ${session.workers - 1})${same === probe.length ? "" : " -> fall back to PSNR > 45 dB in the Phase 2 gate"}`);
+console.log(`\ndeterminism: ${same}/${probe.length} probe frames${BLURRED ? ` (blurred, ${BLUR === "auto" ? "adaptive" : `${BLUR} subframes`}, ${SHUTTER} degrees)` : ""} hash-identical (forward on page 0 vs reversed on page ${session.workers - 1})${same === probe.length ? "" : " -> fall back to PSNR > 45 dB in the Phase 2 gate"}`);
await session.close();
const pr = execFileSync("ffprobe", ["-v", "error", "-show_entries", "stream=codec_type,codec_name,width,height,nb_frames,duration", "-of", "csv=p=0", out]).toString().trim().split("\n");
console.log(`\noutput: ${out}`); pr.forEach((l) => console.log(` ${l}`));
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/verify-export.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/verify-export.mjs
index b9a77a4..1bf95dc 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/verify-export.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/verify-export.mjs
@@ -15,7 +15,17 @@
// [--fidelity-psnr N] a decoded frame must sit within N dB of the source frame (renders it once)
// [--frame N] which frame --fidelity-psnr compares (default 0)
// [--delivery] this file ships: a near-blank frame 0 (the platform thumbnail) FAILS
-// instead of warning; fix with render --poster-frame N
+// instead of warning; fix with render --poster-frame N; and the true
+// peak AFTER the encode must be at or under -1 dBTP (else it is reported)
+// [--sync-tol MS] audio-to-video: the decoded sound may sit this far from the master mix
+// at each sync marker (default 1 ms)
+//
+// With a score, an MP4 is also checked for SYNC and PEAK: at each of the film's sync markers
+// (meta.sync: the presses and the impact of a launch film; three evenly spaced points otherwise)
+// the decoded audio is cross-correlated with the master mix the page makes (the offset in ms, sub-
+// sample), and the cue's attack in the delivered file is measured against its frame and against the
+// master's own attack (5 ms: AAC pre-echo); the true peak is measured on the DECODED file (ebur128, 4x oversampled), because an AAC
+// encode can push a -1 dBTP master over the ceiling.
//
// Always checked: the file decodes, its pixel size, its exact frame count, its duration against
// the film's meta, and for an MP4 the score: an audio stream exactly when the film has a score,
@@ -25,8 +35,9 @@ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { basename, resolve } from "node:path";
import { defaultOutput, requireFilm } from "./names.mjs";
import { firstFrameBlank } from "./thumb.mjs";
+import { mono, onsetNear, xcorrOffset } from "./avsync.mjs";
-const VAL = new Set(["file", "adapter", "width", "first-frame", "tol", "fidelity-psnr", "scale", "frame"]);
+const VAL = new Set(["file", "adapter", "width", "first-frame", "tol", "fidelity-psnr", "scale", "frame", "sync-tol"]);
const pos = [], opt = {};
for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }
// a file path names its film: out/<film>.mp4 (or a range render's out/<film>.<from>-<to>.mp4)
@@ -98,6 +109,36 @@ if (isMp4) {
const vd = spawnSync("ffmpeg", ["-v", "info", "-i", file, "-map", "0:a:0", "-af", "volumedetect", "-f", "null", "-"], { encoding: "utf8" });
const mx = Number(((vd.stdout + vd.stderr).match(/max_volume:\s*(-?[0-9.]+|-inf) dB/) ?? [])[1]);
say(Number.isFinite(mx) && mx > -40 && mx <= 0, `audio peak ${Number.isFinite(mx) ? mx.toFixed(1) : "-inf"} dBFS`, "audible (> -40 dBFS) and not clipped past 0");
+
+ head("1c", "SYNC the delivered sound sits on the picture's frames");
+ const SR = 48000, dec = spawnSync("ffmpeg", ["-v", "error", "-i", file, "-map", "0:a:0", "-f", "f32le", "-ac", "2", "-ar", String(SR), "-"], { maxBuffer: 1 << 30 });
+ if (dec.status !== 0) die(`ffmpeg could not decode the audio: ${dec.stderr.toString().trim()}`);
+ const di = new Float32Array(dec.stdout.buffer.slice(dec.stdout.byteOffset, dec.stdout.byteOffset + dec.stdout.byteLength)), dL = new Float32Array(di.length / 2), dR = new Float32Array(di.length / 2);
+ for (let i = 0; i < dL.length; i++) { dL[i] = di[2 * i]; dR[i] = di[2 * i + 1]; }
+ const master = await s.audio(SR), mb = Buffer.from(master.float32, "base64"), mi = new Float32Array(mb.buffer.slice(mb.byteOffset, mb.byteOffset + mb.byteLength)), mL = new Float32Array(master.frames), mR = new Float32Array(master.frames);
+ for (let i = 0; i < master.frames; i++) { mL[i] = mi[2 * i]; mR[i] = mi[2 * i + 1]; }
+ const ref = mono(mL, mR), got = mono(dL, dR), tol = Number(opt["sync-tol"] ?? 1);
+ const marks = meta.sync?.length ? meta.sync : [0.25, 0.5, 0.75].map((q) => ({ frame: Math.round(q * N), label: `${Math.round(q * 100)} % in` }));
+ if (!meta.sync?.length) note("no sync markers in meta.sync", "checking three points of the mix instead (a launch template film names its presses and its impact)");
+ for (const mk of marks) {
+ const t = mk.frame / meta.fps, x = xcorrOffset(ref, got, t, SR);
+ if (!Number.isFinite(x.ms)) { note(`frame ${mk.frame} (${mk.label}): the master is silent there`, "nothing to line up"); continue; }
+ say(Math.abs(x.ms) <= tol && x.corr > 0.5, `frame ${mk.frame} ${mk.label}: decoded vs master ${x.ms >= 0 ? "+" : ""}${x.ms.toFixed(2)} ms`, `limit ${tol} ms (correlation ${x.corr.toFixed(3)})`);
+ // the cue's attack, heard in the file, against where the master put it: a sound may be designed to
+ // lead its hit (a press's finger noise, an impact's breath), so the frame itself is the master's truth
+ if (meta.sync?.length) {
+ const on = onsetNear(got, t, SR), want = onsetNear(ref, t, SR);
+ if (Number.isFinite(on) && Number.isFinite(want)) say(Math.abs(on - want) * 1000 <= 5, `frame ${mk.frame} ${mk.label}: the attack starts ${((on - t) * 1000).toFixed(1)} ms from its frame`, `the master's attack is at ${((want - t) * 1000).toFixed(1)} ms (the sound's own lead); delivered within 5 ms of it (AAC pre-echo can pull a sharp attack a few ms early)`);
+ else note(`frame ${mk.frame} ${mk.label}: no attack found within 80 ms`, "a soft attack; the cross-correlation above is the sync measurement");
+ }
+ }
+
+ head("1d", "PEAK the true peak of the file as delivered (after the encode)");
+ const eb = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", file, "-map", "0:a:0", "-af", "ebur128=peak=true", "-f", "null", "-"], { encoding: "utf8", maxBuffer: 1 << 26 });
+ const txt = eb.stdout + eb.stderr, tp = Number((txt.match(/True peak:\s*\n\s*Peak:\s*(-?[0-9.]+|-inf) dBFS/) ?? [])[1]), il = Number((txt.match(/Integrated loudness:\s*\n\s*I:\s*(-?[0-9.]+) LUFS/) ?? [])[1]);
+ if (!Number.isFinite(tp)) note("true peak unreadable from ffmpeg's ebur128", txt.split("\n").slice(-4).join(" "));
+ else if (opt.delivery) say(tp <= -1.0, `true peak after the encode ${tp.toFixed(2)} dBTP`, `ceiling -1 dBTP; integrated ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`);
+ else note(`true peak after the encode ${tp.toFixed(2)} dBTP${tp > -1 ? " (over -1: --delivery fails this)" : ""}`, `integrated ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`);
}
}
diff --git a/plugins/anidoodle/skills/anidoodle/references/formats.md b/plugins/anidoodle/skills/anidoodle/references/formats.md
index 79b13a9..0ffdd51 100644
--- a/plugins/anidoodle/skills/anidoodle/references/formats.md
+++ b/plugins/anidoodle/skills/anidoodle/references/formats.md
@@ -68,9 +68,17 @@ Render options that hold for every moving format:
on frame N (the wall of styles, the logo, the prompt written big) and dissolves into the real
opening by frame 6. The frame count and the score are unchanged. A delivery whose frame 0 is
near-blank gets a warning after the encode.
-- `--blur N`: motion blur, each output frame the average of N subframes over a one-frame shutter,
- in linear light and weighted by alpha (so a transparent WebM or APNG gets no dark fringe). Held
- frames come out unchanged; stepped art (`meta.step` > 1, `onTwos`) is never blurred.
+- `--blur auto` (or `--blur N`): motion blur, each output frame the average of subframes over the
+ shutter, in linear light and weighted by alpha (so a transparent WebM or APNG gets no dark
+ fringe). `auto` measures each frame's on-screen motion (two sharp renders at the shutter's ends,
+ block-matched; drawing strokes, typed letters and halftone patterns are not mistaken for motion)
+ and takes subframes at most `--blur-px` apart (default 3 px): 1 on a still frame, which comes out
+ untouched, up to `--blur-max` (32) on a whip. Deterministic. `--shutter DEG` is the shutter
+ angle, 180 by default (360 is the old whole-frame shutter). Stepped art (`meta.step` > 1,
+ `onTwos`) is never blurred.
+- `--shapes 16x9,1x1,4x5,9x16`: a launch template film rendered in each shape from one timeline
+ (each re-composed by its layout, never cropped) to `out/<name>-<shape>.mp4`. Any tool takes
+ `<name>-<shape>` as the film's name for one shape.
- `--from F --to T`: frames `[F, T)` only, silent, written to `out/<name>.<F>-<T>.<ext>`, never
over the finished film. For checking a passage, not for shipping.
- `--hashes out/x.md5`: the md5 of every frame handed to the encoder, for frame-exact
@@ -78,7 +86,10 @@ Render options that hold for every moving format:
After any encode, `node tools/verify-export.mjs <name> [--first-frame #hex] [--fidelity-psnr 40]`
proves the file on disk is the film: size, exact frame count, duration, the score (an audio
-stream exactly when the film has one, as long as the picture, not silent), and optionally the
+stream exactly when the film has one, as long as the picture, not silent), its SYNC (the decoded
+sound cross-correlated with the master mix at each of `meta.sync`'s markers, within 1 ms, and each
+cue's attack where the master put it), its true peak after the encode (-1 dBTP under
+`--delivery`), and optionally the
first frame's average colour and its fidelity to the source frame (`--frame N` picks which
frame `--fidelity-psnr` compares; default 0). All of it is opt-in beyond the container facts,
so transparent and non-uniform pieces pass cleanly. For a file that ships, add `--delivery`: a
diff --git a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md
index 76552b0..fff4a32 100644
--- a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md
+++ b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video-kit.md
@@ -5,22 +5,35 @@ product. The rules they serve are in `launch-video.md`.
## Start from the template (16 s, one file)
-`launchTemplate.ts` turns data into a film: two or three prompts answered by plates drawing
-themselves in a chat thread, a type frame between them, and an end card with your install lines.
-`launchExample.ts` is a complete one for a made-up product. Copy its shape, not its contents:
-the plates and the score are the product's own, made for its brief.
+`launchTemplate.ts` turns data into a film: one to three asks, a type frame between them, and an
+end card with your install lines. `launchExample.ts` is a complete one for a made-up product (the
+drawn look, chat asks); `launchExampleClean.ts` is the second look on a UI-first product (the
+product's own UI, a split beat, a film in a card, 60 fps). Copy their shape, not their contents:
+the plates, the UI data and the score are the product's own, made for its brief.
+
+```bash
+node tools/launch.mjs new myLaunch # the spec, every product line marked TODO (--preset clean for UI-first)
+node tools/still.mjs myLaunch-9x16 --frames 0,120,330 --sheet out/look-9x16.jpg # one look per shape, one browser
+node tools/launch.mjs ship myLaunch --shapes 16x9,1x1,9x16 --blur auto --gate
+```
+
+`ship` renders every shape to `out/myLaunch-<shape>.mp4`, writes its poster (`.poster.png`, the
+film's own legible frame) and its captions (`.srt`, `.vtt`), runs `verify-export --delivery` on each
+file (size, frames, score, A/V sync at every marker, the true peak after the encode, a legible frame
+0) and, with `--gate`, the gate; one table at the end, exit 1 if any shape fails.
```ts
import { C } from "./launchKit";
import { makeLaunchFilm } from "./launchTemplate";
import { dashboardSketch, onboardingSketch } from "./myProductPlates"; // drawn for YOUR subject
import { myProductScore } from "./myProductScore"; // composed for YOUR brief
+import { myInbox } from "./myProductUI"; // YOUR product's UI, as data (productUI.ts)
export const myLaunch = makeLaunchFilm({
title: "Your Product", subtitle: "the one line it lives by",
asks: [
{ prompt: "sketch my dashboard, as a print", plate: dashboardSketch, label: "print · drawn in code" },
- { prompt: "now the onboarding screen", plate: onboardingSketch, label: "a second answer, same thread" },
+ { kind: "ui", ui: myInbox, prompt: "match every receipt" }, // the product's own UI, before -> after
],
words: [[{ text: "IDEA IN.", style: "ink", color: C.ink }, { text: "ART OUT.", style: "ink", color: C.accent }]],
tagline: "One sentence that says what it is",
@@ -31,48 +44,87 @@ export const myLaunch = makeLaunchFilm({
});
```
-Add `src/hosts/page-myLaunch.ts` (three lines, copy `page-launchExample.ts`), then:
-
-```bash
-node tools/still.mjs myLaunch --frame 0 --out out/poster.png # the first frame is the thumbnail
-node tools/still.mjs myLaunch --frames 0-420:30 --sheet out/sheet.jpg # the cut on one sheet, one browser
-node tools/render.mjs myLaunch # --poster-frame N if frame 0 is quiet
-node tools/gate.mjs myLaunch
-node tools/verify-export.mjs myLaunch --file out/myLaunch.mp4 --delivery
-```
-
-What you get: the first prompt already being typed at frame 0 in a close-up (a hook that reads
-muted), the camera easing out for the press, an ink drop arcing from Generate into the thread
-and blooming open into a card where the plate draws itself live, the thread keeping earlier
-answers and scrolling, a gentle lean onto each new card, full-frame word pages between asks,
-and the end card blooming open and holding. The corner mark (your name, hand-lettered) steps
-aside before any lean. Real holds are declared, so the gate passes. Sync wins over length: the
-score plays at the film's bpm exactly, so every cut sits on its downbeats, and the film is made
-whole bars of the score (`gridScore`: the stretch section repeated or dropped, then the end-card
-hold, which is a hold, grows or shrinks to the bar; the tail rings out in whole bars). A score in
-4/4 with no pickup, starting on frame 0. If no form fits, the build throws: compose a 1-bar
-stretch section or change askBeats/endBeats. Render refuses a beat-grid film whose score is more
-than 0.5 % off its bpm. The bed is set to -14 LUFS with the true peak at or under -1 dBTP
-(`musicBed`); a dynamic piece stops at the peak ceiling first and render says how far short;
-`limit: true` lets a look-ahead limiter take those peaks instead.
-
-**The plates and the score are made for this product, every time.** A style is a recipe applied
-to the user's subject (`references/styles.md`): draw their dashboard, their mascot, their
-product's world in the chosen hand, as a still plus its `*Draw` film. anidoodle's own plates
-(the lighthouse and fox in `launchExample.ts`) are placeholders, never a user's film. The score
-is composed for the brief's style, mood and length (`references/music/compose.md`); `score` is
-required (`null` means silent), `bpm` has no default, and the template refuses anidoodle's own
-pieces, by identity, by title and by content (the same novelty gate `music.mjs check` runs).
+What you get, from data:
+
+- **Chat asks** (`kind` omitted): the first prompt already being typed at frame 0 in a close-up (a
+ hook that reads muted), the camera easing out for the press, an ink drop arcing from Generate
+ into the thread and blooming open into a card where the plate draws itself live (the card opens
+ on a spring), the thread keeping earlier answers and scrolling, a gentle lean onto each new card.
+- **UI asks** (`kind: "ui"`): the product's interface drawn from data (`productUI.ts`) in its
+ `before` state; the ask typed into its command bar if it has a `prompt`; the pointer presses its
+ `action`; every item springs to its place in the `after` state (matched by `id`: rows move,
+ numbers count, bars fill, new items arrive, old ones leave).
+- **Film asks** (`kind: "film"`): any film of this engine (a `webTour`, a loop, a plate) in a card.
+- **Split feature beats**: a UI or film ask with `split: [lines]` puts its words in their own
+ column beside the live UI (above it on a phone), never over it: faster than a full word page.
+- **Seams**: chat to chat is one thread; a seam between kinds with no word page opens as a bloom.
+- **The motif**: an ink drop lifts off Generate (or the product's action, or the film's card) and
+ lands as the dot of the end card's mark ("NAME."); the end card blooms open FROM it and stays.
+- **Sound from the picture** (`launchSound.ts`): a key per character typed (the space bar its
+ own), the press on the frame Generate goes down, the drop and its bloom, each card landing on its
+ spring's first arrival, each UI item's landing; every cue panned to where it happens on screen;
+ one riser and one impact at the reveal and nothing on any other cut. A cue measured under the
+ score is raised until heard (at most +8 dB), then the mix is checked and a buried cue throws.
+ `film.cues` lists them; `meta.sync` names the presses and the impact for verify-export.
+- **Captions**: `meta.captions` from the prompts, the word pages, the split words and the end card;
+ `launch.mjs ship` or `captions.mjs` writes `.srt`/`.vtt`; `captions: "burn"` also draws them
+ in their own band under the picture on the phone shapes (the picture is composed above it).
+- The corner mark (your name) steps aside before any lean. Real holds are declared, so the gate
+ passes.
+
+Sync wins over length: the score plays at the film's bpm exactly, so every cut sits on its
+downbeats, and the film is made whole bars of the score (`gridScore`: the stretch section
+repeated or dropped, then the end-card hold, which is a hold, grows or shrinks to the bar; the
+tail rings out in whole bars). A score in 4/4 with no pickup, starting on frame 0. If no form
+fits, the build throws: compose a 1-bar stretch section or change askBeats/endBeats. Render
+refuses a beat-grid film whose score is more than 0.5 % off its bpm. The bed is set to -14 LUFS
+with the true peak at or under -1 dBTP (`musicBed`); a dynamic piece stops at the peak ceiling
+first and render says how far short; `limit: true` lets a look-ahead limiter take those peaks.
+
+**The plates, the UI and the score are made for this product, every time.** A style is a recipe
+applied to the user's subject (`references/styles.md`): draw their dashboard, their mascot, their
+product's world in the chosen hand, as a still plus its `*Draw` film; a UI ask's data comes from
+the product's real screens and states. anidoodle's own plates (the lighthouse and fox in
+`launchExample.ts`) and the web tour are placeholders, never a user's film. The score is composed
+for the brief's style, mood and length (`references/music/compose.md`); `score` is required
+(`null` means silent), `bpm` has no default, and the template refuses anidoodle's own pieces, by
+identity, by title and by content (the same novelty gate `music.mjs check` runs).
+
+### One timeline, four shapes
+
+`shape: "16x9" | "1x1" | "4x5" | "9x16"` (or `film.reshape(shape)`, or the film name
+`myLaunch-9x16` in any tool) composes the same cut for another frame through `launchLayout.ts`:
+the chat window, composer and card are laid out for the frame (a phone composer wraps the prompt
+and the camera glides after the caret, a line at a time), word pages re-set their lines, the split
+beat stacks, the end card stacks and centres. The timing, the cut and the sound do not change.
+Every line a viewer must read is phone-safe on 1x1, 4x5 and 9x16: at least 32 px at 1080 across
+(about 11 pt on a phone) for prompts, bubbles, card labels, tagline and install lines, 64 px for a
+word page; the layout throws with the fix when one cannot be (an install line too long for 9x16).
+
+### Two looks
+
+`preset: "drawn"` (default): ink blooms, hand-lettered words (`writeOn`), a warm paper palette.
+`preset: "clean"`: a quiet canvas, ONE accent colour (the button, the drop, the dot, the caret;
+`accent` sets it), type as the design: word pages SET in a heavy sans (`setType`: each word rises
+into place behind its own baseline), round iris seams instead of ink, the answer card opening as
+an iris. Both are ours: the clean look is a register, not a copy of anyone's film.
+
+### Frame rate and motion blur
+
+`fps: 60` doubles the frames on the same timing (a UI-heavy film's scrolls and springs read
+smoother); the cues, holds, captions and sync markers follow. `render.mjs --blur auto` takes as
+many subframes as each frame's measured on-screen speed needs (1 on a still frame), `--shutter 180`.
| Spec field | Meaning |
|---|---|
-| `title`, `subtitle`, `placeholder`, `genLabel`, `accent` | the chat's name, subline, empty text, button word, button colour |
-| `asks[]` | 1-3 of `{ prompt, plate, label, from?, to?, crop? }` |
+| `title`, `subtitle`, `placeholder`, `genLabel`, `accent` | the chat's name, subline, empty text, button word, button (and the clean look's one accent) colour |
+| `asks[]` | 1-3 of `{ prompt, plate, label, from?, to?, crop? }` (chat), `{ kind: "ui", ui, prompt?, split? }`, `{ kind: "film", film, from?, to?, split? }` |
| `words[i]` | the type frame after `asks[i]` (not after the last ask; it flows into the end card) |
| `tagline`, `install[]`, `footer` | the end card; install lines are shown exactly as given |
-| `bpm` (required), `fps`, `askBeats`, `typeBeats`, `endBeats` | the beat grid (a beat is 60 x fps / bpm frames) and each part's length in beats |
+| `bpm` (required), `fps` (30 or 60), `askBeats`, `typeBeats`, `endBeats` | the beat grid (a beat is 60 x 30 / bpm frames at 30 fps) and each part's length in beats |
| `claimBar` | land the end card on this bar's downbeat, counting from bar 0 (`claimBar: 4` = frame 4 x bar); throws if it cannot. A longer last ask is really longer, never slowed |
-| `score` (required) or `audio` | the score composed for this product (the `Material` function compose.md writes, or a `Piece`), as a bed; `null` for silence; or your own finished mix (not checked) |
+| `score` (required) or `audio` | the score composed for this product (the `Material` function compose.md writes, or a `Piece`), as a bed; `null` for silence; or your own finished mix (not checked; it replaces the cues too) |
+| `shape`, `preset`, `sfx`, `motif`, `captions` | the frame (16x9 default); the look (drawn, clean); sound cues (default on); the relay into the end card (default on); `"sidecar"` (default) or `"burn"` |
The template refuses a feature list (more than 3 asks) and an end card too short to read.
@@ -94,17 +146,38 @@ The template refuses a feature list (more than 3 asks) and an end card too short
**`kinetic.ts`**: lettering that is written, never set.
- `writeOn(ctx, env, text, x, y, size, p, style, opts)`: a line written stroke by stroke by a
visible tool, in `ink`, `crayon`, `thread`, `chalk`, `brick` or `marker`. `measure` sizes it.
+- `setType(ctx, env, text, x, y, size, p, opts)`: a line SET in a heavy sans, each word rising
+ into place behind its baseline: the clean look's type. `setWidth` measures it.
- `sentence` (one medium per word, one word per beat), `caption` (a small callout with an
underline or arrow), `logo`/`logoCentred` and `logoBug` (anidoodle's own wordmark and corner
mark; for your product, write your name with `writeOn` as the template does).
+**`launchLayout.ts`**: `launchLayout(shape, content)` gives a shape's whole composition (the
+chat geometry, the thread, the camera's rests, the word pages, the split columns, the end card,
+the caption band) and the size of every text role, checked against the phone-safe minimums
+(`MIN_PX`). `drawChatFrame`, `caretAt`, `inkDrop` and `inkCard` take its `chat` geometry;
+`chatGeom(rect, k, px, promptPx, lines)` is the same chat component at any size.
+
+**`productUI.ts`**: `drawProductUI(ctx, rect, ui, { f, t0 }, theme, { minPx })` draws a
+product's interface from data in its before state and springs every item to its after state
+from `t0`; the window fits its content. `uiSettles` gives each item's landing frame and
+`springLand(t0, omega, zeta)` the frame any spring first reaches its target (where its sound goes).
+
+**`motif.ts`**: `relay(keys)` is one object's continuous path across a seam (cut frames),
+`seamGap` and `checkRelay` measure it on both sides of a match cut and throw past 2 px.
+
+**`launchSound.ts`**: `mixLaunch`/`launchAudio` place cues from the sfx kit (`music/sfx`),
+pan each by its screen x (`panOf`), duck the score, raise a buried cue until it is heard, and
+hold the mix under -1 dBTP.
+
**`launchCut.ts`**: the cut as data.
- `pic(from, to, len)` plays a span of your content timeline over `len` frames; `type(lines,
len, before, after)` is a word page. `makeCut(segs)` gives `N`, `at(F)`, `contentOf`, `cutOf`
(map content-frame sound events onto the cut).
- `beatGrid(bpm, fps)`: `beat`, `bar`, `frameOf(bar, beat)`, and `solve(bar, fixed)`, the frames
left for one flexible segment so the claim lands on a bar (launch3 lands on bar 26).
-- `bloomFrame` (a page inside an ink bloom; `close: false` keeps it open for an end card),
+- `bloomFrame` (a page inside an ink bloom; `close: false` keeps it open for an end card;
+ `center` opens it from a point, the motif; `shape: "circle"` is the clean look's iris),
`typeFrame` (one to three lines written on it; `lead`, `stagger`), `bloomRadius` (for holds).
**`launchGallery.ts`**: `drawWall` and `wallCam`, a rolling wall of style cards where the
diff --git a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video.md b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video.md
index 42bb1e1..5345d05 100644
--- a/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video.md
+++ b/plugins/anidoodle/skills/anidoodle/references/workflows/launch-video.md
@@ -51,8 +51,11 @@ pieces are examples of the craft, never material for someone else's film.
## Type
- **Words NEVER sit over the art or the UI.** A word gets its own full frame: an ink bloom
- opens, a brush writes the word, the bloom closes on the next scene (`typeFrame`). Corner marks
- step aside when the camera brings UI under them.
+ opens, a brush writes the word, the bloom closes on the next scene (`typeFrame`). Or, for a
+ feature beat, its own COLUMN: words on the left, the live UI on the right (words above, UI
+ below on a phone), each in its own area of the layout (`split`), faster than a full word page.
+ Corner marks step aside when the camera brings UI under them, and sit in their own strip on a
+ phone frame.
- **3-7 words a frame, few frames.** Collapse word cards into one claim then proof ("JUST CODE."
then "31 STYLES"); fewer cards leave more time for the proof.
- **Hold each settled word 0.5 s or more**, longer for the claim.
@@ -70,9 +73,29 @@ pieces are examples of the craft, never material for someone else's film.
thread scrolls, a follow-up animates in the existing card instead of popping a new one.
- **Web**: show the whole site first, then zoom to each click; the site's copy describes what
the viewer is seeing.
+- **A product that is not a chat shows its own UI**, drawn from its real data in two states: the
+ before (the problem), one press of its action, every item springing to the after. Never a
+ screenshot slideshow (`productUI.ts`, a `kind: "ui"` ask).
+
+## The motif
+
+**Pick ONE object the story already owns and carry it across the seams**: anidoodle's template
+carries the ink drop that every press of Generate sends into the thread; at the end it lifts off
+Generate one last time and lands as the dot of the end card's mark ("NAME."), and the end card
+blooms open FROM it. The rule for any seam you design as a match cut: on the last frame of the
+outgoing shot and the first of the incoming one the object has the same screen position and size
+(within 2 px), and the incoming scene opens from it. `motif.ts` (`relay`, `checkRelay`) checks it;
+a seam that jumps throws. Use it for the seams that matter (the reveal), never on every cut.
- Banned defaults: a centred title on a gradient, everything fading in, bouncy easing, particle
bursts, glow on UI chrome, dead time, text scaled into blur.
+## Two registers
+
+The **drawn** register (default): ink blooms, hand-lettered words, a warm paper palette, the
+product drawn in the chosen style. The **clean** register (`preset: "clean"`) for a UI-first
+product: a quiet canvas, ONE accent colour, type as the design (set, not written; each word rises
+into place), round iris seams, the product's own UI. Pick one per film; never mix them.
+
## Brand and the end card
- **The logo recurs**: a small corner mark on every frame (`logoBug`), not once at the start.
@@ -91,8 +114,12 @@ pieces are examples of the craft, never material for someone else's film.
- **Balance by stem RMS, not only LUFS**: an integrated -14 LUFS hid a sub 7-10 dB too hot.
- **Cut on downbeats, not every beat.** Land the claim on a chord (launch3's lands on bar 26,
the home chord); `beatGrid().solve()` fits a flexible segment so it does.
-- **Sound effects only on real direction changes**: one riser into the big reveal, one impact,
- never a whoosh on every cut (`references/music/sound-design.md`).
+- **Sound effects come from the picture's own math**, never laid on by hand: a key per typed
+ character, the press on the frame the button goes down, the drop and its bloom, a card landing
+ on its spring's first arrival, each panned to where it happens on screen (`launchSound.ts`).
+ Every cue must be heard over the score (the template raises a buried one, then checks).
+- **Transition sounds only on real direction changes**: one riser into the big reveal, one
+ impact on it, never a whoosh on every cut, nothing on a word page (`references/music/sound-design.md`).
- **Master to -14 LUFS integrated, true peak -1 dBTP or lower**, then listen on a phone speaker.
## Delivery
@@ -101,7 +128,17 @@ pieces are examples of the craft, never material for someone else's film.
a platform version rather than pushing one master everywhere. Cut whole beats; never speed
the whole film up (it breaks the beat grid and reads rushed).
- **Shapes**: `16x9` for YouTube and the site, `1x1` or `4x5` for feeds, `9x16` for Reels and
- Shorts. Reframe per shape from one timeline; never crop a wide render.
+ Shorts. Re-compose per shape from one timeline; never crop a wide render. The template does it
+ through `launchLayout.ts` (`launch.mjs ship <film> --shapes 16x9,1x1,9x16`), with phone-safe type:
+ every line a viewer reads at least 32 px at 1080 across on the phone shapes.
+- **Captions**: feeds autoplay muted. Ship `.srt`/`.vtt` for players that take a sidecar (YouTube,
+ LinkedIn, the site); burn them into their OWN band under the picture for feeds that do not
+ (`captions: "burn"`), never over the art.
+- **Sync and peak are checked on the file you ship**, not the master: the sound at every sync
+ marker within 1 ms of the mix, the true peak at or under -1 dBTP after the AAC encode
+ (`verify-export --delivery`).
+- **A UI-heavy film may run at 60 fps** (`fps: 60`); render with `--blur auto` so fast moves blur
+ by their real speed and still frames stay sharp.
- **The first frame is the thumbnail.** Platforms and players show frame 1 before play. Make
it legible and on brand (anidoodle's is the wall of styles; the template's is the prompt, big,
mid-sentence); never a blank, a fade from black, or a whole chat window too small to read.
@@ -124,7 +161,9 @@ pieces are examples of the craft, never material for someone else's film.
first (type over art, spacing, hierarchy), then timing. Render only the changed range
(`render.mjs --from F --to T` writes `out/<film>.<F>-<T>.mp4`, silent). Give notes in camera words ("slow this zoom to 0.7x",
"hold the word 10 frames longer"), never "make it better".
-8. **QA**: `gate.mjs <film>` (determinism, contract, dead air; declare real holds in
- `meta.holds`, each with its reason) and `verify-export.mjs <film> --file <mp4> --delivery
- --first-frame #rrggbb` for EVERY shape shipped; meter the mix. Keep the review page updated as work lands.
+8. **QA**: `launch.mjs ship <film> --shapes ... --gate` runs, for EVERY shape shipped, the gate
+ (determinism, contract, dead air; declare real holds in `meta.holds`, each with its reason)
+ and `verify-export --delivery` (size, frames, score, sync, true peak, a legible frame 0), and
+ writes the poster and captions; add `verify-export <film>-<shape> --first-frame #rrggbb` for a
+ brand colour. Meter the mix. Keep the review page updated as work lands.
9. ✋ **Final approval** on the finished file.