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 parts: productUI (a product's interface from data, before/after states, items spring between them by id; springLand = the frame a spring first arrives), motif.ts (relay/seamGap/checkRelay: one object carried across a match cut, checked to 2 px), setType (the clean register's set type), bloomFrame center/shape/rim, inkCard spring grow + iris, drop colour

Alex Greenshpun8169a1c0e67c
diff --git a/skills/anidoodle/engine/src/canvas-core/kinetic.ts b/skills/anidoodle/engine/src/canvas-core/kinetic.ts
index 0275fec..3343bdf 100644
--- a/skills/anidoodle/engine/src/canvas-core/kinetic.ts
+++ b/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/skills/anidoodle/engine/src/canvas-core/launchCut.ts b/skills/anidoodle/engine/src/canvas-core/launchCut.ts
index ad01e07..57b17bf 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchCut.ts
+++ b/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/skills/anidoodle/engine/src/canvas-core/launchKit.ts b/skills/anidoodle/engine/src/canvas-core/launchKit.ts
index 89c09c6..17de213 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchKit.ts
+++ b/skills/anidoodle/engine/src/canvas-core/launchKit.ts
@@ -137,6 +137,8 @@ export type ChatGeom = {
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
@@ -230,7 +232,7 @@ export const typedAt = (text: string, f: number, times: number[]) => text.slice(
// 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, 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];
+ 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 = 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]; };
@@ -247,14 +249,17 @@ export const inkDropAt = (f: number, d: { t0: number; land: number }, to: P, g:
};
// 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], g: ChatGeom = CHAT_GEOM) => {
+// `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 = out3(ramp(f, d.land, d.full)), c: P = [x + s / 2, y + s / 2];
- softShadow(ctx, x, y, s, s, 20 * k, grow * 1.3);
+ 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) { 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(); }
+ 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/skills/anidoodle/engine/src/canvas-core/motif.ts b/skills/anidoodle/engine/src/canvas-core/motif.ts
new file mode 100644
index 0000000..ae4514d
--- /dev/null
+++ b/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/skills/anidoodle/engine/src/canvas-core/productUI.ts b/skills/anidoodle/engine/src/canvas-core/productUI.ts
new file mode 100644
index 0000000..a5a7bb6
--- /dev/null
+++ b/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(",")})`; };