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