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/README.md +1 -1
- package/dist/browser/index.js +2061 -2112
- package/dist/index.js +1395 -1425
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,805 +1,829 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
98
|
-
|
|
125
|
+
function ee(e) {
|
|
126
|
+
return e.children;
|
|
99
127
|
}
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
139
|
+
var ne = {
|
|
140
|
+
className: "class",
|
|
141
|
+
labelFor: "for"
|
|
119
142
|
};
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
131
|
-
|
|
151
|
+
function re(e) {
|
|
152
|
+
return e.reduce((e, t) => e.concat(t), []);
|
|
132
153
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
154
|
+
function I(e, t) {
|
|
155
|
+
return Array.isArray(e) ? re(e.map((e) => I(e, t))) : L(e, t);
|
|
135
156
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
183
|
-
|
|
182
|
+
function ie(e) {
|
|
183
|
+
return L(e);
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
|
|
185
|
+
function R(...e) {
|
|
186
|
+
return ie(j(...e));
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
|
247
|
-
|
|
233
|
+
async function ue(e) {
|
|
234
|
+
await Promise.all(e.map((e) => ce(e)));
|
|
248
235
|
}
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
|
347
|
-
|
|
330
|
+
function pe() {
|
|
331
|
+
return this.eachAfter(fe);
|
|
348
332
|
}
|
|
349
|
-
function
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
359
|
-
|
|
360
|
-
|
|
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
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
355
|
+
function ve(e) {
|
|
356
|
+
return this.eachBefore(function(t) {
|
|
357
|
+
t.children && t.children.sort(e);
|
|
358
|
+
});
|
|
382
359
|
}
|
|
383
|
-
function
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
|
398
|
-
|
|
399
|
-
|
|
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
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
375
|
+
function Se() {
|
|
376
|
+
var e = [];
|
|
377
|
+
return this.each(function(t) {
|
|
378
|
+
e.push(t);
|
|
379
|
+
}), e;
|
|
407
380
|
}
|
|
408
|
-
function
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
381
|
+
function Ce() {
|
|
382
|
+
var e = [];
|
|
383
|
+
return this.eachBefore(function(t) {
|
|
384
|
+
t.children || e.push(t);
|
|
385
|
+
}), e;
|
|
413
386
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
|
429
|
-
|
|
401
|
+
function Te() {
|
|
402
|
+
return K(this).eachBefore(De);
|
|
430
403
|
}
|
|
431
|
-
function
|
|
432
|
-
|
|
404
|
+
function Ee(e) {
|
|
405
|
+
return e.children;
|
|
433
406
|
}
|
|
434
|
-
function
|
|
435
|
-
|
|
407
|
+
function De(e) {
|
|
408
|
+
e.data = e.data.data;
|
|
436
409
|
}
|
|
437
|
-
function
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
|
444
|
-
|
|
416
|
+
function q(e) {
|
|
417
|
+
this.data = e, this.depth = this.height = 0, this.parent = null;
|
|
445
418
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}, [0, null]),
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
},
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
},
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
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 = " ", 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: ${
|
|
795
|
-
top: ${
|
|
796
|
-
width: ${Math.max(
|
|
797
|
-
height: ${Math.max(20,
|
|
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
|
-
|
|
802
|
-
|
|
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: ${
|
|
813
|
-
font-family: ${
|
|
814
|
-
line-height: ${
|
|
815
|
-
font-weight: ${
|
|
816
|
-
letter-spacing: ${
|
|
817
|
-
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
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), 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: ${
|
|
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", (
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
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 = " ", 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
|
-
|
|
1053
|
-
|
|
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
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
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 ? `` : ``), 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 ? `` : ``;
|
|
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(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/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(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/ /g, " "), t;
|
|
1471
1434
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
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 };
|