Repository navigation
Measure Mermaid diagrams at CSS zoom 1 - #206
Closed
marc-medley wants to merge 1 commit into
Closed
marc-medley wants to merge 1 commit into
marc-medley wants to merge 1 commit into
Conversation
Fix for a Mermaid 11.16 measurement bug that shows up in MarkEdit-preview’s WKWebView when the preview pane is zoomed. Mermaid node labels can end up clipped when the preview pane is zoomed. Mermaid stores getBoundingClientRect() as foreignObject width and height. WKWebView includes the preview pane's CSS zoom in that rect, and the SVG then uses those numbers as user units. At zoom 0.8 the label box is 0.8× the glyphs, so the last letter and the ascenders clip. The bad box stays until the next preview rebuild, which is why a window can stay clipped after zoom is already back at 1. Run mermaid.run() with ancestor zoom forced to 1, then restore the user's zoom. A zoom change during that run cancels the restore.
Contributor
|
Thanks for the detailed report and proposed fix. I’ve confirmed the underlying issue, but this approach still has problems with zoom changes during rendering and stylesheet-defined zoom in Quick Look. I’m closing this PR and will follow up with a fix that avoids temporarily changing the visible pane’s zoom. Keeping #205 open to track that work. |
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.
Candidate fix to close #205
Caveat: This a Grok 4.7 (high) generated source code solution. As such, you may wish to review the code relative to the MarkEdit-preview project coding practices. That said, it is working locally for me to resolve the issue of Mermaid labels being clipped after zooming the preview pane.
Summary
Mermaid 11.16.0 sizes HTML label
<foreignObject>boxes fromgetBoundingClientRect(). WKWebView includes the preview pane's CSSzoomin that rect, and Mermaid writes it into the SVG as user units. At zoom 0.8 every node label is stored at 0.8× its zoom-1 size (previewis 45.5125 × 19.2 instead of 56.890625 × 24), so the last glyph and the ascenders clip. Command-0 does not rebuild the SVG, so the clip remains after zoom is back at 1.handlePostRendernow clears ancestorstyle.zoomto1beforemermaid.run(), forces layout, and restores the previous zoom before the post-render callback.setPageZoominvalidates an in-flight restore, so a zoom key pressed while a diagram is rendering keeps the new value. Quick Look is covered when its content element is the zoomed ancestor. Syntax-hidden diagrams render throughmermaid.render()ondocument.body, outside the preview zoom, and are unchanged.Nested
flowchart.htmlLabels: falseis not this fix. In 11.16.0 node labels still use a<foreignObject>unless roothtmlLabelsis false.Test plan
yarn test—tests/mermaidZoom.test.tschecks the suspend/restore, a zoom write duringmermaid.run(), and a preview with no diagram```mermaidfence.previewin the Web Inspector is about 56.89 × 24, and the word is wholezoomed-inrule). The diagram stays at its natural width and the labels stay whole