// The deck's FINALE composition (finale.mjs): one full-frame HyperFrames page // over the window the schedule's `finale` covers -- the cut's last clips with // the timeline in primary view. // // PURE, like chrome-deck.mjs: a schedule and a render block in, an HTML string // out. compose-chrome.mjs copies the assets in beside it, writes it and renders // it (`region: "finale"`); the build lays its frames over the cut at the // window's second, last, over every other region. // // What it draws: the footer's rail redrawn large across the top (every pip // lit, the fuse burnt through, the markers flagged, each pip's label and // date), the tally's final counts large under it, the author's stats cards, // and -- around the box the clip has moved into (the build's footage move, // deck.mjs `finaleSchedule`) -- the frame's ground, the clip's title, source // line and QR. With `video: "hidden"` the ground covers the footage whole. // // "grow": every piece starts where the footer drew it -- the track, each pip, // each flag, each tally cell, the QR -- and travels to its place over // FINALE_MOTION.grow, while the ground's hole shrinks with the footage on the // same smoothstep the move's perspective filter uses, so picture and hole // never part. "cut": the page dissolves in at its first second, everything // in place. Either way the page fades out through the dissolve after the run. // // The timeline is cues, each stating its from (chrome-deck.mjs says why). import { cueTime, cueTimeAfter, finaleRail, pageDuration, railDrawn, railOffStyle, resolveDeck } from "./deck.mjs"; import { finaleClaimsMarkup } from "./chrome-claims.mjs"; import { mix, rgba, scheduleHasStatus, shapeCss, statusFitScript, statusPartCss, subtitleMarkup, subtitlePartsCss, subtitleTokens } from "./chrome-deck.mjs"; import { resolveFactcheck, tallyCells, tallyFinals, tallyOf } from "./factcheck.mjs"; import { settleFirstFrame } from "./cue-start.mjs"; import { resolveCounter } from "./counter.mjs"; import { aboveTop, FINALE_CLAIMS, FINALE_MOTION, finaleGeometry, resolveFinale } from "./finale.mjs"; /** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ const INSTANT = 0.001; /** The hole's ground reaches this far past the clip's box -- past the frame's far edge at any scale it is drawn at. */ const HOLE_REACH = 8000; const esc = (s) => String(s ?? "") .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); const r2 = (v) => Math.round(v * 100) / 100; const r4 = (v) => Math.round(v * 10000) / 10000; /** A colour a stat or marker names: a hex, or a palette key. */ const colorOf = (key, pal, fallback) => (typeof key === "string" && /^#/.test(key) ? key : pal[key] ?? fallback); /** * Everything the finale page draws and where, frame px -- the large rail's * pips, labels and flags, the totals' cells, the stats' cards, the clip's * captions and QR -- and where the footer drew each piece the "grow" starts * from. Pure; the tests read the legibility floors off it. */ export function finaleLayout(schedule, render) { const fin = schedule.finale; if (!fin) throw new Error("finale: the schedule has no finale (no entry with layout \"finale\")"); const f = resolveFinale(render); const deck = resolveDeck(render); const fc = resolveFactcheck(render); const pal = render.palette; const stamps = schedule.factcheck?.stamps ?? []; const counter = resolveCounter(render); const verdicts = f.totals && stamps.length ? tallyCells(stamps, render) : []; // The large rail (deck.mjs finaleRail): in the room the schedule gave it. const R = finaleRail(schedule, render, { railBottom: fin.railBottom ?? finaleGeometry(render).rail.bottom, textScale: fin.textScale ?? 1 }); const { geo, x0, labels, marks, claims, lay, fxs, footSize } = R; const { rail } = geo; const deckY = geo.H - lay.height; const footV = Math.max(footSize, Math.round((footSize * 5) / 3)); const pips = R.pips.map((p, k) => ({ ...p, foot: { x: r2(fxs[k]), size: p.verdict ? footV : footSize } })); const verdictColors = fc.verdicts; const finSet = new Set(fin.segments); const tally = tallyOf(schedule, render); // The totals: the tally's verdicts, each at its final count. const finals = tallyFinals(stamps, counter.order); const tb = lay.tally ?? null; const T = geo.totals; const totals = T ? verdicts.map((v, j) => ({ verdict: v, count: finals[v], label: verdictColors[v]?.label ?? v, color: verdictColors[v]?.color ?? pal.accent, shape: counter.shapes[v], x: T.x + j * (T.cell + T.gap), y: T.y, width: T.cell, height: T.height, ...(tb && tally?.[j] === v ? { foot: { x: tb.x + j * (tb.cell + tb.gap), y: deckY + tb.y, width: tb.cell, height: tb.height } } : {}), })) : []; const S = geo.stats; const stats = S ? f.stats.map((s, j) => ({ ...s, color: colorOf(s.color, pal, pal.fg), x: S.x + (j % S.cols) * (S.cardW + S.gap), y: S.y + S.titleH + Math.floor(j / S.cols) * (S.cardH + S.gap), width: S.cardW, height: S.cardH, })) : []; const panel = { bottom: rail.bottom + 12 }; const segs = schedule.segments.filter((s) => finSet.has(s.id)); const captions = segs.map((s) => ({ id: s.id, start: s.start, title: s.title, subtitle: s.subtitle, qrUrl: s.qrUrl ?? null, // The automatic line's parts by token (deck.mjs deckText), so the date and the clock stay whole here too. ...(Array.isArray(s.subtitleParts) ? { subtitleParts: s.subtitleParts } : {}), // Only in a two-line subtitle (deck.mjs deckText), so a finale without one is what it was. ...(Array.isArray(s.subtitleLines) && lay.text.lines === 2 ? { subtitleLines: s.subtitleLines } : {}), ...(Array.isArray(s.subtitleLinesParts) && Array.isArray(s.subtitleLines) && lay.text.lines === 2 ? { subtitleLinesParts: s.subtitleLinesParts } : {}), })); return { geo, rail: { ...rail, x0, track: { x0, x1: rail.x1, y: R.Y } }, foot: { y: deckY, track: { x0: lay.pipTrack.x0, x1: lay.pipTrack.x1, y: deckY + lay.pipTrack.y }, qr: lay.qr ? { ...lay.qr, y: deckY + lay.qr.y } : null, // The deck's ground and its first finale clip's words, where it drew // them: what "grow" takes over from (chrome-deck.mjs's colours). ground: { height: lay.height, top: deck.background === "panel" ? mix(pal.bg, pal.fg, 0.095) : pal.bg, bottom: deck.background === "panel" ? mix(pal.bg, pal.fg, 0.04) : pal.bg, plateX: deck.background === "panel" && lay.qr ? lay.qr.x - 46 : null, }, text: { ...lay.text, titleY: deckY + lay.text.titleY, subtitleY: deckY + lay.text.subtitleY, ruleY: deckY + lay.text.ruleY }, }, // `sections` / `none`: no pip's label or date on the rail. pips, labels: f.railLabels === "sections" || f.railLabels === "none" ? { ...labels, groups: [], lead: 0 } : labels, marks, totals, stats, captions, panel, ...(claims ? { claims } : {}), statsTitle: f.statsTitle, railLabels: f.railLabels, video: f.video, motion: f.motion, box: fin.box ?? null, footage: fin.footage, }; } /** * Everything the finale page's timeline does, as data, in the cut's clock: * `init` (t = the window's first second) and `cues` in time order, each with * its from -- chrome-deck.mjs `deckCues`'s contract. */ export function finaleCues(schedule, render, L = finaleLayout(schedule, render)) { const fin = schedule.finale; const D = schedule.transition ?? 0; const A = fin.at; const G = fin.grow > 0 ? fin.grow : 0; const grow = L.motion === "grow" && G > 0; const R = A + G; const m = FINALE_MOTION; const init = {}; const put = (k, v) => { init[k] = { ...(init[k] ?? {}), ...v }; }; const ev = []; // Cue times on the sub-frame grid (deck.mjs cueTime), durations to 4 places. const fps = Number(schedule.fps ?? render.fps ?? 30); const add = (k, at, dur, to, ease, why) => ev.push({ k, at: cueTime(at, fps), dur: r4(Math.max(INSTANT, dur)), to, ease, why }); const ft = L.foot.track, bt = L.rail.track; // From a rect the footer drew to this one: a uniform scale, centres matched // (the element's transform-origin is its top-left). const fromRect = (F, B) => { const s = Math.min(F.width / B.width, F.height / B.height); return { x: r2(F.x + F.width / 2 - (B.width * s) / 2 - B.x), y: r2(F.y + F.height / 2 - (B.height * s) / 2 - B.y), scale: r4(s) }; }; const travel = (k, from, why) => { if (grow) { put(k, from); add(k, A, G, Object.fromEntries(Object.keys(from).map((p) => [p, p.startsWith("scale") || p === "opacity" ? 1 : 0])), "power3.inOut", why); } else put(k, Object.fromEntries(Object.keys(from).map((p) => [p, p.startsWith("scale") || p === "opacity" ? 1 : 0]))); }; // At rest: a scale is 1, an offset 0. const rest = (extra) => Object.fromEntries(Object.keys(extra).map((p) => [p, p.startsWith("scale") ? 1 : 0])); const reveal = (k, at, why, extra = {}) => { if (grow) { put(k, { opacity: 0, ...extra }); add(k, at, m.reveal, { opacity: 1, ...rest(extra) }, "power2.out", why); } else put(k, { opacity: 1, ...rest(extra) }); }; // The stage: "cut" dissolves it in at the run's start; either way it leaves // through the dissolve after the run. if (grow) put("stage", { opacity: 1 }); else { put("stage", { opacity: 0 }); add("stage", fin.start, D, { opacity: 1 }, "power1.inOut", "finale in"); } if (fin.out) add("stage", fin.out[0], fin.out[1] - fin.out[0], { opacity: 0 }, "power1.inOut", "finale out"); // The ground: around the clip's box (its hole shrinks with the footage on // the move's smoothstep), or over everything when the clip is heard only. if (L.box) { const B = L.box, F = L.footage; if (grow) { put("hole", { x: r2(F.x - B.x), y: r2(F.y - B.y), scaleX: r4(F.width / B.width), scaleY: r4(F.height / B.height) }); add("hole", A, G, { x: 0, y: 0, scaleX: 1, scaleY: 1 }, "smoothstep", "finale hole"); put("veil", { opacity: 0 }); add("veil", A, fin.cover - A, { opacity: 1 }, "power1.inOut", "finale ground"); } else { put("hole", { x: 0, y: 0, scaleX: 1, scaleY: 1 }); put("veil", { opacity: 1 }); } reveal("frame", R, "finale frame"); } else if (grow) { put("ground", { opacity: 0 }); add("ground", A, fin.cover - A, { opacity: 1 }, "power1.inOut", "finale ground"); } else put("ground", { opacity: 1 }); // The rail's panel once the footage has left it. reveal("panel", Math.max(A, R - 0.1), "finale panel"); // "grow": the deck's ground and words where it stood (it went at `at`): // the ground sinks and fades as the pieces rise, the words go first. if (grow) { put("dg", { opacity: 1, y: 0 }); add("dg", A, G * 0.6, { opacity: 0, y: 40 }, "power2.in", "finale deck ground"); put("dt", { opacity: 1 }); add("dt", A, 0.2, { opacity: 0 }, "power1.out", "finale deck words"); } // The rail: track, fuse and pips from the footer's track. const bw = bt.x1 - bt.x0; travel("track", { x: r2(ft.x0 - bt.x0), y: r2(ft.y - bt.y), scaleX: r4((ft.x1 - ft.x0) / bw), scaleY: 0.5 }, "finale rail"); const p0 = L.pips[0], pn = L.pips[L.pips.length - 1]; if (L.pips.length > 1) { const fw = pn.x - p0.x; travel("fuse", { x: r2(p0.foot.x - p0.x), y: r2(ft.y - bt.y), scaleX: r4((pn.foot.x - p0.foot.x) / fw), scaleY: 0.5 }, "finale rail"); } L.pips.forEach((p, k) => { travel(`p${k}`, { x: r2(p.foot.x - p.x), y: r2(ft.y - bt.y), scale: r4(p.foot.size / p.size) }, `finale pip ${p.id}`); if (p.here) reveal(`ring${k}`, R, `finale here ${p.id}`, { scale: 0.6 }); }); L.marks.forEach((mk, j) => { travel(`mk${j}`, { x: r2(mk.foot.x - mk.x), y: r2(ft.y - bt.y), scale: 0.4 }, "finale marker"); if (L.railLabels === "all" || L.railLabels === "sections") reveal(`ml${j}`, R + j * m.stagger, "finale marker label"); }); // The claim checks, once the rail is in place: all at once, or ("rotate") // each in its slot, crossfading into the next at the slot's edge. const rotate = L.claims?.mode === "rotate"; const half = FINALE_CLAIMS.fade / 2; (L.claims?.items ?? []).forEach((it, j, all) => { const k = `fq${it.j}`; if (!rotate || j === 0) reveal(k, R + 0.15 + (rotate ? 0 : j * m.stagger), "finale claim"); if (!rotate) return; const [a, b] = L.claims.slots[j]; if (j > 0) { put(k, { opacity: 0 }); add(k, a - half, FINALE_CLAIMS.fade, { opacity: 1 }, "power1.inOut", `finale claim ${j} in`); } if (j < all.length - 1) add(k, b - half, FINALE_CLAIMS.fade, { opacity: 0 }, "power1.inOut", `finale claim ${j} out`); }); L.labels.groups.forEach((g, j) => { reveal(`pl${j}`, R + 0.05 + j * (m.stagger / 2), "finale label"); if (L.labels.lead) reveal(`ld${j}`, R + 0.05 + j * (m.stagger / 2), "finale label"); if (g.to > g.from) reveal(`sp${j}`, R, "finale span"); }); // The totals: each cell from the footer tally's cell, else in. L.totals.forEach((c, j) => { if (c.foot) travel(`tc${j}`, fromRect(c.foot, c), `finale total ${c.verdict}`); else reveal(`tc${j}`, A + G * 0.5, `finale total ${c.verdict}`, { y: 24 }); }); if (L.statsTitle) reveal("stt", R, "finale stats title"); L.stats.forEach((s, j) => reveal(`sc${j}`, R + 0.1 + j * m.stagger, "finale stat", { y: 24 })); // The clip's caption and QR: the first from the footer's QR; each later // finale clip's at its mid-dissolve. L.captions.forEach((c, i) => { if (i === 0) { reveal(`cap${i}`, A + G * 0.6, "finale caption"); if (L.foot.qr && c.qrUrl) { const q = L.geo.qr; travel(`qr${i}`, fromRect({ x: L.foot.qr.x, y: L.foot.qr.y, width: L.foot.qr.size, height: L.foot.qr.size }, { x: q.x, y: q.y, width: q.size, height: q.size }), "finale qr"); } else reveal(`qr${i}`, A + G * 0.6, "finale qr"); return; } const mid = c.start + D / 2; put(`cap${i}`, { autoAlpha: 0 }); put(`qr${i}`, { autoAlpha: 0 }); add(`cap${i - 1}`, mid, INSTANT, { autoAlpha: 0 }, "none", `finale caption ${c.id}`); add(`qr${i - 1}`, mid, INSTANT, { autoAlpha: 0 }, "none", `finale caption ${c.id}`); add(`cap${i}`, mid, INSTANT, { autoAlpha: 1 }, "none", `finale caption ${c.id}`); add(`qr${i}`, mid, INSTANT, { autoAlpha: 1 }, "none", `finale caption ${c.id}`); }); // Order, clamp per element, state the froms (deckCues' walk). ev.forEach((e, n) => { e.n = n; }); ev.sort((x, y) => x.at - y.at || x.n - y.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) ?? -Infinity; if (at < free) { const end = at + dur; at = cueTimeAfter(free, fps); 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] ?? (p.startsWith("scale") || p === "opacity" || p === "autoAlpha" ? 1 : 0); Object.assign(cur, e.to); freeAt.set(e.k, at + dur); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } return { init, cues: settleFirstFrame(init, cues, fps) }; } /** * The finale page's HTML, for its window (`window` = compose-chrome's * `snapWindow` of the schedule's `finale.from`–`to`; frame 1 is cut time * `window.from`). `fonts` = `{ regular, bold }`, `qrSrcs` = `{ [segmentId]: * "assets/qrNN.png" }`, `gsap` = the vendored script's asset path. */ /** * The clip card's source line with the source's TITLE last ("TheQuartering (Rumble) · Nov 3, 2026 · 13:48 · * Democrats PANIC …"): wrapped to two lines, only the title's end is ever clamped -- never the date or the clock * (rev 9: "Democrats PANIC … · N… · 13:48"). */ export function titleLast(subtitle) { const parts = String(subtitle ?? "").split(" · "); if (parts.length < 3) return String(subtitle ?? ""); return [parts[0], ...parts.slice(2), parts[1]].join(" · "); } /** * `titleLast` by token, for the automatic line (deck.mjs deckText's * `subtitleParts`): the title part moved to the end, the others in order -- * whichever position the title stood at (a line of fewer than three parts as it is). null for a typed line * (subtitleTokens). * * @returns {Array<[string, string]> | null} */ export function titleLastParts(subtitle, tokens) { const tok = subtitleTokens(subtitle, tokens); if (!tok) return null; // As titleLast: a line of one or two parts stays in its order. if (tok.length < 3) return tok; return [...tok.filter(([k]) => k !== "title"), ...tok.filter(([k]) => k === "title")]; } export function finaleHtml(schedule, render, window, opts = {}) { const L = finaleLayout(schedule, render); const { init, cues } = finaleCues(schedule, render, L); // A line carries the source status: only then does the page add its rule and its fit (status-fit.mjs). const hs = scheduleHasStatus(schedule); const pal = render.palette; const g = L.geo; const W = g.W, H = g.H; const fonts = opts.fonts ?? {}; const qrSrcs = opts.qrSrcs ?? {}; const gsapSrc = opts.gsap ?? "assets/gsap.min.js"; const from = Number(window.from); const dur = r4(Number(window.to) - from); if (!(dur > 0)) throw new Error("finale: the window is empty"); const fps = schedule.fps ?? render.fps ?? 30; const rail = L.rail; const Y = rail.track.y; const panelTop = mix(pal.bg, pal.fg, 0.06); const panelBottom = mix(pal.bg, pal.fg, 0.025); const hole = L.box ? `