Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 3f02f81c91b07b405f81077db6a0819ffbf1c594
parent 963594cd4714ab71d33b2c8a0e13b52f1b4e0ca5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 28 Oct 2026 23:55:15 -0400

umtool: the story modules -- pair (then and now), chapter (a section bumper), status (a ledger that fills)

- pair: two clips on one subject with their dates; "split" a strip in the
  footage box (THEN | NOW, the side playing lit, the caption under them),
  "then→now" a card over the pair's first seconds. A whole-cut page, each
  pair an item in the frame keys.
- chapter: a bumper over the first seconds of the clip it opens (title,
  subtitle, date), one window page per chapter laid at its own second,
  keyed from its offset.
- status: "announced <date> → <outcome>" rows in a corner of the footage
  box; a row comes in on its first clip, its outcome on the outcome's clip
  (else the end of its last). Each state of the ledger an item.
- chrome-cues.mjs: the cue page the three share (compileCues, cuePageHtml).
- story-settings.mjs: their defaults and validators, a leaf in SETTINGS;
  validateChrome takes render.chrome.pair / chapter / status.
- knobs.md's Modules section regenerated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/docs/knobs.md | 34++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/chrome-cues.mjs | 228+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/chrome-story.mjs | 381+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/compose-chrome.mjs | 2+-
Mumtool/report-to-video/deck.mjs | 2+-
Aumtool/report-to-video/modules/chapter.mjs | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/index.mjs | 5++++-
Aumtool/report-to-video/modules/pair.mjs | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/rail.test.mjs | 2+-
Mumtool/report-to-video/modules/registry.test.mjs | 2+-
Mumtool/report-to-video/modules/settings.mjs | 5+++++
Aumtool/report-to-video/modules/status.mjs | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/story-settings.mjs | 210+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/story.test.mjs | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 1232 insertions(+), 5 deletions(-)

diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -323,9 +323,12 @@ filter. A knob absent is its default, and a module whose knobs are all absent dr | [Popup posts](#popup-posts) `popup-posts` | A clip's posts as cards over the footage, each window its own short page at its own second. (pages at their own seconds) | `render.chrome.deck.posts` | | [Stamps](#stamps) `stamp` | Each counted mark's word, stamped over the footage as it lands. (a page over the whole cut) | `render.chrome.factcheck.stamp` | | [Stats](#stats) `stats` | A frame scan's running numbers over the clips that declare them. (a page over the whole cut) | `render.chrome.stats` | +| [Then and now (pair)](#then-and-now-pair) `pair` | Two clips on one subject, each with its date: a then \| now strip (or a then→now card) with the pair's caption. (a page over the whole cut) | `render.chrome.pair` | +| [Status ledger](#status-ledger) `status` | A row per item -- announced, then followed up or not -- filling a column as the cut plays. (a page over the whole cut) | `render.chrome.status` | | [Effects](#effects) `fx` | Overlays on the picture: receipts, a zoom, a scrubber, captions. (a page over the whole cut) | `render.chrome.fx` | | [Thread rail](#thread-rail) `threads` | A card per thread beside the footage, lit as its clips play. (a page over the whole cut) | `render.chrome.threads` | | [Flips](#flips) `flips` | Pairs of what was said then and now, in the side panel. (a page over the whole cut) | `render.chrome.flips` | +| [Chapters](#chapters) `chapter` | A section bumper over the first seconds of the clip it opens: title, subtitle, date. (pages at their own seconds) | `render.chrome.chapter` | | [Finale](#finale) `finale` | The cut's last clips under the rail redrawn large, the final totals and stats cards. (pages at their own seconds) | `render.chrome.deck.finale` | ### Deck (the shell) @@ -460,6 +463,27 @@ A frame scan’s running numbers over the clips that declare them, in a panel in | `render.chrome.stats.position` | `top-left` `top-right` `bottom-left` `bottom-right` · default `bottom-left` | manifest | | `render.chrome.stats.fields`, `.name` | a list of `stack` `stackBB` `playersLeft` `level`; bool · default all, `true` | manifest | +### Then and now (pair) + +Two clips on one subject, each with its date (`render.chrome.pair`, chrome-story.mjs). The footage is not split -- two clips never play at once: "split" is a strip in the footage box, THEN on one side and NOW on the other, the side playing lit, up while either clip plays; "then→now" a card with both dates over the pair's first `seconds`. A pair whose clips the cut does not play is not drawn. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `chrome.pair.pairs[]` | 1–60 `{then: {clip, date?, label?}, now: {clip, date?, label?}, caption? ≤200, topic? ≤60, style?, also?: [{clip, side, date?}]}` -- a date YYYY, YYYY-MM or YYYY-MM-DD; `also` more clips on a side (≤4) | `umtool modules apply <p> --config module-config.json` · `umtool look <p> pair='{…}'` | +| `chrome.pair.style` | `split` · `then→now` · default `split` (a pair's own `style` wins) | `umtool look <p> pair.style=then→now` | +| `chrome.pair.position`, `.dateFormat`, `.seconds` | `bottom` `top` · `long` `year` `iso` · 1–10 s · default `bottom`, `long`, 4 | `umtool look <p> pair.position=top` | +| `chrome.pair.labels` | `{then, now}` ≤16 each · default Then, Now | `umtool look <p> pair.labels='{"then":"2012"}'` | + +### Status ledger + +A ledger of items, each announced and then followed up -- or not (`render.chrome.status`, chrome-story.mjs): a column in a corner of the footage box that fills as the cut plays. A row comes in on its first clip (its announcement's, else its first evidence clip); its outcome is written on the outcome's clip, else at the end of its last clip. `fill` keeps the last `rows` rows up from the first on; `each` shows a row alone over its own clips. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `chrome.status.items[]` | 1–30 `{item ≤140, announced: words | {clip?, date?, text?}, outcome?: words | {clip?, date?, text?}, evidence?: [clip…]}` -- at least one clip named | `umtool modules apply <p> --config module-config.json` · `umtool look <p> status='{…}'` | +| `chrome.status.mode` | `fill` · `each` · default `fill` | `umtool look <p> status.mode=each` | +| `chrome.status.position`, `.rows`, `.width`, `.title` | a corner of the footage box · 1–8 · 360–900 px · ≤40 · default `top-right`, 4, 640, "On the record" | `umtool look <p> status.position=bottom-left` | + ### Effects Overlays on the picture -- receipts, a zoom, the scrubber, a kinetic quote, punch-ins, whip cuts -- (`render.chrome.fx`, fx.mjs); `umtool takes effects <p>` lists the presets. @@ -484,6 +508,16 @@ Then-and-now pairs in the side panel (`render.chrome.flips`, flips.mjs); the thr |---|---|---| | `render.chrome.flips` | see flips.mjs | manifest | +### Chapters + +A section bumper -- per dog, per crisis, per lawsuit -- over the first `seconds` of the clip it opens (`render.chrome.chapter`, chrome-story.mjs): a window of the cut laid at its own second, over the footage box (the deck stays). It does not insert time: the clip's sound plays under it. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `chrome.chapter.list[]` | 1–40 `{at, title ≤48, subtitle? ≤90, date?}` -- `at` the clip it opens, once each | `umtool modules apply <p> --config module-config.json` · `umtool look <p> chapter='{…}'` | +| `chrome.chapter.style` | `card` (the footage box covered) · `lower` (a band at its foot) · default `card` | `umtool look <p> chapter.style=lower` | +| `chrome.chapter.seconds` | 1–8 s, never past the clip · default 3 | `umtool look <p> chapter.seconds=2.5` | + ### Finale The full reference is [The finale](#the-finale-the-timeline-in-primary-view). It reads the counter's totals (`counter.totals`) and the rail's layout (`rail.layout`); the counter reads its window (`finale.window`): a mark that would stamp inside it counts as it opens. diff --git a/umtool/report-to-video/chrome-cues.mjs b/umtool/report-to-video/chrome-cues.mjs @@ -0,0 +1,228 @@ +// THE CUE PAGE (release 39, the video modules): the one shape a small chrome +// page takes -- markup whose every element starts hidden, and a list of cues +// each stating its FROM, played by a paused GSAP timeline a renderer seeks +// frame by frame. chrome-stats.mjs is the pattern; the pair, chapter and +// status modules write their pages through this file so they do not each +// carry a copy of the interpreter (and the frame-key model reads all three +// the same way: frame-keys.mjs, `frameKeys` on each module). +// +// Two placements: +// - WHOLE: a page as long as the cut (or a window of it, `from`/`duration`), +// its data `{ total, window, ids, init, cues }`. +// - WINDOW: a page for one window of the cut, its data `{ from, dur, init, +// cues }`, the cues in the cut's clock (the frame keys' `offset: "from"`). +// +// PURE: data in, an HTML string out. +import { pageDuration } from "./deck.mjs"; + +/** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ +export const INSTANT = 0.001; + +export const r4 = (v) => Math.round(v * 10000) / 10000; + +export const esc = (s) => + String(s ?? "") + .replace(/&/g, "&amp;") + .replace(/</g, "&lt;") + .replace(/>/g, "&gt;") + .replace(/"/g, "&quot;"); + +/** + * Events -> cues: ordered by time, clamped so a cue never starts before the + * last on its element ends, every FROM stated (the last TO on its element, + * or its init). `events` are `{ k, at, dur, to, ease }`. + * + * @returns {{ init: Record<string, object>, cues: Array<{ k: string, at: number, dur: number, from: object, to: object, ease: string }> }} + */ +export function compileCues(init, events) { + const ev = events.map((e, n) => ({ ...e, at: r4(e.at), dur: r4(Math.max(INSTANT, e.dur)), n })); + ev.sort((a, b) => a.at - b.at || a.n - b.n); + const state = Object.fromEntries(Object.entries(init).map(([k, v]) => [k, { ...v }])); + const freeAt = new Map(); + const cues = []; + for (const e of ev) { + let { at, dur } = e; + const free = freeAt.get(e.k) ?? 0; + if (at < free) { + const end = at + dur; + at = r4(free); + dur = r4(Math.max(INSTANT, end - at)); + } + const cur = state[e.k] ?? (state[e.k] = {}); + const from = {}; + for (const p of Object.keys(e.to)) from[p] = cur[p]; + Object.assign(cur, e.to); + freeAt.set(e.k, r4(at + dur)); + cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease }); + } + return { init, cues }; +} + +/** + * Show `k` over [a, b]: in over `fadeIn`, out over `fadeOut` before b (each + * at most half the span). The events compileCues takes. + */ +export function spanEvents(k, a, b, { fadeIn = 0.35, fadeOut = 0.3, prop = "autoAlpha" } = {}) { + const len = Math.max(0, b - a); + if (!(len > 0)) return []; + return [ + { k, at: a, dur: Math.min(fadeIn, len / 2), to: { [prop]: 1 }, ease: "power2.out" }, + { k, at: Math.max(a, b - fadeOut), dur: Math.min(fadeOut, len / 2), to: { [prop]: 0 }, ease: "power1.in" }, + ]; +} + +/** Spans `{in, out}` with the ones that touch (or overlap) joined. */ +export function joinSpans(spans, gap = 1e-6) { + const out = []; + for (const s of [...spans].sort((x, y) => x.in - y.in)) { + const last = out[out.length - 1]; + if (last && s.in - last.out <= gap) last.out = Math.max(last.out, s.out); + else out.push({ in: s.in, out: s.out }); + } + return out; +} + +/** The deck's two faces, under the deck's private names (docs/quirks.md). */ +function fontFaces(fonts) { + return `@font-face { font-family: 'DeckSans'; font-weight: 400; font-style: normal; src: url('${esc(fonts.regular ?? "")}'); } + @font-face { font-family: 'DeckSansBold'; font-weight: 400; font-style: normal; src: url('${esc(fonts.bold ?? "")}'); }`; +} + +/** + * A cue page's HTML. + * + * @param {{ id: string, W: number, H: number, fps: number, fonts?: {regular?: string, bold?: string}, + * gsapSrc?: string, css: string, body: string, init: object, cues: object[], + * whole?: { total: number, from?: number, duration?: number | null, ids?: string[] }, + * window?: { from: number, dur: number } }} p + */ +export function cuePageHtml(p) { + const { id, W, H, fps, css, body, init, cues } = p; + const fonts = p.fonts ?? {}; + const gsapSrc = p.gsapSrc ?? "assets/gsap.min.js"; + let data; + let dur; + if (p.window) { + dur = r4(p.window.dur); + data = { from: r4(p.window.from), dur, init, cues }; + } else { + const total = p.whole.total; + const from = Number(p.whole.from ?? 0); + dur = p.whole.duration != null ? r4(Number(p.whole.duration)) : r4(total - from); + if (!(dur > 0)) throw new Error(`${id}: nothing to render from ${from}s of a ${total}s cut`); + const windowed = from > 0 || Math.abs(dur - total) > 1e-6; + data = { total: r4(total), window: windowed ? { from: r4(from), dur } : null, ids: p.whole.ids ?? [], init, cues }; + } + const json = JSON.stringify(data).replace(/</g, "\\u003c"); + const D = pageDuration(dur, fps); + // The window's timeline plays the cut's [from, from + dur]; a whole page's + // its own [0, total], or the window of it it was asked for. + const play = p.window + ? `const tl = gsap.timeline({ paused: true }); + tl.add(inner.tweenFromTo(S.from, S.from + S.dur, { duration: S.dur, ease: "none" }), 0); + const local = (t) => Math.max(0, Math.min(S.dur, (Number(t) || 0) - S.from));` + : `inner.set({}, {}, S.total); + let tl = inner; + if (S.window) { + tl = gsap.timeline({ paused: true }); + tl.add(inner.tweenFromTo(S.window.from, S.window.from + S.window.dur, { duration: S.window.dur, ease: "none" }), 0); + } + const local = (t) => { + const v = Number(t) || 0; + return S.window ? Math.max(0, Math.min(S.window.dur, v - S.window.from)) : Math.max(0, v); + };`; + return `<!doctype html> +<html lang="en"> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=${W}, height=${H}" /> + <script src="${esc(gsapSrc)}"></script> + <style> + ${fontFaces(fonts)} + * { margin: 0; padding: 0; box-sizing: border-box; } + html, body { width: ${W}px; height: ${H}px; overflow: hidden; background: transparent; } + body { font-family: 'DeckSans', sans-serif; font-synthesis: none; + -webkit-font-smoothing: antialiased; text-rendering: geometricPrecision; } + #root { position: relative; width: ${W}px; height: ${H}px; overflow: hidden; } + #${id}-clip { position: absolute; left: 0; top: 0; width: ${W}px; height: ${H}px; } + ${css} + </style> + </head> + <body> + <div id="root" data-composition-id="${id}" data-start="0" data-duration="${D}" + data-width="${W}" data-height="${H}"> + <div id="${id}-clip" class="clip" data-start="0" data-duration="${D}" data-track-index="1"> + ${body} + </div> + </div> + + <script id="${id}-data" type="application/json">${json}</script> + <script> + const S = JSON.parse(document.getElementById("${id}-data").textContent); + const byK = {}; + for (const el of document.querySelectorAll("[data-k]")) byK[el.dataset.k] = el; + // t = 0, then the cues. Every cue states its from, so a seek from + // anywhere to anywhere lands on the same pixels. + for (const k of Object.keys(S.init)) if (byK[k]) gsap.set(byK[k], S.init[k]); + const inner = gsap.timeline({ paused: true }); + for (const c of S.cues) { + const el = byK[c.k]; + if (!el) continue; + inner.fromTo(el, c.from, { ...c.to, duration: c.dur, ease: c.ease, immediateRender: false }, c.at); + } + ${play} + window.__timelines = window.__timelines || {}; + window.__timelines["${id}"] = tl; + + const ready = document.fonts.ready.catch(() => {}).then(() => { document.documentElement.dataset.fit = "1"; }); + const params = new URLSearchParams(location.search); + const still = params.get("still"); + if (still !== null) { + tl.seek(local(still), false); + ready.then(() => tl.seek(local(still), false)); + } + // umtool's live preview: the parent seeks in cut seconds, as it seeks the deck. + if (params.get("preview") === "1") { + window.addEventListener("message", (e) => { + const m = e.data || {}; + if (m.type === "deck:seek") tl.seek(local(m.t), false); + }); + ready.then(() => { + if (window.parent !== window) window.parent.postMessage({ type: "${id}:ready", ids: S.ids || [] }, "*"); + }); + } + </script> + </body> +</html> +`; +} + +/** + * Each segment's span in the cut, by id: `{ in, out }` -- its start to its + * end less the dissolve into the next (the frame a viewer reads it on). + */ +export function segmentSpans(schedule) { + const out = new Map(); + for (const s of schedule?.segments ?? []) out.set(s.id, { in: s.start, out: s.end }); + return out; +} + +/** + * A date as the cut writes it: "2012" | "Sep 2012" | "29 Sep 2012" from + * YYYY, YYYY-MM or YYYY-MM-DD (`format` "iso" keeps it; "year" the year). + * Anything else is written as given. + */ +export function dateText(d, format = "long") { + if (d === undefined || d === null || d === "") return ""; + const s = String(d); + const m = /^(\d{4})(?:-(\d{2}))?(?:-(\d{2}))?$/.exec(s); + if (!m || format === "iso") return s; + if (format === "year") return m[1]; + const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + if (!m[2]) return m[1]; + const mon = MON[Number(m[2]) - 1] ?? m[2]; + return m[3] ? `${Number(m[3])} ${mon} ${m[1]}` : `${mon} ${m[1]}`; +} + +/** A YYYY / YYYY-MM / YYYY-MM-DD date (what pair, chapter and status take). */ +export const DATE_RE = /^\d{4}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\d|3[01]))?)?$/; diff --git a/umtool/report-to-video/chrome-story.mjs b/umtool/report-to-video/chrome-story.mjs @@ -0,0 +1,381 @@ +// THE STORY PAGES (release 39): the pages of the `pair`, `chapter` and +// `status` modules (modules/pair.mjs, chapter.mjs, status.mjs), each a cue +// page (chrome-cues.mjs). PURE: a schedule and a render block in, the slice +// a module draws and its HTML out. +// +// - PAIR: then and now -- two clips on one subject, each with its date. As +// "split" a strip in the footage box, THEN on one side and NOW on the +// other, the side playing lit, the caption under them, up while either +// clip plays; as "then→now" a card with both dates and an arrow over the +// first `seconds` of the pair. The footage itself is not split: two clips +// never play at once. +// - CHAPTER: a section bumper over the first `seconds` of the clip it opens +// (a window of the cut, laid at its own second): title, subtitle, date. +// - STATUS: a ledger, a row per item -- "announced <date> → <outcome>" -- +// that fills as the cut plays: a row comes in on its first clip, its +// outcome on the outcome's clip (else the end of its last evidence clip). +// Each STATE of the ledger is its own block, shown over exactly its span. +import { deckGeometry, feedGeometry } from "./deck.mjs"; +import { rgba } from "./chrome-deck.mjs"; +import { compileCues, cuePageHtml, dateText, esc, joinSpans, r4, segmentSpans, spanEvents, INSTANT } from "./chrome-cues.mjs"; +import { CHAPTER_DEFAULTS, PAIR_DEFAULTS, STATUS_DEFAULTS } from "./modules/story-settings.mjs"; + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); + +/** The footage box this cut's clips play in (the feed's when it is one). */ +export function footageBox(render, { feed = false } = {}) { + const f = feed ? feedGeometry(render).footage : deckGeometry(render).footage; + return { x: f.x, y: f.y, width: f.width, height: f.height }; +} + +const scaleOf = (render) => (render?.width ?? 1920) / 1920; +const pxOf = (render) => (v) => Math.max(1, Math.round(v * scaleOf(render))); +const even = (v) => 2 * Math.round(v / 2); + +// --------------------------------------------------------------------------- +// PAIR +// --------------------------------------------------------------------------- + +export function resolvePair(render) { + const v = isObj(render?.chrome?.pair) ? render.chrome.pair : {}; + return { + ...PAIR_DEFAULTS, ...v, + labels: { ...PAIR_DEFAULTS.labels, ...(isObj(v.labels) ? v.labels : {}) }, + pairs: Array.isArray(v.pairs) ? v.pairs : [], + }; +} + +/** The pair strip's region: a band across the footage box, at its foot (or top). */ +export function pairGeometry(render, { feed = false } = {}) { + const f = footageBox(render, { feed }); + const px = pxOf(render); + const P = resolvePair(render); + const height = even(px(P.style === "then→now" ? 200 : 132)); + const inset = px(18); + const width = even(f.width - 2 * inset); + return { + x: f.x + inset, + y: P.position === "top" ? f.y + inset : f.y + f.height - inset - height, + width, height, + }; +} + +/** + * The pairs this cut plays, in the cut's clock: each `{ i, style, then, now, + * caption, topic, spans: [{in, out}], phases: [{side, in, out}] }` -- a pair + * none of whose clips is in the cut is left out. + */ +export function pairSchedule(schedule, render) { + const P = resolvePair(render); + const at = segmentSpans(schedule); + const out = []; + P.pairs.forEach((p, i) => { + if (!isObj(p?.then) || !isObj(p?.now)) return; + const sides = [ + { side: "then", clip: p.then.clip }, + { side: "now", clip: p.now.clip }, + ...(Array.isArray(p.also) ? p.also.map((a) => ({ side: a.side, clip: a.clip })) : []), + ]; + const phases = []; + for (const s of sides) { + const sp = at.get(s.clip); + if (!sp) continue; + const same = p.then.clip === p.now.clip; + phases.push({ side: same ? "both" : s.side, in: sp.in, out: sp.out }); + } + if (!phases.length) return; + // One phase per span: a clip named twice (then and now the same clip) once. + const seen = new Set(); + const uniq = phases.filter((ph) => (seen.has(ph.in) ? false : (seen.add(ph.in), true))).sort((a, b) => a.in - b.in); + out.push({ + i, style: p.style ?? P.style, then: p.then, now: p.now, caption: p.caption ?? "", topic: p.topic ?? "", + phases: uniq, spans: joinSpans(uniq.map((ph) => ({ in: ph.in, out: ph.out })), 0.75), + }); + }); + return out; +} + +/** The pair page's cues: a pair's block `p<i>` in over its spans; `p<i>.t` / `p<i>.n` lit by phase. */ +export function pairCues(pairs, P) { + const init = {}; + const ev = []; + for (const p of pairs) { + const k = `p${p.i}`; + init[k] = { autoAlpha: 0 }; + if (p.style === "then→now") { + const a = p.spans[0].in; + const b = Math.min(p.spans[0].out, a + P.seconds); + ev.push(...spanEvents(k, a, b, { fadeIn: 0.4, fadeOut: 0.4 })); + continue; + } + for (const sp of p.spans) ev.push(...spanEvents(k, sp.in, sp.out)); + for (const side of ["t", "n"]) init[`${k}.${side}`] = { opacity: 0.35 }; + for (const ph of p.phases) { + const lit = ph.side === "both" ? ["t", "n"] : [ph.side === "then" ? "t" : "n"]; + for (const s of lit) { + ev.push({ k: `${k}.${s}`, at: ph.in, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + ev.push({ k: `${k}.${s}`, at: Math.max(ph.in + 0.3, ph.out - 0.3), dur: 0.3, to: { opacity: 0.35 }, ease: "power1.in" }); + } + } + } + return compileCues(init, ev); +} + +/** + * The pair page: `{ html, items }` (each pair's block an item, gated by its + * own autoAlpha -- a changed caption recaptures only the frames it is up). + */ +export function pairHtml(schedule, render, opts = {}) { + const P = resolvePair(render); + const pairs = pairSchedule(schedule, render); + if (!pairs.length) throw new Error("pair: the cut plays none of the pairs' clips"); + const geo = pairGeometry(render, { feed: schedule.layout === "feed" }); + const pal = render.palette; + const px = pxOf(render); + const fps = schedule.fps ?? render.fps ?? 30; + const { init, cues } = pairCues(pairs, P); + const items = []; + const blocks = pairs.map((p) => { + const k = `p${p.i}`; + const d = (s) => esc(dateText(s?.date, P.dateFormat)); + const label = (side) => esc(p[side]?.label ?? P.labels[side]); + let html; + if (p.style === "then→now") { + html = `<div class="pair card" data-k="${k}"><div class="row"><div class="side"><div class="lab">${label("then")}</div><div class="date">${d(p.then)}</div></div><div class="arrow">→</div><div class="side"><div class="lab">${label("now")}</div><div class="date">${d(p.now)}</div></div></div>${p.caption ? `<div class="cap">${esc(p.caption)}</div>` : ""}</div>`; + } else { + html = `<div class="pair split" data-k="${k}"><div class="row"><div class="side t" data-k="${k}.t"><span class="lab">${label("then")}</span><span class="date">${d(p.then)}</span></div><div class="mid">${p.topic ? esc(p.topic) : "→"}</div><div class="side n" data-k="${k}.n"><span class="lab">${label("now")}</span><span class="date">${d(p.now)}</span></div></div>${p.caption ? `<div class="cap">${esc(p.caption)}</div>` : ""}</div>`; + } + items.push({ key: k, gate: [k, "autoAlpha"], html }); + return html; + }); + const css = ` + .pair { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; + background: ${rgba(pal.bg, 0.86)}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); + padding: ${px(12)}px ${px(22)}px; display: flex; flex-direction: column; justify-content: center; gap: ${px(6)}px; } + .row { display: flex; align-items: center; justify-content: space-between; gap: ${px(18)}px; } + .side { display: flex; align-items: baseline; gap: ${px(12)}px; white-space: nowrap; } + .split .side.n { justify-content: flex-end; } + .lab { font-family: 'DeckSansBold', sans-serif; font-size: ${px(22)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.accent}; } + .date { font-family: 'DeckSansBold', sans-serif; font-size: ${px(34)}px; color: ${pal.fg}; font-variant-numeric: tabular-nums; } + .mid { flex: 1 1 auto; min-width: 0; text-align: center; font-size: ${px(24)}px; color: ${pal.muted}; + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + .cap { font-size: ${px(24)}px; line-height: ${px(30)}px; color: ${pal.fg}; text-align: center; + display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } + .card .row { justify-content: center; gap: ${px(40)}px; } + .card .side { flex-direction: column; align-items: center; gap: ${px(4)}px; } + .card .date { font-size: ${px(46)}px; } + .arrow { font-family: 'DeckSansBold', sans-serif; font-size: ${px(56)}px; color: ${pal.accent}; }`; + const html = cuePageHtml({ + id: "pair", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, + body: blocks.join("\n "), init, cues, + whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids: pairs.map((p) => `p${p.i}`) }, + }); + return { html, items }; +} + +// --------------------------------------------------------------------------- +// CHAPTER +// --------------------------------------------------------------------------- + +export function resolveChapter(render) { + const v = isObj(render?.chrome?.chapter) ? render.chrome.chapter : {}; + return { ...CHAPTER_DEFAULTS, ...v, list: Array.isArray(v.list) ? v.list : [] }; +} + +/** + * The chapters this cut plays, each its window: `{ segment, from, to, n, + * title, subtitle, date }` -- `segment` the clip it opens, the window its + * first `seconds` (never past the clip). + */ +export function chapterWindows(schedule, render) { + const C = resolveChapter(render); + const at = segmentSpans(schedule); + const out = []; + C.list.forEach((c, n) => { + const sp = at.get(c?.at); + if (!sp) return; + const to = Math.min(sp.out, sp.in + C.seconds); + if (!(to - sp.in > 0.2)) return; + out.push({ segment: c.at, from: sp.in, to, n, title: c.title, subtitle: c.subtitle ?? "", date: c.date ?? null }); + }); + return out; +} + +/** The chapter bumper's region: the footage box. */ +export function chapterGeometry(render, { feed = false } = {}) { + return footageBox(render, { feed }); +} + +/** One chapter window's page. `window` is the snapped `{ segment, from, to }`. */ +export function chapterHtml(schedule, render, window, opts = {}) { + const C = resolveChapter(render); + const ch = chapterWindows(schedule, render).find((w) => w.segment === window.segment); + if (!ch) throw new Error(`chapter: no chapter opens ${window.segment} in this cut`); + const geo = chapterGeometry(render, { feed: schedule.layout === "feed" }); + const pal = render.palette; + const px = pxOf(render); + const fps = schedule.fps ?? render.fps ?? 30; + const from = r4(window.from); + const dur = r4(window.to - window.from); + const ev = [...spanEvents("ch", from, from + dur, { fadeIn: 0.25, fadeOut: 0.45 })]; + ev.push({ k: "ch.t", at: from, dur: 0.5, to: { y: 0 }, ease: "power2.out" }); + const { init, cues } = compileCues({ ch: { autoAlpha: 0 }, "ch.t": { y: px(18) } }, ev); + const lower = C.style === "lower"; + const date = ch.date ? dateText(ch.date) : ""; + const css = ` + .chapter { position: absolute; visibility: hidden; opacity: 0; display: flex; flex-direction: column; + ${lower + ? `left: 0; right: 0; bottom: 0; height: ${px(220)}px; padding: ${px(26)}px ${px(48)}px; justify-content: center; + background: linear-gradient(to top, ${rgba(pal.bg, 0.94)}, ${rgba(pal.bg, 0.0)});` + : `inset: 0; align-items: center; justify-content: center; text-align: center; padding: ${px(60)}px; + background: ${rgba(pal.bg, 0.92)};`} } + .ct { display: flex; flex-direction: column; gap: ${px(12)}px; ${lower ? "" : "align-items: center;"} } + .rule { width: ${px(96)}px; height: ${px(6)}px; background: ${pal.accent}; border-radius: ${px(3)}px; } + .title { font-family: 'DeckSansBold', sans-serif; font-size: ${px(lower ? 54 : 84)}px; line-height: 1.08; color: ${pal.fg}; } + .sub { font-size: ${px(lower ? 28 : 36)}px; line-height: 1.25; color: ${pal.muted}; max-width: ${px(1300)}px; } + .date { font-family: 'DeckSansBold', sans-serif; font-size: ${px(26)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.accent}; }`; + const body = `<div class="chapter" data-k="ch"><div class="ct" data-k="ch.t"><div class="rule"></div>${date ? `<div class="date">${esc(date)}</div>` : ""}<div class="title">${esc(ch.title)}</div>${ch.subtitle ? `<div class="sub">${esc(ch.subtitle)}</div>` : ""}</div></div>`; + return cuePageHtml({ + id: "chapter", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init, cues, + window: { from, dur }, + }); +} + +// --------------------------------------------------------------------------- +// STATUS +// --------------------------------------------------------------------------- + +export function resolveStatus(render) { + const v = isObj(render?.chrome?.status) ? render.chrome.status : {}; + return { ...STATUS_DEFAULTS, ...v, items: Array.isArray(v.items) ? v.items : [] }; +} + +const sideClip = (s) => (isObj(s) && typeof s.clip === "string" ? s.clip : null); +const sideText = (s, fmt = "long") => { + if (typeof s === "string") return s; + if (!isObj(s)) return ""; + const d = s.date ? dateText(s.date, fmt) : ""; + return [d, s.text ?? ""].filter(Boolean).join(" · "); +}; + +/** + * The ledger's rows in the cut's clock: each `{ n, item, announced, outcome, + * in, done }` -- `in` the second it comes in (its first clip's start), + * `done` the second its outcome is filled (the outcome's clip, else the end + * of its last clip), null when no outcome is given. Rows none of whose clips + * the cut plays are left out. + */ +export function statusRows(schedule, render) { + const S = resolveStatus(render); + const at = segmentSpans(schedule); + const rows = []; + S.items.forEach((it, n) => { + const clips = [sideClip(it.announced), ...(Array.isArray(it.evidence) ? it.evidence : []), sideClip(it.outcome)].filter(Boolean); + const spans = clips.map((c) => at.get(c)).filter(Boolean); + if (!spans.length) return; + const first = Math.min(...spans.map((s) => s.in)); + const last = Math.max(...spans.map((s) => s.out)); + const oc = sideClip(it.outcome); + const hasOutcome = it.outcome !== undefined && sideText(it.outcome) !== ""; + const done = !hasOutcome ? null : oc && at.get(oc) ? Math.max(first, at.get(oc).in) : last; + rows.push({ + n, item: it.item, announced: sideText(it.announced), outcome: hasOutcome ? sideText(it.outcome) : "", + in: first, done: done == null ? null : Math.max(first, done), last, + }); + }); + return rows.sort((a, b) => a.in - b.in || a.n - b.n); +} + +/** + * The ledger's states: between two events (a row in, an outcome filled) it + * reads the same. `fill`: from the first row on, the last `rows` rows; `each`: + * a row alone, over its own clips. + */ +export function statusStates(schedule, render) { + const S = resolveStatus(render); + const rows = statusRows(schedule, render); + const total = schedule.total; + if (S.mode === "each") { + return rows.flatMap((r) => { + const parts = []; + if (r.done != null && r.done > r.in + 0.05 && r.done < r.last) { + parts.push({ at: r.in, until: r.done, rows: [{ ...r, filled: false }] }); + parts.push({ at: r.done, until: r.last, rows: [{ ...r, filled: true }] }); + } else parts.push({ at: r.in, until: r.last, rows: [{ ...r, filled: r.done != null && r.done <= r.in + 0.05 }] }); + return parts; + }); + } + const events = [...new Set(rows.flatMap((r) => [r.in, ...(r.done != null ? [r.done] : [])]).map(r4))].sort((a, b) => a - b); + return events.map((t, j) => { + const shown = rows.filter((r) => r.in <= t + 1e-6).slice(-S.rows); + return { at: t, until: events[j + 1] ?? total, rows: shown.map((r) => ({ ...r, filled: r.done != null && r.done <= t + 1e-6 })) }; + }); +} + +/** The ledger's region: a column in a corner of the footage box, as tall as `rows` rows. */ +export function statusGeometry(render, { feed = false } = {}) { + const f = footageBox(render, { feed }); + const S = resolveStatus(render); + const px = pxOf(render); + const width = even(Math.min(px(S.width), f.width - 2 * px(18))); + const height = even(Math.min(f.height - 2 * px(18), px(58) + S.rows * px(92))); + const inset = px(18); + const right = S.position.endsWith("right"); + const bottom = S.position.startsWith("bottom"); + return { + x: right ? f.x + f.width - inset - width : f.x + inset, + y: bottom ? f.y + f.height - inset - height : f.y + inset, + width, height, + }; +} + +/** The status page: `{ html, items }`, each state an item gated by its own autoAlpha. */ +export function statusHtml(schedule, render, opts = {}) { + const S = resolveStatus(render); + const states = statusStates(schedule, render); + if (!states.length) throw new Error("status: the cut plays none of the ledger's clips"); + const geo = statusGeometry(render, { feed: schedule.layout === "feed" }); + const pal = render.palette; + const px = pxOf(render); + const fps = schedule.fps ?? render.fps ?? 30; + const init = { lg: { autoAlpha: 0 } }; + const ev = []; + const spans = joinSpans(states.map((s) => ({ in: s.at, out: s.until })), 1e-3); + for (const sp of spans) ev.push(...spanEvents("lg", sp.in, sp.out, { fadeIn: 0.35, fadeOut: 0.35 })); + const items = []; + const blocks = states.map((st, j) => { + const k = `s${j}`; + init[k] = { autoAlpha: 0 }; + ev.push({ k, at: st.at, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); + ev.push({ k, at: st.until, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); + const rows = st.rows.map((r) => `<div class="r${r.filled ? " done" : ""}"><div class="it">${esc(r.item)}</div><div class="ln"><span class="an">${esc(r.announced || "announced")}</span><span class="ar">→</span><span class="oc">${r.filled ? esc(r.outcome) : "…"}</span></div></div>`).join(""); + const html = `<div class="st" data-k="${k}">${rows}</div>`; + items.push({ key: k, gate: [k, "autoAlpha"], html }); + return html; + }); + const { init: i2, cues } = compileCues(init, ev); + const css = ` + #ledger { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; + background: ${rgba(pal.bg, 0.86)}; border-left: ${px(5)}px solid ${pal.accent}; + box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); } + .hd { position: absolute; left: ${px(20)}px; right: ${px(20)}px; top: ${px(12)}px; height: ${px(34)}px; + font-family: 'DeckSansBold', sans-serif; font-size: ${px(20)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.muted}; } + .st { position: absolute; left: ${px(20)}px; right: ${px(20)}px; top: ${px(50)}px; bottom: ${px(8)}px; + visibility: hidden; opacity: 0; display: flex; flex-direction: column; gap: ${px(10)}px; } + .r { display: flex; flex-direction: column; gap: ${px(2)}px; } + .it { font-family: 'DeckSansBold', sans-serif; font-size: ${px(24)}px; line-height: ${px(30)}px; color: ${pal.fg}; + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + .ln { display: flex; gap: ${px(10)}px; font-size: ${px(21)}px; line-height: ${px(28)}px; color: ${pal.muted}; white-space: nowrap; min-width: 0; } + .an { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 45%; } + .ar { flex: none; color: ${pal.accent}; font-family: 'DeckSansBold', sans-serif; } + .oc { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; } + .done .oc { color: ${pal.amber ?? pal.fg}; }`; + const body = `<div id="ledger" data-k="lg"><div class="hd">${esc(S.title)}</div> + ${blocks.join("\n ")} + </div>`; + const html = cuePageHtml({ + id: "status", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init: i2, cues, + whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids: states.map((_, j) => `s${j}`) }, + }); + return { html, items }; +} diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs @@ -890,7 +890,7 @@ export async function composeChrome({ const suffix = windowed ? `-from${fmtSeconds(from)}` : ""; // A window (a posts window, the finale's): the one asked for, snapped to the frame grid. - const win = mod.window ? mod.window(sched, { window, segment, fps: rate, total }) : null; + const win = mod.window ? mod.window(sched, { window, segment, fps: rate, total, render: manifest.render }) : null; const names = mod.names ? mod.names({ preview, window: win, entry: teaser, suffix }) diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -124,7 +124,7 @@ export function validateChrome(chrome, render = {}) { const errors = []; if (chrome === undefined || chrome === null) return errors; if (!isObj(chrome)) return ["render.chrome must be an object"]; - unknownKeys(chrome, ["engine", "layout", "deck", "factcheck", "threads", "flips", "stats", "fx"], "render.chrome", errors); + unknownKeys(chrome, ["engine", "layout", "deck", "factcheck", "threads", "flips", "stats", "fx", "pair", "chapter", "status"], "render.chrome", errors); if (chrome.engine !== "hyperframes") errors.push('render.chrome.engine must be "hyperframes"'); if (chrome.layout !== "deck") errors.push('render.chrome.layout must be "deck"'); if (render.rail) errors.push("render.chrome (the deck) and render.rail cannot both be set"); diff --git a/umtool/report-to-video/modules/chapter.mjs b/umtool/report-to-video/modules/chapter.mjs @@ -0,0 +1,82 @@ +// THE CHAPTER (module `chapter`, region `chapter`): a section bumper over the +// first seconds of the clip it opens -- a title, a subtitle, a date +// (`render.chrome.chapter`). One short page per chapter, laid at its own +// second like a posts window. chrome-story.mjs writes the page. +import path from "node:path"; + +import { snapWindow } from "../deck.mjs"; +import { chapterGeometry, chapterHtml, chapterWindows, resolveChapter } from "../chrome-story.mjs"; +import { assertRegion, defineModule } from "./contract.mjs"; +import { CHAPTER_DEFAULTS, CHAPTER_LIMITS, CHAPTER_STYLES, validateChapter } from "./story-settings.mjs"; + +const SEGMENT_RE = /^[A-Za-z0-9_.:-]+$/; + +export default defineModule({ + id: "chapter", + version: 1, + z: 85, + kind: "overlay-window", + slot: "footage", + title: "Chapters", + summary: "A section bumper over the first seconds of the clip it opens: title, subtitle, date.", + configKey: "render.chrome.chapter", + defaults: CHAPTER_DEFAULTS, + validate: (v) => validateChapter(v), + resolve: resolveChapter, + ui: [ + { key: "style", type: "enum", options: CHAPTER_STYLES, label: "Style", default: "card" }, + { key: "seconds", type: "number", min: CHAPTER_LIMITS.seconds[0], max: CHAPTER_LIMITS.seconds[1], step: 0.25, label: "Seconds", default: 3 }, + { key: "list", type: "list", label: "Chapters", item: [ + { key: "at", type: "clip", label: "Opens clip" }, + { key: "title", type: "text", label: "Title" }, + { key: "subtitle", type: "text", label: "Subtitle" }, + { key: "date", type: "date", label: "Date" }, + ] }, + ], + docs: { + heading: "Chapters", + intro: "A section bumper -- per dog, per crisis, per lawsuit -- over the first `seconds` of the clip it opens (`render.chrome.chapter`, chrome-story.mjs): a window of the cut laid at its own second, over the footage box (the deck stays). It does not insert time: the clip's sound plays under it.", + rows: [ + ["`chrome.chapter.list[]`", `1–${CHAPTER_LIMITS.list} \`{at, title ≤${CHAPTER_LIMITS.title}, subtitle? ≤${CHAPTER_LIMITS.subtitle}, date?}\` -- \`at\` the clip it opens, once each`, "`umtool modules apply <p> --config module-config.json` · `umtool look <p> chapter='{…}'`"], + ["`chrome.chapter.style`", "`card` (the footage box covered) · `lower` (a band at its foot) · default `card`", "`umtool look <p> chapter.style=lower`"], + ["`chrome.chapter.seconds`", `${CHAPTER_LIMITS.seconds[0]}–${CHAPTER_LIMITS.seconds[1]} s, never past the clip · default 3`, "`umtool look <p> chapter.seconds=2.5`"], + ], + }, + region: "chapter", + workers: "narrow", + noun: "the chapter's", + on: (schedule, render) => !!schedule?.segments && chapterWindows(schedule, render).length > 0, + check: (schedule, render) => (chapterWindows(schedule, render).length + ? null + : "the chapter region needs render.chrome.chapter with a chapter at a clip the cut plays"), + window(schedule, { window = null, segment = null, fps, total, render = {} }) { + const want = window ?? chapterWindows(schedule, render).find((w) => w.segment === segment); + if (!want) throw new Error(segment ? `no chapter opens ${segment} in this schedule` : "the chapter region needs a window (or a segment)"); + if (!SEGMENT_RE.test(String(want.segment))) throw new Error(`chapter: ${want.segment} is not a segment id`); + return snapWindow(want, { fps, total }); + }, + names: ({ preview, window }) => ({ project: `chapter-${preview ? "preview-" : ""}${window.segment}`, stem: `chapter-${window.segment}` }), + async page(ctx) { + const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); + return chapterHtml(ctx.schedule, ctx.render, ctx.window, { fonts }); + }, + regions(schedule, { render, outDir, shift = 0, clip = null }) { + const fps = Number(schedule.fps ?? render.fps); + const g = chapterGeometry(render, { feed: schedule.layout === "feed" }); + return chapterWindows(schedule, render) + .map((w) => ({ w, s: snapWindow(w, { fps, total: schedule.total }) })) + .filter(({ s }) => !clip || (s.from < clip.at + clip.dur && s.to > clip.at)) + .map(({ w, s }) => assertRegion({ + name: "chapter", + segment: s.segment, + window: { segment: w.segment, from: w.from, to: w.to }, + frames: path.join(outDir, "chrome", `chapter-${s.segment}-frames`), + x: g.x, y: g.y, width: g.width, height: g.height, + offset: s.from - shift, + frameCount: s.frames, + }, "window")); + }, + preview: (_slice, { render }) => ({ region: "chapter", geometry: chapterGeometry(render) }), + // A window of the cut: frame n is cut time `from` + n / fps. + frameKeys: { data: "chapter-data", omit: ["init", "cues", "from", "dur"], offset: "from" }, +}); diff --git a/umtool/report-to-video/modules/index.mjs b/umtool/report-to-video/modules/index.mjs @@ -26,12 +26,15 @@ import counter from "./counter.mjs"; import claims from "./claims.mjs"; import intro from "./intro.mjs"; import blur from "./blur.mjs"; +import pair from "./pair.mjs"; +import chapter from "./chapter.mjs"; +import status from "./status.mjs"; export { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, REGION_PLACEMENTS }; /** Every module, by z (stack order), then id. */ export const MODULES = Object.freeze( - [chart, shell, subtitle, qr, rail, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur] + [chart, shell, subtitle, qr, rail, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur, pair, chapter, status] .sort((a, b) => a.z - b.z || a.id.localeCompare(b.id)), ); diff --git a/umtool/report-to-video/modules/pair.mjs b/umtool/report-to-video/modules/pair.mjs @@ -0,0 +1,72 @@ +// THE PAIR (module `pair`, region `pair`): then and now -- two clips on one +// subject, each with its date (`render.chrome.pair`). As "split" a strip in +// the footage box, THEN on one side and NOW on the other, the side playing +// lit and the pair's caption under them; as "then→now" a card with both +// dates and an arrow over the pair's first seconds. chrome-story.mjs writes +// the page; story-settings.mjs holds its rules. +import path from "node:path"; + +import { pairGeometry, pairHtml, pairSchedule, resolvePair } from "../chrome-story.mjs"; +import { assertRegion, defineModule } from "./contract.mjs"; +import { DATE_FORMATS, PAIR_DEFAULTS, PAIR_LIMITS, PAIR_POSITIONS, PAIR_STYLES, validatePair } from "./story-settings.mjs"; + +export default defineModule({ + id: "pair", + version: 1, + z: 52, + kind: "overlay-whole", + slot: "footage", + title: "Then and now", + summary: "Two clips on one subject, each with its date: a then | now strip (or a then→now card) with the pair's caption.", + configKey: "render.chrome.pair", + defaults: PAIR_DEFAULTS, + validate: (v) => validatePair(v), + resolve: resolvePair, + ui: [ + { key: "style", type: "enum", options: PAIR_STYLES, label: "Style", default: "split" }, + { key: "position", type: "enum", options: PAIR_POSITIONS, label: "Strip at", default: "bottom" }, + { key: "dateFormat", type: "enum", options: DATE_FORMATS, label: "Dates", default: "long" }, + { key: "labels.then", type: "text", label: "Then label", default: "Then" }, + { key: "labels.now", type: "text", label: "Now label", default: "Now" }, + { key: "seconds", type: "number", min: PAIR_LIMITS.seconds[0], max: PAIR_LIMITS.seconds[1], step: 0.5, label: "Card seconds (then→now)", default: 4 }, + { key: "pairs", type: "list", label: "Pairs", item: [ + { key: "then.clip", type: "clip", label: "Then clip" }, + { key: "then.date", type: "date", label: "Then date" }, + { key: "now.clip", type: "clip", label: "Now clip" }, + { key: "now.date", type: "date", label: "Now date" }, + { key: "topic", type: "text", label: "Topic" }, + { key: "caption", type: "text", label: "Caption" }, + { key: "style", type: "enum", options: PAIR_STYLES, label: "Style (this pair)" }, + ] }, + ], + docs: { + heading: "Then and now (pair)", + intro: "Two clips on one subject, each with its date (`render.chrome.pair`, chrome-story.mjs). The footage is not split -- two clips never play at once: \"split\" is a strip in the footage box, THEN on one side and NOW on the other, the side playing lit, up while either clip plays; \"then→now\" a card with both dates over the pair's first `seconds`. A pair whose clips the cut does not play is not drawn.", + rows: [ + ["`chrome.pair.pairs[]`", `1–${PAIR_LIMITS.pairs} \`{then: {clip, date?, label?}, now: {clip, date?, label?}, caption? ≤${PAIR_LIMITS.caption}, topic? ≤${PAIR_LIMITS.topic}, style?, also?: [{clip, side, date?}]}\` -- a date YYYY, YYYY-MM or YYYY-MM-DD; \`also\` more clips on a side (≤${PAIR_LIMITS.also})`, "`umtool modules apply <p> --config module-config.json` · `umtool look <p> pair='{…}'`"], + ["`chrome.pair.style`", "`split` · `then→now` · default `split` (a pair's own `style` wins)", "`umtool look <p> pair.style=then→now`"], + ["`chrome.pair.position`, `.dateFormat`, `.seconds`", "`bottom` `top` · `long` `year` `iso` · 1–10 s · default `bottom`, `long`, 4", "`umtool look <p> pair.position=top`"], + ["`chrome.pair.labels`", "`{then, now}` ≤16 each · default Then, Now", "`umtool look <p> pair.labels='{\"then\":\"2012\"}'`"], + ], + }, + region: "pair", + workers: "narrow", + noun: "the pair strip's", + on: (schedule, render) => !!schedule?.segments && pairSchedule(schedule, render).length > 0, + check: (schedule, render) => (pairSchedule(schedule, render).length + ? null + : "the pair region needs render.chrome.pair with a pair whose clips the cut plays"), + async page(ctx) { + const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); + return pairHtml(ctx.schedule, ctx.render, { fonts, from: ctx.from, duration: ctx.duration }); + }, + regions(schedule, { render, outDir, frames = null }) { + return [assertRegion({ + name: "pair", frames: frames ?? path.join(outDir, "chrome", "pair-frames"), + ...pairGeometry(render, { feed: schedule.layout === "feed" }), + })]; + }, + preview: (_slice, { render }) => ({ region: "pair", geometry: pairGeometry(render) }), + // A cue interpreter: each pair an item, so a changed caption recaptures only its frames. + frameKeys: { data: "pair-data", omit: ["init", "cues", "window", "total", "ids"] }, +}); diff --git a/umtool/report-to-video/modules/rail.test.mjs b/umtool/report-to-video/modules/rail.test.mjs @@ -47,5 +47,5 @@ test("rail settings: spacing, pitch, and the deck's other keys refused by name", assert.equal(resolveDeck(render({})).pip.pitch, undefined, "no pitch unless set: the deck resolves as it did"); assert.equal(rail.resolve(render({ spacing: "pitch" })).pip.pitch, 28); assert.equal(rail.validate, settingsOf("rail").validate); - assert.deepEqual(SETTINGS.map((s) => s.id), ["stamp", "threads", "flips", "stats", "fx", "finale", "claims", "counter", "shell", "rail", "subtitle", "qr", "popup-posts"]); + assert.deepEqual(SETTINGS.map((s) => s.id), ["stamp", "threads", "flips", "stats", "fx", "pair", "chapter", "status", "finale", "claims", "counter", "shell", "rail", "subtitle", "qr", "popup-posts"]); }); diff --git a/umtool/report-to-video/modules/registry.test.mjs b/umtool/report-to-video/modules/registry.test.mjs @@ -47,7 +47,7 @@ test("the registry: unique ids and regions, sorted by z, the deck's overlays in assert.equal(new Set(ids).size, ids.length); for (let i = 1; i < MODULES.length; i += 1) assert.ok(MODULES[i - 1].z <= MODULES[i].z); // The order the build has always laid them in: the finale last. - assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "stats", "fx", "threads", "flips", "finale"]); + assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "stats", "pair", "status", "fx", "threads", "flips", "chapter", "finale"]); assert.equal(moduleOfRegion("deck").id, "shell"); assert.equal(regionModule("posts").id, "popup-posts"); assert.throws(() => regionModule("nope"), /unknown chrome region: nope/); diff --git a/umtool/report-to-video/modules/settings.mjs b/umtool/report-to-video/modules/settings.mjs @@ -16,6 +16,7 @@ import { validateThreads } from "../threads.mjs"; import { validateFlips } from "../flips.mjs"; import { validateStats } from "../stats.mjs"; import { validateFx } from "../fx.mjs"; +import { validateChapter, validatePair, validateStatus } from "./story-settings.mjs"; /** * Every deck setting and its default. A manifest names only what it changes; @@ -340,6 +341,10 @@ export const SETTINGS = Object.freeze([ { id: "flips", key: "flips", configKey: "render.chrome.flips", validate: (v) => validateFlips(v) }, { id: "stats", key: "stats", configKey: "render.chrome.stats", validate: (v) => validateStats(v) }, { id: "fx", key: "fx", configKey: "render.chrome.fx", validate: (v) => validateFx(v) }, + // The story modules (story-settings.mjs): then and now, the chapters, the status ledger. + { id: "pair", key: "pair", configKey: "render.chrome.pair", validate: (v) => validatePair(v) }, + { id: "chapter", key: "chapter", configKey: "render.chrome.chapter", validate: (v) => validateChapter(v) }, + { id: "status", key: "status", configKey: "render.chrome.status", validate: (v) => validateStatus(v) }, // From here the deck's own keys: `deck` is an object. { id: "finale", key: "deck.finale", configKey: "render.chrome.deck.finale", deck: true, validate: (v, { where }) => validateFinaleSettings(v, `${where}.finale`) }, diff --git a/umtool/report-to-video/modules/status.mjs b/umtool/report-to-video/modules/status.mjs @@ -0,0 +1,69 @@ +// THE STATUS LEDGER (module `status`, region `status`): a row per item -- +// "announced 12 Mar 2022 → no follow-up found" -- in a column in a corner of +// the footage box that fills as the cut plays (`render.chrome.status`): a +// row comes in on its first clip, its outcome on the outcome's clip (else at +// the end of its last). chrome-story.mjs writes the page. +import path from "node:path"; + +import { resolveStatus, statusGeometry, statusHtml, statusRows } from "../chrome-story.mjs"; +import { assertRegion, defineModule } from "./contract.mjs"; +import { STATUS_DEFAULTS, STATUS_LIMITS, STATUS_MODES, STATUS_POSITIONS, validateStatus } from "./story-settings.mjs"; + +export default defineModule({ + id: "status", + version: 1, + z: 55, + kind: "overlay-whole", + slot: "footage", + title: "Status ledger", + summary: "A row per item -- announced, then followed up or not -- filling a column as the cut plays.", + configKey: "render.chrome.status", + defaults: STATUS_DEFAULTS, + validate: (v) => validateStatus(v), + resolve: resolveStatus, + ui: [ + { key: "title", type: "text", label: "Heading", default: STATUS_DEFAULTS.title }, + { key: "mode", type: "enum", options: STATUS_MODES, label: "Rows", default: "fill" }, + { key: "position", type: "enum", options: STATUS_POSITIONS, label: "Corner", default: "top-right" }, + { key: "rows", type: "number", min: STATUS_LIMITS.rows[0], max: STATUS_LIMITS.rows[1], label: "Rows shown", default: 4 }, + { key: "width", type: "number", min: STATUS_LIMITS.width[0], max: STATUS_LIMITS.width[1], label: "Width (px)", default: 640 }, + { key: "items", type: "list", label: "Items", item: [ + { key: "item", type: "text", label: "Item" }, + { key: "announced.clip", type: "clip", label: "Announced in" }, + { key: "announced.date", type: "date", label: "Announced on" }, + { key: "announced.text", type: "text", label: "Announced (words)" }, + { key: "outcome.clip", type: "clip", label: "Outcome in" }, + { key: "outcome.date", type: "date", label: "Outcome on" }, + { key: "outcome.text", type: "text", label: "Outcome" }, + ] }, + ], + docs: { + heading: "Status ledger", + intro: "A ledger of items, each announced and then followed up -- or not (`render.chrome.status`, chrome-story.mjs): a column in a corner of the footage box that fills as the cut plays. A row comes in on its first clip (its announcement's, else its first evidence clip); its outcome is written on the outcome's clip, else at the end of its last clip. `fill` keeps the last `rows` rows up from the first on; `each` shows a row alone over its own clips.", + rows: [ + ["`chrome.status.items[]`", `1–${STATUS_LIMITS.items} \`{item ≤${STATUS_LIMITS.item}, announced: words | {clip?, date?, text?}, outcome?: words | {clip?, date?, text?}, evidence?: [clip…]}\` -- at least one clip named`, "`umtool modules apply <p> --config module-config.json` · `umtool look <p> status='{…}'`"], + ["`chrome.status.mode`", "`fill` · `each` · default `fill`", "`umtool look <p> status.mode=each`"], + ["`chrome.status.position`, `.rows`, `.width`, `.title`", `a corner of the footage box · ${STATUS_LIMITS.rows.join("–")} · ${STATUS_LIMITS.width.join("–")} px · ≤${STATUS_LIMITS.title} · default \`top-right\`, 4, 640, "On the record"`, "`umtool look <p> status.position=bottom-left`"], + ], + }, + region: "status", + workers: "narrow", + noun: "the status ledger's", + on: (schedule, render) => !!schedule?.segments && statusRows(schedule, render).length > 0, + check: (schedule, render) => (statusRows(schedule, render).length + ? null + : "the status region needs render.chrome.status with an item whose clips the cut plays"), + async page(ctx) { + const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); + return statusHtml(ctx.schedule, ctx.render, { fonts, from: ctx.from, duration: ctx.duration }); + }, + regions(schedule, { render, outDir, frames = null }) { + return [assertRegion({ + name: "status", frames: frames ?? path.join(outDir, "chrome", "status-frames"), + ...statusGeometry(render, { feed: schedule.layout === "feed" }), + })]; + }, + preview: (_slice, { render }) => ({ region: "status", geometry: statusGeometry(render) }), + // A cue interpreter: each state of the ledger an item, keyed only where it is shown. + frameKeys: { data: "status-data", omit: ["init", "cues", "window", "total", "ids"] }, +}); diff --git a/umtool/report-to-video/modules/story-settings.mjs b/umtool/report-to-video/modules/story-settings.mjs @@ -0,0 +1,210 @@ +// THE STORY MODULES' SETTINGS (release 39): `pair` (then and now, two clips +// with their dates), `chapter` (a section bumper at a named clip) and +// `status` (a ledger of items, each announced and then followed up -- or +// not). Their defaults and validators -- the one copy, a LEAF like +// settings.mjs (deck.mjs imports it through SETTINGS, so it imports nothing +// that imports deck.mjs). +// +// render.chrome.pair { style, position, dateFormat, labels, seconds, pairs: [...] } +// render.chrome.chapter { seconds, style, list: [...] } +// render.chrome.status { title, position, rows, width, mode, items: [...] } +// +// A clip is named by its timeline id; whether it is in the cut is checked +// where the timeline is known (`storyClipErrors`, the writers), not here. + +/** A YYYY / YYYY-MM / YYYY-MM-DD date. */ +export const DATE_RE = /^\d{4}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\d|3[01]))?)?$/; +const CLIP_RE = /^[A-Za-z0-9_.:-]{1,80}$/; + +export const PAIR_STYLES = Object.freeze(["split", "then→now"]); +export const PAIR_POSITIONS = Object.freeze(["bottom", "top"]); +export const DATE_FORMATS = Object.freeze(["long", "year", "iso"]); +export const PAIR_SIDES = Object.freeze(["then", "now"]); +export const PAIR_LIMITS = Object.freeze({ pairs: 60, caption: 200, topic: 60, label: 16, also: 4, seconds: [1, 10] }); +export const PAIR_DEFAULTS = Object.freeze({ + style: "split", position: "bottom", dateFormat: "long", + labels: Object.freeze({ then: "Then", now: "Now" }), seconds: 4, pairs: Object.freeze([]), +}); + +export const CHAPTER_STYLES = Object.freeze(["card", "lower"]); +export const CHAPTER_LIMITS = Object.freeze({ list: 40, title: 48, subtitle: 90, seconds: [1, 8] }); +export const CHAPTER_DEFAULTS = Object.freeze({ seconds: 3, style: "card", list: Object.freeze([]) }); + +export const STATUS_POSITIONS = Object.freeze(["top-right", "top-left", "bottom-right", "bottom-left"]); +export const STATUS_MODES = Object.freeze(["fill", "each"]); +export const STATUS_LIMITS = Object.freeze({ items: 30, item: 140, text: 160, title: 40, rows: [1, 8], width: [360, 900], evidence: 12 }); +export const STATUS_DEFAULTS = Object.freeze({ + title: "On the record", position: "top-right", rows: 4, width: 640, mode: "fill", items: Object.freeze([]), +}); + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; +const str = (v) => typeof v === "string" && v.trim().length > 0; + +function unknown(obj, allowed, where, errors) { + for (const k of Object.keys(obj)) if (!allowed.includes(k)) errors.push(`${where}.${k} is not a setting (${allowed.join(", ")})`); +} + +function text(v, max, where, errors, { required = false } = {}) { + if (v === undefined) { + if (required) errors.push(`${where} is required`); + return; + } + if (typeof v !== "string" || (required && !v.trim())) { errors.push(`${where} must be words`); return; } + if ([...v].length > max) errors.push(`${where} is ${[...v].length} characters (at most ${max})`); +} + +function clip(v, where, errors) { + if (typeof v !== "string" || !CLIP_RE.test(v)) errors.push(`${where} must name a clip by its timeline id`); +} + +function date(v, where, errors) { + if (v === undefined || v === null) return; + if (typeof v !== "string" || !DATE_RE.test(v)) errors.push(`${where} must be a date: YYYY, YYYY-MM or YYYY-MM-DD`); +} + +/** Every reason `render.chrome.pair` cannot be drawn (its shape; the clips against the timeline in storyClipErrors). */ +export function validatePair(v, where = "render.chrome.pair") { + if (v === undefined) return []; + if (!isObj(v)) return [`${where} must be an object`]; + const errors = []; + unknown(v, ["style", "position", "dateFormat", "labels", "seconds", "pairs"], where, errors); + if (v.style !== undefined && !PAIR_STYLES.includes(v.style)) errors.push(`${where}.style must be ${PAIR_STYLES.map((s) => `"${s}"`).join(" or ")}`); + if (v.position !== undefined && !PAIR_POSITIONS.includes(v.position)) errors.push(`${where}.position must be "bottom" or "top"`); + if (v.dateFormat !== undefined && !DATE_FORMATS.includes(v.dateFormat)) errors.push(`${where}.dateFormat must be ${DATE_FORMATS.join(", ")}`); + if (v.seconds !== undefined && !numIn(v.seconds, ...PAIR_LIMITS.seconds)) errors.push(`${where}.seconds must be from ${PAIR_LIMITS.seconds[0]} to ${PAIR_LIMITS.seconds[1]}`); + if (v.labels !== undefined) { + if (!isObj(v.labels)) errors.push(`${where}.labels must be { then, now }`); + else { + unknown(v.labels, ["then", "now"], `${where}.labels`, errors); + for (const s of PAIR_SIDES) text(v.labels[s], PAIR_LIMITS.label, `${where}.labels.${s}`, errors); + } + } + if (v.pairs === undefined) return errors; + if (!Array.isArray(v.pairs)) return [...errors, `${where}.pairs must be a list`]; + if (v.pairs.length > PAIR_LIMITS.pairs) errors.push(`${where}.pairs has ${v.pairs.length} (at most ${PAIR_LIMITS.pairs})`); + v.pairs.forEach((p, i) => { + const w = `${where}.pairs[${i}]`; + if (!isObj(p)) { errors.push(`${w} must be { then, now, caption? }`); return; } + unknown(p, ["then", "now", "caption", "topic", "style", "also"], w, errors); + for (const s of PAIR_SIDES) { + const side = p[s]; + if (!isObj(side)) { errors.push(`${w}.${s} must be { clip, date? }`); continue; } + unknown(side, ["clip", "date", "label"], `${w}.${s}`, errors); + clip(side.clip, `${w}.${s}.clip`, errors); + date(side.date, `${w}.${s}.date`, errors); + text(side.label, PAIR_LIMITS.label, `${w}.${s}.label`, errors); + } + text(p.caption, PAIR_LIMITS.caption, `${w}.caption`, errors); + text(p.topic, PAIR_LIMITS.topic, `${w}.topic`, errors); + if (p.style !== undefined && !PAIR_STYLES.includes(p.style)) errors.push(`${w}.style must be ${PAIR_STYLES.map((s) => `"${s}"`).join(" or ")}`); + if (p.also !== undefined) { + if (!Array.isArray(p.also) || p.also.length > PAIR_LIMITS.also) errors.push(`${w}.also must be a list of at most ${PAIR_LIMITS.also} { clip, side, date? }`); + else p.also.forEach((a, j) => { + const aw = `${w}.also[${j}]`; + if (!isObj(a)) { errors.push(`${aw} must be { clip, side, date? }`); return; } + unknown(a, ["clip", "side", "date"], aw, errors); + clip(a.clip, `${aw}.clip`, errors); + if (!PAIR_SIDES.includes(a.side)) errors.push(`${aw}.side must be "then" or "now"`); + date(a.date, `${aw}.date`, errors); + }); + } + }); + return errors; +} + +/** Every reason `render.chrome.chapter` cannot be drawn. */ +export function validateChapter(v, where = "render.chrome.chapter") { + if (v === undefined) return []; + if (!isObj(v)) return [`${where} must be an object`]; + const errors = []; + unknown(v, ["seconds", "style", "list"], where, errors); + if (v.seconds !== undefined && !numIn(v.seconds, ...CHAPTER_LIMITS.seconds)) errors.push(`${where}.seconds must be from ${CHAPTER_LIMITS.seconds[0]} to ${CHAPTER_LIMITS.seconds[1]}`); + if (v.style !== undefined && !CHAPTER_STYLES.includes(v.style)) errors.push(`${where}.style must be "card" or "lower"`); + if (v.list === undefined) return errors; + if (!Array.isArray(v.list)) return [...errors, `${where}.list must be a list`]; + if (v.list.length > CHAPTER_LIMITS.list) errors.push(`${where}.list has ${v.list.length} (at most ${CHAPTER_LIMITS.list})`); + const seen = new Set(); + v.list.forEach((c, i) => { + const w = `${where}.list[${i}]`; + if (!isObj(c)) { errors.push(`${w} must be { at, title, subtitle?, date? }`); return; } + unknown(c, ["at", "title", "subtitle", "date"], w, errors); + clip(c.at, `${w}.at`, errors); + if (seen.has(c.at)) errors.push(`${w}.at: ${c.at} already opens a chapter`); + seen.add(c.at); + text(c.title, CHAPTER_LIMITS.title, `${w}.title`, errors, { required: true }); + text(c.subtitle, CHAPTER_LIMITS.subtitle, `${w}.subtitle`, errors); + date(c.date, `${w}.date`, errors); + }); + return errors; +} + +function statusSide(v, where, errors) { + if (v === undefined) return; + if (typeof v === "string") { text(v, STATUS_LIMITS.text, where, errors); return; } + if (!isObj(v)) { errors.push(`${where} must be words or { clip?, date?, text? }`); return; } + unknown(v, ["clip", "date", "text"], where, errors); + if (v.clip !== undefined) clip(v.clip, `${where}.clip`, errors); + date(v.date, `${where}.date`, errors); + text(v.text, STATUS_LIMITS.text, `${where}.text`, errors); +} + +/** Every reason `render.chrome.status` cannot be drawn. */ +export function validateStatus(v, where = "render.chrome.status") { + if (v === undefined) return []; + if (!isObj(v)) return [`${where} must be an object`]; + const errors = []; + unknown(v, ["title", "position", "rows", "width", "mode", "items"], where, errors); + text(v.title, STATUS_LIMITS.title, `${where}.title`, errors); + if (v.position !== undefined && !STATUS_POSITIONS.includes(v.position)) errors.push(`${where}.position must be ${STATUS_POSITIONS.join(", ")}`); + if (v.mode !== undefined && !STATUS_MODES.includes(v.mode)) errors.push(`${where}.mode must be "fill" or "each"`); + if (v.rows !== undefined && !(Number.isInteger(v.rows) && numIn(v.rows, ...STATUS_LIMITS.rows))) errors.push(`${where}.rows must be a whole number from ${STATUS_LIMITS.rows[0]} to ${STATUS_LIMITS.rows[1]}`); + if (v.width !== undefined && !(Number.isInteger(v.width) && numIn(v.width, ...STATUS_LIMITS.width))) errors.push(`${where}.width must be a whole number of pixels from ${STATUS_LIMITS.width[0]} to ${STATUS_LIMITS.width[1]}`); + if (v.items === undefined) return errors; + if (!Array.isArray(v.items)) return [...errors, `${where}.items must be a list`]; + if (v.items.length > STATUS_LIMITS.items) errors.push(`${where}.items has ${v.items.length} (at most ${STATUS_LIMITS.items})`); + v.items.forEach((it, i) => { + const w = `${where}.items[${i}]`; + if (!isObj(it)) { errors.push(`${w} must be { item, announced, outcome?, evidence? }`); return; } + unknown(it, ["item", "announced", "outcome", "evidence"], w, errors); + text(it.item, STATUS_LIMITS.item, `${w}.item`, errors, { required: true }); + statusSide(it.announced, `${w}.announced`, errors); + statusSide(it.outcome, `${w}.outcome`, errors); + if (it.evidence !== undefined) { + if (!Array.isArray(it.evidence) || it.evidence.length > STATUS_LIMITS.evidence) errors.push(`${w}.evidence must be a list of at most ${STATUS_LIMITS.evidence} clip ids`); + else it.evidence.forEach((c, j) => clip(c, `${w}.evidence[${j}]`, errors)); + } + const clips = [typeof it.announced === "object" ? it.announced?.clip : undefined, typeof it.outcome === "object" ? it.outcome?.clip : undefined, ...(it.evidence ?? [])]; + if (!clips.some((c) => typeof c === "string")) errors.push(`${w} names no clip (announced.clip, outcome.clip or evidence): it would never be shown`); + }); + return errors; +} + +/** The clips a story module's settings name, each with the path that names it. */ +export function storyClips(chrome) { + const out = []; + const c = isObj(chrome) ? chrome : {}; + (Array.isArray(c.pair?.pairs) ? c.pair.pairs : []).forEach((p, i) => { + for (const s of PAIR_SIDES) if (isObj(p?.[s])) out.push([`render.chrome.pair.pairs[${i}].${s}.clip`, p[s].clip]); + (Array.isArray(p?.also) ? p.also : []).forEach((a, j) => out.push([`render.chrome.pair.pairs[${i}].also[${j}].clip`, a?.clip])); + }); + (Array.isArray(c.chapter?.list) ? c.chapter.list : []).forEach((ch, i) => out.push([`render.chrome.chapter.list[${i}].at`, ch?.at])); + (Array.isArray(c.status?.items) ? c.status.items : []).forEach((it, i) => { + for (const s of ["announced", "outcome"]) if (isObj(it?.[s]) && it[s].clip !== undefined) out.push([`render.chrome.status.items[${i}].${s}.clip`, it[s].clip]); + (Array.isArray(it?.evidence) ? it.evidence : []).forEach((e, j) => out.push([`render.chrome.status.items[${i}].evidence[${j}]`, e])); + }); + return out.filter(([, id]) => typeof id === "string"); +} + +/** + * The clips the story modules name that the timeline does not hold: a + * sentence each. What a writer refuses with (a chapter at a clip that is not + * in the cut would never be drawn). The build tolerates them -- a variant or + * an --only build plays fewer clips -- and draws what is there. + */ +export function storyClipErrors(manifest) { + const ids = new Set((manifest?.timeline ?? []).map((e) => e?.id)); + return storyClips(manifest?.render?.chrome) + .filter(([, id]) => !ids.has(id)) + .map(([where, id]) => `${where}: no timeline entry is ${id}`); +} diff --git a/umtool/report-to-video/modules/story.test.mjs b/umtool/report-to-video/modules/story.test.mjs @@ -0,0 +1,143 @@ +// The story modules -- pair, chapter, status: their settings, schedules, +// pages and frame keys, over a synthetic deck schedule. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { frameKeys } from "../frame-keys.mjs"; +import { chapterHtml, chapterWindows, pairHtml, pairSchedule, statusHtml, statusRows, statusStates } from "../chrome-story.mjs"; +import { validateChrome } from "../deck.mjs"; +import { moduleById, moduleProblems } from "./index.mjs"; +import { storyClipErrors, validateChapter, validatePair, validateStatus } from "./story-settings.mjs"; + +const FPS = 30; +const segs = [["a", 0, 10], ["b", 10, 20], ["c", 20, 30], ["d", 30, 45]]; +const schedule = { + kind: "deck", fps: FPS, total: 45, transition: 0.5, + segments: segs.map(([id, start, end]) => ({ id, type: "clip", start, end, duration: end - start, title: id, subtitle: "" })), +}; +const palette = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; +const render = (chrome) => ({ width: 1920, height: 1080, fps: FPS, palette, chrome: { engine: "hyperframes", layout: "deck", ...chrome } }); + +const PAIR = { pairs: [ + { then: { clip: "a", date: "2012-09-29" }, now: { clip: "b", date: "2026-02-27" }, caption: "The same opening, renamed.", topic: "How he opens" }, + { then: { clip: "c", date: "2019" }, now: { clip: "zz", date: "2026-03" }, caption: "Only the then-clip is in this cut." }, +] }; +const CHAPTER = { list: [{ at: "a", title: "Indy", subtitle: "Labrador" }, { at: "c", title: "Huck", date: "2020-10" }, { at: "nope", title: "Gone" }] }; +const STATUS = { items: [ + { item: "Wizards of the Coast", announced: { clip: "a", date: "2017-12-08" }, outcome: { clip: "c", date: "2018-01-04", text: "decided not to sue" }, evidence: ["a", "b", "c"] }, + { item: "CNET", announced: { clip: "b", date: "2019-06-03" }, outcome: "no follow-up found in the archive", evidence: ["b"] }, +] }; + +test("settings: the shapes the module configs use are accepted, mistakes refused", () => { + assert.deepEqual(validatePair(PAIR), []); + assert.deepEqual(validateChapter(CHAPTER), []); + assert.deepEqual(validateStatus(STATUS), []); + assert.match(validatePair({ pairs: [{ then: { clip: "a", date: "Sept 2012" }, now: { clip: "b" } }] }).join(), /date/); + assert.match(validatePair({ style: "diagonal" }).join(), /style/); + assert.match(validateChapter({ list: [{ at: "a" }] }).join(), /title is required/); + assert.match(validateChapter({ list: [{ at: "a", title: "x" }, { at: "a", title: "y" }] }).join(), /already opens/); + assert.match(validateStatus({ items: [{ item: "x", announced: "words only" }] }).join(), /names no clip/); + assert.match(validateStatus({ items: [], rows: 12 }).join(), /rows/); +}); + +test("validateChrome takes the three keys, and refuses through them", () => { + assert.deepEqual(validateChrome(render({ pair: PAIR, chapter: CHAPTER, status: STATUS }).chrome, render({})), []); + assert.match(validateChrome(render({ chapter: { list: [{ at: "a" }] } }).chrome, render({})).join(), /chapter\.list\[0\]\.title/); + const problems = moduleProblems({ render: render({ status: { items: [{ item: "x" }] } }) }); + assert.ok(problems.status?.length); +}); + +test("storyClipErrors names clips the timeline does not hold", () => { + const m = { timeline: [{ id: "a" }, { id: "b" }, { id: "c" }], render: render({ pair: PAIR, chapter: CHAPTER }) }; + const errs = storyClipErrors(m); + assert.ok(errs.some((e) => e.includes("zz"))); + assert.ok(errs.some((e) => e.includes("nope"))); + assert.equal(errs.length, 2); +}); + +test("pair: a pair is up over its clips, each side lit while its clip plays", () => { + const r = render({ pair: PAIR }); + const ps = pairSchedule(schedule, r); + assert.equal(ps.length, 2); + assert.deepEqual(ps[0].spans, [{ in: 0, out: 20 }]); + assert.deepEqual(ps[0].phases.map((p) => p.side), ["then", "now"]); + assert.deepEqual(ps[1].phases.map((p) => p.side), ["then"]); + const { html, items } = pairHtml(schedule, r, {}); + assert.match(html, /29 Sep 2012/); + assert.match(html, /Feb 2026/); + assert.equal(items.length, 2); + for (const it of items) assert.ok(html.includes(it.html)); + assert.ok(moduleById("pair").on(schedule, r)); + assert.ok(!moduleById("pair").on(schedule, render({}))); +}); + +test("pair: then→now draws a card over the pair's first seconds", () => { + const r = render({ pair: { ...PAIR, style: "then→now", seconds: 3 } }); + const { html } = pairHtml(schedule, r, {}); + assert.match(html, /class="arrow"/); +}); + +test("pair frame keys: frames off a pair's span share a key; a caption changed recaptures only its pair's frames", () => { + const r = render({ pair: PAIR }); + const frames = 45 * FPS; + const keysOf = (rr) => { + const { html, items } = pairHtml(schedule, rr, {}); + return frameKeys({ html, region: "pair", fps: FPS, frames, version: "t", items }); + }; + const a = keysOf(r); + assert.ok(a, "the page is modelled"); + const changed = structuredClone(PAIR); + changed.pairs[1].caption = "Changed."; + const b = keysOf(render({ pair: changed })); + const diff = a.map((k, i) => (k !== b[i] ? i : -1)).filter((i) => i >= 0); + assert.ok(diff.length > 0); + // Pair 1 is up over clip c only (20–30 s): nothing before 20 s changes. + assert.ok(diff.every((i) => i / FPS >= 19.9 && i / FPS <= 30.1), `frames ${diff[0]}..${diff[diff.length - 1]}`); +}); + +test("chapter: a window per chapter the cut plays, its page keyed from its offset", () => { + const r = render({ chapter: CHAPTER }); + const w = chapterWindows(schedule, r); + assert.deepEqual(w.map((x) => [x.segment, x.from, x.to]), [["a", 0, 3], ["c", 20, 23]]); + const mod = moduleById("chapter"); + const regions = mod.regions(schedule, { render: r, outDir: "/tmp/x" }); + assert.equal(regions.length, 2); + assert.equal(regions[1].offset, 20); + assert.equal(regions[1].frameCount, 90); + const win = mod.window(schedule, { segment: "c", fps: FPS, total: 45, render: r }); + const html = chapterHtml(schedule, r, win, {}); + assert.match(html, /Huck/); + assert.match(html, /Oct 2020/); + const fk = frameKeys({ html, region: "chapter", fps: FPS, frames: 90, version: "t" }); + assert.ok(fk && fk.length === 90); + // A clip's window from the build: only the ones it intersects. + assert.equal(mod.regions(schedule, { render: r, outDir: "/tmp/x", clip: { at: 15, dur: 10 }, shift: 15 })[0].offset, 5); +}); + +test("status: rows come in on their first clip, outcomes fill on theirs", () => { + const r = render({ status: STATUS }); + const rows = statusRows(schedule, r); + assert.deepEqual(rows.map((x) => [x.item, x.in, x.done]), [["Wizards of the Coast", 0, 20], ["CNET", 10, 20]]); + const states = statusStates(schedule, r); + assert.deepEqual(states.map((s) => [s.at, s.rows.length, s.rows.filter((x) => x.filled).length]), [[0, 1, 0], [10, 2, 0], [20, 2, 2]]); + const each = statusStates(schedule, render({ status: { ...STATUS, mode: "each" } })); + assert.ok(each.every((s) => s.rows.length === 1)); + const { html, items } = statusHtml(schedule, r, {}); + assert.match(html, /decided not to sue/); + assert.match(html, /no follow-up found/); + const fk = frameKeys({ html, region: "status", fps: FPS, frames: 45 * FPS, version: "t", items }); + assert.ok(fk); + // Nothing changes between two events: frames 31..299 share frame 31's key (after the fade in). + assert.equal(new Set(fk.slice(31, 299)).size, 1); +}); + +test("the three modules are registered, documented and carry a generic-panel descriptor", () => { + for (const id of ["pair", "chapter", "status"]) { + const m = moduleById(id); + assert.ok(m, id); + assert.ok(Array.isArray(m.ui) && m.ui.length >= 3, `${id} ui`); + assert.ok(m.docs?.rows?.length, `${id} docs`); + assert.equal(typeof m.preview, "function"); + assert.ok(m.frameKeys); + } +});