{"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/renderQueue.ts","../src/components/customized/MermaidCode/index.tsx","../src/components/customized/formatJson.ts","../src/components/customized/jsonCompleteness.ts","../src/components/customized/useCodeFrame.ts","../src/components/customized/codeFrame.ts","../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 (\n      !code ||\n      code.type !== 'element' ||\n      code.tagName !== 'code' ||\n      !code.position ||\n      node?.children.length !== 1 ||\n      code.children.some((child) => !('value' in child) || typeof child.value !== 'string') ||\n      Object.keys(code.properties ?? {}).some((key) => key !== 'className') ||\n      Object.keys(node.properties ?? {}).length > 0\n    ) {\n      return <pre {...usefulProps} />;\n    }\n    const key = `pre-code-${node?.position?.start?.offset || 0}`;\n    // hast allows `className` as a string as well as an array (a consumer's\n    // rehype plugin may write either); `.find` on a string threw and took\n    // the whole tree down (2026-08-19 review).\n    const classNames = code.properties?.className;\n    const classList = Array.isArray(classNames)\n      ? (classNames as unknown[]).filter((c): c is string => typeof c === 'string')\n      : typeof classNames === 'string'\n        ? classNames.split(/\\s+/)\n        : [];\n    const detectedLanguage = classList\n      .find((className) => className.startsWith('language-'))\n      ?.substring('language-'.length);\n    if (classList.some((className) => !className.startsWith('language-'))) return <pre {...usefulProps} />;\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 { createContext, HTMLAttributes, memo, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n  CodeHighlight,\n  CodeHighlightTabs,\n  CodeHighlightControl,\n  CodeHighlightAdapterProvider,\n  useHighlight,\n} from '@mantine/code-highlight';\nimport { useAIMarkdownState, useAIMarkdownTheme } from '@ai-react-markdown/core';\nimport { useMantineCodeBlockOptions } from '../../hooks/useMantineCodeBlockOptions';\nimport MantineAIMMermaidCode from './MermaidCode';\nimport { CopyButton } from '@mantine/core';\nimport { prettyPrintJson } from './formatJson';\nimport { createJsonCompletenessScanner } from './jsonCompleteness';\nimport { useCodeFrame } from './useCodeFrame';\nexport { jsonLooksComplete } from './jsonCompleteness';\nexport { prettyPrintJson } from './formatJson';\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  // A rejected load (transient network failure) is NOT cached: the next\n  // attempt retries instead of leaving autodetection dead for the page.\n  hljsAutoPromise ??= import('highlight.js').then(\n    (m) => m.default,\n    (err: unknown) => {\n      hljsAutoPromise = null;\n      throw err;\n    }\n  );\n  return hljsAutoPromise;\n};\n\n/** Below this many characters a guess is noise; the block stays \"unknown\". */\nconst AUTODETECT_MIN_CHARS = 32;\n/** Bounded automatic retries of a failed highlight.js module download. */\nconst HLJS_LOAD_RETRIES = 3;\nconst HLJS_LOAD_RETRY_MS = 1500;\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  // Bumped after a failed `import('highlight.js')` so the effect re-runs on\n  // otherwise unchanged inputs and retries the download — the mermaid\n  // renderer's counterpart. Without it a static document whose only load\n  // attempt failed stayed \"unknown\" for good (v2.4.2 review P2-2). Bounded.\n  const [loadAttempt, setLoadAttempt] = useState(0);\n  const loadFailuresRef = useRef(0);\n  const previousTextRef = useRef(codeText);\n  useEffect(() => {\n    const appended = codeText.startsWith(previousTextRef.current);\n    previousTextRef.current = codeText;\n    if (!enabled) {\n      if (detected) setDetected(null);\n      return;\n    }\n    // The block was REPLACED, not appended to (a regenerate reuses this\n    // instance — the key is the block's source offset — or a same-offset\n    // swap): a guess made for the old text is worthless for the new one.\n    // Drop it so the schedule restarts (v2.4.0 review: the old label stuck\n    // for the whole new stream until its end).\n    // Do NOT return here: `detected` is not a dep, so a state reset alone\n    // would never re-run the effect and a non-streaming replacement stayed\n    // \"unknown\" for good (v2.4.1 review) — evaluate the schedule against\n    // the cleared prior in this same pass.\n    const prior = !appended || (detected !== null && codeText.length < detected.atLength) ? null : detected;\n    if (prior !== detected) setDetected(null);\n    if (codeText.length < AUTODETECT_MIN_CHARS) return;\n    const due =\n      prior === null ||\n      // Not streaming: the verdict must be for THIS text (end-of-stream, or a\n      // static content update).\n      (!streaming && prior.finalFor !== codeText) ||\n      // Streaming: doubled since the last guess.\n      (streaming && codeText.length >= prior.atLength * 2);\n    if (!due) return;\n    let cancelled = false;\n    let retryTimer: ReturnType<typeof setTimeout> | undefined;\n    loadHljsForAutoDetect().then(\n      (hljs) => {\n        if (cancelled) return;\n        loadFailuresRef.current = 0;\n        setDetected({\n          language: hljs.highlightAuto(codeText).language ?? '',\n          atLength: codeText.length,\n          finalFor: streaming ? null : codeText,\n        });\n      },\n      () => {\n        // Load failed — stay \"unknown\" and retry the download a bounded\n        // number of times (the loader does not cache rejections).\n        if (cancelled || loadFailuresRef.current >= HLJS_LOAD_RETRIES) return;\n        loadFailuresRef.current += 1;\n        retryTimer = setTimeout(() => setLoadAttempt((n) => n + 1), HLJS_LOAD_RETRY_MS);\n      }\n    );\n    return () => {\n      cancelled = true;\n      if (retryTimer !== undefined) clearTimeout(retryTimer);\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). `loadAttempt`\n    // re-runs it after a failed module download.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [codeText, enabled, streaming, loadAttempt]);\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\nconst RawCodeContext = createContext('');\n\n/** Context updates the copy control without re-running the highlighter. */\nfunction RawCodeCopy() {\n  const code = useContext(RawCodeContext);\n  return (\n    <CopyButton value={code}>\n      {({ copied, copy }) => (\n        <CodeHighlightControl\n          tooltipLabel={copied ? 'Copied' : 'Copy'}\n          aria-label={copied ? 'Copied' : 'Copy code'}\n          onClick={copy}\n        >\n          {copied ? (\n            '✓'\n          ) : (\n            <svg\n              width=\"16\"\n              height=\"16\"\n              viewBox=\"0 0 24 24\"\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth=\"1.5\"\n              aria-hidden=\"true\"\n            >\n              <rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2\" />\n              <path d=\"M16 8V4H4v12h4\" />\n            </svg>\n          )}\n        </CodeHighlightControl>\n      )}\n    </CopyButton>\n  );\n}\n\n/** Single-entry adapter cache. Lives outside render; each request is keyed\n * by every input consumed by the highlighter, and a new function gets a new cache. */\nfunction createCachedHighlightAdapter(highlight: ReturnType<typeof useHighlight>) {\n  let previous: Parameters<typeof highlight>[0] | undefined;\n  let result: ReturnType<typeof highlight>;\n  return {\n    getHighlighter: () => (input: Parameters<typeof highlight>[0]) => {\n      if (\n        !previous ||\n        input.code !== previous.code ||\n        input.language !== previous.language ||\n        input.colorScheme !== previous.colorScheme\n      ) {\n        result = highlight(input);\n        previous = input;\n      }\n      return result;\n    },\n  };\n}\n\n/** Stable props keep Mantine's synchronous adapter out of intermediate renders. */\nconst OrdinaryCodeHighlight = memo(function OrdinaryCodeHighlight({\n  code,\n  language,\n  fileName,\n  fontSize,\n  defaultExpanded,\n}: {\n  code: string;\n  language: string;\n  fileName: string;\n  fontSize: number | string;\n  defaultExpanded: boolean;\n}) {\n  const highlight = useHighlight();\n  const adapter = useMemo(() => createCachedHighlightAdapter(highlight), [highlight]);\n  return (\n    <CodeHighlightAdapterProvider adapter={adapter}>\n      {fileName === 'unknown' ? (\n        <CodeHighlight\n          mb={15}\n          fz={fontSize}\n          w=\"100%\"\n          code={code}\n          withBorder\n          withExpandButton\n          defaultExpanded={defaultExpanded}\n          maxCollapsedHeight=\"320px\"\n          withCopyButton={false}\n          controls={[<RawCodeCopy key=\"copy\" />]}\n        />\n      ) : (\n        <CodeHighlightTabs\n          mb={15}\n          fz={fontSize}\n          w=\"100%\"\n          code={[\n            {\n              fileName: fileName,\n              code: code,\n              language: language,\n            },\n          ]}\n          withBorder\n          withExpandButton\n          defaultExpanded={defaultExpanded}\n          maxCollapsedHeight=\"320px\"\n          withCopyButton={false}\n          controls={[<RawCodeCopy key=\"copy\" />]}\n        />\n      )}\n    </CodeHighlightAdapterProvider>\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 formatted without rounding numeric tokens; nested expansion is optional.\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, formatJson, expandNestedJson, highlightIntervalMs } =\n      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 [scanJson] = useState(createJsonCompletenessScanner);\n    const jsonComplete = useMemo(\n      () => (usedCodeLanguage === 'json' && formatJson && streaming ? scanJson(props.codeText) : false),\n      [usedCodeLanguage, formatJson, streaming, scanJson, props.codeText]\n    );\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 to pretty-print 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. \"Ends with a closing bracket\" alone was not enough\n      // of a tell: pretty-printed JSON (the common LLM shape) ends a chunk\n      // on `}` / `]` at almost every nesting level, so the parse still ran\n      // on nearly every chunk (v2.4.1 review). Only a BALANCED bracket\n      // scan (strings skipped, one linear pass) admits the parse.\n      if (formatJson && usedCodeStr && usedCodeLanguage === 'json' && (!streaming || jsonComplete)) {\n        usedCodeStr = prettyPrintJson(usedCodeStr, expandNestedJson);\n      }\n      return usedCodeStr;\n    }, [isSpecialCodeBlock, props.codeText, usedCodeLanguage, streaming, formatJson, expandNestedJson, jsonComplete]);\n    const displayedCode = useCodeFrame(\n      normalCodeBlockContent ?? '',\n      usedCodeLanguage,\n      streaming && !isSpecialCodeBlock,\n      highlightIntervalMs\n    );\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 ? (\n      specialCodeBlockContent\n    ) : (\n      <RawCodeContext.Provider value={props.codeText}>\n        <OrdinaryCodeHighlight\n          code={displayedCode}\n          language={usedCodeLanguage}\n          fileName={usedFileName}\n          fontSize={fontSize}\n          defaultExpanded={defaultExpanded}\n        />\n      </RawCodeContext.Provider>\n    );\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    if (!Number.isFinite(resolved.highlightIntervalMs) || resolved.highlightIntervalMs < 0) {\n      resolved.highlightIntervalMs = defaultMantineCodeBlockOptions.highlightIntervalMs!;\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  /** Format JSON for display without changing numeric literals. @default true */\n  formatJson?: boolean;\n  /** Expand string values containing JSON objects/arrays for display. @default true */\n  expandNestedJson?: boolean;\n  /** Coalesce appended code display updates while streaming. Completion,\n   * replacement and language changes update immediately; copy uses latest\n   * source. Set 0 for every update. @default 50 */\n  highlightIntervalMs?: number;\n}\n\n/** Shipped defaults for the `codeBlock` behavior group. */\nexport const defaultMantineCodeBlockOptions: Readonly<MantineCodeBlockOptions> = Object.freeze({\n  defaultExpanded: true,\n  autoDetectUnknownLanguage: false,\n  formatJson: true,\n  expandNestedJson: true,\n  highlightIntervalMs: 50,\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","/** Mermaid owns global configuration and a global renderer. Keep initialize,\n * parse and render in one serialized task. Each mounted diagram retains at\n * most one pending task; superseded frames never enter Mermaid. */\nexport function createRenderQueue() {\n  type Job = { run: () => Promise<void>; resolve: () => void; reject: (error: unknown) => void };\n  const pending = new Map<object, Job>();\n  let running = false;\n  async function drain() {\n    if (running) return;\n    running = true;\n    try {\n      while (pending.size) {\n        const [owner, job] = pending.entries().next().value!;\n        pending.delete(owner);\n        try {\n          await job.run();\n          job.resolve();\n        } catch (error) {\n          job.reject(error);\n        }\n      }\n    } finally {\n      running = false;\n    }\n  }\n  return {\n    enqueue(owner: object, run: () => Promise<void>): Promise<void> {\n      pending.get(owner)?.resolve();\n      const promise = new Promise<void>((resolve, reject) => pending.set(owner, { run, resolve, reject }));\n      void drain();\n      return promise;\n    },\n    cancel(owner: object) {\n      pending.get(owner)?.resolve();\n      pending.delete(owner);\n    },\n  };\n}\n\nexport const mermaidRenderQueue = createRenderQueue();\n","'use client';\n\nimport { mermaidRenderQueue } from './renderQueue';\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;\n/** Bounded automatic retries of a failed mermaid module download. */\nconst MERMAID_LOAD_RETRIES = 3;\nconst MERMAID_LOAD_RETRY_MS = 1500;\nconst loadMermaid = (): Promise<Mermaid> => {\n  // A rejected load is not cached — the next render attempt retries.\n  mermaidPromise ??= import('mermaid').then(\n    (m) => m.default,\n    (err: unknown) => {\n      mermaidPromise = null;\n      throw err;\n    }\n  );\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\n/**\n * mermaid's config is a module-level singleton shared with the host\n * application when the bundler dedupes the package, and a host that enables\n * `click` interactions calls `mermaid.initialize({ securityLevel: 'loose' })`\n * — the officially documented way. Under `loose` mermaid skips DOMPurify\n * and its output goes into this component's `innerHTML` verbatim: an\n * LLM-authored diagram string could then run script in the page origin.\n * So the theme cache alone is not enough of a guard: before every render\n * the current `securityLevel` is read back (`mermaidAPI.getConfig()` — a\n * config copy, still far cheaper than `initialize`'s merge + theme\n * variables + diagram registration) and a non-strict value forces a\n * re-initialize\n * (2026-08-19 review r2 P2-11; the v2.4.2 \"documented premise\" made this\n * the host's problem — it is ours, the innerHTML is ours).\n */\nconst ensureMermaidInitialized = (mermaid: Mermaid, isDark: boolean) => {\n  const theme = isDark ? 'dark' : 'light';\n  // `getConfig` lives on `mermaid.mermaidAPI` (deprecated in the types, present\n  // at runtime in mermaid 11) — the default export has none, a cast hid that\n  // and the guard never short-circuited (oracle review of the r2 batch).\n  const api = (mermaid as { mermaidAPI?: { getConfig?: () => { securityLevel?: string } } }).mermaidAPI;\n  const currentLevel = api?.getConfig?.().securityLevel;\n  if (initializedTheme === theme && currentLevel === 'strict') 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  // The blob URL is same-origin — object URLs inherit the origin that made\n  // them — so this opens as a top-level document in the application's own\n  // origin, and reviews keep flagging it. Examined and kept as it is on\n  // 2026-08-20 (do not re-report):\n  //\n  // Loading the SVG as a document does revive `<script>` elements that sit\n  // inertly in our `innerHTML` (the HTML parser flags scripts inserted that\n  // way non-executable, and a fresh parse does not carry the flag over).\n  // What that misses is that inline `on*` handlers inserted the same way are\n  // NOT inert — `<img src=x onerror>` fires in the page — and neither are\n  // `javascript:` hrefs or `<animate>` retargeting one. Anything that\n  // reaches the DOM with a script vector intact therefore already holds the\n  // page's origin, without a popup. The escalation is only real for markup\n  // where `<script>` survives sanitizing while every handler in the same\n  // injection channel does not, which is not the shape a DOMPurify bypass\n  // takes; and a host CSP with `script-src 'self'` closes even that, since\n  // blob documents inherit the creator's policy.\n  //\n  // `noopener` stays for the ordinary reason — the new context does not need\n  // a handle on this window — not as an answer to the above, which it never\n  // was.\n  window.open(url, '_blank', 'noopener');\n  // Revoke either way (a blocked popup would otherwise leak the Blob until\n  // page unload — 2026-08 project review, pkg-small-09). With `noopener`\n  // `window.open` returns null even on success, so the blocked case cannot\n  // be told apart any more: always give the opened document the grace\n  // period to finish loading before the URL goes away.\n  setTimeout(() => URL.revokeObjectURL(url), 5000);\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  /** Bumped (after a short delay) when the mermaid MODULE failed to load, so\n   *  the effect re-runs on otherwise unchanged inputs and retries the\n   *  download. A download failure is not a diagram error: it must neither\n   *  consume the corrective obligation nor show the error tab (v2.4.1\n   *  review — the corrective pass is one-shot, so a transient network\n   *  failure on it left a permanent \"Render Error\" that nothing re-tried).\n   *  Bounded by MERMAID_LOAD_RETRIES per generation. */\n  const [loadAttempt, setLoadAttempt] = useState(0);\n  const loadFailuresRef = useRef(0);\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      loadFailuresRef.current = 0;\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    let retryTimer: ReturnType<typeof setTimeout> | undefined;\n    const renderMermaid = async () => {\n      let mermaid: Mermaid;\n      try {\n        mermaid = await loadMermaid();\n      } catch {\n        // Module load failed: keep whatever is showing (source view or the\n        // last diagram), leave the corrective obligation armed, and retry\n        // the download a bounded number of times.\n        if (cancelled || renderVersion !== renderVersionRef.current) return;\n        if (loadFailuresRef.current < MERMAID_LOAD_RETRIES) {\n          loadFailuresRef.current += 1;\n          retryTimer = setTimeout(() => setLoadAttempt((n) => n + 1), MERMAID_LOAD_RETRY_MS);\n        }\n        return;\n      }\n      loadFailuresRef.current = 0;\n      try {\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        // The queue holds initialization, parsing and rendering together,\n        // so another library instance cannot change the theme mid-task.\n        const rendered = await mermaid.render(generateMermaidUUID(), props.code);\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    const owner = renderVersionRef;\n    void mermaidRenderQueue.enqueue(owner, renderMermaid);\n\n    return () => {\n      cancelled = true;\n      mermaidRenderQueue.cancel(owner);\n      if (retryTimer !== undefined) clearTimeout(retryTimer);\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    // `loadAttempt` re-runs it after a failed module download.\n  }, [props.code, isDark, showOriginalCode, streaming, loadAttempt]);\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            {/* The \"open in a new window\" action is a real button here rather\n                than a `role=\"button\"` on the SVG container: a button's\n                content is presentational to assistive tech, so the diagram's\n                own text and mermaid's accTitle/accDescr were unreachable, and\n                any `click … href` link mermaid emitted sat inside a button\n                (invalid, not tabbable) — 2026-08-19 review r2 P3. The\n                container below carries no role at all, for the same reason. */}\n            {/* Always rendered (also under SSR / the source warm-up, where it\n                is a no-op until the SVG exists) so server and client markup\n                agree. */}\n            {\n              <Tooltip label=\"Open in new window\">\n                <ActionIcon\n                  size={28}\n                  className=\"action-icon\"\n                  variant=\"transparent\"\n                  aria-label=\"Open Mermaid diagram in a new window\"\n                  onClick={viewSvgInNewWindow}\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                    aria-hidden=\"true\"\n                  >\n                    <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path>\n                    <path d=\"M12 6h-6a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-6\"></path>\n                    <path d=\"M11 13l9 -9\"></path>\n                    <path d=\"M15 4h5v5\"></path>\n                  </svg>\n                </ActionIcon>\n              </Tooltip>\n            }\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        {/* No ARIA role on the container: `role=\"img\"` (like the old\n            `role=\"button\"`) makes its children presentational and hides the\n            SVG's own `role=\"graphics-document\"` + accTitle/accDescr that\n            mermaid emits — the SVG names itself. Click-to-open stays as a\n            pointer convenience; the keyboard/AT path is the header button. */}\n        <pre ref={ref} style={PRE_STYLE} onClick={viewSvgInNewWindow} />\n      </div>\n    </>\n  );\n});\n\nMantineAIMMermaidCode.displayName = 'MantineAIMMermaidCode';\n\nexport default MantineAIMMermaidCode;\n","/** Validate with the native parser, but format lexical tokens so numbers,\n * duplicate keys and key order never pass through JavaScript's value model.\n * Nested JSON expansion is optional and only applies to string values. */\nexport function prettyPrintJson(text: string, expandNested = true): string {\n  try {\n    return format(text, expandNested, 0);\n  } catch {\n    return text;\n  }\n}\n\nfunction format(text: string, expandNested: boolean, baseIndent: number): string {\n  JSON.parse(text);\n  const tokens =\n    text.match(/\"(?:\\\\[\\s\\S]|[^\"\\\\])*\"|-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?|true|false|null|[{}[\\],:]/g) ?? [];\n  const out: string[] = [];\n  let indent = baseIndent;\n  const newline = () => out.push('\\n', '  '.repeat(indent));\n  for (let i = 0; i < tokens.length; i++) {\n    const token = tokens[i];\n    if (token === '{' || token === '[') {\n      out.push(token);\n      if (tokens[i + 1] !== (token === '{' ? '}' : ']')) {\n        indent++;\n        newline();\n      }\n    } else if (token === '}' || token === ']') {\n      if (tokens[i - 1] !== (token === '}' ? '{' : '[')) {\n        indent--;\n        newline();\n      }\n      out.push(token);\n    } else if (token === ',') {\n      out.push(',');\n      newline();\n    } else if (token === ':') {\n      out.push(': ');\n    } else if (token.startsWith('\"')) {\n      const value = JSON.parse(token) as string;\n      const trimmed = value.trim();\n      if (expandNested && tokens[i + 1] !== ':' && /^[{[]/.test(trimmed) && indent < 100) {\n        try {\n          out.push(format(trimmed, true, indent));\n          continue;\n        } catch {\n          /* Keep non-JSON strings. */\n        }\n      }\n      out.push(JSON.stringify(value));\n    } else {\n      out.push(token);\n    }\n  }\n  return out.join('');\n}\n","/** Bracket-balance gate, not a JSON validator. Retain quote/escape state\n * across append seams so growing JSON does not rescan its whole body when\n * each nested object closes. Replacements start a fresh lineage. */\nexport function createJsonCompletenessScanner() {\n  let previous = '';\n  let depth = 0;\n  let quoted = false;\n  let escaped = false;\n  let invalid = false;\n  let last = '';\n  return (text: string): boolean => {\n    let from = previous.length;\n    if (!text.startsWith(previous)) {\n      from = 0;\n      depth = 0;\n      quoted = escaped = invalid = false;\n      last = '';\n    }\n    previous = text;\n    for (let i = from; i < text.length; i++) {\n      const c = text[i];\n      if (!/\\s/.test(c)) last = c;\n      if (quoted) {\n        if (escaped) escaped = false;\n        else if (c === '\\\\') escaped = true;\n        else if (c === '\"') quoted = false;\n      } else if (c === '\"') quoted = true;\n      else if (c === '{' || c === '[') depth++;\n      else if (c === '}' || c === ']') {\n        depth--;\n        if (depth < 0) invalid = true;\n      }\n    }\n    return !invalid && !quoted && depth === 0 && (last === '}' || last === ']');\n  };\n}\n\nexport function jsonLooksComplete(text: string): boolean {\n  return createJsonCompletenessScanner()(text);\n}\n","import { useEffect, useState } from 'react';\nimport { createCodeFrame } from './codeFrame';\n\n/** Initial/SSR, static, final and replacement renders use current text.\n * Only append-only streaming frames may display the preceding snapshot. */\nexport function useCodeFrame(code: string, language: string, streaming: boolean, interval: number): string {\n  const [frame, setFrame] = useState(() => ({ code, language }));\n  const [controller] = useState(() => createCodeFrame({ code, language }, setFrame));\n  useEffect(() => {\n    controller.update({ code, language }, streaming, interval);\n  }, [controller, code, language, streaming, interval]);\n  useEffect(() => () => controller.dispose(), [controller]);\n  return !streaming || interval === 0 || language !== frame.language || !code.startsWith(frame.code)\n    ? code\n    : frame.code;\n}\n","export interface CodeFrame {\n  code: string;\n  language: string;\n}\n\n/** A trailing throttle: append bursts replace one pending frame without\n * moving its deadline. Replacements and completion bypass the timer. */\nexport function createCodeFrame(initial: CodeFrame, publish: (frame: CodeFrame) => void) {\n  let shown = initial;\n  let latest = initial;\n  let delay = 0;\n  let timer: ReturnType<typeof setTimeout> | undefined;\n  const cancel = () => {\n    if (timer !== undefined) clearTimeout(timer);\n    timer = undefined;\n  };\n  const flush = () => {\n    cancel();\n    if (shown.code === latest.code && shown.language === latest.language) return;\n    shown = latest;\n    publish(shown);\n  };\n  return {\n    update(next: CodeFrame, streaming: boolean, interval: number) {\n      const replaced = next.language !== latest.language || !next.code.startsWith(latest.code);\n      latest = next;\n      if (delay !== interval) cancel();\n      delay = interval;\n      if (!streaming || interval === 0 || replaced) return flush();\n      if (shown.code === next.code && shown.language === next.language) return cancel();\n      timer ??= setTimeout(flush, interval);\n    },\n    // Cancellation is reversible: Strict Mode replays the update effect.\n    dispose: cancel,\n  };\n}\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;AAAA;;;ACaA,IAAAA,gBAA8B;AAC9B,IAAAC,eAAuB;AACvB,IAAAA,eASO;;;ACxBP,mBAA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,cAAc;AAEhC,IAAO,4BAAQ;;;AYrLR,SAAS,uBAAuB,QAA8D;AACnG,SAAO,OAAO,OAAO,MAAM;AAC7B;;;ACzBA,IAAAE,gBAAsC;AA0B/B,IAAM,+BAA+B,MAErC;AACL,aAAO,qCAAiC;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_core","import_react","import_jsx_runtime","OrdinaryCodeHighlight","SpecialCodeLanguage","import_core","import_jsx_runtime","key","Typography","AIMarkdown","import_core"]}