@xiangfa/mindmap 0.3.0 → 0.5.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.
@@ -1,7 +1,8 @@
1
- import { runRenderOverlay as e } from "./plugins/runner.js";
2
- import { computeEdgePath as t, layoutMultiRoot as n } from "./utils/layout.js";
3
- import { buildExportSVG as r, buildExportSVGForPNG as i, exportToPNG as a } from "./utils/export.js";
4
- import { parseMarkdownMultiRoot as o, parseMarkdownWithFrontMatter as s, toMarkdownMultiRoot as c } from "./utils/markdown.js";
1
+ import { generateCSSVariables as e } from "./utils/theme.js";
2
+ import { runRenderOverlay as t } from "./plugins/runner.js";
3
+ import { computeEdgePath as n, layoutMultiRoot as r } from "./utils/layout.js";
4
+ import { buildExportSVG as i, buildExportSVGForPNG as a, exportToPNG as o } from "./utils/export.js";
5
+ import { parseMarkdownMultiRoot as s, parseMarkdownWithFrontMatter as c, toMarkdownMultiRoot as l } from "./utils/markdown.js";
5
6
  import { detectLocale as ee, resolveMessages as te } from "./utils/i18n.js";
6
7
  import { addChildMulti as ne, addChildToSide as re, findSubtreeMulti as ie, generateId as ae, normalizeData as oe, regenerateIds as se, removeNodeMulti as ce } from "./utils/tree-ops.js";
7
8
  import { useTheme as le } from "./hooks/useTheme.js";
@@ -12,19 +13,20 @@ import { useNewNodeAnimation as pe } from "./hooks/useNewNodeAnimation.js";
12
13
  import { MindMapNode as me } from "./components/MindMapNode.js";
13
14
  import { MindMapControls as he } from "./components/MindMapControls.js";
14
15
  import { MindMapContextMenu as ge } from "./components/MindMapContextMenu.js";
16
+ import { MindMapAIInput as _e } from "./components/MindMapAIInput.js";
15
17
  /* empty css */
16
- import { forwardRef as l, useCallback as u, useEffect as d, useImperativeHandle as _e, useMemo as f, useRef as p, useState as m } from "react";
17
- import { Fragment as ve, jsx as h, jsxs as g } from "react/jsx-runtime";
18
+ import { forwardRef as u, useCallback as d, useEffect as f, useImperativeHandle as ve, useMemo as p, useRef as m, useState as h } from "react";
19
+ import { Fragment as ye, jsx as g, jsxs as _ } from "react/jsx-runtime";
18
20
  //#region src/components/MindMap/MindMap.tsx
19
- function ye(e, t) {
21
+ function be(e, t) {
20
22
  let n = URL.createObjectURL(e), r = document.createElement("a");
21
23
  r.href = n, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
22
24
  }
23
- var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme: xe = "auto", locale: Se, messages: Ce, readonly: v = !1, toolbar: y = !0, onDataChange: we, onEvent: Te, plugins: Ee }, De) {
24
- let Oe = p(null), b = p(null), x = Ee && Ee.length > 0 ? Ee : void 0, ke = f(() => {
25
- if (l || _ === void 0) return null;
26
- if (x) {
27
- let e = s(_, x), t = e.frontMatter.direction, n = e.frontMatter.theme;
25
+ var v = u(function({ data: u, markdown: v, defaultDirection: xe = "both", theme: Se = "auto", locale: Ce, messages: we, readonly: y = !1, toolbar: b = !0, ai: Te, onDataChange: Ee, onEvent: De, plugins: Oe }, ke) {
26
+ let Ae = m(null), x = m(null), S = Oe && Oe.length > 0 ? Oe : void 0, C = p(() => {
27
+ if (u || v === void 0) return null;
28
+ if (S) {
29
+ let e = c(v, S), t = e.frontMatter.direction, n = e.frontMatter.theme;
28
30
  return {
29
31
  roots: e.roots,
30
32
  direction: t === "left" || t === "right" || t === "both" ? t : void 0,
@@ -32,165 +34,165 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
32
34
  };
33
35
  }
34
36
  return {
35
- roots: o(_),
37
+ roots: s(v),
36
38
  direction: void 0,
37
39
  theme: void 0
38
40
  };
39
- }, []), [S, C] = m(() => l ? oe(l) : ke ? ke.roots : [{
41
+ }, []), [w, T] = h(() => u ? oe(u) : C ? C.roots : [{
40
42
  id: "md-0",
41
43
  text: "Root"
42
- }]), [w, Ae] = m(() => ke?.direction ?? be), [T, E] = m({}), [D, O] = m(null), [k, je] = m(null), [Me, Ne] = m({}), Pe = p(null), [Fe, Ie] = m("view"), [Le, Re] = m(!1), [ze, A] = m(""), [Be, Ve] = m(null), [He, Ue] = m({}), [We, Ge] = m(null), [Ke, qe] = m(() => ke?.theme);
43
- d(() => {
44
- l && C(oe(l));
45
- }, [l]), d(() => {
46
- if (_ !== void 0) if (x) {
47
- let { roots: e, frontMatter: t } = s(_, x);
48
- if (C(e), t.direction) {
44
+ }]), [E, je] = h(() => C?.direction ?? xe), [D, O] = h({}), [k, A] = h(null), [j, Me] = h(null), [M, Ne] = h({}), Pe = m(null), [Fe, Ie] = h("view"), [Le, Re] = h(!1), [ze, N] = h(""), [Be, Ve] = h(null), [He, Ue] = h({}), [We, Ge] = h(null), [Ke, qe] = h(() => C?.theme);
45
+ f(() => {
46
+ u && T(oe(u));
47
+ }, [u]), f(() => {
48
+ if (v !== void 0) if (S) {
49
+ let { roots: e, frontMatter: t } = c(v, S);
50
+ if (T(e), t.direction) {
49
51
  let e = t.direction;
50
- (e === "left" || e === "right" || e === "both") && Ae(e);
52
+ (e === "left" || e === "right" || e === "both") && je(e);
51
53
  }
52
54
  if (t.theme) {
53
55
  let e = t.theme;
54
56
  (e === "light" || e === "dark" || e === "auto") && qe(e);
55
57
  }
56
- } else C(o(_));
57
- }, [_, x]);
58
- let j = u((e) => {
59
- C((t) => {
58
+ } else T(s(v));
59
+ }, [v, S]);
60
+ let P = d((e) => {
61
+ T((t) => {
60
62
  let n = e(t);
61
- return we?.(n), n;
63
+ return Ee?.(n), n;
62
64
  });
63
- }, [we]), Je = p(Te);
64
- Je.current = Te;
65
- let M = u((e) => {
65
+ }, [Ee]), Je = m(De);
66
+ Je.current = De;
67
+ let F = d((e) => {
66
68
  Je.current?.(e);
67
- }, []), N = le(Ke ?? xe), P = f(() => te(Se ?? ee(), Ce), [Se, Ce]), Ye = f(() => y === !1 ? { zoom: !1 } : y === !0 || y === void 0 ? { zoom: !0 } : { zoom: y.zoom ?? !0 }, [y]), { nodes: F, edges: I } = f(() => n(S, w, Me, T, x, v, He), [
68
- S,
69
+ }, []), I = le(Ke ?? Se), L = p(() => te(Ce ?? ee(), we), [Ce, we]), Ye = p(() => b === !1 ? { zoom: !1 } : b === !0 || b === void 0 ? { zoom: !0 } : { zoom: b.zoom ?? !0 }, [b]), { nodes: R, edges: z } = p(() => r(w, E, M, D, S, y, He), [
69
70
  w,
70
- Me,
71
- T,
72
- x,
73
- v,
71
+ E,
72
+ M,
73
+ D,
74
+ S,
75
+ y,
74
76
  He
75
77
  ]);
76
- d(() => {
78
+ f(() => {
77
79
  let e = {}, t = !1;
78
- for (let n of F) n.depth === 1 && !Me[n.id] && (e[n.id] = n.color, t = !0);
80
+ for (let n of R) n.depth === 1 && !M[n.id] && (e[n.id] = n.color, t = !0);
79
81
  t && Ne((t) => ({
80
82
  ...t,
81
83
  ...e
82
84
  }));
83
- }, [F, Me]);
84
- let L = f(() => {
85
+ }, [R, M]);
86
+ let B = p(() => {
85
87
  let e = {};
86
- for (let t of F) e[t.id] = t;
88
+ for (let t of R) e[t.id] = t;
87
89
  return e;
88
- }, [F]), Xe = f(() => {
90
+ }, [R]), Xe = p(() => {
89
91
  if (!We) return {};
90
92
  let e = {}, t = [];
91
- for (let e of F) e.parentId === We && t.push({
93
+ for (let e of R) e.parentId === We && t.push({
92
94
  id: e.id,
93
95
  depth: 1
94
96
  });
95
97
  for (; t.length > 0;) {
96
98
  let { id: n, depth: r } = t.shift();
97
99
  e[n] = r * 100;
98
- for (let e of F) e.parentId === n && t.push({
100
+ for (let e of R) e.parentId === n && t.push({
99
101
  id: e.id,
100
102
  depth: r + 1
101
103
  });
102
104
  }
103
105
  return e;
104
- }, [We, F]), { pan: R, setPan: z, zoom: B, setZoom: V, animateTo: H, autoFit: Ze, zoomIn: Qe, zoomOut: $e, contentCenter: et, panToNode: tt } = ue(b, F), { draggingCanvas: nt, floatingNodeId: U, floatingPos: W, floatingSubtreeIds: G, didDragRef: K, handleCanvasMouseDown: rt, handleMouseMove: it, handleMouseUp: at, handleNodeMouseDown: ot } = de({
105
- svgRef: b,
106
- zoom: B,
107
- pan: R,
108
- setPan: z,
109
- setZoom: V,
110
- nodeMap: L,
111
- nodes: F,
112
- updateData: j,
113
- direction: w,
114
- splitIndices: T,
115
- setSplitIndices: E,
116
- mapData: S,
117
- contentCenter: et
118
- }), { editingId: st, editText: ct, setEditText: q, pendingEditId: J, setPendingEditId: Y, handleNodeDoubleClick: lt, commitEdit: ut, cancelEdit: dt } = fe({
119
- nodeMap: L,
120
- updateData: j,
106
+ }, [We, R]), { pan: V, setPan: H, zoom: U, setZoom: Ze, animateTo: Qe, autoFit: $e, zoomIn: et, zoomOut: tt, contentCenter: nt, panToNode: rt } = ue(x, R), { draggingCanvas: it, floatingNodeId: W, floatingPos: G, floatingSubtreeIds: K, didDragRef: at, handleCanvasMouseDown: ot, handleMouseMove: st, handleMouseUp: ct, handleNodeMouseDown: lt } = de({
107
+ svgRef: x,
108
+ zoom: U,
109
+ pan: V,
110
+ setPan: H,
111
+ setZoom: Ze,
112
+ nodeMap: B,
113
+ nodes: R,
114
+ updateData: P,
115
+ direction: E,
116
+ splitIndices: D,
117
+ setSplitIndices: O,
118
+ mapData: w,
119
+ contentCenter: nt
120
+ }), { editingId: ut, editText: dt, setEditText: q, pendingEditId: J, setPendingEditId: Y, handleNodeDoubleClick: ft, commitEdit: pt, cancelEdit: mt } = fe({
121
+ nodeMap: B,
122
+ updateData: P,
121
123
  onTextChange: (e, t, n) => {
122
- M({
124
+ F({
123
125
  type: "nodeTextChange",
124
126
  nodeId: e,
125
127
  oldText: t,
126
128
  newText: n
127
129
  });
128
130
  }
129
- }), ft = pe(F), [X, pt] = m(!1);
130
- d(() => {
131
- if (U || J) return;
132
- let e = Ze();
133
- e ? X ? (V(e.zoom), z({
131
+ }), ht = pe(R), [X, gt] = h(!1);
132
+ f(() => {
133
+ if (W || J) return;
134
+ let e = $e();
135
+ e ? X ? (Ze(e.zoom), H({
134
136
  x: e.panX,
135
137
  y: e.panY
136
- })) : (V(e.zoom * .92), z({
138
+ })) : (Ze(e.zoom * .92), H({
137
139
  x: e.panX,
138
140
  y: e.panY
139
141
  }), requestAnimationFrame(() => {
140
- pt(!0), H(e.zoom, e.panX, e.panY);
141
- })) : X || requestAnimationFrame(() => pt(!0));
142
+ gt(!0), Qe(e.zoom, e.panX, e.panY);
143
+ })) : X || requestAnimationFrame(() => gt(!0));
142
144
  }, [
143
- F,
144
- Ze,
145
- U,
145
+ R,
146
+ $e,
147
+ W,
146
148
  J,
147
- V,
148
- z,
149
+ Ze,
150
+ H,
149
151
  X,
150
- H
151
- ]), d(() => {
152
- J && L[J] && tt(J);
152
+ Qe
153
+ ]), f(() => {
154
+ J && B[J] && rt(J);
153
155
  }, [
154
156
  J,
155
- L,
156
- tt
157
+ B,
158
+ rt
157
159
  ]);
158
- let mt = u((e) => {
159
- je(null), rt(e);
160
- }, [rt]), ht = u((e, t) => {
161
- e.stopPropagation(), K.current || (O(t), M({
160
+ let _t = d((e) => {
161
+ Me(null), ot(e);
162
+ }, [ot]), vt = d((e, t) => {
163
+ e.stopPropagation(), at.current || (A(t), F({
162
164
  type: "nodeSelect",
163
165
  nodeId: t
164
166
  }));
165
- }, [K, M]), gt = u(() => {
166
- K.current || (O(null), M({
167
+ }, [at, F]), yt = d(() => {
168
+ at.current || (A(null), F({
167
169
  type: "nodeSelect",
168
170
  nodeId: null
169
171
  }));
170
- }, [K, M]), _t = u((e) => {
172
+ }, [at, F]), bt = d((e) => {
171
173
  e.preventDefault(), e.stopPropagation();
172
- let t = Oe.current;
174
+ let t = Ae.current;
173
175
  if (!t) return;
174
176
  let n = t.getBoundingClientRect();
175
- je({
177
+ Me({
176
178
  x: e.clientX - n.left,
177
179
  y: e.clientY - n.top
178
180
  });
179
- }, []), Z = u(() => {
180
- je(null);
181
- }, []), vt = u((e) => {
181
+ }, []), Z = d(() => {
182
+ Me(null);
183
+ }, []), xt = d((e) => {
182
184
  if (!e) {
183
185
  Ve(null);
184
186
  return;
185
187
  }
186
- let t = L[e];
188
+ let t = B[e];
187
189
  if (!t || !t.remark) {
188
190
  Ve(null);
189
191
  return;
190
192
  }
191
- let n = b.current;
193
+ let n = x.current;
192
194
  if (!n) return;
193
- let r = n.getBoundingClientRect(), i = (t.x + t.width / 2) * B + R.x, a = (t.y - t.height / 2) * B + R.y;
195
+ let r = n.getBoundingClientRect(), i = (t.x + t.width / 2) * U + V.x, a = (t.y - t.height / 2) * U + V.y;
194
196
  Ve({
195
197
  nodeId: e,
196
198
  text: t.remark,
@@ -198,145 +200,145 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
198
200
  y: a - 8
199
201
  });
200
202
  }, [
201
- L,
202
203
  B,
203
- R
204
- ]), yt = u((e, t, n) => {
205
- if (e.stopPropagation(), v) return;
204
+ U,
205
+ V
206
+ ]), St = d((e, t, n) => {
207
+ if (e.stopPropagation(), y) return;
206
208
  let r = ae(), i = {
207
209
  id: r,
208
- text: P.newNode
210
+ text: L.newNode
209
211
  };
210
- S.some((e) => e.id === t) && n && w === "both" ? j((e) => e.map((e) => {
212
+ w.some((e) => e.id === t) && n && E === "both" ? P((e) => e.map((e) => {
211
213
  if (e.id !== t) return e;
212
- let r = e.children || [], a = T[t] ?? Math.ceil(r.length / 2), o = a, s = r.length - a, c = n;
214
+ let r = e.children || [], a = D[t] ?? Math.ceil(r.length / 2), o = a, s = r.length - a, c = n;
213
215
  n === "right" && o >= 3 * Math.max(s, 1) ? c = "left" : n === "left" && s >= 3 * Math.max(o, 1) && (c = "right");
214
- let ee = re(e, i, c, a);
215
- return E((e) => ({
216
+ let l = re(e, i, c, a);
217
+ return O((e) => ({
216
218
  ...e,
217
- [t]: ee.newSplitIndex
218
- })), ee.data;
219
- })) : j((e) => ne(e, t, i)), M({
219
+ [t]: l.newSplitIndex
220
+ })), l.data;
221
+ })) : P((e) => ne(e, t, i)), F({
220
222
  type: "nodeAdd",
221
223
  node: i,
222
224
  parentId: t
223
225
  }), Y(r), q("");
224
226
  }, [
225
- j,
226
- S,
227
+ P,
227
228
  w,
228
- T,
229
+ E,
230
+ D,
229
231
  Y,
230
232
  q,
231
- P,
232
- v,
233
- M
234
- ]), bt = u(() => {
235
- if (v) return;
233
+ L,
234
+ y,
235
+ F
236
+ ]), Ct = d(() => {
237
+ if (y) return;
236
238
  let e = ae(), t = {
237
239
  id: e,
238
- text: P.newNode
240
+ text: L.newNode
239
241
  };
240
- j((e) => [...e, t]), M({
242
+ P((e) => [...e, t]), F({
241
243
  type: "nodeAdd",
242
244
  node: t,
243
245
  parentId: null
244
246
  }), Y(e), q(""), Z();
245
247
  }, [
246
- j,
248
+ P,
247
249
  Z,
248
250
  Y,
249
251
  q,
250
- P,
251
- v,
252
- M
253
- ]), xt = u(() => {
254
- let e = r(F, I, {}, N, x);
255
- ye(new Blob([e], { type: "image/svg+xml;charset=utf-8" }), "mindmap.svg"), Z();
252
+ L,
253
+ y,
254
+ F
255
+ ]), wt = d(() => {
256
+ let e = i(R, z, {}, I, S);
257
+ be(new Blob([e], { type: "image/svg+xml;charset=utf-8" }), "mindmap.svg"), Z();
256
258
  }, [
257
- F,
259
+ R,
260
+ z,
258
261
  I,
259
- N,
260
262
  Z,
261
- x
262
- ]), St = u(async () => {
263
- ye(await a(i(F, I, { pngSafe: !0 }, N, x)), "mindmap.png"), Z();
263
+ S
264
+ ]), Tt = d(async () => {
265
+ be(await o(a(R, z, { pngSafe: !0 }, I, S)), "mindmap.png"), Z();
264
266
  }, [
265
- F,
267
+ R,
268
+ z,
266
269
  I,
267
- N,
268
270
  Z,
269
- x
270
- ]), Ct = u(() => {
271
- let e = c(S, x);
272
- ye(new Blob([e], { type: "text/markdown;charset=utf-8" }), "mindmap.md"), Z();
271
+ S
272
+ ]), Et = d(() => {
273
+ let e = l(w, S);
274
+ be(new Blob([e], { type: "text/markdown;charset=utf-8" }), "mindmap.md"), Z();
273
275
  }, [
274
- S,
276
+ w,
275
277
  Z,
276
- x
277
- ]), Q = u(() => {
278
- let e = Ze();
279
- e && H(e.zoom, e.panX, e.panY);
280
- }, [Ze, H]), $ = u((e) => {
281
- Ae(e), E({}), M({
278
+ S
279
+ ]), Q = d(() => {
280
+ let e = $e();
281
+ e && Qe(e.zoom, e.panX, e.panY);
282
+ }, [$e, Qe]), $ = d((e) => {
283
+ je(e), O({}), F({
282
284
  type: "directionChange",
283
285
  direction: e
284
286
  });
285
- }, [M]), wt = u(() => {
287
+ }, [F]), Dt = d(() => {
286
288
  Ie((e) => {
287
- if (e === "view") return A(c(S, x)), M({
289
+ if (e === "view") return N(l(w, S)), F({
288
290
  type: "modeChange",
289
291
  mode: "text"
290
292
  }), "text";
291
293
  {
292
- let e = x ? s(ze, x).roots : o(ze);
293
- return j(() => e), E({}), M({
294
+ let e = S ? c(ze, S).roots : s(ze);
295
+ return P(() => e), O({}), F({
294
296
  type: "modeChange",
295
297
  mode: "view"
296
298
  }), "view";
297
299
  }
298
300
  });
299
301
  }, [
300
- S,
302
+ w,
301
303
  ze,
302
- j,
303
- x,
304
- M
305
- ]), Tt = u(() => {
306
- let e = Oe.current;
304
+ P,
305
+ S,
306
+ F
307
+ ]), Ot = d(() => {
308
+ let e = Ae.current;
307
309
  e && (document.fullscreenElement ? document.exitFullscreen() : e.requestFullscreen());
308
310
  }, []);
309
- d(() => {
311
+ f(() => {
310
312
  let e = () => {
311
313
  let e = !!document.fullscreenElement;
312
- Re(e), M({
314
+ Re(e), F({
313
315
  type: "fullscreenChange",
314
316
  fullscreen: e
315
317
  });
316
318
  };
317
319
  return document.addEventListener("fullscreenchange", e), () => document.removeEventListener("fullscreenchange", e);
318
- }, [M]);
319
- let Et = p(B);
320
- d(() => {
321
- B !== Et.current && (Et.current = B, M({
320
+ }, [F]);
321
+ let kt = m(U);
322
+ f(() => {
323
+ U !== kt.current && (kt.current = U, F({
322
324
  type: "zoomChange",
323
- zoom: B
325
+ zoom: U
324
326
  }));
325
- }, [B, M]);
326
- let Dt = u((e) => {
327
- if (e.key === "Escape" && k) {
327
+ }, [U, F]);
328
+ let At = d((e) => {
329
+ if (e.key === "Escape" && j) {
328
330
  e.preventDefault(), Z();
329
331
  return;
330
332
  }
331
- if (st) return;
333
+ if (ut) return;
332
334
  let t = e.metaKey || e.ctrlKey;
333
335
  if (e.shiftKey && !t) {
334
336
  if (e.code === "Equal") {
335
- e.preventDefault(), Qe();
337
+ e.preventDefault(), et();
336
338
  return;
337
339
  }
338
340
  if (e.code === "Minus") {
339
- e.preventDefault(), $e();
341
+ e.preventDefault(), tt();
340
342
  return;
341
343
  }
342
344
  if (e.code === "Digit0") {
@@ -356,93 +358,93 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
356
358
  return;
357
359
  }
358
360
  }
359
- if (e.key === "Enter" && !t && D && !v) {
361
+ if (e.key === "Enter" && !t && k && !y) {
360
362
  e.preventDefault();
361
363
  let t = ae(), n = {
362
364
  id: t,
363
- text: P.newNode
365
+ text: L.newNode
364
366
  };
365
- S.some((e) => e.id === D) && w === "both" ? j((e) => e.map((e) => {
366
- if (e.id !== D) return e;
367
- let t = e.children || [], r = re(e, n, "right", T[D] ?? Math.ceil(t.length / 2));
368
- return E((e) => ({
367
+ w.some((e) => e.id === k) && E === "both" ? P((e) => e.map((e) => {
368
+ if (e.id !== k) return e;
369
+ let t = e.children || [], r = re(e, n, "right", D[k] ?? Math.ceil(t.length / 2));
370
+ return O((e) => ({
369
371
  ...e,
370
- [D]: r.newSplitIndex
372
+ [k]: r.newSplitIndex
371
373
  })), r.data;
372
- })) : j((e) => ne(e, D, n)), Y(t), q(""), M({
374
+ })) : P((e) => ne(e, k, n)), Y(t), q(""), F({
373
375
  type: "nodeAdd",
374
376
  node: n,
375
- parentId: D
377
+ parentId: k
376
378
  });
377
379
  return;
378
380
  }
379
- if ((e.key === "Delete" || e.key === "Backspace") && D && !v) {
380
- if (e.preventDefault(), S.some((e) => e.id === D) && S.length <= 1) return;
381
- M({
381
+ if ((e.key === "Delete" || e.key === "Backspace") && k && !y) {
382
+ if (e.preventDefault(), w.some((e) => e.id === k) && w.length <= 1) return;
383
+ F({
382
384
  type: "nodeDelete",
383
- nodeId: D
384
- }), j((e) => ce(e, D)), O(null);
385
+ nodeId: k
386
+ }), P((e) => ce(e, k)), A(null);
385
387
  return;
386
388
  }
387
- if (t && e.key === "c" && D) {
388
- e.preventDefault(), Pe.current = ie(S, D);
389
+ if (t && e.key === "c" && k) {
390
+ e.preventDefault(), Pe.current = ie(w, k);
389
391
  return;
390
392
  }
391
- if (t && e.key === "x" && D && !v) {
392
- if (e.preventDefault(), Pe.current = ie(S, D), S.some((e) => e.id === D) && S.length <= 1) return;
393
- M({
393
+ if (t && e.key === "x" && k && !y) {
394
+ if (e.preventDefault(), Pe.current = ie(w, k), w.some((e) => e.id === k) && w.length <= 1) return;
395
+ F({
394
396
  type: "nodeDelete",
395
- nodeId: D
396
- }), j((e) => ce(e, D)), O(null);
397
+ nodeId: k
398
+ }), P((e) => ce(e, k)), A(null);
397
399
  return;
398
400
  }
399
- if (t && e.key === "v" && D && Pe.current && !v) {
401
+ if (t && e.key === "v" && k && Pe.current && !y) {
400
402
  e.preventDefault();
401
403
  let t = se(Pe.current);
402
- j((e) => ne(e, D, t)), M({
404
+ P((e) => ne(e, k, t)), F({
403
405
  type: "nodeAdd",
404
406
  node: t,
405
- parentId: D
407
+ parentId: k
406
408
  });
407
409
  return;
408
410
  }
409
411
  }, [
410
- st,
411
- D,
412
- S,
412
+ ut,
413
+ k,
413
414
  w,
414
- T,
415
+ E,
416
+ D,
417
+ P,
415
418
  j,
416
- k,
417
419
  Z,
418
420
  Y,
419
421
  q,
420
- P,
421
- Qe,
422
- $e,
422
+ L,
423
+ et,
424
+ tt,
423
425
  Q,
424
426
  $,
425
- v,
426
- M
427
+ y,
428
+ F
427
429
  ]);
428
- _e(De, () => ({
430
+ ve(ke, () => ({
429
431
  exportToSVG() {
430
- return r(F, I, {}, N, x);
432
+ return i(R, z, {}, I, S);
431
433
  },
432
434
  async exportToPNG() {
433
- return a(i(F, I, {}, N, x));
435
+ return o(a(R, z, {}, I, S));
434
436
  },
435
437
  exportToOutline() {
436
- return c(S, x);
438
+ return l(w, S);
437
439
  },
438
440
  getData() {
439
- return S;
441
+ return w;
440
442
  },
441
443
  setData(e) {
442
- C(oe(e)), E({});
444
+ T(oe(e)), O({});
443
445
  },
444
446
  setMarkdown(e) {
445
- C(x ? s(e, x).roots : o(e)), E({});
447
+ T(S ? c(e, S).roots : s(e)), O({});
446
448
  },
447
449
  fitView() {
448
450
  Q();
@@ -451,19 +453,23 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
451
453
  $(e);
452
454
  }
453
455
  }), [
454
- F,
455
- I,
456
+ R,
457
+ z,
458
+ w,
456
459
  S,
457
- x,
458
460
  Q,
459
461
  $,
460
- N
461
- ]), d(() => {
462
- if (!k) return;
462
+ I
463
+ ]), f(() => {
464
+ if (!j) return;
463
465
  let e = () => Z();
464
466
  return window.addEventListener("click", e), () => window.removeEventListener("click", e);
465
- }, [k, Z]);
466
- let Ot = u((e) => {
467
+ }, [j, Z]);
468
+ let jt = d((e) => {
469
+ T(S ? c(e, S).roots : s(e)), O({});
470
+ }, [S]), Mt = d(() => {
471
+ setTimeout(() => Q(), 100);
472
+ }, [Q]), Nt = d(() => {}, []), Pt = d((e) => {
467
473
  if (e.key !== "Tab") return;
468
474
  e.preventDefault();
469
475
  let t = e.currentTarget, { selectionStart: n, selectionEnd: r, value: i } = t;
@@ -473,7 +479,7 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
473
479
  let a = i.slice(e, r), o = a.match(/^ {1,2}/);
474
480
  if (!o) return;
475
481
  let s = o[0].length;
476
- A(i.slice(0, e) + a.slice(s) + i.slice(r)), requestAnimationFrame(() => {
482
+ N(i.slice(0, e) + a.slice(s) + i.slice(r)), requestAnimationFrame(() => {
477
483
  t.selectionStart = t.selectionEnd = Math.max(e, n - s);
478
484
  });
479
485
  } else {
@@ -481,92 +487,86 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
481
487
  let n = e.match(/^ {1,2}/), r = n ? n[0].length : 0;
482
488
  return o += r, t === 0 && (s = r), e.slice(r);
483
489
  }).join("\n");
484
- A(i.slice(0, e) + c + i.slice(r)), requestAnimationFrame(() => {
490
+ N(i.slice(0, e) + c + i.slice(r)), requestAnimationFrame(() => {
485
491
  t.selectionStart = n - s, t.selectionEnd = r - o;
486
492
  });
487
493
  }
488
- } else if (n === r) A(i.slice(0, n) + " " + i.slice(r)), requestAnimationFrame(() => {
494
+ } else if (n === r) N(i.slice(0, n) + " " + i.slice(r)), requestAnimationFrame(() => {
489
495
  t.selectionStart = t.selectionEnd = n + 2;
490
496
  });
491
497
  else {
492
498
  let e = i.lastIndexOf("\n", n - 1) + 1, a = i.slice(e, r).split("\n"), o = a.map((e) => " " + e).join("\n");
493
- A(i.slice(0, e) + o + i.slice(r)), requestAnimationFrame(() => {
499
+ N(i.slice(0, e) + o + i.slice(r)), requestAnimationFrame(() => {
494
500
  t.selectionStart = n + 2, t.selectionEnd = r + a.length * 2;
495
501
  });
496
502
  }
497
503
  }, []);
498
- return /* @__PURE__ */ g("div", {
499
- ref: Oe,
504
+ return /* @__PURE__ */ _("div", {
505
+ ref: Ae,
500
506
  className: "mindmap-container",
507
+ style: e(I),
501
508
  children: [
502
- Fe === "text" && /* @__PURE__ */ h("textarea", {
509
+ Fe === "text" && /* @__PURE__ */ g("textarea", {
503
510
  className: "mindmap-text-editor",
504
511
  value: ze,
505
- onChange: (e) => A(e.target.value),
506
- onKeyDown: Ot,
507
- readOnly: v,
508
- style: {
509
- background: N.canvas.bgColor,
510
- color: N.node.textColor,
511
- opacity: v ? .7 : 1
512
- }
512
+ onChange: (e) => N(e.target.value),
513
+ onKeyDown: Pt,
514
+ readOnly: y,
515
+ style: y ? { opacity: .7 } : void 0
513
516
  }),
514
- /* @__PURE__ */ h("svg", {
515
- ref: b,
516
- className: `mindmap-svg ${nt ? "dragging-canvas" : ""} ${U ? "dragging-node" : ""}`,
517
- style: {
518
- background: N.canvas.bgColor,
519
- display: Fe === "text" ? "none" : "block"
520
- },
517
+ /* @__PURE__ */ g("svg", {
518
+ ref: x,
519
+ className: `mindmap-svg ${it ? "dragging-canvas" : ""} ${W ? "dragging-node" : ""}`,
520
+ style: Fe === "text" ? { display: "none" } : void 0,
521
521
  tabIndex: 0,
522
- onMouseDown: mt,
523
- onMouseMove: it,
524
- onMouseUp: at,
525
- onMouseLeave: at,
526
- onClick: gt,
527
- onKeyDown: Dt,
528
- onContextMenu: _t,
529
- children: /* @__PURE__ */ g("g", {
530
- className: "mindmap-canvas",
531
- transform: `translate(${R.x}, ${R.y}) scale(${B})`,
522
+ onMouseDown: _t,
523
+ onMouseMove: st,
524
+ onMouseUp: ct,
525
+ onMouseLeave: ct,
526
+ onClick: yt,
527
+ onKeyDown: At,
528
+ onContextMenu: bt,
529
+ children: /* @__PURE__ */ _("g", {
530
+ className: `mindmap-canvas${X ? " mindmap-canvas-ready" : ""}`,
531
+ transform: `translate(${V.x}, ${V.y}) scale(${U})`,
532
532
  opacity: X ? 1 : 0,
533
- style: { transition: X ? "opacity 0.4s ease-out" : "none" },
534
533
  children: [
535
- /* @__PURE__ */ g("g", {
534
+ /* @__PURE__ */ _("g", {
536
535
  className: "mindmap-edges",
537
- children: [I.some((e) => e.isCrossLink) && /* @__PURE__ */ h("defs", { children: /* @__PURE__ */ h("marker", {
536
+ children: [z.some((e) => e.isCrossLink) && /* @__PURE__ */ g("defs", { children: /* @__PURE__ */ g("marker", {
538
537
  id: "mindmap-arrowhead",
539
538
  markerWidth: "8",
540
539
  markerHeight: "6",
541
540
  refX: "8",
542
541
  refY: "3",
543
542
  orient: "auto",
544
- children: /* @__PURE__ */ h("path", {
543
+ children: /* @__PURE__ */ g("path", {
545
544
  d: "M0,0 L8,3 L0,6",
546
545
  fill: "none",
547
546
  stroke: "currentColor",
548
547
  strokeWidth: 1.5
549
548
  })
550
- }) }), I.map((e) => {
549
+ }) }), z.map((e) => {
551
550
  let t = Xe[e.toId], n = t !== void 0;
552
- return /* @__PURE__ */ g("g", { children: [/* @__PURE__ */ h("path", {
551
+ return /* @__PURE__ */ _("g", { children: [/* @__PURE__ */ g("path", {
553
552
  d: e.path,
554
553
  stroke: e.color,
555
- strokeWidth: N.connection.strokeWidth,
554
+ strokeWidth: I.connection.strokeWidth,
556
555
  strokeLinecap: "round",
557
556
  strokeDasharray: n ? void 0 : e.strokeDasharray,
558
557
  markerEnd: e.isCrossLink ? "url(#mindmap-arrowhead)" : void 0,
559
558
  opacity: e.isCrossLink ? .7 : 1,
560
559
  fill: "none",
560
+ "data-branch-index": B[e.toId]?.branchIndex,
561
561
  className: [
562
562
  "mindmap-edge",
563
563
  e.isCrossLink ? "mindmap-edge-cross-link" : "",
564
- n ? "mindmap-edge-expanding" : nt || G.has(e.fromId) || G.has(e.toId) ? "" : "mindmap-edge-animated"
564
+ n ? "mindmap-edge-expanding" : it || K.has(e.fromId) || K.has(e.toId) ? "" : "mindmap-edge-animated"
565
565
  ].filter(Boolean).join(" "),
566
566
  style: n ? { animationDelay: `${t}ms` } : void 0
567
567
  }), e.label && (() => {
568
- let t = L[e.fromId], n = L[e.toId];
569
- return !t || !n ? null : /* @__PURE__ */ h("text", {
568
+ let t = B[e.fromId], n = B[e.toId];
569
+ return !t || !n ? null : /* @__PURE__ */ g("text", {
570
570
  className: "mindmap-edge-label",
571
571
  x: (t.x + n.x) / 2,
572
572
  y: (t.y + n.y) / 2 - 6,
@@ -574,72 +574,69 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
574
574
  fontSize: 11,
575
575
  fill: e.color,
576
576
  opacity: .8,
577
- fontFamily: N.node.fontFamily,
578
- style: { pointerEvents: "none" },
577
+ fontFamily: I.node.fontFamily,
579
578
  children: e.label
580
579
  });
581
580
  })()] }, e.key);
582
581
  })]
583
582
  }),
584
- /* @__PURE__ */ h("g", {
583
+ /* @__PURE__ */ g("g", {
585
584
  className: "mindmap-nodes",
586
- children: F.map((e) => {
587
- let t = G.has(e.id), n = t || nt ? "" : "mindmap-node-animated";
588
- return /* @__PURE__ */ h(me, {
585
+ children: R.map((e) => {
586
+ let t = K.has(e.id), n = t || it ? "" : "mindmap-node-animated";
587
+ return /* @__PURE__ */ g(me, {
589
588
  node: e,
590
- isEditing: st === e.id,
589
+ isEditing: ut === e.id,
591
590
  isPendingEdit: J === e.id,
592
- isSelected: D === e.id,
593
- isNew: ft.has(e.id),
591
+ isSelected: k === e.id,
592
+ isNew: ht.has(e.id),
594
593
  isGhost: t,
595
594
  animClass: n,
596
- editText: ct,
597
- theme: N,
598
- direction: w,
599
- onMouseDown: ot,
600
- onClick: ht,
601
- onDoubleClick: v ? () => {} : lt,
595
+ editText: dt,
596
+ theme: I,
597
+ direction: E,
598
+ onMouseDown: lt,
599
+ onClick: vt,
600
+ onDoubleClick: y ? () => {} : ft,
602
601
  onEditChange: q,
603
- onEditCommit: ut,
604
- onEditCancel: dt,
605
- onAddChild: yt,
606
- onRemarkHover: vt,
607
- onFoldToggle: x ? (e) => {
602
+ onEditCommit: pt,
603
+ onEditCancel: mt,
604
+ onAddChild: St,
605
+ onRemarkHover: xt,
606
+ onFoldToggle: S ? (e) => {
608
607
  He[e] || (Ge(e), setTimeout(() => Ge(null), 800)), Ue((t) => ({
609
608
  ...t,
610
609
  [e]: !t[e]
611
610
  }));
612
611
  } : void 0,
613
612
  expandDelay: Xe[e.id],
614
- readonly: v,
615
- plugins: x
613
+ readonly: y,
614
+ plugins: S
616
615
  }, e.id);
617
616
  })
618
617
  }),
619
- U && W && (() => {
620
- let e = L[U];
618
+ W && G && (() => {
619
+ let e = B[W];
621
620
  if (!e) return null;
622
- let n = W.x - e.x, r = W.y - e.y, i = e.parentId ? L[e.parentId] : null;
623
- return /* @__PURE__ */ g(ve, { children: [i && /* @__PURE__ */ h("path", {
621
+ let t = G.x - e.x, r = G.y - e.y, i = e.parentId ? B[e.parentId] : null;
622
+ return /* @__PURE__ */ _(ye, { children: [i && /* @__PURE__ */ g("path", {
624
623
  className: "mindmap-floating-edge",
625
- d: t(i.x, i.y, i.width, W.x, W.y, e.width, e.side),
624
+ d: n(i.x, i.y, i.width, G.x, G.y, e.width, e.side),
626
625
  stroke: e.color,
627
- strokeWidth: N.connection.strokeWidth,
626
+ strokeWidth: I.connection.strokeWidth,
628
627
  strokeLinecap: "round",
629
- fill: "none",
630
- style: { pointerEvents: "none" }
631
- }), /* @__PURE__ */ g("g", {
628
+ fill: "none"
629
+ }), /* @__PURE__ */ _("g", {
632
630
  className: "mindmap-floating",
633
- transform: `translate(${n}, ${r})`,
634
- style: { pointerEvents: "none" },
635
- children: [I.filter((e) => G.has(e.fromId) && G.has(e.toId)).map((e) => /* @__PURE__ */ h("path", {
631
+ transform: `translate(${t}, ${r})`,
632
+ children: [z.filter((e) => K.has(e.fromId) && K.has(e.toId)).map((e) => /* @__PURE__ */ g("path", {
636
633
  className: "mindmap-floating-edge",
637
634
  d: e.path,
638
635
  stroke: e.color,
639
- strokeWidth: N.connection.strokeWidth,
636
+ strokeWidth: I.connection.strokeWidth,
640
637
  strokeLinecap: "round",
641
638
  fill: "none"
642
- }, `fl-${e.key}`)), F.filter((e) => G.has(e.id)).map((e) => /* @__PURE__ */ h(me, {
639
+ }, `fl-${e.key}`)), R.filter((e) => K.has(e.id)).map((e) => /* @__PURE__ */ g(me, {
643
640
  node: e,
644
641
  isEditing: !1,
645
642
  isPendingEdit: !1,
@@ -647,8 +644,8 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
647
644
  isNew: !1,
648
645
  animClass: "",
649
646
  editText: "",
650
- theme: N,
651
- direction: w,
647
+ theme: I,
648
+ direction: E,
652
649
  onMouseDown: () => {},
653
650
  onClick: () => {},
654
651
  onDoubleClick: () => {},
@@ -660,49 +657,54 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
660
657
  }, `fl-${e.id}`))]
661
658
  })] });
662
659
  })(),
663
- x && e(x, F, I, N).map((e, t) => /* @__PURE__ */ h("g", {
660
+ S && t(S, R, z, I).map((e, t) => /* @__PURE__ */ g("g", {
664
661
  className: "mindmap-plugin-overlay",
665
662
  children: e
666
663
  }, `plugin-overlay-${t}`))
667
664
  ]
668
665
  })
669
666
  }),
670
- /* @__PURE__ */ h(he, {
671
- zoom: B,
672
- theme: N,
673
- messages: P,
667
+ /* @__PURE__ */ g(he, {
668
+ zoom: U,
669
+ theme: I,
670
+ messages: L,
674
671
  showZoom: Ye.zoom,
675
672
  mode: Fe,
676
673
  isFullscreen: Le,
677
- onZoomIn: Qe,
678
- onZoomOut: $e,
674
+ onZoomIn: et,
675
+ onZoomOut: tt,
679
676
  onAutoFit: Q,
680
- onModeToggle: wt,
681
- onFullscreenToggle: Tt
677
+ onModeToggle: Dt,
678
+ onFullscreenToggle: Ot
679
+ }),
680
+ Te && /* @__PURE__ */ g(_e, {
681
+ config: Te,
682
+ theme: I,
683
+ messages: L,
684
+ currentMarkdown: l(w, S),
685
+ onMarkdownStream: jt,
686
+ onComplete: Mt,
687
+ onError: Nt
682
688
  }),
683
- k && /* @__PURE__ */ h(ge, {
684
- position: k,
685
- theme: N,
686
- messages: P,
687
- direction: w,
688
- readonly: v,
689
- onNewRootNode: bt,
690
- onExportSVG: xt,
691
- onExportPNG: St,
692
- onExportMarkdown: Ct,
689
+ j && /* @__PURE__ */ g(ge, {
690
+ position: j,
691
+ theme: I,
692
+ messages: L,
693
+ direction: E,
694
+ readonly: y,
695
+ onNewRootNode: Ct,
696
+ onExportSVG: wt,
697
+ onExportPNG: Tt,
698
+ onExportMarkdown: Et,
693
699
  onDirectionChange: $,
694
700
  onClose: Z
695
701
  }),
696
- Be && /* @__PURE__ */ h("div", {
702
+ Be && /* @__PURE__ */ g("div", {
697
703
  className: "mindmap-remark-tooltip",
698
704
  style: {
699
705
  left: Be.x,
700
706
  top: Be.y,
701
- transform: "translateY(-100%)",
702
- background: N.contextMenu.bgColor,
703
- color: N.contextMenu.textColor,
704
- borderColor: N.contextMenu.borderColor,
705
- border: `1px solid ${N.contextMenu.borderColor}`
707
+ transform: "translateY(-100%)"
706
708
  },
707
709
  children: Be.text
708
710
  })
@@ -710,4 +712,4 @@ var _ = l(function({ data: l, markdown: _, defaultDirection: be = "both", theme:
710
712
  });
711
713
  });
712
714
  //#endregion
713
- export { _ as MindMap };
715
+ export { v as MindMap };