// THE CHAPTER (module `chapter`, region `chapter`): a section bumper over the // first seconds of the clip it opens -- a title, a subtitle, a date // (`render.chrome.chapter`). One short page per chapter, laid at its own // second like a posts window. chrome-story.mjs writes the page. import path from "node:path"; import { snapWindow } from "../deck.mjs"; import { CHAPTER_SIDE_MIN, chapterGeometry, chapterHtml, chapterWindows, resolveChapter } from "../chrome-story.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; import { CHAPTER_DEFAULTS, CHAPTER_LIMITS, CHAPTER_STYLES, validateChapter } from "./story-settings.mjs"; const SEGMENT_RE = /^[A-Za-z0-9_.:-]+$/; export default defineModule({ id: "chapter", version: 1, z: 85, kind: "overlay-window", slot: "footage", // Its form in the stacked vertical deck (vertical-deck.mjs). vertical: { slot: "picture" }, title: "Chapters", summary: "A section bumper over the first seconds of the clip it opens: title, subtitle, date.", configKey: "render.chrome.chapter", defaults: CHAPTER_DEFAULTS, validate: (v) => validateChapter(v), resolve: resolveChapter, ui: [ { key: "style", type: "enum", options: CHAPTER_STYLES, label: "Style", default: "card" }, { key: "seconds", type: "number", min: CHAPTER_LIMITS.seconds[0], max: CHAPTER_LIMITS.seconds[1], step: 0.25, label: "Seconds", default: 3 }, { key: "list", type: "list", label: "Chapters", item: [ { key: "at", type: "clip", label: "Opens clip" }, { key: "title", type: "text", label: "Title" }, { key: "subtitle", type: "text", label: "Subtitle" }, { key: "date", type: "date", label: "Date" }, ] }, ], docs: { heading: "Chapters", intro: "A section bumper -- per dog, per crisis, per lawsuit -- over the first `seconds` of the clip it opens (`render.chrome.chapter`, chrome-story.mjs): a window of the cut laid at its own second, over the footage box (the deck stays). It does not insert time: the clip's sound plays under it.", rows: [ ["`chrome.chapter.list[]`", `1–${CHAPTER_LIMITS.list} \`{at, title ≤${CHAPTER_LIMITS.title}, subtitle? ≤${CHAPTER_LIMITS.subtitle}, date?}\` -- \`at\` the clip it opens, once each`, "`umtool modules apply

--config module-config.json` · `umtool look

chapter='{…}'`"], ["`chrome.chapter.style`", `\`card\` (the footage box covered) · \`lower\` (a band at its foot -- except over a POST item, whose card it never covers: it stands in the card's wider free side margin, its words fitted to it; a card with no margin ${CHAPTER_SIDE_MIN} px wide gets no bumper, the rail's section label still marks it) · default \`card\``, "`umtool look

chapter.style=lower`"], ["`chrome.chapter.seconds`", `${CHAPTER_LIMITS.seconds[0]}–${CHAPTER_LIMITS.seconds[1]} s, never past the clip · default 3`, "`umtool look

chapter.seconds=2.5`"], ], }, region: "chapter", workers: "narrow", noun: "the chapter's", on: (schedule, render) => !!schedule?.segments && chapterWindows(schedule, render).length > 0, check: (schedule, render) => (chapterWindows(schedule, render).length ? null : "the chapter region needs render.chrome.chapter with a chapter at a clip the cut plays"), window(schedule, { window = null, segment = null, fps, total, render = {} }) { const want = window ?? chapterWindows(schedule, render).find((w) => w.segment === segment); if (!want) throw new Error(segment ? `no chapter opens ${segment} in this schedule` : "the chapter region needs a window (or a segment)"); if (!SEGMENT_RE.test(String(want.segment))) throw new Error(`chapter: ${want.segment} is not a segment id`); return snapWindow(want, { fps, total }); }, names: ({ preview, window }) => ({ project: `chapter-${preview ? "preview-" : ""}${window.segment}`, stem: `chapter-${window.segment}` }), async page(ctx) { const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); return chapterHtml(ctx.schedule, ctx.render, ctx.window, { fonts }); }, regions(schedule, { render, outDir, shift = 0, clip = null }) { const fps = Number(schedule.fps ?? render.fps); const g = chapterGeometry(render, { feed: schedule.layout === "feed" }); return chapterWindows(schedule, render) .map((w) => ({ w, s: snapWindow(w, { fps, total: schedule.total }) })) .filter(({ s }) => !clip || (s.from < clip.at + clip.dur && s.to > clip.at)) .map(({ w, s }) => assertRegion({ name: "chapter", segment: s.segment, window: { segment: w.segment, from: w.from, to: w.to }, frames: path.join(outDir, "chrome", `chapter-${s.segment}-frames`), x: g.x, y: g.y, width: g.width, height: g.height, offset: s.from - shift, frameCount: s.frames, }, "window")); }, preview: (_slice, { render }) => ({ region: "chapter", geometry: chapterGeometry(render) }), // Its page is its live preview: Play the cut seeks it in the cut's seconds (contract.mjs, PLAY). play: { clock: "cut", ready: "chapter:ready" }, // A window of the cut: frame n is cut time `from` + n / fps. frameKeys: { data: "chapter-data", omit: ["init", "cues", "from", "dur"], offset: "from" }, });