// 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; }`; }