// THE INSTRUMENTS (rev 9 of the weight video, lane scale-dial): three deck // modules that read the schedule's MEASURE slice (`doc.measure`, written by the // build from a manifest's measure ledger) and stand in a column at the frame's // right, the clip moved to the left to make room for it: // // render.chrome.deck.dial an analog bathroom-scale face: a red needle to // every weight he states, on the word, with a // spring; his remembered weights as grey ghosts; // every goal in force on the bezel, the closest // headlined (measure-goals.mjs) // render.chrome.deck.odometer rolling digits of the pounds he says he has // lost (only ever up), NET beside them // render.chrome.deck.trail his stated weights by DATE, a thin line drawn // up to the playhead, the 300 lb line, a count // of the times he says he is under it // // Each is `true` (its defaults), an object of its settings, or `false` (off); // absent, it is ON when the cut draws a measure (`deck.measure` set) and off // when it does not. With any of them on the frame changes: the footage box moves to the // left edge and the column takes the right (deck.mjs deckGeometry, // instrumentsGeometry); the posts stay in the footage box (`posts.shift` does // not apply) and the side panel (threads, flips) and the feed are refused. // `deck.dial.finale` (default on) also draws the dial and the odometer large // in the finale's lower column (module `dial-finale`). // // A LEAF, like modules/settings.mjs: deck.mjs and settings.mjs import it, so it // imports neither (vertical-deck.mjs, the stacked deck's geometry, is a leaf too). import { stackedOn } from "./vertical-deck.mjs"; /** The column's width at 1920 wide (scaled with the frame): what the footage gives up. */ export const INSTRUMENT_COLUMN = 600; /** The needle's red, the spec's (contract §Screen design). */ export const NEEDLE_RED = "#ff5a4e"; /** Each instrument's settings and their defaults. */ export const DIAL_DEFAULTS = Object.freeze({ // The weight the face accents (its tick and label in the accent colour); null for none. mark: 300, // The remembered weights as ghost ticks, the latest a long ghost needle with its as-of date. ghosts: true, // Every goal in force as a mark on the bezel, the CLOSEST (measure-goals.mjs) the full amber tick // and its words under the digits, a missed one struck in red. goal: true, // The needle's colour: a #hex. needle: NEEDLE_RED, // The dial and the odometer drawn large in the finale's lower column (module dial-finale). finale: true, // The words over the big digits. label: "HE SAYS HE WEIGHS", // Where the instruments stand (a variant to judge): "column" -- the frame's right // column, the footage moved left for it -- or "corner": a smaller dial over one // corner of the footage (`corner`, `size` px at 1920 wide), the odometer and the // trail stacked beside it toward the middle of that side, the footage where the // deck always puts it. placement: "column", size: 340, corner: "bottom-right", // The needle's move to a stated weight: "spring" (back.out, an overshoot and a // settle, as a scale's) or "ease" (power2.inOut, no overshoot). motion: "spring", // The finale's last beat: "odometer" (the wheels roll, NET holds, to the end) or // "promise" -- the instruments hand off to the promise clock (module `promise`): // they fade out at the handoff (dialFinaleHandoff) and the clock takes the column. // With no promise module on the cut it ends as "odometer". // "auto" (the default): "promise" when a promise is on camera, else "odometer" -- // the contract's finale: the dial drops, the odometer rolls, NET holds, THEN the promise clock. finaleEnd: "auto", // A remembered weight (11 Nov variants): "needle" -- the long grey second needle and its as-of words, as it was -- // "rim" (a bold rim marker and a flag), "readout" (a line under the date, a rim marker), "callout" (a ghost needle // sweeps to it with a label held ~2 s, then the rim's flag). chrome-instruments.mjs dialParts. rememberedAs: "needle", // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. flash: null, }); export const DIAL_PLACEMENTS = Object.freeze(["column", "corner"]); export const DIAL_CORNERS = Object.freeze(["bottom-right", "bottom-left", "top-right", "top-left"]); export const DIAL_MOTIONS = Object.freeze(["spring", "ease"]); export const DIAL_FINALE_ENDS = Object.freeze(["auto", "odometer", "promise"]); export const DIAL_REMEMBERED = Object.freeze(["needle", "rim", "readout", "callout"]); /** A corner dial's size bounds, px at 1920 wide. */ export const DIAL_SIZE = Object.freeze([200, 540]); export const ODOMETER_DEFAULTS = Object.freeze({ label: "POUNDS HE SAYS HE'S LOST", // NET (first stated weight of the record to the latest) in plain digits beside the wheels. net: true, // "ACROSS 8 RUNS" under the wheels. runs: true, // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. flash: null, }); export const TRAIL_DEFAULTS = Object.freeze({ // The weight drawn as a line across the trail; null for none. mark: 300, // How many times he says he is under 300 (the measure's `totals.under300` rows), as they land. count: true, label: "WHAT HE SAYS HE WEIGHS, BY DATE", // The axes: "fit" what is shown so far, reflowing as each weight lands; "fixed" to every point of the cut. bounds: "fit", // His remembered weights ("≈390, as of Feb 2023") as points on the line too: hollow grey rings, the line quieter to them. remembered: true, // A stretch with no statement longer than this many days is a break in the time axis, not a line across it: // "auto" (a year, or 8× the median spacing if that is longer), a number of days (30–3650), or 0 for none. gap: "auto", // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. flash: null, }); /** A label's characters at most. */ export const INSTRUMENT_LABEL_MAX = 40; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; /** * Does the cut draw a measure (`render.chrome.deck.measure` set -- the build * writes the measure slice only then)? With one, every instrument is ON unless * it says otherwise -- as the measure extras are (rev 9, 6 Nov: the contract's * "on by default"); without one, an instrument is on only when it is named. */ export const measureAsked = (render) => isObj(render?.chrome?.deck?.measure); /** An instrument's settings, its defaults filled, or null when it is off (`false`; absent without a measure). */ function resolveOne(v, defaults, render) { if (v === false) return null; if (v === true || (v === undefined && measureAsked(render))) return { ...defaults }; if (!isObj(v)) return null; return { ...defaults, ...v }; } export const resolveDial = (render) => resolveOne(render?.chrome?.deck?.dial, DIAL_DEFAULTS, render); export const resolveOdometer = (render) => resolveOne(render?.chrome?.deck?.odometer, ODOMETER_DEFAULTS, render); export const resolveTrail = (render) => resolveOne(render?.chrome?.deck?.trail, TRAIL_DEFAULTS, render); /** Which instruments the render block asks for, in the column's order (top first). */ export function instrumentsWanted(render) { const out = []; if (resolveDial(render)) out.push("dial"); if (resolveOdometer(render)) out.push("odometer"); if (resolveTrail(render)) out.push("trail"); return out; } /** Where the instruments stand: the dial's `placement` ("column" without a dial) -- always the panel's column in the stacked vertical deck. */ export const instrumentsPlacement = (render) => (stackedOn(render) ? "column" : resolveDial(render)?.placement ?? "column"); /** * Is the instrument COLUMN on: any of the three asked for, placed in the column. * The frame's layout changes with it (the footage moves left); in the corner it does not. */ export const instrumentsOn = (render) => instrumentsWanted(render).length > 0 && instrumentsPlacement(render) === "column"; function labelProblem(v, where) { if (typeof v !== "string") return `${where} must be text`; if (/[\r\n]/.test(v)) return `${where} must be one line`; if ([...v].length > INSTRUMENT_LABEL_MAX) return `${where} is ${[...v].length} characters (at most ${INSTRUMENT_LABEL_MAX})`; return null; } /** The common shape: absent, true/false, or an object of known keys. */ function shapeErrors(v, defaults, where) { if (v === undefined || typeof v === "boolean") return { errors: [], obj: null }; if (!isObj(v)) return { errors: [`${where} must be true, false or { ${Object.keys(defaults).join(", ")} }`], obj: null }; const errors = []; for (const k of Object.keys(v)) { if (!Object.hasOwn(defaults, k)) errors.push(`${where}.${k} is not a setting of it (${Object.keys(defaults).join(", ")})`); } return { errors, obj: v }; } const markProblem = (v, where) => (v === null || numIn(v, 0, 2000) ? null : `${where} must be a weight (0 to 2000) or null`); const boolProblem = (v, where) => (typeof v === "boolean" ? null : `${where} must be true or false`); /** `render.chrome.deck.dial`, as sentences. */ export function validateDial(v, where = "render.chrome.deck.dial") { const { errors, obj } = shapeErrors(v, DIAL_DEFAULTS, where); if (!obj) return errors; if (obj.mark !== undefined) { const p = markProblem(obj.mark, `${where}.mark`); if (p) errors.push(p); } for (const k of ["ghosts", "goal", "finale"]) if (obj[k] !== undefined) { const p = boolProblem(obj[k], `${where}.${k}`); if (p) errors.push(p); } if (obj.needle !== undefined && !(typeof obj.needle === "string" && HEX_RE.test(obj.needle))) errors.push(`${where}.needle must be a #hex colour`); if (obj.label !== undefined) { const p = labelProblem(obj.label, `${where}.label`); if (p) errors.push(p); } const oneOf = (k, list) => { if (obj[k] !== undefined && !list.includes(obj[k])) errors.push(`${where}.${k} must be ${list.map((x) => `"${x}"`).join(" or ")}`); }; oneOf("placement", DIAL_PLACEMENTS); oneOf("motion", DIAL_MOTIONS); oneOf("finaleEnd", DIAL_FINALE_ENDS); oneOf("rememberedAs", DIAL_REMEMBERED); oneOf("corner", DIAL_CORNERS); if (obj.size !== undefined && !(Number.isInteger(obj.size) && numIn(obj.size, DIAL_SIZE[0], DIAL_SIZE[1]))) { errors.push(`${where}.size must be a whole number of pixels from ${DIAL_SIZE[0]} to ${DIAL_SIZE[1]}`); } if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; } /** `render.chrome.deck.odometer`, as sentences. */ export function validateOdometer(v, where = "render.chrome.deck.odometer") { const { errors, obj } = shapeErrors(v, ODOMETER_DEFAULTS, where); if (!obj) return errors; for (const k of ["net", "runs"]) if (obj[k] !== undefined) { const p = boolProblem(obj[k], `${where}.${k}`); if (p) errors.push(p); } if (obj.label !== undefined) { const p = labelProblem(obj.label, `${where}.label`); if (p) errors.push(p); } if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; } /** `render.chrome.deck.trail`, as sentences. */ export function validateTrail(v, where = "render.chrome.deck.trail") { const { errors, obj } = shapeErrors(v, TRAIL_DEFAULTS, where); if (!obj) return errors; if (obj.mark !== undefined) { const p = markProblem(obj.mark, `${where}.mark`); if (p) errors.push(p); } if (obj.count !== undefined) { const p = boolProblem(obj.count, `${where}.count`); if (p) errors.push(p); } if (obj.label !== undefined) { const p = labelProblem(obj.label, `${where}.label`); if (p) errors.push(p); } if (obj.remembered !== undefined) { const p = boolProblem(obj.remembered, `${where}.remembered`); if (p) errors.push(p); } if (obj.bounds !== undefined && !["fit", "fixed"].includes(obj.bounds)) errors.push(`${where}.bounds must be "fit" or "fixed"`); if (obj.gap !== undefined && !(obj.gap === "auto" || obj.gap === 0 || numIn(obj.gap, 30, 3650))) errors.push(`${where}.gap must be "auto", 0 (no breaks) or 30 to 3650 days`); if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; }