// THE FEED (module `feed`, region `feed`): the posts in a column of their own // beside the footage for the whole cut, each ticking in as its clip starts // (`render.chrome.deck.posts.layout: "feed"`). chrome-feed.mjs writes the // page; deck.mjs `feedGeometry` lays the column and the footage beside it. import path from "node:path"; import { feedGeometry, resolveDeck } from "../deck.mjs"; import { feedHtml } from "../chrome-feed.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; import { DECK_DEFAULTS, POST_LAYOUTS, POST_LINKS, settingsOf } from "./settings.mjs"; export default defineModule({ id: "feed", version: 1, z: 20, kind: "overlay-whole", slot: "column", title: "Posts feed", summary: "The cut's posts in a column beside the footage, each ticking in as its clip starts.", configKey: "render.chrome.deck.posts", defaults: DECK_DEFAULTS.posts, // `deck.posts` is the popup posts' and the feed's alike: one validator. validate: (_value, ctx) => settingsOf("popup-posts").validate(ctx.deck ?? {}, ctx), 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: "shotMaxHeight", type: "number", min: 120, max: 1080, label: "Screenshot height cap", default: null }, ], docs: { heading: "Posts feed", intro: "`deck.posts.layout: \"feed\"` with posts to draw: a column for the whole cut, each post ticking in as its clip starts; no hold, no footage move. Shares `deck.posts` with the popup posts.", rows: [ ["`deck.posts.layout`", "`popup` · `feed` · default `popup`", "`umtool look
deck.posts='{\"layout\":\"feed\"}'`"], ["`deck.posts.width`, `.inset`", "320–900 · 0–80 px · default 600, 24 (the column's width; the footage keeps the inset clear)", "same"], ["`deck.posts.links`, `.qr`", "`archive` · `original`; bool · default `archive`, `true`", "same"], ], }, region: "feed", // The column slides with the deck's visibility (chrome-feed.mjs): full-frame.mjs `followsDeck`. fullFrame: { followsDeck: true }, workers: "wide", noun: "the feed's", on: (schedule) => schedule?.layout === "feed", check: (schedule) => (schedule.layout !== "feed" ? "the feed region needs a feed's schedule (layout \"feed\": posts.layout \"feed\" and posts to draw)" : null), async page(ctx) { // The posts feed: the deck's faces and QR maker, one page for the whole cut. const { render, schedule } = ctx; const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); const posts = schedule.posts ?? []; // `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); // A thread shot (a reply over the post it answers) is drawn whole: the // feed gives it the column rather than the room beside the card under it. const threads = new Set(); const shotSrcs = await ctx.shots(posts, "shot", threads); // Its items -- each card -- go to the frame keys. const items = []; const html = feedHtml(schedule, render, { fonts, qrSrcs, shotSrcs, threadShots: [...threads], from: ctx.from, duration: ctx.duration, items }); return { html, items }; }, regions(_schedule, { render, outDir, frames = null }) { return [assertRegion({ name: "feed", frames: frames ?? path.join(outDir, "chrome", "feed-frames"), ...feedGeometry(render).column })]; }, // The feed plans its cues IN the page, from the heights its cards measure // (chrome-feed.mjs): keyed by its EVENTS instead (frame-keys.mjs feedFrameKeys). frameKeys: { data: "feed-data", omit: ["window", "total", "ids", "posts", "visibility"], events: true }, });