markmap-lib 0.14.5-alpha.21 → 0.14.5-alpha.24

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,84 +1,47 @@
1
- /*! markmap-lib v0.14.5-alpha.21+fb81f2c | MIT License */
1
+ /*! markmap-lib v0.14.5-alpha.24+08dd40c | MIT License */
2
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
- import { buildJSItem, persistCSS, persistJS, buildCSSItem, Hook, noop, loadJS, getFullUrl, wrapFunction } from 'markmap-common';
4
3
  import { Remarkable } from 'remarkable';
4
+ import { buildJSItem, buildCSSItem, Hook, noop, loadJS, UrlBuilder, wrapFunction, persistCSS, persistJS } from 'markmap-common';
5
5
  import remarkableKatex from 'remarkable-katex';
6
6
  import yaml from 'js-yaml';
7
- import hljs$1 from 'highlight.js';
7
+ import hljs from 'highlight.js';
8
8
 
9
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.14.5-alpha.21"}/dist/browser/index.js`];
11
- function fillTemplate(root, assets, extra) {
12
- var _extra, _extra$baseJs;
13
- extra = _extends({}, extra);
14
- (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => buildJSItem(path));
15
- const {
16
- scripts,
17
- styles
18
- } = assets;
19
- const cssList = [...(styles ? persistCSS(styles) : [])];
20
- const context = {
21
- getMarkmap: () => window.markmap,
22
- getOptions: extra.getOptions,
23
- jsonOptions: extra.jsonOptions,
24
- root
25
- };
26
- const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
10
+ const baseJsPaths = [`d3@${"7.8.5"}/dist/d3.min.js`, `markmap-view@${"0.14.5-alpha.24"}/dist/browser/index.js`];
11
+
12
+ const name$3 = 'katex';
13
+ const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => buildJSItem(path));
14
+ const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
15
+ webfontloader.data.defer = true;
16
+ const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => buildCSSItem(path));
17
+ const config$1 = {
18
+ versions: {
19
+ katex: "0.16.8" ,
20
+ webfontloader: "1.6.28"
21
+ },
22
+ preloadScripts,
23
+ scripts: [{
27
24
  type: 'iife',
28
25
  data: {
29
- fn: (getMarkmap, getOptions, root, jsonOptions) => {
30
- const markmap = getMarkmap();
31
- window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
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
+ };
32
35
  },
33
- getParams: ({
34
- getMarkmap,
35
- getOptions,
36
- root,
37
- jsonOptions
38
- }) => {
39
- return [getMarkmap, getOptions, root, jsonOptions];
36
+ getParams({
37
+ getMarkmap
38
+ }) {
39
+ return [getMarkmap];
40
40
  }
41
41
  }
42
- }], context)];
43
- const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
44
- return html;
45
- }
46
-
47
- const name$3 = 'katex';
48
- function getConfig$1() {
49
- const preloadScripts = [`katex@${"0.16.8"}/dist/katex.min.js`].map(path => buildJSItem(path));
50
- const webfontloader = buildJSItem(`webfontloader@${"1.6.28"}/webfontloader.js`);
51
- webfontloader.data.defer = true;
52
- const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(path => buildCSSItem(path));
53
- return {
54
- versions: {
55
- katex: "0.16.8" ,
56
- webfontloader: "1.6.28"
57
- },
58
- preloadScripts,
59
- scripts: [{
60
- type: 'iife',
61
- data: {
62
- fn: getMarkmap => {
63
- window.WebFontConfig = {
64
- custom: {
65
- 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']
66
- },
67
- active: () => {
68
- getMarkmap().refreshHook.call();
69
- }
70
- };
71
- },
72
- getParams({
73
- getMarkmap
74
- }) {
75
- return [getMarkmap];
76
- }
77
- }
78
- }, webfontloader],
79
- styles
80
- };
81
- }
42
+ }, webfontloader],
43
+ styles: styles$1
44
+ };
82
45
 
83
46
  /**
84
47
  * Find NPM paths and resolve them to full URLs with the same package version as in this library.
@@ -97,9 +60,30 @@ function addDefaultVersions(paths, name, version) {
97
60
  return path;
98
61
  });
99
62
  }
63
+ function patchJSItem(transformer, item) {
64
+ if (item.type === 'script' && item.data.src) {
65
+ return _extends({}, item, {
66
+ data: _extends({}, item.data, {
67
+ src: transformer.urlBuilder.getFullUrl(item.data.src)
68
+ })
69
+ });
70
+ }
71
+ return item;
72
+ }
73
+ function patchCSSItem(transformer, item) {
74
+ if (item.type === 'stylesheet' && item.data.href) {
75
+ return _extends({}, item, {
76
+ data: _extends({}, item.data, {
77
+ href: transformer.urlBuilder.getFullUrl(item.data.href)
78
+ })
79
+ });
80
+ }
81
+ return item;
82
+ }
100
83
 
101
- function createTransformHooks() {
84
+ function createTransformHooks(transformer) {
102
85
  return {
86
+ transformer,
103
87
  parser: new Hook(),
104
88
  beforeParse: new Hook(),
105
89
  afterParse: new Hook(),
@@ -115,64 +99,64 @@ function definePlugin(plugin) {
115
99
  return plugin;
116
100
  }
117
101
 
118
- var katex = definePlugin(() => {
119
- const plugin = {
120
- name: name$3,
121
- config: getConfig$1(),
122
- transform(transformHooks) {
123
- let loading;
124
- const autoload = () => {
125
- loading || (loading = loadJS(plugin.config.preloadScripts));
126
- return loading;
127
- };
128
- const renderKatex = (source, displayMode) => {
129
- const {
130
- katex
131
- } = window;
132
- if (katex) {
133
- return katex.renderToString(source, {
134
- displayMode,
135
- throwOnError: false
136
- });
137
- }
138
- autoload().then(() => {
139
- transformHooks.retransform.call();
102
+ const plugin$1 = definePlugin({
103
+ name: name$3,
104
+ config: config$1,
105
+ transform(transformHooks) {
106
+ var _plugin$config, _plugin$config3, _plugin$config4;
107
+ let loading;
108
+ const preloadScripts = ((_plugin$config = plugin$1.config) == null || (_plugin$config = _plugin$config.preloadScripts) == null ? void 0 : _plugin$config.map(item => patchJSItem(transformHooks.transformer, item))) || [];
109
+ const autoload = () => {
110
+ loading || (loading = loadJS(preloadScripts));
111
+ return loading;
112
+ };
113
+ const renderKatex = (source, displayMode) => {
114
+ const {
115
+ katex
116
+ } = window;
117
+ if (katex) {
118
+ return katex.renderToString(source, {
119
+ displayMode,
120
+ throwOnError: false
140
121
  });
141
- return source;
142
- };
143
- let enableFeature = noop;
144
- transformHooks.parser.tap(md => {
145
- md.use(remarkableKatex);
146
- md.renderer.rules.katex = (tokens, idx) => {
147
- enableFeature();
148
- const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
149
- return result;
150
- };
151
- });
152
- transformHooks.beforeParse.tap((_, context) => {
153
- enableFeature = () => {
154
- context.features[name$3] = true;
155
- };
156
- });
157
- transformHooks.afterParse.tap((_, context) => {
158
- var _context$frontmatter;
159
- const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
160
- if (markmap) {
161
- ['extraJs', 'extraCss'].forEach(key => {
162
- const value = markmap[key];
163
- if (value) {
164
- markmap[key] = addDefaultVersions(value, name$3, plugin.config.versions.katex);
165
- }
166
- });
167
- }
122
+ }
123
+ autoload().then(() => {
124
+ transformHooks.retransform.call();
168
125
  });
169
- return {
170
- styles: plugin.config.styles,
171
- scripts: plugin.config.scripts
126
+ return source;
127
+ };
128
+ let enableFeature = noop;
129
+ transformHooks.parser.tap(md => {
130
+ md.use(remarkableKatex);
131
+ md.renderer.rules.katex = (tokens, idx) => {
132
+ enableFeature();
133
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
134
+ return result;
172
135
  };
173
- }
174
- };
175
- return plugin;
136
+ });
137
+ transformHooks.beforeParse.tap((_, context) => {
138
+ enableFeature = () => {
139
+ context.features[name$3] = true;
140
+ };
141
+ });
142
+ transformHooks.afterParse.tap((_, context) => {
143
+ var _context$frontmatter;
144
+ const markmap = (_context$frontmatter = context.frontmatter) == null ? void 0 : _context$frontmatter.markmap;
145
+ if (markmap) {
146
+ ['extraJs', 'extraCss'].forEach(key => {
147
+ const value = markmap[key];
148
+ if (value) {
149
+ var _plugin$config2;
150
+ markmap[key] = addDefaultVersions(value, name$3, ((_plugin$config2 = plugin$1.config) == null || (_plugin$config2 = _plugin$config2.versions) == null ? void 0 : _plugin$config2.katex) || '');
151
+ }
152
+ });
153
+ }
154
+ });
155
+ return {
156
+ styles: (_plugin$config3 = plugin$1.config) == null ? void 0 : _plugin$config3.styles,
157
+ scripts: (_plugin$config4 = plugin$1.config) == null ? void 0 : _plugin$config4.scripts
158
+ };
159
+ }
176
160
  });
177
161
 
178
162
  const name$2 = 'frontmatter';
@@ -240,7 +224,7 @@ var npmUrl = definePlugin({
240
224
  if (value) {
241
225
  markmap[key] = value.map(path => {
242
226
  if (path.startsWith('npm:')) {
243
- return getFullUrl(path.slice(4));
227
+ return transformHooks.transformer.urlBuilder.getFullUrl(path.slice(4));
244
228
  }
245
229
  return path;
246
230
  });
@@ -253,43 +237,39 @@ var npmUrl = definePlugin({
253
237
  });
254
238
 
255
239
  const name = 'hljs';
256
- function getConfig() {
257
- const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => buildCSSItem(path));
258
- return {
259
- versions: {
260
- hljs: "11.8.0"
261
- },
262
- styles
263
- };
264
- }
265
- var hljs = definePlugin(() => {
266
- const plugin = {
267
- name,
268
- config: getConfig(),
269
- transform(transformHooks) {
270
- let enableFeature = noop;
271
- transformHooks.parser.tap(md => {
272
- md.set({
273
- highlight: (str, language) => {
274
- enableFeature();
275
- return hljs$1.highlightAuto(str, language ? [language] : undefined).value;
276
- }
277
- });
278
- });
279
- transformHooks.beforeParse.tap((_, context) => {
280
- enableFeature = () => {
281
- context.features[name] = true;
282
- };
240
+ const styles = [`highlight.js@${"11.8.0"}/styles/default.css`].map(path => buildCSSItem(path));
241
+ const config = {
242
+ versions: {
243
+ hljs: "11.8.0"
244
+ },
245
+ styles
246
+ };
247
+ const plugin = definePlugin({
248
+ name,
249
+ config,
250
+ transform(transformHooks) {
251
+ var _plugin$config;
252
+ let enableFeature = noop;
253
+ transformHooks.parser.tap(md => {
254
+ md.set({
255
+ highlight: (str, language) => {
256
+ enableFeature();
257
+ return hljs.highlightAuto(str, language ? [language] : undefined).value;
258
+ }
283
259
  });
284
- return {
285
- styles: plugin.config.styles
260
+ });
261
+ transformHooks.beforeParse.tap((_, context) => {
262
+ enableFeature = () => {
263
+ context.features[name] = true;
286
264
  };
287
- }
288
- };
289
- return plugin;
265
+ });
266
+ return {
267
+ styles: (_plugin$config = plugin.config) == null ? void 0 : _plugin$config.styles
268
+ };
269
+ }
290
270
  });
291
271
 
292
- const plugins = [frontmatter, katex, hljs, npmUrl];
272
+ const plugins = [frontmatter, plugin$1, plugin, npmUrl];
293
273
 
294
274
  function cleanNode(node) {
295
275
  if (node.type === 'heading') {
@@ -339,7 +319,8 @@ function resetDepth(node, depth = 0) {
339
319
  class Transformer {
340
320
  constructor(plugins$1 = plugins) {
341
321
  this.assetsMap = {};
342
- this.hooks = createTransformHooks();
322
+ this.urlBuilder = new UrlBuilder();
323
+ this.hooks = createTransformHooks(this);
343
324
  this.plugins = plugins$1.map(plugin => typeof plugin === 'function' ? plugin() : plugin);
344
325
  const assetsMap = {};
345
326
  for (const {
@@ -480,8 +461,8 @@ class Transformer {
480
461
  }
481
462
  }
482
463
  return {
483
- styles,
484
- scripts
464
+ styles: styles.map(item => patchCSSItem(this, item)),
465
+ scripts: scripts.map(item => patchJSItem(this, item))
485
466
  };
486
467
  }
487
468
 
@@ -492,11 +473,46 @@ class Transformer {
492
473
  const keys = this.plugins.map(plugin => plugin.name).filter(name => features[name]);
493
474
  return this.getAssets(keys);
494
475
  }
476
+ fillTemplate(root, assets, extra) {
477
+ var _extra, _extra$baseJs;
478
+ extra = _extends({}, extra);
479
+ (_extra$baseJs = (_extra = extra).baseJs) != null ? _extra$baseJs : _extra.baseJs = baseJsPaths.map(path => this.urlBuilder.getFullUrl(path)).map(path => buildJSItem(path));
480
+ const {
481
+ scripts,
482
+ styles
483
+ } = assets;
484
+ const cssList = [...(styles ? persistCSS(styles) : [])];
485
+ const context = {
486
+ getMarkmap: () => window.markmap,
487
+ getOptions: extra.getOptions,
488
+ jsonOptions: extra.jsonOptions,
489
+ root
490
+ };
491
+ const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), {
492
+ type: 'iife',
493
+ data: {
494
+ fn: (getMarkmap, getOptions, root, jsonOptions) => {
495
+ const markmap = getMarkmap();
496
+ window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root);
497
+ },
498
+ getParams: ({
499
+ getMarkmap,
500
+ getOptions,
501
+ root,
502
+ jsonOptions
503
+ }) => {
504
+ return [getMarkmap, getOptions, root, jsonOptions];
505
+ }
506
+ }
507
+ }], context)];
508
+ const html = template.replace('<!--CSS-->', () => cssList.join('')).replace('<!--JS-->', () => jsList.join(''));
509
+ return html;
510
+ }
495
511
  }
496
512
 
497
513
  const transformerVersions = {
498
- 'markmap-lib': '0.14.5-alpha.21+fb81f2c',
514
+ 'markmap-lib': '0.14.5-alpha.24+08dd40c',
499
515
  d3: "7.8.5"
500
516
  };
501
517
 
502
- export { Transformer, baseJsPaths, plugins as builtInPlugins, fillTemplate, transformerVersions };
518
+ export { Transformer, baseJsPaths, plugins as builtInPlugins, template, transformerVersions };