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