"use client"; import { useMemo } from "react"; import { FOLLOW_DEFAULTS, FOLLOW_LIMITS, cardScopes, followBlockAt, followKnobs } from "umtool-report-to-video/read-follow"; import { cardWordsOf } from "umtool-report-to-video/word-zoom"; import type { PostPlan } from "./review/PostItemPlayer"; import { screenLineSaid, screenOf } from "umtool-report-to-video/post-screens"; // --------------------------------------------------------------------------- // A POST's READ-FOLLOW ON THE BENCH (report-to-video/read-follow.mjs; knobs.md, // "Read-follow"): the BLOCK MAP -- each block of the card's words, which text // it is in, the part of the read that reads it and when (click: the playhead // there), the one being read marked -- and this post's knobs: follow on, off or // the cut's, the other blocks' dim, the ease. The knobs are the bench's draft // (its Save writes them, as hold and redact). // --------------------------------------------------------------------------- type Entry = Record & { id: string }; type Follow = false | { on?: boolean; dim?: number; ease?: number } | undefined; const SCOPE_NAME = (s: string) => (s === "post" ? "post" : s === "quoted" ? "quoted" : s.startsWith("media:") ? "attachment" : s.replace("parent:", "parent ")); export default function PostFollowPanel({ entry, plan, render, s, setS, setEntry, }: { entry: Entry; plan: PostPlan; render: Record; s: number; setS: (s: number) => void; setEntry: (f: (e: Entry) => Entry) => void; }) { const follow = plan.follow ?? null; const own = entry.follow as Follow; const k = followKnobs(entry, render) as { on: boolean; dim: number; ease: number }; const cutOn = (followKnobs({}, render) as { on: boolean }).on; const mode = own === false ? "off" : own && typeof own === "object" && own.on === true ? "on" : "auto"; const texts = useMemo(() => new Map(cardScopes(entry).map((sc: { scope: string; text: string }) => [sc.scope, cardWordsOf(sc.text)])), [entry]); const cur = follow ? followBlockAt(follow, s) : null; const setOwn = (next: Follow) => setEntry((e) => { const out = { ...e }; if (next === undefined || (typeof next === "object" && !Object.keys(next).length)) delete out.follow; else out.follow = next; return out; }); const knob = (key: "dim" | "ease", v: string) => { const base = own && typeof own === "object" ? { ...own } : {}; if (v === "") delete base[key]; else base[key] = Number(v); setOwn(base); }; const read = follow ? follow.blocks.filter((b) => b.start !== null).length : 0; return (

read-follow

{!follow ? (

off: the card shows its words as they are, shrunk to fit.

) : ( <>

{follow.blocks.length} block{follow.blocks.length === 1 ? "" : "s"}, {read} read {follow.source === "take" ? " (the take's parts)" : follow.source === "script" ? " (the script's parts, timed by words)" : " (the reading rule)"}; the read ends at {follow.readEnd.toFixed(1)} s

    {follow.blocks.map((b) => { const words = texts.get(b.scope) ?? []; // A part read off an attachment (post-thread.mjs: a screenshot's words) has no words on the card. // A SCREEN's line (post-screens.mjs): its words, as the screen reads them. const line = typeof (b as { line?: unknown }).line === "number" && String(b.scope).startsWith("screen:") ? screenLineSaid(screenOf(entry, String(b.scope).slice(7)), (b as { line?: number }).line) : null; const head = line !== null ? `line ${(b as { line?: number }).line}: ${line.split(/\s+/).slice(0, 8).join(" ")}` : b.from === null || b.to === null ? "(read off the attachment)" : words.slice(b.from, Math.min(b.to + 1, b.from + 8)).join(" "); return (
  1. ); })}
)}
); }