markmap-view 0.15.0-alpha.0 → 0.15.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.js CHANGED
@@ -1,21 +1,7 @@
1
- /*! markmap-view v0.15.0-alpha.0 | MIT License */
2
- 'use strict';
3
-
4
- var markmapCommon = require('markmap-common');
5
- var d3 = require('d3');
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- for (var k in e) {
11
- n[k] = e[k];
12
- }
13
- }
14
- n.default = e;
15
- return Object.freeze(n);
16
- }
17
-
18
- var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
1
+ /*! markmap-view v0.15.0 | MIT License */
2
+ import { Hook, getId, addClass, walkTree, childSelector, noop } from 'markmap-common';
3
+ export { loadCSS, loadJS } from 'markmap-common';
4
+ import { scaleOrdinal, schemeCategory10, zoomTransform, select, zoom, linkHorizontal, min, max, zoomIdentity, minIndex } from 'd3';
19
5
 
20
6
  function _extends() {
21
7
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -242,8 +228,87 @@ Node$1.prototype = hierarchy.prototype = {
242
228
  copy: node_copy
243
229
  };
244
230
 
245
- var version = "2.1.1";
231
+ var name = "d3-flextree";
232
+ var version$1 = "2.1.2";
233
+ var main = "build/d3-flextree.js";
234
+ var module = "index";
235
+ var author = {
236
+ name: "Chris Maloney",
237
+ url: "http://chrismaloney.org"
238
+ };
239
+ var description = "Flexible tree layout algorithm that allows for variable node sizes.";
240
+ var keywords = [
241
+ "d3",
242
+ "d3-module",
243
+ "layout",
244
+ "tree",
245
+ "hierarchy",
246
+ "d3-hierarchy",
247
+ "plugin",
248
+ "d3-plugin",
249
+ "infovis",
250
+ "visualization",
251
+ "2d"
252
+ ];
253
+ var homepage = "https://github.com/klortho/d3-flextree";
254
+ var license = "WTFPL";
255
+ var repository = {
256
+ type: "git",
257
+ url: "https://github.com/klortho/d3-flextree.git"
258
+ };
259
+ var scripts = {
260
+ clean: "rm -rf build demo test",
261
+ "build:demo": "rollup -c --environment BUILD:demo",
262
+ "build:dev": "rollup -c --environment BUILD:dev",
263
+ "build:prod": "rollup -c --environment BUILD:prod",
264
+ "build:test": "rollup -c --environment BUILD:test",
265
+ build: "rollup -c",
266
+ lint: "eslint index.js src",
267
+ "test:main": "node test/bundle.js",
268
+ "test:browser": "node test/browser-tests.js",
269
+ test: "npm-run-all test:*",
270
+ prepare: "npm-run-all clean build lint test"
271
+ };
272
+ var dependencies = {
273
+ "d3-hierarchy": "^1.1.5"
274
+ };
275
+ var devDependencies = {
276
+ "babel-plugin-external-helpers": "^6.22.0",
277
+ "babel-preset-es2015-rollup": "^3.0.0",
278
+ d3: "^4.13.0",
279
+ "d3-selection-multi": "^1.0.1",
280
+ eslint: "^4.19.1",
281
+ jsdom: "^11.6.2",
282
+ "npm-run-all": "^4.1.2",
283
+ rollup: "^0.55.3",
284
+ "rollup-plugin-babel": "^2.7.1",
285
+ "rollup-plugin-commonjs": "^8.0.2",
286
+ "rollup-plugin-copy": "^0.2.3",
287
+ "rollup-plugin-json": "^2.3.0",
288
+ "rollup-plugin-node-resolve": "^3.0.2",
289
+ "rollup-plugin-uglify": "^3.0.0",
290
+ "uglify-es": "^3.3.9"
291
+ };
292
+ var packageInfo = {
293
+ name: name,
294
+ version: version$1,
295
+ main: main,
296
+ module: module,
297
+ "jsnext:main": "index",
298
+ author: author,
299
+ description: description,
300
+ keywords: keywords,
301
+ homepage: homepage,
302
+ license: license,
303
+ repository: repository,
304
+ scripts: scripts,
305
+ dependencies: dependencies,
306
+ devDependencies: devDependencies
307
+ };
246
308
 
309
+ const {
310
+ version
311
+ } = packageInfo;
247
312
  const defaults = Object.freeze({
248
313
  children: data => data.children,
249
314
  nodeSize: node => node.data.size,
@@ -617,60 +682,47 @@ const updateLows = (lowY, index, lastLows) => {
617
682
  };
618
683
  };
619
684
 
620
- /*! @gera2ld/jsx-dom v2.1.1 | ISC License */
621
- var VTYPE_ELEMENT = 1;
622
- var VTYPE_FUNCTION = 2;
623
- var MOUNT_SINGLE = 1;
624
- var MOUNT_ARRAY = 4;
625
- var SVG_NS = 'http://www.w3.org/2000/svg';
626
- var XLINK_NS = 'http://www.w3.org/1999/xlink';
627
- var NS_ATTRS = {
685
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
686
+ const VTYPE_ELEMENT = 1;
687
+ const VTYPE_FUNCTION = 2;
688
+ const SVG_NS = 'http://www.w3.org/2000/svg';
689
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
690
+ const NS_ATTRS = {
628
691
  show: XLINK_NS,
629
692
  actuate: XLINK_NS,
630
693
  href: XLINK_NS
631
694
  };
632
- var isLeaf = function isLeaf(c) {
633
- return typeof c === 'string' || typeof c === 'number';
634
- };
635
- var isElement = function isElement(c) {
636
- return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
637
- };
638
- var isRenderFunction = function isRenderFunction(c) {
639
- return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
640
- };
695
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
696
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
697
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
641
698
  function jsx(type, props) {
642
- var vtype;
699
+ let vtype;
643
700
  if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
644
701
  return {
645
- vtype: vtype,
646
- type: type,
647
- props: props
702
+ vtype,
703
+ type,
704
+ props
648
705
  };
649
706
  }
650
707
  function Fragment(props) {
651
708
  return props.children;
652
709
  }
653
- var DEFAULT_ENV = {
710
+ const DEFAULT_ENV = {
654
711
  isSvg: false
655
712
  };
656
- function insertDom(parent, ref) {
657
- if (ref.type === MOUNT_SINGLE) {
658
- if (ref.node != null) parent.append(ref.node);
659
- } else if (ref.type === MOUNT_ARRAY) {
660
- ref.children.forEach(function (ch) {
661
- insertDom(parent, ch);
662
- });
663
- } else {
664
- throw new Error("Unkown ref type " + JSON.stringify(ref));
665
- }
713
+ function insertDom(parent, nodes) {
714
+ if (!Array.isArray(nodes)) nodes = [nodes];
715
+ nodes = nodes.filter(Boolean);
716
+ if (nodes.length) parent.append(...nodes);
666
717
  }
667
718
  function mountAttributes(domElement, props, env) {
668
- for (var key in props) {
719
+ for (const key in props) {
669
720
  if (key === 'key' || key === 'children' || key === 'ref') continue;
670
721
  if (key === 'dangerouslySetInnerHTML') {
671
722
  domElement.innerHTML = props[key].__html;
672
- } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
673
- domElement[key] = props[key];
723
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
724
+ const value = props[key];
725
+ if (value != null) domElement[key] = value;
674
726
  } else if (key.startsWith('on')) {
675
727
  domElement[key.toLowerCase()] = props[key];
676
728
  } else {
@@ -678,7 +730,7 @@ function mountAttributes(domElement, props, env) {
678
730
  }
679
731
  }
680
732
  }
681
- var attrMap = {
733
+ const attrMap = {
682
734
  className: 'class',
683
735
  labelFor: 'for'
684
736
  };
@@ -689,7 +741,7 @@ function setDOMAttribute(el, attr, value, isSVG) {
689
741
  } else if (value === false) {
690
742
  el.removeAttribute(attr);
691
743
  } else {
692
- var namespace = isSVG ? NS_ATTRS[attr] : undefined;
744
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
693
745
  if (namespace !== undefined) {
694
746
  el.setAttributeNS(namespace, attr, value);
695
747
  } else {
@@ -697,116 +749,82 @@ function setDOMAttribute(el, attr, value, isSVG) {
697
749
  }
698
750
  }
699
751
  }
700
- function mount(vnode, env) {
701
- if (env === void 0) {
702
- env = DEFAULT_ENV;
703
- }
752
+ function flatten(arr) {
753
+ return arr.reduce((prev, item) => prev.concat(item), []);
754
+ }
755
+ function mountChildren(children, env) {
756
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
757
+ }
758
+ function mount(vnode, env = DEFAULT_ENV) {
704
759
  if (vnode == null || typeof vnode === 'boolean') {
705
- return {
706
- type: MOUNT_SINGLE,
707
- node: null
708
- };
760
+ return null;
709
761
  }
710
762
  if (vnode instanceof Node) {
711
- return {
712
- type: MOUNT_SINGLE,
713
- node: vnode
714
- };
763
+ return vnode;
715
764
  }
716
765
  if (isRenderFunction(vnode)) {
717
- var _ref = vnode,
718
- type = _ref.type,
719
- props = _ref.props;
766
+ const {
767
+ type,
768
+ props
769
+ } = vnode;
720
770
  if (type === Fragment) {
721
- var node = document.createDocumentFragment();
771
+ const node = document.createDocumentFragment();
722
772
  if (props.children) {
723
- var childrenRef = mount(props.children, env);
724
- insertDom(node, childrenRef);
773
+ const children = mountChildren(props.children, env);
774
+ insertDom(node, children);
725
775
  }
726
- return {
727
- type: MOUNT_SINGLE,
728
- node: node
729
- };
776
+ return node;
730
777
  }
731
- var childVNode = type(props);
778
+ const childVNode = type(props);
732
779
  return mount(childVNode, env);
733
780
  }
734
781
  if (isLeaf(vnode)) {
735
- return {
736
- type: MOUNT_SINGLE,
737
- node: document.createTextNode("" + vnode)
738
- };
782
+ return document.createTextNode(`${vnode}`);
739
783
  }
740
784
  if (isElement(vnode)) {
741
- var _node;
742
- var _ref2 = vnode,
743
- _type = _ref2.type,
744
- _props = _ref2.props;
745
- if (!env.isSvg && _type === 'svg') {
785
+ let node;
786
+ const {
787
+ type,
788
+ props
789
+ } = vnode;
790
+ if (!env.isSvg && type === 'svg') {
746
791
  env = Object.assign({}, env, {
747
792
  isSvg: true
748
793
  });
749
794
  }
750
795
  if (!env.isSvg) {
751
- _node = document.createElement(_type);
796
+ node = document.createElement(type);
752
797
  } else {
753
- _node = document.createElementNS(SVG_NS, _type);
798
+ node = document.createElementNS(SVG_NS, type);
754
799
  }
755
- mountAttributes(_node, _props, env);
756
- var _childrenRef;
757
- if (_props.children) {
758
- var childEnv = env;
759
- if (env.isSvg && _type === 'foreignObject') {
800
+ mountAttributes(node, props, env);
801
+ if (props.children) {
802
+ let childEnv = env;
803
+ if (env.isSvg && type === 'foreignObject') {
760
804
  childEnv = Object.assign({}, childEnv, {
761
805
  isSvg: false
762
806
  });
763
807
  }
764
- _childrenRef = mount(_props.children, childEnv);
808
+ const children = mountChildren(props.children, childEnv);
809
+ if (children != null) insertDom(node, children);
765
810
  }
766
- if (_childrenRef != null) insertDom(_node, _childrenRef);
767
- var ref = _props.ref;
768
- if (typeof ref === 'function') ref(_node);
769
- return {
770
- type: MOUNT_SINGLE,
771
- node: _node
772
- };
773
- }
774
- if (Array.isArray(vnode)) {
775
- return {
776
- type: MOUNT_ARRAY,
777
- children: vnode.map(function (child) {
778
- return mount(child, env);
779
- })
780
- };
811
+ const {
812
+ ref
813
+ } = props;
814
+ if (typeof ref === 'function') ref(node);
815
+ return node;
781
816
  }
782
817
  throw new Error('mount: Invalid Vnode!');
783
818
  }
784
- function flattenWithoutNull(array) {
785
- var result = [];
786
- for (var i = 0; i < array.length; i += 1) {
787
- var item = array[i];
788
- if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
789
- }
790
- return result;
791
- }
792
- function asDom(result) {
793
- if (result.type === MOUNT_SINGLE) {
794
- return result.node;
795
- }
796
- return result.children.map(asDom);
797
- }
819
+
798
820
  /**
799
821
  * Mount vdom as real DOM nodes.
800
822
  */
801
-
802
823
  function mountDom(vnode) {
803
- if (Array.isArray(vnode)) {
804
- return flattenWithoutNull(vnode.map(mountDom));
805
- }
806
- return asDom(mount(vnode));
824
+ return mount(vnode);
807
825
  }
808
826
 
809
- 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:700}.markmap-foreign mark{background:#ffeaa7}.markmap-foreign pre,.markmap-foreign pre[class*=language-]{margin:0;padding:.2em .4em}";
827
+ 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);padding:.25em}.markmap-foreign pre{margin:0}.markmap-foreign pre>code{display:block}.markmap-foreign del{text-decoration:line-through}.markmap-foreign em{font-style:italic}.markmap-foreign strong{font-weight:700}.markmap-foreign mark{background:#ffeaa7}";
810
828
 
811
829
  var css_248z = ".markmap-container{height:0;left:-100px;overflow:hidden;position:absolute;top:-100px;width:0}.markmap-container>.markmap-foreign{display:inline-block}.markmap-container>.markmap-foreign>div:last-child{white-space:nowrap}";
812
830
 
@@ -815,15 +833,8 @@ function linkWidth(nodeData) {
815
833
  const data = nodeData.data;
816
834
  return Math.max(4 - 2 * data.depth, 1.5);
817
835
  }
818
- function adjustSpacing(tree, spacing) {
819
- markmapCommon.walkTree(tree, (d, next) => {
820
- d.ySizeInner = d.ySize - spacing;
821
- d.y += spacing;
822
- next();
823
- }, 'children');
824
- }
825
836
  function minBy(numbers, by) {
826
- const index = d3__namespace.minIndex(numbers, by);
837
+ const index = minIndex(numbers, by);
827
838
  return numbers[index];
828
839
  }
829
840
  function stopPropagation(e) {
@@ -831,26 +842,41 @@ function stopPropagation(e) {
831
842
  }
832
843
  function createViewHooks() {
833
844
  return {
834
- transformHtml: new markmapCommon.Hook()
845
+ transformHtml: new Hook()
835
846
  };
836
847
  }
837
848
 
838
849
  /**
839
850
  * A global hook to refresh all markmaps when called.
840
851
  */
841
- const refreshHook = new markmapCommon.Hook();
842
- const defaultColorFn = d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10);
852
+ const refreshHook = new Hook();
853
+ const defaultColorFn = scaleOrdinal(schemeCategory10);
843
854
  const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
844
855
  class Markmap {
845
856
  constructor(svg, opts) {
857
+ this.options = Markmap.defaultOptions;
846
858
  this.revokers = [];
847
- ['handleZoom', 'handleClick', 'handlePan'].forEach(key => {
848
- this[key] = this[key].bind(this);
849
- });
859
+ this.handleZoom = e => {
860
+ const {
861
+ transform
862
+ } = e;
863
+ this.g.attr('transform', transform);
864
+ };
865
+ this.handlePan = e => {
866
+ e.preventDefault();
867
+ const transform = zoomTransform(this.svg.node());
868
+ const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
869
+ this.svg.call(this.zoom.transform, newTransform);
870
+ };
871
+ this.handleClick = (e, d) => {
872
+ let recursive = this.options.toggleRecursively;
873
+ if (e.ctrlKey) recursive = !recursive;
874
+ this.toggleNode(d.data, recursive);
875
+ };
850
876
  this.viewHooks = createViewHooks();
851
- this.svg = svg.datum ? svg : d3__namespace.select(svg);
877
+ this.svg = svg.datum ? svg : select(svg);
852
878
  this.styleNode = this.svg.append('style');
853
- this.zoom = d3__namespace.zoom().filter(event => {
879
+ this.zoom = zoom().filter(event => {
854
880
  if (this.options.scrollForPan) {
855
881
  // Pan with wheels, zoom with ctrl+wheels
856
882
  if (event.type === 'wheel') return event.ctrlKey && !event.button;
@@ -859,7 +885,11 @@ class Markmap {
859
885
  }).on('zoom', this.handleZoom);
860
886
  this.setOptions(opts);
861
887
  this.state = {
862
- id: this.options.id || this.svg.attr('id') || markmapCommon.getId()
888
+ id: this.options.id || this.svg.attr('id') || getId(),
889
+ minX: 0,
890
+ maxX: 0,
891
+ minY: 0,
892
+ maxY: 0
863
893
  };
864
894
  this.g = this.svg.append('g');
865
895
  this.revokers.push(refreshHook.tap(() => {
@@ -877,28 +907,16 @@ class Markmap {
877
907
  return [this.options.embedGlobalCSS && css_248z$1, styleText].filter(Boolean).join('\n');
878
908
  }
879
909
  updateStyle() {
880
- this.svg.attr('class', markmapCommon.addClass(this.svg.attr('class'), 'markmap', this.state.id));
910
+ this.svg.attr('class', addClass(this.svg.attr('class'), 'markmap', this.state.id));
881
911
  const style = this.getStyleContent();
882
912
  this.styleNode.text(style);
883
913
  }
884
- handleZoom(e) {
885
- const {
886
- transform
887
- } = e;
888
- this.g.attr('transform', transform);
889
- }
890
- handlePan(e) {
891
- e.preventDefault();
892
- const transform = d3__namespace.zoomTransform(this.svg.node());
893
- const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
894
- this.svg.call(this.zoom.transform, newTransform);
895
- }
896
914
  toggleNode(data, recursive = false) {
897
915
  var _data$payload;
898
916
  const fold = (_data$payload = data.payload) != null && _data$payload.fold ? 0 : 1;
899
917
  if (recursive) {
900
918
  // recursively
901
- markmapCommon.walkTree(data, (item, next) => {
919
+ walkTree(data, (item, next) => {
902
920
  item.payload = _extends({}, item.payload, {
903
921
  fold
904
922
  });
@@ -912,9 +930,6 @@ class Markmap {
912
930
  }
913
931
  this.renderData(data);
914
932
  }
915
- handleClick(e, d) {
916
- this.toggleNode(d.data, e.ctrlKey);
917
- }
918
933
  initializeData(node) {
919
934
  let nodeId = 0;
920
935
  const {
@@ -935,7 +950,7 @@ class Markmap {
935
950
  document.body.append(container, style);
936
951
  const groupStyle = maxWidth ? `max-width: ${maxWidth}px` : '';
937
952
  let foldRecursively = 0;
938
- markmapCommon.walkTree(node, (item, next, parent) => {
953
+ walkTree(node, (item, next, parent) => {
939
954
  var _item$children, _parent$state, _item$payload;
940
955
  item.children = (_item$children = item.children) == null ? void 0 : _item$children.map(child => _extends({}, child));
941
956
  nodeId += 1;
@@ -974,14 +989,16 @@ class Markmap {
974
989
  // `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
975
990
  // content in one line as much as possible, and subjecting to the given max-width.
976
991
  nodes.forEach(node => {
977
- node.parentNode.append(node.cloneNode(true));
992
+ var _node$parentNode;
993
+ (_node$parentNode = node.parentNode) == null ? void 0 : _node$parentNode.append(node.cloneNode(true));
978
994
  });
979
- markmapCommon.walkTree(node, (item, next, parent) => {
995
+ walkTree(node, (item, next, parent) => {
980
996
  var _parent$state2;
981
- const rect = item.state.el.getBoundingClientRect();
982
- item.content = item.state.el.innerHTML;
983
- item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
984
- item.state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') +
997
+ const state = item.state;
998
+ const rect = state.el.getBoundingClientRect();
999
+ item.content = state.el.innerHTML;
1000
+ state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
1001
+ state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, state.id].filter(Boolean).join('.') +
985
1002
  // FIXME: find a way to check content hash
986
1003
  item.content;
987
1004
  next();
@@ -990,17 +1007,22 @@ class Markmap {
990
1007
  style.remove();
991
1008
  }
992
1009
  setOptions(opts) {
993
- this.options = _extends({}, Markmap.defaultOptions, opts);
1010
+ this.options = _extends({}, this.options, opts);
994
1011
  if (this.options.zoom) {
995
1012
  this.svg.call(this.zoom);
996
1013
  } else {
997
1014
  this.svg.on('.zoom', null);
998
1015
  }
999
- this.svg.on('wheel', this.options.pan ? this.handlePan : null);
1016
+ if (this.options.pan) {
1017
+ this.svg.on('wheel', this.handlePan);
1018
+ } else {
1019
+ this.svg.on('wheel', null);
1020
+ }
1000
1021
  }
1001
1022
  setData(data, opts) {
1002
- if (data) this.state.data = data;
1003
1023
  if (opts) this.setOptions(opts);
1024
+ if (data) this.state.data = data;
1025
+ if (!this.state.data) return;
1004
1026
  this.initializeData(this.state.data);
1005
1027
  this.updateStyle();
1006
1028
  this.renderData();
@@ -1015,25 +1037,24 @@ class Markmap {
1015
1037
  autoFit,
1016
1038
  color
1017
1039
  } = this.options;
1018
- const layout = flextree().children(d => {
1040
+ const layout = flextree({}).children(d => {
1019
1041
  var _d$payload;
1020
- return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
1021
- }).nodeSize(d => {
1022
- const [width, height] = d.data.state.size;
1042
+ if (!((_d$payload = d.payload) != null && _d$payload.fold)) return d.children;
1043
+ }).nodeSize(node => {
1044
+ const [width, height] = node.data.state.size;
1023
1045
  return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
1024
1046
  }).spacing((a, b) => {
1025
1047
  return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
1026
1048
  });
1027
1049
  const tree = layout.hierarchy(this.state.data);
1028
1050
  layout(tree);
1029
- adjustSpacing(tree, spacingHorizontal);
1030
1051
  const descendants = tree.descendants().reverse();
1031
1052
  const links = tree.links();
1032
- const linkShape = d3__namespace.linkHorizontal();
1033
- const minX = d3__namespace.min(descendants, d => d.x - d.xSize / 2);
1034
- const maxX = d3__namespace.max(descendants, d => d.x + d.xSize / 2);
1035
- const minY = d3__namespace.min(descendants, d => d.y);
1036
- const maxY = d3__namespace.max(descendants, d => d.y + d.ySizeInner);
1053
+ const linkShape = linkHorizontal();
1054
+ const minX = min(descendants, d => d.x - d.xSize / 2);
1055
+ const maxX = max(descendants, d => d.x + d.xSize / 2);
1056
+ const minY = min(descendants, d => d.y);
1057
+ const maxY = max(descendants, d => d.y + d.ySize - spacingHorizontal);
1037
1058
  Object.assign(this.state, {
1038
1059
  minX,
1039
1060
  maxX,
@@ -1046,12 +1067,12 @@ class Markmap {
1046
1067
  const y0 = (_origin$data$state$y = origin.data.state.y0) != null ? _origin$data$state$y : origin.y;
1047
1068
 
1048
1069
  // Update the nodes
1049
- const node = this.g.selectAll(markmapCommon.childSelector('g')).data(descendants, d => d.data.state.key);
1050
- const nodeEnter = node.enter().append('g').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})`);
1070
+ const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.state.key);
1071
+ const nodeEnter = node.enter().append('g').attr('data-depth', d => d.data.depth).attr('data-path', d => d.data.state.path).attr('transform', d => `translate(${y0 + origin.ySize - d.ySize},${x0 + origin.xSize / 2 - d.xSize})`);
1051
1072
  const nodeExit = this.transition(node.exit());
1052
- nodeExit.select('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1073
+ nodeExit.select('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1053
1074
  nodeExit.select('foreignObject').style('opacity', 0);
1054
- nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1075
+ nodeExit.attr('transform', d => `translate(${origin.y + origin.ySize - d.ySize},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1055
1076
  const nodeMerge = node.merge(nodeEnter).attr('class', d => {
1056
1077
  var _d$data$payload;
1057
1078
  return ['markmap-node', ((_d$data$payload = d.data.payload) == null ? void 0 : _d$data$payload.fold) && 'markmap-fold'].filter(Boolean).join(' ');
@@ -1059,20 +1080,23 @@ class Markmap {
1059
1080
  this.transition(nodeMerge).attr('transform', d => `translate(${d.y},${d.x - d.xSize / 2})`);
1060
1081
 
1061
1082
  // Update lines under the content
1062
- const line = nodeMerge.selectAll(markmapCommon.childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
1063
- return enter.append('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1083
+ const line = nodeMerge.selectAll(childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
1084
+ return enter.append('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1064
1085
  }, update => update, exit => exit.remove());
1065
- this.transition(line).attr('x1', -1).attr('x2', d => d.ySizeInner + 2).attr('y1', d => d.xSize).attr('y2', d => d.xSize).attr('stroke', d => color(d.data)).attr('stroke-width', linkWidth);
1086
+ this.transition(line).attr('x1', -1).attr('x2', d => d.ySize - spacingHorizontal + 2).attr('y1', d => d.xSize).attr('y2', d => d.xSize).attr('stroke', d => color(d.data)).attr('stroke-width', linkWidth);
1066
1087
 
1067
1088
  // Circle to link to children of the node
1068
- const circle = nodeMerge.selectAll(markmapCommon.childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
1069
- return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', (e, d) => this.handleClick(e, d)).on('mousedown', stopPropagation);
1089
+ const circle = nodeMerge.selectAll(childSelector('circle')).data(d => {
1090
+ var _d$data$children;
1091
+ return (_d$data$children = d.data.children) != null && _d$data$children.length ? [d] : [];
1092
+ }, d => d.data.state.key).join(enter => {
1093
+ return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySize - spacingHorizontal).attr('cy', d => d.xSize).attr('r', 0).on('click', (e, d) => this.handleClick(e, d)).on('mousedown', stopPropagation);
1070
1094
  }, update => update, exit => exit.remove());
1071
- this.transition(circle).attr('r', 6).attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('stroke', d => color(d.data)).attr('fill', d => {
1095
+ this.transition(circle).attr('r', 6).attr('cx', d => d.ySize - spacingHorizontal).attr('cy', d => d.xSize).attr('stroke', d => color(d.data)).attr('fill', d => {
1072
1096
  var _d$data$payload2;
1073
1097
  return (_d$data$payload2 = d.data.payload) != null && _d$data$payload2.fold && d.data.children ? color(d.data) : '#fff';
1074
1098
  });
1075
- const foreignObject = nodeMerge.selectAll(markmapCommon.childSelector('foreignObject')).data(d => [d], d => d.data.state.key).join(enter => {
1099
+ const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.state.key).join(enter => {
1076
1100
  const fo = enter.append('foreignObject').attr('class', 'markmap-foreign').attr('x', paddingX).attr('y', 0).style('opacity', 0).on('mousedown', stopPropagation).on('dblclick', stopPropagation);
1077
1101
  fo.append('xhtml:div').select(function select(d) {
1078
1102
  const clone = d.data.state.el.cloneNode(true);
@@ -1080,26 +1104,28 @@ class Markmap {
1080
1104
  return clone;
1081
1105
  }).attr('xmlns', 'http://www.w3.org/1999/xhtml');
1082
1106
  return fo;
1083
- }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2)).attr('height', d => d.xSize);
1107
+ }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySize - spacingHorizontal - paddingX * 2)).attr('height', d => d.xSize);
1084
1108
  this.transition(foreignObject).style('opacity', 1);
1085
1109
 
1086
1110
  // Update the links
1087
- const path = this.g.selectAll(markmapCommon.childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
1088
- const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
1111
+ const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
1112
+ const source = [y0 + origin.ySize - spacingHorizontal, x0 + origin.xSize / 2];
1089
1113
  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({
1090
1114
  source,
1091
1115
  target: source
1092
1116
  }));
1093
1117
  }, update => update, exit => {
1094
- const source = [origin.y + origin.ySizeInner, origin.x + origin.xSize / 2];
1118
+ const source = [origin.y + origin.ySize - spacingHorizontal, origin.x + origin.xSize / 2];
1095
1119
  return this.transition(exit).attr('d', linkShape({
1096
1120
  source,
1097
1121
  target: source
1098
1122
  })).remove();
1099
1123
  });
1100
1124
  this.transition(path).attr('stroke', d => color(d.target.data)).attr('stroke-width', d => linkWidth(d.target)).attr('d', d => {
1101
- const source = [d.source.y + d.source.ySizeInner, d.source.x + d.source.xSize / 2];
1102
- const target = [d.target.y, d.target.x + d.target.xSize / 2];
1125
+ const origSource = d.source;
1126
+ const origTarget = d.target;
1127
+ const source = [origSource.y + origSource.ySize - spacingHorizontal, origSource.x + origSource.xSize / 2];
1128
+ const target = [origTarget.y, origTarget.x + origTarget.xSize / 2];
1103
1129
  return linkShape({
1104
1130
  source,
1105
1131
  target
@@ -1138,8 +1164,8 @@ class Markmap {
1138
1164
  const naturalWidth = maxY - minY;
1139
1165
  const naturalHeight = maxX - minX;
1140
1166
  const scale = Math.min(offsetWidth / naturalWidth * fitRatio, offsetHeight / naturalHeight * fitRatio, 2);
1141
- const initialZoom = d3__namespace.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale);
1142
- return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(markmapCommon.noop);
1167
+ const initialZoom = zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale);
1168
+ return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop);
1143
1169
  }
1144
1170
 
1145
1171
  /**
@@ -1147,16 +1173,19 @@ class Markmap {
1147
1173
  */
1148
1174
  async ensureView(node, padding) {
1149
1175
  let itemData;
1150
- this.g.selectAll(markmapCommon.childSelector('g')).each(function walk(d) {
1176
+ this.g.selectAll(childSelector('g')).each(function walk(d) {
1151
1177
  if (d.data === node) {
1152
1178
  itemData = d;
1153
1179
  }
1154
1180
  });
1155
1181
  if (!itemData) return;
1156
1182
  const svgNode = this.svg.node();
1183
+ const {
1184
+ spacingHorizontal
1185
+ } = this.options;
1157
1186
  const relRect = svgNode.getBoundingClientRect();
1158
- const transform = d3__namespace.zoomTransform(svgNode);
1159
- const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
1187
+ const transform = zoomTransform(svgNode);
1188
+ const [left, right] = [itemData.y, itemData.y + itemData.ySize - spacingHorizontal + 2].map(x => x * transform.k + transform.x);
1160
1189
  const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
1161
1190
  // Skip if the node includes or is included in the container.
1162
1191
  const pd = _extends({
@@ -1171,7 +1200,7 @@ class Markmap {
1171
1200
  const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0;
1172
1201
  if (dx || dy) {
1173
1202
  const newTransform = transform.translate(dx, dy);
1174
- return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(markmapCommon.noop);
1203
+ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1175
1204
  }
1176
1205
  }
1177
1206
 
@@ -1186,9 +1215,9 @@ class Markmap {
1186
1215
  } = svgNode.getBoundingClientRect();
1187
1216
  const halfWidth = offsetWidth / 2;
1188
1217
  const halfHeight = offsetHeight / 2;
1189
- const transform = d3__namespace.zoomTransform(svgNode);
1218
+ const transform = zoomTransform(svgNode);
1190
1219
  const newTransform = transform.translate((halfWidth - transform.x) * (1 - scale) / transform.k, (halfHeight - transform.y) * (1 - scale) / transform.k).scale(scale);
1191
- return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(markmapCommon.noop);
1220
+ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop);
1192
1221
  }
1193
1222
  destroy() {
1194
1223
  this.svg.on('.zoom', null);
@@ -1197,7 +1226,7 @@ class Markmap {
1197
1226
  fn();
1198
1227
  });
1199
1228
  }
1200
- static create(svg, opts, data) {
1229
+ static create(svg, opts, data = null) {
1201
1230
  const mm = new Markmap(svg, opts);
1202
1231
  if (data) {
1203
1232
  mm.setData(data);
@@ -1209,7 +1238,10 @@ class Markmap {
1209
1238
  }
1210
1239
  Markmap.defaultOptions = {
1211
1240
  autoFit: false,
1212
- color: node => defaultColorFn(`${node.state.path}`),
1241
+ color: node => {
1242
+ var _node$state;
1243
+ return defaultColorFn(`${((_node$state = node.state) == null ? void 0 : _node$state.path) || ''}`);
1244
+ },
1213
1245
  duration: 500,
1214
1246
  embedGlobalCSS: true,
1215
1247
  fitRatio: 0.95,
@@ -1221,25 +1253,26 @@ Markmap.defaultOptions = {
1221
1253
  spacingVertical: 5,
1222
1254
  initialExpandLevel: -1,
1223
1255
  zoom: true,
1224
- pan: true
1256
+ pan: true,
1257
+ toggleRecursively: false
1225
1258
  };
1226
1259
  function deriveOptions(jsonOptions) {
1227
- const opts = {};
1228
- jsonOptions || (jsonOptions = {});
1260
+ const derivedOptions = {};
1261
+ const options = _extends({}, jsonOptions);
1229
1262
  const {
1230
1263
  color,
1231
1264
  colorFreezeLevel
1232
- } = jsonOptions;
1265
+ } = options;
1233
1266
  if ((color == null ? void 0 : color.length) === 1) {
1234
1267
  const solidColor = color[0];
1235
- opts.color = () => solidColor;
1268
+ derivedOptions.color = () => solidColor;
1236
1269
  } else if (color != null && color.length) {
1237
- const colorFn = d3__namespace.scaleOrdinal(color);
1238
- opts.color = node => colorFn(`${node.state.path}`);
1270
+ const colorFn = scaleOrdinal(color);
1271
+ derivedOptions.color = node => colorFn(`${node.state.path}`);
1239
1272
  }
1240
1273
  if (colorFreezeLevel) {
1241
- const color = opts.color || Markmap.defaultOptions.color;
1242
- opts.color = node => {
1274
+ const color = derivedOptions.color || Markmap.defaultOptions.color;
1275
+ derivedOptions.color = node => {
1243
1276
  node = _extends({}, node, {
1244
1277
  state: _extends({}, node.state, {
1245
1278
  path: node.state.path.split('.').slice(0, colorFreezeLevel).join('.')
@@ -1250,21 +1283,15 @@ function deriveOptions(jsonOptions) {
1250
1283
  }
1251
1284
  const numberKeys = ['duration', 'maxWidth', 'initialExpandLevel'];
1252
1285
  numberKeys.forEach(key => {
1253
- const value = jsonOptions[key];
1254
- if (typeof value === 'number') opts[key] = value;
1286
+ const value = options[key];
1287
+ if (typeof value === 'number') derivedOptions[key] = value;
1255
1288
  });
1256
1289
  const booleanKeys = ['zoom', 'pan'];
1257
1290
  booleanKeys.forEach(key => {
1258
- const value = jsonOptions[key];
1259
- if (value != null) opts[key] = !!value;
1291
+ const value = options[key];
1292
+ if (value != null) derivedOptions[key] = !!value;
1260
1293
  });
1261
- return opts;
1294
+ return derivedOptions;
1262
1295
  }
1263
1296
 
1264
- exports.loadCSS = markmapCommon.loadCSS;
1265
- exports.loadJS = markmapCommon.loadJS;
1266
- exports.Markmap = Markmap;
1267
- exports.defaultColorFn = defaultColorFn;
1268
- exports.deriveOptions = deriveOptions;
1269
- exports.globalCSS = globalCSS;
1270
- exports.refreshHook = refreshHook;
1297
+ export { Markmap, defaultColorFn, deriveOptions, globalCSS, refreshHook };