Archilyzer · Source

archilyzer

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

commit d8d24c4a6b2641b17e7b6fc95638d6290bf5003a
parent 6e178040801fb0b5771a591960b2eff5667e2f61
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 24 Oct 2026 04:49:16 -0400

Merge lane/deck-claims: claim checks on the deck (his explicit claims against the record: a count over a window or per span, and goalposts that move)

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

Diffstat:
Meditor/CHANGELOG.md | 1+
Mumtool/app/api/report/chrome/route.ts | 31++++++++++++++++++++++++++++++-
Aumtool/components/projects/DeckClaimsEditor.tsx | 358+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/OnscreenSection.tsx | 61++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/components/projects/review/ClipKnobs.tsx | 5++++-
Mumtool/docs/knobs.md | 30++++++++++++++++++++++++++++++
Aumtool/e2e/deck-claims.spec.ts | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/clipEditorTypes.ts | 2+-
Mumtool/lib/report/knobs.mjs | 13++++++++++---
Mumtool/lib/report/knobsCli.mjs | 19++++++++++++++++---
Mumtool/lib/report/manifest.mjs | 9+++++++--
Mumtool/lib/report/onscreen.mjs | 21++++++++++++++++++---
Mumtool/lib/report/onscreen.test.mjs | 4++--
Mumtool/report-to-video/build-video.mjs | 11++++++++++-
Aumtool/report-to-video/chrome-claims.mjs | 393+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/chrome-deck.mjs | 30++++++++++++++++++++++++------
Mumtool/report-to-video/chrome-finale.mjs | 31++++++++++++++++++++++++++-----
Aumtool/report-to-video/claims.mjs | 255+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/deck-claims.test.mjs | 339+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/deck.mjs | 389+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/report-to-video/factcheck.mjs | 21+++++++++++++++++----
Mumtool/report-to-video/finale.mjs | 56++++++++++++++++++++++++++++++++++++++++----------------
Mumtool/report-to-video/lint.mjs | 6+++++-
Mumtool/report-to-video/package.json | 1+
24 files changed, 2150 insertions(+), 57 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- **A report video can set a subject's own claims against the record on its timeline.** A count claim (`“less than ten” in a year`) draws a band over the dates it is about on the on-screen panel's timeline, dims the rest of the timeline, lights each clip that carries the counter's stamps in date order with its count under it, and counts up to the total under his words in the panel (`19 seizures on camera`). With a **per** (a day, a week, a month) it lights every span that holds that many or more instead (`12 in a day`, `4 in a week`). A goalpost (`“3–5 weeks”` → `“6–8 weeks”`) draws a hollow bracket over the dates each deadline implies; when he moves it, the old one stays dashed and a copy of it moves to the new dates, off the timeline's end with the dates written when they are past its last clip. The finale's large timeline shows every claim at the end. A stamp can be dated by the day the event happened rather than the clip's day (**happened** in the clip editor's Marks). In umtool: the On-screen section's **claim checks** (beside the markers), with **use the playhead** and the build's own checks shown as each field is typed. From a terminal: `umtool look <project> deck.claims='[…]'` and `umtool set <project> <clip> claim.eventDate=2026-09-22`. When the record does not contradict a claim the build prints a note. A video without claims builds exactly as before. Needs a restart of umtool and a rebuild of the video. - **umtool plays a whole report video, or one take of it, in the browser without rendering it, and takes timecoded notes as it plays.** The Cut tab's **Play the cut** (and **Play** beside each take on the takes page) opens `/projects/<project>/play`: every clip plays in order from its fetched window, with the on-screen panel, the tally, the stamps, the markers and the finale drawn over it as the live preview draws them, on one clock across the whole cut, the next clip loaded behind the one playing. A take plays the project's video as it is now with the take's changes, including a take with its own clip list and one a recipe names that was never rendered; **Blurred clips: uncensored** on a take plays its clips as recorded. Under the picture, the **reel strip** shows the whole cut at once: a cell per clip or card as wide as it plays, shaded by the recording's date, hatched when its media is not fetched, the sections' boundaries with their first date, the counter (the tally) drawn as a staircase with its total at the end and at the playhead, and each note as a pin; click or drag on it to move through the cut. Under the strip, **Now** shows what the clip on screen says with the spoken line lit, and which clip comes next. Space plays and pauses, J K L go back, pause and play (L again is faster, at the voice's own pitch), ← and → move 5 seconds, N and P move between clips, [ and ] between notes, and ? lists the keys. A line under the picture lists what it does not do: each crossfade is a hard cut at its middle, cards and teasers are placeholders with their heading, edges are not snapped to silence, and the sound is the recording's. A clip with nothing fetched says "No media for this clip — fetch it" and the video plays on. M (or **Note at 09:44**) saves a note at that second of the cut, naming the clip on screen, its second in the recording, the take, and what it asks for (Trim, Cut, Move, Fact, Look or Other); playback pauses while you write and goes on when it is saved (**Pause while I write**). The notes list in cut order (open, all or resolved), a timecode plays from there, `umtool notes <project>` prints each with where it was taken and what it asks for, and **Send to the assistant** on a note (or **Send N open notes to the assistant**) asks the video assistant, whose reply lands on the note and whose edits wait for **Apply all**. With no assistant configured the button says why. Needs a restart of umtool. - **umtool's clip walk goes through the recordings in date order.** `p`/`n` and the Cut tab's walk used to follow the cut, which can open on a finale and end years earlier. The walk now goes by each clip's date (its on-screen date, else the recording's upload date), with a recording's clips together in the order they come in it, so what is left out between two clips, or split off into a clip of its own, comes up next. The cut's own order is unchanged. - **A clip from a stream captured live can be trimmed again in umtool's clip editor.** Such a stream's record has no length, which umtool passed on as zero, so every drag of a clip's edge snapped back to the left with "that is the edge of what is cached". An unknown length is now treated as unknown. diff --git a/umtool/app/api/report/chrome/route.ts b/umtool/app/api/report/chrome/route.ts @@ -1,5 +1,5 @@ import { withEditNotes } from "@/lib/report/guard"; -import { ChromeRefused, StaleToken, StructureRefused, manifestToken, updateChrome, updateDeckMarkers } from "@/lib/report/manifest.mjs"; +import { ChromeRefused, StaleToken, StructureRefused, manifestToken, updateChrome, updateDeckKeys, updateDeckMarkers } from "@/lib/report/manifest.mjs"; import { MARKER_ALIGNS, MARKER_LAYOUTS } from "@/lib/report/knobs.mjs"; import { invalidateProjects } from "@/lib/projects"; import { resolveReport } from "@/lib/report/serve.mjs"; @@ -20,6 +20,11 @@ export const dynamic = "force-dynamic"; // deck's markers and/or their layout (video knobs: the Markers editor, `umtool // look deck.markers=…`), leaving the rest of the deck as it is -- a // structural edit, snapshotted first (lib/report/manifest.mjs updateDeckMarkers). +// +// PUT { project, token, claims } (no `chrome`) sets only the deck's claim +// checks (`deck.claims`, report-to-video claims.mjs: the claims editor, +// `umtool look deck.claims=…`); `claims: []` or null removes them -- the +// same writer `umtool look` uses (updateDeckKeys), refused in the build's words. type Body = Record<string, unknown>; @@ -60,6 +65,7 @@ export async function PUT(request: Request) { return Response.json({ error: "expected JSON" }, { status: 400 }); } if (!("chrome" in body) && ("markers" in body || "markerLayout" in body)) return putMarkers(body); + if (!("chrome" in body) && "claims" in body) return putClaims(body); if (!("chrome" in body)) { return Response.json({ error: "chrome is required — an object, or null to turn the deck off" }, { status: 400 }); } @@ -119,3 +125,26 @@ async function putMarkers(body: Body) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); } } + +/** The claims editor's save: `deck.claims`, nothing else of the deck. */ +async function putClaims(body: Body) { + const r = await resolveReport(String(body.project ?? "")); + if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); + const claims = body.claims; + if (claims !== null && !Array.isArray(claims)) return Response.json({ error: "claims must be a list, or null to remove them" }, { status: 400 }); + try { + const { result: res, editNotes } = await withEditNotes(r.project, () => + updateDeckKeys(r.project.dir, { claims: claims && claims.length ? claims : null }, { token: typeof body.token === "string" ? body.token : null }), + ); + // revisions/ changed: the project page lists them. + invalidateProjects(); + const deck = (res.deck ?? {}) as { claims?: unknown[] }; + return Response.json({ ok: true, claims: deck.claims ?? [], token: res.token, editNotes }, { headers: noStore }); + } catch (e) { + if (e instanceof StaleToken) { + return Response.json({ error: e.message, expected: e.expected, got: e.got, stale: true }, { status: 409 }); + } + if (e instanceof StructureRefused) return Response.json({ error: e.message, errors: e.errors }, { status: 400 }); + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); + } +} diff --git a/umtool/components/projects/DeckClaimsEditor.tsx b/umtool/components/projects/DeckClaimsEditor.tsx @@ -0,0 +1,358 @@ +"use client"; + +import { useEffect, useMemo, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; +import { DECK_CLAIM_LIMITS, DECK_CLAIM_OPS, DECK_CLAIM_PERS, deckClaimShapeErrors } from "umtool-report-to-video/claims"; + +// THE DECK'S CLAIM CHECKS (render.chrome.deck.claims; report-to-video +// claims.mjs, DESIGN 2026-10-24): his explicit claims drawn against the record +// on the footer's rail. A COUNT claim -- a number over a window of dates +// (`“less than ten” in a year`), the fact-check tally's stamps its record, or +// with `per` the spans that hold more than he said (`“doesn't have multiple +// seizures a week”`). A GOALPOST -- a deadline he set and moved: each step his +// words, the day it runs from and the two durations of its due window. +// +// Each claim is said in a clip at a SOURCE second ("use the playhead" takes +// the scrubber's clip and second). Validation is the build's own +// (claims.mjs deckClaimShapeErrors -- dependency-free, so this bundle takes +// it), shown under each claim as it is typed; the clips it names are checked +// against the cut's here, and the writer refuses in the build's words. One +// save writes `deck.claims` and nothing else of the deck (PUT +// /api/report/chrome { claims }), the writer `umtool look deck.claims=…` uses. + +export type DeckClaim = Record<string, unknown> & { kind: string }; +export type ClaimClip = { id: string; label: string; day: string | null; from?: number }; +/** The record a preview's schedule says for one claim (deck.mjs claimsSchedule's item). */ +export type ClaimRecord = { + kind: string; + n: number; + total?: number; + noun?: string; + window?: { from: string; to: string }; + spans?: { label: string }[]; + holds?: boolean; + steps?: { segment: string; dueText: string }[]; +}; + +type Step = { at: string; t: string; said: string; from: string; due0: string; due1: string }; +type CountRow = { kind: "count"; at: string; t: string; said: string; from: string; to: string; tally: string; per: string; op: string; value: string }; +type GoalRow = { kind: "goalpost"; label: string; steps: Step[] }; +type Row = CountRow | GoalRow; + +const input = + "rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[11px] text-[var(--color-text)] outline-none focus:border-[var(--color-sel)]"; + +const str = (v: unknown) => (v === undefined || v === null ? "" : String(v)); +const num = (s: string): number | undefined => (s.trim() === "" ? undefined : Number(s)); + +function rowOf(c: DeckClaim): Row { + if (c.kind === "goalpost") { + const steps = Array.isArray(c.steps) ? (c.steps as Record<string, unknown>[]) : []; + return { + kind: "goalpost", + label: str(c.label), + steps: steps.map((s) => { + const due = Array.isArray(s.due) ? (s.due as unknown[]) : []; + return { at: str(s.at), t: str(s.t), said: str(s.said), from: str(s.from), due0: str(due[0]), due1: str(due[1]) }; + }), + }; + } + const w = (c.window ?? {}) as Record<string, unknown>; + const cl = (c.claim ?? {}) as Record<string, unknown>; + return { + kind: "count", at: str(c.at), t: str(c.t), said: str(c.said), from: str(w.from), to: str(w.to), tally: str(c.tally), + per: str(c.per), op: str(cl.op), value: str(cl.value), + }; +} + +/** A row as the manifest writes it: blanks left out, numbers as numbers. */ +function claimOf(r: Row): DeckClaim { + if (r.kind === "goalpost") { + return { + kind: "goalpost", + ...(r.label.trim() ? { label: r.label.trim() } : {}), + steps: r.steps.map((s) => ({ + at: s.at, t: num(s.t), said: s.said.trim(), ...(s.from.trim() ? { from: s.from.trim() } : {}), due: [s.due0.trim(), s.due1.trim()], + })), + }; + } + return { + kind: "count", at: r.at, t: num(r.t), said: r.said.trim(), window: { from: r.from.trim(), to: r.to.trim() }, tally: r.tally.trim(), + ...(r.per ? { per: r.per } : {}), + ...(r.op ? { claim: { op: r.op, value: num(r.value) } } : {}), + }; +} + +/** A year before a YYYY-MM-DD, as one: the default window of a count claim said on that day. */ +const yearBefore = (d: string) => (/^\d{4}-\d{2}-\d{2}$/.test(d) ? `${Number(d.slice(0, 4)) - 1}${d.slice(4)}` : ""); + +const PER_NAMES: Record<string, string> = { P1D: "a day", P1W: "a week", P1M: "a month" }; + +export default function DeckClaimsEditor({ + claims, + clips, + verdicts, + playhead, + record, + busy, + save, +}: { + claims: DeckClaim[]; + clips: ClaimClip[]; + /** The tally's words a count claim may name (this cut's verdict labels). */ + verdicts: string[]; + /** The scrubber's clip and source second, or null when it is not on a clip. */ + playhead: () => { clip: string; second: number } | null; + /** The preview schedule's claim items (deck.mjs claimsSchedule), by their index in the saved list. */ + record: ClaimRecord[]; + busy: boolean; + save: (claims: DeckClaim[] | null) => Promise<boolean>; +}) { + const savedKey = JSON.stringify(claims); + const [rows, setRows] = useState<Row[]>(() => claims.map(rowOf)); + const [dirty, setDirty] = useState(false); + useEffect(() => { + setRows(claims.map(rowOf)); + setDirty(false); + // The saved value, by its text: a re-read with the same claims keeps the edits. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [savedKey]); + + const change = (next: Row[]) => { + setRows(next); + setDirty(true); + }; + const put = (i: number, patch: Partial<CountRow> | Partial<GoalRow>) => change(rows.map((r, j) => (j === i ? ({ ...r, ...patch } as Row) : r))); + const putStep = (i: number, k: number, patch: Partial<Step>) => + change(rows.map((r, j) => (j === i && r.kind === "goalpost" ? { ...r, steps: r.steps.map((s, m) => (m === k ? { ...s, ...patch } : s)) } : r))); + + const here = () => { + const p = playhead(); + if (p) return { at: p.clip, t: String(p.second) }; + const c = clips[0]; + return { at: c?.id ?? "", t: c?.from !== undefined ? String(c.from) : "" }; + }; + const dayOf = (id: string) => clips.find((c) => c.id === id)?.day ?? ""; + const addCount = () => { + const h = here(); + const to = dayOf(h.at); + change([...rows, { kind: "count", ...h, said: "", from: yearBefore(to), to, tally: verdicts[0] ?? "", per: "", op: "", value: "" }]); + }; + const addGoal = () => change([...rows, { kind: "goalpost", label: "", steps: [{ ...here(), said: "", from: "", due0: "P3W", due1: "P5W" }] }]); + + // The build's validator, as typed; and the clips each claim names, against this cut's. + const list = useMemo(() => rows.map(claimOf), [rows]); + const problems = useMemo(() => { + const all = deckClaimShapeErrors(list, "claims"); + const ids = new Set(clips.map((c) => c.id)); + rows.forEach((r, i) => { + if (r.kind === "count" && r.at && !ids.has(r.at)) all.push(`claims[${i}].at names ${r.at}, which is not a clip in this cut`); + if (r.kind === "goalpost") r.steps.forEach((s, k) => s.at && !ids.has(s.at) && all.push(`claims[${i}].steps[${k}].at names ${s.at}, which is not a clip in this cut`)); + }); + return all; + }, [list, rows, clips]); + const problemsOf = (i: number) => problems.filter((p) => p.startsWith(`claims[${i}]`)).map((p) => p.replace(`claims[${i}]`, "").replace(/^\./, "")); + const listProblems = problems.filter((p) => !/^claims\[\d+\]/.test(p)); + + const clipSelect = (value: string, onChange: (v: string) => void, testId: string) => ( + <select data-testid={testId} value={value} onChange={(e) => onChange(e.target.value)} className={`${input} max-w-[14em]`}> + {!clips.some((c) => c.id === value) && <option value={value}>{value || "(pick a clip)"}</option>} + {clips.map((c) => ( + <option key={c.id} value={c.id}> + {c.id} — {c.label} + </option> + ))} + </select> + ); + const atPlayhead = (onSet: (at: string, t: string) => void, testId: string) => ( + <button + type="button" + data-testid={testId} + onClick={() => { + const p = playhead(); + if (p) onSet(p.clip, String(p.second)); + }} + className={buttonVariants({ variant: "quiet", size: "sm" })} + title="the clip under the scrubber, and its source second there" + > + use the playhead + </button> + ); + + return ( + <div data-testid="claims-editor" className="space-y-1.5"> + <div className="flex flex-wrap items-center gap-2"> + <span className="micro">claim checks</span> + <span className="text-[11px] text-[var(--color-dim)]"> + {rows.length} of {DECK_CLAIM_LIMITS.count} + </span> + {dirty && <span className="text-[11px] text-[var(--color-dirty)]">unsaved</span>} + <button type="button" data-testid="claims-add-count" disabled={busy || rows.length >= DECK_CLAIM_LIMITS.count || !clips.length} onClick={addCount} className={buttonVariants({ size: "sm" })}> + add a count + </button> + <button type="button" data-testid="claims-add-goalpost" disabled={busy || rows.length >= DECK_CLAIM_LIMITS.count || !clips.length} onClick={addGoal} className={buttonVariants({ size: "sm" })}> + add a goalpost + </button> + <button + type="button" + data-testid="claims-save" + disabled={busy || !dirty || problems.length > 0} + onClick={() => void save(list.length ? list : null).then((ok) => ok && setDirty(false))} + className={`${buttonVariants({ variant: "outline", size: "sm" })} ml-auto`} + > + save claims + </button> + </div> + {listProblems.map((p) => ( + <p key={p} className="m-0 text-[11px] text-[var(--color-bad)]"> + {p} + </p> + ))} + {rows.length === 0 ? ( + <p className="text-[11px] text-[var(--color-dim)]">No claim checks: the rail carries no claim.</p> + ) : ( + <ol className="m-0 list-none space-y-2 p-0"> + {rows.map((r, i) => { + const errs = problemsOf(i); + const rec = !dirty ? record.find((x) => x.n === i) : undefined; + return ( + <li key={i} data-testid={`claim-row-${i}`} data-kind={r.kind} className="space-y-1 rounded border border-[var(--color-line)] p-1.5 text-[11px] text-[var(--color-dim)]"> + <div className="flex flex-wrap items-center gap-1.5"> + <span className="num w-4 text-right font-mono">{i + 1}</span> + <span className="font-mono text-[var(--color-text)]">{r.kind}</span> + {r.kind === "count" ? ( + <> + {clipSelect(r.at, (v) => put(i, { at: v }), `claim-at-${i}`)} + <label className="flex items-center gap-1"> + at + <input data-testid={`claim-t-${i}`} value={r.t} inputMode="decimal" onChange={(e) => put(i, { t: e.target.value })} className={`${input} w-20 font-mono`} title="the SOURCE second he says it" /> + s + </label> + {atPlayhead((at, t) => put(i, { at, t }), `claim-playhead-${i}`)} + </> + ) : ( + <input data-testid={`claim-label-${i}`} value={r.label} placeholder="what it is (optional)" onChange={(e) => put(i, { label: e.target.value })} className={`${input} w-52`} /> + )} + <button type="button" data-testid={`claim-remove-${i}`} onClick={() => change(rows.filter((_, j) => j !== i))} className={`${buttonVariants({ variant: "quiet", size: "sm" })} ml-auto`}> + remove + </button> + </div> + {r.kind === "count" ? ( + <div className="flex flex-wrap items-center gap-1.5 pl-5"> + <input data-testid={`claim-said-${i}`} value={r.said} placeholder="“his words”" onChange={(e) => put(i, { said: e.target.value })} className={`${input} w-64`} /> + <label className="flex items-center gap-1"> + window + <input data-testid={`claim-from-${i}`} value={r.from} placeholder="YYYY-MM-DD" onChange={(e) => put(i, { from: e.target.value })} className={`${input} w-24 font-mono`} /> + – + <input data-testid={`claim-to-${i}`} value={r.to} placeholder="YYYY-MM-DD" onChange={(e) => put(i, { to: e.target.value })} className={`${input} w-24 font-mono`} /> + </label> + <label className="flex items-center gap-1"> + record + <input data-testid={`claim-tally-${i}`} list="claim-verdicts" value={r.tally} onChange={(e) => put(i, { tally: e.target.value })} className={`${input} w-28`} title="the tally's verdict whose stamps are the record: its label or its key" /> + </label> + <label className="flex items-center gap-1"> + per + <select data-testid={`claim-per-${i}`} value={r.per} onChange={(e) => put(i, { per: e.target.value })} className={input}> + <option value="">none (the whole window)</option> + {DECK_CLAIM_PERS.map((p) => ( + <option key={p} value={p}> + {PER_NAMES[p] ?? p} + </option> + ))} + </select> + </label> + <label className="flex items-center gap-1" title="what he claims of the count, for the lint to hold the record to (optional)"> + claims + <select data-testid={`claim-op-${i}`} value={r.op} onChange={(e) => put(i, { op: e.target.value })} className={input}> + <option value="">—</option> + {DECK_CLAIM_OPS.map((o) => ( + <option key={o} value={o}> + {o} + </option> + ))} + </select> + {r.op && <input data-testid={`claim-value-${i}`} value={r.value} inputMode="decimal" onChange={(e) => put(i, { value: e.target.value })} className={`${input} w-12 font-mono`} />} + </label> + </div> + ) : ( + <ol className="m-0 list-none space-y-1 p-0 pl-5"> + {r.steps.map((s, k) => ( + <li key={k} data-testid={`claim-step-${i}-${k}`} className="flex flex-wrap items-center gap-1.5"> + <span className="font-mono">step {k + 1}</span> + {clipSelect(s.at, (v) => putStep(i, k, { at: v }), `claim-step-at-${i}-${k}`)} + <label className="flex items-center gap-1"> + at + <input data-testid={`claim-step-t-${i}-${k}`} value={s.t} inputMode="decimal" onChange={(e) => putStep(i, k, { t: e.target.value })} className={`${input} w-20 font-mono`} /> + s + </label> + {atPlayhead((at, t) => putStep(i, k, { at, t }), `claim-step-playhead-${i}-${k}`)} + <input data-testid={`claim-step-said-${i}-${k}`} value={s.said} placeholder="“his words”" onChange={(e) => putStep(i, k, { said: e.target.value })} className={`${input} w-32`} /> + <label className="flex items-center gap-1"> + from + <input data-testid={`claim-step-from-${i}-${k}`} value={s.from} placeholder={dayOf(s.at) || "the clip's date"} onChange={(e) => putStep(i, k, { from: e.target.value })} className={`${input} w-24 font-mono`} /> + </label> + <label className="flex items-center gap-1" title="the due window: two durations from that day, the soonest first (P3W, P5W; P<n>D, P<n>W, P<n>M)"> + due + <input data-testid={`claim-step-due0-${i}-${k}`} value={s.due0} onChange={(e) => putStep(i, k, { due0: e.target.value })} className={`${input} w-12 font-mono`} /> + – + <input data-testid={`claim-step-due1-${i}-${k}`} value={s.due1} onChange={(e) => putStep(i, k, { due1: e.target.value })} className={`${input} w-12 font-mono`} /> + </label> + {r.steps.length > 1 && ( + <button + type="button" + data-testid={`claim-step-remove-${i}-${k}`} + onClick={() => change(rows.map((x, j) => (j === i && x.kind === "goalpost" ? { ...x, steps: x.steps.filter((_, m) => m !== k) } : x)))} + className={buttonVariants({ variant: "quiet", size: "sm" })} + > + remove step + </button> + )} + </li> + ))} + {r.steps.length < DECK_CLAIM_LIMITS.steps && ( + <li> + <button + type="button" + data-testid={`claim-step-add-${i}`} + onClick={() => { + const last = r.steps[r.steps.length - 1]; + const step = { ...here(), said: "", from: "", due0: last?.due0 ?? "P3W", due1: last?.due1 ?? "P5W" }; + change(rows.map((x, j) => (j === i && x.kind === "goalpost" ? { ...x, steps: [...x.steps, step] } : x))); + }} + className={buttonVariants({ variant: "quiet", size: "sm" })} + > + add a step (he moves it) + </button> + </li> + )} + </ol> + )} + {errs.length > 0 && ( + <ul data-testid={`claim-errors-${i}`} className="m-0 list-none space-y-0.5 p-0 pl-5 text-[var(--color-bad)]"> + {errs.map((e) => ( + <li key={e}>{e}</li> + ))} + </ul> + )} + {rec && ( + <p data-testid={`claim-record-${i}`} className="m-0 pl-5 text-[var(--color-meter)]"> + {rec.kind === "count" + ? `record: ${rec.total} ${rec.noun} in ${rec.window?.from}–${rec.window?.to}` + + (rec.spans ? ` · ${rec.spans.length ? rec.spans.map((s) => s.label).join(", ") : "no span"}` : "") + + (rec.holds === undefined ? "" : rec.holds ? " · it does not contradict him" : " · it contradicts him") + : `due: ${(rec.steps ?? []).map((s) => s.dueText).join(" → ")}`} + </p> + )} + </li> + ); + })} + </ol> + )} + <datalist id="claim-verdicts"> + {verdicts.map((v) => ( + <option key={v} value={v} /> + ))} + </datalist> + </div> + ); +} diff --git a/umtool/components/projects/OnscreenSection.tsx b/umtool/components/projects/OnscreenSection.tsx @@ -4,6 +4,7 @@ import GeneratedBanner from "@/components/notes/GeneratedBanner"; import { TimedVideo } from "@/components/notes/TimedNotes"; import StructureEditors from "./StructureEditors"; import MarkersEditor, { type Marker } from "./MarkersEditor"; +import DeckClaimsEditor, { type ClaimRecord, type DeckClaim } from "./DeckClaimsEditor"; import { MANIFEST_CHANGED } from "./timelineApi"; import { DraftAlternatives, DraftBadge, announceDraftsChanged, useDrafts } from "./drafts"; import { announceNotesChanged, wroteNotes } from "@/components/notes/NotesProvider"; @@ -65,6 +66,8 @@ export type DeckSegment = { hold?: number; /** The fact-check claim this entry carries; absent when none. */ claim?: Claim; + /** The source second the segment starts at, when a stamp or a deck claim is timed in it. */ + sourceFrom?: number; }; /** One claim's verdict stamp, in the cut's clock (factcheck.mjs stampSchedule). */ export type Stamp = { claim: string; verdict: string; segment: string; at: number; landed: number; out: [number, number] }; @@ -82,6 +85,8 @@ export type DeckSchedule = { moves?: FootageMove[]; /** The fact-check stamps, when an entry carries a claim. */ factcheck?: { stamps: Stamp[] }; + /** The deck's claim checks (`deck.claims`), when it carries one: each claim's record. */ + deckClaims?: { items: ClaimRecord[] }; }; /** A placed post: the popup's `appear` and `out`, or the feed's tick-in, `in`. */ export type PostSlot = { id: string; segment: string; slot: number; of: number; appear?: number; out?: [number, number]; in?: number }; @@ -104,6 +109,8 @@ export type DeckPreviewDoc = { stamp?: { geometry: Rect; src?: string; error?: string }; /** The finale, when the cut has one: a full-frame composition for its window (`from`–`to`, cut seconds), laid last. */ finale?: { geometry: Rect; from: number; to: number; src?: string; error?: string }; + /** Each verdict's word as the tally prints it. */ + verdictLabels?: Record<string, string>; }; /** An unsaved change to a post, as PUT /api/report/posts takes it. */ export type PostPatch = { attachTo?: string | null; hide?: boolean }; @@ -739,7 +746,7 @@ type PostRow = { effective: PostWhere | null; timing: { segment: string; slot: number; of: number; appear?: number; out?: [number, number]; in?: number } | null; }; -type ClipOption = { id: string; label: string; day: string | null }; +type ClipOption = { id: string; label: string; day: string | null; from?: number }; /** A post's row as the form holds it: `attachTo` "" is the automatic clip. */ type PostDraft = { attachTo: string; hide: boolean }; type JobView = { @@ -1085,6 +1092,42 @@ export default function OnscreenSection({ [project, queued, loadChrome, recompose], ); + /** The claims editor's save: `deck.claims`, nothing else of the deck. */ + const putClaims = useCallback( + (claims: DeckClaim[] | null) => + queued(async () => { + setBusy("saving…"); + setNote(null); + const r = await fetch("/api/report/chrome", { + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, claims, token: token.current }), + }); + const j = (await r.json()) as Record<string, unknown>; + if (wroteNotes(j)) announceNotesChanged(project); + setBusy(null); + if (!r.ok) { + if (j.stale) { + setStale(true); + setNote(STALE); + } else { + setErrors((j.errors as string[]) ?? []); + setNote(`could not save the claim checks: ${String(j.error ?? r.status)}`); + } + return false; + } + token.current = String(j.token ?? ""); + setErrors([]); + setStale(false); + await loadChrome(); + await recompose(); + const n = claims?.length ?? 0; + setNote(`saved ${n} claim check${n === 1 ? "" : "s"}`); + return true; + }), + [project, queued, loadChrome, recompose], + ); + const toggle = useCallback( async (on: boolean) => { if (!doc) return; @@ -2172,6 +2215,22 @@ export default function OnscreenSection({ save={putMarkers} /> + <DeckClaimsEditor + claims={((doc.chrome?.deck as { claims?: DeckClaim[] } | undefined)?.claims ?? []) as DeckClaim[]} + clips={clips} + verdicts={Object.values(preview?.verdictLabels ?? {})} + playhead={() => { + // The scrubber's clip, and the source second under it. + const clip = current ? clips.find((c) => c.id === current.id) : undefined; + if (!current || !clip) return null; + const from = current.sourceFrom ?? clip.from; + return from === undefined ? null : { clip: clip.id, second: Math.round((from + (t - current.start)) * 100) / 100 }; + }} + record={schedule?.deckClaims?.items ?? []} + busy={!!busy} + save={putClaims} + /> + <div className="space-y-1"> <span className="micro">the built video</span> {typeof finalV === "number" ? ( diff --git a/umtool/components/projects/review/ClipKnobs.tsx b/umtool/components/projects/review/ClipKnobs.tsx @@ -12,7 +12,8 @@ import type { BlurDefaults, ClipAudio, ClipBlur, KnobDefaults, MarkVerdict, Mark // the source second it lands and the tally steps (`at`, Set // at playhead, Shift+S for the selected mark), how long it // stays (`hold`), whether it is drawn (`stamp`), how much it -// counts (`count`), what it says (`label`), remove; Add mark +// counts (`count`), what it says (`label`), the day the +// event happened when not the clip's (`eventDate`), remove; Add mark // at playhead (Shift+M); Clear (every mark) // Audio the clip's sound at the encode: a sync nudge in ms (+ = // later), gain in dB, fades in s; "listen" replays the 3 s @@ -382,6 +383,8 @@ export function MarksBox({ <StampToggle on={m.stamp !== false} busy={busy} onSet={(on) => write({ op: "claim", clip: clipId, mark: m.id, knobs: { stamp: on ? null : false } }, on ? `${m.id}: stamp drawn` : `${m.id}: counts, no stamp`)} /> <KnobField name="count" label="count" step={1} value={m.count} placeholder={String(defaults?.count ?? 1)} busy={busy} onSave={(v) => setKnobs(m.id, { count: numOrNull(v) }, v ? `${m.id} counts ${v}` : `${m.id} counts 1`)} /> <KnobField name="label" label="label" kind="text" maxLength={20} value={m.label} placeholder={word} busy={busy} onSave={(v) => setKnobs(m.id, { label: v || null }, v ? `${m.id}'s stamp says “${v}”` : `${m.id}'s stamp says the verdict's word`)} /> + {/* The day the event happened, when not the clip's: a deck claim's window dates it so. */} + <KnobField name="eventDate" label="happened" kind="text" maxLength={10} value={m.eventDate} placeholder="the clip's day" busy={busy} onSave={(v) => setKnobs(m.id, { eventDate: v || null }, v ? `${m.id} happened ${v}` : `${m.id} happened on its clip's day`)} /> </div> {m.stampsOn && m.stampsOn !== clipId && ( <p data-stamps-on={m.stampsOn} className="m-0 text-muted"> diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -20,6 +20,7 @@ that generates it ([notes.md](notes.md)). | `claim.stamp` — `false`: the claim counts, no stamp is drawn | Marks, **draw the stamp** | `claim.stamp=false` | same | | `claim.count` — how much the tally steps (1–99; default 1) | Marks, **count** | `claim.count=2` | same | | `claim.label` — this stamp's text (≤ 20; default the verdict's stamp word) | Marks, **label** | `claim.label="2 SEIZURES"` | same | +| `claim.eventDate` — `YYYY-MM-DD`, the day the event this mark counts happened when it is not the clip's (a seizure he tells of on 8 Oct that was on 22 Sep): a deck claim's window dates the mark by it ([Claim checks](#claim-checks-on-the-rail)); the stamp lands where it always did | Marks, **happened** | `claim.eventDate=2026-09-22` (`--mark <id>` for another mark) | same | | marks — more than one stamp and count on a clip (≤ 8): see [Marks](#marks) | Marks: **Add mark at playhead** (Shift+M), a mark's verdict, **Remove**, **Clear** | `mark.add=Episodes@190.2` `mark.remove=<id>` `mark.verdict=Grift` `marks=<json>` | `POST /api/report/clip-editor {op: "marks", clip, add \| remove \| mark+verdict \| set}` | | `audio.offset` — ms, + = the sound later (−2000…2000) | clip editor, **Audio**: **sync**, the ±10/±40 nudges, **listen** (the 3 s around the playhead) | `umtool set <p> <clip> audio.offset=-40` | `POST /api/report/clip-editor {op: "audio", clip, audio: {offset}}` | | `audio.gain` — dB (−20…20) | Audio, **gain** | `audio.gain=-3` | same | @@ -118,6 +119,7 @@ that mentions the seizure in question and one before it. The Marks box is on eve | `render.chrome.deck.markers[]` — `{after, label ≤ 24, color?, align?}`, at most 12; `align` `auto` `left` `right` `center` | On-screen, **markers**: add, the clip picker, label, colour, align, ↑ ↓, remove | `umtool look <p> deck.markers='[{"after":"c03","label":"Rescue","align":"right"}]'` | `PUT /api/report/chrome {project, token, markers}` | | `render.chrome.deck.<key>` — any of the deck's own keys (`finale`, `pip`, …), as JSON; refused in the build's words when it does not know the key or the value | On-screen settings (the ones it has a field for) | `umtool look <p> deck.finale='{…}'` | — | | `render.chrome.deck.markerLayout` — `stagger` or `truncate` when labels crowd (default: stagger only when a label would truncate) | markers, **layout** | `deck.markerLayout=truncate` | `PUT /api/report/chrome {project, token, markerLayout}` | +| `render.chrome.deck.claims[]` — his explicit claims drawn against the record on the rail, at most 6: a `count` or a `goalpost` ([below](#claim-checks-on-the-rail)) | On-screen, **claim checks**: add a count / a goalpost, the clip picker, **use the playhead**, his words, the window's dates, the record's verdict, per, the claim; a goalpost's steps (**add a step**), each its from date and due durations; remove — the build's validator under each as it is typed | `umtool look <p> deck.claims='[…]'` (`deck.claims=` none) | `PUT /api/report/chrome {project, token, claims}` | | `render.blur` — `off`: every clip's picture as recorded, no caption (the uncensored variant); `on` (the default) blurs the clips that ask | Build, **Look**: **Blurred clips** | `umtool look <p> blur=off` · a take: `umtool take <p> --id uncensored --set render.blur=off` | `PUT /api/report/render {project, token, patch: {blur}}` | | `render.variants` — the ladder **Make variants** encodes: `{name, height?, crf?, maxMiB?, preset?}` (at most 12; a `maxMiB` rung takes no crf, a height there caps it); `master` is the build itself | Deliver, **Variants and sync**: Edit, Save ladder, Use the default | `umtool look <p> variants='[{"name":"master"},{"name":"720p","height":720,"crf":23}]'` | `PUT /api/report/render {project, token, variants}` | @@ -152,6 +154,34 @@ would land inside the finale counts as the finale opens and is not drawn. Withou bytes it was, `deck.finale` set or not. The render: `<out>/<variant>/chrome/finale-frames/` (a full-frame window over the run, laid last); a still: `compose-chrome.mjs <manifest> --region finale --still <cut s> --png <file>`. +## Claim checks on the rail + +`render.chrome.deck.claims` (report-to-video `claims.mjs`): a subject's explicit claims and goalpost moves, drawn +by the build on the deck's footer rail -- so the live preview, Play the cut and the render all show them, and the +finale's large rail shows each one's final state. His words in quotes and the record's numbers, in the alarm red; +no adjective on screen. + +| Key | What it is | +|---|---| +| `kind` | `count` · `goalpost` | +| count `at`, `t` | the clip he says it in, and the SOURCE second (inside the clip's play window, else a lint note) | +| count `said` | his words as drawn, in quotes (≤ 60): `“less than ten” in a year` | +| count `window` | `{from, to}`, two dates: the stretch his number is about | +| count `tally` | the fact-check verdict whose stamps are the record: its key or its label (`Seizures`). A stamp is dated by its mark's `eventDate`, else its clip's day | +| count `per` | `P1D` · `P1W` · `P1M` · absent. Absent: a band over the window, the rail outside it dimmed, the record's pips lit in date order with their counts while the number under his words counts up to the window's total. Set: every span of that length holding `claim.value` or more (2 without a `claim`; greedy, by date) lit red with its count (`12 in a day`, `4 in a week`) | +| count `claim` | `{op, value}` (`<` `<=` `>` `>=` `=`): what he claims of the count. When the record does NOT contradict it the build prints a NOTE (the operator decides); it never refuses | +| goalpost `label` | what it is (≤ 40, optional; the finale's) | +| goalpost `steps[]` | 1–4 `{at, t, said, from?, due: [d1, d2]}`: his words, the day it runs from (default the clip's), and the due window as two ISO durations (`P3W`, `P5W`; `P<n>D`/`W`/`M`). Each step draws a hollow bracket over its due window from its second; the next step leaves the old one dashed and moves a copy of it to the new window -- off the rail's right end, with its dates, when that lies past the rail's last date | + +The rail is laid by order, not by date: a date is placed between the pips either side of it. A goalpost takes a +row over the markers' (the track moves down by 22 px). From his second to his clip's end a count claim's words +replace the clip's title and source line in the deck (its QR stays). Absent `claims`, the cut is the bytes it was. + +```sh +umtool look <p> deck.claims='[{"kind":"count","at":"less-than-ten","t":903.6,"said":"“less than ten” in a year","window":{"from":"2025-10-22","to":"2026-10-22"},"tally":"Seizures","claim":{"op":"<","value":10}}]' +umtool set <p> costco-ok claim.eventDate=2026-09-22 +``` + ## Walk and preview (the clip editor) The clip editor (`/projects/<p>/clips`, a clip with **Edit**) is where a deck cut is walked: under the player, diff --git a/umtool/e2e/deck-claims.spec.ts b/umtool/e2e/deck-claims.spec.ts @@ -0,0 +1,121 @@ +import { test, expect } from "@playwright/test"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import * as urls from "./urls"; + +// --------------------------------------------------------------------------- +// The deck's claim checks (render.chrome.deck.claims; report-to-video +// claims.mjs) in the On-screen section's claims editor, beside the markers: +// - add a count claim: the build's validator speaks as it is typed (his +// words, the window's dates), the playhead fills its clip and second, a +// tally that names no verdict is refused by the writer in the build's words; +// - add a goalpost with a second step (he moves it); save; reload; edit; +// remove the count -- render.chrome.deck.claims follows each save. +// Fixture: e2e/fixtures/knobs-fixture.mjs (knobs-deck-fixture: the deck on, two clips). +// --------------------------------------------------------------------------- + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const FIXTURE = path.join(HERE, "..", ".e2e-song"); +const DECK_PROJECT = "reports/knobs-deck-fixture"; +const DECK_DIR = path.join(FIXTURE, "reports", "knobs-deck-fixture"); + +type Manifest = { render: Record<string, unknown> & { chrome?: { deck?: Record<string, unknown> } } }; +const readManifest = (): Manifest => JSON.parse(readFileSync(path.join(DECK_DIR, "video.manifest.json"), "utf8")); +const claims = () => readManifest().render.chrome?.deck?.claims; + +test("the claims editor: a count and a goalpost -- validated as typed, the playhead, saved, edited, removed", async ({ page, request }) => { + test.setTimeout(150_000); + test.skip(!readManifest().render.fontRegular, "the deck refuses to draw without render.fontRegular/fontBold, and make-fixture.mjs found no font on this machine"); + // From no claims, whatever an earlier run left. + const token = (await (await request.get(`/api/report/chrome?project=${encodeURIComponent(DECK_PROJECT)}`)).json()).token; + const reset = await request.put("/api/report/chrome", { data: { project: DECK_PROJECT, token, claims: null } }); + expect(reset.ok(), await reset.text()).toBe(true); + await page.goto(urls.section(DECK_PROJECT, "onscreen")); + const ed = page.getByTestId("claims-editor"); + await expect(ed).toBeVisible({ timeout: 30_000 }); + await expect(ed).toContainText("No claim checks"); + + // A count: the validator names what is missing, in the build's words. + await ed.getByTestId("claims-add-count").click(); + await ed.getByTestId("claim-from-0").fill(""); + await ed.getByTestId("claim-to-0").fill(""); + const errs = ed.getByTestId("claim-errors-0"); + await expect(errs).toContainText("said must be his words, in quotes"); + await expect(errs).toContainText("window.from must be a date (YYYY-MM-DD)"); + await expect(ed.getByTestId("claims-save")).toBeDisabled(); + await ed.getByTestId("claim-said-0").fill("“less than ten” in a year"); + await ed.getByTestId("claim-from-0").fill("2025-10-22"); + await ed.getByTestId("claim-to-0").fill("2025-01-01"); + await expect(errs).toContainText("window.from 2025-10-22 is after its to 2025-01-01"); + await ed.getByTestId("claim-to-0").fill("2026-10-22"); + await ed.getByTestId("claim-op-0").selectOption("<"); + await ed.getByTestId("claim-value-0").fill("10"); + // The playhead: the scrubber on the second clip gives its id and a source second inside it. + const scrub = page.getByTestId("onscreen-scrubber"); + await expect(scrub).toBeVisible({ timeout: 30_000 }); + const max = Number(await scrub.getAttribute("max")); + await scrub.fill(String(Math.round(max * 0.8 * 100) / 100)); + await expect(page.getByTestId("onscreen-current")).toHaveText("c02"); + await ed.getByTestId("claim-playhead-0").click(); + await expect(ed.getByTestId("claim-at-0")).toHaveValue("c02"); + const t = Number(await ed.getByTestId("claim-t-0").inputValue()); + expect(t).toBeGreaterThanOrEqual(8.5); + expect(t).toBeLessThanOrEqual(12); + + // A tally that names no verdict: the writer refuses it, in the build's words. + await ed.getByTestId("claim-tally-0").fill("Grift"); + await expect(errs).toHaveCount(0); + await ed.getByTestId("claims-save").click(); + await expect(page.getByText(/could not save the claim checks/)).toBeVisible({ timeout: 15_000 }); + await expect(page.getByText(/tally "Grift" names no verdict/).first()).toBeVisible(); + expect(claims()).toBeUndefined(); + await ed.getByTestId("claim-tally-0").fill("CONTRADICTED"); + + // A goalpost: his first deadline, then the step that moves it. + await ed.getByTestId("claims-add-goalpost").click(); + await ed.getByTestId("claim-label-1").fill("Pill test results"); + await ed.getByTestId("claim-step-at-1-0").selectOption("c01"); + await ed.getByTestId("claim-step-t-1-0").fill("4.5"); + await ed.getByTestId("claim-step-said-1-0").fill("“3–5 weeks”"); + await ed.getByTestId("claim-step-from-1-0").fill("2026-09-23"); + await ed.getByTestId("claim-step-add-1").click(); + await ed.getByTestId("claim-step-at-1-1").selectOption("c02"); + await ed.getByTestId("claim-step-t-1-1").fill("10"); + await ed.getByTestId("claim-step-said-1-1").fill("“6–8 weeks”"); + await ed.getByTestId("claim-step-from-1-1").fill("2026-10-15"); + await ed.getByTestId("claim-step-due0-1-1").fill("P8W"); + await ed.getByTestId("claim-step-due1-1-1").fill("P6W"); + await expect(ed.getByTestId("claim-errors-1")).toContainText("steps[1].due P8W is longer than P6W: the soonest first"); + await ed.getByTestId("claim-step-due0-1-1").fill("P6W"); + await ed.getByTestId("claim-step-due1-1-1").fill("P8W"); + await expect(ed.getByTestId("claim-errors-1")).toHaveCount(0); + await ed.getByTestId("claims-save").click(); + await expect.poll(() => claims()).toEqual([ + { kind: "count", at: "c02", t, said: "“less than ten” in a year", window: { from: "2025-10-22", to: "2026-10-22" }, tally: "CONTRADICTED", claim: { op: "<", value: 10 } }, + { + kind: "goalpost", + label: "Pill test results", + steps: [ + { at: "c01", t: 4.5, said: "“3–5 weeks”", from: "2026-09-23", due: ["P3W", "P5W"] }, + { at: "c02", t: 10, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }, + ], + }, + ]); + + // Reloaded, it reads back; the preview's schedule says the due windows. Edit, remove, save. + await page.reload(); + await expect(page.getByTestId("claim-said-0")).toHaveValue("“less than ten” in a year", { timeout: 30_000 }); + await expect(page.getByTestId("claim-record-1")).toContainText("due: 14–28 Oct → 26 Nov–10 Dec", { timeout: 30_000 }); + await page.getByTestId("claim-per-0").selectOption("P1W"); + await page.getByTestId("claim-remove-0").click(); + await page.getByTestId("claim-step-remove-0-0").click(); + await page.getByTestId("claims-save").click(); + await expect.poll(() => claims()).toEqual([ + { kind: "goalpost", label: "Pill test results", steps: [{ at: "c02", t: 10, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }] }, + ]); + // Removing the last claim removes the key. + await page.getByTestId("claim-remove-0").click(); + await page.getByTestId("claims-save").click(); + await expect.poll(() => readManifest().render.chrome?.deck && "claims" in readManifest().render.chrome!.deck!).toBe(false); +}); diff --git a/umtool/lib/report/clipEditorTypes.ts b/umtool/lib/report/clipEditorTypes.ts @@ -52,7 +52,7 @@ export type ClipBlur = { on: true; caption?: string; strength?: number; from?: n export type BlurDefaults = { caption: string; captionMax: number; strength: { min: number; max: number; default: number }; rendered: boolean }; /** A claim with its knobs (plans/video-knobs-plan.md): `at` is a source second. */ -export type ClaimKnobs = { id: string; verdict: string; at?: number; hold?: number; stamp?: boolean; count?: number; label?: string }; +export type ClaimKnobs = { id: string; verdict: string; at?: number; hold?: number; stamp?: boolean; count?: number; label?: string; eventDate?: string }; /** A mark as the clip editor shows it: its knobs, and the clip that stamps it (the last carrying its id). */ export type MarkView = ClaimKnobs & { stampsOn: string | null }; /** A verdict a mark may take, with this cut's words and colour; `stock`: the cut's own (relabelled, or in use). */ diff --git a/umtool/lib/report/knobs.mjs b/umtool/lib/report/knobs.mjs @@ -3,7 +3,7 @@ // and an agent sets with `umtool set` / `umtool look` -- before manifest.mjs // writes it. // -// a claimed entry claim.at / hold / stamp / count / label (factcheck.mjs normalizeClaim, validateClaims) +// a claimed entry claim.at / hold / stamp / count / label / eventDate (factcheck.mjs normalizeClaim, validateClaims) // a clip audio: { offset, gain, fadeIn, fadeOut } (clip-audio.mjs validateClipAudio) // the fact-check render.chrome.factcheck.stamp.scale / motion / opacity, // verdicts[V].stampLabel (factcheck.mjs validateFactcheck) @@ -21,6 +21,7 @@ import { CLAIM_KEYS, CLAIM_LIMITS, CLAIM_MARKS_MAX, FACTCHECK_DEFAULTS, FACTCHECK_LIMITS, STAMP_MOTIONS, VERDICTS, rawMarksOf, resolveFactcheck, } from "umtool-report-to-video/factcheck"; import { MARKER_ALIGNS, MARKER_LAYOUTS } from "umtool-report-to-video/deck"; +import { isIsoDate } from "umtool-report-to-video/claims"; import { DEFAULT_VARIANTS, validateVariants, variantsOf } from "umtool-report-to-video/variants"; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); @@ -86,13 +87,19 @@ export function claimKnobValue(key, v) { if (s.length > CLAIM_LIMITS.label) throw new Error(`claim.label is ${s.length} characters (at most ${CLAIM_LIMITS.label})`); return s; } + case "eventDate": { + // The day the counted event happened, when not its clip's (a deck claim's window reads it). + const d = typeof v === "string" ? v.trim() : v; + if (!isIsoDate(d)) throw new Error(`claim.eventDate must be a date, YYYY-MM-DD (got ${q(v)})`); + return d; + } default: throw new Error(`claim.${key} is not a claim knob (${CLAIM_KNOBS.join(", ")})`); } } /** - * A patch of claim knobs: `{ at?, hold?, stamp?, count?, label? }`, each a + * A patch of claim knobs: `{ at?, hold?, stamp?, count?, label?, eventDate? }`, each a * value or null (clear). A knob set to its default is CLEARED -- `stamp: true` * and `count: 1` are what an absent key already says. * @@ -100,7 +107,7 @@ export function claimKnobValue(key, v) { * @returns {Record<string, unknown>} key -> value, or null to remove */ export function normalizeClaimKnobPatch(patch) { - if (!isObj(patch)) throw new Error("the claim knobs are an object of at, hold, stamp, count, label"); + if (!isObj(patch)) throw new Error("the claim knobs are an object of at, hold, stamp, count, label, eventDate"); const keys = Object.keys(patch); if (!keys.length) throw new Error("nothing to change"); /** @type {Record<string, unknown>} */ diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs @@ -4,7 +4,7 @@ // (edit-guard.mjs), each write carrying the token read from the file just // before it, so a write here beside an open page is refused rather than lost. // -// umtool set <project> <clip> key=value … claim.at claim.hold claim.stamp claim.count claim.label +// umtool set <project> <clip> key=value … claim.at claim.hold claim.stamp claim.count claim.label claim.eventDate // (a clip's first mark, or --mark <id>'s) // marks=<json> mark.add=<verdict>[@<sec>] mark.remove=<id> // mark.verdict=<verdict> (plans/clip-marks.md) @@ -12,7 +12,7 @@ // blur.on blur.caption blur.strength blur.from blur.to // (`blur.on=` clears the whole blur; report-to-video clip-blur.mjs) // umtool look <project> key=value … factcheck.stamp.<k>, factcheck.verdicts.<V>.<k>, -// deck.markers=<json>, deck.markerLayout=…, variants=<json>, +// deck.markers=<json>, deck.markerLayout=…, deck.claims=<json>, variants=<json>, // and the look's keys (transition=0.3, …) // umtool variants <project> [--take <t>] [--list] [--json] make the encode ladder (or list it) // @@ -49,7 +49,9 @@ export const SET_USAGE = [ ` keys: ${SET_KEYS.join(" ")}`, " claim.at is a SOURCE second inside the clip's window: the stamp lands and the count steps there", " (read from the last clip carrying the claim); claim.hold s (0.5–10); claim.stamp true|false;", - " claim.count 1–99; claim.label ≤ 20 chars. The claim.* keys set the clip's first mark, or --mark <id>'s.", + " claim.count 1–99; claim.label ≤ 20 chars; claim.eventDate YYYY-MM-DD, the day the event it counts", + " happened when not the clip's (a deck claim's window dates it so: render.chrome.deck.claims).", + " The claim.* keys set the clip's first mark, or --mark <id>'s.", " Marks (a clip may carry up to 8, each its own stamp and count): mark.add=<verdict>[@<sec>] adds one", " (the verdict by name or by this cut's label, e.g. Episodes@190.2; a JSON object for its knobs too);", " mark.remove=<id>; mark.verdict=<verdict> (the first mark's, or --mark <id>'s; every clip carrying", @@ -451,6 +453,8 @@ export function knobsOf(manifest) { stampLabels, markers: Array.isArray(deck?.markers) ? deck.markers : [], markerLayout: deck?.markerLayout ?? null, + // The deck's claim checks (report-to-video claims.mjs), as written. + claims: Array.isArray(deck?.claims) ? deck.claims : [], variants: variantsOf(manifest?.render), variantsDefault: !Array.isArray(manifest?.render?.variants), // render.blur "off": the uncensored variant (every clip's blur not drawn). @@ -477,6 +481,15 @@ export function knobsLines(manifest) { if (Object.keys(k.stamp).length) lines.push(` stamp ${Object.entries(k.stamp).map(([a, b]) => `${a}=${b}`).join(" ")}`); if (Object.keys(k.stampLabels).length) lines.push(` stamp word ${Object.entries(k.stampLabels).map(([a, b]) => `${a}=${b}`).join(" ")}`); if (k.markers.length) lines.push(` markers ${k.markers.map((m) => `${m.after}:"${m.label}"${m.align ? `(${m.align})` : ""}`).join(" ")}${k.markerLayout ? ` · layout ${k.markerLayout}` : ""}`); + for (const c of k.claims) { + if (!isObj(c)) continue; + if (c.kind === "count") { + const window = isObj(c.window) ? `${c.window.from}..${c.window.to}` : "?"; + lines.push(` claim count ${c.at}@${c.t} ${c.said} · ${window} · ${c.tally}${c.per ? ` per ${c.per}` : ""}${isObj(c.claim) ? ` · ${c.claim.op} ${c.claim.value}` : ""}`); + } else if (c.kind === "goalpost" && Array.isArray(c.steps)) { + lines.push(` claim goalpost${c.label ? ` "${c.label}"` : ""} ${c.steps.map((st) => `${st.at}@${st.t} ${st.said} ${st.from ?? "(clip date)"}+${Array.isArray(st.due) ? st.due.join("..") : "?"}`).join(" → ")}`); + } + } lines.push(` variants ${k.variants.map((v) => v.name).join(", ")}${k.variantsDefault ? " (default)" : ""}`); if (k.blurOff) lines.push(" blur off (render.blur: the uncensored variant — no clip is blurred)"); return lines; diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -30,7 +30,9 @@ import { rolesGaps, } from "umtool-report-to-video/ledger-totals"; import { isCalendarDate } from "umtool-report-to-video/attribution"; -import { normalizeOnscreen, validateChrome, validateDeckMarkers, validatePosts, validateTeaser, validateTeasers } from "umtool-report-to-video/deck"; +import { + normalizeOnscreen, validateChrome, validateDeckClaims, 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"; @@ -1031,7 +1033,8 @@ export async function updateChrome(dir, chrome, { token = null } = {}) { 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); + // Its claim checks likewise: each is said in a clip in it. + const markers = [...validateDeckMarkers(manifest), ...validateDeckClaims(manifest)]; if (markers.length) throw new ChromeRefused(markers); } @@ -1372,6 +1375,8 @@ function structureErrors(manifest) { ...validateClaims(manifest), // The deck's markers follow clips: removing one a marker names is refused. ...validateDeckMarkers(manifest), + // So are its claim checks said in clips, and they name the tally's verdict. + ...validateDeckClaims(manifest), // The finale is one run of the last clips: moving a clip past it is refused. ...validateFinaleEntries(manifest), ...validateTeasers(manifest), diff --git a/umtool/lib/report/onscreen.mjs b/umtool/lib/report/onscreen.mjs @@ -22,6 +22,7 @@ import { selectVariant } from "umtool-report-to-video/build-video"; import { createPostChannelResolver, resolvePostLinks } from "umtool-report-to-video/post-links"; import { attachPosts, + claimsSchedule, clipDay, deckGeometry, deckOn, @@ -213,7 +214,9 @@ export function previewSchedule({ variantManifest, built, draft, metas, postsDra const deck = resolveDeck(render); const provenance = variantManifest.provenance ?? {}; const patchedEntries = entries.map(patched); - const { posts: _builtPosts, moves: _builtMoves, layout: _builtLayout, factcheck: _builtFactcheck, ...rest } = built; + const { + posts: _builtPosts, moves: _builtMoves, layout: _builtLayout, factcheck: _builtFactcheck, deckClaims: _builtClaims, ...rest + } = built; const round = (v) => Math.round(v * 1000) / 1000; const holds = deck.posts.show ? postHolds({ posts, entries: patchedEntries, metas, render }) : new Map(); let shift = 0; @@ -253,6 +256,12 @@ export function previewSchedule({ variantManifest, built, draft, metas, postsDra : s)), D: built.transition, total, render, }); + // The deck's claim checks as they are NOW, over the build's segments and + // these stamps (deck.mjs claimsSchedule, the build's own arithmetic). + const deckClaims = claimsSchedule({ + entries: patchedEntries, segments, D: built.transition, total, metas, render, stamps, + sourceFrom: (e) => segments.find((s) => s.id === e.id)?.sourceFrom ?? playWindow(e, render).from, + }); return { ...rest, ...(feed ? { layout: "feed" } : {}), @@ -267,6 +276,7 @@ export function previewSchedule({ variantManifest, built, draft, metas, postsDra ...(stamps.length ? { factcheck: { stamps: roundStamps(stamps) } } : {}), ...(placed.length ? { posts: roundPosts(placed) } : {}), ...(moves.length ? { moves: moves.map((m) => ({ ...m, at: round(m.at), segmentAt: round(m.segmentAt) })) } : {}), + ...(deckClaims ? { deckClaims } : {}), }; } return estimateSchedule({ ...variantManifest, posts, timeline: entries.map(patched) }, { metas }); @@ -331,7 +341,8 @@ export function clipLabel(entry, meta) { * - `effective`: where it rides as saved (null when hidden); * - `timing`: its slot in `schedule.posts` when a schedule places it. * - * `clips` is every clip of the cut, in order, for the override select. + * `clips` is every clip of the cut, in order, for the override select (and + * the claims editor's clip picker): its id, label, day and play window's start. * * @param {{ variantManifest: Record<string, any>, metas: Array<Record<string, any> | null>, * schedule?: Record<string, any> | null }} args @@ -369,7 +380,11 @@ export function postRows({ variantManifest, metas, schedule = null }) { clips: entries .map((e, i) => ({ e, i })) .filter(({ e }) => e.type === "clip") - .map(({ e, i }) => ({ id: e.id, label: labelOf.get(e.id) ?? "", day: clipDay(e, metas[i] ?? null) })), + // `from`: the source second its play window starts at -- what the + // claims editor's "use the playhead" maps the scrubber through. + .map(({ e, i }) => ({ + id: e.id, label: labelOf.get(e.id) ?? "", day: clipDay(e, metas[i] ?? null), from: playWindow(e, variantManifest.render ?? {}).from, + })), }; } diff --git a/umtool/lib/report/onscreen.test.mjs b/umtool/lib/report/onscreen.test.mjs @@ -255,8 +255,8 @@ test("postRows: the automatic clip, the effective one, and the slot in the sched assert.equal(by.p3.auto.rule, "first"); assert.deepEqual(by.p3.timing, { segment: "c01", slot: 0, of: 1, appear: 11.9, out: [13.9, 14.4] }); assert.deepEqual(clips, [ - { id: "c01", label: "Stream one", day: "2024-09-03" }, - { id: "c02", label: "Saved", day: "2024-09-10" }, + { id: "c01", label: "Stream one", day: "2024-09-03", from: 10 }, + { id: "c02", label: "Saved", day: "2024-09-10", from: 30 }, ]); assert.deepEqual(postRows({ variantManifest: cut(), metas }).posts, []); }); diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -148,6 +148,7 @@ import { dipOf, estimatedDuration, muteSegmentSeconds, playWindow, postsGeometry, postWindows, resolveDeck, scheduleFrom, snapWindow, stampGeometry, statsGeometry, teaserHits, teaserSeconds, teaserTitle, threadsGeometry, validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, fxGeometry, even as evenPx, + claimRecordNotes, deckClaimClips, validateDeckClaims, } 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"; @@ -5029,6 +5030,9 @@ export async function chapterTitle(entry, index, provenance, { deck = false } = export async function writeChromeSchedule({ manifest, entries, segments, D, outDir }) { const doc = await measureChromeSchedule({ manifest, entries, segments, D }); await writeFile(path.join(outDir, "schedule.json"), JSON.stringify(doc, null, 2) + "\n"); + // What the record says to a deck claim's `claim` (it does not contradict + // him, a stamp with no date): notes, the operator's to weigh. + for (const message of claimRecordNotes(doc)) EMIT("note", { message }); return doc; } @@ -5056,7 +5060,9 @@ export async function measureChromeSchedule({ manifest, entries, segments, D, du // claimed clip's segment really starts at, from its cut record (snapped, // room included). Read only then. let clipClock = null; - const timedMarks = (e) => marksOf(e).some((c) => c.at !== undefined); + // So is a clip a deck claim check is said in (`deck.claims`, claims.mjs). + const claimClips = deckClaimClips(render); + const timedMarks = (e) => marksOf(e).some((c) => c.at !== undefined) || claimClips.has(e.id); if (entries.some(timedMarks)) { clipClock = new Map(); for (let i = 0; i < entries.length; i += 1) { @@ -5417,6 +5423,9 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly // 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 deck's claim checks, likewise: each names a clip in it, and a verdict. + const claimChecks = validateDeckClaims(whole); + if (claimChecks.length) throw new Error(`render.chrome: ${claimChecks.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-claims.mjs b/umtool/report-to-video/chrome-claims.mjs @@ -0,0 +1,393 @@ +// The claim checks (`deck.claims`, claims.mjs) as the footer's page draws +// them: chrome-deck.mjs calls these two and splices their cues and markup +// into its own, so a deck without claims composes the page it always did. +// +// PURE, like chrome-deck.mjs. Every cue states its from through deckCues' +// walk (chrome-deck.mjs says why): what is here only adds events and t = 0 +// states. +// +// What it draws, in the identity's one alarm colour (the markers' and the +// Seizures tally's red, `#e5534b`) -- and no adjective: his words in quotes +// and the record's numbers, the contrast is the argument. +// +// - A COUNT claim, from the second he says it to his clip's end: the clip's +// own words make way and his words stand in the text column, the record +// under them. Without `per`: a band over the rail spanning his window, the +// rail outside it dimmed, each pip that carries the record lit red with its +// count under it, in date order over ~1.2 s, while the number under his +// words counts up to the window's total. With `per`: each span that holds +// enough lit red on the rail with its count (`12 in a day`), left to right. +// - A GOALPOST: from each step's second, a hollow bracket on the rail over +// the due window his words imply, his words over it. At the next step the +// old one stays as a dashed ghost and a copy of it slides to the new +// window -- off the rail's end when that lies past its last date, where +// the new bracket's arrow and its dates stand. +import { MARKER_LABEL_SIZE } from "./deck.mjs"; + +/** The claims' one colour: the alarm red the markers and the Seizures tally use. */ +export const CLAIM_RED = "#e5534b"; + +/** The motion, in seconds: the band in, the record lit over `light`, a span each, the bracket's draw and the move. */ +export const CLAIM_MOTION = Object.freeze({ in: 0.35, light: 1.2, spans: 1.0, out: 0.35, draw: 0.5, move: 0.9, settle: 0.7 }); + +/** The callout's two lines, px: his words, then the record. */ +export const CALLOUT = Object.freeze({ size1: 28, box1: 34, size2: 28, box2: 36 }); + +const esc = (s) => + String(s ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"); +const r4 = (v) => Math.round(v * 10000) / 10000; + +/** + * The claims' events and t = 0 states for deckCues' walk, from `cl` + * (deck.mjs claimsLayout). `put(k, v)` sets a t = 0 state, `add(k, at, dur, + * to, ease, why)` an event; `segIndex(id)` is a segment's index (its text's + * keys are `s<i>.tc` …), `W` the page's width. + */ +export function claimsCues(cl, { put, add, segIndex, W }) { + const m = CLAIM_MOTION; + // A callout gives way to the next claim said on the same clip. + const counts = cl.items.map((it, j) => ({ it, j })).filter(({ it }) => it.kind === "count"); + cl.items.forEach((it, j) => { + if (it.kind === "count") { + const why = `claim ${it.n} ${it.segment}`; + const at = it.at; + const until = Math.max(at + m.in + 0.1, it.until); + // Gone by the time the next one's words come in at the same place: never both at once. + const nextHere = counts.find(({ it: o }) => o.segment === it.segment && o.at > at); + const coEnd = nextHere ? Math.min(until, nextHere.it.at) : until; + const fadeIn = (k, extra = {}) => { + put(k, { autoAlpha: 0, ...Object.fromEntries(Object.keys(extra).map((p) => [p, extra[p][0]])) }); + add(k, at, m.in, { autoAlpha: 1, ...Object.fromEntries(Object.keys(extra).map((p) => [p, extra[p][1]])) }, "power2.out", why); + }; + const out = (k, end = until, dur = m.out) => add(k, end - dur, dur, { autoAlpha: 0 }, "power1.in", `${why} out`); + // The clip's own words make way for his (its QR stays). + const i = segIndex(it.segment); + if (i !== undefined) { + for (const part of ["tc", "sc", "rule"]) { + put(`s${i}.${part}`, { opacity: 1 }); + add(`s${i}.${part}`, at, 0.25, { opacity: 0 }, "power1.out", why); + } + } + put(`c${j}.co`, { autoAlpha: 0, x: -14 }); + add(`c${j}.co`, at, m.in, { autoAlpha: 1, x: 0 }, "power3.out", why); + out(`c${j}.co`, coEnd, nextHere ? 0.2 : m.out); + if (it.band) { + fadeIn(`c${j}.band`); + out(`c${j}.band`); + it.veils.forEach((_, v) => { + put(`c${j}.v${v}`, { opacity: 0 }); + add(`c${j}.v${v}`, at, 0.5, { opacity: 0.72 }, "power1.out", why); + add(`c${j}.v${v}`, until - m.out, m.out, { opacity: 0 }, "power1.in", `${why} out`); + }); + // The record, lit in date order while the number counts up to its total. + const n = it.tags.length; + put(`c${j}.n0`, { autoAlpha: 1 }); + it.tags.forEach((t, k) => { + const lit = at + m.in + (m.light * k) / Math.max(1, n); + put(`c${j}.r${k}`, { autoAlpha: 0, scale: 0.4 }); + add(`c${j}.r${k}`, lit, 0.3, { autoAlpha: 1, scale: 1 }, "back.out(2.2)", `${why} lit`); + out(`c${j}.r${k}`); + if (!t.covered) { + put(`c${j}.t${k}`, { autoAlpha: 0, y: 6 }); + add(`c${j}.t${k}`, lit, 0.25, { autoAlpha: 1, y: 0 }, "power2.out", `${why} lit`); + out(`c${j}.t${k}`); + } + put(`c${j}.n${k + 1}`, { autoAlpha: 0 }); + // A number swaps for the next in one frame: a crossfade would show both. + add(`c${j}.n${k}`, lit, 0.001, { autoAlpha: 0 }, "none", `${why} count`); + add(`c${j}.n${k + 1}`, lit, 0.001, { autoAlpha: 1 }, "none", `${why} count`); + }); + } + (it.spans ?? []).forEach((sp, k) => { + const lit = at + 0.25 + (m.spans * k) / Math.max(1, it.spans.length); + put(`c${j}.s${k}`, { autoAlpha: 0, scaleY: 0.2 }); + add(`c${j}.s${k}`, lit, 0.3, { autoAlpha: 1, scaleY: 1 }, "back.out(2)", `${why} span`); + out(`c${j}.s${k}`); + put(`c${j}.sl${k}`, { autoAlpha: 0, y: 6 }); + add(`c${j}.sl${k}`, lit + 0.1, 0.25, { autoAlpha: 1, y: 0 }, "power2.out", `${why} span`); + out(`c${j}.sl${k}`); + }); + return; + } + it.steps.forEach((st, s) => { + const why = `goalpost ${it.n} step ${s}`; + const prev = s > 0 ? it.steps[s - 1] : null; + // The first is drawn where he says it; a later one lands once the old one's copy has moved. + const shows = prev ? st.at + m.settle : st.at; + put(`g${j}.${s}`, { autoAlpha: 0 }); + add(`g${j}.${s}`, shows, 0.3, { autoAlpha: 1 }, "power2.out", why); + put(`g${j}.${s}b`, { scaleX: 0, transformOrigin: "0% 50%" }); + add(`g${j}.${s}b`, shows, m.draw, { scaleX: 1, transformOrigin: "0% 50%" }, "power2.out", why); + const next = it.steps[s + 1]; + if (!next) return; + // Superseded: the bracket goes dashed and dim, and a copy of it moves to the new window. + add(`g${j}.${s}`, next.at, 0.25, { autoAlpha: 0 }, "power1.in", `${why} moved`); + put(`g${j}.${s}g`, { autoAlpha: 0 }); + add(`g${j}.${s}g`, next.at, 0.3, { autoAlpha: 1 }, "power1.out", `${why} moved`); + const dx = (next.off ? W + 40 : next.a) - st.a; + put(`g${j}.${s}m`, { autoAlpha: 0, x: 0 }); + add(`g${j}.${s}m`, next.at, 0.001, { autoAlpha: 1 }, "none", `${why} moves`); + add(`g${j}.${s}m`, next.at + 0.05, m.move, { x: r4(dx) }, "power2.in", `${why} moves`); + add(`g${j}.${s}m`, next.at + 0.05 + m.move, 0.001, { autoAlpha: 0 }, "none", `${why} moves`); + }); + }); +} + +/** + * The claims' markup, as two strings: `track` goes inside the deck's + * `.track` (positions are relative to it: x as the page's, y from the + * track), `text` inside the panel over the segments' words. `lay` is the + * deck's layout, `pal` the palette, `ground(x)` the panel's colour at the + * track's height at x (what a veil is, so it dims the rail and no more). + */ +export function claimsMarkup(cl, { lay, pal, ground, pipSize }) { + const tr = lay.pipTrack; + const t = lay.text; + const red = CLAIM_RED; + const track = []; + const text = []; + // The band runs from the deck's top to under the record's counts. + const bandTop = 2 - tr.y; + const bandBottom = 34; + const coTop = tr.y + 36; + const ring = Math.max(18, pipSize + 10); + cl.items.forEach((it, j) => { + if (it.kind === "count") { + if (it.band) { + track.push( + `<div class="cband" data-k="c${j}.band" style="left:${it.band.a}px; width:${r4(it.band.b - it.band.a)}px; top:${bandTop}px; height:${bandBottom - bandTop}px"></div>`, + ); + it.veils.forEach(([a, b], v) => { + track.push(`<div class="cveil" data-k="c${j}.v${v}" style="left:${a}px; width:${r4(b - a)}px; background:${ground((a + b) / 2)}"></div>`); + }); + it.tags.forEach((tg, k) => { + track.push(`<div class="cring" data-k="c${j}.r${k}" style="left:${r4(tg.x - ring / 2)}px; top:${-ring / 2}px; width:${ring}px; height:${ring}px"></div>`); + if (!tg.covered) track.push(`<div class="ctag" data-k="c${j}.t${k}" style="left:${r4(tg.x - 50)}px">+${tg.count}</div>`); + }); + } + (it.spans ?? []).forEach((sp, k) => { + track.push(`<div class="cspan-set" data-k="c${j}.s${k}">${sp.bars.map((bar) => `<div class="cspan" style="left:${bar.a}px; width:${r4(bar.b - bar.a)}px"></div>`).join("")}</div>`); + track.push(`<div class="ctag cspl" data-k="c${j}.sl${k}" style="left:${r4(sp.cx - 110)}px; width:220px">${esc(sp.label)}</div>`); + }); + // His words, and the record under them. + let record; + if (it.band) { + const values = [0]; + for (const tg of it.tags) values.push(values[values.length - 1] + tg.count); + const digits = String(values[values.length - 1]).length; + record = + `<span class="cnum" style="width:${r4(digits * 0.6)}em">` + + values.map((v, k) => `<span data-k="c${j}.n${k}">${v}</span>`).join("") + + `</span><span class="cnoun">${esc(it.noun)} on camera</span>`; + } else if (it.spans?.length) { + record = `<span class="cspans">${it.spans.map((sp) => esc(sp.label)).join('<span class="csep">·</span>')}</span>`; + } else record = `<span class="cnoun">none on camera</span>`; + text.push( + `<div class="cco" data-k="c${j}.co" style="left:${t.x}px; top:${coTop}px; width:${t.width}px">` + + `<div class="cco1">${esc(it.said)}</div><div class="cco2">${record}</div></div>`, + ); + return; + } + const labelTop = (lay.claimBand?.y ?? 3) - tr.y; + const stickTop = labelTop + 20; + it.steps.forEach((st, s) => { + const box = (k, ghost = false) => + `<div class="gbox${st.open ? " open" : ""}${ghost ? " ghost" : ""}"${k ? ` data-k="${k}"` : ""} style="left:${st.a}px; width:${r4(st.b - st.a)}px">` + + (st.open ? `<div class="garrow"></div>` : "") + `</div>`; + const stickX = st.align === "right" ? st.b - 1 : st.a + 1; + const label = (ghost) => + `<div class="gstick${ghost ? " ghost" : ""}" style="left:${r4(stickX - 1)}px; top:${stickTop}px; height:${-9 - stickTop}px"></div>` + + `<div class="glabel${ghost ? " ghost" : ""}" style="${st.align === "right" ? `left:${r4(st.b - 400)}px; width:400px; text-align:right` : `left:${st.a}px; width:${Math.max(40, Math.min(400, lay.width - 16 - st.a))}px`}; top:${labelTop}px">${esc(st.label)}</div>`; + track.push(`<div class="gstep" data-k="g${j}.${s}">${box(`g${j}.${s}b`)}${label(false)}</div>`); + if (s + 1 < it.steps.length) { + track.push(`<div class="gstep" data-k="g${j}.${s}g">${box(null, true)}${label(true)}</div>`); + track.push(`<div class="gstep" data-k="g${j}.${s}m">${box(null)}</div>`); + } + }); + }); + const css = ` + /* The claim checks (deck.claims): his words against the record, in the alarm red. */ + .cband { position: absolute; border-radius: 6px; background: rgba(229, 83, 75, 0.13); + box-shadow: inset 0 0 0 1px rgba(229, 83, 75, 0.55); } + .cveil { position: absolute; top: -13px; height: 26px; } + .cring { position: absolute; border-radius: 50%; box-shadow: 0 0 0 3px ${red}, 0 0 16px 4px rgba(229, 83, 75, 0.55); } + .cspan-set { position: absolute; left: 0; top: 0; width: 0; height: 0; } + .cspan { position: absolute; top: -5px; height: 10px; border-radius: 5px; background: ${red}; + box-shadow: 0 0 14px 3px rgba(229, 83, 75, 0.5); } + .ctag { position: absolute; top: 12px; width: 100px; height: 22px; text-align: center; white-space: nowrap; + font-family: 'DeckSansBold', sans-serif; font-size: ${MARKER_LABEL_SIZE}px; line-height: 22px; letter-spacing: 0.04em; + color: ${red}; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); font-variant-numeric: tabular-nums; } + .ctag.cspl { text-transform: uppercase; } + .cco { position: absolute; white-space: nowrap; overflow: hidden; } + .cco1 { font-family: 'DeckSansBold', sans-serif; font-size: ${CALLOUT.size1}px; line-height: ${CALLOUT.box1}px; color: ${pal.fg}; + overflow: hidden; text-overflow: ellipsis; } + .cco2 { font-size: ${CALLOUT.size2}px; line-height: ${CALLOUT.box2}px; color: ${pal.muted}; display: flex; align-items: baseline; } + .cnum { position: relative; display: inline-block; height: ${CALLOUT.box2}px; margin-right: 0.3em; text-align: right; + font-family: 'DeckSansBold', sans-serif; font-size: ${Math.round(CALLOUT.size2 * 1.2)}px; color: ${red}; font-variant-numeric: tabular-nums; } + .cnum > span { position: absolute; right: 0; bottom: 0; } + .cspans { font-family: 'DeckSansBold', sans-serif; color: ${red}; text-transform: uppercase; letter-spacing: 0.02em; } + .csep { padding: 0 0.45em; color: ${pal.muted}; } + .gstep { position: absolute; left: 0; top: 0; width: 0; height: 0; } + .gbox { position: absolute; top: -10px; height: 20px; border: 2px solid ${red}; border-radius: 5px; transform-origin: 0 50%; + background: rgba(229, 83, 75, 0.1); } + .gbox.open { border-right: none; border-radius: 5px 0 0 5px; } + .gbox.ghost { border-style: dashed; border-color: rgba(229, 83, 75, 0.6); background: none; } + .garrow { position: absolute; right: -14px; top: 1px; width: 14px; height: 14px; background: ${red}; + clip-path: polygon(0% 0%, 100% 50%, 0% 100%); } + .gbox.ghost .garrow { background: rgba(229, 83, 75, 0.6); } + .gstick { position: absolute; width: 2px; background: ${red}; } + .gstick.ghost { background: rgba(229, 83, 75, 0.45); } + .glabel { position: absolute; height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + font-family: 'DeckSansBold', sans-serif; font-size: ${MARKER_LABEL_SIZE}px; line-height: 20px; letter-spacing: 0.04em; + text-transform: uppercase; color: ${red}; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); } + .glabel.ghost { color: rgba(229, 83, 75, 0.5); }`; + return { track: track.join(""), text: text.join(""), css }; +} + +// --------------------------------------------------------------------------- +// The finale's large rail (chrome-finale.mjs): every claim's final state. +// --------------------------------------------------------------------------- + +/** + * The claims on the finale's large rail, frame px: the footer's layout + * (`fcl`, claimsLayout) mapped onto the large track by `toBig`, around the + * track at `Y`. Each count claim's band (with the rail dimmed outside it and + * its record's pips ringed) or its spans, and every goalpost step -- each + * superseded one dashed, the last solid. Their words stand in rows above the + * markers' (`markerRows` of them in use), each from `top` down, packed so no + * two meet: his words, and the record in red. + * + * @returns {{ items: any[], rowTops: number[] }} + */ +export function finaleClaims(fcl, { toBig, Y, top, markerRows = 0, bigX, size, textWidth, ringSize, pips = [] }) { + const r2 = (v) => Math.round(v * 100) / 100; + const rowTops = []; + for (let r = Math.max(1, markerRows); ; r += 1) { + const t = Y - 72 - 40 * r; + if (t < top) break; + rowTops.push(t); + } + if (!rowTops.length) rowTops.push(Math.max(top, Y - 112)); + const rows = rowTops.map(() => []); + const place = (left, width) => { + const right = left + width; + for (let r = 0; r < rows.length; r += 1) { + if (rows[r].every(([a, b]) => right + 24 <= a || left >= b + 24)) { rows[r].push([left, right]); return r; } + } + rows[rows.length - 1].push([left, right]); + return rows.length - 1; + }; + const words = (said, record, lead = null) => ({ + said, record, ...(lead ? { lead } : {}), + width: (lead ? textWidth(`${lead} `, size) + 8 : 0) + textWidth(said, size) + (record ? textWidth(` ${record}`, size) + 12 : 0), + }); + const labels = []; + const items = fcl.items.map((it, j) => { + if (it.kind === "count") { + const band = it.band ? { a: r2(toBig(it.band.a)), b: r2(toBig(it.band.b)) } : null; + // Dimmed: the track under each veil, and each pip under one as a dot of + // its own size -- a finale pip's ring (it is playing) stays whole. + const veils = (it.veils ?? []).map(([a, b]) => [r2(toBig(a)), r2(toBig(b))]); + const dots = pips.filter((p) => veils.some(([a, b]) => p.x > a && p.x < b)).map((p) => ({ x: p.x, size: p.size + 4 })); + const rings = it.band ? it.tags.map((t) => ({ x: bigX(t.k), size: ringSize })) : []; + const spans = (it.spans ?? []).map((sp) => ({ + a: r2(toBig(sp.a)), b: r2(toBig(sp.b)), cx: r2(toBig(sp.cx)), label: sp.label, + bars: sp.bars.map((bar) => ({ a: r2(toBig(bar.a)), b: r2(toBig(bar.b)) })), + })); + const record = it.band ? `${it.total} ${it.noun} on camera` : spans.map((sp) => sp.label).join(" · ") || "none on camera"; + const w = words(it.said, record); + const left = band ? band.a : spans.length ? spans[0].a : bigX(0); + // A band's words hang from its left edge; a per claim's from nothing (its spans carry their counts). + const label = { ...w, left: r2(left), stickX: band ? r2(left + 1) : null, j }; + labels.push(label); + return { kind: "count", j, band, veils, dots, rings, spans, label }; + } + const steps = it.steps.map((st, s) => { + const a = r2(toBig(st.a)), b = r2(toBig(st.b)); + // What it is (the goalpost's `label`) leads its standing step's words. + const last = s === it.steps.length - 1; + const w = words(st.said, st.open ? `→ ${st.dueText}` : `· ${st.dueText}`, last && it.label ? `${it.label}:` : null); + const align = st.align; + const left = align === "right" ? b - w.width : a; + const label = { ...w, left: r2(left), stickX: r2(align === "right" ? b - 1 : a + 1), j, s, ghost: s + 1 < it.steps.length }; + labels.push(label); + return { a, b, open: st.open, off: st.off, ghost: s + 1 < it.steps.length, label }; + }); + return { kind: "goalpost", j, ...(it.label ? { name: it.label } : {}), steps }; + }); + // The words, packed into the rows left to right. + for (const l of [...labels].sort((x, y) => x.left - y.left)) l.top = rowTops[place(l.left, l.width)]; + return { items, rowTops }; +} + +/** + * The finale's claims as markup and the keys its cues reveal (`fq<j>`, one + * per claim), from finaleClaims. `ground` is the rail panel's colour at the + * track (a veil's); `Y` the track's y. + */ +export function finaleClaimsMarkup(fc, { Y, ground, size, pal }) { + const red = CLAIM_RED; + const html = []; + const keys = []; + const labelHtml = (l) => { + const stickTop = l.top + Math.round(size * 1.25); + return ( + (l.stickX === null ? "" : `<div class="fqstick${l.ghost ? " ghost" : ""}" style="left:${r4(l.stickX - 1)}px; top:${stickTop}px; height:${Math.max(0, Y - 16 - stickTop)}px"></div>`) + + `<div class="fqlabel${l.ghost ? " ghost" : ""}" style="left:${l.left}px; top:${l.top}px; width:${l.width + 8}px">` + + (l.lead ? `<span class="fqlead">${esc(l.lead)}</span> ` : "") + + `<span class="fqsaid">${esc(l.said)}</span>${l.record ? ` <span class="fqrec">${esc(l.record)}</span>` : ""}</div>` + ); + }; + for (const it of fc.items) { + const k = `fq${it.j}`; + keys.push(k); + const parts = []; + if (it.kind === "count") { + if (it.band) parts.push(`<div class="fqband" style="left:${it.band.a}px; width:${r4(it.band.b - it.band.a)}px; top:${Y - 46}px; height:${66}px"></div>`); + for (const [a, b] of it.veils) parts.push(`<div class="fqveil" style="left:${a}px; width:${r4(b - a)}px; top:${Y - 4}px; background:${ground}"></div>`); + for (const d of it.dots) { + parts.push(`<div class="fqveil dot" style="left:${r4(d.x - d.size / 2)}px; top:${r4(Y - d.size / 2)}px; width:${d.size}px; height:${d.size}px; background:${ground}"></div>`); + } + for (const rg of it.rings) parts.push(`<div class="fqring" style="left:${r4(rg.x - rg.size / 2)}px; top:${r4(Y - rg.size / 2)}px; width:${rg.size}px; height:${rg.size}px"></div>`); + for (const sp of it.spans) { + for (const bar of sp.bars) parts.push(`<div class="fqspan" style="left:${bar.a}px; width:${r4(bar.b - bar.a)}px; top:${Y - 7}px"></div>`); + parts.push(`<div class="fqspl" style="left:${r4(sp.cx - 120)}px; top:${Y - 42}px">${esc(sp.label)}</div>`); + } + parts.push(labelHtml(it.label)); + } else { + for (const st of it.steps) { + parts.push( + `<div class="fqbox${st.open ? " open" : ""}${st.ghost ? " ghost" : ""}" style="left:${st.a}px; width:${r4(st.b - st.a)}px; top:${Y - 15}px">` + + (st.open ? `<div class="fqarrow"></div>` : "") + `</div>`, + ); + parts.push(labelHtml(st.label)); + } + } + html.push(`<div class="fq" data-k="${k}">${parts.join("")}</div>`); + } + const css = ` + /* The claim checks' final state (deck.claims). */ + .fq { position: absolute; left: 0; top: 0; width: 0; height: 0; } + .fqband { position: absolute; border-radius: 8px; background: rgba(229, 83, 75, 0.12); box-shadow: inset 0 0 0 1.5px rgba(229, 83, 75, 0.55); } + .fqveil { position: absolute; height: 8px; opacity: 0.72; } + .fqveil.dot { border-radius: 50%; } + .fqring { position: absolute; border-radius: 50%; box-shadow: 0 0 0 3px ${red}, 0 0 18px 5px rgba(229, 83, 75, 0.5); } + .fqspan { position: absolute; height: 14px; border-radius: 7px; background: ${red}; box-shadow: 0 0 16px 4px rgba(229, 83, 75, 0.5); } + .fqspl { position: absolute; width: 240px; text-align: center; white-space: nowrap; font-family: 'DeckSansBold', sans-serif; + font-size: ${size}px; line-height: ${Math.round(size * 1.25)}px; letter-spacing: 0.04em; text-transform: uppercase; color: ${red}; + text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); } + .fqbox { position: absolute; height: 30px; border: 3px solid ${red}; border-radius: 7px; background: rgba(229, 83, 75, 0.1); } + .fqbox.open { border-right: none; border-radius: 7px 0 0 7px; } + .fqbox.ghost { border-style: dashed; border-color: rgba(229, 83, 75, 0.6); background: none; } + .fqarrow { position: absolute; right: -20px; top: 2px; width: 20px; height: 20px; background: ${red}; clip-path: polygon(0% 0%, 100% 50%, 0% 100%); } + .fqbox.ghost .fqarrow { background: rgba(229, 83, 75, 0.6); } + .fqstick { position: absolute; width: 3px; background: ${red}; } + .fqstick.ghost { background: rgba(229, 83, 75, 0.45); } + .fqlabel { position: absolute; white-space: nowrap; font-family: 'DeckSansBold', sans-serif; font-size: ${size}px; + line-height: ${Math.round(size * 1.25)}px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); } + .fqsaid { color: ${pal.fg}; } + .fqlead { color: ${pal.muted}; } + .fqrec { color: ${red}; } + .fqlabel.ghost .fqsaid, .fqlabel.ghost .fqrec { color: rgba(229, 83, 75, 0.5); }`; + return { html: html.join(""), keys, css }; +} diff --git a/umtool/report-to-video/chrome-deck.mjs b/umtool/report-to-video/chrome-deck.mjs @@ -37,7 +37,10 @@ // second clock or a label. import { fileURLToPath } from "node:url"; -import { deckChoreography, deckLayout, deckMarkers, MARKER_LABEL_SIZE, MARKER_ROW, pageDuration, pipSegments, pipXs, resolveDeck } from "./deck.mjs"; +import { + claimsLayout, deckChoreography, deckLayout, deckMarkers, MARKER_LABEL_SIZE, MARKER_ROW, pageDuration, pipSegments, pipXs, resolveDeck, +} from "./deck.mjs"; +import { claimsCues, claimsMarkup } from "./chrome-claims.mjs"; import { resolveFactcheck, tallyCues, tallyFinals, tallyKey, tallyOf, VERDICT_SHAPES } from "./factcheck.mjs"; /** @@ -293,6 +296,11 @@ export function deckCues(schedule, render) { return { ...mk, at: r4(at) }; }); + // The claim checks (`deck.claims`, chrome-claims.mjs): his words against + // the record on the rail. None: nothing here. + const claims = claimsLayout(schedule, render, xs, pipped, lay); + if (claims) claimsCues(claims, { put, add, segIndex: (id) => idx.get(id), W: lay.width }); + // ---- 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); @@ -314,7 +322,7 @@ 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, ...(markers.length ? { markers } : {}) }; + return { init, cues, pips, slideY, choreography: ch, ...(markers.length ? { markers } : {}), ...(claims ? { claims } : {}) }; } /** A marker's pop as the fuse reaches it: from this scale, over these seconds. */ @@ -376,7 +384,7 @@ 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, markers = [] } = deckCues(schedule, render); + const { init, cues, pips, markers = [], claims = null } = deckCues(schedule, render); const t = lay.text; const tr = lay.pipTrack; const qr = lay.qr; @@ -489,6 +497,16 @@ export function deckHtml(schedule, render, opts = {}) { `</div>` : ""; + // The claim checks: a veil is the panel's own colour where it stands, so it + // dims the rail and the pips under it and draws nothing of its own. + const plateTop = mix(top, pal.bg, 0.55), plateBottom = mix(bottom, pal.bg, 0.6); + const claimMarkup = claims + ? claimsMarkup(claims, { + lay, pal, pipSize: Math.max(pip.size, Math.round((pip.size * 5) / 3)), + ground: (x) => (panel && qr && x >= plateX ? mix(plateTop, plateBottom, tr.y / H) : mix(top, bottom, tr.y / H)), + }) + : null; + const fuseLeft = pips[0]?.x ?? tr.x0; const fuseWidth = pips.length > 1 ? pips[pips.length - 1].x - fuseLeft : 0; @@ -627,7 +645,7 @@ export function deckHtml(schedule, render, opts = {}) { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }` : ""}${staggered ? ` /* Staggered labels: row 1 a row above, its flag's stick up to it. */ .mflag.up .mlabel { top: ${band.y - tr.y}px; } - .mflag.up .mstick { top: ${band.y + 20 - tr.y}px; height: ${tr.y + 6 - (band.y + 20)}px; }` : ""} + .mflag.up .mstick { top: ${band.y + 20 - tr.y}px; height: ${tr.y + 6 - (band.y + 20)}px; }` : ""}${claimMarkup ? claimMarkup.css : ""} .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); } @@ -644,11 +662,11 @@ export function deckHtml(schedule, render, opts = {}) { <div class="track"> <div class="rail"></div> ${fuseWidth > 0 ? `<div class="fuse" data-k="fuse"></div>` : ""} - ${pipHtml}${markerHtml} + ${pipHtml}${markerHtml}${claimMarkup ? claimMarkup.track : ""} <div class="marker" data-k="marker"></div> </div> ${tallyHtml} - ${segHtml} + ${segHtml}${claimMarkup ? claimMarkup.text : ""} </div> </div> </div> diff --git a/umtool/report-to-video/chrome-finale.mjs b/umtool/report-to-video/chrome-finale.mjs @@ -22,7 +22,8 @@ // 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 { deckLayout, deckMarkers, pageDuration, pipSegments, pipXs, resolveDeck } from "./deck.mjs"; +import { claimsLayout, deckLayout, deckMarkers, pageDuration, pipSegments, pipXs, resolveDeck } from "./deck.mjs"; +import { finaleClaims, finaleClaimsMarkup } from "./chrome-claims.mjs"; import { mix, rgba, shapeCss, subtitleMarkup } from "./chrome-deck.mjs"; import { resolveFactcheck, tallyFinals, tallyOf, tallyVerdicts, VERDICT_SHAPES } from "./factcheck.mjs"; import { @@ -110,7 +111,7 @@ export function finaleLayout(schedule, render) { const span = lay.pipTrack.x1 - lay.pipTrack.x0; const toBig = (x) => r2(x0 + ((x - lay.pipTrack.x0) * (rail.x1 - x0)) / (span || 1)); const footMarks = deckMarkers(schedule, render, fxs, pipped, lay); - const marks = railMarkerLayout(footMarks.map((mk) => ({ x: toBig(mk.x), label: mk.label, color: mk.color })), geo) + const marks = railMarkerLayout(footMarks.map((mk) => ({ x: toBig(mk.x), label: mk.label, color: mk.color })), geo, { layout: deck.markerLayout }) .map((mk, j) => ({ ...mk, foot: { x: r2(footMarks[j].x) } })); // The totals: the tally's verdicts, each at its final count. @@ -151,6 +152,15 @@ export function finaleLayout(schedule, render) { 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 claim checks (`deck.claims`): the footer's, on the large track, in + // their final state. None: nothing here. + const fcl = claimsLayout(schedule, render, fxs, pipped, lay); + const claims = fcl + ? finaleClaims(fcl, { + toBig, Y: rail.y + shift, top: rail.top, markerRows: marks.length ? Math.max(...marks.map((mk) => mk.row)) + 1 : 0, + bigX: (k) => r2(xs[k]), size: rail.markerSize, textWidth, ringSize: bigSize + 14, pips, + }) + : null; return { geo, rail: { ...rail, x0, track: { x0, x1: rail.x1, y: rail.y + shift } }, @@ -169,6 +179,7 @@ export function finaleLayout(schedule, render) { text: { ...lay.text, titleY: deckY + lay.text.titleY, subtitleY: deckY + lay.text.subtitleY, ruleY: deckY + lay.text.ruleY }, }, pips, labels, marks, totals, stats, captions, panel, + ...(claims ? { claims } : {}), statsTitle: f.statsTitle, railLabels: f.railLabels, video: f.video, motion: f.motion, @@ -270,6 +281,8 @@ export function finaleCues(schedule, render, L = finaleLayout(schedule, render)) 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") reveal(`ml${j}`, R + j * m.stagger, "finale marker label"); }); + // The claim checks, once the rail is in place. + (L.claims?.items ?? []).forEach((it, j) => reveal(`fq${it.j}`, R + 0.15 + j * m.stagger, "finale claim")); L.labels.groups.forEach((g, j) => { reveal(`pl${j}`, R + 0.05 + j * (m.stagger / 2), "finale label"); if (g.to > g.from) reveal(`sp${j}`, R, "finale span"); @@ -409,7 +422,7 @@ export function finaleHtml(schedule, render, window, opts = {}) { }) .join(""); - const rowTop = [Y - 72, Y - 112]; + const rowTop = [Y - 72, Y - 112, Y - 152]; const markHtml = L.marks .map((mk, j) => { const top = rowTop[mk.row] ?? rowTop[0]; @@ -459,6 +472,14 @@ export function finaleHtml(schedule, render, window, opts = {}) { }) .join(""); + // The claim checks: a veil is the rail panel's colour at the track. + const fq = L.claims + ? finaleClaimsMarkup(L.claims, { + Y, size: rail.markerSize, pal, + ground: mix(panelTop, panelBottom, Math.max(0, Math.min(1, (Y - (rail.top - 12)) / (L.panel.bottom - (rail.top - 12))))), + }) + : null; + const data = { from: r4(from), dur, init, cues: cues.map(({ why, ...c }) => c), @@ -518,7 +539,7 @@ export function finaleHtml(schedule, render, window, opts = {}) { .mh.left { left: -18px; clip-path: polygon(100% 0%, 0% 50%, 100% 100%); } .ml { position: absolute; height: ${Math.round(rail.markerSize * 1.25)}px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: 'DeckSansBold', sans-serif; font-size: ${rail.markerSize}px; line-height: ${Math.round(rail.markerSize * 1.25)}px; - letter-spacing: 0.04em; text-transform: uppercase; color: var(--mc); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); margin-top: -${Math.round(rail.markerSize * 0.2)}px; } + letter-spacing: 0.04em; text-transform: uppercase; color: var(--mc); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); margin-top: -${Math.round(rail.markerSize * 0.2)}px; }${fq ? fq.css : ""} .tc { position: absolute; border-radius: 14px; background: ${rgba(pal.fg, 0.045)}; box-shadow: inset 0 0 0 2px var(--vr); overflow: hidden; transform-origin: 0 0; } .tbar { position: absolute; left: 0; top: 0; width: 100%; height: 8px; background: var(--vc); } @@ -560,7 +581,7 @@ export function finaleHtml(schedule, render, window, opts = {}) { <div class="panel" data-k="panel"></div> <div class="track" data-k="track"></div> ${L.pips.length > 1 ? `<div class="fuse" data-k="fuse"></div>` : ""} - ${spans}${markHtml}${pipHtml} + ${spans}${markHtml}${pipHtml}${fq ? fq.html : ""} ${labelHtml} ${totalsHtml} ${statsHtml} diff --git a/umtool/report-to-video/claims.mjs b/umtool/report-to-video/claims.mjs @@ -0,0 +1,255 @@ +// CLAIM CHECKS on the deck: a subject's explicit claims drawn against the +// record on the footer's rail (`render.chrome.deck.claims`, DESIGN 2026-10-24). +// +// "claims": [ +// { "kind": "count", "at": "<clip id>", "t": <source second he says it>, +// "said": "“less than ten” in a year", +// "window": { "from": "2025-10-22", "to": "2026-10-22" }, +// "tally": "<verdict key or its label>", +// "per": "P1W", -- optional: P1D, P1W or P1M +// "claim": { "op": "<", "value": 10 } -- optional: what the lint holds the record to +// }, +// { "kind": "goalpost", "label": "Pill test results", +// "steps": [ { "at": "pill-test", "t": 1549.2, "said": "“3–5 weeks”", +// "from": "2026-09-23", "due": ["P3W", "P5W"] }, … ] } +// ] +// +// A COUNT claim is a number he gave over a window of dates. The record is the +// fact-check tally's own stamps (factcheck.mjs) of the verdict `tally` names, +// each dated by its `eventDate` when it has one, else by its clip's date. Without +// `per`, the window's total is set against his words (the year band); with +// `per`, every span of that length holding `claim.value` or more is found -- +// "no span of `per` holds `value` or more" is the claim the spans answer. +// +// A GOALPOST is a deadline he set and moved: each step's due window is its +// `from` date (else its clip's date) plus the two durations of `due`. +// +// PURE AND DEPENDENCY-FREE: no node:*, nothing imported -- so umtool's claims +// editor takes this file into a client bundle and validates as the build does +// (one validator, as deck.mjs says of its own). deck.mjs builds the schedule +// and the geometry from these pieces; chrome-deck.mjs and chrome-finale.mjs +// draw them. + +/** The kinds of claim the deck draws. */ +export const DECK_CLAIM_KINDS = Object.freeze(["count", "goalpost"]); + +/** The limits: how many claims, a quote's and a label's characters, a goalpost's steps. */ +export const DECK_CLAIM_LIMITS = Object.freeze({ count: 6, said: 60, label: 40, steps: 4, durationUnits: 365 }); + +/** What a count claim's `per` may be: a day, a week, a month. */ +export const DECK_CLAIM_PERS = Object.freeze(["P1D", "P1W", "P1M"]); + +/** The comparisons a count claim's `claim.op` may make. */ +export const DECK_CLAIM_OPS = Object.freeze(["<", "<=", ">", ">=", "="]); + +/** The keys each kind may carry, and each goalpost step. */ +export const DECK_CLAIM_KEYS = Object.freeze({ + count: Object.freeze(["kind", "at", "t", "said", "window", "tally", "per", "claim"]), + goalpost: Object.freeze(["kind", "label", "steps"]), + step: Object.freeze(["at", "t", "said", "from", "due"]), +}); + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/; +const DURATION = /^P(\d{1,3})([DWM])$/; + +/** Is `s` a real calendar date written YYYY-MM-DD? */ +export function isIsoDate(s) { + const m = ISO_DATE.exec(String(s ?? "")); + if (!m) return false; + const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])); + return d.getUTCFullYear() === +m[1] && d.getUTCMonth() === +m[2] - 1 && d.getUTCDate() === +m[3]; +} + +/** Days since the epoch of a YYYY-MM-DD (UTC), so dates compare and subtract as numbers. */ +export const dayOf = (s) => Date.UTC(+s.slice(0, 4), +s.slice(5, 7) - 1, +s.slice(8, 10)) / 86400000; + +/** A day number back to YYYY-MM-DD. */ +export const dateOfDay = (n) => new Date(n * 86400000).toISOString().slice(0, 10); + +/** Is `s` an ISO-8601 duration the deck reads: `P<n>D`, `P<n>W` or `P<n>M`, n from 1 to 365? */ +export function isDuration(s) { + const m = DURATION.exec(String(s ?? "")); + return !!m && +m[1] >= 1 && +m[1] <= DECK_CLAIM_LIMITS.durationUnits; +} + +/** + * A date plus a duration, as YYYY-MM-DD: days and weeks are days; a month is + * the calendar's (31 Jan + P1M is the month's last day, 28 or 29 Feb). + */ +export function addDuration(date, dur) { + const m = DURATION.exec(dur); + if (!m || !isIsoDate(date)) throw new Error(`addDuration: ${date} + ${dur}`); + const n = +m[1]; + if (m[2] === "D") return dateOfDay(dayOf(date) + n); + if (m[2] === "W") return dateOfDay(dayOf(date) + 7 * n); + const y = +date.slice(0, 4), mo = +date.slice(5, 7) - 1 + n, d = +date.slice(8, 10); + const last = new Date(Date.UTC(y, mo + 1, 0)).getUTCDate(); + return new Date(Date.UTC(y, mo, Math.min(d, last))).toISOString().slice(0, 10); +} + +/** A duration's length in days, for ordering two of them (a month counts 30). */ +export const durationDays = (dur) => { + const m = DURATION.exec(dur); + return m ? +m[1] * (m[2] === "D" ? 1 : m[2] === "W" ? 7 : 30) : NaN; +}; + +const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + +/** + * Two dates as the rail prints them: `14–28 Oct`, `26 Nov–10 Dec`, and with + * the years when they differ (`28 Dec 2026–3 Jan 2027`). By hand, not Intl, + * so a render does not depend on the machine's locale (attribution.mjs). + */ +export function dayRange(a, b) { + const [ya, ma, da] = [+a.slice(0, 4), +a.slice(5, 7) - 1, +a.slice(8, 10)]; + const [yb, mb, db] = [+b.slice(0, 4), +b.slice(5, 7) - 1, +b.slice(8, 10)]; + if (a === b) return `${da} ${MONTHS[ma]}`; + if (ya !== yb) return `${da} ${MONTHS[ma]} ${ya}–${db} ${MONTHS[mb]} ${yb}`; + if (ma === mb) return `${da}–${db} ${MONTHS[mb]}`; + return `${da} ${MONTHS[ma]}–${db} ${MONTHS[mb]}`; +} + +/** Does `actual op value` hold? */ +export function compares(actual, op, value) { + switch (op) { + case "<": return actual < value; + case "<=": return actual <= value; + case ">": return actual > value; + case ">=": return actual >= value; + case "=": return actual === value; + default: return false; + } +} + +/** A `per` as the words a span is labelled with: "in a day", "in a week", "in a month". */ +export const PER_WORDS = Object.freeze({ P1D: "a day", P1W: "a week", P1M: "a month" }); + +/** + * The spans of `per` in which the record holds `value` or more, greedy and + * non-overlapping, earliest first: from each dated stamp in date order, the + * stamps within `per` of it (a week: that day and the six after it) are + * summed; a span that reaches `value` is taken and the walk goes on after its + * last stamp, else it goes on from the next stamp. A span's `unit` is "day" + * when all its stamps fall on one day (`12 in a day`), else `per`'s. + * + * `stamps` are `{ date, count, ... }` (anything else rides along in the span's + * `stamps`), dated YYYY-MM-DD. + * + * @returns {Array<{ from: string, to: string, count: number, unit: string, label: string, stamps: any[] }>} + */ +export function findSpans(stamps, per, value) { + const dated = stamps.filter((s) => isIsoDate(s.date)).sort((a, b) => dayOf(a.date) - dayOf(b.date)); + const out = []; + let i = 0; + while (i < dated.length) { + const start = dated[i].date; + const end = per === "P1D" ? start : dateOfDay(dayOf(addDuration(start, per)) - 1); + let j = i; + let sum = 0; + while (j < dated.length && dayOf(dated[j].date) <= dayOf(end)) { sum += dated[j].count ?? 1; j += 1; } + if (sum >= value) { + const inside = dated.slice(i, j); + const to = inside[inside.length - 1].date; + const unit = to === start ? "a day" : PER_WORDS[per] ?? "a week"; + out.push({ from: start, to, count: sum, unit, label: `${sum} in ${unit}`, stamps: inside }); + i = j; + } else i += 1; + } + return out; +} + +/** The due window a goalpost step's words imply: its from date plus each of `due`. */ +export const dueWindow = (from, due) => [addDuration(from, due[0]), addDuration(from, due[1])]; + +const oneLine = (v, max, where, what, errors) => { + if (typeof v !== "string" || !v.trim()) { errors.push(`${where} must be ${what}`); return; } + if (/[\r\n]/.test(v)) errors.push(`${where} must be one line`); + else if ([...v.trim()].length > max) errors.push(`${where} is ${[...v.trim()].length} characters (at most ${max})`); +}; + +const clipRef = (v, where, errors) => { + if (typeof v !== "string" || !v.trim()) errors.push(`${where} must name a clip's id`); +}; + +const second = (v, where, errors) => { + if (typeof v !== "number" || !Number.isFinite(v) || v < 0) errors.push(`${where} must be the source second he says it (0 or more)`); +}; + +/** + * Every reason a `deck.claims` list cannot be drawn, its shape alone: the + * clips it names and the verdict `tally` names are the timeline's and the + * fact-check's (deck.mjs validateDeckClaims checks those). deck.mjs + * validateChrome calls this; umtool's claims editor calls it as the person types. + * + * @returns {string[]} + */ +export function deckClaimShapeErrors(claims, where = "render.chrome.deck.claims") { + if (claims === undefined) return []; + if (!Array.isArray(claims)) return [`${where} must be a list of claims ({ kind: "count" | "goalpost", … })`]; + const errors = []; + if (claims.length > DECK_CLAIM_LIMITS.count) errors.push(`${where} has ${claims.length} claims (at most ${DECK_CLAIM_LIMITS.count})`); + claims.forEach((c, i) => { + const w = `${where}[${i}]`; + if (!isObj(c)) { errors.push(`${w} must be { kind, … }`); return; } + if (!DECK_CLAIM_KINDS.includes(c.kind)) { errors.push(`${w}.kind must be ${DECK_CLAIM_KINDS.map((k) => `"${k}"`).join(" or ")}`); return; } + const keys = DECK_CLAIM_KEYS[c.kind]; + for (const k of Object.keys(c)) if (!keys.includes(k)) errors.push(`${w}.${k} is not a ${c.kind} claim's setting (${keys.join(", ")})`); + if (c.kind === "count") { + clipRef(c.at, `${w}.at`, errors); + second(c.t, `${w}.t`, errors); + oneLine(c.said, DECK_CLAIM_LIMITS.said, `${w}.said`, "his words, in quotes", errors); + if (!isObj(c.window)) errors.push(`${w}.window must be { from, to }, two dates (YYYY-MM-DD)`); + else { + for (const k of Object.keys(c.window)) if (k !== "from" && k !== "to") errors.push(`${w}.window.${k} is not a window setting (from, to)`); + for (const k of ["from", "to"]) if (!isIsoDate(c.window[k])) errors.push(`${w}.window.${k} must be a date (YYYY-MM-DD)`); + if (isIsoDate(c.window.from) && isIsoDate(c.window.to) && dayOf(c.window.from) > dayOf(c.window.to)) { + errors.push(`${w}.window.from ${c.window.from} is after its to ${c.window.to}`); + } + } + if (typeof c.tally !== "string" || !c.tally.trim()) errors.push(`${w}.tally must name the tally's verdict (its key, or its label)`); + if (c.per !== undefined && !DECK_CLAIM_PERS.includes(c.per)) { + errors.push(`${w}.per must be ${DECK_CLAIM_PERS.map((p) => `"${p}"`).join(", ")} (a day, a week, a month), or absent`); + } + if (c.claim !== undefined) { + if (!isObj(c.claim)) errors.push(`${w}.claim must be { op, value }`); + else { + for (const k of Object.keys(c.claim)) if (k !== "op" && k !== "value") errors.push(`${w}.claim.${k} is not a claim setting (op, value)`); + if (!DECK_CLAIM_OPS.includes(c.claim.op)) errors.push(`${w}.claim.op must be one of ${DECK_CLAIM_OPS.join(" ")}`); + if (typeof c.claim.value !== "number" || !Number.isFinite(c.claim.value) || c.claim.value < 0) { + errors.push(`${w}.claim.value must be a number, 0 or more`); + } + } + } + return; + } + if (c.label !== undefined) oneLine(c.label, DECK_CLAIM_LIMITS.label, `${w}.label`, "a few words", errors); + if (!Array.isArray(c.steps) || !c.steps.length) { errors.push(`${w}.steps must be a list of 1 to ${DECK_CLAIM_LIMITS.steps} steps`); return; } + if (c.steps.length > DECK_CLAIM_LIMITS.steps) errors.push(`${w}.steps has ${c.steps.length} steps (at most ${DECK_CLAIM_LIMITS.steps})`); + c.steps.forEach((s, k) => { + const ws = `${w}.steps[${k}]`; + if (!isObj(s)) { errors.push(`${ws} must be { at, t, said, from?, due }`); return; } + for (const key of Object.keys(s)) if (!DECK_CLAIM_KEYS.step.includes(key)) errors.push(`${ws}.${key} is not a step's setting (${DECK_CLAIM_KEYS.step.join(", ")})`); + clipRef(s.at, `${ws}.at`, errors); + second(s.t, `${ws}.t`, errors); + oneLine(s.said, DECK_CLAIM_LIMITS.said, `${ws}.said`, "his words, in quotes", errors); + if (s.from !== undefined && !isIsoDate(s.from)) errors.push(`${ws}.from must be a date (YYYY-MM-DD), or absent for the clip's date`); + if (!Array.isArray(s.due) || s.due.length !== 2 || !s.due.every(isDuration)) { + errors.push(`${ws}.due must be two durations, the soonest first (["P3W", "P5W"]: P<n>D, P<n>W or P<n>M)`); + } else if (durationDays(s.due[0]) > durationDays(s.due[1])) { + errors.push(`${ws}.due ${s.due[0]} is longer than ${s.due[1]}: the soonest first`); + } + }); + }); + return errors; +} + +/** Which verdict a claim's `tally` names: a verdict key as written, else the verdict whose label it is (case aside). */ +export function tallyVerdictOf(tally, verdicts) { + const t = String(tally ?? "").trim(); + if (!t) return null; + if (verdicts[t]) return t; + const lower = t.toLowerCase(); + for (const [k, v] of Object.entries(verdicts)) if (String(v?.label ?? "").trim().toLowerCase() === lower) return k; + return null; +} diff --git a/umtool/report-to-video/deck-claims.test.mjs b/umtool/report-to-video/deck-claims.test.mjs @@ -0,0 +1,339 @@ +// The deck's claim checks (`render.chrome.deck.claims`, claims.mjs): the +// validator, the spans a `per` claim finds, the window by `eventDate`, a +// goalpost's due dates and where they land on a rail laid by order (off it +// past its last date), the timing in the cut's clock -- and a deck without +// claims composing the page it always did, byte for byte. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import test from "node:test"; + +import { + addDuration, dayRange, deckClaimShapeErrors, dueWindow, findSpans, isDuration, isIsoDate, tallyVerdictOf, +} from "./claims.mjs"; +import { + CLAIM_ROW, claimRecordNotes, claimsLayout, deckClaimNotes, deckLayout, deckSchedule, estimateSchedule, pipSegments, pipXs, + snapWindow, validateChrome, validateDeckClaims, +} from "./deck.mjs"; +import { deckCues, deckHtml } from "./chrome-deck.mjs"; +import { finaleHtml } from "./chrome-finale.mjs"; +import { finaleGeometry, railMarkerLayout } from "./finale.mjs"; +import { normalizeClaim, resolveFactcheck, stampSchedule } from "./factcheck.mjs"; + +const PALETTE = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; +const SEIZURES = { verdicts: { CORROBORATED: { label: "Seizures", color: "#e5534b", stampLabel: "Seizure" } } }; +const md5 = (s) => createHash("md5").update(s).digest("hex"); + +// The Huck walked cut in small: dated clips in the cut's order (not the +// calendar's -- a flash-forward and two old clips at the end, then a finale), +// the record as the tally's stamps, his two claims in one late clip. +const CLIPS = [ + ["arrive", "20201024"], ["meds", "20250514"], ["neuro", "20251106"], ["worst", "20260120", 1, "2026-01-19"], + ["dozen", "20260824", 12, "2026-08-24"], ["ten-k", "20260826"], ["flash", "20261016"], ["rescue", "20260908", 1, "2026-09-08"], + ["pill-test", "20260923"], ["costco-ok", "20261008", 1, "2026-09-22"], ["on-stream-b", "20261014", 3, "2026-10-14"], + ["screenshot", "20261015"], ["blind-oct", "20261020", 1, "2026-10-20"], ["quality", "20261021"], ["less-than-ten", "20261022"], + ["blend", "20261022"], ["tism", "20190613"], ["heartstrings", "20210408"], +]; +// `events: false` leaves the marks' eventDates out: the fixture as it was before they existed. +const entries = (events = true) => CLIPS.map(([id, , count, eventDate], i) => ({ + type: "clip", id, video: `v${i}`, start: 100 * i, end: 100 * i + 30, + ...(count ? { claim: { id, verdict: "CORROBORATED", at: 100 * i + 10, ...(count > 1 ? { count } : {}), ...(eventDate && events ? { eventDate } : {}) } } : {}), + ...(id === "heartstrings" ? { layout: "finale" } : {}), +})); +const metas = () => CLIPS.map(([, up]) => ({ title: "T", uploadDate: up, channel: "C", webpageUrl: null })); +const CLAIMS = [ + { kind: "count", at: "less-than-ten", t: 1405, said: "“doesn't have multiple seizures a week”", window: { from: "2025-10-22", to: "2026-10-22" }, + tally: "Seizures", per: "P1W", claim: { op: "<", value: 2 } }, + { kind: "count", at: "less-than-ten", t: 1410, said: "“less than ten” in a year", window: { from: "2025-10-22", to: "2026-10-22" }, + tally: "Seizures", claim: { op: "<", value: 10 } }, + { kind: "goalpost", label: "Pill test results", steps: [ + { at: "pill-test", t: 815, said: "“3–5 weeks”", from: "2026-09-23", due: ["P3W", "P5W"] }, + { at: "screenshot", t: 1112, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }, + ] }, +]; +const renderWith = (deck = {}) => ({ + width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, + chrome: { engine: "hyperframes", layout: "deck", deck: { pip: { color: "verdict" }, markers: [{ after: "quality", label: "No results after 8 wks", color: "#e5534b" }], finale: { video: "side" }, ...deck }, factcheck: SEIZURES }, +}); +const manifest = (deck = { claims: CLAIMS }, events = true) => ({ + timeline: entries(events), render: renderWith(deck), provenance: { siteOrigin: "https://example.test", channelSlug: "c" }, +}); +const schedule = (m = manifest()) => estimateSchedule(m, { metas: metas() }); + +// ---- the validator ---------------------------------------------------------- + +test("deckClaimShapeErrors: every shape refused in a sentence; the design's shapes pass", () => { + assert.deepEqual(deckClaimShapeErrors(CLAIMS), []); + assert.deepEqual(validateChrome({ engine: "hyperframes", layout: "deck", deck: { claims: CLAIMS } }), []); + const w = "render.chrome.deck.claims"; + assert.deepEqual(deckClaimShapeErrors({}), [`${w} must be a list of claims ({ kind: "count" | "goalpost", … })`]); + assert.deepEqual(deckClaimShapeErrors([{ kind: "lie" }]), [`${w}[0].kind must be "count" or "goalpost"`]); + const bad = deckClaimShapeErrors([{ + kind: "count", at: "", t: -1, said: "", window: { from: "2026-02-30", to: "2025-01-01" }, tally: "", per: "P2W", claim: { op: "≈", value: "ten" }, extra: 1, + }]); + for (const e of [ + `${w}[0].extra is not a count claim's setting (kind, at, t, said, window, tally, per, claim)`, + `${w}[0].at must name a clip's id`, + `${w}[0].t must be the source second he says it (0 or more)`, + `${w}[0].said must be his words, in quotes`, + `${w}[0].window.from must be a date (YYYY-MM-DD)`, + `${w}[0].tally must name the tally's verdict (its key, or its label)`, + `${w}[0].per must be "P1D", "P1W", "P1M" (a day, a week, a month), or absent`, + `${w}[0].claim.op must be one of < <= > >= =`, + `${w}[0].claim.value must be a number, 0 or more`, + ]) assert.ok(bad.includes(e), `${e}\n in\n${bad.join("\n")}`); + assert.ok(deckClaimShapeErrors([{ ...CLAIMS[1], window: { from: "2026-10-22", to: "2025-10-22" } }]) + .includes(`${w}[0].window.from 2026-10-22 is after its to 2025-10-22`)); + const steps = deckClaimShapeErrors([{ kind: "goalpost", steps: [{ at: "x", t: 1, said: "“w”", from: "soon", due: ["P5W", "P3W"] }, { at: "x", t: 1, said: "“w”", due: ["3 weeks"] }] }]); + assert.ok(steps.includes(`${w}[0].steps[0].from must be a date (YYYY-MM-DD), or absent for the clip's date`), steps.join("\n")); + assert.ok(steps.includes(`${w}[0].steps[0].due P5W is longer than P3W: the soonest first`), steps.join("\n")); + assert.ok(steps.includes(`${w}[0].steps[1].due must be two durations, the soonest first (["P3W", "P5W"]: P<n>D, P<n>W or P<n>M)`), steps.join("\n")); + assert.ok(deckClaimShapeErrors(Array.from({ length: 7 }, () => CLAIMS[1])).includes(`${w} has 7 claims (at most 6)`)); +}); + +test("validateDeckClaims: each claim said in a clip of the timeline, its tally a verdict by key or by label", () => { + assert.deepEqual(validateDeckClaims(manifest()), []); + const m = manifest({ claims: [{ ...CLAIMS[1], at: "gone", tally: "Grift" }, { ...CLAIMS[2], steps: [{ ...CLAIMS[2].steps[0], at: "nope" }] }] }); + const errs = validateDeckClaims(m); + assert.ok(errs.includes("render.chrome.deck.claims[0].at names gone, which is not in the timeline"), errs.join("\n")); + assert.ok(errs.some((e) => e.startsWith('render.chrome.deck.claims[0].tally "Grift" names no verdict')), errs.join("\n")); + assert.ok(errs.includes("render.chrome.deck.claims[1].steps[0].at names nope, which is not in the timeline"), errs.join("\n")); + const verdicts = resolveFactcheck(renderWith()).verdicts; + assert.equal(tallyVerdictOf("seizures", verdicts), "CORROBORATED"); + assert.equal(tallyVerdictOf("CORROBORATED", verdicts), "CORROBORATED"); + assert.equal(tallyVerdictOf("Seizure", verdicts), null); +}); + +test("deckClaimNotes: a second outside the clip's play window is a note, not an error", () => { + assert.deepEqual(deckClaimNotes(manifest()), []); + const notes = deckClaimNotes(manifest({ claims: [{ ...CLAIMS[1], t: 5 }] })); + assert.deepEqual(notes, ["render.chrome.deck.claims[0].t 5 is outside less-than-ten's play window 1400–1430 (source seconds): it is drawn at the window's edge"]); +}); + +test("a mark's eventDate: a real date, carried onto its stamp only when set", () => { + assert.deepEqual(normalizeClaim({ id: "k", verdict: "CORROBORATED", eventDate: "2026-09-22" }), { id: "k", verdict: "CORROBORATED", eventDate: "2026-09-22" }); + assert.throws(() => normalizeClaim({ id: "k", verdict: "CORROBORATED", eventDate: "22 Sep" }), /claim\.eventDate must be a date \(YYYY-MM-DD\)/); + const segs = [{ id: "a", start: 0, duration: 10, claim: { id: "a", verdict: "CORROBORATED", eventDate: "2026-09-22" } }, { id: "b", start: 9.5, duration: 10, claim: { id: "b", verdict: "CORROBORATED" } }]; + const [sa, sb] = stampSchedule({ segments: segs, D: 0.5, total: 19.5, render: renderWith() }); + assert.equal(sa.eventDate, "2026-09-22"); + assert.ok(!("eventDate" in sb)); +}); + +// ---- dates ------------------------------------------------------------------ + +test("the date arithmetic: durations, a month's last day, the rail's printed ranges", () => { + assert.equal(isIsoDate("2026-02-29"), false); + assert.equal(isIsoDate("2028-02-29"), true); + assert.ok(isDuration("P3W") && isDuration("P1M") && !isDuration("P0W") && !isDuration("3W")); + assert.deepEqual(dueWindow("2026-09-23", ["P3W", "P5W"]), ["2026-10-14", "2026-10-28"]); + assert.deepEqual(dueWindow("2026-10-15", ["P6W", "P8W"]), ["2026-11-26", "2026-12-10"]); + assert.equal(addDuration("2026-01-31", "P1M"), "2026-02-28"); + assert.equal(addDuration("2026-12-30", "P3D"), "2027-01-02"); + assert.equal(dayRange("2026-10-14", "2026-10-28"), "14–28 Oct"); + assert.equal(dayRange("2026-11-26", "2026-12-10"), "26 Nov–10 Dec"); + assert.equal(dayRange("2026-12-28", "2027-01-03"), "28 Dec 2026–3 Jan 2027"); + assert.equal(dayRange("2026-08-24", "2026-08-24"), "24 Aug"); +}); + +test("findSpans: greedy, non-overlapping, by date -- Huck's record against “multiple seizures a week”", () => { + const record = [ + { date: "2026-01-19", count: 1 }, { date: "2026-08-24", count: 12 }, { date: "2026-09-08", count: 1 }, + { date: "2026-09-22", count: 1 }, { date: "2026-10-14", count: 3 }, { date: "2026-10-20", count: 1 }, + ]; + assert.deepEqual(findSpans(record, "P1W", 2).map(({ stamps: _s, ...sp }) => sp), [ + { from: "2026-08-24", to: "2026-08-24", count: 12, unit: "a day", label: "12 in a day" }, + { from: "2026-10-14", to: "2026-10-20", count: 4, unit: "a week", label: "4 in a week" }, + ]); + // A day: only the same day counts. + assert.deepEqual(findSpans(record, "P1D", 2).map((sp) => sp.label), ["12 in a day", "3 in a day"]); + // A month from 24 Aug takes everything to 23 Sep (12 + 1 + 1), then from 14 Oct. + assert.deepEqual(findSpans(record, "P1M", 2).map((sp) => sp.label), ["14 in a month", "4 in a month"]); + // Nothing reaches it: no span -- the record agrees with him. + assert.deepEqual(findSpans(record, "P1W", 20), []); +}); + +// ---- the schedule ------------------------------------------------------------- + +test("claimsSchedule: the window counts by eventDate, 19 in Huck's year; the per spans; his seconds in the cut's clock", () => { + const s = schedule(); + const seg = s.segments.find((x) => x.id === "less-than-ten"); + const next = s.segments[s.segments.findIndex((x) => x.id === "less-than-ten") + 1]; + const [week, year, goal] = s.deckClaims.items; + assert.equal(year.total, 19); + assert.deepEqual(year.stamps.map((x) => x.date), ["2026-01-19", "2026-08-24", "2026-09-08", "2026-09-22", "2026-10-14", "2026-10-20"]); + // costco-ok was said on 8 Oct; its eventDate (22 Sep) is what the window reads. + assert.equal(year.stamps.find((x) => x.segment === "costco-ok").date, "2026-09-22"); + assert.equal(year.holds, false); + assert.equal(year.noun, "seizures"); + assert.deepEqual(week.spans.map((sp) => [sp.label, sp.segments]), [["12 in a day", ["dozen"]], ["4 in a week", ["on-stream-b", "blind-oct"]]]); + assert.equal(week.holds, false); + // t through the play window's start (no cut record in an estimate), until the next segment's mid-dissolve. + assert.equal(week.at, seg.start + 5); + assert.equal(year.at, seg.start + 10); + assert.equal(year.until, next.start + 0.25); + // The schedule names the second a claim clip's segment starts at, for the preview to place it again. + assert.equal(seg.sourceFrom, 1400); + assert.deepEqual(goal.steps.map((st) => [st.segment, st.due, st.dueText]), [ + ["pill-test", ["2026-10-14", "2026-10-28"], "14–28 Oct"], ["screenshot", ["2026-11-26", "2026-12-10"], "26 Nov–10 Dec"], + ]); + // A stamp moved out of the window by its eventDate leaves the count. + const m = manifest(); + m.timeline.find((e) => e.id === "worst").claim.eventDate = "2025-01-19"; + assert.equal(schedule(m).deckClaims.items[1].total, 18); + // What the record says: nothing, when it contradicts him; a note when it does not. + assert.deepEqual(claimRecordNotes(s), []); + const agrees = manifest({ claims: [{ ...CLAIMS[1], claim: { op: "<", value: 30 } }] }); + assert.match(claimRecordNotes(schedule(agrees))[0], /the record's 19 seizures in 2025-10-22–2026-10-22 is < 30 -- it does not contradict him/); +}); + +test("claimsLayout: the year band between the pips around its dates; a goalpost past the rail's last date runs off it", () => { + const s = schedule(); + const render = renderWith({ claims: CLAIMS }); + const lay = deckLayout(render, { schedule: s }); + const pipped = pipSegments(s); + const xs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, "even"); + const k = (id) => pipped.findIndex((p) => p.id === id); + const cl = claimsLayout(s, render, xs, pipped, lay); + const [week, year, goal] = cl.items; + // 22 Oct 2025 falls between meds (14 May 2025) and neuro (6 Nov 2025): the band starts there. + assert.ok(year.band.a > xs[k("meds")] && year.band.a < xs[k("neuro")], JSON.stringify(year.band)); + assert.ok(year.band.b > xs[k("blend")] && year.band.b < xs[k("tism")], JSON.stringify(year.band)); + // The rail outside the band is veiled; the record's pips are tagged in date order; a pip a per span lit is not. + assert.ok(year.veils.length >= 2); + assert.deepEqual(year.tags.map((t) => [pipped[t.k].id, t.count, t.covered]), [ + ["worst", 1, false], ["dozen", 12, true], ["rescue", 1, false], ["costco-ok", 1, false], ["on-stream-b", 3, true], ["blind-oct", 1, true], + ]); + assert.deepEqual(week.spans.map((sp) => sp.label), ["12 in a day", "4 in a week"]); + // 14 Oct → 28 Oct: from on-stream-b's pip, open past 22 Oct (the rail's last date); 26 Nov → 10 Dec: off the rail. + const [s1, s2] = goal.steps; + assert.ok(Math.abs(s1.a - xs[k("on-stream-b")]) < 13, `${s1.a} vs ${xs[k("on-stream-b")]}`); + assert.equal(s1.open, true); + assert.equal(s1.off, false); + assert.ok(s1.b > xs[k("blend")] && s1.b < xs[k("tism")]); + assert.equal(s1.label, "“3–5 weeks” → 14–28 Oct"); + assert.equal(s2.off, true); + assert.equal(s2.b, cl.end); + assert.equal(s2.align, "right"); + assert.equal(s2.label, "“6–8 weeks” → 26 Nov–10 Dec"); + // A goalpost takes a row over the markers': the track moves down by it. + const without = deckLayout(renderWith(), { schedule: s }); + assert.equal(lay.pipTrack.y - without.pipTrack.y, CLAIM_ROW); + assert.deepEqual(lay.claimBand, { y: 3, height: CLAIM_ROW }); + assert.equal(lay.markerBand.y, 3 + CLAIM_ROW); +}); + +test("the cues: his words replace the clip's, the record lights in date order over ~1.2 s while the count steps to 19; the bracket moves", () => { + const s = schedule(); + const render = renderWith({ claims: CLAIMS }); + const { cues, init } = deckCues(s, render); + const [, year, goal] = s.deckClaims.items; + const of = (k) => cues.filter((c) => c.k === k); + // The year claim is item 1: its callout in at `at`, out by its clip's end. + assert.equal(of("c1.co")[0].at, year.at); + assert.ok(Math.abs(of("c1.co").at(-1).at + of("c1.co").at(-1).dur - year.until) < 1e-3); + // The per claim's callout gives way to the year's. + assert.ok(of("c0.co").at(-1).at + of("c0.co").at(-1).dur <= year.at + 0.36); + // The count: n0 … n6 = 0, 1, 13, 14, 15, 18, 19, each step as its tag lights, over 1.2 s. + const steps = cues.filter((c) => /^c1\.n\d+$/.test(c.k) && c.to.autoAlpha === 1).map((c) => c.at); + assert.equal(steps.length, 6); + assert.ok(steps[0] >= year.at && steps.at(-1) - steps[0] <= 1.2 + 1e-6, steps.join(" ")); + assert.equal(init["c1.n0"].autoAlpha, 1); + const idx = s.segments.findIndex((x) => x.id === "less-than-ten"); + assert.equal(of(`s${idx}.tc`).find((c) => c.to.opacity === 0).at, s.deckClaims.items[0].at); + // The bracket: the first drawn at pill-test's second; at screenshot's, it goes, its ghost comes, its copy moves off the frame. + assert.equal(of("g2.0")[0].at, goal.steps[0].at); + assert.equal(of("g2.0g")[0].at, goal.steps[1].at); + const move = of("g2.0m").find((c) => c.to.x !== undefined); + const lay = deckLayout(render, { schedule: s }); + const pipped = pipSegments(s); + const first = claimsLayout(s, render, pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, "even"), pipped, lay).items[2].steps[0]; + assert.ok(first.a + move.to.x > 1920, `the copy leaves the frame: ${JSON.stringify(move)}`); + const html = deckHtml(s, render, { fonts: { regular: "r.ttf", bold: "b.ttf" } }); + assert.match(html, /“less than ten” in a year/); + assert.match(html, /seizures on camera/); + assert.match(html, /12 in a day/); + assert.match(html, /“3–5 weeks” → 14–28 Oct/); +}); + +test("the finale's large rail draws every claim's final state", () => { + const s = schedule(); + const html = finaleHtml(s, renderWith({ claims: CLAIMS }), snapWindow({ segment: "finale", from: s.finale.from, to: s.finale.to }, { fps: 30, total: s.total }), {}); + assert.match(html, /19 seizures on camera/); + assert.match(html, /12 in a day · 4 in a week/); + assert.match(html, /class="fqbox open ghost"/); + assert.match(html, /“6–8 weeks”/); +}); + +test("claimsLayout: the band and the spans go by membership -- an old clip inside the band is dimmed, the outro outside it", () => { + // An old clip (2019) moved between dozen and ten-k: inside the band's reach, outside his window. + const m = manifest(); + const old = m.timeline.findIndex((e) => e.id === "tism"); + const [tism] = m.timeline.splice(old, 1); + m.timeline.splice(m.timeline.findIndex((e) => e.id === "ten-k"), 0, tism); + const order = m.timeline.map((e) => e.id); + const md = CLIPS.map(([id, up]) => ({ id, up })); + const s = estimateSchedule(m, { metas: order.map((id) => ({ title: "T", uploadDate: md.find((x) => x.id === id).up, channel: "C", webpageUrl: null })) }); + const render = renderWith({ claims: CLAIMS }); + const lay = deckLayout(render, { schedule: s }); + const pipped = pipSegments(s); + const xs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, "even"); + const x = (id) => xs[pipped.findIndex((p) => p.id === id)]; + const [week, year] = claimsLayout(s, render, xs, pipped, lay).items; + assert.ok(year.band.a < x("neuro") && year.band.b > x("blend") && year.band.b < x("heartstrings"), JSON.stringify(year.band)); + // The 2019 clip inside the band is veiled; heartstrings (2021, the outro) is outside it, veiled too. + assert.ok(year.veils.some(([a, b]) => a < x("tism") && b > x("tism")), JSON.stringify(year.veils)); + assert.ok(year.veils.some(([a, b]) => a < x("heartstrings") && b > x("heartstrings")), JSON.stringify(year.veils)); + assert.ok(!year.veils.some(([a, b]) => a < x("dozen") && b > x("dozen"))); + // "4 in a week": on-stream-b and blind-oct with screenshot between -- not one pip of another day: two bars. + const wk = week.spans.find((sp) => sp.label === "4 in a week"); + assert.equal(wk.bars.length, 2); +}); + +test("the finale's marker labels stagger into three rows and never meet; markerLayout truncate keeps one row", () => { + const geo = finaleGeometry({ width: 1920, height: 1080, palette: PALETTE, chrome: { deck: { finale: {} } } }); + const marks = [ + { x: 1105, label: "Pill test: “3–5 weeks”", color: "#e5534b" }, + { x: 1240, label: "Pill test: “6–8 weeks”", color: "#e5534b" }, + { x: 1305, label: "No results after 8 wks", color: "#e5534b" }, + ]; + const laid = railMarkerLayout(marks, geo); + const span = (mk) => (mk.side === "right" ? [mk.x, mk.x + 18 + mk.max] : [mk.x - 18 - mk.max, mk.x]); + for (let i = 0; i < laid.length; i += 1) { + for (let j = i + 1; j < laid.length; j += 1) { + if (laid[i].row !== laid[j].row) continue; + const [a, b] = span(laid[i]), [c, d] = span(laid[j]); + assert.ok(b < c || d < a, `${laid[i].label} and ${laid[j].label} meet in row ${laid[i].row}`); + } + } + assert.equal(new Set(laid.map((mk) => mk.row)).size, 3); + assert.deepEqual(railMarkerLayout(marks, geo, { layout: "truncate" }).map((mk) => mk.row), [0, 0, 0]); +}); + +// ---- no claims: the page it always was ------------------------------------------ + +test("absent claims: the schedule, the deck's page and the finale's are byte-identical to before claims existed", () => { + // md5s taken from main before deck.claims (066bac90), same fixture. + const s = schedule(manifest({}, false)); + assert.ok(!("deckClaims" in s)); + assert.ok(!s.segments.some((x) => "sourceFrom" in x && !x.claim)); + const render = renderWith(); + const page = deckHtml(s, render, { fonts: { regular: "r.ttf", bold: "b.ttf" } }); + const fin = finaleHtml(s, render, snapWindow({ segment: "finale", from: s.finale.from, to: s.finale.to }, { fps: 30, total: s.total }), {}); + assert.equal(md5(JSON.stringify(s)), BEFORE.schedule); + assert.equal(md5(page), BEFORE.deck); + assert.equal(md5(fin), BEFORE.finale); + // An empty list is no claims too. + const empty = schedule(manifest({ claims: [] }, false)); + assert.equal(md5(deckHtml(empty, renderWith({ claims: [] }), { fonts: { regular: "r.ttf", bold: "b.ttf" } })), BEFORE.deck); + // And deckSchedule straight, as the build calls it. + const d = deckSchedule({ entries: entries(false), durs: entries().map(() => 30), D: 0.5, render, metas: metas() }); + assert.equal(md5(JSON.stringify(d)), BEFORE.built); +}); + +const BEFORE = { + schedule: "3a6c6abc6f5d4c095333dbbbe7c85aef", + deck: "4966f5f6904d7c91e8c3bd64b16763b8", + finale: "e4cb165d4e3b816c0d648240cac91eb1", + built: "c6a44e98fce846811cbf87d449e6b40d", +}; diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -27,6 +27,9 @@ import { overlayPointsOf, resolveStats, statsSchedule, statsWanted, validateStat import { fxOn, fxSchedule, validateFx } from "./fx.mjs"; import { estimatedNarratedCardSeconds, hasNarration } from "./narration.mjs"; import { FINALE_MOTION, finaleGeometry, finaleRunOf, finaleRunProblems, resolveFinale, validateFinaleSettings } from "./finale.mjs"; +import { + compares, dayOf, dayRange, deckClaimShapeErrors, dueWindow, findSpans, isIsoDate, tallyVerdictOf, +} from "./claims.mjs"; /** Is the left panel on: the thread rail (threads.mjs) or the flips panel (flips.mjs) -- one region, one or the other. */ export const railOn = (render) => threadsOn(render) || flipsOn(render); @@ -213,9 +216,11 @@ export function validateChrome(chrome, render = {}) { if (!isObj(d)) return [...errors, "render.chrome.deck must be an object"]; const w = "render.chrome.deck"; // `finale` (finale.mjs) is the deck's too, with no default to fill: absent, - // nothing about the deck changes. - unknownKeys(d, [...Object.keys(DECK_DEFAULTS), "finale"], w, errors); + // nothing about the deck changes. So are `claims` (claims.mjs): his words + // against the record, drawn on the rail. + unknownKeys(d, [...Object.keys(DECK_DEFAULTS), "finale", "claims"], w, errors); errors.push(...validateFinaleSettings(d.finale, `${w}.finale`)); + errors.push(...deckClaimShapeErrors(d.claims, `${w}.claims`)); if (d.height !== undefined && !(Number.isInteger(d.height) && numIn(d.height, 120, 400))) { errors.push(`${w}.height must be a whole number of pixels from 120 to 400`); @@ -422,6 +427,123 @@ export function validateDeckMarkers(manifest) { return errors; } +/** + * The deck's claim checks (`deck.claims`, claims.mjs) checked whole: their + * shape, and against the WHOLE timeline and the fact-check, that each `at` + * names a clip in it and each count claim's `tally` names a verdict (its key, + * or its label as `factcheck.verdicts` relabels it). The build and the lint + * refuse with these; umtool's writers refuse before they write. Empty + * without the deck or without claims. + * + * @returns {string[]} + */ +export function validateDeckClaims(manifest) { + const claims = manifest?.render?.chrome?.deck?.claims; + if (!deckOn(manifest?.render) || claims === undefined) return []; + const where = "render.chrome.deck.claims"; + const errors = deckClaimShapeErrors(claims, where); + if (!Array.isArray(claims)) return errors; + const timeline = manifest.timeline ?? []; + const verdicts = resolveFactcheck(manifest.render).verdicts; + const clipAt = (id, w) => { + if (typeof id !== "string" || !id.trim()) return; // the shape says so + const hit = timeline.find((e) => e?.id === id.trim()); + if (!hit) errors.push(`${w} names ${id}, which is not in the timeline`); + else if (hit.type !== "clip") errors.push(`${w} names ${id}, a ${hit.type ?? "entry"}: he says it in a clip`); + }; + claims.forEach((c, i) => { + if (!isObj(c)) return; + if (c.kind === "count") { + clipAt(c.at, `${where}[${i}].at`); + if (typeof c.tally === "string" && c.tally.trim() && !tallyVerdictOf(c.tally, verdicts)) { + errors.push(`${where}[${i}].tally ${JSON.stringify(c.tally)} names no verdict (a key, or a label: ${Object.entries(verdicts).map(([k, v]) => `${k} "${v.label}"`).join(", ")})`); + } + } else if (c.kind === "goalpost" && Array.isArray(c.steps)) { + c.steps.forEach((st, k) => { if (isObj(st)) clipAt(st.at, `${where}[${i}].steps[${k}].at`); }); + } + }); + return errors; +} + +/** + * The clips the deck's claim checks are said in (`deck.claims`' `at`s): the + * build reads where each one's segment really starts (its cut record), as it + * does for a stamp at a source second. Empty without claims. + * + * @returns {Set<string>} + */ +export function deckClaimClips(render) { + const claims = render?.chrome?.deck?.claims; + const out = new Set(); + if (!Array.isArray(claims)) return out; + for (const c of claims) { + if (!isObj(c)) continue; + if (typeof c.at === "string") out.add(c.at.trim()); + if (Array.isArray(c.steps)) for (const st of c.steps) if (isObj(st) && typeof st.at === "string") out.add(st.at.trim()); + } + return out; +} + +/** + * What the deck's claim checks get wrong that no validator refuses, as notes + * (the lint's warnings): a second he says it at that is outside the window + * the clip plays (it is drawn at the window's nearest edge), and a goalpost + * whose steps are not in the cut's order. + * + * @returns {string[]} + */ +export function deckClaimNotes(manifest) { + const claims = manifest?.render?.chrome?.deck?.claims; + if (!deckOn(manifest?.render) || !Array.isArray(claims) || deckClaimShapeErrors(claims).length) return []; + const render = manifest.render; + const timeline = manifest.timeline ?? []; + const notes = []; + const where = "render.chrome.deck.claims"; + const inside = (id, t, w) => { + const e = timeline.find((x) => x?.id === id && x.type === "clip"); + if (!e) return; + const { from, to } = playWindow(e, render); + if (t < from || t > to) notes.push(`${w} ${t} is outside ${id}'s play window ${from}–${to} (source seconds): it is drawn at the window's edge`); + }; + claims.forEach((c, i) => { + if (c.kind === "count") inside(c.at, c.t, `${where}[${i}].t`); + else { + c.steps.forEach((st, k) => inside(st.at, st.t, `${where}[${i}].steps[${k}].t`)); + const order = c.steps.map((st) => timeline.findIndex((e) => e?.id === st.at)); + if (order.some((o, k) => k > 0 && o >= 0 && order[k - 1] >= 0 && o < order[k - 1])) { + notes.push(`${where}[${i}].steps are not in the cut's order: the brackets move in the order the cut plays them`); + } + } + }); + return notes; +} + +/** + * What the record says to each count claim's `claim`, as notes: a NOTE, not + * an error, when the record does NOT contradict his words -- the operator + * decides -- and one when stamps of the claim's verdict have no date (no + * `eventDate` and no clip date), so the window cannot count them. From a + * schedule (`deckClaims`), which knows the clips' dates. + * + * @returns {string[]} + */ +export function claimRecordNotes(schedule) { + const notes = []; + for (const it of schedule?.deckClaims?.items ?? []) { + if (it.kind !== "count") continue; + const w = `render.chrome.deck.claims[${it.n}] (${it.said})`; + if (it.claim && it.holds) { + notes.push( + it.per + ? `${w}: the record has no span of ${it.per} with ${it.claim.value} or more ${it.noun} -- it does not contradict him` + : `${w}: the record's ${it.total} ${it.noun} in ${it.window.from}–${it.window.to} is ${it.claim.op} ${it.claim.value} -- it does not contradict him`, + ); + } + if (it.undated) notes.push(`${w}: ${it.undated} of the ${it.noun} stamps have no date (set the mark's eventDate): the window does not count them`); + } + return notes; +} + /** `validateChrome`, thrown. The build calls this before it spends a single fetch. */ export function assertChrome(chrome, render = {}) { const errors = validateChrome(chrome, render); @@ -534,7 +656,10 @@ export function deckLayout(render, { tally = null, schedule = null } = {}) { const marked = Array.isArray(d.markers) && d.markers.length > 0; const rows = marked && schedule ? markerRowsOf(schedule, render) : 1; const markerBand = marked ? MARKER_BAND + (rows > 1 ? MARKER_ROW : 0) : 0; - const trackY = 16 + markerBand; + // A goalpost's words (`deck.claims`, claims.mjs) stand in a row of their + // own above the markers'; only with one, likewise. + const claimRow = hasGoalpost(d) ? CLAIM_ROW : 0; + const trackY = 16 + claimRow + 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. @@ -542,9 +667,10 @@ export function deckLayout(render, { tally = null, schedule = null } = {}) { const bodyH = rect.height - bodyTop - 8; // Under a marker band the code keeps clear of the active pip's halo and // inside the deck: it shrinks to the room left under the track if it must. - const qrSize = markerBand ? Math.min(d.qr.size, rect.height - (trackY + 12) - 2) : d.qr.size; + const banded = markerBand + claimRow; + const qrSize = banded ? Math.min(d.qr.size, rect.height - (trackY + 12) - 2) : d.qr.size; let qrY = Math.round(bodyTop + (bodyH - qrSize) / 2); - if (markerBand) qrY = Math.min(rect.height - qrSize - 2, Math.max(qrY, trackY + 12)); + if (banded) qrY = Math.min(rect.height - qrSize - 2, Math.max(qrY, trackY + 12)); const qr = d.qr.show ? { x: W - padX - qrSize, y: qrY, size: qrSize } : null; let textX = padX; let textRight = qr ? qr.x - 48 : W - padX; @@ -595,10 +721,18 @@ export function deckLayout(render, { tally = null, schedule = null } = {}) { // 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, ...(rows > 1 ? { rows } : {}) } } : {}), + ...(markerBand ? { markerBand: { y: 3 + claimRow, height: markerBand + 6, ...(rows > 1 ? { rows } : {}) } } : {}), + // Only with a goalpost: where its words stand (claimsLayout). + ...(claimRow ? { claimBand: { y: 3, height: claimRow } } : {}), }; } +/** How far the track moves down for a goalpost's words (`deck.claims`). */ +export const CLAIM_ROW = 22; + +/** Does the deck carry a goalpost claim (claims.mjs)? Then its words take a row over the track. */ +const hasGoalpost = (d) => Array.isArray(d.claims) && d.claims.some((c) => isObj(c) && c.kind === "goalpost"); + /** How far the track moves down to make room for the markers' labels. */ export const MARKER_BAND = 22; @@ -1033,6 +1167,13 @@ export function deckSchedule({ hidden: (e) => hidesDeck(e, deck), }) : null; + // The claim checks (`deck.claims`): his words against the record, timed by + // the stamps' own mapping. None: the schedule is what it always was. + const deckClaims = claimsSchedule({ + entries, segments: segs, D, total, metas, render, stamps, + sourceFrom: (e) => clipClock?.get(e.id) ?? fxClock?.get(e.id) ?? playWindow(e, render).from, + }); + const claimClips = deckClaims ? deckClaimClips(render) : new Set(); return { version: 1, kind: "deck", @@ -1064,7 +1205,10 @@ export function deckSchedule({ ...(marksOf(e).length > 1 ? { claims: marksOf(e) } : {}), // And on one stamped at a source second, the second its segment starts // at -- what placed the stamp, kept for a preview to place it again. - ...(marksOf(e).some((c) => c.at !== undefined) ? { sourceFrom: round(clipClock?.get(e.id) ?? fxClock?.get(e.id) ?? playWindow(e, render).from) } : {}), + // So does a clip a deck claim check is said in (`deck.claims`). + ...(marksOf(e).some((c) => c.at !== undefined) || claimClips.has(e.id) + ? { sourceFrom: round(clipClock?.get(e.id) ?? fxClock?.get(e.id) ?? playWindow(e, render).from) } + : {}), // Only on a finale clip, likewise. ...(finIds.has(e.id) ? { finale: true } : {}), }; @@ -1085,7 +1229,238 @@ export function deckSchedule({ // the schedule it always did. ...(placed.length ? { posts: roundPosts(placed) } : {}), ...(allMoves.length ? { moves: allMoves.map((m) => ({ ...m, at: round(m.at), segmentAt: round(m.segmentAt) })) } : {}), + // The claim checks (`deck.claims`): present only when the deck carries one. + ...(deckClaims ? { deckClaims } : {}), + }; +} + +/** + * The deck's claim checks (`deck.claims`, claims.mjs) in the cut's clock: + * `{ dates, items }`, or null when the deck carries none (or none in this + * cut). THE arithmetic -- the build's schedule and umtool's preview both come + * here, so the render, the live preview and Play the cut agree. + * + * - `dates`: each clip's (and dated still's) day, YYYY-MM-DD -- the rail's + * date axis: pips are laid by order, and a date between two of them is + * placed between them (claimsLayout). + * - a COUNT item: `at`, the cut second he says it (his `t` through the + * source second the clip's segment starts at, `sourceFrom(entry)` -- the + * mapping the stamps use), kept inside the segment; `until`, the clip's end + * (the next segment's mid-dissolve); the verdict `tally` names and its label + * as a noun; the record: every stamp of that verdict dated inside the + * window (its `eventDate`, else its clip's day), in date order, and their + * `total`; with `per`, the `spans` that hold `claim.value` or more (2 + * without a `claim`); with a `claim`, whether the record `holds` it. + * - a GOALPOST item: its steps in this cut, each with `at`, the day it runs + * `from` (its own, else its clip's), the `due` window that implies and that + * window as the rail prints it (`dueText`). + * + * `n` is each item's index in `deck.claims`, for messages. + */ +export function claimsSchedule({ entries, segments, D, total, metas = [], render, stamps = [], sourceFrom }) { + const list = render?.chrome?.deck?.claims; + if (!Array.isArray(list) || !list.length || deckClaimShapeErrors(list).length) return null; + const verdicts = resolveFactcheck(render).verdicts; + const idx = new Map(segments.map((s, i) => [s.id, i])); + const round = (v) => Math.round(v * 1000) / 1000; + const dates = {}; + entries.forEach((e, i) => { + const d = e.type === "clip" ? clipDay(e, metas[i] ?? null) : e.type === "image" ? String(e.date ?? "").slice(0, 10) : null; + if (isIsoDate(d)) dates[e.id] = d; + }); + const cutAt = (id, t) => { + const i = idx.get(id); + const s = segments[i]; + return round(Math.min(s.start + s.duration, Math.max(s.start, s.start + (t - sourceFrom(entries[i]))))); + }; + const untilOf = (id) => { + const i = idx.get(id); + return round(segments[i + 1] ? segments[i + 1].start + D / 2 : total); + }; + const items = []; + list.forEach((c, n) => { + if (c.kind === "count") { + const verdict = tallyVerdictOf(c.tally, verdicts); + if (!verdict || !idx.has(c.at) || entries[idx.get(c.at)].type !== "clip") return; + const record = stamps.filter((s) => s.verdict === verdict) + .map((s) => ({ segment: s.segment, count: s.count ?? 1, date: s.eventDate ?? dates[s.segment] ?? null, landed: s.landed })); + const A = dayOf(c.window.from), B = dayOf(c.window.to); + const inWindow = record + .filter((s) => s.date && dayOf(s.date) >= A && dayOf(s.date) <= B) + .sort((a, b) => dayOf(a.date) - dayOf(b.date) || a.landed - b.landed); + const undated = record.filter((s) => !s.date).length; + const sum = inWindow.reduce((a, s) => a + s.count, 0); + const spans = c.per + ? findSpans(inWindow, c.per, c.claim?.value ?? 2).map((sp) => ({ + from: sp.from, to: sp.to, count: sp.count, label: sp.label, segments: [...new Set(sp.stamps.map((s) => s.segment))], + })) + : null; + items.push({ + kind: "count", n, segment: c.at, at: cutAt(c.at, c.t), until: untilOf(c.at), said: c.said.trim(), + window: { from: c.window.from, to: c.window.to }, verdict, + noun: String(verdicts[verdict].label ?? verdict).trim().toLowerCase(), + total: sum, + stamps: inWindow.map(({ landed: _l, ...s }) => s), + ...(c.per ? { per: c.per, spans } : {}), + ...(c.claim ? { claim: { op: c.claim.op, value: c.claim.value }, holds: c.per ? spans.length === 0 : compares(sum, c.claim.op, c.claim.value) } : {}), + ...(undated ? { undated } : {}), + }); + return; + } + const steps = c.steps + .filter((st) => idx.has(st.at) && entries[idx.get(st.at)].type === "clip" && (st.from ?? dates[st.at])) + .map((st) => { + const from = st.from ?? dates[st.at]; + const due = dueWindow(from, st.due); + return { segment: st.at, at: cutAt(st.at, st.t), said: st.said.trim(), from, due, dueText: dayRange(due[0], due[1]) }; + }) + .sort((a, b) => a.at - b.at); + if (steps.length) items.push({ kind: "goalpost", n, ...(c.label ? { label: c.label.trim() } : {}), steps }); + }); + return items.length ? { dates, items } : null; +} + +/** + * Where the deck's claim checks stand on the footer, region-local px, from + * the schedule's `deckClaims` and the pips (`xs`, pipXs; `pipped`, + * pipSegments) -- what chrome-deck.mjs draws and chrome-finale.mjs maps onto + * its large rail. Null without claims. + * + * The rail is laid by ORDER, not by date, so a date is placed by the pips + * around it: a range of dates covers the longest run of consecutive pips + * dated inside it, its edges at the date between that run and the pip either + * side when that pip's date lies beyond the range (interpolated), else a + * little past the run's end pips. A range that runs past the rail's last + * date ends just after that date's pip, open, its arrow pointing on; one + * wholly past it is `off` the rail, a stub at the rail's right end. + * + * - a count item: its `band` ({ a, b } -- without `per`) and the `veils` that + * dim the rail outside it (and each pip inside it dated outside the + * window); a `tag` per pip that carries in-window stamps (`x`, `count`, + * `order` by date) -- none for a pip a `per` claim already lit on the same + * clip, whose span says it; with `per`, its `spans` ({ a, b, cx, label }). + * - a goalpost item: each step's bracket ({ a, b, open, off }) and its words + * (`label`, `align`: left at the bracket, or right at its end when off the rail). + */ +export function claimsLayout(schedule, render, xs, pipped, lay = deckLayout(render, { schedule })) { + const C = schedule?.deckClaims; + if (!C?.items?.length) return null; + const { x0, x1 } = lay.pipTrack; + const end = Math.min(lay.width - 14, x1 + 30); + const P = pipped.map((s, k) => ({ k, id: s.id, x: xs[k], day: C.dates?.[s.id] ? dayOf(C.dates[s.id]) : null })); + const days = P.filter((p) => p.day !== null).map((p) => p.day); + const maxDay = days.length ? Math.max(...days) : -Infinity; + const minDay = days.length ? Math.min(...days) : Infinity; + // Where the rail's last date stands: a range that runs past it ends just after, its arrow on. + const lastX = Math.max(-Infinity, ...P.filter((p) => p.day === maxDay).map((p) => p.x)); + const gap = xs.length > 1 ? (xs[xs.length - 1] - xs[0]) / (xs.length - 1) : 40; + const pad = Math.max(6, Math.min(12, gap / 2)); + const r2 = (v) => Math.round(v * 100) / 100; + const lerp = (p, q, d) => p.x + ((q.x - p.x) * (d - p.day)) / (q.day - p.day); + const rangeX = (from, to) => { + const A = dayOf(from), B = dayOf(to); + const inR = (p) => p.day !== null && p.day >= A && p.day <= B; + let best = null, cur = null; + for (const p of P) { + if (inR(p)) { + cur = cur ? { first: cur.first, last: p, n: cur.n + 1 } : { first: p, last: p, n: 1 }; + if (!best || cur.n >= best.n) best = cur; + } else cur = null; + } + if (!best) { + if (A > maxDay) return { off: "right" }; + if (B < minDay) return { off: "left" }; + for (let k = 0; k + 1 < P.length; k += 1) { + const p = P[k], q = P[k + 1]; + if (p.day !== null && q.day !== null && p.day < A && q.day > B) return { a: r2(lerp(p, q, A) - pad / 2), b: r2(lerp(p, q, B) + pad / 2), open: false }; + } + return null; + } + const prev = P[best.first.k - 1], next = P[best.last.k + 1]; + const a = prev && prev.day !== null && prev.day < A ? Math.min(lerp(prev, best.first, A), best.first.x - pad) : best.first.x - pad; + if (next && next.day !== null && next.day > B) return { a: r2(a), b: r2(Math.max(lerp(best.last, next, B), best.last.x + pad)), open: false }; + if (B > maxDay) return { a: r2(a), b: r2(Math.min(end - 70, Math.max(best.last.x, lastX) + pad + 6)), open: true }; + return { a: r2(a), b: r2(best.last.x + pad), open: false }; }; + const pipOf = new Map(P.map((p) => [p.id, p])); + // The spans a `per` claim lit, by clip: a later claim on that clip leaves their pips untagged. + const lit = new Map(); + const items = C.items.map((it) => { + if (it.kind === "count") { + const A = dayOf(it.window.from), B = dayOf(it.window.to); + const covered = new Set(); + for (const l of lit.get(it.segment) ?? []) if (l.at < it.at) for (const id of l.segments) covered.add(id); + let band = null; + let veils = []; + if (!it.per) { + // By MEMBERSHIP, not position: the rail's dates are not monotonic (a + // flash-forward among older clips, an outro of old clips at the end). + // A pip is in his window when its clip's day is, or when it carries a + // stamp dated inside it; the band runs from the first such pip to the + // last, its edges eased to the date between it and its neighbour + // where the dates run forward there, and every pip outside the + // window -- inside the band too -- is dimmed. + const stamped = new Set(it.stamps.map((st) => st.segment)); + const inWin = (p) => (p.day !== null && p.day >= A && p.day <= B) || stamped.has(p.id); + const members = P.filter(inWin); + if (members.length) { + const first = members[0], last = members[members.length - 1]; + const prev = P[first.k - 1], next = P[last.k + 1]; + const a = prev && prev.day !== null && first.day !== null && prev.day < A && first.day >= A + ? Math.min(lerp(prev, first, A), first.x - pad) : first.x - pad; + const b = next && next.day !== null && last.day !== null && next.day > B && last.day <= B + ? Math.max(lerp(last, next, B), last.x + pad) : last.x + pad; + band = { a: r2(a), b: r2(b) }; + if (a > x0 - 10) veils.push([x0 - 10, a]); + if (b < end) veils.push([b, end + 4]); + for (const p of P) if (p.x > a && p.x < b && p.day !== null && !inWin(p)) veils.push([p.x - pad, p.x + pad]); + veils = veils.map(([va, vb]) => [r2(va), r2(vb)]).filter(([va, vb]) => vb - va > 1); + } + } + const byPip = new Map(); + it.stamps.forEach((st, order) => { + const p = pipOf.get(st.segment); + if (!p) return; + const t = byPip.get(p.k) ?? { k: p.k, x: r2(p.x), count: 0, order }; + t.count += st.count; + byPip.set(p.k, t); + }); + const tags = [...byPip.values()].sort((a, b) => a.order - b.order).map((t) => ({ ...t, covered: covered.has(P[t.k].id) })); + // A span is its stamps' own pips (by membership): a bar over each run + // of them that stand side by side, its count over them all. + const spans = (it.spans ?? []).map((sp) => { + const ks = sp.segments.map((id) => pipOf.get(id)).filter(Boolean).sort((p, q) => p.k - q.k); + if (!ks.length) return null; + const bars = []; + for (const p of ks) { + const lastBar = bars[bars.length - 1]; + if (lastBar && lastBar.k === p.k - 1) { lastBar.b = p.x + 7; lastBar.k = p.k; } else bars.push({ a: p.x - 7, b: p.x + 7, k: p.k }); + } + const a = bars[0].a, b = bars[bars.length - 1].b; + return { + a: r2(a), b: r2(b), cx: r2((a + b) / 2), label: sp.label, count: sp.count, + bars: bars.map((bar) => ({ a: r2(bar.a), b: r2(bar.b) })), + }; + }).filter(Boolean); + if (it.per) lit.set(it.segment, [...(lit.get(it.segment) ?? []), { at: it.at, segments: it.spans.flatMap((sp) => sp.segments) }]); + return { ...it, band, veils, tags, spans: it.per ? spans : undefined }; + } + const steps = it.steps.map((st) => { + const r = rangeX(st.due[0], st.due[1]); + let geo; + if (!r || r.off === "right") geo = { a: r2(end - 56), b: r2(end), open: true, off: true }; + else if (r.off === "left") geo = { a: r2(x0 - 6), b: r2(x0 + 50), open: false, off: true }; + else geo = { a: r.a, b: r.b, open: r.open, off: false }; + const words = geo.open ? `${st.said} → ${st.dueText}` : `${st.said} · ${st.dueText}`; + const need = markerLabelWidth(words); + // Off the rail its words end where it does; on it they start at its left edge, + // or end at the deck's edge when they would run past it. + const align = geo.off || geo.a + need > lay.width - 16 ? "right" : "left"; + return { ...st, ...geo, label: words, align, need }; + }); + return { ...it, steps }; + }); + return { end: r2(end), pad: r2(pad), items }; } /** diff --git a/umtool/report-to-video/factcheck.mjs b/umtool/report-to-video/factcheck.mjs @@ -7,7 +7,10 @@ // LAST carrying the id): "at" (source seconds the stamp // lands and the count steps), "hold" (seconds on screen), // "stamp": false (counts, draws nothing), "count" (steps -// the tally by n), "label" (the stamp's words) +// the tally by n), "label" (the stamp's words), +// "eventDate" (YYYY-MM-DD: the day the event it counts +// happened, when that is not its clip's -- what a deck +// claim's window reads, claims.mjs) // -- or MARKS: "claims": [ { "id": "k3", "verdict": … }, … ] // (2–8; each its own stamp and tally step at its own // `at`, with its own knobs). A lone `claim` is a list of @@ -31,6 +34,7 @@ // verdicts, their default labels and colours and the override rules are one // copy shared with report.json and the export site's report pages. This file // re-exports the list and lays the stamp and tally settings beside the labels. +import { isIsoDate } from "./claims.mjs"; import { VERDICT_DEFAULTS, VERDICT_LABEL_MAX, @@ -82,7 +86,7 @@ export const FACTCHECK_LIMITS = Object.freeze({ export const CLAIM_LIMITS = Object.freeze({ hold: Object.freeze([0.5, 10]), count: Object.freeze([1, 99]), label: 20 }); /** The keys a `claim` may carry. */ -export const CLAIM_KEYS = Object.freeze(["id", "verdict", "at", "hold", "stamp", "count", "label"]); +export const CLAIM_KEYS = Object.freeze(["id", "verdict", "at", "hold", "stamp", "count", "label", "eventDate"]); /** The most marks (`claims`) one entry may carry. */ export const CLAIM_MARKS_MAX = 8; @@ -195,7 +199,7 @@ export function validateFactcheck(f, where = "render.chrome.factcheck") { * `at` lies in its entry's window is validateClaims', which has the entry.) * * @returns {{ id: string, verdict: string, at?: number, hold?: number, - * stamp?: false, count?: number, label?: string } | null} + * stamp?: false, count?: number, label?: string, eventDate?: string } | null} */ export function normalizeClaim(v) { if (v === undefined || v === null) return null; @@ -232,6 +236,12 @@ export function normalizeClaim(v) { if (label.length > CLAIM_LIMITS.label) throw new Error(`claim.label is ${label.length} characters (at most ${CLAIM_LIMITS.label})`); out.label = label; } + // The day the counted event happened, when it is not the clip's: a deck + // claim's window (claims.mjs) reads it. The stamp lands where it always did. + if (v.eventDate !== undefined) { + if (!isIsoDate(v.eventDate)) throw new Error("claim.eventDate must be a date (YYYY-MM-DD)"); + out.eventDate = v.eventDate; + } return out; } @@ -399,7 +409,8 @@ export function validateClaims(manifest) { * * The claim's other knobs ride on its stamp only when set: `count` (the * tally's step), `stamp: false` (counted, not drawn), `label` (the stamp's - * words). A claim without knobs stamps exactly as it always did. + * words), `eventDate` (the day a deck claim's window dates it by). A claim + * without knobs stamps exactly as it always did. * * MARKS (a segment's `claims`, two or more): each mark is its own stamp and * tally step, stamped on the last segment carrying its id. On a segment that @@ -431,6 +442,8 @@ export function stampSchedule({ segments, D, total, render }) { ...(c.count !== undefined && c.count !== 1 ? { count: c.count } : {}), ...(c.stamp === false ? { stamp: false } : {}), ...(c.label !== undefined ? { label: c.label } : {}), + // Only when set, so a stamp without one is the stamp it always was. + ...(c.eventDate !== undefined ? { eventDate: c.eventDate } : {}), }); return [...bySegment.entries()] .sort((a, b) => a[0] - b[0]) diff --git a/umtool/report-to-video/finale.mjs b/umtool/report-to-video/finale.mjs @@ -426,36 +426,60 @@ export function railLabelLayout(pips, geo, { dates = true } = {}) { /** * The large rail's markers: each flag's x (mapped from its x on the footer's - * track), its label's row (0 just over the track's band, 1 above it) and - * side -- reading right from the flag, or left when it would run off the - * frame. A label that clears neither row is cut to the room it has. + * track), its label's row (0 just over the track's band, 1 above it, 2 above + * that) and side -- reading right from the flag, or left when it would run + * off the frame. A label takes the first row where it clears every label + * already laid there, on its side or, failing that, the other; one that + * clears no row is laid in the row that leaves it the most room and cut to + * that room. `layout` is the deck's `markerLayout`: "stagger" (the default) + * lays them in up to three rows, "truncate" keeps one row and cuts them, as + * the footer does. * * `marks` are `{ x, label, color }` (frame px on the large track). * * @returns {Array<{ x: number, label: string, color: string, row: number, side: "right" | "left", max: number }>} */ -export function railMarkerLayout(marks, geo) { +export function railMarkerLayout(marks, geo, { layout = "stagger" } = {}) { const size = geo.rail.markerSize; const W = geo.W, m = geo.margin; - const rows = [[], []]; + const rows = Array.from({ length: layout === "truncate" ? 1 : RAIL_MARKER_ROWS }, () => []); + const GAP = 12; + const spanOf = (x, side, w) => (side === "right" ? [x, x + 18 + w] : [x - 18 - w, x]); + const clears = (r, [a, b]) => r.every(([c, d]) => a > d + GAP || b < c - GAP); return [...marks] .map((mk, j) => ({ mk, j })) .sort((a, b) => a.mk.x - b.mk.x) .map(({ mk, j }) => { const w = textWidth(String(mk.label).toUpperCase(), size) + Math.round(size * 0.04 * String(mk.label).length); - const side = mk.x + 18 + w > W - m ? "left" : "right"; - const span = side === "right" ? [mk.x, mk.x + 18 + w] : [mk.x - 18 - w, mk.x]; - let row = rows.findIndex((r) => r.every(([a, b]) => span[0] > b + 12 || span[1] < a - 12)); - let max = w; - if (row < 0) { - // Neither row clears it: the row with the most room, the label cut to it. - row = 1; - const blockers = rows[1].map(([a, b]) => (side === "right" ? a - mk.x - 30 : mk.x - b - 30)).filter((v) => v > 0); - max = Math.max(60, Math.min(w, ...blockers)); + const fitsRight = mk.x + 18 + w <= W - m; + const fitsLeft = mk.x - 18 - w >= m / 2; + const sides = fitsRight ? ["right", ...(fitsLeft ? ["left"] : [])] : ["left"]; + for (let row = 0; row < rows.length; row += 1) { + for (const side of sides) { + const span = spanOf(mk.x, side, w); + if (clears(rows[row], span)) { + rows[row].push(span); + return { j, x: mk.x, label: mk.label, color: mk.color, row, side, max: w }; + } + } } - rows[row].push(side === "right" ? [mk.x, mk.x + 18 + max] : [mk.x - 18 - max, mk.x]); - return { j, x: mk.x, label: mk.label, color: mk.color, row, side, max }; + // No row clears it: the row (and side) that leaves it the most room, the label cut to it. + let best = { row: rows.length - 1, side: sides[0], room: -Infinity }; + rows.forEach((r, row) => { + for (const side of sides) { + const room = side === "right" + ? Math.min(W - m - mk.x - 18, ...r.filter(([a, b]) => b > mk.x - GAP).map(([a]) => a - mk.x - 18 - GAP)) + : Math.min(mk.x - 18 - m / 2, ...r.filter(([a, b]) => a < mk.x + GAP).map(([, b]) => mk.x - 18 - b - GAP)); + if (room > best.room) best = { row, side, room }; + } + }); + const max = Math.max(60, Math.min(w, Math.floor(best.room))); + rows[best.row].push(spanOf(mk.x, best.side, max)); + return { j, x: mk.x, label: mk.label, color: mk.color, row: best.row, side: best.side, max }; }) .sort((a, b) => a.j - b.j) .map(({ j: _j, ...rest }) => rest); } + +/** How many rows the large rail's marker labels may take when they stagger. */ +export const RAIL_MARKER_ROWS = 3; 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, - validateChrome, validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, + validateChrome, validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, deckClaimNotes, validateDeckClaims, } from "./deck.mjs"; import { validateClaims } from "./factcheck.mjs"; import { validateClipAudioEntries } from "./clip-audio.mjs"; @@ -299,6 +299,8 @@ export function validatorErrors(whole) { errors.push(...validateChrome(chrome, rest)); // The deck's markers against the whole timeline, as the build refuses them. errors.push(...validateDeckMarkers(whole)); + // And its claim checks (claims.mjs): each names a clip in it, and a verdict. + errors.push(...validateDeckClaims(whole)); } return errors; } @@ -358,6 +360,8 @@ export function lintManifest(manifest, { // The social posts and the video's URL are not the video's: a problem there // is said, never a refusal (release 29 G2's review). warnings.push(...publishWarnings(whole)); + // The deck's claim checks said at a second their clip does not play (claims.mjs). + if (!only) warnings.push(...deckClaimNotes(whole)); // Room at the clips' edges (render.room): a fetched window it can reach past. warnings.push(...roomWindowWarnings(only ? { ...manifest, timeline: (manifest.timeline ?? []).filter((e) => e?.id === only) } : manifest)); diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json @@ -22,6 +22,7 @@ "./brand-ids": "./brand-ids.mjs", "./build-video": "./build-video.mjs", "./check-availability": "./check-availability.mjs", + "./claims": "./claims.mjs", "./clip-audio": "./clip-audio.mjs", "./clip-blur": "./clip-blur.mjs", "./compose-chrome": "./compose-chrome.mjs",