markmap-view-plus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/action.d.ts +110 -0
- package/dist/browser/index.js +2159 -0
- package/dist/constants.d.ts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1506 -0
- package/dist/to-markdown.d.ts +34 -0
- package/dist/types.d.ts +73 -0
- package/dist/util.d.ts +7 -0
- package/dist/view.d.ts +94 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1506 @@
|
|
|
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}`;
|
|
25
|
+
}
|
|
26
|
+
function B() {
|
|
27
|
+
}
|
|
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);
|
|
38
|
+
}
|
|
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(" ");
|
|
44
|
+
}
|
|
45
|
+
function pt() {
|
|
46
|
+
const n = {};
|
|
47
|
+
return n.promise = new Promise((t, e) => {
|
|
48
|
+
n.resolve = t, n.reject = e;
|
|
49
|
+
}), n;
|
|
50
|
+
}
|
|
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
|
+
};
|
|
60
|
+
}
|
|
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
|
+
};
|
|
74
|
+
}
|
|
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);
|
|
85
|
+
}
|
|
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
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function Kt(n) {
|
|
98
|
+
return n.children;
|
|
99
|
+
}
|
|
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);
|
|
105
|
+
}
|
|
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);
|
|
115
|
+
}
|
|
116
|
+
const qt = {
|
|
117
|
+
className: "class",
|
|
118
|
+
labelFor: "for"
|
|
119
|
+
};
|
|
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
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function Zt(n) {
|
|
131
|
+
return n.reduce((t, e) => t.concat(e), []);
|
|
132
|
+
}
|
|
133
|
+
function W(n, t) {
|
|
134
|
+
return Array.isArray(n) ? Zt(n.map((e) => W(e, t))) : K(n, t);
|
|
135
|
+
}
|
|
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!");
|
|
181
|
+
}
|
|
182
|
+
function Qt(n) {
|
|
183
|
+
return K(n);
|
|
184
|
+
}
|
|
185
|
+
function D(...n) {
|
|
186
|
+
return Qt(Wt(...n));
|
|
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;
|
|
214
|
+
}
|
|
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;
|
|
234
|
+
}
|
|
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);
|
|
245
|
+
}
|
|
246
|
+
async function Le(n) {
|
|
247
|
+
await Promise.all(n.map((t) => ie(t)));
|
|
248
|
+
}
|
|
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
|
|
279
|
+
};
|
|
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;
|
|
322
|
+
}
|
|
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);
|
|
328
|
+
}
|
|
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
|
+
};
|
|
339
|
+
}
|
|
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;
|
|
345
|
+
}
|
|
346
|
+
function re() {
|
|
347
|
+
return this.eachAfter(oe);
|
|
348
|
+
}
|
|
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;
|
|
357
|
+
}
|
|
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;
|
|
363
|
+
}
|
|
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;
|
|
371
|
+
}
|
|
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
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function de(n) {
|
|
379
|
+
return this.eachBefore(function(t) {
|
|
380
|
+
t.children && t.children.sort(n);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
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;
|
|
389
|
+
}
|
|
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;
|
|
396
|
+
}
|
|
397
|
+
function ue() {
|
|
398
|
+
for (var n = this, t = [n]; n = n.parent; )
|
|
399
|
+
t.push(n);
|
|
400
|
+
return t;
|
|
401
|
+
}
|
|
402
|
+
function fe() {
|
|
403
|
+
var n = [];
|
|
404
|
+
return this.each(function(t) {
|
|
405
|
+
n.push(t);
|
|
406
|
+
}), n;
|
|
407
|
+
}
|
|
408
|
+
function ge() {
|
|
409
|
+
var n = [];
|
|
410
|
+
return this.eachBefore(function(t) {
|
|
411
|
+
t.children || n.push(t);
|
|
412
|
+
}), n;
|
|
413
|
+
}
|
|
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;
|
|
419
|
+
}
|
|
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);
|
|
427
|
+
}
|
|
428
|
+
function ye() {
|
|
429
|
+
return Y(this).eachBefore(ve);
|
|
430
|
+
}
|
|
431
|
+
function xe(n) {
|
|
432
|
+
return n.children;
|
|
433
|
+
}
|
|
434
|
+
function ve(n) {
|
|
435
|
+
n.data = n.data.data;
|
|
436
|
+
}
|
|
437
|
+
function ke(n) {
|
|
438
|
+
var t = 0;
|
|
439
|
+
do
|
|
440
|
+
n.height = t;
|
|
441
|
+
while ((n = n.parent) && n.height < ++t);
|
|
442
|
+
}
|
|
443
|
+
function P(n) {
|
|
444
|
+
this.data = n, this.depth = this.height = 0, this.parent = null;
|
|
445
|
+
}
|
|
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
|
|
460
|
+
};
|
|
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
|
|
467
|
+
});
|
|
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;
|
|
643
|
+
}
|
|
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 = " ", 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 = `
|
|
793
|
+
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;
|
|
798
|
+
z-index: 9999;
|
|
799
|
+
pointer-events: auto;
|
|
800
|
+
`;
|
|
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 = `
|
|
803
|
+
width: 100%;
|
|
804
|
+
height: 100%;
|
|
805
|
+
margin: 0;
|
|
806
|
+
padding: 2px 6px;
|
|
807
|
+
border: 2px solid #52c41a;
|
|
808
|
+
border-radius: 14px;
|
|
809
|
+
background: #fff;
|
|
810
|
+
box-sizing: border-box;
|
|
811
|
+
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};
|
|
818
|
+
`;
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
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;
|
|
919
|
+
border-radius: 50%;
|
|
920
|
+
background: #b4b4b4;
|
|
921
|
+
color: #fff;
|
|
922
|
+
font-weight: 600;
|
|
923
|
+
font-size: ${h}px;
|
|
924
|
+
line-height: 1;
|
|
925
|
+
padding: 0;
|
|
926
|
+
cursor: pointer;
|
|
927
|
+
box-shadow: none;
|
|
928
|
+
outline: none;
|
|
929
|
+
border: none;
|
|
930
|
+
user-select: none;
|
|
931
|
+
display: flex;
|
|
932
|
+
align-items: center;
|
|
933
|
+
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 = " ", 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();
|
|
1051
|
+
}
|
|
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
|
+
}
|
|
1450
|
+
}
|
|
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 ? `` : ``
|
|
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 ? `` : ``;
|
|
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(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/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(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/ /g, " "), t;
|
|
1471
|
+
}
|
|
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
|
+
`;
|
|
1490
|
+
}
|
|
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
|
+
};
|