// 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": "", "t": , // "said": "“less than ten” in a year", // "window": { "from": "2025-10-22", "to": "2026-10-22" }, // "tally": "", // "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: `PD`, `PW` or `PM`, 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"]: PD, PW or PM)`); } 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; }