markmap-view 0.17.3-alpha.1 → 0.17.3-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { Hook as st, getId as at, debounce as lt, addClass as ct, walkTree as M, childSelector as C, noop as T } from "markmap-common";
2
- import { loadCSS as Ce, loadJS as we } from "markmap-common";
3
- import { scaleOrdinal as Y, schemeCategory10 as ht, zoomTransform as A, select as dt, zoom as ut, linkHorizontal as pt, min as H, max as I, zoomIdentity as mt, minIndex as ft } from "d3";
4
- const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), gt = Y(ht), P = {
1
+ import { Hook as et, getId as nt, debounce as rt, addClass as it, walkTree as X, childSelector as b, noop as R } from "markmap-common";
2
+ import { loadCSS as ce, loadJS as he } from "markmap-common";
3
+ import { scaleOrdinal as N, schemeCategory10 as st, linkHorizontal as ot, zoomTransform as j, select as at, zoom as lt, min as T, max as _, zoomIdentity as ct, minIndex as ht } from "d3";
4
+ const P = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), dt = N(st), W = {
5
5
  autoFit: !1,
6
6
  color: (e) => {
7
7
  var t;
8
- return gt(`${((t = e.state) == null ? void 0 : t.path) || ""}`);
8
+ return dt(`${((t = e.state) == null ? void 0 : t.path) || ""}`);
9
9
  },
10
10
  duration: 500,
11
11
  embedGlobalCSS: !0,
@@ -14,7 +14,7 @@ const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), g
14
14
  maxWidth: 0,
15
15
  nodeMinHeight: 16,
16
16
  paddingX: 8,
17
- scrollForPan: K,
17
+ scrollForPan: P,
18
18
  spacingHorizontal: 80,
19
19
  spacingVertical: 5,
20
20
  initialExpandLevel: -1,
@@ -22,24 +22,24 @@ const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), g
22
22
  pan: !0,
23
23
  toggleRecursively: !1
24
24
  };
25
- function Se(e) {
26
- const t = {}, n = { ...e }, { color: i, colorFreezeLevel: o } = n;
27
- if ((i == null ? void 0 : i.length) === 1) {
28
- const s = i[0];
29
- t.color = () => s;
30
- } else if (i != null && i.length) {
31
- const s = Y(i);
32
- t.color = (l) => s(`${l.state.path}`);
25
+ function se(e) {
26
+ const t = {}, n = { ...e }, { color: r, colorFreezeLevel: s } = n;
27
+ if ((r == null ? void 0 : r.length) === 1) {
28
+ const i = r[0];
29
+ t.color = () => i;
30
+ } else if (r != null && r.length) {
31
+ const i = N(r);
32
+ t.color = (a) => i(`${a.state.path}`);
33
33
  }
34
- if (o) {
35
- const s = t.color || P.color;
36
- t.color = (l) => (l = {
37
- ...l,
34
+ if (s) {
35
+ const i = t.color || W.color;
36
+ t.color = (a) => (a = {
37
+ ...a,
38
38
  state: {
39
- ...l.state,
40
- path: l.state.path.split(".").slice(0, o).join(".")
39
+ ...a.state,
40
+ path: a.state.path.split(".").slice(0, s).join(".")
41
41
  }
42
- }, s(l));
42
+ }, i(a));
43
43
  }
44
44
  return [
45
45
  "duration",
@@ -51,333 +51,186 @@ function Se(e) {
51
51
  "paddingX",
52
52
  "spacingHorizontal",
53
53
  "spacingVertical"
54
- ].forEach((s) => {
55
- const l = n[s];
56
- typeof l == "number" && (t[s] = l);
57
- }), ["zoom", "pan"].forEach((s) => {
58
- const l = n[s];
59
- l != null && (t[s] = !!l);
54
+ ].forEach((i) => {
55
+ const a = n[i];
56
+ typeof a == "number" && (t[i] = a);
57
+ }), ["zoom", "pan"].forEach((i) => {
58
+ const a = n[i];
59
+ a != null && (t[i] = !!a);
60
60
  }), t;
61
61
  }
62
- /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
63
- const U = 1, G = 2, xt = "http://www.w3.org/2000/svg", _ = "http://www.w3.org/1999/xlink", yt = {
64
- show: _,
65
- actuate: _,
66
- href: _
67
- }, kt = (e) => typeof e == "string" || typeof e == "number", vt = (e) => (e == null ? void 0 : e.vtype) === U, St = (e) => (e == null ? void 0 : e.vtype) === G;
68
- function j(e, t) {
69
- let n;
70
- if (typeof e == "string") n = U;
71
- else if (typeof e == "function") n = G;
72
- else throw new Error("Invalid VNode type");
73
- return {
74
- vtype: n,
75
- type: e,
76
- props: t
77
- };
78
- }
79
- function bt(e) {
80
- return e.children;
81
- }
82
- const zt = {
83
- isSvg: !1
84
- };
85
- function L(e, t) {
86
- Array.isArray(t) || (t = [t]), t = t.filter(Boolean), t.length && e.append(...t);
87
- }
88
- function Et(e, t, n) {
89
- for (const i in t)
90
- if (!(i === "key" || i === "children" || i === "ref"))
91
- if (i === "dangerouslySetInnerHTML")
92
- e.innerHTML = t[i].__html;
93
- else if (i === "innerHTML" || i === "textContent" || i === "innerText" || i === "value" && ["textarea", "select"].includes(e.tagName)) {
94
- const o = t[i];
95
- o != null && (e[i] = o);
96
- } else i.startsWith("on") ? e[i.toLowerCase()] = t[i] : wt(e, i, t[i], n.isSvg);
97
- }
98
- const Ct = {
99
- className: "class",
100
- labelFor: "for"
101
- };
102
- function wt(e, t, n, i) {
103
- if (t = Ct[t] || t, n === !0)
104
- e.setAttribute(t, "");
105
- else if (n === !1)
106
- e.removeAttribute(t);
107
- else {
108
- const o = i ? yt[t] : void 0;
109
- o !== void 0 ? e.setAttributeNS(o, t, n) : e.setAttribute(t, n);
110
- }
111
- }
112
- function Xt(e) {
113
- return e.reduce((t, n) => t.concat(n), []);
114
- }
115
- function $(e, t) {
116
- return Array.isArray(e) ? Xt(e.map((n) => $(n, t))) : B(e, t);
117
- }
118
- function B(e, t = zt) {
119
- if (e == null || typeof e == "boolean")
120
- return null;
121
- if (e instanceof Node)
122
- return e;
123
- if (St(e)) {
124
- const {
125
- type: n,
126
- props: i
127
- } = e;
128
- if (n === bt) {
129
- const a = document.createDocumentFragment();
130
- if (i.children) {
131
- const c = $(i.children, t);
132
- L(a, c);
133
- }
134
- return a;
135
- }
136
- const o = n(i);
137
- return B(o, t);
138
- }
139
- if (kt(e))
140
- return document.createTextNode(`${e}`);
141
- if (vt(e)) {
142
- let n;
143
- const {
144
- type: i,
145
- props: o
146
- } = e;
147
- if (!t.isSvg && i === "svg" && (t = Object.assign({}, t, {
148
- isSvg: !0
149
- })), t.isSvg ? n = document.createElementNS(xt, i) : n = document.createElement(i), Et(n, o, t), o.children) {
150
- let c = t;
151
- t.isSvg && i === "foreignObject" && (c = Object.assign({}, c, {
152
- isSvg: !1
153
- }));
154
- const s = $(o.children, c);
155
- s != null && L(n, s);
156
- }
157
- const {
158
- ref: a
159
- } = o;
160
- return typeof a == "function" && a(n), n;
161
- }
162
- throw new Error("mount: Invalid Vnode!");
62
+ function pt(e) {
63
+ let t = 0;
64
+ for (let n = 0; n < e.length; n++)
65
+ t = (t << 5) - t + e.charCodeAt(n) | 0;
66
+ return (t >>> 0).toString(36);
163
67
  }
164
- function O(e) {
165
- return B(e);
166
- }
167
- function jt(e) {
168
- var t = 0, n = e.children, i = n && n.length;
169
- if (!i) t = 1;
170
- else for (; --i >= 0; ) t += n[i].value;
68
+ function ut(e) {
69
+ var t = 0, n = e.children, r = n && n.length;
70
+ if (!r) t = 1;
71
+ else for (; --r >= 0; ) t += n[r].value;
171
72
  e.value = t;
172
73
  }
173
- function Nt() {
174
- return this.eachAfter(jt);
74
+ function mt() {
75
+ return this.eachAfter(ut);
175
76
  }
176
- function Rt(e) {
177
- var t = this, n, i = [t], o, a, c;
77
+ function gt(e) {
78
+ var t = this, n, r = [t], s, l, c;
178
79
  do
179
- for (n = i.reverse(), i = []; t = n.pop(); )
180
- if (e(t), o = t.children, o) for (a = 0, c = o.length; a < c; ++a)
181
- i.push(o[a]);
182
- while (i.length);
80
+ for (n = r.reverse(), r = []; t = n.pop(); )
81
+ if (e(t), s = t.children, s) for (l = 0, c = s.length; l < c; ++l)
82
+ r.push(s[l]);
83
+ while (r.length);
183
84
  return this;
184
85
  }
185
- function Mt(e) {
186
- for (var t = this, n = [t], i, o; t = n.pop(); )
187
- if (e(t), i = t.children, i) for (o = i.length - 1; o >= 0; --o)
188
- n.push(i[o]);
86
+ function ft(e) {
87
+ for (var t = this, n = [t], r, s; t = n.pop(); )
88
+ if (e(t), r = t.children, r) for (s = r.length - 1; s >= 0; --s)
89
+ n.push(r[s]);
189
90
  return this;
190
91
  }
191
- function Tt(e) {
192
- for (var t = this, n = [t], i = [], o, a, c; t = n.pop(); )
193
- if (i.push(t), o = t.children, o) for (a = 0, c = o.length; a < c; ++a)
194
- n.push(o[a]);
195
- for (; t = i.pop(); )
92
+ function xt(e) {
93
+ for (var t = this, n = [t], r = [], s, l, c; t = n.pop(); )
94
+ if (r.push(t), s = t.children, s) for (l = 0, c = s.length; l < c; ++l)
95
+ n.push(s[l]);
96
+ for (; t = r.pop(); )
196
97
  e(t);
197
98
  return this;
198
99
  }
199
- function At(e) {
100
+ function yt(e) {
200
101
  return this.eachAfter(function(t) {
201
- for (var n = +e(t.data) || 0, i = t.children, o = i && i.length; --o >= 0; ) n += i[o].value;
102
+ for (var n = +e(t.data) || 0, r = t.children, s = r && r.length; --s >= 0; ) n += r[s].value;
202
103
  t.value = n;
203
104
  });
204
105
  }
205
- function _t(e) {
106
+ function kt(e) {
206
107
  return this.eachBefore(function(t) {
207
108
  t.children && t.children.sort(e);
208
109
  });
209
110
  }
210
- function Ot(e) {
211
- for (var t = this, n = Dt(t, e), i = [t]; t !== n; )
212
- t = t.parent, i.push(t);
213
- for (var o = i.length; e !== n; )
214
- i.splice(o, 0, e), e = e.parent;
215
- return i;
111
+ function vt(e) {
112
+ for (var t = this, n = bt(t, e), r = [t]; t !== n; )
113
+ t = t.parent, r.push(t);
114
+ for (var s = r.length; e !== n; )
115
+ r.splice(s, 0, e), e = e.parent;
116
+ return r;
216
117
  }
217
- function Dt(e, t) {
118
+ function bt(e, t) {
218
119
  if (e === t) return e;
219
- var n = e.ancestors(), i = t.ancestors(), o = null;
220
- for (e = n.pop(), t = i.pop(); e === t; )
221
- o = e, e = n.pop(), t = i.pop();
222
- return o;
120
+ var n = e.ancestors(), r = t.ancestors(), s = null;
121
+ for (e = n.pop(), t = r.pop(); e === t; )
122
+ s = e, e = n.pop(), t = r.pop();
123
+ return s;
223
124
  }
224
- function $t() {
125
+ function zt() {
225
126
  for (var e = this, t = [e]; e = e.parent; )
226
127
  t.push(e);
227
128
  return t;
228
129
  }
229
- function Bt() {
130
+ function St() {
230
131
  var e = [];
231
132
  return this.each(function(t) {
232
133
  e.push(t);
233
134
  }), e;
234
135
  }
235
- function Ft() {
136
+ function Et() {
236
137
  var e = [];
237
138
  return this.eachBefore(function(t) {
238
139
  t.children || e.push(t);
239
140
  }), e;
240
141
  }
241
- function Ht() {
142
+ function Ct() {
242
143
  var e = this, t = [];
243
144
  return e.each(function(n) {
244
145
  n !== e && t.push({ source: n.parent, target: n });
245
146
  }), t;
246
147
  }
247
- function F(e, t) {
248
- var n = new N(e), i = +e.value && (n.value = e.value), o, a = [n], c, s, l, p;
249
- for (t == null && (t = Lt); o = a.pop(); )
250
- if (i && (o.value = +o.data.value), (s = t(o.data)) && (p = s.length))
251
- for (o.children = new Array(p), l = p - 1; l >= 0; --l)
252
- a.push(c = o.children[l] = new N(s[l])), c.parent = o, c.depth = o.depth + 1;
253
- return n.eachBefore(Vt);
148
+ function O(e, t) {
149
+ var n = new E(e), r = +e.value && (n.value = e.value), s, l = [n], c, i, a, d;
150
+ for (t == null && (t = Xt); s = l.pop(); )
151
+ if (r && (s.value = +s.data.value), (i = t(s.data)) && (d = i.length))
152
+ for (s.children = new Array(d), a = d - 1; a >= 0; --a)
153
+ l.push(c = s.children[a] = new E(i[a])), c.parent = s, c.depth = s.depth + 1;
154
+ return n.eachBefore(jt);
254
155
  }
255
- function It() {
256
- return F(this).eachBefore(Wt);
156
+ function wt() {
157
+ return O(this).eachBefore(Rt);
257
158
  }
258
- function Lt(e) {
159
+ function Xt(e) {
259
160
  return e.children;
260
161
  }
261
- function Wt(e) {
162
+ function Rt(e) {
262
163
  e.data = e.data.data;
263
164
  }
264
- function Vt(e) {
165
+ function jt(e) {
265
166
  var t = 0;
266
167
  do
267
168
  e.height = t;
268
169
  while ((e = e.parent) && e.height < ++t);
269
170
  }
270
- function N(e) {
171
+ function E(e) {
271
172
  this.data = e, this.depth = this.height = 0, this.parent = null;
272
173
  }
273
- N.prototype = F.prototype = {
274
- constructor: N,
275
- count: Nt,
276
- each: Rt,
277
- eachAfter: Tt,
278
- eachBefore: Mt,
279
- sum: At,
280
- sort: _t,
281
- path: Ot,
282
- ancestors: $t,
283
- descendants: Bt,
284
- leaves: Ft,
285
- links: Ht,
286
- copy: It
174
+ E.prototype = O.prototype = {
175
+ constructor: E,
176
+ count: mt,
177
+ each: gt,
178
+ eachAfter: xt,
179
+ eachBefore: ft,
180
+ sum: yt,
181
+ sort: kt,
182
+ path: vt,
183
+ ancestors: zt,
184
+ descendants: St,
185
+ leaves: Et,
186
+ links: Ct,
187
+ copy: wt
287
188
  };
288
- const Yt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index", Gt = {
289
- name: "Chris Maloney",
290
- url: "http://chrismaloney.org"
291
- }, Zt = "Flexible tree layout algorithm that allows for variable node sizes.", qt = [
292
- "d3",
293
- "d3-module",
294
- "layout",
295
- "tree",
296
- "hierarchy",
297
- "d3-hierarchy",
298
- "plugin",
299
- "d3-plugin",
300
- "infovis",
301
- "visualization",
302
- "2d"
303
- ], Jt = "https://github.com/klortho/d3-flextree", Qt = "WTFPL", te = {
304
- type: "git",
305
- url: "https://github.com/klortho/d3-flextree.git"
306
- }, ee = {
307
- clean: "rm -rf build demo test",
308
- "build:demo": "rollup -c --environment BUILD:demo",
309
- "build:dev": "rollup -c --environment BUILD:dev",
310
- "build:prod": "rollup -c --environment BUILD:prod",
311
- "build:test": "rollup -c --environment BUILD:test",
312
- build: "rollup -c",
313
- lint: "eslint index.js src",
314
- "test:main": "node test/bundle.js",
315
- "test:browser": "node test/browser-tests.js",
316
- test: "npm-run-all test:*",
317
- prepare: "npm-run-all clean build lint test"
318
- }, ne = {
319
- "d3-hierarchy": "^1.1.5"
320
- }, ie = {
321
- "babel-plugin-external-helpers": "^6.22.0",
322
- "babel-preset-es2015-rollup": "^3.0.0",
323
- d3: "^4.13.0",
324
- "d3-selection-multi": "^1.0.1",
325
- eslint: "^4.19.1",
326
- jsdom: "^11.6.2",
327
- "npm-run-all": "^4.1.2",
328
- rollup: "^0.55.3",
329
- "rollup-plugin-babel": "^2.7.1",
330
- "rollup-plugin-commonjs": "^8.0.2",
331
- "rollup-plugin-copy": "^0.2.3",
332
- "rollup-plugin-json": "^2.3.0",
333
- "rollup-plugin-node-resolve": "^3.0.2",
334
- "rollup-plugin-uglify": "^3.0.0",
335
- "uglify-es": "^3.3.9"
336
- }, re = {
337
- name: Yt,
338
- version: Kt,
339
- main: Pt,
340
- module: Ut,
189
+ const Mt = "d3-flextree", Bt = "2.1.2", Ot = "build/d3-flextree.js", $t = "index", At = { name: "Chris Maloney", url: "http://chrismaloney.org" }, Ft = "Flexible tree layout algorithm that allows for variable node sizes.", Dt = ["d3", "d3-module", "layout", "tree", "hierarchy", "d3-hierarchy", "plugin", "d3-plugin", "infovis", "visualization", "2d"], Tt = "https://github.com/klortho/d3-flextree", _t = "WTFPL", Ht = { type: "git", url: "https://github.com/klortho/d3-flextree.git" }, Lt = { clean: "rm -rf build demo test", "build:demo": "rollup -c --environment BUILD:demo", "build:dev": "rollup -c --environment BUILD:dev", "build:prod": "rollup -c --environment BUILD:prod", "build:test": "rollup -c --environment BUILD:test", build: "rollup -c", lint: "eslint index.js src", "test:main": "node test/bundle.js", "test:browser": "node test/browser-tests.js", test: "npm-run-all test:*", prepare: "npm-run-all clean build lint test" }, Nt = { "d3-hierarchy": "^1.1.5" }, Pt = { "babel-plugin-external-helpers": "^6.22.0", "babel-preset-es2015-rollup": "^3.0.0", d3: "^4.13.0", "d3-selection-multi": "^1.0.1", eslint: "^4.19.1", jsdom: "^11.6.2", "npm-run-all": "^4.1.2", rollup: "^0.55.3", "rollup-plugin-babel": "^2.7.1", "rollup-plugin-commonjs": "^8.0.2", "rollup-plugin-copy": "^0.2.3", "rollup-plugin-json": "^2.3.0", "rollup-plugin-node-resolve": "^3.0.2", "rollup-plugin-uglify": "^3.0.0", "uglify-es": "^3.3.9" }, Wt = {
190
+ name: Mt,
191
+ version: Bt,
192
+ main: Ot,
193
+ module: $t,
341
194
  "jsnext:main": "index",
342
- author: Gt,
343
- description: Zt,
344
- keywords: qt,
345
- homepage: Jt,
346
- license: Qt,
347
- repository: te,
348
- scripts: ee,
349
- dependencies: ne,
350
- devDependencies: ie
351
- }, { version: oe } = re, se = Object.freeze({
195
+ author: At,
196
+ description: Ft,
197
+ keywords: Dt,
198
+ homepage: Tt,
199
+ license: _t,
200
+ repository: Ht,
201
+ scripts: Lt,
202
+ dependencies: Nt,
203
+ devDependencies: Pt
204
+ }, { version: It } = Wt, Kt = Object.freeze({
352
205
  children: (e) => e.children,
353
206
  nodeSize: (e) => e.data.size,
354
207
  spacing: 0
355
208
  });
356
- function q(e) {
357
- const t = Object.assign({}, se, e);
358
- function n(s) {
359
- const l = t[s];
360
- return typeof l == "function" ? l : () => l;
209
+ function K(e) {
210
+ const t = Object.assign({}, Kt, e);
211
+ function n(i) {
212
+ const a = t[i];
213
+ return typeof a == "function" ? a : () => a;
361
214
  }
362
- function i(s) {
363
- const l = c(a(), s, (p) => p.children);
364
- return l.update(), l.data;
215
+ function r(i) {
216
+ const a = c(l(), i, (d) => d.children);
217
+ return a.update(), a.data;
365
218
  }
366
- function o() {
367
- const s = n("nodeSize"), l = n("spacing");
368
- return class Z extends F.prototype.constructor {
219
+ function s() {
220
+ const i = n("nodeSize"), a = n("spacing");
221
+ return class I extends O.prototype.constructor {
369
222
  constructor(h) {
370
223
  super(h);
371
224
  }
372
225
  copy() {
373
- const h = c(this.constructor, this, (u) => u.children);
374
- return h.each((u) => u.data = u.data.data), h;
226
+ const h = c(this.constructor, this, (p) => p.children);
227
+ return h.each((p) => p.data = p.data.data), h;
375
228
  }
376
229
  get size() {
377
- return s(this);
230
+ return i(this);
378
231
  }
379
232
  spacing(h) {
380
- return l(this, h);
233
+ return a(this, h);
381
234
  }
382
235
  get nodes() {
383
236
  return this.descendants();
@@ -421,7 +274,7 @@ function q(e) {
421
274
  }
422
275
  get extents() {
423
276
  return (this.children || []).reduce(
424
- (h, u) => Z.maxExtents(h, u.extents),
277
+ (h, p) => I.maxExtents(h, p.extents),
425
278
  this.nodeExtents
426
279
  );
427
280
  }
@@ -433,19 +286,19 @@ function q(e) {
433
286
  right: this.right
434
287
  };
435
288
  }
436
- static maxExtents(h, u) {
289
+ static maxExtents(h, p) {
437
290
  return {
438
- top: Math.min(h.top, u.top),
439
- bottom: Math.max(h.bottom, u.bottom),
440
- left: Math.min(h.left, u.left),
441
- right: Math.max(h.right, u.right)
291
+ top: Math.min(h.top, p.top),
292
+ bottom: Math.max(h.bottom, p.bottom),
293
+ left: Math.min(h.left, p.left),
294
+ right: Math.max(h.right, p.right)
442
295
  };
443
296
  }
444
297
  };
445
298
  }
446
- function a() {
447
- const s = o(), l = n("nodeSize"), p = n("spacing");
448
- return class extends s {
299
+ function l() {
300
+ const i = s(), a = n("nodeSize"), d = n("spacing");
301
+ return class extends i {
449
302
  constructor(h) {
450
303
  super(h), Object.assign(this, {
451
304
  x: 0,
@@ -463,10 +316,10 @@ function q(e) {
463
316
  });
464
317
  }
465
318
  get size() {
466
- return l(this.data);
319
+ return a(this.data);
467
320
  }
468
321
  spacing(h) {
469
- return p(this.data, h.data);
322
+ return d(this.data, h.data);
470
323
  }
471
324
  get x() {
472
325
  return this.data.x;
@@ -481,112 +334,112 @@ function q(e) {
481
334
  this.data.y = h;
482
335
  }
483
336
  update() {
484
- return J(this), Q(this), this;
337
+ return G(this), U(this), this;
485
338
  }
486
339
  };
487
340
  }
488
- function c(s, l, p) {
489
- const h = (u, g) => {
490
- const x = new s(u);
491
- Object.assign(x, {
492
- parent: g,
493
- depth: g === null ? 0 : g.depth + 1,
341
+ function c(i, a, d) {
342
+ const h = (p, u) => {
343
+ const g = new i(p);
344
+ Object.assign(g, {
345
+ parent: u,
346
+ depth: u === null ? 0 : u.depth + 1,
494
347
  height: 0,
495
348
  length: 1
496
349
  });
497
- const m = p(u) || [];
498
- return x.children = m.length === 0 ? null : m.map((y) => h(y, x)), x.children && Object.assign(x, x.children.reduce(
499
- (y, f) => ({
500
- height: Math.max(y.height, f.height + 1),
501
- length: y.length + f.length
350
+ const f = d(p) || [];
351
+ return g.children = f.length === 0 ? null : f.map((x) => h(x, g)), g.children && Object.assign(g, g.children.reduce(
352
+ (x, v) => ({
353
+ height: Math.max(x.height, v.height + 1),
354
+ length: x.length + v.length
502
355
  }),
503
- x
504
- )), x;
356
+ g
357
+ )), g;
505
358
  };
506
- return h(l, null);
359
+ return h(a, null);
507
360
  }
508
- return Object.assign(i, {
509
- nodeSize(s) {
510
- return arguments.length ? (t.nodeSize = s, i) : t.nodeSize;
361
+ return Object.assign(r, {
362
+ nodeSize(i) {
363
+ return arguments.length ? (t.nodeSize = i, r) : t.nodeSize;
511
364
  },
512
- spacing(s) {
513
- return arguments.length ? (t.spacing = s, i) : t.spacing;
365
+ spacing(i) {
366
+ return arguments.length ? (t.spacing = i, r) : t.spacing;
514
367
  },
515
- children(s) {
516
- return arguments.length ? (t.children = s, i) : t.children;
368
+ children(i) {
369
+ return arguments.length ? (t.children = i, r) : t.children;
517
370
  },
518
- hierarchy(s, l) {
519
- const p = typeof l > "u" ? t.children : l;
520
- return c(o(), s, p);
371
+ hierarchy(i, a) {
372
+ const d = typeof a > "u" ? t.children : a;
373
+ return c(s(), i, d);
521
374
  },
522
- dump(s) {
523
- const l = n("nodeSize"), p = (h) => (u) => {
524
- const g = h + " ", x = h + " ", { x: m, y } = u, f = l(u), k = u.children || [], v = k.length === 0 ? " " : `,${g}children: [${x}${k.map(p(x)).join(x)}${g}],${h}`;
525
- return `{ size: [${f.join(", ")}],${g}x: ${m}, y: ${y}${v}},`;
375
+ dump(i) {
376
+ const a = n("nodeSize"), d = (h) => (p) => {
377
+ const u = h + " ", g = h + " ", { x: f, y: x } = p, v = a(p), k = p.children || [], z = k.length === 0 ? " " : `,${u}children: [${g}${k.map(d(g)).join(g)}${u}],${h}`;
378
+ return `{ size: [${v.join(", ")}],${u}x: ${f}, y: ${x}${z}},`;
526
379
  };
527
- return p(`
528
- `)(s);
380
+ return d(`
381
+ `)(i);
529
382
  }
530
- }), i;
531
- }
532
- q.version = oe;
533
- const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, i) => {
534
- const [o, a] = n;
535
- J(i, e.y + e.ySize);
536
- const c = (o === 0 ? i.lExt : i.rExt).bottom;
537
- o !== 0 && le(e, o, a);
538
- const s = ge(c, o, a);
539
- return [o + 1, s];
540
- }, [0, null]), ae(e), fe(e), e), Q = (e, t, n) => {
383
+ }), r;
384
+ }
385
+ K.version = It;
386
+ const G = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, r) => {
387
+ const [s, l] = n;
388
+ G(r, e.y + e.ySize);
389
+ const c = (s === 0 ? r.lExt : r.rExt).bottom;
390
+ s !== 0 && Ut(e, s, l);
391
+ const i = ee(c, s, l);
392
+ return [s + 1, i];
393
+ }, [0, null]), Gt(e), te(e), e), U = (e, t, n) => {
541
394
  typeof t > "u" && (t = -e.relX - e.prelim, n = 0);
542
- const i = t + e.relX;
543
- return e.relX = i + e.prelim - n, e.prelim = 0, e.x = n + e.relX, (e.children || []).forEach((o) => Q(o, i, e.x)), e;
544
- }, ae = (e) => {
395
+ const r = t + e.relX;
396
+ return e.relX = r + e.prelim - n, e.prelim = 0, e.x = n + e.relX, (e.children || []).forEach((s) => U(s, r, e.x)), e;
397
+ }, Gt = (e) => {
545
398
  (e.children || []).reduce((t, n) => {
546
- const [i, o] = t, a = i + n.shift, c = o + a + n.change;
547
- return n.relX += c, [a, c];
399
+ const [r, s] = t, l = r + n.shift, c = s + l + n.change;
400
+ return n.relX += c, [l, c];
548
401
  }, [0, 0]);
549
- }, le = (e, t, n) => {
550
- const i = e.children[t - 1], o = e.children[t];
551
- let a = i, c = i.relX, s = o, l = o.relX, p = !0;
552
- for (; a && s; ) {
553
- a.bottom > n.lowY && (n = n.next);
554
- const h = c + a.prelim - (l + s.prelim) + a.xSize / 2 + s.xSize / 2 + a.spacing(s);
555
- (h > 0 || h < 0 && p) && (l += h, ce(o, h), he(e, t, n.index, h)), p = !1;
556
- const u = a.bottom, g = s.bottom;
557
- u <= g && (a = ue(a), a && (c += a.relX)), u >= g && (s = de(s), s && (l += s.relX));
402
+ }, Ut = (e, t, n) => {
403
+ const r = e.children[t - 1], s = e.children[t];
404
+ let l = r, c = r.relX, i = s, a = s.relX, d = !0;
405
+ for (; l && i; ) {
406
+ l.bottom > n.lowY && (n = n.next);
407
+ const h = c + l.prelim - (a + i.prelim) + l.xSize / 2 + i.xSize / 2 + l.spacing(i);
408
+ (h > 0 || h < 0 && d) && (a += h, Vt(s, h), Yt(e, t, n.index, h)), d = !1;
409
+ const p = l.bottom, u = i.bottom;
410
+ p <= u && (l = qt(l), l && (c += l.relX)), p >= u && (i = Zt(i), i && (a += i.relX));
558
411
  }
559
- !a && s ? pe(e, t, s, l) : a && !s && me(e, t, a, c);
560
- }, ce = (e, t) => {
412
+ !l && i ? Jt(e, t, i, a) : l && !i && Qt(e, t, l, c);
413
+ }, Vt = (e, t) => {
561
414
  e.relX += t, e.lExtRelX += t, e.rExtRelX += t;
562
- }, he = (e, t, n, i) => {
563
- const o = e.children[t], a = t - n;
564
- if (a > 1) {
565
- const c = i / a;
566
- e.children[n + 1].shift += c, o.shift -= c, o.change -= i - c;
415
+ }, Yt = (e, t, n, r) => {
416
+ const s = e.children[t], l = t - n;
417
+ if (l > 1) {
418
+ const c = r / l;
419
+ e.children[n + 1].shift += c, s.shift -= c, s.change -= r - c;
567
420
  }
568
- }, de = (e) => e.hasChildren ? e.firstChild : e.lThr, ue = (e) => e.hasChildren ? e.lastChild : e.rThr, pe = (e, t, n, i) => {
569
- const o = e.firstChild, a = o.lExt, c = e.children[t];
570
- a.lThr = n;
571
- const s = i - n.relX - o.lExtRelX;
572
- a.relX += s, a.prelim -= s, o.lExt = c.lExt, o.lExtRelX = c.lExtRelX;
573
- }, me = (e, t, n, i) => {
574
- const o = e.children[t], a = o.rExt, c = e.children[t - 1];
575
- a.rThr = n;
576
- const s = i - n.relX - o.rExtRelX;
577
- a.relX += s, a.prelim -= s, o.rExt = c.rExt, o.rExtRelX = c.rExtRelX;
578
- }, fe = (e) => {
421
+ }, Zt = (e) => e.hasChildren ? e.firstChild : e.lThr, qt = (e) => e.hasChildren ? e.lastChild : e.rThr, Jt = (e, t, n, r) => {
422
+ const s = e.firstChild, l = s.lExt, c = e.children[t];
423
+ l.lThr = n;
424
+ const i = r - n.relX - s.lExtRelX;
425
+ l.relX += i, l.prelim -= i, s.lExt = c.lExt, s.lExtRelX = c.lExtRelX;
426
+ }, Qt = (e, t, n, r) => {
427
+ const s = e.children[t], l = s.rExt, c = e.children[t - 1];
428
+ l.rThr = n;
429
+ const i = r - n.relX - s.rExtRelX;
430
+ l.relX += i, l.prelim -= i, s.rExt = c.rExt, s.rExtRelX = c.rExtRelX;
431
+ }, te = (e) => {
579
432
  if (e.hasChildren) {
580
- const t = e.firstChild, n = e.lastChild, i = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
433
+ const t = e.firstChild, n = e.lastChild, r = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
581
434
  Object.assign(e, {
582
- prelim: i,
435
+ prelim: r,
583
436
  lExt: t.lExt,
584
437
  lExtRelX: t.lExtRelX,
585
438
  rExt: n.rExt,
586
439
  rExtRelX: n.rExtRelX
587
440
  });
588
441
  }
589
- }, ge = (e, t, n) => {
442
+ }, ee = (e, t, n) => {
590
443
  for (; n !== null && e >= n.lowY; )
591
444
  n = n.next;
592
445
  return {
@@ -594,133 +447,131 @@ const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, i) => {
594
447
  index: t,
595
448
  next: n
596
449
  };
597
- }, xe = ".markmap-container{position:absolute;width:0;height:0;top:-100px;left:-100px;overflow:hidden}.markmap-container>.markmap-foreign{display:inline-block}.markmap-container>.markmap-foreign>div:last-child,.markmap-container>.markmap-foreign>div:last-child :not(pre){white-space:nowrap}.markmap-container>.markmap-foreign>div:last-child code{white-space:inherit}", tt = ".markmap{--markmap-max-width: none;--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;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{padding:.25em;font-size:calc(1em - 2px);color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign-testing-max{max-width:var(--markmap-max-width)}.markmap-foreign-testing-max img{max-width:var(--markmap-max-width);max-height:none}.markmap-dark .markmap{--markmap-code-bg: #1a1b26;--markmap-code-color: #ddd;--markmap-circle-open-bg: #444;--markmap-text-color: #eee}", be = tt;
598
- function W(e) {
599
- const t = e.data;
600
- return Math.max(4 - 2 * t.state.depth, 1.5);
450
+ }, V = ".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;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{padding:.25em;font-size:calc(1em - 2px);color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign>div{width:var(--markmap-max-width)}.markmap-foreign>div>div{display:inline-block}.markmap-dark .markmap{--markmap-code-bg: #1a1b26;--markmap-code-color: #ddd;--markmap-circle-open-bg: #444;--markmap-text-color: #eee}", oe = V, M = ot();
451
+ function H(e) {
452
+ return Math.max(4 - 2 * e.state.depth, 1.5);
601
453
  }
602
- function V(e, t) {
603
- const n = ft(e, t);
454
+ function L(e, t) {
455
+ const n = ht(e, t);
604
456
  return e[n];
605
457
  }
606
- function D(e) {
458
+ function B(e) {
607
459
  e.stopPropagation();
608
460
  }
609
- const ye = new st();
610
- class et {
461
+ const ne = new et();
462
+ class Y {
611
463
  constructor(t, n) {
612
- this.options = P, this.revokers = [], this.imgCache = {}, this.handleZoom = (i) => {
613
- const { transform: o } = i;
614
- this.g.attr("transform", o);
615
- }, this.handlePan = (i) => {
616
- i.preventDefault();
617
- const o = A(this.svg.node()), a = o.translate(
618
- -i.deltaX / o.k,
619
- -i.deltaY / o.k
464
+ this.options = W, this.revokers = [], this.handleZoom = (r) => {
465
+ const { transform: s } = r;
466
+ this.g.attr("transform", s);
467
+ }, this.handlePan = (r) => {
468
+ r.preventDefault();
469
+ const s = j(this.svg.node()), l = s.translate(
470
+ -r.deltaX / s.k,
471
+ -r.deltaY / s.k
620
472
  );
621
- this.svg.call(this.zoom.transform, a);
622
- }, this.handleClick = (i, o) => {
623
- let a = this.options.toggleRecursively;
624
- (K ? i.metaKey : i.ctrlKey) && (a = !a), this.toggleNode(o.data, a);
625
- }, this.svg = t.datum ? t : dt(t), this.styleNode = this.svg.append("style"), this.zoom = ut().filter((i) => this.options.scrollForPan && i.type === "wheel" ? i.ctrlKey && !i.button : (!i.ctrlKey || i.type === "wheel") && !i.button).on("zoom", this.handleZoom), this.setOptions(n), this.state = {
626
- id: this.options.id || this.svg.attr("id") || at(),
627
- minX: 0,
628
- maxX: 0,
629
- minY: 0,
630
- maxY: 0
631
- }, this.g = this.svg.append("g"), this.debouncedRefresh = lt(() => this.setData(), 200), this.revokers.push(
632
- ye.tap(() => {
473
+ this.svg.call(this.zoom.transform, l);
474
+ }, this.handleClick = (r, s) => {
475
+ let l = this.options.toggleRecursively;
476
+ (P ? r.metaKey : r.ctrlKey) && (l = !l), this.toggleNode(s, l);
477
+ }, this.svg = t.datum ? t : at(t), this.styleNode = this.svg.append("style"), this.zoom = lt().filter((r) => this.options.scrollForPan && r.type === "wheel" ? r.ctrlKey && !r.button : (!r.ctrlKey || r.type === "wheel") && !r.button).on("zoom", this.handleZoom), this.setOptions(n), this.state = {
478
+ id: this.options.id || this.svg.attr("id") || nt(),
479
+ rect: { x1: 0, y1: 0, x2: 0, y2: 0 }
480
+ }, this.g = this.svg.append("g"), this.observer = new ResizeObserver(
481
+ rt(() => {
482
+ this.renderData();
483
+ }, 100)
484
+ ), this.revokers.push(
485
+ ne.tap(() => {
633
486
  this.setData();
634
487
  })
635
488
  );
636
489
  }
637
490
  getStyleContent() {
638
- const { style: t } = this.options, { id: n } = this.state, i = typeof t == "function" ? t(n) : "";
639
- return [this.options.embedGlobalCSS && tt, i].filter(Boolean).join(`
491
+ const { style: t } = this.options, { id: n } = this.state, r = typeof t == "function" ? t(n) : "";
492
+ return [this.options.embedGlobalCSS && V, r].filter(Boolean).join(`
640
493
  `);
641
494
  }
642
495
  updateStyle() {
643
496
  this.svg.attr(
644
497
  "class",
645
- ct(this.svg.attr("class"), "markmap", this.state.id)
498
+ it(this.svg.attr("class"), "markmap", this.state.id)
646
499
  );
647
500
  const t = this.getStyleContent();
648
501
  this.styleNode.text(t);
649
502
  }
650
- toggleNode(t, n = !1) {
651
- var o, a;
652
- const i = (o = t.payload) != null && o.fold ? 0 : 1;
653
- n ? M(t, (c, s) => {
503
+ async toggleNode(t, n = !1) {
504
+ var s, l;
505
+ const r = (s = t.payload) != null && s.fold ? 0 : 1;
506
+ n ? X(t, (c, i) => {
654
507
  c.payload = {
655
508
  ...c.payload,
656
- fold: i
657
- }, s();
509
+ fold: r
510
+ }, i();
658
511
  }) : t.payload = {
659
512
  ...t.payload,
660
- fold: (a = t.payload) != null && a.fold ? 0 : 1
661
- }, this.renderData(t);
513
+ fold: (l = t.payload) != null && l.fold ? 0 : 1
514
+ }, await this.renderData(t);
662
515
  }
663
- initializeData(t) {
516
+ _initializeData(t) {
664
517
  let n = 0;
665
- const { color: i, nodeMinHeight: o, maxWidth: a, initialExpandLevel: c } = this.options, { id: s } = this.state, l = O(
666
- /* @__PURE__ */ j("div", { className: `markmap-container markmap ${s}-g` })
667
- ), p = O(
668
- /* @__PURE__ */ j("style", { children: [this.getStyleContent(), xe].join(`
669
- `) })
670
- );
671
- document.body.append(l, p);
672
- const h = a ? `--markmap-max-width: ${a}px` : "";
673
- let u = 0, g = 0;
674
- M(t, (m, y, f) => {
675
- var b, w, z;
676
- g += 1, m.children = (b = m.children) == null ? void 0 : b.map((E) => ({ ...E })), n += 1;
677
- const k = O(
678
- /* @__PURE__ */ j(
679
- "div",
680
- {
681
- className: "markmap-foreign markmap-foreign-testing-max",
682
- style: h,
683
- children: /* @__PURE__ */ j("div", { dangerouslySetInnerHTML: { __html: m.content } })
684
- }
685
- )
686
- );
687
- l.append(k), m.state = {
688
- ...m.state,
689
- depth: g,
518
+ const { color: r, initialExpandLevel: s } = this.options;
519
+ let l = 0, c = 0;
520
+ X(t, (i, a, d) => {
521
+ var p, u, g, f;
522
+ c += 1, i.children = (p = i.children) == null ? void 0 : p.map((x) => ({ ...x })), n += 1, i.state = {
523
+ ...i.state,
524
+ depth: c,
690
525
  id: n,
691
- el: k.firstChild
692
- }, m.state.path = [(w = f == null ? void 0 : f.state) == null ? void 0 : w.path, m.state.id].filter(Boolean).join("."), i(m);
693
- const v = ((z = m.payload) == null ? void 0 : z.fold) === 2;
694
- v ? u += 1 : (u || c >= 0 && m.state.depth >= c) && (m.payload = { ...m.payload, fold: 1 }), y(), v && (u -= 1), g -= 1;
526
+ rect: {
527
+ x: 0,
528
+ y: 0,
529
+ width: 0,
530
+ height: 0
531
+ },
532
+ size: [0, 0]
533
+ }, i.state.key = [(u = d == null ? void 0 : d.state) == null ? void 0 : u.id, i.state.id].filter(Boolean).join(".") + pt(i.content), i.state.path = [(g = d == null ? void 0 : d.state) == null ? void 0 : g.path, i.state.id].filter(Boolean).join("."), r(i);
534
+ const h = ((f = i.payload) == null ? void 0 : f.fold) === 2;
535
+ h ? l += 1 : (l || s >= 0 && i.state.depth >= s) && (i.payload = { ...i.payload, fold: 1 }), a(), h && (l -= 1), c -= 1;
695
536
  });
696
- const x = Array.from(l.childNodes).map(
697
- (m) => m.firstChild
698
- );
699
- this._checkImages(l), x.forEach((m) => {
700
- var y;
701
- (y = m.parentNode) == null || y.append(m.cloneNode(!0));
702
- }), M(t, (m, y, f) => {
703
- var b;
704
- const k = m.state, v = k.el.getBoundingClientRect();
705
- m.content = k.el.innerHTML, k.size = [
706
- Math.ceil(v.width) + 1,
707
- Math.max(Math.ceil(v.height), o)
708
- ], k.key = [(b = f == null ? void 0 : f.state) == null ? void 0 : b.id, k.id].filter(Boolean).join(".") + // FIXME: find a way to check content hash
709
- m.content, y();
710
- }), l.remove(), p.remove();
711
537
  }
712
- _checkImages(t) {
713
- t.querySelectorAll("img").forEach((n) => {
714
- if (n.width) return;
715
- const i = this.imgCache[n.src];
716
- i != null && i[0] ? [n.width, n.height] = i : i || this._loadImage(n.src);
538
+ _relayout() {
539
+ if (!this.state.data) return;
540
+ this.g.selectAll(b("g")).selectAll(
541
+ b("foreignObject")
542
+ ).each(function(i) {
543
+ var h;
544
+ const a = (h = this.firstChild) == null ? void 0 : h.firstChild, d = [a.scrollWidth, a.scrollHeight];
545
+ i.state.size = d;
717
546
  });
718
- }
719
- _loadImage(t) {
720
- this.imgCache[t] = [0, 0];
721
- const n = new Image();
722
- n.src = t, n.onload = () => {
723
- this.imgCache[t] = [n.naturalWidth, n.naturalHeight], this.debouncedRefresh();
547
+ const { spacingHorizontal: t, paddingX: n, spacingVertical: r } = this.options, s = K({}).children((i) => {
548
+ var a;
549
+ if (!((a = i.payload) != null && a.fold)) return i.children;
550
+ }).nodeSize((i) => {
551
+ const [a, d] = i.data.state.size;
552
+ return [d, a + (a ? n * 2 : 0) + t];
553
+ }).spacing((i, a) => i.parent === a.parent ? r : r * 2), l = s.hierarchy(this.state.data);
554
+ s(l);
555
+ const c = l.descendants();
556
+ c.forEach((i) => {
557
+ const a = i.data;
558
+ a.state.rect = {
559
+ x: i.y,
560
+ y: i.x,
561
+ width: i.ySize - t,
562
+ height: i.xSize
563
+ };
564
+ }), this.state.rect = {
565
+ x1: T(c, (i) => i.data.state.rect.x) || 0,
566
+ y1: T(c, (i) => i.data.state.rect.y) || 0,
567
+ x2: _(
568
+ c,
569
+ (i) => i.data.state.rect.x + i.data.state.rect.width
570
+ ) || 0,
571
+ y2: _(
572
+ c,
573
+ (i) => i.data.state.rect.y + i.data.state.rect.height
574
+ ) || 0
724
575
  };
725
576
  }
726
577
  setOptions(t) {
@@ -729,127 +580,99 @@ class et {
729
580
  ...t
730
581
  }, 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);
731
582
  }
732
- setData(t, n) {
733
- n && this.setOptions(n), t && (this.state.data = t), this.state.data && (this.initializeData(this.state.data), this.updateStyle(), this.renderData());
583
+ async setData(t, n) {
584
+ n && this.setOptions(n), t && (this.state.data = t), this.state.data && (this._initializeData(this.state.data), this.updateStyle(), await this.renderData());
734
585
  }
735
- renderData(t) {
586
+ async renderData(t) {
587
+ const { paddingX: n, autoFit: r, color: s, maxWidth: l } = this.options;
736
588
  if (!this.state.data) return;
737
- const { spacingHorizontal: n, paddingX: i, spacingVertical: o, autoFit: a, color: c } = this.options, s = q({}).children((r) => {
738
- var d;
739
- if (!((d = r.payload) != null && d.fold)) return r.children;
740
- }).nodeSize((r) => {
741
- const [d, S] = r.data.state.size;
742
- return [S, d + (d ? i * 2 : 0) + n];
743
- }).spacing((r, d) => r.parent === d.parent ? o : o * 2), l = s.hierarchy(this.state.data);
744
- s(l);
745
- const p = l.descendants().reverse(), h = l.links(), u = pt(), g = H(p, (r) => r.x - r.xSize / 2), x = I(p, (r) => r.x + r.xSize / 2), m = H(p, (r) => r.y), y = I(p, (r) => r.y + r.ySize - n);
746
- Object.assign(this.state, {
747
- minX: g,
748
- maxX: x,
749
- minY: m,
750
- maxY: y
751
- }), a && this.fit();
752
- const f = t && p.find((r) => r.data === t) || l, k = f.data.state.x0 ?? f.x, v = f.data.state.y0 ?? f.y, b = this.g.selectAll(C("g")).data(p, (r) => r.data.state.key), w = b.enter().append("g").attr("data-depth", (r) => r.data.state.depth).attr("data-path", (r) => r.data.state.path).attr(
753
- "transform",
754
- (r) => `translate(${v + f.ySize - r.ySize},${k + f.xSize / 2 - r.xSize})`
755
- ), z = this.transition(b.exit());
756
- z.select("line").attr("x1", (r) => r.ySize - n).attr("x2", (r) => r.ySize - n), z.select("foreignObject").style("opacity", 0), z.attr(
757
- "transform",
758
- (r) => `translate(${f.y + f.ySize - r.ySize},${f.x + f.xSize / 2 - r.xSize})`
759
- ).remove();
760
- const E = b.merge(w).attr(
589
+ const c = [];
590
+ X(this.state.data, (o, m) => {
591
+ var y;
592
+ (y = o.payload) != null && y.fold || m(), c.push(o);
593
+ });
594
+ const a = (t || this.state.data).state.rect, d = this.g.selectAll(b("g")).data(c, (o) => o.state.key), h = d.enter().append("g").attr("data-depth", (o) => o.state.depth).attr("data-path", (o) => o.state.path), p = d.exit(), u = d.merge(h).attr(
761
595
  "class",
762
- (r) => {
763
- var d;
764
- return ["markmap-node", ((d = r.data.payload) == null ? void 0 : d.fold) && "markmap-fold"].filter(Boolean).join(" ");
765
- }
766
- );
767
- this.transition(E).attr(
768
- "transform",
769
- (r) => `translate(${r.y},${r.x - r.xSize / 2})`
770
- );
771
- const nt = E.selectAll(
772
- C("line")
596
+ (o) => {
597
+ var m;
598
+ return ["markmap-node", ((m = o.payload) == null ? void 0 : m.fold) && "markmap-fold"].filter(Boolean).join(" ");
599
+ }
600
+ ), g = u.selectAll(b("line")).data(
601
+ (o) => [o],
602
+ (o) => o.state.key
603
+ ), f = g.enter().append("line"), x = p.selectAll(
604
+ b("line")
605
+ ), v = g.merge(f), k = u.selectAll(
606
+ b("circle")
773
607
  ).data(
774
- (r) => [r],
775
- (r) => r.data.state.key
776
- ).join(
777
- (r) => r.append("line").attr("x1", (d) => d.ySize - n).attr("x2", (d) => d.ySize - n),
778
- (r) => r,
779
- (r) => r.remove()
780
- );
781
- this.transition(nt).attr("x1", -1).attr("x2", (r) => r.ySize - n + 2).attr("y1", (r) => r.xSize).attr("y2", (r) => r.xSize).attr("stroke", (r) => c(r.data)).attr("stroke-width", W);
782
- const it = E.selectAll(
783
- C("circle")
784
- ).data(
785
- (r) => {
786
- var d;
787
- return (d = r.data.children) != null && d.length ? [r] : [];
608
+ (o) => {
609
+ var m;
610
+ return (m = o.children) != null && m.length ? [o] : [];
788
611
  },
789
- (r) => r.data.state.key
612
+ (o) => o.state.key
790
613
  ).join(
791
- (r) => r.append("circle").attr("stroke-width", "1.5").attr("cx", (d) => d.ySize - n).attr("cy", (d) => d.xSize).attr("r", 0).on("click", (d, S) => this.handleClick(d, S)).on("mousedown", D),
792
- (r) => r,
793
- (r) => r.remove()
614
+ (o) => o.append("circle").attr("stroke-width", "1.5").attr("r", 0).on("click", (m, y) => this.handleClick(m, y)).on("mousedown", B),
615
+ (o) => o,
616
+ (o) => o.remove()
617
+ ), z = this.observer, $ = u.selectAll(b("foreignObject")).data(
618
+ (o) => [o],
619
+ (o) => o.state.key
620
+ ), C = $.enter().append("foreignObject").attr("class", "markmap-foreign").attr("x", n).attr("y", 0).style("opacity", 0).on("mousedown", B).on("dblclick", B);
621
+ C.append("xhtml:div").append("xhtml:div").html((o) => o.content).attr("xmlns", "http://www.w3.org/1999/xhtml"), C.each(function() {
622
+ var m;
623
+ const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
624
+ z.observe(o);
625
+ });
626
+ const A = p.selectAll(
627
+ b("foreignObject")
794
628
  );
795
- this.transition(it).attr("r", 6).attr("cx", (r) => r.ySize - n).attr("cy", (r) => r.xSize).attr("stroke", (r) => c(r.data)).attr(
629
+ A.each(function() {
630
+ var m;
631
+ const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
632
+ z.unobserve(o);
633
+ });
634
+ const F = C.merge($), Z = c.flatMap(
635
+ (o) => {
636
+ var m;
637
+ return (m = o.payload) != null && m.fold ? [] : o.children.map((y) => ({ source: o, target: y }));
638
+ }
639
+ ), w = this.g.selectAll(b("path")).data(Z, (o) => o.target.state.key), q = w.exit(), D = w.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (o) => o.target.state.depth).attr("data-path", (o) => o.target.state.path), J = D.merge(w);
640
+ this.svg.style(
641
+ "--markmap-max-width",
642
+ l ? `${l}px` : null
643
+ ), await new Promise(requestAnimationFrame), this._relayout(), this.transition(p).attr("transform", (o) => {
644
+ const m = a.x + a.width - o.state.rect.width, y = a.y + a.height / 2 - o.state.rect.height;
645
+ return `translate(${m},${y})`;
646
+ }).remove(), h.attr(
647
+ "transform",
648
+ (o) => `translate(${a.x + a.width - o.state.rect.width},${a.y + a.height / 2 - o.state.rect.height})`
649
+ ), this.transition(u).attr(
650
+ "transform",
651
+ (o) => `translate(${o.state.rect.x},${o.state.rect.y - o.state.rect.height / 2})`
652
+ ), this.transition(x).attr("x1", (o) => o.state.rect.width).attr("x2", (o) => o.state.rect.width), f.attr("x1", (o) => o.state.rect.width).attr("x2", (o) => o.state.rect.width), v.attr("y1", (o) => o.state.rect.height).attr("y2", (o) => o.state.rect.height).attr("stroke", (o) => s(o)), this.transition(v).attr("x1", -1).attr("x2", (o) => o.state.rect.width + 2).attr("stroke-width", H), k.attr("cx", (o) => o.state.rect.width).attr("cy", (o) => o.state.rect.height).attr("stroke", (o) => s(o)).attr(
796
653
  "fill",
797
- (r) => {
798
- var d;
799
- return (d = r.data.payload) != null && d.fold && r.data.children ? c(r.data) : "var(--markmap-circle-open-bg)";
800
- }
801
- );
802
- const rt = E.selectAll(
803
- C("foreignObject")
804
- ).data(
805
- (r) => [r],
806
- (r) => r.data.state.key
807
- ).join(
808
- (r) => {
809
- const d = r.append("foreignObject").attr("class", "markmap-foreign").attr("x", i).attr("y", 0).style("opacity", 0).on("mousedown", D).on("dblclick", D);
810
- return d.append("xhtml:div").select(function(R) {
811
- const X = R.data.state.el.cloneNode(!0);
812
- return this.replaceWith(X), X;
813
- }).attr("xmlns", "http://www.w3.org/1999/xhtml"), d;
814
- },
815
- (r) => r,
816
- (r) => r.remove()
817
- ).attr(
818
- "width",
819
- (r) => Math.max(0, r.ySize - n - i * 2)
820
- ).attr("height", (r) => r.xSize);
821
- this.transition(rt).style("opacity", 1);
822
- const ot = this.g.selectAll(
823
- C("path")
824
- ).data(h, (r) => r.target.data.state.key).join(
825
- (r) => {
826
- const d = [
827
- v + f.ySize - n,
828
- k + f.xSize / 2
829
- ];
830
- return r.insert("path", "g").attr("class", "markmap-link").attr("data-depth", (S) => S.target.data.state.depth).attr("data-path", (S) => S.target.data.state.path).attr("d", u({ source: d, target: d }));
831
- },
832
- (r) => r,
833
- (r) => {
834
- const d = [
835
- f.y + f.ySize - n,
836
- f.x + f.xSize / 2
837
- ];
838
- return this.transition(r).attr("d", u({ source: d, target: d })).remove();
839
- }
840
- );
841
- this.transition(ot).attr("stroke", (r) => c(r.target.data)).attr("stroke-width", (r) => W(r.target)).attr("d", (r) => {
842
- const d = r.source, S = r.target, R = [
843
- d.y + d.ySize - n,
844
- d.x + d.xSize / 2
845
- ], X = [
846
- S.y,
847
- S.x + S.xSize / 2
654
+ (o) => {
655
+ var m;
656
+ return (m = o.payload) != null && m.fold && o.children ? s(o) : "var(--markmap-circle-open-bg)";
657
+ }
658
+ ), this.transition(k).attr("r", 6), this.transition(A).style("opacity", 0), F.attr("width", (o) => Math.max(0, o.state.rect.width - n * 2)).attr("height", (o) => o.state.rect.height), this.transition(F).style("opacity", 1);
659
+ const S = [
660
+ a.x + a.width,
661
+ a.y + a.height / 2
662
+ ];
663
+ this.transition(q).attr("d", M({ source: S, target: S })).remove(), D.attr(
664
+ "d",
665
+ M({ source: S, target: S })
666
+ ), this.transition(J).attr("stroke", (o) => s(o.target)).attr("stroke-width", (o) => H(o.target)).attr("d", (o) => {
667
+ const m = o.source, y = o.target, Q = [
668
+ m.state.rect.x + m.state.rect.width,
669
+ m.state.rect.y + m.state.rect.height / 2
670
+ ], tt = [
671
+ y.state.rect.x,
672
+ y.state.rect.y + y.state.rect.height / 2
848
673
  ];
849
- return u({ source: R, target: X });
850
- }), p.forEach((r) => {
851
- r.data.state.x0 = r.x, r.data.state.y0 = r.y;
852
- });
674
+ return M({ source: Q, target: tt });
675
+ }), r && this.fit();
853
676
  }
854
677
  transition(t) {
855
678
  const { duration: n } = this.options;
@@ -859,21 +682,21 @@ class et {
859
682
  * Fit the content to the viewport.
860
683
  */
861
684
  async fit(t = this.options.maxInitialScale) {
862
- const n = this.svg.node(), { width: i, height: o } = n.getBoundingClientRect(), { fitRatio: a } = this.options, { minX: c, maxX: s, minY: l, maxY: p } = this.state, h = p - l, u = s - c, g = Math.min(
863
- i / h * a,
864
- o / u * a,
685
+ const n = this.svg.node(), { width: r, height: s } = n.getBoundingClientRect(), { fitRatio: l } = this.options, { x1: c, y1: i, x2: a, y2: d } = this.state.rect, h = a - c, p = d - i, u = Math.min(
686
+ r / h * l,
687
+ s / p * l,
865
688
  t
866
- ), x = mt.translate(
867
- (i - h * g) / 2 - l * g,
868
- (o - u * g) / 2 - c * g
869
- ).scale(g);
870
- return this.transition(this.svg).call(this.zoom.transform, x).end().catch(T);
689
+ ), g = ct.translate(
690
+ (r - h * u) / 2 - c * u,
691
+ (s - p * u) / 2 - i * u
692
+ ).scale(u);
693
+ return this.transition(this.svg).call(this.zoom.transform, g).end().catch(R);
871
694
  }
872
695
  findElement(t) {
873
696
  let n;
874
- return this.g.selectAll(C("g")).each(function(o) {
875
- o.data === t && (n = {
876
- data: o,
697
+ return this.g.selectAll(b("g")).each(function(s) {
698
+ s === t && (n = {
699
+ data: s,
877
700
  g: this
878
701
  });
879
702
  }), n;
@@ -882,57 +705,58 @@ class et {
882
705
  * Pan the content to make the provided node visible in the viewport.
883
706
  */
884
707
  async ensureView(t, n) {
885
- var k;
886
- const i = (k = this.findElement(t)) == null ? void 0 : k.data;
887
- if (!i) return;
888
- const o = this.svg.node(), { spacingHorizontal: a } = this.options, c = o.getBoundingClientRect(), s = A(o), [l, p] = [
889
- i.y,
890
- i.y + i.ySize - a + 2
891
- ].map((v) => v * s.k + s.x), [h, u] = [
892
- i.x - i.xSize / 2,
893
- i.x + i.xSize / 2
894
- ].map((v) => v * s.k + s.y), g = {
708
+ var v;
709
+ const r = (v = this.findElement(t)) == null ? void 0 : v.data;
710
+ if (!r) return;
711
+ const s = this.svg.node(), l = s.getBoundingClientRect(), c = j(s), [i, a] = [
712
+ r.state.rect.x,
713
+ r.state.rect.x + r.state.rect.width + 2
714
+ ].map((k) => k * c.k + c.x), [d, h] = [
715
+ r.state.rect.y - r.state.rect.height / 2,
716
+ r.state.rect.y + r.state.rect.height / 2
717
+ ].map((k) => k * c.k + c.y), p = {
895
718
  left: 0,
896
719
  right: 0,
897
720
  top: 0,
898
721
  bottom: 0,
899
722
  ...n
900
- }, x = [g.left - l, c.width - g.right - p], m = [g.top - h, c.height - g.bottom - u], y = x[0] * x[1] > 0 ? V(x, Math.abs) / s.k : 0, f = m[0] * m[1] > 0 ? V(m, Math.abs) / s.k : 0;
901
- if (y || f) {
902
- const v = s.translate(y, f);
903
- return this.transition(this.svg).call(this.zoom.transform, v).end().catch(T);
723
+ }, u = [p.left - i, l.width - p.right - a], g = [p.top - d, l.height - p.bottom - h], f = u[0] * u[1] > 0 ? L(u, Math.abs) / c.k : 0, x = g[0] * g[1] > 0 ? L(g, Math.abs) / c.k : 0;
724
+ if (f || x) {
725
+ const k = c.translate(f, x);
726
+ return this.transition(this.svg).call(this.zoom.transform, k).end().catch(R);
904
727
  }
905
728
  }
906
729
  /**
907
730
  * Scale content with it pinned at the center of the viewport.
908
731
  */
909
732
  async rescale(t) {
910
- const n = this.svg.node(), { width: i, height: o } = n.getBoundingClientRect(), a = i / 2, c = o / 2, s = A(n), l = s.translate(
911
- (a - s.x) * (1 - t) / s.k,
912
- (c - s.y) * (1 - t) / s.k
733
+ const n = this.svg.node(), { width: r, height: s } = n.getBoundingClientRect(), l = r / 2, c = s / 2, i = j(n), a = i.translate(
734
+ (l - i.x) * (1 - t) / i.k,
735
+ (c - i.y) * (1 - t) / i.k
913
736
  ).scale(t);
914
- return this.transition(this.svg).call(this.zoom.transform, l).end().catch(T);
737
+ return this.transition(this.svg).call(this.zoom.transform, a).end().catch(R);
915
738
  }
916
739
  destroy() {
917
740
  this.svg.on(".zoom", null), this.svg.html(null), this.revokers.forEach((t) => {
918
741
  t();
919
742
  });
920
743
  }
921
- static create(t, n, i = null) {
922
- const o = new et(t, n);
923
- return i && (o.setData(i), requestAnimationFrame(() => {
924
- o.fit();
925
- })), o;
744
+ static create(t, n, r = null) {
745
+ const s = new Y(t, n);
746
+ return r && s.setData(r).then(() => {
747
+ s.fit();
748
+ }), s;
926
749
  }
927
750
  }
928
751
  export {
929
- et as Markmap,
930
- gt as defaultColorFn,
931
- P as defaultOptions,
932
- Se as deriveOptions,
933
- be as globalCSS,
934
- K as isMacintosh,
935
- Ce as loadCSS,
936
- we as loadJS,
937
- ye as refreshHook
752
+ Y as Markmap,
753
+ dt as defaultColorFn,
754
+ W as defaultOptions,
755
+ se as deriveOptions,
756
+ oe as globalCSS,
757
+ P as isMacintosh,
758
+ ce as loadCSS,
759
+ he as loadJS,
760
+ ne as refreshHook,
761
+ pt as simpleHash
938
762
  };