// THE COMPOSITIONS' TUNABLE PARAMS (release 38 lane E): the HyperFrames // regions a report cut can carry (report-to-video deck.mjs, stats.mjs, fx.mjs) // declare here the settings a person -- or the video assistant -- may change // by name, each with its bounds. Only a DECLARED param can be the target of a // video-assist `fx` op; nothing else under `render.chrome` is reachable that // way, and never free HTML. // // composition id where its settings live on when // deck render.chrome.deck the deck is (chrome.engine "hyperframes", layout "deck") // stats render.chrome.stats the deck is, and chrome.stats is an object // fx. render.chrome.fx. that effect is an object (fx.mjs FX_KEYS) // // A param is `{ key, label, kind, min?, max?, values?, maxLength?, default }`: // `key` a dot path inside the composition's settings, `kind` one of seconds / // number / int / px / enum / bool / text. The bounds are the composition's own // validator's (deck.mjs validateChrome, stats.mjs validateStats, fx.mjs // validateFx) -- report-to-video's fx-params.test.mjs holds each declaration // to its validator, at both bounds and just past them, so the two cannot // drift. The writer (umtool updateChrome, validateChrome on the whole render) // still has the last word at Apply: a param whose value is fine alone but // clashes with another setting is refused there, with the validator's reason. // // The modules re-export their own slice (DECK_PARAMS, STATS_PARAMS, // FX_PARAMS). Settings that move the layout as a whole (the deck's height, // the footage scale, the QR's size, the pips' sizes) are left out: each is // bounded by another and is a Media-tab decision, not a tweak. // // PURE. Plain ESM with a .d.mts beside it. const P = (key, label, kind, more) => Object.freeze({ key, label, kind, ...more }); const sec = (key, label, min, max, def) => P(key, label, "seconds", { min, max, default: def }); const numP = (key, label, min, max, def) => P(key, label, "number", { min, max, default: def }); const intP = (key, label, min, max, def) => P(key, label, "int", { min, max, default: def }); const oneOf = (key, label, values, def) => P(key, label, "enum", { values: Object.freeze(values), default: def }); const bool = (key, label, def) => P(key, label, "bool", { default: def }); const text = (key, label, maxLength, def) => P(key, label, "text", { maxLength, default: def }); const CORNERS = ["top-left", "top-right", "bottom-left", "bottom-right"]; /** Every composition's declared params, by composition id. */ export const COMPOSITION_PARAMS = Object.freeze({ deck: Object.freeze([ sec("motion.in", "the deck's slide in", 0, 2, 0.45), sec("motion.out", "the deck's slide out", 0, 2, 0.3), sec("motion.pip", "the timeline pip's move", 0, 3, 0.7), numP("title.size", "the clip title's size", 24, 96, 54), intP("title.maxChars", "the clip title's length", 10, 120, 48), bool("qr.show", "the deck's QR code", true), oneOf("subtitle.dateFormat", "the subtitle's date", ["long", "iso"], "long"), oneOf("background", "the deck's background", ["panel", "flush"], "panel"), oneOf("overCards", "the deck over cards", ["hide", "show"], "hide"), sec("posts.seconds", "how long a post is up", 0.5, 10, 4), sec("posts.hold", "the freeze under a post", 0, 10, 2.5), ]), stats: Object.freeze([ oneOf("position", "the stats panel's corner", CORNERS, "bottom-left"), bool("name", "the stats panel's name", true), ]), "fx.kineticQuote": Object.freeze([ oneOf("position", "the kinetic quote's place", ["bottom", "top"], "bottom"), numP("size", "the kinetic quote's size", 24, 96, 54), intP("maxWords", "the kinetic quote's words a page", 3, 30, 12), ]), "fx.redact": Object.freeze([ oneOf("position", "the redaction's place", ["bottom", "top"], "bottom"), numP("size", "the redaction's size", 24, 96, 44), intP("maxWords", "the redaction's words a page", 3, 30, 14), ]), "fx.odometer": Object.freeze([ oneOf("position", "the odometer's corner", CORNERS, "top-right"), text("label", "the odometer's label", 24, "times"), oneOf("at", "when the odometer rolls", ["phrase", "start"], "phrase"), ]), "fx.scrubber": Object.freeze([ oneOf("position", "the date rail's edge", ["top", "bottom"], "top"), bool("thumbs", "the date rail's thumbnails", true), ]), "fx.glitch": Object.freeze([ // "clips" tears into the clips its `clips` list names -- a list this table // has no kind for, so it is set in the manifest only; on "clips" with // no list, or a list under another `on`, is refused at Apply. oneOf("on", "where the glitch tears", ["year", "every", "clips"], "year"), sec("seconds", "the glitch's length", 0.2, 1.5, 0.5), bool("stamp", "the glitch's date stamp", true), bool("year", "the glitch's big year", true), ]), "fx.thenNow": Object.freeze([ sec("seconds", "the THEN/NOW wipe's length", 0.3, 2, 0.6), oneOf("dates", "the THEN/NOW dates", ["date", "year"], "date"), ]), "fx.receipts": Object.freeze([ oneOf("position", "the receipts' side", ["right", "left"], "right"), numP("width", "the receipts' width (of the footage)", 0.2, 0.6, 0.36), ]), "fx.zoom": Object.freeze([numP("width", "the zoom card's width (of the footage)", 0.3, 0.9, 0.56)]), "fx.punchIn": Object.freeze([ numP("scale", "the punch-in's scale", 1.05, 2, 1.2), sec("hold", "the punch-in's hold", 0.2, 6, 1.4), oneOf("anchor", "where the punch-in aims", ["upper", "center"], "upper"), bool("auto", "punch in on laughs", true), ]), "fx.whip": Object.freeze([oneOf("on", "where the whip pans", ["every", "year"], "every")]), }); export const COMPOSITION_IDS = Object.freeze(Object.keys(COMPOSITION_PARAMS)); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const deckOnOf = (render) => { const c = render?.chrome; return isObj(c) && c.engine === "hyperframes" && c.layout === "deck"; }; /** Is this composition drawn by the cut? */ export function compositionOn(render, id) { if (!COMPOSITION_IDS.includes(id)) return false; if (id === "deck") return deckOnOf(render); if (id === "stats") return deckOnOf(render) && isObj(render.chrome.stats); const fx = render?.chrome?.fx; return isObj(fx) && isObj(fx[id.slice(3)]); } /** The compositions this cut draws, in COMPOSITION_IDS order. */ export const compositionsOn = (render) => COMPOSITION_IDS.filter((id) => compositionOn(render, id)); /** Where a composition's settings live under `render.chrome`, as a path. */ export const settingsPathOf = (id) => (id === "deck" ? ["deck"] : id === "stats" ? ["stats"] : ["fx", id.slice(3)]); /** The declared param `key` of composition `id`, or null. */ export function paramOf(id, key) { return (COMPOSITION_PARAMS[id] ?? []).find((p) => p.key === key) ?? null; } const at = (o, keys) => keys.reduce((v, k) => (isObj(v) ? v[k] : undefined), o); /** A param's value in this render: as written, else its default. */ export function paramValue(render, id, key) { const p = paramOf(id, key); if (!p) return undefined; const v = at(render?.chrome, [...settingsPathOf(id), ...key.split(".")]); return v === undefined || v === null ? p.default : v; } /** Why `value` is not a value of the declared param (null: it is). */ export function paramValueError(p, value) { const fin = typeof value === "number" && Number.isFinite(value); switch (p.kind) { case "seconds": case "number": case "px": return fin && value >= p.min && value <= p.max ? null : `${p.label} is ${p.kind === "seconds" ? "seconds" : "a number"} from ${p.min} to ${p.max}`; case "int": return fin && Number.isInteger(value) && value >= p.min && value <= p.max ? null : `${p.label} is a whole number from ${p.min} to ${p.max}`; case "enum": return p.values.includes(value) ? null : `${p.label} is one of ${p.values.join(", ")}`; case "bool": return typeof value === "boolean" ? null : `${p.label} is true or false`; case "text": return typeof value === "string" && value.trim().length <= p.maxLength ? null : `${p.label} is a text of at most ${p.maxLength} characters`; default: return `${p.label} cannot be set here`; } } /** * `render.chrome` with one declared param set (a copy; null when the * composition is not drawn by this cut or the param is not declared). The * composition writer (updateChrome) validates the result as a whole. */ export function chromeWithParam(render, id, key, value) { if (!compositionOn(render, id) || !paramOf(id, key)) return null; const chrome = structuredClone(render.chrome); let o = chrome; for (const k of [...settingsPathOf(id), ...key.split(".").slice(0, -1)]) { if (!isObj(o[k])) o[k] = {}; o = o[k]; } o[key.split(".").at(-1)] = value; return chrome; }