markmap-view-plus 0.0.2 → 0.0.3

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.
package/dist/index.js CHANGED
@@ -1,805 +1,829 @@
1
- import { scaleOrdinal as ht, schemeCategory10 as Nt, select as S, zoomTransform as z, linkHorizontal as $t, zoom as zt, max as nt, min as ot, zoomIdentity as Rt, minIndex as At } from "d3";
2
- class Tt {
3
- constructor() {
4
- this.listeners = [];
5
- }
6
- tap(t) {
7
- return this.listeners.push(t), () => this.revoke(t);
8
- }
9
- revoke(t) {
10
- const e = this.listeners.indexOf(t);
11
- e >= 0 && this.listeners.splice(e, 1);
12
- }
13
- revokeAll() {
14
- this.listeners.splice(0);
15
- }
16
- call(...t) {
17
- for (const e of this.listeners)
18
- e(...t);
19
- }
20
- }
21
- const Mt = Math.random().toString(36).slice(2, 8);
22
- let rt = 0;
23
- function Bt() {
24
- return rt += 1, `mm-${Mt}-${rt}`;
1
+ import { linkHorizontal as e, max as t, min as n, minIndex as r, scaleOrdinal as i, schemeCategory10 as a, select as o, zoom as s, zoomIdentity as c, zoomTransform as l } from "d3";
2
+ var u = "npm2url/dist/index.cjs", d = {
3
+ jsdelivr: (e) => `https://cdn.jsdelivr.net/npm/${e}`,
4
+ unpkg: (e) => `https://unpkg.com/${e}`
5
+ };
6
+ async function f(e, t) {
7
+ let n = await fetch(e, { signal: t });
8
+ if (!n.ok) throw n;
9
+ await n.text();
25
10
  }
26
- function B() {
11
+ new class {
12
+ constructor() {
13
+ this.providers = { ...d }, this.provider = "jsdelivr";
14
+ }
15
+ /**
16
+ * Get the fastest provider name.
17
+ * If none of the providers returns a valid response within `timeout`, an error will be thrown.
18
+ */
19
+ async getFastestProvider(e = 5e3, t = u) {
20
+ let n = new AbortController(), r = 0;
21
+ try {
22
+ return await new Promise((i, a) => {
23
+ Promise.all(Object.entries(this.providers).map(async ([e, r]) => {
24
+ try {
25
+ await f(r(t), n.signal), i(e);
26
+ } catch {}
27
+ })).then(() => a(/* @__PURE__ */ Error("All providers failed"))), r = setTimeout(a, e, /* @__PURE__ */ Error("Timed out"));
28
+ });
29
+ } finally {
30
+ n.abort(), clearTimeout(r);
31
+ }
32
+ }
33
+ /**
34
+ * Set the current provider to the fastest provider found by `getFastestProvider`.
35
+ */
36
+ async findFastestProvider(e, t) {
37
+ return this.provider = await this.getFastestProvider(e, t), this.provider;
38
+ }
39
+ setProvider(e, t) {
40
+ t ? this.providers[e] = t : delete this.providers[e];
41
+ }
42
+ getFullUrl(e, t = this.provider) {
43
+ if (e.includes("://")) return e;
44
+ let n = this.providers[t];
45
+ if (!n) throw Error(`Provider ${t} not found`);
46
+ return n(e);
47
+ }
48
+ }();
49
+ var p = class {
50
+ constructor() {
51
+ this.listeners = [];
52
+ }
53
+ tap(e) {
54
+ return this.listeners.push(e), () => this.revoke(e);
55
+ }
56
+ revoke(e) {
57
+ let t = this.listeners.indexOf(e);
58
+ t >= 0 && this.listeners.splice(t, 1);
59
+ }
60
+ revokeAll() {
61
+ this.listeners.splice(0);
62
+ }
63
+ call(...e) {
64
+ for (let t of this.listeners) t(...e);
65
+ }
66
+ }, m = Math.random().toString(36).slice(2, 8), h = 0;
67
+ function g() {
68
+ return h += 1, `mm-${m}-${h}`;
27
69
  }
28
- function R(n, t) {
29
- const e = (i, o) => t(
30
- i,
31
- () => {
32
- var s;
33
- return (s = i.children) == null ? void 0 : s.map((a) => e(a, i));
34
- },
35
- o
36
- );
37
- return e(n);
70
+ function _() {}
71
+ function v(e, t) {
72
+ let n = (e, r) => t(e, () => e.children?.map((t) => n(t, e)), r);
73
+ return n(e);
38
74
  }
39
- function Dt(n, ...t) {
40
- const e = "".split(" ").filter(Boolean);
41
- return t.forEach((i) => {
42
- i && e.indexOf(i) < 0 && e.push(i);
43
- }), e.join(" ");
75
+ function y(e, ...t) {
76
+ let n = (e || "").split(" ").filter(Boolean);
77
+ return t.forEach((e) => {
78
+ e && n.indexOf(e) < 0 && n.push(e);
79
+ }), n.join(" ");
44
80
  }
45
- function pt() {
46
- const n = {};
47
- return n.promise = new Promise((t, e) => {
48
- n.resolve = t, n.reject = e;
49
- }), n;
81
+ function b() {
82
+ let e = {};
83
+ return e.promise = new Promise((t, n) => {
84
+ e.resolve = t, e.reject = n;
85
+ }), e;
50
86
  }
51
- function Pt(n) {
52
- const t = {};
53
- return function(...i) {
54
- const o = `${i[0]}`;
55
- let s = t[o];
56
- return s || (s = {
57
- value: n(...i)
58
- }, t[o] = s), s.value;
59
- };
87
+ function x(e) {
88
+ let t = {};
89
+ return function(...n) {
90
+ let r = `${n[0]}`, i = t[r];
91
+ return i || (i = { value: e(...n) }, t[r] = i), i.value;
92
+ };
60
93
  }
61
- function jt(n, t) {
62
- const e = {
63
- timer: 0
64
- };
65
- function i() {
66
- e.timer && (window.clearTimeout(e.timer), e.timer = 0);
67
- }
68
- function o() {
69
- i(), e.args && (e.result = n(...e.args));
70
- }
71
- return function(...a) {
72
- return i(), e.args = a, e.timer = window.setTimeout(o, t), e.result;
73
- };
94
+ function S(e, t) {
95
+ let n = { timer: 0 };
96
+ function r() {
97
+ n.timer &&= (window.clearTimeout(n.timer), 0);
98
+ }
99
+ function i() {
100
+ r(), n.args && (n.result = e(...n.args));
101
+ }
102
+ return function(...e) {
103
+ return r(), n.args = e, n.timer = window.setTimeout(i, t), n.result;
104
+ };
74
105
  }
75
- /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
76
- const ut = 1, ft = 2, Xt = "http://www.w3.org/2000/svg", H = "http://www.w3.org/1999/xlink", Ut = {
77
- show: H,
78
- actuate: H,
79
- href: H
80
- }, Ht = (n) => typeof n == "string" || typeof n == "number", Lt = (n) => (n == null ? void 0 : n.vtype) === ut, Ft = (n) => (n == null ? void 0 : n.vtype) === ft;
81
- function Wt(n, t, ...e) {
82
- return t = Object.assign({}, t, {
83
- children: e.length === 1 ? e[0] : e
84
- }), Vt(n, t);
106
+ var C = 1, w = 2, T = "http://www.w3.org/2000/svg", E = "http://www.w3.org/1999/xlink", D = {
107
+ show: E,
108
+ actuate: E,
109
+ href: E
110
+ }, O = (e) => typeof e == "string" || typeof e == "number", k = (e) => e?.vtype === C, A = (e) => e?.vtype === w;
111
+ function j(e, t, ...n) {
112
+ return t = Object.assign({}, t, { children: n.length === 1 ? n[0] : n }), M(e, t);
85
113
  }
86
- function Vt(n, t) {
87
- let e;
88
- if (typeof n == "string") e = ut;
89
- else if (typeof n == "function") e = ft;
90
- else throw new Error("Invalid VNode type");
91
- return {
92
- vtype: e,
93
- type: n,
94
- props: t
95
- };
114
+ function M(e, t) {
115
+ let n;
116
+ if (typeof e == "string") n = C;
117
+ else if (typeof e == "function") n = w;
118
+ else throw Error("Invalid VNode type");
119
+ return {
120
+ vtype: n,
121
+ type: e,
122
+ props: t
123
+ };
96
124
  }
97
- function Kt(n) {
98
- return n.children;
125
+ function ee(e) {
126
+ return e.children;
99
127
  }
100
- const Yt = {
101
- isSvg: !1
102
- };
103
- function st(n, t) {
104
- Array.isArray(t) || (t = [t]), t = t.filter(Boolean), t.length && n.append(...t);
128
+ var N = { isSvg: !1 };
129
+ function P(e, t) {
130
+ Array.isArray(t) || (t = [t]), t = t.filter(Boolean), t.length && e.append(...t);
105
131
  }
106
- function Gt(n, t, e) {
107
- for (const i in t)
108
- if (!(i === "key" || i === "children" || i === "ref"))
109
- if (i === "dangerouslySetInnerHTML")
110
- n.innerHTML = t[i].__html;
111
- else if (i === "innerHTML" || i === "textContent" || i === "innerText" || i === "value" && ["textarea", "select"].includes(n.tagName)) {
112
- const o = t[i];
113
- o != null && (n[i] = o);
114
- } else i.startsWith("on") ? n[i.toLowerCase()] = t[i] : Jt(n, i, t[i], e.isSvg);
132
+ function te(e, t, n) {
133
+ for (let r in t) if (!(r === "key" || r === "children" || r === "ref")) if (r === "dangerouslySetInnerHTML") e.innerHTML = t[r].__html;
134
+ else if (r === "innerHTML" || r === "textContent" || r === "innerText" || r === "value" && ["textarea", "select"].includes(e.tagName)) {
135
+ let n = t[r];
136
+ n != null && (e[r] = n);
137
+ } else r.startsWith("on") ? e[r.toLowerCase()] = t[r] : F(e, r, t[r], n.isSvg);
115
138
  }
116
- const qt = {
117
- className: "class",
118
- labelFor: "for"
139
+ var ne = {
140
+ className: "class",
141
+ labelFor: "for"
119
142
  };
120
- function Jt(n, t, e, i) {
121
- if (t = qt[t] || t, e === !0)
122
- n.setAttribute(t, "");
123
- else if (e === !1)
124
- n.removeAttribute(t);
125
- else {
126
- const o = i ? Ut[t] : void 0;
127
- o !== void 0 ? n.setAttributeNS(o, t, e) : n.setAttribute(t, e);
128
- }
143
+ function F(e, t, n, r) {
144
+ if (t = ne[t] || t, n === !0) e.setAttribute(t, "");
145
+ else if (n === !1) e.removeAttribute(t);
146
+ else {
147
+ let i = r ? D[t] : void 0;
148
+ i === void 0 ? e.setAttribute(t, n) : e.setAttributeNS(i, t, n);
149
+ }
129
150
  }
130
- function Zt(n) {
131
- return n.reduce((t, e) => t.concat(e), []);
151
+ function re(e) {
152
+ return e.reduce((e, t) => e.concat(t), []);
132
153
  }
133
- function W(n, t) {
134
- return Array.isArray(n) ? Zt(n.map((e) => W(e, t))) : K(n, t);
154
+ function I(e, t) {
155
+ return Array.isArray(e) ? re(e.map((e) => I(e, t))) : L(e, t);
135
156
  }
136
- function K(n, t = Yt) {
137
- if (n == null || typeof n == "boolean")
138
- return null;
139
- if (n instanceof Node)
140
- return n;
141
- if (Ft(n)) {
142
- const {
143
- type: e,
144
- props: i
145
- } = n;
146
- if (e === Kt) {
147
- const s = document.createDocumentFragment();
148
- if (i.children) {
149
- const a = W(i.children, t);
150
- st(s, a);
151
- }
152
- return s;
153
- }
154
- const o = e(i);
155
- return K(o, t);
156
- }
157
- if (Ht(n))
158
- return document.createTextNode(`${n}`);
159
- if (Lt(n)) {
160
- let e;
161
- const {
162
- type: i,
163
- props: o
164
- } = n;
165
- if (!t.isSvg && i === "svg" && (t = Object.assign({}, t, {
166
- isSvg: !0
167
- })), t.isSvg ? e = document.createElementNS(Xt, i) : e = document.createElement(i), Gt(e, o, t), o.children) {
168
- let a = t;
169
- t.isSvg && i === "foreignObject" && (a = Object.assign({}, a, {
170
- isSvg: !1
171
- }));
172
- const l = W(o.children, a);
173
- l != null && st(e, l);
174
- }
175
- const {
176
- ref: s
177
- } = o;
178
- return typeof s == "function" && s(e), e;
179
- }
180
- throw new Error("mount: Invalid Vnode!");
157
+ function L(e, t = N) {
158
+ if (e == null || typeof e == "boolean") return null;
159
+ if (e instanceof Node) return e;
160
+ if (A(e)) {
161
+ let { type: n, props: r } = e;
162
+ if (n === ee) {
163
+ let e = document.createDocumentFragment();
164
+ return r.children && P(e, I(r.children, t)), e;
165
+ }
166
+ return L(n(r), t);
167
+ }
168
+ if (O(e)) return document.createTextNode(`${e}`);
169
+ if (k(e)) {
170
+ let n, { type: r, props: i } = e;
171
+ if (!t.isSvg && r === "svg" && (t = Object.assign({}, t, { isSvg: !0 })), n = t.isSvg ? document.createElementNS(T, r) : document.createElement(r), te(n, i, t), i.children) {
172
+ let e = t;
173
+ t.isSvg && r === "foreignObject" && (e = Object.assign({}, e, { isSvg: !1 }));
174
+ let a = I(i.children, e);
175
+ a != null && P(n, a);
176
+ }
177
+ let { ref: a } = i;
178
+ return typeof a == "function" && a(n), n;
179
+ }
180
+ throw Error("mount: Invalid Vnode!");
181
181
  }
182
- function Qt(n) {
183
- return K(n);
182
+ function ie(e) {
183
+ return L(e);
184
184
  }
185
- function D(...n) {
186
- return Qt(Wt(...n));
185
+ function R(...e) {
186
+ return ie(j(...e));
187
187
  }
188
- const te = Pt((n) => {
189
- document.head.append(
190
- D("link", {
191
- rel: "preload",
192
- as: "script",
193
- href: n
194
- })
195
- );
196
- }), at = {}, lt = {};
197
- async function ee(n, t) {
198
- var e;
199
- const i = n.type === "script" && ((e = n.data) == null ? void 0 : e.src) || "";
200
- if (n.loaded || (n.loaded = at[i]), !n.loaded) {
201
- const o = pt();
202
- if (n.loaded = o.promise, n.type === "script" && (document.head.append(
203
- D("script", {
204
- ...n.data,
205
- onLoad: () => o.resolve(),
206
- onError: o.reject
207
- })
208
- ), i ? at[i] = n.loaded : o.resolve()), n.type === "iife") {
209
- const { fn: s, getParams: a } = n.data;
210
- s(...(a == null ? void 0 : a(t)) || []), o.resolve();
211
- }
212
- }
213
- await n.loaded;
188
+ var ae = x((e) => {
189
+ document.head.append(R("link", {
190
+ rel: "preload",
191
+ as: "script",
192
+ href: e
193
+ }));
194
+ }), z = {}, oe = {};
195
+ async function se(e, t) {
196
+ let n = e.type === "script" && e.data?.src || "";
197
+ if (e.loaded ||= z[n], !e.loaded) {
198
+ let r = b();
199
+ if (e.loaded = r.promise, e.type === "script" && (document.head.append(R("script", {
200
+ ...e.data,
201
+ onLoad: () => r.resolve(),
202
+ onError: r.reject
203
+ })), n ? z[n] = e.loaded : r.resolve()), e.type === "iife") {
204
+ let { fn: n, getParams: i } = e.data;
205
+ n(...i?.(t) || []), r.resolve();
206
+ }
207
+ }
208
+ await e.loaded;
214
209
  }
215
- async function ie(n) {
216
- const t = n.type === "stylesheet" && n.data.href || "";
217
- if (n.loaded || (n.loaded = lt[t]), !n.loaded) {
218
- const e = pt();
219
- n.loaded = e.promise, t && (lt[t] = n.loaded), n.type === "style" ? (document.head.append(
220
- D("style", {
221
- textContent: n.data
222
- })
223
- ), e.resolve()) : t && (document.head.append(
224
- D("link", {
225
- rel: "stylesheet",
226
- ...n.data
227
- })
228
- ), fetch(t).then((i) => {
229
- if (i.ok) return i.text();
230
- throw i;
231
- }).then(() => e.resolve(), e.reject));
232
- }
233
- await n.loaded;
210
+ async function ce(e) {
211
+ let t = e.type === "stylesheet" && e.data.href || "";
212
+ if (e.loaded ||= oe[t], !e.loaded) {
213
+ let n = b();
214
+ e.loaded = n.promise, t && (oe[t] = e.loaded), e.type === "style" ? (document.head.append(R("style", { textContent: e.data })), n.resolve()) : t && (document.head.append(R("link", {
215
+ rel: "stylesheet",
216
+ ...e.data
217
+ })), fetch(t).then((e) => {
218
+ if (e.ok) return e.text();
219
+ throw e;
220
+ }).then(() => n.resolve(), n.reject));
221
+ }
222
+ await e.loaded;
234
223
  }
235
- async function He(n, t) {
236
- n.forEach((e) => {
237
- var i;
238
- e.type === "script" && ((i = e.data) != null && i.src) && te(e.data.src);
239
- }), t = {
240
- getMarkmap: () => window.markmap,
241
- ...t
242
- };
243
- for (const e of n)
244
- await ee(e, t);
224
+ async function le(e, t) {
225
+ e.forEach((e) => {
226
+ e.type === "script" && e.data?.src && ae(e.data.src);
227
+ }), t = {
228
+ getMarkmap: () => window.markmap,
229
+ ...t
230
+ };
231
+ for (let n of e) await se(n, t);
245
232
  }
246
- async function Le(n) {
247
- await Promise.all(n.map((t) => ie(t)));
233
+ async function ue(e) {
234
+ await Promise.all(e.map((e) => ce(e)));
248
235
  }
249
- const gt = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), ne = ht(Nt), mt = (n = 1, t = 3, e = 2) => (i) => n + t / e ** i.state.depth, yt = {
250
- autoFit: !1,
251
- duration: 500,
252
- embedGlobalCSS: !0,
253
- fitRatio: 0.95,
254
- maxInitialScale: 2,
255
- scrollForPan: gt,
256
- initialExpandLevel: -1,
257
- zoom: !0,
258
- pan: !0,
259
- toggleRecursively: !1,
260
- editable: !0,
261
- addable: !0,
262
- deletable: !0,
263
- collapseOnHover: !0,
264
- hoverBorder: !0,
265
- clickBorder: !0,
266
- onNodeEdit: void 0,
267
- onNodeAdd: void 0,
268
- inputPlaceholder: "Enter text",
269
- color: (n) => {
270
- var t;
271
- return ne(`${((t = n.state) == null ? void 0 : t.path) || ""}`);
272
- },
273
- lineWidth: mt(),
274
- maxWidth: 0,
275
- nodeMinHeight: 16,
276
- paddingX: 8,
277
- spacingHorizontal: 80,
278
- spacingVertical: 5
236
+ const B = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), V = i(a), H = (e = 1, t = 3, n = 2) => (r) => e + t / n ** r.state.depth, U = {
237
+ autoFit: !1,
238
+ duration: 500,
239
+ embedGlobalCSS: !0,
240
+ fitRatio: .95,
241
+ maxInitialScale: 2,
242
+ scrollForPan: B,
243
+ initialExpandLevel: -1,
244
+ zoom: !0,
245
+ pan: !0,
246
+ toggleRecursively: !1,
247
+ editable: !0,
248
+ addable: !0,
249
+ deletable: !0,
250
+ collapseOnHover: !0,
251
+ hoverBorder: !0,
252
+ clickBorder: !0,
253
+ onNodeEdit: void 0,
254
+ onNodeAdd: void 0,
255
+ inputPlaceholder: "Enter text",
256
+ color: (e) => V(`${e.state?.path || ""}`),
257
+ lineWidth: H(),
258
+ maxWidth: 0,
259
+ nodeMinHeight: 16,
260
+ paddingX: 8,
261
+ spacingHorizontal: 80,
262
+ spacingVertical: 5
279
263
  };
280
- function Fe(n) {
281
- const t = {}, e = { ...n }, { color: i, colorFreezeLevel: o, lineWidth: s } = e;
282
- if ((i == null ? void 0 : i.length) === 1) {
283
- const h = i[0];
284
- t.color = () => h;
285
- } else if (i != null && i.length) {
286
- const h = ht(i);
287
- t.color = (c) => h(`${c.state.path}`);
288
- }
289
- if (o) {
290
- const h = t.color || yt.color;
291
- t.color = (c) => (c = {
292
- ...c,
293
- state: {
294
- ...c.state,
295
- path: c.state.path.split(".").slice(0, o).join(".")
296
- }
297
- }, h(c));
298
- }
299
- if (s) {
300
- const h = Array.isArray(s) ? s : [s, 0, 1];
301
- t.lineWidth = mt(
302
- ...h
303
- );
304
- }
305
- return [
306
- "duration",
307
- "fitRatio",
308
- "initialExpandLevel",
309
- "maxInitialScale",
310
- "maxWidth",
311
- "nodeMinHeight",
312
- "paddingX",
313
- "spacingHorizontal",
314
- "spacingVertical"
315
- ].forEach((h) => {
316
- const c = e[h];
317
- typeof c == "number" && (t[h] = c);
318
- }), ["zoom", "pan"].forEach((h) => {
319
- const c = e[h];
320
- c != null && (t[h] = !!c);
321
- }), t;
264
+ function de(e) {
265
+ let t = {}, n = { ...e }, { color: r, colorFreezeLevel: a, lineWidth: o } = n;
266
+ if (r?.length === 1) {
267
+ let e = r[0];
268
+ t.color = () => e;
269
+ } else if (r?.length) {
270
+ let e = i(r);
271
+ t.color = (t) => e(`${t.state.path}`);
272
+ }
273
+ if (a) {
274
+ let e = t.color || U.color;
275
+ t.color = (t) => (t = {
276
+ ...t,
277
+ state: {
278
+ ...t.state,
279
+ path: t.state.path.split(".").slice(0, a).join(".")
280
+ }
281
+ }, e(t));
282
+ }
283
+ return o && (t.lineWidth = H(...Array.isArray(o) ? o : [
284
+ o,
285
+ 0,
286
+ 1
287
+ ])), [
288
+ "duration",
289
+ "fitRatio",
290
+ "initialExpandLevel",
291
+ "maxInitialScale",
292
+ "maxWidth",
293
+ "nodeMinHeight",
294
+ "paddingX",
295
+ "spacingHorizontal",
296
+ "spacingVertical"
297
+ ].forEach((e) => {
298
+ let r = n[e];
299
+ typeof r == "number" && (t[e] = r);
300
+ }), ["zoom", "pan"].forEach((e) => {
301
+ let r = n[e];
302
+ r != null && (t[e] = !!r);
303
+ }), t;
322
304
  }
323
- function V(n) {
324
- let t = 0;
325
- for (let e = 0; e < n.length; e++)
326
- t = (t << 5) - t + n.charCodeAt(e) | 0;
327
- return (t >>> 0).toString(36);
305
+ /**
306
+ * Credit: https://gist.github.com/jlevy/c246006675becc446360a798e2b2d781?permalink_comment_id=4738050#gistcomment-4738050
307
+ */
308
+ function W(e) {
309
+ let t = 0;
310
+ for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n) | 0;
311
+ return (t >>> 0).toString(36);
328
312
  }
329
- function b(n) {
330
- if (typeof n == "string") {
331
- const e = n;
332
- n = (i) => i.matches(e);
333
- }
334
- const t = n;
335
- return function() {
336
- let i = Array.from(this.childNodes);
337
- return t && (i = i.filter((o) => t(o))), i;
338
- };
313
+ function G(e) {
314
+ if (typeof e == "string") {
315
+ let t = e;
316
+ e = (e) => e.matches(t);
317
+ }
318
+ let t = e;
319
+ return function() {
320
+ let e = Array.from(this.childNodes);
321
+ return t && (e = e.filter((e) => t(e))), e;
322
+ };
339
323
  }
340
- function oe(n) {
341
- var t = 0, e = n.children, i = e && e.length;
342
- if (!i) t = 1;
343
- else for (; --i >= 0; ) t += e[i].value;
344
- n.value = t;
324
+ function fe(e) {
325
+ var t = 0, n = e.children, r = n && n.length;
326
+ if (!r) t = 1;
327
+ else for (; --r >= 0;) t += n[r].value;
328
+ e.value = t;
345
329
  }
346
- function re() {
347
- return this.eachAfter(oe);
330
+ function pe() {
331
+ return this.eachAfter(fe);
348
332
  }
349
- function se(n) {
350
- var t = this, e, i = [t], o, s, a;
351
- do
352
- for (e = i.reverse(), i = []; t = e.pop(); )
353
- if (n(t), o = t.children, o) for (s = 0, a = o.length; s < a; ++s)
354
- i.push(o[s]);
355
- while (i.length);
356
- return this;
333
+ function me(e) {
334
+ var t = this, n, r = [t], i, a, o;
335
+ do
336
+ for (n = r.reverse(), r = []; t = n.pop();) if (e(t), i = t.children, i) for (a = 0, o = i.length; a < o; ++a) r.push(i[a]);
337
+ while (r.length);
338
+ return this;
357
339
  }
358
- function ae(n) {
359
- for (var t = this, e = [t], i, o; t = e.pop(); )
360
- if (n(t), i = t.children, i) for (o = i.length - 1; o >= 0; --o)
361
- e.push(i[o]);
362
- return this;
340
+ function he(e) {
341
+ for (var t = this, n = [t], r, i; t = n.pop();) if (e(t), r = t.children, r) for (i = r.length - 1; i >= 0; --i) n.push(r[i]);
342
+ return this;
363
343
  }
364
- function le(n) {
365
- for (var t = this, e = [t], i = [], o, s, a; t = e.pop(); )
366
- if (i.push(t), o = t.children, o) for (s = 0, a = o.length; s < a; ++s)
367
- e.push(o[s]);
368
- for (; t = i.pop(); )
369
- n(t);
370
- return this;
344
+ function ge(e) {
345
+ for (var t = this, n = [t], r = [], i, a, o; t = n.pop();) if (r.push(t), i = t.children, i) for (a = 0, o = i.length; a < o; ++a) n.push(i[a]);
346
+ for (; t = r.pop();) e(t);
347
+ return this;
371
348
  }
372
- function ce(n) {
373
- return this.eachAfter(function(t) {
374
- for (var e = +n(t.data) || 0, i = t.children, o = i && i.length; --o >= 0; ) e += i[o].value;
375
- t.value = e;
376
- });
349
+ function _e(e) {
350
+ return this.eachAfter(function(t) {
351
+ for (var n = +e(t.data) || 0, r = t.children, i = r && r.length; --i >= 0;) n += r[i].value;
352
+ t.value = n;
353
+ });
377
354
  }
378
- function de(n) {
379
- return this.eachBefore(function(t) {
380
- t.children && t.children.sort(n);
381
- });
355
+ function ve(e) {
356
+ return this.eachBefore(function(t) {
357
+ t.children && t.children.sort(e);
358
+ });
382
359
  }
383
- function he(n) {
384
- for (var t = this, e = pe(t, n), i = [t]; t !== e; )
385
- t = t.parent, i.push(t);
386
- for (var o = i.length; n !== e; )
387
- i.splice(o, 0, n), n = n.parent;
388
- return i;
360
+ function ye(e) {
361
+ for (var t = this, n = be(t, e), r = [t]; t !== n;) t = t.parent, r.push(t);
362
+ for (var i = r.length; e !== n;) r.splice(i, 0, e), e = e.parent;
363
+ return r;
389
364
  }
390
- function pe(n, t) {
391
- if (n === t) return n;
392
- var e = n.ancestors(), i = t.ancestors(), o = null;
393
- for (n = e.pop(), t = i.pop(); n === t; )
394
- o = n, n = e.pop(), t = i.pop();
395
- return o;
365
+ function be(e, t) {
366
+ if (e === t) return e;
367
+ var n = e.ancestors(), r = t.ancestors(), i = null;
368
+ for (e = n.pop(), t = r.pop(); e === t;) i = e, e = n.pop(), t = r.pop();
369
+ return i;
396
370
  }
397
- function ue() {
398
- for (var n = this, t = [n]; n = n.parent; )
399
- t.push(n);
400
- return t;
371
+ function xe() {
372
+ for (var e = this, t = [e]; e = e.parent;) t.push(e);
373
+ return t;
401
374
  }
402
- function fe() {
403
- var n = [];
404
- return this.each(function(t) {
405
- n.push(t);
406
- }), n;
375
+ function Se() {
376
+ var e = [];
377
+ return this.each(function(t) {
378
+ e.push(t);
379
+ }), e;
407
380
  }
408
- function ge() {
409
- var n = [];
410
- return this.eachBefore(function(t) {
411
- t.children || n.push(t);
412
- }), n;
381
+ function Ce() {
382
+ var e = [];
383
+ return this.eachBefore(function(t) {
384
+ t.children || e.push(t);
385
+ }), e;
413
386
  }
414
- function me() {
415
- var n = this, t = [];
416
- return n.each(function(e) {
417
- e !== n && t.push({ source: e.parent, target: e });
418
- }), t;
387
+ function we() {
388
+ var e = this, t = [];
389
+ return e.each(function(n) {
390
+ n !== e && t.push({
391
+ source: n.parent,
392
+ target: n
393
+ });
394
+ }), t;
419
395
  }
420
- function Y(n, t) {
421
- var e = new P(n), i = +n.value && (e.value = n.value), o, s = [e], a, l, h, c;
422
- for (t == null && (t = xe); o = s.pop(); )
423
- if (i && (o.value = +o.data.value), (l = t(o.data)) && (c = l.length))
424
- for (o.children = new Array(c), h = c - 1; h >= 0; --h)
425
- s.push(a = o.children[h] = new P(l[h])), a.parent = o, a.depth = o.depth + 1;
426
- return e.eachBefore(ke);
396
+ function K(e, t) {
397
+ var n = new q(e), r = +e.value && (n.value = e.value), i, a = [n], o, s, c, l;
398
+ for (t ??= Ee; i = a.pop();) if (r && (i.value = +i.data.value), (s = t(i.data)) && (l = s.length)) for (i.children = Array(l), c = l - 1; c >= 0; --c) a.push(o = i.children[c] = new q(s[c])), o.parent = i, o.depth = i.depth + 1;
399
+ return n.eachBefore(Oe);
427
400
  }
428
- function ye() {
429
- return Y(this).eachBefore(ve);
401
+ function Te() {
402
+ return K(this).eachBefore(De);
430
403
  }
431
- function xe(n) {
432
- return n.children;
404
+ function Ee(e) {
405
+ return e.children;
433
406
  }
434
- function ve(n) {
435
- n.data = n.data.data;
407
+ function De(e) {
408
+ e.data = e.data.data;
436
409
  }
437
- function ke(n) {
438
- var t = 0;
439
- do
440
- n.height = t;
441
- while ((n = n.parent) && n.height < ++t);
410
+ function Oe(e) {
411
+ var t = 0;
412
+ do
413
+ e.height = t;
414
+ while ((e = e.parent) && e.height < ++t);
442
415
  }
443
- function P(n) {
444
- this.data = n, this.depth = this.height = 0, this.parent = null;
416
+ function q(e) {
417
+ this.data = e, this.depth = this.height = 0, this.parent = null;
445
418
  }
446
- P.prototype = Y.prototype = {
447
- constructor: P,
448
- count: re,
449
- each: se,
450
- eachAfter: le,
451
- eachBefore: ae,
452
- sum: ce,
453
- sort: de,
454
- path: he,
455
- ancestors: ue,
456
- descendants: fe,
457
- leaves: ge,
458
- links: me,
459
- copy: ye
419
+ q.prototype = K.prototype = {
420
+ constructor: q,
421
+ count: pe,
422
+ each: me,
423
+ eachAfter: ge,
424
+ eachBefore: he,
425
+ sum: _e,
426
+ sort: ve,
427
+ path: ye,
428
+ ancestors: xe,
429
+ descendants: Se,
430
+ leaves: Ce,
431
+ links: we,
432
+ copy: Te
433
+ };
434
+ const ke = {
435
+ name: "Chris Maloney",
436
+ url: "http://chrismaloney.org"
437
+ }, Ae = [
438
+ "d3",
439
+ "d3-module",
440
+ "layout",
441
+ "tree",
442
+ "hierarchy",
443
+ "d3-hierarchy",
444
+ "plugin",
445
+ "d3-plugin",
446
+ "infovis",
447
+ "visualization",
448
+ "2d"
449
+ ], je = {
450
+ type: "git",
451
+ url: "https://github.com/klortho/d3-flextree.git"
452
+ }, Me = {
453
+ clean: "rm -rf build demo test",
454
+ "build:demo": "rollup -c --environment BUILD:demo",
455
+ "build:dev": "rollup -c --environment BUILD:dev",
456
+ "build:prod": "rollup -c --environment BUILD:prod",
457
+ "build:test": "rollup -c --environment BUILD:test",
458
+ build: "rollup -c",
459
+ lint: "eslint index.js src",
460
+ "test:main": "node test/bundle.js",
461
+ "test:browser": "node test/browser-tests.js",
462
+ test: "npm-run-all test:*",
463
+ prepare: "npm-run-all clean build lint test"
464
+ }, Ne = { "d3-hierarchy": "^1.1.5" }, Pe = {
465
+ "babel-plugin-external-helpers": "^6.22.0",
466
+ "babel-preset-es2015-rollup": "^3.0.0",
467
+ d3: "^4.13.0",
468
+ "d3-selection-multi": "^1.0.1",
469
+ eslint: "^4.19.1",
470
+ jsdom: "^11.6.2",
471
+ "npm-run-all": "^4.1.2",
472
+ rollup: "^0.55.3",
473
+ "rollup-plugin-babel": "^2.7.1",
474
+ "rollup-plugin-commonjs": "^8.0.2",
475
+ "rollup-plugin-copy": "^0.2.3",
476
+ "rollup-plugin-json": "^2.3.0",
477
+ "rollup-plugin-node-resolve": "^3.0.2",
478
+ "rollup-plugin-uglify": "^3.0.0",
479
+ "uglify-es": "^3.3.9"
460
480
  };
461
- const be = "2.1.2", we = {
462
- version: be
463
- }, { version: Ee } = we, Se = Object.freeze({
464
- children: (n) => n.children,
465
- nodeSize: (n) => n.data.size,
466
- spacing: 0
481
+ var { version: Fe } = {
482
+ name: "d3-flextree",
483
+ version: "2.1.2",
484
+ main: "build/d3-flextree.js",
485
+ module: "index",
486
+ "jsnext:main": "index",
487
+ author: ke,
488
+ description: "Flexible tree layout algorithm that allows for variable node sizes.",
489
+ keywords: Ae,
490
+ homepage: "https://github.com/klortho/d3-flextree",
491
+ license: "WTFPL",
492
+ repository: je,
493
+ scripts: Me,
494
+ dependencies: Ne,
495
+ devDependencies: Pe
496
+ }, Ie = Object.freeze({
497
+ children: (e) => e.children,
498
+ nodeSize: (e) => e.data.size,
499
+ spacing: 0
467
500
  });
468
- function vt(n) {
469
- const t = Object.assign({}, Se, n);
470
- function e(l) {
471
- const h = t[l];
472
- return typeof h == "function" ? h : () => h;
473
- }
474
- function i(l) {
475
- const h = a(s(), l, (c) => c.children);
476
- return h.update(), h.data;
477
- }
478
- function o() {
479
- const l = e("nodeSize"), h = e("spacing");
480
- return class xt extends Y.prototype.constructor {
481
- constructor(d) {
482
- super(d);
483
- }
484
- copy() {
485
- const d = a(this.constructor, this, (u) => u.children);
486
- return d.each((u) => u.data = u.data.data), d;
487
- }
488
- get size() {
489
- return l(this);
490
- }
491
- spacing(d) {
492
- return h(this, d);
493
- }
494
- get nodes() {
495
- return this.descendants();
496
- }
497
- get xSize() {
498
- return this.size[0];
499
- }
500
- get ySize() {
501
- return this.size[1];
502
- }
503
- get top() {
504
- return this.y;
505
- }
506
- get bottom() {
507
- return this.y + this.ySize;
508
- }
509
- get left() {
510
- return this.x - this.xSize / 2;
511
- }
512
- get right() {
513
- return this.x + this.xSize / 2;
514
- }
515
- get root() {
516
- const d = this.ancestors();
517
- return d[d.length - 1];
518
- }
519
- get numChildren() {
520
- return this.hasChildren ? this.children.length : 0;
521
- }
522
- get hasChildren() {
523
- return !this.noChildren;
524
- }
525
- get noChildren() {
526
- return this.children === null;
527
- }
528
- get firstChild() {
529
- return this.hasChildren ? this.children[0] : null;
530
- }
531
- get lastChild() {
532
- return this.hasChildren ? this.children[this.numChildren - 1] : null;
533
- }
534
- get extents() {
535
- return (this.children || []).reduce(
536
- (d, u) => xt.maxExtents(d, u.extents),
537
- this.nodeExtents
538
- );
539
- }
540
- get nodeExtents() {
541
- return {
542
- top: this.top,
543
- bottom: this.bottom,
544
- left: this.left,
545
- right: this.right
546
- };
547
- }
548
- static maxExtents(d, u) {
549
- return {
550
- top: Math.min(d.top, u.top),
551
- bottom: Math.max(d.bottom, u.bottom),
552
- left: Math.min(d.left, u.left),
553
- right: Math.max(d.right, u.right)
554
- };
555
- }
556
- };
557
- }
558
- function s() {
559
- const l = o(), h = e("nodeSize"), c = e("spacing");
560
- return class extends l {
561
- constructor(d) {
562
- super(d), Object.assign(this, {
563
- x: 0,
564
- y: 0,
565
- relX: 0,
566
- prelim: 0,
567
- shift: 0,
568
- change: 0,
569
- lExt: this,
570
- lExtRelX: 0,
571
- lThr: null,
572
- rExt: this,
573
- rExtRelX: 0,
574
- rThr: null
575
- });
576
- }
577
- get size() {
578
- return h(this.data);
579
- }
580
- spacing(d) {
581
- return c(this.data, d.data);
582
- }
583
- get x() {
584
- return this.data.x;
585
- }
586
- set x(d) {
587
- this.data.x = d;
588
- }
589
- get y() {
590
- return this.data.y;
591
- }
592
- set y(d) {
593
- this.data.y = d;
594
- }
595
- update() {
596
- return kt(this), bt(this), this;
597
- }
598
- };
599
- }
600
- function a(l, h, c) {
601
- const d = (u, f) => {
602
- const g = new l(u);
603
- Object.assign(g, {
604
- parent: f,
605
- depth: f === null ? 0 : f.depth + 1,
606
- height: 0,
607
- length: 1
608
- });
609
- const y = c(u) || [];
610
- return g.children = y.length === 0 ? null : y.map((v) => d(v, g)), g.children && Object.assign(g, g.children.reduce(
611
- (v, k) => ({
612
- height: Math.max(v.height, k.height + 1),
613
- length: v.length + k.length
614
- }),
615
- g
616
- )), g;
617
- };
618
- return d(h, null);
619
- }
620
- return Object.assign(i, {
621
- nodeSize(l) {
622
- return arguments.length ? (t.nodeSize = l, i) : t.nodeSize;
623
- },
624
- spacing(l) {
625
- return arguments.length ? (t.spacing = l, i) : t.spacing;
626
- },
627
- children(l) {
628
- return arguments.length ? (t.children = l, i) : t.children;
629
- },
630
- hierarchy(l, h) {
631
- const c = typeof h > "u" ? t.children : h;
632
- return a(o(), l, c);
633
- },
634
- dump(l) {
635
- const h = e("nodeSize"), c = (d) => (u) => {
636
- const f = d + " ", g = d + " ", { x: y, y: v } = u, k = h(u), x = u.children || [], _ = x.length === 0 ? " " : `,${f}children: [${g}${x.map(c(g)).join(g)}${f}],${d}`;
637
- return `{ size: [${k.join(", ")}],${f}x: ${y}, y: ${v}${_}},`;
638
- };
639
- return c(`
640
- `)(l);
641
- }
642
- }), i;
501
+ function Le(e) {
502
+ let t = Object.assign({}, Ie, e);
503
+ function n(e) {
504
+ let n = t[e];
505
+ return typeof n == "function" ? n : () => n;
506
+ }
507
+ function r(e) {
508
+ let t = o(a(), e, (e) => e.children);
509
+ return t.update(), t.data;
510
+ }
511
+ function i() {
512
+ let e = n("nodeSize"), t = n("spacing");
513
+ return class n extends K.prototype.constructor {
514
+ constructor(e) {
515
+ super(e);
516
+ }
517
+ copy() {
518
+ let e = o(this.constructor, this, (e) => e.children);
519
+ return e.each((e) => e.data = e.data.data), e;
520
+ }
521
+ get size() {
522
+ return e(this);
523
+ }
524
+ spacing(e) {
525
+ return t(this, e);
526
+ }
527
+ get nodes() {
528
+ return this.descendants();
529
+ }
530
+ get xSize() {
531
+ return this.size[0];
532
+ }
533
+ get ySize() {
534
+ return this.size[1];
535
+ }
536
+ get top() {
537
+ return this.y;
538
+ }
539
+ get bottom() {
540
+ return this.y + this.ySize;
541
+ }
542
+ get left() {
543
+ return this.x - this.xSize / 2;
544
+ }
545
+ get right() {
546
+ return this.x + this.xSize / 2;
547
+ }
548
+ get root() {
549
+ let e = this.ancestors();
550
+ return e[e.length - 1];
551
+ }
552
+ get numChildren() {
553
+ return this.hasChildren ? this.children.length : 0;
554
+ }
555
+ get hasChildren() {
556
+ return !this.noChildren;
557
+ }
558
+ get noChildren() {
559
+ return this.children === null;
560
+ }
561
+ get firstChild() {
562
+ return this.hasChildren ? this.children[0] : null;
563
+ }
564
+ get lastChild() {
565
+ return this.hasChildren ? this.children[this.numChildren - 1] : null;
566
+ }
567
+ get extents() {
568
+ return (this.children || []).reduce((e, t) => n.maxExtents(e, t.extents), this.nodeExtents);
569
+ }
570
+ get nodeExtents() {
571
+ return {
572
+ top: this.top,
573
+ bottom: this.bottom,
574
+ left: this.left,
575
+ right: this.right
576
+ };
577
+ }
578
+ static maxExtents(e, t) {
579
+ return {
580
+ top: Math.min(e.top, t.top),
581
+ bottom: Math.max(e.bottom, t.bottom),
582
+ left: Math.min(e.left, t.left),
583
+ right: Math.max(e.right, t.right)
584
+ };
585
+ }
586
+ };
587
+ }
588
+ function a() {
589
+ let e = i(), t = n("nodeSize"), r = n("spacing");
590
+ return class extends e {
591
+ constructor(e) {
592
+ super(e), Object.assign(this, {
593
+ x: 0,
594
+ y: 0,
595
+ relX: 0,
596
+ prelim: 0,
597
+ shift: 0,
598
+ change: 0,
599
+ lExt: this,
600
+ lExtRelX: 0,
601
+ lThr: null,
602
+ rExt: this,
603
+ rExtRelX: 0,
604
+ rThr: null
605
+ });
606
+ }
607
+ get size() {
608
+ return t(this.data);
609
+ }
610
+ spacing(e) {
611
+ return r(this.data, e.data);
612
+ }
613
+ get x() {
614
+ return this.data.x;
615
+ }
616
+ set x(e) {
617
+ this.data.x = e;
618
+ }
619
+ get y() {
620
+ return this.data.y;
621
+ }
622
+ set y(e) {
623
+ this.data.y = e;
624
+ }
625
+ update() {
626
+ return Re(this), ze(this), this;
627
+ }
628
+ };
629
+ }
630
+ function o(e, t, n) {
631
+ let r = (t, i) => {
632
+ let a = new e(t);
633
+ Object.assign(a, {
634
+ parent: i,
635
+ depth: i === null ? 0 : i.depth + 1,
636
+ height: 0,
637
+ length: 1
638
+ });
639
+ let o = n(t) || [];
640
+ return a.children = o.length === 0 ? null : o.map((e) => r(e, a)), a.children && Object.assign(a, a.children.reduce((e, t) => ({
641
+ height: Math.max(e.height, t.height + 1),
642
+ length: e.length + t.length
643
+ }), a)), a;
644
+ };
645
+ return r(t, null);
646
+ }
647
+ return Object.assign(r, {
648
+ nodeSize(e) {
649
+ return arguments.length ? (t.nodeSize = e, r) : t.nodeSize;
650
+ },
651
+ spacing(e) {
652
+ return arguments.length ? (t.spacing = e, r) : t.spacing;
653
+ },
654
+ children(e) {
655
+ return arguments.length ? (t.children = e, r) : t.children;
656
+ },
657
+ hierarchy(e, n) {
658
+ let r = n === void 0 ? t.children : n;
659
+ return o(i(), e, r);
660
+ },
661
+ dump(e) {
662
+ let t = n("nodeSize"), r = (e) => (n) => {
663
+ let i = e + " ", a = e + " ", { x: o, y: s } = n, c = t(n), l = n.children || [], u = l.length === 0 ? " " : `,${i}children: [${a}${l.map(r(a)).join(a)}${i}],${e}`;
664
+ return `{ size: [${c.join(", ")}],${i}x: ${o}, y: ${s}${u}},`;
665
+ };
666
+ return r("\n")(e);
667
+ }
668
+ }), r;
643
669
  }
644
- vt.version = Ee;
645
- const kt = (n, t = 0) => (n.y = t, (n.children || []).reduce((e, i) => {
646
- const [o, s] = e;
647
- kt(i, n.y + n.ySize);
648
- const a = (o === 0 ? i.lExt : i.rExt).bottom;
649
- o !== 0 && _e(n, o, s);
650
- const l = Te(a, o, s);
651
- return [o + 1, l];
652
- }, [0, null]), Ce(n), Ae(n), n), bt = (n, t, e) => {
653
- typeof t > "u" && (t = -n.relX - n.prelim, e = 0);
654
- const i = t + n.relX;
655
- return n.relX = i + n.prelim - e, n.prelim = 0, n.x = e + n.relX, (n.children || []).forEach((o) => bt(o, i, n.x)), n;
656
- }, Ce = (n) => {
657
- (n.children || []).reduce((t, e) => {
658
- const [i, o] = t, s = i + e.shift, a = o + s + e.change;
659
- return e.relX += a, [s, a];
660
- }, [0, 0]);
661
- }, _e = (n, t, e) => {
662
- const i = n.children[t - 1], o = n.children[t];
663
- let s = i, a = i.relX, l = o, h = o.relX, c = !0;
664
- for (; s && l; ) {
665
- s.bottom > e.lowY && (e = e.next);
666
- const d = a + s.prelim - (h + l.prelim) + s.xSize / 2 + l.xSize / 2 + s.spacing(l);
667
- (d > 0 || d < 0 && c) && (h += d, Oe(o, d), Ie(n, t, e.index, d)), c = !1;
668
- const u = s.bottom, f = l.bottom;
669
- u <= f && (s = $e(s), s && (a += s.relX)), u >= f && (l = Ne(l), l && (h += l.relX));
670
- }
671
- !s && l ? ze(n, t, l, h) : s && !l && Re(n, t, s, a);
672
- }, Oe = (n, t) => {
673
- n.relX += t, n.lExtRelX += t, n.rExtRelX += t;
674
- }, Ie = (n, t, e, i) => {
675
- const o = n.children[t], s = t - e;
676
- if (s > 1) {
677
- const a = i / s;
678
- n.children[e + 1].shift += a, o.shift -= a, o.change -= i - a;
679
- }
680
- }, Ne = (n) => n.hasChildren ? n.firstChild : n.lThr, $e = (n) => n.hasChildren ? n.lastChild : n.rThr, ze = (n, t, e, i) => {
681
- const o = n.firstChild, s = o.lExt, a = n.children[t];
682
- s.lThr = e;
683
- const l = i - e.relX - o.lExtRelX;
684
- s.relX += l, s.prelim -= l, o.lExt = a.lExt, o.lExtRelX = a.lExtRelX;
685
- }, Re = (n, t, e, i) => {
686
- const o = n.children[t], s = o.rExt, a = n.children[t - 1];
687
- s.rThr = e;
688
- const l = i - e.relX - o.rExtRelX;
689
- s.relX += l, s.prelim -= l, o.rExt = a.rExt, o.rExtRelX = a.rExtRelX;
690
- }, Ae = (n) => {
691
- if (n.hasChildren) {
692
- const t = n.firstChild, e = n.lastChild, i = (t.prelim + t.relX - t.xSize / 2 + e.relX + e.prelim + e.xSize / 2) / 2;
693
- Object.assign(n, {
694
- prelim: i,
695
- lExt: t.lExt,
696
- lExtRelX: t.lExtRelX,
697
- rExt: e.rExt,
698
- rExtRelX: e.rExtRelX
699
- });
700
- }
701
- }, Te = (n, t, e) => {
702
- for (; e !== null && n >= e.lowY; )
703
- e = e.next;
704
- return {
705
- lowY: n,
706
- index: t,
707
- next: e
708
- };
709
- }, wt = ".markmap{--markmap-max-width: 9999px;--markmap-a-color: #0097e6;--markmap-a-hover-color: #00a8ff;--markmap-code-bg: #f0f0f0;--markmap-code-color: #555;--markmap-highlight-bg: #ffeaa7;--markmap-table-border: 1px solid currentColor;--markmap-font: 300 16px/20px sans-serif;--markmap-circle-open-bg: #fff;--markmap-text-color: #333;--markmap-highlight-node-bg: #ff02;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-node-hovered>foreignObject>div>div{padding:2px 6px;border-radius:14px;border:2px solid #d9d9d9}.markmap-selected>foreignObject>div>div,.markmap-selected.markmap-node-hovered>foreignObject>div>div{padding:2px 6px;border-radius:14px;border:2px solid #b4b4b4}.markmap-selected>circle{opacity:0!important;pointer-events:none}.markmap-collapse-on-hover .markmap-node>circle{opacity:0;transition:opacity .2s}.markmap-collapse-on-hover .markmap-node:hover>circle{opacity:1}.markmap-foreign{display:inline-block}.markmap-foreign>div>div{padding:4px 6px}.markmap-foreign .markmap-edit-wrapper{position:relative;width:100%;padding:4px;background:#fff;border-radius:4px;box-shadow:0 2px 8px #00000026;animation:fadeIn .2s ease-in}.markmap-foreign .markmap-edit-input{width:100%;padding:8px 12px;border:2px solid #4A90E2;border-radius:4px;font-size:14px;font-family:inherit;outline:none;background:#f8f9fa;transition:all .2s}.markmap-foreign .markmap-edit-input:focus{border-color:#2d7dd2;background:#fff;box-shadow:0 0 0 3px #4a90e21a}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{padding:.25em;font-size:calc(1em - 2px);color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign>div{width:var(--markmap-max-width);text-align:left}.markmap-foreign>div>div{display:inline-block;max-width:var(--markmap-wrap-width, 30em);overflow-wrap:break-word;word-break:break-word;white-space:normal}.markmap-highlight rect{fill:var(--markmap-highlight-node-bg)}.markmap-dark .markmap{--markmap-code-bg: #1a1b26;--markmap-code-color: #ddd;--markmap-circle-open-bg: #444;--markmap-text-color: #eee}@keyframes fadeIn{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}", L = "g.markmap-node";
710
- class Me {
711
- constructor(t) {
712
- this.ctx = t, this.editingNode = null, this.selectedNode = null;
713
- }
714
- // ── Private helpers ──────────────────────────────────────────────────────
715
- _getNodeContentEl(t) {
716
- const e = this.ctx.findElement(t);
717
- return e && S(e.g).select("foreignObject").select("div").select("div").node() || null;
718
- }
719
- _getOverlayRoot() {
720
- const t = this.ctx.svg.node();
721
- return (t == null ? void 0 : t.parentElement) || document.body;
722
- }
723
- _positionOverlayToEl(t, e, i) {
724
- const o = this._getOverlayRoot();
725
- window.getComputedStyle(o).position === "static" && (o.style.position = "relative");
726
- const a = e.getBoundingClientRect(), l = o.getBoundingClientRect(), h = (i == null ? void 0 : i.dx) ?? 0, c = (i == null ? void 0 : i.dy) ?? 0, d = (i == null ? void 0 : i.minW) ?? 0, u = (i == null ? void 0 : i.minH) ?? 0;
727
- let f = a.left - l.left + h, g = a.top - l.top + c;
728
- (i == null ? void 0 : i.anchor) === "br" ? (f = a.right - l.left + h, g = a.bottom - l.top + c) : (i == null ? void 0 : i.anchor) === "r" && (f = a.right - l.left + h, g = a.top - l.top + c), t.style.left = `${f}px`, t.style.top = `${g}px`, d && (t.style.width = `${Math.max(d, a.width)}px`), u && (t.style.height = `${Math.max(u, a.height)}px`);
729
- }
730
- _safeRemoveEl(t) {
731
- try {
732
- t.parentNode && t.remove();
733
- } catch {
734
- }
735
- }
736
- _clearSelectionCss() {
737
- this.ctx.options.clickBorder && this.ctx.g.selectAll(b(L)).classed("markmap-selected", !1);
738
- }
739
- _findParent(t) {
740
- if (!this.ctx.state.data) return null;
741
- let e = null;
742
- return R(this.ctx.state.data, (i, o) => {
743
- if (e) return;
744
- const s = i.children || [];
745
- for (let a = 0; a < s.length; a++)
746
- if (s[a] === t) {
747
- e = { parent: i, index: a };
748
- return;
749
- }
750
- o();
751
- }), e;
752
- }
753
- /** Create a blank child INode and append it to parent.children. */
754
- _insertNewChildNode(t) {
755
- var l, h, c;
756
- let e = 0;
757
- R(this.ctx.state.data, (d, u) => {
758
- var f;
759
- ((f = d.state) == null ? void 0 : f.id) > e && (e = d.state.id), u();
760
- });
761
- const i = e + 1, o = (((l = t.state) == null ? void 0 : l.depth) ?? 0) + 1, s = "&nbsp;", a = {
762
- content: s,
763
- children: [],
764
- payload: {},
765
- state: {
766
- id: i,
767
- depth: o,
768
- key: `${(h = t.state) == null ? void 0 : h.id}.${i}` + V(s),
769
- path: [(c = t.state) == null ? void 0 : c.path, i].filter(Boolean).join("."),
770
- rect: { x: 0, y: 0, width: 0, height: 0 },
771
- size: [0, 0]
772
- }
773
- };
774
- return t.children = [...t.children || [], a], this.ctx.options.color(a), a;
775
- }
776
- /**
777
- * Core overlay builder shared by _editNewNode and handleEdit.
778
- *
779
- * @param node - The INode being edited (content will be mutated on save).
780
- * @param contentNode - The inner <div> whose position / style drives the overlay.
781
- * @param opts.initialValue - Starting text in the input ('': new node, textContent: existing).
782
- * @param opts.minWidth - Minimum overlay width in px.
783
- * @param opts.placeholder - Input placeholder (only shown when initialValue is empty).
784
- * @param opts.selectAll - Whether to select all text on focus (true for existing nodes).
785
- * @param opts.onSave - Called after the overlay is torn down on a successful save.
786
- * @param opts.onCancel - Called after the overlay is torn down on cancel / empty input.
787
- */
788
- _openEditOverlay(t, e, i) {
789
- const o = this._getOverlayRoot();
790
- window.getComputedStyle(o).position === "static" && (o.style.position = "relative");
791
- const a = e.getBoundingClientRect(), l = o.getBoundingClientRect(), h = document.createElement("div");
792
- h.className = "markmap-node-edit-overlay", h.style.cssText = `
670
+ Le.version = Fe;
671
+ var Re = (e, t = 0) => (e.y = t, (e.children || []).reduce((t, n) => {
672
+ let [r, i] = t;
673
+ Re(n, e.y + e.ySize);
674
+ let a = (r === 0 ? n.lExt : n.rExt).bottom;
675
+ r !== 0 && Ve(e, r, i);
676
+ let o = Ye(a, r, i);
677
+ return [r + 1, o];
678
+ }, [0, null]), Be(e), Je(e), e), ze = (e, t, n) => {
679
+ t === void 0 && (t = -e.relX - e.prelim, n = 0);
680
+ let r = t + e.relX;
681
+ return e.relX = r + e.prelim - n, e.prelim = 0, e.x = n + e.relX, (e.children || []).forEach((t) => ze(t, r, e.x)), e;
682
+ }, Be = (e) => {
683
+ (e.children || []).reduce((e, t) => {
684
+ let [n, r] = e, i = n + t.shift, a = r + i + t.change;
685
+ return t.relX += a, [i, a];
686
+ }, [0, 0]);
687
+ }, Ve = (e, t, n) => {
688
+ let r = e.children[t - 1], i = e.children[t], a = r, o = r.relX, s = i, c = i.relX, l = !0;
689
+ for (; a && s;) {
690
+ a.bottom > n.lowY && (n = n.next);
691
+ let r = o + a.prelim - (c + s.prelim) + a.xSize / 2 + s.xSize / 2 + a.spacing(s);
692
+ (r > 0 || r < 0 && l) && (c += r, He(i, r), Ue(e, t, n.index, r)), l = !1;
693
+ let u = a.bottom, d = s.bottom;
694
+ u <= d && (a = Ge(a), a && (o += a.relX)), u >= d && (s = We(s), s && (c += s.relX));
695
+ }
696
+ !a && s ? Ke(e, t, s, c) : a && !s && qe(e, t, a, o);
697
+ }, He = (e, t) => {
698
+ e.relX += t, e.lExtRelX += t, e.rExtRelX += t;
699
+ }, Ue = (e, t, n, r) => {
700
+ let i = e.children[t], a = t - n;
701
+ if (a > 1) {
702
+ let t = r / a;
703
+ e.children[n + 1].shift += t, i.shift -= t, i.change -= r - t;
704
+ }
705
+ }, We = (e) => e.hasChildren ? e.firstChild : e.lThr, Ge = (e) => e.hasChildren ? e.lastChild : e.rThr, Ke = (e, t, n, r) => {
706
+ let i = e.firstChild, a = i.lExt, o = e.children[t];
707
+ a.lThr = n;
708
+ let s = r - n.relX - i.lExtRelX;
709
+ a.relX += s, a.prelim -= s, i.lExt = o.lExt, i.lExtRelX = o.lExtRelX;
710
+ }, qe = (e, t, n, r) => {
711
+ let i = e.children[t], a = i.rExt, o = e.children[t - 1];
712
+ a.rThr = n;
713
+ let s = r - n.relX - i.rExtRelX;
714
+ a.relX += s, a.prelim -= s, i.rExt = o.rExt, i.rExtRelX = o.rExtRelX;
715
+ }, Je = (e) => {
716
+ if (e.hasChildren) {
717
+ let t = e.firstChild, n = e.lastChild, r = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
718
+ Object.assign(e, {
719
+ prelim: r,
720
+ lExt: t.lExt,
721
+ lExtRelX: t.lExtRelX,
722
+ rExt: n.rExt,
723
+ rExtRelX: n.rExtRelX
724
+ });
725
+ }
726
+ }, Ye = (e, t, n) => {
727
+ for (; n !== null && e >= n.lowY;) n = n.next;
728
+ return {
729
+ lowY: e,
730
+ index: t,
731
+ next: n
732
+ };
733
+ }, Xe = ".markmap{--markmap-max-width:9999px;--markmap-a-color:#0097e6;--markmap-a-hover-color:#00a8ff;--markmap-code-bg:#f0f0f0;--markmap-code-color:#555;--markmap-highlight-bg:#ffeaa7;--markmap-table-border:1px solid currentColor;--markmap-font:300 16px/20px sans-serif;--markmap-circle-open-bg:#fff;--markmap-text-color:#333;--markmap-highlight-node-bg:#ff02;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-node-hovered>foreignObject>div>div{border:2px solid #d9d9d9;border-radius:14px;padding:2px 6px}.markmap-selected>foreignObject>div>div,.markmap-selected.markmap-node-hovered>foreignObject>div>div{border:2px solid #b4b4b4;border-radius:14px;padding:2px 6px}.markmap-selected>circle{pointer-events:none;opacity:0!important}.markmap-collapse-on-hover .markmap-node>circle{opacity:0;transition:opacity .2s}.markmap-collapse-on-hover .markmap-node:hover>circle{opacity:1}.markmap-foreign{display:inline-block}.markmap-foreign>div>div{padding:4px 6px}.markmap-foreign .markmap-edit-wrapper{background:#fff;border-radius:4px;width:100%;padding:4px;animation:.2s ease-in fadeIn;position:relative;box-shadow:0 2px 8px #00000026}.markmap-foreign .markmap-edit-input{background:#f8f9fa;border:2px solid #4a90e2;border-radius:4px;outline:none;width:100%;padding:8px 12px;font-family:inherit;font-size:14px;transition:all .2s}.markmap-foreign .markmap-edit-input:focus{background:#fff;border-color:#2d7dd2;box-shadow:0 0 0 3px #4a90e21a}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px;padding:.25em;font-size:calc(1em - 2px)}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign>div{width:var(--markmap-max-width);text-align:left}.markmap-foreign>div>div{max-width:var(--markmap-wrap-width,30em);overflow-wrap:break-word;word-break:break-word;white-space:normal;display:inline-block}.markmap-highlight rect{fill:var(--markmap-highlight-node-bg)}.markmap-dark .markmap{--markmap-code-bg:#1a1b26;--markmap-code-color:#ddd;--markmap-circle-open-bg:#444;--markmap-text-color:#eee}@keyframes fadeIn{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}", J = "g.markmap-node", Ze = class {
734
+ constructor(e) {
735
+ this.ctx = e, this.editingNode = null, this.selectedNode = null;
736
+ }
737
+ _getNodeContentEl(e) {
738
+ let t = this.ctx.findElement(e);
739
+ return t && o(t.g).select("foreignObject").select("div").select("div").node() || null;
740
+ }
741
+ _getOverlayRoot() {
742
+ return this.ctx.svg.node()?.parentElement || document.body;
743
+ }
744
+ _positionOverlayToEl(e, t, n) {
745
+ let r = this._getOverlayRoot();
746
+ window.getComputedStyle(r).position === "static" && (r.style.position = "relative");
747
+ let i = t.getBoundingClientRect(), a = r.getBoundingClientRect(), o = n?.dx ?? 0, s = n?.dy ?? 0, c = n?.minW ?? 0, l = n?.minH ?? 0, u = i.left - a.left + o, d = i.top - a.top + s;
748
+ n?.anchor === "br" ? (u = i.right - a.left + o, d = i.bottom - a.top + s) : n?.anchor === "r" && (u = i.right - a.left + o, d = i.top - a.top + s), e.style.left = `${u}px`, e.style.top = `${d}px`, c && (e.style.width = `${Math.max(c, i.width)}px`), l && (e.style.height = `${Math.max(l, i.height)}px`);
749
+ }
750
+ _safeRemoveEl(e) {
751
+ try {
752
+ e.parentNode && e.remove();
753
+ } catch {}
754
+ }
755
+ _clearSelectionCss() {
756
+ this.ctx.options.clickBorder && this.ctx.g.selectAll(G(J)).classed("markmap-selected", !1);
757
+ }
758
+ _findParent(e) {
759
+ if (!this.ctx.state.data) return null;
760
+ let t = null;
761
+ return v(this.ctx.state.data, (n, r) => {
762
+ if (t) return;
763
+ let i = n.children || [];
764
+ for (let r = 0; r < i.length; r++) if (i[r] === e) {
765
+ t = {
766
+ parent: n,
767
+ index: r
768
+ };
769
+ return;
770
+ }
771
+ r();
772
+ }), t;
773
+ }
774
+ /** Create a blank child INode and append it to parent.children. */
775
+ _insertNewChildNode(e) {
776
+ let t = 0;
777
+ v(this.ctx.state.data, (e, n) => {
778
+ e.state?.id > t && (t = e.state.id), n();
779
+ });
780
+ let n = t + 1, r = (e.state?.depth ?? 0) + 1, i = "&nbsp;", a = {
781
+ content: i,
782
+ children: [],
783
+ payload: {},
784
+ state: {
785
+ id: n,
786
+ depth: r,
787
+ key: `${e.state?.id}.${n}` + W(i),
788
+ path: [e.state?.path, n].filter(Boolean).join("."),
789
+ rect: {
790
+ x: 0,
791
+ y: 0,
792
+ width: 0,
793
+ height: 0
794
+ },
795
+ size: [0, 0]
796
+ }
797
+ };
798
+ return e.children = [...e.children || [], a], this.ctx.options.color(a), a;
799
+ }
800
+ /**
801
+ * Core overlay builder shared by _editNewNode and handleEdit.
802
+ *
803
+ * @param node - The INode being edited (content will be mutated on save).
804
+ * @param contentNode - The inner <div> whose position / style drives the overlay.
805
+ * @param opts.initialValue - Starting text in the input ('': new node, textContent: existing).
806
+ * @param opts.minWidth - Minimum overlay width in px.
807
+ * @param opts.placeholder - Input placeholder (only shown when initialValue is empty).
808
+ * @param opts.selectAll - Whether to select all text on focus (true for existing nodes).
809
+ * @param opts.onSave - Called after the overlay is torn down on a successful save.
810
+ * @param opts.onCancel - Called after the overlay is torn down on cancel / empty input.
811
+ */
812
+ _openEditOverlay(e, t, n) {
813
+ let r = this._getOverlayRoot();
814
+ window.getComputedStyle(r).position === "static" && (r.style.position = "relative");
815
+ let i = t.getBoundingClientRect(), a = r.getBoundingClientRect(), o = document.createElement("div");
816
+ o.className = "markmap-node-edit-overlay", o.style.cssText = `
793
817
  position: absolute;
794
- left: ${a.left - l.left}px;
795
- top: ${a.top - l.top}px;
796
- width: ${Math.max(i.minWidth, a.width)}px;
797
- height: ${Math.max(20, a.height)}px;
818
+ left: ${i.left - a.left}px;
819
+ top: ${i.top - a.top}px;
820
+ width: ${Math.max(n.minWidth, i.width)}px;
821
+ height: ${Math.max(20, i.height)}px;
798
822
  z-index: 9999;
799
823
  pointer-events: auto;
800
824
  `;
801
- const c = window.getComputedStyle(e), d = document.createElement("input");
802
- d.type = "text", d.value = i.initialValue, i.placeholder && (d.placeholder = i.placeholder), d.autocomplete = "off", d.spellcheck = !1, d.className = "markmap-node-edit-overlay-input", d.style.cssText = `
825
+ let s = window.getComputedStyle(t), c = document.createElement("input");
826
+ c.type = "text", c.value = n.initialValue, n.placeholder && (c.placeholder = n.placeholder), c.autocomplete = "off", c.spellcheck = !1, c.className = "markmap-node-edit-overlay-input", c.style.cssText = `
803
827
  width: 100%;
804
828
  height: 100%;
805
829
  margin: 0;
@@ -809,118 +833,126 @@ class Me {
809
833
  background: #fff;
810
834
  box-sizing: border-box;
811
835
  outline: none;
812
- font-size: ${c.fontSize};
813
- font-family: ${c.fontFamily};
814
- line-height: ${c.lineHeight};
815
- font-weight: ${c.fontWeight};
816
- letter-spacing: ${c.letterSpacing};
817
- color: ${c.color};
836
+ font-size: ${s.fontSize};
837
+ font-family: ${s.fontFamily};
838
+ line-height: ${s.lineHeight};
839
+ font-weight: ${s.fontWeight};
840
+ letter-spacing: ${s.letterSpacing};
841
+ color: ${s.color};
818
842
  `;
819
- const u = e.style.visibility;
820
- e.style.visibility = "hidden", h.appendChild(d), o.appendChild(h), this.editOverlay = { wrap: h, input: d, contentEl: e, prevVisibility: u }, setTimeout(() => {
821
- d.focus(), i.selectAll && d.select();
822
- }, 0);
823
- const f = (x) => x.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
824
- let g = !1;
825
- const y = (x) => {
826
- g || (g = !0, d.removeEventListener("keydown", v), d.removeEventListener("blur", k), this.editOverlay ? (this.editOverlay.contentEl.style.visibility = this.editOverlay.prevVisibility, this.editOverlay.wrap.remove(), this.editOverlay = void 0) : (e.style.visibility = u, h.remove()), this.editingNode = null, x ? i.onCancel() : i.onSave(f(d.value.trim())));
827
- }, v = (x) => {
828
- if (x.key === "Enter") {
829
- x.preventDefault(), x.stopPropagation();
830
- const _ = d.value.trim();
831
- _ ? (t.content = f(_), y(!1)) : y(!0);
832
- } else x.key === "Escape" && (x.preventDefault(), x.stopPropagation(), y(!0));
833
- }, k = () => {
834
- setTimeout(() => {
835
- if (document.activeElement !== d) {
836
- const x = d.value.trim();
837
- x ? (t.content = f(x), y(!1)) : y(!0);
838
- }
839
- }, 100);
840
- };
841
- d.addEventListener("keydown", v), d.addEventListener("blur", k);
842
- }
843
- /**
844
- * Open an edit overlay for a freshly-inserted node.
845
- * Empty input → confirm saves; blank input → cancels and removes the node from the tree.
846
- */
847
- _editNewNode(t, e) {
848
- const i = this.ctx.findElement(t);
849
- if (!i) return;
850
- this.editingNode = t;
851
- const o = S(i.g).select("foreignObject").select("div").select("div").node();
852
- o && this._openEditOverlay(t, o, {
853
- initialValue: "",
854
- minWidth: 120,
855
- placeholder: this.ctx.options.inputPlaceholder,
856
- selectAll: !1,
857
- onCancel: () => {
858
- e.children = (e.children || []).filter((s) => s !== t), this.hideAddUI(), this.selectedNode = null, this._clearSelectionCss(), this.ctx.renderData();
859
- },
860
- onSave: () => {
861
- var s, a;
862
- (a = (s = this.ctx.options).onNodeAdd) == null || a.call(s, e, t), this.hideAddUI(), this.ctx.renderData().then(() => {
863
- const l = () => {
864
- this.selectedNode = t, this.ctx.options.clickBorder && this.ctx.g.selectAll(b(L)).classed("markmap-selected", (h) => h === t), this.showAddUI(t);
865
- };
866
- this.ctx.options.duration > 0 ? setTimeout(l, this.ctx.options.duration) : l();
867
- });
868
- }
869
- });
870
- }
871
- // ── Public API ───────────────────────────────────────────────────────────
872
- /** Reposition all active overlays after zoom / pan. */
873
- repositionOverlays() {
874
- if (this.addUI) {
875
- const t = this._getNodeContentEl(this.addUI.node);
876
- if (t) {
877
- const e = this.ctx.svg.node(), i = e ? z(e).k : 1, o = Math.round(16 * i), s = Math.round(14 * i);
878
- this.addUI.btn.style.width = `${o}px`, this.addUI.btn.style.height = `${o}px`, this.addUI.btn.style.fontSize = `${s}px`, this._positionOverlayToEl(this.addUI.wrap, t, { anchor: "br", dx: Math.round(14 * i), dy: 0 });
879
- }
880
- }
881
- if (this.addInputUI) {
882
- const t = this._getNodeContentEl(this.addInputUI.node);
883
- if (t) {
884
- this._positionOverlayToEl(this.addInputUI.wrap, t, { anchor: "r", dx: 16, dy: 0 });
885
- const e = 30, i = t.getBoundingClientRect().height, o = parseFloat(this.addInputUI.wrap.style.top) || 0;
886
- this.addInputUI.wrap.style.top = `${o + i / 2 - e / 2}px`;
887
- }
888
- }
889
- if (this.editOverlay) {
890
- const t = this._getOverlayRoot(), e = this.editOverlay.contentEl.getBoundingClientRect(), i = t.getBoundingClientRect();
891
- this.editOverlay.wrap.style.left = `${e.left - i.left}px`, this.editOverlay.wrap.style.top = `${e.top - i.top}px`, this.editOverlay.wrap.style.width = `${Math.max(40, e.width)}px`, this.editOverlay.wrap.style.height = `${Math.max(20, e.height)}px`;
892
- }
893
- }
894
- /** Hide and destroy the + button and any associated input overlay. */
895
- hideAddUI() {
896
- this.addInputUI && (this._safeRemoveEl(this.addInputUI.wrap), this.addInputUI = void 0), this.addUI && (this.addUI.cleanupDoc(), this._safeRemoveEl(this.addUI.wrap), this.addUI = void 0);
897
- }
898
- /** Show the + button anchored to the bottom-right corner of `node`. */
899
- showAddUI(t) {
900
- var f;
901
- if (!this.ctx.options.addable || this.editingNode) return;
902
- const e = this._getNodeContentEl(t);
903
- if (!e) return;
904
- if (((f = this.addUI) == null ? void 0 : f.node) === t) {
905
- this._positionOverlayToEl(this.addUI.wrap, e, { anchor: "br", dx: 14, dy: 0 });
906
- return;
907
- }
908
- this.hideAddUI();
909
- const i = this._getOverlayRoot(), o = document.createElement("div");
910
- o.style.cssText = `
911
- position: absolute;
912
- z-index: 9999;
913
- pointer-events: auto;
914
- `;
915
- const s = this.ctx.svg.node(), a = s ? z(s).k : 1, l = Math.round(16 * a), h = Math.round(14 * a), c = document.createElement("button");
916
- c.type = "button", c.className = "markmap-add-btn", c.textContent = "+", c.style.cssText = `
917
- width: ${l}px;
918
- height: ${l}px;
843
+ let l = t.style.visibility;
844
+ t.style.visibility = "hidden", o.appendChild(c), r.appendChild(o), this.editOverlay = {
845
+ wrap: o,
846
+ input: c,
847
+ contentEl: t,
848
+ prevVisibility: l
849
+ }, setTimeout(() => {
850
+ c.focus(), n.selectAll && c.select();
851
+ }, 0);
852
+ let u = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), d = !1, f = (e) => {
853
+ d || (d = !0, c.removeEventListener("keydown", p), c.removeEventListener("blur", m), this.editOverlay ? (this.editOverlay.contentEl.style.visibility = this.editOverlay.prevVisibility, this.editOverlay.wrap.remove(), this.editOverlay = void 0) : (t.style.visibility = l, o.remove()), this.editingNode = null, e ? n.onCancel() : n.onSave(u(c.value.trim())));
854
+ }, p = (t) => {
855
+ if (t.key === "Enter") {
856
+ t.preventDefault(), t.stopPropagation();
857
+ let n = c.value.trim();
858
+ n ? (e.content = u(n), f(!1)) : f(!0);
859
+ } else t.key === "Escape" && (t.preventDefault(), t.stopPropagation(), f(!0));
860
+ }, m = () => {
861
+ setTimeout(() => {
862
+ if (document.activeElement !== c) {
863
+ let t = c.value.trim();
864
+ t ? (e.content = u(t), f(!1)) : f(!0);
865
+ }
866
+ }, 100);
867
+ };
868
+ c.addEventListener("keydown", p), c.addEventListener("blur", m);
869
+ }
870
+ /**
871
+ * Open an edit overlay for a freshly-inserted node.
872
+ * Empty input → confirm saves; blank input → cancels and removes the node from the tree.
873
+ */
874
+ _editNewNode(e, t) {
875
+ let n = this.ctx.findElement(e);
876
+ if (!n) return;
877
+ this.editingNode = e;
878
+ let r = o(n.g).select("foreignObject").select("div").select("div").node();
879
+ r && this._openEditOverlay(e, r, {
880
+ initialValue: "",
881
+ minWidth: 120,
882
+ placeholder: this.ctx.options.inputPlaceholder,
883
+ selectAll: !1,
884
+ onCancel: () => {
885
+ t.children = (t.children || []).filter((t) => t !== e), this.hideAddUI(), this.selectedNode = null, this._clearSelectionCss(), this.ctx.renderData();
886
+ },
887
+ onSave: () => {
888
+ this.ctx.options.onNodeAdd?.(t, e), this.hideAddUI(), this.ctx.renderData().then(() => {
889
+ let t = () => {
890
+ this.selectedNode = e, this.ctx.options.clickBorder && this.ctx.g.selectAll(G(J)).classed("markmap-selected", (t) => t === e), this.showAddUI(e);
891
+ };
892
+ this.ctx.options.duration > 0 ? setTimeout(t, this.ctx.options.duration) : t();
893
+ });
894
+ }
895
+ });
896
+ }
897
+ /** Reposition all active overlays after zoom / pan. */
898
+ repositionOverlays() {
899
+ if (this.addUI) {
900
+ let e = this._getNodeContentEl(this.addUI.node);
901
+ if (e) {
902
+ let t = this.ctx.svg.node(), n = t ? l(t).k : 1, r = Math.round(16 * n), i = Math.round(14 * n);
903
+ this.addUI.btn.style.width = `${r}px`, this.addUI.btn.style.height = `${r}px`, this.addUI.btn.style.fontSize = `${i}px`, this._positionOverlayToEl(this.addUI.wrap, e, {
904
+ anchor: "br",
905
+ dx: Math.round(14 * n),
906
+ dy: 0
907
+ });
908
+ }
909
+ }
910
+ if (this.addInputUI) {
911
+ let e = this._getNodeContentEl(this.addInputUI.node);
912
+ if (e) {
913
+ this._positionOverlayToEl(this.addInputUI.wrap, e, {
914
+ anchor: "r",
915
+ dx: 16,
916
+ dy: 0
917
+ });
918
+ let t = e.getBoundingClientRect().height, n = parseFloat(this.addInputUI.wrap.style.top) || 0;
919
+ this.addInputUI.wrap.style.top = `${n + t / 2 - 30 / 2}px`;
920
+ }
921
+ }
922
+ if (this.editOverlay) {
923
+ let e = this._getOverlayRoot(), t = this.editOverlay.contentEl.getBoundingClientRect(), n = e.getBoundingClientRect();
924
+ this.editOverlay.wrap.style.left = `${t.left - n.left}px`, this.editOverlay.wrap.style.top = `${t.top - n.top}px`, this.editOverlay.wrap.style.width = `${Math.max(40, t.width)}px`, this.editOverlay.wrap.style.height = `${Math.max(20, t.height)}px`;
925
+ }
926
+ }
927
+ /** Hide and destroy the + button and any associated input overlay. */
928
+ hideAddUI() {
929
+ this.addInputUI &&= (this._safeRemoveEl(this.addInputUI.wrap), void 0), this.addUI &&= (this.addUI.cleanupDoc(), this._safeRemoveEl(this.addUI.wrap), void 0);
930
+ }
931
+ /** Show the + button anchored to the bottom-right corner of `node`. */
932
+ showAddUI(e) {
933
+ if (!this.ctx.options.addable || this.editingNode) return;
934
+ let t = this._getNodeContentEl(e);
935
+ if (!t) return;
936
+ if (this.addUI?.node === e) {
937
+ this._positionOverlayToEl(this.addUI.wrap, t, {
938
+ anchor: "br",
939
+ dx: 14,
940
+ dy: 0
941
+ });
942
+ return;
943
+ }
944
+ this.hideAddUI();
945
+ let n = this._getOverlayRoot(), r = document.createElement("div");
946
+ r.style.cssText = "\n position: absolute;\n z-index: 9999;\n pointer-events: auto;\n ";
947
+ let i = this.ctx.svg.node(), a = i ? l(i).k : 1, o = Math.round(16 * a), s = Math.round(14 * a), c = document.createElement("button");
948
+ c.type = "button", c.className = "markmap-add-btn", c.textContent = "+", c.style.cssText = `
949
+ width: ${o}px;
950
+ height: ${o}px;
919
951
  border-radius: 50%;
920
952
  background: #b4b4b4;
921
953
  color: #fff;
922
954
  font-weight: 600;
923
- font-size: ${h}px;
955
+ font-size: ${s}px;
924
956
  line-height: 1;
925
957
  padding: 0;
926
958
  cursor: pointer;
@@ -931,576 +963,514 @@ class Me {
931
963
  display: flex;
932
964
  align-items: center;
933
965
  justify-content: center;
934
- `, c.addEventListener("click", (g) => {
935
- g.preventDefault(), g.stopPropagation(), this.showAddInput(t);
936
- }), o.style.transform = "translate(-50%, -50%)", o.appendChild(c), i.appendChild(o), this._positionOverlayToEl(o, e, { anchor: "br", dx: Math.round(14 * a), dy: 0 });
937
- const d = (g) => {
938
- var k;
939
- const y = g.target;
940
- if (!y || o.contains(y) || (k = this.addInputUI) != null && k.wrap.contains(y)) return;
941
- const v = this._getNodeContentEl(t);
942
- v && v.contains(y) || this.hideAddUI();
943
- };
944
- document.addEventListener("click", d, !0);
945
- const u = () => document.removeEventListener("click", d, !0);
946
- this.addUI = { node: t, btn: c, wrap: o, cleanupDoc: u };
947
- }
948
- /** Delete `node` from the tree and re-render. */
949
- deleteNode(t) {
950
- if (!this.ctx.options.deletable || !this.ctx.state.data) return;
951
- const e = this._findParent(t);
952
- if (!e) return;
953
- const { parent: i, index: o } = e, s = [...i.children || []];
954
- s.splice(o, 1), i.children = s, this.selectedNode = null, this.hideAddUI(), this._clearSelectionCss(), this.ctx.renderData();
955
- }
956
- /**
957
- * Insert a new sibling node after `sibling`, render it, then open an edit overlay.
958
- * Called when the user presses Enter on a selected node.
959
- */
960
- async showAddSiblingInput(t) {
961
- var u, f, g;
962
- if (!this.ctx.state.data) return;
963
- const e = this._findParent(t);
964
- if (!e) return;
965
- const { parent: i, index: o } = e;
966
- this.hideAddUI();
967
- let s = 0;
968
- R(this.ctx.state.data, (y, v) => {
969
- var k;
970
- ((k = y.state) == null ? void 0 : k.id) > s && (s = y.state.id), v();
971
- });
972
- const a = s + 1, l = ((u = t.state) == null ? void 0 : u.depth) ?? 1, h = "&nbsp;", c = {
973
- content: h,
974
- children: [],
975
- payload: {},
976
- state: {
977
- id: a,
978
- depth: l,
979
- key: `${(f = i.state) == null ? void 0 : f.id}.${a}` + V(h),
980
- path: [(g = i.state) == null ? void 0 : g.path, a].filter(Boolean).join("."),
981
- rect: { x: 0, y: 0, width: 0, height: 0 },
982
- size: [0, 0]
983
- }
984
- }, d = [...i.children || []];
985
- d.splice(o + 1, 0, c), i.children = d, this.ctx.options.color(c), await this.ctx.renderData(), this.ctx.options.duration > 0 && await new Promise((y) => setTimeout(y, this.ctx.options.duration)), this._editNewNode(c, i);
986
- }
987
- /**
988
- * Insert a new child node under `node`, render it, then open an edit overlay.
989
- * Called when the user clicks the + button or presses Tab.
990
- */
991
- async showAddInput(t) {
992
- if (!this.ctx.state.data) return;
993
- this.hideAddUI();
994
- const e = this._insertNewChildNode(t);
995
- await this.ctx.renderData(), this.ctx.options.duration > 0 && await new Promise((i) => setTimeout(i, this.ctx.options.duration)), this._editNewNode(e, t);
996
- }
997
- /**
998
- * Open an edit overlay for an *existing* node.
999
- * Called on double-click. On confirm the node content is updated in-place.
1000
- */
1001
- handleEdit(t, e) {
1002
- if (!this.ctx.options.editable) return;
1003
- t.preventDefault(), t.stopPropagation(), t.stopImmediatePropagation(), this.editingNode && this.saveEdit();
1004
- const i = this.ctx.findElement(e);
1005
- if (!i) return;
1006
- const o = S(i.g).select("foreignObject").select("div").select("div").node();
1007
- if (!o) return;
1008
- if (this.editOverlay) {
1009
- try {
1010
- this.editOverlay.contentEl.style.visibility = this.editOverlay.prevVisibility, this.editOverlay.wrap.remove();
1011
- } catch {
1012
- }
1013
- this.editOverlay = void 0;
1014
- }
1015
- const s = e.content;
1016
- this.editingNode = e, this._openEditOverlay(e, o, {
1017
- initialValue: o.textContent || "",
1018
- minWidth: 40,
1019
- selectAll: !0,
1020
- onCancel: () => {
1021
- e.content = s, this.ctx.renderData();
1022
- },
1023
- onSave: (a) => {
1024
- var l, h;
1025
- (h = (l = this.ctx.options).onNodeEdit) == null || h.call(l, e, a), this.hideAddUI(), this.ctx.renderData().then(() => {
1026
- if (!this.ctx.options.addable) return;
1027
- const c = () => {
1028
- this.selectedNode = e, this.ctx.options.clickBorder && this.ctx.g.selectAll(b(L)).classed("markmap-selected", (d) => d === e), this.showAddUI(e);
1029
- };
1030
- this.ctx.options.duration > 0 ? setTimeout(c, this.ctx.options.duration) : c();
1031
- });
1032
- }
1033
- });
1034
- }
1035
- /** Immediately discard any in-progress edit overlay without saving. */
1036
- saveEdit() {
1037
- if (this.editOverlay) {
1038
- const { input: t, contentEl: e, prevVisibility: i, wrap: o } = this.editOverlay;
1039
- t.remove(), e.style.visibility = i, o.remove(), this.editOverlay = void 0;
1040
- }
1041
- this.editingNode && (this.editingNode = null);
1042
- }
1043
- }
1044
- const We = wt, A = "g.markmap-node", Be = "path.markmap-link", De = "g.markmap-highlight", F = $t();
1045
- function ct(n, t) {
1046
- const e = At(n, t);
1047
- return n[e];
1048
- }
1049
- function dt(n) {
1050
- n.stopPropagation();
966
+ `, c.addEventListener("click", (t) => {
967
+ t.preventDefault(), t.stopPropagation(), this.showAddInput(e);
968
+ }), r.style.transform = "translate(-50%, -50%)", r.appendChild(c), n.appendChild(r), this._positionOverlayToEl(r, t, {
969
+ anchor: "br",
970
+ dx: Math.round(14 * a),
971
+ dy: 0
972
+ });
973
+ let u = (t) => {
974
+ let n = t.target;
975
+ if (!n || r.contains(n) || this.addInputUI?.wrap.contains(n)) return;
976
+ let i = this._getNodeContentEl(e);
977
+ i && i.contains(n) || this.hideAddUI();
978
+ };
979
+ document.addEventListener("click", u, !0), this.addUI = {
980
+ node: e,
981
+ btn: c,
982
+ wrap: r,
983
+ cleanupDoc: () => document.removeEventListener("click", u, !0)
984
+ };
985
+ }
986
+ /** Delete `node` from the tree and re-render. */
987
+ deleteNode(e) {
988
+ if (!this.ctx.options.deletable || !this.ctx.state.data) return;
989
+ let t = this._findParent(e);
990
+ if (!t) return;
991
+ let { parent: n, index: r } = t, i = [...n.children || []];
992
+ i.splice(r, 1), n.children = i, this.selectedNode = null, this.hideAddUI(), this._clearSelectionCss(), this.ctx.renderData();
993
+ }
994
+ /**
995
+ * Insert a new sibling node after `sibling`, render it, then open an edit overlay.
996
+ * Called when the user presses Enter on a selected node.
997
+ */
998
+ async showAddSiblingInput(e) {
999
+ if (!this.ctx.state.data) return;
1000
+ let t = this._findParent(e);
1001
+ if (!t) return;
1002
+ let { parent: n, index: r } = t;
1003
+ this.hideAddUI();
1004
+ let i = 0;
1005
+ v(this.ctx.state.data, (e, t) => {
1006
+ e.state?.id > i && (i = e.state.id), t();
1007
+ });
1008
+ let a = i + 1, o = e.state?.depth ?? 1, s = "&nbsp;", c = {
1009
+ content: s,
1010
+ children: [],
1011
+ payload: {},
1012
+ state: {
1013
+ id: a,
1014
+ depth: o,
1015
+ key: `${n.state?.id}.${a}` + W(s),
1016
+ path: [n.state?.path, a].filter(Boolean).join("."),
1017
+ rect: {
1018
+ x: 0,
1019
+ y: 0,
1020
+ width: 0,
1021
+ height: 0
1022
+ },
1023
+ size: [0, 0]
1024
+ }
1025
+ }, l = [...n.children || []];
1026
+ l.splice(r + 1, 0, c), n.children = l, this.ctx.options.color(c), await this.ctx.renderData(), this.ctx.options.duration > 0 && await new Promise((e) => setTimeout(e, this.ctx.options.duration)), this._editNewNode(c, n);
1027
+ }
1028
+ /**
1029
+ * Insert a new child node under `node`, render it, then open an edit overlay.
1030
+ * Called when the user clicks the + button or presses Tab.
1031
+ */
1032
+ async showAddInput(e) {
1033
+ if (!this.ctx.state.data) return;
1034
+ this.hideAddUI();
1035
+ let t = this._insertNewChildNode(e);
1036
+ await this.ctx.renderData(), this.ctx.options.duration > 0 && await new Promise((e) => setTimeout(e, this.ctx.options.duration)), this._editNewNode(t, e);
1037
+ }
1038
+ /**
1039
+ * Open an edit overlay for an *existing* node.
1040
+ * Called on double-click. On confirm the node content is updated in-place.
1041
+ */
1042
+ handleEdit(e, t) {
1043
+ if (!this.ctx.options.editable) return;
1044
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), this.editingNode && this.saveEdit();
1045
+ let n = this.ctx.findElement(t);
1046
+ if (!n) return;
1047
+ let r = o(n.g).select("foreignObject").select("div").select("div").node();
1048
+ if (!r) return;
1049
+ if (this.editOverlay) {
1050
+ try {
1051
+ this.editOverlay.contentEl.style.visibility = this.editOverlay.prevVisibility, this.editOverlay.wrap.remove();
1052
+ } catch {}
1053
+ this.editOverlay = void 0;
1054
+ }
1055
+ let i = t.content;
1056
+ this.editingNode = t, this._openEditOverlay(t, r, {
1057
+ initialValue: r.textContent || "",
1058
+ minWidth: 40,
1059
+ selectAll: !0,
1060
+ onCancel: () => {
1061
+ t.content = i, this.ctx.renderData();
1062
+ },
1063
+ onSave: (e) => {
1064
+ this.ctx.options.onNodeEdit?.(t, e), this.hideAddUI(), this.ctx.renderData().then(() => {
1065
+ if (!this.ctx.options.addable) return;
1066
+ let e = () => {
1067
+ this.selectedNode = t, this.ctx.options.clickBorder && this.ctx.g.selectAll(G(J)).classed("markmap-selected", (e) => e === t), this.showAddUI(t);
1068
+ };
1069
+ this.ctx.options.duration > 0 ? setTimeout(e, this.ctx.options.duration) : e();
1070
+ });
1071
+ }
1072
+ });
1073
+ }
1074
+ /** Immediately discard any in-progress edit overlay without saving. */
1075
+ saveEdit() {
1076
+ if (this.editOverlay) {
1077
+ let { input: e, contentEl: t, prevVisibility: n, wrap: r } = this.editOverlay;
1078
+ e.remove(), t.style.visibility = n, r.remove(), this.editOverlay = void 0;
1079
+ }
1080
+ this.editingNode &&= null;
1081
+ }
1082
+ };
1083
+ const Qe = Xe;
1084
+ var Y = "g.markmap-node", $e = "path.markmap-link", et = "g.markmap-highlight", X = e();
1085
+ function Z(e, t) {
1086
+ return e[r(e, t)];
1051
1087
  }
1052
- const Pe = new Tt();
1053
- class Et {
1054
- constructor(t, e) {
1055
- this.options = { ...yt }, this._disposeList = [], this.handleZoom = (o) => {
1056
- const { transform: s } = o;
1057
- this.g.attr("transform", s), this._actions.repositionOverlays();
1058
- }, this.handlePan = (o) => {
1059
- o.preventDefault();
1060
- const s = z(this.svg.node()), a = s.translate(
1061
- -o.deltaX / s.k,
1062
- -o.deltaY / s.k
1063
- );
1064
- this.svg.call(this.zoom.transform, a);
1065
- }, this.handleClick = (o, s) => {
1066
- let a = this.options.toggleRecursively;
1067
- (gt ? o.metaKey : o.ctrlKey) && (a = !a), this.toggleNode(s, a);
1068
- }, this.ensureView = this.ensureVisible, this.svg = t.datum ? t : S(t), this.styleNode = this.svg.append("style"), this.zoom = zt().filter((o) => this.options.scrollForPan && o.type === "wheel" ? o.ctrlKey && !o.button : (!o.ctrlKey || o.type === "wheel") && !o.button).on("zoom", this.handleZoom), this.setOptions(e), this.state = {
1069
- id: this.options.id || this.svg.attr("id") || Bt(),
1070
- rect: { x1: 0, y1: 0, x2: 0, y2: 0 }
1071
- }, this.g = this.svg.append("g"), this.g.append("g").attr("class", "markmap-highlight"), this._actions = new Me(this), this.svg.on("click", () => {
1072
- this._actions.selectedNode && (this._actions.selectedNode = null, this.options.clickBorder && this.g.selectAll(b(A)).classed("markmap-selected", !1), this._actions.hideAddUI());
1073
- });
1074
- const i = (o) => {
1075
- var a;
1076
- if (!this._actions.selectedNode || this._actions.editingNode || this._actions.editOverlay || this._actions.addInputUI) return;
1077
- const s = (a = document.activeElement) == null ? void 0 : a.tagName;
1078
- s === "INPUT" || s === "TEXTAREA" || (o.key === "Tab" && this.options.addable ? (o.preventDefault(), o.stopPropagation(), this._actions.showAddInput(this._actions.selectedNode)) : o.key === "Enter" && this.options.addable ? (o.preventDefault(), o.stopPropagation(), this._actions.showAddSiblingInput(this._actions.selectedNode)) : (o.key === "Delete" || o.key === "Backspace") && this.options.deletable && (o.preventDefault(), o.stopPropagation(), this._actions.deleteNode(this._actions.selectedNode)));
1079
- };
1080
- document.addEventListener("keydown", i), this._disposeList.push(() => document.removeEventListener("keydown", i)), this._observer = new ResizeObserver(
1081
- jt(() => {
1082
- this._actions.editingNode || this.renderData();
1083
- }, 100)
1084
- ), this._disposeList.push(
1085
- Pe.tap(() => {
1086
- this.setData();
1087
- }),
1088
- () => this._actions.hideAddUI(),
1089
- () => this._observer.disconnect()
1090
- );
1091
- }
1092
- getStyleContent() {
1093
- const { style: t } = this.options, { id: e } = this.state, i = typeof t == "function" ? t(e) : "";
1094
- return [this.options.embedGlobalCSS && wt, i].filter(Boolean).join(`
1095
- `);
1096
- }
1097
- updateStyle() {
1098
- const t = Dt("", "markmap", this.state.id), e = this.options.collapseOnHover ? "markmap-collapse-on-hover" : "";
1099
- this.svg.attr("class", [t, e].filter(Boolean).join(" "));
1100
- const i = this.getStyleContent();
1101
- this.styleNode.text(i);
1102
- }
1103
- async toggleNode(t, e = !1) {
1104
- var o, s;
1105
- const i = (o = t.payload) != null && o.fold ? 0 : 1;
1106
- e ? R(t, (a, l) => {
1107
- a.payload = {
1108
- ...a.payload,
1109
- fold: i
1110
- }, l();
1111
- }) : t.payload = {
1112
- ...t.payload,
1113
- fold: (s = t.payload) != null && s.fold ? 0 : 1
1114
- }, await this.renderData(t);
1115
- }
1116
- _initializeData(t) {
1117
- let e = 0;
1118
- const { color: i, initialExpandLevel: o } = this.options;
1119
- let s = 0, a = 0;
1120
- return R(t, (l, h, c) => {
1121
- var u, f, g, y;
1122
- a += 1, l.children = (u = l.children) == null ? void 0 : u.map((v) => ({ ...v })), e += 1, l.state = {
1123
- ...l.state,
1124
- depth: a,
1125
- id: e,
1126
- rect: {
1127
- x: 0,
1128
- y: 0,
1129
- width: 0,
1130
- height: 0
1131
- },
1132
- size: [0, 0]
1133
- }, l.state.key = [(f = c == null ? void 0 : c.state) == null ? void 0 : f.id, l.state.id].filter(Boolean).join(".") + V(l.content), l.state.path = [(g = c == null ? void 0 : c.state) == null ? void 0 : g.path, l.state.id].filter(Boolean).join("."), i(l);
1134
- const d = ((y = l.payload) == null ? void 0 : y.fold) === 2;
1135
- d ? s += 1 : (s || o >= 0 && l.state.depth >= o) && (l.payload = { ...l.payload, fold: 1 }), h(), d && (s -= 1), a -= 1;
1136
- }), t;
1137
- }
1138
- _relayout() {
1139
- if (!this.state.data) return;
1140
- this.g.selectAll(b(A)).selectAll(
1141
- b("foreignObject")
1142
- ).each(function(c) {
1143
- var f;
1144
- const d = (f = this.firstChild) == null ? void 0 : f.firstChild, u = [d.scrollWidth, d.scrollHeight];
1145
- c.state.size = u;
1146
- });
1147
- const { lineWidth: t, paddingX: e, spacingHorizontal: i, spacingVertical: o } = this.options, s = (c) => {
1148
- var u;
1149
- return (u = c.payload) != null && u.fold ? i : (c.children || []).length === 1 ? Math.round(i / 2) : i;
1150
- }, a = vt({}).children((c) => {
1151
- var d;
1152
- if (!((d = c.payload) != null && d.fold)) return c.children;
1153
- }).nodeSize((c) => {
1154
- const [d, u] = c.data.state.size, f = s(c.data);
1155
- return [u, d + (d ? e * 2 : 0) + f];
1156
- }).spacing((c, d) => (c.parent === d.parent ? o : o * 2) + t(c.data)), l = a.hierarchy(this.state.data);
1157
- a(l);
1158
- const h = l.descendants();
1159
- h.forEach((c) => {
1160
- const d = c.data, u = s(d);
1161
- d.state.rect = {
1162
- x: c.y,
1163
- y: c.x - c.xSize / 2,
1164
- width: c.ySize - u,
1165
- height: c.xSize
1166
- };
1167
- }), this.state.rect = {
1168
- x1: ot(h, (c) => c.data.state.rect.x) || 0,
1169
- y1: ot(h, (c) => c.data.state.rect.y) || 0,
1170
- x2: nt(
1171
- h,
1172
- (c) => c.data.state.rect.x + c.data.state.rect.width
1173
- ) || 0,
1174
- y2: nt(
1175
- h,
1176
- (c) => c.data.state.rect.y + c.data.state.rect.height
1177
- ) || 0
1178
- };
1179
- }
1180
- setOptions(t) {
1181
- const e = (t == null ? void 0 : t.mode) === "display" ? { editable: !1, addable: !1, deletable: !1, collapseOnHover: !1, hoverBorder: !1, clickBorder: !1 } : (t == null ? void 0 : t.mode) === "editable" ? { editable: !0, addable: !0, deletable: !0, collapseOnHover: !0, hoverBorder: !0, clickBorder: !0 } : {};
1182
- this.options = {
1183
- ...this.options,
1184
- ...e,
1185
- ...t
1186
- }, this.options.zoom ? this.svg.call(this.zoom) : this.svg.on(".zoom", null), this.options.pan ? this.svg.on("wheel", this.handlePan) : this.svg.on("wheel", null);
1187
- }
1188
- async setData(t, e) {
1189
- e && this.setOptions(e), t && (this.state.data = this._initializeData(t)), this.state.data && (this.updateStyle(), await this.renderData());
1190
- }
1191
- getData(t) {
1192
- const e = this.state.data;
1193
- if (!e) return;
1194
- if (!t) return e;
1195
- const i = (o) => ({
1196
- content: o.content,
1197
- payload: o.payload,
1198
- children: (o.children || []).map(i)
1199
- });
1200
- return i(e);
1201
- }
1202
- async setHighlight(t) {
1203
- this.state.highlight = t || void 0, await this.renderData();
1204
- }
1205
- _getHighlightRect(t) {
1206
- const e = this.svg.node(), o = 4 / z(e).k, s = {
1207
- ...t.state.rect
1208
- };
1209
- return s.x -= o, s.y -= o, s.width += 2 * o, s.height += 2 * o, s;
1210
- }
1211
- async renderData(t) {
1212
- const { paddingX: e, autoFit: i, color: o, maxWidth: s, lineWidth: a } = this.options, l = this.state.data;
1213
- if (!l) return;
1214
- const h = {}, c = {}, d = [];
1215
- R(l, (r, p, m) => {
1216
- var w;
1217
- (w = r.payload) != null && w.fold || p(), h[r.state.id] = r, m && (c[r.state.id] = m.state.id), d.push(r);
1218
- });
1219
- const u = {}, f = {}, g = (r) => {
1220
- !r || u[r.state.id] || R(r, (p, m) => {
1221
- u[p.state.id] = r.state.id, m();
1222
- });
1223
- }, y = (r) => f[u[r.state.id]] || l.state.rect, v = (r) => (h[u[r.state.id]] || l).state.rect;
1224
- f[l.state.id] = l.state.rect, t && g(t);
1225
- let { highlight: k } = this.state;
1226
- k && !h[k.state.id] && (k = void 0);
1227
- let x = this.g.selectAll(b(De)).selectAll(b("rect")).data(k ? [this._getHighlightRect(k)] : []).join("rect").attr("x", (r) => r.x).attr("y", (r) => r.y).attr("width", (r) => r.width).attr("height", (r) => r.height);
1228
- const _ = this.g.selectAll(b(A)).each((r) => {
1229
- f[r.state.id] = r.state.rect;
1230
- }).data(d, (r) => r.state.key), G = _.enter().append("g").attr("data-depth", (r) => r.state.depth).attr("data-path", (r) => r.state.path).each((r) => {
1231
- g(h[c[r.state.id]]);
1232
- }), T = _.exit().each((r) => {
1233
- g(h[c[r.state.id]]);
1234
- }), M = _.merge(G).attr(
1235
- "class",
1236
- (r) => {
1237
- var p;
1238
- return ["markmap-node", ((p = r.payload) == null ? void 0 : p.fold) && "markmap-fold"].filter(Boolean).join(" ");
1239
- }
1240
- ), q = M.selectAll(b("line")).data(
1241
- (r) => [r],
1242
- (r) => r.state.key
1243
- ), J = q.enter().append("line").attr("stroke", (r) => o(r)).attr("stroke-width", 0), Z = q.merge(J), j = M.selectAll(b("circle")).data(
1244
- (r) => {
1245
- var p;
1246
- return (p = r.children) != null && p.length ? [r] : [];
1247
- },
1248
- (r) => r.state.key
1249
- );
1250
- this.transition(j.exit()).attr("r", 0).attr("stroke-width", 0).remove();
1251
- const Q = j.enter().append("circle").attr("stroke-width", 0).attr("r", 0).on("click", (r, p) => this.handleClick(r, p)).on("mousedown", dt).merge(j).attr("stroke", (r) => o(r)).attr(
1252
- "fill",
1253
- (r) => {
1254
- var p;
1255
- return (p = r.payload) != null && p.fold && r.children ? o(r) : "var(--markmap-circle-open-bg)";
1256
- }
1257
- ), tt = this._observer, et = M.selectAll(b("foreignObject")).data(
1258
- (r) => [r],
1259
- (r) => r.state.key
1260
- ), X = et.enter().append("foreignObject").attr("class", "markmap-foreign").attr("x", e).attr("y", 0).style("opacity", 0).on("mousedown", dt).on("dblclick", (r, p) => {
1261
- r.preventDefault(), r.stopPropagation(), r.stopImmediatePropagation(), this._actions.handleEdit(r, p);
1262
- });
1263
- X.append("xhtml:div").append("xhtml:div").html((r) => r.content).attr("xmlns", "http://www.w3.org/1999/xhtml"), X.each(function() {
1264
- var p;
1265
- const r = (p = this.firstChild) == null ? void 0 : p.firstChild;
1266
- tt.observe(r);
1267
- });
1268
- const it = T.selectAll(
1269
- b("foreignObject")
1270
- );
1271
- it.each(function() {
1272
- var p;
1273
- const r = (p = this.firstChild) == null ? void 0 : p.firstChild;
1274
- tt.unobserve(r);
1275
- });
1276
- const O = X.merge(et);
1277
- O.on("dblclick", (r, p) => {
1278
- r.preventDefault(), r.stopPropagation(), r.stopImmediatePropagation(), this._actions.handleEdit(r, p);
1279
- }), O.on("mouseenter", (r, p) => {
1280
- var N, I;
1281
- if (!this.options.hoverBorder) return;
1282
- const m = this.findElement(p);
1283
- if (!m) return;
1284
- const w = (I = (N = S(m.g).select("foreignObject").node()) == null ? void 0 : N.firstChild) == null ? void 0 : I.firstChild;
1285
- if (!w) return;
1286
- const E = w.getBoundingClientRect();
1287
- r.clientX >= E.left && r.clientX <= E.right && r.clientY >= E.top && r.clientY <= E.bottom && S(m.g).classed("markmap-node-hovered", !0);
1288
- }), O.on("mousemove", (r, p) => {
1289
- var I, C;
1290
- if (!this.options.hoverBorder) return;
1291
- const m = this.findElement(p);
1292
- if (!m) return;
1293
- const w = (C = (I = S(m.g).select("foreignObject").node()) == null ? void 0 : I.firstChild) == null ? void 0 : C.firstChild;
1294
- if (!w) return;
1295
- const E = w.getBoundingClientRect(), N = r.clientX >= E.left && r.clientX <= E.right && r.clientY >= E.top && r.clientY <= E.bottom;
1296
- S(m.g).classed("markmap-node-hovered", N);
1297
- }), O.on("mouseleave", (r, p) => {
1298
- if (!this.options.hoverBorder) return;
1299
- const m = this.findElement(p);
1300
- m && S(m.g).classed("markmap-node-hovered", !1);
1301
- }), O.on("click", (r, p) => {
1302
- var N, I;
1303
- if (this._actions.editingNode || this._actions.editOverlay) return;
1304
- r.stopPropagation();
1305
- const m = this.findElement(p), w = m ? (I = (N = S(m.g).select("foreignObject").node()) == null ? void 0 : N.firstChild) == null ? void 0 : I.firstChild : null;
1306
- (() => {
1307
- if (!w) return !1;
1308
- const C = w.getBoundingClientRect();
1309
- return r.clientX >= C.left && r.clientX <= C.right && r.clientY >= C.top && r.clientY <= C.bottom;
1310
- })() && (this._actions.selectedNode = p, this.options.clickBorder && this.g.selectAll(b(A)).classed("markmap-selected", (C) => C === p), this.options.addable && this._actions.showAddUI(p));
1311
- }), O.select("div").select("div").html((r) => r.content);
1312
- const St = d.flatMap(
1313
- (r) => {
1314
- var p;
1315
- return (p = r.payload) != null && p.fold ? [] : r.children.map((m) => ({ source: r, target: m }));
1316
- }
1317
- ), U = this.g.selectAll(b(Be)).data(St, (r) => r.target.state.key), Ct = U.exit(), _t = U.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (r) => r.target.state.depth).attr("data-path", (r) => r.target.state.path).attr("d", (r) => {
1318
- const p = y(r.target), m = [
1319
- p.x + p.width,
1320
- p.y + p.height
1321
- ];
1322
- return F({ source: m, target: m });
1323
- }).attr("stroke-width", 0).merge(U);
1324
- this.svg.style(
1325
- "--markmap-max-width",
1326
- s ? `${s}px` : null
1327
- ), await new Promise(requestAnimationFrame), this._relayout(), x = x.data(k ? [this._getHighlightRect(k)] : []).join("rect"), this.transition(x).attr("x", (r) => r.x).attr("y", (r) => r.y).attr("width", (r) => r.width).attr("height", (r) => r.height), G.attr("transform", (r) => {
1328
- const p = y(r);
1329
- return `translate(${p.x + p.width - r.state.rect.width},${p.y + p.height - r.state.rect.height})`;
1330
- }), this.transition(T).attr("transform", (r) => {
1331
- const p = v(r), m = p.x + p.width - r.state.rect.width, w = p.y + p.height - r.state.rect.height;
1332
- return `translate(${m},${w})`;
1333
- }).remove(), this.transition(M).attr(
1334
- "transform",
1335
- (r) => `translate(${r.state.rect.x},${r.state.rect.y})`
1336
- );
1337
- const Ot = T.selectAll(
1338
- b("line")
1339
- );
1340
- this.transition(Ot).attr("x1", (r) => r.state.rect.width).attr("stroke-width", 0), J.attr("x1", (r) => r.state.rect.width).attr("x2", (r) => r.state.rect.width), Z.attr("y1", (r) => r.state.rect.height + a(r) / 2).attr("y2", (r) => r.state.rect.height + a(r) / 2), this.transition(Z).attr("x1", -1).attr("x2", (r) => r.state.rect.width + 2).attr("stroke", (r) => o(r)).attr("stroke-width", a);
1341
- const It = T.selectAll(
1342
- b("circle")
1343
- );
1344
- this.transition(It).attr("r", 0).attr("stroke-width", 0), Q.attr("cx", (r) => r.state.rect.width + 4).attr("cy", (r) => r.state.rect.height + a(r) / 2), this.transition(Q).attr("r", 6).attr("stroke-width", 1.5), this.transition(it).style("opacity", 0), O.attr("width", (r) => Math.max(0, r.state.rect.width - e * 2 + 16)).attr("height", (r) => r.state.rect.height), this.transition(O).style("opacity", 1), this.transition(Ct).attr("d", (r) => {
1345
- const p = v(r.target), m = [
1346
- p.x + p.width,
1347
- p.y + p.height + a(r.target) / 2
1348
- ];
1349
- return F({ source: m, target: m });
1350
- }).attr("stroke-width", 0).remove(), this.transition(_t).attr("stroke", (r) => o(r.target)).attr("stroke-width", (r) => a(r.target)).attr("d", (r) => {
1351
- const p = r.source, m = r.target, w = [
1352
- p.state.rect.x + p.state.rect.width,
1353
- p.state.rect.y + p.state.rect.height + a(p) / 2
1354
- ], E = [
1355
- m.state.rect.x,
1356
- m.state.rect.y + m.state.rect.height + a(m) / 2
1357
- ];
1358
- return F({ source: w, target: E });
1359
- }), i && this.fit();
1360
- }
1361
- transition(t) {
1362
- const { duration: e } = this.options;
1363
- return t.transition().duration(e);
1364
- }
1365
- /**
1366
- * Fit the content to the viewport.
1367
- */
1368
- async fit(t = this.options.maxInitialScale) {
1369
- const e = this.svg.node(), { width: i, height: o } = e.getBoundingClientRect(), { fitRatio: s } = this.options, { x1: a, y1: l, x2: h, y2: c } = this.state.rect, d = h - a, u = c - l, f = Math.min(
1370
- i / d * s,
1371
- o / u * s,
1372
- t
1373
- ), g = Rt.translate(
1374
- (i - d * f) / 2 - a * f,
1375
- (o - u * f) / 2 - l * f
1376
- ).scale(f);
1377
- return this.transition(this.svg).call(this.zoom.transform, g).end().catch(B);
1378
- }
1379
- findElement(t) {
1380
- let e;
1381
- return this.g.selectAll(b(A)).each(function(o) {
1382
- o === t && (e = {
1383
- data: o,
1384
- g: this
1385
- });
1386
- }), e;
1387
- }
1388
- /**
1389
- * Pan the content to make the provided node visible in the viewport.
1390
- */
1391
- async ensureVisible(t, e) {
1392
- var k;
1393
- const i = (k = this.findElement(t)) == null ? void 0 : k.data;
1394
- if (!i) return;
1395
- const o = this.svg.node(), s = o.getBoundingClientRect(), a = z(o), [l, h] = [
1396
- i.state.rect.x,
1397
- i.state.rect.x + i.state.rect.width + 2
1398
- ].map((x) => x * a.k + a.x), [c, d] = [
1399
- i.state.rect.y,
1400
- i.state.rect.y + i.state.rect.height
1401
- ].map((x) => x * a.k + a.y), u = {
1402
- left: 0,
1403
- right: 0,
1404
- top: 0,
1405
- bottom: 0,
1406
- ...e
1407
- }, f = [u.left - l, s.width - u.right - h], g = [u.top - c, s.height - u.bottom - d], y = f[0] * f[1] > 0 ? ct(f, Math.abs) / a.k : 0, v = g[0] * g[1] > 0 ? ct(g, Math.abs) / a.k : 0;
1408
- if (y || v) {
1409
- const x = a.translate(y, v);
1410
- return this.transition(this.svg).call(this.zoom.transform, x).end().catch(B);
1411
- }
1412
- }
1413
- async centerNode(t, e) {
1414
- var y;
1415
- const i = (y = this.findElement(t)) == null ? void 0 : y.data;
1416
- if (!i) return;
1417
- const o = this.svg.node(), s = o.getBoundingClientRect(), a = z(o), l = (i.state.rect.x + i.state.rect.width / 2) * a.k + a.x, h = (i.state.rect.y + i.state.rect.height / 2) * a.k + a.y, c = {
1418
- left: 0,
1419
- right: 0,
1420
- top: 0,
1421
- bottom: 0,
1422
- ...e
1423
- }, d = (c.left + s.width - c.right) / 2, u = (c.top + s.height - c.bottom) / 2, f = (d - l) / a.k, g = (u - h) / a.k;
1424
- if (f || g) {
1425
- const v = a.translate(f, g);
1426
- return this.transition(this.svg).call(this.zoom.transform, v).end().catch(B);
1427
- }
1428
- }
1429
- /**
1430
- * Scale content with it pinned at the center of the viewport.
1431
- */
1432
- async rescale(t) {
1433
- const e = this.svg.node(), { width: i, height: o } = e.getBoundingClientRect(), s = i / 2, a = o / 2, l = z(e), h = l.translate(
1434
- (s - l.x) * (1 - t) / l.k,
1435
- (a - l.y) * (1 - t) / l.k
1436
- ).scale(t);
1437
- return this.transition(this.svg).call(this.zoom.transform, h).end().catch(B);
1438
- }
1439
- destroy() {
1440
- this.svg.on(".zoom", null), this.svg.html(null), this._disposeList.forEach((t) => {
1441
- t();
1442
- });
1443
- }
1444
- static create(t, e, i = null) {
1445
- const o = new Et(t, e);
1446
- return i && o.setData(i).then(() => {
1447
- o.fit();
1448
- }), o;
1449
- }
1088
+ function tt(e) {
1089
+ e.stopPropagation();
1450
1090
  }
1451
- function $(n) {
1452
- if (!n) return "";
1453
- let t = n;
1454
- return t = t.replace(
1455
- /<img(?=[^>]*?\bsrc="([^"]*)")(?=[^>]*?\balt="([^"]*)")(?=[^>]*?\btitle="([^"]*)")?[^>]*?\/?>/gi,
1456
- (e, i, o, s) => s ? `![${o}](${i} "${s}")` : `![${o}](${i})`
1457
- ), t = t.replace(
1458
- /<img\s[^>]*?\/?>/gi,
1459
- (e) => {
1460
- const i = (e.match(/\bsrc="([^"]*)"/) || [])[1] ?? "", o = (e.match(/\balt="([^"]*)"/) || [])[1] ?? "", s = (e.match(/\btitle="([^"]*)"/) || [])[1];
1461
- return s ? `![${o}](${i} "${s}")` : `![${o}](${i})`;
1462
- }
1463
- ), t = t.replace(
1464
- /<a\s[^>]*?href="([^"]*)"[^>]*?>([\s\S]*?)<\/a>/gi,
1465
- (e, i, o) => {
1466
- const s = (e.match(/\btitle="([^"]*)"/) || [])[1], a = $(o);
1467
- return s ? `[${a}](${i} "${s}")` : `[${a}](${i})`;
1468
- }
1469
- ), t = t.replace(/<strong>([\s\S]*?)<\/strong>/gi, (e, i) => `**${$(i)}**`), t = t.replace(/<b>([\s\S]*?)<\/b>/gi, (e, i) => `**${$(i)}**`), t = t.replace(/<em>([\s\S]*?)<\/em>/gi, (e, i) => `*${$(i)}*`), t = t.replace(/<i>([\s\S]*?)<\/i>/gi, (e, i) => `*${$(i)}*`), t = t.replace(/<(?:del|s)>([\s\S]*?)<\/(?:del|s)>/gi, (e, i) => `~~${$(i)}~~`), t = t.replace(/<code>([\s\S]*?)<\/code>/gi, (e, i) => "`" + i.replace(/&#x([0-9a-f]+);/gi, (s, a) => String.fromCodePoint(parseInt(a, 16))).replace(/&#([0-9]+);/g, (s, a) => String.fromCodePoint(parseInt(a, 10))).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'") + "`"), t = t.replace(/<br\s*\/?>/gi, `
1470
- `), t = t.replace(/<[^>]+>/g, ""), t = t.replace(/&#x([0-9a-f]+);/gi, (e, i) => String.fromCodePoint(parseInt(i, 16))).replace(/&#([0-9]+);/g, (e, i) => String.fromCodePoint(parseInt(i, 10))).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " "), t;
1091
+ /**
1092
+ * A global hook to refresh all markmaps when called.
1093
+ */
1094
+ const Q = new p();
1095
+ var nt = class e {
1096
+ constructor(e, t) {
1097
+ this.options = { ...U }, this._disposeList = [], this.handleZoom = (e) => {
1098
+ let { transform: t } = e;
1099
+ this.g.attr("transform", t), this._actions.repositionOverlays();
1100
+ }, this.handlePan = (e) => {
1101
+ e.preventDefault();
1102
+ let t = l(this.svg.node()), n = t.translate(-e.deltaX / t.k, -e.deltaY / t.k);
1103
+ this.svg.call(this.zoom.transform, n);
1104
+ }, this.handleClick = (e, t) => {
1105
+ let n = this.options.toggleRecursively;
1106
+ (B ? e.metaKey : e.ctrlKey) && (n = !n), this.toggleNode(t, n);
1107
+ }, this.ensureView = this.ensureVisible, this.svg = e.datum ? e : o(e), this.styleNode = this.svg.append("style"), this.zoom = s().filter((e) => this.options.scrollForPan && e.type === "wheel" ? e.ctrlKey && !e.button : (!e.ctrlKey || e.type === "wheel") && !e.button).on("zoom", this.handleZoom), this.setOptions(t), this.state = {
1108
+ id: this.options.id || this.svg.attr("id") || g(),
1109
+ rect: {
1110
+ x1: 0,
1111
+ y1: 0,
1112
+ x2: 0,
1113
+ y2: 0
1114
+ }
1115
+ }, this.g = this.svg.append("g"), this.g.append("g").attr("class", "markmap-highlight"), this._actions = new Ze(this), this.svg.on("click", () => {
1116
+ this._actions.selectedNode && (this._actions.selectedNode = null, this.options.clickBorder && this.g.selectAll(G(Y)).classed("markmap-selected", !1), this._actions.hideAddUI());
1117
+ });
1118
+ let n = (e) => {
1119
+ if (!this._actions.selectedNode || this._actions.editingNode || this._actions.editOverlay || this._actions.addInputUI) return;
1120
+ let t = document.activeElement?.tagName;
1121
+ t === "INPUT" || t === "TEXTAREA" || (e.key === "Tab" && this.options.addable ? (e.preventDefault(), e.stopPropagation(), this._actions.showAddInput(this._actions.selectedNode)) : e.key === "Enter" && this.options.addable ? (e.preventDefault(), e.stopPropagation(), this._actions.showAddSiblingInput(this._actions.selectedNode)) : (e.key === "Delete" || e.key === "Backspace") && this.options.deletable && (e.preventDefault(), e.stopPropagation(), this._actions.deleteNode(this._actions.selectedNode)));
1122
+ };
1123
+ document.addEventListener("keydown", n), this._disposeList.push(() => document.removeEventListener("keydown", n)), this._observer = new ResizeObserver(S(() => {
1124
+ this._actions.editingNode || this.renderData();
1125
+ }, 100)), this._disposeList.push(Q.tap(() => {
1126
+ this.setData();
1127
+ }), () => this._actions.hideAddUI(), () => this._observer.disconnect());
1128
+ }
1129
+ getStyleContent() {
1130
+ let { style: e } = this.options, { id: t } = this.state, n = typeof e == "function" ? e(t) : "";
1131
+ return [this.options.embedGlobalCSS && ".markmap{--markmap-max-width:9999px;--markmap-a-color:#0097e6;--markmap-a-hover-color:#00a8ff;--markmap-code-bg:#f0f0f0;--markmap-code-color:#555;--markmap-highlight-bg:#ffeaa7;--markmap-table-border:1px solid currentColor;--markmap-font:300 16px/20px sans-serif;--markmap-circle-open-bg:#fff;--markmap-text-color:#333;--markmap-highlight-node-bg:#ff02;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-node-hovered>foreignObject>div>div{border:2px solid #d9d9d9;border-radius:14px;padding:2px 6px}.markmap-selected>foreignObject>div>div,.markmap-selected.markmap-node-hovered>foreignObject>div>div{border:2px solid #b4b4b4;border-radius:14px;padding:2px 6px}.markmap-selected>circle{pointer-events:none;opacity:0!important}.markmap-collapse-on-hover .markmap-node>circle{opacity:0;transition:opacity .2s}.markmap-collapse-on-hover .markmap-node:hover>circle{opacity:1}.markmap-foreign{display:inline-block}.markmap-foreign>div>div{padding:4px 6px}.markmap-foreign .markmap-edit-wrapper{background:#fff;border-radius:4px;width:100%;padding:4px;animation:.2s ease-in fadeIn;position:relative;box-shadow:0 2px 8px #00000026}.markmap-foreign .markmap-edit-input{background:#f8f9fa;border:2px solid #4a90e2;border-radius:4px;outline:none;width:100%;padding:8px 12px;font-family:inherit;font-size:14px;transition:all .2s}.markmap-foreign .markmap-edit-input:focus{background:#fff;border-color:#2d7dd2;box-shadow:0 0 0 3px #4a90e21a}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px;padding:.25em;font-size:calc(1em - 2px)}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign>div{width:var(--markmap-max-width);text-align:left}.markmap-foreign>div>div{max-width:var(--markmap-wrap-width,30em);overflow-wrap:break-word;word-break:break-word;white-space:normal;display:inline-block}.markmap-highlight rect{fill:var(--markmap-highlight-node-bg)}.markmap-dark .markmap{--markmap-code-bg:#1a1b26;--markmap-code-color:#ddd;--markmap-circle-open-bg:#444;--markmap-text-color:#eee}@keyframes fadeIn{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}", n].filter(Boolean).join("\n");
1132
+ }
1133
+ updateStyle() {
1134
+ let e = y("", "markmap", this.state.id), t = this.options.collapseOnHover ? "markmap-collapse-on-hover" : "";
1135
+ this.svg.attr("class", [e, t].filter(Boolean).join(" "));
1136
+ let n = this.getStyleContent();
1137
+ this.styleNode.text(n);
1138
+ }
1139
+ async toggleNode(e, t = !1) {
1140
+ let n = e.payload?.fold ? 0 : 1;
1141
+ t ? v(e, (e, t) => {
1142
+ e.payload = {
1143
+ ...e.payload,
1144
+ fold: n
1145
+ }, t();
1146
+ }) : e.payload = {
1147
+ ...e.payload,
1148
+ fold: e.payload?.fold ? 0 : 1
1149
+ }, await this.renderData(e);
1150
+ }
1151
+ _initializeData(e) {
1152
+ let t = 0, { color: n, initialExpandLevel: r } = this.options, i = 0, a = 0;
1153
+ return v(e, (e, o, s) => {
1154
+ a += 1, e.children = e.children?.map((e) => ({ ...e })), t += 1, e.state = {
1155
+ ...e.state,
1156
+ depth: a,
1157
+ id: t,
1158
+ rect: {
1159
+ x: 0,
1160
+ y: 0,
1161
+ width: 0,
1162
+ height: 0
1163
+ },
1164
+ size: [0, 0]
1165
+ }, e.state.key = [s?.state?.id, e.state.id].filter(Boolean).join(".") + W(e.content), e.state.path = [s?.state?.path, e.state.id].filter(Boolean).join("."), n(e);
1166
+ let c = e.payload?.fold === 2;
1167
+ c ? i += 1 : (i || r >= 0 && e.state.depth >= r) && (e.payload = {
1168
+ ...e.payload,
1169
+ fold: 1
1170
+ }), o(), c && --i, --a;
1171
+ }), e;
1172
+ }
1173
+ _relayout() {
1174
+ if (!this.state.data) return;
1175
+ this.g.selectAll(G(Y)).selectAll(G("foreignObject")).each(function(e) {
1176
+ let t = this.firstChild?.firstChild, n = [t.scrollWidth, t.scrollHeight];
1177
+ e.state.size = n;
1178
+ });
1179
+ let { lineWidth: e, paddingX: r, spacingHorizontal: i, spacingVertical: a } = this.options, o = (e) => e.payload?.fold ? i : (e.children || []).length === 1 ? Math.round(i / 2) : i, s = Le({}).children((e) => {
1180
+ if (!e.payload?.fold) return e.children;
1181
+ }).nodeSize((e) => {
1182
+ let [t, n] = e.data.state.size, i = o(e.data);
1183
+ return [n, t + (t ? r * 2 : 0) + i];
1184
+ }).spacing((t, n) => (t.parent === n.parent ? a : a * 2) + e(t.data)), c = s.hierarchy(this.state.data);
1185
+ s(c);
1186
+ let l = c.descendants();
1187
+ l.forEach((e) => {
1188
+ let t = e.data, n = o(t);
1189
+ t.state.rect = {
1190
+ x: e.y,
1191
+ y: e.x - e.xSize / 2,
1192
+ width: e.ySize - n,
1193
+ height: e.xSize
1194
+ };
1195
+ }), this.state.rect = {
1196
+ x1: n(l, (e) => e.data.state.rect.x) || 0,
1197
+ y1: n(l, (e) => e.data.state.rect.y) || 0,
1198
+ x2: t(l, (e) => e.data.state.rect.x + e.data.state.rect.width) || 0,
1199
+ y2: t(l, (e) => e.data.state.rect.y + e.data.state.rect.height) || 0
1200
+ };
1201
+ }
1202
+ setOptions(e) {
1203
+ let t = e?.mode === "display" ? {
1204
+ editable: !1,
1205
+ addable: !1,
1206
+ deletable: !1,
1207
+ collapseOnHover: !1,
1208
+ hoverBorder: !1,
1209
+ clickBorder: !1
1210
+ } : e?.mode === "editable" ? {
1211
+ editable: !0,
1212
+ addable: !0,
1213
+ deletable: !0,
1214
+ collapseOnHover: !0,
1215
+ hoverBorder: !0,
1216
+ clickBorder: !0
1217
+ } : {};
1218
+ this.options = {
1219
+ ...this.options,
1220
+ ...t,
1221
+ ...e
1222
+ }, this.options.zoom ? this.svg.call(this.zoom) : this.svg.on(".zoom", null), this.options.pan ? this.svg.on("wheel", this.handlePan) : this.svg.on("wheel", null);
1223
+ }
1224
+ async setData(e, t) {
1225
+ t && this.setOptions(t), e && (this.state.data = this._initializeData(e)), this.state.data && (this.updateStyle(), await this.renderData());
1226
+ }
1227
+ getData(e) {
1228
+ let t = this.state.data;
1229
+ if (!t) return;
1230
+ if (!e) return t;
1231
+ let n = (e) => ({
1232
+ content: e.content,
1233
+ payload: e.payload,
1234
+ children: (e.children || []).map(n)
1235
+ });
1236
+ return n(t);
1237
+ }
1238
+ async setHighlight(e) {
1239
+ this.state.highlight = e || void 0, await this.renderData();
1240
+ }
1241
+ _getHighlightRect(e) {
1242
+ let t = 4 / l(this.svg.node()).k, n = { ...e.state.rect };
1243
+ return n.x -= t, n.y -= t, n.width += 2 * t, n.height += 2 * t, n;
1244
+ }
1245
+ async renderData(e) {
1246
+ let { paddingX: t, autoFit: n, color: r, maxWidth: i, lineWidth: a } = this.options, s = this.state.data;
1247
+ if (!s) return;
1248
+ let c = {}, l = {}, u = [];
1249
+ v(s, (e, t, n) => {
1250
+ e.payload?.fold || t(), c[e.state.id] = e, n && (l[e.state.id] = n.state.id), u.push(e);
1251
+ });
1252
+ let d = {}, f = {}, p = (e) => {
1253
+ !e || d[e.state.id] || v(e, (t, n) => {
1254
+ d[t.state.id] = e.state.id, n();
1255
+ });
1256
+ }, m = (e) => f[d[e.state.id]] || s.state.rect, h = (e) => (c[d[e.state.id]] || s).state.rect;
1257
+ f[s.state.id] = s.state.rect, e && p(e);
1258
+ let { highlight: g } = this.state;
1259
+ g && !c[g.state.id] && (g = void 0);
1260
+ let _ = this.g.selectAll(G(et)).selectAll(G("rect")).data(g ? [this._getHighlightRect(g)] : []).join("rect").attr("x", (e) => e.x).attr("y", (e) => e.y).attr("width", (e) => e.width).attr("height", (e) => e.height), y = this.g.selectAll(G(Y)).each((e) => {
1261
+ f[e.state.id] = e.state.rect;
1262
+ }).data(u, (e) => e.state.key), b = y.enter().append("g").attr("data-depth", (e) => e.state.depth).attr("data-path", (e) => e.state.path).each((e) => {
1263
+ p(c[l[e.state.id]]);
1264
+ }), x = y.exit().each((e) => {
1265
+ p(c[l[e.state.id]]);
1266
+ }), S = y.merge(b).attr("class", (e) => ["markmap-node", e.payload?.fold && "markmap-fold"].filter(Boolean).join(" ")), C = S.selectAll(G("line")).data((e) => [e], (e) => e.state.key), w = C.enter().append("line").attr("stroke", (e) => r(e)).attr("stroke-width", 0), T = C.merge(w), E = S.selectAll(G("circle")).data((e) => e.children?.length ? [e] : [], (e) => e.state.key);
1267
+ this.transition(E.exit()).attr("r", 0).attr("stroke-width", 0).remove();
1268
+ let D = E.enter().append("circle").attr("stroke-width", 0).attr("r", 0).on("click", (e, t) => this.handleClick(e, t)).on("mousedown", tt).merge(E).attr("stroke", (e) => r(e)).attr("fill", (e) => e.payload?.fold && e.children ? r(e) : "var(--markmap-circle-open-bg)"), O = this._observer, k = S.selectAll(G("foreignObject")).data((e) => [e], (e) => e.state.key), A = k.enter().append("foreignObject").attr("class", "markmap-foreign").attr("x", t).attr("y", 0).style("opacity", 0).on("mousedown", tt).on("dblclick", (e, t) => {
1269
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), this._actions.handleEdit(e, t);
1270
+ });
1271
+ A.append("xhtml:div").append("xhtml:div").html((e) => e.content).attr("xmlns", "http://www.w3.org/1999/xhtml"), A.each(function() {
1272
+ let e = this.firstChild?.firstChild;
1273
+ O.observe(e);
1274
+ });
1275
+ let j = x.selectAll(G("foreignObject"));
1276
+ j.each(function() {
1277
+ let e = this.firstChild?.firstChild;
1278
+ O.unobserve(e);
1279
+ });
1280
+ let M = A.merge(k);
1281
+ M.on("dblclick", (e, t) => {
1282
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation(), this._actions.handleEdit(e, t);
1283
+ }), M.on("mouseenter", (e, t) => {
1284
+ if (!this.options.hoverBorder) return;
1285
+ let n = this.findElement(t);
1286
+ if (!n) return;
1287
+ let r = o(n.g).select("foreignObject").node()?.firstChild?.firstChild;
1288
+ if (!r) return;
1289
+ let i = r.getBoundingClientRect();
1290
+ e.clientX >= i.left && e.clientX <= i.right && e.clientY >= i.top && e.clientY <= i.bottom && o(n.g).classed("markmap-node-hovered", !0);
1291
+ }), M.on("mousemove", (e, t) => {
1292
+ if (!this.options.hoverBorder) return;
1293
+ let n = this.findElement(t);
1294
+ if (!n) return;
1295
+ let r = o(n.g).select("foreignObject").node()?.firstChild?.firstChild;
1296
+ if (!r) return;
1297
+ let i = r.getBoundingClientRect(), a = e.clientX >= i.left && e.clientX <= i.right && e.clientY >= i.top && e.clientY <= i.bottom;
1298
+ o(n.g).classed("markmap-node-hovered", a);
1299
+ }), M.on("mouseleave", (e, t) => {
1300
+ if (!this.options.hoverBorder) return;
1301
+ let n = this.findElement(t);
1302
+ n && o(n.g).classed("markmap-node-hovered", !1);
1303
+ }), M.on("click", (e, t) => {
1304
+ if (this._actions.editingNode || this._actions.editOverlay) return;
1305
+ e.stopPropagation();
1306
+ let n = this.findElement(t), r = n ? o(n.g).select("foreignObject").node()?.firstChild?.firstChild : null;
1307
+ (() => {
1308
+ if (!r) return !1;
1309
+ let t = r.getBoundingClientRect();
1310
+ return e.clientX >= t.left && e.clientX <= t.right && e.clientY >= t.top && e.clientY <= t.bottom;
1311
+ })() && (this._actions.selectedNode = t, this.options.clickBorder && this.g.selectAll(G(Y)).classed("markmap-selected", (e) => e === t), this.options.addable && this._actions.showAddUI(t));
1312
+ }), M.select("div").select("div").html((e) => e.content);
1313
+ let ee = u.flatMap((e) => e.payload?.fold ? [] : e.children.map((t) => ({
1314
+ source: e,
1315
+ target: t
1316
+ }))), N = this.g.selectAll(G($e)).data(ee, (e) => e.target.state.key), P = N.exit(), te = N.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (e) => e.target.state.depth).attr("data-path", (e) => e.target.state.path).attr("d", (e) => {
1317
+ let t = m(e.target), n = [t.x + t.width, t.y + t.height];
1318
+ return X({
1319
+ source: n,
1320
+ target: n
1321
+ });
1322
+ }).attr("stroke-width", 0).merge(N);
1323
+ this.svg.style("--markmap-max-width", i ? `${i}px` : null), await new Promise(requestAnimationFrame), this._relayout(), _ = _.data(g ? [this._getHighlightRect(g)] : []).join("rect"), this.transition(_).attr("x", (e) => e.x).attr("y", (e) => e.y).attr("width", (e) => e.width).attr("height", (e) => e.height), b.attr("transform", (e) => {
1324
+ let t = m(e);
1325
+ return `translate(${t.x + t.width - e.state.rect.width},${t.y + t.height - e.state.rect.height})`;
1326
+ }), this.transition(x).attr("transform", (e) => {
1327
+ let t = h(e);
1328
+ return `translate(${t.x + t.width - e.state.rect.width},${t.y + t.height - e.state.rect.height})`;
1329
+ }).remove(), this.transition(S).attr("transform", (e) => `translate(${e.state.rect.x},${e.state.rect.y})`);
1330
+ let ne = x.selectAll(G("line"));
1331
+ this.transition(ne).attr("x1", (e) => e.state.rect.width).attr("stroke-width", 0), w.attr("x1", (e) => e.state.rect.width).attr("x2", (e) => e.state.rect.width), T.attr("y1", (e) => e.state.rect.height + a(e) / 2).attr("y2", (e) => e.state.rect.height + a(e) / 2), this.transition(T).attr("x1", -1).attr("x2", (e) => e.state.rect.width + 2).attr("stroke", (e) => r(e)).attr("stroke-width", a);
1332
+ let F = x.selectAll(G("circle"));
1333
+ this.transition(F).attr("r", 0).attr("stroke-width", 0), D.attr("cx", (e) => e.state.rect.width + 4).attr("cy", (e) => e.state.rect.height + a(e) / 2), this.transition(D).attr("r", 6).attr("stroke-width", 1.5), this.transition(j).style("opacity", 0), M.attr("width", (e) => Math.max(0, e.state.rect.width - t * 2 + 16)).attr("height", (e) => e.state.rect.height), this.transition(M).style("opacity", 1), this.transition(P).attr("d", (e) => {
1334
+ let t = h(e.target), n = [t.x + t.width, t.y + t.height + a(e.target) / 2];
1335
+ return X({
1336
+ source: n,
1337
+ target: n
1338
+ });
1339
+ }).attr("stroke-width", 0).remove(), this.transition(te).attr("stroke", (e) => r(e.target)).attr("stroke-width", (e) => a(e.target)).attr("d", (e) => {
1340
+ let t = e.source, n = e.target;
1341
+ return X({
1342
+ source: [t.state.rect.x + t.state.rect.width, t.state.rect.y + t.state.rect.height + a(t) / 2],
1343
+ target: [n.state.rect.x, n.state.rect.y + n.state.rect.height + a(n) / 2]
1344
+ });
1345
+ }), n && this.fit();
1346
+ }
1347
+ transition(e) {
1348
+ let { duration: t } = this.options;
1349
+ return e.transition().duration(t);
1350
+ }
1351
+ /**
1352
+ * Fit the content to the viewport.
1353
+ */
1354
+ async fit(e = this.options.maxInitialScale) {
1355
+ let { width: t, height: n } = this.svg.node().getBoundingClientRect(), { fitRatio: r } = this.options, { x1: i, y1: a, x2: o, y2: s } = this.state.rect, l = o - i, u = s - a, d = Math.min(t / l * r, n / u * r, e), f = c.translate((t - l * d) / 2 - i * d, (n - u * d) / 2 - a * d).scale(d);
1356
+ return this.transition(this.svg).call(this.zoom.transform, f).end().catch(_);
1357
+ }
1358
+ findElement(e) {
1359
+ let t;
1360
+ return this.g.selectAll(G(Y)).each(function(n) {
1361
+ n === e && (t = {
1362
+ data: n,
1363
+ g: this
1364
+ });
1365
+ }), t;
1366
+ }
1367
+ /**
1368
+ * Pan the content to make the provided node visible in the viewport.
1369
+ */
1370
+ async ensureVisible(e, t) {
1371
+ let n = this.findElement(e)?.data;
1372
+ if (!n) return;
1373
+ let r = this.svg.node(), i = r.getBoundingClientRect(), a = l(r), [o, s] = [n.state.rect.x, n.state.rect.x + n.state.rect.width + 2].map((e) => e * a.k + a.x), [c, u] = [n.state.rect.y, n.state.rect.y + n.state.rect.height].map((e) => e * a.k + a.y), d = {
1374
+ left: 0,
1375
+ right: 0,
1376
+ top: 0,
1377
+ bottom: 0,
1378
+ ...t
1379
+ }, f = [d.left - o, i.width - d.right - s], p = [d.top - c, i.height - d.bottom - u], m = f[0] * f[1] > 0 ? Z(f, Math.abs) / a.k : 0, h = p[0] * p[1] > 0 ? Z(p, Math.abs) / a.k : 0;
1380
+ if (m || h) {
1381
+ let e = a.translate(m, h);
1382
+ return this.transition(this.svg).call(this.zoom.transform, e).end().catch(_);
1383
+ }
1384
+ }
1385
+ async centerNode(e, t) {
1386
+ let n = this.findElement(e)?.data;
1387
+ if (!n) return;
1388
+ let r = this.svg.node(), i = r.getBoundingClientRect(), a = l(r), o = (n.state.rect.x + n.state.rect.width / 2) * a.k + a.x, s = (n.state.rect.y + n.state.rect.height / 2) * a.k + a.y, c = {
1389
+ left: 0,
1390
+ right: 0,
1391
+ top: 0,
1392
+ bottom: 0,
1393
+ ...t
1394
+ }, u = (c.left + i.width - c.right) / 2, d = (c.top + i.height - c.bottom) / 2, f = (u - o) / a.k, p = (d - s) / a.k;
1395
+ if (f || p) {
1396
+ let e = a.translate(f, p);
1397
+ return this.transition(this.svg).call(this.zoom.transform, e).end().catch(_);
1398
+ }
1399
+ }
1400
+ /**
1401
+ * Scale content with it pinned at the center of the viewport.
1402
+ */
1403
+ async rescale(e) {
1404
+ let t = this.svg.node(), { width: n, height: r } = t.getBoundingClientRect(), i = n / 2, a = r / 2, o = l(t), s = o.translate((i - o.x) * (1 - e) / o.k, (a - o.y) * (1 - e) / o.k).scale(e);
1405
+ return this.transition(this.svg).call(this.zoom.transform, s).end().catch(_);
1406
+ }
1407
+ destroy() {
1408
+ this.svg.on(".zoom", null), this.svg.html(null), this._disposeList.forEach((e) => {
1409
+ e();
1410
+ });
1411
+ }
1412
+ static create(t, n, r = null) {
1413
+ let i = new e(t, n);
1414
+ return r && i.setData(r).then(() => {
1415
+ i.fit();
1416
+ }), i;
1417
+ }
1418
+ };
1419
+ /**
1420
+ * Convert a single HTML inline-content string to Markdown text.
1421
+ * Handles common inline elements produced by markdown-it:
1422
+ * strong, em, del/s, code, a, img, br, and HTML entities.
1423
+ */
1424
+ function $(e) {
1425
+ if (!e) return "";
1426
+ let t = e;
1427
+ return t = t.replace(/<img(?=[^>]*?\bsrc="([^"]*)")(?=[^>]*?\balt="([^"]*)")(?=[^>]*?\btitle="([^"]*)")?[^>]*?\/?>/gi, (e, t, n, r) => r ? `![${n}](${t} "${r}")` : `![${n}](${t})`), t = t.replace(/<img\s[^>]*?\/?>/gi, (e) => {
1428
+ let t = (e.match(/\bsrc="([^"]*)"/) || [])[1] ?? "", n = (e.match(/\balt="([^"]*)"/) || [])[1] ?? "", r = (e.match(/\btitle="([^"]*)"/) || [])[1];
1429
+ return r ? `![${n}](${t} "${r}")` : `![${n}](${t})`;
1430
+ }), t = t.replace(/<a\s[^>]*?href="([^"]*)"[^>]*?>([\s\S]*?)<\/a>/gi, (e, t, n) => {
1431
+ let r = (e.match(/\btitle="([^"]*)"/) || [])[1], i = $(n);
1432
+ return r ? `[${i}](${t} "${r}")` : `[${i}](${t})`;
1433
+ }), t = t.replace(/<strong>([\s\S]*?)<\/strong>/gi, (e, t) => `**${$(t)}**`), t = t.replace(/<b>([\s\S]*?)<\/b>/gi, (e, t) => `**${$(t)}**`), t = t.replace(/<em>([\s\S]*?)<\/em>/gi, (e, t) => `*${$(t)}*`), t = t.replace(/<i>([\s\S]*?)<\/i>/gi, (e, t) => `*${$(t)}*`), t = t.replace(/<(?:del|s)>([\s\S]*?)<\/(?:del|s)>/gi, (e, t) => `~~${$(t)}~~`), t = t.replace(/<code>([\s\S]*?)<\/code>/gi, (e, t) => "`" + t.replace(/&#x([0-9a-f]+);/gi, (e, t) => String.fromCodePoint(parseInt(t, 16))).replace(/&#([0-9]+);/g, (e, t) => String.fromCodePoint(parseInt(t, 10))).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'") + "`"), t = t.replace(/<br\s*\/?>/gi, "\n"), t = t.replace(/<[^>]+>/g, ""), t = t.replace(/&#x([0-9a-f]+);/gi, (e, t) => String.fromCodePoint(parseInt(t, 16))).replace(/&#([0-9]+);/g, (e, t) => String.fromCodePoint(parseInt(t, 10))).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&nbsp;/g, " "), t;
1471
1434
  }
1472
- function Ve(n) {
1473
- const t = [];
1474
- function e(i, o) {
1475
- const s = $(i.content).trim();
1476
- if (s)
1477
- if (o <= 2) {
1478
- const a = "#".repeat(o + 1);
1479
- t.length > 0 && t.push(""), t.push(`${a} ${s}`);
1480
- } else {
1481
- const a = " ".repeat(o - 3);
1482
- t.push(`${a}- ${s}`);
1483
- }
1484
- for (const a of i.children)
1485
- e(a, o + 1);
1486
- }
1487
- return e(n, 0), t.join(`
1488
- `).trimStart() + `
1489
- `;
1435
+ /**
1436
+ * Serialize an `IPureNode` tree back to a Markdown string.
1437
+ *
1438
+ * This is the conceptual inverse of `Transformer.transform()`.
1439
+ * The algorithm maps tree depth to Markdown heading levels:
1440
+ *
1441
+ * - depth 0 → `# text`
1442
+ * - depth 1 → `## text`
1443
+ * - depth 2 → `### text`
1444
+ * - depth 3+ → `- text` (indented list items, 2 spaces per extra level)
1445
+ *
1446
+ * A blank line is inserted between heading-level siblings to keep the
1447
+ * output readable and round-trip-stable through `transform()`.
1448
+ *
1449
+ * @param root Root node of the markmap tree (e.g. from `mm.getData(true)`).
1450
+ * @returns Markdown string.
1451
+ *
1452
+ * @example
1453
+ * ```ts
1454
+ * import { toMarkdown } from 'markmap-lib';
1455
+ *
1456
+ * const pureNode = mm.getData(true); // IPureNode
1457
+ * const markdown = toMarkdown(pureNode);
1458
+ * console.log(markdown);
1459
+ * ```
1460
+ */
1461
+ function rt(e) {
1462
+ let t = [];
1463
+ function n(e, r) {
1464
+ let i = $(e.content).trim();
1465
+ if (i) if (r <= 2) {
1466
+ let e = "#".repeat(r + 1);
1467
+ t.length > 0 && t.push(""), t.push(`${e} ${i}`);
1468
+ } else {
1469
+ let e = " ".repeat(r - 3);
1470
+ t.push(`${e}- ${i}`);
1471
+ }
1472
+ for (let t of e.children) n(t, r + 1);
1473
+ }
1474
+ return n(e, 0), t.join("\n").trimStart() + "\n";
1490
1475
  }
1491
- export {
1492
- Et as Markmap,
1493
- b as childSelector,
1494
- ne as defaultColorFn,
1495
- yt as defaultOptions,
1496
- Fe as deriveOptions,
1497
- We as globalCSS,
1498
- $ as htmlInlineToMarkdown,
1499
- gt as isMacintosh,
1500
- mt as lineWidthFactory,
1501
- Le as loadCSS,
1502
- He as loadJS,
1503
- Pe as refreshHook,
1504
- V as simpleHash,
1505
- Ve as toMarkdown
1506
- };
1476
+ export { nt as Markmap, G as childSelector, V as defaultColorFn, U as defaultOptions, de as deriveOptions, Qe as globalCSS, $ as htmlInlineToMarkdown, B as isMacintosh, H as lineWidthFactory, ue as loadCSS, le as loadJS, Q as refreshHook, W as simpleHash, rt as toMarkdown };