markmap-view 0.14.5-alpha.15 → 0.14.5-alpha.17

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.
@@ -1,4 +1,4 @@
1
- /*! markmap-view v0.14.5-alpha.15+1fe26c8 | MIT License */
1
+ /*! markmap-view v0.14.5-alpha.17+0d6a717 | MIT License */
2
2
  (function (exports, d3) {
3
3
  'use strict';
4
4
 
@@ -15,7 +15,7 @@ return Object.freeze(n);
15
15
 
16
16
  var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
17
17
 
18
- /*! markmap-common v0.14.5-alpha.15+1fe26c8 | MIT License */
18
+ /*! markmap-common v0.14.2 | MIT License */
19
19
  class Hook {
20
20
  constructor() {
21
21
  this.listeners = [];
@@ -60,10 +60,10 @@ function getId() {
60
60
  function noop() {
61
61
  // noop
62
62
  }
63
- function walkTree(tree, callback, key = 'children') {
63
+ function walkTree(tree, callback) {
64
64
  const walk = (item, parent) => callback(item, () => {
65
- var _item$key;
66
- (_item$key = item[key]) == null ? void 0 : _item$key.forEach(child => {
65
+ var _item$children;
66
+ (_item$children = item.children) == null ? void 0 : _item$children.forEach(child => {
67
67
  walk(child, item);
68
68
  });
69
69
  }, parent);
@@ -102,22 +102,163 @@ function memoize(fn) {
102
102
  return data.value;
103
103
  };
104
104
  }
105
- function createElement(tagName, props, attrs) {
106
- const el = document.createElement(tagName);
107
- if (props) {
108
- Object.entries(props).forEach(([key, value]) => {
109
- el[key] = value;
110
- });
105
+
106
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
107
+ const VTYPE_ELEMENT$1 = 1;
108
+ const VTYPE_FUNCTION$1 = 2;
109
+ const SVG_NS$1 = 'http://www.w3.org/2000/svg';
110
+ const XLINK_NS$1 = 'http://www.w3.org/1999/xlink';
111
+ const NS_ATTRS$1 = {
112
+ show: XLINK_NS$1,
113
+ actuate: XLINK_NS$1,
114
+ href: XLINK_NS$1
115
+ };
116
+ const isLeaf$1 = c => typeof c === 'string' || typeof c === 'number';
117
+ const isElement$1 = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT$1;
118
+ const isRenderFunction$1 = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION$1;
119
+ function h(type, props, ...children) {
120
+ props = Object.assign({}, props, {
121
+ children: children.length === 1 ? children[0] : children
122
+ });
123
+ return jsx$1(type, props);
124
+ }
125
+ function jsx$1(type, props) {
126
+ let vtype;
127
+ if (typeof type === 'string') vtype = VTYPE_ELEMENT$1;else if (typeof type === 'function') vtype = VTYPE_FUNCTION$1;else throw new Error('Invalid VNode type');
128
+ return {
129
+ vtype,
130
+ type,
131
+ props
132
+ };
133
+ }
134
+ function Fragment$1(props) {
135
+ return props.children;
136
+ }
137
+ const DEFAULT_ENV$1 = {
138
+ isSvg: false
139
+ };
140
+ function insertDom$1(parent, nodes) {
141
+ if (!Array.isArray(nodes)) nodes = [nodes];
142
+ nodes = nodes.filter(Boolean);
143
+ if (nodes.length) parent.append(...nodes);
144
+ }
145
+ function mountAttributes$1(domElement, props, env) {
146
+ for (const key in props) {
147
+ if (key === 'key' || key === 'children' || key === 'ref') continue;
148
+ if (key === 'dangerouslySetInnerHTML') {
149
+ domElement.innerHTML = props[key].__html;
150
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
151
+ const value = props[key];
152
+ if (value != null) domElement[key] = value;
153
+ } else if (key.startsWith('on')) {
154
+ domElement[key.toLowerCase()] = props[key];
155
+ } else {
156
+ setDOMAttribute$1(domElement, key, props[key], env.isSvg);
157
+ }
111
158
  }
112
- if (attrs) {
113
- Object.entries(attrs).forEach(([key, value]) => {
114
- el.setAttribute(key, value);
115
- });
159
+ }
160
+ const attrMap$1 = {
161
+ className: 'class',
162
+ labelFor: 'for'
163
+ };
164
+ function setDOMAttribute$1(el, attr, value, isSVG) {
165
+ attr = attrMap$1[attr] || attr;
166
+ if (value === true) {
167
+ el.setAttribute(attr, '');
168
+ } else if (value === false) {
169
+ el.removeAttribute(attr);
170
+ } else {
171
+ const namespace = isSVG ? NS_ATTRS$1[attr] : undefined;
172
+ if (namespace !== undefined) {
173
+ el.setAttributeNS(namespace, attr, value);
174
+ } else {
175
+ el.setAttribute(attr, value);
176
+ }
177
+ }
178
+ }
179
+ function flatten$1(arr) {
180
+ return arr.reduce((prev, item) => prev.concat(item), []);
181
+ }
182
+ function mountChildren$1(children, env) {
183
+ return Array.isArray(children) ? flatten$1(children.map(child => mountChildren$1(child, env))) : mount$1(children, env);
184
+ }
185
+ function mount$1(vnode, env = DEFAULT_ENV$1) {
186
+ if (vnode == null || typeof vnode === 'boolean') {
187
+ return null;
188
+ }
189
+ if (vnode instanceof Node) {
190
+ return vnode;
191
+ }
192
+ if (isRenderFunction$1(vnode)) {
193
+ const {
194
+ type,
195
+ props
196
+ } = vnode;
197
+ if (type === Fragment$1) {
198
+ const node = document.createDocumentFragment();
199
+ if (props.children) {
200
+ const children = mountChildren$1(props.children, env);
201
+ insertDom$1(node, children);
202
+ }
203
+ return node;
204
+ }
205
+ const childVNode = type(props);
206
+ return mount$1(childVNode, env);
207
+ }
208
+ if (isLeaf$1(vnode)) {
209
+ return document.createTextNode(`${vnode}`);
210
+ }
211
+ if (isElement$1(vnode)) {
212
+ let node;
213
+ const {
214
+ type,
215
+ props
216
+ } = vnode;
217
+ if (!env.isSvg && type === 'svg') {
218
+ env = Object.assign({}, env, {
219
+ isSvg: true
220
+ });
221
+ }
222
+ if (!env.isSvg) {
223
+ node = document.createElement(type);
224
+ } else {
225
+ node = document.createElementNS(SVG_NS$1, type);
226
+ }
227
+ mountAttributes$1(node, props, env);
228
+ if (props.children) {
229
+ let childEnv = env;
230
+ if (env.isSvg && type === 'foreignObject') {
231
+ childEnv = Object.assign({}, childEnv, {
232
+ isSvg: false
233
+ });
234
+ }
235
+ const children = mountChildren$1(props.children, childEnv);
236
+ if (children != null) insertDom$1(node, children);
237
+ }
238
+ const {
239
+ ref
240
+ } = props;
241
+ if (typeof ref === 'function') ref(node);
242
+ return node;
116
243
  }
117
- return el;
244
+ throw new Error('mount: Invalid Vnode!');
245
+ }
246
+
247
+ /**
248
+ * Mount vdom as real DOM nodes.
249
+ */
250
+ function mountDom$1(vnode) {
251
+ return mount$1(vnode);
252
+ }
253
+
254
+ /**
255
+ * Render and mount without returning VirtualDOM, useful when you don't need SVG support.
256
+ */
257
+ function hm(...args) {
258
+ return mountDom$1(h(...args));
118
259
  }
119
260
  const memoizedPreloadJS = memoize(url => {
120
- document.head.append(createElement('link', {
261
+ document.head.append(hm('link', {
121
262
  rel: 'preload',
122
263
  as: 'script',
123
264
  href: url
@@ -128,9 +269,9 @@ async function loadJSItem(item, context) {
128
269
  if (item.type === 'script') {
129
270
  item.loaded = new Promise((resolve, reject) => {
130
271
  var _item$data;
131
- document.head.append(createElement('script', _extends$1({}, item.data, {
132
- onload: resolve,
133
- onerror: reject
272
+ document.head.append(hm('script', _extends$1({}, item.data, {
273
+ onLoad: resolve,
274
+ onError: reject
134
275
  })));
135
276
  // Run inline script synchronously
136
277
  if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
@@ -153,21 +294,22 @@ function loadCSSItem(item) {
153
294
  if (item.loaded) return;
154
295
  item.loaded = true;
155
296
  if (item.type === 'style') {
156
- document.head.append(createElement('style', {
297
+ document.head.append(hm('style', {
157
298
  textContent: item.data
158
299
  }));
159
300
  } else if (item.type === 'stylesheet') {
160
- document.head.append(createElement('link', _extends$1({
301
+ document.head.append(hm('link', _extends$1({
161
302
  rel: 'stylesheet'
162
303
  }, item.data)));
163
304
  }
164
305
  }
165
306
  async function loadJS(items, context) {
166
- const needPreload = items.filter(item => {
307
+ items.forEach(item => {
167
308
  var _item$data2;
168
- return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
309
+ if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
310
+ memoizedPreloadJS(item.data.src);
311
+ }
169
312
  });
170
- if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
171
313
  context = _extends$1({
172
314
  getMarkmap: () => window.markmap
173
315
  }, context);
@@ -781,60 +923,47 @@ const updateLows = (lowY, index, lastLows) => {
781
923
  };
782
924
  };
783
925
 
784
- /*! @gera2ld/jsx-dom v2.1.1 | ISC License */
785
- var VTYPE_ELEMENT = 1;
786
- var VTYPE_FUNCTION = 2;
787
- var MOUNT_SINGLE = 1;
788
- var MOUNT_ARRAY = 4;
789
- var SVG_NS = 'http://www.w3.org/2000/svg';
790
- var XLINK_NS = 'http://www.w3.org/1999/xlink';
791
- var NS_ATTRS = {
926
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
927
+ const VTYPE_ELEMENT = 1;
928
+ const VTYPE_FUNCTION = 2;
929
+ const SVG_NS = 'http://www.w3.org/2000/svg';
930
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
931
+ const NS_ATTRS = {
792
932
  show: XLINK_NS,
793
933
  actuate: XLINK_NS,
794
934
  href: XLINK_NS
795
935
  };
796
- var isLeaf = function isLeaf(c) {
797
- return typeof c === 'string' || typeof c === 'number';
798
- };
799
- var isElement = function isElement(c) {
800
- return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
801
- };
802
- var isRenderFunction = function isRenderFunction(c) {
803
- return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
804
- };
936
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
937
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
938
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
805
939
  function jsx(type, props) {
806
- var vtype;
940
+ let vtype;
807
941
  if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
808
942
  return {
809
- vtype: vtype,
810
- type: type,
811
- props: props
943
+ vtype,
944
+ type,
945
+ props
812
946
  };
813
947
  }
814
948
  function Fragment(props) {
815
949
  return props.children;
816
950
  }
817
- var DEFAULT_ENV = {
951
+ const DEFAULT_ENV = {
818
952
  isSvg: false
819
953
  };
820
- function insertDom(parent, ref) {
821
- if (ref.type === MOUNT_SINGLE) {
822
- if (ref.node != null) parent.append(ref.node);
823
- } else if (ref.type === MOUNT_ARRAY) {
824
- ref.children.forEach(function (ch) {
825
- insertDom(parent, ch);
826
- });
827
- } else {
828
- throw new Error("Unkown ref type " + JSON.stringify(ref));
829
- }
954
+ function insertDom(parent, nodes) {
955
+ if (!Array.isArray(nodes)) nodes = [nodes];
956
+ nodes = nodes.filter(Boolean);
957
+ if (nodes.length) parent.append(...nodes);
830
958
  }
831
959
  function mountAttributes(domElement, props, env) {
832
- for (var key in props) {
960
+ for (const key in props) {
833
961
  if (key === 'key' || key === 'children' || key === 'ref') continue;
834
962
  if (key === 'dangerouslySetInnerHTML') {
835
963
  domElement.innerHTML = props[key].__html;
836
- } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
837
- domElement[key] = props[key];
964
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
965
+ const value = props[key];
966
+ if (value != null) domElement[key] = value;
838
967
  } else if (key.startsWith('on')) {
839
968
  domElement[key.toLowerCase()] = props[key];
840
969
  } else {
@@ -842,7 +971,7 @@ function mountAttributes(domElement, props, env) {
842
971
  }
843
972
  }
844
973
  }
845
- var attrMap = {
974
+ const attrMap = {
846
975
  className: 'class',
847
976
  labelFor: 'for'
848
977
  };
@@ -853,7 +982,7 @@ function setDOMAttribute(el, attr, value, isSVG) {
853
982
  } else if (value === false) {
854
983
  el.removeAttribute(attr);
855
984
  } else {
856
- var namespace = isSVG ? NS_ATTRS[attr] : undefined;
985
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
857
986
  if (namespace !== undefined) {
858
987
  el.setAttributeNS(namespace, attr, value);
859
988
  } else {
@@ -861,113 +990,79 @@ function setDOMAttribute(el, attr, value, isSVG) {
861
990
  }
862
991
  }
863
992
  }
864
- function mount(vnode, env) {
865
- if (env === void 0) {
866
- env = DEFAULT_ENV;
867
- }
993
+ function flatten(arr) {
994
+ return arr.reduce((prev, item) => prev.concat(item), []);
995
+ }
996
+ function mountChildren(children, env) {
997
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
998
+ }
999
+ function mount(vnode, env = DEFAULT_ENV) {
868
1000
  if (vnode == null || typeof vnode === 'boolean') {
869
- return {
870
- type: MOUNT_SINGLE,
871
- node: null
872
- };
1001
+ return null;
873
1002
  }
874
1003
  if (vnode instanceof Node) {
875
- return {
876
- type: MOUNT_SINGLE,
877
- node: vnode
878
- };
1004
+ return vnode;
879
1005
  }
880
1006
  if (isRenderFunction(vnode)) {
881
- var _ref = vnode,
882
- type = _ref.type,
883
- props = _ref.props;
1007
+ const {
1008
+ type,
1009
+ props
1010
+ } = vnode;
884
1011
  if (type === Fragment) {
885
- var node = document.createDocumentFragment();
1012
+ const node = document.createDocumentFragment();
886
1013
  if (props.children) {
887
- var childrenRef = mount(props.children, env);
888
- insertDom(node, childrenRef);
1014
+ const children = mountChildren(props.children, env);
1015
+ insertDom(node, children);
889
1016
  }
890
- return {
891
- type: MOUNT_SINGLE,
892
- node: node
893
- };
1017
+ return node;
894
1018
  }
895
- var childVNode = type(props);
1019
+ const childVNode = type(props);
896
1020
  return mount(childVNode, env);
897
1021
  }
898
1022
  if (isLeaf(vnode)) {
899
- return {
900
- type: MOUNT_SINGLE,
901
- node: document.createTextNode("" + vnode)
902
- };
1023
+ return document.createTextNode(`${vnode}`);
903
1024
  }
904
1025
  if (isElement(vnode)) {
905
- var _node;
906
- var _ref2 = vnode,
907
- _type = _ref2.type,
908
- _props = _ref2.props;
909
- if (!env.isSvg && _type === 'svg') {
1026
+ let node;
1027
+ const {
1028
+ type,
1029
+ props
1030
+ } = vnode;
1031
+ if (!env.isSvg && type === 'svg') {
910
1032
  env = Object.assign({}, env, {
911
1033
  isSvg: true
912
1034
  });
913
1035
  }
914
1036
  if (!env.isSvg) {
915
- _node = document.createElement(_type);
1037
+ node = document.createElement(type);
916
1038
  } else {
917
- _node = document.createElementNS(SVG_NS, _type);
1039
+ node = document.createElementNS(SVG_NS, type);
918
1040
  }
919
- mountAttributes(_node, _props, env);
920
- var _childrenRef;
921
- if (_props.children) {
922
- var childEnv = env;
923
- if (env.isSvg && _type === 'foreignObject') {
1041
+ mountAttributes(node, props, env);
1042
+ if (props.children) {
1043
+ let childEnv = env;
1044
+ if (env.isSvg && type === 'foreignObject') {
924
1045
  childEnv = Object.assign({}, childEnv, {
925
1046
  isSvg: false
926
1047
  });
927
1048
  }
928
- _childrenRef = mount(_props.children, childEnv);
1049
+ const children = mountChildren(props.children, childEnv);
1050
+ if (children != null) insertDom(node, children);
929
1051
  }
930
- if (_childrenRef != null) insertDom(_node, _childrenRef);
931
- var ref = _props.ref;
932
- if (typeof ref === 'function') ref(_node);
933
- return {
934
- type: MOUNT_SINGLE,
935
- node: _node
936
- };
937
- }
938
- if (Array.isArray(vnode)) {
939
- return {
940
- type: MOUNT_ARRAY,
941
- children: vnode.map(function (child) {
942
- return mount(child, env);
943
- })
944
- };
1052
+ const {
1053
+ ref
1054
+ } = props;
1055
+ if (typeof ref === 'function') ref(node);
1056
+ return node;
945
1057
  }
946
1058
  throw new Error('mount: Invalid Vnode!');
947
1059
  }
948
- function flattenWithoutNull(array) {
949
- var result = [];
950
- for (var i = 0; i < array.length; i += 1) {
951
- var item = array[i];
952
- if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
953
- }
954
- return result;
955
- }
956
- function asDom(result) {
957
- if (result.type === MOUNT_SINGLE) {
958
- return result.node;
959
- }
960
- return result.children.map(asDom);
961
- }
1060
+
962
1061
  /**
963
1062
  * Mount vdom as real DOM nodes.
964
1063
  */
965
-
966
1064
  function mountDom(vnode) {
967
- if (Array.isArray(vnode)) {
968
- return flattenWithoutNull(vnode.map(mountDom));
969
- }
970
- return asDom(mount(vnode));
1065
+ return mount(vnode);
971
1066
  }
972
1067
 
973
1068
  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}";
@@ -979,13 +1074,6 @@ function linkWidth(nodeData) {
979
1074
  const data = nodeData.data;
980
1075
  return Math.max(4 - 2 * data.depth, 1.5);
981
1076
  }
982
- function adjustSpacing(tree, spacing) {
983
- walkTree(tree, (d, next) => {
984
- d.ySizeInner = d.ySize - spacing;
985
- d.y += spacing;
986
- next();
987
- }, 'children');
988
- }
989
1077
  function minBy(numbers, by) {
990
1078
  const index = d3__namespace.minIndex(numbers, by);
991
1079
  return numbers[index];
@@ -1007,10 +1095,25 @@ const defaultColorFn = d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10
1007
1095
  const isMacintosh = typeof navigator !== 'undefined' && navigator.userAgent.includes('Macintosh');
1008
1096
  class Markmap {
1009
1097
  constructor(svg, opts) {
1098
+ this.options = Markmap.defaultOptions;
1010
1099
  this.revokers = [];
1011
- ['handleZoom', 'handleClick', 'handlePan'].forEach(key => {
1012
- this[key] = this[key].bind(this);
1013
- });
1100
+ this.handleZoom = e => {
1101
+ const {
1102
+ transform
1103
+ } = e;
1104
+ this.g.attr('transform', transform);
1105
+ };
1106
+ this.handlePan = e => {
1107
+ e.preventDefault();
1108
+ const transform = d3__namespace.zoomTransform(this.svg.node());
1109
+ const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
1110
+ this.svg.call(this.zoom.transform, newTransform);
1111
+ };
1112
+ this.handleClick = (e, d) => {
1113
+ let recursive = this.options.toggleRecursively;
1114
+ if (e.ctrlKey) recursive = !recursive;
1115
+ this.toggleNode(d.data, recursive);
1116
+ };
1014
1117
  this.viewHooks = createViewHooks();
1015
1118
  this.svg = svg.datum ? svg : d3__namespace.select(svg);
1016
1119
  this.styleNode = this.svg.append('style');
@@ -1023,7 +1126,11 @@ class Markmap {
1023
1126
  }).on('zoom', this.handleZoom);
1024
1127
  this.setOptions(opts);
1025
1128
  this.state = {
1026
- id: this.options.id || this.svg.attr('id') || getId()
1129
+ id: this.options.id || this.svg.attr('id') || getId(),
1130
+ minX: 0,
1131
+ maxX: 0,
1132
+ minY: 0,
1133
+ maxY: 0
1027
1134
  };
1028
1135
  this.g = this.svg.append('g');
1029
1136
  this.revokers.push(refreshHook.tap(() => {
@@ -1045,18 +1152,6 @@ class Markmap {
1045
1152
  const style = this.getStyleContent();
1046
1153
  this.styleNode.text(style);
1047
1154
  }
1048
- handleZoom(e) {
1049
- const {
1050
- transform
1051
- } = e;
1052
- this.g.attr('transform', transform);
1053
- }
1054
- handlePan(e) {
1055
- e.preventDefault();
1056
- const transform = d3__namespace.zoomTransform(this.svg.node());
1057
- const newTransform = transform.translate(-e.deltaX / transform.k, -e.deltaY / transform.k);
1058
- this.svg.call(this.zoom.transform, newTransform);
1059
- }
1060
1155
  toggleNode(data, recursive = false) {
1061
1156
  var _data$payload;
1062
1157
  const fold = (_data$payload = data.payload) != null && _data$payload.fold ? 0 : 1;
@@ -1076,11 +1171,6 @@ class Markmap {
1076
1171
  }
1077
1172
  this.renderData(data);
1078
1173
  }
1079
- handleClick(e, d) {
1080
- let recursive = this.options.toggleRecursively;
1081
- if (e.ctrlKey) recursive = !recursive;
1082
- this.toggleNode(d.data, recursive);
1083
- }
1084
1174
  initializeData(node) {
1085
1175
  let nodeId = 0;
1086
1176
  const {
@@ -1140,14 +1230,16 @@ class Markmap {
1140
1230
  // `white-space: nowrap` gets re-layouted, then we will get the expected layout, with
1141
1231
  // content in one line as much as possible, and subjecting to the given max-width.
1142
1232
  nodes.forEach(node => {
1143
- node.parentNode.append(node.cloneNode(true));
1233
+ var _node$parentNode;
1234
+ (_node$parentNode = node.parentNode) == null ? void 0 : _node$parentNode.append(node.cloneNode(true));
1144
1235
  });
1145
1236
  walkTree(node, (item, next, parent) => {
1146
1237
  var _parent$state2;
1147
- const rect = item.state.el.getBoundingClientRect();
1148
- item.content = item.state.el.innerHTML;
1149
- item.state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
1150
- item.state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, item.state.id].filter(Boolean).join('.') +
1238
+ const state = item.state;
1239
+ const rect = state.el.getBoundingClientRect();
1240
+ item.content = state.el.innerHTML;
1241
+ state.size = [Math.ceil(rect.width) + 1, Math.max(Math.ceil(rect.height), nodeMinHeight)];
1242
+ state.key = [parent == null || (_parent$state2 = parent.state) == null ? void 0 : _parent$state2.id, state.id].filter(Boolean).join('.') +
1151
1243
  // FIXME: find a way to check content hash
1152
1244
  item.content;
1153
1245
  next();
@@ -1156,17 +1248,21 @@ class Markmap {
1156
1248
  style.remove();
1157
1249
  }
1158
1250
  setOptions(opts) {
1159
- this.options = _extends({}, Markmap.defaultOptions, opts);
1251
+ this.options = _extends({}, this.options, opts);
1160
1252
  if (this.options.zoom) {
1161
1253
  this.svg.call(this.zoom);
1162
1254
  } else {
1163
1255
  this.svg.on('.zoom', null);
1164
1256
  }
1165
- this.svg.on('wheel', this.options.pan ? this.handlePan : null);
1257
+ if (this.options.pan) {
1258
+ this.svg.on('wheel', this.handlePan);
1259
+ } else {
1260
+ this.svg.on('wheel', null);
1261
+ }
1166
1262
  }
1167
1263
  setData(data, opts) {
1168
- if (data) this.state.data = data;
1169
1264
  if (opts) this.setOptions(opts);
1265
+ if (data) this.state.data = data;
1170
1266
  if (!this.state.data) return;
1171
1267
  this.initializeData(this.state.data);
1172
1268
  this.updateStyle();
@@ -1182,25 +1278,24 @@ class Markmap {
1182
1278
  autoFit,
1183
1279
  color
1184
1280
  } = this.options;
1185
- const layout = flextree().children(d => {
1281
+ const layout = flextree({}).children(d => {
1186
1282
  var _d$payload;
1187
- return !((_d$payload = d.payload) != null && _d$payload.fold) && d.children;
1188
- }).nodeSize(d => {
1189
- const [width, height] = d.data.state.size;
1283
+ if (!((_d$payload = d.payload) != null && _d$payload.fold)) return d.children;
1284
+ }).nodeSize(node => {
1285
+ const [width, height] = node.data.state.size;
1190
1286
  return [height, width + (width ? paddingX * 2 : 0) + spacingHorizontal];
1191
1287
  }).spacing((a, b) => {
1192
1288
  return a.parent === b.parent ? spacingVertical : spacingVertical * 2;
1193
1289
  });
1194
1290
  const tree = layout.hierarchy(this.state.data);
1195
1291
  layout(tree);
1196
- adjustSpacing(tree, spacingHorizontal);
1197
1292
  const descendants = tree.descendants().reverse();
1198
1293
  const links = tree.links();
1199
1294
  const linkShape = d3__namespace.linkHorizontal();
1200
1295
  const minX = d3__namespace.min(descendants, d => d.x - d.xSize / 2);
1201
1296
  const maxX = d3__namespace.max(descendants, d => d.x + d.xSize / 2);
1202
1297
  const minY = d3__namespace.min(descendants, d => d.y);
1203
- const maxY = d3__namespace.max(descendants, d => d.y + d.ySizeInner);
1298
+ const maxY = d3__namespace.max(descendants, d => d.y + d.ySize - spacingHorizontal);
1204
1299
  Object.assign(this.state, {
1205
1300
  minX,
1206
1301
  maxX,
@@ -1214,11 +1309,11 @@ class Markmap {
1214
1309
 
1215
1310
  // Update the nodes
1216
1311
  const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.state.key);
1217
- 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})`);
1312
+ 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})`);
1218
1313
  const nodeExit = this.transition(node.exit());
1219
- nodeExit.select('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1314
+ nodeExit.select('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1220
1315
  nodeExit.select('foreignObject').style('opacity', 0);
1221
- nodeExit.attr('transform', d => `translate(${origin.y + origin.ySizeInner - d.ySizeInner},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1316
+ nodeExit.attr('transform', d => `translate(${origin.y + origin.ySize - d.ySize},${origin.x + origin.xSize / 2 - d.xSize})`).remove();
1222
1317
  const nodeMerge = node.merge(nodeEnter).attr('class', d => {
1223
1318
  var _d$data$payload;
1224
1319
  return ['markmap-node', ((_d$data$payload = d.data.payload) == null ? void 0 : _d$data$payload.fold) && 'markmap-fold'].filter(Boolean).join(' ');
@@ -1227,15 +1322,18 @@ class Markmap {
1227
1322
 
1228
1323
  // Update lines under the content
1229
1324
  const line = nodeMerge.selectAll(childSelector('line')).data(d => [d], d => d.data.state.key).join(enter => {
1230
- return enter.append('line').attr('x1', d => d.ySizeInner).attr('x2', d => d.ySizeInner);
1325
+ return enter.append('line').attr('x1', d => d.ySize - spacingHorizontal).attr('x2', d => d.ySize - spacingHorizontal);
1231
1326
  }, update => update, exit => exit.remove());
1232
- 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);
1327
+ 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);
1233
1328
 
1234
1329
  // Circle to link to children of the node
1235
- const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.children ? [d] : [], d => d.data.state.key).join(enter => {
1236
- 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);
1330
+ const circle = nodeMerge.selectAll(childSelector('circle')).data(d => {
1331
+ var _d$data$children;
1332
+ return (_d$data$children = d.data.children) != null && _d$data$children.length ? [d] : [];
1333
+ }, d => d.data.state.key).join(enter => {
1334
+ 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);
1237
1335
  }, update => update, exit => exit.remove());
1238
- 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 => {
1336
+ 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 => {
1239
1337
  var _d$data$payload2;
1240
1338
  return (_d$data$payload2 = d.data.payload) != null && _d$data$payload2.fold && d.data.children ? color(d.data) : '#fff';
1241
1339
  });
@@ -1247,26 +1345,28 @@ class Markmap {
1247
1345
  return clone;
1248
1346
  }).attr('xmlns', 'http://www.w3.org/1999/xhtml');
1249
1347
  return fo;
1250
- }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySizeInner - paddingX * 2)).attr('height', d => d.xSize);
1348
+ }, update => update, exit => exit.remove()).attr('width', d => Math.max(0, d.ySize - spacingHorizontal - paddingX * 2)).attr('height', d => d.xSize);
1251
1349
  this.transition(foreignObject).style('opacity', 1);
1252
1350
 
1253
1351
  // Update the links
1254
1352
  const path = this.g.selectAll(childSelector('path')).data(links, d => d.target.data.state.key).join(enter => {
1255
- const source = [y0 + origin.ySizeInner, x0 + origin.xSize / 2];
1353
+ const source = [y0 + origin.ySize - spacingHorizontal, x0 + origin.xSize / 2];
1256
1354
  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({
1257
1355
  source,
1258
1356
  target: source
1259
1357
  }));
1260
1358
  }, update => update, exit => {
1261
- const source = [origin.y + origin.ySizeInner, origin.x + origin.xSize / 2];
1359
+ const source = [origin.y + origin.ySize - spacingHorizontal, origin.x + origin.xSize / 2];
1262
1360
  return this.transition(exit).attr('d', linkShape({
1263
1361
  source,
1264
1362
  target: source
1265
1363
  })).remove();
1266
1364
  });
1267
1365
  this.transition(path).attr('stroke', d => color(d.target.data)).attr('stroke-width', d => linkWidth(d.target)).attr('d', d => {
1268
- const source = [d.source.y + d.source.ySizeInner, d.source.x + d.source.xSize / 2];
1269
- const target = [d.target.y, d.target.x + d.target.xSize / 2];
1366
+ const origSource = d.source;
1367
+ const origTarget = d.target;
1368
+ const source = [origSource.y + origSource.ySize - spacingHorizontal, origSource.x + origSource.xSize / 2];
1369
+ const target = [origTarget.y, origTarget.x + origTarget.xSize / 2];
1270
1370
  return linkShape({
1271
1371
  source,
1272
1372
  target
@@ -1321,9 +1421,12 @@ class Markmap {
1321
1421
  });
1322
1422
  if (!itemData) return;
1323
1423
  const svgNode = this.svg.node();
1424
+ const {
1425
+ spacingHorizontal
1426
+ } = this.options;
1324
1427
  const relRect = svgNode.getBoundingClientRect();
1325
1428
  const transform = d3__namespace.zoomTransform(svgNode);
1326
- const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x);
1429
+ const [left, right] = [itemData.y, itemData.y + itemData.ySize - spacingHorizontal + 2].map(x => x * transform.k + transform.x);
1327
1430
  const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y);
1328
1431
  // Skip if the node includes or is included in the container.
1329
1432
  const pd = _extends({
@@ -1364,7 +1467,7 @@ class Markmap {
1364
1467
  fn();
1365
1468
  });
1366
1469
  }
1367
- static create(svg, opts, data) {
1470
+ static create(svg, opts, data = null) {
1368
1471
  const mm = new Markmap(svg, opts);
1369
1472
  if (data) {
1370
1473
  mm.setData(data);
@@ -1376,7 +1479,10 @@ class Markmap {
1376
1479
  }
1377
1480
  Markmap.defaultOptions = {
1378
1481
  autoFit: false,
1379
- color: node => defaultColorFn(`${node.state.path}`),
1482
+ color: node => {
1483
+ var _node$state;
1484
+ return defaultColorFn(`${((_node$state = node.state) == null ? void 0 : _node$state.path) || ''}`);
1485
+ },
1380
1486
  duration: 500,
1381
1487
  embedGlobalCSS: true,
1382
1488
  fitRatio: 0.95,
@@ -1392,22 +1498,22 @@ Markmap.defaultOptions = {
1392
1498
  toggleRecursively: false
1393
1499
  };
1394
1500
  function deriveOptions(jsonOptions) {
1395
- const opts = {};
1396
- jsonOptions || (jsonOptions = {});
1501
+ const derivedOptions = {};
1502
+ const options = _extends({}, jsonOptions);
1397
1503
  const {
1398
1504
  color,
1399
1505
  colorFreezeLevel
1400
- } = jsonOptions;
1506
+ } = options;
1401
1507
  if ((color == null ? void 0 : color.length) === 1) {
1402
1508
  const solidColor = color[0];
1403
- opts.color = () => solidColor;
1509
+ derivedOptions.color = () => solidColor;
1404
1510
  } else if (color != null && color.length) {
1405
1511
  const colorFn = d3__namespace.scaleOrdinal(color);
1406
- opts.color = node => colorFn(`${node.state.path}`);
1512
+ derivedOptions.color = node => colorFn(`${node.state.path}`);
1407
1513
  }
1408
1514
  if (colorFreezeLevel) {
1409
- const color = opts.color || Markmap.defaultOptions.color;
1410
- opts.color = node => {
1515
+ const color = derivedOptions.color || Markmap.defaultOptions.color;
1516
+ derivedOptions.color = node => {
1411
1517
  node = _extends({}, node, {
1412
1518
  state: _extends({}, node.state, {
1413
1519
  path: node.state.path.split('.').slice(0, colorFreezeLevel).join('.')
@@ -1418,15 +1524,15 @@ function deriveOptions(jsonOptions) {
1418
1524
  }
1419
1525
  const numberKeys = ['duration', 'maxWidth', 'initialExpandLevel'];
1420
1526
  numberKeys.forEach(key => {
1421
- const value = jsonOptions[key];
1422
- if (typeof value === 'number') opts[key] = value;
1527
+ const value = options[key];
1528
+ if (typeof value === 'number') derivedOptions[key] = value;
1423
1529
  });
1424
1530
  const booleanKeys = ['zoom', 'pan'];
1425
1531
  booleanKeys.forEach(key => {
1426
- const value = jsonOptions[key];
1427
- if (value != null) opts[key] = !!value;
1532
+ const value = options[key];
1533
+ if (value != null) derivedOptions[key] = !!value;
1428
1534
  });
1429
- return opts;
1535
+ return derivedOptions;
1430
1536
  }
1431
1537
 
1432
1538
  exports.Markmap = Markmap;