markmap-view 0.2.5 → 0.13.0-alpha.0
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/index.cjs.js +826 -586
- package/dist/index.esm.js +821 -584
- package/dist/index.js +827 -587
- package/dist/index.min.js +5 -4
- package/package.json +3 -4
- package/types/index.d.ts +3 -53
- package/types/types.d.ts +43 -38
- package/types/view.d.ts +57 -0
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! markmap-view v0.
|
|
1
|
+
/*! markmap-view v0.13.0-alpha.0 | MIT License */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var d3 = require('d3');
|
|
@@ -7,16 +7,44 @@ function _interopNamespace(e) {
|
|
|
7
7
|
if (e && e.__esModule) return e;
|
|
8
8
|
var n = Object.create(null);
|
|
9
9
|
if (e) {
|
|
10
|
-
|
|
10
|
+
for (var k in e) {
|
|
11
11
|
n[k] = e[k];
|
|
12
|
-
});
|
|
13
12
|
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
n["default"] = e;
|
|
15
15
|
return Object.freeze(n);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
var d3__namespace = /*#__PURE__*/_interopNamespace(d3);
|
|
19
19
|
|
|
20
|
+
/*! markmap-common v0.13.0-alpha.0 | MIT License */
|
|
21
|
+
class Hook {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.listeners = [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
tap(fn) {
|
|
27
|
+
this.listeners.push(fn);
|
|
28
|
+
return () => this.revoke(fn);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
revoke(fn) {
|
|
32
|
+
const i = this.listeners.indexOf(fn);
|
|
33
|
+
if (i >= 0) this.listeners.splice(i, 1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
revokeAll() {
|
|
37
|
+
this.listeners.splice(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
call(...args) {
|
|
41
|
+
for (const fn of this.listeners) {
|
|
42
|
+
fn(...args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
20
48
|
function _extends$1() {
|
|
21
49
|
_extends$1 = Object.assign || function (target) {
|
|
22
50
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -35,52 +63,186 @@ function _extends$1() {
|
|
|
35
63
|
return _extends$1.apply(this, arguments);
|
|
36
64
|
}
|
|
37
65
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
41
|
-
}
|
|
66
|
+
const uniqId = Math.random().toString(36).slice(2, 8);
|
|
67
|
+
let globalIndex = 0;
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
function getId() {
|
|
70
|
+
globalIndex += 1;
|
|
71
|
+
return `mm-${uniqId}-${globalIndex}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function noop() {// noop
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function walkTree(tree, callback, key = 'children') {
|
|
78
|
+
const walk = (item, parent) => callback(item, () => {
|
|
79
|
+
var _item$key;
|
|
80
|
+
|
|
81
|
+
(_item$key = item[key]) == null ? void 0 : _item$key.forEach(child => {
|
|
82
|
+
walk(child, item);
|
|
83
|
+
});
|
|
84
|
+
}, parent);
|
|
85
|
+
|
|
86
|
+
walk(tree);
|
|
44
87
|
}
|
|
45
88
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
89
|
+
function arrayFrom(arrayLike) {
|
|
90
|
+
if (Array.from) return Array.from(arrayLike);
|
|
91
|
+
const array = [];
|
|
92
|
+
|
|
93
|
+
for (let i = 0; i < arrayLike.length; i += 1) {
|
|
94
|
+
array.push(arrayLike[i]);
|
|
53
95
|
}
|
|
96
|
+
|
|
97
|
+
return array;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function addClass(className, ...rest) {
|
|
101
|
+
const classList = (className || '').split(' ').filter(Boolean);
|
|
102
|
+
rest.forEach(item => {
|
|
103
|
+
if (item && classList.indexOf(item) < 0) classList.push(item);
|
|
104
|
+
});
|
|
105
|
+
return classList.join(' ');
|
|
54
106
|
}
|
|
55
107
|
|
|
56
|
-
function
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
108
|
+
function childSelector(filter) {
|
|
109
|
+
if (typeof filter === 'string') {
|
|
110
|
+
const tagName = filter;
|
|
111
|
+
|
|
112
|
+
filter = el => el.tagName === tagName;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const filterFn = filter;
|
|
116
|
+
return function selector() {
|
|
117
|
+
let nodes = arrayFrom(this.childNodes);
|
|
118
|
+
if (filterFn) nodes = nodes.filter(node => filterFn(node));
|
|
119
|
+
return nodes;
|
|
120
|
+
};
|
|
60
121
|
}
|
|
61
122
|
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
123
|
+
function memoize(fn) {
|
|
124
|
+
const cache = {};
|
|
125
|
+
return function memoized(...args) {
|
|
126
|
+
const key = `${args[0]}`;
|
|
127
|
+
let data = cache[key];
|
|
128
|
+
|
|
129
|
+
if (!data) {
|
|
130
|
+
data = {
|
|
131
|
+
value: fn(...args)
|
|
132
|
+
};
|
|
133
|
+
cache[key] = data;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return data.value;
|
|
66
137
|
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function createElement(tagName, props, attrs) {
|
|
141
|
+
const el = document.createElement(tagName);
|
|
142
|
+
|
|
143
|
+
if (props) {
|
|
144
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
145
|
+
el[key] = value;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (attrs) {
|
|
150
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
151
|
+
el.setAttribute(key, value);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return el;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const memoizedPreloadJS = memoize(url => {
|
|
159
|
+
document.head.append(createElement('link', {
|
|
160
|
+
rel: 'preload',
|
|
161
|
+
as: 'script',
|
|
162
|
+
href: url
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
function loadJSItem(item, context) {
|
|
167
|
+
if (item.type === 'script') {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
var _item$data;
|
|
170
|
+
|
|
171
|
+
document.head.append(createElement('script', _extends$1({}, item.data, {
|
|
172
|
+
onload: resolve,
|
|
173
|
+
onerror: reject
|
|
174
|
+
}))); // Run inline script synchronously
|
|
67
175
|
|
|
68
|
-
|
|
176
|
+
if (!((_item$data = item.data) != null && _item$data.src)) resolve();
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (item.type === 'iife') {
|
|
181
|
+
const {
|
|
182
|
+
fn,
|
|
183
|
+
getParams
|
|
184
|
+
} = item.data;
|
|
185
|
+
fn(...((getParams == null ? void 0 : getParams(context)) || []));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function loadCSSItem(item) {
|
|
190
|
+
if (item.type === 'style') {
|
|
191
|
+
document.head.append(createElement('style', {
|
|
192
|
+
textContent: item.data
|
|
193
|
+
}));
|
|
194
|
+
} else if (item.type === 'stylesheet') {
|
|
195
|
+
document.head.append(createElement('link', _extends$1({
|
|
196
|
+
rel: 'stylesheet'
|
|
197
|
+
}, item.data)));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function loadJS(items, context) {
|
|
202
|
+
const needPreload = items.filter(item => {
|
|
203
|
+
var _item$data2;
|
|
204
|
+
|
|
205
|
+
return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
|
|
206
|
+
});
|
|
207
|
+
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
|
|
208
|
+
context = _extends$1({
|
|
209
|
+
getMarkmap: () => window.markmap
|
|
210
|
+
}, context);
|
|
211
|
+
|
|
212
|
+
for (const item of items) {
|
|
213
|
+
await loadJSItem(item, context);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function loadCSS(items) {
|
|
218
|
+
for (const item of items) {
|
|
219
|
+
loadCSSItem(item);
|
|
220
|
+
}
|
|
69
221
|
}
|
|
70
222
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
223
|
+
function _extends() {
|
|
224
|
+
_extends = Object.assign || function (target) {
|
|
225
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
226
|
+
var source = arguments[i];
|
|
227
|
+
|
|
228
|
+
for (var key in source) {
|
|
229
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
230
|
+
target[key] = source[key];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return target;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return _extends.apply(this, arguments);
|
|
75
239
|
}
|
|
76
240
|
|
|
77
241
|
function count(node) {
|
|
78
242
|
var sum = 0,
|
|
79
243
|
children = node.children,
|
|
80
244
|
i = children && children.length;
|
|
81
|
-
if (!i) sum = 1;else while (--i >= 0)
|
|
82
|
-
sum += children[i].value;
|
|
83
|
-
}
|
|
245
|
+
if (!i) sum = 1;else while (--i >= 0) sum += children[i].value;
|
|
84
246
|
node.value = sum;
|
|
85
247
|
}
|
|
86
248
|
|
|
@@ -154,9 +316,7 @@ function node_sum (value) {
|
|
|
154
316
|
children = node.children,
|
|
155
317
|
i = children && children.length;
|
|
156
318
|
|
|
157
|
-
while (--i >= 0)
|
|
158
|
-
sum += children[i].value;
|
|
159
|
-
}
|
|
319
|
+
while (--i >= 0) sum += children[i].value;
|
|
160
320
|
|
|
161
321
|
node.value = sum;
|
|
162
322
|
});
|
|
@@ -252,7 +412,7 @@ function node_links () {
|
|
|
252
412
|
}
|
|
253
413
|
|
|
254
414
|
function hierarchy(data, children) {
|
|
255
|
-
var root = new Node(data),
|
|
415
|
+
var root = new Node$1(data),
|
|
256
416
|
valued = +data.value && (root.value = data.value),
|
|
257
417
|
node,
|
|
258
418
|
nodes = [root],
|
|
@@ -269,7 +429,7 @@ function hierarchy(data, children) {
|
|
|
269
429
|
node.children = new Array(n);
|
|
270
430
|
|
|
271
431
|
for (i = n - 1; i >= 0; --i) {
|
|
272
|
-
nodes.push(child = node.children[i] = new Node(childs[i]));
|
|
432
|
+
nodes.push(child = node.children[i] = new Node$1(childs[i]));
|
|
273
433
|
child.parent = node;
|
|
274
434
|
child.depth = node.depth + 1;
|
|
275
435
|
}
|
|
@@ -294,17 +454,15 @@ function copyData(node) {
|
|
|
294
454
|
function computeHeight(node) {
|
|
295
455
|
var height = 0;
|
|
296
456
|
|
|
297
|
-
do
|
|
298
|
-
node.height = height;
|
|
299
|
-
} while ((node = node.parent) && node.height < ++height);
|
|
457
|
+
do node.height = height; while ((node = node.parent) && node.height < ++height);
|
|
300
458
|
}
|
|
301
|
-
function Node(data) {
|
|
459
|
+
function Node$1(data) {
|
|
302
460
|
this.data = data;
|
|
303
461
|
this.depth = this.height = 0;
|
|
304
462
|
this.parent = null;
|
|
305
463
|
}
|
|
306
|
-
Node.prototype = hierarchy.prototype = {
|
|
307
|
-
constructor: Node,
|
|
464
|
+
Node$1.prototype = hierarchy.prototype = {
|
|
465
|
+
constructor: Node$1,
|
|
308
466
|
count: node_count,
|
|
309
467
|
each: node_each,
|
|
310
468
|
eachAfter: node_eachAfter,
|
|
@@ -319,15 +477,90 @@ Node.prototype = hierarchy.prototype = {
|
|
|
319
477
|
copy: node_copy
|
|
320
478
|
};
|
|
321
479
|
|
|
322
|
-
var
|
|
480
|
+
var name = "d3-flextree";
|
|
481
|
+
var version$1 = "2.1.2";
|
|
482
|
+
var main = "build/d3-flextree.js";
|
|
483
|
+
var module$1 = "index";
|
|
484
|
+
var author = {
|
|
485
|
+
name: "Chris Maloney",
|
|
486
|
+
url: "http://chrismaloney.org"
|
|
487
|
+
};
|
|
488
|
+
var description = "Flexible tree layout algorithm that allows for variable node sizes.";
|
|
489
|
+
var keywords = [
|
|
490
|
+
"d3",
|
|
491
|
+
"d3-module",
|
|
492
|
+
"layout",
|
|
493
|
+
"tree",
|
|
494
|
+
"hierarchy",
|
|
495
|
+
"d3-hierarchy",
|
|
496
|
+
"plugin",
|
|
497
|
+
"d3-plugin",
|
|
498
|
+
"infovis",
|
|
499
|
+
"visualization",
|
|
500
|
+
"2d"
|
|
501
|
+
];
|
|
502
|
+
var homepage = "https://github.com/klortho/d3-flextree";
|
|
503
|
+
var license = "WTFPL";
|
|
504
|
+
var repository = {
|
|
505
|
+
type: "git",
|
|
506
|
+
url: "https://github.com/klortho/d3-flextree.git"
|
|
507
|
+
};
|
|
508
|
+
var scripts = {
|
|
509
|
+
clean: "rm -rf build demo test",
|
|
510
|
+
"build:demo": "rollup -c --environment BUILD:demo",
|
|
511
|
+
"build:dev": "rollup -c --environment BUILD:dev",
|
|
512
|
+
"build:prod": "rollup -c --environment BUILD:prod",
|
|
513
|
+
"build:test": "rollup -c --environment BUILD:test",
|
|
514
|
+
build: "rollup -c",
|
|
515
|
+
lint: "eslint index.js src",
|
|
516
|
+
"test:main": "node test/bundle.js",
|
|
517
|
+
"test:browser": "node test/browser-tests.js",
|
|
518
|
+
test: "npm-run-all test:*",
|
|
519
|
+
prepare: "npm-run-all clean build lint test"
|
|
520
|
+
};
|
|
521
|
+
var dependencies = {
|
|
522
|
+
"d3-hierarchy": "^1.1.5"
|
|
523
|
+
};
|
|
524
|
+
var devDependencies = {
|
|
525
|
+
"babel-plugin-external-helpers": "^6.22.0",
|
|
526
|
+
"babel-preset-es2015-rollup": "^3.0.0",
|
|
527
|
+
d3: "^4.13.0",
|
|
528
|
+
"d3-selection-multi": "^1.0.1",
|
|
529
|
+
eslint: "^4.19.1",
|
|
530
|
+
jsdom: "^11.6.2",
|
|
531
|
+
"npm-run-all": "^4.1.2",
|
|
532
|
+
rollup: "^0.55.3",
|
|
533
|
+
"rollup-plugin-babel": "^2.7.1",
|
|
534
|
+
"rollup-plugin-commonjs": "^8.0.2",
|
|
535
|
+
"rollup-plugin-copy": "^0.2.3",
|
|
536
|
+
"rollup-plugin-json": "^2.3.0",
|
|
537
|
+
"rollup-plugin-node-resolve": "^3.0.2",
|
|
538
|
+
"rollup-plugin-uglify": "^3.0.0",
|
|
539
|
+
"uglify-es": "^3.3.9"
|
|
540
|
+
};
|
|
541
|
+
var packageInfo = {
|
|
542
|
+
name: name,
|
|
543
|
+
version: version$1,
|
|
544
|
+
main: main,
|
|
545
|
+
module: module$1,
|
|
546
|
+
"jsnext:main": "index",
|
|
547
|
+
author: author,
|
|
548
|
+
description: description,
|
|
549
|
+
keywords: keywords,
|
|
550
|
+
homepage: homepage,
|
|
551
|
+
license: license,
|
|
552
|
+
repository: repository,
|
|
553
|
+
scripts: scripts,
|
|
554
|
+
dependencies: dependencies,
|
|
555
|
+
devDependencies: devDependencies
|
|
556
|
+
};
|
|
323
557
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
},
|
|
558
|
+
const {
|
|
559
|
+
version
|
|
560
|
+
} = packageInfo;
|
|
561
|
+
const defaults = Object.freeze({
|
|
562
|
+
children: data => data.children,
|
|
563
|
+
nodeSize: node => node.data.size,
|
|
331
564
|
spacing: 0
|
|
332
565
|
}); // Create a layout function with customizable options. Per D3-style, the
|
|
333
566
|
// options can be set at any time using setter methods. The layout function
|
|
@@ -335,244 +568,192 @@ var defaults = Object.freeze({
|
|
|
335
568
|
// time it is called.
|
|
336
569
|
|
|
337
570
|
function flextree(options) {
|
|
338
|
-
|
|
571
|
+
const opts = Object.assign({}, defaults, options);
|
|
339
572
|
|
|
340
573
|
function accessor(name) {
|
|
341
|
-
|
|
342
|
-
return typeof opt === 'function' ? opt :
|
|
343
|
-
return opt;
|
|
344
|
-
};
|
|
574
|
+
const opt = opts[name];
|
|
575
|
+
return typeof opt === 'function' ? opt : () => opt;
|
|
345
576
|
}
|
|
346
577
|
|
|
347
578
|
function layout(tree) {
|
|
348
|
-
|
|
349
|
-
return node.children;
|
|
350
|
-
});
|
|
579
|
+
const wtree = wrap(getWrapper(), tree, node => node.children);
|
|
351
580
|
wtree.update();
|
|
352
581
|
return wtree.data;
|
|
353
582
|
}
|
|
354
583
|
|
|
355
584
|
function getFlexNode() {
|
|
356
|
-
|
|
585
|
+
const nodeSize = accessor('nodeSize');
|
|
586
|
+
const spacing = accessor('spacing');
|
|
587
|
+
return class FlexNode extends hierarchy.prototype.constructor {
|
|
588
|
+
constructor(data) {
|
|
589
|
+
super(data);
|
|
590
|
+
}
|
|
357
591
|
|
|
358
|
-
|
|
592
|
+
copy() {
|
|
593
|
+
const c = wrap(this.constructor, this, node => node.children);
|
|
594
|
+
c.each(node => node.data = node.data.data);
|
|
595
|
+
return c;
|
|
596
|
+
}
|
|
359
597
|
|
|
360
|
-
|
|
361
|
-
|
|
598
|
+
get size() {
|
|
599
|
+
return nodeSize(this);
|
|
600
|
+
}
|
|
362
601
|
|
|
363
|
-
|
|
364
|
-
return
|
|
602
|
+
spacing(oNode) {
|
|
603
|
+
return spacing(this, oNode);
|
|
365
604
|
}
|
|
366
605
|
|
|
367
|
-
|
|
606
|
+
get nodes() {
|
|
607
|
+
return this.descendants();
|
|
608
|
+
}
|
|
368
609
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
});
|
|
373
|
-
c.each(function (node) {
|
|
374
|
-
return node.data = node.data.data;
|
|
375
|
-
});
|
|
376
|
-
return c;
|
|
377
|
-
};
|
|
610
|
+
get xSize() {
|
|
611
|
+
return this.size[0];
|
|
612
|
+
}
|
|
378
613
|
|
|
379
|
-
|
|
380
|
-
return
|
|
381
|
-
}
|
|
614
|
+
get ySize() {
|
|
615
|
+
return this.size[1];
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
get top() {
|
|
619
|
+
return this.y;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
get bottom() {
|
|
623
|
+
return this.y + this.ySize;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
get left() {
|
|
627
|
+
return this.x - this.xSize / 2;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
get right() {
|
|
631
|
+
return this.x + this.xSize / 2;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
get root() {
|
|
635
|
+
const ancs = this.ancestors();
|
|
636
|
+
return ancs[ancs.length - 1];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
get numChildren() {
|
|
640
|
+
return this.hasChildren ? this.children.length : 0;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
get hasChildren() {
|
|
644
|
+
return !this.noChildren;
|
|
645
|
+
}
|
|
382
646
|
|
|
383
|
-
|
|
647
|
+
get noChildren() {
|
|
648
|
+
return this.children === null;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
get firstChild() {
|
|
652
|
+
return this.hasChildren ? this.children[0] : null;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
get lastChild() {
|
|
656
|
+
return this.hasChildren ? this.children[this.numChildren - 1] : null;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
get extents() {
|
|
660
|
+
return (this.children || []).reduce((acc, kid) => FlexNode.maxExtents(acc, kid.extents), this.nodeExtents);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
get nodeExtents() {
|
|
664
|
+
return {
|
|
665
|
+
top: this.top,
|
|
666
|
+
bottom: this.bottom,
|
|
667
|
+
left: this.left,
|
|
668
|
+
right: this.right
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
static maxExtents(e0, e1) {
|
|
384
673
|
return {
|
|
385
674
|
top: Math.min(e0.top, e1.top),
|
|
386
675
|
bottom: Math.max(e0.bottom, e1.bottom),
|
|
387
676
|
left: Math.min(e0.left, e1.left),
|
|
388
677
|
right: Math.max(e0.right, e1.right)
|
|
389
678
|
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
_createClass(FlexNode, [{
|
|
393
|
-
key: "size",
|
|
394
|
-
get: function get() {
|
|
395
|
-
return nodeSize(this);
|
|
396
|
-
}
|
|
397
|
-
}, {
|
|
398
|
-
key: "nodes",
|
|
399
|
-
get: function get() {
|
|
400
|
-
return this.descendants();
|
|
401
|
-
}
|
|
402
|
-
}, {
|
|
403
|
-
key: "xSize",
|
|
404
|
-
get: function get() {
|
|
405
|
-
return this.size[0];
|
|
406
|
-
}
|
|
407
|
-
}, {
|
|
408
|
-
key: "ySize",
|
|
409
|
-
get: function get() {
|
|
410
|
-
return this.size[1];
|
|
411
|
-
}
|
|
412
|
-
}, {
|
|
413
|
-
key: "top",
|
|
414
|
-
get: function get() {
|
|
415
|
-
return this.y;
|
|
416
|
-
}
|
|
417
|
-
}, {
|
|
418
|
-
key: "bottom",
|
|
419
|
-
get: function get() {
|
|
420
|
-
return this.y + this.ySize;
|
|
421
|
-
}
|
|
422
|
-
}, {
|
|
423
|
-
key: "left",
|
|
424
|
-
get: function get() {
|
|
425
|
-
return this.x - this.xSize / 2;
|
|
426
|
-
}
|
|
427
|
-
}, {
|
|
428
|
-
key: "right",
|
|
429
|
-
get: function get() {
|
|
430
|
-
return this.x + this.xSize / 2;
|
|
431
|
-
}
|
|
432
|
-
}, {
|
|
433
|
-
key: "root",
|
|
434
|
-
get: function get() {
|
|
435
|
-
var ancs = this.ancestors();
|
|
436
|
-
return ancs[ancs.length - 1];
|
|
437
|
-
}
|
|
438
|
-
}, {
|
|
439
|
-
key: "numChildren",
|
|
440
|
-
get: function get() {
|
|
441
|
-
return this.hasChildren ? this.children.length : 0;
|
|
442
|
-
}
|
|
443
|
-
}, {
|
|
444
|
-
key: "hasChildren",
|
|
445
|
-
get: function get() {
|
|
446
|
-
return !this.noChildren;
|
|
447
|
-
}
|
|
448
|
-
}, {
|
|
449
|
-
key: "noChildren",
|
|
450
|
-
get: function get() {
|
|
451
|
-
return this.children === null;
|
|
452
|
-
}
|
|
453
|
-
}, {
|
|
454
|
-
key: "firstChild",
|
|
455
|
-
get: function get() {
|
|
456
|
-
return this.hasChildren ? this.children[0] : null;
|
|
457
|
-
}
|
|
458
|
-
}, {
|
|
459
|
-
key: "lastChild",
|
|
460
|
-
get: function get() {
|
|
461
|
-
return this.hasChildren ? this.children[this.numChildren - 1] : null;
|
|
462
|
-
}
|
|
463
|
-
}, {
|
|
464
|
-
key: "extents",
|
|
465
|
-
get: function get() {
|
|
466
|
-
return (this.children || []).reduce(function (acc, kid) {
|
|
467
|
-
return FlexNode.maxExtents(acc, kid.extents);
|
|
468
|
-
}, this.nodeExtents);
|
|
469
|
-
}
|
|
470
|
-
}, {
|
|
471
|
-
key: "nodeExtents",
|
|
472
|
-
get: function get() {
|
|
473
|
-
return {
|
|
474
|
-
top: this.top,
|
|
475
|
-
bottom: this.bottom,
|
|
476
|
-
left: this.left,
|
|
477
|
-
right: this.right
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
}]);
|
|
679
|
+
}
|
|
481
680
|
|
|
482
|
-
|
|
483
|
-
}(hierarchy.prototype.constructor);
|
|
681
|
+
};
|
|
484
682
|
}
|
|
485
683
|
|
|
486
684
|
function getWrapper() {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
function _class(data) {
|
|
496
|
-
var _this;
|
|
497
|
-
|
|
498
|
-
_this = _FlexNode.call(this, data) || this;
|
|
499
|
-
Object.assign(_assertThisInitialized(_this), {
|
|
685
|
+
const FlexNode = getFlexNode();
|
|
686
|
+
const nodeSize = accessor('nodeSize');
|
|
687
|
+
const spacing = accessor('spacing');
|
|
688
|
+
return class extends FlexNode {
|
|
689
|
+
constructor(data) {
|
|
690
|
+
super(data);
|
|
691
|
+
Object.assign(this, {
|
|
500
692
|
x: 0,
|
|
501
693
|
y: 0,
|
|
502
694
|
relX: 0,
|
|
503
695
|
prelim: 0,
|
|
504
696
|
shift: 0,
|
|
505
697
|
change: 0,
|
|
506
|
-
lExt:
|
|
698
|
+
lExt: this,
|
|
507
699
|
lExtRelX: 0,
|
|
508
700
|
lThr: null,
|
|
509
|
-
rExt:
|
|
701
|
+
rExt: this,
|
|
510
702
|
rExtRelX: 0,
|
|
511
703
|
rThr: null
|
|
512
704
|
});
|
|
513
|
-
return _this;
|
|
514
705
|
}
|
|
515
706
|
|
|
516
|
-
|
|
707
|
+
get size() {
|
|
708
|
+
return nodeSize(this.data);
|
|
709
|
+
}
|
|
517
710
|
|
|
518
|
-
|
|
519
|
-
return
|
|
520
|
-
}
|
|
711
|
+
spacing(oNode) {
|
|
712
|
+
return spacing(this.data, oNode.data);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
get x() {
|
|
716
|
+
return this.data.x;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
set x(v) {
|
|
720
|
+
this.data.x = v;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
get y() {
|
|
724
|
+
return this.data.y;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
set y(v) {
|
|
728
|
+
this.data.y = v;
|
|
729
|
+
}
|
|
521
730
|
|
|
522
|
-
|
|
731
|
+
update() {
|
|
523
732
|
layoutChildren(this);
|
|
524
733
|
resolveX(this);
|
|
525
734
|
return this;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
_createClass(_class, [{
|
|
529
|
-
key: "size",
|
|
530
|
-
get: function get() {
|
|
531
|
-
return nodeSize(this.data);
|
|
532
|
-
}
|
|
533
|
-
}, {
|
|
534
|
-
key: "x",
|
|
535
|
-
get: function get() {
|
|
536
|
-
return this.data.x;
|
|
537
|
-
},
|
|
538
|
-
set: function set(v) {
|
|
539
|
-
this.data.x = v;
|
|
540
|
-
}
|
|
541
|
-
}, {
|
|
542
|
-
key: "y",
|
|
543
|
-
get: function get() {
|
|
544
|
-
return this.data.y;
|
|
545
|
-
},
|
|
546
|
-
set: function set(v) {
|
|
547
|
-
this.data.y = v;
|
|
548
|
-
}
|
|
549
|
-
}]);
|
|
735
|
+
}
|
|
550
736
|
|
|
551
|
-
|
|
552
|
-
}(FlexNode);
|
|
737
|
+
};
|
|
553
738
|
}
|
|
554
739
|
|
|
555
740
|
function wrap(FlexClass, treeData, children) {
|
|
556
|
-
|
|
557
|
-
|
|
741
|
+
const _wrap = (data, parent) => {
|
|
742
|
+
const node = new FlexClass(data);
|
|
558
743
|
Object.assign(node, {
|
|
559
|
-
parent
|
|
744
|
+
parent,
|
|
560
745
|
depth: parent === null ? 0 : parent.depth + 1,
|
|
561
746
|
height: 0,
|
|
562
747
|
length: 1
|
|
563
748
|
});
|
|
564
|
-
|
|
565
|
-
node.children = kidsData.length === 0 ? null : kidsData.map(
|
|
566
|
-
return _wrap(kd, node);
|
|
567
|
-
});
|
|
749
|
+
const kidsData = children(data) || [];
|
|
750
|
+
node.children = kidsData.length === 0 ? null : kidsData.map(kd => _wrap(kd, node));
|
|
568
751
|
|
|
569
752
|
if (node.children) {
|
|
570
|
-
Object.assign(node, node.children.reduce(
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
};
|
|
575
|
-
}, node));
|
|
753
|
+
Object.assign(node, node.children.reduce((hl, kid) => ({
|
|
754
|
+
height: Math.max(hl.height, kid.height + 1),
|
|
755
|
+
length: hl.length + kid.length
|
|
756
|
+
}), node));
|
|
576
757
|
}
|
|
577
758
|
|
|
578
759
|
return node;
|
|
@@ -582,57 +763,57 @@ function flextree(options) {
|
|
|
582
763
|
}
|
|
583
764
|
|
|
584
765
|
Object.assign(layout, {
|
|
585
|
-
nodeSize
|
|
766
|
+
nodeSize(arg) {
|
|
586
767
|
return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize;
|
|
587
768
|
},
|
|
588
|
-
|
|
769
|
+
|
|
770
|
+
spacing(arg) {
|
|
589
771
|
return arguments.length ? (opts.spacing = arg, layout) : opts.spacing;
|
|
590
772
|
},
|
|
591
|
-
|
|
773
|
+
|
|
774
|
+
children(arg) {
|
|
592
775
|
return arguments.length ? (opts.children = arg, layout) : opts.children;
|
|
593
776
|
},
|
|
594
|
-
|
|
595
|
-
|
|
777
|
+
|
|
778
|
+
hierarchy(treeData, children) {
|
|
779
|
+
const kids = typeof children === 'undefined' ? opts.children : children;
|
|
596
780
|
return wrap(getFlexNode(), treeData, kids);
|
|
597
781
|
},
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
782
|
+
|
|
783
|
+
dump(tree) {
|
|
784
|
+
const nodeSize = accessor('nodeSize');
|
|
785
|
+
|
|
786
|
+
const _dump = i0 => node => {
|
|
787
|
+
const i1 = i0 + ' ';
|
|
788
|
+
const i2 = i0 + ' ';
|
|
789
|
+
const {
|
|
790
|
+
x,
|
|
791
|
+
y
|
|
792
|
+
} = node;
|
|
793
|
+
const size = nodeSize(node);
|
|
794
|
+
const kids = node.children || [];
|
|
795
|
+
const kdumps = kids.length === 0 ? ' ' : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`;
|
|
796
|
+
return `{ size: [${size.join(', ')}],${i1}x: ${x}, y: ${y}${kdumps}},`;
|
|
612
797
|
};
|
|
613
798
|
|
|
614
799
|
return _dump('\n')(tree);
|
|
615
800
|
}
|
|
801
|
+
|
|
616
802
|
});
|
|
617
803
|
return layout;
|
|
618
804
|
}
|
|
619
805
|
flextree.version = version;
|
|
620
806
|
|
|
621
|
-
|
|
622
|
-
if (y === void 0) {
|
|
623
|
-
y = 0;
|
|
624
|
-
}
|
|
625
|
-
|
|
807
|
+
const layoutChildren = (w, y = 0) => {
|
|
626
808
|
w.y = y;
|
|
627
|
-
(w.children || []).reduce(
|
|
628
|
-
|
|
629
|
-
lastLows = acc[1];
|
|
809
|
+
(w.children || []).reduce((acc, kid) => {
|
|
810
|
+
const [i, lastLows] = acc;
|
|
630
811
|
layoutChildren(kid, w.y + w.ySize); // The lowest vertical coordinate while extreme nodes still point
|
|
631
812
|
// in current subtree.
|
|
632
813
|
|
|
633
|
-
|
|
814
|
+
const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom;
|
|
634
815
|
if (i !== 0) separate(w, i, lastLows);
|
|
635
|
-
|
|
816
|
+
const lows = updateLows(lowY, i, lastLows);
|
|
636
817
|
return [i + 1, lows];
|
|
637
818
|
}, [0, null]);
|
|
638
819
|
shiftChange(w);
|
|
@@ -644,7 +825,7 @@ var layoutChildren = function layoutChildren(w, y) {
|
|
|
644
825
|
// to its parent.
|
|
645
826
|
|
|
646
827
|
|
|
647
|
-
|
|
828
|
+
const resolveX = (w, prevSum, parentX) => {
|
|
648
829
|
// A call to resolveX without arguments is assumed to be for the root of
|
|
649
830
|
// the tree. This will set the root's x-coord to zero.
|
|
650
831
|
if (typeof prevSum === 'undefined') {
|
|
@@ -652,24 +833,21 @@ var resolveX = function resolveX(w, prevSum, parentX) {
|
|
|
652
833
|
parentX = 0;
|
|
653
834
|
}
|
|
654
835
|
|
|
655
|
-
|
|
836
|
+
const sum = prevSum + w.relX;
|
|
656
837
|
w.relX = sum + w.prelim - parentX;
|
|
657
838
|
w.prelim = 0;
|
|
658
839
|
w.x = parentX + w.relX;
|
|
659
|
-
(w.children || []).forEach(
|
|
660
|
-
return resolveX(k, sum, w.x);
|
|
661
|
-
});
|
|
840
|
+
(w.children || []).forEach(k => resolveX(k, sum, w.x));
|
|
662
841
|
return w;
|
|
663
842
|
}; // Process shift and change for all children, to add intermediate spacing to
|
|
664
843
|
// each child's modifier.
|
|
665
844
|
|
|
666
845
|
|
|
667
|
-
|
|
668
|
-
(w.children || []).reduce(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
var changeSum = lastChangeSum + shiftSum + child.change;
|
|
846
|
+
const shiftChange = w => {
|
|
847
|
+
(w.children || []).reduce((acc, child) => {
|
|
848
|
+
const [lastShiftSum, lastChangeSum] = acc;
|
|
849
|
+
const shiftSum = lastShiftSum + child.shift;
|
|
850
|
+
const changeSum = lastChangeSum + shiftSum + child.change;
|
|
673
851
|
child.relX += changeSum;
|
|
674
852
|
return [shiftSum, changeSum];
|
|
675
853
|
}, [0, 0]);
|
|
@@ -678,21 +856,21 @@ var shiftChange = function shiftChange(w) {
|
|
|
678
856
|
/* eslint-disable complexity */
|
|
679
857
|
|
|
680
858
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
859
|
+
const separate = (w, i, lows) => {
|
|
860
|
+
const lSib = w.children[i - 1];
|
|
861
|
+
const curSubtree = w.children[i];
|
|
862
|
+
let rContour = lSib;
|
|
863
|
+
let rSumMods = lSib.relX;
|
|
864
|
+
let lContour = curSubtree;
|
|
865
|
+
let lSumMods = curSubtree.relX;
|
|
866
|
+
let isFirst = true;
|
|
689
867
|
|
|
690
868
|
while (rContour && lContour) {
|
|
691
869
|
if (rContour.bottom > lows.lowY) lows = lows.next; // How far to the left of the right side of rContour is the left side
|
|
692
870
|
// of lContour? First compute the center-to-center distance, then add
|
|
693
871
|
// the "spacing"
|
|
694
872
|
|
|
695
|
-
|
|
873
|
+
const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour);
|
|
696
874
|
|
|
697
875
|
if (dist > 0 || dist < 0 && isFirst) {
|
|
698
876
|
lSumMods += dist; // Move subtree by changing relX.
|
|
@@ -703,8 +881,8 @@ var separate = function separate(w, i, lows) {
|
|
|
703
881
|
|
|
704
882
|
isFirst = false; // Advance highest node(s) and sum(s) of modifiers
|
|
705
883
|
|
|
706
|
-
|
|
707
|
-
|
|
884
|
+
const rightBottom = rContour.bottom;
|
|
885
|
+
const leftBottom = lContour.bottom;
|
|
708
886
|
|
|
709
887
|
if (rightBottom <= leftBottom) {
|
|
710
888
|
rContour = nextRContour(rContour);
|
|
@@ -726,39 +904,39 @@ var separate = function separate(w, i, lows) {
|
|
|
726
904
|
// Move subtree by changing relX.
|
|
727
905
|
|
|
728
906
|
|
|
729
|
-
|
|
907
|
+
const moveSubtree = (subtree, distance) => {
|
|
730
908
|
subtree.relX += distance;
|
|
731
909
|
subtree.lExtRelX += distance;
|
|
732
910
|
subtree.rExtRelX += distance;
|
|
733
911
|
};
|
|
734
912
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
913
|
+
const distributeExtra = (w, curSubtreeI, leftSibI, dist) => {
|
|
914
|
+
const curSubtree = w.children[curSubtreeI];
|
|
915
|
+
const n = curSubtreeI - leftSibI; // Are there intermediate children?
|
|
738
916
|
|
|
739
917
|
if (n > 1) {
|
|
740
|
-
|
|
918
|
+
const delta = dist / n;
|
|
741
919
|
w.children[leftSibI + 1].shift += delta;
|
|
742
920
|
curSubtree.shift -= delta;
|
|
743
921
|
curSubtree.change -= dist - delta;
|
|
744
922
|
}
|
|
745
923
|
};
|
|
746
924
|
|
|
747
|
-
|
|
925
|
+
const nextLContour = w => {
|
|
748
926
|
return w.hasChildren ? w.firstChild : w.lThr;
|
|
749
927
|
};
|
|
750
928
|
|
|
751
|
-
|
|
929
|
+
const nextRContour = w => {
|
|
752
930
|
return w.hasChildren ? w.lastChild : w.rThr;
|
|
753
931
|
};
|
|
754
932
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
933
|
+
const setLThr = (w, i, lContour, lSumMods) => {
|
|
934
|
+
const firstChild = w.firstChild;
|
|
935
|
+
const lExt = firstChild.lExt;
|
|
936
|
+
const curSubtree = w.children[i];
|
|
759
937
|
lExt.lThr = lContour; // Change relX so that the sum of modifier after following thread is correct.
|
|
760
938
|
|
|
761
|
-
|
|
939
|
+
const diff = lSumMods - lContour.relX - firstChild.lExtRelX;
|
|
762
940
|
lExt.relX += diff; // Change preliminary x coordinate so that the node does not move.
|
|
763
941
|
|
|
764
942
|
lExt.prelim -= diff; // Update extreme node and its sum of modifiers.
|
|
@@ -768,12 +946,12 @@ var setLThr = function setLThr(w, i, lContour, lSumMods) {
|
|
|
768
946
|
}; // Mirror image of setLThr.
|
|
769
947
|
|
|
770
948
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
949
|
+
const setRThr = (w, i, rContour, rSumMods) => {
|
|
950
|
+
const curSubtree = w.children[i];
|
|
951
|
+
const rExt = curSubtree.rExt;
|
|
952
|
+
const lSib = w.children[i - 1];
|
|
775
953
|
rExt.rThr = rContour;
|
|
776
|
-
|
|
954
|
+
const diff = rSumMods - rContour.relX - curSubtree.rExtRelX;
|
|
777
955
|
rExt.relX += diff;
|
|
778
956
|
rExt.prelim -= diff;
|
|
779
957
|
curSubtree.rExt = lSib.rExt;
|
|
@@ -781,13 +959,13 @@ var setRThr = function setRThr(w, i, rContour, rSumMods) {
|
|
|
781
959
|
}; // Position root between children, taking into account their modifiers
|
|
782
960
|
|
|
783
961
|
|
|
784
|
-
|
|
962
|
+
const positionRoot = w => {
|
|
785
963
|
if (w.hasChildren) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
964
|
+
const k0 = w.firstChild;
|
|
965
|
+
const kf = w.lastChild;
|
|
966
|
+
const prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2;
|
|
789
967
|
Object.assign(w, {
|
|
790
|
-
prelim
|
|
968
|
+
prelim,
|
|
791
969
|
lExt: k0.lExt,
|
|
792
970
|
lExtRelX: k0.lExtRelX,
|
|
793
971
|
rExt: kf.rExt,
|
|
@@ -798,226 +976,257 @@ var positionRoot = function positionRoot(w) {
|
|
|
798
976
|
// lowest vertical coordinate.
|
|
799
977
|
|
|
800
978
|
|
|
801
|
-
|
|
979
|
+
const updateLows = (lowY, index, lastLows) => {
|
|
802
980
|
// Remove siblings that are hidden by the new subtree.
|
|
803
|
-
while (lastLows !== null && lowY >= lastLows.lowY)
|
|
804
|
-
lastLows = lastLows.next;
|
|
805
|
-
} // Prepend the new subtree.
|
|
981
|
+
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next; // Prepend the new subtree.
|
|
806
982
|
|
|
807
983
|
|
|
808
984
|
return {
|
|
809
|
-
lowY
|
|
810
|
-
index
|
|
985
|
+
lowY,
|
|
986
|
+
index,
|
|
811
987
|
next: lastLows
|
|
812
988
|
};
|
|
813
989
|
};
|
|
814
990
|
|
|
815
|
-
/*!
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
991
|
+
/*! @gera2ld/jsx-dom v2.1.1 | ISC License */
|
|
992
|
+
var VTYPE_ELEMENT = 1;
|
|
993
|
+
var VTYPE_FUNCTION = 2;
|
|
994
|
+
var MOUNT_SINGLE = 1;
|
|
995
|
+
var MOUNT_ARRAY = 4;
|
|
996
|
+
var SVG_NS = 'http://www.w3.org/2000/svg';
|
|
997
|
+
var XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
998
|
+
var NS_ATTRS = {
|
|
999
|
+
show: XLINK_NS,
|
|
1000
|
+
actuate: XLINK_NS,
|
|
1001
|
+
href: XLINK_NS
|
|
1002
|
+
};
|
|
820
1003
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
1004
|
+
var isLeaf = function isLeaf(c) {
|
|
1005
|
+
return typeof c === 'string' || typeof c === 'number';
|
|
1006
|
+
};
|
|
825
1007
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
}
|
|
1008
|
+
var isElement = function isElement(c) {
|
|
1009
|
+
return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
1010
|
+
};
|
|
830
1011
|
|
|
831
|
-
|
|
832
|
-
|
|
1012
|
+
var isRenderFunction = function isRenderFunction(c) {
|
|
1013
|
+
return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
function jsx(type, props) {
|
|
1017
|
+
var vtype;
|
|
1018
|
+
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
1019
|
+
return {
|
|
1020
|
+
vtype: vtype,
|
|
1021
|
+
type: type,
|
|
1022
|
+
props: props
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function Fragment(props) {
|
|
1027
|
+
return props.children;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
var DEFAULT_ENV = {
|
|
1031
|
+
isSvg: false
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
function insertDom(parent, ref) {
|
|
1035
|
+
if (ref.type === MOUNT_SINGLE) {
|
|
1036
|
+
if (ref.node != null) parent.append(ref.node);
|
|
1037
|
+
} else if (ref.type === MOUNT_ARRAY) {
|
|
1038
|
+
ref.children.forEach(function (ch) {
|
|
1039
|
+
insertDom(parent, ch);
|
|
1040
|
+
});
|
|
1041
|
+
} else {
|
|
1042
|
+
throw new Error("Unkown ref type " + JSON.stringify(ref));
|
|
833
1043
|
}
|
|
1044
|
+
}
|
|
834
1045
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
1046
|
+
function mountAttributes(domElement, props, env) {
|
|
1047
|
+
for (var key in props) {
|
|
1048
|
+
if (key === 'key' || key === 'children' || key === 'ref') continue;
|
|
1049
|
+
|
|
1050
|
+
if (key === 'dangerouslySetInnerHTML') {
|
|
1051
|
+
domElement.innerHTML = props[key].__html;
|
|
1052
|
+
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
|
|
1053
|
+
domElement[key] = props[key];
|
|
1054
|
+
} else if (key.startsWith('on')) {
|
|
1055
|
+
domElement[key.toLowerCase()] = props[key];
|
|
1056
|
+
} else {
|
|
1057
|
+
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
838
1058
|
}
|
|
839
1059
|
}
|
|
840
|
-
|
|
841
1060
|
}
|
|
842
1061
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
1062
|
+
var attrMap = {
|
|
1063
|
+
className: 'class',
|
|
1064
|
+
labelFor: 'for'
|
|
1065
|
+
};
|
|
847
1066
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
target[key] = source[key];
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
}
|
|
1067
|
+
function setDOMAttribute(el, attr, value, isSVG) {
|
|
1068
|
+
attr = attrMap[attr] || attr;
|
|
854
1069
|
|
|
855
|
-
|
|
856
|
-
|
|
1070
|
+
if (value === true) {
|
|
1071
|
+
el.setAttribute(attr, '');
|
|
1072
|
+
} else if (value === false) {
|
|
1073
|
+
el.removeAttribute(attr);
|
|
1074
|
+
} else {
|
|
1075
|
+
var namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
857
1076
|
|
|
858
|
-
|
|
1077
|
+
if (namespace !== undefined) {
|
|
1078
|
+
el.setAttributeNS(namespace, attr, value);
|
|
1079
|
+
} else {
|
|
1080
|
+
el.setAttribute(attr, value);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
859
1083
|
}
|
|
860
1084
|
|
|
861
|
-
|
|
862
|
-
|
|
1085
|
+
function mount(vnode, env) {
|
|
1086
|
+
if (env === void 0) {
|
|
1087
|
+
env = DEFAULT_ENV;
|
|
1088
|
+
}
|
|
863
1089
|
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1090
|
+
if (vnode == null || typeof vnode === 'boolean') {
|
|
1091
|
+
return {
|
|
1092
|
+
type: MOUNT_SINGLE,
|
|
1093
|
+
node: null
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
868
1096
|
|
|
869
|
-
|
|
870
|
-
|
|
1097
|
+
if (vnode instanceof Node) {
|
|
1098
|
+
return {
|
|
1099
|
+
type: MOUNT_SINGLE,
|
|
1100
|
+
node: vnode
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
871
1103
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1104
|
+
if (isRenderFunction(vnode)) {
|
|
1105
|
+
var _ref = vnode,
|
|
1106
|
+
type = _ref.type,
|
|
1107
|
+
props = _ref.props;
|
|
875
1108
|
|
|
876
|
-
(
|
|
877
|
-
|
|
878
|
-
});
|
|
879
|
-
}, parent);
|
|
1109
|
+
if (type === Fragment) {
|
|
1110
|
+
var node = document.createDocumentFragment();
|
|
880
1111
|
|
|
881
|
-
|
|
882
|
-
|
|
1112
|
+
if (props.children) {
|
|
1113
|
+
var childrenRef = mount(props.children, env);
|
|
1114
|
+
insertDom(node, childrenRef);
|
|
1115
|
+
}
|
|
883
1116
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1117
|
+
return {
|
|
1118
|
+
type: MOUNT_SINGLE,
|
|
1119
|
+
node: node
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
887
1122
|
|
|
888
|
-
|
|
889
|
-
|
|
1123
|
+
var childVNode = type(props);
|
|
1124
|
+
return mount(childVNode, env);
|
|
890
1125
|
}
|
|
891
1126
|
|
|
892
|
-
|
|
893
|
-
|
|
1127
|
+
if (isLeaf(vnode)) {
|
|
1128
|
+
return {
|
|
1129
|
+
type: MOUNT_SINGLE,
|
|
1130
|
+
node: document.createTextNode("" + vnode)
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
894
1133
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
rest.forEach(item => {
|
|
898
|
-
if (item && classList.indexOf(item) < 0) classList.push(item);
|
|
899
|
-
});
|
|
900
|
-
return classList.join(' ');
|
|
901
|
-
}
|
|
1134
|
+
if (isElement(vnode)) {
|
|
1135
|
+
var _node;
|
|
902
1136
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1137
|
+
var _ref2 = vnode,
|
|
1138
|
+
_type = _ref2.type,
|
|
1139
|
+
_props = _ref2.props;
|
|
906
1140
|
|
|
907
|
-
|
|
908
|
-
|
|
1141
|
+
if (!env.isSvg && _type === 'svg') {
|
|
1142
|
+
env = Object.assign({}, env, {
|
|
1143
|
+
isSvg: true
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
909
1146
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
};
|
|
916
|
-
}
|
|
1147
|
+
if (!env.isSvg) {
|
|
1148
|
+
_node = document.createElement(_type);
|
|
1149
|
+
} else {
|
|
1150
|
+
_node = document.createElementNS(SVG_NS, _type);
|
|
1151
|
+
}
|
|
917
1152
|
|
|
918
|
-
|
|
919
|
-
const cache = {};
|
|
920
|
-
return function memoized(...args) {
|
|
921
|
-
const key = `${args[0]}`;
|
|
922
|
-
let data = cache[key];
|
|
1153
|
+
mountAttributes(_node, _props, env);
|
|
923
1154
|
|
|
924
|
-
|
|
925
|
-
data = {
|
|
926
|
-
value: fn(...args)
|
|
927
|
-
};
|
|
928
|
-
cache[key] = data;
|
|
929
|
-
}
|
|
1155
|
+
var _childrenRef;
|
|
930
1156
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
}
|
|
1157
|
+
if (_props.children) {
|
|
1158
|
+
var childEnv = env;
|
|
934
1159
|
|
|
935
|
-
|
|
936
|
-
|
|
1160
|
+
if (env.isSvg && _type === 'foreignObject') {
|
|
1161
|
+
childEnv = Object.assign({}, childEnv, {
|
|
1162
|
+
isSvg: false
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
937
1165
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1166
|
+
_childrenRef = mount(_props.children, childEnv);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
if (_childrenRef != null) insertDom(_node, _childrenRef);
|
|
1170
|
+
var ref = _props.ref;
|
|
1171
|
+
if (typeof ref === 'function') ref(_node);
|
|
1172
|
+
return {
|
|
1173
|
+
type: MOUNT_SINGLE,
|
|
1174
|
+
node: _node
|
|
1175
|
+
};
|
|
942
1176
|
}
|
|
943
1177
|
|
|
944
|
-
if (
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1178
|
+
if (Array.isArray(vnode)) {
|
|
1179
|
+
return {
|
|
1180
|
+
type: MOUNT_ARRAY,
|
|
1181
|
+
children: vnode.map(function (child) {
|
|
1182
|
+
return mount(child, env);
|
|
1183
|
+
})
|
|
1184
|
+
};
|
|
948
1185
|
}
|
|
949
1186
|
|
|
950
|
-
|
|
1187
|
+
throw new Error('mount: Invalid Vnode!');
|
|
951
1188
|
}
|
|
952
1189
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
rel: 'preload',
|
|
956
|
-
as: 'script',
|
|
957
|
-
href: url
|
|
958
|
-
}));
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
function loadJSItem(item, context) {
|
|
962
|
-
if (item.type === 'script') {
|
|
963
|
-
return new Promise((resolve, reject) => {
|
|
964
|
-
var _item$data;
|
|
965
|
-
|
|
966
|
-
document.head.append(createElement('script', _extends({}, item.data, {
|
|
967
|
-
onload: resolve,
|
|
968
|
-
onerror: reject
|
|
969
|
-
}))); // Run inline script synchronously
|
|
1190
|
+
function flattenWithoutNull(array) {
|
|
1191
|
+
var result = [];
|
|
970
1192
|
|
|
971
|
-
|
|
972
|
-
|
|
1193
|
+
for (var i = 0; i < array.length; i += 1) {
|
|
1194
|
+
var item = array[i];
|
|
1195
|
+
if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
|
|
973
1196
|
}
|
|
974
1197
|
|
|
975
|
-
|
|
976
|
-
const {
|
|
977
|
-
fn,
|
|
978
|
-
getParams
|
|
979
|
-
} = item.data;
|
|
980
|
-
fn(...((getParams == null ? void 0 : getParams(context)) || []));
|
|
981
|
-
}
|
|
1198
|
+
return result;
|
|
982
1199
|
}
|
|
983
1200
|
|
|
984
|
-
function
|
|
985
|
-
if (
|
|
986
|
-
|
|
987
|
-
textContent: item.data
|
|
988
|
-
}));
|
|
989
|
-
} else if (item.type === 'stylesheet') {
|
|
990
|
-
document.head.append(createElement('link', _extends({
|
|
991
|
-
rel: 'stylesheet'
|
|
992
|
-
}, item.data)));
|
|
1201
|
+
function asDom(result) {
|
|
1202
|
+
if (result.type === MOUNT_SINGLE) {
|
|
1203
|
+
return result.node;
|
|
993
1204
|
}
|
|
994
|
-
}
|
|
995
1205
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1206
|
+
return result.children.map(asDom);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Mount vdom as real DOM nodes.
|
|
1210
|
+
*/
|
|
999
1211
|
|
|
1000
|
-
return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
|
|
1001
|
-
});
|
|
1002
|
-
if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
|
|
1003
|
-
context = _extends({
|
|
1004
|
-
getMarkmap: () => window.markmap
|
|
1005
|
-
}, context);
|
|
1006
1212
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1213
|
+
function mountDom(vnode) {
|
|
1214
|
+
if (Array.isArray(vnode)) {
|
|
1215
|
+
return flattenWithoutNull(vnode.map(mountDom));
|
|
1009
1216
|
}
|
|
1010
|
-
}
|
|
1011
1217
|
|
|
1012
|
-
|
|
1013
|
-
for (const item of items) {
|
|
1014
|
-
loadCSSItem(item);
|
|
1015
|
-
}
|
|
1218
|
+
return asDom(mount(vnode));
|
|
1016
1219
|
}
|
|
1017
1220
|
|
|
1221
|
+
var css_248z$1 = ".markmap{font:300 16px/20px sans-serif}.markmap-link{fill:none}.markmap-node>circle{cursor:pointer}.markmap-foreign{display:inline-block}.markmap-foreign a{color:#0097e6}.markmap-foreign a:hover{color:#00a8ff}.markmap-foreign code{background-color:#f0f0f0;border-radius:2px;color:#555;font-size:calc(1em - 2px)}.markmap-foreign :not(pre)>code{padding:.2em .4em}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:bolder}.markmap-foreign mark{background:#ffeaa7}.markmap-foreign pre,.markmap-foreign pre[class*=language-]{margin:0;padding:.2em .4em}";
|
|
1222
|
+
|
|
1223
|
+
var css_248z = ".markmap-container{height:0;left:-100px;overflow:hidden;position:absolute;top:-100px;width:0}.markmap-container>*{display:inline-block}.markmap-container>*>.markmap-foreign:last-child{white-space:nowrap}";
|
|
1224
|
+
|
|
1225
|
+
const globalCSS = css_248z$1;
|
|
1226
|
+
|
|
1018
1227
|
function linkWidth(nodeData) {
|
|
1019
1228
|
const data = nodeData.data;
|
|
1020
|
-
return Math.max(6 - 2 * data.
|
|
1229
|
+
return Math.max(6 - 2 * data.depth, 1.5);
|
|
1021
1230
|
}
|
|
1022
1231
|
|
|
1023
1232
|
function adjustSpacing(tree, spacing) {
|
|
@@ -1048,30 +1257,32 @@ function createViewHooks() {
|
|
|
1048
1257
|
|
|
1049
1258
|
|
|
1050
1259
|
const refreshHook = new Hook();
|
|
1260
|
+
const defaultColorFn = d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10);
|
|
1261
|
+
const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
|
|
1051
1262
|
class Markmap {
|
|
1052
1263
|
constructor(svg, opts) {
|
|
1053
|
-
this.options = void 0;
|
|
1054
|
-
this.state = void 0;
|
|
1055
|
-
this.svg = void 0;
|
|
1056
|
-
this.styleNode = void 0;
|
|
1057
|
-
this.g = void 0;
|
|
1058
|
-
this.zoom = void 0;
|
|
1059
|
-
this.viewHooks = void 0;
|
|
1060
1264
|
this.revokers = [];
|
|
1061
|
-
['handleZoom', 'handleClick'].forEach(key => {
|
|
1265
|
+
['handleZoom', 'handleClick', 'handlePan'].forEach(key => {
|
|
1062
1266
|
this[key] = this[key].bind(this);
|
|
1063
1267
|
});
|
|
1064
1268
|
this.viewHooks = createViewHooks();
|
|
1065
1269
|
this.svg = svg.datum ? svg : d3__namespace.select(svg);
|
|
1066
1270
|
this.styleNode = this.svg.append('style');
|
|
1067
|
-
this.zoom = d3__namespace.zoom().
|
|
1068
|
-
|
|
1271
|
+
this.zoom = d3__namespace.zoom().filter(event => {
|
|
1272
|
+
if (this.options.scrollForPan) {
|
|
1273
|
+
// Pan with wheels, zoom with ctrl+wheels
|
|
1274
|
+
if (event.type === 'wheel') return event.ctrlKey && !event.button;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return (!event.ctrlKey || event.type === 'wheel') && !event.button;
|
|
1278
|
+
}).on('zoom', this.handleZoom);
|
|
1279
|
+
this.setOptions(opts);
|
|
1069
1280
|
this.state = {
|
|
1070
|
-
id: this.options.id || getId()
|
|
1281
|
+
id: this.options.id || this.svg.attr('id') || getId()
|
|
1071
1282
|
};
|
|
1072
|
-
this.g = this.svg.append('g')
|
|
1283
|
+
this.g = this.svg.append('g');
|
|
1073
1284
|
this.updateStyle();
|
|
1074
|
-
this.svg.call(this.zoom);
|
|
1285
|
+
this.svg.call(this.zoom).on('wheel', this.handlePan);
|
|
1075
1286
|
this.revokers.push(refreshHook.tap(() => {
|
|
1076
1287
|
this.setData();
|
|
1077
1288
|
}));
|
|
@@ -1079,34 +1290,19 @@ class Markmap {
|
|
|
1079
1290
|
|
|
1080
1291
|
getStyleContent() {
|
|
1081
1292
|
const {
|
|
1082
|
-
style
|
|
1083
|
-
nodeFont
|
|
1293
|
+
style
|
|
1084
1294
|
} = this.options;
|
|
1085
1295
|
const {
|
|
1086
1296
|
id
|
|
1087
1297
|
} = this.state;
|
|
1088
|
-
const
|
|
1089
|
-
|
|
1090
|
-
.${id} { line-height: 1; }
|
|
1091
|
-
.${id} a { color: #0097e6; }
|
|
1092
|
-
.${id} a:hover { color: #00a8ff; }
|
|
1093
|
-
.${id}-g > path { fill: none; }
|
|
1094
|
-
.${id}-g > g > circle { cursor: pointer; }
|
|
1095
|
-
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; }
|
|
1096
|
-
.${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }
|
|
1097
|
-
.${id}-fo :not(pre) > code { padding: .2em .4em; }
|
|
1098
|
-
.${id}-fo del { text-decoration: line-through; }
|
|
1099
|
-
.${id}-fo em { font-style: italic; }
|
|
1100
|
-
.${id}-fo strong { font-weight: bolder; }
|
|
1101
|
-
.${id}-fo pre { margin: 0; padding: .2em .4em; }
|
|
1102
|
-
${extraStyle}
|
|
1103
|
-
`;
|
|
1104
|
-
return styleText;
|
|
1298
|
+
const styleText = typeof style === 'function' ? style(id) : '';
|
|
1299
|
+
return [this.options.embedGlobalCSS && css_248z$1, styleText].filter(Boolean).join('\n');
|
|
1105
1300
|
}
|
|
1106
1301
|
|
|
1107
1302
|
updateStyle() {
|
|
1108
|
-
this.svg.attr('class', addClass(this.svg.attr('class'), this.state.id));
|
|
1109
|
-
this.
|
|
1303
|
+
this.svg.attr('class', addClass(this.svg.attr('class'), 'markmap', this.state.id));
|
|
1304
|
+
const style = this.getStyleContent();
|
|
1305
|
+
this.styleNode.text(style);
|
|
1110
1306
|
}
|
|
1111
1307
|
|
|
1112
1308
|
handleZoom(e) {
|
|
@@ -1116,76 +1312,84 @@ ${extraStyle}
|
|
|
1116
1312
|
this.g.attr('transform', transform);
|
|
1117
1313
|
}
|
|
1118
1314
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1315
|
+
handlePan(e) {
|
|
1316
|
+
e.preventDefault();
|
|
1317
|
+
const transform = d3__namespace.zoomTransform(this.svg.node());
|
|
1318
|
+
const newTransform = transform.translate(-e.deltaX, -e.deltaY);
|
|
1319
|
+
this.svg.call(this.zoom.transform, newTransform);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
handleClick(_, d) {
|
|
1323
|
+
var _data$payload;
|
|
1121
1324
|
|
|
1122
1325
|
const {
|
|
1123
1326
|
data
|
|
1124
1327
|
} = d;
|
|
1125
|
-
data.
|
|
1126
|
-
|
|
1328
|
+
data.payload = _extends({}, data.payload, {
|
|
1329
|
+
fold: !((_data$payload = data.payload) != null && _data$payload.fold)
|
|
1127
1330
|
});
|
|
1128
1331
|
this.renderData(d.data);
|
|
1129
1332
|
}
|
|
1130
1333
|
|
|
1131
1334
|
initializeData(node) {
|
|
1132
|
-
let
|
|
1335
|
+
let nodeId = 0;
|
|
1133
1336
|
const {
|
|
1134
|
-
nodeFont,
|
|
1135
1337
|
color,
|
|
1136
|
-
nodeMinHeight
|
|
1338
|
+
nodeMinHeight,
|
|
1339
|
+
maxWidth
|
|
1137
1340
|
} = this.options;
|
|
1138
1341
|
const {
|
|
1139
1342
|
id
|
|
1140
1343
|
} = this.state;
|
|
1141
|
-
const container =
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
const style =
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
width: 0;
|
|
1150
|
-
height: 0;
|
|
1151
|
-
top: -100px;
|
|
1152
|
-
left: -100px;
|
|
1153
|
-
overflow: hidden;
|
|
1154
|
-
font: ${nodeFont};
|
|
1155
|
-
}
|
|
1156
|
-
.${containerClass} > div {
|
|
1157
|
-
display: inline-block;
|
|
1158
|
-
}
|
|
1159
|
-
`;
|
|
1160
|
-
document.body.append(style, container);
|
|
1344
|
+
const container = mountDom(jsx("div", {
|
|
1345
|
+
className: `markmap-container markmap ${id}-g`
|
|
1346
|
+
}));
|
|
1347
|
+
const style = mountDom(jsx("style", {
|
|
1348
|
+
children: [this.getStyleContent(), css_248z].join('\n')
|
|
1349
|
+
}));
|
|
1350
|
+
document.body.append(container, style);
|
|
1351
|
+
const groupStyle = maxWidth ? `max-width: ${maxWidth}px` : null;
|
|
1161
1352
|
walkTree(node, (item, next) => {
|
|
1162
|
-
var _item$
|
|
1163
|
-
|
|
1164
|
-
item.
|
|
1165
|
-
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1353
|
+
var _item$children;
|
|
1354
|
+
|
|
1355
|
+
item.children = (_item$children = item.children) == null ? void 0 : _item$children.map(child => _extends({}, child));
|
|
1356
|
+
nodeId += 1;
|
|
1357
|
+
const group = mountDom(jsx("div", {
|
|
1358
|
+
style: groupStyle,
|
|
1359
|
+
children: jsx("div", {
|
|
1360
|
+
className: "markmap-foreign",
|
|
1361
|
+
dangerouslySetInnerHTML: {
|
|
1362
|
+
__html: item.content
|
|
1363
|
+
}
|
|
1364
|
+
})
|
|
1365
|
+
}));
|
|
1366
|
+
container.append(group);
|
|
1367
|
+
item.state = _extends({}, item.state, {
|
|
1368
|
+
id: nodeId,
|
|
1369
|
+
el: group.firstChild
|
|
1173
1370
|
});
|
|
1174
1371
|
color(item); // preload colors
|
|
1175
1372
|
|
|
1176
1373
|
next();
|
|
1177
1374
|
});
|
|
1178
|
-
const nodes = arrayFrom(container.childNodes);
|
|
1179
|
-
this.viewHooks.transformHtml.call(this, nodes);
|
|
1375
|
+
const nodes = arrayFrom(container.childNodes).map(group => group.firstChild);
|
|
1376
|
+
this.viewHooks.transformHtml.call(this, nodes); // Clone the rendered HTML and set `white-space: nowrap` to it to detect its max-width.
|
|
1377
|
+
// The parent node will have a width of the max-width and the original content without
|
|
1378
|
+
// `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
|
|
1379
|
+
// content in one line as much as possible, and subjecting to the given max-width.
|
|
1380
|
+
|
|
1381
|
+
nodes.forEach(node => {
|
|
1382
|
+
node.parentNode.append(node.cloneNode(true));
|
|
1383
|
+
});
|
|
1180
1384
|
walkTree(node, (item, next, parent) => {
|
|
1181
|
-
var _parent$
|
|
1182
|
-
|
|
1183
|
-
const rect = item.
|
|
1184
|
-
item.
|
|
1185
|
-
item.
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
item.
|
|
1385
|
+
var _parent$state, _parent$state2;
|
|
1386
|
+
|
|
1387
|
+
const rect = item.state.el.getBoundingClientRect();
|
|
1388
|
+
item.content = item.state.el.innerHTML;
|
|
1389
|
+
item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
|
|
1390
|
+
item.state.path = [parent == null ? void 0 : (_parent$state = parent.state) == null ? void 0 : _parent$state.path, item.state.id].filter(Boolean).join('.');
|
|
1391
|
+
item.state.key = [parent == null ? void 0 : (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') + // FIXME: find a way to check content hash
|
|
1392
|
+
item.content;
|
|
1189
1393
|
next();
|
|
1190
1394
|
});
|
|
1191
1395
|
container.remove();
|
|
@@ -1193,19 +1397,18 @@ ${this.getStyleContent()}
|
|
|
1193
1397
|
}
|
|
1194
1398
|
|
|
1195
1399
|
setOptions(opts) {
|
|
1196
|
-
|
|
1400
|
+
this.options = _extends({}, Markmap.defaultOptions, opts);
|
|
1197
1401
|
}
|
|
1198
1402
|
|
|
1199
1403
|
setData(data, opts) {
|
|
1200
|
-
if (
|
|
1201
|
-
this.state.data
|
|
1202
|
-
this.initializeData(data);
|
|
1404
|
+
if (data) this.state.data = data;
|
|
1405
|
+
this.initializeData(this.state.data);
|
|
1203
1406
|
if (opts) this.setOptions(opts);
|
|
1204
1407
|
this.renderData();
|
|
1205
1408
|
}
|
|
1206
1409
|
|
|
1207
1410
|
renderData(originData) {
|
|
1208
|
-
var _origin$data$
|
|
1411
|
+
var _origin$data$state$x, _origin$data$state$y;
|
|
1209
1412
|
|
|
1210
1413
|
if (!this.state.data) return;
|
|
1211
1414
|
const {
|
|
@@ -1215,15 +1418,12 @@ ${this.getStyleContent()}
|
|
|
1215
1418
|
autoFit,
|
|
1216
1419
|
color
|
|
1217
1420
|
} = this.options;
|
|
1218
|
-
const {
|
|
1219
|
-
id
|
|
1220
|
-
} = this.state;
|
|
1221
1421
|
const layout = flextree().children(d => {
|
|
1222
|
-
var _d$
|
|
1422
|
+
var _d$payload;
|
|
1223
1423
|
|
|
1224
|
-
return !((_d$
|
|
1424
|
+
return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
|
|
1225
1425
|
}).nodeSize(d => {
|
|
1226
|
-
const [width, height] = d.data.
|
|
1426
|
+
const [width, height] = d.data.state.size;
|
|
1227
1427
|
return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
|
|
1228
1428
|
}).spacing((a, b) => {
|
|
1229
1429
|
return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
|
|
@@ -1246,43 +1446,45 @@ ${this.getStyleContent()}
|
|
|
1246
1446
|
});
|
|
1247
1447
|
if (autoFit) this.fit();
|
|
1248
1448
|
const origin = originData && descendants.find(item => item.data === originData) || tree;
|
|
1249
|
-
const x0 = (_origin$data$
|
|
1250
|
-
const y0 = (_origin$data$
|
|
1449
|
+
const x0 = (_origin$data$state$x = origin.data.state.x0) != null ? _origin$data$state$x : origin.x;
|
|
1450
|
+
const y0 = (_origin$data$state$y = origin.data.state.y0) != null ? _origin$data$state$y : origin.y; // Update the nodes
|
|
1251
1451
|
|
|
1252
|
-
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.
|
|
1253
|
-
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`);
|
|
1452
|
+
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.state.key);
|
|
1453
|
+
const nodeEnter = node.enter().append('g').attr('class', 'markmap-node').attr('data-depth', d => d.data.depth).attr('data-path', d => d.data.state.path).attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`);
|
|
1254
1454
|
const nodeExit = this.transition(node.exit());
|
|
1255
|
-
nodeExit.select('
|
|
1455
|
+
nodeExit.select('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
|
|
1256
1456
|
nodeExit.select('foreignObject').style('opacity', 0);
|
|
1257
1457
|
nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
|
|
1258
1458
|
const nodeMerge = node.merge(nodeEnter);
|
|
1259
|
-
this.transition(nodeMerge).attr('transform', d => `translate(${d.y},${d.x - d.xSize / 2})`);
|
|
1260
|
-
|
|
1261
|
-
|
|
1459
|
+
this.transition(nodeMerge).attr('transform', d => `translate(${d.y},${d.x - d.xSize / 2})`); // Update lines under the content
|
|
1460
|
+
|
|
1461
|
+
const line = nodeMerge.selectAll(childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
|
|
1462
|
+
return enter.append('line').attr('x1', d => d.ySizeInner).attr('y1', d => d.xSize).attr('x2', d => d.ySizeInner).attr('y2', d => d.xSize);
|
|
1262
1463
|
}, update => update, exit => exit.remove());
|
|
1263
|
-
this.transition(
|
|
1264
|
-
|
|
1464
|
+
this.transition(line).attr('x1', -1).attr('x2', d => d.ySizeInner + 2).attr('stroke', d => color(d.data)).attr('stroke-width', linkWidth); // Circle to link to children of the node
|
|
1465
|
+
|
|
1466
|
+
const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
|
|
1265
1467
|
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', this.handleClick);
|
|
1266
1468
|
}, update => update, exit => exit.remove());
|
|
1267
1469
|
this.transition(circle).attr('r', 6).attr('stroke', d => color(d.data)).attr('fill', d => {
|
|
1268
|
-
var _d$data$
|
|
1470
|
+
var _d$data$payload;
|
|
1269
1471
|
|
|
1270
|
-
return (_d$data$
|
|
1472
|
+
return (_d$data$payload = d.data.payload) != null && _d$data$payload.fold && d.data.children ? color(d.data) : '#fff';
|
|
1271
1473
|
});
|
|
1272
|
-
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.
|
|
1273
|
-
const fo = enter.append('foreignObject').attr('class',
|
|
1474
|
+
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.state.key).join(enter => {
|
|
1475
|
+
const fo = enter.append('foreignObject').attr('class', 'markmap-foreign').attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize).on('mousedown', stopPropagation).on('dblclick', stopPropagation);
|
|
1274
1476
|
fo.append('xhtml:div').select(function select(d) {
|
|
1275
|
-
const
|
|
1276
|
-
this.replaceWith(
|
|
1277
|
-
return
|
|
1477
|
+
const clone = d.data.state.el.cloneNode(true);
|
|
1478
|
+
this.replaceWith(clone);
|
|
1479
|
+
return clone;
|
|
1278
1480
|
}).attr('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
1279
1481
|
return fo;
|
|
1280
1482
|
}, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2));
|
|
1281
1483
|
this.transition(foreignObject).style('opacity', 1); // Update the links
|
|
1282
1484
|
|
|
1283
|
-
const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.
|
|
1485
|
+
const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
|
|
1284
1486
|
const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
|
|
1285
|
-
return enter.insert('path', 'g').attr('d', linkShape({
|
|
1487
|
+
return enter.insert('path', 'g').attr('class', 'markmap-link').attr('data-depth', d => d.target.data.depth).attr('data-path', d => d.target.data.state.path).attr('d', linkShape({
|
|
1286
1488
|
source,
|
|
1287
1489
|
target: source
|
|
1288
1490
|
}));
|
|
@@ -1302,8 +1504,8 @@ ${this.getStyleContent()}
|
|
|
1302
1504
|
});
|
|
1303
1505
|
});
|
|
1304
1506
|
descendants.forEach(d => {
|
|
1305
|
-
d.data.
|
|
1306
|
-
d.data.
|
|
1507
|
+
d.data.state.x0 = d.x;
|
|
1508
|
+
d.data.state.y0 = d.y;
|
|
1307
1509
|
});
|
|
1308
1510
|
}
|
|
1309
1511
|
|
|
@@ -1360,7 +1562,7 @@ ${this.getStyleContent()}
|
|
|
1360
1562
|
const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
|
|
1361
1563
|
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y); // Skip if the node includes or is included in the container.
|
|
1362
1564
|
|
|
1363
|
-
const pd = _extends
|
|
1565
|
+
const pd = _extends({
|
|
1364
1566
|
left: 0,
|
|
1365
1567
|
right: 0,
|
|
1366
1568
|
top: 0,
|
|
@@ -1396,7 +1598,8 @@ ${this.getStyleContent()}
|
|
|
1396
1598
|
}
|
|
1397
1599
|
|
|
1398
1600
|
destroy() {
|
|
1399
|
-
this.svg.
|
|
1601
|
+
this.svg.on('.zoom', null);
|
|
1602
|
+
this.svg.html(null);
|
|
1400
1603
|
this.revokers.forEach(fn => {
|
|
1401
1604
|
fn();
|
|
1402
1605
|
});
|
|
@@ -1415,18 +1618,55 @@ ${this.getStyleContent()}
|
|
|
1415
1618
|
|
|
1416
1619
|
}
|
|
1417
1620
|
Markmap.defaultOptions = {
|
|
1621
|
+
autoFit: false,
|
|
1622
|
+
color: node => defaultColorFn(`${node.state.id}`),
|
|
1418
1623
|
duration: 500,
|
|
1419
|
-
|
|
1624
|
+
embedGlobalCSS: true,
|
|
1625
|
+
fitRatio: 0.95,
|
|
1626
|
+
maxWidth: 0,
|
|
1420
1627
|
nodeMinHeight: 16,
|
|
1421
|
-
|
|
1628
|
+
paddingX: 8,
|
|
1629
|
+
scrollForPan: isMacintosh,
|
|
1422
1630
|
spacingHorizontal: 80,
|
|
1423
|
-
|
|
1424
|
-
fitRatio: 0.95,
|
|
1425
|
-
color: (colorFn => node => colorFn(node.p.i))(d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10)),
|
|
1426
|
-
paddingX: 8
|
|
1631
|
+
spacingVertical: 5
|
|
1427
1632
|
};
|
|
1633
|
+
function deriveOptions(jsonOptions) {
|
|
1634
|
+
const {
|
|
1635
|
+
color,
|
|
1636
|
+
duration,
|
|
1637
|
+
maxWidth
|
|
1638
|
+
} = jsonOptions || {};
|
|
1639
|
+
let opts;
|
|
1640
|
+
|
|
1641
|
+
if (typeof color === 'string') {
|
|
1642
|
+
opts = _extends({}, opts, {
|
|
1643
|
+
color: () => color
|
|
1644
|
+
});
|
|
1645
|
+
} else if (color != null && color.length) {
|
|
1646
|
+
opts = _extends({}, opts, {
|
|
1647
|
+
color: node => color[node.state.id % color.length]
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
if (typeof duration === 'number') {
|
|
1652
|
+
opts = _extends({}, opts, {
|
|
1653
|
+
duration
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
if (typeof maxWidth === 'number') {
|
|
1658
|
+
opts = _extends({}, opts, {
|
|
1659
|
+
maxWidth
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
return opts;
|
|
1664
|
+
}
|
|
1428
1665
|
|
|
1429
1666
|
exports.Markmap = Markmap;
|
|
1667
|
+
exports.defaultColorFn = defaultColorFn;
|
|
1668
|
+
exports.deriveOptions = deriveOptions;
|
|
1669
|
+
exports.globalCSS = globalCSS;
|
|
1430
1670
|
exports.loadCSS = loadCSS;
|
|
1431
1671
|
exports.loadJS = loadJS;
|
|
1432
1672
|
exports.refreshHook = refreshHook;
|