flow-mindmap 0.1.0-beta.1

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.
@@ -0,0 +1,1849 @@
1
+ import { defineComponent as st, openBlock as w, createElementBlock as k, Fragment as R, createElementVNode as g, createStaticVNode as pe, createCommentVNode as D, ref as A, reactive as Ue, onMounted as ut, onBeforeUnmount as dt, computed as Y, withModifiers as $, normalizeStyle as oe, createVNode as P, toDisplayString as ve, watch as Dt, nextTick as j, unref as S, renderList as Pt, normalizeClass as be, withDirectives as zn, withKeys as qe, vModelText as En, createBlock as Nn } from "vue";
2
+ const In = ["width", "height", "stroke-width"], Wn = {
3
+ key: 4,
4
+ points: "6 9 12 15 18 9"
5
+ }, $n = {
6
+ key: 5,
7
+ points: "9 6 15 12 9 18"
8
+ }, O = /* @__PURE__ */ st({
9
+ __name: "Icon",
10
+ props: {
11
+ name: {},
12
+ size: {},
13
+ stroke: {}
14
+ },
15
+ setup(n) {
16
+ return (d, i) => (w(), k("svg", {
17
+ width: n.size ?? 16,
18
+ height: n.size ?? 16,
19
+ viewBox: "0 0 24 24",
20
+ fill: "none",
21
+ stroke: "currentColor",
22
+ "stroke-width": n.stroke ?? 1.8,
23
+ "stroke-linecap": "round",
24
+ "stroke-linejoin": "round",
25
+ "aria-hidden": "true"
26
+ }, [
27
+ n.name === "add" ? (w(), k(R, { key: 0 }, [
28
+ i[0] || (i[0] = g("circle", {
29
+ cx: "12",
30
+ cy: "12",
31
+ r: "9"
32
+ }, null, -1)),
33
+ i[1] || (i[1] = g("line", {
34
+ x1: "12",
35
+ y1: "8",
36
+ x2: "12",
37
+ y2: "16"
38
+ }, null, -1)),
39
+ i[2] || (i[2] = g("line", {
40
+ x1: "8",
41
+ y1: "12",
42
+ x2: "16",
43
+ y2: "12"
44
+ }, null, -1))
45
+ ], 64)) : n.name === "minus" ? (w(), k(R, { key: 1 }, [
46
+ i[3] || (i[3] = g("circle", {
47
+ cx: "12",
48
+ cy: "12",
49
+ r: "9"
50
+ }, null, -1)),
51
+ i[4] || (i[4] = g("line", {
52
+ x1: "8",
53
+ y1: "12",
54
+ x2: "16",
55
+ y2: "12"
56
+ }, null, -1))
57
+ ], 64)) : n.name === "delete" ? (w(), k(R, { key: 2 }, [
58
+ i[5] || (i[5] = pe('<polyline points="4 7 20 7"></polyline><path d="M9 7 V5 a1 1 0 0 1 1 -1 h4 a1 1 0 0 1 1 1 V7"></path><path d="M6 7 l1 12 a1 1 0 0 0 1 1 h8 a1 1 0 0 0 1 -1 l1 -12"></path><line x1="10" y1="11" x2="10" y2="18"></line><line x1="14" y1="11" x2="14" y2="18"></line>', 5))
59
+ ], 64)) : n.name === "edit" ? (w(), k(R, { key: 3 }, [
60
+ i[6] || (i[6] = g("path", { d: "M4 20 l4 -1 11 -11 -3 -3 -11 11 z" }, null, -1)),
61
+ i[7] || (i[7] = g("line", {
62
+ x1: "14",
63
+ y1: "6",
64
+ x2: "18",
65
+ y2: "10"
66
+ }, null, -1))
67
+ ], 64)) : n.name === "collapse" ? (w(), k("polyline", Wn)) : n.name === "expand" ? (w(), k("polyline", $n)) : n.name === "zoom-in" ? (w(), k(R, { key: 6 }, [
68
+ i[8] || (i[8] = g("circle", {
69
+ cx: "11",
70
+ cy: "11",
71
+ r: "7"
72
+ }, null, -1)),
73
+ i[9] || (i[9] = g("line", {
74
+ x1: "11",
75
+ y1: "8",
76
+ x2: "11",
77
+ y2: "14"
78
+ }, null, -1)),
79
+ i[10] || (i[10] = g("line", {
80
+ x1: "8",
81
+ y1: "11",
82
+ x2: "14",
83
+ y2: "11"
84
+ }, null, -1)),
85
+ i[11] || (i[11] = g("line", {
86
+ x1: "16",
87
+ y1: "16",
88
+ x2: "21",
89
+ y2: "21"
90
+ }, null, -1))
91
+ ], 64)) : n.name === "zoom-out" ? (w(), k(R, { key: 7 }, [
92
+ i[12] || (i[12] = g("circle", {
93
+ cx: "11",
94
+ cy: "11",
95
+ r: "7"
96
+ }, null, -1)),
97
+ i[13] || (i[13] = g("line", {
98
+ x1: "8",
99
+ y1: "11",
100
+ x2: "14",
101
+ y2: "11"
102
+ }, null, -1)),
103
+ i[14] || (i[14] = g("line", {
104
+ x1: "16",
105
+ y1: "16",
106
+ x2: "21",
107
+ y2: "21"
108
+ }, null, -1))
109
+ ], 64)) : n.name === "reset" ? (w(), k(R, { key: 8 }, [
110
+ i[15] || (i[15] = g("circle", {
111
+ cx: "12",
112
+ cy: "12",
113
+ r: "9"
114
+ }, null, -1)),
115
+ i[16] || (i[16] = g("circle", {
116
+ cx: "12",
117
+ cy: "12",
118
+ r: "4"
119
+ }, null, -1)),
120
+ i[17] || (i[17] = g("circle", {
121
+ cx: "12",
122
+ cy: "12",
123
+ r: "0.8",
124
+ fill: "currentColor"
125
+ }, null, -1))
126
+ ], 64)) : n.name === "logo" ? (w(), k(R, { key: 9 }, [
127
+ i[18] || (i[18] = pe('<circle cx="12" cy="12" r="2.2"></circle><circle cx="4" cy="5" r="1.6"></circle><circle cx="20" cy="5" r="1.6"></circle><circle cx="4" cy="19" r="1.6"></circle><circle cx="20" cy="19" r="1.6"></circle><line x1="10.5" y1="10.8" x2="5.2" y2="6.4"></line><line x1="13.5" y1="10.8" x2="18.8" y2="6.4"></line><line x1="10.5" y1="13.2" x2="5.2" y2="17.6"></line><line x1="13.5" y1="13.2" x2="18.8" y2="17.6"></line>', 9))
128
+ ], 64)) : n.name === "import" ? (w(), k(R, { key: 10 }, [
129
+ i[19] || (i[19] = g("path", { d: "M12 4 V15" }, null, -1)),
130
+ i[20] || (i[20] = g("polyline", { points: "7 10 12 15 17 10" }, null, -1)),
131
+ i[21] || (i[21] = g("path", { d: "M4 19 H20" }, null, -1))
132
+ ], 64)) : n.name === "export" ? (w(), k(R, { key: 11 }, [
133
+ i[22] || (i[22] = g("path", { d: "M12 15 V4" }, null, -1)),
134
+ i[23] || (i[23] = g("polyline", { points: "7 9 12 4 17 9" }, null, -1)),
135
+ i[24] || (i[24] = g("path", { d: "M4 19 H20" }, null, -1))
136
+ ], 64)) : n.name === "balance" ? (w(), k(R, { key: 12 }, [
137
+ i[25] || (i[25] = pe('<line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line><polyline points="9 4 5 6 9 8"></polyline><polyline points="15 4 19 6 15 8"></polyline><polyline points="9 10 5 12 9 14"></polyline><polyline points="15 10 19 12 15 14"></polyline><polyline points="9 16 5 18 9 20"></polyline><polyline points="15 16 19 18 15 20"></polyline>', 9))
138
+ ], 64)) : n.name === "mindmap" ? (w(), k(R, { key: 13 }, [
139
+ i[26] || (i[26] = pe('<circle cx="12" cy="12" r="2.2" fill="currentColor" stroke="none"></circle><line x1="13" y1="11" x2="19" y2="6"></line><line x1="13" y1="13" x2="19" y2="18"></line><line x1="11" y1="11" x2="5" y2="6"></line><line x1="11" y1="13" x2="5" y2="18"></line>', 5))
140
+ ], 64)) : n.name === "tree" ? (w(), k(R, { key: 14 }, [
141
+ i[27] || (i[27] = pe('<circle cx="6" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="6" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="18" r="2" fill="currentColor" stroke="none"></circle><line x1="8" y1="12" x2="16" y2="6"></line><line x1="8" y1="12" x2="16" y2="12"></line><line x1="8" y1="12" x2="16" y2="18"></line>', 7))
142
+ ], 64)) : n.name === "org" ? (w(), k(R, { key: 15 }, [
143
+ i[28] || (i[28] = pe('<circle cx="12" cy="5" r="2" fill="currentColor" stroke="none"></circle><circle cx="6" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="12" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="19" r="2" fill="currentColor" stroke="none"></circle><line x1="12" y1="7" x2="12" y2="13"></line><line x1="6" y1="13" x2="18" y2="13"></line><line x1="6" y1="13" x2="6" y2="17"></line><line x1="12" y1="13" x2="12" y2="17"></line><line x1="18" y1="13" x2="18" y2="17"></line>', 9))
144
+ ], 64)) : n.name === "image" ? (w(), k(R, { key: 16 }, [
145
+ i[29] || (i[29] = g("rect", {
146
+ x: "3",
147
+ y: "5",
148
+ width: "18",
149
+ height: "14",
150
+ rx: "2"
151
+ }, null, -1)),
152
+ i[30] || (i[30] = g("circle", {
153
+ cx: "9",
154
+ cy: "11",
155
+ r: "1.6"
156
+ }, null, -1)),
157
+ i[31] || (i[31] = g("polyline", { points: "3 17 9 12 13 15 16 13 21 17" }, null, -1))
158
+ ], 64)) : n.name === "x" ? (w(), k(R, { key: 17 }, [
159
+ i[32] || (i[32] = g("line", {
160
+ x1: "6",
161
+ y1: "6",
162
+ x2: "18",
163
+ y2: "18"
164
+ }, null, -1)),
165
+ i[33] || (i[33] = g("line", {
166
+ x1: "18",
167
+ y1: "6",
168
+ x2: "6",
169
+ y2: "18"
170
+ }, null, -1))
171
+ ], 64)) : n.name === "link" ? (w(), k(R, { key: 18 }, [
172
+ i[34] || (i[34] = g("path", { d: "M10 13 a4 4 0 0 0 5.66 0 l3 -3 a4 4 0 1 0 -5.66 -5.66 l-1 1" }, null, -1)),
173
+ i[35] || (i[35] = g("path", { d: "M14 11 a4 4 0 0 0 -5.66 0 l-3 3 a4 4 0 1 0 5.66 5.66 l1 -1" }, null, -1))
174
+ ], 64)) : n.name === "note" ? (w(), k(R, { key: 19 }, [
175
+ i[36] || (i[36] = g("path", { d: "M6 4 h9 l3 3 v13 a1 1 0 0 1 -1 1 h-11 a1 1 0 0 1 -1 -1 v-15 a1 1 0 0 1 1 -1 z" }, null, -1)),
176
+ i[37] || (i[37] = g("line", {
177
+ x1: "8",
178
+ y1: "10",
179
+ x2: "16",
180
+ y2: "10"
181
+ }, null, -1)),
182
+ i[38] || (i[38] = g("line", {
183
+ x1: "8",
184
+ y1: "13",
185
+ x2: "16",
186
+ y2: "13"
187
+ }, null, -1)),
188
+ i[39] || (i[39] = g("line", {
189
+ x1: "8",
190
+ y1: "16",
191
+ x2: "13",
192
+ y2: "16"
193
+ }, null, -1))
194
+ ], 64)) : D("", !0)
195
+ ], 8, In));
196
+ }
197
+ }), Bn = "data:image/svg+xml,%3csvg%20t='1780822312364'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='7459'%20width='200'%20height='200'%3e%3cpath%20d='M329.16%20292.571h658.286V512H329.16zM329.16%200h658.286v219.429H329.16z'%20fill='%239AA1A2'%20p-id='7460'%3e%3c/path%3e%3cpath%20d='M44.927%20146.286a46.519%2046.519%200%200%201%2038.107-73.143h319.269v73.143H109.73V791.99l-48.713%205.705-24.43-651.41h8.339z'%20fill='%239AA1A2'%20p-id='7461'%3e%3c/path%3e%3cpath%20d='M363.83%20877.714H179.51c-78.775%200-142.921-66.12-142.921-147.31V112.787c0-21.943%2017.188-39.643%2038.473-39.643%2021.211%200%2033.5%2017.774%2033.5%2039.643v617.619c0%2037.522%2028.013%2076.58%2064.438%2076.58h190.903c21.211%200%2038.766%2013.97%2038.766%2035.84%200%2021.943-17.555%2034.89-38.766%2034.89z'%20fill='%239AA1A2'%20p-id='7462'%3e%3c/path%3e%3cpath%20d='M432.95%20438.857H179.51c-78.775%200-81.043-18.578-81.043-62.903l10.094-90.624c0%2020.48%2013.458%2080.677%2049.884%2080.677h210.139c21.211%200%20120.613%204.023%20120.613%2016.018%200%2011.922-35.036%2056.832-56.32%2056.832zM640.017%20749.714V640a54.857%2054.857%200%200%201%20109.714%200v109.714h109.715a54.857%2054.857%200%200%201%200%20109.715H749.73v109.714a54.857%2054.857%200%200%201-109.714%200V859.429H530.303a54.857%2054.857%200%200%201%200-109.715h109.714z'%20fill='%239AA1A2'%20p-id='7463'%3e%3c/path%3e%3c/svg%3e", Rn = "data:image/svg+xml,%3csvg%20t='1780822464335'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='8457'%20width='200'%20height='200'%3e%3cpath%20d='M512%20804.571h512V1024H512V804.571zM0%200h658.286v219.429H0V0z'%20fill='%239AA1A2'%20p-id='8458'%3e%3c/path%3e%3cpath%20d='M619.813%20950.857h-184.32c-78.775%200-142.922-66.121-142.922-147.31V185.93c0-21.943%2017.189-39.643%2038.474-39.643%2021.211%200%2033.353%2017.773%2033.353%2039.643v617.618c0%2037.523%2034.743%2073.728%2071.095%2073.728h184.32c21.211%200%2038.473%2012.069%2038.473%2033.939%200%2021.943-17.189%2039.643-38.473%2039.643z'%20fill='%239AA1A2'%20p-id='8459'%3e%3c/path%3e%3cpath%20d='M676.571%20457.143V347.429a54.857%2054.857%200%200%201%20109.715%200v109.714H896a54.857%2054.857%200%200%201%200%20109.714H786.286v109.714a54.857%2054.857%200%200%201-109.715%200V566.857H566.857a54.857%2054.857%200%200%201%200-109.714h109.714z'%20fill='%239AA1A2'%20p-id='8460'%3e%3c/path%3e%3c/svg%3e", Je = [18, 15, 13, 12], An = [700, 600, 500, 400], Ln = [52, 40, 32, 28], Ot = [120, 80, 60, 44], Hn = [0.8, 0.8, 0.8, 0.8], Dn = Je.length - 1;
198
+ function Pn(n) {
199
+ return Math.round(Je[je(n)] * Hn[je(n)]);
200
+ }
201
+ function je(n) {
202
+ return Math.min(Dn, Math.max(0, n));
203
+ }
204
+ function On(n) {
205
+ return Je[je(n)];
206
+ }
207
+ const Ye = 60, Me = 14, J = 24;
208
+ let at = null;
209
+ function Tn() {
210
+ if (at) return at;
211
+ const n = typeof document < "u" ? document.createElement("canvas").getContext("2d") : null;
212
+ return n ? (at = n, n) : {
213
+ font: "",
214
+ measureText: () => ({ width: 0 })
215
+ };
216
+ }
217
+ const Tt = /* @__PURE__ */ new Map();
218
+ function Fn(n, d, i) {
219
+ const l = `${i}|${d}|${n}`, a = Tt.get(l);
220
+ if (a !== void 0) return a;
221
+ const s = Tn();
222
+ s.font = `${i} ${d}px "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif`;
223
+ const f = s.measureText(n).width;
224
+ return Tt.set(l, f), f;
225
+ }
226
+ const Vn = 24, Xn = 400, qn = 8, Ft = 16, Yn = 4;
227
+ function Un(n, d, i) {
228
+ return Math.min(i, Math.max(d, n));
229
+ }
230
+ function Kn(n, d) {
231
+ const i = je(d), l = Fn(n.text || "", Je[i], An[i]), a = Pn(d), s = Math.ceil(l + a * 2), f = Ln[i];
232
+ let x = 0;
233
+ if (n.link && (x += Ft), n.note && (x += Ft), x > 0) {
234
+ const I = (n.link ? 1 : 0) + (n.note ? 1 : 0);
235
+ x += Yn * I;
236
+ }
237
+ const m = s + x;
238
+ if (!n.image)
239
+ return { w: Math.max(Ot[i], m), h: f };
240
+ const y = Un(n.image.width, Vn, Xn), u = Math.max(Ot[i], m, Math.ceil(y + a * 2)), b = Math.ceil(n.image.height + qn + f);
241
+ return { w: u, h: b };
242
+ }
243
+ function Gn(n, d = {}) {
244
+ const i = d.mode ?? "mindmap", l = d.preservePositions === !0, a = qt(n, 0, null, 1, "right");
245
+ return Jn(a), jn(a, i, l), a.x = 0, a.y = 0, Zn(a, l);
246
+ }
247
+ function jn(n, d, i = !1) {
248
+ if (d === "mindmap") {
249
+ const l = n.children;
250
+ if (l.length !== 0) if (l.length === 1)
251
+ l[0]._dir = "right", l[0].side = 1, l[0]._dirRight = 1;
252
+ else {
253
+ const x = l.reduce((b, I) => b + I._subtreeH, 0);
254
+ let m = 1, y = Math.abs(l[0]._subtreeH - (x - l[0]._subtreeH)), u = 0;
255
+ for (let b = 0; b < l.length - 1; b++) {
256
+ u += l[b]._subtreeH;
257
+ const I = Math.abs(u - (x - u));
258
+ I < y && (y = I, m = b + 1);
259
+ }
260
+ for (let b = 0; b < m; b++)
261
+ l[b]._dir = "right", l[b].side = 1, l[b]._dirRight = 1;
262
+ for (let b = m; b < l.length; b++)
263
+ l[b]._dir = "left", l[b].side = -1, l[b]._dirRight = -1;
264
+ }
265
+ const a = n.children.filter((x) => x.side === 1), s = n.children.filter((x) => x.side === -1), f = (x, m) => {
266
+ const y = m === "right" ? 1 : -1;
267
+ x._dir = m, x.side = y, x._dirRight = y;
268
+ for (const u of x.children) f(u, m);
269
+ };
270
+ for (const x of a) f(x, "right");
271
+ for (const x of s) f(x, "left");
272
+ if (a.length > 0) {
273
+ const x = { ...n, children: a };
274
+ Ke(x, "right", Ye, !0, i);
275
+ }
276
+ if (s.length > 0) {
277
+ const x = { ...n, children: s };
278
+ Ke(x, "left", Ye, !0, i);
279
+ }
280
+ } else if (d === "tree") {
281
+ const l = (a) => {
282
+ a.side = 1, a._dir = "right";
283
+ for (const s of a.children) l(s);
284
+ };
285
+ for (const a of n.children) a._dir = "right";
286
+ Ke(n, "right", Ye, !0, i), l(n);
287
+ } else {
288
+ for (const l of n.children) l._dir = "down";
289
+ Xt(n, Ye, i);
290
+ }
291
+ }
292
+ function Ke(n, d, i, l, a = !1) {
293
+ if (n.children.length === 0) return;
294
+ const s = n.children.reduce(
295
+ (y, u, b) => y + u._subtreeH + (b > 0 ? Me : 0),
296
+ 0
297
+ ), f = d === "right" ? 1 : -1, x = l ? f : 1;
298
+ let m = n.y - x * s / 2;
299
+ n.children.forEach((y) => {
300
+ a || (y.x = n.x + f * (n.width / 2 + i + y.width / 2), y.y = m + x * y._subtreeH / 2), y._dir = d, m += x * (y._subtreeH + Me), Ke(y, d, i, !1, a);
301
+ });
302
+ }
303
+ function Xt(n, d, i = !1) {
304
+ if (n.children.length === 0) return;
305
+ const l = n.children.reduce(
306
+ (s, f, x) => s + f._subtreeW + (x > 0 ? Me * 2 : 0),
307
+ 0
308
+ );
309
+ let a = n.x - l / 2;
310
+ n.children.forEach((s) => {
311
+ i || (s.x = a + s._subtreeW / 2, s.y = n.y + n.height / 2 + d + s.height / 2), s._dir = "down", a += s._subtreeW + Me * 2, Xt(s, d, i);
312
+ });
313
+ }
314
+ function qt(n, d, i, l, a) {
315
+ const s = Kn(n, d), f = {
316
+ id: n.id,
317
+ text: n.text,
318
+ depth: d,
319
+ // Honor a user-set position from the data tree (drag commit).
320
+ // The next applyDoLayout pass will overwrite these unless
321
+ // preservePositions is true.
322
+ x: n._x ?? 0,
323
+ y: n._y ?? 0,
324
+ width: s.w,
325
+ height: s.h,
326
+ fontSize: On(d),
327
+ isRoot: d === 0,
328
+ collapsed: n.collapsed,
329
+ side: l,
330
+ _dir: a,
331
+ _dirRight: l,
332
+ _subtreeH: s.h,
333
+ _subtreeW: s.w,
334
+ image: n.image ? { ...n.image } : void 0,
335
+ link: n.link ? { url: n.link.url } : void 0,
336
+ note: n.note ? { text: n.note.text } : void 0,
337
+ children: [],
338
+ parent: i
339
+ };
340
+ if (n.collapsed) return f;
341
+ const x = n.children.length, m = Math.ceil(x / 2);
342
+ return f.children = n.children.map((y, u) => {
343
+ const b = d === 0 ? u < m ? 1 : -1 : l;
344
+ return qt(y, d + 1, f, b, a);
345
+ }), f;
346
+ }
347
+ function Jn(n) {
348
+ const d = [n];
349
+ for (let i = 0; i < d.length; i++) {
350
+ const l = d[i];
351
+ for (const a of l.children) d.push(a);
352
+ }
353
+ for (let i = d.length - 1; i >= 0; i--) {
354
+ const l = d[i];
355
+ if (l.collapsed || l.children.length === 0) {
356
+ l._subtreeH = l.height, l._subtreeW = l.width;
357
+ continue;
358
+ }
359
+ let a = 0, s = 0;
360
+ for (const f of l.children)
361
+ a += f._subtreeH, s += f._subtreeW;
362
+ l.children.length > 1 && (a += Me * (l.children.length - 1), s += Me * 2 * (l.children.length - 1)), l._subtreeH = Math.max(l.height, a), l._subtreeW = Math.max(l.width, s);
363
+ }
364
+ }
365
+ function Zn(n, d = !1) {
366
+ const i = [n];
367
+ let l = 1 / 0, a = -1 / 0, s = 1 / 0, f = -1 / 0;
368
+ for (; i.length; ) {
369
+ const y = i.pop(), u = y.width / 2, b = y.height / 2;
370
+ y.x - u < l && (l = y.x - u), y.x + u > a && (a = y.x + u), y.y - b < s && (s = y.y - b), y.y + b > f && (f = y.y + b), i.push(...y.children);
371
+ }
372
+ if (d)
373
+ return {
374
+ root: n,
375
+ width: a - l + J * 2,
376
+ height: f - s + J * 2,
377
+ vbX: l - J,
378
+ vbY: s - J,
379
+ vbW: a - l + J * 2,
380
+ vbH: f - s + J * 2
381
+ };
382
+ const x = J - s, m = [n];
383
+ for (; m.length; ) {
384
+ const y = m.pop();
385
+ y.y += x, m.push(...y.children);
386
+ }
387
+ return s += x, f += x, {
388
+ root: n,
389
+ width: a - l + J * 2,
390
+ height: f + J,
391
+ vbX: l - J,
392
+ vbY: 0,
393
+ vbW: a - l + J * 2,
394
+ vbH: f + J
395
+ };
396
+ }
397
+ const Le = [
398
+ {
399
+ id: "default",
400
+ name: "默认",
401
+ colors: [
402
+ "#f87171",
403
+ "#fb923c",
404
+ "#fbbf24",
405
+ "#a3e635",
406
+ "#34d399",
407
+ "#22d3ee",
408
+ "#818cf8",
409
+ "#c084fc"
410
+ ]
411
+ },
412
+ {
413
+ id: "classic",
414
+ name: "经典",
415
+ colors: [
416
+ "#ef4444",
417
+ "#f59e0b",
418
+ "#10b981",
419
+ "#3b82f6",
420
+ "#6366f1",
421
+ "#8b5cf6",
422
+ "#ec4899",
423
+ "#14b8a6"
424
+ ]
425
+ },
426
+ {
427
+ id: "vivid",
428
+ name: "活力",
429
+ colors: [
430
+ "#dc2626",
431
+ "#ea580c",
432
+ "#ca8a04",
433
+ "#16a34a",
434
+ "#0891b2",
435
+ "#2563eb",
436
+ "#7c3aed",
437
+ "#db2777"
438
+ ]
439
+ },
440
+ {
441
+ id: "dev",
442
+ name: "代码",
443
+ colors: [
444
+ "#f472b6",
445
+ "#a78bfa",
446
+ "#60a5fa",
447
+ "#38bdf8",
448
+ "#22d3ee",
449
+ "#34d399",
450
+ "#facc15",
451
+ "#fb923c"
452
+ ]
453
+ },
454
+ {
455
+ id: "mint",
456
+ name: "薄荷",
457
+ colors: [
458
+ "#5eead4",
459
+ "#67e8f9",
460
+ "#93c5fd",
461
+ "#c4b5fd",
462
+ "#fbcfe8",
463
+ "#fde68a",
464
+ "#a7f3d0",
465
+ "#bae6fd"
466
+ ]
467
+ }
468
+ ];
469
+ function Qn(n, d = []) {
470
+ return [...Le, ...d].find((l) => l.id === n) ?? Le[0];
471
+ }
472
+ function Ze() {
473
+ return "n_" + Math.random().toString(36).slice(2, 10) + Date.now().toString(36).slice(-4);
474
+ }
475
+ function ke(n) {
476
+ return JSON.parse(JSON.stringify(n));
477
+ }
478
+ function W(n, d) {
479
+ if (n.id === d) return n;
480
+ for (const i of n.children) {
481
+ const l = W(i, d);
482
+ if (l) return l;
483
+ }
484
+ return null;
485
+ }
486
+ function te(n, d, i = null) {
487
+ if (n.id === d) return i;
488
+ for (const l of n.children) {
489
+ const a = te(l, d, n);
490
+ if (a !== null) return a;
491
+ }
492
+ return null;
493
+ }
494
+ function Yt(n, d) {
495
+ const i = n.children.findIndex((l) => l.id === d);
496
+ if (i >= 0)
497
+ return n.children.splice(i, 1), !0;
498
+ for (const l of n.children)
499
+ if (Yt(l, d)) return !0;
500
+ return !1;
501
+ }
502
+ function _n(n, d, i) {
503
+ const l = W(n, d);
504
+ return !l || l.text === i ? !1 : (l.text = i, !0);
505
+ }
506
+ function ei(n, d, i, l) {
507
+ if (!te(n, d) || d === i || W(W(n, d), i)) return !1;
508
+ const a = te(n, d), s = a.children.findIndex((y) => y.id === d);
509
+ if (s < 0) return !1;
510
+ const [f] = a.children.splice(s, 1);
511
+ if (l === "child") {
512
+ const y = W(n, i);
513
+ return y ? (y.children.push(f), !0) : (a.children.splice(s, 0, f), !1);
514
+ }
515
+ const x = te(n, i);
516
+ if (!x)
517
+ return a.children.splice(s, 0, f), !1;
518
+ let m = x.children.findIndex((y) => y.id === i);
519
+ return m < 0 ? (a.children.splice(s, 0, f), !1) : (l === "after" && (m += 1), x.children.splice(m, 0, f), !0);
520
+ }
521
+ function Ut(n) {
522
+ const d = /^新节点(?:\s+(\d+))?$/;
523
+ let i = 0, l = !1;
524
+ for (const a of n.children) {
525
+ const s = a.text.match(d);
526
+ if (s)
527
+ if (s[1]) {
528
+ const f = parseInt(s[1], 10);
529
+ f > i && (i = f);
530
+ } else
531
+ l = !0;
532
+ }
533
+ return i === 0 && !l ? Ge : i > 0 ? `新节点 ${i + 1}` : "新节点 2";
534
+ }
535
+ function ti(n, d, i) {
536
+ const l = W(n, d);
537
+ if (!l) return null;
538
+ const a = { id: Ze(), text: i ?? Ut(l), children: [] };
539
+ return l.children.push(a), a;
540
+ }
541
+ function ni(n, d, i) {
542
+ const l = te(n, d);
543
+ if (!l) return null;
544
+ const a = l.children.findIndex((f) => f.id === d);
545
+ if (a < 0) return null;
546
+ const s = { id: Ze(), text: i ?? Ut(l), children: [] };
547
+ return l.children.splice(a + 1, 0, s), s;
548
+ }
549
+ function ii(n, d, i) {
550
+ const l = te(n, d);
551
+ if (!l) return null;
552
+ const a = l.children.findIndex((f) => f.id === d);
553
+ if (a < 0) return null;
554
+ const s = { id: Ze(), text: i, children: [] };
555
+ return l.children.splice(a, 0, s), s;
556
+ }
557
+ function li(n, d) {
558
+ const i = te(n, d);
559
+ if (!i) return null;
560
+ const l = i.children.findIndex((f) => f.id === d);
561
+ if (l < 0) return null;
562
+ const a = i.children[l], s = ke(a);
563
+ return Kt(s), i.children.splice(l + 1, 0, s), s;
564
+ }
565
+ function Kt(n) {
566
+ n.id = Ze();
567
+ for (const d of n.children) Kt(d);
568
+ }
569
+ const Ge = "新节点";
570
+ function oi(n) {
571
+ const d = n.minScale ?? 0.2, i = n.maxScale ?? 3, l = n.step ?? 1.2, a = A(1), s = A(0), f = A(0), x = A(!1), m = Ue({
572
+ x: 0,
573
+ y: 0,
574
+ ox: 0,
575
+ oy: 0
576
+ }), y = A(!1), u = Ue({ x: 0, y: 0 }), b = Ue({ x: 0, y: 0, width: 0, height: 0 }), I = A(0);
577
+ let C = null;
578
+ function H(E) {
579
+ C = E;
580
+ }
581
+ function _(E) {
582
+ E.preventDefault();
583
+ const V = n.getContainer();
584
+ if (!V) return;
585
+ const X = -E.deltaY * 1e-3, U = Math.min(i, Math.max(d, a.value * (1 + X))), Z = V.getBoundingClientRect(), Q = E.clientX - Z.left, he = E.clientY - Z.top, Ie = (Q - s.value) / a.value, re = (he - f.value) / a.value;
586
+ a.value = U, s.value = Q - Ie * U, f.value = he - re * U;
587
+ }
588
+ function ie() {
589
+ a.value = Math.min(i, a.value * l);
590
+ }
591
+ function He() {
592
+ a.value = Math.max(d, a.value / l);
593
+ }
594
+ function le(E) {
595
+ var X;
596
+ E.target.closest(".zm-node, .zm-toolbar, button, input, textarea") || (x.value = !0, m.x = E.clientX, m.y = E.clientY, m.ox = s.value, m.oy = f.value, window.addEventListener("mousemove", Ce), window.addEventListener("mouseup", De), (X = E.preventDefault) == null || X.call(E));
597
+ }
598
+ function Ce(E) {
599
+ x.value && (s.value = m.ox + (E.clientX - m.x), f.value = m.oy + (E.clientY - m.y));
600
+ }
601
+ function De() {
602
+ x.value = !1, window.removeEventListener("mousemove", Ce), window.removeEventListener("mouseup", De);
603
+ }
604
+ function Se(E, V) {
605
+ y.value = !0, u.x = E, u.y = V, b.x = E, b.y = V, b.width = 0, b.height = 0, I.value++, window.addEventListener("mousemove", Ne), window.addEventListener("mouseup", Ee);
606
+ }
607
+ function ze(E, V) {
608
+ if (!y.value) return;
609
+ const X = Math.min(u.x, E), U = Math.min(u.y, V), Z = Math.max(u.x, E), Q = Math.max(u.y, V);
610
+ b.x = X, b.y = U, b.width = Z - X, b.height = Q - U, I.value++;
611
+ }
612
+ function Ee() {
613
+ y.value = !1, window.removeEventListener("mousemove", Ne), window.removeEventListener("mouseup", Ee), C && C();
614
+ }
615
+ function Ne(E) {
616
+ if (!y.value) return;
617
+ const V = n.getContainer();
618
+ if (!V) return;
619
+ const X = V.getBoundingClientRect(), U = (E.clientX - X.left - s.value) / a.value, Z = (E.clientY - X.top - f.value) / a.value;
620
+ ze(U, Z);
621
+ }
622
+ function F(E, V, X, U = 60) {
623
+ const Z = n.getContainer();
624
+ if (!Z) return;
625
+ const Q = Z.getBoundingClientRect(), he = (Q.width - U * 2) / E, Ie = (Q.height - U * 2) / V, re = Math.min(1, Math.max(0.3, Math.min(he, Ie)));
626
+ a.value = re, s.value = Q.width / 2, f.value = Q.height / 2 - X * re;
627
+ }
628
+ return {
629
+ scale: a,
630
+ offsetX: s,
631
+ offsetY: f,
632
+ isPanning: x,
633
+ onWheel: _,
634
+ zoomIn: ie,
635
+ zoomOut: He,
636
+ startPan: le,
637
+ startMarquee: Se,
638
+ updateMarquee: ze,
639
+ isMarquee: y,
640
+ marquee: b,
641
+ marqueeVersion: I,
642
+ setOnMarqueeEnd: H,
643
+ resetView: F
644
+ };
645
+ }
646
+ const ri = typeof navigator < "u" && /Mac|iPhone|iPad/.test(navigator.platform);
647
+ function Vt(n) {
648
+ return ri ? n.metaKey : n.ctrlKey;
649
+ }
650
+ function ai(n) {
651
+ function d() {
652
+ const l = n.getSelectedId();
653
+ return l || (n.defaultTargetId ? n.defaultTargetId() : n.getRootId());
654
+ }
655
+ function i(l) {
656
+ const a = l.target;
657
+ if (a && (a.tagName === "INPUT" || a.tagName === "TEXTAREA" || a.isContentEditable) || n.isReadonly() || n.isEditing()) return;
658
+ const s = n.getSelectedId(), f = d();
659
+ if (f) {
660
+ if (Vt(l) && !l.shiftKey) {
661
+ if (l.key === "d" || l.key === "D") {
662
+ s && s !== n.getRootId() && (l.preventDefault(), n.onDuplicate(s));
663
+ return;
664
+ }
665
+ if (l.key === "z" || l.key === "Z") {
666
+ l.preventDefault(), n.onUndo();
667
+ return;
668
+ }
669
+ if (l.key === "y" || l.key === "Y") {
670
+ l.preventDefault(), n.onRedo();
671
+ return;
672
+ }
673
+ if (l.key === "Home") {
674
+ l.preventDefault(), n.onSelectRoot();
675
+ return;
676
+ }
677
+ }
678
+ if (Vt(l) && l.shiftKey && (l.key === "Z" || l.key === "z")) {
679
+ l.preventDefault(), n.onRedo();
680
+ return;
681
+ }
682
+ l.key === "Tab" ? (l.preventDefault(), n.onAddChild(f)) : l.key === "Enter" ? (l.preventDefault(), l.shiftKey ? s && s !== n.getRootId() && n.onAddSiblingBefore(s) : n.onAddSibling(f)) : (l.key === "Delete" || l.key === "Backspace") && s && s !== n.getRootId() ? (l.preventDefault(), n.onRemove(s)) : l.key === "F2" && s ? (l.preventDefault(), n.onStartEdit(s)) : l.key === "Escape" ? (l.preventDefault(), n.onClearSelection()) : l.key === "ArrowDown" ? (l.preventDefault(), n.onNavigate(0, 1)) : l.key === "ArrowUp" ? (l.preventDefault(), n.onNavigate(0, -1)) : l.key === "ArrowRight" ? (l.preventDefault(), n.onNavigate(1, 0)) : l.key === "ArrowLeft" && (l.preventDefault(), n.onNavigate(-1, 0));
683
+ }
684
+ }
685
+ ut(() => {
686
+ window.addEventListener("keydown", i);
687
+ }), dt(() => {
688
+ window.removeEventListener("keydown", i);
689
+ });
690
+ }
691
+ function ui(n = 100) {
692
+ const d = A([]);
693
+ let i = -1;
694
+ function l() {
695
+ return i > 0;
696
+ }
697
+ function a() {
698
+ return i < d.value.length - 1;
699
+ }
700
+ function s(y) {
701
+ const u = JSON.stringify(y);
702
+ for (i < d.value.length - 1 && (d.value = d.value.slice(0, i + 1)), d.value.push(u), i = d.value.length - 1; d.value.length > n; )
703
+ d.value.shift(), i--;
704
+ }
705
+ function f() {
706
+ return l() ? (i--, JSON.parse(d.value[i])) : null;
707
+ }
708
+ function x() {
709
+ return a() ? (i++, JSON.parse(d.value[i])) : null;
710
+ }
711
+ function m() {
712
+ d.value = [], i = -1;
713
+ }
714
+ return {
715
+ canUndo: l,
716
+ canRedo: a,
717
+ record: s,
718
+ undo: f,
719
+ redo: x,
720
+ reset: m
721
+ };
722
+ }
723
+ const si = ["disabled"], di = ["disabled"], ci = ["disabled"], fi = ["disabled"], vi = ["disabled"], hi = ["disabled"], mi = /* @__PURE__ */ st({
724
+ __name: "NodeContextMenu",
725
+ props: {
726
+ x: {},
727
+ y: {},
728
+ container: {},
729
+ hasImage: { type: Boolean, default: !1 },
730
+ hasLink: { type: Boolean, default: !1 },
731
+ hasNote: { type: Boolean, default: !1 },
732
+ readonly: { type: Boolean, default: !1 }
733
+ },
734
+ emits: ["pickImage", "setLink", "removeLink", "editNote", "removeNote", "removeImage", "close"],
735
+ setup(n, { emit: d }) {
736
+ const i = n, l = d, a = Y(() => {
737
+ let I = i.x + 2, C = i.y + 2;
738
+ if (i.container) {
739
+ const H = i.container.getBoundingClientRect(), _ = 180, ie = s.value ? f.value ? 184 : 160 : 136;
740
+ I + _ > H.right && (I = Math.max(H.left + 4, i.x - _ - 2)), C + ie > H.bottom && (C = Math.max(H.top + 4, i.y - ie - 2)), I < H.left + 2 && (I = H.left + 2), C < H.top + 2 && (C = H.top + 2);
741
+ }
742
+ return { left: I, top: C };
743
+ }), s = Y(() => i.hasImage), f = Y(() => i.hasLink), x = Y(() => i.hasNote);
744
+ function m(I) {
745
+ const C = I.target;
746
+ C && C.closest(".zm-node-menu") || l("close");
747
+ }
748
+ function y(I) {
749
+ I.key === "Escape" && l("close");
750
+ }
751
+ function u() {
752
+ l("close");
753
+ }
754
+ window.addEventListener("mousedown", m, !0), window.addEventListener("keydown", y, !0), window.addEventListener("wheel", u, !0), window.addEventListener("scroll", u, !0), dt(() => {
755
+ window.removeEventListener("mousedown", m, !0), window.removeEventListener("keydown", y, !0), window.removeEventListener("wheel", u, !0), window.removeEventListener("scroll", u, !0);
756
+ });
757
+ function b(I) {
758
+ i.readonly || (I(), l("close"));
759
+ }
760
+ return (I, C) => (w(), k("div", {
761
+ class: "zm-node-menu",
762
+ style: oe({ left: a.value.left + "px", top: a.value.top + "px" }),
763
+ onContextmenu: C[6] || (C[6] = $(() => {
764
+ }, ["prevent"]))
765
+ }, [
766
+ g("button", {
767
+ class: "zm-node-menu-item",
768
+ disabled: n.readonly,
769
+ onClick: C[0] || (C[0] = $((H) => b(() => l("pickImage")), ["stop"]))
770
+ }, [
771
+ P(O, {
772
+ name: "image",
773
+ size: 13
774
+ }),
775
+ g("span", null, ve(s.value ? "替换图片" : "添加图片"), 1)
776
+ ], 8, si),
777
+ s.value ? (w(), k("button", {
778
+ key: 0,
779
+ class: "zm-node-menu-item",
780
+ disabled: n.readonly,
781
+ onClick: C[1] || (C[1] = $((H) => b(() => l("removeImage")), ["stop"]))
782
+ }, [
783
+ P(O, {
784
+ name: "x",
785
+ size: 13
786
+ }),
787
+ C[7] || (C[7] = g("span", null, "移除图片", -1))
788
+ ], 8, di)) : D("", !0),
789
+ g("button", {
790
+ class: "zm-node-menu-item",
791
+ disabled: n.readonly,
792
+ onClick: C[2] || (C[2] = $((H) => b(() => l("setLink")), ["stop"]))
793
+ }, [
794
+ P(O, {
795
+ name: "link",
796
+ size: 13
797
+ }),
798
+ g("span", null, ve(f.value ? "编辑链接" : "添加链接"), 1)
799
+ ], 8, ci),
800
+ f.value ? (w(), k("button", {
801
+ key: 1,
802
+ class: "zm-node-menu-item",
803
+ disabled: n.readonly,
804
+ onClick: C[3] || (C[3] = $((H) => b(() => l("removeLink")), ["stop"]))
805
+ }, [
806
+ P(O, {
807
+ name: "x",
808
+ size: 13
809
+ }),
810
+ C[8] || (C[8] = g("span", null, "移除链接", -1))
811
+ ], 8, fi)) : D("", !0),
812
+ g("button", {
813
+ class: "zm-node-menu-item",
814
+ disabled: n.readonly,
815
+ onClick: C[4] || (C[4] = $((H) => b(() => l("editNote")), ["stop"]))
816
+ }, [
817
+ P(O, {
818
+ name: "note",
819
+ size: 13
820
+ }),
821
+ g("span", null, ve(x.value ? "编辑笔记" : "添加笔记"), 1)
822
+ ], 8, vi),
823
+ x.value ? (w(), k("button", {
824
+ key: 2,
825
+ class: "zm-node-menu-item",
826
+ disabled: n.readonly,
827
+ onClick: C[5] || (C[5] = $((H) => b(() => l("removeNote")), ["stop"]))
828
+ }, [
829
+ P(O, {
830
+ name: "x",
831
+ size: 13
832
+ }),
833
+ C[9] || (C[9] = g("span", null, "移除笔记", -1))
834
+ ], 8, hi)) : D("", !0)
835
+ ], 36));
836
+ }
837
+ }), yi = ["viewBox", "width", "height"], gi = { class: "zm-edges" }, xi = ["d", "fill"], pi = ["data-node-id", "onClick", "onDblclick", "onContextmenu", "onMouseenter", "onMouseleave"], bi = ["src", "width", "height", "alt"], wi = {
838
+ key: 1,
839
+ class: "zm-text"
840
+ }, ki = { class: "zm-text-label" }, Mi = ["href", "title"], Ci = ["title", "onClick"], Si = ["title"], zi = ["title", "onClick"], Ei = ["onClick"], Ni = ["onMousedown"], Ii = ["onClick"], Wi = {
841
+ key: 0,
842
+ class: "zm-toolbar"
843
+ }, $i = ["src"], Bi = ["src"], Ri = { class: "zm-tb-tip" }, we = 24, Ae = 400, fe = 160, Ai = /* @__PURE__ */ st({
844
+ __name: "MindMap",
845
+ props: {
846
+ data: {},
847
+ readonly: { type: Boolean, default: !1 },
848
+ theme: {},
849
+ previewMode: { type: Boolean, default: !1 }
850
+ },
851
+ emits: ["change", "select", "edit-note"],
852
+ setup(n, { expose: d, emit: i }) {
853
+ const l = n, a = i, s = A(null), f = A(null), x = A(""), m = A(null), y = A(/* @__PURE__ */ new Set()), u = A(ke(l.data)), b = Y(() => p.showOrderBadge === !0), I = A(/* @__PURE__ */ new Map()), C = I.value;
854
+ function H(e, t) {
855
+ const r = {};
856
+ t.bg && (r.bg = t.bg), t.textColor && (r.textColor = t.textColor), t.borderColor && (r.borderColor = t.borderColor), t.fontWeight && (r.fontWeight = t.fontWeight), Object.keys(r).length === 0 ? C.delete(e) : C.set(e, r), I.value = new Map(C);
857
+ }
858
+ function _(e) {
859
+ return C.get(e) ?? {};
860
+ }
861
+ function ie(e, t) {
862
+ const r = W(u.value, e);
863
+ r && (r.image = {
864
+ src: t.src,
865
+ naturalW: t.naturalW,
866
+ naturalH: t.naturalH,
867
+ width: le(t.width, we, Ae),
868
+ height: le(t.height, we, Ae)
869
+ }, K(), L(), a("change", u.value));
870
+ }
871
+ function He(e) {
872
+ const t = W(u.value, e);
873
+ !t || !t.image || (delete t.image, K(), L(), a("change", u.value));
874
+ }
875
+ function le(e, t, r) {
876
+ return Math.min(r, Math.max(t, e));
877
+ }
878
+ function Ce(e, t) {
879
+ const r = new FileReader();
880
+ r.onload = () => {
881
+ if (typeof r.result != "string") return;
882
+ const c = r.result, v = new window.Image();
883
+ v.onload = () => {
884
+ const o = v.naturalWidth || fe, h = v.naturalHeight || fe, N = le(o, we, fe), T = le(Math.round(h * N / o), we, Ae);
885
+ t({ src: c, naturalW: o, naturalH: h, width: N, height: T });
886
+ }, v.onerror = () => {
887
+ t({ src: c, naturalW: fe, naturalH: fe, width: fe, height: fe });
888
+ }, v.src = c;
889
+ }, r.readAsDataURL(e);
890
+ }
891
+ function De(e) {
892
+ const t = document.createElement("input");
893
+ t.type = "file", t.accept = "image/*", t.style.display = "none", t.onchange = () => {
894
+ var c;
895
+ const r = (c = t.files) == null ? void 0 : c[0];
896
+ r && (Ce(r, (v) => ie(e, v)), document.body.removeChild(t));
897
+ }, document.body.appendChild(t), t.click();
898
+ }
899
+ function Se(e, t) {
900
+ const r = t.trim(), c = W(u.value, e);
901
+ c && (r ? c.link = { url: r } : delete c.link, K(), L(), a("change", u.value));
902
+ }
903
+ function ze(e) {
904
+ Se(e, "");
905
+ }
906
+ function Ee(e, t) {
907
+ const r = W(u.value, e);
908
+ r && (t ? r.note = { text: t } : delete r.note, K(), L(), a("change", u.value));
909
+ }
910
+ function Ne(e) {
911
+ Ee(e, "");
912
+ }
913
+ const F = A(null);
914
+ function E(e, t) {
915
+ l.readonly || (e.preventDefault(), e.stopPropagation(), m.value = t.id, a("select", W(u.value, t.id)), F.value = { nodeId: t.id, x: e.clientX, y: e.clientY });
916
+ }
917
+ function V() {
918
+ F.value = null;
919
+ }
920
+ function X() {
921
+ var t;
922
+ const e = (t = F.value) == null ? void 0 : t.nodeId;
923
+ e && De(e);
924
+ }
925
+ function U() {
926
+ var c, v, o;
927
+ const e = (c = F.value) == null ? void 0 : c.nodeId;
928
+ if (!e) return;
929
+ const t = ((o = (v = W(u.value, e)) == null ? void 0 : v.link) == null ? void 0 : o.url) ?? "", r = window.prompt("输入链接 URL(留空取消)", t);
930
+ r !== null && Se(e, r);
931
+ }
932
+ function Z() {
933
+ var t;
934
+ const e = (t = F.value) == null ? void 0 : t.nodeId;
935
+ e && ze(e);
936
+ }
937
+ function Q() {
938
+ var t;
939
+ const e = (t = F.value) == null ? void 0 : t.nodeId;
940
+ e && re(e);
941
+ }
942
+ function he() {
943
+ var t;
944
+ const e = (t = F.value) == null ? void 0 : t.nodeId;
945
+ e && Ne(e);
946
+ }
947
+ function Ie() {
948
+ var t;
949
+ const e = (t = F.value) == null ? void 0 : t.nodeId;
950
+ e && He(e);
951
+ }
952
+ function re(e) {
953
+ l.readonly || a("edit-note", e);
954
+ }
955
+ function Gt(e, t = 60) {
956
+ const r = e.replace(/\s+/g, " ").trim();
957
+ return r.length <= t ? r || "点击编辑笔记" : r.slice(0, t) + "…";
958
+ }
959
+ function ct(e) {
960
+ var v;
961
+ if (l.readonly || f.value) return;
962
+ const t = e.target;
963
+ if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable))
964
+ return;
965
+ const r = m.value;
966
+ if (!r) return;
967
+ const c = (v = e.clipboardData) == null ? void 0 : v.items;
968
+ if (c)
969
+ for (let o = 0; o < c.length; o++) {
970
+ const h = c[o];
971
+ if (h.kind === "file" && h.type.startsWith("image/")) {
972
+ const N = h.getAsFile();
973
+ if (!N) continue;
974
+ e.preventDefault();
975
+ const T = W(u.value, r);
976
+ if (T != null && T.image && !window.confirm("该节点已有图片,要用剪贴板里的图片替换吗?"))
977
+ return;
978
+ Ce(N, (q) => ie(r, q));
979
+ return;
980
+ }
981
+ }
982
+ }
983
+ ut(() => {
984
+ window.addEventListener("paste", ct);
985
+ }), dt(() => {
986
+ window.removeEventListener("paste", ct);
987
+ });
988
+ const We = A(null), jt = Y(() => {
989
+ var e;
990
+ return ((e = We.value) == null ? void 0 : e.nodeId) ?? null;
991
+ });
992
+ function Jt(e, t) {
993
+ if (!t.image) return;
994
+ e.preventDefault(), e.stopPropagation();
995
+ const r = t.image.naturalW || t.image.width, c = t.image.naturalH || t.image.height, v = c > 0 ? c / r : 1;
996
+ We.value = {
997
+ nodeId: t.id,
998
+ startX: e.clientX,
999
+ startY: e.clientY,
1000
+ startW: t.image.width,
1001
+ startH: t.image.height,
1002
+ naturalW: r,
1003
+ naturalH: c,
1004
+ ratio: v,
1005
+ pendingW: t.image.width,
1006
+ pendingH: t.image.height
1007
+ }, window.addEventListener("mousemove", ft), window.addEventListener("mouseup", vt);
1008
+ }
1009
+ function ft(e) {
1010
+ var T, q;
1011
+ const t = We.value;
1012
+ if (!t) return;
1013
+ const r = M.scale.value || 1, c = e.clientX - t.startX, v = le(t.startW + c / r, we, Ae), o = le(v * t.ratio, we, Ae);
1014
+ t.pendingW = v, t.pendingH = o;
1015
+ const h = (T = s.value) == null ? void 0 : T.querySelector(
1016
+ `[data-node-id="${t.nodeId}"] .zm-node-img`
1017
+ );
1018
+ h && (h.style.width = `${v}px`, h.style.height = `${o}px`);
1019
+ const N = (q = s.value) == null ? void 0 : q.querySelector(
1020
+ `[data-node-id="${t.nodeId}"]`
1021
+ );
1022
+ N && (N.style.minWidth = `${Math.max(80, Math.ceil(v + 28))}px`, N.style.height = `${Math.ceil(o + 8 + 30)}px`);
1023
+ }
1024
+ function vt() {
1025
+ const e = We.value;
1026
+ if (window.removeEventListener("mousemove", ft), window.removeEventListener("mouseup", vt), We.value = null, !e) return;
1027
+ const t = W(u.value, e.nodeId);
1028
+ !t || !t.image || (ie(e.nodeId, {
1029
+ src: t.image.src,
1030
+ naturalW: t.image.naturalW,
1031
+ naturalH: t.image.naturalH,
1032
+ width: e.pendingW,
1033
+ height: e.pendingH
1034
+ }), m.value = e.nodeId, a("select", t), _e = !0);
1035
+ }
1036
+ const Qe = A(null);
1037
+ let _e = !1;
1038
+ function Zt(e) {
1039
+ Qe.value = e;
1040
+ }
1041
+ function Qt(e) {
1042
+ Qe.value === e && (Qe.value = null);
1043
+ }
1044
+ const ht = A(0), et = A(!1), ae = ui(100);
1045
+ function K() {
1046
+ ae.record({ data: u.value });
1047
+ }
1048
+ function L() {
1049
+ y.value = new Set(y.value), ht.value++;
1050
+ }
1051
+ const ee = Y(() => {
1052
+ var e, t, r, c, v, o, h, N, T, q;
1053
+ return {
1054
+ rootBg: ((e = l.theme) == null ? void 0 : e.rootBg) ?? "#1f2937",
1055
+ rootText: ((t = l.theme) == null ? void 0 : t.rootText) ?? "#ffffff",
1056
+ branchBg: ((r = l.theme) == null ? void 0 : r.branchBg) ?? "#ffffff",
1057
+ branchText: ((c = l.theme) == null ? void 0 : c.branchText) ?? "#1f2937",
1058
+ lineColor: ((v = l.theme) == null ? void 0 : v.lineColor) ?? "#94a3b8",
1059
+ bgColor: ((o = l.theme) == null ? void 0 : o.bgColor) ?? "#f8fafc",
1060
+ fontSize: ((h = l.theme) == null ? void 0 : h.fontSize) ?? 14,
1061
+ lineWidthStart: ((N = l.theme) == null ? void 0 : N.lineWidthStart) ?? 2.2,
1062
+ lineWidthEnd: ((T = l.theme) == null ? void 0 : T.lineWidthEnd) ?? 0.8,
1063
+ rainbowBranch: ((q = l.theme) == null ? void 0 : q.rainbowBranch) ?? !1
1064
+ };
1065
+ }), p = Ue({
1066
+ autoBalanceOnChange: !0,
1067
+ lineWidthStart: 12,
1068
+ lineWidthEnd: 3.6,
1069
+ rainbowBranch: !0,
1070
+ branchPaletteId: "default",
1071
+ customPalettes: [],
1072
+ lineStyle: "curve",
1073
+ layoutMode: "mindmap",
1074
+ taperedEdge: !0,
1075
+ showOrderBadge: !1
1076
+ });
1077
+ function mt(e) {
1078
+ return p.taperedEdge ? _t(e) : gt(e);
1079
+ }
1080
+ function yt(e) {
1081
+ return p.taperedEdge ? p.lineWidthEnd : gt(e);
1082
+ }
1083
+ function _t(e) {
1084
+ return e <= 0 ? p.lineWidthStart : e === 1 ? Math.max(1.5, p.lineWidthStart * 0.67) : e === 2 ? Math.max(0.8, p.lineWidthStart * 0.42) : p.lineWidthEnd;
1085
+ }
1086
+ function gt(e) {
1087
+ if (e <= 0) return p.lineWidthStart;
1088
+ if (e >= 3) return p.lineWidthEnd;
1089
+ const t = e / 3;
1090
+ return p.lineWidthStart + (p.lineWidthEnd - p.lineWidthStart) * t;
1091
+ }
1092
+ function en(e, t, r, c) {
1093
+ const v = 1 - e, o = v * v * v * t.x + 3 * v * v * e * r.x1 + 3 * v * e * e * r.x2 + e * e * e * c.x, h = v * v * v * t.y + 3 * v * v * e * r.y1 + 3 * v * e * e * r.y2 + e * e * e * c.y;
1094
+ return { x: o, y: h };
1095
+ }
1096
+ function tn(e, t, r, c, v = 32, o = "curve", h = "right") {
1097
+ if (o === "curve") {
1098
+ let ce;
1099
+ if (h === "right" || h === "left") {
1100
+ const B = Math.abs(t.x - e.x) * 0.45, ne = h === "right" ? 1 : -1;
1101
+ ce = { x1: e.x + ne * B, y1: e.y, x2: t.x - ne * B, y2: t.y };
1102
+ } else {
1103
+ const B = Math.abs(t.y - e.y) * 0.45;
1104
+ ce = { x1: e.x, y1: e.y + B, x2: t.x, y2: t.y - B };
1105
+ }
1106
+ const Sn = (z) => {
1107
+ const B = 1 - z, ne = -3 * B * B * e.x + 3 * (B * B - 2 * B * z) * ce.x1 + 3 * (2 * B * z - z * z) * ce.x2 + 3 * z * z * t.x, xe = -3 * B * B * e.y + 3 * (B * B - 2 * B * z) * ce.y1 + 3 * (2 * B * z - z * z) * ce.y2 + 3 * z * z * t.y;
1108
+ return { dx: ne, dy: xe };
1109
+ }, Re = [], rt = [];
1110
+ for (let z = 0; z <= v; z++) {
1111
+ const B = z / v, ne = z === 0 ? e : z === v ? t : en(B, e, ce, t), xe = Sn(B);
1112
+ let Ve = Math.hypot(xe.dx, xe.dy);
1113
+ Ve < 1e-6 && (Ve = 1);
1114
+ const Lt = -xe.dy / Ve, Ht = xe.dx / Ve, Xe = (r + (c - r) * B) / 2;
1115
+ Re.push({ x: ne.x + Lt * Xe, y: ne.y + Ht * Xe }), rt.push({ x: ne.x - Lt * Xe, y: ne.y - Ht * Xe });
1116
+ }
1117
+ let Fe = `M ${Re[0].x.toFixed(2)} ${Re[0].y.toFixed(2)}`;
1118
+ for (let z = 1; z <= v; z++) Fe += ` L ${Re[z].x.toFixed(2)} ${Re[z].y.toFixed(2)}`;
1119
+ for (let z = v; z >= 0; z--) Fe += ` L ${rt[z].x.toFixed(2)} ${rt[z].y.toFixed(2)}`;
1120
+ return Fe += " Z", Fe;
1121
+ }
1122
+ const N = t.x - e.x, T = t.y - e.y;
1123
+ let q = Math.hypot(N, T);
1124
+ q < 1e-6 && (q = 1);
1125
+ const de = -T / q, ye = N / q, ge = r / 2, Be = c / 2, $t = { x: e.x + de * ge, y: e.y + ye * ge }, Bt = { x: e.x - de * ge, y: e.y - ye * ge }, Rt = { x: t.x - de * Be, y: t.y - ye * Be }, At = { x: t.x + de * Be, y: t.y + ye * Be };
1126
+ return `M ${$t.x.toFixed(2)} ${$t.y.toFixed(2)} L ${At.x.toFixed(2)} ${At.y.toFixed(2)} L ${Rt.x.toFixed(2)} ${Rt.y.toFixed(2)} L ${Bt.x.toFixed(2)} ${Bt.y.toFixed(2)} Z`;
1127
+ }
1128
+ const Pe = Y(() => G.value.root.children), nn = Le[0].colors, xt = Y(
1129
+ () => Qn(p.branchPaletteId, p.customPalettes)
1130
+ ), ue = Y(() => {
1131
+ const e = /* @__PURE__ */ new Map();
1132
+ if (!p.rainbowBranch) return e;
1133
+ const t = xt.value.colors.length > 0 ? xt.value.colors : nn;
1134
+ for (let c = 0; c < Pe.value.length; c++) {
1135
+ const v = Pe.value[c];
1136
+ e.set(v.id, t[c % t.length]);
1137
+ }
1138
+ const r = (c, v) => {
1139
+ e.set(c.id, v);
1140
+ for (const o of c.children) r(o, v);
1141
+ };
1142
+ for (let c = 0; c < Pe.value.length; c++) {
1143
+ const v = Pe.value[c];
1144
+ r(v, t[c % t.length]);
1145
+ }
1146
+ return e;
1147
+ });
1148
+ function ln(e, t) {
1149
+ return p.rainbowBranch ? ue.value.get(t.id) ?? ee.value.lineColor : ee.value.lineColor;
1150
+ }
1151
+ function on(e) {
1152
+ const t = _(e.id);
1153
+ if (t.bg) return t.bg;
1154
+ if (e.isRoot) return ee.value.rootBg;
1155
+ if (p.rainbowBranch) {
1156
+ const r = ue.value.get(e.id);
1157
+ if (r) return sn(r, 0.18);
1158
+ }
1159
+ return ee.value.branchBg;
1160
+ }
1161
+ function rn(e) {
1162
+ const t = _(e.id);
1163
+ if (t.textColor) return t.textColor;
1164
+ if (e.isRoot) return ee.value.rootText;
1165
+ if (p.rainbowBranch) {
1166
+ const r = ue.value.get(e.id);
1167
+ if (r) return pt(r, 0.55);
1168
+ }
1169
+ return ee.value.branchText;
1170
+ }
1171
+ function an(e) {
1172
+ const t = _(e.id);
1173
+ if (t.borderColor) return t.borderColor;
1174
+ if (e.isRoot) return ee.value.rootBg;
1175
+ if (p.rainbowBranch) {
1176
+ const r = ue.value.get(e.id);
1177
+ if (r) return pt(r, 0.3);
1178
+ }
1179
+ return ee.value.lineColor;
1180
+ }
1181
+ function un(e) {
1182
+ return _(e.id).fontWeight ?? (e.isRoot ? 600 : 400);
1183
+ }
1184
+ function sn(e, t) {
1185
+ const r = e.replace("#", ""), c = r.length === 6 ? r : r.split("").map((N) => N + N).join(""), v = parseInt(c.slice(0, 2), 16), o = parseInt(c.slice(2, 4), 16), h = parseInt(c.slice(4, 6), 16);
1186
+ return `rgba(${v}, ${o}, ${h}, ${t})`;
1187
+ }
1188
+ function pt(e, t) {
1189
+ const r = e.replace("#", ""), c = r.length === 6 ? r : r.split("").map((N) => N + N).join(""), v = Math.round(parseInt(c.slice(0, 2), 16) * (1 - t)), o = Math.round(parseInt(c.slice(2, 4), 16) * (1 - t)), h = Math.round(parseInt(c.slice(4, 6), 16) * (1 - t));
1190
+ return `rgb(${v}, ${o}, ${h})`;
1191
+ }
1192
+ const M = oi({ getContainer: () => s.value });
1193
+ M.setOnMarqueeEnd(bn), ai({
1194
+ isEditing: () => f.value !== null,
1195
+ isReadonly: () => l.readonly,
1196
+ getSelectedId: () => m.value,
1197
+ getRootId: () => u.value.id,
1198
+ // If nothing is selected, default Tab/Enter to the root so the user
1199
+ // can build a tree from scratch without first clicking somewhere.
1200
+ defaultTargetId: () => u.value.id,
1201
+ onAddChild: me,
1202
+ onAddSibling: Te,
1203
+ onAddSiblingBefore: kt,
1204
+ onRemove: Ct,
1205
+ onStartEdit: $e,
1206
+ onClearSelection: () => {
1207
+ m.value = null, a("select", null);
1208
+ },
1209
+ onDuplicate: Mt,
1210
+ onUndo: nt,
1211
+ onRedo: it,
1212
+ onNavigate: hn,
1213
+ onSelectRoot: () => {
1214
+ m.value = u.value.id;
1215
+ const e = W(u.value, u.value.id);
1216
+ e && a("select", e);
1217
+ }
1218
+ });
1219
+ const G = Y(() => {
1220
+ const e = ke(u.value);
1221
+ return wt(e), Gn(e, { mode: p.layoutMode });
1222
+ }), bt = A([]), tt = Y(() => (ht.value, bt.value));
1223
+ Dt(
1224
+ G,
1225
+ (e) => {
1226
+ const t = [], r = (c) => {
1227
+ t.push(c);
1228
+ for (const v of c.children) r(v);
1229
+ };
1230
+ r(e.root), bt.value = t;
1231
+ },
1232
+ { immediate: !0 }
1233
+ );
1234
+ const dn = Y(() => {
1235
+ const e = [];
1236
+ for (const t of tt.value)
1237
+ for (const r of t.children)
1238
+ e.push({ from: t, to: r, key: `${t.id}->${r.id}` });
1239
+ return e;
1240
+ }), cn = Y(
1241
+ () => `${G.value.vbX} ${G.value.vbY} ${G.value.vbW} ${G.value.vbH}`
1242
+ );
1243
+ function wt(e) {
1244
+ if (y.value.has(e.id)) {
1245
+ e.children = [], e.collapsed = !0;
1246
+ return;
1247
+ }
1248
+ e.collapsed = !1;
1249
+ for (const t of e.children) wt(t);
1250
+ }
1251
+ function $e(e) {
1252
+ const t = W(u.value, e);
1253
+ t && (f.value = e, x.value = t.text, j(() => {
1254
+ const r = document.querySelector(".zm-input");
1255
+ r == null || r.focus(), r == null || r.select();
1256
+ }));
1257
+ }
1258
+ function Oe(e = {}) {
1259
+ if (!f.value) return;
1260
+ const t = W(u.value, f.value);
1261
+ t && t.text !== (x.value.trim() || " ") && (t.text = x.value.trim() || " ", K(), a("change", u.value));
1262
+ const r = f.value;
1263
+ f.value = null, e.addChild ? j(() => me(r)) : e.addSibling === "after" ? j(() => Te(r)) : e.addSibling === "before" && j(() => kt(r));
1264
+ }
1265
+ function fn() {
1266
+ f.value = null;
1267
+ }
1268
+ function vn(e) {
1269
+ const t = e.metaKey || e.ctrlKey;
1270
+ t && (e.key === "z" || e.key === "Z") && !e.shiftKey ? (e.preventDefault(), nt()) : (t && e.shiftKey && (e.key === "z" || e.key === "Z") || t && (e.key === "y" || e.key === "Y") && !e.shiftKey) && (e.preventDefault(), it());
1271
+ }
1272
+ function me(e) {
1273
+ const t = ti(u.value, e, Ge);
1274
+ t && (K(), L(), a("change", u.value), j(() => $e(t.id)));
1275
+ }
1276
+ function Te(e) {
1277
+ if (e === u.value.id) {
1278
+ me(e);
1279
+ return;
1280
+ }
1281
+ const t = ni(u.value, e, Ge);
1282
+ t && (K(), L(), a("change", u.value), j(() => $e(t.id)));
1283
+ }
1284
+ function kt(e) {
1285
+ if (e === u.value.id) {
1286
+ me(e);
1287
+ return;
1288
+ }
1289
+ const t = ii(u.value, e, Ge);
1290
+ t && (K(), L(), a("change", u.value), j(() => $e(t.id)));
1291
+ }
1292
+ function Mt(e) {
1293
+ if (e === u.value.id) return;
1294
+ const t = li(u.value, e);
1295
+ t && (K(), m.value = t.id, a("change", u.value), L());
1296
+ }
1297
+ function nt() {
1298
+ const e = ae.undo();
1299
+ e && (u.value = e.data, m.value = null, a("select", null), L(), a("change", u.value));
1300
+ }
1301
+ function it() {
1302
+ const e = ae.redo();
1303
+ e && (u.value = e.data, m.value = null, a("select", null), L(), a("change", u.value));
1304
+ }
1305
+ function hn(e, t) {
1306
+ const r = m.value ?? u.value.id, c = W(u.value, r);
1307
+ if (!c) return;
1308
+ let v = null;
1309
+ if (t === 1) {
1310
+ const o = te(u.value, c.id);
1311
+ if (o) {
1312
+ const h = o.children.findIndex((N) => N.id === c.id);
1313
+ h >= 0 && h < o.children.length - 1 && (v = o.children[h + 1].id);
1314
+ }
1315
+ } else if (t === -1) {
1316
+ const o = te(u.value, c.id);
1317
+ if (o) {
1318
+ const h = o.children.findIndex((N) => N.id === c.id);
1319
+ h > 0 && (v = o.children[h - 1].id);
1320
+ }
1321
+ } else if (e === 1) {
1322
+ const o = te(u.value, c.id);
1323
+ o && (v = o.id);
1324
+ } else e === -1 && c.children.length > 0 && (v = c.children[0].id);
1325
+ if (v) {
1326
+ m.value = v;
1327
+ const o = W(u.value, v);
1328
+ o && a("select", o);
1329
+ }
1330
+ }
1331
+ function Ct(e) {
1332
+ e !== u.value.id && Yt(u.value, e) && (K(), m.value === e && (m.value = null), L(), a("change", u.value));
1333
+ }
1334
+ function St(e) {
1335
+ y.value.has(e) ? y.value.delete(e) : y.value.add(e), L();
1336
+ }
1337
+ function mn(e, t) {
1338
+ _n(u.value, e, t) && (K(), L(), a("change", u.value));
1339
+ }
1340
+ function yn(e, t, r) {
1341
+ return ei(u.value, e, t, r) ? (K(), L(), a("change", u.value), !0) : !1;
1342
+ }
1343
+ function gn(e, t) {
1344
+ e.stopPropagation(), m.value = t.id;
1345
+ const r = W(u.value, t.id);
1346
+ a("select", r);
1347
+ }
1348
+ function xn(e) {
1349
+ const t = e.target;
1350
+ if (!t || t.closest(".zm-node, .zm-toolbar, button, input, textarea")) return;
1351
+ if (e.button === 2) {
1352
+ M.startPan(e);
1353
+ return;
1354
+ }
1355
+ if (e.button !== 0) return;
1356
+ const r = s.value.getBoundingClientRect(), c = (e.clientX - r.left - M.offsetX.value) / M.scale.value, v = (e.clientY - r.top - M.offsetY.value) / M.scale.value;
1357
+ M.startMarquee(c, v);
1358
+ }
1359
+ function pn(e) {
1360
+ if (_e) {
1361
+ _e = !1;
1362
+ return;
1363
+ }
1364
+ const t = e.target;
1365
+ if (!t || t.closest(".zm-node")) return;
1366
+ const r = M.marquee;
1367
+ r.width >= 4 || r.height >= 4 || m.value !== null && (m.value = null, a("select", null));
1368
+ }
1369
+ function bn() {
1370
+ const e = M.marquee;
1371
+ if (e.width < 4 && e.height < 4)
1372
+ return;
1373
+ const t = e.x, r = e.y, c = e.x + e.width, v = e.y + e.height, o = [];
1374
+ for (const h of tt.value) {
1375
+ const N = h.width / 2, T = h.height / 2, q = h.x - N, de = h.x + N, ye = h.y - T, ge = h.y + T;
1376
+ q <= c && de >= t && ye <= v && ge >= r && o.push(h.id);
1377
+ }
1378
+ if (o.length > 0) {
1379
+ m.value = o[0];
1380
+ const h = W(u.value, o[0]);
1381
+ h && a("select", h);
1382
+ }
1383
+ }
1384
+ function zt(e) {
1385
+ return y.value.has(e);
1386
+ }
1387
+ function wn(e) {
1388
+ const t = W(u.value, e.id);
1389
+ return !!t && t.children.length > 0;
1390
+ }
1391
+ function lt(e) {
1392
+ const t = W(u.value, e);
1393
+ return t ? t.children.length : 0;
1394
+ }
1395
+ function Et(e) {
1396
+ if (!W(u.value, e)) return 0;
1397
+ const c = [u.value];
1398
+ for (; c.length; ) {
1399
+ const v = c.pop(), o = v.children.findIndex((h) => h.id === e);
1400
+ if (o >= 0) return o;
1401
+ for (const h of v.children) c.push(h);
1402
+ }
1403
+ return 0;
1404
+ }
1405
+ function Nt(e, t, r, c) {
1406
+ if (((c == null ? void 0 : c._dir) ?? e._dir) === "down")
1407
+ return t === "out" ? { x: e.x, y: e.y + e.height / 2 } : { x: e.x, y: e.y - e.height / 2 };
1408
+ let o;
1409
+ return t === "in" ? o = -e.side : r !== void 0 ? o = r : o = e.side, { x: e.x + o * (e.width / 2), y: e.y };
1410
+ }
1411
+ function se() {
1412
+ const e = G.value;
1413
+ M.resetView(e.width, e.height, e.root.y);
1414
+ }
1415
+ function kn() {
1416
+ et.value = !0, K(), L(), j(() => se());
1417
+ }
1418
+ function ot(e) {
1419
+ p.layoutMode !== e && (p.layoutMode = e, L(), j(() => se()));
1420
+ }
1421
+ function It() {
1422
+ return JSON.stringify(u.value, null, 2);
1423
+ }
1424
+ function Wt(e) {
1425
+ try {
1426
+ const t = JSON.parse(e);
1427
+ return !t.id || !Array.isArray(t.children) ? !1 : (ae.reset(), u.value = ke(t), m.value = null, y.value = /* @__PURE__ */ new Set(), L(), j(() => se()), a("change", u.value), !0);
1428
+ } catch {
1429
+ return !1;
1430
+ }
1431
+ }
1432
+ function Mn() {
1433
+ const e = document.createElement("input");
1434
+ e.type = "file", e.accept = "application/json", e.onchange = () => {
1435
+ var c;
1436
+ const t = (c = e.files) == null ? void 0 : c[0];
1437
+ if (!t) return;
1438
+ const r = new FileReader();
1439
+ r.onload = () => {
1440
+ typeof r.result == "string" && (Wt(r.result) || alert("导入失败:JSON 格式无效"));
1441
+ }, r.readAsText(t);
1442
+ }, e.click();
1443
+ }
1444
+ function Cn() {
1445
+ const e = new Blob([It()], { type: "application/json" }), t = URL.createObjectURL(e), r = document.createElement("a");
1446
+ r.href = t, r.download = `${u.value.text || "mindmap"}.json`, r.click(), URL.revokeObjectURL(t);
1447
+ }
1448
+ return d({
1449
+ addChild: (e) => me(e),
1450
+ addSibling: (e) => Te(e),
1451
+ removeNode: (e) => Ct(e),
1452
+ duplicateNode: (e) => Mt(e),
1453
+ setNodeText: (e, t) => mn(e, t),
1454
+ moveNode: (e, t, r) => yn(e, t, r),
1455
+ lineWidthForDepth: mt,
1456
+ endWidthForDepth: yt,
1457
+ getData: () => u.value,
1458
+ setData: (e) => {
1459
+ ae.reset(), u.value = ke(e), m.value = null, y.value = /* @__PURE__ */ new Set(), L(), j(() => se());
1460
+ },
1461
+ resetView: () => se(),
1462
+ exportData: It,
1463
+ importData: Wt,
1464
+ // Make balanced the active layout (sticky). Subsequent data changes
1465
+ // and additions stay in balanced mode. Pass `false` to revert to the
1466
+ // default compact layout.
1467
+ setBalanced: (e) => {
1468
+ et.value = e;
1469
+ },
1470
+ isBalanced: () => et.value,
1471
+ // Re-balance now: clear all manual drag offsets, re-run the balanced
1472
+ // layout, and re-center the view. This is the action tied to the
1473
+ // "balance" toolbar button.
1474
+ balance: () => kn(),
1475
+ applyNodeStyle: (e, t) => H(e, t),
1476
+ getNodeStyle: (e) => _(e),
1477
+ applyNodeLink: (e, t) => Se(e, t),
1478
+ removeNodeLink: (e) => ze(e),
1479
+ applyNodeNote: (e, t) => Ee(e, t),
1480
+ removeNodeNote: (e) => Ne(e),
1481
+ undo: () => nt(),
1482
+ redo: () => it(),
1483
+ canUndo: () => ae.canUndo(),
1484
+ canRedo: () => ae.canRedo(),
1485
+ // Settings panel / external mutation hooks
1486
+ applySettings: (e) => {
1487
+ e.autoBalanceOnChange !== void 0 && (p.autoBalanceOnChange = e.autoBalanceOnChange), e.lineWidthStart !== void 0 && (p.lineWidthStart = Math.max(0.5, Math.min(20, e.lineWidthStart))), e.lineWidthEnd !== void 0 && (p.lineWidthEnd = Math.max(0.3, Math.min(10, e.lineWidthEnd))), e.rainbowBranch !== void 0 && (p.rainbowBranch = e.rainbowBranch), e.branchPaletteId !== void 0 && (p.branchPaletteId = e.branchPaletteId), e.customPalettes !== void 0 && (p.customPalettes = e.customPalettes), e.lineStyle !== void 0 && (p.lineStyle = e.lineStyle), e.taperedEdge !== void 0 && (p.taperedEdge = e.taperedEdge), e.showOrderBadge !== void 0 && (p.showOrderBadge = e.showOrderBadge);
1488
+ },
1489
+ getSettings: () => ({
1490
+ autoBalanceOnChange: p.autoBalanceOnChange,
1491
+ lineWidthStart: p.lineWidthStart,
1492
+ lineWidthEnd: p.lineWidthEnd,
1493
+ rainbowBranch: p.rainbowBranch,
1494
+ branchPaletteId: p.branchPaletteId,
1495
+ customPalettes: p.customPalettes,
1496
+ lineStyle: p.lineStyle,
1497
+ layoutMode: p.layoutMode,
1498
+ taperedEdge: p.taperedEdge,
1499
+ showOrderBadge: p.showOrderBadge
1500
+ }),
1501
+ setBranchPalette: (e) => {
1502
+ if (!e) return;
1503
+ [...Le, ...p.customPalettes].find((r) => r.id === e) && (p.branchPaletteId = e);
1504
+ },
1505
+ getBranchPalette: () => p.branchPaletteId,
1506
+ getBranchPalettes: () => [...Le, ...p.customPalettes]
1507
+ }), Dt(
1508
+ () => l.data,
1509
+ (e) => {
1510
+ u.value = ke(e), L();
1511
+ },
1512
+ { deep: !1 }
1513
+ ), ut(() => {
1514
+ j(() => se());
1515
+ }), (e, t) => {
1516
+ var r, c, v;
1517
+ return w(), k("div", {
1518
+ class: "zm-mindmap",
1519
+ style: oe({ background: ee.value.bgColor, fontSize: ee.value.fontSize + "px" })
1520
+ }, [
1521
+ g("div", {
1522
+ ref_key: "wrapperRef",
1523
+ ref: s,
1524
+ class: "zm-canvas",
1525
+ onMousedown: xn,
1526
+ onContextmenu: t[13] || (t[13] = $(() => {
1527
+ }, ["prevent"])),
1528
+ onWheel: t[14] || (t[14] = //@ts-ignore
1529
+ (...o) => S(M).onWheel && S(M).onWheel(...o)),
1530
+ onClick: pn
1531
+ }, [
1532
+ g("div", {
1533
+ class: "zm-svg-layer",
1534
+ style: oe({
1535
+ left: G.value.vbX * S(M).scale.value + S(M).offsetX.value + "px",
1536
+ top: G.value.vbY * S(M).scale.value + S(M).offsetY.value + "px",
1537
+ width: G.value.vbW * S(M).scale.value + "px",
1538
+ height: G.value.vbH * S(M).scale.value + "px"
1539
+ })
1540
+ }, [
1541
+ (w(), k("svg", {
1542
+ class: "zm-svg",
1543
+ viewBox: cn.value,
1544
+ preserveAspectRatio: "xMinYMin meet",
1545
+ width: G.value.vbW * S(M).scale.value,
1546
+ height: G.value.vbH * S(M).scale.value
1547
+ }, [
1548
+ g("g", gi, [
1549
+ (w(!0), k(R, null, Pt(dn.value, (o) => (w(), k("path", {
1550
+ key: o.key,
1551
+ d: tn(Nt(o.from, "out", o.to.side, o.to), Nt(o.to, "in"), mt(o.from.depth), yt(o.to.depth), 32, p.lineStyle, o.to._dir),
1552
+ fill: ln(o.from, o.to),
1553
+ stroke: "none"
1554
+ }, null, 8, xi))), 128))
1555
+ ])
1556
+ ], 8, yi))
1557
+ ], 4),
1558
+ S(M).isMarquee.value ? (w(), k("div", {
1559
+ key: 0,
1560
+ class: "zm-marquee",
1561
+ style: oe({
1562
+ left: S(M).marquee.x * S(M).scale.value + S(M).offsetX.value + "px",
1563
+ top: S(M).marquee.y * S(M).scale.value + S(M).offsetY.value + "px",
1564
+ width: S(M).marquee.width * S(M).scale.value + "px",
1565
+ height: S(M).marquee.height * S(M).scale.value + "px"
1566
+ })
1567
+ }, null, 4)) : D("", !0),
1568
+ g("div", {
1569
+ class: "zm-world",
1570
+ style: oe({
1571
+ transform: `translate(${S(M).offsetX.value}px, ${S(M).offsetY.value}px) scale(${S(M).scale.value})`
1572
+ })
1573
+ }, [
1574
+ (w(!0), k(R, null, Pt(tt.value, (o) => (w(), k("div", {
1575
+ key: o.id,
1576
+ class: be(["zm-node", {
1577
+ "is-root": o.isRoot,
1578
+ "is-selected": m.value === o.id,
1579
+ "is-editing": f.value === o.id,
1580
+ "has-image": !!o.image,
1581
+ "is-resizing": jt.value === o.id
1582
+ }]),
1583
+ "data-node-id": o.id,
1584
+ style: oe({
1585
+ left: o.x + "px",
1586
+ top: o.y + "px",
1587
+ minWidth: o.width + "px",
1588
+ height: o.height + "px",
1589
+ fontSize: o.fontSize + "px",
1590
+ background: on(o),
1591
+ color: rn(o),
1592
+ borderColor: an(o),
1593
+ fontWeight: un(o),
1594
+ // Center the box on (x, y) with translate(-50%, -50%)
1595
+ transform: "translate(-50%, -50%)"
1596
+ }),
1597
+ onClick: (h) => gn(h, o),
1598
+ onDblclick: (h) => {
1599
+ h.stopPropagation(), n.readonly || $e(o.id);
1600
+ },
1601
+ onContextmenu: (h) => E(h, o),
1602
+ onMouseenter: (h) => Zt(o.id),
1603
+ onMouseleave: (h) => Qt(o.id)
1604
+ }, [
1605
+ o.image ? (w(), k("img", {
1606
+ key: 0,
1607
+ class: "zm-node-img",
1608
+ src: o.image.src,
1609
+ width: o.image.width,
1610
+ height: o.image.height,
1611
+ alt: o.text,
1612
+ draggable: "false"
1613
+ }, null, 8, bi)) : D("", !0),
1614
+ f.value !== o.id ? (w(), k("span", wi, [
1615
+ g("span", ki, ve(o.text), 1),
1616
+ o.link && !f.value ? (w(), k("a", {
1617
+ key: 0,
1618
+ class: "zm-node-link",
1619
+ href: o.link.url,
1620
+ target: "_blank",
1621
+ rel: "noopener noreferrer",
1622
+ title: `打开链接:${o.link.url}`,
1623
+ onClick: t[0] || (t[0] = $(() => {
1624
+ }, ["stop"])),
1625
+ onMousedown: t[1] || (t[1] = $(() => {
1626
+ }, ["stop"]))
1627
+ }, [
1628
+ P(O, {
1629
+ name: "link",
1630
+ size: 11,
1631
+ stroke: 2
1632
+ })
1633
+ ], 40, Mi)) : D("", !0),
1634
+ o.note && !f.value ? (w(), k("button", {
1635
+ key: 1,
1636
+ class: "zm-node-note-btn",
1637
+ type: "button",
1638
+ title: Gt(o.note.text),
1639
+ onClick: $((h) => re(o.id), ["stop"]),
1640
+ onMousedown: t[2] || (t[2] = $(() => {
1641
+ }, ["stop"]))
1642
+ }, [
1643
+ P(O, {
1644
+ name: "note",
1645
+ size: 11,
1646
+ stroke: 2
1647
+ })
1648
+ ], 40, Ci)) : D("", !0)
1649
+ ])) : zn((w(), k("input", {
1650
+ key: 2,
1651
+ class: "zm-input",
1652
+ "onUpdate:modelValue": t[3] || (t[3] = (h) => x.value = h),
1653
+ autofocus: "",
1654
+ onBlur: t[4] || (t[4] = (h) => Oe()),
1655
+ onKeydown: [
1656
+ t[5] || (t[5] = qe($((h) => Oe({ addSibling: "after" }), ["exact"]), ["enter"])),
1657
+ t[6] || (t[6] = qe($((h) => Oe({ addSibling: "before" }), ["shift", "prevent", "exact"]), ["enter"])),
1658
+ t[7] || (t[7] = qe($((h) => Oe({ addChild: !0 }), ["prevent"]), ["tab"])),
1659
+ qe(fn, ["esc"]),
1660
+ vn
1661
+ ],
1662
+ onMousedown: t[8] || (t[8] = $(() => {
1663
+ }, ["stop"])),
1664
+ onClick: t[9] || (t[9] = $(() => {
1665
+ }, ["stop"]))
1666
+ }, null, 544)), [
1667
+ [En, x.value]
1668
+ ]),
1669
+ b.value ? (w(), k("span", {
1670
+ key: 3,
1671
+ class: "zm-order-badge",
1672
+ title: `数据顺序:第 ${Et(o.id) + 1} 个`
1673
+ }, ve(Et(o.id) + 1), 9, Si)) : D("", !0),
1674
+ zt(o.id) && !o.isRoot && lt(o.id) > 0 ? (w(), k("span", {
1675
+ key: 4,
1676
+ class: be(["zm-collapse-badge", { "is-on-left": o.side === -1 }]),
1677
+ style: oe({ background: ue.value.get(o.id) ?? "#64748b" }),
1678
+ title: `展开 ${lt(o.id)} 个子节点`,
1679
+ onMousedown: t[10] || (t[10] = $(() => {
1680
+ }, ["stop"])),
1681
+ onClick: $((h) => St(o.id), ["stop"])
1682
+ }, ve(lt(o.id)), 47, zi)) : D("", !0),
1683
+ !n.readonly && !o.isRoot && wn(o) && !zt(o.id) ? (w(), k("button", {
1684
+ key: 5,
1685
+ class: be(["zm-btn zm-collapse", { "is-on-left": o.side === -1 }]),
1686
+ style: oe({ color: ue.value.get(o.id) ?? "#64748b", borderColor: ue.value.get(o.id) ?? "#64748b" }),
1687
+ title: "折叠",
1688
+ onMousedown: t[11] || (t[11] = $(() => {
1689
+ }, ["stop"])),
1690
+ onClick: $((h) => St(o.id), ["stop"])
1691
+ }, [
1692
+ P(O, {
1693
+ name: "minus",
1694
+ size: 10,
1695
+ stroke: 2.4
1696
+ })
1697
+ ], 46, Ei)) : D("", !0),
1698
+ o.image && m.value === o.id && f.value !== o.id ? (w(), k("span", {
1699
+ key: 6,
1700
+ class: "zm-img-resize-handle",
1701
+ title: "拖动调整图片大小",
1702
+ onMousedown: $((h) => Jt(h, o), ["stop"])
1703
+ }, null, 40, Ni)) : D("", !0),
1704
+ o.image && m.value === o.id && f.value !== o.id ? (w(), k("button", {
1705
+ key: 7,
1706
+ class: "zm-img-remove-btn",
1707
+ title: "移除图片",
1708
+ onMousedown: t[12] || (t[12] = $(() => {
1709
+ }, ["stop"])),
1710
+ onClick: $((h) => He(o.id), ["stop"])
1711
+ }, [
1712
+ P(O, {
1713
+ name: "x",
1714
+ size: 9,
1715
+ stroke: 2.2
1716
+ })
1717
+ ], 40, Ii)) : D("", !0)
1718
+ ], 46, pi))), 128))
1719
+ ], 4),
1720
+ F.value ? (w(), Nn(mi, {
1721
+ key: 1,
1722
+ x: F.value.x,
1723
+ y: F.value.y,
1724
+ container: s.value,
1725
+ "has-image": !!((r = S(W)(u.value, F.value.nodeId)) != null && r.image),
1726
+ "has-link": !!((c = S(W)(u.value, F.value.nodeId)) != null && c.link),
1727
+ "has-note": !!((v = S(W)(u.value, F.value.nodeId)) != null && v.note),
1728
+ readonly: l.readonly,
1729
+ onPickImage: X,
1730
+ onRemoveImage: Ie,
1731
+ onSetLink: U,
1732
+ onRemoveLink: Z,
1733
+ onEditNote: Q,
1734
+ onRemoveNote: he,
1735
+ onClose: V
1736
+ }, null, 8, ["x", "y", "container", "has-image", "has-link", "has-note", "readonly"])) : D("", !0)
1737
+ ], 544),
1738
+ l.previewMode ? D("", !0) : (w(), k("div", Wi, [
1739
+ g("button", {
1740
+ class: "zm-tb-btn",
1741
+ title: "放大",
1742
+ onClick: t[15] || (t[15] = //@ts-ignore
1743
+ (...o) => S(M).zoomIn && S(M).zoomIn(...o))
1744
+ }, [
1745
+ P(O, { name: "zoom-in" })
1746
+ ]),
1747
+ g("button", {
1748
+ class: "zm-tb-btn",
1749
+ title: "缩小",
1750
+ onClick: t[16] || (t[16] = //@ts-ignore
1751
+ (...o) => S(M).zoomOut && S(M).zoomOut(...o))
1752
+ }, [
1753
+ P(O, { name: "zoom-out" })
1754
+ ]),
1755
+ g("button", {
1756
+ class: "zm-tb-btn",
1757
+ title: "重置视图",
1758
+ onClick: se
1759
+ }, [
1760
+ P(O, { name: "reset" })
1761
+ ]),
1762
+ t[22] || (t[22] = g("span", { class: "zm-tb-divider" }, null, -1)),
1763
+ n.readonly ? D("", !0) : (w(), k("button", {
1764
+ key: 0,
1765
+ class: "zm-tb-btn",
1766
+ title: "添加子节点 (Tab)",
1767
+ onClick: t[17] || (t[17] = (o) => m.value && me(m.value))
1768
+ }, [
1769
+ g("img", {
1770
+ src: S(Rn),
1771
+ width: "14",
1772
+ height: "14",
1773
+ alt: "添加子节点",
1774
+ draggable: "false"
1775
+ }, null, 8, $i)
1776
+ ])),
1777
+ n.readonly ? D("", !0) : (w(), k("button", {
1778
+ key: 1,
1779
+ class: "zm-tb-btn",
1780
+ title: "添加同级 (Enter)",
1781
+ onClick: t[18] || (t[18] = (o) => m.value && Te(m.value))
1782
+ }, [
1783
+ g("img", {
1784
+ src: S(Bn),
1785
+ width: "14",
1786
+ height: "14",
1787
+ alt: "添加同级",
1788
+ draggable: "false"
1789
+ }, null, 8, Bi)
1790
+ ])),
1791
+ t[23] || (t[23] = g("span", { class: "zm-tb-divider" }, null, -1)),
1792
+ g("button", {
1793
+ class: be(["zm-tb-btn", { active: p.layoutMode === "mindmap" }]),
1794
+ title: "思维导图布局 (中心辐射)",
1795
+ onClick: t[19] || (t[19] = (o) => ot("mindmap"))
1796
+ }, [
1797
+ P(O, { name: "mindmap" })
1798
+ ], 2),
1799
+ g("button", {
1800
+ class: be(["zm-tb-btn", { active: p.layoutMode === "tree" }]),
1801
+ title: "树形布局 (向右展开)",
1802
+ onClick: t[20] || (t[20] = (o) => ot("tree"))
1803
+ }, [
1804
+ P(O, { name: "tree" })
1805
+ ], 2),
1806
+ g("button", {
1807
+ class: be(["zm-tb-btn", { active: p.layoutMode === "org" }]),
1808
+ title: "组织结构布局 (向下展开)",
1809
+ onClick: t[21] || (t[21] = (o) => ot("org"))
1810
+ }, [
1811
+ P(O, { name: "org" })
1812
+ ], 2),
1813
+ t[24] || (t[24] = g("span", { class: "zm-tb-divider" }, null, -1)),
1814
+ n.readonly ? D("", !0) : (w(), k("button", {
1815
+ key: 2,
1816
+ class: "zm-tb-btn",
1817
+ title: "导入 JSON",
1818
+ onClick: Mn
1819
+ }, [
1820
+ P(O, { name: "import" })
1821
+ ])),
1822
+ g("button", {
1823
+ class: "zm-tb-btn",
1824
+ title: "导出 JSON",
1825
+ onClick: Cn
1826
+ }, [
1827
+ P(O, { name: "export" })
1828
+ ]),
1829
+ g("span", Ri, ve(Math.round(S(M).scale.value * 100)) + "%", 1)
1830
+ ]))
1831
+ ], 4);
1832
+ };
1833
+ }
1834
+ }), Hi = {
1835
+ install(n) {
1836
+ n.component("FlowMindMap", Ai);
1837
+ }
1838
+ };
1839
+ export {
1840
+ Ai as MindMap,
1841
+ ti as addChild,
1842
+ ni as addSibling,
1843
+ ke as clone,
1844
+ Hi as default,
1845
+ W as findNode,
1846
+ te as findParent,
1847
+ Yt as removeNode,
1848
+ Ze as uid
1849
+ };