Repository navigation
zgx Mermaid: diagrams drawn by Merman, in Zeron's look, with Expand and Save - #1641
Open
quanpersie2001 wants to merge 4 commits into
Open
quanpersie2001 wants to merge 4 commits into
quanpersie2001 wants to merge 4 commits into
Conversation
…nd Save Replace mermaid-rs-renderer 0.3.1 with Merman 0.11 (a headless port of Mermaid's own parser, layouts and SVG). Labels are measured with rustybuzz over the faces usvg draws them with (bundled Geist first), flowcharts are laid out by ELK with orthogonal, rounded edges, edge labels sit on pills, arrowheads are fine chevrons, and decisions are dashed question cards unless the source styles them. Theme fixes for state labels, mindmap sections and deep branches, git branches, classDef ink, and glass grounds. A diagram's strip gets Expand; the lightbox shows a diagram on a panel of its own fill, rounded as a dialog, and saves it as PNG or SVG. Mock harness: ZERON_MOCK_MERMAID=1 appends one diagram of each common kind. merman-elk-layered (the ELK port) is EPL-2.0; see THIRD_PARTY_NOTICES.md.
quanpersie2001
marked this pull request as ready for review
November 28, 2026 19:31
… the host's colour zgx rasterizes an SVG in the frame that first shows it; mounted as the lightbox opened, a diagram's raster landed on the opening frame (a class diagram's: paint 14.7 ms, the frame 47 ms median over six opens). Drawn once the motion rests, the opening frame paints in 4.5 ms (31 ms); its pixels, drawn at 2x, show while it moves. The panel's fill is the host's colour for the diagram, passed through ui.raw, so the design lint no longer flags it.
Morphing out of its thumbnail, a diagram had three pictures taking over from each other mid-motion (the thumbnail's snapshot, its plate, its SVG), and zgx rasterizes the SVG in the first frame that shows it: opening and more so closing flickered (a close's first frame took 64 ms). A diagram is now drawn first, unseen (PREPARE, 64 ms: its raster and upload land in a frame no one sees), then fades and grows in from 0.96 with its panel, as Zeron's dialogs do, and fades and shrinks back as it goes. One picture all the way; its thumbnail stays under the scrim. Other pictures still morph from their thumbnails.
zgx's modal gives focus back, as it closes, to what had it as it opened, scrolling to show it. Whatever that was, the reply was scrolled there as the lightbox closed: the thumbnail itself (pressed, it took focus; a diagram taller than its view can't all show, so it moved), or anything pressed earlier and read past since (another diagram, its Expand, Copy, Show source), and the reply jumped back to it. Focus now goes first to a harbor in the host, off the reply, without a scroll, and the modal opens once it has it: closing gives focus back to the harbor and scrolls nothing. The thumbnail is then given focus without a scroll, for the keyboard, and the harbor goes. A press on a thumbnail leaves focus where it is (focus_on_press). A test opens and closes two diagrams taller than their view in turn by pointer, after an Expand on the other, and by Tab and Enter: the reply never moves, and focus is back on the diagram.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mermaid diagrams in replies were hard to read:
mermaid-rs-renderer0.3.1's own layout misplaced nodes, overlapped labels and subgraphs in larger diagrams, and refused common syntax (<<interface>>in class diagrams showed the source instead of a diagram). This draws them with Merman 0.11 (a headless Rust port of Mermaid's own parser, layouts and SVG, which Zed also uses), in Zeron's look.apps/zgx/src/mermaid.rs): Merman'sbasetheme with every role taken from the theme's tokens. Labels are measured with rustybuzz over the faces usvg then draws them with (bundled Geist first), so text fits its boxes, Vietnamese and CJK included.id{…}) drawn as dashed question cards in the accent instead of diamonds, unless the source styles them (a rewrite Mermaid can't parse falls back to the source as written). Subgraph and composite-state grounds are washes over the glass fence, not solid colours guessed from it.17 - 3 × depth, negative past the fourth level); git branches all grey; a source's lightclassDeffill left labels unreadable in dark (labels now take dark or light ink below 3:1 contrast, keeping an ink the source chose that reads).zeron.dialog.radius), where it zooms and pans; it opens from the thumbnail. It saves the diagram as PNG or SVG (island button, context menu, ⌘S). Other pictures open as before.style/classDefvalues out unescaped, so a source could inject SVG elements; Merman escapes them (the layer-budget test now pins that). Rendering runs under a 4 s deadline and Merman's interactive resource policy.mermaid.saveonly copies a PNG this module drew, from its own folder.ZERON_MOCK_MERMAID=1makes mock turns include a simple and a large flowchart, a sequence, a state and a class diagram (CONTRIBUTORS.md). The screenshots use it.Every new crate is MIT OR Apache-2.0 (one Apache-2.0, one MIT), except
merman-elk-layered, Merman's port of Eclipse ELK's layered layout, which is EPL-2.0. It's what gives flowcharts their orthogonal routing (layout-elkfeature). EPL-2.0 is file-level copyleft: Zeron's own code stays MIT, but distributing the app means keeping the notice and pointing to that crate's source (done inTHIRD_PARTY_NOTICES.md). It would be the first copyleft-only crate in the app, so this is your call:"layout-elk"fromapps/zgx/Cargo.tomland"layout": "elk"fromsite_config. Everything else stays; edges go back to Mermaid's default (dagre) routing, with some diagonal segments. Happy to push that change.Dependencies (why)
merman0.11.0 replacesmermaid-rs-renderer0.3.1 (featuressvg,all-diagrams,layout-cytoscape,layout-elk).rustybuzz0.20 was already in the tree; it's now a direct dependency for label measurement, so no second usvg/resvg is pulled in.Look closely at
soften_decisions(a source rewrite, with fallback) and the SVG post-processing inbadges/drop_grounds/thin_arrows.ds/lightbox.luau's panel mode (panel(),geo(),clamp_view), and the new tokenzeron.lightbox.panel_margin(also in Zeron v2's tokens;.base.jsonblessed).Test plan
cargo test --bin zeron-zgx -- mermaid:: official::: 19 passed. New: labels fit their boxes, class annotations draw, labels never inked in the node's fill, classDef labels legible, mindmap branches drawn, decisions become cards unless styled, rewrite fallback, pills and chevrons, save writes only diagrams.zgx test ui: Mermaid (incl. new "Expand opens the drawn diagram in the lightbox, which offers Save") and lightbox tests pass.cargo test -p zeron-harness --lib mock: passed.scripts/ci/test-zgx.sh rusthas 1 failure,transcript_scroll_tests::a_synced_chat_scrolled_up_from_its_end_passes_through_every_message, which fails identically onmain(checked in a clean worktree).scripts/ci/test-zgx.sh uifailuresan @ pick goes out as Zeron's file mentionand the twomention_launchertests fail identically onmain.cargo clippy --bin zeron-zgx: no new warnings in touched code;zgx lint: 0 errors.ZERON_ZGX_ENGINE_PORT/DATA/HOMEin /tmp) with the mock agent; the same conversation opened bymainand by this branch, dark and light, each diagram in the reply and in the lightbox; opening animation stepped with a frozen clock.Screenshots
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.