// The deck past a dozen markers, and subsections (2026-11-01): the marker cap // is one shared constant (marker-limits.mjs, 32); the rail lays 24 and 32 // labelled flags without two labels meeting, saying the ones it can and a tick // for the rest; a marker with `level: 2` is a subsection -- a shorter flag in // its section's colour, a quieter label, no colour band of its own, "Section › // Sub" in the section title -- and the cut's first marker must be a section. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { deckLayout, deckMarkers, deckSchedule, MARKER_LABEL_MIN_BOX, MARKER_LEVELS, MARKER_LIMITS, MARKER_SUB_LABEL_SIZE, markerLabelWidth, markerRowsOf, pipSegments, pipXs, railSections, resolveDeck, validateChrome, validateDeckMarkers, } from "./deck.mjs"; import { deckHtml, sectionTitleAt, sectionTitleTimeline } from "./chrome-deck.mjs"; import * as limits from "./marker-limits.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const CHROME = { engine: "hyperframes", layout: "deck" }; const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE }; const PROV = { siteOrigin: "https://example.test", channelSlug: "chan" }; const renderWith = (deck = {}) => ({ ...BASE, chrome: { ...CHROME, deck } }); const N = 40; const ENTRIES = Array.from({ length: N }, (_, i) => ({ id: `c${i}`, type: "clip", video: `v${i}`, start: 0, end: 30 })); const DURS = ENTRIES.map(() => 30); const COLORS = ["#e070d0", "#f2a65a", "#ffc861", "#c4a1ff", "#6fc3ff", "#7fdc9a", "#5fd1c9", "#ff7a59"]; /** `n` labelled markers after c0…c(n-1), every `subEvery`-th one a subsection (none when 0). */ const many = (n, { subEvery = 0, label = (i) => `Section ${i + 1}: words` } = {}) => Array.from({ length: n }, (_, i) => ({ after: `c${i}`, label: label(i), color: COLORS[i % COLORS.length], ...(subEvery && i % subEvery === subEvery - 1 ? { level: 2 } : {}), })); function lay(render) { const s = deckSchedule({ entries: ENTRIES, durs: DURS, D: 0.5, render, provenance: PROV }); const l = deckLayout(render, { schedule: s }); const pipped = pipSegments(s); const xs = pipXs(pipped.length, l.pipTrack.x0, l.pipTrack.x1, "even"); return { s, l, ms: deckMarkers(s, render, xs, pipped, l), pipped }; } /** No two labels in a row meet; row 0 keeps clear of row 1's sticks; every box inside the deck; a hidden label has no box. */ function assertLegible(ms, W) { const shown = ms.filter((m) => m.label && !m.hide); for (const row of [0, 1]) { const inRow = shown.filter((m) => (m.row ?? 0) === row).sort((a, b) => a.x - b.x); for (let j = 1; j < inRow.length; j += 1) { assert.ok(inRow[j - 1].box[1] < inRow[j].box[0], `row ${row}: ${inRow[j - 1].after} ${inRow[j - 1].box} and ${inRow[j].after} ${inRow[j].box} meet`); } } const sticks = shown.filter((m) => m.row === 1).map((m) => m.x); for (const m of shown.filter((x) => (x.row ?? 0) === 0)) { for (const x of sticks) assert.ok(x < m.box[0] || x > m.box[1], `${m.after}'s label crosses a stick at ${x}`); } for (const m of shown) { assert.ok(m.box[0] >= 16 && m.box[1] <= W - 16, `${m.after} ${m.box}`); const w = m.box[1] - m.box[0]; assert.ok(w >= MARKER_LABEL_MIN_BOX || markerLabelWidth(m.label, m.level === 2 ? MARKER_SUB_LABEL_SIZE : 18) <= w, `${m.after}'s box ${m.box} is too narrow to say anything and was not hidden`); } for (const m of ms.filter((x) => x.hide)) assert.equal(m.box[0], m.box[1], `${m.after} is hidden: an empty box`); } test("the cap is one constant: 32 markers, 24 characters, levels 1 and 2 -- deck.mjs re-exports marker-limits.mjs", () => { assert.equal(MARKER_LIMITS, limits.MARKER_LIMITS); assert.deepEqual({ ...MARKER_LIMITS }, { count: 32, label: 24 }); assert.deepEqual([...MARKER_LEVELS], [1, 2]); assert.equal(limits.SUBSECTION_SEPARATOR, " › "); const bad = (markers) => validateChrome({ ...CHROME, deck: { markers } }, BASE); assert.deepEqual(bad(many(32)), []); assert.match(bad(many(33)).join(" "), /has 33 markers \(at most 32\)/); }); for (const n of [24, 32]) { test(`${n} labelled markers stagger legibly: no label meets another, a stick or the edge; the rest are ticks, never "…" alone`, () => { const r = renderWith({ markers: many(n) }); const t0 = Date.now(); const { s, l, ms } = lay(r); assert.ok(Date.now() - t0 < 2000, `laid in ${Date.now() - t0} ms`); assert.equal(ms.length, n); assert.equal(markerRowsOf(s, r), 2); assertLegible(ms, l.width); // Two rows say more than one would: the labels with words, at least as many // as half the flags (each row holds every other one or so). const shown = ms.filter((m) => !m.hide); assert.ok(shown.length >= Math.floor(n / 2), `${shown.length} of ${n} labels drawn`); // The page draws a hidden label as a tick, the others as flags with words. const html = deckHtml(s, r, {}); assert.equal((html.match(/class="mflag bare"/g) ?? []).length, ms.filter((m) => m.hide).length); assert.equal((html.match(/class="mlabel"/g) ?? []).length, shown.length); }); test(`${n} markers, truncate: one row, no two labels meet, a box too narrow is a tick`, () => { const { l, ms } = lay(renderWith({ markers: many(n), markerLayout: "truncate" })); for (const m of ms) assert.equal("row" in m, false); assertLegible(ms, l.width); }); } test("short labels at 32 markers all fit in two rows: nothing hidden", () => { const { l, ms } = lay(renderWith({ markers: many(32, { label: (i) => `S${i + 1}` }) })); assert.equal(ms.filter((m) => m.hide).length, 0); assert.ok(ms.every((m) => markerLabelWidth(m.label) <= m.box[1] - m.box[0]), "every label fits its box"); assertLegible(ms, l.width); }); test("a dozen or fewer: the exhaustive split, as before -- nothing hidden on a roomy rail", () => { const { ms } = lay(renderWith({ markers: many(12).map((m, i) => ({ ...m, after: `c${3 * i + 1}` })) })); assert.equal(ms.filter((m) => m.hide).length, 0); assert.ok(ms.every((m) => !("level" in m)), "no level key on a section"); }); test("a subsection: `level: 2` placed, its own colour kept, else its section's; measured at its own size", () => { const markers = [ { after: "c2", label: "Who she is", color: "#e070d0" }, { after: "c4", label: "Early days", level: 2 }, { after: "c6", label: "On stage", level: 2, color: "#5fd1c9" }, { after: "c9", label: "After", color: "#7fdc9a" }, { after: "c11", label: "Later", level: 2 }, ]; const r = renderWith({ markers, pip: { color: "section", sectionColor0: "#b79cff" } }); const { s, ms, pipped } = lay(r); assert.deepEqual(ms.map((m) => [m.after, m.level ?? 1, m.color]), [ ["c2", 1, "#e070d0"], ["c4", 2, "#e070d0"], ["c6", 2, "#5fd1c9"], ["c9", 1, "#7fdc9a"], ["c11", 2, "#7fdc9a"], ]); assert.ok(MARKER_SUB_LABEL_SIZE < 18); assert.ok(markerLabelWidth("Early days", MARKER_SUB_LABEL_SIZE) < markerLabelWidth("Early days")); // The rail's sections: one per marker (the pips, the fuse bars, the rings // keep their indices), a subsection's colour its parent's -- even one that // carries a colour of its own (its flag wears that). const sec = railSections(ms, pipped.length, resolveDeck(r), PALETTE); assert.deepEqual(sec.colors, ["#b79cff", "#e070d0", "#e070d0", "#e070d0", "#7fdc9a", "#7fdc9a"]); // The page: a subsection's flag is `sub` (shorter, quieter); a section's is not. const html = deckHtml(s, r, {}); assert.equal((html.match(/class="mflag sub"/g) ?? []).length, 3); assert.match(html, /\.mflag\.sub \.mlabel \{ font-size: 14px; opacity: 0\.72; \}/); assert.match(html, /\.mflag\.sub \.mstick \{ top: -8px; height: 14px;/); // An unlabelled subsection is a half-height tick. const ticks = deckHtml(s, renderWith({ markers: markers.map(({ label: _l, ...m }) => m), pip: { color: "section" } }), {}); assert.equal((ticks.match(/class="mflag bare sub"/g) ?? []).length, 3); assert.match(ticks, /\.mflag\.sub \.mtick \{ top: -3px; height: 6px;/); // No subsection: none of the sub css. assert.doesNotMatch(deckHtml(s, renderWith({ markers: many(4) }), {}), /\.mflag\.sub/); }); test("the section title inside a subsection: \"Section › Sub\"; either alone when the other has no words; the opening is the parent of a stray one", () => { const markers = [ { after: "c2", label: "Who she is", color: "#e070d0" }, { after: "c4", label: "Early days", level: 2 }, { after: "c6", level: 2 }, // unlabelled: still inside "Who she is" { after: "c9", label: "After", color: "#7fdc9a" }, ]; const r = renderWith({ markers, rail: { labels: false }, sectionTitle: { first: "Opening", color: "section" }, pip: { sectionColor0: "#b79cff" } }); const s = deckSchedule({ entries: ENTRIES, durs: DURS, D: 0.5, render: r, provenance: PROV }); const tl = sectionTitleTimeline(s, r); const at = (id) => sectionTitleAt(tl, s.segments.find((x) => x.id === id).start + 5); assert.equal(at("c1"), "Opening"); assert.equal(at("c3"), "Who she is"); assert.equal(at("c5"), "Who she is › Early days"); assert.equal(at("c7"), "Who she is", "an unlabelled subsection says its section"); assert.equal(at("c10"), "After"); // In the section's colour. const sub = tl.titles.find((t) => t.label === "Who she is › Early days"); assert.equal(sub.color, "#e070d0"); }); test("the cut's first marker must be a section: a leading subsection is refused by where it stands, not where it is listed", () => { const manifest = (markers) => ({ timeline: ENTRIES.slice(0, 8), render: renderWith({ markers }) }); assert.deepEqual(validateDeckMarkers(manifest([{ after: "c1", label: "A" }, { after: "c3", label: "a", level: 2 }])), []); const lead = validateDeckMarkers(manifest([{ after: "c3", label: "A" }, { after: "c1", label: "a", level: 2 }])); assert.equal(lead.length, 1); assert.match(lead[0], /markers\[1\] \(after c1\) is a subsection \(level 2\) with no section before it/); assert.match(validateDeckMarkers(manifest([{ after: "c1", level: 2 }])).join(" "), /first marker opens a section/); });