// RESPELL A VIDEO MANIFEST — the video side of `archilyzer reports respell` // (lib/citations/respell.mjs says what a respelling is; lib/report/respellReport.ts // is the report side). // // Every string in the manifest is walked: // - under a QUOTE key (`quote` — a clip's verbatim words, burned into its frames; // `words` — a flip card's quoted line): the respelling as it says (bracketed when // it asks); // - under a key that names a thing (ids, slugs, sources, paths, urls, dates — SKIP_KEYS) // or a value that looks like a path or url: untouched; // - anything else (titles, subtitles, narration, card text — the author's words): plain. // `respellings` is merged in at the top, so resolve-windows' cut-to-quote applies the // same respellings to the cues (a respelled quote still finds its span). // // Pure: the caller reads and writes the file. Types: respellManifest.d.mts. import { applyRespellings, cleanRespellings, mergeRespellings } from "../citations/respell.mjs"; const QUOTE_KEYS = new Set(["quote", "words"]); const SKIP_KEYS = new Set([ "id", "entry", "slug", "src", "source", "file", "path", "url", "href", "link", "siteOrigin", "siteChannel", "siteVideo", "channel", "video", "videoId", "cite", "citeUrl", "kind", "type", "status", "date", "when", "generatedOn", "schemaVersion", "model", "voice", "preset", "layout", "theme", "accent", "color", "font", "respellings", "drafted", "provenance", ]); const looksLikeRef = (v) => /^(https?:|file:|\/|\.{1,2}\/|~\/)/.test(v) || /\.[a-z0-9]{2,4}$/i.test(v); export function respellManifest(manifest, respellings) { const rs = cleanRespellings(respellings); const changes = []; const out = structuredClone(manifest); const walk = (node, at, key) => { if (typeof node === "string") { if (SKIP_KEYS.has(key) || looksLikeRef(node)) return node; const after = applyRespellings(node, rs, QUOTE_KEYS.has(key) ? "display" : "plain"); if (after !== node) changes.push({ at, before: node, after }); return after; } if (Array.isArray(node)) return node.map((v, i) => walk(v, `${at}[${i}]`, key)); if (node && typeof node === "object") { for (const [k, v] of Object.entries(node)) { if (SKIP_KEYS.has(k) && typeof v === "object") continue; node[k] = walk(v, at ? `${at}.${k}` : k, k); } return node; } return node; }; walk(out, "", ""); if (rs.length) out.respellings = mergeRespellings(out.respellings, rs); return { manifest: out, changes }; }