@barzhsieh/nuxt-content-mermaid 2.2.2 → 3.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.
Files changed (62) hide show
  1. package/README.md +190 -90
  2. package/README.zh-TW.md +183 -99
  3. package/dist/module.d.mts +39 -53
  4. package/dist/module.json +3 -3
  5. package/dist/module.mjs +600 -155
  6. package/dist/runtime/built-in-renderer/BuiltInRenderer.d.vue.ts +0 -0
  7. package/dist/runtime/built-in-renderer/BuiltInRenderer.vue +597 -0
  8. package/dist/runtime/built-in-renderer/BuiltInRenderer.vue.d.ts +0 -0
  9. package/dist/runtime/component-configuration-error.d.ts +3 -0
  10. package/dist/runtime/component-configuration-error.js +7 -0
  11. package/dist/runtime/component-configuration.d.ts +23 -0
  12. package/dist/runtime/component-configuration.js +78 -0
  13. package/dist/runtime/components/ContentMermaidTransport.d.vue.ts +10 -0
  14. package/dist/runtime/components/ContentMermaidTransport.vue +21 -0
  15. package/dist/runtime/components/ContentMermaidTransport.vue.d.ts +10 -0
  16. package/dist/runtime/components/Mermaid.d.vue.ts +0 -31
  17. package/dist/runtime/components/Mermaid.vue +136 -743
  18. package/dist/runtime/components/Mermaid.vue.d.ts +0 -31
  19. package/dist/runtime/components/MermaidExpandOverlay.d.vue.ts +13 -16
  20. package/dist/runtime/components/MermaidExpandOverlay.vue +61 -53
  21. package/dist/runtime/components/MermaidExpandOverlay.vue.d.ts +13 -16
  22. package/dist/runtime/components/MermaidFullscreenPresentation.d.vue.ts +18 -0
  23. package/dist/runtime/components/MermaidFullscreenPresentation.vue +56 -0
  24. package/dist/runtime/components/MermaidFullscreenPresentation.vue.d.ts +18 -0
  25. package/dist/runtime/composables/useMermaidExpand.d.ts +16 -32
  26. package/dist/runtime/composables/useMermaidExpand.js +232 -75
  27. package/dist/runtime/composables/useMermaidFullscreen.d.ts +18 -0
  28. package/dist/runtime/composables/useMermaidFullscreen.js +242 -0
  29. package/dist/runtime/composables/useMermaidZoom.d.ts +5 -1
  30. package/dist/runtime/composables/useMermaidZoom.js +54 -28
  31. package/dist/runtime/configuration/core.d.ts +27 -0
  32. package/dist/runtime/configuration/core.js +340 -0
  33. package/dist/runtime/configuration/module.d.ts +17 -0
  34. package/dist/runtime/configuration/module.js +233 -0
  35. package/dist/runtime/configuration/runtime-options.d.ts +4 -0
  36. package/dist/runtime/configuration/runtime-options.js +57 -0
  37. package/dist/runtime/constants.d.ts +24 -0
  38. package/dist/runtime/constants.js +60 -2
  39. package/dist/runtime/direct-mermaid-config.d.ts +5 -0
  40. package/dist/runtime/direct-mermaid-config.js +216 -0
  41. package/dist/runtime/mermaid-config.d.ts +9 -5
  42. package/dist/runtime/mermaid-config.js +30 -19
  43. package/dist/runtime/mermaid-rendering.d.ts +28 -0
  44. package/dist/runtime/mermaid-rendering.js +140 -0
  45. package/dist/runtime/plugins/content-mermaid-transport.d.ts +2 -0
  46. package/dist/runtime/plugins/content-mermaid-transport.js +5 -0
  47. package/dist/runtime/plugins/mermaid.client.d.ts +0 -3
  48. package/dist/runtime/plugins/mermaid.client.js +14 -32
  49. package/dist/runtime/plugins/runtime-config.d.ts +2 -0
  50. package/dist/runtime/plugins/runtime-config.js +9 -0
  51. package/dist/runtime/rendererSelection.d.ts +43 -0
  52. package/dist/runtime/rendererSelection.js +36 -0
  53. package/dist/runtime/rendererSelectionOrchestration.d.ts +12 -0
  54. package/dist/runtime/rendererSelectionOrchestration.js +13 -0
  55. package/dist/runtime/runtime-snapshot.d.ts +3 -0
  56. package/dist/runtime/runtime-snapshot.js +26 -0
  57. package/dist/runtime/utils/index.d.ts +0 -4
  58. package/dist/runtime/utils/index.js +0 -37
  59. package/dist/types.d.mts +2 -2
  60. package/package.json +36 -32
  61. package/dist/runtime/utils/mermaid-transform.d.ts +0 -18
  62. package/dist/runtime/utils/mermaid-transform.js +0 -345
package/README.zh-TW.md CHANGED
@@ -14,54 +14,99 @@
14
14
  專為 [**Nuxt Content v3**](https://content.nuxt.com/docs/getting-started) 整合 [**Mermaid**](https://mermaid.js.org/) 的模組。
15
15
  能自動將 Markdown 中的 \`\`\`mermaid 區塊轉換為響應式的圖表元件,並支援 Lazy Loading 與深色模式切換。
16
16
 
17
- ## Features
17
+ <details>
18
+ <summary>目錄</summary>
19
+
20
+ - [功能特色](#功能特色)
21
+ - [使用前提](#使用前提)
22
+ - [相依與遷移契約](./docs/ch/DEPENDENCY_AND_MIGRATION_CONTRACT.md)
23
+ - [快速開始](#快速開始)
24
+ - [設定](#設定)
25
+ - [遷移至 v3](#遷移至-v3)
26
+ - [樣式自訂(CSS 變數)](#樣式自訂css-變數)
27
+ - [進階用法](#進階用法)
28
+ - [Debug 模式](#debug-模式)
29
+ - [主題與顏色模式](#主題與顏色模式-theme--color-mode)
30
+ - [以 frontmatter 覆寫單頁設定](#以-frontmatter-覆寫單頁設定)
31
+ - [Mermaid Inline attrs 與 YAML Frontmatter](#mermaid-inline-attrs-與-yaml-frontmatter)
32
+ - [自訂渲染元件](#自訂渲染元件-custom-component)
33
+ - [元件使用方式](#元件使用方式)
34
+ - [錯誤處理](#錯誤處理)
35
+ - [支持專案](#支持專案)
36
+ - [貢獻](#貢獻)
37
+ - [授權](#授權)
38
+
39
+ </details>
40
+
41
+ ## 功能特色
18
42
 
19
43
  - **自動轉換**:解析 Markdown 代碼區塊並替換為 `<Mermaid>` 渲染元件。
20
44
  - **效能優化**:支援 Lazy Loading,僅在元件掛載時載入 Mermaid 核心與資源。
21
45
  - **主題整合**:無縫整合 `@nuxtjs/color-mode`,自動切換 Light/Dark 對應主題。
22
- - **高度客製**:支援自訂渲染元件(Wrapper)、Loading Spinner、錯誤畫面以及 CDN 來源。
23
- - **Runtime Config**:支援透過環境變數動態覆寫設定。
46
+ - **高度客製**:支援自訂渲染元件、Loading Spinner、錯誤畫面、主題與工具列控制。
47
+ - **部署期設定**:可透過 public runtime config 傳遞純資料設定,並在每個 Nuxt 應用程式初始化時解析一次。
24
48
 
25
49
  ## 使用前提
26
50
 
27
- - `nuxt@^3.20.1 || ^4.1.0`
28
- - `@nuxt/content@>=3.5.0`
51
+ - Node.js `>=22.19.0`
52
+ - `nuxt@^4.1.0`
53
+ - `@nuxt/content@>=3.5.0 <4.0.0`
29
54
 
30
- ## Quick Setup
55
+ 相依擁有權、2.x 遷移方式、渲染保證與視覺快照限制,請參閱[相依與遷移契約](./docs/ch/DEPENDENCY_AND_MIGRATION_CONTRACT.md)。
31
56
 
32
- ### 1. 安裝模組
33
-
34
- **自動設定(自動寫入 `modules`):**
35
-
36
- ```bash
37
- npx nuxi module add @barzhsieh/nuxt-content-mermaid
38
- ```
57
+ ## 快速開始
39
58
 
40
- > Nuxt CLI 對第三方模組預設會裝到 `dependencies`。若你偏好放在 `devDependencies`,請安裝完後移動或改用下方的方式手動安裝。
59
+ ### 1. 安裝套件
41
60
 
42
- **裝到 `devDependencies`(需手動加入 `modules`):**
61
+ 套件管理器安裝與 Nuxt 模組初始化是兩個不同步驟。您的應用程式擁有 Nuxt 與 Nuxt Content 這兩個 peer dependencies,因此必須自行安裝、鎖定與更新它們。請一併安裝本模組與支援範圍內的 Nuxt Content peer:
43
62
 
44
63
  ```bash
45
64
  # pnpm
46
- pnpm add -D @barzhsieh/nuxt-content-mermaid
65
+ pnpm add @barzhsieh/nuxt-content-mermaid @nuxt/content
47
66
 
48
67
  # npm
49
- npm install -D @barzhsieh/nuxt-content-mermaid
68
+ npm install @barzhsieh/nuxt-content-mermaid @nuxt/content
50
69
 
51
70
  # yarn
52
- yarn add -D @barzhsieh/nuxt-content-mermaid
71
+ yarn add @barzhsieh/nuxt-content-mermaid @nuxt/content
53
72
  ```
54
73
 
55
- ### 2. 配置 `nuxt.config.ts`
74
+ Mermaid 是本模組綁定的 Module-Owned Dependency,因此不必為了本模組另行安裝。
56
75
 
57
- 確保模組已加入 `modules` 清單(若使用 `nuxi module add` 則可略過):
76
+ > [!NOTE]
77
+ > **Nuxt Content 資料庫 connector** — 在 Node.js 環境中,Nuxt Content 會由
78
+ > 應用程式選擇資料庫 connector;可用選項包含 `better-sqlite3`、`sqlite3`,
79
+ > 以及受支援 Node.js 版本提供的 native SQLite。本模組不要求或擁有特定
80
+ > connector;請依已安裝版本參閱
81
+ > [Nuxt Content 安裝指南](https://content.nuxt.com/docs/getting-started/installation)。
82
+ >
83
+ > **pnpm v10+** — 若選擇 `better-sqlite3` 或 `sqlite3`,pnpm v10 預設會
84
+ > 封鎖其原生 build script。請執行 `pnpm approve-builds`,或只在
85
+ > `package.json` 允許你選用的 connector。下例使用 `better-sqlite3`;若
86
+ > 選用 `sqlite3`,請先將套件名稱替換為 `sqlite3`:
87
+ >
88
+ > ```json
89
+ > {
90
+ > "pnpm": {
91
+ > "onlyBuiltDependencies": ["better-sqlite3"]
92
+ > }
93
+ > }
94
+ > ```
95
+
96
+ ### 2. 初始化 Nuxt 模組
97
+
98
+ 標準 `modules` 設定只需列出本模組:
58
99
 
59
100
  ```ts
60
101
  export default defineNuxtConfig({
61
- modules: ["@barzhsieh/nuxt-content-mermaid", "@nuxt/content"],
102
+ modules: ["@barzhsieh/nuxt-content-mermaid"],
62
103
  });
63
104
  ```
64
105
 
106
+ 本模組透過 `moduleDependencies` 宣告必要的 Nuxt Content 關係與相容版本,因此 Nuxt 會依必要順序初始化已安裝的 `@nuxt/content` 模組。這項宣告不會安裝、鎖定或更新 Nuxt Content;這些套件管理器責任仍由您的應用程式承擔。
107
+
108
+ 若您的應用程式已在 `modules` 中手動列出 `@nuxt/content`,可以保留該項設定。手動列出仍受支援,但不再是標準設定。
109
+
65
110
  ### 3. 在 Markdown 中使用
66
111
 
67
112
  在 `content/` 目錄下的 `.md` 檔案中直接撰寫 Mermaid 語法:
@@ -79,10 +124,9 @@ graph LR
79
124
 
80
125
  模組會自動將其轉換為 SVG 圖表。
81
126
 
82
- ## Configuration
127
+ ## 設定
83
128
 
84
- 你可以透過 `contentMermaid` 選項進行全域設定。
85
- (`mermaidContent` 仍會被接受以維持相容,但已棄用,未來版本會移除。)
129
+ 請透過正式的 `contentMermaid` 選項進行全域設定。舊的 `mermaidContent` alias 已在 v3 移除,使用時會得到遷移錯誤。
86
130
 
87
131
  ```ts
88
132
  // nuxt.config.ts
@@ -100,11 +144,6 @@ export default defineNuxtConfig({
100
144
  light: "default",
101
145
  dark: "dark",
102
146
  },
103
- components: {
104
- renderer: undefined,
105
- spinner: undefined,
106
- error: undefined,
107
- },
108
147
  toolbar: {
109
148
  title: "mermaid",
110
149
  fontSize: "14px",
@@ -144,27 +183,42 @@ export default defineNuxtConfig({
144
183
 
145
184
  **loader**
146
185
 
147
- | 參數 | 類型 | 預設值 | 說明 |
148
- | :--------------- | :------------------------------------- | :----------------------- | :---------------------------------------------------------------------- |
149
- | `loader.init` | `MermaidConfig` | `{ startOnLoad: false }` | 直接傳遞給 `mermaid.initialize` 的原始設定。 |
150
- | `loader.lazy` | `boolean \| { threshold?: number }` | `true` | 元件進入 viewport 時才載入 Mermaid;設為 `false` 會在前一刻就載入。 |
186
+ | 參數 | 類型 | 預設值 | 說明 |
187
+ | :--------------- | :------------------------------------- | :--------- | :---------------------------------------------------------------------- |
188
+ | `loader.init` | `RuntimeMermaidConfig`(嚴格純資料) | 套件預設值 | 傳遞至 `mermaid.initialize` 的純資料 Mermaid 設定。 |
189
+ | `loader.lazy` | `boolean \| { threshold?: number }` | `true` | 元件進入 viewport 時才載入 Mermaid;設為 `false` 會在前一刻就載入。 |
190
+
191
+ `loader.init` 的 baseline 為:
192
+
193
+ ```ts
194
+ {
195
+ startOnLoad: false,
196
+ theme: 'default',
197
+ fontFamily: 'Arial, sans-serif, 微軟正黑體',
198
+ securityLevel: 'strict',
199
+ }
200
+ ```
201
+
202
+ 未明確設定時,`debug: false` 會解析成 `logLevel: 5` 與
203
+ `suppressErrorRendering: true`;`debug: true` 則解析成 `logLevel: 1` 與
204
+ `suppressErrorRendering: false`。使用者明確提供的值一律優先。
151
205
 
152
206
  **theme**
153
207
 
154
208
  若專案安裝了 `@nuxtjs/color-mode` 會自動偵測並跟隨;透過 `useMermaidTheme()` 設定的手動主題會優先。
155
209
 
156
- | 參數 | 類型 | 預設值 | 說明 |
157
- | :------------ | :----- | :---------- | :-------------------------------------------------------------------------------- |
158
- | `theme.light` | string | `'default'` | 當 color-mode 為 light 時的主題,若 color-mode 不存在也會回退使用。 |
159
- | `theme.dark` | string | `'dark'` | 當 color-mode 為 dark 時的主題,若 color-mode 不存在也會回退使用。 |
210
+ | 參數 | 類型 | 預設值 | 說明 |
211
+ | :------------ | :----- | :---------- | :------------------------------------------------------------ |
212
+ | `theme.light` | string | `'default'` | 用於 light color mode 與手動 `setMermaidTheme('light')` 策略。 |
213
+ | `theme.dark` | string | `'dark'` | 用於 dark color mode 與手動 `setMermaidTheme('dark')` 策略。 |
160
214
 
161
215
  **components**
162
216
 
163
- | 參數 | 類型 | 預設值 | 說明 |
164
- | :----------------------- | :------- | :--------- | :----------------------------------------------------- |
165
- | `components.renderer` | `string` | `undefined` | 指定自訂的 Mermaid 實作元件名稱(見進階用法)。 |
166
- | `components.spinner` | `string` | `undefined` | 指定全域的 Loading 元件名稱。 |
167
- | `components.error` | `string` | `undefined` | 指定全域的錯誤顯示元件名稱,渲染失敗時會使用。 |
217
+ | 參數 | 類型 | 預設值 | 說明 |
218
+ | :----------------------- | :------- | :----- | :----------------------------------------------------- |
219
+ | `components.renderer` | `string` | 未設定 | 選填:指定自訂的 Mermaid 實作元件名稱(見進階用法)。 |
220
+ | `components.spinner` | `string` | 未設定 | 選填:指定全域的 Loading 元件名稱。 |
221
+ | `components.error` | `string` | 未設定 | 選填:指定全域的錯誤顯示元件名稱,渲染失敗時會使用。 |
168
222
 
169
223
  **toolbar**
170
224
 
@@ -207,7 +261,11 @@ export default defineNuxtConfig({
207
261
  可透過 `toolbar.fullscreenToolbarScale` 調整 Fullscreen 工具列與縮放控制的尺寸。
208
262
 
209
263
 
210
- > **Note**: 所有設定皆可透過 `runtimeConfig.public.contentMermaid` 在部署時進行覆寫(`runtimeConfig.public.mermaidContent` 仍支援但已棄用)。
264
+ > **注意**:`contentMermaid.enabled` 在 Nuxt setup 時決定模組啟用狀態。設為 `false` 只會停用 Mermaid 的 Content/runtime integration,不會停用 Nuxt Content。它絕不是 public runtime 設定。`runtimeConfig.public.contentMermaid` 只能傳遞嚴格純資料,並在每個 Nuxt 應用程式初始化時解析一次;之後變更它不會更新既有的 Runtime Mermaid Snapshot。
265
+
266
+ ## 遷移至 v3
267
+
268
+ [v3 遷移指南](./docs/ch/MIGRATION_V3.md)說明移除的設定 alias、建置期 activation、純資料 runtime transport、Page 與 Direct Mermaid Config、Property-Presence Merge、expand 重設語意,以及公開的診斷與渲染保證。Playground 的 `/migration` 路徑提供可操作的對照範例。
211
269
 
212
270
  ## 樣式自訂(CSS 變數)
213
271
 
@@ -236,7 +294,6 @@ html[data-theme="dark"],
236
294
  }
237
295
  ```
238
296
 
239
- 可覆寫的變數:
240
297
  可覆寫的變數:
241
298
  - `--ncm-code-bg`:Mermaid 區塊背景色
242
299
  - `--ncm-code-bg-hover`:工具列按鈕 hover 背景
@@ -256,16 +313,16 @@ html[data-theme="dark"],
256
313
  - `--ncm-hint-text`:縮放提示訊息文字顏色(預設 `#fff`)
257
314
  - `--ncm-hint-radius`:縮放提示訊息圓角(預設 `8px`)
258
315
 
259
- ## Advanced Usage
316
+ ## 進階用法
260
317
 
261
318
  ### Debug 模式
262
319
 
263
320
  **`contentMermaid.debug`**(預設 `false`):
264
- - **自動配置**:若未手動設定 `loader.init.logLevel` 或 `suppressErrorRendering`,開啟 debug 模式會自動將 `logLevel` 設為 `1` (Info),並將 `suppressErrorRendering` 設為 `false`(允許 Mermaid 在 DOM 中顯示錯誤訊息)。
321
+ - **自動配置**:若未明確設定 `loader.init.logLevel` 或 `suppressErrorRendering`,`debug: false` 會解析為 `logLevel: 5` 與 `suppressErrorRendering: true`;`debug: true` 會解析為 `logLevel: 1` 與 `suppressErrorRendering: false`(允許 Mermaid 在 DOM 中顯示錯誤訊息)。明確設定的值一律優先。
265
322
  - **執行行為**:
266
323
  - **Debug 開啟**:`mermaid.run` 使用 `suppressErrors: false`,發生錯誤時會拋出完整堆疊以便除錯。
267
324
  - **Debug 關閉**:`mermaid.run` 使用 `suppressErrors: true`,避免單一圖表錯誤中斷其他圖表的渲染。
268
- - **主控台輸出**:模組會額外輸出渲染佇列的診斷資訊與執行時間統計。
325
+ - **主控台輸出**:Debug log 的文字與內部渲染排程不是公開 API。設定失敗時,應辨識文件記載的公開錯誤 fingerprint,不要解析內部訊息細節。
269
326
 
270
327
  ### 主題與顏色模式 (Theme & Color Mode)
271
328
 
@@ -276,8 +333,7 @@ html[data-theme="dark"],
276
333
  3. `@nuxtjs/color-mode`(安裝時自動偵測):
277
334
  - `dark` → 使用 `theme.dark`
278
335
  - `light` → 使用 `theme.light`
279
- 4. `loader.init.theme`(若有設定)
280
- 5. 回退:`theme.light`,若無則 Mermaid 預設 `'default'`
336
+ 4. 解析後的 `loader.init.theme`(套件預設為 `'default'`)
281
337
 
282
338
  更多進階手動控制(如:強制指定特定主題、自訂切換邏輯),請參閱 [手動主題控制指南](./docs/ch/MANUAL_THEME_CONTROL.md)。
283
339
 
@@ -399,13 +455,16 @@ graph TD
399
455
 
400
456
  若需完全接管 Mermaid 的渲染行為(例如:加入外框、Expand/Collapse 功能),可指定 `components.renderer`。
401
457
 
458
+ 指定的名稱在元件解析完成前只是候選。解析期間 Built-in Renderer 會保持暫停;若找不到或無法載入該元件,模組才會回退到 Built-in Renderer。一旦解析成功,Custom Renderer 就完全擁有渲染流程,之後的 mount 或 render failure 不會觸發 Built-in fallback。
459
+
402
460
  1. 在 `nuxt.config.ts` 中指定元件名稱:
403
461
 
404
462
  ```ts
405
463
  contentMermaid: {
406
464
  components: {
407
- renderer: "MyCustomMermaid",
408
- }
465
+ renderer: 'MyCustomMermaid',
466
+ spinner: 'MySpinner', // 選填:傳入自訂渲染元件
467
+ },
409
468
  }
410
469
  ```
411
470
 
@@ -413,56 +472,56 @@ graph TD
413
472
 
414
473
  ```vue
415
474
  <script setup lang="ts">
416
- // 你可以在此使用 slot 內容或自行呼叫 useMermaid() 等邏輯
475
+ import { onMounted, ref, shallowRef, useId } from 'vue'
476
+ import type { Component } from 'vue'
477
+
478
+ const props = defineProps<{
479
+ code?: string
480
+ spinner: Component | string
481
+ }>()
482
+
483
+ const loading = ref(true)
484
+ const error = shallowRef<unknown>()
485
+ const svg = ref('')
486
+ const renderId = `custom-mermaid-${useId().replaceAll(':', '')}`
487
+
488
+ onMounted(async () => {
489
+ try {
490
+ const mermaid = await useNuxtApp().$mermaid()
491
+ svg.value = (await mermaid.render(renderId, props.code ?? '')).svg
492
+ }
493
+ catch (cause) {
494
+ error.value = cause
495
+ }
496
+ finally {
497
+ loading.value = false
498
+ }
499
+ })
417
500
  </script>
418
501
 
419
502
  <template>
420
503
  <div class="custom-wrapper border rounded p-4">
421
- <Mermaid>
422
- <slot />
423
- </Mermaid>
504
+ <component
505
+ :is="props.spinner"
506
+ v-if="loading"
507
+ />
508
+ <p
509
+ v-else-if="error"
510
+ role="alert"
511
+ >
512
+ 圖表渲染失敗:{{ error instanceof Error ? error.message : String(error) }}
513
+ </p>
514
+ <div
515
+ v-else
516
+ v-html="svg"
517
+ />
424
518
  </div>
425
519
  </template>
426
520
  ```
427
521
 
428
- #### 載入中指示
429
-
430
- 模組在首次渲染前會使用內建的 spinner,如需替換可在 `components.spinner` 指定元件名稱;該元件也會以 `spinner` prop 傳入你的自訂渲染元件,方便直接渲染。
522
+ Custom Renderer 會收到既有的 `code`、default slot 與 `spinner` 輸入;不會收到 Built-in 的設定、主題、toolbar、loading 或 error state。`components.error` 只處理 Built-in Mermaid render failure,因此 Custom Renderer 必須自行呈現錯誤狀態,如上例所示。
431
523
 
432
- 以下是極簡的設定與元件示例:
433
-
434
- ```ts
435
- // nuxt.config.ts
436
- export default defineNuxtConfig({
437
- contentMermaid: {
438
- components: {
439
- renderer: 'MyCustomMermaid',
440
- spinner: 'MySpinner', // 選填:改用自己的全域 Loading 元件
441
- }
442
- }
443
- })
444
- ```
445
-
446
- ```vue
447
- <!-- components/MyCustomMermaid.vue -->
448
- <script setup lang="ts">
449
- import { ref, onMounted } from 'vue'
450
- import type { Component } from 'vue'
451
-
452
- const props = defineProps<{ spinner: Component | string }>()
453
- const loading = ref(true)
454
- onMounted(() => { loading.value = false })
455
- </script>
456
-
457
- <template>
458
- <div class="my-mermaid">
459
- <component v-if="loading" :is="props.spinner" />
460
- <Mermaid v-else>
461
- <slot />
462
- </Mermaid>
463
- </div>
464
- </template>
465
- ```
524
+ 目前被設定為 `components.renderer` 的元件不得渲染 `<Mermaid>`:巢狀元件會再次選中同一個 Custom Renderer。請改為直接呼叫 `$mermaid()`、其他 rendering library 或自己的 renderer。
466
525
 
467
526
  ### 元件使用方式
468
527
 
@@ -536,21 +595,46 @@ export default defineNuxtConfig({
536
595
  })
537
596
  ```
538
597
 
539
- ## Contribution
598
+ ## 相容性
599
+
600
+ 公開 peer contract 支援 Nuxt `^4.1.0` 與 Nuxt Content `>=3.5.0 <4.0.0`。發布前會驗證兩個固定的 package artifact profiles:位於公開最低版本的 `v3-minimum`,以及刻意固定已知最新版本的 `v3-known-latest`。兩者都會在各自的精確 Node runtime 下驗證 clean installation、公開型別、production build 與基本瀏覽器 SVG rendering。
601
+
602
+ 這兩個 profiles 是完整 peer range 的代表性證據,不是唯一支援版本清單。如果 profile 失敗,必須診斷並修復相容性邊界;不能靠刪除 profile 或降低 Package User assertions 取得綠燈。
603
+
604
+ 請在各 profile 的精確 Node runtime 下執行:
605
+
606
+ ```bash
607
+ volta run --node 22.19.0 pnpm test:compatibility-profile --profile v3-minimum
608
+ volta run --node 24.19.0 pnpm test:package-artifact
609
+ ```
610
+
611
+ ## 支持專案
612
+
613
+ 如果這個模組對你有幫助,歡迎透過 [Ko-fi 支持我的開源工作](https://ko-fi.com/barzhsieh)。你的支持將協助專案持續維護、相容性更新、測試與文件撰寫。
614
+
615
+ ## 貢獻
616
+
617
+ 歡迎提交 Issue 回報問題或建議新功能!也歡迎直接發 Pull Request。
618
+
619
+ - Commit 訊息請遵循 [Conventional Commits](https://www.conventionalcommits.org/) 格式(例如 `feat: add spinner option`、`fix: handle dark mode toggle`)。
620
+ - PR 請附上變更摘要與測試結果。
540
621
 
541
622
  <details>
542
- <summary>Local Development Commands</summary>
623
+ <summary>開發指令</summary>
543
624
 
544
625
  ```bash
545
- pnpm install
546
- pnpm dev:prepare
547
- pnpm dev # Run playground
548
- pnpm test # Run tests
626
+ pnpm install # 安裝依賴
627
+ pnpm dev:prepare # 建置模組 stub 並準備 playground
628
+ pnpm dev # 啟動 playground
629
+ pnpm test # 執行測試
630
+ pnpm test:package-artifact # 驗證 known-latest package artifact profile
631
+ pnpm lint # 執行 ESLint
632
+ pnpm test:types # 型別檢查
549
633
  ```
550
634
 
551
635
  </details>
552
636
 
553
- ## License
637
+ ## 授權
554
638
 
555
639
  [MIT License](./LICENSE)
556
640
 
package/dist/module.d.mts CHANGED
@@ -26,37 +26,21 @@ declare module 'vue' {
26
26
  $mermaid: () => Promise<Mermaid>
27
27
  }
28
28
  interface GlobalComponents {
29
- Mermaid: DefineComponent<{
30
- config?: MermaidConfig
31
- toolbar?: MermaidToolbarOptions
32
- code?: string
33
- }>
29
+ Mermaid: DefineComponent<MermaidComponentProps>
34
30
  }
35
31
  }
36
32
 
37
- declare module 'nuxt/schema' {
33
+ declare module '@nuxt/schema' {
38
34
  interface NuxtConfig {
39
35
  contentMermaid?: ModuleOptions
40
- /**
41
- * @deprecated Use `contentMermaid`
42
- */
43
- mermaidContent?: ModuleOptions
44
36
  }
45
37
 
46
38
  interface NuxtOptions {
47
39
  contentMermaid?: ModuleOptions
48
- /**
49
- * @deprecated Use `contentMermaid`
50
- */
51
- mermaidContent?: ModuleOptions
52
40
  }
53
41
 
54
42
  interface PublicRuntimeConfig {
55
- contentMermaid?: Partial<ModuleOptions>
56
- /**
57
- * @deprecated Use `contentMermaid`
58
- */
59
- mermaidContent?: Partial<ModuleOptions>
43
+ contentMermaid?: RuntimeOptions
60
44
  }
61
45
  }
62
46
 
@@ -72,12 +56,18 @@ declare global {
72
56
  }
73
57
  }
74
58
 
75
- interface ModuleOptions {
76
- /**
77
- * Whether to enable the entire Mermaid process
78
- * @default true
79
- */
80
- enabled?: boolean;
59
+ type JsonPrimitive = string | number | boolean | null;
60
+ type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
61
+ type JsonObject = {
62
+ [key: string]: JsonValue;
63
+ };
64
+ type IsAny<T> = 0 extends (1 & T) ? true : false;
65
+ type RuntimeDataMember<T> = IsAny<T> extends true ? never : T extends JsonPrimitive ? T : T extends (...args: never[]) => unknown ? never : T extends readonly (infer Item)[] ? RuntimeDataMember<Item>[] : T extends object ? {
66
+ [Key in keyof T]: RuntimeDataMember<T[Key]>;
67
+ } : never;
68
+ type RuntimeMermaidConfig = RuntimeDataMember<MermaidConfig> & JsonObject;
69
+ type PageMermaidConfig = RuntimeMermaidConfig;
70
+ interface RuntimeOptions {
81
71
  /**
82
72
  * Enable debug mode for detailed logging and error reporting
83
73
  * @default false
@@ -88,9 +78,9 @@ interface ModuleOptions {
88
78
  */
89
79
  loader?: {
90
80
  /**
91
- * Pass-through to `mermaid.initialize`
81
+ * Pure-data configuration passed through Nuxt public runtime config.
92
82
  */
93
- init?: MermaidConfig;
83
+ init?: RuntimeMermaidConfig;
94
84
  /**
95
85
  * Whether to lazy load the diagram when it enters the viewport.
96
86
  * Can be a boolean or an object with IntersectionObserver options.
@@ -104,10 +94,7 @@ interface ModuleOptions {
104
94
  * Options related to theme handling
105
95
  */
106
96
  theme?: {
107
- /**
108
- * @deprecated The module now automatically detects and syncs with @nuxtjs/color-mode.
109
- * This option no longer has any effect and will be removed in a future version.
110
- */
97
+ /** @deprecated No effect; retained for 3.0 compatibility. */
111
98
  useColorModeTheme?: boolean;
112
99
  light?: MermaidConfig['theme'];
113
100
  dark?: MermaidConfig['theme'];
@@ -116,28 +103,10 @@ interface ModuleOptions {
116
103
  * Names for custom implementation components
117
104
  */
118
105
  components?: {
119
- /**
120
- * Custom Mermaid implementation component name (e.g., 'MyMermaid').
121
- * The Markdown transformation phase always outputs `<Mermaid>`, this setting only affects
122
- * which component implementation `Mermaid.vue` delegates to at runtime.
123
- */
124
106
  renderer?: string;
125
- /**
126
- * Spinner component name to use while Mermaid is loading.
127
- * This should be a globally available component name (e.g., under the project `components/` directory).
128
- * If not provided, the module's built-in `Spinner.vue` will be used.
129
- */
130
107
  spinner?: string;
131
- /**
132
- * Error component name to display when Mermaid rendering fails.
133
- * This should be a globally available component name (e.g., under the project `components/` directory).
134
- * If not provided, the module's built-in fallback message will be used.
135
- */
136
108
  error?: string;
137
109
  };
138
- /**
139
- * Options related to SVG expand (lightbox) interactions
140
- */
141
110
  /**
142
111
  * Expand configuration. `false` disables expand, `true` uses defaults.
143
112
  */
@@ -147,9 +116,26 @@ interface ModuleOptions {
147
116
  */
148
117
  toolbar?: MermaidToolbarOptions;
149
118
  }
150
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
119
+ interface ModuleOptions extends RuntimeOptions {
120
+ /**
121
+ * Whether to enable the entire Mermaid process at build time.
122
+ * @default true
123
+ */
124
+ enabled?: boolean;
125
+ }
126
+ interface MermaidComponentBaseProps {
127
+ toolbar?: MermaidToolbarOptions;
128
+ code?: string;
129
+ }
130
+ type MermaidComponentProps = MermaidComponentBaseProps & ({
131
+ pageConfig?: PageMermaidConfig;
132
+ config?: never;
133
+ } | {
134
+ pageConfig?: never;
135
+ config?: MermaidConfig;
136
+ });
151
137
 
152
- declare function transformMermaidCodeBlocks(body: string, componentName: string, frontmatterConfigKey?: string): string;
138
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
153
139
 
154
- export { _default as default, transformMermaidCodeBlocks };
155
- export type { ModuleOptions };
140
+ export { _default as default };
141
+ export type { MermaidComponentProps, ModuleOptions, PageMermaidConfig, RuntimeMermaidConfig, RuntimeOptions };
package/dist/module.json CHANGED
@@ -2,11 +2,11 @@
2
2
  "name": "@barzhsieh/nuxt-content-mermaid",
3
3
  "configKey": "contentMermaid",
4
4
  "compatibility": {
5
- "nuxt": "^3.20.1 || ^4.1.0"
5
+ "nuxt": "^4.1.0"
6
6
  },
7
- "version": "2.2.2",
7
+ "version": "3.0.0",
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
9
+ "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
11
11
  }
12
12
  }