// THE MODULE REGISTRY (release 39): every chrome module, once. The build's // overlay pass, the composer, the validator and umtool's panels all loop over // this list -- a module joins the video by being registered here, and by // nothing else. The order a list is in is its `z`: a region with a higher z // is laid over one with a lower. // // Pure: the module files are, and so is this. import { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, PLAY_CLOCKS, REGION_PLACEMENTS } from "./contract.mjs"; import { settingsOf, settingValue } from "./settings.mjs"; // The stacked vertical deck's rules (vertical-deck.mjs) and the render a vertical cut is built with (vertical.mjs). import { instrumentsGeometry } from "../deck.mjs"; import { verticalOn, verticalRender } from "../vertical.mjs"; import { leftOutWords, stackedOn } from "../vertical-deck.mjs"; import { resolveDial } from "../instruments.mjs"; import { runsFinaleWanted } from "../chrome-runs-finale.mjs"; import chart from "./chart.mjs"; import shell from "./shell.mjs"; import feed from "./feed.mjs"; import popupPosts from "./popup-posts.mjs"; import stamp from "./stamp.mjs"; import stats from "./stats.mjs"; import fx from "./fx.mjs"; import threads from "./threads.mjs"; import flips from "./flips.mjs"; import finale from "./finale.mjs"; import teaser from "./teaser.mjs"; import analysis from "./analysis.mjs"; import subtitle from "./subtitle.mjs"; import qr from "./qr.mjs"; import rail from "./rail.mjs"; import counter from "./counter.mjs"; import claims from "./claims.mjs"; import intro from "./intro.mjs"; import blur from "./blur.mjs"; import gapCue from "./gap-cue.mjs"; import pair from "./pair.mjs"; import chapter from "./chapter.mjs"; import status from "./status.mjs"; import chat from "./chat.mjs"; import sectionTitle from "./section-title.mjs"; import dial from "./dial.mjs"; import odometer from "./odometer.mjs"; import trail from "./trail.mjs"; import dialFinale from "./dial-finale.mjs"; import diet from "./diet.mjs"; import peak from "./peak.mjs"; import goals from "./goals.mjs"; import promise from "./promise.mjs"; import streak from "./streak.mjs"; import shelf from "./shelf.mjs"; import runsFinale from "./runs-finale.mjs"; export { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, PLAY_CLOCKS, REGION_PLACEMENTS }; /** Every module, by z (stack order), then id. */ export const MODULES = Object.freeze( [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, analysis, intro, blur, gapCue, pair, chapter, status, chat, shelf, diet, peak, goals, promise, streak, dial, odometer, trail, dialFinale, runsFinale] .sort((a, b) => a.z - b.z || a.id.localeCompare(b.id)), ); { const ids = new Set(); const regions = new Set(); for (const m of MODULES) { if (ids.has(m.id)) throw new Error(`registry: two modules are ${m.id}`); ids.add(m.id); if (m.region) { if (regions.has(m.region)) throw new Error(`registry: two modules file their frames as ${m.region}`); regions.add(m.region); } } const provided = new Set(MODULES.flatMap((m) => m.provides ?? [])); for (const m of MODULES) { if (m.host && !ids.has(m.host)) throw new Error(`registry: ${m.id}'s host ${m.host} is not a module`); for (const d of m.deps ?? []) if (!provided.has(d)) throw new Error(`registry: ${m.id} reads ${d}, which no module provides`); } } const BY_ID = new Map(MODULES.map((m) => [m.id, m])); const BY_REGION = new Map(MODULES.filter((m) => m.region).map((m) => [m.region, m])); /** A module by id, or undefined. */ export const moduleById = (id) => BY_ID.get(id); /** The module that files its frames as `region` (`deck` is the shell's), or undefined. */ export const moduleOfRegion = (region) => BY_REGION.get(region); /** A module by region, or a sentence saying there is none. */ export function regionModule(region) { const m = BY_REGION.get(region); if (!m) throw new Error(`unknown chrome region: ${region}`); return m; } /** * The overlays a deck build composes and lays, in z order: every * render-cached overlay module (the deck's shell first, the finale last). */ export const deckOverlays = () => MODULES.filter((m) => (m.kind === "overlay-whole" || m.kind === "overlay-window") && m.cached !== false); /** * The modules Play the cut and the live preview draw through the generic * path, in z order: every module that declares `play` (contract.mjs, PLAY). * Its own page, composed for preview and seeked on its clock. */ export const playModules = () => MODULES.filter((m) => m.play); /** * How a region is laid over the cut: "whole" (a sequence as long as the cut, * from frame 1 -- or a chunk's `startNumber`), "window" (a short sequence at * its own second), or null for the legacy chart band (its chain stays as it * shipped). */ export function placementOf(region) { const m = BY_REGION.get(region); if (!m || m.cached === false) return null; return m.kind === "overlay-window" ? "window" : m.kind === "overlay-whole" ? "whole" : null; } /** A region's render cache: is its page keyed (`.key`, frame keys), and is it drawn over the whole cut (windowable)? */ export function regionCaching(region) { const m = regionModule(region); const keyed = m.cached !== false; return { keyed, wholeCut: keyed && m.kind === "overlay-whole" }; } /** The parts drawn in `host`'s page, by z. */ export const partsOf = (host) => MODULES.filter((m) => m.host === host); /** * The deck schedule as its modules' SLICES, `{ [moduleId]: slice }`: what * each module reads of the one schedule the build writes (schedule.json * keeps its shape -- the pages, umtool's preview and the caches read it). * A module the cut does not use has no slice. */ export function scheduleSlices(doc) { if (!doc || doc.kind !== "deck") return {}; const stamps = doc.factcheck?.stamps ?? []; const out = { shell: { segments: doc.segments, total: doc.total, fps: doc.fps, transition: doc.transition, ...(doc.moves ? { moves: doc.moves } : {}) }, rail: { pips: doc.segments.filter((s) => !s.noPip).map((s) => s.id) }, ...(stamps.length ? { counter: { stamps }, stamp: { stamps: stamps.filter((s) => s.stamp !== false) } } : {}), ...(doc.layout === "feed" ? { feed: { posts: doc.posts ?? [] } } : doc.posts ? { "popup-posts": { posts: doc.posts } } : {}), ...(doc.finale ? { finale: doc.finale } : {}), ...(doc.deckClaims ? { claims: doc.deckClaims } : {}), ...(doc.threads ? { threads: doc.threads } : {}), ...(doc.flips ? { flips: doc.flips } : {}), ...(doc.stats ? { stats: doc.stats } : {}), ...(doc.fx ? { fx: doc.fx } : {}), // The measure ledger's slice (measure-slice.mjs): every instrument module // (dial, odometer, trail, goals, peak, promise, diet) reads it whole. ...(doc.measure ? { measure: doc.measure } : {}), // The shelf's notes (`deck.shelf`, an entry's shelfNote): only with one on the shelf. ...(doc.shelf ? { shelf: doc.shelf } : {}), }; return out; } /** * Every module's own settings checked against a manifest: `{ [moduleId]: * sentences }`, only the modules with something to say. What umtool's * generic panel shows under each module; the build refuses with the same * sentences (deck.mjs validateChrome runs the deck's in one list). */ export function moduleProblems(manifest) { const render = manifest?.render ?? {}; const chrome = render.chrome ?? {}; const deckOnCut = !!chrome && typeof chrome === "object" && chrome.layout === "deck"; const out = {}; for (const m of MODULES) { if (!m.validate) continue; // A deck module's settings are read through its SETTINGS entry (the // path validateChrome reads); any other's at its configKey. const entry = settingsOf(m.id); if ((entry || m.configKey?.startsWith("render.chrome")) && !deckOnCut) continue; const value = entry ? settingValue(chrome, entry) : (m.configKey ?? "").split(".").slice(1).reduce((o, k) => (o && typeof o === "object" ? o[k] : undefined), render); const errors = m.validate(value, { render, chrome, deck: chrome.deck ?? {}, manifest, where: "render.chrome.deck" }); if (errors.length) out[m.id] = errors; } return out; } // --------------------------------------------------------------------------- // THE STACKED VERTICAL DECK (vertical-deck.mjs): a module stands in it by its // `vertical` form (contract.mjs VERTICAL_SLOTS); one with none is left out -- // said so in the lint and the build's notes, never squashed into the frame. // --------------------------------------------------------------------------- /** A module's form in the stacked vertical deck (`{ slot }`), or null: it has none. */ export const verticalFormOf = (m) => (m && m.vertical) || null; /** Is this module's setting written on the render (its configKey, or its SETTINGS entry) and not `false`? */ function configured(m, render) { const chrome = render?.chrome ?? {}; const entry = settingsOf(m.id); const value = entry ? settingValue(chrome, entry) : m.configKey ? m.configKey.split(".").slice(1).reduce((o, k) => (o && typeof o === "object" ? o[k] : undefined), render) : undefined; if (value === undefined || value === null || value === false) return false; if (value && typeof value === "object" && value.show === false) return false; return true; } /** * What the stacked vertical deck leaves out of a manifest, as sentences: each * module the cut sets up that has no vertical form (the posts popups and * feed, the side panel, the finale's landscape page …), and an instrument * the panel has no room for. Empty for any other cut. `manifest.render` is the * cut's as written (the vertical one is derived here, as the build derives it). */ export function stackedLeftOut(manifest) { const render = verticalRender(manifest?.render ?? {}); if (!verticalOn(manifest?.render) || !stackedOn(render)) return []; const out = []; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; for (const m of MODULES) { if (verticalFormOf(m)) continue; let on = configured(m, render); // The finale's diet runs: on with `deck.finale.dietRuns` and a finale to draw them in. if (m.id === "runs-finale") on = !!runsFinaleWanted(render) && tl.some((e) => e?.layout === "finale"); // The legacy chart band (`render.chart` under `render.chromeEngine`): drawn only without the deck, so a stacked // deck says so only when the cut asks for it. if (m.id === "chart") on = manifest?.render?.chromeEngine === "hyperframes" && !!manifest?.render?.chart; if (m.id === "popup-posts") on = Array.isArray(manifest?.posts) && manifest.posts.length > 0 && render?.chrome?.deck?.posts?.show !== false; if (m.id === "finale") on = tl.some((e) => e?.layout === "finale"); if (m.id === "feed") on = render?.chrome?.deck?.posts?.layout === "feed"; if (!on) continue; // The finale's landscape page: the stacked deck stands the dial's instrument column in its window, when the dial draws one. if (m.id === "finale" && resolveDial(render)?.finale) { out.push(leftOutWords("finale", "its landscape page has no vertical form (the instrument column, module dial-finale, stands in its window)")); continue; } out.push(leftOutWords(m.id)); } for (const id of instrumentsGeometry(render).out ?? []) out.push(leftOutWords(id, "no room left in the instruments' panel")); return out; }