@barzhsieh/nuxt-content-mermaid 3.0.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  [English](./README.md) | [中文](./README.zh-TW.md)
2
2
 
3
- [![nuxt-content-social-card](https://raw.githubusercontent.com/andy820621/nuxt-content-mermaid/main/src/assets/nuxt-content-mermaid.webp)](https://www.npmjs.com/package/@barzhsieh/nuxt-content-mermaid)
3
+ [![nuxt-content-social-card](https://raw.githubusercontent.com/andy820621/nuxt-content-mermaid/main/src/assets/nuxt-content-mermaid.webp)](https://nuxt-content-mermaid.barz.app)
4
4
 
5
5
  # nuxt-content-mermaid
6
6
 
@@ -11,639 +11,84 @@
11
11
  [![Mermaid](https://img.shields.io/badge/mermaid-11.x-0f5b9d?logo=mermaid)](https://mermaid.js.org/)
12
12
  [![Nuxt Content](https://img.shields.io/badge/Nuxt%20Content-3.x-00DC82?logo=nuxt.js)](https://content.nuxt.com/)
13
13
 
14
- A Nuxt module designed for integrating [**Mermaid**](https://mermaid.js.org/) with [**Nuxt Content v3**](https://content.nuxt.com/docs/getting-started).
15
- It automatically converts `mermaid` code blocks in Markdown into responsive chart components, and supports lazy loading and dark/light theme switching.
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
- <details>
18
- <summary>Table of Contents</summary>
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.
19
22
 
20
- - [Features](#features)
21
- - [Requirements](#requirements)
22
- - [Dependency and Migration Contract](./docs/en/DEPENDENCY_AND_MIGRATION_CONTRACT.md)
23
- - [Quick Setup](#quick-setup)
24
- - [Configuration](#configuration)
25
- - [Migrating to v3](#migrating-to-v3)
26
- - [Styling (CSS Variables)](#styling-css-variables)
27
- - [Advanced Usage](#advanced-usage)
28
- - [Debug mode](#debug-mode)
29
- - [Theme & Color Mode](#theme--color-mode)
30
- - [Override Per-Page Settings with Frontmatter](#override-per-page-settings-with-frontmatter)
31
- - [Mermaid Inline Attributes & YAML Frontmatter](#mermaid-inline-attributes--yaml-frontmatter)
32
- - [Custom Rendering Component](#custom-rendering-component)
33
- - [Wrapper Example](#wrapper-example)
34
- - [Error Handling](#error-handling)
35
- - [Support](#support)
36
- - [Contribution](#contribution)
37
- - [License](#license)
23
+ ## Package fit
38
24
 
39
- </details>
25
+ Use this module when your Nuxt Content application needs to:
40
26
 
41
- ## Features
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.
42
32
 
43
- - **Automatic conversion**: Parses Markdown code blocks and replaces them with a `<Mermaid>` rendering component.
44
- - **Performance friendly**: Supports lazy loading — Mermaid core and related resources are only loaded when the component mounts.
45
- - **Theme integration**: Integrates with `@nuxtjs/color-mode` to automatically switch between light and dark Mermaid themes.
46
- - **Highly customizable**: Supports custom renderers, loading spinners, error views, themes, and toolbar controls.
47
- - **Deployment configuration**: Pure-data settings can be transported through public runtime config and are resolved once for each Nuxt application.
33
+ The module owns its compatible Mermaid version. Applications own their Nuxt and
34
+ Nuxt Content peer dependencies and the Nuxt Content database connector.
48
35
 
49
- ## Requirements
36
+ ## Compatibility
50
37
 
51
38
  - Node.js `>=22.19.0`
52
- - `nuxt@^4.1.0`
53
- - `@nuxt/content@>=3.5.0 <4.0.0`
54
-
55
- For the ownership model, 2.x migration path, rendering guarantees, and visual
56
- snapshot limits, see the [Dependency and Migration Contract](./docs/en/DEPENDENCY_AND_MIGRATION_CONTRACT.md).
39
+ - Nuxt `^4.1.0`
40
+ - Nuxt Content `>=3.5.0 <4.0.0`
57
41
 
58
- ## Quick Setup
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).
59
45
 
60
- ### 1. Install the packages
46
+ ## Quick start
61
47
 
62
- Package-manager installation and Nuxt module initialization are separate
63
- steps. Your application owns the Nuxt and Nuxt Content peer dependencies, so it
64
- must install, pin, and update them. Install this module together with the
65
- supported Nuxt Content peer:
48
+ Install the module and its Nuxt Content peer:
66
49
 
67
50
  ```bash
68
- # pnpm
69
51
  pnpm add @barzhsieh/nuxt-content-mermaid @nuxt/content
70
-
71
- # npm
72
- npm install @barzhsieh/nuxt-content-mermaid @nuxt/content
73
-
74
- # yarn
75
- yarn add @barzhsieh/nuxt-content-mermaid @nuxt/content
76
- ```
77
-
78
- Mermaid is bundled as this module's Module-Owned Dependency, so you do not need
79
- to install it separately for this module.
80
-
81
- > [!NOTE]
82
- > **Nuxt Content database connector** — On Node.js, Nuxt Content asks the
83
- > application to choose a database connector. `better-sqlite3`, `sqlite3`, and
84
- > native SQLite in supported Node.js versions are available choices; this
85
- > module does not require or own a specific connector. Follow the
86
- > [Nuxt Content installation guide](https://content.nuxt.com/docs/getting-started/installation)
87
- > for the options supported by your installed version.
88
- >
89
- > **pnpm v10+** — If you choose `better-sqlite3` or `sqlite3`, pnpm v10 blocks
90
- > their native build scripts by default. Run `pnpm approve-builds`, or allow
91
- > only the connector you selected in `package.json`. The example below uses
92
- > `better-sqlite3`; replace it with `sqlite3` when that is your connector:
93
- >
94
- > ```json
95
- > {
96
- > "pnpm": {
97
- > "onlyBuiltDependencies": ["better-sqlite3"]
98
- > }
99
- > }
100
- > ```
101
-
102
- ### 2. Initialize the Nuxt module
103
-
104
- List only this module in the standard `modules` configuration:
105
-
106
- ```ts
107
- export default defineNuxtConfig({
108
- modules: ["@barzhsieh/nuxt-content-mermaid"],
109
- });
110
- ```
111
-
112
- The module declares the required Nuxt Content relationship and compatible
113
- version through `moduleDependencies`, so Nuxt initializes the installed
114
- `@nuxt/content` module in the required order. This does not install, pin, or
115
- update Nuxt Content; those package-manager responsibilities remain with your
116
- application.
117
-
118
- If your application already lists `@nuxt/content` manually in `modules`, you
119
- may keep that entry. Manual listing remains supported, but it is no longer the
120
- standard configuration.
121
-
122
- ### 3. Use Mermaid in Markdown
123
-
124
- Add Mermaid code blocks inside `.md` files under the `content/` directory:
125
-
126
- ````markdown
127
- # Flowchart example
128
-
129
- ```mermaid
130
- graph LR
131
- A[Start] --> B{Is it working?}
132
- B -- Yes --> C[Great!]
133
- B -- No --> D[Debug]
134
52
  ```
135
- ````
136
-
137
- The module will automatically transform the block into an SVG chart component.
138
-
139
- ## Configuration
140
53
 
141
- Configure the module globally through the canonical `contentMermaid` option. The former `mermaidContent` alias was removed in v3 and produces a migration error.
54
+ Register the module:
142
55
 
143
56
  ```ts
144
- // nuxt.config.ts
145
57
  export default defineNuxtConfig({
146
- contentMermaid: {
147
- enabled: true,
148
- loader: {
149
- init: {
150
- securityLevel: "strict",
151
- // additional options passed to mermaid.initialize()
152
- },
153
- lazy: true,
154
- },
155
- theme: {
156
- light: "default",
157
- dark: "dark",
158
- },
159
- toolbar: {
160
- title: "mermaid",
161
- fontSize: "14px",
162
- fullscreenToolbarScale: 1.25,
163
- buttons: {
164
- copy: true,
165
- fullscreen: true,
166
- expand: true,
167
- },
168
- },
169
- expand: {
170
- enabled: true,
171
- margin: 0,
172
- invokeOpenOn: {
173
- diagramClick: true,
174
- },
175
- invokeCloseOn: {
176
- esc: true,
177
- wheel: true,
178
- swipe: true,
179
- overlayClick: true,
180
- closeButtonClick: true,
181
- },
182
- },
183
- },
184
- });
185
- ```
186
-
187
- ### Options
188
-
189
- **Top-level**
190
-
191
- | Option | Type | Default | Description |
192
- | :-------- | :-------- | :------ | :--------------------------------------------------- |
193
- | `enabled` | `boolean` | `true` | Whether the module and its conversion logic are on. |
194
- | `debug` | `boolean` | `false` | Enable verbose diagnostics; see Debug section below. |
195
-
196
- **loader**
197
-
198
- | Option | Type | Default | Description |
199
- | :---------------- | :------------------------------------ | :--------------- | :------------------------------------------------------------------------------- |
200
- | `loader.init` | `RuntimeMermaidConfig` (strict pure data) | package defaults | Pure-data Mermaid options transported to `mermaid.initialize`. |
201
- | `loader.lazy` | `boolean \| { threshold?: number }` | `true` | Lazy load Mermaid when the component enters the viewport; set `false` to preload. |
202
-
203
- The `loader.init` baseline is:
204
-
205
- ```ts
206
- {
207
- startOnLoad: false,
208
- theme: 'default',
209
- fontFamily: 'Arial, sans-serif, 微軟正黑體',
210
- securityLevel: 'strict',
211
- }
212
- ```
213
-
214
- When omitted, debug-derived values resolve to `logLevel: 5` and
215
- `suppressErrorRendering: true` with `debug: false`, or `logLevel: 1` and
216
- `suppressErrorRendering: false` with `debug: true`. Explicit values always win.
217
-
218
- **theme**
219
-
220
- Color mode integration is automatic when `@nuxtjs/color-mode` is installed; manual themes set via `useMermaidTheme()` take precedence.
221
-
222
- | Option | Type | Default | Description |
223
- | :---------------- | :----- | :---------- | :--------------------------------------------------------------------------- |
224
- | `theme.light` | string | `'default'` | Used for light color mode and the manual `setMermaidTheme('light')` strategy. |
225
- | `theme.dark` | string | `'dark'` | Used for dark color mode and the manual `setMermaidTheme('dark')` strategy. |
226
-
227
- **components**
228
-
229
- | Option | Type | Default | Description |
230
- | :------------------------ | :------- | :------ | :----------------------------------------------------------------------- |
231
- | `components.renderer` | `string` | omitted | Optional: custom Mermaid renderer component name. |
232
- | `components.spinner` | `string` | omitted | Optional: global loading spinner component name. |
233
- | `components.error` | `string` | omitted | Optional: global error component name when Mermaid rendering fails. |
234
-
235
- **toolbar**
236
-
237
- | Option | Type | Default | Description |
238
- | :------------------------- | :----------------- | :------ | :------------------------------------------ |
239
- | `toolbar.title` | `string` | `'mermaid'` | Default toolbar title for Mermaid blocks. |
240
- | `toolbar.fontSize` | `string \| number` | `'14px'` | Default toolbar font size. |
241
- | `toolbar.fullscreenToolbarScale` | `number` | `1.25` | Scale factor for toolbar font/icon size in fullscreen. |
242
- | `toolbar.buttons.copy` | `boolean` | `true` | Show copy-source button in the toolbar. |
243
- | `toolbar.buttons.fullscreen` | `boolean` | `true` | Show fullscreen button in the toolbar. |
244
- | `toolbar.buttons.expand` | `boolean` | `true` | Show expand button in the toolbar. |
245
-
246
- **expand**
247
-
248
- Control SVG expand interactions. You can also set `expand: false` to disable it, or `expand: true` to use defaults.
249
-
250
- | Option | Type | Default | Description |
251
- | :------------------------- | :-------- | :------ | :------------------------------------------------------------------------- |
252
- | `expand.enabled` | `boolean` | `true` | Enable or disable expand features entirely. |
253
- | `expand.margin` | `number` | `0` | Margin (px) around the expanded SVG within the viewport. |
254
- | `expand.invokeOpenOn.diagramClick` | `boolean` | `true` | Allow clicking the SVG to open expand overlay. |
255
- | `expand.invokeCloseOn.esc` | `boolean` | `true` | Allow Escape key to close. |
256
- | `expand.invokeCloseOn.wheel` | `boolean` | `true` | Allow mouse wheel to close. |
257
- | `expand.invokeCloseOn.swipe` | `boolean` | `true` | Allow swipe gesture to close. |
258
- | `expand.invokeCloseOn.overlayClick` | `boolean` | `true` | Allow clicking the overlay background to close. |
259
- | `expand.invokeCloseOn.closeButtonClick`| `boolean`| `true` | Show the overlay close button. |
260
-
261
- **Pan & Zoom (Expand Overlay / Fullscreen)**
262
-
263
- When fullscreen or expand mode is active, users can pan and zoom the diagram:
264
-
265
- | Interaction | Desktop | Mobile |
266
- |:---|:---|:---|
267
- | **Pan** | `Space` + Drag | 1-finger Drag |
268
- | **Zoom** | `Ctrl/⌘` + Scroll | 2-finger Pinch |
269
- | **Keyboard** | `+`/`-` to zoom, Arrow keys to pan, `0` to reset | — |
270
-
271
- A zoom toolbar appears with +/−/Reset buttons and a percentage display.
272
-
273
- Use `toolbar.fullscreenToolbarScale` to scale the fullscreen toolbar and zoom controls.
274
-
275
-
276
- > **Note**: `contentMermaid.enabled` controls Module Activation during Nuxt setup. Setting it to `false` disables only the Mermaid Content/runtime integration; it does not disable Nuxt Content. It is never a public runtime setting. `runtimeConfig.public.contentMermaid` carries only strict pure data and is resolved once during each Nuxt application initialization; mutating it later does not update the established Runtime Mermaid Snapshot.
277
-
278
- ## Migrating to v3
279
-
280
- The [v3 migration guide](./docs/en/MIGRATION_V3.md) covers the removed configuration alias, build-time activation, pure-data runtime transport, Page versus Direct Mermaid Config, Property-Presence Merge, expand reset semantics, and public diagnostic and rendering guarantees. A runnable companion is available at `/migration` in the playground.
281
-
282
- ## Styling (CSS Variables)
283
-
284
- 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:
285
-
286
- ```css
287
- :root {
288
- --ncm-code-bg: #f3f4f6;
289
- --ncm-code-bg-hover: #e5e7eb;
290
- --ncm-border: #e5e7eb;
291
- --ncm-text: #111827;
292
- --ncm-text-muted: #4b5563;
293
- --ncm-text-xmuted: #6b7280;
294
- --ncm-overlay-bg: rgba(255, 255, 255, 0.98);
295
- }
296
-
297
- html[data-theme="dark"],
298
- .dark {
299
- --ncm-code-bg: #111827;
300
- --ncm-code-bg-hover: #1f2937;
301
- --ncm-border: #1f2937;
302
- --ncm-text: #f9fafb;
303
- --ncm-text-muted: #9ca3af;
304
- --ncm-text-xmuted: #6b7280;
305
- --ncm-overlay-bg: rgba(17, 24, 39, 0.98);
306
- }
307
- ```
308
-
309
- Variables:
310
- - `--ncm-code-bg`: Mermaid block background.
311
- - `--ncm-code-bg-hover`: Hover background for toolbar buttons.
312
- - `--ncm-border-color`: Border color for the block and toolbar.
313
- - `--ncm-border-width`: Border thickness.
314
- - `--ncm-border-style`: Border style.
315
- - `--ncm-border`: Composite shorthand (width, style, color) for borders.
316
- - `--ncm-border-bottom`: Border style applied to the toolbar bottom.
317
- - `--ncm-text`: Primary text color.
318
- - `--ncm-text-muted`: Title and secondary text.
319
- - `--ncm-text-xmuted`: Toolbar icon and subtle UI text.
320
- - `--ncm-overlay-bg`: Expand overlay background (defaults to `--ncm-code-bg`).
321
- - `--ncm-expand-target-bg`: Background color shown behind the expanded SVG when `expand.margin` leaves breathing room.
322
- - `--ncm-overlay-opacity`: Overlay transparency (thinned when `expand.margin` creates breathing room).
323
- - `--ncm-overlay-backdrop`: `backdrop-filter` applied to the overlay when it becomes visible.
324
- - `--ncm-hint-bg`: Zoom hint toast background (default: `rgba(0,0,0,0.75)`).
325
- - `--ncm-hint-text`: Zoom hint toast text color (default: `#fff`).
326
- - `--ncm-hint-radius`: Zoom hint toast border radius (default: `8px`).
327
-
328
- ## Advanced Usage
329
-
330
- ### Debug mode
331
-
332
- **`contentMermaid.debug`** (default `false`):
333
- - **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.
334
- - **Runtime behavior**:
335
- - **Debug on**: `mermaid.run` uses `suppressErrors: false`, errors throw with full stack traces for debugging.
336
- - **Debug off**: `mermaid.run` uses `suppressErrors: true`, so one failing chart won't block others.
337
- - **Console output**: Debug log wording and internal render scheduling are not public APIs. For configuration failures, recognize the documented public fingerprint instead of parsing private details.
338
-
339
- ### Theme & Color Mode
340
-
341
- The module determines the active Mermaid theme with the following priority:
342
-
343
- 1. Frontmatter `config.theme` (per-page override)
344
- 2. Manual mode via `useMermaidTheme()` (if set)
345
- 3. `@nuxtjs/color-mode` (auto-detected when installed):
346
- - `dark` → `theme.dark`
347
- - `light` → `theme.light`
348
- 4. Resolved `loader.init.theme` (package default: `'default'`)
349
-
350
- 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).
351
-
352
- ### Override Per-Page Settings with Frontmatter
353
-
354
- Each Markdown file can override module settings by adding a `config` field in the frontmatter.
355
-
356
- > **⚠️ To use frontmatter `config` overrides, you MUST declare the `config` field in your collection schema in `content.config.ts`.**
357
- > Without this, Nuxt Content will not parse the `config` field as a JSON object, and your overrides will not work.
358
-
359
- Add this to your `content.config.ts`:
360
-
361
- ```ts
362
- import { defineContentConfig, defineCollection, z } from '@nuxt/content'
363
-
364
- export default defineContentConfig({
365
- collections: {
366
- content: defineCollection({
367
- type: 'page',
368
- source: '**',
369
- schema: z.object({
370
- config: z.record(z.unknown()).optional(), // ← Declare config field
371
- }).passthrough(),
372
- }),
373
- },
58
+ modules: ['@barzhsieh/nuxt-content-mermaid'],
374
59
  })
375
60
  ```
376
61
 
377
- Then use it in your Markdown frontmatter:
62
+ Then add a Mermaid fence to a Content Markdown file:
378
63
 
379
64
  ````markdown
380
- ---
381
- title: Example of Overriding Mermaid Settings Per Page
382
- config:
383
- theme: forest
384
- flowchart:
385
- htmlLabels: false
386
- ---
387
65
  ```mermaid
388
66
  flowchart LR
389
- A["<b>Allow HTML labels?</b>"] --> B{Not allowed}
390
- ```
391
- ````
392
-
393
- ### Priority Order of `%%{init}%%` Syntax, Frontmatter, and Module Settings
394
-
395
- Mermaid itself also supports overriding settings within diagrams using the `%%{init: ...}%%` syntax, for example:
396
- ````markdown
397
- ```mermaid
398
- %%{init: { 'theme': 'forest', 'flowchart': { 'curve': 'step' } }}%%
399
- graph TD
400
- A[Input] --> B{Valid?}
401
- B -- Yes --> C[Persist]
402
- B -- No --> D[Error]
403
- ```
404
- ````
405
-
406
- > For details, refer to the [official Mermaid documentation](https://mermaid.js.org/config/directives.html#declaring-directives)
407
-
408
- The actual priority order when settings take effect is as follows:
409
-
410
- 1. **`%%{init: ...}%%` within the diagram** — Highest priority, processed directly by Mermaid.
411
- 2. **Frontmatter `config`** — merged on top of the module's `loader.init`.
412
- 3. **Module-level `contentMermaid.loader.init`** — Project default settings.
413
-
414
- ### Mermaid Inline Attributes & YAML Frontmatter
415
-
416
- You can control Mermaid blocks in three ways: inline attrs, Mermaid YAML frontmatter, and `%%{init}%%` directives.
417
-
418
- #### Inline attrs (fence info)
419
-
420
- 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.*`).
421
-
422
- ````markdown
423
- ```mermaid {title="Diagram A" toolbar='{"title":"My Diagram","fontSize":"14px"}' config='{"theme":"dark"}'}
424
- graph TD
425
- A --> B
426
- ```
427
- ````
428
-
429
- #### Mermaid YAML frontmatter (inside the block)
430
-
431
- 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`).
432
-
433
- ````markdown
434
- ```mermaid
435
- ---
436
- title: Sample Flowchart
437
- displayMode: compact
438
- config:
439
- theme: dark
440
- toolbar:
441
- title: "Sample Diagram"
442
- buttons:
443
- copy: true
444
- ---
445
- graph TD
446
- A --> B
447
- ```
448
- ````
449
-
450
- #### `%%{init}%%` directive (inside the block)
451
-
452
- Use Mermaid directives to set render options directly in the diagram definition.
453
-
454
- ````markdown
455
- ```mermaid
456
- %%{init: { 'theme': 'forest', 'flowchart': { 'curve': 'step' } }}%%
457
- graph TD
458
- A --> B
67
+ Markdown --> Content --> Mermaid --> SVG
459
68
  ```
460
69
  ````
461
70
 
462
- ### Custom Rendering Component
463
-
464
- 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`.
465
-
466
- The configured name is a candidate until its component resolves. Built-in rendering remains paused during resolution. If the component cannot be found or loaded, the module falls back to the Built-in Renderer. Once resolution succeeds, the Custom Renderer completely owns rendering; its later mount or render failures do not trigger Built-in fallback.
467
-
468
- 1. Specify the component name in `nuxt.config.ts`:
469
-
470
- ```ts
471
- contentMermaid: {
472
- components: {
473
- renderer: "MyCustomMermaid",
474
- spinner: "MySpinner", // optional input for your component
475
- },
476
- }
477
- ```
478
-
479
- 2. Implement the component in `components/MyCustomMermaid.vue`:
480
-
481
- ```vue
482
- <script setup lang="ts">
483
- import { onMounted, ref, shallowRef, useId } from 'vue'
484
- import type { Component } from 'vue'
485
-
486
- const props = defineProps<{
487
- code?: string
488
- spinner: Component | string
489
- }>()
490
-
491
- const loading = ref(true)
492
- const error = shallowRef<unknown>()
493
- const svg = ref('')
494
- const renderId = `custom-mermaid-${useId().replaceAll(':', '')}`
495
-
496
- onMounted(async () => {
497
- try {
498
- const mermaid = await useNuxtApp().$mermaid()
499
- svg.value = (await mermaid.render(renderId, props.code ?? '')).svg
500
- }
501
- catch (cause) {
502
- error.value = cause
503
- }
504
- finally {
505
- loading.value = false
506
- }
507
- })
508
- </script>
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).
509
74
 
510
- <template>
511
- <div class="custom-wrapper border rounded p-4">
512
- <component
513
- :is="props.spinner"
514
- v-if="loading"
515
- />
516
- <p
517
- v-else-if="error"
518
- role="alert"
519
- >
520
- Diagram failed: {{ error instanceof Error ? error.message : String(error) }}
521
- </p>
522
- <div
523
- v-else
524
- v-html="svg"
525
- />
526
- </div>
527
- </template>
528
- ```
75
+ ## Canonical package documentation
529
76
 
530
- The Custom Renderer receives the existing `code`, default slot, and `spinner` inputs. It does not receive Built-in configuration, theme, toolbar, loading, or error state. `components.error` handles only Built-in Mermaid render failures, so a Custom Renderer must own its error presentation as shown above.
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)
531
82
 
532
- Do not render `<Mermaid>` from the component currently configured as `components.renderer`: that nested component would select the same Custom Renderer again. Invoke `$mermaid`, another rendering library, or your own renderer directly instead.
83
+ ## Support and contribution
533
84
 
534
- ### Wrapper Example
535
-
536
- Independently of `components.renderer`, you can wrap `<Mermaid>` inside your own Vue component. Do not configure that wrapper itself as the Custom Renderer.
537
- For example, you can bundle a title, loading state, and error/fallback UI, then drop it anywhere in templates:
538
-
539
- ```vue
540
- <!-- WrapperMermaid.vue -->
541
- <template>
542
- <section>
543
- <header v-if="title">{{ title }}</header>
544
-
545
- <Mermaid>
546
- <slot>
547
- <pre><code>{{ code }}</code></pre>
548
- </slot>
549
-
550
- <template #loading>
551
- <component :is="spinner" v-if="spinner" />
552
- <p v-else>Diagram loading…</p>
553
- </template>
554
-
555
- <template #error="{ error, source }">
556
- <p>Render failed: {{ error instanceof Error ? error.message : String(error) }}</p>
557
- <pre><code>{{ source }}</code></pre>
558
- </template>
559
- </Mermaid>
560
- </section>
561
- </template>
562
- ```
563
-
564
- ```vue
565
- <!-- usage -->
566
- <WrapperMermaid
567
- title="Demo Diagram"
568
- spinner="MySpinner"
569
- >
570
- <pre><code>graph TD; A-->B; B-->C; C-->A</code></pre>
571
- </WrapperMermaid>
572
- ```
573
-
574
- Copy or adapt this pattern to centralize the common slots you want to reuse.
575
-
576
- ### Error Handling
577
-
578
- 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.
579
-
580
- ```vue
581
- <Mermaid>
582
- <pre><code>graph TD; A-->B; B-->C; C-->A</code></pre>
583
-
584
- <template #error="{ error, source }">
585
- <p>Render failed: {{ error instanceof Error ? error.message : String(error) }}</p>
586
- <details>
587
- <summary>Show definition</summary>
588
- <pre><code>{{ source }}</code></pre>
589
- </details>
590
- </template>
591
- </Mermaid>
592
- ```
593
-
594
- To reuse a global error view everywhere, register it once and reference it in config:
595
-
596
- ```ts
597
- // nuxt.config.ts
598
- export default defineNuxtConfig({
599
- contentMermaid: {
600
- components: {
601
- error: 'MermaidError', // globally registered component name
602
- },
603
- },
604
- })
605
- ```
606
-
607
- ## Compatibility
608
-
609
- The public peer contract supports Nuxt `^4.1.0` and Nuxt Content `>=3.5.0 <4.0.0`. Releases verify two fixed package artifact profiles: `v3-minimum` at the public floors and `v3-known-latest` at the deliberately pinned known-latest versions. Both profiles cover clean installation, public types, production build, and basic browser SVG rendering under their exact Node runtimes.
610
-
611
- These profiles are evidence for the complete peer range, not a list of the only supported versions. If a profile fails, the resolution is to diagnose and fix the compatibility boundary—not to remove that profile or weaken its Package User assertions.
612
-
613
- Run each profile under its exact Node runtime:
614
-
615
- ```bash
616
- volta run --node 22.19.0 pnpm test:compatibility-profile --profile v3-minimum
617
- volta run --node 24.19.0 pnpm test:package-artifact
618
- ```
619
-
620
- ## Support
621
-
622
- If this module is useful to you, you can [support my open-source work on Ko-fi](https://ko-fi.com/barzhsieh). Your support helps fund maintenance, compatibility updates, testing, and documentation.
623
-
624
- ## Contribution
625
-
626
- Contributions are welcome! Feel free to open an [issue](https://github.com/andy820621/nuxt-content-mermaid/issues) or submit a pull request.
627
-
628
- Maintainers should follow the [stable release runbook](./docs/en/RELEASING.md).
629
-
630
- - Commit messages should follow [Conventional Commits](https://www.conventionalcommits.org/) (e.g. `feat: add spinner option`, `fix: handle dark mode toggle`).
631
- - PRs should include a summary of changes and test results.
632
-
633
- <details>
634
- <summary>Local Development Commands</summary>
635
-
636
- ```bash
637
- pnpm install # Install dependencies
638
- pnpm dev:prepare # Build module stubs & prepare playground
639
- pnpm dev # Start playground
640
- pnpm test # Run tests
641
- pnpm test:package-artifact # Verify the known-latest package artifact profile
642
- pnpm lint # Run ESLint
643
- pnpm test:types # Type checking
644
- ```
85
+ If the module is useful to you, you can
86
+ [support my open-source work on Ko-fi](https://ko-fi.com/barzhsieh).
645
87
 
646
- </details>
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).
647
92
 
648
93
  ## License
649
94