// THE SHELF'S OWN PAGE (module `shelf`, region `shelf`): the note an entry puts // on the shelf (`entry.shelfNote`, deck.mjs entryShelfNotes -> schedule.shelf.notes), // a short chip in the note's slot (measure-extras.mjs shelfLayout) that comes in // and goes with its entry. The shelf's other occupants -- the diet's tags, the // streak chain, a goal stack -- are their own modules' pages, laid in their own // slots of it; this page draws only the notes, so a video with no measure slice // has a use for the shelf too. // // PURE: a schedule and a render block in, `{ html, items }` out. A cue page // (chrome-cues.mjs) over the whole cut: each note an item gated by its own // autoAlpha, so a frame keys only the note it shows. import { rgba } from "./chrome-deck.mjs"; import { compileCues, cuePageHtml, esc, spanEvents } from "./chrome-cues.mjs"; import { shelfLayout } from "./measure-extras.mjs"; import { resolveShelf } from "./modules/shelf-settings.mjs"; /** How a note comes in and goes, s. */ export const SHELF_NOTE_FADE = Object.freeze({ in: 0.35, out: 0.3 }); /** The schedule's shelf notes, `[{ segment, from, to, text }]` (none without the shelf). */ export function shelfNotes(schedule, render) { if (!resolveShelf(render)) return []; const notes = schedule?.shelf?.notes; return Array.isArray(notes) ? notes.filter((n) => Number.isFinite(n?.from) && Number.isFinite(n?.to) && n.to > n.from && typeof n.text === "string" && n.text) : []; } /** The note's slot on the shelf, or null (no shelf, `items` without "note", or too little width left). */ export function shelfNoteGeometry(render) { const slot = shelfLayout(render)?.slots.note; return slot ? { ...slot } : null; } /** Does the cut draw the shelf's page: the shelf on, a slot for the note, and a note to show. */ export const shelfOn = (schedule, render) => !!shelfNoteGeometry(render) && shelfNotes(schedule, render).length > 0; /** The shelf's page: `{ html, items }`. */ export function shelfHtml(schedule, render, opts = {}) { const geo = shelfNoteGeometry(render); const notes = shelfNotes(schedule, render); if (!geo || !notes.length) throw new Error("shelf: no note for the shelf (render.chrome.deck.shelf with \"note\" in its items, and an entry's shelfNote)"); const pal = render.palette; const k = (render.width ?? 1920) / 1920; const px = (v) => Math.max(1, Math.round(v * k)); // Two lines of words at most, in the slot's height less its padding. const size = Math.max(12, Math.round(Math.min(24 * k, (geo.height - px(20)) / 2.5))); const init = {}; const ev = []; const items = []; const blocks = notes.map((n, i) => { const key = `n${i}`; init[key] = { autoAlpha: 0 }; ev.push(...spanEvents(key, n.from, n.to, { fadeIn: SHELF_NOTE_FADE.in, fadeOut: SHELF_NOTE_FADE.out })); const html = `