markmap-lib 0.15.5 → 0.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,50 +1,68 @@
1
- /*! markmap-lib v0.15.5 | MIT License */
2
- 'use strict';
3
-
4
- var _extends = require('@babel/runtime/helpers/extends');
5
- var remarkable = require('remarkable');
6
- var markmapCommon = require('markmap-common');
7
- var remarkableKatex = require('remarkable-katex');
8
- var yaml = require('js-yaml');
9
- var hljs = require('highlight.js');
10
-
11
- 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" ;
12
- const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.15.5"}/dist/browser/index.js`];
13
-
14
- const name$3 = 'katex';
15
- const preloadScripts$1 = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => markmapCommon.buildJSItem(path));
16
- const webfontloader = markmapCommon.buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const remarkable = require("remarkable");
4
+ const markmapCommon = require("markmap-common");
5
+ const remarkableKatex = require("remarkable-katex");
6
+ const yaml = require("js-yaml");
7
+ const hljs = require("highlight.js");
8
+ 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';
9
+ const baseJsPaths = [
10
+ `d3@${"7.8.5"}/dist/d3.min.js`,
11
+ `markmap-view@${"0.15.6"}/dist/browser/index.js`
12
+ ];
13
+ const name$3 = "katex";
14
+ const preloadScripts$1 = [
15
+ `katex@${"0.16.8"}/dist/katex.min.js`
16
+ ].map((path) => markmapCommon.buildJSItem(path));
17
+ const webfontloader = markmapCommon.buildJSItem(
18
+ `webfontloader@${"1.6.28"}/webfontloader.js`
19
+ );
17
20
  webfontloader.data.defer = true;
18
- const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => markmapCommon.buildCSSItem(path));
21
+ const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
22
+ (path) => markmapCommon.buildCSSItem(path)
23
+ );
19
24
  const config$1 = {
20
25
  versions: {
21
- katex: "0.16.8" ,
22
- webfontloader: "1.6.28"
26
+ katex: "0.16.8",
27
+ webfontloader: "1.6.28"
23
28
  },
24
29
  preloadScripts: preloadScripts$1,
25
- scripts: [{
26
- type: 'iife',
27
- data: {
28
- fn: getMarkmap => {
29
- window.WebFontConfig = {
30
- custom: {
31
- families: ['KaTeX_AMS', 'KaTeX_Caligraphic:n4,n7', 'KaTeX_Fraktur:n4,n7', 'KaTeX_Main:n4,n7,i4,i7', 'KaTeX_Math:i4,i7', 'KaTeX_Script', 'KaTeX_SansSerif:n4,n7,i4', 'KaTeX_Size1', 'KaTeX_Size2', 'KaTeX_Size3', 'KaTeX_Size4', 'KaTeX_Typewriter']
32
- },
33
- active: () => {
34
- getMarkmap().refreshHook.call();
35
- }
36
- };
37
- },
38
- getParams({
39
- getMarkmap
40
- }) {
41
- return [getMarkmap];
30
+ scripts: [
31
+ {
32
+ type: "iife",
33
+ data: {
34
+ fn: (getMarkmap) => {
35
+ window.WebFontConfig = {
36
+ custom: {
37
+ families: [
38
+ "KaTeX_AMS",
39
+ "KaTeX_Caligraphic:n4,n7",
40
+ "KaTeX_Fraktur:n4,n7",
41
+ "KaTeX_Main:n4,n7,i4,i7",
42
+ "KaTeX_Math:i4,i7",
43
+ "KaTeX_Script",
44
+ "KaTeX_SansSerif:n4,n7,i4",
45
+ "KaTeX_Size1",
46
+ "KaTeX_Size2",
47
+ "KaTeX_Size3",
48
+ "KaTeX_Size4",
49
+ "KaTeX_Typewriter"
50
+ ]
51
+ },
52
+ active: () => {
53
+ getMarkmap().refreshHook.call();
54
+ }
55
+ };
56
+ },
57
+ getParams({ getMarkmap }) {
58
+ return [getMarkmap];
59
+ }
42
60
  }
43
- }
44
- }, webfontloader],
61
+ },
62
+ webfontloader
63
+ ],
45
64
  styles: styles$1
46
65
  };
47
-
48
66
  function createTransformHooks(transformer) {
49
67
  return {
50
68
  transformer,
@@ -55,26 +73,24 @@ function createTransformHooks(transformer) {
55
73
  retransform: new markmapCommon.Hook()
56
74
  };
57
75
  }
58
-
59
- /**
60
- * This function is only used to help type checking.
61
- */
62
- function definePlugin(plugin) {
63
- return plugin;
76
+ function definePlugin(plugin2) {
77
+ return plugin2;
64
78
  }
65
-
66
79
  const plugin$1 = definePlugin({
67
80
  name: name$3,
68
81
  config: config$1,
69
82
  transform(transformHooks) {
70
- var _plugin$config, _plugin$config2;
83
+ var _a, _b;
71
84
  let enableFeature = markmapCommon.noop;
72
- transformHooks.parser.tap(md => {
85
+ transformHooks.parser.tap((md) => {
73
86
  md.use(remarkableKatex);
74
- md.renderer.rules.katex = markmapCommon.wrapFunction(md.renderer.rules.katex, (render, ...args) => {
75
- enableFeature();
76
- return render(...args);
77
- });
87
+ md.renderer.rules.katex = markmapCommon.wrapFunction(
88
+ md.renderer.rules.katex,
89
+ (render, ...args) => {
90
+ enableFeature();
91
+ return render(...args);
92
+ }
93
+ );
78
94
  });
79
95
  transformHooks.beforeParse.tap((_, context) => {
80
96
  enableFeature = () => {
@@ -82,78 +98,83 @@ const plugin$1 = definePlugin({
82
98
  };
83
99
  });
84
100
  return {
85
- styles: (_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.styles,
86
- scripts: (_plugin$config2 = plugin$1.config) == null ? void 0 : _plugin$config2.scripts
101
+ styles: (_a = plugin$1.config) == null ? void 0 : _a.styles,
102
+ scripts: (_b = plugin$1.config) == null ? void 0 : _b.scripts
87
103
  };
88
104
  }
89
105
  });
90
-
91
- const name$2 = 'frontmatter';
92
- var frontmatter = definePlugin({
106
+ const name$2 = "frontmatter";
107
+ const frontmatter = definePlugin({
93
108
  name: name$2,
94
109
  transform(transformHooks) {
95
110
  transformHooks.beforeParse.tap((md, context) => {
96
- const {
97
- content
98
- } = context;
99
- if (!content.startsWith('---\n')) return;
100
- const endOffset = content.indexOf('\n---\n');
101
- if (endOffset < 0) return;
111
+ const { content } = context;
112
+ if (!content.startsWith("---\n"))
113
+ return;
114
+ const endOffset = content.indexOf("\n---\n");
115
+ if (endOffset < 0)
116
+ return;
102
117
  const raw = content.slice(4, endOffset);
103
- let frontmatter;
118
+ let frontmatter2;
104
119
  try {
105
- var _frontmatter;
106
- frontmatter = yaml.load(raw);
107
- if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
108
- frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
120
+ frontmatter2 = yaml.load(raw);
121
+ if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
122
+ frontmatter2.markmap = normalizeMarkmapJsonOptions(
123
+ frontmatter2.markmap
124
+ );
109
125
  }
110
- } catch (_unused) {
126
+ } catch {
111
127
  return;
112
128
  }
113
- context.frontmatter = frontmatter;
129
+ context.frontmatter = frontmatter2;
114
130
  context.content = content.slice(endOffset + 5);
115
- context.contentLineOffset = content.slice(0, endOffset).split('\n').length + 1;
131
+ context.contentLineOffset = content.slice(0, endOffset).split("\n").length + 1;
116
132
  });
117
133
  return {};
118
134
  }
119
135
  });
120
136
  function normalizeMarkmapJsonOptions(options) {
121
- if (!options) return;
122
- ['color', 'extraJs', 'extraCss'].forEach(key => {
123
- if (options[key] != null) options[key] = normalizeStringArray(options[key]);
137
+ if (!options)
138
+ return;
139
+ ["color", "extraJs", "extraCss"].forEach((key) => {
140
+ if (options[key] != null)
141
+ options[key] = normalizeStringArray(options[key]);
124
142
  });
125
- ['duration', 'maxWidth', 'initialExpandLevel'].forEach(key => {
126
- if (options[key] != null) options[key] = normalizeNumber(options[key]);
143
+ ["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
144
+ if (options[key] != null)
145
+ options[key] = normalizeNumber(options[key]);
127
146
  });
128
147
  return options;
129
148
  }
130
149
  function normalizeStringArray(value) {
131
- var _result;
132
150
  let result;
133
- if (typeof value === 'string') result = [value];else if (Array.isArray(value)) result = value.filter(item => item && typeof item === 'string');
134
- return (_result = result) != null && _result.length ? result : undefined;
151
+ if (typeof value === "string")
152
+ result = [value];
153
+ else if (Array.isArray(value))
154
+ result = value.filter((item) => item && typeof item === "string");
155
+ return (result == null ? void 0 : result.length) ? result : void 0;
135
156
  }
136
157
  function normalizeNumber(value) {
137
- if (isNaN(+value)) return;
158
+ if (isNaN(+value))
159
+ return;
138
160
  return +value;
139
161
  }
140
-
141
- const name$1 = 'npmUrl';
142
- var npmUrl = definePlugin({
162
+ const name$1 = "npmUrl";
163
+ const npmUrl = definePlugin({
143
164
  name: name$1,
144
165
  transform(transformHooks) {
145
166
  transformHooks.afterParse.tap((_, context) => {
146
- const {
147
- frontmatter
148
- } = context;
149
- const markmap = frontmatter == null ? void 0 : frontmatter.markmap;
167
+ const { frontmatter: frontmatter2 } = context;
168
+ const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
150
169
  if (markmap) {
151
- ['extraJs', 'extraCss'].forEach(key => {
170
+ ["extraJs", "extraCss"].forEach((key) => {
152
171
  const value = markmap[key];
153
172
  if (value) {
154
- markmap[key] = value.map(path => {
155
- if (path.startsWith('npm:')) {
156
- return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
173
+ markmap[key] = value.map((path) => {
174
+ if (path.startsWith("npm:")) {
175
+ return transformHooks.transformer.urlBuilder.getFullUrl(
176
+ path.slice(4)
177
+ );
157
178
  }
158
179
  return path;
159
180
  });
@@ -164,31 +185,32 @@ var npmUrl = definePlugin({
164
185
  return {};
165
186
  }
166
187
  });
167
-
168
- const name = 'hljs';
169
- const preloadScripts = [`@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`].map(path => markmapCommon.buildJSItem(path));
170
- const styles = [`@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
171
- // `highlight.js@${"11.8.0"}/styles/default.css`,
172
- ].map(path => markmapCommon.buildCSSItem(path));
188
+ const name = "hljs";
189
+ const preloadScripts = [
190
+ `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
191
+ ].map((path) => markmapCommon.buildJSItem(path));
192
+ const styles = [
193
+ `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
194
+ // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
195
+ ].map((path) => markmapCommon.buildCSSItem(path));
173
196
  const config = {
174
197
  versions: {
175
- hljs: "11.8.0"
198
+ hljs: "11.8.0"
176
199
  },
177
200
  preloadScripts,
178
201
  styles
179
202
  };
180
-
181
203
  const plugin = definePlugin({
182
204
  name,
183
205
  config,
184
206
  transform(transformHooks) {
185
- var _plugin$config;
207
+ var _a;
186
208
  let enableFeature = markmapCommon.noop;
187
- transformHooks.parser.tap(md => {
209
+ transformHooks.parser.tap((md) => {
188
210
  md.set({
189
211
  highlight: (str, language) => {
190
212
  enableFeature();
191
- return hljs.highlightAuto(str, language ? [language] : undefined).value;
213
+ return hljs.highlightAuto(str, language ? [language] : void 0).value;
192
214
  }
193
215
  });
194
216
  });
@@ -198,68 +220,70 @@ const plugin = definePlugin({
198
220
  };
199
221
  });
200
222
  return {
201
- styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
223
+ styles: (_a = plugin.config) == null ? void 0 : _a.styles
202
224
  };
203
225
  }
204
226
  });
205
-
206
227
  const plugins = [frontmatter, plugin$1, plugin, npmUrl];
207
-
208
- function patchJSItem(transformer, item) {
209
- if (item.type === 'script' && item.data.src) {
210
- return _extends({}, item, {
211
- data: _extends({}, item.data, {
212
- src: transformer.urlBuilder.getFullUrl(item.data.src)
213
- })
214
- });
228
+ function patchJSItem(urlBuilder, item) {
229
+ if (item.type === "script" && item.data.src) {
230
+ return {
231
+ ...item,
232
+ data: {
233
+ ...item.data,
234
+ src: urlBuilder.getFullUrl(item.data.src)
235
+ }
236
+ };
215
237
  }
216
238
  return item;
217
239
  }
218
- function patchCSSItem(transformer, item) {
219
- if (item.type === 'stylesheet' && item.data.href) {
220
- return _extends({}, item, {
221
- data: _extends({}, item.data, {
222
- href: transformer.urlBuilder.getFullUrl(item.data.href)
223
- })
224
- });
240
+ function patchCSSItem(urlBuilder, item) {
241
+ if (item.type === "stylesheet" && item.data.href) {
242
+ return {
243
+ ...item,
244
+ data: {
245
+ ...item.data,
246
+ href: urlBuilder.getFullUrl(item.data.href)
247
+ }
248
+ };
225
249
  }
226
250
  return item;
227
251
  }
228
-
229
252
  function cleanNode(node) {
230
- if (node.type === 'heading') {
231
- // drop all paragraphs
232
- node.children = node.children.filter(item => item.type !== 'paragraph');
233
- } else if (node.type === 'list_item') {
234
- var _node$payload;
235
- // keep first paragraph as content of list_item, drop others
236
- node.children = node.children.filter(item => {
237
- if (['paragraph', 'fence'].includes(item.type)) {
253
+ var _a, _b;
254
+ if (node.type === "heading") {
255
+ node.children = node.children.filter((item) => item.type !== "paragraph");
256
+ } else if (node.type === "list_item") {
257
+ node.children = node.children.filter((item) => {
258
+ if (["paragraph", "fence"].includes(item.type)) {
238
259
  if (!node.content) {
239
260
  node.content = item.content;
240
- node.payload = _extends({}, node.payload, item.payload);
261
+ node.payload = {
262
+ ...node.payload,
263
+ ...item.payload
264
+ };
241
265
  }
242
266
  return false;
243
267
  }
244
268
  return true;
245
269
  });
246
- if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) {
270
+ if (((_a = node.payload) == null ? void 0 : _a.index) != null) {
247
271
  node.content = `${node.payload.index}. ${node.content}`;
248
272
  }
249
- } else if (node.type === 'ordered_list') {
250
- var _node$payload$startIn, _node$payload2;
251
- let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
252
- node.children.forEach(item => {
253
- if (item.type === 'list_item') {
254
- item.payload = _extends({}, item.payload, {
273
+ } else if (node.type === "ordered_list") {
274
+ let index = ((_b = node.payload) == null ? void 0 : _b.startIndex) ?? 1;
275
+ node.children.forEach((item) => {
276
+ if (item.type === "list_item") {
277
+ item.payload = {
278
+ ...item.payload,
255
279
  index
256
- });
280
+ };
257
281
  index += 1;
258
282
  }
259
283
  });
260
284
  }
261
285
  if (node.children.length > 0) {
262
- node.children.forEach(child => cleanNode(child));
286
+ node.children.forEach((child) => cleanNode(child));
263
287
  if (node.children.length === 1 && !node.children[0].content) {
264
288
  node.children = node.children[0].children;
265
289
  }
@@ -267,7 +291,7 @@ function cleanNode(node) {
267
291
  }
268
292
  function resetDepth(node, depth = 0) {
269
293
  node.depth = depth;
270
- node.children.forEach(child => {
294
+ node.children.forEach((child) => {
271
295
  resetDepth(child, depth + 1);
272
296
  });
273
297
  }
@@ -276,39 +300,36 @@ class Transformer {
276
300
  this.assetsMap = {};
277
301
  this.urlBuilder = new markmapCommon.UrlBuilder();
278
302
  this.hooks = createTransformHooks(this);
279
- this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
303
+ this.plugins = plugins$1.map(
304
+ (plugin2) => typeof plugin2 === "function" ? plugin2() : plugin2
305
+ );
280
306
  const assetsMap = {};
281
- for (const {
282
- name,
283
- transform
284
- } of this.plugins) {
285
- assetsMap[name] = transform(this.hooks);
307
+ for (const { name: name2, transform } of this.plugins) {
308
+ assetsMap[name2] = transform(this.hooks);
286
309
  }
287
310
  this.assetsMap = assetsMap;
288
- const md = new remarkable.Remarkable('full', {
311
+ const md = new remarkable.Remarkable("full", {
289
312
  html: true,
290
313
  breaks: true,
291
314
  maxNesting: Infinity
292
315
  });
293
- md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, (render, ...args) => {
294
- const result = render(...args);
295
- this.hooks.htmltag.call({
296
- args,
297
- result
298
- });
299
- return result;
300
- });
316
+ md.renderer.rules.htmltag = markmapCommon.wrapFunction(
317
+ md.renderer.rules.htmltag,
318
+ (render, ...args) => {
319
+ const result = render(...args);
320
+ this.hooks.htmltag.call({ args, result });
321
+ return result;
322
+ }
323
+ );
301
324
  this.md = md;
302
325
  this.hooks.parser.call(md);
303
326
  }
304
327
  buildTree(tokens) {
305
- const {
306
- md
307
- } = this;
328
+ const { md } = this;
308
329
  const root = {
309
- type: 'root',
330
+ type: "root",
310
331
  depth: 0,
311
- content: '',
332
+ content: "",
312
333
  children: [],
313
334
  payload: {}
314
335
  };
@@ -320,19 +341,17 @@ class Transformer {
320
341
  payload.lines = token.lines;
321
342
  }
322
343
  let current = stack[stack.length - 1];
323
- if (token.type.endsWith('_open')) {
344
+ if (token.type.endsWith("_open")) {
324
345
  const type = token.type.slice(0, -5);
325
- if (type === 'heading') {
346
+ if (type === "heading") {
326
347
  depth = token.hLevel;
327
- while (((_current = current) == null ? void 0 : _current.depth) >= depth) {
328
- var _current;
348
+ while ((current == null ? void 0 : current.depth) >= depth) {
329
349
  stack.pop();
330
350
  current = stack[stack.length - 1];
331
351
  }
332
352
  } else {
333
- var _current2;
334
- depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1;
335
- if (type === 'ordered_list') {
353
+ depth = Math.max(depth, (current == null ? void 0 : current.depth) || 0) + 1;
354
+ if (type === "ordered_list") {
336
355
  payload.startIndex = token.order;
337
356
  }
338
357
  }
@@ -340,7 +359,7 @@ class Transformer {
340
359
  type,
341
360
  depth,
342
361
  payload,
343
- content: '',
362
+ content: "",
344
363
  children: []
345
364
  };
346
365
  current.children.push(item);
@@ -348,28 +367,29 @@ class Transformer {
348
367
  } else if (!current) {
349
368
  continue;
350
369
  } else if (token.type === `${current.type}_close`) {
351
- if (current.type === 'heading') {
370
+ if (current.type === "heading") {
352
371
  depth = current.depth;
353
372
  } else {
354
373
  stack.pop();
355
374
  depth = 0;
356
375
  }
357
- } else if (token.type === 'inline') {
358
- const revoke = this.hooks.htmltag.tap(ctx => {
359
- var _ctx$result;
360
- const comment = (_ctx$result = ctx.result) == null ? void 0 : _ctx$result.match(/^<!--([\s\S]*?)-->$/);
361
- const data = comment == null ? void 0 : comment[1].trim().split(' ');
362
- if ((data == null ? void 0 : data[0]) === 'fold') {
363
- current.payload = _extends({}, current.payload, {
364
- fold: ['all', 'recursively'].includes(data[1]) ? 2 : 1
365
- });
366
- ctx.result = '';
376
+ } else if (token.type === "inline") {
377
+ const revoke = this.hooks.htmltag.tap((ctx) => {
378
+ var _a;
379
+ const comment = (_a = ctx.result) == null ? void 0 : _a.match(/^<!--([\s\S]*?)-->$/);
380
+ const data = comment == null ? void 0 : comment[1].trim().split(" ");
381
+ if ((data == null ? void 0 : data[0]) === "fold") {
382
+ current.payload = {
383
+ ...current.payload,
384
+ fold: ["all", "recursively"].includes(data[1]) ? 2 : 1
385
+ };
386
+ ctx.result = "";
367
387
  }
368
388
  });
369
389
  const text = md.renderer.render([token], md.options, {});
370
390
  revoke();
371
- current.content = `${current.content || ''}${text}`;
372
- } else if (token.type === 'fence') {
391
+ current.content = `${current.content || ""}${text}`;
392
+ } else if (token.type === "fence") {
373
393
  const result = md.renderer.render([token], md.options, {});
374
394
  current.children.push({
375
395
  type: token.type,
@@ -378,12 +398,13 @@ class Transformer {
378
398
  children: [],
379
399
  payload
380
400
  });
381
- } else ;
401
+ } else
402
+ ;
382
403
  }
383
404
  return root;
384
405
  }
385
406
  transform(content) {
386
- var _root$children;
407
+ var _a;
387
408
  const context = {
388
409
  content,
389
410
  features: {},
@@ -394,82 +415,84 @@ class Transformer {
394
415
  this.hooks.afterParse.call(this.md, context);
395
416
  let root = this.buildTree(tokens);
396
417
  cleanNode(root);
397
- if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
418
+ if (((_a = root.children) == null ? void 0 : _a.length) === 1)
419
+ root = root.children[0];
398
420
  resetDepth(root);
399
- return _extends({}, context, {
400
- root
401
- });
421
+ return { ...context, root };
402
422
  }
403
-
404
423
  /**
405
424
  * Get all assets from enabled plugins or filter them by plugin names as keys.
406
425
  */
407
426
  getAssets(keys) {
408
- var _keys;
409
- const styles = [];
427
+ const styles2 = [];
410
428
  const scripts = [];
411
- (_keys = keys) != null ? _keys : keys = this.plugins.map(plugin => plugin.name);
412
- for (const assets of keys.map(key => this.assetsMap[key])) {
429
+ keys ?? (keys = this.plugins.map((plugin2) => plugin2.name));
430
+ for (const assets of keys.map((key) => this.assetsMap[key])) {
413
431
  if (assets) {
414
- if (assets.styles) styles.push(...assets.styles);
415
- if (assets.scripts) scripts.push(...assets.scripts);
432
+ if (assets.styles)
433
+ styles2.push(...assets.styles);
434
+ if (assets.scripts)
435
+ scripts.push(...assets.scripts);
416
436
  }
417
437
  }
418
438
  return {
419
- styles: styles.map(item => patchCSSItem(this, item)),
420
- scripts: scripts.map(item => patchJSItem(this, item))
439
+ styles: styles2.map((item) => patchCSSItem(this.urlBuilder, item)),
440
+ scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
421
441
  };
422
442
  }
423
-
424
443
  /**
425
444
  * Get used assets by features object returned by `transform`.
426
445
  */
427
446
  getUsedAssets(features) {
428
- const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
447
+ const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
429
448
  return this.getAssets(keys);
430
449
  }
431
450
  fillTemplate(root, assets, extra) {
432
- var _extra, _extra$baseJs;
433
- extra = _extends({}, extra);
434
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => markmapCommon.buildJSItem(path));
435
- const {
436
- scripts,
437
- styles
438
- } = assets;
439
- const cssList = [...(styles ? markmapCommon.persistCSS(styles) : [])];
451
+ extra = {
452
+ ...extra
453
+ };
454
+ extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
455
+ const { scripts, styles: styles2 } = assets;
456
+ const cssList = [...styles2 ? markmapCommon.persistCSS(styles2) : []];
440
457
  const context = {
441
458
  getMarkmap: () => window.markmap,
442
459
  getOptions: extra.getOptions,
443
460
  jsonOptions: extra.jsonOptions,
444
461
  root
445
462
  };
446
- const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), {
447
- type: 'iife',
448
- data: {
449
- fn: (getMarkmap, getOptions, root, jsonOptions) => {
450
- const markmap = getMarkmap();
451
- window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
452
- },
453
- getParams: ({
454
- getMarkmap,
455
- getOptions,
456
- root,
457
- jsonOptions
458
- }) => {
459
- return [getMarkmap, getOptions, root, jsonOptions];
460
- }
461
- }
462
- }], context)];
463
- const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
463
+ const jsList = [
464
+ ...markmapCommon.persistJS(
465
+ [
466
+ ...extra.baseJs,
467
+ ...scripts || [],
468
+ {
469
+ type: "iife",
470
+ data: {
471
+ fn: (getMarkmap, getOptions, root2, jsonOptions) => {
472
+ const markmap = getMarkmap();
473
+ window.mm = markmap.Markmap.create(
474
+ "svg#mindmap",
475
+ (getOptions || markmap.deriveOptions)(jsonOptions),
476
+ root2
477
+ );
478
+ },
479
+ getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
480
+ return [getMarkmap, getOptions, root2, jsonOptions];
481
+ }
482
+ }
483
+ }
484
+ ],
485
+ context
486
+ )
487
+ ];
488
+ const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
464
489
  return html;
465
490
  }
466
491
  }
467
-
468
492
  const transformerVersions = {
469
- 'markmap-lib': '0.15.5',
493
+ "markmap-lib": "process.env.VERSION",
470
494
  d3: "7.8.5"
471
495
  };
472
-
473
496
  exports.Transformer = Transformer;
474
497
  exports.baseJsPaths = baseJsPaths;
475
498
  exports.builtInPlugins = plugins;