markmap-view 0.14.5-alpha.13 → 0.14.5-alpha.16

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,4 +1,4 @@
1
- /*! markmap-view v0.14.5-alpha.13+50ca560 | MIT License */
1
+ /*! markmap-view v0.14.5-alpha.16+33e8294 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var markmapCommon = require('markmap-common');
@@ -617,60 +617,47 @@ const updateLows = (lowY, index, lastLows) => {
617
617
  };
618
618
  };
619
619
 
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 = {
620
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
621
+ const VTYPE_ELEMENT = 1;
622
+ const VTYPE_FUNCTION = 2;
623
+ const SVG_NS = 'http://www.w3.org/2000/svg';
624
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
625
+ const NS_ATTRS = {
628
626
  show: XLINK_NS,
629
627
  actuate: XLINK_NS,
630
628
  href: XLINK_NS
631
629
  };
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
- };
630
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
631
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
632
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
641
633
  function jsx(type, props) {
642
- var vtype;
634
+ let vtype;
643
635
  if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
644
636
  return {
645
- vtype: vtype,
646
- type: type,
647
- props: props
637
+ vtype,
638
+ type,
639
+ props
648
640
  };
649
641
  }
650
642
  function Fragment(props) {
651
643
  return props.children;
652
644
  }
653
- var DEFAULT_ENV = {
645
+ const DEFAULT_ENV = {
654
646
  isSvg: false
655
647
  };
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
- }
648
+ function insertDom(parent, nodes) {
649
+ if (!Array.isArray(nodes)) nodes = [nodes];
650
+ nodes = nodes.filter(Boolean);
651
+ if (nodes.length) parent.append(...nodes);
666
652
  }
667
653
  function mountAttributes(domElement, props, env) {
668
- for (var key in props) {
654
+ for (const key in props) {
669
655
  if (key === 'key' || key === 'children' || key === 'ref') continue;
670
656
  if (key === 'dangerouslySetInnerHTML') {
671
657
  domElement.innerHTML = props[key].__html;
672
- } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
673
- domElement[key] = props[key];
658
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
659
+ const value = props[key];
660
+ if (value != null) domElement[key] = value;
674
661
  } else if (key.startsWith('on')) {
675
662
  domElement[key.toLowerCase()] = props[key];
676
663
  } else {
@@ -678,7 +665,7 @@ function mountAttributes(domElement, props, env) {
678
665
  }
679
666
  }
680
667
  }
681
- var attrMap = {
668
+ const attrMap = {
682
669
  className: 'class',
683
670
  labelFor: 'for'
684
671
  };
@@ -689,7 +676,7 @@ function setDOMAttribute(el, attr, value, isSVG) {
689
676
  } else if (value === false) {
690
677
  el.removeAttribute(attr);
691
678
  } else {
692
- var namespace = isSVG ? NS_ATTRS[attr] : undefined;
679
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
693
680
  if (namespace !== undefined) {
694
681
  el.setAttributeNS(namespace, attr, value);
695
682
  } else {
@@ -697,113 +684,79 @@ function setDOMAttribute(el, attr, value, isSVG) {
697
684
  }
698
685
  }
699
686
  }
700
- function mount(vnode, env) {
701
- if (env === void 0) {
702
- env = DEFAULT_ENV;
703
- }
687
+ function flatten(arr) {
688
+ return arr.reduce((prev, item) => prev.concat(item), []);
689
+ }
690
+ function mountChildren(children, env) {
691
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
692
+ }
693
+ function mount(vnode, env = DEFAULT_ENV) {
704
694
  if (vnode == null || typeof vnode === 'boolean') {
705
- return {
706
- type: MOUNT_SINGLE,
707
- node: null
708
- };
695
+ return null;
709
696
  }
710
697
  if (vnode instanceof Node) {
711
- return {
712
- type: MOUNT_SINGLE,
713
- node: vnode
714
- };
698
+ return vnode;
715
699
  }
716
700
  if (isRenderFunction(vnode)) {
717
- var _ref = vnode,
718
- type = _ref.type,
719
- props = _ref.props;
701
+ const {
702
+ type,
703
+ props
704
+ } = vnode;
720
705
  if (type === Fragment) {
721
- var node = document.createDocumentFragment();
706
+ const node = document.createDocumentFragment();
722
707
  if (props.children) {
723
- var childrenRef = mount(props.children, env);
724
- insertDom(node, childrenRef);
708
+ const children = mountChildren(props.children, env);
709
+ insertDom(node, children);
725
710
  }
726
- return {
727
- type: MOUNT_SINGLE,
728
- node: node
729
- };
711
+ return node;
730
712
  }
731
- var childVNode = type(props);
713
+ const childVNode = type(props);
732
714
  return mount(childVNode, env);
733
715
  }
734
716
  if (isLeaf(vnode)) {
735
- return {
736
- type: MOUNT_SINGLE,
737
- node: document.createTextNode("" + vnode)
738
- };
717
+ return document.createTextNode(`${vnode}`);
739
718
  }
740
719
  if (isElement(vnode)) {
741
- var _node;
742
- var _ref2 = vnode,
743
- _type = _ref2.type,
744
- _props = _ref2.props;
745
- if (!env.isSvg && _type === 'svg') {
720
+ let node;
721
+ const {
722
+ type,
723
+ props
724
+ } = vnode;
725
+ if (!env.isSvg && type === 'svg') {
746
726
  env = Object.assign({}, env, {
747
727
  isSvg: true
748
728
  });
749
729
  }
750
730
  if (!env.isSvg) {
751
- _node = document.createElement(_type);
731
+ node = document.createElement(type);
752
732
  } else {
753
- _node = document.createElementNS(SVG_NS, _type);
733
+ node = document.createElementNS(SVG_NS, type);
754
734
  }
755
- mountAttributes(_node, _props, env);
756
- var _childrenRef;
757
- if (_props.children) {
758
- var childEnv = env;
759
- if (env.isSvg && _type === 'foreignObject') {
735
+ mountAttributes(node, props, env);
736
+ if (props.children) {
737
+ let childEnv = env;
738
+ if (env.isSvg && type === 'foreignObject') {
760
739
  childEnv = Object.assign({}, childEnv, {
761
740
  isSvg: false
762
741
  });
763
742
  }
764
- _childrenRef = mount(_props.children, childEnv);
743
+ const children = mountChildren(props.children, childEnv);
744
+ if (children != null) insertDom(node, children);
765
745
  }
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
- };
746
+ const {
747
+ ref
748
+ } = props;
749
+ if (typeof ref === 'function') ref(node);
750
+ return node;
781
751
  }
782
752
  throw new Error('mount: Invalid Vnode!');
783
753
  }
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
- }
754
+
798
755
  /**
799
756
  * Mount vdom as real DOM nodes.
800
757
  */
801
-
802
758
  function mountDom(vnode) {
803
- if (Array.isArray(vnode)) {
804
- return flattenWithoutNull(vnode.map(mountDom));
805
- }
806
- return asDom(mount(vnode));
759
+ return mount(vnode);
807
760
  }
808
761
 
809
762
  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}";
@@ -815,13 +768,6 @@ function linkWidth(nodeData) {
815
768
  const data = nodeData.data;
816
769
  return Math.max(4 - 2 * data.depth, 1.5);
817
770
  }
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
771
  function minBy(numbers, by) {
826
772
  const index = d3__namespace.minIndex(numbers, by);
827
773
  return numbers[index];
@@ -843,10 +789,25 @@ const defaultColorFn = d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10
843
789
  const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
844
790
  class Markmap {
845
791
  constructor(svg, opts) {
792
+ this.options = Markmap.defaultOptions;
846
793
  this.revokers = [];
847
- ['handleZoom', 'handleClick', 'handlePan'].forEach(key => {
848
- this[key] = this[key].bind(this);
849
- });
794
+ this.handleZoom = e => {
795
+ const {
796
+ transform
797
+ } = e;
798
+ this.g.attr('transform', transform);
799
+ };
800
+ this.handlePan = e => {
801
+ e.preventDefault();
802
+ const transform = d3__namespace.zoomTransform(this.svg.node());
803
+ const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
804
+ this.svg.call(this.zoom.transform, newTransform);
805
+ };
806
+ this.handleClick = (e, d) => {
807
+ let recursive = this.options.toggleRecursively;
808
+ if (e.ctrlKey) recursive = !recursive;
809
+ this.toggleNode(d.data, recursive);
810
+ };
850
811
  this.viewHooks = createViewHooks();
851
812
  this.svg = svg.datum ? svg : d3__namespace.select(svg);
852
813
  this.styleNode = this.svg.append('style');
@@ -859,7 +820,11 @@ class Markmap {
859
820
  }).on('zoom', this.handleZoom);
860
821
  this.setOptions(opts);
861
822
  this.state = {
862
- id: this.options.id || this.svg.attr('id') || markmapCommon.getId()
823
+ id: this.options.id || this.svg.attr('id') || markmapCommon.getId(),
824
+ minX: 0,
825
+ maxX: 0,
826
+ minY: 0,
827
+ maxY: 0
863
828
  };
864
829
  this.g = this.svg.append('g');
865
830
  this.revokers.push(refreshHook.tap(() => {
@@ -881,18 +846,6 @@ class Markmap {
881
846
  const style = this.getStyleContent();
882
847
  this.styleNode.text(style);
883
848
  }
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
849
  toggleNode(data, recursive = false) {
897
850
  var _data$payload;
898
851
  const fold = (_data$payload = data.payload) != null && _data$payload.fold ? 0 : 1;
@@ -912,11 +865,6 @@ class Markmap {
912
865
  }
913
866
  this.renderData(data);
914
867
  }
915
- handleClick(e, d) {
916
- let recursive = this.options.toggleRecursively;
917
- if (e.ctrlKey) recursive = !recursive;
918
- this.toggleNode(d.data, recursive);
919
- }
920
868
  initializeData(node) {
921
869
  let nodeId = 0;
922
870
  const {
@@ -976,14 +924,16 @@ class Markmap {
976
924
  // `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
977
925
  // content in one line as much as possible, and subjecting to the given max-width.
978
926
  nodes.forEach(node => {
979
- node.parentNode.append(node.cloneNode(true));
927
+ var _node$parentNode;
928
+ (_node$parentNode = node.parentNode) == null ? void 0 : _node$parentNode.append(node.cloneNode(true));
980
929
  });
981
930
  markmapCommon.walkTree(node, (item, next, parent) => {
982
931
  var _parent$state2;
983
- const rect = item.state.el.getBoundingClientRect();
984
- item.content = item.state.el.innerHTML;
985
- item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
986
- item.state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') +
932
+ const state = item.state;
933
+ const rect = state.el.getBoundingClientRect();
934
+ item.content = state.el.innerHTML;
935
+ state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
936
+ state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, state.id].filter(Boolean).join('.') +
987
937
  // FIXME: find a way to check content hash
988
938
  item.content;
989
939
  next();
@@ -998,11 +948,16 @@ class Markmap {
998
948
  } else {
999
949
  this.svg.on('.zoom', null);
1000
950
  }
1001
- this.svg.on('wheel', this.options.pan ? this.handlePan : null);
951
+ if (this.options.pan) {
952
+ this.svg.on('wheel', this.handlePan);
953
+ } else {
954
+ this.svg.on('wheel', null);
955
+ }
1002
956
  }
1003
957
  setData(data, opts) {
1004
- if (data) this.state.data = data;
1005
958
  if (opts) this.setOptions(opts);
959
+ if (data) this.state.data = data;
960
+ if (!this.state.data) return;
1006
961
  this.initializeData(this.state.data);
1007
962
  this.updateStyle();
1008
963
  this.renderData();
@@ -1017,25 +972,24 @@ class Markmap {
1017
972
  autoFit,
1018
973
  color
1019
974
  } = this.options;
1020
- const layout = flextree().children(d => {
975
+ const layout = flextree({}).children(d => {
1021
976
  var _d$payload;
1022
- return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
1023
- }).nodeSize(d => {
1024
- const [width, height] = d.data.state.size;
977
+ if (!((_d$payload = d.payload) != null && _d$payload.fold)) return d.children;
978
+ }).nodeSize(node => {
979
+ const [width, height] = node.data.state.size;
1025
980
  return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
1026
981
  }).spacing((a, b) => {
1027
982
  return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
1028
983
  });
1029
984
  const tree = layout.hierarchy(this.state.data);
1030
985
  layout(tree);
1031
- adjustSpacing(tree, spacingHorizontal);
1032
986
  const descendants = tree.descendants().reverse();
1033
987
  const links = tree.links();
1034
988
  const linkShape = d3__namespace.linkHorizontal();
1035
989
  const minX = d3__namespace.min(descendants, d => d.x - d.xSize / 2);
1036
990
  const maxX = d3__namespace.max(descendants, d => d.x + d.xSize / 2);
1037
991
  const minY = d3__namespace.min(descendants, d => d.y);
1038
- const maxY = d3__namespace.max(descendants, d => d.y + d.ySizeInner);
992
+ const maxY = d3__namespace.max(descendants, d => d.y + d.ySize - spacingHorizontal);
1039
993
  Object.assign(this.state, {
1040
994
  minX,
1041
995
  maxX,
@@ -1049,11 +1003,11 @@ class Markmap {
1049
1003
 
1050
1004
  // Update the nodes
1051
1005
  const node = this.g.selectAll(markmapCommon.childSelector('g')).data(descendants, d => d.data.state.key);
1052
- 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})`);
1006
+ 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})`);
1053
1007
  const nodeExit = this.transition(node.exit());
1054
- nodeExit.select('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1008
+ nodeExit.select('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1055
1009
  nodeExit.select('foreignObject').style('opacity', 0);
1056
- nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1010
+ nodeExit.attr('transform', d => `translate(${origin.y + origin.ySize - d.ySize},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1057
1011
  const nodeMerge = node.merge(nodeEnter).attr('class', d => {
1058
1012
  var _d$data$payload;
1059
1013
  return ['markmap-node', ((_d$data$payload = d.data.payload) == null ? void 0 : _d$data$payload.fold) && 'markmap-fold'].filter(Boolean).join(' ');
@@ -1062,15 +1016,18 @@ class Markmap {
1062
1016
 
1063
1017
  // Update lines under the content
1064
1018
  const line = nodeMerge.selectAll(markmapCommon.childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
1065
- return enter.append('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1019
+ return enter.append('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1066
1020
  }, update => update, exit => exit.remove());
1067
- 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);
1021
+ 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);
1068
1022
 
1069
1023
  // Circle to link to children of the node
1070
- const circle = nodeMerge.selectAll(markmapCommon.childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
1071
- 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);
1024
+ const circle = nodeMerge.selectAll(markmapCommon.childSelector('circle')).data(d => {
1025
+ var _d$data$children;
1026
+ return (_d$data$children = d.data.children) != null && _d$data$children.length ? [d] : [];
1027
+ }, d => d.data.state.key).join(enter => {
1028
+ 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);
1072
1029
  }, update => update, exit => exit.remove());
1073
- 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 => {
1030
+ 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 => {
1074
1031
  var _d$data$payload2;
1075
1032
  return (_d$data$payload2 = d.data.payload) != null && _d$data$payload2.fold && d.data.children ? color(d.data) : '#fff';
1076
1033
  });
@@ -1082,26 +1039,28 @@ class Markmap {
1082
1039
  return clone;
1083
1040
  }).attr('xmlns', 'http://www.w3.org/1999/xhtml');
1084
1041
  return fo;
1085
- }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2)).attr('height', d => d.xSize);
1042
+ }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySize - spacingHorizontal - paddingX * 2)).attr('height', d => d.xSize);
1086
1043
  this.transition(foreignObject).style('opacity', 1);
1087
1044
 
1088
1045
  // Update the links
1089
1046
  const path = this.g.selectAll(markmapCommon.childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
1090
- const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
1047
+ const source = [y0 + origin.ySize - spacingHorizontal, x0 + origin.xSize / 2];
1091
1048
  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({
1092
1049
  source,
1093
1050
  target: source
1094
1051
  }));
1095
1052
  }, update => update, exit => {
1096
- const source = [origin.y + origin.ySizeInner, origin.x + origin.xSize / 2];
1053
+ const source = [origin.y + origin.ySize - spacingHorizontal, origin.x + origin.xSize / 2];
1097
1054
  return this.transition(exit).attr('d', linkShape({
1098
1055
  source,
1099
1056
  target: source
1100
1057
  })).remove();
1101
1058
  });
1102
1059
  this.transition(path).attr('stroke', d => color(d.target.data)).attr('stroke-width', d => linkWidth(d.target)).attr('d', d => {
1103
- const source = [d.source.y + d.source.ySizeInner, d.source.x + d.source.xSize / 2];
1104
- const target = [d.target.y, d.target.x + d.target.xSize / 2];
1060
+ const origSource = d.source;
1061
+ const origTarget = d.target;
1062
+ const source = [origSource.y + origSource.ySize - spacingHorizontal, origSource.x + origSource.xSize / 2];
1063
+ const target = [origTarget.y, origTarget.x + origTarget.xSize / 2];
1105
1064
  return linkShape({
1106
1065
  source,
1107
1066
  target
@@ -1156,9 +1115,12 @@ class Markmap {
1156
1115
  });
1157
1116
  if (!itemData) return;
1158
1117
  const svgNode = this.svg.node();
1118
+ const {
1119
+ spacingHorizontal
1120
+ } = this.options;
1159
1121
  const relRect = svgNode.getBoundingClientRect();
1160
1122
  const transform = d3__namespace.zoomTransform(svgNode);
1161
- const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
1123
+ const [left, right] = [itemData.y, itemData.y + itemData.ySize - spacingHorizontal + 2].map(x => x * transform.k + transform.x);
1162
1124
  const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
1163
1125
  // Skip if the node includes or is included in the container.
1164
1126
  const pd = _extends({
@@ -1199,7 +1161,7 @@ class Markmap {
1199
1161
  fn();
1200
1162
  });
1201
1163
  }
1202
- static create(svg, opts, data) {
1164
+ static create(svg, opts, data = null) {
1203
1165
  const mm = new Markmap(svg, opts);
1204
1166
  if (data) {
1205
1167
  mm.setData(data);
@@ -1211,7 +1173,10 @@ class Markmap {
1211
1173
  }
1212
1174
  Markmap.defaultOptions = {
1213
1175
  autoFit: false,
1214
- color: node => defaultColorFn(`${node.state.path}`),
1176
+ color: node => {
1177
+ var _node$state;
1178
+ return defaultColorFn(`${((_node$state = node.state) == null ? void 0 : _node$state.path) || ''}`);
1179
+ },
1215
1180
  duration: 500,
1216
1181
  embedGlobalCSS: true,
1217
1182
  fitRatio: 0.95,
@@ -1227,22 +1192,22 @@ Markmap.defaultOptions = {
1227
1192
  toggleRecursively: false
1228
1193
  };
1229
1194
  function deriveOptions(jsonOptions) {
1230
- const opts = {};
1231
- jsonOptions || (jsonOptions = {});
1195
+ const derivedOptions = {};
1196
+ const options = _extends({}, jsonOptions);
1232
1197
  const {
1233
1198
  color,
1234
1199
  colorFreezeLevel
1235
- } = jsonOptions;
1200
+ } = options;
1236
1201
  if ((color == null ? void 0 : color.length) === 1) {
1237
1202
  const solidColor = color[0];
1238
- opts.color = () => solidColor;
1203
+ derivedOptions.color = () => solidColor;
1239
1204
  } else if (color != null && color.length) {
1240
1205
  const colorFn = d3__namespace.scaleOrdinal(color);
1241
- opts.color = node => colorFn(`${node.state.path}`);
1206
+ derivedOptions.color = node => colorFn(`${node.state.path}`);
1242
1207
  }
1243
1208
  if (colorFreezeLevel) {
1244
- const color = opts.color || Markmap.defaultOptions.color;
1245
- opts.color = node => {
1209
+ const color = derivedOptions.color || Markmap.defaultOptions.color;
1210
+ derivedOptions.color = node => {
1246
1211
  node = _extends({}, node, {
1247
1212
  state: _extends({}, node.state, {
1248
1213
  path: node.state.path.split('.').slice(0, colorFreezeLevel).join('.')
@@ -1253,15 +1218,15 @@ function deriveOptions(jsonOptions) {
1253
1218
  }
1254
1219
  const numberKeys = ['duration', 'maxWidth', 'initialExpandLevel'];
1255
1220
  numberKeys.forEach(key => {
1256
- const value = jsonOptions[key];
1257
- if (typeof value === 'number') opts[key] = value;
1221
+ const value = options[key];
1222
+ if (typeof value === 'number') derivedOptions[key] = value;
1258
1223
  });
1259
1224
  const booleanKeys = ['zoom', 'pan'];
1260
1225
  booleanKeys.forEach(key => {
1261
- const value = jsonOptions[key];
1262
- if (value != null) opts[key] = !!value;
1226
+ const value = options[key];
1227
+ if (value != null) derivedOptions[key] = !!value;
1263
1228
  });
1264
- return opts;
1229
+ return derivedOptions;
1265
1230
  }
1266
1231
 
1267
1232
  exports.loadCSS = markmapCommon.loadCSS;