Skip to content
Merged
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
1 change: 1 addition & 0 deletions .fallowrc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"packages/cli/src/commands/contrast-audit.browser.js",
"packages/cli/src/commands/motion-sample.browser.js",
"packages/cli/src/commands/motion-signature.browser.js",
"packages/cli/src/commands/blank-span.browser.js",
// Worker entry points loaded dynamically by their *Pool.ts companions.
"packages/producer/src/services/pngDecodeBlitWorker.ts",
"packages/producer/src/services/shaderTransitionWorker.ts",
Expand Down
8 changes: 7 additions & 1 deletion docs/packages/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ cover every finding from the full check.
| `--budget <ms\|90s\|8m>` | Stop the whole check this long after it starts (at least 30s) and report what it found, with `check_budget_reached` naming the phase it was in. For hosts with their own time limit. |
| `--no-cache` | Run the check even when the project files, flags, CLI and browser are unchanged since the last pass. Without it, an unchanged project returns that pass in about a second, marked as cached; remote scripts and assets are not fetched again for that. A failure is never cached, and a project with `node_modules` or a linked directory is never replayed. |
| `--no-contrast` | Skip the WCAG pass while iterating |
| `--no-craft` | Skip the craft pass (dead stretches, unread lines, silent film), the longest part of a full check. The report marks it skipped. Use it for a render preflight; keep it on for the full check before a release. |
| `--no-craft` | Skip the craft pass (dead stretches, blank stretches, unread lines, silent film), the longest part of a full check. The report marks it skipped. Use it for a render preflight; keep it on for the full check before a release. |
| `--strict` | Exit non-zero on warnings too (default: errors only) |
| `--caption-zone "<x0=..;y0=..;x1=..;y1=..>"` | Opt-in band gate. Flags a text element's DOM box that overlaps the fractional band. Optional `severity` and `seek`. |
| `--safe-zone <tiktok\|reels\|shorts\|standard\|off>` | Warn when text, captions included, leaves a safe area: a platform's on 9:16 compositions (default: all three), or `standard` title-safe margins (10% from each edge) on any frame. Never fails `--strict` |
Expand Down Expand Up @@ -1577,12 +1577,18 @@ edges re-measured to about 0.01 s, and skipped for a `--range` check.
| `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. |
| `film_silent` | A film longer than 15 s has no unmuted `<audio>` and no `<video>` with sound. |
| `blank_span` | Nothing is visible for 0.5 s or more between two hard cuts: content at full opacity just before and after, and every sample in between renders only the stage colour with nothing under the root rendered, even off the canvas. |

Captions-track text (`data-track-kind="captions"`) and `data-layout-ignore`
text are exempt from the text rules. `dead_stretch` never counts the film's
last 3 s (a held end card) or time when an element marked `data-hold` is on
screen, and it stays quiet when `sweep_static` already reports the sweep or a
whole-composition `keepsMoving` assertion sets its own limit.
`blank_span` never counts a blank that opens or ends the film, one beside a fade
(content below full opacity an 8 fps step outside it), a full-bleed card or cover
(any rendered background), content moved off the canvas, or a stage with no opaque
background colour. Mark a deliberate blank between two cuts with
`data-layout-allow-blank` on any element.

#### Audio findings

Expand Down
5 changes: 5 additions & 0 deletions packages/cli/scripts/build-copy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ async function main() {
cpSync(motionSampleScript, join(DIST, "commands", "motion-sample.browser.js"));
}

const blankSpanScript = join(CLI_ROOT, "src", "commands", "blank-span.browser.js");
if (existsSync(blankSpanScript)) {
cpSync(blankSpanScript, join(DIST, "commands", "blank-span.browser.js"));
}

// Player bundles for the standalone browser player used by `present` and
// `play`. resolvePlayerPath/resolveSlideshowPath look for these alongside the
// built CLI (dist/<name>.global.js), so they must ship in the package — the
Expand Down
71 changes: 71 additions & 0 deletions packages/cli/src/commands/blank-span.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// blank_span's page half (utils/blankSpan.ts): does a frame show only the bare stage, by motion-signature's framesDiffer.
(function () {
const CONTENT_TAGS = new Set(["IMG", "VIDEO", "CANVAS", "SVG", "IFRAME", "OBJECT", "EMBED"]);
const RENDERED_OPTIONS = { opacityProperty: true, visibilityProperty: true };
const PNG_PREFIX = "data:image/png;base64,";

// An `rgb()` or `rgba()` colour's alpha; null for any other notation, which is never read as transparent.
function alphaOf(color) {
const match = /^rgba?\(([^)]*)\)$/.exec(color);
if (!match) return null;
const parts = match[1].split(/[\s,/]+/).filter(Boolean);
return parts.length === 4 ? Number.parseFloat(parts[3]) : 1;
}

// The colour behind everything: the first background colour at or above the root that is not transparent.
function stageColor(root) {
for (let element = root; element; element = element.parentElement) {
const color = getComputedStyle(element).backgroundColor;
if (alphaOf(color) !== 0) return color;
}
return null;
}

function hasPseudoContent(element) {
return ["::before", "::after"].some((pseudo) => {
const content = getComputedStyle(element, pseudo).content;
return content !== "none" && content !== "normal";
});
}

function hasOwnText(element) {
return Array.from(element.childNodes).some(
(node) => node.nodeType === Node.TEXT_NODE && (node.textContent || "").trim() !== "",
);
}

// fallow-ignore-next-line complexity
function paintsSomething(element) {
if (CONTENT_TAGS.has(element.tagName.toUpperCase())) return true;
const style = getComputedStyle(element);
if (style.backgroundImage !== "none" || alphaOf(style.backgroundColor) !== 0) return true;
return hasOwnText(element) || hasPseudoContent(element);
}

// Off the canvas, clipped, filtered or covered, a rendered element still means the stage is in use.
function rendersAnything(root) {
return Array.from(root.querySelectorAll("*")).some(
(element) => element.checkVisibility(RENDERED_OPTIONS) && paintsSomething(element),
);
}

async function stageFrame(color, png) {
const image = new Image();
image.src = PNG_PREFIX + png;
await image.decode();
const canvas = document.createElement("canvas");
canvas.width = image.naturalWidth;
canvas.height = image.naturalHeight;
const context = canvas.getContext("2d");
context.fillStyle = color;
context.fillRect(0, 0, canvas.width, canvas.height);
return canvas.toDataURL("image/png").slice(PNG_PREFIX.length);
}

window.__hyperframesStageIsEmpty = async function stageIsEmpty(png) {
const root = window.__hyperframesMotionSignature.compositionRoot();
const color = stageColor(root);
if (color === null || rendersAnything(root)) return false;
return !(await window.__hyperframesFramesDiffer(await stageFrame(color, png), png));
};
})();
3 changes: 2 additions & 1 deletion packages/cli/src/commands/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,7 @@ describe("check pipeline", () => {
: [],
held: false,
painted: time > 0,
presence: time > 0 ? 1 : 0,
signature: time >= 7.5 && time <= 12.5 ? "still" : `moving-${time}`,
};
}
Expand All @@ -3628,7 +3629,7 @@ describe("check pipeline", () => {
return fakeDriver({
getDuration: vi.fn(async () => 20),
collectCraftFrame: vi.fn(async (time: number) => craftFrame(time)),
collectCraftFilm: vi.fn(async () => ({ soundSources: 0 })),
collectCraftFilm: vi.fn(async () => ({ soundSources: 0, blankAllowed: false })),
...overrides,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const CHECK_COMMAND_ARGS = {
craft: {
type: "boolean",
description:
"Run the craft pass (dead stretches, unread lines, silent films; enabled by default). --no-craft skips it, e.g. for a render preflight",
"Run the craft pass (dead stretches, blank stretches, unread lines, silent films; enabled by default). --no-craft skips it, e.g. for a render preflight",
default: true,
},
strict: {
Expand Down
29 changes: 18 additions & 11 deletions packages/cli/src/commands/layout-audit.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3247,24 +3247,29 @@
});
}

function isPaintedBox(element, rootRect) {
function boxOpacity(element, rootRect) {
if (typeof element.checkVisibility === "function" && !element.checkVisibility(PAINT_OPTIONS)) {
return false;
return 0;
}
const style = getComputedStyle(element);
if (style.display === "none" || style.visibility === "hidden") return false;
if (opacityChain(element) < CRAFT_PAINTED_OPACITY) return false;
if (style.display === "none" || style.visibility === "hidden") return 0;
const rect = element.getBoundingClientRect();
return rect.width >= 4 && rect.height >= 4 && intersectsRect(rect, rootRect);
if (rect.width < 4 || rect.height < 4 || !intersectsRect(rect, rootRect)) return 0;
return opacityChain(element);
}

function isPaintedBox(element, rootRect) {
return boxOpacity(element, rootRect) >= CRAFT_PAINTED_OPACITY;
}

function paintsContent(root, rootRect, parts) {
if (parts.some((part) => part.opacity >= CRAFT_PAINTED_OPACITY)) return true;
// Opacity of the most opaque text or media on screen; content paints from CRAFT_PAINTED_OPACITY up.
function contentPresence(root, rootRect, parts) {
let presence = Math.max(0, ...parts.map((part) => part.opacity));
for (const element of Array.from(root.querySelectorAll("img, video, canvas, svg"))) {
if (element.parentElement?.closest("svg")) continue;
if (isPaintedBox(element, rootRect)) return true;
presence = Math.max(presence, boxOpacity(element, rootRect));
}
return false;
return presence;
}

window.__hyperframesCraftSample = function collectCraftSample(options) {
Expand All @@ -3279,10 +3284,12 @@
element.hasAttribute("data-hold"),
);
const shared = window.__hyperframesMotionSignature;
const presence = contentPresence(root, rootRect, parts);
return {
parts,
held: holds.some((element) => isPaintedBox(element, rootRect)),
painted: paintsContent(root, rootRect, parts),
painted: presence >= CRAFT_PAINTED_OPACITY,
presence,
coveredBy: cover ? cover.selector : null,
signature: shared
? shared.compositionSignature(shared.compositionRoot(), { quantize: true })
Expand All @@ -3301,7 +3308,7 @@
media.tagName.toUpperCase() === "AUDIO" || declared === null || declared === "true";
if (audible) soundSources += 1;
}
return { soundSources };
return { soundSources, blankAllowed: !!document.querySelector("[data-layout-allow-blank]") };
};

// The frozen-sweep fingerprint (window.__hyperframesLayoutGeometry, #U10 in
Expand Down
174 changes: 174 additions & 0 deletions packages/cli/src/utils/blankSpan.chromium.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Real-Chromium pins for blank_span: an empty stage between two hard cuts warns; deliberate blanks stay quiet.
import { existsSync } from "node:fs";
import type { Browser } from "puppeteer-core";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { findSystemBrowser } from "../browser/manager.js";
import { createPageDriver } from "./checkBrowser.js";
import { DEFAULT_CHECK_OPTIONS, runAuditGrid } from "./checkPipeline.js";
import type { CraftFinding } from "./checkTypes.js";

function resolveExecutable(): string | undefined {
for (const name of ["HYPERFRAMES_BROWSER_PATH", "PUPPETEER_EXECUTABLE_PATH"]) {
const candidate = process.env[name];
if (candidate && existsSync(candidate)) return candidate;
}
return findSystemBrowser()?.executablePath;
}

const executablePath = resolveExecutable();
const RUNS_CHROMIUM =
!!executablePath &&
(process.platform !== "win32" || process.env.HYPERFRAMES_BROWSER_TESTS === "1");
const BROWSER_LAUNCH_TIMEOUT_MS = 120_000;

const STAGE =
"html, body { margin: 0; width: 640px; height: 360px; overflow: hidden; background: #0a0a0a; }";
const TITLE =
"position: absolute; left: 80px; top: 140px; margin: 0; color: #fff; font: 600 48px sans-serif";

// A 6 s film whose state at each seek is what `draw(t)` sets; `window.__hf` is the seek target check drives.
function film(body: string, draw: string, { stage = STAGE, rootAttributes = "" } = {}): string {
return `<!doctype html><html><head><style>${stage}</style></head><body>
<div id="root" data-composition-id="main" data-duration="6" data-width="640" data-height="360" ${rootAttributes}>
<h1 id="a" style="${TITLE}">Before</h1>
<h1 id="b" style="${TITLE}">After</h1>
${body}
</div>
<script>
const show = (id, on) => { const el = document.getElementById(id); if (el) el.style.display = on ? "" : "none"; };
const fade = (id, opacity) => { document.getElementById(id).style.opacity = String(Math.max(0, Math.min(1, opacity))); };
const draw = (t) => { ${draw} };
window.__hf = { duration: 6, seek: draw };
draw(0);
</script>
</body></html>`;
}

// Title A until `from`, title B from `to`: a hard cut out and a hard cut in.
const CUTS = (from: number, to: number) => `show("a", t < ${from}); show("b", t >= ${to});`;

describe.skipIf(!RUNS_CHROMIUM)("blank_span in Chromium", () => {
let browser: Browser;

beforeAll(async () => {
const puppeteer = await import("puppeteer-core");
browser = await puppeteer.default.launch({
headless: true,
executablePath,
args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"],
});
}, BROWSER_LAUNCH_TIMEOUT_MS);

afterAll(async () => {
await browser?.close();
});

async function blankSpans(html: string): Promise<CraftFinding[]> {
const page = await browser.newPage();
try {
await page.setViewport({ width: 640, height: 360 });
await page.setContent(html);
const result = await runAuditGrid(
createPageDriver(page),
{ ...DEFAULT_CHECK_OPTIONS, contrast: false },
{ kind: "none" },
);
return result.craft.findings.filter((finding) => finding.code === "blank_span");
} finally {
await page.close();
}
}

it("warns on an empty stage between two hard cuts, with its time range", async () => {
const [span, ...rest] = await blankSpans(film("", CUTS(2, 3.5)));

expect(rest).toEqual([]);
expect(span?.severity).toBe("warning");
expect(span?.timeRange?.[0]).toBeCloseTo(2, 2);
expect(span?.timeRange?.[1]).toBeCloseTo(3.375, 2);
expect(span?.message).toContain("Nothing is visible from 2.00 s to 3.38 s");
});

it.each([
["a blank shorter than 0.5 s", film("", CUTS(2, 2.375))],
["a fade through black", film("", `fade("a", (2 - t) / 0.5); fade("b", (t - 3) / 0.5);`)],
["a fade out and a hard cut in", film("", `fade("a", (2 - t) / 0.5); show("b", t >= 3.5);`)],
["a hard cut out and a fade in", film("", `show("a", t < 2); fade("b", (t - 3) / 0.5);`)],
[
"a blank opening and end padding",
film("", `show("a", t >= 1 && t < 3); show("b", t >= 3 && t < 4.5);`),
],
[
"a solid-colour card with text",
film(
`<div id="card" style="position: absolute; inset: 0; background: #e11d48">
<h2 style="${TITLE}">Chapter two</h2></div>`,
`${CUTS(2, 3.5)} show("card", t >= 2 && t < 3.5);`,
),
],
[
"a solid-colour card without text",
film(
`<div id="card" style="position: absolute; inset: 0; background: #e11d48"></div>`,
`${CUTS(2, 3.5)} show("card", t >= 2 && t < 3.5);`,
),
],
[
"a black cover held over the cut",
film(
`<div id="cover" style="position: absolute; inset: 0; background: #0a0a0a"></div>`,
`${CUTS(2, 3.5)} show("cover", t >= 2 && t < 3.5);`,
),
],
[
"a title slid off the canvas and back",
film(
"",
`show("b", false); document.getElementById("a").style.transform = t >= 2 && t < 3.5 ? "translateX(900px)" : "";`,
),
],
[
"a pseudo-element title slid off the canvas and back",
film(
`<style>#mark::before { content: "Mark"; color: #fff; font: 600 48px sans-serif; }</style>
<div id="mark" style="position: absolute; left: 80px; top: 60px"></div>`,
`${CUTS(2, 3.5)} document.getElementById("mark").style.transform = t >= 2 && t < 3.5 ? "translateX(900px)" : "";`,
),
],
[
"an image that never loaded",
film(
`<img id="photo" src="http://127.0.0.1:9/never.png" />`,
`${CUTS(2, 3.5)} show("photo", t >= 2 && t < 3.5);`,
),
],
[
"a drawing slid off the canvas and back",
film(
`<canvas id="drawing" width="200" height="200" style="position: absolute; left: 80px; top: 80px"></canvas>`,
`${CUTS(2, 3.5)} document.getElementById("drawing").style.transform = t >= 2 && t < 3.5 ? "translateX(900px)" : "";`,
),
],
[
"a full-bleed canvas scene",
film(
`<canvas id="scene" width="640" height="360" style="position: absolute; inset: 0"></canvas>`,
`${CUTS(2, 3.5)} show("scene", t >= 2 && t < 3.5);`,
),
],
[
"paint outside the composition root",
film("", CUTS(2, 3.5)).replace(
"<script>",
`<div id="outside" style="position: fixed; left: 0; top: 0; width: 80px; height: 80px; background: #fff"></div><script>`,
),
],
["a film with no opaque stage", film("", CUTS(2, 3.5), { stage: "html, body { margin: 0; }" })],
[
"a blank marked deliberate",
film("", CUTS(2, 3.5), { rootAttributes: "data-layout-allow-blank" }),
],
])("stays quiet on %s", async (_, html) => {
expect(await blankSpans(html)).toEqual([]);
});
});
Loading
Loading