@barzhsieh/nuxt-content-mermaid 2.2.3 → 3.0.2
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/README.md +47 -502
- package/README.zh-TW.md +46 -509
- package/dist/module.d.mts +39 -53
- package/dist/module.json +3 -3
- package/dist/module.mjs +600 -155
- package/dist/runtime/built-in-renderer/BuiltInRenderer.d.vue.ts +0 -0
- package/dist/runtime/built-in-renderer/BuiltInRenderer.vue +597 -0
- package/dist/runtime/built-in-renderer/BuiltInRenderer.vue.d.ts +0 -0
- package/dist/runtime/component-configuration-error.d.ts +3 -0
- package/dist/runtime/component-configuration-error.js +7 -0
- package/dist/runtime/component-configuration.d.ts +23 -0
- package/dist/runtime/component-configuration.js +78 -0
- package/dist/runtime/components/ContentMermaidTransport.d.vue.ts +10 -0
- package/dist/runtime/components/ContentMermaidTransport.vue +21 -0
- package/dist/runtime/components/ContentMermaidTransport.vue.d.ts +10 -0
- package/dist/runtime/components/Mermaid.d.vue.ts +0 -31
- package/dist/runtime/components/Mermaid.vue +136 -743
- package/dist/runtime/components/Mermaid.vue.d.ts +0 -31
- package/dist/runtime/components/MermaidExpandOverlay.d.vue.ts +13 -16
- package/dist/runtime/components/MermaidExpandOverlay.vue +61 -53
- package/dist/runtime/components/MermaidExpandOverlay.vue.d.ts +13 -16
- package/dist/runtime/components/MermaidFullscreenPresentation.d.vue.ts +18 -0
- package/dist/runtime/components/MermaidFullscreenPresentation.vue +56 -0
- package/dist/runtime/components/MermaidFullscreenPresentation.vue.d.ts +18 -0
- package/dist/runtime/composables/useMermaidExpand.d.ts +16 -32
- package/dist/runtime/composables/useMermaidExpand.js +232 -75
- package/dist/runtime/composables/useMermaidFullscreen.d.ts +18 -0
- package/dist/runtime/composables/useMermaidFullscreen.js +242 -0
- package/dist/runtime/composables/useMermaidZoom.d.ts +5 -1
- package/dist/runtime/composables/useMermaidZoom.js +54 -28
- package/dist/runtime/configuration/core.d.ts +27 -0
- package/dist/runtime/configuration/core.js +340 -0
- package/dist/runtime/configuration/module.d.ts +17 -0
- package/dist/runtime/configuration/module.js +233 -0
- package/dist/runtime/configuration/runtime-options.d.ts +4 -0
- package/dist/runtime/configuration/runtime-options.js +57 -0
- package/dist/runtime/constants.d.ts +24 -0
- package/dist/runtime/constants.js +60 -2
- package/dist/runtime/direct-mermaid-config.d.ts +5 -0
- package/dist/runtime/direct-mermaid-config.js +216 -0
- package/dist/runtime/mermaid-config.d.ts +9 -5
- package/dist/runtime/mermaid-config.js +30 -19
- package/dist/runtime/mermaid-rendering.d.ts +28 -0
- package/dist/runtime/mermaid-rendering.js +140 -0
- package/dist/runtime/plugins/content-mermaid-transport.d.ts +2 -0
- package/dist/runtime/plugins/content-mermaid-transport.js +5 -0
- package/dist/runtime/plugins/mermaid.client.d.ts +0 -3
- package/dist/runtime/plugins/mermaid.client.js +14 -32
- package/dist/runtime/plugins/runtime-config.d.ts +2 -0
- package/dist/runtime/plugins/runtime-config.js +9 -0
- package/dist/runtime/rendererSelection.d.ts +43 -0
- package/dist/runtime/rendererSelection.js +36 -0
- package/dist/runtime/rendererSelectionOrchestration.d.ts +12 -0
- package/dist/runtime/rendererSelectionOrchestration.js +13 -0
- package/dist/runtime/runtime-snapshot.d.ts +3 -0
- package/dist/runtime/runtime-snapshot.js +26 -0
- package/dist/runtime/utils/index.d.ts +0 -4
- package/dist/runtime/utils/index.js +0 -37
- package/dist/types.d.mts +2 -2
- package/package.json +38 -32
- package/dist/runtime/utils/mermaid-transform.d.ts +0 -18
- package/dist/runtime/utils/mermaid-transform.js +0 -345
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[English](./README.md) | [中文](./README.zh-TW.md)
|
|
2
2
|
|
|
3
|
-
[](https://
|
|
3
|
+
[](https://nuxt-content-mermaid.barz.app)
|
|
4
4
|
|
|
5
5
|
# nuxt-content-mermaid
|
|
6
6
|
|
|
@@ -11,539 +11,84 @@
|
|
|
11
11
|
[](https://mermaid.js.org/)
|
|
12
12
|
[](https://content.nuxt.com/)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
**@barzhsieh/nuxt-content-mermaid** turns `mermaid` code blocks in Nuxt
|
|
15
|
+
Content Markdown into responsive, interactive diagrams. It supports lazy
|
|
16
|
+
loading, light and dark themes, toolbar controls, and application-provided
|
|
17
|
+
rendering components.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
The [documentation website](https://nuxt-content-mermaid.barz.app) is the
|
|
20
|
+
canonical package documentation. This README is a bounded distribution summary
|
|
21
|
+
for npm and GitHub.
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
- **Performance friendly**: Supports lazy loading — Mermaid core and related resources are only loaded when the component mounts.
|
|
21
|
-
- **Theme integration**: Integrates with `@nuxtjs/color-mode` to automatically switch between light and dark Mermaid themes.
|
|
22
|
-
- **Highly customizable**: Allows custom wrapper components, loading spinners, error views, and custom CDN or local import sources.
|
|
23
|
-
- **Runtime config**: Settings can be overridden at deployment time through runtime config / environment variables.
|
|
23
|
+
## Package fit
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Use this module when your Nuxt Content application needs to:
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- author diagrams as Mermaid fences in Markdown;
|
|
28
|
+
- render diagrams in the browser with package-owned loading and error states;
|
|
29
|
+
- follow application light and dark modes;
|
|
30
|
+
- configure diagrams globally, per page, or per fence;
|
|
31
|
+
- opt into lazy rendering, toolbar controls, or custom rendering components.
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
The module owns its compatible Mermaid version. Applications own their Nuxt and
|
|
34
|
+
Nuxt Content peer dependencies and the Nuxt Content database connector.
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
## Compatibility
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
- Node.js `>=22.19.0`
|
|
39
|
+
- Nuxt `^4.1.0`
|
|
40
|
+
- Nuxt Content `>=3.5.0 <4.0.0`
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
For dependency ownership, the Nuxt Content v2 migration boundary, and rendering
|
|
43
|
+
guarantees, see the
|
|
44
|
+
[Dependency and Migration Contract](./docs/en/DEPENDENCY_AND_MIGRATION_CONTRACT.md).
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
## Quick start
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
Install the module and its Nuxt Content peer:
|
|
43
49
|
|
|
44
50
|
```bash
|
|
45
|
-
|
|
46
|
-
pnpm add -D @barzhsieh/nuxt-content-mermaid
|
|
47
|
-
|
|
48
|
-
# npm
|
|
49
|
-
npm install -D @barzhsieh/nuxt-content-mermaid
|
|
50
|
-
|
|
51
|
-
# yarn
|
|
52
|
-
yarn add -D @barzhsieh/nuxt-content-mermaid
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 2. Configure `nuxt.config.ts`
|
|
56
|
-
|
|
57
|
-
Make sure the module is included in the `modules` array (skip if you used `nuxi module add`):
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
export default defineNuxtConfig({
|
|
61
|
-
modules: ["@barzhsieh/nuxt-content-mermaid", "@nuxt/content"],
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 3. Use Mermaid in Markdown
|
|
66
|
-
|
|
67
|
-
Add Mermaid code blocks inside `.md` files under the `content/` directory:
|
|
68
|
-
|
|
69
|
-
````markdown
|
|
70
|
-
# Flowchart example
|
|
71
|
-
|
|
72
|
-
```mermaid
|
|
73
|
-
graph LR
|
|
74
|
-
A[Start] --> B{Is it working?}
|
|
75
|
-
B -- Yes --> C[Great!]
|
|
76
|
-
B -- No --> D[Debug]
|
|
51
|
+
pnpm add @barzhsieh/nuxt-content-mermaid @nuxt/content
|
|
77
52
|
```
|
|
78
|
-
````
|
|
79
|
-
|
|
80
|
-
The module will automatically transform the block into an SVG chart component.
|
|
81
|
-
|
|
82
|
-
## Configuration
|
|
83
53
|
|
|
84
|
-
|
|
85
|
-
(`mermaidContent` is still accepted for backward compatibility, but will be removed in a future release.)
|
|
54
|
+
Register the module:
|
|
86
55
|
|
|
87
56
|
```ts
|
|
88
|
-
// nuxt.config.ts
|
|
89
57
|
export default defineNuxtConfig({
|
|
90
|
-
|
|
91
|
-
enabled: true,
|
|
92
|
-
loader: {
|
|
93
|
-
init: {
|
|
94
|
-
securityLevel: "strict",
|
|
95
|
-
// additional options passed to mermaid.initialize()
|
|
96
|
-
},
|
|
97
|
-
lazy: true,
|
|
98
|
-
},
|
|
99
|
-
theme: {
|
|
100
|
-
light: "default",
|
|
101
|
-
dark: "dark",
|
|
102
|
-
},
|
|
103
|
-
components: {
|
|
104
|
-
renderer: undefined,
|
|
105
|
-
spinner: undefined,
|
|
106
|
-
error: undefined,
|
|
107
|
-
},
|
|
108
|
-
toolbar: {
|
|
109
|
-
title: "mermaid",
|
|
110
|
-
fontSize: "14px",
|
|
111
|
-
fullscreenToolbarScale: 1.25,
|
|
112
|
-
buttons: {
|
|
113
|
-
copy: true,
|
|
114
|
-
fullscreen: true,
|
|
115
|
-
expand: true,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
expand: {
|
|
119
|
-
enabled: true,
|
|
120
|
-
margin: 0,
|
|
121
|
-
invokeOpenOn: {
|
|
122
|
-
diagramClick: true,
|
|
123
|
-
},
|
|
124
|
-
invokeCloseOn: {
|
|
125
|
-
esc: true,
|
|
126
|
-
wheel: true,
|
|
127
|
-
swipe: true,
|
|
128
|
-
overlayClick: true,
|
|
129
|
-
closeButtonClick: true,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Options
|
|
137
|
-
|
|
138
|
-
**Top-level**
|
|
139
|
-
|
|
140
|
-
| Option | Type | Default | Description |
|
|
141
|
-
| :-------- | :-------- | :------ | :--------------------------------------------------- |
|
|
142
|
-
| `enabled` | `boolean` | `true` | Whether the module and its conversion logic are on. |
|
|
143
|
-
| `debug` | `boolean` | `false` | Enable verbose diagnostics; see Debug section below. |
|
|
144
|
-
|
|
145
|
-
**loader**
|
|
146
|
-
|
|
147
|
-
| Option | Type | Default | Description |
|
|
148
|
-
| :---------------- | :------------------------------------ | :--------------------- | :------------------------------------------------------------------------------- |
|
|
149
|
-
| `loader.init` | `MermaidConfig` | `{ startOnLoad: false }` | Raw options object passed to `mermaid.initialize`. |
|
|
150
|
-
| `loader.lazy` | `boolean \| { threshold?: number }` | `true` | Lazy load Mermaid when the component enters the viewport; set `false` to preload. |
|
|
151
|
-
|
|
152
|
-
**theme**
|
|
153
|
-
|
|
154
|
-
Color mode integration is automatic when `@nuxtjs/color-mode` is installed; manual themes set via `useMermaidTheme()` take precedence.
|
|
155
|
-
|
|
156
|
-
| Option | Type | Default | Description |
|
|
157
|
-
| :---------------- | :----- | :---------- | :------------------------------------------------------------------------------------------ |
|
|
158
|
-
| `theme.light` | string | `'default'` | Mermaid theme to use when color mode is light (and as fallback when color-mode is missing). |
|
|
159
|
-
| `theme.dark` | string | `'dark'` | Mermaid theme to use when color mode is dark (and as fallback when color-mode is missing). |
|
|
160
|
-
|
|
161
|
-
**components**
|
|
162
|
-
|
|
163
|
-
| Option | Type | Default | Description |
|
|
164
|
-
| :------------------------ | :------- | :---------- | :----------------------------------------------------------------------- |
|
|
165
|
-
| `components.renderer` | `string` | `undefined` | Optional: custom Mermaid renderer component name. |
|
|
166
|
-
| `components.spinner` | `string` | `undefined` | Optional: global loading spinner component name. |
|
|
167
|
-
| `components.error` | `string` | `undefined` | Optional: global error component name when Mermaid rendering fails. |
|
|
168
|
-
|
|
169
|
-
**toolbar**
|
|
170
|
-
|
|
171
|
-
| Option | Type | Default | Description |
|
|
172
|
-
| :------------------------- | :----------------- | :------ | :------------------------------------------ |
|
|
173
|
-
| `toolbar.title` | `string` | `'mermaid'` | Default toolbar title for Mermaid blocks. |
|
|
174
|
-
| `toolbar.fontSize` | `string \| number` | `'14px'` | Default toolbar font size. |
|
|
175
|
-
| `toolbar.fullscreenToolbarScale` | `number` | `1.25` | Scale factor for toolbar font/icon size in fullscreen. |
|
|
176
|
-
| `toolbar.buttons.copy` | `boolean` | `true` | Show copy-source button in the toolbar. |
|
|
177
|
-
| `toolbar.buttons.fullscreen` | `boolean` | `true` | Show fullscreen button in the toolbar. |
|
|
178
|
-
| `toolbar.buttons.expand` | `boolean` | `true` | Show expand button in the toolbar. |
|
|
179
|
-
|
|
180
|
-
**expand**
|
|
181
|
-
|
|
182
|
-
Control SVG expand interactions. You can also set `expand: false` to disable it, or `expand: true` to use defaults.
|
|
183
|
-
|
|
184
|
-
| Option | Type | Default | Description |
|
|
185
|
-
| :------------------------- | :-------- | :------ | :------------------------------------------------------------------------- |
|
|
186
|
-
| `expand.enabled` | `boolean` | `true` | Enable or disable expand features entirely. |
|
|
187
|
-
| `expand.margin` | `number` | `0` | Margin (px) around the expanded SVG within the viewport. |
|
|
188
|
-
| `expand.invokeOpenOn.diagramClick` | `boolean` | `true` | Allow clicking the SVG to open expand overlay. |
|
|
189
|
-
| `expand.invokeCloseOn.esc` | `boolean` | `true` | Allow Escape key to close. |
|
|
190
|
-
| `expand.invokeCloseOn.wheel` | `boolean` | `true` | Allow mouse wheel to close. |
|
|
191
|
-
| `expand.invokeCloseOn.swipe` | `boolean` | `true` | Allow swipe gesture to close. |
|
|
192
|
-
| `expand.invokeCloseOn.overlayClick` | `boolean` | `true` | Allow clicking the overlay background to close. |
|
|
193
|
-
| `expand.invokeCloseOn.closeButtonClick`| `boolean`| `true` | Show the overlay close button. |
|
|
194
|
-
|
|
195
|
-
**Pan & Zoom (Expand Overlay / Fullscreen)**
|
|
196
|
-
|
|
197
|
-
When fullscreen or expand mode is active, users can pan and zoom the diagram:
|
|
198
|
-
|
|
199
|
-
| Interaction | Desktop | Mobile |
|
|
200
|
-
|:---|:---|:---|
|
|
201
|
-
| **Pan** | `Space` + Drag | 1-finger Drag |
|
|
202
|
-
| **Zoom** | `Ctrl/⌘` + Scroll | 2-finger Pinch |
|
|
203
|
-
| **Keyboard** | `+`/`-` to zoom, Arrow keys to pan, `0` to reset | — |
|
|
204
|
-
|
|
205
|
-
A zoom toolbar appears with +/−/Reset buttons and a percentage display.
|
|
206
|
-
|
|
207
|
-
Use `toolbar.fullscreenToolbarScale` to scale the fullscreen toolbar and zoom controls.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
> **Note**: All options can be overridden at runtime via `runtimeConfig.public.contentMermaid` (`runtimeConfig.public.mermaidContent` remains supported but deprecated).
|
|
211
|
-
|
|
212
|
-
## Styling (CSS Variables)
|
|
213
|
-
|
|
214
|
-
This module ships global CSS variables (from `runtime/styles.css`) so the Mermaid wrapper and expand overlay share the same palette. You can override them in your app:
|
|
215
|
-
|
|
216
|
-
```css
|
|
217
|
-
:root {
|
|
218
|
-
--ncm-code-bg: #f3f4f6;
|
|
219
|
-
--ncm-code-bg-hover: #e5e7eb;
|
|
220
|
-
--ncm-border: #e5e7eb;
|
|
221
|
-
--ncm-text: #111827;
|
|
222
|
-
--ncm-text-muted: #4b5563;
|
|
223
|
-
--ncm-text-xmuted: #6b7280;
|
|
224
|
-
--ncm-overlay-bg: rgba(255, 255, 255, 0.98);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
html[data-theme="dark"],
|
|
228
|
-
.dark {
|
|
229
|
-
--ncm-code-bg: #111827;
|
|
230
|
-
--ncm-code-bg-hover: #1f2937;
|
|
231
|
-
--ncm-border: #1f2937;
|
|
232
|
-
--ncm-text: #f9fafb;
|
|
233
|
-
--ncm-text-muted: #9ca3af;
|
|
234
|
-
--ncm-text-xmuted: #6b7280;
|
|
235
|
-
--ncm-overlay-bg: rgba(17, 24, 39, 0.98);
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
Variables:
|
|
240
|
-
- `--ncm-code-bg`: Mermaid block background.
|
|
241
|
-
- `--ncm-code-bg-hover`: Hover background for toolbar buttons.
|
|
242
|
-
- `--ncm-border-color`: Border color for the block and toolbar.
|
|
243
|
-
- `--ncm-border-width`: Border thickness.
|
|
244
|
-
- `--ncm-border-style`: Border style.
|
|
245
|
-
- `--ncm-border`: Composite shorthand (width, style, color) for borders.
|
|
246
|
-
- `--ncm-border-bottom`: Border style applied to the toolbar bottom.
|
|
247
|
-
- `--ncm-text`: Primary text color.
|
|
248
|
-
- `--ncm-text-muted`: Title and secondary text.
|
|
249
|
-
- `--ncm-text-xmuted`: Toolbar icon and subtle UI text.
|
|
250
|
-
- `--ncm-overlay-bg`: Expand overlay background (defaults to `--ncm-code-bg`).
|
|
251
|
-
- `--ncm-expand-target-bg`: Background color shown behind the expanded SVG when `expand.margin` leaves breathing room.
|
|
252
|
-
- `--ncm-overlay-opacity`: Overlay transparency (thinned when `expand.margin` creates breathing room).
|
|
253
|
-
- `--ncm-overlay-backdrop`: `backdrop-filter` applied to the overlay when it becomes visible.
|
|
254
|
-
- `--ncm-hint-bg`: Zoom hint toast background (default: `rgba(0,0,0,0.75)`).
|
|
255
|
-
- `--ncm-hint-text`: Zoom hint toast text color (default: `#fff`).
|
|
256
|
-
- `--ncm-hint-radius`: Zoom hint toast border radius (default: `8px`).
|
|
257
|
-
|
|
258
|
-
## Advanced Usage
|
|
259
|
-
|
|
260
|
-
### Debug mode
|
|
261
|
-
|
|
262
|
-
**`contentMermaid.debug`** (default `false`):
|
|
263
|
-
- **Auto-config**: If you did **not** set `loader.init.logLevel` or `suppressErrorRendering`, debug defaults them to `logLevel: 1` and `suppressErrorRendering: false` (Mermaid shows errors in the DOM). If you set them explicitly, your values win.
|
|
264
|
-
- **Runtime behavior**:
|
|
265
|
-
- **Debug on**: `mermaid.run` uses `suppressErrors: false`, errors throw with full stack traces for debugging.
|
|
266
|
-
- **Debug off**: `mermaid.run` uses `suppressErrors: true`, so one failing chart won't block others.
|
|
267
|
-
- **Console output**: Adds queue diagnostics and render-time stats.
|
|
268
|
-
|
|
269
|
-
### Theme & Color Mode
|
|
270
|
-
|
|
271
|
-
The module determines the active Mermaid theme with the following priority:
|
|
272
|
-
|
|
273
|
-
1. Frontmatter `config.theme` (per-page override)
|
|
274
|
-
2. Manual mode via `useMermaidTheme()` (if set)
|
|
275
|
-
3. `@nuxtjs/color-mode` (auto-detected when installed):
|
|
276
|
-
- `dark` → `theme.dark`
|
|
277
|
-
- `light` → `theme.light`
|
|
278
|
-
4. `loader.init.theme` (if provided)
|
|
279
|
-
5. Fallback: `theme.light`, then Mermaid default `'default'`
|
|
280
|
-
|
|
281
|
-
For advanced manual control (e.g., forcing specific themes, custom toggle logic), please refer to the [Manual Theme Control Guide](./docs/en/MANUAL_THEME_CONTROL.md).
|
|
282
|
-
|
|
283
|
-
### Override Per-Page Settings with Frontmatter
|
|
284
|
-
|
|
285
|
-
Each Markdown file can override module settings by adding a `config` field in the frontmatter.
|
|
286
|
-
|
|
287
|
-
> **⚠️ To use frontmatter `config` overrides, you MUST declare the `config` field in your collection schema in `content.config.ts`.**
|
|
288
|
-
> Without this, Nuxt Content will not parse the `config` field as a JSON object, and your overrides will not work.
|
|
289
|
-
|
|
290
|
-
Add this to your `content.config.ts`:
|
|
291
|
-
|
|
292
|
-
```ts
|
|
293
|
-
import { defineContentConfig, defineCollection, z } from '@nuxt/content'
|
|
294
|
-
|
|
295
|
-
export default defineContentConfig({
|
|
296
|
-
collections: {
|
|
297
|
-
content: defineCollection({
|
|
298
|
-
type: 'page',
|
|
299
|
-
source: '**',
|
|
300
|
-
schema: z.object({
|
|
301
|
-
config: z.record(z.unknown()).optional(), // ← Declare config field
|
|
302
|
-
}).passthrough(),
|
|
303
|
-
}),
|
|
304
|
-
},
|
|
58
|
+
modules: ['@barzhsieh/nuxt-content-mermaid'],
|
|
305
59
|
})
|
|
306
60
|
```
|
|
307
61
|
|
|
308
|
-
Then
|
|
62
|
+
Then add a Mermaid fence to a Content Markdown file:
|
|
309
63
|
|
|
310
64
|
````markdown
|
|
311
|
-
---
|
|
312
|
-
title: Example of Overriding Mermaid Settings Per Page
|
|
313
|
-
config:
|
|
314
|
-
theme: forest
|
|
315
|
-
flowchart:
|
|
316
|
-
htmlLabels: false
|
|
317
|
-
---
|
|
318
65
|
```mermaid
|
|
319
66
|
flowchart LR
|
|
320
|
-
|
|
67
|
+
Markdown --> Content --> Mermaid --> SVG
|
|
321
68
|
```
|
|
322
69
|
````
|
|
323
70
|
|
|
324
|
-
|
|
71
|
+
Mermaid is included by the module and does not need to be installed separately.
|
|
72
|
+
For database connector choices and a complete first-project walkthrough, follow
|
|
73
|
+
[Getting Started](https://nuxt-content-mermaid.barz.app/getting-started).
|
|
325
74
|
|
|
326
|
-
|
|
327
|
-
````markdown
|
|
328
|
-
```mermaid
|
|
329
|
-
%%{init: { 'theme': 'forest', 'flowchart': { 'curve': 'step' } }}%%
|
|
330
|
-
graph TD
|
|
331
|
-
A[Input] --> B{Valid?}
|
|
332
|
-
B -- Yes --> C[Persist]
|
|
333
|
-
B -- No --> D[Error]
|
|
334
|
-
```
|
|
335
|
-
````
|
|
75
|
+
## Canonical package documentation
|
|
336
76
|
|
|
337
|
-
|
|
77
|
+
- [Getting Started](https://nuxt-content-mermaid.barz.app/getting-started)
|
|
78
|
+
- [Writing Diagrams](https://nuxt-content-mermaid.barz.app/writing-diagrams)
|
|
79
|
+
- [Configuration](https://nuxt-content-mermaid.barz.app/configuration)
|
|
80
|
+
- [Troubleshooting](https://nuxt-content-mermaid.barz.app/troubleshooting)
|
|
81
|
+
- [Migration to v3](https://nuxt-content-mermaid.barz.app/migration/v3)
|
|
338
82
|
|
|
339
|
-
|
|
83
|
+
## Support and contribution
|
|
340
84
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
3. **Module-level `contentMermaid.loader.init`** — Project default settings.
|
|
344
|
-
|
|
345
|
-
### Mermaid Inline Attributes & YAML Frontmatter
|
|
346
|
-
|
|
347
|
-
You can control Mermaid blocks in three ways: inline attrs, Mermaid YAML frontmatter, and `%%{init}%%` directives.
|
|
348
|
-
|
|
349
|
-
#### Inline attrs (fence info)
|
|
350
|
-
|
|
351
|
-
Use inline attrs on the `mermaid` fence to pass props to the wrapper component or set Mermaid YAML fields (including `toolbar` options like title/fontSize and `toolbar.buttons.*`).
|
|
352
|
-
|
|
353
|
-
````markdown
|
|
354
|
-
```mermaid {title="Diagram A" toolbar='{"title":"My Diagram","fontSize":"14px"}' config='{"theme":"dark"}'}
|
|
355
|
-
graph TD
|
|
356
|
-
A --> B
|
|
357
|
-
```
|
|
358
|
-
````
|
|
359
|
-
|
|
360
|
-
#### Mermaid YAML frontmatter (inside the block)
|
|
361
|
-
|
|
362
|
-
Place Mermaid’s own YAML frontmatter at the top of the code block to affect SVG rendering (e.g. title, displayMode, config), and you can also provide `toolbar` values for the wrapper component (including `toolbar.buttons.copy: true`).
|
|
363
|
-
|
|
364
|
-
````markdown
|
|
365
|
-
```mermaid
|
|
366
|
-
---
|
|
367
|
-
title: Sample Flowchart
|
|
368
|
-
displayMode: compact
|
|
369
|
-
config:
|
|
370
|
-
theme: dark
|
|
371
|
-
toolbar:
|
|
372
|
-
title: "Sample Diagram"
|
|
373
|
-
buttons:
|
|
374
|
-
copy: true
|
|
375
|
-
---
|
|
376
|
-
graph TD
|
|
377
|
-
A --> B
|
|
378
|
-
```
|
|
379
|
-
````
|
|
380
|
-
|
|
381
|
-
#### `%%{init}%%` directive (inside the block)
|
|
382
|
-
|
|
383
|
-
Use Mermaid directives to set render options directly in the diagram definition.
|
|
384
|
-
|
|
385
|
-
````markdown
|
|
386
|
-
```mermaid
|
|
387
|
-
%%{init: { 'theme': 'forest', 'flowchart': { 'curve': 'step' } }}%%
|
|
388
|
-
graph TD
|
|
389
|
-
A --> B
|
|
390
|
-
```
|
|
391
|
-
````
|
|
392
|
-
|
|
393
|
-
### Custom Rendering Component
|
|
394
|
-
|
|
395
|
-
If you want full control over rendering (for example to add a border, expand controls, or other UI), you can provide a custom component via `components.renderer`.
|
|
396
|
-
|
|
397
|
-
1. Specify the component name in `nuxt.config.ts`:
|
|
398
|
-
|
|
399
|
-
```ts
|
|
400
|
-
contentMermaid: {
|
|
401
|
-
components: {
|
|
402
|
-
renderer: "MyCustomMermaid",
|
|
403
|
-
},
|
|
404
|
-
}
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
2. Implement the component in `components/MyCustomMermaid.vue`:
|
|
408
|
-
|
|
409
|
-
```vue
|
|
410
|
-
<script setup lang="ts">
|
|
411
|
-
// You can consume slot content or invoke useMermaid() logic here
|
|
412
|
-
</script>
|
|
413
|
-
|
|
414
|
-
<template>
|
|
415
|
-
<div class="custom-wrapper border rounded p-4">
|
|
416
|
-
<Mermaid>
|
|
417
|
-
<slot />
|
|
418
|
-
</Mermaid>
|
|
419
|
-
</div>
|
|
420
|
-
</template>
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
#### Loading Indicator
|
|
424
|
-
|
|
425
|
-
The module renders a built-in spinner before the first Mermaid render. If you set `components.spinner`, the named component will replace the default spinner and will be passed into your custom renderer as a `spinner` prop.
|
|
426
|
-
|
|
427
|
-
Minimal example that uses the provided spinner while waiting for your own loading logic:
|
|
428
|
-
|
|
429
|
-
```ts
|
|
430
|
-
// nuxt.config.ts
|
|
431
|
-
export default defineNuxtConfig({
|
|
432
|
-
contentMermaid: {
|
|
433
|
-
components: {
|
|
434
|
-
renderer: 'MyCustomMermaid',
|
|
435
|
-
spinner: 'MySpinner', // optional: globally replace the default spinner
|
|
436
|
-
},
|
|
437
|
-
},
|
|
438
|
-
})
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
```vue
|
|
442
|
-
<!-- components/MyCustomMermaid.vue -->
|
|
443
|
-
<script setup lang="ts">
|
|
444
|
-
import { ref, onMounted } from 'vue'
|
|
445
|
-
import type { Component } from 'vue'
|
|
446
|
-
|
|
447
|
-
const props = defineProps<{ spinner: Component | string }>()
|
|
448
|
-
const loading = ref(true)
|
|
449
|
-
onMounted(() => { loading.value = false })
|
|
450
|
-
</script>
|
|
451
|
-
|
|
452
|
-
<template>
|
|
453
|
-
<div class="my-mermaid">
|
|
454
|
-
<component v-if="loading" :is="props.spinner" />
|
|
455
|
-
<Mermaid v-else>
|
|
456
|
-
<slot />
|
|
457
|
-
</Mermaid>
|
|
458
|
-
</div>
|
|
459
|
-
</template>
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Wrapper Example
|
|
463
|
-
|
|
464
|
-
You can wrap `<Mermaid>` inside your own Vue component.
|
|
465
|
-
For example, you can bundle a title, loading state, and error/fallback UI, then drop it anywhere in templates:
|
|
466
|
-
|
|
467
|
-
```vue
|
|
468
|
-
<!-- WrapperMermaid.vue -->
|
|
469
|
-
<template>
|
|
470
|
-
<section>
|
|
471
|
-
<header v-if="title">{{ title }}</header>
|
|
472
|
-
|
|
473
|
-
<Mermaid>
|
|
474
|
-
<slot>
|
|
475
|
-
<pre><code>{{ code }}</code></pre>
|
|
476
|
-
</slot>
|
|
477
|
-
|
|
478
|
-
<template #loading>
|
|
479
|
-
<component :is="spinner" v-if="spinner" />
|
|
480
|
-
<p v-else>Diagram loading…</p>
|
|
481
|
-
</template>
|
|
482
|
-
|
|
483
|
-
<template #error="{ error, source }">
|
|
484
|
-
<p>Render failed: {{ error instanceof Error ? error.message : String(error) }}</p>
|
|
485
|
-
<pre><code>{{ source }}</code></pre>
|
|
486
|
-
</template>
|
|
487
|
-
</Mermaid>
|
|
488
|
-
</section>
|
|
489
|
-
</template>
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
```vue
|
|
493
|
-
<!-- usage -->
|
|
494
|
-
<WrapperMermaid
|
|
495
|
-
title="Demo Diagram"
|
|
496
|
-
spinner="MySpinner"
|
|
497
|
-
>
|
|
498
|
-
<pre><code>graph TD; A-->B; B-->C; C-->A</code></pre>
|
|
499
|
-
</WrapperMermaid>
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
Copy or adapt this pattern to centralize the common slots you want to reuse.
|
|
503
|
-
|
|
504
|
-
### Error Handling
|
|
505
|
-
|
|
506
|
-
When Mermaid parsing/rendering fails, the component exposes an `error` slot and supports a global error component via `components.error`. Both receive the thrown error and the original Mermaid source for inspection.
|
|
507
|
-
|
|
508
|
-
```vue
|
|
509
|
-
<Mermaid>
|
|
510
|
-
<pre><code>graph TD; A-->B; B-->C; C-->A</code></pre>
|
|
511
|
-
|
|
512
|
-
<template #error="{ error, source }">
|
|
513
|
-
<p>Render failed: {{ error instanceof Error ? error.message : String(error) }}</p>
|
|
514
|
-
<details>
|
|
515
|
-
<summary>Show definition</summary>
|
|
516
|
-
<pre><code>{{ source }}</code></pre>
|
|
517
|
-
</details>
|
|
518
|
-
</template>
|
|
519
|
-
</Mermaid>
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
To reuse a global error view everywhere, register it once and reference it in config:
|
|
523
|
-
|
|
524
|
-
```ts
|
|
525
|
-
// nuxt.config.ts
|
|
526
|
-
export default defineNuxtConfig({
|
|
527
|
-
contentMermaid: {
|
|
528
|
-
components: {
|
|
529
|
-
error: 'MermaidError', // globally registered component name
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
})
|
|
533
|
-
```
|
|
534
|
-
## Contribution
|
|
535
|
-
|
|
536
|
-
<details>
|
|
537
|
-
<summary>Local Development Commands</summary>
|
|
538
|
-
|
|
539
|
-
```bash
|
|
540
|
-
pnpm install
|
|
541
|
-
pnpm dev:prepare
|
|
542
|
-
pnpm dev # Run playground
|
|
543
|
-
pnpm test # Run tests
|
|
544
|
-
```
|
|
85
|
+
If the module is useful to you, you can
|
|
86
|
+
[support my open-source work on Ko-fi](https://ko-fi.com/barzhsieh).
|
|
545
87
|
|
|
546
|
-
|
|
88
|
+
Contributions are welcome. Open an
|
|
89
|
+
[issue](https://github.com/andy820621/nuxt-content-mermaid/issues) or submit a
|
|
90
|
+
pull request with a clear summary and test results. Maintainers should follow
|
|
91
|
+
the [stable release runbook](./docs/en/RELEASING.md).
|
|
547
92
|
|
|
548
93
|
## License
|
|
549
94
|
|