@ai-react-markdown/mantine 2.3.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,10 +38,10 @@ yarn add @ai-react-markdown/mantine @ai-react-markdown/core
38
38
  {
39
39
  "react": ">=19",
40
40
  "react-dom": ">=19",
41
- "@ai-react-markdown/core": "^2.3.2",
41
+ "@ai-react-markdown/core": "^2.4.0",
42
42
  "@mantine/core": "^9.0.0",
43
43
  "@mantine/code-highlight": "^9.0.0",
44
- "highlight.js": "^11.11.1"
44
+ "highlight.js": "^11.11.2"
45
45
  }
46
46
  ```
47
47
 
@@ -206,13 +206,13 @@ Activated by importing `@ai-react-markdown/mantine/styles.css` in your app entry
206
206
 
207
207
  The Mantine package installs a default `<pre>` renderer (`MantineAIMPreCode`) that powers all code-block features. Behavior by code-block flavor:
208
208
 
209
- | Code-block flavor | Rendered as | Notes |
210
- | ------------------------------------------ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
211
- | Annotated, known language (e.g. ` ```ts `) | `<CodeHighlightTabs>` | Tab label = language name |
212
- | Annotated, unknown language identifier | `<CodeHighlight>` plaintext | Filename label shows the unknown identifier |
213
- | No language annotation | `<CodeHighlight>` plaintext | Label = `"unknown"`. With `codeBlock.autoDetectUnknownLanguage: true`, `hljs.highlightAuto` is consulted before falling back |
214
- | ` ```mermaid ` | Interactive Mermaid diagram | See [Mermaid Diagrams](#mermaid-diagrams) |
215
- | ` ```json ` | Pretty-printed JSON | Deep-parsed via `deep-parse-json` to expand any nested JSON-encoded strings, then re-serialized with 2-space indent before rendering |
209
+ | Code-block flavor | Rendered as | Notes |
210
+ | ------------------------------------------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
211
+ | Annotated, known language (e.g. ` ```ts `) | `<CodeHighlightTabs>` | Tab label = language name |
212
+ | Annotated, unknown language identifier | `<CodeHighlightTabs>` | Tab label = the identifier as written; Mantine's highlight adapter degrades an unknown language to plaintext |
213
+ | No language annotation | `<CodeHighlight>` plaintext | Label = `"unknown"`. With `codeBlock.autoDetectUnknownLanguage: true`, `hljs.highlightAuto` guesses early, re-checks as the block grows, and settles at end of stream — label/highlighting upgrade in place |
214
+ | ` ```mermaid ` (any case) | Interactive Mermaid diagram | See [Mermaid Diagrams](#mermaid-diagrams); the language match is case-insensitive |
215
+ | ` ```json ` (any case) | Pretty-printed JSON | As soon as the block looks complete (ends in `}`/`]`), deep-parsed via `deep-parse-json` to expand any nested JSON-encoded strings, then re-serialized with 2-space indent before rendering |
216
216
 
217
217
  All non-special blocks render with `withBorder` and `withExpandButton`, collapsing to `maxCollapsedHeight="320px"` until expanded.
218
218
 
@@ -243,11 +243,23 @@ By default, code blocks without an explicit language annotation render as plaint
243
243
  <MantineAIMarkdown content={markdown} codeBlock={{ autoDetectUnknownLanguage: true }} />
244
244
  ```
245
245
 
246
- This uses `highlight.js`'s `highlightAuto` to guess the language. Results may vary for short or ambiguous snippets.
246
+ This uses `highlight.js`'s `highlightAuto` to guess the language. Results may vary for short or ambiguous snippets. While a block streams, detection runs on a doubling schedule — a first guess once the block has ~32 characters, a corrective re-run each time it has doubled in length, and a final verdict when the stream ends — so a long block gets an early label and periodic corrections at O(n) total cost instead of a full re-score on every chunk. The full `highlight.js` build is loaded on demand the first time it is needed; the package itself no longer imports the root `highlight.js` entry, so consumers who register only the languages they need via `highlight.js/lib/core` keep that bundle saving unless they turn this option on.
247
+
248
+ ### Preloading the on-demand assets
249
+
250
+ `mermaid` and (for auto-detection) `highlight.js` are loaded lazily by the code-block renderers. An app that would rather pay that cost at startup — a documentation page whose first screen shows a diagram, or a chat UI that wants zero first-diagram latency — calls the exported helper once at boot:
251
+
252
+ ```tsx
253
+ import { preloadMantineCodeAssets } from '@ai-react-markdown/mantine';
254
+
255
+ void preloadMantineCodeAssets(); // idempotent; failures are swallowed and the renderers fall back to lazy loading
256
+ ```
257
+
258
+ Importing the modules yourself at app entry (`import 'mermaid'`) has the same effect under a bundler: the dynamic import then resolves to the already-loaded module.
247
259
 
248
260
  ## Mermaid Diagrams
249
261
 
250
- Fenced code blocks with the `mermaid` language identifier render as interactive SVG diagrams:
262
+ Fenced code blocks with the `mermaid` language identifier render as interactive SVG diagrams. The `mermaid` module is loaded on demand — the first diagram that renders pays the import (the raw source shows as a code block while it loads), and an app whose content never contains a mermaid fence never downloads it:
251
263
 
252
264
  ````markdown
253
265
  ```mermaid
package/dist/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  default: () => MantineAIMarkdown_default,
36
36
  defaultMantineCodeBlockOptions: () => defaultMantineCodeBlockOptions,
37
37
  defineMantineBehaviors: () => defineMantineBehaviors,
38
+ preloadMantineCodeAssets: () => preloadMantineCodeAssets,
38
39
  useMantineAIMarkdownMetadata: () => useMantineAIMarkdownMetadata,
39
40
  useMantineCodeBlockOptions: () => useMantineCodeBlockOptions
40
41
  });
@@ -64,7 +65,6 @@ var DefaultExtraStyles_default = MantineAIMDefaultExtraStyles;
64
65
  var import_react4 = require("react");
65
66
  var import_code_highlight2 = require("@mantine/code-highlight");
66
67
  var import_deep_parse_json = require("deep-parse-json");
67
- var import_highlight = __toESM(require("highlight.js"), 1);
68
68
  var import_core5 = require("@ai-react-markdown/core");
69
69
 
70
70
  // src/hooks/useMantineCodeBlockOptions.ts
@@ -81,23 +81,34 @@ var defaultMantineCodeBlockOptions = Object.freeze({
81
81
  function useMantineCodeBlockOptions() {
82
82
  const behaviors = (0, import_core2.useAIMarkdownBehaviors)();
83
83
  const group = behaviors.codeBlock;
84
- return (0, import_react2.useMemo)(() => ({ ...defaultMantineCodeBlockOptions, ...group }), [group]);
84
+ return (0, import_react2.useMemo)(() => {
85
+ const resolved = { ...defaultMantineCodeBlockOptions };
86
+ for (const key of Object.keys(defaultMantineCodeBlockOptions)) {
87
+ const value = group?.[key];
88
+ if (value !== void 0) resolved[key] = value;
89
+ }
90
+ return resolved;
91
+ }, [group]);
85
92
  }
86
93
 
87
94
  // src/components/customized/MermaidCode/index.tsx
88
95
  var import_react3 = require("react");
89
96
  var import_code_highlight = require("@mantine/code-highlight");
90
97
  var import_core3 = require("@mantine/core");
91
- var import_mermaid = __toESM(require("mermaid"), 1);
92
98
  var import_core4 = require("@ai-react-markdown/core");
93
99
  var import_jsx_runtime3 = require("react/jsx-runtime");
94
100
  var PRE_STYLE = { cursor: "pointer", overflow: "auto", width: "100%", padding: "0.5rem" };
95
101
  var sameView = (a, b) => a.kind === "diagram" && b.kind === "diagram" ? a.chartType === b.chartType : a.kind === b.kind;
102
+ var mermaidPromise = null;
103
+ var loadMermaid = () => {
104
+ mermaidPromise ??= import("mermaid").then((m) => m.default);
105
+ return mermaidPromise;
106
+ };
96
107
  var initializedTheme = null;
97
- var ensureMermaidInitialized = (isDark) => {
108
+ var ensureMermaidInitialized = (mermaid, isDark) => {
98
109
  const theme = isDark ? "dark" : "light";
99
110
  if (initializedTheme === theme) return;
100
- import_mermaid.default.initialize({
111
+ mermaid.initialize({
101
112
  startOnLoad: false,
102
113
  securityLevel: "strict",
103
114
  theme: isDark ? "dark" : "base",
@@ -122,9 +133,7 @@ var handleViewSVGInNewWindow = (svgElement, isDark) => {
122
133
  const blob = new Blob([text], { type: "image/svg+xml" });
123
134
  const url = URL.createObjectURL(blob);
124
135
  const win = window.open(url);
125
- if (win) {
126
- setTimeout(() => URL.revokeObjectURL(url), 5e3);
127
- }
136
+ setTimeout(() => URL.revokeObjectURL(url), win ? 5e3 : 0);
128
137
  };
129
138
  var MantineAIMMermaidCode = (0, import_react3.memo)((props) => {
130
139
  const { colorScheme, fontSize } = (0, import_core4.useAIMarkdownTheme)();
@@ -166,15 +175,27 @@ var MantineAIMMermaidCode = (0, import_react3.memo)((props) => {
166
175
  let cancelled = false;
167
176
  const renderMermaid = async () => {
168
177
  try {
169
- ensureMermaidInitialized(isDark);
170
- const parseResult = await import_mermaid.default.parse(props.code);
178
+ const mermaid = await loadMermaid();
179
+ if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {
180
+ return;
181
+ }
182
+ ensureMermaidInitialized(mermaid, isDark);
183
+ const parseResult = await mermaid.parse(props.code);
171
184
  if (!parseResult) {
172
185
  throw new Error("Failed to parse mermaid code");
173
186
  }
174
187
  if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {
175
188
  return;
176
189
  }
177
- const { svg, bindFunctions, diagramType } = await import_mermaid.default.render(generateMermaidUUID(), props.code);
190
+ let rendered = await mermaid.render(generateMermaidUUID(), props.code);
191
+ if (initializedTheme !== (isDark ? "dark" : "light")) {
192
+ if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {
193
+ return;
194
+ }
195
+ ensureMermaidInitialized(mermaid, isDark);
196
+ rendered = await mermaid.render(generateMermaidUUID(), props.code);
197
+ }
198
+ const { svg, bindFunctions, diagramType } = rendered;
178
199
  if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {
179
200
  return;
180
201
  }
@@ -339,6 +360,44 @@ var MermaidCode_default = MantineAIMMermaidCode;
339
360
 
340
361
  // src/components/customized/PreCode.tsx
341
362
  var import_jsx_runtime4 = require("react/jsx-runtime");
363
+ var hljsAutoPromise = null;
364
+ var loadHljsForAutoDetect = () => {
365
+ hljsAutoPromise ??= import("highlight.js").then((m) => m.default);
366
+ return hljsAutoPromise;
367
+ };
368
+ var AUTODETECT_MIN_CHARS = 32;
369
+ function useAutoDetectedLanguage(codeText, enabled, streaming) {
370
+ const [detected, setDetected] = (0, import_react4.useState)(
371
+ null
372
+ );
373
+ (0, import_react4.useEffect)(() => {
374
+ if (!enabled || codeText.length < AUTODETECT_MIN_CHARS) return;
375
+ const due = detected === null || // Not streaming: the verdict must be for THIS text (end-of-stream, or a
376
+ // static content update).
377
+ !streaming && detected.finalFor !== codeText || // Streaming: doubled since the last guess.
378
+ streaming && codeText.length >= detected.atLength * 2;
379
+ if (!due) return;
380
+ let cancelled = false;
381
+ void loadHljsForAutoDetect().then((hljs) => {
382
+ if (cancelled) return;
383
+ setDetected({
384
+ language: hljs.highlightAuto(codeText).language ?? "",
385
+ atLength: codeText.length,
386
+ finalFor: streaming ? null : codeText
387
+ });
388
+ });
389
+ return () => {
390
+ cancelled = true;
391
+ };
392
+ }, [codeText, enabled, streaming]);
393
+ return enabled ? detected?.language ?? "" : "";
394
+ }
395
+ function preloadMantineCodeAssets() {
396
+ return Promise.all([import("mermaid"), loadHljsForAutoDetect()]).then(
397
+ () => void 0,
398
+ () => void 0
399
+ );
400
+ }
342
401
  var SpecialCodeLanguage = /* @__PURE__ */ ((SpecialCodeLanguage2) => {
343
402
  SpecialCodeLanguage2["Mermaid"] = "mermaid";
344
403
  return SpecialCodeLanguage2;
@@ -347,26 +406,24 @@ var SPECIAL_LANGUAGES = new Set(Object.values(SpecialCodeLanguage));
347
406
  var MantineAIMPreCode = (0, import_react4.memo)(
348
407
  (props) => {
349
408
  const { fontSize } = (0, import_core5.useAIMarkdownTheme)();
409
+ const { streaming } = (0, import_core5.useAIMarkdownState)();
350
410
  const { autoDetectUnknownLanguage, defaultExpanded } = useMantineCodeBlockOptions();
351
- const codeLanguage = (0, import_react4.useMemo)(() => {
352
- if (props.existLanguage) return props.existLanguage;
353
- if (autoDetectUnknownLanguage) {
354
- return import_highlight.default.highlightAuto(props.codeText).language || "";
355
- }
356
- return "";
357
- }, [props.existLanguage, props.codeText, autoDetectUnknownLanguage]);
358
- const [usedCodeLanguage, usedFileName] = (0, import_react4.useMemo)(() => {
359
- if (!codeLanguage) return ["plaintext", "unknown"];
360
- if (!import_highlight.default.getLanguage(codeLanguage)) {
361
- return ["plaintext", codeLanguage];
362
- }
363
- return [codeLanguage, codeLanguage];
364
- }, [codeLanguage]);
411
+ const detectedLanguage = useAutoDetectedLanguage(
412
+ props.codeText,
413
+ autoDetectUnknownLanguage && !props.existLanguage,
414
+ streaming
415
+ );
416
+ const codeLanguage = (props.existLanguage || detectedLanguage).toLowerCase();
417
+ const [usedCodeLanguage, usedFileName] = (0, import_react4.useMemo)(
418
+ () => codeLanguage ? [codeLanguage, codeLanguage] : ["plaintext", "unknown"],
419
+ [codeLanguage]
420
+ );
365
421
  const isSpecialCodeBlock = SPECIAL_LANGUAGES.has(codeLanguage);
366
422
  const normalCodeBlockContent = (0, import_react4.useMemo)(() => {
367
423
  if (isSpecialCodeBlock) return null;
368
424
  let usedCodeStr = props.codeText;
369
- if (usedCodeStr && usedCodeLanguage.toLowerCase() === "json") {
425
+ const looksComplete = /[}\]]\s*$/.test(usedCodeStr);
426
+ if (usedCodeStr && (looksComplete || !streaming) && usedCodeLanguage === "json") {
370
427
  const deepParsedResult = (0, import_deep_parse_json.deepParseJson)(usedCodeStr);
371
428
  usedCodeStr = typeof deepParsedResult === "string" ? deepParsedResult : JSON.stringify(deepParsedResult, null, 2);
372
429
  }
@@ -401,7 +458,7 @@ var MantineAIMPreCode = (0, import_react4.memo)(
401
458
  maxCollapsedHeight: "320px"
402
459
  }
403
460
  );
404
- }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, usedFileName, fontSize, defaultExpanded]);
461
+ }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, usedFileName, fontSize, defaultExpanded, streaming]);
405
462
  const specialCodeBlockContent = (0, import_react4.useMemo)(() => {
406
463
  switch (codeLanguage) {
407
464
  case "mermaid" /* Mermaid */:
@@ -431,7 +488,7 @@ var DefaultCustomComponents = {
431
488
  }
432
489
  const key = `pre-code-${node?.position?.start?.offset || 0}`;
433
490
  const detectedLanguage = code.properties?.className?.find((className) => className.startsWith("language-"))?.substring("language-".length);
434
- const codeText = code.children.map((child) => child.value ?? "").join("\n");
491
+ const codeText = code.children.map((child) => child.value ?? "").join("");
435
492
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PreCode_default, { codeText, existLanguage: detectedLanguage }, key);
436
493
  }
437
494
  };
@@ -484,6 +541,7 @@ var useMantineAIMarkdownMetadata = () => {
484
541
  MantineAIMarkdownTypography,
485
542
  defaultMantineCodeBlockOptions,
486
543
  defineMantineBehaviors,
544
+ preloadMantineCodeAssets,
487
545
  useMantineAIMarkdownMetadata,
488
546
  useMantineCodeBlockOptions
489
547
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","../src/MantineAIMarkdown.tsx","../src/components/typography/MantineTypography.tsx","../src/components/extra-styles/DefaultExtraStyles/index.tsx","../src/components/customized/PreCode.tsx","../src/hooks/useMantineCodeBlockOptions.ts","../src/defs.tsx","../src/components/customized/MermaidCode/index.tsx","../src/define.ts","../src/hooks/useMantineAIMarkdownMetadata.ts"],"sourcesContent":["/**\n * Public API surface for `@ai-react-markdown/mantine`.\n *\n * Re-exports the Mantine-integrated AI markdown component, its supporting\n * sub-components, extended types, default configuration, and typed hooks.\n *\n * @packageDocumentation\n */\n\n// --- Components ---\n\n/** Props for the main {@link MantineAIMarkdown} component. */\nexport type { MantineAIMarkdownProps } from './MantineAIMarkdown';\n\n/** Main component -- Mantine-integrated AI markdown renderer (default export). */\nexport { default } from './MantineAIMarkdown';\n\n/** Mantine-themed typography wrapper used by default inside {@link MantineAIMarkdown}. */\nexport { default as MantineAIMarkdownTypography } from './components/typography/MantineTypography';\n\n/** Default extra styles wrapper providing Mantine-compatible CSS scoping and overrides. */\nexport { default as MantineAIMDefaultExtraStyles } from './components/extra-styles/DefaultExtraStyles';\n\n// --- Types, config, and hooks ---\n\n/** Extended render configuration and metadata types for the Mantine integration. */\nexport type { MantineAIMarkdownMetadata, MantineCodeBlockOptions } from './defs';\n\n// ── v2 surface (props-api v2) ───────────────────────────────────────────────\n\n/** Shipped defaults of the `codeBlock` behavior group. */\nexport { defaultMantineCodeBlockOptions } from './defs';\n\n/** Narrow hook for the `codeBlock` behavior group — the single assertion site. */\nexport { useMantineCodeBlockOptions } from './hooks/useMantineCodeBlockOptions';\n\n/** Widened behaviors factory (core fields + mantine's `codeBlock` group). */\nexport { defineMantineBehaviors } from './define';\nexport type { MantineBehaviorProps } from './define';\n\n/** Typed hook for accessing metadata within the Mantine AI markdown tree. */\nexport { useMantineAIMarkdownMetadata } from './hooks/useMantineAIMarkdownMetadata';\n","/**\n * Main Mantine integration component for AI markdown rendering.\n *\n * Wraps the core {@link AIMarkdown} component with Mantine-specific defaults:\n * - {@link MantineAIMarkdownTypography} as the typography wrapper\n * - {@link MantineAIMDefaultExtraStyles} as the extra styles wrapper\n * - {@link MantineAIMPreCode} as the default `<pre>` component (with syntax\n * highlighting via Mantine's CodeHighlight and mermaid diagram support)\n * - Automatic color scheme detection via Mantine's `useComputedColorScheme`\n *\n * @module MantineAIMarkdown\n */\n\nimport { memo, useMemo } from 'react';\nimport AIMarkdown from '@ai-react-markdown/core';\nimport {\n type AIMarkdownProps,\n type AIMarkdownCustomComponents,\n type AIMarkdownBehaviorGroups,\n type AIMarkdownStabilityTable,\n AIMarkdownBehaviorsProvider,\n AIMarkdownStabilityPolicy,\n useStableRecord,\n useStableValue,\n} from '@ai-react-markdown/core';\nimport MantineAIMarkdownTypography from './components/typography/MantineTypography';\nimport MantineAIMDefaultExtraStyles from './components/extra-styles/DefaultExtraStyles';\nimport { MantineAIMarkdownMetadata, MantineCodeBlockOptions } from './defs';\nimport MantineAIMPreCode from './components/customized/PreCode';\nimport { useComputedColorScheme } from '@mantine/core';\n\n/**\n * Props for the {@link MantineAIMarkdown} component.\n *\n * Extends {@link AIMarkdownProps} with the mantine behavior groups.\n * All core props (`content`, `streaming`, `fontSize`, `enginePlugins`, etc.)\n * are inherited.\n *\n * @typeParam TMetadata - Metadata type, defaults to {@link MantineAIMarkdownMetadata}.\n */\nexport interface MantineAIMarkdownProps<\n TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata,\n> extends AIMarkdownProps<TMetadata> {\n /**\n * Code-block behavior group (Behaviors system). The group value replaces\n * atomically; omitted fields resolve to the shipped defaults inside\n * `useMantineCodeBlockOptions()`. `null` counts as absent. When absent,\n * this wrapper contributes NO `codeBlock` group, so a group provided by\n * an outer app-level `AIMarkdownBehaviorsProvider` passes through; when\n * present, this prop wins over any outer group (inner-wins merge).\n */\n codeBlock?: Partial<MantineCodeBlockOptions>;\n}\n\n/**\n * Stable empty CONTRIBUTION for the absent-prop case. Deliberately carries\n * no `codeBlock` key at all: contributing `codeBlock: {}` would shadow a\n * group provided by an outer app-level `AIMarkdownBehaviorsProvider`\n * (inner-wins merge) even though this wrapper has nothing to say — the\n * documented app-level extension path would silently go dead.\n */\nconst NO_GROUPS: AIMarkdownBehaviorGroups = Object.freeze({});\n\n/**\n * Mantine's stability-firewall table — one row today: `codeBlock` is the\n * only object prop this wrapper TERMINATES (consumes in its own machinery).\n * Forwarded object props ride core's firewall untouched; the merged\n * `customComponents` derived below is caught by core's wall.\n */\nconst MANTINE_STABILITY_TABLE: AIMarkdownStabilityTable<{\n codeBlock: Partial<MantineCodeBlockOptions> | undefined;\n}> = {\n codeBlock: AIMarkdownStabilityPolicy.DEEP_EQUAL,\n};\n\n/**\n * Default custom component overrides applied by the Mantine integration.\n *\n * Overrides the `<pre>` element to extract code blocks and render them via\n * {@link MantineAIMPreCode}, which provides syntax highlighting, expand/collapse,\n * and mermaid diagram support. Falls back to a plain `<pre>` when the child\n * is not a recognized code element.\n */\nconst DefaultCustomComponents: AIMarkdownCustomComponents = {\n pre: ({ node, ...usefulProps }) => {\n const code = node?.children[0] as\n | {\n type: string;\n tagName?: string;\n position?: { start?: { offset?: number } };\n properties?: Record<string, unknown>;\n children: { value?: string }[];\n }\n | undefined;\n if (!code || code.type !== 'element' || code.tagName !== 'code' || !code.position) {\n return <pre {...usefulProps} />;\n }\n const key = `pre-code-${node?.position?.start?.offset || 0}`;\n const detectedLanguage = (code.properties?.className as string[])\n ?.find((className: string) => className.startsWith('language-'))\n ?.substring('language-'.length);\n const codeText = code.children.map((child: { value?: string }) => child.value ?? '').join('\\n');\n return <MantineAIMPreCode key={key} codeText={codeText} existLanguage={detectedLanguage} />;\n },\n};\n\n/**\n * Inner (non-memoized) implementation of the Mantine AI markdown component.\n *\n * Merges caller-provided `customComponents` with the Mantine defaults (the caller's\n * overrides take precedence). Automatically resolves the color scheme from Mantine's\n * `useComputedColorScheme` when no explicit `colorScheme` prop is provided.\n *\n * @typeParam TMetadata - Metadata type.\n */\nconst MantineAIMarkdownComponent = <TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata>({\n Typography = MantineAIMarkdownTypography,\n ExtraStyles = MantineAIMDefaultExtraStyles,\n customComponents,\n colorScheme,\n codeBlock,\n ...props\n}: MantineAIMarkdownProps<TMetadata>) => {\n const stableCustomComponents = useStableValue(customComponents);\n\n const usedComponents = useMemo(() => {\n return stableCustomComponents ? { ...DefaultCustomComponents, ...stableCustomComponents } : DefaultCustomComponents;\n }, [stableCustomComponents]);\n\n const computedColorScheme = useComputedColorScheme('light');\n\n // Mantine's stability firewall: `codeBlock` is terminated here (it feeds\n // the behaviors Provider below, not the core prop surface).\n const stable = useStableRecord({ codeBlock }, MANTINE_STABILITY_TABLE);\n\n // Contribute the group through the additive behaviors Provider — firewall\n // output used directly, record identity memoized so the context value\n // stays stable across unrelated re-renders. `null`/absent prop ≡ no\n // contribution (NOT an empty group): an outer app-level Provider's\n // `codeBlock` group then stays visible; when the prop IS present the\n // inner-wins merge gives this wrapper's value precedence. The narrow hook\n // fills the defaults for the no-group-anywhere case.\n const behaviorGroups = useMemo<AIMarkdownBehaviorGroups>(\n () => (stable.codeBlock != null ? { codeBlock: stable.codeBlock } : NO_GROUPS),\n [stable.codeBlock]\n );\n\n return (\n <AIMarkdownBehaviorsProvider value={behaviorGroups}>\n <AIMarkdown<MantineAIMarkdownMetadata>\n Typography={Typography}\n ExtraStyles={ExtraStyles}\n customComponents={usedComponents}\n colorScheme={colorScheme ?? computedColorScheme}\n {...props}\n />\n </AIMarkdownBehaviorsProvider>\n );\n};\n\n/**\n * Mantine-integrated AI markdown renderer.\n *\n * A memoized wrapper around the core `<AIMarkdown>` component that provides\n * Mantine-themed typography, code highlighting (via `@mantine/code-highlight`),\n * mermaid diagram rendering, and automatic color scheme detection.\n *\n * This is the default export of `@ai-react-markdown/mantine`.\n *\n * @example\n * ```tsx\n * import MantineAIMarkdown from '@ai-react-markdown/mantine';\n *\n * function Chat({ content }: { content: string }) {\n * return <MantineAIMarkdown content={content} />;\n * }\n * ```\n */\nexport const MantineAIMarkdown = memo(MantineAIMarkdownComponent);\n\nMantineAIMarkdown.displayName = 'MantineAIMarkdown';\n\nexport default MantineAIMarkdown as typeof MantineAIMarkdownComponent;\n","import { memo } from 'react';\nimport { Typography } from '@mantine/core';\nimport type { AIMarkdownTypographyProps } from '@ai-react-markdown/core';\n\n/**\n * Mantine-themed typography wrapper for AI markdown content.\n *\n * Replaces the core default typography component with Mantine's `<Typography>`\n * element, applying the configured `fontSize` at full width. This ensures all\n * rendered markdown inherits Mantine's font family, line height, and theming.\n *\n * Used as the default `Typography` prop in {@link MantineAIMarkdown}.\n * Can be replaced by passing a custom `Typography` component.\n *\n * @param props - Standard {@link AIMarkdownTypographyProps} from the core package.\n */\nconst MantineAIMarkdownTypography = memo(({ children, fontSize, style }: AIMarkdownTypographyProps) => (\n <Typography w=\"100%\" fz={fontSize} style={style}>\n {children}\n </Typography>\n));\n\nMantineAIMarkdownTypography.displayName = 'MantineAIMarkdownTypography';\n\nexport default MantineAIMarkdownTypography;\n","import React from 'react';\nimport { AIMarkdownExtraStylesComponent } from '@ai-react-markdown/core';\nimport './styles.scss';\n\n/**\n * Default extra styles wrapper for the Mantine integration.\n *\n * Wraps markdown content in a `<div>` with the `aim-mantine-extra-styles` CSS class,\n * which provides Mantine-compatible typography overrides including:\n * - Relative `em`-based Mantine spacing and font-size CSS custom properties\n * - Heading, list, paragraph, blockquote, and code styling\n * - Definition list layout\n *\n * Used as the default `ExtraStyles` prop in {@link MantineAIMarkdown}.\n */\nconst MantineAIMDefaultExtraStyles: AIMarkdownExtraStylesComponent = ({ children }) => {\n return <div className=\"aim-mantine-extra-styles\">{children}</div>;\n};\n\nexport default MantineAIMDefaultExtraStyles;\n","'use client';\n\nimport { HTMLAttributes, memo, useMemo } from 'react';\nimport { CodeHighlight, CodeHighlightTabs } from '@mantine/code-highlight';\nimport { deepParseJson } from 'deep-parse-json';\nimport hljs from 'highlight.js';\nimport { useAIMarkdownTheme } from '@ai-react-markdown/core';\nimport { useMantineCodeBlockOptions } from '../../hooks/useMantineCodeBlockOptions';\nimport MantineAIMMermaidCode from './MermaidCode';\n\n/**\n * Code languages that receive specialized rendering instead of standard\n * syntax-highlighted code blocks. Adding a new member here automatically\n * marks that language as \"special\" — you only need to add the corresponding\n * rendering branch in the component's return.\n */\nenum SpecialCodeLanguage {\n /** Rendered as interactive diagrams via {@link MantineAIMMermaidCode} */\n Mermaid = 'mermaid',\n}\n\n/** O(1) lookup set, derived from {@link SpecialCodeLanguage}. */\nconst SPECIAL_LANGUAGES = new Set<string>(Object.values(SpecialCodeLanguage));\n\n/**\n * Mantine code block renderer for `<pre>` elements.\n *\n * Replaces the default `<pre>` rendering with Mantine's {@link CodeHighlight} or\n * {@link CodeHighlightTabs} components, providing syntax highlighting, expand/collapse\n * behavior, and file-name tabs.\n *\n * Behavior:\n * - If the code block has an explicit language annotation, uses that language.\n * - If no language is specified and the `codeBlock` group's\n * `autoDetectUnknownLanguage` option is enabled, uses `highlight.js`\n * auto-detection.\n * - Mermaid code blocks (`language-mermaid`) are rendered as interactive diagrams\n * via {@link MantineAIMMermaidCode}.\n * - JSON code blocks are deep-parsed and pretty-printed before display.\n * - Unrecognized languages render as plaintext with an \"unknown\" label using\n * {@link CodeHighlight} (no tabs).\n * - Recognized languages render with {@link CodeHighlightTabs} showing the\n * language name as the tab label.\n *\n * @param props.codeText - The raw text content of the code block.\n * @param props.existLanguage - Language identifier extracted from the `language-*` CSS class, if present.\n */\nconst MantineAIMPreCode = memo(\n (\n props: HTMLAttributes<HTMLPreElement> & {\n codeText: string;\n existLanguage?: string;\n }\n ) => {\n const { fontSize } = useAIMarkdownTheme();\n const { autoDetectUnknownLanguage, defaultExpanded } = useMantineCodeBlockOptions();\n\n const codeLanguage = useMemo(() => {\n if (props.existLanguage) return props.existLanguage;\n if (autoDetectUnknownLanguage) {\n return hljs.highlightAuto(props.codeText).language || '';\n }\n return '';\n }, [props.existLanguage, props.codeText, autoDetectUnknownLanguage]);\n\n const [usedCodeLanguage, usedFileName] = useMemo(() => {\n if (!codeLanguage) return ['plaintext', 'unknown'];\n if (!hljs.getLanguage(codeLanguage)) {\n return ['plaintext', codeLanguage];\n }\n return [codeLanguage, codeLanguage];\n }, [codeLanguage]);\n\n const isSpecialCodeBlock = SPECIAL_LANGUAGES.has(codeLanguage);\n\n const normalCodeBlockContent = useMemo(() => {\n if (isSpecialCodeBlock) return null;\n let usedCodeStr = props.codeText;\n if (usedCodeStr && usedCodeLanguage.toLowerCase() === 'json') {\n const deepParsedResult = deepParseJson(usedCodeStr);\n usedCodeStr =\n typeof deepParsedResult === 'string' ? deepParsedResult : JSON.stringify(deepParsedResult, null, 2);\n }\n return usedFileName === 'unknown' ? (\n <CodeHighlight\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={usedCodeStr}\n withBorder\n withExpandButton\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n />\n ) : (\n <CodeHighlightTabs\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={[\n {\n fileName: usedFileName,\n code: usedCodeStr,\n language: usedCodeLanguage,\n },\n ]}\n withBorder\n withExpandButton\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n />\n );\n }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, usedFileName, fontSize, defaultExpanded]);\n\n const specialCodeBlockContent = useMemo(() => {\n switch (codeLanguage) {\n case SpecialCodeLanguage.Mermaid:\n return <MantineAIMMermaidCode code={props.codeText} />;\n default:\n return null;\n }\n }, [codeLanguage, props.codeText]);\n\n return isSpecialCodeBlock ? specialCodeBlockContent : normalCodeBlockContent;\n }\n);\n\nMantineAIMPreCode.displayName = 'MantineAIMPreCode';\n\nexport default MantineAIMPreCode;\n","/**\n * Narrow hook for the mantine `codeBlock` behavior group.\n *\n * This is THE single type-assertion site for the group (the pattern that\n * retires the public caller-asserted `TConfig` generic): the opaque\n * extension record from `useAIMarkdownBehaviors()` is narrowed here, and\n * group defaults are applied here — read sites must consume this hook and\n * never re-apply defaults with bare `??` (multiple read sites duplicating\n * defaults will drift).\n *\n * @module hooks/useMantineCodeBlockOptions\n */\n\nimport { useMemo } from 'react';\nimport { useAIMarkdownBehaviors } from '@ai-react-markdown/core';\nimport { defaultMantineCodeBlockOptions, type MantineCodeBlockOptions } from '../defs';\n\n/**\n * Read the resolved code-block options from the behaviors context.\n *\n * Group values replace atomically at the transport layer; defaults are\n * filled in here, so a partial group (e.g. `codeBlock={{ defaultExpanded:\n * false }}`) resolves the omitted fields to the shipped defaults.\n *\n * Must be called inside a `<MantineAIMarkdown>` (or any `<AIMarkdown>`\n * wrapped in the mantine Provider stack) — throws outside, same contract\n * as the core narrow hooks.\n */\nexport function useMantineCodeBlockOptions(): Required<MantineCodeBlockOptions> {\n const behaviors = useAIMarkdownBehaviors();\n // The single assertion: the `codeBlock` group key is owned by this\n // package, contributed by `MantineAIMarkdown` via its behaviors Provider.\n const group = behaviors.codeBlock as Partial<MantineCodeBlockOptions> | undefined;\n return useMemo(() => ({ ...defaultMantineCodeBlockOptions, ...group }), [group]);\n}\n","/**\n * Mantine-specific type definitions and defaults: the `codeBlock` behavior\n * group and the metadata extension point.\n *\n * @module defs\n */\n\nimport { AIMarkdownMetadata } from '@ai-react-markdown/core';\n\n/**\n * Code block rendering options (the mantine `codeBlock` behavior group).\n *\n * v2 transport: passed as the flat `codeBlock` prop on `MantineAIMarkdown`\n * (group value replaces atomically) and read through\n * `useMantineCodeBlockOptions()`, which applies the defaults below inside\n * the hook — the single place defaults live at read time.\n */\nexport interface MantineCodeBlockOptions {\n /**\n * Whether code blocks start in their expanded state.\n * When `false`, long code blocks are collapsed with an expand button.\n *\n * @default true\n */\n defaultExpanded: boolean;\n\n /**\n * When `true`, uses `highlight.js` auto-detection to determine the language\n * of code blocks that lack an explicit language annotation.\n *\n * @default false\n */\n autoDetectUnknownLanguage: boolean;\n}\n\n/** Shipped defaults for the `codeBlock` behavior group. */\nexport const defaultMantineCodeBlockOptions: Readonly<MantineCodeBlockOptions> = Object.freeze({\n defaultExpanded: true,\n autoDetectUnknownLanguage: false,\n});\n\n/**\n * Metadata type for the Mantine integration.\n *\n * Currently identical to {@link AIMarkdownMetadata}. Exists as an extension point\n * so that consumers can augment metadata in Mantine-specific wrappers without\n * needing to reference the core type directly.\n */\nexport interface MantineAIMarkdownMetadata extends AIMarkdownMetadata {}\n","'use client';\n\nimport React, { memo, useEffect, useRef, useState, useCallback } from 'react';\nimport { CodeHighlightControl, CodeHighlightTabs } from '@mantine/code-highlight';\nimport { ActionIcon, CopyButton, Flex, Tooltip } from '@mantine/core';\nimport mermaid from 'mermaid';\nimport { useAIMarkdownState, useAIMarkdownTheme } from '@ai-react-markdown/core';\nimport { useMantineCodeBlockOptions } from '../../../hooks/useMantineCodeBlockOptions';\nimport './styles.scss';\n\n/** Static `<pre>` style for the mermaid container. */\nconst PRE_STYLE = { cursor: 'pointer', overflow: 'auto', width: '100%', padding: '0.5rem' } as const;\n\n/**\n * What the component currently shows. One value instead of separate\n * `hasRendered`/`renderError`/`chartType` fields whose combinations had to\n * be kept coherent by hand:\n * - `source`: warm-up / SSR fallback — raw code as a plain code block\n * (nothing rendered yet this generation).\n * - `diagram`: the last successful SVG is up.\n * - `error`: the error tab — only a post-stream corrective failure or a\n * never-rendered static failure can enter this state.\n *\n * The user's source toggle (`showOriginalCode`) is deliberately NOT a\n * phase: it overlays any view and flipping it back must restore the prior\n * one unchanged.\n */\ntype MermaidView = { kind: 'source' } | { kind: 'diagram'; chartType: string } | { kind: 'error' };\n\n/** Equality used to skip no-op view updates — repeat mid-stream successes\n * of the same chart type must not re-render the host per chunk. */\nconst sameView = (a: MermaidView, b: MermaidView): boolean =>\n a.kind === 'diagram' && b.kind === 'diagram' ? a.chartType === b.chartType : a.kind === b.kind;\n\n/** Theme mermaid.initialize was last called with. mermaid's config is a\n * module-level singleton, so re-asserting an unchanged theme before every\n * render attempt (each streamed chunk re-runs the effect) is pure waste —\n * but instances under providers with DIFFERENT schemes must each\n * re-assert before their own render, so the cache is module-level and\n * checked per attempt rather than hoisted into a per-instance effect. */\nlet initializedTheme: 'dark' | 'light' | null = null;\n\nconst ensureMermaidInitialized = (isDark: boolean) => {\n const theme = isDark ? 'dark' : 'light';\n if (initializedTheme === theme) return;\n mermaid.initialize({\n startOnLoad: false,\n securityLevel: 'strict',\n theme: isDark ? 'dark' : 'base',\n darkMode: isDark,\n // Without a svgContainingElement, a draw-phase throw (an error that\n // got past mermaid.parse) leaves mermaid's temp element orphaned in\n // document.body — its error path only cleans up when this flag is\n // set. We render our own error tab anyway, so mermaid's built-in\n // error diagram is dead weight here regardless.\n suppressErrorRendering: true,\n });\n initializedTheme = theme;\n};\n\n/**\n * Generate a unique ID for mermaid SVG rendering.\n * Combines a timestamp with a random suffix to avoid collisions when\n * multiple mermaid diagrams render concurrently.\n *\n * @returns A unique string in the format `mermaid-{timestamp}-{random}`.\n */\nconst generateMermaidUUID = () => {\n return `mermaid-${new Date().getTime()}-${Math.random().toString(36).slice(2, 10)}`;\n};\n\n/**\n * Open the rendered mermaid SVG in a new browser window.\n *\n * Clones the SVG element, applies a background color matching the current\n * color scheme, serializes it to an object URL, and opens it in a new tab.\n * The object URL is revoked after a short delay to free memory.\n *\n * @param svgElement - The rendered SVG element to view, or `null`/`undefined` to no-op.\n * @param isDark - Whether the current color scheme is dark (used for background color).\n */\nconst handleViewSVGInNewWindow = (svgElement: SVGElement | null | undefined, isDark: boolean) => {\n if (!svgElement) return;\n const targetSvg = svgElement.cloneNode(true) as SVGElement;\n targetSvg.style.backgroundColor = isDark ? '#242424' : 'white';\n const text = new XMLSerializer().serializeToString(targetSvg);\n const blob = new Blob([text], { type: 'image/svg+xml' });\n const url = URL.createObjectURL(blob);\n const win = window.open(url);\n if (win) {\n setTimeout(() => URL.revokeObjectURL(url), 5000);\n }\n};\n\n/**\n * Interactive mermaid diagram renderer.\n *\n * Parses and renders mermaid diagram source code into an inline SVG visualization.\n * Automatically adapts to the current Mantine color scheme (light/dark) by\n * re-initializing mermaid with the appropriate theme.\n *\n * Features:\n * - Live SVG rendering with automatic dark/light theme switching\n * - Fallback to raw source code display on parse/render errors\n * - Toggle between rendered diagram and raw mermaid source\n * - Click on the rendered diagram to open the SVG in a new browser window\n * - Copy button for the raw mermaid source code\n * - Chart type label extracted from mermaid's parse result\n * - Preserves the last successful render across transient parse failures\n *\n * ## Streaming contract\n *\n * While `streaming` is true (from render state), the code prop is usually a\n * truncated prefix of the final diagram, so parse failures are *expected*,\n * not exceptional:\n * - Before the first successful render, the raw source is shown as a plain\n * code block (never the error tab).\n * - After a success, the last good SVG stays up; each subsequent chunk is\n * re-attempted and the diagram refreshes only on the next success.\n * - When streaming ends (`streaming` is an effect dep), one corrective pass\n * runs on the final code: success refreshes the diagram, failure surfaces\n * the real error tab — even over a previously rendered mid-stream diagram,\n * because that diagram no longer matches the final source. The pending\n * corrective obligation is tracked by `needsCorrectiveRef` (armed on the\n * streaming→false edge, consumed by the next completed attempt), so ONLY\n * that one pass may clobber a rendered diagram; any later failure (e.g. a\n * transient throw on a theme-flip re-render) falls back to the static rule\n * below.\n * - A streaming→true edge marks a NEW generation (chat \"regenerate\" reuses\n * the same component instance when the block's source offset — and thus\n * its React key — is unchanged). All per-generation state is reset so the\n * warm-up shows the new source instead of the previous generation's stale\n * diagram or error tab.\n *\n * ## Static contract (`streaming` stays false)\n *\n * Without streaming edges, failures follow the original conservative rule:\n * the error tab shows only while nothing has rendered yet. Once a diagram is\n * up, later failures (theme-flip re-render, a not-yet-complete `code` update\n * from a consumer that didn't pass `streaming`) keep the last good diagram\n * instead of clobbering it with an error.\n *\n * @param props.code - Raw mermaid diagram source code to render.\n */\nconst MantineAIMMermaidCode = memo((props: { code: string }) => {\n const { colorScheme, fontSize } = useAIMarkdownTheme();\n const { streaming } = useAIMarkdownState();\n const { defaultExpanded } = useMantineCodeBlockOptions();\n const isDark = colorScheme === 'dark';\n\n const ref = useRef<HTMLPreElement>(null);\n const renderVersionRef = useRef(0);\n /** Mirrors `view` for reads inside the async render closure — state reads\n * there can be stale when deps change mid-flight. */\n const viewRef = useRef<MermaidView>({ kind: 'source' });\n /** Previous `streaming` value, for edge detection in the effect. */\n const prevStreamingRef = useRef(false);\n /** Armed on the streaming→false edge: the next completed render attempt is\n * the end-of-stream corrective pass, whose failure must surface even over\n * a rendered diagram. Consumed (reset) by that attempt's success OR\n * surfaced failure, so later unrelated failures can't clobber the SVG. */\n const needsCorrectiveRef = useRef(false);\n /** Inputs of the render whose SVG currently sits in the host `<pre>`.\n * When the effect re-runs with the same (code, theme) pair — the\n * post-stream corrective flip on an already-final diagram, or returning\n * from the source view — the DOM already holds that exact render, so\n * the attempt (and its parse + temp-element render) is skipped. */\n const lastSuccessRef = useRef<{ code: string; isDark: boolean } | null>(null);\n const [view, setViewState] = useState<MermaidView>({ kind: 'source' });\n const [showOriginalCode, setShowOriginalCode] = useState(false);\n\n useEffect(() => {\n // View updates funnel through here so the ref mirror can't desync from\n // the state, and no-op updates are dropped (repeat mid-stream successes\n // and idempotent edge resets must not re-render the host per chunk).\n const applyView = (next: MermaidView) => {\n viewRef.current = next;\n setViewState((prev) => (sameView(prev, next) ? prev : next));\n };\n\n // Streaming edge detection MUST run before any early return — the first\n // chunk of a new stream can arrive while the code is still empty.\n if (streaming && !prevStreamingRef.current) {\n // Rising edge = a new generation is starting on this same instance\n // (same block offset → same React key → no remount on regenerate).\n // Reset all per-generation state so warm-up shows the incoming source,\n // not the previous generation's stale diagram or error tab. Everything\n // here is idempotent — a StrictMode double-run is harmless.\n needsCorrectiveRef.current = false;\n lastSuccessRef.current = null;\n applyView({ kind: 'source' });\n if (ref.current) {\n ref.current.innerHTML = '';\n }\n } else if (!streaming && prevStreamingRef.current) {\n // Falling edge = the stream just ended; arm the corrective pass.\n needsCorrectiveRef.current = true;\n }\n prevStreamingRef.current = streaming;\n if (!props.code || !ref.current || showOriginalCode) {\n return;\n }\n\n // The SVG in the DOM already came from exactly this (code, theme) pair —\n // nothing to recompute. This also SATISFIES a pending corrective\n // obligation: the identical successful render IS the verdict on the\n // final source, so the obligation is consumed, not left armed for some\n // later unrelated failure to inherit.\n if (lastSuccessRef.current?.code === props.code && lastSuccessRef.current.isDark === isDark) {\n needsCorrectiveRef.current = false;\n return;\n }\n\n const renderVersion = ++renderVersionRef.current;\n let cancelled = false;\n\n const renderMermaid = async () => {\n try {\n ensureMermaidInitialized(isDark);\n const parseResult = await mermaid.parse(props.code);\n if (!parseResult) {\n throw new Error('Failed to parse mermaid code');\n }\n\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n\n // Deliberately NOT passing `ref.current` as mermaid's\n // svgContainingElement: before the first success the host container\n // is hidden with `display: none` (source fallback is showing), and\n // mermaid measures text via getBBox during render — inside a\n // display:none subtree layout never runs, every measurement is 0,\n // and the diagram comes out as a ~16px SVG. With the argument\n // omitted, mermaid renders in a temp element appended to\n // `document.body` (its default path, cleaned up internally), so\n // measurement works no matter what our container is doing. The SVG\n // string is written into our own <pre> below either way.\n const { svg, bindFunctions, diagramType } = await mermaid.render(generateMermaidUUID(), props.code);\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n\n ref.current.innerHTML = svg;\n bindFunctions?.(ref.current);\n needsCorrectiveRef.current = false;\n lastSuccessRef.current = { code: props.code, isDark };\n applyView({ kind: 'diagram', chartType: diagramType });\n } catch {\n if (cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n // Mid-stream failures are expected (truncated code) — keep the last\n // good diagram / source placeholder and wait for more bytes. The\n // corrective pass after streaming ends reports real errors.\n if (streaming) {\n return;\n }\n // End-of-stream corrective pass: the final source no longer renders,\n // so the error must surface even over a mid-stream diagram. Consume\n // the obligation so later unrelated failures don't inherit it.\n if (needsCorrectiveRef.current) {\n needsCorrectiveRef.current = false;\n applyView({ kind: 'error' });\n return;\n }\n // Static rule: never clobber a rendered diagram (theme-flip\n // re-renders, un-flagged code updates from static consumers).\n if (viewRef.current.kind === 'diagram') {\n return;\n }\n applyView({ kind: 'error' });\n }\n };\n\n void renderMermaid();\n\n return () => {\n cancelled = true;\n };\n // `streaming` in the deps is what drives the end-of-stream corrective\n // pass: the flip to false re-runs this effect on the (unchanged) final\n // code, so the last state reflects the full diagram source.\n }, [props.code, isDark, showOriginalCode, streaming]);\n\n const viewSvgInNewWindow = useCallback(() => {\n handleViewSVGInNewWindow(ref.current?.querySelector('svg'), isDark);\n }, [isDark]);\n\n // Show the raw source instead of the diagram container when the user asked\n // for it, when the (post-stream) render failed, or before the first\n // successful render (SSR output and the streaming warm-up phase). The\n // diagram container below stays MOUNTED throughout — merely hidden — so\n // `ref` is always available for mermaid to render into; unmounting it would\n // make the effect's `!ref.current` guard bail forever.\n const showSourceFallback = showOriginalCode || view.kind !== 'diagram';\n\n return (\n <>\n {showSourceFallback && (\n <CodeHighlightTabs\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={[\n {\n fileName: view.kind === 'error' ? 'Mermaid Render Error' : 'mermaid',\n code: props.code,\n language: 'mermaid',\n },\n ]}\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n styles={{\n filesScrollarea: {\n right: '90px',\n },\n }}\n controls={\n // The \"Render Mermaid\" control only makes sense as the way back\n // from the user-toggled source view. In the error and warm-up\n // fallbacks `showOriginalCode` is already false, so the control\n // would be a no-op — hide it there. (No view-kind conjunct: the\n // toggle is only reachable from the visible diagram view, and\n // while the source view is open the effect early-returns, so\n // showOriginalCode && view.kind === 'error' is unreachable.)\n showOriginalCode\n ? [\n <CodeHighlightControl\n tooltipLabel=\"Render Mermaid\"\n key=\"gpt\"\n onClick={() => {\n setShowOriginalCode(false);\n }}\n >\n <Flex align=\"center\" justify=\"center\" w={18} h={18}>\n <span className=\"icon-[gravity-ui--logo-mermaid] relative bottom-[1px] text-[16px]\"></span>\n </Flex>\n </CodeHighlightControl>,\n ]\n : []\n }\n withBorder\n withExpandButton\n />\n )}\n <div\n className={`aim-mantine-mermaid-code ${isDark ? 'dark' : ''}`}\n style={\n showSourceFallback\n ? {\n display: 'none',\n }\n : {}\n }\n >\n <div className=\"chart-header\">\n <div className=\"chart-type-tag\">{view.kind === 'diagram' ? view.chartType : 'unknown'}</div>\n <Flex align=\"center\" justify=\"flex-end\" gap={0}>\n <Tooltip label=\"Show Mermaid Code\">\n <ActionIcon\n size={28}\n className=\"action-icon\"\n variant=\"transparent\"\n aria-label=\"Show Mermaid code\"\n onClick={() => {\n setShowOriginalCode(true);\n }}\n >\n <Flex align=\"center\" justify=\"center\" w={18} h={18}>\n <span className=\"icon-[entypo--code] relative bottom-[0.25px] text-[16px]\"></span>\n </Flex>\n </ActionIcon>\n </Tooltip>\n <CopyButton value={props.code}>\n {({ copied, copy }) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon\n variant=\"transparent\"\n size={28}\n className=\"action-icon\"\n aria-label={copied ? 'Mermaid code copied' : 'Copy Mermaid code'}\n onClick={copy}\n >\n {copied ? (\n <span className=\"icon-origin-[lucide--check] text-[18px]\"></span>\n ) : (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"2\"\n stroke=\"currentColor\"\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n width=\"18px\"\n height=\"18px\"\n >\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path>\n <path d=\"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z\"></path>\n <path d=\"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2\"></path>\n </svg>\n )}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\n </Flex>\n </div>\n <pre\n ref={ref}\n style={PRE_STYLE}\n role=\"button\"\n tabIndex={0}\n aria-label=\"Open Mermaid diagram in a new window\"\n onClick={viewSvgInNewWindow}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n viewSvgInNewWindow();\n }\n }}\n />\n </div>\n </>\n );\n});\n\nMantineAIMMermaidCode.displayName = 'MantineAIMMermaidCode';\n\nexport default MantineAIMMermaidCode;\n","/**\n * Widened `define*` factory for the mantine wrapper (EXECUTION-PLAN §4\n * item 8): identity + mantine prop types + freeze, zero logic. Core\n * factories accept core fields only — passing `codeBlock` to core's\n * `defineBehaviors` is a TS error; this widened factory is the wrapper's\n * one-line obligation.\n *\n * @module define\n */\n\nimport type { AIMarkdownBehaviorProps } from '@ai-react-markdown/core';\nimport type { MantineCodeBlockOptions } from './defs';\n\n/** Behavior-system props packagable at integration time, mantine-widened. */\nexport interface MantineBehaviorProps extends AIMarkdownBehaviorProps {\n /** The mantine `codeBlock` behavior group (atomic replacement; defaults applied at read time). */\n codeBlock?: Partial<MantineCodeBlockOptions>;\n}\n\n// NON-generic on purpose — see core's `define.ts`: a fresh literal is\n// excess-property checked against the concrete parameter type.\n\n/** Freeze a mantine behaviors fragment. Identity + types + freeze; zero logic. */\nexport function defineMantineBehaviors(values: MantineBehaviorProps): Readonly<MantineBehaviorProps> {\n return Object.freeze(values);\n}\n","import { useAIMarkdownMetadata } from '@ai-react-markdown/core';\nimport { MantineAIMarkdownMetadata } from '../defs';\n\n/**\n * Typed wrapper around the core {@link useAIMarkdownMetadata} hook.\n *\n * Returns the current metadata defaulting to {@link MantineAIMarkdownMetadata}.\n * Accepts an optional generic parameter for further extension.\n *\n * Metadata lives in a separate React context from the render state, meaning\n * metadata updates do not trigger re-renders in components that only consume\n * render state.\n *\n * Must be called inside a component rendered within the `<MantineAIMarkdown>` tree.\n *\n * @typeParam TMetadata - Metadata type (defaults to {@link MantineAIMarkdownMetadata}).\n * @returns The current metadata, or `undefined` if none was provided.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const metadata = useMantineAIMarkdownMetadata();\n * // Access Mantine-specific metadata fields\n * }\n * ```\n */\nexport const useMantineAIMarkdownMetadata = <\n TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata,\n>() => {\n return useAIMarkdownMetadata<TMetadata>();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaA,IAAAA,gBAA8B;AAC9B,IAAAC,eAAuB;AACvB,IAAAA,eASO;;;ACxBP,mBAAqB;AACrB,kBAA2B;AAgBzB;AADF,IAAM,kCAA8B,mBAAK,CAAC,EAAE,UAAU,UAAU,MAAM,MACpE,4CAAC,0BAAW,GAAE,QAAO,IAAI,UAAU,OAChC,UACH,CACD;AAED,4BAA4B,cAAc;AAE1C,IAAO,4BAAQ;;;ACRN,IAAAC,sBAAA;AADT,IAAM,+BAA+D,CAAC,EAAE,SAAS,MAAM;AACrF,SAAO,6CAAC,SAAI,WAAU,4BAA4B,UAAS;AAC7D;AAEA,IAAO,6BAAQ;;;ACjBf,IAAAC,gBAA8C;AAC9C,IAAAC,yBAAiD;AACjD,6BAA8B;AAC9B,uBAAiB;AACjB,IAAAC,eAAmC;;;ACOnC,IAAAC,gBAAwB;AACxB,IAAAC,eAAuC;;;ACsBhC,IAAM,iCAAoE,OAAO,OAAO;AAAA,EAC7F,iBAAiB;AAAA,EACjB,2BAA2B;AAC7B,CAAC;;;ADXM,SAAS,6BAAgE;AAC9E,QAAM,gBAAY,qCAAuB;AAGzC,QAAM,QAAQ,UAAU;AACxB,aAAO,uBAAQ,OAAO,EAAE,GAAG,gCAAgC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC;AACjF;;;AEhCA,IAAAC,gBAAsE;AACtE,4BAAwD;AACxD,IAAAC,e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AAC9F,WAAO,6CAAC,mBAA4B,UAAoB,eAAe,oBAAxC,GAA0D;AAAA,EAC3F;AACF;AAWA,IAAM,6BAA6B,CAA0E;AAAA,EAC3G,YAAAC,cAAa;AAAA,EACb,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyC;AACvC,QAAM,6BAAyB,6BAAe,gBAAgB;AAE9D,QAAM,qBAAiB,uBAAQ,MAAM;AACnC,WAAO,yBAAyB,EAAE,GAAG,yBAAyB,GAAG,uBAAuB,IAAI;AAAA,EAC9F,GAAG,CAAC,sBAAsB,CAAC;AAE3B,QAAM,0BAAsB,qCAAuB,OAAO;AAI1D,QAAM,aAAS,8BAAgB,EAAE,UAAU,GAAG,uBAAuB;AASrE,QAAM,qBAAiB;AAAA,IACrB,MAAO,OAAO,aAAa,OAAO,EAAE,WAAW,OAAO,UAAU,IAAI;AAAA,IACpE,CAAC,OAAO,SAAS;AAAA,EACnB;AAEA,SACE,6CAAC,4CAA4B,OAAO,gBAClC;AAAA,IAAC,aAAAC;AAAA,IAAA;AAAA,MACC,YAAYD;AAAA,MACZ;AAAA,MACA,kBAAkB;AAAA,MAClB,aAAa,eAAe;AAAA,MAC3B,GAAG;AAAA;AAAA,EACN,GACF;AAEJ;AAoBO,IAAM,wBAAoB,oBAAK,0BAA0B;AAEhE,kBAAkB,cAAc;AAEhC,IAAO,4BAAQ;;;AO/JR,SAAS,uBAAuB,QAA8D;AACnG,SAAO,OAAO,OAAO,MAAM;AAC7B;;;ACzBA,IAAAE,eAAsC;AA0B/B,IAAM,+BAA+B,MAErC;AACL,aAAO,oCAAiC;AAC1C;","names":["import_react","import_core","import_jsx_runtime","import_react","import_code_highlight","import_core","import_react","import_core","import_react","import_core","import_jsx_runtime","mermaid","import_jsx_runtime","SpecialCodeLanguage","hljs","import_core","import_jsx_runtime","Typography","AIMarkdown","import_core"]}
1
+ {"version":3,"sources":["../src/index.tsx","../src/MantineAIMarkdown.tsx","../src/components/typography/MantineTypography.tsx","../src/components/extra-styles/DefaultExtraStyles/index.tsx","../src/components/customized/PreCode.tsx","../src/hooks/useMantineCodeBlockOptions.ts","../src/defs.tsx","../src/components/customized/MermaidCode/index.tsx","../src/define.ts","../src/hooks/useMantineAIMarkdownMetadata.ts"],"sourcesContent":["/**\n * Public API surface for `@ai-react-markdown/mantine`.\n *\n * Re-exports the Mantine-integrated AI markdown component, its supporting\n * sub-components, extended types, default configuration, and typed hooks.\n *\n * @packageDocumentation\n */\n\n// --- Components ---\n\n/** Props for the main {@link MantineAIMarkdown} component. */\nexport type { MantineAIMarkdownProps } from './MantineAIMarkdown';\n\n/** Main component -- Mantine-integrated AI markdown renderer (default export). */\nexport { default } from './MantineAIMarkdown';\n\n/** Mantine-themed typography wrapper used by default inside {@link MantineAIMarkdown}. */\nexport { default as MantineAIMarkdownTypography } from './components/typography/MantineTypography';\n\n/** Default extra styles wrapper providing Mantine-compatible CSS scoping and overrides. */\nexport { default as MantineAIMDefaultExtraStyles } from './components/extra-styles/DefaultExtraStyles';\n\n// --- Types, config, and hooks ---\n\n/** Extended render configuration and metadata types for the Mantine integration. */\nexport type { MantineAIMarkdownMetadata, MantineCodeBlockOptions } from './defs';\n\n// ── v2 surface (props-api v2) ───────────────────────────────────────────────\n\n/** Shipped defaults of the `codeBlock` behavior group. */\nexport { defaultMantineCodeBlockOptions } from './defs';\n\n/** Narrow hook for the `codeBlock` behavior group — the single assertion site. */\nexport { useMantineCodeBlockOptions } from './hooks/useMantineCodeBlockOptions';\n\n/** Optional eager loading of the on-demand code-block assets (mermaid, highlight.js). */\nexport { preloadMantineCodeAssets } from './components/customized/PreCode';\n\n/** Widened behaviors factory (core fields + mantine's `codeBlock` group). */\nexport { defineMantineBehaviors } from './define';\nexport type { MantineBehaviorProps } from './define';\n\n/** Typed hook for accessing metadata within the Mantine AI markdown tree. */\nexport { useMantineAIMarkdownMetadata } from './hooks/useMantineAIMarkdownMetadata';\n","/**\n * Main Mantine integration component for AI markdown rendering.\n *\n * Wraps the core {@link AIMarkdown} component with Mantine-specific defaults:\n * - {@link MantineAIMarkdownTypography} as the typography wrapper\n * - {@link MantineAIMDefaultExtraStyles} as the extra styles wrapper\n * - {@link MantineAIMPreCode} as the default `<pre>` component (with syntax\n * highlighting via Mantine's CodeHighlight and mermaid diagram support)\n * - Automatic color scheme detection via Mantine's `useComputedColorScheme`\n *\n * @module MantineAIMarkdown\n */\n\nimport { memo, useMemo } from 'react';\nimport AIMarkdown from '@ai-react-markdown/core';\nimport {\n type AIMarkdownProps,\n type AIMarkdownCustomComponents,\n type AIMarkdownBehaviorGroups,\n type AIMarkdownStabilityTable,\n AIMarkdownBehaviorsProvider,\n AIMarkdownStabilityPolicy,\n useStableRecord,\n useStableValue,\n} from '@ai-react-markdown/core';\nimport MantineAIMarkdownTypography from './components/typography/MantineTypography';\nimport MantineAIMDefaultExtraStyles from './components/extra-styles/DefaultExtraStyles';\nimport { MantineAIMarkdownMetadata, MantineCodeBlockOptions } from './defs';\nimport MantineAIMPreCode from './components/customized/PreCode';\nimport { useComputedColorScheme } from '@mantine/core';\n\n/**\n * Props for the {@link MantineAIMarkdown} component.\n *\n * Extends {@link AIMarkdownProps} with the mantine behavior groups.\n * All core props (`content`, `streaming`, `fontSize`, `enginePlugins`, etc.)\n * are inherited.\n *\n * @typeParam TMetadata - Metadata type, defaults to {@link MantineAIMarkdownMetadata}.\n */\nexport interface MantineAIMarkdownProps<\n TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata,\n> extends AIMarkdownProps<TMetadata> {\n /**\n * Code-block behavior group (Behaviors system). The group value replaces\n * atomically; omitted fields resolve to the shipped defaults inside\n * `useMantineCodeBlockOptions()`. `null` counts as absent. When absent,\n * this wrapper contributes NO `codeBlock` group, so a group provided by\n * an outer app-level `AIMarkdownBehaviorsProvider` passes through; when\n * present, this prop wins over any outer group (inner-wins merge).\n */\n codeBlock?: Partial<MantineCodeBlockOptions>;\n}\n\n/**\n * Stable empty CONTRIBUTION for the absent-prop case. Deliberately carries\n * no `codeBlock` key at all: contributing `codeBlock: {}` would shadow a\n * group provided by an outer app-level `AIMarkdownBehaviorsProvider`\n * (inner-wins merge) even though this wrapper has nothing to say — the\n * documented app-level extension path would silently go dead.\n */\nconst NO_GROUPS: AIMarkdownBehaviorGroups = Object.freeze({});\n\n/**\n * Mantine's stability-firewall table — one row today: `codeBlock` is the\n * only object prop this wrapper TERMINATES (consumes in its own machinery).\n * Forwarded object props ride core's firewall untouched; the merged\n * `customComponents` derived below is caught by core's wall.\n */\nconst MANTINE_STABILITY_TABLE: AIMarkdownStabilityTable<{\n codeBlock: Partial<MantineCodeBlockOptions> | undefined;\n}> = {\n codeBlock: AIMarkdownStabilityPolicy.DEEP_EQUAL,\n};\n\n/**\n * Default custom component overrides applied by the Mantine integration.\n *\n * Overrides the `<pre>` element to extract code blocks and render them via\n * {@link MantineAIMPreCode}, which provides syntax highlighting, expand/collapse,\n * and mermaid diagram support. Falls back to a plain `<pre>` when the child\n * is not a recognized code element.\n */\nconst DefaultCustomComponents: AIMarkdownCustomComponents = {\n pre: ({ node, ...usefulProps }) => {\n const code = node?.children[0] as\n | {\n type: string;\n tagName?: string;\n position?: { start?: { offset?: number } };\n properties?: Record<string, unknown>;\n children: { value?: string }[];\n }\n | undefined;\n if (!code || code.type !== 'element' || code.tagName !== 'code' || !code.position) {\n return <pre {...usefulProps} />;\n }\n const key = `pre-code-${node?.position?.start?.offset || 0}`;\n const detectedLanguage = (code.properties?.className as string[])\n ?.find((className: string) => className.startsWith('language-'))\n ?.substring('language-'.length);\n // A `<code>` inside `<pre>` normally carries ONE text child; if an\n // upstream plugin splits it, the pieces are contiguous source — join\n // with '' (a '\\n' joiner would invent line breaks the source lacks).\n const codeText = code.children.map((child: { value?: string }) => child.value ?? '').join('');\n return <MantineAIMPreCode key={key} codeText={codeText} existLanguage={detectedLanguage} />;\n },\n};\n\n/**\n * Inner (non-memoized) implementation of the Mantine AI markdown component.\n *\n * Merges caller-provided `customComponents` with the Mantine defaults (the caller's\n * overrides take precedence). Automatically resolves the color scheme from Mantine's\n * `useComputedColorScheme` when no explicit `colorScheme` prop is provided.\n *\n * @typeParam TMetadata - Metadata type.\n */\nconst MantineAIMarkdownComponent = <TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata>({\n Typography = MantineAIMarkdownTypography,\n ExtraStyles = MantineAIMDefaultExtraStyles,\n customComponents,\n colorScheme,\n codeBlock,\n ...props\n}: MantineAIMarkdownProps<TMetadata>) => {\n const stableCustomComponents = useStableValue(customComponents);\n\n const usedComponents = useMemo(() => {\n return stableCustomComponents ? { ...DefaultCustomComponents, ...stableCustomComponents } : DefaultCustomComponents;\n }, [stableCustomComponents]);\n\n const computedColorScheme = useComputedColorScheme('light');\n\n // Mantine's stability firewall: `codeBlock` is terminated here (it feeds\n // the behaviors Provider below, not the core prop surface).\n const stable = useStableRecord({ codeBlock }, MANTINE_STABILITY_TABLE);\n\n // Contribute the group through the additive behaviors Provider — firewall\n // output used directly, record identity memoized so the context value\n // stays stable across unrelated re-renders. `null`/absent prop ≡ no\n // contribution (NOT an empty group): an outer app-level Provider's\n // `codeBlock` group then stays visible; when the prop IS present the\n // inner-wins merge gives this wrapper's value precedence. The narrow hook\n // fills the defaults for the no-group-anywhere case.\n const behaviorGroups = useMemo<AIMarkdownBehaviorGroups>(\n () => (stable.codeBlock != null ? { codeBlock: stable.codeBlock } : NO_GROUPS),\n [stable.codeBlock]\n );\n\n return (\n <AIMarkdownBehaviorsProvider value={behaviorGroups}>\n <AIMarkdown<MantineAIMarkdownMetadata>\n Typography={Typography}\n ExtraStyles={ExtraStyles}\n customComponents={usedComponents}\n colorScheme={colorScheme ?? computedColorScheme}\n {...props}\n />\n </AIMarkdownBehaviorsProvider>\n );\n};\n\n/**\n * Mantine-integrated AI markdown renderer.\n *\n * A memoized wrapper around the core `<AIMarkdown>` component that provides\n * Mantine-themed typography, code highlighting (via `@mantine/code-highlight`),\n * mermaid diagram rendering, and automatic color scheme detection.\n *\n * This is the default export of `@ai-react-markdown/mantine`.\n *\n * @example\n * ```tsx\n * import MantineAIMarkdown from '@ai-react-markdown/mantine';\n *\n * function Chat({ content }: { content: string }) {\n * return <MantineAIMarkdown content={content} />;\n * }\n * ```\n */\nexport const MantineAIMarkdown = memo(MantineAIMarkdownComponent);\n\nMantineAIMarkdown.displayName = 'MantineAIMarkdown';\n\nexport default MantineAIMarkdown as typeof MantineAIMarkdownComponent;\n","import { memo } from 'react';\nimport { Typography } from '@mantine/core';\nimport type { AIMarkdownTypographyProps } from '@ai-react-markdown/core';\n\n/**\n * Mantine-themed typography wrapper for AI markdown content.\n *\n * Replaces the core default typography component with Mantine's `<Typography>`\n * element, applying the configured `fontSize` at full width. This ensures all\n * rendered markdown inherits Mantine's font family, line height, and theming.\n *\n * Used as the default `Typography` prop in {@link MantineAIMarkdown}.\n * Can be replaced by passing a custom `Typography` component.\n *\n * @param props - Standard {@link AIMarkdownTypographyProps} from the core package.\n */\nconst MantineAIMarkdownTypography = memo(({ children, fontSize, style }: AIMarkdownTypographyProps) => (\n <Typography w=\"100%\" fz={fontSize} style={style}>\n {children}\n </Typography>\n));\n\nMantineAIMarkdownTypography.displayName = 'MantineAIMarkdownTypography';\n\nexport default MantineAIMarkdownTypography;\n","import React from 'react';\nimport { AIMarkdownExtraStylesComponent } from '@ai-react-markdown/core';\nimport './styles.scss';\n\n/**\n * Default extra styles wrapper for the Mantine integration.\n *\n * Wraps markdown content in a `<div>` with the `aim-mantine-extra-styles` CSS class,\n * which provides Mantine-compatible typography overrides including:\n * - Relative `em`-based Mantine spacing and font-size CSS custom properties\n * - Heading, list, paragraph, blockquote, and code styling\n * - Definition list layout\n *\n * Used as the default `ExtraStyles` prop in {@link MantineAIMarkdown}.\n */\nconst MantineAIMDefaultExtraStyles: AIMarkdownExtraStylesComponent = ({ children }) => {\n return <div className=\"aim-mantine-extra-styles\">{children}</div>;\n};\n\nexport default MantineAIMDefaultExtraStyles;\n","'use client';\n\nimport { HTMLAttributes, memo, useEffect, useMemo, useState } from 'react';\nimport { CodeHighlight, CodeHighlightTabs } from '@mantine/code-highlight';\nimport { deepParseJson } from 'deep-parse-json';\nimport { useAIMarkdownState, useAIMarkdownTheme } from '@ai-react-markdown/core';\nimport { useMantineCodeBlockOptions } from '../../hooks/useMantineCodeBlockOptions';\nimport MantineAIMMermaidCode from './MermaidCode';\n\n/**\n * highlight.js is NOT imported statically any more: the root entry carries\n * every language definition (~130 KB gzip) and the only always-on use was a\n * `getLanguage()` existence check that Mantine's own adapter already\n * performs (unknown language → plaintext). Auto-detection is the one real\n * consumer, and it loads the module on demand — only when\n * `autoDetectUnknownLanguage` is on and an unlabelled block shows up\n * (2026-08 project review, pkg-small-02: the static import defeated\n * consumers' `highlight.js/lib/core` slimming). Consumers who want it (and\n * mermaid) in the main bundle up front call `preloadMantineCodeAssets()`\n * at app start, or simply import the modules themselves.\n */\nlet hljsAutoPromise: Promise<{ highlightAuto: (code: string) => { language?: string } }> | null = null;\nexport const loadHljsForAutoDetect = () => {\n hljsAutoPromise ??= import('highlight.js').then((m) => m.default);\n return hljsAutoPromise;\n};\n\n/** Below this many characters a guess is noise; the block stays \"unknown\". */\nconst AUTODETECT_MIN_CHARS = 32;\n\n/**\n * The language highlight.js guesses for an unlabelled block.\n *\n * `highlightAuto` scores every registered language against the whole text,\n * so re-running it on every streamed chunk was O(languages × n) per chunk —\n * O(n²) over a long block (pkg-small-06). Schedule instead:\n * - first guess as soon as the block has AUTODETECT_MIN_CHARS (an early\n * label rather than \"unknown\" for the whole stream);\n * - a corrective re-run each time the block has DOUBLED in length since\n * the last guess (32 → 64 → 128 → …): a wrong early guess on a long\n * block is fixed within its next doubling, and the total work stays\n * O(n) — at most log₂(n) runs;\n * - a final verdict when streaming ends (the last run always sees the\n * complete block).\n * Returns '' while disabled, still loading, or below the minimum, so the\n * block renders as plaintext/\"unknown\" and upgrades in place.\n */\nfunction useAutoDetectedLanguage(codeText: string, enabled: boolean, streaming: boolean): string {\n const [detected, setDetected] = useState<{ language: string; atLength: number; finalFor: string | null } | null>(\n null\n );\n useEffect(() => {\n if (!enabled || codeText.length < AUTODETECT_MIN_CHARS) return;\n const due =\n detected === null ||\n // Not streaming: the verdict must be for THIS text (end-of-stream, or a\n // static content update).\n (!streaming && detected.finalFor !== codeText) ||\n // Streaming: doubled since the last guess.\n (streaming && codeText.length >= detected.atLength * 2);\n if (!due) return;\n let cancelled = false;\n void loadHljsForAutoDetect().then((hljs) => {\n if (cancelled) return;\n setDetected({\n language: hljs.highlightAuto(codeText).language ?? '',\n atLength: codeText.length,\n finalFor: streaming ? null : codeText,\n });\n });\n return () => {\n cancelled = true;\n };\n // `detected` is deliberately not a dep: a completed guess must not\n // re-trigger the effect (it re-runs on the next content/streaming\n // change, which is when the schedule is re-evaluated).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [codeText, enabled, streaming]);\n return enabled ? (detected?.language ?? '') : '';\n}\n\n/**\n * Loads mermaid and highlight.js ahead of time. Both are imported on demand\n * by the code-block renderers (the first diagram / the first auto-detected\n * block pays the download); an app that would rather take that cost at\n * startup — a documentation page whose first screen shows a diagram, say —\n * calls this once at boot. Safe to call repeatedly; failures are swallowed\n * (the renderers will simply load lazily later).\n */\nexport function preloadMantineCodeAssets(): Promise<void> {\n return Promise.all([import('mermaid'), loadHljsForAutoDetect()]).then(\n () => undefined,\n () => undefined\n );\n}\n\n/**\n * Code languages that receive specialized rendering instead of standard\n * syntax-highlighted code blocks. Adding a new member here automatically\n * marks that language as \"special\" — you only need to add the corresponding\n * rendering branch in the component's return.\n */\nenum SpecialCodeLanguage {\n /** Rendered as interactive diagrams via {@link MantineAIMMermaidCode} */\n Mermaid = 'mermaid',\n}\n\n/** O(1) lookup set, derived from {@link SpecialCodeLanguage}. */\nconst SPECIAL_LANGUAGES = new Set<string>(Object.values(SpecialCodeLanguage));\n\n/**\n * Mantine code block renderer for `<pre>` elements.\n *\n * Replaces the default `<pre>` rendering with Mantine's {@link CodeHighlight} or\n * {@link CodeHighlightTabs} components, providing syntax highlighting, expand/collapse\n * behavior, and file-name tabs.\n *\n * Behavior:\n * - If the code block has an explicit language annotation, uses that language.\n * - If no language is specified and the `codeBlock` group's\n * `autoDetectUnknownLanguage` option is enabled, uses `highlight.js`\n * auto-detection.\n * - Mermaid code blocks (`language-mermaid`) are rendered as interactive diagrams\n * via {@link MantineAIMMermaidCode}.\n * - JSON code blocks are deep-parsed and pretty-printed before display.\n * - Unrecognized languages render as plaintext with an \"unknown\" label using\n * {@link CodeHighlight} (no tabs).\n * - Recognized languages render with {@link CodeHighlightTabs} showing the\n * language name as the tab label.\n *\n * @param props.codeText - The raw text content of the code block.\n * @param props.existLanguage - Language identifier extracted from the `language-*` CSS class, if present.\n */\nconst MantineAIMPreCode = memo(\n (\n props: HTMLAttributes<HTMLPreElement> & {\n codeText: string;\n existLanguage?: string;\n }\n ) => {\n const { fontSize } = useAIMarkdownTheme();\n const { streaming } = useAIMarkdownState();\n const { autoDetectUnknownLanguage, defaultExpanded } = useMantineCodeBlockOptions();\n\n const detectedLanguage = useAutoDetectedLanguage(\n props.codeText,\n autoDetectUnknownLanguage && !props.existLanguage,\n streaming\n );\n // Lower-cased once for every decision below: fence languages arrive in\n // whatever case the model wrote (` ```Mermaid `, ` ```JSON `), and both\n // the special-language switch and the JSON branch must agree\n // (2026-08 project review, pkg-small-08 — the mermaid check was\n // case-sensitive while the JSON check was not).\n const codeLanguage = (props.existLanguage || detectedLanguage).toLowerCase();\n\n // The language is passed straight to Mantine's highlighter, whose\n // adapter already degrades unknown languages to plaintext; the label\n // is \"unknown\" only when there is no language at all.\n const [usedCodeLanguage, usedFileName] = useMemo(\n () => (codeLanguage ? [codeLanguage, codeLanguage] : ['plaintext', 'unknown']),\n [codeLanguage]\n );\n\n const isSpecialCodeBlock = SPECIAL_LANGUAGES.has(codeLanguage);\n\n const normalCodeBlockContent = useMemo(() => {\n if (isSpecialCodeBlock) return null;\n let usedCodeStr = props.codeText;\n // JSON pretty-print as soon as the block LOOKS complete: a streamed\n // prefix never parses, so trying deepParseJson on every chunk of a\n // growing block was O(n²) work for nothing (pkg-small-06) — but a\n // block that finished mid-document must not wait for the whole\n // message to end. A complete JSON value ends in `}`, `]`, `\"`, a\n // digit or a literal; the cheap tell that rules out the common\n // in-progress shapes is \"ends with a closing bracket\".\n const looksComplete = /[}\\]]\\s*$/.test(usedCodeStr);\n if (usedCodeStr && (looksComplete || !streaming) && usedCodeLanguage === 'json') {\n const deepParsedResult = deepParseJson(usedCodeStr);\n usedCodeStr =\n typeof deepParsedResult === 'string' ? deepParsedResult : JSON.stringify(deepParsedResult, null, 2);\n }\n return usedFileName === 'unknown' ? (\n <CodeHighlight\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={usedCodeStr}\n withBorder\n withExpandButton\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n />\n ) : (\n <CodeHighlightTabs\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={[\n {\n fileName: usedFileName,\n code: usedCodeStr,\n language: usedCodeLanguage,\n },\n ]}\n withBorder\n withExpandButton\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n />\n );\n }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, usedFileName, fontSize, defaultExpanded, streaming]);\n\n const specialCodeBlockContent = useMemo(() => {\n switch (codeLanguage) {\n case SpecialCodeLanguage.Mermaid:\n return <MantineAIMMermaidCode code={props.codeText} />;\n default:\n return null;\n }\n }, [codeLanguage, props.codeText]);\n\n return isSpecialCodeBlock ? specialCodeBlockContent : normalCodeBlockContent;\n }\n);\n\nMantineAIMPreCode.displayName = 'MantineAIMPreCode';\n\nexport default MantineAIMPreCode;\n","/**\n * Narrow hook for the mantine `codeBlock` behavior group.\n *\n * This is THE single type-assertion site for the group (the pattern that\n * retires the public caller-asserted `TConfig` generic): the opaque\n * extension record from `useAIMarkdownBehaviors()` is narrowed here, and\n * group defaults are applied here — read sites must consume this hook and\n * never re-apply defaults with bare `??` (multiple read sites duplicating\n * defaults will drift).\n *\n * @module hooks/useMantineCodeBlockOptions\n */\n\nimport { useMemo } from 'react';\nimport { useAIMarkdownBehaviors } from '@ai-react-markdown/core';\nimport { defaultMantineCodeBlockOptions, type MantineCodeBlockOptions } from '../defs';\n\n/**\n * Read the resolved code-block options from the behaviors context.\n *\n * Group values replace atomically at the transport layer; defaults are\n * filled in here, so a partial group (e.g. `codeBlock={{ defaultExpanded:\n * false }}`) resolves the omitted fields to the shipped defaults.\n *\n * Must be called inside a `<MantineAIMarkdown>` (or any `<AIMarkdown>`\n * wrapped in the mantine Provider stack) — throws outside, same contract\n * as the core narrow hooks.\n */\nexport function useMantineCodeBlockOptions(): Required<MantineCodeBlockOptions> {\n const behaviors = useAIMarkdownBehaviors();\n // The single assertion: the `codeBlock` group key is owned by this\n // package, contributed by `MantineAIMarkdown` via its behaviors Provider.\n const group = behaviors.codeBlock as Partial<MantineCodeBlockOptions> | undefined;\n return useMemo(() => {\n // Field-wise `??` rather than a spread: `codeBlock={{ defaultExpanded:\n // undefined }}` type-checks, and a spread would let that explicit\n // undefined punch through the default while the signature promises\n // `Required<…>` (2026-08 project review, pkg-small-12).\n const resolved = { ...defaultMantineCodeBlockOptions } as Required<MantineCodeBlockOptions>;\n for (const key of Object.keys(defaultMantineCodeBlockOptions) as Array<keyof MantineCodeBlockOptions>) {\n const value = group?.[key];\n if (value !== undefined) (resolved as Record<string, unknown>)[key] = value;\n }\n return resolved;\n }, [group]);\n}\n","/**\n * Mantine-specific type definitions and defaults: the `codeBlock` behavior\n * group and the metadata extension point.\n *\n * @module defs\n */\n\nimport { AIMarkdownMetadata } from '@ai-react-markdown/core';\n\n/**\n * Code block rendering options (the mantine `codeBlock` behavior group).\n *\n * v2 transport: passed as the flat `codeBlock` prop on `MantineAIMarkdown`\n * (group value replaces atomically) and read through\n * `useMantineCodeBlockOptions()`, which applies the defaults below inside\n * the hook — the single place defaults live at read time.\n */\nexport interface MantineCodeBlockOptions {\n /**\n * Whether code blocks start in their expanded state.\n * When `false`, long code blocks are collapsed with an expand button.\n *\n * @default true\n */\n defaultExpanded: boolean;\n\n /**\n * When `true`, uses `highlight.js` auto-detection to determine the language\n * of code blocks that lack an explicit language annotation.\n *\n * @default false\n */\n autoDetectUnknownLanguage: boolean;\n}\n\n/** Shipped defaults for the `codeBlock` behavior group. */\nexport const defaultMantineCodeBlockOptions: Readonly<MantineCodeBlockOptions> = Object.freeze({\n defaultExpanded: true,\n autoDetectUnknownLanguage: false,\n});\n\n/**\n * Metadata type for the Mantine integration.\n *\n * Currently identical to {@link AIMarkdownMetadata}. Exists as an extension point\n * so that consumers can augment metadata in Mantine-specific wrappers without\n * needing to reference the core type directly.\n */\nexport interface MantineAIMarkdownMetadata extends AIMarkdownMetadata {}\n","'use client';\n\nimport React, { memo, useEffect, useRef, useState, useCallback } from 'react';\nimport { CodeHighlightControl, CodeHighlightTabs } from '@mantine/code-highlight';\nimport { ActionIcon, CopyButton, Flex, Tooltip } from '@mantine/core';\nimport type mermaidModule from 'mermaid';\nimport { useAIMarkdownState, useAIMarkdownTheme } from '@ai-react-markdown/core';\nimport { useMantineCodeBlockOptions } from '../../../hooks/useMantineCodeBlockOptions';\nimport './styles.scss';\n\n/** Static `<pre>` style for the mermaid container. */\nconst PRE_STYLE = { cursor: 'pointer', overflow: 'auto', width: '100%', padding: '0.5rem' } as const;\n\n/**\n * What the component currently shows. One value instead of separate\n * `hasRendered`/`renderError`/`chartType` fields whose combinations had to\n * be kept coherent by hand:\n * - `source`: warm-up / SSR fallback — raw code as a plain code block\n * (nothing rendered yet this generation).\n * - `diagram`: the last successful SVG is up.\n * - `error`: the error tab — only a post-stream corrective failure or a\n * never-rendered static failure can enter this state.\n *\n * The user's source toggle (`showOriginalCode`) is deliberately NOT a\n * phase: it overlays any view and flipping it back must restore the prior\n * one unchanged.\n */\ntype MermaidView = { kind: 'source' } | { kind: 'diagram'; chartType: string } | { kind: 'error' };\n\n/** Equality used to skip no-op view updates — repeat mid-stream successes\n * of the same chart type must not re-render the host per chunk. */\nconst sameView = (a: MermaidView, b: MermaidView): boolean =>\n a.kind === 'diagram' && b.kind === 'diagram' ? a.chartType === b.chartType : a.kind === b.kind;\n\ntype Mermaid = typeof mermaidModule;\n\n/**\n * mermaid is loaded on demand — the FIRST diagram that actually renders\n * pays the import; an app whose content never contains a mermaid fence\n * never downloads the ~1.5 MB module (2026-08 project review,\n * pkg-small-03: the static import sat on the default `pre` component's\n * import chain, so every consumer's main bundle carried it). The promise is\n * cached module-wide; the source-view warm-up covers the loading window.\n */\nlet mermaidPromise: Promise<Mermaid> | null = null;\nconst loadMermaid = (): Promise<Mermaid> => {\n mermaidPromise ??= import('mermaid').then((m) => m.default);\n return mermaidPromise;\n};\n\n/** Theme mermaid.initialize was last called with. mermaid's config is a\n * module-level singleton, so re-asserting an unchanged theme before every\n * render attempt (each streamed chunk re-runs the effect) is pure waste —\n * but instances under providers with DIFFERENT schemes must each\n * re-assert before their own render, so the cache is module-level and\n * checked per attempt rather than hoisted into a per-instance effect. */\nlet initializedTheme: 'dark' | 'light' | null = null;\n\nconst ensureMermaidInitialized = (mermaid: Mermaid, isDark: boolean) => {\n const theme = isDark ? 'dark' : 'light';\n if (initializedTheme === theme) return;\n mermaid.initialize({\n startOnLoad: false,\n securityLevel: 'strict',\n theme: isDark ? 'dark' : 'base',\n darkMode: isDark,\n // Without a svgContainingElement, a draw-phase throw (an error that\n // got past mermaid.parse) leaves mermaid's temp element orphaned in\n // document.body — its error path only cleans up when this flag is\n // set. We render our own error tab anyway, so mermaid's built-in\n // error diagram is dead weight here regardless.\n suppressErrorRendering: true,\n });\n initializedTheme = theme;\n};\n\n/**\n * Generate a unique ID for mermaid SVG rendering.\n * Combines a timestamp with a random suffix to avoid collisions when\n * multiple mermaid diagrams render concurrently.\n *\n * @returns A unique string in the format `mermaid-{timestamp}-{random}`.\n */\nconst generateMermaidUUID = () => {\n return `mermaid-${new Date().getTime()}-${Math.random().toString(36).slice(2, 10)}`;\n};\n\n/**\n * Open the rendered mermaid SVG in a new browser window.\n *\n * Clones the SVG element, applies a background color matching the current\n * color scheme, serializes it to an object URL, and opens it in a new tab.\n * The object URL is revoked after a short delay to free memory.\n *\n * @param svgElement - The rendered SVG element to view, or `null`/`undefined` to no-op.\n * @param isDark - Whether the current color scheme is dark (used for background color).\n */\nconst handleViewSVGInNewWindow = (svgElement: SVGElement | null | undefined, isDark: boolean) => {\n if (!svgElement) return;\n const targetSvg = svgElement.cloneNode(true) as SVGElement;\n targetSvg.style.backgroundColor = isDark ? '#242424' : 'white';\n const text = new XMLSerializer().serializeToString(targetSvg);\n const blob = new Blob([text], { type: 'image/svg+xml' });\n const url = URL.createObjectURL(blob);\n const win = window.open(url);\n // Revoke either way: when a popup blocker returns null nobody will ever\n // load the URL, and leaving it alive leaks the Blob until page unload\n // (2026-08 project review, pkg-small-09). The opened window needs the\n // grace period to finish loading it.\n setTimeout(() => URL.revokeObjectURL(url), win ? 5000 : 0);\n};\n\n/**\n * Interactive mermaid diagram renderer.\n *\n * Parses and renders mermaid diagram source code into an inline SVG visualization.\n * Automatically adapts to the current Mantine color scheme (light/dark) by\n * re-initializing mermaid with the appropriate theme.\n *\n * Features:\n * - Live SVG rendering with automatic dark/light theme switching\n * - Fallback to raw source code display on parse/render errors\n * - Toggle between rendered diagram and raw mermaid source\n * - Click on the rendered diagram to open the SVG in a new browser window\n * - Copy button for the raw mermaid source code\n * - Chart type label extracted from mermaid's parse result\n * - Preserves the last successful render across transient parse failures\n *\n * ## Streaming contract\n *\n * While `streaming` is true (from render state), the code prop is usually a\n * truncated prefix of the final diagram, so parse failures are *expected*,\n * not exceptional:\n * - Before the first successful render, the raw source is shown as a plain\n * code block (never the error tab).\n * - After a success, the last good SVG stays up; each subsequent chunk is\n * re-attempted and the diagram refreshes only on the next success.\n * - When streaming ends (`streaming` is an effect dep), one corrective pass\n * runs on the final code: success refreshes the diagram, failure surfaces\n * the real error tab — even over a previously rendered mid-stream diagram,\n * because that diagram no longer matches the final source. The pending\n * corrective obligation is tracked by `needsCorrectiveRef` (armed on the\n * streaming→false edge, consumed by the next completed attempt), so ONLY\n * that one pass may clobber a rendered diagram; any later failure (e.g. a\n * transient throw on a theme-flip re-render) falls back to the static rule\n * below.\n * - A streaming→true edge marks a NEW generation (chat \"regenerate\" reuses\n * the same component instance when the block's source offset — and thus\n * its React key — is unchanged). All per-generation state is reset so the\n * warm-up shows the new source instead of the previous generation's stale\n * diagram or error tab.\n *\n * ## Static contract (`streaming` stays false)\n *\n * Without streaming edges, failures follow the original conservative rule:\n * the error tab shows only while nothing has rendered yet. Once a diagram is\n * up, later failures (theme-flip re-render, a not-yet-complete `code` update\n * from a consumer that didn't pass `streaming`) keep the last good diagram\n * instead of clobbering it with an error.\n *\n * @param props.code - Raw mermaid diagram source code to render.\n */\nconst MantineAIMMermaidCode = memo((props: { code: string }) => {\n const { colorScheme, fontSize } = useAIMarkdownTheme();\n const { streaming } = useAIMarkdownState();\n const { defaultExpanded } = useMantineCodeBlockOptions();\n const isDark = colorScheme === 'dark';\n\n const ref = useRef<HTMLPreElement>(null);\n const renderVersionRef = useRef(0);\n /** Mirrors `view` for reads inside the async render closure — state reads\n * there can be stale when deps change mid-flight. */\n const viewRef = useRef<MermaidView>({ kind: 'source' });\n /** Previous `streaming` value, for edge detection in the effect. */\n const prevStreamingRef = useRef(false);\n /** Armed on the streaming→false edge: the next completed render attempt is\n * the end-of-stream corrective pass, whose failure must surface even over\n * a rendered diagram. Consumed (reset) by that attempt's success OR\n * surfaced failure, so later unrelated failures can't clobber the SVG. */\n const needsCorrectiveRef = useRef(false);\n /** Inputs of the render whose SVG currently sits in the host `<pre>`.\n * When the effect re-runs with the same (code, theme) pair — the\n * post-stream corrective flip on an already-final diagram, or returning\n * from the source view — the DOM already holds that exact render, so\n * the attempt (and its parse + temp-element render) is skipped. */\n const lastSuccessRef = useRef<{ code: string; isDark: boolean } | null>(null);\n const [view, setViewState] = useState<MermaidView>({ kind: 'source' });\n const [showOriginalCode, setShowOriginalCode] = useState(false);\n\n useEffect(() => {\n // View updates funnel through here so the ref mirror can't desync from\n // the state, and no-op updates are dropped (repeat mid-stream successes\n // and idempotent edge resets must not re-render the host per chunk).\n const applyView = (next: MermaidView) => {\n viewRef.current = next;\n setViewState((prev) => (sameView(prev, next) ? prev : next));\n };\n\n // Streaming edge detection MUST run before any early return — the first\n // chunk of a new stream can arrive while the code is still empty.\n if (streaming && !prevStreamingRef.current) {\n // Rising edge = a new generation is starting on this same instance\n // (same block offset → same React key → no remount on regenerate).\n // Reset all per-generation state so warm-up shows the incoming source,\n // not the previous generation's stale diagram or error tab. Everything\n // here is idempotent — a StrictMode double-run is harmless.\n needsCorrectiveRef.current = false;\n lastSuccessRef.current = null;\n applyView({ kind: 'source' });\n if (ref.current) {\n ref.current.innerHTML = '';\n }\n } else if (!streaming && prevStreamingRef.current) {\n // Falling edge = the stream just ended; arm the corrective pass.\n needsCorrectiveRef.current = true;\n }\n prevStreamingRef.current = streaming;\n if (!props.code || !ref.current || showOriginalCode) {\n return;\n }\n\n // The SVG in the DOM already came from exactly this (code, theme) pair —\n // nothing to recompute. This also SATISFIES a pending corrective\n // obligation: the identical successful render IS the verdict on the\n // final source, so the obligation is consumed, not left armed for some\n // later unrelated failure to inherit.\n if (lastSuccessRef.current?.code === props.code && lastSuccessRef.current.isDark === isDark) {\n needsCorrectiveRef.current = false;\n return;\n }\n\n const renderVersion = ++renderVersionRef.current;\n let cancelled = false;\n\n const renderMermaid = async () => {\n try {\n const mermaid = await loadMermaid();\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n ensureMermaidInitialized(mermaid, isDark);\n const parseResult = await mermaid.parse(props.code);\n if (!parseResult) {\n throw new Error('Failed to parse mermaid code');\n }\n\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n\n // Deliberately NOT passing `ref.current` as mermaid's\n // svgContainingElement: before the first success the host container\n // is hidden with `display: none` (source fallback is showing), and\n // mermaid measures text via getBBox during render — inside a\n // display:none subtree layout never runs, every measurement is 0,\n // and the diagram comes out as a ~16px SVG. With the argument\n // omitted, mermaid renders in a temp element appended to\n // `document.body` (its default path, cleaned up internally), so\n // measurement works no matter what our container is doing. The SVG\n // string is written into our own <pre> below either way.\n // mermaid's config is a module singleton and the awaits above yield:\n // an instance under the OTHER color scheme may have re-initialized\n // in between, in which case this render came out in the wrong theme.\n // Re-assert and render once more; a second flip is vanishingly\n // unlikely and would self-heal on the next attempt anyway\n // (2026-08 project review, pkg-small-11).\n let rendered = await mermaid.render(generateMermaidUUID(), props.code);\n if (initializedTheme !== (isDark ? 'dark' : 'light')) {\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n ensureMermaidInitialized(mermaid, isDark);\n rendered = await mermaid.render(generateMermaidUUID(), props.code);\n }\n const { svg, bindFunctions, diagramType } = rendered;\n if (!ref.current || cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n\n ref.current.innerHTML = svg;\n bindFunctions?.(ref.current);\n needsCorrectiveRef.current = false;\n lastSuccessRef.current = { code: props.code, isDark };\n applyView({ kind: 'diagram', chartType: diagramType });\n } catch {\n if (cancelled || renderVersion !== renderVersionRef.current) {\n return;\n }\n // Mid-stream failures are expected (truncated code) — keep the last\n // good diagram / source placeholder and wait for more bytes. The\n // corrective pass after streaming ends reports real errors.\n if (streaming) {\n return;\n }\n // End-of-stream corrective pass: the final source no longer renders,\n // so the error must surface even over a mid-stream diagram. Consume\n // the obligation so later unrelated failures don't inherit it.\n if (needsCorrectiveRef.current) {\n needsCorrectiveRef.current = false;\n applyView({ kind: 'error' });\n return;\n }\n // Static rule: never clobber a rendered diagram (theme-flip\n // re-renders, un-flagged code updates from static consumers).\n if (viewRef.current.kind === 'diagram') {\n return;\n }\n applyView({ kind: 'error' });\n }\n };\n\n void renderMermaid();\n\n return () => {\n cancelled = true;\n };\n // `streaming` in the deps is what drives the end-of-stream corrective\n // pass: the flip to false re-runs this effect on the (unchanged) final\n // code, so the last state reflects the full diagram source.\n }, [props.code, isDark, showOriginalCode, streaming]);\n\n const viewSvgInNewWindow = useCallback(() => {\n handleViewSVGInNewWindow(ref.current?.querySelector('svg'), isDark);\n }, [isDark]);\n\n // Show the raw source instead of the diagram container when the user asked\n // for it, when the (post-stream) render failed, or before the first\n // successful render (SSR output and the streaming warm-up phase). The\n // diagram container below stays MOUNTED throughout — merely hidden — so\n // `ref` is always available for mermaid to render into; unmounting it would\n // make the effect's `!ref.current` guard bail forever.\n const showSourceFallback = showOriginalCode || view.kind !== 'diagram';\n\n return (\n <>\n {showSourceFallback && (\n <CodeHighlightTabs\n mb={15}\n fz={fontSize}\n w=\"100%\"\n code={[\n {\n fileName: view.kind === 'error' ? 'Mermaid Render Error' : 'mermaid',\n code: props.code,\n language: 'mermaid',\n },\n ]}\n defaultExpanded={defaultExpanded}\n maxCollapsedHeight=\"320px\"\n styles={{\n filesScrollarea: {\n right: '90px',\n },\n }}\n controls={\n // The \"Render Mermaid\" control only makes sense as the way back\n // from the user-toggled source view. In the error and warm-up\n // fallbacks `showOriginalCode` is already false, so the control\n // would be a no-op — hide it there. (No view-kind conjunct: the\n // toggle is only reachable from the visible diagram view, and\n // while the source view is open the effect early-returns, so\n // showOriginalCode && view.kind === 'error' is unreachable.)\n showOriginalCode\n ? [\n <CodeHighlightControl\n tooltipLabel=\"Render Mermaid\"\n key=\"gpt\"\n onClick={() => {\n setShowOriginalCode(false);\n }}\n >\n <Flex align=\"center\" justify=\"center\" w={18} h={18}>\n <span className=\"icon-[gravity-ui--logo-mermaid] relative bottom-[1px] text-[16px]\"></span>\n </Flex>\n </CodeHighlightControl>,\n ]\n : []\n }\n withBorder\n withExpandButton\n />\n )}\n <div\n className={`aim-mantine-mermaid-code ${isDark ? 'dark' : ''}`}\n style={\n showSourceFallback\n ? {\n display: 'none',\n }\n : {}\n }\n >\n <div className=\"chart-header\">\n <div className=\"chart-type-tag\">{view.kind === 'diagram' ? view.chartType : 'unknown'}</div>\n <Flex align=\"center\" justify=\"flex-end\" gap={0}>\n <Tooltip label=\"Show Mermaid Code\">\n <ActionIcon\n size={28}\n className=\"action-icon\"\n variant=\"transparent\"\n aria-label=\"Show Mermaid code\"\n onClick={() => {\n setShowOriginalCode(true);\n }}\n >\n <Flex align=\"center\" justify=\"center\" w={18} h={18}>\n <span className=\"icon-[entypo--code] relative bottom-[0.25px] text-[16px]\"></span>\n </Flex>\n </ActionIcon>\n </Tooltip>\n <CopyButton value={props.code}>\n {({ copied, copy }) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon\n variant=\"transparent\"\n size={28}\n className=\"action-icon\"\n aria-label={copied ? 'Mermaid code copied' : 'Copy Mermaid code'}\n onClick={copy}\n >\n {copied ? (\n <span className=\"icon-origin-[lucide--check] text-[18px]\"></span>\n ) : (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n strokeWidth=\"2\"\n stroke=\"currentColor\"\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n width=\"18px\"\n height=\"18px\"\n >\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path>\n <path d=\"M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z\"></path>\n <path d=\"M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2\"></path>\n </svg>\n )}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\n </Flex>\n </div>\n <pre\n ref={ref}\n style={PRE_STYLE}\n role=\"button\"\n tabIndex={0}\n aria-label=\"Open Mermaid diagram in a new window\"\n onClick={viewSvgInNewWindow}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n viewSvgInNewWindow();\n }\n }}\n />\n </div>\n </>\n );\n});\n\nMantineAIMMermaidCode.displayName = 'MantineAIMMermaidCode';\n\nexport default MantineAIMMermaidCode;\n","/**\n * Widened `define*` factory for the mantine wrapper (EXECUTION-PLAN §4\n * item 8): identity + mantine prop types + freeze, zero logic. Core\n * factories accept core fields only — passing `codeBlock` to core's\n * `defineBehaviors` is a TS error; this widened factory is the wrapper's\n * one-line obligation.\n *\n * @module define\n */\n\nimport type { AIMarkdownBehaviorProps } from '@ai-react-markdown/core';\nimport type { MantineCodeBlockOptions } from './defs';\n\n/** Behavior-system props packagable at integration time, mantine-widened. */\nexport interface MantineBehaviorProps extends AIMarkdownBehaviorProps {\n /** The mantine `codeBlock` behavior group (atomic replacement; defaults applied at read time). */\n codeBlock?: Partial<MantineCodeBlockOptions>;\n}\n\n// NON-generic on purpose — see core's `define.ts`: a fresh literal is\n// excess-property checked against the concrete parameter type.\n\n/** Freeze a mantine behaviors fragment. Identity + types + freeze; zero logic. */\nexport function defineMantineBehaviors(values: MantineBehaviorProps): Readonly<MantineBehaviorProps> {\n return Object.freeze(values);\n}\n","import { useAIMarkdownMetadata } from '@ai-react-markdown/core';\nimport { MantineAIMarkdownMetadata } from '../defs';\n\n/**\n * Typed wrapper around the core {@link useAIMarkdownMetadata} hook.\n *\n * Returns the current metadata defaulting to {@link MantineAIMarkdownMetadata}.\n * Accepts an optional generic parameter for further extension.\n *\n * Metadata lives in a separate React context from the render state, meaning\n * metadata updates do not trigger re-renders in components that only consume\n * render state.\n *\n * Must be called inside a component rendered within the `<MantineAIMarkdown>` tree.\n *\n * @typeParam TMetadata - Metadata type (defaults to {@link MantineAIMarkdownMetadata}).\n * @returns The current metadata, or `undefined` if none was provided.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const metadata = useMantineAIMarkdownMetadata();\n * // Access Mantine-specific metadata fields\n * }\n * ```\n */\nexport const useMantineAIMarkdownMetadata = <\n TMetadata extends MantineAIMarkdownMetadata = MantineAIMarkdownMetadata,\n>() => {\n return useAIMarkdownMetadata<TMetadata>();\n};\n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AAAA,EAC3F;AACF;AAWA,IAAM,6BAA6B,CAA0E;AAAA,EAC3G,YAAAC,cAAa;AAAA,EACb,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyC;AACvC,QAAM,6BAAyB,6BAAe,gBAAgB;AAE9D,QAAM,qBAAiB,uBAAQ,MAAM;AACnC,WAAO,yBAAyB,EAAE,GAAG,yBAAyB,GAAG,uBAAuB,IAAI;AAAA,EAC9F,GAAG,CAAC,sBAAsB,CAAC;AAE3B,QAAM,0BAAsB,qCAAuB,OAAO;AAI1D,QAAM,aAAS,8BAAgB,EAAE,UAAU,GAAG,uBAAuB;AASrE,QAAM,qBAAiB;AAAA,IACrB,MAAO,OAAO,aAAa,OAAO,EAAE,WAAW,OAAO,UAAU,IAAI;AAAA,IACpE,CAAC,OAAO,SAAS;AAAA,EACnB;AAEA,SACE,6CAAC,4CAA4B,OAAO,gBAClC;AAAA,IAAC,aAAAC;AAAA,IAAA;AAAA,MACC,YAAYD;AAAA,MACZ;AAAA,MACA,kBAAkB;AAAA,MAClB,aAAa,eAAe;AAAA,MAC3B,GAAG;AAAA;AAAA,EACN,GACF;AAEJ;AAoBO,IAAM,wBAAoB,oBAAK,0BAA0B;AAEhE,kBAAkB,cAAc;AAEhC,IAAO,4BAAQ;;;AOlKR,SAAS,uBAAuB,QAA8D;AACnG,SAAO,OAAO,OAAO,MAAM;AAC7B;;;ACzBA,IAAAE,eAAsC;AA0B/B,IAAM,+BAA+B,MAErC;AACL,aAAO,oCAAiC;AAC1C;","names":["import_react","import_core","import_jsx_runtime","import_react","import_code_highlight","import_core","import_react","import_core","import_react","import_core","import_jsx_runtime","import_jsx_runtime","SpecialCodeLanguage","import_core","import_jsx_runtime","Typography","AIMarkdown","import_core"]}
package/dist/index.css CHANGED
@@ -148,9 +148,9 @@
148
148
  }
149
149
  .aim-mantine-mermaid-code .chart-header .chart-type-tag {
150
150
  padding: calc(0.2125rem * var(--mantine-scale)) calc(0.5625rem * var(--mantine-scale));
151
- color: black;
151
+ color: var(--mantine-color-text);
152
152
  border: 1px solid var(--mantine-color-gray-3);
153
- background: white;
153
+ background: var(--mantine-color-body);
154
154
  border-radius: var(--mantine-radius-default);
155
155
  font-size: var(--mantine-font-size-xs);
156
156
  font-weight: 700;