// The gap mark as a HyperFrames module (lane gap-cue, slice 1d): the schedule's `gapCue` slice (gap-cue-slice.mjs) // from the cut records the schedule already reads -- an old record with no `gapMarks` field included (the // retrofit: a chrome-only pass, no re-cut) -- its two places (over the footage at the corner, in the deck at the end // of the source line, beside the source status and the QR), the hop off a stamp while it is up, a clip whose // segment drew its own marks left out; the module's page and regions; and the mark off or unset is no slice, no // region, and no change to any page or schedule, byte for byte. // // Run with: node --test umtool/report-to-video/gap-cue-slice.test.mjs import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import test from "node:test"; import { deckHtml } from "./chrome-deck.mjs"; import { gapCueHtml, gapCueWindows } from "./chrome-gap-cue.mjs"; import { deckGeometry, deckLayout, estimateSchedule, overlayBox, stampGeometry } from "./deck.mjs"; import { tallyOf } from "./factcheck.mjs"; import { gapCueDeckRect, gapCueSlice, withGapCue } from "./gap-cue-slice.mjs"; import { gapMarkByChrome } from "./gap-mark.mjs"; import { gapCueBorderOf, gapCueBoxStyle, gapCueLook } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { verticalRender } from "./vertical.mjs"; import gapCueModule from "./modules/gap-cue.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const FONTS = { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" }; const sha = (s) => createHash("sha256").update(s).digest("hex"); const clip = (id, video, start, extra = {}) => ({ id, type: "clip", video, start, end: start + 20, cite: start + 2, quote: "a synthetic line", ...extra }); function manifest({ gapCue = undefined, deck = {}, chrome = {}, timeline = null, render = {} } = {}) { return { title: "Synthetic cut", provenance: { channelSlug: "synth-channel", channel: "Synth Channel", siteOrigin: "https://archive.example.test" }, render: { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck, ...chrome }, ...(gapCue !== undefined ? { gapCue } : {}), ...render, }, timeline: timeline ?? [ clip("c01", "synthvid001", 600, { onscreen: { title: "The first moment" }, gaps: [{ from: 605, to: 617 }] }), clip("c02", "synthvid002", 1200, { onscreen: { title: "The second moment" } }), ], }; } const META = (n) => ({ title: `Synthetic stream ${n}`, uploadDate: "20310301", channel: "Synth Channel", webpageUrl: `https://video.example.test/${n}` }); const METAS = [META(1), META(2)]; const scheduleOf = (m, metas = METAS) => estimateSchedule(m, { metas }); /** A cut record as a build before this slice wrote it: start, end, gaps -- no gapMarks. */ const OLD_RECORD = { version: 1, id: "c01", video: "synthvid001", start: 599.8, end: 620.1, snapped: { start: 599.8, end: 620.1 }, gaps: [{ from: 605, to: 617 }], framing: { layout: "deck" } }; const sliceOf = (m, records = new Map([["c01", OLD_RECORD]]), metas = METAS) => gapCueSlice(scheduleOf(m, metas), { entries: m.timeline, render: m.render, records, provenance: m.provenance }); test("who draws it: the module wherever the deck is laid over the picture, else the drawtext", () => { const deck = manifest().render; assert.equal(gapMarkByChrome(deck), true); assert.equal(gapMarkByChrome(deck, { noChrome: true }), false, "--no-chrome"); assert.equal(gapMarkByChrome({ ...deck, chrome: undefined }), false, "the plain cut"); assert.equal(gapMarkByChrome(verticalRender({ ...deck, format: "vertical", vertical: { deck: "stacked" } })), true, "the stacked vertical deck"); assert.equal(gapMarkByChrome(verticalRender({ ...deck, format: "vertical", vertical: { deck: "bare" } })), false, "a bare vertical cut"); }); test("retrofit: an old record (no gapMarks field) gives the marks on the cut's clock -- the join, its life, its text", () => { const m = manifest({ gapCue: { mark: true } }); const s = sliceOf(m); const seg = scheduleOf(m).segments[0]; assert.equal(s.marks.length, 1); const k = s.marks[0]; assert.equal(k.id, "c01.g0"); assert.equal(k.segment, "c01"); assert.equal(k.text, "» 12 s"); // The join is 5.2 s into the segment (599.8 → 605), on the cut's clock from the segment's start; up a life. assert.ok(Math.abs(k.at - (seg.start + 5.2)) < 1e-3, `at ${k.at}`); assert.ok(Math.abs(k.until - k.at - 1.1) < 1e-3, `until ${k.until}`); assert.equal(k.place, "footage"); assert.equal(k.corner, "bl", "the deck's free corner"); const box = overlayBox(m.render); assert.ok(k.rect.x >= box.x && k.rect.y + k.rect.h <= box.y + box.height, "inside the footage box, at its foot"); assert.equal(s.inSegment, undefined); }); test("with no record (a preview before a build) the play window and the clip's own gaps stand in", () => { const m = manifest({ gapCue: { mark: true } }); const s = sliceOf(m, null); assert.equal(s.marks.length, 1); assert.equal(s.marks[0].text, "» 12 s"); }); test("a pieced record: every second left out -- between the pieces too -- and joins inside a life are one mark", () => { const rec = { ...OLD_RECORD, start: 600, end: 900, gaps: [{ from: 605, to: 617 }, { from: 617.5, to: 890 }] }; const m = manifest({ gapCue: { mark: true }, timeline: [clip("c01", "synthvid001", 600, { end: 900, gaps: [{ from: 605, to: 617 }, { from: 617.5, to: 890 }] }), clip("c02", "synthvid002", 1200)] }); const s = sliceOf(m, new Map([["c01", rec]])); assert.equal(s.marks.length, 1, "merged"); assert.equal(s.marks[0].count, 2); assert.equal(s.marks[0].text, "» 4:45", "12 s and 272.5 s"); }); test("a clip whose segment drew its own marks (the drawtext path) is left out: never both on one frame", () => { const m = manifest({ gapCue: { mark: true } }); const s = sliceOf(m, new Map([["c01", { ...OLD_RECORD, gapMarks: [{ at: 5.2, until: 6.3, seconds: 12, text: "» 12 s", corner: "bl" }] }]])); assert.deepEqual(s, { marks: [], inSegment: ["c01"] }); assert.equal(gapCueModule.on(withGapCue(scheduleOf(m), { entries: m.timeline, render: m.render, records: new Map([["c01", { ...OLD_RECORD, gapMarks: [{}] }]]) })), false); }); test("place deck: right-aligned at the end of the source line's row, left of the QR's plate, centred on the row", () => { const m = manifest({ gapCue: { mark: true, place: "deck" } }); const sched = scheduleOf(m); const s = sliceOf(m); const k = s.marks[0]; assert.equal(k.place, "deck"); const { deck: band } = deckGeometry(m.render); const lay = deckLayout(m.render, { tally: tallyOf(sched, m.render), schedule: sched }); assert.ok(k.rect.x + k.rect.w <= band.x + lay.qr.x - 46 - 20, `left of the plate (${JSON.stringify(k.rect)})`); assert.ok(k.rect.x + k.rect.w <= band.x + lay.text.x + lay.text.width, "inside the text column"); const mid = band.y + lay.text.subtitleY + lay.text.subtitleBox / 2; assert.ok(Math.abs(k.rect.y + k.rect.h / 2 - mid) <= 1, "centred on the source line's row"); assert.ok(k.rect.y >= band.y + lay.text.titleY + lay.text.titleBox, "under the title's box"); assert.ok(k.font < lay.text.subtitleSize, "a size under the source line"); }); test("place deck beside the source status: it fits after the line's words, or it falls to the footage -- the narrowest column too", () => { const STAMP = { refreshedAt: "2031-03-02T00:00:00.000Z", sources: { "synth-channel/synthvid001": { now: "members_only", since: null, asOf: "2031-03-01T20:00:00Z", first: "public", firstAt: "2031-03-01T10:05:00Z", firstWhen: "live", from: "corpus", evidence: [] } } }; const withStatus = { ...manifest({ gapCue: { mark: true, place: "deck" }, deck: { subtitle: { parts: ["channel", "date", "clock"], status: "end" } } }), sourceStatus: STAMP }; const s = sliceOf(withStatus); const seg = scheduleOf(withStatus).segments[0]; assert.match(seg.subtitle, /members-only/, "the line carries its status"); assert.equal(s.marks[0].place, "deck", "a short line (channel, date, clock, status) leaves room for the mark"); // The narrowest column: a tally beside the QR (a stamped claim) and a long source title in the line too. const LONG = [1, 2].map((n) => ({ ...META(n), title: `Synthetic stream ${n}: a long title about a great many things at once` })); const narrow = { ...manifest({ gapCue: { mark: true, place: "deck" }, deck: { subtitle: { status: "end" } }, chrome: { factcheck: { stamp: { seconds: 1 } } }, timeline: [ clip("c01", "synthvid001", 600, { onscreen: { title: "The first moment" }, gaps: [{ from: 605, to: 617 }], claim: { id: "k1", verdict: "CORROBORATED" } }), clip("c02", "synthvid002", 1200, { claim: { id: "k2", verdict: "CORROBORATED" } }), ], }), sourceStatus: STAMP, }; const sch = scheduleOf(narrow, LONG); const lay = deckLayout(narrow.render, { tally: tallyOf(sch, narrow.render), schedule: sch }); assert.ok(lay.tally, "a tally narrows the column"); const ns = sliceOf(narrow, undefined, LONG); assert.equal(ns.marks[0].place, "footage", "no room on the row: over the footage, never over the line or the status"); assert.equal(ns.marks[0].fell, "row"); // Asked directly: the row's own answer. assert.deepEqual(gapCueDeckRect({ render: narrow.render, schedule: sch, segment: sch.segments[0], text: "» 12 s" }), { fell: "row" }); }); test("place deck in the stacked vertical deck, or over a segment that hides the deck: over the footage", () => { const m = manifest({ gapCue: { mark: true, place: "deck" } }); const v = { ...m, render: verticalRender({ ...m.render, format: "vertical" }) }; const s = gapCueSlice(scheduleOf(v), { entries: v.timeline, render: v.render, records: new Map([["c01", OLD_RECORD]]) }); assert.equal(s.marks[0].place, "footage"); assert.equal(s.marks[0].fell, "stacked"); const sch = scheduleOf(m); assert.deepEqual(gapCueDeckRect({ render: m.render, schedule: sch, segment: { ...sch.segments[0], hideDeck: true }, text: "» 1 s" }), { fell: "hidden" }); }); test("over the footage it hops off a stamp while the stamp is up (its corner), and stays where asked otherwise", () => { // A stamp at the bottom left, up over the join: the mark hops to the next free corner. const m = manifest({ gapCue: { mark: true }, chrome: { factcheck: { stamp: { position: "bottom-left", seconds: 8 } } }, // Stamped just after the gap: the stamp slams in at the join and stays 8 s. timeline: [clip("c01", "synthvid001", 600, { gaps: [{ from: 605, to: 617 }], claim: { id: "k1", verdict: "CORROBORATED", at: 617.2 } }), clip("c02", "synthvid002", 1200)], }); const sch = scheduleOf(m); const st = sch.factcheck.stamps[0]; const k = sliceOf(m).marks[0]; const g = stampGeometry(m.render); assert.ok(st.at < k.until && st.out[1] > k.at, `the stamp is up while the mark is (${st.at}-${st.out[1]} vs ${k.at}-${k.until})`); assert.notEqual(k.corner, "bl", "hopped off the stamp"); const r = k.rect; assert.ok(!(r.x < g.x + g.width && g.x < r.x + r.w && r.y < g.y + g.height && g.y < r.y + r.h), "not over the stamp"); // Without the stamp, the deck's free corner. const bare = manifest({ gapCue: { mark: true } }); assert.equal(sliceOf(bare).marks[0].corner, "bl"); }); test("the page: one mark, its text escaped, the look's CSS (a real border, the deck's face), cues at the join and the end", () => { const m = manifest({ gapCue: { mark: true, label: "{s} " } }); const sched = withGapCue(scheduleOf(m), { entries: m.timeline, render: m.render, records: new Map([["c01", OLD_RECORD]]) }); const [w] = gapCueWindows(sched); const html = gapCueHtml(sched, m.render, w, { fonts: FONTS }); assert.match(html, /data-gm="12 s <later>"/); assert.ok(!html.includes(""), "escaped"); // Variant B: the border in the deck's accent (this palette's #a97bff), at full opacity; the box at 0.9. assert.match(html, /border: 2px solid rgba\(169, 123, 255, 1\)/); assert.match(html, /linear-gradient\(rgba\(16, 16, 16, 0\.9\), rgba\(16, 16, 16, 0\.9\)\)/); assert.match(html, /font-family: 'DeckSansBold'/); assert.match(html, /id="gap-cue-data"/); const data = JSON.parse(/