@ant-design/agentic-ui 2.1.0 → 2.2.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.
@@ -53,7 +53,7 @@ import {
53
53
  import { defaultColorList } from "../const";
54
54
  import { findDataPointByXValue, isXValueEqual, toNumber } from "../utils";
55
55
  import { useStyle } from "./style";
56
- ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
56
+ var funnelChartComponentsRegistered = false;
57
57
  var FunnelChart = (_a) => {
58
58
  var _b = _a, {
59
59
  title,
@@ -70,6 +70,7 @@ var FunnelChart = (_a) => {
70
70
  showPercent = true,
71
71
  toolbarExtra,
72
72
  renderFilterInToolbar = false,
73
+ bottomLayerMinWidth = 0,
73
74
  typeNames,
74
75
  statistic: statisticConfig
75
76
  } = _b, props = __objRest(_b, [
@@ -87,9 +88,21 @@ var FunnelChart = (_a) => {
87
88
  "showPercent",
88
89
  "toolbarExtra",
89
90
  "renderFilterInToolbar",
91
+ "bottomLayerMinWidth",
90
92
  "typeNames",
91
93
  "statistic"
92
94
  ]);
95
+ useMemo(() => {
96
+ if (funnelChartComponentsRegistered) {
97
+ return void 0;
98
+ }
99
+ if (typeof window === "undefined") {
100
+ return void 0;
101
+ }
102
+ ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
103
+ funnelChartComponentsRegistered = true;
104
+ return void 0;
105
+ }, []);
93
106
  const safeData = Array.isArray(data) ? data : [];
94
107
  const statistics = useMemo(() => {
95
108
  if (!statisticConfig)
@@ -100,7 +113,6 @@ var FunnelChart = (_a) => {
100
113
  typeof window !== "undefined" ? window.innerWidth : 768
101
114
  );
102
115
  const isMobile = windowWidth <= 768;
103
- const responsiveWidth = isMobile ? "100%" : width;
104
116
  useEffect(() => {
105
117
  const handleResize = () => setWindowWidth(window.innerWidth);
106
118
  if (typeof window !== "undefined") {
@@ -170,6 +182,12 @@ var FunnelChart = (_a) => {
170
182
  }
171
183
  return chartHeight;
172
184
  }, [height, chartHeight]);
185
+ const originalValues = useMemo(() => {
186
+ return stages.map((x) => {
187
+ const dp = findDataPointByXValue(filteredData, x);
188
+ return toNumber(dp == null ? void 0 : dp.y, 0);
189
+ });
190
+ }, [filteredData, stages]);
173
191
  const processedData = useMemo(() => {
174
192
  const baseColor = color || defaultColorList[0];
175
193
  const labels = stages.map((x) => x.toString());
@@ -179,7 +197,25 @@ var FunnelChart = (_a) => {
179
197
  return n;
180
198
  });
181
199
  const typeName = (typeNames == null ? void 0 : typeNames.name) || "转化";
182
- const datasetData = values.map(
200
+ const adjustedValues = (() => {
201
+ if (bottomLayerMinWidth <= 0 || bottomLayerMinWidth > 1 || values.length === 0) {
202
+ return values;
203
+ }
204
+ const maxValue = Math.max(...values);
205
+ const minValue = Math.min(...values);
206
+ if (minValue >= maxValue * bottomLayerMinWidth) {
207
+ return values;
208
+ }
209
+ const minWidth = bottomLayerMinWidth * maxValue;
210
+ const range = maxValue - minValue;
211
+ return values.map((v) => {
212
+ if (range === 0)
213
+ return maxValue;
214
+ const normalized = (v - minValue) / range;
215
+ return minWidth + normalized * (maxValue - minWidth);
216
+ });
217
+ })();
218
+ const datasetData = adjustedValues.map(
183
219
  (v) => [-v / 2, v / 2]
184
220
  );
185
221
  const hexToRgb = (hex) => {
@@ -223,7 +259,7 @@ var FunnelChart = (_a) => {
223
259
  }
224
260
  ]
225
261
  };
226
- }, [filteredData, stages]);
262
+ }, [filteredData, stages, bottomLayerMinWidth, color, typeNames]);
227
263
  const ratioDisplay = useMemo(() => {
228
264
  const formatRaw = (v) => {
229
265
  if (v === null || v === void 0)
@@ -379,15 +415,14 @@ var FunnelChart = (_a) => {
379
415
  return (it == null ? void 0 : it.label) ? String(it.label) : "";
380
416
  },
381
417
  label: (ctx) => {
382
- var _a2, _b2, _c;
383
- const raw = ctx.raw;
384
- const width2 = Array.isArray(raw) ? Math.abs(((_a2 = raw[1]) != null ? _a2 : 0) - ((_b2 = raw[0]) != null ? _b2 : 0)) : typeof raw === "number" ? Math.abs(raw) : 0;
385
- const idx = (_c = ctx.dataIndex) != null ? _c : 0;
418
+ var _a2, _b2;
419
+ const idx = (_a2 = ctx.dataIndex) != null ? _a2 : 0;
420
+ const originalValue = (_b2 = originalValues == null ? void 0 : originalValues[idx]) != null ? _b2 : 0;
386
421
  const percentStr = ratioDisplay == null ? void 0 : ratioDisplay[idx];
387
422
  if (showPercent === false || !percentStr) {
388
- return `${width2}`;
423
+ return `${originalValue}`;
389
424
  }
390
- return `${width2}(${percentStr})`;
425
+ return `${originalValue}(${percentStr})`;
391
426
  }
392
427
  }
393
428
  }
@@ -517,7 +552,7 @@ var FunnelChart = (_a) => {
517
552
  const maxEnd = Math.max(...ends);
518
553
  const padding = 12;
519
554
  meta.data.forEach((el, i) => {
520
- var _a3, _b3, _c;
555
+ var _a3, _b3, _c, _d;
521
556
  const raw = ds == null ? void 0 : ds[i];
522
557
  if (!raw || !Array.isArray(raw))
523
558
  return;
@@ -527,30 +562,46 @@ var FunnelChart = (_a) => {
527
562
  const start = Number((_b3 = raw[0]) != null ? _b3 : 0);
528
563
  const end = Number((_c = raw[1]) != null ? _c : 0);
529
564
  const mid = (start + end) / 2;
530
- const value = Math.abs(end - start);
565
+ const originalValue = (_d = originalValues == null ? void 0 : originalValues[i]) != null ? _d : 0;
531
566
  const cx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(mid) : el.x;
532
567
  ctx.save();
533
568
  ctx.fillStyle = "#fff";
534
569
  ctx.textAlign = "center";
535
- ctx.fillText(String(Math.round(value)), cx, y);
570
+ ctx.fillText(String(Math.round(originalValue)), cx, y);
536
571
  ctx.restore();
537
572
  });
538
573
  ctx.restore();
539
574
  }
540
575
  };
541
- }, [isMobile, axisTextColor]);
576
+ }, [isMobile, axisTextColor, originalValues]);
577
+ const containerClassName = useMemo(() => {
578
+ if (isMobile)
579
+ return "w-full";
580
+ if (typeof width === "number")
581
+ return "";
582
+ if (typeof width === "string" && width === "100%")
583
+ return "w-full";
584
+ return "";
585
+ }, [isMobile, width]);
586
+ const containerStyle = useMemo(() => {
587
+ if (isMobile)
588
+ return void 0;
589
+ if (typeof width === "number")
590
+ return { width };
591
+ if (typeof width === "string" && width !== "100%")
592
+ return { width };
593
+ return void 0;
594
+ }, [isMobile, width]);
542
595
  return wrapSSR(
543
596
  /* @__PURE__ */ React.createElement(
544
597
  ChartContainer,
545
598
  {
546
599
  baseClassName,
547
- className,
600
+ className: `${className || ""} ${containerClassName}`.trim(),
548
601
  theme,
549
602
  isMobile,
550
603
  variant: props.variant,
551
- style: {
552
- width: responsiveWidth
553
- }
604
+ style: containerStyle
554
605
  },
555
606
  /* @__PURE__ */ React.createElement(
556
607
  ChartToolBar,
@@ -58,15 +58,7 @@ import {
58
58
  findDataPointByXValue
59
59
  } from "../utils";
60
60
  import { useStyle } from "./style";
61
- ChartJS.register(
62
- CategoryScale,
63
- LinearScale,
64
- PointElement,
65
- LineElement,
66
- Filler,
67
- Tooltip,
68
- Legend
69
- );
61
+ var lineChartComponentsRegistered = false;
70
62
  var LineChart = (_a) => {
71
63
  var _b = _a, {
72
64
  title,
@@ -109,6 +101,25 @@ var LineChart = (_a) => {
109
101
  "renderFilterInToolbar",
110
102
  "statistic"
111
103
  ]);
104
+ useMemo(() => {
105
+ if (lineChartComponentsRegistered) {
106
+ return void 0;
107
+ }
108
+ if (typeof window === "undefined") {
109
+ return void 0;
110
+ }
111
+ ChartJS.register(
112
+ CategoryScale,
113
+ LinearScale,
114
+ PointElement,
115
+ LineElement,
116
+ Filler,
117
+ Tooltip,
118
+ Legend
119
+ );
120
+ lineChartComponentsRegistered = true;
121
+ return void 0;
122
+ }, []);
112
123
  const safeData = Array.isArray(data) ? data : [];
113
124
  const [windowWidth, setWindowWidth] = useState(
114
125
  typeof window !== "undefined" ? window.innerWidth : 768
@@ -53,14 +53,7 @@ import {
53
53
  } from "../components";
54
54
  import { defaultColorList } from "../const";
55
55
  import { useStyle } from "./style";
56
- ChartJS.register(
57
- RadialLinearScale,
58
- PointElement,
59
- LineElement,
60
- Filler,
61
- Tooltip,
62
- Legend
63
- );
56
+ var radarChartComponentsRegistered = false;
64
57
  var RadarChart = (_a) => {
65
58
  var _b = _a, {
66
59
  data,
@@ -87,6 +80,24 @@ var RadarChart = (_a) => {
87
80
  "statistic",
88
81
  "textMaxWidth"
89
82
  ]);
83
+ useMemo(() => {
84
+ if (radarChartComponentsRegistered) {
85
+ return void 0;
86
+ }
87
+ if (typeof window === "undefined") {
88
+ return void 0;
89
+ }
90
+ ChartJS.register(
91
+ RadialLinearScale,
92
+ PointElement,
93
+ LineElement,
94
+ Filler,
95
+ Tooltip,
96
+ Legend
97
+ );
98
+ radarChartComponentsRegistered = true;
99
+ return void 0;
100
+ }, []);
90
101
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
91
102
  const prefixCls = getPrefixCls("radar-chart");
92
103
  const { wrapSSR, hashId } = useStyle(prefixCls);
@@ -52,7 +52,7 @@ import {
52
52
  } from "../components";
53
53
  import { defaultColorList } from "../const";
54
54
  import { useStyle } from "./style";
55
- ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend);
55
+ var scatterChartComponentsRegistered = false;
56
56
  var ScatterChart = (_a) => {
57
57
  var _b = _a, {
58
58
  data,
@@ -97,6 +97,17 @@ var ScatterChart = (_a) => {
97
97
  "statistic",
98
98
  "textMaxWidth"
99
99
  ]);
100
+ useMemo(() => {
101
+ if (scatterChartComponentsRegistered) {
102
+ return void 0;
103
+ }
104
+ if (typeof window === "undefined") {
105
+ return void 0;
106
+ }
107
+ ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend);
108
+ scatterChartComponentsRegistered = true;
109
+ return void 0;
110
+ }, []);
100
111
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
101
112
  const prefixCls = getPrefixCls("scatter-chart");
102
113
  const { wrapSSR, hashId } = useStyle(prefixCls);
@@ -0,0 +1,18 @@
1
+ type AreaChartComponent = typeof import('./AreaChart').default;
2
+ type BarChartComponent = typeof import('./BarChart').default;
3
+ type DonutChartComponent = typeof import('./DonutChart').default;
4
+ type FunnelChartComponent = typeof import('./FunnelChart').default;
5
+ type LineChartComponent = typeof import('./LineChart').default;
6
+ type RadarChartComponent = typeof import('./RadarChart').default;
7
+ type ScatterChartComponent = typeof import('./ScatterChart').default;
8
+ export interface ChartRuntime {
9
+ AreaChart: AreaChartComponent;
10
+ BarChart: BarChartComponent;
11
+ DonutChart: DonutChartComponent;
12
+ FunnelChart: FunnelChartComponent;
13
+ LineChart: LineChartComponent;
14
+ RadarChart: RadarChartComponent;
15
+ ScatterChart: ScatterChartComponent;
16
+ }
17
+ export declare const loadChartRuntime: () => Promise<ChartRuntime>;
18
+ export {};
@@ -0,0 +1,91 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __async = (__this, __arguments, generator) => {
31
+ return new Promise((resolve, reject) => {
32
+ var fulfilled = (value) => {
33
+ try {
34
+ step(generator.next(value));
35
+ } catch (e) {
36
+ reject(e);
37
+ }
38
+ };
39
+ var rejected = (value) => {
40
+ try {
41
+ step(generator.throw(value));
42
+ } catch (e) {
43
+ reject(e);
44
+ }
45
+ };
46
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
47
+ step((generator = generator.apply(__this, __arguments)).next());
48
+ });
49
+ };
50
+
51
+ // src/Plugins/chart/loadChartRuntime.ts
52
+ var runtimeLoader = null;
53
+ var loadChartRuntime = () => __async(void 0, null, function* () {
54
+ if (typeof window === "undefined") {
55
+ throw new Error("图表运行时仅在浏览器环境中可用");
56
+ }
57
+ if (!runtimeLoader) {
58
+ runtimeLoader = Promise.all([
59
+ Promise.resolve().then(() => __toESM(__require("./AreaChart"))),
60
+ Promise.resolve().then(() => __toESM(__require("./BarChart"))),
61
+ Promise.resolve().then(() => __toESM(__require("./DonutChart"))),
62
+ Promise.resolve().then(() => __toESM(__require("./FunnelChart"))),
63
+ Promise.resolve().then(() => __toESM(__require("./LineChart"))),
64
+ Promise.resolve().then(() => __toESM(__require("./RadarChart"))),
65
+ Promise.resolve().then(() => __toESM(__require("./ScatterChart")))
66
+ ]).then(([
67
+ areaModule,
68
+ barModule,
69
+ donutModule,
70
+ funnelModule,
71
+ lineModule,
72
+ radarModule,
73
+ scatterModule
74
+ ]) => ({
75
+ AreaChart: areaModule.default,
76
+ BarChart: barModule.default,
77
+ DonutChart: donutModule.default,
78
+ FunnelChart: funnelModule.default,
79
+ LineChart: lineModule.default,
80
+ RadarChart: radarModule.default,
81
+ ScatterChart: scatterModule.default
82
+ })).catch((error) => {
83
+ runtimeLoader = null;
84
+ throw error;
85
+ });
86
+ }
87
+ return runtimeLoader;
88
+ });
89
+ export {
90
+ loadChartRuntime
91
+ };
@@ -6,6 +6,9 @@ export declare const standardPlugins: {
6
6
  code: typeof CodeElement;
7
7
  chart: (props: import("slate-react").RenderElementProps) => import("react").JSX.Element;
8
8
  katex: typeof KatexElement;
9
+ mermaid: (props: {
10
+ element: import("..").CodeNode;
11
+ }) => import("react").JSX.Element | null;
9
12
  'inline-katex': ({ children, element, attributes, style, }: import("..").ElementProps<import("..").InlineKatexNode> & {
10
13
  style?: import("react").CSSProperties | undefined;
11
14
  }) => import("react").JSX.Element;
@@ -2,12 +2,14 @@
2
2
  import { ChartElement } from "./chart";
3
3
  import { CodeElement } from "./code";
4
4
  import { InlineKatex, KatexElement } from "./katex";
5
+ import { Mermaid } from "./mermaid/Mermaid";
5
6
  var standardPlugins = [
6
7
  {
7
8
  elements: {
8
9
  code: CodeElement,
9
10
  chart: ChartElement,
10
11
  katex: KatexElement,
12
+ mermaid: Mermaid,
11
13
  "inline-katex": InlineKatex
12
14
  }
13
15
  }
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
2
  import { CodeNode } from '../../MarkdownEditor/el';
3
+ type MermaidApi = typeof import('mermaid').default;
4
+ export declare const loadMermaid: () => Promise<MermaidApi>;
3
5
  /**
4
6
  * Mermaid 组件 - Mermaid图表渲染组件
5
7
  *
@@ -36,5 +38,6 @@ import { CodeNode } from '../../MarkdownEditor/el';
36
38
  * - 自动生成唯一ID
37
39
  */
38
40
  export declare const Mermaid: (props: {
39
- el: CodeNode;
40
- }) => React.JSX.Element;
41
+ element: CodeNode;
42
+ }) => React.JSX.Element | null;
43
+ export {};
@@ -1,3 +1,32 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
1
30
  var __async = (__this, __arguments, generator) => {
2
31
  return new Promise((resolve, reject) => {
3
32
  var fulfilled = (value) => {
@@ -20,61 +49,124 @@ var __async = (__this, __arguments, generator) => {
20
49
  };
21
50
 
22
51
  // src/Plugins/mermaid/Mermaid.tsx
23
- import mermaid from "mermaid";
24
- import React, { useCallback, useEffect, useMemo, useRef } from "react";
52
+ import React, { useEffect, useMemo, useRef } from "react";
25
53
  import { useGetSetState } from "react-use";
54
+ import { useIntersectionOnce } from "../../Hooks/useIntersectionOnce";
55
+ var mermaidLoader = null;
56
+ var loadMermaid = () => __async(void 0, null, function* () {
57
+ if (typeof window === "undefined") {
58
+ throw new Error("Mermaid 仅在浏览器环境中可用");
59
+ }
60
+ if (!mermaidLoader) {
61
+ mermaidLoader = Promise.resolve().then(() => __toESM(__require("mermaid"))).then((module) => {
62
+ const api = module.default;
63
+ if (api == null ? void 0 : api.initialize) {
64
+ api.initialize({ startOnLoad: false });
65
+ }
66
+ return api;
67
+ }).catch((error) => {
68
+ mermaidLoader = null;
69
+ throw error;
70
+ });
71
+ }
72
+ return mermaidLoader;
73
+ });
26
74
  var Mermaid = (props) => {
75
+ var _a;
76
+ const isBrowser = typeof window !== "undefined";
27
77
  const [state, setState] = useGetSetState({
28
78
  code: "",
29
79
  error: ""
30
80
  });
81
+ const containerRef = useRef(null);
31
82
  const divRef = useRef(null);
32
- const timer = useRef(0);
83
+ const timer = useRef(null);
84
+ const mermaidRef = useRef(null);
33
85
  const id = useMemo(
34
86
  () => "m" + (Date.now() + Math.ceil(Math.random() * 1e3)),
35
87
  []
36
88
  );
37
- const render = useCallback(() => __async(void 0, null, function* () {
38
- mermaid.render(id, state().code).then((res) => {
39
- setState({ error: "" });
40
- divRef.current.innerHTML = res.svg;
41
- }).catch(() => {
42
- mermaid.parse(state().code).catch((e) => {
43
- setState({ error: e.toString(), code: "" });
44
- });
45
- }).finally(() => {
46
- var _a;
47
- (_a = document.querySelector("#d" + id)) == null ? void 0 : _a.classList.add("hidden");
48
- });
49
- }), []);
89
+ const isVisible = useIntersectionOnce(containerRef);
50
90
  useEffect(() => {
51
- const code = props.el.value || "";
52
- if (state().code !== code) {
53
- clearTimeout(timer.current);
54
- timer.current = window.setTimeout(
55
- () => {
56
- setState({ code });
57
- if (state().code) {
58
- render();
59
- } else {
60
- setState({ error: "" });
61
- }
62
- },
63
- !state().code ? 0 : 300
64
- );
91
+ if (!isBrowser) {
92
+ return void 0;
93
+ }
94
+ console.log("props---", props);
95
+ const nextCode = props.element.value || "";
96
+ const currentState = state();
97
+ if (!isVisible) {
98
+ return void 0;
99
+ }
100
+ if (currentState.code === nextCode && currentState.error === "") {
101
+ return void 0;
102
+ }
103
+ if (timer.current !== null) {
104
+ window.clearTimeout(timer.current);
105
+ timer.current = null;
106
+ }
107
+ if (!nextCode) {
108
+ timer.current = window.setTimeout(() => {
109
+ setState({ code: "", error: "" });
110
+ if (divRef.current) {
111
+ divRef.current.innerHTML = "";
112
+ }
113
+ timer.current = null;
114
+ }, 0);
115
+ return () => {
116
+ if (timer.current !== null) {
117
+ window.clearTimeout(timer.current);
118
+ timer.current = null;
119
+ }
120
+ };
65
121
  }
66
- return () => window.clearTimeout(timer.current);
67
- }, [props.el]);
122
+ const delay = currentState.code ? 300 : 0;
123
+ timer.current = window.setTimeout(() => __async(void 0, null, function* () {
124
+ var _a2, _b;
125
+ try {
126
+ const api = (_a2 = mermaidRef.current) != null ? _a2 : yield loadMermaid();
127
+ mermaidRef.current = api;
128
+ const { svg } = yield api.render(id, nextCode);
129
+ if (divRef.current) {
130
+ divRef.current.innerHTML = svg;
131
+ }
132
+ setState({ code: nextCode, error: "" });
133
+ } catch (error) {
134
+ const api = mermaidRef.current;
135
+ if (api) {
136
+ try {
137
+ yield api.parse(nextCode);
138
+ } catch (parseError) {
139
+ setState({ error: String(parseError), code: "" });
140
+ return;
141
+ }
142
+ }
143
+ setState({ error: String(error), code: "" });
144
+ } finally {
145
+ (_b = document.querySelector("#d" + id)) == null ? void 0 : _b.classList.add("hidden");
146
+ }
147
+ timer.current = null;
148
+ }), delay);
149
+ return () => {
150
+ if (timer.current !== null) {
151
+ window.clearTimeout(timer.current);
152
+ timer.current = null;
153
+ }
154
+ };
155
+ }, [isBrowser, (_a = props == null ? void 0 : props.element) == null ? void 0 : _a.value, id, isVisible, setState, state]);
156
+ if (!isBrowser) {
157
+ return null;
158
+ }
159
+ const snapshot = state();
68
160
  return /* @__PURE__ */ React.createElement(
69
161
  "div",
70
162
  {
163
+ ref: containerRef,
71
164
  style: {
72
165
  marginBottom: "0.75em",
73
166
  cursor: "default",
74
167
  userSelect: "none",
75
168
  padding: "0.75rem 0",
76
- backgroundColor: "rgba(15, 17, 20, 0.05)",
77
- borderRadius: "0.25em",
169
+ borderRadius: "1em",
78
170
  display: "flex",
79
171
  justifyContent: "center"
80
172
  },
@@ -89,14 +181,15 @@ var Mermaid = (props) => {
89
181
  width: "100%",
90
182
  display: "flex",
91
183
  justifyContent: "center",
92
- visibility: state().code && !state().error ? "visible" : "hidden"
184
+ visibility: snapshot.code && !snapshot.error ? "visible" : "hidden"
93
185
  }
94
186
  }
95
187
  ),
96
- state().error && /* @__PURE__ */ React.createElement("div", { style: { textAlign: "center", color: "rgba(239, 68, 68, 0.8)" } }, state().error),
97
- !state().code && !state().error && /* @__PURE__ */ React.createElement("div", { style: { textAlign: "center", color: "#6B7280" } }, "Empty")
188
+ snapshot.error && /* @__PURE__ */ React.createElement("div", { style: { textAlign: "center", color: "rgba(239, 68, 68, 0.8)" } }, snapshot.error),
189
+ !snapshot.code && !snapshot.error && /* @__PURE__ */ React.createElement("div", { style: { textAlign: "center", color: "#6B7280" } }, "Empty")
98
190
  );
99
191
  };
100
192
  export {
101
- Mermaid
193
+ Mermaid,
194
+ loadMermaid
102
195
  };
@@ -157,7 +157,7 @@ function MermaidElement(props) {
157
157
  ),
158
158
  /* @__PURE__ */ React.createElement("div", { className: "ant-agentic-md-editor-hidden" }, props.children)
159
159
  ),
160
- /* @__PURE__ */ React.createElement(Mermaid, { el: props.element })
160
+ /* @__PURE__ */ React.createElement(Mermaid, { element: props.element })
161
161
  );
162
162
  }
163
163
  export {