// THE VERTICAL FORMAT, drawn (lane vertical, 5 Nov). The rules -- the knobs, // their defaults and their checks -- are common's (lib/report/vertical.mjs), // re-exported here; this module is the pure geometry the build draws them // with: a clip's picture in each layout, its captions, tag and hook as one ASS // document, a side post's place and motion, and a post item's box. // // T1 "full" the 9:16 crop full-bleed; big captions in the lower middle, each word lit as said // T2 "framed" the whole picture in the middle third over a blurred, darkened enlargement of // itself; the hook band above it, the captions below it // T3 "quote" the picture in the top 40 %; the words set large below it as a quote, each lit // as it is said; "-- channel · date" under them // M1 "split" (a clip with a side post) the picture in the top half; the post rises into the // bottom half at the side's `from` and leaves at its `to` // M2 "overlay" (a clip with a side post) T1, the post floating over its lower third // P1-P3 a post item drawn by post-render in a portrait box inside the safe area // // Every text a layout draws keeps out of the safe edges (render.vertical.safe: // the top 8 %, the bottom 20 % and the right 12 % by default), where the // platforms lay their own buttons and captions. // // PURE: no fs, no ffmpeg. The build (build-video.mjs) and umtool's vertical // command (lib/report/verticalCli.mjs) call it. import { DESKTOP_HEIGHT, DESKTOP_WIDTH, VERTICAL_HEIGHT, VERTICAL_WIDTH, clipLayoutOf, desktopKnobs, sidePostOf, sideSpan, stackedDeckWanted, verticalKnobs, verticalOn, } from "yt-dlp-transcript-common/lib/report/vertical.mjs"; import { assColour, assTime, captionText, cropPixels } from "./look.mjs"; export { CLIP_OWN_LAYOUTS, VERTICAL_DECKS, clipTwoCrop, stackedDeckWanted, LANDSCAPE_SIDE_PLACES, RENDER_FORMATS, SIDE_MIN_SECONDS, SIDE_PLACES, VERTICAL_CAPTION_SIZES, VERTICAL_CLIP_LAYOUTS, VERTICAL_DEFAULTS, VERTICAL_HEIGHT, VERTICAL_HOOKS, VERTICAL_KEYS, VERTICAL_POST_LAYOUTS, VERTICAL_SIDE_LAYOUTS, VERTICAL_WIDTH, clipLayoutOf, sideErrors, sidePostOf, sideSpan, validateClipSides, validateVerticalFormat, validateVerticalRender, verticalKnobs, verticalOn, DESKTOP_CAPTION_SIZES, DESKTOP_DEFAULTS, DESKTOP_HEIGHT, DESKTOP_KEYS, DESKTOP_QR_CORNERS, DESKTOP_QR_SIZE, DESKTOP_WIDTH, desktopKnobs, validateDesktopRender, } from "yt-dlp-transcript-common/lib/report/vertical.mjs"; const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const even = (n) => Math.max(2, 2 * Math.round(n / 2)); const f3 = (n) => Number(n).toFixed(3); /** The caption colours: a word not yet said, a word said (lit). */ export const VERTICAL_CAPTION_COLOURS = Object.freeze({ said: "#FFC840", unsaid: "#FFFFFF", muted: "#D9D2C3" }); /** The caption face (vendored, look.mjs CAPTION_FONT). */ export const VERTICAL_FONT = "IBM Plex Sans"; /** A caption group: at most this many words, broken at a pause this long (s). */ export const VERTICAL_GROUP_WORDS = 7; export const VERTICAL_GROUP_PAUSE = 0.5; /** A quote's phrase (T3): at most this many words. */ export const VERTICAL_QUOTE_WORDS = 14; /** How long a caption stays up after its last word (s), never past the next. */ export const VERTICAL_HOLD = 0.35; /** The side post's entrance and exit (s). */ export const SIDE_MOTION = 0.35; /** * The render a vertical cut is built with: 1080x1920 at the cut's fps, no * header, footer, QR, rail, deck or montage; the cut's posts, narration, * palette and fonts kept; the loudness the short is brought to. A cut that * keeps its deck (`render.vertical.deck` "stacked", the default, on a cut with * one: vertical-deck.mjs) keeps `chrome` -- the deck's geometry answers for * 9:16 -- and nothing else changes; "bare" is the format as it first shipped. */ export function verticalRender(render = {}) { const { chrome, rail: _r, chromeEngine: _e, brand: _b, montage: _m, intro: _i, room: _ro, ...rest } = render; const k = verticalKnobs(render); return { ...rest, ...(stackedDeckWanted(render) ? { chrome } : {}), format: "vertical", width: VERTICAL_WIDTH, height: VERTICAL_HEIGHT, headerHeight: 0, footerHeight: 0, qr: false, captions: { style: "speakers", ...(isObj(render.captions?.labels) ? { labels: render.captions.labels } : {}), size: "l" }, loudness: { target: k.loudness }, }; } /** * The render a DESKTOP clip is built with (lane clip-kit): 1920x1080 at the cut's fps, the picture full frame -- no * header, footer, corner QR, rail, deck, montage or intro -- the cut's palette, fonts and caption labels kept, its * loudness the desktop knobs'. `render.desktop` stays: the geometry reads it. */ export function desktopRender(render = {}) { const { chrome: _c, rail: _r, chromeEngine: _e, brand: _b, montage: _m, intro: _i, room: _ro, format: _f, ...rest } = render; const k = desktopKnobs(render); return { ...rest, width: DESKTOP_WIDTH, height: DESKTOP_HEIGHT, headerHeight: 0, footerHeight: 0, qr: false, captions: { style: "speakers", ...(isObj(render.captions?.labels) ? { labels: render.captions.labels } : {}), size: "l" }, loudness: { target: k.loudness }, // What says this render IS a desktop build (the lint measures its code): `render.desktop` alone is a look key a // landscape cut may carry for its batch. desktopBuild: true, }; } /** The desktop clip's safe area in px (render.desktop.safe): every text keeps inside it. */ export function desktopSafeArea(render, W = DESKTOP_WIDTH, H = DESKTOP_HEIGHT) { const s = desktopKnobs(render).safe; return { x0: Math.round(W * s.left), x1: Math.round(W * (1 - s.right)), y0: Math.round(H * s.top), y1: Math.round(H * (1 - s.bottom)) }; } /** The desktop caption face's size (px) for its caption size. */ export const desktopCaptionSize = (render, W = DESKTOP_WIDTH) => Math.round(W * ({ m: 0.028, l: 0.034, xl: 0.04 }[desktopKnobs(render).captions.size] ?? 0.034)); /** * A desktop clip's geometry: the picture full frame (fitted, never cropped), the source line top-left on a plate, * the hook under it, the captions along the foot of the safe area; `qr` (clip-kit.mjs desktopQrBox) at a bottom * corner narrows the captions on both sides so they keep centred and clear of it. */ export function desktopGeometry(render, W = DESKTOP_WIDTH, H = DESKTOP_HEIGHT, { qr = null } = {}) { const a = desktopSafeArea(render, W, H); const size = desktopCaptionSize(render, W); // A code at the top left: the source line stands to its right. const topLeftQr = qr && qr.x <= a.x0 + 1 && qr.y <= a.y0 + 1; const tag = { x: topLeftQr ? qr.x + qr.size + Math.round(W * 0.012) : a.x0, y: a.y0, size: Math.round(W * 0.016) }; const bottomQr = qr && qr.y + qr.size > a.y1 - Math.round(H * 0.25); const inset = bottomQr ? qr.size + Math.round(W * 0.015) : 0; return { layout: "desktop", size, tag, safe: a, video: { x: 0, y: 0, w: W, h: H, aspect: W / H, fill: "fit" }, background: false, hook: { top: tag.y + Math.round(tag.size * 2.2), size: Math.round(W * 0.026) }, captions: { align: 2, marginL: a.x0 + inset, marginR: W - a.x1 + inset, marginV: H - a.y1 }, }; } /** The desktop clip's hook (render.desktop.hook, from the cut's own copy only), or null. */ export function desktopHookOf(entry, render, sections = null) { return hookText(desktopKnobs(render).hook, { entry, sectionTitle: sections?.get?.(entry?.id) ?? null }); } /** The safe area in px: text keeps inside x0..x1, y0..y1. */ export function safeArea(render, W = VERTICAL_WIDTH, H = VERTICAL_HEIGHT) { const s = verticalKnobs(render).safe; return { x0: Math.round(W * 0.055), x1: Math.round(W * (1 - s.right)), y0: Math.round(H * s.top), y1: Math.round(H * (1 - s.bottom)) }; } /** The caption face's size (px) for the cut's caption size. */ export const captionSize = (render, W = VERTICAL_WIDTH) => Math.round(W * (verticalKnobs(render).captions.size === "xl" ? 0.08 : 0.068)); /** Characters a caption line holds at `size` px across `width` px (a bold face's average advance). */ export const lineChars = (width, size) => Math.max(10, Math.floor(width / (size * 0.56))); /** * Where everything sits for a clip in `layout` (a clip layout, or "split" / * "overlay" for a clip carrying a side post), in px of the frame: * `video` the picture's box, `crop` its aspect cut from the source, * `captions` {align, marginL, marginR, marginV} (ASS), `card` the side post's * box, `tag` / `hook` / `quote` / `cite` the text blocks' anchors. */ export function clipGeometry(layout, render, W = VERTICAL_WIDTH, H = VERTICAL_HEIGHT) { const a = safeArea(render, W, H); const size = captionSize(render, W); const capMarg = { marginL: a.x0, marginR: W - a.x1 }; const tag = { x: a.x0, y: a.y0 + Math.round(H * 0.012), size: Math.round(W * 0.034) }; if (layout === "framed") { const vh = even((W * 9) / 16); const vy = even((H - vh) / 2 - H * 0.02); return { layout, size, tag, video: { x: 0, y: vy, w: W, h: vh, aspect: W / vh, fill: "fit" }, background: true, hook: { bottom: vy - Math.round(H * 0.025), size: Math.round(W * 0.062) }, captions: { align: 8, ...capMarg, marginV: vy + vh + Math.round(H * 0.025) }, }; } if (layout === "quote") { const vh = even(H * 0.4); return { layout, size: Math.round(W * 0.066), tag: null, video: { x: 0, y: 0, w: W, h: vh, aspect: W / vh, fill: "crop" }, background: true, mark: { x: a.x0 - 8, y: vh + Math.round(H * 0.012), size: Math.round(W * 0.16) }, captions: { align: 7, marginL: a.x0, marginR: W - a.x1 + 20, marginV: vh + Math.round(H * 0.085) }, cite: { x: a.x0, bottom: a.y1 - Math.round(H * 0.02), size: Math.round(W * 0.036) }, }; } if (layout === "split") { const vh = even(H / 2); const cardY = vh + Math.round(H * 0.022); return { // The tag on the picture, under the top band: the bottom half is the side post's. layout, size, tag, video: { x: 0, y: 0, w: W, h: vh, aspect: W / vh, fill: "crop" }, background: true, captions: { align: 2, ...capMarg, marginV: H - vh + Math.round(H * 0.018) }, card: { x: a.x0 - 20, y: cardY, w: even(a.x1 - a.x0 + 20), h: even(a.y1 - cardY - Math.round(H * 0.01)) }, }; } // full (T1), and overlay (M2): the crop full-bleed. const cardH = even(H * 0.27); const card = layout === "overlay" ? { x: a.x0 - 20, y: a.y1 - cardH - Math.round(H * 0.01), w: even(a.x1 - a.x0 + 20), h: cardH } : null; return { layout, size, tag, video: { x: 0, y: 0, w: W, h: H, aspect: 9 / 16, fill: "crop" }, background: false, hook: { top: tag.y + Math.round(tag.size * 2.2), size: Math.round(W * 0.058) }, captions: { align: 2, ...capMarg, marginV: H - a.y1 + Math.round(H * 0.06) }, // While the side post is up, the captions sit above it. captionsAbove: card ? { align: 2, ...capMarg, marginV: H - card.y + Math.round(H * 0.015) } : null, card, }; } /** A box of `aspect` (w/h) cut from a `sw` × `sh` picture about `crop`'s centre (or the middle), even px. */ export function aspectCrop(sw, sh, aspect, crop = null) { let w = sw; let h = Math.round(sw / aspect); if (h > sh) { h = sh; w = Math.round(sh * aspect); } w = Math.min(even(w), sw - (sw % 2)); h = Math.min(even(h), sh - (sh % 2)); const [fx, fy, fw, fh] = Array.isArray(crop) && crop.length === 4 ? crop : [0, 0, 1, 1]; const cx = (fx + fw / 2) * sw; const cy = (fy + fh / 2) * sh; return { w, h, x: Math.round(Math.max(0, Math.min(sw - w, cx - w / 2))), y: Math.round(Math.max(0, Math.min(sh - h, cy - h / 2))) }; } /** * The part of the source a clip's layout shows (px: {x, y, w, h}) and the enlargement it shows it at (the frame's * pixels over the source's) -- the box verticalClipGraph cuts, measured. A zoom (clip-zoom.mjs) multiplies it. */ export function pictureRegion(geo, srcW, srcH, crop = null) { const v = geo.video; if (v.fill === "fit") return { region: { x: 0, y: 0, w: srcW, h: srcH }, rest: Math.min(v.w / srcW, v.h / srcH) }; const box = v.aspect === 9 / 16 ? cropPixels(crop, srcW, srcH) : aspectCrop(srcW, srcH, v.aspect, crop); return { region: box, rest: Math.min(v.w / box.w, v.h / box.h) }; } /** * The picture of a vertical clip as ONE filtergraph from a single input pad * (written after the build's `${pic}`) to its last filter (the build names it): * the source's own blur first (`blur`: clip-blur's filters on the source * picture), then the layout. `side` ({idx, from, to}: the card PNG's input * index and its span in the segment's seconds) lays the side post in. */ export function verticalClipGraph({ geo, srcW, srcH, crop = null, blur = [], side = null, fps = 30, W = VERTICAL_WIDTH, H = VERTICAL_HEIGHT, id = "v" }) { const p = (s) => `${id}${s}`; const v = geo.video; const lead = [...blur, "setsar=1"].join(","); const parts = []; // The picture's own box: a 9:16 crop (the clip's `vertical.crop` when set), else the layout's aspect. const box = v.fill === "fit" ? null : v.aspect === 9 / 16 ? cropPixels(crop, srcW, srcH) : aspectCrop(srcW, srcH, v.aspect, crop); const fg = box ? `crop=${box.w}:${box.h}:${box.x}:${box.y},scale=${v.w}:${v.h}:flags=lanczos,setsar=1` : `scale=${v.w}:${v.h}:force_original_aspect_ratio=decrease:flags=lanczos,pad=${v.w}:${v.h}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1`; if (geo.background) { // The ground: the picture enlarged to cover the frame, blurred and darkened. const dark = geo.layout === "framed" ? -0.16 : -0.3; parts.push( `${lead},split=2[${p("bgs")}][${p("fgs")}]`, `[${p("bgs")}]scale=${W}:${H}:force_original_aspect_ratio=increase,crop=${W}:${H},gblur=sigma=38:steps=2,eq=brightness=${dark}:saturation=0.75,setsar=1[${p("bg")}]`, `[${p("fgs")}]${fg}[${p("fg")}]`, `[${p("bg")}][${p("fg")}]overlay=x=${v.x}:y=${v.y}:format=auto,fps=${fps}`, ); } else { parts.push(`${lead},${fg},fps=${fps}`); } if (side && geo.card) { const c = geo.card; const a = Number(side.from); const b = Number(side.to); const m = SIDE_MOTION; // Up from below with an ease-out, and down again at its end; off-frame outside its span. const y = `if(lt(t,${f3(a)}),${H},if(lt(t,${f3(a + m)}),${c.y}+(${H}-${c.y})*pow(1-(t-${f3(a)})/${m},2),if(lt(t,${f3(b - m)}),${c.y},if(lt(t,${f3(b)}),${c.y}+(${H}-${c.y})*pow((t-${f3(b - m)})/${m},2),${H}))))`; parts[parts.length - 1] += `[${p("pre")}]`; parts.push(`[${side.idx}:v]format=rgba,scale=w=${c.w}:h=${c.h}:force_original_aspect_ratio=decrease:flags=lanczos,pad=${c.w}:${c.h}:(ow-iw)/2:(oh-ih)/2:color=0x00000000,setsar=1[${p("card")}]`, `[${p("pre")}][${p("card")}]overlay=x=${c.x}:y='${y}':eval=frame:format=auto`); } return parts.join(";"); } /** * The side post as a landscape cut draws it: a panel over the right (or left) * of the picture area `pic` ({x, y, w, h} in the frame) while it is up, * sliding in from that edge. Returns the box the card is drawn at and the * overlay filter (from `[base]` and `[card]` pads the caller names). */ export function landscapeSideGeometry(pic, place = "right") { const w = even(pic.w * 0.34); const h = even(Math.min(pic.h * 0.86, w * 1.15)); const m = Math.round(pic.w * 0.025); const x = place === "left" ? pic.x + m : pic.x + pic.w - w - m; const y = Math.round(pic.y + (pic.h - h) / 2); return { x, y, w, h, place: place === "left" ? "left" : "right" }; } /** The overlay of a landscape side panel: in from its edge over SIDE_MOTION, out again at its end. */ export function landscapeSideOverlay(geo, side, W) { const a = Number(side.from); const b = Number(side.to); const m = SIDE_MOTION; const off = geo.place === "left" ? -geo.w - 10 : W + 10; const x = `if(lt(t,${f3(a)}),${off},if(lt(t,${f3(a + m)}),${geo.x}+(${off}-${geo.x})*pow(1-(t-${f3(a)})/${m},2),if(lt(t,${f3(b - m)}),${geo.x},if(lt(t,${f3(b)}),${geo.x}+(${off}-${geo.x})*pow((t-${f3(b - m)})/${m},2),${off}))))`; return `overlay=x='${x}':y=${geo.y}:eval=frame:format=auto`; } // --------------------------------------------------------------------------- // The words: groups lit word by word, as one ASS document with the tag, the // hook and the quote's citation. // --------------------------------------------------------------------------- /** * Words (segment seconds) to caption groups: at most `maxWords`, at most * `maxChars` × `lines` characters, broken at a pause. `{start, end, words}`. */ export function captionGroups(words, { maxWords = VERTICAL_GROUP_WORDS, maxChars = 24, lines = 2, pause = VERTICAL_GROUP_PAUSE, seconds = Infinity, breaks = [] } = {}) { const used = (words ?? []) .map((w) => ({ text: captionText(w.text), start: Number(w.start), end: Number(w.end) })) .filter((w) => w.text && Number.isFinite(w.start) && Number.isFinite(w.end) && w.end > 0 && w.start < seconds) .map((w) => ({ ...w, start: Math.max(0, w.start), end: Math.min(seconds, Math.max(w.start + 0.05, w.end)) })) .sort((x, y) => x.start - y.start); const groups = []; let cur = null; const budget = maxChars * lines; for (const w of used) { const chars = cur ? cur.words.reduce((n, x) => n + x.text.length + 1, 0) + w.text.length : 0; const prev = cur?.words[cur.words.length - 1]; // A break (the promo card's start): no group runs across it. const across = cur && breaks.some((b) => cur.words[0].start < b && w.start >= b); if (!cur || across || cur.words.length >= maxWords || chars > budget || (cur.words.length >= 2 && w.start - prev.end >= pause)) { cur = { words: [w] }; groups.push(cur); } else cur.words.push(w); } return groups.map((g, i) => { const start = g.words[0].start; const last = g.words[g.words.length - 1].end; const next = groups[i + 1]?.words[0].start ?? Infinity; // Never held across a break it was said before. const wall = breaks.find((b) => start < b) ?? Infinity; const end = Math.min(seconds, wall, Math.max(last, Math.min(next, last + VERTICAL_HOLD))); return { start, end: Math.max(end, Math.min(start + 0.25, wall)), words: g.words }; }); } /** One group as karaoke text: each word lit when it is said (`\k`, centiseconds from the group's start). */ export function karaokeText(group) { let at = group.start; return group.words .map((w, j) => { const lead = Math.max(0, Math.round((w.start - at) * 100)); const next = group.words[j + 1]?.start ?? w.end; const dur = Math.max(1, Math.round((Math.max(next, w.start + 0.05) - w.start) * 100)); at = w.start + dur / 100; return `${lead ? `{\\k${lead}}` : ""}{\\k${dur}}${w.text}`; }) .join(" "); } /** A tag or a citation line: "Channel · 27 Oct 2026" from what the clip says of itself. */ export function sourceTagText({ channel = "", date = "" } = {}) { const d = /^\d{4}-\d{2}-\d{2}/.test(String(date)) ? formatDay(String(date).slice(0, 10)) : String(date ?? ""); return [String(channel ?? "").trim(), d].filter(Boolean).join(" · "); } const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; /** 2026-10-27 as "27 Oct 2026". */ export function formatDay(iso) { const [y, m, d] = iso.split("-").map(Number); return `${d} ${MONTHS[m - 1]} ${y}`; } /** * The hook line a clip shows, from the cut's own copy only: `hook` "title" is * the clip's own title, "section" its section's title (`sectionTitle`, given * by the build), {text} the cut's line. Null when there is none. */ export function hookText(hook, { entry = null, sectionTitle = null } = {}) { if (!hook) return null; if (isObj(hook) && typeof hook.text === "string") return hook.text.trim() || null; if (hook === "title") return typeof entry?.title === "string" && entry.title.trim() ? entry.title.trim() : null; if (hook === "section") return typeof sectionTitle === "string" && sectionTitle.trim() ? sectionTitle.trim() : null; return null; } /** * The ASS document a vertical clip burns in: its captions (each word lit as * said; a quote's phrases in T3), its source tag, its hook, a quote's mark and * citation. `words` in segment seconds; `hook` the line (verticalHookOf), `side` the side post's span (captions * move above an overlay card while it is up). */ export function verticalAss({ geo, render, words = [], seconds, tag = null, hook = null, side = null, W = VERTICAL_WIDTH, H = VERTICAL_HEIGHT, font = VERTICAL_FONT, knobs = null, promo = null }) { // `promo` (promo-card.mjs; {from, fade, captions, band}): from `from` the card is up -- the captions move into its // band (or, `captions: false`, stop there), the tag and the hook fade out with the card's fade in. // `knobs` (a desktop clip's: desktopKnobs) speak over the vertical ones for its lines and its tag. const k = knobs ?? verticalKnobs(render); const quote = geo.layout === "quote"; const size = geo.size; const width = W - geo.captions.marginL - geo.captions.marginR; const maxChars = lineChars(width, size); const breaks = promo ? [promo.from] : []; const groups0 = captionGroups(words, quote ? { maxWords: VERTICAL_QUOTE_WORDS, maxChars, lines: 4, pause: 0.9, seconds, breaks } : { maxChars, lines: k.captions.lines, seconds, breaks }); const groups = promo && !promo.captions ? groups0.filter((g) => g.start < promo.from) : groups0; const C = VERTICAL_CAPTION_COLOURS; const pal = { accent: "#c8752a", bg: "#12100c", ...(render?.palette ?? {}) }; const outline = Math.max(2, Math.round(size * 0.075)); const style = (name, { fs, primary, secondary = primary, align, mL = 0, mR = 0, mV = 0, bold = -1, ol = outline, sh = 2, border = 1, back = "#000000", backA = 0x80 }) => `Style: ${name},${[font, fs, assColour(primary), assColour(secondary), assColour("#000000"), assColour(back, backA), bold, 0, 0, 0, 100, 100, 0, 0, border, ol, sh, align, mL, mR, mV, 1].join(",")}`; const cap = geo.captions; const styles = [ style("cap", { fs: size, primary: C.said, secondary: C.unsaid, align: cap.align, mL: cap.marginL, mR: cap.marginR, mV: cap.marginV, ol: quote ? 0 : outline, sh: quote ? 0 : 2 }), style("tag", { fs: geo.tag?.size ?? 36, primary: "#F6F1E6", align: 7, mL: geo.tag?.x ?? 0, mV: geo.tag?.y ?? 0, bold: 0, ol: 10, sh: 0, border: 3, back: pal.bg, backA: 0x40 }), style("hook", { fs: geo.hook?.size ?? 60, primary: "#FFFFFF", align: geo.layout === "framed" ? 2 : 8, mL: cap.marginL, mR: cap.marginR, mV: geo.layout === "framed" ? H - (geo.hook?.bottom ?? 0) : geo.hook?.top ?? 0, ol: Math.round(outline * 0.8) }), style("mark", { fs: geo.mark?.size ?? 160, primary: pal.accent, align: 7, mL: geo.mark?.x ?? 0, mV: geo.mark?.y ?? 0, ol: 0, sh: 0 }), style("cite", { fs: geo.cite?.size ?? 38, primary: C.muted, align: 1, mL: geo.cite?.x ?? 0, mV: geo.cite ? H - geo.cite.bottom : 0, bold: 0, ol: 0, sh: 0 }), ]; const end = assTime(Math.max(0.1, seconds)); const events = []; const above = geo.captionsAbove; for (const g of groups) { const over = above && side && g.start < side.to && g.end > side.from; const onCard = promo?.band && g.start >= promo.from; const mv = onCard ? `{\\an2\\pos(${Math.round(W / 2 + (cap.marginL - cap.marginR) / 2)},${promo.band.y1})}` : over ? `{\\an${above.align}\\pos(${Math.round(W / 2 + (above.marginL - above.marginR) / 2)},${H - above.marginV})}` : ""; events.push(`Dialogue: 1,${assTime(g.start)},${assTime(g.end)},cap,,0,0,0,,${mv}${karaokeText(g)}`); } // Under the card, the tag and the hook go as it comes up. const fixedEnd = promo ? assTime(Math.min(seconds, promo.from + promo.fade)) : end; const fadeOut = promo ? `{\\fad(0,${Math.round(promo.fade * 1000)})}` : ""; if (tag && k.tag && geo.tag) events.push(`Dialogue: 0,${assTime(0)},${fixedEnd},tag,,0,0,0,,${fadeOut}${captionText(tag)}`); const h = typeof hook === "string" && hook.trim() ? hook.trim() : null; if (h && geo.hook) events.push(`Dialogue: 0,${assTime(0)},${fixedEnd},hook,,0,0,0,,${fadeOut}${captionText(h)}`); if (quote) { events.push(`Dialogue: 0,${assTime(0)},${fixedEnd},mark,,0,0,0,,${fadeOut}“`); if (tag) events.push(`Dialogue: 0,${assTime(0)},${fixedEnd},cite,,0,0,0,,${fadeOut}— ${captionText(tag)}`); } return [ "[Script Info]", "ScriptType: v4.00+", `PlayResX: ${W}`, `PlayResY: ${H}`, "WrapStyle: 0", "ScaledBorderAndShadow: yes", "YCbCr Matrix: None", "", "[V4+ Styles]", "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding", ...styles, "", "[Events]", "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text", ...events, "", ].join("\n"); } // --------------------------------------------------------------------------- // Post items in a vertical cut: a portrait box inside the safe area. // --------------------------------------------------------------------------- /** Where a post item is drawn in a vertical frame: its box (post-render's) and the pad that places it. */ export function verticalPostBox(render, W = VERTICAL_WIDTH, H = VERTICAL_HEIGHT) { const a = safeArea(render, W, H); const x = Math.round(W * 0.03); const y = a.y0; const width = even(a.x1 - x); const height = even(a.y1 - y); const bg = String(render?.palette?.bg ?? "#12100c").replace("#", "0x"); return { box: { x, y, width, height }, place: [`pad=${W}:${H}:${x}:${y}:color=${bg}`, "setsar=1", `fps=${render?.fps ?? 30}`] }; } /** The share of a portrait box a P3 ("media") attachment takes at the top. */ export const MEDIA_FIRST_SHARE = 0.6; /** * A post item as a vertical layout draws it (the run's copy, never written * back): P1 "card" lays its attachment under the words, one still card (no * read-follow column); P2 "stack" over them (the conversation column below, * lit as it is read); P3 "media" large over them. */ export function verticalPostEntry(entry, render) { if (!isObj(entry) || entry.type !== "post") return entry; const layout = verticalKnobs(render).post; if (layout === "media") return { ...entry, panel: "top", panelShare: MEDIA_FIRST_SHARE }; if (layout === "stack") return { ...entry, panel: "top" }; // P1: one card, still -- the posts it answers as compact context over it, never a panning column (read-follow off). return { ...entry, panel: "bottom", follow: false }; } /** The clips of a vertical cut and the layout each plays in: its own, or split / overlay when it carries a side post. */ export function clipVerticalLayout(entry, render) { if (isObj(entry?.side)) { const place = entry.side.place; return place === "split" || place === "overlay" ? place : verticalKnobs(render).side; } return clipLayoutOf(entry, render); } /** A vertical cut's notes: over its length (a note, not a refusal). */ export function verticalNotes(render, seconds) { if (!verticalOn(render)) return []; const max = verticalKnobs(render).maxSeconds; return Number.isFinite(seconds) && seconds > max + 0.05 ? [`this short runs ${seconds.toFixed(1)} s, over its ${max} s (render.vertical.maxSeconds)`] : []; } export { sidePostOf as sidePost, sideSpan as sideSpanOf }; /** * Each entry's section title, from the deck's markers (`render.chrome.deck.markers`, each after an entry, its * `label` the section from there on; `sectionTitle.first` before the first): the hook "section" reads it. */ export function sectionTitlesOf(manifest) { const deck = manifest?.render?.chrome?.deck ?? {}; const markers = Array.isArray(deck.markers) ? deck.markers : []; const after = new Map(markers.filter((m) => isObj(m) && typeof m.after === "string").map((m) => [m.after, typeof m.label === "string" ? m.label : null])); let cur = isObj(deck.sectionTitle) && typeof deck.sectionTitle.first === "string" ? deck.sectionTitle.first : null; const out = new Map(); for (const e of manifest?.timeline ?? []) { if (typeof e?.id !== "string") continue; out.set(e.id, cur); if (after.has(e.id)) cur = after.get(e.id); } return out; } /** The hook a vertical clip shows (render.vertical.hook, resolved from the cut's own copy), or null. */ export function verticalHookOf(entry, render, sections = null) { return hookText(verticalKnobs(render).hook, { entry, sectionTitle: sections?.get?.(entry?.id) ?? null }); } /** The post as a side card shows it: its words, its context and its author; no attachments, no word effects. */ export function sideCardEntry(post) { const { media: _m, fx: _f, panel: _p, panelShare: _s, links: _l, ...rest } = post ?? {}; return { ...rest, type: "post" }; }