Archilyzer · Source

archilyzer

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

commit 4df9f0ae7fc25985611fd22eea00151004845744
parent 54567fe0a6e60237e51b6b0d9ba2233a400a27c1
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu,  5 Nov 2026 11:03:49 -0500

Merge main (picture-replies) into lane/post-media-wave: the changelog keeps both bullets

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

Diffstat:
Meditor/CHANGELOG.md | 1+
Mumtool/app/api/report/post-item/route.ts | 3+++
Mumtool/components/projects/PostBench.tsx | 58+++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mumtool/components/projects/review/PostItemPlayer.tsx | 9+++++++++
Mumtool/docs/cli.md | 2+-
Mumtool/docs/knobs.md | 30++++++++++++++++++++++++++++--
Mumtool/docs/report-video.md | 27+++++++++++++++++++++++++++
Aumtool/e2e/picture-replies.spec.ts | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/manifest.mjs | 11++++++++---
Mumtool/lib/report/postsCli.mjs | 21+++++++++++++++++----
Mumtool/report-to-video/post-item.mjs | 176++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Aumtool/report-to-video/post-picture.mjs | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/post-picture.test.mjs | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/post-render.mjs | 168+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mumtool/report-to-video/post-thread-scenes.test.mjs | 10+++++++---
Mumtool/report-to-video/post-thread.mjs | 80++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Mumtool/report-to-video/read-follow.mjs | 22++++++++++++++++------
17 files changed, 931 insertions(+), 87 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] - **umtool: the post bench's attachment lanes are back on the take-only bench, and a GIF has one.** On `?inTake=<t>` (the only bench of an item a take carries and the cut does not) the bench showed a note where the lanes were, so a video's in and out could only be typed; and the lane covered the first video only. Now every video and GIF of the item has a lane under the player: its whole length as a waveform (a flat line for a GIF or a silent video, which still drags), the in and out as its two handles (never closer than 0.5 s, never past the file), the part the item plays dashed and the playhead, with the bench's clock following a moving edge so the player shows its frame. A handle moves the same draft the **in / out** fields do (they follow at once, as the plan's seconds do) and **Save** writes it -- into the take's patch on a take-only bench, the project's manifest untouched; focused, `[ ]` and `, .` nudge the in and out (Shift coarser) and `← →` the edge last moved. The read's lane (its lead dragged) and **Re-pick best** write the take there too (`/api/report/post-narration` takes `inTake` for set and fit); recording, re-takes and the mix stay on the cut's bench. umtool/docs/knobs.md. +- **A reply that is only a picture is drawn as its message, and a long post on a card alone keeps large text.** A post whose words are only @mentions and links with an attachment (an "@ObviousRises" and a GIF, a reply that is a screenshot of another post) is now picture-only in a report video: its picture is drawn inside its own card where its words would be, at the card's width, with the mention drawn small as a reply-to line, never in the side slot. The GIF that showed beside Mr. Obvious's reply while he was being read now has its own beat first: shown alone in its card for its own length (an image for 2 s, between 1.5 and 4 s), then the read. The read's start moves and the take is not re-made, so word zooms, captions, slams and beeps stay on their words. The render plays the GIF over its place in the card, Play plays it in the card, and the post bench has a **picture-only** block with an auto, on or off setting for the item and for each post it answers or quotes (`umtool posts set-item <p> <item> pictureOnly=on|off|auto`, `parent.<i>.pictureOnly=`, `quoted.pictureOnly=`). `render.posts.pictureReply` sets the beat's length or turns the rule off. A long post on a card alone is now drawn at a reading size and scrolled with the read, where it used to shrink to read-follow's minimum to fit (operator, 5 Nov: "bigger text for the novel"). Posts that are not picture-only, and posts whose words fit their card, render exactly as before. - **umtool: a pause can be put in after words of an approved read, without reading it again.** A countdown read as "20 10 4 0" in one breath could only be spaced by synthesizing a new read, losing a delivery that was liked. `umtool posts reread <p> <item> --pause "20=0.45,10=0.45,4=0.45"` now cuts the picked take just after each word named (found in its word timings as a word zoom finds one: case and punctuation aside, `#2` its second time, `--target linked:0` one piece's words) and puts that much silence in (0.05–3 s), moving everything after it on -- its words, its parts and its length, so zooms, captions, slams, beeps and the read-follow stay on their words. It is a new take, picked in one undoable write; on a paused take it re-cuts from the take before (`=0` takes a pause away), `--dry-run` shows each cut and the new length, `--in-take <t>` puts it in a take's read, and a take with no word timings is refused naming `umtool posts narrate <p> <item> --words`. The post bench's Options → Re-join the read has **pause after** with Preview and Apply, on the take-only bench too. umtool/docs/cli.md, knobs.md. - **A post's @handles typed inside the message are read.** A read dropped every @handle, so "its good advice @grok don't you agree?" lost "@grok" and the lexicon's `@grok` -> "at grok" never applied. Only the run of handles a reply OPENS with (X adds those) is dropped now; a handle inside the sentence stays in the script and is said "at <handle>" (`sayHandles`), the lexicon's own spelling first. Existing takes are untouched; a re-read picks it up. - **umtool: Play is one press from anywhere, a clip is added without its spec, and every page leads with its next step.** A cut or a take named anywhere now carries a Play that opens the newest take (at the item when there is one): the project's head on every tab (with Walk, + Add a clip and the status `latest <take> · <length> · rendered <day> · <n> open notes`), every Cut tab row, every take card, the take walk, `/jobs`' renders (with the mp4's local path and Copy), the Inbox's cards and the rail's Recent cuts; a cut of posts showed no Play at all. **+ Add a clip** finds the words in the recordings the cut draws on (or the archive, or a pasted link with a time), sets the in and out on the moment's cues, places it after a row (by date when the cut is in date order) and fetches its window through the editor; from the Cut tab, from Play at the playhead and from a take ("to this take only": `umtool timeline <p> --take <t> insert <spec> --after <id>`). **+ Add posts** is `posts reel` with a preview; **Reads and voices** edits the pronunciation lexicon and the voice map with Try it; also the redacted words, the slur filter and the cut's narration mix, and queues the cut-wide passes (every script, every missing read, context from captures, conversations) as queue steps. A take has **Check before render** (`lint --take`), **Check the joins**, **New draft from this take** and **Add items from another project** (with a preview); New take has **Save as a draft**; the post bench's **edits go to: take <t> only** writes the take's patch (`--in-take`) and its **Re-join the read** re-times, drops parts or URLs and raises the caps; the clip bench can **Fetch this window again**; the reel cut takes a finale, a file name and a dry run; the Deliver tab opens on **Output files**, absolute paths with Copy. The rest of each page sits under one **Options** / **Advanced** disclosure, its open state remembered per viewer; nothing was removed. diff --git a/umtool/app/api/report/post-item/route.ts b/umtool/app/api/report/post-item/route.ts @@ -258,6 +258,9 @@ export async function GET(request: Request) { redaction, // THE JOIN (post-join.mjs): the post the item before ended on drawn as it drew its post (Play lays the morph). join: followOn && found.ctx.join && found.prev?.type === "post" ? joinCarry(found.prev as Entry, found.prevCtx, cutRender, { width: w, height: h }) : null, + // PICTURE-ONLY posts (post-picture.mjs): each picture in its own card -- a GIF or a video playing there. + mediaUrl: (src: string) => `${base}&file=${encodeURIComponent(src)}`, + livePics: true, }); return new Response(html, { headers: { "content-type": "text/html; charset=utf-8", ...noStore } }); } diff --git a/umtool/components/projects/PostBench.tsx b/umtool/components/projects/PostBench.tsx @@ -7,7 +7,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { postBenchHref } from "@/lib/hrefs"; -import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, postItemPlan, readingSeconds, ruleSeconds, panelEntry } from "umtool-report-to-video/post-item"; +import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, ownPictureOnly, postItemPlan, readingSeconds, refPictureOnly, ruleSeconds, panelEntry } from "umtool-report-to-video/post-item"; import PostItemPlayer, { type PostPlan } from "./review/PostItemPlayer"; import PostFollowPanel from "./PostFollowPanel"; import PostThreadPanel from "./PostThreadPanel"; @@ -46,8 +46,15 @@ import { sceneEntry } from "umtool-report-to-video/post-media-scene"; type Blur = { on: boolean; strength?: number; boxes?: number[][]; label?: string | false; band?: Band; style?: "blur" | "black" | "pixelate" }; type Media = Record<string, unknown> & { src: string; kind: string; seconds?: number; start?: number; end?: number; mute?: boolean; crop?: number[]; push?: boolean; words?: string; audio?: boolean; width?: number; height?: number; blur?: Blur }; -type Ref = Record<string, unknown> & { author?: string; handle?: string; text?: string; paraphrase?: string }; -type Entry = Record<string, unknown> & { id: string; media?: Media[]; hold?: number; mediaLayout?: string; redact?: boolean; quoted?: Ref; parents?: Ref[] }; +type Ref = Record<string, unknown> & { author?: string; handle?: string; text?: string; paraphrase?: string; media?: Media[]; pictureOnly?: boolean }; +type Entry = Record<string, unknown> & { id: string; media?: Media[]; hold?: number; mediaLayout?: string; redact?: boolean; quoted?: Ref; parents?: Ref[]; pictureOnly?: boolean }; +/** A post with its `pictureOnly` knob set (undefined: the rule, post-picture.mjs). */ +const withPictureOnly = <T extends Record<string, unknown>>(p: T, v: boolean | undefined): T => { + const out = { ...p } as Record<string, unknown>; + if (v === undefined) delete out.pictureOnly; + else out.pictureOnly = v; + return out as T; +}; const r2 = (v: number) => Math.round(v * 100) / 100; /** A context post with its paraphrase set (undefined: none, its own words). */ @@ -210,9 +217,11 @@ export default function PostBench({ }, ]), ), - ...(e.quoted && typeof e.quoted === "object" ? { quoted: { paraphrase: e.quoted.paraphrase?.trim() ? e.quoted.paraphrase : null } } : {}), + // Picture-only (post-picture.mjs): true, false, or null (the rule). + pictureOnly: typeof e.pictureOnly === "boolean" ? e.pictureOnly : null, + ...(e.quoted && typeof e.quoted === "object" ? { quoted: { paraphrase: e.quoted.paraphrase?.trim() ? e.quoted.paraphrase : null, pictureOnly: typeof e.quoted.pictureOnly === "boolean" ? e.quoted.pictureOnly : null } } : {}), ...(Array.isArray(e.parents) && e.parents.length - ? { parents: Object.fromEntries(e.parents.map((p, i) => [i, { paraphrase: p?.paraphrase?.trim() ? p.paraphrase : null }])) } + ? { parents: Object.fromEntries(e.parents.map((p, i) => [i, { paraphrase: p?.paraphrase?.trim() ? p.paraphrase : null, pictureOnly: typeof p?.pictureOnly === "boolean" ? p.pictureOnly : null }])) } : {}), }); // The context posts the card draws: the one it quotes, the ones it answers (nearest first). @@ -504,6 +513,45 @@ export default function PostBench({ </label> </section> + {/* PICTURE-ONLY posts (post-picture.mjs): each post with an attachment, whether its picture is its message. */} + {(() => { + const rows: Array<{ key: string; label: string; post: Ref | Entry; on: boolean; auto: boolean; set: (v: boolean | undefined) => void }> = []; + if ((entry.media ?? []).length) rows.push({ key: "post", label: "his post", post: entry, on: ownPictureOnly(entry), auto: ownPictureOnly(withPictureOnly(entry, undefined)), set: (v) => setEntry((x) => withPictureOnly(x, v)) }); + (entry.parents ?? []).forEach((p, i) => { + if (!(p?.media ?? []).length) return; + rows.push({ key: `parent.${i}`, label: i === 0 ? "the post it answers" : `the post that answers (${i + 1} up)`, post: p, on: refPictureOnly(p), auto: refPictureOnly(withPictureOnly(p, undefined)), set: (v) => setEntry((x) => ({ ...x, parents: (x.parents ?? []).map((q, j) => (j === i ? withPictureOnly(q, v) : q)) })) }); + }); + if (entry.quoted && (entry.quoted.media ?? []).length) { + const q = entry.quoted; + rows.push({ key: "quoted", label: "the post it quotes", post: q, on: refPictureOnly(q), auto: refPictureOnly(withPictureOnly(q, undefined)), set: (v) => setEntry((x) => ({ ...x, quoted: withPictureOnly(x.quoted ?? {}, v) })) }); + } + if (!rows.length) return null; + const beats = plan.follow?.beats ?? []; + return ( + <section className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3" data-post-bench-picture=""> + <h2 className="micro mb-2">picture-only</h2> + <p className="m-0 mb-2 text-text-2">A post of only @mentions and links with an attachment says it with its picture: drawn in its own card where its words would be, never beside the card; a post it answers or quotes gets its own beat before the read.</p> + {rows.map((r) => { + const beat = beats.find((b) => b.scope === (r.key === "post" ? "post" : r.key.replace(".", ":"))); + return ( + <label key={r.key} className="mt-1 flex flex-wrap items-center gap-2" data-post-bench-picture-row={r.key} data-picture-only={r.on ? "1" : "0"}> + <span className="min-w-[12rem]">{r.label}: <b>{r.on ? "picture-only" : "words and a picture"}</b>{beat ? ` (its beat ${r2(beat.t1 - beat.t0)} s before the read)` : ""}</span> + <select + value={typeof r.post.pictureOnly === "boolean" ? (r.post.pictureOnly ? "on" : "off") : "auto"} + onChange={(e) => r.set(e.target.value === "on" ? true : e.target.value === "off" ? false : undefined)} + data-post-bench-picture-knob={r.key} + > + <option value="auto">auto ({r.auto ? "picture-only" : "not"})</option> + <option value="on">picture-only</option> + <option value="off">not picture-only</option> + </select> + </label> + ); + })} + </section> + ); + })()} + {combo && ( <PostComboPanel project={project} diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -111,6 +111,8 @@ export type NarrationSchedule = { at: number; seconds: number; takeSeconds?: num /** The plan's read-follow (read-follow.mjs followSchedule). */ export type FollowPlan = { join?: { seconds: number }; + /** PICTURE-ONLY context posts' beats before the read (post-thread.mjs pictureBeats). */ + beats?: Array<{ scope: string; t0: number; t1: number }>; dim: number; ease: number; readEnd: number; @@ -131,6 +133,8 @@ export type PanelShow = { scope: string; media: Array<Record<string, unknown> & export type PostPlan = { panel?: { fade: number; shows: PanelShow[] }; + /** PICTURE-ONLY posts (post-picture.mjs): each picture drawn in its own card (Play: the card's page plays it). */ + pics?: Array<{ scope: string; media: PanelShow["media"] }>; /** Its own attachments come in at this item second, with his own post (post-item.mjs ownMediaEnterAt). */ enter?: number; reading: number; @@ -211,6 +215,7 @@ export function postItemAssets({ project, take = null, entry, plan, box, publish } } for (const sh of plan.panel?.shows ?? []) for (const m of sh.media) files.push(postFileUrl(project, m.src)); + for (const pc of plan.pics ?? []) for (const m of pc.media) files.push(postFileUrl(project, m.src)); if (joinFrom) for (const x of endMediaOf(joinFrom.plan as never, { stepAt, mediaTimeAt }) as Array<{ m: { src?: unknown } }>) if (x.m.src) files.push(postFileUrl(project, String(x.m.src))); return { id: entry.id, docs: [...new Set(docs)], files: [...new Set(files)] }; } @@ -1100,6 +1105,8 @@ export default function PostItemPlayer({ setProgressState(progAt && progFrac !== null ? { ...progAt, frac: progFrac, opacity: op } : null, doc); }, [progress, progAt, progFrac, s, layout.mode, plan.steps]); const src = shown && inStep ? mediaTimeAt(shown, s) : null; + // A PICTURE-ONLY context post's BEAT (post-picture.mjs): the one being shown alone before the read, if any. + const beatNow = (plan.follow?.beats ?? []).find((b) => s >= b.t0 && s < b.t1) ?? null; const cue = wordsRel && src !== null ? (cues[wordsRel] ?? []).find((c) => src >= c.start && src < c.end) ?? null : null; return ( <div @@ -1107,6 +1114,8 @@ export default function PostItemPlayer({ data-post-play={entry.id} data-post-layout={layout.mode} data-post-panel={layout.panel ?? undefined} + data-post-pics={plan.pics?.length ? plan.pics.map((p) => p.scope).join(" ") : undefined} + data-post-beat={beatNow ? beatNow.scope : undefined} data-post-join={joinOn ? (jp !== null ? String(Math.round(jp * 100) / 100) : "done") : undefined} data-post-step={reading ? "read" : current?.kind ?? "held"} data-post-s={String(Math.round(s * 100) / 100)} diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -87,7 +87,7 @@ Inbox cannot disagree about what is wrong with one. | `posts set <project> <post> thread=on\|off [hide=on\|off] [attach=<clipId>\|auto] [crop=<px>\|off] [--json]` | the Posts table's writer (`updatePosts`, `PUT /api/report/posts`) from a terminal: `<post>` is the manifest's id (`x-<postId>`) or the bare `<postId>`; `thread=on` draws a reply with the post it answers above it (`shot-thread.png` beside its `shot`, taken by `capture-posts` `"thread": true`; its own shot while there is none), `off` removes the key.; `crop=<px>` the post's own crop of its screenshot (`shotMaxHeight`, 120–1080: its top that tall, never panned; `off` removes it) ([knobs.md](knobs.md#add-post-a-post-card-from-play-the-cut)). Refused in the build's words (a post with no `shot`, an `attach` that is not a clip) — **exit 1** | | `posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID] [--thread] [--crop <px>] [--dry-run] [--json]` | a **post card** from the corpus's posts archive (`channels/<slug>/posts/*.jsonl`): its words, date, link and handle; id `x-<postId>` (`bsky-`, `post-`); the author an earlier post by the same handle carries in the cut, else the archive's. Its capture (`posts-media/<postId>/`: `shot.png`, `capture.json`, the post's pictures) is copied to the project's `posts-media/<slug>/<postId>/` — or used where it is, when that folder links the channel's captures; never copied through a link anywhere else. Then `upsertPost` (a post with the id is replaced, its `attachTo` kept). **Exit 1** with no screenshot, naming the `pnpm ops capture-posts` to run. `--thread`: the entry gets `thread: true` (a reply drawn with the post it answers; `shot-thread.png` is copied with the rest, and with none yet it prints the `"thread": true` capture to run). `--crop <px>`: the post's own crop (`shotMaxHeight`). A post that quotes another, reposts one or carries media is added with a `WARNING:` line (`--json`: `warnings`) — its screenshot shows them, by the post's own data. Play the cut's **Add post** runs this same write ([knobs.md](knobs.md#add-post-a-post-card-from-play-the-cut)) | | `posts reel <project> --channel <slug> [--channel <slug> …] [--since YYYY-MM-DD] [--until YYYY-MM-DD] [--own] [--with-media] [--replies include\|only\|exclude] [--order chrono\|reverse] [--limit N] [--after <id\|->] [--dry-run] [--json]` | **POST ITEMS** ([report-video.md](report-video.md#post-items-a-post-as-an-entry-of-the-cut)): each archived post an entry of the cut -- its card drawn from the archive row (snapshotted), its attachments copied into `posts-media/` and played in it. The channels are read as one archive, merged in time order, de-duplicated by post id (`--channel ObviousRises-x --channel ObviousRises-x-replies`); `--own` the accounts' own posts (their config's `socialHandle`, no reposts); `--with-media` only posts whose capture holds an attachment; `--replies` keeps, keeps only or drops replies (a reply carries the posts it answers from the archive, else the capture's thread shot, else a "Replying to" line; the quoted post and the parent the archive lacks come from the capture's `context`, as `posts context` fills them). A post the cut already plays (by its id, a repost's original, a repost of it) is skipped, so a **re-run adds only what is new**; the rest goes in in ONE write (one undo point: `timeline <p> undo`), at the end unless `--after` | -| `posts set-item <project> <item> [hold=<s>\|off] [layout=sequence\|grid] [redact=on\|off\|auto] [fit=read[:<linger>]] [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.trim=off] [media.<i>.mute=on\|off] [media.<i>.crop=x,y,w,h\|off] [media.<i>.push=on\|off] [media.<i>.enter=post\|item] [media.<i>.blur=on\|off] [media.<i>.blur.strength=1–10] [media.<i>.blur.label="…"\|off] [media.<i>.blur.boxes=x,y,w,h;…\|off] [quoted.paraphrase="…"\|off] [parent.<i>.paraphrase="…"\|off] [follow=on\|off\|auto] [follow.dim=<0.2-1>] [follow.ease=<s>] [thread.parent[.<i>]=auto\|full\|excerpt\|context\|carry\|hidden] [thread.quoted=…] [thread.carry=auto\|on\|off] [thread.reveal=on\|off] [thread.shrink=<0.3-1>] [thread.dim=<0.15-1>] [thread.seconds=<s>] [thread.pan=<s>] [thread=auto] [thread.group=<name>\|off] [thread.map=auto\|on\|off\|map\|label\|both] [panel=auto\|side\|top\|bottom] [media.add=<file>] [media.<i>=off] [parent.<i>=<json ref>\|@<file>\|off] [parent.<i>.media=<file>[,…]\|off] [link.add=<json ref>] [link.<i>=<json ref>\|off] [link.<i>.media=<file>\|off] [link.<i>.transcript="…"\|off] [--json]` | a **post item's knobs** (the post bench's writer, `updatePostItem`; [knobs.md](knobs.md#a-post-item-a-post-as-an-entry-of-the-cut)): `<item>` is its id or the post's id; refused in the build's words. `quoted.paraphrase` / `parent.<i>.paraphrase`: your retelling of a long context post (≤ 600 characters), drawn in place of its words with a "paraphrased" label (its text kept); `off` or empty clears it. `follow=`: its read-follow ([knobs.md](knobs.md#read-follow-the-block-being-read-lit-the-card-panned-to-it)) -- `off`, `on`, `auto` (the cut's); `follow.dim=` / `follow.ease=` over the cut's. `thread.*`: its THREAD READ ([knobs.md](knobs.md#thread-reads-every-part-of-a-read-on-screen-while-it-is-said)) -- what each context post is on screen (`thread.parent.<i>` one parent, nearest first), the shrink, dim and their seconds, the pan's; `thread=auto` the cut's; a setting that would narrate a post the card hides is refused (**exit 1**). `media.<i>.blur…` CENSORS the attachment in the render (a real blur of the whole frame or of its boxes, labelled "Censored"; the file untouched; merged key by key, `blur=off` keeps the settings). THREAD SCENES ([knobs.md](knobs.md#thread-scenes-the-join-whole-threads-manual-threads-wide-attachments-context-media-link-visits-the-branch-map)): `parent.<i>=` an ancestor added / replaced / dropped (a whole-thread read), `parent.<i>.media=` its attachments, `media.add=` / `media.<i>=off` an attachment from a project file (measured), `link.add=` a post its words link to (a link visit) with its picture and transcript, `thread.group=` a manual thread, `thread.map=` the branch map, `panel=` where its attachments sit; `media.<i>.enter=` when its own attachment comes in -- with his own post's read (`post`, the default: a parent or a quote read first shows none of it) or with the item (`item`) | +| `posts set-item <project> <item> [hold=<s>\|off] [layout=sequence\|grid] [redact=on\|off\|auto] [fit=read[:<linger>]] [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.trim=off] [media.<i>.mute=on\|off] [media.<i>.crop=x,y,w,h\|off] [media.<i>.push=on\|off] [media.<i>.enter=post\|item] [media.<i>.blur=on\|off] [media.<i>.blur.strength=1–10] [media.<i>.blur.label="…"\|off] [media.<i>.blur.boxes=x,y,w,h;…\|off] [quoted.paraphrase="…"\|off] [parent.<i>.paraphrase="…"\|off] [follow=on\|off\|auto] [follow.dim=<0.2-1>] [follow.ease=<s>] [thread.parent[.<i>]=auto\|full\|excerpt\|context\|carry\|hidden] [thread.quoted=…] [thread.carry=auto\|on\|off] [thread.reveal=on\|off] [thread.shrink=<0.3-1>] [thread.dim=<0.15-1>] [thread.seconds=<s>] [thread.pan=<s>] [thread=auto] [thread.group=<name>\|off] [thread.map=auto\|on\|off\|map\|label\|both] [panel=auto\|side\|top\|bottom] [media.add=<file>] [media.<i>=off] [parent.<i>=<json ref>\|@<file>\|off] [parent.<i>.media=<file>[,…]\|off] [link.add=<json ref>] [link.<i>=<json ref>\|off] [link.<i>.media=<file>\|off] [link.<i>.transcript="…"\|off] [pictureOnly=on\|off\|auto] [parent.<i>.pictureOnly=on\|off\|auto] [quoted.pictureOnly=on\|off\|auto] [--json]` | a **post item's knobs** (the post bench's writer, `updatePostItem`; [knobs.md](knobs.md#a-post-item-a-post-as-an-entry-of-the-cut)): `<item>` is its id or the post's id; refused in the build's words. `quoted.paraphrase` / `parent.<i>.paraphrase`: your retelling of a long context post (≤ 600 characters), drawn in place of its words with a "paraphrased" label (its text kept); `off` or empty clears it. `follow=`: its read-follow ([knobs.md](knobs.md#read-follow-the-block-being-read-lit-the-card-panned-to-it)) -- `off`, `on`, `auto` (the cut's); `follow.dim=` / `follow.ease=` over the cut's. `thread.*`: its THREAD READ ([knobs.md](knobs.md#thread-reads-every-part-of-a-read-on-screen-while-it-is-said)) -- what each context post is on screen (`thread.parent.<i>` one parent, nearest first), the shrink, dim and their seconds, the pan's; `thread=auto` the cut's; a setting that would narrate a post the card hides is refused (**exit 1**). `media.<i>.blur…` CENSORS the attachment in the render (a real blur of the whole frame or of its boxes, labelled "Censored"; the file untouched; merged key by key, `blur=off` keeps the settings). THREAD SCENES ([knobs.md](knobs.md#thread-scenes-the-join-whole-threads-manual-threads-wide-attachments-context-media-link-visits-the-branch-map)): `parent.<i>=` an ancestor added / replaced / dropped (a whole-thread read), `parent.<i>.media=` its attachments, `media.add=` / `media.<i>=off` an attachment from a project file (measured), `link.add=` a post its words link to (a link visit) with its picture and transcript, `thread.group=` a manual thread, `thread.map=` the branch map, `panel=` where its attachments sit; `media.<i>.enter=` when its own attachment comes in -- with his own post's read (`post`, the default: a parent or a quote read first shows none of it) or with the item (`item`). `pictureOnly=` a PICTURE-ONLY post ([knobs.md](knobs.md#picture-only-posts-a-reply-that-is-its-picture)): its attachment drawn in its own card where its words would be, never in the slot, a context post that is one given its own beat before the read -- `auto` (a post of only @mentions and links with an attachment), `on`, `off`; `parent.<i>.pictureOnly=` / `quoted.pictureOnly=` for those | | `posts set-item \| roles \| narrate \| reread \| fx <project> … --in-take <take>` (set-item, roles, reread, fx: `--take <take>` too) | **a take-scoped edit** (`takeScope.mjs`): the same command, on a TAKE of the project -- its manifest read as the take's (the project's now with the take's patches), every write landing in `takes/<take>/take.json`'s patch with an undo point of the take's own (`timeline <p> --take <take> undo`). The project's manifest, and any project the take's items were imported from, are untouched; a new read (`narrate --take`, `--thread`, `reread`) lands in the project's `narration/` under a take number no file or entry has. A writer not routed to the take refuses and writes nothing. `--json`: the command's own object plus `take {id, edits, revisions, undo}`. narrate's own `--take` is "make a new read": `narrate … --take <a take's id>` is refused (exit 2) naming `--in-take`. **Exit 1** when the take is not there or is rendering ([take-scoped edits](#edit-a-take-not-the-project-items-from-other-projects-and-take-scoped-edits)) | | `posts reread <project> <item> [--without parent:0\|parent:1\|quoted[,…]] [--drop-parts 3,4] [--drop-urls] [--dry-run] [--json]` | a narrated read **re-joined without a piece**, no TTS ([knobs.md](knobs.md#thread-reads-every-part-of-a-read-on-screen-while-it-is-said), [report-video.md](report-video.md#thread-reads)): the picked take's kept parts cut out of its own file (ffmpeg) and joined with the read's pauses, measured, added as a derived take (`steps: [{op: "rejoin", drop}]`, its parts re-timed with their roles, its word timings moved, its slurs state kept) and picked — ONE write (one undo point). `--without` drops the parts that read the post it answers (`parent:0`), its parent (`parent:1`) or the quoted post; `--drop-parts` by number; `--drop-urls` the parts that are nothing but a link. Nothing to drop, every part dropped or a take read in one go: **exit 1**. `posts set-item … thread.parent.<i>=context\|hidden` (or `thread.quoted=…`) on a piece the take reads runs it first (`--no-reread`: refused, as before) | | `posts reread <project> <item> --tempo-for "4-16=1.35,21-25=1.3" \| --tempo <x> --parts <runs> [--stretch atempo\|rubberband] [--dry-run] [--json]` | a narrated read's **parts re-timed**, no TTS ([knobs.md](knobs.md#thread-reads-every-part-of-a-read-on-screen-while-it-is-said), [report-video.md](report-video.md#a-long-read-sped-up-and-its-caps-yelled)): the parts named time-stretched (1–1.6, pitch kept), the rest untouched, joined with the read's pauses (each stretched part padded and trimmed to its length, sample-exact), its words scaled with their part, a derived take (`steps: [{op: "tempo", tempo, params: {stretch}}]`) picked in ONE write. A tempo is absolute: on a re-timed take it re-cuts from the take before. `posts set-item <p> <item> narration.tempo="4-16=1.35"` runs the same. A part outside the take, a tempo outside 1–1.6, nothing changed: **exit 1** | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -975,16 +975,42 @@ card route and the build draw the same states. | `render.posts.join` — the join between items of one run: `{on, seconds}` (default on, 0.6 s, 0.2–2); the read starts after it | — | (the manifest's `render.posts.join`) | — | | `join` on a post item — `false`: a cut; `{seconds}` its own | — | (the manifest) | `POST /api/report/post-item {op: "set", patch}` | | `parents[i]` — an ancestor added (i = the next index), replaced or dropped, nearest first, up to 8: `{id, author, handle, date, text, media?, paraphrase?}` | — | `umtool posts set-item <p> <item> 'parent.1={"id":"…","handle":"…","author":"…","date":"…","text":"…"}'` · `parent.1=@ref.json` · `parent.1=off` | `POST /api/report/post-item {op: "set", patch: {parents: {"1": {ref}}}}` | -| `parents[i].media` — a context post's attachments, shown in the slot while it is on screen (project files, measured) | — | `umtool posts set-item <p> <item> parent.0.media=posts-media/…/1.mp4[,…]` · `=off` | same, `{parents: {"0": {media: [...]}}}` | +| `parents[i].media` — a context post's attachments, shown in the slot while it is on screen (project files, measured); a picture-only one's are drawn in its card ([Picture-only posts](#picture-only-posts-a-reply-that-is-its-picture)) | — | `umtool posts set-item <p> <item> parent.0.media=posts-media/…/1.mp4[,…]` · `=off` | same, `{parents: {"0": {media: [...]}}}` | | `media` from a project file — added (kind, size, length measured) or removed | — | `umtool posts set-item <p> <item> media.add=posts-media/…` · `media.1=off` | same, `{mediaAdd: [...]}` · `{media: {"1": null}}` | | `links[]` — a post its words link to that the card draws (a link visit), its picture and the words read off it (`transcript`, role `linked:<i>`) | — | `umtool posts set-item <p> <item> 'link.add={…}'` · `link.0.media=<file>` · `link.0.transcript="…"` · `link.0=off` | same, `{linksAdd: [...]}` · `{links: {"0": {...}}}` | | `thread.group` — a MANUAL THREAD: consecutive items of one group are one scene, in timeline order | — | `umtool posts set-item <p> <item> thread.group=jiggle` (`off`) · `umtool timeline <p> threads --write --conversation jiggle` (gathered in date order) | same, `{thread: {group}}` | | `render.posts.panel` — a wide attachment's layout: `{wide, place}` (default 2.0, `top`; `bottom`; `side`: never) | — | (the manifest) | — | -| `panel` on a post item — `side`, `top`, `bottom` (absent: the cut's rule) | — | `umtool posts set-item <p> <item> panel=top` (`auto`) | same, `{panel}` | +| `panel` on a post item — `side`, `top`, `bottom` (absent: the cut's rule); a picture-only item has no slot: its picture is in its card ([Picture-only posts](#picture-only-posts-a-reply-that-is-its-picture)) | — | `umtool posts set-item <p> <item> panel=top` (`auto`) | same, `{panel}` | | `render.posts.linkVisit` — `{on, hold}` (default on, 1.4 s: a post read earlier lit again that long) · `linkVisit: false` on an item | — | (the manifest) | — | | `render.posts.threadMap` — the branch map: `{on, style}` (default on, `both`; `map`, `label`) · `thread.map` on an item: `false`, `true`, a style | — | `umtool posts set-item <p> <item> thread.map=off` (`label`, `map`, `both`, `auto`) | same, `{thread: {map}}` | | a post item made by hand (no archive holds it) | — | `umtool timeline <p> insert --after <id> 'post-json:{"post":"<chan>/<id>","author":…,"handle":…,"date":…,"text":…,"media":["posts-media/…"]}'` (or `post-json:@file.json`) | — | +## Picture-only posts (a reply that is its picture) + +A post whose words are only @mentions and links -- "@ObviousRises" and a GIF -- says what it says with its picture +([report-video.md](report-video.md#picture-only-posts); `report-to-video/post-picture.mjs`). Such a post -- an item, a +post it answers, the post it quotes -- is drawn as its message: its attachment INSIDE its own card where its words would +be (the card's width, its aspect and crop kept; a GIF or a video playing there), its mention-only words small as X's +reply-to line; never in the side slot, never while another post's read plays. In a thread read, a picture-only context +post the read does not read gets its own BEAT before the read: lit and shown alone, then the read -- the read's start +moved (the take never re-made: word zooms, captions, slams and beeps stay on their words), his own attachment entering +with his words. A picture-only item not narrated lasts its beat. The build plays a GIF over its still while its card is +at full size and still (`<id>.post.json`'s notes say when); Play plays it in the card; the post bench's **picture-only** +block says which of the item's posts are and sets the knob. A picture-only post standing BETWEEN two read pieces has no +beat (it is drawn in its card and gives way with the piece after it). The rule's beat is part of the item's length +everywhere (the schedule, the bench, Play, the build); a parent carried in from the item before (`thread.carry`) is that +item's, and has none. + +| Knob | In umtool | From a terminal | Route | +|---|---|---|---| +| `pictureOnly` on a post item -- `true`: picture-only (it needs an attachment) · `false`: never · absent: the rule (its words only @mentions and links, and an attachment) | post bench, **picture-only**: his post's row (auto / picture-only / not) | `umtool posts set-item <p> <item> pictureOnly=on` (`off`, `auto`) | `POST /api/report/post-item {project, op: "set", id, patch: {pictureOnly: true \| false \| null}, token}` | +| `parents[i].pictureOnly`, `quoted.pictureOnly` -- the same for a context post | post bench, **picture-only**: its row | `umtool posts set-item <p> <item> parent.0.pictureOnly=on` · `quoted.pictureOnly=off` (`auto`) | same, `patch: {parents: {"0": {pictureOnly}}, quoted: {pictureOnly}}` | +| `render.posts.pictureReply` -- the cut's rule: `{on, image, min, max}` (default `on: true`; a beat is a GIF's or a video's own length, an image `image` = 2 s, clamped to `min`–`max` = 1.5–4 s); `on: false` turns the rule off (a post's own `pictureOnly: true` still wins) | — | (the manifest) | — | + +A LONG READ on a card alone (no attachment, or a picture-only one in the card): words that do not fit the card at any +size are drawn at a reading size (`POST_LONG_READ_SIZE`, 36 px of a 1080 frame) and panned by read-follow -- never +shrunk to fit; beside an attachment they keep read-follow's minimum (28 px). + ## The combo counter A post item that plays an attachment an earlier post item of the cut already played gets a fighting-game badge, diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -1295,6 +1295,33 @@ kept only as a picture) -- `post`, `author`, `handle`, `date`, `text`, `media` ( its avatar `posts avatar <p> <handle> <file>`; refused as the build would. **An attachment from a file**: `posts set-item … media.add=<file>` (kind and size measured), `media.<i>=off`. +### Picture-only posts + +A post whose words are only @mentions and links, with an attachment -- "@ObviousRises" and a GIF, a reply that is a +screenshot of somebody else's post -- says what it says WITH its picture (operator, 5 Nov, the Mr. Obvious mid cut at +26:53: the "It's time to stop" GIF "shows while Obvious is speaking rather than it being a picture-only response like +the MW post, we need to handle this because it's a standard type of post"). `report-to-video/post-picture.mjs` decides +it (`isPictureOnly`: the post's own `pictureOnly`, else the rule) and the card draws it as its message: + +- **in its own card**: its first attachment where its words would be, at the card's (or the tile's) width, its aspect + and crop kept, at most about 60 % of the card tall ("+N" when it carries more); its mention-only words drawn small, as + X's reply-to line. Never in the side slot (`slotMediaOf`, `panelSchedule` skip it), so never beside another post's + read. An image is drawn by the page (a censored one blurred whole); a GIF's or a video's first frame is the page's + still, and the build lays the file over that place, looped and silent, wherever the card is at full size and still + (`measurePics`, from the frames read-follow shoots), fading back to the still as the card moves on; +- **its own beat** (`post-thread.mjs pictureBeats`): a picture-only parent or quoted post the read does not read, + standing before the read's first piece, is a piece of its own -- revealed, lit and shown alone (a GIF's or a video's + own length, an image 2 s, clamped to 1.5–4 s: `render.posts.pictureReply`), shrinking as the read comes in. The read + is never re-made: postItemPlan moves its START by the beats (as it does for a join), so every word zoom, caption, slam + and beep stays on its word; the item is the beats longer; his own attachment enters with his words; +- **an item** that is picture-only has no slot (a card alone, its picture in it); not narrated, it lasts its beat; + narrated (a read of the words on the picture), the read's length, as any item. + +One standing between two read pieces has no beat (drawn in its card, it gives way with the piece after it); a parent +carried in from the item before is that item's (no beat). `render.posts.pictureReply.on: false` restores the old +drawing (a chip, the picture in the slot) for every post that does not say `pictureOnly: true`. + + ### The combo counter When a post item's attachment is one an EARLIER post item of the cut already played — diff --git a/umtool/e2e/picture-replies.spec.ts b/umtool/e2e/picture-replies.spec.ts @@ -0,0 +1,125 @@ +import { test, expect, type Page } from "@playwright/test"; +import { copyFileSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import * as urls from "./urls"; + +// --------------------------------------------------------------------------- +// PICTURE-ONLY POSTS (report-to-video/post-picture.mjs; knobs.md, "Picture-only posts"; operator, 5 Nov, the Mr. +// Obvious mid cut at 26:53: "the "It's time to stop" gif shows while Obvious is speaking rather than it being a +// picture-only response like the MW post, we need to handle this because it's a standard type of post"): +// - a reply's parent that is only "@him" and a GIF has its own beat before the reply's read: lit, alone, its GIF +// drawn IN ITS CARD (the page plays it) -- never in the slot -- and the reply's read after it, the GIF's card +// small and dim, still never in the slot; +// - an item that is only "@him" and a picture is a card alone, its picture inside it where its words would be; +// - the post bench says which posts are picture-only and sets the knob. +// Fixture: e2e/fixtures/post-narration-fixture.mjs's items, rewritten here. +// +// PICTURE_REPLIES_SHOTS=<dir> screenshots there +// --------------------------------------------------------------------------- + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const REPORTS = path.join(HERE, "..", ".e2e-song", "reports"); +const DIR = path.join(REPORTS, "post-narration-fixture"); +const MANIFEST = path.join(DIR, "video.manifest.json"); +const PROJECT = "reports/post-narration-fixture"; +const SHOTS = process.env.PICTURE_REPLIES_SHOTS ?? null; + +const REPLY = "Then do not antagonize me, that is something the whole community needs to learn about me."; +const GIF = { src: "posts-media/narrchan-x/11/11_1.mp4", kind: "gif", width: 320, height: 180, seconds: 2.5 }; + +function takeOf(text: string) { + const seconds = Math.round((text.split(/\s+/).length / 3) * 100) / 100; + return { file: "narration/posts/11/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds, script: text, parts: [{ n: 1, para: 0, text, start: 0, seconds, role: "post" }] }; +} + +test.beforeAll(() => { + if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`); +}); +test.beforeEach(() => { + test.setTimeout(120_000); + copyFileSync(`${MANIFEST}.pristine`, MANIFEST); + rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); + rmSync(path.join(DIR, "notes.json"), { force: true }); + const m = JSON.parse(readFileSync(MANIFEST, "utf8")); + const byId = (id: string) => m.timeline.find((x: { id: string }) => x.id === id); + // His reply to a post that is only "@narrsubject" and a GIF. + const reply = { ...structuredClone(byId("p-12")), id: "p-41", post: "narrchan-x/41", text: REPLY, date: "2026-10-30T07:00:00.000Z", narration: { script: REPLY, takes: [takeOf(REPLY)], pick: 0 } }; + delete reply.media; + reply.parents = [{ id: "40", author: "Furri", handle: "furri_m", date: "2026-10-30T06:58:00.000Z", text: "@narrsubject", media: [GIF] }]; + // A reply of somebody else's that is only "@narrsubject" and a picture. + const pic = { ...structuredClone(byId("p-12")), id: "p-42", post: "othchan-x/42", author: "Kir", handle: "kir_v", text: "@narrsubject", date: "2026-10-30T08:00:00.000Z", media: [{ src: "posts-media/narrchan-x/12/12_2.png", kind: "image", width: 320, height: 180 }], panel: "side" }; + m.timeline = [reply, pic, byId("p-13")]; + writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); +}); + +async function playAt(page: Page, id: string, at: number) { + await page.goto(urls.playHref(PROJECT, { bare: true, clip: id, at })); + const player = page.locator(`[data-post-play="${id}"]`); + await expect(player).toBeVisible({ timeout: 15_000 }); + const frame = page.frameLocator('[data-post-card-frame="read"]'); + await expect(frame.locator("body")).toHaveAttribute("data-post-ready", "1", { timeout: 15_000 }); + await expect.poll(async () => Math.abs(Number(await player.getAttribute("data-post-s")) - at)).toBeLessThan(0.3); + return { player, frame }; +} + +const opacityOf = (frame: ReturnType<Page["frameLocator"]>, sel: string) => frame.locator(sel).evaluate((el) => { + let op = 1; + for (let e: Element | null = el; e; e = e.parentElement) op *= Number(getComputedStyle(e).opacity); + return op; +}); + +test("A PICTURE-ONLY PARENT has its own beat before his read: its GIF in its own card, alone and lit -- then his read, the GIF's card small and dim, never a GIF in the slot", async ({ page }) => { + await page.setViewportSize({ width: 1366, height: 1000 }); + { + const { player, frame } = await playAt(page, "p-41", 1); + await expect(player).toHaveAttribute("data-post-pics", "parent:0"); + await expect(player).toHaveAttribute("data-post-beat", "parent:0"); + // Drawn IN the parent's card (the page plays it), where its words would be -- its mention small. + await expect(frame.locator('[data-thread-tile="parent:0"] [data-post-pic="parent:0"] video')).toHaveCount(1); + await expect(frame.locator('[data-thread-tile="parent:0"] .pmen')).toContainText("@narrsubject"); + await expect(frame.locator("[data-thread-media]")).toHaveCount(0); + // Never over the slot. + await expect(page.locator('[data-post-panel="parent:0"]')).toHaveCount(0); + await expect(frame.locator("[data-post-slot]")).toHaveCount(0); + // (The card's frame may be swapped in once more as Play settles: read again until it holds.) + await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="parent:0"]')).toBeGreaterThan(0.95)).toPass({ timeout: 10_000 }); + const pic = await frame.locator('[data-post-pic="parent:0"]').boundingBox({ timeout: 10_000 }); + expect(pic && pic.width > 300 && Math.abs(pic.width / pic.height - 16 / 9) < 0.05, "at the tile's width, its aspect kept").toBe(true); + if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-beat.png") }); + } + { + // His read: after the beat (2.5 s) and the lead. + const { player, frame } = await playAt(page, "p-41", 5); + await expect(player).not.toHaveAttribute("data-post-beat", /./); + await expect(page.locator('[data-post-panel="parent:0"]')).toHaveCount(0); + await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="parent:0"]')).toBeLessThan(0.7)).toPass({ timeout: 10_000 }); + await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="post"]')).toBeGreaterThan(0.95)).toPass({ timeout: 10_000 }); + if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-read.png") }); + } +}); + +test("A PICTURE-ONLY ITEM is a card alone, its picture inside it where its words would be -- no slot, whatever its panel says", async ({ page }) => { + await page.setViewportSize({ width: 1366, height: 1000 }); + const { player, frame } = await playAt(page, "p-42", 0.5); + await expect(player).toHaveAttribute("data-post-layout", "text"); + await expect(player).toHaveAttribute("data-post-pics", "post"); + await expect(frame.locator('[data-post-card] [data-post-pic="post"] img')).toHaveCount(1); + await expect(frame.locator("[data-post-slot]")).toHaveCount(0); + const pic = await frame.locator('[data-post-pic="post"]').boundingBox(); + const card = await frame.locator("[data-post-card]").boundingBox(); + expect(pic && card && pic.width > card.width * 0.8, "the card's width").toBe(true); + if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-item.png") }); +}); + +test("THE POST BENCH's picture-only block: the parent picture-only by the rule, the knob turns it off and Save writes it", async ({ page }) => { + await page.setViewportSize({ width: 1500, height: 1100 }); + await page.goto(urls.postBenchHref(PROJECT, "p-41")); + const row = page.locator('[data-post-bench-picture-row="parent.0"]'); + await expect(row).toHaveAttribute("data-picture-only", "1", { timeout: 15_000 }); + await expect(row).toContainText("its beat 2.5 s before the read"); + await page.locator('[data-post-bench-picture-knob="parent.0"]').selectOption("off"); + await expect(row).toHaveAttribute("data-picture-only", "0"); + await page.locator("[data-post-bench-save]").click(); + await expect.poll(() => JSON.parse(readFileSync(MANIFEST, "utf8")).timeline.find((e: { id: string }) => e.id === "p-41").parents[0].pictureOnly).toBe(false); +}); diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -2402,13 +2402,13 @@ export async function insertEntries(dir, afterId, specs, { token = null, op = "i } /** The knobs of a post item a write may set (post-item.mjs; knobs.md, "A post item"). */ -export const POST_ITEM_KNOBS = Object.freeze(["hold", "mediaLayout", "panel", "redact", "follow", "thread", "scene", "progress"]); +export const POST_ITEM_KNOBS = Object.freeze(["hold", "mediaLayout", "panel", "redact", "follow", "thread", "scene", "progress", "pictureOnly"]); /** A post item attachment's knobs: its trim, its sound, its crop, the push-in, its transcript, its censoring blur. */ export const POST_MEDIA_KNOBS = Object.freeze(["start", "end", "mute", "crop", "push", "words", "blur", "enter"]); /** A context post's knobs (`quoted`, `parents[i]`): the operator's paraphrase of its words. */ -export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase", "ref", "media", "transcript"]); +export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase", "ref", "media", "transcript", "pictureOnly"]); /** The fields a context post (a parent, a linked post) is given by hand (`parent.<i>=<ref>`, post-item.mjs refErrors). */ -const POST_REF_FIELDS = Object.freeze(["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via"]); +const POST_REF_FIELDS = Object.freeze(["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via", "pictureOnly"]); /** * SET A POST ITEM's KNOBS (the post bench, `umtool posts set-item`): `patch` @@ -2515,6 +2515,11 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) { if (cp.media !== null && !Array.isArray(cp.media)) throw new Error(`${what}.media is a list of attachments (or null: none)`); set(ref, "media", cp.media?.length ? cp.media : null); } + // Picture-only (post-picture.mjs): true, false, or null (the rule). + if ("pictureOnly" in cp) { + if (cp.pictureOnly !== null && typeof cp.pictureOnly !== "boolean") throw new Error(`${what}.pictureOnly is true or false (or null: the rule)`); + set(ref, "pictureOnly", cp.pictureOnly); + } if ("transcript" in cp) { if (cp.transcript !== null && typeof cp.transcript !== "string") throw new Error(`${what}.transcript is the words read off its picture (or null)`); set(ref, "transcript", typeof cp.transcript === "string" && cp.transcript.trim() ? cp.transcript.trim() : null); diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -110,7 +110,8 @@ export const POSTS_USAGE = [ " [panel=auto|side|top|bottom] [media.add=<posts-media/…file>] [media.<i>=off]", " [parent.<i>=<json ref>|@<file.json>|off] [parent.<i>.media=<file>[,<file>…]|off]", " [link.add=<json ref>|@<file.json>] [link.<i>=<json ref>|off] [link.<i>.media=<file>|off] [link.<i>.transcript=\"…\"|off]", - " [thread.group=<name>|off] [thread.map=auto|on|off|map|label|both] [--json]", + " [thread.group=<name>|off] [thread.map=auto|on|off|map|label|both]", + " [pictureOnly=on|off|auto] [parent.<i>.pictureOnly=on|off|auto] [quoted.pictureOnly=on|off|auto] [--json]", " a post item's knobs (the post bench's writer, updatePostItem): its hold, its images' grid, the blur of other authors,", " an attachment's trim, sound, crop (fractions of its picture) and push-in; fit=read[:linger] (a narrated post: its", " video cut to its best part for the read, `posts fit`). quoted.paraphrase / parent.<i>.paraphrase (nearest first):", @@ -137,6 +138,9 @@ export const POSTS_USAGE = [ " thread.group=<name>: a MANUAL THREAD -- consecutive items of one group are one scene (timeline threads --write", " gathers them in date order). thread.map: the BRANCH MAP drawn when the scene changes branch (post-branch-map.mjs).", " panel=: where the attachments sit -- beside the card, or at full width above (top) or below it (a wide one: auto).", + " pictureOnly=: a PICTURE-ONLY post (post-picture.mjs) -- its attachment drawn in its own card where its words would", + " be, never in the slot; a post it answers or quotes that is one gets its own beat before the read. auto: a post", + " whose words are only @mentions and links, with an attachment; on / off force it (parent.<i>., quoted. for those).", ...ROLES_LINES, ...REREAD_LINES, " umtool posts set-item | roles | narrate | reread | fx <project> … --in-take <take> A TAKE-SCOPED EDIT: the same", @@ -850,7 +854,7 @@ const fileArg = (raw, k) => { }; /** The ref keys a context post may carry (post-item.mjs refErrors). */ -const REF_KEYS = ["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via"]; +const REF_KEYS = ["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via", "pictureOnly"]; /** A context post given on the command line: JSON, or `@<file>.json`. Its `media` may name project files. */ const refArg = (raw, k) => { @@ -960,7 +964,16 @@ export function postItemPatchOf(pairs) { else if (/^links?\.\d+$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).ref = OFF.has(v) ? null : refArg(raw, k)); else if (/^links?\.\d+\.media$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).media = OFF.has(v) || v === "" ? null : raw.split(",").map((f) => fileArg(f, k))); else if (/^links?\.\d+\.transcript$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).transcript = OFF.has(v) || raw.trim() === "" ? null : raw); - else if (k === "quoted.paraphrase") out.quoted = { paraphrase: paraphraseOf(raw) }; + else if (k === "quoted.paraphrase") out.quoted = { ...(out.quoted ?? {}), paraphrase: paraphraseOf(raw) }; + // PICTURE-ONLY (post-picture.mjs): on, off, or auto (the rule: only @mentions and links, with an attachment). + else if (k === "pictureOnly" || k === "quoted.pictureOnly" || /^parents?\.\d+\.pictureOnly$/.test(k)) { + const v = raw.trim().toLowerCase(); + if (!["on", "off", "auto", "true", "false", ""].includes(v)) throw new CliError(`${k}= takes on, off or auto`); + const val = v === "on" || v === "true" ? true : v === "off" || v === "false" ? false : null; + if (k === "pictureOnly") out.pictureOnly = val; + else if (k === "quoted.pictureOnly") out.quoted = { ...(out.quoted ?? {}), pictureOnly: val }; + else ((out.parents ??= {})[k.split(".")[1]] ??= {}).pictureOnly = val; + } else if (/^parents?\.\d+\.paraphrase$/.test(k)) ((out.parents ??= {})[k.split(".")[1]] ??= {}).paraphrase = paraphraseOf(raw); else if (/^media\.\d+\.blur(\.(strength|label|boxes|band|style))?$/.test(k)) { // The censoring blur (post-censor.mjs): on|off, its strength, its label (off: none), its boxes (x,y,w,h;…|off), @@ -992,7 +1005,7 @@ export function postItemPatchOf(pairs) { } } else { const m = /^media\.(\d+)\.(start|end|mute|crop|push|trim|enter)$/.exec(k); - if (!m) throw new CliError(`${pair}: not a post item knob (hold=, layout=, panel=, redact=, scene=, follow=, follow.dim|ease=, thread=, thread.parent|quoted|carry|reveal|shrink|dim|seconds|pan|group|map=, media.add=, media.<i>=off, media.<i>.start|end|mute|crop|push|trim|enter=, media.<i>.blur[.strength|.label|.boxes|.band|.style]=, media.<i>.censor=, quoted.paraphrase=, parent.<i>=<ref>|off, parent.<i>.media=, parent.<i>.paraphrase=, link.add=, link.<i>=<ref>|off, link.<i>.media=, link.<i>.transcript=)`); + if (!m) throw new CliError(`${pair}: not a post item knob (hold=, layout=, panel=, redact=, scene=, follow=, follow.dim|ease=, thread=, thread.parent|quoted|carry|reveal|shrink|dim|seconds|pan|group|map=, media.add=, media.<i>=off, media.<i>.start|end|mute|crop|push|trim|enter=, media.<i>.blur[.strength|.label|.boxes|.band|.style]=, media.<i>.censor=, quoted.paraphrase=, parent.<i>=<ref>|off, parent.<i>.media=, parent.<i>.paraphrase=, pictureOnly=, parent.<i>.pictureOnly=, quoted.pictureOnly=, link.add=, link.<i>=<ref>|off, link.<i>.media=, link.<i>.transcript=)`); const media = (out.media ??= {}); const one = (media[m[1]] ??= {}); if (m[2] === "start" || m[2] === "end") one[m[2]] = OFF.has(v) || v === "" ? null : Number(raw); diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -33,10 +33,11 @@ import { isNarrated, narrationSchedule, postNarrationFiles, postNarrationKnobs, validatePostNarration, } from "./post-narration.mjs"; import { BAR_CSS, barsHtml, hasMarks, projectRedactOf, redactEntry, redactSceneRef, redactionOn, validatePostsRender } from "./post-redact.mjs"; -import { blurErrors } from "./post-censor.mjs"; +import { blurErrors, blurOn } from "./post-censor.mjs"; import { WORD_ZOOM_HIGHLIGHT_ALPHA, cardTokens, cardWordsOf, findMatch, targetTextOf, validatePostFx } from "./word-zoom.mjs"; import { FOLLOW_MIN_SIZE, followBlocks, followKnobs, followSchedule, scopeBlocks, validatePostFollow } from "./read-follow.mjs"; -import { panelSchedule, validatePostThread } from "./post-thread.mjs"; +import { panelSchedule, pictureBeats, threadLayout, validatePostThread } from "./post-thread.mjs"; +import { isPictureOnly, pictureBeatSeconds, pictureMediaOf, pictureRuleEntry, validatePictureOnly, validatePictureReplyRender } from "./post-picture.mjs"; import { joinLayerHtml, validatePostJoin, validatePostJoinRender } from "./post-join.mjs"; import { validatePostLinkVisit, validatePostLinkVisitRender, visitsEnd } from "./post-link-visit.mjs"; import { progressErrors } from "./post-progress.mjs"; @@ -123,6 +124,11 @@ export const refMediaOf = (ref) => (Array.isArray(ref?.media) ? ref.media.filter /** Whether a context post is drawn at all: it has words, or an attachment (an image-only reply). */ export const refShown = (ref) => !!contextText(ref).trim() || refMediaOf(ref).length > 0; +/** Whether the item's OWN post is picture-only (post-picture.mjs): its attachment drawn in its card, never in the slot. */ +export const ownPictureOnly = (entry) => isPictureOnly(entry, { text: cardText(entry) }); +/** Whether a context post (a parent, the quoted post) is picture-only (post-picture.mjs). */ +export const refPictureOnly = (ref) => isPictureOnly(ref); + /** Seconds to read the post itself (the rule above, its first line). */ export function readSeconds(entry) { return clamp(POST_READ.lead + wordCount(cardText(entry)) / POST_READ.wps, POST_READ.min, POST_READ.max); @@ -145,11 +151,16 @@ export function contextReadSeconds(ref) { return clamp(wordCount(contextText(ref)) / POST_READ.wps, POST_CONTEXT_READ.min, POST_CONTEXT_READ.max); } -/** The whole reading time: the post and its context. */ -export function readingSeconds(entry) { - let s = readSeconds(entry); - for (const p of parentsOf(entry)) s += contextReadSeconds(p); - if (isObj(entry?.quoted)) s += contextReadSeconds(entry.quoted); +/** + * The whole reading time: the post and its context. A PICTURE-ONLY post (post-picture.mjs) is its picture's beat + * instead of its words' reading (`render`: the cut's rule). + */ +export function readingSeconds(entry, render = undefined) { + const e = pictureRuleEntry(entry, render); + const ctx = (p) => (refPictureOnly(p) ? pictureBeatSeconds(refMediaOf(p), render) : contextReadSeconds(p)); + let s = ownPictureOnly(e) ? pictureBeatSeconds(pictureMediaOf(e), render) : readSeconds(e); + for (const p of parentsOf(e)) s += ctx(p); + if (isObj(e?.quoted)) s += ctx(e.quoted); return round3(s); } @@ -175,9 +186,9 @@ export function mediaSeconds(m) { return POST_IMAGE_SECONDS; } -/** The attachments as they play: a grid of the images (mediaLayout "grid", 2-4 of them) is one step. */ +/** The attachments as they play: a grid of the images (mediaLayout "grid", 2-4 of them) is one step. A picture-only post's are in its card (post-picture.mjs): none. */ export function mediaSteps(entry) { - const media = Array.isArray(entry?.media) ? entry.media.filter(isObj).slice(0, POST_MEDIA_MAX) : []; + const media = Array.isArray(entry?.media) && !ownPictureOnly(entry) ? entry.media.filter(isObj).slice(0, POST_MEDIA_MAX) : []; const indexed = media.map((m, i) => ({ ...m, i })); const images = indexed.filter((m) => m.kind === "image"); if (entry?.mediaLayout === "grid" && images.length >= 2) { @@ -273,14 +284,20 @@ export function postItemPlan(entry, render = undefined, { prev = null, scene = n * @param {Record<string, any> | null} [mediaScene] */ function planOf(entry, render, hold, prev = null, scene = null, mediaScene = null, join = null) { + // PICTURE-ONLY posts (post-picture.mjs): the cut's rule laid on (off: none is). + entry = pictureRuleEntry(entry, render); const narrated = isNarrated(entry); const k = postNarrationKnobs(entry, render); // THE JOIN (post-join.mjs) comes first: the read starts after it (the item a join's seconds longer). - const pre = join && fin(join.seconds) ? join.seconds : 0; + const joinPre = join && fin(join.seconds) ? join.seconds : 0; + // Then a PICTURE-ONLY context post's BEAT (post-thread.mjs pictureBeats): shown alone, the read after it -- its + // start moved, the take never re-made. Looked for only when a context post is picture-only. + const beats = narrated && followKnobs(entry, render).on && hasPictureContext(entry) ? pictureBeats(entry, render, threadLayout(entry, render, { prev, scene }), joinPre) : []; + const pre = round3(joinPre + (beats.length ? beats[beats.length - 1].t1 - joinPre : 0)); const sch = narrated ? narrationSchedule(entry, render, { pre }) : null; // Its read-follow (read-follow.mjs): each block's start on the item's clock -- null when it is off. `prev`: the // item before it in the cut (post-thread.mjs: a parent that is that item is carried in, not cut to). - const follow = followSchedule(entry, render, { hold, narration: sch, prev, scene, mediaScene, join }); + const follow = followSchedule(entry, render, { hold, narration: sch, prev, scene, mediaScene, join, ...(beats.length ? { beats } : {}) }); const extra = { ...(sch ? { narration: sch } : {}), ...(follow ? { follow } : {}) }; if (sch && k.attach === "after") { const voiceOnly = round3(sch.at + sch.seconds + k.tail); @@ -289,9 +306,10 @@ function planOf(entry, render, hold, prev = null, scene = null, mediaScene = nul const total = hold ?? round3(voiceOnly + media + (all.length ? 0 : k.linger)); const plan = planSteps(all, voiceOnly, total); const panel = follow ? panelSchedule(entry, follow, total) : null; - return { ...plan, reading: round3(Math.min(voiceOnly, total)), total, ...extra, ...(panel ? { panel } : {}) }; + const pics = picturesOf(entry, follow); + return { ...plan, reading: round3(Math.min(voiceOnly, total)), total, ...extra, ...(panel ? { panel } : {}), ...(pics.length ? { pics } : {}) }; } - const span = sch ? round3(sch.at + sch.seconds + k.tail + k.linger) : readingSeconds(entry); + const span = sch ? round3(sch.at + sch.seconds + k.tail + k.linger) : readingSeconds(entry, render); // ITS OWN ATTACHMENTS come in with ITS OWN POST (ownMediaEnterAt): a thread read's parents and quotes first, his // attachment when his words begin -- a video starts there, its sound too, its trim fitted to what is left. const enter = ownMediaEnterAt(entry, follow, { mediaScene }); @@ -322,7 +340,29 @@ function planOf(entry, render, hold, prev = null, scene = null, mediaScene = nul } // A CONTEXT POST's attachment (post-thread.mjs panelSchedule): over the slot while it is on screen. const panel = follow ? panelSchedule(entry, follow, total) : null; - return { ...plan, reading: 0, total, ...extra, ...(panel ? { panel } : {}), ...(enter > 0 && plan.steps.length ? { enter } : {}) }; + // A PICTURE-ONLY post's picture in its card (post-picture.mjs): the posts that have one, for the build's overlay. + const inCard = picturesOf(entry, follow); + return { ...plan, reading: 0, total, ...extra, ...(panel ? { panel } : {}), ...(enter > 0 && plan.steps.length ? { enter } : {}), ...(inCard.length ? { pics: inCard } : {}) }; +} + +/** Whether any context post of the item (a parent, the quoted post) is picture-only. */ +const hasPictureContext = (entry) => parentsOf(entry).some(refPictureOnly) || (isObj(entry?.quoted) && refPictureOnly(entry.quoted)); + +/** + * THE PICTURES IN CARDS (post-picture.mjs), pure: `[{ scope, media }]` -- each picture-only post the card draws + * (his own: "post"; a parent: "parent:<i>"; the quoted post: "quoted") with its attachments, the first drawn in its + * card. The build plays a GIF's or a video's over its place while its card is at full size and still; Play plays it + * in the card. A threaded card's hidden tile draws none. + */ +export function picturesOf(entry, follow = null) { + const hidden = new Set((follow?.thread?.tiles ?? []).filter((t) => t.mode === "hidden").map((t) => t.scope)); + const out = []; + if (ownPictureOnly(entry)) out.push({ scope: "post", media: pictureMediaOf(entry) }); + parentsOf(entry).forEach((p, i) => { + if (refPictureOnly(p) && !hidden.has(`parent:${i}`)) out.push({ scope: `parent:${i}`, media: pictureMediaOf(p) }); + }); + if (isObj(entry?.quoted) && refPictureOnly(entry.quoted) && !hidden.has("quoted")) out.push({ scope: "quoted", media: pictureMediaOf(entry.quoted) }); + return out; } /** Where an item's own attachments may come in (`media[0].enter`): with its own post (the default), or with the item. */ @@ -350,7 +390,9 @@ export function ownMediaEnterAt(entry, follow, { mediaScene = null } = {}) { const post = blocks.filter((b) => b.scope === "post"); if (!post.length) return 0; const at = Math.min(...post.map((b) => b.start)); - return blocks.some((b) => b.scope !== "post" && b.start < at - 1e-6) ? round3(at) : 0; + // A picture-only context post's BEAT before his words (post-picture.mjs) is a piece read before them too. + const beat = (follow.beats ?? []).some((b) => fin(b.t0) && b.t0 < at - 1e-6); + return beat || blocks.some((b) => b.scope !== "post" && b.start < at - 1e-6) ? round3(at) : 0; } /** Steps placed from `at0`, cut at `total` (postItemPlan's walk). */ @@ -589,6 +631,8 @@ export function validatePostItem(e) { errors.push(...validatePostLinkVisit(e)); // Its progress bar (post-progress.mjs): auto, on or off (absent: the cut's). errors.push(...progressErrors(e.progress, `timeline ${e?.id ?? "?"}.progress`)); + // Picture-only (post-picture.mjs): its own, a parent's, the quoted post's -- true or false. + errors.push(...validatePictureOnly(e)); return errors; } @@ -628,7 +672,7 @@ export function validatePostItems(manifest) { const errors = []; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; for (const e of tl) if (e?.type === "post") errors.push(...validatePostItem(e)); - errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(manifest?.render), ...validatePostJoinRender(manifest?.render), ...validatePostLinkVisitRender(manifest?.render), ...validatePostMapRender(manifest?.render)); + errors.push(...validatePostsRender(manifest?.render), ...validatePostSceneRender(manifest?.render), ...validatePostPanelRender(manifest?.render), ...validatePostJoinRender(manifest?.render), ...validatePostLinkVisitRender(manifest?.render), ...validatePostMapRender(manifest?.render), ...validatePictureReplyRender(manifest?.render)); // A word zoom on a word the project's list blanks (the corpus's and a post's markup are checked by the build). const own = { terms: projectRedactOf(manifest?.render) }; for (const e of tl) if (e?.type === "post") errors.push(...fxRedactionErrors(e, own)); @@ -692,6 +736,17 @@ const CHAR_EM = 0.5; const LINE = 1.32; /** The text sizes tried, largest first, in px of a 1080-high frame (scaled to the box). */ export const POST_TEXT_SIZES = Object.freeze([46, 42, 38, 34, 30, 27, 24, 22, 20, 18]); +/** + * A LONG READ's words on a card ALONE (operator, 5 Nov, mid-15's "novel": "bigger text for the novel"): px of a + * 1080-high landscape frame. Words that do not fit the card at any size of POST_TEXT_SIZES, read with read-follow (it + * pans them), are drawn at this size -- never shrunk to fit; beside an attachment they keep FOLLOW_MIN_SIZE. + */ +export const POST_LONG_READ_SIZE = 36; +/** The size a following card alone draws words that do not fit (POST_LONG_READ_SIZE scaled), else null. */ +export function longReadSize(L, { width, height }, follow, fits = L.fits) { + if (!follow || L.mode !== "text" || fits || width < height) return null; + return Math.round(POST_LONG_READ_SIZE * (height / 1080)); +} /** Below this size the words beside an attachment are too small: the card reads first, then the attachments play large. */ export const POST_SIDE_MIN = 26; @@ -790,9 +845,10 @@ export const POST_PANEL_DEFAULTS = Object.freeze({ wide: 2.0, place: "top" }); /** What the slot shows over the item: its own attachments, else the context posts' (post-thread.mjs panelSchedule). */ export function slotMediaOf(entry) { - const own = Array.isArray(entry?.media) ? entry.media.filter(isObj) : []; + // A picture-only post's attachment is drawn in its card (post-picture.mjs), never in the slot. + const own = Array.isArray(entry?.media) && !ownPictureOnly(entry) ? entry.media.filter(isObj) : []; if (own.length) return own; - const refs = [...[...parentsOf(entry)].reverse(), ...(isObj(entry?.quoted) ? [entry.quoted] : []), ...linksOf(entry)]; + const refs = [...[...parentsOf(entry)].reverse(), ...(isObj(entry?.quoted) ? [entry.quoted] : []), ...linksOf(entry)].filter((r) => !refPictureOnly(r)); return refs.flatMap(refMediaOf); } @@ -812,6 +868,8 @@ export function panelOf(entry, rule = null) { /** The item with the CUT's wide-attachment rule laid on (`panel` set when the cut's rule differs from the defaults'). */ export function panelEntry(entry, render) { + // PICTURE-ONLY posts (post-picture.mjs): the cut's rule laid on first (off: none is) -- the entry as it is, else. + entry = pictureRuleEntry(entry, render); const rule = isObj(render?.posts?.panel) ? render.posts.panel : null; if (!rule || !isObj(entry) || POST_PANELS.includes(entry.panel)) return entry; const p = panelOf(entry, rule); @@ -985,6 +1043,39 @@ export function nameHtml(who, { redact, cls = "" }) { } /** + * A PICTURE-ONLY post's picture in its card (post-picture.mjs): its first attachment where its words would be, at the + * column's `width` (its aspect and crop kept, at most `maxH` tall), `[data-post-pic="<scope>"]`. An image is drawn by + * the page (a censored one blurred whole); a GIF's or a video's still (`posters`: src → url) -- the build plays it + * over that place while the card is still (post-render.mjs) -- or, `live` (Play), the video itself, looping. With no + * `mediaUrl` (src → url) its place only. More than one attachment: "+N" over its corner. + */ +/** + * @param {string} scope + * @param {Array<Record<string, any>>} media + * @param {{ width: number, maxH: number, k: number, mediaUrl?: ((src: string) => string) | null, posters?: Record<string, string>, live?: boolean, line?: string }} o + */ +export function pictureHtml(scope, media, { width, maxH, k, mediaUrl = null, posters = {}, live = false, line = "#333" }) { + const m = media[0]; + if (!m) return ""; + const crop = Array.isArray(m.crop) && m.crop.length === 4 ? m.crop : null; + const iw = (fin(m.width) ? m.width : 16) * (crop ? crop[2] : 1); + const ih = (fin(m.height) ? m.height : 9) * (crop ? crop[3] : 1); + const sc = Math.min(Math.max(2, width) / iw, Math.max(2, maxH) / ih); + const w = Math.max(2, Math.floor((iw * sc) / 2) * 2); + const h = Math.max(2, Math.floor((ih * sc) / 2) * 2); + const url = typeof mediaUrl === "function" ? mediaUrl(m.src) : null; + const moving = m.kind === "gif" || m.kind === "video"; + // The source scaled so its crop fills the box, moved so the crop's corner is the box's. + const fw = crop ? w / crop[2] : w; + const fh = crop ? h / crop[3] : h; + const pos = `width:${Math.round(fw)}px;height:${Math.round(fh)}px;${crop ? `margin-left:${-Math.round(crop[0] * fw)}px;margin-top:${-Math.round(crop[1] * fh)}px;` : ""}${blurOn(m) ? `filter:blur(${Math.round(26 * k)}px);` : ""}`; + const src = moving ? (live ? url : posters[m.src] ?? null) : url; + const inner = !src ? "" : moving && live ? `<video src="${esc(src)}" muted loop playsinline autoplay preload="auto" style="${pos}display:block"></video>` : `<img src="${esc(src)}" alt="" style="${pos}display:block">`; + const more = media.length > 1 ? `<span class="picmore">+${media.length - 1}</span>` : ""; + return `<div class="tpic" data-post-pic="${esc(scope)}" data-pic-kind="${esc(m.kind)}" data-pic-src="${esc(m.src)}" style="width:${w}px;height:${h}px;border-color:${line}">${inner}${more}</div>`; +} + +/** * The card's HTML: one page `width` × `height` (the box the item fills), the * card drawn in the deck's palette and faces, the attachments' slot left as a * well for the media to be laid into (the build overlays the files; Play the @@ -1012,9 +1103,11 @@ export function nameHtml(who, { redact, cls = "" }) { * highlight?: { scope: string, from: number, to: number, color: string } | null, * redaction?: { terms: Array<{term: string, wholeWord?: boolean}>, markup?: Record<string, any> } | null, follow?: boolean, * thread?: { tiles?: Array<{ scope: string, mode: string }> } | null, - * join?: { A?: { x: number, y: number, width: number, height: number }, slotA?: Record<string, number> | null, fromUrl?: string | null, size?: number | null, same?: boolean, plain?: boolean, headSize?: number | null } | null }} o + * join?: { A?: { x: number, y: number, width: number, height: number }, slotA?: Record<string, number> | null, fromUrl?: string | null, size?: number | null, same?: boolean, plain?: boolean, headSize?: number | null } | null, + * mediaUrl?: ((src: string) => string) | null, posters?: Record<string, string>, livePics?: boolean }} o + * `mediaUrl`, `posters`, `livePics`: a PICTURE-ONLY post's picture in its card (pictureHtml). */ -export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, phase = "read", parentShotUrl = null, transparent = false, avatars = {}, highlight = null, redaction = null, follow = false, thread = null, join = null }) { +export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, phase = "read", parentShotUrl = null, transparent = false, avatars = {}, highlight = null, redaction = null, follow = false, thread = null, join = null, mediaUrl = null, posters = {}, livePics = false }) { const hlOf = (scope) => (highlight && highlight.scope === scope ? highlight : null); // THREADED (post-thread.mjs): the conversation as a column of tiles -- `thread` the layout's tiles // (threadLayout, or the plan's follow.thread), each `{ scope, mode }`; a hidden one is not drawn. @@ -1025,6 +1118,11 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p // mapped on the words as written (the plan's are), whose indices the redaction's bars keep. const fmap = follow ? followBlocks(entry) : null; const blk = (scope) => (fmap ? scopeBlocks(fmap, scope) : null); + // PICTURE-ONLY posts (post-picture.mjs), judged on the words as written (before any bar is drawn over them). + const picOwn = ownPictureOnly(entry); + const picPar = parentsOf(entry).map(refPictureOnly); + const picQ = isObj(entry.quoted) && refPictureOnly(entry.quoted); + const anyPic = picOwn || picQ || picPar.some(Boolean); // AS PUBLISHED (post-redact.mjs): every redacted match drawn as a bar, its letters never in the page. The // marks keep the text's length and its spaces, so the card's word indices (a word zoom's) are the original's. entry = redactEntry(entry, redaction); @@ -1034,12 +1132,18 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const k = height / 1080; // Following, the words never shrink below a readable size to fit: the card pans them instead. const followMin = Math.round(FOLLOW_MIN_SIZE * k); - const size = follow ? Math.max(L.size, followMin) : L.size; + // A LONG READ on a card alone: at a reading size, panned -- never shrunk to fit (longReadSize). + const longRead = longReadSize(L, { width, height }, follow); + const size = follow ? Math.max(L.size, longRead ?? followMin) : L.size; const authors = cardAuthors(entry); const blurred = authors.filter((a) => a.redact && a.handle).map((a) => a.handle); const red = (where) => authors.find((a) => a.where === where)?.redact ?? false; const cardBg = mixHex(pal.bg, pal.fg, 0.07); const line = mixHex(pal.bg, pal.fg, 0.18); + // A picture-only post's picture where its words would be; its mention-only words small, as X's reply-to line. + const picIn = (scope, ref, w, maxH) => pictureHtml(scope, pictureMediaOf(ref), { width: w, maxH, k, mediaUrl, posters, live: livePics, line }); + const menSize = Math.round(22 * k); + const ownPicMax = Math.max(Math.round(140 * k), L.card.height - 2 * L.pad - Math.round(250 * k) - Math.min(2, parentsOf(entry).length) * Math.round(130 * k) - (isObj(entry.quoted) ? Math.round(170 * k) : 0)); const own = { author: entry.author, handle: entry.handle }; const ownRed = red("author"); const strip = phase === "media" && L.mode === "stack"; @@ -1059,7 +1163,7 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const r = red(`parents[${i}]`); const subject = !r && subjectsOf(entry).some((h) => String(h).toLowerCase() === String(p.handle ?? "").replace(/^@/, "").toLowerCase()); ctx.push( - `<div class="parent" data-post-parent="${i}"${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: Math.round(44 * k), accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody"><div class="phead">${nameHtml(p, { redact: r })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span>${paraLabel(p)}</div><div class="ptext"${isParaphrased(p) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(p) || (p.url ? "(not archived)" : ""), blurred, contextText(p) ? `parent:${i}` : null, hlOf(`parent:${i}`), blk(`parent:${i}`))}</div></div></div>`, + `<div class="parent" data-post-parent="${i}"${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: Math.round(44 * k), accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody"><div class="phead">${nameHtml(p, { redact: r })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span>${paraLabel(p)}</div><div class="ptext${picPar[i] ? " pmen" : ""}"${isParaphrased(p) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(p) || (p.url ? "(not archived)" : ""), blurred, contextText(p) ? `parent:${i}` : null, hlOf(`parent:${i}`), blk(`parent:${i}`))}</div>${picPar[i] ? picIn(`parent:${i}`, p, L.card.width - 2 * L.pad - Math.round(58 * k), Math.round(240 * k)) : ""}</div></div>`, ); } if (!parents.length && parentShotUrl) ctx.push(`<div class="pshot" data-post-parent-shot=""><img src="${esc(parentShotUrl)}" alt=""></div>`); @@ -1068,14 +1172,14 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p } const q = isObj(entry.quoted) ? entry.quoted : null; const quoted = q - ? `<div class="quoted" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round(30 * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted") })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span>${paraLabel(q)}</div><div class="qtext"${isParaphrased(q) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(q), blurred, "quoted", hlOf("quoted"), blk("quoted"))}</div></div>` + ? `<div class="quoted" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round(30 * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted") })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span>${paraLabel(q)}</div><div class="qtext${picQ ? " pmen" : ""}"${isParaphrased(q) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(q), blurred, "quoted", hlOf("quoted"), blk("quoted"))}</div>${picQ ? picIn("quoted", q, L.card.width - 2 * L.pad - Math.round(34 * k), Math.round(280 * k)) : ""}</div>` : ""; const repost = entry.repostedBy ? `<div class="repost" data-post-repost="">&#x21bb; ${esc(str(entry.repostedBy.author) || `@${entry.repostedBy.handle}`)} reposted</div>` : ""; const head = `<div class="head"${ownRed ? ' data-redacted=""' : ""}>${avatarHtml(own, { redact: ownRed, size: Math.round(64 * k), accent: ownRed ? undefined : pal.accent, img: pic(own) })}<div class="hwho">${nameHtml(own, { redact: ownRed, cls: "big" })}<div class="date">${esc(cardDate(entry.date))}</div></div><div class="mark">${esc(PLATFORM_NAME[entry.platform] ?? "")}</div></div>`; // A card alone (text, or a stack's reading) is as tall as its words, centred in its box; beside the attachments, the box's height. - const card = (box) => `<div class="card" data-post-card="${esc(entry.id)}" style="left:${box.x}px;${L.mode === "side" ? `top:${box.y}px;height:${box.height}px` : `top:${box.y + box.height / 2}px;transform:translateY(-50%);max-height:${box.height}px`};width:${box.width}px">${repost}${ctx.length ? `<div class="context">${ctx.join("")}</div>` : ""}${head}<div class="words" data-post-words="" style="font-size:${size}px">${follow ? `<div class="wflow" data-post-flow="">${wordsHtml(cardText(entry), blurred, "post", hlOf("post"), blk("post"))}</div><div class="wfade" data-post-fade="top"></div><div class="wfade" data-post-fade="bottom"></div>` : wordsHtml(cardText(entry), blurred, "post", hlOf("post"))}</div>${quoted}${counts ? `<div class="counts" data-post-counts="">${counts}</div>` : ""}</div>`; + const card = (box) => `<div class="card" data-post-card="${esc(entry.id)}" style="left:${box.x}px;${L.mode === "side" ? `top:${box.y}px;height:${box.height}px` : `top:${box.y + box.height / 2}px;transform:translateY(-50%);max-height:${box.height}px`};width:${box.width}px">${repost}${ctx.length ? `<div class="context">${ctx.join("")}</div>` : ""}${head}<div class="words${picOwn ? " pmen" : ""}" data-post-words="" style="font-size:${picOwn ? menSize : size}px">${follow ? `<div class="wflow" data-post-flow="">${wordsHtml(cardText(entry), blurred, "post", hlOf("post"), blk("post"))}</div><div class="wfade" data-post-fade="top"></div><div class="wfade" data-post-fade="bottom"></div>` : wordsHtml(cardText(entry), blurred, "post", hlOf("post"))}</div>${picOwn ? picIn("post", entry, L.card.width - 2 * L.pad, ownPicMax) : ""}${quoted}${counts ? `<div class="counts" data-post-counts="">${counts}</div>` : ""}</div>`; const stripHtml = L.strip ? `<div class="strip" data-post-strip="" style="left:${L.strip.x}px;top:${L.strip.y}px;width:${L.strip.width}px;height:${L.strip.height}px">${avatarHtml(own, { redact: ownRed, size: Math.round(56 * k), accent: ownRed ? undefined : pal.accent, img: pic(own) })}<div class="hwho">${nameHtml(own, { redact: ownRed, cls: "big" })}<div class="date">${esc(cardDate(entry.date))}</div></div><div class="sline">${wordsHtml(cardText(entry).split("\n")[0].slice(0, 140) + (cardText(entry).length > 140 ? "…" : ""), blurred)}</div></div>` : ""; @@ -1131,10 +1235,12 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const size = sizeFor(words || " ", innerW - av - Math.round(16 * k), innerH - 90 * k); for (const kk of cut(scope) ?? []) cutCss.push(`[data-thread-tile="${scope}"] [data-post-block="${kk}"]`); const med = refMediaOf(p); + // PICTURE-ONLY (post-picture.mjs): its picture in this tile, not a chip naming what the slot shows. + const pictured = refPictureOnly(p); const chip = med.length ? `<span class="plabel" data-thread-media="${med.length}">${med[0].kind === "image" ? (med.length > 1 ? `${med.length} photos` : "photo") : med[0].kind}</span>` : ""; const rel = relationHtml(t0(scope)); tileHtml.push( - `<div class="tslot" data-thread-slot="${scope}"><div class="tile tparent" data-thread-tile="${scope}" data-thread-mode="${mode}" ${attr}${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: av, accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody">${rel}<div class="phead">${nameHtml(p, { redact: r, cls: "big" })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span>${mode === "excerpt" ? '<span class="plabel" data-thread-excerpt="">excerpt</span>' : ""}${scope.startsWith("linked:") ? '<span class="plabel" data-thread-linked="">linked</span>' : ""}${chip}${paraLabel(p)}</div>${words ? `<div class="ptext tt"${isParaphrased(p) ? ' data-post-paraphrase=""' : ""} style="font-size:${size}px">${wordsHtml(words, blurred, scope, hlOf(scope), blk(scope))}</div>` : ""}</div></div></div>`, + `<div class="tslot" data-thread-slot="${scope}"><div class="tile tparent" data-thread-tile="${scope}" data-thread-mode="${mode}" ${attr}${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: av, accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody">${rel}<div class="phead">${nameHtml(p, { redact: r, cls: "big" })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span>${mode === "excerpt" ? '<span class="plabel" data-thread-excerpt="">excerpt</span>' : ""}${scope.startsWith("linked:") ? '<span class="plabel" data-thread-linked="">linked</span>' : ""}${pictured ? "" : chip}${paraLabel(p)}</div>${words ? `<div class="ptext tt${pictured ? " pmen" : ""}"${isParaphrased(p) ? ' data-post-paraphrase=""' : ""} style="font-size:${pictured ? menSize : size}px">${wordsHtml(words, blurred, scope, hlOf(scope), blk(scope))}</div>` : ""}${pictured ? picIn(scope, p, innerW - av - Math.round(16 * k), Math.round(innerH * 0.6)) : ""}</div></div></div>`, ); }; for (let i = parents.length - 1; i >= 0; i -= 1) refTile(`parent:${i}`, parents[i], `parents[${i}]`, `data-post-parent="${i}"`); @@ -1148,17 +1254,19 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const qsize = sizeFor(contextText(q), innerW - Math.round(36 * k), innerH - 140 * k); for (const kk of cut("quoted") ?? []) cutCss.push(`[data-thread-tile="quoted"] [data-post-block="${kk}"]`); const label = qabove ? '<span class="plabel" data-thread-quoted-label="">quoted</span>' : ""; - quotedTile = `<div class="tslot" data-thread-slot="quoted"${qabove ? ' data-thread-above=""' : ""}><div class="tile quoted${qabove ? " tabove" : ""}" data-thread-tile="quoted" data-thread-mode="${qmode}" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round((qabove ? 44 : 36) * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted"), cls: qabove ? "big" : "" })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span>${label}${qmode === "excerpt" ? '<span class="plabel" data-thread-excerpt="">excerpt</span>' : ""}${paraLabel(q)}</div><div class="qtext tt"${isParaphrased(q) ? ' data-post-paraphrase=""' : ""} style="font-size:${qabove ? qsize : Math.round(qsize * 0.9)}px">${wordsHtml(contextText(q), blurred, "quoted", hlOf("quoted"), blk("quoted"))}</div></div></div>`; + quotedTile = `<div class="tslot" data-thread-slot="quoted"${qabove ? ' data-thread-above=""' : ""}><div class="tile quoted${qabove ? " tabove" : ""}" data-thread-tile="quoted" data-thread-mode="${qmode}" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round((qabove ? 44 : 36) * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted"), cls: qabove ? "big" : "" })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span>${label}${qmode === "excerpt" ? '<span class="plabel" data-thread-excerpt="">excerpt</span>' : ""}${paraLabel(q)}</div><div class="qtext tt${picQ ? " pmen" : ""}"${isParaphrased(q) ? ' data-post-paraphrase=""' : ""} style="font-size:${picQ ? menSize : qabove ? qsize : Math.round(qsize * 0.9)}px">${wordsHtml(contextText(q), blurred, "quoted", hlOf("quoted"), blk("quoted"))}</div>${picQ ? picIn("quoted", q, innerW - Math.round(36 * k), Math.round(innerH * (qabove ? 0.6 : 0.4))) : ""}</div></div>`; } if (qabove && quotedTile) { tileHtml.push(quotedTile); quotedTile = ""; } const own = cardText(entry); - const psize = own.trim() ? sizeFor(own, innerW, innerH - 170 * k) : size; + // A LONG READ alone (longReadSize): his words at a reading size, panned, when they do not fit his tile. + const pfit = fitSize(own, innerW, innerH - 170 * k, k); + const psize = own.trim() ? Math.max(followMin, pfit.size, pfit.fits ? 0 : longReadSize(L, { width, height }, true, false) ?? 0) : size; const lead = !parents.length && (parentShotUrl || entry.replyingTo) ? ctx.join("") : ""; tileHtml.push( - `<div class="tslot" data-thread-slot="post"><div class="tile tpost" data-thread-tile="post">${repost}${lead}${relationHtml(t0("post"))}${head}<div class="twords" style="font-size:${psize}px">${wordsHtml(own, blurred, "post", hlOf("post"), blk("post"))}</div>${quotedTile}${counts ? `<div class="counts" data-post-counts="">${counts}</div>` : ""}</div></div>`, + `<div class="tslot" data-thread-slot="post"><div class="tile tpost" data-thread-tile="post">${repost}${lead}${relationHtml(t0("post"))}${head}<div class="twords${picOwn ? " pmen" : ""}" style="font-size:${picOwn ? menSize : psize}px">${wordsHtml(own, blurred, "post", hlOf("post"), blk("post"))}</div>${picOwn ? picIn("post", entry, innerW, Math.round(innerH * 0.62)) : ""}${quotedTile}${counts ? `<div class="counts" data-post-counts="">${counts}</div>` : ""}</div></div>`, ); // THE SCENE (post-conversation.mjs): the posts the run left on screen, drawn as they were -- never read (no // blocks, no word spans), their words redacted by the same terms, their authors blurred by their own item's rule. @@ -1188,7 +1296,7 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p // part reads (links are never read: post-narration.mjs dropUrls). const tc = threaded ? threadCard(L.card) : null; const body = strip ? `${stripHtml}${slot}` : `${tc ? tc.html : card(L.card)}${slot}`; - const minSize = tc ? size : follow ? followMin : Math.round(POST_TEXT_SIZES[POST_TEXT_SIZES.length - 1] * k); + const minSize = tc ? size : follow ? longRead ?? followMin : Math.round(POST_TEXT_SIZES[POST_TEXT_SIZES.length - 1] * k); // A status link is marked (`data-link`, post-link-visit.mjs) only when it names a post the card draws -- a link to // anything else draws as it always did. const drawnIds = new Set([...parentsOf(entry).map((p) => str(p.id)), str(entry?.quoted?.id), ...linksOf(entry).map((l) => str(l.id))].filter(Boolean)); @@ -1237,7 +1345,10 @@ b, .name, .mark { font-family: 'PostSansBold', sans-serif; font-weight: 400; } .counts b { color: ${pal.fg}; } .redact { filter: blur(${Math.round(9 * k)}px); color: ${pal.muted}; } .avatar.redact { background: ${rgbaOf(pal.muted, 0.6)} !important; } -.slot { background: ${rgbaOf("#000000", 0.32)}; border-radius: ${Math.round(14 * k)}px; }${follow ? ` +.slot { background: ${rgbaOf("#000000", 0.32)}; border-radius: ${Math.round(14 * k)}px; }${anyPic ? ` +.tpic { position: relative; overflow: hidden; flex: none; border: 1px solid; border-radius: ${Math.round(14 * k)}px; background: ${rgbaOf("#000000", 0.35)}; margin-top: ${Math.round(10 * k)}px; } +.picmore { position: absolute; right: ${Math.round(10 * k)}px; bottom: ${Math.round(10 * k)}px; padding: ${Math.round(2 * k)}px ${Math.round(10 * k)}px; border-radius: ${Math.round(8 * k)}px; background: ${rgbaOf("#000000", 0.6)}; color: #fff; font-size: ${Math.round(20 * k)}px; } +.pmen, .tile .tt.pmen, .twords.pmen { color: ${pal.muted}; line-height: 1.3; }` : ""}${follow ? ` .words { position: relative; } .wflow { will-change: transform; } .wfade { position: absolute; left: 0; right: 0; height: 1.5em; pointer-events: none; opacity: 0; } @@ -1303,9 +1414,10 @@ export function cardWordsSize(entry, { width, height }, { follow = false, thread const own = cardText(entry); const innerW = L.card.width - 2 * L.pad; const innerH = L.card.height - 2 * L.pad; - return own.trim() ? Math.max(followMin, fitSize(own, innerW, innerH - 170 * k, k).size) : Math.max(L.size, followMin); + const f = fitSize(own, innerW, innerH - 170 * k, k); + return own.trim() ? Math.max(followMin, f.size, f.fits ? 0 : longReadSize(L, { width, height }, true, false) ?? 0) : Math.max(L.size, followMin); } - return follow ? Math.max(L.size, followMin) : L.size; + return follow ? Math.max(L.size, longReadSize(L, { width, height }, true) ?? followMin) : L.size; } /** diff --git a/umtool/report-to-video/post-picture.mjs b/umtool/report-to-video/post-picture.mjs @@ -0,0 +1,134 @@ +// PICTURE-ONLY POSTS (umtool/docs/report-video.md, "Picture-only posts"; operator, 5 Nov, walking the Mr. Obvious mid +// cut at 26:53: "the "It's time to stop" gif shows while Obvious is speaking rather than it being a picture-only +// response like the MW post, we need to handle this because it's a standard type of post"; and, of Kirsche's reply +// that is only a picture of another post: "better inserted inline in Kirsche's message, almost as if it's text, +// becuase it's treated like such"). +// +// A post whose words are nothing but @mentions and links -- "@ObviousRises" and a GIF -- says what it says WITH its +// picture. Such a post (an item, a post it answers, the post it quotes) is PICTURE-ONLY: +// +// - its attachment is drawn INSIDE its own card, where its words would be (the card's width, its aspect kept, a +// GIF or a video playing), in the thread's column like any post -- never in the side slot, never while another +// post's read plays; its mention-only words are drawn small, as the reply-to line X shows; +// - in a thread read, a picture-only context post the read does not read gets its own BEAT before the read: +// lit and shown alone (a GIF or a video its own length, clamped; an image `image` s), the read starting after +// it -- the take is never re-made: the read's start moves (the item's clock gains the beat, as a join's); +// - an item that is picture-only and not narrated lasts its beat. +// +// THE KNOBS: `pictureOnly: true | false` on an item, on `parents[i]`, on `quoted` (absent: the rule above), and the +// cut's `render.posts.pictureReply: { on, image, min, max }` (on: the rule at all; the beat's length). +// +// PURE and dependency-free: the plan, the card, the build, Play, the bench and the writers all read it from here. + +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 clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v)); + +/** The cut's rule (`render.posts.pictureReply`): on; an image's beat; a GIF's or a video's own length clamped to [min, max]. */ +export const PICTURE_REPLY_DEFAULTS = Object.freeze({ on: true, image: 2, min: 1.5, max: 4 }); +export const PICTURE_REPLY_LIMITS = Object.freeze({ image: [0.5, 8], min: [0.5, 8], max: [0.5, 12] }); + +/** A word that is not words: an @mention, a link (a bare domain link too: pic.x.com/…, t.co/…). */ +const MENTION_RE = /^[(\[]?@[A-Za-z0-9_.]{1,64}[)\],.:;!?]*$/; +const URL_RE = /^(?:https?:\/\/\S+|(?:www\.|pic\.(?:x|twitter)\.com\/|t\.co\/)\S*)$/i; + +/** Whether `text` has no words but @mentions and links (whitespace aside). An empty text has none. */ +export function onlyMentions(text) { + return str(text).split(/\s+/).filter(Boolean).every((w) => MENTION_RE.test(w) || URL_RE.test(w)); +} + +/** A post's attachments (an item's `media`, a context post's), the drawable ones. */ +export const pictureMediaOf = (post) => (Array.isArray(post?.media) ? post.media.filter((m) => isObj(m) && typeof m.src === "string" && ["image", "gif", "video"].includes(m.kind)) : []); + +/** + * Whether a post -- an item, a context post (a parent, the quoted post) -- is PICTURE-ONLY: its own `pictureOnly` + * (true needs an attachment), else its words (its paraphrase, when it has one: then it has words) are only @mentions + * and links AND it carries at least one attachment. `text`: the words its card shows (cardText / contextText). + * @param {Record<string, any> | null | undefined} post + * @param {{ text?: string }} [o] + */ +export function isPictureOnly(post, { text = undefined } = {}) { + if (!isObj(post)) return false; + if (post.pictureOnly === false) return false; + if (!pictureMediaOf(post).length) return false; + if (post.pictureOnly === true) return true; + if (str(post.paraphrase).trim()) return false; + return onlyMentions(text === undefined ? str(post.text) : text); +} + +/** The cut's picture-reply rule (`render.posts.pictureReply`), over the defaults. */ +export function pictureReplyKnobs(render) { + const v = isObj(render?.posts) && isObj(render.posts.pictureReply) ? render.posts.pictureReply : {}; + const out = { ...PICTURE_REPLY_DEFAULTS }; + if (typeof v.on === "boolean") out.on = v.on; + for (const k of ["image", "min", "max"]) if (fin(v[k])) out[k] = v[k]; + if (out.max < out.min) out.max = out.min; + return out; +} + +/** Every reason `render.posts.pictureReply` cannot be built. */ +export function validatePictureReplyRender(render) { + const v = isObj(render?.posts) ? render.posts.pictureReply : undefined; + if (v === undefined) return []; + if (!isObj(v)) return ["render.posts.pictureReply must be { on?, image?, min?, max? } (picture-only posts)"]; + const errors = Object.keys(v).filter((k) => !(k in PICTURE_REPLY_DEFAULTS)).map((k) => `render.posts.pictureReply.${k} is not a picture-reply knob (on, image, min, max)`); + if (v.on !== undefined && typeof v.on !== "boolean") errors.push("render.posts.pictureReply.on must be true or false"); + for (const k of ["image", "min", "max"]) { + const [lo, hi] = PICTURE_REPLY_LIMITS[k]; + if (v[k] !== undefined && !(fin(v[k]) && v[k] >= lo && v[k] <= hi)) errors.push(`render.posts.pictureReply.${k} must be ${lo}–${hi} seconds`); + } + if (fin(v.min) && fin(v.max) && v.max < v.min) errors.push("render.posts.pictureReply.max must be at least its min"); + return errors; +} + +/** A post item's `pictureOnly` knobs' errors (its own, each parent's, the quoted post's). */ +export function validatePictureOnly(e) { + const w = `timeline ${e?.id ?? "?"}`; + const errors = []; + const check = (v, where) => { + if (v !== undefined && typeof v !== "boolean") errors.push(`${w}.${where} must be true or false (absent: a post of only @mentions and links with an attachment is picture-only)`); + }; + check(e?.pictureOnly, "pictureOnly"); + (Array.isArray(e?.parents) ? e.parents : []).forEach((p, i) => check(p?.pictureOnly, `parents[${i}].pictureOnly`)); + if (isObj(e?.quoted)) check(e.quoted.pictureOnly, "quoted.pictureOnly"); + return errors; +} + +/** + * The item with the CUT's rule laid on: with `render.posts.pictureReply.on` false, every post that does not say + * otherwise is not picture-only (`pictureOnly: false` set where it is absent); else the item as it is. + */ +export function pictureRuleEntry(entry, render) { + if (!isObj(entry) || pictureReplyKnobs(render).on) return entry; + const off = (p) => (isObj(p) && p.pictureOnly === undefined ? { ...p, pictureOnly: false } : p); + return { + ...off(entry), + ...(Array.isArray(entry.parents) ? { parents: entry.parents.map(off) } : {}), + ...(isObj(entry.quoted) ? { quoted: off(entry.quoted) } : {}), + }; +} + +/** One attachment's own length (a GIF's pass, a video's trimmed span), else null (an image). */ +function ownLength(m) { + if (m?.kind !== "gif" && m?.kind !== "video") return null; + const len = fin(m.seconds) && m.seconds > 0 ? m.seconds : null; + const from = fin(m.start) ? Math.max(0, m.start) : 0; + const to = fin(m.end) ? m.end : len; + return fin(to) && to > from ? Math.min(to, len ?? to) - from : null; +} + +/** + * A picture-only post's BEAT, seconds: its attachments' own lengths (a GIF's pass, a video's span; an image the + * rule's `image`), together, clamped to the rule's [min, max]. + * @param {Array<Record<string, any>>} media + * @param {Record<string, any>} [render] + */ +export function pictureBeatSeconds(media, render = undefined) { + const k = pictureReplyKnobs(render); + const list = (Array.isArray(media) ? media : []).filter(isObj); + if (!list.length) return 0; + const sum = list.reduce((n, m) => n + (ownLength(m) ?? k.image), 0); + return r3(clamp(sum, k.min, k.max)); +} diff --git a/umtool/report-to-video/post-picture.test.mjs b/umtool/report-to-video/post-picture.test.mjs @@ -0,0 +1,141 @@ +// lane/picture-replies: PICTURE-ONLY posts (post-picture.mjs) -- a post of only @mentions and links with an +// attachment is drawn as its picture in its own card, never in the slot; a context post's beat comes before the read. +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { isPictureOnly, onlyMentions, pictureBeatSeconds, pictureReplyKnobs, pictureRuleEntry, validatePictureOnly, validatePictureReplyRender } from "./post-picture.mjs"; +import { mediaSteps, panelEntry, postCardHtml, postItemPlan, postLayout, readingSeconds, slotMediaOf, validatePostItem, validatePostItems } from "./post-item.mjs"; +import { pictureBeats, threadLayout } from "./post-thread.mjs"; + +const at = (h, m = 0) => `2026-11-02T${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:00.000Z`; +const GIF = { src: "posts-media/furri-x/9/9_1.mp4", kind: "gif", width: 480, height: 270, seconds: 2.53 }; +const IMG = { src: "posts-media/kir-x/7/7_1.jpg", kind: "image", width: 1127, height: 500 }; +const VID = { src: "posts-media/subj-x/1/1_1.mp4", kind: "video", width: 1080, height: 1200, seconds: 46.3, audio: true }; +const WORDS = "then don't antagonize me, that's something the community needs to learn, the worst thing you can do with me is antagonize me"; +const base = (o = {}) => ({ type: "post", id: "p-1", post: "subj-x/1", platform: "x", author: "Subject", handle: "subject", date: at(21, 5), text: WORDS, ...o }); +const narrate = (e, text = e.text) => ({ ...e, narration: { script: text, pick: 0, takes: [{ file: "narration/posts/1/take-1.wav", engine: "orpheus", voice: "zac", seconds: 8, script: text, parts: [{ n: 1, para: 0, text, start: 0, seconds: 8, role: "post" }] }] } }); +const gifParent = { id: "9", author: "Furri", handle: "furri", date: at(20, 58), text: "@subject", media: [GIF] }; +const R = { postNarration: { lead: 0.25 } }; + +test("DETECTION: words of only @mentions and links, with an attachment, are picture-only -- the knob forces or denies it", () => { + assert.equal(onlyMentions("@ObviousRises"), true); + assert.equal(onlyMentions(" @a @b_c https://t.co/xyz pic.x.com/abc "), true); + assert.equal(onlyMentions("@ObviousRises lol"), false); + assert.equal(isPictureOnly({ text: "@ObviousRises", media: [GIF] }), true); + assert.equal(isPictureOnly({ text: "", media: [IMG] }), true); + assert.equal(isPictureOnly({ text: "@ObviousRises", media: [] }), false, "no attachment: a mention, not a picture"); + assert.equal(isPictureOnly({ text: "@a look at this", media: [IMG] }), false); + assert.equal(isPictureOnly({ text: "@a", media: [IMG], pictureOnly: false }), false); + assert.equal(isPictureOnly({ text: "@a look at this", media: [IMG], pictureOnly: true }), true); + assert.equal(isPictureOnly({ text: "@a", media: [], pictureOnly: true }), false, "forced with nothing to draw: not"); + assert.equal(isPictureOnly({ text: "@a", media: [IMG], paraphrase: "He posts a screenshot." }), false, "a paraphrase is words"); +}); + +test("THE BEAT: a GIF's or a video's own length, an image the rule's 2 s, clamped to 1.5–4 s; the cut's knobs over it", () => { + assert.equal(pictureBeatSeconds([GIF]), 2.53); + assert.equal(pictureBeatSeconds([{ ...GIF, seconds: 0.8 }]), 1.5); + assert.equal(pictureBeatSeconds([VID]), 4); + assert.equal(pictureBeatSeconds([IMG]), 2); + assert.equal(pictureBeatSeconds([IMG], { posts: { pictureReply: { image: 3, max: 5 } } }), 3); + assert.deepEqual(pictureReplyKnobs(undefined), { on: true, image: 2, min: 1.5, max: 4 }); +}); + +test("A PICTURE-ONLY PARENT (furri's '@subject' and a GIF): its own beat before his read, drawn in its card in full, never in the slot -- the read moved, the take untouched", () => { + const e = narrate(base({ parents: [gifParent], media: [VID] })); + const L = threadLayout(e, R); + assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, !!t.pic]), [["parent:0", "full", true], ["post", "full", false]]); + assert.deepEqual(pictureBeats(e, R, L, 0), [{ scope: "parent:0", t0: 0, t1: 2.53 }]); + const plan = postItemPlan(e, R); + assert.equal(plan.narration.at, 0.25 + 2.53, "the read starts after the beat (and the lead)"); + assert.deepEqual(plan.follow.beats, [{ scope: "parent:0", t0: 0, t1: 2.53 }]); + assert.equal(plan.panel, undefined, "the GIF is never in the slot"); + assert.deepEqual(plan.pics.map((p) => p.scope), ["parent:0"]); + // His own video comes in with his words, not under the GIF's beat. + assert.equal(plan.enter, plan.narration.at); + assert.equal(plan.steps[0].at, plan.narration.at); + // The GIF's tile in full through its beat, small as his read comes; his post revealed for it. + const row = (sc) => plan.follow.thread.tiles.find((t) => t.scope === sc); + assert.deepEqual([row("parent:0").from, row("parent:0").to, row("parent:0").t0], [[1, 1], [0.62, 0.5], 2.38]); + assert.deepEqual([row("post").from, row("post").to, row("post").t0], [[1, 0], [1, 1], 2.38]); + // The take's parts are its own: the item is a beat longer. + const off = postItemPlan(narrate(base({ parents: [{ ...gifParent, pictureOnly: false }], media: [VID] })), R); + assert.equal(Math.round((plan.total - off.total) * 1000) / 1000, 2.53); + assert.deepEqual(e.narration.takes[0].parts[0].start, 0); + // The card draws the GIF's place in the parent's tile, its mention small. + const html = postCardHtml(e, { width: 1920, height: 1080, follow: true, thread: plan.follow.thread, mediaUrl: (s) => `file:///p/${s}`, posters: { [GIF.src]: "file:///p/still.png" } }); + assert.match(html, /data-thread-tile="parent:0"[^]*class="ptext tt pmen"[^]*data-post-pic="parent:0" data-pic-kind="gif"[^]*src="file:\/\/\/p\/still.png"/); + assert.doesNotMatch(html, /data-thread-media=/, "no chip pointing at the slot"); +}); + +test("THE CUT's RULE OFF (render.posts.pictureReply.on false): the plan as before -- context, the GIF in the slot", () => { + const e = narrate(base({ parents: [gifParent], media: [VID] })); + const r = { ...R, posts: { pictureReply: { on: false } } }; + const plan = postItemPlan(e, r); + const denied = postItemPlan(narrate(base({ parents: [{ ...gifParent, pictureOnly: false }], media: [VID] })), R); + assert.deepEqual(plan, denied); + assert.equal(plan.pics, undefined); + assert.ok(plan.panel?.shows?.some((s) => s.scope === "parent:0")); + assert.equal(pictureRuleEntry(e, r).parents[0].pictureOnly, false); + assert.equal(panelEntry(e, r).parents[0].pictureOnly, false); + assert.equal(pictureRuleEntry(e, R), e, "on: the entry itself"); +}); + +test("NOT PICTURE-ONLY: a post with words and a picture plays as before (no key, no beat, its attachment in the slot)", () => { + const e = narrate(base({ media: [IMG], parents: [{ id: "8", author: "A", handle: "a", date: at(20), text: "@subject what do you mean by that exactly", media: [GIF] }] })); + const plan = postItemPlan(e, R); + assert.equal(plan.pics, undefined); + assert.equal(plan.follow.beats, undefined); + assert.deepEqual(plan, postItemPlan(e, { ...R, posts: { pictureReply: { on: false } } })); + assert.equal(slotMediaOf(e)[0], IMG); + assert.equal(postLayout(e, { width: 1920, height: 1080 }).mode, "side"); +}); + +test("A PICTURE-ONLY ITEM (Kirsche's '@subject' and a screenshot): its picture in its card at the card's width, no slot; not narrated, it lasts its beat", () => { + const e = base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@ObviousRises", media: [IMG], panel: "side" }); + assert.deepEqual(validatePostItem(e), []); + assert.deepEqual(mediaSteps(e), []); + assert.deepEqual(slotMediaOf(e), []); + const L = postLayout(e, { width: 1920, height: 1080 }); + assert.equal(L.mode, "text"); + const plan = postItemPlan(e); + assert.equal(plan.total, 2); + assert.deepEqual(plan.steps, []); + assert.deepEqual(plan.pics, [{ scope: "post", media: [IMG] }]); + const html = postCardHtml(e, { width: 1920, height: 1080, mediaUrl: (s) => `file:///p/${s}` }); + assert.match(html, /class="words pmen" data-post-words="" style="font-size:22px"/); + const m = /data-post-pic="post" data-pic-kind="image" data-pic-src="[^"]+" style="width:(\d+)px;height:(\d+)px/.exec(html); + assert.ok(m, "the picture drawn in the card"); + assert.ok(Number(m[1]) > 900 && Math.abs(Number(m[1]) / Number(m[2]) - 1127 / 500) < 0.02, "at the card's width, its aspect kept"); + assert.match(html, /<img src="file:\/\/\/p\/posts-media\/kir-x\/7\/7_1.jpg"/); + // Narrated (its read reads the words on the picture): the read's length, as before. + const n = narrate(e, "It's amazing how much discourse is just pretending not to understand things."); + assert.equal(postItemPlan(n, R).total, postItemPlan({ ...n, pictureOnly: false, media: [] }, R).total); + assert.equal(readingSeconds(base({ parents: [gifParent] })), readingSeconds(base()) + 2.53); +}); + +test("A PICTURE-ONLY ITEM whose read reads its picture (the words on a screenshot): the read is its post's piece -- the carried post it answers gives way, its picture framed", () => { + const kir = base({ id: "p-7", post: "kir-x/7", author: "Kir", handle: "kir", text: "@subject", media: [IMG], parents: [{ id: "1", author: "Subject", handle: "subject", date: at(19), text: WORDS }] }); + const n = narrate(kir, "It's amazing how much discourse is just pretending not to understand things."); + const plan = postItemPlan(n, R, { prev: base({ post: "subj-x/1" }) }); + assert.deepEqual(plan.follow.picReads, [{ scope: "post", t0: plan.narration.at, t1: plan.follow.readEnd }]); + const row = (sc) => plan.follow.thread.tiles.find((t) => t.scope === sc); + assert.equal(row("parent:0").mode, "carry"); + assert.deepEqual(row("parent:0").to, [0.62, 0.5], "the carried post shrinks as the read begins"); + assert.deepEqual(row("post").to, [1, 1]); +}); + +test("A PICTURE-ONLY QUOTED post the read does not read: above his post, its own beat", () => { + const e = narrate(base({ quoted: { id: "5", author: "Q", handle: "q", date: at(19), text: "", media: [IMG] } })); + const L = threadLayout(e, R); + assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, !!t.above]), [["quoted", "full", true], ["post", "full", false]]); + const plan = postItemPlan(e, R); + assert.deepEqual(plan.follow.beats, [{ scope: "quoted", t0: 0, t1: 2 }]); + assert.equal(plan.narration.at, 2.25); +}); + +test("THE KNOBS are refused in the build's words", () => { + assert.deepEqual(validatePictureOnly({ id: "p-1", pictureOnly: "yes", parents: [{ pictureOnly: 1 }], quoted: { pictureOnly: null } }).length, 3); + assert.deepEqual(validatePictureOnly({ id: "p-1", pictureOnly: true, parents: [{ pictureOnly: false }] }), []); + assert.deepEqual(validatePictureReplyRender({ posts: { pictureReply: { on: true, image: 2, min: 1, max: 4 } } }), []); + assert.equal(validatePictureReplyRender({ posts: { pictureReply: { on: "x", nope: 1, image: 99, min: 3, max: 2 } } }).length, 4); + assert.ok(validatePostItems({ render: { posts: { pictureReply: "on" } }, timeline: [] }).some((x) => /pictureReply/.test(x))); +}); diff --git a/umtool/report-to-video/post-render.mjs b/umtool/report-to-video/post-render.mjs @@ -101,7 +101,7 @@ export function clockJoinExpr(base, d, seconds) { return `${num(base)}+${num(d)}*(1-${e})`; } -export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [], join = null, map = null, captionFx = [], clock = null, slams = [], slamHitList = [], progress = null }) { +export function postSegmentArgs({ entry, box, plan, layout, cards, files, render, place = [], encode = [], captions = [], fontfile = null, outPath, narration = null, zooms = [], follow = null, panelFiles = [], join = null, map = null, captionFx = [], clock = null, slams = [], slamHitList = [], progress = null, pics = [] }) { const fps = render.fps ?? 30; const T = plan.total; const inputs = []; @@ -128,6 +128,24 @@ export function postSegmentArgs({ entry, box, plan, layout, cards, files, render parts.push(`[${cur}][rf]overlay=x=${follow.clip.x}:y=${follow.clip.y}:eof_action=repeat[${next}]`); cur = next; } + // PICTURE-ONLY posts' GIFs and videos (post-picture.mjs, measurePics): played over their stills in their cards + // while the card is still, looped and silent, fading back to the still -- under the zooms, captions and slams. + pics.forEach((pc, pi) => { + const { m, box: b, t0, t1, file } = pc; + if (!file || !(t1 > t0)) return; + const label = `pic${pi}`; + const raw = blurOn(m) ? `${label}r` : label; + const crop = Array.isArray(m.crop) ? `crop=iw*${num(m.crop[2])}:ih*${num(m.crop[3])}:iw*${num(m.crop[0])}:ih*${num(m.crop[1])},` : ""; + const from = Number.isFinite(m.start) && m.start > 0 ? m.start : 0; + const len = t1 - t0; + const k = add(["-stream_loop", "-1", ...(from > 0 ? ["-ss", num(from)] : []), "-t", num(len + 0.1), "-i", file]); + const fadeAt = Math.max(0, len - POST_PIC_FADE); + parts.push(`[${k}:v]${crop}scale=${b.width}:${b.height},setsar=1,fps=${fps},format=rgba${t1 < T - 0.05 ? `,fade=t=out:st=${num(fadeAt)}:d=${num(Math.min(POST_PIC_FADE, len))}:alpha=1` : ""},setpts=PTS-STARTPTS+${num(t0)}/TB[${raw}]`); + if (raw !== label) parts.push(...blurFilters(raw, label, m, b)); + const next = `b${++n}`; + parts.push(`[${cur}][${label}]overlay=x=${b.x}:y=${b.y}:eof_action=pass:enable='between(t,${num(t0)},${num(t1)})'[${next}]`); + cur = next; + }); if (layout.mode === "stack" && cards.media && plan.steps.length) { const mi = add(["-loop", "1", "-framerate", String(fps), "-t", num(T), "-i", cards.media]); parts.push(`[${mi}:v]scale=${box.width}:${box.height},setsar=1,fps=${fps}[mc]`); @@ -423,7 +441,7 @@ export async function loadChromium() { * stack layout. The page is a file beside them, so its faces and the parent * shot load from disk (an about:blank page may not read file: urls). */ -export async function renderPostCards(entry, { box, render, dir, manifestDir, layout, avatars = {}, zooms = [], redaction = null, follow = null, total = 0, joinFrom = null, captions = [], clock = null, obstacles = [], slams = [], progress = null }) { +export async function renderPostCards(entry, { box, render, dir, manifestDir, layout, avatars = {}, zooms = [], redaction = null, follow = null, total = 0, joinFrom = null, captions = [], clock = null, obstacles = [], slams = [], progress = null, pics = [], cardPics = null }) { await mkdir(dir, { recursive: true }); const fonts = { regular: render.fontRegular ? pathToFileURL(render.fontRegular).href : "", @@ -509,12 +527,13 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la } // THE CLOCK (post-clock.mjs), shot before the read's frames: over a join, where it opens decides the shot the // card opens on (joinClockOf: carried on from the item before's clock, or that one laid in the shot, fading). - if (clock) out.clock = await shootClock(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, clock, redaction, follow, total }); + if (clock) out.clock = await shootClock(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, clock, redaction, follow, total, cardPics }); if (join) { const jc = joinClockOf({ from: out.joinFrom?.clock ?? null, own: out.clock?.at ?? null, k: box.height / 1080 }); if (jc.bake && out.joinFrom?.pngClock) join.fromUrl = pathToFileURL(out.joinFrom.pngClock).href; if (out.clock) out.clock.join = { seconds: follow.join.seconds, from: jc.move, fadeIn: jc.fadeIn }; } + let picPath = null; for (const phase of phases) { const html = postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase, parentShotUrl, @@ -524,6 +543,8 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la thread: follow?.thread ?? null, redaction, ...(join && phase === "read" ? { join } : {}), + // PICTURE-ONLY posts (post-picture.mjs): their pictures in their cards, the files and the GIFs' stills. + ...(cardPics ?? {}), }); const file = path.join(dir, `${phase}.html`); await writeFile(file, html, "utf8"); @@ -554,20 +575,24 @@ export async function renderPostCards(entry, { box, render, dir, manifestDir, la // THE INVARIANT (read-follow.mjs readInViewErrors): what each part reads is in view, whole and lit, in the // frames as they are shot -- or, with none shot, in the page as drawn. const fpath = out.follow?.path ?? followPath(follow, geo); + picPath = fpath; out.inView = readInViewErrors(follow, geo, shotStateAt(follow, fpath, fps, !!out.follow), { total, id: entry.id }); } + // PICTURE-ONLY posts' GIFs and videos (post-picture.mjs): where each is drawn while its card is at full size + // and still -- the build plays it over that place then (the page draws its still the rest of the time). + if (phase === "read" && pics.some(movingPic)) out.pics = await measurePics(page, { pics, follow, path: picPath, total, fps: render.fps ?? 30, joined: !!join }); } await ctx.close(); - if (zooms.length) out.zooms = await shootZooms(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, zooms, redaction, follow }); + if (zooms.length) out.zooms = await shootZooms(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, zooms, redaction, follow, cardPics }); // The progress bar (post-progress.mjs): along the card's foot, short of the clock on its line. if (progress) { const k = box.height / 1080; const cb = out.clock?.box ? { x: out.clock.box.x + Math.round(240 * k), y: out.clock.box.y, width: out.clock.box.width - Math.round(240 * k), height: out.clock.box.height } : null; - out.progress = await shootProgress(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, progress, redaction, follow, total, avoid: cb ? [cb] : [] }); + out.progress = await shootProgress(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, progress, redaction, follow, total, avoid: cb ? [cb] : [], cardPics }); } // A caption covers none of the attachments (`obstacles`: their boxes) nor the clock. - if (captions.length) out.captions = await shootCaptions(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, captions, redaction, follow, obstacles: [...obstacles, ...(out.clock ? [out.clock.box] : [])] }); - if (slams.length) out.slams = await shootSlams(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, slams, redaction, follow }); + if (captions.length) out.captions = await shootCaptions(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, captions, redaction, follow, obstacles: [...obstacles, ...(out.clock ? [out.clock.box] : [])], cardPics }); + if (slams.length) out.slams = await shootSlams(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, slams, redaction, follow, cardPics }); } finally { await browser.close(); } @@ -634,6 +659,78 @@ export async function shootFollow(page, { follow, total, fps, box, dir, geo = nu return { list, clip, shots: shots.size, frames, geo, path: path0 }; } +/** A picture-only post whose picture moves (a GIF, a video): the build plays it in its card. */ +const movingPic = (p) => p?.media?.[0]?.kind === "gif" || p?.media?.[0]?.kind === "video"; + +/** + * WHERE A PICTURE-ONLY POST's GIF OR VIDEO PLAYS (post-picture.mjs), measured on the card's page: `[{ scope, m, box, + * t0, t1 }]` -- each span of the item, at least POST_PIC_MIN_SPAN s, through which its card's tile is at full size + * and strength and its picture's place does not move (no pan, no join, no shrink); the page's still is what shows + * the rest of the time. A card with no read-follow is still: the whole item. + */ +export async function measurePics(page, { pics, follow, path: fpath = null, total, fps, joined = false }) { + const rectOf = (scope) => page.evaluate((sc) => { + const el = document.querySelector(`[data-post-pic="${sc}"]`); + if (!el) return null; + const r = el.getBoundingClientRect(); + const win = document.querySelector("[data-post-words]")?.getBoundingClientRect() ?? null; + return { x: r.left, y: r.top, width: r.width, height: r.height, w0: el.offsetWidth, h0: el.offsetHeight, win: win ? { top: win.top, bottom: win.bottom } : null }; + }, scope); + const out = []; + const moving = pics.filter(movingPic); + if (!follow) { + for (const p of moving) { + const r = await rectOf(p.scope); + if (r) out.push({ scope: p.scope, m: p.media[0], box: evenBox(r), t0: 0, t1: r3(total) }); + } + return out; + } + const runs = followRuns(follow, fpath ?? followPath(follow, await page.evaluate(measureFollow)), total, fps); + const samples = new Map(moving.map((p) => [p.scope, []])); + let frame = 0; + for (const run of runs) { + await page.evaluate(applyFollowState, run.st); + if (joined) await page.evaluate(applyJoinState, run.st.join ?? null); + for (const p of moving) { + const r = await rectOf(p.scope); + const st = run.st.tiles?.[p.scope] ?? [1, 1]; + const full = !!r && st[0] >= 0.999 && st[1] >= 0.999 && Math.abs(r.width - r.w0) < 0.6 && Math.abs(r.height - r.h0) < 0.6; + const inView = !!r && (!r.win || (r.y >= r.win.top - 0.5 && r.y + r.height <= r.win.bottom + 0.5)); + samples.get(p.scope).push({ f0: frame, f1: frame + run.n, ok: full && inView, r }); + } + frame += run.n; + } + await page.evaluate(applyFollowState, null); + if (joined) await page.evaluate(applyJoinState, null); + for (const p of moving) { + let cur = null; + const close = () => { + if (cur && (cur.f1 - cur.f0) / fps >= POST_PIC_MIN_SPAN) out.push({ scope: p.scope, m: p.media[0], box: evenBox(cur.r), t0: r3(cur.f0 / fps), t1: r3(Math.min(total, cur.f1 / fps)) }); + cur = null; + }; + for (const sm of samples.get(p.scope)) { + const same = cur && Math.abs(sm.r.x - cur.r.x) < 0.6 && Math.abs(sm.r.y - cur.r.y) < 0.6; + if (!sm.ok) close(); + else if (same) cur.f1 = sm.f1; + else { + close(); + cur = { f0: sm.f0, f1: sm.f1, r: sm.r }; + } + } + close(); + } + return out; +} + +/** The shortest span a picture-only post's GIF is played over its still (s). */ +export const POST_PIC_MIN_SPAN = 0.3; +/** Its fade back to the still at a span's end (s). */ +export const POST_PIC_FADE = 0.25; +/** The drawing of a picture-only post (postSegmentKeyOf `pics`): bump it when the card draws one differently. */ +export const POST_PICTURE_DRAW_V = 1; + +const evenBox = (r) => ({ x: Math.round(r.x), y: Math.round(r.y), width: Math.max(2, Math.round(r.width / 2) * 2), height: Math.max(2, Math.round(r.height / 2) * 2) }); + /** * THE BRANCH MAP's FRAMES (post-branch-map.mjs): the map alone on a transparent page, each distinct state (its * strength, its light's place) shot once over its span, a concat list holding each for its frames; `{ list, x, y, @@ -703,14 +800,14 @@ export const zoomShotScale = (zooms) => Math.min(4, Math.max(2, Math.ceil(Math.m * and the region shot plain and with the zoom's highlight under the words. * `zooms`: `[{ i, scope, from, to, scale, highlight }]`. */ -async function shootZooms(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, zooms, redaction = null, follow = null }) { +async function shootZooms(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, zooms, redaction = null, follow = null, cardPics = null }) { const k = zoomShotScale(zooms); const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: k, offline: true, serviceWorkers: "block" }); const page = await ctx.newPage(); const av = Object.fromEntries(Object.entries(avatars).map(([h, f]) => [h, pathToFileURL(f).href])); const load = async (name, highlight) => { const file = path.join(dir, `${name}.html`); - await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, highlight, redaction, follow: !!follow, thread: follow?.thread ?? null }), "utf8"); + await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, highlight, redaction, follow: !!follow, thread: follow?.thread ?? null, ...(cardPics ?? {}) }), "utf8"); await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); }; @@ -785,7 +882,7 @@ async function shootZooms(browser, entry, { box, render, dir, fonts, parentShotU * frame over the caption's span: its `track`, which the chip rides. * `captions`: captionPlan's. Returns `[{ ...caption, chip, mark, slide, track, placed }]`. */ -export async function shootCaptions(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, captions, redaction = null, follow = null, obstacles: fixed = [] }) { +export async function shootCaptions(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, captions, redaction = null, follow = null, obstacles: fixed = [], cardPics = null }) { const fps = render.fps ?? 30; const k = box.height / 1080; const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: 1, offline: true, serviceWorkers: "block" }); @@ -794,7 +891,7 @@ export async function shootCaptions(browser, entry, { box, render, dir, fonts, p const out = []; try { const file = path.join(dir, "caption.html"); - await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null }), "utf8"); + await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null, ...(cardPics ?? {}) }), "utf8"); await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); await page.evaluate(() => document.fonts.ready.then(() => true)); @@ -908,7 +1005,7 @@ async function clockPlaceOn(page, { follow, total, size, k }) { * holding each for its frames. `slams`: slamPlan's. Returns `[{ ...slam, * list, t0, t3, layout, size, shots }]`. */ -export async function shootSlams(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, slams, redaction = null, follow = null }) { +export async function shootSlams(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, slams, redaction = null, follow = null, cardPics = null }) { const fps = render.fps ?? 30; const k = box.height / 1080; const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: 1, offline: true, serviceWorkers: "block" }); @@ -917,7 +1014,7 @@ export async function shootSlams(browser, entry, { box, render, dir, fonts, pare const out = []; try { const file = path.join(dir, "slam.html"); - await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null }), "utf8"); + await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null, ...(cardPics ?? {}) }), "utf8"); await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); await page.evaluate(() => document.fonts.ready.then(() => true)); @@ -1026,14 +1123,14 @@ export async function shootSlams(browser, entry, { box, render, dir, fonts, pare * its start, middle and end, the place covering fewest words), then its track and its fill shot alone on a clear * page. `{ track, fill, x, y, width, height, place, covers, plan }`. */ -export async function shootProgress(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, progress, redaction = null, follow = null, total = 0, avoid = [] }) { +export async function shootProgress(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, progress, redaction = null, follow = null, total = 0, avoid = [], cardPics = null }) { const k = box.height / 1080; const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: 1, offline: true, serviceWorkers: "block" }); const page = await ctx.newPage(); const av = Object.fromEntries(Object.entries(avatars).map(([h, f]) => [h, pathToFileURL(f).href])); try { const file = path.join(dir, "progress.html"); - await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null }), "utf8"); + await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null, ...(cardPics ?? {}) }), "utf8"); await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); const css = progressCss({ height: box.height, palette: render.palette }); @@ -1077,7 +1174,7 @@ export async function shootProgress(browser, entry, { box, render, dir, fonts, p * once) and a concat list holding each for its frames, the last to the end. * `{ list, x, y, place, covers, shots }`. */ -export async function shootClock(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, clock, redaction = null, follow = null, total = 0 }) { +export async function shootClock(browser, entry, { box, render, dir, fonts, parentShotUrl, avatars, clock, redaction = null, follow = null, total = 0, cardPics = null }) { const fps = render.fps ?? 30; const k = box.height / 1080; const ctx = await browser.newContext({ viewport: { width: box.width, height: box.height }, deviceScaleFactor: 1, offline: true, serviceWorkers: "block" }); @@ -1085,7 +1182,7 @@ export async function shootClock(browser, entry, { box, render, dir, fonts, pare const av = Object.fromEntries(Object.entries(avatars).map(([h, f]) => [h, pathToFileURL(f).href])); try { const file = path.join(dir, "clock.html"); - await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null }), "utf8"); + await writeFile(file, postCardHtml(entry, { width: box.width, height: box.height, palette: render.palette, fonts, phase: "read", parentShotUrl, avatars: av, redaction, follow: !!follow, thread: follow?.thread ?? null, ...(cardPics ?? {}) }), "utf8"); await page.goto(pathToFileURL(file).href, { waitUntil: "load" }); await page.waitForSelector("body[data-post-ready='1']", { timeout: 15000 }); const face = clockFace(clock.to, clock.zone); @@ -1238,6 +1335,8 @@ export function postSegmentKeyOf({ entry, redaction = null, box, place = [], ren // clock (where this one's starts) and its parent's shot. ...(from ? { joinFrom: { entry: from.entry, follow: from.plan.follow ?? null, total: from.plan.total, media: from.media.map((x) => [x.m.src, x.t, x.box]), fadeIn: from.fadeIn, jv: POST_JOIN_DRAW_V, clock: from.clock ?? null, ...(from.carry ? { carry: from.carry } : {}), ...(Number.isFinite(from.anchorY) ? { anchorY: from.anchorY } : {}) } } : {}), ...(plan.panel ? { panel: plan.panel } : {}), + // PICTURE-ONLY posts (post-picture.mjs): the pictures drawn in their cards -- only an item that has one. + ...(plan.pics ? { pics: { v: POST_PICTURE_DRAW_V, list: plan.pics } } : {}), // Its own attachment entering with his own post (post-item.mjs ownMediaEnterAt): only an item that reads // something before its post carries it -- every other keeps its key. ...(plan.enter > 0 ? { enter: { at: plan.enter, fade: POST_ENTER_FADE } } : {}), @@ -1327,6 +1426,11 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box for (const [i, f] of panelFiles.flat().entries()) { if (!(await stat(f).catch(() => null))) throw new Error(`${entry.id}: a context post's attachment is not on disk: ${f} (${i})`); } + // PICTURE-ONLY posts' pictures (post-picture.mjs, plan.pics): files of the project, drawn in their cards. + const picFiles = (plan.pics ?? []).flatMap((p) => p.media.map((m) => path.resolve(manifestDir, m.src))); + for (const f of picFiles) { + if (!(await stat(f).catch(() => null))) throw new Error(`${entry.id}: a picture-only post's attachment is not on disk: ${f}`); + } const wordFiles = (entry.media ?? []).map((m) => (typeof m.words === "string" ? path.resolve(manifestDir, m.words) : null)); // Its narration's picked take (post-narration.mjs): a file of the project, levelled by its measured loudness. const take = isNarrated(entry) ? pickedTake(entry) : null; @@ -1334,7 +1438,7 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box if (takeFile && !(await stat(takeFile).catch(() => null))) throw new Error(`${entry.id}: its narration take is not on disk: ${takeFile} (${take.file})`); // The slurs its take SAYS, covered (post-slurs.mjs): a public render never plays one -- without word timings it is refused. const bleeps = take ? takeSlurBleeps(entry, take, redaction) : null; - const stamps = await Promise.all([...files, ...panelFiles.flat(), ...(from?.media ?? []).map((x) => x.file), ...wordFiles.filter(Boolean), ...Object.values(avatars), ...(takeFile ? [takeFile] : []), ...(entry.parentShot ? [path.resolve(manifestDir, entry.parentShot)] : []), ...(typeof from?.entry?.parentShot === "string" ? [path.resolve(manifestDir, from.entry.parentShot)] : [])].map(async (f) => { + const stamps = await Promise.all([...files, ...panelFiles.flat(), ...picFiles.filter((f) => !files.includes(f)), ...(from?.media ?? []).map((x) => x.file), ...wordFiles.filter(Boolean), ...Object.values(avatars), ...(takeFile ? [takeFile] : []), ...(entry.parentShot ? [path.resolve(manifestDir, entry.parentShot)] : []), ...(typeof from?.entry?.parentShot === "string" ? [path.resolve(manifestDir, from.entry.parentShot)] : [])].map(async (f) => { const st = await stat(f).catch(() => null); return st ? `${f}:${st.size}:${Math.round(st.mtimeMs)}` : `${f}:-`; })); @@ -1371,7 +1475,27 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box const clk = clockPlan(entry, render, prev); // Its progress bar (post-progress.mjs): the read's span on the item's clock (a long read's, auto). const prog = progressPlan(entry, render, plan, { stack: layout.mode === "stack" }); - const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, redaction, follow: plan.follow ?? null, total: plan.total, joinFrom: from, captions: capPlan, clock: clk, obstacles: layout.slot ? plan.steps.flatMap((st) => stepBoxes(st, layout.slot)) : [], slams: slPlan, progress: prog }); + // PICTURE-ONLY posts (post-picture.mjs): the page draws each picture in its card -- an image itself, a GIF's or a + // video's first frame (its still; the encode plays it over that place while the card is still). + let cardPics = null; + if (plan.pics?.length) { + await mkdir(cardDir, { recursive: true }); + const posters = {}; + for (const [pi, pc] of plan.pics.entries()) { + const m = pc.media[0]; + if (m?.kind !== "gif" && m?.kind !== "video") continue; + const still = path.join(cardDir, `pic-${pi}.png`); + const from = Number.isFinite(m.start) && m.start > 0 ? m.start : 0; + try { + await exec(ffmpeg, ["-nostdin", "-v", "error", "-y", "-ss", String(from), "-i", path.resolve(manifestDir, m.src), "-frames:v", "1", still], { maxBuffer: 1 << 24 }); + posters[m.src] = pathToFileURL(still).href; + } catch (err) { + throw new Error(`${entry.id}: the still of a picture-only post's ${m.kind} could not be made (${m.src}): ${String(err?.stderr ?? err?.message ?? err).trim()}`); + } + } + cardPics = { mediaUrl: (src) => pathToFileURL(path.resolve(manifestDir, src)).href, posters }; + } + const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, pics: plan.pics ?? [], cardPics, redaction, follow: plan.follow ?? null, total: plan.total, joinFrom: from, captions: capPlan, clock: clk, obstacles: layout.slot ? plan.steps.flatMap((st) => stepBoxes(st, layout.slot)) : [], slams: slPlan, progress: prog }); // NO HIDDEN TEXT IS EVER NARRATED (operator, 4 Nov): a part whose words are not in view, whole and lit, while it // is said -- or a context post drawn over its context size -- refuses the build (READ_IN_VIEW=warn: a note). // A part read off a linked post's picture is on screen only while the panel shows it (post-thread.mjs panelReadErrors). @@ -1405,7 +1529,7 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box const lufs = Number.isFinite(take.lufs) ? take.lufs : await measureLufsOf(takeFile, { exec, ffmpeg }); narration = { file: takeFile, gainDb: narrationLevelDb(lufs, plan.narration.lufs), lufs, ...(bleeps ? { bleeps } : {}) }; } - const argv = postSegmentArgs({ entry, box, plan, layout, cards, files, render, place, encode, captions, fontfile: render.fontBold ?? render.fontRegular ?? null, outPath: tmp, narration, zooms, follow: cards.follow ?? null, panelFiles, map: cards.map ?? null, join: from && cards.joinFrom ? { seconds: plan.follow.join.seconds, fadeIn: from.fadeIn, from: from.media } : null, captionFx: cards.captions ?? [], clock: cards.clock ? { ...cards.clock, until: layout.mode === "stack" && plan.steps.length ? plan.steps[0].at : plan.total } : null, slams: cards.slams ?? [], slamHitList: (cards.slams ?? []).flatMap((sl) => slamHits(sl.fx, sl.span).map((h) => ({ ...h, gain: h.gain * sl.fx.volume }))), progress: cards.progress ?? null }); + const argv = postSegmentArgs({ entry, box, plan, layout, cards, files, render, place, encode, captions, fontfile: render.fontBold ?? render.fontRegular ?? null, outPath: tmp, narration, zooms, follow: cards.follow ?? null, panelFiles, map: cards.map ?? null, join: from && cards.joinFrom ? { seconds: plan.follow.join.seconds, fadeIn: from.fadeIn, from: from.media } : null, captionFx: cards.captions ?? [], clock: cards.clock ? { ...cards.clock, until: layout.mode === "stack" && plan.steps.length ? plan.steps[0].at : plan.total } : null, slams: cards.slams ?? [], slamHitList: (cards.slams ?? []).flatMap((sl) => slamHits(sl.fx, sl.span).map((h) => ({ ...h, gain: h.gain * sl.fx.volume }))), progress: cards.progress ?? null, pics: (cards.pics ?? []).map((pc) => ({ ...pc, file: path.resolve(manifestDir, pc.m.src) })) }); try { await exec(ffmpeg, argv, { maxBuffer: 1 << 24 }); } catch (err) { @@ -1424,6 +1548,10 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box ? `${entry.id}: post item ${plan.total.toFixed(1)} s, narrated (${take.file}: ${plan.narration.seconds.toFixed(1)} s from ${plan.narration.at} s, muffled to ${plan.narration.voiceEnd.toFixed(1)} s)` : `${entry.id}: post item ${plan.total.toFixed(1)} s (${layout.mode}: ${plan.reading.toFixed(1)} s to read${plan.steps.length ? `, ${plan.steps.length} attachment step(s)` : ""})`, }); + for (const pc of plan.pics ?? []) { + const shown = (cards.pics ?? []).filter((x) => x.scope === pc.scope); + emit("note", { message: `${entry.id}: picture-only ${pc.scope === "post" ? "post" : pc.scope} -- its ${pc.media[0]?.kind ?? "picture"} drawn in its card${shown.length ? `, played ${shown.map((x) => `${x.t0}–${x.t1} s`).join(", ")}` : ""}${(plan.follow?.beats ?? []).filter((b) => b.scope === pc.scope).map((b) => `, its beat ${b.t0}–${b.t1} s before the read`).join("")}` }); + } if (cards.follow) emit("note", { message: `${entry.id}: read-follow -- ${plan.follow.blocks.filter((b) => b.start !== null).length} block(s) read, ${cards.follow.path.segments.length ? `the words panned ${cards.follow.path.segments.length} time(s) over ${Math.round(cards.follow.path.max)} px` : "no pan (the words fit)"}; ${cards.follow.shots} shot(s) for ${cards.follow.frames} frames` }); if (cards.progress) emit("note", { message: `${entry.id}: progress bar over the read ${prog.from}–${prog.to} s (${prog.mode}${prog.ticks.length ? `, ${prog.ticks.length + 1} parts ticked` : ""}), ${cards.progress.place === "foot" ? "along the card's foot" : "under the card"}${cards.progress.covers ? ` -- WARNING: over ${cards.progress.covers} word(s)` : ""}` }); if (cards.clock) emit("note", { message: `${entry.id}: clock ${clockFace(clk.to, clk.zone).time} ${clockFace(clk.to, clk.zone).date} (${clk.mode === "none" ? "shown" : clk.mode === "rewind" ? "rewound" : "run forward"}${clk.mode === "none" ? "" : ` from the item before, ${clk.gap / 60000 | 0} min`}), ${cards.clock.place}${cards.clock.covers ? ` -- WARNING: over ${cards.clock.covers} word(s)` : ""}` }); diff --git a/umtool/report-to-video/post-thread-scenes.test.mjs b/umtool/report-to-video/post-thread-scenes.test.mjs @@ -84,12 +84,16 @@ test("THE READ IN DATE ORDER (operator, 4 Nov: D): a quoted take older than the assert.deepEqual(readInViewErrors(plan.follow, geo, shotStateAt(plan.follow, followPath(plan.follow, geo), 30), { total: plan.total, id: e.id }), []); }); -test("AN IMAGE-ONLY REPLY is a tile (its head and a chip), never read; a parent's attachment is a file the lint checks", () => { +test("AN IMAGE-ONLY REPLY is a tile, never read -- picture-only (post-picture.mjs): its picture in its tile, in full; `pictureOnly: false`: its head and a chip, as context; a parent's attachment is a file the lint checks", () => { const e = narrate(base({ parents: [ref("9", "furri", "", 19, { media: [{ src: "posts-media/f/9/9_1.jpg", kind: "image", width: 600, height: 800 }] }), ref("1", "subject", ROOT, 17)] }), [[base().text]]); assert.deepEqual(validatePostItem(e), []); const L = threadLayout(e); - assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode]), [["parent:1", "context"], ["parent:0", "context"], ["post", "full"]]); - const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: L }); + assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode]), [["parent:1", "context"], ["parent:0", "full"], ["post", "full"]]); + assert.match(postCardHtml(e, { width: 1600, height: 900, follow: true, thread: L }), /data-post-parent="0"[^>]*>.*data-post-pic="parent:0"/s); + const off = { ...e, parents: [{ ...e.parents[0], pictureOnly: false }, e.parents[1]] }; + const L0 = threadLayout(off); + assert.deepEqual(L0.tiles.map((t) => [t.scope, t.mode]), [["parent:1", "context"], ["parent:0", "context"], ["post", "full"]]); + const html = postCardHtml(off, { width: 1600, height: 900, follow: true, thread: L0 }); assert.match(html, /data-post-parent="0"[^>]*>.*data-thread-media="1">photo</s); assert.deepEqual(validatePostItem({ ...e, parents: [{ media: [{ src: "/abs.jpg", kind: "image" }] }] }).length > 0, true); }); diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs @@ -54,6 +54,7 @@ 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"; /** What a context tile may be. */ export const THREAD_MODES = Object.freeze(["auto", "full", "excerpt", "context", "carry", "hidden"]); @@ -308,12 +309,14 @@ export function threadLayout(entry, render = undefined, { prev = null, scene = n 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" : "context"; + mode = isRead ? "full" : carry ? "carry" : pic ? "full" : "context"; } if (mode === "carry" && isRead) mode = "full"; - tiles.push({ scope, mode, read: isRead }); + 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 @@ -321,10 +324,13 @@ export function threadLayout(entry, render = undefined, { prev = null, scene = n 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") }; - if (isObj(entry?.quoted) && contextText(entry.quoted).trim()) { - const m = k.quoted === "auto" ? (read.has("quoted") ? "full" : "context") : k.quoted; - const q = { scope: "quoted", mode: m, read: read.has("quoted"), ...(quotedAt === "above" && m !== "hidden" && m !== "context" ? { above: true } : {}) }; + 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); @@ -349,6 +355,34 @@ export function threadLayout(entry, render = undefined, { prev = null, scene = n 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<string, any>} entry + * @param {Record<string, any> | undefined} render + * @param {{ on: boolean, tiles: Array<Record<string, any>> } | 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; @@ -558,17 +592,19 @@ export function threadReadErrors(entry, render = undefined, { prev = null, scene * (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 }) { +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(); for (const b of blocks) if (b.part !== null && b.start !== null && !startOfPart.has(b.part)) startOfPart.set(b.part, b.start); - const pieces = readPieces(entry, roles).map((p) => { + // 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(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); + }).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; @@ -621,6 +657,24 @@ export function threadSchedule(entry, render, { layout, blocks, lead = 0.4 }) { 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); @@ -835,14 +889,18 @@ export function refOfScope(entry, scope) { export function panelSchedule(entry, follow, total, { lead = 0.4 } = {}) { const th = follow?.thread; if (!th) return null; - const own = Array.isArray(entry?.media) && entry.media.length > 0; + // 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 media = refMediaOf(refOfScope(entry, row.scope)); + 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; diff --git a/umtool/report-to-video/read-follow.mjs b/umtool/report-to-video/read-follow.mjs @@ -340,7 +340,7 @@ const wordsIn = (t) => scriptWordsOf(t).length; * * @param {{ hold?: number | null, narration?: Record<string, any> | null, prev?: Record<string, any> | null, scene?: Record<string, any> | null, mediaScene?: Record<string, any> | null, join?: { seconds: number } | null }} [o] */ -export function followSchedule(entry, render = undefined, { hold = null, narration = undefined, prev = null, scene = null, mediaScene = null, join = null } = {}) { +export function followSchedule(entry, render = undefined, { hold = null, narration = undefined, prev = null, scene = null, mediaScene = null, join = null, beats = [] } = {}) { const k = followKnobs(entry, render); if (!k.on) return null; const map = followBlocks(entry); @@ -396,13 +396,20 @@ export function followSchedule(entry, render = undefined, { hold = null, narrati // A MEDIA SCENE (post-media-scene.mjs): the scene's earlier messages above the card's own tiles -- a narrated // item's on its thread read's schedule, an un-narrated one's on the scene's. const layout = ms ? sceneLayout(base, entry, ms) : base; - const own = !layout?.on ? null : base ? threadSchedule(entry, render, { layout, blocks, lead: FOLLOW_PAN.lead }) : sceneSchedule(threadKnobs(entry, render), { layout, blocks, lead: FOLLOW_PAN.lead }); + // PICTURE-ONLY context posts' BEATS (post-thread.mjs pictureBeats, post-picture.mjs): pieces of their own before the read. + const beatsOn = base && Array.isArray(beats) && beats.length ? beats : []; + // A PICTURE-ONLY post of his own whose read reads its picture (the words on a screenshot: no block of the card's + // words is timed) is read as a piece of its own from the read's start: its tile -- the picture -- framed whole. + const picReads = base?.on && isNarrated(entry) && base.tiles.some((t) => t.scope === "post" && t.pic) && !blocks.some((b) => b.start !== null) + ? [{ scope: "post", t0: r3((narration ?? narrationSchedule(entry, render)).at), t1: readEnd }] + : []; + const own = !layout?.on ? null : base ? threadSchedule(entry, render, { layout, blocks, lead: FOLLOW_PAN.lead, beats: [...beatsOn, ...picReads] }) : sceneSchedule(threadKnobs(entry, render), { layout, blocks, lead: FOLLOW_PAN.lead }); const thread0 = ms ? sceneRows(own, layout) : own; // LINK VISITS (post-link-visit.mjs): a link in the words visited -- the pointer, the click, the post opened. const visits = thread0 && isNarrated(entry) ? linkVisits(entry, thread0, blocks, render) : []; const thread = visits.length ? visitRows(thread0, visits) : thread0; // THE JOIN (post-join.mjs): its first seconds morph from the item before as it ended. - return { dim: k.dim, ease: k.ease, readEnd, source: map.source, blocks, ...(thread ? { thread } : {}), ...(visits.length ? { visits } : {}), ...(join && fin(join.seconds) ? { join: { seconds: join.seconds } } : {}) }; + return { dim: k.dim, ease: k.ease, readEnd, source: map.source, blocks, ...(thread ? { thread } : {}), ...(visits.length ? { visits } : {}), ...(join && fin(join.seconds) ? { join: { seconds: join.seconds } } : {}), ...(thread && beatsOn.length ? { beats: beatsOn } : {}), ...(thread && picReads.length ? { picReads } : {}) }; } /** The block being read at item second `s` (its k), or null (before the read's first block, or none). */ @@ -492,7 +499,10 @@ export function threadPath(follow, geo) { if (max < 1) return Math.round((max / 2) * 100) / 100; return Math.round(clamp(want, 0, max) * 100) / 100; }; - const read = (follow.blocks ?? []).filter((b) => b.start !== null && geo.blocks?.[b.k]).sort((a, b) => a.start - b.start || a.k - b.k); + // A PICTURE-ONLY post's BEAT (post-picture.mjs) is framed as a piece read: its tile, for its beat. + const beatBlocks = [...(Array.isArray(follow.beats) ? follow.beats : []), ...(Array.isArray(follow.picReads) ? follow.picReads : [])].filter((b) => geo?.tiles?.[b.scope]).map((b) => ({ scope: b.scope, start: b.t0, end: b.t1, k: null, beat: true })); + const read = [...beatBlocks, ...(follow.blocks ?? []).filter((b) => b.start !== null && geo.blocks?.[b.k]).sort((a, b) => a.start - b.start || a.k - b.k)]; + const boxOf = (g, b) => (b.beat ? g.tiles[b.scope] : g.blocks[b.k]); // The opening frame: a carried post (or the scene's post the item before ended on) framed as the item before // left it; else the first block's place. const carry = (th.tiles ?? []).find((t) => t.mode === "carry") ?? (th.tiles ?? []).find((t) => t.mode === "scene" && t.wasPost); @@ -512,7 +522,7 @@ export function threadPath(follow, geo) { const g = at(read[0].start - lead + span); // The first post read, whole when it fits the window; else its first block a margin from the top. const tile = g.tiles[tileScopeOf(read[0].scope)]; - off = placed(g, tile && tile.bottom - tile.top <= H - m ? tile.top - Math.min(m / 2, tile.top) : g.blocks[read[0].k].top - m); + off = placed(g, tile && tile.bottom - tile.top <= H - m ? tile.top - Math.min(m / 2, tile.top) : boxOf(g, read[0]).top - m); } else off = placed(g0, 0); const start = off; const segments = []; @@ -533,7 +543,7 @@ export function threadPath(follow, geo) { if (i === 0 && !carry) return; const g = at(b.start - lead + span); maxSeen = Math.max(maxSeen, g.C - H); - const bb = g.blocks[b.k]; + const bb = boxOf(g, b); if (first) { // A new piece: its tile under a strip of the one it answers, the block itself in view. const tile = g.tiles[tileScopeOf(b.scope)];