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