// THE GAP MARK ON umtool's PAGES (lane gap-cue, slice 1b): the clip bench and // Play the cut draw the mark the render draws at a gap's join ("» 27 s"), at // the same seconds, with the same text and the same fade. Nothing here times // a mark: the rule is common lib/report/gapCue.mjs's (gapCues, gapCueAlpha, // gapCueText -- the build's gap-mark.mjs reads the same three), and the clocks // are gaps.mjs's (offsetIn). This file only says which joins a page has, on // the clock the page plays, and which mark is up at a second of it. // // PURE and dependency-free beyond those two: the client bundle takes it. import { GAP_CUE_MOTION, gapCueAlpha, gapCueText, gapCues, gapMarkOn, gapOwnSays } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { gappedLength, gapsWithin, offsetIn } from "umtool-report-to-video/gaps"; const fin = (v) => typeof v === "number" && Number.isFinite(v); /** How far a clip's own gap may sit from the one the render took out (the frame grid) and still be it. */ const NEAR = 0.05; /** * The corner a page draws the mark at: the clip's `corner`, or for `auto` the * layout's own (gap-mark.mjs's `prefer`): the deck's footage bottom left, a * plain cut's picture top left. * * @param {string | null | undefined} corner * @param {{ deck: boolean }} layout * @returns {"tl" | "tr" | "bl" | "br"} */ export function gapMarkCorner(corner, { deck }) { if (corner === "tl" || corner === "tr" || corner === "bl" || corner === "br") return corner; return deck ? "bl" : "tl"; } /** * Is one of the clip's own gaps (`own`, with their `mark`) the one a page * plays from `from`–`to`: the same seconds, give or take the frame grid. */ const ownOf = (own, from, to) => (own ?? []).filter((c) => fin(c?.from) && fin(c?.to) && c.to > from - NEAR && c.from < to + NEAR); /** * The marks of a clip played from `from` to `to` (source seconds) with its * `gaps` (the clip's own, each with its `mark`), on the clock of what PLAYS: * seconds from `from`, the gaps taken out -- the segment's clock, which is the * render's. `cue` is the clip's settings (common gapCue.mjs clipGapCueOf). * Each mark is `{ at, until, seconds, count, text }`; [] when nothing is * marked. * * @param {{ cue: { mark: boolean, min: number, label: string }, gaps: Array<{ from: number, to: number, mark?: boolean }> | null | undefined, * from: number, to: number }} o * @returns {Array<{ at: number, until: number, seconds: number, count: number, text: string }>} */ export function clipGapMarks({ cue, gaps, from, to }) { if (!fin(from) || !fin(to) || to <= from) return []; const inside = gapsWithin(gaps ?? [], from, to).sort((a, b) => a.from - b.from); const joins = inside.map((g) => { const own = ownOf(gaps, g.from, g.to); return { at: offsetIn(g.from, from, inside), seconds: g.to - g.from, mark: own.length ? own.some((c) => gapMarkOn(cue, c)) : cue.mark, ...gapOwnSays(own) }; }); return gapCues(joins, { min: cue.min, seconds: gappedLength(from, to, inside) }).map((c) => ({ ...c, text: gapCueText(c.seconds, cue.label, c.why) })); } /** * Source second `src` on clipGapMarks's clock (a page whose playhead is in * source seconds: the bench), or null outside `from`–`to`. A second inside a * gap is its join, where no mark is up yet. * * @param {{ gaps: Array<{ from: number, to: number }> | null | undefined, from: number, to: number }} o * @param {number | null | undefined} src */ export function clipPlayClock({ gaps, from, to }, src) { if (!fin(src) || !fin(from) || !fin(to) || /** @type {number} */ (src) < from - 1e-6 || /** @type {number} */ (src) > to + 1e-6) return null; return offsetIn(/** @type {number} */ (src), from, gapsWithin(gaps ?? [], from, to).sort((a, b) => a.from - b.from)); } /** * The marks of one of Play's clip items, on the CUT's clock: its joins as * Play lays them (playCut.mjs gapJoins: `{ at, from, to }`, the render's gaps * when it said, so the join is where Play jumps), each marked as the clip's * own gap there says (`entryGaps`), under the clip's settings (`cue`). A * mark never outlives the clip's footage (`playEnd`). * * @param {Array<{ at: number, from: number, to: number }>} joins * @param {{ cue: { mark: boolean, min: number, label: string }, entryGaps?: Array<{ from: number, to: number, mark?: boolean }> | null, * playEnd: number }} o */ export function playGapMarks(joins, { cue, entryGaps = [], playEnd }) { const marked = (joins ?? []).map((j) => { const own = ownOf(entryGaps, j.from, j.to); return { at: j.at, seconds: j.to - j.from, mark: own.length ? own.some((c) => gapMarkOn(cue, c)) : cue.mark, ...gapOwnSays(own) }; }); return gapCues(marked, { min: cue.min, seconds: fin(playEnd) ? playEnd : Infinity }).map((c) => ({ ...c, text: gapCueText(c.seconds, cue.label, c.why) })); } /** * The mark up at `t` (the marks' clock) and its opacity (gapCueAlpha), or * null when none is. `peak` is its opacity at full, for a page that fades the * text and its box together, as drawtext's alpha does. * * `corner` is the mark's own (its gap's), when it has one. * * @param {Array<{ at: number, until: number, text: string, corner?: string }>} marks * @param {number | null | undefined} t * @returns {{ text: string, alpha: number, at: number, until: number, corner?: string } | null} */ export function gapMarkAt(marks, t) { if (!fin(t)) return null; for (const m of marks ?? []) { const alpha = gapCueAlpha(/** @type {number} */ (t), m); if (alpha > 0) return { text: m.text, alpha, at: m.at, until: m.until, ...(m.corner ? { corner: m.corner } : {}) }; } return null; } /** The mark's opacity at full (common gapCue.mjs GAP_CUE_MOTION.peak). */ export const GAP_MARK_PEAK = GAP_CUE_MOTION.peak;