// THE ANALYSIS ITEM'S PAGE (module `analysis`, a segment): the plan
// (analysis-plan.mjs) drawn full frame on the deck's ground, faces and colours
// -- the chart of the run on the left (its grid, its month ticks, the band, the
// mark line, one line through the points, the marks), the pace table and the
// status rows on the right, the reading and the footnote across the foot, and,
// with audio, the clip's citation and its QR (its picture is never shown).
//
// CALM, NOT A TRAILER: no slam, no hit, no camera move. The title fades in,
// the axes and the band after it, the line draws point to point in date order
// (each point coming up as the line reaches it, its mark after it), the pace
// rows land one by one, then the status, then the reading.
//
// PURE: an entry, its context and the faces in, an HTML string out (a cue
// interpreter, measure-draw.mjs pageHtml/cueList -- seekable from either side).
import { colorsOf, fontStack } from "./chrome-instruments.mjs";
import { mix, rgba } from "./chrome-deck.mjs";
import { ANALYSIS_MOTION, READ_AFTER, analysisPlan } from "./analysis-plan.mjs";
import { cueList, esc, fmtWeight, pageHtml, r4 } from "./measure-draw.mjs";
/** The motion's seconds: analysis-plan.mjs's (one copy, with the reading's time). */
export { ANALYSIS_MOTION };
/** The frame, in the 1280x720 units the page is laid out in (scaled to the render). */
export const ANALYSIS_BOX = Object.freeze({ x0: 70, x1: 800, y0: 150, y1: 560, panel: 850, panelR: 1230, qr: 140 });
/**
* When each thing lands, in the item's own seconds: `{ k, title, axes, band, points: Map(n -> t), rows: [t], reading,
* foot, readLit, end, leave, readHold }`. The title, the axes and the band; the line drawn point to point; then the
* READING right after the line (fully lit at `readLit`) with the pace and status rows landing beside it, one after
* another. Scaled by k = min(1, (leave − readHold − its fade) / READ_AFTER), at least kMin (the fades are never
* scaled: nothing hurries), so the reading stays fully lit for
* `readHold` before the picture starts to leave (`leave`: the dissolve out, or the cut's closing fade when last).
*/
export function analysisTimes(plan) {
const M = ANALYSIS_MOTION;
const line = plan.line.map((n) => plan.pos.get(n));
const span = line.length > 1 ? line.reduce((s, p, i) => (i ? s + Math.hypot(p.x - line[i - 1].x, p.y - line[i - 1].y) : 0), 0) : 0;
const leave = Number.isFinite(plan.leave) ? plan.leave : plan.seconds;
const readHold = Number.isFinite(plan.readHold) ? plan.readHold : 0;
const k = Math.min(1, Math.max(M.kMin, (leave - readHold - M.reading) / READ_AFTER));
const at = (v) => r4(v * k);
const points = new Map();
let walked = 0;
plan.line.forEach((n, i) => {
if (i) walked += Math.hypot(line[i].x - line[i - 1].x, line[i].y - line[i - 1].y);
points.set(n, at(M.lineFrom + (span ? (walked / span) * M.line : 0)));
});
// A point that is not on the line (another weight for its day): with the line's point that day.
for (const p of plan.points) if (!points.has(p.n)) points.set(p.n, points.get(plan.line.find((n) => plan.points[n].day === p.day)) ?? at(M.lineFrom));
const after = M.lineFrom + M.line + M.readGap;
const reading = at(after);
const rows = [...plan.pace, ...plan.status].map((_, i) => at(after + i * M.rowGap));
const readLit = r4(reading + M.reading);
const foot = r4(reading + at(M.foot));
const end = r4(Math.max(readLit, foot + M.reading, rows.length ? rows[rows.length - 1] + M.row : 0));
return { k, title: 0, axes: at(0.3), band: at(M.band), points, rows, reading, foot, readLit, end, leave, readHold };
}
/**
* The page. `ctx` = `{ ledger, schema, timeline, render }` (analysis-plan.mjs); `opts` = `{ fonts, gsap, cite, qrSrc }`:
* the faces (instrumentFonts), the clip's citation line and its QR's asset (both null without audio).
*/
export function analysisHtml(entry, ctx, opts = {}) {
const render = ctx.render ?? {};
const W = Number(render.width) || 1920, H = Number(render.height) || 1080;
const u = W / 1280;
const px = (v) => Math.round(v * u * 100) / 100;
const fps = render.fps ?? 30;
const fonts = opts.fonts ?? {};
const C = colorsOf(render);
const B = ANALYSIS_BOX;
const plan = analysisPlan(entry, ctx, { x0: px(B.x0), x1: px(B.x1), y0: px(B.y0), y1: px(B.y1) });
const T = analysisTimes(plan);
const M = ANALYSIS_MOTION;
const L = cueList(fps);
const parts = [];
const show = (k, at, dur, extra = {}, ease = "power1.out") => L.add(k, at, dur, { autoAlpha: 1, ...extra }, ease);
const hidden = (k, extra = {}) => L.set(k, { autoAlpha: 0, ...extra });
const color = (c) => (c === "accent" ? C.accent : c === "amber" ? C.amber : c === "red" ? C.needle : c === "muted" ? C.muted : c === "fg" ? C.fg : c);
const lay = plan.layout;
// The title.
parts.push(`
${esc(plan.kicker)}
${esc(plan.title)}
`);
hidden("kick", { y: px(8) });
hidden("ttl", { y: px(8) });
show("kick", T.title, M.title, { y: 0 });
show("ttl", T.title + 0.1, M.title, { y: 0 });
// The axes: a rule and its figure per grid step, a tick and a name per month, the mark line.
const axes = [];
for (const g of lay.grid) axes.push(`${g.v}
`);
axes.push(``);
for (const m of lay.months) axes.push(`${m.text}
`);
if (lay.mark !== null) axes.push(`${esc(lay.markLabel)}
`);
parts.push(`${axes.join("")}
`);
hidden("axes");
show("axes", T.axes, 0.5);
// The band.
if (plan.band) {
const bw = Math.max(px(2), plan.band.x1 - plan.band.x0);
parts.push(``);
parts.push(`${esc(plan.band.label)}${plan.band.label ? " · " : ""}${esc(dm(plan.band.from))} – ${esc(dm(plan.band.to))}
`);
hidden("band");
hidden("bandl");
show("band", T.band, 0.6);
show("bandl", T.band + 0.15, 0.5);
}
// The line, point to point in date order; a stretch to or from a bound is quieter and dotted (the bound is no exact figure).
const byN = new Map(plan.points.map((p) => [p.n, p]));
for (let i = 1; i < plan.line.length; i += 1) {
const a = plan.pos.get(plan.line[i - 1]), b = plan.pos.get(plan.line[i]);
const loose = byN.get(plan.line[i - 1]).bound || byN.get(plan.line[i]).bound;
const k = `s${i}`;
parts.push(``);
L.set(k, { x: a.x, y: a.y, width: r4(Math.hypot(b.x - a.x, b.y - a.y)), rotation: r4((Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI), scaleX: 0, transformOrigin: "0% 50%" });
const t0 = T.points.get(plan.line[i - 1]), t1 = T.points.get(plan.line[i]);
L.add(k, t0, Math.max(0.05, t1 - t0), { scaleX: 1 }, "none");
}
// The points: solid, or hollow when the row is a bound (or "about"): never drawn as an exact figure.
for (const p of plan.points) {
const at = plan.pos.get(p.n);
const hollow = p.bound || p.qualifier === "≈";
parts.push(``);
L.set(`p${p.n}`, { x: at.x, y: at.y, autoAlpha: 0, scale: 0.6 });
L.add(`p${p.n}`, T.points.get(p.n), M.point, { autoAlpha: 1, scale: 1 }, "power1.out");
}
// The marks: the row's figure and day, the operator's words, his quote under them -- beside the point, on the
// side away from the line (right of a point in the chart's first half, left and below in its second).
const mid = (px(B.x0) + px(B.x1)) / 2;
plan.marks.forEach((m, i) => {
const right = m.at.x > mid;
const style = right
? `right:${r4(W - m.at.x + px(10))}px; top:${r4(m.at.y + px(10))}px; text-align:right`
: `left:${r4(m.at.x + px(10))}px; top:${r4(m.at.y - px(30))}px`;
parts.push(`${esc(m.text)}
${m.quote ? `
“${esc(m.quote)}”
` : ""}
`);
hidden(`m${i}`);
show(`m${i}`, r4(T.points.get(m.n) + 0.15), M.mark);
});
// The pace table and the status rows: each lands (a short rise and a fade), one after another.
const rows = [];
plan.pace.forEach((x) => {
const sub = [`${x.days} days`, x.note, x.bound ? boundNote(x) : ""].filter(Boolean).join(" · ");
rows.push(`${esc(x.span.toUpperCase())}
${esc(sub)}
` +
`
${paceFigure(x)}
`);
});
plan.status.forEach((x) => {
rows.push(`${esc(x.label)}
${x.note ? `
${esc(x.note)}
` : ""}
` +
`
${esc(x.value)}
`);
});
parts.push(`${rows.map((r, i) => r.replace('
', `
`)).join("")}
`);
rows.forEach((_, i) => {
hidden(`r${i}`, { y: px(M.rowRise) });
show(`r${i}`, T.rows[i], M.row, { y: 0 }, "power2.out");
});
// The reading, the footnote, and with audio the clip's citation and its code.
const narrow = !!opts.qrSrc;
parts.push(``);
hidden("rd");
show("rd", T.reading, M.reading);
if (plan.footnote) { hidden("fn"); show("fn", T.foot, M.reading); }
if (opts.cite) { hidden("ci"); show("ci", T.foot, M.reading); }
if (opts.qrSrc) {
parts.push(`
})
`);
hidden("qr");
show("qr", T.foot, M.reading);
}
const { init, cues } = L.build();
const css = `
.bg { position: absolute; inset: 0; background: ${C.bg}; }
.kick { position: absolute; left: ${px(B.x0)}px; top: ${px(36)}px; font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(20)}px;
letter-spacing: 0.14em; color: ${C.muted}; white-space: nowrap; }
.ttl { position: absolute; left: ${px(B.x0)}px; top: ${px(62)}px; font-family: ${fontStack(fonts, "display")}; font-size: ${px(40)}px;
color: ${C.fg}; white-space: nowrap; }
.axes { position: absolute; inset: 0; }
.grid, .base, .markl { position: absolute; left: ${px(B.x0)}px; width: ${r4(px(B.x1) - px(B.x0))}px; height: 0; border-top: 1px solid ${C.rule}; }
.base { border-top-color: ${mix(C.bg, C.fg, 0.28)}; }
.markl { border-top: ${px(1.5)}px dashed ${rgba(C.accent, 0.7)}; }
.gv { position: absolute; right: ${r4(W - px(B.x0) + px(10))}px; transform: translateY(-50%); font-family: ${fontStack(fonts, "condensed")};
font-size: ${px(15)}px; color: ${C.muted}; letter-spacing: 0.04em; }
.gv.mk { color: ${C.accent}; font-family: ${fontStack(fonts, "bold")}; }
.mt { position: absolute; width: 1px; height: ${px(6)}px; background: ${mix(C.bg, C.fg, 0.28)}; }
.mn { position: absolute; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px;
color: ${C.muted}; letter-spacing: 0.08em; white-space: nowrap; }
.band { position: absolute; top: ${px(B.y0)}px; height: ${r4(px(B.y1) - px(B.y0))}px; background: ${rgba(C.amber, 0.13)}; }
.bandl { position: absolute; top: ${px(B.y0 - 24)}px; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")};
font-size: ${px(15)}px; letter-spacing: 0.08em; color: ${C.amber}; white-space: nowrap; }
.seg { position: absolute; left: 0; top: 0; height: ${px(3)}px; margin-top: -${px(1.5)}px; background: ${C.accent}; border-radius: ${px(2)}px; }
.seg.loose { height: 0; margin-top: -${px(1)}px; background: none; border-top: ${px(2)}px dotted ${rgba(C.accent, 0.7)}; border-radius: 0; }
.pt { position: absolute; left: 0; top: 0; width: ${px(8)}px; height: ${px(8)}px; margin: -${px(4)}px 0 0 -${px(4)}px; border-radius: 50%; background: ${C.accent}; }
.pt.q { width: ${px(11)}px; height: ${px(11)}px; margin: -${px(5.5)}px 0 0 -${px(5.5)}px; background: ${C.bg}; border: ${px(2)}px solid ${C.accent}; }
.mk1 { position: absolute; max-width: ${px(420)}px; }
.mt1 { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; color: ${C.fg}; white-space: nowrap; }
.mq { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.amber}; font-style: italic; margin-top: ${px(2)}px; }
.side { position: absolute; left: ${px(B.panel)}px; width: ${px(B.panelR - B.panel)}px; top: ${px(B.y0)}px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: ${px(10)}px 0; border-bottom: 1px solid ${C.rule}; }
.row .lt { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(17)}px; letter-spacing: 0.05em; color: ${C.muted}; white-space: nowrap; }
.row .ls { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.muted}; margin-top: ${px(3)}px; white-space: nowrap; }
.row .v { font-family: ${fontStack(fonts, "display")}; font-size: ${px(30)}px; color: ${C.fg}; white-space: nowrap; text-align: right; }
.row .v.b { color: ${mix(C.bg, C.fg, 0.82)}; }
.row .v.st { font-size: ${px(28)}px; }
.row .bw { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; letter-spacing: 0.08em; color: ${C.muted}; }
.row .bw.ab { margin-right: ${px(8)}px; vertical-align: ${px(4)}px; }
.row .bt { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(17)}px; color: ${C.muted}; margin-left: ${px(4)}px; }
.foot { position: absolute; left: ${px(B.x0)}px; right: ${px(1280 - B.panelR)}px; top: ${px(604)}px; }
.foot.narrow { right: ${px(1280 - B.panelR + B.qr + 24)}px; }
.rd { font-family: ${fontStack(fonts, "regular")}; font-size: ${px(24)}px; line-height: 1.3; color: ${C.fg}; }
.fn { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; color: ${C.muted}; margin-top: ${px(6)}px; }
.ci { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.muted}; margin-top: ${px(4)}px; letter-spacing: 0.03em; }
.qr { position: absolute; left: ${px(B.panelR - B.qr)}px; top: ${px(720 - 16 - B.qr)}px; width: ${px(B.qr)}px; height: ${px(B.qr)}px; }`;
return pageHtml({
id: "analysis", W, H, fps, fonts, gsap: opts.gsap,
data: { total: plan.seconds, window: null, init, cues },
css,
body: `
${parts.join("")}${measureScript(W, H)}`,
});
}
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const dm = (iso) => {
const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso ?? ""));
return m ? `${Number(m[3])} ${MON[Number(m[2]) - 1]}`.toUpperCase() : "";
};
/**
* A pace row's figure: exact, the signed change; "about" before an approximate one; a bound in words, unsigned --
* "MORE THAN" / "AT MOST" over the figure, "lost" / "gained" after it (analysis-plan.mjs paceWords).
*/
function paceFigure(x) {
if (x.lead === "about") return `
about${esc(x.figure)}`;
if (x.lead) return `
${esc(x.lead)}
${esc(x.figure)}${esc(x.tail)}
`;
return esc(x.figure);
}
/**
* THE PAGE MEASURED (the build's check, `?measure`): at the item's last frame, every text box and the code
* against the frame and each other -- a box leaving the frame, a row's words and figure overlapping or the row
* wider than the panel, the table running into the reading, the QR or the citation over the table, the reading or
* the footnote, a mark over the table -- written as `data-measure` (a JSON list of sentences) on the root.
*/
function measureScript(W, H) {
return ``;
}
/** The measure's sentences from a page's dumped DOM (`data-measure`), or null when the page did not measure. */
export function measuredProblems(dom) {
const m = /]*\sdata-measure="([^"]*)"/.exec(String(dom ?? ""));
if (!m) return null;
const json = m[1].replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
try {
const v = JSON.parse(json);
return Array.isArray(v) ? v.map(String) : null;
} catch {
return null;
}
}
/** The words under a bounded pace row: which end is a bound, as he said it ("to < 300"). */
function boundNote(x) {
const end = (e) => `${e.qualifier} ${fmtWeight(e.value)}`;
const ends = [];
if (x.boundRows.includes(x.from.row)) ends.push(`from ${end(x.from)}`);
if (x.boundRows.includes(x.to.row)) ends.push(`to ${end(x.to)}`);
return ends.join(", ");
}
/**
* The clip's citation as the page prints it: "HEARD:
· · · " from attributionParts'
* parts (attribution.mjs) -- the build's own, with the source's metadata when it has it.
*/
export function analysisCite(parts) {
if (!parts) return null;
const at = Number(parts.at);
const clock = Number.isFinite(at)
? `${Math.floor(at / 3600) ? `${Math.floor(at / 3600)}:${String(Math.floor((at % 3600) / 60)).padStart(2, "0")}` : Math.floor(at / 60)}:${String(Math.floor(at % 60)).padStart(2, "0")}`
: "";
return ["HEARD:", [parts.channel, parts.title, parts.date, clock].filter((x) => x && String(x).trim()).join(" · ")].join(" ");
}