// THE MEASURE EXTRAS' PAGES (weight video rev 9, lane measure-extras): the // goal stack, the moving start, the promise clock and the diet badge, each a // cue page (chrome-cues.mjs) over the whole cut -- the render captures it // frame by frame (HyperFrames png-sequence) and Play iframes the SAME page, // seeked by `deck:seek`, posting `:ready`. // // Each STATE (measure-extras.mjs) is its own block, shown over exactly its // span and handed to the frame keys as an item gated by its own autoAlpha: // a frame keys only the block on screen, so between two events every frame // is the same frame and the render reuses it. Motion is the block's own: the // note that lands, the tick that grows, the stamp that slams -- each a cue // with its FROM stated, so a seek from anywhere lands on the same pixels. // // PURE: a schedule and a render block in, `{ html, items }` out. import { formatDeckDate } from "./attribution.mjs"; import { rgba } from "./chrome-deck.mjs"; import { compileCues, cuePageHtml, esc, INSTANT, joinSpans, r4, spanEvents } from "./chrome-cues.mjs"; import { daysBetween, daysLeftText, daysText, DIET_TAG, dietDays, dietStates, dietTagStep, goalStates, goalText, GOALS_SHELF, jitter, measureBox, measureExtraGeometry, measureOf, MEASURE_BOXES, promiseStripRect, promiseStripType, MEASURE_DODGE_MOVE, measurePlacements, monthYear, peakStates, promiseStates, shortDate, stampNoteClause, stampNoteLine, streakStates, upSpans, weightText, } from "./measure-extras.mjs"; 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 }); const feedOf = (schedule) => schedule?.layout === "feed"; /** The page's frame: its region, its pixel scale against its design box, its fps. */ function frameOf(id, schedule, render) { const geo = measureExtraGeometry(id, render, { feed: feedOf(schedule) }); // On the shelf a module is scaled to the shelf's HEIGHT: its slot may be wider than its box (the goals' fan // takes the width left over) and is never narrower. const box = measureBox(id, render); const k = resolveMeasureExtra(id, render)?.position === SHELF_POSITION ? geo.height / box.height : geo.width / box.width; const px = (v) => Math.max(1, Math.round(v * k)); return { geo, k, px, fps: schedule.fps ?? render.fps ?? 30 }; } /** The display face, when the render names one (`fontDisplay`): the condensed extra-bold, else the deck's bold. */ const displayFace = (fonts) => (fonts?.display ? `@font-face { font-family: 'MeasureDisplay'; font-weight: 400; font-style: normal; src: url('${esc(fonts.display)}'); }` : ""); const DISPLAY = "'MeasureDisplay', 'DeckSansBold', sans-serif"; /** * The cues every state page shares: the panel `pn` up over the module's spans, * each state `s` shown from its `at` to the next one's (+ `overlap`, while * the next one's entrance runs), and the state's own events. */ function stateCues(states, spans, { overlap = 0, own = () => [] } = {}, initExtra = {}) { const init = { pn: { autoAlpha: 0 }, ...initExtra }; const ev = []; for (const sp of spans) ev.push(...spanEvents("pn", sp.in, sp.out, { fadeIn: MEASURE_FADE.in, fadeOut: MEASURE_FADE.out })); states.forEach((st, j) => { const k = `s${j}`; init[k] = { autoAlpha: 0 }; const until = states[j + 1] ? states[j + 1].at + overlap : null; ev.push({ k, at: st.at, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); if (until !== null) ev.push({ k, at: until, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); ev.push(...own(st, j, init)); }); return compileCues(init, ev); } /** * Where the mover stands over time: `[{ at, to: "home" | "hide" | { x, y, size } }]`, * one step wherever that changes. Moves may overlap (a post item's span * crossfades into the next one's, a chapter band rises inside a post): while * any move that hides is on, it is hidden; else it stands where the latest * move to start puts it; with none, at home. */ export function moverSteps(moves) { const cuts = [...new Set(moves.flatMap((m) => [m.from, m.to]))].sort((a, b) => a - b); const steps = []; let was = "home"; for (const at of cuts) { const on = moves.filter((m) => m.from <= at + 1e-6 && m.to > at + 1e-6); let to = "home"; if (on.some((m) => !m.rect)) to = "hide"; else if (on.length) { const m = on.reduce((x, y) => (y.from >= x.from ? y : x)); to = { x: m.rect.x, y: m.rect.y, size: m.size }; } if (JSON.stringify(to) !== JSON.stringify(was)) steps.push({ at, to }); was = to; } return steps; } /** * The mover's cues (measure-extras.mjs measurePlacements, through * moverSteps): the module's box `mv` slides to each slot clear of a post card * or a chapter band (scaled from its corner) and back, or fades out and in * when nothing fits -- each change over MEASURE_DODGE_MOVE, or half the time * to the next. */ export function moverCues(place) { const { home } = place; const init = { mv: { x: 0, y: 0, scale: 1, autoAlpha: 1 } }; const steps = moverSteps(place.moves); const ev = []; let alpha = 1; let pos = { x: 0, y: 0, scale: 1 }; steps.forEach((st, i) => { const next = steps[i + 1]?.at ?? Infinity; const d = Math.max(INSTANT, Math.min(MEASURE_DODGE_MOVE, (next - st.at) / 2)); if (st.to === "hide") { if (alpha !== 0) ev.push({ k: "mv", at: st.at, dur: d, to: { autoAlpha: 0 }, ease: "power1.in" }); alpha = 0; return; } const want = st.to === "home" ? { x: 0, y: 0, scale: 1 } : { x: st.to.x - home.x, y: st.to.y - home.y, scale: st.to.size }; const moved = JSON.stringify(want) !== JSON.stringify(pos); if (alpha === 0) { // Hidden: put it in place at once, then fade it in there. if (moved) ev.push({ k: "mv", at: st.at, dur: INSTANT, to: want, ease: "none" }); ev.push({ k: "mv", at: st.at, dur: d, to: { autoAlpha: 1 }, ease: "power1.out" }); } else if (moved) ev.push({ k: "mv", at: st.at, dur: d, to: want, ease: "power2.inOut" }); alpha = 1; pos = want; }); return compileCues(init, ev); } /** * A module's page: its box drawn in its region (its home, and every slot it * moves clear to), inside the mover `mv`. */ /** * Where the promise clock goes in the finale: the dial's finale hands its lower * column to it (instruments.mjs `finaleEnd`, default "auto": when a promise is * on camera) -- `{ at, rect, size }`, its box fitted into that column, or null * (no dial finale, or no handoff). */ export function promiseFinaleSlot(schedule, render) { if (!schedule?.finale || !resolveMeasureExtra("promise", render)) return null; let at = null; let geo = null; try { at = dialFinaleHandoff(schedule, render); geo = at !== null ? dialFinaleGeometry(schedule, render) : null; } catch { return null; } if (at === null || !geo) return null; const box = measureBox("promise", render); const k0 = (render?.width ?? 1920) / 1920; const size = Math.min(1.6, geo.width / (box.width * k0), geo.height / (box.height * k0)); const home = measureExtraGeometry("promise", render); const w = Math.round(home.width * size); const h = Math.round(home.height * size); return { at, size: r4(size), rect: { x: geo.x + Math.round((geo.width - w) / 2), y: geo.y + Math.round((geo.height - h) / 2), width: w, height: h } }; } /** Every module's placement as its page and its region read it (the promise clock's finale slot included). */ export const placementsFor = (schedule, render) => measurePlacements(schedule, render, { finaleSlot: promiseFinaleSlot(schedule, render) }); /** * A module's page: its box drawn in its region (its home, and every slot it * moves clear to), inside the mover `mv`; `outside` is drawn beside the mover * (the promise clock's strip), its cues in `extra`. */ const page = (id, schedule, opts, { fps }, css, body, init, cues, ids, render, { outside = "", extra = null } = {}) => { const place = placementsFor(schedule, render)[id]; const { home, region } = place; const mover = moverCues(place); return cuePageHtml({ id, W: region.width, H: region.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css: `${displayFace(opts.fonts)}\n #mv { position: absolute; left: ${home.x - region.x}px; top: ${home.y - region.y}px; width: ${home.width}px; height: ${home.height}px; transform-origin: 0 0; }\n ${css}`, body: `
\n ${body}\n
${outside}`, init: { ...init, ...mover.init, ...(extra?.init ?? {}) }, cues: [...cues, ...mover.cues, ...(extra?.cues ?? [])], whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids }, primeWindow: true, }); }; // --------------------------------------------------------------------------- // GOALS: the sticky notes. // --------------------------------------------------------------------------- /** A note's place at `depth` in the pile (0 the front), region pixels. */ function notePlace(note, depth, px, H) { return { x: px(40 + note.dx + 6 * depth), y: H - px(46 + 150) - px(36 * depth), rotation: r4(note.rot + (depth ? (depth % 2 ? -2.5 : 2) : 0)), }; } /** The goal stack's page: `{ html, items }`. */ export function goalsHtml(schedule, render, opts = {}) { const cfg = resolveMeasureExtra("goals", render); const m = measureOf(schedule); const states = goalStates(schedule, render); if (!cfg || !m || !states.length) throw new Error("goals: the schedule's measure slice has no goal on camera"); if (cfg.position === SHELF_POSITION) return goalsShelfHtml(schedule, render, opts, cfg, states); const F = frameOf("goals", schedule, render); const { geo, px } = F; const H = geo.height; const pal = render.palette; 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); if (n.key === st.top) { // The new note lands: from above, turned, a size up -- onto the pile. init[k] = { x: to.x - px(30), y: to.y - px(230), rotation: r4(to.rotation + 13), scale: 1.12, opacity: 0 }; ev.push({ k, at: st.at, dur: 0.42, to: { x: to.x, y: to.y, rotation: to.rotation, scale: 1, opacity: 1 }, ease: "back.out(1.3)" }); if (n.count > 1) { init[`${k}c`] = { scale: 1.9, opacity: 0 }; ev.push({ k: `${k}c`, at: st.at + 0.3, dur: 0.32, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); } } else if (n.prev !== null && n.prev !== n.depth) { const from = notePlace(n, n.prev, px, H); init[k] = { x: from.x, y: from.y, rotation: from.rotation }; ev.push({ k, at: st.at, dur: 0.36, to: { x: to.x, y: to.y, rotation: to.rotation }, ease: "power2.out" }); } else { init[k] = { x: to.x, y: to.y, rotation: to.rotation }; } } return ev; }, }); const blocks = states.map((st, j) => { const notes = st.notes.map((n) => { const k = `s${j}.${n.id}`; const dl = cfg.countdown && n.deadline ? `
${esc(n.deadline)}${n.days !== null ? ` · ${esc(daysLeftText(n.days))}` : ""}
${n.target !== null ? `
needs ${esc(weightText(n.target))}
` : ""}` : ""; const count = n.count > 1 ? `
×${n.count}
` : ""; const shade = n.depth ? `
` : ""; const fr = n.base ? `
${esc(n.base)}
` : ""; const fl = flashing && j > 0 && n.key === st.top ? `
` : ""; return `
Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}
${esc(n.text)}
${fr}${dl}${count}${shade}${fl}
`; }).join(""); const html = `
${notes}
${st.goalsSet} goal${st.goalsSet === 1 ? "" : "s"} set
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .note { position: absolute; left: 0; top: 0; width: ${px(290)}px; height: ${px(150)}px; padding: ${px(14)}px ${px(18)}px; border-radius: ${px(3)}px; color: #2a1c06; overflow: hidden; background: linear-gradient(168deg, ${paper} 0%, ${paper} 62%, ${rgba(paper, 0.86)} 100%); box-shadow: 0 ${px(10)}px ${px(22)}px rgba(0, 0, 0, 0.45), 0 ${px(1)}px ${px(2)}px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; justify-content: center; gap: ${px(2)}px; } .tape { position: absolute; left: 50%; top: ${px(-8)}px; width: ${px(84)}px; height: ${px(24)}px; margin-left: ${px(-42)}px; background: rgba(255, 255, 255, 0.38); transform: rotate(-3deg); } .nh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(15)}px; line-height: ${px(18)}px; letter-spacing: 0.14em; 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. */ .ct { position: absolute; right: ${px(12)}px; top: ${px(6)}px; min-width: ${px(54)}px; height: ${px(30)}px; padding: 0 ${px(9)}px; border-radius: ${px(15)}px; background: #2a1c06; color: ${paper}; text-align: center; font-family: ${DISPLAY}; font-size: ${px(24)}px; line-height: ${px(30)}px; } .sh { position: absolute; inset: 0; background: #000; pointer-events: none; } .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; }${flashing ? ` ${flashCss(".note .fl", paper, { radius: `${px(5)}px`, width: Math.max(2, Math.round(px(3))), inset: `-${px(5)}px` })}` : ""}`; const body = `
${blocks.join("\n ")}
`; 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 * and ink as the pile in the footage -- fanned sideways like the diet's tags, * the newest in front landing from above (the pile's own landing), the older * ones a place to the right behind it, each showing its goal's words in the * strip beside the one in front (all of each when the slot is wide enough: * shelfLayout gives the fan the shelf's spare width). A block per state, as the * pile's: a repeat comes to the front with its count; the number of goals set * pops at each. */ function goalsShelfHtml(schedule, render, opts, cfg, states) { const F = frameOf("goals", schedule, render); const { geo, px } = F; const pal = render.palette; const paper = cfg.color ?? pal.amber ?? "#E8A33F"; const G = GOALS_SHELF; const max = cfg.max ?? 4; 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)), rotation: r4(note.rot * 0.45 + (depth ? (depth % 2 ? -1.4 : 1.2) : 0)), }); const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; // 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); if (n.key === st.top) { // The pile's landing: from above, turned, a size up -- onto the fan. init[k] = { x: to.x - px(30), y: to.y - px(140), rotation: r4(to.rotation + 13), scale: 1.12, opacity: 0 }; ev.push({ k, at: st.at, dur: 0.42, to: { x: to.x, y: to.y, rotation: to.rotation, scale: 1, opacity: 1 }, ease: "back.out(1.3)" }); } else if (n.prev !== null && n.prev !== n.depth) { const from = place(n, n.prev); init[k] = { x: from.x, y: from.y, rotation: from.rotation }; ev.push({ k, at: st.at, dur: 0.36, to: { x: to.x, y: to.y, rotation: to.rotation }, ease: "power2.out" }); // Out of the front: its whole face gives way to the strip that shows beside the new one. if (backs && n.prev === 0 && n.depth > 0) { init[`${k}f`] = { opacity: 1 }; init[`${k}b`] = { opacity: 0 }; ev.push({ k: `${k}f`, at: st.at, dur: 0.3, to: { opacity: 0 }, ease: "power1.out" }); ev.push({ k: `${k}b`, at: st.at + 0.1, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); } } else { init[k] = { x: to.x, y: to.y, rotation: to.rotation }; } } // The count pops as a goal lands; a state the board alone changed (a goal met, missed, or lapsed) keeps it still. if (st.top) { init[`s${j}.c`] = { scale: 1.6, opacity: 0 }; ev.push({ k: `s${j}.c`, at: st.at + 0.25, dur: 0.3, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); } return ev; }, }); const blocks = shelfStates.map((st, j) => { const notes = st.notes.map((n) => { const k = `s${j}.${n.id}`; const dl = cfg.countdown && n.deadline ? `
${esc(n.deadline)}${n.days !== null ? ` · ${esc(daysLeftText(n.days))}` : ""}${n.target !== null ? ` · needs ${esc(weightText(n.target))}` : ""}
` : ""; const count = n.count > 1 ? `
×${n.count}
` : ""; // The ladder: how many more goals are in force beside the headline one, when the state says. const more = n.depth === 0 && st.headline && Number.isFinite(st.active) && st.active > 1 ? `
+${st.active - 1} more
` : ""; const front = n.depth === 0 || !backs; const crossing = backs && n.prev === 0 && n.depth > 0; const fr = n.base ? `
${esc(n.base)}
` : ""; const face = `
Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}
${esc(n.text)}
${fr}${dl}
`; // 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 ? `
${esc(n.text)}
${n.base ? `
${esc(n.base)}
` : ""}${n.date ? `
${esc(monthYear(n.date))}
` : ""}
` : ""; // Missed (the board's, held as the dial holds it): struck in red, MISSED on it. const miss = st.missed?.includes(n.key) ? `
Missed
` : ""; const fl = flashKey(st, j) === `${k}.fl` ? `
` : ""; return `
${face}${back}${count}${more}${miss}${fl}
`; }).join(""); const html = `
${st.goalsSet}
goal${st.goalsSet === 1 ? "" : "s"} set
${notes}
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .gc { position: absolute; left: 0; top: 0; width: ${px(G.count)}px; height: ${px(G.height)}px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.88)}; } .gn { font-family: ${DISPLAY}; font-size: ${px(46)}px; line-height: ${px(46)}px; color: ${paper}; font-variant-numeric: tabular-nums; } .gl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(15)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.muted}; text-align: center; } .note { position: absolute; left: 0; top: 0; width: ${px(G.card)}px; height: ${px(G.height - 12)}px; border-radius: ${px(3)}px; color: #2a1c06; background: linear-gradient(168deg, ${paper} 0%, ${paper} 62%, ${rgba(paper, 0.86)} 100%); box-shadow: 0 ${px(8)}px ${px(18)}px rgba(0, 0, 0, 0.45), ${px(-4)}px 0 ${px(10)}px rgba(0, 0, 0, 0.3), 0 ${px(1)}px ${px(2)}px rgba(0, 0, 0, 0.3); } .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; 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}; 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; 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}; transform: rotate(-8deg); border-radius: ${px(2)}px; } .ms { position: absolute; left: ${px(10)}px; bottom: ${px(6)}px; padding: 0 ${px(7)}px; height: ${px(20)}px; border-radius: ${px(10)}px; background: ${MEASURE_RED}; color: #fff; font-family: 'DeckSansBold', sans-serif; font-size: ${px(12)}px; line-height: ${px(20)}px; 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; }${flashing ? ` ${flashCss(".note .fl", paper, { radius: `${px(4)}px`, width: Math.max(2, Math.round(px(3))), inset: `-${px(4)}px` })}` : ""}`; const body = `
${blocks.join("\n ")}
`; return { html: page("goals", schedule, opts, F, css, body, init, cues, shelfStates.map((_, j) => `s${j}`), render), items }; } /** * The shelf's goal states, ordered by the dial's goal board (measure-goals.mjs goalBoard / goalsAt), so the two * always agree: each of goalStates' states (one per goal he sets) and a state wherever the board alone changes * after the first (a goal met, missed or past its day; a missed one's hold ending) -- the same notes, `top` null. * Each carries `headline` (the board headline's note key, or null: the newest leads), `active` (the goals in force) * and `missed` (the note keys struck now); its notes in front-to-back order: the headline, then by recency. */ export function shelfGoalStates(schedule, states) { if (!states.length) return []; const m = schedule.measure; const board = goalBoard(m); const unit = m?.unit ?? "lb"; const keyOf = new Map((m?.events ?? []).filter((e) => e.kind === "goal" || e.kind === "goalLoss").map((e) => [e.row, goalText(e, unit).toLowerCase()])); const times = [...new Set([...states.map((st) => st.at), ...board.map((b) => r4(b.t)).filter((t) => t > states[0].at)])].sort((a, b) => a - b); let before = new Map(); return times.map((t) => { const own = states.find((st) => Math.abs(st.at - t) < 1e-6); const base = own ?? [...states].reverse().find((st) => st.at <= t); const b = goalsAt(board, t); const headline = b.headline ? keyOf.get(b.headline.row) ?? null : null; const recent = [...base.notes].sort((x, y) => x.depth - y.depth); const lead = headline ? recent.find((n) => n.key === headline) : null; const list = lead ? [lead, ...recent.filter((n) => n !== lead)] : recent; const notes = list.map((n, i) => ({ ...n, depth: i, prev: before.has(n.key) ? before.get(n.key) : null })); before = new Map(notes.map((n) => [n.key, n.depth])); return { ...base, at: t, top: own ? own.top : null, ...(own ? {} : { repeat: false }), headline: lead ? headline : null, active: b.active.length, missed: b.missed.map((g) => keyOf.get(g.row)).filter(Boolean), notes, }; }); } // --------------------------------------------------------------------------- // PEAK: the moving start. // --------------------------------------------------------------------------- /** Label rows on a scale: each wanted y, pushed apart to `gap` and kept in [top, bottom]. */ export function spreadLabels(ys, gap, top, bottom) { const order = ys.map((y, i) => ({ y, i })).sort((a, b) => a.y - b.y); const out = order.map((o) => o.y); for (let i = 1; i < out.length; i += 1) out[i] = Math.max(out[i], out[i - 1] + gap); if (out.length && out[out.length - 1] > bottom) { out[out.length - 1] = bottom; for (let i = out.length - 2; i >= 0; i -= 1) out[i] = Math.min(out[i], out[i + 1] - gap); } if (out.length && out[0] < top) { out[0] = top; for (let i = 1; i < out.length; i += 1) out[i] = Math.max(out[i], out[i - 1] + gap); } const res = new Array(ys.length); order.forEach((o, n) => { res[o.i] = out[n]; }); return res; } /** The moving start's page: `{ html, items }`. */ export function peakHtml(schedule, render, opts = {}) { const cfg = resolveMeasureExtra("peak", render); const states = peakStates(schedule, render); if (!cfg || !states.length) throw new Error("peak: the schedule's measure slice has no remembered start on camera"); const F = frameOf("peak", schedule, render); const { geo, px } = F; const pal = render.palette; const red = cfg.color ?? MEASURE_RED; const [lo, hi] = states[0].range; const top = px(96); const bottom = geo.height - px(84); const yOf = (v) => r4(bottom - ((v - lo) / (hi - lo)) * (bottom - top)); const rulerX = px(72); // The ruler: a tick a pound, a number every five. const marks = []; for (let v = Math.ceil(lo); v <= hi; v += 1) { const major = v % 5 === 0; marks.push(`
${major ? `
${v}
` : ""}`); } const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; const { init, cues } = stateCues(states, spans, { own: (st, j, init) => { const ev = []; const t = st.ticks.find((x) => x.latest); const k = `s${j}.t${String(t.value).replace(".", "_")}`; if (!st.repeat) { init[`${k}b`] = { scaleX: 0 }; init[`${k}l`] = { opacity: 0, x: px(-12) }; ev.push({ k: `${k}b`, at: st.at, dur: 0.35, to: { scaleX: 1 }, ease: "power3.out" }); ev.push({ k: `${k}l`, at: st.at + 0.15, dur: 0.3, to: { opacity: 1, x: 0 }, ease: "power2.out" }); } else { init[`${k}n`] = { scale: 1.8, opacity: 0 }; ev.push({ k: `${k}n`, at: st.at + 0.05, dur: 0.32, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); } // The drift bracket grows to its new extent. const prev = states[j - 1]; if (prev && (prev.lo !== st.lo || prev.hi !== st.hi)) { init[`s${j}.br`] = { y: r4(yOf(prev.hi) - yOf(st.hi)), height: r4(yOf(prev.lo) - yOf(prev.hi)) }; ev.push({ k: `s${j}.br`, at: st.at + 0.1, dur: 0.45, to: { y: 0, height: r4(yOf(st.lo) - yOf(st.hi)) }, ease: "power2.out" }); } return ev; }, }); const labelGap = px(30); const blocks = states.map((st, j) => { const ys = st.ticks.map((t) => yOf(t.value)); const ly = spreadLabels(ys, labelGap, top - px(8), bottom + px(8)); const ticks = st.ticks.map((t, i) => { const k = `s${j}.t${String(t.value).replace(".", "_")}`; const cls = t.latest ? " now" : ""; const lead = Math.abs(ly[i] - ys[i]) > 1 ? `` : ""; const n = t.count > 1 ? `×${t.count}` : ""; return `
${lead}
${t.approx ? "≈" : ""}${esc(weightText(t.value))}${n}
`; }).join(""); const br = st.hi > st.lo ? `
` : ""; const foot = `
${st.hi > st.lo ? `+${esc(weightText(st.drift))} lb` : `${st.ticks[0].approx ? "≈" : ""}${esc(weightText(st.lo))} lb`}
${st.hi > st.lo ? "between his tellings" : "his first telling"} · told ${st.told}×
`; const html = `
${br}${ticks}${foot}
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.88)}; border-left: ${px(5)}px solid ${pal.muted}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); } .ti { position: absolute; left: ${px(20)}px; right: ${px(16)}px; top: ${px(16)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; line-height: ${px(24)}px; letter-spacing: 0.1em; text-transform: uppercase; color: ${pal.fg}; } .ti small { display: block; margin-top: ${px(2)}px; font-family: 'DeckSans', sans-serif; font-size: ${px(16)}px; letter-spacing: 0.02em; text-transform: none; color: ${pal.muted}; white-space: nowrap; } .ru { position: absolute; left: ${rulerX}px; top: ${top}px; width: ${px(2)}px; height: ${r4(bottom - top)}px; background: ${rgba(pal.muted, 0.7)}; } .mk { position: absolute; left: ${rulerX - px(6)}px; width: ${px(6)}px; height: ${px(1)}px; background: ${rgba(pal.muted, 0.55)}; } .mk.mj { left: ${rulerX - px(12)}px; width: ${px(12)}px; height: ${px(2)}px; background: ${pal.muted}; } .ml { position: absolute; left: ${px(14)}px; width: ${px(40)}px; text-align: right; font-size: ${px(15)}px; line-height: ${px(18)}px; color: ${pal.muted}; font-variant-numeric: tabular-nums; } .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .tb { position: absolute; left: ${rulerX + px(2)}px; width: ${px(40)}px; height: ${px(4)}px; border-radius: ${px(2)}px; background: ${pal.muted}; transform-origin: 0 50%; } .tb.now { background: ${pal.fg}; box-shadow: 0 0 ${px(10)}px ${rgba(pal.fg, 0.6)}; } .ld { position: absolute; left: ${rulerX + px(42)}px; width: ${px(14)}px; overflow: visible; } .ld line { stroke: ${pal.muted}; stroke-width: ${px(1.5)}; } .tl { position: absolute; left: ${rulerX + px(58)}px; height: ${px(30)}px; white-space: nowrap; color: ${pal.muted}; display: flex; align-items: baseline; gap: ${px(6)}px; } .tl.now { color: ${pal.fg}; } .tv { font-family: ${DISPLAY}; font-size: ${px(27)}px; line-height: ${px(30)}px; font-variant-numeric: tabular-nums; } .tn { display: inline-block; font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; color: ${red}; transform-origin: 0 70%; } .br { position: absolute; left: ${px(32)}px; width: ${px(10)}px; border: ${px(3)}px solid ${red}; border-right: none; border-radius: ${px(3)}px 0 0 ${px(3)}px; } .ft { position: absolute; left: ${px(20)}px; right: ${px(14)}px; bottom: ${px(14)}px; } .fd { font-family: ${DISPLAY}; font-size: ${px(36)}px; line-height: ${px(38)}px; color: ${red}; white-space: nowrap; } .fd.one { color: ${pal.fg}; } .fs { font-size: ${px(15)}px; line-height: ${px(19)}px; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }`; const body = `
${esc(cfg.title)}what he says he started at
${marks.join("")} ${blocks.join("\n ")}
`; return { html: page("peak", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render), items }; } // --------------------------------------------------------------------------- // PROMISE: the days since. // --------------------------------------------------------------------------- /** A speaker's handle as the clock writes it: `promise.speakers[k].handle`, the manifest's postAvatars key, else the key. */ // An anonymous speaker (post-anon.mjs: `opts.anonHandles`) is its pseudonym, whatever the settings name. const handleOf = (speaker, cfg, opts) => String(opts.anonHandles?.[speaker] ?? cfg.speakers?.[speaker]?.handle ?? opts.handles?.[speaker] ?? speaker ?? "").replace(/^@/, ""); /** * The promise clock's STRIP (footage slot): while a post item is up, one line * in the post box's top margin over the card -- "SCALE VIDEO OFFERED 23 OCT · * PAID 23 OCT BY @MADAMSAVVY · 14 DAYS · NONE POSTED" -- each state's its own * line `t` (an item), shown with its state. Returns `{ html, cues, rect }`. */ function promiseStrip(states, place, cfg, render, opts, items) { const rect = promiseStripRect(render); const reg = place.region; const ev = []; const init = { ps: { autoAlpha: 0 } }; for (const sp of place.strips) ev.push(...spanEvents("ps", sp.from, sp.to, { fadeIn: 0.3, fadeOut: 0.3 })); const lines = states.map((st, j) => { const k = `t${j}`; init[k] = { autoAlpha: 0 }; ev.push({ k, at: st.at, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); if (states[j + 1]) ev.push({ k, at: states[j + 1].at, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); const r = st.rows[0]; const days = r.days === 0 ? "today" : `${r.days} day${r.days === 1 ? "" : "s"}`; const claim = r.claim ? `·${esc(cfg.claimVerb)} ${esc(shortDate(r.claim.paidOn ?? r.claim.date))} by @${esc(handleOf(r.claim.speaker, cfg, opts))}` : ""; const o = r.outcome; const status = o && o.kind !== "kept" ? `${o.kind === "refunded" ? "refunded" : "withdrawn"} · ${esc(stampNoteClause(o))}` : r.kept ? `${esc(cfg.kept)}` : `${esc(cfg.broken)}`; const html = `
${esc(r.what)} ${esc(cfg.verb)} ${esc(shortDate(r.said))}${claim}·${esc(days)}·${status}
`; items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }); const compiled = compileCues(init, ev); // Its type from the longest line's words (rev 9: 16 px did not read). const chars = Math.max(1, ...lines.map((l) => l.replace(/<[^>]+>/g, "").replace(/&[a-z#0-9]+;/gi, "x").length)); const type = promiseStripType(rect, render, chars); const html = `
${lines.join("")}
`; return { html, cues: compiled, rect, type }; } /** The promise clock's page: `{ html, items }`. `opts.avatars` = `{ : "assets/…" }`, `opts.handles` = `{ : handle }`. */ export function promiseHtml(schedule, render, opts = {}) { const cfg = resolveMeasureExtra("promise", render); const states = promiseStates(schedule, render); if (!cfg || !states.length) throw new Error("promise: the schedule's measure slice has no promise on camera"); const F = frameOf("promise", schedule, render); const { px } = F; const pal = render.palette; const red = MEASURE_RED; const green = pal.accent ?? "#22AB83"; const amber = pal.amber ?? "#E8A33F"; const inkOf = (speaker) => cfg.speakers?.[speaker]?.color ?? cfg.claimColor; const bottom = cfg.position.startsWith("bottom") && !(Number.isFinite(cfg.x) && Number.isFinite(cfg.y)); const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; // In the instruments' column the compact form; in the footage box a strip over each post item's card. const compact = cfg.slot === "column"; const place = placementsFor(schedule, render).promise; const sk = (render?.width ?? 1920) / 1920; const strip = !compact && place.strips.length ? promiseStrip(states, place, cfg, render, opts, items) : null; const { init, cues } = stateCues(states, spans, { own: (st, j, init) => { const ev = []; const prev = states[j - 1]; st.rows.forEach((r, i) => { const k = `s${j}.r${i}`; const was = prev?.rows[i]; if (was && was.days !== r.days) { init[`${k}d`] = { y: px(-14), opacity: 0.35 }; ev.push({ k: `${k}d`, at: st.at, dur: 0.18, to: { y: 0, opacity: 1 }, ease: "power2.out" }); } if (r.fresh && r.word) { init[`${k}f`] = { opacity: 0.9 }; init[`${k}q`] = { x: px(18), opacity: 0 }; ev.push({ k: `${k}q`, at: st.at, dur: 0.3, to: { x: 0, opacity: 1 }, ease: "power2.out" }); ev.push({ k: `${k}f`, at: st.at + 0.15, dur: 1.4, to: { opacity: 0 }, ease: "power1.in" }); } if (r.claim && !was?.claim) { init[`${k}c`] = { opacity: 0, x: px(-14) }; ev.push({ k: `${k}c`, at: st.at, dur: 0.35, to: { opacity: 1, x: 0 }, ease: "power2.out" }); } // An outcome that is not "kept" slams on as a stamp. if (r.outcome && r.outcome.kind !== "kept" && was?.outcome?.kind !== r.outcome.kind) { init[`${k}o`] = { scale: 2, rotation: -12, opacity: 0 }; ev.push({ k: `${k}o`, at: st.at, dur: 0.16, to: { scale: 1, rotation: -4, opacity: 1 }, ease: "power4.in" }); } }); return ev; }, }); const blocks = states.map((st, j) => { const rows = st.rows.map((r, i) => { const k = `s${j}.r${i}`; const days = r.days === 0 ? "Today" : `${r.days} day${r.days === 1 ? "" : "s"}`; let claim = ""; if (r.claim) { const h = handleOf(r.claim.speaker, cfg, opts); const ink = inkOf(r.claim.speaker); const av = opts.avatars?.[r.claim.speaker] ? `` : `${esc((h[0] ?? "?").toUpperCase())}`; const when = r.claim.paidOn ?? r.claim.date; claim = `
${av}${esc(cfg.claimVerb)}${when ? ` ${esc(shortDate(when))}` : ""} by @${esc(h)}
`; } let status; const o = r.outcome; if (o && o.kind !== "kept") { const word = o.kind === "refunded" ? "Refunded" : "Withdrawn"; status = `
${word}
${esc(stampNoteLine(o))}
`; } else status = `
${esc(r.kept ? cfg.kept : cfg.broken)}
`; let q; if (r.word) { const hers = !r.word.his && r.word.speaker; const ink = hers ? inkOf(r.word.speaker) : amber; // An outcome's words are what she reports (his refund email): "reads", not "says". const who = hers ? `@${esc(handleOf(r.word.speaker, cfg, opts))}${r.word.outcome ? " reads" : ""} ` : ""; q = `
${who}“${esc(r.word.text.replace(/^["“”]+|["“”]+$/g, ""))}”${r.word.date ? ` · ${esc(shortDate(r.word.date))}` : ""}
`; } else q = `
no word on it since
`; if (compact) { // The column's compact form (600×138): the promise and her claim on one line, the days and the status on // the next, the latest words under them on one. const cl = r.claim ? ` · ${esc(cfg.claimVerb)}${(r.claim.paidOn ?? r.claim.date) ? ` ${esc(shortDate(r.claim.paidOn ?? r.claim.date))}` : ""} by @${esc(handleOf(r.claim.speaker, cfg, opts))}` : ""; return `
${esc(r.what)} · ${esc(cfg.verb)} ${esc(shortDate(r.said))}${cl}
${esc(days)}
as of ${esc(shortDate(r.to))}
${status}
${q}
`; } return `
${esc(r.what)} ${esc(cfg.verb)} ${esc(shortDate(r.said))}
${claim}
${esc(days)}
as of
${esc(shortDate(r.to))}
${status}
${q}
`; }).join(""); const r0 = st.rows[0]; const cls = r0?.kept ? " kept" : r0?.outcome ? ` ${r0.outcome.kind}` : ""; const html = `
${rows}
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); const compactCss = !compact ? "" : ` .st { top: 0; bottom: 0; padding: ${px(10)}px ${px(16)}px ${px(8)}px ${px(16)}px; border-left-width: ${px(5)}px; } .row { gap: ${px(2)}px; } .hd { font-size: ${px(16)}px; line-height: ${px(20)}px; letter-spacing: 0.08em; } .hd b { letter-spacing: 0.02em; text-transform: none; } .mid { height: ${px(54)}px; gap: ${px(12)}px; } .dy { font-size: ${px(50)}px; line-height: ${px(54)}px; } .to { flex: 1 1 auto; align-self: center; padding-bottom: 0; font-size: ${px(14)}px; } .pill { height: ${px(32)}px; line-height: ${px(32)}px; font-size: ${px(17)}px; padding: 0 ${px(12)}px; } .stamp { padding: ${px(1)}px ${px(10)}px ${px(2)}px; border-width: ${px(3)}px; transform: rotate(-3deg); } .sw { font-size: ${px(24)}px; line-height: ${px(26)}px; } .ss { font-size: ${px(12)}px; line-height: ${px(14)}px; } .ck { font-size: ${px(16)}px; line-height: ${px(21)}px; -webkit-line-clamp: 1; display: block; white-space: nowrap; text-overflow: ellipsis; }`; const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } /* The card is as tall as what it says, hung from its anchor's edge. */ .st { position: absolute; left: 0; right: 0; ${bottom ? "bottom: 0;" : "top: 0;"} visibility: hidden; opacity: 0; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.95)}; border-left: ${px(6)}px solid ${red}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.45); padding: ${px(14)}px ${px(22)}px ${px(12)}px ${px(22)}px; } .st.kept { border-left-color: ${green}; } .row { display: flex; flex-direction: column; gap: ${px(4)}px; } .hd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(21)}px; line-height: ${px(26)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .cl { display: flex; align-items: center; gap: ${px(10)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; line-height: ${px(30)}px; letter-spacing: 0.1em; text-transform: uppercase; color: ${pal.fg}; white-space: nowrap; } .cl b { letter-spacing: 0.02em; text-transform: none; font-size: ${px(21)}px; } .av { flex: none; width: ${px(30)}px; height: ${px(30)}px; border-radius: 50%; object-fit: cover; } .av.mono { display: inline-block; text-align: center; color: #fff; font-family: ${DISPLAY}; font-size: ${px(20)}px; line-height: ${px(30)}px; letter-spacing: 0; } .mid { display: flex; align-items: center; justify-content: space-between; gap: ${px(16)}px; height: ${px(78)}px; } .dy { font-family: ${DISPLAY}; font-size: ${px(74)}px; line-height: ${px(78)}px; color: ${pal.fg}; text-transform: uppercase; white-space: nowrap; font-variant-numeric: tabular-nums; } .to { flex: 1 1 auto; align-self: flex-end; padding-bottom: ${px(14)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(16)}px; line-height: ${px(19)}px; letter-spacing: 0.1em; text-transform: uppercase; color: ${pal.muted}; white-space: nowrap; } .pill { flex: none; padding: 0 ${px(16)}px; height: ${px(42)}px; border-radius: ${px(6)}px; background: ${red}; color: #fff; font-family: 'DeckSansBold', sans-serif; font-size: ${px(23)}px; line-height: ${px(42)}px; letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; } .kept .pill { background: ${green}; } .stamp { flex: none; padding: ${px(2)}px ${px(14)}px ${px(4)}px; border: ${px(4)}px solid ${red}; border-radius: ${px(6)}px; color: ${red}; text-align: center; transform: rotate(-4deg); } .stamp.withdrawn { border-color: ${pal.muted}; color: ${pal.muted}; } .sw { font-family: ${DISPLAY}; font-size: ${px(34)}px; line-height: ${px(36)}px; text-transform: uppercase; letter-spacing: 0.04em; } .ss { font-family: 'DeckSansBold', sans-serif; font-size: ${px(15)}px; line-height: ${px(18)}px; text-transform: uppercase; letter-spacing: 0.1em; white-space: nowrap; } .ck { position: relative; font-size: ${px(20)}px; line-height: ${px(25)}px; color: ${pal.fg}; padding: ${px(2)}px ${px(6)}px; margin-left: ${px(-6)}px; border-radius: ${px(4)}px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } .ck.none { color: ${pal.muted}; } .cf { position: absolute; inset: 0; opacity: 0; border-radius: ${px(4)}px; z-index: -1; } .ck { isolation: isolate; } .who { font-family: 'DeckSansBold', sans-serif; } .qm { font-family: 'DeckSansBold', sans-serif; } .cd { color: ${pal.muted}; white-space: nowrap; }${compactCss} #ps { position: absolute; visibility: hidden; opacity: 0; } .sl { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; align-items: center; justify-content: center; gap: ${Math.round(sk * 10)}px; white-space: nowrap; overflow: hidden; font-family: 'DeckSansBold', sans-serif; font-size: ${strip ? strip.type.size : 12}px; line-height: 1; letter-spacing: 0.08em; text-transform: uppercase; color: ${pal.muted}; }${strip?.type.lines === 2 ? ` .sl { flex-wrap: wrap; align-content: center; row-gap: 0; white-space: normal; } .sl > * { white-space: nowrap; }` : ""} .sl b { color: ${pal.fg}; font-family: ${DISPLAY}; font-weight: 400; letter-spacing: 0.04em; } .sl .no { color: ${red}; } .sl .ok { color: ${green}; } .sl .sp { color: ${pal.muted}; opacity: 0.6; }`; const body = `
${blocks.join("\n ")}
`; return { html: page("promise", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render, strip ? { outside: strip.html, extra: strip.cues } : {}), items }; } // --------------------------------------------------------------------------- // DIET: the stamp. // --------------------------------------------------------------------------- /** The stamp's words a size that fits its box: the condensed face at ~0.5 em a letter. */ export function stampSize(label, room) { const n = Math.max(1, [...String(label)].length); return Math.max(30, Math.min(76, Math.floor(room / (0.52 * n)))); } // An ink texture: fractal noise as the stamp's alpha, so it reads pressed, not printed. const INK = "url(\"data:image/svg+xml;utf8,\")"; /** The diet badge's page: `{ html, items }` -- the stamp, or (`form: "tags"`) the row of dated tags. */ export function dietHtml(schedule, render, opts = {}) { const cfg = resolveMeasureExtra("diet", render); const states = dietStates(schedule, render); if (!cfg || !states.length) throw new Error("diet: the schedule's measure slice has no diet on camera"); if (cfg.form === "tags") return dietTagsHtml(schedule, render, opts, cfg, states); const F = frameOf("diet", schedule, render); const { geo, px } = F; const pal = render.palette; const SLAM = 0.16; const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; const { init, cues } = stateCues(states, spans, { overlap: SLAM, own: (st, j, init) => { const k = `s${j}.s`; const ev = []; if (!st.diet) { init[k] = { opacity: 0 }; ev.push({ k, at: st.at, dur: 0.5, to: { opacity: 0.6 }, ease: "power1.out" }); } else if (st.slam) { // The slam: in from big and turned, hard onto the page, then a shake. init[k] = { scale: 2.3, rotation: -15, opacity: 0 }; ev.push({ k, at: st.at, dur: SLAM, to: { scale: 1, rotation: -5, opacity: 1 }, ease: "power4.in" }); init[`s${j}.w`] = { x: 0 }; const shake = [8, -6, 4, -2, 0].map((v) => Math.round(v * F.k)); shake.forEach((x, n) => ev.push({ k: `s${j}.w`, at: st.at + SLAM + n * 0.045, dur: 0.045, to: { x }, ease: "sine.inOut" })); } else { init[k] = { opacity: 0 }; ev.push({ k, at: st.at, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); } return ev; }, }); // The words' room in design pixels (the box less the stamp's border and padding). const room = MEASURE_BOXES.diet.width - 110; const blocks = states.map((st, j) => { const d = st.diet; const label = d ? d.label : cfg.labels.off ?? "No diet"; const ink = d ? d.color : pal.muted; const size = stampSize(label, room); const sub = d ? `
Diet${d.n !== null ? ` #${d.n}` : ""}${d.detail ? `${esc(d.detail)}` : ""}
` : `
he says he is on none
`; const html = `
${esc(label)}
${sub}
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; align-items: center; justify-content: center; } .wr { display: flex; align-items: center; justify-content: center; } /* The plate is solid (it has to read over any footage); only the ink is pressed. */ .sp { max-width: ${geo.width - px(40)}px; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.93)}; padding: ${px(6)}px; box-shadow: 0 ${px(8)}px ${px(22)}px rgba(0, 0, 0, 0.5); transform: rotate(-5deg); } .ink { padding: ${px(6)}px ${px(22)}px ${px(10)}px ${px(22)}px; border: ${px(6)}px solid; border-radius: ${px(7)}px; box-shadow: inset 0 0 0 ${px(3)}px ${rgba(pal.bg, 0.9)}, inset 0 0 0 ${px(5)}px currentColor; display: flex; flex-direction: column; align-items: center; -webkit-mask-image: ${INK}; mask-image: ${INK}; -webkit-mask-size: ${px(240)}px ${px(120)}px; mask-size: ${px(240)}px ${px(120)}px; } .lb { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; } .sb { display: flex; align-items: baseline; gap: ${px(12)}px; margin-top: ${px(2)}px; white-space: nowrap; max-width: 100%; } .dn { font-family: 'DeckSansBold', sans-serif; font-size: ${px(22)}px; letter-spacing: 0.16em; text-transform: uppercase; } .dd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(20)}px; color: ${pal.fg}; overflow: hidden; text-overflow: ellipsis; } .off .dd { color: ${pal.muted}; }`; const body = `
${blocks.join("\n ")}
`; return { html: page("diet", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`), render), items }; } /** * A tag's regime word a size that fits its width (`room`, design px: the tag * less its plate, border and padding): the condensed extra-bold face set in * capitals and spaced, at ~0.62 em a letter ("CARNIVORE" 31 px, "KETO" 44). */ export function tagWordSize(label, room = DIET_TAG.width - 44) { const n = Math.max(1, [...String(label)].length); return Math.max(16, Math.min(44, Math.floor(room / (0.62 * n)))); } /** * A tag's words without the regime they open with: the tag already says it in * its ink, so "Keto · 5 carbs a day" is "5 carbs a day" (and fits) -- only * where a separator follows it ("Keto + IF + walking" stays whole). Words * that are only the regime are none. */ export function tagWords(detail, names) { let w = String(detail ?? "").trim(); for (const name of names) { const n = String(name ?? "").trim(); if (!n) continue; const re = new RegExp(`^${n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:\\s*[·:,;–—-]\\s*|$)`, "i"); if (re.test(w)) { w = w.replace(re, "").trim(); break; } } return w; } /** * The diet as a row of DATED TAGS (`diet.form: "tags"`, the shelf's default): * the last `tags` diets (dietStates' `tags`, newest first), each a small stamp * -- the regime's word in its ink, "DIET #n" and the ledger's words when they * say more, and the day he named it ("Mar 14, 2025", formatDeckDate). At a * change of diet the new tag slams in at the left with the stamp's motion (in * big and turned, a shake), the older ones slide right a place and dim, and the * one past `tags` slides off and fades; a change of words alone fades the new * tag in over the old; "No diet" is a grey tag with its date. */ function dietTagsHtml(schedule, render, opts, cfg, states) { const F = frameOf("diet", schedule, render); const { px } = F; const pal = render.palette; const SLAM = 0.16; const SLIDE = 0.4; const DIM = 0.45; const n = cfg.tags ?? 3; const daysOn = cfg.days === true; const W = dietTagWidth(daysOn); const overlap = cfg.overlap ?? 0; // FANNED (`overlap` > 0): the goal stack's look turned on its side -- each tag its own small turn and drop, // the depth's tilt, the stack's shadow; the newest lands on top from above (the goal note's landing), the // older ones slide a place right behind it and show their regime word and date in the strip beside it. They // keep their colours: the depth is the overlap and the shadow. Side by side (0): the row, the slam and the dim. const fan = overlap > 0; const step = dietTagStep(overlap, daysOn); const slotX = (i) => px(i * step); const rotOf = (id, i) => (fan ? r4(jitter(`diet${id}`) * 1.8 + (i ? (i % 2 ? -1.6 : 1.3) : 0)) : 0); const yOf = (id, i) => (fan ? Math.round(px(2) + jitter(`diet${id}`, 7) * px(2) + (i ? px(1) : 0)) : 0); const spans = upSpans(states.map((s) => s.at), cfg, schedule); const init = { pn: { autoAlpha: 0 } }; const ev = []; for (const sp of spans) ev.push(...spanEvents("pn", sp.in, sp.out, { fadeIn: MEASURE_FADE.in, fadeOut: MEASURE_FADE.out })); // Every tag once, by its id: what it shows, and the first state it is in (how it comes in). const tags = new Map(); states.forEach((st) => { for (const t of st.tags) if (!tags.has(t.id)) tags.set(t.id, t); }); for (const id of tags.keys()) { const k = `t${id}`; init[k] = { x: 0, y: yOf(id, 0), rotation: rotOf(id, 0), scale: 1, autoAlpha: 0 }; init[`${k}.d`] = { opacity: 1 }; init[`${k}.w`] = { x: 0 }; init[`${k}.s`] = { scale: 1, rotation: fan ? 0 : -3, opacity: 1 }; if (fan) { init[`${k}.f`] = { opacity: 1 }; init[`${k}.b`] = { opacity: 0 }; } } states.forEach((st, j) => { const prev = j ? states[j - 1].tags.map((t) => t.id) : []; const cur = st.tags.map((t) => t.id); const at = st.at; const front = cur[0]; if (!prev.includes(front)) { const k = `t${front}`; if (fan && !st.replaced && st.diet) { // The goal note's landing: from above, turned, a size up -- onto the stack. init[k] = { x: -px(30), y: yOf(front, 0) - px(140), rotation: r4(rotOf(front, 0) + 13), scale: 1.12, autoAlpha: 0 }; ev.push({ k, at, dur: 0.42, to: { x: 0, y: yOf(front, 0), rotation: rotOf(front, 0), scale: 1, autoAlpha: 1 }, ease: "back.out(1.3)" }); } else { ev.push({ k, at, dur: INSTANT, to: { x: 0, autoAlpha: 1 }, ease: "none" }); if (st.slam && !fan) { // The slam: in from big and turned, hard onto the shelf, then a shake. init[`${k}.s`] = { scale: 2.3, rotation: -15, opacity: 0 }; ev.push({ k: `${k}.s`, at, dur: SLAM, to: { scale: 1, rotation: -3, opacity: 1 }, ease: "power4.in" }); [8, -6, 4, -2, 0].map((v) => Math.round(v * F.k)).forEach((x, m) => ev.push({ k: `${k}.w`, at: at + SLAM + m * 0.045, dur: 0.045, to: { x }, ease: "sine.inOut" })); } else { init[`${k}.s`] = { scale: 1, rotation: fan ? 0 : -3, opacity: 0 }; ev.push({ k: `${k}.s`, at, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); } } } // The older ones a place to the right: dimmed in the row; in the fan, behind the new one, its strip showing. cur.forEach((id, i) => { const p = prev.indexOf(id); if (p < 0 || p === i) return; if (fan) { ev.push({ k: `t${id}`, at, dur: 0.36, to: { x: slotX(i), y: yOf(id, i), rotation: rotOf(id, i) }, ease: "power2.out" }); if (p === 0) { ev.push({ k: `t${id}.f`, at, dur: 0.3, to: { opacity: 0 }, ease: "power1.out" }); ev.push({ k: `t${id}.b`, at: at + 0.1, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); } } else { ev.push({ k: `t${id}`, at, dur: SLIDE, to: { x: slotX(i) }, ease: "power2.inOut" }); ev.push({ k: `t${id}.d`, at, dur: SLIDE, to: { opacity: i === 0 ? 1 : DIM }, ease: "power1.out" }); } }); // Off the row: the one replaced by new words fades where it stands; the one past `tags` slides off. for (const id of prev) { if (cur.includes(id)) continue; if (st.replaced && id === prev[0]) ev.push({ k: `t${id}`, at, dur: 0.25, to: { autoAlpha: 0 }, ease: "power1.in" }); else ev.push({ k: `t${id}`, at, dur: SLIDE, to: { x: slotX(n), autoAlpha: 0 }, ease: "power2.in" }); } }); // THE RUNNING DAY COUNT (`days`): on the front tag, the days on its diet to the in-record date at the playhead // (dietDays), a number per stretch it holds -- cut wherever the count or the front tag changes. const dayBlocks = new Map(); if (daysOn) { const counts = dietDays(schedule, render); const cuts = [...new Set([...counts.map((c) => c.at), ...states.map((s) => s.at)])].sort((a, b) => a - b); const end = Number(schedule.total) || 0; const valueAt = (list, t) => { let v = null; for (const x of list) { if (x.at <= t + 1e-6) v = x; else break; } return v; }; const runs = []; cuts.forEach((t, i) => { const st = valueAt(states, t); const c = valueAt(counts, t); const card = st?.diet && c && c.days !== null ? st.tags[0].id : null; const days = card === null ? null : c.days; const last = runs[runs.length - 1]; const to = cuts[i + 1] ?? end; if (last && last.card === card && last.days === days) { last.to = to; return; } runs.push({ from: t, to, card, days }); }); runs.filter((r) => r.card !== null).forEach((r, m) => { const k = `t${r.card}.y${m}`; init[k] = { autoAlpha: 0 }; ev.push({ k, at: r.from, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); if (r.to < end - 1e-6) ev.push({ k, at: r.to, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); if (!dayBlocks.has(r.card)) dayBlocks.set(r.card, []); dayBlocks.get(r.card).push(`
${r.days}
day${r.days === 1 ? "" : "s"}
`); }); } // 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; const blocks = [...tags.values()].map((t) => { const k = `t${t.id}`; const d = t.diet; const label = d ? d.label : cfg.labels.off ?? "No diet"; const ink = d ? d.color : pal.muted; const size = tagWordSize(label, room); const date = t.since ? formatDeckDate(t.since) : ""; const words = d ? tagWords(d.detail, [d.label, d.regime]) : ""; const sub = d ? `
Diet${d.n !== null ? ` #${d.n}` : ""}${words ? `${esc(words)}` : ""}
` : `
he says he is on none
`; const faceBody = `
${esc(label)}
${sub}` + `${date ? `
${esc(date)}
` : ""}`; const face = daysOn ? `
${faceBody}
${(dayBlocks.get(t.id) ?? []).join("")}
` : faceBody; // The strip an older tag shows beside the one in front of it: its regime word and its date. const back = fan ? `
${esc(label)}
${date ? `
${esc(date)}
` : ""}
` : ""; const html = `
` + `
${face}
${back}
` + `${flashed.has(t.id) ? `
` : ""}
`; 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; }${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; box-shadow: ${fan ? `0 ${px(8)}px ${px(18)}px rgba(0, 0, 0, 0.5), ${px(-4)}px 0 ${px(10)}px rgba(0, 0, 0, 0.35)` : `0 ${px(6)}px ${px(16)}px rgba(0, 0, 0, 0.45)`}; } .ink { position: relative; height: 100%; padding: ${px(3)}px ${px(10)}px ${px(4)}px; border: ${px(4)}px solid; border-radius: ${px(6)}px; box-shadow: inset 0 0 0 ${px(2)}px ${rgba(pal.bg, 0.9)}, inset 0 0 0 ${px(3)}px currentColor; overflow: hidden; -webkit-mask-image: ${INK}; mask-image: ${INK}; -webkit-mask-size: ${px(240)}px ${px(120)}px; mask-size: ${px(240)}px ${px(120)}px; } .fr { height: 100%; display: flex; ${daysOn ? "flex-direction: row; align-items: stretch;" : "flex-direction: column; align-items: center; justify-content: center;"} } .fc { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; } .dc { position: relative; flex: none; width: ${px(76)}px; margin-left: ${px(6)}px; border-left: ${px(2)}px solid ${rgba(pal.fg, 0.18)}; } .dy { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; } .dyn { font-family: ${DISPLAY}; font-size: ${px(40)}px; line-height: ${px(40)}px; font-variant-numeric: tabular-nums; } .dyl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(13)}px; line-height: ${px(16)}px; letter-spacing: 0.16em; text-transform: uppercase; color: ${pal.fg}; } .bk { position: absolute; right: 0; top: 0; bottom: 0; width: ${px(step - 20)}px; display: flex; flex-direction: column; align-items: center; justify-content: center; } .bl { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; line-height: 1.05; } .bd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(14)}px; line-height: ${px(18)}px; color: ${pal.fg}; white-space: nowrap; font-variant-numeric: tabular-nums; } .lb { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; } .sb { display: flex; align-items: baseline; justify-content: center; gap: ${px(8)}px; white-space: nowrap; max-width: 100%; } .dn { flex: none; font-family: 'DeckSansBold', sans-serif; font-size: ${px(14)}px; line-height: ${px(18)}px; letter-spacing: 0.14em; text-transform: uppercase; } .dd { min-width: 0; font-family: 'DeckSansBold', sans-serif; font-size: ${px(14)}px; line-height: ${px(18)}px; color: ${pal.fg}; overflow: hidden; text-overflow: ellipsis; } .off .dd { color: ${pal.muted}; } .dt { margin-top: ${px(2)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(17)}px; line-height: ${px(21)}px; color: ${pal.fg}; letter-spacing: 0.02em; white-space: nowrap; font-variant-numeric: tabular-nums; }`; const body = `
${blocks.join("\n ")}
`; return { html: page("diet", schedule, opts, F, css, body, init, cues, items.map((i) => i.key), render), items }; } // --------------------------------------------------------------------------- // STREAK: the chains. // --------------------------------------------------------------------------- /** Each source's own word over the readout when `title` is not set. */ const STREAK_TITLES = Object.freeze({ diet: "Diet runs", lostRuns: "Weight-loss runs", pledges: "Dry streaks" }); /** * The streak chain's page: `{ html, items }`. Past chains are items of their * own (each up from its crack on, dimmed); the live chain and the readout are * a block per state. */ export function streakHtml(schedule, render, opts = {}) { const cfg = resolveMeasureExtra("streak", render); const { runs, states, span } = streakStates(schedule, render); if (!cfg || !states.length) throw new Error("streak: the schedule's measure slice has no run on camera"); const F = frameOf("streak", schedule, render); const { px } = F; const pal = render.palette; const red = MEASURE_RED; const X0 = px(196); const X1 = F.geo.width - px(18); const barY = px(66); const barH = px(16); // Where a run's chain stands: to scale on the dates, or each in its own slot (√ of its length). const total = Math.max(1, daysBetween(span[0], span[1]) ?? 1); const xOfDate = (d) => r4(X0 + ((daysBetween(span[0], d) ?? 0) / total) * (X1 - X0)); let slots = null; if (cfg.axis === "runs") { const gap = px(3); const ws = runs.map((r) => Math.sqrt(r.days + 1)); const k = (X1 - X0 - gap * (runs.length - 1)) / ws.reduce((a, b) => a + b, 0); let x = X0; slots = ws.map((w) => { const s = { x: r4(x), w: r4(Math.max(px(2), w * k)) }; x += w * k + gap; return s; }); } const left = (i) => (slots ? slots[i].x : xOfDate(runs[i].start)); const widthAt = (i, days) => { if (slots) return r4(Math.max(px(3), slots[i].w * Math.sqrt(days + 1) / Math.sqrt(runs[i].days + 1))); return r4(Math.max(px(3), (days / total) * (X1 - X0))); }; const spans = upSpans(states.map((s) => s.at), cfg, schedule); const items = []; const init = {}; const extra = []; // The past chains: each up from its crack, the tip snapping off, its length // tagged until the next crack, then dimmed into the row. const cracks = runs.map((r, i) => ({ i, t: r.endT })).filter((c) => c.t !== null).sort((a, b) => a.t - b.t); const chains = runs.map((r, i) => { if (r.endT === null) return ""; const k = `c${i}`; const w = widthAt(i, r.days); const next = cracks.find((c) => c.t > r.endT + 1e-6); init[k] = { autoAlpha: 0 }; init[`${k}.b`] = { opacity: 1 }; init[`${k}.tip`] = { x: 0, y: 0, rotation: 0, opacity: 1 }; init[`${k}.l`] = { opacity: 0, scale: 1.5 }; init[`${k}.z`] = { opacity: 0 }; init[`${k}.lf`] = { opacity: 0.95 }; extra.push({ k, at: r.endT, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); extra.push({ k: `${k}.tip`, at: r.endT, dur: 0.5, to: { x: px(16), y: px(14), rotation: 38, opacity: 0 }, ease: "power2.in" }); extra.push({ k: `${k}.l`, at: r.endT, dur: 0.3, to: { opacity: 1, scale: 1 }, ease: "back.out(2)" }); extra.push({ k: `${k}.z`, at: r.endT, dur: 0.12, to: { opacity: 1 }, ease: "power1.out" }); extra.push({ k: `${k}.lf`, at: r.endT + 0.2, dur: 1, to: { opacity: 0 }, ease: "power1.in" }); extra.push({ k: `${k}.b`, at: r.endT + 0.6, dur: 0.8, to: { opacity: 0.36 }, ease: "power1.out" }); // The break and the tag stay until the next crack takes over. if (next) { extra.push({ k: `${k}.l`, at: Math.max(r.endT + 0.35, next.t), dur: INSTANT, to: { opacity: 0 }, ease: "none" }); extra.push({ k: `${k}.z`, at: Math.max(r.endT + 0.15, next.t), dur: INSTANT, to: { opacity: 0 }, ease: "none" }); } const word = r.days === 0 && r.zeroWord ? r.zeroWord : r.ended === "lapse" ? `after ${daysText(r.days)}` : daysText(r.days); const lx = Math.max(X0, Math.min(X1 - px(240), left(i) + w - px(120))); const html = `
${esc(r.name)} · ${esc(word)}
`; items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }).join(""); const compiled = stateCues(states, spans, { own: (st, j, init2) => { const ev = []; if (!st.live) return ev; const prev = states[j - 1]; const k = `s${j}.lv`; const w = widthAt(st.live.i, st.live.days); const from = prev?.live?.i === st.live.i ? widthAt(st.live.i, prev.live.days) : px(3); if (from !== w) { init2[k] = { width: from }; ev.push({ k, at: st.at, dur: 0.4, to: { width: w }, ease: "power2.out" }); } return ev; }, }, init); const allCues = compileCues(compiled.init, [...compiled.cues.map(({ from: _f, ...c }) => c), ...extra]); const blocks = states.map((st, j) => { let readout; let live = ""; if (st.live) { const r = runs[st.live.i]; live = `
`; // A long name ("Counting calories") a size down to fit the readout's width. const ns = Math.max(18, Math.min(32, Math.floor(166 / (0.5 * Math.max(1, [...r.name].length))))); readout = `
${esc(r.name)}
Day ${st.live.days}
${r.detail ? `
${esc(r.detail)}
` : ""}`; } else { const last = [...runs.keys()].filter((i) => runs[i].endT !== null && runs[i].endT <= st.at + 1e-6).pop(); const r = last !== undefined ? runs[last] : null; readout = r ? `
Snapped
${esc(r.name)}
after ${esc(daysText(r.days))}
` : `
—
`; } const html = `
${readout}
${live}
`; items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); return html; }); // The axis: the years, when the chains stand on the dates. const years = []; if (!slots) { const y0 = Number(span[0].slice(0, 4)); const y1 = Number(span[1].slice(0, 4)); const every = y1 - y0 > 8 ? 2 : 1; for (let y = y0 + 1; y <= y1; y += 1) { const x = xOfDate(`${y}-01-01`); years.push(`
${(y - y0) % every === 0 ? `
${y}
` : ""}`); } } const title = cfg.title ?? STREAK_TITLES[cfg.source]; const css = ` #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.9)}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.45); } .ti { position: absolute; left: ${px(18)}px; top: ${px(12)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(15)}px; letter-spacing: 0.14em; text-transform: uppercase; color: ${pal.muted}; white-space: nowrap; } .ax { position: absolute; left: ${X0}px; width: ${r4(X1 - X0)}px; top: ${barY + barH + px(10)}px; height: ${px(2)}px; background: ${rgba(pal.muted, 0.45)}; } .yt { position: absolute; top: ${barY + barH + px(6)}px; width: ${px(1)}px; height: ${px(10)}px; background: ${rgba(pal.muted, 0.6)}; } .yl { position: absolute; top: ${barY + barH + px(18)}px; width: ${px(40)}px; text-align: center; font-size: ${px(14)}px; color: ${pal.muted}; font-variant-numeric: tabular-nums; } .ch, .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } /* A chain: links of the run's colour, a gap every few pixels. */ .bar { position: absolute; top: ${barY}px; height: ${barH}px; border-radius: ${px(4)}px; background: repeating-linear-gradient(90deg, var(--c) 0 ${px(6)}px, transparent ${px(6)}px ${px(8)}px); } .bar.live { box-shadow: 0 0 ${px(10)}px var(--c); } .tip { position: absolute; top: ${barY}px; width: ${px(6)}px; height: ${barH}px; border-radius: ${px(2)}px; background: var(--c); } .zz { position: absolute; top: ${barY - px(4)}px; width: ${px(6)}px; height: ${barH + px(8)}px; background: linear-gradient(115deg, transparent 40%, ${red} 40% 60%, transparent 60%); } .tf { position: absolute; inset: 0; border-radius: ${px(4)}px; background: ${rgba(red, 0.75)}; z-index: -1; } .tag { position: absolute; top: ${px(36)}px; width: ${px(240)}px; isolation: isolate; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: ${px(16)}px; line-height: ${px(22)}px; color: ${pal.fg}; transform-origin: 50% 100%; } .tag b { font-family: 'DeckSansBold', sans-serif; text-transform: uppercase; letter-spacing: 0.06em; } .ro { position: absolute; left: ${px(18)}px; top: ${px(34)}px; width: ${px(166)}px; } .nm { font-family: ${DISPLAY}; font-size: ${px(32)}px; line-height: ${px(36)}px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .nm.sn { color: ${red}; } .dy { font-family: ${DISPLAY}; font-size: ${px(30)}px; line-height: ${px(34)}px; color: ${pal.fg}; text-transform: uppercase; white-space: nowrap; font-variant-numeric: tabular-nums; } .dy.sm { font-size: ${px(22)}px; line-height: ${px(28)}px; overflow: hidden; text-overflow: ellipsis; } .dt { font-size: ${px(15)}px; line-height: ${px(19)}px; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }`; const body = `
${esc(title)}
${slots ? "" : `
${years.join("")}`} ${chains} ${blocks.join("\n ")}
`; return { html: page("streak", schedule, opts, F, css, body, allCues.init, allCues.cues, states.map((_, j) => `s${j}`), render), items }; }