markmap-view 0.18.3 → 0.18.4-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 +140 -367
- package/dist/index.d.ts +0 -1
- package/dist/index.js +356 -344
- package/dist/types.d.ts +2 -3
- package/dist/util.d.ts +1 -1
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -1,342 +1,5 @@
|
|
|
1
1
|
(function(exports, d32) {
|
|
2
2
|
"use strict";
|
|
3
|
-
class Hook {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.listeners = [];
|
|
6
|
-
}
|
|
7
|
-
tap(fn) {
|
|
8
|
-
this.listeners.push(fn);
|
|
9
|
-
return () => this.revoke(fn);
|
|
10
|
-
}
|
|
11
|
-
revoke(fn) {
|
|
12
|
-
const i = this.listeners.indexOf(fn);
|
|
13
|
-
if (i >= 0) this.listeners.splice(i, 1);
|
|
14
|
-
}
|
|
15
|
-
revokeAll() {
|
|
16
|
-
this.listeners.splice(0);
|
|
17
|
-
}
|
|
18
|
-
call(...args) {
|
|
19
|
-
for (const fn of this.listeners) {
|
|
20
|
-
fn(...args);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const uniqId = Math.random().toString(36).slice(2, 8);
|
|
25
|
-
let globalIndex = 0;
|
|
26
|
-
function getId() {
|
|
27
|
-
globalIndex += 1;
|
|
28
|
-
return `mm-${uniqId}-${globalIndex}`;
|
|
29
|
-
}
|
|
30
|
-
function noop() {
|
|
31
|
-
}
|
|
32
|
-
function walkTree(tree, callback) {
|
|
33
|
-
const walk = (item, parent) => callback(
|
|
34
|
-
item,
|
|
35
|
-
() => {
|
|
36
|
-
var _a;
|
|
37
|
-
return (_a = item.children) == null ? void 0 : _a.map((child) => walk(child, item));
|
|
38
|
-
},
|
|
39
|
-
parent
|
|
40
|
-
);
|
|
41
|
-
return walk(tree);
|
|
42
|
-
}
|
|
43
|
-
function addClass(className, ...rest) {
|
|
44
|
-
const classList = (className || "").split(" ").filter(Boolean);
|
|
45
|
-
rest.forEach((item) => {
|
|
46
|
-
if (item && classList.indexOf(item) < 0) classList.push(item);
|
|
47
|
-
});
|
|
48
|
-
return classList.join(" ");
|
|
49
|
-
}
|
|
50
|
-
function childSelector(filter) {
|
|
51
|
-
if (typeof filter === "string") {
|
|
52
|
-
const tagName = filter;
|
|
53
|
-
filter = (el) => el.tagName === tagName;
|
|
54
|
-
}
|
|
55
|
-
const filterFn = filter;
|
|
56
|
-
return function selector() {
|
|
57
|
-
let nodes = Array.from(this.childNodes);
|
|
58
|
-
if (filterFn) nodes = nodes.filter((node) => filterFn(node));
|
|
59
|
-
return nodes;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function defer() {
|
|
63
|
-
const obj = {};
|
|
64
|
-
obj.promise = new Promise((resolve, reject) => {
|
|
65
|
-
obj.resolve = resolve;
|
|
66
|
-
obj.reject = reject;
|
|
67
|
-
});
|
|
68
|
-
return obj;
|
|
69
|
-
}
|
|
70
|
-
function memoize(fn) {
|
|
71
|
-
const cache = {};
|
|
72
|
-
return function memoized(...args) {
|
|
73
|
-
const key = `${args[0]}`;
|
|
74
|
-
let data = cache[key];
|
|
75
|
-
if (!data) {
|
|
76
|
-
data = {
|
|
77
|
-
value: fn(...args)
|
|
78
|
-
};
|
|
79
|
-
cache[key] = data;
|
|
80
|
-
}
|
|
81
|
-
return data.value;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function debounce(fn, time) {
|
|
85
|
-
const state = {
|
|
86
|
-
timer: 0
|
|
87
|
-
};
|
|
88
|
-
function reset() {
|
|
89
|
-
if (state.timer) {
|
|
90
|
-
window.clearTimeout(state.timer);
|
|
91
|
-
state.timer = 0;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function run() {
|
|
95
|
-
reset();
|
|
96
|
-
if (state.args) state.result = fn(...state.args);
|
|
97
|
-
}
|
|
98
|
-
return function debounced(...args) {
|
|
99
|
-
reset();
|
|
100
|
-
state.args = args;
|
|
101
|
-
state.timer = window.setTimeout(run, time);
|
|
102
|
-
return state.result;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
106
|
-
const VTYPE_ELEMENT = 1;
|
|
107
|
-
const VTYPE_FUNCTION = 2;
|
|
108
|
-
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
109
|
-
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
110
|
-
const NS_ATTRS = {
|
|
111
|
-
show: XLINK_NS,
|
|
112
|
-
actuate: XLINK_NS,
|
|
113
|
-
href: XLINK_NS
|
|
114
|
-
};
|
|
115
|
-
const isLeaf = (c) => typeof c === "string" || typeof c === "number";
|
|
116
|
-
const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
117
|
-
const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
118
|
-
function h(type, props, ...children) {
|
|
119
|
-
props = Object.assign({}, props, {
|
|
120
|
-
children: children.length === 1 ? children[0] : children
|
|
121
|
-
});
|
|
122
|
-
return jsx(type, props);
|
|
123
|
-
}
|
|
124
|
-
function jsx(type, props) {
|
|
125
|
-
let vtype;
|
|
126
|
-
if (typeof type === "string") vtype = VTYPE_ELEMENT;
|
|
127
|
-
else if (typeof type === "function") vtype = VTYPE_FUNCTION;
|
|
128
|
-
else throw new Error("Invalid VNode type");
|
|
129
|
-
return {
|
|
130
|
-
vtype,
|
|
131
|
-
type,
|
|
132
|
-
props
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function Fragment(props) {
|
|
136
|
-
return props.children;
|
|
137
|
-
}
|
|
138
|
-
const DEFAULT_ENV = {
|
|
139
|
-
isSvg: false
|
|
140
|
-
};
|
|
141
|
-
function insertDom(parent, nodes) {
|
|
142
|
-
if (!Array.isArray(nodes)) nodes = [nodes];
|
|
143
|
-
nodes = nodes.filter(Boolean);
|
|
144
|
-
if (nodes.length) parent.append(...nodes);
|
|
145
|
-
}
|
|
146
|
-
function mountAttributes(domElement, props, env) {
|
|
147
|
-
for (const key in props) {
|
|
148
|
-
if (key === "key" || key === "children" || key === "ref") continue;
|
|
149
|
-
if (key === "dangerouslySetInnerHTML") {
|
|
150
|
-
domElement.innerHTML = props[key].__html;
|
|
151
|
-
} else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
|
|
152
|
-
const value = props[key];
|
|
153
|
-
if (value != null) domElement[key] = value;
|
|
154
|
-
} else if (key.startsWith("on")) {
|
|
155
|
-
domElement[key.toLowerCase()] = props[key];
|
|
156
|
-
} else {
|
|
157
|
-
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const attrMap = {
|
|
162
|
-
className: "class",
|
|
163
|
-
labelFor: "for"
|
|
164
|
-
};
|
|
165
|
-
function setDOMAttribute(el, attr, value, isSVG) {
|
|
166
|
-
attr = attrMap[attr] || attr;
|
|
167
|
-
if (value === true) {
|
|
168
|
-
el.setAttribute(attr, "");
|
|
169
|
-
} else if (value === false) {
|
|
170
|
-
el.removeAttribute(attr);
|
|
171
|
-
} else {
|
|
172
|
-
const namespace = isSVG ? NS_ATTRS[attr] : void 0;
|
|
173
|
-
if (namespace !== void 0) {
|
|
174
|
-
el.setAttributeNS(namespace, attr, value);
|
|
175
|
-
} else {
|
|
176
|
-
el.setAttribute(attr, value);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function flatten(arr) {
|
|
181
|
-
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
182
|
-
}
|
|
183
|
-
function mountChildren(children, env) {
|
|
184
|
-
return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
|
|
185
|
-
}
|
|
186
|
-
function mount(vnode, env = DEFAULT_ENV) {
|
|
187
|
-
if (vnode == null || typeof vnode === "boolean") {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
if (vnode instanceof Node) {
|
|
191
|
-
return vnode;
|
|
192
|
-
}
|
|
193
|
-
if (isRenderFunction(vnode)) {
|
|
194
|
-
const {
|
|
195
|
-
type,
|
|
196
|
-
props
|
|
197
|
-
} = vnode;
|
|
198
|
-
if (type === Fragment) {
|
|
199
|
-
const node = document.createDocumentFragment();
|
|
200
|
-
if (props.children) {
|
|
201
|
-
const children = mountChildren(props.children, env);
|
|
202
|
-
insertDom(node, children);
|
|
203
|
-
}
|
|
204
|
-
return node;
|
|
205
|
-
}
|
|
206
|
-
const childVNode = type(props);
|
|
207
|
-
return mount(childVNode, env);
|
|
208
|
-
}
|
|
209
|
-
if (isLeaf(vnode)) {
|
|
210
|
-
return document.createTextNode(`${vnode}`);
|
|
211
|
-
}
|
|
212
|
-
if (isElement(vnode)) {
|
|
213
|
-
let node;
|
|
214
|
-
const {
|
|
215
|
-
type,
|
|
216
|
-
props
|
|
217
|
-
} = vnode;
|
|
218
|
-
if (!env.isSvg && type === "svg") {
|
|
219
|
-
env = Object.assign({}, env, {
|
|
220
|
-
isSvg: true
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (!env.isSvg) {
|
|
224
|
-
node = document.createElement(type);
|
|
225
|
-
} else {
|
|
226
|
-
node = document.createElementNS(SVG_NS, type);
|
|
227
|
-
}
|
|
228
|
-
mountAttributes(node, props, env);
|
|
229
|
-
if (props.children) {
|
|
230
|
-
let childEnv = env;
|
|
231
|
-
if (env.isSvg && type === "foreignObject") {
|
|
232
|
-
childEnv = Object.assign({}, childEnv, {
|
|
233
|
-
isSvg: false
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
const children = mountChildren(props.children, childEnv);
|
|
237
|
-
if (children != null) insertDom(node, children);
|
|
238
|
-
}
|
|
239
|
-
const {
|
|
240
|
-
ref
|
|
241
|
-
} = props;
|
|
242
|
-
if (typeof ref === "function") ref(node);
|
|
243
|
-
return node;
|
|
244
|
-
}
|
|
245
|
-
throw new Error("mount: Invalid Vnode!");
|
|
246
|
-
}
|
|
247
|
-
function mountDom(vnode) {
|
|
248
|
-
return mount(vnode);
|
|
249
|
-
}
|
|
250
|
-
function hm(...args) {
|
|
251
|
-
return mountDom(h(...args));
|
|
252
|
-
}
|
|
253
|
-
const memoizedPreloadJS = memoize((url) => {
|
|
254
|
-
document.head.append(
|
|
255
|
-
hm("link", {
|
|
256
|
-
rel: "preload",
|
|
257
|
-
as: "script",
|
|
258
|
-
href: url
|
|
259
|
-
})
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
const jsCache = {};
|
|
263
|
-
const cssCache = {};
|
|
264
|
-
async function loadJSItem(item, context) {
|
|
265
|
-
var _a;
|
|
266
|
-
const src = item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src) || "";
|
|
267
|
-
item.loaded || (item.loaded = jsCache[src]);
|
|
268
|
-
if (!item.loaded) {
|
|
269
|
-
const deferred = defer();
|
|
270
|
-
item.loaded = deferred.promise;
|
|
271
|
-
if (item.type === "script") {
|
|
272
|
-
document.head.append(
|
|
273
|
-
hm("script", {
|
|
274
|
-
...item.data,
|
|
275
|
-
onLoad: () => deferred.resolve(),
|
|
276
|
-
onError: deferred.reject
|
|
277
|
-
})
|
|
278
|
-
);
|
|
279
|
-
if (!src) {
|
|
280
|
-
deferred.resolve();
|
|
281
|
-
} else {
|
|
282
|
-
jsCache[src] = item.loaded;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (item.type === "iife") {
|
|
286
|
-
const { fn, getParams } = item.data;
|
|
287
|
-
fn(...(getParams == null ? void 0 : getParams(context)) || []);
|
|
288
|
-
deferred.resolve();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
await item.loaded;
|
|
292
|
-
}
|
|
293
|
-
async function loadCSSItem(item) {
|
|
294
|
-
const url = item.type === "stylesheet" && item.data.href || "";
|
|
295
|
-
item.loaded || (item.loaded = cssCache[url]);
|
|
296
|
-
if (!item.loaded) {
|
|
297
|
-
const deferred = defer();
|
|
298
|
-
item.loaded = deferred.promise;
|
|
299
|
-
if (url) cssCache[url] = item.loaded;
|
|
300
|
-
if (item.type === "style") {
|
|
301
|
-
document.head.append(
|
|
302
|
-
hm("style", {
|
|
303
|
-
textContent: item.data
|
|
304
|
-
})
|
|
305
|
-
);
|
|
306
|
-
deferred.resolve();
|
|
307
|
-
} else if (url) {
|
|
308
|
-
document.head.append(
|
|
309
|
-
hm("link", {
|
|
310
|
-
rel: "stylesheet",
|
|
311
|
-
...item.data
|
|
312
|
-
})
|
|
313
|
-
);
|
|
314
|
-
fetch(url).then((res) => {
|
|
315
|
-
if (res.ok) return res.text();
|
|
316
|
-
throw res;
|
|
317
|
-
}).then(() => deferred.resolve(), deferred.reject);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
await item.loaded;
|
|
321
|
-
}
|
|
322
|
-
async function loadJS(items, context) {
|
|
323
|
-
items.forEach((item) => {
|
|
324
|
-
var _a;
|
|
325
|
-
if (item.type === "script" && ((_a = item.data) == null ? void 0 : _a.src)) {
|
|
326
|
-
memoizedPreloadJS(item.data.src);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
context = {
|
|
330
|
-
getMarkmap: () => window.markmap,
|
|
331
|
-
...context
|
|
332
|
-
};
|
|
333
|
-
for (const item of items) {
|
|
334
|
-
await loadJSItem(item, context);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
async function loadCSS(items) {
|
|
338
|
-
await Promise.all(items.map((item) => loadCSSItem(item)));
|
|
339
|
-
}
|
|
340
3
|
const isMacintosh = typeof navigator !== "undefined" && navigator.userAgent.includes("Macintosh");
|
|
341
4
|
const defaultColorFn = d32.scaleOrdinal(d32.schemeCategory10);
|
|
342
5
|
const defaultOptions = {
|
|
@@ -530,14 +193,14 @@
|
|
|
530
193
|
return links;
|
|
531
194
|
}
|
|
532
195
|
function hierarchy(data, children) {
|
|
533
|
-
var root = new Node
|
|
196
|
+
var root = new Node(data), valued = +data.value && (root.value = data.value), node, nodes = [root], child, childs, i, n;
|
|
534
197
|
if (children == null) children = defaultChildren;
|
|
535
198
|
while (node = nodes.pop()) {
|
|
536
199
|
if (valued) node.value = +node.data.value;
|
|
537
200
|
if ((childs = children(node.data)) && (n = childs.length)) {
|
|
538
201
|
node.children = new Array(n);
|
|
539
202
|
for (i = n - 1; i >= 0; --i) {
|
|
540
|
-
nodes.push(child = node.children[i] = new Node
|
|
203
|
+
nodes.push(child = node.children[i] = new Node(childs[i]));
|
|
541
204
|
child.parent = node;
|
|
542
205
|
child.depth = node.depth + 1;
|
|
543
206
|
}
|
|
@@ -560,13 +223,13 @@
|
|
|
560
223
|
node.height = height;
|
|
561
224
|
while ((node = node.parent) && node.height < ++height);
|
|
562
225
|
}
|
|
563
|
-
function Node
|
|
226
|
+
function Node(data) {
|
|
564
227
|
this.data = data;
|
|
565
228
|
this.depth = this.height = 0;
|
|
566
229
|
this.parent = null;
|
|
567
230
|
}
|
|
568
|
-
Node
|
|
569
|
-
constructor: Node
|
|
231
|
+
Node.prototype = hierarchy.prototype = {
|
|
232
|
+
constructor: Node,
|
|
570
233
|
count: node_count,
|
|
571
234
|
each: node_each,
|
|
572
235
|
eachAfter: node_eachAfter,
|
|
@@ -942,6 +605,86 @@
|
|
|
942
605
|
next: lastLows
|
|
943
606
|
};
|
|
944
607
|
};
|
|
608
|
+
class Hook {
|
|
609
|
+
constructor() {
|
|
610
|
+
this.listeners = [];
|
|
611
|
+
}
|
|
612
|
+
tap(fn) {
|
|
613
|
+
this.listeners.push(fn);
|
|
614
|
+
return () => this.revoke(fn);
|
|
615
|
+
}
|
|
616
|
+
revoke(fn) {
|
|
617
|
+
const i = this.listeners.indexOf(fn);
|
|
618
|
+
if (i >= 0) this.listeners.splice(i, 1);
|
|
619
|
+
}
|
|
620
|
+
revokeAll() {
|
|
621
|
+
this.listeners.splice(0);
|
|
622
|
+
}
|
|
623
|
+
call(...args) {
|
|
624
|
+
for (const fn of this.listeners) {
|
|
625
|
+
fn(...args);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const uniqId = Math.random().toString(36).slice(2, 8);
|
|
630
|
+
let globalIndex = 0;
|
|
631
|
+
function getId() {
|
|
632
|
+
globalIndex += 1;
|
|
633
|
+
return `mm-${uniqId}-${globalIndex}`;
|
|
634
|
+
}
|
|
635
|
+
function noop() {
|
|
636
|
+
}
|
|
637
|
+
function walkTree(tree, callback) {
|
|
638
|
+
const walk = (item, parent) => callback(
|
|
639
|
+
item,
|
|
640
|
+
() => {
|
|
641
|
+
var _a;
|
|
642
|
+
return (_a = item.children) == null ? void 0 : _a.map((child) => walk(child, item));
|
|
643
|
+
},
|
|
644
|
+
parent
|
|
645
|
+
);
|
|
646
|
+
return walk(tree);
|
|
647
|
+
}
|
|
648
|
+
function addClass(className, ...rest) {
|
|
649
|
+
const classList = (className || "").split(" ").filter(Boolean);
|
|
650
|
+
rest.forEach((item) => {
|
|
651
|
+
if (item && classList.indexOf(item) < 0) classList.push(item);
|
|
652
|
+
});
|
|
653
|
+
return classList.join(" ");
|
|
654
|
+
}
|
|
655
|
+
function childSelector(filter) {
|
|
656
|
+
if (typeof filter === "string") {
|
|
657
|
+
const tagName = filter;
|
|
658
|
+
filter = (el) => el.tagName === tagName;
|
|
659
|
+
}
|
|
660
|
+
const filterFn = filter;
|
|
661
|
+
return function selector() {
|
|
662
|
+
let nodes = Array.from(this.childNodes);
|
|
663
|
+
if (filterFn) nodes = nodes.filter((node) => filterFn(node));
|
|
664
|
+
return nodes;
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function debounce(fn, time) {
|
|
668
|
+
const state = {
|
|
669
|
+
timer: 0
|
|
670
|
+
};
|
|
671
|
+
function reset() {
|
|
672
|
+
if (state.timer) {
|
|
673
|
+
window.clearTimeout(state.timer);
|
|
674
|
+
state.timer = 0;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function run() {
|
|
678
|
+
reset();
|
|
679
|
+
if (state.args) state.result = fn(...state.args);
|
|
680
|
+
}
|
|
681
|
+
return function debounced(...args) {
|
|
682
|
+
reset();
|
|
683
|
+
state.args = args;
|
|
684
|
+
state.timer = window.setTimeout(run, time);
|
|
685
|
+
return state.result;
|
|
686
|
+
};
|
|
687
|
+
}
|
|
945
688
|
const css = ".markmap {\n --markmap-max-width: 9999px;\n --markmap-a-color: #0097e6;\n --markmap-a-hover-color: #00a8ff;\n --markmap-code-bg: #f0f0f0;\n --markmap-code-color: #555;\n --markmap-highlight-bg: #ffeaa7;\n --markmap-table-border: 1px solid currentColor;\n --markmap-font: 300 16px/20px sans-serif;\n --markmap-circle-open-bg: #fff;\n --markmap-text-color: #333;\n\n font: var(--markmap-font);\n color: var(--markmap-text-color);\n}\n\n .markmap-link {\n fill: none;\n }\n\n .markmap-node > circle {\n cursor: pointer;\n }\n\n .markmap-foreign {\n display: inline-block;\n }\n\n .markmap-foreign p {\n margin: 0;\n }\n\n .markmap-foreign a {\n color: var(--markmap-a-color);\n }\n\n .markmap-foreign a:hover {\n color: var(--markmap-a-hover-color);\n }\n\n .markmap-foreign code {\n padding: 0.25em;\n font-size: calc(1em - 2px);\n color: var(--markmap-code-color);\n background-color: var(--markmap-code-bg);\n border-radius: 2px;\n }\n\n .markmap-foreign pre {\n margin: 0;\n }\n\n .markmap-foreign pre > code {\n display: block;\n }\n\n .markmap-foreign del {\n text-decoration: line-through;\n }\n\n .markmap-foreign em {\n font-style: italic;\n }\n\n .markmap-foreign strong {\n font-weight: bold;\n }\n\n .markmap-foreign mark {\n background: var(--markmap-highlight-bg);\n }\n\n .markmap-foreign table,\n .markmap-foreign th,\n .markmap-foreign td {\n border-collapse: collapse;\n border: var(--markmap-table-border);\n }\n\n .markmap-foreign img {\n display: inline-block;\n }\n\n .markmap-foreign svg {\n fill: currentColor;\n }\n\n .markmap-foreign > div {\n width: var(--markmap-max-width);\n text-align: left;\n }\n\n .markmap-foreign > div > div {\n display: inline-block;\n }\n\n.markmap-dark .markmap {\n --markmap-code-bg: #1a1b26;\n --markmap-code-color: #ddd;\n --markmap-circle-open-bg: #444;\n --markmap-text-color: #eee;\n}\n";
|
|
946
689
|
const globalCSS = css;
|
|
947
690
|
const linkShape = d32.linkHorizontal();
|
|
@@ -1001,7 +744,8 @@
|
|
|
1001
744
|
this.revokers.push(
|
|
1002
745
|
refreshHook.tap(() => {
|
|
1003
746
|
this.setData();
|
|
1004
|
-
})
|
|
747
|
+
}),
|
|
748
|
+
() => this.observer.disconnect()
|
|
1005
749
|
);
|
|
1006
750
|
}
|
|
1007
751
|
getStyleContent() {
|
|
@@ -1144,18 +888,43 @@
|
|
|
1144
888
|
}
|
|
1145
889
|
async renderData(originData) {
|
|
1146
890
|
const { paddingX, autoFit, color, maxWidth } = this.options;
|
|
1147
|
-
|
|
891
|
+
const rootNode = this.state.data;
|
|
892
|
+
if (!rootNode) return;
|
|
893
|
+
const nodeMap = {};
|
|
894
|
+
const parentMap = {};
|
|
1148
895
|
const nodes = [];
|
|
1149
|
-
walkTree(
|
|
896
|
+
walkTree(rootNode, (item, next, parent) => {
|
|
1150
897
|
var _a;
|
|
1151
898
|
if (!((_a = item.payload) == null ? void 0 : _a.fold)) next();
|
|
899
|
+
nodeMap[item.state.id] = item;
|
|
900
|
+
if (parent) parentMap[item.state.id] = parent.state.id;
|
|
1152
901
|
nodes.push(item);
|
|
1153
902
|
});
|
|
1154
|
-
const
|
|
1155
|
-
const
|
|
1156
|
-
const
|
|
1157
|
-
|
|
1158
|
-
|
|
903
|
+
const originMap = {};
|
|
904
|
+
const sourceRectMap = {};
|
|
905
|
+
const setOriginNode = (originNode) => {
|
|
906
|
+
if (!originNode || originMap[originNode.state.id]) return;
|
|
907
|
+
walkTree(originNode, (item, next) => {
|
|
908
|
+
originMap[item.state.id] = originNode.state.id;
|
|
909
|
+
next();
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
const getOriginSourceRect = (node) => {
|
|
913
|
+
const rect = sourceRectMap[originMap[node.state.id]];
|
|
914
|
+
return rect || rootNode.state.rect;
|
|
915
|
+
};
|
|
916
|
+
const getOriginTargetRect = (node) => (nodeMap[originMap[node.state.id]] || rootNode).state.rect;
|
|
917
|
+
sourceRectMap[rootNode.state.id] = rootNode.state.rect;
|
|
918
|
+
if (originData) setOriginNode(originData);
|
|
919
|
+
const mmG = this.g.selectAll(childSelector("g")).each((d) => {
|
|
920
|
+
sourceRectMap[d.state.id] = d.state.rect;
|
|
921
|
+
}).data(nodes, (d) => d.state.key);
|
|
922
|
+
const mmGEnter = mmG.enter().append("g").attr("data-depth", (d) => d.state.depth).attr("data-path", (d) => d.state.path).each((d) => {
|
|
923
|
+
setOriginNode(nodeMap[parentMap[d.state.id]]);
|
|
924
|
+
});
|
|
925
|
+
const mmGExit = mmG.exit().each((d) => {
|
|
926
|
+
setOriginNode(nodeMap[parentMap[d.state.id]]);
|
|
927
|
+
});
|
|
1159
928
|
const mmGMerge = mmG.merge(mmGEnter).attr(
|
|
1160
929
|
"class",
|
|
1161
930
|
(d) => {
|
|
@@ -1213,11 +982,14 @@
|
|
|
1213
982
|
);
|
|
1214
983
|
const mmPath = this.g.selectAll(childSelector("path")).data(links, (d) => d.target.state.key);
|
|
1215
984
|
const mmPathExit = mmPath.exit();
|
|
1216
|
-
const
|
|
1217
|
-
originRect
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
985
|
+
const mmPathEnter = mmPath.enter().insert("path", "g").attr("class", "markmap-link").attr("data-depth", (d) => d.target.state.depth).attr("data-path", (d) => d.target.state.path).attr("d", (d) => {
|
|
986
|
+
const originRect = getOriginSourceRect(d.target);
|
|
987
|
+
const pathOrigin = [
|
|
988
|
+
originRect.x + originRect.width,
|
|
989
|
+
originRect.y + originRect.height
|
|
990
|
+
];
|
|
991
|
+
return linkShape({ source: pathOrigin, target: pathOrigin });
|
|
992
|
+
}).attr("stroke-width", 0);
|
|
1221
993
|
const mmPathMerge = mmPathEnter.merge(mmPath);
|
|
1222
994
|
this.svg.style(
|
|
1223
995
|
"--markmap-max-width",
|
|
@@ -1225,12 +997,12 @@
|
|
|
1225
997
|
);
|
|
1226
998
|
await new Promise(requestAnimationFrame);
|
|
1227
999
|
this._relayout();
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
);
|
|
1000
|
+
mmGEnter.attr("transform", (d) => {
|
|
1001
|
+
const originRect = getOriginSourceRect(d);
|
|
1002
|
+
return `translate(${originRect.x + originRect.width - d.state.rect.width},${originRect.y + originRect.height - d.state.rect.height})`;
|
|
1003
|
+
});
|
|
1233
1004
|
this.transition(mmGExit).attr("transform", (d) => {
|
|
1005
|
+
const targetRect = getOriginTargetRect(d);
|
|
1234
1006
|
const targetX = targetRect.x + targetRect.width - d.state.rect.width;
|
|
1235
1007
|
const targetY = targetRect.y + targetRect.height - d.state.rect.height;
|
|
1236
1008
|
return `translate(${targetX},${targetY})`;
|
|
@@ -1255,11 +1027,14 @@
|
|
|
1255
1027
|
this.transition(mmFoExit).style("opacity", 0);
|
|
1256
1028
|
mmFoMerge.attr("width", (d) => Math.max(0, d.state.rect.width - paddingX * 2)).attr("height", (d) => d.state.rect.height);
|
|
1257
1029
|
this.transition(mmFoMerge).style("opacity", 1);
|
|
1258
|
-
|
|
1259
|
-
targetRect
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1030
|
+
this.transition(mmPathExit).attr("d", (d) => {
|
|
1031
|
+
const targetRect = getOriginTargetRect(d.target);
|
|
1032
|
+
const pathTarget = [
|
|
1033
|
+
targetRect.x + targetRect.width,
|
|
1034
|
+
targetRect.y + targetRect.height
|
|
1035
|
+
];
|
|
1036
|
+
return linkShape({ source: pathTarget, target: pathTarget });
|
|
1037
|
+
}).attr("stroke-width", 0).remove();
|
|
1263
1038
|
this.transition(mmPathMerge).attr("stroke", (d) => color(d.target)).attr("stroke-width", (d) => linkWidth(d.target)).attr("d", (d) => {
|
|
1264
1039
|
const origSource = d.source;
|
|
1265
1040
|
const origTarget = d.target;
|
|
@@ -1409,8 +1184,6 @@
|
|
|
1409
1184
|
exports.deriveOptions = deriveOptions;
|
|
1410
1185
|
exports.globalCSS = globalCSS;
|
|
1411
1186
|
exports.isMacintosh = isMacintosh;
|
|
1412
|
-
exports.loadCSS = loadCSS;
|
|
1413
|
-
exports.loadJS = loadJS;
|
|
1414
1187
|
exports.refreshHook = refreshHook;
|
|
1415
1188
|
exports.simpleHash = simpleHash;
|
|
1416
1189
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/dist/index.d.ts
CHANGED