diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index b816e22425..832d53e4f2 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -720,7 +720,11 @@ geometry, opacity, text and generated content, form-control state, painted CSS counters, clip-path, variable-font axes, and the pixels of visible canvas/video/img elements all count as motion — so a playing same-origin (or CORS-readable) background video keeps a scope live on its own. Elements under -`data-layout-ignore` never count. +`data-layout-ignore` inside the scope never count; the opt-out does not apply to +the scope element itself, since naming it in an assertion outranks it. Content +the browser does not paint (`display: none` subtrees, `visibility: hidden` +boxes, skipped `content-visibility` contents) never counts as motion either. + `duration`, `keepsMoving.withinSelector`, and `keepsMoving.maxStaticSec` are optional. Findings use the same shape and envelope as layout findings and are errors by default, so a failed assertion fails the run. A selector that matches diff --git a/packages/cli/src/commands/motion-sample.browser.js b/packages/cli/src/commands/motion-sample.browser.js index b136dad0f0..33bc9fdfd9 100644 --- a/packages/cli/src/commands/motion-sample.browser.js +++ b/packages/cli/src/commands/motion-sample.browser.js @@ -7,23 +7,19 @@ // Visibility, opacity, and the liveness signature all come from the shared // motion classifier so this sampler and the frozen-sweep guard can never // disagree on what counts as motion (see motion-signature.browser.js). + // Resolved at install, checked at call: addScriptTag resolves on load, so an + // install-time throw would only surface as a page error and an opaque + // "__hyperframesMotionSample is not a function" from the driver's evaluate. const shared = window.__hyperframesMotionSignature; - if (!shared) { - throw new Error("motion-signature.browser.js must be injected before motion-sample.browser.js"); - } - - function round(value) { - return Math.round(value * 100) / 100; - } function toRect(rect) { return { - left: round(rect.left), - top: round(rect.top), - right: round(rect.right), - bottom: round(rect.bottom), - width: round(rect.width), - height: round(rect.height), + left: shared.round(rect.left), + top: shared.round(rect.top), + right: shared.round(rect.right), + bottom: shared.round(rect.bottom), + width: shared.round(rect.width), + height: shared.round(rect.height), }; } @@ -31,7 +27,7 @@ const rect = element.getBoundingClientRect(); return { rect: toRect(rect), - opacity: round(shared.opacityChain(element)), + opacity: shared.round(shared.opacityChain(element)), visible: shared.isVisibleElement(element), }; } @@ -69,6 +65,11 @@ } window.__hyperframesMotionSample = function motionSample(options) { + if (!shared) { + throw new Error( + "motion-signature.browser.js must be injected before motion-sample.browser.js", + ); + } const { selectors = [], livenessScopes = [] } = options || {}; return { data: sampleSelectors(selectors), liveness: sampleLiveness(livenessScopes) }; }; diff --git a/packages/cli/src/commands/motion-sample.browser.test.ts b/packages/cli/src/commands/motion-sample.browser.test.ts index 0db96bbaaa..1349864946 100644 --- a/packages/cli/src/commands/motion-sample.browser.test.ts +++ b/packages/cli/src/commands/motion-sample.browser.test.ts @@ -77,9 +77,12 @@ describe("motion-sample.browser", () => { Reflect.deleteProperty(window, "__hyperframesLayoutGeometry"); }); - it("throws at install when the shared motion classifier is missing", () => { + it("installs without the shared motion classifier and names it on the first call", () => { + // Installing must not throw: addScriptTag resolves on load regardless, so + // the driver only ever sees the error from its evaluate call. // eslint-disable-next-line no-new-func - expect(() => new Function(script)()).toThrow(/motion-signature\.browser\.js/); + expect(() => new Function(script)()).not.toThrow(); + expect(() => sample({ livenessScopes: ["*"] })).toThrow(/motion-signature\.browser\.js/); }); it("samples a present, visible selector and returns null for an absent one", () => { diff --git a/packages/cli/src/commands/motion-signature.browser.chromium.test.ts b/packages/cli/src/commands/motion-signature.browser.chromium.test.ts index 7e93be463d..12d3f4354d 100644 --- a/packages/cli/src/commands/motion-signature.browser.chromium.test.ts +++ b/packages/cli/src/commands/motion-signature.browser.chromium.test.ts @@ -3,9 +3,15 @@ // (motion-signature.browser.test.ts) mocks getComputedStyle, so it asserts the // classifier's control flow against a fake; this suite asserts the same // branches against the platform — Blink's attr() substitution in computed -// pseudo content, unsubstituted counter(), display:none subtrees, clip-path, +// pseudo content, unsubstituted counter(), display:none and +// content-visibility:hidden subtrees, opt-outs on a measured scope, clip-path, // and form control state — using the exact scripts `hyperframes check` injects. -// Skipped when no Chrome/Chromium binary is available without downloading. +// Skipped when no Chrome/Chromium binary is available without downloading. On +// Windows the suite is opt-in (HYPERFRAMES_BROWSER_TESTS=1): in the shared +// Windows package test lane the launch of the runner's Chrome did not complete +// within the package hookTimeout (cause not established; no other suite in this +// package launches a browser), and the suite already runs on Linux CI, where +// the runner's Chrome is found as a system browser. import { existsSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -26,6 +32,12 @@ function resolveExecutable(): string | undefined { } const executablePath = resolveExecutable(); +const RUNS_CHROMIUM = + !!executablePath && + (process.platform !== "win32" || process.env.HYPERFRAMES_BROWSER_TESTS === "1"); +// The package hookTimeout is sized for cold module imports, not for launching +// a browser; give the launch its own ceiling. +const BROWSER_LAUNCH_TIMEOUT_MS = 120_000; interface Samples { sweep: string; @@ -52,7 +64,7 @@ function composition(css: string, body: string): string { `; } -describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => { +describe.skipIf(!RUNS_CHROMIUM)("motion-signature.browser in Chromium", () => { let browser: Browser; let page: Page; @@ -65,7 +77,7 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => { }); page = await browser.newPage(); await page.setViewport({ width: 640, height: 360 }); - }); + }, BROWSER_LAUNCH_TIMEOUT_MS); afterAll(async () => { await browser?.close(); @@ -77,11 +89,17 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => { await page.addScriptTag({ content: motionSampleScript }); } - async function sample(): Promise { - return page.evaluate(() => ({ - sweep: window.__hyperframesLayoutGeometry(), - liveness: window.__hyperframesMotionSample({ livenessScopes: ["*"] }).liveness["*"] ?? "", - })); + async function sample(scope = "*"): Promise { + return page.evaluate( + (livenessScope) => ({ + sweep: window.__hyperframesLayoutGeometry(), + liveness: + window.__hyperframesMotionSample({ livenessScopes: [livenessScope] }).liveness[ + livenessScope + ] ?? "", + }), + scope, + ); } async function mutate(script: string): Promise { @@ -381,4 +399,164 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => { expect(after).toEqual(before); }); + + // A keepsMoving scope names the element explicitly, so the layout-audit + // opt-out on the scope itself does not empty its signature (which the Node + // side would otherwise report as motion_selector_missing for an element that + // exists). Opt-outs INSIDE the scope still apply. + it("measures a keepsMoving scope that is itself data-layout-ignore, but not opted-out layers inside it", async () => { + await load( + composition( + "#scene { position: absolute; width: 300px; height: 200px; } #logo, #glow { position: absolute; width: 50px; height: 50px; background: #00f; }", + '
', + ), + ); + const before = await sample("#scene"); + expect(before.liveness).not.toBe(""); + await mutate('document.getElementById("glow").style.left = "100px"'); + const afterIgnoredMove = await sample("#scene"); + await mutate('document.getElementById("logo").style.left = "100px"'); + const afterMove = await sample("#scene"); + + expect(afterIgnoredMove.liveness).toBe(before.liveness); + expect(afterMove.liveness).not.toBe(before.liveness); + }); + + it("ignores text mutations inside content-visibility:hidden contents", async () => { + await load( + composition( + "#wrap { content-visibility: hidden; }", + '
10
10', + ), + ); + const before = await sample(); + await mutate('document.getElementById("skipped").textContent = "09"'); + const after = await sample(); + + expect(after).toEqual(before); + }); + + it("ignores a decoy counter owner inside content-visibility:hidden contents", async () => { + await load( + composition( + "#wrap { content-visibility: hidden; } #decoy { counter-reset: countdown 10; } #countdown::after { content: counter(countdown); }", + '
', + ), + ); + const before = await sample(); + await mutate('document.getElementById("decoy").style.counterReset = "countdown 9"'); + const after = await sample(); + + expect(after).toEqual(before); + }); + + it("ignores a decoy counter owner inside off-screen content-visibility:auto contents", async () => { + await load( + composition( + "#far { content-visibility: auto; position: absolute; top: 5000px; width: 10px; height: 10px; } #decoy { counter-reset: countdown 10; } #countdown::after { content: counter(countdown); }", + '
', + ), + ); + const before = await sample(); + await mutate('document.getElementById("decoy").style.counterReset = "countdown 9"'); + const after = await sample(); + + expect(after).toEqual(before); + }); + + it("ignores a repaint of a canvas whose contents are skipped by content-visibility:hidden", async () => { + await load( + composition( + "#c { content-visibility: hidden; width: 100px; height: 100px; }", + '', + ), + ); + const before = await sample(); + await mutate( + 'const ctx = document.getElementById("c").getContext("2d"); ctx.fillStyle = "#f00"; ctx.fillRect(0, 0, 100, 100);', + ); + const after = await sample(); + + expect(after).toEqual(before); + }); + + // content-visibility only skips contents where size containment applies; on + // a non-atomic inline host it is a no-op and everything inside still paints. + it("keeps signing text and pseudo content inside an inline content-visibility:hidden host", async () => { + await load( + composition( + "#host { content-visibility: hidden; } #host::after { content: attr(data-txt); }", + '10', + ), + ); + const start = await sample(); + await mutate('document.getElementById("kid").textContent = "09"'); + const afterText = await sample(); + await mutate('document.getElementById("host").setAttribute("data-txt", "09")'); + const afterPseudo = await sample(); + + expect(afterText.sweep).not.toBe(start.sweep); + expect(afterText.liveness).not.toBe(start.liveness); + expect(afterPseudo.sweep).not.toBe(afterText.sweep); + }); + + it("sees a checkbox toggle on a content-visibility:hidden control", async () => { + await load( + composition( + "#toggle { content-visibility: hidden; width: 24px; height: 24px; }", + '', + ), + ); + const before = await sample(); + await mutate('document.getElementById("toggle").checked = true'); + const after = await sample(); + + expect(after.sweep).not.toBe(before.sweep); + }); + + it("ignores a value change on a text input whose contents are skipped by content-visibility:hidden", async () => { + await load( + composition( + "#note { content-visibility: hidden; width: 120px; height: 40px; font: 24px monospace; }", + '', + ), + ); + const before = await sample(); + await mutate('document.getElementById("note").value = "09"'); + const after = await sample(); + + expect(after).toEqual(before); + }); + + it("sees a counter painted only by a display:contents host's pseudo-element", async () => { + await load( + composition( + "body { counter-reset: countdown 10; } #host { display: contents; } #host::after { content: counter(countdown); font: 32px/48px monospace; }", + '
', + ), + ); + const before = await sample(); + await mutate('document.body.style.counterReset = "countdown 9"'); + const after = await sample(); + + expect(after.sweep).not.toBe(before.sweep); + }); + + it("ignores a content-visibility:hidden host's own text and pseudo content but still sees its box move", async () => { + await load( + composition( + "#host { content-visibility: hidden; position: absolute; width: 80px; height: 48px; background: #f00; } #host::after { content: attr(data-txt); }", + '
10
', + ), + ); + const start = await sample(); + await mutate('document.getElementById("host").firstChild.textContent = "09"'); + await mutate('document.getElementById("host").setAttribute("data-txt", "09")'); + const afterContents = await sample(); + await mutate('document.getElementById("host").style.left = "100px"'); + const afterMove = await sample(); + + expect(afterContents).toEqual(start); + expect(afterMove.sweep).not.toBe(start.sweep); + }); }); diff --git a/packages/cli/src/commands/motion-signature.browser.js b/packages/cli/src/commands/motion-signature.browser.js index 9392a1f528..6ed11ec8fb 100644 --- a/packages/cli/src/commands/motion-signature.browser.js +++ b/packages/cli/src/commands/motion-signature.browser.js @@ -20,11 +20,15 @@ // whether the seek moved anything at all. // // Adding a channel (e.g. SVG stroke-dasharray/dashoffset): append one reader -// `(element, ctx) => string` to ELEMENT_CHANNELS. `ctx` carries the element's -// computed style, its ::before/::after styles, its inherited opacity, and the -// quantize flag. A reader returns a string that is equal between two samples -// iff that channel did not visibly change; return "" for elements the channel -// does not apply to so ordinary compositions gain no payload. +// `(element, ctx) => string` to BOX_CHANNELS (reads the element's own box, +// including a control's widget type and checked state) or CONTENT_CHANNELS (reads what the +// element's contents paint — text, pseudo content, control values, media +// pixels — which `content-visibility: hidden` skips). `ctx` +// carries the element's computed style, its ::before/::after styles, its +// inherited opacity, and the quantize flag. A reader returns a string that is +// equal between two samples iff that channel did not visibly change; return "" +// for elements the channel does not apply to so ordinary compositions gain no +// payload. // // Signatures are a single opaque string per sample (not a structured array): // Node only ever needs equality, never per-element diffing. Textual channels @@ -43,6 +47,36 @@ const COUNTER_FUNCTION = /counters?\(\s*([^\s,)]+)/g; const IMPLICIT_MARKER_CONTENT = "counter(list-item)"; const LIST_ITEM_DISPLAY = /\blist-item\b/; + // Whether an element sits inside skipped contents (content-visibility: + // hidden, or auto while off-screen) is not on its own computed style; only + // the platform knows. RENDERED_BOX asks "does this element have a rendered + // box" (false for display:none, display:contents, and skipped contents); + // PAINTED adds the opacity/visibility properties and is the option set + // layout-audit.browser.js isVisibleElement uses on its opacity-floor path. + // happy-dom has no checkVisibility, so both callers keep a computed-style + // fallback. + const RENDERED_BOX_OPTIONS = { contentVisibilityAuto: true }; + const PAINTED_OPTIONS = { + opacityProperty: true, + visibilityProperty: true, + contentVisibilityAuto: true, + }; + // Stand-in for the ::before/::after of an element whose contents are skipped: + // no pseudo box exists, so nothing it declares (content, counter-*) paints. + const NO_BOX = Object.freeze({ display: "none" }); + const SKIPPED_PSEUDO = Object.freeze({ before: NO_BOX, after: NO_BOX }); + // content-visibility only skips contents where size containment applies + // (css-contain-2): not on non-atomic inline boxes, display:contents, table + // boxes and internal table boxes (a caption is neither), or the inline ruby + // container and internal ruby boxes. Such a host paints everything. Replaced + // elements (MEDIA_TAGS) are atomic even at display:inline. + const NOT_CONTAINABLE_DISPLAY = + /^(inline( list-item)?|contents|table|inline-table|table-(?!caption$)[a-z-]+|ruby[a-z-]*)$/; + + function skipsContents(element, style) { + if (style.contentVisibility !== "hidden") return false; + return MEDIA_TAGS.has(element.tagName) || !NOT_CONTAINABLE_DISPLAY.test(style.display); + } function round(value) { return Math.round(value * 100) / 100; @@ -71,16 +105,26 @@ ); } - // Same visibility floor as layout-audit.browser.js isVisibleElement's default. - // The author opt-out (data-layout-ignore / data-layout-check=ignore) is NOT - // applied here: motion-sample reports this bit for explicitly asserted - // selectors, and an assertion naming an element outranks a layout-audit - // opt-out. compositionSignature applies the opt-out itself (see there). - // clip-path is not probed either; it is a channel, so a clip-path wipe over a - // static box counts as motion directly. + // Visibility floor: checkVisibility (as layout-audit.browser.js + // isVisibleElement's opacity-floor path; its default path skips it and so + // cannot see skipped contents), then display/visibility, then inherited + // opacity, then a non-empty box. Kept local rather than shared because + // layout-audit is also installed and tested on its own; this module owns the + // decision for both motion samplers. The author opt-out (data-layout-ignore / + // data-layout-check=ignore) is NOT applied here: motion-sample reports this + // bit for explicitly asserted selectors, and an assertion naming an element + // outranks a layout-audit opt-out. compositionSignature applies the opt-out + // itself (see there). clip-path is not probed either; it is a channel, so a + // clip-path wipe over a static box counts as motion directly. // fallow-ignore-next-line complexity function isVisibleElement(element, style, opacity) { if (IGNORE_TAGS.has(element.tagName)) return false; + if ( + typeof element.checkVisibility === "function" && + !element.checkVisibility(PAINTED_OPTIONS) + ) { + return false; + } if (isHiddenStyle(style || getComputedStyle(element))) return false; if ((opacity === undefined ? opacityChain(element) : opacity) < 0.2) return false; const rect = element.getBoundingClientRect(); @@ -156,33 +200,32 @@ return value ? "1" : "0"; } - function inputState(element) { - return [ - element.type || "", - element.value || "", - flag(element.checked), - flag(element.indeterminate), - ]; - } - function selectState(element) { const fields = [String(element.selectedIndex), element.value || ""]; for (const option of element.options) fields.push(flag(option.selected)); return fields; } - const CONTROL_STATE = { - INPUT: inputState, + // A control's value is painted by its inner (shadow) contents, which + // content-visibility: hidden skips; the widget itself (its type, a + // checkbox/radio glyph) is theme paint of the control's own box and still + // shows. Hence two channels. + const CONTROL_VALUE = { + INPUT: (element) => [element.value || ""], TEXTAREA: (element) => [element.value || ""], SELECT: selectState, }; - // Form controls paint their value/checked state without changing the box. - function controlChannel(element) { - const read = CONTROL_STATE[element.tagName]; + function controlValueChannel(element) { + const read = CONTROL_VALUE[element.tagName]; return read ? hashFields(read(element)) : ""; } + function controlWidgetChannel(element) { + if (element.tagName !== "INPUT") return ""; + return hashFields([element.type || "", flag(element.checked), flag(element.indeterminate)]); + } + // Chromium substitutes attr() in computed pseudo content, so this is the // platform-owned rendered string rather than a CSS expression to reparse. // counter() is NOT substituted — that is what the counter channel is for. @@ -223,16 +266,24 @@ } } - const ELEMENT_CHANNELS = [ + // The element's own box still paints when its contents are skipped + // (content-visibility: hidden) — including a checkbox's check glyph; its + // text, pseudo boxes, control value, and replaced content (a canvas/video/img's + // pixels) do not. + const BOX_CHANNELS = [ boxChannel, opacityChannel, fontAxesChannel, clipPathChannel, + controlWidgetChannel, + ]; + const CONTENT_CHANNELS = [ textChannel, - controlChannel, + controlValueChannel, generatedContentChannel, mediaPixelChannel, ]; + const ELEMENT_CHANNELS = [...BOX_CHANNELS, ...CONTENT_CHANNELS]; // --- Composition-level counter channel ------------------------------------ // @@ -252,21 +303,33 @@ // own absolutely-positioned pseudo-elements can paint.
    /
  1. are not surfaced in computed counter-* and stay invisible here. - // Generated content of one box owner that reaches the screen: the host is - // not under an author opt-out, has a paintable inherited opacity, and the - // pseudo box itself is not hidden. A list-item box also paints its ::marker - // (counter(list-item) when the marker content is `normal`). + // Generated content of one box owner that reaches the screen: the host has + // a paintable inherited opacity and paints its contents, and the pseudo box + // itself is not hidden. A list-item box also paints its ::marker + // (counter(list-item) when the marker content is `normal`). The caller has + // already excluded opted-out hosts and hosts whose contents are skipped. function markerContent(element, style) { if (isHiddenStyle(style) || !LIST_ITEM_DISPLAY.test(style.display)) return ""; return cssValue(getComputedStyle(element, "::marker").content) || IMPLICIT_MARKER_CONTENT; } function paintedContent(element, style, pseudo, opacity) { - if (opacity < 0.2 || element.closest(IGNORE_SELECTOR)) return []; + if (opacity < 0.2) return []; const boxes = [pseudo.before, pseudo.after].filter((box) => !isHiddenStyle(box)); return [...boxes.map((box) => cssValue(box.content)), markerContent(element, style)]; } + // The author opt-out applies to elements INSIDE the measured root, never to + // the root itself or its ancestors: a keepsMoving scope (or the composition + // root) is explicitly asserted, and an assertion naming an element outranks + // a layout-audit opt-out — see isVisibleElement. + function isOptedOut(element, root) { + for (let current = element; current && current !== root; current = current.parentElement) { + if (current.matches(IGNORE_SELECTOR)) return true; + } + return false; + } + function consumedCounterNames(owners) { const names = new Set(); for (const owner of owners) { @@ -312,34 +375,62 @@ // whose only textual motion is a direct text node of the root still moves) // that a viewer could see change between two seeks. `options.quantize` // selects liveness bucketing (see header). Elements under an author opt-out - // (data-layout-ignore / data-layout-check=ignore) — typically a decorative - // layer that may animate off the seeked timeline — are neither signed nor - // allowed to consume counters: they must not prove that the timeline - // advanced. They remain counter owners, since their boxes still propagate. + // inside the root (data-layout-ignore / data-layout-check=ignore) — typically + // a decorative layer that may animate off the seeked timeline — are neither + // signed nor allowed to consume counters: they must not prove that the + // timeline advanced. They remain counter owners, since their boxes still + // propagate. The root itself is always measured (see isOptedOut). // fallow-ignore-next-line complexity function compositionSignature(root, options) { if (!root) return ""; const quantize = !!(options && options.quantize); const parts = []; const boxOwners = []; - const hiddenSubtree = new Set(); + // Unrendered elements (display:none subtrees, skipped contents) paint + // nothing and cannot feed a painted counter(). The platform decides where it + // can; the fallback is display:none and content-visibility:hidden hosts, + // propagated to descendants. display:contents has no box of its own but its + // pseudo-elements and children render, so it stays an owner. + const unrenderedBelow = new Set(); for (const element of [root, ...root.querySelectorAll("*")]) { if (IGNORE_TAGS.has(element.tagName)) continue; const style = getComputedStyle(element); - if (style.display === "none" || hiddenSubtree.has(element.parentElement)) { - hiddenSubtree.add(element); + const platformDecides = typeof element.checkVisibility === "function"; + const noBox = platformDecides + ? !element.checkVisibility(RENDERED_BOX_OPTIONS) + : style.display === "none"; + if (unrenderedBelow.has(element.parentElement) || (noBox && style.display !== "contents")) { + unrenderedBelow.add(element); continue; } - const pseudo = { - before: getComputedStyle(element, "::before"), - after: getComputedStyle(element, "::after"), - }; + // A host that skips its contents paints its box but none of its contents. + // Its counter-* declarations stay in: in Chromium a skipped host's + // counter-increment / counter-set still reach a sibling's painted + // counter() (counter-reset does not; keeping it is an over-count accepted + // for a guard). An `auto` host that is currently off-screen skips its + // contents too but is not detected here; its descendants are pruned by + // the platform check above, only its own direct text / pseudo content + // would still be signed. + const skipped = skipsContents(element, style); + if (skipped && !platformDecides) unrenderedBelow.add(element); + const pseudo = skipped + ? SKIPPED_PSEUDO + : { + before: getComputedStyle(element, "::before"), + after: getComputedStyle(element, "::after"), + }; const opacity = opacityChain(element); - boxOwners.push({ style, pseudo, painted: paintedContent(element, style, pseudo, opacity) }); - if (element.closest(IGNORE_SELECTOR)) continue; - if (!isVisibleElement(element, style, opacity)) continue; + const optedOut = isOptedOut(element, root); + const paintsContent = !optedOut && !skipped; + boxOwners.push({ + style, + pseudo, + painted: paintsContent ? paintedContent(element, style, pseudo, opacity) : [], + }); + if (optedOut || !isVisibleElement(element, style, opacity)) continue; const ctx = { style, pseudo, opacity, quantize }; - parts.push(ELEMENT_CHANNELS.map((channel) => channel(element, ctx)).join(",")); + const channels = skipped ? BOX_CHANNELS : ELEMENT_CHANNELS; + parts.push(channels.map((channel) => channel(element, ctx)).join(",")); } parts.push(...counterParts(root, boxOwners)); return parts.join("|"); @@ -349,6 +440,7 @@ compositionRoot, isVisibleElement, opacityChain, + round, compositionSignature, }; diff --git a/packages/cli/src/commands/motion-signature.browser.test.ts b/packages/cli/src/commands/motion-signature.browser.test.ts index 2bb57675b9..7528f094f7 100644 --- a/packages/cli/src/commands/motion-signature.browser.test.ts +++ b/packages/cli/src/commands/motion-signature.browser.test.ts @@ -306,6 +306,36 @@ describe("motion-signature.browser media and geometry channels", () => { expect(collect()).toBe(before); }); + it("measures a root that is itself data-layout-ignore while still excluding opted-out layers inside it", () => { + document.body.innerHTML = ` +
    +
    + +
    +
    +
    + `; + let logoLeft = 40; + let glowLeft = 40; + installFixture({ rects: { root: ROOT, scene: { left: 0, top: 0, width: 300, height: 200 } } }); + vi.spyOn(document.getElementById("logo")!, "getBoundingClientRect").mockImplementation(() => + rect({ left: logoLeft, top: 40, width: 50, height: 50 }), + ); + vi.spyOn(document.getElementById("glow")!, "getBoundingClientRect").mockImplementation(() => + rect({ left: glowLeft, top: 40, width: 50, height: 50 }), + ); + installScript(); + const { compositionSignature } = signatureWindow().__hyperframesMotionSignature; + const scene = document.getElementById("scene")!; + + const before = compositionSignature(scene); + expect(before).not.toBe(""); + glowLeft = 200; + expect(compositionSignature(scene)).toBe(before); + logoLeft = 200; + expect(compositionSignature(scene)).not.toBe(before); + }); + it("buckets sub-threshold moves out of the quantized liveness signature only", () => { document.body.innerHTML = `