Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/packages/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ edges re-measured to about 0.01 s, and skipped for a `--range` check.

| Code | Warns when |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `line_unread` | A reading-size line (30 px or taller at 1080) is on screen for less than its floor: 0.4 s for one or two words, otherwise three quarters of 0.5 s + 0.3 s a word. The film's last line needs 2 s. |
| `line_unread` | A reading-size line (30 px or taller at 1080) is on screen for less than its floor: 0.4 s for one or two words, otherwise three quarters of 0.5 s + 0.3 s a word. The film's last line needs 2 s. A line the next scene repeats in place is timed as one line. |
| `dead_stretch` | Nothing on screen changes for more than 3 s, by the same classifier `keepsMoving` uses. |
| `text_below_floor` | Text under 2.6% of the frame's short side (28 px on 1080) stays on screen 0.5 s or more. One finding per file lists every such element. |
| `first_frame_empty` | Frame 0 paints nothing but the background (no text, image, video, canvas or SVG), or an opaque element covers every other clip and is named. The first frame is the thumbnail on social players. |
Expand Down
29 changes: 28 additions & 1 deletion packages/cli/src/utils/craftAudit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface Shown {
block?: number;
/** The block's rendered text; defaults to `text`. */
blockText?: string;
/** Where the line sits; defaults to a few pixels below the previous key's. */
top?: number;
}

function part(shown: Shown): CraftTextPart {
Expand All @@ -40,7 +42,7 @@ function part(shown: Shown): CraftTextPart {
blockText: shown.blockText ?? shown.text,
opacity: 1,
fontPx,
rect: { left: 100, top: 100 + shown.key * 10, width: 800, height: fontPx * 1.2 },
rect: { left: 100, top: shown.top ?? 100 + shown.key * 10, width: 800, height: fontPx * 1.2 },
captions: shown.captions ?? false,
};
}
Expand Down Expand Up @@ -218,6 +220,31 @@ describe("line_unread", () => {
expect(await detectLineUnread(film(12, shown), 12, CANVAS, probeFor(shown))).toEqual([]);
});

// fails without the fix: each scene's copy of the alert was its own line, so the first measured 2.1 s.
it("measures a line the next scene repeats in place as one line", async () => {
const alert =
"Ballistic missile threat inbound to Hawaii. Seek immediate shelter. This is not a drill.";
const shown: Shown[] = [
{ key: 1, text: alert, from: 0, to: 2.1, top: 560 },
{ key: 2, text: alert, from: 2.1, to: 7, top: 560 },
{ key: 3, text: "The end", from: 7, to: 10 },
];
expect(await detectLineUnread(film(10, shown), 10, CANVAS, probeFor(shown))).toEqual([]);
});

it("still measures the same words shown elsewhere on screen as another line", async () => {
const alert =
"Ballistic missile threat inbound to Hawaii. Seek immediate shelter. This is not a drill.";
const shown: Shown[] = [
{ key: 1, text: alert, from: 0, to: 2.1, top: 100 },
{ key: 2, text: alert, from: 2.1, to: 7, top: 700 },
{ key: 3, text: "The end", from: 7, to: 10 },
];
const findings = await detectLineUnread(film(10, shown), 10, CANVAS, probeFor(shown));
expect(findings.map((finding) => finding.selector)).toEqual(["#t1"]);
expect(findings[0]?.seconds).toBeCloseTo(2.1, 1);
});

it("skips text too small to be a reading line", async () => {
const shown: Shown[] = [
{ key: 1, text: "Legal fine print that flashes by", from: 1, to: 1.3, fontPx: 18 },
Expand Down
52 changes: 37 additions & 15 deletions packages/cli/src/utils/craftAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ interface CraftRect {
}

interface BlockTrack {
key: number;
keys: Set<number>;
selector: string;
sourceFile: string;
/** Frame index → what the block showed there. */
Expand Down Expand Up @@ -259,19 +259,39 @@ interface Anchor {

function trackBlocks(frames: CraftFrame[], readHeight: number): BlockTrack[] {
const tracks = new Map<number, BlockTrack>();
let previous = new Map<number, BlockFrame & Anchor>();
frames.forEach((frame, index) => {
for (const [key, block] of readableBlocks(frame, readHeight)) {
const track = tracks.get(key) ?? {
key,
selector: block.selector,
sourceFile: block.sourceFile,
seen: new Map<number, BlockFrame>(),
};
track.seen.set(index, { text: block.text, rect: block.rect });
const blocks = readableBlocks(frame, readHeight);
for (const [key, block] of blocks) {
const track = tracks.get(key) ??
carriedOver(tracks, previous, block) ?? {
keys: new Set<number>(),
selector: block.selector,
sourceFile: block.sourceFile,
seen: new Map<number, BlockFrame>(),
};
track.keys.add(key);
if (!track.seen.has(index)) track.seen.set(index, { text: block.text, rect: block.rect });
tracks.set(key, track);
}
previous = blocks;
});
return [...tracks.values()];
return [...new Set(tracks.values())];
}

function carriedOver(
tracks: Map<number, BlockTrack>,
previous: Map<number, BlockFrame>,
block: BlockFrame,
): BlockTrack | undefined {
for (const [key, before] of previous) {
if (before.text === block.text && rectsOverlap(before.rect, block.rect)) return tracks.get(key);
}
return undefined;
}

function rectsOverlap(a: CraftRect, b: CraftRect): boolean {
return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
}

/** Maximal runs of consecutive frame indices. */
Expand Down Expand Up @@ -374,8 +394,10 @@ async function refineWindow(
canvas: Canvas,
): Promise<LineWindow> {
const readHeight = T.readHeightAt1080 * (Math.min(canvas.width, canvas.height) / 1080);
const visibleAt = async (time: number) =>
readableBlocks(await probe(time), readHeight).has(candidate.track.key);
const visibleAt = async (time: number) => {
const blocks = readableBlocks(await probe(time), readHeight);
return [...candidate.track.keys].some((key) => blocks.has(key));
};
const window = { ...candidate.window };
for (let step = 0; step < T.refineSteps; step += 1) {
if (window.startIn > window.startOut) {
Expand Down Expand Up @@ -445,7 +467,7 @@ function lineUnreadFinding(
words,
seconds: round(held),
floorSeconds: round(floor),
measured: measuredAround(frames, track.key, candidate.firstIndex, candidate.lastIndex),
measured: measuredAround(frames, track.keys, candidate.firstIndex, candidate.lastIndex),
};
}

Expand All @@ -454,7 +476,7 @@ const MEASURED_SPAN = 3;
/** The samples at both ends of the line's run, as the sampler measured them. */
function measuredAround(
frames: CraftFrame[],
key: number,
keys: Set<number>,
first: number,
last: number,
): NonNullable<CraftFinding["measured"]> {
Expand All @@ -466,7 +488,7 @@ function measuredAround(
for (const index of [...indices].sort((a, b) => a - b)) {
const frame = frames[index];
if (!frame) continue;
const parts = frame.parts.filter((part) => part.block === key && !part.captions);
const parts = frame.parts.filter((part) => keys.has(part.block) && !part.captions);
if (parts.length === 0) {
out.push({ time: round(frame.time), opacity: null, heightPx: null });
continue;
Expand Down
2 changes: 1 addition & 1 deletion skills-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"files": 80
},
"hyperframes-cli": {
"hash": "d6972257fbc99fc0",
"hash": "f6d0b68333e48008",
"files": 13
},
"hyperframes-registry": {
Expand Down
2 changes: 1 addition & 1 deletion skills/hyperframes-cli/references/lint-validate-inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Run it as `npx hyperframes check`, never through `npm run`: a tool timeout's SIG
- **Motion**: `*.motion.json` sidecar assertions against the same seeked timeline (see below).
- **Contrast**: WCAG AA on visible text, sampled at 5 grid points. Failures are **errors** and each finding carries the sampled fg/bg colors, measured vs required ratio, and a suggested compliant color in the same palette direction, so most contrast fixes need no screenshot at all.
- **Craft**: warnings only, even under `--strict` (a film may break one on purpose), measured on an 8 fps sweep of the whole film and skipped under `--range`. Each message names the fix and the reference to read.
- `line_unread`: a reading-size line (≥ 30 px tall at 1080) on screen under its floor: 0.4 s for 1–2 words, otherwise ¾ of 0.5 s + 0.3 s a word (3 words 1.05 s, 6 words 1.73 s); the film's last line needs 2 s. Edges are re-measured to ~0.01 s. Captions-track text and `data-layout-ignore` are exempt.
- `line_unread`: a reading-size line (≥ 30 px tall at 1080) on screen under its floor: 0.4 s for 1–2 words, otherwise ¾ of 0.5 s + 0.3 s a word (3 words 1.05 s, 6 words 1.73 s); the film's last line needs 2 s. A line the next scene repeats in place is timed as one line. Edges are re-measured to ~0.01 s. Captions-track text and `data-layout-ignore` are exempt.
- `dead_stretch`: more than 3 s where the `keepsMoving` classifier sees nothing change. The final 3 s and any time a `data-hold` element is on screen are exempt; it stays quiet when `sweep_static` fires or a whole-composition `keepsMoving` assertion sets the limit.
- `text_below_floor`: text under 2.6% of the frame's short side (28 px on 1080) held 0.5 s or more, one finding per file listing every element.
- `first_frame_empty`: frame 0 paints nothing but the background (no text, image, video, canvas or svg), or an opaque element covers every other clip and the message names it; it is the thumbnail on social players.
Expand Down