// The rail in sections (`deck.pip.color: "section"`), unlabelled markers, // `deck.rail.labels: false`, and the two-line subtitle's title dedupe. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { deckLayout, deckMarkers, deckSchedule, deckText, labelledMarkers, markerRowsOf, pipSegments, pipXs, railSections, resolveDeck, titleKey, validateChrome, } from "./deck.mjs"; import { deckCues, deckHtml, fitSectionColor, sectionFuses } from "./chrome-deck.mjs"; import { contrast } from "./chrome-intro.mjs"; import rail from "./modules/rail.mjs"; const PALETTE = { bg: "#12100c", fg: "#f6f1e6", muted: "#a2957f", accent: "#c8752a", amber: "#ffc860" }; const CHROME = { engine: "hyperframes", layout: "deck" }; const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE }; const renderWith = (deck = {}) => ({ ...BASE, chrome: { ...CHROME, deck } }); const PROV = { siteOrigin: "https://example.test", channelSlug: "chan" }; const N = 8; const ENTRIES = Array.from({ length: N }, (_, i) => ({ id: `c${i}`, type: "clip", video: `v${i}`, start: 0, end: 10 })); const DURS = ENTRIES.map(() => 10); const sched = (render) => deckSchedule({ entries: ENTRIES, durs: DURS, D: 0.5, render, provenance: PROV }); const SECTIONED = (extra = {}) => renderWith({ pip: { color: "section", ...extra }, markers: [{ after: "c2", color: "#e07a9a" }, { after: "c5", color: "#5fa8d3" }], }); test("settings: section colour, unlabelled markers and rail.labels validate; bad values refused in words", () => { const ok = (deck) => validateChrome({ ...CHROME, deck }, BASE); assert.deepEqual(ok({ pip: { color: "section", sectionColor0: "#9a8fd6" }, markers: [{ after: "c2" }, { after: "c4", label: "" }] }), []); assert.deepEqual(ok({ pip: { color: "section", sectionColor0: "amber" } }), []); assert.deepEqual(ok({ rail: { labels: false } }), []); assert.match(ok({ pip: { sectionColor0: "pink" } }).join(" "), /pip\.sectionColor0 must be a #hex colour/); assert.match(ok({ pip: { color: "rainbow" } }).join(" "), /pip\.color must be "accent" or "verdict" or "section"/); assert.match(ok({ rail: { labels: "no" } }).join(" "), /rail\.labels must be true or false/); assert.match(ok({ rail: { words: false } }).join(" "), /rail\.words is not a deck setting/); // The module's descriptors carry the new keys. const keys = rail.ui.map((u) => u.key); for (const k of ["pip.sectionColor0", "rail.labels"]) assert.ok(keys.includes(k), k); assert.ok(rail.ui.find((u) => u.key === "pip.color").options.includes("section")); assert.deepEqual(rail.resolve(renderWith({})).rail, undefined, "no rail key unless set"); assert.deepEqual(rail.resolve(renderWith({ rail: { labels: false } })).rail, { labels: false }); }); test("railSections: the stretch before the first marker, then marker to marker; a marker's own pip closes the section before it", () => { const placed = [{ k: 5, x: 900, color: "#5fa8d3" }, { k: 2, x: 400, color: "#e07a9a" }]; const s = railSections(placed, 8, { pip: {} }, PALETTE); assert.deepEqual(s.colors, [PALETTE.accent, "#e07a9a", "#5fa8d3"]); assert.deepEqual(s.bounds, [400, 900]); assert.deepEqual(s.pipSection, [0, 0, 0, 1, 1, 1, 2, 2]); // sectionColor0: a hex, or a palette key. assert.equal(railSections(placed, 8, { pip: { sectionColor0: "#123456" } }, PALETTE).colors[0], "#123456"); assert.equal(railSections(placed, 8, { pip: { sectionColor0: "amber" } }, PALETTE).colors[0], PALETTE.amber); // No markers: one section, every pip in it. assert.deepEqual(railSections([], 3, { pip: {} }, PALETTE), { colors: [PALETTE.accent], bounds: [], pipSection: [0, 0, 0] }); // A marker after the last clip opens a section with no pip; two after one clip, an empty one between. const edge = railSections([{ k: 2, x: 500, color: "#111111" }, { k: 2, x: 500, color: "#222222" }, { k: 7, x: 1800, color: "#333333" }], 8, { pip: {} }, PALETTE); assert.deepEqual(edge.pipSection, [0, 0, 0, 2, 2, 2, 2, 2]); assert.deepEqual(edge.bounds, [500, 500, 1800]); }); test("sectionFuses: a bar per section with any of the fuse's span, empty ones dropped", () => { const s = { colors: ["#a", "#b", "#c", "#d"], bounds: [400, 400, 900] }; assert.deepEqual(sectionFuses(s, 48, 1872).map((f) => [f.k, f.x0, f.x1]), [["fz0", 48, 400], ["fz2", 400, 900], ["fz3", 900, 1872]]); // A boundary past the fuse's end (a marker after the last clip): its section has no bar. assert.deepEqual(sectionFuses({ colors: ["#a", "#b"], bounds: [1880] }, 48, 1872).map((f) => f.k), ["fz0"]); }); test("the deck in sections: pips, fuse bars and the marker's rings take their section's colour; the burn is the one fuse's, split", () => { const r = SECTIONED(); const s = sched(r); const c = deckCues(s, r); assert.deepEqual(c.pips.map((p) => p.section), [0, 0, 0, 1, 1, 1, 2, 2]); assert.equal(c.init.fuse, undefined, "no single fuse in sections"); assert.deepEqual(c.sections.fuses.map((f) => f.k), ["fz0", "fz1", "fz2"]); assert.deepEqual(c.sections.rings, [0, 1, 2]); assert.deepEqual(c.init.mr0, { opacity: 1 }); assert.deepEqual(c.init.mr1, { opacity: 0 }); // Every bar ends burnt through but the last's share past the last pip (none here: even spacing ends on it). const last = (k) => c.cues.filter((q) => q.k === k).at(-1)?.to.scaleX; assert.equal(last("fz0"), 1); assert.equal(last("fz1"), 1); assert.equal(last("fz2"), 1); // The burns are in time order and never overlap on one bar; the section 0 bar // finishes when the fuse crosses the first boundary, as the marker flag pops. for (const k of ["fz0", "fz1", "fz2"]) { const cs = c.cues.filter((q) => q.k === k); for (let i = 1; i < cs.length; i += 1) assert.ok(cs[i].at >= cs[i - 1].at + cs[i - 1].dur - 1e-6, `${k} cue ${i}`); } const fz0End = c.cues.filter((q) => q.k === "fz0").at(-1); const mk0 = c.markers[0]; assert.ok(Math.abs(fz0End.at + fz0End.dur - mk0.at) < 0.05, `${fz0End.at + fz0End.dur} vs ${mk0.at}`); // The rings switch once per section change, in order. const ringCues = c.cues.filter((q) => /^mr\d$/.test(q.k)); assert.deepEqual(ringCues.map((q) => `${q.k}:${q.to.opacity}`), ["mr0:0", "mr1:1", "mr1:0", "mr2:1"]); const html = deckHtml(s, r, {}); const cols = c.sections.colors.map((x) => fitSectionColor(x, "#000000")); assert.equal(cols.length, 3); assert.match(html, /