commit f447488a36287853c29d5d515fd3e4880b34e045
parent c8292375b3b5d8739e7c088bb14f1887dcfa6e5a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 20 Oct 2026 14:43:41 -0400
common: the look's rules move to common/lib/report/look.mjs; compositions declare their tunable params
applyLookPatch is updateRender's body, pure: umtool's writer, the build, the lint
and (next) the video assistant check a look with one function. report-to-video
look/room/transition re-export every moved name. fxParams.mjs declares the deck's,
the stats panel's and each effect's tunable params with their validators' bounds;
deck/stats/fx re-export their slice; fx-params.test.mjs holds each declaration to
validateChrome at its bounds and just past them.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
13 files changed, 763 insertions(+), 279 deletions(-)
diff --git a/common/lib/report/fxParams.d.mts b/common/lib/report/fxParams.d.mts
@@ -0,0 +1,24 @@
+// Types for ./fxParams.mjs (release 38 lane E): the compositions' declared params.
+
+export type ParamKind = "seconds" | "number" | "int" | "px" | "enum" | "bool" | "text";
+export type CompositionParam = {
+ readonly key: string;
+ readonly label: string;
+ readonly kind: ParamKind;
+ readonly min?: number;
+ readonly max?: number;
+ readonly values?: readonly string[];
+ readonly maxLength?: number;
+ readonly default: unknown;
+};
+type Render = Record<string, unknown> | null | undefined;
+
+export const COMPOSITION_PARAMS: Readonly<Record<string, readonly CompositionParam[]>>;
+export const COMPOSITION_IDS: readonly string[];
+export function compositionOn(render: Render, id: string): boolean;
+export function compositionsOn(render: Render): string[];
+export function settingsPathOf(id: string): string[];
+export function paramOf(id: string, key: string): CompositionParam | null;
+export function paramValue(render: Render, id: string, key: string): unknown;
+export function paramValueError(p: CompositionParam, value: unknown): string | null;
+export function chromeWithParam(render: Render, id: string, key: string, value: unknown): Record<string, unknown> | null;
diff --git a/common/lib/report/fxParams.mjs b/common/lib/report/fxParams.mjs
@@ -0,0 +1,176 @@
+// THE COMPOSITIONS' TUNABLE PARAMS (release 38 lane E): the HyperFrames
+// regions a report cut can carry (report-to-video deck.mjs, stats.mjs, fx.mjs)
+// declare here the settings a person -- or the video assistant -- may change
+// by name, each with its bounds. Only a DECLARED param can be the target of a
+// video-assist `fx` op; nothing else under `render.chrome` is reachable that
+// way, and never free HTML.
+//
+// composition id where its settings live on when
+// deck render.chrome.deck the deck is (chrome.engine "hyperframes", layout "deck")
+// stats render.chrome.stats the deck is, and chrome.stats is an object
+// fx.<effect> render.chrome.fx.<effect> that effect is an object (fx.mjs FX_KEYS)
+//
+// A param is `{ key, label, kind, min?, max?, values?, maxLength?, default }`:
+// `key` a dot path inside the composition's settings, `kind` one of seconds /
+// number / int / px / enum / bool / text. The bounds are the composition's own
+// validator's (deck.mjs validateChrome, stats.mjs validateStats, fx.mjs
+// validateFx) -- report-to-video's fx-params.test.mjs holds each declaration
+// to its validator, at both bounds and just past them, so the two cannot
+// drift. The writer (umtool updateChrome, validateChrome on the whole render)
+// still has the last word at Apply: a param whose value is fine alone but
+// clashes with another setting is refused there, with the validator's reason.
+//
+// The modules re-export their own slice (DECK_PARAMS, STATS_PARAMS,
+// FX_PARAMS). Settings that move the layout as a whole (the deck's height,
+// the footage scale, the QR's size, the pips' sizes) are left out: each is
+// bounded by another and is a Media-tab decision, not a tweak.
+//
+// PURE. Plain ESM with a .d.mts beside it.
+
+const P = (key, label, kind, more) => Object.freeze({ key, label, kind, ...more });
+const sec = (key, label, min, max, def) => P(key, label, "seconds", { min, max, default: def });
+const numP = (key, label, min, max, def) => P(key, label, "number", { min, max, default: def });
+const intP = (key, label, min, max, def) => P(key, label, "int", { min, max, default: def });
+const oneOf = (key, label, values, def) => P(key, label, "enum", { values: Object.freeze(values), default: def });
+const bool = (key, label, def) => P(key, label, "bool", { default: def });
+const text = (key, label, maxLength, def) => P(key, label, "text", { maxLength, default: def });
+
+const CORNERS = ["top-left", "top-right", "bottom-left", "bottom-right"];
+
+/** Every composition's declared params, by composition id. */
+export const COMPOSITION_PARAMS = Object.freeze({
+ deck: Object.freeze([
+ sec("motion.in", "the deck's slide in", 0, 2, 0.45),
+ sec("motion.out", "the deck's slide out", 0, 2, 0.3),
+ sec("motion.pip", "the timeline pip's move", 0, 3, 0.7),
+ numP("title.size", "the clip title's size", 24, 96, 54),
+ intP("title.maxChars", "the clip title's length", 10, 120, 48),
+ bool("qr.show", "the deck's QR code", true),
+ oneOf("subtitle.dateFormat", "the subtitle's date", ["long", "iso"], "long"),
+ oneOf("background", "the deck's background", ["panel", "flush"], "panel"),
+ oneOf("overCards", "the deck over cards", ["hide", "show"], "hide"),
+ sec("posts.seconds", "how long a post is up", 0.5, 10, 4),
+ sec("posts.hold", "the freeze under a post", 0, 10, 2.5),
+ ]),
+ stats: Object.freeze([
+ oneOf("position", "the stats panel's corner", CORNERS, "bottom-left"),
+ bool("name", "the stats panel's name", true),
+ ]),
+ "fx.kineticQuote": Object.freeze([
+ oneOf("position", "the kinetic quote's place", ["bottom", "top"], "bottom"),
+ numP("size", "the kinetic quote's size", 24, 96, 54),
+ intP("maxWords", "the kinetic quote's words a page", 3, 30, 12),
+ ]),
+ "fx.redact": Object.freeze([
+ oneOf("position", "the redaction's place", ["bottom", "top"], "bottom"),
+ numP("size", "the redaction's size", 24, 96, 44),
+ intP("maxWords", "the redaction's words a page", 3, 30, 14),
+ ]),
+ "fx.odometer": Object.freeze([
+ oneOf("position", "the odometer's corner", CORNERS, "top-right"),
+ text("label", "the odometer's label", 24, "times"),
+ oneOf("at", "when the odometer rolls", ["phrase", "start"], "phrase"),
+ ]),
+ "fx.scrubber": Object.freeze([
+ oneOf("position", "the date rail's edge", ["top", "bottom"], "top"),
+ bool("thumbs", "the date rail's thumbnails", true),
+ ]),
+ "fx.glitch": Object.freeze([
+ oneOf("on", "where the glitch tears", ["year", "every"], "year"),
+ sec("seconds", "the glitch's length", 0.2, 1.5, 0.5),
+ bool("stamp", "the glitch's date stamp", true),
+ ]),
+ "fx.thenNow": Object.freeze([
+ sec("seconds", "the THEN/NOW wipe's length", 0.3, 2, 0.6),
+ oneOf("dates", "the THEN/NOW dates", ["date", "year"], "date"),
+ ]),
+ "fx.receipts": Object.freeze([
+ oneOf("position", "the receipts' side", ["right", "left"], "right"),
+ numP("width", "the receipts' width (of the footage)", 0.2, 0.6, 0.36),
+ ]),
+ "fx.zoom": Object.freeze([numP("width", "the zoom card's width (of the footage)", 0.3, 0.9, 0.56)]),
+ "fx.punchIn": Object.freeze([
+ numP("scale", "the punch-in's scale", 1.05, 2, 1.2),
+ sec("hold", "the punch-in's hold", 0.2, 6, 1.4),
+ oneOf("anchor", "where the punch-in aims", ["upper", "center"], "upper"),
+ bool("auto", "punch in on laughs", true),
+ ]),
+ "fx.whip": Object.freeze([oneOf("on", "where the whip pans", ["every", "year"], "every")]),
+});
+
+export const COMPOSITION_IDS = Object.freeze(Object.keys(COMPOSITION_PARAMS));
+
+const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
+
+const deckOnOf = (render) => {
+ const c = render?.chrome;
+ return isObj(c) && c.engine === "hyperframes" && c.layout === "deck";
+};
+
+/** Is this composition drawn by the cut? */
+export function compositionOn(render, id) {
+ if (!COMPOSITION_IDS.includes(id)) return false;
+ if (id === "deck") return deckOnOf(render);
+ if (id === "stats") return deckOnOf(render) && isObj(render.chrome.stats);
+ const fx = render?.chrome?.fx;
+ return isObj(fx) && isObj(fx[id.slice(3)]);
+}
+
+/** The compositions this cut draws, in COMPOSITION_IDS order. */
+export const compositionsOn = (render) => COMPOSITION_IDS.filter((id) => compositionOn(render, id));
+
+/** Where a composition's settings live under `render.chrome`, as a path. */
+export const settingsPathOf = (id) => (id === "deck" ? ["deck"] : id === "stats" ? ["stats"] : ["fx", id.slice(3)]);
+
+/** The declared param `key` of composition `id`, or null. */
+export function paramOf(id, key) {
+ return (COMPOSITION_PARAMS[id] ?? []).find((p) => p.key === key) ?? null;
+}
+
+const at = (o, keys) => keys.reduce((v, k) => (isObj(v) ? v[k] : undefined), o);
+
+/** A param's value in this render: as written, else its default. */
+export function paramValue(render, id, key) {
+ const p = paramOf(id, key);
+ if (!p) return undefined;
+ const v = at(render?.chrome, [...settingsPathOf(id), ...key.split(".")]);
+ return v === undefined || v === null ? p.default : v;
+}
+
+/** Why `value` is not a value of the declared param (null: it is). */
+export function paramValueError(p, value) {
+ const fin = typeof value === "number" && Number.isFinite(value);
+ switch (p.kind) {
+ case "seconds":
+ case "number":
+ case "px":
+ return fin && value >= p.min && value <= p.max ? null : `${p.label} is ${p.kind === "seconds" ? "seconds" : "a number"} from ${p.min} to ${p.max}`;
+ case "int":
+ return fin && Number.isInteger(value) && value >= p.min && value <= p.max ? null : `${p.label} is a whole number from ${p.min} to ${p.max}`;
+ case "enum":
+ return p.values.includes(value) ? null : `${p.label} is one of ${p.values.join(", ")}`;
+ case "bool":
+ return typeof value === "boolean" ? null : `${p.label} is true or false`;
+ case "text":
+ return typeof value === "string" && value.trim().length <= p.maxLength ? null : `${p.label} is a text of at most ${p.maxLength} characters`;
+ default:
+ return `${p.label} cannot be set here`;
+ }
+}
+
+/**
+ * `render.chrome` with one declared param set (a copy; null when the
+ * composition is not drawn by this cut or the param is not declared). The
+ * composition writer (updateChrome) validates the result as a whole.
+ */
+export function chromeWithParam(render, id, key, value) {
+ if (!compositionOn(render, id) || !paramOf(id, key)) return null;
+ const chrome = structuredClone(render.chrome);
+ let o = chrome;
+ for (const k of [...settingsPathOf(id), ...key.split(".").slice(0, -1)]) {
+ if (!isObj(o[k])) o[k] = {};
+ o = o[k];
+ }
+ o[key.split(".").at(-1)] = value;
+ return chrome;
+}
diff --git a/common/lib/report/look.d.mts b/common/lib/report/look.d.mts
@@ -0,0 +1,48 @@
+// Types for ./look.mjs (release 38 lane E): the look's rules — one set of
+// checks for umtool's updateRender, the build and the video assistant.
+
+type Manifest = { render?: Record<string, unknown> | null; timeline?: unknown[] } & Record<string, unknown>;
+type Render = Record<string, unknown> | null | undefined;
+
+export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide";
+export const LOOK_KEYS: readonly LookKey[];
+export const BAND_MAX: number;
+export const TRANSITION_MAX: number;
+export const TRANSITION_DEFAULT: number;
+
+export const TRANSITION_STYLES: readonly string[];
+export function transitionStyleOf(render: Render): string;
+export type Slide = { travel: number; blur: number; grain: number };
+export const SLIDE_DEFAULTS: Readonly<Slide>;
+export const SLIDE_BOUNDS: Readonly<Record<keyof Slide, readonly [number, number]>>;
+export function slideOf(render: Render): Slide;
+export function validateTransitionStyle(manifest: unknown): string[];
+export function validateSlide(manifest: unknown): string[];
+
+export const ROOM: Readonly<{ minGap: number; maxS: number; fade: number; pad: number; detectDb: number; detectD: number }>;
+export const ROOM_EDGES: readonly ("tail" | "head")[];
+export const ROOM_BOUNDS: Readonly<{ minGap: readonly [number, number]; maxS: readonly [number, number] }>;
+export function roomOn(render: Render): boolean;
+export function clipRoom(entry: unknown, render: Render): { tail: boolean; head: boolean; minGap: number; maxS: number } | null;
+export function validateRoom(manifest: unknown): string[];
+
+export const CAPTION_STYLES: readonly string[];
+export const CAPTION_SIZES: readonly string[];
+export const CAPTION_LABEL_MAX: number;
+export const LOUDNESS_MIN: number;
+export const LOUDNESS_MAX: number;
+export const VERTICAL_RATIO: number;
+export const VERTICAL_TOLERANCE: number;
+export const DEFAULT_SOURCE_ASPECT: number;
+export function captionsOn(render: Render): boolean;
+export function loudnessOn(render: Render): boolean;
+export function loudnessTargetOf(render: Render): number | null;
+export function validateCaptions(manifest: unknown): string[];
+export function validateLoudness(manifest: unknown): string[];
+export function verticalErrors(v: unknown, who?: string): string[];
+export function validateVertical(manifest: unknown): string[];
+export function validateLook(manifest: unknown): string[];
+
+export function lookErrors(manifest: unknown): string[];
+export function applyLookPatch(manifest: Manifest, patch: Record<string, unknown>): { render: Record<string, unknown>; errors: string[] };
+export function lookOf(render: unknown): Record<string, unknown>;
diff --git a/common/lib/report/look.mjs b/common/lib/report/look.mjs
@@ -0,0 +1,350 @@
+// THE LOOK'S RULES (release 38 lane E): the render keys a person sets for a
+// cut with no deck -- `headerHeight`, `footerHeight`, `qr`, `transition`,
+// `transitionStyle`, `loudness`, `captions`, `room`, `slide` -- and the ONE set
+// of checks every writer and reader of them runs:
+//
+// umtool's updateRender (lib/report/manifest.mjs: applyLookPatch, then lookErrors)
+// the build and the lint (report-to-video look.mjs / room.mjs / transition.mjs re-export these)
+// the video assistant (./videoAssistOps.mjs: a proposed look op is checked here first)
+//
+// They lived in report-to-video until release 38 moved them here so the
+// editor's `video-assist` task (which cannot import umtool) refuses exactly
+// what the writer and the build refuse. Moved, not copied: the render modules
+// re-export every name, so nothing that imported them changed.
+//
+// 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);
+const round2 = (n) => Number(Number(n).toFixed(2));
+
+/** The render keys the Look panel writes, in its order. */
+export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide"]);
+
+/** `headerHeight` / `footerHeight`: whole pixels, 0 (off) to this. */
+export const BAND_MAX = 240;
+/** `transition`: seconds, 0 (a hard cut) to this. */
+export const TRANSITION_MAX = 3;
+/** The join's length when a cut sets none (the build's default). */
+export const TRANSITION_DEFAULT = 0.5;
+
+// ---------------------------------------------------------------------------
+// The join's style (`render.transitionStyle`) and the blur slide's knobs
+// (`render.slide`) -- report-to-video/transition.mjs draws them.
+// ---------------------------------------------------------------------------
+
+export const TRANSITION_STYLES = Object.freeze(["fade", "fadeblack", "fadewhite", "dissolve", "blurslide"]);
+
+/** The style a plain join uses (`render.transitionStyle`, default "fade"). */
+export const transitionStyleOf = (render) => render?.transitionStyle ?? "fade";
+
+// The push's knobs (`render.slide`): travel = fraction of the width the
+// pictures move; blur = motion-smear strength (0 none, 1 = a frame's travel);
+// grain = noise strength on the seam's frames (0 none).
+export const SLIDE_DEFAULTS = Object.freeze({ travel: 0.08, blur: 0.5, grain: 2 });
+export const SLIDE_BOUNDS = Object.freeze({ travel: Object.freeze([0, 0.5]), blur: Object.freeze([0, 2]), grain: Object.freeze([0, 20]) });
+
+/** The push's knobs, the defaults filled in. */
+export function slideOf(render) {
+ const s = render?.slide && typeof render.slide === "object" ? render.slide : {};
+ const out = {};
+ for (const k of Object.keys(SLIDE_DEFAULTS)) out[k] = Number.isFinite(s[k]) ? s[k] : SLIDE_DEFAULTS[k];
+ return out;
+}
+
+/** @param {{ render?: { transitionStyle?: unknown } }} manifest */
+export function validateTransitionStyle(manifest) {
+ const s = manifest?.render?.transitionStyle;
+ const slide = validateSlide(manifest);
+ if (s === undefined || s === null) return slide;
+ return typeof s === "string" && TRANSITION_STYLES.includes(s)
+ ? slide
+ : [`render.transitionStyle: ${JSON.stringify(s)} is not one of ${TRANSITION_STYLES.join(", ")}`, ...slide];
+}
+
+/** `render.slide`: absent, or an object of the push's knobs within bounds. */
+export function validateSlide(manifest) {
+ const s = manifest?.render?.slide;
+ if (s === undefined || s === null) return [];
+ if (typeof s !== "object" || Array.isArray(s)) return ["render.slide must be an object {travel?, blur?, grain?}"];
+ const errs = [];
+ for (const [k, v] of Object.entries(s)) {
+ const b = SLIDE_BOUNDS[k];
+ if (!b) errs.push(`render.slide.${k} is not a key (travel, blur, grain)`);
+ else if (!Number.isFinite(v) || v < b[0] || v > b[1]) errs.push(`render.slide.${k} must be a number from ${b[0]} to ${b[1]}`);
+ }
+ return errs;
+}
+
+// ---------------------------------------------------------------------------
+// Room at a clip's edges (`render.room`, a clip's `room`) -- report-to-video/
+// room.mjs says what it does to the sound and the picture.
+// ---------------------------------------------------------------------------
+
+export const ROOM = Object.freeze({
+ /** A gap between two words this long (s) is the silence the sound stops at. */
+ minGap: 0.35,
+ /** The sound never runs more than this (s) past the cut's end. */
+ maxS: 2.5,
+ /** The fade at the silence point, and the fade in at a muted head (s). */
+ fade: 0.06,
+ /** Muted picture past D, so the fade is done before the join begins (s). */
+ pad: 0.1,
+ /** silencedetect, when there are no words: noise floor (dB) and least length (s). */
+ detectDb: -35,
+ detectD: 0.3,
+});
+export const ROOM_EDGES = Object.freeze(["tail", "head"]);
+/** `render.room.minGap` and `render.room.maxS`: seconds, within these. */
+export const ROOM_BOUNDS = Object.freeze({ minGap: Object.freeze([0.1, 2]), maxS: Object.freeze([0, 10]) });
+const MIN_GAP = ROOM_BOUNDS.minGap;
+const MAX_S = ROOM_BOUNDS.maxS;
+
+/** Does the cut's render block turn room on for either edge? */
+export const roomOn = (render) => isObj(render?.room) && (render.room.tail === true || render.room.head === true);
+
+/**
+ * One clip's room: `{tail, head, minGap, maxS}` with at least one edge on, or
+ * null. The clip's `room` (false, or per-edge booleans) beats the cut's.
+ */
+export function clipRoom(entry, render) {
+ const r = isObj(render?.room) ? render.room : null;
+ const c = entry?.room;
+ if (c === false) return null;
+ const edge = (k) => (isObj(c) && typeof c[k] === "boolean" ? c[k] : r?.[k] === true);
+ const tail = edge("tail");
+ const head = edge("head");
+ if (!tail && !head) return null;
+ return {
+ tail,
+ head,
+ minGap: num(r?.minGap) ? r.minGap : ROOM.minGap,
+ maxS: num(r?.maxS) ? r.maxS : ROOM.maxS,
+ };
+}
+
+/** `render.room` and every clip's `room`: each problem in a sentence naming the key. */
+export function validateRoom(manifest) {
+ const render = manifest?.render ?? {};
+ const errors = [];
+ const room = render.room;
+ if (room !== undefined && room !== null) {
+ if (!isObj(room)) errors.push(`render.room must be an object ({tail: true, head: true}) or absent, not ${q(room)}`);
+ else {
+ for (const k of Object.keys(room)) {
+ if (!["tail", "head", "minGap", "maxS"].includes(k)) errors.push(`render.room.${k} is not a setting here (tail, head, minGap, maxS)`);
+ }
+ for (const k of ROOM_EDGES) {
+ if (room[k] !== undefined && typeof room[k] !== "boolean") errors.push(`render.room.${k} must be true or false, not ${q(room[k])}`);
+ }
+ if (room.minGap !== undefined && (!num(room.minGap) || room.minGap < MIN_GAP[0] || room.minGap > MIN_GAP[1])) {
+ errors.push(`render.room.minGap must be seconds from ${MIN_GAP[0]} to ${MIN_GAP[1]}, not ${q(room.minGap)}`);
+ }
+ if (room.maxS !== undefined && (!num(room.maxS) || room.maxS < MAX_S[0] || room.maxS > MAX_S[1])) {
+ errors.push(`render.room.maxS must be seconds from ${MAX_S[0]} to ${MAX_S[1]}, not ${q(room.maxS)}`);
+ }
+ if (render.montage !== undefined && render.montage !== null) errors.push("render.room does not combine with render.montage (a montage cuts to its phrases)");
+ }
+ }
+ (manifest?.timeline ?? []).forEach((e, i) => {
+ if (e?.room === undefined) return;
+ const who = `timeline[${i}] (${e?.id ?? "?"}).room`;
+ if (e?.type !== "clip") errors.push(`${who}: only a clip has room at its edges`);
+ else if (e.room === false || e.room === null) return;
+ else if (!isObj(e.room)) errors.push(`${who} must be false or {tail?, head?}, not ${q(e.room)}`);
+ else {
+ for (const [k, v] of Object.entries(e.room)) {
+ if (!ROOM_EDGES.includes(k)) errors.push(`${who}.${k} is not a setting here (tail, head)`);
+ else if (typeof v !== "boolean") errors.push(`${who}.${k} must be true or false, not ${q(v)}`);
+ }
+ }
+ });
+ return errors;
+}
+
+// ---------------------------------------------------------------------------
+// Captions, loudness and a clip's vertical crop -- report-to-video/look.mjs
+// draws them.
+// ---------------------------------------------------------------------------
+
+export const CAPTION_STYLES = Object.freeze(["speakers"]);
+export const CAPTION_SIZES = Object.freeze(["m", "l"]);
+export const CAPTION_LABEL_MAX = 40;
+
+export const LOUDNESS_MIN = -30;
+export const LOUDNESS_MAX = -8;
+
+export const VERTICAL_RATIO = 9 / 16;
+/** How far a crop's shape may be from 9:16 (relative): the build fits it exactly. */
+export const VERTICAL_TOLERANCE = 0.03;
+export const DEFAULT_SOURCE_ASPECT = 16 / 9;
+
+export const captionsOn = (render) => isObj(render?.captions);
+export const loudnessOn = (render) => isObj(render?.loudness) && num(render.loudness.target);
+/** The target in LUFS, or null when the cut sets none. */
+export const loudnessTargetOf = (render) => (loudnessOn(render) ? render.loudness.target : null);
+
+/** `render.captions`: its keys and values, and what it does not combine with. */
+export function validateCaptions(manifest) {
+ const render = manifest?.render ?? {};
+ const c = render.captions;
+ if (c === undefined || c === null) return [];
+ if (!isObj(c)) return [`render.captions must be an object ({style: "speakers"}) or absent, not ${q(c)}`];
+ const errors = [];
+ for (const k of Object.keys(c)) {
+ if (!["style", "labels", "size"].includes(k)) errors.push(`render.captions.${k} is not a setting here (the settings are style, labels, size)`);
+ }
+ if (!CAPTION_STYLES.includes(c.style)) errors.push(`render.captions.style must be "speakers", not ${q(c.style)}`);
+ if (c.size !== undefined && !CAPTION_SIZES.includes(c.size)) errors.push(`render.captions.size must be "m" or "l", not ${q(c.size)}`);
+ if (c.labels !== undefined && c.labels !== null) {
+ if (!isObj(c.labels)) errors.push(`render.captions.labels must be an object ({host, subject}), not ${q(c.labels)}`);
+ else {
+ for (const [k, v] of Object.entries(c.labels)) {
+ if (k !== "host" && k !== "subject") errors.push(`render.captions.labels.${k} is not a role here (host, subject)`);
+ else if (v !== null && (typeof v !== "string" || v.length > CAPTION_LABEL_MAX)) {
+ errors.push(`render.captions.labels.${k} must be a short text (up to ${CAPTION_LABEL_MAX} characters), or null`);
+ }
+ }
+ }
+ }
+ if (isObj(render.chrome)) errors.push("render.captions does not combine with render.chrome (the deck draws its own words: render.chrome.fx.kineticQuote)");
+ if (render.montage !== undefined && render.montage !== null) errors.push("render.captions does not combine with render.montage (a montage re-times its clips)");
+ return errors;
+}
+
+/** `render.loudness`: `{target}` in LUFS. */
+export function validateLoudness(manifest) {
+ const render = manifest?.render ?? {};
+ const l = render.loudness;
+ if (l === undefined || l === null) return [];
+ if (!isObj(l)) return [`render.loudness must be an object ({target: -16}) or absent, not ${q(l)}`];
+ const errors = [];
+ for (const k of Object.keys(l)) if (k !== "target") errors.push(`render.loudness.${k} is not a setting here (the setting is target)`);
+ if (!num(l.target) || l.target < LOUDNESS_MIN || l.target > LOUDNESS_MAX) {
+ errors.push(`render.loudness.target must be a number from ${LOUDNESS_MIN} to ${LOUDNESS_MAX} LUFS, not ${q(l.target)}`);
+ }
+ if (render.montage !== undefined && render.montage !== null) errors.push("render.loudness does not combine with render.montage (a montage levels with render.montage.loudness)");
+ return errors;
+}
+
+/** One clip's `vertical` (null when it has none): its errors, prefixed by `who`. */
+export function verticalErrors(v, who = "vertical") {
+ if (v === undefined || v === null) return [];
+ if (!isObj(v)) return [`${who} must be an object ({crop: [x, y, w, h]}), not ${q(v)}`];
+ const errors = [];
+ for (const k of Object.keys(v)) if (k !== "crop" && k !== "aspect") errors.push(`${who}.${k} is not a setting here (crop, aspect)`);
+ if (v.aspect !== undefined && (!num(v.aspect) || v.aspect <= 0.2 || v.aspect > 5)) {
+ errors.push(`${who}.aspect must be the source's width / height (a number from 0.2 to 5), not ${q(v.aspect)}`);
+ }
+ const c = v.crop;
+ if (!Array.isArray(c) || c.length !== 4 || !c.every(num)) {
+ errors.push(`${who}.crop must be [x, y, w, h], four fractions of the source picture`);
+ return errors;
+ }
+ const [x, y, w, h] = c;
+ const E = 1e-3;
+ if (w <= 0 || h <= 0) errors.push(`${who}.crop's width and height must be above 0`);
+ if (x < -E || y < -E || x + w > 1 + E || y + h > 1 + E) errors.push(`${who}.crop must lie inside the picture (each of x, y, x + w, y + h from 0 to 1)`);
+ if (w > 0 && h > 0) {
+ const aspect = num(v.aspect) ? v.aspect : DEFAULT_SOURCE_ASPECT;
+ const shape = (w * aspect) / h;
+ if (Math.abs(shape / VERTICAL_RATIO - 1) > VERTICAL_TOLERANCE) {
+ errors.push(`${who}.crop must be 9:16 on the source (w × aspect / h ≈ 0.5625; this one is ${shape.toFixed(4)})`);
+ }
+ }
+ return errors;
+}
+
+/** Every clip's `vertical`. */
+export function validateVertical(manifest) {
+ const errors = [];
+ (manifest?.timeline ?? []).forEach((e, i) => {
+ if (e?.vertical === undefined) return;
+ const who = `timeline[${i}] (${e?.id ?? "?"}).vertical`;
+ if (e?.type !== "clip") errors.push(`${who}: only a clip has a vertical crop`);
+ else errors.push(...verticalErrors(e.vertical, who));
+ });
+ return errors;
+}
+
+/** All of the look's keys: the build's validators and the lint call this. */
+export function validateLook(manifest) {
+ // render.room and a clip's room (release 36 lane E) are part of the look.
+ return [...validateCaptions(manifest), ...validateLoudness(manifest), ...validateVertical(manifest), ...validateRoom(manifest)];
+}
+
+// ---------------------------------------------------------------------------
+// A patch of the look, applied: what updateRender writes, and what the video
+// assistant checks a proposed op against before anything is written.
+// ---------------------------------------------------------------------------
+
+/** Every reason this manifest's look cannot be built (the join's style and the slide, then the rest). */
+export const lookErrors = (manifest) => [...validateTransitionStyle(manifest), ...validateLook(manifest)];
+
+/**
+ * A patch of LOOK_KEYS applied to a render block: `null` removes a key (the
+ * build's default again); `qr: true` turns the code back on (removes a
+ * `false`; an object of settings is kept), `qr: false` turns it off; the
+ * heights and the join's length are checked here, everything else by the
+ * build's own validators against the manifest as it would be.
+ *
+ * Pure: returns `{ render, errors }` -- the new render block (a copy) and
+ * every sentence that refuses it (empty: it can be written).
+ *
+ * @param {{ render?: Record<string, unknown>, timeline?: unknown[] } & Record<string, unknown>} manifest
+ * @param {Record<string, unknown>} patch
+ * @returns {{ render: Record<string, unknown>, errors: string[] }}
+ */
+export function applyLookPatch(manifest, patch) {
+ const base = isObj(manifest?.render) ? manifest.render : {};
+ if (!isObj(patch)) return { render: { ...base }, errors: ["the patch must be an object of render keys"] };
+ const errors = [];
+ for (const k of Object.keys(patch)) {
+ if (k === "chrome") errors.push("render.chrome is the deck's: set it from the deck's settings (updateChrome), not here");
+ else if (!LOOK_KEYS.includes(k)) errors.push(`render.${k} is not a look setting (${LOOK_KEYS.join(", ")})`);
+ }
+ if (errors.length) return { render: { ...base }, errors };
+ const render = { ...base };
+ for (const [k, v] of Object.entries(patch)) {
+ if (v === null) {
+ delete render[k];
+ continue;
+ }
+ switch (k) {
+ case "headerHeight":
+ case "footerHeight":
+ if (!(Number.isInteger(v) && v >= 0 && v <= BAND_MAX)) errors.push(`render.${k} must be a whole number of pixels from 0 to ${BAND_MAX}`);
+ else render[k] = v;
+ break;
+ case "qr":
+ if (v === false) render.qr = false;
+ else if (v === true) {
+ if (render.qr === false) delete render.qr;
+ } else errors.push("render.qr must be true (on) or false (off)");
+ break;
+ case "transition":
+ if (typeof v !== "number" || !Number.isFinite(v) || v < 0 || v > TRANSITION_MAX) errors.push(`render.transition must be a number of seconds from 0 (a hard cut) to ${TRANSITION_MAX}`);
+ else render.transition = round2(v);
+ break;
+ case "transitionStyle":
+ if (typeof v !== "string" || !TRANSITION_STYLES.includes(v)) errors.push(`render.transitionStyle must be one of ${TRANSITION_STYLES.join(", ")}`);
+ else render.transitionStyle = v;
+ break;
+ default:
+ // loudness, captions, room, slide: stored as given; the build's validators below say what is wrong.
+ render[k] = v;
+ }
+ }
+ errors.push(...lookErrors({ ...manifest, render }));
+ return { render, errors };
+}
+
+/** The look keys of a render block as written (absent keys left out). */
+export function lookOf(render) {
+ const r = isObj(render) ? render : {};
+ /** @type {Record<string, unknown>} */
+ const out = {};
+ for (const k of LOOK_KEYS) if (r[k] !== undefined) out[k] = r[k];
+ return out;
+}
diff --git a/common/package.json b/common/package.json
@@ -48,6 +48,10 @@
"./lib/montage/voiceMatch.mjs": "./lib/montage/voiceMatch.mjs",
"./lib/ports.mjs": "./lib/ports.mjs",
"./lib/report/drafted.mjs": "./lib/report/drafted.mjs",
+ "./lib/report/look.mjs": "./lib/report/look.mjs",
+ "./lib/report/fxParams.mjs": "./lib/report/fxParams.mjs",
+ "./lib/report/videoAssistOps.mjs": "./lib/report/videoAssistOps.mjs",
+ "./lib/report/videoAssistProposals.mjs": "./lib/report/videoAssistProposals.mjs",
"./lib/report/respellManifest.mjs": "./lib/report/respellManifest.mjs",
"./lib/report/panels.mjs": "./lib/report/panels.mjs",
"./lib/report/social.mjs": "./lib/report/social.mjs",
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -33,9 +33,9 @@ import { isCalendarDate } from "umtool-report-to-video/attribution";
import { normalizeOnscreen, validateChrome, validatePosts, validateTeaser, validateTeasers } from "umtool-report-to-video/deck";
import { validateThreadEntries } from "yt-dlp-transcript-common/lib/report/panels.mjs";
import { validateAssist } from "yt-dlp-transcript-common/lib/clips/assist.mjs";
-import { validateLook, verticalErrors } from "umtool-report-to-video/look";
+import { verticalErrors } from "umtool-report-to-video/look";
+import { LOOK_KEYS, applyLookPatch, lookOf } from "yt-dlp-transcript-common/lib/report/look.mjs";
import { validateRoom } from "umtool-report-to-video/room";
-import { TRANSITION_STYLES, validateTransitionStyle } from "umtool-report-to-video/transition";
import { applySectionEnter } from "./sections.mjs";
import { normalizeClaim, validateClaims } from "umtool-report-to-video/factcheck";
import { validateNarration } from "umtool-report-to-video/narration";
@@ -936,17 +936,10 @@ export class ChromeRefused extends Error {
// checks against the render as it will be, then written atomically.
// ---------------------------------------------------------------------------
-/** The render keys the Look panel writes, in its order. */
-export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide"]);
-
-/** The look keys of a render block as written (absent keys left out). */
-export function lookOf(render) {
- const r = isObj(render) ? render : {};
- /** @type {Record<string, unknown>} */
- const out = {};
- for (const k of LOOK_KEYS) if (r[k] !== undefined) out[k] = r[k];
- return out;
-}
+// LOOK_KEYS, lookOf and the patch's rules are the look's (common
+// lib/report/look.mjs, release 38): the video assistant checks a proposed op
+// with the same function this writer writes with.
+export { LOOK_KEYS, lookOf };
/** The build's sentences for a refused look, thrown whole so a route can return each one. */
export class RenderRefused extends Error {
@@ -958,12 +951,12 @@ export class RenderRefused extends Error {
}
}
-const intIn = (v, lo, hi) => Number.isInteger(v) && v >= lo && v <= hi;
-
/**
* Patch the look. Each key of `patch` is one of LOOK_KEYS; `null` removes the
* key (the build's default again). `qr: true` turns the code back on (removes
* a `false`; an object of settings is kept), `qr: false` turns it off.
+ * The rules are applyLookPatch's (common lib/report/look.mjs), against the
+ * manifest as it is inside the lock.
*
* @param {string} dir
* @param {Record<string, unknown>} patch
@@ -972,49 +965,16 @@ const intIn = (v, lo, hi) => Number.isInteger(v) && v >= lo && v <= hi;
*/
export async function updateRender(dir, patch, { token = null } = {}) {
if (!isObj(patch)) throw new RenderRefused(["the patch must be an object of render keys"]);
- const errors = [];
- for (const k of Object.keys(patch)) {
- if (k === "chrome") errors.push("render.chrome is the deck's: set it from the deck's settings (updateChrome), not here");
- else if (!LOOK_KEYS.includes(k)) errors.push(`render.${k} is not a look setting (${LOOK_KEYS.join(", ")})`);
+ {
+ // The keys alone, before the lock: a patch naming no look key is refused without reading the file.
+ const keys = applyLookPatch({}, Object.fromEntries(Object.keys(patch).map((k) => [k, null])));
+ if (keys.errors.length) throw new RenderRefused(keys.errors);
}
- if (errors.length) throw new RenderRefused(errors);
return withManifestLock(async () => {
const current = await manifestToken(dir);
if (token !== null && current !== token) throw new StaleToken(token, current);
const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8"));
- const render = { ...(isObj(manifest.render) ? manifest.render : {}) };
- for (const [k, v] of Object.entries(patch)) {
- if (v === null) {
- delete render[k];
- continue;
- }
- switch (k) {
- case "headerHeight":
- case "footerHeight":
- if (!intIn(v, 0, 240)) errors.push(`render.${k} must be a whole number of pixels from 0 to 240`);
- else render[k] = v;
- break;
- case "qr":
- if (v === false) render.qr = false;
- else if (v === true) {
- if (render.qr === false) delete render.qr;
- } else errors.push("render.qr must be true (on) or false (off)");
- break;
- case "transition":
- if (typeof v !== "number" || !Number.isFinite(v) || v < 0 || v > 3) errors.push("render.transition must be a number of seconds from 0 (a hard cut) to 3");
- else render.transition = round2(v);
- break;
- case "transitionStyle":
- if (typeof v !== "string" || !TRANSITION_STYLES.includes(v)) errors.push(`render.transitionStyle must be one of ${TRANSITION_STYLES.join(", ")}`);
- else render.transitionStyle = v;
- break;
- default:
- // loudness, captions, room: stored as given; the build's validators below say what is wrong.
- render[k] = v;
- }
- }
- const next = { ...manifest, render };
- errors.push(...validateTransitionStyle(next), ...validateLook(next));
+ const { render, errors } = applyLookPatch(manifest, patch);
if (errors.length) throw new RenderRefused(errors);
manifest.render = render;
const nextToken = await writeManifestAtomic(dir, manifest);
diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs
@@ -15,6 +15,7 @@
// No ffmpeg, no fs, no network. If a function here needs one, it belongs in
// build-video.mjs or compose-chrome.mjs instead.
import { createHash } from "node:crypto";
+import { COMPOSITION_PARAMS } from "yt-dlp-transcript-common/lib/report/fxParams.mjs";
import { attributionParts, deckSubtitle } from "./attribution.mjs";
import {
@@ -74,6 +75,14 @@ export const DECK_DEFAULTS = Object.freeze({
}),
});
+/**
+ * The deck's TUNABLE params (release 38): the settings the video assistant's
+ * `fx` op may set by name, each with the bounds validateChrome holds it to
+ * (declared in common lib/report/fxParams.mjs; fx-params.test.mjs keeps the
+ * two in step).
+ */
+export const DECK_PARAMS = COMPOSITION_PARAMS.deck;
+
/** Where a clip's deck QR links (`qr.links`): the archive at the clip, or the original. */
export const QR_LINKS = Object.freeze(["site", "original"]);
diff --git a/umtool/report-to-video/fx-params.test.mjs b/umtool/report-to-video/fx-params.test.mjs
@@ -0,0 +1,79 @@
+// The compositions' declared params (release 38 lane E, common
+// lib/report/fxParams.mjs) held to the validators that build them: every
+// declared param is accepted at its bounds and its default and refused just
+// past them, so a declaration cannot promise the video assistant a value the
+// deck's own check refuses.
+//
+// Run with: pnpm test:scripts
+import assert from "node:assert/strict";
+import test from "node:test";
+import { COMPOSITION_PARAMS, chromeWithParam, compositionOn } from "yt-dlp-transcript-common/lib/report/fxParams.mjs";
+import { DECK_PARAMS, validateChrome } from "./deck.mjs";
+import { STATS_PARAMS } from "./stats.mjs";
+import { FX_KEYS, FX_PARAMS } from "./fx.mjs";
+
+// Each composition on, with the one setting validateChrome needs beside it.
+const ON = {
+ deck: {},
+ stats: { stats: {} },
+ "fx.kineticQuote": { fx: { kineticQuote: {} } },
+ "fx.redact": { fx: { redact: {} } },
+ "fx.odometer": { fx: { odometer: {} } },
+ "fx.scrubber": { fx: { scrubber: {} } },
+ "fx.glitch": { fx: { glitch: {} } },
+ "fx.thenNow": { fx: { thenNow: { pairs: [{ then: "c1", now: "c2" }] } } },
+ "fx.receipts": { fx: { receipts: {} } },
+ "fx.zoom": { fx: { zoom: {} } },
+ "fx.punchIn": { fx: { punchIn: {} } },
+ "fx.whip": { fx: { whip: {} } },
+};
+const renderOf = (id) => ({ width: 1920, height: 1080, fps: 30, transition: 0.5, chrome: { engine: "hyperframes", layout: "deck", deck: {}, ...ON[id] } });
+const errorsWith = (id, key, value) => {
+ const render = renderOf(id);
+ const chrome = chromeWithParam(render, id, key, value);
+ assert.ok(chrome, `${id}.${key}: chromeWithParam gave nothing`);
+ const { chrome: _c, ...rest } = render;
+ return validateChrome(chrome, rest);
+};
+
+test("the modules re-export their slice of the declarations", () => {
+ assert.equal(DECK_PARAMS, COMPOSITION_PARAMS.deck);
+ assert.equal(STATS_PARAMS, COMPOSITION_PARAMS.stats);
+ assert.deepEqual(Object.keys(FX_PARAMS).sort(), Object.keys(COMPOSITION_PARAMS).filter((k) => k.startsWith("fx.")).map((k) => k.slice(3)).sort());
+ for (const k of Object.keys(FX_PARAMS)) assert.ok(FX_KEYS.includes(k), `${k} is an effect`);
+ for (const id of Object.keys(COMPOSITION_PARAMS)) assert.ok(ON[id], `${id} has a fixture here`);
+});
+
+test("every declared param: its default and both bounds build; just past them, the validator refuses", () => {
+ for (const [id, params] of Object.entries(COMPOSITION_PARAMS)) {
+ assert.ok(compositionOn(renderOf(id), id), `${id} is on in its fixture`);
+ for (const p of params) {
+ const where = `${id}.${p.key}`;
+ assert.deepEqual(errorsWith(id, p.key, p.default), [], `${where} default`);
+ if (p.kind === "enum") {
+ for (const v of p.values) assert.deepEqual(errorsWith(id, p.key, v), [], `${where} = ${v}`);
+ assert.ok(errorsWith(id, p.key, "nope").length, `${where} = "nope" is refused`);
+ } else if (p.kind === "bool") {
+ for (const v of [true, false]) assert.deepEqual(errorsWith(id, p.key, v), [], `${where} = ${v}`);
+ assert.ok(errorsWith(id, p.key, "yes").length, `${where} = "yes" is refused`);
+ } else if (p.kind === "text") {
+ assert.deepEqual(errorsWith(id, p.key, "x".repeat(p.maxLength)), [], `${where} at its length`);
+ assert.ok(errorsWith(id, p.key, "x".repeat(p.maxLength + 1)).length, `${where} past its length is refused`);
+ } else {
+ const eps = p.kind === "int" ? 1 : 0.01;
+ assert.deepEqual(errorsWith(id, p.key, p.min), [], `${where} = min ${p.min}`);
+ assert.deepEqual(errorsWith(id, p.key, p.max), [], `${where} = max ${p.max}`);
+ assert.ok(errorsWith(id, p.key, p.min - eps).length, `${where} below min is refused`);
+ assert.ok(errorsWith(id, p.key, p.max + eps).length, `${where} above max is refused`);
+ }
+ }
+ }
+});
+
+test("a composition the cut does not draw has nothing to set", () => {
+ const plain = { width: 1920, height: 1080 };
+ assert.equal(compositionOn(plain, "deck"), false);
+ assert.equal(chromeWithParam(plain, "deck", "motion.in", 0.3), null);
+ assert.equal(compositionOn(renderOf("deck"), "fx.glitch"), false);
+ assert.equal(chromeWithParam(renderOf("deck"), "deck", "height", 300), null, "an undeclared param");
+});
diff --git a/umtool/report-to-video/fx.mjs b/umtool/report-to-video/fx.mjs
@@ -29,6 +29,8 @@
// way round -- and it imports nothing of the montage's (montage.mjs imports
// deck.mjs), so the few date and phrase helpers it needs are its own.
+import { COMPOSITION_PARAMS } from "yt-dlp-transcript-common/lib/report/fxParams.mjs";
+
/** Each effect's key under `render.chrome.fx`, in the order the page stacks them (later on top). */
export const FX_KEYS = Object.freeze(["scrubber", "receipts", "zoom", "kineticQuote", "redact", "odometer", "punchIn", "thenNow", "whip", "glitch"]);
@@ -62,6 +64,16 @@ export const FX_DEFAULTS = Object.freeze({
whip: Object.freeze({ on: "every" }),
});
+/**
+ * Each effect's TUNABLE params (release 38), keyed by effect: the settings the
+ * video assistant's `fx` op may set by name ("fx.<effect>"), with the bounds
+ * validateFx holds them to (declared in common lib/report/fxParams.mjs;
+ * fx-params.test.mjs keeps the two in step).
+ */
+export const FX_PARAMS = Object.freeze(
+ Object.fromEntries(Object.entries(COMPOSITION_PARAMS).filter(([id]) => id.startsWith("fx.")).map(([id, ps]) => [id.slice(3), ps])),
+);
+
/** The motion every effect shares, in seconds. */
export const FX_MOTION = Object.freeze({
word: 0.14, // a word coming in
diff --git a/umtool/report-to-video/look.mjs b/umtool/report-to-video/look.mjs
@@ -23,17 +23,36 @@
// other #F6F1E6 paper bottom centre (a third voice, or a word heard in no turn)
// Black outline (3 px at 1080p), soft shadow. ASS colours are &HAABBGGRR.
-import { validateRoom } from "./room.mjs";
+// The checks (captions, loudness, the vertical crop, room) and their bounds
+// are the look's rules (common lib/report/look.mjs, release 38): re-exported
+// here, so the writer, the build and the video assistant refuse the same things.
+import { DEFAULT_SOURCE_ASPECT, VERTICAL_RATIO, loudnessTargetOf } from "yt-dlp-transcript-common/lib/report/look.mjs";
+
+export {
+ CAPTION_LABEL_MAX,
+ CAPTION_SIZES,
+ CAPTION_STYLES,
+ DEFAULT_SOURCE_ASPECT,
+ LOUDNESS_MAX,
+ LOUDNESS_MIN,
+ VERTICAL_RATIO,
+ VERTICAL_TOLERANCE,
+ captionsOn,
+ loudnessOn,
+ loudnessTargetOf,
+ validateCaptions,
+ validateLoudness,
+ validateLook,
+ validateVertical,
+ verticalErrors,
+} from "yt-dlp-transcript-common/lib/report/look.mjs";
-export const CAPTION_STYLES = Object.freeze(["speakers"]);
-export const CAPTION_SIZES = Object.freeze(["m", "l"]);
export const CAPTION_ROLES = Object.freeze(["host", "subject", "other"]);
export const CAPTION_COLOURS = Object.freeze({ host: "#FFC840", subject: "#6FD3FF", other: "#F6F1E6" });
/** ASS alignment (numpad): host bottom-left, subject bottom-right, other bottom-centre. */
export const CAPTION_ALIGN = Object.freeze({ host: 1, subject: 3, other: 2 });
/** The font, vendored in fonts/ (IBM Plex Sans, OFL): libass is pointed at that directory. */
export const CAPTION_FONT = "IBM Plex Sans";
-export const CAPTION_LABEL_MAX = 40;
/** Words a line: at least (unless a speaker change or the clip's end forces fewer), at most. */
export const CAPTION_MIN_WORDS = 2;
export const CAPTION_MAX_WORDS = 6;
@@ -42,115 +61,14 @@ export const CAPTION_PAUSE = 0.45;
/** How long a line stays up after its last word (s), never past the next line. */
export const CAPTION_HOLD = 0.3;
-export const LOUDNESS_MIN = -30;
-export const LOUDNESS_MAX = -8;
/** A short's target when the cut sets none. */
export const SHORT_LOUDNESS = -16;
export const SHORT_WIDTH = 1080;
export const SHORT_HEIGHT = 1920;
-export const VERTICAL_RATIO = 9 / 16;
-/** How far a crop's shape may be from 9:16 (relative): the build fits it exactly. */
-export const VERTICAL_TOLERANCE = 0.03;
-export const DEFAULT_SOURCE_ASPECT = 16 / 9;
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 captionsOn = (render) => isObj(render?.captions);
-export const loudnessOn = (render) => isObj(render?.loudness) && num(render.loudness.target);
-/** The target in LUFS, or null when the cut sets none. */
-export const loudnessTargetOf = (render) => (loudnessOn(render) ? render.loudness.target : null);
-
-/** `render.captions`: its keys and values, and what it does not combine with. */
-export function validateCaptions(manifest) {
- const render = manifest?.render ?? {};
- const c = render.captions;
- if (c === undefined || c === null) return [];
- if (!isObj(c)) return [`render.captions must be an object ({style: "speakers"}) or absent, not ${q(c)}`];
- const errors = [];
- for (const k of Object.keys(c)) {
- if (!["style", "labels", "size"].includes(k)) errors.push(`render.captions.${k} is not a setting here (the settings are style, labels, size)`);
- }
- if (!CAPTION_STYLES.includes(c.style)) errors.push(`render.captions.style must be "speakers", not ${q(c.style)}`);
- if (c.size !== undefined && !CAPTION_SIZES.includes(c.size)) errors.push(`render.captions.size must be "m" or "l", not ${q(c.size)}`);
- if (c.labels !== undefined && c.labels !== null) {
- if (!isObj(c.labels)) errors.push(`render.captions.labels must be an object ({host, subject}), not ${q(c.labels)}`);
- else {
- for (const [k, v] of Object.entries(c.labels)) {
- if (k !== "host" && k !== "subject") errors.push(`render.captions.labels.${k} is not a role here (host, subject)`);
- else if (v !== null && (typeof v !== "string" || v.length > CAPTION_LABEL_MAX)) {
- errors.push(`render.captions.labels.${k} must be a short text (up to ${CAPTION_LABEL_MAX} characters), or null`);
- }
- }
- }
- }
- if (isObj(render.chrome)) errors.push("render.captions does not combine with render.chrome (the deck draws its own words: render.chrome.fx.kineticQuote)");
- if (render.montage !== undefined && render.montage !== null) errors.push("render.captions does not combine with render.montage (a montage re-times its clips)");
- return errors;
-}
-
-/** `render.loudness`: `{target}` in LUFS. */
-export function validateLoudness(manifest) {
- const render = manifest?.render ?? {};
- const l = render.loudness;
- if (l === undefined || l === null) return [];
- if (!isObj(l)) return [`render.loudness must be an object ({target: -16}) or absent, not ${q(l)}`];
- const errors = [];
- for (const k of Object.keys(l)) if (k !== "target") errors.push(`render.loudness.${k} is not a setting here (the setting is target)`);
- if (!num(l.target) || l.target < LOUDNESS_MIN || l.target > LOUDNESS_MAX) {
- errors.push(`render.loudness.target must be a number from ${LOUDNESS_MIN} to ${LOUDNESS_MAX} LUFS, not ${q(l.target)}`);
- }
- if (render.montage !== undefined && render.montage !== null) errors.push("render.loudness does not combine with render.montage (a montage levels with render.montage.loudness)");
- return errors;
-}
-
-/** One clip's `vertical` (null when it has none): its errors, prefixed by `who`. */
-export function verticalErrors(v, who = "vertical") {
- if (v === undefined || v === null) return [];
- if (!isObj(v)) return [`${who} must be an object ({crop: [x, y, w, h]}), not ${q(v)}`];
- const errors = [];
- for (const k of Object.keys(v)) if (k !== "crop" && k !== "aspect") errors.push(`${who}.${k} is not a setting here (crop, aspect)`);
- if (v.aspect !== undefined && (!num(v.aspect) || v.aspect <= 0.2 || v.aspect > 5)) {
- errors.push(`${who}.aspect must be the source's width / height (a number from 0.2 to 5), not ${q(v.aspect)}`);
- }
- const c = v.crop;
- if (!Array.isArray(c) || c.length !== 4 || !c.every(num)) {
- errors.push(`${who}.crop must be [x, y, w, h], four fractions of the source picture`);
- return errors;
- }
- const [x, y, w, h] = c;
- const E = 1e-3;
- if (w <= 0 || h <= 0) errors.push(`${who}.crop's width and height must be above 0`);
- if (x < -E || y < -E || x + w > 1 + E || y + h > 1 + E) errors.push(`${who}.crop must lie inside the picture (each of x, y, x + w, y + h from 0 to 1)`);
- if (w > 0 && h > 0) {
- const aspect = num(v.aspect) ? v.aspect : DEFAULT_SOURCE_ASPECT;
- const shape = (w * aspect) / h;
- if (Math.abs(shape / VERTICAL_RATIO - 1) > VERTICAL_TOLERANCE) {
- errors.push(`${who}.crop must be 9:16 on the source (w × aspect / h ≈ 0.5625; this one is ${shape.toFixed(4)})`);
- }
- }
- return errors;
-}
-
-/** Every clip's `vertical`. */
-export function validateVertical(manifest) {
- const errors = [];
- (manifest?.timeline ?? []).forEach((e, i) => {
- if (e?.vertical === undefined) return;
- const who = `timeline[${i}] (${e?.id ?? "?"}).vertical`;
- if (e?.type !== "clip") errors.push(`${who}: only a clip has a vertical crop`);
- else errors.push(...verticalErrors(e.vertical, who));
- });
- return errors;
-}
-
-/** All of the look's keys: the build's validators and the lint call this. */
-export function validateLook(manifest) {
- // render.room and a clip's room (room.mjs, release 36 lane E) are part of the look.
- return [...validateCaptions(manifest), ...validateLoudness(manifest), ...validateVertical(manifest), ...validateRoom(manifest)];
-}
// ---------------------------------------------------------------------------
// The vertical crop.
diff --git a/umtool/report-to-video/room.mjs b/umtool/report-to-video/room.mjs
@@ -36,90 +36,16 @@
// fetch pad) clamps it -- the build says so, and the lint warns when the
// room can reach past the window.
-export const ROOM = Object.freeze({
- /** A gap between two words this long (s) is the silence the sound stops at. */
- minGap: 0.35,
- /** The sound never runs more than this (s) past the cut's end. */
- maxS: 2.5,
- /** The fade at the silence point, and the fade in at a muted head (s). */
- fade: 0.06,
- /** Muted picture past D, so the fade is done before the join begins (s). */
- pad: 0.1,
- /** silencedetect, when there are no words: noise floor (dB) and least length (s). */
- detectDb: -35,
- detectD: 0.3,
-});
-export const ROOM_EDGES = Object.freeze(["tail", "head"]);
-const MIN_GAP = [0.1, 2];
-const MAX_S = [0, 10];
+// ROOM, its edges, its bounds and validateRoom / roomOn / clipRoom are the
+// look's rules (common lib/report/look.mjs, release 38): re-exported here, so
+// the writer, the build and the video assistant refuse the same things.
+import { ROOM, clipRoom } from "yt-dlp-transcript-common/lib/report/look.mjs";
+
+export { ROOM, ROOM_BOUNDS, ROOM_EDGES, clipRoom, roomOn, validateRoom } from "yt-dlp-transcript-common/lib/report/look.mjs";
-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);
const r3 = (n) => Math.round(n * 1000) / 1000;
-/** Does the cut's render block turn room on for either edge? */
-export const roomOn = (render) => isObj(render?.room) && (render.room.tail === true || render.room.head === true);
-
-/**
- * One clip's room: `{tail, head, minGap, maxS}` with at least one edge on, or
- * null. The clip's `room` (false, or per-edge booleans) beats the cut's.
- */
-export function clipRoom(entry, render) {
- const r = isObj(render?.room) ? render.room : null;
- const c = entry?.room;
- if (c === false) return null;
- const edge = (k) => (isObj(c) && typeof c[k] === "boolean" ? c[k] : r?.[k] === true);
- const tail = edge("tail");
- const head = edge("head");
- if (!tail && !head) return null;
- return {
- tail,
- head,
- minGap: num(r?.minGap) ? r.minGap : ROOM.minGap,
- maxS: num(r?.maxS) ? r.maxS : ROOM.maxS,
- };
-}
-
-/** `render.room` and every clip's `room`: each problem in a sentence naming the key. */
-export function validateRoom(manifest) {
- const render = manifest?.render ?? {};
- const errors = [];
- const room = render.room;
- if (room !== undefined && room !== null) {
- if (!isObj(room)) errors.push(`render.room must be an object ({tail: true, head: true}) or absent, not ${q(room)}`);
- else {
- for (const k of Object.keys(room)) {
- if (!["tail", "head", "minGap", "maxS"].includes(k)) errors.push(`render.room.${k} is not a setting here (tail, head, minGap, maxS)`);
- }
- for (const k of ROOM_EDGES) {
- if (room[k] !== undefined && typeof room[k] !== "boolean") errors.push(`render.room.${k} must be true or false, not ${q(room[k])}`);
- }
- if (room.minGap !== undefined && (!num(room.minGap) || room.minGap < MIN_GAP[0] || room.minGap > MIN_GAP[1])) {
- errors.push(`render.room.minGap must be seconds from ${MIN_GAP[0]} to ${MIN_GAP[1]}, not ${q(room.minGap)}`);
- }
- if (room.maxS !== undefined && (!num(room.maxS) || room.maxS < MAX_S[0] || room.maxS > MAX_S[1])) {
- errors.push(`render.room.maxS must be seconds from ${MAX_S[0]} to ${MAX_S[1]}, not ${q(room.maxS)}`);
- }
- if (render.montage !== undefined && render.montage !== null) errors.push("render.room does not combine with render.montage (a montage cuts to its phrases)");
- }
- }
- (manifest?.timeline ?? []).forEach((e, i) => {
- if (e?.room === undefined) return;
- const who = `timeline[${i}] (${e?.id ?? "?"}).room`;
- if (e?.type !== "clip") errors.push(`${who}: only a clip has room at its edges`);
- else if (e.room === false || e.room === null) return;
- else if (!isObj(e.room)) errors.push(`${who} must be false or {tail?, head?}, not ${q(e.room)}`);
- else {
- for (const [k, v] of Object.entries(e.room)) {
- if (!ROOM_EDGES.includes(k)) errors.push(`${who}.${k} is not a setting here (tail, head)`);
- else if (typeof v !== "boolean") errors.push(`${who}.${k} must be true or false, not ${q(v)}`);
- }
- }
- });
- return errors;
-}
-
/** Timed words, in time order (any of the transcribers' keys for the text is fine; only times are read). */
function timed(words) {
return (Array.isArray(words) ? words : [])
diff --git a/umtool/report-to-video/stats.mjs b/umtool/report-to-video/stats.mjs
@@ -15,6 +15,8 @@
// PURE, like factcheck.mjs: validation, the defaults, the schedule. No fs, no
// ffmpeg. deck.mjs imports this file -- never the other way round.
+import { COMPOSITION_PARAMS } from "yt-dlp-transcript-common/lib/report/fxParams.mjs";
+
/** Where the stats sit in the footage box. */
export const STATS_POSITIONS = Object.freeze(["top-left", "top-right", "bottom-left", "bottom-right"]);
@@ -31,6 +33,9 @@ export const STATS_LABELS = Object.freeze({ stack: "Stack", stackBB: "Big blinds
*/
export const STATS_DEFAULTS = Object.freeze({ position: "bottom-left", fields: STATS_FIELDS, name: true });
+/** The stats panel's TUNABLE params (release 38; common lib/report/fxParams.mjs): what the video assistant's `fx` op may set. */
+export const STATS_PARAMS = COMPOSITION_PARAMS.stats;
+
/** How long the panel takes to come in and go out, in seconds. */
export const STATS_MOTION = Object.freeze({ in: 0.3, out: 0.25 });
diff --git a/umtool/report-to-video/transition.mjs b/umtool/report-to-video/transition.mjs
@@ -12,24 +12,21 @@
// five taps spaced by the moment's speed (most at the start, none as it lands),
// and the frames nearest the seam take a light temporal grain. One xfade
// custom expression (`pushExpr`) plus the grain on each clip's edge.
-export const TRANSITION_STYLES = Object.freeze(["fade", "fadeblack", "fadewhite", "dissolve", "blurslide"]);
+//
+// The style list, the slide's knobs and their checks are the look's rules
+// (common lib/report/look.mjs, release 38): re-exported here, so the writer,
+// the build and the video assistant refuse the same things.
+import { slideOf, transitionStyleOf } from "yt-dlp-transcript-common/lib/report/look.mjs";
-/** The style a plain join uses (`render.transitionStyle`, default "fade"). */
-export const transitionStyleOf = (render) => render?.transitionStyle ?? "fade";
-
-// The push's knobs (`render.slide`): travel = fraction of the width the
-// pictures move; blur = motion-smear strength (0 none, 1 = a frame's travel);
-// grain = noise strength on the seam's frames (0 none).
-export const SLIDE_DEFAULTS = Object.freeze({ travel: 0.08, blur: 0.5, grain: 2 });
-const SLIDE_BOUNDS = Object.freeze({ travel: [0, 0.5], blur: [0, 2], grain: [0, 20] });
-
-/** The push's knobs, the defaults filled in. */
-export function slideOf(render) {
- const s = render?.slide && typeof render.slide === "object" ? render.slide : {};
- const out = {};
- for (const k of Object.keys(SLIDE_DEFAULTS)) out[k] = Number.isFinite(s[k]) ? s[k] : SLIDE_DEFAULTS[k];
- return out;
-}
+export {
+ SLIDE_BOUNDS,
+ SLIDE_DEFAULTS,
+ TRANSITION_STYLES,
+ slideOf,
+ transitionStyleOf,
+ validateSlide,
+ validateTransitionStyle,
+} from "yt-dlp-transcript-common/lib/report/look.mjs";
/**
* The push as an xfade custom expression, for a join `D` seconds long at `fps`.
@@ -89,27 +86,3 @@ export function blurSlideEdges(d, D, render, { tail = false, head = false } = {}
if (head) parts.push(`lt(t,${w.toFixed(3)})`);
return `noise=alls=${Math.round(grain)}:allf=t+u:enable='${parts.join("+")}'`;
}
-
-/** @param {{ render?: { transitionStyle?: unknown } }} manifest */
-export function validateTransitionStyle(manifest) {
- const s = manifest?.render?.transitionStyle;
- const slide = validateSlide(manifest);
- if (s === undefined || s === null) return slide;
- return typeof s === "string" && TRANSITION_STYLES.includes(s)
- ? slide
- : [`render.transitionStyle: ${JSON.stringify(s)} is not one of ${TRANSITION_STYLES.join(", ")}`, ...slide];
-}
-
-/** `render.slide`: absent, or an object of the push's knobs within bounds. */
-export function validateSlide(manifest) {
- const s = manifest?.render?.slide;
- if (s === undefined || s === null) return [];
- if (typeof s !== "object" || Array.isArray(s)) return ["render.slide must be an object {travel?, blur?, grain?}"];
- const errs = [];
- for (const [k, v] of Object.entries(s)) {
- const b = SLIDE_BOUNDS[k];
- if (!b) errs.push(`render.slide.${k} is not a key (travel, blur, grain)`);
- else if (!Number.isFinite(v) || v < b[0] || v > b[1]) errs.push(`render.slide.${k} must be a number from ${b[0]} to ${b[1]}`);
- }
- return errs;
-}