Files
faunosteo/.claude/audits/2026-10-30-v1-2-2-three-medium-tools/zz-junction.spec.ts

45 lines
2.6 KiB
TypeScript

// THROWAWAY (never committed): capture of each visible shape under three layer orders.
import { test } from '../support/browser'
test('junction options @phone', async ({ page }, info) => {
await page.goto('/e2e/harness/canvas.html?drawing=plain')
await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
for (const option of ['current', 'points-above-zones', 'visible-wins']) {
const out = await page.evaluate((option) => {
const svg = document.querySelector('[data-testid="anatomy-canvas"] svg') as SVGSVGElement
const layer = svg.lastElementChild as SVGGElement
const kids = Array.from(layer.children) as SVGGeometryElement[]
const hit = kids.filter((k) => k.getAttribute('fill') === 'transparent')
const twins = kids.filter((k) => k.getAttribute('pointer-events') === 'none')
const shapes = kids.filter((k) => !hit.includes(k) && !twins.includes(k))
if (option === 'points-above-zones') {
const points = kids.filter((k) => hit.includes(k) || twins.includes(k))
layer.replaceChildren(...shapes, ...points)
}
if (option === 'visible-wins') {
twins.forEach((t) => t.setAttribute('pointer-events', 'visibleFill'))
layer.replaceChildren(...hit, ...shapes, ...twins)
}
const ctm = svg.getScreenCTM()!
const who = (x: number, y: number) => { const p = new DOMPoint(x, y).matrixTransform(ctm); return document.elementFromPoint(p.x, p.y)?.closest('[data-anno-id]')?.getAttribute('data-anno-id') ?? '-' }
const rows: Record<string, string> = {}
for (const t of twins) {
const id = t.getAttribute('data-anno-id')!
const cx = +t.getAttribute('cx')!, cy = +t.getAttribute('cy')!, r = +t.getAttribute('r')!
let n = 0, own = 0
for (let dx = -r; dx <= r; dx += 2) for (let dy = -r; dy <= r; dy += 2) { if (Math.hypot(dx, dy) > r) continue; n++; if (who(cx + dx, cy + dy) === id) own++ }
if (own < n) rows[id] = `disc ${own}/${n}`
}
for (const z of shapes) {
const id = z.getAttribute('data-anno-id')!
const b = z.getBBox()
let n = 0, own = 0
for (let x = b.x; x <= b.x + b.width; x += 6) for (let y = b.y; y <= b.y + b.height; y += 6) { if (!z.isPointInFill(new DOMPoint(x, y))) continue; n++; if (who(x, y) === id) own++ }
if (own < n) rows[id] = `area ${own}/${n}`
}
return rows
}, option)
console.log(`JUNCTION ${info.project.name} ${option} ${JSON.stringify(out)}`)
await page.reload(); await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
}
})