Archilyzer · Source

archilyzer

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

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

umtool: a wide attachment (width/height >= render.posts.panel.wide, 2.0) is laid at full width above the card (panel=top|bottom|side, the cut's place); a context post's attachments show in the slot while it is on screen (plan.panel: the build, Play) -- an image-only reply a beat, a root's video held when he carries none, a linked post's tall screenshot scrolled as its transcript is read, guarded (panelReadErrors)

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

Diffstat:
Mumtool/app/api/report/post-item/route.ts | 5+++--
Mumtool/components/projects/PostBench.tsx | 4++--
Mumtool/components/projects/PostBenchPage.tsx | 4++--
Mumtool/components/projects/review/PostItemPlayer.tsx | 42++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/playView.mjs | 6+++---
Mumtool/lib/report/postNarrationCli.mjs | 2+-
Mumtool/lib/report/postThreadCli.mjs | 4++--
Mumtool/report-to-video/post-combo-render.mjs | 4++--
Mumtool/report-to-video/post-item.mjs | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mumtool/report-to-video/post-narration.mjs | 2+-
Mumtool/report-to-video/post-redact.mjs | 4++++
Mumtool/report-to-video/post-render.mjs | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mumtool/report-to-video/post-thread-scenes.test.mjs | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/post-thread.mjs | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/report-to-video/read-follow.mjs | 12++++++++++++
15 files changed, 405 insertions(+), 29 deletions(-)

diff --git a/umtool/app/api/report/post-item/route.ts b/umtool/app/api/report/post-item/route.ts @@ -1,6 +1,6 @@ import { readFile, realpath, stat } from "node:fs/promises"; import path from "node:path"; -import { postCardHtml } from "umtool-report-to-video/post-item"; +import { panelEntry, postCardHtml } from "umtool-report-to-video/post-item"; import { avatarUrls } from "umtool-report-to-video/post-avatars"; import { jobState, startJob } from "@/lib/research/case-editor"; import { withEditNotes } from "@/lib/report/guard"; @@ -191,7 +191,8 @@ export async function GET(request: Request) { ? ((await projectCombos(r.project.dir, found.manifest, { channelsDir: channelsDirFor(r.project.dir, found.manifest) }).catch(() => ({ groups: [] }))).groups as unknown[]) : []; const media = groups.length ? mediaSceneById(tl, found.item.id, groups as never, cutRender) : null; - const item = sceneEntry(found.item, media) as Entry; + // A WIDE attachment at full width above the card (post-item.mjs panelEntry: the cut's rule laid on). + const item = panelEntry(sceneEntry(found.item, media), cutRender) as Entry; // THE THREAD SCENE WINS (post-media-scene.mjs's header): with the conversation's scene (post-conversation.mjs) the // media scene keeps only the attachment (sceneEntry above), never the card. const scene = found.ctx.scene ? null : media; diff --git a/umtool/components/projects/PostBench.tsx b/umtool/components/projects/PostBench.tsx @@ -6,7 +6,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { postBenchHref } from "@/lib/hrefs"; -import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, postItemPlan, readingSeconds, ruleSeconds } from "umtool-report-to-video/post-item"; +import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, postItemPlan, readingSeconds, ruleSeconds, panelEntry } from "umtool-report-to-video/post-item"; import PostItemPlayer, { type PostPlan } from "./review/PostItemPlayer"; import PostFollowPanel from "./PostFollowPanel"; import PostThreadPanel from "./PostThreadPanel"; @@ -119,7 +119,7 @@ export default function PostBench({ : savedScene, [entry, savedScene], ); - const shown = useMemo(() => sceneEntry(entry, scene) as Entry, [entry, scene]); + const shown = useMemo(() => panelEntry(sceneEntry(entry, scene), render) as Entry, [entry, scene, render]); const plan = useMemo(() => (entry === initial ? initialPlan : (postItemPlan(shown, render, { prev: before, scene: conversation, mediaScene: conversation ? null : scene }) as PostPlan)), [entry, shown, initial, initialPlan, render, before, scene, conversation]); const total = plan.total; const [s, setS] = useState(0); diff --git a/umtool/components/projects/PostBenchPage.tsx b/umtool/components/projects/PostBenchPage.tsx @@ -5,7 +5,7 @@ import { channelsDirFor, readManifest } from "@/lib/projects/report.mjs"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { projectHref, playHref } from "@/lib/hrefs"; import { deckGeometry, deckOn, feedGeometry, feedOn } from "umtool-report-to-video/deck"; -import { postItemPlan } from "umtool-report-to-video/post-item"; +import { postItemPlan, panelEntry } from "umtool-report-to-video/post-item"; import { planContext } from "umtool-report-to-video/post-conversation"; import { projectCombos } from "umtool-report-to-video/post-combo-prints"; import { mediaSceneOf, sceneEntry } from "umtool-report-to-video/post-media-scene"; @@ -56,7 +56,7 @@ export default async function PostBenchPage({ project, id, search = {} }: { proj entry={entry} token={await manifestToken(project.dir)} box={{ width: box.width, height: box.height }} - plan={postItemPlan(sceneEntry(entry, scene), render, { ...ctx, mediaScene: ctx.scene ? null : scene }) as unknown as PostPlan} + plan={postItemPlan(panelEntry(sceneEntry(entry, scene), render), render, { ...ctx, mediaScene: ctx.scene ? null : scene }) as unknown as PostPlan} scene={scene} render={render} before={ctx.prev} 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 { 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"; import { blurCqw, blurOf, labelBoxOf, pixelGrid } from "umtool-report-to-video/post-censor"; import { WORD_ZOOM_HIGHLIGHT_ALPHA, findMatch, highlightAt, resolveWordZoom, targetScope, targetTextOf, wordZoomTimes, zoomAt, zoomProgressAt, zoomSpan, zoomWindow } from "umtool-report-to-video/word-zoom"; @@ -95,7 +96,11 @@ export type FollowPlan = { }; }; +/** A context post's attachment over the slot (post-thread.mjs panelSchedule). */ +export type PanelShow = { scope: string; media: Array<Record<string, unknown> & { src: string; kind: string; width?: number; height?: number }>; t0: number; t1: number; scroll?: number[][] }; + export type PostPlan = { + panel?: { fade: number; shows: PanelShow[] }; reading: number; total: number; held: number; @@ -347,6 +352,39 @@ function MediaEl({ ); } +/** The panel's shows over the slot, as the build lays them: each crossfaded, a tall picture read through scrolled. */ +function PanelShows({ project, shows, fade, slot, box, s }: { project: string; shows: PanelShow[]; fade: number; slot: Rect; box: Box; s: number }) { + return ( + <> + {shows.map((sh, i) => { + const op = showOpacityAt(sh as never, s, fade); + if (op <= 0) return null; + const m = sh.media[0]; + const w = m.width ?? 16; + const h = m.height ?? 9; + const scroll = !!sh.scroll && m.kind === "image" && h / w > (slot.height / slot.width) * 1.4; + const fitS = Math.min(slot.width / w, slot.height / h); + const bw = scroll ? Math.min(slot.width, slot.height * 0.8) : w * fitS; + const bh = scroll ? slot.height : h * fitS; + const full = scroll ? (bw * h) / w : bh; + const y = scroll ? -(full - bh) * scrollAt(sh.scroll as never, s) : 0; + const left = slot.x + (slot.width - bw) / 2; + const top = slot.y + (scroll ? 0 : (slot.height - bh) / 2); + return ( + <div key={`${sh.scope}:${i}`} data-post-panel={sh.scope} className="absolute z-10 overflow-hidden" style={{ left: pct(left, box.width), top: pct(top, box.height), width: pct(bw, box.width), height: pct(bh, box.height), opacity: op }}> + {m.kind === "image" ? ( + // eslint-disable-next-line @next/next/no-img-element + <img alt="" src={postFileUrl(project, m.src)} style={{ position: "absolute", left: 0, top: `${(y / bh) * 100}%`, width: "100%", height: scroll ? `${(full / bh) * 100}%` : "100%", display: "block" }} /> + ) : ( + <video src={postFileUrl(project, m.src)} muted loop autoPlay playsInline style={{ width: "100%", height: "100%" }} /> + )} + </div> + ); + })} + </> + ); +} + export default function PostItemPlayer({ project, take = null, entry, plan, box, s, playing, cardKey = null, speed = 1, published = false, uncensored = false, scene = null, }: { @@ -560,6 +598,10 @@ export default function PostItemPlayer({ )} </div> )} + {plan.panel && layout.slot && ( + // THE PANEL (post-thread.mjs panelSchedule): a context post's attachment over the slot while it is on screen. + <PanelShows project={project} shows={plan.panel.shows} fade={plan.panel.fade} slot={layout.slot} box={box} s={s} /> + )} {shown && layout.slot && (layout.mode === "side" || mediaPhase) && ( <> {stepBoxes(shown, layout.slot).map((b: { x: number; y: number; width: number; height: number }, j: number) => ( diff --git a/umtool/lib/report/playView.mjs b/umtool/lib/report/playView.mjs @@ -14,7 +14,7 @@ import { resolveFactcheck } from "umtool-report-to-video/factcheck"; import { channelsDirFor, clipDateKey, readManifest } from "../projects/report.mjs"; import { rejectionOf } from "./rejectReasons.mjs"; import { dateKeyLabel } from "./playCut.mjs"; -import { postDay, postItemPlan } from "umtool-report-to-video/post-item"; +import { panelEntry, postDay, postItemPlan } from "umtool-report-to-video/post-item"; import { planContext } from "umtool-report-to-video/post-conversation"; import { pickWindow, projectCache, windowVersion, windowsFor } from "./serve.mjs"; import { playableTakes, resolveTakeManifest } from "./takeManifest.mjs"; @@ -60,10 +60,10 @@ export function postPlayEntry(e, render = undefined, ctx = null, mediaScene = nu dateLabel: dateKeyLabel(dateKey), date: day || null, quote: words || null, - post: sceneEntry(e, mediaScene), + 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(sceneEntry(e, mediaScene), 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 }), ...(mediaScene ? { postScene: { key: mediaScene.key, n: mediaScene.n, of: mediaScene.of, ids: mediaScene.ids, anchor: mediaScene.anchor.id } } : {}), }; } diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -182,7 +182,7 @@ export function normalizeParts(raw) { seconds: r3(p.seconds), ...(Number.isFinite(Number(p.gapBefore)) ? { gapBefore: r3(p.gapBefore) } : {}), // The text it reads (post-thread.mjs), the voice and the piece the batch read it in. - ...(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d)$/.test(p.role) ? { role: p.role } : {}), + ...(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d|linked:\d)$/.test(p.role) ? { role: p.role } : {}), ...(typeof p.voice === "string" && /^[A-Za-z0-9][A-Za-z0-9_.+-]{0,63}$/.test(p.voice) ? { voice: p.voice } : {}), ...(Number.isInteger(p.piece) && p.piece >= 0 ? { piece: p.piece } : {}), })); diff --git a/umtool/lib/report/postThreadCli.mjs b/umtool/lib/report/postThreadCli.mjs @@ -37,7 +37,7 @@ export class RolesError extends Error { } } -const ROLE_RE = /^(post|quoted|parent:\d|media:\d)$/; +const ROLE_RE = /^(post|quoted|parent:\d|media:\d|linked:\d)$/; /** * A narrated item's read, piece by piece: `{ id, take, pieces: [{ role, parts, source, mode }], errors, threaded }`. @@ -83,7 +83,7 @@ export async function rolesCommand(project, ids, { write = false, set = null, js const n = Number(m[1]); if (!(n >= 1 && n <= t.parts.length)) throw new RolesError(`--set ${pair}: ${e.id}'s take has parts 1-${t.parts.length}`); const role = m[2].trim(); - if (role !== "off" && !ROLE_RE.test(role)) throw new RolesError(`--set ${pair}: a role is post, quoted, parent:<i>, media:<i> (or off: inferred)`); + if (role !== "off" && !ROLE_RE.test(role)) throw new RolesError(`--set ${pair}: a role is post, quoted, parent:<i>, linked:<i>, media:<i> (or off: inferred)`); roles[n - 1] = role === "off" ? null : role; } const take = (Number.isInteger(t.index) ? t.index : e.narration.pick ?? 0); diff --git a/umtool/report-to-video/post-combo-render.mjs b/umtool/report-to-video/post-combo-render.mjs @@ -21,7 +21,7 @@ import { copyFile, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/ import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { COMBO_TIMING, comboBadgeHtml, comboFrame, comboPlace, comboStart, comboTransform } from "./post-combo.mjs"; -import { postItemPlan, postLayout, stepBoxes } from "./post-item.mjs"; +import { panelEntry, postItemPlan, postLayout, stepBoxes } from "./post-item.mjs"; const HERE = path.dirname(/* turbopackIgnore: true */ fileURLToPath(import.meta.url)); const r3 = (v) => Math.round(v * 1000) / 1000; @@ -47,7 +47,7 @@ export function comboPlan(entry, combo, { box, render }) { const at = comboStart(plan, combo.media); if (at === null || at >= plan.total - 0.05) return null; const step = plan.steps.find((s) => s.items.some((m) => m.i === combo.media)); - const layout = postLayout(entry, box); + const layout = postLayout(panelEntry(entry, render), box); if (!layout.slot) return null; const boxes = stepBoxes(step, layout.slot); const mb = boxes[step.items.findIndex((m) => m.i === combo.media)] ?? boxes[0]; diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -36,7 +36,7 @@ import { BAR_CSS, barsHtml, hasMarks, projectRedactOf, redactEntry, redactSceneR 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 { validatePostThread } from "./post-thread.mjs"; +import { panelSchedule, validatePostThread } from "./post-thread.mjs"; import { validatePostScene, validatePostSceneRender } from "./post-media-scene.mjs"; /** The platforms a post item may come from (deck.mjs POST_PLATFORMS). */ @@ -282,7 +282,8 @@ function planOf(entry, render, hold, prev = null, scene = null, mediaScene = nul const media = all.reduce((n, s) => n + s.seconds, 0); const total = hold ?? round3(voiceOnly + media + (all.length ? 0 : k.linger)); const plan = planSteps(all, voiceOnly, total); - return { ...plan, reading: round3(Math.min(voiceOnly, total)), total, ...extra }; + const panel = follow ? panelSchedule(entry, follow, total) : null; + return { ...plan, reading: round3(Math.min(voiceOnly, total)), total, ...extra, ...(panel ? { panel } : {}) }; } const span = sch ? round3(sch.at + sch.seconds + k.tail + k.linger) : readingSeconds(entry); const all = mediaSteps(entry).map((s) => { @@ -308,7 +309,9 @@ function planOf(entry, render, hold, prev = null, scene = null, mediaScene = nul last.loop = true; plan.held = 0; } - return { ...plan, reading: 0, total, ...extra }; + // A CONTEXT POST's attachment (post-thread.mjs panelSchedule): over the slot while it is on screen. + const panel = follow ? panelSchedule(entry, follow, total) : null; + return { ...plan, reading: 0, total, ...extra, ...(panel ? { panel } : {}) }; } /** Steps placed from `at0`, cut at `total` (postItemPlan's walk). */ @@ -579,7 +582,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)); + errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(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)); @@ -679,6 +682,8 @@ export function postLayout(entry, { width, height }) { const k = height / 1080; const pad = Math.round(36 * k); const steps = mediaSteps(entry); + // The slot is laid out for its own attachments, else for a context post's (a parent's picture, post-thread.mjs panel). + const shown = slotMediaOf(entry); const words = cardText(entry); // What the card spends besides the words: its head (avatar, name, date), its counts, the context. const context = Math.min(2, parentsOf(entry).length) * 130 * k + (isObj(entry?.quoted) ? 170 * k : 0) + (entry?.replyingTo || entry?.parentShot ? 40 * k : 0); @@ -688,9 +693,27 @@ export function postLayout(entry, { width, height }) { const box = { x: Math.round((width - cw) / 2), y: pad, width: cw, height: height - 2 * pad }; return { box, fit: fitSize(words, cw - 2 * pad, box.height - 2 * pad - chrome, k) }; }; - if (!steps.length) { + if (!steps.length && !shown.length) { const t = textCard(width - 2 * pad); - return { mode: "text", card: t.box, slot: null, strip: null, size: t.fit.size, fits: t.fit.fits, pad }; + return { mode: "text", card: t.box, slot: null, strip: null, size: t.fit.size, fits: t.fit.fits, pad, panel: null }; + } + // A WIDE attachment (operator, 4 Nov: "for these super wide images a top-bottom layout would be better"): at full + // width above (or below) the card, never a side panel -- `panel`, else the cut's rule (panelEntry). + const panel = panelOf(entry); + if (panel === "top" || panel === "bottom") { + const first = shown[0] ?? {}; + const crop = Array.isArray(first.crop) ? first.crop : null; + const ar = ((first.width ?? 16) * (crop ? crop[2] : 1)) / Math.max(1, (first.height ?? 9) * (crop ? crop[3] : 1)); + const fullW = width - 2 * pad; + const slotH = Math.max(Math.round(120 * k), Math.min(Math.round(fullW / Math.max(0.2, ar)), Math.round(height * POST_PANEL_SHARE))); + const cw = Math.min(fullW, Math.round(1500 * k)); + const cardH = height - 3 * pad - slotH; + const slotY = panel === "top" ? pad : height - pad - slotH; + const cardY = panel === "top" ? pad + slotH + pad : pad; + const card = { x: Math.round((width - cw) / 2), y: cardY, width: cw, height: cardH }; + const slot = { x: pad, y: slotY, width: fullW, height: slotH }; + const fit = fitSize(words, cw - 2 * pad, cardH - 2 * pad - chrome, k); + return { mode: "side", panel, card, slot, strip: null, size: fit.size, fits: fit.fits, pad }; } const cardW = Math.round((width - 3 * pad) * 0.42); const side = fitSize(words, cardW - 2 * pad, height - 4 * pad - chrome, k); @@ -699,13 +722,59 @@ export function postLayout(entry, { width, height }) { if (side.fits || steps.length) { const card = { x: pad, y: pad, width: cardW, height: height - 2 * pad }; const slot = { x: 2 * pad + cardW, y: pad, width: width - 3 * pad - cardW, height: height - 2 * pad }; - return { mode: "side", card, slot, strip: null, size: side.size, fits: side.fits, pad }; + return { mode: "side", panel: "side", card, slot, strip: null, size: side.size, fits: side.fits, pad }; } const t = textCard(width - 2 * pad); const stripH = Math.round(92 * k); const strip = { x: pad, y: pad, width: width - 2 * pad, height: stripH }; const slot = { x: pad, y: pad + stripH + Math.round(pad / 2), width: width - 2 * pad, height: height - 2 * pad - stripH - Math.round(pad / 2) }; - return { mode: "stack", card: t.box, slot, strip, size: t.fit.size, fits: t.fit.fits, pad }; + return { mode: "stack", card: t.box, slot, strip, size: t.fit.size, fits: t.fit.fits, pad, panel: null }; +} + +/** A wide panel's height: at most this share of the box. */ +export const POST_PANEL_SHARE = 0.42; +/** The cut's rule for a wide attachment (`render.posts.panel`): at this width ÷ height or more, laid at full width `place`. */ +export const POST_PANEL_DEFAULTS = Object.freeze({ wide: 2.0, place: "top" }); + +/** What the slot shows over the item: its own attachments, else the context posts' (post-thread.mjs panelSchedule). */ +export function slotMediaOf(entry) { + const own = Array.isArray(entry?.media) ? entry.media.filter(isObj) : []; + if (own.length) return own; + const refs = [...[...parentsOf(entry)].reverse(), ...(isObj(entry?.quoted) ? [entry.quoted] : []), ...linksOf(entry)]; + return refs.flatMap(refMediaOf); +} + +/** + * Where an item's attachments sit: its `panel`, else top/bottom (the cut's `place`) when the first is WIDE (width ÷ + * height ≥ `wide`; its crop counted), else beside the card. `rule`: the cut's (`render.posts.panel`), else the defaults. + */ +export function panelOf(entry, rule = null) { + if (POST_PANELS.includes(entry?.panel)) return entry.panel; + const r = { ...POST_PANEL_DEFAULTS, ...(isObj(rule) ? rule : {}) }; + const m = slotMediaOf(entry)[0]; + if (!m || !fin(m.width) || !fin(m.height) || r.place === "side") return "side"; + const crop = Array.isArray(m.crop) ? m.crop : null; + const ar = (m.width * (crop ? crop[2] : 1)) / Math.max(1, m.height * (crop ? crop[3] : 1)); + return ar >= r.wide ? r.place : "side"; +} + +/** The item with the CUT's wide-attachment rule laid on (`panel` set when the cut's rule differs from the defaults'). */ +export function panelEntry(entry, render) { + const rule = isObj(render?.posts?.panel) ? render.posts.panel : null; + if (!rule || !isObj(entry) || POST_PANELS.includes(entry.panel)) return entry; + const p = panelOf(entry, rule); + return p === panelOf(entry) ? entry : { ...entry, panel: p }; +} + +/** Every reason `render.posts.panel` cannot be built. */ +export function validatePostPanelRender(render) { + const v = render?.posts?.panel; + if (v === undefined) return []; + if (!isObj(v)) return ["render.posts.panel must be { wide?, place? } (where a wide attachment sits)"]; + const errors = Object.keys(v).filter((k) => !(k in POST_PANEL_DEFAULTS)).map((k) => `render.posts.panel.${k} is not a panel knob (wide, place)`); + if (v.wide !== undefined && !(fin(v.wide) && v.wide >= 1.2 && v.wide <= 10)) errors.push("render.posts.panel.wide must be 1.2–10 (width ÷ height from which an attachment is laid at full width)"); + if (v.place !== undefined && !POST_PANELS.includes(v.place)) errors.push(`render.posts.panel.place must be one of ${POST_PANELS.join(", ")}`); + return errors; } /** diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs @@ -644,7 +644,7 @@ export function validatePostNarration(e) { if (!(fin(p.start) && p.start >= 0)) errors.push(`${pw}.start must be where it starts in the take, seconds`); if (!(fin(p.seconds) && p.seconds > 0)) errors.push(`${pw}.seconds must be its length`); if (p.text !== undefined && typeof p.text !== "string") errors.push(`${pw}.text must be the words it reads`); - if (p.role !== undefined && !(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d)$/.test(p.role))) errors.push(`${pw}.role must be post, quoted, parent:<i> or media:<i> (the text it reads)`); + if (p.role !== undefined && !(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d|linked:\d)$/.test(p.role))) errors.push(`${pw}.role must be post, quoted, parent:<i>, linked:<i> or media:<i> (the text it reads)`); }); } }); diff --git a/umtool/report-to-video/post-redact.mjs b/umtool/report-to-video/post-redact.mjs @@ -267,6 +267,7 @@ export function redactEntry(entry, red) { for (const k of ["author", "handle"]) if (k in out) out[k] = mark(out[k], all); if ("text" in out) out.text = mark(out.text, re, spansFor(entry, red, scope, index)); if ("paraphrase" in out) out.paraphrase = mark(out.paraphrase, re); + if ("transcript" in out) out.transcript = mark(out.transcript, re); return out; }; const out = { ...entry }; @@ -276,6 +277,8 @@ export function redactEntry(entry, red) { if (isObj(entry.repostedBy)) out.repostedBy = { ...entry.repostedBy, author: mark(entry.repostedBy.author, all), handle: mark(entry.repostedBy.handle, all) }; if (Array.isArray(entry.parents)) out.parents = entry.parents.map((p, i) => ref(p, "parent", i)); if (isObj(entry.quoted)) out.quoted = ref(entry.quoted, "quoted"); + // A post its words link to (post-thread.mjs): marked by the project's terms, as a quoted post is. + if (Array.isArray(entry.links)) out.links = entry.links.map((p) => ref(p, "quoted")); return slurEntry(out, red?.slurs); } @@ -323,6 +326,7 @@ export function slurEntry(entry, slurs) { if (isObj(entry.repostedBy)) out.repostedBy = { ...entry.repostedBy, author: m(entry.repostedBy.author) }; if (Array.isArray(entry.parents)) out.parents = entry.parents.map(ref); if (isObj(entry.quoted)) out.quoted = ref(entry.quoted); + if (Array.isArray(entry.links)) out.links = entry.links.map((r) => (isObj(r) && "transcript" in r ? { ...ref(r), transcript: m(r.transcript) } : ref(r))); return out; } diff --git a/umtool/report-to-video/post-render.mjs b/umtool/report-to-video/post-render.mjs @@ -18,13 +18,14 @@ 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, postCardHtml, postItemPlan, postLayout, stepBoxes } from "./post-item.mjs"; +import { POST_PICTURE_XFADE, POST_PUSH, fxRedactionErrors, panelEntry, postCardHtml, postItemPlan, postLayout, 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"; 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 { WORD_ZOOM_DEFAULTS, findMatch, overlappingZooms, resolveWordZoom, targetScope, targetTextOf, wordZoomTimes, zoomSpan, zoomTarget, zoompanExprs } from "./word-zoom.mjs"; const r3 = (v) => Math.round(v * 1000) / 1000; @@ -59,6 +60,19 @@ export function stepCaptions(step, cues) { .filter((c) => c.to - c.from > 0.05); } +/** A scroll's keyframes (post-thread.mjs panelSchedule) as an ffmpeg expression of t: 0..1, linear between them. */ +export function scrollExpr(keys) { + if (!Array.isArray(keys) || !keys.length) return "0"; + let e = num(keys[keys.length - 1][1]); + for (let i = keys.length - 1; i >= 1; i -= 1) { + const [t1, f1] = keys[i]; + const [t0, f0] = keys[i - 1]; + const seg = t1 > t0 ? `${num(f0)}+(${num(f1 - f0)})*(t-${num(t0)})/${num(t1 - t0)}` : num(f1); + e = `if(lt(t,${num(t1)}),${seg},${e})`; + } + return `if(lt(t,${num(keys[0][0])}),${num(keys[0][1])},${e})`; +} + /** * The encode, pure. `cards`: the read-phase PNG and (a stack layout) the * media-phase one; `files[i]`: attachment i's absolute path; `captions`: @@ -68,7 +82,7 @@ export function stepCaptions(step, cues) { * * @returns {string[]} */ -export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null }) { +export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [] }) { const fps = render.fps ?? 30; const T = plan.total; const inputs = []; @@ -180,6 +194,44 @@ export function postSegmentArgs({ entry, box, plan, layout, cards, files, render } }); }); + // THE PANEL (post-thread.mjs panelSchedule): a context post's attachment over the slot while it is on screen -- + // crossfaded in and out over the item's own; a tall picture read through scrolled top to foot (its crop's y on t). + if (plan.panel && layout.slot) { + const fade = plan.panel.fade ?? 0.3; + plan.panel.shows.forEach((show, pi) => { + const items = show.media.map((m, j) => ({ ...m, i: j })); + const boxes = stepBoxes({ items }, layout.slot); + const until = Math.min(T, show.t1 + fade); + items.forEach((m, j) => { + const file = panelFiles[pi]?.[j]; + if (!file) return; + const label = `pn${pi}_${j}`; + const raw = blurOn(m) ? `${label}r` : label; + const fades = `format=rgba${show.t0 > 0.001 ? `,fade=t=in:st=${num(show.t0)}:d=${num(fade)}:alpha=1` : ""}${until < T - 0.001 ? `,fade=t=out:st=${num(show.t1)}:d=${num(fade)}:alpha=1` : ""}`; + let b = boxes[j]; + if (show.scroll && j === 0 && m.kind === "image" && (m.height ?? 0) / Math.max(1, m.width ?? 1) > (layout.slot.height / layout.slot.width) * 1.4) { + // Scrolled: the picture at a readable width, a window of the slot's height panned down it as it is read. + const w = Math.max(2, Math.floor(Math.min(layout.slot.width, layout.slot.height * 0.8) / 2) * 2); + const fullH = Math.max(2, Math.floor((w * (m.height ?? 1)) / Math.max(1, m.width ?? 1) / 2) * 2); + const h = Math.max(2, Math.floor(layout.slot.height / 2) * 2); + const range = Math.max(0, fullH - h); + b = { x: Math.round(layout.slot.x + (layout.slot.width - w) / 2), y: layout.slot.y, width: w, height: h }; + const k = add(["-loop", "1", "-framerate", String(fps), "-t", num(until), "-i", file]); + parts.push(`[${k}:v]scale=${w}:${fullH},setsar=1,fps=${fps},crop=${w}:${h}:0:'${num(range)}*(${scrollExpr(show.scroll)})',${fades}[${raw}]`); + } else if (m.kind === "image") { + const crop = Array.isArray(m.crop) ? `crop=iw*${num(m.crop[2])}:ih*${num(m.crop[3])}:iw*${num(m.crop[0])}:ih*${num(m.crop[1])},` : ""; + const k = add(["-loop", "1", "-framerate", String(fps), "-t", num(until), "-i", file]); + parts.push(`[${k}:v]${crop}scale=${b.width}:${b.height},setsar=1,fps=${fps},${fades}[${raw}]`); + } else { + // A video or a GIF of a context post: looped, silent, from its first frame as it comes up. + const k = add(["-stream_loop", "-1", "-t", num(Math.max(0.1, until - show.t0)), "-i", file]); + parts.push(`[${k}:v]scale=${b.width}:${b.height},setsar=1,fps=${fps},setpts=PTS-STARTPTS,tpad=start_duration=${num(show.t0)}:start_mode=clone,${fades}[${raw}]`); + } + if (raw !== label) parts.push(...blurFilters(raw, label, m, b)); + lay(label, b.x, b.y, show.t0, until); + }); + }); + } // 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)); @@ -456,6 +508,8 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box entry = censorEntry(entry, redaction); // In a media scene (post-media-scene.mjs) the shared attachment is the anchor's -- its markup laid on too. entry = sceneEntry(entry, mediaScene, { censor: (e) => censorEntry(e, redaction) }); + // A WIDE attachment at full width above (or below) the card: the cut's rule laid on (post-item.mjs panelEntry). + entry = panelEntry(entry, render); // A word zoom on a redacted word is refused in the build's words (the corpus's terms and the markup included). const fxRed = fxRedactionErrors(entry, redaction); if (fxRed.length) throw new Error(fxRed.join("; ")); @@ -468,6 +522,11 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box 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})`); } + // A context post's attachments (post-thread.mjs panelSchedule): files of the project, as the item's own are. + const panelFiles = (plan.panel?.shows ?? []).map((sh) => sh.media.map((m) => path.resolve(manifestDir, m.src))); + for (const [i, f] of panelFiles.flat().entries()) { + if (!(await stat(f).catch(() => null))) throw new Error(`${entry.id}: a context post's attachment is not on disk: ${f} (${i})`); + } const wordFiles = (entry.media ?? []).map((m) => (typeof m.words === "string" ? path.resolve(manifestDir, m.words) : null)); // Its narration's picked take (post-narration.mjs): a file of the project, levelled by its measured loudness. const take = isNarrated(entry) ? pickedTake(entry) : null; @@ -475,7 +534,7 @@ 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, ...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(), ...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}:-`; })); @@ -494,6 +553,9 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, redaction, follow: plan.follow ?? null, total: plan.total }); // 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). + const panelErr = panelReadErrors(plan.follow, plan.panel, { id: entry.id }); + if (panelErr.length) cards.inView = [...(cards.inView ?? []), ...panelErr]; if (cards.inView?.length) { const msg = `${entry.id}: the read is not on screen while it is said (read-follow.mjs readInViewErrors):\n ${cards.inView.join("\n ")}`; if (process.env.READ_IN_VIEW === "warn") emit("note", { message: `warning: ${msg}` }); @@ -522,7 +584,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 }); + 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 }); 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 @@ -139,3 +139,74 @@ test("A MANUAL THREAD is gathered in DATE order (timeline threads --write): the const { ids } = gatheredOrder(tl); assert.deepEqual(ids, ["p-72", "p-73", "p-78", "p-79", "p-80", "p-74", "p-75"]); }); + +import { panelEntry, panelOf, postLayout, validatePostItems } from "./post-item.mjs"; + +test("A WIDE ATTACHMENT (operator, 4 Nov: \"a top-bottom layout would be better\"): 692×141 is laid at full width above the card; the cut's rule (wide, place) and the item's panel override", () => { + const wide = base({ media: [{ src: "posts-media/a/1.png", kind: "image", width: 692, height: 141 }] }); + const box = { width: 1920, height: 1080 }; + assert.equal(panelOf(wide), "top"); + const L = postLayout(wide, box); + assert.equal(L.mode, "side"); + assert.equal(L.panel, "top"); + assert.ok(L.slot.width > 1800 && L.slot.y < L.card.y, "the picture across the top, the card under it"); + assert.ok(L.slot.height <= Math.round(1080 * 0.42) && L.card.y + L.card.height <= 1080); + // A picture that is not wide stays beside the card; `panel` overrides either way. + assert.equal(panelOf(base({ media: [{ src: "a.png", kind: "image", width: 800, height: 600 }] })), "side"); + assert.equal(postLayout({ ...wide, panel: "side" }, box).panel, "side"); + assert.equal(postLayout({ ...wide, panel: "bottom" }, box).slot.y > 500, true); + // The cut's rule: a stricter threshold keeps it beside; place bottom. + assert.equal(postLayout(panelEntry(wide, { posts: { panel: { wide: 6 } } }), box).panel, "side"); + assert.equal(postLayout(panelEntry(wide, { posts: { panel: { place: "bottom" } } }), box).panel, "bottom"); + assert.match(validatePostItems({ render: { posts: { panel: { wide: 0.5 } } }, timeline: [] }).join(" "), /panel\.wide must be/); + // The card is drawn in its box under the picture. + const html = postCardHtml(wide, { width: 1920, height: 1080 }); + assert.match(html, new RegExp(`data-post-slot="" style="left:${L.slot.x}px;top:${L.slot.y}px;width:${L.slot.width}px`)); +}); + +import { panelReadErrors, panelSchedule, scrollAt, showOpacityAt } from "./post-thread.mjs"; +import { postSegmentArgs, scrollExpr } from "./post-render.mjs"; + +test("THE PANEL: a context post's picture over the slot while it is read; an image-only reply shown at least a beat; with no attachment of his own the last one held; a slot laid out for it", () => { + const pic = { src: "posts-media/b/1/baby.mp4", kind: "video", width: 720, height: 1280, seconds: 9 }; + const root = ref("1", "subject", "a video of my baby girl, pretty sure she's trying to eat me", 17, { media: [pic] }); + const e = narrate(base({ parents: [ref("2", "panda", "There is an acceptable level of crazy cat behaviour and this is it.", 18), root] }), [[root.text], ["There is an acceptable level of crazy cat behaviour and this is it."], [base().text]]); + const L = postLayout(e, { width: 1920, height: 1080 }); + assert.equal(L.mode, "side", "his reply has no attachment: the slot is for the root's video"); + const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); + assert.equal(plan.panel.shows.length, 1); + const sh = plan.panel.shows[0]; + assert.equal(sh.scope, "parent:1"); + assert.equal(sh.t0, 0); + assert.equal(sh.t1, plan.total, "held to the end: he carries none"); + assert.equal(showOpacityAt(sh, 0.1), 1); + // Over his own attachment: from its piece until his words come. + const own = { ...e, media: [{ src: "posts-media/b/2/own.jpg", kind: "image", width: 800, height: 800 }] }; + const p2 = postItemPlan(own, { postNarration: { lead: 0.4 } }); + const post = p2.follow.blocks.find((b) => b.scope === "post"); + assert.ok(Math.abs(p2.panel.shows[0].t1 - (post.start - 0.4)) < 0.01); + // The build lays it over the slot, crossfaded out. + const argv = postSegmentArgs({ entry: own, box: { width: 1920, height: 1080 }, plan: p2, layout: postLayout(own, { width: 1920, height: 1080 }), cards: { read: "r.png" }, files: ["own.jpg"], render: { fps: 30 }, outPath: "o.mp4", panelFiles: [["baby.mp4"]] }); + const fc = argv[argv.indexOf("-filter_complex") + 1]; + assert.match(fc, /fade=t=out:st=[\d.]+:d=0\.3:alpha=1\[pn0_0\]/); + assert.ok(argv.includes("baby.mp4")); +}); + +test("A LINKED POST's PICTURE READ THROUGH (H): its transcript's parts are picture blocks; the tall screenshot scrolls top to foot as they are read; the guard names a part read while the panel is elsewhere", () => { + const dm = "first line of the messages he sent\n\nsecond line of the messages he sent\n\nthird and last line of them"; + const link = { id: "2116805001309823299", handle: "Infinity_Virus_", author: "Infinity", date: at(8), text: "Ya try to be civil and they go insane", transcript: dm, media: [{ src: "posts-media/iv/1.jpg", kind: "image", width: 600, height: 4029 }] }; + const saber = ref("5", "SaberXVeritas", "this you? https://x.com/Infinity_Virus_/status/2116805001309823299", 9); + const e = narrate(base({ parents: [saber], links: [link] }), [["this you?", "parent:0"], ["Ya try to be civil and they go insane", "linked:0"], [dm, "linked:0"], [base().text, "post"]], { roles: true }); + assert.deepEqual(validatePostItem(e), []); + const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); + const pics = plan.follow.blocks.filter((b) => b.pic); + assert.equal(pics.length, 3); + const sh = plan.panel.shows.find((x) => x.scope === "linked:0"); + assert.ok(sh.scroll.length >= 4); + assert.equal(scrollAt(sh.scroll, sh.t0), 0); + assert.equal(scrollAt(sh.scroll, plan.total), 1); + assert.ok(scrollAt(sh.scroll, pics[1].start + 0.5) > 0.2 && scrollAt(sh.scroll, pics[1].start + 0.5) < 0.8); + assert.match(scrollExpr(sh.scroll), /^if\(lt\(t,/); + 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/); +}); diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs @@ -48,7 +48,7 @@ // PURE and dependency-free (but its siblings): the plan, the build, Play, the // bench, the writers and the lint all read the same rules from here. -import { POST_PARENTS_MAX, cardText, contextText, linksOf, parentsOf, refShown } from "./post-item.mjs"; +import { POST_PARENTS_MAX, cardText, contextText, linksOf, parentsOf, refMediaOf, refShown } from "./post-item.mjs"; import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, scriptParts, spokenUrls } from "./post-narration.mjs"; import { normWord, scriptWordsOf } from "./word-zoom.mjs"; import { followKnobs } from "./read-follow.mjs"; @@ -156,7 +156,7 @@ export function readTexts(entry) { add("quoted", [contextText(q), str(q.text), spoken(contextText(q)), spoken(q.text)]); } // A post its words link to (`links[]`): read in place when the take reads it. - linksOf(entry).forEach((l, i) => add(`linked:${i}`, [contextText(l), str(l.text), spoken(contextText(l)), spoken(l.text)])); + linksOf(entry).forEach((l, i) => add(`linked:${i}`, [contextText(l), str(l.text), spoken(contextText(l)), spoken(l.text), str(l.transcript), spoken(l.transcript)])); add("post", [cardText(entry), str(entry?.narration?.script), spoken(cardText(entry))]); return out; } @@ -760,3 +760,118 @@ export function validateThreadReads(manifest) { }); return errors; } + +// --------------------------------------------------------------------------- +// THE PANEL: a context post's attachment in the slot while it is on screen +// (operator, 4 Nov: "a parent or ancestor that carries media shows it while +// that piece is on screen"; furrimessiah's image-only reply, his "video of my +// baby girl"; Infinity_Virus_'s screenshot scrolled as its words are read). +// --------------------------------------------------------------------------- + +/** The panel's crossfade (s) and the least a context post's picture that is not read stays up (s). */ +export const PANEL = Object.freeze({ fade: 0.3, minUnread: 1.2 }); + +/** The context post a tile draws (a parent, the quoted post, a linked post), or null. */ +export function refOfScope(entry, scope) { + const m = /^(parent|linked):(\d)$/.exec(String(scope)); + if (m) return (m[1] === "parent" ? parentsOf(entry) : linksOf(entry))[Number(m[2])] ?? null; + return scope === "quoted" && isObj(entry?.quoted) ? entry.quoted : null; +} + +/** + * THE PANEL SCHEDULE, pure: `{ fade, shows: [{ scope, media, t0, t1, scroll? }] }` -- each context post with + * attachments shown over the slot from when its piece is read (its first block's start, less the pan's lead; one + * not read: from when its tile is on screen, at least PANEL.minUnread) until the next one's (his own words, when he + * carries attachments: they are under it, playing on their plan); the last one held to the end when he carries + * none. A tall picture whose words are read (a linked post's `transcript`) SCROLLS: `scroll` the keyframes + * `[[t, f]]` (f: 0 the picture's top in view, 1 its foot) through its parts, by their words. Null: none. + * + * @param {Record<string, any>} entry + * @param {Record<string, any> | null} follow the plan's (followSchedule) + * @param {number} total + */ +export function panelSchedule(entry, follow, total, { lead = 0.4 } = {}) { + const th = follow?.thread; + if (!th) return null; + const own = Array.isArray(entry?.media) && entry.media.length > 0; + const startOf = (scope) => { + const ts = (follow.blocks ?? []).filter((b) => b.scope === scope && fin(b.start)).map((b) => b.start); + return ts.length ? Math.min(...ts) : null; + }; + const cand = []; + for (const row of th.tiles ?? []) { + const media = refMediaOf(refOfScope(entry, row.scope)); + if (!media.length) continue; + const s = startOf(row.scope); + const on = row.read && s !== null ? s - lead : row.from?.[1] > 0 ? 0 : row.t0; + cand.push({ scope: row.scope, media, on: r3(Math.max(0, on)), read: !!row.read && s !== null }); + } + if (!cand.length) return null; + const postAt = startOf("post"); + if (own) cand.push({ scope: "own", on: r3(Math.max(0, (postAt ?? 0) - lead)), read: true }); + cand.sort((a, b) => a.on - b.on); + const shows = []; + cand.forEach((c, i) => { + if (c.scope === "own") return; + const next = cand[i + 1]; + const end = next ? next.on : total; + const t1 = r3(Math.min(total, Math.max(end, c.read ? end : c.on + PANEL.minUnread))); + if (t1 <= c.on + 0.05) return; + const show = { scope: c.scope, media: c.media, t0: c.on, t1 }; + // A picture read through (its transcript's parts, read-follow.mjs pic blocks): scrolled top to foot as it is read. + const pics = (follow.blocks ?? []).filter((b) => b.scope === c.scope && b.pic && fin(b.start)).sort((a, b) => a.start - b.start); + if (pics.length) { + const words = pics.reduce((n, b) => n + (b.words ?? 1), 0) || 1; + const keys = [[c.on, 0]]; + let w = 0; + for (const b of pics) { + keys.push([r3(b.start), r3(w / words)]); + w += b.words ?? 1; + keys.push([r3(Math.max(b.start + 0.1, fin(b.end) ? b.end : b.start + 1)), r3(w / words)]); + } + show.scroll = keys; + } + shows.push(show); + }); + return shows.length ? { fade: PANEL.fade, shows } : null; +} + +/** A scroll's place at item second `s` (0: the top in view, 1: the foot), linear between keyframes. */ +export function scrollAt(keys, s) { + if (!Array.isArray(keys) || !keys.length) return 0; + if (s <= keys[0][0]) return keys[0][1]; + for (let i = 1; i < keys.length; i += 1) { + const [t1, f1] = keys[i]; + const [t0, f0] = keys[i - 1]; + if (s <= t1) return t1 > t0 ? f0 + ((f1 - f0) * (s - t0)) / (t1 - t0) : f1; + } + return keys[keys.length - 1][1]; +} + +/** + * A panel show's strength at item second `s` (its crossfade in and out). + * @param {{ t0: number, t1: number }} show + * @param {number} s + * @param {number} [fade] + */ +export function showOpacityAt(show, s, fade = 0.3) { + if (s < show.t0 || s > show.t1 + fade) return 0; + const up = show.t0 <= 0.001 ? 1 : Math.min(1, (s - show.t0) / fade); + const down = s <= show.t1 ? 1 : 1 - (s - show.t1) / fade; + return Math.round(Math.max(0, Math.min(up, down)) * 1000) / 1000; +} + +/** + * THE PANEL's GUARD, pure: a part read off a linked post's PICTURE is on screen only while the panel shows that + * picture -- every such part whose read (less the settle) falls outside its show is named. + */ +export function panelReadErrors(follow, panel, { id = "?", settle = 0.35 } = {}) { + const errors = []; + for (const b of (follow?.blocks ?? []).filter((x) => x.pic && fin(x.start))) { + const show = (panel?.shows ?? []).find((sh) => sh.scope === b.scope); + const a = b.start + settle; + const z = Math.max(a, (fin(b.end) ? b.end : b.start) - 0.4); + if (!show || show.t0 > a + 1e-6 || show.t1 < z - 1e-6) errors.push(`${id}: part ${b.part + 1} reads the picture of ${b.scope}, which the panel does not show while it is said (${r3(b.start)}–${r3(fin(b.end) ? b.end : b.start)} s)`); + } + return errors; +} diff --git a/umtool/report-to-video/read-follow.mjs b/umtool/report-to-video/read-follow.mjs @@ -234,6 +234,18 @@ export function followBlocks(entry) { } const keys = partKeys(p.text); if (!keys.length) return; + // A part read off a LINKED post's picture (its `transcript`, post-thread.mjs: the picture scrolls as it is read): + // a block with no card words, its words counted for the scroll. + if (typeof p.scope === "string" && p.scope.startsWith("linked:")) { + const l = linksOf(entry)[Number(p.scope.slice(7))]; + const onCard = new Set(partKeys(contextText(l))); + const inPic = new Set(partKeys(l?.transcript ?? "")); + const share = (set) => keys.filter((x) => set.has(x)).length / keys.length; + if (inPic.size && share(inPic) > share(onCard)) { + media.push({ scope: p.scope, from: null, to: null, part: pi, pic: true, words: keys.length }); + return; + } + } // Which of the card's texts it reads: its own scope (the card's parts), else the one most of its words are in. let target = p.scope ? byScope.get(p.scope) : null; if (!target) {