@chadfurman/docsify-mermaid-zoom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chad Furman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # docsify-mermaid-zoom
2
+
3
+ Interactive mermaid diagrams for [docsify](https://docsify.js.org/) — zoom, pan, resize, and fullscreen.
4
+
5
+ ![demo](https://img.shields.io/badge/demo-docsify--mermaid--zoom-0F766E)
6
+
7
+ ## Features
8
+
9
+ - **Pinch-to-zoom / Ctrl+scroll** on any mermaid diagram (regular scrolling passes through to the page)
10
+ - **Click-and-drag to pan** with grab/grabbing cursor
11
+ - **Resize handle** — drag the bottom-right corner to make the diagram taller/shorter
12
+ - **Fullscreen mode** — expand any diagram to fill the viewport (ESC to exit)
13
+ - **Zoom controls** — +, -, reset buttons in the top-right corner
14
+ - **Auto-fit** — diagrams fit and center on load, resize, and page navigation
15
+ - **Configurable** — min/max zoom, container height limits, render delay
16
+ - **Graceful fallback** — if svg-pan-zoom fails, diagrams still render normally
17
+
18
+ ## Install
19
+
20
+ ### CDN (recommended for docsify)
21
+
22
+ Add to your docsify `index.html`, after mermaid and docsify-mermaid:
23
+
24
+ ```html
25
+ <!-- CSS -->
26
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-mermaid-zoom/dist/docsify-mermaid-zoom.css">
27
+
28
+ <!-- Dependencies (load these first) -->
29
+ <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
30
+ <script src="https://cdn.jsdelivr.net/npm/docsify-mermaid@2/dist/docsify-mermaid.js"></script>
31
+ <script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js"></script>
32
+
33
+ <!-- Plugin -->
34
+ <script src="https://cdn.jsdelivr.net/npm/docsify-mermaid-zoom/dist/docsify-mermaid-zoom.js"></script>
35
+ ```
36
+
37
+ ### npm
38
+
39
+ ```bash
40
+ npm install docsify-mermaid-zoom
41
+ ```
42
+
43
+ Then reference `node_modules/docsify-mermaid-zoom/dist/` in your HTML.
44
+
45
+ ## Dependencies
46
+
47
+ These must be loaded **before** docsify-mermaid-zoom:
48
+
49
+ | Package | Purpose |
50
+ |---------|---------|
51
+ | [mermaid](https://mermaid.js.org/) | Renders mermaid markdown into SVG |
52
+ | [docsify-mermaid](https://github.com/Leward/mermaid-docsify) | Hooks mermaid into docsify's rendering pipeline |
53
+ | [svg-pan-zoom](https://github.com/bumbu/svg-pan-zoom) | Provides zoom/pan/fit on SVG elements |
54
+
55
+ ## Configuration
56
+
57
+ Optional — configure via `window.$docsify.mermaidZoom`:
58
+
59
+ ```html
60
+ <script>
61
+ window.$docsify = {
62
+ // ... your docsify config
63
+ mermaidZoom: {
64
+ renderDelay: 300, // ms to wait for mermaid to finish rendering
65
+ minZoom: 0.1, // minimum zoom level
66
+ maxZoom: 10, // maximum zoom level
67
+ minHeight: 300, // minimum container height (px)
68
+ maxHeight: 800 // maximum container height (px)
69
+ }
70
+ }
71
+ </script>
72
+ ```
73
+
74
+ ## Theming
75
+
76
+ The accent color used for hover borders and button highlights can be customized with a CSS variable:
77
+
78
+ ```css
79
+ :root {
80
+ --mermaid-zoom-accent: #0F766E;
81
+ }
82
+ ```
83
+
84
+ ## How it works
85
+
86
+ 1. After each docsify page render, the plugin waits for mermaid to finish rendering SVGs
87
+ 2. Each `.mermaid` element gets wrapped in a `.mermaid-zoom-container` div
88
+ 3. The container is sized proportionally to the diagram's aspect ratio
89
+ 4. `svg-pan-zoom` is initialized on the SVG with fit + center
90
+ 5. Zoom controls, fullscreen button, and resize handle are added
91
+ 6. A `ResizeObserver` watches the container so dragging the resize handle re-fits the diagram
92
+
93
+ ## Full example
94
+
95
+ ```html
96
+ <!DOCTYPE html>
97
+ <html>
98
+ <head>
99
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">
100
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-mermaid-zoom/dist/docsify-mermaid-zoom.css">
101
+ </head>
102
+ <body>
103
+ <div id="app"></div>
104
+ <script>
105
+ window.$docsify = {
106
+ loadSidebar: true,
107
+ mermaidZoom: { maxHeight: 600 }
108
+ }
109
+ </script>
110
+ <script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js"></script>
111
+ <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
112
+ <script src="https://cdn.jsdelivr.net/npm/docsify-mermaid@2/dist/docsify-mermaid.js"></script>
113
+ <script>mermaid.initialize({ startOnLoad: false });</script>
114
+ <script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js"></script>
115
+ <script src="https://cdn.jsdelivr.net/npm/docsify-mermaid-zoom/dist/docsify-mermaid-zoom.js"></script>
116
+ </body>
117
+ </html>
118
+ ```
119
+
120
+ Then in any markdown file:
121
+
122
+ ````markdown
123
+ ```mermaid
124
+ graph TD
125
+ A[Start] --> B{Decision}
126
+ B -->|Yes| C[Do something]
127
+ B -->|No| D[Do something else]
128
+ C --> E[End]
129
+ D --> E
130
+ ```
131
+ ````
132
+
133
+ ## License
134
+
135
+ MIT
@@ -0,0 +1,117 @@
1
+ /* docsify-mermaid-zoom — Interactive mermaid diagrams for docsify */
2
+
3
+ /* Base mermaid element inside zoom container */
4
+ .mermaid-zoom-container .mermaid {
5
+ display: flex;
6
+ justify-content: center;
7
+ margin: 0;
8
+ height: 100%;
9
+ }
10
+ .mermaid-zoom-container .mermaid svg {
11
+ max-width: 100%;
12
+ height: 100%;
13
+ }
14
+
15
+ /* Interactive container */
16
+ .mermaid-zoom-container {
17
+ position: relative;
18
+ border: 1px solid #e2e8f0;
19
+ border-radius: 8px;
20
+ margin: 1.5em 0;
21
+ background: #fafbfc;
22
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
23
+ overflow: hidden;
24
+ width: 100%;
25
+ min-height: 300px;
26
+ resize: vertical;
27
+ }
28
+ .mermaid-zoom-container:hover {
29
+ border-color: var(--mermaid-zoom-accent, #0F766E);
30
+ box-shadow: 0 2px 8px rgba(15, 118, 110, 0.12);
31
+ }
32
+ .mermaid-zoom-container svg {
33
+ cursor: grab;
34
+ max-width: none;
35
+ display: block;
36
+ }
37
+ .mermaid-zoom-container svg:active {
38
+ cursor: grabbing;
39
+ }
40
+
41
+ /* Fullscreen mode */
42
+ .mermaid-zoom-container.fullscreen {
43
+ position: fixed;
44
+ top: 0;
45
+ left: 0;
46
+ width: 100vw !important;
47
+ height: 100vh !important;
48
+ max-height: none !important;
49
+ z-index: 9999;
50
+ border-radius: 0;
51
+ border: none;
52
+ margin: 0;
53
+ resize: none;
54
+ background: white;
55
+ }
56
+ .mermaid-zoom-container.fullscreen .mermaid-zoom-controls {
57
+ top: 16px;
58
+ right: 16px;
59
+ opacity: 1;
60
+ }
61
+ .mermaid-zoom-container.fullscreen .mermaid-zoom-hint {
62
+ bottom: 16px;
63
+ right: 16px;
64
+ }
65
+
66
+ /* Zoom controls */
67
+ .mermaid-zoom-controls {
68
+ position: absolute;
69
+ top: 8px;
70
+ right: 8px;
71
+ display: flex;
72
+ flex-direction: column;
73
+ gap: 2px;
74
+ z-index: 10;
75
+ opacity: 0.7;
76
+ transition: opacity 0.2s;
77
+ }
78
+ .mermaid-zoom-container:hover .mermaid-zoom-controls {
79
+ opacity: 1;
80
+ }
81
+ .mermaid-zoom-controls button {
82
+ width: 30px;
83
+ height: 30px;
84
+ border: 1px solid #d1d5db;
85
+ background: white;
86
+ border-radius: 4px;
87
+ font-size: 16px;
88
+ font-weight: 600;
89
+ color: #374151;
90
+ cursor: pointer;
91
+ display: flex;
92
+ align-items: center;
93
+ justify-content: center;
94
+ line-height: 1;
95
+ padding: 0;
96
+ transition: background 0.15s, border-color 0.15s;
97
+ }
98
+ .mermaid-zoom-controls button:hover {
99
+ background: #f0fdfa;
100
+ border-color: var(--mermaid-zoom-accent, #0F766E);
101
+ color: var(--mermaid-zoom-accent, #0F766E);
102
+ }
103
+
104
+ /* Hint label */
105
+ .mermaid-zoom-hint {
106
+ position: absolute;
107
+ bottom: 6px;
108
+ right: 8px;
109
+ font-size: 11px;
110
+ color: #9ca3af;
111
+ pointer-events: none;
112
+ opacity: 0;
113
+ transition: opacity 0.2s;
114
+ }
115
+ .mermaid-zoom-container:hover .mermaid-zoom-hint {
116
+ opacity: 1;
117
+ }
@@ -0,0 +1,220 @@
1
+ /**
2
+ * docsify-mermaid-zoom
3
+ *
4
+ * Interactive mermaid diagrams for docsify — zoom, pan, resize, and fullscreen.
5
+ *
6
+ * Dependencies (load before this script):
7
+ * - mermaid (https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js)
8
+ * - docsify-mermaid (https://cdn.jsdelivr.net/npm/docsify-mermaid@2/dist/docsify-mermaid.js)
9
+ * - svg-pan-zoom (https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js)
10
+ *
11
+ * Usage:
12
+ * <link rel="stylesheet" href="docsify-mermaid-zoom.css">
13
+ * <script src="docsify-mermaid-zoom.js"></script>
14
+ *
15
+ * Configuration (optional, via window.$docsify.mermaidZoom):
16
+ * - renderDelay: ms to wait after page render for mermaid to finish (default: 300)
17
+ * - minZoom: minimum zoom level (default: 0.1)
18
+ * - maxZoom: maximum zoom level (default: 10)
19
+ * - minHeight: minimum container height in px (default: 300)
20
+ * - maxHeight: maximum container height in px (default: 800)
21
+ */
22
+ (function () {
23
+ 'use strict';
24
+
25
+ var DEFAULTS = {
26
+ renderDelay: 300,
27
+ minZoom: 0.1,
28
+ maxZoom: 10,
29
+ minHeight: 300,
30
+ maxHeight: 800
31
+ };
32
+
33
+ function getConfig() {
34
+ var userConfig = (window.$docsify && window.$docsify.mermaidZoom) || {};
35
+ return {
36
+ renderDelay: userConfig.renderDelay || DEFAULTS.renderDelay,
37
+ minZoom: userConfig.minZoom || DEFAULTS.minZoom,
38
+ maxZoom: userConfig.maxZoom || DEFAULTS.maxZoom,
39
+ minHeight: userConfig.minHeight || DEFAULTS.minHeight,
40
+ maxHeight: userConfig.maxHeight || DEFAULTS.maxHeight
41
+ };
42
+ }
43
+
44
+ function createButton(text, title, ariaLabel) {
45
+ var btn = document.createElement('button');
46
+ btn.textContent = text;
47
+ btn.title = title;
48
+ btn.setAttribute('aria-label', ariaLabel);
49
+ return btn;
50
+ }
51
+
52
+ function initZoomContainers() {
53
+ var config = getConfig();
54
+ var diagrams = document.querySelectorAll('.mermaid');
55
+
56
+ diagrams.forEach(function (el) {
57
+ // Skip if already wrapped
58
+ if (el.parentElement && el.parentElement.classList.contains('mermaid-zoom-container')) return;
59
+
60
+ var svg = el.querySelector('svg');
61
+ if (!svg) return;
62
+
63
+ // Create the interactive container
64
+ var container = document.createElement('div');
65
+ container.className = 'mermaid-zoom-container';
66
+
67
+ // Compute proportional height from SVG aspect ratio
68
+ var bbox = svg.getBBox ? svg.getBBox() : null;
69
+ var svgWidth = bbox ? bbox.width : 800;
70
+ var svgHeight = bbox ? bbox.height : 400;
71
+ var aspectRatio = svgHeight / svgWidth;
72
+ var containerHeight = Math.min(
73
+ Math.max(Math.round(aspectRatio * 900), config.minHeight),
74
+ config.maxHeight
75
+ );
76
+ container.style.height = containerHeight + 'px';
77
+
78
+ // Insert container and move diagram inside
79
+ el.parentNode.insertBefore(container, el);
80
+ container.appendChild(el);
81
+
82
+ // Ensure SVG has a viewBox with padding
83
+ if (!svg.getAttribute('viewBox') && bbox) {
84
+ svg.setAttribute('viewBox',
85
+ (bbox.x - 10) + ' ' + (bbox.y - 10) + ' ' +
86
+ (bbox.width + 20) + ' ' + (bbox.height + 20));
87
+ }
88
+
89
+ // Remove inline styles so svg-pan-zoom can control sizing
90
+ svg.removeAttribute('style');
91
+ svg.style.width = '100%';
92
+ svg.style.height = '100%';
93
+
94
+ // Create controls
95
+ var controls = document.createElement('div');
96
+ controls.className = 'mermaid-zoom-controls';
97
+
98
+ var zoomIn = createButton('+', 'Zoom in', 'Zoom in');
99
+ var zoomOut = createButton('\u2212', 'Zoom out', 'Zoom out');
100
+ var resetBtn = createButton('\u21BA', 'Reset view', 'Reset zoom');
101
+ var fullscreenBtn = createButton('\u26F6', 'Fullscreen', 'Toggle fullscreen');
102
+ fullscreenBtn.style.marginTop = '6px';
103
+
104
+ controls.appendChild(zoomIn);
105
+ controls.appendChild(zoomOut);
106
+ controls.appendChild(resetBtn);
107
+ controls.appendChild(fullscreenBtn);
108
+ container.appendChild(controls);
109
+
110
+ // Hint
111
+ var hint = document.createElement('div');
112
+ hint.className = 'mermaid-zoom-hint';
113
+ hint.textContent = 'Pinch or Ctrl+scroll to zoom \u00B7 Drag to pan \u00B7 Resize from corner';
114
+ container.appendChild(hint);
115
+
116
+ // Initialize svg-pan-zoom
117
+ try {
118
+ var panZoom = svgPanZoom(svg, {
119
+ zoomEnabled: true,
120
+ panEnabled: true,
121
+ controlIconsEnabled: false,
122
+ mouseWheelZoomEnabled: false,
123
+ preventMouseEventsDefault: true,
124
+ zoomScaleSensitivity: 0.3,
125
+ minZoom: config.minZoom,
126
+ maxZoom: config.maxZoom,
127
+ fit: true,
128
+ center: true,
129
+ contain: false
130
+ });
131
+
132
+ // Custom wheel handler: only zoom on pinch (ctrlKey) or Ctrl+scroll.
133
+ // Regular two-finger scroll passes through to the page.
134
+ container.addEventListener('wheel', function (e) {
135
+ if (!e.ctrlKey) return; // let normal scroll bubble to page
136
+ e.preventDefault();
137
+ var direction = e.deltaY < 0 ? 1.1 : 0.9;
138
+ panZoom.zoomBy(direction);
139
+ }, { passive: false });
140
+
141
+ // Force fit after layout settles
142
+ setTimeout(function () {
143
+ panZoom.resize();
144
+ panZoom.fit();
145
+ panZoom.center();
146
+ }, 100);
147
+
148
+ // Zoom controls
149
+ zoomIn.addEventListener('click', function (e) {
150
+ e.preventDefault();
151
+ panZoom.zoomIn();
152
+ });
153
+ zoomOut.addEventListener('click', function (e) {
154
+ e.preventDefault();
155
+ panZoom.zoomOut();
156
+ });
157
+ resetBtn.addEventListener('click', function (e) {
158
+ e.preventDefault();
159
+ panZoom.resetZoom();
160
+ panZoom.resetPan();
161
+ panZoom.fit();
162
+ panZoom.center();
163
+ });
164
+
165
+ // Fullscreen toggle
166
+ var savedHeight = container.style.height;
167
+ fullscreenBtn.addEventListener('click', function (e) {
168
+ e.preventDefault();
169
+ var isFullscreen = container.classList.toggle('fullscreen');
170
+ fullscreenBtn.textContent = isFullscreen ? '\u2716' : '\u26F6';
171
+ fullscreenBtn.title = isFullscreen ? 'Exit fullscreen' : 'Fullscreen';
172
+ document.body.style.overflow = isFullscreen ? 'hidden' : '';
173
+ if (!isFullscreen) container.style.height = savedHeight;
174
+ setTimeout(function () {
175
+ panZoom.resize();
176
+ panZoom.fit();
177
+ panZoom.center();
178
+ }, 50);
179
+ });
180
+
181
+ // ESC to exit fullscreen
182
+ document.addEventListener('keydown', function (e) {
183
+ if (e.key === 'Escape' && container.classList.contains('fullscreen')) {
184
+ fullscreenBtn.click();
185
+ }
186
+ });
187
+
188
+ // Refit on window resize and container resize (draggable corner)
189
+ var resizeTimer;
190
+ var resizeHandler = function () {
191
+ clearTimeout(resizeTimer);
192
+ resizeTimer = setTimeout(function () {
193
+ panZoom.resize();
194
+ panZoom.fit();
195
+ panZoom.center();
196
+ }, 150);
197
+ };
198
+ window.addEventListener('resize', resizeHandler);
199
+ if (window.ResizeObserver) {
200
+ new ResizeObserver(resizeHandler).observe(container);
201
+ }
202
+ } catch (err) {
203
+ console.warn('docsify-mermaid-zoom: svg-pan-zoom init failed:', err);
204
+ }
205
+ });
206
+ }
207
+
208
+ // Docsify plugin registration
209
+ function mermaidZoomPlugin(hook) {
210
+ hook.doneEach(function () {
211
+ var config = getConfig();
212
+ setTimeout(initZoomContainers, config.renderDelay);
213
+ });
214
+ }
215
+
216
+ // Register
217
+ if (!window.$docsify) window.$docsify = {};
218
+ if (!window.$docsify.plugins) window.$docsify.plugins = [];
219
+ window.$docsify.plugins.push(mermaidZoomPlugin);
220
+ })();
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@chadfurman/docsify-mermaid-zoom",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "1.0.0",
7
+ "description": "Interactive mermaid diagrams for docsify — zoom, pan, resize, and fullscreen",
8
+ "main": "dist/docsify-mermaid-zoom.js",
9
+ "files": [
10
+ "dist/",
11
+ "src/"
12
+ ],
13
+ "scripts": {
14
+ "build": "mkdir -p dist && cp src/docsify-mermaid-zoom.js dist/ && cp src/docsify-mermaid-zoom.css dist/",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "docsify",
19
+ "docsify-plugin",
20
+ "mermaid",
21
+ "zoom",
22
+ "pan",
23
+ "fullscreen",
24
+ "interactive",
25
+ "diagrams",
26
+ "svg-pan-zoom"
27
+ ],
28
+ "author": "Chad Furman",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/chadfurman/docsify-mermaid-zoom.git"
33
+ },
34
+ "homepage": "https://github.com/chadfurman/docsify-mermaid-zoom#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/chadfurman/docsify-mermaid-zoom/issues"
37
+ },
38
+ "peerDependencies": {
39
+ "docsify": ">=4.0.0",
40
+ "mermaid": ">=10.0.0"
41
+ }
42
+ }
@@ -0,0 +1,117 @@
1
+ /* docsify-mermaid-zoom — Interactive mermaid diagrams for docsify */
2
+
3
+ /* Base mermaid element inside zoom container */
4
+ .mermaid-zoom-container .mermaid {
5
+ display: flex;
6
+ justify-content: center;
7
+ margin: 0;
8
+ height: 100%;
9
+ }
10
+ .mermaid-zoom-container .mermaid svg {
11
+ max-width: 100%;
12
+ height: 100%;
13
+ }
14
+
15
+ /* Interactive container */
16
+ .mermaid-zoom-container {
17
+ position: relative;
18
+ border: 1px solid #e2e8f0;
19
+ border-radius: 8px;
20
+ margin: 1.5em 0;
21
+ background: #fafbfc;
22
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
23
+ overflow: hidden;
24
+ width: 100%;
25
+ min-height: 300px;
26
+ resize: vertical;
27
+ }
28
+ .mermaid-zoom-container:hover {
29
+ border-color: var(--mermaid-zoom-accent, #0F766E);
30
+ box-shadow: 0 2px 8px rgba(15, 118, 110, 0.12);
31
+ }
32
+ .mermaid-zoom-container svg {
33
+ cursor: grab;
34
+ max-width: none;
35
+ display: block;
36
+ }
37
+ .mermaid-zoom-container svg:active {
38
+ cursor: grabbing;
39
+ }
40
+
41
+ /* Fullscreen mode */
42
+ .mermaid-zoom-container.fullscreen {
43
+ position: fixed;
44
+ top: 0;
45
+ left: 0;
46
+ width: 100vw !important;
47
+ height: 100vh !important;
48
+ max-height: none !important;
49
+ z-index: 9999;
50
+ border-radius: 0;
51
+ border: none;
52
+ margin: 0;
53
+ resize: none;
54
+ background: white;
55
+ }
56
+ .mermaid-zoom-container.fullscreen .mermaid-zoom-controls {
57
+ top: 16px;
58
+ right: 16px;
59
+ opacity: 1;
60
+ }
61
+ .mermaid-zoom-container.fullscreen .mermaid-zoom-hint {
62
+ bottom: 16px;
63
+ right: 16px;
64
+ }
65
+
66
+ /* Zoom controls */
67
+ .mermaid-zoom-controls {
68
+ position: absolute;
69
+ top: 8px;
70
+ right: 8px;
71
+ display: flex;
72
+ flex-direction: column;
73
+ gap: 2px;
74
+ z-index: 10;
75
+ opacity: 0.7;
76
+ transition: opacity 0.2s;
77
+ }
78
+ .mermaid-zoom-container:hover .mermaid-zoom-controls {
79
+ opacity: 1;
80
+ }
81
+ .mermaid-zoom-controls button {
82
+ width: 30px;
83
+ height: 30px;
84
+ border: 1px solid #d1d5db;
85
+ background: white;
86
+ border-radius: 4px;
87
+ font-size: 16px;
88
+ font-weight: 600;
89
+ color: #374151;
90
+ cursor: pointer;
91
+ display: flex;
92
+ align-items: center;
93
+ justify-content: center;
94
+ line-height: 1;
95
+ padding: 0;
96
+ transition: background 0.15s, border-color 0.15s;
97
+ }
98
+ .mermaid-zoom-controls button:hover {
99
+ background: #f0fdfa;
100
+ border-color: var(--mermaid-zoom-accent, #0F766E);
101
+ color: var(--mermaid-zoom-accent, #0F766E);
102
+ }
103
+
104
+ /* Hint label */
105
+ .mermaid-zoom-hint {
106
+ position: absolute;
107
+ bottom: 6px;
108
+ right: 8px;
109
+ font-size: 11px;
110
+ color: #9ca3af;
111
+ pointer-events: none;
112
+ opacity: 0;
113
+ transition: opacity 0.2s;
114
+ }
115
+ .mermaid-zoom-container:hover .mermaid-zoom-hint {
116
+ opacity: 1;
117
+ }
@@ -0,0 +1,220 @@
1
+ /**
2
+ * docsify-mermaid-zoom
3
+ *
4
+ * Interactive mermaid diagrams for docsify — zoom, pan, resize, and fullscreen.
5
+ *
6
+ * Dependencies (load before this script):
7
+ * - mermaid (https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js)
8
+ * - docsify-mermaid (https://cdn.jsdelivr.net/npm/docsify-mermaid@2/dist/docsify-mermaid.js)
9
+ * - svg-pan-zoom (https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js)
10
+ *
11
+ * Usage:
12
+ * <link rel="stylesheet" href="docsify-mermaid-zoom.css">
13
+ * <script src="docsify-mermaid-zoom.js"></script>
14
+ *
15
+ * Configuration (optional, via window.$docsify.mermaidZoom):
16
+ * - renderDelay: ms to wait after page render for mermaid to finish (default: 300)
17
+ * - minZoom: minimum zoom level (default: 0.1)
18
+ * - maxZoom: maximum zoom level (default: 10)
19
+ * - minHeight: minimum container height in px (default: 300)
20
+ * - maxHeight: maximum container height in px (default: 800)
21
+ */
22
+ (function () {
23
+ 'use strict';
24
+
25
+ var DEFAULTS = {
26
+ renderDelay: 300,
27
+ minZoom: 0.1,
28
+ maxZoom: 10,
29
+ minHeight: 300,
30
+ maxHeight: 800
31
+ };
32
+
33
+ function getConfig() {
34
+ var userConfig = (window.$docsify && window.$docsify.mermaidZoom) || {};
35
+ return {
36
+ renderDelay: userConfig.renderDelay || DEFAULTS.renderDelay,
37
+ minZoom: userConfig.minZoom || DEFAULTS.minZoom,
38
+ maxZoom: userConfig.maxZoom || DEFAULTS.maxZoom,
39
+ minHeight: userConfig.minHeight || DEFAULTS.minHeight,
40
+ maxHeight: userConfig.maxHeight || DEFAULTS.maxHeight
41
+ };
42
+ }
43
+
44
+ function createButton(text, title, ariaLabel) {
45
+ var btn = document.createElement('button');
46
+ btn.textContent = text;
47
+ btn.title = title;
48
+ btn.setAttribute('aria-label', ariaLabel);
49
+ return btn;
50
+ }
51
+
52
+ function initZoomContainers() {
53
+ var config = getConfig();
54
+ var diagrams = document.querySelectorAll('.mermaid');
55
+
56
+ diagrams.forEach(function (el) {
57
+ // Skip if already wrapped
58
+ if (el.parentElement && el.parentElement.classList.contains('mermaid-zoom-container')) return;
59
+
60
+ var svg = el.querySelector('svg');
61
+ if (!svg) return;
62
+
63
+ // Create the interactive container
64
+ var container = document.createElement('div');
65
+ container.className = 'mermaid-zoom-container';
66
+
67
+ // Compute proportional height from SVG aspect ratio
68
+ var bbox = svg.getBBox ? svg.getBBox() : null;
69
+ var svgWidth = bbox ? bbox.width : 800;
70
+ var svgHeight = bbox ? bbox.height : 400;
71
+ var aspectRatio = svgHeight / svgWidth;
72
+ var containerHeight = Math.min(
73
+ Math.max(Math.round(aspectRatio * 900), config.minHeight),
74
+ config.maxHeight
75
+ );
76
+ container.style.height = containerHeight + 'px';
77
+
78
+ // Insert container and move diagram inside
79
+ el.parentNode.insertBefore(container, el);
80
+ container.appendChild(el);
81
+
82
+ // Ensure SVG has a viewBox with padding
83
+ if (!svg.getAttribute('viewBox') && bbox) {
84
+ svg.setAttribute('viewBox',
85
+ (bbox.x - 10) + ' ' + (bbox.y - 10) + ' ' +
86
+ (bbox.width + 20) + ' ' + (bbox.height + 20));
87
+ }
88
+
89
+ // Remove inline styles so svg-pan-zoom can control sizing
90
+ svg.removeAttribute('style');
91
+ svg.style.width = '100%';
92
+ svg.style.height = '100%';
93
+
94
+ // Create controls
95
+ var controls = document.createElement('div');
96
+ controls.className = 'mermaid-zoom-controls';
97
+
98
+ var zoomIn = createButton('+', 'Zoom in', 'Zoom in');
99
+ var zoomOut = createButton('\u2212', 'Zoom out', 'Zoom out');
100
+ var resetBtn = createButton('\u21BA', 'Reset view', 'Reset zoom');
101
+ var fullscreenBtn = createButton('\u26F6', 'Fullscreen', 'Toggle fullscreen');
102
+ fullscreenBtn.style.marginTop = '6px';
103
+
104
+ controls.appendChild(zoomIn);
105
+ controls.appendChild(zoomOut);
106
+ controls.appendChild(resetBtn);
107
+ controls.appendChild(fullscreenBtn);
108
+ container.appendChild(controls);
109
+
110
+ // Hint
111
+ var hint = document.createElement('div');
112
+ hint.className = 'mermaid-zoom-hint';
113
+ hint.textContent = 'Pinch or Ctrl+scroll to zoom \u00B7 Drag to pan \u00B7 Resize from corner';
114
+ container.appendChild(hint);
115
+
116
+ // Initialize svg-pan-zoom
117
+ try {
118
+ var panZoom = svgPanZoom(svg, {
119
+ zoomEnabled: true,
120
+ panEnabled: true,
121
+ controlIconsEnabled: false,
122
+ mouseWheelZoomEnabled: false,
123
+ preventMouseEventsDefault: true,
124
+ zoomScaleSensitivity: 0.3,
125
+ minZoom: config.minZoom,
126
+ maxZoom: config.maxZoom,
127
+ fit: true,
128
+ center: true,
129
+ contain: false
130
+ });
131
+
132
+ // Custom wheel handler: only zoom on pinch (ctrlKey) or Ctrl+scroll.
133
+ // Regular two-finger scroll passes through to the page.
134
+ container.addEventListener('wheel', function (e) {
135
+ if (!e.ctrlKey) return; // let normal scroll bubble to page
136
+ e.preventDefault();
137
+ var direction = e.deltaY < 0 ? 1.1 : 0.9;
138
+ panZoom.zoomBy(direction);
139
+ }, { passive: false });
140
+
141
+ // Force fit after layout settles
142
+ setTimeout(function () {
143
+ panZoom.resize();
144
+ panZoom.fit();
145
+ panZoom.center();
146
+ }, 100);
147
+
148
+ // Zoom controls
149
+ zoomIn.addEventListener('click', function (e) {
150
+ e.preventDefault();
151
+ panZoom.zoomIn();
152
+ });
153
+ zoomOut.addEventListener('click', function (e) {
154
+ e.preventDefault();
155
+ panZoom.zoomOut();
156
+ });
157
+ resetBtn.addEventListener('click', function (e) {
158
+ e.preventDefault();
159
+ panZoom.resetZoom();
160
+ panZoom.resetPan();
161
+ panZoom.fit();
162
+ panZoom.center();
163
+ });
164
+
165
+ // Fullscreen toggle
166
+ var savedHeight = container.style.height;
167
+ fullscreenBtn.addEventListener('click', function (e) {
168
+ e.preventDefault();
169
+ var isFullscreen = container.classList.toggle('fullscreen');
170
+ fullscreenBtn.textContent = isFullscreen ? '\u2716' : '\u26F6';
171
+ fullscreenBtn.title = isFullscreen ? 'Exit fullscreen' : 'Fullscreen';
172
+ document.body.style.overflow = isFullscreen ? 'hidden' : '';
173
+ if (!isFullscreen) container.style.height = savedHeight;
174
+ setTimeout(function () {
175
+ panZoom.resize();
176
+ panZoom.fit();
177
+ panZoom.center();
178
+ }, 50);
179
+ });
180
+
181
+ // ESC to exit fullscreen
182
+ document.addEventListener('keydown', function (e) {
183
+ if (e.key === 'Escape' && container.classList.contains('fullscreen')) {
184
+ fullscreenBtn.click();
185
+ }
186
+ });
187
+
188
+ // Refit on window resize and container resize (draggable corner)
189
+ var resizeTimer;
190
+ var resizeHandler = function () {
191
+ clearTimeout(resizeTimer);
192
+ resizeTimer = setTimeout(function () {
193
+ panZoom.resize();
194
+ panZoom.fit();
195
+ panZoom.center();
196
+ }, 150);
197
+ };
198
+ window.addEventListener('resize', resizeHandler);
199
+ if (window.ResizeObserver) {
200
+ new ResizeObserver(resizeHandler).observe(container);
201
+ }
202
+ } catch (err) {
203
+ console.warn('docsify-mermaid-zoom: svg-pan-zoom init failed:', err);
204
+ }
205
+ });
206
+ }
207
+
208
+ // Docsify plugin registration
209
+ function mermaidZoomPlugin(hook) {
210
+ hook.doneEach(function () {
211
+ var config = getConfig();
212
+ setTimeout(initZoomContainers, config.renderDelay);
213
+ });
214
+ }
215
+
216
+ // Register
217
+ if (!window.$docsify) window.$docsify = {};
218
+ if (!window.$docsify.plugins) window.$docsify.plugins = [];
219
+ window.$docsify.plugins.push(mermaidZoomPlugin);
220
+ })();