@slidev/parser 0.27.18 → 0.28.1
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/chunk-HINA34KW.mjs +393 -0
- package/dist/chunk-WBX4FRCI.js +393 -0
- package/dist/core.js +2 -2
- package/dist/core.mjs +1 -1
- package/dist/fs.js +11 -13
- package/dist/fs.mjs +2 -2
- package/dist/index.js +2 -6
- package/dist/index.mjs +1 -1
- package/fs.d.ts +1 -0
- package/package.json +11 -7
- package/dist/chunk-4MLX4OSA.js +0 -727
- package/dist/chunk-W27AU6TD.mjs +0 -704
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/core.ts
|
|
22
|
+
import YAML from "js-yaml";
|
|
23
|
+
|
|
24
|
+
// ../../node_modules/.pnpm/@antfu+utils@0.4.0/node_modules/@antfu/utils/dist/index.mjs
|
|
25
|
+
function toArray(array) {
|
|
26
|
+
array = array || [];
|
|
27
|
+
if (Array.isArray(array))
|
|
28
|
+
return array;
|
|
29
|
+
return [array];
|
|
30
|
+
}
|
|
31
|
+
function uniq(array) {
|
|
32
|
+
return Array.from(new Set(array));
|
|
33
|
+
}
|
|
34
|
+
function range(...args) {
|
|
35
|
+
let start, stop, step;
|
|
36
|
+
if (args.length === 1) {
|
|
37
|
+
start = 0;
|
|
38
|
+
step = 1;
|
|
39
|
+
[stop] = args;
|
|
40
|
+
} else {
|
|
41
|
+
[start, stop, step = 1] = args;
|
|
42
|
+
}
|
|
43
|
+
const arr = [];
|
|
44
|
+
let current = start;
|
|
45
|
+
while (current < stop) {
|
|
46
|
+
arr.push(current);
|
|
47
|
+
current += step || 1;
|
|
48
|
+
}
|
|
49
|
+
return arr;
|
|
50
|
+
}
|
|
51
|
+
var toString = (v) => Object.prototype.toString.call(v);
|
|
52
|
+
function notNullish(v) {
|
|
53
|
+
return v != null;
|
|
54
|
+
}
|
|
55
|
+
function isTruthy(v) {
|
|
56
|
+
return Boolean(v);
|
|
57
|
+
}
|
|
58
|
+
var isNumber = (val) => typeof val === "number";
|
|
59
|
+
var isObject = (val) => toString(val) === "[object Object]";
|
|
60
|
+
function objectMap(obj, fn) {
|
|
61
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/utils.ts
|
|
65
|
+
function parseRangeString(total, rangeStr) {
|
|
66
|
+
if (!rangeStr || rangeStr === "all" || rangeStr === "*")
|
|
67
|
+
return range(1, total + 1);
|
|
68
|
+
const pages = [];
|
|
69
|
+
for (const part of rangeStr.split(/[,;]/g)) {
|
|
70
|
+
if (!part.includes("-")) {
|
|
71
|
+
pages.push(+part);
|
|
72
|
+
} else {
|
|
73
|
+
const [start, end] = part.split("-", 2);
|
|
74
|
+
pages.push(...range(+start, !end ? total + 1 : +end + 1));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return uniq(pages).filter((i) => i <= total).sort((a, b) => a - b);
|
|
78
|
+
}
|
|
79
|
+
function parseAspectRatio(str) {
|
|
80
|
+
if (isNumber(str))
|
|
81
|
+
return str;
|
|
82
|
+
if (!isNaN(+str))
|
|
83
|
+
return +str;
|
|
84
|
+
const [wStr = "", hStr = ""] = str.split(/[:\/x\|]/);
|
|
85
|
+
const w = parseFloat(wStr.trim());
|
|
86
|
+
const h = parseFloat(hStr.trim());
|
|
87
|
+
if (isNaN(w) || isNaN(h) || h === 0)
|
|
88
|
+
throw new Error(`Invalid aspect ratio "${str}"`);
|
|
89
|
+
return w / h;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/config.ts
|
|
93
|
+
function resolveConfig(headmatter, themeMeta = {}) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const themeHightlighter = ["prism", "shiki"].includes(themeMeta.highlighter || "") ? themeMeta.highlighter : void 0;
|
|
96
|
+
const themeColorSchema = ["light", "dark"].includes(themeMeta.colorSchema || "") ? themeMeta.colorSchema : void 0;
|
|
97
|
+
const defaultConfig = {
|
|
98
|
+
theme: "default",
|
|
99
|
+
title: "Slidev",
|
|
100
|
+
titleTemplate: "%s - Slidev",
|
|
101
|
+
remoteAssets: false,
|
|
102
|
+
monaco: "dev",
|
|
103
|
+
download: false,
|
|
104
|
+
info: false,
|
|
105
|
+
highlighter: themeHightlighter || "prism",
|
|
106
|
+
lineNumbers: false,
|
|
107
|
+
colorSchema: themeColorSchema || "auto",
|
|
108
|
+
routerMode: "history",
|
|
109
|
+
aspectRatio: 16 / 9,
|
|
110
|
+
canvasWidth: 980,
|
|
111
|
+
selectable: false,
|
|
112
|
+
themeConfig: {},
|
|
113
|
+
fonts: {},
|
|
114
|
+
favicon: "https://cdn.jsdelivr.net/gh/slidevjs/slidev/assets/favicon.png",
|
|
115
|
+
drawings: {},
|
|
116
|
+
plantUmlServer: "https://www.plantuml.com/plantuml"
|
|
117
|
+
};
|
|
118
|
+
const config = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, defaultConfig), themeMeta.defaults), headmatter.config), headmatter), {
|
|
119
|
+
fonts: resolveFonts(__spreadValues(__spreadValues(__spreadValues({}, (_a = themeMeta.defaults) == null ? void 0 : _a.fonts), (_b = headmatter.config) == null ? void 0 : _b.fonts), headmatter == null ? void 0 : headmatter.fonts)),
|
|
120
|
+
drawings: resolveDarwings(headmatter.drawings)
|
|
121
|
+
});
|
|
122
|
+
if (config.colorSchema !== "dark" && config.colorSchema !== "light")
|
|
123
|
+
config.colorSchema = "auto";
|
|
124
|
+
if (themeColorSchema && config.colorSchema === "auto")
|
|
125
|
+
config.colorSchema = themeColorSchema;
|
|
126
|
+
config.aspectRatio = parseAspectRatio(config.aspectRatio);
|
|
127
|
+
if (themeColorSchema && config.colorSchema !== themeColorSchema)
|
|
128
|
+
console.warn(`[slidev] Color schema "${config.colorSchema}" does not supported by the theme`);
|
|
129
|
+
if (themeHightlighter && config.highlighter !== themeHightlighter)
|
|
130
|
+
console.warn(`[slidev] Syntax highlighter "${config.highlighter}" does not supported by the theme`);
|
|
131
|
+
return config;
|
|
132
|
+
}
|
|
133
|
+
function resolveFonts(fonts = {}) {
|
|
134
|
+
const {
|
|
135
|
+
fallbacks = true,
|
|
136
|
+
italic = false,
|
|
137
|
+
provider = "google"
|
|
138
|
+
} = fonts;
|
|
139
|
+
let sans = toArray(fonts.sans).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
140
|
+
let serif = toArray(fonts.serif).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
141
|
+
let mono = toArray(fonts.mono).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
142
|
+
const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
|
|
143
|
+
const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
144
|
+
const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
|
|
145
|
+
const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([...sans, ...serif, ...mono, ...custom]) : [];
|
|
146
|
+
webfonts.filter((i) => local.includes(i));
|
|
147
|
+
function toQuoted(font) {
|
|
148
|
+
if (/^(['"]).*\1$/.test(font))
|
|
149
|
+
return font;
|
|
150
|
+
return `"${font}"`;
|
|
151
|
+
}
|
|
152
|
+
if (fallbacks) {
|
|
153
|
+
sans = uniq([
|
|
154
|
+
...sans.map(toQuoted),
|
|
155
|
+
"ui-sans-serif",
|
|
156
|
+
"system-ui",
|
|
157
|
+
"-apple-system",
|
|
158
|
+
"BlinkMacSystemFont",
|
|
159
|
+
'"Segoe UI"',
|
|
160
|
+
"Roboto",
|
|
161
|
+
'"Helvetica Neue"',
|
|
162
|
+
"Arial",
|
|
163
|
+
'"Noto Sans"',
|
|
164
|
+
"sans-serif",
|
|
165
|
+
'"Apple Color Emoji"',
|
|
166
|
+
'"Segoe UI Emoji"',
|
|
167
|
+
'"Segoe UI Symbol"',
|
|
168
|
+
'"Noto Color Emoji"'
|
|
169
|
+
]);
|
|
170
|
+
serif = uniq([
|
|
171
|
+
...serif.map(toQuoted),
|
|
172
|
+
"ui-serif",
|
|
173
|
+
"Georgia",
|
|
174
|
+
"Cambria",
|
|
175
|
+
'"Times New Roman"',
|
|
176
|
+
"Times",
|
|
177
|
+
"serif"
|
|
178
|
+
]);
|
|
179
|
+
mono = uniq([
|
|
180
|
+
...mono.map(toQuoted),
|
|
181
|
+
"ui-monospace",
|
|
182
|
+
"SFMono-Regular",
|
|
183
|
+
"Menlo",
|
|
184
|
+
"Monaco",
|
|
185
|
+
"Consolas",
|
|
186
|
+
'"Liberation Mono"',
|
|
187
|
+
'"Courier New"',
|
|
188
|
+
"monospace"
|
|
189
|
+
]);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
sans,
|
|
193
|
+
serif,
|
|
194
|
+
mono,
|
|
195
|
+
webfonts,
|
|
196
|
+
provider,
|
|
197
|
+
local,
|
|
198
|
+
italic,
|
|
199
|
+
weights
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function resolveDarwings(options = {}) {
|
|
203
|
+
const {
|
|
204
|
+
enabled = true,
|
|
205
|
+
persist = false,
|
|
206
|
+
presenterOnly = false,
|
|
207
|
+
syncAll = true
|
|
208
|
+
} = options;
|
|
209
|
+
const persistPath = typeof persist === "string" ? persist : persist ? ".slidev/drawings" : false;
|
|
210
|
+
return {
|
|
211
|
+
enabled,
|
|
212
|
+
persist: persistPath,
|
|
213
|
+
presenterOnly,
|
|
214
|
+
syncAll
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/core.ts
|
|
219
|
+
function stringify(data) {
|
|
220
|
+
return `${data.slides.map((slide, idx) => stringifySlide(slide.inline || slide, idx)).join("\n").trim()}
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
223
|
+
function filterDisabled(data) {
|
|
224
|
+
data.slides = data.slides.filter((i) => {
|
|
225
|
+
var _a;
|
|
226
|
+
return !((_a = i.frontmatter) == null ? void 0 : _a.disabled);
|
|
227
|
+
});
|
|
228
|
+
return data;
|
|
229
|
+
}
|
|
230
|
+
function stringifySlide(data, idx = 0) {
|
|
231
|
+
if (data.raw == null)
|
|
232
|
+
prettifySlide(data);
|
|
233
|
+
return data.raw.startsWith("---") || idx === 0 ? data.raw : `---
|
|
234
|
+
${data.raw.startsWith("\n") ? data.raw : `
|
|
235
|
+
${data.raw}`}`;
|
|
236
|
+
}
|
|
237
|
+
function prettifySlide(data) {
|
|
238
|
+
data.content = `
|
|
239
|
+
${data.content.trim()}
|
|
240
|
+
`;
|
|
241
|
+
data.raw = Object.keys(data.frontmatter || {}).length ? `---
|
|
242
|
+
${YAML.dump(data.frontmatter).trim()}
|
|
243
|
+
---
|
|
244
|
+
${data.content}` : data.content;
|
|
245
|
+
if (data.note)
|
|
246
|
+
data.raw += `
|
|
247
|
+
<!--
|
|
248
|
+
${data.note.trim()}
|
|
249
|
+
-->
|
|
250
|
+
`;
|
|
251
|
+
else
|
|
252
|
+
data.raw += "\n";
|
|
253
|
+
return data;
|
|
254
|
+
}
|
|
255
|
+
function prettify(data) {
|
|
256
|
+
data.slides.forEach(prettifySlide);
|
|
257
|
+
return data;
|
|
258
|
+
}
|
|
259
|
+
function matter(code) {
|
|
260
|
+
let data = {};
|
|
261
|
+
const content = code.replace(/^---.*\r?\n([\s\S]*?)---/, (_, d) => {
|
|
262
|
+
data = YAML.load(d);
|
|
263
|
+
if (!isObject(data))
|
|
264
|
+
data = {};
|
|
265
|
+
return "";
|
|
266
|
+
});
|
|
267
|
+
return { data, content };
|
|
268
|
+
}
|
|
269
|
+
function detectFeatures(code) {
|
|
270
|
+
return {
|
|
271
|
+
katex: !!code.match(/\$.*?\$/) || !!code.match(/$\$\$/),
|
|
272
|
+
monaco: !!code.match(/{monaco.*}/),
|
|
273
|
+
tweet: !!code.match(/<Tweet\b/),
|
|
274
|
+
mermaid: !!code.match(/^```mermaid/m)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function parseSlide(raw) {
|
|
278
|
+
var _a, _b;
|
|
279
|
+
const result = matter(raw);
|
|
280
|
+
let note;
|
|
281
|
+
const frontmatter = result.data || {};
|
|
282
|
+
let content = result.content.trim();
|
|
283
|
+
const comments = Array.from(content.matchAll(/<!--([\s\S]*?)-->/g));
|
|
284
|
+
if (comments.length) {
|
|
285
|
+
const last = comments[comments.length - 1];
|
|
286
|
+
if (last.index && last.index + last[0].length >= content.length) {
|
|
287
|
+
note = last[1].trim();
|
|
288
|
+
content = content.slice(0, last.index).trim();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
let title;
|
|
292
|
+
let level;
|
|
293
|
+
if (frontmatter.title || frontmatter.name) {
|
|
294
|
+
title = frontmatter.title || frontmatter.name;
|
|
295
|
+
level = frontmatter.level || 1;
|
|
296
|
+
} else {
|
|
297
|
+
const match = content.match(/^(#+) (.*)$/m);
|
|
298
|
+
title = (_a = match == null ? void 0 : match[2]) == null ? void 0 : _a.trim();
|
|
299
|
+
level = (_b = match == null ? void 0 : match[1]) == null ? void 0 : _b.length;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
raw,
|
|
303
|
+
title,
|
|
304
|
+
level,
|
|
305
|
+
content,
|
|
306
|
+
frontmatter,
|
|
307
|
+
note
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function parse(markdown, filepath, themeMeta) {
|
|
311
|
+
var _a, _b;
|
|
312
|
+
const lines = markdown.split(/\r?\n/g);
|
|
313
|
+
const slides = [];
|
|
314
|
+
let start = 0;
|
|
315
|
+
function slice(end) {
|
|
316
|
+
if (start === end)
|
|
317
|
+
return;
|
|
318
|
+
const raw = lines.slice(start, end).join("\n");
|
|
319
|
+
slides.push(__spreadProps(__spreadValues({}, parseSlide(raw)), {
|
|
320
|
+
index: slides.length,
|
|
321
|
+
start,
|
|
322
|
+
end
|
|
323
|
+
}));
|
|
324
|
+
start = end + 1;
|
|
325
|
+
}
|
|
326
|
+
for (let i = 0; i < lines.length; i++) {
|
|
327
|
+
const line = lines[i].trimEnd();
|
|
328
|
+
if (line.match(/^---+/)) {
|
|
329
|
+
slice(i);
|
|
330
|
+
const next = lines[i + 1];
|
|
331
|
+
if (line.match(/^---([^-].*)?$/) && !(next == null ? void 0 : next.match(/^\s*$/))) {
|
|
332
|
+
start = i;
|
|
333
|
+
for (i += 1; i < lines.length; i++) {
|
|
334
|
+
if (lines[i].trimEnd().match(/^---$/))
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
} else if (line.startsWith("```")) {
|
|
339
|
+
for (i += 1; i < lines.length; i++) {
|
|
340
|
+
if (lines[i].startsWith("```"))
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (start <= lines.length - 1)
|
|
346
|
+
slice(lines.length);
|
|
347
|
+
const headmatter = ((_a = slides[0]) == null ? void 0 : _a.frontmatter) || {};
|
|
348
|
+
headmatter.title = headmatter.title || ((_b = slides[0]) == null ? void 0 : _b.title);
|
|
349
|
+
const config = resolveConfig(headmatter, themeMeta);
|
|
350
|
+
const features = detectFeatures(markdown);
|
|
351
|
+
return {
|
|
352
|
+
raw: markdown,
|
|
353
|
+
filepath,
|
|
354
|
+
slides,
|
|
355
|
+
config,
|
|
356
|
+
features,
|
|
357
|
+
headmatter,
|
|
358
|
+
themeMeta
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function mergeFeatureFlags(a, b) {
|
|
362
|
+
return objectMap(a, (k, v) => [k, v || b[k]]);
|
|
363
|
+
}
|
|
364
|
+
function scanMonacoModules(md) {
|
|
365
|
+
const typeModules = /* @__PURE__ */ new Set();
|
|
366
|
+
md.replace(/^```(\w+?)\s*{monaco([\w:,-]*)}[\s\n]*([\s\S]+?)^```/mg, (full, lang = "ts", options, code) => {
|
|
367
|
+
options = options || "";
|
|
368
|
+
lang = lang.trim();
|
|
369
|
+
if (lang === "ts" || lang === "typescript") {
|
|
370
|
+
Array.from(code.matchAll(/\s+from\s+(["'])([\/\w@-]+)\1/g)).map((i) => i[2]).filter(isTruthy).map((i) => typeModules.add(i));
|
|
371
|
+
}
|
|
372
|
+
return "";
|
|
373
|
+
});
|
|
374
|
+
return Array.from(typeModules);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export {
|
|
378
|
+
__spreadValues,
|
|
379
|
+
parseRangeString,
|
|
380
|
+
parseAspectRatio,
|
|
381
|
+
resolveConfig,
|
|
382
|
+
resolveFonts,
|
|
383
|
+
stringify,
|
|
384
|
+
filterDisabled,
|
|
385
|
+
stringifySlide,
|
|
386
|
+
prettifySlide,
|
|
387
|
+
prettify,
|
|
388
|
+
detectFeatures,
|
|
389
|
+
parseSlide,
|
|
390
|
+
parse,
|
|
391
|
+
mergeFeatureFlags,
|
|
392
|
+
scanMonacoModules
|
|
393
|
+
};
|