// A POST ITEM's THREAD READ (umtool/docs/report-video.md, "Thread reads"; // operator, 3-4 Nov 2026: "when narrating a reply parent you're just narrating // hidden text. Rework the thread system so you're never narrating hidden // text" -- "If it's a big reply that we're reading, show the parent in full // then transition in the reply as the parent shrinks and goes dim"; and, // earlier, "start with the first post in the chain, then reveal the rest of // the thread as we read through, pushing older posts up top"). // // THE INVARIANT: every narrated part is on screen, legible and highlighted // while it is said. A post item's read is assembled in PIECES -- the post it // answers, the post it quotes, his words (and, by hand, words read off an // attachment) -- and each piece has a ROLE, the text it reads: // // "parent:" parents[i] (nearest first) "quoted" the post it quotes // "post" his own words "media:" an attachment's words (a screenshot) // // A part's role is its own (`parts[k].role`, stored by the import and by // `umtool posts roles --write`), else INFERRED: the parts grouped into their // pieces (`para` div 100), each piece matched by its words to the text it // reads (the context post's words as written and as a voice says them, // draftScript; his card text and his script), in the read's order. // // THE CARD, threaded: a narrated, following post item with a context post // drawn becomes a column of TILES (oldest first: the parents, then his post, // the quoted post inside it) panned by read-follow. A tile's MODE is what is // on screen for it (render.postNarration.thread / entry.thread): // // full the post in full, at the words' size, the frame's focus while it is read // excerpt as full, but only the paragraphs the read reads ("…" for the rest) // context small and dim the whole item -- never read // carry (a parent the read skips because it is the item just before in // the cut) it opens as that item ended -- in full -- and shrinks // and dims as the reply comes in, instead of a cold cut // hidden not drawn at all -- never read // auto (the default) full when the read reads it; else carry when it // is the item before (carry: auto), else context // // THE MOTION: a read tile is shown in full while it is read; when the next // piece starts, it SHRINKS (`shrink`) and DIMS (`dim`) over `seconds`, and the // tile being read next is revealed (`reveal`) under it -- older up top -- the // column panned (`pan` s, eased) so the new piece sits under a strip of what it // answers. A quoted post is never shrunk: it dims once it has been read. // // THE GUARD (threadReadErrors; the build's lint): a part whose role is a tile // that is hidden or context, a part no text on the card reads, or a threaded // read with read-follow off is refused, with the fix. // // 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, readEditOf, refMediaOf, refShown } from "./post-item.mjs"; import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, postNarrationKnobs, scriptParts, spokenUrls } from "./post-narration.mjs"; import { normWord, scriptWordsOf } from "./word-zoom.mjs"; import { followKnobs } from "./read-follow.mjs"; import { planContext } from "./post-conversation.mjs"; import { branchMapOf, mapKnobs, mapTimes } from "./post-branch-map.mjs"; import { isPictureOnly, pictureBeatSeconds } from "./post-picture.mjs"; import { isScreenScope, parseScreenRole, readScreens, screenLineProblem, screenLineSaid, screenLineSpoken, screenOrder, screenPieces, screenReadLines, screenRole, screenScope, screenWarnings, screensOf as screensOfEntry, shapeSpans, tileOfRole } from "./post-screens.mjs"; /** What a context tile may be. */ export const THREAD_MODES = Object.freeze(["auto", "full", "excerpt", "context", "carry", "hidden"]); export const THREAD_DEFAULTS = Object.freeze({ parent: "auto", quoted: "auto", carry: "auto", reveal: true, shrink: 0.62, dim: 0.5, seconds: 0.7, pan: 0.7 }); export const THREAD_LIMITS = Object.freeze({ shrink: [0.3, 1], dim: [0.15, 1], seconds: [0, 3], pan: [0.1, 3] }); /** The share of a piece's words the text it reads must hold (else it is matched to no text). */ const ROLE_MIN = 0.5; /** The share of the window kept for the post a new piece answers (its foot above the new piece). */ export const THREAD_CONTEXT_ROOM = 0.3; /** `thread.group` (one item's): a MANUAL THREAD -- consecutive items of one group play as one scene (post-conversation.mjs). */ export const THREAD_GROUP_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,47}$/; /** `thread.map`: the branch map (post-branch-map.mjs) -- on, off, or its style. */ export const THREAD_MAP_VALUES = Object.freeze([true, false, "map", "label", "both"]); const KEYS = new Set([...Object.keys(THREAD_DEFAULTS), "group", "map"]); const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const fin = (v) => typeof v === "number" && Number.isFinite(v); const str = (v) => (typeof v === "string" ? v : ""); const r3 = (v) => Math.round(v * 1000) / 1000; const ROLE_RE = /^(post|quoted|parent:\d|media:\d|linked:\d|screen:[a-z0-9][a-z0-9-]{0,23}:\d{1,2})$/; // --------------------------------------------------------------------------- // The knobs. // --------------------------------------------------------------------------- const modeOk = (v, carryOk) => typeof v === "string" && THREAD_MODES.includes(v) && (carryOk || v !== "carry"); /** One thread knob's errors (`where`: its path in the manifest). */ export function threadKnobErrors(v, where) { if (v === undefined || v === null) return []; if (!isObj(v)) return [`${where} must be { parent?, quoted?, carry?, reveal?, shrink?, dim?, seconds?, pan?, group? }`]; const errors = []; for (const k of Object.keys(v)) if (!KEYS.has(k)) errors.push(`${where}.${k} is not a thread knob (${[...KEYS].join(", ")})`); if (v.parent !== undefined) { const list = Array.isArray(v.parent) ? v.parent : [v.parent]; if (!list.length || list.length > POST_PARENTS_MAX || !list.every((m) => modeOk(m, true))) errors.push(`${where}.parent must be one of ${THREAD_MODES.join(", ")} (or a list of them, nearest parent first)`); } if (v.quoted !== undefined && !modeOk(v.quoted, false)) errors.push(`${where}.quoted must be one of ${THREAD_MODES.filter((m) => m !== "carry").join(", ")}`); if (v.carry !== undefined && !(v.carry === "auto" || typeof v.carry === "boolean")) errors.push(`${where}.carry must be auto, true or false`); if (v.reveal !== undefined && typeof v.reveal !== "boolean") errors.push(`${where}.reveal must be true or false`); if (v.map !== undefined && !THREAD_MAP_VALUES.includes(v.map)) errors.push(`${where}.map must be true, false, "map", "label" or "both" (the branch map)`); if (v.group !== undefined && !(typeof v.group === "string" && THREAD_GROUP_RE.test(v.group))) errors.push(`${where}.group must be a name (letters, digits, . _ -): the manual thread the item plays in`); for (const k of ["shrink", "dim", "seconds", "pan"]) { if (v[k] !== undefined && !(fin(v[k]) && v[k] >= THREAD_LIMITS[k][0] && v[k] <= THREAD_LIMITS[k][1])) { errors.push(`${where}.${k} must be ${THREAD_LIMITS[k][0]}–${THREAD_LIMITS[k][1]}${k === "shrink" ? " (a context post's size)" : k === "dim" ? " (a context post's opacity)" : " seconds"}`); } } return errors; } /** A post item's `thread` errors (validatePostItem). */ export const validatePostThread = (e) => threadKnobErrors(e?.thread, `timeline ${e?.id ?? "?"}.thread`); const pick = (o) => (isObj(o) ? Object.fromEntries(Object.entries(o).filter(([k, v]) => KEYS.has(k) && v !== undefined && v !== null)) : {}); /** * One post's thread knobs: its own, else the cut's (`render.postNarration.thread`), else the defaults. * @param {Record | null | undefined} entry * @param {Record} [render] * @returns {{ parent: string | string[], quoted: string, carry: "auto"|boolean, reveal: boolean, shrink: number, dim: number, seconds: number, pan: number }} */ export function threadKnobs(entry, render = undefined) { const r = isObj(render?.postNarration) ? render.postNarration.thread : undefined; const { group: _g, ...cut } = pick(r); void _g; return /** @type {any} */ ({ ...THREAD_DEFAULTS, ...cut, ...pick(entry?.thread) }); } /** An item's manual thread (`thread.group`), or null. */ export const groupOf = (e) => (typeof e?.thread?.group === "string" && THREAD_GROUP_RE.test(e.thread.group) ? e.thread.group : null); /** Parent `i`'s mode as the knobs set it (before `auto` is resolved). */ const parentKnob = (k, i) => (Array.isArray(k.parent) ? k.parent[i] ?? k.parent[k.parent.length - 1] : k.parent) ?? "auto"; // --------------------------------------------------------------------------- // THE ROLES: which text each part of the read reads. // --------------------------------------------------------------------------- const keyOf = (w) => normWord(w).replace(/'/g, ""); /** A text's words as matching sees them: normalized, a "this/that" split at its slash, the voice's "slash" dropped. */ const keysOf = (t) => scriptWordsOf(t).flatMap((w) => w.split("/")).map(keyOf).filter((k) => k && k !== "slash"); const pairsOf = (keys) => keys.slice(1).map((k, i) => `${keys[i]} ${k}`); /** * The texts a read may read, in the order the read reads them: the parents * (nearest first), the quoted post, his words -- each as its words and its * word PAIRS, over every form it may be read in (as written, its paraphrase, * as a voice says it). */ export function readTexts(entry) { const out = []; const spoken = (t) => (str(t).trim() ? draftScript(t).script : ""); const add = (role, forms, pic = false) => { const lists = forms.filter((t) => str(t).trim()).map(keysOf); if (!lists.some((l) => l.length)) return; out.push({ role, keys: new Set(lists.flat()), pairs: new Set(lists.flatMap(pairsOf)), ...(pic ? { pic: true } : {}) }); }; parentsOf(entry).forEach((p, i) => add(`parent:${i}`, [contextText(p), str(p.text), spoken(contextText(p)), spoken(p.text)])); if (isObj(entry?.quoted)) { const q = entry.quoted; 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)]); // The words read off its picture: matched by their word pairs only (a two-word part is never a picture's). add(`linked:${i}`, [str(l.transcript), spoken(l.transcript)], true); }); add("post", [cardText(entry), str(entry?.narration?.script), spoken(cardText(entry))]); // ITS SCREENS' read lines (post-screens.mjs): each its own text (a take's stored roles name them; a long line is matched). for (const sc of readScreens(entry)) for (const r of screenReadLines(sc)) add(screenRole(sc.id, r.n), [screenLineSaid(sc, r.n), screenLineSpoken(sc, r.n)]); return out; } /** The share of a piece's words a text holds: by word pairs, in order (one word a pair: by words). */ function shareOf(keys, text) { if (text.pic && keys.length < 3) return 0; if (keys.length >= 3) { const pairs = pairsOf(keys); return pairs.filter((p) => text.pairs.has(p)).length / pairs.length; } return keys.filter((w) => text.keys.has(w)).length / keys.length; } /** The read's order of the roles by KIND (a parent, oldest first, before the quoted post before his words). */ const kindOrder = (role) => (role.startsWith("parent:") ? 2 - Number(role.slice(7)) / 10 : role === "quoted" ? 3 : role.startsWith("linked:") ? 3.5 : role === "post" ? 4 : 5); /** * THE READ's ORDER of the roles (operator, 4 Nov: "include the whole thread chronologically"): by the DATE of * the post each reads when every text has one -- the chain oldest first, a quoted post at its own date, his words * at theirs -- else by kind (kindOrder). An attachment's words come last. Ranks from 1. */ export function roleOrderOf(entry) { const base = roleOrderByDate(entry); // A SCREEN's line (post-screens.mjs) after every other text, in the screens' order and its lines'. return readScreens(entry).length ? (role) => screenOrder(entry, role) ?? base(role) : base; } function roleOrderByDate(entry) { const dates = new Map(); parentsOf(entry).forEach((p, i) => dates.set(`parent:${i}`, Date.parse(str(p?.date)))); if (isObj(entry?.quoted)) dates.set("quoted", Date.parse(str(entry.quoted.date))); linksOf(entry).forEach((l, i) => dates.set(`linked:${i}`, Date.parse(str(l?.date)))); dates.set("post", Date.parse(str(entry?.date))); if (![...dates.values()].every(Number.isFinite)) return kindOrder; const ranked = [...dates.keys()].sort((a, b) => dates.get(a) - dates.get(b) || kindOrder(a) - kindOrder(b)); const rank = new Map(ranked.map((r, i) => [r, i + 1])); return (role) => rank.get(role) ?? ranked.length + 1; } /** * THE ROLES of the picked take's parts, pure: `[{ role, source }]` (one a * part; `role` null: no text on the card reads it; `source` "stored" or * "inferred"). Empty when the item has no take with parts. * * @param {Record} entry * @param {Record | null} [take] a take other than the picked one */ export function partRoles(entry, take = undefined) { const t = take === undefined ? pickedTake(entry) : take; let parts = Array.isArray(t?.parts) ? t.parts : []; // A take read in one go (no parts): its script's parts, as read-follow times them -- each paragraph a piece. if (!parts.length && t) { const script = str(t.script).trim() ? t.script : str(entry?.narration?.script); parts = scriptParts(script).map((p) => ({ text: p.text, para: p.para * 100 })); } if (!parts.length) return []; // HIS WORDS EDITED FOR READING (post-item.mjs readEditOf: the take's stamp; ruling 3): a read of them that stores // no roles is his post's, part by part -- never inferred from the edited words as a parent, the quoted post or a picture. if (t && readEditOf(entry, t) === "reading" && !parts.some((p) => typeof p?.role === "string")) return parts.map(() => ({ role: "post", source: "inferred" })); const texts = readTexts(entry); const orderOf = roleOrderOf(entry); const images = (Array.isArray(entry?.media) ? entry.media : []).map((m, i) => ({ m, i })).filter((x) => x.m?.kind === "image"); // The pieces: consecutive parts of one `para` div 100 (a take of one piece: all of it). const pieceOf = (p) => (Number.isInteger(p?.para) ? Math.floor(p.para / 100) : 0); const groups = []; parts.forEach((p, k) => { const g = groups[groups.length - 1]; if (g && g.piece === pieceOf(p)) g.parts.push(k); else groups.push({ piece: pieceOf(p), parts: [k] }); }); const out = parts.map((p) => (typeof p?.role === "string" && ROLE_RE.test(p.role) ? { role: p.role, source: "stored" } : null)); let floor = 0; for (const g of groups) { const stored = g.parts.map((k) => out[k]).filter(Boolean); if (stored.length === g.parts.length) { floor = Math.max(floor, orderOf(stored[stored.length - 1].role)); continue; } const keys = keysOf(g.parts.map((k) => str(parts[k].text)).join(" ")); let role = null; if (keys.length) { const scored = texts.map((x) => ({ role: x.role, share: shareOf(keys, x) })); const best = Math.max(...scored.map((x) => x.share)); if (best >= ROLE_MIN) { // Among the near-best, the one the read's order expects (never back up the thread). // A new piece reads another text than the one before it: among the near-best, the next one along. const near = scored.filter((x) => x.share >= best - 0.05); const ahead = near.filter((x) => orderOf(x.role) > floor); const fwd = near.filter((x) => orderOf(x.role) >= floor); role = (ahead.length && floor > 0 ? ahead : fwd.length ? fwd : near).sort((a, b) => b.share - a.share || orderOf(a.role) - orderOf(b.role))[0].role; } } // Words no text holds, on an item with a picture: read off the picture (a screenshot). if (!role && images.length) role = `media:${images[0].i}`; if (role) floor = Math.max(floor, orderOf(role)); for (const k of g.parts) out[k] ??= { role, source: "inferred" }; } return out; } /** * The read's PIECES in order: `[{ role, parts: [k…] }]` -- runs of parts of one role. * @param {Record} entry * @param {Array<{ role: string | null, source?: string }>} [roles] */ export function readPieces(entry, roles = partRoles(entry)) { const out = []; roles.forEach((r, k) => { const last = out[out.length - 1]; if (last && last.role === r.role) last.parts.push(k); else out.push({ role: r.role, parts: [k] }); }); return out; } // --------------------------------------------------------------------------- // THE TILES: what each context post is on screen. // --------------------------------------------------------------------------- /** The archive id of an item's post (`/` → ``). */ const postIdOf = (e) => String(e?.post ?? "").split("/")[1] ?? ""; /** The id of the post an item's card shows (a repost shows its original). */ export const shownIdOf = (e) => str(e?.originalId) || postIdOf(e); /** * THE SCREENS A THREADED CARD DRAWS, pure: each screen whose lines the screen reads and the picked take reads a line of, * in the screens' order (threadLayout's tiles; the public payload's screens: one rule). `roles`: partRoles' (none: not * narrated -- no screen is drawn). */ export function drawnScreens(entry, roles = isNarrated(entry) ? partRoles(entry) : []) { return readScreens(entry).filter((sc) => roles.some((r) => r?.role && parseScreenRole(r.role)?.id === sc.id)); } /** * THE THREAD LAYOUT, pure: `{ on, tiles: [{ scope, mode, read }], roles, * quotedAt }` -- the tiles top to bottom (the parents oldest first, a quoted * post read first, "post", a quoted post inside it), each with its resolved * mode (never "auto") and whether the read reads it. `on`: the card is * threaded (a narrated item with a context tile drawn; read-follow on is the * caller's to require). `prev`: the item before it in the cut (a parent that * is that item is carried). `scene` (post-conversation.mjs planContext): the * posts the run had on screen as the item before ended -- each a tile * `conv:` (mode "scene", never read, `ref` what it draws), kept on top as * context when it is an ancestor of this item, else collapsed away; one this * item draws itself is its own tile. Every tile in the tree's order. * * @param {Record} entry * @param {Record} [render] * @param {{ prev?: Record | null, scene?: Record | null }} [o] */ export function threadLayout(entry, render = undefined, { prev = null, scene = null } = {}) { const k = threadKnobs(entry, render); const roles = isNarrated(entry) ? partRoles(entry) : []; const read = new Set(roles.map((r) => r.role).filter(Boolean)); const prevId = prev ? shownIdOf(prev) : ""; const tiles = []; const parents = parentsOf(entry); for (let i = parents.length - 1; i >= 0; i -= 1) { const scope = `parent:${i}`; // An image-only reply (no words, a picture) is drawn too: its head and its attachment in the slot. if (!refShown(parents[i])) continue; let mode = parentKnob(k, i); const isRead = read.has(scope); // A PICTURE-ONLY post (post-picture.mjs): its picture drawn in its tile, in full -- its own beat, not context. const pic = isPictureOnly(parents[i]); if (mode === "auto") { const carry = k.carry === true || (k.carry === "auto" && !!prevId && String(parents[i].id ?? "") === prevId); mode = isRead ? "full" : carry ? "carry" : pic ? "full" : "context"; } if (mode === "carry" && isRead) mode = "full"; tiles.push({ scope, mode, read: isRead, ...(pic ? { pic: true } : {}) }); } // THE QUOTED POST (operator, 4 Nov: the quote read first while it sat under his words -- "the card opens // scrolled down"): read BEFORE his words, it is its own tile ABOVE his post, read in full and lit, then // shrunk and dimmed like a parent as his words come in; read after them (or not at all), inside his post. const postAt = roles.findIndex((r) => r.role === "post"); const quotedFirst = roles.findIndex((r) => r.role === "quoted"); const quotedAt = quotedFirst >= 0 && (postAt < 0 || quotedFirst < postAt) ? "above" : "inside"; const post = { scope: "post", mode: "full", read: read.has("post"), ...(isPictureOnly(entry, { text: cardText(entry) }) ? { pic: true } : {}) }; const qpic = isObj(entry?.quoted) && isPictureOnly(entry.quoted); if (isObj(entry?.quoted) && (contextText(entry.quoted).trim() || qpic)) { const m = k.quoted === "auto" ? (read.has("quoted") ? "full" : qpic ? "full" : "context") : k.quoted; // A picture-only quoted post the read does not read has its beat before the read: above his post, like a parent. const above = (quotedAt === "above" || (qpic && !read.has("quoted"))) && m !== "hidden" && m !== "context"; const q = { scope: "quoted", mode: m, read: read.has("quoted"), ...(above ? { above: true } : {}), ...(qpic ? { pic: true } : {}) }; if (q.above) tiles.push(q, post); else tiles.push(post, q); } else tiles.push(post); // THE POSTS ITS WORDS LINK TO (`links[]`, a link visit): each a tile after the one whose words link it (else after his). linksOf(entry).forEach((l, i) => { if (!refShown(l)) return; const scope = `linked:${i}`; const isRead = read.has(scope); const from = linkedFrom(entry, l); const at = tiles.findIndex((t) => t.scope === (from ?? "post")); tiles.splice(at < 0 ? tiles.length : at + 1, 0, { scope, mode: isRead ? "full" : "context", read: isRead, ...(from ? { linkedFrom: from } : {}) }); }); // THE READ's ORDER (operator, 4 Nov: "read the whole thread chronologically"): the tiles in the order the take // reads them -- a quote read before the post it answers sits above it -- one not read where it stood before the next. orderByRead(tiles, roles); // ITS SCREENS (post-screens.mjs): each screen the take reads a line of, a tile after his post's, in the screens' order. for (const sc of drawnScreens(entry, roles)) tiles.push({ scope: screenScope(sc.id), mode: "full", read: true, screen: true }); const quotedAtOut = tiles.some((t) => t.above) ? "above" : "inside"; // THE SCENE (post-conversation.mjs): what the run had on screen, in the tree's order with this item's own tiles. const scened = withRelations(entry, isNarrated(entry) ? sceneTiles(entry, tiles, scene, k) : tiles, { group: !!scene?.group || !!groupOf(entry) }); const on = isNarrated(entry) && scened.some((t) => t.scope !== "post" && t.mode !== "hidden"); // THE BRANCH MAP (post-branch-map.mjs): where the scene goes when it changes branch. const map = on && scene && prev ? layoutMap(entry, scened, roles, { prevId: prevId, group: !!scene?.group || !!groupOf(entry), knobs: mapKnobs(entry, render) }) : null; return { on, tiles: scened, roles, quotedAt: quotedAtOut, ...(map ? { map } : {}) }; } /** * THE BEATS of a threaded card's PICTURE-ONLY context posts (post-picture.mjs), pure: `[{ scope, t0, t1 }]` -- each * picture-only parent or quoted post drawn in full that the read does not read, standing before the read's first * piece, lit and shown alone for its beat (pictureBeatSeconds) from item second `at0` (the join's end), one after * another; the read starts after the last (postItemPlan moves its start: the take is never re-made). One standing * between two read pieces has no beat (drawn in its card, it gives way with the piece after it). Empty: none. * * @param {Record} entry * @param {Record | undefined} render * @param {{ on: boolean, tiles: Array> } | null} layout threadLayout's * @param {number} [at0] */ export function pictureBeats(entry, render, layout, at0 = 0) { if (!layout?.on) return []; const tiles = layout.tiles ?? []; const firstRead = tiles.findIndex((t) => t.read); const out = []; let t = fin(at0) ? at0 : 0; tiles.forEach((tile, i) => { if (!tile.pic || tile.read || tile.mode !== "full" || tile.scope === "post" || (firstRead >= 0 && i > firstRead)) return; const secs = pictureBeatSeconds(refMediaOf(refOfScope(entry, tile.scope)), render); if (!(secs > 0)) return; out.push({ scope: tile.scope, t0: r3(t), t1: r3(t + secs) }); t += secs; }); return out; } /** The id a tile of `entry` draws (a parent's, his post's, a quoted or linked post's; null: none known). */ export function tileIdOf(entry, t) { if (t.scope === "post") return shownIdOf(entry) || null; if (t.scope === "quoted") return str(entry?.quoted?.id) || statusIdOf(entry?.quoted?.url) || null; const l = /^linked:(\d)$/.exec(t.scope); if (l) return str(linksOf(entry)[Number(l[1])]?.id) || null; const m = /^parent:(\d)$/.exec(t.scope); return m ? str(parentsOf(entry)[Number(m[1])]?.id) || null : null; } /** The status id an x.com / twitter.com link names (null: none). */ export function statusIdOf(url) { const m = /(?:x|twitter)\.com\/[^/\s]+\/status(?:es)?\/(\d{5,25})/i.exec(str(url)); return m ? m[1] : null; } /** The tile whose words link to post `ref` (a status link naming its id): "post", "parent:", "quoted" -- null: none. */ export function linkedFrom(entry, ref) { const id = str(ref?.id) || statusIdOf(ref?.url); if (!id) return null; const holds = (t) => [...str(t).matchAll(/https?:\/\/\S+/g)].some((m) => statusIdOf(m[0]) === id); if (holds(cardText(entry))) return "post"; const ps = parentsOf(entry); for (let i = 0; i < ps.length; i += 1) if (holds(ps[i]?.text)) return `parent:${i}`; if (isObj(entry?.quoted) && holds(entry.quoted.text)) return "quoted"; return null; } /** * The tiles in place in THE READ's ORDER: each read tile by its first part; a tile not read (and a quoted post * inside his) keeps its place before the next tile it stood before. Stable when the read is in the drawn order. */ function orderByRead(tiles, roles) { const first = new Map(); roles.forEach((r, k) => { if (r?.role && !first.has(r.role)) first.set(r.role, k); }); const own = (t) => t.scope !== "quoted" || !!t.above; const keyed = tiles.map((t, i) => ({ t, i, k: own(t) && first.has(t.scope) ? first.get(t.scope) : null })); // A tile not read takes the key of the next read tile after it (it stands before it), less a little. for (let i = keyed.length - 1, next = Infinity; i >= 0; i -= 1) { if (keyed[i].k !== null) next = keyed[i].k; else keyed[i].k = next - 0.5 + i / 1000; } // A quoted post inside his post rides with it. const post = keyed.find((x) => x.t.scope === "post"); for (const x of keyed) if (x.t.scope === "quoted" && !x.t.above && post) x.k = post.k + 0.0001; keyed.sort((a, b) => a.k - b.k || a.i - b.i); tiles.splice(0, tiles.length, ...keyed.map((x) => x.t)); } /** * The layout's tiles with the SCENE's (planContext's `scene.tiles`: `{ id, * ref, from: "full"|"small", action: "keep"|"collapse" }`) merged in, in the * tree's order (`scene.rank`, id → place): a scene post this item draws * itself is left to its own tile. */ function sceneTiles(entry, tiles, scene, k) { const list = Array.isArray(scene?.tiles) ? scene.tiles : []; if (!list.length) return tiles; const own = new Set(tiles.filter((t) => t.mode !== "hidden").map((t) => tileIdOf(entry, t)).filter(Boolean)); // A post of his own card the run already had on screen grows from where it was (small), never pops in from nothing. const was = new Map(list.filter((t) => isObj(t) && str(t.id)).map((t) => [str(t.id), t.from === "full" ? [1, 1] : [k.shrink, k.dim]])); for (const t of tiles) { const id = tileIdOf(entry, t); if (id && was.has(id) && t.mode !== "hidden") t.fromScene = was.get(id); } const extra = list .filter((t) => isObj(t) && str(t.id) && isObj(t.ref) && !own.has(str(t.id))) .map((t) => ({ scope: `conv:${t.id}`, mode: "scene", read: false, action: t.action === "keep" ? "keep" : "collapse", from: t.from === "full" ? [1, 1] : [k.shrink, k.dim], ...(t.from === "full" ? { wasPost: true } : {}), ref: t.ref, })); if (!extra.length) return tiles; const rank = isObj(scene.rank) ? scene.rank : {}; const rankOf = (id) => (id && fin(rank[id]) ? rank[id] : null); // His own tiles keep their order; one with no place in the tree sits just after the one before it. const mine = tiles.map((t) => ({ t, r: rankOf(tileIdOf(entry, t)) })); let last = null; mine.forEach((x, i) => { if (x.r === null) { const next = mine.slice(i + 1).find((y) => y.r !== null); x.r = last !== null ? last + 0.001 : next ? next.r - 0.5 + i * 0.001 : -1 + i * 0.001; } // A quoted post rides with his post (above it or inside it). if (x.t.scope === "quoted") x.r = (mine.find((y) => y.t.scope === "post")?.r ?? x.r) + (x.t.above ? -0.0005 : 0.0005); last = x.r; }); const theirs = extra.map((t, i) => ({ t, r: rankOf(t.scope.slice(5)) ?? 1e9 + i })); return [...mine, ...theirs].map((x, i) => ({ ...x, i })).sort((a, b) => a.r - b.r || a.i - b.i).map((x) => x.t); } /** * Each tile's RELATION to what it answers (operator, 4 Nov: "subtly indicate the original relations"): `rel` -- * `{ to: | null, above: boolean, id }` -- when the post it answers is NOT the tile drawn just above it * (a branch: "replying to @X"), and, in a manual thread (`group`), on every reply ("replying to the post above"). * From the real parents: his post answers parents[0], parents[i] answers parents[i + 1], a scene post its own. */ function withRelations(entry, tiles, { group = false } = {}) { const parents = parentsOf(entry); const answers = (t) => { if (t.scope === "post") return parents[0] ? { id: str(parents[0].id), handle: str(parents[0].handle) } : str(entry?.replyingTo) ? { id: "", handle: str(entry.replyingTo) } : null; const m = /^parent:(\d)$/.exec(t.scope); if (m) { const p = parents[Number(m[1]) + 1]; return p ? { id: str(p.id), handle: str(p.handle) } : null; } if (t.mode === "scene" && isObj(t.ref?.replyTo)) return { id: str(t.ref.replyTo.id), handle: str(t.ref.replyTo.handle) }; return null; }; const idOf = (t) => (t.mode === "scene" ? t.scope.slice(5) : tileIdOf(entry, t)); const drawn = tiles.filter((t) => t.mode !== "hidden" && (t.scope !== "quoted" || t.above)); return tiles.map((t) => { if (t.mode === "hidden" || (t.scope === "quoted" && !t.above) || t.scope.startsWith("linked:")) return t; const a = answers(t); if (!a) return t; const at = drawn.indexOf(t); const above = at > 0 ? idOf(drawn[at - 1]) : null; const isAbove = !!a.id && above === a.id; if (isAbove && !group) return t; return { ...t, rel: { to: a.handle || null, above: isAbove, id: a.id || null } }; }); } /** The branch map of a laid-out card (post-branch-map.mjs branchMapOf), from its tiles' ids, parents and authors. */ function layoutMap(entry, tiles, roles, { prevId, group, knobs }) { if (!knobs.on) return null; const parents = parentsOf(entry); const node = (t) => { if (t.mode === "hidden") return null; if (t.mode === "scene") return { scope: t.scope, id: t.scope.slice(5), parent: str(t.ref?.replyTo?.id), handle: str(t.ref?.handle) }; if (t.scope === "post") return { scope: t.scope, id: shownIdOf(entry), parent: str(parents[0]?.id), handle: str(entry?.handle) }; const m = /^parent:(\d)$/.exec(t.scope); if (m) return { scope: t.scope, id: str(parents[Number(m[1])]?.id), parent: str(parents[Number(m[1]) + 1]?.id), handle: str(parents[Number(m[1])]?.handle) }; return null; }; const nodes = tiles.map(node).filter((n) => n && n.id); // The post read first is where the scene goes (his own when he is read first). const first = roles.find((r) => r.role && (r.role === "post" || r.role.startsWith("parent:")))?.role ?? "post"; const now = nodes.find((n) => n.scope === first)?.id ?? shownIdOf(entry); return branchMapOf(nodes, { prevId, nowId: now, subject: str(entry?.handle), style: knobs.style, group }); } /** * ONE SCREEN PART's errors (part k of the picked take, its role a screen line's), pure: the line the screen does not * read (left out, redacted, `read: "none"`, gone); the line CHANGED since the read (its words or its speaker: * screenLineChanged -- judged on the entry it is given: the build judges the cut AS WRITTEN, validateScreenReads); and * what the part SAYS holding a shape (an e-mail, a number: a recording that says what the card masks). `changed`: the * roles already said changed (one sentence a line). */ export function screenPartErrors(entry, k, roles = partRoles(entry), changed = new Set()) { const r = roles[k]; const p = r?.role ? parseScreenRole(r.role) : null; if (!p) return []; const w = `timeline ${entry?.id ?? "?"}`; const id = entry?.id ?? ""; const n = k + 1; const out = []; const why = screenLineProblem(entry, r.role); if (why) out.push(`${w}: its take's part ${n} reads ${why} -- read it (umtool posts screen

${id} set read=…) or re-make the read without it (umtool posts screen

${id} read)`); // The words it says are the line's AS IT IS NOW (operator's rule: nothing said the card does not show): a line edited, // removed or moved since the read leaves the old audio under new lit text -- refused, never played. else if (!changed.has(r.role) && screenLineChanged(entry, r.role, roles)) { changed.add(r.role); out.push(`${w}: its take's part ${n}: line ${p.n} of screen ${p.id} changed since the read (its words or its speaker are not what the take says) -- make the read again (umtool posts screen

${id} read)`); } const part = (pickedTake(entry)?.parts ?? [])[k]; const kinds = [...new Set(shapeSpans(str(part?.text)).map((x) => x.kind))]; if (kinds.length) out.push(`${w}: its take's part ${n} (line ${p.n} of screen ${p.id}) says ${kinds.map((x) => (x === "email" ? "an e-mail address" : x === "order" ? "an order or reference number" : "a long number or a phone number")).join(" and ")} -- the card masks it, and a read never says it: re-record the line without it, or make the read again (umtool posts screen

${id} read)`); return out; } /** * THE SCREENS' READS over a cut, pure (the build's ENFORCED lint, build-video.mjs enforcedLint, gives it the cut AS * WRITTEN -- never the anonymised copy it draws): every screen part's errors (screenPartErrors) of every narrated post * item that carries screens. Empty for a cut with none. */ export function validateScreenReads(manifest) { const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; return tl.flatMap((e) => itemReadRefusals(e)); } /** * ONE POST ITEM's READ, REFUSED, pure -- what the build's enforced lint refuses about it (validateScreenReads is this * over a cut), judged on the item AS WRITTEN: every screen part's errors (screenPartErrors: a line changed since the * read, not read, gone, a shape said) and every part that SAYS WHAT ITS SCREENS HIDE (readSaysHiddenErrors). Empty * for an item with no screens, or not narrated. */ export function itemReadRefusals(e) { if (e?.type !== "post" || !Array.isArray(e.screens) || !isNarrated(e)) return []; const out = []; const roles = partRoles(e); const changed = new Set(); roles.forEach((r, k) => { if (r?.role && parseScreenRole(r.role)) out.push(...screenPartErrors(e, k, roles, changed)); }); out.push(...readSaysHiddenErrors(e)); return out; } /** A shape's KEY, to know it said elsewhere: an e-mail lower case; a number its digits (fullwidth ones too). */ const digitsOf = (t) => str(t).replace(/\p{Nd}/gu, (d) => String(Number.parseInt(d.normalize("NFKC"), 10))).replace(/[^0-9]/g, ""); const shapeKey = (text, sp) => (sp.kind === "email" ? text.slice(sp.start, sp.end).toLowerCase() : digitsOf(text.slice(sp.start, sp.end))); /** Every run of digits a text says (its separators between them dropped): `["4419283", "5552014477"]`. */ const digitRunsOf = (t) => [...str(t).matchAll(/\p{Nd}(?:[\s\-‐‑–—·./()]{0,3}\p{Nd})*/gu)].map((m) => digitsOf(m[0])); /** * WHAT ITS SCREENS HIDE, SAID ANYWHERE IN ITS READ, pure (review round 1, M2: a picture's words read by the post's own * part and again by its screen): every part of the picked take -- his words, a context post, a screen line, a take with * no parts as its words -- that says a SHAPE one of the item's screens masks (an e-mail, a number of four digits or * more: post-screens.mjs shapeSpans, its digits however they are joined) or the words of a line marked `redact` (three * or more of them in a row). Names the part and the screen's line, never the value. None without screens. */ export function readSaysHiddenErrors(e) { const screens = screensOfEntry(e); const t = pickedTake(e); if (!screens.length || !t) return []; const id = e?.id ?? ""; const masked = []; const redacted = []; for (const sc of screens) { sc.lines.forEach((l, n) => { if (!l || typeof l !== "object") return; const text = str(l.text); if (l.redact === true) { const w = sayKeys(text); if (w.length >= 3) redacted.push({ screen: sc.id, n, w }); return; } for (const sp of shapeSpans(text)) { const key = shapeKey(text, sp); if (sp.kind === "email" ? key.length >= 3 : key.length >= 4) masked.push({ screen: sc.id, n, kind: sp.kind, key }); } }); } if (!masked.length && !redacted.length) return []; const parts = Array.isArray(t.parts) && t.parts.length ? t.parts.map((p) => str(p?.text)) : [str(t.said) || str(t.script)]; const out = []; parts.forEach((said, k) => { const where = Array.isArray(t.parts) && t.parts.length ? `its take's part ${k + 1}` : "its picked take"; const runs = new Set(digitRunsOf(said)); const low = said.toLowerCase(); const hit = masked.find((m) => (m.kind === "email" ? low.includes(m.key) : runs.has(m.key) || [...runs].some((r) => r.length >= m.key.length && r.includes(m.key)))); if (hit) out.push(`timeline ${e?.id ?? "?"}: ${where} says ${hit.kind === "email" ? "an e-mail address" : "a number"} that line ${hit.n} of screen ${hit.screen} masks -- the card never shows it and no read may say it: make the read again (umtool posts screen

${id} read)`); const w = sayKeys(said); const red = redacted.find((r) => w.some((_, i) => r.w.every((x, j) => w[i + j] === x))); if (red) out.push(`timeline ${e?.id ?? "?"}: ${where} says the words of line ${red.n} of screen ${red.screen}, which is redacted -- make the read again (umtool posts screen

${id} read)`); }); return out; } /** * WHAT A SPOKEN EDIT WOULD SAY THAT ITS SCREENS HIDE, pure (lane line-rerun): readSaysHiddenErrors over `text` as the * read's words -- the script saved for reading, a screen line's "said as" -- so a spoken edit the build would refuse is * refused when it is WRITTEN, and never reaches a take (whose refusal would drop the read from the preview). */ // It judges the text as WRITTEN, not as spokenRead would say it (the lexicon, the redaction): refusing more is the safe // side -- a word the lexicon would say another way is still refused if written as a masked shape (review 1: no change). export function spokenSaysHiddenErrors(e, text, where = "the read") { if (!str(text).trim() || !screensOfEntry(e).length) return []; const probe = { ...e, narration: { pick: 0, takes: [{ file: "narration/probe.wav", seconds: 1, script: str(text) }] } }; return readSaysHiddenErrors(probe).map((m) => m.replace("its picked take", where).replace(/: make the read again \(umtool posts screen

[^)]*\)$/, ": say it another way")); } // --------------------------------------------------------------------------- // WHAT A PREVIEW PLAYS (Play, Present, the post bench's player, the card page): never a read the build refuses. // --------------------------------------------------------------------------- /** What a preview says of a read it does not play. */ export const READ_REFUSED_REASON = "the read is older than its screen, or says what the screen hides -- it is not played: make the read again (umtool posts screen

read)"; /** * AN ITEM's PLAYABLE READ, pure: the picked take a preview may play -- none when the item says its read is refused * (`readRefused`, playableEntry's) or the build would refuse it (itemReadRefusals). EVERY player, preview and payload * reads the take through this (the source test pins it: lib/report/postScreensReview3.test.mjs, e). */ export function playableTake(e) { if (!e || e.readRefused) return null; if (itemReadRefusals(e).length) return null; return pickedTake(e); } /** * THE ITEM AS A PREVIEW MAY PLAY IT, pure (review round 1, M1): the item itself when the build would play its read; * else the item WITHOUT its read -- no narration, no take, no part in it (it plays silent, as an item not narrated) -- * with `readRefused: { reason, errors }` saying why. Judged on the item as written (itemReadRefusals); every player and * payload goes through it: playView (Play, Present -- the public payload too), the card page, the post bench's player. */ export function playableEntry(e) { return playableAsWritten(e, e); } /** * THE VERDICT ON THE ITEM AS WRITTEN, APPLIED TO THE ITEM AS DRAWN, pure (re-check b: one verdict everywhere): `drawn` * (the anonymised, censored copy a page draws) as it may play -- itself, or without its read (`readRefused`) when * `written` (the same item before those passes: what the build's enforced lint judges) has a read the build refuses. */ export function playableAsWritten(written, drawn) { const errors = itemReadRefusals(written); if (!errors.length) return drawn; const { narration: _n, ...rest } = drawn; return { ...rest, readRefused: { reason: READ_REFUSED_REASON, errors } }; } const sayKeys = (t) => str(t).toLowerCase().split(/\s+/).map((x) => x.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, "")).filter(Boolean); const normText = (t) => str(t).replace(/\s+/g, " ").trim(); /** * Whether the picked take's parts for a screen line (`role`) say something else than the line says NOW: the line each * part was made from (`parts[k].line`, stored by the thread read) is compared exactly with the line's words as a read * would write them (draftScript of screenLineSaid); a part with none stored, by its own words, word for word. */ export function screenLineChanged(entry, role, roles = partRoles(entry)) { const p = parseScreenRole(role); const sc = p ? screensOfEntry(entry).find((x) => x.id === p.id) : null; if (!sc) return false; const said = screenLineSaid(sc, p.n); const t = pickedTake(entry); const parts = Array.isArray(t?.parts) && t.parts.length ? t.parts : scriptParts(str(t?.script).trim() ? t.script : str(entry?.narration?.script)).map((q) => ({ text: q.text })); const mine = roles.map((r, k) => (r?.role === role ? parts[k] : null)).filter(Boolean); if (!mine.length) return false; // Its speaker (`speaker`, stored beside the line): a line given to someone else is not the line the voice read. const spk = mine.find((x) => typeof x.speaker === "string"); if (spk && normText(spk.speaker).toLowerCase() !== normText(sc.lines[p.n]?.who).toLowerCase()) return true; const stored = mine.find((x) => typeof x.line === "string"); if (stored) return normText(stored.line) !== normText(draftScript(said).script); const a = sayKeys(mine.map((x) => str(x.text)).join(" ")); const b = sayKeys(said); return a.length !== b.length || a.some((x, i) => x !== b[i]); } // --------------------------------------------------------------------------- // A SCREEN LINE's OWN TAKE (a recording of the line: lib/report/screenLineRecord.mjs, `posts screen … record`). // --------------------------------------------------------------------------- /** A screen line's words AS A READ WRITES THEM (draftScript of what it says): what a part's `line` and a line take's `screenLine.said` hold. */ export const screenLineWritten = (screen, n) => draftScript(screenLineSaid(screen, n)).script; /** A take's id (its file's name without .wav: post-narration.mjs takeIdOf). */ const idOfTake = (t) => str(t?.file).split("/").pop().replace(/\.wav$/i, ""); /** * Whether a line take (`screenLine`) SAYS line `n` of screen `screenId` AS IT IS NOW -- by its content, not its index: * the same screen, the line's words as a read writes them, its speaker. (Without `screenId`/`n`: the line it was recorded * for, by its index.) A take that is no recording of a line: null. */ export function lineTakeCurrent(entry, take, screenId = undefined, n = undefined) { const sl = take?.screenLine; if (!sl || typeof sl !== "object") return null; const sid = screenId ?? sl.screen; const k = n ?? sl.n; if (sl.screen !== sid) return false; const sc = screensOfEntry(entry).find((x) => x.id === sid); if (!sc || !sc.lines[k] || sc.lines[k].redact === true) return false; return normText(sl.said) === normText(screenLineWritten(sc, k)) && normText(sl.speaker).toLowerCase() === normText(sc.lines[k]?.who).toLowerCase(); } /** * Each screen line's RECORDINGS, pure, BY CONTENT: `[{ role, screen, n, takes: [{ n, id, take, current, chosen }] }]` -- * for each line, the item's takes that are recordings of a line of its screen (`screenLine`) and say that line as it is * now (`current`), or that the screen chose for it (`chosen`, current or not); a recording that says no line now is * listed under the line it was recorded for, not current. Lines with none are left out. */ export function lineTakesOf(entry) { const takes = Array.isArray(entry?.narration?.takes) ? entry.narration.takes : []; const recs = takes.map((t, i) => ({ t, i })).filter(({ t }) => t?.screenLine && typeof t.screenLine === "object"); if (!recs.length) return []; const out = []; const placed = new Set(); for (const sc of screensOfEntry(entry)) { sc.lines.forEach((_, k) => { const chosenId = sc.lineTakes && typeof sc.lineTakes === "object" ? sc.lineTakes[String(k)] : undefined; const mine = recs.filter(({ t }) => t.screenLine.screen === sc.id && (idOfTake(t) === chosenId || lineTakeCurrent(entry, t, sc.id, k) === true)); if (!mine.length) return; for (const { i } of mine) placed.add(i); out.push({ role: screenRole(sc.id, k), screen: sc.id, n: k, takes: mine.map(({ t, i }) => ({ n: i + 1, id: idOfTake(t), take: t, current: lineTakeCurrent(entry, t, sc.id, k) === true, chosen: idOfTake(t) === chosenId })) }); }); } // Recordings that say no line now (the line edited, the screen gone): under the line they were recorded for. for (const { t, i } of recs) { if (placed.has(i)) continue; const sl = t.screenLine; const role = screenRole(sl.screen, sl.n); let row = out.find((x) => x.role === role); if (!row) { row = { role, screen: sl.screen, n: sl.n, takes: [] }; out.push(row); } row.takes.push({ n: i + 1, id: idOfTake(t), take: t, current: false, chosen: false }); } return out; } /** The takes the screens CHOSE for their lines, as --line-take takes them: `{ "": }` (none: {}). */ export function chosenLineTakes(entry) { const takes = Array.isArray(entry?.narration?.takes) ? entry.narration.takes : []; const out = {}; for (const sc of screensOfEntry(entry)) { if (!sc.lineTakes || typeof sc.lineTakes !== "object") continue; for (const [k, v] of Object.entries(sc.lineTakes)) { const i = takes.findIndex((t) => idOfTake(t) === v); if (i >= 0 && /^\d{1,2}$/.test(k)) out[screenRole(sc.id, Number(k))] = i + 1; } } return out; } /** * THE LINE TAKES' WARNINGS (the lint; never refused here -- the read refuses a stale one when it is made): a chosen take * recorded for the line as it was, a recording no read uses (not chosen), a chosen take the picked read does not play. * They name lines and take numbers, never words. */ export function lineTakeWarnings(entry) { const id = entry?.id ?? "?"; const out = []; const t = pickedTake(entry); const parts = Array.isArray(t?.parts) ? t.parts : []; for (const L of lineTakesOf(entry)) { const sc = screensOfEntry(entry).find((x) => x.id === L.screen); if (!sc) continue; const chosen = L.takes.find((x) => x.chosen); if (chosen && !chosen.current) out.push(`timeline ${id}: line ${L.n} of screen ${L.screen}: its chosen take (take ${chosen.n}) was recorded for the line as it was -- record it again (umtool posts screen

${id} record ${L.screen} ${L.n} --recording ) or unchoose it (umtool posts screen

${id} set ${L.screen} take.${L.n}=off)`); else if (!chosen && L.takes.some((x) => x.current) && screenReadLines(sc).some((r) => r.n === L.n)) { out.push(`timeline ${id}: line ${L.n} of screen ${L.screen} has a recording no read uses (take ${L.takes.filter((x) => x.current).map((x) => x.n).join(", take ")}) -- choose one: umtool posts screen

${id} set ${L.screen} take.${L.n}= (or on the post bench), then make the read`); } // NOT HEARD (review round 1, j): nothing verified what a recording says unless --check-words heard it -- its words // are the line's text compared with itself. if (chosen && !chosen.take?.screenLine?.heard) out.push(`timeline ${id}: line take ${chosen.n} of screen ${L.screen} line ${L.n} was not heard -- nothing verified what the recording says; \`umtool posts screen

${id} record ${L.screen} ${L.n} --recording --check-words\` hears it`); if (chosen && chosen.current && isNarrated(entry)) { const mine = parts.filter((p) => p?.role === L.role); if (mine.length && !mine.every((p) => p.take === chosen.id)) out.push(`timeline ${id}: line ${L.n} of screen ${L.screen}: the picked read does not play its chosen take (take ${chosen.n}) -- make the read: umtool posts screen

${id} read`); } } return out; } /** A tile's mode in a layout (null: no such tile). */ export const tileModeOf = (layout, scope) => layout?.tiles?.find((t) => t.scope === scope)?.mode ?? null; // --------------------------------------------------------------------------- // THE GUARD: never narrate hidden text. // --------------------------------------------------------------------------- const ROLE_NAME = (r) => (parseScreenRole(r) ? `line ${parseScreenRole(r).n} of screen ${parseScreenRole(r).id}` : r === "post" ? "his words" : r === "quoted" ? "the post it quotes" : r.startsWith("linked:") ? "the post its words link to" : r.startsWith("parent:") ? (r === "parent:0" ? "the post it answers" : "the post that one answers") : `the words on attachment ${Number(r.slice(6)) + 1}`); /** * Every reason post item `entry`'s read narrates text the card does not show, * as sentences with the fix (empty: every part is on screen while it is said). * `followOn`: its read-follow (read-follow.mjs followKnobs(...).on). * * @param {Record} entry * @param {Record} [render] * @param {{ prev?: Record | null, scene?: Record | null, followOn?: boolean }} [o] */ export function threadReadErrors(entry, render = undefined, { prev = null, scene = null, followOn = true } = {}) { if (!isNarrated(entry)) return []; const w = `timeline ${entry?.id ?? "?"}`; const L = threadLayout(entry, render, { prev, scene }); const errors = []; const changed = new Set(); const fix = `umtool posts set-item

${entry?.id ?? ""}`; const remake = `or re-make the read without it (umtool posts narrate

${entry?.id ?? ""} --take, a script that leaves it out)`; L.roles.forEach((r, k) => { const n = k + 1; if (!r.role) { errors.push(`${w}: its take's part ${n} reads words the card does not show (no text on it holds them) -- set its role (umtool posts roles

${entry?.id ?? ""} --set ${n}=post|quoted|parent:0|media:0) ${remake}`); return; } if (parseScreenRole(r.role)) { errors.push(...screenPartErrors(entry, k, L.roles, changed)); return; } if (r.role.startsWith("media:")) { const m = (entry?.media ?? [])[Number(r.role.slice(6))]; if (!m) errors.push(`${w}: its take's part ${n} reads attachment ${Number(r.role.slice(6)) + 1}, which it does not have -- set its role (umtool posts roles)`); return; } const mode = tileModeOf(L, r.role); if (mode === null) errors.push(`${w}: its take's part ${n} reads ${ROLE_NAME(r.role)}, which the item does not carry -- set its role (umtool posts roles) ${remake}`); else if (mode === "hidden" || mode === "context") { const knob = r.role === "quoted" ? "thread.quoted" : r.role.startsWith("linked:") ? "thread.linked" : "thread.parent"; errors.push(`${w}: its take's part ${n} reads ${ROLE_NAME(r.role)}, which is drawn ${mode === "hidden" ? "hidden (not at all)" : "as context (small and dim)"} -- show it (${fix} ${knob}=full) ${remake}`); } }); if (L.on && !followOn && L.roles.some((r) => r.role && r.role !== "post" && !r.role.startsWith("media:"))) { errors.push(`${w}: its read reads the post it answers or quotes, and its read-follow is off -- the card can only show a context post in full while it is read with it on (${fix} follow=on) ${remake}`); } return [...new Set(errors)]; } // --------------------------------------------------------------------------- // THE SCHEDULE: each tile's size and strength on the item's clock. // --------------------------------------------------------------------------- /** * THE THREAD SCHEDULE, pure (read-follow's plan carries it, `follow.thread`): * `{ shrink, dim, seconds, pan, tiles: [{ scope, mode, read, from: [s, op], * to: [s, op], t0, t1 }] }` -- a tile at `from` until t0, eased to `to` by t1 * (s its scale, op its opacity). `blocks`: read-follow's scheduled blocks * (each `{ scope, part, start }`); `roles`: the parts' roles; `layout`: * threadLayout's. Null when the card is not threaded. */ export function threadSchedule(entry, render, { layout, blocks, lead = 0.4, beats = [] }) { if (!layout?.on) return null; const k = threadKnobs(entry, render); const roles = layout.roles; // Each read piece's start on the item's clock: its first block's start. const startOfPart = new Map(); // Keyed by the TAKE's part (`takePart` when read-follow's part stands for one: his words edited for reading). for (const b of blocks) { const n = b.part === null ? null : b.takePart ?? b.part; if (n !== null && b.start !== null && (!startOfPart.has(n) || b.start < startOfPart.get(n))) startOfPart.set(n, b.start); } // A PICTURE-ONLY context post's BEAT (pictureBeats) is a piece of its own, before the read's first. const beatOf = new Map((Array.isArray(beats) ? beats : []).map((b) => [b.scope, b])); const pieces = [...beatOf.values()].map((b) => ({ role: b.scope, parts: [], start: b.t0, beat: b.scope !== "post" })).concat(tilePieces(readPieces(entry, roles)).map((p) => { const ts = p.parts.map((n) => startOfPart.get(n)).filter(fin); return { ...p, start: ts.length ? Math.min(...ts) : null }; }).filter((p) => p.start !== null && p.role)); // A tile's pieces (a quoted post inside his post's tile: the post tile shows for both; above it, its own). const above = layout.quotedAt === "above"; const firstRead = (scope) => pieces.find((p) => p.role === scope || (scope === "post" && p.role === "quoted" && !above))?.start ?? null; /** The start of the first piece after the last piece of `scope` that is of another tile. */ const after = (scope) => { let last = -1; pieces.forEach((p, i) => { if (p.role === scope) last = i; }); if (last < 0) return null; const next = pieces.slice(last + 1).find((p) => p.role !== scope); return next ? next.start : null; }; const first = pieces[0] ?? null; const win = (T) => { const t0 = r3(Math.max(0, T - lead)); return { t0, t1: r3(t0 + k.seconds) }; }; const small = [k.shrink, k.dim]; // A carried parent (or a scene the run left on screen) opens the item: what the read reads first comes in // under it as it gives way. const carried = layout.tiles.some((t) => t.mode === "carry" || t.mode === "scene"); const revealed = (scope, T0) => !!k.reveal && !!first && T0 !== null && (first.start < T0 - 1e-6 ? first.role !== scope : carried) && !first.role.startsWith("media:"); const tiles = []; for (const t of layout.tiles) { if (t.mode === "hidden") continue; const row = { scope: t.scope, mode: t.mode, read: t.read, from: [1, 1], to: [1, 1], t0: 0, t1: 0 }; if (t.scope === "post") { // His post: revealed when its first piece (or the quoted post inside it) starts, when something else is read first. const T = firstRead("post"); if (revealed("post", T) && (carried || above || first.role !== "quoted")) { row.from = [1, 0]; Object.assign(row, win(T)); } // ITS SCREENS read after it (post-screens.mjs): his post gives way to a strip as the first comes in. const S = pieces.find((p) => !p.beat && isScreenScope(p.role) && (T === null || p.start > T))?.start ?? null; if (S !== null) { if (row.t1 > row.t0) row.then = { to: small, ...win(S) }; else { row.to = small; Object.assign(row, win(S)); } } } else if (t.mode === "scene") { // A post the run left on screen (post-conversation.mjs): it opens as the item before ended, and as the // read begins an ancestor of this item stays on top as context, any other post collapses away. row.from = t.from; row.to = t.action === "keep" ? small : [0, 0]; if (row.to[0] !== row.from[0] || row.to[1] !== row.from[1]) Object.assign(row, win(first ? first.start : lead)); row.action = t.action; row.ref = t.ref; if (t.wasPost) row.wasPost = true; } else if (t.mode === "context") { row.from = t.scope === "quoted" ? [1, k.dim] : small; row.to = row.from; } else if (t.mode === "carry") { // It opens as the item before ended, and gives way as the read begins. if (first) { row.to = small; Object.assign(row, win(first.start)); } } else if (t.pic && !t.read) { // PICTURE-ONLY (post-picture.mjs): its beat is its read -- revealed for it when something came before, in full // through it, small and dim as the next piece starts; with no beat, it gives way with the piece after it. const beat = beatOf.get(t.scope) ?? null; const at = layout.tiles.indexOf(t); const T = beat ? after(t.scope) : pieces.find((p) => !p.beat && layout.tiles.findIndex((x) => x.scope === p.role || (p.role === "quoted" && x.scope === "post" && !above)) > at)?.start ?? null; const own = t.scope !== "quoted" || !!t.above; if (beat && own && revealed(t.scope, beat.t0)) { row.from = t.fromScene ?? [1, 0]; row.to = [1, 1]; Object.assign(row, win(beat.t0)); if (T !== null) row.then = { to: small, ...win(T) }; } else if (T !== null) { row.to = own ? small : [1, k.dim]; Object.assign(row, win(T)); } row.pic = true; if (beat) row.beat = { t0: beat.t0, t1: beat.t1 }; } else if (t.read) { // Read: in full while it is read, then small and dim (a quoted post only dims) as the next piece starts. const T = after(t.scope); const T0 = firstRead(t.scope); // A quoted post above his: a top-level tile like a parent (revealed, shrunk); inside his: it only dims. const own = t.scope !== "quoted" || !!t.above; // A SCREEN (post-screens.mjs) read and done COLLAPSES as the next one comes in: stacked, they would bury it. const done = t.screen ? [0, 0] : small; if (own && revealed(t.scope, T0)) { // Revealed when its read comes (an older post read before it) -- from where the run had it, when it had it. row.from = t.fromScene ?? [1, 0]; row.to = [1, 1]; Object.assign(row, win(T0)); if (T !== null) row.then = { to: done, ...win(T) }; } else if (T !== null) { row.to = own ? done : [1, k.dim]; Object.assign(row, win(T)); } if (t.screen) row.screen = true; } if (t.above) row.above = true; if (t.rel) row.rel = t.rel; if (t.linkedFrom) row.linkedFrom = t.linkedFrom; tiles.push(row); } // THE BRANCH MAP (post-branch-map.mjs): in as the scene changes branch (its first piece, less the pan's lead). const map = layout.map ? { ...layout.map, times: mapTimes(first ? Math.max(0, first.start - lead) : lead) } : null; return { shrink: k.shrink, dim: k.dim, seconds: k.seconds, pan: k.pan, contextRoom: THREAD_CONTEXT_ROOM, quotedAt: above ? "above" : "inside", tiles, ...(map ? { map } : {}) }; } /** The read's pieces on their TILES: a screen's lines (post-screens.mjs) are one piece of its tile; any other role its own. */ function tilePieces(pieces) { if (!pieces.some((p) => p.role && isScreenScope(p.role))) return pieces; const out = []; for (const p of pieces) { const role = p.role ? tileOfRole(p.role) : p.role; const last = out[out.length - 1]; if (last && last.role === role && role) last.parts = [...last.parts, ...p.parts]; else out.push({ ...p, role }); } return out; } /** inOut cubic over [0, 1]. */ const ease = (x) => { const v = Math.min(1, Math.max(0, x)); return v < 0.5 ? 4 * v ** 3 : 1 - (-2 * v + 2) ** 3 / 2; }; const mix = (a, b, f) => a + (b - a) * f; /** One tile's `[scale, opacity]` at item second `s` (seek-safe). */ export function tileStateAt(row, s) { const step = (from, to, t0, t1) => { if (s <= t0) return from; if (s >= t1) return to; const f = ease((s - t0) / Math.max(1e-6, t1 - t0)); return [mix(from[0], to[0], f), mix(from[1], to[1], f)]; }; let v = step(row.from, row.to, row.t0, row.t1); if (row.then && s > row.then.t0) v = step(row.to, row.then.to, row.then.t0, row.then.t1); // A LINK VISIT (post-link-visit.mjs): lit again -- full size and strength over its hold, eased in and out. const p = row.pulse; if (p && s > p.t0 && s < p.t3) { const w = s < p.t1 ? ease((s - p.t0) / Math.max(1e-6, p.t1 - p.t0)) : s > p.t2 ? 1 - ease((s - p.t2) / Math.max(1e-6, p.t3 - p.t2)) : 1; v = [mix(v[0], 1, w), mix(v[1], 1, w)]; } return [Math.round(v[0] * 1000) / 1000, Math.round(v[1] * 1000) / 1000]; } /** Every tile's state at `s`: `{ : [scale, opacity] }`. */ export function threadStateAt(thread, s) { const out = {}; for (const row of thread?.tiles ?? []) out[row.scope] = tileStateAt(row, s); return out; } /** The times a tile's state changes (the starts and ends of its transitions). */ export function threadTimes(thread) { const out = new Set(); for (const row of thread?.tiles ?? []) { if (row.t1 > row.t0) out.add(row.t0).add(row.t1); if (row.then) out.add(row.then.t0).add(row.then.t1); if (row.pulse) out.add(row.pulse.t0).add(row.pulse.t1).add(row.pulse.t2).add(row.pulse.t3); } return [...out].sort((a, b) => a - b); } // --------------------------------------------------------------------------- // THE GEOMETRY under the tiles' scales (pure: the pan's path is worked out // from the page measured once, at every tile's full size). // --------------------------------------------------------------------------- /** * Where the flow's things are with the tiles at `scales` (`{ : s }`): * `{ C, top(y), blocks: { : { top, bottom } } }`. `geo` is measureFollow's * (its `tiles`: `{ : { top, height } }` at full size, `blockTile`: the * tile each block is in). A tile shrinks about its top-left corner and the * flow below it closes up. */ export function threadGeoAt(geo, scales) { const tiles = Object.entries(geo?.tiles ?? {}).map(([scope, t]) => ({ scope, ...t, s: fin(scales?.[scope]) ? scales[scope] : 1 })).sort((a, b) => a.top - b.top); const shift = (y) => { let d = 0; for (const t of tiles) { if (t.s >= 0.9995) continue; if (y >= t.top + t.height - 0.5) d += (1 - t.s) * t.height; else if (y > t.top) d += (1 - t.s) * (y - t.top); // A scene tile collapsing away (post-conversation.mjs) closes the gap above it too. if (t.gap > 0 && (t.scope.startsWith("conv:") || isScreenScope(t.scope)) && y >= t.top - 0.5) d += (1 - t.s) * t.gap; } return y - d; }; const blocks = {}; for (const [k, b] of Object.entries(geo?.blocks ?? {})) blocks[k] = { top: shift(b.top), bottom: shift(b.bottom) }; const tileTops = {}; for (const t of tiles) tileTops[t.scope] = { top: shift(t.top), bottom: shift(t.top + t.height) }; return { C: shift(geo?.C ?? 0), blocks, tiles: tileTops }; } // --------------------------------------------------------------------------- // THE WARNINGS: what a read says that is not on its card, short of the guard. // --------------------------------------------------------------------------- /** * WHERE A PICKED TAKE SAYS A LINK (post-narration.mjs spokenUrls), pure: * `{ parts: [k…], words: [link…], whole, script }` -- the parts that say one * (k from 0), what they say, and whether each of them is nothing but links * (`whole`: dropping them is the fix, `posts reread … --drop-urls`; else a * re-take). A take read in one go: its script (`script` true, no parts). * Null when it says none. */ export function urlParts(entry) { const t = pickedTake(entry); if (!t) return null; const parts = Array.isArray(t.parts) ? t.parts : []; if (parts.length) { const hit = parts.map((p, k) => ({ k, urls: spokenUrls(p?.text) })).filter((x) => x.urls.length); if (!hit.length) return null; return { parts: hit.map((x) => x.k), words: hit.flatMap((x) => x.urls), whole: hit.every((x) => isOnlyUrls(parts[x.k].text)), script: false }; } const urls = spokenUrls(str(t.script).trim() ? t.script : entry?.narration?.script); return urls.length ? { parts: [], words: urls, whole: false, script: true } : null; } /** * Post item `entry`'s read WARNINGS (the build's lint says them, never * refuses): a take that says a link aloud, with its fix. */ export function threadReadWarnings(entry) { if (!isNarrated(entry)) return []; const id = entry?.id ?? "?"; const out = []; const u = urlParts(entry); if (u) { const said = [...new Set(u.words)].slice(0, 2).map((w) => `"${w.length > 40 ? `${w.slice(0, 39)}…` : w}"`).join(", "); const where = u.script ? "its read says" : `part${u.parts.length === 1 ? "" : "s"} ${u.parts.map((k) => k + 1).join(", ")} of its take say${u.parts.length === 1 ? "s" : ""}`; const fix = u.whole ? `drop ${u.parts.length === 1 ? "it" : "them"} (umtool posts reread

${id} --drop-urls)` : `re-make the take on a script without it (umtool posts narrate

${id} --take; a drafted script drops links)`; out.push(`timeline ${id}: ${where} a link aloud (${said}) -- ${fix}`); } // A text the archive kept cut short (X's "…" or "Show more", not a link's): the read and the card stop mid-thought. const roles = new Set(partRoles(entry).map((r) => r.role).filter(Boolean)); const texts = [["post", "his words", entry?.text], ["quoted", "the post it quotes", entry?.quoted?.text], ...parentsOf(entry).map((p, i) => [`parent:${i}`, i ? "the post that one answers" : "the post it answers", p?.text])]; for (const [scope, name, text] of texts) { if ((scope !== "post" && !roles.has(scope)) || !isTruncated(text)) continue; out.push(`timeline ${id}: ${name} (${scope}) ends cut short in the archive ("…") -- the read stops mid-thought; re-fetch the post (umtool posts context

, or the editor's capture) or paraphrase it`); } return out; } /** Whether an archived text ends CUT SHORT: X's "…" or "Show more" at its end that is not a link's (joinSplitLinks drops those). */ export function isTruncated(text) { const t = joinSplitLinks(str(text)).trim(); return /…$/.test(t) || /\bshow more$/i.test(t); } /** THE WARNINGS over a cut (the build's lint): every narrated post item's (threadReadWarnings), and its screens' (post-screens.mjs). */ export function validateThreadReadWarnings(manifest) { const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; return tl.filter((e) => e?.type === "post").flatMap((e) => [ ...threadReadWarnings(e), ...(Array.isArray(e.screens) ? screenWarnings(e, { narrated: isNarrated(e), takeRoles: isNarrated(e) ? partRoles(e).map((r) => r.role) : [], attachAfter: isNarrated(e) && postNarrationKnobs(e, manifest?.render).attach === "after" }) : []), // Recordings of its screens' lines (screenLine takes): none on an item without them. ...(Array.isArray(e.screens) ? lineTakeWarnings(e) : []), ]); } /** * THE GUARD over a cut (the build's lint): every post item's read against * what its card shows (threadReadErrors), each with the item before it. */ export function validateThreadReads(manifest) { const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const errors = []; tl.forEach((e, i) => { if (e?.type !== "post") return; // Each with the item before it and the scene its run leaves on screen (post-conversation.mjs). errors.push(...threadReadErrors(e, manifest?.render, { ...planContext(tl, i, manifest?.render), followOn: followKnobs(e, manifest?.render).on })); }); 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} entry * @param {Record | 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; // His own attachments in the slot (a picture-only post's are in his card: post-picture.mjs). const own = Array.isArray(entry?.media) && entry.media.length > 0 && !isPictureOnly(entry, { text: cardText(entry) }); 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 ref = refOfScope(entry, row.scope); // A PICTURE-ONLY post's picture is in its own card (post-picture.mjs), never in the slot. if (isPictureOnly(ref)) continue; const media = refMediaOf(ref); 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]; // A context post's picture shown (not read) while his own words are read: a look at it, then his own attachment again. const ownAt = cand.find((x) => x.scope === "own")?.on ?? null; const end = next ? next.on : !c.read && ownAt !== null && c.on >= ownAt ? Math.min(total, c.on + 2 * PANEL.minUnread) : 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; } else { // A TALL picture shown, not read (a screenshot of a long chat): its top at a readable width, drifting down a // little -- never the whole of it shrunk to a sliver. const m0 = c.media[0]; if (m0?.kind === "image" && fin(m0.width) && fin(m0.height) && m0.height / Math.max(1, m0.width) > 2) show.scroll = [[c.on, 0], [t1, 0.12]]; } 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.takePart ?? 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; } /** * THE READ's PIECES IN DATE ORDER (operator, 4 Nov: "include the whole thread chronologically"), pure: what a * narration batch reads, in the order to read it -- `[{ role, date, author, handle, text }]`, every context post * the card draws with words (the parents, the quoted post, the linked posts; a linked post's `transcript` as its own * words) and his post, oldest first (roleOrderOf). `skip`: roles the run has read already (a carried post). * * @param {Record} entry * @param {{ skip?: string[] }} [o] */ export function chronoPieces(entry, { skip = [] } = {}) { const order = roleOrderOf(entry); const out = []; const add = (role, ref, text) => { if (!str(text).trim() || skip.includes(role)) return; out.push({ role, date: str(ref?.date) || null, author: str(ref?.author) || null, handle: str(ref?.handle) || null, text: str(text) }); }; parentsOf(entry).forEach((p, i) => add(`parent:${i}`, p, contextText(p))); if (isObj(entry?.quoted)) add("quoted", entry.quoted, contextText(entry.quoted)); linksOf(entry).forEach((l, i) => add(`linked:${i}`, l, [contextText(l), str(l.transcript)].filter((t) => t.trim()).join("\n\n"))); add("post", entry, cardText(entry)); out.sort((a, b) => order(a.role) - order(b.role)); // ITS SCREENS' read lines (post-screens.mjs), after everything else, in the screens' order: `who` as written. for (const p of screenPieces(entry)) if (!skip.includes(p.role)) out.push({ role: p.role, date: null, author: null, handle: null, who: p.who, screen: p.screen, text: p.text, ...(p.spoken ? { spoken: p.spoken } : {}) }); return out; }