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.

launch kit: one timeline, four shapes. launchLayout re-composes the chat, cards, word pages, split beat and end card for 16x9, 1x1, 4x5 and 9x16 with phone-safe type minimums (checked, throws with the fix); drawChatFrame/caretAt/inkDrop/inkCard take the chat geometry (16x9 byte-identical); film.reshape + <film>-<shape> names in every tool; render --shapes

Alex Greenshpun6b67afd5dec8
diff --git a/skills/anidoodle/engine/src/canvas-core/film.ts b/skills/anidoodle/engine/src/canvas-core/film.ts
index 493f93b..152f23c 100644
--- a/skills/anidoodle/engine/src/canvas-core/film.ts
+++ b/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/skills/anidoodle/engine/src/canvas-core/launchKit.ts b/skills/anidoodle/engine/src/canvas-core/launchKit.ts
index d9c2a4b..89c09c6 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchKit.ts
+++ b/skills/anidoodle/engine/src/canvas-core/launchKit.ts
@@ -126,41 +126,89 @@ 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>;
+};
+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 +229,33 @@ 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 = 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;
+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) => {
+ 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 = 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);
+ softShadow(ctx, x, y, s, s, 20 * k, grow * 1.3);
+ ctx.save(); rr(ctx, x, y, s, s, 20 * k); ctx.clip();
+ if (grow < 1) { pathOf(ctx, blot(c, lerp(16 * k, s * 0.8, grow) + 28 * k * (1 - grow), 77)); ctx.fillStyle = 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/skills/anidoodle/engine/src/canvas-core/launchLayout.ts b/skills/anidoodle/engine/src/canvas-core/launchLayout.ts
new file mode 100644
index 0000000..1fddcd3
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/launchLayout.ts
@@ -0,0 +1,144 @@
+// 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, 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;
+};
+
+export { CHAT };
diff --git a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
index 4b8a77b..351f4d6 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
+++ b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts
@@ -19,9 +19,10 @@
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,
+ C, SANS, MONO, camLerp, caretAt, charTimes, clamp, drawChatFrame, expo, inOut, inkCard, inkDrop,
lerp, lerpP, out3, plateLayer, pointer, press, ramp, rr, typedAt, useCam, type Cam, type Drop,
} from "./launchKit";
+import { launchLayout, 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 { fitScore, limiter, renderPiece } from "./music/render";
@@ -64,9 +65,9 @@ export type LaunchSpec = {
score: (() => Piece | Material) | null;
audio?: Film["audio"]; // or your own finished mix; wins over score
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
};
-const W = 1920, H = 1080;
// 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,8 +83,6 @@ 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];
// the timing inside one ask beat, from its prompt and its length
const askTiming = (prompt: string, i: number, ASK: number) => {
@@ -94,8 +93,13 @@ const askTiming = (prompt: string, i: number, ASK: number) => {
return { times, b, down, up, 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 };
+export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {
+ const fps = spec.fps ?? 30, n = spec.asks.length, shape = spec.shape ?? "16x9";
+ if (!(shape in SHAPES)) throw new Error(`launchTemplate: shape '${shape}' is not one of ${Object.keys(SHAPES).join(", ")}`);
+ const L = launchLayout(shape, { prompts: spec.asks.map((a) => a.prompt), install: spec.install, tagline: spec.tagline, title: spec.title });
+ const W = L.W, H = L.stage.h, G = L.chat, TH = L.thread, CAM = L.cam, CARD = TH.card, VIEW_BOTTOM = TH.viewBottom;
+ const GEN_C: P = [G.GEN.x + G.GEN.w / 2, G.GEN.y + G.GEN.h / 2];
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 (spec.score) refuseOurs(spec.score);
@@ -115,43 +119,54 @@ export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeo
const END0 = BASE[n - 1] + LEN[n - 1]; // content frame where the end card starts
// ---------------------------------------------------------------- the thread
- type Item = { at: number; h: number; user?: string; card?: number };
+ 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; }); })();
+ T.forEach((t, i) => { items.push({ at: t.base + t.up, h: TH.bubbleH + (TH.bubbles[i].length - 1) * TH.bubbleLineH, user: spec.asks[i].prompt, lines: TH.bubbles[i] }); 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 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], 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 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) => 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: spec.accent }, 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 = C.chip; rr(ctx, TH.bubbleR - bw, y, bw, it.h - 2, TH.bubbleRad); ctx.fill();
+ ctx.fillStyle = C.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 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);
}
});
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]));
+ T.forEach((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 });
// `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
+ // 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 = (ctx: Ctx, i: number, l: number, z: number): P => {
+ const half = W / 2 / z, lo = G.INPUT.x - 24 * G.k + half, hi = Math.max(lo, G.GEN.x + G.GEN.w + 30 * G.k - half);
+ let x = 0, y = 0; for (let j = 0; j < 10; j++) { const [cx, cy] = caretAt(ctx, typedAt(spec.asks[i].prompt, l - j, T[i].times), G); x += clamp(cx - 110 * G.k, lo, hi); y += cy; }
+ const yLo = G.INPUT.y + (H / 2) / z - 90 * G.k, yHi = G.INPUT.y + G.INPUT.h + 40 * G.k - (H / 2) / z;
+ return [x / 10, clamp(y / 10, Math.min(yLo, yHi), Math.max(yLo, yHi))];
+ };
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);
- // 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)) };
+ const t = T[i], l = f - t.base, typed = typedAt(spec.asks[i].prompt, l, t.times), [cx] = caretAt(ctx, typed, G);
+ // the macro creeps in while the words arrive: the frame is never a still. On a phone frame the
+ // whole composer is in view (the words wrap), so it holds on the composer instead of the caret
+ 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(ctx, i, l, mz), z: mz };
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 }; }
return { cam: l < t.b - 4 ? macro : camLerp(macro, HOME, expo(ramp(l, t.b - 4, t.down))), lean: 0 };
@@ -163,43 +178,44 @@ export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeo
const typed = typedAt(spec.asks[i].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);
+ const off: P = CAM.pointerOff, on: P = CAM.pointerOn;
+ 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);
// 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;
if (show > 0) { ctx.globalAlpha = show; bug(ctx, env); ctx.globalAlpha = 1; }
};
// ---------------------------------------------------------------- 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 = Math.min(E.titleMax, (E.titleW / measure(spec.title, 100)) * 100);
+ 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));
+ c.globalAlpha = ramp(e, 34, 46); c.fillStyle = C.soft; c.font = SANS(500, E.taglinePx); E.tagline.forEach((t, j) => c.fillText(t, cx, E.taglineY + j * E.taglineLH));
+ c.globalAlpha = ramp(e, 40, 52); 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 = "#1f1c18"; rr(c, cx - pw / 2, py, pw, ph, 22 * L.k); c.fill();
+ c.fillStyle = "#ece4d6"; spec.install.forEach((s, k) => c.fillText(s, cx, E.lineY0 + k * 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); }
+ const lastW = c.measureText(spec.install[nI - 1]).width;
+ if (Math.floor((e - 40) / 15) % 2 === 0) 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 = C.soft; c.font = SANS(500, E.footerPx); c.fillText(spec.footer, cx, E.footerY); }
c.globalAlpha = 1; c.textAlign = "left";
};
const content = (ctx: Ctx, env: Env, f: number) => {
const g = clamp(Math.round(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), (c) => endPage(c, env, e), { close: false, inF: 16, W, H });
};
// ---------------------------------------------------------------- the cut, as data
const words = spec.words ?? [];
+ const TYPE_OPTS = L.shape === "16x9" ? TYPE_O : { ...TYPE_O, W, H, maxW: L.type.maxW };
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.
@@ -211,26 +227,45 @@ export const makeLaunchFilm = (spec: LaunchSpec): Film & { cut: ReturnType<typeo
const { s, local } = cut.at(F);
if (s.kind === "pic") content(ctx, env, cut.contentOf(s, local));
// 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 typeFrame(ctx, env, s.lines, local + 2, s.len + 4, (first) => content(ctx, env, first ? s.before : s.after), (c) => bug(c, env), TYPE_OPTS);
};
// 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
+ let open = s.len - 1; while (open > written && bloomRadius(open + 2, s.len + 4) < L.type.cover) open--; // last fully covered frame
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 } } : {}) },
+ 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, raster: "cpu", kind: "launch", holds, ...(bed ? { score: { tempo: spec.bpm, form: bed.form, grid: true } } : {}) },
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,
+ cut, layout: L,
+ // 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/skills/anidoodle/engine/src/hosts/page.ts b/skills/anidoodle/engine/src/hosts/page.ts
index 628409e..2395042 100644
--- a/skills/anidoodle/engine/src/hosts/page.ts
+++ b/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.
diff --git a/skills/anidoodle/engine/test/launchLayout.test.ts b/skills/anidoodle/engine/test/launchLayout.test.ts
new file mode 100644
index 0000000..e188be6
--- /dev/null
+++ b/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/skills/anidoodle/engine/tools/build-page.mjs b/skills/anidoodle/engine/tools/build-page.mjs
index 8c5189f..106c404 100644
--- a/skills/anidoodle/engine/tools/build-page.mjs
+++ b/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/skills/anidoodle/engine/tools/names.mjs b/skills/anidoodle/engine/tools/names.mjs
index 2d3a5c7..375402b 100644
--- a/skills/anidoodle/engine/tools/names.mjs
+++ b/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/skills/anidoodle/engine/tools/render.mjs b/skills/anidoodle/engine/tools/render.mjs
index 3b2448a..3811909 100644
--- a/skills/anidoodle/engine/tools/render.mjs
+++ b/skills/anidoodle/engine/tools/render.mjs
@@ -22,7 +22,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,6 +38,15 @@ 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); }