Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Overlay text check: show how long a problem lasts, and keep lyric fixes backing-free
Claudea69250286e0a
diff --git a/client/src/components/musicVideo/OverlayTextCheck.jsx b/client/src/components/musicVideo/OverlayTextCheck.jsxindex cba3f087ae..f32d455733 100644--- a/client/src/components/musicVideo/OverlayTextCheck.jsx+++ b/client/src/components/musicVideo/OverlayTextCheck.jsx@@ -30,20 +30,26 @@ export default function OverlayTextCheck({ report, onCheck, busy = false, onSeekconst running = report.status === 'running';const stale = report.status === 'complete' && !report.current;const summary = summaryOf(report);- const renderFinding = (finding) => (- <li key={finding.id} className="min-w-0">- <div className="flex flex-wrap items-center gap-x-2">- <span className={`font-medium ${finding.severity === 'error' ? 'text-port-error' : 'text-port-warning'}`}>{KIND_LABELS[finding.kind] || finding.kind}</span>- {onSeek- ? <button type="button" onClick={() => onSeek(finding.atSec)} aria-label={`Play ${formatTimecode(finding.atSec)} in the preview`}- className="min-h-[44px] text-port-accent underline sm:min-h-0">{formatTimecode(finding.atSec)}</button>- : <span>{formatTimecode(finding.atSec)}</span>}- {finding.sceneLabel && <span className="min-w-0 break-words text-xs text-port-text-muted">{finding.sceneLabel}</span>}- {finding.count > 1 && <span className="text-xs text-port-text-muted">seen {formatCount(finding.count)} times</span>}- </div>- <p className="break-words text-xs text-port-text-muted">{finding.message}</p>- </li>- );+ const renderFinding = (finding) => {+ // A problem traced to a few frames shows its exact first frame and its length, so it isn't mistaken for a false alarm.+ const momentary = finding.span && !finding.span.open && finding.span.frames > 0;+ const time = formatTimecode(finding.atSec, momentary ? 3 : 2);+ return (+ <li key={finding.id} className="min-w-0">+ <div className="flex flex-wrap items-center gap-x-2">+ <span className={`font-medium ${finding.severity === 'error' ? 'text-port-error' : 'text-port-warning'}`}>{KIND_LABELS[finding.kind] || finding.kind}</span>+ {onSeek+ ? <button type="button" onClick={() => onSeek(finding.atSec)} aria-label={`Play ${time} in the preview`}+ className="min-h-[44px] text-port-accent underline sm:min-h-0">{time}</button>+ : <span>{time}</span>}+ {momentary && <span className="text-xs text-port-warning">{plural(finding.span.frames, 'frame')} only</span>}+ {finding.sceneLabel && <span className="min-w-0 break-words text-xs text-port-text-muted">{finding.sceneLabel}</span>}+ {finding.count > 1 && <span className="text-xs text-port-text-muted">seen {formatCount(finding.count)} times</span>}+ </div>+ <p className="break-words text-xs text-port-text-muted">{finding.message}</p>+ </li>+ );+ };const shown = report.findings.slice(0, SHOWN);const folded = report.findings.slice(SHOWN);return (diff --git a/client/src/components/musicVideo/OverlayTextCheck.test.jsx b/client/src/components/musicVideo/OverlayTextCheck.test.jsxindex a4d33ce197..cddc658f0d 100644--- a/client/src/components/musicVideo/OverlayTextCheck.test.jsx+++ b/client/src/components/musicVideo/OverlayTextCheck.test.jsx@@ -25,6 +25,13 @@ describe('OverlayTextCheck', () => {expect(screen.getByText('Hard to read')).toBeTruthy();fireEvent.click(screen.getByRole('button', { name: 'Play 1:01.00 in the preview' }));expect(onSeek).toHaveBeenCalledWith(61);++ // A collision traced to one frame shows that frame exactly, and its length.+ const momentary = { ...finding(5), atSec: 44.767, span: { startSec: 44.767, endSec: 44.767, frames: 1, open: false } };+ rerender(<OverlayTextCheck report={{ status: 'complete', current: true, textSamples: 40, findings: [momentary], counts: counts(1) }} onCheck={onCheck} onSeek={onSeek} />);+ expect(screen.getByText('1 frame only')).toBeTruthy();+ fireEvent.click(screen.getByRole('button', { name: 'Play 0:44.767 in the preview' }));+ expect(onSeek).toHaveBeenLastCalledWith(44.767);});it('says when the text is clean, when the result is for an earlier version, and why a check failed', () => {diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.jsindex b6dcab4cc6..a26e0ddacb 100644--- a/client/src/utils/formatters.js+++ b/client/src/utils/formatters.js@@ -632,11 +632,11 @@ export function formatDurationSec(seconds) {* Format a number of seconds as M:SS.ss for video-editor timecodes* (e.g. 95.42 → "1:35.42"). Negative or non-finite inputs render as "0:00.00".*/-export function formatTimecode(seconds) {- if (!Number.isFinite(seconds) || seconds < 0) return '0:00.00';+export function formatTimecode(seconds, digits = 2) {+ if (!Number.isFinite(seconds) || seconds < 0) return `0:00.${'0'.repeat(digits)}`;const m = Math.floor(seconds / 60);const s = seconds - m * 60;- return `${m}:${s.toFixed(2).padStart(5, '0')}`;+ return `${m}:${s.toFixed(digits).padStart(3 + digits, '0')}`;}/**diff --git a/server/services/musicVideo/documentRender.js b/server/services/musicVideo/documentRender.jsindex 9ee0ef7409..70735007ab 100644--- a/server/services/musicVideo/documentRender.js+++ b/server/services/musicVideo/documentRender.js@@ -444,9 +444,10 @@ const PROBE_BACKDROP_SCALE = 0.5;* Open a project's composition document the way a render does (same staged* data and selected takes, same frame) with the overlay text probe installed* (overlayTextProbe.js), and visit each song time `sampleTimes(data, frame)`- * returns. At each one `onSample({ atSec, records, backdrop })` gets the text- * the page drew and, when there was any, the frame with that text hidden as- * linear luminance (`{ width, height, scale, values: Float32Array }`). Resolves+ * returns. At each one `onSample({ index, atSec, records, backdrop })` gets the+ * text the page drew and, when there was any, the frame with that text hidden+ * as linear luminance (`{ width, height, scale, values: Float32Array }`). Times+ * `onSample` returns are visited after the planned ones. Resolves* `{ frame, scenes, samples }` (the PORTOS_MV scenes, for naming shots).*/export async function probeDocumentText({ project, jobId, signal, sampleTimes, onSample, onProgress }) {@@ -489,8 +490,11 @@ export async function probeDocumentText({ project, jobId, signal, sampleTimes, oawait page.evaluate(`globalThis.portosComposition.layout({ width: ${target.width}, height: ${target.height} })`);}const frame = { width: target.width, height: target.height };- const times = sampleTimes(data, { ...frame, fps: target.fps, durationSec: target.durationSec });- for (const [index, atSec] of times.entries()) {+ // onSample may return extra times to probe (a problem traced frame by frame); they+ // run after the planned ones, in the order returned, each with its own index.+ const times = [...sampleTimes(data, { ...frame, fps: target.fps, durationSec: target.durationSec })];+ for (let index = 0; index < times.length; index++) {+ const atSec = times[index];signal?.throwIfAborted();page.check();await page.evaluate('globalThis.__portosTextProbe.begin()');@@ -509,7 +513,8 @@ export async function probeDocumentText({ project, jobId, signal, sampleTimes, o}backdrop = { width: info.width, height: info.height, scale: info.width / target.width, values };}- onSample({ atSec, frame, records: Array.isArray(records) ? records : [], backdrop });+ const extra = onSample({ index, atSec, frame, records: Array.isArray(records) ? records : [], backdrop });+ for (const t of Array.isArray(extra) ? extra : []) times.push(t);onProgress?.((index + 1) / times.length);}page.check();diff --git a/server/services/musicVideo/overlayText.js b/server/services/musicVideo/overlayText.jsindex 0e366082af..71db4f6f17 100644--- a/server/services/musicVideo/overlayText.js+++ b/server/services/musicVideo/overlayText.js@@ -41,6 +41,9 @@ const OVERLAY_TEXT_LIMITS = Object.freeze({minHaloContrast: 3,// Text more transparent than this is mid-fade: skipped for overlap and size.minAlpha: 0.35,+ // Collisions and cut-off text are traced frame by frame up to this many frames+ // each way, so a momentary one (a line swap, a slam-in swell) reports its length.+ spanFrames: 4,// Contrast is judged only on settled (near-opaque) text.contrastAlpha: 0.85,});@@ -50,7 +53,9 @@ const SEVERITY = Object.freeze({ overlap: 'error', 'off-frame': 'error', contrasexport const OVERLAY_TEXT_PROCESS_ID = randomUUID();const finite = (n) => typeof n === 'number' && Number.isFinite(n);-const round3 = (n) => Math.round(n * 1000) / 1000;+// Frame times are kept to the millisecond, rounded UP: a time rounded down can fall+// in the previous frame (7/12 s → 0.583 is still frame 6), so a seek would show the wrong one.+const frameMs = (n) => Math.ceil(n * 1000 - 1e-6) / 1000;const round1 = (n) => Math.round(n * 10) / 10;/** `{ r, g, b, a }` (0-255, alpha 0-1) for a CSS colour a canvas or computed style reports; null otherwise. */@@ -126,10 +131,10 @@ export function planTextSampleTimes({ lyrics = [], textCues = [], scenes = [], d.map((t) => Math.min(last, Math.max(0, Math.floor(t * fps + 1e-6) / fps))).sort((a, b) => a - b);const kept = [];- for (const t of snapped) if (!kept.length || t - kept[kept.length - 1] >= 0.15) kept.push(round3(t));+ for (const t of snapped) if (!kept.length || t - kept[kept.length - 1] >= 0.15) kept.push(frameMs(t));// The first frame drawn at or after the entrance (a frame before it shows nothing yet).const firstFrames = [...new Set(entrances- .map((t) => round3(Math.min(last, Math.max(0, Math.ceil(t * fps - 1e-6) / fps)))))].sort((a, b) => a - b);+ .map((t) => frameMs(Math.min(last, Math.max(0, Math.ceil(t * fps - 1e-6) / fps)))))].sort((a, b) => a - b);const merged = new Set([...thinEvenly(kept, maxSamples), ...thinEvenly(firstFrames, maxEntrances)]);return [...merged].sort((a, b) => a - b);}@@ -297,16 +302,45 @@ export function analyzeTextFrame(items = [], frame) {const quote = (text) => `“${text}”`;/** One plain sentence for a finding (what is wrong, and the fix lyricType uses). */-function describeTextFinding({ kind, texts, detail }) {+function describeTextFinding({ kind, texts, detail, span }) {+ return `${describeProblem({ kind, texts, detail })}${spanNote(span)}`;+}++// A problem traced to a few frames says so: it is real but easy to miss when scrubbing.+const spanNote = (span) => (span && !span.open && span.frames > 0+ ? ` It is on screen for ${span.frames} frame${span.frames === 1 ? '' : 's'}.` : '');++function describeProblem({ kind, texts, detail }) {switch (kind) {case 'overlap': return `${quote(texts[0])} collides with ${quote(texts[1])}. Move the smaller one to the corner opposite the sung words, or time them apart.`;case 'off-frame': return `${quote(texts[0])} runs off the edge of the frame. Keep it inside the safe margin or let it wrap.`;case 'small': return `${quote(texts[0])} is ${detail?.phoneEmPx ?? 'too few'}px tall at phone width. Set it larger (at least ${OVERLAY_TEXT_LIMITS.minPhoneEmPx}px on a phone).`;- case 'contrast': return `${quote(texts[0])} blends into the picture (${detail?.ratio ?? '?'}:1). Give it an ink outline wide enough to read on a phone${detail?.outlined ? ' (its outline is too thin there)' : ''}, or a plate behind it.`;+ case 'contrast': return `${quote(texts[0])} blends into the picture (${detail?.ratio ?? '?'}:1). ${detail?.needed === OVERLAY_TEXT_LIMITS.contrastSmall+ // Small type is a readout or caption, which may sit on a plate; lyrics never take a backing.+ ? `Give it an ink outline wide enough to read on a phone${detail?.outlined ? ' (its outline is too thin there)' : ''}, or a plate behind it.`+ : `Give it a wider ink outline${detail?.outlined ? ' (its outline is too thin there)' : ''}, move it to a darker or quieter part of the frame, or time it off the brightest moment; lyrics take no plate or shade behind them.`}`;default: return quote(texts.join(' / '));}}+const sameText = (a, b) => {+ const x = String(a).toLowerCase();+ const y = String(b).toLowerCase();+ return x.includes(y) || y.includes(x);+};++/**+ * The same problem on a neighbouring frame: same kind and the same text (either+ * may be a partial reading while a line reveals word by word), in either order+ * for a collision.+ */+export function sameIssue(a, b) {+ if (a?.kind !== b?.kind || a.texts?.length !== b.texts?.length) return false;+ if (a.texts.length === 1) return sameText(a.texts[0], b.texts[0]);+ return (sameText(a.texts[0], b.texts[0]) && sameText(a.texts[1], b.texts[1]))+ || (sameText(a.texts[0], b.texts[1]) && sameText(a.texts[1], b.texts[0]));+}+// Words appear one by one, so the same line reads "whole", then "whole species// bloom": a finding of the same kind whose text contains (or is contained in)// another's, seen within a few seconds, is the same problem.@@ -328,9 +362,15 @@ function sameProblem(finding, issue, atSec) {const sceneAt = (scenes, t) => (scenes || []).filter((s) => finite(s?.startSec) && s.startSec <= t + 1e-6 && (!finite(s.endSec) || t < s.endSec)).pop() || null;const findingKey = (issue) => `${issue.kind}|${issue.texts.map((t) => t.toLowerCase()).sort().join('|')}`;+/** Kinds whose length is traced frame by frame (they are often momentary). */+export const OVERLAY_TEXT_SPAN_KINDS = Object.freeze(['overlap', 'off-frame']);+/** Frames traced each way before a problem counts as lasting (`span.open`). */+export const OVERLAY_TEXT_SPAN_FRAMES = OVERLAY_TEXT_LIMITS.spanFrames;+/*** Merge per-sample issues (`[{ atSec, issues }]`) into findings, errors first,- * then by first time seen; each names the shot it was first seen in.+ * then by first time seen; each names the shot it was first seen in. An issue's+ * `span` (`{ startSec, endSec, frames, open }`, traced by the service) rides along.*/export function summarizeTextFindings(samples = [], scenes = []) {const L = OVERLAY_TEXT_LIMITS;@@ -340,14 +380,15 @@ export function summarizeTextFindings(samples = [], scenes = []) {const key = findingKey(issue);const found = byKey.get(key) || [...byKey.values()].find((f) => sameProblem(f, issue, sample.atSec));if (found) {- if (found.times.length < L.maxTimesPerFinding && !found.times.includes(round3(sample.atSec))) found.times.push(round3(sample.atSec));+ if (found.times.length < L.maxTimesPerFinding && !found.times.includes(frameMs(sample.atSec))) found.times.push(frameMs(sample.atSec));found.count += 1;+ if (!found.span && issue.span) found.span = issue.span;found.lastSec = sample.atSec;// Keep the fullest reading of the text (the whole line, not its first word).if (issue.texts.join(' ').length > found.texts.join(' ').length) {found.texts = issue.texts;found.detail = issue.detail ?? found.detail;- found.message = describeTextFinding(issue);+ found.message = describeTextFinding({ ...issue, span: issue.span ?? found.span });}continue;}@@ -355,7 +396,9 @@ export function summarizeTextFindings(samples = [], scenes = []) {byKey.set(key, {id: createHash('sha1').update(key).digest('hex').slice(0, 12),kind: issue.kind, severity: SEVERITY[issue.kind] || 'warning', texts: issue.texts, detail: issue.detail ?? null,- atSec: round3(sample.atSec), lastSec: sample.atSec, times: [round3(sample.atSec)], count: 1,+ // A traced span starts the finding at the first frame the problem is on screen.+ atSec: frameMs(issue.span?.startSec ?? sample.atSec), lastSec: sample.atSec, times: [frameMs(sample.atSec)], count: 1,+ span: issue.span ?? null,sceneId: scene?.sceneId ?? null, sceneLabel: scene?.label || null,message: describeTextFinding(issue),});diff --git a/server/services/musicVideo/overlayText.test.js b/server/services/musicVideo/overlayText.test.jsindex f75a6026d2..ba45102902 100644--- a/server/services/musicVideo/overlayText.test.js+++ b/server/services/musicVideo/overlayText.test.js@@ -6,7 +6,7 @@*/import { describe, expect, it } from 'vitest';import {- OVERLAY_TEXT_PROCESS_ID, analyzeTextFrame, mergeTextRecords, overlayTextReport, planTextSampleTimes, summarizeTextFindings,+ OVERLAY_TEXT_PROCESS_ID, analyzeTextFrame, mergeTextRecords, overlayTextReport, planTextSampleTimes, sameIssue, summarizeTextFindings,} from './overlayText.js';const FRAME = { width: 1920, height: 1080 };@@ -57,6 +57,15 @@ describe('analyzeTextFrame', () => {// Dark ink on the same pale frame needs no outline.expect(frameIssues(word('BLOOM', 100, 400, { fill: INK }), PALE)).toEqual([]);});++ it('never suggests a backing behind lyrics; a small readout may take a plate', () => {+ const [lyric] = summarizeTextFindings([{ atSec: 1, issues: frameIssues(word('BLOOM', 100, 400), PALE) }]);+ expect(lyric.message).toContain('lyrics take no plate or shade');+ expect(lyric.message).not.toContain('plate behind it');+ const readout = word('20 MILLION YEARS', 40, 80, { font: '500 40px Plex Mono', em: 40, w: 700, h: 32 });+ const [data] = summarizeTextFindings([{ atSec: 1, issues: frameIssues(readout, PALE) }]);+ expect(data.message).toContain('or a plate behind it');+ });});describe('summarizeTextFindings', () => {@@ -77,6 +86,21 @@ describe('summarizeTextFindings', () => {]);expect(findings[1].message).toContain('“whole species bloom”');});++ it('starts a traced problem at its first frame and says when it lasts only a few frames', () => {+ const overlap = (a, b, span) => ({ kind: 'overlap', texts: [a, b], detail: null, span });+ const [brief, lasting] = summarizeTextFindings([+ { atSec: 44.792, issues: [overlap('AT THE SCALE OF THE UNIVERSE', 'YOU', { startSec: 44.75, endSec: 44.792, frames: 2, open: false })] },+ { atSec: 60, issues: [overlap('DATA', 'HOOK', { startSec: 59.833, endSec: 60.167, frames: 9, open: true })] },+ ]);+ expect(brief).toMatchObject({ atSec: 44.75, span: { frames: 2, open: false } });+ expect(brief.message).toContain('on screen for 2 frames');+ expect(lasting.atSec).toBe(59.833);+ expect(lasting.message).not.toContain('frames');+ // The next frame's reading of the same problem may have more of the line, or the pair the other way round.+ expect(sameIssue(overlap('YOU', 'AT THE SCALE'), overlap('AT THE SCALE OF THE UNIVERSE', 'YOU ARE'))).toBe(true);+ expect(sameIssue(overlap('YOU', 'AT THE SCALE'), { kind: 'off-frame', texts: ['YOU'] })).toBe(false);+ });});describe('planTextSampleTimes', () => {@@ -87,7 +111,7 @@ describe('planTextSampleTimes', () => {durationSec: 8, fps: 24,});// 1 and 2.042 are entrance frames (a slam-in is largest there), kept however close to a settled sample.- expect(times).toEqual([0.25, 1, 1.333, 2.042, 2.5, 3.792, 4]);+ expect(times).toEqual([0.25, 1, 1.334, 2.042, 2.5, 3.792, 4]);expect(times.every((t) => Math.abs(t * 24 - Math.round(t * 24)) < 0.05)).toBe(true);const many = planTextSampleTimes({ scenes: Array.from({ length: 300 }, (_, i) => ({ startSec: i, endSec: i + 1 })), durationSec: 300, maxSamples: 50 });expect(many).toHaveLength(50);diff --git a/server/services/musicVideo/overlayTextService.browser.test.js b/server/services/musicVideo/overlayTextService.browser.test.jsindex 0ca7b3050c..69afeab3eb 100644--- a/server/services/musicVideo/overlayTextService.browser.test.js+++ b/server/services/musicVideo/overlayTextService.browser.test.js@@ -1,7 +1,8 @@/*** The overlay text check end to end in a real headless Chrome: a document that* draws a corner readout under a big lyric, a pale caption on a pale frame, a- * line past the right edge, a tiny tag and a DOM caption is staged like a+ * line past the right edge, a tiny tag, a word that crosses that tag for a+ * single frame and a DOM caption is staged like a* render, probed at its text moments, and each problem comes back once —* while a word ringed in a wide ink outline, and a caption on an ink plate,* pass on the same pale frame: either is a legibility treatment, not a problem.@@ -39,7 +40,7 @@ const PAGE = `<!doctype html><html><head><style>const APP = `const ctx = document.getElementById('c').getContext('2d');-function draw() {+function draw(t) {ctx.fillStyle = '#f3ead7'; ctx.fillRect(0, 0, 1280, 720);// A corner readout on a plate too short for it, under a big outlined lyric.ctx.fillStyle = '#141217'; ctx.fillRect(40, 60, 380, 60);@@ -57,8 +58,10 @@ function draw() {ctx.fillStyle = '#141217'; ctx.fillText('OFF THE EDGE', 1040, 640);// Too small for a phone.ctx.font = '14px sans-serif'; ctx.fillText('tiny tag', 80, 600);+ // Over the tag for exactly one frame (fps 12), as a line swap can be.+ if (t >= 0.5 - 1e-6 && t < 0.5 + 1 / 12 - 1e-6) { ctx.font = '900 64px sans-serif'; ctx.fillText('FLASH', 70, 620); }}-globalThis.portosComposition = { durationSec: 4, fps: 12, width: 1280, height: 720, async seek() { draw(); } };+globalThis.portosComposition = { durationSec: 4, fps: 12, width: 1280, height: 720, async seek(t) { draw(t); } };`;describe.skipIf(!chrome)('overlay text check (headless Chrome)', () => {@@ -81,7 +84,10 @@ describe.skipIf(!chrome)('overlay text check (headless Chrome)', () => {const kinds = (text) => check.findings.filter((f) => f.texts.some((t) => t.includes(text))).map((f) => f.kind).sort();expect(kinds('20 MILLION YEARS')).toContain('overlap');- expect(check.findings.find((f) => f.kind === 'overlap').texts).toEqual(expect.arrayContaining(['20 MILLION YEARS', 'WHOLE']));+ expect(check.findings.find((f) => f.kind === 'overlap' && f.texts.includes('WHOLE')).texts).toEqual(expect.arrayContaining(['20 MILLION YEARS', 'WHOLE']));+ // Traced frame by frame: the one-frame collision reports its exact frame and length; a lasting one stays open.+ expect(check.findings.find((f) => f.texts.includes('FLASH'))).toMatchObject({ kind: 'overlap', atSec: 0.5, span: { frames: 1, open: false } });+ expect(check.findings.find((f) => f.texts.includes('WHOLE')).span).toMatchObject({ open: true });expect(kinds('DISAPPEAR')).toEqual(['contrast']);expect(kinds('OFF THE EDGE')).toEqual(['off-frame']);expect(kinds('tiny tag')).toContain('small');@@ -94,7 +100,7 @@ describe.skipIf(!chrome)('overlay text check (headless Chrome)', () => {const report = productionReadiness(await projects.getProject(created.id)).storyboard.text;expect(report).toMatchObject({ status: 'complete', current: true });- expect(report.counts.errors).toBe(2);+ expect(report.counts.errors).toBe(3);}, 120000);it('passes the shipped layered template: lyricType lines and a data readout on a pale still', async () => {diff --git a/server/services/musicVideo/overlayTextService.js b/server/services/musicVideo/overlayTextService.jsindex 4130f27ef7..d0617895c0 100644--- a/server/services/musicVideo/overlayTextService.js+++ b/server/services/musicVideo/overlayTextService.js@@ -20,7 +20,8 @@ import { getProject, mutateProjectRecord } from './projects.js';import { musicVideoEvents } from './events.js';import { overlayTextBasis, productionReadiness } from './productionReview.js';import {- OVERLAY_TEXT_PROCESS_ID, analyzeTextFrame, backdropStats, mergeTextRecords, planTextSampleTimes, summarizeTextFindings,+ OVERLAY_TEXT_PROCESS_ID, OVERLAY_TEXT_SPAN_FRAMES, OVERLAY_TEXT_SPAN_KINDS, analyzeTextFrame, backdropStats, mergeTextRecords,+ planTextSampleTimes, sameIssue, summarizeTextFindings,} from './overlayText.js';const inflight = new Map(); // projectId → { id, controller, done }@@ -48,17 +49,62 @@ function assertCheckable(project) {async function inspectOverlayText(project, { signal, onProgress } = {}) {const { probeDocumentText } = await import('./documentRender.js');const samples = [];+ // Each extra probe, in the order it was queued: which sample's problems it traces, which way, how far.+ const steps = [];+ let plannedCount = 0;+ let clock = null;let textSamples = 0;+ const frameAt = (t) => Math.round(t * clock.fps);+ const lastFrame = () => Math.floor(clock.durationSec * clock.fps - 1e-6);+ // The next frame along `dir` (-1 back, +1 forward) for a sample's traced problems, or nothing past either end.+ const stepFrom = (sample, atSec, dir, step) => {+ const next = frameAt(atSec) + dir;+ if (next < 0 || next > lastFrame()) return [];+ steps.push({ sample, dir, step });+ return [next / clock.fps];+ };const result = await probeDocumentText({project, jobId: `text-check-${randomUUID()}`, signal, onProgress,- sampleTimes: (data, clock) => planTextSampleTimes({ lyrics: data.lyrics, textCues: data.textCues, scenes: data.scenes, durationSec: clock.durationSec, fps: clock.fps }),- onSample: ({ atSec, frame, records, backdrop }) => {+ sampleTimes: (data, docClock) => {+ clock = docClock;+ const times = planTextSampleTimes({ lyrics: data.lyrics, textCues: data.textCues, scenes: data.scenes, durationSec: docClock.durationSec, fps: docClock.fps });+ plannedCount = times.length;+ return times;+ },+ // A collision or cut-off line is traced frame by frame each way (extra probe+ // times returned to the renderer), so a momentary one reports its length.+ onSample: ({ index, atSec, frame, records, backdrop }) => {const items = mergeTextRecords(records);- if (items.length) textSamples += 1;for (const item of items) item.backdrop = backdropStats(backdrop, item);- samples.push({ atSec, issues: analyzeTextFrame(items, frame) });+ const issues = analyzeTextFrame(items, frame);+ if (index < plannedCount) {+ if (items.length) textSamples += 1;+ const traced = issues.filter((i) => OVERLAY_TEXT_SPAN_KINDS.includes(i.kind));+ for (const issue of traced) issue.span = { startSec: atSec, endSec: atSec, open: false, alive: { [-1]: true, [1]: true } };+ const sample = { atSec, issues };+ samples.push(sample);+ return traced.length ? [...stepFrom(sample, atSec, -1, 1), ...stepFrom(sample, atSec, 1, 1)] : undefined;+ }+ const { sample, dir, step } = steps[index - plannedCount];+ let going = false;+ for (const issue of sample.issues) {+ if (!issue.span?.alive[dir]) continue;+ if (!issues.some((later) => sameIssue(issue, later))) { issue.span.alive[dir] = false; continue; }+ issue.span[dir < 0 ? 'startSec' : 'endSec'] = atSec;+ if (step >= OVERLAY_TEXT_SPAN_FRAMES) { issue.span.open = true; issue.span.alive[dir] = false; } else going = true;+ }+ return going ? stepFrom(sample, atSec, dir, step + 1) : undefined;},});+ for (const sample of samples) {+ for (const issue of sample.issues) {+ if (!issue.span) continue;+ const { startSec, endSec, open } = issue.span;+ // Milliseconds rounded up, so a seek to either end lands on that frame.+ const ms = (t) => Math.ceil(t * 1000 - 1e-6) / 1000;+ issue.span = { startSec: ms(startSec), endSec: ms(endSec), open, frames: frameAt(endSec) - frameAt(startSec) + 1 };+ }+ }return { samples: result.samples, textSamples, frame: result.frame, findings: summarizeTextFindings(samples, result.scenes) };}