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