Skip to content

Decouple visual targets from diagram rendering - #285

Merged
max-sixty merged 4 commits into
mainfrom
codex/beautiful-mermaid
Sep 5, 2026
Merged

max-sixty merged 4 commits into
mainfrom
codex/beautiful-mermaid

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

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.

This was written by Codex on behalf of max-sixty

# 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 leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py and tests/test_render_gate.py at 0b7627e1 — 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 on 04d4be1a, so it is not from this PR. The two keyline assertions this PR does change (⏎ → ⌘⏎/Ctrl+⏎, Enter → Meta+Enter Control+Enter) fail on 04d4be1a and pass here, which matches SEND = "Mod+Enter" in skills/leaf/assets/runtime/composing/input.js.

All three files carry pytestmark = pytest.mark.nightly, so the PR gate does not run them.

Comment thread skills/leaf/assets/runtime/anchors.js Resolved
@max-sixty
max-sixty merged commit f949fe9 into main Sep 5, 2026
6 checks passed
@max-sixty
max-sixty deleted the codex/beautiful-mermaid branch September 5, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants