commit 87d47f3b4be1a2765f9aabf43ea1a3cf91a4b036 parent fc5f479e6e275718b5654b581fbbe485634171b5 Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Wed, 11 Nov 2026 14:23:35 -0500 Merge lane/frame-zero: the instruments no longer show on a cut's first frame, and the weight deck's widgets say more -- every weight said is on the by-date chart, goal cards keep their right end and may carry the weight they were set from, an update flash, three other looks for a remembered weight, and post avatars found in every channels tree Co-Authored-By: Claude <noreply@anthropic.com> Diffstat:
40 files changed, 1812 insertions(+), 151 deletions(-)
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -2368,6 +2368,7 @@ The diet he names as a rubber stamp in a corner of the footage box (`render.chro | `deck.diet.overlap` | 0–0.8, the share of each older tag hidden behind the one in front · default 0 (side by side, the slam and the dim). Above 0 the tags FAN sideways the way the goal stack's notes pile: the newest in front at the left, landing from above like a goal note, each older one a place to the right behind it with its own small turn, keeping its colours (the depth is the overlap and the shadow), showing its regime word and date in the strip beside the one in front; the one past `tags` slides off the back. The fan is narrower by what hides. An older tag's word and date need 110 design px of it, so it is refused past 0.5 (0.63 with `days`) | `umtool look <p> deck.diet.overlap=0.5` | | `deck.diet.days` | `true` · `false`: the front tag's running count of days on its diet (to the in-record date at the playhead, the streak chain's "Day N"), in a column of its own -- the tag 300 design px wide · default `false` | `umtool look <p> deck.diet.days=true` | | `deck.diet.colors`, `.labels` | `{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names | `umtool look <p> deck.diet.labels='{"glp1":"Ozempic"}'` | +| `deck.diet.flash` | bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): with `form: "tags"`: the new front tag lights, in its ink, at a new diet or new words for it -- never the running day count, never the first tag; the stamp form does not flash; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away | `umtool look <p> deck.diet.flash=false` | | `deck.diet.onPosts`, `.onChapters` | `dodge` `hide` `show` · default `dodge`: while a post item's card (its card, slot and strip as postLayout lays them: the schedule's `covers`) or a chapter band is up where it stands, it moves to a free anchor of the footage box -- a size down to half if it must, never onto another measure extra that is up -- and hides when none fits; `hide` hides, `show` stays over it | `umtool look <p> deck.diet.onPosts=hide` | | `deck.diet.position=shelf` | in its own slot on the shelf (`deck.shelf`: under or over the footage), scaled to the shelf's height, left to right in `deck.shelf.items` order -- nothing covers it there, so it never dodges (`onPosts`, `onChapters`, `x`/`y`, `scale` and `avoid` do not apply), and it is over the finale as the shelf is (`deck.shelf.finale`) | `umtool look <p> deck.shelf=true deck.diet.position=shelf` | | a timeline entry's `hideModules` | `["diet", …]` on an entry hides it over that entry's span, with its own fade, whatever it would otherwise do there (text in the footage no dodge can know of) · any entry, a post item too | `umtool set <p> <entry> hideModules=diet` (`--take <t>` for a take) | @@ -2392,11 +2393,13 @@ A sticky note per goal on a pile in a corner of the footage box, read off the sc | Knob | Range · default | From a terminal | |---|---|---| -| `deck.goals` | `true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice | `umtool look <p> deck.goals=false` | +| `deck.goals` | `true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown, base}` · default on with a measure slice | `umtool look <p> deck.goals=false` | | `deck.goals.position`, `.x`/`.y`, `.scale` | `top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1 | `umtool look <p> deck.goals.position=bottom-left` | | `deck.goals.position=shelf` | its shelf form (`deck.shelf`): the count of goals set in a column, then the notes fanned sideways like the diet's tags -- ordered by the dial's goal board (measure-goals.mjs `goalsAt(goalBoard(schedule.measure), t)`, so the shelf and the dial always agree): its headline -- the closest goal in force -- in front with "+N more" for the others in force, the rest by recency; a goal the board misses struck in red, MISSED on it, for the dial's 6 s; with no goal in force, the newest in front; a new goal landing from above as on the pile; each older one showing its goal's words in the strip beside it (all of each when there is room); a repeat comes to the front with its ×n. The fan takes the shelf's spare width (shelfLayout), up to its notes side by side. On the shelf it stays up from the first goal (`hold` unset). What the dial draws of the goal stays on the dial | `umtool look <p> deck.shelf.items='["diet","goals"]' deck.goals.position=shelf` | | `deck.goals.max`, `.color`, `.countdown` | 1–8 notes · #hex paper · bool · default 4, the palette's amber, `true` | `umtool look <p> deck.goals.max=6` | +| `deck.goals.base` | bool · default `false`: each note also says the weight he had stated when he set the goal -- "LOSE 100 (FROM 346.7)", its qualifier kept ("(FROM ≈390)") -- the slice's own base for that goal, the one the gauge reckons its target from (measure-slice.mjs `goalBase`: the start of the run open when he set it, else the latest weight he gave by the goal's date, stated or remembered). A goal with no base (no weight by then, a target goal such as "250 LB", a base the scale's foot refuses) shows none -- never one made up. On a back card it is a line of its own, right-aligned like the label | `umtool look <p> deck.goals.base=true` | | `deck.goals.hold`, `.finale` | 0 (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide` | `umtool look <p> deck.goals.hold=0` | +| `deck.goals.flash` | bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the note that lands lights as a goal is set -- not the first note (the stack coming up), not the board's own changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away | `umtool look <p> deck.goals.flash=false` | | `deck.goals.onPosts`, `.onChapters` | `dodge` `hide` `show` · default `dodge`: while a post item's card (its card, slot and strip as postLayout lays them: the schedule's `covers`) or a chapter band is up where it stands, it moves to a free anchor of the footage box -- a size down to half if it must, never onto another measure extra that is up -- and hides when none fits; `hide` hides, `show` stays over it | `umtool look <p> deck.goals.onPosts=hide` | | `deck.goals.position=shelf` | in its own slot on the shelf (`deck.shelf`: under or over the footage), scaled to the shelf's height, left to right in `deck.shelf.items` order -- nothing covers it there, so it never dodges (`onPosts`, `onChapters`, `x`/`y`, `scale` and `avoid` do not apply), and it is over the finale as the shelf is (`deck.shelf.finale`) | `umtool look <p> deck.shelf=true deck.goals.position=shelf` | | a timeline entry's `hideModules` | `["goals", …]` on an entry hides it over that entry's span, with its own fade, whatever it would otherwise do there (text in the footage no dodge can know of) · any entry, a post item too | `umtool set <p> <entry> hideModules=goals` (`--take <t>` for a take) | @@ -2419,6 +2422,8 @@ A bathroom-scale face at the top of the instruments' column (the right of the fr | `deck.dial.mark` | a weight, or `null` · default `300` (its tick and label in the accent) | `umtool look <p> deck.dial.mark=300` | | `deck.dial.ghosts`, `.goal` | bool · default `true` each (`.goal`: every goal in force, the closest headlined) | `umtool look <p> deck.dial.ghosts=false` | | `deck.measure.ghosts` | `true` · `{opacity, tolerance, ramp, pulse}` · `false` / absent: off (the default). CLAIM GHOSTS (measure-ghosts.mjs), not `deck.dial.ghosts`: every weight he has claimed so far -- each stated weight the needle goes to and each remembered one, his own, in cut order -- leaves a thin faint tick across the dial's rim at its value, under everything else on the face; a value claimed again (within `tolerance` lb of the tick's first value; an `≈` value as its rounded number; `>300` and `<300` at 300) steps that tick along the `ramp` -- 1× faint, 2× warm, 3× and up hot, a little thicker each step -- and it pulses once as the repeat lands (`pulse`). In the finale every tick stays at its count at the cut's end. Seek-safe: a frame at t draws the claims before t | `umtool look <p> deck.measure.ghosts=true` | +| `deck.dial.rememberedAs` | `needle` · `rim` · `readout` · `callout` · default `needle` (as it was: a long grey second needle from the hub to the value, its words -- "≈390 / AS OF 24 FEB 2023" -- along it). `rim`: no long needle; a bold marker across the rim at the value and a flag inside it -- "HEAVIEST ≈390 / AS OF FEB 2023 · HE SAYS" -- placed clear of the scale's figures, the hub and the readout. `readout`: a line in the readout under the date -- "HEAVIEST HE'S SAID: ≈390 (FEB 2023)", the goal under it -- and the rim marker. `callout`: as he says it a ghost needle sweeps from where the needle stands to the value and a label ("HEAVIEST HE'S SAID / ≈390 / AS OF FEB 2023") holds 2.2 s, then the rim's flag. The words are the ledger's: its qualifier, its asOf's month; HEAVIEST only for the record's highest remembered weight above every weight he stated (the peak extra's `totals.peakDrift`), else "HE SAYS HE WAS". Each is up while it is the latest remembered; the thin rim ticks of every remembered weight stay as they are | `umtool look <p> deck.dial.rememberedAs=rim` | +| `deck.measure.flash` | bool · default `false` (off: every cut renders as before) -- THE UPDATE FLASH for every measure widget at once (update-flash.mjs): at the moment a widget's shown value changes its outline lights in its own colour and decays (0.15 s up, 0.7 s down) -- the dial on a weight stated or remembered or a goal change, the odometer on the pounds lost or NET, the trail on each weight landing, the goal stack on a goal set, the diet tags on a new diet; widgets that change on one event flash together; never on frame 0, while the deck is away (the intro, a card) or on a widget's first appearance. A widget's own `flash` overrides it | `umtool look <p> deck.measure.flash=true` | | `deck.measure.ghosts.opacity`, `.tolerance` | 0.15–0.9 (the 1× tick's; +0.2 a step, at most 0.95) · 0–5 lb · default `0.5`, `0.5` | `umtool look <p> deck.measure.ghosts='{"tolerance":1}'` | | `deck.measure.ghosts.ramp`, `.pulse` | 2–4 #hex, 1× first (the last for every count from there up), or `null`: the palette's muted, amber, and amber half way to the needle's red · bool · default `null`, `true` | `umtool look <p> deck.measure.ghosts='{"ramp":["#98a29b","#e8a33f","#f37e47"],"pulse":false}'` | | `deck.dial.needle` | a #hex · default `#ff5a4e` | `umtool look <p> deck.dial.needle='"#ff5a4e"'` | @@ -2429,6 +2434,7 @@ A bathroom-scale face at the top of the instruments' column (the right of the fr | `deck.dial.corner` | `bottom-right` `bottom-left` `top-right` `top-left` · default `bottom-right` (the corner only): the dial in that corner, the odometer and the trail up the same side. The measure extras stand at their own anchors in the footage (goals bottom-right, peak top-right, promise top-centre, diet bottom-left, streak bottom-centre): a corner instrument over one that is on is REFUSED by the build, naming it -- move one (`deck.goals.position`, …) or the corner; `top-left` is clear of all five | `umtool look <p> deck.dial.corner=top-left` | | `deck.dial.motion` | `spring` `ease` · default `spring`. A VARIANT: the needle's `back.out` overshoot and settle, or a plain `power2.inOut` (the finale's drop too) | `umtool look <p> deck.dial.motion=ease` | | `deck.dial.finaleEnd` | `auto` `odometer` `promise` · default `auto` (`promise` when a promise is on camera, else `odometer`): `promise` hands the finale's last beat to the promise clock (module `promise`) -- the instruments fade out once NET has held (`dialFinaleHandoff`) and the clock takes their place in the finale's lower column, clear of the rail; with no promise module on the cut it ends on the odometer | `umtool look <p> deck.dial.finaleEnd=promise` | +| `deck.dial.flash` | bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the bezel lights as a weight is stated or remembered, or the goal in force changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away | `umtool look <p> deck.dial.flash=false` | ### Lost odometer @@ -2439,10 +2445,11 @@ Under the dial: the measure's `state.lost.total` (the highest real-time loss cla | `deck.odometer` | `true` · an object of the knobs below · `false` off · absent: ON when the cut draws a measure (`deck.measure` set), else off | `umtool look <p> deck.odometer=false` | | `deck.odometer.label` | words over the wheels, ≤ 40 · default `POUNDS HE SAYS HE'S LOST` | `umtool look <p> deck.odometer.label='"…"'` | | `deck.odometer.net`, `.runs` | bool · default `true` each | `umtool look <p> deck.odometer.net=false` | +| `deck.odometer.flash` | bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the card lights as the pounds lost go up (or the runs change) and as NET changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away | `umtool look <p> deck.odometer.flash=false` | ### Weight trail -At the foot of the instruments' column: every STATED weight the cut shows, placed by the date he was weighed (its `asOf`, else its date) across the span of them, a dot appearing at its event's `t` and the line between two neighbours drawn once both are said; a red ring on the latest said. The `mark` line (300) dashed across; with `count` and the mark at 300, `UNDER 300 · SAID n×` counts the measure's `totals.under300` rows as the cut reaches each. +At the foot of the instruments' column: every weight the cut shows -- the STATED ones and (`remembered`) the remembered ones, "≈390, as of Feb 2023" -- placed by the date he was that weight (its `asOf`, else its date), a dot appearing at its event's `t`; the line joins neighbours by date among the stated ones once both are said (a remembered one is a hollow grey dot, never joined; a qualified one hollow). The axes FIT what has been said so far (trail-plan.mjs): each new weight outside them reflows the chart over 0.4 s -- the years, the bounds, every dot -- so the time axis advances with the story; a stretch with no statement longer than `gap` is a break in the time axis (a narrow dashed band, `//` at its foot, each side with its own years) and the line across it dotted, so a decade of nothing does not take the width from the dense run after it. A red ring on the latest said. The `mark` line (300) dashed across; with `count` and the mark at 300, `UNDER 300 · SAID n×` counts the measure's `totals.under300` rows as the cut reaches each. | Knob | Range · default | From a terminal | |---|---|---| @@ -2450,6 +2457,10 @@ At the foot of the instruments' column: every STATED weight the cut shows, place | `deck.trail.mark` | a weight, or `null` · default `300` | `umtool look <p> deck.trail.mark=300` | | `deck.trail.count` | bool · default `true` | `umtool look <p> deck.trail.count=false` | | `deck.trail.label` | its title, ≤ 40 · default `WHAT HE SAYS HE WEIGHS, BY DATE` | `umtool look <p> deck.trail.label='"…"'` | +| `deck.trail.bounds` | `fit` · `fixed` · default `fit`: the axes fit the weights said so far and reflow as each lands; `fixed` lays every moment on the axes of all the cut's weights | `umtool look <p> deck.trail.bounds=fixed` | +| `deck.trail.remembered` | bool · default `true`: his remembered weights are points too, hollow and grey, not joined into the line | `umtool look <p> deck.trail.remembered=false` | +| `deck.trail.gap` | `auto` · days 30–3650 · `0` none · default `auto`: a stretch with no statement longer than a year (or 8× the median spacing, if longer) is a break in the time axis | `umtool look <p> deck.trail.gap=540` | +| `deck.trail.flash` | bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the card lights as each weight lands on it; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away | `umtool look <p> deck.trail.flash=false` | ### Flips diff --git a/umtool/lib/report/postAvatarStores.test.mjs b/umtool/lib/report/postAvatarStores.test.mjs @@ -0,0 +1,140 @@ +// The archive's authors' pictures found where they are (postReel.mjs +// archiveAvatarStores, `umtool posts avatars`, `umtool posts avatar`): +// a project whose channels tree is a SHADOW (posts copied in, no _avatars/) +// reads the corpus's stores behind it; a channel with no store at all does +// not end the search; the store's "TheSubject" is the card's "thesubject" +// (quartering-diet rev 9, 11 Nov: "copied 0 picture(s) … no picture yet for +// @thequartering, @madamsavvy" while the corpus held both). +// +// Temp dirs under UMTOOL_TEST_TMP when set (a scratch dir off /tmp), else the +// system's. +import assert from "node:assert/strict"; +import { mkdtempSync } from "node:fs"; +import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { after, test } from "node:test"; + +const BASE = process.env.UMTOOL_TEST_TMP || tmpdir(); +await mkdir(BASE, { recursive: true }); +const ROOT = mkdtempSync(path.join(BASE, "umtool-post-avatar-stores-")); +after(() => rm(ROOT, { recursive: true, force: true })); +const CORPUS = path.join(ROOT, "corpus-channels"); +const REPORTS = path.join(ROOT, "reports"); +// The corpus is CHANNELS_DIR, read when paths.mjs loads: set before the imports. +process.env.CHANNELS_DIR = CORPUS; +delete process.env.CHANNELS_FALLBACK; +const reel = await import("./postReel.mjs"); +const { postsCommand } = await import("./postsCli.mjs"); + +// First-listed channel: posts only, no posts-media/ anywhere. Then a store keyed +// "TheSubject" (as X printed it) and one keyed "MadamOther". +const CHANNELS = ["first-x", "subj-X", "other-x"]; + +async function store(tree, slug, doc) { + const dir = path.join(tree, slug, "posts-media", "_avatars"); + await mkdir(dir, { recursive: true }); + for (const a of Object.values(doc)) await writeFile(path.join(dir, a.file), "picture"); + await writeFile(path.join(dir, "avatars.json"), JSON.stringify(doc, null, 2)); +} +async function posts(tree, slug) { + await mkdir(path.join(tree, slug, "posts"), { recursive: true }); + await writeFile(path.join(tree, slug, "posts", "2026-10.jsonl"), ""); +} + +const item = (slug, id, handle) => ({ + type: "post", id: `p-${id}`, post: `${slug}/${id}`, platform: "x", author: handle.toUpperCase(), handle, + date: `2026-10-2${id}T10:00:00.000Z`, text: `post ${id}`, +}); + +async function project(name) { + const dir = path.join(REPORTS, name); + const shadow = path.join(dir, ".shadow-channels"); + for (const c of CHANNELS) await posts(shadow, c); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ + schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "", channelSlug: "subj-X", channelsDir: ".shadow-channels" }, + render: { width: 1920, height: 1080, fps: 30, palette: { bg: "#000000", fg: "#ffffff", muted: "#888888", accent: "#c8752a" } }, + // The first card spells the author in lower case, as a mention does. + timeline: [item("first-x", "1", "thesubject"), item("subj-X", "2", "TheSubject"), item("other-x", "3", "MadamOther")], + }, null, 2)); + return { id: name, dir, shadow }; +} +const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); +const cli = async (args) => { + const lines = []; + const errs = []; + const code = await postsCommand(args, { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); + return { code, out: lines.join("\n"), err: errs.join("\n") }; +}; + +for (const c of CHANNELS) await posts(CORPUS, c); +await store(CORPUS, "subj-X", { + TheSubject: { file: "TheSubject.png", url: "https://pbs.twimg.com/a.png", capturedAt: "2026-11-07T00:00:00Z" }, + MadamOther: { file: "MadamOther.jpg", capturedAt: "2026-11-01T00:00:00Z" }, +}); +await store(CORPUS, "other-x", { MadamOther: { file: "MadamOther.jpg", url: "https://pbs.twimg.com/b.jpg", capturedAt: "2026-11-07T00:00:00Z" } }); + +test("archiveAvatarStores: every tree, every channel; a missing _avatars/ is noted and skipped; keys any case", async () => { + const p = await project("unit"); + const { store: got, searched } = await reel.archiveAvatarStores([p.shadow, CORPUS], CHANNELS); + assert.deepEqual([...got.keys()].sort(), ["madamother", "thesubject"]); + assert.equal(got.get("thesubject").handle, "TheSubject"); + // The newest of two stores' pictures of one author. + assert.equal(got.get("madamother").file, path.join(CORPUS, "other-x", "posts-media", "_avatars", "MadamOther.jpg")); + assert.deepEqual(searched.map((s) => `${s.channel}@${s.tree === CORPUS ? "corpus" : "shadow"}:${s.state}`), [ + "first-x@shadow:none", "first-x@corpus:none", "subj-X@shadow:none", "subj-X@corpus:read", "other-x@shadow:none", "other-x@corpus:read", + ]); + const said = reel.avatarStoresSaid(searched); + assert.equal(said.length, 3); + assert.match(said[0], /^first-x: no _avatars\/ in .*\.shadow-channels or .*corpus-channels$/); + assert.match(said[1], /^subj-X: 2 picture\(s\) in .*corpus-channels\/subj-X\/posts-media\/_avatars; no _avatars\/ in .*\.shadow-channels$/); + // One tree, as a string, as before. + assert.equal((await reel.archiveAvatars(CORPUS, ["subj-X"])).size, 2); +}); + +test("posts avatars: a shadow-channels project copies the corpus's pictures, names the stores it searched", async () => { + const p = await project("shadowed"); + const r = await cli(["avatars", "shadowed"]); + assert.equal(r.code, 0, r.err); + assert.match(r.out, /^copied 2 picture\(s\) from subj-X \+ other-x's stores: /, r.out); + assert.doesNotMatch(r.out, /no picture yet/, r.out); + assert.match(r.out, /first-x: no _avatars\//); + const m = await manifest(p); + assert.equal(m.postAvatars.TheSubject.src, "posts-media/_avatars/TheSubject.png"); + assert.equal(m.postAvatars.TheSubject.source, "archive"); + assert.equal(m.postAvatars.MadamOther.url, "https://pbs.twimg.com/b.jpg"); + await readFile(path.join(p.dir, "posts-media", "_avatars", "TheSubject.png")); + // Again: nothing more to copy, and nobody without one. + const again = await cli(["avatars", "shadowed", "--json"]); + const j = JSON.parse(again.out); + assert.deepEqual(j.copied, {}); + assert.deepEqual(j.without, []); + assert.ok(j.stores.some((s) => s.channel === "first-x" && s.state === "none")); +}); + +test("posts avatars: no store anywhere says so, and names the author as the card draws them", async () => { + const p = await project("bare"); + const m0 = await manifest(p); + m0.timeline = [item("first-x", "1", "NoPicture")]; + await writeFile(path.join(p.dir, "video.manifest.json"), JSON.stringify(m0, null, 2)); + const r = await cli(["avatars", "bare"]); + assert.equal(r.code, 0, r.err); + assert.match(r.out, /^copied 0 picture\(s\) from no store/); + assert.match(r.out, /no picture yet for @NoPicture /); +}); + +test("posts avatar: a handle in any case sets and clears the drawn author's picture", async () => { + const p = await project("manual"); + const pic = path.join(ROOT, "manual.png"); + await writeFile(pic, "picture"); + assert.equal((await cli(["avatar", "manual", "@madamother", pic])).code, 0); + let m = await manifest(p); + assert.deepEqual(m.postAvatars, { MadamOther: { src: "posts-media/_avatars/MadamOther-manual.png", source: "manual" } }); + // The archive's never replaces it. + assert.equal((await cli(["avatars", "manual"])).code, 0); + m = await manifest(p); + assert.equal(m.postAvatars.MadamOther.source, "manual"); + assert.equal(m.postAvatars.TheSubject.source, "archive"); + assert.equal((await cli(["avatar", "manual", "MADAMOTHER", "off"])).code, 0); + assert.equal((await manifest(p)).postAvatars.MadamOther, undefined); +}); diff --git a/umtool/lib/report/postReel.mjs b/umtool/lib/report/postReel.mjs @@ -330,32 +330,92 @@ async function copyInto(projectDir, from, rel) { /** * The archive's pictures (each channel's posts-media/_avatars/avatars.json, * the editor's capture-posts store: `{ <handle>: { file, url, capturedAt } }`), - * by handle key, the newest when two channels hold one. + * by handle key -- the handle without `@`, LOWERCASED: the store keys a + * picture by the handle as X printed it ("TheQuartering"), a card or a + * mention may spell it otherwise ("@thequartering") -- the newest when two + * stores hold one. * - * @returns {Promise<Map<string, { handle: string, file: string, url: string | null, capturedAt: string | null }>>} + * `layers` is one channels tree or the trees a project reads, in order + * (projects/report.mjs channelsLayersFor: its own `.shadow-channels/` or + * `provenance.channelsDir`, then the corpus behind it). EVERY tree's store of + * EVERY channel is read -- not only the project's own tree, nor the first + * tree that holds the channel's posts: a shadow is made by copying a + * channel's `posts/` (and a capture or two), never its `_avatars/`, so the + * pictures are in the corpus while the posts are in the shadow + * (quartering-diet rev 9, 11 Nov: the shadow held the three channels' posts + * and none of their stores, `posts avatars` read the shadow alone and copied + * 0 of the two pictures the corpus had -- "no picture yet for + * @thequartering, @madamsavvy"). A channel with no store in one tree -- or in + * any -- is noted in `searched` and skipped, never the end of the search. + * + * @param {string | string[]} layers + * @param {string[]} channels + * @returns {Promise<{ store: Map<string, { handle: string, file: string, url: string | null, capturedAt: string | null }>, + * searched: Array<{ channel: string, tree: string, dir: string, state: "read" | "none" | "unreadable", pictures: number }> }>} */ -export async function archiveAvatars(channelsDir, channels) { - const out = new Map(); +export async function archiveAvatarStores(layers, channels) { + const trees = [...new Set((Array.isArray(layers) ? layers : [layers]).filter((d) => typeof d === "string" && d).map((d) => path.resolve(d)))]; + const store = new Map(); + const searched = []; for (const slug of channels) { - const dir = path.join(channelsDir, slug, "posts-media", ARCHIVE_AVATARS_DIR); - let doc; - try { - doc = JSON.parse(await readFile(path.join(dir, ARCHIVE_AVATARS_FILE), "utf8")); - } catch { - continue; - } - if (!doc || typeof doc !== "object" || Array.isArray(doc)) continue; - for (const [h, a] of Object.entries(doc)) { - if (!a || typeof a !== "object" || typeof a.file !== "string" || a.file.includes("/") || a.file.includes("\\") || !AVATAR_EXT_RE.test(a.file)) continue; - const file = path.join(dir, a.file); - if (!(await stat(file).catch(() => null))?.isFile()) continue; - const had = out.get(handleKey(h)); - const at = typeof a.capturedAt === "string" ? a.capturedAt : null; - if (had && (had.capturedAt ?? "") >= (at ?? "")) continue; - out.set(handleKey(h), { handle: h.replace(/^@/, ""), file, url: typeof a.url === "string" ? a.url : null, capturedAt: at }); + for (const tree of trees) { + const dir = path.join(tree, slug, "posts-media", ARCHIVE_AVATARS_DIR); + let doc; + try { + doc = JSON.parse(await readFile(path.join(dir, ARCHIVE_AVATARS_FILE), "utf8")); + } catch (e) { + searched.push({ channel: slug, tree, dir, state: e?.code === "ENOENT" || e?.code === "ENOTDIR" ? "none" : "unreadable", pictures: 0 }); + continue; + } + if (!doc || typeof doc !== "object" || Array.isArray(doc)) { + searched.push({ channel: slug, tree, dir, state: "unreadable", pictures: 0 }); + continue; + } + let pictures = 0; + for (const [h, a] of Object.entries(doc)) { + if (!a || typeof a !== "object" || typeof a.file !== "string" || a.file.includes("/") || a.file.includes("\\") || !AVATAR_EXT_RE.test(a.file)) continue; + const file = path.join(dir, a.file); + if (!(await stat(file).catch(() => null))?.isFile()) continue; + pictures += 1; + const k = handleKey(h); + const had = store.get(k); + const at = typeof a.capturedAt === "string" ? a.capturedAt : null; + if (had && (had.capturedAt ?? "") >= (at ?? "")) continue; + store.set(k, { handle: h.replace(/^@/, ""), file, url: typeof a.url === "string" ? a.url : null, capturedAt: at }); + } + searched.push({ channel: slug, tree, dir, state: "read", pictures }); } } - return out; + return { store, searched }; +} + +/** The archive's pictures alone (archiveAvatarStores' `store`); `layers` one channels tree or several. */ +export async function archiveAvatars(layers, channels) { + return (await archiveAvatarStores(layers, channels)).store; +} + +/** + * What archiveAvatarStores searched, in words, one line per channel: each + * store it read (and how many pictures it holds), and each tree that had + * none -- so "no picture" says WHERE it looked. PURE. + * + * @param {Array<{ channel: string, tree: string, dir: string, state: string, pictures: number }>} searched + * @returns {string[]} + */ +export function avatarStoresSaid(searched) { + const by = new Map(); + for (const s of searched ?? []) { + if (!by.has(s.channel)) by.set(s.channel, []); + by.get(s.channel).push(s); + } + const lines = []; + for (const [channel, rows] of by) { + const said = rows.filter((r) => r.state === "read").map((r) => `${r.pictures} picture(s) in ${r.dir}`); + const none = rows.filter((r) => r.state !== "read"); + if (none.length) said.push(`no ${ARCHIVE_AVATARS_DIR}/ in ${none.map((r) => `${r.tree}${r.state === "unreadable" ? ` (${ARCHIVE_AVATARS_FILE} unreadable)` : ""}`).join(" or ")}`); + lines.push(`${channel}: ${said.join("; ")}`); + } + return lines; } /** Every handle an entry's card draws UNBLURRED (a redacted author never gets a picture). */ @@ -482,9 +542,9 @@ export async function postsReel(project, o) { entries.push(made.entry); dropped += made.dropped; } - // The authors' pictures: the archive's, for every author the cards draw unblurred that the cut has none of. - const store = new Map(); - for (const c of channels) for (const [k, v] of await archiveAvatars(await root(c), [c])) if (!store.has(k)) store.set(k, v); + // The authors' pictures: the archive's, for every author the cards draw unblurred that the cut has none of -- + // from every tree's store (the project's, the corpus behind it), not only the tree its posts were read from. + const store = await archiveAvatars(layers, channels); const avatars = store.size ? await avatarsToCopy(manifest, entries, store, o.dryRun ? async (_f, rel) => rel : (from, rel) => copyInto(project.dir, from, rel)) : {}; const summary = { channels, channelsDir, archived: index.size, selected: picked.length, already, added: entries.length, droppedMedia: dropped, avatars: Object.keys(avatars) }; if (o.dryRun) return { ...summary, entries, dryRun: true, result: null, editNotes: null }; @@ -548,8 +608,8 @@ export async function postItemFromArchive(project, manifest, slug, postId, { id * @param {{ channelsDir?: string | null }} [o] */ export async function archiveAvatarsFor(project, manifest, channels, entries, { channelsDir = null } = {}) { - const dir = channelsDir ?? channelsDirFor(project.dir, manifest); - const store = await archiveAvatars(dir, channels); + // Every tree the project reads (its own, the corpus behind it): a shadow copies posts, not the stores. + const store = await archiveAvatars(channelsDir ?? channelsLayersFor(project.dir, manifest), channels); if (!store.size) return {}; return avatarsToCopy(manifest, entries, store, (from, rel) => copyInto(project.dir, from, rel)); } diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -1319,8 +1319,14 @@ async function avatarCommand(projectArg, rest, { root, json, out }) { else for (const [h, a] of Object.entries(map)) out(`@${h} ${a.src} (${a.source ?? "manual"}${a.capturedAt ? `, captured ${String(a.capturedAt).slice(0, 10)}` : ""})`); return 0; } - const h = String(handle).replace(/^@/, ""); - if (!/^[A-Za-z0-9_.-]{1,64}$/.test(h)) throw new CliError(`"${handle}" is not a handle`); + const typed = String(handle).replace(/^@/, ""); + if (!/^[A-Za-z0-9_.-]{1,64}$/.test(typed)) throw new CliError(`"${handle}" is not a handle`); + // Matched without regard to case (post-avatars.mjs handleKey): "thequartering" sets the picture of the + // author the cards draw as "TheQuartering", and is kept under that spelling (the first card's). + const { handleKey } = await import("umtool-report-to-video/post-avatars"); + const { shownHandles } = await import("./postReel.mjs"); + const drawnAs = ((await readManifest(project.dir))?.timeline ?? []).flatMap((e) => shownHandles(e)).map((x) => String(x).replace(/^@/, "")).find((x) => handleKey(x) === handleKey(typed)); + const h = drawnAs && /^[A-Za-z0-9_.-]{1,64}$/.test(drawnAs) ? drawnAs : typed; if (!file) throw new CliError(`name the picture: umtool posts avatar ${project.id} ${h} <image-file> (or off)`); if (OFF.has(String(file).toLowerCase())) { const { result, editNotes } = await withEditNotes(project, async () => setPostAvatar(project.dir, h, null, { token: await manifestToken(project.dir) })); @@ -1354,10 +1360,13 @@ async function avatarsCommand(projectArg, { root, json, dryRun, out }) { const project = await projectOf(projectArg, root); const manifest = await readManifest(project.dir); if (!manifest) throw new CliError(`${project.id} has no manifest`); - const { archiveAvatars, avatarsToCopy, postChannelsOf, shownHandles } = await import("./postReel.mjs"); - const { channelsDirFor } = await import("../projects/report.mjs"); + const { archiveAvatarStores, avatarStoresSaid, avatarsToCopy, postChannelsOf, shownHandles } = await import("./postReel.mjs"); + const { channelsLayersFor } = await import("../projects/report.mjs"); + const { handleKey } = await import("umtool-report-to-video/post-avatars"); const channels = postChannelsOf(manifest); - const store = await archiveAvatars(channelsDirFor(project.dir, manifest), channels); + // Every tree the project reads -- its own (.shadow-channels/, provenance.channelsDir) and the corpus behind + // it: a shadow copies a channel's posts, never its _avatars/ (postReel.mjs archiveAvatarStores). + const { store, searched } = await archiveAvatarStores(channelsLayersFor(project.dir, manifest), channels); const pics = store.size ? await avatarsToCopy(manifest, [], store, dryRun ? async (_f, rel) => rel : async (from, rel) => { const to = path.join(project.dir, ...rel.split("/")); @@ -1366,16 +1375,21 @@ async function avatarsCommand(projectArg, { root, json, dryRun, out }) { return rel; }) : {}; - const drawn = [...new Set((manifest.timeline ?? []).flatMap((e) => shownHandles(e)).map((h) => h.toLowerCase()))]; - const have = Object.keys(manifest.postAvatars ?? {}).map((h) => h.toLowerCase()); - const without = drawn.filter((h) => !have.includes(h) && !Object.keys(pics).some((p) => p.toLowerCase() === h)); + // The authors drawn, compared by handle key (no @, any case), each said as its first card spells it. + const drawnAs = new Map(); + for (const h of (manifest.timeline ?? []).flatMap((e) => shownHandles(e))) if (!drawnAs.has(handleKey(h))) drawnAs.set(handleKey(h), String(h).replace(/^@/, "")); + const have = new Set([...Object.keys(manifest.postAvatars ?? {}), ...Object.keys(pics)].map(handleKey)); + const without = [...drawnAs].filter(([k]) => !have.has(k)).map(([, h]) => h); let result = null; if (!dryRun && Object.keys(pics).length) ({ result } = await withEditNotes(project, async () => addArchiveAvatars(project.dir, pics, { token: await manifestToken(project.dir) }))); if (json) { - out(JSON.stringify({ ok: true, dryRun, channels, copied: pics, without, snapshot: result?.snapshot ?? null }, null, 2)); + out(JSON.stringify({ ok: true, dryRun, channels, stores: searched, copied: pics, without, snapshot: result?.snapshot ?? null }, null, 2)); return 0; } - out(`${dryRun ? "would copy" : "copied"} ${Object.keys(pics).length} picture(s) from ${channels.join(" + ") || "no channel"}'s store${Object.keys(pics).length ? `: ${Object.keys(pics).map((h) => `@${h}`).join(", ")}` : ""}`); + const read = [...new Set(searched.filter((s) => s.state === "read").map((s) => s.channel))]; + out(`${dryRun ? "would copy" : "copied"} ${Object.keys(pics).length} picture(s) from ${read.length ? `${read.join(" + ")}'s store${read.length > 1 ? "s" : ""}` : "no store"}${Object.keys(pics).length ? `: ${Object.keys(pics).map((h) => `@${h}`).join(", ")}` : ""}`); + if (!channels.length) out(" the cut has no post item from a posts channel (post: \"<channel>/<postId>\") -- no store to read"); + for (const line of avatarStoresSaid(searched)) out(` ${line}`); if (without.length) out(` no picture yet for ${without.map((h) => `@${h}`).join(", ")} (pnpm ops capture-posts … "avatars": true, or umtool posts avatar ${project.id} <handle> <image>)`); return 0; } diff --git a/umtool/report-to-video/chrome-cues.mjs b/umtool/report-to-video/chrome-cues.mjs @@ -14,6 +14,7 @@ // // PURE: data in, an HTML string out. import { pageDuration } from "./deck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ export const INSTANT = 0.001; @@ -55,7 +56,7 @@ export function compileCues(init, events) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease }); } - return { init, cues }; + return { init, cues: settleFirstFrame(init, cues) }; } /** diff --git a/umtool/report-to-video/chrome-deck.mjs b/umtool/report-to-video/chrome-deck.mjs @@ -46,6 +46,7 @@ import { claimsCues, claimsMarkup } from "./chrome-claims.mjs"; import { fitTallyLabel, resolveFactcheck, TALLY_WRITTEN, tallyCues, tallyFinals, tallyKey, tallyOf, tallyPopIns } from "./factcheck.mjs"; import { resolveCounter } from "./counter.mjs"; import { SUBSECTION_SEPARATOR } from "./marker-limits.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** * GSAP, vendored, for every chrome region. @@ -450,7 +451,7 @@ export function deckCues(schedule, render) { cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } return { - init, cues, pips, slideY, choreography: ch, ...(markers.length ? { markers } : {}), ...(claims ? { claims } : {}), + init, cues: settleFirstFrame(init, cues, fps), pips, slideY, choreography: ch, ...(markers.length ? { markers } : {}), ...(claims ? { claims } : {}), ...(sections ? { sections: { ...sections, fuses: fuseParts ?? [], rings } } : {}), ...(sectionTitle ? { sectionTitle } : {}), }; diff --git a/umtool/report-to-video/chrome-finale.mjs b/umtool/report-to-video/chrome-finale.mjs @@ -26,6 +26,7 @@ import { cueTime, cueTimeAfter, finaleRail, pageDuration, resolveDeck } from "./ import { finaleClaimsMarkup } from "./chrome-claims.mjs"; import { mix, rgba, shapeCss, subtitleMarkup, subtitlePartsCss, subtitleTokens } from "./chrome-deck.mjs"; import { resolveFactcheck, tallyCells, tallyFinals, tallyOf } from "./factcheck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; import { resolveCounter } from "./counter.mjs"; import { aboveTop, FINALE_CLAIMS, FINALE_MOTION, finaleGeometry, resolveFinale } from "./finale.mjs"; @@ -299,7 +300,7 @@ export function finaleCues(schedule, render, L = finaleLayout(schedule, render)) freeAt.set(e.k, at + dur); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } - return { init, cues }; + return { init, cues: settleFirstFrame(init, cues, fps) }; } /** diff --git a/umtool/report-to-video/chrome-instruments.mjs b/umtool/report-to-video/chrome-instruments.mjs @@ -19,6 +19,8 @@ import { mix, rgba } from "./chrome-deck.mjs"; import { finaleLayout } from "./chrome-finale.mjs"; import { FINALE_MOTION } from "./finale.mjs"; import { resolveDial, resolveOdometer, resolveTrail } from "./instruments.mjs"; +import { TRAIL_REFLOW, trailLayout, trailPoints, trailStates } from "./trail-plan.mjs"; +import { deckAwaySpans, flashCss, flashCues, flashOn, flashTimes } from "./update-flash.mjs"; import { promiseStates, upSpans } from "./measure-extras.mjs"; import { ghostOpacity, ghostRamp, ghostTicks, resolveGhosts } from "./measure-ghosts.mjs"; import { goalBoard, goalsAt } from "./measure-goals.mjs"; @@ -99,7 +101,8 @@ function withDeck(L, schedule, render, k) { const D = Number(schedule.transition) || 0; const m = Math.max(D, 0.3); for (const sd of mergedSpans(stackedStandDowns(schedule))) { - shown.push({ at: Math.max(0, sd.from), dur: m, hide: true }); + // Standing down from the cut's first instant is init, not a fade over the opening (cue-start.mjs). + shown.push({ at: Math.max(0, sd.from), dur: sd.from <= 0 ? INSTANT : m, hide: true }); if (sd.to < (schedule.total ?? Infinity) - 0.05) shown.push({ at: sd.to, dur: m, hide: false }); } // Each change once, in time: a stand-down inside a span the deck is already away for adds nothing. @@ -247,6 +250,33 @@ export function clearSpot(spots, obstacles, m = 0) { /** A centred box `w` x `h` at (x, y). */ const boxAt = (x, y, w, h) => ({ x0: x - w / 2, x1: x + w / 2, y0: y - h / 2, y1: y + h / 2 }); +/** How the dial shows a remembered weight (`deck.dial.rememberedAs`): "needle" (the long grey needle, as it was), "rim", "readout", "callout". */ +export const rememberedMode = (cfg) => (["rim", "readout", "callout"].includes(cfg?.rememberedAs) ? cfg.rememberedAs : "needle"); + +/** His highest remembered weight above every one he stated (the peak extra's `totals.peakDrift`), or null. */ +export const heaviestOf = (measure) => { + const drift = Array.isArray(measure?.totals?.peakDrift) ? measure.totals.peakDrift.filter(Number.isFinite) : []; + return drift.length ? Math.max(...drift) : null; +}; + +/** + * A remembered weight's words, from its own fields: `value` with its qualifier ("≈390"), `when` its asOf's month + * ("FEB 2023", null without one), `kind` "HEAVIEST HE'S SAID" when it is `heaviest` (heaviestOf) else "HE SAYS HE + * WAS"; and the forms the looks draw -- `head`/`sub` (the rim's flag), `line` (the readout's). + */ +export function rememberedWords(g, heaviest = null) { + const value = weightWords(g); + const top = heaviest !== null && Number.isFinite(g.value) && Math.abs(g.value - heaviest) < 0.05; + const when = g.asOf ? fmtDate(g.asOf, { day: false }) : null; + const kind = top ? "HEAVIEST HE'S SAID" : "HE SAYS HE WAS"; + return { + value, when, kind, heaviest: top, + head: top ? `HEAVIEST ${value}` : value, + sub: [when ? `AS OF ${when}` : "REMEMBERED", top ? "HE SAYS" : ""].filter(Boolean).join(" · "), + line: `${kind}: ${value}${when ? ` (${when})` : ""}`, + }; +} + /** * An as-of label's places, best first: along its ghost (angle `a`) at half the face's radius, each of its `forms` * (its small words on one line, then on two), then stepping in toward the hub; never lower than just under the hub, @@ -274,7 +304,7 @@ function asofSpots({ C, Rf, u, a, head, forms, px, fpx }) { * the hub and the readout blocks. Shared by the column's dial and the * finale's. Returns its markup and css; its cues are the caller's. */ -function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], lines = [], ghosts = null, prefix = "", preState = true }) { +function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], lines = [], ghosts = null, prefix = "", preState = true, heaviest = null }) { const face = dialFaceSvg({ size, scale, mark: cfg.mark, colors: { ...colors, mark: colors.accent }, labelFont: fontStack(fonts, "condensed") }); const { C, R, Rf, u } = face; const px = (v) => Math.round(v * u * 100) / 100; @@ -348,7 +378,8 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], parts.push(`<div class="ly" data-k="${prefix}gm${i}">${svg(`gm${i}h`, head)}${svg(`gm${i}o`, other)}${svg(`gm${i}x`, strike)}${svg(`gm${i}p`, flash)}</div>`); }); } - if (cfg.ghosts && track.remembered.length) { + const mode = rememberedMode(cfg); + if (cfg.ghosts && track.remembered.length && (mode === "needle" || mode === "callout")) { parts.push(layer("gn", `<line x1="${C}" y1="${C + 22 * u}" x2="${C}" y2="${C - Rf + 66 * u}" stroke="${colors.ghost}" stroke-width="${px(5)}" stroke-linecap="round"/>`)); } // The needle: a tapered blade from a counterweight through the hub. @@ -359,7 +390,7 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], // The as-of labels, each by its ghost, up while it is the latest -- and never on a scale figure (rev 9: "≈390 · // AS OF FEB 2025 · TOLD 4×" sat on the 380). Along its ghost, never down into the readout's words under the hub; // where its box would touch a figure's, its words go on two lines, then it steps in toward the hub. - if (cfg.ghosts) { + if (cfg.ghosts && mode === "needle") { track.remembered.forEach((g, j) => { const a = dialAngle(g.value, scale); const head = weightWords(g); @@ -371,6 +402,52 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], parts.push(`<div class="asof" data-k="${prefix}ga${j}" style="left:${spot.x}px; top:${spot.y}px"><b>${esc(head)}</b>${spot.lines.map((l) => `<span>${esc(l)}</span>`).join("")}</div>`); }); } + // THE REMEMBERED WEIGHT'S OTHER LOOKS (`deck.dial.rememberedAs`, 11 Nov: the long grey second needle and its + // small words crossed the main needle and the readout and did not say what the weight was). Each from the + // ledger's own fields -- the qualifier, the asOf, "heaviest" only for the record's highest remembered weight above + // every one he stated (the peak extra's `totals.peakDrift`) -- never words of ours. + // rim a bold marker on the rim at the value and a flag inside it, clear of the hub, the figures and the readout + // readout a line in the readout under the date ("HEAVIEST HE'S SAID: ≈390 (FEB 2023)"), a marker on the rim + // callout a ghost needle sweeps to the value as he says it, a clear label holds ~2 s, then the rim's flag + const readoutBox = { x0: C - 128 * u, x1: C + 128 * u, y0: C + 60 * u, y1: C + 230 * u }; + if (cfg.ghosts && mode !== "needle") { + const ink = mix(colors.ghost, colors.fg, 0.55); + track.remembered.forEach((g, j) => { + const w = rememberedWords(g, heaviest); + const a = dialAngle(g.value, scale); + // The marker: a bold wedge across the rim, pointing in -- the scale's own ticks show through either side. + parts.push(layer(`gk${j}`, `<polygon points="${C - 9 * u},${C - R - 3 * u} ${C + 9 * u},${C - R - 3 * u} ${C + 3 * u},${C - Rf + 30 * u} ${C - 3 * u},${C - Rf + 30 * u}" fill="${ink}" stroke="${colors.bg}" stroke-width="${px(2)}"/>`)); + if (mode === "readout") { + parts.push(`<div class="rline" data-k="${prefix}gr${j}" style="top:${C + 188 * u}px">${esc(w.line)}</div>`); + return; + } + // The flag: inside the rim by the marker -- along it, then turning a little either way, stepping in -- clear of + // the scale's figures, the hub, the readout and the needle where it stands as he says it. + const hb = px(22), hs = fpx(12); + const flagLines = [w.heaviest ? "HEAVIEST" : "REMEMBERED", w.when ? w.when : ""].filter(Boolean); + const fw = Math.max(w.value.length * hb * 0.56, ...flagLines.map((l) => l.length * hs * 0.66)) + 2 * px(8); + const fh = hb * 1.08 + flagLines.length * hs * 1.12 + 2 * px(4); + const stands = [...track.current].filter((c) => c.t <= g.t + 1e-9 && Number.isFinite(c.value)).pop(); + const needle = []; + if (stands) { + const na = dialAngle(stands.value, scale); + for (let r = 24 * u; r <= Rf - 30 * u; r += 14 * u) { const [x, y] = polar(C, C, r, na); needle.push(boxAt(x, y, 10 * u, 10 * u)); } + } + const spots = []; + for (const da of [0, -8, 8, -16, 16, -24, 24, -32, 32, -40, -48]) { + for (let r = Rf * 0.64; r >= Rf * 0.34 - 1e-9; r -= Rf * 0.04) { + const [x, y] = polar(C, C, r, a + da); + spots.push({ x, y, box: boxAt(x, y, fw, fh) }); + } + } + const spot = clearSpot(spots, [...faceFigures.map((f) => f.box), hub, readoutBox, ...needle], 4 * u); + const [l0, l1] = flagLines; + parts.push(`<div class="rflag" data-k="${prefix}gl${j}" style="left:${spot.x}px; top:${spot.y}px"><span>${esc(l0)}</span><b>${esc(w.value)}</b>${l1 ? `<span>${esc(l1)}</span>` : ""}</div>`); + if (mode === "callout") { + parts.push(`<div class="rcall" data-k="${prefix}gc${j}" style="top:${C - 104 * u}px"><span>${esc(w.kind)}</span><b>${esc(w.value)}</b>${w.when ? `<span>AS OF ${esc(w.when)}</span>` : ""}</div>`); + } + }); + } // The readout under the hub: the words, the weight, the weighing's date, the goal. // Inside the face's open quarter: each line kept within the chord at its height. parts.push(`<div class="rlab" style="top:${C + 72 * u}px">${esc(cfg.label)}</div>`); @@ -382,7 +459,9 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], }); if (cfg.goal) { lines.forEach((g, j) => { - parts.push(`<div class="goalw${g.missed ? " miss" : ""}" data-k="${prefix}gw${j}" style="top:${C + 188 * u}px">${esc(g.words)}</div>`); + // Under the remembered line when the readout carries one (rememberedAs "readout"). + const gy = cfg.ghosts && mode === "readout" && track.remembered.length ? C + 210 * u : C + 188 * u; + parts.push(`<div class="goalw${g.missed ? " miss" : ""}" data-k="${prefix}gw${j}" style="top:${gy}px">${esc(g.words)}</div>`); }); } const css = ` @@ -408,7 +487,19 @@ function dialParts({ size, ox, oy, scale, cfg, colors, fonts, track, marks = [], color: ${colors.accent}; white-space: nowrap; padding: ${px(1)}px ${px(6)}px; border-radius: ${px(5)}px; background: ${rgba(colors.face, 0.9)}; } .dial .goalw { position: absolute; left: 0; width: ${size}px; text-align: center; font-family: ${fontStack(fonts, "bold")}; font-size: ${fpx(17)}px; line-height: ${Math.max(15, px(20))}px; letter-spacing: 0.05em; color: ${colors.amber}; white-space: nowrap; } - .dial .goalw.miss { color: ${colors.needle}; }`; + .dial .goalw.miss { color: ${colors.needle}; }${cfg.ghosts && mode !== "needle" && track.remembered.length ? ` + .dial .rflag { position: absolute; transform: translate(-50%, -50%); text-align: center; white-space: nowrap; line-height: 1.08; + padding: ${px(4)}px ${px(8)}px; border-radius: ${px(6)}px; background: ${rgba(colors.face, 0.92)}; + border: ${px(1.5)}px solid ${rgba(mix(colors.ghost, colors.fg, 0.55), 0.7)}; color: ${mix(colors.ghost, colors.fg, 0.6)}; } + .dial .rflag b { display: block; font-family: ${fontStack(fonts, "display")}; font-weight: 400; font-size: ${px(22)}px; } + .dial .rflag span { display: block; font-family: ${fontStack(fonts, "condensed")}; font-size: ${fpx(12)}px; letter-spacing: 0.1em; color: ${colors.ghost}; } + .dial .rline { position: absolute; left: 0; width: ${size}px; text-align: center; font-family: ${fontStack(fonts, "condensed")}; + font-size: ${fpx(16)}px; line-height: ${Math.max(15, px(20))}px; letter-spacing: 0.06em; color: ${mix(colors.ghost, colors.fg, 0.55)}; white-space: nowrap; } + .dial .rcall { position: absolute; left: 50%; transform: translate(-50%, -50%); text-align: center; white-space: nowrap; line-height: 1.05; + padding: ${px(6)}px ${px(14)}px; border-radius: ${px(8)}px; background: ${rgba(colors.face, 0.94)}; + border: ${px(2)}px solid ${mix(colors.ghost, colors.fg, 0.55)}; color: ${mix(colors.ghost, colors.fg, 0.7)}; } + .dial .rcall b { display: block; font-family: ${fontStack(fonts, "display")}; font-weight: 400; font-size: ${px(40)}px; } + .dial .rcall span { display: block; font-family: ${fontStack(fonts, "condensed")}; font-size: ${fpx(15)}px; letter-spacing: 0.1em; color: ${colors.ghost}; }` : ""}`; return { html: `<div class="dial">${parts.join("\n ")}</div>`, css, face }; } @@ -461,7 +552,8 @@ function dialCues(L, { track, scale, cfg, marks = [], lines = [], ghosts = null, L.add(k(`gb${j}`), g.t, M.fade, { autoAlpha: 1 }, "power1.out"); } }); - if (track.remembered.length && finale) { + if (rememberedMode(cfg) !== "needle") rememberedCues(L, { track, scale, cfg, k, finale }); + else if (track.remembered.length && finale) { // All at once: the long ghost and its words on the last (the finale puts his highest there). const last = track.remembered.length - 1; const g = track.remembered[last]; @@ -482,6 +574,48 @@ function dialCues(L, { track, scale, cfg, marks = [], lines = [], ghosts = null, if (ghosts) ghostCues(L, { ghosts, scale, k, finale, at }); } +/** The callout's hold (rememberedAs "callout"): the label up this long after he says it, then the rim's flag. */ +export const CALLOUT_HOLD = 2.2; + +/** + * The remembered weight's cues in the looks other than the long needle (dialParts, `deck.dial.rememberedAs`): its + * rim marker and its flag (or its readout line) up while it is the latest remembered; with "callout", first the + * ghost needle sweeping from where the needle stands to the value and the label held CALLOUT_HOLD s. In the finale, + * the last one's, all at once. + */ +function rememberedCues(L, { track, scale, cfg, k, finale }) { + const M = INSTRUMENT_MOTION; + const R = track.remembered; + if (!R.length) return; + const mode = rememberedMode(cfg); + const call = mode === "callout" && !finale; + const label = mode === "readout" ? "gr" : "gl"; + const startOf = (g) => (call ? g.t + CALLOUT_HOLD : g.t); + R.forEach((g, j) => { + L.set(k(`gk${j}`), { rotation: dialAngle(g.value, scale), autoAlpha: 0 }); + L.set(k(`${label}${j}`), { autoAlpha: 0 }); + if (call) L.set(k(`gc${j}`), { autoAlpha: 0 }); + if (finale && j !== R.length - 1) return; + const next = finale ? null : R[j + 1]; + for (const key of [`gk${j}`, `${label}${j}`]) { + L.add(k(key), startOf(g), M.fade, { autoAlpha: 1 }, "power1.out"); + if (next) L.add(k(key), startOf(next), M.fade * 0.6, { autoAlpha: 0 }, "power1.in"); + } + }); + if (!call) return; + const a0 = dialAngle(scale.min, scale); + L.set(k("gn"), { rotation: dialAngle(R[0].value, scale), autoAlpha: 0 }); + R.forEach((g, j) => { + // From where the needle stands as he says it (his stated weight in force then; the scale's foot before one). + const cur = [...track.current].filter((c) => c.t <= g.t + 1e-9 && Number.isFinite(c.value)).pop(); + L.add(k("gn"), g.t, INSTANT, { rotation: cur ? dialAngle(cur.value, scale) : a0, autoAlpha: 0.9 }, "none"); + L.add(k("gn"), g.t + 0.05, M.needle, { rotation: dialAngle(g.value, scale) }, "power2.inOut"); + L.add(k("gn"), g.t + CALLOUT_HOLD, 0.4, { autoAlpha: 0 }, "power1.in"); + L.add(k(`gc${j}`), g.t + 0.25, M.fade, { autoAlpha: 1 }, "power1.out"); + L.add(k(`gc${j}`), g.t + CALLOUT_HOLD, 0.4, { autoAlpha: 0 }, "power1.in"); + }); +} + /** * The goal board's cues (goalMarks, goalLines): each mark's status from each board state -- the headline's triangle, * an other's tick, a miss struck in red with a flash -- and the goal line's words. @@ -578,16 +712,26 @@ export function dialHtml(schedule, render, opts = {}) { const marks = goalMarks(board, M.scale); const lines = goalLines(board); const ghosts = ghostsOf(M, render, colors); - const parts = dialParts({ size, ox: Math.floor((W - size) / 2), oy: Math.floor((H - size) / 2), scale: M.scale, cfg, colors, fonts, track, marks, lines, ghosts }); + const parts = dialParts({ size, ox: Math.floor((W - size) / 2), oy: Math.floor((H - size) / 2), scale: M.scale, cfg, colors, fonts, track, marks, lines, ghosts, heaviest: heaviestOf(M) }); const L = cueList(fps); withDeck(L, schedule, render, "rt"); dialCues(L, { track, scale: M.scale, cfg, marks, lines, ghosts }); + // THE UPDATE FLASH (update-flash.mjs): the bezel lights as a weight is stated or remembered, or the goal changes. + let flash = { html: "", css: "" }; + if (flashOn(render, cfg.flash)) { + const times = [...track.current.slice(1), ...track.remembered, ...track.goals.slice(1)].map((x) => x.t); + flashCues(L, "fl", flashTimes(times, { fps, away: deckAwaySpans(schedule, render) })); + flash = { + html: `<div class="flw" style="left:${Math.floor((W - size) / 2)}px; top:${Math.floor((H - size) / 2)}px; width:${size}px; height:${size}px"><div class="fl" data-k="fl"></div></div>`, + css: `\n .flw { position: absolute; }\n ${flashCss(".flw .fl", colors.accent, { radius: "50%", width: 3 })}`, + }; + } const { init, cues } = L.build(); return pageHtml({ id: "dial", W, H, fps, fonts, gsap: opts.gsap, data: { total: r4(schedule.total), window: windowOf(schedule, opts, "dial"), init, cues }, - css: `#rt { position: absolute; inset: 0; }${parts.css}`, - body: `<div id="rt" data-k="rt">${parts.html}</div>`, + css: `#rt { position: absolute; inset: 0; }${parts.css}${flash.css}`, + body: `<div id="rt" data-k="rt">${parts.html}${flash.html}</div>`, }); } @@ -681,12 +825,19 @@ export function odometerHtml(schedule, render, opts = {}) { }); if (cfg.runs) blocks(L, track.lost, "rn"); if (cfg.net) blocks(L, track.net, "nt"); + // THE UPDATE FLASH (update-flash.mjs): the card lights as the pounds lost go up, its runs or NET change. + let flash = { html: "", css: "" }; + if (flashOn(render, cfg.flash)) { + const times = [...track.lost.slice(1), ...(cfg.net ? track.net.slice(1) : [])].map((x) => x.t); + flashCues(L, "fl", flashTimes(times, { fps, away: deckAwaySpans(schedule, render) })); + flash = { html: `<div class="fl" data-k="fl"></div>`, css: `\n ${flashCss("#rt > .fl", colors.accent, { radius: `${Math.round(10 * u * 100) / 100}px`, width: 2 })}` }; + } const { init, cues } = L.build(); return pageHtml({ id: "odometer", W, H, fps, fonts, gsap: opts.gsap, data: { total: r4(schedule.total), window: windowOf(schedule, opts, "odometer"), init, cues }, - css: `#rt { position: absolute; inset: 0; }${parts.css}`, - body: `<div id="rt" data-k="rt">${parts.html}</div>`, + css: `#rt { position: absolute; inset: 0; }${parts.css}${flash.css}`, + body: `<div id="rt" data-k="rt">${parts.html}${flash.html}</div>`, }); } @@ -707,58 +858,126 @@ export function trailHtml(schedule, render, opts = {}) { const colors = colorsOf(render); const track = measureTrack(M); const mark = Number.isFinite(cfg.mark) ? cfg.mark : null; - // By date: each stated weight at the day it was weighed, in date order. - const pts = track.stated - .map((p, n) => ({ ...p, day: dayNumber(p.date), n })) - .filter((p) => Number.isFinite(p.day)) - .sort((a, b) => a.day - b.day || a.n - b.n); - const x0 = px(54), x1 = W - px(18), y0 = px(38), y1 = H - px(26); - let d0 = pts.length ? pts[0].day : 0, d1 = pts.length ? pts[pts.length - 1].day : 1; - if (d1 - d0 < 60) { d0 -= 30; d1 += 30; } - const vals = pts.map((p) => p.value).concat(mark !== null ? [mark] : []); - const lo = vals.length ? Math.floor((Math.min(...vals) - 5) / 10) * 10 : M.scale.min; - const hi = vals.length ? Math.ceil((Math.max(...vals) + 5) / 10) * 10 : M.scale.max; - const X = (d) => r4(x0 + ((d - d0) / (d1 - d0)) * (x1 - x0)); - const Y = (v) => r4(y1 - ((v - lo) / Math.max(1, hi - lo)) * (y1 - y0)); - const parts = []; - // The years along the foot. - const yearOf = (d) => new Date(d * 86400000).getUTCFullYear(); - for (let yr = yearOf(d0) + 1; yr <= yearOf(d1); yr += 1) { - const x = X(Date.UTC(yr, 0, 1) / 86400000); - parts.push(`<div class="yr" style="left:${x}px; top:${y1 + px(4)}px">${yr}</div><div class="ytick" style="left:${x}px; top:${y0}px; height:${y1 - y0}px"></div>`); - } - if (mark !== null && mark >= lo && mark <= hi) { - parts.push(`<div class="mark" style="left:${x0}px; top:${Y(mark)}px; width:${x1 - x0}px"></div><div class="marklab" style="left:${px(12)}px; top:${Y(mark)}px">${mark}</div>`); - } - parts.push(`<div class="lohi" style="left:${px(12)}px; top:${y0}px">${hi}</div><div class="lohi" style="left:${px(12)}px; top:${y1}px">${lo}</div>`); + // THE PLAN (trail-plan.mjs): a state per moment a weight is said -- stated, and remembered unless `remembered` is + // off -- each laid out on axes that fit what is shown, the time axis broken across long empty stretches. + const pts = trailPoints(M, { remembered: cfg.remembered !== false }); + const box = { x0: px(54), x1: W - px(18), y0: px(38), y1: H - px(26), gapPx: px(22), yearPx: px(34) }; + const states = trailStates(pts, box, { gap: cfg.gap ?? "auto", mark, bounds: cfg.bounds ?? "fit" }); + const first = states[0]?.layout ?? trailLayout([], box, { mark }); + const { y0, y1 } = box; const L = cueList(fps); withDeck(L, schedule, render, "rt"); const M2 = INSTRUMENT_MOTION; - // The line: each pair of neighbours by date, drawn once both have been said. - for (let j = 0; j + 1 < pts.length; j += 1) { - const a = pts[j], b = pts[j + 1]; - const xa = X(a.day), ya = Y(a.value), xb = X(b.day), yb = Y(b.value); - const len = r4(Math.hypot(xb - xa, yb - ya)); - const ang = r4((Math.atan2(yb - ya, xb - xa) * 180) / Math.PI); - parts.push(`<div class="seg" data-k="s${j}" style="left:${xa}px; top:${ya}px; width:${len}px"></div>`); - L.set(`s${j}`, { rotation: ang, scaleX: 0, transformOrigin: "0% 50%" }); - L.add(`s${j}`, Math.max(a.t, b.t), M2.segment, { scaleX: 1 }, "power2.out"); - } - pts.forEach((p, j) => { - parts.push(`<div class="pt${p.qualifier ? " q" : ""}" data-k="p${j}" style="left:${X(p.day)}px; top:${Y(p.value)}px"></div>`); - L.set(`p${j}`, { autoAlpha: 0, scale: 0.3 }); - L.add(`p${j}`, p.t, M2.point, { autoAlpha: 1, scale: 1 }, "back.out(2)"); + const RF = TRAIL_REFLOW; + const parts = []; + const moved = (a, b) => !a || !b || Math.abs(a.x - b.x) > 0.05 || Math.abs(a.y - b.y) > 0.05; + + // The axes: a label per year (its tick inside a cluster), a break per gap between clusters, the bounds' two figures + // and the mark line -- each shown, moved and hidden state by state; before the first weight, the first state's axes. + const yearKeys = new Map(); + const gapKeys = new Map(); + const bounds = new Map(); + states.forEach((st) => { + for (const y of st.layout.years) if (!yearKeys.has(y.key)) yearKeys.set(y.key, y); + for (const g of st.layout.gaps) if (!gapKeys.has(g.key)) gapKeys.set(g.key, g); + for (const v of [`hi${st.layout.hi}`, `lo${st.layout.lo}`]) bounds.set(v, null); }); - // The latest said, ringed in the needle's red: it travels to each as it lands. - if (pts.length) { - parts.push(`<div class="ring" data-k="pl"></div>`); - const inCut = [...pts].sort((a, b) => a.t - b.t || a.n - b.n); - L.set("pl", { x: X(inCut[0].day), y: Y(inCut[0].value), autoAlpha: 0 }); - inCut.forEach((p, j) => { - if (j === 0) L.add("pl", p.t, M2.point, { autoAlpha: 1 }, "power1.out"); - else L.add("pl", p.t, M2.point, { x: X(p.day), y: Y(p.value) }, "power2.inOut"); - }); + if (!states.length) for (const v of [`hi${first.hi}`, `lo${first.lo}`]) bounds.set(v, null); + for (const [key, y] of yearKeys) { + parts.push(`<div class="yw" data-k="y${key}">${y.tick ? `<div class="ytick" style="top:${y0}px; height:${r4(y1 - y0)}px"></div>` : ""}<div class="yr" style="top:${r4(y1 + px(4))}px">${y.text}</div></div>`); + } + for (const [key] of gapKeys) { + parts.push(`<div class="gp" data-k="g${key}" style="top:${y0}px; height:${r4(y1 - y0)}px"><div class="gz">//</div></div>`); } + for (const key of bounds.keys()) { + parts.push(`<div class="lohi" data-k="b${key}" style="left:${px(12)}px; top:${key.startsWith("hi") ? y0 : y1}px">${key.slice(2)}</div>`); + } + if (mark !== null) parts.push(`<div class="mark" data-k="mk" style="left:${box.x0}px; width:${r4(box.x1 - box.x0)}px"></div><div class="marklab" data-k="ml" style="left:${px(12)}px">${mark}</div>`); + const axisAt = (layout, at, prev) => { + const vis = (list) => new Map(list.map((x) => [x.key, x])); + const ys = vis(layout.years), gs = vis(layout.gaps); + const pys = prev ? vis(prev.years) : new Map(), pgs = prev ? vis(prev.gaps) : new Map(); + for (const [key] of yearKeys) { + const now = ys.get(key), was = pys.get(key); + if (!prev) { L.set(`y${key}`, { x: (now ?? yearKeys.get(key)).x ?? 0, autoAlpha: now ? 1 : 0 }); continue; } + if (now && was) { if (Math.abs(now.x - was.x) > 0.05) L.add(`y${key}`, at, RF, { x: now.x }, "power2.inOut"); } + else if (now) L.add(`y${key}`, at, RF, { x: now.x, autoAlpha: 1 }, "power2.out"); + else if (was) L.add(`y${key}`, at, RF * 0.6, { autoAlpha: 0 }, "power1.in"); + } + for (const [key] of gapKeys) { + const now = gs.get(key), was = pgs.get(key); + if (!prev) { L.set(`g${key}`, { x: (now ?? gapKeys.get(key)).x, autoAlpha: now ? 1 : 0 }); continue; } + if (now && was) { if (Math.abs(now.x - was.x) > 0.05) L.add(`g${key}`, at, RF, { x: now.x }, "power2.inOut"); } + else if (now) L.add(`g${key}`, at, RF, { x: now.x, autoAlpha: 1 }, "power2.out"); + else if (was) L.add(`g${key}`, at, RF * 0.6, { autoAlpha: 0 }, "power1.in"); + } + // A bound's figure gives way to the mark's when they would sit on each other. + const clear = (lay, v) => mark === null || Math.abs(lay.Y(mark) - lay.Y(v)) >= px(14); + const shows = (lay, key) => (key === `hi${lay.hi}` && clear(lay, lay.hi)) || (key === `lo${lay.lo}` && clear(lay, lay.lo)); + for (const key of bounds.keys()) { + const on = shows(layout, key); + const was = prev ? shows(prev, key) : null; + if (!prev) L.set(`b${key}`, { autoAlpha: on ? 1 : 0 }); + else if (on !== was) L.add(`b${key}`, at, RF * 0.6, { autoAlpha: on ? 1 : 0 }, "power1.inOut"); + } + if (mark !== null) { + const y = layout.Y(mark); + if (!prev) { L.set("mk", { y }); L.set("ml", { y, yPercent: -50 }); } + else if (Math.abs(prev.Y(mark) - y) > 0.05) { L.add("mk", at, RF, { y }, "power2.inOut"); L.add("ml", at, RF, { y }, "power2.inOut"); } + } + }; + axisAt(first, 0, null); + + // The points: each pops in at its place in the state it is said in, then moves with every reflow after. + const firstState = new Map(); + states.forEach((st, j) => { for (const n of st.shown) if (!firstState.has(n)) firstState.set(n, j); }); + for (const p of pts) { + const j = firstState.get(p.n); + const at = states[j].pos.get(p.n); + const cls = `pt${p.kind === "remembered" ? " rem" : ""}${p.qualifier ? " q" : ""}`; + parts.push(`<div class="${cls}" data-k="p${p.n}"></div>`); + L.set(`p${p.n}`, { x: at.x, y: at.y, autoAlpha: 0, scale: 0.3 }); + L.add(`p${p.n}`, p.t, M2.point, { autoAlpha: 1, scale: 1 }, "back.out(2)"); + } + // The line: neighbours by date among the stated points shown, a pair drawn in when it first is one, moved with the + // reflows while it lasts, gone the moment a weight said later lands between them. Across a break it is dotted. + const pairFirst = new Map(); + states.forEach((st, j) => { for (const pr of st.pairs) if (!pairFirst.has(pr.key)) pairFirst.set(pr.key, { ...pr, j }); }); + const geomOf = (st, pr) => { + const a = st.pos.get(pr.a), b = st.pos.get(pr.b); + return { x: a.x, y: a.y, width: r4(Math.hypot(b.x - a.x, b.y - a.y)), rotation: r4((Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI) }; + }; + for (const [key, pr] of pairFirst) { + parts.push(`<div class="seg${pr.gap ? " gap" : ""}" data-k="s${key}"></div>`); + L.set(`s${key}`, { ...geomOf(states[pr.j], pr), scaleX: 0, autoAlpha: 1, transformOrigin: "0% 50%" }); + L.add(`s${key}`, states[pr.j].at, M2.segment, { scaleX: 1 }, "power2.out"); + } + // The latest said, ringed in the needle's red: it travels to each as it lands, and with the reflows. + if (pts.length) parts.push(`<div class="ring" data-k="pl"></div>`); + states.forEach((st, j) => { + const prev = j ? states[j - 1] : null; + const latest = pts.filter((p) => p.t <= st.at + 1e-9).at(-1); + if (!prev) { + const at0 = st.pos.get(latest.n); + L.set("pl", { x: at0.x, y: at0.y, autoAlpha: 0 }); + L.add("pl", st.at, M2.point, { autoAlpha: 1 }, "power1.out"); + return; + } + axisAt(st.layout, st.at, prev.layout); + for (const n of prev.shown) { + const a = prev.pos.get(n), b = st.pos.get(n); + if (moved(a, b)) L.add(`p${n}`, st.at, RF, { x: b.x, y: b.y }, "power2.inOut"); + } + const was = new Map(prev.pairs.map((pr) => [pr.key, pr])); + const now = new Map(st.pairs.map((pr) => [pr.key, pr])); + for (const [key, pr] of was) { + if (!now.has(key)) { L.add(`s${key}`, st.at, RF * 0.5, { autoAlpha: 0 }, "power1.in"); continue; } + const g0 = geomOf(prev, pr), g1 = geomOf(st, pr); + if (moved(g0, g1) || Math.abs(g0.width - g1.width) > 0.05 || Math.abs(g0.rotation - g1.rotation) > 0.05) L.add(`s${key}`, st.at, RF, g1, "power2.inOut"); + } + const ring = st.pos.get(latest.n); + L.add("pl", st.at, RF, { x: ring.x, y: ring.y }, "power2.inOut"); + }); // How many times he says he is under 300, counted as each lands. const counts = cfg.count && mark === 300 ? track.under.slice().sort((a, b) => a.t - b.t).map((x, n) => ({ t: x.t, n: n + 1 })) : []; counts.forEach((c) => parts.push(`<div class="cnt" data-k="uc${c.n - 1}">UNDER ${mark} · SAID ${c.n}×</div>`)); @@ -770,26 +989,39 @@ export function trailHtml(schedule, render, opts = {}) { if (sp.out < schedule.total - 0.05) L.add("ty", sp.out, 0.4, { autoAlpha: 1 }, "power1.out"); } L.set("ty", { autoAlpha: 1 }); + // THE UPDATE FLASH (update-flash.mjs): the card lights as each weight lands on it. + const flashing = flashOn(render, cfg.flash); + if (flashing) { + flashCues(L, "fl", flashTimes(states.map((st) => st.at), { fps, away: deckAwaySpans(schedule, render) })); + parts.push(`<div class="fl" data-k="fl"></div>`); + } const { init, cues } = L.build(); const css = ` #rt { position: absolute; inset: 0; } - .ty { position: absolute; inset: 0; } - .trail { position: absolute; inset: 0; border-radius: ${px(10)}px; background: ${colors.card}; } + .ty { position: absolute; inset: 0; }${flashing ? `\n ${flashCss(".trail .fl", colors.accent, { radius: `${px(10)}px`, width: 2 })}` : ""} + .trail { position: absolute; inset: 0; border-radius: ${px(10)}px; background: ${colors.card}; overflow: hidden; } .trail .lab { position: absolute; left: ${px(14)}px; top: ${px(10)}px; font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; letter-spacing: 0.12em; color: ${colors.muted}; white-space: nowrap; } .trail .cnt { position: absolute; right: ${px(16)}px; top: ${px(9)}px; font-family: ${fontStack(fonts, "bold")}; font-size: ${px(15)}px; letter-spacing: 0.06em; color: ${colors.accent}; white-space: nowrap; } - .trail .yr { position: absolute; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(13)}px; - color: ${colors.muted}; letter-spacing: 0.06em; } - .trail .ytick { position: absolute; width: 1px; background: ${colors.rule}; } - .trail .mark { position: absolute; height: 0; border-top: ${px(2)}px dashed ${rgba(colors.accent, 0.75)}; } + .trail .yw { position: absolute; left: 0; top: 0; width: 0; height: 0; } + .trail .yr { position: absolute; left: 0; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(13)}px; + color: ${colors.muted}; letter-spacing: 0.06em; white-space: nowrap; } + .trail .ytick { position: absolute; left: 0; width: 1px; background: ${colors.rule}; } + .trail .gp { position: absolute; left: 0; width: ${px(14)}px; margin-left: -${px(7)}px; background: ${rgba(colors.muted, 0.08)}; } + .trail .gz { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-family: ${fontStack(fonts, "condensed")}; + font-size: ${px(13)}px; color: ${colors.muted}; letter-spacing: -0.1em; } + .trail .mark { position: absolute; top: 0; height: 0; border-top: ${px(2)}px dashed ${rgba(colors.accent, 0.75)}; } .trail .marklab, .trail .lohi { position: absolute; transform: translateY(-50%); font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(13)}px; color: ${colors.muted}; } - .trail .marklab { color: ${colors.accent}; font-family: ${fontStack(fonts, "bold")}; } - .trail .seg { position: absolute; height: ${px(2.6)}px; margin-top: -${px(1.3)}px; background: ${colors.accent}; border-radius: ${px(2)}px; } - .trail .pt { position: absolute; width: ${px(10)}px; height: ${px(10)}px; margin: -${px(5)}px 0 0 -${px(5)}px; border-radius: 50%; + .trail .marklab { top: 0; transform: none; color: ${colors.accent}; font-family: ${fontStack(fonts, "bold")}; } + .trail .seg { position: absolute; left: 0; top: 0; height: ${px(2.6)}px; margin-top: -${px(1.3)}px; background: ${colors.accent}; border-radius: ${px(2)}px; } + .trail .seg.gap { height: 0; margin-top: -${px(1)}px; background: none; border-top: ${px(2)}px dotted ${rgba(colors.accent, 0.55)}; border-radius: 0; } + .trail .pt { position: absolute; left: 0; top: 0; width: ${px(10)}px; height: ${px(10)}px; margin: -${px(5)}px 0 0 -${px(5)}px; border-radius: 50%; background: ${colors.accent}; border: ${px(2)}px solid ${colors.card}; } .trail .pt.q { background: ${colors.card}; border: ${px(2.4)}px solid ${colors.accent}; } + .trail .pt.rem { background: ${colors.card}; border: ${px(2.4)}px solid ${colors.ghost}; } + .trail .pt.rem.q { border-style: dashed; } .trail .ring { position: absolute; left: 0; top: 0; width: ${px(20)}px; height: ${px(20)}px; margin: -${px(10)}px 0 0 -${px(10)}px; border-radius: 50%; border: ${px(3)}px solid ${colors.needle}; }`; return pageHtml({ @@ -934,7 +1166,7 @@ export function dialFinaleHtml(schedule, render, window, opts = {}) { const k = size / 524; const dial = dialParts({ size, ox: portrait ? Math.floor((W - size) / 2) : 0, oy: portrait ? titleH + Math.round(18 * u) + Math.floor((cardH - size) / 2) : Math.floor((H - size) / 2), - scale: M.scale, cfg, colors, fonts, track, marks, lines, ghosts, prefix: "f", preState: false, + scale: M.scale, cfg, colors, fonts, track, marks, lines, ghosts, prefix: "f", preState: false, heaviest: heaviestOf(M), }); const rw = portrait ? W - Math.round(48 * u) : W - size - Math.round(40 * k); const top = Math.max(Number(M.totals?.lost) || 0, nums.lost); diff --git a/umtool/report-to-video/chrome-measure-extras.mjs b/umtool/report-to-video/chrome-measure-extras.mjs @@ -22,6 +22,7 @@ import { import { dietTagWidth, MEASURE_RED, resolveMeasureExtra, SHELF_POSITION } from "./modules/measure-extras-settings.mjs"; import { dialFinaleGeometry, dialFinaleHandoff } from "./chrome-instruments.mjs"; import { goalBoard, goalsAt } from "./measure-goals.mjs"; +import { deckAwaySpans, flashCss, flashEvents, flashOn, flashTimes } from "./update-flash.mjs"; /** How each module's panel comes in and goes out, s. */ export const MEASURE_FADE = Object.freeze({ in: 0.35, out: 0.4 }); @@ -203,9 +204,19 @@ export function goalsHtml(schedule, render, opts = {}) { const paper = cfg.color ?? pal.amber ?? "#E8A33F"; const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; + // THE UPDATE FLASH (update-flash.mjs): a goal set lights the note that lands -- not the first, the stack's entrance. + const flashing = flashOn(render, cfg.flash); + const away = flashing ? deckAwaySpans(schedule, render) : []; const { init, cues } = stateCues(states, spans, { own: (st, j, init) => { const ev = []; + if (flashing && j > 0) { + const top = st.notes.find((n) => n.key === st.top); + if (top) { + init[`s${j}.${top.id}.fl`] = { opacity: 0 }; + ev.push(...flashEvents(`s${j}.${top.id}.fl`, flashTimes([st.at], { fps: F.fps, away }))); + } + } for (const n of st.notes) { const k = `s${j}.${n.id}`; const to = notePlace(n, n.depth, px, H); @@ -236,7 +247,9 @@ export function goalsHtml(schedule, render, opts = {}) { : ""; const count = n.count > 1 ? `<div class="ct" data-k="${k}c">×${n.count}</div>` : ""; const shade = n.depth ? `<div class="sh" style="opacity:${r4(Math.min(0.5, 0.14 * n.depth))}"></div>` : ""; - return `<div class="note${dl ? " due" : ""}" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${dl}${count}${shade}</div>`; + const fr = n.base ? `<div class="fr">${esc(n.base)}</div>` : ""; + const fl = flashing && j > 0 && n.key === st.top ? `<div class="fl" data-k="${k}.fl"></div>` : ""; + return `<div class="note${dl ? " due" : ""}${fr ? " based" : ""}" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${fr}${dl}${count}${shade}${fl}</div>`; }).join(""); const html = `<div class="st" data-k="s${j}">${notes}<div class="hd"><span class="hn">${st.goalsSet}</span> goal${st.goalsSet === 1 ? "" : "s"} set</div></div>`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); @@ -256,6 +269,9 @@ export function goalsHtml(schedule, render, opts = {}) { text-transform: uppercase; color: rgba(42, 28, 6, 0.62); } .nt { font-family: ${DISPLAY}; font-size: ${px(54)}px; line-height: ${px(58)}px; white-space: nowrap; letter-spacing: 0.01em; } .due .nt { font-size: ${px(44)}px; line-height: ${px(48)}px; } + .based .nt { font-size: ${px(46)}px; line-height: ${px(50)}px; } + .based.due .nt { font-size: ${px(38)}px; line-height: ${px(41)}px; } + .fr { font-family: ${DISPLAY}; font-size: ${px(22)}px; line-height: ${px(25)}px; color: rgba(42, 28, 6, 0.78); white-space: nowrap; letter-spacing: 0.02em; } .dl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; line-height: ${px(23)}px; color: #7d150c; white-space: nowrap; } .dl2 { font-family: 'DeckSansBold', sans-serif; font-size: ${px(18)}px; line-height: ${px(22)}px; color: rgba(42, 28, 6, 0.8); white-space: nowrap; } /* The count sits in the note's top strip: what shows of a note further down the pile. */ @@ -266,13 +282,27 @@ export function goalsHtml(schedule, render, opts = {}) { .hd { position: absolute; left: ${px(10)}px; bottom: ${px(4)}px; height: ${px(32)}px; padding: 0 ${px(14)}px; border-radius: ${px(16)}px; background: ${rgba(pal.bg, 0.88)}; color: ${pal.muted}; font-family: 'DeckSansBold', sans-serif; font-size: ${px(17)}px; line-height: ${px(32)}px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; } - .hn { color: ${paper}; font-family: ${DISPLAY}; font-size: ${px(22)}px; letter-spacing: 0.02em; }`; + .hn { color: ${paper}; font-family: ${DISPLAY}; font-size: ${px(22)}px; letter-spacing: 0.02em; }${flashing ? ` + ${flashCss(".note .fl", paper, { radius: `${px(5)}px`, width: Math.max(2, Math.round(px(3))), inset: `-${px(5)}px` })}` : ""}`; const body = `<div id="pn" data-k="pn"> ${blocks.join("\n ")} </div>`; return { html: page("goals", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render), items }; } +/** A back card's padding (design px): its sides and foot, and the top it leaves to the ×n badge. */ +export const GOALS_BACK = Object.freeze({ pad: 8, top: 30, max: 24, min: 17 }); + +/** + * A back card's words a size that fits `room` (design px, the strip that shows) when they can -- the display face + * at ~0.5 em a letter, 24 px at most -- and 17 px at the least: below that they keep their size, right-aligned, and + * their left goes under the card in front. + */ +export function backTextSize(text, room) { + const n = Math.max(1, [...String(text)].length); + return Math.max(GOALS_BACK.min, Math.min(GOALS_BACK.max, Math.floor(room / (0.5 * n)))); +} + /** * The goal stack ON THE SHELF (`goals.position: "shelf"`): the count of goals * set in a column at the left, then the notes -- the same paper, tape, shadow @@ -294,6 +324,8 @@ function goalsShelfHtml(schedule, render, opts, cfg, states) { const room = geo.width / F.k - G.count - G.gap - G.card; const step = max > 1 ? Math.max(G.back, Math.min(G.card + G.step, room / (max - 1))) : 0; const backs = step < G.card; + // The strip of a back card that shows beside the card in front (design px), less its padding. + const strip = Math.min(step, G.card) - 14 - 2 * GOALS_BACK.pad; const place = (note, depth) => ({ x: px(G.count + G.gap + depth * step), y: Math.round(px(6) + note.dx * 0.15 * F.k + (depth ? px(1) : 0)), @@ -304,9 +336,22 @@ function goalsShelfHtml(schedule, render, opts, cfg, states) { // THE ORDER ON THE SHELF is the dial's (shelfGoalStates): the goal board's headline -- the closest goal in force -- // in front with "+N more" for the others in force, the rest by how recently he set them, a missed goal struck. const shelfStates = shelfGoalStates(schedule, states); + // THE UPDATE FLASH (update-flash.mjs): a goal set lights the note that lands -- not the first, the shelf's entrance. + const flashing = flashOn(render, cfg.flash); + const away = flashing ? deckAwaySpans(schedule, render) : []; + const flashKey = (st, j) => { + if (!flashing || j === 0 || !st.top) return null; + const top = st.notes.find((n) => n.key === st.top); + return top ? `s${j}.${top.id}.fl` : null; + }; const { init, cues } = stateCues(shelfStates, spans, { own: (st, j, init) => { const ev = []; + const fk = flashKey(st, j); + if (fk) { + init[fk] = { opacity: 0 }; + ev.push(...flashEvents(fk, flashTimes([st.at], { fps: F.fps, away }))); + } for (const n of st.notes) { const k = `s${j}.${n.id}`; const to = place(n, n.depth); @@ -348,13 +393,18 @@ function goalsShelfHtml(schedule, render, opts, cfg, states) { const more = n.depth === 0 && st.headline && Number.isFinite(st.active) && st.active > 1 ? `<div class="mo">+${st.active - 1} more</div>` : ""; const front = n.depth === 0 || !backs; const crossing = backs && n.prev === 0 && n.depth > 0; - const face = `<div class="nf"${crossing ? ` data-k="${k}f"` : ""} style="opacity:${front || crossing ? 1 : 0}"><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${dl}</div>`; + const fr = n.base ? `<div class="fr">${esc(n.base)}</div>` : ""; + const face = `<div class="nf${fr ? " based" : ""}"${crossing ? ` data-k="${k}f"` : ""} style="opacity:${front || crossing ? 1 : 0}"><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${fr}${dl}</div>`; + // A BACK CARD's words end at its right edge and are never cut there (11 Nov): the right end is what tells one + // goal from another ("LOSE 1…" read as any of three). Sized to fit the strip that shows when they can + // (backTextSize); when they cannot, it is their LEFT that goes under the card in front. const back = backs && n.depth > 0 - ? `<div class="nb"${crossing ? ` data-k="${k}b"` : ""} style="opacity:${crossing ? 0 : 1}"><div class="bt">${esc(n.text)}</div>${n.date ? `<div class="bh">${esc(monthYear(n.date))}</div>` : ""}</div>` + ? `<div class="nb"${crossing ? ` data-k="${k}b"` : ""} style="opacity:${crossing ? 0 : 1}"><div class="bt" style="font-size:${px(backTextSize(n.text, strip))}px">${esc(n.text)}</div>${n.base ? `<div class="bf">${esc(n.base)}</div>` : ""}${n.date ? `<div class="bh">${esc(monthYear(n.date))}</div>` : ""}</div>` : ""; // Missed (the board's, held as the dial holds it): struck in red, MISSED on it. const miss = st.missed?.includes(n.key) ? `<div class="mx"></div><div class="ms">Missed</div>` : ""; - return `<div class="note${miss ? " missed" : ""}" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div>${face}${back}${count}${more}${miss}</div>`; + const fl = flashKey(st, j) === `${k}.fl` ? `<div class="fl" data-k="${k}.fl"></div>` : ""; + return `<div class="note${miss ? " missed" : ""}" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div>${face}${back}${count}${more}${miss}${fl}</div>`; }).join(""); const html = `<div class="st" data-k="s${j}"><div class="gc"><div class="gn" data-k="s${j}.c">${st.goalsSet}</div><div class="gl">goal${st.goalsSet === 1 ? "" : "s"} set</div></div>${notes}</div>`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); @@ -374,16 +424,19 @@ function goalsShelfHtml(schedule, render, opts, cfg, states) { .tape { position: absolute; left: 50%; top: ${px(-6)}px; width: ${px(70)}px; height: ${px(18)}px; margin-left: ${px(-35)}px; background: rgba(255, 255, 255, 0.38); transform: rotate(-3deg); } .nf { position: absolute; inset: 0; padding: ${px(8)}px ${px(14)}px; display: flex; flex-direction: column; justify-content: center; gap: ${px(1)}px; overflow: hidden; } - .nb { position: absolute; right: 0; top: 0; bottom: 0; width: ${px(Math.min(step, G.card) - 14)}px; padding: 0 ${px(6)}px; - display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; } + .nb { position: absolute; left: 0; right: 0; top: 0; bottom: 0; padding: ${px(GOALS_BACK.top)}px ${px(GOALS_BACK.pad)}px ${px(GOALS_BACK.pad)}px; + display: flex; flex-direction: column; justify-content: center; align-items: flex-end; text-align: right; overflow: hidden; } .nh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(42, 28, 6, 0.62); white-space: nowrap; } .nt { font-family: ${DISPLAY}; font-size: ${px(40)}px; line-height: ${px(44)}px; white-space: nowrap; letter-spacing: 0.01em; } .dl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; color: #7d150c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } - .bt { font-family: ${DISPLAY}; font-size: ${px(24)}px; line-height: ${px(27)}px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; } + .bt { font-family: ${DISPLAY}; line-height: 1.12; white-space: nowrap; flex: none; } + .bf { font-family: ${DISPLAY}; font-size: ${px(15)}px; line-height: ${px(18)}px; color: rgba(42, 28, 6, 0.78); white-space: nowrap; flex: none; } .bh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(15)}px; letter-spacing: 0.1em; text-transform: uppercase; - color: rgba(42, 28, 6, 0.62); white-space: nowrap; } + color: rgba(42, 28, 6, 0.62); white-space: nowrap; flex: none; } + .fr { font-family: ${DISPLAY}; font-size: ${px(18)}px; line-height: ${px(20)}px; color: rgba(42, 28, 6, 0.78); white-space: nowrap; letter-spacing: 0.02em; } + .nf.based .nt { font-size: ${px(36)}px; line-height: ${px(38)}px; } .mo { position: absolute; right: ${px(8)}px; bottom: ${px(6)}px; padding: 0 ${px(7)}px; height: ${px(20)}px; border-radius: ${px(10)}px; background: rgba(42, 28, 6, 0.85); color: ${paper}; font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(20)}px; } .mx { position: absolute; left: ${px(6)}px; right: ${px(6)}px; top: 50%; height: ${px(4)}px; margin-top: ${px(-2)}px; background: ${MEASURE_RED}; @@ -393,7 +446,8 @@ function goalsShelfHtml(schedule, render, opts, cfg, states) { letter-spacing: 0.1em; text-transform: uppercase; } .ct { position: absolute; right: ${px(8)}px; top: ${px(5)}px; min-width: ${px(40)}px; height: ${px(24)}px; padding: 0 ${px(7)}px; border-radius: ${px(12)}px; background: #2a1c06; color: ${paper}; text-align: center; - font-family: ${DISPLAY}; font-size: ${px(19)}px; line-height: ${px(24)}px; }`; + font-family: ${DISPLAY}; font-size: ${px(19)}px; line-height: ${px(24)}px; }${flashing ? ` + ${flashCss(".note .fl", paper, { radius: `${px(4)}px`, width: Math.max(2, Math.round(px(3))), inset: `-${px(4)}px` })}` : ""}`; const body = `<div id="pn" data-k="pn"> ${blocks.join("\n ")} </div>`; @@ -993,6 +1047,21 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { dayBlocks.get(r.card).push(`<div class="dy" data-k="${k}"><div class="dyn">${r.days}</div><div class="dyl">day${r.days === 1 ? "" : "s"}</div></div>`); }); } + // THE UPDATE FLASH (update-flash.mjs): a new diet -- a new front tag, or new words for it -- lights that tag in its + // ink; never the running day count, never the first tag (the badge's entrance). + const flashing = flashOn(render, cfg.flash); + const flashed = new Set(); + if (flashing) { + const away = deckAwaySpans(schedule, render); + states.forEach((st, j) => { + const front = st.tags[0]?.id; + if (!j || front === undefined || front === states[j - 1].tags[0]?.id) return; + const k = `t${front}.fl`; + init[k] = { opacity: 0 }; + flashed.add(front); + ev.push(...flashEvents(k, flashTimes([st.at], { fps: F.fps, away }))); + }); + } const { cues } = compileCues(init, ev); const items = []; const room = DIET_TAG.width - 44; @@ -1015,14 +1084,16 @@ function dietTagsHtml(schedule, render, opts, cfg, states) { ? `<div class="bk" data-k="${k}.b"><div class="bl" style="font-size:${px(Math.min(32, tagWordSize(label, step - 30)))}px">${esc(label)}</div>${date ? `<div class="bd">${esc(date)}</div>` : ""}</div>` : ""; const html = `<div class="tg" data-k="${k}"${fan ? ` style="z-index:${10 + t.id}"` : ""}><div class="dm" data-k="${k}.d"><div class="sw" data-k="${k}.w"><div class="sp${d ? "" : " off"}" data-k="${k}.s">` + - `<div class="ink" style="color:${ink};border-color:${ink}"><div class="fr"${fan ? ` data-k="${k}.f"` : ""}>${face}</div>${back}</div></div></div></div></div>`; + `<div class="ink" style="color:${ink};border-color:${ink}"><div class="fr"${fan ? ` data-k="${k}.f"` : ""}>${face}</div>${back}</div>` + + `${flashed.has(t.id) ? `<div class="fl" data-k="${k}.fl" style="color:${ink}"></div>` : ""}</div></div></div></div>`; items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .tg { position: absolute; left: 0; top: 0; width: ${px(W)}px; height: ${px(DIET_TAG.height)}px; visibility: hidden; opacity: 0;${fan ? " transform-origin: 30% 60%;" : ""} } - .dm, .sw { position: absolute; inset: 0; } + .dm, .sw { position: absolute; inset: 0; }${flashing ? ` + ${flashCss(".sp > .fl", "currentColor", { radius: `${px(9)}px`, width: Math.max(2, Math.round(px(3))), inset: `-${px(2)}px` })}` : ""} /* A tag: the stamp's plate and pressed ink, small. The plate is solid; only the ink is pressed. */ .sp { position: absolute; left: ${px(4)}px; top: ${px(4)}px; right: ${px(4)}px; bottom: ${px(4)}px; border-radius: ${px(8)}px; background: ${rgba(pal.bg, fan ? 0.97 : 0.93)}; padding: ${px(4)}px; diff --git a/umtool/report-to-video/chrome-posts.mjs b/umtool/report-to-video/chrome-posts.mjs @@ -34,6 +34,7 @@ import { formatDeckDate } from "./attribution.mjs"; import { pageDuration, postsGeometry, resolveDeck, snapWindow } from "./deck.mjs"; import { mix, rgba } from "./chrome-deck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; // The window arithmetic is deck.mjs's (pure, and loaded by the build without // this page module); re-exported for the page's own callers. @@ -195,7 +196,7 @@ export function postsCues({ // keeps every element's own order (and so every from). cues.sort((x, y) => x.at - y.at || x.n - y.n); for (const c of cues) delete c.n; - return { tops, init, cues }; + return { tops, init, cues: settleFirstFrame(init, cues) }; } /** A card's head: `@handle · Bluesky`, the separator in the deck's accent. */ @@ -428,6 +429,7 @@ export function postsHtml(schedule, render, window, opts = {}) { const P = JSON.parse(document.getElementById("posts-data").textContent); const byK = {}; for (const el of document.querySelectorAll("[data-k]")) byK[el.dataset.k] = el; + ${embedFn("settleFirstFrame", settleFirstFrame)} ${embedFn("postsCues", postsCues)} const params = new URLSearchParams(location.search); diff --git a/umtool/report-to-video/chrome-stamp.mjs b/umtool/report-to-video/chrome-stamp.mjs @@ -14,6 +14,7 @@ import { cueTime, cueTimeAfter, pageDuration, stampGeometry, stampsOnFrames } from "./deck.mjs"; import { mix, rgba } from "./chrome-deck.mjs"; import { drawnStamps, resolveFactcheck, STAMP_MOTION } from "./factcheck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ const INSTANT = 0.001; @@ -102,7 +103,7 @@ export function stampCues(schedule, render = null) { freeAt.set(e.k, at + dur); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } - return { init, cues }; + return { init, cues: settleFirstFrame(init, cues, fps) }; } /** diff --git a/umtool/report-to-video/chrome-stats.mjs b/umtool/report-to-video/chrome-stats.mjs @@ -18,6 +18,7 @@ import { pageDuration, statsGeometry } from "./deck.mjs"; import { rgba } from "./chrome-deck.mjs"; import { STATS_LABELS, STATS_MOTION } from "./stats.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ const INSTANT = 0.001; @@ -112,7 +113,7 @@ export function statsCues(schedule) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease }); } - return { init, cues }; + return { init, cues: settleFirstFrame(init, cues, schedule.fps) }; } /** diff --git a/umtool/report-to-video/chrome-teaser.mjs b/umtool/report-to-video/chrome-teaser.mjs @@ -31,6 +31,7 @@ import { export { TEASER_MOTION }; import { mix, rgba } from "./chrome-deck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** * The display face: Archivo, a variable font (wght 100–900, wdth 62–125), @@ -222,7 +223,7 @@ export function teaserCues({ lines, tail = "", seconds, motion = TEASER_MOTION, } // `need` is the validator's; the page's data is what it always was. const { T: _T, need: _need, ...times } = beats; - return { init, cues, beats: times, scale: beats.scale }; + return { init, cues: settleFirstFrame(init, cues), beats: times, scale: beats.scale }; } /** Each role's type: size (px, the most it may be), weight, width (%), tracking (em), and the fit floor. */ diff --git a/umtool/report-to-video/cue-start.mjs b/umtool/report-to-video/cue-start.mjs @@ -0,0 +1,66 @@ +// THE CUT'S FIRST FRAME (the frame-zero fix, 11 Nov): a cue that takes effect +// at the cut's first instant belongs in a page's init, not in its cue list. +// +// Every cue page sets its init, then builds a paused timeline of fromTo tweens +// (`immediateRender: false`) and is seeked frame by frame. The renderer's first +// frame is a seek to 0 -- no change to GSAP, and a tween placed at 0 shows its +// FROM there anyway -- so a cue at 0 shorter than a frame is drawn on frame 1, +// never on frame 0. That is how the instruments' column (dial, odometer, trail: +// chrome-instruments.mjs withDeck) showed for one frame over a cut that opens on +// the intro: their root is up in init and hidden by an instant cue at 0. +// +// LEAF: no imports, so every cue compiler can call it -- and SELF-CONTAINED +// (no module constant): the posts' page embeds postsCues, and this with it, in +// the browser (chrome-posts.mjs embedFn). + +/** + * Fold every cue that has finished before frame 1 and starts at the cut's + * first instant (at or before 0, or where an earlier folded cue on the same + * element ended) into init. A cue a frame or longer, or one after a cue on + * its element that stays, is left alone: frame 0 then shows its FROM, which is + * init, as it should. + * + * `init` is changed IN PLACE (an entry replaced, never mutated -- entries may + * be shared) because several callers read their own init after compiling; the + * cue list is returned without the folded cues. + * + * @template {{ k: string, at: number, dur: number, to: object }} C + * @param {Record<string, object>} init + * @param {C[]} cues in time order per element (every compiler's output) + * @param {number} [fps] + * @returns {C[]} + */ +export function settleFirstFrame(init, cues, fps = 30) { + // At or before this, a time is the cut's first instant. + const START_EPS = 1e-4; + const frame = 1 / (Number(fps) > 0 ? Number(fps) : 30); + /** element -> where its folded cues end; absent once a cue on it stays. */ + const foldEnd = new Map(); + const kept = new Set(); + const out = []; + for (const c of cues) { + const start = foldEnd.has(c.k) ? foldEnd.get(c.k) : 0; + const foldable = !kept.has(c.k) && Number(c.at) <= start + START_EPS && Number(c.at) + Number(c.dur) < frame - START_EPS; + if (!foldable) { + kept.add(c.k); + out.push(c); + continue; + } + init[c.k] = { ...(init[c.k] ?? {}), ...c.to }; + foldEnd.set(c.k, Number(c.at) + Number(c.dur)); + } + return out; +} + +/** + * The cues a renderer's frame 0 cannot show: a change at the cut's first + * instant, over before frame 1. Empty for a page settleFirstFrame has seen. + * + * @param {{ init?: object, cues?: Array<{ k: string, at: number, dur: number, from?: object, to: object }> }} data + */ +export function unseenFirstFrameCues(data, fps = 30) { + const init = structuredClone(data.init ?? {}); + const cues = (data.cues ?? []).filter((c) => JSON.stringify(c.from ?? null) !== JSON.stringify(c.to)); + const settled = settleFirstFrame(init, cues, fps); + return cues.filter((c) => !settled.includes(c)); +} diff --git a/umtool/report-to-video/fixtures/measure-remembered/measure.json b/umtool/report-to-video/fixtures/measure-remembered/measure.json @@ -0,0 +1,249 @@ +{ + "_fixture": "rev9-a7's moment for the dial's remembered-weight looks (11 Nov): 342.9 stated (21 Mar 2013), LOSE 75 in force, ≈390 remembered as of 24 Feb 2023 -- his heaviest (totals.peakDrift) -- and a 368 as of 2008 that is not.", + "version": 1, + "unit": "lb", + "scale": { + "min": 220, + "max": 400 + }, + "asOfRender": "2026-11-11", + "scopes": [ + "weight" + ], + "events": [ + { + "t": 1, + "row": "w1", + "scope": "weight", + "kind": "stated", + "value": 342.9, + "qualifier": null, + "date": "2013-03-21", + "asOf": null, + "display": "342.9 lb" + }, + { + "t": 1.5, + "row": "g1", + "scope": "weight", + "kind": "goalLoss", + "value": -75, + "qualifier": null, + "date": "2023-07-26", + "asOf": null, + "display": "lose 75", + "deadline": null, + "due": null + }, + { + "t": 3, + "row": "w21", + "scope": "weight", + "kind": "remembered", + "value": 390, + "qualifier": "≈", + "date": "2023-09-29", + "asOf": "2023-02-24", + "display": "≈390 lb" + }, + { + "t": 8, + "row": "w35", + "scope": "weight", + "kind": "remembered", + "value": 368, + "qualifier": null, + "date": "2024-01-10", + "asOf": "2008-06-30", + "display": "368 lb" + } + ], + "hidden": [], + "state": [ + { + "t": 0, + "current": null, + "remembered": [], + "goal": null, + "goals": [], + "lost": { + "total": 0, + "runs": [] + }, + "net": null + }, + { + "t": 1, + "current": { + "value": 342.9, + "qualifier": null, + "row": "w1", + "date": "2013-03-21" + }, + "remembered": [], + "goal": null, + "goals": [], + "lost": { + "total": 0, + "runs": [] + }, + "net": null + }, + { + "t": 1.5, + "current": { + "value": 342.9, + "qualifier": null, + "row": "w1", + "date": "2013-03-21" + }, + "remembered": [], + "goal": { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + }, + "goals": [ + { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + } + ], + "lost": { + "total": 0, + "runs": [] + }, + "net": null + }, + { + "t": 3, + "current": { + "value": 342.9, + "qualifier": null, + "row": "w1", + "date": "2013-03-21" + }, + "remembered": [ + { + "value": 390, + "asOf": "2023-02-24", + "row": "w21" + } + ], + "goal": { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + }, + "goals": [ + { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + } + ], + "lost": { + "total": 0, + "runs": [] + }, + "net": null + }, + { + "t": 8, + "current": { + "value": 342.9, + "qualifier": null, + "row": "w1", + "date": "2013-03-21" + }, + "remembered": [ + { + "value": 390, + "asOf": "2023-02-24", + "row": "w21" + }, + { + "value": 368, + "asOf": "2008-06-30", + "row": "w35" + } + ], + "goal": { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + }, + "goals": [ + { + "value": 267.9, + "loss": 75, + "deadline": null, + "due": null, + "row": "g1", + "display": "lose 75", + "base": { + "value": 342.9, + "row": "w1", + "from": "stated" + } + } + ], + "lost": { + "total": 0, + "runs": [] + }, + "net": null + } + ], + "totals": { + "lost": 0, + "peakDrift": [ + 390 + ], + "under300": { + "said": 0, + "rows": [] + } + } +} +\ No newline at end of file diff --git a/umtool/report-to-video/frame-zero.test.mjs b/umtool/report-to-video/frame-zero.test.mjs @@ -0,0 +1,88 @@ +// THE CUT'S FIRST FRAME (cue-start.mjs): a page a renderer seeks to 0 draws its +// init there, so whatever the cut is at its first instant must be IN init. The +// instruments' column (dial, odometer, trail) was up in init and hidden by an +// instant cue at 0: over a cut that opens on the intro, frame 0 showed the +// gauge, the counter and the chart strip before the wordmark (rev9-a6/a7, 11 Nov). +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 { estimateSchedule } from "./deck.mjs"; +import { dialHtml, odometerHtml, trailHtml } from "./chrome-instruments.mjs"; +import { settleFirstFrame, unseenFirstFrameCues } from "./cue-start.mjs"; +import { cueList } from "./measure-draw.mjs"; +import { compileCues } from "./chrome-cues.mjs"; +import { statsCues } from "./chrome-stats.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const MEASURE = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-dial", "measure.json"), "utf8")); +const FPS = 30; +const RENDER = { + width: 1920, height: 1080, fps: FPS, transition: 0.4, + palette: { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }, + chrome: { engine: "hyperframes", layout: "deck", deck: { dial: true, odometer: true, trail: true, qr: { show: false }, finale: { video: "side", totals: false } } }, +}; +const fonts = { DeckSans: "assets/DeckSans.ttf", DeckSansBold: "assets/DeckSansBold.ttf" }; + +/** The instruments' fixture cut, opening on the intro (selectVariant's entry: the deck hides over it). */ +function introCut() { + const timeline = Array.from({ length: 9 }, (_, i) => ({ + type: "clip", id: `c${i + 1}`, video: "vidx", start: 10 * i, end: 10 * i + (i === 8 ? 14 : 8), cite: 1, section: 0, + quote: "q", onscreen: { title: `Clip ${i + 1}` }, ...(i === 8 ? { layout: "finale" } : {}), + })); + timeline.unshift({ type: "intro", id: "brand-intro", style: "boot-dark", seconds: 4.75, heading: "Intro" }); + const manifest = { slug: "m", title: "M", provenance: {}, render: RENDER, timeline }; + const schedule = { ...estimateSchedule(manifest), measure: MEASURE }; + assert.equal(schedule.segments[0].hideDeck, true, "the intro hides the deck"); + return schedule; +} + +const dataOf = (html, id) => JSON.parse(new RegExp(`<script id="${id}-data" type="application/json">(.*?)</script>`, "s").exec(html)[1]); + +test("over an intro the instruments are hidden from frame 0: their root is down in init, with no instant cue at 0", () => { + const schedule = introCut(); + for (const [id, html] of [["dial", dialHtml(schedule, RENDER, { fonts })], ["odometer", odometerHtml(schedule, RENDER, { fonts })], ["trail", trailHtml(schedule, RENDER, { fonts })]]) { + const data = dataOf(html, id); + assert.deepEqual(data.init.rt, { autoAlpha: 0 }, `${id}: hidden at the cut's first instant`); + assert.deepEqual(unseenFirstFrameCues(data, FPS), [], `${id}: no change at 0 that frame 0 cannot show`); + // And up again with the deck, after the intro: the first cue on the root shows it. + const first = data.cues.find((c) => c.k === "rt"); + assert.ok(first.at > 4, `${id}: the column comes up after the intro (${first.at})`); + assert.deepEqual(first.to, { autoAlpha: 1 }); + } +}); + +test("settleFirstFrame folds what happens at the first instant into init, and leaves every real move alone", () => { + const init = { a: { autoAlpha: 1 }, b: { opacity: 0 }, c: { x: 0 } }; + const shared = init.a; + const cues = [ + { k: "a", at: 0, dur: 0.001, from: { autoAlpha: 1 }, to: { autoAlpha: 0 } }, + { k: "a", at: 0.001, dur: 0.001, from: { autoAlpha: 0 }, to: { autoAlpha: 0.5 } }, // chained after the first, still before frame 1 + { k: "b", at: 0, dur: 0.4, from: { opacity: 0 }, to: { opacity: 1 } }, // a fade from 0: frame 0 is its from + { k: "b", at: 0.4, dur: 0.001, from: { opacity: 1 }, to: { opacity: 0 } }, + { k: "c", at: 0.5, dur: 0.001, from: { x: 0 }, to: { x: 5 } }, + ]; + const out = settleFirstFrame(init, cues, 30); + assert.deepEqual(init.a, { autoAlpha: 0.5 }); + assert.deepEqual(shared, { autoAlpha: 1 }, "an init entry is replaced, never mutated (entries may be shared)"); + assert.deepEqual(out.map((c) => `${c.k}@${c.at}`), ["b@0", "b@0.4", "c@0.5"]); +}); + +test("every cue compiler settles the first frame: cueList, compileCues, the stats panel", () => { + const L = cueList(FPS); + L.set("rt", { autoAlpha: 1 }); + L.add("rt", 0, 0, { autoAlpha: 0 }); + L.add("rt", 5, 0.45, { autoAlpha: 1 }); + const built = L.build(); + assert.deepEqual(built.init.rt, { autoAlpha: 0 }); + assert.deepEqual(built.cues.map((c) => c.at), [5]); + const cc = compileCues({ x: { autoAlpha: 0 } }, [{ k: "x", at: 0, dur: 0, to: { autoAlpha: 1 }, ease: "none" }]); + assert.deepEqual(cc.init.x, { autoAlpha: 1 }); + assert.equal(cc.cues.length, 0); + // A stat card shown from the cut's first instant (v7gkv5w-poker-2's s0_0): up on frame 0, not frame 1. + const st = statsCues({ fps: FPS, stats: { clips: [{ in: 0, out: 6, states: [{ at: 0 }, { at: 3 }] }] } }); + assert.deepEqual(unseenFirstFrameCues(st, FPS), []); + assert.equal(st.init.s0_0.autoAlpha, 1); +}); diff --git a/umtool/report-to-video/fx.mjs b/umtool/report-to-video/fx.mjs @@ -38,6 +38,7 @@ import { COMPOSITION_PARAMS } from "yt-dlp-transcript-common/lib/report/fxParams.mjs"; import { offsetIn, sourceAtOffset } from "./gaps.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** Each effect's key under `render.chrome.fx`, in the order the page stacks them (later on top). */ export const FX_KEYS = Object.freeze(["scrubber", "receipts", "zoom", "kineticQuote", "redact", "odometer", "punchIn", "thenNow", "whip", "glitch"]); @@ -1053,7 +1054,7 @@ export function compileCues(init, events) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease }); } - return cues; + return settleFirstFrame(init, cues); } /** An object's numbers with -0 as 0: the cue list is data, and JSON has no -0. */ diff --git a/umtool/report-to-video/instruments.mjs b/umtool/report-to-video/instruments.mjs @@ -66,12 +66,19 @@ export const DIAL_DEFAULTS = Object.freeze({ // "auto" (the default): "promise" when a promise is on camera, else "odometer" -- // the contract's finale: the dial drops, the odometer rolls, NET holds, THEN the promise clock. finaleEnd: "auto", + // A remembered weight (11 Nov variants): "needle" -- the long grey second needle and its as-of words, as it was -- + // "rim" (a bold rim marker and a flag), "readout" (a line under the date, a rim marker), "callout" (a ghost needle + // sweeps to it with a label held ~2 s, then the rim's flag). chrome-instruments.mjs dialParts. + rememberedAs: "needle", + // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. + flash: null, }); export const DIAL_PLACEMENTS = Object.freeze(["column", "corner"]); export const DIAL_CORNERS = Object.freeze(["bottom-right", "bottom-left", "top-right", "top-left"]); export const DIAL_MOTIONS = Object.freeze(["spring", "ease"]); export const DIAL_FINALE_ENDS = Object.freeze(["auto", "odometer", "promise"]); +export const DIAL_REMEMBERED = Object.freeze(["needle", "rim", "readout", "callout"]); /** A corner dial's size bounds, px at 1920 wide. */ export const DIAL_SIZE = Object.freeze([200, 540]); @@ -81,6 +88,8 @@ export const ODOMETER_DEFAULTS = Object.freeze({ net: true, // "ACROSS 8 RUNS" under the wheels. runs: true, + // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. + flash: null, }); export const TRAIL_DEFAULTS = Object.freeze({ @@ -89,6 +98,15 @@ export const TRAIL_DEFAULTS = Object.freeze({ // How many times he says he is under 300 (the measure's `totals.under300` rows), as they land. count: true, label: "WHAT HE SAYS HE WEIGHS, BY DATE", + // The axes: "fit" what is shown so far, reflowing as each weight lands; "fixed" to every point of the cut. + bounds: "fit", + // His remembered weights ("≈390, as of Feb 2023") as points too: hollow and grey, never joined into the line. + remembered: true, + // A stretch with no statement longer than this many days is a break in the time axis, not a line across it: + // "auto" (a year, or 8× the median spacing if that is longer), a number of days (30–3650), or 0 for none. + gap: "auto", + // The update flash (update-flash.mjs): null follows render.chrome.deck.measure.flash; true/false for this one. + flash: null, }); /** A label's characters at most. */ @@ -171,10 +189,12 @@ export function validateDial(v, where = "render.chrome.deck.dial") { oneOf("placement", DIAL_PLACEMENTS); oneOf("motion", DIAL_MOTIONS); oneOf("finaleEnd", DIAL_FINALE_ENDS); + oneOf("rememberedAs", DIAL_REMEMBERED); oneOf("corner", DIAL_CORNERS); if (obj.size !== undefined && !(Number.isInteger(obj.size) && numIn(obj.size, DIAL_SIZE[0], DIAL_SIZE[1]))) { errors.push(`${where}.size must be a whole number of pixels from ${DIAL_SIZE[0]} to ${DIAL_SIZE[1]}`); } + if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; } @@ -184,6 +204,7 @@ export function validateOdometer(v, where = "render.chrome.deck.odometer") { if (!obj) return errors; for (const k of ["net", "runs"]) if (obj[k] !== undefined) { const p = boolProblem(obj[k], `${where}.${k}`); if (p) errors.push(p); } if (obj.label !== undefined) { const p = labelProblem(obj.label, `${where}.label`); if (p) errors.push(p); } + if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; } @@ -194,5 +215,9 @@ export function validateTrail(v, where = "render.chrome.deck.trail") { if (obj.mark !== undefined) { const p = markProblem(obj.mark, `${where}.mark`); if (p) errors.push(p); } if (obj.count !== undefined) { const p = boolProblem(obj.count, `${where}.count`); if (p) errors.push(p); } if (obj.label !== undefined) { const p = labelProblem(obj.label, `${where}.label`); if (p) errors.push(p); } + if (obj.remembered !== undefined) { const p = boolProblem(obj.remembered, `${where}.remembered`); if (p) errors.push(p); } + if (obj.bounds !== undefined && !["fit", "fixed"].includes(obj.bounds)) errors.push(`${where}.bounds must be "fit" or "fixed"`); + if (obj.gap !== undefined && !(obj.gap === "auto" || obj.gap === 0 || numIn(obj.gap, 30, 3650))) errors.push(`${where}.gap must be "auto", 0 (no breaks) or 30 to 3650 days`); + if (obj.flash !== undefined && obj.flash !== null) { const p = boolProblem(obj.flash, `${where}.flash`); if (p) errors.push(p); } return errors; } diff --git a/umtool/report-to-video/instruments.test.mjs b/umtool/report-to-video/instruments.test.mjs @@ -112,14 +112,14 @@ test("the instruments' settings: true, an object of known keys, or off; the side const side = validateChrome({ ...chromeWith({ trail: true }), threads: { list: [{ id: "a", label: "A" }] } }, {}); assert.ok(side.some((e) => /render\.chrome\.threads and render\.chrome\.deck\.trail both need the frame/.test(e)), side.join("\n")); assert.deepEqual(resolveDial(RENDER), { - mark: 300, ghosts: true, goal: true, needle: "#ff5a4e", finale: true, label: "HE SAYS HE WEIGHS", placement: "column", size: 340, corner: "bottom-right", motion: "spring", finaleEnd: "auto", + mark: 300, ghosts: true, goal: true, needle: "#ff5a4e", finale: true, label: "HE SAYS HE WEIGHS", placement: "column", size: 340, corner: "bottom-right", motion: "spring", finaleEnd: "auto", rememberedAs: "needle", flash: null, }); assert.match(validateDial({ placement: "left" })[0], /placement must be "column" or "corner"/); assert.match(validateDial({ size: 100 })[0], /size must be a whole number of pixels from 200 to 540/); assert.match(validateDial({ motion: "bounce" })[0], /motion must be "spring" or "ease"/); assert.match(validateDial({ finaleEnd: "net" })[0], /finaleEnd must be "auto" or "odometer" or "promise"/); assert.equal(resolveDial({ chrome: chromeWith({ dial: false }) }), null); - assert.deepEqual(moduleProblems({ render: { ...RENDER, chrome: chromeWith({ dial: { ghost: true } }) } }).dial, ["render.chrome.deck.dial.ghost is not a setting of it (mark, ghosts, goal, needle, finale, label, placement, size, corner, motion, finaleEnd)"]); + assert.deepEqual(moduleProblems({ render: { ...RENDER, chrome: chromeWith({ dial: { ghost: true } }) } }).dial, ["render.chrome.deck.dial.ghost is not a setting of it (mark, ghosts, goal, needle, finale, label, placement, size, corner, motion, finaleEnd, rememberedAs, flash)"]); }); // --------------------------------------------------------------------------- diff --git a/umtool/report-to-video/measure-draw.mjs b/umtool/report-to-video/measure-draw.mjs @@ -16,6 +16,7 @@ // // Pure: strings in, strings out. No fs. import { cueTime, pageDuration } from "./deck.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; /** Instant cues still take a millisecond: a zero-duration tween has its own seek rules. */ export const INSTANT = 0.001; @@ -71,7 +72,7 @@ export function cueList(fps) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease }); } - return { init, cues }; + return { init, cues: settleFirstFrame(init, cues, fps) }; }, }; } diff --git a/umtool/report-to-video/measure-extras.mjs b/umtool/report-to-video/measure-extras.mjs @@ -216,6 +216,18 @@ export function goalText(e, unit = "lb") { } /** + * A goal's base as its note writes it -- "(FROM 346.7)", "(FROM ≈390)" -- from the + * slice's `goal.base` ({ value, row }), the qualifier its row carries; null + * when there is none. + */ +export function goalBaseText(base, m) { + if (!base || !Number.isFinite(base.value)) return null; + const row = [...(m?.events ?? []), ...(m?.hidden ?? [])].find((e) => e.row === base.row); + const q = typeof row?.qualifier === "string" && /^[≈<>]$/.test(row.qualifier) ? row.qualifier : ""; + return `(FROM ${q}${weightText(base.value)})`; +} + +/** * The pile's states: one per goal event, `{ at, top, goalsSet, notes }` -- * `notes` back to front (the last is the one that just landed, `top` its key), * each `{ key, text, count, date, deadline, deadlineDate, days, target, rot, @@ -255,6 +267,10 @@ export function goalStates(schedule, render) { const target = s?.goal && s.goal.row === e.row && Number.isFinite(s.goal.value) ? s.goal.value : e.kind === "goal" && Number.isFinite(e.value) ? e.value : null; note.target = target; + // The weight he had stated when he set it (`goals.base`): the slice's own base for this goal -- the weight the + // gauge's target is reckoned from (measure-slice.mjs goalBase: the run's start, else the latest weight he gave by + // the goal's date) -- with its row's qualifier. None resolved, none shown: never one made up here. + note.base = cfg.base && s?.goal?.row === e.row ? goalBaseText(s.goal.base, m) : null; order = [...order.filter((k) => k !== key), key]; const shown = order.slice(-cfg.max); const depth = new Map(shown.map((k, i) => [k, shown.length - 1 - i])); @@ -267,7 +283,7 @@ export function goalStates(schedule, render) { const x = notes.get(k); return { key: k, id: x.id, text: x.text, count: x.count, date: x.date, deadline: x.deadline, - deadlineDate: x.deadlineDate, days: x.days, target: x.target, rot: x.rot, dx: x.dx, + deadlineDate: x.deadlineDate, days: x.days, target: x.target, base: x.base ?? null, rot: x.rot, dx: x.dx, depth: depth.get(k), prev: k === key ? null : prevDepth.get(k) ?? null, }; }), diff --git a/umtool/report-to-video/measure-slice.mjs b/umtool/report-to-video/measure-slice.mjs @@ -33,7 +33,7 @@ export const MEASURE_SLICE_VERSION = 1; export { PROMISE_FORMS }; /** `render.chrome.deck.measure`'s keys. */ -export const MEASURE_SETTINGS_KEYS = Object.freeze(["scopes", "scale", "asOf", "ghosts"]); +export const MEASURE_SETTINGS_KEYS = Object.freeze(["scopes", "scale", "asOf", "ghosts", "flash"]); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const isIso = (v) => typeof v === "string" && /^\d{4}-\d{2}-\d{2}$/.test(v) && !Number.isNaN(Date.parse(`${v}T00:00:00Z`)); @@ -66,6 +66,8 @@ export function validateMeasureSettings(v, where = "render.chrome.deck.measure") else for (const k of Object.keys(s)) if (k !== "min" && k !== "max") errors.push(`${where}.scale.${k} is not a scale setting (min, max)`); } if (v.asOf !== undefined && !isIso(v.asOf)) errors.push(`${where}.asOf must be a date (YYYY-MM-DD)`); + // The update flash (update-flash.mjs): every measure widget's outline lights as its value changes. + if (v.flash !== undefined && typeof v.flash !== "boolean") errors.push(`${where}.flash must be true or false`); errors.push(...validateGhosts(v.ghosts, `${where}.ghosts`)); return errors; } diff --git a/umtool/report-to-video/measure-slice.test.mjs b/umtool/report-to-video/measure-slice.test.mjs @@ -198,7 +198,7 @@ test("the settings: their shape, their scopes against the ledger, and when a cut assert.deepEqual(validateMeasureSettings(undefined), []); assert.deepEqual(validateMeasureSettings({ scopes: ["weight"], scale: { min: 220, max: 400 }, asOf: "2026-11-05" }), []); assert.deepEqual(validateMeasureSettings({ scopes: [], scale: { min: 4, max: 2 }, asOf: "Nov 5", x: 1 }), [ - "render.chrome.deck.measure.x is not a measure setting (scopes, scale, asOf, ghosts)", + "render.chrome.deck.measure.x is not a measure setting (scopes, scale, asOf, ghosts, flash)", "render.chrome.deck.measure.scopes must be a list of the ledger's track keys (at least one)", "render.chrome.deck.measure.scale.min must be below scale.max", "render.chrome.deck.measure.asOf must be a date (YYYY-MM-DD)", diff --git a/umtool/report-to-video/modules/dial.mjs b/umtool/report-to-video/modules/dial.mjs @@ -43,6 +43,8 @@ export default defineModule({ { key: "corner", type: "enum", options: ["bottom-right", "bottom-left", "top-right", "top-left"], label: "The corner", default: "bottom-right" }, { key: "motion", type: "enum", options: ["spring", "ease"], label: "The needle's move", default: "spring" }, { key: "finaleEnd", type: "enum", options: ["auto", "odometer", "promise"], label: "The finale's last beat", default: "auto" }, + { key: "rememberedAs", type: "enum", options: ["needle", "rim", "readout", "callout"], label: "A remembered weight drawn as", default: "needle" }, + { key: "flash", type: "boolean", label: "Flash its outline when its value changes (unset: deck.measure.flash)" }, ], docs: { heading: "Scale dial", @@ -52,6 +54,8 @@ export default defineModule({ ["`deck.dial.mark`", "a weight, or `null` · default `300` (its tick and label in the accent)", "`umtool look <p> deck.dial.mark=300`"], ["`deck.dial.ghosts`, `.goal`", "bool · default `true` each (`.goal`: every goal in force, the closest headlined)", "`umtool look <p> deck.dial.ghosts=false`"], ["`deck.measure.ghosts`", "`true` · `{opacity, tolerance, ramp, pulse}` · `false` / absent: off (the default). CLAIM GHOSTS (measure-ghosts.mjs), not `deck.dial.ghosts`: every weight he has claimed so far -- each stated weight the needle goes to and each remembered one, his own, in cut order -- leaves a thin faint tick across the dial's rim at its value, under everything else on the face; a value claimed again (within `tolerance` lb of the tick's first value; an `≈` value as its rounded number; `>300` and `<300` at 300) steps that tick along the `ramp` -- 1× faint, 2× warm, 3× and up hot, a little thicker each step -- and it pulses once as the repeat lands (`pulse`). In the finale every tick stays at its count at the cut's end. Seek-safe: a frame at t draws the claims before t", "`umtool look <p> deck.measure.ghosts=true`"], + ["`deck.dial.rememberedAs`", "`needle` · `rim` · `readout` · `callout` · default `needle` (as it was: a long grey second needle from the hub to the value, its words -- \"≈390 / AS OF 24 FEB 2023\" -- along it). `rim`: no long needle; a bold marker across the rim at the value and a flag inside it -- \"HEAVIEST ≈390 / AS OF FEB 2023 · HE SAYS\" -- placed clear of the scale's figures, the hub and the readout. `readout`: a line in the readout under the date -- \"HEAVIEST HE'S SAID: ≈390 (FEB 2023)\", the goal under it -- and the rim marker. `callout`: as he says it a ghost needle sweeps from where the needle stands to the value and a label (\"HEAVIEST HE'S SAID / ≈390 / AS OF FEB 2023\") holds 2.2 s, then the rim's flag. The words are the ledger's: its qualifier, its asOf's month; HEAVIEST only for the record's highest remembered weight above every weight he stated (the peak extra's `totals.peakDrift`), else \"HE SAYS HE WAS\". Each is up while it is the latest remembered; the thin rim ticks of every remembered weight stay as they are", "`umtool look <p> deck.dial.rememberedAs=rim`"], + ["`deck.measure.flash`", "bool · default `false` (off: every cut renders as before) -- THE UPDATE FLASH for every measure widget at once (update-flash.mjs): at the moment a widget's shown value changes its outline lights in its own colour and decays (0.15 s up, 0.7 s down) -- the dial on a weight stated or remembered or a goal change, the odometer on the pounds lost or NET, the trail on each weight landing, the goal stack on a goal set, the diet tags on a new diet; widgets that change on one event flash together; never on frame 0, while the deck is away (the intro, a card) or on a widget's first appearance. A widget's own `flash` overrides it", "`umtool look <p> deck.measure.flash=true`"], ["`deck.measure.ghosts.opacity`, `.tolerance`", "0.15–0.9 (the 1× tick's; +0.2 a step, at most 0.95) · 0–5 lb · default `0.5`, `0.5`", "`umtool look <p> deck.measure.ghosts='{\"tolerance\":1}'`"], ["`deck.measure.ghosts.ramp`, `.pulse`", "2–4 #hex, 1× first (the last for every count from there up), or `null`: the palette's muted, amber, and amber half way to the needle's red · bool · default `null`, `true`", "`umtool look <p> deck.measure.ghosts='{\"ramp\":[\"#98a29b\",\"#e8a33f\",\"#f37e47\"],\"pulse\":false}'`"], ["`deck.dial.needle`", "a #hex · default `#ff5a4e`", "`umtool look <p> deck.dial.needle='\"#ff5a4e\"'`"], @@ -62,6 +66,7 @@ export default defineModule({ ["`deck.dial.corner`", "`bottom-right` `bottom-left` `top-right` `top-left` · default `bottom-right` (the corner only): the dial in that corner, the odometer and the trail up the same side. The measure extras stand at their own anchors in the footage (goals bottom-right, peak top-right, promise top-centre, diet bottom-left, streak bottom-centre): a corner instrument over one that is on is REFUSED by the build, naming it -- move one (`deck.goals.position`, …) or the corner; `top-left` is clear of all five", "`umtool look <p> deck.dial.corner=top-left`"], ["`deck.dial.motion`", "`spring` `ease` · default `spring`. A VARIANT: the needle's `back.out` overshoot and settle, or a plain `power2.inOut` (the finale's drop too)", "`umtool look <p> deck.dial.motion=ease`"], ["`deck.dial.finaleEnd`", "`auto` `odometer` `promise` · default `auto` (`promise` when a promise is on camera, else `odometer`): `promise` hands the finale's last beat to the promise clock (module `promise`) -- the instruments fade out once NET has held (`dialFinaleHandoff`) and the clock takes their place in the finale's lower column, clear of the rail; with no promise module on the cut it ends on the odometer", "`umtool look <p> deck.dial.finaleEnd=promise`"], + ["`deck.dial.flash`", "bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the bezel lights as a weight is stated or remembered, or the goal in force changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away", "`umtool look <p> deck.dial.flash=false`"], ], }, region: "dial", diff --git a/umtool/report-to-video/modules/diet.mjs b/umtool/report-to-video/modules/diet.mjs @@ -25,6 +25,7 @@ export default measureExtraModule({ { key: "tags", type: "number", min: DIET_TAGS[0], max: DIET_TAGS[1], step: 1, label: "Tags in the row", default: 3, when: { form: "tags" } }, { key: "overlap", type: "number", min: DIET_OVERLAP[0], max: DIET_OVERLAP[1], step: 0.05, label: "Overlap (0: side by side; the share of each older tag behind the one in front)", default: 0, when: { form: "tags" } }, { key: "days", type: "boolean", label: "Days on the diet, on the front tag", default: false, when: { form: "tags" } }, + { key: "flash", type: "boolean", label: "Flash its outline when its value changes (unset: deck.measure.flash)" }, ], docs: { intro: "The diet he names as a rubber stamp in a corner of the footage box (`render.chrome.deck.diet`, measure-extras.mjs): at each change of the state's diet -- its regime or its diet number -- a new stamp slams on (in big and turned, onto the page, a shake), the regime's word in its ink and \"DIET #n\" under it with the ledger's words when they say more (\"Keto · 5 carbs a day\"); a change of words alone fades the new stamp in. A null diet after one fades to \"NO DIET\" in grey. It draws `state.diet` as the measure slice gives it -- the off-scope rule (\"off GLP-1\" while on keto is still keto) is the ledger's. The inks default to the quartering-diet regimes' (keto #E0913C, carnivore #C9534B, fasting #4E9BD8, calories #3FA9A0, glp1 #B168C6, other #8E97A8, off #98A29B).", @@ -36,6 +37,7 @@ export default measureExtraModule({ ["`deck.diet.overlap`", `${DIET_OVERLAP[0]}–${DIET_OVERLAP[1]}, the share of each older tag hidden behind the one in front · default 0 (side by side, the slam and the dim). Above 0 the tags FAN sideways the way the goal stack's notes pile: the newest in front at the left, landing from above like a goal note, each older one a place to the right behind it with its own small turn, keeping its colours (the depth is the overlap and the shadow), showing its regime word and date in the strip beside the one in front; the one past \`tags\` slides off the back. The fan is narrower by what hides. An older tag's word and date need ${DIET_BACK_MIN} design px of it, so it is refused past ${dietOverlapMax(false)} (${dietOverlapMax(true)} with \`days\`)`, "`umtool look <p> deck.diet.overlap=0.5`"], ["`deck.diet.days`", "`true` · `false`: the front tag's running count of days on its diet (to the in-record date at the playhead, the streak chain's \"Day N\"), in a column of its own -- the tag 300 design px wide · default `false`", "`umtool look <p> deck.diet.days=true`"], ["`deck.diet.colors`, `.labels`", "`{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names", "`umtool look <p> deck.diet.labels='{\"glp1\":\"Ozempic\"}'`"], + ["`deck.diet.flash`", "bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): with `form: \"tags\"`: the new front tag lights, in its ink, at a new diet or new words for it -- never the running day count, never the first tag; the stamp form does not flash; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away", "`umtool look <p> deck.diet.flash=false`"], ], }, }); diff --git a/umtool/report-to-video/modules/goals.mjs b/umtool/report-to-video/modules/goals.mjs @@ -22,15 +22,19 @@ export default measureExtraModule({ { key: "max", type: "number", min: MEASURE_LIMITS.max[0], max: MEASURE_LIMITS.max[1], label: "Notes shown", default: 4 }, { key: "color", type: "color", label: "Paper (default the palette's amber)" }, { key: "countdown", type: "boolean", label: "Count a deadline down to the render date", default: true }, + { key: "base", type: "boolean", label: "Say the weight he had stated when he set it", default: false }, + { key: "flash", type: "boolean", label: "Flash its outline when its value changes (unset: deck.measure.flash)" }, ], docs: { intro: "A sticky note per goal on a pile in a corner of the footage box, read off the schedule's `measure` slice (`render.chrome.deck.goals`, measure-extras.mjs): each goal or goalLoss event drops one, turned a little, onto the pile; the same goal in the same words (\"lose 100\") merges into its note with a count (\"×8\") and comes to the front; `max` notes show, the newest in front, with the goals set so far under them. A goal with a `deadline` counts down to `measure.asOfRender` (\"by Christmas · 50 days left · needs 226.5\"): Christmas is the next 25 Dec from the day he said it, \"next year\" a year on, a named year that year; words that name no date (\"by my birthday\") keep their label and no countdown. On whenever the cut has a measure slice with a goal on camera; `false` turns it off. Up for `hold` seconds after each goal (default 20), the pile as it stands each time. The four measure extras sit at anchors of the footage box by default, clear of the instrument panel's right column and of the top-left, where the streams' face cam most often is (the diet badge bottom-left, the goal stack bottom-right, the moving start top-right, the promise clock top-centre); `position` or `x`/`y` move one.", rows: [ - ["`deck.goals`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice", "`umtool look <p> deck.goals=false`"], + ["`deck.goals`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown, base}` · default on with a measure slice", "`umtool look <p> deck.goals=false`"], ["`deck.goals.position`, `.x`/`.y`, `.scale`", "`top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1", "`umtool look <p> deck.goals.position=bottom-left`"], ["`deck.goals.position=shelf`", "its shelf form (`deck.shelf`): the count of goals set in a column, then the notes fanned sideways like the diet's tags -- ordered by the dial's goal board (measure-goals.mjs \`goalsAt(goalBoard(schedule.measure), t)\`, so the shelf and the dial always agree): its headline -- the closest goal in force -- in front with \"+N more\" for the others in force, the rest by recency; a goal the board misses struck in red, MISSED on it, for the dial's 6 s; with no goal in force, the newest in front; a new goal landing from above as on the pile; each older one showing its goal's words in the strip beside it (all of each when there is room); a repeat comes to the front with its ×n. The fan takes the shelf's spare width (shelfLayout), up to its notes side by side. On the shelf it stays up from the first goal (`hold` unset). What the dial draws of the goal stays on the dial", "`umtool look <p> deck.shelf.items='[\"diet\",\"goals\"]' deck.goals.position=shelf`"], ["`deck.goals.max`, `.color`, `.countdown`", "1–8 notes · #hex paper · bool · default 4, the palette's amber, `true`", "`umtool look <p> deck.goals.max=6`"], + ["`deck.goals.base`", "bool · default `false`: each note also says the weight he had stated when he set the goal -- \"LOSE 100 (FROM 346.7)\", its qualifier kept (\"(FROM ≈390)\") -- the slice's own base for that goal, the one the gauge reckons its target from (measure-slice.mjs `goalBase`: the start of the run open when he set it, else the latest weight he gave by the goal's date, stated or remembered). A goal with no base (no weight by then, a target goal such as \"250 LB\", a base the scale's foot refuses) shows none -- never one made up. On a back card it is a line of its own, right-aligned like the label", "`umtool look <p> deck.goals.base=true`"], ["`deck.goals.hold`, `.finale`", "0 (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide`", "`umtool look <p> deck.goals.hold=0`"], + ["`deck.goals.flash`", "bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the note that lands lights as a goal is set -- not the first note (the stack coming up), not the board's own changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away", "`umtool look <p> deck.goals.flash=false`"], ], }, }); diff --git a/umtool/report-to-video/modules/measure-extras-settings.mjs b/umtool/report-to-video/modules/measure-extras-settings.mjs @@ -6,10 +6,10 @@ // SETTINGS), so it imports only instruments.mjs (a leaf too: whether the // instruments' column is on decides two defaults here). // -// render.chrome.deck.goals { show, position, x, y, scale, hold, finale, max, color, countdown } +// render.chrome.deck.goals { show, position, x, y, scale, hold, finale, max, color, countdown, base, flash } // render.chrome.deck.peak { show, position, x, y, scale, hold, finale, title, color, values } // render.chrome.deck.promise { show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks, speakers, claimVerb, claimColor } -// render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels, form, tags, overlap, days } +// render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels, form, tags, overlap, days, flash } // render.chrome.deck.streak { show, position, x, y, scale, hold, finale, source, axis, title, color, colors, labels } // // Each is ON whenever the cut has a measure slice (the build writes one only @@ -122,7 +122,9 @@ export const MEASURE_DEFAULTS = Object.freeze({ // The sticky notes pile in the bottom-right corner, up for `hold` seconds // after each goal; `max` notes show, the newest in front; `color` is the // paper (default the palette's amber). - goals: Object.freeze({ ...COMMON, position: "bottom-right", hold: 20, max: 4, color: null, countdown: true }), + // `base`: each note also says the weight he had stated when he set it, "(FROM 346.7)" (the slice's goal base). + // `flash`: the update flash (update-flash.mjs) -- null follows deck.measure.flash, true/false for this module. + goals: Object.freeze({ ...COMMON, position: "bottom-right", hold: 20, max: 4, color: null, countdown: true, base: false, flash: null }), // The moving start: up for `hold` seconds after each retelling. peak: Object.freeze({ ...COMMON, position: "top-right", hold: 12, title: "The start keeps moving", color: null, values: "drift" }), // The promise clock: up from the promise on, through the finale. @@ -134,7 +136,7 @@ export const MEASURE_DEFAULTS = Object.freeze({ speakers: Object.freeze({}), claimVerb: "paid", claimColor: "#E37AB8", slot: "auto" }), // The diet badge: up from the first diet on, re-stamped at every change. // `form` "tags" (the default on the shelf): the last `tags` diets as dated tags, the newest slammed in at the left. - diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}), form: "stamp", tags: 3, overlap: 0, days: false }), + diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}), form: "stamp", tags: 3, overlap: 0, days: false, flash: null }), // The streak chain: bottom-centre, between the diet badge and the goal // stack, so either or both can run. `title` null is the source's own word. streak: Object.freeze({ ...COMMON, position: "bottom-center", source: "diet", axis: "date", title: null, color: null, colors: Object.freeze({}), labels: Object.freeze({}) }), @@ -262,6 +264,10 @@ export function validateMeasureExtra(id, v, where = `render.chrome.deck.${id}`, } color(v.color, `${where}.color`, errors); if (v.countdown !== undefined && typeof v.countdown !== "boolean") errors.push(`${where}.countdown must be true or false`); + if (v.base !== undefined && typeof v.base !== "boolean") errors.push(`${where}.base must be true or false`); + } + if (id === "goals" || id === "diet") { + if (v.flash !== undefined && v.flash !== null && typeof v.flash !== "boolean") errors.push(`${where}.flash must be true, false or null (deck.measure.flash)`); } if (id === "peak") { text(v.title, L.text, `${where}.title`, errors, { nullable: false }); diff --git a/umtool/report-to-video/modules/odometer.mjs b/umtool/report-to-video/modules/odometer.mjs @@ -31,6 +31,7 @@ export default defineModule({ { key: "label", type: "text", label: "Over the wheels", default: ODOMETER_DEFAULTS.label }, { key: "net", type: "boolean", label: "NET beside them", default: true }, { key: "runs", type: "boolean", label: "How many runs", default: true }, + { key: "flash", type: "boolean", label: "Flash its outline when its value changes (unset: deck.measure.flash)" }, ], docs: { heading: "Lost odometer", @@ -39,6 +40,7 @@ export default defineModule({ ["`deck.odometer`", "`true` · an object of the knobs below · `false` off · absent: ON when the cut draws a measure (`deck.measure` set), else off", "`umtool look <p> deck.odometer=false`"], ["`deck.odometer.label`", "words over the wheels, ≤ 40 · default `POUNDS HE SAYS HE'S LOST`", "`umtool look <p> deck.odometer.label='\"…\"'`"], ["`deck.odometer.net`, `.runs`", "bool · default `true` each", "`umtool look <p> deck.odometer.net=false`"], + ["`deck.odometer.flash`", "bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the card lights as the pounds lost go up (or the runs change) and as NET changes; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away", "`umtool look <p> deck.odometer.flash=false`"], ], }, region: "odometer", diff --git a/umtool/report-to-video/modules/promise.mjs b/umtool/report-to-video/modules/promise.mjs @@ -9,7 +9,7 @@ import path from "node:path"; import { promiseHtml } from "../chrome-measure-extras.mjs"; import { measureOf, promiseStates } from "../measure-extras.mjs"; -import { avatarEntryOf } from "../post-avatars.mjs"; +import { avatarEntryOf, handleKey } from "../post-avatars.mjs"; import { measureExtraModule } from "./measure-extras-module.mjs"; import { PROMISE_CHECKS, resolveMeasureExtra } from "./measure-extras-settings.mjs"; @@ -27,10 +27,13 @@ async function speakerOpts(ctx) { for (const s of m?.state ?? []) for (const p of s?.promises ?? []) for (const c of p?.claims ?? []) if (c?.speaker) speakers.add(c.speaker); const handles = {}; const avatars = {}; + // A speaker's settings matched as a handle is -- without @, without regard to case -- so + // `speakers.MadamSavvy` serves the measure's "madamsavvy" (post-avatars.mjs handleKey). + const spCfg = (sp) => cfg?.speakers?.[sp] ?? Object.entries(cfg?.speakers ?? {}).find(([k]) => handleKey(k) === handleKey(sp))?.[1]; for (const sp of speakers) { - const want = cfg?.speakers?.[sp]?.handle ?? sp; + const want = spCfg(sp)?.handle ?? sp; const entry = avatarEntryOf(ctx.manifest, want) ?? avatarEntryOf(ctx.manifest, sp); - handles[sp] = String(cfg?.speakers?.[sp]?.handle ?? entry?.[0] ?? sp).replace(/^@/, ""); + handles[sp] = String(spCfg(sp)?.handle ?? entry?.[0] ?? sp).replace(/^@/, ""); if (entry?.[1]?.src && ctx.manifestDir) { const src = path.resolve(ctx.manifestDir, entry[1].src); const url = await ctx.asset(src, `avatar-${sp.replace(/[^A-Za-z0-9_-]/g, "_")}${path.extname(src) || ".jpg"}`).catch(() => null); diff --git a/umtool/report-to-video/modules/rail.test.mjs b/umtool/report-to-video/modules/rail.test.mjs @@ -28,10 +28,13 @@ test("the deck at a pitch: pips after the first hidden until the marker reaches 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]); - assert.deepEqual(init.pb1, { opacity: 0 }); + // 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 === "pb1" && c.to.opacity === 1)); + 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 class="pip" data-k="pb1" style="left:85px"><\/div>/); diff --git a/umtool/report-to-video/modules/trail.mjs b/umtool/report-to-video/modules/trail.mjs @@ -30,15 +30,22 @@ export default defineModule({ { key: "mark", type: "number", min: 0, max: 2000, step: 1, label: "The line across", default: 300 }, { key: "count", type: "boolean", label: "Count the \"under 300\" claims", default: true }, { key: "label", type: "text", label: "Its title", default: TRAIL_DEFAULTS.label }, + { key: "bounds", type: "enum", options: ["fit", "fixed"], label: "Axes: fit what is shown so far, or fixed to the whole cut", default: "fit" }, + { key: "remembered", type: "boolean", label: "His remembered weights as points too (hollow, not joined)", default: true }, + { key: "flash", type: "boolean", label: "Flash its outline when its value changes (unset: deck.measure.flash)" }, ], docs: { heading: "Weight trail", - intro: "At the foot of the instruments' column: every STATED weight the cut shows, placed by the date he was weighed (its `asOf`, else its date) across the span of them, a dot appearing at its event's `t` and the line between two neighbours drawn once both are said; a red ring on the latest said. The `mark` line (300) dashed across; with `count` and the mark at 300, `UNDER 300 · SAID n×` counts the measure's `totals.under300` rows as the cut reaches each.", + intro: "At the foot of the instruments' column: every weight the cut shows -- the STATED ones and (`remembered`) the remembered ones, \"≈390, as of Feb 2023\" -- placed by the date he was that weight (its `asOf`, else its date), a dot appearing at its event's `t`; the line joins neighbours by date among the stated ones once both are said (a remembered one is a hollow grey dot, never joined; a qualified one hollow). The axes FIT what has been said so far (trail-plan.mjs): each new weight outside them reflows the chart over 0.4 s -- the years, the bounds, every dot -- so the time axis advances with the story; a stretch with no statement longer than `gap` is a break in the time axis (a narrow dashed band, `//` at its foot, each side with its own years) and the line across it dotted, so a decade of nothing does not take the width from the dense run after it. A red ring on the latest said. The `mark` line (300) dashed across; with `count` and the mark at 300, `UNDER 300 · SAID n×` counts the measure's `totals.under300` rows as the cut reaches each.", rows: [ ["`deck.trail`", "`true` · an object of the knobs below · `false` off · absent: ON when the cut draws a measure (`deck.measure` set), else off", "`umtool look <p> deck.trail=false`"], ["`deck.trail.mark`", "a weight, or `null` · default `300`", "`umtool look <p> deck.trail.mark=300`"], ["`deck.trail.count`", "bool · default `true`", "`umtool look <p> deck.trail.count=false`"], ["`deck.trail.label`", "its title, ≤ 40 · default `WHAT HE SAYS HE WEIGHS, BY DATE`", "`umtool look <p> deck.trail.label='\"…\"'`"], + ["`deck.trail.bounds`", "`fit` · `fixed` · default `fit`: the axes fit the weights said so far and reflow as each lands; `fixed` lays every moment on the axes of all the cut's weights", "`umtool look <p> deck.trail.bounds=fixed`"], + ["`deck.trail.remembered`", "bool · default `true`: his remembered weights are points too, hollow and grey, not joined into the line", "`umtool look <p> deck.trail.remembered=false`"], + ["`deck.trail.gap`", "`auto` · days 30–3650 · `0` none · default `auto`: a stretch with no statement longer than a year (or 8× the median spacing, if longer) is a break in the time axis", "`umtool look <p> deck.trail.gap=540`"], + ["`deck.trail.flash`", "bool · unset (default): follows `deck.measure.flash` -- THE UPDATE FLASH (update-flash.mjs): the card lights as each weight lands on it; a thin outline in its own colour, up over 0.15 s and gone over 0.7 s, no size change, never on frame 0 or while the deck is away", "`umtool look <p> deck.trail.flash=false`"], ], }, region: "trail", diff --git a/umtool/report-to-video/remembered-looks.test.mjs b/umtool/report-to-video/remembered-looks.test.mjs @@ -0,0 +1,82 @@ +// THE DIAL'S REMEMBERED-WEIGHT LOOKS (`deck.dial.rememberedAs`; operator, 11 Nov: "max weight statements could be +// shown better" -- the long grey second needle and its small words crossed the main needle and the readout and did +// not say what the weight was). Three looks beside today's, each worded from the ledger entry's own fields. +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 { CALLOUT_HOLD, dialHtml, heaviestOf, rememberedMode, rememberedWords } from "./chrome-instruments.mjs"; +import { estimateSchedule } from "./deck.mjs"; +import { validateDial } from "./instruments.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const MEASURE = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-remembered", "measure.json"), "utf8")); +const PALETTE = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; +const renderAs = (as) => ({ width: 1920, height: 1080, fps: 30, transition: 0.4, palette: PALETTE, + chrome: { engine: "hyperframes", layout: "deck", deck: { dial: as === undefined ? true : { rememberedAs: as }, odometer: true, trail: true } } }); +const page = (as) => { + const r = renderAs(as); + const timeline = Array.from({ length: 3 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "v", start: 0, end: 10 })); + const html = dialHtml({ ...estimateSchedule({ slug: "m", title: "M", provenance: {}, render: r, timeline }), measure: MEASURE }, r, { fonts: {} }); + return { html, data: JSON.parse(/<script id="dial-data" type="application\/json">(.*?)<\/script>/s.exec(html)[1]) }; +}; + +test("the words are the ledger's: its qualifier, its asOf's month; HEAVIEST only for the record's highest above every stated weight", () => { + assert.equal(heaviestOf(MEASURE), 390); + assert.equal(heaviestOf({ totals: {} }), null); + const top = rememberedWords({ value: 390, qualifier: "≈", asOf: "2023-02-24" }, 390); + assert.deepEqual([top.value, top.when, top.kind, top.line], ["≈390", "FEB 2023", "HEAVIEST HE'S SAID", "HEAVIEST HE'S SAID: ≈390 (FEB 2023)"]); + const other = rememberedWords({ value: 368, qualifier: null, asOf: "2008-06-30" }, 390); + assert.deepEqual([other.kind, other.line], ["HE SAYS HE WAS", "HE SAYS HE WAS: 368 (JUN 2008)"]); + // No peak drift on the record: nothing is called his heaviest. + assert.equal(rememberedWords({ value: 390, qualifier: "≈", asOf: "2023-02-24" }, null).heaviest, false); + assert.equal(rememberedWords({ value: 390, qualifier: "≈", asOf: null }, 390).line, "HEAVIEST HE'S SAID: ≈390"); +}); + +test("needle (the default) is today's dial; rim, readout and callout draw no long needle at rest and no floating as-of words", () => { + assert.equal(rememberedMode({}), "needle"); + assert.deepEqual(validateDial({ rememberedAs: "rim" }), []); + assert.match(validateDial({ rememberedAs: "flag" }).join(), /rememberedAs must be "needle" or "rim" or "readout" or "callout"/); + const today = page(undefined); + assert.deepEqual(page("needle").html, today.html, "needle is the default, byte for byte"); + assert.match(today.html, /data-k="gn"/); + assert.match(today.html, /class="asof" data-k="ga0"/); + for (const as of ["rim", "readout"]) { + const { html } = page(as); + assert.doesNotMatch(html, /data-k="gn"|class="asof"/, as); + assert.match(html, /data-k="gk0"/, `${as}: the rim marker`); + } + assert.match(page("rim").html, /class="rflag" data-k="gl0"[^>]*><span>HEAVIEST<\/span><b>≈390<\/b><span>FEB 2023<\/span>/); + assert.match(page("rim").html, /class="rflag" data-k="gl1"[^>]*><span>REMEMBERED<\/span><b>368<\/b><span>JUN 2008<\/span>/); + assert.match(page("readout").html, /class="rline" data-k="gr0"[^>]*>HEAVIEST HE'S SAID: ≈390 \(FEB 2023\)<|class="rline" data-k="gr0"[^>]*>HEAVIEST HE'S SAID: ≈390 \(FEB 2023\)</); + // The goal line moves under the remembered line in the readout look. + const goalTop = (html) => Number(/class="goalw" data-k="gw\d+" style="top:([\d.]+)px"/.exec(html)[1]); + assert.ok(goalTop(page("readout").html) > goalTop(today.html)); +}); + +test("the rim's flag is never on the hub or the readout", () => { + const { html } = page("rim"); + const at = /class="rflag" data-k="gl0" style="left:([\d.]+)px; top:([\d.]+)px"/.exec(html); + const [x, y] = [Number(at[1]), Number(at[2])]; + // The dial's 540 face: centre 270, the readout's words from 60 px under it. + assert.ok(Math.hypot(x - 270, y - 270) > 80, `clear of the hub (${x}, ${y})`); + assert.ok(!(y > 270 + 40 && Math.abs(x - 270) < 128), `clear of the readout (${x}, ${y})`); +}); + +test("one at a time, the latest remembered; the callout sweeps a ghost needle and holds its label, then the flag", () => { + const rim = page("rim").data; + const up = (d, k) => d.cues.filter((c) => c.k === k && c.to.autoAlpha === 1).map((c) => c.at); + const down = (d, k) => d.cues.filter((c) => c.k === k && c.to.autoAlpha === 0).map((c) => c.at); + assert.deepEqual(up(rim, "gl0"), [3]); + assert.deepEqual(down(rim, "gl0"), [8], "gives way to the next remembered"); + assert.deepEqual(up(rim, "gl1"), [8]); + const call = page("callout").data; + assert.deepEqual(up(call, "gl0"), [3 + CALLOUT_HOLD], "the flag after the hold"); + assert.deepEqual(up(call, "gc0"), [3.25]); + assert.deepEqual(down(call, "gc0"), [3 + CALLOUT_HOLD]); + const gn = call.cues.filter((c) => c.k === "gn"); + assert.ok(gn.some((c) => c.at === 3 && c.to.autoAlpha === 0.9), "the ghost needle comes up where the needle stands"); + assert.ok(gn.some((c) => Math.abs(c.at - (3 + CALLOUT_HOLD)) < 1e-6 && c.to.autoAlpha === 0), "and goes after the hold"); +}); diff --git a/umtool/report-to-video/shelf.test.mjs b/umtool/report-to-video/shelf.test.mjs @@ -10,11 +10,11 @@ import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; -import { dietHtml, goalsHtml, shelfGoalStates, tagWords, tagWordSize } from "./chrome-measure-extras.mjs"; +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, goalStates, dietTagsBox, GOALS_SHELF, goalsShelfWidth, measureExtraGeometry, measurePlacements, shelfLayout, streakStates } from "./measure-extras.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"; @@ -258,7 +258,7 @@ test("goals on the shelf: the count and the fanned notes, the fan taking the she const { html, items } = goalsHtml(schedule(), r, { fonts: {} }); assert.match(html, /<div class="gc"><div class="gn" data-k="s0\.c">1<\/div><div class="gl">goal set<\/div><\/div>/); assert.match(html, /class="note" data-k="s\d+\.n\d+" style="z-index:19"><div class="tape"><\/div><div class="nf"/); - assert.match(html, /<div class="nb"[^>]*><div class="bt">LOSE 100<\/div>/, "an older note shows its words beside the one in front"); + assert.match(html, /<div class="nb"[^>]*><div class="bt"[^>]*>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. @@ -286,3 +286,78 @@ test("goals on the shelf: the dial's goal board orders the fan -- its headline i const { html } = goalsHtml(sched, r, { fonts: {} }); assert.match(html, new RegExp(`<div class="mo">\\+${end.active.length - 1} more</div>`)); }); + +// --------------------------------------------------------------------------- +// 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 class="nt">[^<]+<\/div><div class="fr">\(FROM [≈<>]?[\d.]+\)<\/div>/); + assert.match(html, /<div class="bt"[^>]*>[^<]+<\/div><div class="bf">\(FROM [≈<>]?[\d.]+\)<\/div>/); + // Off: none of it. + assert.doesNotMatch(goalsHtml(schedule(), renderOf(FAN), { fonts: {} }).html, /class="(fr|bf)"/); +}); diff --git a/umtool/report-to-video/stats.test.mjs b/umtool/report-to-video/stats.test.mjs @@ -137,9 +137,11 @@ test("the page: one block per state, the numbers as the panel shows them, every const schedule = estimateSchedule({ render: render(), timeline: ENTRIES, frameScan: OVERLAY }); const { init, cues } = statsCues(schedule); assert.deepEqual(Object.keys(init).sort(), ["pn", "s0_0", "s0_1", "s1_0"]); - // The first state shows at the clip's in, hides as the second shows. + // The first state shows at the clip's in -- here the cut's first instant, so it is up in init, on frame 0 (cue-start.mjs + // settleFirstFrame) -- and hides as the second shows. const s00 = cues.filter((c) => c.k === "s0_0"); - assert.deepEqual(s00.map((c) => [c.at, c.from.autoAlpha, c.to.autoAlpha]), [[0, 0, 1], [6, 1, 0]]); + assert.equal(init.s0_0.autoAlpha, 1); + assert.deepEqual(s00.map((c) => [c.at, c.from.autoAlpha, c.to.autoAlpha]), [[6, 1, 0]]); for (const c of cues) assert.ok(Object.keys(c.to).every((p) => p in c.from), JSON.stringify(c)); const html = statsHtml(schedule, render(), { fonts: { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" } }); diff --git a/umtool/report-to-video/threads.mjs b/umtool/report-to-video/threads.mjs @@ -23,6 +23,7 @@ import { resolveFactcheck } from "./factcheck.mjs"; // The limits and the validators are common's (lib/report/panels.mjs, release // 28): the threads draft task checks exactly what the build refuses. import { THREADS_LIMITS, threadOf, threadsOn, validateThreadEntries, validateThreads } from "yt-dlp-transcript-common/lib/report/panels.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; export { THREADS_LIMITS, threadOf, threadsOn, validateThreadEntries, validateThreads }; @@ -172,7 +173,7 @@ export function planCues(init, events, instant = 0.001) { freeAt.set(e.k, r4(at + dur)); cues.push({ k: e.k, at, dur, from, to: e.to, ease: e.ease, why: e.why }); } - return cues; + return settleFirstFrame(init, cues); } /** A card's resting opacity before its thread plays, and after. */ diff --git a/umtool/report-to-video/trail-plan.mjs b/umtool/report-to-video/trail-plan.mjs @@ -0,0 +1,149 @@ +// THE TRAIL'S PLAN (the by-date chart strip under the instruments, 11 Nov): which +// weights it shows at each moment of the cut, and where each one stands then. +// +// Before this the strip laid every STATED weight of the whole cut on one fixed +// pair of axes from the first frame: a remembered weight ("≈390, as of Feb +// 2023", "368 as of Jun 2008") was never a point, a 2013 weigh-in sat pinned at +// the left edge of a 2013–2026 axis for minutes, and one straight line crossed +// a decade of nothing to the 2025–26 points squeezed into the last pixels. +// +// Now the chart is a sequence of STATES, one per moment a weight is said: the +// points said so far -- stated ones, and remembered ones (`remembered`, hollow +// and grey, never joined into the line) -- at their own dates (asOf, else the +// day said) and values; the axes FIT what is shown (`bounds: "fit"`; "fixed" +// pins them to the whole cut's points); and a stretch of time with no statement +// longer than the gap threshold (`gap`) is not drawn as data: the time axis is +// cut there into CLUSTERS, each with its own years, a narrow break between them +// and a dotted connector across it, so the dense recent run gets the width. The +// page (chrome-instruments.mjs trailHtml) moves everything from one state's +// places to the next's over TRAIL_REFLOW seconds. +// +// PURE: the measure slice and a box in, plain data out. +import { dayNumber } from "./measure-draw.mjs"; + +/** Seconds a reflow takes: the axes and every point moving to the new state's places. */ +export const TRAIL_REFLOW = 0.4; + +/** `gap: "auto"`: a stretch is a break when longer than this many days, or `GAP_MEDIANS` times the median spacing. */ +export const GAP_FLOOR_DAYS = 365; +export const GAP_MEDIANS = 8; + +const r2 = (v) => Math.round(v * 100) / 100; + +/** + * The trail's points, in the order the cut says them: `{ n, t, row, value, qualifier, day, kind }`, `kind` + * "stated" or "remembered" (only with `remembered`), `day` the day number of its asOf, else its date. + */ +export function trailPoints(measure, { remembered = true } = {}) { + const out = []; + for (const e of measure?.events ?? []) { + if (!Number.isFinite(e.t) || !Number.isFinite(Number(e.value))) continue; + if (e.kind !== "stated" && !(remembered && e.kind === "remembered")) continue; + const day = dayNumber(e.asOf ?? e.date); + if (!Number.isFinite(day)) continue; + out.push({ t: e.t, row: e.row ?? null, value: Number(e.value), qualifier: e.qualifier ?? null, day, kind: e.kind }); + } + out.sort((a, b) => a.t - b.t); + return out.map((p, n) => ({ ...p, n })); +} + +/** The gap threshold in days: `gap` a number of days, 0/false never, "auto" from the data (see GAP_FLOOR_DAYS). */ +export function gapThreshold(points, gap = "auto") { + if (gap === 0 || gap === false) return Infinity; + if (typeof gap === "number" && gap > 0) return gap; + const days = [...new Set(points.map((p) => p.day))].sort((a, b) => a - b); + const steps = days.slice(1).map((d, i) => d - days[i]).sort((a, b) => a - b); + const median = steps.length ? steps[Math.floor(steps.length / 2)] : 0; + return Math.max(GAP_FLOOR_DAYS, GAP_MEDIANS * median); +} + +/** Days, sorted, cut into clusters where a step is longer than `thr`: `[{ first, last }]`. */ +export function clustersOf(days, thr) { + const ds = [...new Set(days)].sort((a, b) => a - b); + const out = []; + for (const d of ds) { + const c = out[out.length - 1]; + if (c && d - c.last <= thr) c.last = d; + else out.push({ first: d, last: d }); + } + return out; +} + +const yearOf = (d) => new Date(d * 86400000).getUTCFullYear(); +const jan1 = (y) => Date.UTC(y, 0, 1) / 86400000; + +/** + * One state's places: the y bounds (`lo`/`hi`, tens of the unit around the values shown and the mark), the + * clusters along x (each `{ first, last, from, to, x0, x1 }`: its days, its padded span, its pixels), the breaks + * between them (`gaps`: `{ key, x }`), the year labels (`years`: `{ key, text, x, tick }`), and `X(day)` / `Y(v)`. + * + * `box` = `{ x0, x1, y0, y1, gapPx, yearPx }` in page pixels. + */ +export function trailLayout(points, box, { thr = Infinity, mark = null } = {}) { + const { x0, x1, y0, y1 } = box; + const gapPx = box.gapPx ?? 22; + const yearPx = box.yearPx ?? 34; + const vals = points.map((p) => p.value).concat(mark !== null && mark !== undefined ? [mark] : []); + const lo = vals.length ? Math.floor((Math.min(...vals) - 5) / 10) * 10 : 0; + const hi = vals.length ? Math.ceil((Math.max(...vals) + 5) / 10) * 10 : 10; + const cl = clustersOf(points.map((p) => p.day), thr); + const spread = cl.reduce((s, c) => s + (c.last - c.first), 0); + const pad = Math.max(20, 0.04 * spread); + for (const c of cl) { + const p = c.last - c.first < 1 ? Math.max(pad, 60) : pad; + c.from = c.first - p; + c.to = c.last + p; + } + const widthDays = cl.reduce((s, c) => s + (c.to - c.from), 0) || 1; + const scale = Math.max(0, x1 - x0 - gapPx * Math.max(0, cl.length - 1)) / widthDays; + let at = x0; + for (const c of cl) { + c.x0 = r2(at); + c.x1 = r2(at + (c.to - c.from) * scale); + at = c.x1 + gapPx; + } + const X = (d) => { + const c = cl.find((k) => d >= k.from - 1e-9 && d <= k.to + 1e-9) ?? null; + return c ? r2(c.x0 + (d - c.from) * scale) : null; + }; + const Y = (v) => r2(y1 - ((v - lo) / Math.max(1, hi - lo)) * (y1 - y0)); + const gaps = cl.slice(1).map((c, i) => ({ key: `${cl[i].last}_${c.first}`, x: r2((cl[i].x1 + c.x0) / 2) })); + // The years: each cluster's first year labelled at its first point (unless that year's 1 January is a tick in it), + // each 1 January inside a cluster's span a tick; then thinned left to right so no two labels are closer than + // `yearPx`, a cluster's own year first. + const cands = []; + for (const c of cl) { + const firstYear = yearOf(c.first); + if (jan1(firstYear) < c.from) cands.push({ key: `c${firstYear}`, text: String(firstYear), x: X(c.first), tick: false, lead: true }); + for (let y = yearOf(c.from) + 1; jan1(y) <= c.to; y += 1) cands.push({ key: `t${y}`, text: String(y), x: X(jan1(y)), tick: true }); + } + cands.sort((a, b) => a.x - b.x || (b.lead ? 1 : 0) - (a.lead ? 1 : 0)); + const years = []; + for (const y of cands) if (!years.length || y.x - years[years.length - 1].x >= yearPx) years.push(y); + return { lo, hi, clusters: cl, gaps, years, X, Y }; +} + +/** + * The trail's states: one per moment a point is said (`at`), each with the points shown (`shown`, their `n`), its + * layout, each shown point's place (`pos`: n -> {x, y}) and the line's pairs (`pairs`: neighbours by date among the + * STATED points shown, `{ key, a, b, gap }`, `gap` when they straddle a break). `bounds: "fixed"` lays every state on + * the layout of all the cut's points (the strip as it was, but with its breaks). + * + * @param {ReturnType<typeof trailPoints>} points + */ +export function trailStates(points, box, { gap = "auto", mark = null, bounds = "fit" } = {}) { + const thr = gapThreshold(points, gap); + const all = bounds === "fixed" ? trailLayout(points, box, { thr, mark }) : null; + const times = [...new Set(points.map((p) => p.t))].sort((a, b) => a - b); + return times.map((at) => { + const shown = points.filter((p) => p.t <= at + 1e-9); + const layout = all ?? trailLayout(shown, box, { thr, mark }); + const pos = new Map(shown.map((p) => [p.n, { x: layout.X(p.day), y: layout.Y(p.value) }])); + const stated = shown.filter((p) => p.kind === "stated").sort((a, b) => a.day - b.day || a.t - b.t); + const pairs = stated.slice(1).map((b, i) => { + const a = stated[i]; + return { key: `${a.n}_${b.n}`, a: a.n, b: b.n, gap: b.day - a.day > thr }; + }); + return { at, shown: shown.map((p) => p.n), layout, pos, pairs, thr }; + }); +} diff --git a/umtool/report-to-video/trail-plan.test.mjs b/umtool/report-to-video/trail-plan.test.mjs @@ -0,0 +1,118 @@ +// THE TRAIL'S PLAN (trail-plan.mjs; chrome-instruments.mjs trailHtml): the by-date chart shows every weight said +// so far -- stated and remembered -- on axes that fit them and reflow as each lands, its time axis broken across +// long empty stretches (rev9-a7, 11 Nov: a 2013 dot pinned at the left edge for minutes, 2008 and ≈390 never drawn, +// one line across a decade to the 2025–26 points squeezed at the right). +import assert from "node:assert/strict"; +import test from "node:test"; + +import { trailHtml } from "./chrome-instruments.mjs"; +import { estimateSchedule } from "./deck.mjs"; +import { clustersOf, GAP_FLOOR_DAYS, gapThreshold, trailLayout, trailPoints, trailStates } from "./trail-plan.mjs"; +import { dayNumber } from "./measure-draw.mjs"; +import { validateTrail } from "./instruments.mjs"; + +/** The a7 sequence: a 2013 weigh-in and a second 2013 weight; a remembered ≈390 (as of Feb 2023) above them; a + * remembered 368 as of 2008 -- before everything and above the old top; then the dense 2025–26 run. */ +const ev = (t, kind, value, date, extra = {}) => ({ t, kind, value, date, row: `r${t}`, scope: "weight", qualifier: null, asOf: null, ...extra }); +const EVENTS = [ + ev(9, "stated", 346.7, "2013-03-09"), + ev(31, "stated", 342.9, "2013-03-21"), + ev(60, "remembered", 390, "2023-09-29", { asOf: "2023-02-24", qualifier: "≈" }), + ev(100, "remembered", 368, "2025-01-10", { asOf: "2008-06-30" }), + ev(175, "stated", 349, "2025-04-08"), + ev(204, "stated", 341, "2025-06-02"), + ev(225, "stated", 336, "2025-07-15"), + ev(230, "stated", 331.5, "2025-08-01"), + ev(280, "stated", 322, "2025-10-08"), + ev(293, "stated", 318, "2025-11-20"), + ev(320, "stated", 305, "2026-01-16"), + ev(324, "stated", 299, "2026-03-02"), + ev(337, "stated", 296, "2026-06-01", { qualifier: "≈" }), + ev(347, "goal", 250, "2026-07-01"), +]; +const MEASURE = { unit: "lb", scale: { min: 220, max: 400 }, events: EVENTS, state: [{ t: 0 }], totals: {} }; +const BOX = { x0: 54, x1: 582, y0: 38, y1: 174, gapPx: 22, yearPx: 34 }; + +test("the trail's points: stated and remembered, each at its own date (asOf first), in the cut's order", () => { + const pts = trailPoints(MEASURE); + assert.equal(pts.length, 13, "the goal is not a weight"); + assert.deepEqual(pts.map((p) => p.kind).slice(0, 5), ["stated", "stated", "remembered", "remembered", "stated"]); + assert.equal(pts[3].day, dayNumber("2008-06-30"), "a remembered weight stands at the day it was his weight"); + assert.equal(trailPoints(MEASURE, { remembered: false }).length, 11); +}); + +test("at every moment the chart shows exactly the weights said by then, on axes that contain all of them", () => { + const pts = trailPoints(MEASURE); + const states = trailStates(pts, BOX, { mark: 300 }); + assert.equal(states.length, 13); + for (const st of states) { + const shown = pts.filter((p) => p.t <= st.at); + assert.equal(st.shown.length, shown.length, `at ${st.at}`); + for (const p of shown) { + assert.ok(st.layout.lo <= p.value && p.value <= st.layout.hi, `at ${st.at}: ${p.value} inside ${st.layout.lo}–${st.layout.hi}`); + const { x, y } = st.pos.get(p.n); + assert.ok(x !== null && x >= BOX.x0 && x <= BOX.x1, `at ${st.at}: ${p.value} on the x axis (${x})`); + assert.ok(y >= BOX.y0 && y <= BOX.y1, `at ${st.at}: ${p.value} on the y axis (${y})`); + } + } + // The first weigh-in alone: in the middle of the strip, not pinned to its left edge. + const one = states[0].pos.get(0).x; + assert.ok(one > BOX.x0 + 100 && one < BOX.x1 - 100, `a lone point stands mid-strip (${one})`); + // The remembered ≈390 raises the top; the 2008 one moves the start of time back and keeps 390 in. + assert.ok(states[1].layout.hi < 390 && states[2].layout.hi >= 390); + assert.ok(states[3].pos.get(3).x < states[3].pos.get(0).x, "2008 stands left of 2013"); + // The axes advance with the story: no 2026 on the axis until a 2026 weight is said. + const years = (st) => st.layout.years.map((y) => y.text); + assert.ok(!years(states[4]).includes("2026")); + assert.ok(years(states.at(-1)).includes("2026")); +}); + +test("the gap rule: a stretch longer than a year (or 8× the median spacing) breaks the time axis; the dense run gets the width", () => { + const pts = trailPoints(MEASURE); + // The median step between the dates here is 57 days: 8× is 456, past the year's floor. + assert.equal(gapThreshold(pts), 456); + assert.equal(gapThreshold([0, 7, 14, 21, 28].map((day) => ({ day }))), GAP_FLOOR_DAYS, "weekly statements: the year's floor rules"); + assert.equal(gapThreshold(pts, 540), 540); + assert.equal(gapThreshold(pts, 0), Infinity); + // Spacing of 100 days: 8× is 800, past the floor. + const sparse = [0, 100, 200, 300, 400].map((day) => ({ day })); + assert.equal(gapThreshold(sparse), 800); + assert.deepEqual(clustersOf([1, 2, 500, 900, 901], 365), [{ first: 1, last: 2 }, { first: 500, last: 500 }, { first: 900, last: 901 }]); + const last = trailStates(pts, BOX, { mark: 300 }).at(-1); + // 2008 | 2013 | 2023 | 2025–26: three breaks, each a narrow band. + assert.equal(last.layout.clusters.length, 4); + assert.equal(last.layout.gaps.length, 3); + const dense = last.layout.clusters.at(-1); + assert.ok(dense.x1 - dense.x0 > 0.5 * (BOX.x1 - BOX.x0), `the 2025–26 run has most of the width (${dense.x1 - dense.x0} px)`); + // The line: stated neighbours only -- the remembered never joined -- dotted across a break. + const byN = new Map(pts.map((p) => [p.n, p])); + for (const pr of last.pairs) assert.ok(byN.get(pr.a).kind === "stated" && byN.get(pr.b).kind === "stated"); + const across = last.pairs.find((pr) => byN.get(pr.a).value === 342.9); + assert.equal(across.gap, true, "2013 to 2025 is a dotted connector, not data"); + assert.ok(last.pairs.filter((pr) => !pr.gap).length >= 8); + // gap: 0 -- one cluster, no breaks. + assert.equal(trailStates(pts, BOX, { gap: 0, mark: 300 }).at(-1).layout.gaps.length, 0); + // bounds: "fixed" -- every moment on the whole cut's axes. + const fixed = trailStates(pts, BOX, { bounds: "fixed", mark: 300 }); + assert.equal(fixed[0].layout.hi, fixed.at(-1).layout.hi); +}); + +test("the page: points pop in where their moment puts them and move with every reflow, seek-safe; the knobs validate", () => { + const timeline = Array.from({ length: 4 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "v", start: 0, end: 100 })); + const render = { width: 1920, height: 1080, fps: 30, transition: 0.4, palette: { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }, + chrome: { engine: "hyperframes", layout: "deck", deck: { dial: true, odometer: true, trail: true } } }; + const schedule = { ...estimateSchedule({ slug: "m", title: "M", provenance: {}, render, timeline }), measure: MEASURE }; + const html = trailHtml(schedule, render, { fonts: {} }); + const data = JSON.parse(/<script id="trail-data" type="application\/json">(.*?)<\/script>/s.exec(html)[1]); + assert.match(html, /class="pt rem q" data-k="p2"/, "the remembered ≈390: hollow, grey, its qualifier dashed"); + assert.match(html, /class="seg gap" data-k="s1_4"/, "2013 → 2025 dotted"); + assert.ok(!/data-k="s\d+_2"|data-k="s2_\d+"/.test(html), "the remembered are never joined"); + // p0 (the 2013 weigh-in) moves when the 2013 second weight lands, and again when 2008 pushes time back. + const moves = data.cues.filter((c) => c.k === "p0" && "x" in c.to).map((c) => c.at); + assert.ok(moves.includes(31) && moves.includes(100), `p0 reflows at 31 and 100 (${moves})`); + // Every cue states its from (seek-safe), and nothing changes at 0 that frame 0 cannot show. + assert.ok(data.cues.every((c) => Object.keys(c.to).every((k) => k in c.from))); + assert.deepEqual(validateTrail({ bounds: "fixed", remembered: false, gap: 540 }), []); + assert.match(validateTrail({ gap: 10 }).join(), /gap must be "auto", 0 \(no breaks\) or 30 to 3650 days/); + assert.match(validateTrail({ bounds: "loose" }).join(), /bounds must be "fit" or "fixed"/); +}); diff --git a/umtool/report-to-video/update-flash.mjs b/umtool/report-to-video/update-flash.mjs @@ -0,0 +1,84 @@ +// THE UPDATE FLASH (operator, 11 Nov: "whenever a widget gets updated, have it +// show a subtle border flash or something to indicate that at a glance"): at +// the moment a measure widget's shown value changes, a thin outline just inside +// its edge lights over FLASH_MOTION.up and decays over FLASH_MOTION.down, in the +// widget's own colour -- no size change, no layout shift. Widgets that change on +// the same event flash together (each reads the same event times). +// +// What counts as a change, per widget (each page picks its own times): +// the dial a new stated weight, a remembered one, a goal in force changing +// the odometer the pounds lost going up (or its runs), NET changing +// the trail each weight landing on the chart +// the diet a new diet (a new front tag) -- never the running day count +// the goals a goal set (a note landing) -- not the board's own changes +// Never on frame 0, never while the deck is away (the intro, a card, the +// finale's hand-over), never on a widget's first appearance (its own entrance +// marks that) unless it is the dial, which stands from the start. +// +// OFF by default: `render.chrome.deck.measure.flash: true` turns it on for +// every widget; a widget's own `flash` (true/false) overrides that for it. +import { deckChoreography } from "./deck.mjs"; + +/** Seconds: the outline's rise and its decay. */ +export const FLASH_MOTION = Object.freeze({ up: 0.15, down: 0.7 }); + +/** Is the flash on for a widget: its own `flash` when it says, else `deck.measure.flash`. */ +export function flashOn(render, own = null) { + if (typeof own === "boolean") return own; + return render?.chrome?.deck?.measure?.flash === true; +} + +/** The spans the deck is away (deckChoreography's visibility): `[{ from, to }]`, `to` Infinity when it stays away. */ +export function deckAwaySpans(schedule, render) { + let vis = []; + try { + vis = deckChoreography(schedule, render).visibility; + } catch { + return []; + } + const out = []; + let open = null; + for (const v of [...vis].sort((a, b) => a.at[0] - b.at[0])) { + if (v.hide && open === null) open = v.at[0]; + else if (!v.hide && open !== null) { out.push({ from: open, to: v.at[1] }); open = null; } + } + if (open !== null) out.push({ from: open, to: Infinity }); + return out; +} + +/** + * The moments a widget flashes: its change `times`, sorted, one per 0.05 s, none before frame 1 and none while the + * deck is away (`away`, deckAwaySpans). + */ +export function flashTimes(times, { fps = 30, away = [] } = {}) { + const frame = 1 / (Number(fps) > 0 ? Number(fps) : 30); + const out = []; + for (const t of [...times].filter(Number.isFinite).sort((a, b) => a - b)) { + if (t < frame - 1e-9) continue; + if (away.some((s) => t >= s.from - 1e-6 && t < s.to)) continue; + if (out.length && t - out[out.length - 1] < 0.05) continue; + out.push(t); + } + return out; +} + +/** The outline's cue events (compileCues / cueList shape): up, then down, at each time. */ +export function flashEvents(k, times) { + const { up, down } = FLASH_MOTION; + return times.flatMap((t) => [ + { k, at: t, dur: up, to: { opacity: 1 }, ease: "power1.out" }, + { k, at: t + up, dur: down, to: { opacity: 0 }, ease: "power2.out" }, + ]); +} + +/** A cueList's adds for the outline `k` (its init: hidden). */ +export function flashCues(L, k, times) { + L.set(k, { opacity: 0 }); + for (const e of flashEvents(k, times)) L.add(e.k, e.at, e.dur, e.to, e.ease); +} + +/** The outline's look: a thin line in `color` just inside the box (`inset` negative: just outside), a soft glow; `radius` its corners (CSS). */ +export function flashCss(sel, color, { radius = "0px", width = 2, inset = "0px" } = {}) { + return `${sel} { position: absolute; inset: ${inset}; border-radius: ${radius}; border: ${width}px solid ${color}; + box-shadow: 0 0 ${width * 5}px ${color}, inset 0 0 ${width * 3}px ${color}; opacity: 0; pointer-events: none; }`; +} diff --git a/umtool/report-to-video/update-flash.test.mjs b/umtool/report-to-video/update-flash.test.mjs @@ -0,0 +1,130 @@ +// THE UPDATE FLASH (update-flash.mjs; operator, 11 Nov): a measure widget's outline lights at the moment its +// shown value changes -- exactly that widget, exactly then -- and never on frame 0, over the intro, or on a widget's +// first appearance. Off by default: a cut renders as it did. +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 { estimateSchedule } from "./deck.mjs"; +import { dialHtml, odometerHtml, trailHtml } from "./chrome-instruments.mjs"; +import { dietHtml, goalsHtml, shelfGoalStates } from "./chrome-measure-extras.mjs"; +import { dietStates, goalStates } from "./measure-extras.mjs"; +import { measureTrack } from "./measure-draw.mjs"; +import { validateMeasureSettings } from "./measure-slice.mjs"; +import { validateDial } from "./instruments.mjs"; +import { validateMeasureExtra } from "./modules/measure-extras-settings.mjs"; +import { trailPoints } from "./trail-plan.mjs"; +import { FLASH_MOTION, flashOn, flashTimes } from "./update-flash.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const DIAL = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-dial", "measure.json"), "utf8")); +const EXTRAS = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-extras", "measure.json"), "utf8")); +const FPS = 30; +const PALETTE = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; +const deckOf = (deck) => ({ width: 1920, height: 1080, fps: FPS, transition: 0.4, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck } }); +const INSTR = { dial: true, odometer: true, trail: true, qr: { show: false }, finale: { video: "side", totals: false } }; +const ON = deckOf({ ...INSTR, measure: { flash: true } }); +const OFF = deckOf(INSTR); + +/** The instruments' fixture cut: 9 clips, the last the finale -- optionally opening on the intro. */ +function cut(render, { intro = false } = {}) { + const timeline = Array.from({ length: 9 }, (_, i) => ({ + type: "clip", id: `c${i + 1}`, video: "vidx", start: 10 * i, end: 10 * i + (i === 8 ? 14 : 8), cite: 1, section: 0, + quote: "q", onscreen: { title: `Clip ${i + 1}` }, ...(i === 8 ? { layout: "finale" } : {}), + })); + if (intro) timeline.unshift({ type: "intro", id: "brand-intro", style: "boot-dark", seconds: 4.75, heading: "Intro" }); + return { ...estimateSchedule({ slug: "m", title: "M", provenance: {}, render, timeline }), measure: DIAL }; +} +const dataOf = (html, id) => JSON.parse(new RegExp(`<script id="${id}-data" type="application/json">(.*?)</script>`, "s").exec(html)[1]); +/** The moments an outline `k` lights: its rising cues. */ +const lit = (data, k = "fl") => data.cues.filter((c) => c.k === k && c.to.opacity === 1).map((c) => c.at); +const near = (a, b) => a.length === b.length && a.every((x, i) => Math.abs(x - b[i]) < 0.02); + +test("off by default: no outline on any widget, and the pages are the pages they were", () => { + const s = cut(OFF); + for (const [id, html] of [["dial", dialHtml(s, OFF, {})], ["odometer", odometerHtml(s, OFF, {})], ["trail", trailHtml(s, OFF, {})]]) { + assert.doesNotMatch(html, /data-k="fl"/, id); + assert.equal(lit(dataOf(html, id)).length, 0, id); + } + assert.equal(flashOn(OFF), false); + assert.equal(flashOn(ON), true); + assert.equal(flashOn(ON, false), false, "a widget's own false beats the measure's true"); + assert.equal(flashOn(OFF, true), true); +}); + +test("a value change at t lights exactly the widget whose value changed, at t -- and nothing else does", () => { + const s = cut(ON); + const track = measureTrack(DIAL); + const frame = 1 / FPS; + const want = (times) => flashTimes(times, { fps: FPS }); + const dialT = want([...track.current.slice(1), ...track.remembered, ...track.goals.slice(1)].map((x) => x.t)); + const odoT = want([...track.lost.slice(1), ...track.net.slice(1)].map((x) => x.t)); + const trailT = want(trailPoints(DIAL).map((p) => p.t)); + const got = { dial: lit(dataOf(dialHtml(s, ON, {}), "dial")), odometer: lit(dataOf(odometerHtml(s, ON, {}), "odometer")), trail: lit(dataOf(trailHtml(s, ON, {}), "trail")) }; + assert.ok(near(got.dial, dialT), `dial ${got.dial} vs ${dialT}`); + assert.ok(near(got.odometer, odoT), `odometer ${got.odometer} vs ${odoT}`); + assert.ok(near(got.trail, trailT), `trail ${got.trail} vs ${trailT}`); + assert.ok(got.dial.length && got.odometer.length && got.trail.length); + // A moment only the odometer changes at (a loss claim, no weight stated): the odometer lights, the dial does not. + const onlyOdo = odoT.find((t) => !dialT.some((d) => Math.abs(d - t) < 0.02) && !trailT.some((d) => Math.abs(d - t) < 0.02)); + assert.ok(onlyOdo !== undefined, "the fixture has a loss claim with no weight stated with it"); + assert.ok(!got.dial.some((t) => Math.abs(t - onlyOdo) < 0.02)); + // A stated weight lights the dial and the trail together, at the same instant. + const both = dialT.find((t) => trailT.some((d) => Math.abs(d - t) < 0.02)); + assert.ok(both !== undefined && got.trail.some((t) => Math.abs(t - both) < 0.02)); + // Up over 0.15 s, down over 0.7 s; never before frame 1. + const d = dataOf(dialHtml(s, ON, {}), "dial"); + const up = d.cues.find((c) => c.k === "fl" && c.to.opacity === 1); + const down = d.cues.find((c) => c.k === "fl" && c.to.opacity === 0); + assert.equal(up.dur, FLASH_MOTION.up); + assert.equal(down.dur, FLASH_MOTION.down); + assert.ok(Object.values(got).flat().every((t) => t >= frame)); + assert.deepEqual(d.init.fl, { opacity: 0 }, "dark on frame 0"); +}); + +test("never over the intro: a change said while the deck is away does not light anything", () => { + const s = cut(ON, { intro: true }); + const introEnd = s.segments[1].start; + for (const [id, html] of [["dial", dialHtml(s, ON, {})], ["odometer", odometerHtml(s, ON, {})], ["trail", trailHtml(s, ON, {})]]) { + const times = lit(dataOf(html, id)); + assert.ok(times.every((t) => t >= introEnd), `${id}: ${times} after ${introEnd}`); + } + // The fixture's changes at 2 and 3.75 s fall inside the 4.75 s intro: they are dropped, not moved. + assert.ok(!lit(dataOf(dialHtml(s, ON, {}), "dial")).some((t) => t < introEnd)); +}); + +test("the goal stack and the diet tags: a goal set / a new diet lights the card that lands -- never the first", () => { + const FAN = { dial: true, odometer: true, trail: true, shelf: { items: ["diet", "goals"] }, diet: { position: "shelf", form: "tags", overlap: 0.6, days: true }, goals: { position: "shelf" }, streak: false, measure: { flash: true } }; + const r = deckOf(FAN); + const sched = { kind: "deck", fps: FPS, total: 740, transition: 0.4, segments: [{ id: "a", start: 0, duration: 740, end: 740 }], measure: EXTRAS }; + const shelf = shelfGoalStates(sched, goalStates(sched, r)); + const g = dataOf(goalsHtml(sched, r, { fonts: {} }).html, "goals"); + const gLit = g.cues.filter((c) => /\.fl$/.test(c.k) && c.to.opacity === 1); + const wantG = shelf.filter((st, j) => j > 0 && st.top).map((st) => st.at); + assert.ok(near(gLit.map((c) => c.at), wantG), `goals ${gLit.map((c) => c.at)} vs ${wantG}`); + assert.ok(!gLit.some((c) => c.k.startsWith("s0.")), "the first goal is the stack's entrance"); + // A board-only change (met, missed) is not a goal set: no outline. + assert.ok(shelf.some((st) => !st.top), "the fixture's board changes on its own") ; + const states = dietStates(sched, r); + const d = dataOf(dietHtml(sched, r, { fonts: {} }).html, "diet"); + const dLit = d.cues.filter((c) => /\.fl$/.test(c.k) && c.to.opacity === 1).map((c) => c.at); + const wantD = states.filter((st, j) => j > 0 && st.tags[0]?.id !== states[j - 1].tags[0]?.id).map((st) => st.at); + assert.ok(near(dLit, wantD), `diet ${dLit} vs ${wantD}`); + // The running day count changes far more often than the diet: it never lights the tag. + assert.ok(dLit.length < d.cues.filter((c) => /\.y\d+$/.test(c.k)).length); + // Off: nothing. + const off = deckOf({ ...FAN, measure: undefined }); + assert.doesNotMatch(goalsHtml(sched, off, { fonts: {} }).html, /class="fl"/); + assert.doesNotMatch(dietHtml(sched, off, { fonts: {} }).html, /class="fl"/); +}); + +test("the knobs: deck.measure.flash and each widget's own flash validate", () => { + assert.deepEqual(validateMeasureSettings({ flash: true }), []); + assert.match(validateMeasureSettings({ flash: "on" }).join(), /measure\.flash must be true or false/); + assert.deepEqual(validateDial({ flash: false }), []); + assert.match(validateDial({ flash: 1 }).join(), /dial\.flash must be true or false/); + assert.deepEqual(validateMeasureExtra("goals", { flash: true }), []); + assert.match(validateMeasureExtra("diet", { flash: "x" }).join(), /flash must be true, false or null/); +}); diff --git a/umtool/report-to-video/vertical-deck.test.mjs b/umtool/report-to-video/vertical-deck.test.mjs @@ -266,7 +266,10 @@ const MAIN = { deck: "546848c82d65e45e4d1a4ac4c7a9c3c8", dial: "f7e21e4a3622703975f746d39cbcb738", odometer: "8425983d217408dddcb6ee794881c6c4", - trail: "3512192be69f8b9bc33aec6e7b41a088", + // Re-pinned on lane/frame-zero (11 Nov): the trail's axes fit the weights said so far and reflow, its remembered + // weights are points, its time axis breaks over long empty stretches (trail-plan.mjs) -- the page is new by design. + // Main's was 3512192be69f8b9bc33aec6e7b41a088. + trail: "39c3694f4e26963277d9b22ebfd0f60b", dialFinale: "52866e4d87e15bd55afe8c1a703414a3", geometry: "182959796c281f769766df3d02962904", bare: "7ce1f7a66452adec21575bcdbba900f1",