// THE GAP MARKS ON THE CUT'S CLOCK (lane gap-cue, slice 1d): the schedule's // `gapCue` slice, which the gap-cue MODULE draws (modules/gap-cue.mjs: one // small HyperFrames page per mark, chrome-gap-cue.mjs) wherever a deck is drawn // -- so a mark turned on, moved, restyled or re-worded re-renders chrome only, // never a clip segment (gap-mark.mjs gapMarkByChrome: the segment then draws // none). // // THE JOINS come from what each clip's segment really left out: its cut record // (`start`, `end`, `gaps` -- the recording's seconds, between a clip's pieces // too), the record the schedule already reads for its gaps. A record written // before this slice carries all three, so an old take gets its marks from a // chrome-only pass: no re-cut. The record DECIDES: one written with no `gaps` // (a segment cut before its clip had them) plays them, so it has no join to // mark (the chrome-only pass says so, build-video.mjs segmentGapNote). Only // with no record at all (a preview before any build) do the clip's play window // and its own gaps stand in. The marks themselves -- the threshold, the merge // inside a life, the text -- are gap-mark-place.mjs recordGapMarks, the // drawtext path's own rule, then on the cut's clock: `segment.start + at`. // // A clip whose record carries `gapMarks` was built with its marks drawn INTO // its segment (the drawtext path: `--no-chrome`, or a build before this slice): // the slice leaves it out (`inSegment`), so a mark is never drawn twice on one // frame. A full build rebuilds that segment without them (its plain key) first. // // WHERE (`place`, the clip's over the project's): // footage in the footage box (deck.mjs overlayBox; a twocrop clip's crop one // inside the stacked deck's safe area), at its corner -- `auto` the // deck's bottom left (twocrop: top right) -- hopping to the next free // corner off a hidden region, a stamp, the posts' column, the chat // column, a chapter's cover, the stats panel and the effects' // screenshots while one is up (none free: the asked corner). // deck in the band, right-aligned at the end of the source line's row // (left of the QR's plate and a tally beside it), centred on the row, // a size under the source line's text. The deck's own page is not // touched: the source line keeps its words, the status part at its // end included. When the line (status and all, at its longest, // reckoned in the face the deck sets it in: deckLineWidth) and the // mark do not both fit the row, the mark is drawn over the footage // instead (`fell: "row"`); so it is in the stacked vertical deck (its // band is laid otherwise: `fell: "stacked"`) and over a segment that // hides the deck (`fell: "hidden"`). The PAGE checks again in its own // faces (chrome-gap-cue.mjs: `line`, `alt`), so a reckoning that is // short can never put the mark on the line's words. // // PURE: a schedule and a render in, the slice out. Byte for byte: no clip // wanting a mark, no slice (the key absent). import { GAP_CUE_LOOK, clipGapCueOf, gapCueBorderOf, gapCueWanted } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { sourceLineRow, subtitleTokens } from "./chrome-deck.mjs"; import { censorRegionsOf } from "./clip-censor.mjs"; import { chatGeometry } from "./chrome-chat.mjs"; import { chapterCover, chapterWindows } from "./chrome-story.mjs"; import { deckGeometry, deckLayout, deckOn, deckScale, fxGeometry, overlayBox, playWindow, postsGeometry, stampGeometry, statsGeometry } from "./deck.mjs"; import { FX_RECEIPTS_MAX } from "./fx.mjs"; import { tallyOf } from "./factcheck.mjs"; import { censorAvoidRects, gapMarkAsked, gapMarkPlaces, gapMarkSize, monoWidth, recordGapMarks, sansWidth, twoCropMarkBox } from "./gap-mark-place.mjs"; import { recordGaps } from "./gaps.mjs"; import { clipTwoCrop, stackedGeometry, stackedOn } from "./vertical-deck.mjs"; const r4 = (v) => Math.round(v * 10000) / 10000; const rectOf = (b) => ({ x: b.x, y: b.y, w: b.w ?? b.width, h: b.h ?? b.height }); const fin = (v) => typeof v === "number" && Number.isFinite(v); /** * How wide a mark's text is reckoned in the deck's bold face, whatever face the brand gives it: the wider of a bold * sans's advances (sansWidth) and a monospace's (monoWidth, Plex Mono -- the default deck's bold). A reckoning that * errs wide places and hops the mark; the page sizes the element to its text, never cutting one that fits its room. */ export const deckFaceWidth = (text, fontSize) => Math.max(sansWidth(text, fontSize), monoWidth(text, fontSize)); /** The shortest a mark is drawn for, seconds (its join too near the dissolve out of its segment: none). */ export const GAP_CUE_MIN_UP = 0.2; /** The deck place's text against the source line's: a size under it (its box then sits inside the row and the air round it). */ export const GAP_CUE_DECK_FONT = 0.9; /** The deck place's line box, in ems: the row is short, so the box is the text's own height. */ export const GAP_CUE_DECK_LINE = 1; /** * The basis a clip's marks are taken from. Its cut record DECIDES when it has one: the seconds it starts and ends at * and the gaps it really left out (`gaps` absent = none: a segment cut before its gaps plays them, so it has no * joins to mark -- null when the record cannot say where the segment starts). Only with no record at all (a * preview before any build) do its play window and its own gaps inside it stand in, an estimate as a preview's * segments are. * * @returns {{ start: number, end: number, gaps: Array<{ from: number, to: number }> } | null} */ export function basisOf(entry, render, rec) { if (rec) { if (!fin(Number(rec.start)) || !fin(Number(rec.end))) return null; return { ...rec, gaps: recordGaps(rec) }; } const pw = playWindow(entry, render); const gaps = (Array.isArray(entry.gaps) ? entry.gaps : []) .filter((g) => fin(g?.from) && fin(g?.to) && g.to > pw.from && g.from < pw.to) .map((g) => ({ from: Math.max(pw.from, g.from), to: Math.min(pw.to, g.to) })) .filter((g) => g.to > g.from); return { start: pw.from, end: pw.to, gaps }; } /** The air a deck-placed mark keeps after the source line's end, band px at 1080 (deckScale). */ export const GAP_CUE_DECK_AIR = 24; /** Is the deck's regular face the brand's IBM Plex Mono (brand.mjs resolveBrandRender)? Read by its file's name. */ const monoDeck = (render) => /IBMPlexMono-Regular\.[ot]tf$/i.test(String(render?.fontRegular ?? "")); /** * How wide a source line draws, px, reckoned WIDE: its parts in the face the page sets them in (the brand's Plex * Mono when `render.fontRegular` is it; else the wider of a sans's advances and a mono's, whatever face it is), * each separator its bold dot and the 0.42 em of padding either side of it (chrome-deck.mjs `.deck-sub .sep`), and * the line's 0.005 em letter-spacing on every character, each glyph's advance rounded up to a whole pixel. The page measures the line itself too, once its faces * are in (chrome-gap-cue.mjs): this only decides where the mark is laid, never alone that it is clear of the text. */ export function deckLineWidth({ text, parts = null, size, render }) { const said = subtitleTokens(text, parts)?.map((p) => p[1]) ?? String(text ?? "").split(" · "); const mono = monoDeck(render); // Per glyph, rounded up: the render browser lays a hinted face's advances on whole pixels (Plex Mono at 26 px // draws 16 px a glyph, not 15.6). const glyph = (ch) => (mono ? monoWidth(ch, size) : Math.max(sansWidth(ch, size), monoWidth(ch, size))); const face = (v) => [...v].reduce((n, ch) => n + glyph(ch), 0); const seps = Math.max(0, said.length - 1); const chars = said.reduce((n, v) => n + [...v].length, 0) + seps; return Math.ceil(said.reduce((n, v) => n + face(v), 0) + seps * (monoWidth("·", size) + 0.84 * size) + 0.005 * size * chars); } /** * The deck place's rect for one mark's text, frame px, or why it cannot stand there (`fell`): right-aligned at the * source line row's end, centred on the row (chrome-deck.mjs sourceLineRow: the rows the page lays the line on). * `line` is what the page measures before it shows the mark: the line's row, its words and its size. * * @returns {{ rect: { x: number, y: number, w: number, h: number }, font: number, stroke: number, room: number, * line: { x: number, y: number, size: number, air: number, text: string, parts: unknown } } | { fell: string }} */ export function gapCueDeckRect({ render, schedule, segment, text }) { if (stackedOn(render)) return { fell: "stacked" }; if (segment.hideDeck) return { fell: "hidden" }; const { deck: band } = deckGeometry(render); const lay = deckLayout(render, { tally: tallyOf(schedule, render), schedule }); const t = lay.text; const k = deckScale(render); const z = (v) => (k === 1 ? v : Math.round(v * k)); const row = sourceLineRow(t, segment); const font = Math.max(12, Math.round(row.size * GAP_CUE_DECK_FONT)); const stroke = Math.max(GAP_CUE_LOOK.strokeMin, Math.round(Math.min(render.width ?? 1920, render.height ?? 1080) * GAP_CUE_LOOK.stroke)); const edge = Math.round(font * GAP_CUE_LOOK.pad) + stroke; const w = deckFaceWidth(text, font) + 2 * edge; const h = Math.ceil(font * GAP_CUE_DECK_LINE) + 2 * edge; const right = t.x + t.width - z(22); const air = z(GAP_CUE_DECK_AIR); // The source line as it would draw at its longest (its status at its longest too), and air before the mark. const lineW = deckLineWidth({ text: row.text, parts: row.parts, size: row.size, render }); if (t.x + lineW + air > right - w) return { fell: "row" }; return { rect: { x: band.x + right - w, y: band.y + row.y + Math.round((row.box - h) / 2), w, h }, font, stroke, // Its room: from the line's end (and the air after it) to the row's. room: right - (t.x + lineW + air), line: { x: band.x + t.x, y: band.y + row.y, size: row.size, air, text: row.text, parts: row.parts ?? null }, }; } /** * What stands over the footage that a mark keeps off, frame px, each over its cut seconds (`from`–`to`): the * stamps while each is up, the posts' column while a clip's cards are, the chat column while a clip shows chat, * a chapter's cover while its bumper is up, the stats panel while a clip shows its stats, the effects' screenshots * (the receipts, the zoom) while each is up. */ export function moduleAvoids(schedule, render) { const feed = schedule.layout === "feed"; const out = []; const stamps = schedule.factcheck?.stamps ?? []; if (stamps.length) { const g = rectOf(stampGeometry(render, { feed })); for (const s of stamps) if (fin(s.at) && Array.isArray(s.out)) out.push({ ...g, from: s.at, to: s.out[1] }); } if (!feed && (schedule.posts ?? []).length) { const g = rectOf(postsGeometry(render)); for (const p of schedule.posts) if (fin(p.appear) && Array.isArray(p.out)) out.push({ ...g, from: p.appear, to: p.out[1] }); } for (const c of schedule.chat?.clips ?? []) { out.push({ ...rectOf(chatGeometry(render, { feed })), from: c.in, to: c.out }); } if (render?.chrome?.chapter) { const g = rectOf(chapterCover(render, { feed })); for (const w of chapterWindows(schedule, render)) out.push({ ...g, from: w.from, to: w.to }); } // The stats panel while a clip that declares stats shows it. if ((schedule.stats?.clips ?? []).length) { const g = rectOf(statsGeometry(render, { feed })); for (const c of schedule.stats.clips) if (fin(c.in) && fin(c.out)) out.push({ ...g, from: c.in, to: c.out }); } out.push(...fxShotAvoids(schedule, render, feed)); return out; } /** * Where the effects' screenshots stand while each is up (chrome-fx.mjs fxPlan), reckoned at their largest -- the * page sizes a card to its shot, which the schedule does not know: the receipts' fan, a column on their side of the * footage box as wide as `receipts.width` plus the fan's spread and inset, the whole box tall; the zoom's card, centred, * `zoom.width` of the box wide and 84 % of it tall. */ function fxShotAvoids(schedule, render, feed) { const fx = schedule.fx; if (!fx) return []; const geo = rectOf(fxGeometry(render, { feed })); const px = (v) => Math.max(1, Math.round(v * (geo.w / 1574))); const out = []; if (fx.receipts?.clips?.length) { const right = fx.receipts.position !== "left"; const w = Math.min(geo.w, Math.ceil((fx.receipts.width ?? 0.36) * geo.w) + px(48) + (FX_RECEIPTS_MAX - 1) * px(22) + px(8)); const rect = { x: right ? geo.x + geo.w - w : geo.x, y: geo.y, w, h: geo.h }; for (const r of fx.receipts.clips) if (fin(r.in) && fin(r.out)) out.push({ ...rect, from: r.in, to: r.out }); } if (fx.zoom?.clips?.length) { const w = Math.min(geo.w, Math.ceil((fx.zoom.width ?? 0.6) * geo.w) + 2 * px(8)); const h = Math.min(geo.h, Math.ceil(geo.h * 0.84) + px(36) + 2 * px(8)); const rect = { x: geo.x + Math.floor((geo.w - w) / 2), y: geo.y + Math.floor((geo.h - h) / 2), w, h }; for (const z of fx.zoom.clips) if (fin(z.in) && fin(z.out)) out.push({ ...rect, from: z.in, to: z.out }); } return out; } /** * The schedule's `gapCue` slice: `{ marks: [...], inSegment?: [clip ids] }`, or null when no clip wants a mark * (or no deck is drawn). Each mark: `{ id, segment, at, until, seconds, count?, text, place, corner?, asked?, * rect, room, font, stroke, border, fell? }` -- `at`/`until` the cut's seconds, `rect` frame px (its width reckoned * wide: deckFaceWidth), `room` the widest the element may draw, `font`/`stroke` px, `border` its border's colour * (common gapCueBorderOf: the clip's `border`, else the deck's accent, `render.palette.accent`). * * @param {Record} schedule the deck's (deckSchedule): its segments, stamps, posts, chat * @param {{ entries: any[], render: any, records?: Map | null, provenance?: any }} o */ export function gapCueSlice(schedule, { entries, render, records = null, provenance = {} }) { if (!deckOn(render)) return null; const wanted = entries.filter((e) => e?.type === "clip" && Array.isArray(e.gaps) && e.gaps.length && gapCueWanted(render, e)); if (!wanted.length) return null; const segs = new Map((schedule.segments ?? []).map((s) => [s.id, s])); const lastSeg = (schedule.segments ?? []).at(-1) ?? null; const D = Number(schedule.transition) > 0 ? Number(schedule.transition) : 0; const W = render.width ?? 1920; const H = render.height ?? 1080; const size = gapMarkSize(W, H); const feed = schedule.layout === "feed"; const avoids = moduleAvoids(schedule, render); const marks = []; const inSegment = []; for (const e of wanted) { const seg = segs.get(e.id); if (!seg) continue; const rec = records?.get(e.id) ?? null; if (Array.isArray(rec?.gapMarks) && rec.gapMarks.length) { inSegment.push(e.id); continue; } const basis = basisOf(e, render, rec); if (!basis) continue; const own = recordGapMarks({ render, entry: e, record: basis }); if (!own.length) continue; const cue = clipGapCueOf(render, e); const border = gapCueBorderOf(render, e); // Over the footage: the footage box (twocrop: crop one inside the safe area), the deck's free corner. const twocrop = stackedOn(render) && clipTwoCrop(e); const fb = twocrop ? twoCropMarkBox(stackedGeometry(render)) : { box: rectOf(overlayBox(render, { feed })), prefer: "bl" }; const base = rectOf(fb.box); // A hidden region (clip-censor.mjs), mapped onto the box as the drawtext path maps it, over the cut's seconds. const segSeconds = Number(basis.end) - Number(basis.start) - basis.gaps.reduce((n, g) => n + (g.to - g.from), 0); const censor = twocrop ? [] : censorAvoidRects(censorRegionsOf(e, render, provenance), { sw: 1, sh: 1, dest: base, from: Number(basis.start), gaps: basis.gaps, seconds: segSeconds, }).map((a) => ({ ...a, from: a.from == null ? null : seg.start + a.from, to: a.to == null ? null : seg.start + a.to })); // On the cut's clock, and gone before the dissolve into the next segment begins (its picture is the next // clip's by then): a mark that would run on into it ends there, fading out by then. One left shorter than // GAP_CUE_MIN_UP is not drawn. const outAt = segs.size && seg !== lastSeg ? seg.end - D : seg.end; const onCut = own .map((m) => ({ ...m, at: r4(seg.start + m.at), until: r4(Math.min(seg.start + m.until, outAt)) })) .filter((m) => m.until - m.at >= GAP_CUE_MIN_UP); if (!onCut.length) continue; const places = gapMarkPlaces({ marks: onCut, box: base, want: cue.corner, prefer: fb.prefer, size, avoid: [...censor, ...avoids], measure: deckFaceWidth }); // Over the footage, a mark's room is its box less the insets. const room = base.w - 2 * size.inset; onCut.forEach((m, k) => { const asked = gapMarkAsked(m, cue.corner); const common = { id: `${e.id}.g${k}`, segment: e.id, at: m.at, until: m.until, seconds: m.seconds, ...(m.count > 1 ? { count: m.count } : {}), border, }; const p = places[k]; const footage = { text: p.text, place: "footage", corner: p.corner, ...(asked ? { asked } : {}), rect: p.rect, room, font: p.size.fontSize, stroke: p.size.stroke }; if (cue.place === "deck") { const d = gapCueDeckRect({ render, schedule, segment: seg, text: m.text }); if ("rect" in d) { // `line`: what the page measures in its own faces before it shows the mark; `alt`: where it stands // instead when the line and the mark would touch (chrome-gap-cue.mjs) -- never on the text. marks.push({ ...common, text: m.text, place: "deck", rect: d.rect, room: d.room, font: d.font, stroke: d.stroke, line: d.line, alt: footage }); return; } marks.push({ ...common, ...footage, fell: d.fell }); return; } marks.push({ ...common, ...footage }); }); } if (!marks.length && !inSegment.length) return null; return { marks, ...(inSegment.length ? { inSegment } : {}) }; } /** `schedule` with its gap-cue slice (gapCueSlice) set -- or as it was, the key absent, when there is none. */ export function withGapCue(schedule, o) { const { gapCue: _was, ...rest } = schedule; const slice = gapCueSlice(rest, o); return slice ? { ...rest, gapCue: slice } : (_was === undefined ? schedule : rest); }