// THE VERTICAL DECK (lane vertical-deck, 9 Nov): a cut that has a deck keeps it // in 9:16. The operator's pick from the layouts (out/vertical-design): the // STACKED deck as the default (`render.vertical.deck: "stacked"`; "bare" is the // vertical format as it first shipped, no deck), a clip's TWO-CROP reframe as // its own option (`vertical.layout: "twocrop"`, `vertical.crops`), and a post // item as the hero card with the deck kept round it. // // ONE composition, two geometries: the deck's schedule, its pages and its // timing are the landscape cut's; only where things stand changes. This file // says where, top to bottom, inside the platforms' safe area // (render.vertical.safe: the top 8 %, the bottom 20 %, the right 12 %): // // rail the section's name and its progress segments, "2 / 5" under the top band // picture the clip's 16:9 footage box at the frame's full width // shelf over the picture's lower-left (the stamps, a shelf's notes) // captions under the picture, at most two lines, each word lit // panel the instruments in two columns (the dial tall at the left) // counters the tally's cells, when the cut counts // source channel · title · date · time, the QR beside it above the bottom band // wordmark the site's name, dim, in the bottom band (decoration only) // // A post item: its card in the picture's and the captions' room, the counters // under it, the big date line and the QR in the source block. A twocrop clip: // the source line and the rail together on top, crop one, a one-row strip of // the instruments, crop two with the captions over its foot, the QR small and // low-left in the bottom band. The finale: the instrument column over the // picture's room. // // A LEAF and PURE: no fs, no ffmpeg, and it imports nothing of the deck's -- // deck.mjs, the pages and the build read it. import { VERTICAL_HEIGHT, VERTICAL_WIDTH, clipTwoCrop, stackedDeckWanted, verticalKnobs } from "yt-dlp-transcript-common/lib/report/vertical.mjs"; export { clipTwoCrop, stackedDeckWanted }; const even = (n) => 2 * Math.round(n / 2); const evenDown = (n) => 2 * Math.floor(n / 2); /** * Is this render the stacked deck: a 9:16 render (`format: "vertical"`, the * build's 1080x1920) that keeps its deck. The geometry functions of deck.mjs * (deckGeometry, instrumentsGeometry …) ask this and answer with the stacked * deck's boxes; a landscape render is never one. */ export const stackedOn = (render) => stackedDeckWanted(render) && (render?.height ?? 0) > (render?.width ?? 0); /** How large the picture's own overlays (the stamps, the stats, the measure extras) are drawn, against the landscape deck's 1920 design px. */ export const STACKED_PICTURE_K = 0.75; /** The caption face's size in the stacked deck, a share of the frame's width (under the picture: two lines fit their band). */ export const STACKED_CAPTION_SHARE = 0.046; /** The QR's size (a share of the width) in the source block, and the twocrop's small one in the bottom band. */ export const STACKED_QR_SHARE = 0.13; export const STACKED_QR_SMALL_SHARE = 0.1; /** The smallest a panel cell is drawn against its column's width (its aspect kept) before it is left out. */ export const PANEL_SHRINK = 0.8; /** The panel's gap between its two columns and between its cells, a share of the width. */ export const STACKED_GAP_SHARE = 0.02; /** * The safe area in px: everything that must be read keeps inside x0..x1, * y0..y1 (render.vertical.safe). The left margin is the stacked deck's own * (the mockups' 14 of 405). */ export function stackedSafe(render, W = render?.width ?? VERTICAL_WIDTH, H = render?.height ?? VERTICAL_HEIGHT) { const s = verticalKnobs(render).safe; return { x0: Math.round(W * 0.035), x1: Math.round(W * (1 - s.right)), y0: Math.round(H * s.top), y1: Math.round(H * (1 - s.bottom)) }; } /** * Where everything of the stacked deck stands, frame px. `counter`: the cut * draws the tally's cells (they take a row over the source block). * * @returns {{ W: number, H: number, safe: {x0:number,x1:number,y0:number,y1:number}, * rail: Rect & { label: number, bar: number }, picture: Rect, shelf: Rect, captions: Rect & { size: number, lines: number }, * panel: Rect, gap: number, counters: Rect | null, source: Rect & { qr: {x:number,y:number,size:number}, text: Rect }, * wordmark: { x: number, y: number, size: number }, post: { card: Rect, counters: Rect }, * twocrop: { top: Rect, crop1: Rect, strip: Rect, crop2: Rect, captions: { bottom: number }, qr: {x:number,y:number,size:number} }, * finale: { title: Rect, column: Rect } }} */ export function stackedGeometry(render, { counter = false } = {}) { const W = render?.width ?? VERTICAL_WIDTH; const H = render?.height ?? VERTICAL_HEIGHT; const a = stackedSafe(render, W, H); const u = W / 1080; const gap = Math.round(W * STACKED_GAP_SHARE); const k = verticalKnobs(render); // The rail: the section's name over its progress segments, just under the top band. const label = Math.round(40 * u); const bar = Math.max(4, Math.round(8 * u)); const rail = { x: a.x0, y: a.y0 + Math.round(12 * u), width: a.x1 - a.x0, height: label + Math.round(17 * u) + bar, label, bar }; // The picture: the frame's full width, 16:9, under the rail. const ph = even((W * 9) / 16); const picture = { x: 0, y: even(rail.y + rail.height + Math.round(31 * u)), width: W, height: ph }; // The shelf: over the picture's lower-left. const shelf = { x: a.x0 - Math.round(11 * u), y: picture.y + ph - Math.round(16 * u) - Math.round(110 * u), width: evenDown((a.x1 - a.x0) * 0.62), height: Math.round(110 * u) }; // The captions: at most two lines under the picture. const size = Math.round(W * STACKED_CAPTION_SHARE); const lines = k.captions.lines; const captions = { x: a.x0, y: picture.y + ph + Math.round(22 * u), width: a.x1 - a.x0, height: Math.round(size * 1.24 * 2), size, lines }; // The source block, standing on the bottom band: its rule, the QR, the words. const qrSize = even(W * STACKED_QR_SHARE); const padTop = Math.round(22 * u); const sourceH = padTop + qrSize; const source = { x: a.x0, y: a.y1 - Math.round(12 * u) - sourceH, width: a.x1 - a.x0, height: sourceH }; const sq = { x: a.x0, y: source.y + padTop, size: qrSize }; const sourceBlock = { ...source, qr: sq, text: { x: sq.x + qrSize + Math.round(27 * u), y: sq.y, width: a.x1 - (sq.x + qrSize + Math.round(27 * u)), height: qrSize } }; // The tally's row, over the source block. const counters = counter ? { x: a.x0, y: source.y - gap - Math.round(72 * u), width: a.x1 - a.x0, height: Math.round(72 * u) } : null; // The panel: what is left between the captions and the counters (or the source block). const panelTop = captions.y + captions.height + Math.round(15 * u); const panelBottom = (counters ? counters.y : source.y) - gap; const panel = { x: a.x0, y: panelTop, width: a.x1 - a.x0, height: Math.max(0, panelBottom - panelTop) }; // The wordmark: dim, low in the bottom band. const wordmark = { x: a.x0, y: H - Math.round(38 * u) - Math.round(28 * u), size: Math.round(28 * u) }; // A post item (layout 4): its card from under the rail to the panel's top, the counters under it. const card = { x: a.x0, y: even(rail.y + rail.height + Math.round(76 * u)), width: evenDown(a.x1 - a.x0), height: 0 }; card.height = evenDown(panelTop - card.y); const postCounters = { x: a.x0, y: card.y + card.height + Math.round(26 * u), width: a.x1 - a.x0, height: Math.round(80 * u) }; // Two crops (layout 3): the source line over the rail at the top, crop one, the strip, crop two to the bottom band. const top = { x: a.x0, y: a.y0 + Math.round(6 * u), width: a.x1 - a.x0, height: picture.y - (a.y0 + Math.round(6 * u)) - Math.round(10 * u) }; const crop1 = { x: 0, y: picture.y, width: W, height: even(H * 0.3275) }; const strip = { x: 0, y: crop1.y + crop1.height, width: W, height: even(144 * u) }; const crop2 = { x: 0, y: strip.y + strip.height, width: W, height: evenDown(a.y1 - (strip.y + strip.height)) }; const qs = even(W * STACKED_QR_SMALL_SHARE); const twocrop = { top, crop1, strip, crop2, captions: { bottom: crop2.y + crop2.height - Math.round(18 * u) }, qr: { x: a.x0, y: a.y1 + Math.round((H - a.y1 - qs) / 2), size: qs }, }; // The finale: its title in the rail's place, the instrument column over the picture's room. const finale = { title: { x: a.x0, y: rail.y, width: a.x1 - a.x0, height: label }, column: { x: a.x0, y: even(rail.y + label + Math.round(30 * u)), width: evenDown(a.x1 - a.x0), height: 0 }, }; finale.column.height = evenDown(a.y1 - Math.round(10 * u) - finale.column.y); return { W, H, safe: a, gap, rail, picture, shelf, captions, panel, counters, source: sourceBlock, wordmark, post: { card, counters: postCounters }, twocrop, finale, }; } /** * The panel's cells: `items` in order, each `{ id, tall?, aspect }` (its * design box's width / height). A TALL item (the dial) takes the left column's * whole height and the rest stack down the right; without one they fill the * two columns, the shorter first. Each cell is its column's width and its * aspect's height (at most what is left). An item that does not fit is left * out (`out`), never squashed. * * @param {{x:number,y:number,width:number,height:number}} panel * @param {Array<{ id: string, tall?: boolean, aspect: number }>} items * @param {number} gap * @returns {{ cells: Record, out: string[] }} */ export function panelCells(panel, items, gap) { const colW = evenDown((panel.width - gap) / 2); const cols = [ { x: panel.x, y: panel.y }, { x: panel.x + panel.width - colW, y: panel.y }, ]; const bottom = panel.y + panel.height; const cells = {}; const out = []; let tallDone = false; for (const it of items) { if (it.tall && !tallDone && cols[0].y === panel.y) { cells[it.id] = { x: cols[0].x, y: panel.y, width: colW, height: evenDown(panel.height) }; cols[0].y = bottom + gap; tallDone = true; continue; } // At its column's width, else a size down (to PANEL_SHRINK of it, its aspect kept) where that fits. let placed = null; for (const k of [1, 0.95, 0.9, 0.85, PANEL_SHRINK]) { const w = evenDown(colW * k); const h = evenDown(w / Math.max(0.2, it.aspect)); // The column with the most room left that holds it. const fits = cols.filter((c) => c.y + h <= bottom + 0.5).sort((p, q) => p.y - q.y || p.x - q.x); if (fits.length && h >= 24) { placed = { c: fits[0], w, h }; break; } } if (!placed) { out.push(it.id); continue; } const { c, w, h } = placed; cells[it.id] = { x: c.x, y: c.y, width: w, height: h }; c.y += h + gap; } return { cells, out }; } /** * The caption geometry the vertical captions (vertical.mjs verticalAss) are * drawn with in the stacked deck: under the picture, centred, the stacked * deck's size -- or, for a twocrop clip, over crop two's foot. */ export function stackedCaptionGeo(render, { twocrop = false } = {}) { const g = stackedGeometry(render); const marginL = g.safe.x0 + Math.round(10 * (g.W / 1080)); const marginR = g.W - g.safe.x1 + Math.round(10 * (g.W / 1080)); if (twocrop) { return { layout: "stacked", size: Math.round(g.captions.size * 1.08), tag: null, captions: { align: 2, marginL, marginR, marginV: g.H - g.twocrop.captions.bottom } }; } return { layout: "stacked", size: g.captions.size, tag: null, captions: { align: 8, marginL, marginR, marginV: g.captions.y } }; } /** * A crop of the source (`[x, y, w, h]` fractions) cut to a box's aspect about * its centre, in source px (even): what a twocrop band shows. */ export function cropToBox(crop, srcW, srcH, box) { const [fx, fy, fw, fh] = crop; let w = fw * srcW; let h = fh * srcH; const want = box.width / box.height; if (w / h > want) w = h * want; else h = w / want; w = Math.max(2, Math.min(evenDown(w), srcW - (srcW % 2))); h = Math.max(2, Math.min(evenDown(h), srcH - (srcH % 2))); const cx = (fx + fw / 2) * srcW; const cy = (fy + fh / 2) * srcH; return { w, h, x: Math.round(Math.max(0, Math.min(srcW - w, cx - w / 2))), y: Math.round(Math.max(0, Math.min(srcH - h, cy - h / 2))) }; } /** How far a band enlarges the source's own pixels, each crop (its band's width over the crop's): past ENLARGE_WARN it softens. */ export function twoCropEnlargement(crops, srcW, srcH, render) { const g = stackedGeometry(render).twocrop; return [g.crop1, g.crop2].map((box, i) => { const c = cropToBox(crops[i], srcW, srcH, box); return Math.round((box.width / c.w) * 100) / 100; }); } /** A band enlarged past this many times its source pixels is said to soften (a lint warning, never a refusal). */ export const ENLARGE_WARN = 2.5; /** * The twocrop picture as ONE filtergraph from the build's picture pad to its * last filter: the frame's ground, crop one in its band, crop two in its band. * `blur` the clip's own blur on the source first. */ export function twoCropGraph({ crops, srcW, srcH, render, blur = [], fps = 30, id = "tc" }) { const g = stackedGeometry(render); const W = g.W; const H = g.H; const p = (s) => `${id}${s}`; const bg = String(render?.palette?.bg ?? "#12100c").replace("#", "0x"); const t = g.twocrop; const a = cropToBox(crops[0], srcW, srcH, t.crop1); const b = cropToBox(crops[1], srcW, srcH, t.crop2); const lead = [...blur, "setsar=1"].join(","); // The ground is crop one PADDED to the frame -- never an endless colour source under an overlay, which the // filtergraph fills faster than the picture drains it (the real-data preview was OOM-killed at 8 GB, 9 Nov). return [ `${lead},split=2[${p("a")}][${p("b")}]`, `[${p("a")}]crop=${a.w}:${a.h}:${a.x}:${a.y},scale=${t.crop1.width}:${t.crop1.height}:flags=lanczos,setsar=1,pad=${W}:${H}:0:${t.crop1.y}:color=${bg}[${p("g1")}]`, `[${p("b")}]crop=${b.w}:${b.h}:${b.x}:${b.y},scale=${t.crop2.width}:${t.crop2.height}:flags=lanczos,setsar=1[${p("2")}]`, `[${p("g1")}][${p("2")}]overlay=x=0:y=${t.crop2.y}:format=auto,setsar=1,fps=${fps}`, ].join(";"); } /** * The spans the panel's instruments stand down for in the stacked deck: a post * item (its card takes the room) and a twocrop clip (its strip carries them). * `[{ from, to }]` in cut seconds, from the schedule's segments. */ export function stackedStandDowns(schedule) { return (schedule?.segments ?? []) .filter((s) => s.type === "post" || s.vlayout === "twocrop") .map((s) => ({ from: s.start, to: s.end ?? s.start + s.duration, why: s.type === "post" ? "post" : "twocrop" })); } /** The words a module left out of the stacked deck is said with (the lint, the build's note). */ export const leftOutWords = (id, why = "no vertical form") => `${id}: ${why} -- left out of the stacked vertical deck (render.vertical.deck "bare" drops the deck; landscape keeps it)`;