Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit ab46ca305ae311cb23346b12afe4749c338c6a85
parent c53d6eadbc7eb32d2db102e46d5d95157dd8417c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 30 Oct 2026 15:37:00 -0400

umtool popup posts persist: deck.posts.persist keeps a card up on its own clock across clip joins, no footage freeze, close posts share one bar

Operator: "don't pause for the tweets, just keep that bar up independently
for a little bit even between clips and then hide it if there's no other
post soon."

deck.posts.persist (true | {seconds 8-60 = 12, gap 0-30 = 6}; opt-in): a
popup card comes up at its moment as ever and stays up `seconds` on its own
clock, over joins and dissolves; no hold (posts.hold is ignored). A post
whose moment comes while the bar is up, or within `gap` after it would go,
joins the bar -- one window (a span, keyed by its first clip) -- and a later
clip's cards SWAP in (`fresh`: the cards up slide up and out as it lands;
a clip's own still stack), so the bar holds one clip's posts and stale cards
never pile up over the footage. With no post soon it leaves (0.45 s). The
bar is over clips only: gone by the dissolve into a card, teaser, image or
the finale.

`shift` spans it: every segment the bar overlaps moves on the cut's clock
(moves carry `phases`, aside at `at` / back at `until`, which the build's
perspective expression, the previews' footageAt and the left panel's
asides all read), so both sides of a dissolve stand aside together and the
footage glides back as the bar leaves.

Absent (or false/null), schedules, windows, holds, moves and pages are
byte-identical (posts-persist.test.mjs, beside schedule, swap, gap, card
limit, ffmpeg-phase and headless-pixel tests). Docs: the Popup posts table
(knobs.md, generated from the module) and its panel fields.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/docs/knobs.md | 1+
Mumtool/lib/report/footage-move.mjs | 19+++++++++++++++++--
Mumtool/report-to-video/build-video.mjs | 13++++++++++++-
Mumtool/report-to-video/chrome-posts.mjs | 22++++++++++++++++------
Mumtool/report-to-video/deck.mjs | 125++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mumtool/report-to-video/flips.mjs | 6+++---
Mumtool/report-to-video/modules/popup-posts.mjs | 8+++++++-
Mumtool/report-to-video/modules/settings.mjs | 25++++++++++++++++++++++++-
Aumtool/report-to-video/posts-persist.test.mjs | 260+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/threads.mjs | 29+++++++++++++++++++++++++++--
10 files changed, 485 insertions(+), 23 deletions(-)

diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -533,6 +533,7 @@ A clip's posts as cards over the footage (`deck.posts`, the `popup` layout), eac | `deck.posts.position` | `top-right` · `top-left` · default `top-right` | same | | `deck.posts.shift` | `false` · `{scale 0.5–1, seconds 0–3}` · default 0.86, 0.6 (the footage moves aside while they are up) | same | | `deck.posts.shotMaxHeight` | null · 120–1080 px · default null (a full card of words) | same | +| `deck.posts.persist` | `true` · `{seconds 8–60, gap 0–30}` · `false`/absent (off: each clip's posts its own short window, as above) · default seconds 12, gap 6. On: the footage NEVER freezes (`hold` is ignored). A card comes up at its moment (`at`, as above) and stays up on its own clock for `seconds`, over clip joins and dissolves. A post whose moment comes while the bar is up, or within `gap` after it would go, keeps it up: a later clip's cards SWAP in (the cards up slide up and out as the new one lands — the bar holds one clip's posts at a time, so stale cards never pile up over the footage), a clip's own still stack. With no post soon it leaves (0.45 s fade). The bar never runs into a card, a teaser, an image or the finale: it is gone by the transition into one. `shift` spans it too: the footage stays aside across the joins the bar spans, every segment moving on the cut's clock, and glides back as the bar leaves (a segment that starts as it leaves comes in at its normal box). Absent, every render is byte for byte what it was | `umtool look <p> deck.posts.persist='{"seconds":12,"gap":6}'` (`deck.posts.persist=` off) | ### Stamps diff --git a/umtool/lib/report/footage-move.mjs b/umtool/lib/report/footage-move.mjs @@ -13,11 +13,14 @@ // the scrubber is in the next segment there is no move; // - before `at` the footage is in its box; over `seconds` it eases to `to`; // after that it stays at `to` to the end of the segment (the hold included). +// - under PERSISTING popups (`posts.persist`) every segment a bar spans has +// a move with `phases` on the cut's clock: aside at `at`, back at `until`. // // The easing is smoothstep, p²(3 − 2p): the curve the build's move uses. /** @typedef {{ x: number, y: number, width: number, height: number }} Rect */ -/** @typedef {{ segment: string, at: number, segmentAt: number, seconds: number, from: Rect, to: Rect }} Move */ +/** @typedef {{ at: number, segmentAt: number, until: number, segmentUntil: number }} Phase */ +/** @typedef {{ segment: string, at: number, segmentAt: number, seconds: number, from: Rect, to: Rect, phases?: Phase[] }} Move */ /** smoothstep on [0, 1], clamped: 0 and 1 outside it. */ export function ease(p) { @@ -43,6 +46,18 @@ export function segmentIdAt(schedule, t) { const lerp = (a, b, p) => a + (b - a) * p; /** + * A persisting popup's move (`posts.persist`, deck.mjs persistMoves): aside + * at each phase's `at`, back at its `until` (cut clock), each over `seconds` + * -- min(1, Σ in·(1 − back)), the build's own sum. + */ +function phasesProgress(m, t) { + const step = (from) => (m.seconds > 0 ? ease((t - from) / m.seconds) : t >= from ? 1 : 0); + let e = 0; + for (const ph of m.phases) e += step(ph.at) * (1 - step(ph.until)); + return Math.min(1, e); +} + +/** * The footage's box at `t`, when the segment on screen has a move: its * eased progress (0 before the move, 1 after it) and the rect between `from` * and `to`. null when the segment on screen has no move -- the footage is in @@ -58,7 +73,7 @@ export function footageAt(schedule, t) { const id = segmentIdAt(schedule, t); const m = moves.find((x) => x.segment === id); if (!m) return null; - const progress = m.seconds > 0 ? ease((t - m.at) / m.seconds) : t >= m.at ? 1 : 0; + const progress = Array.isArray(m.phases) && m.phases.length ? phasesProgress(m, t) : m.seconds > 0 ? ease((t - m.at) / m.seconds) : t >= m.at ? 1 : 0; const rect = { x: lerp(m.from.x, m.to.x, progress), y: lerp(m.from.y, m.to.y, progress), diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -3773,7 +3773,18 @@ export function moveFilter(move, render) { const a = exprNum(move.segmentAt); const p = move.seconds > 0 ? `clip((${t}-${a})/${exprNum(move.seconds)},0,1)` : `gte(${t},${a})`; // smoothstep, 3p² − 2p³: flat at both ends, so the glide starts and lands without a jolt. - const e = (base, d) => `'st(0,${p});${base}+(${exprNum(d)})*ld(0)*ld(0)*(3-2*ld(0))'`; + let e = (base, d) => `'st(0,${p});${base}+(${exprNum(d)})*ld(0)*ld(0)*(3-2*ld(0))'`; + if (Array.isArray(move.phases) && move.phases.length) { + // Persisting popups (deck.mjs persistMoves): aside at each phase's + // `segmentAt`, back at its `segmentUntil`, either possibly outside the + // segment -- e = min(1, Σ S(in)·(1 − S(back))), S the same smoothstep. + const at = (x) => (move.seconds > 0 ? `clip((${t}-(${exprNum(x)}))/${exprNum(move.seconds)},0,1)` : `gte(${t},${exprNum(x)})`); + const S = (k) => `ld(${k})*ld(${k})*(3-2*ld(${k}))`; + const sum = move.phases + .map((ph) => `st(0,${at(ph.segmentAt)});st(1,${at(ph.segmentUntil)});st(2,ld(2)+${S(0)}*(1-${S(1)}))`) + .join(";"); + e = (base, d) => `'st(2,0);${sum};${base}+(${exprNum(d)})*min(1,ld(2))'`; + } const corners = [ ["x0", e("0", dx(0))], ["y0", e("0", dy(0))], ["x1", e("W", dx(W))], ["y1", e("0", dy(0))], diff --git a/umtool/report-to-video/chrome-posts.mjs b/umtool/report-to-video/chrome-posts.mjs @@ -61,9 +61,15 @@ export const POSTS_MOTION = Object.freeze({ enter: 0.55, slide: 0.35, gap: 14, glowAt: 0.3, glowUp: 0.18, glowDown: 1.1, glowRest: 0.3, }); -/** The schedule's posts for one window's segment, in slot order. */ +/** + * The schedule's posts for one window's segment, in slot order -- or, for a + * persisting span (`posts.persist`, keyed by its first clip), every post of + * the span in the order they come up. + */ export function windowPosts(schedule, segment) { - return (schedule.posts ?? []).filter((p) => p.segment === segment).sort((a, b) => a.slot - b.slot); + return (schedule.posts ?? []) + .filter((p) => (p.span ?? p.segment) === segment) + .sort((a, b) => (a.span !== undefined ? a.appear - b.appear : 0) || a.slot - b.slot); } /** @@ -129,9 +135,10 @@ export function postsCues({ for (let j = 0; j < posts.length; j += 1) { const p = posts[j]; const t = p.appear; - // The oldest go until card j fits below what is left. + // The oldest go until card j fits below what is left -- or, a `fresh` + // card (a later clip's, on a persisting bar), every card up goes. const gone = []; - while (visible.length && tops[j] + (heights[j] || 0) - shift > column) { + while (visible.length && (p.fresh || tops[j] + (heights[j] || 0) - shift > column)) { gone.push(visible.shift()); shift = visible.length ? tops[visible[0]] : tops[j]; } @@ -145,7 +152,9 @@ export function postsCues({ add(`g${j}`, t + glowAt + glowUp, glowDown, { opacity: glowRest }, "power2.inOut", `settle ${p.id}`); if (pans[j] > 0) { const landed = t + enter; - const leave = p.out[0]; + // Its leave: the bar's, or a later clip's cards swapping it out first. + const swap = posts.find((q, n) => n > j && q.fresh); + const leave = swap ? Math.min(p.out[0], swap.appear) : p.out[0]; let a = landed + panHold; let b = leave - panHold; if (b - a < 1) { a = landed; b = Math.max(landed + MIN, leave); } @@ -312,7 +321,8 @@ export function postsHtml(schedule, render, window, opts = {}) { glowDown: POSTS_MOTION.glowDown, glowRest: POSTS_MOTION.glowRest, ids: posts.map((p) => p.id), - posts: posts.map((p) => ({ id: p.id, appear: p.appear, out: p.out })), + // `fresh` only on a persisting bar's swap, so every other page is as it was. + posts: posts.map((p) => ({ id: p.id, appear: p.appear, out: p.out, ...(p.fresh ? { fresh: true } : {}) })), }; // `</script>` inside a JSON string would close the tag; nothing in here is // trusted text, but a segment id is the manifest's and costs nothing to guard. diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -27,7 +27,7 @@ import { resolveCounter } from "./counter.mjs"; import { DECK_PAD_X, COUNTER_CELL } from "./modules/design.mjs"; import { DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, markerShapeErrors, - PIP_COLORS, PIP_PITCH_DEFAULT, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SETTINGS, settingValue, SUBTITLE_TOKENS, + PIP_COLORS, PIP_PITCH_DEFAULT, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, QR_LINKS, SETTINGS, settingValue, SUBTITLE_TOKENS, } from "./modules/settings.mjs"; // The deck's settings and their limits live with the modules' validators @@ -35,7 +35,7 @@ import { // they always had. export { DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, PIP_COLORS, PIP_PITCH_DEFAULT, - PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SUBTITLE_TOKENS, + PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, QR_LINKS, SUBTITLE_TOKENS, }; export { SUBTITLE_LINES } from "./modules/settings.mjs"; import { threadOf, threadSchedule, threadsOn, validateThreads } from "./threads.mjs"; @@ -1988,7 +1988,80 @@ export function postSchedule({ posts = [], entries, metas = [], segments, D, tot }); }); }); - return out; + // `posts.persist`: each card stays up on its own clock, across the joins. + const persist = feed ? null : postsPersist(render); + return persist ? persistPosts(out, { segments, entries, D, total, persist }) : out; +} + +/** + * `posts.persist` resolved: `{ seconds, gap }` when the popup posts persist + * across clips, else null (absent, false, or the feed -- which keeps every + * post up anyway). + */ +export function postsPersist(render) { + const p = resolveDeck(render).posts; + if (p.layout === "feed" || !p.persist) return null; + const v = isObj(p.persist) ? p.persist : {}; + return { seconds: v.seconds ?? POST_PERSIST.seconds.default, gap: v.gap ?? POST_PERSIST.gap.default }; +} + +/** How long a persisting bar takes to leave (its cards' fade), in seconds. */ +export const POSTS_PERSIST_LEAVE = 0.45; + +/** + * The popup posts that PERSIST (`posts.persist`): placed as ever (their + * `appear`), then each stays up on its own clock for `seconds` instead of + * leaving with its clip -- over the joins, the footage playing on (no hold). + * Posts whose moments come while the bar is up, or within `gap` after it + * would go, share one SPAN: one page (`span`, its first clip's id, keys the + * window -- postWindows), up from the first post's appear until `seconds` + * after the last's, then out over POSTS_PERSIST_LEAVE (every card of the span + * leaves together, `out`). A clip's own posts are always one span. + * + * A later clip's posts come in as `fresh`: the cards up before them slide up + * and out as they land (chrome-posts.mjs postsCues), so the bar holds one + * clip's posts at a time -- a SWAP between clips, a stack within one. + * + * The bar is drawn over clips only: a span is gone by the transition into the + * first entry after its clip that is not a clip (a card, a teaser, an image) + * or is the finale's, and by the end of the cut. + * + * @returns {Array<object>} the posts, each with `out`, `span` and (a swap) `fresh` + */ +export function persistPosts(placed, { segments, entries = [], D, total, persist }) { + if (!placed.length) return placed; + const idx = new Map(segments.map((s, i) => [s.id, i])); + const run = finaleRunOf(entries) && !finaleRunProblems(entries).length ? finaleRunOf(entries) : null; + const leaveInto = (k) => (D > 0 ? [segments[k].start, segments[k].start + D] : [segments[k].start - 0.3, segments[k].start]); + const limitOf = (i) => { + for (let k = i + 1; k < segments.length; k += 1) { + const type = entries[k]?.type ?? segments[k].type; + if (type !== "clip" || (run && k >= run.first && k <= run.last)) return leaveInto(k); + } + return [total - 0.3, total]; + }; + const order = [...placed].sort((a, b) => a.appear - b.appear || idx.get(a.segment) - idx.get(b.segment) || a.slot - b.slot); + const spanOf = new Map(); + const fresh = new Set(); + const spans = []; + let cur = null; + for (const p of order) { + const joins = cur && (cur.segments.has(p.segment) || (p.appear <= cur.hide + persist.gap && p.appear < cur.limit[0])); + if (!joins) { + cur = { key: p.segment, hide: -Infinity, limit: limitOf(idx.get(p.segment)), segments: new Set() }; + spans.push(cur); + } else if (!cur.segments.has(p.segment)) fresh.add(p.id); + cur.segments.add(p.segment); + cur.hide = Math.max(cur.hide, p.appear + persist.seconds); + spanOf.set(p.id, cur); + } + for (const s of spans) { + s.out = s.hide >= s.limit[0] ? s.limit : [s.hide, Math.min(s.hide + POSTS_PERSIST_LEAVE, s.limit[1])]; + } + return placed.map((p) => { + const s = spanOf.get(p.id); + return { ...p, out: s.out, span: s.key, ...(fresh.has(p.id) ? { fresh: true } : {}) }; + }); } /** What a placed post carries for the page that draws it. */ @@ -2074,10 +2147,12 @@ export function postWindows(schedule) { if (schedule.layout === "feed") return []; const by = new Map(); for (const p of schedule.posts ?? []) { - const w = by.get(p.segment) ?? { segment: p.segment, from: Infinity, to: -Infinity }; + // A persisting span (`posts.persist`) is one window, keyed by its first clip. + const key = p.span ?? p.segment; + const w = by.get(key) ?? { segment: key, from: Infinity, to: -Infinity }; w.from = Math.min(w.from, p.appear); w.to = Math.max(w.to, p.out[1]); - by.set(p.segment, w); + by.set(key, w); } return [...by.values()].sort((a, b) => a.from - b.from); } @@ -2264,8 +2339,10 @@ export function postHolds({ posts = [], entries = [], metas = [], render }) { const settings = resolveDeck(render).posts; const hold = Math.round(settings.hold * fps) / fps; const out = new Map(); - // The feed never pauses the cut: a post is in its column while the clip plays on. - if (!(hold > 0) || settings.layout === "feed") return out; + // The feed never pauses the cut: a post is in its column while the clip + // plays on. Nor do persisting popups (`posts.persist`): the card stays up + // on its own clock instead. + if (!(hold > 0) || settings.layout === "feed" || postsPersist(render)) return out; for (const a of attachPosts({ posts, entries, metas })) out.set(a.entryId, hold); return out; } @@ -2286,6 +2363,7 @@ export function footageMoves({ posts, segments, render }) { if (!to) return []; const from = deckGeometry(render).footage; const seconds = resolveDeck(render).posts.shift.seconds; + if (posts.some((p) => p.span !== undefined)) return persistMoves({ posts, segments, from, to, seconds }); const first = new Map(); for (const p of posts) first.set(p.segment, Math.min(first.get(p.segment) ?? Infinity, p.appear)); return segments @@ -2293,6 +2371,39 @@ export function footageMoves({ posts, segments, render }) { .map((s) => ({ segment: s.id, at: first.get(s.id), segmentAt: first.get(s.id) - s.start, seconds, from, to })); } +/** + * The footage moves under PERSISTING popups (`posts.persist`): the footage is + * aside for as long as a span's bar is up, across the joins it spans -- every + * segment the span overlaps moves on the CUT's clock, so the two sides of a + * dissolve stand at the same place -- and it glides back as the bar leaves. + * Each move carries its `phases`: `{ at, segmentAt, until, segmentUntil }`, + * aside over `seconds` from `at`, back over `seconds` from `until` (cut + * clock; `segment…` in the segment's own, which may be negative or past its + * end). `at`/`segmentAt` are the first phase's, for the readers that take one. + * A segment that starts once the bar is leaving comes in at its normal box. + * + * @returns {Array<{ segment, at, segmentAt, seconds, from, to, phases }>} + */ +function persistMoves({ posts, segments, from, to, seconds }) { + const R = (v) => Math.round(v * 1000) / 1000; + const spans = new Map(); + for (const p of posts) { + const s = spans.get(p.span) ?? { at: Infinity, until: p.out[0] }; + s.at = Math.min(s.at, p.appear); + spans.set(p.span, s); + } + const out = []; + for (const seg of segments) { + const end = seg.start + seg.duration; + const phases = [...spans.values()] + .filter((s) => seg.start < s.until && end > s.at) + .sort((a, b) => a.at - b.at) + .map((s) => ({ at: R(s.at), segmentAt: R(s.at - seg.start), until: R(s.until), segmentUntil: R(s.until - seg.start) })); + if (phases.length) out.push({ segment: seg.id, at: phases[0].at, segmentAt: phases[0].segmentAt, seconds, from, to, phases }); + } + return out; +} + // --------------------------------------------------------------------------- // Cut edits made where the cut is joined, like the hold: a clip's `muteFrom` // and the cut's `render.endFade`. Neither touches a segment file, so diff --git a/umtool/report-to-video/flips.mjs b/umtool/report-to-video/flips.mjs @@ -18,7 +18,7 @@ // The limits and the validators are common's (lib/report/panels.mjs, release // 28): the flips draft task checks exactly what the build refuses. import { FLIPS_LIMITS, flipsOn, validateFlipEntries, validateFlips } from "yt-dlp-transcript-common/lib/report/panels.mjs"; -import { planCues } from "./threads.mjs"; +import { asidesOf, planCues } from "./threads.mjs"; export { FLIPS_LIMITS, flipsOn, validateFlipEntries, validateFlips }; @@ -69,9 +69,9 @@ export function flipSchedule({ segments, total, render, moves = [] }) { .filter((p) => p.then && p.now) .sort((a, b) => a.then.from - b.then.from) .map((p, i, all) => ({ ...p, index: i + 1, of: all.length })); - const asides = moves.map((m) => { + const asides = asidesOf(moves, (m) => { const i = idx.get(m.segment); - return { from: R(m.at), to: R(i === undefined ? total : endOf(i)) }; + return R(i === undefined ? total : endOf(i)); }); return { pairs, asides }; } diff --git a/umtool/report-to-video/modules/popup-posts.mjs b/umtool/report-to-video/modules/popup-posts.mjs @@ -8,7 +8,7 @@ import path from "node:path"; import { postsGeometry, postWindows, resolveDeck, snapWindow } from "../deck.mjs"; import { postsHtml, windowPosts } from "../chrome-posts.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; -import { DECK_DEFAULTS, POST_AT, POST_LAYOUTS, POST_LINKS, settingsOf } from "./settings.mjs"; +import { DECK_DEFAULTS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, settingsOf } from "./settings.mjs"; const SEGMENT_RE = /^[A-Za-z0-9_-]+$/; @@ -37,6 +37,11 @@ export default defineModule({ { key: "hold", type: "number", min: 0, max: 10, step: 0.5, label: "Hold (s)", default: DECK_DEFAULTS.posts.hold }, { key: "position", type: "enum", options: ["top-right", "top-left"], label: "Side", default: "top-right" }, { key: "shotMaxHeight", type: "number", min: 120, max: 1080, label: "Screenshot height cap", default: null }, + // `persist` (opt-in): the cards stay up on their own clock across clips; no hold. + { key: "persist.seconds", type: "number", min: POST_PERSIST.seconds.min, max: POST_PERSIST.seconds.max, step: 1, + label: "Persist across clips: seconds up", default: null }, + { key: "persist.gap", type: "number", min: POST_PERSIST.gap.min, max: POST_PERSIST.gap.max, step: 1, + label: "Persist: stay up for a post within (s)", default: null }, ], docs: { heading: "Popup posts", @@ -47,6 +52,7 @@ export default defineModule({ ["`deck.posts.position`", "`top-right` · `top-left` · default `top-right`", "same"], ["`deck.posts.shift`", "`false` · `{scale 0.5–1, seconds 0–3}` · default 0.86, 0.6 (the footage moves aside while they are up)", "same"], ["`deck.posts.shotMaxHeight`", "null · 120–1080 px · default null (a full card of words)", "same"], + ["`deck.posts.persist`", "`true` · `{seconds 8–60, gap 0–30}` · `false`/absent (off: each clip's posts its own short window, as above) · default seconds 12, gap 6. On: the footage NEVER freezes (`hold` is ignored). A card comes up at its moment (`at`, as above) and stays up on its own clock for `seconds`, over clip joins and dissolves. A post whose moment comes while the bar is up, or within `gap` after it would go, keeps it up: a later clip's cards SWAP in (the cards up slide up and out as the new one lands — the bar holds one clip's posts at a time, so stale cards never pile up over the footage), a clip's own still stack. With no post soon it leaves (0.45 s fade). The bar never runs into a card, a teaser, an image or the finale: it is gone by the transition into one. `shift` spans it too: the footage stays aside across the joins the bar spans, every segment moving on the cut's clock, and glides back as the bar leaves (a segment that starts as it leaves comes in at its normal box). Absent, every render is byte for byte what it was", "`umtool look <p> deck.posts.persist='{\"seconds\":12,\"gap\":6}'` (`deck.posts.persist=` off)"], ], }, region: "posts", diff --git a/umtool/report-to-video/modules/settings.mjs b/umtool/report-to-video/modules/settings.mjs @@ -137,6 +137,16 @@ export const POST_AT = Object.freeze(["end", "start"]); export const POST_LAYOUTS = Object.freeze(["popup", "feed"]); /** Where a post's QR links (`posts.links`): its page on the archive, or the platform's own link. */ export const POST_LINKS = Object.freeze(["archive", "original"]); +/** + * Popup posts that PERSIST (`posts.persist`, opt-in): a card stays up on its + * own clock for `seconds` after it comes up, across clip joins, while the + * footage plays on (no hold); a post coming up within that, or within `gap` + * after it, keeps the bar up. Each with its bounds and default. + */ +export const POST_PERSIST = Object.freeze({ + seconds: Object.freeze({ min: 8, max: 60, default: 12 }), + gap: Object.freeze({ min: 0, max: 30, default: 6 }), +}); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; @@ -330,8 +340,21 @@ export function validateQrSettings(d, { where: w }) { /** The posts (the popup cards and the feed): every `deck.posts` setting. */ export function validatePostsSettings(d, { where: w }) { const errors = []; - sub(d, "posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr"], w, errors, (p) => { + sub(d, "posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr", "persist"], w, errors, (p) => { if (p.qr !== undefined && typeof p.qr !== "boolean") errors.push(`${w}.posts.qr must be true or false`); + // `persist`: true (the defaults), { seconds?, gap? }, or false/null (off). + if (p.persist !== undefined && p.persist !== null && typeof p.persist !== "boolean") { + if (!isObj(p.persist)) errors.push(`${w}.posts.persist must be true, false or { seconds, gap }`); + else { + unknownKeys(p.persist, ["seconds", "gap"], `${w}.posts.persist`, errors); + for (const k of ["seconds", "gap"]) { + const b = POST_PERSIST[k]; + if (p.persist[k] !== undefined && !numIn(p.persist[k], b.min, b.max)) { + errors.push(`${w}.posts.persist.${k} must be from ${b.min} to ${b.max} seconds`); + } + } + } + } if (p.at !== undefined && !POST_AT.includes(p.at)) { errors.push(`${w}.posts.at must be ${POST_AT.map((a) => `"${a}"`).join(" or ")}`); } diff --git a/umtool/report-to-video/posts-persist.test.mjs b/umtool/report-to-video/posts-persist.test.mjs @@ -0,0 +1,260 @@ +// Popup posts that PERSIST (`render.chrome.deck.posts.persist`): a card stays +// up on its own clock across clip joins, the footage playing on; close posts +// share one bar (a later clip's swap in), and the bar leaves when none follows +// soon. Absent, every schedule and page is what it was. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +import { postsCues, postsHtml, snapWindow, windowPosts } from "./chrome-posts.mjs"; +import { + POSTS_PERSIST_LEAVE, deckSchedule, footageMoves, postHolds, postSchedule, postWindows, postsPersist, shiftedFootage, + deckGeometry, validateChrome, +} from "./deck.mjs"; +import { asidesOf } from "./threads.mjs"; +import { footageAt } from "../lib/report/footage-move.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; +const renderOf = (posts = {}) => ({ + width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, + chrome: { engine: "hyperframes", layout: "deck", deck: { posts } }, +}); +const POST = (id, attachTo, extra = {}) => ({ + id, platform: "bluesky", author: "A", handle: "a.example", date: "2024-10-01", attachTo, + text: `words of ${id}`, url: `https://bsky.app/profile/a.example/post/${id}`, ...extra, +}); + +// Four 20 s clips under 0.5 s dissolves: starts 0, 19.5, 39, 58.5; the cut is 78.5 s. +const CLIPS = ["c1", "c2", "c3", "c4"].map((id) => ({ id, type: "clip", date: "2024-09-01" })); +const SEGS = CLIPS.map((c, i) => ({ id: c.id, start: i * 19.5, duration: 20 })); +const TOTAL = 78.5; +const place = (posts, persist, { entries = CLIPS, segments = SEGS, total = TOTAL } = {}) => + postSchedule({ posts, entries, segments, D: 0.5, total, render: renderOf(persist === undefined ? {} : { persist }) }); +const byId = (placed) => Object.fromEntries(placed.map((p) => [p.id, p])); + +test("validation: persist is true, false/null, or { seconds 8–60, gap 0–30 }", () => { + const ok = (persist) => validateChrome(renderOf({ persist }).chrome, renderOf({ persist })); + for (const v of [true, false, null, {}, { seconds: 8 }, { seconds: 60, gap: 0 }, { gap: 30 }]) assert.deepEqual(ok(v), [], JSON.stringify(v)); + assert.match(ok({ seconds: 5 }).join(), /posts\.persist\.seconds must be from 8 to 60 seconds/); + assert.match(ok({ gap: 31 }).join(), /posts\.persist\.gap must be from 0 to 30 seconds/); + assert.match(ok({ hold: 2 }).join(), /posts\.persist\.hold is not a deck setting/); + assert.match(ok("yes").join(), /posts\.persist must be true, false or \{ seconds, gap \}/); + assert.deepEqual(postsPersist(renderOf({ persist: true })), { seconds: 12, gap: 6 }); + assert.deepEqual(postsPersist(renderOf({ persist: { seconds: 20 } })), { seconds: 20, gap: 6 }); + assert.equal(postsPersist(renderOf({ persist: false })), null); + assert.equal(postsPersist(renderOf({})), null); + // The feed keeps every post up anyway: persist is not its. + assert.equal(postsPersist(renderOf({ persist: true, layout: "feed" })), null); +}); + +test("absent persist: the schedule, the windows, the holds and the page are what they were (false and null alike)", () => { + const posts = [POST("a", "c1"), POST("b", "c2"), POST("b2", "c2")]; + const plain = place(posts); + for (const v of [false, null]) assert.deepEqual(place(posts, v), plain); + for (const p of plain) assert.ok(!("span" in p) && !("fresh" in p), "no persist keys"); + assert.deepEqual(postWindows({ posts: plain }).map((w) => w.segment), ["c1", "c2"]); + const entries = CLIPS; + assert.equal(postHolds({ posts, entries, render: renderOf({}) }).get("c1"), 2.5); + const sched = { fps: 30, total: TOTAL, posts: plain }; + const win = snapWindow(postWindows(sched)[1], { fps: 30, total: TOTAL }); + const html = postsHtml(sched, renderOf({}), win, {}); + assert.equal(postsHtml({ ...sched, posts: place(posts, false) }, renderOf({ persist: false }), win, {}), html); + assert.doesNotMatch(html, /"fresh"/); +}); + +test("persist: a card stays up across the join, the bar runs to `seconds` after the last post, and nothing is held", () => { + const posts = [POST("a", "c1")]; + const p = byId(place(posts, { seconds: 12, gap: 6 })).a; + // At its clip's end as ever (A = c2's start, 19.5, less posts.seconds 4)... + assert.equal(p.appear, 15.5); + // ...and up for 12 s on its own clock: past the join at 19.5–20, out over POSTS_PERSIST_LEAVE. + assert.deepEqual(p.out, [27.5, 27.5 + POSTS_PERSIST_LEAVE]); + assert.equal(p.span, "c1"); + const w = postWindows({ posts: [p] }); + assert.deepEqual(w, [{ segment: "c1", from: 15.5, to: 27.95 }]); + assert.ok(w[0].to > SEGS[1].start + 0.5, "the window runs over the join into c2"); + // The footage never freezes. + assert.equal(postHolds({ posts, entries: CLIPS, render: renderOf({ persist: true }) }).size, 0); + const s = deckSchedule({ entries: CLIPS, durs: SEGS.map((x) => x.duration), D: 0.5, render: renderOf({ persist: true }), posts }); + assert.ok(s.segments.every((x) => !("hold" in x))); + assert.equal(s.total, TOTAL); +}); + +test("persist: a later clip's post within the bar (or the gap after it) joins it and swaps in; one past the gap opens a new bar", () => { + const posts = [POST("a", "c1"), POST("b", "c2"), POST("b2", "c2"), POST("d", "c4")]; + const near = byId(place(posts, { seconds: 12, gap: 8 })); + // c2's two posts come up a posts.seconds apart before its dissolve out (39): 31, 35. + assert.equal(near.b.appear, 31); + assert.equal(near.b2.appear, 35); + // a's bar would go at 27.5; b's moment, 31, is within its gap of 8: one bar. + assert.equal(near.b.span, "c1"); + assert.equal(near.b2.span, "c1"); + assert.equal(near.b.fresh, true, "the first of a later clip's posts swaps the bar's cards out"); + assert.ok(!("fresh" in near.b2), "the clip's own next one stacks"); + assert.ok(!("fresh" in near.a)); + // The bar runs to 12 s after the last post on it, every card out together. + for (const id of ["a", "b", "b2"]) assert.deepEqual(near[id].out, [47, 47 + POSTS_PERSIST_LEAVE]); + // d (c4: appear 74.2) is past 47 + 8: a bar of its own, ending with the cut. + assert.equal(near.d.span, "c4"); + assert.deepEqual(near.d.out, [TOTAL - 0.3, TOTAL]); + assert.deepEqual(postWindows({ posts: Object.values(near) }).map((w) => [w.segment, w.from, w.to]), [["c1", 15.5, 47.45], ["c4", 74.2, 78.5]]); + // The page for the span: every post of it, in the order they come up. + assert.deepEqual(windowPosts({ posts: Object.values(near) }, "c1").map((p) => p.id), ["a", "b", "b2"]); + + // A gap too short: a's bar goes at 27.5 and b's opens at 31. + const far = byId(place(posts, { seconds: 12, gap: 2 })); + assert.equal(far.a.span, "c1"); + assert.deepEqual(far.a.out, [27.5, 27.95]); + assert.equal(far.b.span, "c2"); + assert.ok(!("fresh" in far.b), "the first post of a bar is not a swap"); +}); + +test("persist: the bar is over clips only -- gone by the dissolve into a card (or the finale), and a post after it starts anew", () => { + const entries = [CLIPS[0], { id: "k1", type: "card" }, CLIPS[1], CLIPS[2]]; + const segments = entries.map((e, i) => ({ id: e.id, start: i * 19.5, duration: 20 })); + const posts = [POST("a", "c1"), POST("b", "c2")]; + const p = byId(place(posts, { seconds: 30, gap: 30 }, { entries, segments })); + assert.deepEqual(p.a.out, [19.5, 20], "out with the dissolve into the card, as a clip's posts always left"); + assert.equal(p.b.span, "c2"); + // The finale: its clips are the end of any bar. + const fin = [CLIPS[0], CLIPS[1], { ...CLIPS[2], layout: "finale" }]; + const segs3 = fin.map((e, i) => ({ id: e.id, start: i * 19.5, duration: 20 })); + const q = byId(place([POST("a", "c1")], { seconds: 60, gap: 0 }, { entries: fin, segments: segs3, total: 59 })); + assert.deepEqual(q.a.out, [39, 39.5]); +}); + +test("persist + shift: the footage is aside across the joins the bar spans, on the cut's clock, and glides back as it leaves", () => { + const render = renderOf({ persist: { seconds: 12, gap: 8 } }); + const posts = [POST("a", "c1"), POST("b", "c2")]; + const placed = postSchedule({ posts, entries: CLIPS, segments: SEGS, D: 0.5, total: TOTAL, render }); + const moves = footageMoves({ posts: placed, segments: SEGS, render }); + // a: 15.5; b: 35 (its clip's end); the bar leaves at 47 -- inside c3. + assert.deepEqual(moves.map((m) => m.segment), ["c1", "c2", "c3"]); + const phase = { at: 15.5, until: 47 }; + for (const m of moves) { + const s = SEGS.find((x) => x.id === m.segment); + assert.deepEqual(m.phases, [{ ...phase, segmentAt: Math.round((15.5 - s.start) * 1000) / 1000, segmentUntil: Math.round((47 - s.start) * 1000) / 1000 }]); + assert.equal(m.at, 15.5); + assert.deepEqual(m.to, shiftedFootage(render)); + assert.deepEqual(m.from, deckGeometry(render).footage); + } + // The preview's box: aside after the glide, on both sides of the join and through it; back after the bar. + const sched = { segments: SEGS, moves }; + assert.equal(footageAt(sched, 15.4).progress, 0); + for (const t of [16.2, 19.4, 19.6, 20.2, 30, 46.9]) assert.equal(footageAt(sched, t).progress, 1, `aside at ${t}`); + assert.ok(footageAt(sched, 47.3).progress > 0 && footageAt(sched, 47.3).progress < 1, "gliding back"); + assert.equal(footageAt(sched, 47.7).progress, 0); + assert.equal(footageAt(sched, 60), null, "c4 never moves"); + // The left panel steps aside once for the whole bar. + assert.deepEqual(asidesOf(moves, () => 0), [{ from: 15.5, to: 47 }]); +}); + +test("postsCues: a fresh card swaps the bar -- every card up slides up and out as it lands; without fresh, as before", () => { + const posts = [ + { id: "a", appear: 1, out: [20, 20.45] }, + { id: "a2", appear: 3, out: [20, 20.45] }, + { id: "b", appear: 9, out: [20, 20.45], fresh: true }, + ]; + const plan = postsCues({ posts, heights: [200, 200, 200], column: 900 }); + const at9 = plan.cues.filter((c) => c.at === 9); + assert.deepEqual(at9.filter((c) => c.k === "stack").map((c) => c.to), [{ y: -428 }], "the stack moves the new card to the top"); + assert.deepEqual(at9.filter((c) => c.why === "slide for b").map((c) => c.k).sort(), ["c0", "c1", "stack"]); + assert.ok(plan.cues.some((c) => c.k === "c2" && c.why === "enter b" && c.at === 9)); + assert.ok(!plan.cues.some((c) => c.why === "leave a"), "a swapped card does not leave again"); + assert.ok(plan.cues.some((c) => c.why === "leave b" && c.at === 20)); + // The same posts without the flag stack as they always did: nobody slides out. + const stacked = postsCues({ posts: posts.map(({ fresh: _f, ...p }) => p), heights: [200, 200, 200], column: 900 }); + assert.ok(!stacked.cues.some((c) => c.k === "stack")); +}); + +test("ffmpeg: a persisting move's phases -- aside before the segment starts, back inside it -- parse and move the picture", { skip: !have("ffmpeg", ["-version"]) }, async () => { + const { joinInputChain } = await import("./build-video.mjs"); + const dir = mkdtempSync(path.join(tmpdir(), "persist-ff-")); + try { + const render = renderOf({ persist: true }); + const move = { + segment: "c2", at: 15.5, segmentAt: -4, seconds: 0.6, from: deckGeometry(render).footage, to: shiftedFootage(render), + phases: [{ at: 15.5, segmentAt: -4, until: 21, segmentUntil: 1.5 }], + }; + const runChain = (m, name) => { + const c = joinInputChain(0, { hold: 0, move: m }, render); + const out = path.join(dir, name); + const res = spawnSync("ffmpeg", ["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i", "testsrc2=s=1920x1080:r=30:d=3", + "-filter_complex", `${c.parts.join(";")};${c.v}format=rgb24[o]`, "-map", "[o]", "-f", "rawvideo", out], { maxBuffer: 1 << 28 }); + assert.equal(res.status, 0, String(res.stderr)); + return readFileSync(out); + }; + const a = runChain(move, "o.rgb"); + // The same chain with the bar never up: the picture in its box (the + // move's edge pinning included), what "back" must equal. + const b = runChain({ ...move, phases: [{ at: 99, segmentAt: 99, until: 100, segmentUntil: 100 }] }, "p.rgb"); + const F = 1920 * 1080 * 3; + const frame = (buf, n) => buf.subarray(n * F, (n + 1) * F); + assert.ok(!frame(a, 0).equals(frame(b, 0)), "aside from its first frame (the bar came up before it)"); + assert.ok(!frame(a, 30).equals(frame(b, 30)), "still aside at 1 s"); + assert.ok(frame(a, 75).equals(frame(b, 75)), "back in its box once the bar has gone (2.5 s)"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + +// --------------------------------------------------------------------------- +// The pixels: the page a persisting bar is drawn by, seeked as the renderer seeks. +// --------------------------------------------------------------------------- + +function have(b, a) { + return spawnSync(b, a, { stdio: "ignore" }).status === 0; +} +const haveChromium = have("qrencode", ["-V"]) && have("magick", ["-version"]) && have(process.env.CHROME ?? "/usr/bin/chromium", ["--version"]); + +function inked(png, x, y, w, h) { + const r = spawnSync("magick", [png, "-crop", `${w}x${h}+${x}+${y}`, "+repage", "-depth", "8", "rgba:-"], { maxBuffer: 1 << 26 }); + let n = 0; + for (let i = 3; i < r.stdout.length; i += 4) if (r.stdout[i] > 128) n += 1; + return n / (r.stdout.length / 4); +} + +test("pixels: the card is up across the join and after it, swapped for the next clip's, and gone when no post follows", { skip: !haveChromium }, async () => { + const { composeChrome } = await import("./compose-chrome.mjs"); + const dir = mkdtempSync(path.join(tmpdir(), "persist-px-")); + try { + const render = { + ...renderOf({ persist: { seconds: 12, gap: 8 } }), + fontRegular: path.join(HERE, "fonts", "IBMPlexMono-Regular.ttf"), + fontBold: path.join(HERE, "fonts", "IBMPlexMono-Bold.ttf"), + }; + const manifestPath = path.join(dir, "video.manifest.json"); + writeFileSync(manifestPath, JSON.stringify({ slug: "t", title: "t", provenance: {}, render, timeline: [] })); + const posts = postSchedule({ posts: [POST("a", "c1"), POST("b", "c2")], entries: CLIPS, segments: SEGS, D: 0.5, total: TOTAL, render }); + const sched = { + version: 1, kind: "deck", estimated: false, fps: 30, transition: 0.5, total: TOTAL, multiChannel: false, + segments: SEGS.map((s) => ({ ...s, type: "clip", end: s.start + s.duration, title: "", subtitle: "", qrUrl: null, hideDeck: false })), + posts, + }; + const [window] = postWindows(sched); + assert.deepEqual([window.segment, window.from, window.to], ["c1", 15.5, 47.45]); + const still = async (t) => { + const png = path.join(dir, `still-${t}.png`); + await composeChrome({ manifestPath, region: "posts", schedule: sched, window, still: t, png }); + return png; + }; + // The top card's band of the column (the region is the posts column). + const band = [40, 20, 500, 120]; + assert.ok(inked(await still(15.3), ...band) < 0.01, "nothing before the first post"); + for (const t of [17, 19.75, 21, 29]) assert.ok(inked(await still(t), ...band) > 0.3, `the card is up at ${t} (the join is 19.5–20)`); + // b swaps in at 35 and stays to 47; the bar leaves by 47.45. + const html = readFileSync(path.join(dir, "out", "sourced", "chrome", "posts-c1", "index.html"), "utf8"); + assert.match(html, /"id":"b","appear":35,"out":\[47,47\.45\],"fresh":true/); + assert.ok(inked(await still(40), ...band) > 0.3, "the next clip's card is up"); + assert.ok(inked(await still(47.44), ...band) < 0.05, "gone as the bar leaves"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/threads.mjs b/umtool/report-to-video/threads.mjs @@ -39,6 +39,31 @@ export const THREAD_MOTION = Object.freeze({ /** How long before its thread's last clip ends the outcome lands, at most. */ export const OUTCOME_LEAD = 1.8; +/** + * When the left panel steps aside for the popup posts' footage moves: one + * `{from, to}` per move, `to` its segment's end (`endOf(m)`) -- or, under + * PERSISTING popups (a move's `phases`, deck.mjs persistMoves), each phase's + * own span, from `at` to `until`, once however many segments it crosses. + */ +export function asidesOf(moves, endOf) { + const R = (v) => Math.round(v * 1000) / 1000; + const out = []; + const seen = new Set(); + for (const m of moves) { + if (!Array.isArray(m.phases)) { + out.push({ from: R(m.at), to: endOf(m) }); + continue; + } + for (const ph of m.phases) { + const key = `${ph.at}|${ph.until}`; + if (seen.has(key)) continue; + seen.add(key); + out.push({ from: R(ph.at), to: R(ph.until) }); + } + } + return out; +} + const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** @@ -92,9 +117,9 @@ export function threadSchedule({ segments, D, total, render, moves = [] }) { t.clips.push({ segment: s.id, at: R(i === 0 ? s.start : s.start + D / 2) }); last.set(t.id, i); }); - const asides = moves.map((m) => { + const asides = asidesOf(moves, (m) => { const i = segments.findIndex((s) => s.id === m.segment); - return { from: R(m.at), to: R(i < 0 ? total : endOf(i)) }; + return R(i < 0 ? total : endOf(i)); }); for (const t of threads) { if (!t.outcome || !last.has(t.id)) continue;