// A POST's SCREENS: TEXT SCREENSHOTS READ AS PART OF THE POST (umtool/docs/report-video.md, "Screens"; operator, 12 Nov // 2026, on quartering-diet rev9-a9: "the screenshots should be treated as extensions of the post rather than // transparent, probably read and probably with excerpts because it's long text. You can show it alongside the video in // the tweet slot as you read" -- "The 'read text screenshots as posts' ability in different variations should be first // class, it's a very common pattern"). // // A post item may carry SCREENS: the text screenshots that belong to the post -- a DM exchange or an email shown in its // video, an image attachment that is a screenshot of a chat, a letter, another post. Each is TRANSCRIBED once (data, a // person checks it), DRAWN legibly on the card as part of the post, and READ -- whole or in excerpts -- in the voices of // the people in it, each line lit while it is said. The standing rule holds: no hidden text is ever narrated, and every // read piece is on screen in full and lit while it is read (post-thread.mjs). // // screens: [{ id: "s1", media: 0, at: [3.5, 8], kind: "dm", title?, source?: "transcribed", checked?: { by, at }, // ref?: "/", unread?: "omit" | "dim", // lines: [{ who?, side?: "left" | "right", text, time?, redact?: true }], // read: "all" | "none" | [{ line, text? }], // lineTakes?: { "": "" }, saidAs?: { "": "" } }] // // - `media` names the attachment (an index into the item's `media`); `at` the source span a video or GIF shows it. // - `read`: every line ("all"), none ("none": transcribed only -- not drawn, not read), or the lines listed, each read // whole or an EXCERPT (`text`: a contiguous run of that line's words; drawn "…excerpt…", the cut sides marked). // - `unread`: the lines a read screen does not read are left out ("omit", the default: a "⋯" row where they were) or // drawn dim ("dim"). A line marked `redact: true` is never drawn nor read. // - THE SHAPES: an e-mail address, a phone number, a long run of digits, an order or confirmation number in a line are // MASKED (a bar on the card, never said) whether or not anyone marked them -- the lint says which line held one. // - `lineTakes`: the take the operator CHOSE for a line (a recording of it: `posts screen … record`, the bench's per-line // Record), by its id -- read in that line's place by every read of the item (postThreadRead.mjs); never chosen for // it by anything else. // - `saidAs` (lane line-rerun; operator ruling 3, 15 Nov 2026: every edit is for READING only): what the voice SAYS // for a read line, in place of its words -- an acronym spelled out, a typo said right. Never drawn: the card shows // the line as written. A line's identity (is a take still this line?) is its shown words, never what it is said as. // - `who`: a handle or a name; it is the post's author (her own lines, on the right), or another speaker, voiced through // the project's characters and the cast as a thread read's pieces are (post-say.mjs) and drawn under the item's // privacy rule (a subject, or `redact: false`, shown; else blurred), an anonymous one under its shown name. // // THE READ (lib/report/postThreadRead.mjs): each read line is a piece of the thread read, after the post's own words, in // the screens' order, its ROLE `screen::` (n the line's index). THE CARD (post-thread.mjs threadLayout): a screen // the take reads is a tile `screen:` after his post -- his post shrinks to a strip as it is revealed, it collapses as // the next comes in. THE MEDIA (post-item.mjs planOf): while a screen is read the slot plays its span, its last frame held. // // PURE and dependency-free but for its siblings. import { REDACT_MARK, dropMarks, redactText } from "./post-redact.mjs"; import { handleKey } from "./post-say.mjs"; export const SCREEN_KINDS = Object.freeze(["dm", "email", "post", "text"]); export const SCREEN_SIDES = Object.freeze(["left", "right"]); export const SCREEN_UNREAD = Object.freeze(["omit", "dim"]); export const SCREEN_ID_RE = /^[a-z0-9][a-z0-9-]{0,23}$/; export const SCREENS_MAX = 8; export const SCREEN_LINES_MAX = 60; export const SCREEN_LINE_MAX = 600; export const SCREEN_TITLE_MAX = 80; export const SCREEN_WHO_MAX = 64; export const SCREEN_TIME_MAX = 24; /** The least span (s) a screen may name in a video. */ export const SCREEN_MIN_SPAN = 0.5; /** The pause between two lines of one screen in a joined read (a new piece is POST_PART_GAP.piece). */ export const SCREEN_LINE_GAP = 0.35; /** The drawing's version: a change to how a screen is drawn rebuilds the segments that draw one (post-render.mjs). */ export const POST_SCREEN_DRAW_V = 1; /** A screen line's role: `screen::`. */ export const SCREEN_ROLE_RE = /^screen:([a-z0-9][a-z0-9-]{0,23}):(\d{1,2})$/; const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); /** A take's id (post-narration.mjs takeIdOf: its file's name without .wav -- not imported: that module imports this one's). */ const takeIdOfFile = (t) => String(t?.file ?? "").split("/").pop().replace(/\.wav$/i, ""); const fin = (v) => typeof v === "number" && Number.isFinite(v); const str = (v) => (typeof v === "string" ? v : ""); const r3 = (v) => Math.round(v * 1000) / 1000; /** A line's role. */ export const screenRole = (id, n) => `screen:${id}:${n}`; /** A screen's tile scope on the card. */ export const screenScope = (id) => `screen:${id}`; /** A role's screen and line, or null when it is not a screen line's. */ export function parseScreenRole(role) { const m = SCREEN_ROLE_RE.exec(str(role)); return m ? { id: m[1], n: Number(m[2]) } : null; } /** Whether a scope or role is a screen's. */ export const isScreenScope = (s) => str(s).startsWith("screen:"); /** The TILE a role is read on: a screen line's is its screen's; any other role is its own. */ export const tileOfRole = (role) => { const p = parseScreenRole(role); return p ? screenScope(p.id) : role; }; /** An item's screens as drawn and read (each an object with an id and lines); [] when it has none. */ export const screensOf = (entry) => Array.isArray(entry?.screens) ? entry.screens.filter((s) => isObj(s) && SCREEN_ID_RE.test(str(s.id)) && Array.isArray(s.lines)).slice(0, SCREENS_MAX) : []; /** Whether an item carries screens. */ export const hasScreens = (entry) => screensOf(entry).length > 0; /** One screen by id. */ export const screenOf = (entry, id) => screensOf(entry).find((s) => s.id === id) ?? null; // --------------------------------------------------------------------------- // THE SHAPES: what is never typeset nor read, marked or not. // --------------------------------------------------------------------------- // Letters and digits of any script (`u`): "jöhn.doe@exämple.com", fullwidth digits "555". const EMAIL_RE = /[\p{L}\p{N}._%+-]+[@@](?:[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+|[\p{L}\p{N}-]{2,})/gu; const SPOKEN_EMAIL_RE = /[\p{L}\p{N}._-]+ (?:at) [\p{L}\p{N}-]+ (?:dot) (?:com|net|org|co|uk|io|me|us|edu|gov|ca|de|fr|au)\b/giu; /** A PHONE-STYLE RUN: digits joined by spaces, dashes, dots, middle dots, slashes or brackets (at most three between). */ const RUN_RE = /[+(]?\p{Nd}(?:[ \t\-‐‑–—·./()]{0,3}\p{Nd})*/gu; /** A decimal (an amount, a weight: "99.95", "312.4") -- never part of a run. */ const DECIMAL_RE = /\p{Nd}+[.,]\p{Nd}{1,2}(?!\p{Nd})/gu; /** * A PLAUSIBLE date -- shown: a year of 19xx / 20xx first with a month and a day after it (2026-11-02), or a month and a * day (either order) then a two-digit or a 19xx / 20xx year (11/02/2026, 02.11.26). A 3-2-4 group (an SSN) is never one. */ const DATE_SHAPE = /^(\p{Nd}{1,4})[/.\-‐‑–—](\p{Nd}{1,2})[/.\-‐‑–—](\p{Nd}{1,4})$/u; const isDate = (v) => { const m = DATE_SHAPE.exec(str(v).replace(/\p{Nd}/gu, (d) => String(Number.parseInt(d.normalize("NFKC"), 10)))); if (!m) return false; const [a, b, c] = [m[1], m[2], m[3]]; const year4 = (y) => /^(19|20)\d\d$/.test(y); const md = (x, y) => (Number(x) >= 1 && Number(x) <= 12 && Number(y) >= 1 && Number(y) <= 31) || (Number(y) >= 1 && Number(y) <= 12 && Number(x) >= 1 && Number(x) <= 31); if (year4(a)) return Number(b) >= 1 && Number(b) <= 12 && Number(c) >= 1 && Number(c) <= 31 && c.length <= 2; return a.length <= 2 && b.length <= 2 && (c.length === 2 || year4(c)) && md(a, b); }; /** Case-insensitive by letters (the `i` flag would make the IBAN's \p{Lu} match any letter). */ const ci = (w) => w.replace(/[a-z]/g, (c) => `[${c}${c.toUpperCase()}]`); const KEYWORDS = "order|confirmation|conf|invoice|tracking|reference|ref|account|acct|card|iban|ssn|social security|security code|code|pin|passcode|routing|member|customer|ticket|receipt|transaction|policy|booking|reservation|serial|cvv|cvc|exp|expiry|expires|dob|date of birth|born|birthday|id".split("|").map(ci).join("|"); const GROUP = String.raw`[#]?[\p{L}\p{N}\-/.]*\p{Nd}[\p{L}\p{N}\-/.]*`; /** A keyword, "number" / "no." / "#", "is" / ":" / "ending in", then its value: groups with digits (an IBAN's capitals between them). */ const ORDER_RE = new RegExp(String.raw`(? (str(t).match(/\p{Nd}/gu) ?? []).length; const SHAPE_CACHE = new Map(); /** * THE SHAPES in a line, pure: `[{ start, end, kind }]` -- what is never drawn nor said, marked or not: * "email" an e-mail address (any script; with or without its domain's ending), or one spelt out ("x at y dot com") * "number" a phone-style run of nine digits or more (a card, an IBAN's digits, a phone, a spaced SSN), a local number * (555 1234), a token of six digits or more -- never an amount ($104.90, 1,000,000), a decimal, a DATE * (11/02/2026, 2026-11-02) or a time * "order" the value after order / confirmation / tracking / reference / account / card / code … ("is", ":", "#", * "ending in" between), or a "#1234" * Merged, in order. Linear in the line (one pass a pattern). */ export function shapeSpans(text) { const t = str(text); if (!t) return []; const hit = SHAPE_CACHE.get(t); if (hit) return hit.map((x) => ({ ...x })); const out = []; for (const m of t.matchAll(EMAIL_RE)) { // "@handle" alone is a mention (a local part is needed); a trailing dot is the sentence's. const v = m[0].replace(/[.\-]+$/, ""); if (/^[@@]/.test(v)) continue; out.push({ start: m.index, end: m.index + v.length, kind: "email" }); } for (const m of t.matchAll(SPOKEN_EMAIL_RE)) out.push({ start: m.index, end: m.index + m[0].length, kind: "email" }); // Runs, a free-standing decimal blanked first (a list of weights is not a phone number) -- never one that touches a // run's separator or another digit ("555 201-44.77", "078.05.1120": those are the run). const blank = t.replace(DECIMAL_RE, (d, at) => (/[\-‐‑–—·./()\p{Nd}]/u.test(t[at - 1] ?? "") || /[\-‐‑–—·./()\p{Nd}]/u.test(t[at + d.length] ?? "") ? d : "x".repeat(d.length))); for (const m of blank.matchAll(RUN_RE)) { const v = m[0].replace(/[ \t\-‐‑–—·./(]+$/, ""); const n = digitsIn(v); if (n < 7 || isDate(v.replace(/^[+(]/, ""))) continue; const local = n <= 8 && /^\p{Nd}{3}[ \t\-‐‑–—·.]{1,3}\p{Nd}{4}$/u.test(v); if (n >= 9 || local) out.push({ start: m.index, end: m.index + v.length, kind: "number" }); } for (const m of t.matchAll(ORDER_RE)) { const v = m[1].replace(/[.\-]+$/, ""); if (digitsIn(v) < 3) continue; const at = m.index + m[0].length - m[1].length; out.push({ start: at, end: at + v.length, kind: "order" }); } for (const m of t.matchAll(HASHNUM_RE)) out.push({ start: m.index, end: m.index + m[0].length, kind: "order" }); for (const m of t.matchAll(TOKEN_RE)) { const tok = m[0]; if (digitsIn(tok) < 6 || AMOUNT_RE.test(tok)) continue; const lead = tok.match(/^[("'“[]*/)[0].length; const trail = tok.match(/[)"'”\].,;:!?]*$/)[0].length; const core = tok.slice(lead, tok.length - trail); if (isDate(core) || /^\p{Nd}{1,2}:\p{Nd}{2}(?::\p{Nd}{2})?$/u.test(core)) continue; out.push({ start: m.index + lead, end: m.index + tok.length - trail, kind: "number" }); } out.sort((a, b) => a.start - b.start || b.end - a.end); const merged = []; for (const sp of out) { if (sp.end <= sp.start) continue; const last = merged[merged.length - 1]; if (last && sp.start <= last.end) last.end = Math.max(last.end, sp.end); else merged.push({ ...sp }); } if (SHAPE_CACHE.size > 20000) SHAPE_CACHE.clear(); SHAPE_CACHE.set(t, merged.map((x) => ({ ...x }))); return merged; } /** A line's words with its shapes MASKED (the redaction's marks: drawn as bars, dropped when said), and what was masked. */ export function maskShapes(text) { const spans = shapeSpans(text); if (!spans.length) return { text: str(text), kinds: [] }; return { text: redactText(str(text), [], { spans }).text, kinds: [...new Set(spans.map((s) => s.kind))] }; } /** A short field (a title, a speaker, a time) as drawn: its shapes masked. */ export const maskedField = (v) => maskShapes(str(v)).text; // --------------------------------------------------------------------------- // WHAT IS READ AND WHAT IS DRAWN of a screen. // --------------------------------------------------------------------------- const words = (t) => [...str(t).matchAll(/\S+/g)].map((m) => ({ w: m[0], start: m.index, end: m.index + m[0].length })); const wkey = (w) => w.toLowerCase().replace(/^[^\p{L}\p{N}$#@]+|[^\p{L}\p{N}%]+$/gu, ""); /** * Where an EXCERPT stands in its line, pure: `{ start, end }` (character offsets of the line's own words it names, a * contiguous run; their edge punctuation need not match) -- or null when it is not a run of the line's words. */ export function excerptRun(line, excerpt) { const L = words(line); const E = words(excerpt).map((x) => wkey(x.w)); if (!E.length || E.length > L.length) return null; const keys = L.map((x) => wkey(x.w)); for (let i = 0; i + E.length <= L.length; i += 1) { let ok = true; for (let j = 0; j < E.length; j += 1) { if (keys[i + j] !== E[j]) { ok = false; break; } } if (ok) return { start: L[i].start, end: L[i + E.length - 1].end }; } return null; } /** Whether a line can be read or drawn at all: not marked redact, with words. */ const lineOk = (l) => isObj(l) && l.redact !== true && !!str(l.text).trim(); /** One screen worked out once (memoized by the screen object and what it holds): its read lines, its broken excerpts. */ const VIEWS = new WeakMap(); function viewOf(screen) { if (!isObj(screen)) return { reads: [], broken: [] }; const lines = Array.isArray(screen.lines) ? screen.lines : []; const key = JSON.stringify([screen.read, lines, isObj(screen.saidAs) ? screen.saidAs : null]); const had = VIEWS.get(screen); if (had && had.key === key) return had; const r = screen.read; const asked = r === "all" ? lines.map((_, n) => ({ line: n })) : Array.isArray(r) ? r.filter((x) => isObj(x) && Number.isInteger(x.line)) : []; const seen = new Set(); const reads = []; const broken = []; for (const x of asked) { const l = lines[x.line]; if (!lineOk(l) || seen.has(x.line)) continue; seen.add(x.line); const t = str(l.text); const all = { start: t.search(/\S/), end: t.trimEnd().length }; let span = all; if (str(x.text).trim()) { const run = excerptRun(t, x.text); // An excerpt that is not in the line (as drawn: after the redaction or anonymity passes) is NEVER read or drawn // whole: the line is left out, and the build is told (screenDrawErrors). if (!run) { broken.push(x.line); continue; } span = run; } const masked = maskShapes(t).text; const cut = masked.slice(span.start, span.end); const said = cut.includes(REDACT_MARK) ? dropMarks(cut) : cut.trim(); const as = saidAsOf(screen, x.line); reads.push({ n: x.line, start: span.start, end: span.end, cutBefore: span.start > all.start, cutAfter: span.end < all.end, said, shown: cut, spoken: as ?? said }); } reads.sort((a, b) => a.n - b.n); const v = { key, reads, broken }; VIEWS.set(screen, v); return v; } /** * A screen's READ LINES, pure, in the line order: `[{ n, start, end, cutBefore, cutAfter }]` -- each line read, the * run of its words read (the whole line, or its excerpt), and whether words were cut before or after it. "none", a * redacted line, a line with no words, or an EXCERPT NOT IN ITS LINE: none (never the whole line instead). */ export function screenReadLines(screen) { return viewOf(screen).reads.map(({ said: _s, shown: _w, spoken: _p, ...r }) => r); } /** A line's "said as" (`saidAs`), trimmed, or null when it has none. */ export function saidAsOf(screen, n) { const v = isObj(screen?.saidAs) ? screen.saidAs[String(n)] : undefined; return typeof v === "string" && v.trim() ? v.trim() : null; } /** The screens the DATA says are read (a read line or more), in order. */ export const readScreens = (entry) => screensOf(entry).filter((s) => viewOf(s).reads.length > 0); /** * A read line's words as SHOWN, ready to be said (before the thread read's spokenRead): its read run, its shapes left * out ("" when not read). The line's identity -- a take is this line's while it said these -- never its "said as". */ export function screenLineSaid(screen, n) { return viewOf(screen).reads.find((x) => x.n === n)?.said ?? ""; } /** What the voice SAYS for a read line: its "said as" (`saidAs`), else screenLineSaid ("" when not read). */ export function screenLineSpoken(screen, n) { return viewOf(screen).reads.find((x) => x.n === n)?.spoken ?? ""; } /** * A screen with lines `drops` (their indices) REMOVED, pure (a copy): its read follows them -- a removed line's read * goes, the later lines' numbers move down (the CLI's `line.=off`, the post bench's ×: one rule). A read the take * already made is then held to the lines as they are (post-thread.mjs screenLineChanged). */ export function withoutLines(screen, drops) { const gone = new Set(drops); const to = (n) => n - [...gone].filter((d) => d < n).length; const out = { ...screen, lines: (Array.isArray(screen?.lines) ? screen.lines : []).filter((_, n) => !gone.has(n)) }; if (Array.isArray(screen?.read)) out.read = screen.read.filter((x) => !gone.has(x?.line)).map((x) => ({ ...x, line: to(x.line) })); // The takes chosen for its lines follow them too: a removed line's choice goes, the later ones' keys move down. if (isObj(screen?.lineTakes)) { const lt = Object.fromEntries(Object.entries(screen.lineTakes).filter(([k]) => /^\d{1,2}$/.test(k) && !gone.has(Number(k))).map(([k, v]) => [String(to(Number(k))), v])); if (Object.keys(lt).length) out.lineTakes = lt; else delete out.lineTakes; } // So do their "said as" (saidAs): a removed line's goes, the later ones' keys move down. if (isObj(screen?.saidAs)) { const sa = Object.fromEntries(Object.entries(screen.saidAs).filter(([k]) => /^\d{1,2}$/.test(k) && !gone.has(Number(k))).map(([k, v]) => [String(to(Number(k))), v])); if (Object.keys(sa).length) out.saidAs = sa; else delete out.saidAs; } return out; } /** Every reason the screens AS DRAWN (after the redaction and anonymity passes) cannot be drawn as the operator chose. */ export function screenDrawErrors(entry) { const out = []; for (const sc of screensOf(entry)) for (const n of viewOf(sc).broken) out.push(`timeline ${entry?.id ?? "?"}: line ${n} of screen ${sc.id}: its excerpt is not in the line as drawn -- the line is left out (fix the excerpt: umtool posts screen

${entry?.id ?? ""} set ${sc.id} read.${n}=…)`); return out; } /** * A screen's DRAWN ROWS, pure: `[{ n, text, read, cutBefore, cutAfter } | { gap: true, lines }]` -- each line drawn * (masked; a read excerpt alone, its cut sides marked "…"), whether it is read; the lines not read left out (a gap row * where they were) under `unread: "omit"`, drawn dim under "dim". A redacted line is never drawn (a gap row under omit); * nor is a line whose excerpt is broken (screenDrawErrors). */ export function screenRows(screen) { const lines = Array.isArray(screen?.lines) ? screen.lines : []; const v = viewOf(screen); const reads = new Map(v.reads.map((r) => [r.n, r])); const broken = new Set(v.broken); const dim = screen?.unread === "dim"; const out = []; let gap = 0; const flush = () => { if (gap && out.length) out.push({ gap: true, lines: gap }); gap = 0; }; lines.forEach((l, n) => { const r = reads.get(n); if (!r && !(dim && lineOk(l) && !broken.has(n))) { gap += 1; return; } flush(); out.push({ n, text: r ? r.shown : maskShapes(str(l.text)).text.trim(), read: !!r, cutBefore: !!r?.cutBefore, cutAfter: !!r?.cutAfter }); }); // A gap after the last row drawn: the screen goes on past what is shown. if (gap && out.length) out.push({ gap: true, lines: gap }); return out; } /** Whether a screen's drawing leaves anything of it out (a line, or words of one): its header says "excerpt". */ export const screenIsExcerpt = (screen) => screenRows(screen).some((r) => r.gap || r.cutBefore || r.cutAfter); // --------------------------------------------------------------------------- // WHO SAYS IT. // --------------------------------------------------------------------------- /** * WHO a line is, pure: `{ self, handle, name }` -- `self` when it is the post's author (by handle or by name), else the * handle it resolves to: written as a handle, or a character's name (`names`: lower-case name -> handle, the project's * characters and the cast's) resolved to its handle; `name` as written. An empty `who`: the author's when the screen's * kind is a letter, none else. * * @param {string | undefined} who * @param {{ handle?: string, author?: string }} entry * @param {Record | Map} [names] */ export function screenWho(who, entry, names = {}) { const w = str(who).trim(); const key = handleKey(w); const self = !!w && ((!!key && key === handleKey(entry?.handle)) || w.toLowerCase() === str(entry?.author).trim().toLowerCase()); if (!w) return { self: false, handle: null, name: "" }; if (self) return { self: true, handle: str(entry?.handle).replace(/^@/, "") || null, name: w }; const byName = names instanceof Map ? names.get(w.toLowerCase()) : names?.[w.toLowerCase()]; if (byName) return { self: false, handle: str(byName).replace(/^@/, ""), name: w }; return { self: false, handle: /^@?[A-Za-z0-9_]{1,30}$/.test(w) ? w.replace(/^@/, "") : null, name: w }; } /** The side a line is drawn on: its own `side`, else the author's lines on the right and the others on the left. */ export const screenSide = (line, entry) => (SCREEN_SIDES.includes(line?.side) ? line.side : screenWho(line?.who, entry).self ? "right" : "left"); // --------------------------------------------------------------------------- // A LINE TYPED OR PASTED (the CLI's --from text, the post bench's paste box: one rule). // --------------------------------------------------------------------------- /** One line of TEXT as a screen line: `[right] who: words | time`, `- words`, `[redact] …`. Null: a blank line. */ export function lineOfText(raw) { let t = String(raw).trim(); if (!t) return null; const out = {}; for (;;) { const m = /^\[(left|right|redact)\]\s*/i.exec(t); if (!m) break; if (m[1].toLowerCase() === "redact") out.redact = true; else out.side = m[1].toLowerCase(); t = t.slice(m[0].length); } const bar = t.lastIndexOf(" | "); if (bar > 0) { out.time = t.slice(bar + 3).trim(); t = t.slice(0, bar).trim(); } if (t.startsWith("- ")) t = t.slice(2); else { const c = /^([^:]{1,64}?):\s+(.*)$/s.exec(t); // NEVER a shape split into a speaker ("Order number: 4419", "Ref: AB-1234", "savvy@x.com: hi"): a "speaker" with a // digit, an @, a shape keyword, or a shape of the whole line that reaches into it stays part of the line's words. const keyword = new RegExp(`^(?:${KEYWORDS}|${["phone", "tel", "mobile", "cell", "fax", "email", "e-mail", "address", "zip", "postcode", "number", "no"].map(ci).join("|")})(?![\\p{L}\\p{N}])`, "u"); const splits = !!c && !/^https?$/i.test(c[1]) && !/[\p{Nd}@@#]/u.test(c[1]) && !keyword.test(c[1].trim()) && !shapeSpans(t).some((sp) => sp.start < c[1].length + 1); if (c && splits) { out.who = c[1].trim(); t = c[2]; } } return { ...(out.who ? { who: out.who } : {}), ...(out.side ? { side: out.side } : {}), text: t.trim(), ...(out.time ? { time: out.time } : {}), ...(out.redact ? { redact: true } : {}) }; } /** Orpheus's expressive tags (the editor's TTS_EXPRESSIVE_TAGS): how a script is read, never the picture's words. Any other `<…>` is words. */ const SCRIPT_TAG_RE = /<(?:laugh|chuckle|sigh|cough|sniffle|groan|yawn|gasp)>/g; /** * A PICTURE-ONLY post's READ as a screen's LINES, pure (`posts screen … add --from-read`, the post bench's "From its * read": one rule): its script (`narration.script`, the words on the picture as the operator wrote them to be read) a * line per line of it -- blank lines dropped, its emotion tags left out, a line longer than a screen line split at its * sentence ends (then at a space) -- each `{ text }` alone: a "who:" is NEVER parsed out of a read (a shape or a * heading would become a speaker: "Order number: 4419"); the speakers are the operator's to set. Throws when it holds * no words or more lines than a screen takes. * * @param {string} script * @returns {Array<{ text: string }>} */ export function linesOfRead(script) { const out = []; const push = (t) => { const v = t.replace(/\s+/g, " ").trim(); if (v) out.push({ text: v }); }; for (const raw of str(script).replace(SCRIPT_TAG_RE, " ").split(/\r?\n/)) { let t = raw.replace(/\s+/g, " ").trim(); while (t.length > SCREEN_LINE_MAX) { const head = t.slice(0, SCREEN_LINE_MAX + 1); const ends = [...head.matchAll(/[.!?…]["')\]”’]*\s/g)].map((m) => m.index + m[0].length).filter((i) => i <= SCREEN_LINE_MAX); const sp = head.lastIndexOf(" "); const cut = ends.length ? ends[ends.length - 1] : sp > 0 ? sp + 1 : SCREEN_LINE_MAX; push(t.slice(0, cut)); t = t.slice(cut).trim(); } push(t); } if (!out.length) throw new Error("its read has no words to make lines of (narration.script is empty)"); if (out.length > SCREEN_LINES_MAX) throw new Error(`its read is ${out.length} lines -- a screen takes at most ${SCREEN_LINES_MAX}: shorten the script, or add the screen's lines by hand`); return out; } /** * A SCREEN MADE FROM A PICTURE-ONLY POST's READ, pure: `{ screen }` -- on its picture (`media`: the index given, else * its first image, else its first attachment), `kind` (default "text"), its lines linesOfRead's, read whole, NOT * checked (the lint says so until a person reads it against the picture) -- or `{ error }`: not picture-only * (`pictureOnly`: the caller's post-item.mjs ownPictureOnly), no script, no attachment, a kind or an index wrong. * * @param {Record} e * @param {{ pictureOnly: boolean, id: string, media?: number | null, kind?: string | null }} o */ export function screenFromRead(e, { pictureOnly, id, media = null, kind = null }) { if (!pictureOnly) return { error: `${e?.id ?? "the item"} is not a picture-only post: --from-read makes a screen of a picture-only post's read (its words on the picture); type or paste this one's lines (--from , --line)` }; const list = Array.isArray(e?.media) ? e.media : []; if (!list.length) return { error: `${e?.id ?? "the item"} has no attachment for the screen to be in` }; const at = media !== null && media !== undefined ? media : Math.max(0, list.findIndex((m) => m?.kind === "image")); if (!Number.isInteger(at) || !isObj(list[at])) return { error: `--media ${media}: ${e?.id} has attachments 0–${list.length - 1}` }; const k = kind ?? "text"; if (!SCREEN_KINDS.includes(k)) return { error: `--kind takes ${SCREEN_KINDS.join(", ")}` }; let lines; try { lines = linesOfRead(str(e?.narration?.script)); } catch (err) { return { error: `${e?.id}: ${err instanceof Error ? err.message : err}` }; } // A GIF's or a video's: visible its whole length (the picture stays in its card), when its length is known. const m = list[at]; const timed = m.kind === "video" || m.kind === "gif"; if (timed && !(fin(m.seconds) && m.seconds >= SCREEN_MIN_SPAN)) return { error: `attachment ${at} is a ${m.kind} of no known length: add the screen with --at ,` }; return { screen: { id, media: at, ...(timed ? { at: [0, r3(m.seconds)] } : {}), kind: k, source: "read", lines, read: "all" } }; } // --------------------------------------------------------------------------- // THE VALIDATION. // --------------------------------------------------------------------------- /** Every reason an item's `screens` cannot be drawn or read (validatePostItem). */ export function validateScreens(e) { const s = e?.screens; if (s === undefined) return []; const w = `timeline ${e?.id ?? "?"}.screens`; if (!Array.isArray(s)) return [`${w} must be a list of the text screenshots the post carries`]; const errors = []; if (s.length > SCREENS_MAX) errors.push(`${w}: at most ${SCREENS_MAX} screens`); const media = Array.isArray(e?.media) ? e.media : []; const ids = new Set(); s.forEach((sc, i) => { const at = `${w}[${i}]`; if (!isObj(sc)) { errors.push(`${at} must be an object`); return; } const known = new Set(["id", "media", "at", "kind", "title", "source", "checked", "ref", "unread", "lines", "read", "lineTakes", "saidAs"]); for (const k of Object.keys(sc)) if (!known.has(k)) errors.push(`${at}.${k} is not a screen's field (${[...known].join(", ")})`); if (!SCREEN_ID_RE.test(str(sc.id))) errors.push(`${at}.id must be a short name (lower-case letters, digits, -)`); else if (ids.has(sc.id)) errors.push(`${at}.id "${sc.id}" is the id of another screen of the item`); else ids.add(sc.id); const m = Number.isInteger(sc.media) ? media[sc.media] : undefined; if (!Number.isInteger(sc.media) || !isObj(m)) errors.push(`${at}.media must be the index of the attachment it is in (0–${Math.max(0, media.length - 1)}${media.length ? "" : ": the item has none"})`); const timed = m?.kind === "video" || m?.kind === "gif"; if (sc.at !== undefined) { if (m && !timed) errors.push(`${at}.at: only a video or a GIF has a span (attachment ${sc.media} is ${m.kind === "image" ? "an image" : m.kind})`); else if (!(Array.isArray(sc.at) && sc.at.length === 2 && sc.at.every((v) => fin(v) && v >= 0) && sc.at[1] - sc.at[0] >= SCREEN_MIN_SPAN - 1e-9 && (!fin(m?.seconds) || sc.at[1] <= m.seconds + 0.05))) { errors.push(`${at}.at must be [from, to], the seconds of attachment ${sc.media} it is visible in (at least ${SCREEN_MIN_SPAN} s${fin(m?.seconds) ? `, inside 0–${m.seconds}` : ""})`); } } else if (timed) errors.push(`${at}.at must be [from, to]: the seconds of the ${m.kind} it is visible in`); if (!SCREEN_KINDS.includes(sc.kind)) errors.push(`${at}.kind must be one of ${SCREEN_KINDS.join(", ")}`); if (sc.title !== undefined && !(typeof sc.title === "string" && sc.title.trim() && sc.title.length <= SCREEN_TITLE_MAX)) errors.push(`${at}.title must be words (at most ${SCREEN_TITLE_MAX} characters)`); // "read": made from a picture-only post's read (--from-read) -- its lines ARE the post's read (postThreadRead.mjs). if (sc.source !== undefined && sc.source !== "transcribed" && sc.source !== "read") errors.push(`${at}.source must be "transcribed" or "read" (made from its read)`); if (sc.checked !== undefined && !(isObj(sc.checked) && typeof sc.checked.by === "string" && sc.checked.by.trim() && sc.checked.by.length <= 40 && typeof sc.checked.at === "string" && !Number.isNaN(Date.parse(sc.checked.at)))) { errors.push(`${at}.checked must be { by, at }: who checked the transcription and when (ISO)`); } if (sc.ref !== undefined && !(sc.kind === "post" && typeof sc.ref === "string" && /^[A-Za-z0-9._-]+\/[A-Za-z0-9_-]+$/.test(sc.ref))) errors.push(`${at}.ref must be / (a screenshot of a post only)`); if (sc.unread !== undefined && !SCREEN_UNREAD.includes(sc.unread)) errors.push(`${at}.unread must be ${SCREEN_UNREAD.join(" or ")}`); const lines = Array.isArray(sc.lines) ? sc.lines : null; if (!lines || !lines.length) errors.push(`${at}.lines must be the transcription: a list of { who?, side?, text, time?, redact? }`); else { if (lines.length > SCREEN_LINES_MAX) errors.push(`${at}.lines: at most ${SCREEN_LINES_MAX}`); lines.forEach((l, n) => { const lw = `${at}.lines[${n}]`; if (!isObj(l)) { errors.push(`${lw} must be { who?, side?, text, time?, redact? }`); return; } for (const k of Object.keys(l)) if (!["who", "side", "text", "time", "redact", "anonymous"].includes(k)) errors.push(`${lw}.${k} is not a line's field (who, side, text, time, redact)`); if (l.anonymous !== undefined && l.anonymous !== true) errors.push(`${lw}.anonymous is the anonymising pass's own flag (true, or absent)`); if (typeof l.text !== "string" || l.text.length > SCREEN_LINE_MAX) errors.push(`${lw}.text must be the line's words (at most ${SCREEN_LINE_MAX} characters)`); else if (!l.text.trim() && l.redact !== true) errors.push(`${lw}.text is empty (a line with no words: remove it, or mark it redact)`); if (l.who !== undefined && !(typeof l.who === "string" && l.who.trim() && l.who.length <= SCREEN_WHO_MAX)) errors.push(`${lw}.who must be a handle or a name`); if (l.side !== undefined && !SCREEN_SIDES.includes(l.side)) errors.push(`${lw}.side must be left or right`); if (l.time !== undefined && !(typeof l.time === "string" && l.time.length <= SCREEN_TIME_MAX)) errors.push(`${lw}.time must be the time shown (at most ${SCREEN_TIME_MAX} characters)`); if (l.redact !== undefined && l.redact !== true) errors.push(`${lw}.redact must be true (or absent)`); }); } // The takes CHOSEN for its lines (a recording of each): a line it has, a take of the item that is a recording of it. if (sc.lineTakes !== undefined) { const lt = sc.lineTakes; const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : []; if (!isObj(lt) || Object.keys(lt).length > SCREEN_LINES_MAX) errors.push(`${at}.lineTakes must be { "": "" } (the take chosen for each line)`); else for (const [k, v] of Object.entries(lt)) { const n = /^\d{1,2}$/.test(k) ? Number(k) : -1; if (n < 0 || !isObj(lines?.[n])) errors.push(`${at}.lineTakes.${k}: the screen has no line ${k}`); else if (lines[n].redact === true) errors.push(`${at}.lineTakes.${k}: line ${k} is redacted -- it is never read`); const t = typeof v === "string" ? takes.find((x) => takeIdOfFile(x) === v) : null; if (!t) errors.push(`${at}.lineTakes.${k} must be the id of one of the item's takes (a recording of line ${k})`); // A recording of a line of THIS screen; whether it says this line as it is now is the read's to judge (by its // words and speaker, not its index: a line removed above it moves the choice, not the take). else if (!isObj(t.screenLine) || t.screenLine.screen !== sc.id) errors.push(`${at}.lineTakes.${k}: take ${takes.indexOf(t) + 1} is not a recording of a line of screen ${sc.id}${isObj(t.screenLine) ? ` (it is of screen ${t.screenLine.screen})` : ""}`); } } // What a line is SAID AS (never drawn): a line it has, not redacted, words -- and no shape (an e-mail, a number the // card would mask is never said, however it is typed). if (sc.saidAs !== undefined) { const sa = sc.saidAs; if (!isObj(sa) || Object.keys(sa).length > SCREEN_LINES_MAX) errors.push(`${at}.saidAs must be { "": "" }`); else for (const [k, v] of Object.entries(sa)) { const n = /^\d{1,2}$/.test(k) ? Number(k) : -1; if (n < 0 || !isObj(lines?.[n])) errors.push(`${at}.saidAs.${k}: the screen has no line ${k}`); else if (lines[n].redact === true) errors.push(`${at}.saidAs.${k}: line ${k} is redacted -- it is never read`); if (typeof v !== "string" || !v.trim() || v.length > SCREEN_LINE_MAX) errors.push(`${at}.saidAs.${k} must be words (at most ${SCREEN_LINE_MAX} characters)`); else if (shapeSpans(v).length) errors.push(`${at}.saidAs.${k} says ${shapeSpans(v)[0].kind === "email" ? "an e-mail address" : "a number"} the card would mask -- a read never says one: say it another way`); } } const r = sc.read; if (r === "all" || r === "none") return; if (!Array.isArray(r)) { errors.push(`${at}.read must be "all", "none" or a list of { line, text? }`); return; } const lines2 = lines ?? []; const seen = new Set(); r.forEach((x, j) => { const rw = `${at}.read[${j}]`; if (!isObj(x) || !Number.isInteger(x.line) || !isObj(lines2[x.line])) { errors.push(`${rw} must be { line, text? } naming a line (0–${Math.max(0, lines2.length - 1)})`); return; } if (seen.has(x.line)) errors.push(`${rw}: line ${x.line} is read twice`); seen.add(x.line); if (lines2[x.line].redact === true) errors.push(`${rw}: line ${x.line} is redacted -- it is never read`); if (x.text !== undefined) { if (typeof x.text !== "string" || !x.text.trim()) errors.push(`${rw}.text must be the words of the line to read (an excerpt)`); else if (!excerptRun(str(lines2[x.line].text), x.text)) errors.push(`${rw}.text is not a run of line ${x.line}'s words (an excerpt is the line's own words, in a row)`); } for (const k of Object.keys(x)) if (!["line", "text"].includes(k)) errors.push(`${rw}.${k} is not a read's field (line, text)`); }); }); return errors; } /** * A screen line the take reads, checked against the data: null when it is drawn and read, else why not (the guard, * post-thread.mjs threadReadErrors). */ export function screenLineProblem(entry, role) { const p = parseScreenRole(role); if (!p) return "not a screen line"; const sc = screenOf(entry, p.id); if (!sc) return `screen ${p.id}, which the item does not carry`; const l = sc.lines[p.n]; if (!isObj(l)) return `line ${p.n} of screen ${p.id}, which it does not have`; if (l.redact === true) return `line ${p.n} of screen ${p.id}, which is redacted (never drawn)`; if (!screenReadLines(sc).some((r) => r.n === p.n)) return `line ${p.n} of screen ${p.id}, which the screen does not read (${sc.read === "none" ? 'read: "none" -- not drawn' : sc.unread === "dim" ? "drawn dim, never lit" : "left out of the card"})`; return null; } // --------------------------------------------------------------------------- // THE PIECES a read reads (post-thread.mjs chronoPieces): after the post's own words. // --------------------------------------------------------------------------- /** Each read line of the item's read screens, in order: `[{ role, who, text }]` (`text` what it says). */ export function screenPieces(entry) { const out = []; for (const sc of readScreens(entry)) { for (const r of screenReadLines(sc)) { const text = screenLineSaid(sc, r.n); // `spoken`: its "said as" (saidAs), only when it has one -- `text` stays the line as shown (its identity). const as = saidAsOf(sc, r.n); if (text.trim()) out.push({ role: screenRole(sc.id, r.n), who: str(sc.lines[r.n].who) || null, text, screen: sc.id, ...(as ? { spoken: as } : {}) }); } } return out; } /** The read's order of a screen role: after every other text, by its screen's place and its line (null: not one). */ export function screenOrder(entry, role) { const p = parseScreenRole(role); if (!p) return null; const at = screensOf(entry).findIndex((s) => s.id === p.id); return 100 + Math.max(0, at) + p.n / 1000; } // --------------------------------------------------------------------------- // THE MEDIA: what the slot plays while a screen is read (post-item.mjs planOf). // --------------------------------------------------------------------------- /** * WHEN EACH SCREEN IS UP, pure: `[{ id, media, t0 }]` -- each screen tile of the plan's thread from its first read * line's start less the pan's lead (`lead`), in order. Empty: none read. */ export function screenShows(entry, follow, { lead = 0.4 } = {}) { const tiles = (follow?.thread?.tiles ?? []).filter((t) => isScreenScope(t.scope)); const out = []; for (const t of tiles) { const id = t.scope.slice(7); const sc = screenOf(entry, id); if (!sc) continue; const ts = (follow.blocks ?? []).filter((b) => b.scope === t.scope && fin(b.start)).map((b) => b.start); if (!ts.length) continue; out.push({ id, media: sc.media, at: Array.isArray(sc.at) ? sc.at : null, t0: r3(Math.max(0, Math.min(...ts) - lead)) }); } return out.sort((a, b) => a.t0 - b.t0); } // --------------------------------------------------------------------------- // THE DRAWING (post-item.mjs postCardHtml's threaded card calls it). // --------------------------------------------------------------------------- const KIND_WORD = { dm: "DMs", email: "An email", post: "A post", text: "Text" }; const KIND_SHORT = { dm: "DMs", email: "Email", post: "Post", text: "Text" }; /** * A screen's HEADER, pure: what it is and that it is transcribed -- "DMs shown in Savvy's video · transcribed" (its * `title` for the kind's word; the author's SHOWN name, an anonymous one's; "the post's" for a blurred author). */ export function screenHeader(entry, screen, { authorHidden = false } = {}) { const m = Array.isArray(entry?.media) ? entry.media[screen?.media] : null; const where = m?.kind === "image" ? "picture" : "video"; const who = authorHidden || !str(entry?.author).trim() ? "the post's" : `${str(entry.author).trim()}'s`; // A title's shapes masked as a line's are (an e-mail, a number in it never drawn). const title = maskedField(str(screen?.title).trim()); const what = title || KIND_WORD[screen?.kind] || "Text"; return { text: `${what} shown in ${who} ${where}`, badge: `${title || KIND_SHORT[screen?.kind] || "Text"} · transcribed` }; } /** * ONE SCREEN's TILE, as HTML (escaped; the redaction's marks drawn as bars by the page's barsHtml). `blocks`: line -> * the read-follow block that reads it (`data-post-block`); `shown(lineWho)`: whether a speaker is drawn (the privacy * rule), else blurred. `h`: the card's helpers (esc, mixHex, rgbaOf). The kinds: a DM as bubbles (the author's on the * right in the accent, the others on the left), an email or text as a quiet letter block, a post as a post tile marked * "screenshot". * * @param {Record} entry * @param {Record} screen * @param {{ k: number, size: number, blocks: Map, shown: (line: Record) => boolean, authorHidden?: boolean, h: { esc: (s: any) => string } }} o */ export function screenTileHtml(entry, screen, { k, size, blocks, shown, authorHidden = false, h }) { const { esc } = h; const id = screen.id; const scope = screenScope(id); const head = screenHeader(entry, screen, { authorHidden }); const excerpt = screenIsExcerpt(screen) ? 'excerpt' : ""; const rows = screenRows(screen); const blk = (n) => (blocks.has(n) ? ` data-post-block="${blocks.get(n)}"` : ""); const words = (r) => `${r.cutBefore ? "…" : ""}${esc(r.text)}${r.cutAfter ? "…" : ""}`; const nameOf = (l) => { const w = str(l?.who).trim(); if (!w) return ""; // A speaker's shapes masked whatever the privacy rule says (an e-mail or a phone number as a "name"). return shown(l) ? `${esc(maskedField(w))}` : 'xxxxxxxx'; }; const time = (l) => (str(l?.time).trim() ? `${esc(maskedField(l.time.trim()))}` : ""); let body; if (screen.kind === "dm") { const named = new Set(); let last = null; body = rows .map((r) => { if (r.gap) { last = null; return `

⋯
`; } const l = screen.lines[r.n]; const side = screenSide(l, entry); const who = str(l.who).trim(); const key = who.toLowerCase(); // The speaker's name on first use (and again after a gap or the other side). const name = who && (!named.has(key) || last !== key) ? `
${nameOf(l)}
` : ""; named.add(key); last = key; return `
${name}
${words(r)}${time(l)}
`; }) .join(""); } else if (screen.kind === "post") { // Its author: the speaker of the first line DRAWN (never a redacted or left-out line's). const first = rows.filter((r) => !r.gap).map((r) => screen.lines[r.n]).find((l) => str(l?.who).trim()); body = `
${first ? `
${nameOf(first)}screenshot
` : '
screenshot
'}${rows .map((r) => (r.gap ? `
⋯
` : `

${words(r)}

`)) .join("")}
`; } else { let lastWho = null; body = `
${rows .map((r) => { if (r.gap) return `
⋯
`; const l = screen.lines[r.n]; const who = str(l.who).trim(); const from = who && who !== lastWho ? `
${nameOf(l)}${time(l)}
` : ""; if (who) lastWho = who; return `${from}

${words(r)}${from ? "" : time(l)}

`; }) .join("")}
`; } return `
${esc(head.text)} · transcribed${excerpt}
${body}
`; } /** A screen's BADGE: pinned to the card's top while that screen is up (followStateAt's `screen`) -- "· transcribed" never leaves the screen. */ export const screenBadgeHtml = (entry, screen, { esc, authorHidden = false }) => `
${esc(screenHeader(entry, screen, { authorHidden }).badge)}
`; /** The CSS a page with screens adds (none without). */ export function screenCss({ k, pal, mixHex, rgbaOf, pad }) { const px = (v) => `${Math.round(v * k)}px`; const bub = mixHex(pal.bg, pal.fg, 0.14); return ` .tscreen { display: flex; flex-direction: column; gap: ${px(10)}; line-height: 1.32; } .shead { display: flex; align-items: baseline; gap: ${px(8)}; color: ${pal.muted}; font-size: ${px(20)}; letter-spacing: 0.01em; } .shead .strans { color: ${pal.muted}; } .shead .plabel { margin-left: auto; } .srow { display: flex; flex-direction: column; max-width: 86%; } .srow.left { align-self: flex-start; align-items: flex-start; } .srow.right { align-self: flex-end; align-items: flex-end; } .tscreen[data-screen-kind="dm"] { align-items: stretch; } .tscreen[data-screen-kind="dm"] > .srow, .tscreen[data-screen-kind="dm"] > .sgap { } .swho { color: ${pal.muted}; font-size: ${px(19)}; margin: ${px(4)} ${px(6)} ${px(2)}; } .sbub { padding: ${px(8)} ${px(16)}; border-radius: ${px(20)}; background: ${bub}; color: ${pal.fg}; overflow-wrap: anywhere; } .srow.right .sbub { background: ${rgbaOf(pal.accent, 0.42)}; } .stime { color: ${pal.muted}; font-size: ${px(16)}; margin-left: ${px(10)}; white-space: nowrap; } .sdim { opacity: 0.45; } .sgap { align-self: center; color: ${pal.muted}; font-size: ${px(22)}; line-height: 1; letter-spacing: 0.2em; } .sletter, .spost { border: 1px solid ${mixHex(pal.bg, pal.fg, 0.22)}; border-radius: ${px(12)}; padding: ${px(14)} ${px(18)}; display: flex; flex-direction: column; gap: ${px(8)}; } .sfrom { color: ${pal.muted}; font-size: ${px(19)}; } .sline { color: ${pal.fg}; overflow-wrap: anywhere; } .sphead { display: flex; align-items: center; gap: ${px(10)}; font-size: ${px(22)}; } .sname { font-family: 'PostSansBold', sans-serif; color: ${pal.fg}; } .swho .sname { color: ${pal.muted}; } .sbadge { position: absolute; top: ${Math.max(2, Math.round((pad - 22 * k) / 2))}px; right: ${pad}px; font-size: ${px(16)}; line-height: 1; padding: ${px(3)} ${px(9)}; border-radius: ${px(6)}; background: ${rgbaOf(pal.bg, 0.85)}; color: ${pal.muted}; border: 1px solid ${mixHex(pal.bg, pal.fg, 0.22)}; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0; z-index: 3; }`; } // --------------------------------------------------------------------------- // THE LINT's WARNINGS (lint.mjs; never refused). They NAME a line, never quote a value. // --------------------------------------------------------------------------- const kindWords = (kinds) => kinds.map((k) => (k === "email" ? "an e-mail address" : k === "order" ? "an order or reference number" : "a long number or a phone number")).join(" and "); /** * Post item `entry`'s screens WARNINGS, pure: a transcription no one checked, a line holding a shape the card masks, a * screen on an item not narrated (not drawn), a screenshot of a post naming an archived one, a speaker the privacy rule * blurs, read lines the picked take does not read. `takeRoles`: the picked take's roles (post-thread.mjs partRoles), * `narrated` whether it plays a take. * * @param {Record} entry * @param {{ narrated?: boolean, takeRoles?: Array, attachAfter?: boolean }} [o] */ export function screenWarnings(entry, { narrated = false, takeRoles = [], attachAfter = false } = {}) { const out = []; const id = entry?.id ?? "?"; const w = `timeline ${id}`; const roles = new Set(takeRoles.filter(Boolean)); const subjects = new Set((Array.isArray(entry?.subjects) ? entry.subjects : []).map((h) => handleKey(h))); for (const sc of screensOf(entry)) { if (!isObj(sc.checked)) out.push(`${w}: screen ${sc.id}'s transcription not checked -- read it against the screenshot, then umtool posts screen

${id} check ${sc.id} (or tick it on the post bench)`); sc.lines.forEach((l, n) => { if (!isObj(l) || l.redact === true) return; const kinds = [...new Set(shapeSpans(str(l.text)).map((s) => s.kind))]; if (kinds.length) out.push(`${w}: screen ${sc.id} line ${n} holds ${kindWords(kinds)} -- masked on the card and never said; mark the line redact (umtool posts screen

${id} set ${sc.id} line.${n}.redact=on) if the rest of it should go too`); // Its speaker and its time: masked on the card too. for (const [f, what] of [["who", "speaker"], ["time", "time"]]) { const k2 = [...new Set(shapeSpans(str(l[f])).map((x) => x.kind))]; if (k2.length) out.push(`${w}: screen ${sc.id} line ${n}'s ${what} holds ${kindWords(k2)} -- masked on the card; write it without (umtool posts screen

${id} set ${sc.id} line.${n}.${f}=…)`); } }); // DIGITS SPLIT ACROSS TWO LINES ("my card is 4111 1111" / "1111 1111"): a shape only the two together make. for (let n = 0; n + 1 < sc.lines.length; n += 1) { const a = sc.lines[n]; const b = sc.lines[n + 1]; if (!isObj(a) || !isObj(b) || a.redact === true || b.redact === true) continue; const ta = str(a.text); const joined = `${ta} ${str(b.text)}`; const across = shapeSpans(joined).filter((sp) => sp.start < ta.length && sp.end > ta.length + 1); if (across.length) out.push(`${w}: lines ${n} and ${n + 1} of screen ${sc.id} together hold ${kindWords([...new Set(across.map((x) => x.kind))])} split across them -- each alone is drawn and said; mark them redact (umtool posts screen

${id} set ${sc.id} line.${n}.redact=on line.${n + 1}.redact=on) or join them`); } const tk = [...new Set(shapeSpans(str(sc.title)).map((x) => x.kind))]; if (tk.length) out.push(`${w}: screen ${sc.id}'s title holds ${kindWords(tk)} -- masked on the card; write it without (umtool posts screen

${id} set ${sc.id} title=…)`); if (sc.kind === "post" && sc.ref) out.push(`${w}: screen ${sc.id} pictures ${sc.ref} -- drawn from its transcription; umtool posts set-item

${id} link.add=… draws the archived post itself`); const reads = screenReadLines(sc); if (!reads.length) continue; if (!narrated) { out.push(`${w}: screen ${sc.id} is drawn and read only on a narrated item -- make its read: umtool posts screen

${id} read`); continue; } // A read over the card first, the attachments after it (`attach: "after"`): the slot does not play the screen's span. if (attachAfter) out.push(`${w}: screen ${sc.id}'s span is not played while it is read: the item's narration attaches its media after the read (attach: after) -- set attach=under to play it`); const missing = reads.filter((r) => !roles.has(screenRole(sc.id, r.n))); if (missing.length === reads.length) out.push(`${w}: its picked take does not read screen ${sc.id} (not drawn until it does) -- umtool posts screen

${id} read`); else if (missing.length) out.push(`${w}: its picked take does not read line${missing.length === 1 ? "" : "s"} ${missing.map((r) => r.n).join(", ")} of screen ${sc.id} -- umtool posts screen

${id} read`); const blurred = new Set(); for (const r of reads) { const who = str(sc.lines[r.n].who).trim(); const s = screenWho(who, entry); if (who && !s.self && entry?.redact !== false && sc.lines[r.n].anonymous !== true && !subjects.has(handleKey(s.handle ?? "")) && !blurred.has(who.toLowerCase())) { blurred.add(who.toLowerCase()); out.push(`${w}: screen ${sc.id} line ${r.n}'s speaker is drawn blurred (the privacy rule: not a subject of the item) -- add them to its subjects or set redact: false to show the name`); } } } return out; }