commit 964c06d2b7172368b9f3f8e534b8ab9d0e847e68 parent e027f701ec5ddc8ef57e24091a8138ca088d41da Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Wed, 21 Oct 2026 22:32:11 -0400 deck: stamps off with the tally counting, no QR on post cards, verdict pips, track markers render.chrome.factcheck.stamp.show false renders and lays no stamp region (build, verify, compose, preview) while the tally steps at each stamp's landed second. deck.posts.qr false drops the code and its cell from popup and feed cards. deck.pip.color "verdict" lights a claimed pip in its verdict's colour and shape, the tally cell carrying the same shape. deck.markers flags the pip track after a clip, popping in as the fuse reaches it; validateDeckMarkers checks them against the timeline for the build, the lint and umtool's writers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Diffstat:
15 files changed, 681 insertions(+), 53 deletions(-)
diff --git a/umtool/app/api/report/chrome/preview/route.ts b/umtool/app/api/report/chrome/preview/route.ts @@ -13,7 +13,7 @@ import { deckPreviewSrc, feedPreviewSrc, postsPreviewSrc, resolveReport, stampPr import { deckGeometry, deckLayout, deckOn, feedGeometry, postsGeometry, stampGeometry, validateChrome, } from "umtool-report-to-video/deck"; -import { tallyOf } from "umtool-report-to-video/factcheck"; +import { stampsDrawn, tallyOf } from "umtool-report-to-video/factcheck"; export const dynamic = "force-dynamic"; @@ -123,11 +123,11 @@ export async function POST(request: Request) { }; } - // The fact-check stamps, when the cut stamps a claim -- over the footage, - // so not on the clip bench's strip either. - const stamps = (schedule as { factcheck?: { stamps?: unknown[] } }).factcheck?.stamps ?? []; + // The fact-check stamps, when the cut stamps a claim and they are on + // (`factcheck.stamp.show`) -- over the footage, so not on the clip bench's + // strip either. Off, the tally in the deck still counts. let stampDoc: Record<string, unknown> | null = null; - if (body.posts !== false && stamps.length) { + if (body.posts !== false && stampsDrawn(schedule, render)) { let error: string | null = null; try { await composeStampPreview(r.project, r.variant, schedule); diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -30,7 +30,7 @@ import { rolesGaps, } from "umtool-report-to-video/ledger-totals"; import { isCalendarDate } from "umtool-report-to-video/attribution"; -import { normalizeOnscreen, validateChrome, validatePosts, validateTeaser, validateTeasers } from "umtool-report-to-video/deck"; +import { normalizeOnscreen, validateChrome, validateDeckMarkers, validatePosts, validateTeaser, validateTeasers } from "umtool-report-to-video/deck"; import { validateThreadEntries } from "yt-dlp-transcript-common/lib/report/panels.mjs"; import { validateAssist } from "yt-dlp-transcript-common/lib/clips/assist.mjs"; import { verticalErrors } from "umtool-report-to-video/look"; @@ -883,6 +883,9 @@ export async function updateChrome(dir, chrome, { token = null } = {}) { const errors = validateChrome(chrome, renderWithoutChrome); if (errors.length) throw new ChromeRefused(errors); manifest.render = { ...(manifest.render ?? {}), chrome }; + // The deck's markers against the timeline: each follows a clip in it. + const markers = validateDeckMarkers(manifest); + if (markers.length) throw new ChromeRefused(markers); } const nextToken = await writeManifestAtomic(dir, manifest); @@ -1220,6 +1223,8 @@ function structureErrors(manifest) { return [ ...validatePosts(manifest.posts, manifest.timeline ?? [], manifest.render), ...validateClaims(manifest), + // The deck's markers follow clips: removing one a marker names is refused. + ...validateDeckMarkers(manifest), ...validateTeasers(manifest), ...validateNarration(manifest), ...validateDrafted(manifest), diff --git a/umtool/lib/report/manifest.test.mjs b/umtool/lib/report/manifest.test.mjs @@ -269,6 +269,31 @@ test("updateChrome: round trip stores the block as given; null removes it", asyn } }); +test("updateChrome: a deck marker must follow a clip in the timeline; nothing is written otherwise", async () => { + const dir = await project(); + try { + const before = await readRaw(dir); + const deck = (markers) => ({ engine: "hyperframes", layout: "deck", deck: { markers } }); + for (const [markers, want] of [ + [[{ after: "zz", label: "Weeks pass" }], /names zz, which is not in the timeline/], + [[{ after: "k1", label: "Weeks pass" }], /names k1, a card: a marker follows a clip/], + [[{ after: "c01", label: "x".repeat(25) }], /label is 25 characters/], + ]) { + await assert.rejects(updateChrome(dir, deck(markers)), (e) => { + assert.ok(e instanceof ChromeRefused, String(e)); + assert.ok(e.errors.some((s) => want.test(s)), `${want} in ${JSON.stringify(e.errors)}`); + return true; + }); + assert.equal(await readRaw(dir), before); + } + const ok = deck([{ after: "c01", label: "3 to 5 weeks", color: "amber" }]); + await updateChrome(dir, ok); + assert.deepEqual((await read(dir)).render.chrome, ok); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); + test("updateChrome: a manifest with no render block gets one", async () => { const m = base(); delete m.render; diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -141,11 +141,11 @@ import { assertChrome, deckGeometry, deckOn, deckSchedule, endFadeOf, feedGeometry, feedOn, frameCount, hidesDeck, MUTE_FADE, dipOf, muteSegmentSeconds, playWindow, postsGeometry, postWindows, resolveDeck, scheduleFrom, snapWindow, stampGeometry, statsGeometry, teaserHits, teaserSeconds, teaserTitle, threadsGeometry, - validateCutEdits, validatePosts, validateTeasers, fxGeometry, even as evenPx, + validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, fxGeometry, even as evenPx, } from "./deck.mjs"; // The effects region (`render.chrome.fx`, release 35): pure, in fx.mjs. import { fxOn, fxQuoteSpan, resolveFx, fxWhipJoins, fxWipeJoins, fxWordsOf, fxZoomJoins, validateFxEntries } from "./fx.mjs"; -import { validateClaims } from "./factcheck.mjs"; +import { stampsDrawn, validateClaims } from "./factcheck.mjs"; import { validateThreadEntries } from "./threads.mjs"; import { validateFlipEntries } from "./flips.mjs"; import { validateStatsEntries } from "./stats.mjs"; @@ -4634,8 +4634,9 @@ async function renderDeck({ manifestPath, render, outDir, variant, schedule, fro // The fact-check stamps (a schedule whose `factcheck` stamps a claim): one // sequence for the whole cut -- or the deck's window -- laid last, over the - // posts, at stampGeometry's box in the footage. - if (schedule.factcheck?.stamps?.length) { + // posts, at stampGeometry's box in the footage. With `stamp.show: false` + // none is composed or laid; the deck's tally still counts each claim. + if (stampsDrawn(schedule, render)) { EMIT("chrome", { phase: "compose", region: "stamp", ...(duration != null ? { from, duration } : {}) }); const t1 = Date.now(); const st = await composeChrome({ @@ -5179,6 +5180,9 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly if (deck) { const errors = validatePosts(whole.posts, whole.timeline ?? [], whole.render); if (errors.length) throw new Error(`posts: ${errors.join("; ")}`); + // The deck's markers, against the whole timeline: each follows a clip in it. + const markers = validateDeckMarkers(whole); + if (markers.length) throw new Error(`render.chrome: ${markers.join("; ")}`); } // The lint (lint.mjs): what a render would get wrong that no validator // refuses -- a picture that is not beside the manifest, a QR too small to diff --git a/umtool/report-to-video/chrome-deck.mjs b/umtool/report-to-video/chrome-deck.mjs @@ -37,8 +37,8 @@ // second clock or a label. import { fileURLToPath } from "node:url"; -import { deckChoreography, deckLayout, pageDuration, pipSegments, pipXs, resolveDeck } from "./deck.mjs"; -import { resolveFactcheck, tallyCues, tallyKey, tallyOf } from "./factcheck.mjs"; +import { deckChoreography, deckLayout, deckMarkers, pageDuration, pipSegments, pipXs, resolveDeck } from "./deck.mjs"; +import { resolveFactcheck, tallyCues, tallyKey, tallyOf, VERDICT_SHAPES } from "./factcheck.mjs"; /** * GSAP, vendored, for every chrome region. @@ -154,7 +154,11 @@ export function deckCues(schedule, render) { pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, deck.pip.spacing, deck.pip.spacing === "time" ? { total: schedule.total, segments: pipped } : null, ); - const pips = pipped.map((s, k) => ({ id: s.id, x: r4(xs[k]) })); + // `pip.color: "verdict"`: a claimed clip's pip carries its verdict (drawn + // in its colour and shape once lit). Only then, so the pips are as they + // always were otherwise. + const byVerdict = deck.pip.color === "verdict"; + const pips = pipped.map((s, k) => ({ id: s.id, x: r4(xs[k]), ...(byVerdict && s.claim?.verdict ? { verdict: s.claim.verdict } : {}) })); const pipOf = new Map(pipped.map((s, k) => [s.id, k])); const fuseX0 = xs[0] ?? 0; const fuseW = xs.length > 1 ? xs[xs.length - 1] - xs[0] : 0; @@ -269,6 +273,24 @@ export function deckCues(schedule, render) { } } + // The markers (`deck.markers`): hidden until the fuse burns past the flag + // -- it burns linearly from pip k to pip k+1 over the marker's rest on k -- + // then a short pop, lit for the rest of the cut. A flag past the last pip + // (it follows the last clip) pops in a second before that clip ends. + const markers = deckMarkers(schedule, render, xs, pipped, lay).map((mk, j) => { + const a = arrive.get(mk.k), b = depart.get(mk.k); + let at; + if (mk.k + 1 < xs.length && a !== undefined && b !== undefined && xs[mk.k + 1] > xs[mk.k]) { + at = a + ((b - a) * Math.max(0, Math.min(1, (mk.x - xs[mk.k]) / (xs[mk.k + 1] - xs[mk.k])))); + } else { + const seg = segs[idx.get(mk.after)]; + at = Math.max(seg.start, seg.start + seg.duration - Math.min(1, seg.duration / 2)); + } + put(`mk${j}`, { autoAlpha: 0, scale: MARKER_POP.from }); + add(`mk${j}`, at, MARKER_POP.seconds, { autoAlpha: 1, scale: 1 }, "back.out(2.2)", `marker ${mk.after}`); + return { ...mk, at: r4(at) }; + }); + // ---- order, clamp, and state the froms --------------------------------- ev.forEach((e, n) => { e.n = n; }); ev.sort((x, y) => x.at - y.at || x.n - y.n); @@ -290,7 +312,30 @@ export function deckCues(schedule, render) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } - return { init, cues, pips, slideY, choreography: ch }; + return { init, cues, pips, slideY, choreography: ch, ...(markers.length ? { markers } : {}) }; +} + +/** A marker's pop as the fuse reaches it: from this scale, over these seconds. */ +export const MARKER_POP = Object.freeze({ from: 0.35, seconds: 0.35 }); + +/** + * A verdict pip's shape as CSS, `size` px: a circle, a diamond (a square + * turned, shrunk to the circle's reach), a square, a triangle, a ring. + */ +function shapeCss(shape, size, color) { + const d = Math.round(size * 0.78 * 100) / 100; + switch (shape) { + case "diamond": + return `width:${d}px; height:${d}px; margin:${r4((size - d) / 2)}px; border-radius:1px; transform:rotate(45deg); background:${color};`; + case "square": + return `border-radius:1.5px; background:${color};`; + case "triangle": + return `border-radius:0; clip-path:polygon(50% 0%, 100% 92%, 0% 92%); background:${color};`; + case "ring": + return `border-radius:50%; background:transparent; box-shadow:inset 0 0 0 ${Math.max(2, Math.round(size * 0.24))}px ${color};`; + default: + return `border-radius:50%; background:${color};`; + } } // --------------------------------------------------------------------------- @@ -329,12 +374,16 @@ export function deckHtml(schedule, render, opts = {}) { if (!(dur > 0)) throw new Error(`deck: nothing to render from ${from}s of a ${total}s cut`); const windowed = from > 0 || Math.abs(dur - total) > 1e-6; - const { init, cues, pips } = deckCues(schedule, render); + const { init, cues, pips, markers = [] } = deckCues(schedule, render); const t = lay.text; const tr = lay.pipTrack; const qr = lay.qr; const pip = deck.pip; const panel = deck.background === "panel"; + // The verdicts' colours as the tally draws them (relabels and recolours + // included), so a claimed pip and its tally cell are the same colour. + const verdictColors = resolveFactcheck(render).verdicts; + const byVerdict = pip.color === "verdict"; // The lift: a few percent toward the foreground, so the deck reads as a // surface standing on the frame's ground rather than a hole cut in it. @@ -370,12 +419,33 @@ export function deckHtml(schedule, render, opts = {}) { }) .join("\n "); + // A verdict pip is drawn a little larger than a plain one, so its shape + // reads; the active marker still covers it. + const vSize = Math.max(pip.size, Math.round((pip.size * 5) / 3)); const pipHtml = pips - .map( - (p, k) => - `<div class="pip" style="left:${r4(p.x - pip.size / 2)}px"></div>` + - `<div class="pip lit" data-k="pip${k}" style="left:${r4(p.x - pip.size / 2)}px"></div>`, - ) + .map((p, k) => { + const base = `<div class="pip" style="left:${r4(p.x - pip.size / 2)}px"></div>`; + if (!p.verdict) return base + `<div class="pip lit" data-k="pip${k}" style="left:${r4(p.x - pip.size / 2)}px"></div>`; + const color = verdictColors[p.verdict]?.color ?? pal.accent; + return ( + base + + `<div class="pip lit vpip" data-k="pip${k}" data-verdict="${esc(p.verdict)}" data-shape="${VERDICT_SHAPES[p.verdict]}" ` + + `style="left:${r4(p.x - vSize / 2)}px; top:${r4(-vSize / 2)}px; width:${vSize}px; height:${vSize}px; ` + + `${shapeCss(VERDICT_SHAPES[p.verdict], vSize, esc(color))}"></div>` + ); + }) + .join(""); + // The markers: a flag on the track and its label in the band above it. + const band = lay.markerBand ?? null; + const markerHtml = markers + .map((mk, j) => { + const left = r4(mk.box[0] - mk.x); + return ( + `<div class="mflag" data-k="mk${j}" data-after="${esc(mk.after)}" style="left:${r4(mk.x)}px; --mc:${esc(mk.color)}">` + + `<div class="mstick"></div><div class="mhead"></div>` + + `<div class="mlabel" style="left:${left}px; width:${mk.box[1] - mk.box[0]}px">${esc(mk.label)}</div></div>` + ); + }) .join(""); // The tally: one cell per verdict the cut stamps, each with every count it // will show stacked in one box (`n0` … `n<final>`), its label under it. @@ -399,7 +469,11 @@ export function deckHtml(schedule, render, opts = {}) { `style="left:${j * (tb.cell + tb.gap)}px; --vc:${esc(color)}; --vg:${rgba(color, 0.55)}; --vr:${rgba(color, 0.4)}; ` + `--vl:${mix(color, pal.fg, 0.35)}">` + `<div class="tbar"></div><div class="tcount">${nums}</div>` + - `<div class="tlabel">${esc(verdictSet[v].label)}</div>` + + // With verdict pips the cell carries its pip's shape too: the key + // a viewer who cannot tell the colours apart reads the rail by. + `<div class="tlabel">${byVerdict + ? `<span class="tshape" data-shape="${VERDICT_SHAPES[v]}" style="${shapeCss(VERDICT_SHAPES[v], 10, esc(color))}"></span>` + : ""}${esc(verdictSet[v].label)}</div>` + `<div class="tflash" data-k="${tallyKey(v, "flash")}"></div></div>` ); }) @@ -531,7 +605,17 @@ export function deckHtml(schedule, render, opts = {}) { letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--vl); } .tflash { position: absolute; inset: 0; border-radius: 8px; opacity: 0; pointer-events: none; - box-shadow: inset 0 0 0 2px var(--vc), inset 0 0 22px var(--vg); }` : ""} + box-shadow: inset 0 0 0 2px var(--vc), inset 0 0 22px var(--vg); }` : ""}${tb && byVerdict ? ` + .tshape { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: 0; }` : ""}${markers.length ? ` + /* The markers: a flag on the track, its label in the band above, both + in the marker's colour; hidden until the fuse reaches it. */ + .mflag { position: absolute; top: 0; width: 0; height: 0; transform-origin: 0 0; } + .mstick { position: absolute; left: -1px; top: -8px; width: 2px; height: 12px; border-radius: 1px; background: var(--mc); } + .mhead { position: absolute; left: 1px; top: -8px; width: 7px; height: 6px; background: var(--mc); + clip-path: polygon(0% 0%, 100% 50%, 0% 100%); } + .mlabel { position: absolute; top: ${(band?.y ?? 3) - tr.y}px; height: 14px; text-align: center; white-space: nowrap; + overflow: hidden; text-overflow: ellipsis; font-family: 'DeckSansBold', sans-serif; font-size: 12px; + line-height: 14px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--mc); }` : ""} .deck-qr img { display: block; width: ${qr?.size ?? 0}px; height: ${qr?.size ?? 0}px; border-radius: 6px; image-rendering: pixelated; backface-visibility: hidden; box-shadow: 0 0 0 1px ${rgba(pal.fg, 0.25)}, 0 6px 18px rgba(0, 0, 0, 0.35); } @@ -548,7 +632,7 @@ export function deckHtml(schedule, render, opts = {}) { <div class="track"> <div class="rail"></div> ${fuseWidth > 0 ? `<div class="fuse" data-k="fuse"></div>` : ""} - ${pipHtml} + ${pipHtml}${markerHtml} <div class="marker" data-k="marker"></div> </div> ${tallyHtml} diff --git a/umtool/report-to-video/chrome-feed.mjs b/umtool/report-to-video/chrome-feed.mjs @@ -87,7 +87,8 @@ export function feedLayout(render) { header: { top: headerTop, height: headerH, ruleY }, stack: { x: padX, y: stackY, width: W - 2 * padX, height: H - stackY - bottom }, card: { - rail: 6, pad: 16, qrSize: p.qrSize, plate: p.qrSize + 28, metaSize: 18, + // `posts.qr: false`: no code and no cell for it (plate 0). + rail: 6, pad: 16, qrSize: p.qr === false ? 0 : p.qrSize, plate: p.qr === false ? 0 : p.qrSize + 28, metaSize: 18, textSize, lineH: Math.round(textSize * 1.36), maxLines: p.maxLines, }, }; @@ -258,9 +259,12 @@ export function feedHtml(schedule, render, opts = {}) { `<span class="date">${esc(postDate(p, deck.subtitle.dateFormat))}</span></div>` + `<div class="text">${postParagraphs(p.text).map((t) => `<p class="para">${esc(t)}</p>`).join("")}</div>` + `</div>`) + - `<div class="plate">` + - (src ? `<img src="${esc(src)}" width="${c.qrSize}" height="${c.qrSize}" alt="">` : "") + - `</div>` + + // `posts.qr: false` (plate 0): no code and no cell; the words take its width. + (c.plate > 0 + ? `<div class="plate">` + + (src ? `<img src="${esc(src)}" width="${c.qrSize}" height="${c.qrSize}" alt="">` : "") + + `</div>` + : "") + `<div class="hl" data-k="h${j}"></div>` + `</article>` ); @@ -338,7 +342,7 @@ export function feedHtml(schedule, render, opts = {}) { box-shadow: inset 0 0 0 2px ${rgba(pal.accent, 0.95)}, inset 0 0 16px ${rgba(pal.accent, 0.5)}; } .hl::before { content: ""; position: absolute; ${left ? "right" : "left"}: 0; top: 0; bottom: 0; width: 4px; background: ${pal.accent}; box-shadow: 0 0 14px 2px ${rgba(pal.accent, 0.6)}; } - .body { position: relative; width: ${lay.stack.width - c.plate - c.rail}px;${left ? ` margin-left: ${c.plate}px;` : ""} + .body { position: relative; width: ${lay.stack.width - c.plate - c.rail}px;${left && c.plate > 0 ? ` margin-left: ${c.plate}px;` : ""} padding: ${c.pad - 3}px ${c.pad + 2}px ${c.pad - 2}px ${c.pad + 2}px; } .meta { display: flex; align-items: center; gap: 10px; font-size: ${c.metaSize}px; line-height: ${Math.round(c.metaSize * 1.3)}px; white-space: nowrap; } diff --git a/umtool/report-to-video/chrome-posts.mjs b/umtool/report-to-video/chrome-posts.mjs @@ -246,6 +246,7 @@ export function postsHtml(schedule, render, window, opts = {}) { const pad = 18; const plateW = set.qrSize + 2 * pad; + const qrOn = set.qr !== false; const LOGO_H = 72; const rail = 6; const metaSize = 18; @@ -257,16 +258,20 @@ export function postsHtml(schedule, render, window, opts = {}) { const cardHtml = posts .map((p, j) => { const { name, platform } = postWho(p); - const src = qrSrcs[p.id]; + // `posts.qr: false`: no code on any card, whatever qrSrcs holds. + const src = qrOn ? qrSrcs[p.id] : null; const shot = shotSrcs[p.id]; const logo = logoSrcs[p.id]; + // Without a code a card keeps its source cell only for a logo; else + // the words take the cell's width (`.no-plate`). + const plate = qrOn || logo; const acc = typeof p.accent === "string" && /^#[0-9a-fA-F]{6}$/.test(p.accent) ? p.accent : null; const style = acc ? ` style="--acc: ${acc}; --acc-rim: ${rgba(acc, 0.95)}; --acc-glow: ${rgba(acc, 0.55)}"` : ""; const flag = p.flag ? `<div class="flag">${esc(p.flag)}</div>` : ""; return ( - `<article class="post${shot ? " has-shot" : ""}${logo ? " has-logo" : ""}" data-post="${esc(p.id)}" data-k="c${j}"${style}>` + + `<article class="post${shot ? " has-shot" : ""}${logo ? " has-logo" : ""}${plate ? "" : " no-plate"}" data-post="${esc(p.id)}" data-k="c${j}"${style}>` + (shot ? `<div class="body shot-body">${flag}<div class="shot-view"><img class="shot" data-k="s${j}" src="${esc(shot)}" alt=""></div></div>` : `<div class="body">${flag}` + @@ -276,10 +281,12 @@ export function postsHtml(schedule, render, window, opts = {}) { `<span class="date">${esc(postDate(p, deck.subtitle.dateFormat))}</span></div>` + `<div class="text">${postParagraphs(p.text).map((t) => `<p class="para">${esc(t)}</p>`).join("")}</div>` + `</div>`) + - `<div class="plate">` + - (logo ? `<img class="logo" src="${esc(logo)}" alt="">` : "") + - (src ? `<img src="${esc(src)}" width="${set.qrSize}" height="${set.qrSize}" alt="">` : "") + - `</div>` + + (plate + ? `<div class="plate">` + + (logo ? `<img class="logo" src="${esc(logo)}" alt="">` : "") + + (src ? `<img src="${esc(src)}" width="${set.qrSize}" height="${set.qrSize}" alt="">` : "") + + `</div>` + : "") + `<div class="glow" data-k="g${j}"></div>` + `</article>` ); @@ -350,7 +357,12 @@ export function postsHtml(schedule, render, window, opts = {}) { font-family: 'DeckSansBold', sans-serif; font-size: ${metaSize}px; line-height: ${metaSize + 6}px; letter-spacing: 0.02em; color: ${pal.bg}; background: var(--acc, ${pal.accent}); } /* A card's logo: the top corner, above its QR. */ - .post.has-logo { min-height: ${set.qrSize + 2 * pad + LOGO_H + 10}px; } + .post.has-logo { min-height: ${set.qrSize + 2 * pad + LOGO_H + 10}px; }${qrOn ? "" : ` + /* posts.qr false: a card is as tall as its words (a logo's cell as tall + as the logo), and a card with no cell gives its words the width. */ + .post { min-height: 0; } + .post.has-logo { min-height: ${LOGO_H + 2 * pad}px; } + .post.no-plate .body { width: ${W - rail}px; }`} .logo { display: block; width: ${plateW - 16}px; height: auto; max-height: ${LOGO_H}px; object-fit: contain; border-radius: 6px; } .body { position: relative; width: ${W - plateW - rail}px; padding: ${pad - 4}px ${pad + 2}px ${pad - 3}px ${pad + 2}px; } diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs @@ -47,6 +47,7 @@ import { deckHtml, GSAP_FILE } from "./chrome-deck.mjs"; import { postsHtml, snapWindow, windowPosts } from "./chrome-posts.mjs"; import { feedHtml } from "./chrome-feed.mjs"; import { stampHtml } from "./chrome-stamp.mjs"; +import { stampsDrawn } from "./factcheck.mjs"; import { threadsHtml } from "./chrome-threads.mjs"; import { flipsHtml } from "./chrome-flips.mjs"; import { statsHtml } from "./chrome-stats.mjs"; @@ -761,7 +762,10 @@ async function regionHtml(region, { manifest, manifestDir, base, projDir, assets const render = manifest.render; const fonts = await copyFonts(render, assetsDir, { regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); const posts = windowPosts(schedule, window.segment); - const byUrl = await qrPngsFor(posts.map((p) => p.qrUrl), render, resolveDeck(render).posts.qrSize, assetsDir); + // `posts.qr: false`: no codes are made, and the page draws none. + const byUrl = resolveDeck(render).posts.qr === false + ? new Map() + : await qrPngsFor(posts.map((p) => p.qrUrl), render, resolveDeck(render).posts.qrSize, assetsDir); const qrSrcs = {}; for (const p of posts) if (p.qrUrl) qrSrcs[p.id] = byUrl.get(p.qrUrl); const shotSrcs = await copyShots(posts, manifestDir, assetsDir); @@ -773,7 +777,10 @@ async function regionHtml(region, { manifest, manifestDir, base, projDir, assets const render = manifest.render; const fonts = await copyFonts(render, assetsDir, { regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); const posts = schedule.posts ?? []; - const byUrl = await qrPngsFor(posts.map((p) => p.qrUrl), render, resolveDeck(render).posts.qrSize, assetsDir); + // `posts.qr: false`: no codes are made, and the page draws none. + const byUrl = resolveDeck(render).posts.qr === false + ? new Map() + : await qrPngsFor(posts.map((p) => p.qrUrl), render, resolveDeck(render).posts.qrSize, assetsDir); const qrSrcs = {}; for (const p of posts) if (p.qrUrl) qrSrcs[p.id] = byUrl.get(p.qrUrl); const shotSrcs = await copyShots(posts, manifestDir, assetsDir); @@ -976,6 +983,9 @@ export async function composeChrome({ if (region === "stamp" && !sched.factcheck?.stamps?.length) { throw new Error("the stamp region needs a schedule that stamps a claim (an entry with a `claim`)"); } + if (region === "stamp" && !stampsDrawn(sched, manifest.render)) { + throw new Error("the stamps are off (render.chrome.factcheck.stamp.show: false): there is no stamp region to compose"); + } const D = transition ?? transitionOf(manifest.render); const rate = Number(fps ?? sched?.fps ?? manifest.render.fps ?? 30); const total = teaser ? teaserSeconds(teaser, D, rate) : keyed ? sched.total : null; diff --git a/umtool/report-to-video/deck-counts.test.mjs b/umtool/report-to-video/deck-counts.test.mjs @@ -0,0 +1,305 @@ +// Tests for the deck-counts lane (plans/deck-counts.md): the stamps off with +// the tally still counting (`factcheck.stamp.show`), no QR on the post cards +// (`deck.posts.qr`), pips in their claim's verdict colour and shape +// (`deck.pip.color: "verdict"`), and flags on the pip track +// (`deck.markers`). Each is optional, and a deck without them is as it was. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; + +import { + DECK_DEFAULTS, deckLayout, deckMarkers, deckSchedule, MARKER_BAND, MARKER_LIMITS, pipSegments, pipXs, postWindows, + resolveDeck, snapWindow, validateChrome, validateDeckMarkers, +} from "./deck.mjs"; +import { deckCues, deckHtml, MARKER_POP } from "./chrome-deck.mjs"; +import { postsHtml, windowPosts } from "./chrome-posts.mjs"; +import { feedHtml, feedLayout } from "./chrome-feed.mjs"; +import { + FACTCHECK_DEFAULTS, resolveFactcheck, stampsDrawn, tallyCues, validateFactcheck, VERDICT_SHAPES, VERDICTS, +} from "./factcheck.mjs"; +import { validatorErrors } from "./lint.mjs"; + +const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; +const CHROME = { engine: "hyperframes", layout: "deck" }; +const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE }; +const renderWith = (deck = {}, factcheck = undefined) => + ({ ...BASE, chrome: { ...CHROME, deck, ...(factcheck ? { factcheck } : {}) } }); +const PROV = { siteOrigin: "https://example.test", channelSlug: "chan" }; + +// Four clips and a card: c1 PARTLY, c2 CONTRADICTED, c4 CORROBORATED, c3 none. +const ENTRIES = [ + { id: "c1", type: "clip", video: "a", start: 0, end: 10, date: "2024-09-05", claim: { id: "k1", verdict: "PARTLY" } }, + { id: "c2", type: "clip", video: "b", start: 0, end: 20, date: "2024-10-01", claim: { id: "k2", verdict: "CONTRADICTED" } }, + { id: "t1", type: "card", seconds: 4, heading: "Three weeks later" }, + { id: "c3", type: "clip", video: "c", start: 0, end: 6, date: "2025-12-08" }, + { id: "c4", type: "clip", video: "d", start: 0, end: 9, date: "2025-12-09", claim: { id: "k4", verdict: "CORROBORATED" } }, +]; +const DURS = [10, 20, 4, 6, 9]; +const POST = (id, date, extra = {}) => ({ + id, platform: "x", author: "Someone", handle: "someone", date, text: `words of ${id}`, + url: `https://x.com/someone/status/${id}`, ...extra, +}); +const POSTS = [POST("p1", "2024-10-02", { attachTo: "c2" }), POST("p2", "2024-10-03", { attachTo: "c2" })]; +const sched = (render, posts = []) => deckSchedule({ entries: ENTRIES, durs: DURS, D: 0.5, render, provenance: PROV, posts }); +const FONTS = { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" }; + +// ---- F1: the stamp off, the tally still counting ------------------------------ + +test("stamp.show: a setting, default on; refused when not a boolean", () => { + assert.equal(FACTCHECK_DEFAULTS.stamp.show, true); + assert.equal(resolveFactcheck(renderWith()).stamp.show, true); + assert.equal(resolveFactcheck(renderWith({}, { stamp: { show: false } })).stamp.show, false); + assert.deepEqual(validateFactcheck({ stamp: { show: false, seconds: 2 } }), []); + assert.match(validateFactcheck({ stamp: { show: "no" } }).join(" "), /stamp\.show must be true or false/); + assert.deepEqual(validateChrome({ ...CHROME, factcheck: { stamp: { show: false } } }, BASE), []); +}); + +test("stamp.show false: the schedule keeps its stamps, nothing is drawn, and the tally counts at the same seconds", () => { + const on = renderWith(); + const off = renderWith({}, { stamp: { show: false } }); + const a = sched(on), b = sched(off); + // The schedule is the same: the stamps are when the tally steps. + assert.deepEqual(b, a); + assert.equal(a.factcheck.stamps.length, 3); + assert.equal(stampsDrawn(a, on), true); + assert.equal(stampsDrawn(b, off), false); + assert.equal(stampsDrawn({ segments: [] }, on), false); + // The tally's cues -- each count and its flash -- are exactly the stamps-on ones. + const tally = (r, s) => deckCues(s, r).cues.filter((c) => c.k.startsWith("ty.")); + assert.deepEqual(tally(off, b), tally(on, a)); + assert.ok(tally(off, b).some((c) => c.k === "ty.CONTRADICTED.flash"), "the flash fires"); + const steps = tallyCues(b.factcheck.stamps).events.filter((e) => e.k.endsWith(".n1")); + assert.deepEqual(steps.map((e) => e.at).sort(), b.factcheck.stamps.map((s) => s.landed).sort()); + // The deck page itself is identical: the stamp is another region. + assert.equal(deckHtml(b, off, { fonts: FONTS }), deckHtml(a, on, { fonts: FONTS })); +}); + +test("compose-chrome: no stamp region when the stamps are off", async () => { + const dir = mkdtempSync(path.join(tmpdir(), "deck-counts-stamp-")); + const env = process.env.HYPERFRAMES_BIN; + try { + const stub = path.join(dir, "hf-stub.mjs"); + writeFileSync(stub, "#!/usr/bin/env node\nprocess.exit(1);\n"); + chmodSync(stub, 0o755); + process.env.HYPERFRAMES_BIN = stub; + const font = path.join(dir, "face.ttf"); + writeFileSync(font, "face"); + const render = { ...renderWith({}, { stamp: { show: false } }), fontRegular: font, fontBold: font }; + const mp = path.join(dir, "video.manifest.json"); + writeFileSync(mp, JSON.stringify({ slug: "f", render, timeline: ENTRIES })); + const out = path.join(dir, "out", "sourced"); + mkdirSync(out, { recursive: true }); + writeFileSync(path.join(out, "schedule.json"), JSON.stringify(sched(render))); + const { composeChrome } = await import("./compose-chrome.mjs"); + await assert.rejects(composeChrome({ manifestPath: mp, region: "stamp" }), /the stamps are off/); + } finally { + if (env === undefined) delete process.env.HYPERFRAMES_BIN; + else process.env.HYPERFRAMES_BIN = env; + rmSync(dir, { recursive: true, force: true }); + } +}); + +// ---- F2: no QR on the posts --------------------------------------------------- + +test("posts.qr: a setting, default on; refused when not a boolean", () => { + assert.equal(DECK_DEFAULTS.posts.qr, true); + assert.equal(resolveDeck(renderWith({ posts: { qr: false } })).posts.qr, false); + assert.deepEqual(validateChrome({ ...CHROME, deck: { posts: { qr: false } } }, BASE), []); + assert.match(validateChrome({ ...CHROME, deck: { posts: { qr: 0 } } }, BASE).join(" "), /posts\.qr must be true or false/); +}); + +test("posts.qr false, popup: no code and no cell; the words take the width; the deck's own QR stays", () => { + const on = renderWith(); + const off = renderWith({ posts: { qr: false } }); + const qrSrcs = { p1: "assets/pqr0.png", p2: "assets/pqr1.png" }; + const page = (r) => { + const s = sched(r, POSTS); + const win = snapWindow(postWindows(s)[0], { fps: 30, total: s.total }); + assert.deepEqual(windowPosts(s, win.segment).map((p) => p.id), ["p1", "p2"]); + return postsHtml(s, r, win, { fonts: FONTS, qrSrcs, logoSrcs: { p2: "assets/logo.png" } }); + }; + const withQr = page(on); + assert.ok(withQr.includes('<img src="assets/pqr0.png"')); + const without = page(off); + assert.doesNotMatch(without, /pqr\d\.png/, "no code, whatever qrSrcs holds"); + // p1 has no cell at all; p2 keeps one for its logo only. + assert.match(without, /class="post no-plate" data-post="p1"/); + assert.match(without, /class="post has-logo" data-post="p2"/); + assert.equal((without.match(/<div class="plate">/g) ?? []).length, 1); + assert.match(without, /\.post\.no-plate \.body \{ width: 594px; \}/, "600 less the rail"); + assert.match(without, /\.post \{ min-height: 0; \}/); + // The clip's deck QR is the deck's: untouched. + const s = sched(off, POSTS); + assert.equal(deckHtml(s, off, { qrSrcs: { c2: "assets/qr1.png" } }), deckHtml(sched(on, POSTS), on, { qrSrcs: { c2: "assets/qr1.png" } })); +}); + +test("posts.qr false, feed: no code, no cell, the body the stack's width less the rail", () => { + const off = renderWith({ posts: { layout: "feed", qr: false } }); + const on = renderWith({ posts: { layout: "feed" } }); + assert.equal(feedLayout(off).card.plate, 0); + assert.equal(feedLayout(on).card.plate, 120 + 28); + const qrSrcs = { p1: "assets/pqr0.png", p2: "assets/pqr1.png" }; + const html = feedHtml(sched(off, POSTS), off, { qrSrcs }); + assert.doesNotMatch(html, /pqr\d\.png/); + assert.doesNotMatch(html, /<div class="plate">/); + const lay = feedLayout(off); + assert.ok(html.includes(`.body { position: relative; width: ${lay.stack.width - lay.card.rail}px;`)); + assert.ok(feedHtml(sched(on, POSTS), on, { qrSrcs }).includes('<img src="assets/pqr0.png"')); +}); + +// ---- F3: pips by verdict ------------------------------------------------------ + +test("pip.color: accent (default) or verdict; anything else refused", () => { + assert.equal(DECK_DEFAULTS.pip.color, "accent"); + assert.deepEqual(validateChrome({ ...CHROME, deck: { pip: { color: "verdict" } } }, BASE), []); + assert.match(validateChrome({ ...CHROME, deck: { pip: { color: "red" } } }, BASE).join(" "), /pip\.color must be "accent" or "verdict"/); +}); + +test("VERDICT_SHAPES: one distinct shape per verdict, in VERDICTS order", () => { + assert.deepEqual(Object.keys(VERDICT_SHAPES), [...VERDICTS]); + assert.equal(new Set(Object.values(VERDICT_SHAPES)).size, VERDICTS.length); + assert.deepEqual(Object.values(VERDICT_SHAPES), ["circle", "diamond", "square", "triangle", "ring"]); +}); + +test("pip.color verdict: a claimed pip lit in its verdict's colour (relabels included) and shape; an unclaimed one as before", () => { + const r = renderWith({ pip: { color: "verdict" } }, { verdicts: { PARTLY: { color: "#ff00aa" } } }); + const s = sched(r); + const { pips } = deckCues(s, r); + assert.deepEqual(pips.map((p) => [p.id, p.verdict ?? null]), + [["c1", "PARTLY"], ["c2", "CONTRADICTED"], ["c3", null], ["c4", "CORROBORATED"]]); + const html = deckHtml(s, r, {}); + const lit = (k) => new RegExp(`<div class="pip lit[^"]*" data-k="pip${k}"[^>]*>`).exec(html)[0]; + assert.match(lit(0), /data-verdict="PARTLY" data-shape="diamond"/); + assert.match(lit(0), /background:#ff00aa/, "the override's colour"); + assert.match(lit(0), /transform:rotate\(45deg\)/); + assert.match(lit(1), /data-shape="square"/); + assert.match(lit(1), /background:#e5534b/); + assert.match(lit(3), /data-shape="circle"/); + assert.match(lit(3), /background:#3fbf7f/); + assert.equal(lit(2), `<div class="pip lit" data-k="pip2" style="left:${pips[2].x - 3}px">`, "unclaimed: as it always was"); + // The tally cell is the same colour, and carries the same shape. + const cell = /<div class="tcell" data-verdict="PARTLY"[^>]*>.*?<div class="tlabel">(.*?)<\/div>/s.exec(html); + assert.match(cell[0], /--vc:#ff00aa/); + assert.match(cell[1], /class="tshape" data-shape="diamond"[^>]*background:#ff00aa/); + // The pips still light as they did: one opacity cue each, same times. + const plain = renderWith({}, { verdicts: { PARTLY: { color: "#ff00aa" } } }); + const cuesOf = (rr) => deckCues(s, rr).cues.filter((c) => c.k.startsWith("pip")); + assert.deepEqual(cuesOf(r), cuesOf(plain)); + // Accent (the default): no verdict pips, no shape in the tally. + const accent = deckHtml(s, plain, {}); + assert.doesNotMatch(accent, /vpip|tshape/); +}); + +// ---- F4: markers ---------------------------------------------------------------- + +const MARKS = [{ after: "c2", label: "3 to 5 weeks pass" }, { after: "c4", label: "promise lapses", color: "#e5534b" }]; + +test("markers: shape refused in sentences -- unknown keys, labels, colours, count", () => { + const bad = (markers) => validateChrome({ ...CHROME, deck: { markers } }, BASE).join(" "); + assert.equal(bad(MARKS), ""); + assert.match(bad("c2"), /markers must be a list/); + assert.match(bad([{ after: "c2", label: "x", note: 1 }]), /markers\[0\]\.note is not a marker setting/); + assert.match(bad([{ after: "", label: "x" }]), /markers\[0\]\.after must name a clip's id/); + assert.match(bad([{ after: "c2", label: " " }]), /markers\[0\]\.label must be a word or two/); + assert.match(bad([{ after: "c2", label: "x".repeat(MARKER_LIMITS.label + 1) }]), /is 25 characters \(at most 24\)/); + assert.equal(bad([{ after: "c2", label: "x".repeat(MARKER_LIMITS.label) }]), ""); + assert.match(bad([{ after: "c2", label: "a\nb" }]), /must be one line/); + assert.match(bad([{ after: "c2", label: "x", color: "red" }]), /color must be a #hex colour/); + assert.equal(bad([{ after: "c2", label: "x", color: "amber" }]), ""); + assert.match(bad(Array.from({ length: 13 }, () => ({ after: "c2", label: "x" }))), /13 markers \(at most 12\)/); +}); + +test("markers: `after` must name a clip in the timeline -- the build's, the lint's and the writer's check", () => { + const m = (markers, timeline = ENTRIES) => ({ timeline, render: renderWith({ markers }) }); + assert.deepEqual(validateDeckMarkers(m(MARKS)), []); + assert.match(validateDeckMarkers(m([{ after: "zz", label: "x" }])).join(" "), /names zz, which is not in the timeline/); + assert.match(validateDeckMarkers(m([{ after: "t1", label: "x" }])).join(" "), /names t1, a card: a marker follows a clip/); + // The shape too, for the lint, which does not run validateChrome. + assert.match(validateDeckMarkers(m([{ after: "c2" }])).join(" "), /label must be a word or two/); + assert.match(validatorErrors(m([{ after: "zz", label: "x" }])).join(" "), /not in the timeline/); + // Without the deck, or without markers, nothing to say. + assert.deepEqual(validateDeckMarkers({ timeline: ENTRIES, render: BASE }), []); + assert.deepEqual(validateDeckMarkers({ timeline: ENTRIES, render: renderWith() }), []); +}); + +test("markers: a band above the track only when there are some; the code and the tally keep clear of it", () => { + const plain = deckLayout(renderWith(), { tally: ["PARTLY"] }); + const marked = deckLayout(renderWith({ markers: MARKS }), { tally: ["PARTLY"] }); + assert.equal(plain.pipTrack.y, 16); + assert.equal(plain.markerBand, undefined); + assert.equal(marked.pipTrack.y, 16 + MARKER_BAND); + assert.deepEqual(marked.markerBand, { y: 3, height: MARKER_BAND + 6 }); + // The labels' band ends above everything in the body. + const bandEnd = marked.markerBand.y + 14; + assert.ok(marked.qr.y >= marked.pipTrack.y + 12 && marked.qr.y + marked.qr.size <= 190, `qr ${marked.qr.y}`); + assert.ok(marked.tally.y > bandEnd && marked.text.titleY > bandEnd); +}); + +test("markers: placed between the pip they follow and the next; time spacing at the hand-over; boxes never meet", () => { + const r = renderWith({ markers: MARKS }); + const s = sched(r); + const lay = deckLayout(r); + const pipped = pipSegments(s); + const xs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, "even"); + const ms = deckMarkers(s, r, xs, pipped, lay); + assert.deepEqual(ms.map((m) => [m.after, m.k]), [["c2", 1], ["c4", 3]]); + assert.equal(ms[0].x, (xs[1] + xs[2]) / 2); + assert.equal(ms[1].x, (xs[3] + lay.pipTrack.x1) / 2, "after the last pip: toward the track's end"); + assert.equal(ms[0].color, PALETTE.amber, "the default colour is the palette's amber"); + assert.equal(ms[1].color, "#e5534b"); + for (const m of ms) assert.ok(m.box[0] <= m.x && m.box[1] >= m.x && m.box[1] - m.box[0] <= 240); + // Time spacing: at the next segment's mid-dissolve, in the cut's clock. + const rt = renderWith({ markers: MARKS, pip: { spacing: "time" } }); + const st = sched(rt); + const tl = deckLayout(rt); + const tp = pipSegments(st); + const txs = pipXs(tp.length, tl.pipTrack.x0, tl.pipTrack.x1, "time", { total: st.total, segments: tp }); + const [m0] = deckMarkers(st, rt, txs, tp, tl); + const next = st.segments[st.segments.findIndex((x) => x.id === "c2") + 1]; + assert.ok(Math.abs(m0.x - (tl.pipTrack.x0 + ((tl.pipTrack.x1 - tl.pipTrack.x0) * (next.start + 0.25)) / st.total)) < 0.01); + assert.ok(m0.x > txs[1] && m0.x < txs[2]); + // Crowded flags: each label stops short of halfway to its neighbour. + const crowd = renderWith({ markers: [{ after: "c1", label: "a long label of a flag" }, { after: "c2", label: "another long label" }, { after: "c3", label: "third" }] }); + const cs = sched(crowd); + const cl = deckLayout(crowd); + const cp = pipSegments(cs); + const cx = pipXs(cp.length, cl.pipTrack.x0, cl.pipTrack.x1, "even"); + const placed = deckMarkers(cs, crowd, cx, cp, cl); + for (let j = 1; j < placed.length; j += 1) assert.ok(placed[j - 1].box[1] < placed[j].box[0], `boxes ${j - 1} and ${j} meet`); +}); + +test("markers: hidden until the fuse reaches the flag, then a pop, lit for the rest; drawn in the page", () => { + const r = renderWith({ markers: MARKS }); + const s = sched(r); + const { init, cues, markers } = deckCues(s, r); + assert.equal(markers.length, 2); + assert.deepEqual(init.mk0, { autoAlpha: 0, scale: MARKER_POP.from }); + const mk0 = cues.filter((c) => c.k === "mk0"); + assert.equal(mk0.length, 1, "one cue: it pops in and stays"); + assert.deepEqual(mk0[0].from, { autoAlpha: 0, scale: MARKER_POP.from }); + assert.deepEqual(mk0[0].to, { autoAlpha: 1, scale: 1 }); + // The fuse from pip 1 (c2) toward pip 2 (c3) passes the midpoint halfway + // through its burn: c2's rest, from its arrival to the deck sliding away. + const fuse = cues.find((c) => c.k === "fuse" && c.why === "fuse c2"); + assert.ok(Math.abs(mk0[0].at - (fuse.at + fuse.dur / 2)) < 0.01, `${mk0[0].at} vs fuse ${fuse.at}+${fuse.dur}`); + assert.ok(mk0[0].at > s.segments[1].start && mk0[0].at < s.segments[1].end); + // After the last pip: a second before its clip ends. + const c4 = s.segments.find((x) => x.id === "c4"); + const mk1 = cues.find((c) => c.k === "mk1"); + assert.ok(Math.abs(mk1.at - (c4.end - 1)) < 0.01); + // The page: a flag per marker, its label escaped, in the band. + const html = deckHtml(s, r, {}); + assert.equal((html.match(/class="mflag"/g) ?? []).length, 2); + assert.match(html, /data-k="mk0" data-after="c2"[^>]*--mc:#ffc860/); + assert.match(html, /<div class="mlabel"[^>]*>3 to 5 weeks pass<\/div>/); + assert.match(html, /\.mlabel \{ position: absolute; top: -23px;/, "the band, above the track"); + assert.match(html, /text-overflow: ellipsis; font-family: 'DeckSansBold'/); + const esc = renderWith({ markers: [{ after: "c2", label: "<b>x</b> & y" }] }); + assert.match(deckHtml(sched(esc), esc, {}), /><b>x<\/b> & y</); + // No markers: none of it. + assert.doesNotMatch(deckHtml(s, renderWith(), {}), /mflag|mlabel/); +}); diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -42,7 +42,9 @@ export const DECK_DEFAULTS = Object.freeze({ height: 190, footageScale: 0.82, background: "panel", // | "flush" - pip: Object.freeze({ spacing: "even", size: 6, activeSize: 12 }), // spacing | "time" + // spacing | "time". `color` "verdict": a claimed clip's pip, once lit, takes + // its claim's verdict colour and shape (factcheck.mjs VERDICT_SHAPES). + pip: Object.freeze({ spacing: "even", size: 6, activeSize: 12, color: "accent" }), title: Object.freeze({ size: 54, maxChars: 48 }), subtitle: Object.freeze({ parts: "auto", dateFormat: "long" }), // dateFormat | "iso" // `links` is where a clip's QR goes: "site" (the archive's page at the @@ -72,9 +74,29 @@ export const DECK_DEFAULTS = Object.freeze({ posts: Object.freeze({ show: true, layout: "popup", seconds: 4, hold: 2.5, position: "top-right", width: 600, qrSize: 120, maxLines: 7, inset: 24, shift: Object.freeze({ scale: 0.86, seconds: 0.6 }), links: "archive", at: "end", shotMaxHeight: null, + // `qr: false` draws no QR on any post card (popup or feed); the words + // take the code's width. The clip's own deck QR (`qr`) is untouched. + qr: true, }), + // Flags on the pip track: `[{ after, label, color? }]`, each between the pip + // of the clip `after` names and the next, hidden until the fuse reaches it + // (deckMarkers). An empty list is no flags, and the deck lays out as it + // always did. + markers: Object.freeze([]), }); +/** The pip's colour when lit (`pip.color`): the deck's accent, or a claimed clip's verdict. */ +export const PIP_COLORS = Object.freeze(["accent", "verdict"]); + +/** A marker's limits: how many, and a label's characters. */ +export const MARKER_LIMITS = Object.freeze({ count: 12, label: 24 }); + +/** The palette keys a marker's `color` may name (else a `#rgb` / `#rrggbb`). */ +export const MARKER_PALETTE_KEYS = Object.freeze(["fg", "muted", "accent", "amber", "dim"]); + +/** A marker with no `color` is drawn in this palette key. */ +export const MARKER_DEFAULT_COLOR = "amber"; + /** * The deck's TUNABLE params (release 38): the settings the video assistant's * `fx` op may set by name, each with the bounds validateChrome holds it to @@ -194,10 +216,13 @@ export function validateChrome(chrome, render = {}) { unknownKeys(d[key], allowed, `${w}.${key}`, errors); check(d[key]); }; - sub("pip", ["spacing", "size", "activeSize"], (p) => { + sub("pip", ["spacing", "size", "activeSize", "color"], (p) => { if (p.spacing !== undefined && !["even", "time"].includes(p.spacing)) { errors.push(`${w}.pip.spacing must be "even" or "time"`); } + if (p.color !== undefined && !PIP_COLORS.includes(p.color)) { + errors.push(`${w}.pip.color must be ${PIP_COLORS.map((c) => `"${c}"`).join(" or ")}`); + } if (p.size !== undefined && !numIn(p.size, 2, 24)) errors.push(`${w}.pip.size must be from 2 to 24`); if (p.activeSize !== undefined && !numIn(p.activeSize, 2, 40)) { errors.push(`${w}.pip.activeSize must be from 2 to 40`); @@ -239,7 +264,8 @@ export function validateChrome(chrome, render = {}) { errors.push(`${w}.qr.size ${size} does not fit a ${h}px deck (at most ${h - 20})`); } }); - sub("posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight"], (p) => { + sub("posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr"], (p) => { + if (p.qr !== undefined && typeof p.qr !== "boolean") errors.push(`${w}.posts.qr must be true or false`); if (p.at !== undefined && !POST_AT.includes(p.at)) { errors.push(`${w}.posts.at must be ${POST_AT.map((a) => `"${a}"`).join(" or ")}`); } @@ -276,6 +302,7 @@ export function validateChrome(chrome, render = {}) { } if (p.inset !== undefined && !numIn(p.inset, 0, 80)) errors.push(`${w}.posts.inset must be from 0 to 80`); }); + errors.push(...markerShapeErrors(d.markers, `${w}.markers`)); sub("motion", ["out", "in", "pip"], (m) => { for (const k of ["out", "in"]) { if (m[k] !== undefined && !numIn(m[k], 0, 2)) errors.push(`${w}.motion.${k} must be from 0 to 2 seconds`); @@ -311,6 +338,64 @@ export function validateChrome(chrome, render = {}) { return errors; } +const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; + +/** + * Every reason a `deck.markers` list cannot be drawn, its shape alone (the + * timeline is not in `render.chrome`: `validateDeckMarkers` checks `after` + * against it). validateChrome calls this. + * + * @returns {string[]} + */ +function markerShapeErrors(markers, where) { + if (markers === undefined) return []; + if (!Array.isArray(markers)) return [`${where} must be a list of { after, label, color? }`]; + const errors = []; + if (markers.length > MARKER_LIMITS.count) errors.push(`${where} has ${markers.length} markers (at most ${MARKER_LIMITS.count})`); + markers.forEach((m, i) => { + const at = `${where}[${i}]`; + if (!isObj(m)) { errors.push(`${at} must be { after, label, color? }`); return; } + for (const k of Object.keys(m)) { + if (!["after", "label", "color"].includes(k)) errors.push(`${at}.${k} is not a marker setting (after, label, color)`); + } + if (typeof m.after !== "string" || !m.after.trim()) errors.push(`${at}.after must name a clip's id`); + const label = typeof m.label === "string" ? m.label.trim() : ""; + if (!label) errors.push(`${at}.label must be a word or two`); + else if (/[\r\n]/.test(label)) errors.push(`${at}.label must be one line`); + else if ([...label].length > MARKER_LIMITS.label) { + errors.push(`${at}.label is ${[...label].length} characters (at most ${MARKER_LIMITS.label})`); + } + if (m.color !== undefined && !(typeof m.color === "string" && (HEX_RE.test(m.color) || MARKER_PALETTE_KEYS.includes(m.color)))) { + errors.push(`${at}.color must be a #hex colour or one of ${MARKER_PALETTE_KEYS.join(", ")}`); + } + }); + return errors; +} + +/** + * The deck's markers checked whole: their shape (as validateChrome checks + * it) and, against the WHOLE timeline, that each `after` names a clip in it. + * The build and the lint refuse with these; umtool's writers refuse before + * they write. Empty without the deck or without markers. + * + * @returns {string[]} + */ +export function validateDeckMarkers(manifest) { + const markers = manifest?.render?.chrome?.deck?.markers; + if (!deckOn(manifest?.render) || markers === undefined) return []; + const errors = markerShapeErrors(markers, "render.chrome.deck.markers"); + if (!Array.isArray(markers)) return errors; + const timeline = manifest.timeline ?? []; + markers.forEach((m, i) => { + if (!isObj(m) || typeof m.after !== "string" || !m.after.trim()) return; // markerShapeErrors says so + const hit = timeline.find((e) => e?.id === m.after.trim()); + const where = `render.chrome.deck.markers[${i}].after`; + if (!hit) errors.push(`${where} names ${m.after}, which is not in the timeline`); + else if (hit.type !== "clip") errors.push(`${where} names ${m.after}, a ${hit.type ?? "entry"}: a marker follows a clip`); + }); + return errors; +} + /** `validateChrome`, thrown. The build calls this before it spends a single fetch. */ export function assertChrome(chrome, render = {}) { const errors = validateChrome(chrome, render); @@ -413,15 +498,21 @@ export function deckLayout(render, { tally = null } = {}) { const { W, deck: rect } = deckGeometry(render); const d = resolveDeck(render); const padX = 48; - const trackY = 16; + // The markers' labels (`deck.markers`) stand in a band above the track: the + // track moves down by it, and only when there is a marker to label, so a + // deck without them lays out as it always did. + const markerBand = Array.isArray(d.markers) && d.markers.length ? MARKER_BAND : 0; + const trackY = 16 + markerBand; // The body is everything under the pip track: the text block and the QR are // both centred in it, so the title's optical centre and the code's agree // whatever the deck's height. 14 px clears the active pip's halo. const bodyTop = trackY + 14; const bodyH = rect.height - bodyTop - 8; - const qr = d.qr.show - ? { x: W - padX - d.qr.size, y: Math.round(bodyTop + (bodyH - d.qr.size) / 2), size: d.qr.size } - : null; + let qrY = Math.round(bodyTop + (bodyH - d.qr.size) / 2); + // Under a marker band the code keeps clear of the active pip's halo and + // inside the deck, whichever gives way. + if (markerBand) qrY = Math.min(rect.height - d.qr.size - 2, Math.max(qrY, trackY + 12)); + const qr = d.qr.show ? { x: W - padX - d.qr.size, y: qrY, size: d.qr.size } : null; let textX = padX; let textRight = qr ? qr.x - 48 : W - padX; let tallyBox = null; @@ -470,9 +561,72 @@ export function deckLayout(render, { tally = null } = {}) { qr, // Only with a tally, so a deck without claims lays out as it always did. ...(tallyBox ? { tally: tallyBox } : {}), + // Only with markers, likewise: where their labels stand (deckMarkers). + ...(markerBand ? { markerBand: { y: 3, height: markerBand + 6 } } : {}), }; } +/** How far the track moves down to make room for the markers' labels. */ +export const MARKER_BAND = 10; + +/** + * Where each of the deck's markers (`deck.markers`) stands on the pip track, + * region-local px: `x` between the pip of the clip it follows and the next + * pip (their midpoint; with `pip.spacing: "time"` the cut's second where the + * two segments hand over -- the next segment's mid-dissolve), and its label's + * box `[left, right]`: at most 240 px centred on the flag, never past halfway + * to the next flag either side nor off the track's ends, so two labels never + * meet -- a long one is ellipsized in it. `k` is the pip it follows. A marker + * whose clip has no pip (not in the cut) is left out. + * + * `xs` are the pips' x (pipXs), `pipped` their segments (pipSegments). + * + * @returns {Array<{ after: string, label: string, color: string, k: number, x: number, box: [number, number] }>} + */ +export function deckMarkers(schedule, render, xs, pipped, lay = deckLayout(render)) { + const d = resolveDeck(render); + const markers = Array.isArray(d.markers) ? d.markers : []; + if (!markers.length || !pipped.length) return []; + const { x0, x1 } = lay.pipTrack; + const pal = render?.palette ?? {}; + const segs = schedule.segments ?? []; + const D = schedule.transition ?? 0; + const pipOf = new Map(pipped.map((s, k) => [s.id, k])); + const placed = []; + for (const m of markers) { + const after = String(m?.after ?? "").trim(); + const k = pipOf.get(after); + if (k === undefined) continue; + let x; + if (d.pip.spacing === "time" && schedule.total > 0) { + const i = segs.findIndex((s) => s.id === after); + const next = segs[i + 1]; + x = next ? x0 + ((x1 - x0) * (next.start + D / 2)) / schedule.total : x1; + } else { + x = k + 1 < xs.length ? (xs[k] + xs[k + 1]) / 2 : (xs[k] + x1) / 2; + } + x = Math.min(x1, Math.max(x0, x)); + const key = m.color ?? MARKER_DEFAULT_COLOR; + const color = HEX_RE.test(key) ? key : pal[key] ?? pal.fg ?? "#ffffff"; + placed.push({ after, label: String(m.label ?? "").trim(), color, k, x: Math.round(x * 100) / 100 }); + } + // The label boxes: each up to halfway to its neighbours, 240 px at most. + const order = placed.map((p, j) => j).sort((a, b) => placed[a].x - placed[b].x); + const W = lay.width; + return placed.map((p, j) => { + const o = order.indexOf(j); + const prev = o > 0 ? placed[order[o - 1]].x : null; + const next = o < order.length - 1 ? placed[order[o + 1]].x : null; + const lo = Math.max(16, p.x - 120, prev === null ? -Infinity : (prev + p.x) / 2 + 3); + const hi = Math.max(lo, Math.min(W - 16, p.x + 120, next === null ? Infinity : (p.x + next) / 2 - 3)); + // Centred on the flag when that leaves the label room; else the whole + // stretch it may take, off-centre (a flag near the track's end). + const half = Math.min(p.x - lo, hi - p.x); + const box = half * 2 >= Math.min(140, hi - lo) ? [p.x - half, p.x + half] : [lo, hi]; + return { ...p, box: box.map((v) => Math.round(v)) }; + }); +} + /** * The x of every pip on the track. * diff --git a/umtool/report-to-video/deck.test.mjs b/umtool/report-to-video/deck.test.mjs @@ -45,7 +45,7 @@ test("deckOn: only the hyperframes deck", () => { test("resolveDeck merges one level deep", () => { const d = resolveDeck({ chrome: { ...CHROME, deck: { height: 200, pip: { size: 8 } } } }); assert.equal(d.height, 200); - assert.deepEqual(d.pip, { spacing: "even", size: 8, activeSize: 12 }); + assert.deepEqual(d.pip, { spacing: "even", size: 8, activeSize: 12, color: "accent" }); assert.deepEqual(d.motion, DECK_DEFAULTS.motion); }); diff --git a/umtool/report-to-video/factcheck.mjs b/umtool/report-to-video/factcheck.mjs @@ -4,7 +4,7 @@ // // timeline entry: "claim": { "id": "k3", "verdict": "CONTRADICTED" } // render.chrome: "factcheck": { "verdicts": { "PARTLY": { "label": "Half true" } }, -// "stamp": { "seconds": 3, "position": "top-left" }, +// "stamp": { "show": true, "seconds": 3, "position": "top-left" }, // "tally": { "show": true, "position": "right" } } // // `claim` is its own key: an entry's `verdict` is the clip review's @@ -46,7 +46,9 @@ export const TALLY_POSITIONS = Object.freeze(["right", "left"]); */ export const FACTCHECK_DEFAULTS = Object.freeze({ verdicts: VERDICT_DEFAULTS, - stamp: Object.freeze({ seconds: 3, position: "top-left" }), + // `show: false` draws no stamp at all -- no composition, no overlay -- and + // the tally still counts each claim at the second its stamp would have landed. + stamp: Object.freeze({ show: true, seconds: 3, position: "top-left" }), tally: Object.freeze({ show: true, position: "right" }), }); @@ -111,7 +113,8 @@ export function validateFactcheck(f, where = "render.chrome.factcheck") { unknownKeys(f[key], allowed, `${where}.${key}`, errors); check(f[key]); }; - sub("stamp", ["seconds", "position"], (s) => { + sub("stamp", ["show", "seconds", "position"], (s) => { + if (s.show !== undefined && typeof s.show !== "boolean") errors.push(`${where}.stamp.show must be true or false`); const [lo, hi] = FACTCHECK_LIMITS.seconds; if (s.seconds !== undefined && !numIn(s.seconds, lo, hi)) errors.push(`${where}.stamp.seconds must be from ${lo} to ${hi}`); if (s.position !== undefined && !STAMP_POSITIONS.includes(s.position)) { @@ -230,6 +233,24 @@ export function stampSchedule({ segments, D, total, render }) { }); } +/** + * Are the stamps DRAWN: the schedule stamps a claim and `stamp.show` is on. + * With it off the schedule still carries its stamps -- the tally counts at + * each one's `landed` -- but no stamp composition is rendered or laid. + */ +export function stampsDrawn(schedule, render) { + return !!schedule?.factcheck?.stamps?.length && resolveFactcheck(render).stamp.show !== false; +} + +/** + * The shape a claimed clip's pip takes (`deck.pip.color: "verdict"`), one per + * verdict in VERDICTS order, so a viewer who cannot tell the colours apart + * can still tell the verdicts apart. The tally's cells carry the same shape. + */ +export const VERDICT_SHAPES = Object.freeze(Object.fromEntries( + VERDICTS.map((v, i) => [v, ["circle", "diamond", "square", "triangle", "ring"][i] ?? "circle"]), +)); + /** `stampSchedule`'s stamps as a schedule writes them: seconds to the millisecond. */ export function roundStamps(stamps) { const round = (v) => Math.round(v * 1000) / 1000; diff --git a/umtool/report-to-video/factcheck.test.mjs b/umtool/report-to-video/factcheck.test.mjs @@ -94,12 +94,12 @@ test("validateClaims: shape, never on a teaser, one verdict per claim id; the re test("resolveFactcheck: every default, a verdict's label and colour filled on their own", () => { assert.deepEqual(resolveFactcheck(RENDER), { verdicts: Object.fromEntries(VERDICTS.map((v) => [v, { ...FACTCHECK_DEFAULTS.verdicts[v] }])), - stamp: { seconds: 3, position: "top-left" }, + stamp: { show: true, seconds: 3, position: "top-left" }, tally: { show: true, position: "right" }, }); const f = resolveFactcheck({ chrome: { ...CHROME, factcheck: { verdicts: { PARTLY: { label: "Half true" } }, stamp: { seconds: 5 } } } }); assert.deepEqual(f.verdicts.PARTLY, { label: "Half true", color: FACTCHECK_DEFAULTS.verdicts.PARTLY.color }); - assert.deepEqual(f.stamp, { seconds: 5, position: "top-left" }); + assert.deepEqual(f.stamp, { show: true, seconds: 5, position: "top-left" }); }); test("validateChrome refuses a bad factcheck block in sentences, unknown keys included", () => { diff --git a/umtool/report-to-video/lint.mjs b/umtool/report-to-video/lint.mjs @@ -78,7 +78,7 @@ import { existsSync } from "node:fs"; import path from "node:path"; import { deckOn, deckQrUrl, postArchiveUrl, postNativeId, postQrUrl, resolveDeck, teaserLines, - validateCutEdits, validatePosts, validateTeasers, + validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, } from "./deck.mjs"; import { validateClaims } from "./factcheck.mjs"; import { validateThreadEntries } from "./threads.mjs"; @@ -247,6 +247,8 @@ export function validatorErrors(whole) { ]; if (deckOn(whole.render)) { errors.push(...validatePosts(whole.posts, whole.timeline ?? [], whole.render).map((m) => `posts: ${m}`)); + // The deck's markers against the whole timeline, as the build refuses them. + errors.push(...validateDeckMarkers(whole)); } return errors; } diff --git a/umtool/report-to-video/verify-build.mjs b/umtool/report-to-video/verify-build.mjs @@ -21,6 +21,7 @@ import path from "node:path"; import { postsRegions, selectVariant, variantPaths } from "./build-video.mjs"; import { deckGeometry, deckOn, frameCount, postsGeometry, resolveDeck, teaserSeconds, transitionOf } from "./deck.mjs"; import { statsClips } from "./stats.mjs"; +import { stampsDrawn } from "./factcheck.mjs"; import { frameKeyOf, framesOf } from "./prune-frames.mjs"; import { montageSplit, resolveMontage } from "./montage.mjs"; import { applyMontageRulings, readMontageRulings } from "./montage-rulings.mjs"; @@ -172,9 +173,10 @@ export async function verifyDeck(variantDir, render, file, problems, manifest = problems.push(`the posts feed never pauses the cut, but the schedule holds ${held.join(", ") || "nothing"} and moves ${schedule.moves?.length ?? 0}`); } } - // The fact-check stamps: one sequence for the whole cut, as long as the deck's. + // The fact-check stamps: one sequence for the whole cut, as long as the + // deck's -- unless they are off (`stamp.show: false`), when none is drawn. let stamp = null; - if (schedule.factcheck?.stamps?.length) { + if (stampsDrawn(schedule, render)) { const dir = path.join(variantDir, "chrome", "stamp-frames"); const got = await countFrames(dir); stamp = { frames: got, expectedFrames: want, stamps: schedule.factcheck.stamps.length };