markmap-lib 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.
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.14.5-alpha.13+50ca560 | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.16+33e8294 | MIT License */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('katex')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'katex'], factory) :
@@ -20,7 +20,7 @@ function _extends$1() {
20
20
  return _extends$1.apply(this, arguments);
21
21
  }
22
22
 
23
- /*! markmap-common v0.14.5-alpha.13+50ca560 | MIT License */
23
+ /*! markmap-common v0.14.5-alpha.16+33e8294 | MIT License */
24
24
  class Hook {
25
25
  constructor() {
26
26
  this.listeners = [];
@@ -69,12 +69,13 @@ function _objectWithoutPropertiesLoose(source, excluded) {
69
69
  return target;
70
70
  }
71
71
  const _excluded = ["textContent"];
72
+ const escapeChars = {
73
+ '&': '&',
74
+ '<': '&lt;',
75
+ '"': '&quot;'
76
+ };
72
77
  function escapeHtml$1(html) {
73
- return html.replace(/[&<"]/g, m => ({
74
- '&': '&amp;',
75
- '<': '&lt;',
76
- '"': '&quot;'
77
- })[m]);
78
+ return html.replace(/[&<"]/g, m => escapeChars[m]);
78
79
  }
79
80
  function escapeScript(content) {
80
81
  return content.replace(/<(\/script>)/g, '\\x3c$2');
@@ -154,6 +155,161 @@ function memoize(fn) {
154
155
  return data.value;
155
156
  };
156
157
  }
158
+
159
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
160
+ const VTYPE_ELEMENT = 1;
161
+ const VTYPE_FUNCTION = 2;
162
+ const SVG_NS = 'http://www.w3.org/2000/svg';
163
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
164
+ const NS_ATTRS = {
165
+ show: XLINK_NS,
166
+ actuate: XLINK_NS,
167
+ href: XLINK_NS
168
+ };
169
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
170
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
171
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
172
+ function h(type, props, ...children) {
173
+ props = Object.assign({}, props, {
174
+ children: children.length === 1 ? children[0] : children
175
+ });
176
+ return jsx(type, props);
177
+ }
178
+ function jsx(type, props) {
179
+ let vtype;
180
+ if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
181
+ return {
182
+ vtype,
183
+ type,
184
+ props
185
+ };
186
+ }
187
+ function Fragment(props) {
188
+ return props.children;
189
+ }
190
+ const DEFAULT_ENV = {
191
+ isSvg: false
192
+ };
193
+ function insertDom(parent, nodes) {
194
+ if (!Array.isArray(nodes)) nodes = [nodes];
195
+ nodes = nodes.filter(Boolean);
196
+ if (nodes.length) parent.append(...nodes);
197
+ }
198
+ function mountAttributes(domElement, props, env) {
199
+ for (const key in props) {
200
+ if (key === 'key' || key === 'children' || key === 'ref') continue;
201
+ if (key === 'dangerouslySetInnerHTML') {
202
+ domElement.innerHTML = props[key].__html;
203
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
204
+ const value = props[key];
205
+ if (value != null) domElement[key] = value;
206
+ } else if (key.startsWith('on')) {
207
+ domElement[key.toLowerCase()] = props[key];
208
+ } else {
209
+ setDOMAttribute(domElement, key, props[key], env.isSvg);
210
+ }
211
+ }
212
+ }
213
+ const attrMap = {
214
+ className: 'class',
215
+ labelFor: 'for'
216
+ };
217
+ function setDOMAttribute(el, attr, value, isSVG) {
218
+ attr = attrMap[attr] || attr;
219
+ if (value === true) {
220
+ el.setAttribute(attr, '');
221
+ } else if (value === false) {
222
+ el.removeAttribute(attr);
223
+ } else {
224
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
225
+ if (namespace !== undefined) {
226
+ el.setAttributeNS(namespace, attr, value);
227
+ } else {
228
+ el.setAttribute(attr, value);
229
+ }
230
+ }
231
+ }
232
+ function flatten(arr) {
233
+ return arr.reduce((prev, item) => prev.concat(item), []);
234
+ }
235
+ function mountChildren(children, env) {
236
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
237
+ }
238
+ function mount(vnode, env = DEFAULT_ENV) {
239
+ if (vnode == null || typeof vnode === 'boolean') {
240
+ return null;
241
+ }
242
+ if (vnode instanceof Node) {
243
+ return vnode;
244
+ }
245
+ if (isRenderFunction(vnode)) {
246
+ const {
247
+ type,
248
+ props
249
+ } = vnode;
250
+ if (type === Fragment) {
251
+ const node = document.createDocumentFragment();
252
+ if (props.children) {
253
+ const children = mountChildren(props.children, env);
254
+ insertDom(node, children);
255
+ }
256
+ return node;
257
+ }
258
+ const childVNode = type(props);
259
+ return mount(childVNode, env);
260
+ }
261
+ if (isLeaf(vnode)) {
262
+ return document.createTextNode(`${vnode}`);
263
+ }
264
+ if (isElement(vnode)) {
265
+ let node;
266
+ const {
267
+ type,
268
+ props
269
+ } = vnode;
270
+ if (!env.isSvg && type === 'svg') {
271
+ env = Object.assign({}, env, {
272
+ isSvg: true
273
+ });
274
+ }
275
+ if (!env.isSvg) {
276
+ node = document.createElement(type);
277
+ } else {
278
+ node = document.createElementNS(SVG_NS, type);
279
+ }
280
+ mountAttributes(node, props, env);
281
+ if (props.children) {
282
+ let childEnv = env;
283
+ if (env.isSvg && type === 'foreignObject') {
284
+ childEnv = Object.assign({}, childEnv, {
285
+ isSvg: false
286
+ });
287
+ }
288
+ const children = mountChildren(props.children, childEnv);
289
+ if (children != null) insertDom(node, children);
290
+ }
291
+ const {
292
+ ref
293
+ } = props;
294
+ if (typeof ref === 'function') ref(node);
295
+ return node;
296
+ }
297
+ throw new Error('mount: Invalid Vnode!');
298
+ }
299
+
300
+ /**
301
+ * Mount vdom as real DOM nodes.
302
+ */
303
+ function mountDom(vnode) {
304
+ return mount(vnode);
305
+ }
306
+
307
+ /**
308
+ * Render and mount without returning VirtualDOM, useful when you don't need SVG support.
309
+ */
310
+ function hm(...args) {
311
+ return mountDom(h(...args));
312
+ }
157
313
  const providers = {
158
314
  jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
159
315
  unpkg: path => `https://unpkg.com/${path}`
@@ -165,22 +321,8 @@ function cdnUrl(provider, path) {
165
321
  }
166
322
  return factory(path);
167
323
  }
168
- function createElement(tagName, props, attrs) {
169
- const el = document.createElement(tagName);
170
- if (props) {
171
- Object.entries(props).forEach(([key, value]) => {
172
- el[key] = value;
173
- });
174
- }
175
- if (attrs) {
176
- Object.entries(attrs).forEach(([key, value]) => {
177
- el.setAttribute(key, value);
178
- });
179
- }
180
- return el;
181
- }
182
324
  const memoizedPreloadJS = memoize(url => {
183
- document.head.append(createElement('link', {
325
+ document.head.append(hm('link', {
184
326
  rel: 'preload',
185
327
  as: 'script',
186
328
  href: url
@@ -191,9 +333,9 @@ async function loadJSItem(item, context) {
191
333
  if (item.type === 'script') {
192
334
  item.loaded = new Promise((resolve, reject) => {
193
335
  var _item$data;
194
- document.head.append(createElement('script', _extends({}, item.data, {
195
- onload: resolve,
196
- onerror: reject
336
+ document.head.append(hm('script', _extends({}, item.data, {
337
+ onLoad: resolve,
338
+ onError: reject
197
339
  })));
198
340
  // Run inline script synchronously
199
341
  if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
@@ -213,11 +355,12 @@ async function loadJSItem(item, context) {
213
355
  await item.loaded;
214
356
  }
215
357
  async function loadJS(items, context) {
216
- const needPreload = items.filter(item => {
358
+ items.forEach(item => {
217
359
  var _item$data2;
218
- return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
360
+ if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
361
+ memoizedPreloadJS(item.data.src);
362
+ }
219
363
  });
220
- if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
221
364
  context = _extends({
222
365
  getMarkmap: () => window.markmap
223
366
  }, context);
@@ -226,33 +369,33 @@ async function loadJS(items, context) {
226
369
  }
227
370
  }
228
371
  let provider = 'jsdelivr';
229
- function getFullUrl(path) {
372
+ function getFullUrl(path, overrideProvider = provider) {
230
373
  if (path.includes('://')) return path;
231
- return cdnUrl(provider, path);
374
+ return cdnUrl(overrideProvider, path);
232
375
  }
233
- function buildJSItem(path) {
376
+ function buildJSItem(path, overrideProvider) {
234
377
  return {
235
378
  type: 'script',
236
379
  data: {
237
- src: getFullUrl(path)
380
+ src: getFullUrl(path, overrideProvider)
238
381
  }
239
382
  };
240
383
  }
241
- function buildCSSItem(path) {
384
+ function buildCSSItem(path, overrideProvider) {
242
385
  return {
243
386
  type: 'stylesheet',
244
387
  data: {
245
- href: getFullUrl(path)
388
+ href: getFullUrl(path, overrideProvider)
246
389
  }
247
390
  };
248
391
  }
249
392
 
250
- const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n";
251
- const baseJsPaths = [`d3@${"6.2.0"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`];
393
+ const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n" ;
394
+ const baseJsPaths = [`d3@${"6.2.0"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.16+33e8294"}/dist/browser/index.js`];
252
395
  function fillTemplate(root, assets, extra) {
253
396
  var _extra, _extra$baseJs;
254
397
  extra = _extends$1({}, extra);
255
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(buildJSItem);
398
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => buildJSItem(path));
256
399
  const {
257
400
  scripts,
258
401
  styles
@@ -7546,14 +7689,14 @@ var remarkableKatex = rkatex;
7546
7689
  var remarkableKatex$1 = /*@__PURE__*/getDefaultExportFromCjs(remarkableKatex);
7547
7690
 
7548
7691
  function getConfig$1() {
7549
- const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(buildJSItem);
7692
+ const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(path => buildJSItem(path));
7550
7693
  const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
7551
7694
  webfontloader.data.defer = true;
7552
- const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(buildCSSItem);
7695
+ const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(path => buildCSSItem(path));
7553
7696
  return {
7554
7697
  versions: {
7555
- katex: "0.16.0",
7556
- webfontloader: "1.6.28"
7698
+ katex: "0.16.0" ,
7699
+ webfontloader: "1.6.28"
7557
7700
  },
7558
7701
  preloadScripts,
7559
7702
  scripts: [{
@@ -7646,7 +7789,7 @@ var katex = definePlugin(() => {
7646
7789
  md.use(remarkableKatex$1);
7647
7790
  md.renderer.rules.katex = (tokens, idx) => {
7648
7791
  enableFeature();
7649
- const result = renderKatex(tokens[idx].content, tokens[idx].block);
7792
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
7650
7793
  return result;
7651
7794
  };
7652
7795
  });
@@ -7656,13 +7799,13 @@ var katex = definePlugin(() => {
7656
7799
  };
7657
7800
  });
7658
7801
  transformHooks.afterParse.tap((_, context) => {
7659
- const {
7660
- frontmatter
7661
- } = context;
7662
- if (frontmatter != null && frontmatter.markmap) {
7802
+ var _context$frontmatter;
7803
+ const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
7804
+ if (markmap) {
7663
7805
  ['extraJs', 'extraCss'].forEach(key => {
7664
- if (frontmatter.markmap[key]) {
7665
- frontmatter.markmap[key] = addDefaultVersions(frontmatter.markmap[key], name$3, plugin.config.versions.katex);
7806
+ const value = markmap[key];
7807
+ if (value) {
7808
+ markmap[key] = addDefaultVersions(value, name$3, plugin.config.versions.katex);
7666
7809
  }
7667
7810
  });
7668
7811
  }
@@ -7677,11 +7820,11 @@ var katex = definePlugin(() => {
7677
7820
  });
7678
7821
 
7679
7822
  function getConfig() {
7680
- const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(buildJSItem);
7681
- const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(buildCSSItem);
7823
+ const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(path => buildJSItem(path));
7824
+ const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(path => buildCSSItem(path));
7682
7825
  return {
7683
7826
  versions: {
7684
- prismjs: "1.28.0"
7827
+ prismjs: "1.28.0"
7685
7828
  },
7686
7829
  preloadScripts,
7687
7830
  styles
@@ -10906,10 +11049,12 @@ var npmUrl = definePlugin({
10906
11049
  const {
10907
11050
  frontmatter
10908
11051
  } = context;
10909
- if (frontmatter != null && frontmatter.markmap) {
11052
+ const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
11053
+ if (markmap) {
10910
11054
  ['extraJs', 'extraCss'].forEach(key => {
10911
- if (frontmatter.markmap[key]) {
10912
- frontmatter.markmap[key] = frontmatter.markmap[key].map(path => {
11055
+ const value = markmap[key];
11056
+ if (value) {
11057
+ markmap[key] = value.map(path => {
10913
11058
  if (path.startsWith('npm:')) {
10914
11059
  return getFullUrl(path.slice(4));
10915
11060
  }
@@ -10957,9 +11102,7 @@ function cleanNode(node) {
10957
11102
  }
10958
11103
  });
10959
11104
  }
10960
- if (node.children.length === 0) {
10961
- delete node.children;
10962
- } else {
11105
+ if (node.children.length > 0) {
10963
11106
  node.children.forEach(child => cleanNode(child));
10964
11107
  if (node.children.length === 1 && !node.children[0].content) {
10965
11108
  node.children = node.children[0].children;
@@ -10967,9 +11110,8 @@ function cleanNode(node) {
10967
11110
  }
10968
11111
  }
10969
11112
  function resetDepth(node, depth = 0) {
10970
- var _node$children;
10971
11113
  node.depth = depth;
10972
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
11114
+ node.children.forEach(child => {
10973
11115
  resetDepth(child, depth + 1);
10974
11116
  });
10975
11117
  }
@@ -11057,10 +11199,13 @@ class Transformer {
11057
11199
  }
11058
11200
  } else if (token.type === 'inline') {
11059
11201
  const revoke = this.hooks.htmltag.tap(ctx => {
11060
- const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
11202
+ var _ctx$result;
11203
+ const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
11061
11204
  const data = comment == null ? void 0 : comment[1].trim().split(' ');
11062
- if (data[0] === 'fold') {
11063
- current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
11205
+ if ((data == null ? void 0 : data[0]) === 'fold') {
11206
+ current.payload = _extends$1({}, current.payload, {
11207
+ fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
11208
+ });
11064
11209
  ctx.result = '';
11065
11210
  }
11066
11211
  });
@@ -11131,7 +11276,7 @@ class Transformer {
11131
11276
  }
11132
11277
 
11133
11278
  const transformerVersions = {
11134
- 'markmap-lib': '0.14.5-alpha.13+50ca560',
11279
+ 'markmap-lib': '0.14.5-alpha.16+33e8294',
11135
11280
  d3: "6.2.0"
11136
11281
  };
11137
11282
 
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.14.5-alpha.13+50ca560 | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.16+33e8294 | MIT License */
2
2
  import require$$0 from 'katex';
3
3
 
4
4
  function _extends$1() {
@@ -16,7 +16,7 @@ function _extends$1() {
16
16
  return _extends$1.apply(this, arguments);
17
17
  }
18
18
 
19
- /*! markmap-common v0.14.5-alpha.13+50ca560 | MIT License */
19
+ /*! markmap-common v0.14.5-alpha.16+33e8294 | MIT License */
20
20
  class Hook {
21
21
  constructor() {
22
22
  this.listeners = [];
@@ -65,12 +65,13 @@ function _objectWithoutPropertiesLoose(source, excluded) {
65
65
  return target;
66
66
  }
67
67
  const _excluded = ["textContent"];
68
+ const escapeChars = {
69
+ '&': '&amp;',
70
+ '<': '&lt;',
71
+ '"': '&quot;'
72
+ };
68
73
  function escapeHtml$1(html) {
69
- return html.replace(/[&<"]/g, m => ({
70
- '&': '&amp;',
71
- '<': '&lt;',
72
- '"': '&quot;'
73
- })[m]);
74
+ return html.replace(/[&<"]/g, m => escapeChars[m]);
74
75
  }
75
76
  function escapeScript(content) {
76
77
  return content.replace(/<(\/script>)/g, '\\x3c$2');
@@ -150,6 +151,161 @@ function memoize(fn) {
150
151
  return data.value;
151
152
  };
152
153
  }
154
+
155
+ /*! @gera2ld/jsx-dom v2.2.2 | ISC License */
156
+ const VTYPE_ELEMENT = 1;
157
+ const VTYPE_FUNCTION = 2;
158
+ const SVG_NS = 'http://www.w3.org/2000/svg';
159
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
160
+ const NS_ATTRS = {
161
+ show: XLINK_NS,
162
+ actuate: XLINK_NS,
163
+ href: XLINK_NS
164
+ };
165
+ const isLeaf = c => typeof c === 'string' || typeof c === 'number';
166
+ const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
167
+ const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
168
+ function h(type, props, ...children) {
169
+ props = Object.assign({}, props, {
170
+ children: children.length === 1 ? children[0] : children
171
+ });
172
+ return jsx(type, props);
173
+ }
174
+ function jsx(type, props) {
175
+ let vtype;
176
+ if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
177
+ return {
178
+ vtype,
179
+ type,
180
+ props
181
+ };
182
+ }
183
+ function Fragment(props) {
184
+ return props.children;
185
+ }
186
+ const DEFAULT_ENV = {
187
+ isSvg: false
188
+ };
189
+ function insertDom(parent, nodes) {
190
+ if (!Array.isArray(nodes)) nodes = [nodes];
191
+ nodes = nodes.filter(Boolean);
192
+ if (nodes.length) parent.append(...nodes);
193
+ }
194
+ function mountAttributes(domElement, props, env) {
195
+ for (const key in props) {
196
+ if (key === 'key' || key === 'children' || key === 'ref') continue;
197
+ if (key === 'dangerouslySetInnerHTML') {
198
+ domElement.innerHTML = props[key].__html;
199
+ } else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
200
+ const value = props[key];
201
+ if (value != null) domElement[key] = value;
202
+ } else if (key.startsWith('on')) {
203
+ domElement[key.toLowerCase()] = props[key];
204
+ } else {
205
+ setDOMAttribute(domElement, key, props[key], env.isSvg);
206
+ }
207
+ }
208
+ }
209
+ const attrMap = {
210
+ className: 'class',
211
+ labelFor: 'for'
212
+ };
213
+ function setDOMAttribute(el, attr, value, isSVG) {
214
+ attr = attrMap[attr] || attr;
215
+ if (value === true) {
216
+ el.setAttribute(attr, '');
217
+ } else if (value === false) {
218
+ el.removeAttribute(attr);
219
+ } else {
220
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
221
+ if (namespace !== undefined) {
222
+ el.setAttributeNS(namespace, attr, value);
223
+ } else {
224
+ el.setAttribute(attr, value);
225
+ }
226
+ }
227
+ }
228
+ function flatten(arr) {
229
+ return arr.reduce((prev, item) => prev.concat(item), []);
230
+ }
231
+ function mountChildren(children, env) {
232
+ return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
233
+ }
234
+ function mount(vnode, env = DEFAULT_ENV) {
235
+ if (vnode == null || typeof vnode === 'boolean') {
236
+ return null;
237
+ }
238
+ if (vnode instanceof Node) {
239
+ return vnode;
240
+ }
241
+ if (isRenderFunction(vnode)) {
242
+ const {
243
+ type,
244
+ props
245
+ } = vnode;
246
+ if (type === Fragment) {
247
+ const node = document.createDocumentFragment();
248
+ if (props.children) {
249
+ const children = mountChildren(props.children, env);
250
+ insertDom(node, children);
251
+ }
252
+ return node;
253
+ }
254
+ const childVNode = type(props);
255
+ return mount(childVNode, env);
256
+ }
257
+ if (isLeaf(vnode)) {
258
+ return document.createTextNode(`${vnode}`);
259
+ }
260
+ if (isElement(vnode)) {
261
+ let node;
262
+ const {
263
+ type,
264
+ props
265
+ } = vnode;
266
+ if (!env.isSvg && type === 'svg') {
267
+ env = Object.assign({}, env, {
268
+ isSvg: true
269
+ });
270
+ }
271
+ if (!env.isSvg) {
272
+ node = document.createElement(type);
273
+ } else {
274
+ node = document.createElementNS(SVG_NS, type);
275
+ }
276
+ mountAttributes(node, props, env);
277
+ if (props.children) {
278
+ let childEnv = env;
279
+ if (env.isSvg && type === 'foreignObject') {
280
+ childEnv = Object.assign({}, childEnv, {
281
+ isSvg: false
282
+ });
283
+ }
284
+ const children = mountChildren(props.children, childEnv);
285
+ if (children != null) insertDom(node, children);
286
+ }
287
+ const {
288
+ ref
289
+ } = props;
290
+ if (typeof ref === 'function') ref(node);
291
+ return node;
292
+ }
293
+ throw new Error('mount: Invalid Vnode!');
294
+ }
295
+
296
+ /**
297
+ * Mount vdom as real DOM nodes.
298
+ */
299
+ function mountDom(vnode) {
300
+ return mount(vnode);
301
+ }
302
+
303
+ /**
304
+ * Render and mount without returning VirtualDOM, useful when you don't need SVG support.
305
+ */
306
+ function hm(...args) {
307
+ return mountDom(h(...args));
308
+ }
153
309
  const providers = {
154
310
  jsdelivr: path => `https://cdn.jsdelivr.net/npm/${path}`,
155
311
  unpkg: path => `https://unpkg.com/${path}`
@@ -161,22 +317,8 @@ function cdnUrl(provider, path) {
161
317
  }
162
318
  return factory(path);
163
319
  }
164
- function createElement(tagName, props, attrs) {
165
- const el = document.createElement(tagName);
166
- if (props) {
167
- Object.entries(props).forEach(([key, value]) => {
168
- el[key] = value;
169
- });
170
- }
171
- if (attrs) {
172
- Object.entries(attrs).forEach(([key, value]) => {
173
- el.setAttribute(key, value);
174
- });
175
- }
176
- return el;
177
- }
178
320
  const memoizedPreloadJS = memoize(url => {
179
- document.head.append(createElement('link', {
321
+ document.head.append(hm('link', {
180
322
  rel: 'preload',
181
323
  as: 'script',
182
324
  href: url
@@ -187,9 +329,9 @@ async function loadJSItem(item, context) {
187
329
  if (item.type === 'script') {
188
330
  item.loaded = new Promise((resolve, reject) => {
189
331
  var _item$data;
190
- document.head.append(createElement('script', _extends({}, item.data, {
191
- onload: resolve,
192
- onerror: reject
332
+ document.head.append(hm('script', _extends({}, item.data, {
333
+ onLoad: resolve,
334
+ onError: reject
193
335
  })));
194
336
  // Run inline script synchronously
195
337
  if (!((_item$data = item.data) != null && _item$data.src)) resolve(undefined);
@@ -209,11 +351,12 @@ async function loadJSItem(item, context) {
209
351
  await item.loaded;
210
352
  }
211
353
  async function loadJS(items, context) {
212
- const needPreload = items.filter(item => {
354
+ items.forEach(item => {
213
355
  var _item$data2;
214
- return item.type === 'script' && ((_item$data2 = item.data) == null ? void 0 : _item$data2.src);
356
+ if (item.type === 'script' && (_item$data2 = item.data) != null && _item$data2.src) {
357
+ memoizedPreloadJS(item.data.src);
358
+ }
215
359
  });
216
- if (needPreload.length > 1) needPreload.forEach(item => memoizedPreloadJS(item.data.src));
217
360
  context = _extends({
218
361
  getMarkmap: () => window.markmap
219
362
  }, context);
@@ -222,33 +365,33 @@ async function loadJS(items, context) {
222
365
  }
223
366
  }
224
367
  let provider = 'jsdelivr';
225
- function getFullUrl(path) {
368
+ function getFullUrl(path, overrideProvider = provider) {
226
369
  if (path.includes('://')) return path;
227
- return cdnUrl(provider, path);
370
+ return cdnUrl(overrideProvider, path);
228
371
  }
229
- function buildJSItem(path) {
372
+ function buildJSItem(path, overrideProvider) {
230
373
  return {
231
374
  type: 'script',
232
375
  data: {
233
- src: getFullUrl(path)
376
+ src: getFullUrl(path, overrideProvider)
234
377
  }
235
378
  };
236
379
  }
237
- function buildCSSItem(path) {
380
+ function buildCSSItem(path, overrideProvider) {
238
381
  return {
239
382
  type: 'stylesheet',
240
383
  data: {
241
- href: getFullUrl(path)
384
+ href: getFullUrl(path, overrideProvider)
242
385
  }
243
386
  };
244
387
  }
245
388
 
246
- const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n";
247
- const baseJsPaths = [`d3@${"6.2.0"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`];
389
+ const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n" ;
390
+ const baseJsPaths = [`d3@${"6.2.0"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.16+33e8294"}/dist/browser/index.js`];
248
391
  function fillTemplate(root, assets, extra) {
249
392
  var _extra, _extra$baseJs;
250
393
  extra = _extends$1({}, extra);
251
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(buildJSItem);
394
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => buildJSItem(path));
252
395
  const {
253
396
  scripts,
254
397
  styles
@@ -7542,14 +7685,14 @@ var remarkableKatex = rkatex;
7542
7685
  var remarkableKatex$1 = /*@__PURE__*/getDefaultExportFromCjs(remarkableKatex);
7543
7686
 
7544
7687
  function getConfig$1() {
7545
- const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(buildJSItem);
7688
+ const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(path => buildJSItem(path));
7546
7689
  const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
7547
7690
  webfontloader.data.defer = true;
7548
- const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(buildCSSItem);
7691
+ const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(path => buildCSSItem(path));
7549
7692
  return {
7550
7693
  versions: {
7551
- katex: "0.16.0",
7552
- webfontloader: "1.6.28"
7694
+ katex: "0.16.0" ,
7695
+ webfontloader: "1.6.28"
7553
7696
  },
7554
7697
  preloadScripts,
7555
7698
  scripts: [{
@@ -7642,7 +7785,7 @@ var katex = definePlugin(() => {
7642
7785
  md.use(remarkableKatex$1);
7643
7786
  md.renderer.rules.katex = (tokens, idx) => {
7644
7787
  enableFeature();
7645
- const result = renderKatex(tokens[idx].content, tokens[idx].block);
7788
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
7646
7789
  return result;
7647
7790
  };
7648
7791
  });
@@ -7652,13 +7795,13 @@ var katex = definePlugin(() => {
7652
7795
  };
7653
7796
  });
7654
7797
  transformHooks.afterParse.tap((_, context) => {
7655
- const {
7656
- frontmatter
7657
- } = context;
7658
- if (frontmatter != null && frontmatter.markmap) {
7798
+ var _context$frontmatter;
7799
+ const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
7800
+ if (markmap) {
7659
7801
  ['extraJs', 'extraCss'].forEach(key => {
7660
- if (frontmatter.markmap[key]) {
7661
- frontmatter.markmap[key] = addDefaultVersions(frontmatter.markmap[key], name$3, plugin.config.versions.katex);
7802
+ const value = markmap[key];
7803
+ if (value) {
7804
+ markmap[key] = addDefaultVersions(value, name$3, plugin.config.versions.katex);
7662
7805
  }
7663
7806
  });
7664
7807
  }
@@ -7673,11 +7816,11 @@ var katex = definePlugin(() => {
7673
7816
  });
7674
7817
 
7675
7818
  function getConfig() {
7676
- const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(buildJSItem);
7677
- const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(buildCSSItem);
7819
+ const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(path => buildJSItem(path));
7820
+ const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(path => buildCSSItem(path));
7678
7821
  return {
7679
7822
  versions: {
7680
- prismjs: "1.28.0"
7823
+ prismjs: "1.28.0"
7681
7824
  },
7682
7825
  preloadScripts,
7683
7826
  styles
@@ -10902,10 +11045,12 @@ var npmUrl = definePlugin({
10902
11045
  const {
10903
11046
  frontmatter
10904
11047
  } = context;
10905
- if (frontmatter != null && frontmatter.markmap) {
11048
+ const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
11049
+ if (markmap) {
10906
11050
  ['extraJs', 'extraCss'].forEach(key => {
10907
- if (frontmatter.markmap[key]) {
10908
- frontmatter.markmap[key] = frontmatter.markmap[key].map(path => {
11051
+ const value = markmap[key];
11052
+ if (value) {
11053
+ markmap[key] = value.map(path => {
10909
11054
  if (path.startsWith('npm:')) {
10910
11055
  return getFullUrl(path.slice(4));
10911
11056
  }
@@ -10953,9 +11098,7 @@ function cleanNode(node) {
10953
11098
  }
10954
11099
  });
10955
11100
  }
10956
- if (node.children.length === 0) {
10957
- delete node.children;
10958
- } else {
11101
+ if (node.children.length > 0) {
10959
11102
  node.children.forEach(child => cleanNode(child));
10960
11103
  if (node.children.length === 1 && !node.children[0].content) {
10961
11104
  node.children = node.children[0].children;
@@ -10963,9 +11106,8 @@ function cleanNode(node) {
10963
11106
  }
10964
11107
  }
10965
11108
  function resetDepth(node, depth = 0) {
10966
- var _node$children;
10967
11109
  node.depth = depth;
10968
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
11110
+ node.children.forEach(child => {
10969
11111
  resetDepth(child, depth + 1);
10970
11112
  });
10971
11113
  }
@@ -11053,10 +11195,13 @@ class Transformer {
11053
11195
  }
11054
11196
  } else if (token.type === 'inline') {
11055
11197
  const revoke = this.hooks.htmltag.tap(ctx => {
11056
- const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
11198
+ var _ctx$result;
11199
+ const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
11057
11200
  const data = comment == null ? void 0 : comment[1].trim().split(' ');
11058
- if (data[0] === 'fold') {
11059
- current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
11201
+ if ((data == null ? void 0 : data[0]) === 'fold') {
11202
+ current.payload = _extends$1({}, current.payload, {
11203
+ fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
11204
+ });
11060
11205
  ctx.result = '';
11061
11206
  }
11062
11207
  });
@@ -11127,7 +11272,7 @@ class Transformer {
11127
11272
  }
11128
11273
 
11129
11274
  const transformerVersions = {
11130
- 'markmap-lib': '0.14.5-alpha.13+50ca560',
11275
+ 'markmap-lib': '0.14.5-alpha.16+33e8294',
11131
11276
  d3: "6.2.0"
11132
11277
  };
11133
11278
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.14.5-alpha.13+50ca560 | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.16+33e8294 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var _extends = require('@babel/runtime/helpers/extends');
@@ -9,12 +9,12 @@ var Prism = require('prismjs');
9
9
  var loadLanguages = require('prismjs/components/index.js');
10
10
  var yaml = require('js-yaml');
11
11
 
12
- const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n";
13
- const baseJsPaths = [`d3@${"6.2.0"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`];
12
+ const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n" ;
13
+ const baseJsPaths = [`d3@${"6.2.0"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.16+33e8294"}/dist/browser/index.js`];
14
14
  function fillTemplate(root, assets, extra) {
15
15
  var _extra, _extra$baseJs;
16
16
  extra = _extends({}, extra);
17
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(markmapCommon.buildJSItem);
17
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => markmapCommon.buildJSItem(path));
18
18
  const {
19
19
  scripts,
20
20
  styles
@@ -48,14 +48,14 @@ function fillTemplate(root, assets, extra) {
48
48
  }
49
49
 
50
50
  function getConfig$1() {
51
- const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(markmapCommon.buildJSItem);
51
+ const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
52
52
  const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
53
53
  webfontloader.data.defer = true;
54
- const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(markmapCommon.buildCSSItem);
54
+ const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
55
55
  return {
56
56
  versions: {
57
- katex: "0.16.0",
58
- webfontloader: "1.6.28"
57
+ katex: "0.16.0" ,
58
+ webfontloader: "1.6.28"
59
59
  },
60
60
  preloadScripts,
61
61
  scripts: [{
@@ -128,11 +128,11 @@ var katex = definePlugin(() => {
128
128
  });
129
129
 
130
130
  function getConfig() {
131
- const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(markmapCommon.buildJSItem);
132
- const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(markmapCommon.buildCSSItem);
131
+ const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(path => markmapCommon.buildJSItem(path));
132
+ const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(path => markmapCommon.buildCSSItem(path));
133
133
  return {
134
134
  versions: {
135
- prismjs: "1.28.0"
135
+ prismjs: "1.28.0"
136
136
  },
137
137
  preloadScripts,
138
138
  styles
@@ -233,10 +233,12 @@ var npmUrl = definePlugin({
233
233
  const {
234
234
  frontmatter
235
235
  } = context;
236
- if (frontmatter != null && frontmatter.markmap) {
236
+ const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
237
+ if (markmap) {
237
238
  ['extraJs', 'extraCss'].forEach(key => {
238
- if (frontmatter.markmap[key]) {
239
- frontmatter.markmap[key] = frontmatter.markmap[key].map(path => {
239
+ const value = markmap[key];
240
+ if (value) {
241
+ markmap[key] = value.map(path => {
240
242
  if (path.startsWith('npm:')) {
241
243
  return markmapCommon.getFullUrl(path.slice(4));
242
244
  }
@@ -284,9 +286,7 @@ function cleanNode(node) {
284
286
  }
285
287
  });
286
288
  }
287
- if (node.children.length === 0) {
288
- delete node.children;
289
- } else {
289
+ if (node.children.length > 0) {
290
290
  node.children.forEach(child => cleanNode(child));
291
291
  if (node.children.length === 1 && !node.children[0].content) {
292
292
  node.children = node.children[0].children;
@@ -294,9 +294,8 @@ function cleanNode(node) {
294
294
  }
295
295
  }
296
296
  function resetDepth(node, depth = 0) {
297
- var _node$children;
298
297
  node.depth = depth;
299
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
298
+ node.children.forEach(child => {
300
299
  resetDepth(child, depth + 1);
301
300
  });
302
301
  }
@@ -384,10 +383,13 @@ class Transformer {
384
383
  }
385
384
  } else if (token.type === 'inline') {
386
385
  const revoke = this.hooks.htmltag.tap(ctx => {
387
- const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
386
+ var _ctx$result;
387
+ const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
388
388
  const data = comment == null ? void 0 : comment[1].trim().split(' ');
389
- if (data[0] === 'fold') {
390
- current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
389
+ if ((data == null ? void 0 : data[0]) === 'fold') {
390
+ current.payload = _extends({}, current.payload, {
391
+ fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
392
+ });
391
393
  ctx.result = '';
392
394
  }
393
395
  });
@@ -458,7 +460,7 @@ class Transformer {
458
460
  }
459
461
 
460
462
  const transformerVersions = {
461
- 'markmap-lib': '0.14.5-alpha.13+50ca560',
463
+ 'markmap-lib': '0.14.5-alpha.16+33e8294',
462
464
  d3: "6.2.0"
463
465
  };
464
466
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-lib v0.14.5-alpha.13+50ca560 | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.16+33e8294 | MIT License */
2
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
3
  import { buildJSItem, persistCSS, persistJS, buildCSSItem, Hook, wrapFunction, noop, getFullUrl } from 'markmap-common';
4
4
  import { Remarkable } from 'remarkable';
@@ -7,12 +7,12 @@ import Prism from 'prismjs';
7
7
  import loadLanguages from 'prismjs/components/index.js';
8
8
  import yaml from 'js-yaml';
9
9
 
10
- const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n";
11
- const baseJsPaths = [`d3@${"6.2.0"}`, `markmap-view@${"0.14.5-alpha.13+50ca560"}`];
10
+ const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n" ;
11
+ const baseJsPaths = [`d3@${"6.2.0"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.16+33e8294"}/dist/browser/index.js`];
12
12
  function fillTemplate(root, assets, extra) {
13
13
  var _extra, _extra$baseJs;
14
14
  extra = _extends({}, extra);
15
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(buildJSItem);
15
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => buildJSItem(path));
16
16
  const {
17
17
  scripts,
18
18
  styles
@@ -46,14 +46,14 @@ function fillTemplate(root, assets, extra) {
46
46
  }
47
47
 
48
48
  function getConfig$1() {
49
- const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(buildJSItem);
49
+ const preloadScripts = [`katex@${"0.16.0"}/dist/katex.min.js`].map(path => buildJSItem(path));
50
50
  const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
51
51
  webfontloader.data.defer = true;
52
- const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(buildCSSItem);
52
+ const styles = [`katex@${"0.16.0"}/dist/katex.min.css`].map(path => buildCSSItem(path));
53
53
  return {
54
54
  versions: {
55
- katex: "0.16.0",
56
- webfontloader: "1.6.28"
55
+ katex: "0.16.0" ,
56
+ webfontloader: "1.6.28"
57
57
  },
58
58
  preloadScripts,
59
59
  scripts: [{
@@ -126,11 +126,11 @@ var katex = definePlugin(() => {
126
126
  });
127
127
 
128
128
  function getConfig() {
129
- const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(buildJSItem);
130
- const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(buildCSSItem);
129
+ const preloadScripts = [`prismjs@${"1.28.0"}/components/prism-core.min.js`, `prismjs@${"1.28.0"}/plugins/autoloader/prism-autoloader.min.js`].map(path => buildJSItem(path));
130
+ const styles = [`prismjs@${"1.28.0"}/themes/prism.css`].map(path => buildCSSItem(path));
131
131
  return {
132
132
  versions: {
133
- prismjs: "1.28.0"
133
+ prismjs: "1.28.0"
134
134
  },
135
135
  preloadScripts,
136
136
  styles
@@ -231,10 +231,12 @@ var npmUrl = definePlugin({
231
231
  const {
232
232
  frontmatter
233
233
  } = context;
234
- if (frontmatter != null && frontmatter.markmap) {
234
+ const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
235
+ if (markmap) {
235
236
  ['extraJs', 'extraCss'].forEach(key => {
236
- if (frontmatter.markmap[key]) {
237
- frontmatter.markmap[key] = frontmatter.markmap[key].map(path => {
237
+ const value = markmap[key];
238
+ if (value) {
239
+ markmap[key] = value.map(path => {
238
240
  if (path.startsWith('npm:')) {
239
241
  return getFullUrl(path.slice(4));
240
242
  }
@@ -282,9 +284,7 @@ function cleanNode(node) {
282
284
  }
283
285
  });
284
286
  }
285
- if (node.children.length === 0) {
286
- delete node.children;
287
- } else {
287
+ if (node.children.length > 0) {
288
288
  node.children.forEach(child => cleanNode(child));
289
289
  if (node.children.length === 1 && !node.children[0].content) {
290
290
  node.children = node.children[0].children;
@@ -292,9 +292,8 @@ function cleanNode(node) {
292
292
  }
293
293
  }
294
294
  function resetDepth(node, depth = 0) {
295
- var _node$children;
296
295
  node.depth = depth;
297
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(child => {
296
+ node.children.forEach(child => {
298
297
  resetDepth(child, depth + 1);
299
298
  });
300
299
  }
@@ -382,10 +381,13 @@ class Transformer {
382
381
  }
383
382
  } else if (token.type === 'inline') {
384
383
  const revoke = this.hooks.htmltag.tap(ctx => {
385
- const comment = ctx.result.match(/^<!--([\s\S]*?)-->$/);
384
+ var _ctx$result;
385
+ const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
386
386
  const data = comment == null ? void 0 : comment[1].trim().split(' ');
387
- if (data[0] === 'fold') {
388
- current.payload.fold = ['all', 'recursively'].includes(data[1]) ? 2 : 1;
387
+ if ((data == null ? void 0 : data[0]) === 'fold') {
388
+ current.payload = _extends({}, current.payload, {
389
+ fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
390
+ });
389
391
  ctx.result = '';
390
392
  }
391
393
  });
@@ -456,7 +458,7 @@ class Transformer {
456
458
  }
457
459
 
458
460
  const transformerVersions = {
459
- 'markmap-lib': '0.14.5-alpha.13+50ca560',
461
+ 'markmap-lib': '0.14.5-alpha.16+33e8294',
460
462
  d3: "6.2.0"
461
463
  };
462
464
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-lib",
3
- "version": "0.14.5-alpha.13+50ca560",
3
+ "version": "0.14.5-alpha.16+33e8294",
4
4
  "description": "Visualize your Markdown as mindmaps with Markmap",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -47,8 +47,8 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/remarkable": "^2.0.3",
50
- "markmap-common": "0.14.5-alpha.13+50ca560",
51
- "markmap-view": "0.14.5-alpha.13+50ca560",
50
+ "markmap-common": "0.14.5-alpha.16+33e8294",
51
+ "markmap-view": "0.14.5-alpha.16+33e8294",
52
52
  "webfontloader": "^1.6.28"
53
53
  },
54
54
  "dependencies": {
@@ -62,5 +62,5 @@
62
62
  "peerDependencies": {
63
63
  "markmap-common": "*"
64
64
  },
65
- "gitHead": "50ca5603019498f93dba6485c96d0a5630b221e5"
65
+ "gitHead": "33e8294050d7438f6cdadd5bf06a665560585195"
66
66
  }
package/types/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export * from './template';
3
3
  export * from './transform';
4
4
  export declare const transformerVersions: {
5
5
  'markmap-lib': string;
6
- d3: string;
6
+ d3: string | undefined;
7
7
  };
@@ -1,7 +1,7 @@
1
- import { JSItem, INode, IMarkmapOptions, IMarkmapJSONOptions } from 'markmap-common';
1
+ import { JSItem, IMarkmapOptions, IMarkmapJSONOptions, IPureNode } from 'markmap-common';
2
2
  import { IAssets } from './types';
3
3
  export declare const baseJsPaths: string[];
4
- export declare function fillTemplate(root: INode | undefined, assets: IAssets, extra?: {
4
+ export declare function fillTemplate(root: IPureNode | null, assets: IAssets, extra?: {
5
5
  baseJs?: JSItem[];
6
6
  jsonOptions?: IMarkmapJSONOptions;
7
7
  getOptions?: (jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>;
@@ -1,5 +1,5 @@
1
1
  import { Remarkable } from 'remarkable';
2
- import { INode } from 'markmap-common';
2
+ import { IPureNode } from 'markmap-common';
3
3
  import { ITransformResult, ITransformPlugin, IAssets, ITransformHooks, IFeatures } from './types';
4
4
  import { plugins as builtInPlugins } from './plugins';
5
5
  export { builtInPlugins };
@@ -9,7 +9,7 @@ export declare class Transformer {
9
9
  assetsMap: Record<string, IAssets>;
10
10
  plugins: ITransformPlugin[];
11
11
  constructor(plugins?: Array<ITransformPlugin | (() => ITransformPlugin)>);
12
- buildTree(tokens: Remarkable.Token[]): INode;
12
+ buildTree(tokens: Remarkable.Token[]): IPureNode;
13
13
  transform(content: string): ITransformResult;
14
14
  /**
15
15
  * Get all assets from enabled plugins or filter them by plugin names as keys.
package/types/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Remarkable } from 'remarkable';
2
- import { CSSItem, JSItem, INode, IWrapContext, Hook, IMarkmapJSONOptions } from 'markmap-common';
2
+ import { CSSItem, JSItem, IPureNode, IWrapContext, Hook, IMarkmapJSONOptions } from 'markmap-common';
3
3
  type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>;
4
4
  export interface ITransformHooks {
5
5
  /**
@@ -51,7 +51,7 @@ export interface ITransformContext {
51
51
  contentLineOffset: number;
52
52
  }
53
53
  export interface ITransformResult extends ITransformContext {
54
- root: INode;
54
+ root: IPureNode;
55
55
  }
56
56
  export interface ITransformPlugin {
57
57
  name: string;