// THE MEASURE EXTRAS' MODULE SHAPE (weight video rev 9, lane measure-extras): // the goal stack, the moving start, the promise clock and the diet badge are // four modules of one shape -- a whole-cut overlay in a corner of the footage // box (or at `x`/`y`), its page chrome-measure-extras.mjs's, its states // measure-extras.mjs's, its settings measure-extras-settings.mjs's at // `render.chrome.deck.` -- so they are made here, once, and each module // file says only what is its own. import path from "node:path"; import { measureExtraGeometry, measureOf } from "../measure-extras.mjs"; import { placementsFor } from "../chrome-measure-extras.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; import { MEASURE_AVOID, MEASURE_DEFAULTS, MEASURE_FINALE, MEASURE_LIMITS, MEASURE_POSITIONS, resolveMeasureExtra, SHELF_POSITION, } from "./measure-extras-settings.mjs"; import { SHELF_EXTRAS } from "./shelf-settings.mjs"; import { settingsOf } from "./settings.mjs"; /** The ui fields every one of the four has: on, where, how big, how long, over the finale. */ const commonUi = (id) => [ { key: "show", type: "boolean", label: "Drawn (with a measure slice)", default: true }, { key: "position", type: "enum", options: SHELF_EXTRAS.includes(id) ? [...MEASURE_POSITIONS, SHELF_POSITION] : MEASURE_POSITIONS, label: SHELF_EXTRAS.includes(id) ? "Anchor in the footage, or the shelf" : "Anchor in the footage", default: MEASURE_DEFAULTS[id].position }, { key: "x", type: "number", min: MEASURE_LIMITS.x[0], max: MEASURE_LIMITS.x[1], label: "x (design px, with y: overrides the anchor)" }, { key: "y", type: "number", min: MEASURE_LIMITS.y[0], max: MEASURE_LIMITS.y[1], label: "y (design px)" }, { key: "scale", type: "number", min: MEASURE_LIMITS.scale[0], max: MEASURE_LIMITS.scale[1], step: 0.05, label: "Scale", default: 1 }, { key: "hold", type: "number", min: MEASURE_LIMITS.hold[0], max: MEASURE_LIMITS.hold[1], label: "Seconds up after each event (0: stays up)", ...(MEASURE_DEFAULTS[id].hold !== null ? { default: MEASURE_DEFAULTS[id].hold } : {}) }, { key: "finale", type: "enum", options: MEASURE_FINALE, label: "Over the finale", default: MEASURE_DEFAULTS[id].finale }, { key: "onPosts", type: "enum", options: MEASURE_AVOID, label: "Over a post item's card", default: "dodge" }, { key: "onChapters", type: "enum", options: MEASURE_AVOID, label: "Over a chapter band", default: "dodge" }, ]; /** * One of the four, as a module. * * @param {{ id: "goals" | "peak" | "promise" | "diet", z: number, title: string, summary: string, * states: (schedule: any, render: any) => any[], html: (schedule: any, render: any, opts: any) => { html: string, items: any[] }, * ui?: any[], docs: { intro: string, rows: string[][] }, needs: string, * pageOpts?: (ctx: any) => Promise> }} spec */ export function measureExtraModule(spec) { const { id } = spec; const drawn = (schedule, render) => !!measureOf(schedule) && !!resolveMeasureExtra(id, render) && spec.states(schedule, render).length > 0; return defineModule({ id, version: 1, z: spec.z, kind: "overlay-whole", slot: "footage", // Its form in the stacked vertical deck (vertical-deck.mjs): over the picture, at its anchor there. vertical: { slot: "picture" }, title: spec.title, summary: spec.summary, configKey: `render.chrome.deck.${id}`, defaults: MEASURE_DEFAULTS[id], validate: settingsOf(id).validate, resolve: (render) => resolveMeasureExtra(id, render), ui: [...commonUi(id), ...(spec.ui ?? [])], docs: { heading: spec.title, intro: spec.docs.intro, rows: [ ...spec.docs.rows, [`\`deck.${id}.onPosts\`, \`.onChapters\``, "`dodge` `hide` `show` · default `dodge`: while a post item's card (its card, slot and strip as postLayout lays them: the schedule's `covers`) or a chapter band is up where it stands, it moves to a free anchor of the footage box -- a size down to half if it must, never onto another measure extra that is up -- and hides when none fits; `hide` hides, `show` stays over it", `\`umtool look

deck.${id}.onPosts=hide\``], ...(SHELF_EXTRAS.includes(id) ? [[`\`deck.${id}.position=shelf\``, `in its own slot on the shelf (\`deck.shelf\`: under or over the footage), scaled to the shelf's height, left to right in \`deck.shelf.items\` order -- nothing covers it there, so it never dodges (\`onPosts\`, \`onChapters\`, \`x\`/\`y\`, \`scale\` and \`avoid\` do not apply), and it is over the finale as the shelf is (\`deck.shelf.finale\`)`, `\`umtool look

deck.shelf=true deck.${id}.position=shelf\``]] : []), ["a timeline entry's `hideModules`", `\`["${id}", …]\` on an entry hides it over that entry's span, with its own fade, whatever it would otherwise do there (text in the footage no dodge can know of) · any entry, a post item too`, `\`umtool set

hideModules=${id}\` (\`--take \` for a take)`], ], }, region: id, workers: "narrow", noun: `the ${spec.title.toLowerCase()}'s`, on: drawn, check: (schedule, render) => { if (!measureOf(schedule)) return `the ${id} region needs a schedule with a measure slice (a measure ledger and render.chrome.deck.measure)`; if (!resolveMeasureExtra(id, render)) return `the ${id} region is off (render.chrome.deck.${id})`; return spec.states(schedule, render).length ? null : `the ${id} region needs ${spec.needs} on camera in the measure slice`; }, async page(ctx) { const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); // The condensed display face the video's other chrome uses, when the render names one. const display = ctx.render.fontDisplay ? await ctx.asset(ctx.render.fontDisplay, `MeasureDisplay${path.extname(ctx.render.fontDisplay) || ".ttf"}`).catch(() => null) : null; const extra = spec.pageOpts ? await spec.pageOpts(ctx) : {}; return spec.html(ctx.schedule, ctx.render, { ...extra, fonts: { ...fonts, ...(display ? { display } : {}) }, from: ctx.from, duration: ctx.duration }); }, regions(schedule, { render, outDir, frames = null }) { return [assertRegion({ name: id, frames: frames ?? path.join(outDir, "chrome", `${id}-frames`), // Its home, and every slot it moves clear to (a post card, a chapter band: measurePlacements). ...placementsFor(schedule, render)[id].region, })]; }, preview: (_slice, { render }) => ({ region: id, geometry: measureExtraGeometry(id, render) }), // Its page is its live preview: Play the cut seeks it in the cut's seconds (contract.mjs, PLAY). play: { clock: "cut", ready: `${id}:ready` }, // A cue interpreter: each state a block, keyed only while it is shown (frame-keys.mjs). frameKeys: { data: `${id}-data`, omit: ["init", "cues", "window", "total", "ids"] }, }); }