@wazootech/linked-markdown 0.0.0-stage → 0.1.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2847 @@
1
+ // node_modules/@std/front-matter/_shared.js
2
+ function extractFrontMatter(input, extractRegExp) {
3
+ const groups = extractRegExp.exec(input)?.groups;
4
+ if (!groups) throw new TypeError("Unexpected end of input");
5
+ const { frontMatter = "", body = "" } = groups;
6
+ return {
7
+ frontMatter,
8
+ body
9
+ };
10
+ }
11
+ // node_modules/@std/front-matter/_formats.js
12
+ /**
13
+ * Supported format for front matter. `"unknown"` is used when auto format
14
+ * detection logic fails.
15
+ */ const BOM = "\\ufeff?";
16
+ const YAML_HEADER = `${BOM}(?:---yaml|= yaml =|---)`;
17
+ const YAML_FOOTER = `(?:= yaml =|---)`;
18
+ const TOML_HEADER = `${BOM}(?:---toml|\\+\\+\\+|= toml =)`;
19
+ const TOML_FOOTER = `(?:---|\\+\\+\\+|= toml =)`;
20
+ const JSON_HEADER = `${BOM}(?:---json|= json =)`;
21
+ const JSON_FOOTER = `(?:---|= json =)`;
22
+ const WHITESPACES = "\\s*";
23
+ const NEWLINE = "\\r?\\n";
24
+ const FRONT_MATTER = "(?<frontMatter>.+?)";
25
+ const BODY = "(?:\\r?\\n(?<body>.+))?";
26
+ new RegExp(`^${YAML_HEADER}${WHITESPACES}${NEWLINE}`, "i");
27
+ new RegExp(`^${TOML_HEADER}${WHITESPACES}${NEWLINE}`, "i");
28
+ new RegExp(`^${JSON_HEADER}${WHITESPACES}${NEWLINE}`, "i");
29
+ const EXTRACT_YAML_REGEXP = new RegExp(`^${YAML_HEADER}${WHITESPACES}${NEWLINE}${WHITESPACES}(?:${FRONT_MATTER}${WHITESPACES}${NEWLINE})?${YAML_FOOTER}${WHITESPACES}${BODY}$`, "is");
30
+ const EXTRACT_TOML_REGEXP = new RegExp(`^${TOML_HEADER}${WHITESPACES}${NEWLINE}${WHITESPACES}(?:${FRONT_MATTER}${WHITESPACES}${NEWLINE})?${TOML_FOOTER}${WHITESPACES}${BODY}$`, "is");
31
+ const EXTRACT_JSON_REGEXP = new RegExp(`^${JSON_HEADER}${WHITESPACES}${NEWLINE}${WHITESPACES}(?:${FRONT_MATTER}${WHITESPACES}${NEWLINE})?${JSON_FOOTER}${WHITESPACES}${BODY}$`, "is");
32
+ const EXTRACT_REGEXP_MAP = /* @__PURE__ */ new Map([
33
+ ["yaml", EXTRACT_YAML_REGEXP],
34
+ ["toml", EXTRACT_TOML_REGEXP],
35
+ ["json", EXTRACT_JSON_REGEXP]
36
+ ]);
37
+ // node_modules/@std/front-matter/json.js
38
+ /**
39
+ * Extracts and parses {@link https://www.json.org/ | JSON } from the metadata
40
+ * of front matter content.
41
+ *
42
+ * @example Extract JSON front matter
43
+ * ```ts
44
+ * import { extract } from "@std/front-matter/json";
45
+ * import { assertEquals } from "@std/assert";
46
+ *
47
+ * const output = `---json
48
+ * { "title": "Three dashes marks the spot" }
49
+ * ---
50
+ * Hello, world!`;
51
+ * const result = extract(output);
52
+ *
53
+ * assertEquals(result, {
54
+ * frontMatter: '{ "title": "Three dashes marks the spot" }',
55
+ * body: "Hello, world!",
56
+ * attrs: { title: "Three dashes marks the spot" },
57
+ * });
58
+ * ```
59
+ *
60
+ * @typeParam T The type of the parsed front matter.
61
+ * @param text The text to extract JSON front matter from.
62
+ * @returns The extracted JSON front matter and body content.
63
+ */ function extract$3(text) {
64
+ const { frontMatter, body } = extractFrontMatter(text, EXTRACT_JSON_REGEXP);
65
+ return {
66
+ frontMatter,
67
+ body,
68
+ attrs: frontMatter ? JSON.parse(frontMatter) : {}
69
+ };
70
+ }
71
+ // node_modules/@jsr/std__collections/deep_merge.js
72
+ /** Default merging options - cached to avoid object allocation on each call */ const DEFAULT_OPTIONS = {
73
+ arrays: "merge",
74
+ sets: "merge",
75
+ maps: "merge"
76
+ };
77
+ function deepMerge(record, other, options) {
78
+ return deepMergeInternal(record, other, /* @__PURE__ */ new Set(), options ?? DEFAULT_OPTIONS);
79
+ }
80
+ function deepMergeInternal(record, other, seen, options) {
81
+ const result = {};
82
+ const keys = /* @__PURE__ */ new Set([...getKeys(record), ...getKeys(other)]);
83
+ for (const key of keys) {
84
+ if (key === "__proto__") continue;
85
+ const a = record[key];
86
+ if (!Object.hasOwn(other, key)) {
87
+ result[key] = a;
88
+ continue;
89
+ }
90
+ const b = other[key];
91
+ if (isNonNullObject(a) && isNonNullObject(b) && !seen.has(a) && !seen.has(b)) {
92
+ seen.add(a);
93
+ seen.add(b);
94
+ result[key] = mergeObjects(a, b, seen, options);
95
+ continue;
96
+ }
97
+ result[key] = b;
98
+ }
99
+ return result;
100
+ }
101
+ function mergeObjects(left, right, seen, options) {
102
+ if (isMergeable(left) && isMergeable(right)) return deepMergeInternal(left, right, seen, options);
103
+ if (isIterable(left) && isIterable(right)) {
104
+ if (Array.isArray(left) && Array.isArray(right)) {
105
+ if (options.arrays === "merge") return left.concat(right);
106
+ return right;
107
+ }
108
+ if (left instanceof Map && right instanceof Map) {
109
+ if (options.maps === "merge") {
110
+ const result = new Map(left);
111
+ for (const [k, v] of right) result.set(k, v);
112
+ return result;
113
+ }
114
+ return right;
115
+ }
116
+ if (left instanceof Set && right instanceof Set) {
117
+ if (options.sets === "merge") {
118
+ const result = new Set(left);
119
+ for (const v of right) result.add(v);
120
+ return result;
121
+ }
122
+ return right;
123
+ }
124
+ }
125
+ return right;
126
+ }
127
+ /**
128
+ * Test whether a value is mergeable or not
129
+ * Builtins that look like objects, null and user defined classes
130
+ * are not considered mergeable (it means that reference will be copied)
131
+ */ function isMergeable(value) {
132
+ return Object.getPrototypeOf(value) === Object.prototype;
133
+ }
134
+ function isIterable(value) {
135
+ return typeof value[Symbol.iterator] === "function";
136
+ }
137
+ function isNonNullObject(value) {
138
+ return value !== null && typeof value === "object";
139
+ }
140
+ function getKeys(record) {
141
+ const keys = Object.keys(record);
142
+ const symbols = Object.getOwnPropertySymbols(record);
143
+ if (symbols.length === 0) return keys;
144
+ for (const sym of symbols) if (Object.prototype.propertyIsEnumerable.call(record, sym)) keys.push(sym);
145
+ return keys;
146
+ }
147
+ // node_modules/@jsr/std__toml/_parser.js
148
+ /**
149
+ * Copy of `import { isLeap } from "@std/datetime";` because it cannot be impoted as long as it is unstable.
150
+ */ function isLeap(yearNumber) {
151
+ return yearNumber % 4 === 0 && yearNumber % 100 !== 0 || yearNumber % 400 === 0;
152
+ }
153
+ var Scanner$1 = class {
154
+ #whitespace = /[ \t]/;
155
+ #position = 0;
156
+ #source;
157
+ constructor(source) {
158
+ this.#source = source;
159
+ }
160
+ get position() {
161
+ return this.#position;
162
+ }
163
+ get source() {
164
+ return this.#source;
165
+ }
166
+ /**
167
+ * Get current character
168
+ * @param index - relative index from current position
169
+ */ char(index = 0) {
170
+ return this.#source[this.#position + index] ?? "";
171
+ }
172
+ /**
173
+ * Get sliced string
174
+ * @param start - start position relative from current position
175
+ * @param end - end position relative from current position
176
+ */ slice(start, end) {
177
+ return this.#source.slice(this.#position + start, this.#position + end);
178
+ }
179
+ /**
180
+ * Move position to next
181
+ */ next(count = 1) {
182
+ this.#position += count;
183
+ }
184
+ skipWhitespaces() {
185
+ while (this.#whitespace.test(this.char()) && !this.eof()) this.next();
186
+ if (!this.isCurrentCharEOL() && /\s/.test(this.char())) {
187
+ const escaped = "\\u" + this.char().charCodeAt(0).toString(16);
188
+ const position = this.#position;
189
+ throw new SyntaxError(`Cannot parse the TOML: It contains invalid whitespace at position '${position}': \`${escaped}\``);
190
+ }
191
+ }
192
+ nextUntilChar(options = { skipComments: true }) {
193
+ while (!this.eof()) {
194
+ const char = this.char();
195
+ if (this.#whitespace.test(char) || this.isCurrentCharEOL()) this.next();
196
+ else if (options.skipComments && this.char() === "#") while (!this.isCurrentCharEOL() && !this.eof()) this.next();
197
+ else break;
198
+ }
199
+ }
200
+ /**
201
+ * Position reached EOF or not
202
+ */ eof() {
203
+ return this.#position >= this.#source.length;
204
+ }
205
+ isCurrentCharEOL() {
206
+ return this.char() === "\n" || this.startsWith("\r\n");
207
+ }
208
+ startsWith(searchString) {
209
+ return this.#source.startsWith(searchString, this.#position);
210
+ }
211
+ match(regExp) {
212
+ if (!regExp.sticky) throw new Error(`RegExp ${regExp} does not have a sticky 'y' flag`);
213
+ regExp.lastIndex = this.#position;
214
+ return this.#source.match(regExp);
215
+ }
216
+ };
217
+ function success(body) {
218
+ return {
219
+ ok: true,
220
+ body
221
+ };
222
+ }
223
+ function failure() {
224
+ return { ok: false };
225
+ }
226
+ /**
227
+ * Creates a nested object from the keys and values.
228
+ *
229
+ * e.g. `unflat(["a", "b", "c"], 1)` returns `{ a: { b: { c: 1 } } }`
230
+ */ function unflat(keys, values = { __proto__: null }) {
231
+ return keys.reduceRight((acc, key) => ({ [key]: acc }), values);
232
+ }
233
+ function isObject$1(value) {
234
+ return typeof value === "object" && value !== null;
235
+ }
236
+ function getTargetValue(target, keys) {
237
+ const key = keys[0];
238
+ if (!key) throw new Error("Cannot parse the TOML: key length is not a positive number");
239
+ return target[key];
240
+ }
241
+ function deepAssignTable(target, table) {
242
+ const { keys, type, value } = table;
243
+ const currentValue = getTargetValue(target, keys);
244
+ if (currentValue === void 0) return Object.assign(target, unflat(keys, value));
245
+ if (Array.isArray(currentValue)) {
246
+ deepAssign(currentValue.at(-1), {
247
+ type,
248
+ keys: keys.slice(1),
249
+ value
250
+ });
251
+ return target;
252
+ }
253
+ if (isObject$1(currentValue)) {
254
+ deepAssign(currentValue, {
255
+ type,
256
+ keys: keys.slice(1),
257
+ value
258
+ });
259
+ return target;
260
+ }
261
+ throw new Error("Unexpected assign");
262
+ }
263
+ function deepAssignTableArray(target, table) {
264
+ const { type, keys, value } = table;
265
+ const currentValue = getTargetValue(target, keys);
266
+ if (currentValue === void 0) return Object.assign(target, unflat(keys, [value]));
267
+ if (Array.isArray(currentValue)) {
268
+ if (table.keys.length === 1) currentValue.push(value);
269
+ else deepAssign(currentValue.at(-1), {
270
+ type: table.type,
271
+ keys: table.keys.slice(1),
272
+ value: table.value
273
+ });
274
+ return target;
275
+ }
276
+ if (isObject$1(currentValue)) {
277
+ deepAssign(currentValue, {
278
+ type,
279
+ keys: keys.slice(1),
280
+ value
281
+ });
282
+ return target;
283
+ }
284
+ throw new Error("Unexpected assign");
285
+ }
286
+ function deepAssign(target, body) {
287
+ switch (body.type) {
288
+ case "Block": return deepMerge(target, body.value);
289
+ case "Table": return deepAssignTable(target, body);
290
+ case "TableArray": return deepAssignTableArray(target, body);
291
+ }
292
+ }
293
+ function or(parsers) {
294
+ return (scanner) => {
295
+ for (const parse of parsers) {
296
+ const result = parse(scanner);
297
+ if (result.ok) return result;
298
+ }
299
+ return failure();
300
+ };
301
+ }
302
+ /** Join the parse results of the given parser into an array.
303
+ *
304
+ * If the parser fails at the first attempt, it will return an empty array.
305
+ */ function join(parser, separator) {
306
+ const Separator = character(separator);
307
+ return (scanner) => {
308
+ const out = [];
309
+ const first = parser(scanner);
310
+ if (!first.ok) return success(out);
311
+ out.push(first.body);
312
+ while (!scanner.eof()) {
313
+ if (!Separator(scanner).ok) break;
314
+ const result = parser(scanner);
315
+ if (!result.ok) throw new SyntaxError(`Invalid token after "${separator}"`);
316
+ out.push(result.body);
317
+ }
318
+ return success(out);
319
+ };
320
+ }
321
+ /** Join the parse results of the given parser into an array.
322
+ *
323
+ * This requires the parser to succeed at least once.
324
+ */ function join1(parser, separator) {
325
+ const Separator = character(separator);
326
+ return (scanner) => {
327
+ const first = parser(scanner);
328
+ if (!first.ok) return failure();
329
+ const out = [first.body];
330
+ while (!scanner.eof()) {
331
+ if (!Separator(scanner).ok) break;
332
+ const result = parser(scanner);
333
+ if (!result.ok) throw new SyntaxError(`Invalid token after "${separator}"`);
334
+ out.push(result.body);
335
+ }
336
+ return success(out);
337
+ };
338
+ }
339
+ function kv(keyParser, separator, valueParser) {
340
+ const Separator = character(separator);
341
+ return (scanner) => {
342
+ const position = scanner.position;
343
+ const key = keyParser(scanner);
344
+ if (!key.ok) return failure();
345
+ if (!Separator(scanner).ok) throw new SyntaxError(`key/value pair doesn't have "${separator}"`);
346
+ const value = valueParser(scanner);
347
+ if (!value.ok) {
348
+ const lineEndIndex = scanner.source.indexOf("\n", scanner.position);
349
+ const endPosition = lineEndIndex > 0 ? lineEndIndex : scanner.source.length;
350
+ const line = scanner.source.slice(position, endPosition);
351
+ throw new SyntaxError(`Cannot parse value on line '${line}'`);
352
+ }
353
+ return success(unflat(key.body, value.body));
354
+ };
355
+ }
356
+ function merge$1(parser) {
357
+ return (scanner) => {
358
+ const result = parser(scanner);
359
+ if (!result.ok) return failure();
360
+ let body = { __proto__: null };
361
+ for (const record of result.body) if (typeof record === "object" && record !== null) body = deepMerge(body, record);
362
+ return success(body);
363
+ };
364
+ }
365
+ function repeat(parser) {
366
+ return (scanner) => {
367
+ const body = [];
368
+ while (!scanner.eof()) {
369
+ const result = parser(scanner);
370
+ if (!result.ok) break;
371
+ body.push(result.body);
372
+ scanner.nextUntilChar();
373
+ }
374
+ if (body.length === 0) return failure();
375
+ return success(body);
376
+ };
377
+ }
378
+ function surround(left, parser, right) {
379
+ const Left = character(left);
380
+ const Right = character(right);
381
+ return (scanner) => {
382
+ if (!Left(scanner).ok) return failure();
383
+ const result = parser(scanner);
384
+ if (!result.ok) throw new SyntaxError(`Invalid token after "${left}"`);
385
+ if (!Right(scanner).ok) throw new SyntaxError(`Not closed by "${right}" after started with "${left}"`);
386
+ return success(result.body);
387
+ };
388
+ }
389
+ function character(str) {
390
+ return (scanner) => {
391
+ scanner.skipWhitespaces();
392
+ if (!scanner.startsWith(str)) return failure();
393
+ scanner.next(str.length);
394
+ scanner.skipWhitespaces();
395
+ return success(void 0);
396
+ };
397
+ }
398
+ const BARE_KEY_REGEXP = /[A-Za-z0-9_-]+/y;
399
+ function bareKey(scanner) {
400
+ scanner.skipWhitespaces();
401
+ const key = scanner.match(BARE_KEY_REGEXP)?.[0];
402
+ if (!key) return failure();
403
+ scanner.next(key.length);
404
+ return success(key);
405
+ }
406
+ function escapeSequence(scanner) {
407
+ if (scanner.char() !== "\\") return failure();
408
+ scanner.next();
409
+ switch (scanner.char()) {
410
+ case "b":
411
+ scanner.next();
412
+ return success("\b");
413
+ case "t":
414
+ scanner.next();
415
+ return success(" ");
416
+ case "n":
417
+ scanner.next();
418
+ return success("\n");
419
+ case "f":
420
+ scanner.next();
421
+ return success("\f");
422
+ case "r":
423
+ scanner.next();
424
+ return success("\r");
425
+ case "u":
426
+ case "U": {
427
+ const codePointLen = scanner.char() === "u" ? 4 : 6;
428
+ const codePoint = parseInt("0x" + scanner.slice(1, 1 + codePointLen), 16);
429
+ const str = String.fromCodePoint(codePoint);
430
+ scanner.next(codePointLen + 1);
431
+ return success(str);
432
+ }
433
+ case "\"":
434
+ scanner.next();
435
+ return success("\"");
436
+ case "\\":
437
+ scanner.next();
438
+ return success("\\");
439
+ default: throw new SyntaxError(`Invalid escape sequence: \\${scanner.char()}`);
440
+ }
441
+ }
442
+ function basicString(scanner) {
443
+ scanner.skipWhitespaces();
444
+ if (scanner.char() !== "\"") return failure();
445
+ scanner.next();
446
+ const acc = [];
447
+ while (scanner.char() !== "\"" && !scanner.eof()) {
448
+ if (scanner.char() === "\n") throw new SyntaxError("Single-line string cannot contain EOL");
449
+ const escapedChar = escapeSequence(scanner);
450
+ if (escapedChar.ok) acc.push(escapedChar.body);
451
+ else {
452
+ acc.push(scanner.char());
453
+ scanner.next();
454
+ }
455
+ }
456
+ if (scanner.eof()) throw new SyntaxError(`Single-line string is not closed:\n${acc.join("")}`);
457
+ scanner.next();
458
+ return success(acc.join(""));
459
+ }
460
+ function literalString(scanner) {
461
+ scanner.skipWhitespaces();
462
+ if (scanner.char() !== "'") return failure();
463
+ scanner.next();
464
+ const acc = [];
465
+ while (scanner.char() !== "'" && !scanner.eof()) {
466
+ if (scanner.char() === "\n") throw new SyntaxError("Single-line string cannot contain EOL");
467
+ acc.push(scanner.char());
468
+ scanner.next();
469
+ }
470
+ if (scanner.eof()) throw new SyntaxError(`Single-line string is not closed:\n${acc.join("")}`);
471
+ scanner.next();
472
+ return success(acc.join(""));
473
+ }
474
+ function multilineBasicString(scanner) {
475
+ scanner.skipWhitespaces();
476
+ if (!scanner.startsWith("\"\"\"")) return failure();
477
+ scanner.next(3);
478
+ if (scanner.char() === "\n") scanner.next();
479
+ else if (scanner.startsWith("\r\n")) scanner.next(2);
480
+ const acc = [];
481
+ while (!scanner.startsWith("\"\"\"") && !scanner.eof()) {
482
+ if (scanner.startsWith("\\\n")) {
483
+ scanner.next();
484
+ scanner.nextUntilChar({ skipComments: false });
485
+ continue;
486
+ } else if (scanner.startsWith("\\\r\n")) {
487
+ scanner.next();
488
+ scanner.nextUntilChar({ skipComments: false });
489
+ continue;
490
+ }
491
+ const escapedChar = escapeSequence(scanner);
492
+ if (escapedChar.ok) acc.push(escapedChar.body);
493
+ else {
494
+ acc.push(scanner.char());
495
+ scanner.next();
496
+ }
497
+ }
498
+ if (scanner.eof()) throw new SyntaxError(`Multi-line string is not closed:\n${acc.join("")}`);
499
+ if (scanner.char(3) === "\"") {
500
+ acc.push("\"");
501
+ scanner.next();
502
+ }
503
+ scanner.next(3);
504
+ return success(acc.join(""));
505
+ }
506
+ function multilineLiteralString(scanner) {
507
+ scanner.skipWhitespaces();
508
+ if (!scanner.startsWith("'''")) return failure();
509
+ scanner.next(3);
510
+ if (scanner.char() === "\n") scanner.next();
511
+ else if (scanner.startsWith("\r\n")) scanner.next(2);
512
+ const acc = [];
513
+ while (!scanner.startsWith("'''") && !scanner.eof()) {
514
+ acc.push(scanner.char());
515
+ scanner.next();
516
+ }
517
+ if (scanner.eof()) throw new SyntaxError(`Multi-line string is not closed:\n${acc.join("")}`);
518
+ if (scanner.char(3) === "'") {
519
+ acc.push("'");
520
+ scanner.next();
521
+ }
522
+ scanner.next(3);
523
+ return success(acc.join(""));
524
+ }
525
+ const BOOLEAN_REGEXP = /(?:true|false)\b/y;
526
+ function boolean(scanner) {
527
+ scanner.skipWhitespaces();
528
+ const match = scanner.match(BOOLEAN_REGEXP);
529
+ if (!match) return failure();
530
+ const string = match[0];
531
+ scanner.next(string.length);
532
+ return success(string === "true");
533
+ }
534
+ const INFINITY_MAP = /* @__PURE__ */ new Map([
535
+ ["inf", 1e400],
536
+ ["+inf", 1e400],
537
+ ["-inf", -1e400]
538
+ ]);
539
+ const INFINITY_REGEXP = /[+-]?inf\b/y;
540
+ function infinity(scanner) {
541
+ scanner.skipWhitespaces();
542
+ const match = scanner.match(INFINITY_REGEXP);
543
+ if (!match) return failure();
544
+ const string = match[0];
545
+ scanner.next(string.length);
546
+ return success(INFINITY_MAP.get(string));
547
+ }
548
+ const NAN_REGEXP = /[+-]?nan\b/y;
549
+ function nan(scanner) {
550
+ scanner.skipWhitespaces();
551
+ const match = scanner.match(NAN_REGEXP);
552
+ if (!match) return failure();
553
+ const string = match[0];
554
+ scanner.next(string.length);
555
+ return success(NaN);
556
+ }
557
+ const dottedKey = join1(or([
558
+ bareKey,
559
+ basicString,
560
+ literalString
561
+ ]), ".");
562
+ const BINARY_REGEXP = /0b[01]+(?:_[01]+)*\b/y;
563
+ function binary$1(scanner) {
564
+ scanner.skipWhitespaces();
565
+ const match = scanner.match(BINARY_REGEXP)?.[0];
566
+ if (!match) return failure();
567
+ scanner.next(match.length);
568
+ const value = match.slice(2).replaceAll("_", "");
569
+ const number = parseInt(value, 2);
570
+ return isNaN(number) ? failure() : success(number);
571
+ }
572
+ const OCTAL_REGEXP = /0o[0-7]+(?:_[0-7]+)*\b/y;
573
+ function octal(scanner) {
574
+ scanner.skipWhitespaces();
575
+ const match = scanner.match(OCTAL_REGEXP)?.[0];
576
+ if (!match) return failure();
577
+ scanner.next(match.length);
578
+ const value = match.slice(2).replaceAll("_", "");
579
+ const number = parseInt(value, 8);
580
+ return isNaN(number) ? failure() : success(number);
581
+ }
582
+ const HEX_REGEXP = /0x[0-9a-f]+(?:_[0-9a-f]+)*\b/iy;
583
+ function hex(scanner) {
584
+ scanner.skipWhitespaces();
585
+ const match = scanner.match(HEX_REGEXP)?.[0];
586
+ if (!match) return failure();
587
+ scanner.next(match.length);
588
+ const value = match.slice(2).replaceAll("_", "");
589
+ const number = parseInt(value, 16);
590
+ return isNaN(number) ? failure() : success(number);
591
+ }
592
+ const INTEGER_REGEXP = /[+-]?(?:0|[1-9][0-9]*(?:_[0-9]+)*)\b/y;
593
+ function integer(scanner) {
594
+ scanner.skipWhitespaces();
595
+ const match = scanner.match(INTEGER_REGEXP)?.[0];
596
+ if (!match) return failure();
597
+ scanner.next(match.length);
598
+ const value = match.replaceAll("_", "");
599
+ return success(parseInt(value, 10));
600
+ }
601
+ const FLOAT_REGEXP = /[+-]?(?:0|[1-9][0-9]*(?:_[0-9]+)*)(?:\.[0-9]+(?:_[0-9]+)*)?(?:e[+-]?[0-9]+(?:_[0-9]+)*)?\b/iy;
602
+ function float$1(scanner) {
603
+ scanner.skipWhitespaces();
604
+ const match = scanner.match(FLOAT_REGEXP)?.[0];
605
+ if (!match) return failure();
606
+ scanner.next(match.length);
607
+ const value = match.replaceAll("_", "");
608
+ const float = parseFloat(value);
609
+ if (isNaN(float)) return failure();
610
+ return success(float);
611
+ }
612
+ const DATE_TIME_REGEXP = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})(?:[ 0-9TZ.:+-]+)?\b/y;
613
+ function dateTime(scanner) {
614
+ scanner.skipWhitespaces();
615
+ const match = scanner.match(DATE_TIME_REGEXP);
616
+ if (!match) return failure();
617
+ const string = match[0];
618
+ scanner.next(string.length);
619
+ const groups = match.groups;
620
+ if (groups.month == "02") {
621
+ const days = parseInt(groups.day);
622
+ if (days > 29) throw new SyntaxError(`Invalid date string "${match}"`);
623
+ const year = parseInt(groups.year);
624
+ if (days > 28 && !isLeap(year)) throw new SyntaxError(`Invalid date string "${match}"`);
625
+ }
626
+ const date = new Date(string.trim());
627
+ if (isNaN(date.getTime())) throw new SyntaxError(`Invalid date string "${match}"`);
628
+ return success(date);
629
+ }
630
+ const LOCAL_TIME_REGEXP = /(\d{2}):(\d{2}):(\d{2})(?:\.[0-9]+)?\b/y;
631
+ function localTime(scanner) {
632
+ scanner.skipWhitespaces();
633
+ const match = scanner.match(LOCAL_TIME_REGEXP)?.[0];
634
+ if (!match) return failure();
635
+ scanner.next(match.length);
636
+ return success(match);
637
+ }
638
+ function arrayValue(scanner) {
639
+ scanner.skipWhitespaces();
640
+ if (scanner.char() !== "[") return failure();
641
+ scanner.next();
642
+ const array = [];
643
+ while (!scanner.eof()) {
644
+ scanner.nextUntilChar();
645
+ const result = value(scanner);
646
+ if (!result.ok) break;
647
+ array.push(result.body);
648
+ scanner.skipWhitespaces();
649
+ if (scanner.char() !== ",") break;
650
+ scanner.next();
651
+ }
652
+ scanner.nextUntilChar();
653
+ if (scanner.char() !== "]") throw new SyntaxError("Array is not closed");
654
+ scanner.next();
655
+ return success(array);
656
+ }
657
+ function inlineTable(scanner) {
658
+ scanner.nextUntilChar();
659
+ if (scanner.char(1) === "}") {
660
+ scanner.next(2);
661
+ return success({ __proto__: null });
662
+ }
663
+ const pairs = surround("{", join(pair, ","), "}")(scanner);
664
+ if (!pairs.ok) return failure();
665
+ let table = { __proto__: null };
666
+ for (const pair of pairs.body) table = deepMerge(table, pair);
667
+ return success(table);
668
+ }
669
+ const value = or([
670
+ multilineBasicString,
671
+ multilineLiteralString,
672
+ basicString,
673
+ literalString,
674
+ boolean,
675
+ infinity,
676
+ nan,
677
+ dateTime,
678
+ localTime,
679
+ binary$1,
680
+ octal,
681
+ hex,
682
+ float$1,
683
+ integer,
684
+ arrayValue,
685
+ inlineTable
686
+ ]);
687
+ const pair = kv(dottedKey, "=", value);
688
+ function block(scanner) {
689
+ scanner.nextUntilChar();
690
+ const result = merge$1(repeat(pair))(scanner);
691
+ if (result.ok) return success({
692
+ type: "Block",
693
+ value: result.body
694
+ });
695
+ return failure();
696
+ }
697
+ const tableHeader = surround("[", dottedKey, "]");
698
+ function table(scanner) {
699
+ scanner.nextUntilChar();
700
+ const header = tableHeader(scanner);
701
+ if (!header.ok) return failure();
702
+ scanner.nextUntilChar();
703
+ const b = block(scanner);
704
+ return success({
705
+ type: "Table",
706
+ keys: header.body,
707
+ value: b.ok ? b.body.value : { __proto__: null }
708
+ });
709
+ }
710
+ const tableArrayHeader = surround("[[", dottedKey, "]]");
711
+ function tableArray(scanner) {
712
+ scanner.nextUntilChar();
713
+ const header = tableArrayHeader(scanner);
714
+ if (!header.ok) return failure();
715
+ scanner.nextUntilChar();
716
+ const b = block(scanner);
717
+ return success({
718
+ type: "TableArray",
719
+ keys: header.body,
720
+ value: b.ok ? b.body.value : { __proto__: null }
721
+ });
722
+ }
723
+ function toml(scanner) {
724
+ const blocks = repeat(or([
725
+ block,
726
+ tableArray,
727
+ table
728
+ ]))(scanner);
729
+ if (!blocks.ok) return success({ __proto__: null });
730
+ return success(blocks.body.reduce(deepAssign, { __proto__: null }));
731
+ }
732
+ function createParseErrorMessage(scanner, message) {
733
+ const lines = scanner.source.slice(0, scanner.position).split("\n");
734
+ return `Parse error on line ${lines.length}, column ${lines.at(-1)?.length ?? 0}: ${message}`;
735
+ }
736
+ function parserFactory(parser) {
737
+ return (tomlString) => {
738
+ const scanner = new Scanner$1(tomlString);
739
+ try {
740
+ const result = parser(scanner);
741
+ if (result.ok && scanner.eof()) return result.body;
742
+ const message = `Unexpected character: "${scanner.char()}"`;
743
+ throw new SyntaxError(createParseErrorMessage(scanner, message));
744
+ } catch (error) {
745
+ if (error instanceof Error) throw new SyntaxError(createParseErrorMessage(scanner, error.message));
746
+ throw new SyntaxError(createParseErrorMessage(scanner, "Invalid error type caught"));
747
+ }
748
+ };
749
+ }
750
+ // node_modules/@jsr/std__toml/parse.js
751
+ /**
752
+ * Parses a {@link https://toml.io | TOML} string into an object.
753
+ *
754
+ * @example Usage
755
+ * ```ts
756
+ * import { parse } from "@std/toml/parse";
757
+ * import { assertEquals } from "@std/assert";
758
+ *
759
+ * const tomlString = `title = "TOML Example"
760
+ * [owner]
761
+ * name = "Alice"
762
+ * bio = "Alice is a programmer."`;
763
+ *
764
+ * const obj = parse(tomlString);
765
+ * assertEquals(obj, { title: "TOML Example", owner: { name: "Alice", bio: "Alice is a programmer." } });
766
+ * ```
767
+ * @param tomlString TOML string to be parsed.
768
+ * @returns The parsed JS object.
769
+ */ function parse$1(tomlString) {
770
+ return parserFactory(toml)(tomlString);
771
+ }
772
+ // node_modules/@std/front-matter/toml.js
773
+ /**
774
+ * Extracts and parses {@link https://toml.io | TOML} from the metadata of
775
+ * front matter content.
776
+ *
777
+ * @example Extract TOML front matter
778
+ * ```ts
779
+ * import { extract } from "@std/front-matter/toml";
780
+ * import { assertEquals } from "@std/assert";
781
+ *
782
+ * const output = `---toml
783
+ * title = "Three dashes marks the spot"
784
+ * ---
785
+ * Hello, world!`;
786
+ * const result = extract(output);
787
+ *
788
+ * assertEquals(result, {
789
+ * frontMatter: 'title = "Three dashes marks the spot"',
790
+ * body: "Hello, world!",
791
+ * attrs: { title: "Three dashes marks the spot" },
792
+ * });
793
+ * ```
794
+ *
795
+ * @typeParam T The type of the parsed front matter.
796
+ * @param text The text to extract TOML front matter from.
797
+ * @returns The extracted TOML front matter and body content.
798
+ */ function extract$2(text) {
799
+ const { frontMatter, body } = extractFrontMatter(text, EXTRACT_TOML_REGEXP);
800
+ return {
801
+ frontMatter,
802
+ body,
803
+ attrs: frontMatter ? parse$1(frontMatter) : {}
804
+ };
805
+ }
806
+ function isEOL(c) {
807
+ return c === 10 || c === 13;
808
+ }
809
+ function isWhiteSpace(c) {
810
+ return c === 9 || c === 32;
811
+ }
812
+ function isWhiteSpaceOrEOL(c) {
813
+ return isWhiteSpace(c) || isEOL(c);
814
+ }
815
+ function isFlowIndicator(c) {
816
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
817
+ }
818
+ // node_modules/@jsr/std__yaml/_type/binary.js
819
+ const BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
820
+ function resolveYamlBinary(data) {
821
+ if (data === null) return false;
822
+ let code;
823
+ let bitlen = 0;
824
+ const max = data.length;
825
+ const map = BASE64_MAP;
826
+ for (let idx = 0; idx < max; idx++) {
827
+ code = map.indexOf(data.charAt(idx));
828
+ if (code > 64) continue;
829
+ if (code < 0) return false;
830
+ bitlen += 6;
831
+ }
832
+ return bitlen % 8 === 0;
833
+ }
834
+ function constructYamlBinary(data) {
835
+ const input = data.replace(/[\r\n=]/g, "");
836
+ const max = input.length;
837
+ const map = BASE64_MAP;
838
+ const result = [];
839
+ let bits = 0;
840
+ for (let idx = 0; idx < max; idx++) {
841
+ if (idx % 4 === 0 && idx) {
842
+ result.push(bits >> 16 & 255);
843
+ result.push(bits >> 8 & 255);
844
+ result.push(bits & 255);
845
+ }
846
+ bits = bits << 6 | map.indexOf(input.charAt(idx));
847
+ }
848
+ const tailbits = max % 4 * 6;
849
+ if (tailbits === 0) {
850
+ result.push(bits >> 16 & 255);
851
+ result.push(bits >> 8 & 255);
852
+ result.push(bits & 255);
853
+ } else if (tailbits === 18) {
854
+ result.push(bits >> 10 & 255);
855
+ result.push(bits >> 2 & 255);
856
+ } else if (tailbits === 12) result.push(bits >> 4 & 255);
857
+ return new Uint8Array(result);
858
+ }
859
+ function representYamlBinary(object) {
860
+ const max = object.length;
861
+ const map = BASE64_MAP;
862
+ let result = "";
863
+ let bits = 0;
864
+ for (let idx = 0; idx < max; idx++) {
865
+ if (idx % 3 === 0 && idx) {
866
+ result += map[bits >> 18 & 63];
867
+ result += map[bits >> 12 & 63];
868
+ result += map[bits >> 6 & 63];
869
+ result += map[bits & 63];
870
+ }
871
+ bits = (bits << 8) + object[idx];
872
+ }
873
+ const tail = max % 3;
874
+ if (tail === 0) {
875
+ result += map[bits >> 18 & 63];
876
+ result += map[bits >> 12 & 63];
877
+ result += map[bits >> 6 & 63];
878
+ result += map[bits & 63];
879
+ } else if (tail === 2) {
880
+ result += map[bits >> 10 & 63];
881
+ result += map[bits >> 4 & 63];
882
+ result += map[bits << 2 & 63];
883
+ result += map[64];
884
+ } else if (tail === 1) {
885
+ result += map[bits >> 2 & 63];
886
+ result += map[bits << 4 & 63];
887
+ result += map[64];
888
+ result += map[64];
889
+ }
890
+ return result;
891
+ }
892
+ function isBinary(obj) {
893
+ return obj instanceof Uint8Array;
894
+ }
895
+ const binary = {
896
+ tag: "tag:yaml.org,2002:binary",
897
+ construct: constructYamlBinary,
898
+ kind: "scalar",
899
+ predicate: isBinary,
900
+ represent: representYamlBinary,
901
+ resolve: resolveYamlBinary
902
+ };
903
+ // node_modules/@jsr/std__yaml/_type/bool.js
904
+ const YAML_TRUE_BOOLEANS = [
905
+ "true",
906
+ "True",
907
+ "TRUE"
908
+ ];
909
+ const YAML_FALSE_BOOLEANS = [
910
+ "false",
911
+ "False",
912
+ "FALSE"
913
+ ];
914
+ const YAML_BOOLEANS = [...YAML_TRUE_BOOLEANS, ...YAML_FALSE_BOOLEANS];
915
+ const bool = {
916
+ tag: "tag:yaml.org,2002:bool",
917
+ kind: "scalar",
918
+ defaultStyle: "lowercase",
919
+ predicate: (value) => typeof value === "boolean" || value instanceof Boolean,
920
+ construct: (data) => YAML_TRUE_BOOLEANS.includes(data),
921
+ resolve: (data) => YAML_BOOLEANS.includes(data),
922
+ represent: {
923
+ lowercase: (object) => {
924
+ return (object instanceof Boolean ? object.valueOf() : object) ? "true" : "false";
925
+ },
926
+ uppercase: (object) => {
927
+ return (object instanceof Boolean ? object.valueOf() : object) ? "TRUE" : "FALSE";
928
+ },
929
+ camelcase: (object) => {
930
+ return (object instanceof Boolean ? object.valueOf() : object) ? "True" : "False";
931
+ }
932
+ }
933
+ };
934
+ // node_modules/@jsr/std__yaml/_utils.js
935
+ function isObject(value) {
936
+ return value !== null && typeof value === "object";
937
+ }
938
+ function isNegativeZero(i) {
939
+ return i === 0 && Number.NEGATIVE_INFINITY === 1 / i;
940
+ }
941
+ function isPlainObject(object) {
942
+ return Object.prototype.toString.call(object) === "[object Object]";
943
+ }
944
+ // node_modules/@jsr/std__yaml/_type/float.js
945
+ const YAML_FLOAT_REGEXP = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
946
+ function resolveYamlFloat(data) {
947
+ if (!YAML_FLOAT_REGEXP.test(data) || data[data.length - 1] === "_") return false;
948
+ return true;
949
+ }
950
+ function constructYamlFloat(data) {
951
+ let value = data.replace(/_/g, "").toLowerCase();
952
+ const sign = value[0] === "-" ? -1 : 1;
953
+ if (value[0] && "+-".includes(value[0])) value = value.slice(1);
954
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
955
+ if (value === ".nan") return NaN;
956
+ return sign * parseFloat(value);
957
+ }
958
+ const SCIENTIFIC_WITHOUT_DOT_REGEXP = /^[-+]?[0-9]+e/;
959
+ function representYamlFloat(object, style) {
960
+ const value = object instanceof Number ? object.valueOf() : object;
961
+ if (isNaN(value)) switch (style) {
962
+ case "lowercase": return ".nan";
963
+ case "uppercase": return ".NAN";
964
+ case "camelcase": return ".NaN";
965
+ }
966
+ else if (Number.POSITIVE_INFINITY === value) switch (style) {
967
+ case "lowercase": return ".inf";
968
+ case "uppercase": return ".INF";
969
+ case "camelcase": return ".Inf";
970
+ }
971
+ else if (Number.NEGATIVE_INFINITY === value) switch (style) {
972
+ case "lowercase": return "-.inf";
973
+ case "uppercase": return "-.INF";
974
+ case "camelcase": return "-.Inf";
975
+ }
976
+ else if (isNegativeZero(value)) return "-0.0";
977
+ const res = value.toString(10);
978
+ return SCIENTIFIC_WITHOUT_DOT_REGEXP.test(res) ? res.replace("e", ".e") : res;
979
+ }
980
+ function isFloat(object) {
981
+ if (object instanceof Number) object = object.valueOf();
982
+ return typeof object === "number" && (object % 1 !== 0 || isNegativeZero(object));
983
+ }
984
+ const float = {
985
+ tag: "tag:yaml.org,2002:float",
986
+ construct: constructYamlFloat,
987
+ defaultStyle: "lowercase",
988
+ kind: "scalar",
989
+ predicate: isFloat,
990
+ represent: representYamlFloat,
991
+ resolve: resolveYamlFloat
992
+ };
993
+ // node_modules/@jsr/std__yaml/_type/int.js
994
+ function isCharCodeInRange(c, lower, upper) {
995
+ return lower <= c && c <= upper;
996
+ }
997
+ function isHexCode(c) {
998
+ return isCharCodeInRange(c, 48, 57) || isCharCodeInRange(c, 65, 70) || isCharCodeInRange(c, 97, 102);
999
+ }
1000
+ function isOctCode(c) {
1001
+ return isCharCodeInRange(c, 48, 55);
1002
+ }
1003
+ function isDecCode(c) {
1004
+ return isCharCodeInRange(c, 48, 57);
1005
+ }
1006
+ function resolveYamlInteger(data) {
1007
+ const max = data.length;
1008
+ let index = 0;
1009
+ let hasDigits = false;
1010
+ if (!max) return false;
1011
+ let ch = data[index];
1012
+ if (ch === "-" || ch === "+") ch = data[++index];
1013
+ if (ch === "0") {
1014
+ if (index + 1 === max) return true;
1015
+ ch = data[++index];
1016
+ if (ch === "b") {
1017
+ index++;
1018
+ for (; index < max; index++) {
1019
+ ch = data[index];
1020
+ if (ch === "_") continue;
1021
+ if (ch !== "0" && ch !== "1") return false;
1022
+ hasDigits = true;
1023
+ }
1024
+ return hasDigits && ch !== "_";
1025
+ }
1026
+ if (ch === "x") {
1027
+ index++;
1028
+ for (; index < max; index++) {
1029
+ ch = data[index];
1030
+ if (ch === "_") continue;
1031
+ if (!isHexCode(data.charCodeAt(index))) return false;
1032
+ hasDigits = true;
1033
+ }
1034
+ return hasDigits && ch !== "_";
1035
+ }
1036
+ for (; index < max; index++) {
1037
+ ch = data[index];
1038
+ if (ch === "_") continue;
1039
+ if (!isOctCode(data.charCodeAt(index))) return false;
1040
+ hasDigits = true;
1041
+ }
1042
+ return hasDigits && ch !== "_";
1043
+ }
1044
+ if (ch === "_") return false;
1045
+ for (; index < max; index++) {
1046
+ ch = data[index];
1047
+ if (ch === "_") continue;
1048
+ if (!isDecCode(data.charCodeAt(index))) return false;
1049
+ hasDigits = true;
1050
+ }
1051
+ if (!hasDigits || ch === "_") return false;
1052
+ return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
1053
+ }
1054
+ function constructYamlInteger(data) {
1055
+ let value = data;
1056
+ if (value.includes("_")) value = value.replace(/_/g, "");
1057
+ let sign = 1;
1058
+ let ch = value[0];
1059
+ if (ch === "-" || ch === "+") {
1060
+ if (ch === "-") sign = -1;
1061
+ value = value.slice(1);
1062
+ ch = value[0];
1063
+ }
1064
+ if (value === "0") return 0;
1065
+ if (ch === "0") {
1066
+ if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
1067
+ if (value[1] === "x") return sign * parseInt(value, 16);
1068
+ return sign * parseInt(value, 8);
1069
+ }
1070
+ return sign * parseInt(value, 10);
1071
+ }
1072
+ function isInteger(object) {
1073
+ if (object instanceof Number) object = object.valueOf();
1074
+ return typeof object === "number" && object % 1 === 0 && !isNegativeZero(object);
1075
+ }
1076
+ const int = {
1077
+ tag: "tag:yaml.org,2002:int",
1078
+ construct: constructYamlInteger,
1079
+ defaultStyle: "decimal",
1080
+ kind: "scalar",
1081
+ predicate: isInteger,
1082
+ represent: {
1083
+ binary(object) {
1084
+ const value = object instanceof Number ? object.valueOf() : object;
1085
+ return value >= 0 ? `0b${value.toString(2)}` : `-0b${value.toString(2).slice(1)}`;
1086
+ },
1087
+ octal(object) {
1088
+ const value = object instanceof Number ? object.valueOf() : object;
1089
+ return value >= 0 ? `0${value.toString(8)}` : `-0${value.toString(8).slice(1)}`;
1090
+ },
1091
+ decimal(object) {
1092
+ return (object instanceof Number ? object.valueOf() : object).toString(10);
1093
+ },
1094
+ hexadecimal(object) {
1095
+ const value = object instanceof Number ? object.valueOf() : object;
1096
+ return value >= 0 ? `0x${value.toString(16).toUpperCase()}` : `-0x${value.toString(16).toUpperCase().slice(1)}`;
1097
+ }
1098
+ },
1099
+ resolve: resolveYamlInteger
1100
+ };
1101
+ // node_modules/@jsr/std__yaml/_type/map.js
1102
+ const map = {
1103
+ tag: "tag:yaml.org,2002:map",
1104
+ resolve() {
1105
+ return true;
1106
+ },
1107
+ construct(data) {
1108
+ return data !== null ? data : {};
1109
+ },
1110
+ kind: "mapping"
1111
+ };
1112
+ // node_modules/@jsr/std__yaml/_type/merge.js
1113
+ const merge = {
1114
+ tag: "tag:yaml.org,2002:merge",
1115
+ kind: "scalar",
1116
+ resolve: (data) => data === "<<" || data === null,
1117
+ construct: (data) => data
1118
+ };
1119
+ // node_modules/@jsr/std__yaml/_type/nil.js
1120
+ const nil = {
1121
+ tag: "tag:yaml.org,2002:null",
1122
+ kind: "scalar",
1123
+ defaultStyle: "lowercase",
1124
+ predicate: (object) => object === null,
1125
+ construct: () => null,
1126
+ resolve: (data) => {
1127
+ return data === "~" || data === "null" || data === "Null" || data === "NULL";
1128
+ },
1129
+ represent: {
1130
+ lowercase: () => "null",
1131
+ uppercase: () => "NULL",
1132
+ camelcase: () => "Null"
1133
+ }
1134
+ };
1135
+ // node_modules/@jsr/std__yaml/_type/omap.js
1136
+ function resolveYamlOmap(data) {
1137
+ const objectKeys = /* @__PURE__ */ new Set();
1138
+ for (const object of data) {
1139
+ if (!isPlainObject(object)) return false;
1140
+ const keys = Object.keys(object);
1141
+ if (keys.length !== 1) return false;
1142
+ for (const key of keys) {
1143
+ if (objectKeys.has(key)) return false;
1144
+ objectKeys.add(key);
1145
+ }
1146
+ }
1147
+ return true;
1148
+ }
1149
+ const omap = {
1150
+ tag: "tag:yaml.org,2002:omap",
1151
+ kind: "sequence",
1152
+ resolve: resolveYamlOmap,
1153
+ construct(data) {
1154
+ return data;
1155
+ }
1156
+ };
1157
+ // node_modules/@jsr/std__yaml/_type/pairs.js
1158
+ function resolveYamlPairs(data) {
1159
+ if (data === null) return true;
1160
+ return data.every((it) => isPlainObject(it) && Object.keys(it).length === 1);
1161
+ }
1162
+ const pairs = {
1163
+ tag: "tag:yaml.org,2002:pairs",
1164
+ construct(data) {
1165
+ return data?.flatMap(Object.entries) ?? [];
1166
+ },
1167
+ kind: "sequence",
1168
+ resolve: resolveYamlPairs
1169
+ };
1170
+ // node_modules/@jsr/std__yaml/_type/regexp.js
1171
+ const REGEXP = /^\/(?<regexp>[\s\S]+)\/(?<modifiers>[gismuy]*)$/;
1172
+ const regexp = {
1173
+ tag: "tag:yaml.org,2002:js/regexp",
1174
+ kind: "scalar",
1175
+ resolve(data) {
1176
+ if (data === null || !data.length) return false;
1177
+ if (data.charAt(0) === "/") {
1178
+ const groups = data.match(REGEXP)?.groups;
1179
+ if (!groups) return false;
1180
+ const modifiers = groups.modifiers ?? "";
1181
+ if (new Set(modifiers).size < modifiers.length) return false;
1182
+ }
1183
+ return true;
1184
+ },
1185
+ construct(data) {
1186
+ const { regexp = data, modifiers = "" } = data.match(REGEXP)?.groups ?? {};
1187
+ return new RegExp(regexp, modifiers);
1188
+ },
1189
+ predicate: (object) => object instanceof RegExp,
1190
+ represent: (object) => object.toString()
1191
+ };
1192
+ // node_modules/@jsr/std__yaml/_type/seq.js
1193
+ const seq = {
1194
+ tag: "tag:yaml.org,2002:seq",
1195
+ kind: "sequence",
1196
+ resolve: () => true,
1197
+ construct: (data) => data !== null ? data : []
1198
+ };
1199
+ // node_modules/@jsr/std__yaml/_type/set.js
1200
+ const set = {
1201
+ tag: "tag:yaml.org,2002:set",
1202
+ kind: "mapping",
1203
+ construct: (data) => data !== null ? data : {},
1204
+ resolve: (data) => {
1205
+ if (data === null) return true;
1206
+ return Object.values(data).every((it) => it === null);
1207
+ }
1208
+ };
1209
+ // node_modules/@jsr/std__yaml/_type/str.js
1210
+ const str = {
1211
+ tag: "tag:yaml.org,2002:str",
1212
+ kind: "scalar",
1213
+ resolve: () => true,
1214
+ construct: (data) => data !== null ? data : ""
1215
+ };
1216
+ // node_modules/@jsr/std__yaml/_type/timestamp.js
1217
+ const YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
1218
+ const YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([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]))?))?$");
1219
+ function resolveYamlTimestamp(data) {
1220
+ if (data === null) return false;
1221
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
1222
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
1223
+ return false;
1224
+ }
1225
+ function constructYamlTimestamp(data) {
1226
+ let match = YAML_DATE_REGEXP.exec(data);
1227
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
1228
+ if (match === null) throw new Error("Cannot construct YAML timestamp: date resolve error");
1229
+ const year = +match[1];
1230
+ const month = +match[2] - 1;
1231
+ const day = +match[3];
1232
+ if (!match[4]) return new Date(Date.UTC(year, month, day));
1233
+ const hour = +match[4];
1234
+ const minute = +match[5];
1235
+ const second = +match[6];
1236
+ let fraction = 0;
1237
+ if (match[7]) {
1238
+ let partFraction = match[7].slice(0, 3);
1239
+ while (partFraction.length < 3) partFraction += "0";
1240
+ fraction = +partFraction;
1241
+ }
1242
+ let delta = null;
1243
+ if (match[9] && match[10]) {
1244
+ const tzHour = +match[10];
1245
+ const tzMinute = +(match[11] || 0);
1246
+ delta = (tzHour * 60 + tzMinute) * 6e4;
1247
+ if (match[9] === "-") delta = -delta;
1248
+ }
1249
+ const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1250
+ if (delta) date.setTime(date.getTime() - delta);
1251
+ return date;
1252
+ }
1253
+ function representYamlTimestamp(date) {
1254
+ return date.toISOString();
1255
+ }
1256
+ const timestamp = {
1257
+ tag: "tag:yaml.org,2002:timestamp",
1258
+ construct: constructYamlTimestamp,
1259
+ predicate(object) {
1260
+ return object instanceof Date;
1261
+ },
1262
+ kind: "scalar",
1263
+ represent: representYamlTimestamp,
1264
+ resolve: resolveYamlTimestamp
1265
+ };
1266
+ // node_modules/@jsr/std__yaml/_type/undefined.js
1267
+ const undefinedType = {
1268
+ tag: "tag:yaml.org,2002:js/undefined",
1269
+ kind: "scalar",
1270
+ resolve() {
1271
+ return true;
1272
+ },
1273
+ construct() {},
1274
+ predicate(object) {
1275
+ return typeof object === "undefined";
1276
+ },
1277
+ represent() {
1278
+ return "";
1279
+ }
1280
+ };
1281
+ // node_modules/@jsr/std__yaml/_schema.js
1282
+ function createTypeMap(implicitTypes, explicitTypes) {
1283
+ const result = {
1284
+ fallback: /* @__PURE__ */ new Map(),
1285
+ mapping: /* @__PURE__ */ new Map(),
1286
+ scalar: /* @__PURE__ */ new Map(),
1287
+ sequence: /* @__PURE__ */ new Map()
1288
+ };
1289
+ const fallbackMap = result.fallback;
1290
+ for (const type of [...implicitTypes, ...explicitTypes]) {
1291
+ result[type.kind].set(type.tag, type);
1292
+ fallbackMap.set(type.tag, type);
1293
+ }
1294
+ return result;
1295
+ }
1296
+ function createSchema({ explicitTypes = [], implicitTypes = [], include }) {
1297
+ if (include) {
1298
+ implicitTypes.push(...include.implicitTypes);
1299
+ explicitTypes.push(...include.explicitTypes);
1300
+ }
1301
+ return {
1302
+ implicitTypes,
1303
+ explicitTypes,
1304
+ typeMap: createTypeMap(implicitTypes, explicitTypes)
1305
+ };
1306
+ }
1307
+ /**
1308
+ * Standard YAML's failsafe schema.
1309
+ *
1310
+ * @see {@link http://www.yaml.org/spec/1.2/spec.html#id2802346}
1311
+ */ const FAILSAFE_SCHEMA = createSchema({ explicitTypes: [
1312
+ str,
1313
+ seq,
1314
+ map
1315
+ ] });
1316
+ /**
1317
+ * Standard YAML's JSON schema.
1318
+ *
1319
+ * @see {@link http://www.yaml.org/spec/1.2/spec.html#id2803231}
1320
+ */ const JSON_SCHEMA = createSchema({
1321
+ implicitTypes: [
1322
+ nil,
1323
+ bool,
1324
+ int,
1325
+ float
1326
+ ],
1327
+ include: FAILSAFE_SCHEMA
1328
+ });
1329
+ /**
1330
+ * Standard YAML's core schema.
1331
+ *
1332
+ * @see {@link http://www.yaml.org/spec/1.2/spec.html#id2804923}
1333
+ */ const CORE_SCHEMA = createSchema({ include: JSON_SCHEMA });
1334
+ /**
1335
+ * Default YAML schema. It is not described in the YAML specification.
1336
+ */ const DEFAULT_SCHEMA = createSchema({
1337
+ explicitTypes: [
1338
+ binary,
1339
+ omap,
1340
+ pairs,
1341
+ set
1342
+ ],
1343
+ implicitTypes: [timestamp, merge],
1344
+ include: CORE_SCHEMA
1345
+ });
1346
+ /***
1347
+ * Extends JS-YAML default schema with additional JavaScript types
1348
+ * It is not described in the YAML specification.
1349
+ * Functions are no longer supported for security reasons.
1350
+ *
1351
+ * @example
1352
+ * ```ts
1353
+ * import { parse } from "@std/yaml";
1354
+ *
1355
+ * const data = parse(
1356
+ * `
1357
+ * regexp:
1358
+ * simple: !!js/regexp foobar
1359
+ * modifiers: !!js/regexp /foobar/mi
1360
+ * undefined: !!js/undefined ~
1361
+ * `,
1362
+ * { schema: "extended" },
1363
+ * );
1364
+ * ```
1365
+ */ const EXTENDED_SCHEMA = createSchema({
1366
+ explicitTypes: [regexp, undefinedType],
1367
+ include: DEFAULT_SCHEMA
1368
+ });
1369
+ const SCHEMA_MAP = /* @__PURE__ */ new Map([
1370
+ ["core", CORE_SCHEMA],
1371
+ ["default", DEFAULT_SCHEMA],
1372
+ ["failsafe", FAILSAFE_SCHEMA],
1373
+ ["json", JSON_SCHEMA],
1374
+ ["extended", EXTENDED_SCHEMA]
1375
+ ]);
1376
+ // node_modules/@jsr/std__yaml/types.js
1377
+ /**
1378
+ * Type definitions for the YAML parser.
1379
+ *
1380
+ * @module
1381
+ */ /**
1382
+ * Position information for error reporting.
1383
+ *
1384
+ * `line` and `column` are 1-indexed; `offset` is the 0-indexed character
1385
+ * offset into the source string.
1386
+ */ /**
1387
+ * Error thrown when YAML parsing fails.
1388
+ *
1389
+ * Subclass of {@linkcode SyntaxError}, so existing
1390
+ * `instanceof SyntaxError` checks keep working. Carries structured
1391
+ * position information so consumers do not have to parse the message.
1392
+ *
1393
+ * @example Usage
1394
+ * ```ts
1395
+ * import { parse, YamlSyntaxError } from "@std/yaml";
1396
+ * import { assertInstanceOf } from "@std/assert";
1397
+ *
1398
+ * try {
1399
+ * parse(`"`);
1400
+ * } catch (error) {
1401
+ * assertInstanceOf(error, YamlSyntaxError);
1402
+ * assertInstanceOf(error, SyntaxError);
1403
+ * }
1404
+ * ```
1405
+ */ var YamlSyntaxError = class extends SyntaxError {
1406
+ /**
1407
+ * The line number where the error occurred (1-indexed).
1408
+ *
1409
+ * @example Usage
1410
+ * ```ts
1411
+ * import { YamlSyntaxError } from "@std/yaml";
1412
+ * import { assertEquals } from "@std/assert";
1413
+ *
1414
+ * const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
1415
+ * assertEquals(error.line, 5);
1416
+ * ```
1417
+ */ line;
1418
+ /**
1419
+ * The column number where the error occurred (1-indexed).
1420
+ *
1421
+ * @example Usage
1422
+ * ```ts
1423
+ * import { YamlSyntaxError } from "@std/yaml";
1424
+ * import { assertEquals } from "@std/assert";
1425
+ *
1426
+ * const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
1427
+ * assertEquals(error.column, 10);
1428
+ * ```
1429
+ */ column;
1430
+ /**
1431
+ * The character offset where the error occurred (0-indexed).
1432
+ *
1433
+ * @example Usage
1434
+ * ```ts
1435
+ * import { YamlSyntaxError } from "@std/yaml";
1436
+ * import { assertEquals } from "@std/assert";
1437
+ *
1438
+ * const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
1439
+ * assertEquals(error.offset, 50);
1440
+ * ```
1441
+ */ offset;
1442
+ /**
1443
+ * A formatted snippet of the source around the error, including a caret
1444
+ * line indicating the column. Undefined when the source is empty.
1445
+ *
1446
+ * @example Usage
1447
+ * ```ts
1448
+ * import { YamlSyntaxError } from "@std/yaml";
1449
+ * import { assertEquals } from "@std/assert";
1450
+ *
1451
+ * const snippet = " foo: bar\n ^";
1452
+ * const error = new YamlSyntaxError(
1453
+ * "Test",
1454
+ * { line: 1, column: 6, offset: 5 },
1455
+ * snippet,
1456
+ * );
1457
+ * assertEquals(error.snippet, snippet);
1458
+ * ```
1459
+ */ snippet;
1460
+ /**
1461
+ * Constructs a new YamlSyntaxError.
1462
+ *
1463
+ * The constructed `message` is `${message} at line ${line}, column ${column}`,
1464
+ * with `:\n${snippet}` appended when a snippet is provided.
1465
+ *
1466
+ * @param message The error message describing the syntax issue.
1467
+ * @param position The position in the YAML source where the error occurred.
1468
+ * @param snippet Optional formatted snippet of the source around the error.
1469
+ */ constructor(message, position, snippet) {
1470
+ let fullMessage = `${message} at line ${position.line}, column ${position.column}`;
1471
+ if (snippet) fullMessage += `:\n${snippet}`;
1472
+ super(fullMessage);
1473
+ this.name = "YamlSyntaxError";
1474
+ this.line = position.line;
1475
+ this.column = position.column;
1476
+ this.offset = position.offset;
1477
+ if (snippet !== void 0) this.snippet = snippet;
1478
+ }
1479
+ };
1480
+ // node_modules/@jsr/std__yaml/_loader_state.js
1481
+ const CONTEXT_FLOW_IN = 1;
1482
+ const CONTEXT_FLOW_OUT = 2;
1483
+ const CONTEXT_BLOCK_IN = 3;
1484
+ const CONTEXT_BLOCK_OUT = 4;
1485
+ const CHOMPING_CLIP = 1;
1486
+ const CHOMPING_STRIP = 2;
1487
+ const CHOMPING_KEEP = 3;
1488
+ const PATTERN_NON_PRINTABLE_REGEXP = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1489
+ const PATTERN_NON_ASCII_LINE_BREAKS_REGEXP = /[\x85\u2028\u2029]/;
1490
+ const PATTERN_FLOW_INDICATORS_REGEXP = /[,\[\]\{\}]/;
1491
+ const PATTERN_TAG_HANDLE_REGEXP = /^(?:!|!!|![a-z\-]+!)$/i;
1492
+ const PATTERN_TAG_URI_REGEXP = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1493
+ const ESCAPED_HEX_LENGTHS = /* @__PURE__ */ new Map([
1494
+ [120, 2],
1495
+ [117, 4],
1496
+ [85, 8]
1497
+ ]);
1498
+ const SIMPLE_ESCAPE_SEQUENCES = /* @__PURE__ */ new Map([
1499
+ [48, "\0"],
1500
+ [97, "\x07"],
1501
+ [98, "\b"],
1502
+ [116, " "],
1503
+ [9, " "],
1504
+ [110, "\n"],
1505
+ [118, "\v"],
1506
+ [102, "\f"],
1507
+ [114, "\r"],
1508
+ [101, "\x1B"],
1509
+ [32, " "],
1510
+ [34, "\""],
1511
+ [47, "/"],
1512
+ [92, "\\"],
1513
+ [78, "…"],
1514
+ [95, "\xA0"],
1515
+ [76, "\u2028"],
1516
+ [80, "\u2029"]
1517
+ ]);
1518
+ /**
1519
+ * Converts a hexadecimal character code to its decimal value.
1520
+ */ function hexCharCodeToNumber(charCode) {
1521
+ if (48 <= charCode && charCode <= 57) return charCode - 48;
1522
+ const lc = charCode | 32;
1523
+ if (97 <= lc && lc <= 102) return lc - 97 + 10;
1524
+ return -1;
1525
+ }
1526
+ /**
1527
+ * Converts a decimal character code to its decimal value.
1528
+ */ function decimalCharCodeToNumber(charCode) {
1529
+ if (48 <= charCode && charCode <= 57) return charCode - 48;
1530
+ return -1;
1531
+ }
1532
+ /**
1533
+ * Converts a Unicode code point to a string.
1534
+ */ function codepointToChar(codepoint) {
1535
+ if (codepoint <= 65535) return String.fromCharCode(codepoint);
1536
+ return String.fromCharCode((codepoint - 65536 >> 10) + 55296, (codepoint - 65536 & 1023) + 56320);
1537
+ }
1538
+ const INDENT = 4;
1539
+ const MAX_LENGTH = 75;
1540
+ const DELIMITERS = "\0\r\n…\u2028\u2029";
1541
+ function getSnippet(buffer, position) {
1542
+ if (!buffer) return null;
1543
+ let start = position;
1544
+ let end = position;
1545
+ let head = "";
1546
+ let tail = "";
1547
+ while (start > 0 && !DELIMITERS.includes(buffer.charAt(start - 1))) {
1548
+ start--;
1549
+ if (position - start > MAX_LENGTH / 2 - 1) {
1550
+ head = " ... ";
1551
+ start += 5;
1552
+ break;
1553
+ }
1554
+ }
1555
+ while (end < buffer.length && !DELIMITERS.includes(buffer.charAt(end))) {
1556
+ end++;
1557
+ if (end - position > MAX_LENGTH / 2 - 1) {
1558
+ tail = " ... ";
1559
+ end -= 5;
1560
+ break;
1561
+ }
1562
+ }
1563
+ const snippet = buffer.slice(start, end);
1564
+ const indent = " ".repeat(INDENT);
1565
+ const caretIndent = " ".repeat(INDENT + position - start + head.length);
1566
+ return `${indent + head + snippet + tail}\n${caretIndent}^`;
1567
+ }
1568
+ function getIndentStatus(lineIndent, parentIndent) {
1569
+ if (lineIndent > parentIndent) return 1;
1570
+ if (lineIndent < parentIndent) return -1;
1571
+ return 0;
1572
+ }
1573
+ function writeFoldedLines(count) {
1574
+ if (count === 1) return " ";
1575
+ if (count > 1) return "\n".repeat(count - 1);
1576
+ return "";
1577
+ }
1578
+ var Scanner = class {
1579
+ source;
1580
+ #length;
1581
+ position = 0;
1582
+ constructor(source) {
1583
+ source += "\0";
1584
+ this.source = source;
1585
+ this.#length = source.length;
1586
+ }
1587
+ peek(offset = 0) {
1588
+ return this.source.charCodeAt(this.position + offset);
1589
+ }
1590
+ next() {
1591
+ this.position += 1;
1592
+ }
1593
+ eof() {
1594
+ return this.position >= this.#length - 1;
1595
+ }
1596
+ };
1597
+ var LoaderState = class {
1598
+ #scanner;
1599
+ lineIndent = 0;
1600
+ lineStart = 0;
1601
+ line = 0;
1602
+ onWarning;
1603
+ allowDuplicateKeys;
1604
+ implicitTypes;
1605
+ typeMap;
1606
+ checkLineBreaks = false;
1607
+ tagMap = /* @__PURE__ */ new Map();
1608
+ anchorMap = /* @__PURE__ */ new Map();
1609
+ constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
1610
+ this.#scanner = new Scanner(input);
1611
+ this.onWarning = onWarning;
1612
+ this.allowDuplicateKeys = allowDuplicateKeys;
1613
+ this.implicitTypes = schema.implicitTypes;
1614
+ this.typeMap = schema.typeMap;
1615
+ this.readIndent();
1616
+ }
1617
+ skipWhitespaces() {
1618
+ let ch = this.#scanner.peek();
1619
+ while (isWhiteSpace(ch)) {
1620
+ this.#scanner.next();
1621
+ ch = this.#scanner.peek();
1622
+ }
1623
+ }
1624
+ skipComment() {
1625
+ let ch = this.#scanner.peek();
1626
+ if (ch !== 35) return;
1627
+ this.#scanner.next();
1628
+ ch = this.#scanner.peek();
1629
+ while (ch !== 0 && !isEOL(ch)) {
1630
+ this.#scanner.next();
1631
+ ch = this.#scanner.peek();
1632
+ }
1633
+ }
1634
+ readIndent() {
1635
+ let ch = this.#scanner.peek();
1636
+ while (ch === 32) {
1637
+ this.lineIndent += 1;
1638
+ this.#scanner.next();
1639
+ ch = this.#scanner.peek();
1640
+ }
1641
+ }
1642
+ #createError(message) {
1643
+ const offset = this.#scanner.position;
1644
+ const snippet = getSnippet(this.#scanner.source, offset) ?? void 0;
1645
+ return new YamlSyntaxError(message, {
1646
+ line: this.line + 1,
1647
+ column: offset - this.lineStart + 1,
1648
+ offset
1649
+ }, snippet);
1650
+ }
1651
+ dispatchWarning(message) {
1652
+ const error = this.#createError(message);
1653
+ this.onWarning?.(error);
1654
+ }
1655
+ yamlDirectiveHandler(args) {
1656
+ if (args.length !== 1) throw this.#createError("Cannot handle YAML directive: YAML directive accepts exactly one argument");
1657
+ const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
1658
+ if (match === null) throw this.#createError("Cannot handle YAML directive: ill-formed argument");
1659
+ const major = parseInt(match[1], 10);
1660
+ const minor = parseInt(match[2], 10);
1661
+ if (major !== 1) throw this.#createError("Cannot handle YAML directive: unacceptable YAML version");
1662
+ this.checkLineBreaks = minor < 2;
1663
+ if (minor !== 1 && minor !== 2) this.dispatchWarning("Cannot handle YAML directive: unsupported YAML version");
1664
+ return args[0] ?? null;
1665
+ }
1666
+ tagDirectiveHandler(args) {
1667
+ if (args.length !== 2) throw this.#createError(`Cannot handle tag directive: directive accepts exactly two arguments, received ${args.length}`);
1668
+ const handle = args[0];
1669
+ const prefix = args[1];
1670
+ if (!PATTERN_TAG_HANDLE_REGEXP.test(handle)) throw this.#createError(`Cannot handle tag directive: ill-formed handle (first argument) in "${handle}"`);
1671
+ if (this.tagMap.has(handle)) throw this.#createError(`Cannot handle tag directive: previously declared suffix for "${handle}" tag handle`);
1672
+ if (!PATTERN_TAG_URI_REGEXP.test(prefix)) throw this.#createError("Cannot handle tag directive: ill-formed tag prefix (second argument) of the TAG directive");
1673
+ this.tagMap.set(handle, prefix);
1674
+ }
1675
+ captureSegment(start, end, checkJson) {
1676
+ if (start < end) {
1677
+ const result = this.#scanner.source.slice(start, end);
1678
+ if (checkJson) for (let position = 0; position < result.length; position++) {
1679
+ const character = result.charCodeAt(position);
1680
+ if (!(character === 9 || 32 <= character && character <= 1114111)) throw this.#createError(`Expected valid JSON character: received "${character}"`);
1681
+ }
1682
+ else if (PATTERN_NON_PRINTABLE_REGEXP.test(result)) throw this.#createError("Stream contains non-printable characters");
1683
+ return result;
1684
+ }
1685
+ }
1686
+ readBlockSequence(tag, anchor, nodeIndent) {
1687
+ let detected = false;
1688
+ const result = [];
1689
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1690
+ let ch = this.#scanner.peek();
1691
+ while (ch !== 0) {
1692
+ if (ch !== 45) break;
1693
+ if (!isWhiteSpaceOrEOL(this.#scanner.peek(1))) break;
1694
+ detected = true;
1695
+ this.#scanner.next();
1696
+ if (this.skipSeparationSpace(true, -1)) {
1697
+ if (this.lineIndent <= nodeIndent) {
1698
+ result.push(null);
1699
+ ch = this.#scanner.peek();
1700
+ continue;
1701
+ }
1702
+ }
1703
+ const line = this.line;
1704
+ const newState = this.composeNode({
1705
+ parentIndent: nodeIndent,
1706
+ nodeContext: CONTEXT_BLOCK_IN,
1707
+ allowToSeek: false,
1708
+ allowCompact: true
1709
+ });
1710
+ if (newState) result.push(newState.result);
1711
+ this.skipSeparationSpace(true, -1);
1712
+ ch = this.#scanner.peek();
1713
+ if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
1714
+ else if (this.lineIndent < nodeIndent) break;
1715
+ }
1716
+ if (detected) return {
1717
+ tag,
1718
+ anchor,
1719
+ kind: "sequence",
1720
+ result
1721
+ };
1722
+ }
1723
+ mergeMappings(destination, source, overridableKeys) {
1724
+ if (!isObject(source)) throw this.#createError("Cannot merge mappings: the provided source object is unacceptable");
1725
+ for (const [key, value] of Object.entries(source)) {
1726
+ if (Object.hasOwn(destination, key)) continue;
1727
+ if (key === "__proto__") Object.defineProperty(destination, key, {
1728
+ value,
1729
+ writable: true,
1730
+ enumerable: true,
1731
+ configurable: true
1732
+ });
1733
+ else destination[key] = value;
1734
+ overridableKeys.add(key);
1735
+ }
1736
+ }
1737
+ storeMappingPair(result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
1738
+ if (Array.isArray(keyNode)) {
1739
+ keyNode = Array.prototype.slice.call(keyNode);
1740
+ for (let index = 0; index < keyNode.length; index++) {
1741
+ if (Array.isArray(keyNode[index])) throw this.#createError("Cannot store mapping pair: nested arrays are not supported inside keys");
1742
+ if (typeof keyNode === "object" && isPlainObject(keyNode[index])) keyNode[index] = "[object Object]";
1743
+ }
1744
+ }
1745
+ if (typeof keyNode === "object" && isPlainObject(keyNode)) keyNode = "[object Object]";
1746
+ keyNode = String(keyNode);
1747
+ if (keyTag === "tag:yaml.org,2002:merge") {
1748
+ if (Array.isArray(valueNode)) for (let index = 0; index < valueNode.length; index++) this.mergeMappings(result, valueNode[index], overridableKeys);
1749
+ else this.mergeMappings(result, valueNode, overridableKeys);
1750
+ } else {
1751
+ if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
1752
+ this.line = startLine || this.line;
1753
+ this.#scanner.position = startPos || this.#scanner.position;
1754
+ throw this.#createError("Cannot store mapping pair: duplicated key");
1755
+ }
1756
+ if (keyNode === "__proto__") Object.defineProperty(result, keyNode, {
1757
+ value: valueNode,
1758
+ writable: true,
1759
+ enumerable: true,
1760
+ configurable: true
1761
+ });
1762
+ else result[keyNode] = valueNode;
1763
+ overridableKeys.delete(keyNode);
1764
+ }
1765
+ return result;
1766
+ }
1767
+ readLineBreak() {
1768
+ const ch = this.#scanner.peek();
1769
+ if (ch === 10) this.#scanner.next();
1770
+ else if (ch === 13) {
1771
+ this.#scanner.next();
1772
+ if (this.#scanner.peek() === 10) this.#scanner.next();
1773
+ } else throw this.#createError("Cannot read line: line break not found");
1774
+ this.line += 1;
1775
+ this.lineStart = this.#scanner.position;
1776
+ }
1777
+ skipSeparationSpace(allowComments, checkIndent) {
1778
+ let lineBreaks = 0;
1779
+ let ch = this.#scanner.peek();
1780
+ while (ch !== 0) {
1781
+ this.skipWhitespaces();
1782
+ ch = this.#scanner.peek();
1783
+ if (allowComments) {
1784
+ this.skipComment();
1785
+ ch = this.#scanner.peek();
1786
+ }
1787
+ if (isEOL(ch)) {
1788
+ this.readLineBreak();
1789
+ ch = this.#scanner.peek();
1790
+ lineBreaks++;
1791
+ this.lineIndent = 0;
1792
+ this.readIndent();
1793
+ ch = this.#scanner.peek();
1794
+ } else break;
1795
+ }
1796
+ if (checkIndent !== -1 && lineBreaks !== 0 && this.lineIndent < checkIndent) this.dispatchWarning("deficient indentation");
1797
+ return lineBreaks;
1798
+ }
1799
+ testDocumentSeparator() {
1800
+ let ch = this.#scanner.peek();
1801
+ if ((ch === 45 || ch === 46) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
1802
+ ch = this.#scanner.peek(3);
1803
+ if (ch === 0 || isWhiteSpaceOrEOL(ch)) return true;
1804
+ }
1805
+ return false;
1806
+ }
1807
+ readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
1808
+ let ch = this.#scanner.peek();
1809
+ if (isWhiteSpaceOrEOL(ch) || isFlowIndicator(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) return;
1810
+ let following;
1811
+ if (ch === 63 || ch === 45) {
1812
+ following = this.#scanner.peek(1);
1813
+ if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) return;
1814
+ }
1815
+ let result = "";
1816
+ let captureEnd = this.#scanner.position;
1817
+ let captureStart = this.#scanner.position;
1818
+ let hasPendingContent = false;
1819
+ let line = 0;
1820
+ while (ch !== 0) {
1821
+ if (ch === 58) {
1822
+ following = this.#scanner.peek(1);
1823
+ if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) break;
1824
+ } else if (ch === 35) {
1825
+ if (isWhiteSpaceOrEOL(this.#scanner.peek(-1))) break;
1826
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) break;
1827
+ else if (isEOL(ch)) {
1828
+ line = this.line;
1829
+ const lineStart = this.lineStart;
1830
+ const lineIndent = this.lineIndent;
1831
+ this.skipSeparationSpace(false, -1);
1832
+ if (this.lineIndent >= nodeIndent) {
1833
+ hasPendingContent = true;
1834
+ ch = this.#scanner.peek();
1835
+ continue;
1836
+ } else {
1837
+ this.#scanner.position = captureEnd;
1838
+ this.line = line;
1839
+ this.lineStart = lineStart;
1840
+ this.lineIndent = lineIndent;
1841
+ break;
1842
+ }
1843
+ }
1844
+ if (hasPendingContent) {
1845
+ const segment = this.captureSegment(captureStart, captureEnd, false);
1846
+ if (segment) result += segment;
1847
+ result += writeFoldedLines(this.line - line);
1848
+ captureStart = captureEnd = this.#scanner.position;
1849
+ hasPendingContent = false;
1850
+ }
1851
+ if (!isWhiteSpace(ch)) captureEnd = this.#scanner.position + 1;
1852
+ this.#scanner.next();
1853
+ ch = this.#scanner.peek();
1854
+ }
1855
+ const segment = this.captureSegment(captureStart, captureEnd, false);
1856
+ if (segment) result += segment;
1857
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1858
+ if (result) return {
1859
+ tag,
1860
+ anchor,
1861
+ kind: "scalar",
1862
+ result
1863
+ };
1864
+ }
1865
+ readSingleQuotedScalar(tag, anchor, nodeIndent) {
1866
+ let ch = this.#scanner.peek();
1867
+ if (ch !== 39) return;
1868
+ let result = "";
1869
+ this.#scanner.next();
1870
+ let captureStart = this.#scanner.position;
1871
+ let captureEnd = this.#scanner.position;
1872
+ ch = this.#scanner.peek();
1873
+ while (ch !== 0) {
1874
+ if (ch === 39) {
1875
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1876
+ if (segment) result += segment;
1877
+ this.#scanner.next();
1878
+ ch = this.#scanner.peek();
1879
+ if (ch === 39) {
1880
+ captureStart = this.#scanner.position;
1881
+ this.#scanner.next();
1882
+ captureEnd = this.#scanner.position;
1883
+ } else {
1884
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1885
+ return {
1886
+ tag,
1887
+ anchor,
1888
+ kind: "scalar",
1889
+ result
1890
+ };
1891
+ }
1892
+ } else if (isEOL(ch)) {
1893
+ const segment = this.captureSegment(captureStart, captureEnd, true);
1894
+ if (segment) result += segment;
1895
+ result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1896
+ captureStart = captureEnd = this.#scanner.position;
1897
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) throw this.#createError("Unexpected end of the document within a single quoted scalar");
1898
+ else {
1899
+ this.#scanner.next();
1900
+ captureEnd = this.#scanner.position;
1901
+ }
1902
+ ch = this.#scanner.peek();
1903
+ }
1904
+ throw this.#createError("Unexpected end of the stream within a single quoted scalar");
1905
+ }
1906
+ readDoubleQuotedScalar(tag, anchor, nodeIndent) {
1907
+ let ch = this.#scanner.peek();
1908
+ if (ch !== 34) return;
1909
+ let result = "";
1910
+ this.#scanner.next();
1911
+ let captureEnd = this.#scanner.position;
1912
+ let captureStart = this.#scanner.position;
1913
+ let tmp;
1914
+ ch = this.#scanner.peek();
1915
+ while (ch !== 0) {
1916
+ if (ch === 34) {
1917
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1918
+ if (segment) result += segment;
1919
+ this.#scanner.next();
1920
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1921
+ return {
1922
+ tag,
1923
+ anchor,
1924
+ kind: "scalar",
1925
+ result
1926
+ };
1927
+ }
1928
+ if (ch === 92) {
1929
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1930
+ if (segment) result += segment;
1931
+ this.#scanner.next();
1932
+ ch = this.#scanner.peek();
1933
+ if (isEOL(ch)) this.skipSeparationSpace(false, nodeIndent);
1934
+ else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
1935
+ result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
1936
+ this.#scanner.next();
1937
+ } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
1938
+ let hexLength = tmp;
1939
+ let hexResult = 0;
1940
+ for (; hexLength > 0; hexLength--) {
1941
+ this.#scanner.next();
1942
+ ch = this.#scanner.peek();
1943
+ if ((tmp = hexCharCodeToNumber(ch)) >= 0) hexResult = (hexResult << 4) + tmp;
1944
+ else throw this.#createError("Cannot read double quoted scalar: expected hexadecimal character");
1945
+ }
1946
+ result += codepointToChar(hexResult);
1947
+ this.#scanner.next();
1948
+ } else throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
1949
+ captureStart = captureEnd = this.#scanner.position;
1950
+ } else if (isEOL(ch)) {
1951
+ const segment = this.captureSegment(captureStart, captureEnd, true);
1952
+ if (segment) result += segment;
1953
+ result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1954
+ captureStart = captureEnd = this.#scanner.position;
1955
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) throw this.#createError("Unexpected end of the document within a double quoted scalar");
1956
+ else {
1957
+ this.#scanner.next();
1958
+ captureEnd = this.#scanner.position;
1959
+ }
1960
+ ch = this.#scanner.peek();
1961
+ }
1962
+ throw this.#createError("Unexpected end of the stream within a double quoted scalar");
1963
+ }
1964
+ readFlowCollection(tag, anchor, nodeIndent) {
1965
+ let ch = this.#scanner.peek();
1966
+ let terminator;
1967
+ let isMapping = true;
1968
+ let result = {};
1969
+ if (ch === 91) {
1970
+ terminator = 93;
1971
+ isMapping = false;
1972
+ result = [];
1973
+ } else if (ch === 123) terminator = 125;
1974
+ else return;
1975
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1976
+ this.#scanner.next();
1977
+ ch = this.#scanner.peek();
1978
+ let readNext = true;
1979
+ let valueNode = null;
1980
+ let keyNode = null;
1981
+ let keyTag = null;
1982
+ let isExplicitPair = false;
1983
+ let isPair = false;
1984
+ let following = 0;
1985
+ let line = 0;
1986
+ const overridableKeys = /* @__PURE__ */ new Set();
1987
+ while (ch !== 0) {
1988
+ this.skipSeparationSpace(true, nodeIndent);
1989
+ ch = this.#scanner.peek();
1990
+ if (ch === terminator) {
1991
+ this.#scanner.next();
1992
+ return {
1993
+ tag,
1994
+ anchor,
1995
+ kind: isMapping ? "mapping" : "sequence",
1996
+ result
1997
+ };
1998
+ }
1999
+ if (!readNext) throw this.#createError("Cannot read flow collection: missing comma between flow collection entries");
2000
+ keyTag = keyNode = valueNode = null;
2001
+ isPair = isExplicitPair = false;
2002
+ if (ch === 63) {
2003
+ following = this.#scanner.peek(1);
2004
+ if (isWhiteSpaceOrEOL(following)) {
2005
+ isPair = isExplicitPair = true;
2006
+ this.#scanner.next();
2007
+ this.skipSeparationSpace(true, nodeIndent);
2008
+ }
2009
+ }
2010
+ line = this.line;
2011
+ const newState = this.composeNode({
2012
+ parentIndent: nodeIndent,
2013
+ nodeContext: CONTEXT_FLOW_IN,
2014
+ allowToSeek: false,
2015
+ allowCompact: true
2016
+ });
2017
+ if (newState) {
2018
+ keyTag = newState.tag || null;
2019
+ keyNode = newState.result;
2020
+ }
2021
+ this.skipSeparationSpace(true, nodeIndent);
2022
+ ch = this.#scanner.peek();
2023
+ if ((isExplicitPair || this.line === line) && ch === 58) {
2024
+ isPair = true;
2025
+ this.#scanner.next();
2026
+ ch = this.#scanner.peek();
2027
+ this.skipSeparationSpace(true, nodeIndent);
2028
+ const newState = this.composeNode({
2029
+ parentIndent: nodeIndent,
2030
+ nodeContext: CONTEXT_FLOW_IN,
2031
+ allowToSeek: false,
2032
+ allowCompact: true
2033
+ });
2034
+ if (newState) valueNode = newState.result;
2035
+ }
2036
+ if (isMapping) this.storeMappingPair(result, overridableKeys, keyTag, keyNode, valueNode);
2037
+ else if (isPair) result.push(this.storeMappingPair({}, overridableKeys, keyTag, keyNode, valueNode));
2038
+ else result.push(keyNode);
2039
+ this.skipSeparationSpace(true, nodeIndent);
2040
+ ch = this.#scanner.peek();
2041
+ if (ch === 44) {
2042
+ readNext = true;
2043
+ this.#scanner.next();
2044
+ ch = this.#scanner.peek();
2045
+ } else readNext = false;
2046
+ }
2047
+ throw this.#createError("Cannot read flow collection: unexpected end of the stream within a flow collection");
2048
+ }
2049
+ readBlockScalar(tag, anchor, nodeIndent) {
2050
+ let chomping = CHOMPING_CLIP;
2051
+ let didReadContent = false;
2052
+ let detectedIndent = false;
2053
+ let textIndent = nodeIndent;
2054
+ let emptyLines = 0;
2055
+ let atMoreIndented = false;
2056
+ let ch = this.#scanner.peek();
2057
+ let folding = false;
2058
+ if (ch === 124) folding = false;
2059
+ else if (ch === 62) folding = true;
2060
+ else return;
2061
+ let result = "";
2062
+ let tmp = 0;
2063
+ while (ch !== 0) {
2064
+ this.#scanner.next();
2065
+ ch = this.#scanner.peek();
2066
+ if (ch === 43 || ch === 45) {
2067
+ if (CHOMPING_CLIP === chomping) chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
2068
+ else throw this.#createError("Cannot read block: chomping mode identifier repeated");
2069
+ } else if ((tmp = decimalCharCodeToNumber(ch)) >= 0) {
2070
+ if (tmp === 0) throw this.#createError("Cannot read block: indentation width must be greater than 0");
2071
+ else if (!detectedIndent) {
2072
+ textIndent = nodeIndent + tmp - 1;
2073
+ detectedIndent = true;
2074
+ } else throw this.#createError("Cannot read block: indentation width identifier repeated");
2075
+ } else break;
2076
+ }
2077
+ if (isWhiteSpace(ch)) {
2078
+ this.skipWhitespaces();
2079
+ this.skipComment();
2080
+ ch = this.#scanner.peek();
2081
+ }
2082
+ while (ch !== 0) {
2083
+ this.readLineBreak();
2084
+ this.lineIndent = 0;
2085
+ ch = this.#scanner.peek();
2086
+ while ((!detectedIndent || this.lineIndent < textIndent) && ch === 32) {
2087
+ this.lineIndent++;
2088
+ this.#scanner.next();
2089
+ ch = this.#scanner.peek();
2090
+ }
2091
+ if (!detectedIndent && this.lineIndent > textIndent) textIndent = this.lineIndent;
2092
+ if (isEOL(ch)) {
2093
+ emptyLines++;
2094
+ continue;
2095
+ }
2096
+ if (this.lineIndent < textIndent) {
2097
+ if (chomping === CHOMPING_KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
2098
+ else if (chomping === CHOMPING_CLIP) {
2099
+ if (didReadContent) result += "\n";
2100
+ }
2101
+ break;
2102
+ }
2103
+ if (folding) {
2104
+ if (isWhiteSpace(ch)) {
2105
+ atMoreIndented = true;
2106
+ result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
2107
+ } else if (atMoreIndented) {
2108
+ atMoreIndented = false;
2109
+ result += "\n".repeat(emptyLines + 1);
2110
+ } else if (emptyLines === 0) {
2111
+ if (didReadContent) result += " ";
2112
+ } else result += "\n".repeat(emptyLines);
2113
+ } else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
2114
+ didReadContent = true;
2115
+ detectedIndent = true;
2116
+ emptyLines = 0;
2117
+ const captureStart = this.#scanner.position;
2118
+ while (!isEOL(ch) && ch !== 0) {
2119
+ this.#scanner.next();
2120
+ ch = this.#scanner.peek();
2121
+ }
2122
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
2123
+ if (segment) result += segment;
2124
+ }
2125
+ if (anchor !== null) this.anchorMap.set(anchor, result);
2126
+ return {
2127
+ tag,
2128
+ anchor,
2129
+ kind: "scalar",
2130
+ result
2131
+ };
2132
+ }
2133
+ readBlockMapping(tag, anchor, nodeIndent, flowIndent) {
2134
+ const result = {};
2135
+ const overridableKeys = /* @__PURE__ */ new Set();
2136
+ let allowCompact = false;
2137
+ let line;
2138
+ let pos;
2139
+ let keyTag = null;
2140
+ let keyNode = null;
2141
+ let valueNode = null;
2142
+ let atExplicitKey = false;
2143
+ let detected = false;
2144
+ if (anchor !== null) this.anchorMap.set(anchor, result);
2145
+ let ch = this.#scanner.peek();
2146
+ while (ch !== 0) {
2147
+ const following = this.#scanner.peek(1);
2148
+ line = this.line;
2149
+ pos = this.#scanner.position;
2150
+ if ((ch === 63 || ch === 58) && isWhiteSpaceOrEOL(following)) {
2151
+ if (ch === 63) {
2152
+ if (atExplicitKey) {
2153
+ this.storeMappingPair(result, overridableKeys, keyTag, keyNode, null);
2154
+ keyTag = null;
2155
+ keyNode = null;
2156
+ valueNode = null;
2157
+ }
2158
+ detected = true;
2159
+ atExplicitKey = true;
2160
+ allowCompact = true;
2161
+ } else if (atExplicitKey) {
2162
+ atExplicitKey = false;
2163
+ allowCompact = true;
2164
+ } else throw this.#createError("Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line");
2165
+ this.#scanner.next();
2166
+ ch = following;
2167
+ } else {
2168
+ const newState = this.composeNode({
2169
+ parentIndent: flowIndent,
2170
+ nodeContext: CONTEXT_FLOW_OUT,
2171
+ allowToSeek: false,
2172
+ allowCompact: true
2173
+ });
2174
+ if (!newState) break;
2175
+ if (this.line === line) {
2176
+ ch = this.#scanner.peek();
2177
+ this.skipWhitespaces();
2178
+ ch = this.#scanner.peek();
2179
+ if (ch === 58) {
2180
+ this.#scanner.next();
2181
+ ch = this.#scanner.peek();
2182
+ if (!isWhiteSpaceOrEOL(ch)) throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
2183
+ if (atExplicitKey) {
2184
+ this.storeMappingPair(result, overridableKeys, keyTag, keyNode, null);
2185
+ keyTag = null;
2186
+ keyNode = null;
2187
+ valueNode = null;
2188
+ }
2189
+ detected = true;
2190
+ atExplicitKey = false;
2191
+ allowCompact = false;
2192
+ keyTag = newState.tag;
2193
+ keyNode = newState.result;
2194
+ } else if (detected) throw this.#createError("Cannot read an implicit mapping pair: missing colon");
2195
+ else {
2196
+ const { kind, result } = newState;
2197
+ return {
2198
+ tag,
2199
+ anchor,
2200
+ kind,
2201
+ result
2202
+ };
2203
+ }
2204
+ } else if (detected) throw this.#createError("Cannot read a block mapping entry: a multiline key may not be an implicit key");
2205
+ else {
2206
+ const { kind, result } = newState;
2207
+ return {
2208
+ tag,
2209
+ anchor,
2210
+ kind,
2211
+ result
2212
+ };
2213
+ }
2214
+ }
2215
+ if (this.line === line || this.lineIndent > nodeIndent) {
2216
+ const newState = this.composeNode({
2217
+ parentIndent: nodeIndent,
2218
+ nodeContext: CONTEXT_BLOCK_OUT,
2219
+ allowToSeek: true,
2220
+ allowCompact
2221
+ });
2222
+ if (newState) {
2223
+ if (atExplicitKey) keyNode = newState.result;
2224
+ else valueNode = newState.result;
2225
+ }
2226
+ if (!atExplicitKey) {
2227
+ this.storeMappingPair(result, overridableKeys, keyTag, keyNode, valueNode, line, pos);
2228
+ keyTag = keyNode = valueNode = null;
2229
+ }
2230
+ this.skipSeparationSpace(true, -1);
2231
+ ch = this.#scanner.peek();
2232
+ }
2233
+ if (this.lineIndent > nodeIndent && ch !== 0) throw this.#createError("Cannot read block: bad indentation of a mapping entry");
2234
+ else if (this.lineIndent < nodeIndent) break;
2235
+ }
2236
+ if (atExplicitKey) this.storeMappingPair(result, overridableKeys, keyTag, keyNode, null);
2237
+ if (detected) return {
2238
+ tag,
2239
+ anchor,
2240
+ kind: "mapping",
2241
+ result
2242
+ };
2243
+ }
2244
+ readTagProperty(tag) {
2245
+ let isVerbatim = false;
2246
+ let isNamed = false;
2247
+ let tagHandle = "";
2248
+ let tagName;
2249
+ let ch = this.#scanner.peek();
2250
+ if (ch !== 33) return;
2251
+ if (tag !== null) throw this.#createError("Cannot read tag property: duplication of a tag property");
2252
+ this.#scanner.next();
2253
+ ch = this.#scanner.peek();
2254
+ if (ch === 60) {
2255
+ isVerbatim = true;
2256
+ this.#scanner.next();
2257
+ ch = this.#scanner.peek();
2258
+ } else if (ch === 33) {
2259
+ isNamed = true;
2260
+ tagHandle = "!!";
2261
+ this.#scanner.next();
2262
+ ch = this.#scanner.peek();
2263
+ } else tagHandle = "!";
2264
+ let position = this.#scanner.position;
2265
+ if (isVerbatim) {
2266
+ do {
2267
+ this.#scanner.next();
2268
+ ch = this.#scanner.peek();
2269
+ } while (ch !== 0 && ch !== 62);
2270
+ if (!this.#scanner.eof()) {
2271
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
2272
+ this.#scanner.next();
2273
+ ch = this.#scanner.peek();
2274
+ } else throw this.#createError("Cannot read tag property: unexpected end of stream");
2275
+ } else {
2276
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
2277
+ if (ch === 33) {
2278
+ if (!isNamed) {
2279
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
2280
+ if (!PATTERN_TAG_HANDLE_REGEXP.test(tagHandle)) throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
2281
+ isNamed = true;
2282
+ position = this.#scanner.position + 1;
2283
+ } else throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
2284
+ }
2285
+ this.#scanner.next();
2286
+ ch = this.#scanner.peek();
2287
+ }
2288
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
2289
+ if (PATTERN_FLOW_INDICATORS_REGEXP.test(tagName)) throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
2290
+ }
2291
+ if (tagName && !PATTERN_TAG_URI_REGEXP.test(tagName)) throw this.#createError(`Cannot read tag property: invalid characters in tag name "${tagName}"`);
2292
+ if (isVerbatim) return tagName;
2293
+ else if (this.tagMap.has(tagHandle)) return this.tagMap.get(tagHandle) + tagName;
2294
+ else if (tagHandle === "!") return `!${tagName}`;
2295
+ else if (tagHandle === "!!") return `tag:yaml.org,2002:${tagName}`;
2296
+ throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
2297
+ }
2298
+ readAnchorProperty(anchor) {
2299
+ let ch = this.#scanner.peek();
2300
+ if (ch !== 38) return;
2301
+ if (anchor !== null) throw this.#createError("Cannot read anchor property: duplicate anchor property");
2302
+ this.#scanner.next();
2303
+ ch = this.#scanner.peek();
2304
+ const position = this.#scanner.position;
2305
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
2306
+ this.#scanner.next();
2307
+ ch = this.#scanner.peek();
2308
+ }
2309
+ if (this.#scanner.position === position) throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
2310
+ return this.#scanner.source.slice(position, this.#scanner.position);
2311
+ }
2312
+ readAlias() {
2313
+ if (this.#scanner.peek() !== 42) return;
2314
+ this.#scanner.next();
2315
+ let ch = this.#scanner.peek();
2316
+ const position = this.#scanner.position;
2317
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
2318
+ this.#scanner.next();
2319
+ ch = this.#scanner.peek();
2320
+ }
2321
+ if (this.#scanner.position === position) throw this.#createError("Cannot read alias: alias name must contain at least one character");
2322
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
2323
+ if (!this.anchorMap.has(alias)) throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
2324
+ this.skipSeparationSpace(true, -1);
2325
+ return this.anchorMap.get(alias);
2326
+ }
2327
+ resolveTag(state) {
2328
+ switch (state.tag) {
2329
+ case null:
2330
+ case "!": return state;
2331
+ case "?":
2332
+ for (const type of this.implicitTypes) {
2333
+ if (!type.resolve(state.result)) continue;
2334
+ const result = type.construct(state.result);
2335
+ state.result = result;
2336
+ state.tag = type.tag;
2337
+ const { anchor } = state;
2338
+ if (anchor !== null) this.anchorMap.set(anchor, result);
2339
+ return state;
2340
+ }
2341
+ return state;
2342
+ }
2343
+ const kind = state.kind ?? "fallback";
2344
+ const type = this.typeMap[kind].get(state.tag);
2345
+ if (!type) throw this.#createError(`Cannot resolve unknown tag !<${state.tag}>`);
2346
+ if (state.result !== null && type.kind !== state.kind) throw this.#createError(`Unacceptable node kind for !<${state.tag}> tag: it should be "${type.kind}", not "${state.kind}"`);
2347
+ if (!type.resolve(state.result)) throw this.#createError(`Cannot resolve a node with !<${state.tag}> explicit tag`);
2348
+ const result = type.construct(state.result);
2349
+ state.result = result;
2350
+ const { anchor } = state;
2351
+ if (anchor !== null) this.anchorMap.set(anchor, result);
2352
+ return state;
2353
+ }
2354
+ composeNode({ parentIndent, nodeContext, allowToSeek, allowCompact }) {
2355
+ let indentStatus = 1;
2356
+ let atNewLine = false;
2357
+ const allowBlockScalars = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
2358
+ let allowBlockCollections = allowBlockScalars;
2359
+ const allowBlockStyles = allowBlockScalars;
2360
+ if (allowToSeek) {
2361
+ if (this.skipSeparationSpace(true, -1)) {
2362
+ atNewLine = true;
2363
+ indentStatus = getIndentStatus(this.lineIndent, parentIndent);
2364
+ }
2365
+ }
2366
+ let tag = null;
2367
+ let anchor = null;
2368
+ if (indentStatus === 1) while (true) {
2369
+ const newTag = this.readTagProperty(tag);
2370
+ if (newTag) tag = newTag;
2371
+ else {
2372
+ const newAnchor = this.readAnchorProperty(anchor);
2373
+ if (!newAnchor) break;
2374
+ anchor = newAnchor;
2375
+ }
2376
+ if (this.skipSeparationSpace(true, -1)) {
2377
+ atNewLine = true;
2378
+ allowBlockCollections = allowBlockStyles;
2379
+ indentStatus = getIndentStatus(this.lineIndent, parentIndent);
2380
+ } else allowBlockCollections = false;
2381
+ }
2382
+ if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
2383
+ if (indentStatus === 1) {
2384
+ const flowIndent = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext ? parentIndent : parentIndent + 1;
2385
+ if (allowBlockCollections) {
2386
+ const blockIndent = this.#scanner.position - this.lineStart;
2387
+ const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
2388
+ if (blockSequenceState) return this.resolveTag(blockSequenceState);
2389
+ const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
2390
+ if (blockMappingState) return this.resolveTag(blockMappingState);
2391
+ }
2392
+ const flowCollectionState = this.readFlowCollection(tag, anchor, flowIndent);
2393
+ if (flowCollectionState) return this.resolveTag(flowCollectionState);
2394
+ if (allowBlockScalars) {
2395
+ const blockScalarState = this.readBlockScalar(tag, anchor, flowIndent);
2396
+ if (blockScalarState) return this.resolveTag(blockScalarState);
2397
+ }
2398
+ const singleQuoteState = this.readSingleQuotedScalar(tag, anchor, flowIndent);
2399
+ if (singleQuoteState) return this.resolveTag(singleQuoteState);
2400
+ const doubleQuoteState = this.readDoubleQuotedScalar(tag, anchor, flowIndent);
2401
+ if (doubleQuoteState) return this.resolveTag(doubleQuoteState);
2402
+ const alias = this.readAlias();
2403
+ if (alias) {
2404
+ if (tag !== null || anchor !== null) throw this.#createError("Cannot compose node: alias node should not have any properties");
2405
+ return this.resolveTag({
2406
+ tag,
2407
+ anchor,
2408
+ kind: null,
2409
+ result: alias
2410
+ });
2411
+ }
2412
+ const plainScalarState = this.readPlainScalar(tag, anchor, flowIndent, CONTEXT_FLOW_IN === nodeContext);
2413
+ if (plainScalarState) {
2414
+ plainScalarState.tag ??= "?";
2415
+ return this.resolveTag(plainScalarState);
2416
+ }
2417
+ } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
2418
+ const blockIndent = this.#scanner.position - this.lineStart;
2419
+ const newState = this.readBlockSequence(tag, anchor, blockIndent);
2420
+ if (newState) return this.resolveTag(newState);
2421
+ }
2422
+ const newState = this.resolveTag({
2423
+ tag,
2424
+ anchor,
2425
+ kind: null,
2426
+ result: null
2427
+ });
2428
+ if (newState.tag !== null || newState.anchor !== null) return newState;
2429
+ }
2430
+ readDirectives() {
2431
+ let hasDirectives = false;
2432
+ let version = null;
2433
+ let ch = this.#scanner.peek();
2434
+ while (ch !== 0) {
2435
+ this.skipSeparationSpace(true, -1);
2436
+ ch = this.#scanner.peek();
2437
+ if (this.lineIndent > 0 || ch !== 37) break;
2438
+ hasDirectives = true;
2439
+ this.#scanner.next();
2440
+ ch = this.#scanner.peek();
2441
+ let position = this.#scanner.position;
2442
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
2443
+ this.#scanner.next();
2444
+ ch = this.#scanner.peek();
2445
+ }
2446
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
2447
+ const directiveArgs = [];
2448
+ if (directiveName.length < 1) throw this.#createError("Cannot read document: directive name length must be greater than zero");
2449
+ while (ch !== 0) {
2450
+ this.skipWhitespaces();
2451
+ this.skipComment();
2452
+ ch = this.#scanner.peek();
2453
+ if (isEOL(ch)) break;
2454
+ position = this.#scanner.position;
2455
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
2456
+ this.#scanner.next();
2457
+ ch = this.#scanner.peek();
2458
+ }
2459
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
2460
+ }
2461
+ if (ch !== 0) this.readLineBreak();
2462
+ switch (directiveName) {
2463
+ case "YAML":
2464
+ if (version !== null) throw this.#createError("Cannot handle YAML directive: duplication of %YAML directive");
2465
+ version = this.yamlDirectiveHandler(directiveArgs);
2466
+ break;
2467
+ case "TAG":
2468
+ this.tagDirectiveHandler(directiveArgs);
2469
+ break;
2470
+ default: this.dispatchWarning(`unknown document directive "${directiveName}"`);
2471
+ }
2472
+ ch = this.#scanner.peek();
2473
+ }
2474
+ return hasDirectives;
2475
+ }
2476
+ readDocument() {
2477
+ const documentStart = this.#scanner.position;
2478
+ this.checkLineBreaks = false;
2479
+ this.tagMap = /* @__PURE__ */ new Map();
2480
+ this.anchorMap = /* @__PURE__ */ new Map();
2481
+ const hasDirectives = this.readDirectives();
2482
+ this.skipSeparationSpace(true, -1);
2483
+ let result = null;
2484
+ if (this.lineIndent === 0 && this.#scanner.peek() === 45 && this.#scanner.peek(1) === 45 && this.#scanner.peek(2) === 45) {
2485
+ this.#scanner.position += 3;
2486
+ this.skipSeparationSpace(true, -1);
2487
+ } else if (hasDirectives) throw this.#createError("Cannot read document: directives end mark is expected");
2488
+ const newState = this.composeNode({
2489
+ parentIndent: this.lineIndent - 1,
2490
+ nodeContext: CONTEXT_BLOCK_OUT,
2491
+ allowToSeek: false,
2492
+ allowCompact: true
2493
+ });
2494
+ if (newState) result = newState.result;
2495
+ this.skipSeparationSpace(true, -1);
2496
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS_REGEXP.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) this.dispatchWarning("non-ASCII line breaks are interpreted as content");
2497
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
2498
+ if (this.#scanner.peek() === 46) {
2499
+ this.#scanner.position += 3;
2500
+ this.skipSeparationSpace(true, -1);
2501
+ }
2502
+ } else if (!this.#scanner.eof()) throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
2503
+ return result;
2504
+ }
2505
+ *readDocuments(options = {}) {
2506
+ const { singleDocument = false } = options;
2507
+ let yielded = 0;
2508
+ while (!this.#scanner.eof()) {
2509
+ if (singleDocument && yielded > 0) throw this.#createError("Found more than 1 document in the stream: expected a single document");
2510
+ yield this.readDocument();
2511
+ yielded++;
2512
+ }
2513
+ }
2514
+ };
2515
+ // node_modules/@jsr/std__yaml/parse.js
2516
+ function sanitizeInput(input) {
2517
+ input = String(input);
2518
+ if (input.length > 0) {
2519
+ if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
2520
+ if (input.charCodeAt(0) === 65279) input = input.slice(1);
2521
+ }
2522
+ return input;
2523
+ }
2524
+ /**
2525
+ * Parse and return a YAML string as a parsed YAML document object.
2526
+ *
2527
+ * Note: This does not support functions. Untrusted data is safe to parse.
2528
+ *
2529
+ * @example Usage
2530
+ * ```ts
2531
+ * import { parse } from "@std/yaml/parse";
2532
+ * import { assertEquals } from "@std/assert";
2533
+ *
2534
+ * const data = parse(`
2535
+ * id: 1
2536
+ * name: Alice
2537
+ * `);
2538
+ *
2539
+ * assertEquals(data, { id: 1, name: "Alice" });
2540
+ * ```
2541
+ *
2542
+ * @throws {YamlSyntaxError} Throws if the YAML is invalid or contains more
2543
+ * than one document.
2544
+ * @param content YAML string to parse.
2545
+ * @param options Parsing options.
2546
+ * @returns Parsed document.
2547
+ */ function parse(content, options = {}) {
2548
+ content = sanitizeInput(content);
2549
+ const documents = new LoaderState(content, {
2550
+ ...options,
2551
+ schema: SCHEMA_MAP.get(options.schema)
2552
+ }).readDocuments({ singleDocument: true });
2553
+ const document = documents.next().value;
2554
+ documents.next();
2555
+ return document ?? null;
2556
+ }
2557
+ // node_modules/@std/front-matter/yaml.js
2558
+ /**
2559
+ * Extracts and parses {@link https://yaml.org | YAML} from the metadata of
2560
+ * front matter content.
2561
+ *
2562
+ * @example Extract YAML front matter
2563
+ * ```ts
2564
+ * import { extract } from "@std/front-matter/yaml";
2565
+ * import { assertEquals } from "@std/assert";
2566
+ *
2567
+ * const output = `---yaml
2568
+ * title: Three dashes marks the spot
2569
+ * ---
2570
+ * Hello, world!`;
2571
+ * const result = extract(output);
2572
+ *
2573
+ * assertEquals(result, {
2574
+ * frontMatter: "title: Three dashes marks the spot",
2575
+ * body: "Hello, world!",
2576
+ * attrs: { title: "Three dashes marks the spot" },
2577
+ * });
2578
+ * ```
2579
+ *
2580
+ * Note: If you need to pass the options to the yaml parse,
2581
+ * use the new version of this API from `@std/yaml/unstable-yaml`.
2582
+ *
2583
+ * @typeParam T The type of the parsed front matter.
2584
+ * @param text The text to extract YAML front matter from.
2585
+ * @returns The extracted YAML front matter and body content.
2586
+ */ function extract$1(text) {
2587
+ const { frontMatter, body } = extractFrontMatter(text, EXTRACT_YAML_REGEXP);
2588
+ return {
2589
+ frontMatter,
2590
+ body,
2591
+ attrs: frontMatter ? parse(frontMatter) : {}
2592
+ };
2593
+ }
2594
+ // node_modules/@std/front-matter/test.js
2595
+ /**
2596
+ * Tests if a string has valid front matter.
2597
+ * Supports {@link https://yaml.org | YAML}, {@link https://toml.io | TOML} and
2598
+ * {@link https://www.json.org/ | JSON}.
2599
+ *
2600
+ * @param str String to test.
2601
+ * @param formats A list of formats to test for. Defaults to all supported formats.
2602
+ * @returns `true` if the string has valid front matter, otherwise `false`.
2603
+ *
2604
+ * @example Test for valid YAML front matter
2605
+ * ```ts
2606
+ * import { test } from "@std/front-matter/test";
2607
+ * import { assert } from "@std/assert";
2608
+ *
2609
+ * const result = test(
2610
+ * `---
2611
+ * title: Three dashes marks the spot
2612
+ * ---
2613
+ * `);
2614
+ * assert(result);
2615
+ * ```
2616
+ *
2617
+ * @example Test for valid TOML front matter
2618
+ * ```ts
2619
+ * import { test } from "@std/front-matter/test";
2620
+ * import { assert } from "@std/assert";
2621
+ *
2622
+ * const result = test(
2623
+ * `---toml
2624
+ * title = 'Three dashes followed by format marks the spot'
2625
+ * ---
2626
+ * `);
2627
+ * assert(result);
2628
+ * ```
2629
+ *
2630
+ * @example Test for valid JSON front matter
2631
+ * ```ts
2632
+ * import { test } from "@std/front-matter/test";
2633
+ * import { assert } from "@std/assert";
2634
+ *
2635
+ * const result = test(
2636
+ * `---json
2637
+ * {"title": "Three dashes followed by format marks the spot"}
2638
+ * ---
2639
+ * `);
2640
+ * assert(result);
2641
+ * ```
2642
+ *
2643
+ * @example JSON front matter is not valid as YAML
2644
+ * ```ts
2645
+ * import { test } from "@std/front-matter/test";
2646
+ * import { assertFalse } from "@std/assert";
2647
+ *
2648
+ * const result = test(
2649
+ * `---json
2650
+ * {"title": "Three dashes followed by format marks the spot"}
2651
+ * ---
2652
+ * `, ["yaml"]);
2653
+ * assertFalse(result);
2654
+ * ```
2655
+ */ function test(str, formats) {
2656
+ if (!formats) formats = [...EXTRACT_REGEXP_MAP.keys()];
2657
+ for (const format of formats) {
2658
+ const regexp = EXTRACT_REGEXP_MAP.get(format);
2659
+ if (!regexp) throw new TypeError(`Unable to test for ${format} front matter format`);
2660
+ if (regexp.exec(str)?.index === 0) return true;
2661
+ }
2662
+ return false;
2663
+ }
2664
+ // node_modules/@std/front-matter/mod.js
2665
+ /**
2666
+ * Extracts
2667
+ * {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | front matter}
2668
+ * from strings. Adapted from
2669
+ * {@link https://github.com/jxson/front-matter/blob/36f139ef797bd9e5196a9ede03ef481d7fbca18e/index.js | jxson/front-matter}.
2670
+ *
2671
+ * ## Supported formats
2672
+ *
2673
+ * ### JSON
2674
+ *
2675
+ * ```ts
2676
+ * import { test, extractJson } from "@std/front-matter";
2677
+ * import { assertEquals } from "@std/assert";
2678
+ *
2679
+ * const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";
2680
+ *
2681
+ * assertEquals(test(str), true);
2682
+ * assertEquals(extractJson(str), {
2683
+ * frontMatter: "{\"and\": \"this\"}",
2684
+ * body: "deno is awesome",
2685
+ * attrs: { and: "this" }
2686
+ * });
2687
+ * ```
2688
+ *
2689
+ * {@linkcode extractJson | extract} and {@linkcode test} support the following
2690
+ * delimiters.
2691
+ *
2692
+ * ```markdown
2693
+ * ---json
2694
+ * {
2695
+ * "and": "this"
2696
+ * }
2697
+ * ---
2698
+ * ```
2699
+ *
2700
+ * ```markdown
2701
+ * {
2702
+ * "is": "JSON"
2703
+ * }
2704
+ * ```
2705
+ *
2706
+ * ### TOML
2707
+ *
2708
+ * ```ts
2709
+ * import { test, extractToml } from "@std/front-matter";
2710
+ * import { assertEquals } from "@std/assert";
2711
+ *
2712
+ * const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";
2713
+ *
2714
+ * assertEquals(test(str), true);
2715
+ * assertEquals(extractToml(str), {
2716
+ * frontMatter: "module = 'front_matter'",
2717
+ * body: "deno is awesome",
2718
+ * attrs: { module: "front_matter" }
2719
+ * });
2720
+ * ```
2721
+ *
2722
+ * {@linkcode extractToml | extract} and {@linkcode test} support the following
2723
+ * delimiters.
2724
+ *
2725
+ * ```markdown
2726
+ * ---toml
2727
+ * this = 'is'
2728
+ * ---
2729
+ * ```
2730
+ *
2731
+ * ```markdown
2732
+ * = toml =
2733
+ * parsed = 'as'
2734
+ * toml = 'data'
2735
+ * = toml =
2736
+ * ```
2737
+ *
2738
+ * ```markdown
2739
+ * +++
2740
+ * is = 'that'
2741
+ * not = 'cool?'
2742
+ * +++
2743
+ * ```
2744
+ *
2745
+ * ### YAML
2746
+ *
2747
+ * ```ts
2748
+ * import { test, extractYaml } from "@std/front-matter";
2749
+ * import { assertEquals } from "@std/assert";
2750
+ *
2751
+ * const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";
2752
+ *
2753
+ * assertEquals(test(str), true);
2754
+ * assertEquals(extractYaml(str), {
2755
+ * frontMatter: "module: front_matter",
2756
+ * body: "deno is awesome",
2757
+ * attrs: { module: "front_matter" }
2758
+ * });
2759
+ * ```
2760
+ *
2761
+ * {@linkcode extractYaml | extract} and {@linkcode test} support the following
2762
+ * delimiters.
2763
+ *
2764
+ * ```front_matter
2765
+ * ---
2766
+ * these: are
2767
+ * ---
2768
+ * ```
2769
+ *
2770
+ * ```markdown
2771
+ * ---yaml
2772
+ * all: recognized
2773
+ * ---
2774
+ * ```
2775
+ *
2776
+ * ```markdown
2777
+ * = yaml =
2778
+ * as: yaml
2779
+ * = yaml =
2780
+ * ```
2781
+ *
2782
+ * @module
2783
+ */
2784
+ // src/errors.ts
2785
+ /**
2786
+ * LinkedMarkdownError is a custom error class for LinkedMarkdown errors.
2787
+ */
2788
+ var LinkedMarkdownError = class extends Error {
2789
+ code;
2790
+ cause;
2791
+ constructor(code, message, cause) {
2792
+ super(message ?? code);
2793
+ this.name = "LinkedMarkdownError";
2794
+ this.code = code;
2795
+ this.cause = cause;
2796
+ }
2797
+ };
2798
+ /**
2799
+ * LMD_NO_FRONTMATTER is an error code indicating that the LinkedMarkdown
2800
+ * content does not contain frontmatter.
2801
+ */
2802
+ const LMD_NO_FRONTMATTER = "LMD_NO_FRONTMATTER";
2803
+ /**
2804
+ * LMD_INVALID_FRONTMATTER is an error code indicating that the frontmatter in
2805
+ * the LinkedMarkdown content is invalid.
2806
+ */
2807
+ const LMD_INVALID_FRONTMATTER = "LMD_INVALID_FRONTMATTER";
2808
+ // src/extract.ts
2809
+ /**
2810
+ * extract extracts front matter and body content from a LinkedMarkdown document.
2811
+ *
2812
+ * @param content The LinkedMarkdown document content.
2813
+ * @returns An object containing the extracted front matter and body content.
2814
+ */
2815
+ function extract(content) {
2816
+ content = content.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
2817
+ const markerMatch = content.match(/^---(\w+)/);
2818
+ if (markerMatch && ![
2819
+ "yaml",
2820
+ "json",
2821
+ "toml",
2822
+ ""
2823
+ ].includes(markerMatch[1].toLowerCase())) throw new LinkedMarkdownError(LMD_INVALID_FRONTMATTER, `Unknown front matter marker: ${markerMatch[1]}`);
2824
+ const equalsMatch = content.match(/^= (\w+) =/);
2825
+ if (equalsMatch && ![
2826
+ "yaml",
2827
+ "json",
2828
+ "toml"
2829
+ ].includes(equalsMatch[1].toLowerCase())) throw new LinkedMarkdownError(LMD_INVALID_FRONTMATTER, `Unknown front matter marker: ${equalsMatch[1]}`);
2830
+ if (!/^(---|\+\+\+(?:\n|$)|= \w+ =(?:\n|$))/.test(content)) throw new LinkedMarkdownError(LMD_NO_FRONTMATTER);
2831
+ try {
2832
+ let result;
2833
+ if (test(content, ["json"])) result = extract$3(content);
2834
+ else if (test(content, ["toml"])) result = extract$2(content);
2835
+ else if (test(content, ["yaml"])) result = extract$1(content);
2836
+ else throw new LinkedMarkdownError(LMD_INVALID_FRONTMATTER);
2837
+ if (typeof result.attrs !== "object" || result.attrs === null || Array.isArray(result.attrs)) throw new LinkedMarkdownError(LMD_INVALID_FRONTMATTER);
2838
+ return {
2839
+ ...result,
2840
+ frontMatter: result.frontMatter && !result.frontMatter.endsWith("\n") ? result.frontMatter + "\n" : result.frontMatter
2841
+ };
2842
+ } catch (e) {
2843
+ if (e instanceof LinkedMarkdownError) throw e;
2844
+ throw new LinkedMarkdownError(LMD_INVALID_FRONTMATTER, void 0, e instanceof Error ? e : void 0);
2845
+ }
2846
+ }
2847
+ export { LMD_INVALID_FRONTMATTER, LMD_NO_FRONTMATTER, LinkedMarkdownError, extract };