@depup/js-yaml 5.2.1-depup.9

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.
@@ -0,0 +1,3136 @@
1
+ /*! js-yaml 5.2.1 https://github.com/nodeca/js-yaml @license MIT */
2
+ //#region src/tag.ts
3
+ var NOT_RESOLVED = Symbol("NOT_RESOLVED");
4
+ var MERGE_KEY = Symbol("MERGE_KEY");
5
+ function defineScalarTag(tagName, options) {
6
+ return {
7
+ tagName,
8
+ nodeKind: "scalar",
9
+ implicit: options.implicit ?? false,
10
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
11
+ implicitFirstChars: options.implicitFirstChars ?? null,
12
+ resolve: options.resolve,
13
+ identify: options.identify ?? null,
14
+ represent: options.represent ?? ((data) => String(data)),
15
+ representTagName: options.representTagName ?? null
16
+ };
17
+ }
18
+ function defineSequenceTag(tagName, options) {
19
+ const carrierIsResult = options.finalize === void 0;
20
+ return {
21
+ tagName,
22
+ nodeKind: "sequence",
23
+ implicit: false,
24
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
25
+ create: options.create,
26
+ addItem: options.addItem,
27
+ finalize: options.finalize ?? ((carrier) => carrier),
28
+ carrierIsResult,
29
+ identify: options.identify ?? null,
30
+ represent: options.represent ?? ((data) => data),
31
+ representTagName: options.representTagName ?? null
32
+ };
33
+ }
34
+ function defineMappingTag(tagName, options) {
35
+ const carrierIsResult = options.finalize === void 0;
36
+ return {
37
+ tagName,
38
+ nodeKind: "mapping",
39
+ implicit: false,
40
+ matchByTagPrefix: options.matchByTagPrefix ?? false,
41
+ create: options.create,
42
+ addPair: options.addPair,
43
+ has: options.has,
44
+ keys: options.keys,
45
+ get: options.get,
46
+ finalize: options.finalize ?? ((carrier) => carrier),
47
+ carrierIsResult,
48
+ identify: options.identify ?? null,
49
+ represent: options.represent ?? ((data) => data),
50
+ representTagName: options.representTagName ?? null
51
+ };
52
+ }
53
+ //#endregion
54
+ //#region src/tag/scalar/str.ts
55
+ var strTag = defineScalarTag("tag:yaml.org,2002:str", {
56
+ resolve: (source) => source,
57
+ identify: (data) => typeof data === "string"
58
+ });
59
+ //#endregion
60
+ //#region src/tag/scalar/null_core.ts
61
+ var NULL_VALUES$1 = [
62
+ "",
63
+ "~",
64
+ "null",
65
+ "Null",
66
+ "NULL"
67
+ ];
68
+ var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
69
+ implicit: true,
70
+ implicitFirstChars: [
71
+ "",
72
+ "~",
73
+ "n",
74
+ "N"
75
+ ],
76
+ resolve: (source) => {
77
+ if (NULL_VALUES$1.indexOf(source) !== -1) return null;
78
+ return NOT_RESOLVED;
79
+ },
80
+ identify: (object) => object === null,
81
+ represent: () => "null"
82
+ });
83
+ //#endregion
84
+ //#region src/tag/scalar/null_json.ts
85
+ var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
86
+ implicit: true,
87
+ implicitFirstChars: ["n"],
88
+ resolve: (source, isExplicit) => {
89
+ if (source === "null" || isExplicit && source === "") return null;
90
+ return NOT_RESOLVED;
91
+ },
92
+ identify: (object) => object === null,
93
+ represent: () => "null"
94
+ });
95
+ //#endregion
96
+ //#region src/tag/scalar/null_yaml11.ts
97
+ var NULL_VALUES = [
98
+ "",
99
+ "~",
100
+ "null",
101
+ "Null",
102
+ "NULL"
103
+ ];
104
+ var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
105
+ implicit: true,
106
+ implicitFirstChars: [
107
+ "",
108
+ "~",
109
+ "n",
110
+ "N"
111
+ ],
112
+ resolve: (source) => {
113
+ if (NULL_VALUES.indexOf(source) !== -1) return null;
114
+ return NOT_RESOLVED;
115
+ },
116
+ identify: (object) => object === null,
117
+ represent: () => "null"
118
+ });
119
+ //#endregion
120
+ //#region src/tag/scalar/bool_core.ts
121
+ var TRUE_VALUES$2 = [
122
+ "true",
123
+ "True",
124
+ "TRUE"
125
+ ];
126
+ var FALSE_VALUES$2 = [
127
+ "false",
128
+ "False",
129
+ "FALSE"
130
+ ];
131
+ var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
132
+ implicit: true,
133
+ implicitFirstChars: [
134
+ "t",
135
+ "T",
136
+ "f",
137
+ "F"
138
+ ],
139
+ resolve: (source) => {
140
+ if (TRUE_VALUES$2.indexOf(source) !== -1) return true;
141
+ if (FALSE_VALUES$2.indexOf(source) !== -1) return false;
142
+ return NOT_RESOLVED;
143
+ },
144
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
145
+ represent: (object) => object ? "true" : "false"
146
+ });
147
+ //#endregion
148
+ //#region src/tag/scalar/bool_json.ts
149
+ var TRUE_VALUES$1 = ["true"];
150
+ var FALSE_VALUES$1 = ["false"];
151
+ var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
152
+ implicit: true,
153
+ implicitFirstChars: ["t", "f"],
154
+ resolve: (source) => {
155
+ if (TRUE_VALUES$1.indexOf(source) !== -1) return true;
156
+ if (FALSE_VALUES$1.indexOf(source) !== -1) return false;
157
+ return NOT_RESOLVED;
158
+ },
159
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
160
+ represent: (object) => object ? "true" : "false"
161
+ });
162
+ //#endregion
163
+ //#region src/tag/scalar/bool_yaml11.ts
164
+ var TRUE_VALUES = [
165
+ "true",
166
+ "True",
167
+ "TRUE",
168
+ "y",
169
+ "Y",
170
+ "yes",
171
+ "Yes",
172
+ "YES",
173
+ "on",
174
+ "On",
175
+ "ON"
176
+ ];
177
+ var FALSE_VALUES = [
178
+ "false",
179
+ "False",
180
+ "FALSE",
181
+ "n",
182
+ "N",
183
+ "no",
184
+ "No",
185
+ "NO",
186
+ "off",
187
+ "Off",
188
+ "OFF"
189
+ ];
190
+ var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
191
+ implicit: true,
192
+ implicitFirstChars: [
193
+ "y",
194
+ "Y",
195
+ "n",
196
+ "N",
197
+ "t",
198
+ "T",
199
+ "f",
200
+ "F",
201
+ "o",
202
+ "O"
203
+ ],
204
+ resolve: (source) => {
205
+ if (TRUE_VALUES.indexOf(source) !== -1) return true;
206
+ if (FALSE_VALUES.indexOf(source) !== -1) return false;
207
+ return NOT_RESOLVED;
208
+ },
209
+ identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
210
+ represent: (object) => object ? "true" : "false"
211
+ });
212
+ //#endregion
213
+ //#region src/tag/scalar/int_core.ts
214
+ var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
215
+ var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
216
+ function parseYamlInteger$2(source) {
217
+ let value = source;
218
+ let sign = 1;
219
+ if (value[0] === "-" || value[0] === "+") {
220
+ if (value[0] === "-") sign = -1;
221
+ value = value.slice(1);
222
+ }
223
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
224
+ if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
225
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
226
+ return sign * parseInt(value, 10);
227
+ }
228
+ function resolveYamlInteger$2(source, isExplicit) {
229
+ if (isExplicit) {
230
+ if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
231
+ } else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
232
+ const result = parseYamlInteger$2(source);
233
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
234
+ }
235
+ var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
236
+ implicit: true,
237
+ implicitFirstChars: [
238
+ "-",
239
+ "+",
240
+ ..."0123456789"
241
+ ],
242
+ resolve: resolveYamlInteger$2,
243
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
244
+ represent: (object) => object.toString(10)
245
+ });
246
+ //#endregion
247
+ //#region src/tag/scalar/int_json.ts
248
+ var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
249
+ var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
250
+ function parseYamlInteger$1(source) {
251
+ let value = source;
252
+ let sign = 1;
253
+ if (value[0] === "-" || value[0] === "+") {
254
+ if (value[0] === "-") sign = -1;
255
+ value = value.slice(1);
256
+ }
257
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
258
+ if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
259
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
260
+ return sign * parseInt(value, 10);
261
+ }
262
+ function resolveYamlInteger$1(source, isExplicit) {
263
+ if (isExplicit) {
264
+ if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
265
+ } else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
266
+ const result = parseYamlInteger$1(source);
267
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
268
+ }
269
+ var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
270
+ implicit: true,
271
+ implicitFirstChars: ["-", ..."0123456789"],
272
+ resolve: resolveYamlInteger$1,
273
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
274
+ represent: (object) => object.toString(10)
275
+ });
276
+ //#endregion
277
+ //#region src/tag/scalar/int_yaml11.ts
278
+ 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_]*))$");
279
+ function parseYamlInteger(source) {
280
+ let value = source.replace(/_/g, "");
281
+ let sign = 1;
282
+ if (value[0] === "-" || value[0] === "+") {
283
+ if (value[0] === "-") sign = -1;
284
+ value = value.slice(1);
285
+ }
286
+ if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
287
+ if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
288
+ if (value.includes(":")) {
289
+ let result = 0;
290
+ for (const part of value.split(":")) result = result * 60 + Number(part);
291
+ return sign * result;
292
+ }
293
+ if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8);
294
+ return sign * parseInt(value, 10);
295
+ }
296
+ function resolveYamlInteger(source) {
297
+ if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED;
298
+ const result = parseYamlInteger(source);
299
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
300
+ }
301
+ var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
302
+ implicit: true,
303
+ implicitFirstChars: [
304
+ "-",
305
+ "+",
306
+ ..."0123456789"
307
+ ],
308
+ resolve: resolveYamlInteger,
309
+ identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
310
+ represent: (object) => object.toString(10)
311
+ });
312
+ //#endregion
313
+ //#region src/tag/scalar/float_core.ts
314
+ 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))$");
315
+ var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
316
+ function resolveYamlFloat$2(source) {
317
+ if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED;
318
+ let value = source.toLowerCase();
319
+ const sign = value[0] === "-" ? -1 : 1;
320
+ if ("+-".includes(value[0])) value = value.slice(1);
321
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
322
+ if (value === ".nan") return NaN;
323
+ const result = sign * parseFloat(value);
324
+ if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result;
325
+ return NOT_RESOLVED;
326
+ }
327
+ function representYamlFloat$2(object) {
328
+ if (isNaN(object)) return ".nan";
329
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
330
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
331
+ if (Object.is(object, -0)) return "-0.0";
332
+ const result = object.toString(10);
333
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
334
+ }
335
+ var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
336
+ implicit: true,
337
+ implicitFirstChars: [
338
+ "-",
339
+ "+",
340
+ ".",
341
+ ..."0123456789"
342
+ ],
343
+ resolve: resolveYamlFloat$2,
344
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
345
+ represent: representYamlFloat$2
346
+ });
347
+ //#endregion
348
+ //#region src/tag/scalar/float_json.ts
349
+ var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
350
+ 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))$");
351
+ function resolveYamlFloat$1(source, isExplicit) {
352
+ if (isExplicit) {
353
+ if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
354
+ let value = source.toLowerCase();
355
+ const sign = value[0] === "-" ? -1 : 1;
356
+ if ("+-".includes(value[0])) value = value.slice(1);
357
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
358
+ if (value === ".nan") return NaN;
359
+ const result = sign * parseFloat(value);
360
+ return Number.isFinite(result) ? result : NOT_RESOLVED;
361
+ }
362
+ if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
363
+ const result = Number(source);
364
+ if (Number.isFinite(result)) return result;
365
+ return NOT_RESOLVED;
366
+ }
367
+ function representYamlFloat$1(object) {
368
+ if (isNaN(object)) return ".nan";
369
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
370
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
371
+ if (Object.is(object, -0)) return "-0.0";
372
+ const result = object.toString(10);
373
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
374
+ }
375
+ var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
376
+ implicit: true,
377
+ implicitFirstChars: ["-", ..."0123456789"],
378
+ resolve: resolveYamlFloat$1,
379
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
380
+ represent: representYamlFloat$1
381
+ });
382
+ //#endregion
383
+ //#region src/tag/scalar/float_yaml11.ts
384
+ 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))$");
385
+ var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
386
+ function resolveYamlFloat(source) {
387
+ if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED;
388
+ let value = source.toLowerCase().replace(/_/g, "");
389
+ const sign = value[0] === "-" ? -1 : 1;
390
+ if ("+-".includes(value[0])) value = value.slice(1);
391
+ if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
392
+ if (value === ".nan") return NaN;
393
+ let result = 0;
394
+ if (value.includes(":")) {
395
+ for (const part of value.split(":")) result = result * 60 + Number(part);
396
+ result *= sign;
397
+ } else result = sign * parseFloat(value);
398
+ if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result;
399
+ return NOT_RESOLVED;
400
+ }
401
+ function representYamlFloat(object) {
402
+ if (isNaN(object)) return ".nan";
403
+ if (object === Number.POSITIVE_INFINITY) return ".inf";
404
+ if (object === Number.NEGATIVE_INFINITY) return "-.inf";
405
+ if (Object.is(object, -0)) return "-0.0";
406
+ const result = object.toString(10);
407
+ return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
408
+ }
409
+ var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
410
+ implicit: true,
411
+ implicitFirstChars: [
412
+ "-",
413
+ "+",
414
+ ".",
415
+ ..."0123456789"
416
+ ],
417
+ resolve: resolveYamlFloat,
418
+ identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
419
+ represent: representYamlFloat
420
+ });
421
+ //#endregion
422
+ //#region src/tag/scalar/merge.ts
423
+ var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
424
+ implicit: true,
425
+ implicitFirstChars: ["<"],
426
+ resolve: (source, isExplicit) => {
427
+ if (source === "<<" || isExplicit && source === "") return MERGE_KEY;
428
+ return NOT_RESOLVED;
429
+ }
430
+ });
431
+ //#endregion
432
+ //#region src/tag/scalar/binary.ts
433
+ var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
434
+ function resolveYamlBinary(source) {
435
+ const input = source.replace(/\s/g, "");
436
+ if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED;
437
+ const binary = atob(input);
438
+ const result = new Uint8Array(binary.length);
439
+ for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index);
440
+ return result;
441
+ }
442
+ function representYamlBinary(object) {
443
+ let binary = "";
444
+ for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
445
+ return btoa(binary);
446
+ }
447
+ var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
448
+ resolve: resolveYamlBinary,
449
+ identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
450
+ represent: representYamlBinary
451
+ });
452
+ //#endregion
453
+ //#region src/tag/scalar/timestamp.ts
454
+ var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
455
+ 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]))?))?$");
456
+ function resolveYamlTimestamp(source) {
457
+ let match = YAML_DATE_REGEXP.exec(source);
458
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
459
+ if (match === null) return NOT_RESOLVED;
460
+ const year = +match[1];
461
+ const month = +match[2] - 1;
462
+ const day = +match[3];
463
+ if (!match[4]) {
464
+ const date = new Date(Date.UTC(year, month, day));
465
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
466
+ return date;
467
+ }
468
+ const hour = +match[4];
469
+ const minute = +match[5];
470
+ const second = +match[6];
471
+ let fraction = 0;
472
+ if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED;
473
+ if (match[7]) {
474
+ let value = match[7].slice(0, 3);
475
+ while (value.length < 3) value += "0";
476
+ fraction = +value;
477
+ }
478
+ const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
479
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
480
+ if (match[9]) {
481
+ const offsetHour = +match[10];
482
+ const offsetMinute = +(match[11] || 0);
483
+ if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED;
484
+ const offset = (offsetHour * 60 + offsetMinute) * 6e4;
485
+ date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
486
+ }
487
+ return date;
488
+ }
489
+ var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
490
+ implicit: true,
491
+ implicitFirstChars: [..."0123456789"],
492
+ resolve: resolveYamlTimestamp,
493
+ identify: (object) => object instanceof Date,
494
+ represent: (object) => object.toISOString()
495
+ });
496
+ //#endregion
497
+ //#region src/tag/sequence/seq.ts
498
+ var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
499
+ create: () => [],
500
+ addItem: (container, item) => {
501
+ container.push(item);
502
+ },
503
+ identify: Array.isArray
504
+ });
505
+ //#endregion
506
+ //#region src/common/object.ts
507
+ function isPlainObject(data) {
508
+ if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
509
+ const prototype = Object.getPrototypeOf(data);
510
+ return prototype === null || prototype === Object.prototype;
511
+ }
512
+ function pick(object, keys) {
513
+ const result = {};
514
+ for (const key of keys) if (object[key] !== void 0) result[key] = object[key];
515
+ return result;
516
+ }
517
+ //#endregion
518
+ //#region src/tag/sequence/omap.ts
519
+ var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
520
+ create: () => ({
521
+ list: [],
522
+ seen: /* @__PURE__ */ new Set()
523
+ }),
524
+ addItem: (carrier, item) => {
525
+ let key;
526
+ if (item instanceof Map) {
527
+ if (item.size !== 1) return "cannot resolve an ordered map item";
528
+ key = item.keys().next().value;
529
+ } else if (isPlainObject(item)) {
530
+ const itemKeys = Object.keys(item);
531
+ if (itemKeys.length !== 1) return "cannot resolve an ordered map item";
532
+ key = itemKeys[0];
533
+ } else return "cannot resolve an ordered map item";
534
+ if (carrier.seen.has(key)) return "duplicate key in ordered map";
535
+ carrier.seen.add(key);
536
+ carrier.list.push(item);
537
+ return "";
538
+ },
539
+ finalize: (carrier) => carrier.list
540
+ });
541
+ //#endregion
542
+ //#region src/tag/sequence/pairs.ts
543
+ var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
544
+ create: () => [],
545
+ addItem: (container, item) => {
546
+ if (item instanceof Map) {
547
+ if (item.size !== 1) return "cannot resolve a pairs item";
548
+ container.push(item.entries().next().value);
549
+ return "";
550
+ }
551
+ if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item";
552
+ const object = item;
553
+ const keys = Object.keys(object);
554
+ if (keys.length !== 1) return "cannot resolve a pairs item";
555
+ container.push([keys[0], object[keys[0]]]);
556
+ return "";
557
+ }
558
+ });
559
+ //#endregion
560
+ //#region src/tag/mapping/map.ts
561
+ var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
562
+ create: () => ({}),
563
+ identify: isPlainObject,
564
+ represent: (o) => {
565
+ const map = /* @__PURE__ */ new Map();
566
+ for (const key of Object.keys(o)) map.set(key, o[key]);
567
+ return map;
568
+ },
569
+ addPair: (container, key, value) => {
570
+ if (key !== null && typeof key === "object") return "object-based map does not support complex keys";
571
+ const normalizedKey = String(key);
572
+ if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
573
+ value,
574
+ enumerable: true,
575
+ configurable: true,
576
+ writable: true
577
+ });
578
+ else container[normalizedKey] = value;
579
+ return "";
580
+ },
581
+ has: (container, key) => {
582
+ if (key !== null && typeof key === "object") return false;
583
+ return Object.prototype.hasOwnProperty.call(container, String(key));
584
+ },
585
+ keys: (container) => Object.keys(container),
586
+ get: (container, key) => container[String(key)]
587
+ });
588
+ //#endregion
589
+ //#region src/tag/mapping/set.ts
590
+ var setTag = defineMappingTag("tag:yaml.org,2002:set", {
591
+ create: () => /* @__PURE__ */ new Set(),
592
+ identify: (data) => data instanceof Set,
593
+ represent: (data) => {
594
+ const map = /* @__PURE__ */ new Map();
595
+ for (const key of data) map.set(key, null);
596
+ return map;
597
+ },
598
+ addPair: (container, key, value) => {
599
+ if (value !== null) return "cannot resolve a set item";
600
+ container.add(key);
601
+ return "";
602
+ },
603
+ has: (container, key) => container.has(key),
604
+ keys: (container) => container.keys(),
605
+ get: () => null
606
+ });
607
+ //#endregion
608
+ //#region src/schema.ts
609
+ function createTagDefinitionMap() {
610
+ return {
611
+ scalar: {},
612
+ sequence: {},
613
+ mapping: {}
614
+ };
615
+ }
616
+ function createTagDefinitionListMap() {
617
+ return {
618
+ scalar: [],
619
+ sequence: [],
620
+ mapping: []
621
+ };
622
+ }
623
+ function compileTags(tags) {
624
+ const result = [];
625
+ for (const tag of tags) {
626
+ let index = result.length;
627
+ for (let previousIndex = 0; previousIndex < result.length; previousIndex++) {
628
+ const previous = result[previousIndex];
629
+ if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
630
+ index = previousIndex;
631
+ break;
632
+ }
633
+ }
634
+ result[index] = tag;
635
+ }
636
+ return result;
637
+ }
638
+ var Schema = class Schema {
639
+ tags;
640
+ implicitScalarTags;
641
+ implicitScalarByFirstChar;
642
+ implicitScalarAnyFirstChar;
643
+ defaultScalarTag;
644
+ defaultSequenceTag;
645
+ defaultMappingTag;
646
+ exact;
647
+ prefix;
648
+ constructor(tags) {
649
+ const compiledTags = compileTags(tags);
650
+ const implicitScalarTags = [];
651
+ const exact = createTagDefinitionMap();
652
+ const prefix = createTagDefinitionListMap();
653
+ for (const tag of compiledTags) {
654
+ if (tag.nodeKind === "scalar" && tag.implicit) {
655
+ if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix");
656
+ implicitScalarTags.push(tag);
657
+ }
658
+ switch (tag.nodeKind) {
659
+ case "scalar":
660
+ if (tag.matchByTagPrefix) prefix.scalar.push(tag);
661
+ else exact.scalar[tag.tagName] = tag;
662
+ break;
663
+ case "sequence":
664
+ if (tag.matchByTagPrefix) prefix.sequence.push(tag);
665
+ else exact.sequence[tag.tagName] = tag;
666
+ break;
667
+ case "mapping":
668
+ if (tag.matchByTagPrefix) prefix.mapping.push(tag);
669
+ else exact.mapping[tag.tagName] = tag;
670
+ break;
671
+ }
672
+ }
673
+ const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
674
+ const keys = /* @__PURE__ */ new Set();
675
+ for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key);
676
+ const implicitScalarByFirstChar = /* @__PURE__ */ new Map();
677
+ for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
678
+ const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
679
+ if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
680
+ this.tags = compiledTags;
681
+ this.implicitScalarTags = implicitScalarTags;
682
+ this.implicitScalarByFirstChar = implicitScalarByFirstChar;
683
+ this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
684
+ this.defaultScalarTag = defaultScalarTag;
685
+ this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
686
+ this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
687
+ this.exact = exact;
688
+ this.prefix = prefix;
689
+ }
690
+ withTags(...tags) {
691
+ let flatTags = [];
692
+ for (const tag of tags) flatTags = flatTags.concat(tag);
693
+ return new Schema([...this.tags, ...flatTags]);
694
+ }
695
+ };
696
+ var FAILSAFE_SCHEMA = new Schema([
697
+ strTag,
698
+ seqTag,
699
+ mapTag
700
+ ]);
701
+ var JSON_SCHEMA = new Schema([
702
+ ...FAILSAFE_SCHEMA.tags,
703
+ nullJsonTag,
704
+ boolJsonTag,
705
+ intJsonTag,
706
+ floatJsonTag
707
+ ]);
708
+ var CORE_SCHEMA = new Schema([
709
+ ...FAILSAFE_SCHEMA.tags,
710
+ nullCoreTag,
711
+ boolCoreTag,
712
+ intCoreTag,
713
+ floatCoreTag
714
+ ]);
715
+ var YAML11_SCHEMA = new Schema([
716
+ ...FAILSAFE_SCHEMA.tags,
717
+ nullYaml11Tag,
718
+ boolYaml11Tag,
719
+ intYaml11Tag,
720
+ floatYaml11Tag,
721
+ timestampTag,
722
+ mergeTag,
723
+ binaryTag,
724
+ omapTag,
725
+ pairsTag,
726
+ setTag
727
+ ]);
728
+ //#endregion
729
+ //#region src/tag/mapping/real_map.ts
730
+ var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
731
+ create: () => /* @__PURE__ */ new Map(),
732
+ addPair: (container, key, value) => {
733
+ container.set(key, value);
734
+ return "";
735
+ },
736
+ has: (container, key) => container.has(key),
737
+ keys: (container) => container.keys(),
738
+ get: (container, key) => container.get(key),
739
+ identify: (data) => data instanceof Map || isPlainObject(data),
740
+ represent: (data) => {
741
+ if (data instanceof Map) return data;
742
+ const map = /* @__PURE__ */ new Map();
743
+ const obj = data;
744
+ for (const key of Object.keys(obj)) map.set(key, obj[key]);
745
+ return map;
746
+ }
747
+ });
748
+ //#endregion
749
+ //#region src/tag/mapping/legacy_map.ts
750
+ function normalizeKey(key) {
751
+ if (Array.isArray(key)) {
752
+ const array = Array.prototype.slice.call(key);
753
+ for (let index = 0; index < array.length; index++) {
754
+ if (Array.isArray(array[index])) return null;
755
+ if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]";
756
+ }
757
+ return String(array);
758
+ }
759
+ if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
760
+ return String(key);
761
+ }
762
+ var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
763
+ create: () => ({}),
764
+ identify: isPlainObject,
765
+ represent: (o) => {
766
+ const map = /* @__PURE__ */ new Map();
767
+ for (const key of Object.keys(o)) map.set(key, o[key]);
768
+ return map;
769
+ },
770
+ addPair: (container, key, value) => {
771
+ const normalizedKey = normalizeKey(key);
772
+ if (normalizedKey === null) return "nested arrays are not supported inside keys";
773
+ if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
774
+ value,
775
+ enumerable: true,
776
+ configurable: true,
777
+ writable: true
778
+ });
779
+ else container[normalizedKey] = value;
780
+ return "";
781
+ },
782
+ has: (container, key) => {
783
+ const normalizedKey = normalizeKey(key);
784
+ return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
785
+ },
786
+ keys: (container) => Object.keys(container),
787
+ get: (container, key) => container[String(key)]
788
+ });
789
+ //#endregion
790
+ //#region src/common/snippet.ts
791
+ var DEFAULT_SNIPPET_OPTIONS = {
792
+ maxLength: 79,
793
+ indent: 1,
794
+ linesBefore: 3,
795
+ linesAfter: 2
796
+ };
797
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
798
+ let head = "";
799
+ let tail = "";
800
+ const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
801
+ if (position - lineStart > maxHalfLength) {
802
+ head = " ... ";
803
+ lineStart = position - maxHalfLength + head.length;
804
+ }
805
+ if (lineEnd - position > maxHalfLength) {
806
+ tail = " ...";
807
+ lineEnd = position + maxHalfLength - tail.length;
808
+ }
809
+ return {
810
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
811
+ pos: position - lineStart + head.length
812
+ };
813
+ }
814
+ function padStart(string, max) {
815
+ return " ".repeat(Math.max(max - string.length, 0)) + string;
816
+ }
817
+ function makeSnippet(mark, options) {
818
+ if (!mark.buffer) return null;
819
+ const opts = {
820
+ ...DEFAULT_SNIPPET_OPTIONS,
821
+ ...options
822
+ };
823
+ const re = /\r?\n|\r|\0/g;
824
+ const lineStarts = [0];
825
+ const lineEnds = [];
826
+ let match;
827
+ let foundLineNo = -1;
828
+ while (match = re.exec(mark.buffer)) {
829
+ lineEnds.push(match.index);
830
+ lineStarts.push(match.index + match[0].length);
831
+ if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2;
832
+ }
833
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
834
+ let result = "";
835
+ const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
836
+ const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
837
+ for (let i = 1; i <= opts.linesBefore; i++) {
838
+ if (foundLineNo - i < 0) break;
839
+ const line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
840
+ result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line.str}\n${result}`;
841
+ }
842
+ const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
843
+ result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}\n`;
844
+ result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^\n`;
845
+ for (let i = 1; i <= opts.linesAfter; i++) {
846
+ if (foundLineNo + i >= lineEnds.length) break;
847
+ const line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
848
+ result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line.str}\n`;
849
+ }
850
+ return result.replace(/\n$/, "");
851
+ }
852
+ //#endregion
853
+ //#region src/common/exception.ts
854
+ function formatError(exception, compact) {
855
+ let where = "";
856
+ if (!exception.mark) return exception.reason;
857
+ if (exception.mark.name) where += `in "${exception.mark.name}" `;
858
+ where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
859
+ if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
860
+ return `${exception.reason} ${where}`;
861
+ }
862
+ var YAMLException = class extends Error {
863
+ reason;
864
+ mark;
865
+ constructor(reason, mark) {
866
+ super();
867
+ this.name = "YAMLException";
868
+ this.reason = reason;
869
+ this.mark = mark;
870
+ this.message = formatError(this, false);
871
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
872
+ }
873
+ toString(compact) {
874
+ return `${this.name}: ${formatError(this, compact)}`;
875
+ }
876
+ };
877
+ function throwErrorAt(source, position, message, filename = "") {
878
+ let line = 0;
879
+ let lineStart = 0;
880
+ for (let index = 0; index < position; index++) {
881
+ const ch = source.charCodeAt(index);
882
+ if (ch === 10) {
883
+ line++;
884
+ lineStart = index + 1;
885
+ } else if (ch === 13) {
886
+ line++;
887
+ if (source.charCodeAt(index + 1) === 10) index++;
888
+ lineStart = index + 1;
889
+ }
890
+ }
891
+ const mark = {
892
+ name: filename,
893
+ buffer: source,
894
+ position,
895
+ line,
896
+ column: position - lineStart
897
+ };
898
+ mark.snippet = makeSnippet(mark);
899
+ throw new YAMLException(message, mark);
900
+ }
901
+ //#endregion
902
+ //#region src/parser/events.ts
903
+ var EVENT_DOCUMENT = 1;
904
+ var EVENT_SEQUENCE = 2;
905
+ var EVENT_MAPPING = 3;
906
+ var EVENT_SCALAR = 4;
907
+ var EVENT_ALIAS = 5;
908
+ var EVENT_POP = 6;
909
+ var SCALAR_STYLE_PLAIN = 1;
910
+ var SCALAR_STYLE_SINGLE_QUOTED = 2;
911
+ var SCALAR_STYLE_DOUBLE_QUOTED = 3;
912
+ var SCALAR_STYLE_LITERAL_BLOCK = 4;
913
+ var SCALAR_STYLE_FOLDED_BLOCK = 5;
914
+ var COLLECTION_STYLE_BLOCK = 1;
915
+ var COLLECTION_STYLE_FLOW = 2;
916
+ var CHOMPING_CLIP = 1;
917
+ var CHOMPING_STRIP = 2;
918
+ var CHOMPING_KEEP = 3;
919
+ //#endregion
920
+ //#region src/parser/parser_scalar.ts
921
+ var NO_RANGE$3 = -1;
922
+ function simpleEscapeSequence(c) {
923
+ switch (c) {
924
+ case 48: return "\0";
925
+ case 97: return "\x07";
926
+ case 98: return "\b";
927
+ case 116: return " ";
928
+ case 9: return " ";
929
+ case 110: return "\n";
930
+ case 118: return "\v";
931
+ case 102: return "\f";
932
+ case 114: return "\r";
933
+ case 101: return "\x1B";
934
+ case 32: return " ";
935
+ case 34: return "\"";
936
+ case 47: return "/";
937
+ case 92: return "\\";
938
+ case 78: return "…";
939
+ case 95: return "\xA0";
940
+ case 76: return "\u2028";
941
+ case 80: return "\u2029";
942
+ default: return "";
943
+ }
944
+ }
945
+ var simpleEscapeCheck = new Array(256);
946
+ var simpleEscapeMap = new Array(256);
947
+ for (let i = 0; i < 256; i++) {
948
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
949
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
950
+ }
951
+ function charFromCodepoint(c) {
952
+ if (c <= 65535) return String.fromCharCode(c);
953
+ return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
954
+ }
955
+ function fromHexCode$1(c) {
956
+ if (c >= 48 && c <= 57) return c - 48;
957
+ return (c | 32) - 97 + 10;
958
+ }
959
+ function escapedHexLen$1(c) {
960
+ if (c === 120) return 2;
961
+ if (c === 117) return 4;
962
+ return 8;
963
+ }
964
+ function skipFoldedBreaks(input, position, end) {
965
+ let breaks = 0;
966
+ while (position < end) {
967
+ const ch = input.charCodeAt(position);
968
+ if (ch === 10) {
969
+ breaks++;
970
+ position++;
971
+ } else if (ch === 13) {
972
+ breaks++;
973
+ position++;
974
+ if (input.charCodeAt(position) === 10) position++;
975
+ } else if (ch === 32 || ch === 9) position++;
976
+ else break;
977
+ }
978
+ return {
979
+ position,
980
+ breaks
981
+ };
982
+ }
983
+ function foldedBreaks(count) {
984
+ if (count === 1) return " ";
985
+ return "\n".repeat(count - 1);
986
+ }
987
+ function getPlainValue(input, start, end) {
988
+ let result = "";
989
+ let position = start;
990
+ let captureStart = start;
991
+ let captureEnd = start;
992
+ while (position < end) {
993
+ const ch = input.charCodeAt(position);
994
+ if (ch === 10 || ch === 13) {
995
+ result += input.slice(captureStart, captureEnd);
996
+ const fold = skipFoldedBreaks(input, position, end);
997
+ result += foldedBreaks(fold.breaks);
998
+ position = captureStart = captureEnd = fold.position;
999
+ } else {
1000
+ position++;
1001
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1002
+ }
1003
+ }
1004
+ return result + input.slice(captureStart, captureEnd);
1005
+ }
1006
+ function getSingleQuotedValue(input, start, end) {
1007
+ let result = "";
1008
+ let position = start;
1009
+ let captureStart = start;
1010
+ let captureEnd = start;
1011
+ while (position < end) {
1012
+ const ch = input.charCodeAt(position);
1013
+ if (ch === 39) {
1014
+ result += input.slice(captureStart, position) + "'";
1015
+ position += 2;
1016
+ captureStart = captureEnd = position;
1017
+ } else if (ch === 10 || ch === 13) {
1018
+ result += input.slice(captureStart, captureEnd);
1019
+ const fold = skipFoldedBreaks(input, position, end);
1020
+ result += foldedBreaks(fold.breaks);
1021
+ position = captureStart = captureEnd = fold.position;
1022
+ } else {
1023
+ position++;
1024
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1025
+ }
1026
+ }
1027
+ return result + input.slice(captureStart, end);
1028
+ }
1029
+ function getDoubleQuotedValue(input, start, end) {
1030
+ let result = "";
1031
+ let position = start;
1032
+ let captureStart = start;
1033
+ let captureEnd = start;
1034
+ while (position < end) {
1035
+ const ch = input.charCodeAt(position);
1036
+ if (ch === 92) {
1037
+ result += input.slice(captureStart, position);
1038
+ position++;
1039
+ const escaped = input.charCodeAt(position);
1040
+ if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position;
1041
+ else if (escaped < 256 && simpleEscapeCheck[escaped]) {
1042
+ result += simpleEscapeMap[escaped];
1043
+ position++;
1044
+ } else {
1045
+ let hexLength = escapedHexLen$1(escaped);
1046
+ let hexResult = 0;
1047
+ for (; hexLength > 0; hexLength--) {
1048
+ position++;
1049
+ const digit = fromHexCode$1(input.charCodeAt(position));
1050
+ hexResult = (hexResult << 4) + digit;
1051
+ }
1052
+ result += charFromCodepoint(hexResult);
1053
+ position++;
1054
+ }
1055
+ captureStart = captureEnd = position;
1056
+ } else if (ch === 10 || ch === 13) {
1057
+ result += input.slice(captureStart, captureEnd);
1058
+ const fold = skipFoldedBreaks(input, position, end);
1059
+ result += foldedBreaks(fold.breaks);
1060
+ position = captureStart = captureEnd = fold.position;
1061
+ } else {
1062
+ position++;
1063
+ if (ch !== 32 && ch !== 9) captureEnd = position;
1064
+ }
1065
+ }
1066
+ return result + input.slice(captureStart, end);
1067
+ }
1068
+ function getBlockValue(input, start, end, indent, chomping, folded) {
1069
+ const textIndent = indent < 0 ? 0 : indent;
1070
+ const region = input.slice(start, end).replace(/\r\n?/g, "\n");
1071
+ const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n");
1072
+ let result = "";
1073
+ let didReadContent = false;
1074
+ let emptyLines = 0;
1075
+ let atMoreIndented = false;
1076
+ for (const line of lines) {
1077
+ let column = 0;
1078
+ while (column < textIndent && line.charCodeAt(column) === 32) column++;
1079
+ if (indent < 0 || column >= line.length) {
1080
+ emptyLines++;
1081
+ continue;
1082
+ }
1083
+ const content = line.slice(textIndent);
1084
+ const first = content.charCodeAt(0);
1085
+ if (folded) if (first === 32 || first === 9) {
1086
+ atMoreIndented = true;
1087
+ result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1088
+ } else if (atMoreIndented) {
1089
+ atMoreIndented = false;
1090
+ result += "\n".repeat(emptyLines + 1);
1091
+ } else if (emptyLines === 0) {
1092
+ if (didReadContent) result += " ";
1093
+ } else result += "\n".repeat(emptyLines);
1094
+ else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1095
+ result += content;
1096
+ didReadContent = true;
1097
+ emptyLines = 0;
1098
+ }
1099
+ if (chomping === 3) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1100
+ else if (chomping !== 2) {
1101
+ if (didReadContent) result += "\n";
1102
+ }
1103
+ return result;
1104
+ }
1105
+ function getScalarValue(input, scalar) {
1106
+ if (scalar.valueStart === NO_RANGE$3) return "";
1107
+ const { valueStart, valueEnd } = scalar;
1108
+ if (scalar.fast) return input.slice(valueStart, valueEnd);
1109
+ switch (scalar.style) {
1110
+ case 2: return getSingleQuotedValue(input, valueStart, valueEnd);
1111
+ case 3: return getDoubleQuotedValue(input, valueStart, valueEnd);
1112
+ case 4: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
1113
+ case 5: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
1114
+ default: return getPlainValue(input, valueStart, valueEnd);
1115
+ }
1116
+ }
1117
+ //#endregion
1118
+ //#region src/common/tagname.ts
1119
+ var DEFAULT_TAG_HANDLERS = {
1120
+ "!": "!",
1121
+ "!!": "tag:yaml.org,2002:"
1122
+ };
1123
+ function tagPercentEncode(source) {
1124
+ return encodeURI(source).replace(/!/g, "%21");
1125
+ }
1126
+ function tagNameFull(rawTag, tagHandlers) {
1127
+ if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return decodeURIComponent(rawTag.slice(2, -1));
1128
+ const handleEnd = rawTag.indexOf("!", 1);
1129
+ const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
1130
+ const prefix = tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle;
1131
+ return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length));
1132
+ }
1133
+ function tagNameShort(fullTag) {
1134
+ let tag = fullTag;
1135
+ if (tag.charCodeAt(0) === 33) {
1136
+ tag = tag.slice(1);
1137
+ return `!${tagPercentEncode(tag)}`;
1138
+ }
1139
+ if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18))}`;
1140
+ return `!<${tagPercentEncode(tag)}>`;
1141
+ }
1142
+ //#endregion
1143
+ //#region src/parser/constructor.ts
1144
+ var NO_RANGE$2 = -1;
1145
+ var DEFAULT_CONSTRUCTOR_OPTIONS = {
1146
+ filename: "",
1147
+ schema: CORE_SCHEMA,
1148
+ json: false,
1149
+ maxTotalMergeKeys: 1e4,
1150
+ maxAliases: -1
1151
+ };
1152
+ function eventPosition$1(event) {
1153
+ if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart;
1154
+ if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart;
1155
+ if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart;
1156
+ if ("start" in event) return event.start;
1157
+ return 0;
1158
+ }
1159
+ function throwError$1(state, message) {
1160
+ throwErrorAt(state.source, state.position, message, state.filename);
1161
+ }
1162
+ function finalizeCollection(state, position, tag, carrier) {
1163
+ try {
1164
+ return tag.finalize(carrier);
1165
+ } catch (error) {
1166
+ if (error instanceof YAMLException) throw error;
1167
+ throwErrorAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
1168
+ }
1169
+ }
1170
+ function lookupTag(exact, prefix, tagName) {
1171
+ const exactTag = exact[tagName];
1172
+ if (exactTag) return exactTag;
1173
+ for (const tag of prefix) if (tagName.startsWith(tag.tagName)) return tag;
1174
+ }
1175
+ function findExplicitTag(state, exact, prefix, tagName, nodeKind) {
1176
+ const tag = lookupTag(exact, prefix, tagName);
1177
+ if (tag) return tag;
1178
+ throwError$1(state, `unknown ${nodeKind} tag !<${tagName}>`);
1179
+ }
1180
+ function constructScalar(state, event) {
1181
+ const source = getScalarValue(state.source, event);
1182
+ const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1183
+ const strTag = state.schema.defaultScalarTag;
1184
+ if (rawTag !== "") {
1185
+ if (rawTag === "!") return {
1186
+ value: source,
1187
+ tag: strTag
1188
+ };
1189
+ const tagName = tagNameFull(rawTag, state.tagHandlers);
1190
+ const scalarTag = lookupTag(state.schema.exact.scalar, state.schema.prefix.scalar, tagName);
1191
+ if (scalarTag) {
1192
+ const result = scalarTag.resolve(source, true, tagName);
1193
+ if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1194
+ return {
1195
+ value: result,
1196
+ tag: scalarTag
1197
+ };
1198
+ }
1199
+ const collectionTagDef = lookupTag(state.schema.exact.mapping, state.schema.prefix.mapping, tagName) ?? lookupTag(state.schema.exact.sequence, state.schema.prefix.sequence, tagName);
1200
+ if (collectionTagDef) {
1201
+ if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1202
+ const carrier = collectionTagDef.create(tagName);
1203
+ return {
1204
+ value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier),
1205
+ tag: collectionTagDef
1206
+ };
1207
+ }
1208
+ throwError$1(state, `unknown scalar tag !<${tagName}>`);
1209
+ }
1210
+ if (event.style === 1) {
1211
+ const candidates = state.schema.implicitScalarByFirstChar.get(source.charAt(0)) ?? state.schema.implicitScalarAnyFirstChar;
1212
+ for (const tag of candidates) {
1213
+ const result = tag.resolve(source, false, tag.tagName);
1214
+ if (result !== NOT_RESOLVED) return {
1215
+ value: result,
1216
+ tag
1217
+ };
1218
+ }
1219
+ }
1220
+ return {
1221
+ value: strTag.resolve(source, false, strTag.tagName),
1222
+ tag: strTag
1223
+ };
1224
+ }
1225
+ function collectionTag(state, event, exact, prefix, defaultTagName, nodeKind) {
1226
+ const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1227
+ const tagName = rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
1228
+ return {
1229
+ tagName,
1230
+ tag: findExplicitTag(state, exact, prefix, tagName, nodeKind)
1231
+ };
1232
+ }
1233
+ function isMappingTag(tag) {
1234
+ return tag.nodeKind === "mapping";
1235
+ }
1236
+ function mergeKeys(state, frame, source, sourceTag) {
1237
+ for (const sourceKey of sourceTag.keys(source)) {
1238
+ if (state.maxTotalMergeKeys !== -1 && ++state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
1239
+ if (frame.tag.has(frame.value, sourceKey)) continue;
1240
+ const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
1241
+ if (err) throwError$1(state, err);
1242
+ (frame.overridable ??= /* @__PURE__ */ new Set()).add(sourceKey);
1243
+ }
1244
+ }
1245
+ function mergeSource(state, frame, source, sourceTag) {
1246
+ state.position = frame.keyPosition;
1247
+ if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
1248
+ else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) for (const element of source) mergeKeys(state, frame, element, frame.tag);
1249
+ else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1250
+ }
1251
+ function addMappingValue(state, frame, key, value, tag) {
1252
+ state.position = frame.keyPosition;
1253
+ if (key === MERGE_KEY) {
1254
+ mergeSource(state, frame, value, tag);
1255
+ return;
1256
+ }
1257
+ if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key)) throwError$1(state, "duplicated mapping key");
1258
+ const err = frame.tag.addPair(frame.value, key, value);
1259
+ if (err) throwError$1(state, err);
1260
+ frame.overridable?.delete(key);
1261
+ }
1262
+ function addValue(state, value, tag) {
1263
+ const frame = state.frames[state.frames.length - 1];
1264
+ if (frame.kind === "document") {
1265
+ frame.value = value;
1266
+ frame.hasValue = true;
1267
+ } else if (frame.kind === "sequence") {
1268
+ if (frame.merge) {
1269
+ if (!isMappingTag(tag)) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1270
+ }
1271
+ const err = frame.tag.addItem(frame.value, value, frame.index++);
1272
+ if (err) throwError$1(state, err);
1273
+ } else if (frame.hasKey) {
1274
+ const key = frame.key;
1275
+ frame.key = void 0;
1276
+ frame.hasKey = false;
1277
+ addMappingValue(state, frame, key, value, tag);
1278
+ } else {
1279
+ frame.key = value;
1280
+ frame.keyPosition = state.position;
1281
+ frame.hasKey = true;
1282
+ }
1283
+ }
1284
+ function storeAnchor(state, event, value, tag, isValueFinal) {
1285
+ if (event.anchorStart !== NO_RANGE$2) {
1286
+ const anchor = {
1287
+ value,
1288
+ tag,
1289
+ isValueFinal
1290
+ };
1291
+ state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor);
1292
+ return anchor;
1293
+ }
1294
+ return null;
1295
+ }
1296
+ function constructFromEvents(events, options) {
1297
+ const state = {
1298
+ ...DEFAULT_CONSTRUCTOR_OPTIONS,
1299
+ ...options,
1300
+ events,
1301
+ documents: [],
1302
+ eventIndex: 0,
1303
+ position: 0,
1304
+ frames: [],
1305
+ anchors: /* @__PURE__ */ new Map(),
1306
+ tagHandlers: Object.create(null),
1307
+ totalMergeKeys: 0,
1308
+ aliasCount: 0
1309
+ };
1310
+ while (state.eventIndex < state.events.length) {
1311
+ const event = state.events[state.eventIndex++];
1312
+ state.position = eventPosition$1(event);
1313
+ switch (event.type) {
1314
+ case 1:
1315
+ state.anchors = /* @__PURE__ */ new Map();
1316
+ state.aliasCount = 0;
1317
+ state.tagHandlers = Object.create(null);
1318
+ for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
1319
+ state.frames.push({
1320
+ kind: "document",
1321
+ position: state.position,
1322
+ value: void 0,
1323
+ hasValue: false
1324
+ });
1325
+ break;
1326
+ case 4: {
1327
+ const { value, tag } = constructScalar(state, event);
1328
+ storeAnchor(state, event, value, tag, true);
1329
+ addValue(state, value, tag);
1330
+ break;
1331
+ }
1332
+ case 2: {
1333
+ const definition = collectionTag(state, event, state.schema.exact.sequence, state.schema.prefix.sequence, "tag:yaml.org,2002:seq", "sequence");
1334
+ const value = definition.tag.create(definition.tagName);
1335
+ const anchor = storeAnchor(state, event, value, definition.tag, definition.tag.carrierIsResult);
1336
+ const parent = state.frames[state.frames.length - 1];
1337
+ const merge = parent !== void 0 && parent.kind === "mapping" && parent.hasKey && parent.key === MERGE_KEY;
1338
+ state.frames.push({
1339
+ kind: "sequence",
1340
+ position: state.position,
1341
+ value,
1342
+ tag: definition.tag,
1343
+ anchor,
1344
+ index: 0,
1345
+ merge
1346
+ });
1347
+ break;
1348
+ }
1349
+ case 3: {
1350
+ const definition = collectionTag(state, event, state.schema.exact.mapping, state.schema.prefix.mapping, "tag:yaml.org,2002:map", "mapping");
1351
+ const value = definition.tag.create(definition.tagName);
1352
+ const anchor = storeAnchor(state, event, value, definition.tag, definition.tag.carrierIsResult);
1353
+ state.frames.push({
1354
+ kind: "mapping",
1355
+ position: state.position,
1356
+ value,
1357
+ tag: definition.tag,
1358
+ anchor,
1359
+ key: void 0,
1360
+ keyPosition: state.position,
1361
+ hasKey: false,
1362
+ overridable: null
1363
+ });
1364
+ break;
1365
+ }
1366
+ case 5: {
1367
+ if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
1368
+ const name = state.source.slice(event.anchorStart, event.anchorEnd);
1369
+ const anchor = state.anchors.get(name);
1370
+ if (!anchor) throwError$1(state, `unidentified alias "${name}"`);
1371
+ if (!anchor.isValueFinal) throwError$1(state, `recursive alias "${name}" is not supported for tag ${anchor.tag.tagName} because it uses finalize()`);
1372
+ addValue(state, anchor.value, anchor.tag);
1373
+ break;
1374
+ }
1375
+ case 6: {
1376
+ const frame = state.frames.pop();
1377
+ if (frame.kind === "document") state.documents.push(frame.value);
1378
+ else {
1379
+ const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
1380
+ if (frame.anchor) {
1381
+ frame.anchor.value = value;
1382
+ frame.anchor.isValueFinal = true;
1383
+ }
1384
+ addValue(state, value, frame.tag);
1385
+ }
1386
+ break;
1387
+ }
1388
+ }
1389
+ }
1390
+ return state.documents;
1391
+ }
1392
+ //#endregion
1393
+ //#region src/parser/parser.ts
1394
+ var NO_RANGE$1 = -1;
1395
+ var HAS_OWN = Object.prototype.hasOwnProperty;
1396
+ var CONTEXT_FLOW_IN = 1;
1397
+ var CONTEXT_FLOW_OUT = 2;
1398
+ var CONTEXT_BLOCK_IN = 3;
1399
+ var CONTEXT_BLOCK_OUT = 4;
1400
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1401
+ var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
1402
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
1403
+ var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
1404
+ var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
1405
+ var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
1406
+ var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
1407
+ var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
1408
+ var DEFAULT_PARSER_OPTIONS = {
1409
+ filename: "",
1410
+ maxDepth: 100
1411
+ };
1412
+ function addDocumentEvent(state, explicitStart, explicitEnd) {
1413
+ state.events.push({
1414
+ type: 1,
1415
+ explicitStart,
1416
+ explicitEnd,
1417
+ directives: state.directives
1418
+ });
1419
+ }
1420
+ function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1421
+ state.events.push({
1422
+ type: 2,
1423
+ start,
1424
+ anchorStart,
1425
+ anchorEnd,
1426
+ tagStart,
1427
+ tagEnd,
1428
+ style
1429
+ });
1430
+ }
1431
+ function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1432
+ state.events.push({
1433
+ type: 3,
1434
+ start,
1435
+ anchorStart,
1436
+ anchorEnd,
1437
+ tagStart,
1438
+ tagEnd,
1439
+ style
1440
+ });
1441
+ }
1442
+ function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = 1, indent = -1, fast = false) {
1443
+ state.events.push({
1444
+ type: 4,
1445
+ valueStart,
1446
+ valueEnd,
1447
+ anchorStart,
1448
+ anchorEnd,
1449
+ tagStart,
1450
+ tagEnd,
1451
+ style,
1452
+ chomping,
1453
+ indent,
1454
+ fast
1455
+ });
1456
+ }
1457
+ function addAliasEvent(state, anchorStart, anchorEnd) {
1458
+ state.events.push({
1459
+ type: 5,
1460
+ anchorStart,
1461
+ anchorEnd
1462
+ });
1463
+ }
1464
+ function addPopEvent(state) {
1465
+ state.events.push({ type: 6 });
1466
+ }
1467
+ function addEmptyScalarEvent(state) {
1468
+ addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 1);
1469
+ }
1470
+ function emptyProperties() {
1471
+ return {
1472
+ anchorStart: NO_RANGE$1,
1473
+ anchorEnd: NO_RANGE$1,
1474
+ tagStart: NO_RANGE$1,
1475
+ tagEnd: NO_RANGE$1
1476
+ };
1477
+ }
1478
+ function snapshotState(state) {
1479
+ return {
1480
+ position: state.position,
1481
+ line: state.line,
1482
+ lineStart: state.lineStart,
1483
+ lineIndent: state.lineIndent,
1484
+ firstTabInLine: state.firstTabInLine,
1485
+ eventsLength: state.events.length
1486
+ };
1487
+ }
1488
+ function restoreState(state, snapshot) {
1489
+ state.position = snapshot.position;
1490
+ state.line = snapshot.line;
1491
+ state.lineStart = snapshot.lineStart;
1492
+ state.lineIndent = snapshot.lineIndent;
1493
+ state.firstTabInLine = snapshot.firstTabInLine;
1494
+ state.events.length = snapshot.eventsLength;
1495
+ }
1496
+ function throwError(state, message) {
1497
+ throwErrorAt(state.input.slice(0, state.length), state.position, message, state.filename);
1498
+ }
1499
+ function isEol(c) {
1500
+ return c === 10 || c === 13;
1501
+ }
1502
+ function isWhiteSpace(c) {
1503
+ return c === 9 || c === 32;
1504
+ }
1505
+ function isWsOrEol(c) {
1506
+ return isWhiteSpace(c) || isEol(c);
1507
+ }
1508
+ function isWsOrEolOrEnd(c) {
1509
+ return c === 0 || isWsOrEol(c);
1510
+ }
1511
+ function isFlowIndicator(c) {
1512
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
1513
+ }
1514
+ function fromDecimalCode(c) {
1515
+ return c >= 48 && c <= 57 ? c - 48 : -1;
1516
+ }
1517
+ function fromHexCode(c) {
1518
+ if (c >= 48 && c <= 57) return c - 48;
1519
+ const lc = c | 32;
1520
+ if (lc >= 97 && lc <= 102) return lc - 97 + 10;
1521
+ return -1;
1522
+ }
1523
+ function escapedHexLen(c) {
1524
+ if (c === 120) return 2;
1525
+ if (c === 117) return 4;
1526
+ if (c === 85) return 8;
1527
+ return 0;
1528
+ }
1529
+ function isSimpleEscape(c) {
1530
+ 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;
1531
+ }
1532
+ function consumeLineBreak(state) {
1533
+ if (state.input.charCodeAt(state.position) === 10) state.position++;
1534
+ else {
1535
+ state.position++;
1536
+ if (state.input.charCodeAt(state.position) === 10) state.position++;
1537
+ }
1538
+ state.line++;
1539
+ state.lineStart = state.position;
1540
+ state.lineIndent = 0;
1541
+ state.firstTabInLine = -1;
1542
+ }
1543
+ function skipSeparationSpace(state, allowComments) {
1544
+ let lineBreaks = 0;
1545
+ let ch = state.input.charCodeAt(state.position);
1546
+ let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
1547
+ while (ch !== 0) {
1548
+ while (isWhiteSpace(ch)) {
1549
+ hasSeparation = true;
1550
+ if (ch === 9 && state.firstTabInLine === -1) state.firstTabInLine = state.position;
1551
+ ch = state.input.charCodeAt(++state.position);
1552
+ }
1553
+ if (allowComments && hasSeparation && ch === 35) do
1554
+ ch = state.input.charCodeAt(++state.position);
1555
+ while (!isEol(ch) && ch !== 0);
1556
+ if (!isEol(ch)) break;
1557
+ consumeLineBreak(state);
1558
+ lineBreaks++;
1559
+ hasSeparation = true;
1560
+ ch = state.input.charCodeAt(state.position);
1561
+ while (ch === 32) {
1562
+ state.lineIndent++;
1563
+ ch = state.input.charCodeAt(++state.position);
1564
+ }
1565
+ }
1566
+ return lineBreaks;
1567
+ }
1568
+ function testDocumentSeparator(state, position = state.position) {
1569
+ const ch = state.input.charCodeAt(position);
1570
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
1571
+ const following = state.input.charCodeAt(position + 3);
1572
+ return following === 0 || isWsOrEol(following);
1573
+ }
1574
+ return false;
1575
+ }
1576
+ function skipUntilLineEnd(state) {
1577
+ let ch = state.input.charCodeAt(state.position);
1578
+ while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
1579
+ }
1580
+ function checkPrintable(state, start, end) {
1581
+ if (PATTERN_NON_PRINTABLE.test(state.input.slice(start, end))) throwError(state, "the stream contains non-printable characters");
1582
+ }
1583
+ function readTagProperty(state, props, inFlow) {
1584
+ if (state.input.charCodeAt(state.position) !== 33) return false;
1585
+ if (props.tagStart !== NO_RANGE$1) throwError(state, "duplication of a tag property");
1586
+ const start = state.position;
1587
+ let isVerbatim = false;
1588
+ let isNamed = false;
1589
+ let tagHandle = "!";
1590
+ let ch = state.input.charCodeAt(++state.position);
1591
+ if (ch === 60) {
1592
+ isVerbatim = true;
1593
+ ch = state.input.charCodeAt(++state.position);
1594
+ } else if (ch === 33) {
1595
+ isNamed = true;
1596
+ tagHandle = "!!";
1597
+ ch = state.input.charCodeAt(++state.position);
1598
+ }
1599
+ let suffixStart = state.position;
1600
+ let tagName;
1601
+ if (isVerbatim) {
1602
+ while (ch !== 0 && ch !== 62) ch = state.input.charCodeAt(++state.position);
1603
+ if (ch !== 62) throwError(state, "unexpected end of the stream within a verbatim tag");
1604
+ tagName = state.input.slice(suffixStart, state.position);
1605
+ state.position++;
1606
+ } else {
1607
+ while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
1608
+ if (ch === 33) if (!isNamed) {
1609
+ tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
1610
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
1611
+ isNamed = true;
1612
+ suffixStart = state.position + 1;
1613
+ } else throwError(state, "tag suffix cannot contain exclamation marks");
1614
+ ch = state.input.charCodeAt(++state.position);
1615
+ }
1616
+ tagName = state.input.slice(suffixStart, state.position);
1617
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) throwError(state, "tag suffix cannot contain flow indicator characters");
1618
+ }
1619
+ if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName))) throwError(state, `tag name cannot contain such characters: ${tagName}`);
1620
+ if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle)) throwError(state, `undeclared tag handle "${tagHandle}"`);
1621
+ props.tagStart = start;
1622
+ props.tagEnd = state.position;
1623
+ return true;
1624
+ }
1625
+ function readAnchorProperty(state, props) {
1626
+ if (state.input.charCodeAt(state.position) !== 38) return false;
1627
+ if (props.anchorStart !== NO_RANGE$1) throwError(state, "duplication of an anchor property");
1628
+ state.position++;
1629
+ const start = state.position;
1630
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
1631
+ if (state.position === start) throwError(state, "name of an anchor node must contain at least one character");
1632
+ props.anchorStart = start;
1633
+ props.anchorEnd = state.position;
1634
+ return true;
1635
+ }
1636
+ function readAlias(state, props) {
1637
+ if (state.input.charCodeAt(state.position) !== 42) return false;
1638
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) throwError(state, "alias node should not have any properties");
1639
+ state.position++;
1640
+ const start = state.position;
1641
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
1642
+ if (state.position === start) throwError(state, "name of an alias node must contain at least one character");
1643
+ addAliasEvent(state, start, state.position);
1644
+ return true;
1645
+ }
1646
+ function readFlowScalarBreak(state, nodeIndent) {
1647
+ skipSeparationSpace(state, false);
1648
+ if (state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
1649
+ }
1650
+ function readSingleQuotedScalar(state, nodeIndent, props) {
1651
+ if (state.input.charCodeAt(state.position) !== 39) return false;
1652
+ state.position++;
1653
+ const start = state.position;
1654
+ let simple = true;
1655
+ while (state.input.charCodeAt(state.position) !== 0) {
1656
+ const ch = state.input.charCodeAt(state.position);
1657
+ if (ch === 39) {
1658
+ if (state.input.charCodeAt(state.position + 1) === 39) {
1659
+ simple = false;
1660
+ state.position += 2;
1661
+ continue;
1662
+ }
1663
+ const end = state.position;
1664
+ state.position++;
1665
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2, 1, -1, simple);
1666
+ return true;
1667
+ }
1668
+ if (isEol(ch)) {
1669
+ simple = false;
1670
+ readFlowScalarBreak(state, nodeIndent);
1671
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a single quoted scalar");
1672
+ else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
1673
+ else state.position++;
1674
+ }
1675
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
1676
+ }
1677
+ function readDoubleQuotedScalar(state, nodeIndent, props) {
1678
+ if (state.input.charCodeAt(state.position) !== 34) return false;
1679
+ state.position++;
1680
+ const start = state.position;
1681
+ let simple = true;
1682
+ while (state.input.charCodeAt(state.position) !== 0) {
1683
+ const ch = state.input.charCodeAt(state.position);
1684
+ if (ch === 34) {
1685
+ const end = state.position;
1686
+ state.position++;
1687
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 3, 1, -1, simple);
1688
+ return true;
1689
+ }
1690
+ if (ch === 92) {
1691
+ simple = false;
1692
+ const escaped = state.input.charCodeAt(++state.position);
1693
+ if (isEol(escaped)) readFlowScalarBreak(state, nodeIndent);
1694
+ else if (isSimpleEscape(escaped)) state.position++;
1695
+ else {
1696
+ let hexLength = escapedHexLen(escaped);
1697
+ if (hexLength === 0) throwError(state, "unknown escape sequence");
1698
+ while (hexLength-- > 0) {
1699
+ state.position++;
1700
+ if (fromHexCode(state.input.charCodeAt(state.position)) < 0) throwError(state, "expected hexadecimal character");
1701
+ }
1702
+ state.position++;
1703
+ }
1704
+ } else if (isEol(ch)) {
1705
+ simple = false;
1706
+ readFlowScalarBreak(state, nodeIndent);
1707
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a double quoted scalar");
1708
+ else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
1709
+ else state.position++;
1710
+ }
1711
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
1712
+ }
1713
+ function readBlockScalar(state, parentIndent, props) {
1714
+ const ch = state.input.charCodeAt(state.position);
1715
+ let chomping = 1;
1716
+ let indent = -1;
1717
+ let detectedIndent = false;
1718
+ if (ch !== 124 && ch !== 62) return false;
1719
+ const style = ch === 124 ? 4 : 5;
1720
+ state.position++;
1721
+ while (state.input.charCodeAt(state.position) !== 0) {
1722
+ const current = state.input.charCodeAt(state.position);
1723
+ const digit = fromDecimalCode(current);
1724
+ if (current === 43 || current === 45) {
1725
+ if (chomping !== 1) throwError(state, "repeat of a chomping mode identifier");
1726
+ chomping = current === 43 ? 3 : 2;
1727
+ state.position++;
1728
+ } else if (digit >= 0) {
1729
+ if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1730
+ if (detectedIndent) throwError(state, "repeat of an indentation width identifier");
1731
+ indent = parentIndent + digit - 1;
1732
+ detectedIndent = true;
1733
+ state.position++;
1734
+ } else break;
1735
+ }
1736
+ let hadWhitespace = false;
1737
+ while (isWhiteSpace(state.input.charCodeAt(state.position))) {
1738
+ hadWhitespace = true;
1739
+ state.position++;
1740
+ }
1741
+ if (hadWhitespace && state.input.charCodeAt(state.position) === 35) skipUntilLineEnd(state);
1742
+ if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
1743
+ else if (state.input.charCodeAt(state.position) !== 0) throwError(state, "a line break is expected");
1744
+ let contentIndent = detectedIndent ? indent : -1;
1745
+ let maxLeadingIndent = 0;
1746
+ const valueStart = state.position;
1747
+ let valueEnd = state.position;
1748
+ while (state.input.charCodeAt(state.position) !== 0) {
1749
+ const linePosition = state.position;
1750
+ let column = 0;
1751
+ while (state.input.charCodeAt(linePosition + column) === 32) column++;
1752
+ const first = state.input.charCodeAt(linePosition + column);
1753
+ if (first === 0) {
1754
+ if (contentIndent >= 0) {
1755
+ if (column > contentIndent) valueEnd = linePosition + column;
1756
+ } else if (column > 0) valueEnd = linePosition + column;
1757
+ break;
1758
+ }
1759
+ if (linePosition === state.lineStart && testDocumentSeparator(state, linePosition)) break;
1760
+ if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
1761
+ if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
1762
+ if (first === 9 && column < parentIndent) {
1763
+ state.position = linePosition + column;
1764
+ throwError(state, "tab characters must not be used in indentation");
1765
+ }
1766
+ if (column < maxLeadingIndent) {
1767
+ state.position = linePosition + column;
1768
+ throwError(state, "bad indentation of a mapping entry");
1769
+ }
1770
+ }
1771
+ if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
1772
+ state.lineIndent = column;
1773
+ state.position = linePosition + column;
1774
+ break;
1775
+ }
1776
+ if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1) contentIndent = column;
1777
+ const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
1778
+ if (first !== 0 && !isEol(first) && column < requiredIndent) {
1779
+ state.lineIndent = column;
1780
+ state.position = linePosition + column;
1781
+ break;
1782
+ }
1783
+ skipUntilLineEnd(state);
1784
+ valueEnd = state.position;
1785
+ if (isEol(state.input.charCodeAt(state.position))) {
1786
+ consumeLineBreak(state);
1787
+ valueEnd = state.position;
1788
+ }
1789
+ }
1790
+ checkPrintable(state, valueStart, valueEnd);
1791
+ addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
1792
+ return true;
1793
+ }
1794
+ function canStartPlainScalar(state, nodeContext) {
1795
+ const ch = state.input.charCodeAt(state.position);
1796
+ const inFlow = nodeContext === CONTEXT_FLOW_IN;
1797
+ 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 || inFlow && isFlowIndicator(ch)) return false;
1798
+ if (ch === 63 || ch === 45) {
1799
+ const following = state.input.charCodeAt(state.position + 1);
1800
+ if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
1801
+ }
1802
+ return true;
1803
+ }
1804
+ function readPlainScalar(state, nodeIndent, nodeContext, props) {
1805
+ if (!canStartPlainScalar(state, nodeContext)) return false;
1806
+ const start = state.position;
1807
+ let end = state.position;
1808
+ let ch = state.input.charCodeAt(state.position);
1809
+ const inFlow = nodeContext === CONTEXT_FLOW_IN;
1810
+ let multiline = false;
1811
+ while (ch !== 0) {
1812
+ if (state.position === state.lineStart && testDocumentSeparator(state)) break;
1813
+ if (ch === 58) {
1814
+ const following = state.input.charCodeAt(state.position + 1);
1815
+ if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
1816
+ } else if (ch === 35) {
1817
+ if (isWsOrEol(state.input.charCodeAt(state.position - 1))) break;
1818
+ } else if (inFlow && isFlowIndicator(ch)) break;
1819
+ else if (isEol(ch)) {
1820
+ const savedPosition = state.position;
1821
+ const savedLine = state.line;
1822
+ const savedLineStart = state.lineStart;
1823
+ const savedLineIndent = state.lineIndent;
1824
+ skipSeparationSpace(state, false);
1825
+ if (state.lineIndent >= nodeIndent) {
1826
+ multiline = true;
1827
+ ch = state.input.charCodeAt(state.position);
1828
+ continue;
1829
+ }
1830
+ state.position = savedPosition;
1831
+ state.line = savedLine;
1832
+ state.lineStart = savedLineStart;
1833
+ state.lineIndent = savedLineIndent;
1834
+ break;
1835
+ }
1836
+ if (!isWhiteSpace(ch)) end = state.position + 1;
1837
+ ch = state.input.charCodeAt(++state.position);
1838
+ }
1839
+ if (end === start) return false;
1840
+ checkPrintable(state, start, end);
1841
+ addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1, 1, -1, !multiline);
1842
+ return true;
1843
+ }
1844
+ function skipFlowSeparationSpace(state, nodeIndent) {
1845
+ const startLine = state.line;
1846
+ skipSeparationSpace(state, true);
1847
+ if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
1848
+ }
1849
+ function readFlowCollection(state, nodeIndent, props) {
1850
+ const ch = state.input.charCodeAt(state.position);
1851
+ const isMapping = ch === 123;
1852
+ const start = state.position;
1853
+ let readNext = true;
1854
+ if (ch !== 91 && ch !== 123) return false;
1855
+ const terminator = isMapping ? 125 : 93;
1856
+ if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2);
1857
+ else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2);
1858
+ state.position++;
1859
+ while (state.input.charCodeAt(state.position) !== 0) {
1860
+ skipFlowSeparationSpace(state, nodeIndent);
1861
+ let ch = state.input.charCodeAt(state.position);
1862
+ if (ch === terminator) {
1863
+ state.position++;
1864
+ addPopEvent(state);
1865
+ return true;
1866
+ } else if (!readNext) throwError(state, "missed comma between flow collection entries");
1867
+ else if (ch === 44) throwError(state, "expected the node content, but found ','");
1868
+ let isPair = false;
1869
+ let isExplicitPair = false;
1870
+ if (ch === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
1871
+ isPair = isExplicitPair = true;
1872
+ state.position += 1;
1873
+ skipFlowSeparationSpace(state, nodeIndent);
1874
+ }
1875
+ const entryLine = state.line;
1876
+ const entryStart = snapshotState(state);
1877
+ const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1878
+ skipFlowSeparationSpace(state, nodeIndent);
1879
+ ch = state.input.charCodeAt(state.position);
1880
+ if ((isMapping || isExplicitPair || state.line === entryLine) && ch === 58) {
1881
+ isPair = true;
1882
+ state.position++;
1883
+ skipFlowSeparationSpace(state, nodeIndent);
1884
+ if (!isMapping) {
1885
+ restoreState(state, entryStart);
1886
+ addMappingEvent(state, entryStart.position, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 2);
1887
+ if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
1888
+ skipFlowSeparationSpace(state, nodeIndent);
1889
+ state.position++;
1890
+ skipFlowSeparationSpace(state, nodeIndent);
1891
+ } else if (!keyWasRead) addEmptyScalarEvent(state);
1892
+ if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
1893
+ skipFlowSeparationSpace(state, nodeIndent);
1894
+ if (!isMapping) addPopEvent(state);
1895
+ } else if (isMapping && isPair) {
1896
+ if (!keyWasRead) addEmptyScalarEvent(state);
1897
+ addEmptyScalarEvent(state);
1898
+ } else if (isMapping) addEmptyScalarEvent(state);
1899
+ else if (isPair) {
1900
+ restoreState(state, entryStart);
1901
+ addMappingEvent(state, entryStart.position, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 2);
1902
+ parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1903
+ addEmptyScalarEvent(state);
1904
+ addPopEvent(state);
1905
+ }
1906
+ ch = state.input.charCodeAt(state.position);
1907
+ if (ch === 44) {
1908
+ readNext = true;
1909
+ state.position++;
1910
+ } else readNext = false;
1911
+ }
1912
+ throwError(state, "unexpected end of the stream within a flow collection");
1913
+ }
1914
+ function readBlockSequence(state, nodeIndent, props) {
1915
+ if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
1916
+ addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
1917
+ while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
1918
+ if (state.firstTabInLine !== -1) {
1919
+ state.position = state.firstTabInLine;
1920
+ throwError(state, "tab characters must not be used in indentation");
1921
+ }
1922
+ const entryLine = state.line;
1923
+ state.position++;
1924
+ const hadBreak = skipSeparationSpace(state, true) > 0;
1925
+ 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");
1926
+ if (hadBreak && state.lineIndent <= nodeIndent) addEmptyScalarEvent(state);
1927
+ else parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
1928
+ skipSeparationSpace(state, true);
1929
+ if (state.lineIndent < nodeIndent || state.position >= state.length) break;
1930
+ if (state.lineIndent > nodeIndent) throwError(state, "bad indentation of a sequence entry");
1931
+ 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");
1932
+ }
1933
+ addPopEvent(state);
1934
+ return true;
1935
+ }
1936
+ function readBlockMapping(state, nodeIndent, flowIndent, props) {
1937
+ let atExplicitKey = false;
1938
+ let detected = false;
1939
+ let mappingOpened = false;
1940
+ let pendingExplicitKey = false;
1941
+ if (state.firstTabInLine !== -1) return false;
1942
+ let ch = state.input.charCodeAt(state.position);
1943
+ while (ch !== 0) {
1944
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
1945
+ state.position = state.firstTabInLine;
1946
+ throwError(state, "tab characters must not be used in indentation");
1947
+ }
1948
+ const following = state.input.charCodeAt(state.position + 1);
1949
+ const entryLine = state.line;
1950
+ if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
1951
+ if (!mappingOpened) {
1952
+ addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
1953
+ mappingOpened = true;
1954
+ }
1955
+ if (ch === 63) {
1956
+ if (atExplicitKey) addEmptyScalarEvent(state);
1957
+ detected = true;
1958
+ atExplicitKey = true;
1959
+ } else if (atExplicitKey) atExplicitKey = false;
1960
+ else {
1961
+ addEmptyScalarEvent(state);
1962
+ detected = true;
1963
+ atExplicitKey = false;
1964
+ }
1965
+ state.position += 1;
1966
+ pendingExplicitKey = true;
1967
+ } else {
1968
+ if (atExplicitKey) {
1969
+ addEmptyScalarEvent(state);
1970
+ atExplicitKey = false;
1971
+ }
1972
+ const beforeKey = snapshotState(state);
1973
+ if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) break;
1974
+ if (state.line === entryLine) {
1975
+ ch = state.input.charCodeAt(state.position);
1976
+ while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
1977
+ if (ch === 58) {
1978
+ ch = state.input.charCodeAt(++state.position);
1979
+ if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
1980
+ if (!mappingOpened) {
1981
+ restoreState(state, beforeKey);
1982
+ addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
1983
+ mappingOpened = true;
1984
+ parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true);
1985
+ ch = state.input.charCodeAt(state.position);
1986
+ while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
1987
+ state.position++;
1988
+ }
1989
+ detected = true;
1990
+ atExplicitKey = false;
1991
+ pendingExplicitKey = false;
1992
+ } else if (detected) throwError(state, "expected ':' after a mapping key");
1993
+ else {
1994
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
1995
+ restoreState(state, beforeKey);
1996
+ return false;
1997
+ }
1998
+ return true;
1999
+ }
2000
+ } else if (detected) throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
2001
+ else {
2002
+ if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
2003
+ restoreState(state, beforeKey);
2004
+ return false;
2005
+ }
2006
+ return true;
2007
+ }
2008
+ }
2009
+ if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey)) pendingExplicitKey = false;
2010
+ if (!atExplicitKey) {
2011
+ if (pendingExplicitKey) {
2012
+ addEmptyScalarEvent(state);
2013
+ pendingExplicitKey = false;
2014
+ }
2015
+ }
2016
+ skipSeparationSpace(state, true);
2017
+ ch = state.input.charCodeAt(state.position);
2018
+ if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0) throwError(state, "bad indentation of a mapping entry");
2019
+ else if (state.lineIndent < nodeIndent) break;
2020
+ }
2021
+ if (!detected) return false;
2022
+ if (atExplicitKey) addEmptyScalarEvent(state);
2023
+ if (mappingOpened) addPopEvent(state);
2024
+ return true;
2025
+ }
2026
+ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
2027
+ if (state.depth >= state.maxDepth) throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
2028
+ state.depth++;
2029
+ let indentStatus = 1;
2030
+ let atNewLine = false;
2031
+ let hasContent = false;
2032
+ let propertyStart = null;
2033
+ const props = emptyProperties();
2034
+ let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
2035
+ let allowBlockCollections = allowBlockScalars;
2036
+ const allowBlockStyles = allowBlockScalars;
2037
+ if (allowToSeek && skipSeparationSpace(state, true)) {
2038
+ atNewLine = true;
2039
+ if (state.lineIndent > parentIndent) indentStatus = 1;
2040
+ else if (state.lineIndent === parentIndent) indentStatus = 0;
2041
+ else indentStatus = -1;
2042
+ }
2043
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
2044
+ state.depth--;
2045
+ return false;
2046
+ }
2047
+ if (indentStatus === 1) while (true) {
2048
+ const ch = state.input.charCodeAt(state.position);
2049
+ const propertyState = snapshotState(state);
2050
+ if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38)) break;
2051
+ if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
2052
+ const fallbackState = snapshotState(state);
2053
+ const flowIndent = parentIndent + 1;
2054
+ if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === 3) {
2055
+ state.depth--;
2056
+ return true;
2057
+ }
2058
+ restoreState(state, fallbackState);
2059
+ }
2060
+ if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1)) break;
2061
+ if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props)) break;
2062
+ if (propertyStart === null) propertyStart = propertyState;
2063
+ if (skipSeparationSpace(state, true)) {
2064
+ atNewLine = true;
2065
+ allowBlockCollections = allowBlockStyles;
2066
+ if (state.lineIndent > parentIndent) indentStatus = 1;
2067
+ else if (state.lineIndent === parentIndent) indentStatus = 0;
2068
+ else indentStatus = -1;
2069
+ } else allowBlockCollections = false;
2070
+ }
2071
+ if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
2072
+ if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
2073
+ const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
2074
+ const blockIndent = state.position - state.lineStart;
2075
+ if (indentStatus === 1) if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
2076
+ else {
2077
+ const ch = state.input.charCodeAt(state.position);
2078
+ if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
2079
+ const fallbackState = snapshotState(state);
2080
+ const propertyIndent = propertyStart.position - propertyStart.lineStart;
2081
+ restoreState(state, propertyStart);
2082
+ if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === 3) hasContent = true;
2083
+ else restoreState(state, fallbackState);
2084
+ }
2085
+ 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;
2086
+ }
2087
+ else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
2088
+ }
2089
+ allowBlockScalars = allowBlockScalars && !hasContent;
2090
+ if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
2091
+ addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
2092
+ hasContent = true;
2093
+ }
2094
+ state.depth--;
2095
+ return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
2096
+ }
2097
+ function readDirective(state) {
2098
+ if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37) return false;
2099
+ state.position++;
2100
+ const nameStart = state.position;
2101
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2102
+ const name = state.input.slice(nameStart, state.position);
2103
+ const args = [];
2104
+ if (name.length === 0) throwError(state, "directive name must not be less than one character in length");
2105
+ while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
2106
+ while (isWhiteSpace(state.input.charCodeAt(state.position))) state.position++;
2107
+ if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0) break;
2108
+ const start = state.position;
2109
+ while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2110
+ args.push(state.input.slice(start, state.position));
2111
+ }
2112
+ if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
2113
+ if (name === "YAML") {
2114
+ if (state.directives.some((directive) => directive.kind === "yaml")) throwError(state, "duplication of %YAML directive");
2115
+ if (args.length !== 1) throwError(state, "YAML directive accepts exactly one argument");
2116
+ const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
2117
+ if (match === null) throwError(state, "ill-formed argument of the YAML directive");
2118
+ if (parseInt(match[1], 10) !== 1) throwError(state, "unacceptable YAML version of the document");
2119
+ state.directives.push({
2120
+ kind: "yaml",
2121
+ version: args[0]
2122
+ });
2123
+ } else if (name === "TAG") {
2124
+ if (args.length !== 2) throwError(state, "TAG directive accepts exactly two arguments");
2125
+ const [handle, prefix] = args;
2126
+ if (!PATTERN_TAG_HANDLE.test(handle)) throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
2127
+ if (HAS_OWN.call(state.tagHandlers, handle)) throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
2128
+ if (!PATTERN_TAG_PREFIX.test(prefix)) throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
2129
+ state.tagHandlers[handle] = prefix;
2130
+ state.directives.push({
2131
+ kind: "tag",
2132
+ handle,
2133
+ prefix
2134
+ });
2135
+ }
2136
+ return true;
2137
+ }
2138
+ function readDocument(state) {
2139
+ state.directives = [];
2140
+ state.tagHandlers = Object.create(null);
2141
+ let hasDirectives = false;
2142
+ skipSeparationSpace(state, true);
2143
+ while (readDirective(state)) {
2144
+ hasDirectives = true;
2145
+ skipSeparationSpace(state, true);
2146
+ }
2147
+ let explicitStart = false;
2148
+ let explicitEnd = false;
2149
+ let allowCompact = true;
2150
+ 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))) {
2151
+ explicitStart = true;
2152
+ const markerLine = state.line;
2153
+ state.position += 3;
2154
+ skipSeparationSpace(state, true);
2155
+ allowCompact = state.line > markerLine;
2156
+ } else if (hasDirectives) throwError(state, "directives end mark is expected");
2157
+ const documentEventIndex = state.events.length;
2158
+ if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
2159
+ state.position += 3;
2160
+ skipSeparationSpace(state, true);
2161
+ return;
2162
+ }
2163
+ addDocumentEvent(state, explicitStart, false);
2164
+ if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact)) addEmptyScalarEvent(state);
2165
+ skipSeparationSpace(state, true);
2166
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
2167
+ explicitEnd = state.input.charCodeAt(state.position) === 46;
2168
+ if (explicitEnd) {
2169
+ const markerLine = state.line;
2170
+ state.position += 3;
2171
+ skipSeparationSpace(state, true);
2172
+ if (state.line === markerLine && state.position < state.length) throwError(state, "end of the stream or a document separator is expected");
2173
+ }
2174
+ }
2175
+ const documentEvent = state.events[documentEventIndex];
2176
+ if (documentEvent?.type === 1) documentEvent.explicitEnd = explicitEnd;
2177
+ addPopEvent(state);
2178
+ if (!explicitEnd && state.position < state.length && !(state.position === state.lineStart && testDocumentSeparator(state))) throwError(state, "end of the stream or a document separator is expected");
2179
+ }
2180
+ function parseEvents(input, options) {
2181
+ const length = input.length;
2182
+ const state = {
2183
+ ...DEFAULT_PARSER_OPTIONS,
2184
+ ...options,
2185
+ input: `${input}\0`,
2186
+ length,
2187
+ position: 0,
2188
+ line: 0,
2189
+ lineStart: 0,
2190
+ lineIndent: 0,
2191
+ firstTabInLine: -1,
2192
+ depth: 0,
2193
+ directives: [],
2194
+ tagHandlers: Object.create(null),
2195
+ events: []
2196
+ };
2197
+ const nullpos = input.indexOf("\0");
2198
+ if (nullpos !== -1) throwErrorAt(input, nullpos, "null byte is not allowed in input", state.filename);
2199
+ if (state.input.charCodeAt(state.position) === 65279) state.position++;
2200
+ while (state.position < state.length) {
2201
+ skipSeparationSpace(state, true);
2202
+ if (state.position >= state.length) break;
2203
+ const documentStart = state.position;
2204
+ readDocument(state);
2205
+ if (state.position === documentStart)
2206
+ /* c8 ignore next */
2207
+ throwError(state, "can not read a document");
2208
+ }
2209
+ return state.events;
2210
+ }
2211
+ //#endregion
2212
+ //#region src/load.ts
2213
+ var DEFAULT_LOAD_OPTIONS = {
2214
+ ...DEFAULT_PARSER_OPTIONS,
2215
+ ...DEFAULT_CONSTRUCTOR_OPTIONS
2216
+ };
2217
+ function loadDocuments(input, options = {}) {
2218
+ const opts = {
2219
+ ...DEFAULT_LOAD_OPTIONS,
2220
+ ...options
2221
+ };
2222
+ const source = String(input);
2223
+ const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
2224
+ const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
2225
+ return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
2226
+ ...pick(opts, CONSTRUCTOR_OPT_KEYS),
2227
+ source
2228
+ });
2229
+ }
2230
+ function loadAll(input, iteratorOrOptions, options) {
2231
+ let iterator = null;
2232
+ if (typeof iteratorOrOptions === "function") iterator = iteratorOrOptions;
2233
+ else if (iteratorOrOptions !== null && typeof iteratorOrOptions === "object") options = iteratorOrOptions;
2234
+ const documents = loadDocuments(input, options);
2235
+ if (iterator === null) return documents;
2236
+ for (const document of documents) iterator(document);
2237
+ }
2238
+ function load(input, options) {
2239
+ const documents = loadDocuments(input, options);
2240
+ if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
2241
+ if (documents.length === 1) return documents[0];
2242
+ throw new YAMLException("expected a single document in the stream, but found more");
2243
+ }
2244
+ //#endregion
2245
+ //#region src/ast/nodes.ts
2246
+ var Style = class {
2247
+ tagged = false;
2248
+ flow = false;
2249
+ singleQuoted = false;
2250
+ doubleQuoted = false;
2251
+ literal = false;
2252
+ folded = false;
2253
+ };
2254
+ //#endregion
2255
+ //#region src/ast/from_js.ts
2256
+ var INVALID = Symbol("INVALID");
2257
+ function buildRepresentTypes(schema) {
2258
+ const defaultTags = new Set([
2259
+ schema.defaultScalarTag,
2260
+ schema.defaultSequenceTag,
2261
+ schema.defaultMappingTag
2262
+ ].filter((t) => t !== void 0));
2263
+ const implicitScalars = schema.implicitScalarTags;
2264
+ const explicitTags = schema.tags.filter((t) => !(t.nodeKind === "scalar" && t.implicit) && !defaultTags.has(t));
2265
+ const defaultTagsLast = schema.tags.filter((t) => defaultTags.has(t));
2266
+ return [
2267
+ ...implicitScalars.map((tag) => ({
2268
+ tag,
2269
+ implicitTag: true
2270
+ })),
2271
+ ...explicitTags.map((tag) => ({
2272
+ tag,
2273
+ implicitTag: false
2274
+ })),
2275
+ ...defaultTagsLast.map((tag) => ({
2276
+ tag,
2277
+ implicitTag: true
2278
+ }))
2279
+ ];
2280
+ }
2281
+ function matchTag(state, object) {
2282
+ for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
2283
+ const { tag, implicitTag } = state.representTypes[index];
2284
+ if (tag.identify && tag.identify(object)) {
2285
+ let tagName;
2286
+ if (tag.matchByTagPrefix && tag.representTagName) tagName = tag.representTagName(object);
2287
+ else tagName = tag.tagName;
2288
+ return {
2289
+ tag,
2290
+ tagName,
2291
+ implicitTag
2292
+ };
2293
+ }
2294
+ }
2295
+ return null;
2296
+ }
2297
+ function build(state, object) {
2298
+ if (!state.noRefs && object !== null && typeof object === "object") {
2299
+ const existing = state.refs.get(object);
2300
+ if (existing) {
2301
+ if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
2302
+ return {
2303
+ kind: "alias",
2304
+ tag: "",
2305
+ style: new Style(),
2306
+ anchor: existing.anchor
2307
+ };
2308
+ }
2309
+ }
2310
+ const matched = matchTag(state, object);
2311
+ if (!matched) {
2312
+ if (object === void 0) return INVALID;
2313
+ if (state.skipInvalid) return INVALID;
2314
+ throw new YAMLException(`unacceptable kind of an object to dump ${Object.prototype.toString.call(object)}`);
2315
+ }
2316
+ const { tag, tagName, implicitTag } = matched;
2317
+ const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
2318
+ if (tag.nodeKind === "scalar") {
2319
+ const style = new Style();
2320
+ style.tagged = !implicitTag;
2321
+ return {
2322
+ kind: "scalar",
2323
+ tag: nodeTagName,
2324
+ style,
2325
+ value: tag.represent(object)
2326
+ };
2327
+ }
2328
+ if (tag.nodeKind === "sequence") {
2329
+ const container = tag.represent(object);
2330
+ const style = new Style();
2331
+ style.tagged = !implicitTag;
2332
+ const node = {
2333
+ kind: "sequence",
2334
+ tag: nodeTagName,
2335
+ style,
2336
+ items: []
2337
+ };
2338
+ if (!state.noRefs) state.refs.set(object, node);
2339
+ for (let index = 0, length = container.length; index < length; index += 1) {
2340
+ let item = build(state, container[index]);
2341
+ if (item === INVALID && container[index] === void 0) item = build(state, null);
2342
+ if (item === INVALID) continue;
2343
+ node.items.push(item);
2344
+ }
2345
+ return node;
2346
+ }
2347
+ const map = tag.represent(object);
2348
+ const style = new Style();
2349
+ style.tagged = !implicitTag;
2350
+ const node = {
2351
+ kind: "mapping",
2352
+ tag: nodeTagName,
2353
+ style,
2354
+ items: []
2355
+ };
2356
+ if (!state.noRefs) state.refs.set(object, node);
2357
+ for (const [objectKey, objectValue] of map) {
2358
+ const key = build(state, objectKey);
2359
+ if (key === INVALID) continue;
2360
+ const value = build(state, objectValue);
2361
+ if (value === INVALID) continue;
2362
+ node.items.push({
2363
+ key,
2364
+ value
2365
+ });
2366
+ }
2367
+ return node;
2368
+ }
2369
+ function jsToAst(input, schema, options = {}) {
2370
+ const root = build({
2371
+ representTypes: buildRepresentTypes(schema),
2372
+ noRefs: options.noRefs ?? false,
2373
+ skipInvalid: options.skipInvalid ?? false,
2374
+ refs: /* @__PURE__ */ new Map(),
2375
+ refCounter: 0
2376
+ }, input);
2377
+ return [{
2378
+ contents: root === INVALID ? null : root,
2379
+ directives: []
2380
+ }];
2381
+ }
2382
+ //#endregion
2383
+ //#region src/ast/visit.ts
2384
+ var VISIT_BREAK = Symbol("visit:break");
2385
+ var VISIT_SKIP = Symbol("visit:skip");
2386
+ function visitNode(node, visitor, ctx) {
2387
+ const control = visitor(node, ctx);
2388
+ if (control === VISIT_BREAK) return true;
2389
+ if (control === VISIT_SKIP) return false;
2390
+ const depth = ctx.depth + 1;
2391
+ switch (node.kind) {
2392
+ case "sequence":
2393
+ for (const item of node.items) if (visitNode(item, visitor, {
2394
+ depth,
2395
+ parent: node,
2396
+ isKey: false
2397
+ })) return true;
2398
+ break;
2399
+ case "mapping":
2400
+ for (const { key, value } of node.items) {
2401
+ if (visitNode(key, visitor, {
2402
+ depth,
2403
+ parent: node,
2404
+ isKey: true
2405
+ })) return true;
2406
+ if (visitNode(value, visitor, {
2407
+ depth,
2408
+ parent: node,
2409
+ isKey: false
2410
+ })) return true;
2411
+ }
2412
+ break;
2413
+ }
2414
+ return false;
2415
+ }
2416
+ function visit(documents, visitor) {
2417
+ for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
2418
+ depth: 0,
2419
+ parent: null,
2420
+ isKey: false
2421
+ })) return;
2422
+ }
2423
+ //#endregion
2424
+ //#region src/ast/presenter.ts
2425
+ var CHAR_BOM = 65279;
2426
+ var CHAR_TAB = 9;
2427
+ var CHAR_LINE_FEED = 10;
2428
+ var CHAR_CARRIAGE_RETURN = 13;
2429
+ var CHAR_SPACE = 32;
2430
+ var CHAR_EXCLAMATION = 33;
2431
+ var CHAR_DOUBLE_QUOTE = 34;
2432
+ var CHAR_SHARP = 35;
2433
+ var CHAR_PERCENT = 37;
2434
+ var CHAR_AMPERSAND = 38;
2435
+ var CHAR_SINGLE_QUOTE = 39;
2436
+ var CHAR_ASTERISK = 42;
2437
+ var CHAR_COMMA = 44;
2438
+ var CHAR_MINUS = 45;
2439
+ var CHAR_COLON = 58;
2440
+ var CHAR_EQUALS = 61;
2441
+ var CHAR_GREATER_THAN = 62;
2442
+ var CHAR_QUESTION = 63;
2443
+ var CHAR_COMMERCIAL_AT = 64;
2444
+ var CHAR_LEFT_SQUARE_BRACKET = 91;
2445
+ var CHAR_RIGHT_SQUARE_BRACKET = 93;
2446
+ var CHAR_GRAVE_ACCENT = 96;
2447
+ var CHAR_LEFT_CURLY_BRACKET = 123;
2448
+ var CHAR_VERTICAL_LINE = 124;
2449
+ var CHAR_RIGHT_CURLY_BRACKET = 125;
2450
+ var ESCAPE_SEQUENCES = {};
2451
+ ESCAPE_SEQUENCES[0] = "\\0";
2452
+ ESCAPE_SEQUENCES[7] = "\\a";
2453
+ ESCAPE_SEQUENCES[8] = "\\b";
2454
+ ESCAPE_SEQUENCES[9] = "\\t";
2455
+ ESCAPE_SEQUENCES[10] = "\\n";
2456
+ ESCAPE_SEQUENCES[11] = "\\v";
2457
+ ESCAPE_SEQUENCES[12] = "\\f";
2458
+ ESCAPE_SEQUENCES[13] = "\\r";
2459
+ ESCAPE_SEQUENCES[27] = "\\e";
2460
+ ESCAPE_SEQUENCES[34] = "\\\"";
2461
+ ESCAPE_SEQUENCES[92] = "\\\\";
2462
+ ESCAPE_SEQUENCES[133] = "\\N";
2463
+ ESCAPE_SEQUENCES[160] = "\\_";
2464
+ ESCAPE_SEQUENCES[8232] = "\\L";
2465
+ ESCAPE_SEQUENCES[8233] = "\\P";
2466
+ var DEFAULT_PRESENTER_OPTIONS = {
2467
+ indent: 2,
2468
+ seqNoIndent: false,
2469
+ seqInlineFirst: true,
2470
+ sortKeys: false,
2471
+ lineWidth: 80,
2472
+ flowBracketPadding: false,
2473
+ flowSkipCommaSpace: false,
2474
+ flowSkipColonSpace: false,
2475
+ quoteFlowKeys: false,
2476
+ quoteStyle: "single",
2477
+ forceQuotes: false,
2478
+ tagBeforeAnchor: false
2479
+ };
2480
+ function nodeTagShort(node) {
2481
+ return node.style.tagged ? node.tag : tagNameShort(node.tag);
2482
+ }
2483
+ function createPresenterState(options) {
2484
+ const opts = {
2485
+ ...DEFAULT_PRESENTER_OPTIONS,
2486
+ ...options
2487
+ };
2488
+ return {
2489
+ ...opts,
2490
+ defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
2491
+ implicitResolvers: opts.schema.implicitScalarTags
2492
+ };
2493
+ }
2494
+ function encodeNonPrintable(character) {
2495
+ const string = character.toString(16).toUpperCase();
2496
+ const handle = character <= 255 ? "x" : "u";
2497
+ const length = character <= 255 ? 2 : 4;
2498
+ return `\\${handle}${"0".repeat(length - string.length)}${string}`;
2499
+ }
2500
+ function indentString(string, spaces) {
2501
+ const ind = " ".repeat(spaces);
2502
+ let position = 0;
2503
+ let result = "";
2504
+ const length = string.length;
2505
+ while (position < length) {
2506
+ let line;
2507
+ const next = string.indexOf("\n", position);
2508
+ if (next === -1) {
2509
+ line = string.slice(position);
2510
+ position = length;
2511
+ } else {
2512
+ line = string.slice(position, next + 1);
2513
+ position = next + 1;
2514
+ }
2515
+ if (line.length && line !== "\n") result += ind;
2516
+ result += line;
2517
+ }
2518
+ return result;
2519
+ }
2520
+ function generateNextLine(state, level) {
2521
+ return `\n${" ".repeat(state.indent * level)}`;
2522
+ }
2523
+ function scalarLayout(state, level) {
2524
+ const indent = state.indent * Math.max(1, level);
2525
+ return {
2526
+ indent,
2527
+ blockIndent: level === 0 ? state.indent + 1 : state.indent,
2528
+ lineWidth: state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent)
2529
+ };
2530
+ }
2531
+ function resolveImplicitTag(state, str) {
2532
+ for (let index = 0, length = state.implicitResolvers.length; index < length; index += 1) {
2533
+ const tagDefinition = state.implicitResolvers[index];
2534
+ if (tagDefinition.resolve(str, false, tagDefinition.tagName) !== NOT_RESOLVED) return tagDefinition.tagName;
2535
+ }
2536
+ return state.defaultScalarTagName;
2537
+ }
2538
+ function isWhitespace(c) {
2539
+ return c === CHAR_SPACE || c === CHAR_TAB;
2540
+ }
2541
+ function startsWithDocumentSeparator(string) {
2542
+ const marker = string.charCodeAt(0);
2543
+ if (marker !== CHAR_MINUS && marker !== 46 || string.charCodeAt(1) !== marker || string.charCodeAt(2) !== marker) return false;
2544
+ if (string.length === 3) return true;
2545
+ const following = string.charCodeAt(3);
2546
+ return isWhitespace(following) || following === CHAR_CARRIAGE_RETURN || following === CHAR_LINE_FEED;
2547
+ }
2548
+ function isPrintable(c) {
2549
+ return c >= 32 && c <= 126 || c >= 161 && c <= 55295 && c !== 8232 && c !== 8233 || c >= 57344 && c <= 65533 && c !== CHAR_BOM || c >= 65536 && c <= 1114111;
2550
+ }
2551
+ function isNsCharOrWhitespace(c) {
2552
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
2553
+ }
2554
+ function isPlainSafe(c, prev, inblock) {
2555
+ const cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
2556
+ const cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
2557
+ return (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar;
2558
+ }
2559
+ function isPlainSafeFirst(c) {
2560
+ return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
2561
+ }
2562
+ function isPlainSafeAtStart(string, inblock) {
2563
+ const first = codePointAt(string, 0);
2564
+ if (isPlainSafeFirst(first)) return true;
2565
+ if (string.length > 1 && (first === CHAR_MINUS || first === CHAR_QUESTION || first === CHAR_COLON)) {
2566
+ const second = codePointAt(string, 1);
2567
+ return !isWhitespace(second) && isPlainSafe(second, first, inblock);
2568
+ }
2569
+ return false;
2570
+ }
2571
+ function isPlainSafeLast(c) {
2572
+ return !isWhitespace(c) && c !== CHAR_COLON;
2573
+ }
2574
+ function codePointAt(string, pos) {
2575
+ const first = string.charCodeAt(pos);
2576
+ let second;
2577
+ if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
2578
+ second = string.charCodeAt(pos + 1);
2579
+ if (second >= 56320 && second <= 57343) return (first - 55296) * 1024 + second - 56320 + 65536;
2580
+ }
2581
+ return first;
2582
+ }
2583
+ function needIndentIndicator(string) {
2584
+ return /^\n* /.test(string);
2585
+ }
2586
+ var STYLE_PLAIN = 1;
2587
+ var STYLE_SINGLE = 2;
2588
+ var STYLE_LITERAL = 3;
2589
+ var STYLE_FOLDED = 4;
2590
+ var STYLE_DOUBLE = 5;
2591
+ function chooseScalarStyle(state, string, layout, singleLineOnly, forceQuote, inblock) {
2592
+ const { blockIndent, lineWidth } = layout;
2593
+ let i;
2594
+ let char = 0;
2595
+ let prevChar = -1;
2596
+ let hasLineBreak = false;
2597
+ let hasFoldableLine = false;
2598
+ const shouldTrackWidth = lineWidth !== -1;
2599
+ let previousLineBreak = -1;
2600
+ let plain = !startsWithDocumentSeparator(string) && isPlainSafeAtStart(string, inblock) && isPlainSafeLast(codePointAt(string, string.length - 1));
2601
+ if (singleLineOnly || forceQuote) for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2602
+ char = codePointAt(string, i);
2603
+ if (!isPrintable(char)) return STYLE_DOUBLE;
2604
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2605
+ prevChar = char;
2606
+ }
2607
+ else {
2608
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2609
+ char = codePointAt(string, i);
2610
+ if (char === CHAR_LINE_FEED) {
2611
+ hasLineBreak = true;
2612
+ if (shouldTrackWidth) {
2613
+ hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2614
+ previousLineBreak = i;
2615
+ }
2616
+ } else if (!isPrintable(char)) return STYLE_DOUBLE;
2617
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2618
+ prevChar = char;
2619
+ }
2620
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2621
+ }
2622
+ if (!hasLineBreak && !hasFoldableLine) {
2623
+ if (plain && !forceQuote) return STYLE_PLAIN;
2624
+ return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
2625
+ }
2626
+ if (blockIndent > 9 && needIndentIndicator(string)) return STYLE_DOUBLE;
2627
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
2628
+ }
2629
+ function renderScalarStyle(string, style, layout) {
2630
+ const { indent, blockIndent, lineWidth } = layout;
2631
+ switch (style) {
2632
+ case STYLE_PLAIN: return encodeFlowBreaks(string, indent);
2633
+ case STYLE_SINGLE: return `'${encodeFlowBreaks(string, indent).replace(/'/g, "''")}'`;
2634
+ case STYLE_LITERAL: return "|" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(string, indent));
2635
+ case STYLE_FOLDED: return ">" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(foldBlockScalar(string, lineWidth), indent));
2636
+ case STYLE_DOUBLE: return `"${escapeString(string)}"`;
2637
+ }
2638
+ }
2639
+ function resolveScalarStyle(state, node, layout, iskey, inblock) {
2640
+ const singleLineOnly = iskey || !inblock;
2641
+ if (node.style.singleQuoted) return STYLE_SINGLE;
2642
+ if (node.style.doubleQuoted) return STYLE_DOUBLE;
2643
+ if (!singleLineOnly) {
2644
+ if (node.style.literal) return STYLE_LITERAL;
2645
+ if (node.style.folded) return STYLE_FOLDED;
2646
+ }
2647
+ const string = node.value;
2648
+ if (string.length === 0) {
2649
+ if (node.style.tagged || resolveImplicitTag(state, string) === node.tag) return STYLE_PLAIN;
2650
+ return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
2651
+ }
2652
+ const style = chooseScalarStyle(state, string, layout, singleLineOnly, state.forceQuotes && !iskey, inblock);
2653
+ if (style === STYLE_PLAIN && !node.style.tagged && resolveImplicitTag(state, string) !== node.tag) return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
2654
+ return style;
2655
+ }
2656
+ function blockHeader(string, indentPerLevel) {
2657
+ const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
2658
+ const clip = string[string.length - 1] === "\n";
2659
+ return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
2660
+ }
2661
+ function encodeFlowBreaks(string, indent) {
2662
+ let nextLF = string.indexOf("\n");
2663
+ if (nextLF === -1) return string;
2664
+ const pad = " ".repeat(indent);
2665
+ let result = string.slice(0, nextLF);
2666
+ const lineRe = /(\n+)([^\n]*)/g;
2667
+ lineRe.lastIndex = nextLF;
2668
+ let match;
2669
+ while (match = lineRe.exec(string)) {
2670
+ const breaks = match[1].length;
2671
+ const line = match[2];
2672
+ result += "\n".repeat(breaks + 1) + pad + line;
2673
+ }
2674
+ return result;
2675
+ }
2676
+ function dropEndingNewline(string) {
2677
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2678
+ }
2679
+ function foldBlockScalar(string, width) {
2680
+ const lineRe = /(\n+)([^\n]*)/g;
2681
+ let nextLF = string.indexOf("\n");
2682
+ if (nextLF === -1) nextLF = string.length;
2683
+ lineRe.lastIndex = nextLF;
2684
+ let result = foldLine(string.slice(0, nextLF), width);
2685
+ let prevMoreIndented = string[0] === "\n" || string[0] === " ";
2686
+ let moreIndented;
2687
+ let match;
2688
+ while (match = lineRe.exec(string)) {
2689
+ const prefix = match[1];
2690
+ const line = match[2];
2691
+ moreIndented = line[0] === " ";
2692
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2693
+ prevMoreIndented = moreIndented;
2694
+ }
2695
+ return result;
2696
+ }
2697
+ function foldLine(line, width) {
2698
+ if (line === "" || line[0] === " ") return line;
2699
+ const breakRe = / [^ ]/g;
2700
+ let match;
2701
+ let start = 0;
2702
+ let end;
2703
+ let curr = 0;
2704
+ let next = 0;
2705
+ let result = "";
2706
+ while (match = breakRe.exec(line)) {
2707
+ next = match.index;
2708
+ if (next - start > width) {
2709
+ end = curr > start ? curr : next;
2710
+ result += `\n${line.slice(start, end)}`;
2711
+ start = end + 1;
2712
+ }
2713
+ curr = next;
2714
+ }
2715
+ result += "\n";
2716
+ if (line.length - start > width && curr > start) result += `${line.slice(start, curr)}\n${line.slice(curr + 1)}`;
2717
+ else result += line.slice(start);
2718
+ return result.slice(1);
2719
+ }
2720
+ function escapeString(string) {
2721
+ let result = "";
2722
+ let char = 0;
2723
+ for (let i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2724
+ char = codePointAt(string, i);
2725
+ const escapeSeq = ESCAPE_SEQUENCES[char];
2726
+ if (escapeSeq) {
2727
+ result += escapeSeq;
2728
+ continue;
2729
+ }
2730
+ if (isPrintable(char)) {
2731
+ result += string[i];
2732
+ if (char >= 65536) result += string[i + 1];
2733
+ continue;
2734
+ }
2735
+ result += encodeNonPrintable(char);
2736
+ }
2737
+ return result;
2738
+ }
2739
+ function writeFlowSequence(state, level, node) {
2740
+ let result = "";
2741
+ for (let index = 0, length = node.items.length; index < length; index += 1) {
2742
+ const item = writeNode(state, level, node.items[index], {});
2743
+ if (result !== "") result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
2744
+ result += item;
2745
+ }
2746
+ const pad = state.flowBracketPadding && result !== "" ? " " : "";
2747
+ return `[${pad}${result}${pad}]`;
2748
+ }
2749
+ function writeBlockSequence(state, level, node, compact) {
2750
+ let result = "";
2751
+ for (let index = 0, length = node.items.length; index < length; index += 1) {
2752
+ const item = writeNode(state, level + 1, node.items[index], {
2753
+ block: true,
2754
+ compact: state.seqInlineFirst,
2755
+ isblockseq: true
2756
+ });
2757
+ if (!compact || result !== "") result += generateNextLine(state, level);
2758
+ if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
2759
+ else result += "- ";
2760
+ result += item;
2761
+ }
2762
+ return result;
2763
+ }
2764
+ function writeFlowMapping(state, level, node) {
2765
+ let result = "";
2766
+ const items = sortMappingItems(state, node.items);
2767
+ for (const { key, value } of items) {
2768
+ let pairBuffer = "";
2769
+ if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
2770
+ const keyText = writeNode(state, level, key, { iskey: true });
2771
+ const explicitPair = keyText.length > 1024;
2772
+ if (explicitPair) pairBuffer += "? ";
2773
+ else if (state.quoteFlowKeys) pairBuffer += "\"";
2774
+ const valueText = writeNode(state, level, value, {});
2775
+ const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
2776
+ pairBuffer += `${keyText}${state.quoteFlowKeys && !explicitPair ? "\"" : ""}:${sep}${valueText}`;
2777
+ result += pairBuffer;
2778
+ }
2779
+ const pad = state.flowBracketPadding && result !== "" ? " " : "";
2780
+ return `{${pad}${result}${pad}}`;
2781
+ }
2782
+ function sortKeyValue(key) {
2783
+ return key.kind === "scalar" ? key.value : key;
2784
+ }
2785
+ function sortMappingItems(state, items) {
2786
+ if (!state.sortKeys) return items;
2787
+ const copy = items.slice();
2788
+ if (state.sortKeys === true) copy.sort((a, b) => {
2789
+ const x = sortKeyValue(a.key);
2790
+ const y = sortKeyValue(b.key);
2791
+ if (x < y) return -1;
2792
+ if (x > y) return 1;
2793
+ return 0;
2794
+ });
2795
+ else {
2796
+ const fn = state.sortKeys;
2797
+ copy.sort((a, b) => fn(sortKeyValue(a.key), sortKeyValue(b.key)));
2798
+ }
2799
+ return copy;
2800
+ }
2801
+ function writeBlockMapping(state, level, node, compact) {
2802
+ let result = "";
2803
+ const items = sortMappingItems(state, node.items);
2804
+ for (let index = 0, length = items.length; index < length; index += 1) {
2805
+ let pairBuffer = "";
2806
+ if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
2807
+ const { key, value } = items[index];
2808
+ const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && !key.style.flow && key.items.length !== 0 || key.kind === "scalar" && (key.style.literal || key.style.folded);
2809
+ const keyText = keyIsBlock ? writeNode(state, level + 1, key, {
2810
+ block: true,
2811
+ compact: true,
2812
+ isblockseq: !cannotBeCompact(state, key, level + 1)
2813
+ }) : writeNode(state, level + 1, key, {
2814
+ block: true,
2815
+ compact: true,
2816
+ iskey: true
2817
+ });
2818
+ const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
2819
+ const explicitPair = keyIsBlock || keyHasLineBreak || keyText.length > 1024;
2820
+ if (explicitPair) if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
2821
+ else pairBuffer += "? ";
2822
+ pairBuffer += keyText;
2823
+ if (explicitPair) pairBuffer += generateNextLine(state, level);
2824
+ const valueText = writeNode(state, level + 1, value, {
2825
+ block: true,
2826
+ compact: explicitPair,
2827
+ isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
2828
+ });
2829
+ const keyIsBareProps = key.kind === "scalar" && key.value === "" && keyText !== "" && keyText.charCodeAt(keyText.length - 1) !== CHAR_SINGLE_QUOTE && keyText.charCodeAt(keyText.length - 1) !== CHAR_DOUBLE_QUOTE;
2830
+ const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
2831
+ if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
2832
+ else pairBuffer += `${keyColonSep}: `;
2833
+ pairBuffer += valueText;
2834
+ result += pairBuffer;
2835
+ }
2836
+ return result;
2837
+ }
2838
+ function cannotBeCompact(state, node, level) {
2839
+ return node.style.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
2840
+ }
2841
+ function writeNode(state, level, node, ctx) {
2842
+ if (node.kind === "alias") return `*${node.anchor}`;
2843
+ const { block = false, iskey = false, isblockseq = false } = ctx;
2844
+ let compact = ctx.compact ?? false;
2845
+ const hasAnchor = node.anchor !== void 0;
2846
+ if (cannotBeCompact(state, node, level)) compact = false;
2847
+ let body;
2848
+ let shouldPrintTag = node.style.tagged;
2849
+ const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && !node.style.flow && node.items.length !== 0;
2850
+ if (node.kind === "mapping") if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
2851
+ else body = writeFlowMapping(state, level, node);
2852
+ else if (node.kind === "sequence") if (useBlockCollection) if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
2853
+ else body = writeBlockSequence(state, level, node, compact);
2854
+ else body = writeFlowSequence(state, level, node);
2855
+ else {
2856
+ const layout = scalarLayout(state, level);
2857
+ const style = resolveScalarStyle(state, node, layout, iskey, block);
2858
+ body = renderScalarStyle(node.value, style, layout);
2859
+ shouldPrintTag = node.style.tagged || style !== STYLE_PLAIN && node.tag !== state.defaultScalarTagName;
2860
+ }
2861
+ if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
2862
+ if (shouldPrintTag || hasAnchor) {
2863
+ const props = [];
2864
+ const tag = shouldPrintTag ? nodeTagShort(node) : null;
2865
+ const anchor = hasAnchor ? `&${node.anchor}` : null;
2866
+ if (state.tagBeforeAnchor) {
2867
+ if (tag !== null) props.push(tag);
2868
+ if (anchor !== null) props.push(anchor);
2869
+ } else {
2870
+ if (anchor !== null) props.push(anchor);
2871
+ if (tag !== null) props.push(tag);
2872
+ }
2873
+ const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
2874
+ body = `${props.join(" ")}${sep}${body}`;
2875
+ }
2876
+ return body;
2877
+ }
2878
+ function rootStartsOwnLine(node) {
2879
+ return (node.kind === "sequence" || node.kind === "mapping") && !node.style.flow && node.items.length !== 0 && !node.style.tagged && node.anchor === void 0;
2880
+ }
2881
+ function isOpenEnded(node) {
2882
+ let leaf = node;
2883
+ while ((leaf.kind === "sequence" || leaf.kind === "mapping") && !leaf.style.flow && leaf.items.length !== 0) leaf = leaf.kind === "sequence" ? leaf.items[leaf.items.length - 1] : leaf.items[leaf.items.length - 1].value;
2884
+ if (leaf.kind !== "scalar" || !(leaf.style.literal || leaf.style.folded)) return false;
2885
+ const { value } = leaf;
2886
+ return value.endsWith("\n\n") || value === "\n";
2887
+ }
2888
+ function writeDocumentDirectives(doc) {
2889
+ let result = "";
2890
+ for (const directive of doc.directives) {
2891
+ if (directive.kind === "yaml") {
2892
+ result += `%YAML ${directive.version}\n`;
2893
+ continue;
2894
+ }
2895
+ const { handle, prefix } = directive;
2896
+ result += `%TAG ${handle} ${prefix}\n`;
2897
+ }
2898
+ return result;
2899
+ }
2900
+ function present(documents, options) {
2901
+ const state = createPresenterState(options);
2902
+ let result = "";
2903
+ let previousEnded = false;
2904
+ for (let index = 0; index < documents.length; index += 1) {
2905
+ const doc = documents[index];
2906
+ const directives = writeDocumentDirectives(doc);
2907
+ const hasDirectives = directives !== "";
2908
+ const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
2909
+ result += directives;
2910
+ if (doc.contents === null) {
2911
+ if (marker) result += "---\n";
2912
+ } else if (marker) {
2913
+ const body = writeNode(state, 0, doc.contents, {
2914
+ block: true,
2915
+ compact: true
2916
+ });
2917
+ const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
2918
+ result += `---${sep}${body}\n`;
2919
+ } else result += writeNode(state, 0, doc.contents, {
2920
+ block: true,
2921
+ compact: true
2922
+ }) + "\n";
2923
+ previousEnded = doc.explicitEnd || doc.contents !== null && isOpenEnded(doc.contents);
2924
+ if (previousEnded) result += "...\n";
2925
+ }
2926
+ return result;
2927
+ }
2928
+ //#endregion
2929
+ //#region src/dump.ts
2930
+ var DEFAULT_DUMP_SCHEMA = YAML11_SCHEMA.withTags({
2931
+ ...intYaml11Tag,
2932
+ resolve: (source, isExplicit, tagName) => {
2933
+ const result = intYaml11Tag.resolve(source, isExplicit, tagName);
2934
+ return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
2935
+ }
2936
+ }, {
2937
+ ...floatYaml11Tag,
2938
+ resolve: (source, isExplicit, tagName) => {
2939
+ const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
2940
+ return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
2941
+ }
2942
+ });
2943
+ var DEFAULT_DUMP_OPTIONS = {
2944
+ ...DEFAULT_PRESENTER_OPTIONS,
2945
+ schema: DEFAULT_DUMP_SCHEMA,
2946
+ skipInvalid: false,
2947
+ noRefs: false,
2948
+ flowLevel: -1,
2949
+ transform: () => {}
2950
+ };
2951
+ function dump(input, options = {}) {
2952
+ const opts = {
2953
+ ...DEFAULT_DUMP_OPTIONS,
2954
+ ...options
2955
+ };
2956
+ const documents = jsToAst(input, opts.schema, {
2957
+ noRefs: opts.noRefs,
2958
+ skipInvalid: opts.skipInvalid
2959
+ });
2960
+ if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
2961
+ if (ctx.depth < opts.flowLevel) return;
2962
+ node.style.flow = true;
2963
+ return VISIT_SKIP;
2964
+ });
2965
+ opts.transform(documents);
2966
+ return present(documents, {
2967
+ ...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
2968
+ schema: opts.schema
2969
+ });
2970
+ }
2971
+ //#endregion
2972
+ //#region src/ast/from_events.ts
2973
+ var NO_RANGE = -1;
2974
+ function eventPosition(event) {
2975
+ if ("tagStart" in event && event.tagStart !== NO_RANGE) return event.tagStart;
2976
+ if ("anchorStart" in event && event.anchorStart !== NO_RANGE) return event.anchorStart;
2977
+ if ("valueStart" in event && event.valueStart !== NO_RANGE) return event.valueStart;
2978
+ if ("start" in event) return event.start;
2979
+ return 0;
2980
+ }
2981
+ function rawTag(state, event) {
2982
+ return event.tagStart === NO_RANGE ? "" : state.source.slice(event.tagStart, event.tagEnd);
2983
+ }
2984
+ function anchorName(state, event) {
2985
+ return event.anchorStart === NO_RANGE ? void 0 : state.source.slice(event.anchorStart, event.anchorEnd);
2986
+ }
2987
+ function implicitScalarTagName(state, source) {
2988
+ const { schema } = state;
2989
+ const candidates = schema.implicitScalarByFirstChar.get(source.charAt(0)) ?? schema.implicitScalarAnyFirstChar;
2990
+ for (const tag of candidates) if (tag.resolve(source, false, tag.tagName) !== NOT_RESOLVED) return tag.tagName;
2991
+ return schema.defaultScalarTag.tagName;
2992
+ }
2993
+ function buildScalar(state, event) {
2994
+ const value = getScalarValue(state.source, event);
2995
+ const raw = rawTag(state, event);
2996
+ const style = new Style();
2997
+ switch (event.style) {
2998
+ case 2:
2999
+ style.singleQuoted = true;
3000
+ break;
3001
+ case 3:
3002
+ style.doubleQuoted = true;
3003
+ break;
3004
+ case 4:
3005
+ style.literal = true;
3006
+ break;
3007
+ case 5:
3008
+ style.folded = true;
3009
+ break;
3010
+ }
3011
+ let tag;
3012
+ if (raw !== "") {
3013
+ style.tagged = true;
3014
+ tag = raw;
3015
+ } else if (event.style === 1) tag = implicitScalarTagName(state, value);
3016
+ else tag = state.schema.defaultScalarTag.tagName;
3017
+ return {
3018
+ kind: "scalar",
3019
+ tag,
3020
+ style,
3021
+ anchor: anchorName(state, event),
3022
+ value
3023
+ };
3024
+ }
3025
+ function buildCollection(state, event, defaultTagName) {
3026
+ const raw = rawTag(state, event);
3027
+ const style = new Style();
3028
+ if (event.style === 2) style.flow = true;
3029
+ let tag;
3030
+ if (raw === "") tag = defaultTagName;
3031
+ else {
3032
+ tag = raw;
3033
+ style.tagged = true;
3034
+ }
3035
+ return {
3036
+ tag,
3037
+ style,
3038
+ anchor: anchorName(state, event)
3039
+ };
3040
+ }
3041
+ function addNode(state, node) {
3042
+ const frame = state.frames[state.frames.length - 1];
3043
+ if (frame.kind === "document") frame.doc.contents = node;
3044
+ else if (frame.kind === "sequence") frame.node.items.push(node);
3045
+ else if (frame.key) {
3046
+ frame.node.items.push({
3047
+ key: frame.key,
3048
+ value: node
3049
+ });
3050
+ frame.key = null;
3051
+ } else frame.key = node;
3052
+ }
3053
+ function eventsToAst(events, options) {
3054
+ const state = {
3055
+ source: options.source,
3056
+ schema: options.schema,
3057
+ eventIndex: 0,
3058
+ position: 0,
3059
+ frames: [],
3060
+ documents: []
3061
+ };
3062
+ while (state.eventIndex < events.length) {
3063
+ const event = events[state.eventIndex++];
3064
+ state.position = eventPosition(event);
3065
+ switch (event.type) {
3066
+ case 1: {
3067
+ const doc = {
3068
+ contents: null,
3069
+ explicitStart: event.explicitStart,
3070
+ explicitEnd: event.explicitEnd,
3071
+ directives: event.directives
3072
+ };
3073
+ state.frames.push({
3074
+ kind: "document",
3075
+ doc
3076
+ });
3077
+ break;
3078
+ }
3079
+ case 4:
3080
+ addNode(state, buildScalar(state, event));
3081
+ break;
3082
+ case 2: {
3083
+ const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
3084
+ const node = {
3085
+ kind: "sequence",
3086
+ tag,
3087
+ style,
3088
+ anchor,
3089
+ items: []
3090
+ };
3091
+ state.frames.push({
3092
+ kind: "sequence",
3093
+ node
3094
+ });
3095
+ break;
3096
+ }
3097
+ case 3: {
3098
+ const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
3099
+ const node = {
3100
+ kind: "mapping",
3101
+ tag,
3102
+ style,
3103
+ anchor,
3104
+ items: []
3105
+ };
3106
+ state.frames.push({
3107
+ kind: "mapping",
3108
+ node,
3109
+ key: null
3110
+ });
3111
+ break;
3112
+ }
3113
+ case 5: {
3114
+ const name = state.source.slice(event.anchorStart, event.anchorEnd);
3115
+ addNode(state, {
3116
+ kind: "alias",
3117
+ tag: "",
3118
+ style: new Style(),
3119
+ anchor: name
3120
+ });
3121
+ break;
3122
+ }
3123
+ case 6: {
3124
+ const frame = state.frames.pop();
3125
+ if (frame.kind === "document") state.documents.push(frame.doc);
3126
+ else addNode(state, frame.node);
3127
+ break;
3128
+ }
3129
+ }
3130
+ }
3131
+ return state.documents;
3132
+ }
3133
+ //#endregion
3134
+ export { CHOMPING_CLIP, CHOMPING_KEEP, CHOMPING_STRIP, COLLECTION_STYLE_BLOCK, COLLECTION_STYLE_FLOW, CORE_SCHEMA, EVENT_ALIAS, EVENT_DOCUMENT, EVENT_MAPPING, EVENT_POP, EVENT_SCALAR, EVENT_SEQUENCE, FAILSAFE_SCHEMA, JSON_SCHEMA, MERGE_KEY, NOT_RESOLVED, SCALAR_STYLE_DOUBLE_QUOTED, SCALAR_STYLE_FOLDED_BLOCK, SCALAR_STYLE_LITERAL_BLOCK, SCALAR_STYLE_PLAIN, SCALAR_STYLE_SINGLE_QUOTED, Schema, Style, 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 };
3135
+
3136
+ //# sourceMappingURL=js-yaml.mjs.map