// 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 = `
${esc(n.text)}
`; items.push({ key, gate: [key, "autoAlpha"], html }); return html; }); const { cues } = compileCues(init, ev); const css = ` .nt { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; align-items: center; } /* A chip: the deck's ground, the accent down its left edge, the words in at most two lines. */ .ch { max-width: 100%; max-height: 100%; border-radius: ${px(8)}px; background: ${rgba(pal.bg, 0.9)}; box-shadow: inset ${px(4)}px 0 0 ${pal.accent}, 0 ${px(6)}px ${px(16)}px rgba(0, 0, 0, 0.4); padding: ${px(8)}px ${px(16)}px ${px(8)}px ${px(20)}px; } .tx { font-size: ${size}px; line-height: ${Math.round(size * 1.2)}px; color: ${pal.fg}; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }`; return { html: cuePageHtml({ id: "shelf", W: geo.width, H: geo.height, fps: schedule.fps ?? render.fps ?? 30, fonts: opts.fonts, gsapSrc: opts.gsap, css, body: blocks.join("\n "), init, cues, whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids: items.map((i) => i.key) }, primeWindow: true, }), items, }; }