// full-frame.mjs — THE FULL-FRAME ITEMS: the cut seconds a chrome layer that keeps no time of its own is not drawn. // // An item that takes the whole frame -- a teaser, the brand intro, an analysis item, a video entry, a card // (`card`, `scroll`, `chart`, `ledger`) under `deck.overCards: "hide"` -- is its own picture. The deck slides away // over it (deck.mjs hidesDeck, the segment's `hideDeck`), and the layers that follow the deck's choreography go with // it: the shell, the dial, the odometer, the trail, the feed (their module's `fullFrame.followsDeck`). The others -- // the measure extras (the diet strip, the promise clock, the goals, the streak, the peak), the shelf, the stamps, // the side panels, the chapters, the posts windows, the finale's pages -- keep no such time, so the build lays each // with an `enable` that leaves these items' spans out (build-video.mjs chromeOverlayChain, by `regionSpans`), and // Play hides them while such an item is on screen (playCore.tsx, `layerOffOver`). One list (`fullFrameItems`), and // what each region takes of it (`regionSpans`, by its module's `fullFrame` traits): // // every region but those below: every item's span -- // a video entry that hides the chrome (`noChrome`; `deck: "shown"` keeps it): from the frame the dip into it has // made black (its start + the dissolve − a frame; mid-dissolve for `enter: "cut"`) to mid-dissolve out of it, // or past the cut's end when it is last -- as it always was; // every other item: from the first frame its picture is in -- its dissolve's first frame, or, for a teaser that // dips, the frame the dip has made black (the dip fades the whole frame, overlays with it) -- to the frame // BEFORE the end of its dissolve out (that frame is the next segment's alone), or past the cut's end when it is // last. A first item is off from 0. // `followsDeck` (shell, dial, odometer, trail, feed): only a video entry's and an analysis item's spans, as the // build laid them before (an analysis item's to the end of its dissolve out) -- over a teaser, the intro or a // card their own slide away and back is kept. // `ownFade` (the finale, the dial's finale, the diet runs, the stamps, the posts windows): an item's span starts // once its dissolve in is over, so a page's own exit through that dissolve -- the finale's fade out, a clip's // stamp or posts window leaving over the next segment's dissolve -- plays whole (a video entry's as above). // `drawsMarks` (the stamps): not over a teaser that carries marks -- the stamp is that card's own content. // // Together (`fullFrameTraitProblem` says which may be): `followsDeck` stands alone -- it already lays only the // video entry's and the analysis item's spans, so nothing else may shape them. `ownFade` with `drawsMarks` (the // stamps): `drawsMarks` wins over a teaser that carries marks (no span at all), `ownFade` shapes every other span. // // A segment that keeps the deck up is not full frame: a teaser that COUNTS (deck.mjs teaserCounts: marks, no dip), // a card under `overCards: "show"`, a video entry with `deck: "shown"`. A cut with no full-frame item: [] -- and // every graph is the one it was. // // A LEAF with no imports: the build, umtool's server and its client (Play) read the same rule. const fin = (v) => typeof v === "number" && Number.isFinite(v); const r4 = (v) => Math.round(v * 1e4) / 1e4; /** A module's `fullFrame` traits (contract.mjs): how its region is laid over a full-frame item. */ export const FULL_FRAME_TRAITS = Object.freeze(["followsDeck", "ownFade", "drawsMarks"]); /** * Why a `fullFrame` traits object cannot be laid, as a sentence, or null: each a trait set to `true`, at least one, * and `followsDeck` alone (it lays main's video and analysis spans as they are -- nothing to shape). `ownFade` with * `drawsMarks` is allowed: `drawsMarks` wins over a teaser with marks, `ownFade` shapes the rest. * * @param {unknown} f */ export function fullFrameTraitProblem(f) { if (f === null || typeof f !== "object" || Array.isArray(f) || !Object.keys(f).length) return "an object of one or more traits"; for (const [k, v] of Object.entries(f)) { if (!FULL_FRAME_TRAITS.includes(k)) return `${k} is not a trait (${FULL_FRAME_TRAITS.join(", ")})`; if (v !== true) return `${k} must be true`; } if (f.followsDeck && Object.keys(f).length > 1) return "followsDeck stands alone: it lays only a video entry's and an analysis item's spans, as they are"; return null; } /** * Is this schedule segment full frame? A video entry by its `noChrome`, an analysis item always, anything else by * its `hideDeck`. * * @param {{ type?: string, hideDeck?: boolean, noChrome?: boolean } | null | undefined} seg */ export function fullFrameSegment(seg) { if (!seg) return false; if (seg.type === "video") return !!seg.noChrome; if (seg.type === "analysis") return true; return !!seg.hideDeck; } /** * @typedef {{ id: string, type: string, kind: "video" | "analysis" | "page", index: number, start: number, * end: number, last: boolean, marks: boolean, fps: number, D: number, span: [number, number] }} FullFrameItem * `span` is the item's span as the build laid it before the measure extras were left out (a video entry's * rule; any other's from its first frame to the END of its dissolve out, inclusive). */ /** * The schedule's full-frame items, in order, each with its span and what a region's traits read of it. * * @param {{ segments?: any[], total?: number, fps?: number, transition?: number } | null | undefined} schedule * @returns {FullFrameItem[]} */ export function fullFrameItems(schedule) { const segs = schedule?.segments ?? []; const D = Number(schedule?.transition ?? 0) || 0; const fps = Number(schedule?.fps ?? 30) || 30; /** @type {FullFrameItem[]} */ const out = []; segs.forEach((s, i) => { if (!fullFrameSegment(s) || !fin(Number(s?.start))) return; const start = Number(s.start); const end = fin(Number(s.end)) ? Number(s.end) : start + Number(s.duration); const last = i === segs.length - 1; const kind = s.type === "video" ? "video" : s.type === "analysis" ? "analysis" : "page"; let a; let b; if (kind === "video") { a = i > 0 && s.enter ? start + D - 1 / fps : i > 0 ? start + D / 2 : 0; b = last ? Number(schedule.total ?? end) + 1 : end - D / 2; } else { a = i === 0 ? 0 : s.dip ? start + D - 1 / fps : start; b = last ? Number(schedule.total ?? end) + 1 : end; } out.push({ id: s.id, type: s.type, kind, index: i, start, end, last, marks: !!(s.claim || (Array.isArray(s.claims) && s.claims.length)), fps, D, span: [Math.max(0, r4(a)), r4(b)], }); }); return out; } /** * The spans one region leaves out, `[from, to]` cut seconds by start, for its module's `fullFrame` traits (none: * every region but the deck's own and the finale's). Overlapping pairs (two full-frame items back to back) are kept as * they are: `not(between(…)+between(…))` is off over their union. [] without one. * * @param {FullFrameItem[]} items * @param {{ followsDeck?: boolean, ownFade?: boolean, drawsMarks?: boolean } | null | undefined} [traits] * @returns {Array<[number, number]>} */ export function regionSpans(items, traits = {}) { const t = traits ?? {}; /** @type {Array<[number, number]>} */ const out = []; for (const it of items ?? []) { if (t.followsDeck) { if (it.kind !== "page") out.push([it.span[0], it.span[1]]); continue; } if (t.drawsMarks && it.type === "teaser" && it.marks) continue; let [a, b] = it.span; // The frame at the end of its dissolve out is the next segment's alone: the layer is drawn on it. if (it.kind !== "video" && !it.last) b = r4(b - 1 / it.fps); // Its own fade out through the dissolve in plays whole. if (t.ownFade && it.kind !== "video" && it.index > 0) a = Math.max(a, r4(it.start + it.D)); if (b >= a) out.push([a, b]); } return out.sort((x, y) => x[0] - y[0]); } /** * The spans a region with no traits leaves out (the measure extras, the stamps, every side panel): `regionSpans` * with none. `only` narrows the items (video-entry.mjs videoBlackouts: the video entries' alone). * * @param {{ segments?: any[], total?: number, fps?: number, transition?: number } | null | undefined} schedule * @param {{ only?: (item: FullFrameItem) => boolean }} [opts] */ export function fullFrameSpans(schedule, { only = () => true } = {}) { return regionSpans(fullFrameItems(schedule).filter(only)); } /** The items' spans as the build laid them before (`span`), of one kind: a video entry's, an analysis item's. */ export function itemSpans(schedule, kind) { return fullFrameItems(schedule).filter((it) => it.kind === kind).map((it) => /** @type {[number, number]} */ ([it.span[0], it.span[1]])); } /** * PLAY: is a layer with these traits hidden while `item` (a full-frame item, or null) is the one on screen, at cut * second `tc`? Play cuts at mid-dissolve, so "over it" is while it is on screen. A `followsDeck` layer is off over a * video entry and an analysis item (as the build lays it) and slides away on its own over any other; the stamps stay * over a teaser with marks; an `ownFade` page goes once the dissolve into the item is over. * * @param {FullFrameItem | null | undefined} item * @param {{ followsDeck?: boolean, ownFade?: boolean, drawsMarks?: boolean } | null | undefined} traits * @param {number} tc */ export function layerOffOver(item, traits, tc) { if (!item) return false; const t = traits ?? {}; // As the build lays it: off over a video entry and an analysis item, its own slide over everything else. if (t.followsDeck) return item.kind !== "page"; if (t.drawsMarks && item.type === "teaser" && item.marks) return false; if (t.ownFade && item.kind !== "video" && item.index > 0) return tc >= item.start + item.D; return true; } /** The ids of the schedule's full-frame segments. */ export function fullFrameIds(schedule) { return new Set((schedule?.segments ?? []).filter(fullFrameSegment).map((s) => s.id)); }