// gapCue.mjs (lane gap-cue): the settings and their precedence (project < // clip < gap), the label, the timing of the marks, and the look's writer. import { test } from "node:test"; import assert from "node:assert/strict"; import { GAP_CUE_DEFAULTS, GAP_CUE_LIFE, GAP_CUE_LOOK, clipGapCueOf, gapCueAlpha, gapCueLength, gapCueOf, gapCueText, gapCueWanted, gapCues, gapMarkOn, gapReasonOk, gapWhyWord, validateGapCue, gapCueBoxStyle, gapCueCss, GAP_CUE_BORDER_FALLBACK, gapCueBorderOf, gapCueLook, } from "./gapCue.mjs"; import { applyLookPatch, lookErrors } from "./look.mjs"; test("the defaults: the mark OFF, 2 s, the layout's corner, '» {s}[ · {why}]'", () => { assert.deepEqual(gapCueOf(undefined), { mark: false, min: 2, corner: "auto", label: "» {s}[ · {why}]", place: "footage", border: "accent" }); assert.deepEqual(gapCueOf({}), GAP_CUE_DEFAULTS); assert.equal(gapCueWanted({}, { type: "clip", gaps: [{ from: 1, to: 9 }] }), false, "a cut that says nothing marks nothing"); }); test("precedence: a gap's mark over its clip's over the project's", () => { const render = { gapCue: { mark: true, min: 3 } }; const clip = { type: "clip", gapCue: { mark: false, corner: "tr" }, gaps: [{ from: 1, to: 9 }, { from: 12, to: 20, mark: true }] }; const cue = clipGapCueOf(render, clip); assert.deepEqual(cue, { mark: false, min: 3, corner: "tr", label: "» {s}[ · {why}]", place: "footage", border: "accent" }); assert.equal(gapMarkOn(cue, clip.gaps[0]), false, "the clip's off"); assert.equal(gapMarkOn(cue, clip.gaps[1]), true, "the gap's own on"); assert.equal(gapCueWanted(render, clip), true); assert.equal(gapMarkOn(gapCueOf(render), { from: 1, to: 2, mark: false }), false, "a gap's off beats the project's on"); }); test("the label: whole seconds, then m:ss, then h:mm:ss; {s} is the length", () => { assert.equal(gapCueLength(27.4), "27 s"); assert.equal(gapCueLength(59.4), "59 s"); assert.equal(gapCueLength(59.6), "1:00"); assert.equal(gapCueLength(72), "1:12"); assert.equal(gapCueLength(3723), "1:02:03"); assert.equal(gapCueText(27), "» 27 s"); assert.equal(gapCueText(72, "{s} later"), "1:12 later"); }); test("the reason in the mark (operator, 20 Nov): why's word, or the gap's own reason; none, the length alone as before", () => { assert.equal(gapWhyWord({ why: "dead-air" }), "dead air"); assert.equal(gapWhyWord({ why: "idle" }), "idle"); assert.equal(gapWhyWord({ why: "other" }), "", "other says nothing"); assert.equal(gapWhyWord({ why: "other", reason: " ad break " }), "ad break", "a reason of its own says it"); assert.equal(gapWhyWord({}), ""); assert.equal(gapCueText(26, undefined, "dead air"), "» 26 s · dead air"); assert.equal(gapCueText(26, undefined, ""), "» 26 s", "no reason: exactly the slice 1 text"); assert.equal(gapCueText(72, "{s} skipped[ ({why})]", "idle"), "1:12 skipped (idle)"); assert.equal(gapCueText(72, "{s} skipped[ ({why})]"), "1:12 skipped"); // A merged mark says a reason only when every join in it says the same. const same = gapCues([{ at: 2, seconds: 5, mark: true, why: "dead air" }, { at: 2.5, seconds: 6, mark: true, why: "dead air" }]); assert.equal(same[0]!.why, "dead air"); const mixed = gapCues([{ at: 2, seconds: 5, mark: true, why: "dead air" }, { at: 2.5, seconds: 6, mark: true }]); assert.equal("why" in mixed[0]!, false); // Its corner is the first join's own. assert.equal(gapCues([{ at: 2, seconds: 5, mark: true, corner: "tr" }])[0]!.corner, "tr"); // The label's [ ] parts: closed, not nested, each holding {why}. assert.deepEqual(validateGapCue({ render: { gapCue: { label: "» {s}[ · {why}]" } } }), []); assert.match(validateGapCue({ render: { gapCue: { label: "» {s}[ · why]" } } }).join("\n"), /a part in \[ \] holds \{why\}/); assert.match(validateGapCue({ render: { gapCue: { label: "» {s}[ · {why}" } } }).join("\n"), /a part in \[ \]/); }); test("the marks: under min nothing, marked only, joins within a life are one mark summing their seconds", () => { assert.deepEqual(gapCues([{ at: 2, seconds: 1.5, mark: true }]), [], "a breath taken out draws nothing"); assert.deepEqual(gapCues([{ at: 2, seconds: 27, mark: false }]), [], "unmarked"); assert.deepEqual(gapCues([{ at: 2, seconds: 27, mark: true }], { seconds: 10 }), [{ at: 2, until: 2 + GAP_CUE_LIFE, seconds: 27, count: 1 }]); const two = gapCues([{ at: 5, seconds: 10, mark: true }, { at: 2, seconds: 27, mark: true }, { at: 2.6, seconds: 4, mark: true }], { seconds: 20 }); assert.deepEqual(two, [ { at: 2, until: 2.6 + GAP_CUE_LIFE, seconds: 31, count: 2 }, { at: 5, until: 5 + GAP_CUE_LIFE, seconds: 10, count: 1 }, ]); // Never past the segment; nothing with under 0.2 s left. assert.deepEqual(gapCues([{ at: 3, seconds: 9, mark: true }], { seconds: 3.5 }), [{ at: 3, until: 3.5, seconds: 9, count: 1 }]); assert.deepEqual(gapCues([{ at: 3.4, seconds: 9, mark: true }], { seconds: 3.5 }), []); // A fast-forward's play seconds (slice 3) keep it up that much longer. assert.equal(gapCues([{ at: 1, seconds: 30, mark: true, play: 0.8 }])[0]!.until, Number((1 + 0.8 + GAP_CUE_LIFE).toFixed(4))); }); test("a merged mark's corner: the first of its joins that names one, not only the first join's (review 1, 7)", () => { const joins = [{ at: 2, seconds: 27, mark: true }, { at: 2.5, seconds: 4, mark: true, corner: "br" }, { at: 3, seconds: 3, mark: true, corner: "tr" }]; const [m] = gapCues(joins, { seconds: 20 }); assert.equal(m!.count, 3); assert.equal(m!.corner, "br"); // The first naming one wins over a later one. assert.equal(gapCues([{ ...joins[0]!, corner: "tl" }, joins[1]!], { seconds: 20 })[0]!.corner, "tl"); }); test("a label or a reason holds no control character: one line, drawn as written (review 1, 1)", () => { for (const bad of ["{s}\tlater", "{s}\u0000", "{s}\u2028", "{s}\u2029", "{s}\u007f", "{s}\nlater"]) { assert.match(validateGapCue({ render: { gapCue: { label: bad } } }).join("\n"), /one line of at most 40 characters/, JSON.stringify(bad)); assert.equal(gapCueOf({ gapCue: { label: bad } }).label, GAP_CUE_DEFAULTS.label, `${JSON.stringify(bad)} is not taken`); } // A % or a backslash is words like any other: the build draws it as written. assert.deepEqual(validateGapCue({ render: { gapCue: { label: "{s} (90%) \\ {why}" } } }), []); assert.equal(gapReasonOk("100% idle"), true); assert.equal(gapReasonOk("back\\slash"), true); for (const bad of ["a\tb", "a\u0001", "a\u2028b", "a\u2029", "x\u007f", "a\nb", "[x]", "{x}", "", " ", "x".repeat(25)]) { assert.equal(gapReasonOk(bad), false, JSON.stringify(bad)); } }); test("the opacity: up over 0.15 s, 0.9 at full, down over 0.35 s", () => { const c = { at: 2, until: 2 + GAP_CUE_LIFE }; assert.equal(gapCueAlpha(1.9, c), 0); assert.equal(gapCueAlpha(2, c), 0); assert.ok(Math.abs(gapCueAlpha(2.075, c) - 0.45) < 1e-9); assert.equal(gapCueAlpha(2.5, c), 0.9); assert.equal(gapCueAlpha(c.until, c), 0); }); test("place (slice 1d): footage or deck, the clip's over the project's; anything else refused", () => { assert.equal(clipGapCueOf({ gapCue: { place: "deck" } }, { gapCue: {} }).place, "deck"); assert.equal(clipGapCueOf({ gapCue: { place: "deck" } }, { gapCue: { place: "footage" } }).place, "footage"); assert.deepEqual(validateGapCue({ render: { gapCue: { place: "deck" } } }), []); assert.match(validateGapCue({ render: { gapCue: { place: "band" } } }).join("\n"), /render\.gapCue\.place is footage .* or deck/); assert.equal(gapCueOf({ gapCue: { place: "band" } }).place, "footage", "an unreadable place is the default"); }); test("the look as CSS (slice 1d): one box for the module's page and umtool's element -- a real border, the box inside it", () => { const st = gapCueBoxStyle({ font: 32, stroke: 2 }); assert.equal(st.fontSize, "32px"); assert.equal(st.padding, `${GAP_CUE_LOOK.pad}em`); // Variant B (operator, 20 Nov): the border at full opacity (here the look's fallback amber), the box at 0.9. assert.equal(st.border, "2px solid rgba(245, 179, 0, 1)"); assert.equal(st.background, "linear-gradient(rgba(16, 16, 16, 0.9), rgba(16, 16, 16, 0.9)), rgba(245, 179, 0, 1)"); assert.equal(st.color, "#ffffff", "the text stays white"); assert.equal(gapCueBoxStyle({ font: "3cqmin", stroke: "max(1.5px, 0.19cqmin)" }).fontSize, "3cqmin"); const css = gapCueCss(".gm", { font: 32, stroke: 2 }); assert.match(css, /^\.gm \{ position: absolute;/); assert.match(css, /font-family: 'DeckSansBold', sans-serif;/); assert.match(css, /border: 2px solid rgba\(245, 179, 0, 1\);/); assert.match(css, /background-clip: padding-box;/); assert.match(css, /white-space: nowrap;/); }); test("validation: the project's block and each clip's, in the build's words", () => { assert.deepEqual(validateGapCue({ render: {}, timeline: [] }), []); assert.deepEqual(validateGapCue({ render: { gapCue: { mark: true, min: 4, corner: "bl", label: "{s} later" } } }), []); const errs = validateGapCue({ render: { gapCue: { mark: "yes", min: 0.1, corner: "middle", label: "skipped", size: 3 } }, timeline: [{ type: "clip", id: "c1", gapCue: { mark: 1 } }, { type: "card", id: "k1", gapCue: {} }], }); assert.equal(errs.length, 7, errs.join("\n")); assert.match(errs.join("\n"), /render\.gapCue\.size is not a key/); assert.match(errs.join("\n"), /label is text holding \{s\}/); assert.match(errs.join("\n"), /\(c1\)\.gapCue\.mark is true/); assert.match(errs.join("\n"), /\(k1\)\.gapCue: only a clip has gaps to mark/); }); test("the look's writer: gapCue merged over what it holds, a key null drops it, null drops the block", () => { const m = { render: { gapCue: { mark: true, min: 3 } }, timeline: [] }; assert.deepEqual(applyLookPatch(m, { gapCue: { corner: "tl" } }).render.gapCue, { mark: true, min: 3, corner: "tl" }); assert.deepEqual(applyLookPatch(m, { gapCue: { min: null } }).render.gapCue, { mark: true }); assert.equal(applyLookPatch(m, { gapCue: null }).render.gapCue, undefined); assert.match(applyLookPatch(m, { gapCue: { min: 99 } }).errors.join("\n"), /render\.gapCue\.min is seconds from 0\.5 to 60/); assert.deepEqual(lookErrors({ render: { gapCue: { mark: true } } }), []); }); test("the border (variant B): the deck's accent, else the fallback amber; a #rrggbb setting over it, the clip's over the project's", () => { const teal = { palette: { bg: "#0b1416", fg: "#eef6f5", accent: "#1fb5a8" } }; // The palette's accent (render.palette.accent: the deck's rule and dots). assert.equal(gapCueBorderOf(teal), "#1fb5a8"); assert.equal(gapCueBorderOf({ palette: { accent: "#e8742a" } }, { gapCue: {} }), "#e8742a"); assert.equal(gapCueBorderOf({ palette: { accent: "#1ba" } }), "#11bbaa", "a short palette hex, as drawtext reads it"); // No palette, or no accent in it, or one that is no colour: the fallback. assert.equal(GAP_CUE_BORDER_FALLBACK, "#f5b300"); assert.equal(gapCueBorderOf({}), "#f5b300"); assert.equal(gapCueBorderOf(null), "#f5b300"); assert.equal(gapCueBorderOf({ palette: { bg: "#000000" } }), "#f5b300"); assert.equal(gapCueBorderOf({ palette: { accent: "teal" } }), "#f5b300"); // "accent" is the default spelled out; absent (a take's manifest drops a null key) reads the same. assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: "accent" } }), "#1fb5a8"); assert.equal(gapCueBorderOf({ ...teal, gapCue: { mark: true } }), "#1fb5a8", "absent: the accent"); assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: null } }), "#1fb5a8", "null: the accent"); // An explicit colour: the project's, the clip's over it, "accent" on the clip back to the deck's. assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: "#3AA0FF" } }), "#3AA0FF"); assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: "#3aa0ff" } }, { gapCue: { border: "#ff00aa" } }), "#ff00aa"); assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: "#3aa0ff" } }, { gapCue: { border: "accent" } }), "#1fb5a8"); assert.equal(gapCueBorderOf({ gapCue: { border: "#3aa0ff" } }), "#3aa0ff", "a colour needs no palette"); // An unreadable setting is the default (the accent), as every other key. assert.equal(gapCueBorderOf({ ...teal, gapCue: { border: "red" } }), "#1fb5a8"); // gapCueLook: GAP_CUE_LOOK with that colour, or with a colour already resolved (the slice's mark's). assert.deepEqual(gapCueLook(teal), { ...GAP_CUE_LOOK, strokeColor: "#1fb5a8" }); assert.equal(gapCueLook({}).strokeColor, "#f5b300"); assert.equal(gapCueLook(teal, null, { border: "#e8742a" }).strokeColor, "#e8742a"); assert.equal(gapCueLook(teal, null, { border: null }).strokeColor, "#1fb5a8"); assert.equal(GAP_CUE_LOOK.strokeAlpha, 1); assert.equal(GAP_CUE_LOOK.boxAlpha, 0.9); assert.equal(GAP_CUE_LOOK.fg, "#ffffff"); assert.equal(GAP_CUE_LOOK.box, "#101010"); // The page's CSS carries it. assert.match(gapCueCss(".gm", { font: 32, stroke: 2, look: gapCueLook(teal) }), /border: 2px solid rgba\(31, 181, 168, 1\);/); }); test("the border's validation: accent or #rrggbb, on the project's block and a clip's; the look's writer keeps it", () => { assert.deepEqual(validateGapCue({ render: { gapCue: { border: "accent" } } }), []); assert.deepEqual(validateGapCue({ render: { gapCue: { border: "#3aa0ff" } }, timeline: [{ type: "clip", id: "c1", gapCue: { border: "#FF00AA" } }] }), []); for (const bad of ["red", "#fff", "#3aa0ffcc", "3aa0ff", "", 7, true, "Accent"]) { assert.match(validateGapCue({ render: { gapCue: { border: bad } } }).join("\n"), /render\.gapCue\.border is accent \(the deck's accent colour\) or a #rrggbb colour/, JSON.stringify(bad)); } assert.match(validateGapCue({ timeline: [{ type: "clip", id: "c1", gapCue: { border: "blue" } }] }).join("\n"), /\(c1\)\.gapCue\.border is accent/); const m = applyLookPatch({ render: { gapCue: { mark: true } } }, { gapCue: { border: "#3aa0ff" } }); assert.deepEqual(m.render.gapCue, { mark: true, border: "#3aa0ff" }); assert.deepEqual(applyLookPatch(m, { gapCue: { border: null } }).render.gapCue, { mark: true }, "null drops it: the accent again"); assert.match(lookErrors({ render: { gapCue: { border: "nope" } } }).join("\n"), /render\.gapCue\.border is accent/, "the look writer refuses it in the same words"); });