// The rail module: pip spacing "pitch" (deck.mjs pipXs, chrome-deck.mjs deckCues) // and the settings every deck module validates (modules/settings.mjs). import { test } from "node:test"; import assert from "node:assert/strict"; import { estimateSchedule, pipXs, resolveDeck, validateChrome } from "../deck.mjs"; import { deckCues, deckHtml } from "../chrome-deck.mjs"; import rail from "./rail.mjs"; import { SETTINGS, settingsOf } from "./settings.mjs"; const PALETTE = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; const render = (pip) => ({ width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: { pip } } }); const clip = (id) => ({ type: "clip", id, video: id, start: 0, end: 8 }); test("pipXs at a pitch: each pip a pitch after the last from the left; squeezed only when the track is too short", () => { assert.deepEqual(pipXs(3, 48, 1872, "pitch", null, 40), [48, 88, 128]); assert.deepEqual(pipXs(1, 48, 1872, "pitch", null, 40), [48]); // 100 pips at 40 px need 3960 px: laid at the pitch that fits. const xs = pipXs(100, 48, 1872, "pitch", null, 40); assert.ok(Math.abs(xs.at(-1) - 1872) < 1e-9); assert.equal(xs[0], 48); // A pip's place does not depend on how many come after it. assert.deepEqual(pipXs(4, 48, 1872, "pitch", null, 40).slice(0, 3), pipXs(3, 48, 1872, "pitch", null, 40)); }); test("the deck at a pitch: pips after the first hidden until the marker reaches the one before; the fuse against the track", () => { const r = render({ spacing: "pitch", pitch: 40 }); const s = estimateSchedule({ render: r, timeline: [clip("a"), clip("b"), clip("c")], posts: [], provenance: {} }); const { init, cues, pips } = deckCues(s, r); assert.deepEqual(pips.map((p) => p.x), [48, 88, 128]); // The marker stands on the first pip from the cut's first instant, so the one after it is up from frame 0: in init, // not an instant cue at 0 that only frame 1 could show (cue-start.mjs settleFirstFrame). assert.deepEqual(init.pb1, { opacity: 1 }); assert.ok(!cues.some((c) => c.k === "pb1")); assert.deepEqual(init.pb2, { opacity: 0 }); assert.equal(init.pb0, undefined); assert.ok(cues.some((c) => c.k === "pb2" && c.to.opacity === 1 && c.at > 0)); const html = deckHtml(s, r, {}); assert.match(html, /\.fuse \{ position: absolute; left: 48px; top: -1px; width: 1824px;/); assert.match(html, /
<\/div>/); // Even spacing: no pip is hidden, as it always was. const e = deckCues(s, render({})); assert.equal(e.init.pb1, undefined); }); test("rail settings: spacing, pitch, and the deck's other keys refused by name", () => { assert.deepEqual(validateChrome(render({ spacing: "pitch", pitch: 24 }).chrome, render({})), []); assert.match(validateChrome(render({ spacing: "grid" }).chrome, render({}))[0], /pip\.spacing must be "even", "time" or "pitch"/); assert.match(validateChrome(render({ pitch: 2 }).chrome, render({}))[0], /pip\.pitch must be from 8 to 200/); assert.equal(resolveDeck(render({})).pip.pitch, undefined, "no pitch unless set: the deck resolves as it did"); assert.equal(rail.resolve(render({ spacing: "pitch" })).pip.pitch, 28); assert.equal(rail.validate, settingsOf("rail").validate); assert.deepEqual(SETTINGS.map((s) => s.id), ["stamp", "threads", "flips", "stats", "fx", "chat", "pair", "chapter", "status", "finale", "claims", "measure", "counter", "shell", "rail", "section-title", "subtitle", "qr", "popup-posts", "dial", "odometer", "trail", "diet", "peak", "goals", "promise", "streak", "shelf"]); });