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.
- package/dist/browser/index.js +15 -4
- package/dist/index.js +194 -183
- package/dist/types.d.ts +2 -0
- package/dist/view.d.ts +1 -1
- package/package.json +10 -8
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,15 @@
|
|
|
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
|
+
"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
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
const K = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), gt =
|
|
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:
|
|
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 =
|
|
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 [
|
|
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
|
|
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
|
|
82
|
-
if (!(
|
|
83
|
-
if (
|
|
84
|
-
e.innerHTML = t[
|
|
85
|
-
else if (
|
|
86
|
-
const o = t[
|
|
87
|
-
o != null && (e[
|
|
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
|
-
|
|
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,
|
|
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 =
|
|
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:
|
|
128
|
+
props: i
|
|
120
129
|
} = e;
|
|
121
130
|
if (n === bt) {
|
|
122
131
|
const a = document.createDocumentFragment();
|
|
123
|
-
if (
|
|
124
|
-
const c = $(
|
|
125
|
-
|
|
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(
|
|
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:
|
|
146
|
+
type: i,
|
|
138
147
|
props: o
|
|
139
148
|
} = e;
|
|
140
|
-
if (!t.isSvg &&
|
|
149
|
+
if (!t.isSvg && i === "svg" && (t = Object.assign({}, t, {
|
|
141
150
|
isSvg: !0
|
|
142
|
-
})), t.isSvg ? n = document.createElementNS(xt,
|
|
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 &&
|
|
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 &&
|
|
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,
|
|
162
|
-
if (!
|
|
170
|
+
var t = 0, n = e.children, i = n && n.length;
|
|
171
|
+
if (!i)
|
|
163
172
|
t = 1;
|
|
164
173
|
else
|
|
165
|
-
for (; --
|
|
166
|
-
t += n[
|
|
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,
|
|
182
|
+
var t = this, n, i = [t], o, a, c;
|
|
174
183
|
do
|
|
175
|
-
for (n =
|
|
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
|
-
|
|
179
|
-
while (
|
|
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],
|
|
184
|
-
if (e(t),
|
|
185
|
-
for (o =
|
|
186
|
-
n.push(
|
|
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],
|
|
191
|
-
if (
|
|
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 =
|
|
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,
|
|
201
|
-
n +=
|
|
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),
|
|
212
|
-
t = t.parent,
|
|
213
|
-
for (var o =
|
|
214
|
-
|
|
215
|
-
return
|
|
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(),
|
|
221
|
-
for (e = n.pop(), t =
|
|
222
|
-
o = e, e = n.pop(), t =
|
|
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
|
|
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),
|
|
250
|
-
for (t == null && (t =
|
|
251
|
-
if (
|
|
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(
|
|
263
|
+
return n.eachBefore(Vt);
|
|
255
264
|
}
|
|
256
|
-
function
|
|
265
|
+
function Ht() {
|
|
257
266
|
return F(this).eachBefore(Wt);
|
|
258
267
|
}
|
|
259
|
-
function
|
|
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
|
|
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:
|
|
287
|
-
copy:
|
|
295
|
+
links: It,
|
|
296
|
+
copy: Ht
|
|
288
297
|
};
|
|
289
|
-
const
|
|
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
|
-
},
|
|
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
|
-
},
|
|
338
|
-
name:
|
|
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:
|
|
352
|
-
}, { version: oe } =
|
|
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
|
|
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(
|
|
518
|
+
return Object.assign(i, {
|
|
510
519
|
nodeSize(s) {
|
|
511
|
-
return arguments.length ? (t.nodeSize = s,
|
|
520
|
+
return arguments.length ? (t.nodeSize = s, i) : t.nodeSize;
|
|
512
521
|
},
|
|
513
522
|
spacing(s) {
|
|
514
|
-
return arguments.length ? (t.spacing = s,
|
|
523
|
+
return arguments.length ? (t.spacing = s, i) : t.spacing;
|
|
515
524
|
},
|
|
516
525
|
children(s) {
|
|
517
|
-
return arguments.length ? (t.children = s,
|
|
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
|
-
}),
|
|
540
|
+
}), i;
|
|
532
541
|
}
|
|
533
542
|
q.version = oe;
|
|
534
|
-
const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n,
|
|
543
|
+
const J = (e, t = 0) => (e.y = t, (e.children || []).reduce((n, i) => {
|
|
535
544
|
const [o, a] = n;
|
|
536
|
-
J(
|
|
537
|
-
const c = (o === 0 ?
|
|
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
|
|
544
|
-
return e.relX =
|
|
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 [
|
|
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
|
|
552
|
-
let a =
|
|
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,
|
|
572
|
+
}, he = (e, t, n, i) => {
|
|
564
573
|
const o = e.children[t], a = t - n;
|
|
565
574
|
if (a > 1) {
|
|
566
|
-
const c =
|
|
567
|
-
e.children[n + 1].shift += c, o.shift -= c, o.change -=
|
|
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,
|
|
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 =
|
|
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,
|
|
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 =
|
|
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,
|
|
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:
|
|
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
|
|
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 = (
|
|
614
|
-
const { transform: o } =
|
|
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 = (
|
|
617
|
-
|
|
625
|
+
}, this.handlePan = (i) => {
|
|
626
|
+
i.preventDefault();
|
|
618
627
|
const o = A(this.svg.node()), a = o.translate(
|
|
619
|
-
-
|
|
620
|
-
-
|
|
628
|
+
-i.deltaX / o.k,
|
|
629
|
+
-i.deltaY / o.k
|
|
621
630
|
);
|
|
622
631
|
this.svg.call(this.zoom.transform, a);
|
|
623
|
-
}, this.handleClick = (
|
|
632
|
+
}, this.handleClick = (i, o) => {
|
|
624
633
|
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((
|
|
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,
|
|
640
|
-
return [this.options.embedGlobalCSS && tt,
|
|
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
|
|
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:
|
|
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:
|
|
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("."),
|
|
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
|
|
718
|
-
|
|
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:
|
|
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 =
|
|
743
|
-
return
|
|
744
|
-
}).nodeSize((
|
|
745
|
-
const [d, S] =
|
|
746
|
-
return [S, d + (d ?
|
|
747
|
-
}).spacing((
|
|
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 =
|
|
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((
|
|
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, (
|
|
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
|
-
(
|
|
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", (
|
|
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
|
-
(
|
|
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
|
-
(
|
|
777
|
+
(r) => {
|
|
769
778
|
var d;
|
|
770
|
-
return ["markmap-node", ((d =
|
|
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
|
-
(
|
|
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
|
-
(
|
|
781
|
-
(
|
|
789
|
+
(r) => [r],
|
|
790
|
+
(r) => r.data.state.key
|
|
782
791
|
).join(
|
|
783
|
-
(
|
|
784
|
-
(
|
|
785
|
-
(
|
|
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", (
|
|
788
|
-
const
|
|
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
|
-
(
|
|
800
|
+
(r) => {
|
|
792
801
|
var d;
|
|
793
|
-
return (d =
|
|
802
|
+
return (d = r.data.children) != null && d.length ? [r] : [];
|
|
794
803
|
},
|
|
795
|
-
(
|
|
804
|
+
(r) => r.data.state.key
|
|
796
805
|
).join(
|
|
797
|
-
(
|
|
798
|
-
(
|
|
799
|
-
(
|
|
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(
|
|
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
|
-
(
|
|
812
|
+
(r) => {
|
|
804
813
|
var d;
|
|
805
|
-
return (d =
|
|
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
|
|
817
|
+
const rt = E.selectAll(
|
|
809
818
|
C("foreignObject")
|
|
810
819
|
).data(
|
|
811
|
-
(
|
|
812
|
-
(
|
|
820
|
+
(r) => [r],
|
|
821
|
+
(r) => r.data.state.key
|
|
813
822
|
).join(
|
|
814
|
-
(
|
|
815
|
-
const 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
|
-
(
|
|
822
|
-
(
|
|
830
|
+
(r) => r,
|
|
831
|
+
(r) => r.remove()
|
|
823
832
|
).attr(
|
|
824
833
|
"width",
|
|
825
|
-
(
|
|
826
|
-
).attr("height", (
|
|
827
|
-
this.transition(
|
|
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, (
|
|
831
|
-
(
|
|
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
|
|
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
|
-
(
|
|
839
|
-
(
|
|
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(
|
|
853
|
+
return this.transition(r).attr("d", u({ source: d, target: d })).remove();
|
|
845
854
|
}
|
|
846
855
|
);
|
|
847
|
-
this.transition(ot).attr("stroke", (
|
|
848
|
-
const d =
|
|
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((
|
|
857
|
-
|
|
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
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
),
|
|
873
|
-
(
|
|
874
|
-
(
|
|
875
|
-
).scale(
|
|
876
|
-
return this.transition(this.svg).call(this.zoom.transform,
|
|
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
|
|
895
|
-
if (!
|
|
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
|
-
|
|
899
|
-
|
|
907
|
+
i.y,
|
|
908
|
+
i.y + i.ySize - a + 2
|
|
900
909
|
].map((v) => v * s.k + s.x), [h, u] = [
|
|
901
|
-
|
|
902
|
-
|
|
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 ?
|
|
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:
|
|
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,
|
|
939
|
+
static create(t, n, i = null) {
|
|
931
940
|
const o = new et(t, n);
|
|
932
|
-
return
|
|
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
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.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
|
-
"
|
|
48
|
-
|
|
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
|
+
}
|