Skip to content

Add opt-in mermaid pan/zoom/fullscreen support#1156

Open
yarikoptic wants to merge 1 commit into
jpanther:devfrom
yarikoptic:enh-zoom
Open

Add opt-in mermaid pan/zoom/fullscreen support#1156
yarikoptic wants to merge 1 commit into
jpanther:devfrom
yarikoptic:enh-zoom

Conversation

@yarikoptic

@yarikoptic yarikoptic commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in pan/zoom/fullscreen support for mermaid diagrams, gated by a new site parameter.

When params.mermaid.panZoom = true:

  • Diagrams become zoomable (scroll) and pannable (drag) via svg-pan-zoom (v3.6.2, MIT)
  • A hover-to-show control overlay appears at top-right with: fullscreen toggle, zoom in, reset, zoom out
  • Fullscreen preserves and restores the previous zoom/pan state on exit
  • Diagrams render at their natural size — no extra margins or layout changes

When the parameter is not set (default), behavior is completely unchanged.

Motivation

Complex mermaid diagrams (nested subgraphs, large flowcharts) are hard to read at the default prose width. Discussion #553 (Image Zooming) shows demand for interactive diagram viewing — 21% of readers attempt to click/zoom images. This addresses that need specifically for mermaid.

Implementation notes

  • svg-pan-zoom is vendored at assets/lib/svg-pan-zoom/svg-pan-zoom.min.js (~30KB) and only bundled into mermaid.bundle.js when the param is enabled
  • All control positioning uses inline JS styles rather than CSS classes, since Congo loads css/compiled/main.css (Tailwind pre-built) and additions to css/main.css require a Tailwind rebuild
  • Controls are hidden by default (opacity: 0) and shown on mouseenter / hidden on mouseleave
  • The mermaid-panzoom CSS class is added to the shortcode container when enabled, providing a hook for the JS
  • Minimal CSS in an inline <style> block in vendor.html handles only SVG max-width override and fullscreen background

Files changed

  • assets/lib/svg-pan-zoom/svg-pan-zoom.min.js — new: vendored library (MIT)
  • assets/js/mermaid.js — pan/zoom init, hover controls, fullscreen with state preservation
  • layouts/_partials/vendor.html — conditional svg-pan-zoom bundling + inline styles
  • layouts/_shortcodes/mermaid.html — conditional mermaid-panzoom class

Usage

# config/_default/params.toml
[mermaid]
  panZoom = true

Demo

See it in action:

image

🤖 Generated with Claude Code and refined

edits:
post initial submission, force pushed to

  • change color for buttons in full screen mode since gray is not visible on dark, now - nice
image

@github-actions github-actions Bot added documentation Improvements or additions to documentation i18n Issue with i18n translations labels Mar 6, 2026
@yarikoptic yarikoptic changed the base branch from stable to dev March 6, 2026 00:25
When `params.mermaid.panZoom = true`, mermaid diagrams get:
- svg-pan-zoom integration (scroll to zoom, drag to pan)
- Hover-to-show control overlay (fullscreen, zoom in, reset, zoom out)
- Fullscreen toggle with state preservation on exit
- No extra margins — diagram renders at natural size

Controls appear on mouse hover and hide when the mouse leaves.
All control positioning uses inline JS styles for reliability.

The feature is off by default — existing behavior is unchanged.

New files:
- assets/lib/svg-pan-zoom/svg-pan-zoom.min.js (v3.6.2, MIT)

Modified:
- assets/js/mermaid.js: pan/zoom/fullscreen logic gated by window.mermaidPanZoom
- layouts/_partials/vendor.html: conditionally bundles svg-pan-zoom + minimal CSS
- layouts/_shortcodes/mermaid.html: adds mermaid-panzoom class when enabled

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Mar 6, 2026

Copy link
Copy Markdown

Deploy Preview for hugo-congo ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a204098
🔍 Latest deploy log https://app.netlify.com/projects/hugo-congo/deploys/69aa21b24298ff00083cf8c3
😎 Deploy Preview https://deploy-preview-1156--hugo-congo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any recent activity.
Please review the PR history and add a reply with any requested information. If no information has been requested, it may be that this contribution does not fit with the project objectives, or does not adhere to the contributing guidelines. If this is in error, please add a reply with further details.
This PR will automatically close in 30 days if no further activity occurs.

@github-actions github-actions Bot added the stale This issue or pull request has not had any recent activity label Jul 4, 2026
@yarikoptic

Copy link
Copy Markdown
Contributor Author

Well, needs to be reviewed, seems still no conflicts etc

@github-actions github-actions Bot removed the stale This issue or pull request has not had any recent activity label Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation i18n Issue with i18n translations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant