// THE GAP MARK'S PAGE (module `gap-cue`, region `gap-cue`; lane gap-cue, // slice 1d): "» 27 s" at a clip gap's join, one short page per mark -- the // schedule's `gapCue.marks` (gap-cue-slice.mjs) -- laid at its own seconds // over the whole frame, so the mark stands over the footage or in the deck's // band as its `place` says, at the rect the slice gave it. A cue page // (chrome-cues.mjs): the element comes up over GAP_CUE_MOTION.in at the join, // holds, and goes over GAP_CUE_MOTION.out (common gapCue.mjs, the drawtext // path's own ramp: linear, to GAP_CUE_MOTION.peak). // // THE LOOK is common gapCue.mjs GAP_CUE_LOOK as CSS (gapCueCss): the deck's own // bold face (DeckSansBold), a real border -- in the mark's `border`, the colour // the slice resolved (gapCueLook / gapCueBorderOf: the deck's accent unless the // clip or project names one) -- the box inside it. The page is its // live preview too (the module's `play`): Play the cut loads it as it is. // // PURE: a schedule and a render in, the page's HTML out. import { GAP_CUE_MOTION, gapCueCss, gapCueLook } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { compileCues, cuePageHtml, esc, r4 } from "./chrome-cues.mjs"; import { subtitleMarkup } from "./chrome-deck.mjs"; import { GAP_CUE_DECK_LINE } from "./gap-cue-slice.mjs"; /** * A mark's id (`.g`): what its window, its project and its frames are named by. A clip id takes what the * chapter's segment ids take (`.` and `:` too); never a `/`, `\`, NUL or space, and always after the `gap-cue-` * prefix, so it names one directory entry. Play's route is stricter than this (serve.mjs layerPreviewOf): it also * refuses `.` and `..`, and the `` must be one of the cut's entries. */ export const GAP_CUE_ID_RE = /^[A-Za-z0-9_.:-]+\.g\d+$/; /** The schedule's marks, each a window `{ segment: , from, to, mark }` on the cut's clock. */ export function gapCueWindows(schedule) { return (schedule?.gapCue?.marks ?? []) .filter((m) => typeof m?.id === "string" && Number.isFinite(m.at) && Number.isFinite(m.until) && m.until > m.at) .map((m) => ({ segment: m.id, from: m.at, to: m.until, mark: m })); } /** Where a placed mark stands, as CSS (`left`/`right`, `top`/`bottom`: the edges it is placed against). */ function placeAt(m, W, H) { const right = m.place === "deck" || String(m.corner ?? "").endsWith("r"); const bottom = m.place !== "deck" && String(m.corner ?? "").startsWith("b"); const r = m.rect; return [ right ? `left: auto; right: ${W - (r.x + r.w)}px;` : `left: ${r.x}px; right: auto;`, bottom ? `top: auto; bottom: ${H - (r.y + r.h)}px;` : `top: ${r.y}px; bottom: auto;`, `max-width: ${Math.max(Number(m.room) || r.w, 1)}px;`, ].join(" "); } /** A script string's literal (no `` can close the page's script early). */ const lit = (v) => JSON.stringify(v).replace(/} schedule * @param {Record} render * @param {{ segment: string, from: number, to: number }} window the snapped window * @param {{ fonts?: { regular?: string, bold?: string }, gsap?: string, look?: Record }} [opts] `look` over * the mark's own (gapCueLook of its `border`: the operator's stills of the variants; the build passes none) */ export function gapCueHtml(schedule, render, window, opts = {}) { const w = gapCueWindows(schedule).find((x) => x.segment === window.segment); if (!w) throw new Error(`gap-cue: no mark ${window.segment} in this schedule`); const m = w.mark; const W = render.width ?? 1920; const H = render.height ?? 1080; const fps = schedule.fps ?? render.fps ?? 30; const from = r4(window.from); const dur = r4(window.to - window.from); const M = GAP_CUE_MOTION; // On the window's clock: the mark's own seconds inside the snapped window. const a = r4(m.at); const b = r4(m.until); // A mark shorter than its ramps (cut short before a dissolve) rises only as far as the drawtext's alpha does // (common gapCueAlpha): to where its in and out ramps meet, never a flash to the peak. const len = Math.max(0, b - a); const short = len < M.in + M.out; const inDur = short ? r4((len * M.in) / (M.in + M.out)) : M.in; const outDur = short ? r4(len - inDur) : M.out; const peak = short ? r4((M.peak * len) / (M.in + M.out)) : M.peak; const { init, cues } = compileCues({ gm: { autoAlpha: 0 } }, [ { k: "gm", at: a, dur: inDur, to: { autoAlpha: peak }, ease: "none" }, { k: "gm", at: r4(b - outDur), dur: outDur, to: { autoAlpha: 0 }, ease: "none" }, ]); // The mark's look: its border in the colour the slice resolved (absent -- a schedule from before it carried one -- // gapCueLook of the render alone: its accent), the stills' `look` over it. const look = { look: { ...gapCueLook(render, null, { border: m.border }), ...(opts.look ?? {}) } }; const line = m.place === "deck" ? GAP_CUE_DECK_LINE : 1.2; const guard = m.place === "deck" && m.line && m.alt ? m : null; let css = `${gapCueCss(".gm", { font: m.font, stroke: m.stroke, lineHeight: line, ...look })} .gm { visibility: hidden; opacity: 0; ${placeAt(m, W, H)} }`; let body = `
${esc(m.text)}
`; let fit; if (guard) { const L = guard.line; // The fallback: the mark's own place over the footage, its look at that size (it overrides every edge). css += ` ${gapCueCss(".gm.fell", { font: guard.alt.font, stroke: guard.alt.stroke, lineHeight: 1.2, ...look })} .gm.fell { ${placeAt(guard.alt, W, H)} } /* The source line as the deck draws it (chrome-deck.mjs .deck-sub), never shown: what the mark keeps clear of. */ .gm-line { position: absolute; left: ${L.x}px; top: ${L.y}px; display: flex; white-space: nowrap; visibility: hidden; font-size: ${L.size}px; letter-spacing: 0.005em; } .gm-line .part, .gm-line .sep { flex: none; } .gm-line .sep { padding: 0 0.42em; font-family: 'DeckSansBold', sans-serif; }`; body += `\n `; fit = { loads: [`${L.size}px DeckSans`, `${L.size}px DeckSansBold`, `${m.font}px DeckSansBold`], run: `// The mark never touches the source line: measured in the faces the deck draws it in. (function () { const gm = document.querySelector(".gm"); const ln = document.querySelector(".gm-line"); if (!gm || !ln || ln.getBoundingClientRect().right + ${Number(L.air) || 0} <= gm.getBoundingClientRect().left) return; gm.classList.add("fell"); gm.textContent = ${lit(guard.alt.text)}; gm.dataset.gm = ${lit(guard.alt.text)}; gm.dataset.place = "footage"; gm.dataset.fell = "line"; })();`, }; } return cuePageHtml({ id: "gap-cue", W, H, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init, cues, window: { from, dur }, ...(fit ? { fit } : {}) }); }