// The deck's two-line subtitle (`render.chrome.deck.subtitle.lines: 2`): the // source's title on a line of its own over the rest of the source line, the // band one line taller through the layout engine, and a deck that does not // set it laid out, scheduled and drawn exactly as before. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { deckSubtitle, deckSubtitleLines, deckSubtitleLinesParts, deckSubtitleParts } from "./attribution.mjs"; import { deckHtml, subtitleMarkup } from "./chrome-deck.mjs"; import { titleLastParts } from "./chrome-finale.mjs"; import { deckGeometry, deckLayout, deckText, estimateSchedule, feedGeometry, resolveDeck, subtitleBoxes, validateChrome, } from "./deck.mjs"; import { slotRect, slotRects } from "./modules/layout.mjs"; import { reservedFooterHeight } from "./render-cards.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const renderOf = (deck = {}, { width = 1920, height = 1080 } = {}) => ({ width, height, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck }, }); const TWO = { subtitle: { lines: 2, parts: ["channel", "title", "date", "clock"] } }; const LONG = 'Working my way back to "normal" -- a very long stream title that will never fit on one line of the deck at all'; const PARTS = { channel: "EmberParadox", title: LONG, date: "2026-10-28", at: 3725 }; test("the default is one line, and a deck without the key lays out as it always did", () => { assert.equal(resolveDeck(renderOf()).subtitle.lines, 1); const g = deckGeometry(renderOf()); // The documented geometry: 1574×886 at (173, 2) over a 190 px deck. assert.deepEqual(g.footage, { x: 173, y: 2, width: 1574, height: 886 }); assert.deepEqual(g.deck, { x: 0, y: 890, width: 1920, height: 190 }); assert.equal(subtitleBoxes(resolveDeck(renderOf())).extra, 0); const t = deckLayout(renderOf()).text; assert.deepEqual(t, { x: 48, width: 1626, titleSize: 54, subtitleSize: 26, titleY: 49, titleBox: 65, ruleY: 120, subtitleY: 130, subtitleBox: 34 }); // `lines: 1` written out is the same deck as no key. assert.deepEqual(deckGeometry(renderOf({ subtitle: { lines: 1 } })), g); assert.deepEqual(deckLayout(renderOf({ subtitle: { lines: 1 } })), deckLayout(renderOf())); }); test("two lines at 1920×1080: the band grows by the head line and every slot moves with it", () => { const render = renderOf({ ...TWO, footageScale: 0.78 }); const one = renderOf({ footageScale: 0.78 }); const sb = subtitleBoxes(resolveDeck(render)); assert.deepEqual(sb, { lines: 2, subtitleSize: 26, subtitleBox: 34, headSize: 31, headBox: 39, extra: 39 }); const g = deckGeometry(render); assert.deepEqual(g.deck, { x: 0, y: 1080 - 229, width: 1920, height: 229 }); // The footage keeps its size and stands on the band's top edge, centred in what is left. assert.equal(g.footage.width, deckGeometry(one).footage.width); assert.ok(g.footage.y + g.footage.height <= g.deck.y, "the footage clears the band"); assert.ok(g.footage.y >= 0); // The layout engine's slots are the geometry's: the footer is the band, the rest stand above it. assert.deepEqual(slotRect("footer", render), g.deck); const slots = slotRects(render); for (const s of ["footage", "stamp", "panel", "side", "popup"]) { assert.ok(slots[s].y + slots[s].height <= g.deck.y, `${s} clears the band`); } assert.equal(feedGeometry(render).column.height, g.deck.y, "the feed's column stands on the band"); assert.ok(slotRects(render, { feed: true }).footage.y + slotRects(render, { feed: true }).footage.height <= g.deck.y); // Inside the band: the title where it was, the two lines under it, the QR and the block in the body. const lay = deckLayout(render); const t = lay.text; assert.equal(t.titleY, deckLayout(one).text.titleY, "the block keeps the air it had"); assert.equal(t.lines, 2); assert.equal(t.headSize, 31); assert.equal(t.headBox, 39); assert.ok(t.subtitleY + t.headBox + t.subtitleBox <= lay.height - 8, "both lines inside the band"); assert.ok(lay.qr.y + lay.qr.size <= lay.height, "the QR inside the band"); // A card leaving the deck free at the foot leaves the band as drawn. assert.equal(reservedFooterHeight(renderOf({ ...TWO, footageScale: 0.78, overCards: "show" })), 229); assert.equal(reservedFooterHeight(renderOf({ overCards: "show" })), 190); }); // Lane vertical-deck (9 Nov): a frame shorter than 1080 has its band scaled with its height (deck.mjs deckScale) -- // at 720 two thirds of the 1080 band, its head line too (title 36: a 28 px head box) -- where it was the 1080 band // unscaled (229 px), which refused the default footageScale. footageScale 0.6 fits either way. test("two lines at 1280×720: the band scaled with the frame, and the footage still above it", () => { const render = renderOf({ ...TWO, footageScale: 0.6 }, { width: 1280, height: 720 }); assert.deepEqual(validateChrome(render.chrome, render), []); const g = deckGeometry(render); assert.deepEqual(g.deck, { x: 0, y: 720 - 155, width: 1280, height: 155 }); assert.ok(g.footage.y + g.footage.height <= g.deck.y); const lay = deckLayout(render); assert.ok(lay.text.subtitleY + lay.text.headBox + lay.text.subtitleBox <= lay.height - 8); assert.ok(lay.text.x + lay.text.width <= lay.qr.x, "the text column stops short of the QR"); }); test("validation: the band that does not leave the footage room is refused in words that say how to fix it", () => { const render = renderOf(TWO); const errors = validateChrome(render.chrome, render); assert.equal(errors.length, 1); assert.match(errors[0], /footageScale 0\.82 needs 886px but a 229px deck \(height 190 \+ 39 for subtitle\.lines 2\) leaves 851 \(footageScale at most 0\.787, or subtitle\.lines 1\)/); assert.deepEqual(validateChrome(renderOf({ ...TWO, footageScale: 0.787 }).chrome, renderOf()), []); const bad = (subtitle) => validateChrome({ engine: "hyperframes", layout: "deck", deck: { footageScale: 0.7, subtitle } }, {}); assert.match(bad({ lines: 3 })[0], /subtitle\.lines must be 1 or 2/); assert.match(bad({ lines: "2" })[0], /subtitle\.lines must be 1 or 2/); assert.match(bad({ head: ["title", "title"] })[0], /subtitle\.head must be "auto" or a list/); assert.match(bad({ lines: 2, parts: ["title"] })[0], /leaving the second line empty/); assert.match(bad({ lines: 2, parts: ["date", "clock"] })[0], /head \(auto\) names title, which subtitle\.parts leaves out/); assert.match(bad({ lines: 2, parts: ["title", "date"], head: ["channel"] })[0], /names channel/); assert.deepEqual(bad({ lines: 2, parts: ["channel", "title", "date"], head: ["channel", "title"] }), []); assert.deepEqual(bad({ lines: 2 }), [], "auto parts: the title heads, the date follows"); assert.match(bad({ nope: 1 })[0], /subtitle\.nope is not a deck setting/); }); test("deckSubtitleLines: the head's parts over the rest, each joined as the one line is", () => { const opts = { parts: ["channel", "title", "date", "clock"] }; assert.deepEqual(deckSubtitleLines(PARTS, opts), [LONG, "EmberParadox · Oct 28, 2026 · 1:02:05"]); // The one line is unchanged, and is the two joined in parts order. assert.equal(deckSubtitle(PARTS, opts), `EmberParadox · ${LONG} · Oct 28, 2026 · 1:02:05`); assert.deepEqual(deckSubtitleLines(PARTS, { ...opts, head: ["channel", "title"] }), [`EmberParadox · ${LONG}`, "Oct 28, 2026 · 1:02:05"]); assert.deepEqual(deckSubtitleLines(PARTS, { ...opts, dateFormat: "iso" })[1], "EmberParadox · 2026-10-28 · 1:02:05"); // auto: title and date, the channel only across channels. assert.deepEqual(deckSubtitleLines(PARTS, {}), [LONG, "Oct 28, 2026"]); assert.deepEqual(deckSubtitleLines(PARTS, {}, true), [LONG, "EmberParadox · Oct 28, 2026"]); // A line with nothing on it: no two lines (the one line is drawn). assert.equal(deckSubtitleLines({ ...PARTS, title: "" }, opts), null); assert.equal(deckSubtitleLines(PARTS, { parts: ["title"] }), null); }); test("deckText: a clip's and a still's automatic subtitle in two lines; a typed one, or a one-line deck, never", () => { const deck2 = resolveDeck(renderOf(TWO)); const deck1 = resolveDeck(renderOf({ subtitle: { parts: TWO.subtitle.parts } })); const clip = { type: "clip", id: "x02", video: "v", start: 3725, end: 3740, channel: "ember", title: LONG, date: "2026-10-28" }; const meta = { title: LONG, uploadDate: "20261028", channel: "EmberParadox" }; const prov = { channelSlug: "ember", siteOrigin: "https://example.test" }; const two = deckText(clip, meta, prov, deck2, false); assert.equal(two.subtitleLines.length, 2); assert.equal(two.subtitleLines[0], LONG); assert.match(two.subtitleLines[1], /Oct 28, 2026 · 1:02:05$/); const one = deckText(clip, meta, prov, deck1, false); assert.equal(one.subtitle, two.subtitle, "the whole line is the same either way"); assert.equal("subtitleLines" in one, false); assert.equal("subtitleLines" in deckText({ ...clip, onscreen: { subtitle: "typed" } }, meta, prov, deck2, false), false); const still = deckText({ type: "image", id: "i1", title: "A still", date: "2026-10-01" }, null, prov, deck2, false); assert.deepEqual(still.subtitleLines, ["A still", "Oct 1, 2026"]); assert.equal("subtitleLines" in deckText({ type: "card", id: "k", heading: "H", sub: "s" }, null, prov, deck2, false), false); }); test("the schedule carries the lines only in a two-line deck", () => { const manifest = (deck) => ({ schemaVersion: 1, provenance: { channelSlug: "ember", siteOrigin: "https://example.test" }, render: renderOf(deck), timeline: [ { type: "clip", id: "x02", video: "v", start: 10, end: 20, title: LONG, date: "2026-10-28" }, { type: "clip", id: "c01", video: "w", start: 0, end: 8, title: "Short", date: "2026-10-27", onscreen: { title: "A title" } }, ], }); const one = estimateSchedule(manifest({})); assert.ok(one.segments.every((s) => !("subtitleLines" in s))); const two = estimateSchedule(manifest({ ...TWO, footageScale: 0.78 })); assert.deepEqual(two.segments.map((s) => s.subtitleLines?.[0]), [LONG, "Short"]); assert.deepEqual(two.segments.map((s) => s.subtitle), estimateSchedule(manifest({ subtitle: { parts: TWO.subtitle.parts } })).segments.map((s) => s.subtitle)); }); /** A cut of a long-titled untitled clip, a short-titled titled one, and a typed subtitle. */ function schedule(lines) { const seg = (id, start, extra) => ({ id, type: "clip", start, duration: 10, end: start + 10, title: "", qrUrl: null, hideDeck: false, ...extra }); const L = (a, b) => (lines ? { subtitleLines: [a, b] } : {}); return { version: 1, kind: "deck", estimated: true, fps: 30, transition: 0.5, total: 29, multiChannel: false, segments: [ seg("x02", 0, { subtitle: `EmberParadox · ${LONG} · Oct 28, 2026 · 1:02:05`, ...L(LONG, "EmberParadox · Oct 28, 2026 · 1:02:05") }), seg("c01", 9.5, { title: "A title", subtitle: "EmberParadox · Short · Oct 27, 2026", ...L("Short", "EmberParadox · Oct 27, 2026") }), seg("c02", 19, { title: "Typed", subtitle: "a typed line" }), ], }; } test("the page: two lines where the schedule gave them, a fitted head, and a one-line deck's page untouched", () => { const render = renderOf({ ...TWO, footageScale: 0.78 }); const items = []; const html = deckHtml(schedule(true), render, { items }); // The long title is in the markup whole: the page fits it, never the text. assert.ok(html.includes(`
${LONG.replace(/"/g, """)}
`)); assert.match(html, /class="seg untitled two" data-seg="x02"/); assert.match(html, /class="seg two" data-seg="c01"/); assert.match(html, /class="seg" data-seg="c02"/, "a typed subtitle stays one line"); assert.match(html, /
EmberParadox<\/span>·<\/span>Oct 28, 2026<\/span>/); assert.match(html, /\.seg\.two \.sc \{ height: 73px; \}/); assert.match(html, /\.deck-sub\.head \{ font-size: 31px; line-height: 39px;/); assert.match(html, /function fitHead\(node\)/); assert.match(html, /Math\.ceil\(base \* 0\.7\)/, "the head shrinks to 70 % before it ellipsizes"); // The items carry the line layout: a frame that shows a clip's text keys on its lines. const one = []; deckHtml(schedule(false), renderOf({ footageScale: 0.78 }), { items: one }); const item = (list, k) => list.find((i) => i.key === k).html; assert.notEqual(item(items, "s0"), item(one, "s0")); assert.match(item(items, "s0"), /deck-sub head/); assert.equal(item(items, "s2"), item(one, "s2"), "a one-line segment's item is the one-line item"); // A one-line deck's page has none of it -- and ignores a stray subtitleLines. const plain = deckHtml(schedule(false), renderOf()); assert.equal(deckHtml(schedule(true), renderOf()), plain); for (const s of ["fitHead", "deck-sub head", "seg two", "untitled two", ".two", "data-sub=", ".fitting"]) assert.equal(plain.includes(s), false, s); }); // --------------------------------------------------------------------------- // THE PARTS BY TOKEN (weight video, variant A: "the dates are getting // truncated"): a line `[channel, title, date, clock]` has its date in the // MIDDLE, and the positional rule shrank it with the title ("Huge Win For // Cornell 7, Mamdani … · Oct … · 1:08:48"). The automatic line now says what // each part is, and the page keeps the date and the clock whole by token. // --------------------------------------------------------------------------- const FOUR = { subtitle: { parts: ["channel", "title", "date", "clock"] } }; test("deckSubtitleParts: the line's parts as [token, text], the empty ones dropped; the lines' parts split by the head", () => { assert.deepEqual(deckSubtitleParts(PARTS, FOUR.subtitle), [ ["channel", "EmberParadox"], ["title", LONG], ["date", "Oct 28, 2026"], ["clock", "1:02:05"], ]); assert.equal(deckSubtitleParts(PARTS, FOUR.subtitle).map(([, v]) => v).join(" · "), deckSubtitle(PARTS, FOUR.subtitle)); assert.deepEqual(deckSubtitleParts({ ...PARTS, title: "" }, {}), [["date", "Oct 28, 2026"]]); assert.deepEqual(deckSubtitleLinesParts(PARTS, FOUR.subtitle), [ [["title", LONG]], [["channel", "EmberParadox"], ["date", "Oct 28, 2026"], ["clock", "1:02:05"]], ]); assert.equal(deckSubtitleLinesParts({ ...PARTS, title: "" }, FOUR.subtitle), null); }); test("deckText and the schedule: the automatic line carries its parts; a typed one, a card or a post item none", () => { const deck = resolveDeck(renderOf(FOUR)); const clip = { type: "clip", id: "x02", video: "v", start: 3725, end: 3740, channelTitle: "EmberParadox", title: LONG, date: "2026-10-28", cite: 3725 }; const t = deckText(clip, {}, { channelSlug: "ember" }, deck, false); assert.deepEqual(t.subtitleParts.map(([k]) => k), ["channel", "title", "date", "clock"]); assert.equal(t.subtitleParts.map(([, v]) => v).join(" · "), t.subtitle); assert.equal("subtitleLinesParts" in t, false, "one line: no lines' parts"); assert.equal("subtitleParts" in deckText({ ...clip, onscreen: { subtitle: "typed" } }, {}, {}, deck, false), false); assert.equal("subtitleParts" in deckText({ type: "card", id: "k", heading: "H", sub: "s" }, null, {}, deck, false), false); const deck2 = resolveDeck(renderOf({ subtitle: { ...FOUR.subtitle, lines: 2 }, footageScale: 0.78 })); const t2 = deckText(clip, {}, { channelSlug: "ember" }, deck2, false); assert.deepEqual(t2.subtitleLinesParts.map((l) => l.map(([k]) => k)), [["title"], ["channel", "date", "clock"]]); const sched = estimateSchedule({ schemaVersion: 1, provenance: { channelSlug: "ember", siteOrigin: "https://example.test" }, render: renderOf(FOUR), timeline: [clip, { ...clip, id: "c03", onscreen: { subtitle: "typed" } }], }); assert.deepEqual(sched.segments[0].subtitleParts.map(([k]) => k), ["channel", "title", "date", "clock"]); assert.equal("subtitleParts" in sched.segments[1], false); }); test("the page sets the automatic line by token: the date and the clock never shrink, the title gives way; a typed line by position", () => { const four = [["channel", "TheQuartering (Rumble)"], ["title", LONG], ["date", "Oct 23, 2026"], ["clock", "1:08:48"]]; const line = four.map(([, v]) => v).join(" · "); const m = subtitleMarkup(line, four); assert.match(m, /Oct 23, 2026<\/span>/); assert.match(m, /1:08:48<\/span>/); assert.match(m, //); // Parts that are not the line (stale against a retyped subtitle), or none: by position, as before. assert.equal(subtitleMarkup("a typed · line", four), subtitleMarkup("a typed · line")); assert.equal(subtitleMarkup(line).includes("data-p"), false); const seg = (id, start, extra) => ({ id, type: "clip", start, duration: 10, end: start + 10, title: "", qrUrl: null, hideDeck: false, ...extra }); const sched = { version: 1, kind: "deck", estimated: true, fps: 30, transition: 0.5, total: 19, multiChannel: false, segments: [seg("c01", 0, { subtitle: line, subtitleParts: four }), seg("c02", 9.5, { title: "Typed", subtitle: "a typed line · Oct 1" })], }; const html = deckHtml(sched, renderOf(FOUR)); assert.match(html, /data-seg="c01" data-k="s0" data-sub="/, "the automatic line is what a cleared typed one puts back"); assert.doesNotMatch(html, /data-seg="c02" data-k="s1" data-sub=/); assert.match(html, /\.deck-sub \.part\[data-p="title"\] \{ flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; \}/); assert.match(html, /\.deck-sub \.part:not\(\[data-p\]\):not\(:first-child\):not\(:last-child\)/, "a typed line keeps the positional rule"); assert.doesNotMatch(html, /\[data-p="date"\][^}]*flex: 0 1/, "nothing lets the date shrink"); assert.doesNotMatch(html, /\[data-p="clock"\][^}]*flex: 0 1/, "nothing lets the clock shrink"); // The finale's clip card: the title last by token, wherever it stood. assert.deepEqual(titleLastParts(line, four).map(([k]) => k), ["channel", "date", "clock", "title"]); assert.equal(titleLastParts("typed · line · here", four), null); });