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.mjs 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
  import { Hook, getId, addClass, walkTree, childSelector, noop } from 'markmap-common';
3
3
  export { loadCSS, loadJS } from 'markmap-common';
4
4
  import * as d3 from 'd3';
@@ -603,60 +603,47 @@ const updateLows = (lowY, index, lastLows) => {
603
603
  };
604
604
  };
605
605
 
606
- /*! @gera2ld/jsx-dom v2.1.1 | ISC License */
607
- var VTYPE_ELEMENT = 1;
608
- var VTYPE_FUNCTION = 2;
609
- var MOUNT_SINGLE = 1;
610
- var MOUNT_ARRAY = 4;
611
- var SVG_NS = 'http://www.w3.org/2000/svg';
612
- var XLINK_NS = 'http://www.w3.org/1999/xlink';
613
- var NS_ATTRS = {
606
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
607
+ const VTYPE_ELEMENT = 1;
608
+ const VTYPE_FUNCTION = 2;
609
+ const SVG_NS = 'http://www.w3.org/2000/svg';
610
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
611
+ const NS_ATTRS = {
614
612
  show: XLINK_NS,
615
613
  actuate: XLINK_NS,
616
614
  href: XLINK_NS
617
615
  };
618
- var isLeaf = function isLeaf(c) {
619
- return typeof c === 'string' || typeof c === 'number';
620
- };
621
- var isElement = function isElement(c) {
622
- return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
623
- };
624
- var isRenderFunction = function isRenderFunction(c) {
625
- return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
626
- };
616
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
617
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
618
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
627
619
  function jsx(type, props) {
628
- var vtype;
620
+ let vtype;
629
621
  if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
630
622
  return {
631
- vtype: vtype,
632
- type: type,
633
- props: props
623
+ vtype,
624
+ type,
625
+ props
634
626
  };
635
627
  }
636
628
  function Fragment(props) {
637
629
  return props.children;
638
630
  }
639
- var DEFAULT_ENV = {
631
+ const DEFAULT_ENV = {
640
632
  isSvg: false
641
633
  };
642
- function insertDom(parent, ref) {
643
- if (ref.type === MOUNT_SINGLE) {
644
- if (ref.node != null) parent.append(ref.node);
645
- } else if (ref.type === MOUNT_ARRAY) {
646
- ref.children.forEach(function (ch) {
647
- insertDom(parent, ch);
648
- });
649
- } else {
650
- throw new Error("Unkown ref type " + JSON.stringify(ref));
651
- }
634
+ function insertDom(parent, nodes) {
635
+ if (!Array.isArray(nodes)) nodes = [nodes];
636
+ nodes = nodes.filter(Boolean);
637
+ if (nodes.length) parent.append(...nodes);
652
638
  }
653
639
  function mountAttributes(domElement, props, env) {
654
- for (var key in props) {
640
+ for (const key in props) {
655
641
  if (key === 'key' || key === 'children' || key === 'ref') continue;
656
642
  if (key === 'dangerouslySetInnerHTML') {
657
643
  domElement.innerHTML = props[key].__html;
658
- } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
659
- domElement[key] = props[key];
644
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
645
+ const value = props[key];
646
+ if (value != null) domElement[key] = value;
660
647
  } else if (key.startsWith('on')) {
661
648
  domElement[key.toLowerCase()] = props[key];
662
649
  } else {
@@ -664,7 +651,7 @@ function mountAttributes(domElement, props, env) {
664
651
  }
665
652
  }
666
653
  }
667
- var attrMap = {
654
+ const attrMap = {
668
655
  className: 'class',
669
656
  labelFor: 'for'
670
657
  };
@@ -675,7 +662,7 @@ function setDOMAttribute(el, attr, value, isSVG) {
675
662
  } else if (value === false) {
676
663
  el.removeAttribute(attr);
677
664
  } else {
678
- var namespace = isSVG ? NS_ATTRS[attr] : undefined;
665
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
679
666
  if (namespace !== undefined) {
680
667
  el.setAttributeNS(namespace, attr, value);
681
668
  } else {
@@ -683,113 +670,79 @@ function setDOMAttribute(el, attr, value, isSVG) {
683
670
  }
684
671
  }
685
672
  }
686
- function mount(vnode, env) {
687
- if (env === void 0) {
688
- env = DEFAULT_ENV;
689
- }
673
+ function flatten(arr) {
674
+ return arr.reduce((prev, item) => prev.concat(item), []);
675
+ }
676
+ function mountChildren(children, env) {
677
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
678
+ }
679
+ function mount(vnode, env = DEFAULT_ENV) {
690
680
  if (vnode == null || typeof vnode === 'boolean') {
691
- return {
692
- type: MOUNT_SINGLE,
693
- node: null
694
- };
681
+ return null;
695
682
  }
696
683
  if (vnode instanceof Node) {
697
- return {
698
- type: MOUNT_SINGLE,
699
- node: vnode
700
- };
684
+ return vnode;
701
685
  }
702
686
  if (isRenderFunction(vnode)) {
703
- var _ref = vnode,
704
- type = _ref.type,
705
- props = _ref.props;
687
+ const {
688
+ type,
689
+ props
690
+ } = vnode;
706
691
  if (type === Fragment) {
707
- var node = document.createDocumentFragment();
692
+ const node = document.createDocumentFragment();
708
693
  if (props.children) {
709
- var childrenRef = mount(props.children, env);
710
- insertDom(node, childrenRef);
694
+ const children = mountChildren(props.children, env);
695
+ insertDom(node, children);
711
696
  }
712
- return {
713
- type: MOUNT_SINGLE,
714
- node: node
715
- };
697
+ return node;
716
698
  }
717
- var childVNode = type(props);
699
+ const childVNode = type(props);
718
700
  return mount(childVNode, env);
719
701
  }
720
702
  if (isLeaf(vnode)) {
721
- return {
722
- type: MOUNT_SINGLE,
723
- node: document.createTextNode("" + vnode)
724
- };
703
+ return document.createTextNode(`${vnode}`);
725
704
  }
726
705
  if (isElement(vnode)) {
727
- var _node;
728
- var _ref2 = vnode,
729
- _type = _ref2.type,
730
- _props = _ref2.props;
731
- if (!env.isSvg && _type === 'svg') {
706
+ let node;
707
+ const {
708
+ type,
709
+ props
710
+ } = vnode;
711
+ if (!env.isSvg && type === 'svg') {
732
712
  env = Object.assign({}, env, {
733
713
  isSvg: true
734
714
  });
735
715
  }
736
716
  if (!env.isSvg) {
737
- _node = document.createElement(_type);
717
+ node = document.createElement(type);
738
718
  } else {
739
- _node = document.createElementNS(SVG_NS, _type);
719
+ node = document.createElementNS(SVG_NS, type);
740
720
  }
741
- mountAttributes(_node, _props, env);
742
- var _childrenRef;
743
- if (_props.children) {
744
- var childEnv = env;
745
- if (env.isSvg && _type === 'foreignObject') {
721
+ mountAttributes(node, props, env);
722
+ if (props.children) {
723
+ let childEnv = env;
724
+ if (env.isSvg && type === 'foreignObject') {
746
725
  childEnv = Object.assign({}, childEnv, {
747
726
  isSvg: false
748
727
  });
749
728
  }
750
- _childrenRef = mount(_props.children, childEnv);
729
+ const children = mountChildren(props.children, childEnv);
730
+ if (children != null) insertDom(node, children);
751
731
  }
752
- if (_childrenRef != null) insertDom(_node, _childrenRef);
753
- var ref = _props.ref;
754
- if (typeof ref === 'function') ref(_node);
755
- return {
756
- type: MOUNT_SINGLE,
757
- node: _node
758
- };
759
- }
760
- if (Array.isArray(vnode)) {
761
- return {
762
- type: MOUNT_ARRAY,
763
- children: vnode.map(function (child) {
764
- return mount(child, env);
765
- })
766
- };
732
+ const {
733
+ ref
734
+ } = props;
735
+ if (typeof ref === 'function') ref(node);
736
+ return node;
767
737
  }
768
738
  throw new Error('mount: Invalid Vnode!');
769
739
  }
770
- function flattenWithoutNull(array) {
771
- var result = [];
772
- for (var i = 0; i < array.length; i += 1) {
773
- var item = array[i];
774
- if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
775
- }
776
- return result;
777
- }
778
- function asDom(result) {
779
- if (result.type === MOUNT_SINGLE) {
780
- return result.node;
781
- }
782
- return result.children.map(asDom);
783
- }
740
+
784
741
  /**
785
742
  * Mount vdom as real DOM nodes.
786
743
  */
787
-
788
744
  function mountDom(vnode) {
789
- if (Array.isArray(vnode)) {
790
- return flattenWithoutNull(vnode.map(mountDom));
791
- }
792
- return asDom(mount(vnode));
745
+ return mount(vnode);
793
746
  }
794
747
 
795
748
  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}";
@@ -801,13 +754,6 @@ function linkWidth(nodeData) {
801
754
  const data = nodeData.data;
802
755
  return Math.max(4 - 2 * data.depth, 1.5);
803
756
  }
804
- function adjustSpacing(tree, spacing) {
805
- walkTree(tree, (d, next) => {
806
- d.ySizeInner = d.ySize - spacing;
807
- d.y += spacing;
808
- next();
809
- }, 'children');
810
- }
811
757
  function minBy(numbers, by) {
812
758
  const index = d3.minIndex(numbers, by);
813
759
  return numbers[index];
@@ -829,10 +775,25 @@ const defaultColorFn = d3.scaleOrdinal(d3.schemeCategory10);
829
775
  const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
830
776
  class Markmap {
831
777
  constructor(svg, opts) {
778
+ this.options = Markmap.defaultOptions;
832
779
  this.revokers = [];
833
- ['handleZoom', 'handleClick', 'handlePan'].forEach(key => {
834
- this[key] = this[key].bind(this);
835
- });
780
+ this.handleZoom = e => {
781
+ const {
782
+ transform
783
+ } = e;
784
+ this.g.attr('transform', transform);
785
+ };
786
+ this.handlePan = e => {
787
+ e.preventDefault();
788
+ const transform = d3.zoomTransform(this.svg.node());
789
+ const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
790
+ this.svg.call(this.zoom.transform, newTransform);
791
+ };
792
+ this.handleClick = (e, d) => {
793
+ let recursive = this.options.toggleRecursively;
794
+ if (e.ctrlKey) recursive = !recursive;
795
+ this.toggleNode(d.data, recursive);
796
+ };
836
797
  this.viewHooks = createViewHooks();
837
798
  this.svg = svg.datum ? svg : d3.select(svg);
838
799
  this.styleNode = this.svg.append('style');
@@ -845,7 +806,11 @@ class Markmap {
845
806
  }).on('zoom', this.handleZoom);
846
807
  this.setOptions(opts);
847
808
  this.state = {
848
- id: this.options.id || this.svg.attr('id') || getId()
809
+ id: this.options.id || this.svg.attr('id') || getId(),
810
+ minX: 0,
811
+ maxX: 0,
812
+ minY: 0,
813
+ maxY: 0
849
814
  };
850
815
  this.g = this.svg.append('g');
851
816
  this.revokers.push(refreshHook.tap(() => {
@@ -867,18 +832,6 @@ class Markmap {
867
832
  const style = this.getStyleContent();
868
833
  this.styleNode.text(style);
869
834
  }
870
- handleZoom(e) {
871
- const {
872
- transform
873
- } = e;
874
- this.g.attr('transform', transform);
875
- }
876
- handlePan(e) {
877
- e.preventDefault();
878
- const transform = d3.zoomTransform(this.svg.node());
879
- const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
880
- this.svg.call(this.zoom.transform, newTransform);
881
- }
882
835
  toggleNode(data, recursive = false) {
883
836
  var _data$payload;
884
837
  const fold = (_data$payload = data.payload) != null && _data$payload.fold ? 0 : 1;
@@ -898,11 +851,6 @@ class Markmap {
898
851
  }
899
852
  this.renderData(data);
900
853
  }
901
- handleClick(e, d) {
902
- let recursive = this.options.toggleRecursively;
903
- if (e.ctrlKey) recursive = !recursive;
904
- this.toggleNode(d.data, recursive);
905
- }
906
854
  initializeData(node) {
907
855
  let nodeId = 0;
908
856
  const {
@@ -962,14 +910,16 @@ class Markmap {
962
910
  // `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
963
911
  // content in one line as much as possible, and subjecting to the given max-width.
964
912
  nodes.forEach(node => {
965
- node.parentNode.append(node.cloneNode(true));
913
+ var _node$parentNode;
914
+ (_node$parentNode = node.parentNode) == null ? void 0 : _node$parentNode.append(node.cloneNode(true));
966
915
  });
967
916
  walkTree(node, (item, next, parent) => {
968
917
  var _parent$state2;
969
- const rect = item.state.el.getBoundingClientRect();
970
- item.content = item.state.el.innerHTML;
971
- item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
972
- item.state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') +
918
+ const state = item.state;
919
+ const rect = state.el.getBoundingClientRect();
920
+ item.content = state.el.innerHTML;
921
+ state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
922
+ state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, state.id].filter(Boolean).join('.') +
973
923
  // FIXME: find a way to check content hash
974
924
  item.content;
975
925
  next();
@@ -984,11 +934,16 @@ class Markmap {
984
934
  } else {
985
935
  this.svg.on('.zoom', null);
986
936
  }
987
- this.svg.on('wheel', this.options.pan ? this.handlePan : null);
937
+ if (this.options.pan) {
938
+ this.svg.on('wheel', this.handlePan);
939
+ } else {
940
+ this.svg.on('wheel', null);
941
+ }
988
942
  }
989
943
  setData(data, opts) {
990
- if (data) this.state.data = data;
991
944
  if (opts) this.setOptions(opts);
945
+ if (data) this.state.data = data;
946
+ if (!this.state.data) return;
992
947
  this.initializeData(this.state.data);
993
948
  this.updateStyle();
994
949
  this.renderData();
@@ -1003,25 +958,24 @@ class Markmap {
1003
958
  autoFit,
1004
959
  color
1005
960
  } = this.options;
1006
- const layout = flextree().children(d => {
961
+ const layout = flextree({}).children(d => {
1007
962
  var _d$payload;
1008
- return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
1009
- }).nodeSize(d => {
1010
- const [width, height] = d.data.state.size;
963
+ if (!((_d$payload = d.payload) != null && _d$payload.fold)) return d.children;
964
+ }).nodeSize(node => {
965
+ const [width, height] = node.data.state.size;
1011
966
  return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
1012
967
  }).spacing((a, b) => {
1013
968
  return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
1014
969
  });
1015
970
  const tree = layout.hierarchy(this.state.data);
1016
971
  layout(tree);
1017
- adjustSpacing(tree, spacingHorizontal);
1018
972
  const descendants = tree.descendants().reverse();
1019
973
  const links = tree.links();
1020
974
  const linkShape = d3.linkHorizontal();
1021
975
  const minX = d3.min(descendants, d => d.x - d.xSize / 2);
1022
976
  const maxX = d3.max(descendants, d => d.x + d.xSize / 2);
1023
977
  const minY = d3.min(descendants, d => d.y);
1024
- const maxY = d3.max(descendants, d => d.y + d.ySizeInner);
978
+ const maxY = d3.max(descendants, d => d.y + d.ySize - spacingHorizontal);
1025
979
  Object.assign(this.state, {
1026
980
  minX,
1027
981
  maxX,
@@ -1035,11 +989,11 @@ class Markmap {
1035
989
 
1036
990
  // Update the nodes
1037
991
  const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.state.key);
1038
- 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})`);
992
+ 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})`);
1039
993
  const nodeExit = this.transition(node.exit());
1040
- nodeExit.select('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
994
+ nodeExit.select('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1041
995
  nodeExit.select('foreignObject').style('opacity', 0);
1042
- nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
996
+ nodeExit.attr('transform', d => `translate(${origin.y + origin.ySize - d.ySize},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1043
997
  const nodeMerge = node.merge(nodeEnter).attr('class', d => {
1044
998
  var _d$data$payload;
1045
999
  return ['markmap-node', ((_d$data$payload = d.data.payload) == null ? void 0 : _d$data$payload.fold) && 'markmap-fold'].filter(Boolean).join(' ');
@@ -1048,15 +1002,18 @@ class Markmap {
1048
1002
 
1049
1003
  // Update lines under the content
1050
1004
  const line = nodeMerge.selectAll(childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
1051
- return enter.append('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1005
+ return enter.append('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1052
1006
  }, update => update, exit => exit.remove());
1053
- 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);
1007
+ 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);
1054
1008
 
1055
1009
  // Circle to link to children of the node
1056
- const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
1057
- 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);
1010
+ const circle = nodeMerge.selectAll(childSelector('circle')).data(d => {
1011
+ var _d$data$children;
1012
+ return (_d$data$children = d.data.children) != null && _d$data$children.length ? [d] : [];
1013
+ }, d => d.data.state.key).join(enter => {
1014
+ 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);
1058
1015
  }, update => update, exit => exit.remove());
1059
- 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 => {
1016
+ 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 => {
1060
1017
  var _d$data$payload2;
1061
1018
  return (_d$data$payload2 = d.data.payload) != null && _d$data$payload2.fold && d.data.children ? color(d.data) : '#fff';
1062
1019
  });
@@ -1068,26 +1025,28 @@ class Markmap {
1068
1025
  return clone;
1069
1026
  }).attr('xmlns', 'http://www.w3.org/1999/xhtml');
1070
1027
  return fo;
1071
- }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2)).attr('height', d => d.xSize);
1028
+ }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySize - spacingHorizontal - paddingX * 2)).attr('height', d => d.xSize);
1072
1029
  this.transition(foreignObject).style('opacity', 1);
1073
1030
 
1074
1031
  // Update the links
1075
1032
  const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
1076
- const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
1033
+ const source = [y0 + origin.ySize - spacingHorizontal, x0 + origin.xSize / 2];
1077
1034
  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({
1078
1035
  source,
1079
1036
  target: source
1080
1037
  }));
1081
1038
  }, update => update, exit => {
1082
- const source = [origin.y + origin.ySizeInner, origin.x + origin.xSize / 2];
1039
+ const source = [origin.y + origin.ySize - spacingHorizontal, origin.x + origin.xSize / 2];
1083
1040
  return this.transition(exit).attr('d', linkShape({
1084
1041
  source,
1085
1042
  target: source
1086
1043
  })).remove();
1087
1044
  });
1088
1045
  this.transition(path).attr('stroke', d => color(d.target.data)).attr('stroke-width', d => linkWidth(d.target)).attr('d', d => {
1089
- const source = [d.source.y + d.source.ySizeInner, d.source.x + d.source.xSize / 2];
1090
- const target = [d.target.y, d.target.x + d.target.xSize / 2];
1046
+ const origSource = d.source;
1047
+ const origTarget = d.target;
1048
+ const source = [origSource.y + origSource.ySize - spacingHorizontal, origSource.x + origSource.xSize / 2];
1049
+ const target = [origTarget.y, origTarget.x + origTarget.xSize / 2];
1091
1050
  return linkShape({
1092
1051
  source,
1093
1052
  target
@@ -1142,9 +1101,12 @@ class Markmap {
1142
1101
  });
1143
1102
  if (!itemData) return;
1144
1103
  const svgNode = this.svg.node();
1104
+ const {
1105
+ spacingHorizontal
1106
+ } = this.options;
1145
1107
  const relRect = svgNode.getBoundingClientRect();
1146
1108
  const transform = d3.zoomTransform(svgNode);
1147
- const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
1109
+ const [left, right] = [itemData.y, itemData.y + itemData.ySize - spacingHorizontal + 2].map(x => x * transform.k + transform.x);
1148
1110
  const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
1149
1111
  // Skip if the node includes or is included in the container.
1150
1112
  const pd = _extends({
@@ -1185,7 +1147,7 @@ class Markmap {
1185
1147
  fn();
1186
1148
  });
1187
1149
  }
1188
- static create(svg, opts, data) {
1150
+ static create(svg, opts, data = null) {
1189
1151
  const mm = new Markmap(svg, opts);
1190
1152
  if (data) {
1191
1153
  mm.setData(data);
@@ -1197,7 +1159,10 @@ class Markmap {
1197
1159
  }
1198
1160
  Markmap.defaultOptions = {
1199
1161
  autoFit: false,
1200
- color: node => defaultColorFn(`${node.state.path}`),
1162
+ color: node => {
1163
+ var _node$state;
1164
+ return defaultColorFn(`${((_node$state = node.state) == null ? void 0 : _node$state.path) || ''}`);
1165
+ },
1201
1166
  duration: 500,
1202
1167
  embedGlobalCSS: true,
1203
1168
  fitRatio: 0.95,
@@ -1213,22 +1178,22 @@ Markmap.defaultOptions = {
1213
1178
  toggleRecursively: false
1214
1179
  };
1215
1180
  function deriveOptions(jsonOptions) {
1216
- const opts = {};
1217
- jsonOptions || (jsonOptions = {});
1181
+ const derivedOptions = {};
1182
+ const options = _extends({}, jsonOptions);
1218
1183
  const {
1219
1184
  color,
1220
1185
  colorFreezeLevel
1221
- } = jsonOptions;
1186
+ } = options;
1222
1187
  if ((color == null ? void 0 : color.length) === 1) {
1223
1188
  const solidColor = color[0];
1224
- opts.color = () => solidColor;
1189
+ derivedOptions.color = () => solidColor;
1225
1190
  } else if (color != null && color.length) {
1226
1191
  const colorFn = d3.scaleOrdinal(color);
1227
- opts.color = node => colorFn(`${node.state.path}`);
1192
+ derivedOptions.color = node => colorFn(`${node.state.path}`);
1228
1193
  }
1229
1194
  if (colorFreezeLevel) {
1230
- const color = opts.color || Markmap.defaultOptions.color;
1231
- opts.color = node => {
1195
+ const color = derivedOptions.color || Markmap.defaultOptions.color;
1196
+ derivedOptions.color = node => {
1232
1197
  node = _extends({}, node, {
1233
1198
  state: _extends({}, node.state, {
1234
1199
  path: node.state.path.split('.').slice(0, colorFreezeLevel).join('.')
@@ -1239,15 +1204,15 @@ function deriveOptions(jsonOptions) {
1239
1204
  }
1240
1205
  const numberKeys = ['duration', 'maxWidth', 'initialExpandLevel'];
1241
1206
  numberKeys.forEach(key => {
1242
- const value = jsonOptions[key];
1243
- if (typeof value === 'number') opts[key] = value;
1207
+ const value = options[key];
1208
+ if (typeof value === 'number') derivedOptions[key] = value;
1244
1209
  });
1245
1210
  const booleanKeys = ['zoom', 'pan'];
1246
1211
  booleanKeys.forEach(key => {
1247
- const value = jsonOptions[key];
1248
- if (value != null) opts[key] = !!value;
1212
+ const value = options[key];
1213
+ if (value != null) derivedOptions[key] = !!value;
1249
1214
  });
1250
- return opts;
1215
+ return derivedOptions;
1251
1216
  }
1252
1217
 
1253
1218
  export { Markmap, defaultColorFn, deriveOptions, globalCSS, refreshHook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-view",
3
- "version": "0.14.5-alpha.13+50ca560",
3
+ "version": "0.14.5-alpha.16+33e8294",
4
4
  "description": "View markmaps in browser",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -43,11 +43,12 @@
43
43
  "d3-flextree": "^2.1.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@gera2ld/jsx-dom": "^2.1.1",
47
- "markmap-common": "0.14.5-alpha.13+50ca560"
46
+ "@gera2ld/jsx-dom": "^2.2.2",
47
+ "@types/d3-flextree": "^2.1.1",
48
+ "markmap-common": "0.14.5-alpha.16+33e8294"
48
49
  },
49
50
  "peerDependencies": {
50
51
  "markmap-common": "*"
51
52
  },
52
- "gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
53
+ "gitHead": "33e8294050d7438f6cdadd5bf06a665560585195"
53
54
  }
package/types/types.d.ts CHANGED
@@ -2,22 +2,8 @@ import { INode } from 'markmap-common';
2
2
  export interface IMarkmapState {
3
3
  id: string;
4
4
  data?: INode;
5
- minX?: number;
6
- maxX?: number;
7
- minY?: number;
8
- maxY?: number;
9
- }
10
- export interface IMarkmapFlexTreeItem {
11
- parent: IMarkmapFlexTreeItem;
12
- data: INode;
13
- depth: number;
14
- xSize: number;
15
- ySize: number;
16
- ySizeInner: number;
17
- x: number;
18
- y: number;
19
- }
20
- export interface IMarkmapLinkItem {
21
- source: IMarkmapFlexTreeItem;
22
- target: IMarkmapFlexTreeItem;
5
+ minX: number;
6
+ maxX: number;
7
+ minY: number;
8
+ maxY: number;
23
9
  }