markmap-view 0.18.0 → 0.18.2
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 +36 -10
- package/dist/index.js +186 -170
- package/dist/view.d.ts +4 -1
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -978,6 +978,7 @@
|
|
|
978
978
|
if (isMacintosh ? e.metaKey : e.ctrlKey) recursive = !recursive;
|
|
979
979
|
this.toggleNode(d, recursive);
|
|
980
980
|
};
|
|
981
|
+
this.ensureView = this.ensureVisible;
|
|
981
982
|
this.svg = svg.datum ? svg : d32.select(svg);
|
|
982
983
|
this.styleNode = this.svg.append("style");
|
|
983
984
|
this.zoom = d32.zoom().filter((event) => {
|
|
@@ -1099,7 +1100,7 @@
|
|
|
1099
1100
|
const node = fnode.data;
|
|
1100
1101
|
node.state.rect = {
|
|
1101
1102
|
x: fnode.y,
|
|
1102
|
-
y: fnode.x,
|
|
1103
|
+
y: fnode.x - fnode.xSize / 2,
|
|
1103
1104
|
width: fnode.ySize - spacingHorizontal,
|
|
1104
1105
|
height: fnode.xSize
|
|
1105
1106
|
};
|
|
@@ -1225,16 +1226,16 @@
|
|
|
1225
1226
|
this._relayout();
|
|
1226
1227
|
this.transition(mmGExit).attr("transform", (d) => {
|
|
1227
1228
|
const targetX = originRect.x + originRect.width - d.state.rect.width;
|
|
1228
|
-
const targetY = originRect.y + originRect.height
|
|
1229
|
+
const targetY = originRect.y + originRect.height - d.state.rect.height;
|
|
1229
1230
|
return `translate(${targetX},${targetY})`;
|
|
1230
1231
|
}).remove();
|
|
1231
1232
|
mmGEnter.attr(
|
|
1232
1233
|
"transform",
|
|
1233
|
-
(d) => `translate(${originRect.x + originRect.width - d.state.rect.width},${originRect.y + originRect.height
|
|
1234
|
+
(d) => `translate(${originRect.x + originRect.width - d.state.rect.width},${originRect.y + originRect.height - d.state.rect.height})`
|
|
1234
1235
|
);
|
|
1235
1236
|
this.transition(mmGMerge).attr(
|
|
1236
1237
|
"transform",
|
|
1237
|
-
(d) => `translate(${d.state.rect.x},${d.state.rect.y
|
|
1238
|
+
(d) => `translate(${d.state.rect.x},${d.state.rect.y})`
|
|
1238
1239
|
);
|
|
1239
1240
|
this.transition(mmLineExit).attr("x1", (d) => d.state.rect.width).attr("x2", (d) => d.state.rect.width);
|
|
1240
1241
|
mmLineEnter.attr("x1", (d) => d.state.rect.width).attr("x2", (d) => d.state.rect.width);
|
|
@@ -1253,7 +1254,7 @@
|
|
|
1253
1254
|
this.transition(mmFoMerge).style("opacity", 1);
|
|
1254
1255
|
const pathOrigin = [
|
|
1255
1256
|
originRect.x + originRect.width,
|
|
1256
|
-
originRect.y + originRect.height
|
|
1257
|
+
originRect.y + originRect.height
|
|
1257
1258
|
];
|
|
1258
1259
|
this.transition(mmPathExit).attr("d", linkShape({ source: pathOrigin, target: pathOrigin })).remove();
|
|
1259
1260
|
mmPathEnter.attr(
|
|
@@ -1265,11 +1266,11 @@
|
|
|
1265
1266
|
const origTarget = d.target;
|
|
1266
1267
|
const source = [
|
|
1267
1268
|
origSource.state.rect.x + origSource.state.rect.width,
|
|
1268
|
-
origSource.state.rect.y + origSource.state.rect.height
|
|
1269
|
+
origSource.state.rect.y + origSource.state.rect.height
|
|
1269
1270
|
];
|
|
1270
1271
|
const target = [
|
|
1271
1272
|
origTarget.state.rect.x,
|
|
1272
|
-
origTarget.state.rect.y + origTarget.state.rect.height
|
|
1273
|
+
origTarget.state.rect.y + origTarget.state.rect.height
|
|
1273
1274
|
];
|
|
1274
1275
|
return linkShape({ source, target });
|
|
1275
1276
|
});
|
|
@@ -1315,7 +1316,7 @@
|
|
|
1315
1316
|
/**
|
|
1316
1317
|
* Pan the content to make the provided node visible in the viewport.
|
|
1317
1318
|
*/
|
|
1318
|
-
async
|
|
1319
|
+
async ensureVisible(node, padding) {
|
|
1319
1320
|
var _a;
|
|
1320
1321
|
const itemData = (_a = this.findElement(node)) == null ? void 0 : _a.data;
|
|
1321
1322
|
if (!itemData) return;
|
|
@@ -1327,8 +1328,8 @@
|
|
|
1327
1328
|
itemData.state.rect.x + itemData.state.rect.width + 2
|
|
1328
1329
|
].map((x) => x * transform.k + transform.x);
|
|
1329
1330
|
const [top, bottom] = [
|
|
1330
|
-
itemData.state.rect.y
|
|
1331
|
-
itemData.state.rect.y + itemData.state.rect.height
|
|
1331
|
+
itemData.state.rect.y,
|
|
1332
|
+
itemData.state.rect.y + itemData.state.rect.height
|
|
1332
1333
|
].map((y) => y * transform.k + transform.y);
|
|
1333
1334
|
const pd = {
|
|
1334
1335
|
left: 0,
|
|
@@ -1346,6 +1347,31 @@
|
|
|
1346
1347
|
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
|
|
1347
1348
|
}
|
|
1348
1349
|
}
|
|
1350
|
+
async centerNode(node, padding) {
|
|
1351
|
+
var _a;
|
|
1352
|
+
const itemData = (_a = this.findElement(node)) == null ? void 0 : _a.data;
|
|
1353
|
+
if (!itemData) return;
|
|
1354
|
+
const svgNode = this.svg.node();
|
|
1355
|
+
const relRect = svgNode.getBoundingClientRect();
|
|
1356
|
+
const transform = d32.zoomTransform(svgNode);
|
|
1357
|
+
const x = (itemData.state.rect.x + itemData.state.rect.width / 2) * transform.k + transform.x;
|
|
1358
|
+
const y = (itemData.state.rect.y + itemData.state.rect.height / 2) * transform.k + transform.y;
|
|
1359
|
+
const pd = {
|
|
1360
|
+
left: 0,
|
|
1361
|
+
right: 0,
|
|
1362
|
+
top: 0,
|
|
1363
|
+
bottom: 0,
|
|
1364
|
+
...padding
|
|
1365
|
+
};
|
|
1366
|
+
const cx = (pd.left + relRect.width - pd.right) / 2;
|
|
1367
|
+
const cy = (pd.top + relRect.height - pd.bottom) / 2;
|
|
1368
|
+
const dx = (cx - x) / transform.k;
|
|
1369
|
+
const dy = (cy - y) / transform.k;
|
|
1370
|
+
if (dx || dy) {
|
|
1371
|
+
const newTransform = transform.translate(dx, dy);
|
|
1372
|
+
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1349
1375
|
/**
|
|
1350
1376
|
* Scale content with it pinned at the center of the viewport.
|
|
1351
1377
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Hook as et, getId as nt, debounce as rt, addClass as it, walkTree as
|
|
1
|
+
import { Hook as et, getId as nt, debounce as rt, addClass as it, walkTree as j, childSelector as b, noop as E } from "markmap-common";
|
|
2
2
|
import { loadCSS as ce, loadJS as he } from "markmap-common";
|
|
3
|
-
import { scaleOrdinal as
|
|
4
|
-
const P = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), dt =
|
|
3
|
+
import { scaleOrdinal as L, schemeCategory10 as st, linkHorizontal as ot, zoomTransform as C, select as at, zoom as lt, min as T, max as _, zoomIdentity as ct, minIndex as ht } from "d3";
|
|
4
|
+
const P = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), dt = L(st), W = {
|
|
5
5
|
autoFit: !1,
|
|
6
6
|
color: (e) => {
|
|
7
7
|
var t;
|
|
@@ -23,12 +23,12 @@ const P = typeof navigator < "u" && navigator.userAgent.includes("Macintosh"), d
|
|
|
23
23
|
toggleRecursively: !1
|
|
24
24
|
};
|
|
25
25
|
function se(e) {
|
|
26
|
-
const t = {},
|
|
27
|
-
if ((
|
|
28
|
-
const i =
|
|
26
|
+
const t = {}, r = { ...e }, { color: n, colorFreezeLevel: s } = r;
|
|
27
|
+
if ((n == null ? void 0 : n.length) === 1) {
|
|
28
|
+
const i = n[0];
|
|
29
29
|
t.color = () => i;
|
|
30
|
-
} else if (
|
|
31
|
-
const i =
|
|
30
|
+
} else if (n != null && n.length) {
|
|
31
|
+
const i = L(n);
|
|
32
32
|
t.color = (a) => i(`${a.state.path}`);
|
|
33
33
|
}
|
|
34
34
|
if (s) {
|
|
@@ -52,55 +52,55 @@ function se(e) {
|
|
|
52
52
|
"spacingHorizontal",
|
|
53
53
|
"spacingVertical"
|
|
54
54
|
].forEach((i) => {
|
|
55
|
-
const a =
|
|
55
|
+
const a = r[i];
|
|
56
56
|
typeof a == "number" && (t[i] = a);
|
|
57
57
|
}), ["zoom", "pan"].forEach((i) => {
|
|
58
|
-
const a =
|
|
58
|
+
const a = r[i];
|
|
59
59
|
a != null && (t[i] = !!a);
|
|
60
60
|
}), t;
|
|
61
61
|
}
|
|
62
62
|
function pt(e) {
|
|
63
63
|
let t = 0;
|
|
64
|
-
for (let
|
|
65
|
-
t = (t << 5) - t + e.charCodeAt(
|
|
64
|
+
for (let r = 0; r < e.length; r++)
|
|
65
|
+
t = (t << 5) - t + e.charCodeAt(r) | 0;
|
|
66
66
|
return (t >>> 0).toString(36);
|
|
67
67
|
}
|
|
68
68
|
function ut(e) {
|
|
69
|
-
var t = 0,
|
|
70
|
-
if (!
|
|
71
|
-
else for (; --
|
|
69
|
+
var t = 0, r = e.children, n = r && r.length;
|
|
70
|
+
if (!n) t = 1;
|
|
71
|
+
else for (; --n >= 0; ) t += r[n].value;
|
|
72
72
|
e.value = t;
|
|
73
73
|
}
|
|
74
74
|
function mt() {
|
|
75
75
|
return this.eachAfter(ut);
|
|
76
76
|
}
|
|
77
77
|
function gt(e) {
|
|
78
|
-
var t = this,
|
|
78
|
+
var t = this, r, n = [t], s, l, c;
|
|
79
79
|
do
|
|
80
|
-
for (
|
|
80
|
+
for (r = n.reverse(), n = []; t = r.pop(); )
|
|
81
81
|
if (e(t), s = t.children, s) for (l = 0, c = s.length; l < c; ++l)
|
|
82
|
-
|
|
83
|
-
while (
|
|
82
|
+
n.push(s[l]);
|
|
83
|
+
while (n.length);
|
|
84
84
|
return this;
|
|
85
85
|
}
|
|
86
86
|
function ft(e) {
|
|
87
|
-
for (var t = this,
|
|
88
|
-
if (e(t),
|
|
89
|
-
|
|
87
|
+
for (var t = this, r = [t], n, s; t = r.pop(); )
|
|
88
|
+
if (e(t), n = t.children, n) for (s = n.length - 1; s >= 0; --s)
|
|
89
|
+
r.push(n[s]);
|
|
90
90
|
return this;
|
|
91
91
|
}
|
|
92
92
|
function xt(e) {
|
|
93
|
-
for (var t = this,
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
for (; t =
|
|
93
|
+
for (var t = this, r = [t], n = [], s, l, c; t = r.pop(); )
|
|
94
|
+
if (n.push(t), s = t.children, s) for (l = 0, c = s.length; l < c; ++l)
|
|
95
|
+
r.push(s[l]);
|
|
96
|
+
for (; t = n.pop(); )
|
|
97
97
|
e(t);
|
|
98
98
|
return this;
|
|
99
99
|
}
|
|
100
100
|
function yt(e) {
|
|
101
101
|
return this.eachAfter(function(t) {
|
|
102
|
-
for (var
|
|
103
|
-
t.value =
|
|
102
|
+
for (var r = +e(t.data) || 0, n = t.children, s = n && n.length; --s >= 0; ) r += n[s].value;
|
|
103
|
+
t.value = r;
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
function kt(e) {
|
|
@@ -109,17 +109,17 @@ function kt(e) {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
function vt(e) {
|
|
112
|
-
for (var t = this,
|
|
113
|
-
t = t.parent,
|
|
114
|
-
for (var s =
|
|
115
|
-
|
|
116
|
-
return
|
|
112
|
+
for (var t = this, r = bt(t, e), n = [t]; t !== r; )
|
|
113
|
+
t = t.parent, n.push(t);
|
|
114
|
+
for (var s = n.length; e !== r; )
|
|
115
|
+
n.splice(s, 0, e), e = e.parent;
|
|
116
|
+
return n;
|
|
117
117
|
}
|
|
118
118
|
function bt(e, t) {
|
|
119
119
|
if (e === t) return e;
|
|
120
|
-
var
|
|
121
|
-
for (e =
|
|
122
|
-
s = e, e =
|
|
120
|
+
var r = e.ancestors(), n = t.ancestors(), s = null;
|
|
121
|
+
for (e = r.pop(), t = n.pop(); e === t; )
|
|
122
|
+
s = e, e = r.pop(), t = n.pop();
|
|
123
123
|
return s;
|
|
124
124
|
}
|
|
125
125
|
function zt() {
|
|
@@ -141,17 +141,17 @@ function Et() {
|
|
|
141
141
|
}
|
|
142
142
|
function Ct() {
|
|
143
143
|
var e = this, t = [];
|
|
144
|
-
return e.each(function(
|
|
145
|
-
|
|
144
|
+
return e.each(function(r) {
|
|
145
|
+
r !== e && t.push({ source: r.parent, target: r });
|
|
146
146
|
}), t;
|
|
147
147
|
}
|
|
148
148
|
function O(e, t) {
|
|
149
|
-
var
|
|
149
|
+
var r = new w(e), n = +e.value && (r.value = e.value), s, l = [r], c, i, a, d;
|
|
150
150
|
for (t == null && (t = Xt); s = l.pop(); )
|
|
151
|
-
if (
|
|
151
|
+
if (n && (s.value = +s.data.value), (i = t(s.data)) && (d = i.length))
|
|
152
152
|
for (s.children = new Array(d), a = d - 1; a >= 0; --a)
|
|
153
|
-
l.push(c = s.children[a] = new
|
|
154
|
-
return
|
|
153
|
+
l.push(c = s.children[a] = new w(i[a])), c.parent = s, c.depth = s.depth + 1;
|
|
154
|
+
return r.eachBefore(jt);
|
|
155
155
|
}
|
|
156
156
|
function wt() {
|
|
157
157
|
return O(this).eachBefore(Rt);
|
|
@@ -168,11 +168,11 @@ function jt(e) {
|
|
|
168
168
|
e.height = t;
|
|
169
169
|
while ((e = e.parent) && e.height < ++t);
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function w(e) {
|
|
172
172
|
this.data = e, this.depth = this.height = 0, this.parent = null;
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
constructor:
|
|
174
|
+
w.prototype = O.prototype = {
|
|
175
|
+
constructor: w,
|
|
176
176
|
count: mt,
|
|
177
177
|
each: gt,
|
|
178
178
|
eachAfter: xt,
|
|
@@ -186,20 +186,20 @@ E.prototype = O.prototype = {
|
|
|
186
186
|
links: Ct,
|
|
187
187
|
copy: wt
|
|
188
188
|
};
|
|
189
|
-
const Mt = "d3-flextree", Bt = "2.1.2", Ot = "build/d3-flextree.js", $t = "index", At = { name: "Chris Maloney", url: "http://chrismaloney.org" },
|
|
189
|
+
const Mt = "d3-flextree", Bt = "2.1.2", Ot = "build/d3-flextree.js", $t = "index", At = { name: "Chris Maloney", url: "http://chrismaloney.org" }, Dt = "Flexible tree layout algorithm that allows for variable node sizes.", Ft = ["d3", "d3-module", "layout", "tree", "hierarchy", "d3-hierarchy", "plugin", "d3-plugin", "infovis", "visualization", "2d"], Tt = "https://github.com/klortho/d3-flextree", _t = "WTFPL", Ht = { type: "git", url: "https://github.com/klortho/d3-flextree.git" }, Nt = { clean: "rm -rf build demo test", "build:demo": "rollup -c --environment BUILD:demo", "build:dev": "rollup -c --environment BUILD:dev", "build:prod": "rollup -c --environment BUILD:prod", "build:test": "rollup -c --environment BUILD:test", build: "rollup -c", lint: "eslint index.js src", "test:main": "node test/bundle.js", "test:browser": "node test/browser-tests.js", test: "npm-run-all test:*", prepare: "npm-run-all clean build lint test" }, Lt = { "d3-hierarchy": "^1.1.5" }, Pt = { "babel-plugin-external-helpers": "^6.22.0", "babel-preset-es2015-rollup": "^3.0.0", d3: "^4.13.0", "d3-selection-multi": "^1.0.1", eslint: "^4.19.1", jsdom: "^11.6.2", "npm-run-all": "^4.1.2", rollup: "^0.55.3", "rollup-plugin-babel": "^2.7.1", "rollup-plugin-commonjs": "^8.0.2", "rollup-plugin-copy": "^0.2.3", "rollup-plugin-json": "^2.3.0", "rollup-plugin-node-resolve": "^3.0.2", "rollup-plugin-uglify": "^3.0.0", "uglify-es": "^3.3.9" }, Wt = {
|
|
190
190
|
name: Mt,
|
|
191
191
|
version: Bt,
|
|
192
192
|
main: Ot,
|
|
193
193
|
module: $t,
|
|
194
194
|
"jsnext:main": "index",
|
|
195
195
|
author: At,
|
|
196
|
-
description:
|
|
197
|
-
keywords:
|
|
196
|
+
description: Dt,
|
|
197
|
+
keywords: Ft,
|
|
198
198
|
homepage: Tt,
|
|
199
199
|
license: _t,
|
|
200
200
|
repository: Ht,
|
|
201
|
-
scripts:
|
|
202
|
-
dependencies:
|
|
201
|
+
scripts: Nt,
|
|
202
|
+
dependencies: Lt,
|
|
203
203
|
devDependencies: Pt
|
|
204
204
|
}, { version: It } = Wt, Kt = Object.freeze({
|
|
205
205
|
children: (e) => e.children,
|
|
@@ -208,16 +208,16 @@ const Mt = "d3-flextree", Bt = "2.1.2", Ot = "build/d3-flextree.js", $t = "index
|
|
|
208
208
|
});
|
|
209
209
|
function K(e) {
|
|
210
210
|
const t = Object.assign({}, Kt, e);
|
|
211
|
-
function
|
|
211
|
+
function r(i) {
|
|
212
212
|
const a = t[i];
|
|
213
213
|
return typeof a == "function" ? a : () => a;
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function n(i) {
|
|
216
216
|
const a = c(l(), i, (d) => d.children);
|
|
217
217
|
return a.update(), a.data;
|
|
218
218
|
}
|
|
219
219
|
function s() {
|
|
220
|
-
const i =
|
|
220
|
+
const i = r("nodeSize"), a = r("spacing");
|
|
221
221
|
return class I extends O.prototype.constructor {
|
|
222
222
|
constructor(h) {
|
|
223
223
|
super(h);
|
|
@@ -297,7 +297,7 @@ function K(e) {
|
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
299
|
function l() {
|
|
300
|
-
const i = s(), a =
|
|
300
|
+
const i = s(), a = r("nodeSize"), d = r("spacing");
|
|
301
301
|
return class extends i {
|
|
302
302
|
constructor(h) {
|
|
303
303
|
super(h), Object.assign(this, {
|
|
@@ -334,7 +334,7 @@ function K(e) {
|
|
|
334
334
|
this.data.y = h;
|
|
335
335
|
}
|
|
336
336
|
update() {
|
|
337
|
-
return G(this),
|
|
337
|
+
return G(this), V(this), this;
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
}
|
|
@@ -358,123 +358,123 @@ function K(e) {
|
|
|
358
358
|
};
|
|
359
359
|
return h(a, null);
|
|
360
360
|
}
|
|
361
|
-
return Object.assign(
|
|
361
|
+
return Object.assign(n, {
|
|
362
362
|
nodeSize(i) {
|
|
363
|
-
return arguments.length ? (t.nodeSize = i,
|
|
363
|
+
return arguments.length ? (t.nodeSize = i, n) : t.nodeSize;
|
|
364
364
|
},
|
|
365
365
|
spacing(i) {
|
|
366
|
-
return arguments.length ? (t.spacing = i,
|
|
366
|
+
return arguments.length ? (t.spacing = i, n) : t.spacing;
|
|
367
367
|
},
|
|
368
368
|
children(i) {
|
|
369
|
-
return arguments.length ? (t.children = i,
|
|
369
|
+
return arguments.length ? (t.children = i, n) : t.children;
|
|
370
370
|
},
|
|
371
371
|
hierarchy(i, a) {
|
|
372
372
|
const d = typeof a > "u" ? t.children : a;
|
|
373
373
|
return c(s(), i, d);
|
|
374
374
|
},
|
|
375
375
|
dump(i) {
|
|
376
|
-
const a =
|
|
376
|
+
const a = r("nodeSize"), d = (h) => (p) => {
|
|
377
377
|
const u = h + " ", g = h + " ", { x: f, y: x } = p, v = a(p), k = p.children || [], z = k.length === 0 ? " " : `,${u}children: [${g}${k.map(d(g)).join(g)}${u}],${h}`;
|
|
378
378
|
return `{ size: [${v.join(", ")}],${u}x: ${f}, y: ${x}${z}},`;
|
|
379
379
|
};
|
|
380
380
|
return d(`
|
|
381
381
|
`)(i);
|
|
382
382
|
}
|
|
383
|
-
}),
|
|
383
|
+
}), n;
|
|
384
384
|
}
|
|
385
385
|
K.version = It;
|
|
386
|
-
const G = (e, t = 0) => (e.y = t, (e.children || []).reduce((
|
|
387
|
-
const [s, l] =
|
|
388
|
-
G(
|
|
389
|
-
const c = (s === 0 ?
|
|
390
|
-
s !== 0 &&
|
|
386
|
+
const G = (e, t = 0) => (e.y = t, (e.children || []).reduce((r, n) => {
|
|
387
|
+
const [s, l] = r;
|
|
388
|
+
G(n, e.y + e.ySize);
|
|
389
|
+
const c = (s === 0 ? n.lExt : n.rExt).bottom;
|
|
390
|
+
s !== 0 && Vt(e, s, l);
|
|
391
391
|
const i = ee(c, s, l);
|
|
392
392
|
return [s + 1, i];
|
|
393
|
-
}, [0, null]), Gt(e), te(e), e),
|
|
394
|
-
typeof t > "u" && (t = -e.relX - e.prelim,
|
|
395
|
-
const
|
|
396
|
-
return e.relX =
|
|
393
|
+
}, [0, null]), Gt(e), te(e), e), V = (e, t, r) => {
|
|
394
|
+
typeof t > "u" && (t = -e.relX - e.prelim, r = 0);
|
|
395
|
+
const n = t + e.relX;
|
|
396
|
+
return e.relX = n + e.prelim - r, e.prelim = 0, e.x = r + e.relX, (e.children || []).forEach((s) => V(s, n, e.x)), e;
|
|
397
397
|
}, Gt = (e) => {
|
|
398
|
-
(e.children || []).reduce((t,
|
|
399
|
-
const [
|
|
400
|
-
return
|
|
398
|
+
(e.children || []).reduce((t, r) => {
|
|
399
|
+
const [n, s] = t, l = n + r.shift, c = s + l + r.change;
|
|
400
|
+
return r.relX += c, [l, c];
|
|
401
401
|
}, [0, 0]);
|
|
402
|
-
},
|
|
403
|
-
const
|
|
404
|
-
let l =
|
|
402
|
+
}, Vt = (e, t, r) => {
|
|
403
|
+
const n = e.children[t - 1], s = e.children[t];
|
|
404
|
+
let l = n, c = n.relX, i = s, a = s.relX, d = !0;
|
|
405
405
|
for (; l && i; ) {
|
|
406
|
-
l.bottom >
|
|
406
|
+
l.bottom > r.lowY && (r = r.next);
|
|
407
407
|
const h = c + l.prelim - (a + i.prelim) + l.xSize / 2 + i.xSize / 2 + l.spacing(i);
|
|
408
|
-
(h > 0 || h < 0 && d) && (a += h,
|
|
408
|
+
(h > 0 || h < 0 && d) && (a += h, Ut(s, h), Yt(e, t, r.index, h)), d = !1;
|
|
409
409
|
const p = l.bottom, u = i.bottom;
|
|
410
410
|
p <= u && (l = qt(l), l && (c += l.relX)), p >= u && (i = Zt(i), i && (a += i.relX));
|
|
411
411
|
}
|
|
412
412
|
!l && i ? Jt(e, t, i, a) : l && !i && Qt(e, t, l, c);
|
|
413
|
-
},
|
|
413
|
+
}, Ut = (e, t) => {
|
|
414
414
|
e.relX += t, e.lExtRelX += t, e.rExtRelX += t;
|
|
415
|
-
}, Yt = (e, t,
|
|
416
|
-
const s = e.children[t], l = t -
|
|
415
|
+
}, Yt = (e, t, r, n) => {
|
|
416
|
+
const s = e.children[t], l = t - r;
|
|
417
417
|
if (l > 1) {
|
|
418
|
-
const c =
|
|
419
|
-
e.children[
|
|
418
|
+
const c = n / l;
|
|
419
|
+
e.children[r + 1].shift += c, s.shift -= c, s.change -= n - c;
|
|
420
420
|
}
|
|
421
|
-
}, Zt = (e) => e.hasChildren ? e.firstChild : e.lThr, qt = (e) => e.hasChildren ? e.lastChild : e.rThr, Jt = (e, t,
|
|
421
|
+
}, Zt = (e) => e.hasChildren ? e.firstChild : e.lThr, qt = (e) => e.hasChildren ? e.lastChild : e.rThr, Jt = (e, t, r, n) => {
|
|
422
422
|
const s = e.firstChild, l = s.lExt, c = e.children[t];
|
|
423
|
-
l.lThr =
|
|
424
|
-
const i =
|
|
423
|
+
l.lThr = r;
|
|
424
|
+
const i = n - r.relX - s.lExtRelX;
|
|
425
425
|
l.relX += i, l.prelim -= i, s.lExt = c.lExt, s.lExtRelX = c.lExtRelX;
|
|
426
|
-
}, Qt = (e, t,
|
|
426
|
+
}, Qt = (e, t, r, n) => {
|
|
427
427
|
const s = e.children[t], l = s.rExt, c = e.children[t - 1];
|
|
428
|
-
l.rThr =
|
|
429
|
-
const i =
|
|
428
|
+
l.rThr = r;
|
|
429
|
+
const i = n - r.relX - s.rExtRelX;
|
|
430
430
|
l.relX += i, l.prelim -= i, s.rExt = c.rExt, s.rExtRelX = c.rExtRelX;
|
|
431
431
|
}, te = (e) => {
|
|
432
432
|
if (e.hasChildren) {
|
|
433
|
-
const t = e.firstChild,
|
|
433
|
+
const t = e.firstChild, r = e.lastChild, n = (t.prelim + t.relX - t.xSize / 2 + r.relX + r.prelim + r.xSize / 2) / 2;
|
|
434
434
|
Object.assign(e, {
|
|
435
|
-
prelim:
|
|
435
|
+
prelim: n,
|
|
436
436
|
lExt: t.lExt,
|
|
437
437
|
lExtRelX: t.lExtRelX,
|
|
438
|
-
rExt:
|
|
439
|
-
rExtRelX:
|
|
438
|
+
rExt: r.rExt,
|
|
439
|
+
rExtRelX: r.rExtRelX
|
|
440
440
|
});
|
|
441
441
|
}
|
|
442
|
-
}, ee = (e, t,
|
|
443
|
-
for (;
|
|
444
|
-
|
|
442
|
+
}, ee = (e, t, r) => {
|
|
443
|
+
for (; r !== null && e >= r.lowY; )
|
|
444
|
+
r = r.next;
|
|
445
445
|
return {
|
|
446
446
|
lowY: e,
|
|
447
447
|
index: t,
|
|
448
|
-
next:
|
|
448
|
+
next: r
|
|
449
449
|
};
|
|
450
|
-
},
|
|
450
|
+
}, U = ".markmap{--markmap-max-width: 9999px;--markmap-a-color: #0097e6;--markmap-a-hover-color: #00a8ff;--markmap-code-bg: #f0f0f0;--markmap-code-color: #555;--markmap-highlight-bg: #ffeaa7;--markmap-table-border: 1px solid currentColor;--markmap-font: 300 16px/20px sans-serif;--markmap-circle-open-bg: #fff;--markmap-text-color: #333;font:var(--markmap-font);color:var(--markmap-text-color)}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign p{margin:0}.markmap-foreign a{color:var(--markmap-a-color)}.markmap-foreign a:hover{color:var(--markmap-a-hover-color)}.markmap-foreign code{padding:.25em;font-size:calc(1em - 2px);color:var(--markmap-code-color);background-color:var(--markmap-code-bg);border-radius:2px}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:var(--markmap-highlight-bg)}.markmap-foreign table,.markmap-foreign th,.markmap-foreign td{border-collapse:collapse;border:var(--markmap-table-border)}.markmap-foreign img{display:inline-block}.markmap-foreign svg{fill:currentColor}.markmap-foreign>div{width:var(--markmap-max-width);text-align:left}.markmap-foreign>div>div{display:inline-block}.markmap-dark .markmap{--markmap-code-bg: #1a1b26;--markmap-code-color: #ddd;--markmap-circle-open-bg: #444;--markmap-text-color: #eee}", oe = U, M = ot();
|
|
451
451
|
function H(e) {
|
|
452
452
|
return Math.max(4 - 2 * e.state.depth, 1.5);
|
|
453
453
|
}
|
|
454
|
-
function
|
|
455
|
-
const
|
|
456
|
-
return e[
|
|
454
|
+
function N(e, t) {
|
|
455
|
+
const r = ht(e, t);
|
|
456
|
+
return e[r];
|
|
457
457
|
}
|
|
458
458
|
function B(e) {
|
|
459
459
|
e.stopPropagation();
|
|
460
460
|
}
|
|
461
461
|
const ne = new et();
|
|
462
462
|
class Y {
|
|
463
|
-
constructor(t,
|
|
464
|
-
this.options = W, this.revokers = [], this.handleZoom = (
|
|
465
|
-
const { transform: s } =
|
|
463
|
+
constructor(t, r) {
|
|
464
|
+
this.options = W, this.revokers = [], this.handleZoom = (n) => {
|
|
465
|
+
const { transform: s } = n;
|
|
466
466
|
this.g.attr("transform", s);
|
|
467
|
-
}, this.handlePan = (
|
|
468
|
-
|
|
469
|
-
const s =
|
|
470
|
-
-
|
|
471
|
-
-
|
|
467
|
+
}, this.handlePan = (n) => {
|
|
468
|
+
n.preventDefault();
|
|
469
|
+
const s = C(this.svg.node()), l = s.translate(
|
|
470
|
+
-n.deltaX / s.k,
|
|
471
|
+
-n.deltaY / s.k
|
|
472
472
|
);
|
|
473
473
|
this.svg.call(this.zoom.transform, l);
|
|
474
|
-
}, this.handleClick = (
|
|
474
|
+
}, this.handleClick = (n, s) => {
|
|
475
475
|
let l = this.options.toggleRecursively;
|
|
476
|
-
(P ?
|
|
477
|
-
}, this.svg = t.datum ? t : at(t), this.styleNode = this.svg.append("style"), this.zoom = lt().filter((
|
|
476
|
+
(P ? n.metaKey : n.ctrlKey) && (l = !l), this.toggleNode(s, l);
|
|
477
|
+
}, this.ensureView = this.ensureVisible, this.svg = t.datum ? t : at(t), this.styleNode = this.svg.append("style"), this.zoom = lt().filter((n) => this.options.scrollForPan && n.type === "wheel" ? n.ctrlKey && !n.button : (!n.ctrlKey || n.type === "wheel") && !n.button).on("zoom", this.handleZoom), this.setOptions(r), this.state = {
|
|
478
478
|
id: this.options.id || this.svg.attr("id") || nt(),
|
|
479
479
|
rect: { x1: 0, y1: 0, x2: 0, y2: 0 }
|
|
480
480
|
}, this.g = this.svg.append("g"), this.observer = new ResizeObserver(
|
|
@@ -488,8 +488,8 @@ class Y {
|
|
|
488
488
|
);
|
|
489
489
|
}
|
|
490
490
|
getStyleContent() {
|
|
491
|
-
const { style: t } = this.options, { id:
|
|
492
|
-
return [this.options.embedGlobalCSS &&
|
|
491
|
+
const { style: t } = this.options, { id: r } = this.state, n = typeof t == "function" ? t(r) : "";
|
|
492
|
+
return [this.options.embedGlobalCSS && U, n].filter(Boolean).join(`
|
|
493
493
|
`);
|
|
494
494
|
}
|
|
495
495
|
updateStyle() {
|
|
@@ -500,13 +500,13 @@ class Y {
|
|
|
500
500
|
const t = this.getStyleContent();
|
|
501
501
|
this.styleNode.text(t);
|
|
502
502
|
}
|
|
503
|
-
async toggleNode(t,
|
|
503
|
+
async toggleNode(t, r = !1) {
|
|
504
504
|
var s, l;
|
|
505
|
-
const
|
|
506
|
-
|
|
505
|
+
const n = (s = t.payload) != null && s.fold ? 0 : 1;
|
|
506
|
+
r ? j(t, (c, i) => {
|
|
507
507
|
c.payload = {
|
|
508
508
|
...c.payload,
|
|
509
|
-
fold:
|
|
509
|
+
fold: n
|
|
510
510
|
}, i();
|
|
511
511
|
}) : t.payload = {
|
|
512
512
|
...t.payload,
|
|
@@ -514,15 +514,15 @@ class Y {
|
|
|
514
514
|
}, await this.renderData(t);
|
|
515
515
|
}
|
|
516
516
|
_initializeData(t) {
|
|
517
|
-
let
|
|
518
|
-
const { color:
|
|
517
|
+
let r = 0;
|
|
518
|
+
const { color: n, initialExpandLevel: s } = this.options;
|
|
519
519
|
let l = 0, c = 0;
|
|
520
|
-
|
|
520
|
+
j(t, (i, a, d) => {
|
|
521
521
|
var p, u, g, f;
|
|
522
|
-
c += 1, i.children = (p = i.children) == null ? void 0 : p.map((x) => ({ ...x })),
|
|
522
|
+
c += 1, i.children = (p = i.children) == null ? void 0 : p.map((x) => ({ ...x })), r += 1, i.state = {
|
|
523
523
|
...i.state,
|
|
524
524
|
depth: c,
|
|
525
|
-
id:
|
|
525
|
+
id: r,
|
|
526
526
|
rect: {
|
|
527
527
|
x: 0,
|
|
528
528
|
y: 0,
|
|
@@ -530,7 +530,7 @@ class Y {
|
|
|
530
530
|
height: 0
|
|
531
531
|
},
|
|
532
532
|
size: [0, 0]
|
|
533
|
-
}, i.state.key = [(u = d == null ? void 0 : d.state) == null ? void 0 : u.id, i.state.id].filter(Boolean).join(".") + pt(i.content), i.state.path = [(g = d == null ? void 0 : d.state) == null ? void 0 : g.path, i.state.id].filter(Boolean).join("."),
|
|
533
|
+
}, i.state.key = [(u = d == null ? void 0 : d.state) == null ? void 0 : u.id, i.state.id].filter(Boolean).join(".") + pt(i.content), i.state.path = [(g = d == null ? void 0 : d.state) == null ? void 0 : g.path, i.state.id].filter(Boolean).join("."), n(i);
|
|
534
534
|
const h = ((f = i.payload) == null ? void 0 : f.fold) === 2;
|
|
535
535
|
h ? l += 1 : (l || s >= 0 && i.state.depth >= s) && (i.payload = { ...i.payload, fold: 1 }), a(), h && (l -= 1), c -= 1;
|
|
536
536
|
});
|
|
@@ -544,20 +544,20 @@ class Y {
|
|
|
544
544
|
const a = (h = this.firstChild) == null ? void 0 : h.firstChild, d = [a.scrollWidth, a.scrollHeight];
|
|
545
545
|
i.state.size = d;
|
|
546
546
|
});
|
|
547
|
-
const { spacingHorizontal: t, paddingX:
|
|
547
|
+
const { spacingHorizontal: t, paddingX: r, spacingVertical: n } = this.options, s = K({}).children((i) => {
|
|
548
548
|
var a;
|
|
549
549
|
if (!((a = i.payload) != null && a.fold)) return i.children;
|
|
550
550
|
}).nodeSize((i) => {
|
|
551
551
|
const [a, d] = i.data.state.size;
|
|
552
|
-
return [d, a + (a ?
|
|
553
|
-
}).spacing((i, a) => i.parent === a.parent ?
|
|
552
|
+
return [d, a + (a ? r * 2 : 0) + t];
|
|
553
|
+
}).spacing((i, a) => i.parent === a.parent ? n : n * 2), l = s.hierarchy(this.state.data);
|
|
554
554
|
s(l);
|
|
555
555
|
const c = l.descendants();
|
|
556
556
|
c.forEach((i) => {
|
|
557
557
|
const a = i.data;
|
|
558
558
|
a.state.rect = {
|
|
559
559
|
x: i.y,
|
|
560
|
-
y: i.x,
|
|
560
|
+
y: i.x - i.xSize / 2,
|
|
561
561
|
width: i.ySize - t,
|
|
562
562
|
height: i.xSize
|
|
563
563
|
};
|
|
@@ -580,14 +580,14 @@ class Y {
|
|
|
580
580
|
...t
|
|
581
581
|
}, this.options.zoom ? this.svg.call(this.zoom) : this.svg.on(".zoom", null), this.options.pan ? this.svg.on("wheel", this.handlePan) : this.svg.on("wheel", null);
|
|
582
582
|
}
|
|
583
|
-
async setData(t,
|
|
584
|
-
|
|
583
|
+
async setData(t, r) {
|
|
584
|
+
r && this.setOptions(r), t && (this.state.data = t), this.state.data && (this._initializeData(this.state.data), this.updateStyle(), await this.renderData());
|
|
585
585
|
}
|
|
586
586
|
async renderData(t) {
|
|
587
|
-
const { paddingX:
|
|
587
|
+
const { paddingX: r, autoFit: n, color: s, maxWidth: l } = this.options;
|
|
588
588
|
if (!this.state.data) return;
|
|
589
589
|
const c = [];
|
|
590
|
-
|
|
590
|
+
j(this.state.data, (o, m) => {
|
|
591
591
|
var y;
|
|
592
592
|
(y = o.payload) != null && y.fold || m(), c.push(o);
|
|
593
593
|
});
|
|
@@ -617,8 +617,8 @@ class Y {
|
|
|
617
617
|
), z = this.observer, $ = u.selectAll(b("foreignObject")).data(
|
|
618
618
|
(o) => [o],
|
|
619
619
|
(o) => o.state.key
|
|
620
|
-
),
|
|
621
|
-
|
|
620
|
+
), X = $.enter().append("foreignObject").attr("class", "markmap-foreign").attr("x", r).attr("y", 0).style("opacity", 0).on("mousedown", B).on("dblclick", B);
|
|
621
|
+
X.append("xhtml:div").append("xhtml:div").html((o) => o.content).attr("xmlns", "http://www.w3.org/1999/xhtml"), X.each(function() {
|
|
622
622
|
var m;
|
|
623
623
|
const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
|
|
624
624
|
z.observe(o);
|
|
@@ -631,119 +631,135 @@ class Y {
|
|
|
631
631
|
const o = (m = this.firstChild) == null ? void 0 : m.firstChild;
|
|
632
632
|
z.unobserve(o);
|
|
633
633
|
});
|
|
634
|
-
const
|
|
634
|
+
const D = X.merge($), Z = c.flatMap(
|
|
635
635
|
(o) => {
|
|
636
636
|
var m;
|
|
637
637
|
return (m = o.payload) != null && m.fold ? [] : o.children.map((y) => ({ source: o, target: y }));
|
|
638
638
|
}
|
|
639
|
-
),
|
|
639
|
+
), R = this.g.selectAll(b("path")).data(Z, (o) => o.target.state.key), q = R.exit(), F = R.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (o) => o.target.state.depth).attr("data-path", (o) => o.target.state.path), J = F.merge(R);
|
|
640
640
|
this.svg.style(
|
|
641
641
|
"--markmap-max-width",
|
|
642
642
|
l ? `${l}px` : null
|
|
643
643
|
), await new Promise(requestAnimationFrame), this._relayout(), this.transition(p).attr("transform", (o) => {
|
|
644
|
-
const m = a.x + a.width - o.state.rect.width, y = a.y + a.height
|
|
644
|
+
const m = a.x + a.width - o.state.rect.width, y = a.y + a.height - o.state.rect.height;
|
|
645
645
|
return `translate(${m},${y})`;
|
|
646
646
|
}).remove(), h.attr(
|
|
647
647
|
"transform",
|
|
648
|
-
(o) => `translate(${a.x + a.width - o.state.rect.width},${a.y + a.height
|
|
648
|
+
(o) => `translate(${a.x + a.width - o.state.rect.width},${a.y + a.height - o.state.rect.height})`
|
|
649
649
|
), this.transition(u).attr(
|
|
650
650
|
"transform",
|
|
651
|
-
(o) => `translate(${o.state.rect.x},${o.state.rect.y
|
|
651
|
+
(o) => `translate(${o.state.rect.x},${o.state.rect.y})`
|
|
652
652
|
), this.transition(x).attr("x1", (o) => o.state.rect.width).attr("x2", (o) => o.state.rect.width), f.attr("x1", (o) => o.state.rect.width).attr("x2", (o) => o.state.rect.width), v.attr("y1", (o) => o.state.rect.height).attr("y2", (o) => o.state.rect.height).attr("stroke", (o) => s(o)), this.transition(v).attr("x1", -1).attr("x2", (o) => o.state.rect.width + 2).attr("stroke-width", H), k.attr("cx", (o) => o.state.rect.width).attr("cy", (o) => o.state.rect.height).attr("stroke", (o) => s(o)).attr(
|
|
653
653
|
"fill",
|
|
654
654
|
(o) => {
|
|
655
655
|
var m;
|
|
656
656
|
return (m = o.payload) != null && m.fold && o.children ? s(o) : "var(--markmap-circle-open-bg)";
|
|
657
657
|
}
|
|
658
|
-
), this.transition(k).attr("r", 6), this.transition(A).style("opacity", 0),
|
|
658
|
+
), this.transition(k).attr("r", 6), this.transition(A).style("opacity", 0), D.attr("width", (o) => Math.max(0, o.state.rect.width - r * 2)).attr("height", (o) => o.state.rect.height), this.transition(D).style("opacity", 1);
|
|
659
659
|
const S = [
|
|
660
660
|
a.x + a.width,
|
|
661
|
-
a.y + a.height
|
|
661
|
+
a.y + a.height
|
|
662
662
|
];
|
|
663
|
-
this.transition(q).attr("d", M({ source: S, target: S })).remove(),
|
|
663
|
+
this.transition(q).attr("d", M({ source: S, target: S })).remove(), F.attr(
|
|
664
664
|
"d",
|
|
665
665
|
M({ source: S, target: S })
|
|
666
666
|
), this.transition(J).attr("stroke", (o) => s(o.target)).attr("stroke-width", (o) => H(o.target)).attr("d", (o) => {
|
|
667
667
|
const m = o.source, y = o.target, Q = [
|
|
668
668
|
m.state.rect.x + m.state.rect.width,
|
|
669
|
-
m.state.rect.y + m.state.rect.height
|
|
669
|
+
m.state.rect.y + m.state.rect.height
|
|
670
670
|
], tt = [
|
|
671
671
|
y.state.rect.x,
|
|
672
|
-
y.state.rect.y + y.state.rect.height
|
|
672
|
+
y.state.rect.y + y.state.rect.height
|
|
673
673
|
];
|
|
674
674
|
return M({ source: Q, target: tt });
|
|
675
|
-
}),
|
|
675
|
+
}), n && this.fit();
|
|
676
676
|
}
|
|
677
677
|
transition(t) {
|
|
678
|
-
const { duration:
|
|
679
|
-
return t.transition().duration(
|
|
678
|
+
const { duration: r } = this.options;
|
|
679
|
+
return t.transition().duration(r);
|
|
680
680
|
}
|
|
681
681
|
/**
|
|
682
682
|
* Fit the content to the viewport.
|
|
683
683
|
*/
|
|
684
684
|
async fit(t = this.options.maxInitialScale) {
|
|
685
|
-
const
|
|
686
|
-
|
|
685
|
+
const r = this.svg.node(), { width: n, height: s } = r.getBoundingClientRect(), { fitRatio: l } = this.options, { x1: c, y1: i, x2: a, y2: d } = this.state.rect, h = a - c, p = d - i, u = Math.min(
|
|
686
|
+
n / h * l,
|
|
687
687
|
s / p * l,
|
|
688
688
|
t
|
|
689
689
|
), g = ct.translate(
|
|
690
|
-
(
|
|
690
|
+
(n - h * u) / 2 - c * u,
|
|
691
691
|
(s - p * u) / 2 - i * u
|
|
692
692
|
).scale(u);
|
|
693
|
-
return this.transition(this.svg).call(this.zoom.transform, g).end().catch(
|
|
693
|
+
return this.transition(this.svg).call(this.zoom.transform, g).end().catch(E);
|
|
694
694
|
}
|
|
695
695
|
findElement(t) {
|
|
696
|
-
let
|
|
696
|
+
let r;
|
|
697
697
|
return this.g.selectAll(b("g")).each(function(s) {
|
|
698
|
-
s === t && (
|
|
698
|
+
s === t && (r = {
|
|
699
699
|
data: s,
|
|
700
700
|
g: this
|
|
701
701
|
});
|
|
702
|
-
}),
|
|
702
|
+
}), r;
|
|
703
703
|
}
|
|
704
704
|
/**
|
|
705
705
|
* Pan the content to make the provided node visible in the viewport.
|
|
706
706
|
*/
|
|
707
|
-
async
|
|
707
|
+
async ensureVisible(t, r) {
|
|
708
708
|
var v;
|
|
709
|
-
const
|
|
710
|
-
if (!
|
|
711
|
-
const s = this.svg.node(), l = s.getBoundingClientRect(), c =
|
|
712
|
-
|
|
713
|
-
|
|
709
|
+
const n = (v = this.findElement(t)) == null ? void 0 : v.data;
|
|
710
|
+
if (!n) return;
|
|
711
|
+
const s = this.svg.node(), l = s.getBoundingClientRect(), c = C(s), [i, a] = [
|
|
712
|
+
n.state.rect.x,
|
|
713
|
+
n.state.rect.x + n.state.rect.width + 2
|
|
714
714
|
].map((k) => k * c.k + c.x), [d, h] = [
|
|
715
|
-
|
|
716
|
-
|
|
715
|
+
n.state.rect.y,
|
|
716
|
+
n.state.rect.y + n.state.rect.height
|
|
717
717
|
].map((k) => k * c.k + c.y), p = {
|
|
718
718
|
left: 0,
|
|
719
719
|
right: 0,
|
|
720
720
|
top: 0,
|
|
721
721
|
bottom: 0,
|
|
722
|
-
...
|
|
723
|
-
}, u = [p.left - i, l.width - p.right - a], g = [p.top - d, l.height - p.bottom - h], f = u[0] * u[1] > 0 ?
|
|
722
|
+
...r
|
|
723
|
+
}, u = [p.left - i, l.width - p.right - a], g = [p.top - d, l.height - p.bottom - h], f = u[0] * u[1] > 0 ? N(u, Math.abs) / c.k : 0, x = g[0] * g[1] > 0 ? N(g, Math.abs) / c.k : 0;
|
|
724
724
|
if (f || x) {
|
|
725
725
|
const k = c.translate(f, x);
|
|
726
|
-
return this.transition(this.svg).call(this.zoom.transform, k).end().catch(
|
|
726
|
+
return this.transition(this.svg).call(this.zoom.transform, k).end().catch(E);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
async centerNode(t, r) {
|
|
730
|
+
var f;
|
|
731
|
+
const n = (f = this.findElement(t)) == null ? void 0 : f.data;
|
|
732
|
+
if (!n) return;
|
|
733
|
+
const s = this.svg.node(), l = s.getBoundingClientRect(), c = C(s), i = (n.state.rect.x + n.state.rect.width / 2) * c.k + c.x, a = (n.state.rect.y + n.state.rect.height / 2) * c.k + c.y, d = {
|
|
734
|
+
left: 0,
|
|
735
|
+
right: 0,
|
|
736
|
+
top: 0,
|
|
737
|
+
bottom: 0,
|
|
738
|
+
...r
|
|
739
|
+
}, h = (d.left + l.width - d.right) / 2, p = (d.top + l.height - d.bottom) / 2, u = (h - i) / c.k, g = (p - a) / c.k;
|
|
740
|
+
if (u || g) {
|
|
741
|
+
const x = c.translate(u, g);
|
|
742
|
+
return this.transition(this.svg).call(this.zoom.transform, x).end().catch(E);
|
|
727
743
|
}
|
|
728
744
|
}
|
|
729
745
|
/**
|
|
730
746
|
* Scale content with it pinned at the center of the viewport.
|
|
731
747
|
*/
|
|
732
748
|
async rescale(t) {
|
|
733
|
-
const
|
|
749
|
+
const r = this.svg.node(), { width: n, height: s } = r.getBoundingClientRect(), l = n / 2, c = s / 2, i = C(r), a = i.translate(
|
|
734
750
|
(l - i.x) * (1 - t) / i.k,
|
|
735
751
|
(c - i.y) * (1 - t) / i.k
|
|
736
752
|
).scale(t);
|
|
737
|
-
return this.transition(this.svg).call(this.zoom.transform, a).end().catch(
|
|
753
|
+
return this.transition(this.svg).call(this.zoom.transform, a).end().catch(E);
|
|
738
754
|
}
|
|
739
755
|
destroy() {
|
|
740
756
|
this.svg.on(".zoom", null), this.svg.html(null), this.revokers.forEach((t) => {
|
|
741
757
|
t();
|
|
742
758
|
});
|
|
743
759
|
}
|
|
744
|
-
static create(t,
|
|
745
|
-
const s = new Y(t,
|
|
746
|
-
return
|
|
760
|
+
static create(t, r, n = null) {
|
|
761
|
+
const s = new Y(t, r);
|
|
762
|
+
return n && s.setData(n).then(() => {
|
|
747
763
|
s.fit();
|
|
748
764
|
}), s;
|
|
749
765
|
}
|
package/dist/view.d.ts
CHANGED
|
@@ -39,7 +39,10 @@ export declare class Markmap {
|
|
|
39
39
|
/**
|
|
40
40
|
* Pan the content to make the provided node visible in the viewport.
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
ensureVisible(node: INode, padding?: Partial<IPadding>): Promise<void>;
|
|
43
|
+
/** @deprecated Use `ensureVisible` instead */
|
|
44
|
+
ensureView: (node: INode, padding?: Partial<IPadding>) => Promise<void>;
|
|
45
|
+
centerNode(node: INode, padding?: Partial<IPadding>): Promise<void>;
|
|
43
46
|
/**
|
|
44
47
|
* Scale content with it pinned at the center of the viewport.
|
|
45
48
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-view",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "View markmaps in browser",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"markmap-common": "*"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "75261f82190df5b126faf6f6dc82adeb1c3a2cc2"
|
|
55
55
|
}
|