|
895 | 895 | // actually moved anything and the whole audit run is unreliable. Deliberately |
896 | 896 | // a single opaque string (not a structured array) since Node only ever needs |
897 | 897 | // 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 | + |
898 | 923 | window.__hyperframesLayoutGeometry = function collectLayoutGeometry() { |
899 | 924 | const root = |
900 | 925 | document.querySelector("[data-composition-id][data-width][data-height]") || |
|
903 | 928 | const elements = Array.from(root.querySelectorAll("*")).filter((element) => |
904 | 929 | isVisibleElement(element), |
905 | 930 | ); |
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("|"); |
913 | 941 | }; |
914 | 942 | })(); |
0 commit comments