// THE STORY PAGES (release 39): the pages of the `pair`, `chapter` and // `status` modules (modules/pair.mjs, chapter.mjs, status.mjs), each a cue // page (chrome-cues.mjs). PURE: a schedule and a render block in, the slice // a module draws and its HTML out. // // - PAIR: then and now -- two clips on one subject, each with its date. As // "split" a strip in the footage box, THEN on one side and NOW on the // other, the side playing lit, the caption under them, up while either // clip plays; as "then→now" a card with both dates and an arrow over the // first `seconds` of the pair. The footage itself is not split: two clips // never play at once. // - CHAPTER: a section bumper over the first `seconds` of the clip it opens // (a window of the cut, laid at its own second): title, subtitle, date. // - STATUS: a ledger, a row per item -- "announced → " -- // that fills as the cut plays: a row comes in on its first clip, its // outcome on the outcome's clip (else the end of its last evidence clip). // Each STATE of the ledger is its own block, shown over exactly its span. import { deckGeometry, feedGeometry, overlayBox, pictureK } from "./deck.mjs"; import { rgba } from "./chrome-deck.mjs"; import { compileCues, cuePageHtml, dateText, esc, joinSpans, r4, segmentSpans, spanEvents, INSTANT } from "./chrome-cues.mjs"; import { CHAPTER_DEFAULTS, PAIR_DEFAULTS, STATUS_DEFAULTS } from "./modules/story-settings.mjs"; import { fullFrameItems, regionSpans } from "./full-frame.mjs"; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** The footage box this cut's clips play in (the feed's when it is one). */ export function footageBox(render, { feed = false } = {}) { // The stacked vertical deck's picture inside the safe area (overlayBox); the footage box otherwise. const f = overlayBox(render, { feed }); return { x: f.x, y: f.y, width: f.width, height: f.height }; } // Over the footage at the frame's share of its 1920 design (pictureK: the stacked vertical deck's own size). const scaleOf = (render) => pictureK(render, render?.width ?? 1920); const pxOf = (render) => (v) => Math.max(1, Math.round(v * scaleOf(render))); const even = (v) => 2 * Math.round(v / 2); // --------------------------------------------------------------------------- // PAIR // --------------------------------------------------------------------------- export function resolvePair(render) { const v = isObj(render?.chrome?.pair) ? render.chrome.pair : {}; return { ...PAIR_DEFAULTS, ...v, labels: { ...PAIR_DEFAULTS.labels, ...(isObj(v.labels) ? v.labels : {}) }, pairs: Array.isArray(v.pairs) ? v.pairs : [], }; } /** The pair strip's region: a band across the footage box, at its foot (or top). */ export function pairGeometry(render, { feed = false } = {}) { const f = footageBox(render, { feed }); const px = pxOf(render); const P = resolvePair(render); const height = even(px(P.style === "then→now" ? 200 : 132)); const inset = px(18); const width = even(f.width - 2 * inset); return { x: f.x + inset, y: P.position === "top" ? f.y + inset : f.y + f.height - inset - height, width, height, }; } /** * The pairs this cut plays, in the cut's clock: each `{ i, style, then, now, * caption, topic, spans: [{in, out}], phases: [{side, in, out}] }` -- a pair * none of whose clips is in the cut is left out. */ export function pairSchedule(schedule, render) { const P = resolvePair(render); const at = segmentSpans(schedule); const out = []; P.pairs.forEach((p, i) => { if (!isObj(p?.then) || !isObj(p?.now)) return; const sides = [ { side: "then", clip: p.then.clip }, { side: "now", clip: p.now.clip }, ...(Array.isArray(p.also) ? p.also.map((a) => ({ side: a.side, clip: a.clip })) : []), ]; const phases = []; for (const s of sides) { const sp = at.get(s.clip); if (!sp) continue; const same = p.then.clip === p.now.clip; phases.push({ side: same ? "both" : s.side, in: sp.in, out: sp.out }); } if (!phases.length) return; // One phase per span: a clip named twice (then and now the same clip) once. const seen = new Set(); const uniq = phases.filter((ph) => (seen.has(ph.in) ? false : (seen.add(ph.in), true))).sort((a, b) => a.in - b.in); out.push({ i, style: p.style ?? P.style, then: p.then, now: p.now, caption: p.caption ?? "", topic: p.topic ?? "", phases: uniq, spans: joinSpans(uniq.map((ph) => ({ in: ph.in, out: ph.out })), 0.75), }); }); return out; } /** The pair page's cues: a pair's block `p` in over its spans; `p.t` / `p.n` lit by phase. */ export function pairCues(pairs, P) { const init = {}; const ev = []; for (const p of pairs) { const k = `p${p.i}`; init[k] = { autoAlpha: 0 }; if (p.style === "then→now") { const a = p.spans[0].in; const b = Math.min(p.spans[0].out, a + P.seconds); ev.push(...spanEvents(k, a, b, { fadeIn: 0.4, fadeOut: 0.4 })); continue; } for (const sp of p.spans) ev.push(...spanEvents(k, sp.in, sp.out)); for (const side of ["t", "n"]) init[`${k}.${side}`] = { opacity: 0.35 }; for (const ph of p.phases) { const lit = ph.side === "both" ? ["t", "n"] : [ph.side === "then" ? "t" : "n"]; for (const s of lit) { ev.push({ k: `${k}.${s}`, at: ph.in, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); ev.push({ k: `${k}.${s}`, at: Math.max(ph.in + 0.3, ph.out - 0.3), dur: 0.3, to: { opacity: 0.35 }, ease: "power1.in" }); } } } return compileCues(init, ev); } /** * The pair page: `{ html, items }` (each pair's block an item, gated by its * own autoAlpha -- a changed caption recaptures only the frames it is up). */ export function pairHtml(schedule, render, opts = {}) { const P = resolvePair(render); const pairs = pairSchedule(schedule, render); if (!pairs.length) throw new Error("pair: the cut plays none of the pairs' clips"); const geo = pairGeometry(render, { feed: schedule.layout === "feed" }); const pal = render.palette; const px = pxOf(render); const fps = schedule.fps ?? render.fps ?? 30; const { init, cues } = pairCues(pairs, P); const items = []; const blocks = pairs.map((p) => { const k = `p${p.i}`; const d = (s) => esc(dateText(s?.date, P.dateFormat)); const label = (side) => esc(p[side]?.label ?? P.labels[side]); let html; if (p.style === "then→now") { html = `
${label("then")}
${d(p.then)}
→
${label("now")}
${d(p.now)}
${p.caption ? `
${esc(p.caption)}
` : ""}
`; } else { html = `
${label("then")}${d(p.then)}
${p.topic ? esc(p.topic) : "→"}
${label("now")}${d(p.now)}
${p.caption ? `
${esc(p.caption)}
` : ""}
`; } items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }); const css = ` .pair { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.94)}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); padding: ${px(12)}px ${px(22)}px; display: flex; flex-direction: column; justify-content: center; gap: ${px(6)}px; } .row { display: flex; align-items: center; justify-content: space-between; gap: ${px(18)}px; } .side { display: flex; align-items: baseline; gap: ${px(12)}px; white-space: nowrap; } .split .side.n { justify-content: flex-end; } .lab { font-family: 'DeckSansBold', sans-serif; font-size: ${px(22)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.accent}; } .date { font-family: 'DeckSansBold', sans-serif; font-size: ${px(34)}px; color: ${pal.fg}; font-variant-numeric: tabular-nums; } .mid { flex: 1 1 auto; min-width: 0; text-align: center; font-size: ${px(24)}px; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .cap { font-size: ${px(24)}px; line-height: ${px(30)}px; color: ${pal.fg}; text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } .card .row { justify-content: center; gap: ${px(40)}px; } .card .side { flex-direction: column; align-items: center; gap: ${px(4)}px; } .card .date { font-size: ${px(46)}px; } .arrow { font-family: 'DeckSansBold', sans-serif; font-size: ${px(56)}px; color: ${pal.accent}; }`; const html = cuePageHtml({ id: "pair", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body: blocks.join("\n "), init, cues, whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids: pairs.map((p) => `p${p.i}`) }, }); return { html, items }; } // --------------------------------------------------------------------------- // CHAPTER // --------------------------------------------------------------------------- export function resolveChapter(render) { const v = isObj(render?.chrome?.chapter) ? render.chrome.chapter : {}; return { ...CHAPTER_DEFAULTS, ...v, list: Array.isArray(v.list) ? v.list : [] }; } /** * The chapters this cut plays, each its window: `{ segment, from, to, n, * title, subtitle, date }` -- `segment` the clip it opens, the window its * first `seconds` (never past the clip). */ export function chapterWindows(schedule, render) { const C = resolveChapter(render); const at = segmentSpans(schedule); // A clip whose start is inside a full-frame item's span (the dissolve out of a teaser, the intro, a card: no // chrome is drawn there, full-frame.mjs): its bumper starts on the first frame after that span, so its entrance // plays whole. None: it starts with its clip, as ever. const fps = Number(schedule?.fps) || 30; const off = regionSpans(fullFrameItems(schedule)); const after = (t) => { for (const [a, b] of off) if (t >= a && t <= b) return r4(b + 1 / fps); return t; }; const out = []; C.list.forEach((c, n) => { const sp = at.get(c?.at); if (!sp) return; const from = after(sp.in); const to = Math.min(sp.out, from + C.seconds); if (!(to - from > 0.2)) return; const w = { segment: c.at, from, to, n, title: c.title, subtitle: c.subtitle ?? "", date: c.date ?? null }; // Where it stands (chapterPlacement): a lower band that would cover a post card moves into the card's free side // margin -- or, where neither margin can hold it, the cut has no bumper over that card. const place = chapterPlacement(schedule, render, w); if (place.mode === "none") return; out.push({ ...w, place }); }); return out; } /** The narrowest free margin beside a post card a lower chapter band moves into, design px (1920 wide). */ export const CHAPTER_SIDE_MIN = 180; /** * Where chapter window `w` stands, in frame px: `{ mode, rect, side? }`. * * - `card` (style card): the whole footage box -- a bumper that covers by design. * - `band` (style lower): the band across the footage box's foot, as always. * - `side`: a lower band whose window falls on a POST item (schedule.covers) and * would touch its card stands instead in the card's wider free side margin * (`side` "left" | "right": the footage box's height, a 16 px gap from the * card), its words fitted to that width and set to its foot. The card stays * whole: the post item's words are the evidence on screen. * - `none`: neither margin is CHAPTER_SIDE_MIN wide -- no bumper over that card * (the rail's section label and the section title still mark where it opens). */ export function chapterPlacement(schedule, render, w) { const feed = schedule?.layout === "feed"; const f = chapterGeometry(render, { feed }); if (resolveChapter(render).style !== "lower") return { mode: "card", rect: { ...f } }; const band = chapterCover(render, { feed }); const covers = (Array.isArray(schedule?.covers) ? schedule.covers : []) .filter((c) => Array.isArray(c?.rects) && c.rects.length && c.from < w.to && c.to > w.from); const rects = covers.flatMap((c) => c.rects).filter((r) => r && [r.x, r.y, r.width, r.height].every(Number.isFinite)); const touches = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height; if (!rects.some((r) => touches(r, band))) return { mode: "band", rect: band }; const px = pxOf(render); const gap = px(16); const x0 = Math.min(...rects.map((r) => r.x)), x1 = Math.max(...rects.map((r) => r.x + r.width)); const left = { x: f.x, y: f.y, width: Math.max(0, x0 - gap - f.x), height: f.height }; const right = { x: x1 + gap, y: f.y, width: Math.max(0, f.x + f.width - (x1 + gap)), height: f.height }; const [side, rect] = left.width >= right.width ? ["left", left] : ["right", right]; if (rect.width < px(CHAPTER_SIDE_MIN)) return { mode: "none", rect: null }; return { mode: "side", side, rect }; } /** The chapter bumper's region: the footage box. */ export function chapterGeometry(render, { feed = false } = {}) { return footageBox(render, { feed }); } /** The lower chapter band's height, design px (1920 wide). */ export const CHAPTER_LOWER_HEIGHT = 220; /** * What a chapter bumper covers in the frame while it is up: the lower band * across the footage box's foot (`style: "lower"`), else the whole footage * box (the card). What the measure extras move clear of. */ export function chapterCover(render, { feed = false } = {}) { const f = chapterGeometry(render, { feed }); if (resolveChapter(render).style !== "lower") return { ...f }; const h = pxOf(render)(CHAPTER_LOWER_HEIGHT); return { x: f.x, y: f.y + f.height - h, width: f.width, height: h }; } /** One chapter window's page. `window` is the snapped `{ segment, from, to }`. */ export function chapterHtml(schedule, render, window, opts = {}) { const C = resolveChapter(render); const ch = chapterWindows(schedule, render).find((w) => w.segment === window.segment); if (!ch) throw new Error(`chapter: no chapter opens ${window.segment} in this cut`); const geo = chapterGeometry(render, { feed: schedule.layout === "feed" }); const pal = render.palette; const px = pxOf(render); const fps = schedule.fps ?? render.fps ?? 30; const from = r4(window.from); const dur = r4(window.to - window.from); const ev = [...spanEvents("ch", from, from + dur, { fadeIn: 0.25, fadeOut: 0.45 })]; ev.push({ k: "ch.t", at: from, dur: 0.5, to: { y: 0 }, ease: "power2.out" }); const { init, cues } = compileCues({ ch: { autoAlpha: 0 }, "ch.t": { y: px(18) } }, ev); const lower = C.style === "lower"; const date = ch.date ? dateText(ch.date) : ""; // Beside a post card (chapterPlacement "side"): the band in the card's free margin, its words fitted to it -- // scaled down until the longest word of each line fits the margin's width, then wrapped. const side = ch.place?.mode === "side" ? ch.place : null; let k = 1; if (side) { const room = side.rect.width - 2 * px(20); const longest = (text, em) => Math.max(0, ...String(text ?? "").split(/\s+/).map((wd) => wd.length * em)); const need = Math.max(longest(ch.title, 0.58) * px(54), longest(ch.subtitle, 0.52) * px(28), longest(date, 0.74) * px(26), 1); k = Math.max(0.45, Math.min(1, room / need)); } const fs = (v) => Math.max(1, Math.round(px(v) * k)); const css = ` .chapter { position: absolute; visibility: hidden; opacity: 0; display: flex; flex-direction: column; ${side ? `left: ${side.rect.x - geo.x}px; top: ${side.rect.y - geo.y}px; width: ${side.rect.width}px; height: ${side.rect.height}px; box-sizing: border-box; padding: ${px(26)}px ${px(20)}px; justify-content: flex-end; ${side.side === "right" ? "text-align: right; align-items: flex-end;" : ""} background: linear-gradient(to top, ${rgba(pal.bg, 0.94)}, ${rgba(pal.bg, 0.0)} 60%);` : lower ? `left: 0; right: 0; bottom: 0; height: ${px(CHAPTER_LOWER_HEIGHT)}px; padding: ${px(26)}px ${px(48)}px; justify-content: center; background: linear-gradient(to top, ${rgba(pal.bg, 0.94)}, ${rgba(pal.bg, 0.0)});` : `inset: 0; align-items: center; justify-content: center; text-align: center; padding: ${px(60)}px; background: ${rgba(pal.bg, 0.92)};`} } .ct { display: flex; flex-direction: column; gap: ${fs(12)}px; ${lower ? (side?.side === "right" ? "align-items: flex-end;" : "") : "align-items: center;"} } .rule { width: ${fs(96)}px; height: ${px(6)}px; background: ${pal.accent}; border-radius: ${px(3)}px; } .title { font-family: 'DeckSansBold', sans-serif; font-size: ${lower ? fs(54) : px(84)}px; line-height: 1.08; color: ${pal.fg}; } .sub { font-size: ${lower ? fs(28) : px(36)}px; line-height: 1.25; color: ${pal.muted}; max-width: ${px(1300)}px; } .date { font-family: 'DeckSansBold', sans-serif; font-size: ${fs(26)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.accent}; }`; const body = `
${date ? `
${esc(date)}
` : ""}
${esc(ch.title)}
${ch.subtitle ? `
${esc(ch.subtitle)}
` : ""}
`; return cuePageHtml({ id: "chapter", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init, cues, window: { from, dur }, }); } // --------------------------------------------------------------------------- // STATUS // --------------------------------------------------------------------------- export function resolveStatus(render) { const v = isObj(render?.chrome?.status) ? render.chrome.status : {}; return { ...STATUS_DEFAULTS, ...v, items: Array.isArray(v.items) ? v.items : [] }; } const sideClip = (s) => (isObj(s) && typeof s.clip === "string" ? s.clip : null); const sideText = (s, fmt = "long") => { if (typeof s === "string") return s; if (!isObj(s)) return ""; const d = s.date ? dateText(s.date, fmt) : ""; return [d, s.text ?? ""].filter(Boolean).join(" · "); }; /** * The ledger's rows in the cut's clock: each `{ n, item, announced, outcome, * in, done }` -- `in` the second it comes in (its first clip's start), * `done` the second its outcome is filled (the outcome's clip, else the end * of its last clip), null when no outcome is given. Rows none of whose clips * the cut plays are left out. */ export function statusRows(schedule, render) { const S = resolveStatus(render); const at = segmentSpans(schedule); const rows = []; S.items.forEach((it, n) => { const clips = [sideClip(it.announced), ...(Array.isArray(it.evidence) ? it.evidence : []), sideClip(it.outcome)].filter(Boolean); const spans = clips.map((c) => at.get(c)).filter(Boolean); if (!spans.length) return; const first = Math.min(...spans.map((s) => s.in)); const last = Math.max(...spans.map((s) => s.out)); const oc = sideClip(it.outcome); const hasOutcome = it.outcome !== undefined && sideText(it.outcome) !== ""; const done = !hasOutcome ? null : oc && at.get(oc) ? Math.max(first, at.get(oc).in) : last; rows.push({ n, item: it.item, announced: sideText(it.announced), outcome: hasOutcome ? sideText(it.outcome) : "", in: first, done: done == null ? null : Math.max(first, done), last, }); }); return rows.sort((a, b) => a.in - b.in || a.n - b.n); } /** * The ledger's states: between two events (a row in, an outcome filled) it * reads the same. `fill`: from the first row on, the last `rows` rows; `each`: * a row alone, over its own clips. */ export function statusStates(schedule, render) { const S = resolveStatus(render); const rows = statusRows(schedule, render); const total = schedule.total; if (S.mode === "each") { return rows.flatMap((r) => { const parts = []; if (r.done != null && r.done > r.in + 0.05 && r.done < r.last) { parts.push({ at: r.in, until: r.done, rows: [{ ...r, filled: false }] }); parts.push({ at: r.done, until: r.last, rows: [{ ...r, filled: true }] }); } else parts.push({ at: r.in, until: r.last, rows: [{ ...r, filled: r.done != null && r.done <= r.in + 0.05 }] }); return parts; }); } const events = [...new Set(rows.flatMap((r) => [r.in, ...(r.done != null ? [r.done] : [])]).map(r4))].sort((a, b) => a - b); return events.map((t, j) => { const shown = rows.filter((r) => r.in <= t + 1e-6).slice(-S.rows); return { at: t, until: events[j + 1] ?? total, rows: shown.map((r) => ({ ...r, filled: r.done != null && r.done <= t + 1e-6 })) }; }); } /** The ledger's region: a column in a corner of the footage box, as tall as `rows` rows. */ export function statusGeometry(render, { feed = false } = {}) { const f = footageBox(render, { feed }); const S = resolveStatus(render); const px = pxOf(render); const width = even(Math.min(px(S.width), f.width - 2 * px(18))); const height = even(Math.min(f.height - 2 * px(18), px(58) + S.rows * px(92))); const inset = px(18); const right = S.position.endsWith("right"); const bottom = S.position.startsWith("bottom"); return { x: right ? f.x + f.width - inset - width : f.x + inset, y: bottom ? f.y + f.height - inset - height : f.y + inset, width, height, }; } /** The status page: `{ html, items }`, each state an item gated by its own autoAlpha. */ export function statusHtml(schedule, render, opts = {}) { const S = resolveStatus(render); const states = statusStates(schedule, render); if (!states.length) throw new Error("status: the cut plays none of the ledger's clips"); const geo = statusGeometry(render, { feed: schedule.layout === "feed" }); const pal = render.palette; const px = pxOf(render); const fps = schedule.fps ?? render.fps ?? 30; const bottom = S.position.startsWith("bottom"); const init = { lg: { autoAlpha: 0 } }; const ev = []; const spans = joinSpans(states.map((s) => ({ in: s.at, out: s.until })), 1e-3); for (const sp of spans) ev.push(...spanEvents("lg", sp.in, sp.out, { fadeIn: 0.35, fadeOut: 0.35 })); const items = []; const blocks = states.map((st, j) => { const k = `s${j}`; init[k] = { autoAlpha: 0 }; ev.push({ k, at: st.at, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); ev.push({ k, at: st.until, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); const rows = st.rows.map((r) => `
${esc(r.item)}
${esc(r.announced || "announced")}→${r.filled ? esc(r.outcome) : "…"}
`).join(""); const html = `
${esc(S.title)}
${rows}
`; items.push({ key: k, gate: [k, "autoAlpha"], html }); return html; }); const { init: i2, cues } = compileCues(init, ev); const css = ` #ledger { position: absolute; inset: 0; visibility: hidden; opacity: 0; } /* Each state is its own card, as tall as its rows, from the corner it is anchored to. */ .st { position: absolute; left: 0; right: 0; ${bottom ? "bottom: 0;" : "top: 0;"} visibility: hidden; opacity: 0; display: flex; flex-direction: column; gap: ${px(10)}px; padding: ${px(12)}px ${px(20)}px ${px(14)}px ${px(20)}px; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.94)}; border-left: ${px(5)}px solid ${pal.accent}; box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); } .hd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(20)}px; line-height: ${px(26)}px; letter-spacing: 0.12em; text-transform: uppercase; color: ${pal.muted}; } .r { display: flex; flex-direction: column; gap: ${px(2)}px; } .it { font-family: 'DeckSansBold', sans-serif; font-size: ${px(24)}px; line-height: ${px(30)}px; color: ${pal.fg}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .ln { display: flex; gap: ${px(10)}px; font-size: ${px(21)}px; line-height: ${px(28)}px; color: ${pal.muted}; white-space: nowrap; min-width: 0; } .an { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 45%; } .ar { flex: none; color: ${pal.accent}; font-family: 'DeckSansBold', sans-serif; } .oc { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; min-width: 0; } /* Before its outcome a row's announcement takes the line. */ .r:not(.done) .an { max-width: none; } .r:not(.done) .oc { flex: 0 0 auto; } .done .oc { color: ${pal.amber ?? pal.fg}; }`; const body = `
${blocks.join("\n ")}
`; const html = cuePageHtml({ id: "status", W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css, body, init: i2, cues, whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids: states.map((_, j) => `s${j}`) }, }); return { html, items }; }