Skip to content

Commit 17db454

Browse files
committed
fix(cli): fold canvas pixel hashes into the frozen-sweep fingerprint
1 parent dec7c23 commit 17db454

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,31 @@
895895
// actually moved anything and the whole audit run is unreliable. Deliberately
896896
// a single opaque string (not a structured array) since Node only ever needs
897897
// equality, not per-element diffing.
898+
// Pixel-only canvas motion (a 2D/WebGL canvas repainting without any element
899+
// moving) is invisible to a geometry+opacity fingerprint and false-positived
900+
// sweep_static (wild report: 4K WebGL comp needed a transparent moving DOM
901+
// sentinel to pass). Downsample each visible canvas to 8x8 and fold its
902+
// pixels into the fingerprint. Tainted/zero-sized/unreadable canvases hash
903+
// to a constant — no worse than today, never a new false NEGATIVE for
904+
// DOM-motion comps.
905+
function canvasPixelHash(canvas) {
906+
try {
907+
if (!canvas.width || !canvas.height) return "x";
908+
const off = document.createElement("canvas");
909+
off.width = 8;
910+
off.height = 8;
911+
const ctx = off.getContext("2d");
912+
if (!ctx) return "x";
913+
ctx.drawImage(canvas, 0, 0, 8, 8);
914+
const data = ctx.getImageData(0, 0, 8, 8).data;
915+
let hash = 0;
916+
for (let i = 0; i < data.length; i++) hash = (hash * 31 + data[i]) >>> 0;
917+
return String(hash);
918+
} catch {
919+
return "x";
920+
}
921+
}
922+
898923
window.__hyperframesLayoutGeometry = function collectLayoutGeometry() {
899924
const root =
900925
document.querySelector("[data-composition-id][data-width][data-height]") ||
@@ -903,12 +928,15 @@
903928
const elements = Array.from(root.querySelectorAll("*")).filter((element) =>
904929
isVisibleElement(element),
905930
);
906-
return elements
907-
.map((element) => {
908-
const rect = toRect(element.getBoundingClientRect());
909-
const opacity = round(opacityChain(element));
910-
return `${rect.left},${rect.top},${rect.width},${rect.height},${opacity}`;
911-
})
912-
.join("|");
931+
const parts = elements.map((element) => {
932+
const rect = toRect(element.getBoundingClientRect());
933+
const opacity = round(opacityChain(element));
934+
return `${rect.left},${rect.top},${rect.width},${rect.height},${opacity}`;
935+
});
936+
for (const canvas of root.querySelectorAll("canvas")) {
937+
if (!isVisibleElement(canvas)) continue;
938+
parts.push(`c:${canvasPixelHash(canvas)}`);
939+
}
940+
return parts.join("|");
913941
};
914942
})();

0 commit comments

Comments
 (0)