Archilyzer · Source

archilyzer

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

commit f214f964d0b13e2fe9f1efe40113760dc9103a56
parent 1b17fbda567aad4e288e9e45a62daae6eb7a7a6b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 12:37:10 -0500

umtool: THE JOIN -- an item of a conversation run (or a manual thread) opens on the item before as it ended and morphs into its own layout over its first 0.6 s (render.posts.join, item join=false): the card's container eased from that item's box to its own, that item's card (shot at its last frame) riding it and fading as this one's comes in, the post it ended on carried in drawn as it was and framed where it sat, the slot's well and attachments cross-faded (the same one held); the read starts after the join (mid-6: 16:29, 14:00, 23:27, 21:04 were cuts)

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

Diffstat:
Mumtool/report-to-video/build-video.mjs | 13++++++++++++-
Mumtool/report-to-video/post-conversation.mjs | 13++++++++-----
Mumtool/report-to-video/post-item.mjs | 58+++++++++++++++++++++++++++++++++++++++++++++++++---------
Aumtool/report-to-video/post-join.mjs | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/post-narration.mjs | 8+++++---
Mumtool/report-to-video/post-render.mjs | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mumtool/report-to-video/post-thread-scenes.test.mjs | 37+++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/read-follow.mjs | 29+++++++++++++++++++++++------
8 files changed, 437 insertions(+), 38 deletions(-)

diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -216,7 +216,16 @@ import { // The snap itself (a montage's window snaps with it too), re-exported for the tests. import { snap } from "./snap.mjs"; import { buildPostSegment } from "./post-render.mjs"; -import { planContextOf } from "./post-conversation.mjs"; +import { planContext, planContextOf } from "./post-conversation.mjs"; + +/** The item before post item `id` with its own context (post-join.mjs: what the item opens on), or null. */ +function postJoinFrom(timeline, id, render, groups) { + const tl = Array.isArray(timeline) ? timeline : []; + const i = tl.findIndex((e) => e?.id === id); + const prev = i > 0 ? tl[i - 1] : null; + if (prev?.type !== "post") return null; + return { entry: prev, ...planContext(tl, i - 1, render), mediaScene: mediaSceneById(tl, prev.id, groups, render) }; +} import { readPostRedaction } from "./post-redact-files.mjs"; import { dropMarks, redactEntry } from "./post-redact.mjs"; import { avatarUrls } from "./post-avatars.mjs"; @@ -6440,6 +6449,8 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly // Its media scene (post-media-scene.mjs): neighbours with the same attachment, over the WHOLE cut's groups -- // its attachment always, its card only when the conversation has no scene (read-follow.mjs: that one wins). mediaScene: mediaSceneById(manifest.timeline, entry.id, postGroups, render), + // THE JOIN (post-join.mjs): the item before and its context, so this one opens on it as it ended. + joinFrom: postJoinFrom(manifest.timeline, entry.id, render, postGroups), }); if (fr) await writeCutRecord(seg, { version: 1, id: entry.id, framing: fr }); // Its combo badge (post-combo-render.mjs): a pass over the segment when its attachment repeats an earlier one's. diff --git a/umtool/report-to-video/post-conversation.mjs b/umtool/report-to-video/post-conversation.mjs @@ -39,6 +39,7 @@ import { cardAuthors, cardText, contextText, isParaphrased, parentsOf } from "./post-item.mjs"; import { isNarrated } from "./post-narration.mjs"; import { followKnobs } from "./read-follow.mjs"; +import { joinKnobs } from "./post-join.mjs"; import { groupOf, partRoles, shownIdOf, threadLayout } from "./post-thread.mjs"; const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); @@ -282,7 +283,9 @@ function contextsOf(tl, render) { ...(run.group ? { group: run.group } : {}), }; } - const ctx = { prev, scene }; + // THE JOIN (post-join.mjs): an item of a run opens on the item before as it ended, its card morphing into its own. + const join = r >= 0 && i > 0 && runOf[i - 1] === r && joinKnobs(e, render).on ? { seconds: joinKnobs(e, render).seconds } : null; + const ctx = { prev, scene, join }; out.push({ entry: e, ...ctx }); // What this item leaves on screen for the next: the scene's posts it kept, its drawn parents, its post. end = null; @@ -315,20 +318,20 @@ function contextsOf(tl, render) { * @param {Array<Record<string, any>>} timeline * @param {number} i * @param {Record<string, any>} [render] - * @returns {{ prev: Record<string, any> | null, scene: { tiles: Array<Record<string, any>>, rank: Record<string, number> } | null }} + * @returns {{ prev: Record<string, any> | null, scene: { tiles: Array<Record<string, any>>, rank: Record<string, number>, group?: string } | null, join: { seconds: number } | null }} */ export function planContext(timeline, i, render = undefined) { const tl = Array.isArray(timeline) ? timeline : []; - if (!(i >= 0 && i < tl.length)) return { prev: i > 0 ? tl[i - 1] ?? null : null, scene: null }; + if (!(i >= 0 && i < tl.length)) return { prev: i > 0 ? tl[i - 1] ?? null : null, scene: null, join: null }; const c = contextsOf(tl, render)[i]; - return { prev: c.prev, scene: c.scene }; + return { prev: c.prev, scene: c.scene, join: c.join }; } /** The context of the item with id `id` (planContext; `{ prev: null, scene: null }` when there is none). */ export function planContextOf(timeline, id, render = undefined) { const tl = Array.isArray(timeline) ? timeline : []; const i = tl.findIndex((e) => e?.id === id); - return i < 0 ? { prev: null, scene: null } : planContext(tl, i, render); + return i < 0 ? { prev: null, scene: null, join: null } : planContext(tl, i, render); } // --------------------------------------------------------------------------- diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -37,6 +37,7 @@ import { blurErrors } from "./post-censor.mjs"; import { WORD_ZOOM_HIGHLIGHT_ALPHA, cardTokens, cardWordsOf, findMatch, targetTextOf, validatePostFx } from "./word-zoom.mjs"; import { FOLLOW_MIN_SIZE, followBlocks, followSchedule, scopeBlocks, validatePostFollow } from "./read-follow.mjs"; import { panelSchedule, validatePostThread } from "./post-thread.mjs"; +import { joinLayerHtml, validatePostJoin, validatePostJoinRender } from "./post-join.mjs"; import { validatePostScene, validatePostSceneRender } from "./post-media-scene.mjs"; /** The platforms a post item may come from (deck.mjs POST_PLATFORMS). */ @@ -252,12 +253,12 @@ export function postItemSeconds(entry, render = undefined) { * * @param {Record<string, any>} entry * @param {Record<string, any>} [render] - * @param {{ prev?: Record<string, any> | null, scene?: Record<string, any> | null, mediaScene?: Record<string, any> | null }} [o] the item before it in the cut (post-thread.mjs carries a parent that is it) + * @param {{ prev?: Record<string, any> | null, scene?: Record<string, any> | null, mediaScene?: Record<string, any> | null, join?: { seconds: number } | null }} [o] the item before it in the cut (post-thread.mjs carries a parent that is it); `join` (post-conversation.mjs planContext): it opens on the item before as it ended (post-join.mjs) * @returns {{ reading: number, total: number, steps: Array<Record<string, any>>, held: number, narration?: Record<string, any>, follow?: Record<string, any> }} */ -export function postItemPlan(entry, render = undefined, { prev = null, scene = null, mediaScene = null } = {}) { +export function postItemPlan(entry, render = undefined, { prev = null, scene = null, mediaScene = null, join = null } = {}) { const hold = fin(entry?.hold) && entry.hold > 0 ? round3(entry.hold) : null; - return planOf(entry, render, hold, prev, scene, mediaScene); + return planOf(entry, render, hold, prev, scene, mediaScene, join); } /** @@ -268,13 +269,15 @@ export function postItemPlan(entry, render = undefined, { prev = null, scene = n * @param {Record<string, any> | null} [scene] * @param {Record<string, any> | null} [mediaScene] */ -function planOf(entry, render, hold, prev = null, scene = null, mediaScene = null) { +function planOf(entry, render, hold, prev = null, scene = null, mediaScene = null, join = null) { const narrated = isNarrated(entry); const k = postNarrationKnobs(entry, render); - const sch = narrated ? narrationSchedule(entry, render) : null; + // THE JOIN (post-join.mjs) comes first: the read starts after it (the item a join's seconds longer). + const pre = join && fin(join.seconds) ? join.seconds : 0; + const sch = narrated ? narrationSchedule(entry, render, { pre }) : null; // Its read-follow (read-follow.mjs): each block's start on the item's clock -- null when it is off. `prev`: the // item before it in the cut (post-thread.mjs: a parent that is that item is carried in, not cut to). - const follow = followSchedule(entry, render, { hold, narration: sch, prev, scene, mediaScene }); + const follow = followSchedule(entry, render, { hold, narration: sch, prev, scene, mediaScene, join }); const extra = { ...(sch ? { narration: sch } : {}), ...(follow ? { follow } : {}) }; if (sch && k.attach === "after") { const voiceOnly = round3(sch.at + sch.seconds + k.tail); @@ -544,6 +547,8 @@ export function validatePostItem(e) { errors.push(...validatePostThread(e)); // Its media scene (post-media-scene.mjs): false (never in one) or "join". errors.push(...validatePostScene(e)); + // Its join with the item before (post-join.mjs): false (a cut) or { seconds }. + errors.push(...validatePostJoin(e)); return errors; } @@ -582,7 +587,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)); + errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(manifest?.render), ...validatePostJoinRender(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)); @@ -957,7 +962,7 @@ export function nameHtml(who, { redact, cls = "" }) { * redaction?: { terms: Array<{term: string, wholeWord?: boolean}>, markup?: Record<string, any> } | null, follow?: boolean, * thread?: { tiles?: Array<{ scope: string, mode: string }> } | null }} o */ -export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, phase = "read", parentShotUrl = null, transparent = false, avatars = {}, highlight = null, redaction = null, follow = false, thread = null }) { +export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, phase = "read", parentShotUrl = null, transparent = false, avatars = {}, highlight = null, redaction = null, follow = false, thread = null, join = null }) { const hlOf = (scope) => (highlight && highlight.scope === scope ? highlight : null); // THREADED (post-thread.mjs): the conversation as a column of tiles -- `thread` the layout's tiles // (threadLayout, or the plan's follow.thread), each `{ scope, mode }`; a hidden one is not drawn. @@ -1054,10 +1059,19 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p // A context post's tile: a parent (`data-post-parent`), a post its words link to (`data-post-linked`). One with // no words but an attachment (an image-only reply) is its head and a chip naming what it carries -- the // 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 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>`); + }; const refTile = (scope, p, where, attr) => { const mode = tmode(scope); if (!mode || mode === "hidden" || !refShown(p)) return; const r = red(where); + if (mode === "carry" && join && contextText(p).trim()) return asPost(scope, p, r, attr, mode); const subject = !r && subjectsOf(entry).some((h) => String(h).toLowerCase() === String(p.handle ?? "").replace(/^@/, "").toLowerCase()); const words = contextText(p); const size = sizeFor(words || " ", innerW - av - Math.round(16 * k), innerH - 90 * k); @@ -1098,6 +1112,10 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p if (t.mode !== "scene" || !isObj(t.ref)) continue; 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"); + continue; + } const text = str(ref.text); const tsize = sizeFor(text || " ", innerW - av - Math.round(16 * k), innerH - 90 * k); tileHtml.push( @@ -1182,7 +1200,7 @@ b, .name, .mark { font-family: 'PostSansBold', sans-serif; font-weight: 400; } [data-w-hl] { background: ${rgbaOf(highlight.color, WORD_ZOOM_HIGHLIGHT_ALPHA)}; box-shadow: inset 0 -0.12em 0 ${highlight.color}; border-radius: 0.16em; padding: 0 0.08em; margin: 0 -0.08em; -webkit-box-decoration-break: clone; box-decoration-break: clone; }` : ""} ${BAR_CSS(pal.fg)} </style></head> -<body data-post-item="${esc(entry.id)}" data-post-layout="${L.mode}" data-post-phase="${strip ? "media" : "read"}"${fmap ? ` data-post-follow="${fmap.blocks.length}"` : ""}${tc ? ` data-post-thread="${tiles.length}"` : ""}>${barsHtml(body)} +<body data-post-item="${esc(entry.id)}" data-post-layout="${L.mode}" data-post-phase="${strip ? "media" : "read"}"${fmap ? ` data-post-follow="${fmap.blocks.length}"` : ""}${tc ? ` data-post-thread="${tiles.length}"` : ""}${join?.A ? ` data-join="${esc(JSON.stringify({ A: join.A, slotA: join.slotA ?? null, slotB: L.slot && (L.mode === "side" || strip) ? L.slot : null, same: !!join.same }))}"` : ""}>${join?.A ? joinLayerHtml({ fromUrl: join.fromUrl ?? null, slotA: join.slotA ?? null, cardBg, line, radius: Math.round(18 * k) }) : ""}${barsHtml(body)} <script> // The words at the layout's size, shrunk while they overflow (the browser // knows how they wrap; the layout only estimated it). Then say so. @@ -1207,6 +1225,28 @@ ${BAR_CSS(pal.fg)} } /** + * THE SIZE a card draws its post's words at (post-join.mjs: the post the next item carries is drawn alike): + * threaded, the size that fits it alone in its tile; else the layout's (at least the follow minimum). The page may + * shrink a plain card's further when it overflows -- the estimate's. + * + * @param {Record<string, any>} entry + * @param {{ width: number, height: number }} box + * @param {{ follow?: boolean, threaded?: boolean }} [o] + */ +export function cardWordsSize(entry, { width, height }, { follow = false, threaded = false } = {}) { + const L = postLayout(entry, { width, height }); + const k = height / 1080; + const followMin = Math.round(FOLLOW_MIN_SIZE * k); + if (threaded) { + const own = cardText(entry); + const innerW = L.card.width - 2 * L.pad; + const innerH = L.card.height - 2 * L.pad; + return own.trim() ? Math.max(followMin, fitSize(own, innerW, innerH - 170 * k, k).size) : Math.max(L.size, followMin); + } + return follow ? Math.max(L.size, followMin) : L.size; +} + +/** * A MEDIA SCENE's earlier message as a tile of a later item's column * (post-media-scene.mjs; postCardHtml's threaded card): drawn as its own post * tile was while it was read -- the repost line, its author (under its own diff --git a/umtool/report-to-video/post-join.mjs b/umtool/report-to-video/post-join.mjs @@ -0,0 +1,198 @@ +// THE JOIN between two post items of one run (umtool/docs/report-video.md, "The join"; operator, 4 Nov, mid-6: +// "I'd like a thread-like smooth transition here rather than a cut", "better transition needed between before and +// here", "better thread handling here too"): a conversation run (post-conversation.mjs) -- or a manual thread -- +// is ONE continuous scene even where its items' layouts differ (a card beside an attachment, a card alone, another +// attachment, another width). The item's first `seconds` (0.6) are the join: +// +// the CARD its container morphs from the item before's box (as it ended) to its own -- position, +// width and height eased; the words inside scaled with its width, never re-flowed +// what it SHOWED the item before's card as it ended (the build: a shot of its page at its last frame; +// Play: its page in a second frame) rides the container and fades out as this one's fades in +// the COLUMN the post the item before ended on (carried, or the scene's) is drawn as that item drew it +// -- its head, its words at their size -- and the column opens framed where it was +// the SLOT a slot that appears fades in, one that goes fades out; another attachment cross-fades +// over the one the item before ended on (its last frame); the same one is held (a media scene) +// +// render.posts.join = { on?: true, seconds?: 0.6 } the cut's +// timeline[i].join = false | { seconds? } one item's (false: a cut) +// +// PURE and dependency-free (but its siblings): the plan carries `follow.join` (its seconds; the state at a second +// carries the progress), the build and Play draw the same frame from joinFrameAt. + +const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); +const fin = (v) => typeof v === "number" && Number.isFinite(v); +const r2 = (v) => Math.round(v * 100) / 100; + +export const JOIN_DEFAULTS = Object.freeze({ on: true, seconds: 0.6 }); +export const JOIN_LIMITS = Object.freeze({ seconds: [0.2, 2] }); + +/** One join knob's errors (`where`: its path). */ +export function joinKnobErrors(v, where, { item = false } = {}) { + if (v === undefined || v === null || (item && v === false)) return []; + if (!isObj(v)) return [`${where} must be ${item ? "false (a cut) or " : ""}{ ${item ? "" : "on?, "}seconds? }`]; + const errors = []; + for (const k of Object.keys(v)) if (!(item ? ["seconds"] : ["on", "seconds"]).includes(k)) errors.push(`${where}.${k} is not a join knob`); + if (v.on !== undefined && typeof v.on !== "boolean") errors.push(`${where}.on must be true or false`); + if (v.seconds !== undefined && !(fin(v.seconds) && v.seconds >= JOIN_LIMITS.seconds[0] && v.seconds <= JOIN_LIMITS.seconds[1])) errors.push(`${where}.seconds must be ${JOIN_LIMITS.seconds[0]}–${JOIN_LIMITS.seconds[1]}`); + return errors; +} + +/** A post item's `join` errors, and the cut's (validatePostItem / validatePostItems). */ +export const validatePostJoin = (e) => joinKnobErrors(e?.join, `timeline ${e?.id ?? "?"}.join`, { item: true }); +export const validatePostJoinRender = (render) => joinKnobErrors(render?.posts?.join, "render.posts.join"); + +/** One item's join knobs: its own, else the cut's, else the defaults. */ +export function joinKnobs(entry, render = undefined) { + const r = isObj(render?.posts?.join) ? render.posts.join : {}; + const k = { ...JOIN_DEFAULTS, ...(typeof r.on === "boolean" ? { on: r.on } : {}), ...(fin(r.seconds) ? { seconds: r.seconds } : {}) }; + if (entry?.join === false) return { ...k, on: false }; + if (isObj(entry?.join) && fin(entry.join.seconds)) k.seconds = entry.join.seconds; + return k; +} + +/** The join's ease: in-out cubic. */ +export const joinEase = (x) => { + const v = Math.min(1, Math.max(0, x)); + return v < 0.5 ? 4 * v ** 3 : 1 - (-2 * v + 2) ** 3 / 2; +}; +const lerp = (a, b, f) => a + (b - a) * f; +const lerpRect = (a, b, f) => ({ x: lerp(a.x, b.x, f), y: lerp(a.y, b.y, f), width: lerp(a.width, b.width, f), height: lerp(a.height, b.height, f) }); +const sameRect = (a, b) => !!a && !!b && ["x", "y", "width", "height"].every((k) => Math.abs(a[k] - b[k]) < 1.5); + +/** + * THE JOIN's FRAME at progress `p` (0: the item before as it ended, 1: this item's own), pure: `{ e, R, own, from, + * slotFrom, slotTo }` -- `R` the container's box; `own` this card's transform (`tx`, `ty`, `s`: its top-left moved to + * R's, scaled by R's width over its own; `clipH` the height of it that shows; `op`); `from` the item before's card + * as it ended (`x`, `y`, `s` its scale -- R's width over its own -- and `op`); `slotFrom` / `slotTo` the strength of + * the slot wells (the item before's, this one's). `g`: `{ A, B, slotA, slotB, same }` -- the two cards' boxes, their + * slots, and whether the CONTENT is the same at both ends (a carried post drawn alike: no cross-fade). + */ +export function joinFrameAt(g, p) { + const e = joinEase(p); + const A = g.A; + const B = g.B; + const R = lerpRect(A, B, e); + const s = R.width / Math.max(1, B.width); + // The content cross-fades over the middle half of the join; the same content (sameRect, a carry alike) shows + // this card's from the first frame -- the item before's drawn under it only as long as the box moves. + const x = Math.min(1, Math.max(0, (e - 0.4) / 0.4)); + const y = Math.min(1, Math.max(0, (e - 0.1) / 0.4)); + const opOwn = g.same ? 1 : x; + const sameSlot = sameRect(g.slotA, g.slotB); + return { + e: r2(e), + R: { x: r2(R.x), y: r2(R.y), width: r2(R.width), height: r2(R.height) }, + own: { tx: r2(R.x - B.x), ty: r2(R.y - B.y), s: Math.round(s * 10000) / 10000, clipH: r2(R.height / Math.max(1e-6, s)), op: r2(opOwn) }, + from: { x: r2(R.x), y: r2(R.y), s: Math.round((R.width / Math.max(1, A.width)) * 10000) / 10000, op: r2(g.same ? 1 - Math.min(1, e / 0.3) : 1 - y) }, + slotFrom: g.slotA && !sameSlot ? r2(1 - e) : g.slotA ? 1 : 0, + slotTo: g.slotB && !sameSlot ? r2(e) : g.slotB ? 1 : 0, + }; +} + +/** The join's progress at item second `s` (null: over, or none). */ +export const joinProgressAt = (join, s) => (join && fin(join.seconds) && s < join.seconds - 1e-6 ? Math.max(0, s / join.seconds) : null); + +/** + * WHAT THE ITEM BEFORE ENDED ON in its slot, pure: `[{ m, i, t, scope }]` -- the attachments up at its last frame + * (`t` a video's or a GIF's source second there; a context post's on the panel over its own: `scope`). + * `stepAt` / `mediaTimeAt` are post-item.mjs's (passed: this module imports none of it). + */ +export function endMediaOf(plan, { stepAt, mediaTimeAt, fps = 30 } = {}) { + if (!plan) return []; + const last = Math.max(0, plan.total - 1 / fps); + const show = [...(plan.panel?.shows ?? [])].reverse().find((sh) => sh.t0 <= last && sh.t1 >= last - 1e-6); + if (show) return show.media.map((m, i) => ({ m, i, t: 0, scope: show.scope })); + const step = stepAt(plan, last) ?? plan.steps?.[0] ?? null; + if (!step) return []; + const t = mediaTimeAt(step, last); + // A video held on its last frame: a little before its end (a seek to the very end finds no frame). + return step.items.map((m) => ({ m, i: m.i, t: fin(t) ? Math.max(0, fin(m.seconds) ? Math.min(t, m.seconds - 0.12) : t) : 0, step })); +} + +/** + * IN THE PAGE (self-contained: the build passes it to page.evaluate, Play calls it on its frame's document): this + * card at join progress `p` -- its box moved, scaled and clipped to the container's, its own background drawn by a + * well at the container's box, the item before's card shot (`img[data-join-from]`, the build's) riding it, the slot + * wells faded. The geometry is the body's `data-join` (`{ A, slotA, slotB, same }`); this card's own box is measured + * on the first call (its style put back when `p` is null). + */ +export function applyJoinState(p, doc = document) { + const body = doc.body; + const card = doc.querySelector("[data-post-card]"); + if (!body || !card) return; + const raw = body.getAttribute("data-join"); + const bg = doc.querySelector("[data-join-bg]"); + const from = doc.querySelector("[data-join-from]"); + const slotFrom = doc.querySelector("[data-join-slot-from]"); + const slot = doc.querySelector("[data-post-slot]"); + if (p === null || p === undefined || !raw) { + if (card.getAttribute("data-join-on")) { + card.style.transform = card.getAttribute("data-join-t") || ""; + card.style.clipPath = ""; + card.style.opacity = ""; + card.style.background = ""; + card.style.borderColor = ""; + card.style.top = card.getAttribute("data-join-top") || card.style.top; + card.removeAttribute("data-join-on"); + } + if (bg) bg.style.display = "none"; + if (from) from.style.display = "none"; + if (slotFrom) slotFrom.style.display = "none"; + if (slot) slot.style.opacity = ""; + return; + } + const g = JSON.parse(raw); + if (!card.getAttribute("data-join-on")) { + // Its own box, as laid out (a card alone is centred by a translate: its top made explicit while it joins). + card.setAttribute("data-join-t", card.style.transform || ""); + card.setAttribute("data-join-top", card.style.top || ""); + const b = card.getBoundingClientRect(); + card.setAttribute("data-join-b", JSON.stringify({ x: b.left, y: b.top, width: b.width, height: b.height })); + card.style.top = `${b.top}px`; + card.setAttribute("data-join-on", "1"); + } + const B = JSON.parse(card.getAttribute("data-join-b")); + const A = g.A; + // joinFrameAt, inlined (this function reaches for nothing outside). + const v = Math.min(1, Math.max(0, p)); + const e = v < 0.5 ? 4 * v ** 3 : 1 - (-2 * v + 2) ** 3 / 2; + const L = (a, b2) => a + (b2 - a) * e; + const R = { x: L(A.x, B.x), y: L(A.y, B.y), width: L(A.width, B.width), height: L(A.height, B.height) }; + const s = R.width / Math.max(1, B.width); + const x = Math.min(1, Math.max(0, (e - 0.4) / 0.4)); + const y = Math.min(1, Math.max(0, (e - 0.1) / 0.4)); + const same = (a, b2) => !!a && !!b2 && ["x", "y", "width", "height"].every((k) => Math.abs(a[k] - b2[k]) < 1.5); + const sameSlot = same(g.slotA, g.slotB); + card.style.transformOrigin = "0 0"; + card.style.transform = `translate(${R.x - B.x}px, ${R.y - B.y}px) scale(${s})`; + card.style.clipPath = `inset(0 0 ${Math.max(0, B.height - R.height / s)}px 0)`; + card.style.background = "transparent"; + card.style.borderColor = "transparent"; + card.style.opacity = String(g.same ? 1 : x); + if (bg) { + bg.style.display = "block"; + bg.style.left = `${R.x}px`; + bg.style.top = `${R.y}px`; + bg.style.width = `${R.width}px`; + bg.style.height = `${R.height}px`; + } + if (from) { + from.style.display = "block"; + from.style.left = `${R.x}px`; + from.style.top = `${R.y}px`; + from.style.width = `${A.width}px`; + from.style.transform = `scale(${R.width / Math.max(1, A.width)})`; + from.style.clipPath = `inset(0 0 ${Math.max(0, A.height - R.height / (R.width / Math.max(1, A.width)))}px 0)`; + from.style.opacity = String(g.same ? 1 - Math.min(1, e / 0.3) : 1 - y); + } + if (slotFrom) { + slotFrom.style.display = g.slotA && !sameSlot ? "block" : "none"; + slotFrom.style.opacity = String(1 - e); + } + if (slot) slot.style.opacity = g.slotB && !sameSlot ? String(e) : ""; +} + +/** The page's join layer (postCardHtml): the container's well, the item before's shot, its slot's well -- hidden until a join state shows them. */ +export function joinLayerHtml({ fromUrl = null, slotA = null, cardBg, line, radius }) { + return `<div data-join-bg="" style="position:absolute;display:none;background:${cardBg};border:1px solid ${line};border-radius:${radius}px"></div>${slotA ? `<div data-join-slot-from="" style="position:absolute;display:none;left:${slotA.x}px;top:${slotA.y}px;width:${slotA.width}px;height:${slotA.height}px;background:rgba(0,0,0,0.32);border-radius:${Math.round(radius * 0.78)}px"></div>` : ""}${fromUrl ? `<img data-join-from="" alt="" src="${String(fromUrl).replace(/"/g, "&quot;")}" style="position:absolute;display:none;transform-origin:0 0;z-index:2">` : ""}`; +} diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs @@ -262,14 +262,16 @@ export function nextTakeNumber(entry, files = []) { * * @returns {{ at: number, seconds: number, takeSeconds: number, rate: number, voiceEnd: number, rampEnd: number, wet: number, lowpassHz: number, duck: boolean, attach: string, lufs: number }} */ -export function narrationSchedule(entry, render) { +export function narrationSchedule(entry, render, { pre = 0 } = {}) { const t = pickedTake(entry); const k = postNarrationKnobs(entry, render); const rate = narrationRateOf(entry, render); const seconds = t ? readSecondsOf(t.seconds, rate) : 0; - const voiceEnd = round3(k.lead + seconds + k.tail); + // `pre`: seconds before the lead that are the JOIN's (post-join.mjs: the card morphing from the item before's). + const lead = k.lead + (Number.isFinite(pre) && pre > 0 ? pre : 0); + const voiceEnd = round3(lead + seconds + k.tail); return { - at: round3(k.lead), + at: round3(lead), seconds: round3(seconds), takeSeconds: round3(t ? t.seconds : 0), rate, 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, panelEntry, postCardHtml, postItemPlan, postLayout, stepBoxes } from "./post-item.mjs"; +import { POST_PICTURE_XFADE, POST_PUSH, 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"; @@ -26,6 +26,7 @@ import { bleepFilters, slursOn, takeBleeps } from "./post-slurs.mjs"; import { blurFilters, blurOn, censorEntry, labelFilter } from "./post-censor.mjs"; import { sceneEntry } from "./post-media-scene.mjs"; import { panelReadErrors } from "./post-thread.mjs"; +import { applyJoinState, endMediaOf } from "./post-join.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; @@ -82,7 +83,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 = [] }) { +export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [], join = null }) { const fps = render.fps ?? 30; const T = plan.total; const inputs = []; @@ -184,6 +185,8 @@ export function postSegmentArgs({ entry, box, plan, layout, cards, files, render audio.push({ label: `a${si}`, chain: `[${k}:a]aresample=${render.audioRate ?? 48000},aformat=channel_layouts=stereo,asetpts=PTS-STARTPTS,atrim=0:${num(dur)},afade=t=in:d=0.04,afade=t=out:st=${num(Math.max(0, dur - 0.06))}:d=0.06,adelay=${ms}|${ms}[a${si}]` }); } } + // THE JOIN (post-join.mjs): another attachment than the one the item before ended on fades in over it. + if (si === 0 && join?.fadeIn) parts[parts.length - 1] = parts[parts.length - 1].replace(new RegExp(`\\[${raw}\\]$`), `,format=rgba,fade=t=in:st=${num(join.seconds * 0.35)}:d=${num(join.seconds * 0.65)}:alpha=1[${raw}]`); if (raw !== label) parts.push(...blurFilters(raw, label, m, b)); lay(label, b.x, b.y, shownFrom, until); // Its label ("Censored") on the frame, at the attachment's corner, while it is up. @@ -232,6 +235,21 @@ export function postSegmentArgs({ entry, box, plan, layout, cards, files, render }); }); } + // THE JOIN (post-join.mjs): what the item before ended on in its slot, fading out over the join (a video playing on). + if (join?.from?.length) { + const J = join.seconds; + join.from.forEach((f, ji) => { + const label = `jf${ji}`; + const raw = blurOn(f.m) ? `${label}r` : label; + const crop = Array.isArray(f.m.crop) ? `crop=iw*${num(f.m.crop[2])}:ih*${num(f.m.crop[3])}:iw*${num(f.m.crop[0])}:ih*${num(f.m.crop[1])},` : ""; + const k = f.m.kind === "image" + ? add(["-loop", "1", "-framerate", String(fps), "-t", num(J), "-i", f.file]) + : add([...(f.m.kind === "gif" ? ["-stream_loop", "-1"] : []), "-ss", num(f.t), "-t", num(J + 0.1), "-i", f.file]); + parts.push(`[${k}:v]${crop}scale=${f.box.width}:${f.box.height},setsar=1,fps=${fps},setpts=PTS-STARTPTS,tpad=stop_mode=clone:stop_duration=${num(J)},format=rgba,fade=t=out:st=0:d=${num(J)}:alpha=1[${raw}]`); + if (raw !== label) parts.push(...blurFilters(raw, label, f.m, f.box)); + lay(label, f.box.x, f.box.y, 0, J); + }); + } // 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)); @@ -289,7 +307,7 @@ async function loadChromium() { * stack layout. The page is a file beside them, so its faces and the parent * shot load from disk (an about:blank page may not read file: urls). */ -export async function renderPostCards(entry, { box, render, dir, manifestDir, layout, avatars = {}, zooms = [], redaction = null, follow = null, total = 0 }) { +export async function renderPostCards(entry, { box, render, dir, manifestDir, layout, avatars = {}, zooms = [], redaction = null, follow = null, total = 0, joinFrom = null }) { await mkdir(dir, { recursive: true }); const fonts = { regular: render.fontRegular ? pathToFileURL(render.fontRegular).href : "", @@ -303,14 +321,53 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la try { const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: 1, offline: true, serviceWorkers: "block" }); const page = await ctx.newPage(); + const av = Object.fromEntries(Object.entries(avatars).map(([h, f]) => [h, pathToFileURL(f).href])); + // THE JOIN (post-join.mjs): the item before's card as it ENDED -- its page drawn, its last frame's state set, its + // card shot -- and where its post's words sat; this card opens on it and morphs into its own. + let join = null; + if (follow?.join && joinFrom?.entry) { + const fps = render.fps ?? 30; + const pe = joinFrom.entry; + const pf = joinFrom.plan?.follow ?? null; + const ph = postCardHtml(pe, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", avatars: av, follow: !!pf, thread: pf?.thread ?? null, redaction }); + const pfile = path.join(dir, "join-from.html"); + await writeFile(pfile, ph, "utf8"); + await page.goto(pathToFileURL(pfile).href, { waitUntil: "load" }); + await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); + if (pf) { + const pgeo = await page.evaluate(measureFollow); + await page.evaluate(applyFollowState, followStateAt(pf, followPath(pf, pgeo), Math.max(0, joinFrom.plan.total - 1 / fps))); + } + const m = await page.evaluate(() => { + const card = document.querySelector("[data-post-card]"); + 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"); + 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 }; + }); + if (m) { + const png = path.join(dir, "join-from.png"); + const x = Math.max(0, Math.floor(m.A.x)); + const y = Math.max(0, Math.floor(m.A.y)); + await page.screenshot({ path: png, clip: { x, y, width: Math.min(box.width - x, Math.ceil(m.A.width)), height: Math.min(box.height - y, Math.ceil(m.A.height)) } }); + const pl = postLayout(pe, box); + const same = Math.abs(m.A.width - layout.card.width) < 2 && !!(follow.thread?.tiles ?? []).some((t) => t.mode === "carry" || (t.mode === "scene" && t.wasPost)); + join = { A: { x, y, width: Math.ceil(m.A.width), height: Math.ceil(m.A.height) }, slotA: pl.slot && pl.mode === "side" ? pl.slot : null, fromUrl: pathToFileURL(png).href, size: m.size, same, anchor: m.anchor }; + out.joinFrom = { A: join.A, layout: pl }; + } + } for (const phase of phases) { const html = postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase, parentShotUrl, - avatars: Object.fromEntries(Object.entries(avatars).map(([h, f]) => [h, pathToFileURL(f).href])), + avatars: av, follow: !!follow && phase === "read", // A threaded card (post-thread.mjs): the plan's tiles. thread: follow?.thread ?? null, redaction, + ...(join && phase === "read" ? { join } : {}), }); const file = path.join(dir, `${phase}.html`); await writeFile(file, html, "utf8"); @@ -322,6 +379,15 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la if (phase === "read" && follow) { const fps = render.fps ?? 30; const geo = await page.evaluate(measureFollow); + // THE JOIN: the carried post opens where the item before's post sat (its top this far down the window). + if (join && geo && join.anchor !== null) { + 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; + }); + if (own) geo.joinAnchor = { y: Math.round((join.anchor / (join.A.width / own.width) - own.win) * 100) / 100 }; + } out.follow = await shootFollow(page, { follow, total, fps, box, dir, geo }); // 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. @@ -361,7 +427,9 @@ export async function shootFollow(page, { follow, total, fps, box, dir, geo = nu if (!r) return null; const x = Math.max(0, Math.floor(r.x)); const y = Math.max(0, Math.floor(r.y)); - const clip = { x, y, width: Math.min(box.width - x, Math.ceil(r.x + r.width) - x), height: Math.min(box.height - y, Math.ceil(r.y + r.height) - y) }; + // A JOIN (post-join.mjs) moves the card and the slot's well: the whole box is shot. + const joined = !!follow.join && (await page.evaluate(() => !!document.body.getAttribute("data-join"))); + const clip = joined ? { x: 0, y: 0, width: box.width, height: box.height } : { x, y, width: Math.min(box.width - x, Math.ceil(r.x + r.width) - x), height: Math.min(box.height - y, Math.ceil(r.y + r.height) - y) }; const fdir = path.join(dir, "follow"); await rm(fdir, { recursive: true, force: true }); await mkdir(fdir, { recursive: true }); @@ -370,10 +438,12 @@ export async function shootFollow(page, { follow, total, fps, box, dir, geo = nu if (shots.has(run.key)) continue; const file = path.join(fdir, `f-${String(shots.size).padStart(5, "0")}.png`); await page.evaluate(applyFollowState, run.st); + if (joined) await page.evaluate(applyJoinState, run.st.join ?? null); await page.screenshot({ path: file, clip }); shots.set(run.key, file); } await page.evaluate(applyFollowState, null); + if (joined) await page.evaluate(applyJoinState, 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)}`); @@ -471,10 +541,10 @@ async function shootZooms(browser, entry, { box, render, dir, fonts, parentShotU * scale, highlight, span }]`, each on its time (wordZoomTimes) -- refused in * the build's words when one has no time, or two are up at once. */ -export function postZoomPlan(entry, render, total = Infinity) { +export function postZoomPlan(entry, render, total = Infinity, schedule = undefined) { const fx = Array.isArray(entry?.fx) ? entry.fx : []; if (!fx.length) return []; - const times = wordZoomTimes(entry, render); + const times = wordZoomTimes(entry, render, schedule); const bad = times.filter((t) => t.error); if (bad.length) throw new Error(bad.map((t) => t.error).join("; ")); const zooms = fx.map((f0, i) => { @@ -503,7 +573,7 @@ export function postZoomPlan(entry, render, total = Infinity) { * attachment the anchor's, the scene's earlier messages above its card -- not * drawn when `scene` is). Returns the segment's path. */ -export async function buildPostSegment(entry, { render, outDir, manifestDir, box, place = [], encode = [], exec, ffmpeg = "ffmpeg", emit = () => {}, avatars = {}, redaction = null, prev = null, scene = null, mediaScene = null }) { +export async function buildPostSegment(entry, { render, outDir, manifestDir, box, place = [], encode = [], exec, ffmpeg = "ffmpeg", emit = () => {}, avatars = {}, redaction = null, prev = null, scene = null, mediaScene = null, join = null, joinFrom = null }) { // A channel's markup may censor an attachment for every project (post-censor.mjs); the item's own blur wins. entry = censorEntry(entry, redaction); // In a media scene (post-media-scene.mjs) the shared attachment is the anchor's -- its markup laid on too. @@ -516,8 +586,29 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box const seg = path.join(outDir, "segments", `${entry.id}.mp4`); // `prev`: the item before it in the cut (post-thread.mjs: a parent that is that item is carried in); `scene`: what // its run left on screen (post-conversation.mjs) -- in plan.follow, so in the segment's key; a media scene too. - const plan = postItemPlan(entry, render, { prev, scene, mediaScene }); + const plan = postItemPlan(entry, render, { prev, scene, mediaScene, join }); const layout = postLayout(entry, box); + // THE JOIN (post-join.mjs): the item before as ITS segment draws it (its markup, its media scene, the cut's panel + // rule), its plan -- what this item opens on. `joinFrom`: its entry and its context (planContext's, mediaSceneOf's). + let from = null; + if (plan.follow?.join && joinFrom?.entry?.type === "post") { + let pe = censorEntry(joinFrom.entry, redaction); + pe = panelEntry(sceneEntry(pe, joinFrom.mediaScene ?? null, { censor: (e) => censorEntry(e, redaction) }), render); + const pp = postItemPlan(pe, render, { prev: joinFrom.prev ?? null, scene: joinFrom.scene ?? null, mediaScene: joinFrom.scene ? null : joinFrom.mediaScene ?? null, join: joinFrom.join ?? null }); + const pl = postLayout(pe, box); + const ends = pl.slot && pl.mode === "side" ? endMediaOf(pp, { stepAt, mediaTimeAt, fps: render.fps ?? 30 }) : []; + const boxesOf = (list) => (list.length ? stepBoxes({ items: list.map((x, j) => ({ ...x.m, i: j })) }, pl.slot) : []); + const eb = boxesOf(ends); + const firstOwn = plan.steps[0]?.items?.[0] ?? null; + const ownBox = firstOwn && layout.slot && layout.mode === "side" ? stepBoxes(plan.steps[0], layout.slot)[0] : null; + // The same attachment in the same box (a media scene): held, neither faded. + const held = !!firstOwn && ends.length === 1 && ends[0].m.src === firstOwn.src && !!ownBox && Math.abs(ownBox.x - eb[0].x) < 2 && Math.abs(ownBox.y - eb[0].y) < 2 && Math.abs(ownBox.width - eb[0].width) < 2; + from = { + entry: pe, plan: pp, + media: held ? [] : ends.map((x, j) => ({ file: path.resolve(manifestDir, x.m.src), m: x.m, t: x.t, box: eb[j] })), + fadeIn: !held && !!firstOwn, + }; + } const files = (entry.media ?? []).map((m) => path.resolve(manifestDir, m.src)); for (const [i, f] of files.entries()) { if (!(await stat(f).catch(() => null))) throw new Error(`${entry.id}: media[${i}] is not on disk: ${f} (src: ${entry.media[i].src})`); @@ -534,13 +625,13 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box if (takeFile && !(await stat(takeFile).catch(() => null))) throw new Error(`${entry.id}: its narration take is not on disk: ${takeFile} (${take.file})`); // The slurs its take SAYS, covered (post-slurs.mjs): a public render never plays one -- without word timings it is refused. const bleeps = take ? takeSlurBleeps(entry, take, redaction) : null; - const stamps = await Promise.all([...files, ...panelFiles.flat(), ...wordFiles.filter(Boolean), ...Object.values(avatars), ...(takeFile ? [takeFile] : []), ...(entry.parentShot ? [path.resolve(manifestDir, entry.parentShot)] : [])].map(async (f) => { + const stamps = await Promise.all([...files, ...panelFiles.flat(), ...(from?.media ?? []).map((x) => x.file), ...wordFiles.filter(Boolean), ...Object.values(avatars), ...(takeFile ? [takeFile] : []), ...(entry.parentShot ? [path.resolve(manifestDir, entry.parentShot)] : [])].map(async (f) => { const st = await stat(f).catch(() => null); return st ? `${f}:${st.size}:${Math.round(st.mtimeMs)}` : `${f}:-`; })); const key = createHash("sha256") // A redaction that changes what the card draws changes the key; none leaves it as it was. - .update(JSON.stringify({ v: 1, entry, ...(redactionOn(redaction) ? { published: redactEntry(entry, redaction), blank: termsFor(entry, redaction) } : {}), box, place, palette: render.palette, fonts: [render.fontRegular, render.fontBold], fps: render.fps, encode, stamps, ...(Object.keys(avatars).length ? { avatars } : {}), ...(take ? { narration: plan.narration, postNarration: render.postNarration ?? null } : {}), ...(plan.follow ? { follow: plan.follow } : {}), ...(bleeps ? { bleeps } : {}), ...(slursOn(redaction?.slurs) ? { slurs: redaction.slurs } : {}) })) + .update(JSON.stringify({ v: 1, entry, ...(redactionOn(redaction) ? { published: redactEntry(entry, redaction), blank: termsFor(entry, redaction) } : {}), box, place, palette: render.palette, fonts: [render.fontRegular, render.fontBold], fps: render.fps, encode, stamps, ...(Object.keys(avatars).length ? { avatars } : {}), ...(take ? { narration: plan.narration, postNarration: render.postNarration ?? null } : {}), ...(plan.follow ? { follow: plan.follow } : {}), ...(bleeps ? { bleeps } : {}), ...(slursOn(redaction?.slurs) ? { slurs: redaction.slurs } : {}), ...(from ? { joinFrom: { entry: from.entry, follow: from.plan.follow ?? null, total: from.plan.total, media: from.media.map((x) => [x.m.src, x.t]) } } : {}) })) .digest("hex"); const record = postRecordPath(seg); const had = await readFile(record, "utf8").then((t) => JSON.parse(t), () => null); @@ -549,8 +640,8 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box return seg; } const cardDir = path.join(outDir, "cards", `post-${entry.id}`); - const zoomPlan = postZoomPlan(entry, render, plan.total); - const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, redaction, follow: plan.follow ?? null, total: plan.total }); + const zoomPlan = postZoomPlan(entry, render, plan.total, plan.narration); + const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, redaction, follow: plan.follow ?? null, total: plan.total, joinFrom: from }); // NO HIDDEN TEXT IS EVER NARRATED (operator, 4 Nov): a part whose words are not in view, whole and lit, while it // is said -- or a context post drawn over its context size -- refuses the build (READ_IN_VIEW=warn: a note). // A part read off a linked post's picture is on screen only while the panel shows it (post-thread.mjs panelReadErrors). @@ -584,7 +675,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 }); + 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 }); 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 @@ -210,3 +210,40 @@ test("A LINKED POST's PICTURE READ THROUGH (H): its transcript's parts are pictu assert.deepEqual(panelReadErrors(plan.follow, plan.panel, { id: e.id }), []); assert.match(panelReadErrors(plan.follow, { shows: [] }, { id: e.id }).join(" "), /reads the picture of linked:0/); }); + +import { joinFrameAt, joinKnobs, endMediaOf } from "./post-join.mjs"; +import { followStateAt, isDrawnState } from "./read-follow.mjs"; +import { mediaTimeAt, stepAt } from "./post-item.mjs"; + +test("THE JOIN (operator, 4 Nov: \"a thread-like smooth transition here rather than a cut\"): an item of a run opens on the item before as it ended -- its read after the join's seconds, the card morphing from that item's box, the post it ended on carried in drawn as it was", () => { + const root = said("1", "You all have low testosterone, if I go an entire week I become bestial.", 10); + const ryobi = ref("2", "Ryobi_404", "Three days is enough to make me feel like a completely different person.", 11); + const reply = narrate(base({ id: "p-2", post: "subj-x/2", date: at(12), parents: [ryobi, ref("1", "subject", root.text, 10)] }), [[ryobi.text], [base().text]]); + const tl = [root, reply]; + const ctx = planContext(tl, 1, { postNarration: { lead: 0.25 } }); + assert.deepEqual(ctx.join, { seconds: 0.6 }); + assert.equal(planContext(tl, 0).join, null, "the first of a run cuts in"); + const plain = postItemPlan(reply, { postNarration: { lead: 0.25 } }, { ...ctx, join: null }); + const plan = postItemPlan(reply, { postNarration: { lead: 0.25 } }, ctx); + assert.equal(plan.narration.at, 0.85, "the read starts after the join"); + assert.ok(Math.abs(plan.total - plain.total - 0.6) < 0.01, "the item a join longer"); + assert.equal(plan.follow.join.seconds, 0.6); + assert.equal(followStateAt(plan.follow, null, 0.3).join, 0.5); + assert.equal(followStateAt(plan.follow, null, 0.7).join, undefined); + assert.equal(isDrawnState({ op: {}, offset: 0, join: 0 }), false); + // The carried post is drawn as his post was (head and words), marked as the join's anchor. + const html = postCardHtml(reply, { width: 1600, height: 900, follow: true, thread: plan.follow.thread, join: { A: { x: 10, y: 10, width: 800, height: 500 }, size: 40 } }); + assert.match(html, /class="tile tpost tcarry" data-thread-tile="parent:1" data-thread-mode="carry" data-post-parent="1" data-join-anchor="">/); + assert.match(html, /data-join="\{/); + // The frame: at 0 the item before's box and its card; at 1 its own; the content cross-fades. + const g = { A: { x: 0, y: 100, width: 800, height: 400 }, B: { x: 400, y: 0, width: 1200, height: 900 }, slotA: { x: 900, y: 0, width: 900, height: 900 }, slotB: null }; + const f0 = joinFrameAt(g, 0); + assert.deepEqual([f0.R, f0.from.op, f0.own.op, f0.slotFrom], [g.A, 1, 0, 1]); + const f1 = joinFrameAt(g, 1); + assert.deepEqual([f1.R, f1.from.op, f1.own.op, f1.own.s, f1.slotFrom], [g.B, 0, 1, 1, 0]); + assert.equal(joinKnobs({ join: false }).on, false); + assert.equal(joinKnobs({}, { posts: { join: { seconds: 1 } } }).seconds, 1); + // What the item before ended on: a video held on its last frame, sought a little before its end. + const vplan = { total: 10, steps: [{ kind: "video", at: 0, seconds: 9.6, srcFrom: 0, srcTo: 9.6, items: [{ i: 0, src: "v.mp4", kind: "video", seconds: 9.6 }] }] }; + assert.deepEqual(endMediaOf(vplan, { stepAt, mediaTimeAt }).map((x) => [x.m.src, x.t]), [["v.mp4", 9.48]]); +}); diff --git a/umtool/report-to-video/read-follow.mjs b/umtool/report-to-video/read-follow.mjs @@ -336,9 +336,9 @@ const wordsIn = (t) => scriptWordsOf(t).length; * run left on screen. A conversation scene WINS the card: with one, the media * scene is not drawn (it keeps only the attachment, sceneEntry). * - * @param {{ hold?: number | null, narration?: Record<string, any> | null, prev?: Record<string, any> | null, scene?: Record<string, any> | null, mediaScene?: Record<string, any> | null }} [o] + * @param {{ hold?: number | null, narration?: Record<string, any> | null, prev?: Record<string, any> | null, scene?: Record<string, any> | null, mediaScene?: Record<string, any> | null, join?: { seconds: number } | null }} [o] */ -export function followSchedule(entry, render = undefined, { hold = null, narration = undefined, prev = null, scene = null, mediaScene = null } = {}) { +export function followSchedule(entry, render = undefined, { hold = null, narration = undefined, prev = null, scene = null, mediaScene = null, join = null } = {}) { const k = followKnobs(entry, render); if (!k.on) return null; const map = followBlocks(entry); @@ -366,7 +366,8 @@ export function followSchedule(entry, render = undefined, { hold = null, narrati for (const sc of cardScopes(entry)) spans.set(sc.scope, sc.ref ? contextReadSeconds(sc.ref) : readSeconds(entry)); const reading = [...spans.values()].reduce((n, v) => n + v, 0); const f = fin(hold) && hold > reading + 1 ? (hold - 1) / reading : 1; - let t = 0; + // THE JOIN (post-join.mjs) comes first: the reading after it. + let t = join && fin(join.seconds) ? join.seconds : 0; for (const sc of cardScopes(entry)) { const mine = parts.map((p, i) => ({ p, i })).filter((x) => x.p.scope === sc.scope); const words = mine.reduce((n, x) => n + Math.max(1, wordsIn(x.p.text)), 0) || 1; @@ -395,7 +396,8 @@ export function followSchedule(entry, render = undefined, { hold = null, narrati const layout = ms ? sceneLayout(base, entry, ms) : base; const own = !layout?.on ? null : base ? threadSchedule(entry, render, { layout, blocks, lead: FOLLOW_PAN.lead }) : sceneSchedule(threadKnobs(entry, render), { layout, blocks, lead: FOLLOW_PAN.lead }); const thread = ms ? sceneRows(own, layout) : own; - return { dim: k.dim, ease: k.ease, readEnd, source: map.source, blocks, ...(thread ? { thread } : {}) }; + // THE JOIN (post-join.mjs): its first seconds morph from the item before as it ended. + return { dim: k.dim, ease: k.ease, readEnd, source: map.source, blocks, ...(thread ? { thread } : {}), ...(join && fin(join.seconds) ? { join: { seconds: join.seconds } } : {}) }; } /** The block being read at item second `s` (its k), or null (before the read's first block, or none). */ @@ -491,7 +493,11 @@ export function threadPath(follow, geo) { const carry = (th.tiles ?? []).find((t) => t.mode === "carry") ?? (th.tiles ?? []).find((t) => t.mode === "scene" && t.wasPost); const g0 = at(0); let off; - if (carry && g0.tiles[carry.scope] && th.scene) { + if (carry && g0.tiles[carry.scope] && geo?.joinAnchor && fin(geo.joinAnchor.y)) { + // THE JOIN (post-join.mjs): the post the item before ended on, framed where that item left it (the anchor + // measured on both pages: its top this far down the window). + off = Math.round((g0.tiles[carry.scope].top - geo.joinAnchor.y) * 100) / 100; + } else if (carry && g0.tiles[carry.scope] && th.scene) { // A MEDIA SCENE (post-media-scene.mjs): framed as the item before ended -- what is on screen (the column down // to the carried message) centred, or its foot a margin above the window's when it runs past. const vis = g0.tiles[carry.scope].bottom; @@ -576,6 +582,12 @@ const ramp = (s, a, d) => (d <= 0 ? (s >= a ? 1 : 0) : easeOf("inOut", (s - a) / * end every block rises back to full. A map of fewer than two read blocks is * never dimmed. `path`: followPath's (null: no pan). */ +/** + * @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 }} + */ export function followStateAt(follow, path, s) { const op = {}; if (!follow) return { op, offset: 0, fadeTop: 0, fadeBottom: 0, current: null }; @@ -598,6 +610,8 @@ export function followStateAt(follow, path, s) { const max = path?.max ?? 0; const edge = 24; const current = read.length ? followBlockAt(follow, s) ?? read[0].k : null; + // THE JOIN (post-join.mjs): its progress while the card morphs from the item before's. + const jp = follow.join && fin(follow.join.seconds) && s < follow.join.seconds - 1e-6 ? { join: Math.round((Math.max(0, s) / follow.join.seconds) * 1000) / 1000 } : {}; 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); @@ -620,6 +634,7 @@ export function followStateAt(follow, path, s) { fadeBottom: path?.H && below > 0.5 ? Math.round(clamp(below / edge, 0, 1) * 100) / 100 : 0, current, tiles, + ...jp, }; } return { @@ -628,11 +643,12 @@ export function followStateAt(follow, path, s) { fadeTop: max >= 1 ? Math.round(clamp(offset / edge, 0, 1) * 100) / 100 : 0, fadeBottom: max >= 1 ? Math.round(clamp((max - offset) / edge, 0, 1) * 100) / 100 : 0, current, + ...jp, }; } /** 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] : [])]); +export const followStateKey = (st) => JSON.stringify([st.op, st.offset, st.fadeTop, st.fadeBottom, ...(st.tiles ? [st.tiles] : []), ...(st.join !== undefined ? [st.join] : [])]); /** * Whether a state draws the card PAGE AS DRAWN (no state applied): nothing @@ -645,6 +661,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)) 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;