// THE MODULES' SETTINGS (release 39): every chrome module's home in the // manifest, its defaults and its validator -- the one copy. The registry // (modules/index.mjs) hands each module its entry, and deck.mjs's // validateChrome runs them all in SETTINGS order, so umtool's writers and // the build refuse the same things. // // A LEAF: it imports only files that do not import deck.mjs, because deck.mjs // imports it (a cycle through the module files would read a binding before it // is set). The deck's own constants live here for that reason, and deck.mjs // re-exports them under the names they always had. import { deckClaimShapeErrors } from "../claims.mjs"; import { validateFinaleSettings } from "../finale.mjs"; import { counterLabelProblem, validateFactcheck } from "../factcheck.mjs"; import { validateCounter } from "../counter.mjs"; import { validateThreads } from "../threads.mjs"; import { validateFlips } from "../flips.mjs"; import { validateStats } from "../stats.mjs"; import { validateFx } from "../fx.mjs"; import { validateChat } from "../chat.mjs"; import { validateChapter, validatePair, validateStatus } from "./story-settings.mjs"; import { MARKER_LEVELS, MARKER_LIMITS } from "../marker-limits.mjs"; import { validateDial, validateOdometer, validateTrail } from "../instruments.mjs"; import { MEASURE_EXTRAS, validateMeasureExtra } from "./measure-extras-settings.mjs"; import { validateMeasureSettings } from "../measure-slice.mjs"; import { validateShelf } from "./shelf-settings.mjs"; /** * Every deck setting and its default. A manifest names only what it changes; * `resolveDeck` fills the rest. Each default is a setting, not a constant -- * the alternative in each comment is a supported value. */ export const DECK_DEFAULTS = Object.freeze({ height: 190, footageScale: 0.82, background: "panel", // | "flush" // spacing | "time" | "pitch". `color` "verdict": a claimed clip's pip, once // lit, takes its claim's verdict colour and shape (counter.mjs). With // "pitch", `pip.pitch` is the px between two pips (PIP_PITCH_DEFAULT when // unset; rail.mjs) -- not a default here, so a deck without it resolves as // it always did. pip: Object.freeze({ spacing: "even", size: 6, activeSize: 12, color: "accent" }), title: Object.freeze({ size: 54, maxChars: 48 }), // dateFormat | "iso". `lines` 2 draws the source line in two: `head` (the // parts on line 1, "auto" = the source's title) a size up and brighter, the // rest of `parts` under it; the band grows by the head line (deck.mjs // subtitleBoxes). 1 is the one line it always was. subtitle: Object.freeze({ parts: "auto", dateFormat: "long", lines: 1, head: "auto" }), // `links` is where a clip's QR goes: "site" (the archive's page at the // clip's start) or "original" (the record's own page -- YouTube at the // second, a Rumble page, an X post). An entry's `citeUrl` wins either way. qr: Object.freeze({ show: true, size: 150, links: "site" }), overCards: "hide", // | "show" motion: Object.freeze({ out: 0.3, in: 0.45, pip: 0.7 }), // The manifest's `posts`, drawn as cards over the footage at the end of the // clip each one is attached to. position | "top-left". // `hold` freezes the last frame of a clip that carries posts for that long, // so the last of them can be read before the next clip; `shift` moves the // footage away from the posts column (scaled to `scale`, over `seconds`) // while they are up, or is `false`. // `layout` "popup" draws them as above; "feed" keeps them in a column of // their own beside the footage for the whole cut (feedGeometry), each one // ticking in as its clip starts -- no hold, no move. // `links` is where a post's QR goes: "archive" (the post's page on the // archive the manifest names, `provenance.siteOrigin`, which survives the // post or the platform going away, and links on to the original) or // "original" (the bsky.app / x.com link itself). // `at` is when a popup's posts come up: "end" (the last `seconds` of the // clip, as above) or "start" (from the clip's start, sharing the whole clip // in the order the manifest lists them -- the post beside the words it goes // with, so no hold is needed). `shotMaxHeight` caps a post's screenshot in // px; null keeps it to the height of a full card of words (`maxLines`). posts: Object.freeze({ show: true, layout: "popup", seconds: 4, hold: 2.5, position: "top-right", width: 600, qrSize: 120, maxLines: 7, inset: 24, shift: Object.freeze({ scale: 0.86, seconds: 0.6 }), links: "archive", at: "end", shotMaxHeight: null, // `qr: false` draws no QR on any post card (popup or feed); the words // take the code's width. The clip's own deck QR (`qr`) is untouched. qr: true, }), // Flags on the pip track: `[{ after, label?, color?, align? }]`, each between // the pip of the clip `after` names and the next, hidden until the fuse // reaches it (deckMarkers). An empty list is no flags, and the deck lays out // as it always did. markers: Object.freeze([]), // Crowded labels: "stagger" lays them in two rows when one would not fit in // a single row (the band grows by MARKER_ROW, the track moves down by it); // "truncate" keeps one row and ellipsizes. A single row that fits is laid // the same either way. markerLayout: "stagger", }); /** * The pip's colour when lit (`pip.color`): the deck's accent, a claimed clip's * verdict, or its SECTION's -- the stretch of the rail from one marker to the * next, in that marker's colour (before the first, `pip.sectionColor0`, else * the accent); the fuse and the marker's ring take it too (deck.mjs railSections). */ export const PIP_COLORS = Object.freeze(["accent", "verdict", "section"]); // A marker's limits (how many, a label's characters) and levels: the one // copy is marker-limits.mjs, a leaf the browser imports too. export { MARKER_LEVELS, MARKER_LIMITS }; /** * Where a marker's label sits against its flag: "auto" (centred when it has * the room, else the stretch it may take -- as it always was), "left" (it * starts at the flag and reads on to the right), "right" (it ends at the * flag), "center" (centred on it, always). */ export const MARKER_ALIGNS = Object.freeze(["auto", "left", "right", "center"]); /** `deck.markerLayout`: crowded labels in two rows, or one row ellipsized. */ export const MARKER_LAYOUTS = Object.freeze(["stagger", "truncate"]); /** The palette keys a marker's `color` may name (else a `#rgb` / `#rrggbb`). */ export const MARKER_PALETTE_KEYS = Object.freeze(["fg", "muted", "accent", "amber", "dim"]); /** A marker with no `color` is drawn in this palette key. */ export const MARKER_DEFAULT_COLOR = "amber"; /** Where a clip's deck QR links (`qr.links`): the archive at the clip, or the original. */ export const QR_LINKS = Object.freeze(["site", "original"]); /** Subtitle tokens a `subtitle.parts` array may name. "auto" picks from these. */ export const SUBTITLE_TOKENS = Object.freeze(["channel", "title", "date", "clock", "status"]); /** `subtitle.status`: "off" (default) or "end" -- the source status after the last part (source-status.mjs). */ export { SUBTITLE_STATUS_MODES } from "../source-status.mjs"; /** How many lines the subtitle takes (`subtitle.lines`). */ export const SUBTITLE_LINES = Object.freeze([1, 2]); /** The parts on a two-line subtitle's first line when `subtitle.head` is "auto". */ export const SUBTITLE_HEAD_AUTO = Object.freeze(["title"]); /** How the rail lays its pips (`pip.spacing`): evenly, by time, or at a fixed pitch (rail.mjs). */ export const PIP_SPACINGS = Object.freeze(["even", "time", "pitch"]); /** The rail's pitch (`pip.pitch`, px between two pips when `spacing` is "pitch"): its bounds. */ export const PIP_PITCH = Object.freeze([8, 200]); /** The pitch when `spacing` is "pitch" and `pip.pitch` is unset. */ export const PIP_PITCH_DEFAULT = 28; /** * THE SECTION TITLE (module `section-title`, `deck.sectionTitle`): the * current section's name -- the label of the marker that opened it, `first` * before any -- on one quiet line centred under the rail. Off unless set * (`true`, or an object); `false` is off. `color` "auto" is the subtitle's * muted grey, lifted toward the deck's fg only as far as it needs to read * (4.5:1 at the line's opacity; chrome-deck.mjs sectionTitleColor). */ export const SECTION_TITLE_DEFAULTS = Object.freeze({ first: "", size: 18, opacity: 0.85, fade: 0.4, color: "auto" }); /** The section title's limits: `first`'s characters (a marker label's), size px, opacity, fade s. */ export const SECTION_TITLE_LIMITS = Object.freeze({ first: 24, size: Object.freeze([12, 32]), opacity: Object.freeze([0.2, 1]), fade: Object.freeze([0, 2]) }); /** The section title's colour words beside a #hex and a palette key: "auto" (the neutral text), "section" (its section's). */ export const SECTION_TITLE_COLORS = Object.freeze(["auto", "section"]); /** When a popup's posts come up (`posts.at`): the end of their clip, or its start. */ export const POST_AT = Object.freeze(["end", "start"]); /** How posts are drawn (`posts.layout`): cards at the end of a clip, or a column for the whole cut. */ export const POST_LAYOUTS = Object.freeze(["popup", "feed"]); /** Where a post's QR links (`posts.links`): its page on the archive, or the platform's own link. */ export const POST_LINKS = Object.freeze(["archive", "original"]); /** * Popup posts that PERSIST (`posts.persist`, opt-in): a card stays up on its * own clock for `seconds` after it comes up, across clip joins, while the * footage plays on (no hold); a post coming up within that, or within `gap` * after it, keeps the bar up. Each with its bounds and default. */ export const POST_PERSIST = Object.freeze({ seconds: Object.freeze({ min: 8, max: 60, default: 12 }), gap: Object.freeze({ min: 0, max: 30, default: 6 }), }); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; function unknownKeys(obj, allowed, where, errors) { for (const k of Object.keys(obj)) { if (!allowed.includes(k)) errors.push(`${where}.${k} is not a deck setting`); } } /** * A deck sub-object's check: absent passes, not an object is refused, unknown * keys are refused, then `check` reads it. */ function sub(d, key, allowed, w, errors, check) { if (d[key] === undefined) return; if (!isObj(d[key])) { errors.push(`${w}.${key} must be an object`); return; } unknownKeys(d[key], allowed, `${w}.${key}`, errors); check(d[key]); } const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; /** A marker's (or a section's) `color`: a #hex, or a palette key. */ const isMarkerColor = (c) => typeof c === "string" && (HEX_RE.test(c) || MARKER_PALETTE_KEYS.includes(c)); /** * Every reason a `deck.markers` list cannot be drawn, its shape alone (the * timeline is not in `render.chrome`: `validateDeckMarkers` checks `after` * against it). validateChrome calls this. * * @returns {string[]} */ export function markerShapeErrors(markers, where) { if (markers === undefined) return []; if (!Array.isArray(markers)) return [`${where} must be a list of { after, label?, color? }`]; const errors = []; if (markers.length > MARKER_LIMITS.count) errors.push(`${where} has ${markers.length} markers (at most ${MARKER_LIMITS.count})`); markers.forEach((m, i) => { const at = `${where}[${i}]`; if (!isObj(m)) { errors.push(`${at} must be { after, label?, color? }`); return; } for (const k of Object.keys(m)) { if (!["after", "label", "color", "align", "level"].includes(k)) errors.push(`${at}.${k} is not a marker setting (after, label, color, align, level)`); } // `level`: 1 a section (absent is 1), 2 a subsection of the section // before it (validateDeckMarkers refuses one with no section before it). if (m.level !== undefined && !MARKER_LEVELS.includes(m.level)) errors.push(`${at}.level must be 1 (a section) or 2 (a subsection)`); if (m.align !== undefined && !MARKER_ALIGNS.includes(m.align)) { errors.push(`${at}.align must be ${MARKER_ALIGNS.map((a) => `"${a}"`).join(", ")}`); } if (typeof m.after !== "string" || !m.after.trim()) errors.push(`${at}.after must name a clip's id`); // No label (absent, or "") is a marker with no words: a tick at the // boundary, and with `pip.color: "section"` the colour that changes there. const label = typeof m.label === "string" ? m.label.trim() : ""; if (m.label !== undefined && typeof m.label !== "string") errors.push(`${at}.label must be a word or two (or "" for none)`); else if (!label) { /* unlabelled */ } else if (/[\r\n]/.test(label)) errors.push(`${at}.label must be one line`); else if ([...label].length > MARKER_LIMITS.label) { errors.push(`${at}.label is ${[...label].length} characters (at most ${MARKER_LIMITS.label})`); } if (m.color !== undefined && !isMarkerColor(m.color)) { errors.push(`${at}.color must be a #hex colour or one of ${MARKER_PALETTE_KEYS.join(", ")}`); } }); return errors; } // --------------------------------------------------------------------------- // Each module's validator: (its value, { render, chrome, deck, where }) => // sentences. `deck` is `render.chrome.deck` (an object by the time these // run), `where` the dotted path the messages name. // --------------------------------------------------------------------------- /** The shell: the deck's size, ground, the title and the motion. */ export function validateShellSettings(d, { where: w }) { const errors = []; 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`); } if (d.footageScale !== undefined && !numIn(d.footageScale, 0.5, 1)) { errors.push(`${w}.footageScale must be from 0.5 to 1`); } if (d.background !== undefined && !["panel", "flush"].includes(d.background)) { errors.push(`${w}.background must be "panel" or "flush"`); } if (d.overCards !== undefined && !["hide", "show"].includes(d.overCards)) { errors.push(`${w}.overCards must be "hide" or "show"`); } sub(d, "title", ["size", "maxChars"], w, errors, (t) => { if (t.size !== undefined && !numIn(t.size, 24, 96)) errors.push(`${w}.title.size must be from 24 to 96`); if (t.maxChars !== undefined && !(Number.isInteger(t.maxChars) && numIn(t.maxChars, 10, 120))) { errors.push(`${w}.title.maxChars must be a whole number from 10 to 120`); } }); sub(d, "motion", ["out", "in", "pip"], w, errors, (m) => { for (const k of ["out", "in"]) { if (m[k] !== undefined && !numIn(m[k], 0, 2)) errors.push(`${w}.motion.${k} must be from 0 to 2 seconds`); } if (m.pip !== undefined && !numIn(m.pip, 0, 3)) errors.push(`${w}.motion.pip must be from 0 to 3 seconds`); }); return errors; } /** The rail: the pips, the markers and how crowded labels lay. */ export function validateRailSettings(d, { where: w }) { const errors = []; sub(d, "pip", ["spacing", "size", "activeSize", "color", "pitch", "sectionColor0"], w, errors, (p) => { if (p.spacing !== undefined && !PIP_SPACINGS.includes(p.spacing)) { errors.push(`${w}.pip.spacing must be "even", "time" or "pitch"`); } if (p.color !== undefined && !PIP_COLORS.includes(p.color)) { errors.push(`${w}.pip.color must be ${PIP_COLORS.map((c) => `"${c}"`).join(" or ")}`); } if (p.size !== undefined && !numIn(p.size, 2, 24)) errors.push(`${w}.pip.size must be from 2 to 24`); if (p.activeSize !== undefined && !numIn(p.activeSize, 2, 40)) { errors.push(`${w}.pip.activeSize must be from 2 to 40`); } if (p.pitch !== undefined && !numIn(p.pitch, PIP_PITCH[0], PIP_PITCH[1])) { errors.push(`${w}.pip.pitch must be from ${PIP_PITCH[0]} to ${PIP_PITCH[1]} pixels`); } if (p.sectionColor0 !== undefined && !isMarkerColor(p.sectionColor0)) { errors.push(`${w}.pip.sectionColor0 must be a #hex colour or one of ${MARKER_PALETTE_KEYS.join(", ")}`); } const size = p.size ?? DECK_DEFAULTS.pip.size; const active = p.activeSize ?? DECK_DEFAULTS.pip.activeSize; if (numIn(size, 2, 24) && numIn(active, 2, 40) && active < size) { errors.push(`${w}.pip.activeSize must be at least pip.size`); } }); errors.push(...markerShapeErrors(d.markers, `${w}.markers`)); // `rail.labels: false` draws no marker's words: the flags (or ticks) alone. sub(d, "rail", ["labels"], w, errors, (r) => { if (r.labels !== undefined && typeof r.labels !== "boolean") errors.push(`${w}.rail.labels must be true or false`); }); if (d.markerLayout !== undefined && !MARKER_LAYOUTS.includes(d.markerLayout)) { errors.push(`${w}.markerLayout must be ${MARKER_LAYOUTS.map((l) => `"${l}"`).join(" or ")}`); } return errors; } /** * The section title (`deck.sectionTitle`): `true`/`false`, or `{ first?, size?, * opacity?, fade?, color? }`. Absent or false: off. */ export function validateSectionTitleSettings(v, { where: w }) { const at = `${w}.sectionTitle`; if (v === undefined || typeof v === "boolean") return []; if (!isObj(v)) return [`${at} must be true, false or { first, size, opacity, fade, color }`]; const errors = []; for (const k of Object.keys(v)) { if (!Object.hasOwn(SECTION_TITLE_DEFAULTS, k)) errors.push(`${at}.${k} is not a section title setting (${Object.keys(SECTION_TITLE_DEFAULTS).join(", ")})`); } const L = SECTION_TITLE_LIMITS; if (v.first !== undefined) { if (typeof v.first !== "string") errors.push(`${at}.first must be a word or two (or "" for none)`); else if (/[\r\n]/.test(v.first)) errors.push(`${at}.first must be one line`); else if ([...v.first.trim()].length > L.first) errors.push(`${at}.first is ${[...v.first.trim()].length} characters (at most ${L.first})`); } if (v.size !== undefined && !numIn(v.size, L.size[0], L.size[1])) errors.push(`${at}.size must be from ${L.size[0]} to ${L.size[1]} pixels`); if (v.opacity !== undefined && !numIn(v.opacity, L.opacity[0], L.opacity[1])) errors.push(`${at}.opacity must be from ${L.opacity[0]} to ${L.opacity[1]}`); if (v.fade !== undefined && !numIn(v.fade, L.fade[0], L.fade[1])) errors.push(`${at}.fade must be from ${L.fade[0]} to ${L.fade[1]} seconds`); if (v.color !== undefined && !(SECTION_TITLE_COLORS.includes(v.color) || isMarkerColor(v.color))) { errors.push(`${at}.color must be "auto", "section", a #hex colour or one of ${MARKER_PALETTE_KEYS.join(", ")}`); } return errors; } /** The subtitle: its parts, its date's format, its lines and what heads the second. */ export function validateSubtitleSettings(d, { where: w }) { const errors = []; const tokens = (v) => Array.isArray(v) && v.length > 0 && v.every((p) => SUBTITLE_TOKENS.includes(p)) && new Set(v).size === v.length; sub(d, "subtitle", ["parts", "dateFormat", "lines", "head", "status"], w, errors, (s) => { if (s.status !== undefined && !["off", "end"].includes(s.status)) { errors.push(`${w}.subtitle.status must be "off" or "end" (the source status after the last part)`); } if (s.parts !== undefined && s.parts !== "auto") { if (!tokens(s.parts)) { errors.push(`${w}.subtitle.parts must be "auto" or a list of distinct ${SUBTITLE_TOKENS.join("/")}`); } } if (s.dateFormat !== undefined && !["long", "iso"].includes(s.dateFormat)) { errors.push(`${w}.subtitle.dateFormat must be "long" or "iso"`); } if (s.lines !== undefined && !SUBTITLE_LINES.includes(s.lines)) { errors.push(`${w}.subtitle.lines must be 1 or 2`); } const headOk = s.head === undefined || s.head === "auto" || tokens(s.head); if (!headOk) { errors.push(`${w}.subtitle.head must be "auto" or a list of distinct ${SUBTITLE_TOKENS.join("/")} (the parts on the first of two lines)`); } // Two lines over an explicit parts list: each line has to show something. if (s.lines === 2 && headOk && tokens(s.parts)) { const head = s.head === undefined || s.head === "auto" ? SUBTITLE_HEAD_AUTO : s.head; const missing = head.filter((p) => !s.parts.includes(p)); if (missing.length) { errors.push(`${w}.subtitle.head${s.head === undefined || s.head === "auto" ? " (auto)" : ""} names ${missing.join(", ")}, which subtitle.parts leaves out`); } else if (s.parts.every((p) => head.includes(p))) { errors.push(`${w}.subtitle.head takes every part of subtitle.parts, leaving the second line empty`); } } }); return errors; } /** The QR: shown, its size (inside the deck), where it links. */ export function validateQrSettings(d, { where: w }) { const errors = []; sub(d, "qr", ["show", "size", "links"], w, errors, (q) => { if (q.show !== undefined && typeof q.show !== "boolean") errors.push(`${w}.qr.show must be true or false`); if (q.links !== undefined && !QR_LINKS.includes(q.links)) { errors.push(`${w}.qr.links must be ${QR_LINKS.map((l) => `"${l}"`).join(" or ")}`); } if (q.size !== undefined && !numIn(q.size, 80, 380)) errors.push(`${w}.qr.size must be from 80 to 380`); const h = d.height ?? DECK_DEFAULTS.height; const size = q.size ?? DECK_DEFAULTS.qr.size; if (numIn(size, 80, 380) && Number.isInteger(h) && size > h - 20) { errors.push(`${w}.qr.size ${size} does not fit a ${h}px deck (at most ${h - 20})`); } }); return errors; } /** The posts (the popup cards and the feed): every `deck.posts` setting. */ export function validatePostsSettings(d, { where: w }) { const errors = []; sub(d, "posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr", "persist"], w, errors, (p) => { if (p.qr !== undefined && typeof p.qr !== "boolean") errors.push(`${w}.posts.qr must be true or false`); // `persist`: true (the defaults), { seconds?, gap? }, or false/null (off). if (p.persist !== undefined && p.persist !== null && typeof p.persist !== "boolean") { if (!isObj(p.persist)) errors.push(`${w}.posts.persist must be true, false or { seconds, gap }`); else { unknownKeys(p.persist, ["seconds", "gap"], `${w}.posts.persist`, errors); for (const k of ["seconds", "gap"]) { const b = POST_PERSIST[k]; if (p.persist[k] !== undefined && !numIn(p.persist[k], b.min, b.max)) { errors.push(`${w}.posts.persist.${k} must be from ${b.min} to ${b.max} seconds`); } } } } if (p.at !== undefined && !POST_AT.includes(p.at)) { errors.push(`${w}.posts.at must be ${POST_AT.map((a) => `"${a}"`).join(" or ")}`); } if (p.shotMaxHeight !== undefined && p.shotMaxHeight !== null && !(Number.isInteger(p.shotMaxHeight) && numIn(p.shotMaxHeight, 120, 1080))) { errors.push(`${w}.posts.shotMaxHeight must be null or a whole number of pixels from 120 to 1080`); } if (p.layout !== undefined && !POST_LAYOUTS.includes(p.layout)) { errors.push(`${w}.posts.layout must be ${POST_LAYOUTS.map((l) => `"${l}"`).join(" or ")}`); } if (p.links !== undefined && !POST_LINKS.includes(p.links)) { errors.push(`${w}.posts.links must be ${POST_LINKS.map((l) => `"${l}"`).join(" or ")}`); } if (p.hold !== undefined && !numIn(p.hold, 0, 10)) errors.push(`${w}.posts.hold must be from 0 to 10 seconds`); if (p.shift !== undefined && p.shift !== false) { if (!isObj(p.shift)) errors.push(`${w}.posts.shift must be false or { scale, seconds }`); else { unknownKeys(p.shift, ["scale", "seconds"], `${w}.posts.shift`, errors); if (p.shift.scale !== undefined && !numIn(p.shift.scale, 0.5, 1)) errors.push(`${w}.posts.shift.scale must be from 0.5 to 1`); if (p.shift.seconds !== undefined && !numIn(p.shift.seconds, 0, 3)) errors.push(`${w}.posts.shift.seconds must be from 0 to 3`); } } if (p.show !== undefined && typeof p.show !== "boolean") errors.push(`${w}.posts.show must be true or false`); if (p.seconds !== undefined && !numIn(p.seconds, 0.5, 10)) errors.push(`${w}.posts.seconds must be from 0.5 to 10`); if (p.position !== undefined && !["top-right", "top-left"].includes(p.position)) { errors.push(`${w}.posts.position must be "top-right" or "top-left"`); } if (p.width !== undefined && !(Number.isInteger(p.width) && numIn(p.width, 320, 900))) { errors.push(`${w}.posts.width must be a whole number of pixels from 320 to 900`); } if (p.qrSize !== undefined && !numIn(p.qrSize, 80, 200)) errors.push(`${w}.posts.qrSize must be from 80 to 200`); if (p.maxLines !== undefined && !(Number.isInteger(p.maxLines) && numIn(p.maxLines, 2, 14))) { errors.push(`${w}.posts.maxLines must be a whole number from 2 to 14`); } if (p.inset !== undefined && !numIn(p.inset, 0, 80)) errors.push(`${w}.posts.inset must be from 0 to 80`); }); return errors; } /** * Every module's settings, in the order validateChrome runs them: `id` the * module's, `key` its path under `render.chrome` (`deck` keys are read from * the deck object), `configKey` the manifest path its docs name. */ export const SETTINGS = Object.freeze([ // The fact-check (the stamps' settings, and the verdicts and tally the counter reads without `deck.counter`). { id: "stamp", key: "factcheck", configKey: "render.chrome.factcheck", validate: (v, { render }) => validateFactcheck(v, undefined, { fontBold: render.fontBold ?? null }) }, { id: "threads", key: "threads", configKey: "render.chrome.threads", validate: (v) => validateThreads(v) }, { id: "flips", key: "flips", configKey: "render.chrome.flips", validate: (v) => validateFlips(v) }, { id: "stats", key: "stats", configKey: "render.chrome.stats", validate: (v) => validateStats(v) }, { id: "fx", key: "fx", configKey: "render.chrome.fx", validate: (v) => validateFx(v) }, // The live-chat column (chat.mjs). { id: "chat", key: "chat", configKey: "render.chrome.chat", validate: (v) => validateChat(v) }, // The story modules (story-settings.mjs): then and now, the chapters, the status ledger. { id: "pair", key: "pair", configKey: "render.chrome.pair", validate: (v) => validatePair(v) }, { id: "chapter", key: "chapter", configKey: "render.chrome.chapter", validate: (v) => validateChapter(v) }, { id: "status", key: "status", configKey: "render.chrome.status", validate: (v) => validateStatus(v) }, // From here the deck's own keys: `deck` is an object. { id: "finale", key: "deck.finale", configKey: "render.chrome.deck.finale", deck: true, validate: (v, { where }) => validateFinaleSettings(v, `${where}.finale`) }, { id: "claims", key: "deck.claims", configKey: "render.chrome.deck.claims", deck: true, validate: (v, { where }) => deckClaimShapeErrors(v, `${where}.claims`) }, // The measure ledger's slice (measure-slice.mjs), which the instruments draw from. { id: "measure", key: "deck.measure", configKey: "render.chrome.deck.measure", deck: true, validate: (v, { where }) => validateMeasureSettings(v, `${where}.measure`) }, { id: "counter", key: "deck.counter", configKey: "render.chrome.deck.counter", deck: true, validate: (v, { chrome, render }) => validateCounter(v, { factcheck: chrome.factcheck, labelFits: (s, where, fit) => counterLabelProblem(s, where, { fontBold: render.fontBold ?? null, ...fit }), }) }, { id: "shell", key: "deck", configKey: "render.chrome.deck", deck: true, whole: true, validate: validateShellSettings }, { id: "rail", key: "deck", configKey: "render.chrome.deck.pip", deck: true, whole: true, validate: validateRailSettings }, { id: "section-title", key: "deck.sectionTitle", configKey: "render.chrome.deck.sectionTitle", deck: true, validate: validateSectionTitleSettings }, { id: "subtitle", key: "deck", configKey: "render.chrome.deck.subtitle", deck: true, whole: true, validate: validateSubtitleSettings }, { id: "qr", key: "deck", configKey: "render.chrome.deck.qr", deck: true, whole: true, validate: validateQrSettings }, { id: "popup-posts", key: "deck", configKey: "render.chrome.deck.posts", deck: true, whole: true, validate: validatePostsSettings }, // The measure's instruments (instruments.mjs): the dial, the odometer, the trail. { id: "dial", key: "deck.dial", configKey: "render.chrome.deck.dial", deck: true, validate: (v, { where }) => validateDial(v, `${where}.dial`) }, { id: "odometer", key: "deck.odometer", configKey: "render.chrome.deck.odometer", deck: true, validate: (v, { where }) => validateOdometer(v, `${where}.odometer`) }, { id: "trail", key: "deck.trail", configKey: "render.chrome.deck.trail", deck: true, validate: (v, { where }) => validateTrail(v, `${where}.trail`) }, // The measure extras (measure-extras-settings.mjs): the goal stack, the moving // start, the promise clock and the diet badge, each its own deck key. ...MEASURE_EXTRAS.map((id) => ({ id, key: `deck.${id}`, configKey: `render.chrome.deck.${id}`, deck: true, validate: (v, { where, chrome }) => validateMeasureExtra(id, v, `${where}.${id}`, { chrome }), })), // The shelf (shelf-settings.mjs): the strip beside the footage its occupants stand in. { id: "shelf", key: "deck.shelf", configKey: "render.chrome.deck.shelf", deck: true, validate: (v, { where, chrome }) => validateShelf(v, `${where}.shelf`, chrome) }, ].map((s) => Object.freeze(s))); /** A module's settings entry, or undefined. */ export const settingsOf = (id) => SETTINGS.find((s) => s.id === id); /** The value a SETTINGS entry reads from `render.chrome`. */ export function settingValue(chrome, entry) { if (entry.whole) return chrome.deck ?? {}; return entry.key.split(".").reduce((o, k) => (isObj(o) ? o[k] : undefined), chrome); }