// THE POPUP POSTS (module `popup-posts`, region `posts`): a clip's posts as // cards over the footage at the end of the clip (or from its start), one // short page per clip that carries them, laid at its own second. // chrome-posts.mjs writes the page; deck.mjs `postWindows` / `snapWindow` // time it and `postsGeometry` places it. import path from "node:path"; import { postsGeometry, postWindows, resolveDeck, snapWindow } from "../deck.mjs"; import { postsHtml, windowPosts } from "../chrome-posts.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; import { DECK_DEFAULTS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, settingsOf } from "./settings.mjs"; const SEGMENT_RE = /^[A-Za-z0-9_-]+$/; export default defineModule({ id: "popup-posts", version: 1, z: 30, kind: "overlay-window", slot: "popup", title: "Popup posts", summary: "A clip's posts as cards over the footage, each window its own short page at its own second.", configKey: "render.chrome.deck.posts", defaults: DECK_DEFAULTS.posts, validate: settingsOf("popup-posts").validate, ui: [ { key: "show", type: "boolean", label: "Show the posts", default: true }, { key: "layout", type: "enum", options: POST_LAYOUTS, label: "Layout", default: "popup" }, { key: "links", type: "enum", options: POST_LINKS, label: "QR links to", default: "archive" }, { key: "qr", type: "boolean", label: "QR on each card", default: true }, { key: "width", type: "number", min: 320, max: 900, label: "Width (px)", default: DECK_DEFAULTS.posts.width }, { key: "inset", type: "number", min: 0, max: 80, label: "Inset (px)", default: DECK_DEFAULTS.posts.inset }, { key: "maxLines", type: "number", min: 2, max: 14, label: "Lines of words", default: DECK_DEFAULTS.posts.maxLines }, { key: "qrSize", type: "number", min: 80, max: 200, label: "QR size", default: DECK_DEFAULTS.posts.qrSize }, { key: "at", type: "enum", options: POST_AT, label: "Come up at", default: "end" }, { key: "seconds", type: "number", min: 0.5, max: 10, step: 0.5, label: "Seconds each", default: DECK_DEFAULTS.posts.seconds }, { key: "hold", type: "number", min: 0, max: 10, step: 0.5, label: "Hold (s)", default: DECK_DEFAULTS.posts.hold }, { key: "position", type: "enum", options: ["top-right", "top-left"], label: "Side", default: "top-right" }, { key: "shotMaxHeight", type: "number", min: 120, max: 1080, label: "Screenshot height cap", default: null }, // `persist` (opt-in): the cards stay up on their own clock across clips; no hold. { key: "persist.seconds", type: "number", min: POST_PERSIST.seconds.min, max: POST_PERSIST.seconds.max, step: 1, label: "Persist across clips: seconds up", default: null }, { key: "persist.gap", type: "number", min: POST_PERSIST.gap.min, max: POST_PERSIST.gap.max, step: 1, label: "Persist: stay up for a post within (s)", default: null }, ], docs: { heading: "Popup posts", intro: "A clip's posts as cards over the footage (`deck.posts`, the `popup` layout), each window its own short page.", rows: [ ["`deck.posts.at`", "`end` (the clip's last `seconds` each) · `start` (from the clip's start, sharing it) · default `end`", "`umtool look
deck.posts='{\"at\":\"start\"}'`"], ["`deck.posts.seconds`, `.hold`", "0.5–10 · 0–10 s · default 4, 2.5 (the last frame held so the last card can be read)", "same"], ["`deck.posts.position`", "`top-right` · `top-left` · default `top-right`", "same"], ["`deck.posts.shift`", "`false` · `{scale 0.5–1, seconds 0–3}` · default 0.86, 0.6 (the footage moves aside while they are up)", "same"], ["`deck.posts.shotMaxHeight`", "null · 120–1080 px · default null (a full card of words)", "same"], ["`deck.posts.persist`", "`true` · `{seconds 8–60, gap 0–30}` · `false`/absent (off: each clip's posts its own short window, as above) · default seconds 12, gap 6. On: the footage NEVER freezes (`hold` is ignored). A card comes up at its moment (`at`, as above) and stays up on its own clock for `seconds`, over clip joins and dissolves. A post whose moment comes while the bar is up, or within `gap` after it would go, keeps it up: a later clip's cards SWAP in (the cards up slide up and out as the new one lands — the bar holds one clip's posts at a time, so stale cards never pile up over the footage), a clip's own still stack. With no post soon it leaves (0.45 s fade). The bar never runs into a card, a teaser, an image or the finale: it is gone by the transition into one. `shift` spans it too: the footage stays aside across the joins the bar spans, every segment moving on the cut's clock, and glides back as the bar leaves (a segment that starts as it leaves comes in at its normal box). Absent, every render is byte for byte what it was", "`umtool look
deck.posts.persist='{\"seconds\":12,\"gap\":6}'` (`deck.posts.persist=` off)"], ], }, region: "posts", // A clip's posts window leaves over the next segment's dissolve (deck.mjs postSchedule `out`): into a full-frame // item that exit plays whole (full-frame.mjs `ownFade`). fullFrame: { ownFade: true }, workers: "narrow", noun: "the posts window's", on: (schedule) => postWindows(schedule).length > 0, window(schedule, { window = null, segment = null, fps, total }) { const want = window ?? postWindows(schedule).find((w) => w.segment === segment); if (!want) { throw new Error(segment ? `no post rides on ${segment} in this schedule` : "the posts region needs a window (or a segment)"); } if (!SEGMENT_RE.test(String(want.segment))) throw new Error(`posts: ${want.segment} is not a segment id`); return snapWindow(want, { fps, total }); }, names: ({ preview, window }) => ({ project: `posts-${preview ? "preview-" : ""}${window.segment}`, stem: `posts-${window.segment}` }), async page(ctx) { // The deck's faces and the deck's QR maker: a card is part of the deck's // family, not a second design. const { render, schedule, window } = ctx; const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); const posts = windowPosts(schedule, window.segment); // `posts.qr: false`: no codes are made, and the page draws none. const byUrl = resolveDeck(render).posts.qr === false ? new Map() : await ctx.qrs(posts.map((p) => p.qrUrl), resolveDeck(render).posts.qrSize); const qrSrcs = {}; for (const p of posts) if (p.qrUrl) qrSrcs[p.id] = byUrl.get(p.qrUrl); const shotSrcs = await ctx.shots(posts); const logoSrcs = await ctx.shots(posts, "logo"); return postsHtml(schedule, render, window, { fonts, qrSrcs, shotSrcs, logoSrcs }); }, /** * The posts windows as overlay regions: one per clip that carries posts * (`postWindows`), snapped to the frame grid (`snapWindow`), at * `postsGeometry`. `offset` is the second the window's frame 1 lands on in * the BASE's clock -- the cut's, or a preview's that starts `shift` seconds * in. `clip` (`{at, dur}`) keeps only the windows that intersect it. */ regions(schedule, { render, outDir, shift = 0, clip = null }) { const fps = Number(schedule.fps ?? render.fps); const g = postsGeometry(render); return postWindows(schedule) .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: "posts", segment: s.segment, window: w, frames: path.join(outDir, "chrome", `posts-${s.segment}-frames`), x: g.x, y: g.y, width: g.width, height: g.height, offset: s.from - shift, frameCount: s.frames, }, "window")); }, });