// Draft everything's generation steps (release 28 M9), the pure part: what a // draft would draw nothing on, and how a draft that did not end done is // recorded. Plain node (common's panels.mjs is plain JS too), so the tests // and the Next app may import it; ./chain-run.mjs executes the steps. import { flipsOn, threadsOn } from "yt-dlp-transcript-common/lib/report/panels.mjs"; /** * The minimal on-screen deck: every deck setting its default (deck.mjs * DECK_DEFAULTS). What the On-screen section's switch turns on and what * Draft everything's deck step (release 29 G1) adds to a cut with none -- * one constructor, a fresh object each call. * * @returns {{ engine: "hyperframes", layout: "deck", deck: Record }} */ export function deckChrome() { return { engine: "hyperframes", layout: "deck", deck: {} }; } /** A deck step's line: what it did. */ export const deckStepDetail = (added) => added ? "deck added: render.chrome with every setting its default (a snapshot of the cut before it is in revisions/)" : "deck already there: the cut's render.chrome is kept as it is"; /** * A refused deck step's line: "frame too small for the deck" when the deck's * defaults do not fit the cut's frame (validateChrome's "… needs …px but a * …px deck leaves …"), else the refusal itself. * * @param {string[]} errors validateChrome's sentences * @param {{ width?: number, height?: number } | undefined} render */ export function deckRefusedDetail(errors, render) { const size = render?.width && render?.height ? ` (${render.width}×${render.height})` : ""; const small = (errors ?? []).find((e) => /needs \d+px but a \d+px deck leaves/.test(e)); if (small) return `frame too small for the deck${size}: ${small} — no deck added, so the flips and threads are skipped`; return `the deck was refused: ${(errors ?? []).join("; ")}`; } /** The audit file each task writes beside the manifest (narrate's kept its old name). */ export const draftFileOf = (task) => (task === "narrate" ? "narration-draft.json" : `${task}-draft.json`); /** * Why a draft would draw nothing on this cut, before the editor is asked, or * null: flips and threads need the on-screen deck, and share its left panel * (the task refuses the other panel; Draft everything never forces). */ export function draftPrecheck(task, manifest) { if (task !== "flips" && task !== "threads") return null; const render = manifest?.render ?? {}; if (!render.chrome || typeof render.chrome !== "object") return `the cut has no on-screen deck (render.chrome) to draw the ${task} on`; if (task === "threads" && flipsOn(render)) return "the cut has flips: flips and threads share the left panel"; if (task === "flips" && threadsOn(render)) return "the cut has threads: flips and threads share the left panel"; return null; } /** * How a draft that did not finish done is recorded: skipped when its draft * file says every unit was skipped (each field already written), else failed. */ export function draftOutcome(draftFile) { const units = draftFile && typeof draftFile.units === "object" && draftFile.units ? Object.values(draftFile.units) : []; if (units.length > 0 && units.every((u) => u && typeof u.skipped === "string")) { return { status: "skipped", detail: `nothing to draft: ${units.length} field(s) already written (a re-draft of a draft is “Draft with” with force)` }; } return { status: "failed", detail: null }; }