Archilyzer · Source

archilyzer

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

commit 2b6fcbdb3298966d08d43200d5f8ba1403adb773
parent 492bc565db7072c6b71ec92ca1d94a2af4fec66f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 13:13:59 -0500

umtool: the branch map is its own layer, laid over the attachments' slot (or beside a card alone), never over words being read (the build shoots it on a transparent page; Play lays the same markup); a direct reply draws none, a read back up the stack says "back to @X's post"; the join anchors on the post's head; a post the run had on screen grows from where it was when the item reads it again

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

Diffstat:
Mumtool/components/projects/review/PostItemPlayer.tsx | 27++++++++++++++++++++++-----
Mumtool/report-to-video/post-branch-map.mjs | 43+++++++++++++++++++++++++++++++++++++++----
Mumtool/report-to-video/post-item.mjs | 6++----
Mumtool/report-to-video/post-render.mjs | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mumtool/report-to-video/post-thread-scenes.test.mjs | 11+++++++++--
Mumtool/report-to-video/post-thread.mjs | 10++++++++--
6 files changed, 159 insertions(+), 26 deletions(-)

diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { POST_PUSH, mediaTimeAt, postLayout, stepAt, stepBoxes } from "umtool-report-to-video/post-item"; import { applyJoinState, endMediaOf, joinFrameAt } from "umtool-report-to-video/post-join"; import { applyVisitState } from "umtool-report-to-video/post-link-visit"; -import { applyMapState } from "umtool-report-to-video/post-branch-map"; +import { applyMapState, mapHtml, mapPlace, mapSize } from "umtool-report-to-video/post-branch-map"; import { dryGainAt, mixPhaseAt, pickedTake, wetGainAt } from "umtool-report-to-video/post-narration"; import { applyFollowState, followPath, followStateAt, measureFollow } from "umtool-report-to-video/read-follow"; import { scrollAt, showOpacityAt } from "umtool-report-to-video/post-thread"; @@ -523,7 +523,7 @@ export default function PostItemPlayer({ const card = doc.querySelector("[data-post-card]"); if (!card) return; const c = card.getBoundingClientRect(); - const post = doc.querySelector('[data-thread-slot="post"]') ?? card.querySelector(".head"); + const post = doc.querySelector('[data-thread-slot="post"] .head') ?? card.querySelector(".head"); const pl = postLayout(joinFrom.entry, box); joinMeasure.current = { A: { x: c.left, y: c.top, width: c.width, height: c.height }, anchor: post ? post.getBoundingClientRect().top - c.top : null, slotA: pl.slot && pl.mode === "side" ? pl.slot : null }; setJoinReady((n) => n + 1); @@ -549,7 +549,11 @@ export default function PostItemPlayer({ if (geo && jm && jm.anchor !== null) { const c = card?.getBoundingClientRect(); const w = doc.querySelector("[data-post-words]")?.getBoundingClientRect(); - if (c && w) (geo as Record<string, unknown>).joinAnchor = { y: Math.round((jm.anchor / (jm.A.width / c.width) - (w.top - c.top)) * 100) / 100 }; + const tile = doc.querySelector("[data-join-anchor]"); + const head = tile?.querySelector(".head")?.getBoundingClientRect(); + const slot = tile?.closest("[data-thread-slot]")?.getBoundingClientRect(); + const off = head && slot ? head.top - slot.top : 0; + if (c && w) (geo as Record<string, unknown>).joinAnchor = { y: Math.round((jm.anchor / (jm.A.width / c.width) - (w.top - c.top) - off) * 100) / 100 }; } setFollowGeo(geo); const route = follow && geo ? followPath(follow, geo) : null; @@ -627,6 +631,18 @@ export default function PostItemPlayer({ applyJoinState(jp, doc); }, [jp, joinReady, layout]); const jframe = jp !== null && joinMeasure.current && ownBox ? joinFrameAt({ A: joinMeasure.current.A, B: ownBox, slotA: joinMeasure.current.slotA, slotB: layout.slot && layout.mode === "side" ? layout.slot : null, same: false }, jp) : null; + // THE BRANCH MAP (post-branch-map.mjs): its own layer over the attachments, where the build lays it. + const branchMap = (follow?.thread as { map?: Record<string, unknown> } | undefined)?.map ?? null; + const mapRef = useRef<HTMLDivElement | null>(null); + const mapBox = useMemo(() => { + if (!branchMap) return null; + const k = box.height / 1080; + const size = mapSize(branchMap as never, k); + return { ...mapPlace(layout as never, box, size, k), ...size, html: mapHtml(branchMap as never, { k }) }; + }, [branchMap, box, layout]); + useEffect(() => { + if (mapRef.current) applyMapState((followNow?.map ?? null) as never, mapRef.current as unknown as Document); + }, [followNow, mapBox]); const joinEnds = useMemo(() => (joinFrom ? endMediaOf(joinFrom.plan as never, { stepAt, mediaTimeAt }) : []), [joinFrom]); useEffect(() => { const doc = readFrame.current?.contentDocument; @@ -634,8 +650,6 @@ export default function PostItemPlayer({ // A LINK VISIT (post-link-visit.mjs): the pointer and its click, as the build draws them. const visits = (follow as { visits?: unknown[] } | null)?.visits; if (doc && visits?.length) applyVisitState({ visits, st: followNow?.visit ?? null }, doc); - // THE BRANCH MAP (post-branch-map.mjs), as the build draws it. - if (doc && follow?.thread && (follow.thread as { map?: unknown }).map) applyMapState(followNow?.map ?? null, doc); }, [follow, followNow, followGeo]); const src = shown && inStep ? mediaTimeAt(shown, s) : null; const cue = wordsRel && src !== null ? (cues[wordsRel] ?? []).find((c) => src >= c.start && src < c.end) ?? null : null; @@ -712,6 +726,9 @@ export default function PostItemPlayer({ // THE PANEL (post-thread.mjs panelSchedule): a context post's attachment over the slot while it is on screen. <PanelShows project={project} shows={plan.panel.shows} fade={plan.panel.fade} slot={layout.slot} box={box} s={s} /> )} + {mapBox && ( + <div ref={mapRef} data-post-branch-map="" className="pointer-events-none absolute z-20" style={{ left: pct(mapBox.x, box.width), top: pct(mapBox.y, box.height), transform: `scale(${scale || 1})`, transformOrigin: "0 0" }} dangerouslySetInnerHTML={{ __html: mapBox.html }} /> + )} {jframe && joinFrom && ( // THE JOIN: what the item before ended on in its slot, fading out (the same attachment is held, not drawn twice). <JoinEnds project={project} ends={joinEnds} layout={postLayout(joinFrom.entry, box)} box={box} op={jframe.slotFrom < 1 || !shown || joinEnds[0]?.m?.src !== shown.items[0]?.src ? 1 - jframe.e : 0} /> diff --git a/umtool/report-to-video/post-branch-map.mjs b/umtool/report-to-video/post-branch-map.mjs @@ -70,8 +70,8 @@ export function branchMapOf(tiles, { prevId, nowId, subject = "", style = "both" const a = up(prevId); const b = up(nowId); const shared = a.find((id) => b.includes(id)) ?? null; - // The new post answers the one before it directly (no branch change): no map, but in a manual thread with a jump. - if (shared === prevId && !group) return null; + // The new post answers the one before it directly (no branch change): no map. + if (shared === prevId) return null; // No post shared: through the post the new one answers when it is on screen (a manual thread's reply up the stack). const via = !shared && parentOf(nowId) && parentOf(nowId) !== prevId ? parentOf(nowId) : null; const path = shared ? [...a.slice(0, a.indexOf(shared) + 1), ...b.slice(0, b.indexOf(shared)).reverse()] : via ? [prevId, via, nowId] : [prevId, nowId]; @@ -89,7 +89,10 @@ export function branchMapOf(tiles, { prevId, nowId, subject = "", style = "both" const sh = shared ? byId.get(shared) : via ? byId.get(via) : null; const isHim = (t) => !!subject && str(t?.handle).toLowerCase() === subject.toLowerCase(); const who = sh ? (isHim(sh) ? "his" : sh.handle ? `@${sh.handle}'s` : "the") : null; - const label = !sh ? "a new thread" : shared === nowId ? `back to ${who} post` : `another reply to ${who} post`; + // Back up the stack to a post on screen (the post he answers, read again): "back to"; else a sibling's. + const nowT = byId.get(nowId); + const back = !sh && nowT && nowT.scope !== "post" ? (isHim(nowT) ? "his" : nowT.handle ? `@${nowT.handle}'s` : "the") : null; + const label = back ? `back to ${back} post` : !sh ? "a new thread" : shared === nowId ? `back to ${who} post` : `another reply to ${who} post`; return { style, nodes, edges, path, label, from: prevId, to: nowId, shared }; } @@ -145,7 +148,7 @@ export function mapHtml(map, { k = 1, accent = "#c8752a", fg = "#f6f1e6", muted const text = label && blur.has(label.toLowerCase()) ? map.label.replace(`@${label}'s`, "a stranger's") : map.label; const showMap = map.style !== "label"; const showLabel = map.style !== "map"; - return `<div data-thread-map="${esc(map.style)}" data-map-path='${esc(JSON.stringify(pts))}' style="position:absolute;z-index:6;display:none;right:${Math.round(22 * k)}px;top:${Math.round(22 * k)}px;padding:${Math.round(10 * k)}px;border-radius:${Math.round(12 * k)}px;background:rgba(0,0,0,0.55);pointer-events:none;text-align:right">${showMap ? `<svg width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" style="display:block;margin-left:auto">${lines.join("")}${dots.join("")}<circle data-map-light="" cx="${pts[0][0]}" cy="${pts[0][1]}" r="${r + Math.round(4 * k)}" fill="none" stroke="#ffcf33" stroke-width="${Math.max(2, 3 * k)}"/></svg>` : ""}${showLabel ? `<div data-map-label="" style="margin-top:${showMap ? Math.round(6 * k) : 0}px;color:${fg};font-size:${Math.round(19 * k)}px;white-space:nowrap">${esc(text)}</div>` : ""}</div>`; + return `<div data-thread-map="${esc(map.style)}" data-map-path='${esc(JSON.stringify(pts))}' style="position:absolute;z-index:6;display:none;left:0;top:0;padding:${Math.round(10 * k)}px;border-radius:${Math.round(12 * k)}px;background:rgba(0,0,0,0.55);pointer-events:none;text-align:right">${showMap ? `<svg width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" style="display:block;margin-left:auto">${lines.join("")}${dots.join("")}<circle data-map-light="" cx="${pts[0][0]}" cy="${pts[0][1]}" r="${r + Math.round(4 * k)}" fill="none" stroke="#ffcf33" stroke-width="${Math.max(2, 3 * k)}"/></svg>` : ""}${showLabel ? `<div data-map-label="" style="margin-top:${showMap ? Math.round(6 * k) : 0}px;color:${fg};font-size:${Math.round(19 * k)}px;white-space:nowrap">${esc(text)}</div>` : ""}</div>`; } /** IN THE PAGE (self-contained): the map shown at strength `st.op`, its light `st.p` along its path (null: hidden). */ @@ -183,3 +186,35 @@ export function applyMapState(st, doc = document) { light.setAttribute("cx", String(at[0])); light.setAttribute("cy", String(at[1])); } + +/** The map's box (px), as mapHtml draws it: its tree, its label under it, its padding. */ +export function mapSize(map, k = 1) { + if (!map) return { width: 0, height: 0 }; + const cell = Math.round(26 * k); + const r = Math.round(6 * k); + const cols = Math.max(...map.nodes.map((n) => n.x)) + 1; + const svgW = map.style === "label" ? 0 : cols * cell + 2 * r + 4; + const svgH = map.style === "label" ? 0 : map.nodes.length * cell + 2 * r; + const labelW = map.style === "map" ? 0 : Math.round(String(map.label).length * 19 * k * 0.52); + const labelH = map.style === "map" ? 0 : Math.round(19 * k * 1.3) + (map.style === "both" ? Math.round(6 * k) : 0); + const pad = Math.round(10 * k); + return { width: Math.max(svgW, labelW) + 2 * pad, height: svgH + labelH + 2 * pad }; +} + +/** + * WHERE THE MAP SITS in the item's box -- never over words being read: over the attachments' slot (its top-left + * corner) when there is one, else beside a card alone (right of it, when the box has room), else the card's top-right + * corner. `L`: post-item.mjs postLayout's; `size`: mapSize's. + */ +export function mapPlace(L, box, size, k = 1) { + const m = Math.round(16 * k); + if (L?.slot && L.mode === "side") return { x: L.slot.x + m, y: L.slot.y + m }; + if (L?.card && L.card.x + L.card.width + m + size.width <= box.width - m) return { x: L.card.x + L.card.width + 2 * m, y: L.card.y + m }; + return { x: Math.max(0, (L?.card?.x ?? 0) + (L?.card?.width ?? box.width) - size.width - m), y: (L?.card?.y ?? 0) + m }; +} + +/** The map alone on a transparent page (the build shoots its states and lays them over the attachments). */ +export function mapPageHtml(map, { width, height, k = 1, accent, fg, muted, blurred = [], fonts = {} }) { + const css = (s) => String(s ?? "").replace(/[\\'"\n<>]/g, ""); + return `<!doctype html><html><head><meta charset="utf-8"><style>@font-face { font-family: 'PostSans'; src: url('${css(fonts.regular)}'); } html, body { margin: 0; width: ${width}px; height: ${height}px; background: transparent; font-family: 'PostSans', sans-serif; }</style></head><body>${mapHtml(map, { k, accent, fg, muted, blurred })}</body></html>`; +} diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -39,7 +39,7 @@ import { FOLLOW_MIN_SIZE, followBlocks, followSchedule, scopeBlocks, validatePos import { panelSchedule, validatePostThread } from "./post-thread.mjs"; import { joinLayerHtml, validatePostJoin, validatePostJoinRender } from "./post-join.mjs"; import { validatePostLinkVisit, validatePostLinkVisitRender, visitsEnd } from "./post-link-visit.mjs"; -import { mapHtml, validatePostMapRender } from "./post-branch-map.mjs"; +import { validatePostMapRender } from "./post-branch-map.mjs"; import { validatePostScene, validatePostSceneRender } from "./post-media-scene.mjs"; /** The platforms a post item may come from (deck.mjs POST_PLATFORMS). */ @@ -1133,10 +1133,8 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p ); } const order = [...tiles.map((t) => t.scope).filter((sc) => byScope.has(sc)), ...[...byScope.keys()].filter((sc) => !tiles.some((t) => t.scope === sc))]; - // THE BRANCH MAP (post-branch-map.mjs): in the card's corner (beside a card alone: right of it, the page shot whole). - const mapEl = thread?.map ? mapHtml(thread.map, { k, accent: pal.accent, fg: pal.fg, muted: pal.muted, blurred }) : ""; return { - html: `<div class="card thread" data-post-card="${esc(entry.id)}" data-post-thread="${tiles.length}"${L.mode === "text" ? ' data-thread-fit=""' : ""} style="left:${box.x}px;top:${box.y}px;height:${box.height}px;width:${box.width}px"><div class="words" data-post-words="" style="font-size:${size}px"><div class="wflow" data-post-flow="">${order.map((sc) => byScope.get(sc)).join("")}</div><div class="wfade" data-post-fade="top"></div><div class="wfade" data-post-fade="bottom"></div></div>${mapEl}</div>`, + html: `<div class="card thread" data-post-card="${esc(entry.id)}" data-post-thread="${tiles.length}"${L.mode === "text" ? ' data-thread-fit=""' : ""} style="left:${box.x}px;top:${box.y}px;height:${box.height}px;width:${box.width}px"><div class="words" data-post-words="" style="font-size:${size}px"><div class="wflow" data-post-flow="">${order.map((sc) => byScope.get(sc)).join("")}</div><div class="wfade" data-post-fade="top"></div><div class="wfade" data-post-fade="bottom"></div></div></div>`, css: cutCss.length ? `\n${cutCss.join(", ")} { display: none; }` : "", }; }; diff --git a/umtool/report-to-video/post-render.mjs b/umtool/report-to-video/post-render.mjs @@ -18,7 +18,7 @@ import { createHash } from "node:crypto"; import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { pathToFileURL } from "node:url"; -import { POST_PICTURE_XFADE, POST_PUSH, fxRedactionErrors, mediaTimeAt, panelEntry, postCardHtml, postItemPlan, postLayout, stepAt, stepBoxes } from "./post-item.mjs"; +import { POST_PICTURE_XFADE, POST_PUSH, cardAuthors, fxRedactionErrors, mediaTimeAt, panelEntry, postCardHtml, postItemPlan, postLayout, stepAt, stepBoxes } from "./post-item.mjs"; import { isNarrated, narrationLevelDb, pickedTake, postNarrationFilters, rootTakeOf } from "./post-narration.mjs"; import { applyFollowState, followPath, followRuns, followStateAt, isDrawnState, measureFollow, readInViewErrors, shotStateAt } from "./read-follow.mjs"; import { redactEntry, redactionOn, shownLine, termsFor } from "./post-redact.mjs"; @@ -28,7 +28,7 @@ import { sceneEntry } from "./post-media-scene.mjs"; import { panelReadErrors } from "./post-thread.mjs"; import { applyJoinState, endMediaOf } from "./post-join.mjs"; import { applyVisitState } from "./post-link-visit.mjs"; -import { applyMapState } from "./post-branch-map.mjs"; +import { applyMapState, mapPageHtml, mapPlace, mapSize, mapStateAt } from "./post-branch-map.mjs"; import { WORD_ZOOM_DEFAULTS, findMatch, overlappingZooms, resolveWordZoom, targetScope, targetTextOf, wordZoomTimes, zoomSpan, zoomTarget, zoompanExprs } from "./word-zoom.mjs"; const r3 = (v) => Math.round(v * 1000) / 1000; @@ -85,7 +85,7 @@ export function scrollExpr(keys) { * * @returns {string[]} */ -export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [], join = null }) { +export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [], join = null, map = null }) { const fps = render.fps ?? 30; const T = plan.total; const inputs = []; @@ -252,6 +252,14 @@ export function postSegmentArgs({ entry, box, plan, layout, cards, files, render lay(label, f.box.x, f.box.y, 0, J); }); } + // THE BRANCH MAP (post-branch-map.mjs): over everything, where mapPlace put it, while it is up. + if (map) { + const mi = add(["-f", "concat", "-safe", "0", "-i", map.list]); + parts.push(`[${mi}:v]fps=${fps},format=rgba,setpts=PTS-STARTPTS+${num(map.t0)}/TB[bmap]`); + const next = `b${++n}`; + parts.push(`[${cur}][bmap]overlay=x=${map.x}:y=${map.y}:eof_action=pass:enable='between(t,${num(map.t0)},${num(map.t3)})'[${next}]`); + cur = next; + } // A video attachment's words (its transcript), at the slot's foot. if (captions.length && fontfile && layout.slot) { const size = Math.round(34 * (box.height / 1080)); @@ -345,7 +353,8 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la if (!card) return null; const c = card.getBoundingClientRect(); // His post's head where the item before drew it (a threaded card's post tile; a plain card's head), and its words' size. - const post = document.querySelector('[data-thread-slot="post"]') ?? card.querySelector(".head"); + // Its HEAD (name and date): where the carried post's head goes (a relation line above it moves its tile, not it). + const post = document.querySelector('[data-thread-slot="post"] .head') ?? card.querySelector(".head"); const words = document.querySelector('[data-thread-slot="post"] .twords') ?? document.querySelector("[data-post-words]"); const pr = post ? post.getBoundingClientRect() : null; return { A: { x: c.left, y: c.top, width: c.width, height: c.height }, anchor: pr ? pr.top - c.top : null, size: words ? parseFloat(getComputedStyle(words).fontSize) : null }; @@ -386,11 +395,16 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la const own = await page.evaluate(() => { const c = document.querySelector("[data-post-card]")?.getBoundingClientRect(); const w = document.querySelector("[data-post-words]")?.getBoundingClientRect(); - return c && w ? { win: w.top - c.top, width: c.width } : null; + const tile = document.querySelector("[data-join-anchor]"); + const head = tile?.querySelector(".head")?.getBoundingClientRect(); + const slot = tile?.closest("[data-thread-slot]")?.getBoundingClientRect(); + return c && w ? { win: w.top - c.top, width: c.width, head: head && slot ? head.top - slot.top : 0 } : null; }); - if (own) geo.joinAnchor = { y: Math.round((join.anchor / (join.A.width / own.width) - own.win) * 100) / 100 }; + if (own) geo.joinAnchor = { y: Math.round((join.anchor / (join.A.width / own.width) - own.win - own.head) * 100) / 100 }; } out.follow = await shootFollow(page, { follow, total, fps, box, dir, geo }); + // THE BRANCH MAP (post-branch-map.mjs): its own layer, shot on a transparent page, laid over the attachments. + if (follow.thread?.map) out.map = await shootMap(ctx, { map: follow.thread.map, layout, box, fps, dir, render, fonts, entry }); // THE INVARIANT (read-follow.mjs readInViewErrors): what each part reads is in view, whole and lit, in the // frames as they are shot -- or, with none shot, in the page as drawn. const fpath = out.follow?.path ?? followPath(follow, geo); @@ -443,14 +457,12 @@ export async function shootFollow(page, { follow, total, fps, box, dir, geo = nu if (joined) await page.evaluate(applyJoinState, run.st.join ?? null); // A LINK VISIT (post-link-visit.mjs): the pointer and its click over the link where the state puts it. if (follow.visits?.length) await page.evaluate(applyVisitState, { visits: follow.visits, st: run.st.visit ?? null }); - if (follow.thread?.map) await page.evaluate(applyMapState, run.st.map ?? null); await page.screenshot({ path: file, clip }); shots.set(run.key, file); } await page.evaluate(applyFollowState, null); if (joined) await page.evaluate(applyJoinState, null); if (follow.visits?.length) await page.evaluate(applyVisitState, { visits: follow.visits, st: null }); - if (follow.thread?.map) await page.evaluate(applyMapState, null); const q = (f) => `'${f.replace(/'/g, "'\\''")}'`; const lines = ["ffconcat version 1.0"]; for (const run of runs) lines.push(`file ${q(shots.get(run.key))}`, `duration ${(run.n / fps).toFixed(6)}`); @@ -460,6 +472,64 @@ export async function shootFollow(page, { follow, total, fps, box, dir, geo = nu return { list, clip, shots: shots.size, frames, geo, path: path0 }; } +/** + * THE BRANCH MAP's FRAMES (post-branch-map.mjs): the map alone on a transparent page, each distinct state (its + * strength, its light's place) shot once over its span, a concat list holding each for its frames; `{ list, x, y, + * t0, t3 }` -- where it is laid (mapPlace: over the slot, or beside a card alone) and when. + */ +async function shootMap(ctx, { map, layout, box, fps, dir, render, fonts, entry }) { + const k = box.height / 1080; + const size = mapSize(map, k); + const at = mapPlace(layout, box, size, k); + const pal = { fg: "#f6f1e6", muted: "#a2957f", accent: "#c8752a", ...(render.palette ?? {}) }; + const blurred = cardAuthors(entry).filter((a) => a.redact && a.handle).map((a) => a.handle); + const page = await ctx.newPage(); + try { + await page.setViewportSize({ width: Math.max(2, size.width + 4), height: Math.max(2, size.height + 4) }); + const file = path.join(dir, "map.html"); + await writeFile(file, mapPageHtml(map, { width: size.width + 4, height: size.height + 4, k, accent: pal.accent, fg: pal.fg, muted: pal.muted, blurred, fonts }), "utf8"); + await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); + const el = await page.evaluate(() => { + const m = document.querySelector("[data-thread-map]"); + if (!m) return null; + m.style.display = "block"; + const r = m.getBoundingClientRect(); + return { width: Math.ceil(r.width), height: Math.ceil(r.height) }; + }); + if (!el) return null; + const mdir = path.join(dir, "map"); + await rm(mdir, { recursive: true, force: true }); + await mkdir(mdir, { recursive: true }); + const { t0, t3 } = map.times; + const frames = Math.max(1, Math.round((t3 - t0) * fps)); + const runs = []; + for (let i = 0; i < frames; i += 1) { + const st = mapStateAt(map, t0 + i / fps) ?? { op: 0, p: 0 }; + const key = JSON.stringify(st); + const last = runs[runs.length - 1]; + if (last && last.key === key) last.n += 1; + else runs.push({ key, st, n: 1 }); + } + const shots = new Map(); + for (const run of runs) { + if (shots.has(run.key)) continue; + const png = path.join(mdir, `m-${String(shots.size).padStart(4, "0")}.png`); + await page.evaluate(applyMapState, run.st); + await page.screenshot({ path: png, clip: { x: 0, y: 0, width: el.width, height: el.height }, omitBackground: true }); + shots.set(run.key, png); + } + const q = (f) => `'${f.replace(/'/g, "'\\''")}'`; + const lines = ["ffconcat version 1.0"]; + for (const run of runs) lines.push(`file ${q(shots.get(run.key))}`, `duration ${(run.n / fps).toFixed(6)}`); + lines.push(`file ${q(shots.get(runs[runs.length - 1].key))}`); + const list = path.join(mdir, "frames.ffconcat"); + await writeFile(list, lines.join("\n") + "\n", "utf8"); + return { list, x: Math.round(at.x), y: Math.round(at.y), t0, t3 }; + } finally { + await page.close(); + } +} + /** The device scale a word zoom's shots are taken at: crisp at its scale (2–4). */ export const zoomShotScale = (zooms) => Math.min(4, Math.max(2, Math.ceil(Math.max(1, ...zooms.map((z) => z.scale ?? WORD_ZOOM_DEFAULTS.scale))))); @@ -682,7 +752,7 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box const lufs = Number.isFinite(take.lufs) ? take.lufs : await measureLufsOf(takeFile, { exec, ffmpeg }); narration = { file: takeFile, gainDb: narrationLevelDb(lufs, plan.narration.lufs), lufs, ...(bleeps ? { bleeps } : {}) }; } - const argv = postSegmentArgs({ entry, box, plan, layout, cards, files, render, place, encode, captions, fontfile: render.fontBold ?? render.fontRegular ?? null, outPath: tmp, narration, zooms, follow: cards.follow ?? null, panelFiles, join: from && cards.joinFrom ? { seconds: plan.follow.join.seconds, fadeIn: from.fadeIn, from: from.media } : null }); + const argv = postSegmentArgs({ entry, box, plan, layout, cards, files, render, place, encode, captions, fontfile: render.fontBold ?? render.fontRegular ?? null, outPath: tmp, narration, zooms, follow: cards.follow ?? null, panelFiles, map: cards.map ?? null, join: from && cards.joinFrom ? { seconds: plan.follow.join.seconds, fadeIn: from.fadeIn, from: from.media } : null }); try { await exec(ffmpeg, argv, { maxBuffer: 1 << 24 }); } catch (err) { diff --git a/umtool/report-to-video/post-thread-scenes.test.mjs b/umtool/report-to-video/post-thread-scenes.test.mjs @@ -280,7 +280,7 @@ test("A LINK VISIT that OPENS: SaberXVeritas's \"this you? <link>\", then the li assert.equal(plan.follow.visits[0].at, row.t0); }); -import { mapStateAt } from "./post-branch-map.mjs"; +import { mapPageHtml, mapPlace, mapSize, mapStateAt } from "./post-branch-map.mjs"; test("THE BRANCH MAP (operator, 4 Nov: \"a specific visual for changing thread branches\"): the sibling swap draws the run's posts as a tree, the light travelling from the post the item before ended on up to his root and down to the new reply; the label says it", () => { const ROOTP = ref("771", "subject", "Many have questioned my methods in dealing with the whole mess.", 6); @@ -301,9 +301,16 @@ test("THE BRANCH MAP (operator, 4 Nov: \"a specific visual for changing thread b assert.deepEqual(mapStateAt(m, m.times.travel), { op: 1, p: 0 }); assert.equal(mapStateAt(m, m.times.travel + 1.1).p, 1); assert.equal(followStateAt(plan.follow, null, m.times.travel + 0.5).map.op, 1); - const html = postCardHtml(p13, { width: 1600, height: 900, follow: true, thread: plan.follow.thread }); + // Its own layer, never over words being read: over the slot, else beside a card alone. + const html = mapPageHtml(m, { width: 300, height: 200 }); assert.match(html, /data-thread-map="both"/); assert.match(html, /another reply to his post/); + assert.doesNotMatch(postCardHtml(p13, { width: 1600, height: 900, follow: true, thread: plan.follow.thread }), /data-thread-map/); + const size = mapSize(m); + const side = { mode: "side", card: { x: 36, y: 36, width: 700, height: 1008 }, slot: { x: 772, y: 36, width: 1112, height: 1008 } }; + assert.deepEqual(mapPlace(side, { width: 1920, height: 1080 }, size), { x: 788, y: 52 }); + const alone = { mode: "text", card: { x: 370, y: 36, width: 1180, height: 1008 }, slot: null }; + assert.equal(mapPlace(alone, { width: 1920, height: 1080 }, size).x, 370 + 1180 + 32); // Off for the item, or a label only. assert.equal(threadLayout({ ...p13, thread: { map: false } }, undefined, planContext(tl, 2)).map, undefined); assert.equal(threadLayout({ ...p13, thread: { map: "label" } }, undefined, planContext(tl, 2)).map.style, "label"); diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs @@ -405,6 +405,12 @@ function sceneTiles(entry, tiles, scene, k) { const list = Array.isArray(scene?.tiles) ? scene.tiles : []; if (!list.length) return tiles; const own = new Set(tiles.filter((t) => t.mode !== "hidden").map((t) => tileIdOf(entry, t)).filter(Boolean)); + // A post of his own card the run already had on screen grows from where it was (small), never pops in from nothing. + const was = new Map(list.filter((t) => isObj(t) && str(t.id)).map((t) => [str(t.id), t.from === "full" ? [1, 1] : [k.shrink, k.dim]])); + for (const t of tiles) { + const id = tileIdOf(entry, t); + if (id && was.has(id) && t.mode !== "hidden") t.fromScene = was.get(id); + } const extra = list .filter((t) => isObj(t) && str(t.id) && isObj(t.ref) && !own.has(str(t.id))) .map((t) => ({ @@ -617,8 +623,8 @@ export function threadSchedule(entry, render, { layout, blocks, lead = 0.4 }) { // A quoted post above his: a top-level tile like a parent (revealed, shrunk); inside his: it only dims. const own = t.scope !== "quoted" || !!t.above; if (own && revealed(t.scope, T0)) { - // Revealed when its read comes (an older post read before it). - row.from = [1, 0]; + // Revealed when its read comes (an older post read before it) -- from where the run had it, when it had it. + row.from = t.fromScene ?? [1, 0]; row.to = [1, 1]; Object.assign(row, win(T0)); if (T !== null) row.then = { to: small, ...win(T) };