// Sibling-CSS isolation probe: a full-frame opaque magenta rect, last child of the drawing, carries each candidate style. // Metric: pure-magenta pixel count (equal to control-none = no marker covered) and, in the canvas, the hit at each point centre. import { createRequire } from 'node:module' import { readFileSync, readdirSync } from 'node:fs' const require = createRequire(process.argv[2] + '/apps/app/package.json') const pw = require('@playwright/test') const DIR = process.argv[3] const doc = JSON.parse(readFileSync(process.argv[2] + '/supabase/seed/anatomical-sheets/equine/draft/document.json', 'utf8')) const points = doc.annotations.filter((a) => a.view_id === 'main' && a.geometry.type === 'circle').map((a) => [a.id, a.geometry.cx, a.geometry.cy]) const names = [...new Set(readdirSync(DIR).map((f) => f.split('.')[0]))].sort() const W = 1000, H = Math.round(1000 * 1629.4 / 2073.4) const LIB = `window.mag = (d) => { let n = 0; for (let i = 0; i < d.length; i += 4) if (d[i] === 255 && d[i+1] === 0 && d[i+2] === 255) n++; return n } window.pdf = async (svg) => { const root = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement; root.setAttribute('width', '${W}'); root.setAttribute('height', '${H}'); const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(root)], { type: 'image/svg+xml' })); const img = new Image(); img.width = ${W}; img.height = ${H}; img.src = url; await img.decode(); const c = document.createElement('canvas'); c.width = ${W}; c.height = ${H}; const x = c.getContext('2d'); x.fillStyle = '#fff'; x.fillRect(0, 0, ${W}, ${H}); x.drawImage(img, 0, 0, ${W}, ${H}); return window.mag(x.getImageData(0, 0, ${W}, ${H}).data) } window.png = async (b64) => { const img = new Image(); img.src = 'data:image/png;base64,' + b64; await img.decode(); const c = document.createElement('canvas'); c.width = img.width; c.height = img.height; const x = c.getContext('2d'); x.drawImage(img, 0, 0); return window.mag(x.getImageData(0, 0, c.width, c.height).data) }` for (const engine of process.argv[4].split(',')) { const browser = await pw[engine].launch() const work = await browser.newPage(); await work.setContent('
'); await work.addScriptTag({ content: LIB }) const shot = await browser.newPage({ viewport: { width: 1100, height: 900 } }) console.log(`== ${engine} ${browser.version()}`) for (const name of names) { const pdf = await work.evaluate((s) => window.pdf(s), readFileSync(`${DIR}/${name}.pdf.svg`, 'utf8')) const svg = readFileSync(`${DIR}/${name}.canvas.svg`, 'utf8').replace(/^