// THE VERTICAL FORMAT'S RULES (lane vertical, 5 Nov): a whole cut rendered // 9:16 for the shorts platforms, and the side post a clip may carry. // // render.format "vertical" | "landscape" absent = landscape, the cut as it always was // render.vertical { deck?, clip?, post?, side?, captions?, hook?, tag?, safe?, loudness?, maxSeconds? } // deck "stacked" (the default: a cut that has a deck keeps it in 9:16 -- the rail under the top band, // the picture at full width, the captions under it, the instruments in two columns, // the source line and its QR above the bottom band; report-to-video/vertical-deck.mjs) // "bare" (the vertical format as it first shipped: no header, footer, QR, rail or deck) // clip "full" (T1: a 9:16 crop, big word captions in the lower middle, a source tag) // "framed" (T2: the whole 16:9 picture in the middle third over a blurred enlargement // of itself; captions below, a hook band above) // "quote" (T3: the picture in the top 40 %; the line being said set large below it, // each word lit as it is said; channel and date cited) // post "card" (P1: the card at full width, its attachment beneath) // "stack" (P2: the conversation as a column, the parents dimmed above, his post lit) // "media" (P3: the attachment large at the top, the words in a panel under it) // side "split" (M1: the clip in the top half, the side post in the bottom half while it is up) // "overlay" (M2: the clip full-bleed, the side post floating over its lower third) // captions { size?: "l" | "xl", lines?: 1 | 2 } large, at most two lines // hook false | "title" | "section" | { text } the band over a framed clip: the clip's own // title, its section's title, or a line of the cut's own copy -- never invented commentary // tag true | false the small "channel · date" tag on a clip // safe { top?, bottom?, right? } fractions of the frame kept clear of key text // (the platform's own buttons sit there) // loudness LUFS the short is brought to (-30 to -8; the shorts platforms play at -14) // maxSeconds a short over this is said so (a note, never a refusal) // // clip.side { item?: "", post?: {}, from, to, place? } // a post shown BESIDE a clip while it plays: not read aloud, the clip's own sound running. // `from`/`to` are seconds into the clip as it plays; `place` overrides the cut's // render.vertical.side for this clip ("split" | "overlay"), or, in a landscape cut, // "right" (the default) | "left" for the panel's side. // clip.vertical.layout this clip's own layout ("full" | "framed" | "quote") over the cut's -- or, in the // stacked deck, "twocrop": two crops of its picture stacked, `vertical.crops: [[x,y,w,h],[x,y,w,h]]` // (fractions of the source; the first on top), a strip of the instruments between them. // // PURE: no fs, no ffmpeg. Plain ESM with a .d.mts beside it. const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const num = (v) => typeof v === "number" && Number.isFinite(v); const q = (v) => JSON.stringify(v); export const RENDER_FORMATS = Object.freeze(["landscape", "vertical"]); export const VERTICAL_CLIP_LAYOUTS = Object.freeze(["full", "framed", "quote"]); /** A clip's OWN layouts: the cut's, and the stacked deck's two crops (a clip's alone: it needs its crops). */ export const CLIP_OWN_LAYOUTS = Object.freeze([...VERTICAL_CLIP_LAYOUTS, "twocrop"]); /** What a vertical cut does with the deck: keep it stacked in 9:16, or drop it (the bare vertical). */ export const VERTICAL_DECKS = Object.freeze(["stacked", "bare"]); export const VERTICAL_POST_LAYOUTS = Object.freeze(["card", "stack", "media"]); export const VERTICAL_SIDE_LAYOUTS = Object.freeze(["split", "overlay"]); /** Where a side post sits in a LANDSCAPE cut. */ export const LANDSCAPE_SIDE_PLACES = Object.freeze(["right", "left"]); export const SIDE_PLACES = Object.freeze([...VERTICAL_SIDE_LAYOUTS, ...LANDSCAPE_SIDE_PLACES]); export const VERTICAL_CAPTION_SIZES = Object.freeze(["l", "xl"]); export const VERTICAL_HOOKS = Object.freeze(["title", "section"]); /** A hook line of the cut's own copy: at most this many characters. */ export const VERTICAL_HOOK_MAX = 90; /** The shortest a side post may be up (s). */ export const SIDE_MIN_SECONDS = 1; export const VERTICAL_WIDTH = 1080; export const VERTICAL_HEIGHT = 1920; /** The shorts conventions, as knobs: what a cut that sets none gets. */ export const VERTICAL_DEFAULTS = Object.freeze({ deck: "stacked", clip: "full", post: "card", side: "split", captions: Object.freeze({ size: "xl", lines: 2 }), hook: false, tag: true, safe: Object.freeze({ top: 0.08, bottom: 0.2, right: 0.12 }), loudness: -14, maxSeconds: 60, qr: false, }); export const VERTICAL_KEYS = Object.freeze(Object.keys(VERTICAL_DEFAULTS)); export const VERTICAL_SAFE_MAX = Object.freeze({ top: 0.25, bottom: 0.35, right: 0.25 }); /** Is this cut rendered 9:16? */ export const verticalOn = (render) => render?.format === "vertical"; /** The cut's vertical knobs, the defaults filled in (whatever its format). */ export function verticalKnobs(render) { const v = isObj(render?.vertical) ? render.vertical : {}; return { deck: VERTICAL_DECKS.includes(v.deck) ? v.deck : VERTICAL_DEFAULTS.deck, clip: VERTICAL_CLIP_LAYOUTS.includes(v.clip) ? v.clip : VERTICAL_DEFAULTS.clip, post: VERTICAL_POST_LAYOUTS.includes(v.post) ? v.post : VERTICAL_DEFAULTS.post, side: VERTICAL_SIDE_LAYOUTS.includes(v.side) ? v.side : VERTICAL_DEFAULTS.side, captions: { ...VERTICAL_DEFAULTS.captions, ...(isObj(v.captions) ? v.captions : {}) }, hook: v.hook === undefined || v.hook === null ? VERTICAL_DEFAULTS.hook : v.hook, tag: typeof v.tag === "boolean" ? v.tag : VERTICAL_DEFAULTS.tag, safe: { ...VERTICAL_DEFAULTS.safe, ...(isObj(v.safe) ? v.safe : {}) }, loudness: num(v.loudness) ? v.loudness : VERTICAL_DEFAULTS.loudness, maxSeconds: num(v.maxSeconds) ? v.maxSeconds : VERTICAL_DEFAULTS.maxSeconds, qr: v.qr === true || isObj(v.qr) ? v.qr : VERTICAL_DEFAULTS.qr, }; } /** A short's code (lane clip-kit; umtool report-to-video clip-kit.mjs draws it): where it may stand, its keys. */ export const VERTICAL_QR_CORNERS = Object.freeze(["tr", "tl"]); export const VERTICAL_QR_KEYS = Object.freeze(["corner", "size", "links"]); export const VERTICAL_QR_SIZE = Object.freeze({ min: 0.1, max: 0.3, default: 0.16 }); export const QR_LINKS = Object.freeze(["cite", "moment", "channel"]); /** Each thing wrong with `render.vertical.qr` ([] when fine): false (the default), true, or {corner?, size?, links?}. */ export function verticalQrErrors(v, where = "render.vertical.qr") { if (v === undefined || v === null || v === false || v === true) return []; if (!isObj(v)) return [`${where} is true, false or {${VERTICAL_QR_KEYS.join(", ")}}`]; const errors = []; for (const k of Object.keys(v)) if (!VERTICAL_QR_KEYS.includes(k)) errors.push(`${where}.${k} is not a key (${VERTICAL_QR_KEYS.join(", ")})`); if (v.corner !== undefined && !VERTICAL_QR_CORNERS.includes(v.corner)) { errors.push(`${where}.corner is ${VERTICAL_QR_CORNERS.join(" or ")} (a short's captions run along its foot), not ${q(v.corner)}`); } if (v.size !== undefined && !(num(v.size) && v.size >= VERTICAL_QR_SIZE.min && v.size <= VERTICAL_QR_SIZE.max)) { errors.push(`${where}.size is ${VERTICAL_QR_SIZE.min}–${VERTICAL_QR_SIZE.max} of the frame's width`); } if (v.links !== undefined && !QR_LINKS.includes(v.links)) errors.push(`${where}.links is one of ${QR_LINKS.join(", ")}, not ${q(v.links)}`); return errors; } /** A clip's layout in a vertical cut: its own `vertical.layout`, else the cut's ("twocrop" is the stacked deck's: clipTwoCrop). */ export function clipLayoutOf(entry, render) { const own = entry?.vertical?.layout; return VERTICAL_CLIP_LAYOUTS.includes(own) ? own : verticalKnobs(render).clip; } /** * Does this cut keep its deck in 9:16 (the stacked deck)? A vertical cut whose `render.vertical.deck` is * "stacked" (the default) AND that has a deck to keep (`render.chrome`, the HyperFrames deck). A cut with no * deck is the bare vertical whatever it says. */ export function stackedDeckWanted(render) { const c = render?.chrome; return verticalOn(render) && verticalKnobs(render).deck === "stacked" && isObj(c) && c.engine === "hyperframes" && c.layout === "deck"; } /** A clip's two crops (`vertical.layout: "twocrop"`, `vertical.crops`), or null: the stacked deck plays it so. */ export function clipTwoCrop(entry) { const v = entry?.vertical; if (!isObj(v) || v.layout !== "twocrop" || !Array.isArray(v.crops) || v.crops.length !== 2) return null; return v.crops.every((c) => Array.isArray(c) && c.length === 4 && c.every(num)) ? v.crops.map((c) => [...c]) : null; } /** Every reason `render.format` / `render.vertical` cannot be built. */ export function validateVerticalRender(manifest) { const r = manifest?.render; const errors = []; if (r?.format !== undefined && r?.format !== null && !RENDER_FORMATS.includes(r.format)) { errors.push(`render.format must be one of ${RENDER_FORMATS.join(", ")}, not ${q(r.format)}`); } const v = r?.vertical; if (v === undefined || v === null) return errors; if (!isObj(v)) return [...errors, `render.vertical must be an object of the vertical knobs (${VERTICAL_KEYS.join(", ")})`]; for (const k of Object.keys(v)) if (!VERTICAL_KEYS.includes(k)) errors.push(`render.vertical.${k} is not a vertical knob (${VERTICAL_KEYS.join(", ")})`); const oneOf = (k, list) => { if (v[k] !== undefined && !list.includes(v[k])) errors.push(`render.vertical.${k} must be one of ${list.join(", ")}, not ${q(v[k])}`); }; oneOf("deck", VERTICAL_DECKS); oneOf("clip", VERTICAL_CLIP_LAYOUTS); oneOf("post", VERTICAL_POST_LAYOUTS); oneOf("side", VERTICAL_SIDE_LAYOUTS); if (v.captions !== undefined) { if (!isObj(v.captions)) errors.push("render.vertical.captions must be {size?, lines?}"); else { for (const k of Object.keys(v.captions)) if (k !== "size" && k !== "lines") errors.push(`render.vertical.captions.${k} is not a caption knob (size, lines)`); if (v.captions.size !== undefined && !VERTICAL_CAPTION_SIZES.includes(v.captions.size)) errors.push(`render.vertical.captions.size must be one of ${VERTICAL_CAPTION_SIZES.join(", ")}`); if (v.captions.lines !== undefined && v.captions.lines !== 1 && v.captions.lines !== 2) errors.push("render.vertical.captions.lines must be 1 or 2 (a short's captions are at most two lines)"); } } if (v.hook !== undefined && v.hook !== false) { if (isObj(v.hook)) { const t = v.hook.text; if (Object.keys(v.hook).some((k) => k !== "text")) errors.push("render.vertical.hook must be {text} (a line of the cut's own copy)"); if (typeof t !== "string" || !t.trim() || t.length > VERTICAL_HOOK_MAX) errors.push(`render.vertical.hook.text must be a line of 1–${VERTICAL_HOOK_MAX} characters`); } else if (!VERTICAL_HOOKS.includes(v.hook)) errors.push(`render.vertical.hook must be false, ${VERTICAL_HOOKS.map(q).join(", ")} or {text}`); } if (v.tag !== undefined && typeof v.tag !== "boolean") errors.push("render.vertical.tag must be true or false"); errors.push(...verticalQrErrors(v.qr)); if (v.safe !== undefined) { if (!isObj(v.safe)) errors.push("render.vertical.safe must be {top?, bottom?, right?}"); else { for (const [k, x] of Object.entries(v.safe)) { const max = VERTICAL_SAFE_MAX[k]; if (max === undefined) errors.push(`render.vertical.safe.${k} is not a safe edge (top, bottom, right)`); else if (!num(x) || x < 0 || x > max) errors.push(`render.vertical.safe.${k} must be a fraction of the frame from 0 to ${max}`); } } } if (v.loudness !== undefined && !(num(v.loudness) && v.loudness >= -30 && v.loudness <= -8)) errors.push("render.vertical.loudness must be LUFS from -30 to -8"); if (v.maxSeconds !== undefined && !(num(v.maxSeconds) && v.maxSeconds >= 5 && v.maxSeconds <= 600)) errors.push("render.vertical.maxSeconds must be seconds from 5 to 600"); return errors; } /** Every reason a clip's `side` cannot be built (its post's own fields are the post item's validator's). */ export function sideErrors(side, who = "side", { itemIds = null } = {}) { if (side === undefined || side === null) return []; if (!isObj(side)) return [`${who} must be {item | post, from, to, place?}`]; const errors = []; for (const k of Object.keys(side)) if (!["item", "post", "from", "to", "place"].includes(k)) errors.push(`${who}.${k} is not a side setting (item, post, from, to, place)`); const hasItem = typeof side.item === "string" && side.item.trim() !== ""; const hasPost = isObj(side.post); if (hasItem === hasPost) errors.push(`${who} needs exactly one of item (a post item's id) or post (a post's fields)`); if (hasItem && itemIds && !itemIds.has(side.item)) errors.push(`${who}.item: no post item ${q(side.item)} in the timeline`); if (hasPost && (typeof side.post.text !== "string" || !(side.post.handle || side.post.author))) errors.push(`${who}.post needs at least text and a handle or author`); if (!num(side.from) || side.from < 0) errors.push(`${who}.from must be seconds into the clip (0 or more)`); if (!num(side.to)) errors.push(`${who}.to must be seconds into the clip`); if (num(side.from) && num(side.to) && side.to - side.from < SIDE_MIN_SECONDS) errors.push(`${who} must be up at least ${SIDE_MIN_SECONDS} s (to − from)`); if (side.place !== undefined && !SIDE_PLACES.includes(side.place)) errors.push(`${who}.place must be one of ${SIDE_PLACES.join(", ")}`); return errors; } /** Every clip's `side`, against the timeline (an `item` names a post item in it). */ export function validateClipSides(manifest) { const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const itemIds = new Set(tl.filter((e) => e?.type === "post" && typeof e.id === "string").map((e) => e.id)); const errors = []; tl.forEach((e, i) => { if (e?.side === undefined) return; const who = `timeline[${i}] (${e?.id ?? "?"}).side`; if (e?.type !== "clip") errors.push(`${who}: only a clip carries a side post`); else errors.push(...sideErrors(e.side, who, { itemIds })); }); return errors; } /** The post a clip's side shows: its own `post`, else the post item it names (null when there is none). */ export function sidePostOf(entry, timeline = []) { const s = entry?.side; if (!isObj(s)) return null; if (isObj(s.post)) return { type: "post", id: `${entry.id}-side`, platform: "x", ...s.post }; if (typeof s.item === "string") return (timeline ?? []).find((e) => e?.type === "post" && e.id === s.item) ?? null; return null; } /** The side's span clamped to a clip `seconds` long, or null when none of it is inside. */ export function sideSpan(side, seconds) { if (!isObj(side) || !num(side.from) || !num(side.to)) return null; const from = Math.max(0, side.from); const to = Math.min(num(seconds) ? seconds : Infinity, side.to); return to - from >= 0.2 ? { from, to } : null; } /** All of the vertical format's checks. */ export const validateVerticalFormat = (manifest) => [...validateVerticalRender(manifest), ...validateDesktopRender(manifest), ...validateClipSides(manifest)]; // --------------------------------------------------------------------------- // THE DESKTOP CLIP (lane clip-kit, slice C): a clip of a take built 16:9 by the same per-clip builder as a short // (`umtool vertical --desktop`, a batch's `desktop` format) -- for X, which autoplays muted: the picture full frame // (no letterbox, no header), ONE thin source line on a small plate over it, the words lit as they are said along its // foot, a code in a corner only when asked. Its knobs are `render.desktop`; absent, the defaults below (the // "minimal chrome" look). A cut never renders desktop by itself: only a per-clip build asks for it. // // render.desktop { tag?, hook?, captions?: {size?, lines?}, safe?: {top?, bottom?, right?, left?}, loudness?, // maxSeconds?, qr?: false | true | {corner?: "br"|"bl"|"tr"|"tl", size?, links?} } // --------------------------------------------------------------------------- export const DESKTOP_WIDTH = 1920; export const DESKTOP_HEIGHT = 1080; export const DESKTOP_CAPTION_SIZES = Object.freeze(["m", "l", "xl"]); export const DESKTOP_QR_CORNERS = Object.freeze(["br", "bl", "tr", "tl"]); export const DESKTOP_QR_SIZE = Object.freeze({ min: 0.05, max: 0.2, default: 0.09 }); export const DESKTOP_SAFE_MAX = 0.25; export const DESKTOP_DEFAULTS = Object.freeze({ tag: true, hook: false, captions: Object.freeze({ size: "l", lines: 2 }), safe: Object.freeze({ top: 0.04, bottom: 0.08, right: 0.03, left: 0.03 }), loudness: -14, maxSeconds: 140, qr: false, }); export const DESKTOP_KEYS = Object.freeze(Object.keys(DESKTOP_DEFAULTS)); /** A desktop clip's knobs: `render.desktop` over the defaults. */ export function desktopKnobs(render) { const v = isObj(render?.desktop) ? render.desktop : {}; return { tag: typeof v.tag === "boolean" ? v.tag : DESKTOP_DEFAULTS.tag, hook: v.hook === undefined || v.hook === null ? DESKTOP_DEFAULTS.hook : v.hook, captions: { ...DESKTOP_DEFAULTS.captions, ...(isObj(v.captions) ? v.captions : {}) }, safe: { ...DESKTOP_DEFAULTS.safe, ...(isObj(v.safe) ? v.safe : {}) }, loudness: num(v.loudness) ? v.loudness : DESKTOP_DEFAULTS.loudness, maxSeconds: num(v.maxSeconds) ? v.maxSeconds : DESKTOP_DEFAULTS.maxSeconds, qr: v.qr === true || isObj(v.qr) ? v.qr : DESKTOP_DEFAULTS.qr, }; } /** Each thing wrong with `render.desktop` ([] when fine, or absent). */ export function validateDesktopRender(manifest) { const v = manifest?.render?.desktop; if (v === undefined || v === null) return []; if (!isObj(v)) return [`render.desktop must be an object of the desktop knobs (${DESKTOP_KEYS.join(", ")})`]; const errors = []; for (const k of Object.keys(v)) if (!DESKTOP_KEYS.includes(k)) errors.push(`render.desktop.${k} is not a desktop knob (${DESKTOP_KEYS.join(", ")})`); if (v.tag !== undefined && typeof v.tag !== "boolean") errors.push("render.desktop.tag must be true or false"); if (v.hook !== undefined && v.hook !== false) { if (isObj(v.hook)) { const t = v.hook.text; if (Object.keys(v.hook).some((k) => k !== "text") || typeof t !== "string" || !t.trim() || t.length > VERTICAL_HOOK_MAX) errors.push(`render.desktop.hook.text must be a line of 1–${VERTICAL_HOOK_MAX} characters`); } else if (!VERTICAL_HOOKS.includes(v.hook)) errors.push(`render.desktop.hook must be false, ${VERTICAL_HOOKS.map(q).join(", ")} or {text}`); } if (v.captions !== undefined) { if (!isObj(v.captions)) errors.push("render.desktop.captions must be {size?, lines?}"); else { for (const k of Object.keys(v.captions)) if (k !== "size" && k !== "lines") errors.push(`render.desktop.captions.${k} is not a caption knob (size, lines)`); if (v.captions.size !== undefined && !DESKTOP_CAPTION_SIZES.includes(v.captions.size)) errors.push(`render.desktop.captions.size must be one of ${DESKTOP_CAPTION_SIZES.join(", ")}`); if (v.captions.lines !== undefined && v.captions.lines !== 1 && v.captions.lines !== 2) errors.push("render.desktop.captions.lines must be 1 or 2"); } } if (v.safe !== undefined) { if (!isObj(v.safe)) errors.push("render.desktop.safe must be {top?, bottom?, right?, left?}"); else { for (const [k, x] of Object.entries(v.safe)) { if (!["top", "bottom", "right", "left"].includes(k)) errors.push(`render.desktop.safe.${k} is not an edge (top, bottom, right, left)`); else if (!num(x) || x < 0 || x > DESKTOP_SAFE_MAX) errors.push(`render.desktop.safe.${k} must be a fraction of the frame from 0 to ${DESKTOP_SAFE_MAX}`); } } } if (v.loudness !== undefined && !(num(v.loudness) && v.loudness >= -30 && v.loudness <= -8)) errors.push("render.desktop.loudness must be a LUFS target from -30 to -8"); if (v.maxSeconds !== undefined && !(num(v.maxSeconds) && v.maxSeconds >= 5 && v.maxSeconds <= 600)) errors.push("render.desktop.maxSeconds must be 5 to 600 seconds"); if (v.qr !== undefined && v.qr !== true && v.qr !== false) { if (!isObj(v.qr)) errors.push("render.desktop.qr is true, false or {corner?, size?, links?}"); else { for (const k of Object.keys(v.qr)) if (!VERTICAL_QR_KEYS.includes(k)) errors.push(`render.desktop.qr.${k} is not a key (${VERTICAL_QR_KEYS.join(", ")})`); if (v.qr.corner !== undefined && !DESKTOP_QR_CORNERS.includes(v.qr.corner)) errors.push(`render.desktop.qr.corner is one of ${DESKTOP_QR_CORNERS.join(", ")}`); if (v.qr.size !== undefined && !(num(v.qr.size) && v.qr.size >= DESKTOP_QR_SIZE.min && v.qr.size <= DESKTOP_QR_SIZE.max)) errors.push(`render.desktop.qr.size is ${DESKTOP_QR_SIZE.min}–${DESKTOP_QR_SIZE.max} of the frame's width`); if (v.qr.links !== undefined && !QR_LINKS.includes(v.qr.links)) errors.push(`render.desktop.qr.links is one of ${QR_LINKS.join(", ")}`); } } return errors; }