// THE SHELF (modules/shelf.mjs, shelf-settings.mjs; deck.mjs deckGeometry, // measure-extras.mjs shelfLayout): a strip cleared beside the footage for the // diet's dated tags, the streak chain and an entry's note -- and a deck without // it laid out exactly as before. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { backTextSize, dietHtml, GOALS_BACK, goalsHtml, shelfGoalStates, tagWords, tagWordSize } from "./chrome-measure-extras.mjs"; import { goalBoard, goalsAt } from "./measure-goals.mjs"; import { shelfHtml, shelfNoteGeometry } from "./chrome-shelf.mjs"; import { deckGeometry, entryShelfNotes, estimateSchedule, instrumentsGeometry, parseShelfNote, validateChrome } from "./deck.mjs"; import { dietDays, dietStates, goalBaseText, goalStates, dietTagsBox, GOALS_SHELF, goalsShelfWidth, measureExtraGeometry, measurePlacements, shelfLayout, streakStates } from "./measure-extras.mjs"; import { slotRect } from "./modules/layout.mjs"; import { moduleById, moduleProblems, scheduleSlices } from "./modules/index.mjs"; import { resolveMeasureExtra, validateMeasureExtra } from "./modules/measure-extras-settings.mjs"; import { resolveShelf, validateShelf } from "./modules/shelf-settings.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const MEASURE = JSON.parse(readFileSync(path.join(HERE, "fixtures/measure-extras/measure.json"), "utf8")); const PALETTE = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; const INSTRUMENTS = { dial: true, odometer: true, trail: true }; const renderOf = (deck = {}) => ({ width: 1920, height: 1080, fps: 30, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck } }); const SHELF = { ...INSTRUMENTS, shelf: { items: ["diet", "streak"] }, diet: { position: "shelf" }, streak: { position: "shelf" } }; const schedule = (extra = {}) => ({ kind: "deck", fps: 30, total: 740, transition: 0.4, segments: [{ id: "a", start: 0, duration: 740, end: 740 }], measure: MEASURE, ...extra }); const clone = (v) => JSON.parse(JSON.stringify(v)); test("off, the deck is the deck it was: no shelf key, the footage where it stood", () => { for (const deck of [{}, INSTRUMENTS, { ...INSTRUMENTS, shelf: false }, { ...INSTRUMENTS, shelf: { show: false } }]) { const g = deckGeometry(renderOf(deck)); assert.equal("shelf" in g, false); assert.equal(resolveShelf(renderOf(deck)), null); assert.equal(shelfLayout(renderOf(deck)), null); } assert.deepEqual(deckGeometry(renderOf(INSTRUMENTS)).footage, { x: 24, y: 94, width: 1248, height: 702 }); assert.deepEqual(slotRect("shelf", renderOf(INSTRUMENTS)), { x: 24, y: 796, width: 1248, height: 0 }); }); test("below: the footage at the frame's top and the shelf under it; above: mirrored; the instruments' column unchanged", () => { const below = deckGeometry(renderOf(SHELF)); assert.deepEqual(below.footage, { x: 24, y: 24, width: 1248, height: 702 }); assert.deepEqual(below.shelf, { x: 24, y: 750, width: 1248, height: 116 }); assert.deepEqual(below.deck, deckGeometry(renderOf(INSTRUMENTS)).deck); const above = deckGeometry(renderOf({ ...SHELF, shelf: { ...SHELF.shelf, side: "above" } })); assert.deepEqual(above.footage, { x: 24, y: 164, width: 1248, height: 702 }); assert.deepEqual(above.shelf, { x: 24, y: 24, width: 1248, height: 116 }); assert.deepEqual(instrumentsGeometry(renderOf(SHELF)), instrumentsGeometry(renderOf(INSTRUMENTS))); assert.deepEqual(slotRect("shelf", renderOf(SHELF)), below.shelf); assert.deepEqual(validateChrome(renderOf(SHELF).chrome, renderOf(SHELF)), []); }); test("shelfLayout: left to right in items order, each scaled to the shelf's height; the note takes the width left", () => { const L = shelfLayout(renderOf(SHELF)); assert.deepEqual(L.slots.diet, { x: 24, y: 750, width: 684, height: 116 }, "three tags at 220, 12 apart"); assert.deepEqual(L.slots.streak, { x: 724, y: 750, width: 478, height: 116 }, "the streak's 620×150 at 116 high"); assert.equal("note" in L.slots, false, "an explicit items list without the note has none"); assert.deepEqual(measureExtraGeometry("diet", renderOf(SHELF)), L.slots.diet); // Two tags; the note (in the default items) in what is left. const two = renderOf({ ...INSTRUMENTS, shelf: true, diet: { position: "shelf", tags: 2 }, streak: { position: "shelf" } }); assert.deepEqual(resolveShelf(two).items, ["diet", "streak", "note"]); const L2 = shelfLayout(two); assert.equal(L2.slots.diet.width, 452); assert.equal(L2.slots.streak.x, 24 + 452 + 16); assert.deepEqual(L2.slots.note, { x: 24 + 452 + 16 + 478 + 16, y: 750, width: 286, height: 116 }); // Two lines in the band: a 77 px shelf, everything a size down. const lines2 = renderOf({ ...SHELF, subtitle: { lines: 2, parts: ["channel", "title", "date", "clock"] } }); assert.equal(deckGeometry(lines2).shelf.height, 77); assert.deepEqual(validateChrome(lines2.chrome, lines2), []); assert.ok(shelfLayout(lines2).slots.diet.height <= 77); }); test("validation: room for the shelf, and the way out; positions and items that disagree", () => { const full = renderOf({ shelf: true }); const [e] = validateChrome(full.chrome, full); assert.match(e, /deck\.shelf needs at least 72px below the footage, but footageScale 0\.82 \(886px of footage\) over a 190px deck leaves 0 \(footageScale at most 0\.69, or render\.chrome\.deck\.shelf=false\)/); assert.deepEqual(validateChrome(renderOf({ shelf: true, footageScale: 0.69 }).chrome, renderOf()), []); const two = renderOf({ shelf: true, footageScale: 0.7, subtitle: { lines: 2 } }); assert.match(validateChrome(two.chrome, two)[0], /or subtitle\.lines 1/); const bad = (deck) => validateChrome(renderOf({ ...INSTRUMENTS, ...deck }).chrome, renderOf()); assert.match(bad({ diet: { position: "shelf" } }).join(), /diet\.position is "shelf", but render\.chrome\.deck\.shelf is off/); assert.match(bad({ shelf: { items: ["diet"] }, diet: { position: "top-right" } }).join(), /items puts diet on the shelf, but render\.chrome\.deck\.diet\.position is "top-right"/); assert.match(bad({ shelf: { items: ["streak"] }, diet: { position: "shelf" } }).join(), /diet\.position is "shelf", but render\.chrome\.deck\.shelf\.items leaves it out/); assert.match(bad({ shelf: { items: ["dial"] } }).join(), /items must be a list of distinct items/); assert.match(bad({ shelf: { side: "left" } }).join(), /side must be "below" or "above"/); assert.match(bad({ shelf: { nope: 1 } }).join(), /shelf\.nope is not a shelf setting/); assert.match(validateMeasureExtra("promise", { position: "shelf" }).join(), /position must be/, "the promise clock has its own slot"); assert.match(validateMeasureExtra("diet", { form: "badge" }).join(), /form must be "stamp" or "tags"/); assert.match(validateMeasureExtra("diet", { tags: 5 }).join(), /tags must be a whole number from 1 to 4/); assert.deepEqual(validateShelf({ side: "above", gap: 8, finale: "show", items: ["note"] }), []); assert.deepEqual(moduleProblems({ render: renderOf(SHELF) }), {}); // On the shelf the diet is its tags unless a form is named, and the shelf's finale is the occupants'. assert.equal(resolveMeasureExtra("diet", renderOf(SHELF)).form, "tags"); assert.equal(resolveMeasureExtra("diet", renderOf({ ...SHELF, diet: { position: "shelf", form: "stamp" } })).form, "stamp"); assert.equal(resolveMeasureExtra("diet", renderOf(INSTRUMENTS)).form, "stamp"); assert.equal(resolveMeasureExtra("streak", renderOf({ ...SHELF, shelf: { ...SHELF.shelf, finale: "show" } })).finale, "show"); }); test("on the shelf nothing dodges: a post card or a chapter band over the footage leaves it where it is; hideModules still hides", () => { const r = renderOf(SHELF); const card = { from: 100, to: 110, rects: [{ x: 24, y: 24, width: 1248, height: 702 }] }; const p = measurePlacements(schedule({ covers: [card] }), r); assert.deepEqual(p.diet.moves, []); assert.deepEqual(p.streak.moves, []); assert.deepEqual(p.diet.region, shelfLayout(r).slots.diet); // Off the shelf, the same card moves the badge. const off = measurePlacements(schedule({ covers: [card] }), renderOf(INSTRUMENTS)); assert.ok(off.diet.moves.length > 0); const hid = measurePlacements(schedule({ covers: [card], hides: [{ segment: "v02", from: 600, to: 610, modules: ["diet"] }] }), r); assert.deepEqual(hid.diet.moves, [{ from: 600, to: 610, rect: null, size: 1 }]); }); test("the diet's tags: each change pushes a dated tag in at the front, the oldest past n falls off, words alone replace the newest", () => { const r = renderOf(SHELF); const states = dietStates(schedule(), r); assert.equal(states[0].tags.length, 1); assert.equal(states[0].diet.since, states[0].tags[0].since); assert.ok(states.every((s) => s.tags.length <= 3)); assert.deepEqual(states[3].tags.map((t) => t.id), [3, 2, 1], "the newest first; the fourth diet pushed the first off"); assert.ok(states.every((s) => s.tags[0].diet === s.diet || (s.tags[0].diet === null && s.diet === null))); const two = dietStates(schedule(), renderOf({ ...SHELF, diet: { position: "shelf", tags: 2 } })); assert.ok(two.every((s) => s.tags.length <= 2)); // A change of words only: the newest tag replaced in place; a null after one: a "No diet" tag pushed in. const m = clone(MEASURE); const k = m.state.findIndex((s) => s.diet?.n === 63); m.state[k + 1] = { ...m.state[k + 1], diet: { ...m.state[k].diet, display: "Keto · strict" } }; m.state[m.state.length - 1].diet = null; const s2 = dietStates(schedule({ measure: m }), r); const j = s2.findIndex((s) => s.diet?.detail === "Keto · strict"); assert.equal(s2[j].replaced, true); assert.deepEqual(s2[j].tags.slice(1).map((t) => t.id), s2[j - 1].tags.slice(1).map((t) => t.id), "the older tags stay where they were"); const last = s2.at(-1); assert.equal(last.tags[0].diet, null); assert.equal(last.replaced, false); // The page: each tag once, with its date; drawn at the shelf's scale. const { html, items } = dietHtml(schedule(), r, { fonts: {} }); assert.equal(items.length, new Set(states.flatMap((s) => s.tags.map((t) => t.id))).size); assert.match(html, /
Feb 6, 2018<\/div>/); assert.match(html, /data-k="t0\.s"/); assert.match(html, /\.tg \{ position: absolute; left: 0; top: 0; width: 220px; height: 116px;/); // The regime's word fits its tag: CARNIVORE a size down, KETO at the top size. assert.equal(tagWordSize("Keto"), 44); assert.equal(tagWordSize("Carnivore"), 31); }); test("a tag dates the SWITCH: new words for the same diet keep its since; a new diet gets its own; the words lose the regime they repeat", () => { const r = renderOf(SHELF); const m = clone(MEASURE); // Keto #63 named on its day; later the ledger's words change ("5 carbs a day") with a since of their own. const k = m.state.findIndex((s) => s.diet?.n === 63); const keto = m.state[k].diet; m.state[k + 1] = { ...m.state[k + 1], diet: { ...keto, display: "Keto · 2 carbs a day", since: "2026-08-02" } }; const s2 = dietStates(schedule({ measure: m }), r); const j = s2.findIndex((s) => s.diet?.detail === "Keto · 2 carbs a day"); assert.equal(s2[j].replaced, true); assert.notEqual(s2[j - 1].tags[0].since, "2026-08-02"); assert.equal(s2[j].tags[0].since, s2[j - 1].tags[0].since, "the words' day is not the switch's"); assert.equal(s2[j].diet.since, s2[j - 1].tags[0].since); // A new diet (a slam) gets the day it was named. const slam = s2.findIndex((s, i) => i > 0 && s.slam); assert.equal(s2[slam].tags[0].since, s2[slam].diet.since); assert.notEqual(s2[slam].tags[0].since, s2[slam - 1].tags[0].since); // The words: the regime they open with dropped where a separator follows it. assert.equal(tagWords("Keto · 5 carbs a day", ["Keto", "keto"]), "5 carbs a day"); assert.equal(tagWords("Keto + IF + walking", ["Keto", "keto"]), "Keto + IF + walking"); assert.equal(tagWords("Keto", ["Keto", "keto"]), ""); const { html } = dietHtml(schedule({ measure: m }), r, { fonts: {} }); assert.match(html, /5 carbs a day<\/span>/); assert.match(html, /2 carbs a day<\/span>/); assert.doesNotMatch(html, /Aug 2, 2026/); }); test("the shelf's note: an entry's shelfNote over its span, only with the shelf on; its own page in the slot left", () => { assert.deepEqual(parseShelfNote(" Day 41 "), { value: "Day 41", error: null }); assert.equal(parseShelfNote("").value, null); assert.match(parseShelfNote("a\nb").error, /one line/); assert.match(parseShelfNote("x".repeat(81)).error, /at most 80/); const manifest = (deck) => ({ schemaVersion: 1, provenance: { channelSlug: "c", siteOrigin: "https://example.test" }, render: renderOf(deck), timeline: [ { type: "clip", id: "c01", video: "v", start: 0, end: 8, title: "T", date: "2026-10-27", shelfNote: "Weighed in on camera" }, { type: "clip", id: "c02", video: "v", start: 10, end: 18, title: "T", date: "2026-10-28" }, ], }); assert.equal("shelf" in estimateSchedule(manifest(INSTRUMENTS)), false, "no shelf: the schedule it always was"); const deck = { ...INSTRUMENTS, shelf: { items: ["note"] } }; const s = estimateSchedule(manifest(deck)); assert.deepEqual(s.shelf.notes.map((n) => [n.segment, n.text, n.from]), [["c01", "Weighed in on camera", 0]]); assert.deepEqual(entryShelfNotes([{ id: "x", shelfNote: "" }], [{ id: "x", start: 0, duration: 1 }]), []); assert.deepEqual(scheduleSlices(s).shelf, s.shelf); const r = renderOf(deck); const mod = moduleById("shelf"); assert.equal(mod.on(s, r), true); assert.equal(mod.on(s, renderOf(INSTRUMENTS)), false); assert.deepEqual(shelfNoteGeometry(r), { x: 24, y: 750, width: 1248, height: 116 }); const [region] = mod.regions(s, { render: r, outDir: "/o" }); assert.deepEqual([region.name, region.frames, region.y, region.height], ["shelf", "/o/chrome/shelf-frames", 750, 116]); const { html, items } = shelfHtml(s, r, { fonts: {} }); assert.equal(items.length, 1); assert.match(html, /Weighed in on camera/); assert.match(mod.check(s, renderOf(INSTRUMENTS)), /shelf region is off/); }); // --------------------------------------------------------------------------- // THE FAN (operator, 6 Nov: "overlap cards like the goals do but to the side, we can keep the cards the same // color ... a 'x days' number showing on the diet card"; "put the goal alongside this new diet hud space"). // --------------------------------------------------------------------------- const FAN = { ...INSTRUMENTS, shelf: { items: ["diet", "goals"] }, diet: { position: "shelf", overlap: 0.6, days: true }, goals: { position: "shelf" }, streak: false }; test("overlap: the tags fan sideways, the width shrinking by what hides; capped where an older tag's word and date still show", () => { assert.deepEqual(dietTagsBox(3), { width: 684, height: 116 }, "0: the row as it was"); assert.deepEqual(dietTagsBox(3, 0.5), { width: 220 + 2 * 110, height: 116 }); assert.deepEqual(dietTagsBox(3, 0.6, true), { width: 300 + 2 * 120, height: 116 }, "with the day count a tag is 300 wide"); assert.match(validateMeasureExtra("diet", { overlap: 0.6 }).join(), /overlap 0\.6 hides an older tag's regime word and date: they need 110 of its 220 design px \(overlap at most 0\.5, or 0\.63 with days\)/); assert.deepEqual(validateMeasureExtra("diet", { overlap: 0.6, days: true }), []); assert.match(validateMeasureExtra("diet", { overlap: 0.9, days: true }).join(), /overlap must be from 0 to 0\.8/); assert.match(validateMeasureExtra("diet", { days: "yes" }).join(), /days must be true or false/); assert.deepEqual(validateChrome(renderOf(FAN).chrome, renderOf(FAN)), []); }); test("the page: older tags behind the newest, their own colours (no dim), each with its strip; the newest lands like a goal note", () => { const r = renderOf(FAN); const { html, items } = dietHtml(schedule(), r, { fonts: {} }); assert.match(html, /class="tg" data-k="t3" style="z-index:13"/, "the newer, the nearer"); assert.match(html, /
/, "the strip an older tag shows"); assert.ok(!/"k":"t\d+\.d","at":[\d.]+,"dur":[\d.]+,"from":\{"opacity":1\},"to":\{"opacity":0\.45/.test(html), "nothing dims"); assert.match(html, /"to":\{"x":0,"y":-?\d+,"rotation":-?[\d.]+,"scale":1,"autoAlpha":1\},"ease":"back\.out\(1\.3\)"/, "the goal note's landing"); assert.ok(items.length > 0); // The region is the fan's, at the shelf's height. assert.deepEqual(measureExtraGeometry("diet", r), { x: 24, y: 750, width: 540, height: 116 }); }); test("days: the front tag's running count is the streak chain's day count, to the in-record date at the playhead", () => { const withStreak = renderOf({ ...FAN, streak: { position: "bottom-center" } }); const days = dietDays(schedule(), withStreak); const { states } = streakStates(schedule(), withStreak); for (const st of states.filter((x) => x.live)) { const d = [...days].reverse().find((x) => x.at <= st.at + 1e-6); assert.equal(d.days, st.live.days, `at ${st.at}`); } const { html } = dietHtml(schedule(), renderOf(FAN), { fonts: {} }); assert.match(html, /
\d+<\/div>
days?<\/div><\/div>/); // Off (the default): no count, the tag as it was. assert.doesNotMatch(dietHtml(schedule(), renderOf(SHELF), { fonts: {} }).html, /class="dy"/); }); test("goals on the shelf: the count and the fanned notes, the fan taking the shelf's spare width", () => { const r = renderOf(FAN); assert.equal(goalsShelfWidth(4), GOALS_SHELF.count + GOALS_SHELF.gap + 250 + 3 * 110); const L = shelfLayout(r); assert.deepEqual(L.slots.diet, { x: 24, y: 750, width: 540, height: 116 }); assert.deepEqual(L.slots.goals, { x: 24 + 540 + 16, y: 750, width: 1248 - 540 - 16, height: 116 }, "no gap at the shelf's end"); assert.equal(resolveMeasureExtra("goals", r).hold, null, "on the shelf it stays up"); const { html, items } = goalsHtml(schedule(), r, { fonts: {} }); assert.match(html, /
1<\/div>
goal set<\/div><\/div>/); assert.match(html, /class="note" data-k="s\d+\.n\d+" style="z-index:19">
<\/div>
]*>
]*>LOSE 100<\/div>/, "an older note shows its words beside the one in front"); // A block per state of the fan: each goal he sets, and each second the goal board alone changes (shelfGoalStates). assert.equal(items.length, shelfGoalStates(schedule(), goalStates(schedule(), r)).length); // Off the shelf: the pile in the footage, as it was. assert.doesNotMatch(goalsHtml(schedule(), renderOf(INSTRUMENTS), { fonts: {} }).html, /class="gc"/); }); test("goals on the shelf: the dial's goal board orders the fan -- its headline in front, +N more for the others in force", () => { const r = renderOf(FAN); const m = clone(MEASURE); // Two goals in force at the end, the newer the more ambitious: the closer one leads, not the newest. const lastGoal = m.events.map((e, i) => [e, i]).filter(([e]) => e.kind === "goal" || e.kind === "goalLoss").at(-1)[1]; const t = m.events[lastGoal].t; m.events.splice(lastGoal + 1, 0, { ...m.events[lastGoal], t: t + 0.5, row: "far", kind: "goal", value: 221, display: "221", qualifier: null, deadline: null, due: null, asOf: null, range: undefined }); m.state.splice(lastGoal + 2, 0, { ...m.state[lastGoal + 1], t: t + 0.5 }); const sched = schedule({ measure: m }); const board = goalBoard(m); const end = goalsAt(board, Infinity); assert.ok(end.active.length > 1 && end.headline.row !== "far", "the fixture's last goal is closer than 221"); const shelf = shelfGoalStates(sched, goalStates(sched, r)); const last = shelf.at(-1); const front = last.notes.find((n) => n.depth === 0); assert.equal(front.key, last.headline, "the board's headline is in front"); assert.notEqual(front.key, "221 lb", "not the newest"); assert.equal(last.active, end.active.length); const { html } = goalsHtml(sched, r, { fonts: {} }); assert.match(html, new RegExp(`
\\+${end.active.length - 1} more
`)); }); // --------------------------------------------------------------------------- // A BACK CARD (operator, 11 Nov): "LOSE 1…" for "LOSE 100" -- the right end is what tells one goal from another, so a // back card is never cut on the right: its words end at the card's right edge and their LEFT goes under the card in // front. And a goal may say the weight he had stated when he set it, "LOSE 100 (FROM 346.7)" (`goals.base`). // --------------------------------------------------------------------------- /** The page's CSS rule for `sel`, as written. */ const ruleOf = (html, sel) => new RegExp(`\\n\\s*\\${sel} \\{([^}]*)\\}`).exec(html)?.[1] ?? ""; test("a back card's words are right-aligned to its right edge and never cut with an ellipsis -- for 2, 3, 4 and 8 notes", () => { for (const max of [2, 3, 4, 8]) { const r = renderOf({ ...FAN, goals: { position: "shelf", max } }); const { html } = goalsHtml(schedule(), r, { fonts: {} }); if (!/class="nb"/.test(html)) continue; // room for every note side by side: no back strips at all const nb = ruleOf(html, ".nb"), bt = ruleOf(html, ".bt"), bh = ruleOf(html, ".bh"); assert.match(nb, /align-items: flex-end/, `${max}: the words end at the right`); assert.match(nb, /text-align: right/); assert.match(nb, /left: 0; right: 0/, `${max}: the strip is the card's whole width, so an overflow goes LEFT, under the card in front`); for (const [name, rule] of [["bt", bt], ["bh", bh]]) { assert.doesNotMatch(rule, /ellipsis|max-width/, `${max}: .${name} is never cut on the right`); } // The ×n badge has the top of the strip to itself: the words start under it. const padTop = Number(/padding: ([\d.]+)px/.exec(nb)[1]); const ct = ruleOf(html, ".ct"); const badgeFoot = Number(/top: ([\d.]+)px/.exec(ct)[1]) + Number(/height: ([\d.]+)px/.exec(ct)[1]); assert.ok(badgeFoot <= padTop, `${max}: the ×n badge (to ${badgeFoot} px) is above the words (from ${padTop} px)`); } // Sized to fit the strip when they can, 17 px at the least; past that the left goes under. assert.equal(backTextSize("LOSE 40", 80), 22); assert.equal(backTextSize("LOSE 100", 80), 20); assert.equal(backTextSize("LOSE 100 LB OR SO", 80), GOALS_BACK.min); assert.equal(backTextSize("X", 300), GOALS_BACK.max); }); test("goals.base: off by default; on, each loss goal says the weight the slice reckons it from, its qualifier kept, never one made up", () => { assert.deepEqual(validateMeasureExtra("goals", { base: true }), []); assert.match(validateMeasureExtra("goals", { base: "yes" }).join(), /base must be true or false/); const off = goalStates(schedule(), renderOf(FAN)); assert.ok(off.every((st) => st.notes.every((n) => n.base === null)), "off: no base"); const r = renderOf({ ...FAN, goals: { position: "shelf", base: true } }); // The slice's bases (measure-slice.mjs goalBase; the fixture predates them): w06 from a stated 346.7, w13 from a // remembered ≈390, every other goal none. const m = clone(MEASURE); m.events.push({ t: null, row: "wb1", kind: "stated", value: 346.7, qualifier: null }, { t: null, row: "wb2", kind: "remembered", value: 390, qualifier: "≈" }); for (const st of m.state) { if (st.goal?.row === "w06") st.goal.base = { value: 346.7, row: "wb1", from: "stated" }; if (st.goal?.row === "w13") st.goal.base = { value: 390, row: "wb2", from: "remembered" }; } const sched = schedule({ measure: m }); const states = goalStates(sched, r); // Each note's base is its own goal's state's `goal.base` -- the gauge's -- or none. let withBase = 0; for (const st of states) { const e = m.events.find((x) => x.t === st.at && (x.kind === "goal" || x.kind === "goalLoss")); const s = [...m.state].reverse().find((x) => x.t <= st.at + 1e-9 && x.goal?.row === e.row); const top = st.notes.find((n) => n.key === st.top); const want = s?.goal?.base ? goalBaseText(s.goal.base, m) : null; assert.equal(top.base, want, `${e.row}: the slice's base or none`); if (want) withBase += 1; } assert.equal(withBase, 2); assert.ok(states.some((st) => st.notes.some((n) => n.base === "(FROM ≈390)"))); // The words: "(FROM 346.7)", a qualifier kept, nothing for no base. const mm = { events: [{ row: "w21", qualifier: "≈" }, { row: "w7", qualifier: null }] }; assert.equal(goalBaseText({ value: 346.7, row: "w7" }, mm), "(FROM 346.7)"); assert.equal(goalBaseText({ value: 390, row: "w21" }, mm), "(FROM ≈390)"); assert.equal(goalBaseText(null, mm), null); // Drawn on the front card under the goal, and on a back card as a line of its own, right-aligned with the words. const { html } = goalsHtml(sched, r, { fonts: {} }); assert.match(html, /
[^<]+<\/div>
\(FROM [≈<>]?[\d.]+\)<\/div>/); assert.match(html, /
]*>[^<]+<\/div>
\(FROM [≈<>]?[\d.]+\)<\/div>/); // Off: none of it. assert.doesNotMatch(goalsHtml(schedule(), renderOf(FAN), { fonts: {} }).html, /class="(fr|bf)"/); });