// post-thread.mjs: a post item's THREAD READ -- each part's role (the text it // reads: the post it answers, the post it quotes, his words, an attachment's), // what the card shows for each, the guard that refuses narrating hidden text, // and THE INVARIANT: every part's time span lies inside its block's on-screen, // highlighted interval -- its tile in full, its block lit, in the window. import assert from "node:assert/strict"; import { test } from "node:test"; import { postCardHtml, postItemPlan, validatePostItem } from "./post-item.mjs"; import { validatePostNarrationRender } from "./post-narration.mjs"; import { followPath, followRuns, followStateAt, followStateKey, isDrawnState, readInViewErrors, shotStateAt } from "./read-follow.mjs"; import { THREAD_DEFAULTS, partRoles, readPieces, threadGeoAt, threadKnobs, threadLayout, threadReadErrors, threadStateAt, tileStateAt, validateThreadReads, threadReadWarnings, urlParts, validateThreadReadWarnings, isTruncated, } from "./post-thread.mjs"; const PARENT = "The first thing anyone notices is the noise from the street.\n\nThen the lights in the hall go out without warning.\n\nNobody had planned for any of this at all."; const REPLY = "That is exactly what I was saying yesterday morning.\n\nWe should have bought the generator in the spring."; const QUOTED = "Here is the plan for the weekend repairs on the roof."; const parentRef = (o = {}) => ({ id: "900", author: "Neighbour", handle: "neighbour_one", date: "2026-10-26T19:09:24.000Z", text: PARENT, ...o }); const base = (o = {}) => ({ type: "post", id: "p-1", post: "acct-x/1001", platform: "x", author: "Subject", handle: "subject", date: "2026-10-27T02:41:55.000Z", text: REPLY, ...o, }); /** A take as the batch assembles one: pieces in order (para = piece * 100 + paragraph), each paragraph a part. */ function take(pieces, { roles = false } = {}) { const parts = []; let at = 0; pieces.forEach(([text, role], pi) => { text.split(/\n\n/).forEach((para, k) => { const seconds = Math.round((para.split(/\s+/).length / 3) * 100) / 100; at += parts.length ? (k === 0 ? 0.8 : 0.6) : 0; parts.push({ n: parts.length + 1, para: pi * 100 + k, text: para, start: Math.round(at * 100) / 100, seconds, ...(roles ? { role } : {}) }); at += seconds; }); }); return { file: "narration/posts/1001/take-1.orpheus-thread.wav", engine: "orpheus", voice: "leo+zac", seconds: Math.round(at * 100) / 100, script: pieces.map((p) => p[0]).join("\n\n"), parts }; } const narrate = (e, pieces, o) => ({ ...e, narration: { script: e.text, takes: [take(pieces, o)], pick: 0 } }); test("roles: the parent read first (para 0..), his words after (100..), matched by word pairs -- not by a bag of common words", () => { const e = narrate(base({ parents: [parentRef()] }), [[PARENT, "parent:0"], [REPLY, "post"]]); assert.deepEqual(partRoles(e).map((r) => r.role), ["parent:0", "parent:0", "parent:0", "post", "post"]); assert.ok(partRoles(e).every((r) => r.source === "inferred")); assert.deepEqual(readPieces(e).map((p) => [p.role, p.parts]), [["parent:0", [0, 1, 2]], ["post", [3, 4]]]); // A quoted post read first, then his words. const q = narrate(base({ quoted: { author: "Other", handle: "other", text: QUOTED } }), [[QUOTED], [REPLY]]); assert.deepEqual(partRoles(q).map((r) => r.role), ["quoted", "post", "post"]); // A stored role wins. const s = narrate(base({ parents: [parentRef()] }), [[PARENT, "quoted"], [REPLY, "post"]], { roles: true }); assert.equal(partRoles(s)[0].role, "quoted"); assert.equal(partRoles(s)[0].source, "stored"); }); test("roles: words no text holds are an attachment's when the post has a picture (a screenshot read first), else no text's; a two-word reply that repeats its parent's words still reads his", () => { const shot = "Someone wrote a long thing about the council meeting going sideways again."; const withPic = narrate(base({ media: [{ src: "posts-media/a/1.png", kind: "image", width: 600, height: 700 }] }), [[shot], [REPLY]]); assert.deepEqual(partRoles(withPic).map((r) => r.role), ["media:0", "post", "post"]); const without = narrate(base(), [[shot], [REPLY]]); assert.equal(partRoles(without)[0].role, null); // His two words are in the parent too: a new piece reads the next text along. const tiny = narrate(base({ text: "It wobbles.", parents: [parentRef({ text: "Look how it wobbles, oh my word." })] }), [["Look how it wobbles, oh my word."], ["It wobbles."]]); assert.deepEqual(partRoles(tiny).map((r) => r.role), ["parent:0", "post"]); }); test("the layout: a read parent full, an unread one context -- carried when it is the item before; hidden and excerpt are knobs", () => { const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); const L = threadLayout(e); assert.equal(L.on, true); assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, t.read]), [["parent:0", "full", true], ["post", "full", true]]); // His own reply only: the parent unread -- context, or carried when it is the item before. const own = narrate(base({ parents: [parentRef()] }), [[REPLY]]); assert.equal(threadLayout(own).tiles[0].mode, "context"); assert.equal(threadLayout(own, undefined, { prev: { type: "post", id: "p-0", post: "acct-x/900" } }).tiles[0].mode, "carry"); assert.equal(threadLayout({ ...own, thread: { carry: false } }, undefined, { prev: { post: "acct-x/900" } }).tiles[0].mode, "context"); assert.equal(threadLayout({ ...own, thread: { parent: "hidden" } }).tiles[0].mode, "hidden"); // Un-narrated: never threaded (the card as it was). assert.equal(threadLayout(base({ parents: [parentRef()] })).on, false); // The cut's default, the post's own over it. assert.equal(threadKnobs({}, { postNarration: { thread: { shrink: 0.5 } } }).shrink, 0.5); assert.equal(threadKnobs({ thread: { shrink: 0.7 } }, { postNarration: { thread: { shrink: 0.5 } } }).shrink, 0.7); assert.equal(threadKnobs({}).dim, THREAD_DEFAULTS.dim); }); test("THE GUARD: a part read off a hidden or context post, off no text on the card, or a threaded read with follow off is refused, with the fix", () => { const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); assert.deepEqual(threadReadErrors(e), []); const hidden = threadReadErrors({ ...e, thread: { parent: "hidden" } }); assert.equal(hidden.length, 3); assert.match(hidden[0], /part 1 reads the post it answers, which is drawn hidden.*thread\.parent=full.*re-make the read without it/); assert.match(threadReadErrors({ ...e, thread: { parent: "context" } })[0], /drawn as context/); assert.match(threadReadErrors(e, undefined, { followOn: false }).join(" "), /read-follow is off.*follow=on/); const lost = narrate(base(), [["Words from somewhere nobody can see on the card."], [REPLY]]); assert.match(threadReadErrors(lost)[0], /part 1 reads words the card does not show.*umtool posts roles/); // Over a cut: each item with the one before it. const m = { render: {}, timeline: [base({ id: "p-0", post: "acct-x/900", text: PARENT }), narrate(base({ parents: [parentRef()] }), [[REPLY]])] }; assert.deepEqual(validateThreadReads(m), []); // The knobs' own errors. assert.match(validatePostItem({ ...e, thread: { parent: "huge", shrink: 2 } }).join(" "), /thread\.parent must be one of.*thread\.shrink must be 0\.3–1/); assert.match(validatePostNarrationRender({ postNarration: { thread: { quoted: "carry" } } }).join(" "), /render\.postNarration\.thread\.quoted/); }); test("the schedule: the parent in full while it is read, shrunk and dimmed as his reply comes in -- revealed under it; a carried parent gives way as the read starts", () => { const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); const th = plan.follow.thread; const [par, post] = th.tiles; assert.deepEqual([par.scope, par.from, par.to], ["parent:0", [1, 1], [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]]); assert.deepEqual([post.scope, post.from, post.to], ["post", [1, 0], [1, 1]]); // His first part starts at lead + its start in the take; the change begins FOLLOW_PAN.lead before it. const replyStart = plan.follow.blocks.find((b) => b.scope === "post" && b.part === 3).start; assert.equal(par.t0, Math.round((replyStart - 0.4) * 1000) / 1000); assert.equal(par.t1, Math.round((par.t0 + THREAD_DEFAULTS.seconds) * 1000) / 1000); assert.deepEqual(tileStateAt(par, 1), [1, 1]); assert.deepEqual(tileStateAt(par, par.t1 + 0.01), [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]); assert.deepEqual(threadStateAt(th, 1).post, [1, 0]); // Carried: in full at the first frame, small and dim once the read is under way, his reply revealed. const own = narrate(base({ parents: [parentRef()] }), [[REPLY]]); const cp = postItemPlan(own, {}, { prev: { post: "acct-x/900" } }); const carry = cp.follow.thread.tiles.find((t) => t.scope === "parent:0"); assert.equal(carry.mode, "carry"); assert.deepEqual(tileStateAt(carry, 0), [1, 1]); assert.deepEqual(tileStateAt(carry, 2), [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]); assert.deepEqual(threadStateAt(cp.follow.thread, 0).post, [1, 0]); assert.deepEqual(threadStateAt(cp.follow.thread, 2).post, [1, 1]); }); test("the geometry: a tile shrunk about its corner closes the flow up under it", () => { const geo = { H: 500, C: 1000, tiles: { "parent:0": { top: 0, height: 400 }, post: { top: 420, height: 580 } }, blocks: { 0: { top: 100, bottom: 200 }, 1: { top: 500, bottom: 600 } } }; const g = threadGeoAt(geo, { "parent:0": 0.5 }); assert.deepEqual(g.blocks[0], { top: 50, bottom: 100 }); assert.deepEqual(g.blocks[1], { top: 300, bottom: 400 }); assert.equal(g.C, 800); assert.deepEqual(g.tiles.post, { top: 220, bottom: 800 }); }); /** * A page's geometry for an entry, as measureFollow reports it: each tile's blocks stacked at `line` px a * paragraph's line (a block's words / 6 lines), a head over each tile, the window `H` tall. */ function fakeGeo(plan, { H = 520, line = 44 } = {}) { const blocks = {}; const tiles = {}; let y = 0; const order = plan.follow.thread.tiles.map((t) => t.scope); for (const scope of order) { const top = y; y += 70; for (const b of plan.follow.blocks.filter((x) => x.scope === scope)) { const h = Math.max(1, Math.ceil((b.to - b.from + 1) / 6)) * line; blocks[b.k] = { top: y, bottom: y + h }; y += h + line; } tiles[scope] = { top, height: y - top }; y += 22; } return { H, C: y, blocks, tiles }; } test("THE INVARIANT: every part's time span lies inside its block's on-screen, highlighted interval -- its tile in full, its block lit, inside the window", () => { const cases = [ ["a parent read first", narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]), null], ["a quoted post read first", narrate(base({ quoted: { author: "Other", handle: "other", text: `${QUOTED}\n\n${PARENT}` } }), [[`${QUOTED}\n\n${PARENT}`], [REPLY]]), null], ["two parents, then him", narrate(base({ parents: [parentRef({ id: "901", handle: "second_one", text: "Is anyone else hearing the street noise again tonight?" }), parentRef()] }), [[PARENT], ["Is anyone else hearing the street noise again tonight?"], [REPLY]]), null], ["a carried parent", narrate(base({ parents: [parentRef()] }), [[REPLY]]), { post: "acct-x/900" }], ["a quoted post read after his words", narrate(base({ quoted: { author: "Other", handle: "other", text: QUOTED } }), [[REPLY], [QUOTED]]), null], ]; for (const [what, e, prev] of cases) { const render = { postNarration: { lead: 0.4 } }; const plan = postItemPlan(e, render, { prev }); assert.ok(plan.follow?.thread, `${what}: threaded`); const geo = fakeGeo(plan); const path = followPath(plan.follow, geo); const t = e.narration.takes[0]; const settle = 0.4 + Math.max(THREAD_DEFAULTS.pan, THREAD_DEFAULTS.seconds) - 0.4 + plan.follow.ease / 2 + 0.02; t.parts.forEach((p, k) => { const blk = plan.follow.blocks.find((b) => b.part === k); assert.ok(blk, `${what}: part ${k + 1} has a block`); const from = blk.start + settle; const to = (t.parts[k + 1] ? plan.follow.blocks.find((b) => b.part === k + 1).start : plan.follow.readEnd) - 0.45; for (let s = from; s <= to; s += 0.1) { const st = followStateAt(plan.follow, path, s); const [sc, op] = st.tiles[blk.scope]; assert.equal(sc, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its tile (${blk.scope}) in full`); // A quoted post read first is its own tile above his post: at full strength like any other. if (blk.scope !== "quoted" || plan.follow.thread.quotedAt === "above") assert.equal(op, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its tile at full strength`); else assert.equal(st.tiles.post[1], 1, `${what}: the post the quoted post is in, shown`); assert.equal(st.op[blk.k] ?? 1, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its block lit`); assert.equal(st.current, blk.k, `${what}: part ${k + 1} is the block being read`); const g = threadGeoAt(geo, Object.fromEntries(Object.entries(st.tiles).map(([x, v]) => [x, v[0]]))); const bb = g.blocks[blk.k]; assert.ok(bb.top - st.offset >= -1 && bb.bottom - st.offset <= geo.H + 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its block in the window (${(bb.top - st.offset).toFixed(0)}–${(bb.bottom - st.offset).toFixed(0)} of ${geo.H})`); // Its tile WHOLE in the window while it is read, when it fits (a tile is read in full, not clipped at the foot). const tt = g.tiles[blk.scope]; if (tt && tt.bottom - tt.top <= geo.H - Math.round(geo.H * 0.1)) assert.ok(tt.top - st.offset >= -1 && tt.bottom - st.offset <= geo.H + 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its tile whole in the window (${(tt.top - st.offset).toFixed(0)}–${(tt.bottom - st.offset).toFixed(0)} of ${geo.H})`); } }); // A transition draws a different card every frame; a still read, one. assert.notEqual(followStateKey(followStateAt(plan.follow, path, 0.5)), followStateKey(followStateAt(plan.follow, path, plan.follow.readEnd + 1))); } }); test("the card page: a threaded read draws the conversation as tiles in one flow -- each post whole (no clamp), a hidden one not at all, an excerpt without its unread paragraphs", () => { const e = narrate(base({ parents: [parentRef()], quoted: { author: "Other", handle: "other", text: QUOTED } }), [[PARENT], [REPLY]]); const plan = postItemPlan(e, {}); const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow.thread }); assert.match(html, /data-post-thread="3"/); for (const scope of ["parent:0", "post", "quoted"]) assert.ok(html.includes(`data-thread-slot="${scope}"`), scope); assert.match(html, /data-w="parent:0:\d+">all\.<\/span>/, "the parent's last word is on the page"); assert.match(html, /\.tile \.tt \{ display: block; -webkit-line-clamp: none;/); const hid = postItemPlan({ ...e, thread: { quoted: "hidden" } }, {}); assert.ok(!postCardHtml(e, { width: 1600, height: 900, follow: true, thread: hid.follow.thread }).includes('data-thread-slot="quoted"')); // An excerpt: the parent read only in part -- its unread paragraph not drawn. const part = narrate(base({ parents: [parentRef()] }), [["The first thing anyone notices is the noise from the street."], [REPLY]]); const ex = postItemPlan({ ...part, thread: { parent: "excerpt" } }, {}); const exHtml = postCardHtml({ ...part, thread: { parent: "excerpt" } }, { width: 1600, height: 900, follow: true, thread: ex.follow.thread }); assert.match(exHtml, /data-thread-excerpt/); assert.match(exHtml, /\[data-thread-tile="parent:0"\] \[data-post-block="\d+"\][^{]*\{ display: none; \}/); // Not narrated: the card as it was (no tiles). assert.ok(!postCardHtml(base({ parents: [parentRef()] }), { width: 1600, height: 900, follow: true, thread: null }).includes("data-thread-slot")); }); test("a take read in one go (no parts): its script's paragraphs carry the roles -- the parent it reads is shown in full while the words share the read", () => { const e = base({ parents: [parentRef()], narration: { script: REPLY, takes: [{ file: "narration/posts/1001/take-1.orpheus-zac.wav", seconds: 20, script: `${PARENT}\n\n${REPLY}` }], pick: 0 } }); assert.deepEqual(partRoles(e).map((r) => r.role), ["parent:0", "parent:0", "parent:0", "post", "post"]); const plan = postItemPlan(e, {}); assert.equal(plan.follow.source, "script"); assert.deepEqual(plan.follow.thread.tiles.map((t) => [t.scope, t.mode]), [["parent:0", "full"], ["post", "full"]]); assert.deepEqual(threadReadErrors(e), []); }); test("A READ NEVER SAYS A LINK: a take whose parts say one is warned, with the fix -- drop the parts that are nothing but links, else a re-take", () => { const quoted = { author: "Other", handle: "other", text: `${QUOTED}\n\nhttps://\nweb.archive.org/web/2021032015\n1733/https://twitter.com/x/status/1\n…` }; const e = narrate(base({ quoted }), [[`${QUOTED}\n\nhttps://. web.archive.org slash web slash 2021032015. 1733/. …`], [REPLY]]); const u = urlParts(e); assert.deepEqual(u.parts, [1]); assert.equal(u.whole, true); assert.match(threadReadWarnings(e)[0], /timeline p-1: part 2 of its take says a link aloud \("https:\/\/\.", .*umtool posts reread

p-1 --drop-urls/); // A link inside words: a re-take. const mixed = narrate(base({ quoted }), [[`${QUOTED} See https://x.com/a/b for more.`], [REPLY]]); assert.match(threadReadWarnings(mixed)[0], /part 1 of its take says a link aloud.*re-make the take/); // None: no warning; over a cut, every narrated post item's. assert.deepEqual(threadReadWarnings(narrate(base({ quoted }), [[QUOTED], [REPLY]])), []); assert.equal(validateThreadReadWarnings({ timeline: [e, base({ id: "p-2" })] }).length, 1); }); test("QUOTES READ IN PLACE: read before his words, the quoted post is its own tile ABOVE his post -- in full and lit, then shrunk and dimmed as his words come in under it; read after them, inside his post", () => { const quoted = { author: "Other", handle: "other", text: QUOTED }; const first = narrate(base({ quoted }), [[QUOTED], [REPLY]]); const L = threadLayout(first); assert.equal(L.quotedAt, "above"); assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, !!t.above]), [["quoted", "full", true], ["post", "full", false]]); const plan = postItemPlan(first, { postNarration: { lead: 0.4 } }); const th = plan.follow.thread; assert.equal(th.quotedAt, "above"); const q = th.tiles.find((t) => t.scope === "quoted"); const post = th.tiles.find((t) => t.scope === "post"); assert.deepEqual([q.from, q.to], [[1, 1], [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]]); assert.deepEqual([post.from, post.to], [[1, 0], [1, 1]]); // The card opens on the quoted post: his post not yet shown, the flow not panned down to it. assert.deepEqual(threadStateAt(th, 0.5), { quoted: [1, 1], post: [1, 0] }); const html = postCardHtml(first, { width: 1600, height: 900, follow: true, thread: th }); assert.ok(html.indexOf('data-thread-slot="quoted"') < html.indexOf('data-thread-slot="post"'), "the quoted tile is above his post's"); assert.match(html, /data-thread-slot="quoted" data-thread-above="">

quoted html2.indexOf('data-thread-slot="post"'), "inside his post"); assert.doesNotMatch(html2, /data-thread-above/); }); test("TRUNCATED archive text: a text the read reads that ends in X's \"…\" (not a link's) is warned, naming the item and the piece", () => { assert.equal(isTruncated("He said this and then…"), true); assert.equal(isTruncated("Look\nhttps://\nx.com/a/status/1\n…"), false, "a link's ellipsis"); assert.equal(isTruncated("Read the rest. Show more"), true); assert.equal(isTruncated("A whole post."), false); const cut = parentRef({ text: "The first thing anyone notices is the noise from the street and then…" }); const e = narrate(base({ parents: [cut] }), [[cut.text], [REPLY]]); assert.match(threadReadWarnings(e).join(" "), /timeline p-1: the post it answers \(parent:0\) ends cut short/); // Not read, not warned (a context post shows only a strip of it). assert.deepEqual(threadReadWarnings(narrate(base({ parents: [cut] }), [[REPLY]])), []); }); test("THE READ IN VIEW (readInViewErrors): his post read alone under a long context parent, beside its attachment -- the build must shoot the frames (the parent small and dim, his post whole), and the page as drawn is refused (Mr. Obvious mid-5, p-2117259673917386879)", () => { const longParent = Array.from({ length: 8 }, (_, i) => `Paragraph ${i + 1} of the long post he answers goes on about the coalition and the people in it again.`).join("\n\n"); const video = { src: "posts-media/acct-x/1001/1001_1.mp4", kind: "video", width: 1280, height: 720, seconds: 20, audio: true }; const one = "I returned from being asleep and the whole street is still arguing about the generator we never bought."; const e = { ...narrate(base({ text: one, parents: [parentRef({ text: longParent })], media: [video] }), [[one, "post"]], { roles: true }), thread: { parent: ["context", "auto"] } }; // The card beside its attachment (side), threaded: the parent context, his post the one tile read. const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: postItemPlan(e, {}).follow.thread }); assert.match(html, /data-post-layout="side"/); assert.match(html, /data-thread-mode="context"/); const plan = postItemPlan(e, { postNarration: { lead: 0.25 } }); const th = plan.follow.thread; assert.deepEqual(th.tiles.map((t) => [t.scope, t.mode, t.from]), [["parent:0", "context", [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]], ["post", "full", [1, 1]]]); assert.equal(plan.follow.blocks.filter((b) => b.start !== null).length, 1, "one part read"); const geo = fakeGeo(plan); assert.ok(geo.tiles.post.top + 100 > geo.H, "at full size the parent pushes his post past the window's foot"); const path = followPath(plan.follow, geo); assert.equal(path.segments.length, 0, "nothing moves: no pan"); // The frames are not the page as drawn -- so the build shoots them (post-render.mjs shootFollow). const runs = followRuns(plan.follow, path, plan.total, 30); assert.ok(!runs.every((r) => isDrawnState(r.st)), "the build must shoot the follow frames"); assert.deepEqual(readInViewErrors(plan.follow, geo, shotStateAt(plan.follow, path, 30, true), { total: plan.total, id: e.id }), []); // The page as drawn (no frames shot: the bug): his post cut off at the foot, the parent full and lit. const bad = readInViewErrors(plan.follow, geo, () => null, { total: plan.total, id: e.id }); assert.equal(bad.length, 2, bad.join("\n")); assert.match(bad[0], /^p-1: part 1 \(his post, block \d+\) is not in full view for [\d.]+ s of its read .* past the window's foot/); assert.match(bad[1], /^p-1: the post it answers \(parent:0\) \(context, never read\) is drawn at 1\.00× and 1\.00 strength at 0 s/); }); test("THE READ IN VIEW: a context quote inside his post only dims; a carried parent gives way; a block read off the window's foot or a tile drawn small while read is named; a page with nothing to apply needs no frames", () => { // A quoted post set to context, his words read: inside his post, at its context strength. const q = { ...narrate(base({ quoted: { author: "Other", handle: "other", text: QUOTED } }), [[REPLY, "post"]], { roles: true }), thread: { quoted: "context" } }; const qp = postItemPlan(q, {}); const qg = fakeGeo(qp); const qpath = followPath(qp.follow, qg); assert.deepEqual(readInViewErrors(qp.follow, qg, shotStateAt(qp.follow, qpath, 30), { total: qp.total, id: "q" }), []); assert.match(readInViewErrors(qp.follow, qg, () => null, { total: qp.total, id: "q" }).join("\n"), /q: the quoted post \(context, never read\) is drawn at 1\.00× and 1\.00 strength/); // A carried parent: in full at the first frame, then given way -- the page as drawn never gives way. const own = narrate(base({ parents: [parentRef()] }), [[REPLY]]); const cp = postItemPlan(own, {}, { prev: { post: "acct-x/900" } }); const cg = fakeGeo(cp); const cpath = followPath(cp.follow, cg); assert.deepEqual(readInViewErrors(cp.follow, cg, shotStateAt(cp.follow, cpath, 30), { total: cp.total, id: "c" }), []); assert.match(readInViewErrors(cp.follow, cg, () => null, { total: cp.total, id: "c" }).join("\n"), /c: the post it answers \(parent:0\) \(carry, given way\)/); // A state that frames another place, or draws the tile being read small, is named. const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); const plan = postItemPlan(e, {}); const geo = fakeGeo(plan); const path = followPath(plan.follow, geo); const good = shotStateAt(plan.follow, path, 30); assert.deepEqual(readInViewErrors(plan.follow, geo, good, { total: plan.total, id: "t" }), []); const off = readInViewErrors(plan.follow, geo, (s) => ({ ...good(s), offset: -geo.H }), { total: plan.total, id: "t" }); assert.match(off.join("\n"), /t: part 1 \(the post it answers \(parent:0\), block 0\) is not in full view .* past the window's foot/); const small = readInViewErrors(plan.follow, geo, (s) => { const st = good(s); return { ...st, tiles: { ...st.tiles, post: [0.62, 0.5, st.tiles.post[2]] } }; }, { total: plan.total, id: "t" }); assert.match(small.join("\n"), /t: part 4 \(his post, block \d+\) .* his post is drawn at 0\.62× and 0\.50 strength/); // A plain post read in one block that fits: every frame the page as drawn -- no frames to shoot. const plain = narrate(base(), [[REPLY]]); const pp = postItemPlan({ ...plain, narration: { ...plain.narration, takes: [{ ...plain.narration.takes[0], parts: [{ ...plain.narration.takes[0].parts[0], text: REPLY }] }] } }, {}); const pgeo = { H: 520, C: 200, blocks: Object.fromEntries(pp.follow.blocks.map((b, i) => [b.k, { top: i * 90, bottom: i * 90 + 80 }])) }; const ppath = followPath(pp.follow, pgeo); assert.ok(followRuns(pp.follow, ppath, pp.total, 30).every((r) => isDrawnState(r.st))); assert.deepEqual(readInViewErrors(pp.follow, pgeo, () => null, { total: pp.total, id: "plain" }), []); assert.equal(isDrawnState(null), true); assert.equal(isDrawnState({ op: {}, offset: 0, fadeTop: 0, fadeBottom: 0, tiles: { post: [1, 1, 300] } }), true); assert.equal(isDrawnState({ op: {}, offset: 0, fadeTop: 0, fadeBottom: 0, tiles: { "parent:0": [0.62, 0.5, 300] } }), false); }); test("the card page: his post's excerpt dims the words it does not read in a thread read too (a post that quotes another: 6 Oct Leaflit card, 7 Nov)", () => { const read = "That is exactly what I was saying yesterday morning."; const e = narrate(base({ quoted: { author: "Other", handle: "other", text: QUOTED }, excerpt: [read] }), [[QUOTED], [read]]); const plan = postItemPlan(e, {}); const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow.thread }); assert.ok(html.includes('data-thread-slot="post"'), "drawn as a thread"); assert.match(html, /generator<\/span>/, "an unread word is dimmed"); assert.doesNotMatch(html, /]*class="xcut"[^>]*>yesterday<\/span>/, "a read word is not"); });