Archilyzer · Source

archilyzer

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

commit 7cfb31184c2a448654c38dd9b2c7d5689a260cca
parent afa4f86e2e7ad094c8316556b4c9be687e76fdf5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 12:51:44 -0500

umtool: THE BRANCH MAP -- when a scene moves to another branch of a conversation (a sibling reply, a reply up the stack in a manual thread), a small map in the card's corner draws the posts on screen as a tree, the light travelling from the post the item before ended on up to the post they share and down to the new one, labelled ("another reply to his post"); render.posts.threadMap {on, style: map|label|both}, item thread.map; the build and Play draw it (post-branch-map.mjs). Play's plan carries the join; a scene post drawn as the item before's keeps its scene marker

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

Diffstat:
Mumtool/components/projects/review/PostItemPlayer.tsx | 3+++
Mumtool/lib/report/playView.mjs | 2+-
Mumtool/report-to-video/package.json | 1+
Aumtool/report-to-video/post-branch-map.mjs | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/post-conversation.mjs | 3+++
Mumtool/report-to-video/post-item.mjs | 13++++++++-----
Mumtool/report-to-video/post-render.mjs | 3+++
Mumtool/report-to-video/post-thread-scenes.test.mjs | 29+++++++++++++++++++++++++++++
Mumtool/report-to-video/post-thread.mjs | 28++++++++++++++++++++++++++--
Mumtool/report-to-video/read-follow.mjs | 10+++++++---
10 files changed, 266 insertions(+), 11 deletions(-)

diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -4,6 +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 { 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"; @@ -633,6 +634,8 @@ 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; diff --git a/umtool/lib/report/playView.mjs b/umtool/lib/report/playView.mjs @@ -63,7 +63,7 @@ export function postPlayEntry(e, render = undefined, ctx = null, mediaScene = nu post: panelEntry(sceneEntry(e, mediaScene), render), // `prev`: the item before it in the cut (post-thread.mjs: a parent that is that item is carried in); `scene`: the // posts its run left on screen (post-conversation.mjs: one conversation played as one scene) -- it wins the card. - postPlan: postItemPlan(panelEntry(sceneEntry(e, mediaScene), render), render, { prev: ctx?.prev ?? null, scene: ctx?.scene ?? null, mediaScene: ctx?.scene ? null : mediaScene }), + postPlan: postItemPlan(panelEntry(sceneEntry(e, mediaScene), render), render, { prev: ctx?.prev ?? null, scene: ctx?.scene ?? null, mediaScene: ctx?.scene ? null : mediaScene, join: ctx?.join ?? null }), ...(mediaScene ? { postScene: { key: mediaScene.key, n: mediaScene.n, of: mediaScene.of, ids: mediaScene.ids, anchor: mediaScene.anchor.id } } : {}), }; } diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json @@ -75,6 +75,7 @@ "./post-conversation": "./post-conversation.mjs", "./post-join": "./post-join.mjs", "./post-link-visit": "./post-link-visit.mjs", + "./post-branch-map": "./post-branch-map.mjs", "./post-render": "./post-render.mjs", "./word-zoom": "./word-zoom.mjs", "./read-follow": "./read-follow.mjs", diff --git a/umtool/report-to-video/post-branch-map.mjs b/umtool/report-to-video/post-branch-map.mjs @@ -0,0 +1,185 @@ +// THE BRANCH MAP (umtool/docs/report-video.md, "The branch map"; operator, 4 Nov: "we need a specific visual for +// changing thread branches that makes the context obvious"): when a scene moves from one branch of a conversation +// to another -- a sibling reply, a new reply to an earlier post, a jump back up the tree -- a small map in the card's +// corner shows where we are going: a node for each post on screen, a line for each reply, the post the item before +// ended on lit, the light travelling up to the post the two branches share and down the new branch to the post being +// read; a label under it says it ("another reply to @X's post"; "back to @X's post"). A manual thread +// (`thread.group`) draws its posts' real relations (a post that answers none stands alone). +// +// render.posts.threadMap = { on?: true, style?: "both" } the cut's: "map" | "label" | "both" +// timeline[i].thread.map = false | true | "map" | "label" | "both" +// +// When: the item's scene changes branch (a post the run had on screen collapses away, post-conversation.mjs) or, in a +// manual thread, the post he answers is not the one just above. It shows from the join's end, travels with the +// branch's change (its collapse), holds, and fades (MAP_TIMES). +// +// PURE but the page function (applyMapState, self-contained): threadLayout carries `map` (its nodes, its edges, the +// path), threadSchedule its times, the state at a second its progress; the card page draws it (mapHtml). + +const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); +const fin = (v) => typeof v === "number" && Number.isFinite(v); +const str = (v) => (typeof v === "string" ? v : ""); +const r3 = (v) => Math.round(v * 1000) / 1000; + +export const MAP_DEFAULTS = Object.freeze({ on: true, style: "both" }); +export const MAP_STYLES = Object.freeze(["map", "label", "both"]); +/** The map's fade in (s), the light's travel (s), the hold after it (s), the fade out (s). */ +export const MAP_TIMES = Object.freeze({ in: 0.3, travel: 1.1, hold: 2.2, out: 0.5 }); + +/** The cut's and an item's map knobs: `{ on, style }`. */ +export function mapKnobs(entry, render = undefined) { + const r = isObj(render?.posts?.threadMap) ? render.posts.threadMap : {}; + const k = { ...MAP_DEFAULTS, ...(typeof r.on === "boolean" ? { on: r.on } : {}), ...(MAP_STYLES.includes(r.style) ? { style: r.style } : {}) }; + const v = entry?.thread?.map; + if (v === false) return { ...k, on: false }; + if (v === true) return { ...k, on: true }; + if (MAP_STYLES.includes(v)) return { on: true, style: v }; + return k; +} + +/** Every reason `render.posts.threadMap` cannot be built. */ +export function validatePostMapRender(render) { + const v = render?.posts?.threadMap; + if (v === undefined) return []; + if (!isObj(v)) return ["render.posts.threadMap must be { on?, style? } (the branch map)"]; + const errors = Object.keys(v).filter((k) => !(k in MAP_DEFAULTS)).map((k) => `render.posts.threadMap.${k} is not a branch-map knob (on, style)`); + if (v.on !== undefined && typeof v.on !== "boolean") errors.push("render.posts.threadMap.on must be true or false"); + if (v.style !== undefined && !MAP_STYLES.includes(v.style)) errors.push(`render.posts.threadMap.style must be one of ${MAP_STYLES.join(", ")}`); + return errors; +} + +/** + * THE MAP of a card, pure: `{ style, nodes: [{ id, scope, handle, him, x, y }], edges: [[from, to]], path: [ids], + * label, from, to }` -- or null when the scene does not change branch. `tiles`: threadLayout's (each with its `id`, + * its parent's `parent`, its author's `handle`); `subject`: his handle; `prevId`: the post the item before ended on; + * `nowId`: the post being read first (the new branch's). Laid out as a tree: depth across, the tiles' order down. + */ +export function branchMapOf(tiles, { prevId, nowId, subject = "", style = "both", group = false } = {}) { + const list = (tiles ?? []).filter((t) => str(t.id)); + if (!prevId || !nowId || prevId === nowId || !list.some((t) => t.id === prevId) || !list.some((t) => t.id === nowId)) return null; + const byId = new Map(list.map((t) => [t.id, t])); + const parentOf = (id) => { + const p = str(byId.get(id)?.parent); + return p && byId.has(p) && p !== id ? p : null; + }; + const up = (id) => { + const out = [id]; + for (let p = parentOf(id), n = 0; p && n < 20; p = parentOf(p), n += 1) out.push(p); + return out; + }; + 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; + // 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]; + const depth = new Map(); + const depthOf = (id) => { + if (depth.has(id)) return depth.get(id); + depth.set(id, 0); + const p = parentOf(id); + const d = p ? depthOf(p) + 1 : 0; + depth.set(id, d); + return d; + }; + const nodes = list.map((t, row) => ({ id: t.id, scope: t.scope, handle: str(t.handle), him: !!subject && str(t.handle).toLowerCase() === subject.toLowerCase(), x: depthOf(t.id), y: row })); + const edges = list.map((t) => [parentOf(t.id), t.id]).filter((e) => e[0]); + 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`; + return { style, nodes, edges, path, label, from: prevId, to: nowId, shared }; +} + +/** The map's times on the item's clock: in at `t0`, the light travelling from `travel`, out by `t3`. */ +export function mapTimes(at) { + const t0 = r3(Math.max(0, at)); + const travel = r3(t0 + MAP_TIMES.in); + const t2 = r3(travel + MAP_TIMES.travel + MAP_TIMES.hold); + return { t0, travel, t2, t3: r3(t2 + MAP_TIMES.out) }; +} + +/** The map's state at item second `s`: `{ op, p }` (p: the light's place along its path, 0..1), or null. */ +export function mapStateAt(map, s) { + if (!map?.times) return null; + const { t0, travel, t2, t3 } = map.times; + if (s < t0 || s > t3) return null; + const op = s < travel ? (s - t0) / Math.max(1e-6, travel - t0) : s > t2 ? 1 - (s - t2) / Math.max(1e-6, t3 - t2) : 1; + const x = Math.min(1, Math.max(0, (s - travel) / MAP_TIMES.travel)); + const p = x < 0.5 ? 4 * x ** 3 : 1 - (-2 * x + 2) ** 3 / 2; + return { op: r3(Math.max(0, Math.min(1, op))), p: r3(p) }; +} + +const esc = (s) => String(s ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"); + +/** + * The map's markup (the card page's): an SVG of the nodes and lines in the card's top-right corner, the light (a + * ring that travels), the label under it -- hidden until applyMapState shows it. `k`: the page's scale (height รท + * 1080); `blurred`: handles the card blurs (a label never names one); `accent`: his colour. + */ +export function mapHtml(map, { k = 1, accent = "#c8752a", fg = "#f6f1e6", muted = "#a2957f", blurred = [] } = {}) { + if (!map) return ""; + const cell = Math.round(26 * k); + const r = Math.round(6 * k); + const cols = Math.max(...map.nodes.map((n) => n.x)) + 1; + const rows = map.nodes.length; + const w = cols * cell + 2 * r + 4; + const h = rows * cell + 2 * r; + const at = (n) => [r + 2 + n.x * cell + r, r + n.y * cell + r]; + const pos = new Map(map.nodes.map((n) => [n.id, at(n)])); + const lines = map.edges.map(([a, b]) => { + const [x1, y1] = pos.get(a); + const [x2, y2] = pos.get(b); + return `<path d="M${x1} ${y1} V${y2} H${x2}" fill="none" stroke="${muted}" stroke-width="${Math.max(1.5, 2 * k)}" stroke-opacity="0.7"/>`; + }); + const onPath = new Set(map.path); + const dots = map.nodes.map((n) => { + const [x, y] = pos.get(n.id); + return `<circle data-map-node="${esc(n.id)}" cx="${x}" cy="${y}" r="${r}" fill="${n.him ? accent : fg}" fill-opacity="${onPath.has(n.id) ? 0.95 : 0.45}"/>`; + }); + const pts = map.path.map((id) => pos.get(id)); + const blur = new Set(blurred.map((h) => String(h).replace(/^@/, "").toLowerCase())); + const label = /@([A-Za-z0-9_]+)'s/.exec(map.label)?.[1]; + 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>`; +} + +/** IN THE PAGE (self-contained): the map shown at strength `st.op`, its light `st.p` along its path (null: hidden). */ +export function applyMapState(st, doc = document) { + const el = doc.querySelector("[data-thread-map]"); + if (!el) return; + if (!st) { + el.style.display = "none"; + return; + } + el.style.display = "block"; + el.style.opacity = String(st.op); + const light = el.querySelector("[data-map-light]"); + const pts = JSON.parse(el.getAttribute("data-map-path") || "[]"); + if (!light || pts.length < 1) return; + // Along the path's legs (each an elbow: down, then across), by length. + const legs = []; + for (let i = 1; i < pts.length; i += 1) { + const [a, b] = [pts[i - 1], pts[i]]; + const mid = [a[0], b[1]]; + legs.push([a, mid], [mid, b]); + } + const len = legs.map(([a, b]) => Math.abs(b[0] - a[0]) + Math.abs(b[1] - a[1])); + const total = len.reduce((x, y) => x + y, 0) || 1; + let d = st.p * total; + let at = pts[0]; + for (let i = 0; i < legs.length; i += 1) { + if (d <= len[i] || i === legs.length - 1) { + const f = len[i] ? Math.min(1, d / len[i]) : 1; + at = [legs[i][0][0] + (legs[i][1][0] - legs[i][0][0]) * f, legs[i][0][1] + (legs[i][1][1] - legs[i][0][1]) * f]; + break; + } + d -= len[i]; + } + light.setAttribute("cx", String(at[0])); + light.setAttribute("cy", String(at[1])); +} diff --git a/umtool/report-to-video/post-conversation.mjs b/umtool/report-to-video/post-conversation.mjs @@ -300,6 +300,9 @@ function contextsOf(tl, render) { if (t.action === "keep") end.push({ id: t.scope.slice(5), ref: t.ref }); } else if (t.scope === "post" || t.scope.startsWith("parent:")) { const ref = sceneRefOf(e, t.scope); + // What it answers, from the run's tree when its own item does not carry it (the branch map's lines). + const up = ref?.id ? runs[r].tree.parentOf.get(ref.id) : undefined; + if (ref && !ref.replyTo && up) ref.replyTo = { id: up, handle: "" }; if (ref?.id && str(ref.text).trim()) end.push({ id: ref.id, ref }); } } diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -39,6 +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 { validatePostScene, validatePostSceneRender } from "./post-media-scene.mjs"; /** The platforms a post item may come from (deck.mjs POST_PLATFORMS). */ @@ -591,7 +592,7 @@ export function validatePostItems(manifest) { const errors = []; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; for (const e of tl) if (e?.type === "post") errors.push(...validatePostItem(e)); - errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(manifest?.render), ...validatePostJoinRender(manifest?.render), ...validatePostLinkVisitRender(manifest?.render)); + errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(manifest?.render), ...validatePostJoinRender(manifest?.render), ...validatePostLinkVisitRender(manifest?.render), ...validatePostMapRender(manifest?.render)); // A word zoom on a word the project's list blanks (the corpus's and a post's markup are checked by the build). const own = { terms: projectRedactOf(manifest?.render) }; for (const e of tl) if (e?.type === "post") errors.push(...fxRedactionErrors(e, own)); @@ -1070,11 +1071,11 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p // attachment itself is in the slot while it is on screen (post-thread.mjs panelSchedule). // THE JOIN (post-join.mjs): the post the item before ended on -- carried in, or the scene's -- drawn as that item // drew its post (its head, its words at their size), so the item opens on it exactly as it ended. - const asPost = (scope, p, r, attr, mode) => { + const asPost = (scope, p, r, attr, mode, slotAttr = "") => { const sz = fin(join?.size) ? join.size : sizeFor(contextText(p) || " ", innerW, innerH - 170 * k); const own2 = { author: p.author, handle: p.handle }; const headP = `<div class="head"${r ? ' data-redacted=""' : ""}>${avatarHtml(own2, { redact: r, size: Math.round(64 * k), accent: r ? undefined : pal.accent, img: r ? null : pic(p) })}<div class="hwho">${nameHtml(own2, { redact: r, cls: "big" })}<div class="date">${esc(cardDate(p.date))}</div></div><div class="mark">${esc(PLATFORM_NAME[entry.platform] ?? "")}</div></div>`; - tileHtml.push(`<div class="tslot" data-thread-slot="${esc(scope)}"><div class="tile tpost tcarry" data-thread-tile="${esc(scope)}" data-thread-mode="${mode}" ${attr} data-join-anchor="">${relationHtml(t0(scope))}${headP}<div class="twords" style="font-size:${sz}px">${wordsHtml(contextText(p), r && p.handle ? [...blurred, p.handle] : blurred)}</div></div></div>`); + tileHtml.push(`<div class="tslot" data-thread-slot="${esc(scope)}"${slotAttr}><div class="tile tpost tcarry" data-thread-tile="${esc(scope)}" data-thread-mode="${mode}" ${attr} data-join-anchor="">${relationHtml(t0(scope))}${headP}<div class="twords" style="font-size:${sz}px">${wordsHtml(contextText(p), r && p.handle ? [...blurred, p.handle] : blurred)}</div></div></div>`); }; const refTile = (scope, p, where, attr) => { const mode = tmode(scope); @@ -1122,7 +1123,7 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const ref = redactSceneRef(t.ref, redaction); const r = ref.redact === true; if (t.wasPost && join && str(ref.text).trim()) { - asPost(t.scope, { ...ref, text: str(ref.text) }, r, `data-thread-scene="${t.action === "keep" ? "keep" : "collapse"}" data-post-scene="${esc(t.scope.slice(5))}"`, "scene"); + asPost(t.scope, { ...ref, text: str(ref.text) }, r, `data-post-scene="${esc(t.scope.slice(5))}"`, "scene", ` data-thread-scene="${t.action === "keep" ? "keep" : "collapse"}"`); continue; } const text = str(ref.text); @@ -1132,8 +1133,10 @@ 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></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>${mapEl}</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 @@ -28,6 +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 { WORD_ZOOM_DEFAULTS, findMatch, overlappingZooms, resolveWordZoom, targetScope, targetTextOf, wordZoomTimes, zoomSpan, zoomTarget, zoompanExprs } from "./word-zoom.mjs"; const r3 = (v) => Math.round(v * 1000) / 1000; @@ -442,12 +443,14 @@ 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)}`); diff --git a/umtool/report-to-video/post-thread-scenes.test.mjs b/umtool/report-to-video/post-thread-scenes.test.mjs @@ -279,3 +279,32 @@ test("A LINK VISIT that OPENS: SaberXVeritas's \"this you? <link>\", then the li const row = plan.follow.thread.tiles.find((t) => t.scope === "linked:0"); assert.equal(plan.follow.visits[0].at, row.t0); }); + +import { 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); + const FOX = ref("834", "fox_one", "Far as people should be concerned you are no better than them.", 7); + const DRAC = ref("775", "drac_two", "Oh please, you were never going to change anything here.", 6); + const p11 = narrate(base({ id: "p-11", post: "subj-x/11", date: at(10), text: "I feel like I've failed everyone.", parents: [ROOTP] }), [["I feel like I've failed everyone."]]); + const p12 = narrate(base({ id: "p-12", post: "subj-x/12", date: at(11), text: "You are nobody at all.", parents: [FOX, ref("11", "subject", p11.text, 10)] }), [[FOX.text], ["You are nobody at all."]]); + const p13 = narrate(base({ id: "p-13", post: "subj-x/13", date: at(12), text: "Who are you to tell me.", parents: [DRAC, ROOTP] }), [[DRAC.text], ["Who are you to tell me."]]); + const tl = [p11, p12, p13]; + const L = threadLayout(p13, undefined, planContext(tl, 2)); + assert.deepEqual(L.map.path, ["12", "834", "11", "771", "775"]); + assert.equal(L.map.label, "another reply to his post"); + // No map where the scene does not change branch (p-12 reads the reply to the post the item before ended on). + assert.equal(threadLayout(p12, undefined, planContext(tl, 1)).map, undefined); + const plan = postItemPlan(p13, undefined, planContext(tl, 2)); + const m = plan.follow.thread.map; + assert.ok(m.times.t0 >= 0.6 - 1e-6, "after the join"); + 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 }); + assert.match(html, /data-thread-map="both"/); + assert.match(html, /another reply to his post/); + // 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 @@ -53,6 +53,7 @@ import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, script import { normWord, scriptWordsOf } from "./word-zoom.mjs"; import { followKnobs } from "./read-follow.mjs"; import { planContext } from "./post-conversation.mjs"; +import { branchMapOf, mapKnobs, mapTimes } from "./post-branch-map.mjs"; /** What a context tile may be. */ export const THREAD_MODES = Object.freeze(["auto", "full", "excerpt", "context", "carry", "hidden"]); @@ -338,7 +339,9 @@ export function threadLayout(entry, render = undefined, { prev = null, scene = n // THE SCENE (post-conversation.mjs): what the run had on screen, in the tree's order with this item's own tiles. const scened = withRelations(entry, isNarrated(entry) ? sceneTiles(entry, tiles, scene, k) : tiles, { group: !!scene?.group || !!groupOf(entry) }); const on = isNarrated(entry) && scened.some((t) => t.scope !== "post" && t.mode !== "hidden"); - return { on, tiles: scened, roles, quotedAt: quotedAtOut }; + // THE BRANCH MAP (post-branch-map.mjs): where the scene goes when it changes branch. + const map = on && scene && prev ? layoutMap(entry, scened, roles, { prevId: prevId, group: !!scene?.group || !!groupOf(entry), knobs: mapKnobs(entry, render) }) : null; + return { on, tiles: scened, roles, quotedAt: quotedAtOut, ...(map ? { map } : {}) }; } /** The id a tile of `entry` draws (a parent's, his post's, a quoted or linked post's; null: none known). */ @@ -464,6 +467,25 @@ function withRelations(entry, tiles, { group = false } = {}) { }); } +/** The branch map of a laid-out card (post-branch-map.mjs branchMapOf), from its tiles' ids, parents and authors. */ +function layoutMap(entry, tiles, roles, { prevId, group, knobs }) { + if (!knobs.on) return null; + const parents = parentsOf(entry); + const node = (t) => { + if (t.mode === "hidden") return null; + if (t.mode === "scene") return { scope: t.scope, id: t.scope.slice(5), parent: str(t.ref?.replyTo?.id), handle: str(t.ref?.handle) }; + if (t.scope === "post") return { scope: t.scope, id: shownIdOf(entry), parent: str(parents[0]?.id), handle: str(entry?.handle) }; + const m = /^parent:(\d)$/.exec(t.scope); + if (m) return { scope: t.scope, id: str(parents[Number(m[1])]?.id), parent: str(parents[Number(m[1]) + 1]?.id), handle: str(parents[Number(m[1])]?.handle) }; + return null; + }; + const nodes = tiles.map(node).filter((n) => n && n.id); + // The post read first is where the scene goes (his own when he is read first). + const first = roles.find((r) => r.role && (r.role === "post" || r.role.startsWith("parent:")))?.role ?? "post"; + const now = nodes.find((n) => n.scope === first)?.id ?? shownIdOf(entry); + return branchMapOf(nodes, { prevId, nowId: now, subject: str(entry?.handle), style: knobs.style, group }); +} + /** A tile's mode in a layout (null: no such tile). */ export const tileModeOf = (layout, scope) => layout?.tiles?.find((t) => t.scope === scope)?.mode ?? null; @@ -610,7 +632,9 @@ export function threadSchedule(entry, render, { layout, blocks, lead = 0.4 }) { if (t.linkedFrom) row.linkedFrom = t.linkedFrom; tiles.push(row); } - return { shrink: k.shrink, dim: k.dim, seconds: k.seconds, pan: k.pan, contextRoom: THREAD_CONTEXT_ROOM, quotedAt: above ? "above" : "inside", tiles }; + // THE BRANCH MAP (post-branch-map.mjs): in as the scene changes branch (its first piece, less the pan's lead). + const map = layout.map ? { ...layout.map, times: mapTimes(first ? Math.max(0, first.start - lead) : lead) } : null; + return { shrink: k.shrink, dim: k.dim, seconds: k.seconds, pan: k.pan, contextRoom: THREAD_CONTEXT_ROOM, quotedAt: above ? "above" : "inside", tiles, ...(map ? { map } : {}) }; } /** inOut cubic over [0, 1]. */ diff --git a/umtool/report-to-video/read-follow.mjs b/umtool/report-to-video/read-follow.mjs @@ -49,6 +49,7 @@ import { cardTokens, easeOf, normWord, scriptWordsOf } from "./word-zoom.mjs"; import { partRoles, threadGeoAt, threadKnobs, threadLayout, threadSchedule, threadStateAt } from "./post-thread.mjs"; import { sceneLayout, sceneRows, sceneSchedule } from "./post-media-scene.mjs"; import { linkVisits, visitRows, visitStateAt } from "./post-link-visit.mjs"; +import { mapStateAt } from "./post-branch-map.mjs"; export const FOLLOW_DEFAULTS = Object.freeze({ on: true, dim: 0.65, ease: 0.25 }); export const FOLLOW_LIMITS = Object.freeze({ dim: [0.2, 1], ease: [0, 2] }); @@ -590,7 +591,7 @@ const ramp = (s, a, d) => (d <= 0 ? (s >= a ? 1 : 0) : easeOf("inOut", (s - a) / * @param {Record<string, any> | null} follow * @param {Record<string, any> | null} path * @param {number} s - * @returns {{ op: Record<string, number>, offset: number, fadeTop: number, fadeBottom: number, current: any, tiles?: Record<string, number[]>, join?: number, visit?: { i: number, move: number, click: number, ring: number } }} + * @returns {{ op: Record<string, number>, offset: number, fadeTop: number, fadeBottom: number, current: any, tiles?: Record<string, number[]>, join?: number, visit?: { i: number, move: number, click: number, ring: number }, map?: { op: number, p: number } }} */ export function followStateAt(follow, path, s) { const op = {}; @@ -620,6 +621,9 @@ export function followStateAt(follow, path, s) { // A LINK VISIT (post-link-visit.mjs): the pointer, its click, the linked post's ring. const vs = follow.visits?.length ? visitStateAt(follow.visits, s) : null; if (vs) jp.visit = vs; + // THE BRANCH MAP (post-branch-map.mjs): shown as the scene changes branch, its light travelling. + const ms = follow.thread?.map ? mapStateAt(follow.thread.map, s) : null; + if (ms) jp.map = ms; if (follow.thread) { // THREADED (post-thread.mjs): each tile's scale and opacity, with its full height (the page sets its slot's). const ts = threadStateAt(follow.thread, s); @@ -656,7 +660,7 @@ export function followStateAt(follow, path, s) { } /** A state's key: two frames with the same key draw the same card (the build shoots each key once). */ -export const followStateKey = (st) => JSON.stringify([st.op, st.offset, st.fadeTop, st.fadeBottom, ...(st.tiles ? [st.tiles] : []), ...(st.join !== undefined ? [st.join] : []), ...(st.visit ? [st.visit] : [])]); +export const followStateKey = (st) => JSON.stringify([st.op, st.offset, st.fadeTop, st.fadeBottom, ...(st.tiles ? [st.tiles] : []), ...(st.join !== undefined ? [st.join] : []), ...(st.visit ? [st.visit] : []), ...(st.map ? [st.map] : [])]); /** * Whether a state draws the card PAGE AS DRAWN (no state applied): nothing @@ -669,7 +673,7 @@ export const followStateKey = (st) => JSON.stringify([st.op, st.offset, st.fadeT */ export function isDrawnState(st) { if (!st) return true; - if (fin(st.join) || st.visit) return false; + if (fin(st.join) || st.visit || st.map) return false; if (Object.values(st.op ?? {}).some((o) => fin(o) && o < 0.9995)) return false; if (fin(st.offset) && Math.abs(st.offset) >= 0.5) return false; if ((st.fadeTop ?? 0) > 0 || (st.fadeBottom ?? 0) > 0) return false;