@slidev/cli 0.43.0-beta.4 → 0.43.0-beta.6
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/{build-ZIF7XMD2.mjs → build-BUNPGN2Z.mjs} +1 -1
- package/dist/{build-C6YSRCET.js → build-IN5YJEKU.js} +5 -5
- package/dist/{chunk-WVI7OC5A.js → chunk-3SSSSIJP.js} +4 -4
- package/dist/chunk-3TJE2CDX.mjs +1684 -0
- package/dist/chunk-B2S4FMPE.js +1684 -0
- package/dist/{chunk-B2WFHX3U.mjs → chunk-XH4NQ4ZL.mjs} +2 -2
- package/dist/cli.js +27 -27
- package/dist/cli.mjs +3 -3
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/package.json +8 -8
- package/dist/chunk-4D4M2E5M.js +0 -4872
- package/dist/chunk-4VXY5G3T.mjs +0 -4872
package/dist/chunk-4VXY5G3T.mjs
DELETED
|
@@ -1,4872 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadSetups
|
|
3
|
-
} from "./chunk-JDHANZ37.mjs";
|
|
4
|
-
import {
|
|
5
|
-
generateGoogleFontsUrl,
|
|
6
|
-
resolveGlobalImportPath,
|
|
7
|
-
resolveImportPath,
|
|
8
|
-
stringifyMarkdownTokens,
|
|
9
|
-
toAtFS
|
|
10
|
-
} from "./chunk-ZEKM4EGL.mjs";
|
|
11
|
-
import {
|
|
12
|
-
__commonJS,
|
|
13
|
-
__require,
|
|
14
|
-
__toESM
|
|
15
|
-
} from "./chunk-QHOBBTS4.mjs";
|
|
16
|
-
|
|
17
|
-
// ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
|
|
18
|
-
var require_fast_deep_equal = __commonJS({
|
|
19
|
-
"../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
|
|
20
|
-
"use strict";
|
|
21
|
-
module.exports = function equal2(a, b) {
|
|
22
|
-
if (a === b)
|
|
23
|
-
return true;
|
|
24
|
-
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
25
|
-
if (a.constructor !== b.constructor)
|
|
26
|
-
return false;
|
|
27
|
-
var length, i, keys;
|
|
28
|
-
if (Array.isArray(a)) {
|
|
29
|
-
length = a.length;
|
|
30
|
-
if (length != b.length)
|
|
31
|
-
return false;
|
|
32
|
-
for (i = length; i-- !== 0; )
|
|
33
|
-
if (!equal2(a[i], b[i]))
|
|
34
|
-
return false;
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
if (a.constructor === RegExp)
|
|
38
|
-
return a.source === b.source && a.flags === b.flags;
|
|
39
|
-
if (a.valueOf !== Object.prototype.valueOf)
|
|
40
|
-
return a.valueOf() === b.valueOf();
|
|
41
|
-
if (a.toString !== Object.prototype.toString)
|
|
42
|
-
return a.toString() === b.toString();
|
|
43
|
-
keys = Object.keys(a);
|
|
44
|
-
length = keys.length;
|
|
45
|
-
if (length !== Object.keys(b).length)
|
|
46
|
-
return false;
|
|
47
|
-
for (i = length; i-- !== 0; )
|
|
48
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
|
|
49
|
-
return false;
|
|
50
|
-
for (i = length; i-- !== 0; ) {
|
|
51
|
-
var key = keys[i];
|
|
52
|
-
if (!equal2(a[key], b[key]))
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return a !== a && b !== b;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// node/common.ts
|
|
63
|
-
import { existsSync, promises as fs } from "node:fs";
|
|
64
|
-
import { join } from "node:path";
|
|
65
|
-
import { uniq } from "@antfu/utils";
|
|
66
|
-
import { loadConfigFromFile, mergeConfig } from "vite";
|
|
67
|
-
async function getIndexHtml({ clientRoot, themeRoots, addonRoots, data, userRoot }) {
|
|
68
|
-
let main = await fs.readFile(join(clientRoot, "index.html"), "utf-8");
|
|
69
|
-
let head = "";
|
|
70
|
-
let body = "";
|
|
71
|
-
head += `<link rel="icon" href="${data.config.favicon}">`;
|
|
72
|
-
const roots = uniq([
|
|
73
|
-
...themeRoots,
|
|
74
|
-
...addonRoots,
|
|
75
|
-
userRoot
|
|
76
|
-
]);
|
|
77
|
-
for (const root of roots) {
|
|
78
|
-
const path = join(root, "index.html");
|
|
79
|
-
if (!existsSync(path))
|
|
80
|
-
continue;
|
|
81
|
-
const index = await fs.readFile(path, "utf-8");
|
|
82
|
-
head += `
|
|
83
|
-
${(index.match(/<head>([\s\S]*?)<\/head>/im)?.[1] || "").trim()}`;
|
|
84
|
-
body += `
|
|
85
|
-
${(index.match(/<body>([\s\S]*?)<\/body>/im)?.[1] || "").trim()}`;
|
|
86
|
-
}
|
|
87
|
-
if (data.features.tweet)
|
|
88
|
-
body += '\n<script async src="https://platform.twitter.com/widgets.js"></script>';
|
|
89
|
-
if (data.config.fonts.webfonts.length && data.config.fonts.provider !== "none")
|
|
90
|
-
head += `
|
|
91
|
-
<link rel="stylesheet" href="${generateGoogleFontsUrl(data.config.fonts)}" type="text/css">`;
|
|
92
|
-
main = main.replace("__ENTRY__", toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", head).replace("<!-- body -->", body);
|
|
93
|
-
return main;
|
|
94
|
-
}
|
|
95
|
-
async function mergeViteConfigs({ addonRoots, themeRoots }, viteConfig, config, command) {
|
|
96
|
-
const configEnv = {
|
|
97
|
-
mode: "development",
|
|
98
|
-
command
|
|
99
|
-
};
|
|
100
|
-
const files = uniq([
|
|
101
|
-
...themeRoots,
|
|
102
|
-
...addonRoots
|
|
103
|
-
]).map((i) => join(i, "vite.config.ts"));
|
|
104
|
-
for await (const file of files) {
|
|
105
|
-
if (!existsSync(file))
|
|
106
|
-
continue;
|
|
107
|
-
const viteConfig2 = await loadConfigFromFile(configEnv, file);
|
|
108
|
-
if (!viteConfig2?.config)
|
|
109
|
-
continue;
|
|
110
|
-
config = mergeConfig(config, viteConfig2.config);
|
|
111
|
-
}
|
|
112
|
-
return mergeConfig(viteConfig, config);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// node/plugins/preset.ts
|
|
116
|
-
import { join as join8 } from "node:path";
|
|
117
|
-
import { existsSync as existsSync4 } from "node:fs";
|
|
118
|
-
import process3 from "node:process";
|
|
119
|
-
import Vue from "@vitejs/plugin-vue";
|
|
120
|
-
import VueJsx from "@vitejs/plugin-vue-jsx";
|
|
121
|
-
import Icons from "unplugin-icons/vite";
|
|
122
|
-
import IconsResolver from "unplugin-icons/resolver";
|
|
123
|
-
import Components from "unplugin-vue-components/vite";
|
|
124
|
-
import ServerRef from "vite-plugin-vue-server-ref";
|
|
125
|
-
import { notNullish as notNullish2 } from "@antfu/utils";
|
|
126
|
-
|
|
127
|
-
// node/drawings.ts
|
|
128
|
-
import { basename, dirname, join as join2, resolve } from "node:path";
|
|
129
|
-
import fs2 from "fs-extra";
|
|
130
|
-
import fg from "fast-glob";
|
|
131
|
-
function resolveDrawingsDir(options) {
|
|
132
|
-
return options.data.config.drawings.persist ? resolve(
|
|
133
|
-
dirname(options.entry),
|
|
134
|
-
options.data.config.drawings.persist
|
|
135
|
-
) : void 0;
|
|
136
|
-
}
|
|
137
|
-
async function loadDrawings(options) {
|
|
138
|
-
const dir = resolveDrawingsDir(options);
|
|
139
|
-
if (!dir || !fs2.existsSync(dir))
|
|
140
|
-
return {};
|
|
141
|
-
const files = await fg("*.svg", {
|
|
142
|
-
onlyFiles: true,
|
|
143
|
-
cwd: dir,
|
|
144
|
-
absolute: true,
|
|
145
|
-
suppressErrors: true
|
|
146
|
-
});
|
|
147
|
-
const obj = {};
|
|
148
|
-
await Promise.all(files.map(async (path) => {
|
|
149
|
-
const num = +basename(path, ".svg");
|
|
150
|
-
if (Number.isNaN(num))
|
|
151
|
-
return;
|
|
152
|
-
const content = await fs2.readFile(path, "utf8");
|
|
153
|
-
const lines = content.split(/\n/g);
|
|
154
|
-
obj[num.toString()] = lines.slice(1, -1).join("\n");
|
|
155
|
-
}));
|
|
156
|
-
return obj;
|
|
157
|
-
}
|
|
158
|
-
async function writeDrawings(options, drawing) {
|
|
159
|
-
const dir = resolveDrawingsDir(options);
|
|
160
|
-
if (!dir)
|
|
161
|
-
return;
|
|
162
|
-
const width = options.data.config.canvasWidth;
|
|
163
|
-
const height = Math.round(width / options.data.config.aspectRatio);
|
|
164
|
-
const SVG_HEAD = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">`;
|
|
165
|
-
await fs2.ensureDir(dir);
|
|
166
|
-
return Promise.all(
|
|
167
|
-
Object.entries(drawing).map(async ([key, value]) => {
|
|
168
|
-
if (!value)
|
|
169
|
-
return;
|
|
170
|
-
const svg = `${SVG_HEAD}
|
|
171
|
-
${value}
|
|
172
|
-
</svg>`;
|
|
173
|
-
await fs2.writeFile(join2(dir, `${key}.svg`), svg, "utf-8");
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// node/plugins/extendConfig.ts
|
|
179
|
-
import { dirname as dirname3, join as join4 } from "node:path";
|
|
180
|
-
import { mergeConfig as mergeConfig2 } from "vite";
|
|
181
|
-
import isInstalledGlobally from "is-installed-globally";
|
|
182
|
-
import { uniq as uniq2 } from "@antfu/utils";
|
|
183
|
-
|
|
184
|
-
// ../client/package.json
|
|
185
|
-
var dependencies = {
|
|
186
|
-
"@antfu/utils": "^0.7.6",
|
|
187
|
-
"@slidev/parser": "workspace:*",
|
|
188
|
-
"@slidev/types": "workspace:*",
|
|
189
|
-
"@unocss/reset": "^0.55.5",
|
|
190
|
-
"@vueuse/core": "^10.4.1",
|
|
191
|
-
"@vueuse/head": "^1.3.1",
|
|
192
|
-
"@vueuse/math": "^10.4.1",
|
|
193
|
-
"@vueuse/motion": "^2.0.0",
|
|
194
|
-
codemirror: "^5.65.5",
|
|
195
|
-
defu: "^6.1.2",
|
|
196
|
-
drauu: "^0.3.5",
|
|
197
|
-
"file-saver": "^2.0.5",
|
|
198
|
-
"fuse.js": "^6.6.2",
|
|
199
|
-
"js-base64": "^3.7.5",
|
|
200
|
-
"js-yaml": "^4.1.0",
|
|
201
|
-
katex: "^0.16.8",
|
|
202
|
-
mermaid: "^10.4.0",
|
|
203
|
-
"monaco-editor": "^0.37.1",
|
|
204
|
-
nanoid: "^4.0.2",
|
|
205
|
-
prettier: "^3.0.3",
|
|
206
|
-
recordrtc: "^5.6.2",
|
|
207
|
-
resolve: "^1.22.4",
|
|
208
|
-
unocss: "^0.55.5",
|
|
209
|
-
"vite-plugin-windicss": "^1.9.1",
|
|
210
|
-
vue: "^3.3.4",
|
|
211
|
-
"vue-router": "^4.2.4",
|
|
212
|
-
"vue-starport": "^0.3.0",
|
|
213
|
-
windicss: "^3.5.6"
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// node/vite/searchRoot.ts
|
|
217
|
-
import fs3 from "node:fs";
|
|
218
|
-
import { dirname as dirname2, join as join3 } from "node:path";
|
|
219
|
-
var ROOT_FILES = [
|
|
220
|
-
// '.git',
|
|
221
|
-
// https://pnpm.js.org/workspaces/
|
|
222
|
-
"pnpm-workspace.yaml"
|
|
223
|
-
// https://rushjs.io/pages/advanced/config_files/
|
|
224
|
-
// 'rush.json',
|
|
225
|
-
// https://nx.dev/latest/react/getting-started/nx-setup
|
|
226
|
-
// 'workspace.json',
|
|
227
|
-
// 'nx.json'
|
|
228
|
-
];
|
|
229
|
-
function hasWorkspacePackageJSON(root) {
|
|
230
|
-
const path = join3(root, "package.json");
|
|
231
|
-
try {
|
|
232
|
-
fs3.accessSync(path, fs3.constants.R_OK);
|
|
233
|
-
} catch {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
const content = JSON.parse(fs3.readFileSync(path, "utf-8")) || {};
|
|
237
|
-
return !!content.workspaces;
|
|
238
|
-
}
|
|
239
|
-
function hasRootFile(root) {
|
|
240
|
-
return ROOT_FILES.some((file) => fs3.existsSync(join3(root, file)));
|
|
241
|
-
}
|
|
242
|
-
function hasPackageJSON(root) {
|
|
243
|
-
const path = join3(root, "package.json");
|
|
244
|
-
return fs3.existsSync(path);
|
|
245
|
-
}
|
|
246
|
-
function searchForPackageRoot(current, root = current) {
|
|
247
|
-
if (hasPackageJSON(current))
|
|
248
|
-
return current;
|
|
249
|
-
const dir = dirname2(current);
|
|
250
|
-
if (!dir || dir === current)
|
|
251
|
-
return root;
|
|
252
|
-
return searchForPackageRoot(dir, root);
|
|
253
|
-
}
|
|
254
|
-
function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
|
|
255
|
-
if (hasRootFile(current))
|
|
256
|
-
return current;
|
|
257
|
-
if (hasWorkspacePackageJSON(current))
|
|
258
|
-
return current;
|
|
259
|
-
const dir = dirname2(current);
|
|
260
|
-
if (!dir || dir === current)
|
|
261
|
-
return root;
|
|
262
|
-
return searchForWorkspaceRoot(dir, root);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// node/plugins/extendConfig.ts
|
|
266
|
-
var EXCLUDE = [
|
|
267
|
-
"@slidev/shared",
|
|
268
|
-
"@slidev/types",
|
|
269
|
-
"@slidev/client",
|
|
270
|
-
"@slidev/client/constants",
|
|
271
|
-
"@slidev/client/logic/dark",
|
|
272
|
-
"@vueuse/core",
|
|
273
|
-
"@vueuse/shared",
|
|
274
|
-
"@unocss/reset",
|
|
275
|
-
"unocss",
|
|
276
|
-
"mermaid",
|
|
277
|
-
"vite-plugin-windicss",
|
|
278
|
-
"vue-demi",
|
|
279
|
-
"vue"
|
|
280
|
-
];
|
|
281
|
-
function createConfigPlugin(options) {
|
|
282
|
-
return {
|
|
283
|
-
name: "slidev:config",
|
|
284
|
-
async config(config) {
|
|
285
|
-
const injection = {
|
|
286
|
-
define: getDefine(options),
|
|
287
|
-
resolve: {
|
|
288
|
-
alias: {
|
|
289
|
-
"@slidev/client/": `${toAtFS(options.clientRoot)}/`
|
|
290
|
-
},
|
|
291
|
-
dedupe: ["vue"]
|
|
292
|
-
},
|
|
293
|
-
optimizeDeps: {
|
|
294
|
-
include: [
|
|
295
|
-
...Object.keys(dependencies).filter((i) => !EXCLUDE.includes(i)),
|
|
296
|
-
"codemirror/mode/javascript/javascript",
|
|
297
|
-
"codemirror/mode/css/css",
|
|
298
|
-
"codemirror/mode/markdown/markdown",
|
|
299
|
-
"codemirror/mode/xml/xml",
|
|
300
|
-
"codemirror/mode/htmlmixed/htmlmixed",
|
|
301
|
-
"codemirror/addon/display/placeholder",
|
|
302
|
-
"prettier/plugins/babel",
|
|
303
|
-
"prettier/plugins/html",
|
|
304
|
-
"prettier/plugins/typescript",
|
|
305
|
-
"mermaid/dist/mermaid.esm.min.mjs",
|
|
306
|
-
"mermaid/dist/mermaid.esm.mjs",
|
|
307
|
-
"vite-plugin-vue-server-ref/client"
|
|
308
|
-
],
|
|
309
|
-
exclude: EXCLUDE
|
|
310
|
-
},
|
|
311
|
-
css: options.data.config.css === "unocss" ? {
|
|
312
|
-
postcss: {
|
|
313
|
-
plugins: [
|
|
314
|
-
await import("postcss-nested").then((r) => (r.default || r)())
|
|
315
|
-
]
|
|
316
|
-
}
|
|
317
|
-
} : {},
|
|
318
|
-
server: {
|
|
319
|
-
fs: {
|
|
320
|
-
strict: true,
|
|
321
|
-
allow: uniq2([
|
|
322
|
-
searchForWorkspaceRoot(options.userRoot),
|
|
323
|
-
searchForWorkspaceRoot(options.cliRoot),
|
|
324
|
-
...isInstalledGlobally ? [dirname3(resolveGlobalImportPath("@slidev/client/package.json")), dirname3(resolveGlobalImportPath("katex/package.json"))] : []
|
|
325
|
-
])
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
publicDir: join4(options.userRoot, "public")
|
|
329
|
-
};
|
|
330
|
-
if (isInstalledGlobally) {
|
|
331
|
-
injection.cacheDir = join4(options.cliRoot, "node_modules/.vite");
|
|
332
|
-
injection.root = options.cliRoot;
|
|
333
|
-
injection.resolve.alias.vue = `${resolveImportPath("vue/dist/vue.esm-browser.js", true)}`;
|
|
334
|
-
}
|
|
335
|
-
return mergeConfig2(injection, config);
|
|
336
|
-
},
|
|
337
|
-
configureServer(server) {
|
|
338
|
-
return () => {
|
|
339
|
-
server.middlewares.use(async (req, res, next) => {
|
|
340
|
-
if (req.url.endsWith(".html")) {
|
|
341
|
-
res.setHeader("Content-Type", "text/html");
|
|
342
|
-
res.statusCode = 200;
|
|
343
|
-
res.end(await getIndexHtml(options));
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
next();
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function getDefine(options) {
|
|
353
|
-
return {
|
|
354
|
-
__DEV__: options.mode === "dev" ? "true" : "false",
|
|
355
|
-
__SLIDEV_CLIENT_ROOT__: JSON.stringify(toAtFS(options.clientRoot)),
|
|
356
|
-
__SLIDEV_HASH_ROUTE__: JSON.stringify(options.data.config.routerMode === "hash"),
|
|
357
|
-
__SLIDEV_FEATURE_DRAWINGS__: JSON.stringify(options.data.config.drawings.enabled === true || options.data.config.drawings.enabled === options.mode),
|
|
358
|
-
__SLIDEV_FEATURE_EDITOR__: JSON.stringify(options.mode === "dev" && options.data.config.editor !== false),
|
|
359
|
-
__SLIDEV_FEATURE_DRAWINGS_PERSIST__: JSON.stringify(!!options.data.config.drawings.persist === true),
|
|
360
|
-
__SLIDEV_FEATURE_RECORD__: JSON.stringify(options.data.config.record === true || options.data.config.record === options.mode),
|
|
361
|
-
__SLIDEV_FEATURE_PRESENTER__: JSON.stringify(options.data.config.presenter === true || options.data.config.presenter === options.mode),
|
|
362
|
-
__SLIDEV_HAS_SERVER__: options.mode !== "build" ? "true" : "false"
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// node/plugins/loaders.ts
|
|
367
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
|
368
|
-
import { basename as basename2, join as join5 } from "node:path";
|
|
369
|
-
import process from "node:process";
|
|
370
|
-
import { isString, notNullish, objectMap, range, slash, uniq as uniq3 } from "@antfu/utils";
|
|
371
|
-
import fg2 from "fast-glob";
|
|
372
|
-
import fs4, { existsSync as existsSync2 } from "fs-extra";
|
|
373
|
-
import Markdown from "markdown-it";
|
|
374
|
-
import { bold, gray, red, yellow } from "kolorist";
|
|
375
|
-
import mila from "markdown-it-link-attributes";
|
|
376
|
-
import * as parser from "@slidev/parser/fs";
|
|
377
|
-
var regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/;
|
|
378
|
-
var regexIdQuery = /(\d+?)\.(md|json)$/;
|
|
379
|
-
function getBodyJson(req) {
|
|
380
|
-
return new Promise((resolve3, reject) => {
|
|
381
|
-
let body = "";
|
|
382
|
-
req.on("data", (chunk) => body += chunk);
|
|
383
|
-
req.on("error", reject);
|
|
384
|
-
req.on("end", () => {
|
|
385
|
-
try {
|
|
386
|
-
resolve3(JSON.parse(body) || {});
|
|
387
|
-
} catch (e) {
|
|
388
|
-
reject(e);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
var md = Markdown({ html: true });
|
|
394
|
-
md.use(mila, {
|
|
395
|
-
attrs: {
|
|
396
|
-
target: "_blank",
|
|
397
|
-
rel: "noopener"
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
function prepareSlideInfo(data) {
|
|
401
|
-
return {
|
|
402
|
-
...data,
|
|
403
|
-
noteHTML: md.render(data?.note || "")
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, userRoot, roots, remote }, pluginOptions, serverOptions) {
|
|
407
|
-
const slidePrefix = "/@slidev/slides/";
|
|
408
|
-
const hmrPages = /* @__PURE__ */ new Set();
|
|
409
|
-
let server;
|
|
410
|
-
let _layouts_cache_time = 0;
|
|
411
|
-
let _layouts_cache = {};
|
|
412
|
-
return [
|
|
413
|
-
{
|
|
414
|
-
name: "slidev:loader",
|
|
415
|
-
configureServer(_server) {
|
|
416
|
-
server = _server;
|
|
417
|
-
updateServerWatcher();
|
|
418
|
-
server.middlewares.use(async (req, res, next) => {
|
|
419
|
-
const match = req.url?.match(regexId);
|
|
420
|
-
if (!match)
|
|
421
|
-
return next();
|
|
422
|
-
const [, no, type2] = match;
|
|
423
|
-
const idx = Number.parseInt(no);
|
|
424
|
-
if (type2 === "json" && req.method === "GET") {
|
|
425
|
-
res.write(JSON.stringify(prepareSlideInfo(data.slides[idx])));
|
|
426
|
-
return res.end();
|
|
427
|
-
}
|
|
428
|
-
if (type2 === "json" && req.method === "POST") {
|
|
429
|
-
const body = await getBodyJson(req);
|
|
430
|
-
const slide = data.slides[idx];
|
|
431
|
-
hmrPages.add(idx);
|
|
432
|
-
if (slide.source) {
|
|
433
|
-
Object.assign(slide.source, body);
|
|
434
|
-
await parser.saveExternalSlide(slide.source);
|
|
435
|
-
} else {
|
|
436
|
-
Object.assign(slide, body);
|
|
437
|
-
await parser.save(data, entry);
|
|
438
|
-
}
|
|
439
|
-
res.statusCode = 200;
|
|
440
|
-
res.write(JSON.stringify(prepareSlideInfo(slide)));
|
|
441
|
-
return res.end();
|
|
442
|
-
}
|
|
443
|
-
next();
|
|
444
|
-
});
|
|
445
|
-
},
|
|
446
|
-
async handleHotUpdate(ctx) {
|
|
447
|
-
if (!data.entries.some((i) => slash(i) === ctx.file))
|
|
448
|
-
return;
|
|
449
|
-
await ctx.read();
|
|
450
|
-
const newData = await parser.load(entry, data.themeMeta);
|
|
451
|
-
const moduleIds = /* @__PURE__ */ new Set();
|
|
452
|
-
if (data.slides.length !== newData.slides.length) {
|
|
453
|
-
moduleIds.add("/@slidev/routes");
|
|
454
|
-
range(newData.slides.length).map((i) => hmrPages.add(i));
|
|
455
|
-
}
|
|
456
|
-
if (!(0, import_fast_deep_equal.default)(data.headmatter.defaults, newData.headmatter.defaults)) {
|
|
457
|
-
moduleIds.add("/@slidev/routes");
|
|
458
|
-
range(data.slides.length).map((i) => hmrPages.add(i));
|
|
459
|
-
}
|
|
460
|
-
if (!(0, import_fast_deep_equal.default)(data.config, newData.config))
|
|
461
|
-
moduleIds.add("/@slidev/configs");
|
|
462
|
-
if (!(0, import_fast_deep_equal.default)(data.features, newData.features)) {
|
|
463
|
-
setTimeout(() => {
|
|
464
|
-
ctx.server.ws.send({ type: "full-reload" });
|
|
465
|
-
}, 1);
|
|
466
|
-
}
|
|
467
|
-
const length = Math.max(data.slides.length, newData.slides.length);
|
|
468
|
-
for (let i = 0; i < length; i++) {
|
|
469
|
-
const a = data.slides[i];
|
|
470
|
-
const b = newData.slides[i];
|
|
471
|
-
if (a?.content.trim() === b?.content.trim() && a?.title?.trim() === b?.title?.trim() && a?.note === b?.note && (0, import_fast_deep_equal.default)(a.frontmatter, b.frontmatter))
|
|
472
|
-
continue;
|
|
473
|
-
ctx.server.ws.send({
|
|
474
|
-
type: "custom",
|
|
475
|
-
event: "slidev-update",
|
|
476
|
-
data: {
|
|
477
|
-
id: i,
|
|
478
|
-
data: prepareSlideInfo(newData.slides[i])
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
hmrPages.add(i);
|
|
482
|
-
}
|
|
483
|
-
serverOptions.onDataReload?.(newData, data);
|
|
484
|
-
Object.assign(data, newData);
|
|
485
|
-
if (hmrPages.size > 0)
|
|
486
|
-
moduleIds.add("/@slidev/titles.md");
|
|
487
|
-
const vueModules = Array.from(hmrPages).map(
|
|
488
|
-
(i) => ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.md`)
|
|
489
|
-
);
|
|
490
|
-
hmrPages.clear();
|
|
491
|
-
const moduleEntries = [
|
|
492
|
-
...vueModules,
|
|
493
|
-
...Array.from(moduleIds).map((id) => ctx.server.moduleGraph.getModuleById(id))
|
|
494
|
-
].filter(notNullish).filter((i) => !i.id?.startsWith("/@id/@vite-icons"));
|
|
495
|
-
updateServerWatcher();
|
|
496
|
-
return moduleEntries;
|
|
497
|
-
},
|
|
498
|
-
resolveId(id) {
|
|
499
|
-
if (id.startsWith(slidePrefix) || id.startsWith("/@slidev/"))
|
|
500
|
-
return id;
|
|
501
|
-
return null;
|
|
502
|
-
},
|
|
503
|
-
load(id) {
|
|
504
|
-
if (id === "/@slidev/routes")
|
|
505
|
-
return generateRoutes();
|
|
506
|
-
if (id === "/@slidev/layouts")
|
|
507
|
-
return generateLayouts();
|
|
508
|
-
if (id === "/@slidev/styles")
|
|
509
|
-
return generateUserStyles();
|
|
510
|
-
if (id === "/@slidev/monaco-types")
|
|
511
|
-
return generateMonacoTypes();
|
|
512
|
-
if (id === "/@slidev/configs")
|
|
513
|
-
return generateConfigs();
|
|
514
|
-
if (id === "/@slidev/global-components/top")
|
|
515
|
-
return generateGlobalComponents("top");
|
|
516
|
-
if (id === "/@slidev/global-components/bottom")
|
|
517
|
-
return generateGlobalComponents("bottom");
|
|
518
|
-
if (id === "/@slidev/custom-nav-controls")
|
|
519
|
-
return generateCustomNavControls();
|
|
520
|
-
if (id === "/@slidev/titles.md") {
|
|
521
|
-
return {
|
|
522
|
-
code: data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map(({ title }, i) => {
|
|
523
|
-
return `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
|
|
524
|
-
|
|
525
|
-
${title}
|
|
526
|
-
|
|
527
|
-
</template>`;
|
|
528
|
-
}).join(""),
|
|
529
|
-
map: { mappings: "" }
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
if (id.startsWith(slidePrefix)) {
|
|
533
|
-
const remaning = id.slice(slidePrefix.length);
|
|
534
|
-
const match = remaning.match(regexIdQuery);
|
|
535
|
-
if (match) {
|
|
536
|
-
const [, no, type2] = match;
|
|
537
|
-
const pageNo = Number.parseInt(no) - 1;
|
|
538
|
-
if (type2 === "md") {
|
|
539
|
-
return {
|
|
540
|
-
code: data.slides[pageNo]?.content,
|
|
541
|
-
map: { mappings: "" }
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
return {
|
|
546
|
-
code: "",
|
|
547
|
-
map: { mappings: "" }
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
name: "slidev:layout-transform:pre",
|
|
554
|
-
enforce: "pre",
|
|
555
|
-
async transform(code, id) {
|
|
556
|
-
if (!id.startsWith(slidePrefix))
|
|
557
|
-
return;
|
|
558
|
-
const remaning = id.slice(slidePrefix.length);
|
|
559
|
-
const match = remaning.match(regexIdQuery);
|
|
560
|
-
if (!match)
|
|
561
|
-
return;
|
|
562
|
-
const [, no, type2] = match;
|
|
563
|
-
if (type2 !== "md")
|
|
564
|
-
return;
|
|
565
|
-
const pageNo = Number.parseInt(no) - 1;
|
|
566
|
-
return transformMarkdown(code, pageNo, data);
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
name: "slidev:context-transform:pre",
|
|
571
|
-
enforce: "pre",
|
|
572
|
-
async transform(code, id) {
|
|
573
|
-
if (!id.endsWith(".vue") || id.includes("/@slidev/client/") || id.includes("/packages/client/"))
|
|
574
|
-
return;
|
|
575
|
-
return transformVue(code);
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
{
|
|
579
|
-
name: "slidev:title-transform:pre",
|
|
580
|
-
enforce: "pre",
|
|
581
|
-
transform(code, id) {
|
|
582
|
-
if (id !== "/@slidev/titles.md")
|
|
583
|
-
return;
|
|
584
|
-
return transformTitles(code);
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
name: "slidev:slide-transform:post",
|
|
589
|
-
enforce: "post",
|
|
590
|
-
transform(code, id) {
|
|
591
|
-
if (!id.match(/\/@slidev\/slides\/\d+\.md($|\?)/))
|
|
592
|
-
return;
|
|
593
|
-
return code.replace("if (_rerender_only)", "if (false)");
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
];
|
|
597
|
-
function updateServerWatcher() {
|
|
598
|
-
if (!server)
|
|
599
|
-
return;
|
|
600
|
-
server.watcher.add(data.entries?.map(slash) || []);
|
|
601
|
-
}
|
|
602
|
-
async function transformMarkdown(code, pageNo, data2) {
|
|
603
|
-
const layouts = await getLayouts();
|
|
604
|
-
const frontmatter = {
|
|
605
|
-
...data2.headmatter?.defaults || {},
|
|
606
|
-
...data2.slides[pageNo]?.frontmatter || {}
|
|
607
|
-
};
|
|
608
|
-
let layoutName = frontmatter?.layout || (pageNo === 0 ? "cover" : "default");
|
|
609
|
-
if (!layouts[layoutName]) {
|
|
610
|
-
console.error(red(`
|
|
611
|
-
Unknown layout "${bold(layoutName)}".${yellow(" Available layouts are:")}`) + Object.keys(layouts).map((i, idx) => (idx % 3 === 0 ? "\n " : "") + gray(i.padEnd(15, " "))).join(" "));
|
|
612
|
-
console.error();
|
|
613
|
-
layoutName = "default";
|
|
614
|
-
}
|
|
615
|
-
delete frontmatter.title;
|
|
616
|
-
const imports = [
|
|
617
|
-
'import { inject as _vueInject, toRef as _vueToRef } from "vue"',
|
|
618
|
-
`import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
|
|
619
|
-
'import { injectionSlidevContext as _injectionSlidevContext, injectionClicks as _injectionClicks } from "@slidev/client/constants.ts"',
|
|
620
|
-
`const frontmatter = ${JSON.stringify(frontmatter)}`,
|
|
621
|
-
"const $frontmatter = frontmatter",
|
|
622
|
-
"const $slidev = _vueInject(_injectionSlidevContext)",
|
|
623
|
-
'const $nav = _vueToRef($slidev, "nav")',
|
|
624
|
-
"const $clicks = _vueInject(_injectionClicks)"
|
|
625
|
-
];
|
|
626
|
-
code = code.replace(/(<script setup.*>)/g, `$1
|
|
627
|
-
${imports.join("\n")}
|
|
628
|
-
`);
|
|
629
|
-
const injectA = code.indexOf("<template>") + "<template>".length;
|
|
630
|
-
const injectB = code.lastIndexOf("</template>");
|
|
631
|
-
let body = code.slice(injectA, injectB).trim();
|
|
632
|
-
if (body.startsWith("<div>") && body.endsWith("</div>"))
|
|
633
|
-
body = body.slice(5, -6);
|
|
634
|
-
code = `${code.slice(0, injectA)}
|
|
635
|
-
<InjectedLayout v-bind="frontmatter">
|
|
636
|
-
${body}
|
|
637
|
-
</InjectedLayout>
|
|
638
|
-
${code.slice(injectB)}`;
|
|
639
|
-
return code;
|
|
640
|
-
}
|
|
641
|
-
function transformVue(code) {
|
|
642
|
-
if (code.includes("injectionSlidevContext") || code.includes("injectionClicks") || code.includes("const $slidev"))
|
|
643
|
-
return code;
|
|
644
|
-
const imports = [
|
|
645
|
-
'import { inject as _vueInject, toRef as _vueToRef } from "vue"',
|
|
646
|
-
'import { injectionSlidevContext as _injectionSlidevContext, injectionClicks as _injectionClicks } from "@slidev/client/constants.ts"',
|
|
647
|
-
"const $slidev = _vueInject(_injectionSlidevContext)",
|
|
648
|
-
'const $nav = _vueToRef($slidev, "nav")',
|
|
649
|
-
"const $clicks = _vueInject(_injectionClicks)"
|
|
650
|
-
];
|
|
651
|
-
const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
|
|
652
|
-
if (matchScript && matchScript[2]) {
|
|
653
|
-
return code.replace(/(<script.*>)/g, `$1
|
|
654
|
-
${imports.join("\n")}
|
|
655
|
-
`);
|
|
656
|
-
} else if (matchScript && !matchScript[2]) {
|
|
657
|
-
const matchExport = code.match(/export\s+default\s+{/);
|
|
658
|
-
if (matchExport) {
|
|
659
|
-
const exportIndex = (matchExport.index || 0) + matchExport[0].length;
|
|
660
|
-
let component = code.slice(exportIndex);
|
|
661
|
-
component = component.slice(0, component.indexOf("</script>"));
|
|
662
|
-
const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
|
|
663
|
-
const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants.ts"\n';
|
|
664
|
-
code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
|
|
665
|
-
let injectIndex = exportIndex + provideImport.length;
|
|
666
|
-
let injectObject = "$slidev: { from: injectionSlidevContext },";
|
|
667
|
-
const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
|
|
668
|
-
if (matchInject) {
|
|
669
|
-
injectIndex += (matchInject.index || 0) + matchInject[0].length;
|
|
670
|
-
if (matchInject[1] === "[") {
|
|
671
|
-
let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
|
|
672
|
-
const injectEndIndex = injects.indexOf("]");
|
|
673
|
-
injects = injects.slice(0, injectEndIndex);
|
|
674
|
-
injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
|
|
675
|
-
return `${code.slice(0, injectIndex - 1)}{
|
|
676
|
-
${injectObject}
|
|
677
|
-
}${code.slice(injectIndex + injectEndIndex + 1)}`;
|
|
678
|
-
} else {
|
|
679
|
-
return `${code.slice(0, injectIndex)}
|
|
680
|
-
${injectObject}
|
|
681
|
-
${code.slice(injectIndex)}`;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return `${code.slice(0, injectIndex)}
|
|
685
|
-
inject: { ${injectObject} },
|
|
686
|
-
${code.slice(injectIndex)}`;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return `<script setup>
|
|
690
|
-
${imports.join("\n")}
|
|
691
|
-
</script>
|
|
692
|
-
${code}`;
|
|
693
|
-
}
|
|
694
|
-
function transformTitles(code) {
|
|
695
|
-
return code.replace(/<template>\s*<div>\s*<p>/, "<template>").replace(/<\/p>\s*<\/div>\s*<\/template>/, "</template>").replace(/<script\ssetup>/, `<script setup lang="ts">
|
|
696
|
-
defineProps<{ no: number | string }>()`);
|
|
697
|
-
}
|
|
698
|
-
async function getLayouts() {
|
|
699
|
-
const now = Date.now();
|
|
700
|
-
if (now - _layouts_cache_time < 2e3)
|
|
701
|
-
return _layouts_cache;
|
|
702
|
-
const layouts = {};
|
|
703
|
-
const roots2 = uniq3([
|
|
704
|
-
userRoot,
|
|
705
|
-
...themeRoots,
|
|
706
|
-
...addonRoots,
|
|
707
|
-
clientRoot
|
|
708
|
-
]);
|
|
709
|
-
for (const root of roots2) {
|
|
710
|
-
const layoutPaths = await fg2("layouts/**/*.{vue,ts}", {
|
|
711
|
-
cwd: root,
|
|
712
|
-
absolute: true,
|
|
713
|
-
suppressErrors: true
|
|
714
|
-
});
|
|
715
|
-
for (const layoutPath of layoutPaths) {
|
|
716
|
-
const layout = basename2(layoutPath).replace(/\.\w+$/, "");
|
|
717
|
-
if (layouts[layout])
|
|
718
|
-
continue;
|
|
719
|
-
layouts[layout] = layoutPath;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
_layouts_cache_time = now;
|
|
723
|
-
_layouts_cache = layouts;
|
|
724
|
-
return layouts;
|
|
725
|
-
}
|
|
726
|
-
async function generateUserStyles() {
|
|
727
|
-
const imports = [
|
|
728
|
-
`import "${toAtFS(join5(clientRoot, "styles/vars.css"))}"`,
|
|
729
|
-
`import "${toAtFS(join5(clientRoot, "styles/index.css"))}"`,
|
|
730
|
-
`import "${toAtFS(join5(clientRoot, "styles/code.css"))}"`,
|
|
731
|
-
`import "${toAtFS(join5(clientRoot, "styles/transitions.css"))}"`
|
|
732
|
-
];
|
|
733
|
-
const roots2 = uniq3([
|
|
734
|
-
...themeRoots,
|
|
735
|
-
...addonRoots,
|
|
736
|
-
userRoot
|
|
737
|
-
]);
|
|
738
|
-
for (const root of roots2) {
|
|
739
|
-
const styles = [
|
|
740
|
-
join5(root, "styles", "index.ts"),
|
|
741
|
-
join5(root, "styles", "index.js"),
|
|
742
|
-
join5(root, "styles", "index.css"),
|
|
743
|
-
join5(root, "styles.css"),
|
|
744
|
-
join5(root, "style.css")
|
|
745
|
-
];
|
|
746
|
-
for (const style of styles) {
|
|
747
|
-
if (existsSync2(style)) {
|
|
748
|
-
imports.push(`import "${toAtFS(style)}"`);
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
if (data.features.katex)
|
|
754
|
-
imports.push(`import "${toAtFS(resolveImportPath("katex/dist/katex.min.css", true))}"`);
|
|
755
|
-
if (data.config.css === "unocss") {
|
|
756
|
-
imports.unshift(
|
|
757
|
-
'import "@unocss/reset/tailwind.css"',
|
|
758
|
-
'import "uno:preflights.css"',
|
|
759
|
-
'import "uno:typography.css"',
|
|
760
|
-
'import "uno:shortcuts.css"'
|
|
761
|
-
);
|
|
762
|
-
imports.push('import "uno.css"');
|
|
763
|
-
} else {
|
|
764
|
-
imports.unshift(
|
|
765
|
-
'import "virtual:windi-components.css"',
|
|
766
|
-
'import "virtual:windi-base.css"'
|
|
767
|
-
);
|
|
768
|
-
imports.push('import "virtual:windi-utilities.css"');
|
|
769
|
-
if (process.env.NODE_ENV !== "production")
|
|
770
|
-
imports.push('import "virtual:windi-devtools"');
|
|
771
|
-
}
|
|
772
|
-
return imports.join("\n");
|
|
773
|
-
}
|
|
774
|
-
async function generateMonacoTypes() {
|
|
775
|
-
return `void 0; ${parser.scanMonacoModules(data.raw).map((i) => `import('/@slidev-monaco-types/${i}')`).join("\n")}`;
|
|
776
|
-
}
|
|
777
|
-
async function generateLayouts() {
|
|
778
|
-
const imports = [];
|
|
779
|
-
const layouts = objectMap(
|
|
780
|
-
await getLayouts(),
|
|
781
|
-
(k, v) => {
|
|
782
|
-
imports.push(`import __layout_${k} from "${toAtFS(v)}"`);
|
|
783
|
-
return [k, `__layout_${k}`];
|
|
784
|
-
}
|
|
785
|
-
);
|
|
786
|
-
return [
|
|
787
|
-
imports.join("\n"),
|
|
788
|
-
`export default {
|
|
789
|
-
${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
|
|
790
|
-
}`
|
|
791
|
-
].join("\n\n");
|
|
792
|
-
}
|
|
793
|
-
async function generateRoutes() {
|
|
794
|
-
const imports = [];
|
|
795
|
-
const redirects = [];
|
|
796
|
-
const layouts = await getLayouts();
|
|
797
|
-
imports.push(`import __layout__end from '${layouts.end}'`);
|
|
798
|
-
let no = 1;
|
|
799
|
-
const routes = data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map((i, idx) => {
|
|
800
|
-
imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
|
|
801
|
-
const additions = {
|
|
802
|
-
slide: {
|
|
803
|
-
...prepareSlideInfo(i),
|
|
804
|
-
filepath: i.source?.filepath || entry,
|
|
805
|
-
id: idx,
|
|
806
|
-
no
|
|
807
|
-
},
|
|
808
|
-
__clicksElements: [],
|
|
809
|
-
__preloaded: false
|
|
810
|
-
};
|
|
811
|
-
const meta = Object.assign({}, i.frontmatter, additions);
|
|
812
|
-
const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
|
|
813
|
-
if (i.frontmatter?.routeAlias)
|
|
814
|
-
redirects.push(`{ path: '${i.frontmatter?.routeAlias}', redirect: { path: '${no}' } }`);
|
|
815
|
-
no += 1;
|
|
816
|
-
return route;
|
|
817
|
-
});
|
|
818
|
-
const routesStr = `export default [
|
|
819
|
-
${routes.join(",\n")}
|
|
820
|
-
]`;
|
|
821
|
-
const redirectsStr = `export const redirects = [
|
|
822
|
-
${redirects.join(",\n")}
|
|
823
|
-
]`;
|
|
824
|
-
return [...imports, routesStr, redirectsStr].join("\n");
|
|
825
|
-
}
|
|
826
|
-
function generateConfigs() {
|
|
827
|
-
const config = { ...data.config, remote };
|
|
828
|
-
if (isString(config.title)) {
|
|
829
|
-
const tokens = md.parseInline(config.title, {});
|
|
830
|
-
config.title = stringifyMarkdownTokens(tokens);
|
|
831
|
-
}
|
|
832
|
-
if (isString(config.info))
|
|
833
|
-
config.info = md.render(config.info);
|
|
834
|
-
return `export default ${JSON.stringify(config)}`;
|
|
835
|
-
}
|
|
836
|
-
async function generateGlobalComponents(layer) {
|
|
837
|
-
const components = roots.flatMap((root) => {
|
|
838
|
-
if (layer === "top") {
|
|
839
|
-
return [
|
|
840
|
-
join5(root, "global.vue"),
|
|
841
|
-
join5(root, "global-top.vue"),
|
|
842
|
-
join5(root, "GlobalTop.vue")
|
|
843
|
-
];
|
|
844
|
-
} else {
|
|
845
|
-
return [
|
|
846
|
-
join5(root, "global-bottom.vue"),
|
|
847
|
-
join5(root, "GlobalBottom.vue")
|
|
848
|
-
];
|
|
849
|
-
}
|
|
850
|
-
}).filter((i) => fs4.existsSync(i));
|
|
851
|
-
const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
|
|
852
|
-
const render = components.map((i, idx) => `h(__n${idx})`).join(",");
|
|
853
|
-
return `
|
|
854
|
-
${imports}
|
|
855
|
-
import { h } from 'vue'
|
|
856
|
-
export default {
|
|
857
|
-
render() {
|
|
858
|
-
return [${render}]
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
`;
|
|
862
|
-
}
|
|
863
|
-
async function generateCustomNavControls() {
|
|
864
|
-
const components = roots.flatMap((root) => {
|
|
865
|
-
return [
|
|
866
|
-
join5(root, "custom-nav-controls.vue"),
|
|
867
|
-
join5(root, "CustomNavControls.vue")
|
|
868
|
-
];
|
|
869
|
-
}).filter((i) => fs4.existsSync(i));
|
|
870
|
-
const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
|
|
871
|
-
const render = components.map((i, idx) => `h(__n${idx})`).join(",");
|
|
872
|
-
return `
|
|
873
|
-
${imports}
|
|
874
|
-
import { h } from 'vue'
|
|
875
|
-
export default {
|
|
876
|
-
render() {
|
|
877
|
-
return [${render}]
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
`;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// node/plugins/monacoTransform.ts
|
|
885
|
-
import { join as join6 } from "node:path";
|
|
886
|
-
import process2 from "node:process";
|
|
887
|
-
import { slash as slash2 } from "@antfu/utils";
|
|
888
|
-
async function getPackageData(pkg) {
|
|
889
|
-
const { resolvePackageData } = await eval('import("vite")');
|
|
890
|
-
const info = resolvePackageData(pkg, process2.cwd());
|
|
891
|
-
if (!info)
|
|
892
|
-
return;
|
|
893
|
-
const typePath = info.data.types || info.data.typings;
|
|
894
|
-
if (!typePath)
|
|
895
|
-
return;
|
|
896
|
-
return [info, typePath];
|
|
897
|
-
}
|
|
898
|
-
function createMonacoTypesLoader() {
|
|
899
|
-
return {
|
|
900
|
-
name: "slidev:monaco-types-loader",
|
|
901
|
-
resolveId(id) {
|
|
902
|
-
if (id.startsWith("/@slidev-monaco-types/"))
|
|
903
|
-
return id;
|
|
904
|
-
return null;
|
|
905
|
-
},
|
|
906
|
-
async load(id) {
|
|
907
|
-
const match = id.match(/^\/\@slidev-monaco-types\/(.*)$/);
|
|
908
|
-
if (match) {
|
|
909
|
-
const pkg2 = match[1];
|
|
910
|
-
const packageData = await getPackageData(pkg2) || await getPackageData(`@types/${pkg2}`);
|
|
911
|
-
if (!packageData)
|
|
912
|
-
return;
|
|
913
|
-
const [info2, typePath2] = packageData;
|
|
914
|
-
return [
|
|
915
|
-
"import * as monaco from 'monaco-editor'",
|
|
916
|
-
`import Type from "${slash2(join6(info2.dir, typePath2))}?raw"`,
|
|
917
|
-
...Object.keys(info2.data.dependencies || {}).map((i) => `import "/@slidev-monaco-types/${i}"`),
|
|
918
|
-
`monaco.languages.typescript.typescriptDefaults.addExtraLib(\`declare module "${pkg2}" { \${Type} }\`)`
|
|
919
|
-
].join("\n");
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
// node/plugins/setupClient.ts
|
|
926
|
-
import { existsSync as existsSync3 } from "node:fs";
|
|
927
|
-
import { join as join7, resolve as resolve2 } from "node:path";
|
|
928
|
-
import { slash as slash3, uniq as uniq4 } from "@antfu/utils";
|
|
929
|
-
function createClientSetupPlugin({ clientRoot, themeRoots, addonRoots, userRoot }) {
|
|
930
|
-
const setupEntry = slash3(resolve2(clientRoot, "setup"));
|
|
931
|
-
return {
|
|
932
|
-
name: "slidev:setup",
|
|
933
|
-
enforce: "pre",
|
|
934
|
-
async transform(code, id) {
|
|
935
|
-
if (id.startsWith(setupEntry)) {
|
|
936
|
-
let getInjections2 = function(isAwait = false, isChained = false) {
|
|
937
|
-
return injections.join("\n").replace(/:AWAIT:/g, isAwait ? "await " : "").replace(/(,\s*)?:LAST:/g, isChained ? "$1injection_return" : "");
|
|
938
|
-
};
|
|
939
|
-
var getInjections = getInjections2;
|
|
940
|
-
const name = id.slice(setupEntry.length + 1).replace(/\?.*$/, "");
|
|
941
|
-
const imports = [];
|
|
942
|
-
const injections = [];
|
|
943
|
-
const setups = uniq4([
|
|
944
|
-
...themeRoots,
|
|
945
|
-
...addonRoots,
|
|
946
|
-
userRoot
|
|
947
|
-
]).map((i) => join7(i, "setup", name));
|
|
948
|
-
setups.forEach((path, idx) => {
|
|
949
|
-
if (!existsSync3(path))
|
|
950
|
-
return;
|
|
951
|
-
imports.push(`import __n${idx} from '${toAtFS(path)}'`);
|
|
952
|
-
let fn = `:AWAIT:__n${idx}`;
|
|
953
|
-
if (/\binjection_return\b/g.test(code))
|
|
954
|
-
fn = `injection_return = ${fn}`;
|
|
955
|
-
if (/\binjection_arg\b/g.test(code)) {
|
|
956
|
-
fn += "(";
|
|
957
|
-
const matches = Array.from(code.matchAll(/\binjection_arg(_\d+)?\b/g));
|
|
958
|
-
const dedupedMatches = Array.from(new Set(matches.map((m) => m[0])));
|
|
959
|
-
fn += dedupedMatches.join(", ");
|
|
960
|
-
fn += ", :LAST:)";
|
|
961
|
-
} else {
|
|
962
|
-
fn += "(:LAST:)";
|
|
963
|
-
}
|
|
964
|
-
injections.push(
|
|
965
|
-
`// ${path}`,
|
|
966
|
-
fn
|
|
967
|
-
);
|
|
968
|
-
});
|
|
969
|
-
code = code.replace("/* __imports__ */", imports.join("\n"));
|
|
970
|
-
code = code.replace("/* __injections__ */", getInjections2());
|
|
971
|
-
code = code.replace("/* __async_injections__ */", getInjections2(true));
|
|
972
|
-
code = code.replace("/* __chained_injections__ */", getInjections2(false, true));
|
|
973
|
-
code = code.replace("/* __chained_async_injections__ */", getInjections2(true, true));
|
|
974
|
-
return code;
|
|
975
|
-
}
|
|
976
|
-
return null;
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
// node/plugins/markdown.ts
|
|
982
|
-
import Markdown2 from "unplugin-vue-markdown/vite";
|
|
983
|
-
import * as base64 from "js-base64";
|
|
984
|
-
import { slash as slash4 } from "@antfu/utils";
|
|
985
|
-
import mila2 from "markdown-it-link-attributes";
|
|
986
|
-
import mif from "markdown-it-footnote";
|
|
987
|
-
import { taskLists } from "@hedgedoc/markdown-it-plugins";
|
|
988
|
-
import { encode as encode2 } from "plantuml-encoder";
|
|
989
|
-
|
|
990
|
-
// ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/dist/js-yaml.mjs
|
|
991
|
-
function isNothing(subject) {
|
|
992
|
-
return typeof subject === "undefined" || subject === null;
|
|
993
|
-
}
|
|
994
|
-
function isObject(subject) {
|
|
995
|
-
return typeof subject === "object" && subject !== null;
|
|
996
|
-
}
|
|
997
|
-
function toArray(sequence) {
|
|
998
|
-
if (Array.isArray(sequence))
|
|
999
|
-
return sequence;
|
|
1000
|
-
else if (isNothing(sequence))
|
|
1001
|
-
return [];
|
|
1002
|
-
return [sequence];
|
|
1003
|
-
}
|
|
1004
|
-
function extend(target, source) {
|
|
1005
|
-
var index, length, key, sourceKeys;
|
|
1006
|
-
if (source) {
|
|
1007
|
-
sourceKeys = Object.keys(source);
|
|
1008
|
-
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
|
1009
|
-
key = sourceKeys[index];
|
|
1010
|
-
target[key] = source[key];
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
return target;
|
|
1014
|
-
}
|
|
1015
|
-
function repeat(string, count) {
|
|
1016
|
-
var result = "", cycle;
|
|
1017
|
-
for (cycle = 0; cycle < count; cycle += 1) {
|
|
1018
|
-
result += string;
|
|
1019
|
-
}
|
|
1020
|
-
return result;
|
|
1021
|
-
}
|
|
1022
|
-
function isNegativeZero(number) {
|
|
1023
|
-
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
1024
|
-
}
|
|
1025
|
-
var isNothing_1 = isNothing;
|
|
1026
|
-
var isObject_1 = isObject;
|
|
1027
|
-
var toArray_1 = toArray;
|
|
1028
|
-
var repeat_1 = repeat;
|
|
1029
|
-
var isNegativeZero_1 = isNegativeZero;
|
|
1030
|
-
var extend_1 = extend;
|
|
1031
|
-
var common = {
|
|
1032
|
-
isNothing: isNothing_1,
|
|
1033
|
-
isObject: isObject_1,
|
|
1034
|
-
toArray: toArray_1,
|
|
1035
|
-
repeat: repeat_1,
|
|
1036
|
-
isNegativeZero: isNegativeZero_1,
|
|
1037
|
-
extend: extend_1
|
|
1038
|
-
};
|
|
1039
|
-
function formatError(exception2, compact) {
|
|
1040
|
-
var where = "", message = exception2.reason || "(unknown reason)";
|
|
1041
|
-
if (!exception2.mark)
|
|
1042
|
-
return message;
|
|
1043
|
-
if (exception2.mark.name) {
|
|
1044
|
-
where += 'in "' + exception2.mark.name + '" ';
|
|
1045
|
-
}
|
|
1046
|
-
where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
|
|
1047
|
-
if (!compact && exception2.mark.snippet) {
|
|
1048
|
-
where += "\n\n" + exception2.mark.snippet;
|
|
1049
|
-
}
|
|
1050
|
-
return message + " " + where;
|
|
1051
|
-
}
|
|
1052
|
-
function YAMLException$1(reason, mark) {
|
|
1053
|
-
Error.call(this);
|
|
1054
|
-
this.name = "YAMLException";
|
|
1055
|
-
this.reason = reason;
|
|
1056
|
-
this.mark = mark;
|
|
1057
|
-
this.message = formatError(this, false);
|
|
1058
|
-
if (Error.captureStackTrace) {
|
|
1059
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1060
|
-
} else {
|
|
1061
|
-
this.stack = new Error().stack || "";
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
1065
|
-
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
1066
|
-
YAMLException$1.prototype.toString = function toString(compact) {
|
|
1067
|
-
return this.name + ": " + formatError(this, compact);
|
|
1068
|
-
};
|
|
1069
|
-
var exception = YAMLException$1;
|
|
1070
|
-
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
1071
|
-
var head = "";
|
|
1072
|
-
var tail = "";
|
|
1073
|
-
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
1074
|
-
if (position - lineStart > maxHalfLength) {
|
|
1075
|
-
head = " ... ";
|
|
1076
|
-
lineStart = position - maxHalfLength + head.length;
|
|
1077
|
-
}
|
|
1078
|
-
if (lineEnd - position > maxHalfLength) {
|
|
1079
|
-
tail = " ...";
|
|
1080
|
-
lineEnd = position + maxHalfLength - tail.length;
|
|
1081
|
-
}
|
|
1082
|
-
return {
|
|
1083
|
-
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
|
|
1084
|
-
pos: position - lineStart + head.length
|
|
1085
|
-
// relative position
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
function padStart(string, max) {
|
|
1089
|
-
return common.repeat(" ", max - string.length) + string;
|
|
1090
|
-
}
|
|
1091
|
-
function makeSnippet(mark, options) {
|
|
1092
|
-
options = Object.create(options || null);
|
|
1093
|
-
if (!mark.buffer)
|
|
1094
|
-
return null;
|
|
1095
|
-
if (!options.maxLength)
|
|
1096
|
-
options.maxLength = 79;
|
|
1097
|
-
if (typeof options.indent !== "number")
|
|
1098
|
-
options.indent = 1;
|
|
1099
|
-
if (typeof options.linesBefore !== "number")
|
|
1100
|
-
options.linesBefore = 3;
|
|
1101
|
-
if (typeof options.linesAfter !== "number")
|
|
1102
|
-
options.linesAfter = 2;
|
|
1103
|
-
var re = /\r?\n|\r|\0/g;
|
|
1104
|
-
var lineStarts = [0];
|
|
1105
|
-
var lineEnds = [];
|
|
1106
|
-
var match;
|
|
1107
|
-
var foundLineNo = -1;
|
|
1108
|
-
while (match = re.exec(mark.buffer)) {
|
|
1109
|
-
lineEnds.push(match.index);
|
|
1110
|
-
lineStarts.push(match.index + match[0].length);
|
|
1111
|
-
if (mark.position <= match.index && foundLineNo < 0) {
|
|
1112
|
-
foundLineNo = lineStarts.length - 2;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
if (foundLineNo < 0)
|
|
1116
|
-
foundLineNo = lineStarts.length - 1;
|
|
1117
|
-
var result = "", i, line;
|
|
1118
|
-
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
1119
|
-
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
1120
|
-
for (i = 1; i <= options.linesBefore; i++) {
|
|
1121
|
-
if (foundLineNo - i < 0)
|
|
1122
|
-
break;
|
|
1123
|
-
line = getLine(
|
|
1124
|
-
mark.buffer,
|
|
1125
|
-
lineStarts[foundLineNo - i],
|
|
1126
|
-
lineEnds[foundLineNo - i],
|
|
1127
|
-
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
|
|
1128
|
-
maxLineLength
|
|
1129
|
-
);
|
|
1130
|
-
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
1131
|
-
}
|
|
1132
|
-
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
1133
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
1134
|
-
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
|
|
1135
|
-
for (i = 1; i <= options.linesAfter; i++) {
|
|
1136
|
-
if (foundLineNo + i >= lineEnds.length)
|
|
1137
|
-
break;
|
|
1138
|
-
line = getLine(
|
|
1139
|
-
mark.buffer,
|
|
1140
|
-
lineStarts[foundLineNo + i],
|
|
1141
|
-
lineEnds[foundLineNo + i],
|
|
1142
|
-
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
|
|
1143
|
-
maxLineLength
|
|
1144
|
-
);
|
|
1145
|
-
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
1146
|
-
}
|
|
1147
|
-
return result.replace(/\n$/, "");
|
|
1148
|
-
}
|
|
1149
|
-
var snippet = makeSnippet;
|
|
1150
|
-
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
1151
|
-
"kind",
|
|
1152
|
-
"multi",
|
|
1153
|
-
"resolve",
|
|
1154
|
-
"construct",
|
|
1155
|
-
"instanceOf",
|
|
1156
|
-
"predicate",
|
|
1157
|
-
"represent",
|
|
1158
|
-
"representName",
|
|
1159
|
-
"defaultStyle",
|
|
1160
|
-
"styleAliases"
|
|
1161
|
-
];
|
|
1162
|
-
var YAML_NODE_KINDS = [
|
|
1163
|
-
"scalar",
|
|
1164
|
-
"sequence",
|
|
1165
|
-
"mapping"
|
|
1166
|
-
];
|
|
1167
|
-
function compileStyleAliases(map2) {
|
|
1168
|
-
var result = {};
|
|
1169
|
-
if (map2 !== null) {
|
|
1170
|
-
Object.keys(map2).forEach(function(style) {
|
|
1171
|
-
map2[style].forEach(function(alias) {
|
|
1172
|
-
result[String(alias)] = style;
|
|
1173
|
-
});
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
|
-
return result;
|
|
1177
|
-
}
|
|
1178
|
-
function Type$1(tag, options) {
|
|
1179
|
-
options = options || {};
|
|
1180
|
-
Object.keys(options).forEach(function(name) {
|
|
1181
|
-
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
1182
|
-
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
1183
|
-
}
|
|
1184
|
-
});
|
|
1185
|
-
this.options = options;
|
|
1186
|
-
this.tag = tag;
|
|
1187
|
-
this.kind = options["kind"] || null;
|
|
1188
|
-
this.resolve = options["resolve"] || function() {
|
|
1189
|
-
return true;
|
|
1190
|
-
};
|
|
1191
|
-
this.construct = options["construct"] || function(data) {
|
|
1192
|
-
return data;
|
|
1193
|
-
};
|
|
1194
|
-
this.instanceOf = options["instanceOf"] || null;
|
|
1195
|
-
this.predicate = options["predicate"] || null;
|
|
1196
|
-
this.represent = options["represent"] || null;
|
|
1197
|
-
this.representName = options["representName"] || null;
|
|
1198
|
-
this.defaultStyle = options["defaultStyle"] || null;
|
|
1199
|
-
this.multi = options["multi"] || false;
|
|
1200
|
-
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
1201
|
-
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
1202
|
-
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
var type = Type$1;
|
|
1206
|
-
function compileList(schema2, name) {
|
|
1207
|
-
var result = [];
|
|
1208
|
-
schema2[name].forEach(function(currentType) {
|
|
1209
|
-
var newIndex = result.length;
|
|
1210
|
-
result.forEach(function(previousType, previousIndex) {
|
|
1211
|
-
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
1212
|
-
newIndex = previousIndex;
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
result[newIndex] = currentType;
|
|
1216
|
-
});
|
|
1217
|
-
return result;
|
|
1218
|
-
}
|
|
1219
|
-
function compileMap() {
|
|
1220
|
-
var result = {
|
|
1221
|
-
scalar: {},
|
|
1222
|
-
sequence: {},
|
|
1223
|
-
mapping: {},
|
|
1224
|
-
fallback: {},
|
|
1225
|
-
multi: {
|
|
1226
|
-
scalar: [],
|
|
1227
|
-
sequence: [],
|
|
1228
|
-
mapping: [],
|
|
1229
|
-
fallback: []
|
|
1230
|
-
}
|
|
1231
|
-
}, index, length;
|
|
1232
|
-
function collectType(type2) {
|
|
1233
|
-
if (type2.multi) {
|
|
1234
|
-
result.multi[type2.kind].push(type2);
|
|
1235
|
-
result.multi["fallback"].push(type2);
|
|
1236
|
-
} else {
|
|
1237
|
-
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
for (index = 0, length = arguments.length; index < length; index += 1) {
|
|
1241
|
-
arguments[index].forEach(collectType);
|
|
1242
|
-
}
|
|
1243
|
-
return result;
|
|
1244
|
-
}
|
|
1245
|
-
function Schema$1(definition) {
|
|
1246
|
-
return this.extend(definition);
|
|
1247
|
-
}
|
|
1248
|
-
Schema$1.prototype.extend = function extend2(definition) {
|
|
1249
|
-
var implicit = [];
|
|
1250
|
-
var explicit = [];
|
|
1251
|
-
if (definition instanceof type) {
|
|
1252
|
-
explicit.push(definition);
|
|
1253
|
-
} else if (Array.isArray(definition)) {
|
|
1254
|
-
explicit = explicit.concat(definition);
|
|
1255
|
-
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
1256
|
-
if (definition.implicit)
|
|
1257
|
-
implicit = implicit.concat(definition.implicit);
|
|
1258
|
-
if (definition.explicit)
|
|
1259
|
-
explicit = explicit.concat(definition.explicit);
|
|
1260
|
-
} else {
|
|
1261
|
-
throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
1262
|
-
}
|
|
1263
|
-
implicit.forEach(function(type$1) {
|
|
1264
|
-
if (!(type$1 instanceof type)) {
|
|
1265
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
1266
|
-
}
|
|
1267
|
-
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
1268
|
-
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
1269
|
-
}
|
|
1270
|
-
if (type$1.multi) {
|
|
1271
|
-
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
1272
|
-
}
|
|
1273
|
-
});
|
|
1274
|
-
explicit.forEach(function(type$1) {
|
|
1275
|
-
if (!(type$1 instanceof type)) {
|
|
1276
|
-
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
1277
|
-
}
|
|
1278
|
-
});
|
|
1279
|
-
var result = Object.create(Schema$1.prototype);
|
|
1280
|
-
result.implicit = (this.implicit || []).concat(implicit);
|
|
1281
|
-
result.explicit = (this.explicit || []).concat(explicit);
|
|
1282
|
-
result.compiledImplicit = compileList(result, "implicit");
|
|
1283
|
-
result.compiledExplicit = compileList(result, "explicit");
|
|
1284
|
-
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
1285
|
-
return result;
|
|
1286
|
-
};
|
|
1287
|
-
var schema = Schema$1;
|
|
1288
|
-
var str = new type("tag:yaml.org,2002:str", {
|
|
1289
|
-
kind: "scalar",
|
|
1290
|
-
construct: function(data) {
|
|
1291
|
-
return data !== null ? data : "";
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
|
-
var seq = new type("tag:yaml.org,2002:seq", {
|
|
1295
|
-
kind: "sequence",
|
|
1296
|
-
construct: function(data) {
|
|
1297
|
-
return data !== null ? data : [];
|
|
1298
|
-
}
|
|
1299
|
-
});
|
|
1300
|
-
var map = new type("tag:yaml.org,2002:map", {
|
|
1301
|
-
kind: "mapping",
|
|
1302
|
-
construct: function(data) {
|
|
1303
|
-
return data !== null ? data : {};
|
|
1304
|
-
}
|
|
1305
|
-
});
|
|
1306
|
-
var failsafe = new schema({
|
|
1307
|
-
explicit: [
|
|
1308
|
-
str,
|
|
1309
|
-
seq,
|
|
1310
|
-
map
|
|
1311
|
-
]
|
|
1312
|
-
});
|
|
1313
|
-
function resolveYamlNull(data) {
|
|
1314
|
-
if (data === null)
|
|
1315
|
-
return true;
|
|
1316
|
-
var max = data.length;
|
|
1317
|
-
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
1318
|
-
}
|
|
1319
|
-
function constructYamlNull() {
|
|
1320
|
-
return null;
|
|
1321
|
-
}
|
|
1322
|
-
function isNull(object) {
|
|
1323
|
-
return object === null;
|
|
1324
|
-
}
|
|
1325
|
-
var _null = new type("tag:yaml.org,2002:null", {
|
|
1326
|
-
kind: "scalar",
|
|
1327
|
-
resolve: resolveYamlNull,
|
|
1328
|
-
construct: constructYamlNull,
|
|
1329
|
-
predicate: isNull,
|
|
1330
|
-
represent: {
|
|
1331
|
-
canonical: function() {
|
|
1332
|
-
return "~";
|
|
1333
|
-
},
|
|
1334
|
-
lowercase: function() {
|
|
1335
|
-
return "null";
|
|
1336
|
-
},
|
|
1337
|
-
uppercase: function() {
|
|
1338
|
-
return "NULL";
|
|
1339
|
-
},
|
|
1340
|
-
camelcase: function() {
|
|
1341
|
-
return "Null";
|
|
1342
|
-
},
|
|
1343
|
-
empty: function() {
|
|
1344
|
-
return "";
|
|
1345
|
-
}
|
|
1346
|
-
},
|
|
1347
|
-
defaultStyle: "lowercase"
|
|
1348
|
-
});
|
|
1349
|
-
function resolveYamlBoolean(data) {
|
|
1350
|
-
if (data === null)
|
|
1351
|
-
return false;
|
|
1352
|
-
var max = data.length;
|
|
1353
|
-
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
1354
|
-
}
|
|
1355
|
-
function constructYamlBoolean(data) {
|
|
1356
|
-
return data === "true" || data === "True" || data === "TRUE";
|
|
1357
|
-
}
|
|
1358
|
-
function isBoolean(object) {
|
|
1359
|
-
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
1360
|
-
}
|
|
1361
|
-
var bool = new type("tag:yaml.org,2002:bool", {
|
|
1362
|
-
kind: "scalar",
|
|
1363
|
-
resolve: resolveYamlBoolean,
|
|
1364
|
-
construct: constructYamlBoolean,
|
|
1365
|
-
predicate: isBoolean,
|
|
1366
|
-
represent: {
|
|
1367
|
-
lowercase: function(object) {
|
|
1368
|
-
return object ? "true" : "false";
|
|
1369
|
-
},
|
|
1370
|
-
uppercase: function(object) {
|
|
1371
|
-
return object ? "TRUE" : "FALSE";
|
|
1372
|
-
},
|
|
1373
|
-
camelcase: function(object) {
|
|
1374
|
-
return object ? "True" : "False";
|
|
1375
|
-
}
|
|
1376
|
-
},
|
|
1377
|
-
defaultStyle: "lowercase"
|
|
1378
|
-
});
|
|
1379
|
-
function isHexCode(c) {
|
|
1380
|
-
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
1381
|
-
}
|
|
1382
|
-
function isOctCode(c) {
|
|
1383
|
-
return 48 <= c && c <= 55;
|
|
1384
|
-
}
|
|
1385
|
-
function isDecCode(c) {
|
|
1386
|
-
return 48 <= c && c <= 57;
|
|
1387
|
-
}
|
|
1388
|
-
function resolveYamlInteger(data) {
|
|
1389
|
-
if (data === null)
|
|
1390
|
-
return false;
|
|
1391
|
-
var max = data.length, index = 0, hasDigits = false, ch;
|
|
1392
|
-
if (!max)
|
|
1393
|
-
return false;
|
|
1394
|
-
ch = data[index];
|
|
1395
|
-
if (ch === "-" || ch === "+") {
|
|
1396
|
-
ch = data[++index];
|
|
1397
|
-
}
|
|
1398
|
-
if (ch === "0") {
|
|
1399
|
-
if (index + 1 === max)
|
|
1400
|
-
return true;
|
|
1401
|
-
ch = data[++index];
|
|
1402
|
-
if (ch === "b") {
|
|
1403
|
-
index++;
|
|
1404
|
-
for (; index < max; index++) {
|
|
1405
|
-
ch = data[index];
|
|
1406
|
-
if (ch === "_")
|
|
1407
|
-
continue;
|
|
1408
|
-
if (ch !== "0" && ch !== "1")
|
|
1409
|
-
return false;
|
|
1410
|
-
hasDigits = true;
|
|
1411
|
-
}
|
|
1412
|
-
return hasDigits && ch !== "_";
|
|
1413
|
-
}
|
|
1414
|
-
if (ch === "x") {
|
|
1415
|
-
index++;
|
|
1416
|
-
for (; index < max; index++) {
|
|
1417
|
-
ch = data[index];
|
|
1418
|
-
if (ch === "_")
|
|
1419
|
-
continue;
|
|
1420
|
-
if (!isHexCode(data.charCodeAt(index)))
|
|
1421
|
-
return false;
|
|
1422
|
-
hasDigits = true;
|
|
1423
|
-
}
|
|
1424
|
-
return hasDigits && ch !== "_";
|
|
1425
|
-
}
|
|
1426
|
-
if (ch === "o") {
|
|
1427
|
-
index++;
|
|
1428
|
-
for (; index < max; index++) {
|
|
1429
|
-
ch = data[index];
|
|
1430
|
-
if (ch === "_")
|
|
1431
|
-
continue;
|
|
1432
|
-
if (!isOctCode(data.charCodeAt(index)))
|
|
1433
|
-
return false;
|
|
1434
|
-
hasDigits = true;
|
|
1435
|
-
}
|
|
1436
|
-
return hasDigits && ch !== "_";
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
if (ch === "_")
|
|
1440
|
-
return false;
|
|
1441
|
-
for (; index < max; index++) {
|
|
1442
|
-
ch = data[index];
|
|
1443
|
-
if (ch === "_")
|
|
1444
|
-
continue;
|
|
1445
|
-
if (!isDecCode(data.charCodeAt(index))) {
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
hasDigits = true;
|
|
1449
|
-
}
|
|
1450
|
-
if (!hasDigits || ch === "_")
|
|
1451
|
-
return false;
|
|
1452
|
-
return true;
|
|
1453
|
-
}
|
|
1454
|
-
function constructYamlInteger(data) {
|
|
1455
|
-
var value = data, sign = 1, ch;
|
|
1456
|
-
if (value.indexOf("_") !== -1) {
|
|
1457
|
-
value = value.replace(/_/g, "");
|
|
1458
|
-
}
|
|
1459
|
-
ch = value[0];
|
|
1460
|
-
if (ch === "-" || ch === "+") {
|
|
1461
|
-
if (ch === "-")
|
|
1462
|
-
sign = -1;
|
|
1463
|
-
value = value.slice(1);
|
|
1464
|
-
ch = value[0];
|
|
1465
|
-
}
|
|
1466
|
-
if (value === "0")
|
|
1467
|
-
return 0;
|
|
1468
|
-
if (ch === "0") {
|
|
1469
|
-
if (value[1] === "b")
|
|
1470
|
-
return sign * parseInt(value.slice(2), 2);
|
|
1471
|
-
if (value[1] === "x")
|
|
1472
|
-
return sign * parseInt(value.slice(2), 16);
|
|
1473
|
-
if (value[1] === "o")
|
|
1474
|
-
return sign * parseInt(value.slice(2), 8);
|
|
1475
|
-
}
|
|
1476
|
-
return sign * parseInt(value, 10);
|
|
1477
|
-
}
|
|
1478
|
-
function isInteger(object) {
|
|
1479
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
1480
|
-
}
|
|
1481
|
-
var int = new type("tag:yaml.org,2002:int", {
|
|
1482
|
-
kind: "scalar",
|
|
1483
|
-
resolve: resolveYamlInteger,
|
|
1484
|
-
construct: constructYamlInteger,
|
|
1485
|
-
predicate: isInteger,
|
|
1486
|
-
represent: {
|
|
1487
|
-
binary: function(obj) {
|
|
1488
|
-
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
1489
|
-
},
|
|
1490
|
-
octal: function(obj) {
|
|
1491
|
-
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
1492
|
-
},
|
|
1493
|
-
decimal: function(obj) {
|
|
1494
|
-
return obj.toString(10);
|
|
1495
|
-
},
|
|
1496
|
-
/* eslint-disable max-len */
|
|
1497
|
-
hexadecimal: function(obj) {
|
|
1498
|
-
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
1499
|
-
}
|
|
1500
|
-
},
|
|
1501
|
-
defaultStyle: "decimal",
|
|
1502
|
-
styleAliases: {
|
|
1503
|
-
binary: [2, "bin"],
|
|
1504
|
-
octal: [8, "oct"],
|
|
1505
|
-
decimal: [10, "dec"],
|
|
1506
|
-
hexadecimal: [16, "hex"]
|
|
1507
|
-
}
|
|
1508
|
-
});
|
|
1509
|
-
var YAML_FLOAT_PATTERN = new RegExp(
|
|
1510
|
-
// 2.5e4, 2.5 and integers
|
|
1511
|
-
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
1512
|
-
);
|
|
1513
|
-
function resolveYamlFloat(data) {
|
|
1514
|
-
if (data === null)
|
|
1515
|
-
return false;
|
|
1516
|
-
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
1517
|
-
// Probably should update regexp & check speed
|
|
1518
|
-
data[data.length - 1] === "_") {
|
|
1519
|
-
return false;
|
|
1520
|
-
}
|
|
1521
|
-
return true;
|
|
1522
|
-
}
|
|
1523
|
-
function constructYamlFloat(data) {
|
|
1524
|
-
var value, sign;
|
|
1525
|
-
value = data.replace(/_/g, "").toLowerCase();
|
|
1526
|
-
sign = value[0] === "-" ? -1 : 1;
|
|
1527
|
-
if ("+-".indexOf(value[0]) >= 0) {
|
|
1528
|
-
value = value.slice(1);
|
|
1529
|
-
}
|
|
1530
|
-
if (value === ".inf") {
|
|
1531
|
-
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
1532
|
-
} else if (value === ".nan") {
|
|
1533
|
-
return NaN;
|
|
1534
|
-
}
|
|
1535
|
-
return sign * parseFloat(value, 10);
|
|
1536
|
-
}
|
|
1537
|
-
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
1538
|
-
function representYamlFloat(object, style) {
|
|
1539
|
-
var res;
|
|
1540
|
-
if (isNaN(object)) {
|
|
1541
|
-
switch (style) {
|
|
1542
|
-
case "lowercase":
|
|
1543
|
-
return ".nan";
|
|
1544
|
-
case "uppercase":
|
|
1545
|
-
return ".NAN";
|
|
1546
|
-
case "camelcase":
|
|
1547
|
-
return ".NaN";
|
|
1548
|
-
}
|
|
1549
|
-
} else if (Number.POSITIVE_INFINITY === object) {
|
|
1550
|
-
switch (style) {
|
|
1551
|
-
case "lowercase":
|
|
1552
|
-
return ".inf";
|
|
1553
|
-
case "uppercase":
|
|
1554
|
-
return ".INF";
|
|
1555
|
-
case "camelcase":
|
|
1556
|
-
return ".Inf";
|
|
1557
|
-
}
|
|
1558
|
-
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
1559
|
-
switch (style) {
|
|
1560
|
-
case "lowercase":
|
|
1561
|
-
return "-.inf";
|
|
1562
|
-
case "uppercase":
|
|
1563
|
-
return "-.INF";
|
|
1564
|
-
case "camelcase":
|
|
1565
|
-
return "-.Inf";
|
|
1566
|
-
}
|
|
1567
|
-
} else if (common.isNegativeZero(object)) {
|
|
1568
|
-
return "-0.0";
|
|
1569
|
-
}
|
|
1570
|
-
res = object.toString(10);
|
|
1571
|
-
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
1572
|
-
}
|
|
1573
|
-
function isFloat(object) {
|
|
1574
|
-
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
1575
|
-
}
|
|
1576
|
-
var float = new type("tag:yaml.org,2002:float", {
|
|
1577
|
-
kind: "scalar",
|
|
1578
|
-
resolve: resolveYamlFloat,
|
|
1579
|
-
construct: constructYamlFloat,
|
|
1580
|
-
predicate: isFloat,
|
|
1581
|
-
represent: representYamlFloat,
|
|
1582
|
-
defaultStyle: "lowercase"
|
|
1583
|
-
});
|
|
1584
|
-
var json = failsafe.extend({
|
|
1585
|
-
implicit: [
|
|
1586
|
-
_null,
|
|
1587
|
-
bool,
|
|
1588
|
-
int,
|
|
1589
|
-
float
|
|
1590
|
-
]
|
|
1591
|
-
});
|
|
1592
|
-
var core = json;
|
|
1593
|
-
var YAML_DATE_REGEXP = new RegExp(
|
|
1594
|
-
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
1595
|
-
);
|
|
1596
|
-
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
1597
|
-
"^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
|
|
1598
|
-
);
|
|
1599
|
-
function resolveYamlTimestamp(data) {
|
|
1600
|
-
if (data === null)
|
|
1601
|
-
return false;
|
|
1602
|
-
if (YAML_DATE_REGEXP.exec(data) !== null)
|
|
1603
|
-
return true;
|
|
1604
|
-
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
|
|
1605
|
-
return true;
|
|
1606
|
-
return false;
|
|
1607
|
-
}
|
|
1608
|
-
function constructYamlTimestamp(data) {
|
|
1609
|
-
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
1610
|
-
match = YAML_DATE_REGEXP.exec(data);
|
|
1611
|
-
if (match === null)
|
|
1612
|
-
match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
1613
|
-
if (match === null)
|
|
1614
|
-
throw new Error("Date resolve error");
|
|
1615
|
-
year = +match[1];
|
|
1616
|
-
month = +match[2] - 1;
|
|
1617
|
-
day = +match[3];
|
|
1618
|
-
if (!match[4]) {
|
|
1619
|
-
return new Date(Date.UTC(year, month, day));
|
|
1620
|
-
}
|
|
1621
|
-
hour = +match[4];
|
|
1622
|
-
minute = +match[5];
|
|
1623
|
-
second = +match[6];
|
|
1624
|
-
if (match[7]) {
|
|
1625
|
-
fraction = match[7].slice(0, 3);
|
|
1626
|
-
while (fraction.length < 3) {
|
|
1627
|
-
fraction += "0";
|
|
1628
|
-
}
|
|
1629
|
-
fraction = +fraction;
|
|
1630
|
-
}
|
|
1631
|
-
if (match[9]) {
|
|
1632
|
-
tz_hour = +match[10];
|
|
1633
|
-
tz_minute = +(match[11] || 0);
|
|
1634
|
-
delta = (tz_hour * 60 + tz_minute) * 6e4;
|
|
1635
|
-
if (match[9] === "-")
|
|
1636
|
-
delta = -delta;
|
|
1637
|
-
}
|
|
1638
|
-
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
1639
|
-
if (delta)
|
|
1640
|
-
date.setTime(date.getTime() - delta);
|
|
1641
|
-
return date;
|
|
1642
|
-
}
|
|
1643
|
-
function representYamlTimestamp(object) {
|
|
1644
|
-
return object.toISOString();
|
|
1645
|
-
}
|
|
1646
|
-
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
1647
|
-
kind: "scalar",
|
|
1648
|
-
resolve: resolveYamlTimestamp,
|
|
1649
|
-
construct: constructYamlTimestamp,
|
|
1650
|
-
instanceOf: Date,
|
|
1651
|
-
represent: representYamlTimestamp
|
|
1652
|
-
});
|
|
1653
|
-
function resolveYamlMerge(data) {
|
|
1654
|
-
return data === "<<" || data === null;
|
|
1655
|
-
}
|
|
1656
|
-
var merge = new type("tag:yaml.org,2002:merge", {
|
|
1657
|
-
kind: "scalar",
|
|
1658
|
-
resolve: resolveYamlMerge
|
|
1659
|
-
});
|
|
1660
|
-
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
1661
|
-
function resolveYamlBinary(data) {
|
|
1662
|
-
if (data === null)
|
|
1663
|
-
return false;
|
|
1664
|
-
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
1665
|
-
for (idx = 0; idx < max; idx++) {
|
|
1666
|
-
code = map2.indexOf(data.charAt(idx));
|
|
1667
|
-
if (code > 64)
|
|
1668
|
-
continue;
|
|
1669
|
-
if (code < 0)
|
|
1670
|
-
return false;
|
|
1671
|
-
bitlen += 6;
|
|
1672
|
-
}
|
|
1673
|
-
return bitlen % 8 === 0;
|
|
1674
|
-
}
|
|
1675
|
-
function constructYamlBinary(data) {
|
|
1676
|
-
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
1677
|
-
for (idx = 0; idx < max; idx++) {
|
|
1678
|
-
if (idx % 4 === 0 && idx) {
|
|
1679
|
-
result.push(bits >> 16 & 255);
|
|
1680
|
-
result.push(bits >> 8 & 255);
|
|
1681
|
-
result.push(bits & 255);
|
|
1682
|
-
}
|
|
1683
|
-
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
1684
|
-
}
|
|
1685
|
-
tailbits = max % 4 * 6;
|
|
1686
|
-
if (tailbits === 0) {
|
|
1687
|
-
result.push(bits >> 16 & 255);
|
|
1688
|
-
result.push(bits >> 8 & 255);
|
|
1689
|
-
result.push(bits & 255);
|
|
1690
|
-
} else if (tailbits === 18) {
|
|
1691
|
-
result.push(bits >> 10 & 255);
|
|
1692
|
-
result.push(bits >> 2 & 255);
|
|
1693
|
-
} else if (tailbits === 12) {
|
|
1694
|
-
result.push(bits >> 4 & 255);
|
|
1695
|
-
}
|
|
1696
|
-
return new Uint8Array(result);
|
|
1697
|
-
}
|
|
1698
|
-
function representYamlBinary(object) {
|
|
1699
|
-
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
1700
|
-
for (idx = 0; idx < max; idx++) {
|
|
1701
|
-
if (idx % 3 === 0 && idx) {
|
|
1702
|
-
result += map2[bits >> 18 & 63];
|
|
1703
|
-
result += map2[bits >> 12 & 63];
|
|
1704
|
-
result += map2[bits >> 6 & 63];
|
|
1705
|
-
result += map2[bits & 63];
|
|
1706
|
-
}
|
|
1707
|
-
bits = (bits << 8) + object[idx];
|
|
1708
|
-
}
|
|
1709
|
-
tail = max % 3;
|
|
1710
|
-
if (tail === 0) {
|
|
1711
|
-
result += map2[bits >> 18 & 63];
|
|
1712
|
-
result += map2[bits >> 12 & 63];
|
|
1713
|
-
result += map2[bits >> 6 & 63];
|
|
1714
|
-
result += map2[bits & 63];
|
|
1715
|
-
} else if (tail === 2) {
|
|
1716
|
-
result += map2[bits >> 10 & 63];
|
|
1717
|
-
result += map2[bits >> 4 & 63];
|
|
1718
|
-
result += map2[bits << 2 & 63];
|
|
1719
|
-
result += map2[64];
|
|
1720
|
-
} else if (tail === 1) {
|
|
1721
|
-
result += map2[bits >> 2 & 63];
|
|
1722
|
-
result += map2[bits << 4 & 63];
|
|
1723
|
-
result += map2[64];
|
|
1724
|
-
result += map2[64];
|
|
1725
|
-
}
|
|
1726
|
-
return result;
|
|
1727
|
-
}
|
|
1728
|
-
function isBinary(obj) {
|
|
1729
|
-
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
1730
|
-
}
|
|
1731
|
-
var binary = new type("tag:yaml.org,2002:binary", {
|
|
1732
|
-
kind: "scalar",
|
|
1733
|
-
resolve: resolveYamlBinary,
|
|
1734
|
-
construct: constructYamlBinary,
|
|
1735
|
-
predicate: isBinary,
|
|
1736
|
-
represent: representYamlBinary
|
|
1737
|
-
});
|
|
1738
|
-
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1739
|
-
var _toString$2 = Object.prototype.toString;
|
|
1740
|
-
function resolveYamlOmap(data) {
|
|
1741
|
-
if (data === null)
|
|
1742
|
-
return true;
|
|
1743
|
-
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
1744
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1745
|
-
pair = object[index];
|
|
1746
|
-
pairHasKey = false;
|
|
1747
|
-
if (_toString$2.call(pair) !== "[object Object]")
|
|
1748
|
-
return false;
|
|
1749
|
-
for (pairKey in pair) {
|
|
1750
|
-
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
1751
|
-
if (!pairHasKey)
|
|
1752
|
-
pairHasKey = true;
|
|
1753
|
-
else
|
|
1754
|
-
return false;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
if (!pairHasKey)
|
|
1758
|
-
return false;
|
|
1759
|
-
if (objectKeys.indexOf(pairKey) === -1)
|
|
1760
|
-
objectKeys.push(pairKey);
|
|
1761
|
-
else
|
|
1762
|
-
return false;
|
|
1763
|
-
}
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1766
|
-
function constructYamlOmap(data) {
|
|
1767
|
-
return data !== null ? data : [];
|
|
1768
|
-
}
|
|
1769
|
-
var omap = new type("tag:yaml.org,2002:omap", {
|
|
1770
|
-
kind: "sequence",
|
|
1771
|
-
resolve: resolveYamlOmap,
|
|
1772
|
-
construct: constructYamlOmap
|
|
1773
|
-
});
|
|
1774
|
-
var _toString$1 = Object.prototype.toString;
|
|
1775
|
-
function resolveYamlPairs(data) {
|
|
1776
|
-
if (data === null)
|
|
1777
|
-
return true;
|
|
1778
|
-
var index, length, pair, keys, result, object = data;
|
|
1779
|
-
result = new Array(object.length);
|
|
1780
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1781
|
-
pair = object[index];
|
|
1782
|
-
if (_toString$1.call(pair) !== "[object Object]")
|
|
1783
|
-
return false;
|
|
1784
|
-
keys = Object.keys(pair);
|
|
1785
|
-
if (keys.length !== 1)
|
|
1786
|
-
return false;
|
|
1787
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
1788
|
-
}
|
|
1789
|
-
return true;
|
|
1790
|
-
}
|
|
1791
|
-
function constructYamlPairs(data) {
|
|
1792
|
-
if (data === null)
|
|
1793
|
-
return [];
|
|
1794
|
-
var index, length, pair, keys, result, object = data;
|
|
1795
|
-
result = new Array(object.length);
|
|
1796
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1797
|
-
pair = object[index];
|
|
1798
|
-
keys = Object.keys(pair);
|
|
1799
|
-
result[index] = [keys[0], pair[keys[0]]];
|
|
1800
|
-
}
|
|
1801
|
-
return result;
|
|
1802
|
-
}
|
|
1803
|
-
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
1804
|
-
kind: "sequence",
|
|
1805
|
-
resolve: resolveYamlPairs,
|
|
1806
|
-
construct: constructYamlPairs
|
|
1807
|
-
});
|
|
1808
|
-
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1809
|
-
function resolveYamlSet(data) {
|
|
1810
|
-
if (data === null)
|
|
1811
|
-
return true;
|
|
1812
|
-
var key, object = data;
|
|
1813
|
-
for (key in object) {
|
|
1814
|
-
if (_hasOwnProperty$2.call(object, key)) {
|
|
1815
|
-
if (object[key] !== null)
|
|
1816
|
-
return false;
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
return true;
|
|
1820
|
-
}
|
|
1821
|
-
function constructYamlSet(data) {
|
|
1822
|
-
return data !== null ? data : {};
|
|
1823
|
-
}
|
|
1824
|
-
var set = new type("tag:yaml.org,2002:set", {
|
|
1825
|
-
kind: "mapping",
|
|
1826
|
-
resolve: resolveYamlSet,
|
|
1827
|
-
construct: constructYamlSet
|
|
1828
|
-
});
|
|
1829
|
-
var _default = core.extend({
|
|
1830
|
-
implicit: [
|
|
1831
|
-
timestamp,
|
|
1832
|
-
merge
|
|
1833
|
-
],
|
|
1834
|
-
explicit: [
|
|
1835
|
-
binary,
|
|
1836
|
-
omap,
|
|
1837
|
-
pairs,
|
|
1838
|
-
set
|
|
1839
|
-
]
|
|
1840
|
-
});
|
|
1841
|
-
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
1842
|
-
var CONTEXT_FLOW_IN = 1;
|
|
1843
|
-
var CONTEXT_FLOW_OUT = 2;
|
|
1844
|
-
var CONTEXT_BLOCK_IN = 3;
|
|
1845
|
-
var CONTEXT_BLOCK_OUT = 4;
|
|
1846
|
-
var CHOMPING_CLIP = 1;
|
|
1847
|
-
var CHOMPING_STRIP = 2;
|
|
1848
|
-
var CHOMPING_KEEP = 3;
|
|
1849
|
-
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1850
|
-
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
1851
|
-
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
1852
|
-
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
1853
|
-
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
1854
|
-
function _class(obj) {
|
|
1855
|
-
return Object.prototype.toString.call(obj);
|
|
1856
|
-
}
|
|
1857
|
-
function is_EOL(c) {
|
|
1858
|
-
return c === 10 || c === 13;
|
|
1859
|
-
}
|
|
1860
|
-
function is_WHITE_SPACE(c) {
|
|
1861
|
-
return c === 9 || c === 32;
|
|
1862
|
-
}
|
|
1863
|
-
function is_WS_OR_EOL(c) {
|
|
1864
|
-
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
1865
|
-
}
|
|
1866
|
-
function is_FLOW_INDICATOR(c) {
|
|
1867
|
-
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1868
|
-
}
|
|
1869
|
-
function fromHexCode(c) {
|
|
1870
|
-
var lc;
|
|
1871
|
-
if (48 <= c && c <= 57) {
|
|
1872
|
-
return c - 48;
|
|
1873
|
-
}
|
|
1874
|
-
lc = c | 32;
|
|
1875
|
-
if (97 <= lc && lc <= 102) {
|
|
1876
|
-
return lc - 97 + 10;
|
|
1877
|
-
}
|
|
1878
|
-
return -1;
|
|
1879
|
-
}
|
|
1880
|
-
function escapedHexLen(c) {
|
|
1881
|
-
if (c === 120) {
|
|
1882
|
-
return 2;
|
|
1883
|
-
}
|
|
1884
|
-
if (c === 117) {
|
|
1885
|
-
return 4;
|
|
1886
|
-
}
|
|
1887
|
-
if (c === 85) {
|
|
1888
|
-
return 8;
|
|
1889
|
-
}
|
|
1890
|
-
return 0;
|
|
1891
|
-
}
|
|
1892
|
-
function fromDecimalCode(c) {
|
|
1893
|
-
if (48 <= c && c <= 57) {
|
|
1894
|
-
return c - 48;
|
|
1895
|
-
}
|
|
1896
|
-
return -1;
|
|
1897
|
-
}
|
|
1898
|
-
function simpleEscapeSequence(c) {
|
|
1899
|
-
return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
1900
|
-
}
|
|
1901
|
-
function charFromCodepoint(c) {
|
|
1902
|
-
if (c <= 65535) {
|
|
1903
|
-
return String.fromCharCode(c);
|
|
1904
|
-
}
|
|
1905
|
-
return String.fromCharCode(
|
|
1906
|
-
(c - 65536 >> 10) + 55296,
|
|
1907
|
-
(c - 65536 & 1023) + 56320
|
|
1908
|
-
);
|
|
1909
|
-
}
|
|
1910
|
-
var simpleEscapeCheck = new Array(256);
|
|
1911
|
-
var simpleEscapeMap = new Array(256);
|
|
1912
|
-
for (i = 0; i < 256; i++) {
|
|
1913
|
-
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1914
|
-
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1915
|
-
}
|
|
1916
|
-
var i;
|
|
1917
|
-
function State$1(input, options) {
|
|
1918
|
-
this.input = input;
|
|
1919
|
-
this.filename = options["filename"] || null;
|
|
1920
|
-
this.schema = options["schema"] || _default;
|
|
1921
|
-
this.onWarning = options["onWarning"] || null;
|
|
1922
|
-
this.legacy = options["legacy"] || false;
|
|
1923
|
-
this.json = options["json"] || false;
|
|
1924
|
-
this.listener = options["listener"] || null;
|
|
1925
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
1926
|
-
this.typeMap = this.schema.compiledTypeMap;
|
|
1927
|
-
this.length = input.length;
|
|
1928
|
-
this.position = 0;
|
|
1929
|
-
this.line = 0;
|
|
1930
|
-
this.lineStart = 0;
|
|
1931
|
-
this.lineIndent = 0;
|
|
1932
|
-
this.firstTabInLine = -1;
|
|
1933
|
-
this.documents = [];
|
|
1934
|
-
}
|
|
1935
|
-
function generateError(state, message) {
|
|
1936
|
-
var mark = {
|
|
1937
|
-
name: state.filename,
|
|
1938
|
-
buffer: state.input.slice(0, -1),
|
|
1939
|
-
// omit trailing \0
|
|
1940
|
-
position: state.position,
|
|
1941
|
-
line: state.line,
|
|
1942
|
-
column: state.position - state.lineStart
|
|
1943
|
-
};
|
|
1944
|
-
mark.snippet = snippet(mark);
|
|
1945
|
-
return new exception(message, mark);
|
|
1946
|
-
}
|
|
1947
|
-
function throwError(state, message) {
|
|
1948
|
-
throw generateError(state, message);
|
|
1949
|
-
}
|
|
1950
|
-
function throwWarning(state, message) {
|
|
1951
|
-
if (state.onWarning) {
|
|
1952
|
-
state.onWarning.call(null, generateError(state, message));
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
var directiveHandlers = {
|
|
1956
|
-
YAML: function handleYamlDirective(state, name, args) {
|
|
1957
|
-
var match, major, minor;
|
|
1958
|
-
if (state.version !== null) {
|
|
1959
|
-
throwError(state, "duplication of %YAML directive");
|
|
1960
|
-
}
|
|
1961
|
-
if (args.length !== 1) {
|
|
1962
|
-
throwError(state, "YAML directive accepts exactly one argument");
|
|
1963
|
-
}
|
|
1964
|
-
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1965
|
-
if (match === null) {
|
|
1966
|
-
throwError(state, "ill-formed argument of the YAML directive");
|
|
1967
|
-
}
|
|
1968
|
-
major = parseInt(match[1], 10);
|
|
1969
|
-
minor = parseInt(match[2], 10);
|
|
1970
|
-
if (major !== 1) {
|
|
1971
|
-
throwError(state, "unacceptable YAML version of the document");
|
|
1972
|
-
}
|
|
1973
|
-
state.version = args[0];
|
|
1974
|
-
state.checkLineBreaks = minor < 2;
|
|
1975
|
-
if (minor !== 1 && minor !== 2) {
|
|
1976
|
-
throwWarning(state, "unsupported YAML version of the document");
|
|
1977
|
-
}
|
|
1978
|
-
},
|
|
1979
|
-
TAG: function handleTagDirective(state, name, args) {
|
|
1980
|
-
var handle, prefix;
|
|
1981
|
-
if (args.length !== 2) {
|
|
1982
|
-
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1983
|
-
}
|
|
1984
|
-
handle = args[0];
|
|
1985
|
-
prefix = args[1];
|
|
1986
|
-
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1987
|
-
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1988
|
-
}
|
|
1989
|
-
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1990
|
-
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1991
|
-
}
|
|
1992
|
-
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1993
|
-
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1994
|
-
}
|
|
1995
|
-
try {
|
|
1996
|
-
prefix = decodeURIComponent(prefix);
|
|
1997
|
-
} catch (err) {
|
|
1998
|
-
throwError(state, "tag prefix is malformed: " + prefix);
|
|
1999
|
-
}
|
|
2000
|
-
state.tagMap[handle] = prefix;
|
|
2001
|
-
}
|
|
2002
|
-
};
|
|
2003
|
-
function captureSegment(state, start, end, checkJson) {
|
|
2004
|
-
var _position, _length, _character, _result;
|
|
2005
|
-
if (start < end) {
|
|
2006
|
-
_result = state.input.slice(start, end);
|
|
2007
|
-
if (checkJson) {
|
|
2008
|
-
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|
2009
|
-
_character = _result.charCodeAt(_position);
|
|
2010
|
-
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
2011
|
-
throwError(state, "expected valid JSON character");
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
2015
|
-
throwError(state, "the stream contains non-printable characters");
|
|
2016
|
-
}
|
|
2017
|
-
state.result += _result;
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
function mergeMappings(state, destination, source, overridableKeys) {
|
|
2021
|
-
var sourceKeys, key, index, quantity;
|
|
2022
|
-
if (!common.isObject(source)) {
|
|
2023
|
-
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
2024
|
-
}
|
|
2025
|
-
sourceKeys = Object.keys(source);
|
|
2026
|
-
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
2027
|
-
key = sourceKeys[index];
|
|
2028
|
-
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
2029
|
-
destination[key] = source[key];
|
|
2030
|
-
overridableKeys[key] = true;
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
2035
|
-
var index, quantity;
|
|
2036
|
-
if (Array.isArray(keyNode)) {
|
|
2037
|
-
keyNode = Array.prototype.slice.call(keyNode);
|
|
2038
|
-
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|
2039
|
-
if (Array.isArray(keyNode[index])) {
|
|
2040
|
-
throwError(state, "nested arrays are not supported inside keys");
|
|
2041
|
-
}
|
|
2042
|
-
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
2043
|
-
keyNode[index] = "[object Object]";
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
2048
|
-
keyNode = "[object Object]";
|
|
2049
|
-
}
|
|
2050
|
-
keyNode = String(keyNode);
|
|
2051
|
-
if (_result === null) {
|
|
2052
|
-
_result = {};
|
|
2053
|
-
}
|
|
2054
|
-
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
2055
|
-
if (Array.isArray(valueNode)) {
|
|
2056
|
-
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
2057
|
-
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
2058
|
-
}
|
|
2059
|
-
} else {
|
|
2060
|
-
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
2061
|
-
}
|
|
2062
|
-
} else {
|
|
2063
|
-
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
2064
|
-
state.line = startLine || state.line;
|
|
2065
|
-
state.lineStart = startLineStart || state.lineStart;
|
|
2066
|
-
state.position = startPos || state.position;
|
|
2067
|
-
throwError(state, "duplicated mapping key");
|
|
2068
|
-
}
|
|
2069
|
-
if (keyNode === "__proto__") {
|
|
2070
|
-
Object.defineProperty(_result, keyNode, {
|
|
2071
|
-
configurable: true,
|
|
2072
|
-
enumerable: true,
|
|
2073
|
-
writable: true,
|
|
2074
|
-
value: valueNode
|
|
2075
|
-
});
|
|
2076
|
-
} else {
|
|
2077
|
-
_result[keyNode] = valueNode;
|
|
2078
|
-
}
|
|
2079
|
-
delete overridableKeys[keyNode];
|
|
2080
|
-
}
|
|
2081
|
-
return _result;
|
|
2082
|
-
}
|
|
2083
|
-
function readLineBreak(state) {
|
|
2084
|
-
var ch;
|
|
2085
|
-
ch = state.input.charCodeAt(state.position);
|
|
2086
|
-
if (ch === 10) {
|
|
2087
|
-
state.position++;
|
|
2088
|
-
} else if (ch === 13) {
|
|
2089
|
-
state.position++;
|
|
2090
|
-
if (state.input.charCodeAt(state.position) === 10) {
|
|
2091
|
-
state.position++;
|
|
2092
|
-
}
|
|
2093
|
-
} else {
|
|
2094
|
-
throwError(state, "a line break is expected");
|
|
2095
|
-
}
|
|
2096
|
-
state.line += 1;
|
|
2097
|
-
state.lineStart = state.position;
|
|
2098
|
-
state.firstTabInLine = -1;
|
|
2099
|
-
}
|
|
2100
|
-
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
2101
|
-
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
2102
|
-
while (ch !== 0) {
|
|
2103
|
-
while (is_WHITE_SPACE(ch)) {
|
|
2104
|
-
if (ch === 9 && state.firstTabInLine === -1) {
|
|
2105
|
-
state.firstTabInLine = state.position;
|
|
2106
|
-
}
|
|
2107
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2108
|
-
}
|
|
2109
|
-
if (allowComments && ch === 35) {
|
|
2110
|
-
do {
|
|
2111
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2112
|
-
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
2113
|
-
}
|
|
2114
|
-
if (is_EOL(ch)) {
|
|
2115
|
-
readLineBreak(state);
|
|
2116
|
-
ch = state.input.charCodeAt(state.position);
|
|
2117
|
-
lineBreaks++;
|
|
2118
|
-
state.lineIndent = 0;
|
|
2119
|
-
while (ch === 32) {
|
|
2120
|
-
state.lineIndent++;
|
|
2121
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2122
|
-
}
|
|
2123
|
-
} else {
|
|
2124
|
-
break;
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
2128
|
-
throwWarning(state, "deficient indentation");
|
|
2129
|
-
}
|
|
2130
|
-
return lineBreaks;
|
|
2131
|
-
}
|
|
2132
|
-
function testDocumentSeparator(state) {
|
|
2133
|
-
var _position = state.position, ch;
|
|
2134
|
-
ch = state.input.charCodeAt(_position);
|
|
2135
|
-
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
2136
|
-
_position += 3;
|
|
2137
|
-
ch = state.input.charCodeAt(_position);
|
|
2138
|
-
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
2139
|
-
return true;
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
return false;
|
|
2143
|
-
}
|
|
2144
|
-
function writeFoldedLines(state, count) {
|
|
2145
|
-
if (count === 1) {
|
|
2146
|
-
state.result += " ";
|
|
2147
|
-
} else if (count > 1) {
|
|
2148
|
-
state.result += common.repeat("\n", count - 1);
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
2152
|
-
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
2153
|
-
ch = state.input.charCodeAt(state.position);
|
|
2154
|
-
if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
|
|
2155
|
-
return false;
|
|
2156
|
-
}
|
|
2157
|
-
if (ch === 63 || ch === 45) {
|
|
2158
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2159
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
2160
|
-
return false;
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
state.kind = "scalar";
|
|
2164
|
-
state.result = "";
|
|
2165
|
-
captureStart = captureEnd = state.position;
|
|
2166
|
-
hasPendingContent = false;
|
|
2167
|
-
while (ch !== 0) {
|
|
2168
|
-
if (ch === 58) {
|
|
2169
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2170
|
-
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
2171
|
-
break;
|
|
2172
|
-
}
|
|
2173
|
-
} else if (ch === 35) {
|
|
2174
|
-
preceding = state.input.charCodeAt(state.position - 1);
|
|
2175
|
-
if (is_WS_OR_EOL(preceding)) {
|
|
2176
|
-
break;
|
|
2177
|
-
}
|
|
2178
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
2179
|
-
break;
|
|
2180
|
-
} else if (is_EOL(ch)) {
|
|
2181
|
-
_line = state.line;
|
|
2182
|
-
_lineStart = state.lineStart;
|
|
2183
|
-
_lineIndent = state.lineIndent;
|
|
2184
|
-
skipSeparationSpace(state, false, -1);
|
|
2185
|
-
if (state.lineIndent >= nodeIndent) {
|
|
2186
|
-
hasPendingContent = true;
|
|
2187
|
-
ch = state.input.charCodeAt(state.position);
|
|
2188
|
-
continue;
|
|
2189
|
-
} else {
|
|
2190
|
-
state.position = captureEnd;
|
|
2191
|
-
state.line = _line;
|
|
2192
|
-
state.lineStart = _lineStart;
|
|
2193
|
-
state.lineIndent = _lineIndent;
|
|
2194
|
-
break;
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
if (hasPendingContent) {
|
|
2198
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
2199
|
-
writeFoldedLines(state, state.line - _line);
|
|
2200
|
-
captureStart = captureEnd = state.position;
|
|
2201
|
-
hasPendingContent = false;
|
|
2202
|
-
}
|
|
2203
|
-
if (!is_WHITE_SPACE(ch)) {
|
|
2204
|
-
captureEnd = state.position + 1;
|
|
2205
|
-
}
|
|
2206
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2207
|
-
}
|
|
2208
|
-
captureSegment(state, captureStart, captureEnd, false);
|
|
2209
|
-
if (state.result) {
|
|
2210
|
-
return true;
|
|
2211
|
-
}
|
|
2212
|
-
state.kind = _kind;
|
|
2213
|
-
state.result = _result;
|
|
2214
|
-
return false;
|
|
2215
|
-
}
|
|
2216
|
-
function readSingleQuotedScalar(state, nodeIndent) {
|
|
2217
|
-
var ch, captureStart, captureEnd;
|
|
2218
|
-
ch = state.input.charCodeAt(state.position);
|
|
2219
|
-
if (ch !== 39) {
|
|
2220
|
-
return false;
|
|
2221
|
-
}
|
|
2222
|
-
state.kind = "scalar";
|
|
2223
|
-
state.result = "";
|
|
2224
|
-
state.position++;
|
|
2225
|
-
captureStart = captureEnd = state.position;
|
|
2226
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2227
|
-
if (ch === 39) {
|
|
2228
|
-
captureSegment(state, captureStart, state.position, true);
|
|
2229
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2230
|
-
if (ch === 39) {
|
|
2231
|
-
captureStart = state.position;
|
|
2232
|
-
state.position++;
|
|
2233
|
-
captureEnd = state.position;
|
|
2234
|
-
} else {
|
|
2235
|
-
return true;
|
|
2236
|
-
}
|
|
2237
|
-
} else if (is_EOL(ch)) {
|
|
2238
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
2239
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
2240
|
-
captureStart = captureEnd = state.position;
|
|
2241
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2242
|
-
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
2243
|
-
} else {
|
|
2244
|
-
state.position++;
|
|
2245
|
-
captureEnd = state.position;
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
2249
|
-
}
|
|
2250
|
-
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
2251
|
-
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
2252
|
-
ch = state.input.charCodeAt(state.position);
|
|
2253
|
-
if (ch !== 34) {
|
|
2254
|
-
return false;
|
|
2255
|
-
}
|
|
2256
|
-
state.kind = "scalar";
|
|
2257
|
-
state.result = "";
|
|
2258
|
-
state.position++;
|
|
2259
|
-
captureStart = captureEnd = state.position;
|
|
2260
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2261
|
-
if (ch === 34) {
|
|
2262
|
-
captureSegment(state, captureStart, state.position, true);
|
|
2263
|
-
state.position++;
|
|
2264
|
-
return true;
|
|
2265
|
-
} else if (ch === 92) {
|
|
2266
|
-
captureSegment(state, captureStart, state.position, true);
|
|
2267
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2268
|
-
if (is_EOL(ch)) {
|
|
2269
|
-
skipSeparationSpace(state, false, nodeIndent);
|
|
2270
|
-
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
2271
|
-
state.result += simpleEscapeMap[ch];
|
|
2272
|
-
state.position++;
|
|
2273
|
-
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
2274
|
-
hexLength = tmp;
|
|
2275
|
-
hexResult = 0;
|
|
2276
|
-
for (; hexLength > 0; hexLength--) {
|
|
2277
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2278
|
-
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
2279
|
-
hexResult = (hexResult << 4) + tmp;
|
|
2280
|
-
} else {
|
|
2281
|
-
throwError(state, "expected hexadecimal character");
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
state.result += charFromCodepoint(hexResult);
|
|
2285
|
-
state.position++;
|
|
2286
|
-
} else {
|
|
2287
|
-
throwError(state, "unknown escape sequence");
|
|
2288
|
-
}
|
|
2289
|
-
captureStart = captureEnd = state.position;
|
|
2290
|
-
} else if (is_EOL(ch)) {
|
|
2291
|
-
captureSegment(state, captureStart, captureEnd, true);
|
|
2292
|
-
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
2293
|
-
captureStart = captureEnd = state.position;
|
|
2294
|
-
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2295
|
-
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
2296
|
-
} else {
|
|
2297
|
-
state.position++;
|
|
2298
|
-
captureEnd = state.position;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
2302
|
-
}
|
|
2303
|
-
function readFlowCollection(state, nodeIndent) {
|
|
2304
|
-
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
2305
|
-
ch = state.input.charCodeAt(state.position);
|
|
2306
|
-
if (ch === 91) {
|
|
2307
|
-
terminator = 93;
|
|
2308
|
-
isMapping = false;
|
|
2309
|
-
_result = [];
|
|
2310
|
-
} else if (ch === 123) {
|
|
2311
|
-
terminator = 125;
|
|
2312
|
-
isMapping = true;
|
|
2313
|
-
_result = {};
|
|
2314
|
-
} else {
|
|
2315
|
-
return false;
|
|
2316
|
-
}
|
|
2317
|
-
if (state.anchor !== null) {
|
|
2318
|
-
state.anchorMap[state.anchor] = _result;
|
|
2319
|
-
}
|
|
2320
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2321
|
-
while (ch !== 0) {
|
|
2322
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
2323
|
-
ch = state.input.charCodeAt(state.position);
|
|
2324
|
-
if (ch === terminator) {
|
|
2325
|
-
state.position++;
|
|
2326
|
-
state.tag = _tag;
|
|
2327
|
-
state.anchor = _anchor;
|
|
2328
|
-
state.kind = isMapping ? "mapping" : "sequence";
|
|
2329
|
-
state.result = _result;
|
|
2330
|
-
return true;
|
|
2331
|
-
} else if (!readNext) {
|
|
2332
|
-
throwError(state, "missed comma between flow collection entries");
|
|
2333
|
-
} else if (ch === 44) {
|
|
2334
|
-
throwError(state, "expected the node content, but found ','");
|
|
2335
|
-
}
|
|
2336
|
-
keyTag = keyNode = valueNode = null;
|
|
2337
|
-
isPair = isExplicitPair = false;
|
|
2338
|
-
if (ch === 63) {
|
|
2339
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2340
|
-
if (is_WS_OR_EOL(following)) {
|
|
2341
|
-
isPair = isExplicitPair = true;
|
|
2342
|
-
state.position++;
|
|
2343
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
_line = state.line;
|
|
2347
|
-
_lineStart = state.lineStart;
|
|
2348
|
-
_pos = state.position;
|
|
2349
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2350
|
-
keyTag = state.tag;
|
|
2351
|
-
keyNode = state.result;
|
|
2352
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
2353
|
-
ch = state.input.charCodeAt(state.position);
|
|
2354
|
-
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
2355
|
-
isPair = true;
|
|
2356
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2357
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
2358
|
-
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2359
|
-
valueNode = state.result;
|
|
2360
|
-
}
|
|
2361
|
-
if (isMapping) {
|
|
2362
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
2363
|
-
} else if (isPair) {
|
|
2364
|
-
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
2365
|
-
} else {
|
|
2366
|
-
_result.push(keyNode);
|
|
2367
|
-
}
|
|
2368
|
-
skipSeparationSpace(state, true, nodeIndent);
|
|
2369
|
-
ch = state.input.charCodeAt(state.position);
|
|
2370
|
-
if (ch === 44) {
|
|
2371
|
-
readNext = true;
|
|
2372
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2373
|
-
} else {
|
|
2374
|
-
readNext = false;
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
throwError(state, "unexpected end of the stream within a flow collection");
|
|
2378
|
-
}
|
|
2379
|
-
function readBlockScalar(state, nodeIndent) {
|
|
2380
|
-
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
2381
|
-
ch = state.input.charCodeAt(state.position);
|
|
2382
|
-
if (ch === 124) {
|
|
2383
|
-
folding = false;
|
|
2384
|
-
} else if (ch === 62) {
|
|
2385
|
-
folding = true;
|
|
2386
|
-
} else {
|
|
2387
|
-
return false;
|
|
2388
|
-
}
|
|
2389
|
-
state.kind = "scalar";
|
|
2390
|
-
state.result = "";
|
|
2391
|
-
while (ch !== 0) {
|
|
2392
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2393
|
-
if (ch === 43 || ch === 45) {
|
|
2394
|
-
if (CHOMPING_CLIP === chomping) {
|
|
2395
|
-
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
2396
|
-
} else {
|
|
2397
|
-
throwError(state, "repeat of a chomping mode identifier");
|
|
2398
|
-
}
|
|
2399
|
-
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
2400
|
-
if (tmp === 0) {
|
|
2401
|
-
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
2402
|
-
} else if (!detectedIndent) {
|
|
2403
|
-
textIndent = nodeIndent + tmp - 1;
|
|
2404
|
-
detectedIndent = true;
|
|
2405
|
-
} else {
|
|
2406
|
-
throwError(state, "repeat of an indentation width identifier");
|
|
2407
|
-
}
|
|
2408
|
-
} else {
|
|
2409
|
-
break;
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
if (is_WHITE_SPACE(ch)) {
|
|
2413
|
-
do {
|
|
2414
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2415
|
-
} while (is_WHITE_SPACE(ch));
|
|
2416
|
-
if (ch === 35) {
|
|
2417
|
-
do {
|
|
2418
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2419
|
-
} while (!is_EOL(ch) && ch !== 0);
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
while (ch !== 0) {
|
|
2423
|
-
readLineBreak(state);
|
|
2424
|
-
state.lineIndent = 0;
|
|
2425
|
-
ch = state.input.charCodeAt(state.position);
|
|
2426
|
-
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
2427
|
-
state.lineIndent++;
|
|
2428
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2429
|
-
}
|
|
2430
|
-
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
2431
|
-
textIndent = state.lineIndent;
|
|
2432
|
-
}
|
|
2433
|
-
if (is_EOL(ch)) {
|
|
2434
|
-
emptyLines++;
|
|
2435
|
-
continue;
|
|
2436
|
-
}
|
|
2437
|
-
if (state.lineIndent < textIndent) {
|
|
2438
|
-
if (chomping === CHOMPING_KEEP) {
|
|
2439
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
2440
|
-
} else if (chomping === CHOMPING_CLIP) {
|
|
2441
|
-
if (didReadContent) {
|
|
2442
|
-
state.result += "\n";
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
break;
|
|
2446
|
-
}
|
|
2447
|
-
if (folding) {
|
|
2448
|
-
if (is_WHITE_SPACE(ch)) {
|
|
2449
|
-
atMoreIndented = true;
|
|
2450
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
2451
|
-
} else if (atMoreIndented) {
|
|
2452
|
-
atMoreIndented = false;
|
|
2453
|
-
state.result += common.repeat("\n", emptyLines + 1);
|
|
2454
|
-
} else if (emptyLines === 0) {
|
|
2455
|
-
if (didReadContent) {
|
|
2456
|
-
state.result += " ";
|
|
2457
|
-
}
|
|
2458
|
-
} else {
|
|
2459
|
-
state.result += common.repeat("\n", emptyLines);
|
|
2460
|
-
}
|
|
2461
|
-
} else {
|
|
2462
|
-
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
2463
|
-
}
|
|
2464
|
-
didReadContent = true;
|
|
2465
|
-
detectedIndent = true;
|
|
2466
|
-
emptyLines = 0;
|
|
2467
|
-
captureStart = state.position;
|
|
2468
|
-
while (!is_EOL(ch) && ch !== 0) {
|
|
2469
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2470
|
-
}
|
|
2471
|
-
captureSegment(state, captureStart, state.position, false);
|
|
2472
|
-
}
|
|
2473
|
-
return true;
|
|
2474
|
-
}
|
|
2475
|
-
function readBlockSequence(state, nodeIndent) {
|
|
2476
|
-
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
2477
|
-
if (state.firstTabInLine !== -1)
|
|
2478
|
-
return false;
|
|
2479
|
-
if (state.anchor !== null) {
|
|
2480
|
-
state.anchorMap[state.anchor] = _result;
|
|
2481
|
-
}
|
|
2482
|
-
ch = state.input.charCodeAt(state.position);
|
|
2483
|
-
while (ch !== 0) {
|
|
2484
|
-
if (state.firstTabInLine !== -1) {
|
|
2485
|
-
state.position = state.firstTabInLine;
|
|
2486
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
2487
|
-
}
|
|
2488
|
-
if (ch !== 45) {
|
|
2489
|
-
break;
|
|
2490
|
-
}
|
|
2491
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2492
|
-
if (!is_WS_OR_EOL(following)) {
|
|
2493
|
-
break;
|
|
2494
|
-
}
|
|
2495
|
-
detected = true;
|
|
2496
|
-
state.position++;
|
|
2497
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2498
|
-
if (state.lineIndent <= nodeIndent) {
|
|
2499
|
-
_result.push(null);
|
|
2500
|
-
ch = state.input.charCodeAt(state.position);
|
|
2501
|
-
continue;
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
_line = state.line;
|
|
2505
|
-
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2506
|
-
_result.push(state.result);
|
|
2507
|
-
skipSeparationSpace(state, true, -1);
|
|
2508
|
-
ch = state.input.charCodeAt(state.position);
|
|
2509
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2510
|
-
throwError(state, "bad indentation of a sequence entry");
|
|
2511
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
2512
|
-
break;
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
if (detected) {
|
|
2516
|
-
state.tag = _tag;
|
|
2517
|
-
state.anchor = _anchor;
|
|
2518
|
-
state.kind = "sequence";
|
|
2519
|
-
state.result = _result;
|
|
2520
|
-
return true;
|
|
2521
|
-
}
|
|
2522
|
-
return false;
|
|
2523
|
-
}
|
|
2524
|
-
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
2525
|
-
var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
2526
|
-
if (state.firstTabInLine !== -1)
|
|
2527
|
-
return false;
|
|
2528
|
-
if (state.anchor !== null) {
|
|
2529
|
-
state.anchorMap[state.anchor] = _result;
|
|
2530
|
-
}
|
|
2531
|
-
ch = state.input.charCodeAt(state.position);
|
|
2532
|
-
while (ch !== 0) {
|
|
2533
|
-
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
2534
|
-
state.position = state.firstTabInLine;
|
|
2535
|
-
throwError(state, "tab characters must not be used in indentation");
|
|
2536
|
-
}
|
|
2537
|
-
following = state.input.charCodeAt(state.position + 1);
|
|
2538
|
-
_line = state.line;
|
|
2539
|
-
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
2540
|
-
if (ch === 63) {
|
|
2541
|
-
if (atExplicitKey) {
|
|
2542
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2543
|
-
keyTag = keyNode = valueNode = null;
|
|
2544
|
-
}
|
|
2545
|
-
detected = true;
|
|
2546
|
-
atExplicitKey = true;
|
|
2547
|
-
allowCompact = true;
|
|
2548
|
-
} else if (atExplicitKey) {
|
|
2549
|
-
atExplicitKey = false;
|
|
2550
|
-
allowCompact = true;
|
|
2551
|
-
} else {
|
|
2552
|
-
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
2553
|
-
}
|
|
2554
|
-
state.position += 1;
|
|
2555
|
-
ch = following;
|
|
2556
|
-
} else {
|
|
2557
|
-
_keyLine = state.line;
|
|
2558
|
-
_keyLineStart = state.lineStart;
|
|
2559
|
-
_keyPos = state.position;
|
|
2560
|
-
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
2561
|
-
break;
|
|
2562
|
-
}
|
|
2563
|
-
if (state.line === _line) {
|
|
2564
|
-
ch = state.input.charCodeAt(state.position);
|
|
2565
|
-
while (is_WHITE_SPACE(ch)) {
|
|
2566
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2567
|
-
}
|
|
2568
|
-
if (ch === 58) {
|
|
2569
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2570
|
-
if (!is_WS_OR_EOL(ch)) {
|
|
2571
|
-
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2572
|
-
}
|
|
2573
|
-
if (atExplicitKey) {
|
|
2574
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2575
|
-
keyTag = keyNode = valueNode = null;
|
|
2576
|
-
}
|
|
2577
|
-
detected = true;
|
|
2578
|
-
atExplicitKey = false;
|
|
2579
|
-
allowCompact = false;
|
|
2580
|
-
keyTag = state.tag;
|
|
2581
|
-
keyNode = state.result;
|
|
2582
|
-
} else if (detected) {
|
|
2583
|
-
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
2584
|
-
} else {
|
|
2585
|
-
state.tag = _tag;
|
|
2586
|
-
state.anchor = _anchor;
|
|
2587
|
-
return true;
|
|
2588
|
-
}
|
|
2589
|
-
} else if (detected) {
|
|
2590
|
-
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2591
|
-
} else {
|
|
2592
|
-
state.tag = _tag;
|
|
2593
|
-
state.anchor = _anchor;
|
|
2594
|
-
return true;
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
2598
|
-
if (atExplicitKey) {
|
|
2599
|
-
_keyLine = state.line;
|
|
2600
|
-
_keyLineStart = state.lineStart;
|
|
2601
|
-
_keyPos = state.position;
|
|
2602
|
-
}
|
|
2603
|
-
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
2604
|
-
if (atExplicitKey) {
|
|
2605
|
-
keyNode = state.result;
|
|
2606
|
-
} else {
|
|
2607
|
-
valueNode = state.result;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
if (!atExplicitKey) {
|
|
2611
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
2612
|
-
keyTag = keyNode = valueNode = null;
|
|
2613
|
-
}
|
|
2614
|
-
skipSeparationSpace(state, true, -1);
|
|
2615
|
-
ch = state.input.charCodeAt(state.position);
|
|
2616
|
-
}
|
|
2617
|
-
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
2618
|
-
throwError(state, "bad indentation of a mapping entry");
|
|
2619
|
-
} else if (state.lineIndent < nodeIndent) {
|
|
2620
|
-
break;
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
if (atExplicitKey) {
|
|
2624
|
-
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
2625
|
-
}
|
|
2626
|
-
if (detected) {
|
|
2627
|
-
state.tag = _tag;
|
|
2628
|
-
state.anchor = _anchor;
|
|
2629
|
-
state.kind = "mapping";
|
|
2630
|
-
state.result = _result;
|
|
2631
|
-
}
|
|
2632
|
-
return detected;
|
|
2633
|
-
}
|
|
2634
|
-
function readTagProperty(state) {
|
|
2635
|
-
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
2636
|
-
ch = state.input.charCodeAt(state.position);
|
|
2637
|
-
if (ch !== 33)
|
|
2638
|
-
return false;
|
|
2639
|
-
if (state.tag !== null) {
|
|
2640
|
-
throwError(state, "duplication of a tag property");
|
|
2641
|
-
}
|
|
2642
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2643
|
-
if (ch === 60) {
|
|
2644
|
-
isVerbatim = true;
|
|
2645
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2646
|
-
} else if (ch === 33) {
|
|
2647
|
-
isNamed = true;
|
|
2648
|
-
tagHandle = "!!";
|
|
2649
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2650
|
-
} else {
|
|
2651
|
-
tagHandle = "!";
|
|
2652
|
-
}
|
|
2653
|
-
_position = state.position;
|
|
2654
|
-
if (isVerbatim) {
|
|
2655
|
-
do {
|
|
2656
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2657
|
-
} while (ch !== 0 && ch !== 62);
|
|
2658
|
-
if (state.position < state.length) {
|
|
2659
|
-
tagName = state.input.slice(_position, state.position);
|
|
2660
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2661
|
-
} else {
|
|
2662
|
-
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2663
|
-
}
|
|
2664
|
-
} else {
|
|
2665
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2666
|
-
if (ch === 33) {
|
|
2667
|
-
if (!isNamed) {
|
|
2668
|
-
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
2669
|
-
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
2670
|
-
throwError(state, "named tag handle cannot contain such characters");
|
|
2671
|
-
}
|
|
2672
|
-
isNamed = true;
|
|
2673
|
-
_position = state.position + 1;
|
|
2674
|
-
} else {
|
|
2675
|
-
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2679
|
-
}
|
|
2680
|
-
tagName = state.input.slice(_position, state.position);
|
|
2681
|
-
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
2682
|
-
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
2686
|
-
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
2687
|
-
}
|
|
2688
|
-
try {
|
|
2689
|
-
tagName = decodeURIComponent(tagName);
|
|
2690
|
-
} catch (err) {
|
|
2691
|
-
throwError(state, "tag name is malformed: " + tagName);
|
|
2692
|
-
}
|
|
2693
|
-
if (isVerbatim) {
|
|
2694
|
-
state.tag = tagName;
|
|
2695
|
-
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
2696
|
-
state.tag = state.tagMap[tagHandle] + tagName;
|
|
2697
|
-
} else if (tagHandle === "!") {
|
|
2698
|
-
state.tag = "!" + tagName;
|
|
2699
|
-
} else if (tagHandle === "!!") {
|
|
2700
|
-
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
2701
|
-
} else {
|
|
2702
|
-
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
2703
|
-
}
|
|
2704
|
-
return true;
|
|
2705
|
-
}
|
|
2706
|
-
function readAnchorProperty(state) {
|
|
2707
|
-
var _position, ch;
|
|
2708
|
-
ch = state.input.charCodeAt(state.position);
|
|
2709
|
-
if (ch !== 38)
|
|
2710
|
-
return false;
|
|
2711
|
-
if (state.anchor !== null) {
|
|
2712
|
-
throwError(state, "duplication of an anchor property");
|
|
2713
|
-
}
|
|
2714
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2715
|
-
_position = state.position;
|
|
2716
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2717
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2718
|
-
}
|
|
2719
|
-
if (state.position === _position) {
|
|
2720
|
-
throwError(state, "name of an anchor node must contain at least one character");
|
|
2721
|
-
}
|
|
2722
|
-
state.anchor = state.input.slice(_position, state.position);
|
|
2723
|
-
return true;
|
|
2724
|
-
}
|
|
2725
|
-
function readAlias(state) {
|
|
2726
|
-
var _position, alias, ch;
|
|
2727
|
-
ch = state.input.charCodeAt(state.position);
|
|
2728
|
-
if (ch !== 42)
|
|
2729
|
-
return false;
|
|
2730
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2731
|
-
_position = state.position;
|
|
2732
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2733
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2734
|
-
}
|
|
2735
|
-
if (state.position === _position) {
|
|
2736
|
-
throwError(state, "name of an alias node must contain at least one character");
|
|
2737
|
-
}
|
|
2738
|
-
alias = state.input.slice(_position, state.position);
|
|
2739
|
-
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
2740
|
-
throwError(state, 'unidentified alias "' + alias + '"');
|
|
2741
|
-
}
|
|
2742
|
-
state.result = state.anchorMap[alias];
|
|
2743
|
-
skipSeparationSpace(state, true, -1);
|
|
2744
|
-
return true;
|
|
2745
|
-
}
|
|
2746
|
-
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
2747
|
-
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
2748
|
-
if (state.listener !== null) {
|
|
2749
|
-
state.listener("open", state);
|
|
2750
|
-
}
|
|
2751
|
-
state.tag = null;
|
|
2752
|
-
state.anchor = null;
|
|
2753
|
-
state.kind = null;
|
|
2754
|
-
state.result = null;
|
|
2755
|
-
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
2756
|
-
if (allowToSeek) {
|
|
2757
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2758
|
-
atNewLine = true;
|
|
2759
|
-
if (state.lineIndent > parentIndent) {
|
|
2760
|
-
indentStatus = 1;
|
|
2761
|
-
} else if (state.lineIndent === parentIndent) {
|
|
2762
|
-
indentStatus = 0;
|
|
2763
|
-
} else if (state.lineIndent < parentIndent) {
|
|
2764
|
-
indentStatus = -1;
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
if (indentStatus === 1) {
|
|
2769
|
-
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
2770
|
-
if (skipSeparationSpace(state, true, -1)) {
|
|
2771
|
-
atNewLine = true;
|
|
2772
|
-
allowBlockCollections = allowBlockStyles;
|
|
2773
|
-
if (state.lineIndent > parentIndent) {
|
|
2774
|
-
indentStatus = 1;
|
|
2775
|
-
} else if (state.lineIndent === parentIndent) {
|
|
2776
|
-
indentStatus = 0;
|
|
2777
|
-
} else if (state.lineIndent < parentIndent) {
|
|
2778
|
-
indentStatus = -1;
|
|
2779
|
-
}
|
|
2780
|
-
} else {
|
|
2781
|
-
allowBlockCollections = false;
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
if (allowBlockCollections) {
|
|
2786
|
-
allowBlockCollections = atNewLine || allowCompact;
|
|
2787
|
-
}
|
|
2788
|
-
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
2789
|
-
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
2790
|
-
flowIndent = parentIndent;
|
|
2791
|
-
} else {
|
|
2792
|
-
flowIndent = parentIndent + 1;
|
|
2793
|
-
}
|
|
2794
|
-
blockIndent = state.position - state.lineStart;
|
|
2795
|
-
if (indentStatus === 1) {
|
|
2796
|
-
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
2797
|
-
hasContent = true;
|
|
2798
|
-
} else {
|
|
2799
|
-
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
2800
|
-
hasContent = true;
|
|
2801
|
-
} else if (readAlias(state)) {
|
|
2802
|
-
hasContent = true;
|
|
2803
|
-
if (state.tag !== null || state.anchor !== null) {
|
|
2804
|
-
throwError(state, "alias node should not have any properties");
|
|
2805
|
-
}
|
|
2806
|
-
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
2807
|
-
hasContent = true;
|
|
2808
|
-
if (state.tag === null) {
|
|
2809
|
-
state.tag = "?";
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
if (state.anchor !== null) {
|
|
2813
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2814
|
-
}
|
|
2815
|
-
}
|
|
2816
|
-
} else if (indentStatus === 0) {
|
|
2817
|
-
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
if (state.tag === null) {
|
|
2821
|
-
if (state.anchor !== null) {
|
|
2822
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2823
|
-
}
|
|
2824
|
-
} else if (state.tag === "?") {
|
|
2825
|
-
if (state.result !== null && state.kind !== "scalar") {
|
|
2826
|
-
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
2827
|
-
}
|
|
2828
|
-
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
2829
|
-
type2 = state.implicitTypes[typeIndex];
|
|
2830
|
-
if (type2.resolve(state.result)) {
|
|
2831
|
-
state.result = type2.construct(state.result);
|
|
2832
|
-
state.tag = type2.tag;
|
|
2833
|
-
if (state.anchor !== null) {
|
|
2834
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2835
|
-
}
|
|
2836
|
-
break;
|
|
2837
|
-
}
|
|
2838
|
-
}
|
|
2839
|
-
} else if (state.tag !== "!") {
|
|
2840
|
-
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
2841
|
-
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
2842
|
-
} else {
|
|
2843
|
-
type2 = null;
|
|
2844
|
-
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
2845
|
-
for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
2846
|
-
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
2847
|
-
type2 = typeList[typeIndex];
|
|
2848
|
-
break;
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
if (!type2) {
|
|
2853
|
-
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
2854
|
-
}
|
|
2855
|
-
if (state.result !== null && type2.kind !== state.kind) {
|
|
2856
|
-
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
2857
|
-
}
|
|
2858
|
-
if (!type2.resolve(state.result, state.tag)) {
|
|
2859
|
-
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
2860
|
-
} else {
|
|
2861
|
-
state.result = type2.construct(state.result, state.tag);
|
|
2862
|
-
if (state.anchor !== null) {
|
|
2863
|
-
state.anchorMap[state.anchor] = state.result;
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
}
|
|
2867
|
-
if (state.listener !== null) {
|
|
2868
|
-
state.listener("close", state);
|
|
2869
|
-
}
|
|
2870
|
-
return state.tag !== null || state.anchor !== null || hasContent;
|
|
2871
|
-
}
|
|
2872
|
-
function readDocument(state) {
|
|
2873
|
-
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
2874
|
-
state.version = null;
|
|
2875
|
-
state.checkLineBreaks = state.legacy;
|
|
2876
|
-
state.tagMap = /* @__PURE__ */ Object.create(null);
|
|
2877
|
-
state.anchorMap = /* @__PURE__ */ Object.create(null);
|
|
2878
|
-
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2879
|
-
skipSeparationSpace(state, true, -1);
|
|
2880
|
-
ch = state.input.charCodeAt(state.position);
|
|
2881
|
-
if (state.lineIndent > 0 || ch !== 37) {
|
|
2882
|
-
break;
|
|
2883
|
-
}
|
|
2884
|
-
hasDirectives = true;
|
|
2885
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2886
|
-
_position = state.position;
|
|
2887
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2888
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2889
|
-
}
|
|
2890
|
-
directiveName = state.input.slice(_position, state.position);
|
|
2891
|
-
directiveArgs = [];
|
|
2892
|
-
if (directiveName.length < 1) {
|
|
2893
|
-
throwError(state, "directive name must not be less than one character in length");
|
|
2894
|
-
}
|
|
2895
|
-
while (ch !== 0) {
|
|
2896
|
-
while (is_WHITE_SPACE(ch)) {
|
|
2897
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2898
|
-
}
|
|
2899
|
-
if (ch === 35) {
|
|
2900
|
-
do {
|
|
2901
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2902
|
-
} while (ch !== 0 && !is_EOL(ch));
|
|
2903
|
-
break;
|
|
2904
|
-
}
|
|
2905
|
-
if (is_EOL(ch))
|
|
2906
|
-
break;
|
|
2907
|
-
_position = state.position;
|
|
2908
|
-
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2909
|
-
ch = state.input.charCodeAt(++state.position);
|
|
2910
|
-
}
|
|
2911
|
-
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2912
|
-
}
|
|
2913
|
-
if (ch !== 0)
|
|
2914
|
-
readLineBreak(state);
|
|
2915
|
-
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
2916
|
-
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2917
|
-
} else {
|
|
2918
|
-
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
skipSeparationSpace(state, true, -1);
|
|
2922
|
-
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2923
|
-
state.position += 3;
|
|
2924
|
-
skipSeparationSpace(state, true, -1);
|
|
2925
|
-
} else if (hasDirectives) {
|
|
2926
|
-
throwError(state, "directives end mark is expected");
|
|
2927
|
-
}
|
|
2928
|
-
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2929
|
-
skipSeparationSpace(state, true, -1);
|
|
2930
|
-
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2931
|
-
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2932
|
-
}
|
|
2933
|
-
state.documents.push(state.result);
|
|
2934
|
-
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2935
|
-
if (state.input.charCodeAt(state.position) === 46) {
|
|
2936
|
-
state.position += 3;
|
|
2937
|
-
skipSeparationSpace(state, true, -1);
|
|
2938
|
-
}
|
|
2939
|
-
return;
|
|
2940
|
-
}
|
|
2941
|
-
if (state.position < state.length - 1) {
|
|
2942
|
-
throwError(state, "end of the stream or a document separator is expected");
|
|
2943
|
-
} else {
|
|
2944
|
-
return;
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
function loadDocuments(input, options) {
|
|
2948
|
-
input = String(input);
|
|
2949
|
-
options = options || {};
|
|
2950
|
-
if (input.length !== 0) {
|
|
2951
|
-
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2952
|
-
input += "\n";
|
|
2953
|
-
}
|
|
2954
|
-
if (input.charCodeAt(0) === 65279) {
|
|
2955
|
-
input = input.slice(1);
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
var state = new State$1(input, options);
|
|
2959
|
-
var nullpos = input.indexOf("\0");
|
|
2960
|
-
if (nullpos !== -1) {
|
|
2961
|
-
state.position = nullpos;
|
|
2962
|
-
throwError(state, "null byte is not allowed in input");
|
|
2963
|
-
}
|
|
2964
|
-
state.input += "\0";
|
|
2965
|
-
while (state.input.charCodeAt(state.position) === 32) {
|
|
2966
|
-
state.lineIndent += 1;
|
|
2967
|
-
state.position += 1;
|
|
2968
|
-
}
|
|
2969
|
-
while (state.position < state.length - 1) {
|
|
2970
|
-
readDocument(state);
|
|
2971
|
-
}
|
|
2972
|
-
return state.documents;
|
|
2973
|
-
}
|
|
2974
|
-
function loadAll$1(input, iterator, options) {
|
|
2975
|
-
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2976
|
-
options = iterator;
|
|
2977
|
-
iterator = null;
|
|
2978
|
-
}
|
|
2979
|
-
var documents = loadDocuments(input, options);
|
|
2980
|
-
if (typeof iterator !== "function") {
|
|
2981
|
-
return documents;
|
|
2982
|
-
}
|
|
2983
|
-
for (var index = 0, length = documents.length; index < length; index += 1) {
|
|
2984
|
-
iterator(documents[index]);
|
|
2985
|
-
}
|
|
2986
|
-
}
|
|
2987
|
-
function load$1(input, options) {
|
|
2988
|
-
var documents = loadDocuments(input, options);
|
|
2989
|
-
if (documents.length === 0) {
|
|
2990
|
-
return void 0;
|
|
2991
|
-
} else if (documents.length === 1) {
|
|
2992
|
-
return documents[0];
|
|
2993
|
-
}
|
|
2994
|
-
throw new exception("expected a single document in the stream, but found more");
|
|
2995
|
-
}
|
|
2996
|
-
var loadAll_1 = loadAll$1;
|
|
2997
|
-
var load_1 = load$1;
|
|
2998
|
-
var loader = {
|
|
2999
|
-
loadAll: loadAll_1,
|
|
3000
|
-
load: load_1
|
|
3001
|
-
};
|
|
3002
|
-
var _toString = Object.prototype.toString;
|
|
3003
|
-
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3004
|
-
var CHAR_BOM = 65279;
|
|
3005
|
-
var CHAR_TAB = 9;
|
|
3006
|
-
var CHAR_LINE_FEED = 10;
|
|
3007
|
-
var CHAR_CARRIAGE_RETURN = 13;
|
|
3008
|
-
var CHAR_SPACE = 32;
|
|
3009
|
-
var CHAR_EXCLAMATION = 33;
|
|
3010
|
-
var CHAR_DOUBLE_QUOTE = 34;
|
|
3011
|
-
var CHAR_SHARP = 35;
|
|
3012
|
-
var CHAR_PERCENT = 37;
|
|
3013
|
-
var CHAR_AMPERSAND = 38;
|
|
3014
|
-
var CHAR_SINGLE_QUOTE = 39;
|
|
3015
|
-
var CHAR_ASTERISK = 42;
|
|
3016
|
-
var CHAR_COMMA = 44;
|
|
3017
|
-
var CHAR_MINUS = 45;
|
|
3018
|
-
var CHAR_COLON = 58;
|
|
3019
|
-
var CHAR_EQUALS = 61;
|
|
3020
|
-
var CHAR_GREATER_THAN = 62;
|
|
3021
|
-
var CHAR_QUESTION = 63;
|
|
3022
|
-
var CHAR_COMMERCIAL_AT = 64;
|
|
3023
|
-
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
3024
|
-
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
3025
|
-
var CHAR_GRAVE_ACCENT = 96;
|
|
3026
|
-
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
3027
|
-
var CHAR_VERTICAL_LINE = 124;
|
|
3028
|
-
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
3029
|
-
var ESCAPE_SEQUENCES = {};
|
|
3030
|
-
ESCAPE_SEQUENCES[0] = "\\0";
|
|
3031
|
-
ESCAPE_SEQUENCES[7] = "\\a";
|
|
3032
|
-
ESCAPE_SEQUENCES[8] = "\\b";
|
|
3033
|
-
ESCAPE_SEQUENCES[9] = "\\t";
|
|
3034
|
-
ESCAPE_SEQUENCES[10] = "\\n";
|
|
3035
|
-
ESCAPE_SEQUENCES[11] = "\\v";
|
|
3036
|
-
ESCAPE_SEQUENCES[12] = "\\f";
|
|
3037
|
-
ESCAPE_SEQUENCES[13] = "\\r";
|
|
3038
|
-
ESCAPE_SEQUENCES[27] = "\\e";
|
|
3039
|
-
ESCAPE_SEQUENCES[34] = '\\"';
|
|
3040
|
-
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
3041
|
-
ESCAPE_SEQUENCES[133] = "\\N";
|
|
3042
|
-
ESCAPE_SEQUENCES[160] = "\\_";
|
|
3043
|
-
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
3044
|
-
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
3045
|
-
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
3046
|
-
"y",
|
|
3047
|
-
"Y",
|
|
3048
|
-
"yes",
|
|
3049
|
-
"Yes",
|
|
3050
|
-
"YES",
|
|
3051
|
-
"on",
|
|
3052
|
-
"On",
|
|
3053
|
-
"ON",
|
|
3054
|
-
"n",
|
|
3055
|
-
"N",
|
|
3056
|
-
"no",
|
|
3057
|
-
"No",
|
|
3058
|
-
"NO",
|
|
3059
|
-
"off",
|
|
3060
|
-
"Off",
|
|
3061
|
-
"OFF"
|
|
3062
|
-
];
|
|
3063
|
-
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
3064
|
-
function compileStyleMap(schema2, map2) {
|
|
3065
|
-
var result, keys, index, length, tag, style, type2;
|
|
3066
|
-
if (map2 === null)
|
|
3067
|
-
return {};
|
|
3068
|
-
result = {};
|
|
3069
|
-
keys = Object.keys(map2);
|
|
3070
|
-
for (index = 0, length = keys.length; index < length; index += 1) {
|
|
3071
|
-
tag = keys[index];
|
|
3072
|
-
style = String(map2[tag]);
|
|
3073
|
-
if (tag.slice(0, 2) === "!!") {
|
|
3074
|
-
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
3075
|
-
}
|
|
3076
|
-
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
3077
|
-
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
3078
|
-
style = type2.styleAliases[style];
|
|
3079
|
-
}
|
|
3080
|
-
result[tag] = style;
|
|
3081
|
-
}
|
|
3082
|
-
return result;
|
|
3083
|
-
}
|
|
3084
|
-
function encodeHex(character) {
|
|
3085
|
-
var string, handle, length;
|
|
3086
|
-
string = character.toString(16).toUpperCase();
|
|
3087
|
-
if (character <= 255) {
|
|
3088
|
-
handle = "x";
|
|
3089
|
-
length = 2;
|
|
3090
|
-
} else if (character <= 65535) {
|
|
3091
|
-
handle = "u";
|
|
3092
|
-
length = 4;
|
|
3093
|
-
} else if (character <= 4294967295) {
|
|
3094
|
-
handle = "U";
|
|
3095
|
-
length = 8;
|
|
3096
|
-
} else {
|
|
3097
|
-
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
3098
|
-
}
|
|
3099
|
-
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
3100
|
-
}
|
|
3101
|
-
var QUOTING_TYPE_SINGLE = 1;
|
|
3102
|
-
var QUOTING_TYPE_DOUBLE = 2;
|
|
3103
|
-
function State(options) {
|
|
3104
|
-
this.schema = options["schema"] || _default;
|
|
3105
|
-
this.indent = Math.max(1, options["indent"] || 2);
|
|
3106
|
-
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
3107
|
-
this.skipInvalid = options["skipInvalid"] || false;
|
|
3108
|
-
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
3109
|
-
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
3110
|
-
this.sortKeys = options["sortKeys"] || false;
|
|
3111
|
-
this.lineWidth = options["lineWidth"] || 80;
|
|
3112
|
-
this.noRefs = options["noRefs"] || false;
|
|
3113
|
-
this.noCompatMode = options["noCompatMode"] || false;
|
|
3114
|
-
this.condenseFlow = options["condenseFlow"] || false;
|
|
3115
|
-
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
3116
|
-
this.forceQuotes = options["forceQuotes"] || false;
|
|
3117
|
-
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
3118
|
-
this.implicitTypes = this.schema.compiledImplicit;
|
|
3119
|
-
this.explicitTypes = this.schema.compiledExplicit;
|
|
3120
|
-
this.tag = null;
|
|
3121
|
-
this.result = "";
|
|
3122
|
-
this.duplicates = [];
|
|
3123
|
-
this.usedDuplicates = null;
|
|
3124
|
-
}
|
|
3125
|
-
function indentString(string, spaces) {
|
|
3126
|
-
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
3127
|
-
while (position < length) {
|
|
3128
|
-
next = string.indexOf("\n", position);
|
|
3129
|
-
if (next === -1) {
|
|
3130
|
-
line = string.slice(position);
|
|
3131
|
-
position = length;
|
|
3132
|
-
} else {
|
|
3133
|
-
line = string.slice(position, next + 1);
|
|
3134
|
-
position = next + 1;
|
|
3135
|
-
}
|
|
3136
|
-
if (line.length && line !== "\n")
|
|
3137
|
-
result += ind;
|
|
3138
|
-
result += line;
|
|
3139
|
-
}
|
|
3140
|
-
return result;
|
|
3141
|
-
}
|
|
3142
|
-
function generateNextLine(state, level) {
|
|
3143
|
-
return "\n" + common.repeat(" ", state.indent * level);
|
|
3144
|
-
}
|
|
3145
|
-
function testImplicitResolving(state, str2) {
|
|
3146
|
-
var index, length, type2;
|
|
3147
|
-
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
|
3148
|
-
type2 = state.implicitTypes[index];
|
|
3149
|
-
if (type2.resolve(str2)) {
|
|
3150
|
-
return true;
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
return false;
|
|
3154
|
-
}
|
|
3155
|
-
function isWhitespace(c) {
|
|
3156
|
-
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
3157
|
-
}
|
|
3158
|
-
function isPrintable(c) {
|
|
3159
|
-
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
3160
|
-
}
|
|
3161
|
-
function isNsCharOrWhitespace(c) {
|
|
3162
|
-
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
3163
|
-
}
|
|
3164
|
-
function isPlainSafe(c, prev, inblock) {
|
|
3165
|
-
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
3166
|
-
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
3167
|
-
return (
|
|
3168
|
-
// ns-plain-safe
|
|
3169
|
-
(inblock ? (
|
|
3170
|
-
// c = flow-in
|
|
3171
|
-
cIsNsCharOrWhitespace
|
|
3172
|
-
) : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar
|
|
3173
|
-
);
|
|
3174
|
-
}
|
|
3175
|
-
function isPlainSafeFirst(c) {
|
|
3176
|
-
return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
3177
|
-
}
|
|
3178
|
-
function isPlainSafeLast(c) {
|
|
3179
|
-
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
3180
|
-
}
|
|
3181
|
-
function codePointAt(string, pos) {
|
|
3182
|
-
var first = string.charCodeAt(pos), second;
|
|
3183
|
-
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
3184
|
-
second = string.charCodeAt(pos + 1);
|
|
3185
|
-
if (second >= 56320 && second <= 57343) {
|
|
3186
|
-
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
3187
|
-
}
|
|
3188
|
-
}
|
|
3189
|
-
return first;
|
|
3190
|
-
}
|
|
3191
|
-
function needIndentIndicator(string) {
|
|
3192
|
-
var leadingSpaceRe = /^\n* /;
|
|
3193
|
-
return leadingSpaceRe.test(string);
|
|
3194
|
-
}
|
|
3195
|
-
var STYLE_PLAIN = 1;
|
|
3196
|
-
var STYLE_SINGLE = 2;
|
|
3197
|
-
var STYLE_LITERAL = 3;
|
|
3198
|
-
var STYLE_FOLDED = 4;
|
|
3199
|
-
var STYLE_DOUBLE = 5;
|
|
3200
|
-
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
3201
|
-
var i;
|
|
3202
|
-
var char = 0;
|
|
3203
|
-
var prevChar = null;
|
|
3204
|
-
var hasLineBreak = false;
|
|
3205
|
-
var hasFoldableLine = false;
|
|
3206
|
-
var shouldTrackWidth = lineWidth !== -1;
|
|
3207
|
-
var previousLineBreak = -1;
|
|
3208
|
-
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
3209
|
-
if (singleLineOnly || forceQuotes) {
|
|
3210
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
3211
|
-
char = codePointAt(string, i);
|
|
3212
|
-
if (!isPrintable(char)) {
|
|
3213
|
-
return STYLE_DOUBLE;
|
|
3214
|
-
}
|
|
3215
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
3216
|
-
prevChar = char;
|
|
3217
|
-
}
|
|
3218
|
-
} else {
|
|
3219
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
3220
|
-
char = codePointAt(string, i);
|
|
3221
|
-
if (char === CHAR_LINE_FEED) {
|
|
3222
|
-
hasLineBreak = true;
|
|
3223
|
-
if (shouldTrackWidth) {
|
|
3224
|
-
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
3225
|
-
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
3226
|
-
previousLineBreak = i;
|
|
3227
|
-
}
|
|
3228
|
-
} else if (!isPrintable(char)) {
|
|
3229
|
-
return STYLE_DOUBLE;
|
|
3230
|
-
}
|
|
3231
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
3232
|
-
prevChar = char;
|
|
3233
|
-
}
|
|
3234
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
3235
|
-
}
|
|
3236
|
-
if (!hasLineBreak && !hasFoldableLine) {
|
|
3237
|
-
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
3238
|
-
return STYLE_PLAIN;
|
|
3239
|
-
}
|
|
3240
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
3241
|
-
}
|
|
3242
|
-
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
3243
|
-
return STYLE_DOUBLE;
|
|
3244
|
-
}
|
|
3245
|
-
if (!forceQuotes) {
|
|
3246
|
-
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
3247
|
-
}
|
|
3248
|
-
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
3249
|
-
}
|
|
3250
|
-
function writeScalar(state, string, level, iskey, inblock) {
|
|
3251
|
-
state.dump = function() {
|
|
3252
|
-
if (string.length === 0) {
|
|
3253
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
3254
|
-
}
|
|
3255
|
-
if (!state.noCompatMode) {
|
|
3256
|
-
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
3257
|
-
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
3258
|
-
}
|
|
3259
|
-
}
|
|
3260
|
-
var indent = state.indent * Math.max(1, level);
|
|
3261
|
-
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
3262
|
-
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
3263
|
-
function testAmbiguity(string2) {
|
|
3264
|
-
return testImplicitResolving(state, string2);
|
|
3265
|
-
}
|
|
3266
|
-
switch (chooseScalarStyle(
|
|
3267
|
-
string,
|
|
3268
|
-
singleLineOnly,
|
|
3269
|
-
state.indent,
|
|
3270
|
-
lineWidth,
|
|
3271
|
-
testAmbiguity,
|
|
3272
|
-
state.quotingType,
|
|
3273
|
-
state.forceQuotes && !iskey,
|
|
3274
|
-
inblock
|
|
3275
|
-
)) {
|
|
3276
|
-
case STYLE_PLAIN:
|
|
3277
|
-
return string;
|
|
3278
|
-
case STYLE_SINGLE:
|
|
3279
|
-
return "'" + string.replace(/'/g, "''") + "'";
|
|
3280
|
-
case STYLE_LITERAL:
|
|
3281
|
-
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
3282
|
-
case STYLE_FOLDED:
|
|
3283
|
-
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
3284
|
-
case STYLE_DOUBLE:
|
|
3285
|
-
return '"' + escapeString(string) + '"';
|
|
3286
|
-
default:
|
|
3287
|
-
throw new exception("impossible error: invalid scalar style");
|
|
3288
|
-
}
|
|
3289
|
-
}();
|
|
3290
|
-
}
|
|
3291
|
-
function blockHeader(string, indentPerLevel) {
|
|
3292
|
-
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
3293
|
-
var clip = string[string.length - 1] === "\n";
|
|
3294
|
-
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
3295
|
-
var chomp = keep ? "+" : clip ? "" : "-";
|
|
3296
|
-
return indentIndicator + chomp + "\n";
|
|
3297
|
-
}
|
|
3298
|
-
function dropEndingNewline(string) {
|
|
3299
|
-
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
3300
|
-
}
|
|
3301
|
-
function foldString(string, width) {
|
|
3302
|
-
var lineRe = /(\n+)([^\n]*)/g;
|
|
3303
|
-
var result = function() {
|
|
3304
|
-
var nextLF = string.indexOf("\n");
|
|
3305
|
-
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
3306
|
-
lineRe.lastIndex = nextLF;
|
|
3307
|
-
return foldLine(string.slice(0, nextLF), width);
|
|
3308
|
-
}();
|
|
3309
|
-
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
3310
|
-
var moreIndented;
|
|
3311
|
-
var match;
|
|
3312
|
-
while (match = lineRe.exec(string)) {
|
|
3313
|
-
var prefix = match[1], line = match[2];
|
|
3314
|
-
moreIndented = line[0] === " ";
|
|
3315
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
3316
|
-
prevMoreIndented = moreIndented;
|
|
3317
|
-
}
|
|
3318
|
-
return result;
|
|
3319
|
-
}
|
|
3320
|
-
function foldLine(line, width) {
|
|
3321
|
-
if (line === "" || line[0] === " ")
|
|
3322
|
-
return line;
|
|
3323
|
-
var breakRe = / [^ ]/g;
|
|
3324
|
-
var match;
|
|
3325
|
-
var start = 0, end, curr = 0, next = 0;
|
|
3326
|
-
var result = "";
|
|
3327
|
-
while (match = breakRe.exec(line)) {
|
|
3328
|
-
next = match.index;
|
|
3329
|
-
if (next - start > width) {
|
|
3330
|
-
end = curr > start ? curr : next;
|
|
3331
|
-
result += "\n" + line.slice(start, end);
|
|
3332
|
-
start = end + 1;
|
|
3333
|
-
}
|
|
3334
|
-
curr = next;
|
|
3335
|
-
}
|
|
3336
|
-
result += "\n";
|
|
3337
|
-
if (line.length - start > width && curr > start) {
|
|
3338
|
-
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
3339
|
-
} else {
|
|
3340
|
-
result += line.slice(start);
|
|
3341
|
-
}
|
|
3342
|
-
return result.slice(1);
|
|
3343
|
-
}
|
|
3344
|
-
function escapeString(string) {
|
|
3345
|
-
var result = "";
|
|
3346
|
-
var char = 0;
|
|
3347
|
-
var escapeSeq;
|
|
3348
|
-
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
3349
|
-
char = codePointAt(string, i);
|
|
3350
|
-
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
3351
|
-
if (!escapeSeq && isPrintable(char)) {
|
|
3352
|
-
result += string[i];
|
|
3353
|
-
if (char >= 65536)
|
|
3354
|
-
result += string[i + 1];
|
|
3355
|
-
} else {
|
|
3356
|
-
result += escapeSeq || encodeHex(char);
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
return result;
|
|
3360
|
-
}
|
|
3361
|
-
function writeFlowSequence(state, level, object) {
|
|
3362
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
3363
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
3364
|
-
value = object[index];
|
|
3365
|
-
if (state.replacer) {
|
|
3366
|
-
value = state.replacer.call(object, String(index), value);
|
|
3367
|
-
}
|
|
3368
|
-
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
3369
|
-
if (_result !== "")
|
|
3370
|
-
_result += "," + (!state.condenseFlow ? " " : "");
|
|
3371
|
-
_result += state.dump;
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
state.tag = _tag;
|
|
3375
|
-
state.dump = "[" + _result + "]";
|
|
3376
|
-
}
|
|
3377
|
-
function writeBlockSequence(state, level, object, compact) {
|
|
3378
|
-
var _result = "", _tag = state.tag, index, length, value;
|
|
3379
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
3380
|
-
value = object[index];
|
|
3381
|
-
if (state.replacer) {
|
|
3382
|
-
value = state.replacer.call(object, String(index), value);
|
|
3383
|
-
}
|
|
3384
|
-
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
3385
|
-
if (!compact || _result !== "") {
|
|
3386
|
-
_result += generateNextLine(state, level);
|
|
3387
|
-
}
|
|
3388
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
3389
|
-
_result += "-";
|
|
3390
|
-
} else {
|
|
3391
|
-
_result += "- ";
|
|
3392
|
-
}
|
|
3393
|
-
_result += state.dump;
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
state.tag = _tag;
|
|
3397
|
-
state.dump = _result || "[]";
|
|
3398
|
-
}
|
|
3399
|
-
function writeFlowMapping(state, level, object) {
|
|
3400
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
3401
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
3402
|
-
pairBuffer = "";
|
|
3403
|
-
if (_result !== "")
|
|
3404
|
-
pairBuffer += ", ";
|
|
3405
|
-
if (state.condenseFlow)
|
|
3406
|
-
pairBuffer += '"';
|
|
3407
|
-
objectKey = objectKeyList[index];
|
|
3408
|
-
objectValue = object[objectKey];
|
|
3409
|
-
if (state.replacer) {
|
|
3410
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
3411
|
-
}
|
|
3412
|
-
if (!writeNode(state, level, objectKey, false, false)) {
|
|
3413
|
-
continue;
|
|
3414
|
-
}
|
|
3415
|
-
if (state.dump.length > 1024)
|
|
3416
|
-
pairBuffer += "? ";
|
|
3417
|
-
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
3418
|
-
if (!writeNode(state, level, objectValue, false, false)) {
|
|
3419
|
-
continue;
|
|
3420
|
-
}
|
|
3421
|
-
pairBuffer += state.dump;
|
|
3422
|
-
_result += pairBuffer;
|
|
3423
|
-
}
|
|
3424
|
-
state.tag = _tag;
|
|
3425
|
-
state.dump = "{" + _result + "}";
|
|
3426
|
-
}
|
|
3427
|
-
function writeBlockMapping(state, level, object, compact) {
|
|
3428
|
-
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
3429
|
-
if (state.sortKeys === true) {
|
|
3430
|
-
objectKeyList.sort();
|
|
3431
|
-
} else if (typeof state.sortKeys === "function") {
|
|
3432
|
-
objectKeyList.sort(state.sortKeys);
|
|
3433
|
-
} else if (state.sortKeys) {
|
|
3434
|
-
throw new exception("sortKeys must be a boolean or a function");
|
|
3435
|
-
}
|
|
3436
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
3437
|
-
pairBuffer = "";
|
|
3438
|
-
if (!compact || _result !== "") {
|
|
3439
|
-
pairBuffer += generateNextLine(state, level);
|
|
3440
|
-
}
|
|
3441
|
-
objectKey = objectKeyList[index];
|
|
3442
|
-
objectValue = object[objectKey];
|
|
3443
|
-
if (state.replacer) {
|
|
3444
|
-
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
3445
|
-
}
|
|
3446
|
-
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
3447
|
-
continue;
|
|
3448
|
-
}
|
|
3449
|
-
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
3450
|
-
if (explicitPair) {
|
|
3451
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
3452
|
-
pairBuffer += "?";
|
|
3453
|
-
} else {
|
|
3454
|
-
pairBuffer += "? ";
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
pairBuffer += state.dump;
|
|
3458
|
-
if (explicitPair) {
|
|
3459
|
-
pairBuffer += generateNextLine(state, level);
|
|
3460
|
-
}
|
|
3461
|
-
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
3462
|
-
continue;
|
|
3463
|
-
}
|
|
3464
|
-
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
3465
|
-
pairBuffer += ":";
|
|
3466
|
-
} else {
|
|
3467
|
-
pairBuffer += ": ";
|
|
3468
|
-
}
|
|
3469
|
-
pairBuffer += state.dump;
|
|
3470
|
-
_result += pairBuffer;
|
|
3471
|
-
}
|
|
3472
|
-
state.tag = _tag;
|
|
3473
|
-
state.dump = _result || "{}";
|
|
3474
|
-
}
|
|
3475
|
-
function detectType(state, object, explicit) {
|
|
3476
|
-
var _result, typeList, index, length, type2, style;
|
|
3477
|
-
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
3478
|
-
for (index = 0, length = typeList.length; index < length; index += 1) {
|
|
3479
|
-
type2 = typeList[index];
|
|
3480
|
-
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
3481
|
-
if (explicit) {
|
|
3482
|
-
if (type2.multi && type2.representName) {
|
|
3483
|
-
state.tag = type2.representName(object);
|
|
3484
|
-
} else {
|
|
3485
|
-
state.tag = type2.tag;
|
|
3486
|
-
}
|
|
3487
|
-
} else {
|
|
3488
|
-
state.tag = "?";
|
|
3489
|
-
}
|
|
3490
|
-
if (type2.represent) {
|
|
3491
|
-
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
3492
|
-
if (_toString.call(type2.represent) === "[object Function]") {
|
|
3493
|
-
_result = type2.represent(object, style);
|
|
3494
|
-
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
3495
|
-
_result = type2.represent[style](object, style);
|
|
3496
|
-
} else {
|
|
3497
|
-
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
3498
|
-
}
|
|
3499
|
-
state.dump = _result;
|
|
3500
|
-
}
|
|
3501
|
-
return true;
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
return false;
|
|
3505
|
-
}
|
|
3506
|
-
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
3507
|
-
state.tag = null;
|
|
3508
|
-
state.dump = object;
|
|
3509
|
-
if (!detectType(state, object, false)) {
|
|
3510
|
-
detectType(state, object, true);
|
|
3511
|
-
}
|
|
3512
|
-
var type2 = _toString.call(state.dump);
|
|
3513
|
-
var inblock = block;
|
|
3514
|
-
var tagStr;
|
|
3515
|
-
if (block) {
|
|
3516
|
-
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
3517
|
-
}
|
|
3518
|
-
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
3519
|
-
if (objectOrArray) {
|
|
3520
|
-
duplicateIndex = state.duplicates.indexOf(object);
|
|
3521
|
-
duplicate = duplicateIndex !== -1;
|
|
3522
|
-
}
|
|
3523
|
-
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
3524
|
-
compact = false;
|
|
3525
|
-
}
|
|
3526
|
-
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
3527
|
-
state.dump = "*ref_" + duplicateIndex;
|
|
3528
|
-
} else {
|
|
3529
|
-
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
3530
|
-
state.usedDuplicates[duplicateIndex] = true;
|
|
3531
|
-
}
|
|
3532
|
-
if (type2 === "[object Object]") {
|
|
3533
|
-
if (block && Object.keys(state.dump).length !== 0) {
|
|
3534
|
-
writeBlockMapping(state, level, state.dump, compact);
|
|
3535
|
-
if (duplicate) {
|
|
3536
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3537
|
-
}
|
|
3538
|
-
} else {
|
|
3539
|
-
writeFlowMapping(state, level, state.dump);
|
|
3540
|
-
if (duplicate) {
|
|
3541
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
} else if (type2 === "[object Array]") {
|
|
3545
|
-
if (block && state.dump.length !== 0) {
|
|
3546
|
-
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
3547
|
-
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
3548
|
-
} else {
|
|
3549
|
-
writeBlockSequence(state, level, state.dump, compact);
|
|
3550
|
-
}
|
|
3551
|
-
if (duplicate) {
|
|
3552
|
-
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
3553
|
-
}
|
|
3554
|
-
} else {
|
|
3555
|
-
writeFlowSequence(state, level, state.dump);
|
|
3556
|
-
if (duplicate) {
|
|
3557
|
-
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
3558
|
-
}
|
|
3559
|
-
}
|
|
3560
|
-
} else if (type2 === "[object String]") {
|
|
3561
|
-
if (state.tag !== "?") {
|
|
3562
|
-
writeScalar(state, state.dump, level, iskey, inblock);
|
|
3563
|
-
}
|
|
3564
|
-
} else if (type2 === "[object Undefined]") {
|
|
3565
|
-
return false;
|
|
3566
|
-
} else {
|
|
3567
|
-
if (state.skipInvalid)
|
|
3568
|
-
return false;
|
|
3569
|
-
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
3570
|
-
}
|
|
3571
|
-
if (state.tag !== null && state.tag !== "?") {
|
|
3572
|
-
tagStr = encodeURI(
|
|
3573
|
-
state.tag[0] === "!" ? state.tag.slice(1) : state.tag
|
|
3574
|
-
).replace(/!/g, "%21");
|
|
3575
|
-
if (state.tag[0] === "!") {
|
|
3576
|
-
tagStr = "!" + tagStr;
|
|
3577
|
-
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
3578
|
-
tagStr = "!!" + tagStr.slice(18);
|
|
3579
|
-
} else {
|
|
3580
|
-
tagStr = "!<" + tagStr + ">";
|
|
3581
|
-
}
|
|
3582
|
-
state.dump = tagStr + " " + state.dump;
|
|
3583
|
-
}
|
|
3584
|
-
}
|
|
3585
|
-
return true;
|
|
3586
|
-
}
|
|
3587
|
-
function getDuplicateReferences(object, state) {
|
|
3588
|
-
var objects = [], duplicatesIndexes = [], index, length;
|
|
3589
|
-
inspectNode(object, objects, duplicatesIndexes);
|
|
3590
|
-
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
3591
|
-
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
3592
|
-
}
|
|
3593
|
-
state.usedDuplicates = new Array(length);
|
|
3594
|
-
}
|
|
3595
|
-
function inspectNode(object, objects, duplicatesIndexes) {
|
|
3596
|
-
var objectKeyList, index, length;
|
|
3597
|
-
if (object !== null && typeof object === "object") {
|
|
3598
|
-
index = objects.indexOf(object);
|
|
3599
|
-
if (index !== -1) {
|
|
3600
|
-
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
3601
|
-
duplicatesIndexes.push(index);
|
|
3602
|
-
}
|
|
3603
|
-
} else {
|
|
3604
|
-
objects.push(object);
|
|
3605
|
-
if (Array.isArray(object)) {
|
|
3606
|
-
for (index = 0, length = object.length; index < length; index += 1) {
|
|
3607
|
-
inspectNode(object[index], objects, duplicatesIndexes);
|
|
3608
|
-
}
|
|
3609
|
-
} else {
|
|
3610
|
-
objectKeyList = Object.keys(object);
|
|
3611
|
-
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
3612
|
-
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
function dump$1(input, options) {
|
|
3619
|
-
options = options || {};
|
|
3620
|
-
var state = new State(options);
|
|
3621
|
-
if (!state.noRefs)
|
|
3622
|
-
getDuplicateReferences(input, state);
|
|
3623
|
-
var value = input;
|
|
3624
|
-
if (state.replacer) {
|
|
3625
|
-
value = state.replacer.call({ "": value }, "", value);
|
|
3626
|
-
}
|
|
3627
|
-
if (writeNode(state, 0, value, true, true))
|
|
3628
|
-
return state.dump + "\n";
|
|
3629
|
-
return "";
|
|
3630
|
-
}
|
|
3631
|
-
var dump_1 = dump$1;
|
|
3632
|
-
var dumper = {
|
|
3633
|
-
dump: dump_1
|
|
3634
|
-
};
|
|
3635
|
-
function renamed(from, to) {
|
|
3636
|
-
return function() {
|
|
3637
|
-
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
3638
|
-
};
|
|
3639
|
-
}
|
|
3640
|
-
var Type = type;
|
|
3641
|
-
var Schema = schema;
|
|
3642
|
-
var FAILSAFE_SCHEMA = failsafe;
|
|
3643
|
-
var JSON_SCHEMA = json;
|
|
3644
|
-
var CORE_SCHEMA = core;
|
|
3645
|
-
var DEFAULT_SCHEMA = _default;
|
|
3646
|
-
var load2 = loader.load;
|
|
3647
|
-
var loadAll = loader.loadAll;
|
|
3648
|
-
var dump = dumper.dump;
|
|
3649
|
-
var YAMLException = exception;
|
|
3650
|
-
var types = {
|
|
3651
|
-
binary,
|
|
3652
|
-
float,
|
|
3653
|
-
map,
|
|
3654
|
-
null: _null,
|
|
3655
|
-
pairs,
|
|
3656
|
-
set,
|
|
3657
|
-
timestamp,
|
|
3658
|
-
bool,
|
|
3659
|
-
int,
|
|
3660
|
-
merge,
|
|
3661
|
-
omap,
|
|
3662
|
-
seq,
|
|
3663
|
-
str
|
|
3664
|
-
};
|
|
3665
|
-
var safeLoad = renamed("safeLoad", "load");
|
|
3666
|
-
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
3667
|
-
var safeDump = renamed("safeDump", "dump");
|
|
3668
|
-
var jsYaml = {
|
|
3669
|
-
Type,
|
|
3670
|
-
Schema,
|
|
3671
|
-
FAILSAFE_SCHEMA,
|
|
3672
|
-
JSON_SCHEMA,
|
|
3673
|
-
CORE_SCHEMA,
|
|
3674
|
-
DEFAULT_SCHEMA,
|
|
3675
|
-
load: load2,
|
|
3676
|
-
loadAll,
|
|
3677
|
-
dump,
|
|
3678
|
-
YAMLException,
|
|
3679
|
-
types,
|
|
3680
|
-
safeLoad,
|
|
3681
|
-
safeLoadAll,
|
|
3682
|
-
safeDump
|
|
3683
|
-
};
|
|
3684
|
-
var js_yaml_default = jsYaml;
|
|
3685
|
-
|
|
3686
|
-
// ../../node_modules/.pnpm/markdown-it-mdc@0.1.0_@types+markdown-it@13.0.1_markdown-it@13.0.1/node_modules/markdown-it-mdc/dist/index.mjs
|
|
3687
|
-
import Token from "markdown-it/lib/token.js";
|
|
3688
|
-
var bracketPairs = {
|
|
3689
|
-
"[": "]",
|
|
3690
|
-
"{": "}",
|
|
3691
|
-
"(": ")"
|
|
3692
|
-
};
|
|
3693
|
-
var quotePairs = {
|
|
3694
|
-
"'": "'",
|
|
3695
|
-
'"': '"',
|
|
3696
|
-
"`": "`"
|
|
3697
|
-
};
|
|
3698
|
-
function parseProps(content) {
|
|
3699
|
-
content = content.trim();
|
|
3700
|
-
if (!content)
|
|
3701
|
-
return void 0;
|
|
3702
|
-
const { props, index } = searchProps(content);
|
|
3703
|
-
if (index !== content.length)
|
|
3704
|
-
throw new Error(`Invalid props: \`${content}\`, expected end \`}\` but got \`${content.slice(index)}\``);
|
|
3705
|
-
return props;
|
|
3706
|
-
}
|
|
3707
|
-
function searchProps(content, index = 0) {
|
|
3708
|
-
if (content[index] !== "{")
|
|
3709
|
-
throw new Error(`Invalid props, expected \`{\` but got '${content[index]}'`);
|
|
3710
|
-
const props = [];
|
|
3711
|
-
index += 1;
|
|
3712
|
-
while (index < content.length) {
|
|
3713
|
-
if (content[index] === "\\") {
|
|
3714
|
-
index += 2;
|
|
3715
|
-
} else if (content[index] === "}") {
|
|
3716
|
-
index += 1;
|
|
3717
|
-
break;
|
|
3718
|
-
} else if (content[index] === " ") {
|
|
3719
|
-
index += 1;
|
|
3720
|
-
} else if (content[index] === ".") {
|
|
3721
|
-
index += 1;
|
|
3722
|
-
props.push([
|
|
3723
|
-
"class",
|
|
3724
|
-
searchUntil(" #.}")
|
|
3725
|
-
]);
|
|
3726
|
-
} else if (content[index] === "#") {
|
|
3727
|
-
index += 1;
|
|
3728
|
-
props.push([
|
|
3729
|
-
"id",
|
|
3730
|
-
searchUntil(" #.}")
|
|
3731
|
-
]);
|
|
3732
|
-
} else {
|
|
3733
|
-
const start = index;
|
|
3734
|
-
while (index < content.length) {
|
|
3735
|
-
index += 1;
|
|
3736
|
-
if (" }=".includes(content[index]))
|
|
3737
|
-
break;
|
|
3738
|
-
}
|
|
3739
|
-
const char = content[index];
|
|
3740
|
-
if (start !== index) {
|
|
3741
|
-
const key = content.slice(start, index);
|
|
3742
|
-
if (char === "=") {
|
|
3743
|
-
index += 1;
|
|
3744
|
-
props.push([
|
|
3745
|
-
key,
|
|
3746
|
-
searchValue()
|
|
3747
|
-
]);
|
|
3748
|
-
} else {
|
|
3749
|
-
props.push([
|
|
3750
|
-
key,
|
|
3751
|
-
"true"
|
|
3752
|
-
]);
|
|
3753
|
-
}
|
|
3754
|
-
}
|
|
3755
|
-
index += 1;
|
|
3756
|
-
}
|
|
3757
|
-
}
|
|
3758
|
-
function searchUntil(str2) {
|
|
3759
|
-
const start = index;
|
|
3760
|
-
while (index < content.length) {
|
|
3761
|
-
index += 1;
|
|
3762
|
-
if (content[index] === "\\")
|
|
3763
|
-
index += 2;
|
|
3764
|
-
if (str2.includes(content[index]))
|
|
3765
|
-
break;
|
|
3766
|
-
}
|
|
3767
|
-
return content.slice(start, index);
|
|
3768
|
-
}
|
|
3769
|
-
function searchValue() {
|
|
3770
|
-
const start = index;
|
|
3771
|
-
if (content[index] in bracketPairs) {
|
|
3772
|
-
searchBracket(bracketPairs[content[index]]);
|
|
3773
|
-
index += 1;
|
|
3774
|
-
return content.slice(start, index);
|
|
3775
|
-
} else if (content[index] in quotePairs) {
|
|
3776
|
-
searchString(quotePairs[content[index]]);
|
|
3777
|
-
index += 1;
|
|
3778
|
-
return content.slice(start, index);
|
|
3779
|
-
} else {
|
|
3780
|
-
return searchUntil(" }");
|
|
3781
|
-
}
|
|
3782
|
-
}
|
|
3783
|
-
function searchBracket(end) {
|
|
3784
|
-
while (index < content.length) {
|
|
3785
|
-
index++;
|
|
3786
|
-
if (content[index] in quotePairs)
|
|
3787
|
-
searchString(quotePairs[content[index]]);
|
|
3788
|
-
else if (content[index] in bracketPairs)
|
|
3789
|
-
searchBracket(bracketPairs[content[index]]);
|
|
3790
|
-
else if (content[index] === end)
|
|
3791
|
-
return;
|
|
3792
|
-
}
|
|
3793
|
-
}
|
|
3794
|
-
function searchString(end) {
|
|
3795
|
-
return searchUntil(end);
|
|
3796
|
-
}
|
|
3797
|
-
props.forEach((v) => {
|
|
3798
|
-
if (v[1].match(/^(['"`]).*\1$/))
|
|
3799
|
-
v[1] = v[1].slice(1, -1);
|
|
3800
|
-
});
|
|
3801
|
-
return {
|
|
3802
|
-
props,
|
|
3803
|
-
index
|
|
3804
|
-
};
|
|
3805
|
-
}
|
|
3806
|
-
var RE_BLOCK_NAME = /^[a-zA-Z$][\w\.$-_]+/;
|
|
3807
|
-
function parseBlockParams(str2) {
|
|
3808
|
-
str2 = str2.trim();
|
|
3809
|
-
if (!str2)
|
|
3810
|
-
return { name: "" };
|
|
3811
|
-
const name = str2.match(RE_BLOCK_NAME)?.[0];
|
|
3812
|
-
if (!name)
|
|
3813
|
-
throw new Error(`Invalid block params: ${str2}`);
|
|
3814
|
-
const params = str2.slice(name.length).trim();
|
|
3815
|
-
return {
|
|
3816
|
-
name,
|
|
3817
|
-
props: parseProps(params)
|
|
3818
|
-
};
|
|
3819
|
-
}
|
|
3820
|
-
var MarkdownItMdcBlock = (md2) => {
|
|
3821
|
-
const min_markers = 2;
|
|
3822
|
-
const marker_str = ":";
|
|
3823
|
-
const marker_char = marker_str.charCodeAt(0);
|
|
3824
|
-
md2.block.ruler.before(
|
|
3825
|
-
"fence",
|
|
3826
|
-
"mdc_block_shorthand",
|
|
3827
|
-
// eslint-disable-next-line prefer-arrow-callback
|
|
3828
|
-
function mdc_block_shorthand(state, startLine, endLine, silent) {
|
|
3829
|
-
const line = state.src.slice(state.bMarks[startLine] + state.tShift[startLine], state.eMarks[startLine]);
|
|
3830
|
-
if (!line.match(/^:[\w]/))
|
|
3831
|
-
return false;
|
|
3832
|
-
const {
|
|
3833
|
-
name,
|
|
3834
|
-
props
|
|
3835
|
-
} = parseBlockParams(line.slice(1));
|
|
3836
|
-
state.lineMax = startLine + 1;
|
|
3837
|
-
if (!silent) {
|
|
3838
|
-
const token = state.push("mdc_block_shorthand", name, 0);
|
|
3839
|
-
props?.forEach(([key, value]) => {
|
|
3840
|
-
if (key === "class")
|
|
3841
|
-
token.attrJoin(key, value);
|
|
3842
|
-
else
|
|
3843
|
-
token.attrSet(key, value);
|
|
3844
|
-
});
|
|
3845
|
-
}
|
|
3846
|
-
state.line = startLine + 1;
|
|
3847
|
-
return true;
|
|
3848
|
-
}
|
|
3849
|
-
);
|
|
3850
|
-
md2.block.ruler.before(
|
|
3851
|
-
"fence",
|
|
3852
|
-
"mdc_block",
|
|
3853
|
-
// eslint-disable-next-line prefer-arrow-callback
|
|
3854
|
-
function mdc_block(state, startLine, endLine, silent) {
|
|
3855
|
-
var _a;
|
|
3856
|
-
let pos;
|
|
3857
|
-
let nextLine;
|
|
3858
|
-
let auto_closed = false;
|
|
3859
|
-
let start = state.bMarks[startLine] + state.tShift[startLine];
|
|
3860
|
-
let max = state.eMarks[startLine];
|
|
3861
|
-
const indent = state.sCount[startLine];
|
|
3862
|
-
if (state.src[start] !== ":")
|
|
3863
|
-
return false;
|
|
3864
|
-
for (pos = start + 1; pos <= max; pos++) {
|
|
3865
|
-
if (marker_str !== state.src[pos])
|
|
3866
|
-
break;
|
|
3867
|
-
}
|
|
3868
|
-
const marker_count = Math.floor(pos - start);
|
|
3869
|
-
if (marker_count < min_markers)
|
|
3870
|
-
return false;
|
|
3871
|
-
const markup = state.src.slice(start, pos);
|
|
3872
|
-
const params = parseBlockParams(state.src.slice(pos, max));
|
|
3873
|
-
if (!params.name)
|
|
3874
|
-
return false;
|
|
3875
|
-
if (silent)
|
|
3876
|
-
return true;
|
|
3877
|
-
nextLine = startLine;
|
|
3878
|
-
for (; ; ) {
|
|
3879
|
-
nextLine++;
|
|
3880
|
-
if (nextLine >= endLine) {
|
|
3881
|
-
break;
|
|
3882
|
-
}
|
|
3883
|
-
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
3884
|
-
max = state.eMarks[nextLine];
|
|
3885
|
-
if (start < max && state.sCount[nextLine] < state.blkIndent) {
|
|
3886
|
-
break;
|
|
3887
|
-
}
|
|
3888
|
-
if (marker_char !== state.src.charCodeAt(start))
|
|
3889
|
-
continue;
|
|
3890
|
-
for (pos = start + 1; pos <= max; pos++) {
|
|
3891
|
-
if (marker_str !== state.src[pos])
|
|
3892
|
-
break;
|
|
3893
|
-
}
|
|
3894
|
-
if (pos - start !== marker_count)
|
|
3895
|
-
continue;
|
|
3896
|
-
pos = state.skipSpaces(pos);
|
|
3897
|
-
if (pos < max)
|
|
3898
|
-
continue;
|
|
3899
|
-
auto_closed = true;
|
|
3900
|
-
break;
|
|
3901
|
-
}
|
|
3902
|
-
const old_parent = state.parentType;
|
|
3903
|
-
const old_line_max = state.lineMax;
|
|
3904
|
-
state.parentType = "mdc_block";
|
|
3905
|
-
state.lineMax = nextLine;
|
|
3906
|
-
const tokenOpen = state.push("mdc_block_open", params.name, 1);
|
|
3907
|
-
tokenOpen.markup = markup;
|
|
3908
|
-
tokenOpen.block = true;
|
|
3909
|
-
tokenOpen.info = params.name;
|
|
3910
|
-
tokenOpen.map = [startLine, nextLine];
|
|
3911
|
-
if (params.props) {
|
|
3912
|
-
params.props.forEach(([key, value]) => {
|
|
3913
|
-
if (key === "class")
|
|
3914
|
-
tokenOpen.attrJoin(key, value);
|
|
3915
|
-
else
|
|
3916
|
-
tokenOpen.attrSet(key, value);
|
|
3917
|
-
});
|
|
3918
|
-
}
|
|
3919
|
-
const blkIndent = state.blkIndent;
|
|
3920
|
-
state.blkIndent = indent;
|
|
3921
|
-
(_a = state.env).mdcBlockTokens || (_a.mdcBlockTokens = []);
|
|
3922
|
-
state.env.mdcBlockTokens.unshift(tokenOpen);
|
|
3923
|
-
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
3924
|
-
state.blkIndent = blkIndent;
|
|
3925
|
-
state.env.mdcBlockTokens.shift(tokenOpen);
|
|
3926
|
-
const tokenClose = state.push("mdc_block_close", params.name, -1);
|
|
3927
|
-
tokenClose.markup = state.src.slice(start, pos);
|
|
3928
|
-
tokenClose.block = true;
|
|
3929
|
-
state.tokens.slice(
|
|
3930
|
-
state.tokens.indexOf(tokenOpen) + 1,
|
|
3931
|
-
state.tokens.indexOf(tokenClose)
|
|
3932
|
-
).filter((i) => i.level === tokenOpen.level + 1).forEach((i) => {
|
|
3933
|
-
if (i.tag === "p")
|
|
3934
|
-
i.hidden = true;
|
|
3935
|
-
});
|
|
3936
|
-
state.parentType = old_parent;
|
|
3937
|
-
state.lineMax = old_line_max;
|
|
3938
|
-
state.line = nextLine + (auto_closed ? 1 : 0);
|
|
3939
|
-
return true;
|
|
3940
|
-
},
|
|
3941
|
-
{
|
|
3942
|
-
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
3943
|
-
}
|
|
3944
|
-
);
|
|
3945
|
-
md2.block.ruler.after(
|
|
3946
|
-
"code",
|
|
3947
|
-
"mdc_block_yaml",
|
|
3948
|
-
// eslint-disable-next-line prefer-arrow-callback
|
|
3949
|
-
function mdc_block_yaml(state, startLine, endLine, silent) {
|
|
3950
|
-
if (!state.env.mdcBlockTokens?.length)
|
|
3951
|
-
return false;
|
|
3952
|
-
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
3953
|
-
const end = state.eMarks[startLine];
|
|
3954
|
-
if (state.src.slice(start, end) !== "---")
|
|
3955
|
-
return false;
|
|
3956
|
-
let lineEnd = startLine + 1;
|
|
3957
|
-
let found = false;
|
|
3958
|
-
while (lineEnd < endLine) {
|
|
3959
|
-
const line = state.src.slice(state.bMarks[lineEnd] + state.tShift[startLine], state.eMarks[lineEnd]);
|
|
3960
|
-
if (line === "---") {
|
|
3961
|
-
found = true;
|
|
3962
|
-
break;
|
|
3963
|
-
}
|
|
3964
|
-
lineEnd += 1;
|
|
3965
|
-
}
|
|
3966
|
-
if (!found)
|
|
3967
|
-
return false;
|
|
3968
|
-
if (!silent) {
|
|
3969
|
-
const yaml = state.src.slice(state.bMarks[startLine + 1], state.eMarks[lineEnd - 1]);
|
|
3970
|
-
const data = js_yaml_default.load(yaml);
|
|
3971
|
-
const token = state.env.mdcBlockTokens[0];
|
|
3972
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
3973
|
-
if (key === "class")
|
|
3974
|
-
token.attrJoin(key, value);
|
|
3975
|
-
else
|
|
3976
|
-
token.attrSet(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
3977
|
-
});
|
|
3978
|
-
}
|
|
3979
|
-
state.line = lineEnd + 1;
|
|
3980
|
-
state.lineMax = lineEnd + 1;
|
|
3981
|
-
return true;
|
|
3982
|
-
}
|
|
3983
|
-
);
|
|
3984
|
-
md2.block.ruler.after(
|
|
3985
|
-
"code",
|
|
3986
|
-
"mdc_block_slots",
|
|
3987
|
-
// eslint-disable-next-line prefer-arrow-callback
|
|
3988
|
-
function mdc_block(state, startLine, endLine, silent) {
|
|
3989
|
-
if (!state.env.mdcBlockTokens?.length)
|
|
3990
|
-
return false;
|
|
3991
|
-
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
3992
|
-
if (!(state.src[start] === "#" && state.src[start + 1] !== " "))
|
|
3993
|
-
return false;
|
|
3994
|
-
const line = state.src.slice(start, state.eMarks[startLine]);
|
|
3995
|
-
const {
|
|
3996
|
-
name,
|
|
3997
|
-
props
|
|
3998
|
-
} = parseBlockParams(line.slice(1));
|
|
3999
|
-
let lineEnd = startLine + 1;
|
|
4000
|
-
while (lineEnd < endLine) {
|
|
4001
|
-
const line2 = state.src.slice(state.bMarks[lineEnd] + state.tShift[startLine], state.eMarks[lineEnd]);
|
|
4002
|
-
if (line2.match(/^#(\w)+/) || line2.startsWith("::"))
|
|
4003
|
-
break;
|
|
4004
|
-
lineEnd += 1;
|
|
4005
|
-
}
|
|
4006
|
-
if (silent) {
|
|
4007
|
-
state.line = lineEnd;
|
|
4008
|
-
state.lineMax = lineEnd;
|
|
4009
|
-
return true;
|
|
4010
|
-
}
|
|
4011
|
-
state.lineMax = startLine + 1;
|
|
4012
|
-
const slot = state.push("mdc_block_slot", "template", 1);
|
|
4013
|
-
slot.attrSet(`#${name}`, "");
|
|
4014
|
-
props?.forEach(([key, value]) => {
|
|
4015
|
-
if (key === "class")
|
|
4016
|
-
slot.attrJoin(key, value);
|
|
4017
|
-
else
|
|
4018
|
-
slot.attrSet(key, value);
|
|
4019
|
-
});
|
|
4020
|
-
state.line = startLine + 1;
|
|
4021
|
-
state.lineMax = lineEnd;
|
|
4022
|
-
state.md.block.tokenize(state, startLine + 1, lineEnd);
|
|
4023
|
-
state.push("mdc_block_slot", "template", -1);
|
|
4024
|
-
state.line = lineEnd;
|
|
4025
|
-
state.lineMax = lineEnd;
|
|
4026
|
-
return true;
|
|
4027
|
-
}
|
|
4028
|
-
);
|
|
4029
|
-
};
|
|
4030
|
-
var MarkdownItInlineProps = (md2) => {
|
|
4031
|
-
md2.inline.ruler.after("entity", "mdc_inline_props", (state, silent) => {
|
|
4032
|
-
const start = state.pos;
|
|
4033
|
-
const char = state.src[start];
|
|
4034
|
-
if (char !== "{")
|
|
4035
|
-
return false;
|
|
4036
|
-
const {
|
|
4037
|
-
props,
|
|
4038
|
-
index: end
|
|
4039
|
-
} = searchProps(state.src, start);
|
|
4040
|
-
if (end === start)
|
|
4041
|
-
return false;
|
|
4042
|
-
if (silent)
|
|
4043
|
-
return true;
|
|
4044
|
-
state.pos = start;
|
|
4045
|
-
state.posMax = end;
|
|
4046
|
-
const token = state.push("mdc_inline_props", "span", 0);
|
|
4047
|
-
token.attrs = props;
|
|
4048
|
-
token.hidden = true;
|
|
4049
|
-
state.pos = end;
|
|
4050
|
-
state.posMax = end;
|
|
4051
|
-
return true;
|
|
4052
|
-
});
|
|
4053
|
-
md2.renderer.rules.mdc_inline_props = () => {
|
|
4054
|
-
return "";
|
|
4055
|
-
};
|
|
4056
|
-
const _parse = md2.parse;
|
|
4057
|
-
md2.parse = function(src, env) {
|
|
4058
|
-
const tokens = _parse.call(this, src, env);
|
|
4059
|
-
tokens.forEach((token, index) => {
|
|
4060
|
-
const prev = tokens[index - 1];
|
|
4061
|
-
if (prev?.type !== "heading_open" && prev?.type !== "paragraph_open")
|
|
4062
|
-
return;
|
|
4063
|
-
if (token.type === "inline" && token.children?.length === 2 && token.children[0].type === "text" && token.children[1].type === "mdc_inline_props") {
|
|
4064
|
-
const props = token.children[1].attrs;
|
|
4065
|
-
token.children.splice(1, 1);
|
|
4066
|
-
props?.forEach(([key, value]) => {
|
|
4067
|
-
if (key === "class")
|
|
4068
|
-
prev.attrJoin("class", value);
|
|
4069
|
-
else
|
|
4070
|
-
prev.attrSet(key, value);
|
|
4071
|
-
});
|
|
4072
|
-
}
|
|
4073
|
-
});
|
|
4074
|
-
return tokens;
|
|
4075
|
-
};
|
|
4076
|
-
const _renderInline = md2.renderer.renderInline;
|
|
4077
|
-
md2.renderer.renderInline = function(tokens, options, env) {
|
|
4078
|
-
tokens = [...tokens];
|
|
4079
|
-
tokens.forEach((token, index) => {
|
|
4080
|
-
if (token.type === "mdc_inline_props") {
|
|
4081
|
-
let prevIndex = index - 1;
|
|
4082
|
-
let prev = tokens[prevIndex];
|
|
4083
|
-
while (prevIndex >= 0) {
|
|
4084
|
-
if (prev.type === "text" && !prev.content.trim()) {
|
|
4085
|
-
prevIndex--;
|
|
4086
|
-
prev = tokens[prevIndex];
|
|
4087
|
-
} else {
|
|
4088
|
-
break;
|
|
4089
|
-
}
|
|
4090
|
-
}
|
|
4091
|
-
if (!prev.tag && prev.type === "text") {
|
|
4092
|
-
prev = new Token("mdc_inline_span", "span", 1);
|
|
4093
|
-
tokens.splice(index - 1, 0, prev);
|
|
4094
|
-
const close = new Token("mdc_inline_span", "span", -1);
|
|
4095
|
-
tokens.splice(index + 2, 0, close);
|
|
4096
|
-
} else if (prev.nesting === -1) {
|
|
4097
|
-
let searchIndex = index - 1;
|
|
4098
|
-
while (searchIndex >= 0) {
|
|
4099
|
-
const searchToken = tokens[searchIndex];
|
|
4100
|
-
if (searchToken.nesting === 1 && searchToken.tag === prev.tag && searchToken.level === prev.level) {
|
|
4101
|
-
prev = searchToken;
|
|
4102
|
-
break;
|
|
4103
|
-
}
|
|
4104
|
-
searchIndex--;
|
|
4105
|
-
}
|
|
4106
|
-
}
|
|
4107
|
-
if (prev.nesting === -1)
|
|
4108
|
-
throw new Error(`No matching opening tag found for ${JSON.stringify(prev)}`);
|
|
4109
|
-
token.attrs?.forEach(([key, value]) => {
|
|
4110
|
-
if (key === "class")
|
|
4111
|
-
prev.attrJoin("class", value);
|
|
4112
|
-
else
|
|
4113
|
-
prev.attrSet(key, value);
|
|
4114
|
-
});
|
|
4115
|
-
}
|
|
4116
|
-
});
|
|
4117
|
-
return _renderInline.call(this, tokens, options, env);
|
|
4118
|
-
};
|
|
4119
|
-
};
|
|
4120
|
-
var MarkdownItInlineComponent = (md2) => {
|
|
4121
|
-
md2.inline.ruler.after("entity", "mdc_inline_component", (state, silent) => {
|
|
4122
|
-
const start = state.pos;
|
|
4123
|
-
const char = state.src[start];
|
|
4124
|
-
if (!(char === ":" && state.src[start - 1] === " "))
|
|
4125
|
-
return false;
|
|
4126
|
-
let index = start + 1;
|
|
4127
|
-
let contentStart = -1;
|
|
4128
|
-
let contentEnd = -1;
|
|
4129
|
-
while (index < state.src.length) {
|
|
4130
|
-
const char2 = state.src[index];
|
|
4131
|
-
if (char2 === "[") {
|
|
4132
|
-
contentStart = index + 1;
|
|
4133
|
-
while (index < state.src.length) {
|
|
4134
|
-
index += 1;
|
|
4135
|
-
if (state.src[index] === "\\")
|
|
4136
|
-
index += 2;
|
|
4137
|
-
if (state.src[index] === "]") {
|
|
4138
|
-
contentEnd = index;
|
|
4139
|
-
index += 1;
|
|
4140
|
-
break;
|
|
4141
|
-
}
|
|
4142
|
-
}
|
|
4143
|
-
break;
|
|
4144
|
-
}
|
|
4145
|
-
if (!/[\w\$_-]/.test(char2))
|
|
4146
|
-
break;
|
|
4147
|
-
index += 1;
|
|
4148
|
-
}
|
|
4149
|
-
if (index <= start + 1)
|
|
4150
|
-
return false;
|
|
4151
|
-
if (silent)
|
|
4152
|
-
return true;
|
|
4153
|
-
if (contentEnd !== contentStart) {
|
|
4154
|
-
const name = state.src.slice(start + 1, contentStart - 1);
|
|
4155
|
-
const body = state.src.slice(contentStart, contentEnd);
|
|
4156
|
-
state.posMax = contentStart;
|
|
4157
|
-
state.push("mdc_inline_component", name, 1);
|
|
4158
|
-
state.pos = contentStart;
|
|
4159
|
-
state.posMax = contentEnd;
|
|
4160
|
-
const text = state.push("text", "", 0);
|
|
4161
|
-
text.content = body;
|
|
4162
|
-
state.pos = contentEnd;
|
|
4163
|
-
state.posMax = contentEnd;
|
|
4164
|
-
state.push("mdc_inline_component", name, -1);
|
|
4165
|
-
} else {
|
|
4166
|
-
state.posMax = index;
|
|
4167
|
-
const name = state.src.slice(start + 1, index);
|
|
4168
|
-
state.push("mdc_inline_component", name, 0);
|
|
4169
|
-
}
|
|
4170
|
-
state.pos = index;
|
|
4171
|
-
state.posMax = index;
|
|
4172
|
-
return true;
|
|
4173
|
-
});
|
|
4174
|
-
};
|
|
4175
|
-
var MarkdownItInlineSpan = (md2) => {
|
|
4176
|
-
md2.inline.ruler.after("mdc_inline_props", "mdc_inline_span", (state, silent) => {
|
|
4177
|
-
const start = state.pos;
|
|
4178
|
-
const char = state.src[start];
|
|
4179
|
-
if (char !== "[")
|
|
4180
|
-
return false;
|
|
4181
|
-
let index = start + 1;
|
|
4182
|
-
while (index < state.src.length) {
|
|
4183
|
-
if (state.src[index] === "\\")
|
|
4184
|
-
index += 2;
|
|
4185
|
-
if (state.src[index] === "]")
|
|
4186
|
-
break;
|
|
4187
|
-
index += 1;
|
|
4188
|
-
}
|
|
4189
|
-
if (index === start)
|
|
4190
|
-
return false;
|
|
4191
|
-
if (silent)
|
|
4192
|
-
return true;
|
|
4193
|
-
state.posMax = start + 1;
|
|
4194
|
-
state.push("mdc_inline_span", "span", 1);
|
|
4195
|
-
state.pos = start + 1;
|
|
4196
|
-
state.posMax = index;
|
|
4197
|
-
const text = state.push("text", "", 0);
|
|
4198
|
-
text.content = state.src.slice(start + 1, index);
|
|
4199
|
-
state.pos = index;
|
|
4200
|
-
state.posMax = index + 1;
|
|
4201
|
-
state.push("mdc_inline_span", "span", -1);
|
|
4202
|
-
state.pos = index + 1;
|
|
4203
|
-
state.posMax = index + 1;
|
|
4204
|
-
return true;
|
|
4205
|
-
});
|
|
4206
|
-
};
|
|
4207
|
-
var MarkdownItMdc = (md2, options = {}) => {
|
|
4208
|
-
const {
|
|
4209
|
-
blockComponent = true,
|
|
4210
|
-
inlineProps = true,
|
|
4211
|
-
inlineSpan = true,
|
|
4212
|
-
inlineComponent = true
|
|
4213
|
-
} = options.syntax || {};
|
|
4214
|
-
if (blockComponent)
|
|
4215
|
-
md2.use(MarkdownItMdcBlock);
|
|
4216
|
-
if (inlineProps)
|
|
4217
|
-
md2.use(MarkdownItInlineProps);
|
|
4218
|
-
if (inlineSpan)
|
|
4219
|
-
md2.use(MarkdownItInlineSpan);
|
|
4220
|
-
if (inlineComponent)
|
|
4221
|
-
md2.use(MarkdownItInlineComponent);
|
|
4222
|
-
};
|
|
4223
|
-
|
|
4224
|
-
// node/plugins/markdown-it-katex.ts
|
|
4225
|
-
import katex from "katex";
|
|
4226
|
-
function isValidDelim(state, pos) {
|
|
4227
|
-
const max = state.posMax;
|
|
4228
|
-
let can_open = true;
|
|
4229
|
-
let can_close = true;
|
|
4230
|
-
const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
4231
|
-
const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
4232
|
-
if (prevChar === 32 || prevChar === 9 || /* \t */
|
|
4233
|
-
nextChar >= 48 && nextChar <= 57)
|
|
4234
|
-
can_close = false;
|
|
4235
|
-
if (nextChar === 32 || nextChar === 9)
|
|
4236
|
-
can_open = false;
|
|
4237
|
-
return {
|
|
4238
|
-
can_open,
|
|
4239
|
-
can_close
|
|
4240
|
-
};
|
|
4241
|
-
}
|
|
4242
|
-
function math_inline(state, silent) {
|
|
4243
|
-
let match, token, res, pos;
|
|
4244
|
-
if (state.src[state.pos] !== "$")
|
|
4245
|
-
return false;
|
|
4246
|
-
res = isValidDelim(state, state.pos);
|
|
4247
|
-
if (!res.can_open) {
|
|
4248
|
-
if (!silent)
|
|
4249
|
-
state.pending += "$";
|
|
4250
|
-
state.pos += 1;
|
|
4251
|
-
return true;
|
|
4252
|
-
}
|
|
4253
|
-
const start = state.pos + 1;
|
|
4254
|
-
match = start;
|
|
4255
|
-
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
4256
|
-
pos = match - 1;
|
|
4257
|
-
while (state.src[pos] === "\\")
|
|
4258
|
-
pos -= 1;
|
|
4259
|
-
if ((match - pos) % 2 === 1)
|
|
4260
|
-
break;
|
|
4261
|
-
match += 1;
|
|
4262
|
-
}
|
|
4263
|
-
if (match === -1) {
|
|
4264
|
-
if (!silent)
|
|
4265
|
-
state.pending += "$";
|
|
4266
|
-
state.pos = start;
|
|
4267
|
-
return true;
|
|
4268
|
-
}
|
|
4269
|
-
if (match - start === 0) {
|
|
4270
|
-
if (!silent)
|
|
4271
|
-
state.pending += "$$";
|
|
4272
|
-
state.pos = start + 1;
|
|
4273
|
-
return true;
|
|
4274
|
-
}
|
|
4275
|
-
res = isValidDelim(state, match);
|
|
4276
|
-
if (!res.can_close) {
|
|
4277
|
-
if (!silent)
|
|
4278
|
-
state.pending += "$";
|
|
4279
|
-
state.pos = start;
|
|
4280
|
-
return true;
|
|
4281
|
-
}
|
|
4282
|
-
if (!silent) {
|
|
4283
|
-
token = state.push("math_inline", "math", 0);
|
|
4284
|
-
token.markup = "$";
|
|
4285
|
-
token.content = state.src.slice(start, match);
|
|
4286
|
-
}
|
|
4287
|
-
state.pos = match + 1;
|
|
4288
|
-
return true;
|
|
4289
|
-
}
|
|
4290
|
-
function math_block(state, start, end, silent) {
|
|
4291
|
-
let firstLine;
|
|
4292
|
-
let lastLine;
|
|
4293
|
-
let next;
|
|
4294
|
-
let lastPos;
|
|
4295
|
-
let found = false;
|
|
4296
|
-
let pos = state.bMarks[start] + state.tShift[start];
|
|
4297
|
-
let max = state.eMarks[start];
|
|
4298
|
-
if (pos + 2 > max)
|
|
4299
|
-
return false;
|
|
4300
|
-
if (state.src.slice(pos, pos + 2) !== "$$")
|
|
4301
|
-
return false;
|
|
4302
|
-
pos += 2;
|
|
4303
|
-
firstLine = state.src.slice(pos, max);
|
|
4304
|
-
if (silent)
|
|
4305
|
-
return true;
|
|
4306
|
-
if (firstLine.trim().slice(-2) === "$$") {
|
|
4307
|
-
firstLine = firstLine.trim().slice(0, -2);
|
|
4308
|
-
found = true;
|
|
4309
|
-
}
|
|
4310
|
-
for (next = start; !found; ) {
|
|
4311
|
-
next++;
|
|
4312
|
-
if (next >= end)
|
|
4313
|
-
break;
|
|
4314
|
-
pos = state.bMarks[next] + state.tShift[next];
|
|
4315
|
-
max = state.eMarks[next];
|
|
4316
|
-
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
4317
|
-
break;
|
|
4318
|
-
}
|
|
4319
|
-
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
4320
|
-
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
4321
|
-
lastLine = state.src.slice(pos, lastPos);
|
|
4322
|
-
found = true;
|
|
4323
|
-
}
|
|
4324
|
-
}
|
|
4325
|
-
state.line = next + 1;
|
|
4326
|
-
const token = state.push("math_block", "math", 0);
|
|
4327
|
-
token.block = true;
|
|
4328
|
-
token.content = (firstLine && firstLine.trim() ? `${firstLine}
|
|
4329
|
-
` : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
4330
|
-
token.map = [start, state.line];
|
|
4331
|
-
token.markup = "$$";
|
|
4332
|
-
return true;
|
|
4333
|
-
}
|
|
4334
|
-
function math_plugin(md2, options) {
|
|
4335
|
-
options = options || {};
|
|
4336
|
-
const katexInline = function(latex) {
|
|
4337
|
-
options.displayMode = false;
|
|
4338
|
-
try {
|
|
4339
|
-
return katex.renderToString(latex, options);
|
|
4340
|
-
} catch (error) {
|
|
4341
|
-
if (options.throwOnError)
|
|
4342
|
-
console.warn(error);
|
|
4343
|
-
return latex;
|
|
4344
|
-
}
|
|
4345
|
-
};
|
|
4346
|
-
const inlineRenderer = function(tokens, idx) {
|
|
4347
|
-
return katexInline(tokens[idx].content);
|
|
4348
|
-
};
|
|
4349
|
-
const katexBlock = function(latex) {
|
|
4350
|
-
options.displayMode = true;
|
|
4351
|
-
try {
|
|
4352
|
-
return `<p>${katex.renderToString(latex, options)}</p>`;
|
|
4353
|
-
} catch (error) {
|
|
4354
|
-
if (options.throwOnError)
|
|
4355
|
-
console.warn(error);
|
|
4356
|
-
return latex;
|
|
4357
|
-
}
|
|
4358
|
-
};
|
|
4359
|
-
const blockRenderer = function(tokens, idx) {
|
|
4360
|
-
return `${katexBlock(tokens[idx].content)}
|
|
4361
|
-
`;
|
|
4362
|
-
};
|
|
4363
|
-
md2.inline.ruler.after("escape", "math_inline", math_inline);
|
|
4364
|
-
md2.block.ruler.after("blockquote", "math_block", math_block, {
|
|
4365
|
-
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
4366
|
-
});
|
|
4367
|
-
md2.renderer.rules.math_inline = inlineRenderer;
|
|
4368
|
-
md2.renderer.rules.math_block = blockRenderer;
|
|
4369
|
-
}
|
|
4370
|
-
|
|
4371
|
-
// node/plugins/markdown-it-prism.ts
|
|
4372
|
-
import Prism from "prismjs";
|
|
4373
|
-
import loadLanguages from "prismjs/components/";
|
|
4374
|
-
import * as htmlparser2 from "htmlparser2";
|
|
4375
|
-
var Tag = class {
|
|
4376
|
-
constructor(tagname, attributes) {
|
|
4377
|
-
this.tagname = tagname;
|
|
4378
|
-
this.attributes = attributes;
|
|
4379
|
-
}
|
|
4380
|
-
asOpen() {
|
|
4381
|
-
return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
|
|
4382
|
-
}
|
|
4383
|
-
asClosed() {
|
|
4384
|
-
return `</${this.tagname}>`;
|
|
4385
|
-
}
|
|
4386
|
-
};
|
|
4387
|
-
var DEFAULTS = {
|
|
4388
|
-
plugins: [],
|
|
4389
|
-
init: () => {
|
|
4390
|
-
},
|
|
4391
|
-
defaultLanguageForUnknown: void 0,
|
|
4392
|
-
defaultLanguageForUnspecified: void 0,
|
|
4393
|
-
defaultLanguage: void 0
|
|
4394
|
-
};
|
|
4395
|
-
function loadPrismLang(lang) {
|
|
4396
|
-
if (!lang)
|
|
4397
|
-
return void 0;
|
|
4398
|
-
let langObject = Prism.languages[lang];
|
|
4399
|
-
if (langObject === void 0) {
|
|
4400
|
-
loadLanguages([lang]);
|
|
4401
|
-
langObject = Prism.languages[lang];
|
|
4402
|
-
}
|
|
4403
|
-
return langObject;
|
|
4404
|
-
}
|
|
4405
|
-
function loadPrismPlugin(name) {
|
|
4406
|
-
try {
|
|
4407
|
-
__require(`prismjs/plugins/${name}/prism-${name}`);
|
|
4408
|
-
} catch (e) {
|
|
4409
|
-
throw new Error(`Cannot load Prism plugin "${name}". Please check the spelling.`);
|
|
4410
|
-
}
|
|
4411
|
-
}
|
|
4412
|
-
function selectLanguage(options, lang) {
|
|
4413
|
-
let langToUse = lang;
|
|
4414
|
-
if (langToUse === "" && options.defaultLanguageForUnspecified !== void 0)
|
|
4415
|
-
langToUse = options.defaultLanguageForUnspecified;
|
|
4416
|
-
let prismLang = loadPrismLang(langToUse);
|
|
4417
|
-
if (prismLang === void 0 && options.defaultLanguageForUnknown !== void 0) {
|
|
4418
|
-
langToUse = options.defaultLanguageForUnknown;
|
|
4419
|
-
prismLang = loadPrismLang(langToUse);
|
|
4420
|
-
}
|
|
4421
|
-
return [langToUse, prismLang];
|
|
4422
|
-
}
|
|
4423
|
-
function highlight(markdownit, options, text, lang) {
|
|
4424
|
-
const [langToUse, prismLang] = selectLanguage(options, lang);
|
|
4425
|
-
let code = text.trimEnd();
|
|
4426
|
-
code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
|
|
4427
|
-
code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
|
|
4428
|
-
const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
|
|
4429
|
-
return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
|
|
4430
|
-
}
|
|
4431
|
-
function highlightPrism(code, prismLang, langToUse) {
|
|
4432
|
-
const openTags = [];
|
|
4433
|
-
const parser2 = new htmlparser2.Parser({
|
|
4434
|
-
onopentag(tagname, attributes) {
|
|
4435
|
-
openTags.push(new Tag(tagname, attributes));
|
|
4436
|
-
},
|
|
4437
|
-
onclosetag() {
|
|
4438
|
-
openTags.pop();
|
|
4439
|
-
}
|
|
4440
|
-
});
|
|
4441
|
-
code = Prism.highlight(code, prismLang, langToUse);
|
|
4442
|
-
code = code.split(/\r?\n/g).map((line) => {
|
|
4443
|
-
const prefix = openTags.map((tag) => tag.asOpen()).join("");
|
|
4444
|
-
parser2.write(line);
|
|
4445
|
-
const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
|
|
4446
|
-
return prefix + line + postfix;
|
|
4447
|
-
}).join("\n");
|
|
4448
|
-
parser2.end();
|
|
4449
|
-
return code;
|
|
4450
|
-
}
|
|
4451
|
-
function checkLanguageOption(options, optionName) {
|
|
4452
|
-
const language = options[optionName];
|
|
4453
|
-
if (language !== void 0 && loadPrismLang(language) === void 0)
|
|
4454
|
-
throw new Error(`Bad option ${optionName}: There is no Prism language '${language}'.`);
|
|
4455
|
-
}
|
|
4456
|
-
function markdownItPrism(markdownit, useroptions) {
|
|
4457
|
-
const options = Object.assign({}, DEFAULTS, useroptions);
|
|
4458
|
-
checkLanguageOption(options, "defaultLanguage");
|
|
4459
|
-
checkLanguageOption(options, "defaultLanguageForUnknown");
|
|
4460
|
-
checkLanguageOption(options, "defaultLanguageForUnspecified");
|
|
4461
|
-
options.defaultLanguageForUnknown = options.defaultLanguageForUnknown || options.defaultLanguage;
|
|
4462
|
-
options.defaultLanguageForUnspecified = options.defaultLanguageForUnspecified || options.defaultLanguage;
|
|
4463
|
-
options.plugins.forEach(loadPrismPlugin);
|
|
4464
|
-
options.init(Prism);
|
|
4465
|
-
markdownit.options.highlight = (text, lang) => highlight(markdownit, options, text, lang);
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
// node/plugins/markdown-it-shiki.ts
|
|
4469
|
-
function getThemeName(theme) {
|
|
4470
|
-
if (typeof theme === "string")
|
|
4471
|
-
return theme;
|
|
4472
|
-
return theme.name;
|
|
4473
|
-
}
|
|
4474
|
-
function isShikiDarkModeThemes(theme) {
|
|
4475
|
-
return typeof theme === "object" && ("dark" in theme || "light" in theme);
|
|
4476
|
-
}
|
|
4477
|
-
function resolveShikiOptions(options) {
|
|
4478
|
-
const themes = [];
|
|
4479
|
-
let darkModeThemes;
|
|
4480
|
-
if (!options.theme) {
|
|
4481
|
-
themes.push("nord");
|
|
4482
|
-
} else if (typeof options.theme === "string") {
|
|
4483
|
-
themes.push(options.theme);
|
|
4484
|
-
} else {
|
|
4485
|
-
if (isShikiDarkModeThemes(options.theme)) {
|
|
4486
|
-
darkModeThemes = options.theme;
|
|
4487
|
-
themes.push(options.theme.dark);
|
|
4488
|
-
themes.push(options.theme.light);
|
|
4489
|
-
} else {
|
|
4490
|
-
themes.push(options.theme);
|
|
4491
|
-
}
|
|
4492
|
-
}
|
|
4493
|
-
return {
|
|
4494
|
-
...options,
|
|
4495
|
-
themes,
|
|
4496
|
-
darkModeThemes: darkModeThemes ? {
|
|
4497
|
-
dark: getThemeName(darkModeThemes.dark),
|
|
4498
|
-
light: getThemeName(darkModeThemes.light)
|
|
4499
|
-
} : void 0
|
|
4500
|
-
};
|
|
4501
|
-
}
|
|
4502
|
-
function trimEndNewLine(code) {
|
|
4503
|
-
return code.replace(/\n$/, "");
|
|
4504
|
-
}
|
|
4505
|
-
var MarkdownItShiki = (markdownit, options = {}) => {
|
|
4506
|
-
const _highlighter = options.highlighter;
|
|
4507
|
-
const { darkModeThemes } = resolveShikiOptions(options);
|
|
4508
|
-
markdownit.options.highlight = (code, lang) => {
|
|
4509
|
-
if (darkModeThemes) {
|
|
4510
|
-
const trimmed = trimEndNewLine(code);
|
|
4511
|
-
const dark = _highlighter.codeToHtml(trimmed, { lang: lang || "text", theme: darkModeThemes.dark }).replace('<pre class="shiki', '<pre class="slidev-code shiki shiki-dark');
|
|
4512
|
-
const light = _highlighter.codeToHtml(trimmed, { lang: lang || "text", theme: darkModeThemes.light }).replace('<pre class="shiki', '<pre class="slidev-code shiki shiki-light');
|
|
4513
|
-
return escapeVueInCode(`<pre class="shiki-container">${dark}${light}</pre>`);
|
|
4514
|
-
} else {
|
|
4515
|
-
return escapeVueInCode(
|
|
4516
|
-
_highlighter.codeToHtml(code, { lang: lang || "text" }).replace('<pre class="shiki"', '<pre class="slidev-code shiki"')
|
|
4517
|
-
);
|
|
4518
|
-
}
|
|
4519
|
-
};
|
|
4520
|
-
};
|
|
4521
|
-
var markdown_it_shiki_default = MarkdownItShiki;
|
|
4522
|
-
|
|
4523
|
-
// node/plugins/markdown.ts
|
|
4524
|
-
var DEFAULT_SHIKI_OPTIONS = {
|
|
4525
|
-
theme: {
|
|
4526
|
-
dark: "min-dark",
|
|
4527
|
-
light: "min-light"
|
|
4528
|
-
}
|
|
4529
|
-
};
|
|
4530
|
-
async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, { markdown: mdOptions }) {
|
|
4531
|
-
const setups = [];
|
|
4532
|
-
const entryPath = slash4(entry);
|
|
4533
|
-
if (config.highlighter === "shiki") {
|
|
4534
|
-
const Shiki = await import("shiki");
|
|
4535
|
-
const shikiOptions = await loadSetups(roots, "shiki.ts", Shiki, DEFAULT_SHIKI_OPTIONS, false);
|
|
4536
|
-
const { langs, themes } = resolveShikiOptions(shikiOptions);
|
|
4537
|
-
shikiOptions.highlighter = await Shiki.getHighlighter({ themes, langs });
|
|
4538
|
-
setups.push((md2) => md2.use(markdown_it_shiki_default, shikiOptions));
|
|
4539
|
-
} else {
|
|
4540
|
-
setups.push((md2) => md2.use(markdownItPrism));
|
|
4541
|
-
}
|
|
4542
|
-
if (config.mdc)
|
|
4543
|
-
setups.push((md2) => md2.use(MarkdownItMdc));
|
|
4544
|
-
const KatexOptions = await loadSetups(roots, "katex.ts", {}, { strict: false }, false);
|
|
4545
|
-
return Markdown2({
|
|
4546
|
-
include: [/\.md$/],
|
|
4547
|
-
wrapperClasses: "",
|
|
4548
|
-
headEnabled: false,
|
|
4549
|
-
frontmatter: false,
|
|
4550
|
-
markdownItOptions: {
|
|
4551
|
-
quotes: `""''`,
|
|
4552
|
-
html: true,
|
|
4553
|
-
xhtmlOut: true,
|
|
4554
|
-
linkify: true,
|
|
4555
|
-
...mdOptions?.markdownItOptions
|
|
4556
|
-
},
|
|
4557
|
-
...mdOptions,
|
|
4558
|
-
markdownItSetup(md2) {
|
|
4559
|
-
md2.use(mila2, {
|
|
4560
|
-
attrs: {
|
|
4561
|
-
target: "_blank",
|
|
4562
|
-
rel: "noopener"
|
|
4563
|
-
}
|
|
4564
|
-
});
|
|
4565
|
-
md2.use(mif);
|
|
4566
|
-
md2.use(taskLists, { enabled: true, lineNumber: true, label: true });
|
|
4567
|
-
md2.use(math_plugin, KatexOptions);
|
|
4568
|
-
setups.forEach((i) => i(md2));
|
|
4569
|
-
mdOptions?.markdownItSetup?.(md2);
|
|
4570
|
-
},
|
|
4571
|
-
transforms: {
|
|
4572
|
-
before(code, id) {
|
|
4573
|
-
if (id === entryPath)
|
|
4574
|
-
return "";
|
|
4575
|
-
const monaco = config.monaco === true || config.monaco === mode ? transformMarkdownMonaco : truncateMancoMark;
|
|
4576
|
-
code = transformSlotSugar(code);
|
|
4577
|
-
code = transformMermaid(code);
|
|
4578
|
-
code = transformPlantUml(code, config.plantUmlServer);
|
|
4579
|
-
code = monaco(code);
|
|
4580
|
-
code = transformHighlighter(code);
|
|
4581
|
-
code = transformPageCSS(code, id);
|
|
4582
|
-
return code;
|
|
4583
|
-
}
|
|
4584
|
-
}
|
|
4585
|
-
});
|
|
4586
|
-
}
|
|
4587
|
-
function transformMarkdownMonaco(md2) {
|
|
4588
|
-
md2 = md2.replace(/^```(\w+?)\s*{monaco-diff}\s*?({.*?})?\s*?\n([\s\S]+?)^~~~\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code, diff) => {
|
|
4589
|
-
lang = lang.trim();
|
|
4590
|
-
options = options.trim() || "{}";
|
|
4591
|
-
const encoded = base64.encode(code, true);
|
|
4592
|
-
const encodedDiff = base64.encode(diff, true);
|
|
4593
|
-
return `<Monaco :code="'${encoded}'" :diff="'${encodedDiff}'" lang="${lang}" v-bind="${options}" />`;
|
|
4594
|
-
});
|
|
4595
|
-
md2 = md2.replace(/^```(\w+?)\s*{monaco}\s*?({.*?})?\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code) => {
|
|
4596
|
-
lang = lang.trim();
|
|
4597
|
-
options = options.trim() || "{}";
|
|
4598
|
-
const encoded = base64.encode(code, true);
|
|
4599
|
-
return `<Monaco :code="'${encoded}'" lang="${lang}" v-bind="${options}" />`;
|
|
4600
|
-
});
|
|
4601
|
-
return md2;
|
|
4602
|
-
}
|
|
4603
|
-
function truncateMancoMark(md2) {
|
|
4604
|
-
return md2.replace(/{monaco.*?}/g, "");
|
|
4605
|
-
}
|
|
4606
|
-
function transformSlotSugar(md2) {
|
|
4607
|
-
const lines = md2.split(/\r?\n/g);
|
|
4608
|
-
let prevSlot = false;
|
|
4609
|
-
const { isLineInsideCodeblocks } = getCodeBlocks(md2);
|
|
4610
|
-
lines.forEach((line, idx) => {
|
|
4611
|
-
if (isLineInsideCodeblocks(idx))
|
|
4612
|
-
return;
|
|
4613
|
-
const match = line.trimEnd().match(/^::\s*(\w+)\s*::$/);
|
|
4614
|
-
if (match) {
|
|
4615
|
-
lines[idx] = `${prevSlot ? "\n\n</template>\n" : "\n"}<template v-slot:${match[1]}="slotProps">
|
|
4616
|
-
`;
|
|
4617
|
-
prevSlot = true;
|
|
4618
|
-
}
|
|
4619
|
-
});
|
|
4620
|
-
if (prevSlot)
|
|
4621
|
-
lines[lines.length - 1] += "\n\n</template>";
|
|
4622
|
-
return lines.join("\n");
|
|
4623
|
-
}
|
|
4624
|
-
function transformHighlighter(md2) {
|
|
4625
|
-
return md2.replace(/^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?\s*?)?\n([\s\S]+?)^```/mg, (full, lang = "", rangeStr = "", options = "", code) => {
|
|
4626
|
-
const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
|
|
4627
|
-
code = code.trimEnd();
|
|
4628
|
-
options = options.trim() || "{}";
|
|
4629
|
-
return `
|
|
4630
|
-
<CodeBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
|
|
4631
|
-
|
|
4632
|
-
\`\`\`${lang}
|
|
4633
|
-
${code}
|
|
4634
|
-
\`\`\`
|
|
4635
|
-
|
|
4636
|
-
</CodeBlockWrapper>`;
|
|
4637
|
-
});
|
|
4638
|
-
}
|
|
4639
|
-
function getCodeBlocks(md2) {
|
|
4640
|
-
const codeblocks = Array.from(md2.matchAll(/^```[\s\S]*?^```/mg)).map((m) => {
|
|
4641
|
-
const start = m.index;
|
|
4642
|
-
const end = m.index + m[0].length;
|
|
4643
|
-
const startLine = md2.slice(0, start).match(/\n/g)?.length || 0;
|
|
4644
|
-
const endLine = md2.slice(0, end).match(/\n/g)?.length || 0;
|
|
4645
|
-
return [start, end, startLine, endLine];
|
|
4646
|
-
});
|
|
4647
|
-
return {
|
|
4648
|
-
codeblocks,
|
|
4649
|
-
isInsideCodeblocks(idx) {
|
|
4650
|
-
return codeblocks.some(([s, e]) => s <= idx && idx <= e);
|
|
4651
|
-
},
|
|
4652
|
-
isLineInsideCodeblocks(line) {
|
|
4653
|
-
return codeblocks.some(([, , s, e]) => s <= line && line <= e);
|
|
4654
|
-
}
|
|
4655
|
-
};
|
|
4656
|
-
}
|
|
4657
|
-
function transformPageCSS(md2, id) {
|
|
4658
|
-
const page = id.match(/(\d+)\.md$/)?.[1];
|
|
4659
|
-
if (!page)
|
|
4660
|
-
return md2;
|
|
4661
|
-
const { isInsideCodeblocks } = getCodeBlocks(md2);
|
|
4662
|
-
const result = md2.replace(
|
|
4663
|
-
/(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g,
|
|
4664
|
-
(full, start, css, end, index) => {
|
|
4665
|
-
if (index < 0 || isInsideCodeblocks(index))
|
|
4666
|
-
return full;
|
|
4667
|
-
if (!start.includes("scoped"))
|
|
4668
|
-
start = start.replace("<style", "<style scoped");
|
|
4669
|
-
return `${start}
|
|
4670
|
-
${css}${end}`;
|
|
4671
|
-
}
|
|
4672
|
-
);
|
|
4673
|
-
return result;
|
|
4674
|
-
}
|
|
4675
|
-
function transformMermaid(md2) {
|
|
4676
|
-
return md2.replace(/^```mermaid\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", code = "") => {
|
|
4677
|
-
code = code.trim();
|
|
4678
|
-
options = options.trim() || "{}";
|
|
4679
|
-
const encoded = base64.encode(code, true);
|
|
4680
|
-
return `<Mermaid :code="'${encoded}'" v-bind="${options}" />`;
|
|
4681
|
-
});
|
|
4682
|
-
}
|
|
4683
|
-
function transformPlantUml(md2, server) {
|
|
4684
|
-
return md2.replace(/^```plantuml\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", content = "") => {
|
|
4685
|
-
const code = encode2(content.trim());
|
|
4686
|
-
options = options.trim() || "{}";
|
|
4687
|
-
return `<PlantUml :code="'${code}'" :server="'${server}'" v-bind="${options}" />`;
|
|
4688
|
-
});
|
|
4689
|
-
}
|
|
4690
|
-
function escapeVueInCode(md2) {
|
|
4691
|
-
return md2.replace(/{{(.*?)}}/g, "{{$1}}");
|
|
4692
|
-
}
|
|
4693
|
-
|
|
4694
|
-
// node/plugins/patchTransform.ts
|
|
4695
|
-
import { objectEntries } from "@antfu/utils";
|
|
4696
|
-
function createFixPlugins(options) {
|
|
4697
|
-
const define = objectEntries(getDefine(options));
|
|
4698
|
-
return [
|
|
4699
|
-
{
|
|
4700
|
-
name: "slidev:flags",
|
|
4701
|
-
enforce: "pre",
|
|
4702
|
-
transform(code, id) {
|
|
4703
|
-
if (id.match(/\.vue($|\?)/)) {
|
|
4704
|
-
const original = code;
|
|
4705
|
-
define.forEach(([from, to]) => {
|
|
4706
|
-
code = code.replace(new RegExp(from, "g"), to);
|
|
4707
|
-
});
|
|
4708
|
-
if (original !== code)
|
|
4709
|
-
return code;
|
|
4710
|
-
}
|
|
4711
|
-
}
|
|
4712
|
-
}
|
|
4713
|
-
];
|
|
4714
|
-
}
|
|
4715
|
-
|
|
4716
|
-
// node/plugins/preset.ts
|
|
4717
|
-
var customElements = /* @__PURE__ */ new Set([
|
|
4718
|
-
// katex
|
|
4719
|
-
"annotation",
|
|
4720
|
-
"math",
|
|
4721
|
-
"menclose",
|
|
4722
|
-
"mfrac",
|
|
4723
|
-
"mglyph",
|
|
4724
|
-
"mi",
|
|
4725
|
-
"mlabeledtr",
|
|
4726
|
-
"mn",
|
|
4727
|
-
"mo",
|
|
4728
|
-
"mover",
|
|
4729
|
-
"mpadded",
|
|
4730
|
-
"mphantom",
|
|
4731
|
-
"mroot",
|
|
4732
|
-
"mrow",
|
|
4733
|
-
"mspace",
|
|
4734
|
-
"msqrt",
|
|
4735
|
-
"mstyle",
|
|
4736
|
-
"msub",
|
|
4737
|
-
"msubsup",
|
|
4738
|
-
"msup",
|
|
4739
|
-
"mtable",
|
|
4740
|
-
"mtd",
|
|
4741
|
-
"mtext",
|
|
4742
|
-
"mtr",
|
|
4743
|
-
"munder",
|
|
4744
|
-
"munderover",
|
|
4745
|
-
"semantics"
|
|
4746
|
-
]);
|
|
4747
|
-
async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
|
|
4748
|
-
const {
|
|
4749
|
-
vue: vueOptions = {},
|
|
4750
|
-
vuejsx: vuejsxOptions = {},
|
|
4751
|
-
components: componentsOptions = {},
|
|
4752
|
-
icons: iconsOptions = {},
|
|
4753
|
-
remoteAssets: remoteAssetsOptions = {},
|
|
4754
|
-
serverRef: serverRefOptions = {}
|
|
4755
|
-
} = pluginOptions;
|
|
4756
|
-
const {
|
|
4757
|
-
mode,
|
|
4758
|
-
themeRoots,
|
|
4759
|
-
addonRoots,
|
|
4760
|
-
clientRoot,
|
|
4761
|
-
data: { config }
|
|
4762
|
-
} = options;
|
|
4763
|
-
const VuePlugin = Vue({
|
|
4764
|
-
include: [/\.vue$/, /\.md$/],
|
|
4765
|
-
exclude: [],
|
|
4766
|
-
template: {
|
|
4767
|
-
compilerOptions: {
|
|
4768
|
-
isCustomElement(tag) {
|
|
4769
|
-
return customElements.has(tag);
|
|
4770
|
-
}
|
|
4771
|
-
},
|
|
4772
|
-
...vueOptions?.template
|
|
4773
|
-
},
|
|
4774
|
-
...vueOptions
|
|
4775
|
-
});
|
|
4776
|
-
const VueJsxPlugin = VueJsx(vuejsxOptions);
|
|
4777
|
-
const MarkdownPlugin = await createMarkdownPlugin(options, pluginOptions);
|
|
4778
|
-
const drawingData = await loadDrawings(options);
|
|
4779
|
-
const publicRoots = themeRoots.map((i) => join8(i, "public")).filter(existsSync4);
|
|
4780
|
-
const plugins = [
|
|
4781
|
-
MarkdownPlugin,
|
|
4782
|
-
VueJsxPlugin,
|
|
4783
|
-
VuePlugin,
|
|
4784
|
-
createSlidesLoader(options, pluginOptions, serverOptions),
|
|
4785
|
-
Components({
|
|
4786
|
-
extensions: ["vue", "md", "js", "ts", "jsx", "tsx"],
|
|
4787
|
-
dirs: [
|
|
4788
|
-
join8(clientRoot, "builtin"),
|
|
4789
|
-
join8(clientRoot, "components"),
|
|
4790
|
-
...themeRoots.map((i) => join8(i, "components")),
|
|
4791
|
-
...addonRoots.map((i) => join8(i, "components")),
|
|
4792
|
-
"src/components",
|
|
4793
|
-
"components"
|
|
4794
|
-
],
|
|
4795
|
-
include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/],
|
|
4796
|
-
exclude: [],
|
|
4797
|
-
resolvers: [
|
|
4798
|
-
IconsResolver({
|
|
4799
|
-
prefix: "",
|
|
4800
|
-
customCollections: Object.keys(iconsOptions.customCollections || [])
|
|
4801
|
-
})
|
|
4802
|
-
],
|
|
4803
|
-
dts: false,
|
|
4804
|
-
...componentsOptions
|
|
4805
|
-
}),
|
|
4806
|
-
Icons({
|
|
4807
|
-
defaultClass: "slidev-icon",
|
|
4808
|
-
autoInstall: true,
|
|
4809
|
-
...iconsOptions
|
|
4810
|
-
}),
|
|
4811
|
-
config.remoteAssets === true || config.remoteAssets === mode ? import("vite-plugin-remote-assets").then((r) => r.default({
|
|
4812
|
-
rules: [
|
|
4813
|
-
...r.DefaultRules,
|
|
4814
|
-
{
|
|
4815
|
-
match: /\b(https?:\/\/image.unsplash\.com.*?)(?=[`'")\]])/ig,
|
|
4816
|
-
ext: ".png"
|
|
4817
|
-
}
|
|
4818
|
-
],
|
|
4819
|
-
resolveMode: (id) => id.endsWith("index.html") ? "relative" : "@fs",
|
|
4820
|
-
awaitDownload: mode === "build",
|
|
4821
|
-
...remoteAssetsOptions
|
|
4822
|
-
})) : null,
|
|
4823
|
-
ServerRef({
|
|
4824
|
-
debug: process3.env.NODE_ENV === "development",
|
|
4825
|
-
state: {
|
|
4826
|
-
sync: false,
|
|
4827
|
-
nav: {
|
|
4828
|
-
page: 0,
|
|
4829
|
-
clicks: 0
|
|
4830
|
-
},
|
|
4831
|
-
drawings: drawingData,
|
|
4832
|
-
...serverRefOptions.state
|
|
4833
|
-
},
|
|
4834
|
-
onChanged(key, data, patch, timestamp2) {
|
|
4835
|
-
serverRefOptions.onChanged && serverRefOptions.onChanged(key, data, patch, timestamp2);
|
|
4836
|
-
if (!options.data.config.drawings.persist)
|
|
4837
|
-
return;
|
|
4838
|
-
if (key === "drawings")
|
|
4839
|
-
writeDrawings(options, patch ?? data);
|
|
4840
|
-
}
|
|
4841
|
-
}),
|
|
4842
|
-
createConfigPlugin(options),
|
|
4843
|
-
createClientSetupPlugin(options),
|
|
4844
|
-
createMonacoTypesLoader(),
|
|
4845
|
-
createFixPlugins(options),
|
|
4846
|
-
publicRoots.length ? import("vite-plugin-static-copy").then((r) => r.viteStaticCopy({
|
|
4847
|
-
silent: true,
|
|
4848
|
-
targets: publicRoots.map((r2) => ({
|
|
4849
|
-
src: `${r2}/*`,
|
|
4850
|
-
dest: "theme"
|
|
4851
|
-
}))
|
|
4852
|
-
})) : null,
|
|
4853
|
-
options.inspect ? import("vite-plugin-inspect").then((r) => (r.default || r)({
|
|
4854
|
-
dev: true,
|
|
4855
|
-
build: true
|
|
4856
|
-
})) : null,
|
|
4857
|
-
config.css === "none" ? null : config.css === "windicss" ? import("./windicss-UVXCUIV4.mjs").then((r) => r.createWindiCSSPlugin(options, pluginOptions)) : import("./unocss-2UOAV4VT.mjs").then((r) => r.createUnocssPlugin(options, pluginOptions))
|
|
4858
|
-
];
|
|
4859
|
-
return (await Promise.all(plugins)).flat().filter(notNullish2);
|
|
4860
|
-
}
|
|
4861
|
-
|
|
4862
|
-
export {
|
|
4863
|
-
getIndexHtml,
|
|
4864
|
-
mergeViteConfigs,
|
|
4865
|
-
require_fast_deep_equal,
|
|
4866
|
-
ViteSlidevPlugin
|
|
4867
|
-
};
|
|
4868
|
-
/*! Bundled license information:
|
|
4869
|
-
|
|
4870
|
-
js-yaml/dist/js-yaml.mjs:
|
|
4871
|
-
(*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
|
|
4872
|
-
*/
|