fix(anatomy): V1-2.2 the visible wins on the editor canvas

Owner decision 2026-11-01. The canvas paints and hits every point hitbox,
then every zone and trigger, then every visible twin, which captures on
what it paints; a junction's disc is no longer taken by the zone drawn
after it. The PDF view keeps the document order and its bytes. Click
spec: the five fixme run unmarked, six projects incl. a 320 px phone.
This commit is contained in:
bchanot committed 2026-11-01 00:56:11 +01:00
1 parent e67715025c
commit 9c606aa567
13 files changed
+504 -64

No files matched your search

+28 -2
View File
@@ -152,7 +152,8 @@ export function withDeclaredHitboxes(layer: unknown): unknown {
* Owner brief 2026-10-30 (V1-2.2, three MEDIUM): the composition root is the engine's. Applied
* to a frozen canvas tree (a deep copy): the root keeps its namespaces and `viewBox`; its other
* attributes and every child before the layer go into a `<g>` of the drawing; the layer's
* hitboxes are declared (`withDeclaredHitboxes`). Mirrors `crates/core/tests/common/svg_tree.rs`.
* hitboxes are declared (`withDeclaredHitboxes`) and its markers put in the canvas passes
* (`withCanvasPasses`, owner decision 2026-11-01). Mirrors `crates/core/tests/common/svg_tree.rs`.
*/
export function withIsolatedLayer(tree: unknown): unknown {
const root = structuredClone(tree) as {
@@ -169,6 +170,31 @@ export function withIsolatedLayer(tree: unknown): unknown {
}
const group = { ns: root.ns, name: 'g', attrs: moved, children: root.children }
root.attrs = kept
root.children = [group, withDeclaredHitboxes(layer)]
root.children = [group, withCanvasPasses(withDeclaredHitboxes(layer))]
return root
}
/** A marker's pass on the canvas: 0 a point hitbox, 1 a zone or a trigger, 2 a visible twin. */
function canvasPass(node: unknown): number {
const n = node as { name?: string; attrs?: Record<string, string> }
if (n.name !== 'circle') return 1
if (n.attrs?.fill === 'transparent') return 0
return n.attrs?.['pointer-events'] === 'none' ? 2 : 1
}
/**
* Owner decision 2026-11-01 (V1-2.2, « the visible wins »), the editor canvas only: applied to
* a frozen layer after `withDeclaredHitboxes` (a deep copy). Every point hitbox, then every
* other shape, then every visible twin, each pass in the frozen order; the twins capture on
* `visiblePainted`. Mirrors `with_canvas_passes` in `crates/core/tests/common/svg_tree.rs`.
*/
export function withCanvasPasses(layer: unknown): unknown {
const copy = structuredClone(layer) as { children?: unknown[] }
const ranked = (copy.children ?? []).map((child, at) => ({ child, at, pass: canvasPass(child) }))
ranked.sort((a, b) => a.pass - b.pass || a.at - b.at)
copy.children = ranked.map(({ child, pass }) => {
if (pass === 2) (child as { attrs: Record<string, string> }).attrs['pointer-events'] = 'visiblePainted'
return child
})
return copy
}
+2 -1
View File
@@ -21,6 +21,7 @@ import {
import {
checkR3Golden,
treeOf,
withCanvasPasses,
withDeclaredHitboxes,
withIdsScopedPerView,
withIsolatedLayer,
@@ -101,7 +102,7 @@ describe.each(VIEWS)('the %s canvas', (viewId) => {
Object.fromEntries(
Object.entries(declared(frozen) as Record<string, unknown>).map(([name, layer]) => [
name,
withDeclaredHitboxes(layer),
withCanvasPasses(withDeclaredHitboxes(layer)),
]),
),
)