@lumpcode/core 0.0.6 → 0.0.7

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