markmap-lib 0.14.1 → 0.14.2-alpha.4
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 +166 -152
- package/dist/browser/index.min.js +3 -3
- package/dist/index.esm.js +113 -307
- package/dist/index.js +113 -307
- package/package.json +3 -3
- package/types/plugins/base.d.ts +5 -1
- package/types/plugins/frontmatter.d.ts +2 -3
- package/types/plugins/index.d.ts +1 -4
- package/types/plugins/katex.browser.d.ts +2 -5
- package/types/plugins/katex.d.ts +2 -5
- package/types/plugins/prism.browser.d.ts +2 -5
- package/types/plugins/prism.d.ts +2 -5
- package/types/transform.d.ts +2 -2
- package/types/types.d.ts +7 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,188 +1,21 @@
|
|
|
1
|
-
/*! markmap-lib v0.14.
|
|
2
|
-
import _extends
|
|
1
|
+
/*! markmap-lib v0.14.2-alpha.4+569dd11 | MIT License */
|
|
2
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
|
+
import { persistCSS, persistJS, Hook, wrapFunction } from 'markmap-common';
|
|
3
4
|
import { Remarkable } from 'remarkable';
|
|
4
5
|
import remarkableKatex from 'remarkable-katex';
|
|
5
6
|
import Prism from 'prismjs';
|
|
6
7
|
import loadLanguages from 'prismjs/components/';
|
|
7
8
|
import yaml from 'js-yaml';
|
|
8
9
|
|
|
9
|
-
/*! markmap-common v0.14.0 | MIT License */
|
|
10
|
-
class Hook {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.listeners = [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
tap(fn) {
|
|
16
|
-
this.listeners.push(fn);
|
|
17
|
-
return () => this.revoke(fn);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
revoke(fn) {
|
|
21
|
-
const i = this.listeners.indexOf(fn);
|
|
22
|
-
if (i >= 0) this.listeners.splice(i, 1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
revokeAll() {
|
|
26
|
-
this.listeners.splice(0);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
call(...args) {
|
|
30
|
-
for (const fn of this.listeners) {
|
|
31
|
-
fn(...args);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function _extends() {
|
|
38
|
-
_extends = Object.assign || function (target) {
|
|
39
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
-
var source = arguments[i];
|
|
41
|
-
|
|
42
|
-
for (var key in source) {
|
|
43
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
44
|
-
target[key] = source[key];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return target;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return _extends.apply(this, arguments);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
56
|
-
if (source == null) return {};
|
|
57
|
-
var target = {};
|
|
58
|
-
var sourceKeys = Object.keys(source);
|
|
59
|
-
var key, i;
|
|
60
|
-
|
|
61
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
62
|
-
key = sourceKeys[i];
|
|
63
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
64
|
-
target[key] = source[key];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return target;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const _excluded = ["textContent"];
|
|
71
|
-
|
|
72
|
-
function escapeHtml(html) {
|
|
73
|
-
return html.replace(/[&<"]/g, m => ({
|
|
74
|
-
'&': '&',
|
|
75
|
-
'<': '<',
|
|
76
|
-
'"': '"'
|
|
77
|
-
})[m]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function escapeScript(content) {
|
|
81
|
-
return content.replace(/<(\/script>)/g, '\\x3c$2');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function htmlOpen(tagName, attrs) {
|
|
85
|
-
const attrStr = attrs ? Object.entries(attrs).map(([key, value]) => {
|
|
86
|
-
if (value == null || value === false) return;
|
|
87
|
-
key = ` ${escapeHtml(key)}`;
|
|
88
|
-
if (value === true) return key;
|
|
89
|
-
return `${key}="${escapeHtml(value)}"`;
|
|
90
|
-
}).filter(Boolean).join('') : '';
|
|
91
|
-
return `<${tagName}${attrStr}>`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function htmlClose(tagName) {
|
|
95
|
-
return `</${tagName}>`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function wrapHtml(tagName, content, attrs) {
|
|
99
|
-
if (content == null) return htmlOpen(tagName, attrs);
|
|
100
|
-
return htmlOpen(tagName, attrs) + (content || '') + htmlClose(tagName);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function buildCode(fn, args) {
|
|
104
|
-
const params = args.map(arg => {
|
|
105
|
-
if (typeof arg === 'function') return arg.toString();
|
|
106
|
-
return JSON.stringify(arg != null ? arg : null);
|
|
107
|
-
}).join(',');
|
|
108
|
-
return `(${fn.toString()})(${params})`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function persistJS(items, context) {
|
|
112
|
-
return items.map(item => {
|
|
113
|
-
if (item.type === 'script') {
|
|
114
|
-
const _item$data = item.data,
|
|
115
|
-
{
|
|
116
|
-
textContent
|
|
117
|
-
} = _item$data,
|
|
118
|
-
rest = _objectWithoutPropertiesLoose(_item$data, _excluded);
|
|
119
|
-
|
|
120
|
-
return wrapHtml('script', textContent || '', rest);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (item.type === 'iife') {
|
|
124
|
-
const {
|
|
125
|
-
fn,
|
|
126
|
-
getParams
|
|
127
|
-
} = item.data;
|
|
128
|
-
return wrapHtml('script', escapeScript(buildCode(fn, (getParams == null ? void 0 : getParams(context)) || [])));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return '';
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function persistCSS(items) {
|
|
136
|
-
return items.map(item => {
|
|
137
|
-
if (item.type === 'stylesheet') {
|
|
138
|
-
return wrapHtml('link', null, _extends({
|
|
139
|
-
rel: 'stylesheet'
|
|
140
|
-
}, item.data));
|
|
141
|
-
}
|
|
142
|
-
/* else if (item.type === 'style') */
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return wrapHtml('style', item.data);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
Math.random().toString(36).slice(2, 8);
|
|
150
|
-
|
|
151
|
-
function wrapFunction(fn, {
|
|
152
|
-
before,
|
|
153
|
-
after
|
|
154
|
-
}) {
|
|
155
|
-
return function wrapped(...args) {
|
|
156
|
-
const ctx = {
|
|
157
|
-
args,
|
|
158
|
-
thisObj: this
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
if (before) before(ctx);
|
|
163
|
-
} catch (_unused) {// ignore
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
ctx.result = fn.apply(ctx.thisObj, ctx.args);
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
if (after) after(ctx);
|
|
170
|
-
} catch (_unused2) {// ignore
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return ctx.result;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
10
|
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";
|
|
178
|
-
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.
|
|
11
|
+
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.14.2-alpha.4+569dd11"}`].map(src => ({
|
|
179
12
|
type: 'script',
|
|
180
13
|
data: {
|
|
181
14
|
src
|
|
182
15
|
}
|
|
183
16
|
}));
|
|
184
17
|
function fillTemplate(root, assets, extra) {
|
|
185
|
-
extra = _extends
|
|
18
|
+
extra = _extends({
|
|
186
19
|
baseJs: BASE_JS
|
|
187
20
|
}, extra);
|
|
188
21
|
const {
|
|
@@ -264,66 +97,50 @@ var config$1 = {
|
|
|
264
97
|
}]
|
|
265
98
|
};
|
|
266
99
|
|
|
267
|
-
|
|
100
|
+
function createTransformHooks() {
|
|
101
|
+
return {
|
|
102
|
+
parser: new Hook(),
|
|
103
|
+
beforeParse: new Hook(),
|
|
104
|
+
afterParse: new Hook(),
|
|
105
|
+
htmltag: new Hook(),
|
|
106
|
+
retransform: new Hook()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
268
109
|
/**
|
|
269
|
-
*
|
|
110
|
+
* This function is only used to help type checking.
|
|
270
111
|
*/
|
|
271
112
|
|
|
272
|
-
function
|
|
273
|
-
return
|
|
274
|
-
if (typeof path === 'string') {
|
|
275
|
-
if (path.startsWith(`${name}/`)) {
|
|
276
|
-
path = `${npmPrefix}${name}@${version}${path.slice(name.length)}`;
|
|
277
|
-
} else if (path.startsWith(`${name}@`)) {
|
|
278
|
-
path = `${npmPrefix}${path}`;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return path;
|
|
283
|
-
});
|
|
113
|
+
function definePlugin(plugin) {
|
|
114
|
+
return plugin;
|
|
284
115
|
}
|
|
285
116
|
|
|
286
117
|
const name$2 = 'katex';
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
enableFeature = () => {
|
|
300
|
-
context.features[name$2] = true;
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
transformHooks.afterParse.tap((_, context) => {
|
|
304
|
-
const {
|
|
305
|
-
frontmatter
|
|
306
|
-
} = context;
|
|
307
|
-
|
|
308
|
-
if (frontmatter != null && frontmatter.markmap) {
|
|
309
|
-
['extraJs', 'extraCss'].forEach(key => {
|
|
310
|
-
if (frontmatter.markmap[key]) {
|
|
311
|
-
frontmatter.markmap[key] = resolveNpmPaths(frontmatter.markmap[key], name$2, config$1.versions.katex);
|
|
118
|
+
var katex = definePlugin({
|
|
119
|
+
name: name$2,
|
|
120
|
+
config: config$1,
|
|
121
|
+
|
|
122
|
+
transform(transformHooks) {
|
|
123
|
+
let enableFeature = () => {};
|
|
124
|
+
|
|
125
|
+
transformHooks.parser.tap(md => {
|
|
126
|
+
md.use(remarkableKatex);
|
|
127
|
+
md.renderer.rules.katex = wrapFunction(md.renderer.rules.katex, {
|
|
128
|
+
after: () => {
|
|
129
|
+
enableFeature();
|
|
312
130
|
}
|
|
313
131
|
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
132
|
+
});
|
|
133
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
134
|
+
enableFeature = () => {
|
|
135
|
+
context.features[name$2] = true;
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
styles: config$1.styles,
|
|
140
|
+
scripts: config$1.scripts
|
|
141
|
+
};
|
|
142
|
+
}
|
|
321
143
|
|
|
322
|
-
var katex = /*#__PURE__*/Object.freeze({
|
|
323
|
-
__proto__: null,
|
|
324
|
-
config: config$1,
|
|
325
|
-
name: name$2,
|
|
326
|
-
transform: transform$2
|
|
327
144
|
});
|
|
328
145
|
|
|
329
146
|
var config = {
|
|
@@ -350,83 +167,87 @@ var config = {
|
|
|
350
167
|
};
|
|
351
168
|
|
|
352
169
|
const name$1 = 'prism';
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
grammar = Prism.languages[lang];
|
|
365
|
-
|
|
170
|
+
var prism = definePlugin({
|
|
171
|
+
name: name$1,
|
|
172
|
+
config,
|
|
173
|
+
|
|
174
|
+
transform(transformHooks) {
|
|
175
|
+
let enableFeature = () => {};
|
|
176
|
+
|
|
177
|
+
transformHooks.parser.tap(md => {
|
|
178
|
+
md.set({
|
|
179
|
+
highlight: (str, lang) => {
|
|
180
|
+
enableFeature();
|
|
181
|
+
let grammar = Prism.languages[lang];
|
|
182
|
+
|
|
183
|
+
if (!grammar && lang) {
|
|
184
|
+
loadLanguages([lang]);
|
|
185
|
+
grammar = Prism.languages[lang];
|
|
186
|
+
}
|
|
366
187
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
188
|
+
if (grammar) {
|
|
189
|
+
return Prism.highlight(str, grammar, lang);
|
|
190
|
+
}
|
|
370
191
|
|
|
371
|
-
|
|
372
|
-
|
|
192
|
+
return '';
|
|
193
|
+
}
|
|
194
|
+
});
|
|
373
195
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
196
|
+
transformHooks.beforeParse.tap((_, context) => {
|
|
197
|
+
enableFeature = () => {
|
|
198
|
+
context.features[name$1] = true;
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
styles: config.styles
|
|
378
203
|
};
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
styles: config.styles
|
|
382
|
-
};
|
|
383
|
-
}
|
|
204
|
+
}
|
|
384
205
|
|
|
385
|
-
var prism = /*#__PURE__*/Object.freeze({
|
|
386
|
-
__proto__: null,
|
|
387
|
-
config: config,
|
|
388
|
-
name: name$1,
|
|
389
|
-
transform: transform$1
|
|
390
206
|
});
|
|
391
207
|
|
|
392
208
|
const name = 'frontmatter';
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
frontmatter
|
|
209
|
+
var frontmatter = definePlugin({
|
|
210
|
+
name,
|
|
211
|
+
|
|
212
|
+
transform(transformHooks) {
|
|
213
|
+
transformHooks.beforeParse.tap((md, context) => {
|
|
214
|
+
const origParse = md.parse;
|
|
215
|
+
md.parse = wrapFunction(origParse, {
|
|
216
|
+
before(ctx) {
|
|
217
|
+
const [content] = ctx.args;
|
|
218
|
+
if (!content.startsWith('---\n')) return;
|
|
219
|
+
const endOffset = content.indexOf('\n---\n');
|
|
220
|
+
if (endOffset < 0) return;
|
|
221
|
+
const raw = content.slice(4, endOffset);
|
|
222
|
+
let frontmatter;
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
var _frontmatter;
|
|
226
|
+
|
|
227
|
+
frontmatter = yaml.load(raw);
|
|
228
|
+
|
|
229
|
+
if ((_frontmatter = frontmatter) != null && _frontmatter.markmap) {
|
|
230
|
+
frontmatter.markmap = normalizeMarkmapJsonOptions(frontmatter.markmap);
|
|
231
|
+
}
|
|
232
|
+
} catch (_unused) {
|
|
233
|
+
return;
|
|
412
234
|
}
|
|
413
|
-
} catch (_unused) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
235
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
236
|
+
context.frontmatter = frontmatter;
|
|
237
|
+
const offset = endOffset + 5;
|
|
238
|
+
ctx.args[0] = content.slice(offset);
|
|
239
|
+
},
|
|
421
240
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
241
|
+
after() {
|
|
242
|
+
md.parse = origParse;
|
|
243
|
+
}
|
|
425
244
|
|
|
245
|
+
});
|
|
426
246
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
247
|
+
return {};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
});
|
|
430
251
|
|
|
431
252
|
function normalizeMarkmapJsonOptions(options) {
|
|
432
253
|
if (!options) return;
|
|
@@ -452,22 +273,6 @@ function normalizeNumber(value) {
|
|
|
452
273
|
return +value;
|
|
453
274
|
}
|
|
454
275
|
|
|
455
|
-
var frontmatter = /*#__PURE__*/Object.freeze({
|
|
456
|
-
__proto__: null,
|
|
457
|
-
name: name,
|
|
458
|
-
transform: transform
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
function createTransformHooks() {
|
|
462
|
-
return {
|
|
463
|
-
parser: new Hook(),
|
|
464
|
-
beforeParse: new Hook(),
|
|
465
|
-
afterParse: new Hook(),
|
|
466
|
-
htmltag: new Hook(),
|
|
467
|
-
retransform: new Hook()
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
276
|
const plugins = [frontmatter, katex, prism];
|
|
472
277
|
|
|
473
278
|
function cleanNode(node) {
|
|
@@ -482,7 +287,7 @@ function cleanNode(node) {
|
|
|
482
287
|
if (['paragraph', 'fence'].includes(item.type)) {
|
|
483
288
|
if (!node.content) {
|
|
484
289
|
node.content = item.content;
|
|
485
|
-
node.payload = _extends
|
|
290
|
+
node.payload = _extends({}, node.payload, item.payload);
|
|
486
291
|
}
|
|
487
292
|
|
|
488
293
|
return false;
|
|
@@ -500,7 +305,7 @@ function cleanNode(node) {
|
|
|
500
305
|
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1;
|
|
501
306
|
node.children.forEach(item => {
|
|
502
307
|
if (item.type === 'list_item') {
|
|
503
|
-
item.payload = _extends
|
|
308
|
+
item.payload = _extends({}, item.payload, {
|
|
504
309
|
index
|
|
505
310
|
});
|
|
506
311
|
index += 1;
|
|
@@ -530,6 +335,7 @@ function resetDepth(node, depth = 0) {
|
|
|
530
335
|
|
|
531
336
|
class Transformer {
|
|
532
337
|
constructor(plugins$1 = plugins) {
|
|
338
|
+
this.assetsMap = {};
|
|
533
339
|
this.plugins = plugins$1;
|
|
534
340
|
this.hooks = createTransformHooks();
|
|
535
341
|
const assetsMap = {};
|
|
@@ -661,7 +467,7 @@ class Transformer {
|
|
|
661
467
|
cleanNode(root);
|
|
662
468
|
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0];
|
|
663
469
|
resetDepth(root);
|
|
664
|
-
return _extends
|
|
470
|
+
return _extends({}, context, {
|
|
665
471
|
root
|
|
666
472
|
});
|
|
667
473
|
}
|
|
@@ -702,7 +508,7 @@ class Transformer {
|
|
|
702
508
|
}
|
|
703
509
|
|
|
704
510
|
const transformerVersions = {
|
|
705
|
-
'markmap-lib': '0.14.
|
|
511
|
+
'markmap-lib': '0.14.2-alpha.4+569dd11',
|
|
706
512
|
d3: "6.7.0"
|
|
707
513
|
};
|
|
708
514
|
|