commit 4d487c23aaf87d5d32eb66489293715533454ee9
parent 5ee40d9cc480f77341170b442e3c14fdcea262f4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 28 Oct 2026 23:26:52 -0400
umtool: per-module cache rules on the one reuseFrames path -- items, assets by content, rail pitch
- Every module with a cue-interpreting page declares its frame-key model
(`frameKeys`): threads, flips, stats, fx and the teaser join the deck,
the stamps, the feed and the finale. compose-chrome keys a segment's
page too.
- Assets by content: a page's `assets/<name>` reads as its bytes' hash in
the key, so a post or clip inserted early (which renumbers every qrNN /
shotNN after it) no longer invalidates the frames that show the same
pictures.
- Items: a page hands over the markup a frame draws only while its gate is
visible -- the deck's segment texts (autoAlpha) and pips (opacity), the
feed's cards (from their post's event on). An item's markup, assets and
slots are in the keys of the frames that show it and no others: a
changed subtitle recaptures the frames its clip is on screen, a post
changed or added recaptures from its event on.
- The rail's `pip.spacing: "pitch"`: pips at a fixed pitch from the left,
the fuse measured against the whole track, a pip drawn once the fuse
sets off toward it; the finale's large rail lays them evenly. A clip
appended keeps every frame before the marker reaches the clip before it.
- FRAME_KEY_VERSION 2: a render keyed by version 1 is captured once more.
The pages themselves are unchanged (the Huck pages compare byte-identical).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
13 files changed, 329 insertions(+), 48 deletions(-)
diff --git a/umtool/report-to-video/chrome-deck.mjs b/umtool/report-to-video/chrome-deck.mjs
@@ -38,7 +38,7 @@
import { fileURLToPath } from "node:url";
import {
- claimsLayout, cueTime, cueTimeAfter, stampsOnFrames, deckChoreography, deckLayout, deckMarkers, MARKER_LABEL_SIZE, MARKER_ROW, pageDuration, pipSegments, pipXs, resolveDeck,
+ claimsLayout, cueTime, cueTimeAfter, PIP_PITCH_DEFAULT, stampsOnFrames, deckChoreography, deckLayout, deckMarkers, MARKER_LABEL_SIZE, MARKER_ROW, pageDuration, pipSegments, pipXs, resolveDeck,
} from "./deck.mjs";
import { claimsCues, claimsMarkup } from "./chrome-claims.mjs";
import { resolveFactcheck, tallyCues, tallyFinals, tallyKey, tallyLabelOf, tallyOf, tallyPopIns } from "./factcheck.mjs";
@@ -154,9 +154,10 @@ export function deckCues(schedule, render) {
const segs = schedule.segments;
const ch = deckChoreography(schedule, render);
const pipped = pipSegments(schedule);
+ const pitched = deck.pip.spacing === "pitch";
const xs = pipXs(
pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, deck.pip.spacing,
- deck.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null,
+ deck.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null, deck.pip.pitch ?? PIP_PITCH_DEFAULT,
);
// `pip.color: "verdict"`: a claimed clip's pip carries its verdict (drawn
// in its colour and shape once lit). Only then, so the pips are as they
@@ -165,7 +166,9 @@ export function deckCues(schedule, render) {
const pips = pipped.map((s, k) => ({ id: s.id, x: r4(xs[k]), ...(byVerdict && s.claim?.verdict ? { verdict: s.claim.verdict } : {}) }));
const pipOf = new Map(pipped.map((s, k) => [s.id, k]));
const fuseX0 = xs[0] ?? 0;
- const fuseW = xs.length > 1 ? xs[xs.length - 1] - xs[0] : 0;
+ // At a fixed pitch the fuse is measured against the whole track, so its
+ // progress to a pip does not depend on how many come after it.
+ const fuseW = xs.length > 1 ? (pitched ? lay.pipTrack.x1 - xs[0] : xs[xs.length - 1] - xs[0]) : 0;
const frac = (k) => (fuseW > 0 ? r4((xs[k] - fuseX0) / fuseW) : 0);
const lift = Math.round(lay.text.titleSize * 0.16);
const slideY = lay.height + 12;
@@ -178,6 +181,10 @@ export function deckCues(schedule, render) {
put("marker", { x: r4(xs[0] ?? lay.pipTrack.x0) });
if (fuseW > 0) put("fuse", { scaleX: 0, transformOrigin: "0% 50%" });
pips.forEach((_, k) => put(`pip${k}`, { opacity: 0 }));
+ // At a fixed pitch a pip is not drawn until the fuse sets off toward it
+ // (the marker reaches the pip before): the rail is the record so far, so a
+ // clip inserted later changes nothing drawn before it.
+ if (pitched) pips.forEach((_, k) => { if (k > 0) put(`pb${k}`, { opacity: 0 }); });
segs.forEach((s, i) => {
const st = i === 0 && !s.hideDeck ? SEG_STATE.shown() : SEG_STATE.before(lift);
put(keyOf(i, "seg"), st.seg);
@@ -280,6 +287,14 @@ export function deckCues(schedule, render) {
for (const e of t.events) add(e.k, e.at, e.dur, e.to, e.ease, e.why);
}
+ // At a fixed pitch, each pip after the first comes in as the marker reaches the one before it.
+ if (pitched) {
+ for (let k = 1; k < pips.length; k += 1) {
+ const a = arrive.get(k - 1);
+ if (a !== undefined) add(`pb${k}`, a, INSTANT, { opacity: 1 }, "none", `pip ${pips[k].id} ahead`);
+ }
+ }
+
// The fuse: from pip k to pip k+1 over the time the marker rests on k.
if (fuseW > 0) {
for (let k = 0; k < pips.length - 1; k += 1) {
@@ -385,6 +400,7 @@ export function subtitleMarkup(text) {
*/
export function deckHtml(schedule, render, opts = {}) {
const deck = resolveDeck(render);
+ const pitched = deck.pip.spacing === "pitch";
const tally = tallyOf(schedule, render);
const lay = deckLayout(render, { tally, schedule });
const pal = render.palette;
@@ -424,10 +440,15 @@ export function deckHtml(schedule, render, opts = {}) {
const plateX = qr ? qr.x - 46 : W;
const ink = panel ? mix(pal.bg, pal.fg, 0.085) : pal.bg; // what the marker's ring cuts back to
+ // The page's ITEMS (frame-keys.mjs): each segment's text, each pip -- the
+ // markup a frame draws only while its gate is visible, collected when the
+ // caller asks (`opts.items`, an array) so a frame's key holds the items it
+ // shows and not every other's. The page is the same either way.
+ const items = Array.isArray(opts.items) ? opts.items : null;
const segHtml = schedule.segments
.map((s, i) => {
const src = qrSrcs[s.id];
- return (
+ const html = (
`<div class="seg${s.title ? "" : " untitled"}" data-seg="${esc(s.id)}" data-k="s${i}">` +
`<div class="tc" data-k="s${i}.tc"><div class="ti" data-k="s${i}.ti">` +
`<div class="deck-title">${esc(s.title)}</div></div>` +
@@ -443,6 +464,8 @@ export function deckHtml(schedule, render, opts = {}) {
: `<div class="deck-qr empty" data-k="s${i}.qr"></div>`) +
`</div>`
);
+ if (items) items.push({ key: `s${i}`, gate: [`s${i}`, "autoAlpha"], html });
+ return html;
})
.join("\n ");
@@ -451,15 +474,19 @@ export function deckHtml(schedule, render, opts = {}) {
const vSize = Math.max(pip.size, Math.round((pip.size * 5) / 3));
const pipHtml = pips
.map((p, k) => {
- const base = `<div class="pip" style="left:${r4(p.x - pip.size / 2)}px"></div>`;
- if (!p.verdict) return base + `<div class="pip lit" data-k="pip${k}" style="left:${r4(p.x - pip.size / 2)}px"></div>`;
- const color = verdictColors[p.verdict]?.color ?? pal.accent;
- return (
- base +
- `<div class="pip lit vpip" data-k="pip${k}" data-verdict="${esc(p.verdict)}" data-shape="${shapes[p.verdict]}" ` +
- `style="left:${r4(p.x - vSize / 2)}px; top:${r4(-vSize / 2)}px; width:${vSize}px; height:${vSize}px; ` +
- `${shapeCss(shapes[p.verdict], vSize, esc(color))}"></div>`
- );
+ const base = `<div class="pip"${pitched && k > 0 ? ` data-k="pb${k}"` : ""} style="left:${r4(p.x - pip.size / 2)}px"></div>`;
+ const color = p.verdict ? verdictColors[p.verdict]?.color ?? pal.accent : null;
+ const lit = !p.verdict
+ ? `<div class="pip lit" data-k="pip${k}" style="left:${r4(p.x - pip.size / 2)}px"></div>`
+ : `<div class="pip lit vpip" data-k="pip${k}" data-verdict="${esc(p.verdict)}" data-shape="${shapes[p.verdict]}" ` +
+ `style="left:${r4(p.x - vSize / 2)}px; top:${r4(-vSize / 2)}px; width:${vSize}px; height:${vSize}px; ` +
+ `${shapeCss(shapes[p.verdict], vSize, esc(color))}"></div>`;
+ if (items) {
+ // A pip at a fixed pitch is drawn only once the fuse sets off for it.
+ if (pitched && k > 0) items.push({ key: `pb${k}`, gate: [`pb${k}`, "opacity"], html: base });
+ items.push({ key: `pip${k}`, gate: [`pip${k}`, "opacity"], html: lit });
+ }
+ return base + lit;
})
.join("");
// The markers: a flag on the track and its label in the band above it.
@@ -527,7 +554,7 @@ export function deckHtml(schedule, render, opts = {}) {
: null;
const fuseLeft = pips[0]?.x ?? tr.x0;
- const fuseWidth = pips.length > 1 ? pips[pips.length - 1].x - fuseLeft : 0;
+ const fuseWidth = pips.length > 1 ? (pitched ? tr.x1 - fuseLeft : pips[pips.length - 1].x - fuseLeft) : 0;
const data = {
total,
diff --git a/umtool/report-to-video/chrome-feed.mjs b/umtool/report-to-video/chrome-feed.mjs
@@ -320,12 +320,15 @@ export function feedHtml(schedule, render, opts = {}) {
const cardTop = mix(mix(pal.bg, pal.fg, 0.14), pal.accent, 0.06);
const cardBottom = mix(mix(pal.bg, pal.fg, 0.11), pal.accent, 0.03);
+ // The page's ITEMS (frame-keys.mjs): each card, drawn only from its post's
+ // event on -- collected when the caller asks (`opts.items`).
+ const items = Array.isArray(opts.items) ? opts.items : null;
const cardHtml = posts
.map((p, j) => {
const { name, platform } = postWho(p);
const src = qrSrcs[p.id];
const shot = shotSrcs[p.id];
- return (
+ const html = (
`<article class="post${shot ? " has-shot" : ""}" data-post="${esc(p.id)}" data-k="c${j}">` +
(shot
? `<div class="body shot-body"><img class="shot" src="${esc(shot)}" alt=""></div>`
@@ -345,6 +348,8 @@ export function feedHtml(schedule, render, opts = {}) {
`<div class="hl" data-k="h${j}"></div>` +
`</article>`
);
+ if (items) items.push({ key: `c${j}`, event: j, html });
+ return html;
})
.join("\n ");
diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs
@@ -903,10 +903,14 @@ export async function composeChrome({
await mkdir(assetsDir, { recursive: true });
await copyFile(GSAP_FILE, path.join(assetsDir, "gsap.min.js"));
- const html = await regionHtml(region, {
+ // A module's page is its HTML, or `{ html, items }`: the markup the frame
+ // keys hold only while it is shown (frame-keys.mjs).
+ const drawn = await regionHtml(region, {
manifest, manifestDir: path.dirname(path.resolve(manifestPath)), base, projDir, assetsDir, schedule: sched,
duration: duration != null ? Number(duration) : null, from, window: win, teaser, transition: D,
});
+ const html = typeof drawn === "string" ? drawn : drawn.html;
+ const pageItems = typeof drawn === "string" ? null : drawn.items ?? null;
await writeFile(path.join(projDir, "index.html"), html, "utf8");
await writeFile(path.join(projDir, "hyperframes.json"), HF_JSON + "\n", "utf8");
@@ -955,8 +959,10 @@ export async function composeChrome({
// Each frame's key (frame-keys.mjs), for a whole-cut page it models: a
// render that is not cached whole captures only the frames no render on
// disk has drawn.
- const fk = keyed && sequence && ((wholeCut && !windowed) || mod.kind === "overlay-window") && !preview && mod.frameKeys
- ? frameKeys({ html, region, assets, fps: rate, frames, version: hf.version })
+ // Frame keys, for a page its module models (`frameKeys`): a whole-cut page
+ // over the whole cut, a window's, a segment's.
+ const fk = keyed && sequence && ((wholeCut && !windowed) || mod.kind === "overlay-window" || mod.kind === "segment") && !preview && mod.frameKeys
+ ? frameKeys({ html, region, assets, fps: rate, frames, version: hf.version, items: pageItems })
: null;
if (keyed && sequence) {
const onDisk = await readFile(keyFile, "utf8").then((s) => s.trim(), () => null);
diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs
@@ -26,15 +26,15 @@ import { resolveCounter } from "./counter.mjs";
import { DECK_PAD_X, COUNTER_CELL } from "./modules/design.mjs";
import {
DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, markerShapeErrors,
- PIP_COLORS, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SETTINGS, settingValue, SUBTITLE_TOKENS,
+ PIP_COLORS, PIP_PITCH_DEFAULT, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SETTINGS, settingValue, SUBTITLE_TOKENS,
} from "./modules/settings.mjs";
// The deck's settings and their limits live with the modules' validators
// (modules/settings.mjs, a leaf: this file imports it); here under the names
// they always had.
export {
- DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, PIP_COLORS, PIP_SPACINGS,
- POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SUBTITLE_TOKENS,
+ DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, PIP_COLORS, PIP_PITCH_DEFAULT,
+ PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SUBTITLE_TOKENS,
};
import { threadOf, threadSchedule, threadsOn, validateThreads } from "./threads.mjs";
import { flipSchedule, flipsOn, validateFlips } from "./flips.mjs";
@@ -589,7 +589,7 @@ export function markerRowsOf(schedule, render) {
const pipped = pipSegments(schedule);
const xs = pipXs(
pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, d.pip.spacing,
- d.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null,
+ d.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null, d.pip.pitch ?? PIP_PITCH_DEFAULT,
);
return deckMarkers(schedule, render, xs, pipped, lay).some((m) => m.row === 1) ? 2 : 1;
}
@@ -701,8 +701,16 @@ export function deckMarkers(schedule, render, xs, pipped, lay = deckLayout(rende
* -- needs `schedule` (`{ total, segments: [{start, duration}] }`, the pipped
* segments only, in order).
*/
-export function pipXs(n, x0, x1, spacing = "even", schedule = null) {
+export function pipXs(n, x0, x1, spacing = "even", schedule = null, pitch = PIP_PITCH_DEFAULT) {
if (n <= 0) return [];
+ // "pitch" (rail.mjs): each pip `pitch` px after the one before, from the
+ // left end -- a pip's place depends on the pips before it alone -- unless
+ // the track cannot hold them all at it, when they are laid at the pitch
+ // that fits.
+ if (spacing === "pitch") {
+ const step = n > 1 ? Math.min(pitch, (x1 - x0) / (n - 1)) : pitch;
+ return Array.from({ length: n }, (_, i) => x0 + i * step);
+ }
if (spacing === "time") {
if (!schedule?.segments || schedule.segments.length !== n || !(schedule.total > 0)) {
throw new Error("pipXs: spacing \"time\" needs a schedule with one segment per pip");
@@ -1401,7 +1409,9 @@ function finaleRailAt(schedule, render, railBottom, textScale) {
const lay = deckLayout(render, { tally, schedule });
const pipped = pipSegments(schedule);
const time = deck.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null;
- const fxs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, deck.pip.spacing, time);
+ const fxs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, deck.pip.spacing, time, deck.pip.pitch ?? PIP_PITCH_DEFAULT);
+ // The large rail is the whole record at once: a footer at a fixed pitch is laid evenly across it.
+ const bigSpacing = deck.pip.spacing === "pitch" ? "even" : deck.pip.spacing;
const footSize = deck.pip.size;
const bigSize = Math.max(14, Math.round(footSize * 2.5));
const bigV = Math.round((bigSize * 5) / 3);
@@ -1412,7 +1422,7 @@ function finaleRailAt(schedule, render, railBottom, textScale) {
const dates = f.railLabels === "all";
const labelsAt = (xs, geo) => railLabelLayout(xs.map((x, k) => ({ x, ...info[k] })), geo, { dates });
let x0 = rail.x0;
- let xs = pipXs(pipped.length, x0, rail.x1, deck.pip.spacing, time);
+ let xs = pipXs(pipped.length, x0, rail.x1, bigSpacing, time);
let labels = labelsAt(xs, base);
if (labels.mode === "turned" && labels.groups.length) {
const g0 = labels.groups[0];
@@ -1420,7 +1430,7 @@ function finaleRailAt(schedule, render, railBottom, textScale) {
const need = Math.round(base.margin / 2 + w0 * Math.cos((labels.angle * Math.PI) / 180));
if (need > x0) {
x0 = Math.min(need, Math.round(base.W * 0.2));
- xs = pipXs(pipped.length, x0, rail.x1, deck.pip.spacing, time);
+ xs = pipXs(pipped.length, x0, rail.x1, bigSpacing, time);
labels = labelsAt(xs, base);
}
}
diff --git a/umtool/report-to-video/frame-keys.mjs b/umtool/report-to-video/frame-keys.mjs
@@ -27,6 +27,27 @@
// the ids list (preview messages), and every `data-duration` (each the whole
// page's; checked). Anything else in the page's data stays in.
//
+// PER-MODULE CACHE RULES (release 39, the video modules). Each module's
+// `frameKeys` (modules/<id>.mjs) is its model: the data fields left out of
+// the static part, its own eases, a window's offset -- and two rules that
+// keep the static part MINIMAL:
+//
+// - ASSETS BY CONTENT. A page names its assets by place (`qr03.png`,
+// `shot07.png`: first seen, first numbered), so a post inserted early
+// renumbered every one after it. The key reads each asset reference as
+// its content's hash: an asset is the same asset wherever it is filed.
+// - ITEMS. A page may hand over its items (`items`: each segment's text,
+// each pip, each feed card) -- markup a frame draws only while its GATE
+// is visible: a slot (`gate: [k, prop]`, the item's own opacity or
+// autoAlpha) that is not 0, or for the feed an event that has happened
+// (`event`). An item's markup, the assets it names and its slots' values
+// are in the key of a frame that shows it and of no other, so a changed
+// subtitle recaptures the frames its clip is on screen, and a clip or
+// post inserted later leaves the frames before it as they were.
+//
+// FRAME_KEY_VERSION 2 is these rules: a render keyed by version 1 is
+// captured once more, then reused as ever.
+//
// Refused -- `null`, and the layer is rendered whole as before -- when the
// page is not one this models: no data script, a `data-duration` that is not
// the page's, a window, a cue whose FROM is not what its element holds, two
@@ -45,7 +66,7 @@ import { feedCues } from "./chrome-feed.mjs";
import { MODULES } from "./modules/index.mjs";
/** Bumped when what a frame key covers changes: every frame is captured once more. */
-export const FRAME_KEY_VERSION = 1;
+export const FRAME_KEY_VERSION = 2;
/**
* The regions whose pages this models, and the data fields their key leaves
@@ -107,11 +128,32 @@ function splitData(html, id) {
return { data, before: html.slice(0, from), after: html.slice(to) };
}
+/** An asset reference in a page: `assets/<name>`. */
+const ASSET_REF = /assets\/([A-Za-z0-9._-]+)/g;
+
+/**
+ * A page's text with every asset reference read as its content's hash
+ * (`assets/#<sha>`), and the names it referenced.
+ */
+function byContent(text, hashOf) {
+ const used = new Set();
+ const out = text.replace(ASSET_REF, (m, name) => {
+ const h = hashOf.get(name);
+ if (h === undefined) return m;
+ used.add(name);
+ return `assets/#${h}`;
+ });
+ return { text: out, used };
+}
+
/**
- * The static part's key: the page less what is keyed per frame, the assets'
- * hashes, the frame rate and the renderer. null when the page is not modelled.
+ * The page split into its static part and its items: `{ data, page, items,
+ * assets }`, `page` the static text (the data script less `omit`, every
+ * item's markup out, every asset by content), `items` each `{ key, gate?,
+ * event?, hash }` in page order, `assets` the static part's asset hashes.
+ * null when the page is not modelled.
*/
-export function staticKey({ html, region, assets = [], fps, version, frames = null }) {
+function splitPage({ html, region, assets = [], fps, frames = null, items = null }) {
const spec = FRAME_KEY_REGIONS[region];
if (!spec) return null;
const parts = splitData(html, spec.data);
@@ -128,12 +170,55 @@ export function staticKey({ html, region, assets = [], fps, version, frames = nu
const durs = [...html.matchAll(/data-duration="([^"]*)"/g)].map((m) => m[1]);
if (!durs.length || durs.some((d) => d !== durs[0])) return null;
const starts = [...html.matchAll(/data-start="([^"]*)"/g)].map((m) => m[1]);
- if (starts.some((s) => s !== "0")) return null;
+ if (starts.some((x) => x !== "0")) return null;
const rest = Object.fromEntries(Object.entries(data).filter(([k]) => !spec.omit.includes(k)));
- const page = (parts.before + JSON.stringify(rest) + parts.after).replace(/data-duration="[^"]*"/g, 'data-duration=""');
- const sorted = [...assets].map(([n, h]) => [String(n), String(h)]).sort((x, y) => x[0].localeCompare(y[0]));
+ let page = (parts.before + JSON.stringify(rest) + parts.after).replace(/data-duration="[^"]*"/g, 'data-duration=""');
+ const hashOf = new Map([...assets].map(([n, h]) => [String(n), String(h)]));
+ // The items out of the page, each hashed with the assets it names.
+ const itemOut = [];
+ const itemAssets = new Set();
+ for (const it of items ?? []) {
+ if (!it || typeof it.html !== "string" || !it.html) return null;
+ const at = page.indexOf(it.html);
+ if (at < 0) return null;
+ // With the whitespace that joins it to what is before it: a page's items
+ // are absolutely placed boxes, and the joins between them are not drawn
+ // -- so a page of n items and one of n + 1 have the same static part.
+ const lead = /\s*$/.exec(page.slice(0, at))[0].length;
+ page = page.slice(0, at - lead) + page.slice(at + it.html.length);
+ const { text, used } = byContent(it.html, hashOf);
+ for (const n of used) itemAssets.add(n);
+ itemOut.push({
+ key: it.key, at,
+ ...(it.gate ? { gate: it.gate } : {}),
+ ...(Number.isInteger(it.event) ? { event: it.event } : {}),
+ hash: createHash("sha1").update(text).digest("hex"),
+ });
+ }
+ // In page order (each removal shifts what follows: the order of `at` as removed is not the page's).
+ const ordered = items?.length ? orderItems(html, items, itemOut) : itemOut;
+ const { text: staticText, used } = byContent(page, hashOf);
+ // The static part's assets: every one it names, and every one no item names.
+ const statics = [...hashOf.entries()].filter(([n]) => used.has(n) || !itemAssets.has(n)).map(([, h]) => h).sort();
+ return { data, page: staticText, items: ordered, assets: statics };
+}
+
+/** The items in the order their markup stands in the page. */
+function orderItems(html, items, out) {
+ const pos = items.map((it) => html.indexOf(it.html));
+ return out.map((o, i) => ({ o, p: pos[i] })).sort((x, y) => x.p - y.p).map((x) => x.o);
+}
+
+/**
+ * The static part's key: the page less what is keyed per frame (and less
+ * its items), its assets by content, the frame rate and the renderer. null
+ * when the page is not modelled.
+ */
+export function staticKey({ html, region, assets = [], fps, version, frames = null, items = null }) {
+ const sp = splitPage({ html, region, assets, fps, frames, items });
+ if (!sp) return null;
return createHash("sha256")
- .update(JSON.stringify({ v: FRAME_KEY_VERSION, region, page, assets: sorted, fps, version }))
+ .update(JSON.stringify({ v: FRAME_KEY_VERSION, region, page: sp.page, assets: sp.assets, fps, version, items: !!items?.length }))
.digest("hex");
}
@@ -145,12 +230,13 @@ const repr = (v) => (typeof v === "number" ? `n${gsapRound(v)}` : `s${JSON.strin
*
* @returns {string[] | null} hex keys, frame 1 first
*/
-export function frameKeys({ html, region, assets = [], fps, frames, version }) {
- const sk = staticKey({ html, region, assets, fps, version, frames });
+export function frameKeys({ html, region, assets = [], fps, frames, version, items = null }) {
+ const sk = staticKey({ html, region, assets, fps, version, frames, items });
if (!sk) return null;
- if (FRAME_KEY_REGIONS[region].events) return feedFrameKeys({ html, sk, fps, frames });
+ const sp = splitPage({ html, region, assets, fps, frames, items });
+ if (FRAME_KEY_REGIONS[region].events) return feedFrameKeys({ html, sk, fps, frames, items: sp.items });
const spec = FRAME_KEY_REGIONS[region];
- const { data } = splitData(html, spec.data);
+ const { data } = sp;
const init = data.init;
const cues = data.cues;
const t0 = spec.offset ? Number(data[spec.offset]) : 0;
@@ -217,16 +303,39 @@ export function frameKeys({ html, region, assets = [], fps, frames, version }) {
// The state's hash: XOR over the slots of each slot's (id, value) hash,
// updated only where a value moves. Each slot's changes come from its own
// cue boundaries (a step) or a running cue (every frame).
+ // One accumulator for the page's own slots and one per item: an item's
+ // slots (its key, or its key's children `<key>.<part>`) count only while
+ // it is shown.
const acc = Buffer.alloc(20);
- const xor = (b) => {
- for (let i = 0; i < 20; i += 1) acc[i] ^= b[i];
+ const itemList = sp.items;
+ const itemAcc = itemList.map(() => Buffer.alloc(20));
+ const itemByKey = new Map(itemList.map((it, i) => [it.key, i]));
+ const ownerOf = (k) => {
+ if (itemByKey.has(k)) return itemByKey.get(k);
+ const dot = k.indexOf(".");
+ return dot > 0 && itemByKey.has(k.slice(0, dot)) ? itemByKey.get(k.slice(0, dot)) : -1;
+ };
+ const owner = new Map();
+ for (const s of slots.values()) owner.set(s.id, ownerOf(s.k));
+ const xorInto = (buf, b) => {
+ for (let i = 0; i < 20; i += 1) buf[i] ^= b[i];
+ };
+ const xor = (id, b) => {
+ const o = owner.get(id);
+ xorInto(o >= 0 ? itemAcc[o] : acc, b);
};
const cur = new Map();
for (const s of slots.values()) {
const v = valueAt(s, t0);
cur.set(s.id, v);
- xor(sha1(`${s.id}\u0001${v}`));
+ xor(s.id, sha1(`${s.id}\u0001${v}`));
}
+ // An item's gate: hidden while its slot holds 0 (at rest, from init or a
+ // finished cue); anything else -- a value, a cue running, a CSS default --
+ // is shown.
+ const HIDDEN = new Set(["in0", "en0"]);
+ const gateId = itemList.map((it) => (it.gate ? `${it.gate[0]}\u0000${it.gate[1]}` : null));
+ for (const id of gateId) if (id !== null && !slots.has(id)) return null;
// Per frame, the slots that may move: those with a cue starting by it or running at it.
const frameOf = (t) => Math.ceil((t - t0) * fps - 1e-6);
const touch = new Map(); // frame -> slots
@@ -250,11 +359,17 @@ export function frameKeys({ html, region, assets = [], fps, frames, version }) {
const v = valueAt(s, t);
const was = cur.get(s.id);
if (v === was) continue;
- xor(sha1(`${s.id}\u0001${was}`));
- xor(sha1(`${s.id}\u0001${v}`));
+ xor(s.id, sha1(`${s.id}\u0001${was}`));
+ xor(s.id, sha1(`${s.id}\u0001${v}`));
cur.set(s.id, v);
}
- out[f] = createHash("sha1").update(sk).update(acc).digest("hex");
+ const h = createHash("sha1").update(sk).update(acc);
+ for (let i = 0; i < itemList.length; i += 1) {
+ const g = gateId[i];
+ if (g !== null && HIDDEN.has(cur.get(g))) continue;
+ h.update(`\u0002${itemList[i].key}\u0003${itemList[i].hash}`).update(itemAcc[i]);
+ }
+ out[f] = h.digest("hex");
}
return out;
}
@@ -270,7 +385,7 @@ export function frameKeys({ html, region, assets = [], fps, frames, version }) {
* page's plan, run here with the shortest and the tallest cards, has a cue
* that runs past the cap after the event before it.
*/
-function feedFrameKeys({ html, sk, fps, frames }) {
+function feedFrameKeys({ html, sk, fps, frames, items = [] }) {
const { data } = splitData(html, FRAME_KEY_REGIONS.feed.data);
const g = Number(data.grid);
const per = g / fps;
@@ -306,13 +421,20 @@ function feedFrameKeys({ html, sk, fps, frames }) {
}
}
+ // A card's markup (its item) is in a frame's key from its post's event
+ // on: before it the card is hidden and moves nothing (the plan is causal:
+ // a post's cues start at its event). An event still to come is in no
+ // frame's key, so a post added later leaves the frames before it alone.
+ const cardOf = new Map(items.filter((it) => Number.isInteger(it.event)).map((it) => [`p${it.event}`, it.hash]));
const out = new Array(frames);
for (let f = 0; f < frames; f += 1) {
const t = f * per;
let sig = "";
for (const e of events) {
const d = t - e.at;
- sig += `${e.tag}=${d < 0 ? "f" : d >= cap ? "s" : d};`;
+ if (d < 0) continue;
+ const card = cardOf.get(e.tag);
+ sig += `${e.tag}=${d >= cap ? "s" : d}${card ? `|${card}` : ""};`;
}
out[f] = createHash("sha1").update(sk).update(sig).digest("hex");
}
diff --git a/umtool/report-to-video/frame-keys.test.mjs b/umtool/report-to-video/frame-keys.test.mjs
@@ -276,3 +276,98 @@ test("feed frame keys: by its events; a moved post keys as it did, a changed one
const C = keys([10, 21, 4, 6]);
assert.equal(C.k[200], A.k[200]);
});
+
+// ---- the module cache rules (release 39): items and assets by content ------
+
+const itemKeysOf = (s, render = RENDER, assets = []) => {
+ const items = [];
+ const html = deckHtml(s, render, { fonts: FONTS, items });
+ return frameKeys({ html, region: "deck", fps: 30, frames: Math.round(s.total * 30), version: "v", assets, items });
+};
+
+test("items: a changed title changes only the frames its clip's text is on screen", () => {
+ const A = itemKeysOf(schedule(0));
+ const T = itemKeysOf(schedule(0, { c02: "Another sanctuary" }));
+ const differ = A.map((k, n) => (k !== T[n] ? n : null)).filter((n) => n != null);
+ assert.ok(differ.length > 0, "the frames that show it change");
+ // c02 plays 14–22 s; its text is in from the handover into it to the one out of it.
+ assert.ok(differ[0] >= 14 * 30 - 15, `nothing before its handover changes (first at ${differ[0]})`);
+ assert.ok(differ.at(-1) <= 22.5 * 30, `nothing after it is gone changes (last at ${differ.at(-1)})`);
+ assert.equal(A.slice(0, 13 * 30).join(), T.slice(0, 13 * 30).join());
+ // The page with items keys apart from the page without (a key is its model's).
+ assert.notEqual(A[500], keysOf(schedule(0))[500]);
+});
+
+test("items: assets keyed by content -- the same picture under another name is the same frame", () => {
+ const s = schedule(0);
+ s.segments = s.segments.map((x, i) => ({ ...x, qrUrl: `https://x.test/${x.id}` }));
+ const render = { ...RENDER, chrome: { ...RENDER.chrome, deck: { qr: { show: true } } } };
+ const items = [];
+ const qrs = (names) => Object.fromEntries(s.segments.map((x, i) => [x.id, `assets/${names[i]}`]));
+ const keyed = (names, hashes) => {
+ const its = [];
+ const html = deckHtml(s, render, { fonts: FONTS, qrSrcs: qrs(names), items: its });
+ return frameKeys({ html, region: "deck", fps: 30, frames: 1200, version: "v", items: its, assets: names.map((n, i) => [n, hashes[i]]) });
+ };
+ void items;
+ const H = ["h0", "h1", "h2", "h3", "h4"];
+ const A = keyed(["qr00.png", "qr01.png", "qr02.png", "qr03.png", "qr04.png"], H);
+ const B = keyed(["qr10.png", "qr11.png", "qr12.png", "qr13.png", "qr14.png"], H);
+ assert.deepEqual(A, B, "renamed assets of the same bytes key alike");
+ const C = keyed(["qr00.png", "qr01.png", "qr02.png", "qr03.png", "qr04.png"], ["h0", "h1", "hX", "h3", "h4"]);
+ const differ = A.map((k, n) => (k !== C[n] ? n : null)).filter((n) => n != null);
+ assert.ok(differ.length > 0 && differ[0] >= 13 * 30, "a changed code changes only where its clip shows");
+});
+
+test("rail pitch: a clip appended leaves every frame before it as it was", async () => {
+ const { estimateSchedule } = await import("./deck.mjs");
+ const PITCH = { ...RENDER, chrome: { ...RENDER.chrome, deck: { pip: { spacing: "pitch", pitch: 40 } } } };
+ const clip = (id, end) => ({ type: "clip", id, video: id, start: 0, end, date: "2024-01-01" });
+ const base = [clip("a", 8), clip("b", 9), clip("c", 7)];
+ const keys = (timeline, render) => {
+ const s = estimateSchedule({ render, timeline, posts: [], provenance: {} });
+ return { s, k: itemKeysOf(s, render) };
+ };
+ const A = keys(base, PITCH);
+ const B = keys([...base, clip("d", 6)], PITCH);
+ // Until the marker reaches c's pip -- and d's pip comes in ahead of it --
+ // every frame is the same; from then on the rail shows d's pip.
+ const cStart = A.s.segments[2].start;
+ const first = A.k.findIndex((k, f) => k !== B.k[f]);
+ assert.ok(first > Math.floor(cStart * 30), `the frames before c keep their keys (first change at frame ${first}, c at ${cStart * 30})`);
+ assert.ok(first < Math.floor((cStart + 1.5) * 30), "d's pip comes in as the marker reaches c");
+ // Even spacing moves every pip: nothing is reused.
+ const E = keys(base, RENDER), F = keys([...base, clip("d", 6)], RENDER);
+ assert.notEqual(E.k[10], F.k[10]);
+});
+
+test("feed items: a changed or added post changes only the frames from its event on", async () => {
+ const { feedHtml } = await import("./chrome-feed.mjs");
+ const { deckSchedule } = await import("./deck.mjs");
+ const FEED = { ...RENDER, chrome: { engine: "hyperframes", layout: "deck", deck: { posts: { layout: "feed" } } } };
+ const CLIPS = [
+ { id: "c1", type: "clip", video: "a", start: 0, end: 10, date: "2024-09-05" },
+ { id: "c2", type: "clip", video: "b", start: 0, end: 20, date: "2024-10-01" },
+ { id: "c3", type: "clip", video: "c", start: 0, end: 6, date: "2025-12-08" },
+ ];
+ const POST = (id, date, text = `words of ${id}`) => ({ id, platform: "bluesky", author: "P", handle: "p.live", date, text, url: `https://bsky.app/profile/p.live/post/${id}` });
+ const keys = (posts) => {
+ const s = deckSchedule({ entries: CLIPS, durs: [10, 20, 6], D: 0.5, render: FEED, provenance: { siteOrigin: "https://x.test", channelSlug: "c" }, posts });
+ const items = [];
+ const html = feedHtml(s, FEED, { fonts: FONTS, items });
+ return { s, k: frameKeys({ html, region: "feed", fps: 30, frames: Math.round(s.total * 30), version: "v", items }) };
+ };
+ const base = [POST("a", "2024-10-19"), POST("b", "2025-01-02")];
+ const A = keys(base);
+ assert.ok(A.k, "modelled with items");
+ const lastIn = A.s.posts.at(-1).in;
+ // b's words changed: nothing before b comes in changes.
+ const B = keys([base[0], POST("b", "2025-01-02", "other words entirely")]);
+ const firstB = A.k.findIndex((k, f) => k !== B.k[f]);
+ assert.ok(firstB >= Math.floor(lastIn * 30), `nothing before b's event changes (first at ${firstB}, b at ${lastIn * 30})`);
+ // A post added on the last clip: nothing before it changes.
+ const C = keys([...base, POST("z", "2026-01-22")]);
+ const zIn = C.s.posts.find((p) => p.id === "z").in;
+ const firstC = A.k.findIndex((k, f) => k !== C.k[f]);
+ assert.ok(firstC >= Math.floor(zIn * 30), `nothing before z's event changes (first at ${firstC}, z at ${zIn * 30})`);
+});
diff --git a/umtool/report-to-video/modules/feed.mjs b/umtool/report-to-video/modules/feed.mjs
@@ -60,7 +60,10 @@ export default defineModule({
const qrSrcs = {};
for (const p of posts) if (p.qrUrl) qrSrcs[p.id] = byUrl.get(p.qrUrl);
const shotSrcs = await ctx.shots(posts);
- return feedHtml(schedule, render, { fonts, qrSrcs, shotSrcs, from: ctx.from, duration: ctx.duration });
+ // Its items -- each card -- go to the frame keys.
+ const items = [];
+ const html = feedHtml(schedule, render, { fonts, qrSrcs, shotSrcs, from: ctx.from, duration: ctx.duration, items });
+ return { html, items };
},
regions(_schedule, { render, outDir, frames = null }) {
return [assertRegion({ name: "feed", frames: frames ?? path.join(outDir, "chrome", "feed-frames"), ...feedGeometry(render).column })];
diff --git a/umtool/report-to-video/modules/flips.mjs b/umtool/report-to-video/modules/flips.mjs
@@ -38,4 +38,6 @@ export default defineModule({
regions(_schedule, { render, outDir, frames = null }) {
return [sideRegion(render, frames ?? path.join(outDir, "chrome", "flips-frames"), "flips")];
},
+ // A cue interpreter like the deck's: keyed per frame (frame-keys.mjs).
+ frameKeys: { data: "flips-data", omit: ["init", "cues", "window", "total", "ids"] },
});
diff --git a/umtool/report-to-video/modules/fx.mjs b/umtool/report-to-video/modules/fx.mjs
@@ -48,4 +48,6 @@ export default defineModule({
...fxGeometry(render, { feed: schedule.layout === "feed" }),
})];
},
+ // A cue interpreter like the deck's: keyed per frame (frame-keys.mjs).
+ frameKeys: { data: "fx-data", omit: ["init", "cues", "window", "total"] },
});
diff --git a/umtool/report-to-video/modules/shell.mjs b/umtool/report-to-video/modules/shell.mjs
@@ -62,7 +62,10 @@ export default defineModule({
const byUrl = await ctx.qrs(schedule.segments.map((s) => s.qrUrl), lay.qr.size);
for (const s of schedule.segments) if (s.qrUrl) qrSrcs[s.id] = byUrl.get(s.qrUrl);
}
- return deckHtml(schedule, render, { fonts, qrSrcs, from: ctx.from, duration: ctx.duration });
+ // Its items -- each segment's text, each pip -- go to the frame keys.
+ const items = [];
+ const html = deckHtml(schedule, render, { fonts, qrSrcs, from: ctx.from, duration: ctx.duration, items });
+ return { html, items };
},
regions(_schedule, { render, outDir, frames = null }) {
const { deck } = deckGeometry(render);
diff --git a/umtool/report-to-video/modules/stats.mjs b/umtool/report-to-video/modules/stats.mjs
@@ -44,4 +44,6 @@ export default defineModule({
...statsGeometry(render, { feed: schedule.layout === "feed" }),
})];
},
+ // A cue interpreter like the deck's: keyed per frame (frame-keys.mjs).
+ frameKeys: { data: "stats-data", omit: ["init", "cues", "window", "total", "ids"] },
});
diff --git a/umtool/report-to-video/modules/teaser.mjs b/umtool/report-to-video/modules/teaser.mjs
@@ -42,4 +42,6 @@ export default defineModule({
await ctx.projectFile(TEASER_FONT_FILE, TEASER_FONT_ASSET);
return teaserHtml(ctx.entry, ctx.render, { font: TEASER_FONT_ASSET, transition: ctx.transition });
},
+ // A cue interpreter: a teaser whose words changed recaptures only the frames they are on.
+ frameKeys: { data: "teaser-data", omit: ["init", "cues"] },
});
diff --git a/umtool/report-to-video/modules/threads.mjs b/umtool/report-to-video/modules/threads.mjs
@@ -46,4 +46,6 @@ export default defineModule({
regions(_schedule, { render, outDir, frames = null }) {
return [sideRegion(render, frames ?? path.join(outDir, "chrome", "threads-frames"), "threads")];
},
+ // A cue interpreter like the deck's: keyed per frame (frame-keys.mjs).
+ frameKeys: { data: "threads-data", omit: ["init", "cues", "window", "total", "ids"] },
});