// The EFFECTS region's composition (release 35, lane O2): one HyperFrames page
// for a whole report cut, exactly the footage box (deck.mjs fxGeometry),
// transparent but for the effects fx.mjs schedules -- the kinetic quote, the
// redaction, the odometer, the scrubber, the glitch, the THEN/NOW wipe, the
// receipts and the zoom. Overlays on the evidence, never cards: nothing here
// covers the whole picture for longer than a glitch's half second.
//
// PURE, like chrome-stats.mjs: a schedule and a render block in, an HTML string
// out. compose-chrome.mjs copies the assets in beside it (the faces, the
// screenshots, the scrubber's thumbnails), writes it and renders it
// (`region: "fx"`); the build lays the frames over the cut after the stats.
//
// SEEK-SAFE. A render is a seek per frame from parallel workers in any order,
// so the timeline is a list of cues computed here (fx.mjs compileCues), each
// stating its `from`; nothing is rewritten by a callback and nothing measures
// the page: every size is in the data (a screenshot's pixels are read by
// compose-chrome before the page is written). The glitch's noise is a seeded
// generator's (fxRandom), so frame 412 is the same tear on every worker.
import { fxGeometry, pageDuration } from "./deck.mjs";
import { assetFile, mix, rgba } from "./chrome-deck.mjs";
import { FX_MOTION, INSTANT, compileCues, fxRandom, noNegZero } from "./fx.mjs";
const esc = (s) =>
String(s ?? "")
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """);
// `|| 0`: no -0 in the data (a JSON round trip makes it 0, and a cue list must survive one).
const r2 = (v) => Math.round(v * 100) / 100 || 0;
const r4 = (v) => Math.round(v * 10000) / 10000 || 0;
/** The VHS stamp's mono, vendored beside the brand's faces; copied in as `assets/FxMono.ttf`. */
// Through assetFile (chrome-deck.mjs): a server bundle's asset URL is not fileURLToPath's.
export const FX_MONO_FILE = assetFile(new URL("./fonts/IBMPlexMono-Bold.ttf", import.meta.url));
/** THEN's colour when the palette names none (`palette.then`), as the flips panel's. */
export const FX_THEN_COLOR = "#6fa8dc";
/** The glitch's colours: a red and a cyan channel, and the tear's white. */
export const FX_GLITCH_COLORS = Object.freeze(["rgba(255, 40, 70, 0.62)", "rgba(40, 230, 255, 0.58)", "rgba(255, 255, 255, 0.5)", "rgba(0, 0, 0, 0.55)"]);
/** The receipts' resting tilt, card by card (degrees). */
export const FX_FAN = Object.freeze([-4, 3, -2, 5]);
/**
* Where a scrubber tick sits: its day on the rail, x0..x1 (region pixels).
*/
export const railX = (day, from, to, x0, x1) => x0 + ((day - from) / Math.max(1e-9, to - from)) * (x1 - x0);
/**
* The odometer's cell for one column: cell 0 is blank (a leading column the
* number does not reach), cell d+1 is digit d, cell 11 is the 0 a 9 rolls on to.
*/
export function odoCells(value, digits) {
const s = String(value).padStart(digits, " ");
return [...s.slice(-digits)].map((ch) => (ch === " " ? 0 : Number(ch) + 1));
}
/**
* The zoom's push: the scale and offset (transform-origin top-left) that put
* the focus box's centre in the card's centre at `fill` of the card.
*/
export function zoomPush(focus, cardW, cardH, fill = 0.86) {
const fw = (focus[2] - focus[0]) * cardW, fh = (focus[3] - focus[1]) * cardH;
const s = Math.max(1, fill * Math.min(cardW / fw, cardH / fh));
const cx = ((focus[0] + focus[2]) / 2) * cardW, cy = ((focus[1] + focus[3]) / 2) * cardH;
return { scale: r4(s), x: r2(cardW / 2 - s * cx), y: r2(cardH / 2 - s * cy) };
}
/** A card's size in the region: `width` wide by the shot's aspect, no taller than `maxH`. */
export function cardSize(dims, width, maxH) {
const aspect = dims && dims.w > 0 && dims.h > 0 ? dims.h / dims.w : 0.75;
let w = Math.round(width), h = Math.round(width * aspect);
if (h > maxH) {
h = Math.round(maxH);
w = Math.round(maxH / aspect);
}
return { w, h };
}
/**
* Everything the effects do, as elements and events. Returns the page's body
* markup, its init states and its cues. `assets` = `{ shots: {[path]: {src, w, h}},
* thumbs: {[segment]: src} }`.
*/
export function fxPlan(schedule, render, assets = {}) {
const fx = schedule.fx;
if (!fx) throw new Error("fx: the schedule draws no effects");
const geo = fxGeometry(render, { feed: schedule.layout === "feed" });
const W = geo.width, H = geo.height;
const pal = render.palette;
const k = W / 1574;
const px = (v) => Math.max(1, Math.round(v * k));
const fps = schedule.fps ?? render.fps ?? 30;
const frame = 1 / fps;
const init = {};
const ev = [];
const html = [];
const add = (key, at, dur, to, ease = "none") => ev.push({ k: key, at, dur, to, ease });
const set = (key, at, to) => add(key, at, INSTANT, to);
const shots = assets.shots ?? {};
const thumbs = assets.thumbs ?? {};
const thenC = /^#[0-9a-fA-F]{6}$/.test(pal.then ?? "") ? pal.then : FX_THEN_COLOR;
// ---- the scrubber (drawn first: under everything) -----------------------
if (fx.scrubber) {
const s = fx.scrubber;
const top = s.position === "top";
// The rail keeps clear of the odometer when it sits in a corner on the
// rail's edge of the box.
const odo = fx.odometer;
const odoW = odo ? px(36) + odo.digits * px(58) + px(28) + px(24) : 0;
const odoSide = odo && odo.position.startsWith(top ? "top" : "bottom") ? odo.position.split("-")[1] : null;
const x0 = odoSide === "left" ? odoW + px(24) : px(64);
const x1 = odoSide === "right" ? W - odoW - px(24) : W - px(64);
const railY = top ? px(38) : H - px(38);
const X = (day) => r2(railX(day, s.from, s.to, x0, x1));
const thumbW = px(196), thumbH = Math.round((thumbW * 9) / 16);
init.scr = { autoAlpha: 0 };
for (const sp of s.spans) {
add("scr", sp.in, Math.min(0.35, (sp.out - sp.in) / 2), { autoAlpha: 1 }, "power2.out");
add("scr", Math.max(sp.in, sp.out - 0.3), Math.min(0.3, (sp.out - sp.in) / 2), { autoAlpha: 0 }, "power1.in");
}
const years = s.years.map((y) =>
`