markmap-lib 0.15.9-alpha.5 → 0.16.0

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.
Files changed (35) hide show
  1. package/dist/browser/index.iife.js +417 -482
  2. package/dist/browser/index.mjs +242 -248
  3. package/dist/index.d.ts +1 -3
  4. package/dist/index.js +17 -314
  5. package/dist/index.mjs +18 -315
  6. package/dist/index.no-plugins.js +136 -0
  7. package/dist/index.no-plugins.mjs +136 -0
  8. package/dist/plugins/checkbox/index.d.ts +2 -0
  9. package/dist/plugins/frontmatter/index.d.ts +2 -0
  10. package/dist/plugins/hljs/index.browser.d.ts +2 -0
  11. package/dist/plugins/hljs/index.d.ts +2 -0
  12. package/dist/plugins/index.d.ts +7 -0
  13. package/dist/plugins/katex/index.browser.d.ts +2 -0
  14. package/dist/plugins/katex/index.d.ts +2 -0
  15. package/dist/plugins/npm-url/index.d.ts +2 -0
  16. package/dist/plugins/prism/index.browser.d.ts +2 -0
  17. package/dist/plugins/prism/index.d.ts +2 -0
  18. package/dist/plugins/source-lines/index.d.ts +2 -0
  19. package/dist/plugins.js +307 -0
  20. package/dist/plugins.mjs +307 -0
  21. package/dist/transform.d.ts +3 -9
  22. package/package.json +23 -7
  23. package/dist/constants.d.ts +0 -4
  24. package/dist/plugins/checkbox.d.ts +0 -2
  25. package/dist/plugins/frontmatter.d.ts +0 -2
  26. package/dist/plugins/hljs.browser.d.ts +0 -2
  27. package/dist/plugins/hljs.d.ts +0 -2
  28. package/dist/plugins/katex.browser.d.ts +0 -2
  29. package/dist/plugins/katex.d.ts +0 -2
  30. package/dist/plugins/npm-url.d.ts +0 -2
  31. package/dist/plugins/prism.browser.d.ts +0 -2
  32. package/dist/plugins/prism.d.ts +0 -2
  33. /package/dist/plugins/{hljs.config.d.ts → hljs/config.d.ts} +0 -0
  34. /package/dist/plugins/{katex.config.d.ts → katex/config.d.ts} +0 -0
  35. /package/dist/plugins/{prism.config.d.ts → prism/config.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -3,262 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const markmapCommon = require("markmap-common");
4
4
  const markmapHtmlParser = require("markmap-html-parser");
5
5
  const remarkable = require("remarkable");
6
- const remarkableKatex = require("remarkable-katex");
7
- const yaml = require("js-yaml");
8
- const hljs = require("highlight.js");
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 = [
11
- `d3@${"7.8.5"}/dist/d3.min.js`,
12
- `markmap-view@${"0.15.9-alpha.5"}/dist/browser/index.js`
13
- ];
14
- const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
15
- const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
16
- const name$4 = "katex";
17
- const preloadScripts$1 = [
18
- `katex@${"0.16.8"}/dist/katex.min.js`
19
- ].map((path) => markmapCommon.buildJSItem(path));
20
- const webfontloader = markmapCommon.buildJSItem(
21
- `webfontloader@${"1.6.28"}/webfontloader.js`
22
- );
23
- webfontloader.data.defer = true;
24
- const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
25
- (path) => markmapCommon.buildCSSItem(path)
26
- );
27
- const config$1 = {
28
- versions: {
29
- katex: "0.16.8",
30
- webfontloader: "1.6.28"
31
- },
32
- preloadScripts: preloadScripts$1,
33
- scripts: [
34
- {
35
- type: "iife",
36
- data: {
37
- fn: (getMarkmap) => {
38
- window.WebFontConfig = {
39
- custom: {
40
- families: [
41
- "KaTeX_AMS",
42
- "KaTeX_Caligraphic:n4,n7",
43
- "KaTeX_Fraktur:n4,n7",
44
- "KaTeX_Main:n4,n7,i4,i7",
45
- "KaTeX_Math:i4,i7",
46
- "KaTeX_Script",
47
- "KaTeX_SansSerif:n4,n7,i4",
48
- "KaTeX_Size1",
49
- "KaTeX_Size2",
50
- "KaTeX_Size3",
51
- "KaTeX_Size4",
52
- "KaTeX_Typewriter"
53
- ]
54
- },
55
- active: () => {
56
- getMarkmap().refreshHook.call();
57
- }
58
- };
59
- },
60
- getParams({ getMarkmap }) {
61
- return [getMarkmap];
62
- }
63
- }
64
- },
65
- webfontloader
66
- ],
67
- styles: styles$1
68
- };
69
- function createTransformHooks(transformer) {
70
- return {
71
- transformer,
72
- parser: new markmapCommon.Hook(),
73
- beforeParse: new markmapCommon.Hook(),
74
- afterParse: new markmapCommon.Hook(),
75
- htmltag: new markmapCommon.Hook(),
76
- retransform: new markmapCommon.Hook()
77
- };
78
- }
79
- function definePlugin(plugin2) {
80
- return plugin2;
81
- }
82
- const plugin$2 = definePlugin({
83
- name: name$4,
84
- config: config$1,
85
- transform(transformHooks) {
86
- var _a, _b;
87
- let enableFeature = markmapCommon.noop;
88
- transformHooks.parser.tap((md) => {
89
- md.use(remarkableKatex);
90
- md.renderer.rules.katex = markmapCommon.wrapFunction(
91
- md.renderer.rules.katex,
92
- (render, ...args) => {
93
- enableFeature();
94
- return render(...args);
95
- }
96
- );
97
- });
98
- transformHooks.beforeParse.tap((_, context) => {
99
- enableFeature = () => {
100
- context.features[name$4] = true;
101
- };
102
- });
103
- return {
104
- styles: (_a = plugin$2.config) == null ? void 0 : _a.styles,
105
- scripts: (_b = plugin$2.config) == null ? void 0 : _b.scripts
106
- };
107
- }
108
- });
109
- const name$3 = "frontmatter";
110
- const frontmatter = definePlugin({
111
- name: name$3,
112
- transform(transformHooks) {
113
- transformHooks.beforeParse.tap((md, context) => {
114
- const { content } = context;
115
- if (!/^---\r?\n/.test(content))
116
- return;
117
- const match = /\n---\r?\n/.exec(content);
118
- if (!match)
119
- return;
120
- const raw = content.slice(4, match.index);
121
- let frontmatter2;
122
- try {
123
- frontmatter2 = yaml.load(raw);
124
- if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
125
- frontmatter2.markmap = normalizeMarkmapJsonOptions(
126
- frontmatter2.markmap
127
- );
128
- }
129
- } catch {
130
- return;
131
- }
132
- context.frontmatter = frontmatter2;
133
- context.content = content.slice(match.index + match[0].length);
134
- context.contentLineOffset = content.slice(0, match.index).split("\n").length + 1;
135
- });
136
- return {};
137
- }
138
- });
139
- function normalizeMarkmapJsonOptions(options) {
140
- if (!options)
141
- return;
142
- ["color", "extraJs", "extraCss"].forEach((key) => {
143
- if (options[key] != null)
144
- options[key] = normalizeStringArray(options[key]);
145
- });
146
- ["duration", "maxWidth", "initialExpandLevel"].forEach((key) => {
147
- if (options[key] != null)
148
- options[key] = normalizeNumber(options[key]);
149
- });
150
- return options;
151
- }
152
- function normalizeStringArray(value) {
153
- let result;
154
- if (typeof value === "string")
155
- result = [value];
156
- else if (Array.isArray(value))
157
- result = value.filter((item) => item && typeof item === "string");
158
- return (result == null ? void 0 : result.length) ? result : void 0;
159
- }
160
- function normalizeNumber(value) {
161
- if (isNaN(+value))
162
- return;
163
- return +value;
164
- }
165
- const name$2 = "npmUrl";
166
- const npmUrl = definePlugin({
167
- name: name$2,
168
- transform(transformHooks) {
169
- transformHooks.afterParse.tap((_, context) => {
170
- const { frontmatter: frontmatter2 } = context;
171
- const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
172
- if (markmap) {
173
- ["extraJs", "extraCss"].forEach((key) => {
174
- const value = markmap[key];
175
- if (value) {
176
- markmap[key] = value.map((path) => {
177
- if (path.startsWith("npm:")) {
178
- return transformHooks.transformer.urlBuilder.getFullUrl(
179
- path.slice(4)
180
- );
181
- }
182
- return path;
183
- });
184
- }
185
- });
186
- }
187
- });
188
- return {};
189
- }
190
- });
191
- const name$1 = "hljs";
192
- const preloadScripts = [
193
- `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
194
- ].map((path) => markmapCommon.buildJSItem(path));
195
- const styles = [
196
- `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
197
- // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
198
- ].map((path) => markmapCommon.buildCSSItem(path));
199
- const config = {
200
- versions: {
201
- hljs: "11.8.0"
202
- },
203
- preloadScripts,
204
- styles
205
- };
206
- const plugin$1 = definePlugin({
207
- name: name$1,
208
- config,
209
- transform(transformHooks) {
210
- var _a;
211
- let enableFeature = markmapCommon.noop;
212
- transformHooks.parser.tap((md) => {
213
- md.set({
214
- highlight: (str, language) => {
215
- enableFeature();
216
- return hljs.highlightAuto(str, language ? [language] : void 0).value;
217
- }
218
- });
219
- });
220
- transformHooks.beforeParse.tap((_, context) => {
221
- enableFeature = () => {
222
- context.features[name$1] = true;
223
- };
224
- });
225
- return {
226
- styles: (_a = plugin$1.config) == null ? void 0 : _a.styles
227
- };
228
- }
229
- });
230
- const name = "checkbox";
231
- const plugin = definePlugin({
232
- name,
233
- transform(transformHooks) {
234
- transformHooks.parser.tap((md) => {
235
- md.core.ruler.before(
236
- "inline",
237
- "checkbox",
238
- (state) => {
239
- for (let i = 2; i < state.tokens.length; i += 1) {
240
- const token = state.tokens[i];
241
- if (token.type === "inline" && token.content) {
242
- const prevType = state.tokens[i - 1].type;
243
- const prevPrevType = state.tokens[i - 2].type;
244
- if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
245
- if (token.content.startsWith("[ ]")) {
246
- token.content = `${svg_unmarked} ${token.content.slice(3)}`;
247
- } else if (token.content.startsWith("[x]")) {
248
- token.content = `${svg_marked} ${token.content.slice(3)}`;
249
- }
250
- }
251
- }
252
- }
253
- return false;
254
- },
255
- {}
256
- );
257
- });
258
- return {};
259
- }
260
- });
261
- const plugins = [frontmatter, plugin$2, plugin$1, npmUrl, plugin];
6
+ const plugins = require("./plugins.js");
7
+ require("js-yaml");
8
+ require("highlight.js");
9
+ require("remarkable-katex");
262
10
  function patchJSItem(urlBuilder, item) {
263
11
  if (item.type === "script" && item.data.src) {
264
12
  return {
@@ -283,6 +31,7 @@ function patchCSSItem(urlBuilder, item) {
283
31
  }
284
32
  return item;
285
33
  }
34
+ const builtInPlugins = plugins.plugins;
286
35
  function cleanNode(node) {
287
36
  while (!node.content && node.children.length === 1) {
288
37
  node = node.children[0];
@@ -299,16 +48,16 @@ function cleanNode(node) {
299
48
  };
300
49
  }
301
50
  class Transformer {
302
- constructor(plugins$1 = plugins) {
51
+ constructor(plugins$1 = builtInPlugins) {
303
52
  this.assetsMap = {};
304
53
  this.urlBuilder = new markmapCommon.UrlBuilder();
305
- this.hooks = createTransformHooks(this);
54
+ this.hooks = plugins.createTransformHooks(this);
306
55
  this.plugins = plugins$1.map(
307
- (plugin2) => typeof plugin2 === "function" ? plugin2() : plugin2
56
+ (plugin) => typeof plugin === "function" ? plugin() : plugin
308
57
  );
309
58
  const assetsMap = {};
310
- for (const { name: name2, transform } of this.plugins) {
311
- assetsMap[name2] = transform(this.hooks);
59
+ for (const { name, transform } of this.plugins) {
60
+ assetsMap[name] = transform(this.hooks);
312
61
  }
313
62
  this.assetsMap = assetsMap;
314
63
  const md = new remarkable.Remarkable("full", {
@@ -349,19 +98,19 @@ class Transformer {
349
98
  * Get all assets from enabled plugins or filter them by plugin names as keys.
350
99
  */
351
100
  getAssets(keys) {
352
- const styles2 = [];
101
+ const styles = [];
353
102
  const scripts = [];
354
- keys ?? (keys = this.plugins.map((plugin2) => plugin2.name));
103
+ keys ?? (keys = this.plugins.map((plugin) => plugin.name));
355
104
  for (const assets of keys.map((key) => this.assetsMap[key])) {
356
105
  if (assets) {
357
106
  if (assets.styles)
358
- styles2.push(...assets.styles);
107
+ styles.push(...assets.styles);
359
108
  if (assets.scripts)
360
109
  scripts.push(...assets.scripts);
361
110
  }
362
111
  }
363
112
  return {
364
- styles: styles2.map((item) => patchCSSItem(this.urlBuilder, item)),
113
+ styles: styles.map((item) => patchCSSItem(this.urlBuilder, item)),
365
114
  scripts: scripts.map((item) => patchJSItem(this.urlBuilder, item))
366
115
  };
367
116
  }
@@ -369,59 +118,13 @@ class Transformer {
369
118
  * Get used assets by features object returned by `transform`.
370
119
  */
371
120
  getUsedAssets(features) {
372
- const keys = this.plugins.map((plugin2) => plugin2.name).filter((name2) => features[name2]);
121
+ const keys = this.plugins.map((plugin) => plugin.name).filter((name) => features[name]);
373
122
  return this.getAssets(keys);
374
123
  }
375
- fillTemplate(root, assets, extra) {
376
- extra = {
377
- ...extra
378
- };
379
- extra.baseJs ?? (extra.baseJs = baseJsPaths.map((path) => this.urlBuilder.getFullUrl(path)).map((path) => markmapCommon.buildJSItem(path)));
380
- const { scripts, styles: styles2 } = assets;
381
- const cssList = [...styles2 ? markmapCommon.persistCSS(styles2) : []];
382
- const context = {
383
- getMarkmap: () => window.markmap,
384
- getOptions: extra.getOptions,
385
- jsonOptions: extra.jsonOptions,
386
- root
387
- };
388
- const jsList = [
389
- ...markmapCommon.persistJS(
390
- [
391
- ...extra.baseJs,
392
- ...scripts || [],
393
- {
394
- type: "iife",
395
- data: {
396
- fn: (getMarkmap, getOptions, root2, jsonOptions) => {
397
- const markmap = getMarkmap();
398
- window.mm = markmap.Markmap.create(
399
- "svg#mindmap",
400
- (getOptions || markmap.deriveOptions)(jsonOptions),
401
- root2
402
- );
403
- },
404
- getParams: ({ getMarkmap, getOptions, root: root2, jsonOptions }) => {
405
- return [getMarkmap, getOptions, root2, jsonOptions];
406
- }
407
- }
408
- }
409
- ],
410
- context
411
- )
412
- ];
413
- const html = template.replace("<!--CSS-->", () => cssList.join("")).replace("<!--JS-->", () => jsList.join(""));
414
- return html;
415
- }
416
124
  }
417
125
  const transformerVersions = {
418
- "markmap-lib": "process.env.VERSION",
419
- d3: "7.8.5"
126
+ "markmap-lib": "0.16.0"
420
127
  };
421
128
  exports.Transformer = Transformer;
422
- exports.baseJsPaths = baseJsPaths;
423
- exports.builtInPlugins = plugins;
424
- exports.svg_marked = svg_marked;
425
- exports.svg_unmarked = svg_unmarked;
426
- exports.template = template;
129
+ exports.builtInPlugins = builtInPlugins;
427
130
  exports.transformerVersions = transformerVersions;