// 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(`