@barzhsieh/nuxt-content-mermaid 3.0.4 → 3.0.5

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/dist/module.d.mts CHANGED
@@ -102,6 +102,7 @@ interface RuntimeOptions {
102
102
  /**
103
103
  * Whether to lazy load the diagram when it enters the viewport.
104
104
  * Can be a boolean or an object with IntersectionObserver options.
105
+ * The threshold must be between 0 and 1, inclusive.
105
106
  * @default true
106
107
  */
107
108
  lazy?: boolean | {
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.1.0"
6
6
  },
7
- "version": "3.0.4",
7
+ "version": "3.0.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -94,7 +94,9 @@ function extractInlineAttrsBlock(info) {
94
94
  for (let i = startIndex; i < info.length; i++) {
95
95
  const char = info[i];
96
96
  if (quote) {
97
- if (char === quote && info[i - 1] !== "\\")
97
+ if (char === "\\")
98
+ i += 1;
99
+ else if (char === quote)
98
100
  quote = null;
99
101
  continue;
100
102
  }
@@ -126,7 +128,7 @@ function parseInlineAttrsBlock(raw) {
126
128
  index += 1;
127
129
  const key = raw.slice(keyStart, index).trim();
128
130
  if (!key)
129
- break;
131
+ return null;
130
132
  index = skipWhitespace(raw, index);
131
133
  let value = true;
132
134
  if (index < raw.length && (raw[index] === "=" || raw[index] === ":")) {
@@ -206,7 +208,9 @@ function readBalancedValue(input, start) {
206
208
  for (let i = start; i < input.length; i++) {
207
209
  const char = input[i];
208
210
  if (quote) {
209
- if (char === quote && input[i - 1] !== "\\")
211
+ if (char === "\\")
212
+ i += 1;
213
+ else if (char === quote)
210
214
  quote = null;
211
215
  continue;
212
216
  }
@@ -434,7 +438,7 @@ function resolveMarkdownToolbar(layers) {
434
438
  }
435
439
 
436
440
  const MERMAID_COMPONENT_NAME = "ContentMermaidTransport";
437
- const PAGE_MERMAID_CONFIG_EXPRESSION = "config";
441
+ const PAGE_RENDER_DATA_EXPRESSION = "runtimeData";
438
442
  function serializeInlineAttributeRecord(value) {
439
443
  return JSON.stringify(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;");
440
444
  }
@@ -484,7 +488,7 @@ function transformMarkdownDiagrams(body) {
484
488
  };
485
489
  const buildComponentTag = (encoded, toolbar) => {
486
490
  const attrs = [
487
- `:page-config="${PAGE_MERMAID_CONFIG_EXPRESSION}"`
491
+ `:page-data="${PAGE_RENDER_DATA_EXPRESSION}"`
488
492
  ];
489
493
  if (toolbar && isNonEmptyRecord(toolbar)) {
490
494
  attrs.push(`:toolbar='${serializeInlineAttributeRecord(toolbar)}'`);
@@ -15,6 +15,7 @@ import { defu } from "defu";
15
15
  import { materializeMermaidConfigForInvocation, resolveMermaidTheme } from "../mermaid-config";
16
16
  import { createMermaidRenderer } from "../mermaid-rendering";
17
17
  import { getRuntimeMermaidSnapshot } from "../runtime-snapshot";
18
+ import { createPngRasterizerLoader } from "../png-rasterizer-loader";
18
19
  import {
19
20
  createSafeStandaloneSvgClone,
20
21
  downloadBlob,
@@ -34,10 +35,7 @@ import IconCollapse from "../components/icons/IconCollapse.vue";
34
35
  import IconDownload from "../components/icons/IconDownload.vue";
35
36
  import MermaidFullscreenPresentation from "../components/MermaidFullscreenPresentation.vue";
36
37
  import { DEFAULT_TOOLBAR_LABELS } from "../constants";
37
- let pngRasterizerModulePromise;
38
- function loadPngRasterizer() {
39
- return pngRasterizerModulePromise ??= import("../png-rasterizer");
40
- }
38
+ const loadPngRasterizer = createPngRasterizerLoader(() => import("../png-rasterizer"));
41
39
  const props = defineProps({
42
40
  toolbar: { type: Object, required: false },
43
41
  code: { type: String, required: false },
@@ -1,7 +1,9 @@
1
1
  import type { PageMermaidConfig } from '../../types/config.js';
2
2
  import type { MermaidToolbarOptions } from '../../types/mermaid.js';
3
3
  type __VLS_Props = {
4
- pageConfig?: PageMermaidConfig | null;
4
+ pageData?: {
5
+ config?: PageMermaidConfig | null;
6
+ };
5
7
  toolbar?: MermaidToolbarOptions;
6
8
  code?: string;
7
9
  };
@@ -1,13 +1,14 @@
1
1
  <script setup>
2
2
  import { computed, resolveComponent } from "vue";
3
3
  const props = defineProps({
4
- pageConfig: { type: [Object, null], required: false },
4
+ pageData: { type: Object, required: false },
5
5
  toolbar: { type: Object, required: false },
6
6
  code: { type: String, required: false }
7
7
  });
8
- const normalizedPageConfig = computed(
9
- () => props.pageConfig === null ? void 0 : props.pageConfig
10
- );
8
+ const normalizedPageConfig = computed(() => {
9
+ const config = props.pageData?.config;
10
+ return config === null ? void 0 : config;
11
+ });
11
12
  const MermaidComponent = resolveComponent("Mermaid");
12
13
  </script>
13
14
 
@@ -1,7 +1,9 @@
1
1
  import type { PageMermaidConfig } from '../../types/config.js';
2
2
  import type { MermaidToolbarOptions } from '../../types/mermaid.js';
3
3
  type __VLS_Props = {
4
- pageConfig?: PageMermaidConfig | null;
4
+ pageData?: {
5
+ config?: PageMermaidConfig | null;
6
+ };
5
7
  toolbar?: MermaidToolbarOptions;
6
8
  code?: string;
7
9
  };
@@ -106,6 +106,10 @@ export function validateRuntimeOptions(value, phase) {
106
106
  assertPlainObject(lazy, phase);
107
107
  assertKnownKeys(lazy, /* @__PURE__ */ new Set(["threshold"]), phase, ["loader", "lazy"]);
108
108
  assertNumberProperty(lazy, "threshold", phase, ["loader", "lazy"]);
109
+ const threshold = descriptorValue(lazy, "threshold");
110
+ if (typeof threshold === "number" && (threshold < 0 || threshold > 1)) {
111
+ throwConfigurationIssue(phase, ["loader", "lazy", "threshold"], "INVALID_VALUE", "a number between 0 and 1", "out-of-range-number");
112
+ }
109
113
  }
110
114
  }
111
115
  }
@@ -0,0 +1,3 @@
1
+ type PngRasterizerModule = typeof import('./png-rasterizer');
2
+ export declare function createPngRasterizerLoader(importModule: () => Promise<PngRasterizerModule>): () => Promise<typeof import("./png-rasterizer.js")>;
3
+ export {};
@@ -0,0 +1,7 @@
1
+ export function createPngRasterizerLoader(importModule) {
2
+ let modulePromise;
3
+ return () => modulePromise ??= importModule().catch((error) => {
4
+ modulePromise = void 0;
5
+ throw error;
6
+ });
7
+ }
@@ -0,0 +1,91 @@
1
+ import type { MermaidConfig } from 'mermaid'
2
+ import type { ExpandOptions } from '../runtime/types/expand'
3
+ import type { MermaidToolbarOptions } from './mermaid'
4
+
5
+ export type JsonPrimitive = string | number | boolean | null
6
+ export type JsonValue = JsonPrimitive | JsonObject | JsonValue[]
7
+ export type JsonObject = { [key: string]: JsonValue }
8
+
9
+ type IsAny<T> = 0 extends (1 & T) ? true : false
10
+
11
+ type RuntimeDataMember<T> = IsAny<T> extends true
12
+ ? never
13
+ : T extends JsonPrimitive
14
+ ? T
15
+ : T extends (...args: never[]) => unknown
16
+ ? never
17
+ : T extends readonly (infer Item)[]
18
+ ? RuntimeDataMember<Item>[]
19
+ : T extends object
20
+ ? { [Key in keyof T]: RuntimeDataMember<T[Key]> }
21
+ : never
22
+
23
+ export type RuntimeMermaidConfig = RuntimeDataMember<MermaidConfig> & JsonObject
24
+ export type PageMermaidConfig = RuntimeMermaidConfig
25
+
26
+ export interface RuntimeOptions {
27
+ /**
28
+ * Enable debug mode for detailed logging and error reporting
29
+ * @default false
30
+ */
31
+ debug?: boolean
32
+ /**
33
+ * Options related to loading mermaid
34
+ */
35
+ loader?: {
36
+ /**
37
+ * Pure-data configuration passed through Nuxt public runtime config.
38
+ */
39
+ init?: RuntimeMermaidConfig
40
+ /**
41
+ * Whether to lazy load the diagram when it enters the viewport.
42
+ * Can be a boolean or an object with IntersectionObserver options.
43
+ * The threshold must be between 0 and 1, inclusive.
44
+ * @default true
45
+ */
46
+ lazy?: boolean | { threshold?: number }
47
+ }
48
+ /**
49
+ * Options related to theme handling
50
+ */
51
+ theme?: {
52
+ /** @deprecated No effect; retained for 3.0 compatibility. */
53
+ useColorModeTheme?: boolean
54
+ light?: MermaidConfig['theme']
55
+ dark?: MermaidConfig['theme']
56
+ }
57
+ /**
58
+ * Names for custom implementation components
59
+ */
60
+ components?: {
61
+ renderer?: string
62
+ spinner?: string
63
+ error?: string
64
+ }
65
+ /**
66
+ * Expand configuration. `false` disables expand, `true` uses defaults.
67
+ */
68
+ expand?: ExpandOptions | boolean
69
+ /**
70
+ * Default toolbar settings for Mermaid component
71
+ */
72
+ toolbar?: MermaidToolbarOptions
73
+ }
74
+
75
+ export interface ModuleOptions extends RuntimeOptions {
76
+ /**
77
+ * Whether to enable the entire Mermaid process at build time.
78
+ * @default true
79
+ */
80
+ enabled?: boolean
81
+ }
82
+
83
+ interface MermaidComponentBaseProps {
84
+ toolbar?: MermaidToolbarOptions
85
+ code?: string
86
+ }
87
+
88
+ export type MermaidComponentProps = MermaidComponentBaseProps & (
89
+ | { pageConfig?: PageMermaidConfig, config?: never }
90
+ | { pageConfig?: never, config?: MermaidConfig }
91
+ )
@@ -0,0 +1,78 @@
1
+ import type { DefineComponent } from 'vue'
2
+ import type { Mermaid } from 'mermaid'
3
+ import type { MermaidComponentProps, ModuleOptions, RuntimeOptions } from './config'
4
+ import type { MermaidThemeMode, SimpleMermaidTheme } from '../runtime/composables/useMermaidTheme'
5
+
6
+ export type MermaidToolbarButtons = {
7
+ copy?: boolean
8
+ fullscreen?: boolean
9
+ expand?: boolean
10
+ }
11
+
12
+ export type MermaidToolbarLabels = {
13
+ copy?: string
14
+ copied?: string
15
+ copyFailed?: string
16
+ expand?: string
17
+ collapse?: string
18
+ minimize?: string
19
+ enterFullscreen?: string
20
+ exitFullscreen?: string
21
+ zoomIn?: string
22
+ zoomOut?: string
23
+ resetZoom?: string
24
+ download?: string
25
+ downloadSvg?: string
26
+ downloadPng?: string
27
+ }
28
+
29
+ export type MermaidToolbarOptions = {
30
+ title?: string
31
+ fontSize?: string | number
32
+ fullscreenToolbarScale?: number
33
+ buttons?: MermaidToolbarButtons
34
+ labels?: MermaidToolbarLabels
35
+ }
36
+
37
+ declare module '#app' {
38
+ interface NuxtApp {
39
+ $mermaid: () => Promise<Mermaid>
40
+ }
41
+ }
42
+ declare module 'vue' {
43
+ interface ComponentCustomProperties {
44
+ $mermaid: () => Promise<Mermaid>
45
+ }
46
+ interface GlobalComponents {
47
+ Mermaid: DefineComponent<MermaidComponentProps>
48
+ }
49
+ }
50
+
51
+ declare module '@nuxt/schema' {
52
+ interface NuxtConfig {
53
+ contentMermaid?: ModuleOptions
54
+ }
55
+
56
+ interface NuxtOptions {
57
+ contentMermaid?: ModuleOptions
58
+ }
59
+
60
+ interface PublicRuntimeConfig {
61
+ contentMermaid?: RuntimeOptions
62
+ }
63
+ }
64
+
65
+ declare global {
66
+ interface ImportMeta {
67
+ glob<T = unknown>(
68
+ pattern: string,
69
+ options?: {
70
+ eager?: boolean
71
+ import?: string
72
+ },
73
+ ): Record<string, () => Promise<T>>
74
+ }
75
+ }
76
+
77
+ export type { MermaidThemeMode, SimpleMermaidTheme }
78
+ export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barzhsieh/nuxt-content-mermaid",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "A Nuxt module designed for integrating Mermaid with `@nuxt/content`. It automatically converts `mermaid` code blocks in Markdown into responsive chart components, and supports lazy loading and dark/light theme switching.",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -89,7 +89,7 @@
89
89
  "release:prepare:major": "changelogen --release --major --no-commit --no-tag --no-github && pnpm install --lockfile-only --ignore-scripts",
90
90
  "release:prepare:minor": "changelogen --release --minor --no-commit --no-tag --no-github && pnpm install --lockfile-only --ignore-scripts",
91
91
  "release:prepare:patch": "changelogen --release --patch --no-commit --no-tag --no-github && pnpm install --lockfile-only --ignore-scripts",
92
- "test": "vitest run",
92
+ "test": "vitest run --exclude test/packagePrepack.test.ts && vitest run test/packagePrepack.test.ts",
93
93
  "test:package-artifact": "node scripts/release-verification/package-artifact.mjs --profile v3-known-latest",
94
94
  "test:compatibility-profile": "node scripts/release-verification/package-artifact.mjs",
95
95
  "test:package-contract": "pnpm prepack && vue-tsc -p test/release-verification/consumer-template/type-contracts/tsconfig.json --noEmit",