Skip to content

Commit fbec4c6

Browse files
fix(cli): share one motion classifier between sweep guard and liveness
The frozen-sweep guard (sweep_static) and keepsMoving liveness (motion_frozen) each owned their own definition of "what counts as motion": the sweep fingerprint in layout-audit.browser.js read nine channels while motion-sample.browser.js compared box + opacity only. They meet in one decision in checkPipeline.ts, so a fixed-width attr() countdown was accepted by the sweep guard and still reported frozen by liveness. Move the classifier into motion-signature.browser.js, injected before both samplers, and make it the single owner: - Per-element channels (box, opacity, font-variation axes, clip-path, direct text, form-control state, ::before/::after content, media pixels) as a reader list so further channels (e.g. SVG dash) plug in. - Liveness consumes the same signature with 2px / 0.08 bucketing; the sweep guard consumes it exact. motion-sample throws at install if the shared script is missing. - Counter state is a composition-level channel over box-generating elements and root ancestors. display:none subtrees generate no boxes and are excluded, and only declarations naming a counter that some painted generated content (::before/::after/::marker on a non-ignored, paintable host) consumes are folded in, so a decoy hidden counter cannot make a frozen composition read as live. - clip-path is a channel, replacing the fingerprint's former reliance on the clipped-away visibility probe, so a wipe over a static box still counts. - data-layout-ignore layers are excluded from the signature but not from the per-selector `visible` bit reported for explicit motion assertions. - Root resolution for the "*" liveness scope now matches the sweep guard and the root element is part of its own signature. Tests: motion-signature.browser.test.ts (happy-dom, per-element fake computed style so ancestor handling comes from the classifier) and motion-signature.browser.chromium.test.ts (real Chromium via puppeteer-core; skips without a system browser) pin every branch: attr() substitution, display:none decoys, named-counter gating, ::marker, zero-box hosts, ancestor counters, textarea/indeterminate, root text, clip-path, ignore layers, and sweep/liveness agreement on the countdown fixture. Co-Authored-By: Miguel Ángel <[email protected]>
1 parent a329d21 commit fbec4c6

14 files changed

Lines changed: 1663 additions & 627 deletions

‎.fallowrc.jsonc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"packages/cli/src/commands/layout-audit.browser.js",
3636
"packages/cli/src/commands/contrast-audit.browser.js",
3737
"packages/cli/src/commands/motion-sample.browser.js",
38+
"packages/cli/src/commands/motion-signature.browser.js",
3839
// Worker entry points loaded dynamically by their *Pool.ts companions.
3940
"packages/producer/src/services/pngDecodeBlitWorker.ts",
4041
"packages/producer/src/services/shaderTransitionWorker.ts",

‎docs/packages/cli.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ HTML. Without a sidecar, nothing changes.
715715
| `staysInFrame(selector)` | Off-frame drift — once visible, the box never leaves the canvas (`motion_off_frame`) |
716716
| `keepsMoving(withinSelector?)` | A frozen shot — no fully static window longer than `maxStaticSec`, default 2s (`motion_frozen`) |
717717

718+
`keepsMoving` uses the same motion classifier as the frozen-sweep guard: box
719+
geometry, opacity, text and generated content, form-control state, painted CSS
720+
counters, clip-path, variable-font axes, and the pixels of visible
721+
canvas/video/img elements all count as motion — so a playing same-origin (or
722+
CORS-readable) background video keeps a scope live on its own. Elements under
723+
`data-layout-ignore` never count.
718724
`duration`, `keepsMoving.withinSelector`, and `keepsMoving.maxStaticSec` are
719725
optional. Findings use the same shape and envelope as layout findings and are
720726
errors by default, so a failed assertion fails the run. A selector that matches

‎packages/cli/scripts/build-copy.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ async function main() {
104104
cpSync(contrastAuditScript, join(DIST, "commands", "contrast-audit.browser.js"));
105105
}
106106

107+
const motionSignatureScript = join(CLI_ROOT, "src", "commands", "motion-signature.browser.js");
108+
if (existsSync(motionSignatureScript)) {
109+
cpSync(motionSignatureScript, join(DIST, "commands", "motion-signature.browser.js"));
110+
}
111+
107112
const motionSampleScript = join(CLI_ROOT, "src", "commands", "motion-sample.browser.js");
108113
if (existsSync(motionSampleScript)) {
109114
cpSync(motionSampleScript, join(DIST, "commands", "motion-sample.browser.js"));

‎packages/cli/src/commands/layout-audit.browser.js‎

Lines changed: 4 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,163 +1629,10 @@
16291629
return contentOverlapIssues(root, time);
16301630
};
16311631

1632-
// Frozen-sweep guard (#U10, checkPipeline.ts): a compact per-sample
1633-
// fingerprint of every visible element's box, opacity, and rendered text
1634-
// state, in DOM order. Node
1635-
// calls this once per seeked grid point and compares the strings across the
1636-
// whole run — if every sample produces the identical string, the seek never
1637-
// actually moved anything and the whole audit run is unreliable. Deliberately
1638-
// a single opaque string (not a structured array) since Node only ever needs
1639-
// equality, not per-element diffing.
1640-
// Pixel-only media motion (a 2D/WebGL canvas repainting or a playing video
1641-
// without any element moving) is invisible to a DOM-state fingerprint
1642-
// and false-positives sweep_static. Downsample each visible canvas/video to
1643-
// 8x8 and fold its pixels into the fingerprint. Tainted, zero-sized, or
1644-
// unreadable media hashes to a constant — no worse than DOM-state-only
1645-
// detection and never a new false negative for DOM-motion compositions.
1646-
// Media inside iframes is intentionally outside this fingerprint: it lives
1647-
// in a separate document, and cross-origin frames are inaccessible under SOP.
1648-
function mediaPixelHash(element) {
1649-
try {
1650-
const rect = element.getBoundingClientRect();
1651-
const sourceWidth = element.videoWidth || element.width || rect.width;
1652-
const sourceHeight = element.videoHeight || element.height || rect.height;
1653-
if (!sourceWidth || !sourceHeight) return "x";
1654-
const off = document.createElement("canvas");
1655-
off.width = 8;
1656-
off.height = 8;
1657-
const ctx = off.getContext("2d");
1658-
if (!ctx) return "x";
1659-
ctx.drawImage(element, 0, 0, 8, 8);
1660-
const data = ctx.getImageData(0, 0, 8, 8).data;
1661-
let hash = 0;
1662-
for (let i = 0; i < data.length; i++) hash = (hash * 31 + data[i]) >>> 0;
1663-
return String(hash);
1664-
} catch {
1665-
return "x";
1666-
}
1667-
}
1668-
1669-
function foldFingerprintField(hash, value) {
1670-
hash ^= value.length;
1671-
hash = Math.imul(hash, 16777619);
1672-
for (let i = 0; i < value.length; i++) {
1673-
hash ^= value.charCodeAt(i);
1674-
hash = Math.imul(hash, 16777619);
1675-
}
1676-
return hash;
1677-
}
1678-
1679-
function cssFingerprintValue(value) {
1680-
return value === "none" || value === "normal" ? "" : value || "";
1681-
}
1682-
1683-
function foldCounterState(hash, style) {
1684-
hash = foldFingerprintField(hash, cssFingerprintValue(style.counterReset));
1685-
hash = foldFingerprintField(hash, cssFingerprintValue(style.counterIncrement));
1686-
return foldFingerprintField(hash, cssFingerprintValue(style.counterSet));
1687-
}
1688-
1689-
function counterStateHash(style) {
1690-
const reset = cssFingerprintValue(style.counterReset);
1691-
const increment = cssFingerprintValue(style.counterIncrement);
1692-
const set = cssFingerprintValue(style.counterSet);
1693-
if (!reset && !increment && !set) return "";
1694-
let hash = 2166136261;
1695-
hash = foldCounterState(hash, style);
1696-
return (hash >>> 0).toString(36);
1697-
}
1698-
1699-
function foldLiveControlState(hash, element) {
1700-
if (element.tagName === "INPUT") {
1701-
hash = foldFingerprintField(hash, element.type || "");
1702-
hash = foldFingerprintField(hash, element.value || "");
1703-
hash = foldFingerprintField(hash, element.checked ? "1" : "0");
1704-
return foldFingerprintField(hash, element.indeterminate ? "1" : "0");
1705-
}
1706-
if (element.tagName === "TEXTAREA") {
1707-
return foldFingerprintField(hash, element.value || "");
1708-
}
1709-
if (element.tagName !== "SELECT") return foldFingerprintField(hash, "");
1710-
hash = foldFingerprintField(hash, String(element.selectedIndex));
1711-
hash = foldFingerprintField(hash, element.value || "");
1712-
for (let i = 0; i < element.options.length; i++) {
1713-
hash = foldFingerprintField(hash, element.options[i].selected ? "1" : "0");
1714-
}
1715-
return hash;
1716-
}
1717-
1718-
function textualStateHash(element, style) {
1719-
// Chromium resolves attr() here, so pseudo computed content is the
1720-
// platform-owned rendered value rather than a CSS expression to reparse.
1721-
const before = getComputedStyle(element, "::before");
1722-
const after = getComputedStyle(element, "::after");
1723-
// Visible descendants are fingerprinted separately; direct nodes prevent
1724-
// a hidden descendant's text mutation from masquerading as visible motion.
1725-
let directText = "";
1726-
for (const node of directTextNodes(element)) {
1727-
directText += node.textContent || "";
1728-
}
1729-
let hash = 2166136261;
1730-
hash = foldFingerprintField(hash, directText);
1731-
hash = foldLiveControlState(hash, element);
1732-
hash = foldFingerprintField(hash, cssFingerprintValue(before.content));
1733-
hash = foldFingerprintField(hash, cssFingerprintValue(after.content));
1734-
hash = foldCounterState(hash, style);
1735-
hash = foldCounterState(hash, before);
1736-
hash = foldCounterState(hash, after);
1737-
return (hash >>> 0).toString(36);
1738-
}
1739-
1740-
window.__hyperframesLayoutGeometry = function collectLayoutGeometry() {
1741-
const root =
1742-
document.querySelector("[data-composition-id][data-width][data-height]") ||
1743-
document.querySelector("[data-composition-id]") ||
1744-
document.body;
1745-
const allElements = [root, ...root.querySelectorAll("*")];
1746-
const elements = allElements.filter((element) => isVisibleElement(element));
1747-
const parts = elements.map((element) => {
1748-
const rect = toRect(element.getBoundingClientRect());
1749-
const opacity = round(opacityChain(element));
1750-
// Variable-font axis animation (font-variation-settings) is a real,
1751-
// visible motion channel that moves no geometry and no opacity, so a
1752-
// box+opacity+text fingerprint reads it as a frozen timeline. Worse in a
1753-
// DUPLEXED face (Recursive holds an identical advance width at every
1754-
// weight by design), where not even the line width shifts — the whole
1755-
// run then false-positives sweep_static. Fold the computed axis string
1756-
// in; it is "normal" for every element that does not use it, so this
1757-
// adds nothing to the fingerprint of an ordinary composition.
1758-
const style = getComputedStyle(element);
1759-
const axes = style.fontVariationSettings;
1760-
const textState = textualStateHash(element, style);
1761-
return `${rect.left},${rect.top},${rect.width},${rect.height},${opacity},${
1762-
axes && axes !== "normal" ? axes : ""
1763-
},${textState}`;
1764-
});
1765-
const visibleElements = new Set(elements);
1766-
for (let ancestor = root.parentElement; ancestor; ancestor = ancestor.parentElement) {
1767-
const state = counterStateHash(getComputedStyle(ancestor));
1768-
if (state) parts.push(`c:${state}`);
1769-
}
1770-
// Counter declarations can live on zero-box owners while a visible
1771-
// descendant's ::before/::after paints the resulting value.
1772-
for (const element of allElements) {
1773-
if (visibleElements.has(element)) continue;
1774-
const state = counterStateHash(getComputedStyle(element));
1775-
if (state) parts.push(`c:${state}`);
1776-
}
1777-
// img shares the same pixel-only-motion blind spot as canvas/video: an
1778-
// equal-size, equal-position opaque src/visibility swap moves no
1779-
// geometry and no opacity. mediaPixelHash already handles it generically
1780-
// (drawImage accepts any CanvasImageSource; width/height fall back to
1781-
// rect.width/height same as canvas/video), so only the element selector
1782-
// needed widening.
1783-
for (const media of root.querySelectorAll("canvas, video, img")) {
1784-
if (!isVisibleElement(media)) continue;
1785-
parts.push(`p:${mediaPixelHash(media)}`);
1786-
}
1787-
return parts.join("|");
1788-
};
1632+
// The frozen-sweep fingerprint (window.__hyperframesLayoutGeometry, #U10 in
1633+
// checkPipeline.ts) lives in motion-signature.browser.js, the single owner
1634+
// of "what counts as motion" shared with motion-sample.browser.js's
1635+
// liveness signature.
17891636

17901637
// Rotation-pivot sampling (rotation_pivot_drift). Per sample, report every
17911638
// rotatable candidate's bbox center, size, and current rotation angle. Node

0 commit comments

Comments
 (0)