Repository navigation
Decouple visual targets from diagram rendering - #285
Conversation
# Conflicts: # docs/registry.html # skills/leaf/assets/registry.json # skills/leaf/assets/runtime/composing/surface.js # tests/test_render_semantic_selection.py
# Conflicts: # skills/leaf/assets/runtime/anchors.js
leaf-agent
left a comment
There was a problem hiding this comment.
One finding on the new package contract; the rest of the decoupling reads well.
visualPartAt resolves the deepest registered part and only then checks the authored declaration, so a registered part the page did not declare shadows the enclosing part it did declare, and the hit falls through to the whole picture. skills/leaf/CLAUDE.md states the other order in this same PR — "core admits only tokens authored in ATTR and derives both token lookup and the deepest hit" — so admitting first would match what the contract promises.
Reproduced against this PR's own fixture: serving GENERIC_VISUAL_PAGE with parts="outer html" and Alt-hovering #inner path aims at the whole widget (.lf-aim gets data-for="visual") rather than at outer, whose surface is drawn around it. With all three declared it correctly aims at inner, so only the partial-declaration case is affected. No shipped page hits it today — I checked a stateDiagram-v2 composite state and Mermaid renders Working and its nested Build as sibling [data-id] elements, not nested ones — but the fixture this PR adds does nest, which is the shape the generic contract invites.
What I ran
Against 0b7627e1 and against origin/main at 04d4be1a, on this repo's Chrome:
tests/test_render_aim.pyandtests/test_render_gate.pyat0b7627e1— 124 passed.- With the two inline suggestions applied, the same 124 pass and the probe above aims at
outer. tests/test_render_semantic_selection.py— one failure,test_the_key_line_only_hides_targets_in_the_lane_it_paints, a 0.016px hint/keyline overlap (293.296875 < 293.3125). It reproduces identically on04d4be1a, so it is not from this PR. The two keyline assertions this PR does change (⏎→⌘⏎/Ctrl+⏎,Enter→Meta+Enter Control+Enter) fail on04d4be1aand pass here, which matchesSEND = "Mod+Enter"inskills/leaf/assets/runtime/composing/input.js.
All three files carry pytestmark = pytest.mark.nightly, so the PR gate does not run them.
Mermaid's visual-part targeting previously split token lookup, hit testing, contour extraction, and mark state across the diagram widget and the anchor runtime. This introduces one package-neutral visual-target contract, with Mermaid as its first consumer.
registerVisualParts(source, read)supplies one current{id, element, label, surface?}inventory. Core derives both durable-token resolution and deepest-authored-part hit testing from that inventory, while a resolved-target model keeps semantic ownership, placement, and paint surfaces distinct. The extracted target painter now owns Alt-hover aims and persistent Comment, reaction, action, and pending marks; it follows the union of painted SVG geometry, uses the registered surface's rounded box as a fallback, and respects clipping across declared shadow roots.The diagram package no longer exposes paired lookup methods or names Mermaid shapes. Render-gate validation checks the generic registration contract, and package documentation covers the API and its explicit geometry-update signal. Browser fixtures exercise nested parts, narrowed paint surfaces, compound fill-and-stroke geometry, same-bounds redraws, HTML fallbacks, shadow clipping, and semantic interaction outside the selected paint surface.
The painter intentionally snapshots native SVG geometry instead of reproducing arbitrary masks, filters, patterns, or
<use>instance trees. Unsupported paint semantics retain the rectangular fallback.Verified with
uv run pytest tests(828 passed),uv run pre-commit run --all-files, the light/dark render gate, and browser inspection at 390, 768, and 1280 px.