// PRESENT MODE (operator, 8 Nov 2026: "present X posts in a new UI mode ... navigated like a PowerPoint
// presentation including settings like toggled censors"; umtool/docs/knobs.md, "Present mode"): a cut -- or a
// take -- as SLIDES, one at a time, navigated like a deck. This file is its PAYLOAD: what the viewer
// (`/projects/
/present`, components/projects/present/) and `umtool present --json` read. Deterministic, no AI,
// nothing fetched, cut or rendered.
//
// It is Play's view (playView.mjs playViewWith) cut into slides, so what a slide shows is what Play plays:
//
// - the cut is the LATEST take by default (the working cut, workingCut.mjs), a named take, or the manifest
// alone (`bare`) -- the take's patch applied exactly as Play and the build apply it;
// - a POST slide per post item, keyed by the POST's id (`/`, never the entry's index: a
// story's depths and a viewer's "seen" -- steps 2 and 3 -- key on it), carrying the item as Play draws it
// (its plan, progress bar, clock, media scene, combo badge), its excerpt's spans, its picked narration take,
// and its CENSOR DATA -- every redacted span, masked slur, blurred author and censored attachment the build
// would apply, by kind, so the viewer can show what it hides and toggle it;
// - a CLIP slide per clip the walk did not reject: the spans it plays (its cut minus its gaps) from the cached
// window Play plays, the deck's title, source line and QR link, its quote and its picture's blur;
// - the INTRO (render.intro) as the first slide, before any divider: its style, length and words -- the viewer plays
// the build's own page (POST /api/report/chrome/intro) and its sound;
// - a TEASER slide (its lines), and any other entry as a text slide (its heading);
// - SECTION divider slides where the cut's markers open a section -- or, when the cut is a chronological reel of
// posts with no markers, a DAY divider per calendar day in the posts' clock zone (post-clock.mjs).
//
// THE CAPABILITY. `canUncensor: true` (umtool, the operator) carries the posts as written beside the censor data;
// `canUncensor: false` (a public export, step 4) carries the CENSORED posts only -- every redacted span already
// marked, every masked slur masked, every blurred author's name and handle gone from the data -- and no reveal
// data at all. A public page can add censoring, never remove it.
import { cardAuthors, cardText, excerptRanges, excerptSpansOf, postDay, screenSpeakerShown } from "umtool-report-to-video/post-item";
import { maskedField, screenHeader, screenIsExcerpt, screenRows, screenSide } from "umtool-report-to-video/post-screens";
import { drawnScreens, partRoles, playableTake } from "umtool-report-to-video/post-thread";
import { followKnobs } from "umtool-report-to-video/read-follow";
import { REDACT_MARK, redactEntry, redactionOn } from "umtool-report-to-video/post-redact";
import { maskFor, slurMatches, slursOn } from "umtool-report-to-video/post-slurs";
import { blurOf, censorEntry } from "umtool-report-to-video/post-censor";
import { clockZoneOf } from "umtool-report-to-video/post-clock";
import { estimateSchedule } from "umtool-report-to-video/deck";
import { gapsOf, keptSpans } from "umtool-report-to-video/gaps";
import { clipBlurOf } from "umtool-report-to-video/clip-blur";
import { censorRegionsOf } from "umtool-report-to-video/clip-censor";
import { playViewWith } from "./playView.mjs";
import { projectRedaction } from "./postRedaction.mjs";
import { sectionModel } from "./sectionEdit.mjs";
export const PRESENT_VERSION = 1;
/**
* The viewer's settings when a viewer has set none (each viewer's own are kept in its browser). Everything the build
* censors is censored; the narration plays; a slide waits for the viewer.
*/
export const PRESENT_DEFAULTS = Object.freeze({
censor: Object.freeze({ names: true, slurs: true, authors: true, pictures: true }),
narration: true,
autoAdvance: false,
/** Seconds a slide stays up after its read ends, before auto-advance moves on. */
linger: 1.5,
/** The attachments' own sound (a video's). */
sound: true,
});
/** The censor kinds the viewer toggles, in its words. */
export const CENSOR_KINDS = Object.freeze({
names: "Redacted names",
slurs: "Slurs masked",
authors: "Private authors blurred",
pictures: "Censored pictures",
});
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
const str = (v) => (typeof v === "string" ? v : "");
const fin = (v) => typeof v === "number" && Number.isFinite(v);
const text = (v) => str(v).replace(/\s+/g, " ").trim();
/** The handle a blurred author is given in a public payload: it names nobody, and the card blurs it. */
const NOBODY = "xxxxxxxx";
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
/** `YYYY-MM-DD` of a moment in `zone` (an IANA name), or null. */
export function dayIn(iso, zone) {
const d = new Date(str(iso));
if (Number.isNaN(d.getTime())) return null;
try {
// en-CA writes 2026-11-03.
return new Intl.DateTimeFormat("en-CA", { timeZone: zone, year: "numeric", month: "2-digit", day: "2-digit" }).format(d);
} catch {
return postDay(iso) || null;
}
}
/** "Nov 3" for `YYYY-MM-DD` (the progress line's date). */
export function dayLabel(day) {
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(str(day));
if (!m || Number(m[2]) < 1 || Number(m[2]) > 12) return null;
return `${MON[Number(m[2]) - 1]} ${Number(m[3])}`;
}
/** A clip's dateKey (YYYYMMDD, playView) as `YYYY-MM-DD`. */
const dayOfKey = (k) => (fin(k) ? `${Math.floor(k / 10000)}-${String(Math.floor((k % 10000) / 100)).padStart(2, "0")}-${String(k % 100).padStart(2, "0")}` : null);
// ---------------------------------------------------------------------------
// THE CENSOR DATA (post-redact.mjs, post-slurs.mjs, post-item.mjs authorRedaction, post-censor.mjs).
// ---------------------------------------------------------------------------
/** Every string a card draws of a post item, by its path: `[path, value, slurs?]` (slurs: the filter masks it). */
function drawnFields(entry) {
const out = [];
const add = (path, v, slurs) => {
if (typeof v === "string" && v) out.push([path, v, slurs]);
};
add("author", entry.author, true);
add("handle", entry.handle, false);
add("replyingTo", entry.replyingTo, false);
add("text", entry.text, true);
if (isObj(entry.repostedBy)) {
add("repostedBy.author", entry.repostedBy.author, true);
add("repostedBy.handle", entry.repostedBy.handle, false);
}
const ref = (base, r) => {
if (!isObj(r)) return;
add(`${base}.author`, r.author, true);
add(`${base}.handle`, r.handle, false);
add(`${base}.text`, r.text, true);
add(`${base}.paraphrase`, r.paraphrase, true);
add(`${base}.transcript`, r.transcript, true);
};
if (Array.isArray(entry.parents)) entry.parents.forEach((p, i) => ref(`parents.${i}`, p));
if (isObj(entry.quoted)) ref("quoted", entry.quoted);
if (Array.isArray(entry.links)) entry.links.forEach((p, i) => ref(`links.${i}`, p));
return out;
}
const valueAt = (obj, path) => path.split(".").reduce((o, k) => (o == null ? undefined : o[k]), obj);
/** The runs of REDACT_MARK in `marked`: `[{ start, end }]` (redactText keeps every offset). */
function markRuns(marked) {
const out = [];
const re = new RegExp(`${REDACT_MARK}[${REDACT_MARK}\\s]*${REDACT_MARK}|${REDACT_MARK}`, "g");
for (const m of str(marked).matchAll(re)) out.push({ start: m.index, end: m.index + m[0].length });
return out;
}
/**
* WHAT THE BUILD HIDES ON A POST ITEM, as data: `{ marks, authors, media, counts }` -- each redacted span and each
* masked slur of every string the card draws (`{ kind: "redact"|"slur", field, start, end, mask? }`, offsets in the
* string as written), each author the card blurs (`{ kind: "author", where, handle, reason }`), each censored
* attachment (`{ kind: "blur", i, style, boxes, band, strength, label }`) -- or null when it hides nothing.
*
* @param {Record} entry the item as the card draws it (its censored attachments laid on)
* @param {import("umtool-report-to-video/post-redact").Redaction | null} red
*/
export function censorData(entry, red) {
const marks = [];
// The redaction alone (no slurs): its marks keep every offset of the string as written.
const termsOnly = red ? { ...red, slurs: null } : null;
if (redactionOn(termsOnly)) {
const marked = redactEntry(entry, termsOnly);
for (const [field, v] of drawnFields(entry)) {
const after = valueAt(marked, field);
if (typeof after !== "string" || after === v) continue;
for (const r of markRuns(after)) marks.push({ kind: "redact", field, start: r.start, end: r.end });
}
}
if (slursOn(red?.slurs)) {
for (const [field, v, slurs] of drawnFields(entry)) {
if (!slurs) continue;
for (const h of slurMatches(v, red.slurs)) marks.push({ kind: "slur", field, start: h.start, end: h.end, mask: maskFor(red.slurs, h, v.slice(h.start, h.end)) });
}
}
// Every author the card blurs (post-item.mjs cardAuthors: the parents, the quoted post, a linked post, a reply's
// "replying to", and the item's own author when it names its subjects and is not one).
const authors = cardAuthors(entry).filter((a) => a.redact).map((a) => ({ kind: "author", where: a.where, handle: a.handle, reason: a.reason }));
const media = (Array.isArray(entry.media) ? entry.media : [])
.map((m, i) => {
const b = blurOf(m);
return b ? { kind: "blur", i, style: b.style, boxes: b.boxes, band: b.band, strength: b.strength, label: b.label } : null;
})
.filter(Boolean);
const counts = {
names: marks.filter((m) => m.kind === "redact").length,
slurs: marks.filter((m) => m.kind === "slur").length,
authors: authors.length,
pictures: media.length,
};
return counts.names + counts.slurs + counts.authors + counts.pictures ? { marks, authors, media, counts } : null;
}
/**
* A post item AS PUBLISHED, for a payload that cannot uncensor: its strings marked as the card draws them (the
* redaction's bars, the slurs' masks -- redactEntry), every author the card blurs left nameless (no name, handle or
* link in the data: the card draws "xxxx" for them either way), and its narration only as the take that plays
* (no script).
*
* @param {Record} entry
* @param {import("umtool-report-to-video/post-redact").Redaction | null} red
*/
export function publicPostEntry(entry, red, render = undefined) {
const out = /** @type {Record} */ (structuredClone(redactEntry(entry, red)));
// A blurred author keeps a handle that names nobody: the card's rule still blurs it, and a mention of it in any
// words is drawn blurred too (wordsHtml) -- the real handle is nowhere in the data.
const blurred = new Set();
const blank = (r) => {
if (!isObj(r)) return;
if (r.handle) blurred.add(String(r.handle).replace(/^@/, "").toLowerCase());
r.author = null;
r.handle = NOBODY;
delete r.url;
delete r.avatar;
};
for (const a of cardAuthors(entry)) {
if (!a.redact) continue;
if (a.where === "author") blank(out);
else if (a.where === "replyingTo") {
if (out.replyingTo) blurred.add(String(out.replyingTo).replace(/^@/, "").toLowerCase());
out.replyingTo = NOBODY;
} else if (a.where === "quoted") blank(out.quoted);
else {
const m = /^(parents|links)\[(\d+)\]$/.exec(a.where);
if (m) blank(out[m[1]]?.[Number(m[2])]);
}
}
if (blurred.size) {
const unmention = (v) => (typeof v === "string" ? v.replace(/@([A-Za-z0-9_]{1,30})/g, (m, h) => (blurred.has(h.toLowerCase()) ? `@${NOBODY}` : m)) : v);
const words = (r) => {
if (!isObj(r)) return;
for (const k of ["text", "paraphrase", "transcript"]) if (k in r) r[k] = unmention(r[k]);
};
words(out);
(Array.isArray(out.parents) ? out.parents : []).forEach(words);
words(out.quoted);
(Array.isArray(out.links) ? out.links : []).forEach(words);
if (typeof out.replyingTo === "string" && blurred.has(out.replyingTo.replace(/^@/, "").toLowerCase())) out.replyingTo = NOBODY;
if (Array.isArray(out.subjects)) out.subjects = out.subjects.filter((h) => !blurred.has(String(h).replace(/^@/, "").toLowerCase()));
}
// Its read as a preview may play it (post-thread.mjs playableTake: none when the build refuses it).
const take = playableTake(entry);
if (isObj(out.narration)) out.narration = take ? { takes: [{ file: take.file, seconds: take.seconds, ...(fin(take.rate) ? { rate: take.rate } : {}) }], pick: 0 } : { off: true };
delete out.notes;
// ITS SCREENS AS THE CARD DRAWS THEM (re-check M): built from the card's drawing, never a raw line in the data.
if (Array.isArray(out.screens)) {
out.screens = publicScreens(out, { authorHidden: cardAuthors(entry).some((a) => a.where === "author" && a.redact), roles: take ? partRoles(entry) : [], follow: followKnobs(entry, render ?? {}).on });
}
// A read not played: why, without the build's words (they name commands, not what was said).
if (isObj(out.readRefused)) out.readRefused = { reason: String(out.readRefused.reason ?? "") };
return out;
}
/**
* A post's SCREENS AS ITS CARD DRAWS THEM, for a payload that cannot uncensor (review round 1, i; re-check M) -- built
* FROM THE CARD's OWN DRAWING, never a second pass over the lines: only the screens the card draws (post-thread.mjs
* drawnScreens: the ones its read reads, with read-follow on), each as its rows (post-screens.mjs screenRows: a read
* line's read run alone, masked, "…" where it is cut; a line not read absent -- a `{ gap }` row where the card draws
* "⋯" -- or dim when the card draws it dim; a redacted line never), its header and badge (screenHeader), each row's
* speaker as the card names it (post-item.mjs screenSpeakerShown; a blurred one `xxxxxxxx`, one a speaker) and its
* time masked. `{ id, kind, media, at?, header, badge, excerpt, rows }` -- no `lines`, no `read`: nothing to draw from
* but what was drawn.
*
* @param {Record} entry the post item as the card draws it (its redaction marked, its anonymous authors
* under their names)
* @param {{ authorHidden?: boolean, roles?: Array<{ role: string | null }>, follow?: boolean }} [o] `roles`: its
* picked take's (partRoles); `follow`: read-follow on (off: the card is not threaded, no screen is drawn)
*/
export function publicScreens(entry, { authorHidden = false, roles = [], follow = true } = {}) {
if (!follow) return [];
const hidden = new Map();
const nobody = (who) => {
const k = String(who).trim().toLowerCase();
if (!hidden.has(k)) hidden.set(k, hidden.size ? `${NOBODY}${hidden.size + 1}` : NOBODY);
return hidden.get(k);
};
return drawnScreens(entry, roles).map((sc) => {
const head = screenHeader(entry, sc, { authorHidden });
const rows = screenRows(sc).map((r) => {
if (r.gap) return { gap: r.lines };
const l = sc.lines[r.n] ?? {};
const who = str(l.who).trim();
return {
n: r.n, text: `${r.cutBefore ? "…" : ""}${r.text}${r.cutAfter ? "…" : ""}`, read: r.read, side: screenSide(l, entry),
...(who ? { who: screenSpeakerShown(entry, l, { authorHidden }) ? maskedField(who) : nobody(who) } : {}),
...(str(l.time).trim() ? { time: maskedField(l.time.trim()) } : {}),
};
});
return { id: sc.id, kind: sc.kind, media: sc.media, ...(Array.isArray(sc.at) ? { at: sc.at } : {}), header: head.text, badge: head.badge, excerpt: screenIsExcerpt(sc), rows };
});
}
// ---------------------------------------------------------------------------
// THE SLIDES.
// ---------------------------------------------------------------------------
/** A public post's outline words: its author (or "a private account") and its words, each mark a block. */
function publicHeading(entry) {
const words = cardText(entry).replace(/^RT @[A-Za-z0-9_]+:\s*/, "").replace(/[\uE000-\uF8FF]+/g, "▇▇").replace(/\s+/g, " ").trim();
const who = str(entry.author) || (entry.handle ? `@${entry.handle}` : "a private account");
return `${who}: ${words.length > 80 ? `${words.slice(0, 77)}…` : words || "(no words)"}`;
}
/** A chronological reel of posts: every played entry a post item, their dates in order. */
export function isPostReel(entries) {
const posts = entries.filter((e) => e.type === "post");
if (posts.length < 2 || posts.length !== entries.length) return false;
let last = -Infinity;
for (const e of posts) {
const t = new Date(str(e.post?.date)).getTime();
if (Number.isNaN(t)) return false;
if (t < last) return false;
last = t;
}
return true;
}
/** A post item's slide id: its post's (`/`), else the entry's -- made unique in the deck. */
function postSlideId(e) {
const p = str(e.post?.post).trim();
return p || `item:${e.id}`;
}
/**
* THE PAYLOAD, pure (the tests' door): Play's view of the cut, the cut itself, the project's redaction and the
* deck's estimated schedule -> the presentation.
*
* A clip that hides regions of its picture (clip-censor.mjs) carries NO raw window on a payload that cannot uncensor:
* its `media` is null, and `censored` names its BUILT segment when one hides exactly its regions (`censoredSegments`,
* read by presentPayload: `{v, seconds}` by entry id), else null -- the slide says the clip is not shown. The
* operator's payload keeps the window, the regions overlaid on the operator's screen.
*
* @param {{ view: Record, manifest: Record, red: any, canUncensor?: boolean, censoredSegments?: Map }} o
*/
export function presentFrom({ view, manifest, red, canUncensor = true, censoredSegments = new Map() }) {
const render = manifest.render ?? {};
const timeline = (Array.isArray(manifest.timeline) ? manifest.timeline : []).filter((e) => e && typeof e.id === "string");
const zone = clockZoneOf(render);
// The deck's words per entry (its title, source line and QR) on the estimate's schedule.
/** @type {Map} */
const deck = new Map();
try {
for (const s of estimateSchedule(manifest)?.segments ?? []) deck.set(s.id, { title: str(s.title), subtitle: str(s.subtitle), qrUrl: s.qrUrl ?? null });
} catch {
// A cut the deck cannot schedule has no deck words: the slides carry their own.
}
const byId = new Map(timeline.map((e) => [e.id, e]));
// What plays: Play's entries, the walk's rejected clips left out (Play skips them).
const played = (view.entries ?? []).filter((e) => !(e.type === "clip" && e.rejected));
// ---- the sections: the markers', or the days of a posts reel, or the cut as one ----
const model = sectionModel(manifest);
const indexOf = new Map(timeline.map((e, i) => [e.id, i]));
const marked = model.placed.length > 0;
// (The intro is not a post: a posts reel that opens on one is still a posts reel.)
const days = !marked && isPostReel(played.filter((e) => e.type !== "intro"));
/** @type {Array<{ id: string, kind: "section"|"day"|"cut", label: string, date?: string, level?: number, color?: string | null }>} */
const sections = [];
const sectionIdOf = (e) => {
if (days) return `day-${dayIn(e.post?.date, zone)}`;
if (!marked) return "cut";
return `section-${model.entrySection[indexOf.get(e.id) ?? 0] ?? 0}`;
};
const slides = [];
const used = new Set();
const unique = (id) => {
let out = id;
for (let n = 2; used.has(out); n += 1) out = `${id}~${n}`;
used.add(out);
return out;
};
let lastSection = null;
// THE INTRO opens the deck, before the first divider, in the first section's band of the outline.
const firstReal = played.find((e) => e.type !== "intro");
for (const e of played) {
if (e.type === "intro") {
const src = byId.get(e.id) ?? {};
slides.push({
id: unique(e.id), kind: "intro", section: firstReal ? sectionIdOf(firstReal) : "cut", entry: e.id, label: "Intro", date: null, dateLabel: null,
style: str(src.style), seconds: fin(src.seconds) ? src.seconds : null,
...(typeof src.title === "string" ? { title: src.title } : {}),
...(Array.isArray(src.lines) ? { lines: src.lines.filter((l) => typeof l === "string") } : {}),
});
continue;
}
const sec = sectionIdOf(e);
if (sec !== lastSection) {
lastSection = sec;
if (days) {
const day = sec.slice(4);
sections.push({ id: sec, kind: "day", label: dayLabel(day) ?? day, date: day });
slides.push({ id: unique(sec), kind: "day", section: sec, label: dayLabel(day) ?? day, date: day, dateLabel: dayLabel(day), entry: null });
} else if (marked) {
const k = Number(sec.slice(8));
const s = model.sections[k];
const label = s?.label ?? (k === 0 ? text(manifest.title) || view.title : `Section ${k}`);
sections.push({ id: sec, kind: "section", label, ...(s?.level === 2 ? { level: 2 } : {}), color: s?.color ?? null });
slides.push({ id: unique(sec), kind: "section", section: sec, label, date: null, dateLabel: null, entry: null, ...(s?.level === 2 ? { level: 2, within: s.within ?? null } : {}) });
} else {
sections.push({ id: "cut", kind: "cut", label: view.title });
}
}
const src = byId.get(e.id) ?? {};
const words = deck.get(e.id) ?? null;
if (e.type === "post" && e.post && e.postPlan) {
const post = /** @type {Record} */ (e.post);
const day = dayIn(post.date, zone);
const take = playableTake(post);
const spans = excerptSpansOf(post);
const excerpt = spans ? excerptRanges(cardText(post), spans) : null;
const shown = canUncensor ? post : publicPostEntry(post, red, manifest.render);
slides.push({
id: unique(postSlideId(e)),
kind: "post",
section: sec,
entry: e.id,
label: canUncensor ? e.heading : publicHeading(shown),
date: day,
dateLabel: dayLabel(day),
post: shown,
plan: e.postPlan,
progress: e.postProgress ?? null,
clock: e.postClock ?? null,
scene: e.postScene ?? null,
combo: e.postCombo ?? null,
narration: take ? { file: take.file, seconds: take.seconds, ...(fin(take.rate) ? { rate: take.rate } : {}), ...(Array.isArray(take.words) && take.words.length ? { words: take.words } : {}) } : null,
excerpt,
qrUrl: words?.qrUrl ?? null,
censor: canUncensor ? censorData(post, red) : null,
});
continue;
}
if (e.type === "clip") {
const from = fin(e.cutStart) ? e.cutStart : e.start;
const to = fin(e.cutEnd) ? e.cutEnd : e.end;
const spans = keptSpans(from, to, gapsOf(e));
const day = dayOfKey(e.dateKey);
// Its hidden regions (clip-censor.mjs). A public payload never names the raw window of a clip that has them.
const hidden = censorRegionsOf(src, render, manifest.provenance ?? {});
const withheld = !canUncensor && hidden.length > 0;
const seg = withheld ? (censoredSegments.get(e.id) ?? null) : null;
slides.push({
id: unique(e.id),
kind: "clip",
section: sec,
entry: e.id,
label: words?.title || e.heading,
date: day,
dateLabel: dayLabel(day),
video: e.video,
channel: e.channel ?? null,
media: withheld ? null : (e.media ?? null),
...(withheld ? { censored: seg ? { segment: seg.v, seconds: seg.seconds, ...(seg.take ? { take: seg.take } : {}) } : null } : {}),
spans,
seconds: Math.round(spans.reduce((n, s) => n + (s.to - s.from), 0) * 1000) / 1000,
title: words?.title || text(e.heading),
subtitle: words?.subtitle ?? "",
quote: e.quote ?? null,
qrUrl: words?.qrUrl ?? null,
blur: clipBlurOf(src, render),
// The operator's page overlays them on the raw window (on the screen, not in the file).
hidden,
});
continue;
}
if (e.type === "teaser") {
const lines = (Array.isArray(src.lines) ? src.lines : []).map((l) => (typeof l === "string" ? l : text(l?.text))).filter(Boolean);
slides.push({
id: unique(e.id), kind: "teaser", section: sec, entry: e.id, label: lines[0] ?? e.heading, date: null, dateLabel: null,
lines, tail: typeof src.tail === "string" ? src.tail : null, seconds: fin(src.seconds) ? src.seconds : null,
});
continue;
}
if (e.type === "video" && e.videoEntry) {
slides.push({
id: unique(e.id), kind: "video", section: sec, entry: e.id, label: e.heading, date: null, dateLabel: null,
src: e.videoEntry.src, from: e.videoEntry.from, to: e.videoEntry.to, seconds: e.videoEntry.seconds,
});
continue;
}
slides.push({ id: unique(e.id), kind: "card", section: sec, entry: e.id, label: e.heading, date: null, dateLabel: null, heading: e.heading, type: e.type });
}
// A section's date: its first dated slide's (the outline's hint).
for (const s of sections) {
if (s.kind !== "section") continue;
const d = slides.find((x) => x.section === s.id && x.date)?.date ?? null;
if (d) s.date = d;
}
return {
version: PRESENT_VERSION,
project: view.project,
take: view.take ? { id: view.take.id, label: view.take.label, defaulted: false } : null,
title: view.title,
capabilities: { canUncensor: !!canUncensor },
settings: PRESENT_DEFAULTS,
// A 9:16 cut (`render.format: "vertical"`) is built 1080x1920 whatever its width and height say
// (takePreview.mjs previewKnobs): it presents tall (umtool redesign L7b).
box: render.format === "vertical" ? { width: 1080, height: 1920 } : { width: fin(render.width) ? render.width : 1920, height: fin(render.height) ? render.height : 1080 },
zone,
blurRendered: view.blurRendered !== false,
sections,
slides,
};
}
/**
* THE PAYLOAD of a project (or a take): Play's view, read with the build's own censored attachments (the channel
* markup's, post-censor.mjs censorEntry), and the project's redaction.
*
* @param {{ id: string, dir: string }} project
* @param {{ take?: string | null, bare?: boolean, canUncensor?: boolean }} [opts]
*/
export async function presentPayload(project, { take = null, bare = false, canUncensor = true } = {}) {
// The redaction is the cut's own (its terms, its channels' markup, its slur filter: a take's patch can switch it),
// read off the cut that plays; its censored attachments laid on each post item before it is planned.
let red = null;
// ON-SCREEN ANONYMISING (post-anon.mjs), the project's set: every post item and the deck's words (its subtitles,
// its QRs) as the build draws them. Unresolvable, or this video's characters unread: refused.
let anonymity = null;
let r;
try {
r = await playViewWith(project, {
take, bare,
postFor: async (manifest) => {
red = await projectRedaction(project.dir, manifest, { say: false });
const { projectAnonymousSet } = await import("umtool-report-to-video/project-characters-file");
anonymity = await projectAnonymousSet(project.dir, manifest);
const { anonymiseEntry } = await import("umtool-report-to-video/post-anon");
const set = anonymity.set;
return (e) => censorEntry(anonymiseEntry(e, set), red);
},
});
} catch (e) {
return { error: e instanceof Error ? e.message : String(e) };
}
if ("error" in r) return r;
const { anonymiseManifest } = await import("umtool-report-to-video/post-anon");
const manifest = anonymity ? anonymiseManifest(r.manifest, anonymity.doc, { set: anonymity.set }) : r.manifest;
return presentFrom({ view: r.view, manifest, red, canUncensor, censoredSegments: canUncensor ? new Map() : await censoredSegmentsOf(project, manifest, { take: r.view?.take?.id ?? null }) });
}
/**
* The BUILT segments (/api/report/segment: the project's out/, its cut record beside it) that hide exactly the
* regions a clip asks for now, by entry id -- what a public Present plays instead of the raw window. A segment cut
* with other boxes (or none) is not used.
*
* A take's own segments when a take is presented (takes//out/…), never the draft's under its name.
*
* @param {{ id: string, dir: string }} project
* @param {Record} manifest the cut presented (the take's, when one is)
* @param {{ take?: string | null }} [opts]
*/
export async function censoredSegmentsOf(project, manifest, { take = null } = {}) {
const { segmentFor, segmentHidesAsAsked } = await import("./serve.mjs");
const { readFile } = await import("node:fs/promises");
const out = new Map();
for (const e of manifest.timeline ?? []) {
if (e?.type !== "clip") continue;
if (!censorRegionsOf(e, manifest.render ?? {}, manifest.provenance ?? {}).length) continue;
const seg = await segmentFor(project, e.id, { take }).catch(() => null);
// The route's own rule (segmentHidesAsAsked): exactly the boxes asked for now.
if (!seg || !(await segmentHidesAsAsked(seg.abs, e, manifest))) continue;
const rec = await readFile(/* turbopackIgnore: true */ seg.abs.replace(/\.mp4$/, ".cut.json"), "utf8").then(JSON.parse, () => null);
const seconds = typeof rec?.start === "number" && typeof rec?.end === "number" ? Math.round((rec.end - rec.start) * 1000) / 1000 : null;
out.set(e.id, { v: seg.mtimeMs, seconds, take });
}
return out;
}