@mytools-all/mytools-json 0.0.0-stage → 0.1.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/yaml.mjs ADDED
@@ -0,0 +1,3656 @@
1
+ /*! js-yaml 5.5.0 https://github.com/nodeca/js-yaml @license MIT */
2
+ //#region src/tag.ts
3
+ /**
4
+ * Returned by a scalar resolver when the source does not match its tag.
5
+ *
6
+ * @category Tags
7
+ */
8
+ var NOT_RESOLVED = Symbol("NOT_RESOLVED");
9
+ /**
10
+ * Create a normalized scalar tag definition.
11
+ *
12
+ * @category Tags
13
+ */
14
+ function defineScalarTag(tagName, options) {
15
+ return {
16
+ tagName,
17
+ nodeKind: "scalar",
18
+ implicit: options.implicit ?? false,
19
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
20
+ implicitFirstChars: options.implicitFirstChars ?? null,
21
+ resolve: options.resolve,
22
+ identify: options.identify,
23
+ represent: options.represent ?? ((data) => String(data)),
24
+ representTagName: options.representTagName ?? (() => tagName)
25
+ };
26
+ }
27
+ /**
28
+ * Create a normalized sequence tag definition.
29
+ *
30
+ * @category Tags
31
+ */
32
+ function defineSequenceTag(tagName, options) {
33
+ const carrierIsResult = options.finalize === void 0;
34
+ return {
35
+ tagName,
36
+ nodeKind: "sequence",
37
+ implicit: false,
38
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
39
+ create: options.create,
40
+ addItem: options.addItem,
41
+ finalize: options.finalize ?? ((carrier) => carrier),
42
+ carrierIsResult,
43
+ identify: options.identify,
44
+ represent: options.represent ?? ((data) => data),
45
+ representTagName: options.representTagName ?? (() => tagName)
46
+ };
47
+ }
48
+ /**
49
+ * Create a normalized mapping tag definition.
50
+ *
51
+ * @category Tags
52
+ */
53
+ function defineMappingTag(tagName, options) {
54
+ const carrierIsResult = options.finalize === void 0;
55
+ return {
56
+ tagName,
57
+ nodeKind: "mapping",
58
+ implicit: false,
59
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
60
+ create: options.create,
61
+ addPair: options.addPair,
62
+ has: options.has,
63
+ keys: options.keys,
64
+ get: options.get,
65
+ finalize: options.finalize ?? ((carrier) => carrier),
66
+ carrierIsResult,
67
+ identify: options.identify,
68
+ represent: options.represent ?? ((data) => data),
69
+ representTagName: options.representTagName ?? (() => tagName)
70
+ };
71
+ }
72
+ //#endregion
73
+ //#region src/tag/scalar/str.ts
74
+ /** @category Tags */
75
+ var strTag = defineScalarTag("tag:yaml.org,2002:str", {
76
+ resolve: (source) => source,
77
+ identify: (data) => typeof data === "string"
78
+ });
79
+ //#endregion
80
+ //#region src/tag/scalar/null_core.ts
81
+ var NULL_VALUES$1 = [
82
+ "",
83
+ "~",
84
+ "null",
85
+ "Null",
86
+ "NULL"
87
+ ];
88
+ /** @category Tags */
89
+ var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
90
+ implicit: true,
91
+ implicitFirstChars: [
92
+ "",
93
+ "~",
94
+ "n",
95
+ "N"
96
+ ],
97
+ resolve: (source) => {
98
+ if (NULL_VALUES$1.indexOf(source) !== -1) return null;
99
+ return NOT_RESOLVED;
100
+ },
101
+ identify: (object) => object === null,
102
+ represent: () => "null"
103
+ });
104
+ //#endregion
105
+ //#region src/tag/scalar/null_json.ts
106
+ /** @category Tags */
107
+ var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
108
+ implicit: true,
109
+ implicitFirstChars: ["n"],
110
+ resolve: (source, isExplicit) => {
111
+ if (source === "null" || isExplicit && source === "") return null;
112
+ return NOT_RESOLVED;
113
+ },
114
+ identify: (object) => object === null,
115
+ represent: () => "null"
116
+ });
117
+ //#endregion
118
+ //#region src/tag/scalar/null_yaml11.ts
119
+ var NULL_VALUES = [
120
+ "",
121
+ "~",
122
+ "null",
123
+ "Null",
124
+ "NULL"
125
+ ];
126
+ /** @category Tags */
127
+ var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
128
+ implicit: true,
129
+ implicitFirstChars: [
130
+ "",
131
+ "~",
132
+ "n",
133
+ "N"
134
+ ],
135
+ resolve: (source) => {
136
+ if (NULL_VALUES.indexOf(source) !== -1) return null;
137
+ return NOT_RESOLVED;
138
+ },
139
+ identify: (object) => object === null,
140
+ represent: () => "null"
141
+ });
142
+ //#endregion
143
+ //#region src/tag/scalar/bool_core.ts
144
+ var TRUE_VALUES$2 = [
145
+ "true",
146
+ "True",
147
+ "TRUE"
148
+ ];
149
+ var FALSE_VALUES$2 = [
150
+ "false",
151
+ "False",
152
+ "FALSE"
153
+ ];
154
+ /** @category Tags */
155
+ var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
156
+ implicit: true,
157
+ implicitFirstChars: [
158
+ "t",
159
+ "T",
160
+ "f",
161
+ "F"
162
+ ],
163
+ resolve: (source) => {
164
+ if (TRUE_VALUES$2.indexOf(source) !== -1) return true;
165
+ if (FALSE_VALUES$2.indexOf(source) !== -1) return false;
166
+ return NOT_RESOLVED;
167
+ },
168
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
169
+ represent: (object) => object ? "true" : "false"
170
+ });
171
+ //#endregion
172
+ //#region src/tag/scalar/bool_json.ts
173
+ var TRUE_VALUES$1 = ["true"];
174
+ var FALSE_VALUES$1 = ["false"];
175
+ /** @category Tags */
176
+ var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
177
+ implicit: true,
178
+ implicitFirstChars: ["t", "f"],
179
+ resolve: (source) => {
180
+ if (TRUE_VALUES$1.indexOf(source) !== -1) return true;
181
+ if (FALSE_VALUES$1.indexOf(source) !== -1) return false;
182
+ return NOT_RESOLVED;
183
+ },
184
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
185
+ represent: (object) => object ? "true" : "false"
186
+ });
187
+ //#endregion
188
+ //#region src/tag/scalar/bool_yaml11.ts
189
+ var TRUE_VALUES = [
190
+ "true",
191
+ "True",
192
+ "TRUE",
193
+ "y",
194
+ "Y",
195
+ "yes",
196
+ "Yes",
197
+ "YES",
198
+ "on",
199
+ "On",
200
+ "ON"
201
+ ];
202
+ var FALSE_VALUES = [
203
+ "false",
204
+ "False",
205
+ "FALSE",
206
+ "n",
207
+ "N",
208
+ "no",
209
+ "No",
210
+ "NO",
211
+ "off",
212
+ "Off",
213
+ "OFF"
214
+ ];
215
+ /** @category Tags */
216
+ var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
217
+ implicit: true,
218
+ implicitFirstChars: [
219
+ "y",
220
+ "Y",
221
+ "n",
222
+ "N",
223
+ "t",
224
+ "T",
225
+ "f",
226
+ "F",
227
+ "o",
228
+ "O"
229
+ ],
230
+ resolve: (source) => {
231
+ if (TRUE_VALUES.indexOf(source) !== -1) return true;
232
+ if (FALSE_VALUES.indexOf(source) !== -1) return false;
233
+ return NOT_RESOLVED;
234
+ },
235
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
236
+ represent: (object) => object ? "true" : "false"
237
+ });
238
+ //#endregion
239
+ //#region src/tag/scalar/int_core.ts
240
+ var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
241
+ var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
242
+ function parseYamlInteger$2(source) {
243
+ let value = source;
244
+ let sign = 1;
245
+ if (value[0] === "-" || value[0] === "+") {
246
+ if (value[0] === "-") sign = -1;
247
+ value = value.slice(1);
248
+ }
249
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
250
+ if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
251
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
252
+ return sign * parseInt(value, 10);
253
+ }
254
+ function resolveYamlInteger$2(source, isExplicit) {
255
+ if (isExplicit) {
256
+ if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
257
+ } else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
258
+ const result = parseYamlInteger$2(source);
259
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
260
+ }
261
+ /** @category Tags */
262
+ var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
263
+ implicit: true,
264
+ implicitFirstChars: [
265
+ "-",
266
+ "+",
267
+ ..."0123456789"
268
+ ],
269
+ resolve: resolveYamlInteger$2,
270
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
271
+ represent: (object) => object.toString(10)
272
+ });
273
+ //#endregion
274
+ //#region src/tag/scalar/int_json.ts
275
+ var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
276
+ var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
277
+ function parseYamlInteger$1(source) {
278
+ let value = source;
279
+ let sign = 1;
280
+ if (value[0] === "-" || value[0] === "+") {
281
+ if (value[0] === "-") sign = -1;
282
+ value = value.slice(1);
283
+ }
284
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
285
+ if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
286
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
287
+ return sign * parseInt(value, 10);
288
+ }
289
+ function resolveYamlInteger$1(source, isExplicit) {
290
+ if (isExplicit) {
291
+ if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
292
+ } else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
293
+ const result = parseYamlInteger$1(source);
294
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
295
+ }
296
+ /** @category Tags */
297
+ var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
298
+ implicit: true,
299
+ implicitFirstChars: ["-", ..."0123456789"],
300
+ resolve: resolveYamlInteger$1,
301
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
302
+ represent: (object) => object.toString(10)
303
+ });
304
+ //#endregion
305
+ //#region src/tag/scalar/int_yaml11.ts
306
+ var YAML_INTEGER_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?0x[0-9a-fA-F_]+|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+|[-+]?(?:0|[1-9][0-9_]*))$");
307
+ function parseYamlInteger(source) {
308
+ let value = source.replace(/_/g, "");
309
+ let sign = 1;
310
+ if (value[0] === "-" || value[0] === "+") {
311
+ if (value[0] === "-") sign = -1;
312
+ value = value.slice(1);
313
+ }
314
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
315
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
316
+ if (value.includes(":")) {
317
+ let result = 0;
318
+ for (const part of value.split(":")) result = result * 60 + Number(part);
319
+ return sign * result;
320
+ }
321
+ if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8);
322
+ return sign * parseInt(value, 10);
323
+ }
324
+ function resolveYamlInteger(source) {
325
+ if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED;
326
+ const result = parseYamlInteger(source);
327
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
328
+ }
329
+ /** @category Tags */
330
+ var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
331
+ implicit: true,
332
+ implicitFirstChars: [
333
+ "-",
334
+ "+",
335
+ ..."0123456789"
336
+ ],
337
+ resolve: resolveYamlInteger,
338
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
339
+ represent: (object) => object.toString(10)
340
+ });
341
+ //#endregion
342
+ //#region src/tag/scalar/float_core.ts
343
+ var YAML_FLOAT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
344
+ var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
345
+ function resolveYamlFloat$2(source) {
346
+ if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED;
347
+ let value = source.toLowerCase();
348
+ const sign = value[0] === "-" ? -1 : 1;
349
+ if ("+-".includes(value[0])) value = value.slice(1);
350
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
351
+ if (value === ".nan") return NaN;
352
+ const result = sign * parseFloat(value);
353
+ if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result;
354
+ return NOT_RESOLVED;
355
+ }
356
+ function representYamlFloat$2(object) {
357
+ if (isNaN(object)) return ".nan";
358
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
359
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
360
+ if (Object.is(object, -0)) return "-0.0";
361
+ const result = object.toString(10);
362
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
363
+ }
364
+ /** @category Tags */
365
+ var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
366
+ implicit: true,
367
+ implicitFirstChars: [
368
+ "-",
369
+ "+",
370
+ ".",
371
+ ..."0123456789"
372
+ ],
373
+ resolve: resolveYamlFloat$2,
374
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
375
+ represent: representYamlFloat$2
376
+ });
377
+ //#endregion
378
+ //#region src/tag/scalar/float_json.ts
379
+ var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
380
+ var YAML_FLOAT_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
381
+ function resolveYamlFloat$1(source, isExplicit) {
382
+ if (isExplicit) {
383
+ if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
384
+ let value = source.toLowerCase();
385
+ const sign = value[0] === "-" ? -1 : 1;
386
+ if ("+-".includes(value[0])) value = value.slice(1);
387
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
388
+ if (value === ".nan") return NaN;
389
+ const result = sign * parseFloat(value);
390
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
391
+ }
392
+ if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
393
+ const result = Number(source);
394
+ if (Number.isFinite(result)) return result;
395
+ return NOT_RESOLVED;
396
+ }
397
+ function representYamlFloat$1(object) {
398
+ if (isNaN(object)) return ".nan";
399
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
400
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
401
+ if (Object.is(object, -0)) return "-0.0";
402
+ const result = object.toString(10);
403
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
404
+ }
405
+ /** @category Tags */
406
+ var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
407
+ implicit: true,
408
+ implicitFirstChars: ["-", ..."0123456789"],
409
+ resolve: resolveYamlFloat$1,
410
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
411
+ represent: representYamlFloat$1
412
+ });
413
+ //#endregion
414
+ //#region src/tag/scalar/float_yaml11.ts
415
+ var YAML_FLOAT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:(?:[0-9][0-9_]*)?\\.[0-9_]*)(?:[eE][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
416
+ var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
417
+ function resolveYamlFloat(source) {
418
+ if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED;
419
+ let value = source.toLowerCase().replace(/_/g, "");
420
+ const sign = value[0] === "-" ? -1 : 1;
421
+ if ("+-".includes(value[0])) value = value.slice(1);
422
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
423
+ if (value === ".nan") return NaN;
424
+ let result = 0;
425
+ if (value.includes(":")) {
426
+ for (const part of value.split(":")) result = result * 60 + Number(part);
427
+ result *= sign;
428
+ } else result = sign * parseFloat(value);
429
+ if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result;
430
+ return NOT_RESOLVED;
431
+ }
432
+ function representYamlFloat(object) {
433
+ if (isNaN(object)) return ".nan";
434
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
435
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
436
+ if (Object.is(object, -0)) return "-0.0";
437
+ const result = object.toString(10);
438
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
439
+ }
440
+ /** @category Tags */
441
+ var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
442
+ implicit: true,
443
+ implicitFirstChars: [
444
+ "-",
445
+ "+",
446
+ ".",
447
+ ..."0123456789"
448
+ ],
449
+ resolve: resolveYamlFloat,
450
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
451
+ represent: representYamlFloat
452
+ });
453
+ //#endregion
454
+ //#region src/tag/scalar/merge.ts
455
+ /**
456
+ * Enables merge keys in {@link CORE_SCHEMA} when added with
457
+ * {@link Schema.withTags}.
458
+ *
459
+ * @category Tags
460
+ */
461
+ var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
462
+ implicit: true,
463
+ implicitFirstChars: ["<"],
464
+ resolve: (source, isExplicit) => {
465
+ if (source === "<<" || isExplicit && source === "") return "<<";
466
+ return NOT_RESOLVED;
467
+ },
468
+ identify: () => false
469
+ });
470
+ //#endregion
471
+ //#region src/tag/scalar/binary.ts
472
+ var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
473
+ function resolveYamlBinary(source) {
474
+ const input = source.replace(/\s/g, "");
475
+ if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED;
476
+ const binary = atob(input);
477
+ const result = new Uint8Array(binary.length);
478
+ for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index);
479
+ return result;
480
+ }
481
+ function representYamlBinary(object) {
482
+ let binary = "";
483
+ for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
484
+ return btoa(binary);
485
+ }
486
+ /**
487
+ * The `!!binary` tag, represented as a `Uint8Array`.
488
+ *
489
+ * @category Tags
490
+ */
491
+ var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
492
+ resolve: resolveYamlBinary,
493
+ identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
494
+ represent: representYamlBinary
495
+ });
496
+ //#endregion
497
+ //#region src/tag/scalar/timestamp.ts
498
+ var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
499
+ var 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]))?))?$");
500
+ function makeUtcDate(year, month, day, hour = 0, minute = 0, second = 0, fraction = 0) {
501
+ const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
502
+ date.setUTCFullYear(year, month, day);
503
+ return date;
504
+ }
505
+ function resolveYamlTimestamp(source) {
506
+ let match = YAML_DATE_REGEXP.exec(source);
507
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
508
+ if (match === null) return NOT_RESOLVED;
509
+ const year = +match[1];
510
+ const month = +match[2] - 1;
511
+ const day = +match[3];
512
+ if (!match[4]) {
513
+ const date = makeUtcDate(year, month, day);
514
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
515
+ return date;
516
+ }
517
+ const hour = +match[4];
518
+ const minute = +match[5];
519
+ const second = +match[6];
520
+ let fraction = 0;
521
+ if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED;
522
+ if (match[7]) {
523
+ let value = match[7].slice(0, 3);
524
+ while (value.length < 3) value += "0";
525
+ fraction = +value;
526
+ }
527
+ const date = makeUtcDate(year, month, day, hour, minute, second, fraction);
528
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
529
+ if (match[9]) {
530
+ const offsetHour = +match[10];
531
+ const offsetMinute = +(match[11] || 0);
532
+ if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED;
533
+ const offset = (offsetHour * 60 + offsetMinute) * 6e4;
534
+ date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
535
+ }
536
+ return date;
537
+ }
538
+ /**
539
+ * The YAML 1.1 `!!timestamp` tag, represented as a JavaScript `Date`.
540
+ *
541
+ * @category Tags
542
+ */
543
+ var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
544
+ implicit: true,
545
+ implicitFirstChars: [..."0123456789"],
546
+ resolve: resolveYamlTimestamp,
547
+ identify: (object) => object instanceof Date,
548
+ represent: (object) => object.toISOString()
549
+ });
550
+ //#endregion
551
+ //#region src/tag/sequence/seq.ts
552
+ /** @category Tags */
553
+ var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
554
+ create: () => [],
555
+ addItem: (container, item) => {
556
+ container.push(item);
557
+ },
558
+ identify: Array.isArray
559
+ });
560
+ //#endregion
561
+ //#region src/common/object.ts
562
+ function isPlainObject(data) {
563
+ if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
564
+ const prototype = Object.getPrototypeOf(data);
565
+ return prototype === null || prototype === Object.prototype;
566
+ }
567
+ function pick(object, keys) {
568
+ const result = {};
569
+ for (const key of keys) if (object[key] !== void 0) result[key] = object[key];
570
+ return result;
571
+ }
572
+ //#endregion
573
+ //#region src/tag/sequence/omap.ts
574
+ /**
575
+ * Provided only for YAML 1.1 compatibility and supported by the loader only.
576
+ * JavaScript has no dedicated class to represent this type, so it cannot be
577
+ * identified and dumped.
578
+ *
579
+ * ```yaml
580
+ * !!omap
581
+ * - one: 1
582
+ * - two: 2
583
+ * ```
584
+ *
585
+ * is loaded as
586
+ *
587
+ * ```javascript
588
+ * [
589
+ * { one: 1 },
590
+ * { two: 2 }
591
+ * ]
592
+ * ```
593
+ *
594
+ * @category Tags
595
+ */
596
+ var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
597
+ create: () => ({
598
+ list: [],
599
+ seen: /* @__PURE__ */ new Set()
600
+ }),
601
+ addItem: (carrier, item) => {
602
+ let key;
603
+ if (item instanceof Map) {
604
+ if (item.size !== 1) return "cannot resolve an ordered map item";
605
+ key = item.keys().next().value;
606
+ } else if (isPlainObject(item)) {
607
+ const itemKeys = Object.keys(item);
608
+ if (itemKeys.length !== 1) return "cannot resolve an ordered map item";
609
+ key = itemKeys[0];
610
+ } else return "cannot resolve an ordered map item";
611
+ if (carrier.seen.has(key)) return "duplicate key in ordered map";
612
+ carrier.seen.add(key);
613
+ carrier.list.push(item);
614
+ return "";
615
+ },
616
+ finalize: (carrier) => carrier.list,
617
+ identify: () => false
618
+ });
619
+ //#endregion
620
+ //#region src/tag/sequence/pairs.ts
621
+ /**
622
+ * Provided only for YAML 1.1 compatibility and supported by the loader only.
623
+ * JavaScript has no dedicated class to represent this type, so it cannot be
624
+ * identified and dumped.
625
+ *
626
+ * ```yaml
627
+ * !!pairs
628
+ * - one: 1
629
+ * - two: 2
630
+ * ```
631
+ *
632
+ * is loaded as
633
+ *
634
+ * ```javascript
635
+ * [
636
+ * ['one', 1],
637
+ * ['two', 2]
638
+ * ]
639
+ * ```
640
+ *
641
+ * @category Tags
642
+ */
643
+ var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
644
+ create: () => [],
645
+ addItem: (container, item) => {
646
+ if (item instanceof Map) {
647
+ if (item.size !== 1) return "cannot resolve a pairs item";
648
+ container.push(item.entries().next().value);
649
+ return "";
650
+ }
651
+ if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item";
652
+ const object = item;
653
+ const keys = Object.keys(object);
654
+ if (keys.length !== 1) return "cannot resolve a pairs item";
655
+ container.push([keys[0], object[keys[0]]]);
656
+ return "";
657
+ },
658
+ identify: () => false
659
+ });
660
+ //#endregion
661
+ //#region src/tag/mapping/map.ts
662
+ /**
663
+ * This is the default mapping implementation. It uses `{}` objects and has only
664
+ * partial functionality due to language limitations. This choice was made
665
+ * because users expect to get JavaScript objects, and it was left unchanged to
666
+ * avoid too many breaking changes in the v5 release.
667
+ *
668
+ * Side effects:
669
+ *
670
+ * - `Object.hasOwn()` checks or `for...of` loops are required for safe use (to
671
+ * avoid falling through to prototypes).
672
+ * - Only scalar string keys are supported properly.
673
+ * - Other scalar keys, such as `null` and numbers, are converted to strings.
674
+ * This is historical behaviour, and it can cause side effects such as
675
+ * problems with `!!merge`.
676
+ *
677
+ * Note that non-string scalar keys may be deprecated in future versions.
678
+ *
679
+ * Ideally, use {@link realMapTag} instead.
680
+ *
681
+ * @category Tags
682
+ */
683
+ var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
684
+ create: () => ({}),
685
+ identify: isPlainObject,
686
+ represent: (o) => {
687
+ const map = /* @__PURE__ */ new Map();
688
+ for (const key of Object.keys(o)) map.set(key, o[key]);
689
+ return map;
690
+ },
691
+ addPair: (container, key, value) => {
692
+ if (key !== null && typeof key === "object") return "object-based map does not support complex keys";
693
+ const normalizedKey = String(key);
694
+ if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
695
+ value,
696
+ enumerable: true,
697
+ configurable: true,
698
+ writable: true
699
+ });
700
+ else container[normalizedKey] = value;
701
+ return "";
702
+ },
703
+ has: (container, key) => {
704
+ if (key !== null && typeof key === "object") return false;
705
+ return Object.prototype.hasOwnProperty.call(container, String(key));
706
+ },
707
+ keys: (container) => Object.keys(container),
708
+ get: (container, key) => {
709
+ const normalizedKey = String(key);
710
+ if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
711
+ return container[normalizedKey];
712
+ }
713
+ });
714
+ //#endregion
715
+ //#region src/tag/mapping/set.ts
716
+ /**
717
+ * The YAML 1.1 `!!set` tag, represented as a JavaScript `Set`.
718
+ *
719
+ * @category Tags
720
+ */
721
+ var setTag = defineMappingTag("tag:yaml.org,2002:set", {
722
+ create: () => /* @__PURE__ */ new Set(),
723
+ identify: (data) => data instanceof Set,
724
+ represent: (data) => {
725
+ const map = /* @__PURE__ */ new Map();
726
+ for (const key of data) map.set(key, null);
727
+ return map;
728
+ },
729
+ addPair: (container, key, value) => {
730
+ if (value !== null) return "cannot resolve a set item";
731
+ container.add(key);
732
+ return "";
733
+ },
734
+ has: (container, key) => container.has(key),
735
+ keys: (container) => container.keys(),
736
+ get: () => null
737
+ });
738
+ //#endregion
739
+ //#region src/schema.ts
740
+ function createTagDefinitionMap() {
741
+ return {
742
+ scalar: Object.create(null),
743
+ sequence: Object.create(null),
744
+ mapping: Object.create(null)
745
+ };
746
+ }
747
+ function createTagDefinitionListMap() {
748
+ return {
749
+ scalar: [],
750
+ sequence: [],
751
+ mapping: []
752
+ };
753
+ }
754
+ function compileTags(tags) {
755
+ const result = [];
756
+ for (const tag of tags) {
757
+ let index = result.length;
758
+ for (let previousIndex = 0; previousIndex < result.length; previousIndex++) {
759
+ const previous = result[previousIndex];
760
+ if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
761
+ index = previousIndex;
762
+ break;
763
+ }
764
+ }
765
+ result[index] = tag;
766
+ }
767
+ return result;
768
+ }
769
+ /**
770
+ * Controls tag resolution when loading and type selection when dumping.
771
+ *
772
+ * @category Schemas
773
+ */
774
+ var Schema = class Schema {
775
+ tags;
776
+ /** @internal */
777
+ implicitScalarTags;
778
+ /**
779
+ * Dispatch implicit scalar resolvers by `source.charAt(0)`. Each bucket holds
780
+ * the resolvers that may match that key, in schema order; a key absent from
781
+ * the map uses
782
+ * {@link Schema.implicitScalarAnyFirstChar}
783
+ * (resolvers that declared no first-char constraint, so they apply to any
784
+ * first character).
785
+ */
786
+ implicitScalarByFirstChar;
787
+ implicitScalarAnyFirstChar;
788
+ /**
789
+ * The default scalar tag (`!!str`), resolved once so the composer's fallback
790
+ * for unresolved plain scalars avoids a keyed lookup per scalar.
791
+ *
792
+ * @internal
793
+ */
794
+ defaultScalarTag;
795
+ /**
796
+ * The default container tags (`!!seq` / `!!map`), used by the dumper: when a
797
+ * value is identified by its default tag, the tag is implicit and not
798
+ * printed. Undefined if the schema does not define them (then such values
799
+ * can't be dumped).
800
+ *
801
+ * @internal
802
+ */
803
+ defaultSequenceTag;
804
+ /** @internal */
805
+ defaultMappingTag;
806
+ exact;
807
+ prefix;
808
+ constructor(tags) {
809
+ const compiledTags = compileTags(tags);
810
+ const implicitScalarTags = [];
811
+ const exact = createTagDefinitionMap();
812
+ const prefix = createTagDefinitionListMap();
813
+ for (const tag of compiledTags) {
814
+ if (tag.nodeKind === "scalar" && tag.implicit) {
815
+ if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix");
816
+ implicitScalarTags.push(tag);
817
+ }
818
+ switch (tag.nodeKind) {
819
+ case "scalar":
820
+ if (tag.matchByTagPrefix) prefix.scalar.push(tag);
821
+ else exact.scalar[tag.tagName] = tag;
822
+ break;
823
+ case "sequence":
824
+ if (tag.matchByTagPrefix) prefix.sequence.push(tag);
825
+ else exact.sequence[tag.tagName] = tag;
826
+ break;
827
+ case "mapping": if (tag.matchByTagPrefix) prefix.mapping.push(tag);
828
+ else exact.mapping[tag.tagName] = tag;
829
+ }
830
+ }
831
+ const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
832
+ const keys = /* @__PURE__ */ new Set();
833
+ for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key);
834
+ const implicitScalarByFirstChar = /* @__PURE__ */ new Map();
835
+ for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
836
+ const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
837
+ if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
838
+ this.tags = compiledTags;
839
+ this.implicitScalarTags = implicitScalarTags;
840
+ this.implicitScalarByFirstChar = implicitScalarByFirstChar;
841
+ this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
842
+ this.defaultScalarTag = defaultScalarTag;
843
+ this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
844
+ this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
845
+ this.exact = exact;
846
+ this.prefix = prefix;
847
+ }
848
+ /** @internal */
849
+ lookupScalarTag(tagName) {
850
+ const exactTag = this.exact.scalar[tagName];
851
+ if (exactTag) return exactTag;
852
+ for (const tag of this.prefix.scalar) if (tagName.startsWith(tag.tagName)) return tag;
853
+ }
854
+ /** @internal */
855
+ lookupSequenceTag(tagName) {
856
+ const exactTag = this.exact.sequence[tagName];
857
+ if (exactTag) return exactTag;
858
+ for (const tag of this.prefix.sequence) if (tagName.startsWith(tag.tagName)) return tag;
859
+ }
860
+ /** @internal */
861
+ lookupMappingTag(tagName) {
862
+ const exactTag = this.exact.mapping[tagName];
863
+ if (exactTag) return exactTag;
864
+ for (const tag of this.prefix.mapping) if (tagName.startsWith(tag.tagName)) return tag;
865
+ }
866
+ /** @internal */
867
+ resolveImplicitScalarTag(source) {
868
+ const candidates = this.implicitScalarByFirstChar.get(source.charAt(0)) ?? this.implicitScalarAnyFirstChar;
869
+ for (const tag of candidates) {
870
+ const value = tag.resolve(source, false, tag.tagName);
871
+ if (value !== NOT_RESOLVED) return {
872
+ value,
873
+ tag
874
+ };
875
+ }
876
+ const tag = this.defaultScalarTag;
877
+ return {
878
+ value: tag.resolve(source, false, tag.tagName),
879
+ tag
880
+ };
881
+ }
882
+ /**
883
+ * Creates a new schema with the specified tags added. If a tag already
884
+ * exists, it is replaced by the specified tag.
885
+ *
886
+ * @example
887
+ *
888
+ * ```javascript
889
+ * import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
890
+ *
891
+ * const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)
892
+ * ```
893
+ */
894
+ withTags(...tags) {
895
+ let flatTags = [];
896
+ for (const tag of tags) flatTags = flatTags.concat(tag);
897
+ return new Schema([...this.tags, ...flatTags]);
898
+ }
899
+ };
900
+ /**
901
+ * The YAML 1.2 Failsafe Schema: strings, sequences, and mappings.
902
+ *
903
+ * @category Schemas
904
+ */
905
+ var FAILSAFE_SCHEMA = new Schema([
906
+ strTag,
907
+ seqTag,
908
+ mapTag
909
+ ]);
910
+ /**
911
+ * The YAML 1.2 JSON Schema. It uses JSON scalar forms while retaining YAML
912
+ * collection syntax.
913
+ *
914
+ * @category Schemas
915
+ */
916
+ var JSON_SCHEMA = new Schema([
917
+ ...FAILSAFE_SCHEMA.tags,
918
+ nullJsonTag,
919
+ boolJsonTag,
920
+ intJsonTag,
921
+ floatJsonTag
922
+ ]);
923
+ /**
924
+ * The default schema for the loaders. Note, {@link CORE_SCHEMA} comes
925
+ * without the `!!merge` tag. You can easily enable it if needed.
926
+ *
927
+ * @example
928
+ * Enable {@link mergeTag}:
929
+ *
930
+ * ```javascript
931
+ * import { load, CORE_SCHEMA, mergeTag } from 'js-yaml'
932
+ *
933
+ * try {
934
+ * load(data, { schema: CORE_SCHEMA.withTags(mergeTag) })
935
+ * } catch (e) {
936
+ * console.error(e)
937
+ * }
938
+ * ```
939
+ *
940
+ * @category Schemas
941
+ */
942
+ var CORE_SCHEMA = new Schema([
943
+ ...FAILSAFE_SCHEMA.tags,
944
+ nullCoreTag,
945
+ boolCoreTag,
946
+ intCoreTag,
947
+ floatCoreTag
948
+ ]);
949
+ /**
950
+ * YAML 1.1-compatible schema.
951
+ *
952
+ * @category Schemas
953
+ */
954
+ var YAML11_SCHEMA = new Schema([
955
+ ...FAILSAFE_SCHEMA.tags,
956
+ nullYaml11Tag,
957
+ boolYaml11Tag,
958
+ intYaml11Tag,
959
+ floatYaml11Tag,
960
+ timestampTag,
961
+ mergeTag,
962
+ binaryTag,
963
+ omapTag,
964
+ pairsTag,
965
+ setTag
966
+ ]);
967
+ /**
968
+ * The dumper schema for maximum compatibility. It combines all supported type
969
+ * variants from YAML 1.1 and YAML 1.2 so strings matching any of them are
970
+ * quoted. This makes the generated YAML more compatible with other parsers.
971
+ *
972
+ * The schema is based on YAML 1.1, but extends `!!int` and `!!float` to accept
973
+ * both YAML 1.1 and Core Schema forms, since Core Schema supports some forms
974
+ * that YAML 1.1 does not.
975
+ *
976
+ * @category Schemas
977
+ */
978
+ var DUMP_SCHEMA = YAML11_SCHEMA.withTags({
979
+ ...intYaml11Tag,
980
+ resolve: (source, isExplicit, tagName) => {
981
+ const result = intYaml11Tag.resolve(source, isExplicit, tagName);
982
+ return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
983
+ }
984
+ }, {
985
+ ...floatYaml11Tag,
986
+ resolve: (source, isExplicit, tagName) => {
987
+ const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
988
+ return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
989
+ }
990
+ });
991
+ //#endregion
992
+ //#region src/tag/mapping/real_map.ts
993
+ /**
994
+ * Recommended when non-string keys are actually needed. It uses native
995
+ * JavaScript `Map` objects, so keys keep their constructed types instead of
996
+ * being converted to strings.
997
+ *
998
+ * It is not the default to avoid widespread breaking changes in existing
999
+ * projects. `Map` has a different access API and does not pass deep equality
1000
+ * checks against `{}`-based fixtures. Alongside the other changes in v5,
1001
+ * making it the default was considered too disruptive.
1002
+ *
1003
+ * If these differences are acceptable for your project, we recommend using
1004
+ * {@link realMapTag} to guarantee the absence of problems and side effects.
1005
+ *
1006
+ * @example
1007
+ * Enable {@link realMapTag}:
1008
+ *
1009
+ * ```javascript
1010
+ * import { load, CORE_SCHEMA, realMapTag } from 'js-yaml'
1011
+ *
1012
+ * try {
1013
+ * load(data, { schema: CORE_SCHEMA.withTags(realMapTag) })
1014
+ * } catch (e) {
1015
+ * console.error(e)
1016
+ * }
1017
+ * ```
1018
+ *
1019
+ * @category Tags
1020
+ */
1021
+ var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
1022
+ create: () => /* @__PURE__ */ new Map(),
1023
+ addPair: (container, key, value) => {
1024
+ container.set(key, value);
1025
+ return "";
1026
+ },
1027
+ has: (container, key) => container.has(key),
1028
+ keys: (container) => container.keys(),
1029
+ get: (container, key) => container.get(key),
1030
+ identify: (data) => data instanceof Map || isPlainObject(data),
1031
+ represent: (data) => {
1032
+ if (data instanceof Map) return data;
1033
+ const map = /* @__PURE__ */ new Map();
1034
+ const obj = data;
1035
+ for (const key of Object.keys(obj)) map.set(key, obj[key]);
1036
+ return map;
1037
+ }
1038
+ });
1039
+ //#endregion
1040
+ //#region src/tag/mapping/legacy_map.ts
1041
+ function normalizeKey(key) {
1042
+ if (Array.isArray(key)) {
1043
+ const array = Array.prototype.slice.call(key);
1044
+ for (let index = 0; index < array.length; index++) {
1045
+ if (Array.isArray(array[index])) return null;
1046
+ if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]";
1047
+ }
1048
+ return String(array);
1049
+ }
1050
+ if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
1051
+ return String(key);
1052
+ }
1053
+ /**
1054
+ * This implementation exists solely to reproduce v4 behavior exactly. Its use
1055
+ * is strongly discouraged. If complex or non-string keys are needed, use
1056
+ * {@link realMapTag} instead.
1057
+ *
1058
+ * @category Tags
1059
+ */
1060
+ var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
1061
+ create: () => ({}),
1062
+ identify: isPlainObject,
1063
+ represent: (o) => {
1064
+ const map = /* @__PURE__ */ new Map();
1065
+ for (const key of Object.keys(o)) map.set(key, o[key]);
1066
+ return map;
1067
+ },
1068
+ addPair: (container, key, value) => {
1069
+ const normalizedKey = normalizeKey(key);
1070
+ if (normalizedKey === null) return "nested arrays are not supported inside keys";
1071
+ if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
1072
+ value,
1073
+ enumerable: true,
1074
+ configurable: true,
1075
+ writable: true
1076
+ });
1077
+ else container[normalizedKey] = value;
1078
+ return "";
1079
+ },
1080
+ has: (container, key) => {
1081
+ const normalizedKey = normalizeKey(key);
1082
+ return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
1083
+ },
1084
+ keys: (container) => Object.keys(container),
1085
+ get: (container, key) => {
1086
+ const normalizedKey = String(key);
1087
+ if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
1088
+ return container[normalizedKey];
1089
+ }
1090
+ });
1091
+ //#endregion
1092
+ //#region src/common/snippet.ts
1093
+ var DEFAULT_SNIPPET_OPTIONS = {
1094
+ maxLength: 79,
1095
+ indent: 1,
1096
+ linesBefore: 3,
1097
+ linesAfter: 2
1098
+ };
1099
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
1100
+ let head = "";
1101
+ let tail = "";
1102
+ const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
1103
+ if (position - lineStart > maxHalfLength) {
1104
+ head = " ... ";
1105
+ lineStart = position - maxHalfLength + head.length;
1106
+ }
1107
+ if (lineEnd - position > maxHalfLength) {
1108
+ tail = " ...";
1109
+ lineEnd = position + maxHalfLength - tail.length;
1110
+ }
1111
+ return {
1112
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
1113
+ pos: position - lineStart + head.length
1114
+ };
1115
+ }
1116
+ function padStart(string, max) {
1117
+ return " ".repeat(Math.max(max - string.length, 0)) + string;
1118
+ }
1119
+ function makeSnippet(mark, options) {
1120
+ if (!mark.buffer) return null;
1121
+ const opts = {
1122
+ ...DEFAULT_SNIPPET_OPTIONS,
1123
+ ...options
1124
+ };
1125
+ const re = /\r?\n|\r|\0/g;
1126
+ const lineStarts = [0];
1127
+ const lineEnds = [];
1128
+ let match;
1129
+ let foundLineNo = -1;
1130
+ while (match = re.exec(mark.buffer)) {
1131
+ lineEnds.push(match.index);
1132
+ lineStarts.push(match.index + match[0].length);
1133
+ if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2;
1134
+ }
1135
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
1136
+ let result = "";
1137
+ const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
1138
+ const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
1139
+ for (let i = 1; i <= opts.linesBefore; i++) {
1140
+ if (foundLineNo - i < 0) break;
1141
+ const line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
1142
+ result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line.str}\n${result}`;
1143
+ }
1144
+ const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
1145
+ result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}\n`;
1146
+ result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^\n`;
1147
+ for (let i = 1; i <= opts.linesAfter; i++) {
1148
+ if (foundLineNo + i >= lineEnds.length) break;
1149
+ const line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
1150
+ result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line.str}\n`;
1151
+ }
1152
+ return result.replace(/\n$/, "");
1153
+ }
1154
+ //#endregion
1155
+ //#region src/common/exception.ts
1156
+ function formatError(exception, compact) {
1157
+ let where = "";
1158
+ if (!exception.mark) return exception.reason;
1159
+ if (exception.mark.name) where += `in "${exception.mark.name}" `;
1160
+ where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
1161
+ if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
1162
+ return `${exception.reason} ${where}`;
1163
+ }
1164
+ /**
1165
+ * A YAML error. Unlike an ordinary `Error`, it adds a source snippet showing
1166
+ * the location of the problem to the error message, when available.
1167
+ *
1168
+ * @category Main
1169
+ */
1170
+ var YAMLException = class YAMLException extends Error {
1171
+ reason;
1172
+ mark;
1173
+ /**
1174
+ * Optional `mark` contains source snippet data. Usually, use
1175
+ * {@link YAMLException.throwAt} instead of passing it directly.
1176
+ */
1177
+ constructor(reason, mark) {
1178
+ super();
1179
+ this.name = "YAMLException";
1180
+ this.reason = reason;
1181
+ this.mark = mark;
1182
+ this.message = formatError(this, false);
1183
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
1184
+ }
1185
+ /**
1186
+ * Returns the formatted error, omitting the source snippet in compact mode.
1187
+ */
1188
+ toString(compact) {
1189
+ return `${this.name}: ${formatError(this, compact)}`;
1190
+ }
1191
+ /**
1192
+ * Builds a YAMLException with a source snippet and throws it. `source` is
1193
+ * the raw input text; `position` is an offset into it.
1194
+ */
1195
+ static throwAt(source, position, message, filename = "") {
1196
+ let line = 0;
1197
+ let lineStart = 0;
1198
+ for (let index = 0; index < position; index++) {
1199
+ const ch = source.charCodeAt(index);
1200
+ if (ch === 10) {
1201
+ line++;
1202
+ lineStart = index + 1;
1203
+ } else if (ch === 13) {
1204
+ line++;
1205
+ if (source.charCodeAt(index + 1) === 10) index++;
1206
+ lineStart = index + 1;
1207
+ }
1208
+ }
1209
+ const mark = {
1210
+ name: filename,
1211
+ buffer: source,
1212
+ position,
1213
+ line,
1214
+ column: position - lineStart
1215
+ };
1216
+ mark.snippet = makeSnippet(mark);
1217
+ throw new YAMLException(message, mark);
1218
+ }
1219
+ };
1220
+ //#endregion
1221
+ //#region src/parser/events.ts
1222
+ /** @category Events */
1223
+ var EVENT_ID = {
1224
+ DOCUMENT: 1,
1225
+ SEQUENCE: 2,
1226
+ MAPPING: 3,
1227
+ SCALAR: 4,
1228
+ ALIAS: 5,
1229
+ POP: 6
1230
+ };
1231
+ /** @category Nodes */
1232
+ var SCALAR_STYLE = {
1233
+ PLAIN: 1,
1234
+ SINGLE_QUOTED: 2,
1235
+ DOUBLE_QUOTED: 3,
1236
+ LITERAL_BLOCK: 4,
1237
+ FOLDED_BLOCK: 5
1238
+ };
1239
+ /** @category Nodes */
1240
+ var COLLECTION_STYLE = {
1241
+ BLOCK: 1,
1242
+ FLOW: 2
1243
+ };
1244
+ /** @category Nodes */
1245
+ var CHOMPING_MODE = {
1246
+ CLIP: 1,
1247
+ STRIP: 2,
1248
+ KEEP: 3
1249
+ };
1250
+ //#endregion
1251
+ //#region src/parser/parser_scalar.ts
1252
+ var NO_RANGE$3 = -1;
1253
+ function simpleEscapeSequence(c) {
1254
+ switch (c) {
1255
+ case 48: return "\0";
1256
+ case 97: return "\x07";
1257
+ case 98: return "\b";
1258
+ case 116: return " ";
1259
+ case 9: return " ";
1260
+ case 110: return "\n";
1261
+ case 118: return "\v";
1262
+ case 102: return "\f";
1263
+ case 114: return "\r";
1264
+ case 101: return "\x1B";
1265
+ case 32: return " ";
1266
+ case 34: return "\"";
1267
+ case 47: return "/";
1268
+ case 92: return "\\";
1269
+ case 78: return "…";
1270
+ case 95: return "\xA0";
1271
+ case 76: return "\u2028";
1272
+ case 80: return "\u2029";
1273
+ default: return "";
1274
+ }
1275
+ }
1276
+ var simpleEscapeCheck = new Array(256);
1277
+ var simpleEscapeMap = new Array(256);
1278
+ for (let i = 0; i < 256; i++) {
1279
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1280
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
1281
+ }
1282
+ function charFromCodepoint(c) {
1283
+ if (c <= 65535) return String.fromCharCode(c);
1284
+ return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
1285
+ }
1286
+ function fromHexCode$1(c) {
1287
+ if (c >= 48 && c <= 57) return c - 48;
1288
+ return (c | 32) - 97 + 10;
1289
+ }
1290
+ function escapedHexLen$1(c) {
1291
+ if (c === 120) return 2;
1292
+ if (c === 117) return 4;
1293
+ return 8;
1294
+ }
1295
+ function skipFoldedBreaks(input, position, end) {
1296
+ let breaks = 0;
1297
+ while (position < end) {
1298
+ const ch = input.charCodeAt(position);
1299
+ if (ch === 10) {
1300
+ breaks++;
1301
+ position++;
1302
+ } else if (ch === 13) {
1303
+ breaks++;
1304
+ position++;
1305
+ if (input.charCodeAt(position) === 10) position++;
1306
+ } else if (ch === 32 || ch === 9) position++;
1307
+ else break;
1308
+ }
1309
+ return {
1310
+ position,
1311
+ breaks
1312
+ };
1313
+ }
1314
+ function foldedBreaks(count) {
1315
+ if (count === 1) return " ";
1316
+ return "\n".repeat(count - 1);
1317
+ }
1318
+ function getPlainValue(input, start, end) {
1319
+ let result = "";
1320
+ let position = start;
1321
+ let captureStart = start;
1322
+ let captureEnd = start;
1323
+ while (position < end) {
1324
+ const ch = input.charCodeAt(position);
1325
+ if (ch === 10 || ch === 13) {
1326
+ result += input.slice(captureStart, captureEnd);
1327
+ const fold = skipFoldedBreaks(input, position, end);
1328
+ result += foldedBreaks(fold.breaks);
1329
+ position = captureStart = captureEnd = fold.position;
1330
+ } else {
1331
+ position++;
1332
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1333
+ }
1334
+ }
1335
+ return result + input.slice(captureStart, captureEnd);
1336
+ }
1337
+ function getSingleQuotedValue(input, start, end) {
1338
+ let result = "";
1339
+ let position = start;
1340
+ let captureStart = start;
1341
+ let captureEnd = start;
1342
+ while (position < end) {
1343
+ const ch = input.charCodeAt(position);
1344
+ if (ch === 39) {
1345
+ result += input.slice(captureStart, position) + "'";
1346
+ position += 2;
1347
+ captureStart = captureEnd = position;
1348
+ } else if (ch === 10 || ch === 13) {
1349
+ result += input.slice(captureStart, captureEnd);
1350
+ const fold = skipFoldedBreaks(input, position, end);
1351
+ result += foldedBreaks(fold.breaks);
1352
+ position = captureStart = captureEnd = fold.position;
1353
+ } else {
1354
+ position++;
1355
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1356
+ }
1357
+ }
1358
+ return result + input.slice(captureStart, end);
1359
+ }
1360
+ function getDoubleQuotedValue(input, start, end) {
1361
+ let result = "";
1362
+ let position = start;
1363
+ let captureStart = start;
1364
+ let captureEnd = start;
1365
+ while (position < end) {
1366
+ const ch = input.charCodeAt(position);
1367
+ if (ch === 92) {
1368
+ result += input.slice(captureStart, position);
1369
+ position++;
1370
+ const escaped = input.charCodeAt(position);
1371
+ if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position;
1372
+ else if (escaped < 256 && simpleEscapeCheck[escaped]) {
1373
+ result += simpleEscapeMap[escaped];
1374
+ position++;
1375
+ } else {
1376
+ let hexLength = escapedHexLen$1(escaped);
1377
+ let hexResult = 0;
1378
+ for (; hexLength > 0; hexLength--) {
1379
+ position++;
1380
+ const digit = fromHexCode$1(input.charCodeAt(position));
1381
+ hexResult = (hexResult << 4) + digit;
1382
+ }
1383
+ result += charFromCodepoint(hexResult);
1384
+ position++;
1385
+ }
1386
+ captureStart = captureEnd = position;
1387
+ } else if (ch === 10 || ch === 13) {
1388
+ result += input.slice(captureStart, captureEnd);
1389
+ const fold = skipFoldedBreaks(input, position, end);
1390
+ result += foldedBreaks(fold.breaks);
1391
+ position = captureStart = captureEnd = fold.position;
1392
+ } else {
1393
+ position++;
1394
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1395
+ }
1396
+ }
1397
+ return result + input.slice(captureStart, end);
1398
+ }
1399
+ function getBlockValue(input, start, end, indent, chomping, folded) {
1400
+ const textIndent = indent < 0 ? 0 : indent;
1401
+ const region = input.slice(start, end).replace(/\r\n?/g, "\n");
1402
+ const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n");
1403
+ let result = "";
1404
+ let didReadContent = false;
1405
+ let emptyLines = 0;
1406
+ let atMoreIndented = false;
1407
+ for (const line of lines) {
1408
+ let column = 0;
1409
+ while (column < textIndent && line.charCodeAt(column) === 32) column++;
1410
+ if (indent < 0 || column >= line.length) {
1411
+ emptyLines++;
1412
+ continue;
1413
+ }
1414
+ const content = line.slice(textIndent);
1415
+ const first = content.charCodeAt(0);
1416
+ if (folded) {
1417
+ if (first === 32 || first === 9) {
1418
+ atMoreIndented = true;
1419
+ result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1420
+ } else if (atMoreIndented) {
1421
+ atMoreIndented = false;
1422
+ result += "\n".repeat(emptyLines + 1);
1423
+ } else if (emptyLines === 0) {
1424
+ if (didReadContent) result += " ";
1425
+ } else result += "\n".repeat(emptyLines);
1426
+ } else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1427
+ result += content;
1428
+ didReadContent = true;
1429
+ emptyLines = 0;
1430
+ }
1431
+ if (chomping === CHOMPING_MODE.KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1432
+ else if (chomping !== CHOMPING_MODE.STRIP) {
1433
+ if (didReadContent) result += "\n";
1434
+ }
1435
+ return result;
1436
+ }
1437
+ /**
1438
+ * Decodes the scalar referenced by event offsets in `input`.
1439
+ *
1440
+ * @category Events
1441
+ */
1442
+ function getScalarValue(input, scalar) {
1443
+ if (scalar.valueStart === NO_RANGE$3) return "";
1444
+ const { valueStart, valueEnd } = scalar;
1445
+ if (scalar.fast) return input.slice(valueStart, valueEnd);
1446
+ switch (scalar.style) {
1447
+ case SCALAR_STYLE.SINGLE_QUOTED: return getSingleQuotedValue(input, valueStart, valueEnd);
1448
+ case SCALAR_STYLE.DOUBLE_QUOTED: return getDoubleQuotedValue(input, valueStart, valueEnd);
1449
+ case SCALAR_STYLE.LITERAL_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
1450
+ case SCALAR_STYLE.FOLDED_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
1451
+ default: return getPlainValue(input, valueStart, valueEnd);
1452
+ }
1453
+ }
1454
+ //#endregion
1455
+ //#region src/common/tagname.ts
1456
+ var DEFAULT_TAG_HANDLERS = Object.assign(Object.create(null), {
1457
+ "!": "!",
1458
+ "!!": "tag:yaml.org,2002:"
1459
+ });
1460
+ var TAG_SUFFIX_CHARS = "-#;/?:@&=+$_.~*'()";
1461
+ var TAG_URI_CHARS = TAG_SUFFIX_CHARS + "!,[]";
1462
+ var HEX = "0123456789ABCDEF";
1463
+ function percentByte(byte) {
1464
+ return "%" + HEX[byte >> 4] + HEX[byte & 15];
1465
+ }
1466
+ function tagPercentEncode(source, isSuffix) {
1467
+ const allowed = isSuffix ? TAG_SUFFIX_CHARS : TAG_URI_CHARS;
1468
+ let result = "";
1469
+ for (let index = 0; index < source.length; index++) {
1470
+ let ch = source.charCodeAt(index);
1471
+ if (ch >= 48 && ch <= 57 || ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || allowed.includes(source[index])) {
1472
+ result += source[index];
1473
+ continue;
1474
+ }
1475
+ if (ch >= 55296 && ch <= 56319) ch = 65536 + ((ch & 1023) << 10) + (source.charCodeAt(++index) & 1023);
1476
+ if (ch < 128) result += percentByte(ch);
1477
+ else if (ch < 2048) result += percentByte(192 | ch >> 6) + percentByte(128 | ch & 63);
1478
+ else if (ch < 65536) result += percentByte(224 | ch >> 12) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
1479
+ else result += percentByte(240 | ch >> 18) + percentByte(128 | ch >> 12 & 63) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
1480
+ }
1481
+ return result;
1482
+ }
1483
+ function tagPercentDecode(source) {
1484
+ let result = "";
1485
+ let index = 0;
1486
+ while (index < source.length) {
1487
+ if (source.charCodeAt(index) !== 37) {
1488
+ result += source[index++];
1489
+ continue;
1490
+ }
1491
+ let ch = parseInt(source.slice(index + 1, index + 3), 16);
1492
+ index += 3;
1493
+ if (ch >= 192) {
1494
+ let remaining = ch < 224 ? 1 : ch < 240 ? 2 : 3;
1495
+ ch &= (1 << 6 - remaining) - 1;
1496
+ while (remaining-- > 0) {
1497
+ ch = ch << 6 | parseInt(source.slice(index + 1, index + 3), 16) & 63;
1498
+ index += 3;
1499
+ }
1500
+ }
1501
+ if (ch < 65536) result += String.fromCharCode(ch);
1502
+ else {
1503
+ ch -= 65536;
1504
+ result += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
1505
+ }
1506
+ }
1507
+ return result;
1508
+ }
1509
+ function tagNameFull(rawTag, tagHandlers) {
1510
+ if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return tagPercentDecode(rawTag.slice(2, -1));
1511
+ const handleEnd = rawTag.indexOf("!", 1);
1512
+ const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
1513
+ return tagPercentDecode(tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle) + tagPercentDecode(rawTag.slice(handle.length));
1514
+ }
1515
+ function tagNameShort(fullTag) {
1516
+ let tag = fullTag;
1517
+ if (tag.charCodeAt(0) === 33) {
1518
+ tag = tag.slice(1);
1519
+ return `!${tagPercentEncode(tag, true)}`;
1520
+ }
1521
+ if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18), true)}`;
1522
+ return `!<${tagPercentEncode(tag, false)}>`;
1523
+ }
1524
+ //#endregion
1525
+ //#region src/parser/constructor.ts
1526
+ var NO_RANGE$2 = -1;
1527
+ var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
1528
+ var DEFAULT_CONSTRUCTOR_OPTIONS = {
1529
+ filename: "",
1530
+ schema: CORE_SCHEMA,
1531
+ json: false,
1532
+ maxTotalMergeKeys: 1e4,
1533
+ maxAliases: -1
1534
+ };
1535
+ function eventPosition$1(event) {
1536
+ if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart;
1537
+ if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart;
1538
+ if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart;
1539
+ if ("start" in event) return event.start;
1540
+ return 0;
1541
+ }
1542
+ function throwError$1(state, message) {
1543
+ YAMLException.throwAt(state.source, state.position, message, state.filename);
1544
+ }
1545
+ function finalizeCollection(state, position, tag, carrier) {
1546
+ try {
1547
+ return tag.finalize(carrier);
1548
+ } catch (error) {
1549
+ if (error instanceof YAMLException) throw error;
1550
+ YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
1551
+ }
1552
+ }
1553
+ function constructScalar(state, event) {
1554
+ const source = getScalarValue(state.source, event);
1555
+ const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1556
+ const strTag = state.schema.defaultScalarTag;
1557
+ if (rawTag !== "") {
1558
+ if (rawTag === "!") return {
1559
+ value: source,
1560
+ tag: strTag
1561
+ };
1562
+ const tagName = tagNameFull(rawTag, state.tagHandlers);
1563
+ const scalarTag = state.schema.lookupScalarTag(tagName);
1564
+ if (scalarTag) {
1565
+ const result = scalarTag.resolve(source, true, tagName);
1566
+ if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1567
+ return {
1568
+ value: result,
1569
+ tag: scalarTag
1570
+ };
1571
+ }
1572
+ const collectionTagDef = state.schema.lookupMappingTag(tagName) ?? state.schema.lookupSequenceTag(tagName);
1573
+ if (collectionTagDef) {
1574
+ if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1575
+ const carrier = collectionTagDef.create(tagName);
1576
+ return {
1577
+ value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier),
1578
+ tag: collectionTagDef
1579
+ };
1580
+ }
1581
+ throwError$1(state, `unknown scalar tag !<${tagName}>`);
1582
+ }
1583
+ if (event.style === SCALAR_STYLE.PLAIN) return state.schema.resolveImplicitScalarTag(source);
1584
+ return {
1585
+ value: strTag.resolve(source, false, strTag.tagName),
1586
+ tag: strTag
1587
+ };
1588
+ }
1589
+ function collectionTagName(state, event, defaultTagName) {
1590
+ const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1591
+ return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
1592
+ }
1593
+ function isMappingTag(tag) {
1594
+ return tag.nodeKind === "mapping";
1595
+ }
1596
+ function chargeMergeWork(state) {
1597
+ state.totalMergeKeys++;
1598
+ if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
1599
+ }
1600
+ function mergeKeys(state, frame, source, sourceTag) {
1601
+ chargeMergeWork(state);
1602
+ for (const sourceKey of sourceTag.keys(source)) {
1603
+ chargeMergeWork(state);
1604
+ if (frame.tag.has(frame.value, sourceKey)) continue;
1605
+ const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
1606
+ if (err) throwError$1(state, err);
1607
+ frame.overridable ??= /* @__PURE__ */ new Set();
1608
+ frame.overridable.add(sourceKey);
1609
+ }
1610
+ }
1611
+ function mergeSource(state, frame, source, sourceTag) {
1612
+ state.position = frame.keyPosition;
1613
+ if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
1614
+ else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
1615
+ if (source.length > 100) throwError$1(state, "abnormal merge sequence size");
1616
+ for (const element of source) {
1617
+ const elementTag = state.nodeTags.get(element);
1618
+ if (!elementTag) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1619
+ mergeKeys(state, frame, element, elementTag);
1620
+ }
1621
+ } else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1622
+ }
1623
+ function addMappingValue(state, frame, key, value, tag) {
1624
+ state.position = frame.keyPosition;
1625
+ if (frame.keyIsMerge) {
1626
+ mergeSource(state, frame, value, tag);
1627
+ return;
1628
+ }
1629
+ if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key)) throwError$1(state, "duplicated mapping key");
1630
+ const err = frame.tag.addPair(frame.value, key, value);
1631
+ if (err) throwError$1(state, err);
1632
+ frame.overridable?.delete(key);
1633
+ }
1634
+ function addValue(state, value, tag) {
1635
+ const frame = state.frames[state.frames.length - 1];
1636
+ if (frame.kind === "document") {
1637
+ frame.value = value;
1638
+ frame.hasValue = true;
1639
+ } else if (frame.kind === "sequence") {
1640
+ if (isMappingTag(tag)) state.nodeTags.set(value, tag);
1641
+ const err = frame.tag.addItem(frame.value, value, frame.index++);
1642
+ if (err) throwError$1(state, err);
1643
+ } else if (frame.hasKey) {
1644
+ const key = frame.key;
1645
+ frame.key = void 0;
1646
+ frame.hasKey = false;
1647
+ addMappingValue(state, frame, key, value, tag);
1648
+ } else {
1649
+ frame.key = value;
1650
+ frame.keyPosition = state.position;
1651
+ frame.hasKey = true;
1652
+ frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
1653
+ }
1654
+ }
1655
+ function storeAnchor(state, event, value, tag, isValueFinal) {
1656
+ if (event.anchorStart !== NO_RANGE$2) {
1657
+ const anchor = {
1658
+ value,
1659
+ tag,
1660
+ isValueFinal
1661
+ };
1662
+ state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor);
1663
+ return anchor;
1664
+ }
1665
+ return null;
1666
+ }
1667
+ /**
1668
+ * Constructs JavaScript documents directly from parser events, without an
1669
+ * intermediate AST.
1670
+ *
1671
+ * @category Events
1672
+ */
1673
+ function constructFromEvents(events, options) {
1674
+ const state = {
1675
+ ...DEFAULT_CONSTRUCTOR_OPTIONS,
1676
+ ...options,
1677
+ events,
1678
+ documents: [],
1679
+ eventIndex: 0,
1680
+ position: 0,
1681
+ frames: [],
1682
+ anchors: /* @__PURE__ */ new Map(),
1683
+ nodeTags: /* @__PURE__ */ new Map(),
1684
+ tagHandlers: Object.create(null),
1685
+ totalMergeKeys: 0,
1686
+ aliasCount: 0
1687
+ };
1688
+ while (state.eventIndex < state.events.length) {
1689
+ const event = state.events[state.eventIndex++];
1690
+ state.position = eventPosition$1(event);
1691
+ switch (event.type) {
1692
+ case EVENT_ID.DOCUMENT:
1693
+ state.anchors = /* @__PURE__ */ new Map();
1694
+ state.nodeTags = /* @__PURE__ */ new Map();
1695
+ state.aliasCount = 0;
1696
+ state.tagHandlers = Object.create(null);
1697
+ for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
1698
+ state.frames.push({
1699
+ kind: "document",
1700
+ position: state.position,
1701
+ value: void 0,
1702
+ hasValue: false
1703
+ });
1704
+ break;
1705
+ case EVENT_ID.SCALAR: {
1706
+ const { value, tag } = constructScalar(state, event);
1707
+ storeAnchor(state, event, value, tag, true);
1708
+ addValue(state, value, tag);
1709
+ break;
1710
+ }
1711
+ case EVENT_ID.SEQUENCE: {
1712
+ const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
1713
+ const tag = state.schema.lookupSequenceTag(tagName);
1714
+ if (!tag) throwError$1(state, `unknown sequence tag !<${tagName}>`);
1715
+ const value = tag.create(tagName);
1716
+ const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
1717
+ state.frames.push({
1718
+ kind: "sequence",
1719
+ position: state.position,
1720
+ value,
1721
+ tag,
1722
+ anchor,
1723
+ index: 0
1724
+ });
1725
+ break;
1726
+ }
1727
+ case EVENT_ID.MAPPING: {
1728
+ const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
1729
+ const tag = state.schema.lookupMappingTag(tagName);
1730
+ if (!tag) throwError$1(state, `unknown mapping tag !<${tagName}>`);
1731
+ const value = tag.create(tagName);
1732
+ const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
1733
+ state.frames.push({
1734
+ kind: "mapping",
1735
+ position: state.position,
1736
+ value,
1737
+ tag,
1738
+ anchor,
1739
+ key: void 0,
1740
+ keyPosition: state.position,
1741
+ hasKey: false,
1742
+ keyIsMerge: false,
1743
+ overridable: null
1744
+ });
1745
+ break;
1746
+ }
1747
+ case EVENT_ID.ALIAS: {
1748
+ if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
1749
+ const name = state.source.slice(event.anchorStart, event.anchorEnd);
1750
+ const anchor = state.anchors.get(name);
1751
+ if (!anchor) throwError$1(state, `unidentified alias "${name}"`);
1752
+ if (!anchor.isValueFinal) throwError$1(state, `recursive alias "${name}" is not supported for tag ${anchor.tag.tagName} because it uses finalize()`);
1753
+ addValue(state, anchor.value, anchor.tag);
1754
+ break;
1755
+ }
1756
+ case EVENT_ID.POP: {
1757
+ const frame = state.frames.pop();
1758
+ if (frame.kind === "mapping" && frame.hasKey) {
1759
+ state.position = frame.keyPosition;
1760
+ throwError$1(state, "incomplete mapping pair in event stream");
1761
+ }
1762
+ if (frame.kind === "document") state.documents.push(frame.value);
1763
+ else {
1764
+ const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
1765
+ if (frame.anchor) {
1766
+ frame.anchor.value = value;
1767
+ frame.anchor.isValueFinal = true;
1768
+ }
1769
+ addValue(state, value, frame.tag);
1770
+ }
1771
+ break;
1772
+ }
1773
+ }
1774
+ }
1775
+ return state.documents;
1776
+ }
1777
+ //#endregion
1778
+ //#region src/parser/parser.ts
1779
+ var NO_RANGE$1 = -1;
1780
+ var HAS_OWN = Object.prototype.hasOwnProperty;
1781
+ var CONTEXT_FLOW_IN = 1;
1782
+ var CONTEXT_FLOW_OUT = 2;
1783
+ var CONTEXT_BLOCK_IN = 3;
1784
+ var CONTEXT_BLOCK_OUT = 4;
1785
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1786
+ var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
1787
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
1788
+ var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
1789
+ var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
1790
+ var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
1791
+ var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
1792
+ var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
1793
+ var DEFAULT_PARSER_OPTIONS = {
1794
+ filename: "",
1795
+ maxDepth: 100
1796
+ };
1797
+ function addDocumentEvent(state, explicitStart, explicitEnd) {
1798
+ state.events.push({
1799
+ type: EVENT_ID.DOCUMENT,
1800
+ explicitStart,
1801
+ explicitEnd,
1802
+ directives: state.directives
1803
+ });
1804
+ }
1805
+ function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1806
+ state.events.push({
1807
+ type: EVENT_ID.SEQUENCE,
1808
+ start,
1809
+ anchorStart,
1810
+ anchorEnd,
1811
+ tagStart,
1812
+ tagEnd,
1813
+ style
1814
+ });
1815
+ }
1816
+ function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1817
+ state.events.push({
1818
+ type: EVENT_ID.MAPPING,
1819
+ start,
1820
+ anchorStart,
1821
+ anchorEnd,
1822
+ tagStart,
1823
+ tagEnd,
1824
+ style
1825
+ });
1826
+ }
1827
+ function insertFlowPairMappingEvent(state, snapshot) {
1828
+ state.events.splice(snapshot.eventsLength, 0, {
1829
+ type: EVENT_ID.MAPPING,
1830
+ start: snapshot.position,
1831
+ anchorStart: NO_RANGE$1,
1832
+ anchorEnd: NO_RANGE$1,
1833
+ tagStart: NO_RANGE$1,
1834
+ tagEnd: NO_RANGE$1,
1835
+ style: COLLECTION_STYLE.FLOW
1836
+ });
1837
+ }
1838
+ function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
1839
+ state.events.push({
1840
+ type: EVENT_ID.SCALAR,
1841
+ valueStart,
1842
+ valueEnd,
1843
+ anchorStart,
1844
+ anchorEnd,
1845
+ tagStart,
1846
+ tagEnd,
1847
+ style,
1848
+ chomping,
1849
+ indent,
1850
+ fast
1851
+ });
1852
+ }
1853
+ function addAliasEvent(state, anchorStart, anchorEnd) {
1854
+ state.events.push({
1855
+ type: EVENT_ID.ALIAS,
1856
+ anchorStart,
1857
+ anchorEnd
1858
+ });
1859
+ }
1860
+ function addPopEvent(state) {
1861
+ state.events.push({ type: EVENT_ID.POP });
1862
+ }
1863
+ function addEmptyScalarEvent(state) {
1864
+ addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
1865
+ }
1866
+ function emptyProperties() {
1867
+ return {
1868
+ anchorStart: NO_RANGE$1,
1869
+ anchorEnd: NO_RANGE$1,
1870
+ tagStart: NO_RANGE$1,
1871
+ tagEnd: NO_RANGE$1
1872
+ };
1873
+ }
1874
+ function snapshotState(state) {
1875
+ return {
1876
+ position: state.position,
1877
+ line: state.line,
1878
+ lineStart: state.lineStart,
1879
+ lineIndent: state.lineIndent,
1880
+ firstTabInLine: state.firstTabInLine,
1881
+ eventsLength: state.events.length
1882
+ };
1883
+ }
1884
+ function restoreState(state, snapshot) {
1885
+ state.position = snapshot.position;
1886
+ state.line = snapshot.line;
1887
+ state.lineStart = snapshot.lineStart;
1888
+ state.lineIndent = snapshot.lineIndent;
1889
+ state.firstTabInLine = snapshot.firstTabInLine;
1890
+ state.events.length = snapshot.eventsLength;
1891
+ }
1892
+ function throwError(state, message) {
1893
+ YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
1894
+ }
1895
+ function isEol(c) {
1896
+ return c === 10 || c === 13;
1897
+ }
1898
+ function isWhiteSpace(c) {
1899
+ return c === 9 || c === 32;
1900
+ }
1901
+ function isWsOrEol(c) {
1902
+ return isWhiteSpace(c) || isEol(c);
1903
+ }
1904
+ function isWsOrEolOrEnd(c) {
1905
+ return c === 0 || isWsOrEol(c);
1906
+ }
1907
+ function isFlowIndicator(c) {
1908
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
1909
+ }
1910
+ function fromDecimalCode(c) {
1911
+ return c >= 48 && c <= 57 ? c - 48 : -1;
1912
+ }
1913
+ function fromHexCode(c) {
1914
+ if (c >= 48 && c <= 57) return c - 48;
1915
+ const lc = c | 32;
1916
+ if (lc >= 97 && lc <= 102) return lc - 97 + 10;
1917
+ return -1;
1918
+ }
1919
+ function escapedHexLen(c) {
1920
+ if (c === 120) return 2;
1921
+ if (c === 117) return 4;
1922
+ if (c === 85) return 8;
1923
+ return 0;
1924
+ }
1925
+ function isSimpleEscape(c) {
1926
+ return c === 48 || c === 97 || c === 98 || c === 116 || c === 9 || c === 110 || c === 118 || c === 102 || c === 114 || c === 101 || c === 32 || c === 34 || c === 47 || c === 92 || c === 78 || c === 95 || c === 76 || c === 80;
1927
+ }
1928
+ function consumeLineBreak(state) {
1929
+ if (state.input.charCodeAt(state.position) === 10) state.position++;
1930
+ else {
1931
+ state.position++;
1932
+ if (state.input.charCodeAt(state.position) === 10) state.position++;
1933
+ }
1934
+ state.line++;
1935
+ state.lineStart = state.position;
1936
+ state.lineIndent = 0;
1937
+ state.firstTabInLine = -1;
1938
+ }
1939
+ function skipSeparationSpace(state, allowComments) {
1940
+ let lineBreaks = 0;
1941
+ let ch = state.input.charCodeAt(state.position);
1942
+ let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
1943
+ while (ch !== 0) {
1944
+ while (isWhiteSpace(ch)) {
1945
+ hasSeparation = true;
1946
+ if (ch === 9 && state.firstTabInLine === -1) state.firstTabInLine = state.position;
1947
+ ch = state.input.charCodeAt(++state.position);
1948
+ }
1949
+ if (allowComments && hasSeparation && ch === 35) do
1950
+ ch = state.input.charCodeAt(++state.position);
1951
+ while (!isEol(ch) && ch !== 0);
1952
+ if (!isEol(ch)) break;
1953
+ consumeLineBreak(state);
1954
+ lineBreaks++;
1955
+ hasSeparation = true;
1956
+ ch = state.input.charCodeAt(state.position);
1957
+ while (ch === 32) {
1958
+ state.lineIndent++;
1959
+ ch = state.input.charCodeAt(++state.position);
1960
+ }
1961
+ }
1962
+ return lineBreaks;
1963
+ }
1964
+ function testDocumentSeparator(state, position = state.position) {
1965
+ const ch = state.input.charCodeAt(position);
1966
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
1967
+ const following = state.input.charCodeAt(position + 3);
1968
+ return following === 0 || isWsOrEol(following);
1969
+ }
1970
+ return false;
1971
+ }
1972
+ function skipByteOrderMark(state) {
1973
+ if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
1974
+ state.position++;
1975
+ state.lineStart = state.position;
1976
+ }
1977
+ }
1978
+ function testDocumentBoundary(state) {
1979
+ if (state.position !== state.lineStart) return false;
1980
+ if (testDocumentSeparator(state)) return true;
1981
+ if (state.input.charCodeAt(state.position) !== 65279) return false;
1982
+ const snapshot = snapshotState(state);
1983
+ skipByteOrderMark(state);
1984
+ skipSeparationSpace(state, true);
1985
+ const ch = state.input.charCodeAt(state.position);
1986
+ const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
1987
+ restoreState(state, snapshot);
1988
+ return result;
1989
+ }
1990
+ function skipUntilLineEnd(state) {
1991
+ let ch = state.input.charCodeAt(state.position);
1992
+ while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
1993
+ }
1994
+ function checkPrintable(state, start, end) {
1995
+ const match = PATTERN_NON_PRINTABLE.exec(state.input.slice(start, end));
1996
+ if (match !== null) {
1997
+ state.position = start + match.index + match[0].length - 1;
1998
+ throwError(state, "the stream contains non-printable characters");
1999
+ }
2000
+ }
2001
+ function readTagProperty(state, props, inFlow) {
2002
+ if (state.input.charCodeAt(state.position) !== 33) return false;
2003
+ if (props.tagStart !== NO_RANGE$1) throwError(state, "duplication of a tag property");
2004
+ const start = state.position;
2005
+ let isVerbatim = false;
2006
+ let isNamed = false;
2007
+ let tagHandle = "!";
2008
+ let ch = state.input.charCodeAt(++state.position);
2009
+ if (ch === 60) {
2010
+ isVerbatim = true;
2011
+ ch = state.input.charCodeAt(++state.position);
2012
+ } else if (ch === 33) {
2013
+ isNamed = true;
2014
+ tagHandle = "!!";
2015
+ ch = state.input.charCodeAt(++state.position);
2016
+ }
2017
+ let suffixStart = state.position;
2018
+ let tagName;
2019
+ if (isVerbatim) {
2020
+ while (ch !== 0 && ch !== 62) ch = state.input.charCodeAt(++state.position);
2021
+ if (ch !== 62) throwError(state, "unexpected end of the stream within a verbatim tag");
2022
+ tagName = state.input.slice(suffixStart, state.position);
2023
+ state.position++;
2024
+ } else {
2025
+ while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
2026
+ if (ch === 33) {
2027
+ if (!isNamed) {
2028
+ tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
2029
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
2030
+ isNamed = true;
2031
+ suffixStart = state.position + 1;
2032
+ } else throwError(state, "tag suffix cannot contain exclamation marks");
2033
+ }
2034
+ ch = state.input.charCodeAt(++state.position);
2035
+ }
2036
+ tagName = state.input.slice(suffixStart, state.position);
2037
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) throwError(state, "tag suffix cannot contain flow indicator characters");
2038
+ }
2039
+ if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName))) throwError(state, `tag name cannot contain such characters: ${tagName}`);
2040
+ if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle)) throwError(state, `undeclared tag handle "${tagHandle}"`);
2041
+ props.tagStart = start;
2042
+ props.tagEnd = state.position;
2043
+ return true;
2044
+ }
2045
+ function readAnchorProperty(state, props) {
2046
+ if (state.input.charCodeAt(state.position) !== 38) return false;
2047
+ if (props.anchorStart !== NO_RANGE$1) throwError(state, "duplication of an anchor property");
2048
+ state.position++;
2049
+ const start = state.position;
2050
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
2051
+ if (state.position === start) throwError(state, "name of an anchor node must contain at least one character");
2052
+ props.anchorStart = start;
2053
+ props.anchorEnd = state.position;
2054
+ return true;
2055
+ }
2056
+ function readAlias(state, props) {
2057
+ if (state.input.charCodeAt(state.position) !== 42) return false;
2058
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) throwError(state, "alias node should not have any properties");
2059
+ state.position++;
2060
+ const start = state.position;
2061
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
2062
+ if (state.position === start) throwError(state, "name of an alias node must contain at least one character");
2063
+ addAliasEvent(state, start, state.position);
2064
+ return true;
2065
+ }
2066
+ function readFlowScalarBreak(state, nodeIndent) {
2067
+ skipSeparationSpace(state, false);
2068
+ if (state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
2069
+ }
2070
+ function readSingleQuotedScalar(state, nodeIndent, props) {
2071
+ if (state.input.charCodeAt(state.position) !== 39) return false;
2072
+ state.position++;
2073
+ const start = state.position;
2074
+ let simple = true;
2075
+ while (state.input.charCodeAt(state.position) !== 0) {
2076
+ const ch = state.input.charCodeAt(state.position);
2077
+ if (ch === 39) {
2078
+ if (state.input.charCodeAt(state.position + 1) === 39) {
2079
+ simple = false;
2080
+ state.position += 2;
2081
+ continue;
2082
+ }
2083
+ const end = state.position;
2084
+ state.position++;
2085
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
2086
+ return true;
2087
+ }
2088
+ if (isEol(ch)) {
2089
+ simple = false;
2090
+ readFlowScalarBreak(state, nodeIndent);
2091
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a single quoted scalar");
2092
+ else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
2093
+ else state.position++;
2094
+ }
2095
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
2096
+ }
2097
+ function readDoubleQuotedScalar(state, nodeIndent, props) {
2098
+ if (state.input.charCodeAt(state.position) !== 34) return false;
2099
+ state.position++;
2100
+ const start = state.position;
2101
+ let simple = true;
2102
+ while (state.input.charCodeAt(state.position) !== 0) {
2103
+ const ch = state.input.charCodeAt(state.position);
2104
+ if (ch === 34) {
2105
+ const end = state.position;
2106
+ state.position++;
2107
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
2108
+ return true;
2109
+ }
2110
+ if (ch === 92) {
2111
+ simple = false;
2112
+ const escaped = state.input.charCodeAt(++state.position);
2113
+ if (isEol(escaped)) readFlowScalarBreak(state, nodeIndent);
2114
+ else if (isSimpleEscape(escaped)) state.position++;
2115
+ else {
2116
+ let hexLength = escapedHexLen(escaped);
2117
+ if (hexLength === 0) throwError(state, "unknown escape sequence");
2118
+ while (hexLength-- > 0) {
2119
+ state.position++;
2120
+ if (fromHexCode(state.input.charCodeAt(state.position)) < 0) throwError(state, "expected hexadecimal character");
2121
+ }
2122
+ state.position++;
2123
+ }
2124
+ } else if (isEol(ch)) {
2125
+ simple = false;
2126
+ readFlowScalarBreak(state, nodeIndent);
2127
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a double quoted scalar");
2128
+ else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
2129
+ else state.position++;
2130
+ }
2131
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
2132
+ }
2133
+ function readBlockScalar(state, parentIndent, props) {
2134
+ const ch = state.input.charCodeAt(state.position);
2135
+ let chomping = CHOMPING_MODE.CLIP;
2136
+ let indent = -1;
2137
+ let detectedIndent = false;
2138
+ if (ch !== 124 && ch !== 62) return false;
2139
+ const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
2140
+ state.position++;
2141
+ while (state.input.charCodeAt(state.position) !== 0) {
2142
+ const current = state.input.charCodeAt(state.position);
2143
+ const digit = fromDecimalCode(current);
2144
+ if (current === 43 || current === 45) {
2145
+ if (chomping !== CHOMPING_MODE.CLIP) throwError(state, "repeat of a chomping mode identifier");
2146
+ chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
2147
+ state.position++;
2148
+ } else if (digit >= 0) {
2149
+ if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
2150
+ if (detectedIndent) throwError(state, "repeat of an indentation width identifier");
2151
+ indent = parentIndent + digit - 1;
2152
+ detectedIndent = true;
2153
+ state.position++;
2154
+ } else break;
2155
+ }
2156
+ let hadWhitespace = false;
2157
+ while (isWhiteSpace(state.input.charCodeAt(state.position))) {
2158
+ hadWhitespace = true;
2159
+ state.position++;
2160
+ }
2161
+ if (hadWhitespace && state.input.charCodeAt(state.position) === 35) skipUntilLineEnd(state);
2162
+ if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
2163
+ else if (state.input.charCodeAt(state.position) !== 0) throwError(state, "a line break is expected");
2164
+ let contentIndent = detectedIndent ? indent : -1;
2165
+ let maxLeadingIndent = 0;
2166
+ const valueStart = state.position;
2167
+ let valueEnd = state.position;
2168
+ while (state.input.charCodeAt(state.position) !== 0) {
2169
+ const linePosition = state.position;
2170
+ let column = 0;
2171
+ while (state.input.charCodeAt(linePosition + column) === 32) column++;
2172
+ const first = state.input.charCodeAt(linePosition + column);
2173
+ if (first === 0) {
2174
+ if (contentIndent >= 0) {
2175
+ if (column > contentIndent) valueEnd = linePosition + column;
2176
+ } else if (column > 0) valueEnd = linePosition + column;
2177
+ break;
2178
+ }
2179
+ if (testDocumentBoundary(state)) break;
2180
+ if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
2181
+ if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
2182
+ if (first === 9 && column < parentIndent) {
2183
+ state.position = linePosition + column;
2184
+ throwError(state, "tab characters must not be used in indentation");
2185
+ }
2186
+ if (column >= parentIndent && column < maxLeadingIndent) {
2187
+ state.position = linePosition + column;
2188
+ throwError(state, "bad indentation of a mapping entry");
2189
+ }
2190
+ }
2191
+ if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
2192
+ state.lineIndent = column;
2193
+ state.position = linePosition + column;
2194
+ break;
2195
+ }
2196
+ if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1) contentIndent = column;
2197
+ const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
2198
+ if (first !== 0 && !isEol(first) && column < requiredIndent) {
2199
+ state.lineIndent = column;
2200
+ state.position = linePosition + column;
2201
+ break;
2202
+ }
2203
+ skipUntilLineEnd(state);
2204
+ valueEnd = state.position;
2205
+ if (isEol(state.input.charCodeAt(state.position))) {
2206
+ consumeLineBreak(state);
2207
+ valueEnd = state.position;
2208
+ }
2209
+ }
2210
+ checkPrintable(state, valueStart, valueEnd);
2211
+ addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
2212
+ return true;
2213
+ }
2214
+ function canStartPlainScalar(state, nodeContext) {
2215
+ const ch = state.input.charCodeAt(state.position);
2216
+ const inFlow = nodeContext === CONTEXT_FLOW_IN;
2217
+ if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || isFlowIndicator(ch)) return false;
2218
+ if (ch === 63 || ch === 45) {
2219
+ const following = state.input.charCodeAt(state.position + 1);
2220
+ if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
2221
+ }
2222
+ return true;
2223
+ }
2224
+ function readPlainScalar(state, nodeIndent, nodeContext, props) {
2225
+ if (!canStartPlainScalar(state, nodeContext)) return false;
2226
+ const start = state.position;
2227
+ let end = state.position;
2228
+ let ch = state.input.charCodeAt(state.position);
2229
+ const inFlow = nodeContext === CONTEXT_FLOW_IN;
2230
+ let multiline = false;
2231
+ while (ch !== 0) {
2232
+ if (testDocumentBoundary(state)) break;
2233
+ if (ch === 58) {
2234
+ const following = state.input.charCodeAt(state.position + 1);
2235
+ if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
2236
+ } else if (ch === 35) {
2237
+ if (isWsOrEol(state.input.charCodeAt(state.position - 1))) break;
2238
+ } else if (inFlow && isFlowIndicator(ch)) break;
2239
+ else if (isEol(ch)) {
2240
+ const savedPosition = state.position;
2241
+ const savedLine = state.line;
2242
+ const savedLineStart = state.lineStart;
2243
+ const savedLineIndent = state.lineIndent;
2244
+ skipSeparationSpace(state, false);
2245
+ if (state.lineIndent >= nodeIndent) {
2246
+ multiline = true;
2247
+ ch = state.input.charCodeAt(state.position);
2248
+ continue;
2249
+ }
2250
+ state.position = savedPosition;
2251
+ state.line = savedLine;
2252
+ state.lineStart = savedLineStart;
2253
+ state.lineIndent = savedLineIndent;
2254
+ break;
2255
+ }
2256
+ if (!isWhiteSpace(ch)) end = state.position + 1;
2257
+ ch = state.input.charCodeAt(++state.position);
2258
+ }
2259
+ if (end === start) return false;
2260
+ checkPrintable(state, start, end);
2261
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
2262
+ return true;
2263
+ }
2264
+ function skipFlowSeparationSpace(state, nodeIndent) {
2265
+ const startLine = state.line;
2266
+ skipSeparationSpace(state, true);
2267
+ if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
2268
+ }
2269
+ function readFlowCollection(state, nodeIndent, props) {
2270
+ const ch = state.input.charCodeAt(state.position);
2271
+ const isMapping = ch === 123;
2272
+ const start = state.position;
2273
+ let readNext = true;
2274
+ if (ch !== 91 && ch !== 123) return false;
2275
+ const terminator = isMapping ? 125 : 93;
2276
+ if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
2277
+ else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
2278
+ state.position++;
2279
+ while (state.input.charCodeAt(state.position) !== 0) {
2280
+ skipFlowSeparationSpace(state, nodeIndent);
2281
+ let ch = state.input.charCodeAt(state.position);
2282
+ if (ch === terminator) {
2283
+ state.position++;
2284
+ addPopEvent(state);
2285
+ return true;
2286
+ } else if (!readNext) throwError(state, "missed comma between flow collection entries");
2287
+ else if (ch === 44) throwError(state, "expected the node content, but found ','");
2288
+ let isPair = false;
2289
+ let isExplicitPair = false;
2290
+ if (ch === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
2291
+ isPair = isExplicitPair = true;
2292
+ state.position += 1;
2293
+ skipFlowSeparationSpace(state, nodeIndent);
2294
+ }
2295
+ const entryLine = state.line;
2296
+ const entryStart = snapshotState(state);
2297
+ const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2298
+ skipFlowSeparationSpace(state, nodeIndent);
2299
+ ch = state.input.charCodeAt(state.position);
2300
+ if ((isMapping || isExplicitPair || state.line === entryLine) && ch === 58) {
2301
+ isPair = true;
2302
+ state.position++;
2303
+ skipFlowSeparationSpace(state, nodeIndent);
2304
+ if (!isMapping) {
2305
+ insertFlowPairMappingEvent(state, entryStart);
2306
+ if (!keyWasRead) addEmptyScalarEvent(state);
2307
+ } else if (!keyWasRead) addEmptyScalarEvent(state);
2308
+ if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
2309
+ skipFlowSeparationSpace(state, nodeIndent);
2310
+ if (!isMapping) addPopEvent(state);
2311
+ } else if (isMapping && isPair) {
2312
+ if (!keyWasRead) addEmptyScalarEvent(state);
2313
+ addEmptyScalarEvent(state);
2314
+ } else if (isMapping) addEmptyScalarEvent(state);
2315
+ else if (isPair) {
2316
+ insertFlowPairMappingEvent(state, entryStart);
2317
+ if (!keyWasRead) addEmptyScalarEvent(state);
2318
+ addEmptyScalarEvent(state);
2319
+ addPopEvent(state);
2320
+ }
2321
+ ch = state.input.charCodeAt(state.position);
2322
+ if (ch === 44) {
2323
+ readNext = true;
2324
+ state.position++;
2325
+ } else readNext = false;
2326
+ }
2327
+ throwError(state, "unexpected end of the stream within a flow collection");
2328
+ }
2329
+ function readBlockSequence(state, nodeIndent, props) {
2330
+ if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
2331
+ addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
2332
+ while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
2333
+ if (state.firstTabInLine !== -1) {
2334
+ state.position = state.firstTabInLine;
2335
+ throwError(state, "tab characters must not be used in indentation");
2336
+ }
2337
+ const entryLine = state.line;
2338
+ state.position++;
2339
+ const hadBreak = skipSeparationSpace(state, true) > 0;
2340
+ if (state.firstTabInLine !== -1 && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
2341
+ if (hadBreak && state.lineIndent <= nodeIndent) addEmptyScalarEvent(state);
2342
+ else parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2343
+ skipSeparationSpace(state, true);
2344
+ if (state.lineIndent < nodeIndent || state.position >= state.length) break;
2345
+ if (state.lineIndent > nodeIndent) throwError(state, "bad indentation of a sequence entry");
2346
+ if (state.line === entryLine && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
2347
+ }
2348
+ addPopEvent(state);
2349
+ return true;
2350
+ }
2351
+ function readBlockMapping(state, nodeIndent, flowIndent, props) {
2352
+ let atExplicitKey = false;
2353
+ let detected = false;
2354
+ let mappingOpened = false;
2355
+ let pendingExplicitKey = false;
2356
+ if (state.firstTabInLine !== -1) return false;
2357
+ let ch = state.input.charCodeAt(state.position);
2358
+ while (ch !== 0) {
2359
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
2360
+ state.position = state.firstTabInLine;
2361
+ throwError(state, "tab characters must not be used in indentation");
2362
+ }
2363
+ const following = state.input.charCodeAt(state.position + 1);
2364
+ const entryLine = state.line;
2365
+ if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
2366
+ if (!mappingOpened) {
2367
+ addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
2368
+ mappingOpened = true;
2369
+ }
2370
+ if (ch === 63) {
2371
+ if (atExplicitKey) addEmptyScalarEvent(state);
2372
+ detected = true;
2373
+ atExplicitKey = true;
2374
+ } else if (atExplicitKey) atExplicitKey = false;
2375
+ else {
2376
+ addEmptyScalarEvent(state);
2377
+ detected = true;
2378
+ atExplicitKey = false;
2379
+ }
2380
+ state.position += 1;
2381
+ pendingExplicitKey = true;
2382
+ } else {
2383
+ if (atExplicitKey) {
2384
+ addEmptyScalarEvent(state);
2385
+ atExplicitKey = false;
2386
+ }
2387
+ const beforeKey = snapshotState(state);
2388
+ if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) break;
2389
+ if (state.line === entryLine) {
2390
+ ch = state.input.charCodeAt(state.position);
2391
+ while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
2392
+ if (ch === 58) {
2393
+ ch = state.input.charCodeAt(++state.position);
2394
+ if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
2395
+ if (!mappingOpened) {
2396
+ state.events.splice(beforeKey.eventsLength, 0, {
2397
+ type: EVENT_ID.MAPPING,
2398
+ start: beforeKey.position,
2399
+ anchorStart: props.anchorStart,
2400
+ anchorEnd: props.anchorEnd,
2401
+ tagStart: props.tagStart,
2402
+ tagEnd: props.tagEnd,
2403
+ style: COLLECTION_STYLE.BLOCK
2404
+ });
2405
+ mappingOpened = true;
2406
+ }
2407
+ detected = true;
2408
+ atExplicitKey = false;
2409
+ pendingExplicitKey = false;
2410
+ } else if (detected) throwError(state, "expected ':' after a mapping key");
2411
+ else {
2412
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
2413
+ restoreState(state, beforeKey);
2414
+ return false;
2415
+ }
2416
+ return true;
2417
+ }
2418
+ } else if (detected) throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
2419
+ else {
2420
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
2421
+ restoreState(state, beforeKey);
2422
+ return false;
2423
+ }
2424
+ return true;
2425
+ }
2426
+ }
2427
+ if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey)) pendingExplicitKey = false;
2428
+ if (!atExplicitKey) {
2429
+ if (pendingExplicitKey) {
2430
+ addEmptyScalarEvent(state);
2431
+ pendingExplicitKey = false;
2432
+ }
2433
+ }
2434
+ skipSeparationSpace(state, true);
2435
+ ch = state.input.charCodeAt(state.position);
2436
+ if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0) throwError(state, "bad indentation of a mapping entry");
2437
+ else if (state.lineIndent < nodeIndent) break;
2438
+ }
2439
+ if (!detected) return false;
2440
+ if (atExplicitKey) addEmptyScalarEvent(state);
2441
+ if (mappingOpened) addPopEvent(state);
2442
+ return true;
2443
+ }
2444
+ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
2445
+ if (state.depth >= state.maxDepth) throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
2446
+ state.depth++;
2447
+ let indentStatus = 1;
2448
+ let atNewLine = false;
2449
+ let hasContent = false;
2450
+ let propertyStart = null;
2451
+ const props = emptyProperties();
2452
+ let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
2453
+ let allowBlockCollections = allowBlockScalars;
2454
+ const allowBlockStyles = allowBlockScalars;
2455
+ if (allowToSeek && skipSeparationSpace(state, true)) {
2456
+ atNewLine = true;
2457
+ if (state.lineIndent > parentIndent) indentStatus = 1;
2458
+ else if (state.lineIndent === parentIndent) indentStatus = 0;
2459
+ else indentStatus = -1;
2460
+ }
2461
+ if (indentStatus === 1) while (true) {
2462
+ const ch = state.input.charCodeAt(state.position);
2463
+ const propertyState = snapshotState(state);
2464
+ if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38)) break;
2465
+ if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
2466
+ const fallbackState = snapshotState(state);
2467
+ const flowIndent = parentIndent + 1;
2468
+ if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) {
2469
+ state.depth--;
2470
+ return true;
2471
+ }
2472
+ restoreState(state, fallbackState);
2473
+ }
2474
+ if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1)) break;
2475
+ if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props)) break;
2476
+ if (propertyStart === null) propertyStart = propertyState;
2477
+ if (skipSeparationSpace(state, true)) {
2478
+ atNewLine = true;
2479
+ allowBlockCollections = allowBlockStyles;
2480
+ if (state.lineIndent > parentIndent) indentStatus = 1;
2481
+ else if (state.lineIndent === parentIndent) indentStatus = 0;
2482
+ else indentStatus = -1;
2483
+ } else allowBlockCollections = false;
2484
+ }
2485
+ if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
2486
+ if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
2487
+ const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
2488
+ const blockIndent = state.position - state.lineStart;
2489
+ if (indentStatus === 1) {
2490
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
2491
+ else {
2492
+ const ch = state.input.charCodeAt(state.position);
2493
+ if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
2494
+ const fallbackState = snapshotState(state);
2495
+ const propertyIndent = propertyStart.position - propertyStart.lineStart;
2496
+ restoreState(state, propertyStart);
2497
+ if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
2498
+ else restoreState(state, fallbackState);
2499
+ }
2500
+ if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
2501
+ }
2502
+ } else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
2503
+ }
2504
+ allowBlockScalars = allowBlockScalars && !hasContent;
2505
+ if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
2506
+ addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
2507
+ hasContent = true;
2508
+ }
2509
+ state.depth--;
2510
+ return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
2511
+ }
2512
+ function readDirective(state) {
2513
+ if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37) return false;
2514
+ state.position++;
2515
+ const nameStart = state.position;
2516
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2517
+ const name = state.input.slice(nameStart, state.position);
2518
+ const args = [];
2519
+ if (name.length === 0) throwError(state, "directive name must not be less than one character in length");
2520
+ while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
2521
+ while (isWhiteSpace(state.input.charCodeAt(state.position))) state.position++;
2522
+ if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0) break;
2523
+ const start = state.position;
2524
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2525
+ args.push(state.input.slice(start, state.position));
2526
+ }
2527
+ if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
2528
+ if (name === "YAML") {
2529
+ if (state.directives.some((directive) => directive.kind === "yaml")) throwError(state, "duplication of %YAML directive");
2530
+ if (args.length !== 1) throwError(state, "YAML directive accepts exactly one argument");
2531
+ const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
2532
+ if (match === null) throwError(state, "ill-formed argument of the YAML directive");
2533
+ if (parseInt(match[1], 10) !== 1) throwError(state, "unacceptable YAML version of the document");
2534
+ state.directives.push({
2535
+ kind: "yaml",
2536
+ version: args[0]
2537
+ });
2538
+ } else if (name === "TAG") {
2539
+ if (args.length !== 2) throwError(state, "TAG directive accepts exactly two arguments");
2540
+ const [handle, prefix] = args;
2541
+ if (!PATTERN_TAG_HANDLE.test(handle)) throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
2542
+ if (HAS_OWN.call(state.tagHandlers, handle)) throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
2543
+ if (!PATTERN_TAG_PREFIX.test(prefix)) throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
2544
+ state.tagHandlers[handle] = prefix;
2545
+ state.directives.push({
2546
+ kind: "tag",
2547
+ handle,
2548
+ prefix
2549
+ });
2550
+ }
2551
+ return true;
2552
+ }
2553
+ function readDocument(state) {
2554
+ state.directives = [];
2555
+ state.tagHandlers = Object.create(null);
2556
+ let hasDirectives = false;
2557
+ skipSeparationSpace(state, true);
2558
+ while (readDirective(state)) {
2559
+ hasDirectives = true;
2560
+ skipSeparationSpace(state, true);
2561
+ }
2562
+ let explicitStart = false;
2563
+ let explicitEnd = false;
2564
+ let allowCompact = true;
2565
+ if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 3))) {
2566
+ explicitStart = true;
2567
+ const markerLine = state.line;
2568
+ state.position += 3;
2569
+ skipSeparationSpace(state, true);
2570
+ allowCompact = state.line > markerLine;
2571
+ } else if (hasDirectives) throwError(state, "directives end mark is expected");
2572
+ const documentEventIndex = state.events.length;
2573
+ if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
2574
+ state.position += 3;
2575
+ skipSeparationSpace(state, true);
2576
+ return;
2577
+ }
2578
+ addDocumentEvent(state, explicitStart, false);
2579
+ if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact)) addEmptyScalarEvent(state);
2580
+ skipSeparationSpace(state, true);
2581
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
2582
+ explicitEnd = state.input.charCodeAt(state.position) === 46;
2583
+ if (explicitEnd) {
2584
+ const markerLine = state.line;
2585
+ state.position += 3;
2586
+ skipSeparationSpace(state, true);
2587
+ if (state.line === markerLine && state.position < state.length) throwError(state, "end of the stream or a document separator is expected");
2588
+ }
2589
+ }
2590
+ const documentEvent = state.events[documentEventIndex];
2591
+ if (documentEvent?.type === EVENT_ID.DOCUMENT) documentEvent.explicitEnd = explicitEnd;
2592
+ addPopEvent(state);
2593
+ if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state)) throwError(state, "end of the stream or a document separator is expected");
2594
+ }
2595
+ /**
2596
+ * Parses YAML into a flat event stream referencing source text by offsets.
2597
+ *
2598
+ * @category Events
2599
+ */
2600
+ function parseEvents(input, options) {
2601
+ const length = input.length;
2602
+ const state = {
2603
+ ...DEFAULT_PARSER_OPTIONS,
2604
+ ...options,
2605
+ input: `${input}\0`,
2606
+ length,
2607
+ position: 0,
2608
+ line: 0,
2609
+ lineStart: 0,
2610
+ lineIndent: 0,
2611
+ firstTabInLine: -1,
2612
+ depth: 0,
2613
+ directives: [],
2614
+ tagHandlers: Object.create(null),
2615
+ events: []
2616
+ };
2617
+ const nullpos = input.indexOf("\0");
2618
+ if (nullpos !== -1) YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
2619
+ while (state.position < state.length) {
2620
+ skipByteOrderMark(state);
2621
+ skipSeparationSpace(state, true);
2622
+ if (state.position >= state.length) break;
2623
+ const documentStart = state.position;
2624
+ readDocument(state);
2625
+ if (state.position === documentStart)
2626
+ /* c8 ignore next */
2627
+ throwError(state, "can not read a document");
2628
+ }
2629
+ return state.events;
2630
+ }
2631
+ //#endregion
2632
+ //#region src/load.ts
2633
+ var DEFAULT_LOAD_OPTIONS = {
2634
+ ...DEFAULT_PARSER_OPTIONS,
2635
+ ...DEFAULT_CONSTRUCTOR_OPTIONS
2636
+ };
2637
+ function loadDocuments(input, options = {}) {
2638
+ const opts = {
2639
+ ...DEFAULT_LOAD_OPTIONS,
2640
+ ...options
2641
+ };
2642
+ const source = String(input);
2643
+ const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
2644
+ const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
2645
+ return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
2646
+ ...pick(opts, CONSTRUCTOR_OPT_KEYS),
2647
+ source
2648
+ });
2649
+ }
2650
+ function loadAll(input, iteratorOrOptions, options) {
2651
+ let iterator = null;
2652
+ if (typeof iteratorOrOptions === "function") iterator = iteratorOrOptions;
2653
+ else if (iteratorOrOptions !== null && typeof iteratorOrOptions === "object") options = iteratorOrOptions;
2654
+ const documents = loadDocuments(input, options);
2655
+ if (iterator === null) return documents;
2656
+ for (const document of documents) iterator(document);
2657
+ }
2658
+ /**
2659
+ * Parses `string` as a single YAML document. Throws {@link YAMLException} on
2660
+ * error. This function does not understand multi-document or empty sources; it
2661
+ * throws an exception on those.
2662
+ *
2663
+ * > [!NOTE]
2664
+ * > 1. When processing untrusted input, see the
2665
+ * > [security considerations](../docs/safety.md).
2666
+ * > 2. All exceptions MUST be caught, not just {@link YAMLException}.
2667
+ * > 3. The default {@link CORE_SCHEMA} comes without the `!!merge` tag. You can
2668
+ * > easily enable it if needed.
2669
+ * > 4. The default {@link mapTag} is `{}`-object based, with known limitations
2670
+ * > (see description). For full compatibility use {@link realMapTag}
2671
+ * > instead (it uses native JS `Map`).
2672
+ *
2673
+ * @example
2674
+ * Enable {@link mergeTag} and {@link realMapTag}:
2675
+ *
2676
+ * ```javascript
2677
+ * import { load, CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
2678
+ *
2679
+ * try {
2680
+ * load(data, { schema: CORE_SCHEMA.withTags(mergeTag, realMapTag) })
2681
+ * } catch (e) {
2682
+ * console.error(e)
2683
+ * }
2684
+ * ```
2685
+ *
2686
+ * @category Main
2687
+ */
2688
+ function load(input, options) {
2689
+ const documents = loadDocuments(input, options);
2690
+ if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
2691
+ if (documents.length === 1) return documents[0];
2692
+ throw new YAMLException("expected a single document in the stream, but found more");
2693
+ }
2694
+ //#endregion
2695
+ //#region src/ast/from_js.ts
2696
+ var INVALID = Symbol("INVALID");
2697
+ function buildRepresentTypes(schema) {
2698
+ const defaultTags = new Set([
2699
+ schema.defaultScalarTag,
2700
+ schema.defaultSequenceTag,
2701
+ schema.defaultMappingTag
2702
+ ].filter((t) => t !== void 0));
2703
+ const implicitScalars = schema.implicitScalarTags;
2704
+ const explicitTags = schema.tags.filter((t) => !(t.nodeKind === "scalar" && t.implicit) && !defaultTags.has(t));
2705
+ const defaultTagsLast = schema.tags.filter((t) => defaultTags.has(t));
2706
+ return [
2707
+ ...implicitScalars.map((tag) => ({
2708
+ tag,
2709
+ implicitTag: true
2710
+ })),
2711
+ ...explicitTags.map((tag) => ({
2712
+ tag,
2713
+ implicitTag: false
2714
+ })),
2715
+ ...defaultTagsLast.map((tag) => ({
2716
+ tag,
2717
+ implicitTag: true
2718
+ }))
2719
+ ];
2720
+ }
2721
+ function matchTag(state, object) {
2722
+ for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
2723
+ const { tag, implicitTag } = state.representTypes[index];
2724
+ if (tag.identify(object)) {
2725
+ let tagName;
2726
+ if (tag.matchByTagPrefix) tagName = tag.representTagName(object);
2727
+ else tagName = tag.tagName;
2728
+ return {
2729
+ tag,
2730
+ tagName,
2731
+ implicitTag
2732
+ };
2733
+ }
2734
+ }
2735
+ return null;
2736
+ }
2737
+ function build(state, object) {
2738
+ if (!state.noRefs && object !== null && typeof object === "object") {
2739
+ const existing = state.refs.get(object);
2740
+ if (existing) {
2741
+ if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
2742
+ return {
2743
+ kind: "alias",
2744
+ anchor: existing.anchor
2745
+ };
2746
+ }
2747
+ }
2748
+ const matched = matchTag(state, object);
2749
+ if (!matched) {
2750
+ if (object === void 0) return INVALID;
2751
+ if (state.skipInvalid) return INVALID;
2752
+ throw new YAMLException(`unacceptable kind of an object to dump ${Object.prototype.toString.call(object)}`);
2753
+ }
2754
+ const { tag, tagName, implicitTag } = matched;
2755
+ const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
2756
+ if (tag.nodeKind === "scalar") return {
2757
+ kind: "scalar",
2758
+ tag: nodeTagName,
2759
+ tagged: !implicitTag,
2760
+ style: SCALAR_STYLE.PLAIN,
2761
+ value: tag.represent(object)
2762
+ };
2763
+ if (tag.nodeKind === "sequence") {
2764
+ const container = tag.represent(object);
2765
+ const node = {
2766
+ kind: "sequence",
2767
+ tag: nodeTagName,
2768
+ tagged: !implicitTag,
2769
+ style: COLLECTION_STYLE.BLOCK,
2770
+ items: []
2771
+ };
2772
+ if (!state.noRefs) state.refs.set(object, node);
2773
+ for (let index = 0, length = container.length; index < length; index += 1) {
2774
+ let item = build(state, container[index]);
2775
+ if (item === INVALID && container[index] === void 0) item = build(state, null);
2776
+ if (item === INVALID) continue;
2777
+ node.items.push(item);
2778
+ }
2779
+ return node;
2780
+ }
2781
+ const map = tag.represent(object);
2782
+ const node = {
2783
+ kind: "mapping",
2784
+ tag: nodeTagName,
2785
+ tagged: !implicitTag,
2786
+ style: COLLECTION_STYLE.BLOCK,
2787
+ items: []
2788
+ };
2789
+ if (!state.noRefs) state.refs.set(object, node);
2790
+ for (const [objectKey, objectValue] of map) {
2791
+ const key = build(state, objectKey);
2792
+ if (key === INVALID) continue;
2793
+ const value = build(state, objectValue);
2794
+ if (value === INVALID) continue;
2795
+ node.items.push({
2796
+ key,
2797
+ value
2798
+ });
2799
+ }
2800
+ return node;
2801
+ }
2802
+ /**
2803
+ * Convert JS object to AST. A JS value is one YAML document. An unrepresentable
2804
+ * root becomes an empty document, which the presenter renders as an empty
2805
+ * string.
2806
+ *
2807
+ * @category AST
2808
+ */
2809
+ function jsToAst(input, schema, options = {}) {
2810
+ const root = build({
2811
+ representTypes: buildRepresentTypes(schema),
2812
+ noRefs: options.noRefs ?? false,
2813
+ skipInvalid: options.skipInvalid ?? false,
2814
+ refs: /* @__PURE__ */ new Map(),
2815
+ refCounter: 0
2816
+ }, input);
2817
+ return [{
2818
+ contents: root === INVALID ? null : root,
2819
+ directives: []
2820
+ }];
2821
+ }
2822
+ //#endregion
2823
+ //#region src/ast/visit.ts
2824
+ /**
2825
+ * Return from a visitor to stop the whole traversal.
2826
+ *
2827
+ * @category AST
2828
+ */
2829
+ var VISIT_BREAK = Symbol("visit:break");
2830
+ /**
2831
+ * Return from a visitor to skip the current node's children.
2832
+ *
2833
+ * @category AST
2834
+ */
2835
+ var VISIT_SKIP = Symbol("visit:skip");
2836
+ function visitNode(node, visitor, ctx) {
2837
+ const control = visitor(node, ctx);
2838
+ if (control === VISIT_BREAK) return true;
2839
+ if (control === VISIT_SKIP) return false;
2840
+ const depth = ctx.depth + 1;
2841
+ switch (node.kind) {
2842
+ case "sequence":
2843
+ for (const item of node.items) if (visitNode(item, visitor, {
2844
+ depth,
2845
+ parent: node,
2846
+ isKey: false
2847
+ })) return true;
2848
+ break;
2849
+ case "mapping": for (const { key, value } of node.items) {
2850
+ if (visitNode(key, visitor, {
2851
+ depth,
2852
+ parent: node,
2853
+ isKey: true
2854
+ })) return true;
2855
+ if (visitNode(value, visitor, {
2856
+ depth,
2857
+ parent: node,
2858
+ isKey: false
2859
+ })) return true;
2860
+ }
2861
+ }
2862
+ return false;
2863
+ }
2864
+ /**
2865
+ * Walk every node in the documents, calling {@link Visitor} once per
2866
+ * node (pre-order).
2867
+ *
2868
+ * @category AST
2869
+ */
2870
+ function visit(documents, visitor) {
2871
+ for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
2872
+ depth: 0,
2873
+ parent: null,
2874
+ isKey: false
2875
+ })) return;
2876
+ }
2877
+ //#endregion
2878
+ //#region src/ast/styler_defaults.ts
2879
+ function hasBit(mask, bit) {
2880
+ return (mask & 1 << bit) !== 0;
2881
+ }
2882
+ /**
2883
+ * Default scalar styling rules in application order.
2884
+ * See [Scalar styling](../../docs/scalar_styling.md) for usage details.
2885
+ *
2886
+ * @category AST
2887
+ */
2888
+ var DEFAULT_SCALAR_STYLE_RULES = {
2889
+ applyQuoteFlowKeysOption,
2890
+ doubleQuoteForInvisibles,
2891
+ doubleQuoteWhitespaceOnly,
2892
+ applyForceQuotesOption,
2893
+ tryLongOrMultilineAsBlock,
2894
+ quoteInvalidPlain,
2895
+ fallbackToDoubleQuoted
2896
+ };
2897
+ function _preferredQuotedStyle(layout) {
2898
+ if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED)) return SCALAR_STYLE.SINGLE_QUOTED;
2899
+ return SCALAR_STYLE.DOUBLE_QUOTED;
2900
+ }
2901
+ function applyQuoteFlowKeysOption(layout) {
2902
+ if (!layout.presenterOptions.quoteFlowKeys) return;
2903
+ if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN) return;
2904
+ layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2905
+ }
2906
+ function doubleQuoteForInvisibles(layout) {
2907
+ if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2908
+ }
2909
+ function doubleQuoteWhitespaceOnly(layout) {
2910
+ if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2911
+ }
2912
+ function applyForceQuotesOption(layout) {
2913
+ if (!layout.presenterOptions.forceQuotes) return;
2914
+ if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return;
2915
+ if (layout.node.tag !== layout.presenterOptions.schema.defaultScalarTag.tagName) return;
2916
+ layout.style = layout.node.value.includes("\n") ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
2917
+ }
2918
+ function tryLongOrMultilineAsBlock(layout) {
2919
+ if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey) return;
2920
+ const value = layout.node.value;
2921
+ const multiline = value.indexOf("\n") !== -1;
2922
+ if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
2923
+ if (multiline) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2924
+ return;
2925
+ }
2926
+ const w = layout.presenterOptions.lineWidth;
2927
+ if (w === -1) {
2928
+ if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
2929
+ return;
2930
+ }
2931
+ const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
2932
+ let position = 0;
2933
+ let shouldFold = false;
2934
+ while (position <= value.length) {
2935
+ let lineEnd = value.length;
2936
+ const nextLineBreak = value.indexOf("\n", position);
2937
+ if (nextLineBreak !== -1) lineEnd = nextLineBreak;
2938
+ const line = value.slice(position, lineEnd);
2939
+ if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line)) shouldFold = true;
2940
+ if (nextLineBreak === -1) break;
2941
+ position = nextLineBreak + 1;
2942
+ }
2943
+ if (shouldFold) layout.style = SCALAR_STYLE.FOLDED_BLOCK;
2944
+ else if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
2945
+ }
2946
+ function quoteInvalidPlain(layout) {
2947
+ if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN)) layout.style = _preferredQuotedStyle(layout);
2948
+ }
2949
+ function fallbackToDoubleQuoted(layout) {
2950
+ if (!hasBit(layout.allowedStylesMask, layout.style)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2951
+ }
2952
+ //#endregion
2953
+ //#region src/ast/scalar_styler.ts
2954
+ function setBit(mask, bit) {
2955
+ return mask | 1 << bit;
2956
+ }
2957
+ var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
2958
+ var SRC_B_CHAR = "[\\n\\r]";
2959
+ var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
2960
+ var SRC_S_WHITE = "[ \\t]";
2961
+ var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
2962
+ var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
2963
+ var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
2964
+ var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
2965
+ var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
2966
+ var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
2967
+ var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
2968
+ var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
2969
+ var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
2970
+ var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
2971
+ var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
2972
+ var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
2973
+ var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
2974
+ var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
2975
+ var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
2976
+ var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
2977
+ var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
2978
+ var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
2979
+ var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
2980
+ var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
2981
+ var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
2982
+ var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
2983
+ var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
2984
+ var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
2985
+ var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
2986
+ var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
2987
+ var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
2988
+ var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
2989
+ var C_FORBIDDEN_FIRST_LINE = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/;
2990
+ var C_FORBIDDEN_CONTENT = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/m;
2991
+ function canUsePlain(layout) {
2992
+ const str = layout.node.value;
2993
+ if (str !== "") {
2994
+ if (!(layout.isKey ? layout.flowOnly ? NS_PLAIN_FLOW_KEY : NS_PLAIN_BLOCK_KEY : layout.flowOnly ? NS_PLAIN_FLOW_IN : NS_PLAIN_FLOW_OUT).test(str)) return false;
2995
+ if (layout.shiftOfFirstLine === 0 && C_FORBIDDEN_FIRST_LINE.test(str)) return false;
2996
+ if (layout.shiftOfContent === 0) {
2997
+ const firstLineBreak = str.indexOf("\n");
2998
+ if (firstLineBreak !== -1) {
2999
+ const content = str.slice(firstLineBreak + 1);
3000
+ if (C_FORBIDDEN_CONTENT.test(content)) return false;
3001
+ }
3002
+ }
3003
+ }
3004
+ const resolvedTag = layout.presenterOptions.schema.resolveImplicitScalarTag(str).tag.tagName;
3005
+ if (!layout.node.tagged && resolvedTag !== layout.node.tag) return false;
3006
+ if (!layout.node.tagged && str === "=" && resolvedTag === layout.presenterOptions.schema.defaultScalarTag.tagName) return false;
3007
+ return true;
3008
+ }
3009
+ function canUseSingleQuoted(layout) {
3010
+ const str = layout.node.value;
3011
+ if (!(layout.isKey ? NB_SINGLE_ONE_LINE : NB_SINGLE_MULTI_LINE).test(str)) return false;
3012
+ if (/[ \t]\n|\n[ \t]/.test(str)) return false;
3013
+ if (!layout.isKey && layout.shiftOfContent === 0) {
3014
+ const firstLineBreak = str.indexOf("\n");
3015
+ if (firstLineBreak !== -1 && C_FORBIDDEN_CONTENT.test(str.slice(firstLineBreak + 1))) return false;
3016
+ }
3017
+ return true;
3018
+ }
3019
+ function canUseBlock(layout) {
3020
+ if (layout.flowOnly || !BLOCK_SCALAR_CONTENT.test(layout.node.value)) return false;
3021
+ const contentIndent = layout.shiftOfContent - layout.shiftOfParent;
3022
+ if (contentIndent < 1) return false;
3023
+ if (contentIndent > 9 && /^\n* /.test(layout.node.value)) return false;
3024
+ if (layout.shiftOfContent === 0 && C_FORBIDDEN_CONTENT.test(layout.node.value)) return false;
3025
+ return true;
3026
+ }
3027
+ function detectAllowedStyles(layout) {
3028
+ let mask = setBit(0, SCALAR_STYLE.DOUBLE_QUOTED);
3029
+ if (canUsePlain(layout)) mask = setBit(mask, SCALAR_STYLE.PLAIN);
3030
+ if (canUseSingleQuoted(layout)) mask = setBit(mask, SCALAR_STYLE.SINGLE_QUOTED);
3031
+ if (canUseBlock(layout)) mask = setBit(setBit(mask, SCALAR_STYLE.LITERAL_BLOCK), SCALAR_STYLE.FOLDED_BLOCK);
3032
+ layout.allowedStylesMask = mask;
3033
+ }
3034
+ function renderScalar(layout) {
3035
+ switch (layout.style) {
3036
+ case SCALAR_STYLE.PLAIN: return renderPlain(layout);
3037
+ case SCALAR_STYLE.SINGLE_QUOTED: return renderSingleQuoted(layout);
3038
+ case SCALAR_STYLE.LITERAL_BLOCK: return renderLiteralBlock(layout);
3039
+ case SCALAR_STYLE.FOLDED_BLOCK: return renderFoldedBlock(layout);
3040
+ case SCALAR_STYLE.DOUBLE_QUOTED: return renderDoubleQuoted(layout);
3041
+ }
3042
+ }
3043
+ function renderPlain(layout) {
3044
+ return encodeFlowBreaks(layout.node.value, layout.shiftOfContent);
3045
+ }
3046
+ function renderSingleQuoted(layout) {
3047
+ return `'${encodeFlowBreaks(layout.node.value, layout.shiftOfContent).replace(/'/g, "''")}'`;
3048
+ }
3049
+ function renderLiteralBlock(layout) {
3050
+ const value = layout.node.value;
3051
+ return "|" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(value, layout.shiftOfContent));
3052
+ }
3053
+ function renderFoldedBlock(layout) {
3054
+ const value = layout.node.value;
3055
+ const w = layout.presenterOptions.lineWidth;
3056
+ let availableWidth = Infinity;
3057
+ if (w !== -1) availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
3058
+ return ">" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(foldBlockScalar(value, availableWidth), layout.shiftOfContent));
3059
+ }
3060
+ function renderDoubleQuoted(layout) {
3061
+ return `"${escapeString(layout.node.value)}"`;
3062
+ }
3063
+ function encodeFlowBreaks(string, shiftOfContent) {
3064
+ let nextLF = string.indexOf("\n");
3065
+ if (nextLF === -1) return string;
3066
+ const pad = " ".repeat(shiftOfContent);
3067
+ let result = string.slice(0, nextLF);
3068
+ const lineRe = /(\n+)([^\n]*)/g;
3069
+ lineRe.lastIndex = nextLF;
3070
+ let match;
3071
+ while (match = lineRe.exec(string)) {
3072
+ const breaks = match[1].length;
3073
+ const line = match[2];
3074
+ result += "\n".repeat(breaks + 1) + pad + line;
3075
+ }
3076
+ return result;
3077
+ }
3078
+ function indentString(string, spaces) {
3079
+ const indent = " ".repeat(spaces);
3080
+ let position = 0;
3081
+ let result = "";
3082
+ const length = string.length;
3083
+ while (position < length) {
3084
+ let line;
3085
+ const next = string.indexOf("\n", position);
3086
+ if (next === -1) {
3087
+ line = string.slice(position);
3088
+ position = length;
3089
+ } else {
3090
+ line = string.slice(position, next + 1);
3091
+ position = next + 1;
3092
+ }
3093
+ if (line.length && line !== "\n") result += indent;
3094
+ result += line;
3095
+ }
3096
+ return result;
3097
+ }
3098
+ function needIndentIndicator(string) {
3099
+ return /^\n* /.test(string);
3100
+ }
3101
+ function blockHeader(string, shiftOfParent, shiftOfContent) {
3102
+ const indentIndicator = needIndentIndicator(string) ? String(shiftOfContent - shiftOfParent) : "";
3103
+ const clip = string[string.length - 1] === "\n";
3104
+ return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
3105
+ }
3106
+ function dropEndingNewline(string) {
3107
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
3108
+ }
3109
+ function isMoreIndented(char) {
3110
+ return char === " " || char === " ";
3111
+ }
3112
+ function foldLine(line, width) {
3113
+ if (line === "" || isMoreIndented(line[0])) return line;
3114
+ const breakRe = / [^ \t]/g;
3115
+ let match;
3116
+ let start = 0;
3117
+ let end;
3118
+ let curr = 0;
3119
+ let next = 0;
3120
+ let result = "";
3121
+ while (match = breakRe.exec(line)) {
3122
+ next = match.index;
3123
+ if (next - start > width) {
3124
+ end = curr > start ? curr : next;
3125
+ result += `\n${line.slice(start, end)}`;
3126
+ start = end + 1;
3127
+ }
3128
+ curr = next;
3129
+ }
3130
+ result += "\n";
3131
+ if (line.length - start > width && curr > start) result += `${line.slice(start, curr)}\n${line.slice(curr + 1)}`;
3132
+ else result += line.slice(start);
3133
+ return result.slice(1);
3134
+ }
3135
+ function foldBlockScalar(string, width) {
3136
+ const lineRe = /(\n+)([^\n]*)/g;
3137
+ let nextLF = string.indexOf("\n");
3138
+ if (nextLF === -1) nextLF = string.length;
3139
+ lineRe.lastIndex = nextLF;
3140
+ let result = foldLine(string.slice(0, nextLF), width);
3141
+ let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
3142
+ let moreIndented;
3143
+ let match;
3144
+ while (match = lineRe.exec(string)) {
3145
+ const prefix = match[1];
3146
+ const line = match[2];
3147
+ moreIndented = line !== "" && isMoreIndented(line[0]);
3148
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
3149
+ prevMoreIndented = moreIndented;
3150
+ }
3151
+ return result;
3152
+ }
3153
+ var CHARACTERS_TO_ESCAPE = /["\\\x00-\x1F\x7F-\xA0\u2028\u2029\uD800-\uDFFF\uFEFF\uFFFE\uFFFF]/gu;
3154
+ function escapeCharacter(character) {
3155
+ switch (character) {
3156
+ case "\0": return "\\0";
3157
+ case "\x07": return "\\a";
3158
+ case "\b": return "\\b";
3159
+ case " ": return "\\t";
3160
+ case "\n": return "\\n";
3161
+ case "\v": return "\\v";
3162
+ case "\f": return "\\f";
3163
+ case "\r": return "\\r";
3164
+ case "\x1B": return "\\e";
3165
+ case "\"": return "\\\"";
3166
+ case "\\": return "\\\\";
3167
+ case "…": return "\\N";
3168
+ case "\xA0": return "\\_";
3169
+ case "\u2028": return "\\L";
3170
+ case "\u2029": return "\\P";
3171
+ }
3172
+ const code = character.charCodeAt(0);
3173
+ const hex = code.toString(16).toUpperCase();
3174
+ if (code <= 255) return `\\x${"0".repeat(2 - hex.length)}${hex}`;
3175
+ return `\\u${"0".repeat(4 - hex.length)}${hex}`;
3176
+ }
3177
+ function escapeString(string) {
3178
+ return string.replace(CHARACTERS_TO_ESCAPE, escapeCharacter);
3179
+ }
3180
+ //#endregion
3181
+ //#region src/ast/presenter.ts
3182
+ var CHAR_LINE_FEED = 10;
3183
+ var DEFAULT_PRESENTER_OPTIONS = {
3184
+ indent: 2,
3185
+ seqNoIndent: false,
3186
+ seqInlineFirst: true,
3187
+ lineWidth: 80,
3188
+ flowBracketPadding: false,
3189
+ flowSkipCommaSpace: false,
3190
+ flowSkipColonSpace: false,
3191
+ quoteFlowKeys: false,
3192
+ quoteStyle: "single",
3193
+ forceQuotes: false,
3194
+ scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
3195
+ tagBeforeAnchor: false
3196
+ };
3197
+ function nodeTagShort(node) {
3198
+ return node.tagged ? node.tag : tagNameShort(node.tag);
3199
+ }
3200
+ function createPresenterState(options) {
3201
+ const opts = {
3202
+ ...DEFAULT_PRESENTER_OPTIONS,
3203
+ ...options
3204
+ };
3205
+ if (opts.flowSkipColonSpace) opts.quoteFlowKeys = true;
3206
+ return {
3207
+ ...opts,
3208
+ defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
3209
+ openEnded: false
3210
+ };
3211
+ }
3212
+ function generateNextLine(state, level) {
3213
+ return `\n${" ".repeat(state.indent * level)}`;
3214
+ }
3215
+ function scalarLayout(state, node, parent, level, isKey, flowOnly) {
3216
+ return {
3217
+ node,
3218
+ parent,
3219
+ level,
3220
+ isKey,
3221
+ flowOnly,
3222
+ shiftOfParent: level === 0 ? -1 : state.indent * (level - 1),
3223
+ shiftOfContent: state.indent * Math.max(1, level),
3224
+ shiftOfFirstLine: level === 0 ? 0 : state.indent * level,
3225
+ presenterOptions: state,
3226
+ allowedStylesMask: 0,
3227
+ style: node.style
3228
+ };
3229
+ }
3230
+ function writeFlowSequence(state, level, node) {
3231
+ let result = "";
3232
+ for (let index = 0, length = node.items.length; index < length; index += 1) {
3233
+ const item = writeNode(state, level, node.items[index], node, {}).text;
3234
+ if (index > 0) result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
3235
+ result += item;
3236
+ }
3237
+ const pad = state.flowBracketPadding && node.items.length > 0 ? " " : "";
3238
+ return `[${pad}${result}${pad}]`;
3239
+ }
3240
+ function writeBlockSequence(state, level, node, compact) {
3241
+ let result = "";
3242
+ for (let index = 0, length = node.items.length; index < length; index += 1) {
3243
+ const item = writeNode(state, level + 1, node.items[index], node, {
3244
+ block: true,
3245
+ compact: state.seqInlineFirst,
3246
+ isblockseq: true
3247
+ }).text;
3248
+ if (!compact || result !== "") result += generateNextLine(state, level);
3249
+ if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
3250
+ else result += "- ";
3251
+ result += item;
3252
+ }
3253
+ return result;
3254
+ }
3255
+ function writeFlowMapping(state, level, node) {
3256
+ let result = "";
3257
+ for (const { key, value } of node.items) {
3258
+ let pairBuffer = "";
3259
+ if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
3260
+ const keyRender = writeNode(state, level, key, node, { iskey: true });
3261
+ const keyText = keyRender.text;
3262
+ const valueText = writeNode(state, level, value, node, {}).text;
3263
+ const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
3264
+ const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
3265
+ const keyColonSep = key.kind === "alias" || keyIsBareProps ? " " : "";
3266
+ pairBuffer += `${keyText}${keyColonSep}:${sep}${valueText}`;
3267
+ result += pairBuffer;
3268
+ }
3269
+ const pad = state.flowBracketPadding && result !== "" ? " " : "";
3270
+ return `{${pad}${result}${pad}}`;
3271
+ }
3272
+ function writeBlockMapping(state, level, node, compact) {
3273
+ let result = "";
3274
+ for (let index = 0, length = node.items.length; index < length; index += 1) {
3275
+ let pairBuffer = "";
3276
+ if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
3277
+ const { key, value } = node.items[index];
3278
+ const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && key.style === COLLECTION_STYLE.BLOCK && key.items.length !== 0 || key.kind === "scalar" && (key.style === SCALAR_STYLE.LITERAL_BLOCK || key.style === SCALAR_STYLE.FOLDED_BLOCK);
3279
+ const keyRender = keyIsBlock ? writeNode(state, level + 1, key, node, {
3280
+ block: true,
3281
+ compact: true,
3282
+ isblockseq: !cannotBeCompact(state, key, level + 1)
3283
+ }) : writeNode(state, level + 1, key, node, {
3284
+ block: true,
3285
+ compact: true,
3286
+ iskey: true
3287
+ });
3288
+ const keyText = keyRender.text;
3289
+ const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
3290
+ const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
3291
+ const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
3292
+ if (explicitPair) {
3293
+ if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
3294
+ else pairBuffer += "? ";
3295
+ }
3296
+ pairBuffer += keyText;
3297
+ if (explicitPair) pairBuffer += generateNextLine(state, level);
3298
+ const valueText = writeNode(state, level + 1, value, node, {
3299
+ block: true,
3300
+ compact: explicitPair,
3301
+ isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
3302
+ }).text;
3303
+ const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
3304
+ const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
3305
+ if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
3306
+ else pairBuffer += `${keyColonSep}: `;
3307
+ pairBuffer += valueText;
3308
+ result += pairBuffer;
3309
+ }
3310
+ return result;
3311
+ }
3312
+ function cannotBeCompact(state, node, level) {
3313
+ if (node.kind === "alias") return true;
3314
+ return node.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
3315
+ }
3316
+ function writeNode(state, level, node, parent, ctx) {
3317
+ if (node.kind === "alias") {
3318
+ state.openEnded = false;
3319
+ return {
3320
+ text: `*${node.anchor}`,
3321
+ noBody: false
3322
+ };
3323
+ }
3324
+ const { block = false, iskey = false, isblockseq = false } = ctx;
3325
+ let compact = ctx.compact ?? false;
3326
+ const hasAnchor = node.anchor !== void 0;
3327
+ if (cannotBeCompact(state, node, level)) compact = false;
3328
+ let body;
3329
+ let shouldPrintTag = node.tagged;
3330
+ const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
3331
+ if (node.kind === "mapping") {
3332
+ if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
3333
+ else body = writeFlowMapping(state, level, node);
3334
+ } else if (node.kind === "sequence") {
3335
+ if (useBlockCollection) {
3336
+ if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
3337
+ else body = writeBlockSequence(state, level, node, compact);
3338
+ } else body = writeFlowSequence(state, level, node);
3339
+ } else {
3340
+ const layout = scalarLayout(state, node, parent, level, iskey, !block);
3341
+ detectAllowedStyles(layout);
3342
+ for (const rule of state.scalarStyleRules) rule(layout);
3343
+ body = renderScalar(layout);
3344
+ state.openEnded = (layout.style === SCALAR_STYLE.LITERAL_BLOCK || layout.style === SCALAR_STYLE.FOLDED_BLOCK) && (node.value === "\n" || node.value.endsWith("\n\n"));
3345
+ shouldPrintTag = node.tagged || body === "" && layout.flowOnly && parent?.kind === "sequence" && !hasAnchor || layout.style !== SCALAR_STYLE.PLAIN && node.tag !== state.defaultScalarTagName;
3346
+ }
3347
+ if ((node.kind === "mapping" || node.kind === "sequence") && !useBlockCollection) state.openEnded = false;
3348
+ if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
3349
+ const noBody = body === "";
3350
+ let text = body;
3351
+ if (shouldPrintTag || hasAnchor) {
3352
+ const props = [];
3353
+ const tag = shouldPrintTag ? nodeTagShort(node) : null;
3354
+ const anchor = hasAnchor ? `&${node.anchor}` : null;
3355
+ if (state.tagBeforeAnchor) {
3356
+ if (tag !== null) props.push(tag);
3357
+ if (anchor !== null) props.push(anchor);
3358
+ } else {
3359
+ if (anchor !== null) props.push(anchor);
3360
+ if (tag !== null) props.push(tag);
3361
+ }
3362
+ const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
3363
+ text = `${props.join(" ")}${sep}${body}`;
3364
+ }
3365
+ return {
3366
+ text,
3367
+ noBody
3368
+ };
3369
+ }
3370
+ function rootStartsOwnLine(node) {
3371
+ return (node.kind === "sequence" || node.kind === "mapping") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0 && !node.tagged && node.anchor === void 0;
3372
+ }
3373
+ function writeDocumentDirectives(doc) {
3374
+ let result = "";
3375
+ for (const directive of doc.directives) {
3376
+ if (directive.kind === "yaml") {
3377
+ result += `%YAML ${directive.version}\n`;
3378
+ continue;
3379
+ }
3380
+ const { handle, prefix } = directive;
3381
+ result += `%TAG ${handle} ${prefix}\n`;
3382
+ }
3383
+ return result;
3384
+ }
3385
+ /**
3386
+ * Build YAML from AST.
3387
+ *
3388
+ * @category AST
3389
+ */
3390
+ function present(documents, options) {
3391
+ const state = createPresenterState(options);
3392
+ let result = "";
3393
+ let previousEnded = false;
3394
+ for (let index = 0; index < documents.length; index += 1) {
3395
+ const doc = documents[index];
3396
+ state.openEnded = false;
3397
+ const directives = writeDocumentDirectives(doc);
3398
+ const hasDirectives = directives !== "";
3399
+ const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
3400
+ result += directives;
3401
+ if (doc.contents === null) {
3402
+ if (marker) result += "---\n";
3403
+ } else if (marker) {
3404
+ const body = writeNode(state, 0, doc.contents, null, {
3405
+ block: true,
3406
+ compact: true
3407
+ }).text;
3408
+ const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
3409
+ result += `---${sep}${body}\n`;
3410
+ } else result += writeNode(state, 0, doc.contents, null, {
3411
+ block: true,
3412
+ compact: true
3413
+ }).text + "\n";
3414
+ previousEnded = doc.explicitEnd || state.openEnded;
3415
+ if (previousEnded) result += "...\n";
3416
+ }
3417
+ return result;
3418
+ }
3419
+ //#endregion
3420
+ //#region src/dump.ts
3421
+ var DEFAULT_DUMP_OPTIONS = {
3422
+ ...DEFAULT_PRESENTER_OPTIONS,
3423
+ schema: DUMP_SCHEMA,
3424
+ skipInvalid: false,
3425
+ noRefs: false,
3426
+ flowLevel: -1,
3427
+ sortKeys: false,
3428
+ transform: () => {}
3429
+ };
3430
+ function defaultCompareFn(a, b) {
3431
+ const x = String(a);
3432
+ const y = String(b);
3433
+ if (x < y) return -1;
3434
+ if (x > y) return 1;
3435
+ return 0;
3436
+ }
3437
+ /**
3438
+ * Serializes JS object as a YAML document. By default it can dump every
3439
+ * supported YAML type, so it throws an exception if you try to dump regexps or
3440
+ * functions. However, you can disable exceptions by setting the
3441
+ * {@link DumpOptions.skipInvalid} option to `true`.
3442
+ *
3443
+ * @category Main
3444
+ */
3445
+ function dump(input, options = {}) {
3446
+ const opts = {
3447
+ ...DEFAULT_DUMP_OPTIONS,
3448
+ ...options
3449
+ };
3450
+ const documents = jsToAst(input, opts.schema, {
3451
+ noRefs: opts.noRefs,
3452
+ skipInvalid: opts.skipInvalid
3453
+ });
3454
+ if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
3455
+ if (ctx.depth < opts.flowLevel) return;
3456
+ if (node.kind === "sequence" || node.kind === "mapping") node.style = COLLECTION_STYLE.FLOW;
3457
+ return VISIT_SKIP;
3458
+ });
3459
+ if (opts.sortKeys) {
3460
+ const compareFn = opts.sortKeys === true ? defaultCompareFn : opts.sortKeys;
3461
+ visit(documents, (node) => {
3462
+ if (node.kind !== "mapping") return;
3463
+ node.items.sort((a, b) => compareFn(a.key.kind === "scalar" ? a.key.value : "", b.key.kind === "scalar" ? b.key.value : ""));
3464
+ });
3465
+ }
3466
+ opts.transform(documents);
3467
+ return present(documents, {
3468
+ ...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
3469
+ schema: opts.schema
3470
+ });
3471
+ }
3472
+ //#endregion
3473
+ //#region src/ast/from_events.ts
3474
+ var NO_RANGE = -1;
3475
+ function eventPosition(event) {
3476
+ if ("tagStart" in event && event.tagStart !== NO_RANGE) return event.tagStart;
3477
+ if ("anchorStart" in event && event.anchorStart !== NO_RANGE) return event.anchorStart;
3478
+ if ("valueStart" in event && event.valueStart !== NO_RANGE) return event.valueStart;
3479
+ if ("start" in event) return event.start;
3480
+ return 0;
3481
+ }
3482
+ function rawTag(state, event) {
3483
+ return event.tagStart === NO_RANGE ? "" : state.source.slice(event.tagStart, event.tagEnd);
3484
+ }
3485
+ function anchorName(state, event) {
3486
+ return event.anchorStart === NO_RANGE ? void 0 : state.source.slice(event.anchorStart, event.anchorEnd);
3487
+ }
3488
+ function buildScalar(state, event) {
3489
+ const value = getScalarValue(state.source, event);
3490
+ const raw = rawTag(state, event);
3491
+ let tag;
3492
+ let tagged = false;
3493
+ if (raw !== "") {
3494
+ tagged = true;
3495
+ tag = raw;
3496
+ } else if (event.style === SCALAR_STYLE.PLAIN) tag = state.schema.resolveImplicitScalarTag(value).tag.tagName;
3497
+ else tag = state.schema.defaultScalarTag.tagName;
3498
+ return {
3499
+ kind: "scalar",
3500
+ tag,
3501
+ tagged,
3502
+ style: event.style,
3503
+ anchor: anchorName(state, event),
3504
+ value
3505
+ };
3506
+ }
3507
+ function buildCollection(state, event, defaultTagName) {
3508
+ const raw = rawTag(state, event);
3509
+ let tag;
3510
+ let tagged = false;
3511
+ if (raw === "") tag = defaultTagName;
3512
+ else {
3513
+ tag = raw;
3514
+ tagged = true;
3515
+ }
3516
+ return {
3517
+ tag,
3518
+ tagged,
3519
+ style: event.style,
3520
+ anchor: anchorName(state, event)
3521
+ };
3522
+ }
3523
+ function addNode(state, node) {
3524
+ const frame = state.frames[state.frames.length - 1];
3525
+ if (frame.kind === "document") frame.doc.contents = node;
3526
+ else if (frame.kind === "sequence") frame.node.items.push(node);
3527
+ else if (frame.key) {
3528
+ frame.node.items.push({
3529
+ key: frame.key,
3530
+ value: node
3531
+ });
3532
+ frame.key = null;
3533
+ } else frame.key = node;
3534
+ }
3535
+ /**
3536
+ * Builds an AST from parser events
3537
+ *
3538
+ * @category AST
3539
+ */
3540
+ function eventsToAst(events, options) {
3541
+ const state = {
3542
+ source: options.source,
3543
+ schema: options.schema,
3544
+ eventIndex: 0,
3545
+ position: 0,
3546
+ frames: [],
3547
+ documents: []
3548
+ };
3549
+ while (state.eventIndex < events.length) {
3550
+ const event = events[state.eventIndex++];
3551
+ state.position = eventPosition(event);
3552
+ switch (event.type) {
3553
+ case EVENT_ID.DOCUMENT: {
3554
+ const doc = {
3555
+ contents: null,
3556
+ explicitStart: event.explicitStart,
3557
+ explicitEnd: event.explicitEnd,
3558
+ directives: event.directives
3559
+ };
3560
+ state.frames.push({
3561
+ kind: "document",
3562
+ doc
3563
+ });
3564
+ break;
3565
+ }
3566
+ case EVENT_ID.SCALAR:
3567
+ addNode(state, buildScalar(state, event));
3568
+ break;
3569
+ case EVENT_ID.SEQUENCE: {
3570
+ const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
3571
+ const node = {
3572
+ kind: "sequence",
3573
+ tag,
3574
+ tagged,
3575
+ style,
3576
+ anchor,
3577
+ items: []
3578
+ };
3579
+ state.frames.push({
3580
+ kind: "sequence",
3581
+ node
3582
+ });
3583
+ break;
3584
+ }
3585
+ case EVENT_ID.MAPPING: {
3586
+ const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
3587
+ const node = {
3588
+ kind: "mapping",
3589
+ tag,
3590
+ tagged,
3591
+ style,
3592
+ anchor,
3593
+ items: []
3594
+ };
3595
+ state.frames.push({
3596
+ kind: "mapping",
3597
+ node,
3598
+ key: null
3599
+ });
3600
+ break;
3601
+ }
3602
+ case EVENT_ID.ALIAS:
3603
+ addNode(state, {
3604
+ kind: "alias",
3605
+ anchor: state.source.slice(event.anchorStart, event.anchorEnd)
3606
+ });
3607
+ break;
3608
+ case EVENT_ID.POP: {
3609
+ const frame = state.frames.pop();
3610
+ if (frame.kind === "mapping" && frame.key) throw new Error("incomplete mapping pair in event stream");
3611
+ if (frame.kind === "document") state.documents.push(frame.doc);
3612
+ else addNode(state, frame.node);
3613
+ break;
3614
+ }
3615
+ }
3616
+ }
3617
+ return state.documents;
3618
+ }
3619
+ //#endregion
3620
+ //#region src/index.ts
3621
+ /** @deprecated Use `EVENT_ID.DOCUMENT` instead. @internal */
3622
+ var EVENT_DOCUMENT = EVENT_ID.DOCUMENT;
3623
+ /** @deprecated Use `EVENT_ID.SEQUENCE` instead. @internal */
3624
+ var EVENT_SEQUENCE = EVENT_ID.SEQUENCE;
3625
+ /** @deprecated Use `EVENT_ID.MAPPING` instead. @internal */
3626
+ var EVENT_MAPPING = EVENT_ID.MAPPING;
3627
+ /** @deprecated Use `EVENT_ID.SCALAR` instead. @internal */
3628
+ var EVENT_SCALAR = EVENT_ID.SCALAR;
3629
+ /** @deprecated Use `EVENT_ID.ALIAS` instead. @internal */
3630
+ var EVENT_ALIAS = EVENT_ID.ALIAS;
3631
+ /** @deprecated Use `EVENT_ID.POP` instead. @internal */
3632
+ var EVENT_POP = EVENT_ID.POP;
3633
+ /** @deprecated Use `SCALAR_STYLE.PLAIN` instead. @internal */
3634
+ var SCALAR_STYLE_PLAIN = SCALAR_STYLE.PLAIN;
3635
+ /** @deprecated Use `SCALAR_STYLE.SINGLE_QUOTED` instead. @internal */
3636
+ var SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE.SINGLE_QUOTED;
3637
+ /** @deprecated Use `SCALAR_STYLE.DOUBLE_QUOTED` instead. @internal */
3638
+ var SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE.DOUBLE_QUOTED;
3639
+ /** @deprecated Use `SCALAR_STYLE.LITERAL_BLOCK` instead. @internal */
3640
+ var SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE.LITERAL_BLOCK;
3641
+ /** @deprecated Use `SCALAR_STYLE.FOLDED_BLOCK` instead. @internal */
3642
+ var SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE.FOLDED_BLOCK;
3643
+ /** @deprecated Use `COLLECTION_STYLE.BLOCK` instead. @internal */
3644
+ var COLLECTION_STYLE_BLOCK = COLLECTION_STYLE.BLOCK;
3645
+ /** @deprecated Use `COLLECTION_STYLE.FLOW` instead. @internal */
3646
+ var COLLECTION_STYLE_FLOW = COLLECTION_STYLE.FLOW;
3647
+ /** @deprecated Use `CHOMPING_MODE.CLIP` instead. @internal */
3648
+ var CHOMPING_CLIP = CHOMPING_MODE.CLIP;
3649
+ /** @deprecated Use `CHOMPING_MODE.STRIP` instead. @internal */
3650
+ var CHOMPING_STRIP = CHOMPING_MODE.STRIP;
3651
+ /** @deprecated Use `CHOMPING_MODE.KEEP` instead. @internal */
3652
+ var CHOMPING_KEEP = CHOMPING_MODE.KEEP;
3653
+ //#endregion
3654
+ export { CHOMPING_CLIP, CHOMPING_KEEP, CHOMPING_MODE, CHOMPING_STRIP, COLLECTION_STYLE, COLLECTION_STYLE_BLOCK, COLLECTION_STYLE_FLOW, CORE_SCHEMA, DEFAULT_SCALAR_STYLE_RULES, DUMP_SCHEMA, EVENT_ALIAS, EVENT_DOCUMENT, EVENT_ID, EVENT_MAPPING, EVENT_POP, EVENT_SCALAR, EVENT_SEQUENCE, FAILSAFE_SCHEMA, JSON_SCHEMA, NOT_RESOLVED, SCALAR_STYLE, SCALAR_STYLE_DOUBLE_QUOTED, SCALAR_STYLE_FOLDED_BLOCK, SCALAR_STYLE_LITERAL_BLOCK, SCALAR_STYLE_PLAIN, SCALAR_STYLE_SINGLE_QUOTED, Schema, VISIT_BREAK, VISIT_SKIP, YAML11_SCHEMA, YAMLException, binaryTag, boolCoreTag, boolJsonTag, boolYaml11Tag, constructFromEvents, defineMappingTag, defineScalarTag, defineSequenceTag, dump, eventsToAst, floatCoreTag, floatJsonTag, floatYaml11Tag, getScalarValue, intCoreTag, intJsonTag, intYaml11Tag, jsToAst, legacyMapTag, load, loadAll, mapTag, mergeTag, nullCoreTag, nullJsonTag, nullYaml11Tag, omapTag, pairsTag, parseEvents, present, realMapTag, seqTag, setTag, strTag, timestampTag, visit };
3655
+
3656
+ //# sourceMappingURL=js-yaml.mjs.map