markmap-view 0.17.3-alpha.3 → 0.17.3-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,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,244 +51,145 @@ 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 = {
189
+ const Mt = "d3-flextree", Bt = "2.1.2", Ot = "build/d3-flextree.js", $t = "index", At = {
289
190
  name: "Chris Maloney",
290
191
  url: "http://chrismaloney.org"
291
- }, Zt = "Flexible tree layout algorithm that allows for variable node sizes.", qt = [
192
+ }, Dt = "Flexible tree layout algorithm that allows for variable node sizes.", Ft = [
292
193
  "d3",
293
194
  "d3-module",
294
195
  "layout",
@@ -300,10 +201,10 @@ const Yt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
300
201
  "infovis",
301
202
  "visualization",
302
203
  "2d"
303
- ], Jt = "https://github.com/klortho/d3-flextree", Qt = "WTFPL", te = {
204
+ ], Tt = "https://github.com/klortho/d3-flextree", _t = "WTFPL", Ht = {
304
205
  type: "git",
305
206
  url: "https://github.com/klortho/d3-flextree.git"
306
- }, ee = {
207
+ }, Lt = {
307
208
  clean: "rm -rf build demo test",
308
209
  "build:demo": "rollup -c --environment BUILD:demo",
309
210
  "build:dev": "rollup -c --environment BUILD:dev",
@@ -315,9 +216,9 @@ const Yt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
315
216
  "test:browser": "node test/browser-tests.js",
316
217
  test: "npm-run-all test:*",
317
218
  prepare: "npm-run-all clean build lint test"
318
- }, ne = {
219
+ }, Nt = {
319
220
  "d3-hierarchy": "^1.1.5"
320
- }, ie = {
221
+ }, Pt = {
321
222
  "babel-plugin-external-helpers": "^6.22.0",
322
223
  "babel-preset-es2015-rollup": "^3.0.0",
323
224
  d3: "^4.13.0",
@@ -333,51 +234,51 @@ const Yt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
333
234
  "rollup-plugin-node-resolve": "^3.0.2",
334
235
  "rollup-plugin-uglify": "^3.0.0",
335
236
  "uglify-es": "^3.3.9"
336
- }, re = {
337
- name: Yt,
338
- version: Kt,
339
- main: Pt,
340
- module: Ut,
237
+ }, Wt = {
238
+ name: Mt,
239
+ version: Bt,
240
+ main: Ot,
241
+ module: $t,
341
242
  "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({
243
+ author: At,
244
+ description: Dt,
245
+ keywords: Ft,
246
+ homepage: Tt,
247
+ license: _t,
248
+ repository: Ht,
249
+ scripts: Lt,
250
+ dependencies: Nt,
251
+ devDependencies: Pt
252
+ }, { version: It } = Wt, Kt = Object.freeze({
352
253
  children: (e) => e.children,
353
254
  nodeSize: (e) => e.data.size,
354
255
  spacing: 0
355
256
  });
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;
257
+ function K(e) {
258
+ const t = Object.assign({}, Kt, e);
259
+ function n(i) {
260
+ const a = t[i];
261
+ return typeof a == "function" ? a : () => a;
361
262
  }
362
- function i(s) {
363
- const l = c(a(), s, (p) => p.children);
364
- return l.update(), l.data;
263
+ function r(i) {
264
+ const a = c(l(), i, (d) => d.children);
265
+ return a.update(), a.data;
365
266
  }
366
- function o() {
367
- const s = n("nodeSize"), l = n("spacing");
368
- return class Z extends F.prototype.constructor {
267
+ function s() {
268
+ const i = n("nodeSize"), a = n("spacing");
269
+ return class I extends O.prototype.constructor {
369
270
  constructor(h) {
370
271
  super(h);
371
272
  }
372
273
  copy() {
373
- const h = c(this.constructor, this, (u) => u.children);
374
- return h.each((u) => u.data = u.data.data), h;
274
+ const h = c(this.constructor, this, (p) => p.children);
275
+ return h.each((p) => p.data = p.data.data), h;
375
276
  }
376
277
  get size() {
377
- return s(this);
278
+ return i(this);
378
279
  }
379
280
  spacing(h) {
380
- return l(this, h);
281
+ return a(this, h);
381
282
  }
382
283
  get nodes() {
383
284
  return this.descendants();
@@ -421,7 +322,7 @@ function q(e) {
421
322
  }
422
323
  get extents() {
423
324
  return (this.children || []).reduce(
424
- (h, u) => Z.maxExtents(h, u.extents),
325
+ (h, p) => I.maxExtents(h, p.extents),
425
326
  this.nodeExtents
426
327
  );
427
328
  }
@@ -433,19 +334,19 @@ function q(e) {
433
334
  right: this.right
434
335
  };
435
336
  }
436
- static maxExtents(h, u) {
337
+ static maxExtents(h, p) {
437
338
  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)
339
+ top: Math.min(h.top, p.top),
340
+ bottom: Math.max(h.bottom, p.bottom),
341
+ left: Math.min(h.left, p.left),
342
+ right: Math.max(h.right, p.right)
442
343
  };
443
344
  }
444
345
  };
445
346
  }
446
- function a() {
447
- const s = o(), l = n("nodeSize"), p = n("spacing");
448
- return class extends s {
347
+ function l() {
348
+ const i = s(), a = n("nodeSize"), d = n("spacing");
349
+ return class extends i {
449
350
  constructor(h) {
450
351
  super(h), Object.assign(this, {
451
352
  x: 0,
@@ -463,10 +364,10 @@ function q(e) {
463
364
  });
464
365
  }
465
366
  get size() {
466
- return l(this.data);
367
+ return a(this.data);
467
368
  }
468
369
  spacing(h) {
469
- return p(this.data, h.data);
370
+ return d(this.data, h.data);
470
371
  }
471
372
  get x() {
472
373
  return this.data.x;
@@ -481,112 +382,112 @@ function q(e) {
481
382
  this.data.y = h;
482
383
  }
483
384
  update() {
484
- return J(this), Q(this), this;
385
+ return G(this), U(this), this;
485
386
  }
486
387
  };
487
388
  }
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,
389
+ function c(i, a, d) {
390
+ const h = (p, u) => {
391
+ const g = new i(p);
392
+ Object.assign(g, {
393
+ parent: u,
394
+ depth: u === null ? 0 : u.depth + 1,
494
395
  height: 0,
495
396
  length: 1
496
397
  });
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
398
+ const f = d(p) || [];
399
+ return g.children = f.length === 0 ? null : f.map((x) => h(x, g)), g.children && Object.assign(g, g.children.reduce(
400
+ (x, v) => ({
401
+ height: Math.max(x.height, v.height + 1),
402
+ length: x.length + v.length
502
403
  }),
503
- x
504
- )), x;
404
+ g
405
+ )), g;
505
406
  };
506
- return h(l, null);
407
+ return h(a, null);
507
408
  }
508
- return Object.assign(i, {
509
- nodeSize(s) {
510
- return arguments.length ? (t.nodeSize = s, i) : t.nodeSize;
409
+ return Object.assign(r, {
410
+ nodeSize(i) {
411
+ return arguments.length ? (t.nodeSize = i, r) : t.nodeSize;
511
412
  },
512
- spacing(s) {
513
- return arguments.length ? (t.spacing = s, i) : t.spacing;
413
+ spacing(i) {
414
+ return arguments.length ? (t.spacing = i, r) : t.spacing;
514
415
  },
515
- children(s) {
516
- return arguments.length ? (t.children = s, i) : t.children;
416
+ children(i) {
417
+ return arguments.length ? (t.children = i, r) : t.children;
517
418
  },
518
- hierarchy(s, l) {
519
- const p = typeof l > "u" ? t.children : l;
520
- return c(o(), s, p);
419
+ hierarchy(i, a) {
420
+ const d = typeof a > "u" ? t.children : a;
421
+ return c(s(), i, d);
521
422
  },
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}},`;
423
+ dump(i) {
424
+ const a = n("nodeSize"), d = (h) => (p) => {
425
+ 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}`;
426
+ return `{ size: [${v.join(", ")}],${u}x: ${f}, y: ${x}${z}},`;
526
427
  };
527
- return p(`
528
- `)(s);
428
+ return d(`
429
+ `)(i);
529
430
  }
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) => {
431
+ }), r;
432
+ }
433
+ K.version = It;
434
+ const G = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, r) => {
435
+ const [s, l] = n;
436
+ G(r, e.y + e.ySize);
437
+ const c = (s === 0 ? r.lExt : r.rExt).bottom;
438
+ s !== 0 && Ut(e, s, l);
439
+ const i = ee(c, s, l);
440
+ return [s + 1, i];
441
+ }, [0, null]), Gt(e), te(e), e), U = (e, t, n) => {
541
442
  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) => {
443
+ const r = t + e.relX;
444
+ 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;
445
+ }, Gt = (e) => {
545
446
  (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];
447
+ const [r, s] = t, l = r + n.shift, c = s + l + n.change;
448
+ return n.relX += c, [l, c];
548
449
  }, [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));
450
+ }, Ut = (e, t, n) => {
451
+ const r = e.children[t - 1], s = e.children[t];
452
+ let l = r, c = r.relX, i = s, a = s.relX, d = !0;
453
+ for (; l && i; ) {
454
+ l.bottom > n.lowY && (n = n.next);
455
+ const h = c + l.prelim - (a + i.prelim) + l.xSize / 2 + i.xSize / 2 + l.spacing(i);
456
+ (h > 0 || h < 0 && d) && (a += h, Vt(s, h), Yt(e, t, n.index, h)), d = !1;
457
+ const p = l.bottom, u = i.bottom;
458
+ p <= u && (l = qt(l), l && (c += l.relX)), p >= u && (i = Zt(i), i && (a += i.relX));
558
459
  }
559
- !a && s ? pe(e, t, s, l) : a && !s && me(e, t, a, c);
560
- }, ce = (e, t) => {
460
+ !l && i ? Jt(e, t, i, a) : l && !i && Qt(e, t, l, c);
461
+ }, Vt = (e, t) => {
561
462
  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;
463
+ }, Yt = (e, t, n, r) => {
464
+ const s = e.children[t], l = t - n;
465
+ if (l > 1) {
466
+ const c = r / l;
467
+ e.children[n + 1].shift += c, s.shift -= c, s.change -= r - c;
567
468
  }
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) => {
469
+ }, Zt = (e) => e.hasChildren ? e.firstChild : e.lThr, qt = (e) => e.hasChildren ? e.lastChild : e.rThr, Jt = (e, t, n, r) => {
470
+ const s = e.firstChild, l = s.lExt, c = e.children[t];
471
+ l.lThr = n;
472
+ const i = r - n.relX - s.lExtRelX;
473
+ l.relX += i, l.prelim -= i, s.lExt = c.lExt, s.lExtRelX = c.lExtRelX;
474
+ }, Qt = (e, t, n, r) => {
475
+ const s = e.children[t], l = s.rExt, c = e.children[t - 1];
476
+ l.rThr = n;
477
+ const i = r - n.relX - s.rExtRelX;
478
+ l.relX += i, l.prelim -= i, s.rExt = c.rExt, s.rExtRelX = c.rExtRelX;
479
+ }, te = (e) => {
579
480
  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;
481
+ const t = e.firstChild, n = e.lastChild, r = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
581
482
  Object.assign(e, {
582
- prelim: i,
483
+ prelim: r,
583
484
  lExt: t.lExt,
584
485
  lExtRelX: t.lExtRelX,
585
486
  rExt: n.rExt,
586
487
  rExtRelX: n.rExtRelX
587
488
  });
588
489
  }
589
- }, ge = (e, t, n) => {
490
+ }, ee = (e, t, n) => {
590
491
  for (; n !== null && e >= n.lowY; )
591
492
  n = n.next;
592
493
  return {
@@ -594,133 +495,131 @@ const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, i) => {
594
495
  index: t,
595
496
  next: n
596
497
  };
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}@media (prefers-color-scheme: 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);
498
+ }, 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();
499
+ function H(e) {
500
+ return Math.max(4 - 2 * e.state.depth, 1.5);
601
501
  }
602
- function V(e, t) {
603
- const n = ft(e, t);
502
+ function L(e, t) {
503
+ const n = ht(e, t);
604
504
  return e[n];
605
505
  }
606
- function D(e) {
506
+ function B(e) {
607
507
  e.stopPropagation();
608
508
  }
609
- const ye = new st();
610
- class et {
509
+ const ne = new et();
510
+ class Y {
611
511
  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
512
+ this.options = W, this.revokers = [], this.handleZoom = (r) => {
513
+ const { transform: s } = r;
514
+ this.g.attr("transform", s);
515
+ }, this.handlePan = (r) => {
516
+ r.preventDefault();
517
+ const s = j(this.svg.node()), l = s.translate(
518
+ -r.deltaX / s.k,
519
+ -r.deltaY / s.k
620
520
  );
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(() => {
521
+ this.svg.call(this.zoom.transform, l);
522
+ }, this.handleClick = (r, s) => {
523
+ let l = this.options.toggleRecursively;
524
+ (P ? r.metaKey : r.ctrlKey) && (l = !l), this.toggleNode(s, l);
525
+ }, 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 = {
526
+ id: this.options.id || this.svg.attr("id") || nt(),
527
+ rect: { x1: 0, y1: 0, x2: 0, y2: 0 }
528
+ }, this.g = this.svg.append("g"), this.observer = new ResizeObserver(
529
+ rt(() => {
530
+ this.renderData();
531
+ }, 100)
532
+ ), this.revokers.push(
533
+ ne.tap(() => {
633
534
  this.setData();
634
535
  })
635
536
  );
636
537
  }
637
538
  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(`
539
+ const { style: t } = this.options, { id: n } = this.state, r = typeof t == "function" ? t(n) : "";
540
+ return [this.options.embedGlobalCSS && V, r].filter(Boolean).join(`
640
541
  `);
641
542
  }
642
543
  updateStyle() {
643
544
  this.svg.attr(
644
545
  "class",
645
- ct(this.svg.attr("class"), "markmap", this.state.id)
546
+ it(this.svg.attr("class"), "markmap", this.state.id)
646
547
  );
647
548
  const t = this.getStyleContent();
648
549
  this.styleNode.text(t);
649
550
  }
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) => {
551
+ async toggleNode(t, n = !1) {
552
+ var s, l;
553
+ const r = (s = t.payload) != null && s.fold ? 0 : 1;
554
+ n ? X(t, (c, i) => {
654
555
  c.payload = {
655
556
  ...c.payload,
656
- fold: i
657
- }, s();
557
+ fold: r
558
+ }, i();
658
559
  }) : t.payload = {
659
560
  ...t.payload,
660
- fold: (a = t.payload) != null && a.fold ? 0 : 1
661
- }, this.renderData(t);
561
+ fold: (l = t.payload) != null && l.fold ? 0 : 1
562
+ }, await this.renderData(t);
662
563
  }
663
- initializeData(t) {
564
+ _initializeData(t) {
664
565
  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,
566
+ const { color: r, initialExpandLevel: s } = this.options;
567
+ let l = 0, c = 0;
568
+ X(t, (i, a, d) => {
569
+ var p, u, g, f;
570
+ c += 1, i.children = (p = i.children) == null ? void 0 : p.map((x) => ({ ...x })), n += 1, i.state = {
571
+ ...i.state,
572
+ depth: c,
690
573
  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;
574
+ rect: {
575
+ x: 0,
576
+ y: 0,
577
+ width: 0,
578
+ height: 0
579
+ },
580
+ size: [0, 0]
581
+ }, 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);
582
+ const h = ((f = i.payload) == null ? void 0 : f.fold) === 2;
583
+ h ? l += 1 : (l || s >= 0 && i.state.depth >= s) && (i.payload = { ...i.payload, fold: 1 }), a(), h && (l -= 1), c -= 1;
695
584
  });
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
585
  }
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);
586
+ _relayout() {
587
+ if (!this.state.data) return;
588
+ this.g.selectAll(b("g")).selectAll(
589
+ b("foreignObject")
590
+ ).each(function(i) {
591
+ var h;
592
+ const a = (h = this.firstChild) == null ? void 0 : h.firstChild, d = [a.scrollWidth, a.scrollHeight];
593
+ i.state.size = d;
717
594
  });
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();
595
+ const { spacingHorizontal: t, paddingX: n, spacingVertical: r } = this.options, s = K({}).children((i) => {
596
+ var a;
597
+ if (!((a = i.payload) != null && a.fold)) return i.children;
598
+ }).nodeSize((i) => {
599
+ const [a, d] = i.data.state.size;
600
+ return [d, a + (a ? n * 2 : 0) + t];
601
+ }).spacing((i, a) => i.parent === a.parent ? r : r * 2), l = s.hierarchy(this.state.data);
602
+ s(l);
603
+ const c = l.descendants();
604
+ c.forEach((i) => {
605
+ const a = i.data;
606
+ a.state.rect = {
607
+ x: i.y,
608
+ y: i.x,
609
+ width: i.ySize - t,
610
+ height: i.xSize
611
+ };
612
+ }), this.state.rect = {
613
+ x1: T(c, (i) => i.data.state.rect.x) || 0,
614
+ y1: T(c, (i) => i.data.state.rect.y) || 0,
615
+ x2: _(
616
+ c,
617
+ (i) => i.data.state.rect.x + i.data.state.rect.width
618
+ ) || 0,
619
+ y2: _(
620
+ c,
621
+ (i) => i.data.state.rect.y + i.data.state.rect.height
622
+ ) || 0
724
623
  };
725
624
  }
726
625
  setOptions(t) {
@@ -729,127 +628,99 @@ class et {
729
628
  ...t
730
629
  }, 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
630
  }
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());
631
+ async setData(t, n) {
632
+ n && this.setOptions(n), t && (this.state.data = t), this.state.data && (this._initializeData(this.state.data), this.updateStyle(), await this.renderData());
734
633
  }
735
- renderData(t) {
634
+ async renderData(t) {
635
+ const { paddingX: n, autoFit: r, color: s, maxWidth: l } = this.options;
736
636
  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(
637
+ const c = [];
638
+ X(this.state.data, (o, m) => {
639
+ var y;
640
+ (y = o.payload) != null && y.fold || m(), c.push(o);
641
+ });
642
+ 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
643
  "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")
644
+ (o) => {
645
+ var m;
646
+ return ["markmap-node", ((m = o.payload) == null ? void 0 : m.fold) && "markmap-fold"].filter(Boolean).join(" ");
647
+ }
648
+ ), g = u.selectAll(b("line")).data(
649
+ (o) => [o],
650
+ (o) => o.state.key
651
+ ), f = g.enter().append("line"), x = p.selectAll(
652
+ b("line")
653
+ ), v = g.merge(f), k = u.selectAll(
654
+ b("circle")
773
655
  ).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] : [];
656
+ (o) => {
657
+ var m;
658
+ return (m = o.children) != null && m.length ? [o] : [];
788
659
  },
789
- (r) => r.data.state.key
660
+ (o) => o.state.key
790
661
  ).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()
662
+ (o) => o.append("circle").attr("stroke-width", "1.5").attr("r", 0).on("click", (m, y) => this.handleClick(m, y)).on("mousedown", B),
663
+ (o) => o,
664
+ (o) => o.remove()
665
+ ), z = this.observer, $ = u.selectAll(b("foreignObject")).data(
666
+ (o) => [o],
667
+ (o) => o.state.key
668
+ ), C = $.enter().append("foreignObject").attr("class", "markmap-foreign").attr("x", n).attr("y", 0).style("opacity", 0).on("mousedown", B).on("dblclick", B);
669
+ C.append("xhtml:div").append("xhtml:div").html((o) => o.content).attr("xmlns", "http://www.w3.org/1999/xhtml"), C.each(function() {
670
+ var m;
671
+ const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
672
+ z.observe(o);
673
+ });
674
+ const A = p.selectAll(
675
+ b("foreignObject")
794
676
  );
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(
677
+ A.each(function() {
678
+ var m;
679
+ const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
680
+ z.unobserve(o);
681
+ });
682
+ const D = C.merge($), Z = c.flatMap(
683
+ (o) => {
684
+ var m;
685
+ return (m = o.payload) != null && m.fold ? [] : o.children.map((y) => ({ source: o, target: y }));
686
+ }
687
+ ), w = this.g.selectAll(b("path")).data(Z, (o) => o.target.state.key), q = w.exit(), F = 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 = F.merge(w);
688
+ this.svg.style(
689
+ "--markmap-max-width",
690
+ l ? `${l}px` : null
691
+ ), await new Promise(requestAnimationFrame), this._relayout(), this.transition(p).attr("transform", (o) => {
692
+ const m = a.x + a.width - o.state.rect.width, y = a.y + a.height / 2 - o.state.rect.height;
693
+ return `translate(${m},${y})`;
694
+ }).remove(), h.attr(
695
+ "transform",
696
+ (o) => `translate(${a.x + a.width - o.state.rect.width},${a.y + a.height / 2 - o.state.rect.height})`
697
+ ), this.transition(u).attr(
698
+ "transform",
699
+ (o) => `translate(${o.state.rect.x},${o.state.rect.y - o.state.rect.height / 2})`
700
+ ), 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
701
  "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
702
+ (o) => {
703
+ var m;
704
+ return (m = o.payload) != null && m.fold && o.children ? s(o) : "var(--markmap-circle-open-bg)";
705
+ }
706
+ ), this.transition(k).attr("r", 6), this.transition(A).style("opacity", 0), D.attr("width", (o) => Math.max(0, o.state.rect.width - n * 2)).attr("height", (o) => o.state.rect.height), this.transition(D).style("opacity", 1);
707
+ const S = [
708
+ a.x + a.width,
709
+ a.y + a.height / 2
710
+ ];
711
+ this.transition(q).attr("d", M({ source: S, target: S })).remove(), F.attr(
712
+ "d",
713
+ M({ source: S, target: S })
714
+ ), this.transition(J).attr("stroke", (o) => s(o.target)).attr("stroke-width", (o) => H(o.target)).attr("d", (o) => {
715
+ const m = o.source, y = o.target, Q = [
716
+ m.state.rect.x + m.state.rect.width,
717
+ m.state.rect.y + m.state.rect.height / 2
718
+ ], tt = [
719
+ y.state.rect.x,
720
+ y.state.rect.y + y.state.rect.height / 2
848
721
  ];
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
- });
722
+ return M({ source: Q, target: tt });
723
+ }), r && this.fit();
853
724
  }
854
725
  transition(t) {
855
726
  const { duration: n } = this.options;
@@ -859,21 +730,21 @@ class et {
859
730
  * Fit the content to the viewport.
860
731
  */
861
732
  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,
733
+ 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(
734
+ r / h * l,
735
+ s / p * l,
865
736
  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);
737
+ ), g = ct.translate(
738
+ (r - h * u) / 2 - c * u,
739
+ (s - p * u) / 2 - i * u
740
+ ).scale(u);
741
+ return this.transition(this.svg).call(this.zoom.transform, g).end().catch(R);
871
742
  }
872
743
  findElement(t) {
873
744
  let n;
874
- return this.g.selectAll(C("g")).each(function(o) {
875
- o.data === t && (n = {
876
- data: o,
745
+ return this.g.selectAll(b("g")).each(function(s) {
746
+ s === t && (n = {
747
+ data: s,
877
748
  g: this
878
749
  });
879
750
  }), n;
@@ -882,57 +753,58 @@ class et {
882
753
  * Pan the content to make the provided node visible in the viewport.
883
754
  */
884
755
  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 = {
756
+ var v;
757
+ const r = (v = this.findElement(t)) == null ? void 0 : v.data;
758
+ if (!r) return;
759
+ const s = this.svg.node(), l = s.getBoundingClientRect(), c = j(s), [i, a] = [
760
+ r.state.rect.x,
761
+ r.state.rect.x + r.state.rect.width + 2
762
+ ].map((k) => k * c.k + c.x), [d, h] = [
763
+ r.state.rect.y - r.state.rect.height / 2,
764
+ r.state.rect.y + r.state.rect.height / 2
765
+ ].map((k) => k * c.k + c.y), p = {
895
766
  left: 0,
896
767
  right: 0,
897
768
  top: 0,
898
769
  bottom: 0,
899
770
  ...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);
771
+ }, 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;
772
+ if (f || x) {
773
+ const k = c.translate(f, x);
774
+ return this.transition(this.svg).call(this.zoom.transform, k).end().catch(R);
904
775
  }
905
776
  }
906
777
  /**
907
778
  * Scale content with it pinned at the center of the viewport.
908
779
  */
909
780
  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
781
+ const n = this.svg.node(), { width: r, height: s } = n.getBoundingClientRect(), l = r / 2, c = s / 2, i = j(n), a = i.translate(
782
+ (l - i.x) * (1 - t) / i.k,
783
+ (c - i.y) * (1 - t) / i.k
913
784
  ).scale(t);
914
- return this.transition(this.svg).call(this.zoom.transform, l).end().catch(T);
785
+ return this.transition(this.svg).call(this.zoom.transform, a).end().catch(R);
915
786
  }
916
787
  destroy() {
917
788
  this.svg.on(".zoom", null), this.svg.html(null), this.revokers.forEach((t) => {
918
789
  t();
919
790
  });
920
791
  }
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;
792
+ static create(t, n, r = null) {
793
+ const s = new Y(t, n);
794
+ return r && s.setData(r).then(() => {
795
+ s.fit();
796
+ }), s;
926
797
  }
927
798
  }
928
799
  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
800
+ Y as Markmap,
801
+ dt as defaultColorFn,
802
+ W as defaultOptions,
803
+ se as deriveOptions,
804
+ oe as globalCSS,
805
+ P as isMacintosh,
806
+ ce as loadCSS,
807
+ he as loadJS,
808
+ ne as refreshHook,
809
+ pt as simpleHash
938
810
  };