markmap-view 0.17.0 → 0.17.1-alpha.5

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.
@@ -363,6 +363,7 @@
363
363
  duration: 500,
364
364
  embedGlobalCSS: true,
365
365
  fitRatio: 0.95,
366
+ maxInitialScale: 2,
366
367
  maxWidth: 0,
367
368
  nodeMinHeight: 16,
368
369
  paddingX: 8,
@@ -398,7 +399,15 @@
398
399
  return color2(node);
399
400
  };
400
401
  }
401
- const numberKeys = ["duration", "maxWidth", "initialExpandLevel"];
402
+ const numberKeys = [
403
+ "duration",
404
+ "maxWidth",
405
+ "initialExpandLevel",
406
+ "fitRatio",
407
+ "maxInitialScale",
408
+ "spacingHorizontal",
409
+ "spacingVertical"
410
+ ];
402
411
  numberKeys.forEach((key) => {
403
412
  const value = options[key];
404
413
  if (typeof value === "number")
@@ -1531,7 +1540,7 @@
1531
1540
  /**
1532
1541
  * Fit the content to the viewport.
1533
1542
  */
1534
- async fit() {
1543
+ async fit(maxScale = this.options.maxInitialScale) {
1535
1544
  const svgNode = this.svg.node();
1536
1545
  const { width: offsetWidth, height: offsetHeight } = svgNode.getBoundingClientRect();
1537
1546
  const { fitRatio } = this.options;
@@ -1541,7 +1550,7 @@
1541
1550
  const scale = Math.min(
1542
1551
  offsetWidth / naturalWidth * fitRatio,
1543
1552
  offsetHeight / naturalHeight * fitRatio,
1544
- 2
1553
+ maxScale
1545
1554
  );
1546
1555
  const initialZoom = d32.zoomIdentity.translate(
1547
1556
  (offsetWidth - naturalWidth * scale) / 2 - minY * scale,
@@ -1625,7 +1634,9 @@
1625
1634
  const mm = new Markmap(svg, opts);
1626
1635
  if (data) {
1627
1636
  mm.setData(data);
1628
- mm.fit();
1637
+ requestAnimationFrame(() => {
1638
+ mm.fit();
1639
+ });
1629
1640
  }
1630
1641
  return mm;
1631
1642
  }
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Hook as st, getId as at, debounce as lt, addClass as ct, walkTree as T, childSelector as C, noop as M } from "markmap-common";
2
2
  import { loadCSS as Ce, loadJS as we } from "markmap-common";
3
- import { scaleOrdinal as V, schemeCategory10 as ht, zoomTransform as A, select as dt, zoom as ut, linkHorizontal as pt, min as H, max as L, zoomIdentity as mt, minIndex as ft } from "d3";
4
- const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), gt = V(ht), P = {
3
+ import { scaleOrdinal as Y, schemeCategory10 as ht, zoomTransform as A, select as dt, zoom as ut, linkHorizontal as pt, min as I, max as H, zoomIdentity as mt, minIndex as ft } from "d3";
4
+ const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), gt = Y(ht), P = {
5
5
  autoFit: !1,
6
6
  color: (e) => {
7
7
  var t;
@@ -10,6 +10,7 @@ const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), g
10
10
  duration: 500,
11
11
  embedGlobalCSS: !0,
12
12
  fitRatio: 0.95,
13
+ maxInitialScale: 2,
13
14
  maxWidth: 0,
14
15
  nodeMinHeight: 16,
15
16
  paddingX: 8,
@@ -22,12 +23,12 @@ const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), g
22
23
  toggleRecursively: !1
23
24
  };
24
25
  function Se(e) {
25
- const t = {}, n = { ...e }, { color: r, colorFreezeLevel: o } = n;
26
- if ((r == null ? void 0 : r.length) === 1) {
27
- const s = r[0];
26
+ const t = {}, n = { ...e }, { color: i, colorFreezeLevel: o } = n;
27
+ if ((i == null ? void 0 : i.length) === 1) {
28
+ const s = i[0];
28
29
  t.color = () => s;
29
- } else if (r != null && r.length) {
30
- const s = V(r);
30
+ } else if (i != null && i.length) {
31
+ const s = Y(i);
31
32
  t.color = (l) => s(`${l.state.path}`);
32
33
  }
33
34
  if (o) {
@@ -40,7 +41,15 @@ function Se(e) {
40
41
  }
41
42
  }, s(l));
42
43
  }
43
- return ["duration", "maxWidth", "initialExpandLevel"].forEach((s) => {
44
+ return [
45
+ "duration",
46
+ "maxWidth",
47
+ "initialExpandLevel",
48
+ "fitRatio",
49
+ "maxInitialScale",
50
+ "spacingHorizontal",
51
+ "spacingVertical"
52
+ ].forEach((s) => {
44
53
  const l = n[s];
45
54
  typeof l == "number" && (t[s] = l);
46
55
  }), ["zoom", "pan"].forEach((s) => {
@@ -74,31 +83,31 @@ function bt(e) {
74
83
  const zt = {
75
84
  isSvg: !1
76
85
  };
77
- function I(e, t) {
86
+ function L(e, t) {
78
87
  Array.isArray(t) || (t = [t]), t = t.filter(Boolean), t.length && e.append(...t);
79
88
  }
80
89
  function Et(e, t, n) {
81
- for (const r in t)
82
- if (!(r === "key" || r === "children" || r === "ref"))
83
- if (r === "dangerouslySetInnerHTML")
84
- e.innerHTML = t[r].__html;
85
- else if (r === "innerHTML" || r === "textContent" || r === "innerText" || r === "value" && ["textarea", "select"].includes(e.tagName)) {
86
- const o = t[r];
87
- o != null && (e[r] = o);
90
+ for (const i in t)
91
+ if (!(i === "key" || i === "children" || i === "ref"))
92
+ if (i === "dangerouslySetInnerHTML")
93
+ e.innerHTML = t[i].__html;
94
+ else if (i === "innerHTML" || i === "textContent" || i === "innerText" || i === "value" && ["textarea", "select"].includes(e.tagName)) {
95
+ const o = t[i];
96
+ o != null && (e[i] = o);
88
97
  } else
89
- r.startsWith("on") ? e[r.toLowerCase()] = t[r] : wt(e, r, t[r], n.isSvg);
98
+ i.startsWith("on") ? e[i.toLowerCase()] = t[i] : wt(e, i, t[i], n.isSvg);
90
99
  }
91
100
  const Ct = {
92
101
  className: "class",
93
102
  labelFor: "for"
94
103
  };
95
- function wt(e, t, n, r) {
104
+ function wt(e, t, n, i) {
96
105
  if (t = Ct[t] || t, n === !0)
97
106
  e.setAttribute(t, "");
98
107
  else if (n === !1)
99
108
  e.removeAttribute(t);
100
109
  else {
101
- const o = r ? yt[t] : void 0;
110
+ const o = i ? yt[t] : void 0;
102
111
  o !== void 0 ? e.setAttributeNS(o, t, n) : e.setAttribute(t, n);
103
112
  }
104
113
  }
@@ -116,17 +125,17 @@ function B(e, t = zt) {
116
125
  if (St(e)) {
117
126
  const {
118
127
  type: n,
119
- props: r
128
+ props: i
120
129
  } = e;
121
130
  if (n === bt) {
122
131
  const a = document.createDocumentFragment();
123
- if (r.children) {
124
- const c = $(r.children, t);
125
- I(a, c);
132
+ if (i.children) {
133
+ const c = $(i.children, t);
134
+ L(a, c);
126
135
  }
127
136
  return a;
128
137
  }
129
- const o = n(r);
138
+ const o = n(i);
130
139
  return B(o, t);
131
140
  }
132
141
  if (kt(e))
@@ -134,18 +143,18 @@ function B(e, t = zt) {
134
143
  if (vt(e)) {
135
144
  let n;
136
145
  const {
137
- type: r,
146
+ type: i,
138
147
  props: o
139
148
  } = e;
140
- if (!t.isSvg && r === "svg" && (t = Object.assign({}, t, {
149
+ if (!t.isSvg && i === "svg" && (t = Object.assign({}, t, {
141
150
  isSvg: !0
142
- })), t.isSvg ? n = document.createElementNS(xt, r) : n = document.createElement(r), Et(n, o, t), o.children) {
151
+ })), t.isSvg ? n = document.createElementNS(xt, i) : n = document.createElement(i), Et(n, o, t), o.children) {
143
152
  let c = t;
144
- t.isSvg && r === "foreignObject" && (c = Object.assign({}, c, {
153
+ t.isSvg && i === "foreignObject" && (c = Object.assign({}, c, {
145
154
  isSvg: !1
146
155
  }));
147
156
  const s = $(o.children, c);
148
- s != null && I(n, s);
157
+ s != null && L(n, s);
149
158
  }
150
159
  const {
151
160
  ref: a
@@ -158,47 +167,47 @@ function O(e) {
158
167
  return B(e);
159
168
  }
160
169
  function jt(e) {
161
- var t = 0, n = e.children, r = n && n.length;
162
- if (!r)
170
+ var t = 0, n = e.children, i = n && n.length;
171
+ if (!i)
163
172
  t = 1;
164
173
  else
165
- for (; --r >= 0; )
166
- t += n[r].value;
174
+ for (; --i >= 0; )
175
+ t += n[i].value;
167
176
  e.value = t;
168
177
  }
169
178
  function Nt() {
170
179
  return this.eachAfter(jt);
171
180
  }
172
181
  function Rt(e) {
173
- var t = this, n, r = [t], o, a, c;
182
+ var t = this, n, i = [t], o, a, c;
174
183
  do
175
- for (n = r.reverse(), r = []; t = n.pop(); )
184
+ for (n = i.reverse(), i = []; t = n.pop(); )
176
185
  if (e(t), o = t.children, o)
177
186
  for (a = 0, c = o.length; a < c; ++a)
178
- r.push(o[a]);
179
- while (r.length);
187
+ i.push(o[a]);
188
+ while (i.length);
180
189
  return this;
181
190
  }
182
191
  function Tt(e) {
183
- for (var t = this, n = [t], r, o; t = n.pop(); )
184
- if (e(t), r = t.children, r)
185
- for (o = r.length - 1; o >= 0; --o)
186
- n.push(r[o]);
192
+ for (var t = this, n = [t], i, o; t = n.pop(); )
193
+ if (e(t), i = t.children, i)
194
+ for (o = i.length - 1; o >= 0; --o)
195
+ n.push(i[o]);
187
196
  return this;
188
197
  }
189
198
  function Mt(e) {
190
- for (var t = this, n = [t], r = [], o, a, c; t = n.pop(); )
191
- if (r.push(t), o = t.children, o)
199
+ for (var t = this, n = [t], i = [], o, a, c; t = n.pop(); )
200
+ if (i.push(t), o = t.children, o)
192
201
  for (a = 0, c = o.length; a < c; ++a)
193
202
  n.push(o[a]);
194
- for (; t = r.pop(); )
203
+ for (; t = i.pop(); )
195
204
  e(t);
196
205
  return this;
197
206
  }
198
207
  function At(e) {
199
208
  return this.eachAfter(function(t) {
200
- for (var n = +e(t.data) || 0, r = t.children, o = r && r.length; --o >= 0; )
201
- n += r[o].value;
209
+ for (var n = +e(t.data) || 0, i = t.children, o = i && i.length; --o >= 0; )
210
+ n += i[o].value;
202
211
  t.value = n;
203
212
  });
204
213
  }
@@ -208,18 +217,18 @@ function _t(e) {
208
217
  });
209
218
  }
210
219
  function Ot(e) {
211
- for (var t = this, n = Dt(t, e), r = [t]; t !== n; )
212
- t = t.parent, r.push(t);
213
- for (var o = r.length; e !== n; )
214
- r.splice(o, 0, e), e = e.parent;
215
- return r;
220
+ for (var t = this, n = Dt(t, e), i = [t]; t !== n; )
221
+ t = t.parent, i.push(t);
222
+ for (var o = i.length; e !== n; )
223
+ i.splice(o, 0, e), e = e.parent;
224
+ return i;
216
225
  }
217
226
  function Dt(e, t) {
218
227
  if (e === t)
219
228
  return e;
220
- var n = e.ancestors(), r = t.ancestors(), o = null;
221
- for (e = n.pop(), t = r.pop(); e === t; )
222
- o = e, e = n.pop(), t = r.pop();
229
+ var n = e.ancestors(), i = t.ancestors(), o = null;
230
+ for (e = n.pop(), t = i.pop(); e === t; )
231
+ o = e, e = n.pop(), t = i.pop();
223
232
  return o;
224
233
  }
225
234
  function $t() {
@@ -239,30 +248,30 @@ function Ft() {
239
248
  t.children || e.push(t);
240
249
  }), e;
241
250
  }
242
- function Ht() {
251
+ function It() {
243
252
  var e = this, t = [];
244
253
  return e.each(function(n) {
245
254
  n !== e && t.push({ source: n.parent, target: n });
246
255
  }), t;
247
256
  }
248
257
  function F(e, t) {
249
- var n = new N(e), r = +e.value && (n.value = e.value), o, a = [n], c, s, l, p;
250
- for (t == null && (t = It); o = a.pop(); )
251
- if (r && (o.value = +o.data.value), (s = t(o.data)) && (p = s.length))
258
+ var n = new N(e), i = +e.value && (n.value = e.value), o, a = [n], c, s, l, p;
259
+ for (t == null && (t = Lt); o = a.pop(); )
260
+ if (i && (o.value = +o.data.value), (s = t(o.data)) && (p = s.length))
252
261
  for (o.children = new Array(p), l = p - 1; l >= 0; --l)
253
262
  a.push(c = o.children[l] = new N(s[l])), c.parent = o, c.depth = o.depth + 1;
254
- return n.eachBefore(Yt);
263
+ return n.eachBefore(Vt);
255
264
  }
256
- function Lt() {
265
+ function Ht() {
257
266
  return F(this).eachBefore(Wt);
258
267
  }
259
- function It(e) {
268
+ function Lt(e) {
260
269
  return e.children;
261
270
  }
262
271
  function Wt(e) {
263
272
  e.data = e.data.data;
264
273
  }
265
- function Yt(e) {
274
+ function Vt(e) {
266
275
  var t = 0;
267
276
  do
268
277
  e.height = t;
@@ -283,10 +292,10 @@ N.prototype = F.prototype = {
283
292
  ancestors: $t,
284
293
  descendants: Bt,
285
294
  leaves: Ft,
286
- links: Ht,
287
- copy: Lt
295
+ links: It,
296
+ copy: Ht
288
297
  };
289
- const Vt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index", Gt = {
298
+ const Yt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index", Gt = {
290
299
  name: "Chris Maloney",
291
300
  url: "http://chrismaloney.org"
292
301
  }, Zt = "Flexible tree layout algorithm that allows for variable node sizes.", qt = [
@@ -318,7 +327,7 @@ const Vt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
318
327
  prepare: "npm-run-all clean build lint test"
319
328
  }, ne = {
320
329
  "d3-hierarchy": "^1.1.5"
321
- }, re = {
330
+ }, ie = {
322
331
  "babel-plugin-external-helpers": "^6.22.0",
323
332
  "babel-preset-es2015-rollup": "^3.0.0",
324
333
  d3: "^4.13.0",
@@ -334,8 +343,8 @@ const Vt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
334
343
  "rollup-plugin-node-resolve": "^3.0.2",
335
344
  "rollup-plugin-uglify": "^3.0.0",
336
345
  "uglify-es": "^3.3.9"
337
- }, ie = {
338
- name: Vt,
346
+ }, re = {
347
+ name: Yt,
339
348
  version: Kt,
340
349
  main: Pt,
341
350
  module: Ut,
@@ -348,8 +357,8 @@ const Vt = "d3-flextree", Kt = "2.1.2", Pt = "build/d3-flextree.js", Ut = "index
348
357
  repository: te,
349
358
  scripts: ee,
350
359
  dependencies: ne,
351
- devDependencies: re
352
- }, { version: oe } = ie, se = Object.freeze({
360
+ devDependencies: ie
361
+ }, { version: oe } = re, se = Object.freeze({
353
362
  children: (e) => e.children,
354
363
  nodeSize: (e) => e.data.size,
355
364
  spacing: 0
@@ -360,7 +369,7 @@ function q(e) {
360
369
  const l = t[s];
361
370
  return typeof l == "function" ? l : () => l;
362
371
  }
363
- function r(s) {
372
+ function i(s) {
364
373
  const l = c(a(), s, (p) => p.children);
365
374
  return l.update(), l.data;
366
375
  }
@@ -506,15 +515,15 @@ function q(e) {
506
515
  };
507
516
  return h(l, null);
508
517
  }
509
- return Object.assign(r, {
518
+ return Object.assign(i, {
510
519
  nodeSize(s) {
511
- return arguments.length ? (t.nodeSize = s, r) : t.nodeSize;
520
+ return arguments.length ? (t.nodeSize = s, i) : t.nodeSize;
512
521
  },
513
522
  spacing(s) {
514
- return arguments.length ? (t.spacing = s, r) : t.spacing;
523
+ return arguments.length ? (t.spacing = s, i) : t.spacing;
515
524
  },
516
525
  children(s) {
517
- return arguments.length ? (t.children = s, r) : t.children;
526
+ return arguments.length ? (t.children = s, i) : t.children;
518
527
  },
519
528
  hierarchy(s, l) {
520
529
  const p = typeof l > "u" ? t.children : l;
@@ -528,28 +537,28 @@ function q(e) {
528
537
  return p(`
529
538
  `)(s);
530
539
  }
531
- }), r;
540
+ }), i;
532
541
  }
533
542
  q.version = oe;
534
- const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, r) => {
543
+ const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, i) => {
535
544
  const [o, a] = n;
536
- J(r, e.y + e.ySize);
537
- const c = (o === 0 ? r.lExt : r.rExt).bottom;
545
+ J(i, e.y + e.ySize);
546
+ const c = (o === 0 ? i.lExt : i.rExt).bottom;
538
547
  o !== 0 && le(e, o, a);
539
548
  const s = ge(c, o, a);
540
549
  return [o + 1, s];
541
550
  }, [0, null]), ae(e), fe(e), e), Q = (e, t, n) => {
542
551
  typeof t > "u" && (t = -e.relX - e.prelim, n = 0);
543
- const r = t + e.relX;
544
- return e.relX = r + e.prelim - n, e.prelim = 0, e.x = n + e.relX, (e.children || []).forEach((o) => Q(o, r, e.x)), e;
552
+ const i = t + e.relX;
553
+ 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;
545
554
  }, ae = (e) => {
546
555
  (e.children || []).reduce((t, n) => {
547
- const [r, o] = t, a = r + n.shift, c = o + a + n.change;
556
+ const [i, o] = t, a = i + n.shift, c = o + a + n.change;
548
557
  return n.relX += c, [a, c];
549
558
  }, [0, 0]);
550
559
  }, le = (e, t, n) => {
551
- const r = e.children[t - 1], o = e.children[t];
552
- let a = r, c = r.relX, s = o, l = o.relX, p = !0;
560
+ const i = e.children[t - 1], o = e.children[t];
561
+ let a = i, c = i.relX, s = o, l = o.relX, p = !0;
553
562
  for (; a && s; ) {
554
563
  a.bottom > n.lowY && (n = n.next);
555
564
  const h = c + a.prelim - (l + s.prelim) + a.xSize / 2 + s.xSize / 2 + a.spacing(s);
@@ -560,27 +569,27 @@ const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, r) => {
560
569
  !a && s ? pe(e, t, s, l) : a && !s && me(e, t, a, c);
561
570
  }, ce = (e, t) => {
562
571
  e.relX += t, e.lExtRelX += t, e.rExtRelX += t;
563
- }, he = (e, t, n, r) => {
572
+ }, he = (e, t, n, i) => {
564
573
  const o = e.children[t], a = t - n;
565
574
  if (a > 1) {
566
- const c = r / a;
567
- e.children[n + 1].shift += c, o.shift -= c, o.change -= r - c;
575
+ const c = i / a;
576
+ e.children[n + 1].shift += c, o.shift -= c, o.change -= i - c;
568
577
  }
569
- }, de = (e) => e.hasChildren ? e.firstChild : e.lThr, ue = (e) => e.hasChildren ? e.lastChild : e.rThr, pe = (e, t, n, r) => {
578
+ }, de = (e) => e.hasChildren ? e.firstChild : e.lThr, ue = (e) => e.hasChildren ? e.lastChild : e.rThr, pe = (e, t, n, i) => {
570
579
  const o = e.firstChild, a = o.lExt, c = e.children[t];
571
580
  a.lThr = n;
572
- const s = r - n.relX - o.lExtRelX;
581
+ const s = i - n.relX - o.lExtRelX;
573
582
  a.relX += s, a.prelim -= s, o.lExt = c.lExt, o.lExtRelX = c.lExtRelX;
574
- }, me = (e, t, n, r) => {
583
+ }, me = (e, t, n, i) => {
575
584
  const o = e.children[t], a = o.rExt, c = e.children[t - 1];
576
585
  a.rThr = n;
577
- const s = r - n.relX - o.rExtRelX;
586
+ const s = i - n.relX - o.rExtRelX;
578
587
  a.relX += s, a.prelim -= s, o.rExt = c.rExt, o.rExtRelX = c.rExtRelX;
579
588
  }, fe = (e) => {
580
589
  if (e.hasChildren) {
581
- const t = e.firstChild, n = e.lastChild, r = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
590
+ const t = e.firstChild, n = e.lastChild, i = (t.prelim + t.relX - t.xSize / 2 + n.relX + n.prelim + n.xSize / 2) / 2;
582
591
  Object.assign(e, {
583
- prelim: r,
592
+ prelim: i,
584
593
  lExt: t.lExt,
585
594
  lExtRelX: t.lExtRelX,
586
595
  rExt: n.rExt,
@@ -600,7 +609,7 @@ function W(e) {
600
609
  const t = e.data;
601
610
  return Math.max(4 - 2 * t.state.depth, 1.5);
602
611
  }
603
- function Y(e, t) {
612
+ function V(e, t) {
604
613
  const n = ft(e, t);
605
614
  return e[n];
606
615
  }
@@ -610,20 +619,20 @@ function D(e) {
610
619
  const ye = new st();
611
620
  class et {
612
621
  constructor(t, n) {
613
- this.options = P, this.revokers = [], this.imgCache = {}, this.handleZoom = (r) => {
614
- const { transform: o } = r;
622
+ this.options = P, this.revokers = [], this.imgCache = {}, this.handleZoom = (i) => {
623
+ const { transform: o } = i;
615
624
  this.g.attr("transform", o);
616
- }, this.handlePan = (r) => {
617
- r.preventDefault();
625
+ }, this.handlePan = (i) => {
626
+ i.preventDefault();
618
627
  const o = A(this.svg.node()), a = o.translate(
619
- -r.deltaX / o.k,
620
- -r.deltaY / o.k
628
+ -i.deltaX / o.k,
629
+ -i.deltaY / o.k
621
630
  );
622
631
  this.svg.call(this.zoom.transform, a);
623
- }, this.handleClick = (r, o) => {
632
+ }, this.handleClick = (i, o) => {
624
633
  let a = this.options.toggleRecursively;
625
- (K ? r.metaKey : r.ctrlKey) && (a = !a), this.toggleNode(o.data, a);
626
- }, this.svg = t.datum ? t : dt(t), this.styleNode = this.svg.append("style"), this.zoom = ut().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 = {
634
+ (K ? i.metaKey : i.ctrlKey) && (a = !a), this.toggleNode(o.data, a);
635
+ }, 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 = {
627
636
  id: this.options.id || this.svg.attr("id") || at(),
628
637
  minX: 0,
629
638
  maxX: 0,
@@ -636,8 +645,8 @@ class et {
636
645
  );
637
646
  }
638
647
  getStyleContent() {
639
- const { style: t } = this.options, { id: n } = this.state, r = typeof t == "function" ? t(n) : "";
640
- return [this.options.embedGlobalCSS && tt, r].filter(Boolean).join(`
648
+ const { style: t } = this.options, { id: n } = this.state, i = typeof t == "function" ? t(n) : "";
649
+ return [this.options.embedGlobalCSS && tt, i].filter(Boolean).join(`
641
650
  `);
642
651
  }
643
652
  updateStyle() {
@@ -650,11 +659,11 @@ class et {
650
659
  }
651
660
  toggleNode(t, n = !1) {
652
661
  var o, a;
653
- const r = (o = t.payload) != null && o.fold ? 0 : 1;
662
+ const i = (o = t.payload) != null && o.fold ? 0 : 1;
654
663
  n ? T(t, (c, s) => {
655
664
  c.payload = {
656
665
  ...c.payload,
657
- fold: r
666
+ fold: i
658
667
  }, s();
659
668
  }) : t.payload = {
660
669
  ...t.payload,
@@ -663,7 +672,7 @@ class et {
663
672
  }
664
673
  initializeData(t) {
665
674
  let n = 0;
666
- const { color: r, nodeMinHeight: o, maxWidth: a, initialExpandLevel: c } = this.options, { id: s } = this.state, l = O(
675
+ const { color: i, nodeMinHeight: o, maxWidth: a, initialExpandLevel: c } = this.options, { id: s } = this.state, l = O(
667
676
  /* @__PURE__ */ j("div", { className: `markmap-container markmap ${s}-g` })
668
677
  ), p = O(
669
678
  /* @__PURE__ */ j("style", { children: [this.getStyleContent(), xe].join(`
@@ -690,7 +699,7 @@ class et {
690
699
  depth: g,
691
700
  id: n,
692
701
  el: k.firstChild
693
- }, m.state.path = [(w = f == null ? void 0 : f.state) == null ? void 0 : w.path, m.state.id].filter(Boolean).join("."), r(m);
702
+ }, m.state.path = [(w = f == null ? void 0 : f.state) == null ? void 0 : w.path, m.state.id].filter(Boolean).join("."), i(m);
694
703
  const v = ((z = m.payload) == null ? void 0 : z.fold) === 2;
695
704
  v ? u += 1 : (u || c >= 0 && m.state.depth >= c) && (m.payload = { ...m.payload, fold: 1 }), y(), v && (u -= 1), g -= 1;
696
705
  });
@@ -714,8 +723,8 @@ class et {
714
723
  t.querySelectorAll("img").forEach((n) => {
715
724
  if (n.width)
716
725
  return;
717
- const r = this.imgCache[n.src];
718
- r != null && r[0] ? [n.width, n.height] = r : r || this._loadImage(n.src);
726
+ const i = this.imgCache[n.src];
727
+ i != null && i[0] ? [n.width, n.height] = i : i || this._loadImage(n.src);
719
728
  });
720
729
  }
721
730
  _loadImage(t) {
@@ -737,115 +746,115 @@ class et {
737
746
  renderData(t) {
738
747
  if (!this.state.data)
739
748
  return;
740
- const { spacingHorizontal: n, paddingX: r, spacingVertical: o, autoFit: a, color: c } = this.options, s = q({}).children((i) => {
749
+ const { spacingHorizontal: n, paddingX: i, spacingVertical: o, autoFit: a, color: c } = this.options, s = q({}).children((r) => {
741
750
  var d;
742
- if (!((d = i.payload) != null && d.fold))
743
- return i.children;
744
- }).nodeSize((i) => {
745
- const [d, S] = i.data.state.size;
746
- return [S, d + (d ? r * 2 : 0) + n];
747
- }).spacing((i, d) => i.parent === d.parent ? o : o * 2), l = s.hierarchy(this.state.data);
751
+ if (!((d = r.payload) != null && d.fold))
752
+ return r.children;
753
+ }).nodeSize((r) => {
754
+ const [d, S] = r.data.state.size;
755
+ return [S, d + (d ? i * 2 : 0) + n];
756
+ }).spacing((r, d) => r.parent === d.parent ? o : o * 2), l = s.hierarchy(this.state.data);
748
757
  s(l);
749
- const p = l.descendants().reverse(), h = l.links(), u = pt(), g = H(p, (i) => i.x - i.xSize / 2), x = L(p, (i) => i.x + i.xSize / 2), m = H(p, (i) => i.y), y = L(p, (i) => i.y + i.ySize - n);
758
+ const p = l.descendants().reverse(), h = l.links(), u = pt(), g = I(p, (r) => r.x - r.xSize / 2), x = H(p, (r) => r.x + r.xSize / 2), m = I(p, (r) => r.y), y = H(p, (r) => r.y + r.ySize - n);
750
759
  Object.assign(this.state, {
751
760
  minX: g,
752
761
  maxX: x,
753
762
  minY: m,
754
763
  maxY: y
755
764
  }), a && this.fit();
756
- const f = t && p.find((i) => i.data === t) || l, k = f.data.state.x0 ?? f.x, v = f.data.state.y0 ?? f.y, b = this.g.selectAll(
765
+ 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(
757
766
  C("g")
758
- ).data(p, (i) => i.data.state.key), w = b.enter().append("g").attr("data-depth", (i) => i.data.state.depth).attr("data-path", (i) => i.data.state.path).attr(
767
+ ).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(
759
768
  "transform",
760
- (i) => `translate(${v + f.ySize - i.ySize},${k + f.xSize / 2 - i.xSize})`
769
+ (r) => `translate(${v + f.ySize - r.ySize},${k + f.xSize / 2 - r.xSize})`
761
770
  ), z = this.transition(b.exit());
762
- z.select("line").attr("x1", (i) => i.ySize - n).attr("x2", (i) => i.ySize - n), z.select("foreignObject").style("opacity", 0), z.attr(
771
+ z.select("line").attr("x1", (r) => r.ySize - n).attr("x2", (r) => r.ySize - n), z.select("foreignObject").style("opacity", 0), z.attr(
763
772
  "transform",
764
- (i) => `translate(${f.y + f.ySize - i.ySize},${f.x + f.xSize / 2 - i.xSize})`
773
+ (r) => `translate(${f.y + f.ySize - r.ySize},${f.x + f.xSize / 2 - r.xSize})`
765
774
  ).remove();
766
775
  const E = b.merge(w).attr(
767
776
  "class",
768
- (i) => {
777
+ (r) => {
769
778
  var d;
770
- return ["markmap-node", ((d = i.data.payload) == null ? void 0 : d.fold) && "markmap-fold"].filter(Boolean).join(" ");
779
+ return ["markmap-node", ((d = r.data.payload) == null ? void 0 : d.fold) && "markmap-fold"].filter(Boolean).join(" ");
771
780
  }
772
781
  );
773
782
  this.transition(E).attr(
774
783
  "transform",
775
- (i) => `translate(${i.y},${i.x - i.xSize / 2})`
784
+ (r) => `translate(${r.y},${r.x - r.xSize / 2})`
776
785
  );
777
786
  const nt = E.selectAll(
778
787
  C("line")
779
788
  ).data(
780
- (i) => [i],
781
- (i) => i.data.state.key
789
+ (r) => [r],
790
+ (r) => r.data.state.key
782
791
  ).join(
783
- (i) => i.append("line").attr("x1", (d) => d.ySize - n).attr("x2", (d) => d.ySize - n),
784
- (i) => i,
785
- (i) => i.remove()
792
+ (r) => r.append("line").attr("x1", (d) => d.ySize - n).attr("x2", (d) => d.ySize - n),
793
+ (r) => r,
794
+ (r) => r.remove()
786
795
  );
787
- this.transition(nt).attr("x1", -1).attr("x2", (i) => i.ySize - n + 2).attr("y1", (i) => i.xSize).attr("y2", (i) => i.xSize).attr("stroke", (i) => c(i.data)).attr("stroke-width", W);
788
- const rt = E.selectAll(
796
+ 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);
797
+ const it = E.selectAll(
789
798
  C("circle")
790
799
  ).data(
791
- (i) => {
800
+ (r) => {
792
801
  var d;
793
- return (d = i.data.children) != null && d.length ? [i] : [];
802
+ return (d = r.data.children) != null && d.length ? [r] : [];
794
803
  },
795
- (i) => i.data.state.key
804
+ (r) => r.data.state.key
796
805
  ).join(
797
- (i) => i.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),
798
- (i) => i,
799
- (i) => i.remove()
806
+ (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),
807
+ (r) => r,
808
+ (r) => r.remove()
800
809
  );
801
- this.transition(rt).attr("r", 6).attr("cx", (i) => i.ySize - n).attr("cy", (i) => i.xSize).attr("stroke", (i) => c(i.data)).attr(
810
+ this.transition(it).attr("r", 6).attr("cx", (r) => r.ySize - n).attr("cy", (r) => r.xSize).attr("stroke", (r) => c(r.data)).attr(
802
811
  "fill",
803
- (i) => {
812
+ (r) => {
804
813
  var d;
805
- return (d = i.data.payload) != null && d.fold && i.data.children ? c(i.data) : "var(--markmap-circle-open-bg)";
814
+ return (d = r.data.payload) != null && d.fold && r.data.children ? c(r.data) : "var(--markmap-circle-open-bg)";
806
815
  }
807
816
  );
808
- const it = E.selectAll(
817
+ const rt = E.selectAll(
809
818
  C("foreignObject")
810
819
  ).data(
811
- (i) => [i],
812
- (i) => i.data.state.key
820
+ (r) => [r],
821
+ (r) => r.data.state.key
813
822
  ).join(
814
- (i) => {
815
- const d = i.append("foreignObject").attr("class", "markmap-foreign").attr("x", r).attr("y", 0).style("opacity", 0).on("mousedown", D).on("dblclick", D);
823
+ (r) => {
824
+ const d = r.append("foreignObject").attr("class", "markmap-foreign").attr("x", i).attr("y", 0).style("opacity", 0).on("mousedown", D).on("dblclick", D);
816
825
  return d.append("xhtml:div").select(function(R) {
817
826
  const X = R.data.state.el.cloneNode(!0);
818
827
  return this.replaceWith(X), X;
819
828
  }).attr("xmlns", "http://www.w3.org/1999/xhtml"), d;
820
829
  },
821
- (i) => i,
822
- (i) => i.remove()
830
+ (r) => r,
831
+ (r) => r.remove()
823
832
  ).attr(
824
833
  "width",
825
- (i) => Math.max(0, i.ySize - n - r * 2)
826
- ).attr("height", (i) => i.xSize);
827
- this.transition(it).style("opacity", 1);
834
+ (r) => Math.max(0, r.ySize - n - i * 2)
835
+ ).attr("height", (r) => r.xSize);
836
+ this.transition(rt).style("opacity", 1);
828
837
  const ot = this.g.selectAll(
829
838
  C("path")
830
- ).data(h, (i) => i.target.data.state.key).join(
831
- (i) => {
839
+ ).data(h, (r) => r.target.data.state.key).join(
840
+ (r) => {
832
841
  const d = [
833
842
  v + f.ySize - n,
834
843
  k + f.xSize / 2
835
844
  ];
836
- return i.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 }));
845
+ 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 }));
837
846
  },
838
- (i) => i,
839
- (i) => {
847
+ (r) => r,
848
+ (r) => {
840
849
  const d = [
841
850
  f.y + f.ySize - n,
842
851
  f.x + f.xSize / 2
843
852
  ];
844
- return this.transition(i).attr("d", u({ source: d, target: d })).remove();
853
+ return this.transition(r).attr("d", u({ source: d, target: d })).remove();
845
854
  }
846
855
  );
847
- this.transition(ot).attr("stroke", (i) => c(i.target.data)).attr("stroke-width", (i) => W(i.target)).attr("d", (i) => {
848
- const d = i.source, S = i.target, R = [
856
+ this.transition(ot).attr("stroke", (r) => c(r.target.data)).attr("stroke-width", (r) => W(r.target)).attr("d", (r) => {
857
+ const d = r.source, S = r.target, R = [
849
858
  d.y + d.ySize - n,
850
859
  d.x + d.xSize / 2
851
860
  ], X = [
@@ -853,8 +862,8 @@ class et {
853
862
  S.x + S.xSize / 2
854
863
  ];
855
864
  return u({ source: R, target: X });
856
- }), p.forEach((i) => {
857
- i.data.state.x0 = i.x, i.data.state.y0 = i.y;
865
+ }), p.forEach((r) => {
866
+ r.data.state.x0 = r.x, r.data.state.y0 = r.y;
858
867
  });
859
868
  }
860
869
  transition(t) {
@@ -864,16 +873,16 @@ class et {
864
873
  /**
865
874
  * Fit the content to the viewport.
866
875
  */
867
- async fit() {
868
- const t = this.svg.node(), { width: n, height: r } = t.getBoundingClientRect(), { fitRatio: o } = this.options, { minX: a, maxX: c, minY: s, maxY: l } = this.state, p = l - s, h = c - a, u = Math.min(
869
- n / p * o,
870
- r / h * o,
871
- 2
872
- ), g = mt.translate(
873
- (n - p * u) / 2 - s * u,
874
- (r - h * u) / 2 - a * u
875
- ).scale(u);
876
- return this.transition(this.svg).call(this.zoom.transform, g).end().catch(M);
876
+ async fit(t = this.options.maxInitialScale) {
877
+ 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(
878
+ i / h * a,
879
+ o / u * a,
880
+ t
881
+ ), x = mt.translate(
882
+ (i - h * g) / 2 - l * g,
883
+ (o - u * g) / 2 - c * g
884
+ ).scale(g);
885
+ return this.transition(this.svg).call(this.zoom.transform, x).end().catch(M);
877
886
  }
878
887
  findElement(t) {
879
888
  let n;
@@ -891,22 +900,22 @@ class et {
891
900
  */
892
901
  async ensureView(t, n) {
893
902
  var k;
894
- const r = (k = this.findElement(t)) == null ? void 0 : k.data;
895
- if (!r)
903
+ const i = (k = this.findElement(t)) == null ? void 0 : k.data;
904
+ if (!i)
896
905
  return;
897
906
  const o = this.svg.node(), { spacingHorizontal: a } = this.options, c = o.getBoundingClientRect(), s = A(o), [l, p] = [
898
- r.y,
899
- r.y + r.ySize - a + 2
907
+ i.y,
908
+ i.y + i.ySize - a + 2
900
909
  ].map((v) => v * s.k + s.x), [h, u] = [
901
- r.x - r.xSize / 2,
902
- r.x + r.xSize / 2
910
+ i.x - i.xSize / 2,
911
+ i.x + i.xSize / 2
903
912
  ].map((v) => v * s.k + s.y), g = {
904
913
  left: 0,
905
914
  right: 0,
906
915
  top: 0,
907
916
  bottom: 0,
908
917
  ...n
909
- }, x = [g.left - l, c.width - g.right - p], m = [g.top - h, c.height - g.bottom - u], y = x[0] * x[1] > 0 ? Y(x, Math.abs) / s.k : 0, f = m[0] * m[1] > 0 ? Y(m, Math.abs) / s.k : 0;
918
+ }, 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;
910
919
  if (y || f) {
911
920
  const v = s.translate(y, f);
912
921
  return this.transition(this.svg).call(this.zoom.transform, v).end().catch(M);
@@ -916,7 +925,7 @@ class et {
916
925
  * Scale content with it pinned at the center of the viewport.
917
926
  */
918
927
  async rescale(t) {
919
- const n = this.svg.node(), { width: r, height: o } = n.getBoundingClientRect(), a = r / 2, c = o / 2, s = A(n), l = s.translate(
928
+ const n = this.svg.node(), { width: i, height: o } = n.getBoundingClientRect(), a = i / 2, c = o / 2, s = A(n), l = s.translate(
920
929
  (a - s.x) * (1 - t) / s.k,
921
930
  (c - s.y) * (1 - t) / s.k
922
931
  ).scale(t);
@@ -927,9 +936,11 @@ class et {
927
936
  t();
928
937
  });
929
938
  }
930
- static create(t, n, r = null) {
939
+ static create(t, n, i = null) {
931
940
  const o = new et(t, n);
932
- return r && (o.setData(r), o.fit()), o;
941
+ return i && (o.setData(i), requestAnimationFrame(() => {
942
+ o.fit();
943
+ })), o;
933
944
  }
934
945
  }
935
946
  export {
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface IMarkmapJSONOptions {
14
14
  duration?: number;
15
15
  maxWidth?: number;
16
16
  initialExpandLevel?: number;
17
+ fitRatio?: number;
18
+ maxInitialScale?: number;
17
19
  extraJs?: string[];
18
20
  extraCss?: string[];
19
21
  zoom?: boolean;
package/dist/view.d.ts CHANGED
@@ -34,7 +34,7 @@ export declare class Markmap {
34
34
  /**
35
35
  * Fit the content to the viewport.
36
36
  */
37
- fit(): Promise<void>;
37
+ fit(maxScale?: number): Promise<void>;
38
38
  findElement(node: INode): {
39
39
  data: FlextreeNode<INode>;
40
40
  g: SVGGElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-view",
3
- "version": "0.17.0",
3
+ "version": "0.17.1-alpha.5+a813e1e",
4
4
  "description": "View markmaps in browser",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -18,6 +18,13 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/markmap/markmap.git"
20
20
  },
21
+ "scripts": {
22
+ "clean": "del-cli dist",
23
+ "build:types": "tsc",
24
+ "build:js": "vite build && TARGET=es vite build",
25
+ "build": "run-s clean build:*",
26
+ "prepublishOnly": "run-s build"
27
+ },
21
28
  "bugs": {
22
29
  "url": "https://github.com/markmap/markmap/issues"
23
30
  },
@@ -44,10 +51,5 @@
44
51
  "peerDependencies": {
45
52
  "markmap-common": "*"
46
53
  },
47
- "scripts": {
48
- "clean": "del-cli dist",
49
- "build:types": "tsc",
50
- "build:js": "vite build && TARGET=es vite build",
51
- "build": "run-s clean build:*"
52
- }
53
- }
54
+ "gitHead": "a813e1efd3ad5a1f011fd71320bc36ac3e2b2402"
55
+ }