markmap-lib 0.14.5-alpha.21 → 0.14.5-alpha.22
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/browser/index.js +186 -170
- package/dist/browser/index.mjs +181 -165
- package/dist/index.js +148 -133
- package/dist/index.mjs +148 -133
- package/package.json +4 -4
- package/types/constants.d.ts +2 -0
- package/types/index.d.ts +1 -1
- package/types/plugins/base.d.ts +3 -3
- package/types/plugins/frontmatter.d.ts +1 -1
- package/types/plugins/hljs.d.ts +2 -2
- package/types/plugins/index.d.ts +1 -1
- package/types/plugins/katex.browser.d.ts +2 -2
- package/types/plugins/katex.config.d.ts +1 -1
- package/types/plugins/katex.d.ts +2 -2
- package/types/plugins/npm-url.d.ts +1 -1
- package/types/plugins/prism.browser.d.ts +2 -2
- package/types/plugins/prism.config.d.ts +1 -1
- package/types/plugins/prism.d.ts +2 -2
- package/types/plugins/util.d.ts +4 -0
- package/types/transform.d.ts +9 -3
- package/types/types.d.ts +5 -1
- package/types/template.d.ts +0 -8
package/dist/browser/index.mjs
CHANGED
|
@@ -1,84 +1,47 @@
|
|
|
1
|
-
/*! markmap-lib v0.14.5-alpha.
|
|
1
|
+
/*! markmap-lib v0.14.5-alpha.22+04afb38 | 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
|
|
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.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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.22"}/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:
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
jsonOptions
|
|
38
|
-
}) => {
|
|
39
|
-
return [getMarkmap, getOptions, root, jsonOptions];
|
|
36
|
+
getParams({
|
|
37
|
+
getMarkmap
|
|
38
|
+
}) {
|
|
39
|
+
return [getMarkmap];
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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$config3, _plugin$config4;
|
|
107
|
+
let loading;
|
|
108
|
+
const autoload = () => {
|
|
109
|
+
var _plugin$config;
|
|
110
|
+
loading || (loading = loadJS(((_plugin$config = plugin$1.config) == null ? void 0 : _plugin$config.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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
285
|
-
|
|
260
|
+
});
|
|
261
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
262
|
+
enableFeature = () => {
|
|
263
|
+
context.features[name] = true;
|
|
286
264
|
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
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,
|
|
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.
|
|
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.
|
|
514
|
+
'markmap-lib': '0.14.5-alpha.22+04afb38',
|
|
499
515
|
d3: "7.8.5"
|
|
500
516
|
};
|
|
501
517
|
|
|
502
|
-
export { Transformer, baseJsPaths, plugins as builtInPlugins,
|
|
518
|
+
export { Transformer, baseJsPaths, plugins as builtInPlugins, template, transformerVersions };
|