@midscene/web 0.11.0 → 0.11.1-beta-20250211002541.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/appium.js CHANGED
@@ -336,18 +336,2925 @@ module.exports = __toCommonJS(appium_exports);
336
336
  // src/common/agent.ts
337
337
  var import_core2 = require("@midscene/core");
338
338
  var import_constants2 = require("@midscene/shared/constants");
339
+
340
+ // src/yaml/player.ts
341
+ var import_node_assert = __toESM(require("assert"));
342
+ var import_node_fs = require("fs");
343
+ var import_node_path = require("path");
344
+ var ScriptPlayer = class {
345
+ constructor(script, setupAgent, onTaskStatusChange) {
346
+ this.script = script;
347
+ this.setupAgent = setupAgent;
348
+ this.onTaskStatusChange = onTaskStatusChange;
349
+ this.taskStatusList = [];
350
+ this.status = "init";
351
+ this.unnamedResultIndex = 0;
352
+ this.pageAgent = null;
353
+ var _a;
354
+ this.result = {};
355
+ this.output = (_a = script.target) == null ? void 0 : _a.output;
356
+ this.taskStatusList = (script.tasks || []).map((task, taskIndex) => {
357
+ var _a2;
358
+ return {
359
+ ...task,
360
+ index: taskIndex,
361
+ status: "init",
362
+ totalSteps: ((_a2 = task.flow) == null ? void 0 : _a2.length) || 0
363
+ };
364
+ });
365
+ }
366
+ setPlayerStatus(status, error) {
367
+ this.status = status;
368
+ this.errorInSetup = error;
369
+ }
370
+ notifyCurrentTaskStatusChange(taskIndex) {
371
+ const taskIndexToNotify = typeof taskIndex === "number" ? taskIndex : this.currentTaskIndex;
372
+ if (typeof taskIndexToNotify !== "number") {
373
+ return;
374
+ }
375
+ const taskStatus = this.taskStatusList[taskIndexToNotify];
376
+ if (this.onTaskStatusChange) {
377
+ this.onTaskStatusChange(taskStatus);
378
+ }
379
+ }
380
+ async setTaskStatus(index, statusValue, error) {
381
+ this.taskStatusList[index].status = statusValue;
382
+ if (error) {
383
+ this.taskStatusList[index].error = error;
384
+ }
385
+ this.notifyCurrentTaskStatusChange(index);
386
+ }
387
+ setTaskIndex(taskIndex) {
388
+ this.currentTaskIndex = taskIndex;
389
+ }
390
+ flushResult() {
391
+ if (Object.keys(this.result).length && this.output) {
392
+ const output = (0, import_node_path.join)(process.cwd(), this.output);
393
+ const outputDir = (0, import_node_path.dirname)(output);
394
+ if (!(0, import_node_fs.existsSync)(outputDir)) {
395
+ (0, import_node_fs.mkdirSync)(outputDir, { recursive: true });
396
+ }
397
+ (0, import_node_fs.writeFileSync)(output, JSON.stringify(this.result, void 0, 2));
398
+ }
399
+ }
400
+ async playTask(taskStatus, agent) {
401
+ const { flow } = taskStatus;
402
+ (0, import_node_assert.default)(flow, "missing flow in task");
403
+ for (const flowItemIndex in flow) {
404
+ const currentStep = Number.parseInt(flowItemIndex, 10);
405
+ taskStatus.currentStep = currentStep;
406
+ const flowItem = flow[flowItemIndex];
407
+ if (flowItem.aiAction || flowItem.ai) {
408
+ const actionTask = flowItem;
409
+ const prompt = actionTask.aiAction || actionTask.ai;
410
+ (0, import_node_assert.default)(prompt, "missing prompt for ai (aiAction)");
411
+ (0, import_node_assert.default)(
412
+ typeof prompt === "string",
413
+ "prompt for aiAction must be a string"
414
+ );
415
+ await agent.aiAction(prompt);
416
+ } else if (flowItem.aiAssert) {
417
+ const assertTask = flowItem;
418
+ const prompt = assertTask.aiAssert;
419
+ (0, import_node_assert.default)(prompt, "missing prompt for aiAssert");
420
+ (0, import_node_assert.default)(
421
+ typeof prompt === "string",
422
+ "prompt for aiAssert must be a string"
423
+ );
424
+ await agent.aiAssert(prompt);
425
+ } else if (flowItem.aiQuery) {
426
+ const queryTask = flowItem;
427
+ const prompt = queryTask.aiQuery;
428
+ (0, import_node_assert.default)(prompt, "missing prompt for aiQuery");
429
+ (0, import_node_assert.default)(
430
+ typeof prompt === "string",
431
+ "prompt for aiQuery must be a string"
432
+ );
433
+ const queryResult = await agent.aiQuery(prompt);
434
+ const resultKey = queryTask.name || this.unnamedResultIndex++;
435
+ if (this.result[resultKey]) {
436
+ console.warn(
437
+ `result key ${resultKey} already exists, will overwrite`
438
+ );
439
+ }
440
+ this.result[resultKey] = queryResult;
441
+ this.flushResult();
442
+ } else if (flowItem.aiWaitFor) {
443
+ const waitForTask = flowItem;
444
+ const prompt = waitForTask.aiWaitFor;
445
+ (0, import_node_assert.default)(prompt, "missing prompt for aiWaitFor");
446
+ (0, import_node_assert.default)(
447
+ typeof prompt === "string",
448
+ "prompt for aiWaitFor must be a string"
449
+ );
450
+ const timeout = waitForTask.timeout;
451
+ await agent.aiWaitFor(prompt, { timeoutMs: timeout });
452
+ } else if (flowItem.sleep) {
453
+ const sleepTask = flowItem;
454
+ const ms = sleepTask.sleep;
455
+ (0, import_node_assert.default)(
456
+ ms && ms > 0,
457
+ `ms for sleep must be greater than 0, but got ${ms}`
458
+ );
459
+ await new Promise((resolve) => setTimeout(resolve, ms));
460
+ } else {
461
+ throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
462
+ }
463
+ }
464
+ this.reportFile = agent.reportFile;
465
+ }
466
+ async run() {
467
+ const { target, tasks } = this.script;
468
+ this.setPlayerStatus("running");
469
+ let agent = null;
470
+ let freeFn = [];
471
+ try {
472
+ const { agent: newAgent, freeFn: newFreeFn } = await this.setupAgent(target);
473
+ agent = newAgent;
474
+ freeFn = newFreeFn;
475
+ } catch (e) {
476
+ this.setPlayerStatus("error", e);
477
+ return;
478
+ }
479
+ this.pageAgent = agent;
480
+ let taskIndex = 0;
481
+ this.setPlayerStatus("running");
482
+ let errorFlag = false;
483
+ while (taskIndex < tasks.length) {
484
+ const taskStatus = this.taskStatusList[taskIndex];
485
+ this.setTaskStatus(taskIndex, "running");
486
+ this.setTaskIndex(taskIndex);
487
+ try {
488
+ await this.playTask(taskStatus, this.pageAgent);
489
+ this.setTaskStatus(taskIndex, "done");
490
+ } catch (e) {
491
+ this.setTaskStatus(taskIndex, "error", e);
492
+ if (taskStatus.continueOnError) {
493
+ } else {
494
+ this.reportFile = agent.reportFile;
495
+ errorFlag = true;
496
+ break;
497
+ }
498
+ }
499
+ this.reportFile = agent.reportFile;
500
+ taskIndex++;
501
+ }
502
+ if (errorFlag) {
503
+ this.setPlayerStatus("error");
504
+ } else {
505
+ this.setPlayerStatus("done");
506
+ }
507
+ for (const fn of freeFn) {
508
+ try {
509
+ await fn.fn();
510
+ } catch (e) {
511
+ }
512
+ }
513
+ }
514
+ };
515
+
516
+ // ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/dist/js-yaml.mjs
517
+ function isNothing(subject) {
518
+ return typeof subject === "undefined" || subject === null;
519
+ }
520
+ function isObject(subject) {
521
+ return typeof subject === "object" && subject !== null;
522
+ }
523
+ function toArray(sequence) {
524
+ if (Array.isArray(sequence))
525
+ return sequence;
526
+ else if (isNothing(sequence))
527
+ return [];
528
+ return [sequence];
529
+ }
530
+ function extend(target, source) {
531
+ var index, length, key, sourceKeys;
532
+ if (source) {
533
+ sourceKeys = Object.keys(source);
534
+ for (index = 0, length = sourceKeys.length; index < length; index += 1) {
535
+ key = sourceKeys[index];
536
+ target[key] = source[key];
537
+ }
538
+ }
539
+ return target;
540
+ }
541
+ function repeat(string, count) {
542
+ var result = "", cycle;
543
+ for (cycle = 0; cycle < count; cycle += 1) {
544
+ result += string;
545
+ }
546
+ return result;
547
+ }
548
+ function isNegativeZero(number) {
549
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
550
+ }
551
+ var isNothing_1 = isNothing;
552
+ var isObject_1 = isObject;
553
+ var toArray_1 = toArray;
554
+ var repeat_1 = repeat;
555
+ var isNegativeZero_1 = isNegativeZero;
556
+ var extend_1 = extend;
557
+ var common = {
558
+ isNothing: isNothing_1,
559
+ isObject: isObject_1,
560
+ toArray: toArray_1,
561
+ repeat: repeat_1,
562
+ isNegativeZero: isNegativeZero_1,
563
+ extend: extend_1
564
+ };
565
+ function formatError(exception2, compact) {
566
+ var where = "", message = exception2.reason || "(unknown reason)";
567
+ if (!exception2.mark)
568
+ return message;
569
+ if (exception2.mark.name) {
570
+ where += 'in "' + exception2.mark.name + '" ';
571
+ }
572
+ where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
573
+ if (!compact && exception2.mark.snippet) {
574
+ where += "\n\n" + exception2.mark.snippet;
575
+ }
576
+ return message + " " + where;
577
+ }
578
+ function YAMLException$1(reason, mark) {
579
+ Error.call(this);
580
+ this.name = "YAMLException";
581
+ this.reason = reason;
582
+ this.mark = mark;
583
+ this.message = formatError(this, false);
584
+ if (Error.captureStackTrace) {
585
+ Error.captureStackTrace(this, this.constructor);
586
+ } else {
587
+ this.stack = new Error().stack || "";
588
+ }
589
+ }
590
+ YAMLException$1.prototype = Object.create(Error.prototype);
591
+ YAMLException$1.prototype.constructor = YAMLException$1;
592
+ YAMLException$1.prototype.toString = function toString(compact) {
593
+ return this.name + ": " + formatError(this, compact);
594
+ };
595
+ var exception = YAMLException$1;
596
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
597
+ var head = "";
598
+ var tail = "";
599
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
600
+ if (position - lineStart > maxHalfLength) {
601
+ head = " ... ";
602
+ lineStart = position - maxHalfLength + head.length;
603
+ }
604
+ if (lineEnd - position > maxHalfLength) {
605
+ tail = " ...";
606
+ lineEnd = position + maxHalfLength - tail.length;
607
+ }
608
+ return {
609
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
610
+ pos: position - lineStart + head.length
611
+ // relative position
612
+ };
613
+ }
614
+ function padStart(string, max) {
615
+ return common.repeat(" ", max - string.length) + string;
616
+ }
617
+ function makeSnippet(mark, options) {
618
+ options = Object.create(options || null);
619
+ if (!mark.buffer)
620
+ return null;
621
+ if (!options.maxLength)
622
+ options.maxLength = 79;
623
+ if (typeof options.indent !== "number")
624
+ options.indent = 1;
625
+ if (typeof options.linesBefore !== "number")
626
+ options.linesBefore = 3;
627
+ if (typeof options.linesAfter !== "number")
628
+ options.linesAfter = 2;
629
+ var re = /\r?\n|\r|\0/g;
630
+ var lineStarts = [0];
631
+ var lineEnds = [];
632
+ var match;
633
+ var foundLineNo = -1;
634
+ while (match = re.exec(mark.buffer)) {
635
+ lineEnds.push(match.index);
636
+ lineStarts.push(match.index + match[0].length);
637
+ if (mark.position <= match.index && foundLineNo < 0) {
638
+ foundLineNo = lineStarts.length - 2;
639
+ }
640
+ }
641
+ if (foundLineNo < 0)
642
+ foundLineNo = lineStarts.length - 1;
643
+ var result = "", i, line;
644
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
645
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
646
+ for (i = 1; i <= options.linesBefore; i++) {
647
+ if (foundLineNo - i < 0)
648
+ break;
649
+ line = getLine(
650
+ mark.buffer,
651
+ lineStarts[foundLineNo - i],
652
+ lineEnds[foundLineNo - i],
653
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
654
+ maxLineLength
655
+ );
656
+ result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
657
+ }
658
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
659
+ result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
660
+ result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
661
+ for (i = 1; i <= options.linesAfter; i++) {
662
+ if (foundLineNo + i >= lineEnds.length)
663
+ break;
664
+ line = getLine(
665
+ mark.buffer,
666
+ lineStarts[foundLineNo + i],
667
+ lineEnds[foundLineNo + i],
668
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
669
+ maxLineLength
670
+ );
671
+ result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
672
+ }
673
+ return result.replace(/\n$/, "");
674
+ }
675
+ var snippet = makeSnippet;
676
+ var TYPE_CONSTRUCTOR_OPTIONS = [
677
+ "kind",
678
+ "multi",
679
+ "resolve",
680
+ "construct",
681
+ "instanceOf",
682
+ "predicate",
683
+ "represent",
684
+ "representName",
685
+ "defaultStyle",
686
+ "styleAliases"
687
+ ];
688
+ var YAML_NODE_KINDS = [
689
+ "scalar",
690
+ "sequence",
691
+ "mapping"
692
+ ];
693
+ function compileStyleAliases(map2) {
694
+ var result = {};
695
+ if (map2 !== null) {
696
+ Object.keys(map2).forEach(function(style) {
697
+ map2[style].forEach(function(alias) {
698
+ result[String(alias)] = style;
699
+ });
700
+ });
701
+ }
702
+ return result;
703
+ }
704
+ function Type$1(tag, options) {
705
+ options = options || {};
706
+ Object.keys(options).forEach(function(name) {
707
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
708
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
709
+ }
710
+ });
711
+ this.options = options;
712
+ this.tag = tag;
713
+ this.kind = options["kind"] || null;
714
+ this.resolve = options["resolve"] || function() {
715
+ return true;
716
+ };
717
+ this.construct = options["construct"] || function(data) {
718
+ return data;
719
+ };
720
+ this.instanceOf = options["instanceOf"] || null;
721
+ this.predicate = options["predicate"] || null;
722
+ this.represent = options["represent"] || null;
723
+ this.representName = options["representName"] || null;
724
+ this.defaultStyle = options["defaultStyle"] || null;
725
+ this.multi = options["multi"] || false;
726
+ this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
727
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
728
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
729
+ }
730
+ }
731
+ var type = Type$1;
732
+ function compileList(schema2, name) {
733
+ var result = [];
734
+ schema2[name].forEach(function(currentType) {
735
+ var newIndex = result.length;
736
+ result.forEach(function(previousType, previousIndex) {
737
+ if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
738
+ newIndex = previousIndex;
739
+ }
740
+ });
741
+ result[newIndex] = currentType;
742
+ });
743
+ return result;
744
+ }
745
+ function compileMap() {
746
+ var result = {
747
+ scalar: {},
748
+ sequence: {},
749
+ mapping: {},
750
+ fallback: {},
751
+ multi: {
752
+ scalar: [],
753
+ sequence: [],
754
+ mapping: [],
755
+ fallback: []
756
+ }
757
+ }, index, length;
758
+ function collectType(type2) {
759
+ if (type2.multi) {
760
+ result.multi[type2.kind].push(type2);
761
+ result.multi["fallback"].push(type2);
762
+ } else {
763
+ result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
764
+ }
765
+ }
766
+ for (index = 0, length = arguments.length; index < length; index += 1) {
767
+ arguments[index].forEach(collectType);
768
+ }
769
+ return result;
770
+ }
771
+ function Schema$1(definition) {
772
+ return this.extend(definition);
773
+ }
774
+ Schema$1.prototype.extend = function extend2(definition) {
775
+ var implicit = [];
776
+ var explicit = [];
777
+ if (definition instanceof type) {
778
+ explicit.push(definition);
779
+ } else if (Array.isArray(definition)) {
780
+ explicit = explicit.concat(definition);
781
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
782
+ if (definition.implicit)
783
+ implicit = implicit.concat(definition.implicit);
784
+ if (definition.explicit)
785
+ explicit = explicit.concat(definition.explicit);
786
+ } else {
787
+ throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
788
+ }
789
+ implicit.forEach(function(type$1) {
790
+ if (!(type$1 instanceof type)) {
791
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
792
+ }
793
+ if (type$1.loadKind && type$1.loadKind !== "scalar") {
794
+ throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
795
+ }
796
+ if (type$1.multi) {
797
+ throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
798
+ }
799
+ });
800
+ explicit.forEach(function(type$1) {
801
+ if (!(type$1 instanceof type)) {
802
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
803
+ }
804
+ });
805
+ var result = Object.create(Schema$1.prototype);
806
+ result.implicit = (this.implicit || []).concat(implicit);
807
+ result.explicit = (this.explicit || []).concat(explicit);
808
+ result.compiledImplicit = compileList(result, "implicit");
809
+ result.compiledExplicit = compileList(result, "explicit");
810
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
811
+ return result;
812
+ };
813
+ var schema = Schema$1;
814
+ var str = new type("tag:yaml.org,2002:str", {
815
+ kind: "scalar",
816
+ construct: function(data) {
817
+ return data !== null ? data : "";
818
+ }
819
+ });
820
+ var seq = new type("tag:yaml.org,2002:seq", {
821
+ kind: "sequence",
822
+ construct: function(data) {
823
+ return data !== null ? data : [];
824
+ }
825
+ });
826
+ var map = new type("tag:yaml.org,2002:map", {
827
+ kind: "mapping",
828
+ construct: function(data) {
829
+ return data !== null ? data : {};
830
+ }
831
+ });
832
+ var failsafe = new schema({
833
+ explicit: [
834
+ str,
835
+ seq,
836
+ map
837
+ ]
838
+ });
839
+ function resolveYamlNull(data) {
840
+ if (data === null)
841
+ return true;
842
+ var max = data.length;
843
+ return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
844
+ }
845
+ function constructYamlNull() {
846
+ return null;
847
+ }
848
+ function isNull(object) {
849
+ return object === null;
850
+ }
851
+ var _null = new type("tag:yaml.org,2002:null", {
852
+ kind: "scalar",
853
+ resolve: resolveYamlNull,
854
+ construct: constructYamlNull,
855
+ predicate: isNull,
856
+ represent: {
857
+ canonical: function() {
858
+ return "~";
859
+ },
860
+ lowercase: function() {
861
+ return "null";
862
+ },
863
+ uppercase: function() {
864
+ return "NULL";
865
+ },
866
+ camelcase: function() {
867
+ return "Null";
868
+ },
869
+ empty: function() {
870
+ return "";
871
+ }
872
+ },
873
+ defaultStyle: "lowercase"
874
+ });
875
+ function resolveYamlBoolean(data) {
876
+ if (data === null)
877
+ return false;
878
+ var max = data.length;
879
+ return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
880
+ }
881
+ function constructYamlBoolean(data) {
882
+ return data === "true" || data === "True" || data === "TRUE";
883
+ }
884
+ function isBoolean(object) {
885
+ return Object.prototype.toString.call(object) === "[object Boolean]";
886
+ }
887
+ var bool = new type("tag:yaml.org,2002:bool", {
888
+ kind: "scalar",
889
+ resolve: resolveYamlBoolean,
890
+ construct: constructYamlBoolean,
891
+ predicate: isBoolean,
892
+ represent: {
893
+ lowercase: function(object) {
894
+ return object ? "true" : "false";
895
+ },
896
+ uppercase: function(object) {
897
+ return object ? "TRUE" : "FALSE";
898
+ },
899
+ camelcase: function(object) {
900
+ return object ? "True" : "False";
901
+ }
902
+ },
903
+ defaultStyle: "lowercase"
904
+ });
905
+ function isHexCode(c) {
906
+ return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
907
+ }
908
+ function isOctCode(c) {
909
+ return 48 <= c && c <= 55;
910
+ }
911
+ function isDecCode(c) {
912
+ return 48 <= c && c <= 57;
913
+ }
914
+ function resolveYamlInteger(data) {
915
+ if (data === null)
916
+ return false;
917
+ var max = data.length, index = 0, hasDigits = false, ch;
918
+ if (!max)
919
+ return false;
920
+ ch = data[index];
921
+ if (ch === "-" || ch === "+") {
922
+ ch = data[++index];
923
+ }
924
+ if (ch === "0") {
925
+ if (index + 1 === max)
926
+ return true;
927
+ ch = data[++index];
928
+ if (ch === "b") {
929
+ index++;
930
+ for (; index < max; index++) {
931
+ ch = data[index];
932
+ if (ch === "_")
933
+ continue;
934
+ if (ch !== "0" && ch !== "1")
935
+ return false;
936
+ hasDigits = true;
937
+ }
938
+ return hasDigits && ch !== "_";
939
+ }
940
+ if (ch === "x") {
941
+ index++;
942
+ for (; index < max; index++) {
943
+ ch = data[index];
944
+ if (ch === "_")
945
+ continue;
946
+ if (!isHexCode(data.charCodeAt(index)))
947
+ return false;
948
+ hasDigits = true;
949
+ }
950
+ return hasDigits && ch !== "_";
951
+ }
952
+ if (ch === "o") {
953
+ index++;
954
+ for (; index < max; index++) {
955
+ ch = data[index];
956
+ if (ch === "_")
957
+ continue;
958
+ if (!isOctCode(data.charCodeAt(index)))
959
+ return false;
960
+ hasDigits = true;
961
+ }
962
+ return hasDigits && ch !== "_";
963
+ }
964
+ }
965
+ if (ch === "_")
966
+ return false;
967
+ for (; index < max; index++) {
968
+ ch = data[index];
969
+ if (ch === "_")
970
+ continue;
971
+ if (!isDecCode(data.charCodeAt(index))) {
972
+ return false;
973
+ }
974
+ hasDigits = true;
975
+ }
976
+ if (!hasDigits || ch === "_")
977
+ return false;
978
+ return true;
979
+ }
980
+ function constructYamlInteger(data) {
981
+ var value = data, sign = 1, ch;
982
+ if (value.indexOf("_") !== -1) {
983
+ value = value.replace(/_/g, "");
984
+ }
985
+ ch = value[0];
986
+ if (ch === "-" || ch === "+") {
987
+ if (ch === "-")
988
+ sign = -1;
989
+ value = value.slice(1);
990
+ ch = value[0];
991
+ }
992
+ if (value === "0")
993
+ return 0;
994
+ if (ch === "0") {
995
+ if (value[1] === "b")
996
+ return sign * parseInt(value.slice(2), 2);
997
+ if (value[1] === "x")
998
+ return sign * parseInt(value.slice(2), 16);
999
+ if (value[1] === "o")
1000
+ return sign * parseInt(value.slice(2), 8);
1001
+ }
1002
+ return sign * parseInt(value, 10);
1003
+ }
1004
+ function isInteger(object) {
1005
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
1006
+ }
1007
+ var int = new type("tag:yaml.org,2002:int", {
1008
+ kind: "scalar",
1009
+ resolve: resolveYamlInteger,
1010
+ construct: constructYamlInteger,
1011
+ predicate: isInteger,
1012
+ represent: {
1013
+ binary: function(obj) {
1014
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
1015
+ },
1016
+ octal: function(obj) {
1017
+ return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
1018
+ },
1019
+ decimal: function(obj) {
1020
+ return obj.toString(10);
1021
+ },
1022
+ /* eslint-disable max-len */
1023
+ hexadecimal: function(obj) {
1024
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
1025
+ }
1026
+ },
1027
+ defaultStyle: "decimal",
1028
+ styleAliases: {
1029
+ binary: [2, "bin"],
1030
+ octal: [8, "oct"],
1031
+ decimal: [10, "dec"],
1032
+ hexadecimal: [16, "hex"]
1033
+ }
1034
+ });
1035
+ var YAML_FLOAT_PATTERN = new RegExp(
1036
+ // 2.5e4, 2.5 and integers
1037
+ "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
1038
+ );
1039
+ function resolveYamlFloat(data) {
1040
+ if (data === null)
1041
+ return false;
1042
+ if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
1043
+ // Probably should update regexp & check speed
1044
+ data[data.length - 1] === "_") {
1045
+ return false;
1046
+ }
1047
+ return true;
1048
+ }
1049
+ function constructYamlFloat(data) {
1050
+ var value, sign;
1051
+ value = data.replace(/_/g, "").toLowerCase();
1052
+ sign = value[0] === "-" ? -1 : 1;
1053
+ if ("+-".indexOf(value[0]) >= 0) {
1054
+ value = value.slice(1);
1055
+ }
1056
+ if (value === ".inf") {
1057
+ return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
1058
+ } else if (value === ".nan") {
1059
+ return NaN;
1060
+ }
1061
+ return sign * parseFloat(value, 10);
1062
+ }
1063
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
1064
+ function representYamlFloat(object, style) {
1065
+ var res;
1066
+ if (isNaN(object)) {
1067
+ switch (style) {
1068
+ case "lowercase":
1069
+ return ".nan";
1070
+ case "uppercase":
1071
+ return ".NAN";
1072
+ case "camelcase":
1073
+ return ".NaN";
1074
+ }
1075
+ } else if (Number.POSITIVE_INFINITY === object) {
1076
+ switch (style) {
1077
+ case "lowercase":
1078
+ return ".inf";
1079
+ case "uppercase":
1080
+ return ".INF";
1081
+ case "camelcase":
1082
+ return ".Inf";
1083
+ }
1084
+ } else if (Number.NEGATIVE_INFINITY === object) {
1085
+ switch (style) {
1086
+ case "lowercase":
1087
+ return "-.inf";
1088
+ case "uppercase":
1089
+ return "-.INF";
1090
+ case "camelcase":
1091
+ return "-.Inf";
1092
+ }
1093
+ } else if (common.isNegativeZero(object)) {
1094
+ return "-0.0";
1095
+ }
1096
+ res = object.toString(10);
1097
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
1098
+ }
1099
+ function isFloat(object) {
1100
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
1101
+ }
1102
+ var float = new type("tag:yaml.org,2002:float", {
1103
+ kind: "scalar",
1104
+ resolve: resolveYamlFloat,
1105
+ construct: constructYamlFloat,
1106
+ predicate: isFloat,
1107
+ represent: representYamlFloat,
1108
+ defaultStyle: "lowercase"
1109
+ });
1110
+ var json = failsafe.extend({
1111
+ implicit: [
1112
+ _null,
1113
+ bool,
1114
+ int,
1115
+ float
1116
+ ]
1117
+ });
1118
+ var core = json;
1119
+ var YAML_DATE_REGEXP = new RegExp(
1120
+ "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
1121
+ );
1122
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
1123
+ "^([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]))?))?$"
1124
+ );
1125
+ function resolveYamlTimestamp(data) {
1126
+ if (data === null)
1127
+ return false;
1128
+ if (YAML_DATE_REGEXP.exec(data) !== null)
1129
+ return true;
1130
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
1131
+ return true;
1132
+ return false;
1133
+ }
1134
+ function constructYamlTimestamp(data) {
1135
+ var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
1136
+ match = YAML_DATE_REGEXP.exec(data);
1137
+ if (match === null)
1138
+ match = YAML_TIMESTAMP_REGEXP.exec(data);
1139
+ if (match === null)
1140
+ throw new Error("Date resolve error");
1141
+ year = +match[1];
1142
+ month = +match[2] - 1;
1143
+ day = +match[3];
1144
+ if (!match[4]) {
1145
+ return new Date(Date.UTC(year, month, day));
1146
+ }
1147
+ hour = +match[4];
1148
+ minute = +match[5];
1149
+ second = +match[6];
1150
+ if (match[7]) {
1151
+ fraction = match[7].slice(0, 3);
1152
+ while (fraction.length < 3) {
1153
+ fraction += "0";
1154
+ }
1155
+ fraction = +fraction;
1156
+ }
1157
+ if (match[9]) {
1158
+ tz_hour = +match[10];
1159
+ tz_minute = +(match[11] || 0);
1160
+ delta = (tz_hour * 60 + tz_minute) * 6e4;
1161
+ if (match[9] === "-")
1162
+ delta = -delta;
1163
+ }
1164
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1165
+ if (delta)
1166
+ date.setTime(date.getTime() - delta);
1167
+ return date;
1168
+ }
1169
+ function representYamlTimestamp(object) {
1170
+ return object.toISOString();
1171
+ }
1172
+ var timestamp = new type("tag:yaml.org,2002:timestamp", {
1173
+ kind: "scalar",
1174
+ resolve: resolveYamlTimestamp,
1175
+ construct: constructYamlTimestamp,
1176
+ instanceOf: Date,
1177
+ represent: representYamlTimestamp
1178
+ });
1179
+ function resolveYamlMerge(data) {
1180
+ return data === "<<" || data === null;
1181
+ }
1182
+ var merge = new type("tag:yaml.org,2002:merge", {
1183
+ kind: "scalar",
1184
+ resolve: resolveYamlMerge
1185
+ });
1186
+ var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
1187
+ function resolveYamlBinary(data) {
1188
+ if (data === null)
1189
+ return false;
1190
+ var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
1191
+ for (idx = 0; idx < max; idx++) {
1192
+ code = map2.indexOf(data.charAt(idx));
1193
+ if (code > 64)
1194
+ continue;
1195
+ if (code < 0)
1196
+ return false;
1197
+ bitlen += 6;
1198
+ }
1199
+ return bitlen % 8 === 0;
1200
+ }
1201
+ function constructYamlBinary(data) {
1202
+ var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
1203
+ for (idx = 0; idx < max; idx++) {
1204
+ if (idx % 4 === 0 && idx) {
1205
+ result.push(bits >> 16 & 255);
1206
+ result.push(bits >> 8 & 255);
1207
+ result.push(bits & 255);
1208
+ }
1209
+ bits = bits << 6 | map2.indexOf(input.charAt(idx));
1210
+ }
1211
+ tailbits = max % 4 * 6;
1212
+ if (tailbits === 0) {
1213
+ result.push(bits >> 16 & 255);
1214
+ result.push(bits >> 8 & 255);
1215
+ result.push(bits & 255);
1216
+ } else if (tailbits === 18) {
1217
+ result.push(bits >> 10 & 255);
1218
+ result.push(bits >> 2 & 255);
1219
+ } else if (tailbits === 12) {
1220
+ result.push(bits >> 4 & 255);
1221
+ }
1222
+ return new Uint8Array(result);
1223
+ }
1224
+ function representYamlBinary(object) {
1225
+ var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
1226
+ for (idx = 0; idx < max; idx++) {
1227
+ if (idx % 3 === 0 && idx) {
1228
+ result += map2[bits >> 18 & 63];
1229
+ result += map2[bits >> 12 & 63];
1230
+ result += map2[bits >> 6 & 63];
1231
+ result += map2[bits & 63];
1232
+ }
1233
+ bits = (bits << 8) + object[idx];
1234
+ }
1235
+ tail = max % 3;
1236
+ if (tail === 0) {
1237
+ result += map2[bits >> 18 & 63];
1238
+ result += map2[bits >> 12 & 63];
1239
+ result += map2[bits >> 6 & 63];
1240
+ result += map2[bits & 63];
1241
+ } else if (tail === 2) {
1242
+ result += map2[bits >> 10 & 63];
1243
+ result += map2[bits >> 4 & 63];
1244
+ result += map2[bits << 2 & 63];
1245
+ result += map2[64];
1246
+ } else if (tail === 1) {
1247
+ result += map2[bits >> 2 & 63];
1248
+ result += map2[bits << 4 & 63];
1249
+ result += map2[64];
1250
+ result += map2[64];
1251
+ }
1252
+ return result;
1253
+ }
1254
+ function isBinary(obj) {
1255
+ return Object.prototype.toString.call(obj) === "[object Uint8Array]";
1256
+ }
1257
+ var binary = new type("tag:yaml.org,2002:binary", {
1258
+ kind: "scalar",
1259
+ resolve: resolveYamlBinary,
1260
+ construct: constructYamlBinary,
1261
+ predicate: isBinary,
1262
+ represent: representYamlBinary
1263
+ });
1264
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1265
+ var _toString$2 = Object.prototype.toString;
1266
+ function resolveYamlOmap(data) {
1267
+ if (data === null)
1268
+ return true;
1269
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
1270
+ for (index = 0, length = object.length; index < length; index += 1) {
1271
+ pair = object[index];
1272
+ pairHasKey = false;
1273
+ if (_toString$2.call(pair) !== "[object Object]")
1274
+ return false;
1275
+ for (pairKey in pair) {
1276
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
1277
+ if (!pairHasKey)
1278
+ pairHasKey = true;
1279
+ else
1280
+ return false;
1281
+ }
1282
+ }
1283
+ if (!pairHasKey)
1284
+ return false;
1285
+ if (objectKeys.indexOf(pairKey) === -1)
1286
+ objectKeys.push(pairKey);
1287
+ else
1288
+ return false;
1289
+ }
1290
+ return true;
1291
+ }
1292
+ function constructYamlOmap(data) {
1293
+ return data !== null ? data : [];
1294
+ }
1295
+ var omap = new type("tag:yaml.org,2002:omap", {
1296
+ kind: "sequence",
1297
+ resolve: resolveYamlOmap,
1298
+ construct: constructYamlOmap
1299
+ });
1300
+ var _toString$1 = Object.prototype.toString;
1301
+ function resolveYamlPairs(data) {
1302
+ if (data === null)
1303
+ return true;
1304
+ var index, length, pair, keys, result, object = data;
1305
+ result = new Array(object.length);
1306
+ for (index = 0, length = object.length; index < length; index += 1) {
1307
+ pair = object[index];
1308
+ if (_toString$1.call(pair) !== "[object Object]")
1309
+ return false;
1310
+ keys = Object.keys(pair);
1311
+ if (keys.length !== 1)
1312
+ return false;
1313
+ result[index] = [keys[0], pair[keys[0]]];
1314
+ }
1315
+ return true;
1316
+ }
1317
+ function constructYamlPairs(data) {
1318
+ if (data === null)
1319
+ return [];
1320
+ var index, length, pair, keys, result, object = data;
1321
+ result = new Array(object.length);
1322
+ for (index = 0, length = object.length; index < length; index += 1) {
1323
+ pair = object[index];
1324
+ keys = Object.keys(pair);
1325
+ result[index] = [keys[0], pair[keys[0]]];
1326
+ }
1327
+ return result;
1328
+ }
1329
+ var pairs = new type("tag:yaml.org,2002:pairs", {
1330
+ kind: "sequence",
1331
+ resolve: resolveYamlPairs,
1332
+ construct: constructYamlPairs
1333
+ });
1334
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1335
+ function resolveYamlSet(data) {
1336
+ if (data === null)
1337
+ return true;
1338
+ var key, object = data;
1339
+ for (key in object) {
1340
+ if (_hasOwnProperty$2.call(object, key)) {
1341
+ if (object[key] !== null)
1342
+ return false;
1343
+ }
1344
+ }
1345
+ return true;
1346
+ }
1347
+ function constructYamlSet(data) {
1348
+ return data !== null ? data : {};
1349
+ }
1350
+ var set = new type("tag:yaml.org,2002:set", {
1351
+ kind: "mapping",
1352
+ resolve: resolveYamlSet,
1353
+ construct: constructYamlSet
1354
+ });
1355
+ var _default = core.extend({
1356
+ implicit: [
1357
+ timestamp,
1358
+ merge
1359
+ ],
1360
+ explicit: [
1361
+ binary,
1362
+ omap,
1363
+ pairs,
1364
+ set
1365
+ ]
1366
+ });
1367
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1368
+ var CONTEXT_FLOW_IN = 1;
1369
+ var CONTEXT_FLOW_OUT = 2;
1370
+ var CONTEXT_BLOCK_IN = 3;
1371
+ var CONTEXT_BLOCK_OUT = 4;
1372
+ var CHOMPING_CLIP = 1;
1373
+ var CHOMPING_STRIP = 2;
1374
+ var CHOMPING_KEEP = 3;
1375
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1376
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
1377
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1378
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1379
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1380
+ function _class(obj) {
1381
+ return Object.prototype.toString.call(obj);
1382
+ }
1383
+ function is_EOL(c) {
1384
+ return c === 10 || c === 13;
1385
+ }
1386
+ function is_WHITE_SPACE(c) {
1387
+ return c === 9 || c === 32;
1388
+ }
1389
+ function is_WS_OR_EOL(c) {
1390
+ return c === 9 || c === 32 || c === 10 || c === 13;
1391
+ }
1392
+ function is_FLOW_INDICATOR(c) {
1393
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
1394
+ }
1395
+ function fromHexCode(c) {
1396
+ var lc;
1397
+ if (48 <= c && c <= 57) {
1398
+ return c - 48;
1399
+ }
1400
+ lc = c | 32;
1401
+ if (97 <= lc && lc <= 102) {
1402
+ return lc - 97 + 10;
1403
+ }
1404
+ return -1;
1405
+ }
1406
+ function escapedHexLen(c) {
1407
+ if (c === 120) {
1408
+ return 2;
1409
+ }
1410
+ if (c === 117) {
1411
+ return 4;
1412
+ }
1413
+ if (c === 85) {
1414
+ return 8;
1415
+ }
1416
+ return 0;
1417
+ }
1418
+ function fromDecimalCode(c) {
1419
+ if (48 <= c && c <= 57) {
1420
+ return c - 48;
1421
+ }
1422
+ return -1;
1423
+ }
1424
+ function simpleEscapeSequence(c) {
1425
+ return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "…" : c === 95 ? " " : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
1426
+ }
1427
+ function charFromCodepoint(c) {
1428
+ if (c <= 65535) {
1429
+ return String.fromCharCode(c);
1430
+ }
1431
+ return String.fromCharCode(
1432
+ (c - 65536 >> 10) + 55296,
1433
+ (c - 65536 & 1023) + 56320
1434
+ );
1435
+ }
1436
+ var simpleEscapeCheck = new Array(256);
1437
+ var simpleEscapeMap = new Array(256);
1438
+ for (i = 0; i < 256; i++) {
1439
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1440
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
1441
+ }
1442
+ var i;
1443
+ function State$1(input, options) {
1444
+ this.input = input;
1445
+ this.filename = options["filename"] || null;
1446
+ this.schema = options["schema"] || _default;
1447
+ this.onWarning = options["onWarning"] || null;
1448
+ this.legacy = options["legacy"] || false;
1449
+ this.json = options["json"] || false;
1450
+ this.listener = options["listener"] || null;
1451
+ this.implicitTypes = this.schema.compiledImplicit;
1452
+ this.typeMap = this.schema.compiledTypeMap;
1453
+ this.length = input.length;
1454
+ this.position = 0;
1455
+ this.line = 0;
1456
+ this.lineStart = 0;
1457
+ this.lineIndent = 0;
1458
+ this.firstTabInLine = -1;
1459
+ this.documents = [];
1460
+ }
1461
+ function generateError(state, message) {
1462
+ var mark = {
1463
+ name: state.filename,
1464
+ buffer: state.input.slice(0, -1),
1465
+ // omit trailing \0
1466
+ position: state.position,
1467
+ line: state.line,
1468
+ column: state.position - state.lineStart
1469
+ };
1470
+ mark.snippet = snippet(mark);
1471
+ return new exception(message, mark);
1472
+ }
1473
+ function throwError(state, message) {
1474
+ throw generateError(state, message);
1475
+ }
1476
+ function throwWarning(state, message) {
1477
+ if (state.onWarning) {
1478
+ state.onWarning.call(null, generateError(state, message));
1479
+ }
1480
+ }
1481
+ var directiveHandlers = {
1482
+ YAML: function handleYamlDirective(state, name, args) {
1483
+ var match, major, minor;
1484
+ if (state.version !== null) {
1485
+ throwError(state, "duplication of %YAML directive");
1486
+ }
1487
+ if (args.length !== 1) {
1488
+ throwError(state, "YAML directive accepts exactly one argument");
1489
+ }
1490
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
1491
+ if (match === null) {
1492
+ throwError(state, "ill-formed argument of the YAML directive");
1493
+ }
1494
+ major = parseInt(match[1], 10);
1495
+ minor = parseInt(match[2], 10);
1496
+ if (major !== 1) {
1497
+ throwError(state, "unacceptable YAML version of the document");
1498
+ }
1499
+ state.version = args[0];
1500
+ state.checkLineBreaks = minor < 2;
1501
+ if (minor !== 1 && minor !== 2) {
1502
+ throwWarning(state, "unsupported YAML version of the document");
1503
+ }
1504
+ },
1505
+ TAG: function handleTagDirective(state, name, args) {
1506
+ var handle, prefix;
1507
+ if (args.length !== 2) {
1508
+ throwError(state, "TAG directive accepts exactly two arguments");
1509
+ }
1510
+ handle = args[0];
1511
+ prefix = args[1];
1512
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
1513
+ throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
1514
+ }
1515
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
1516
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
1517
+ }
1518
+ if (!PATTERN_TAG_URI.test(prefix)) {
1519
+ throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
1520
+ }
1521
+ try {
1522
+ prefix = decodeURIComponent(prefix);
1523
+ } catch (err) {
1524
+ throwError(state, "tag prefix is malformed: " + prefix);
1525
+ }
1526
+ state.tagMap[handle] = prefix;
1527
+ }
1528
+ };
1529
+ function captureSegment(state, start, end, checkJson) {
1530
+ var _position, _length, _character, _result;
1531
+ if (start < end) {
1532
+ _result = state.input.slice(start, end);
1533
+ if (checkJson) {
1534
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
1535
+ _character = _result.charCodeAt(_position);
1536
+ if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
1537
+ throwError(state, "expected valid JSON character");
1538
+ }
1539
+ }
1540
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1541
+ throwError(state, "the stream contains non-printable characters");
1542
+ }
1543
+ state.result += _result;
1544
+ }
1545
+ }
1546
+ function mergeMappings(state, destination, source, overridableKeys) {
1547
+ var sourceKeys, key, index, quantity;
1548
+ if (!common.isObject(source)) {
1549
+ throwError(state, "cannot merge mappings; the provided source object is unacceptable");
1550
+ }
1551
+ sourceKeys = Object.keys(source);
1552
+ for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1553
+ key = sourceKeys[index];
1554
+ if (!_hasOwnProperty$1.call(destination, key)) {
1555
+ destination[key] = source[key];
1556
+ overridableKeys[key] = true;
1557
+ }
1558
+ }
1559
+ }
1560
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
1561
+ var index, quantity;
1562
+ if (Array.isArray(keyNode)) {
1563
+ keyNode = Array.prototype.slice.call(keyNode);
1564
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
1565
+ if (Array.isArray(keyNode[index])) {
1566
+ throwError(state, "nested arrays are not supported inside keys");
1567
+ }
1568
+ if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
1569
+ keyNode[index] = "[object Object]";
1570
+ }
1571
+ }
1572
+ }
1573
+ if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
1574
+ keyNode = "[object Object]";
1575
+ }
1576
+ keyNode = String(keyNode);
1577
+ if (_result === null) {
1578
+ _result = {};
1579
+ }
1580
+ if (keyTag === "tag:yaml.org,2002:merge") {
1581
+ if (Array.isArray(valueNode)) {
1582
+ for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1583
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
1584
+ }
1585
+ } else {
1586
+ mergeMappings(state, _result, valueNode, overridableKeys);
1587
+ }
1588
+ } else {
1589
+ if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
1590
+ state.line = startLine || state.line;
1591
+ state.lineStart = startLineStart || state.lineStart;
1592
+ state.position = startPos || state.position;
1593
+ throwError(state, "duplicated mapping key");
1594
+ }
1595
+ if (keyNode === "__proto__") {
1596
+ Object.defineProperty(_result, keyNode, {
1597
+ configurable: true,
1598
+ enumerable: true,
1599
+ writable: true,
1600
+ value: valueNode
1601
+ });
1602
+ } else {
1603
+ _result[keyNode] = valueNode;
1604
+ }
1605
+ delete overridableKeys[keyNode];
1606
+ }
1607
+ return _result;
1608
+ }
1609
+ function readLineBreak(state) {
1610
+ var ch;
1611
+ ch = state.input.charCodeAt(state.position);
1612
+ if (ch === 10) {
1613
+ state.position++;
1614
+ } else if (ch === 13) {
1615
+ state.position++;
1616
+ if (state.input.charCodeAt(state.position) === 10) {
1617
+ state.position++;
1618
+ }
1619
+ } else {
1620
+ throwError(state, "a line break is expected");
1621
+ }
1622
+ state.line += 1;
1623
+ state.lineStart = state.position;
1624
+ state.firstTabInLine = -1;
1625
+ }
1626
+ function skipSeparationSpace(state, allowComments, checkIndent) {
1627
+ var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
1628
+ while (ch !== 0) {
1629
+ while (is_WHITE_SPACE(ch)) {
1630
+ if (ch === 9 && state.firstTabInLine === -1) {
1631
+ state.firstTabInLine = state.position;
1632
+ }
1633
+ ch = state.input.charCodeAt(++state.position);
1634
+ }
1635
+ if (allowComments && ch === 35) {
1636
+ do {
1637
+ ch = state.input.charCodeAt(++state.position);
1638
+ } while (ch !== 10 && ch !== 13 && ch !== 0);
1639
+ }
1640
+ if (is_EOL(ch)) {
1641
+ readLineBreak(state);
1642
+ ch = state.input.charCodeAt(state.position);
1643
+ lineBreaks++;
1644
+ state.lineIndent = 0;
1645
+ while (ch === 32) {
1646
+ state.lineIndent++;
1647
+ ch = state.input.charCodeAt(++state.position);
1648
+ }
1649
+ } else {
1650
+ break;
1651
+ }
1652
+ }
1653
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1654
+ throwWarning(state, "deficient indentation");
1655
+ }
1656
+ return lineBreaks;
1657
+ }
1658
+ function testDocumentSeparator(state) {
1659
+ var _position = state.position, ch;
1660
+ ch = state.input.charCodeAt(_position);
1661
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
1662
+ _position += 3;
1663
+ ch = state.input.charCodeAt(_position);
1664
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
1665
+ return true;
1666
+ }
1667
+ }
1668
+ return false;
1669
+ }
1670
+ function writeFoldedLines(state, count) {
1671
+ if (count === 1) {
1672
+ state.result += " ";
1673
+ } else if (count > 1) {
1674
+ state.result += common.repeat("\n", count - 1);
1675
+ }
1676
+ }
1677
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1678
+ var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
1679
+ ch = state.input.charCodeAt(state.position);
1680
+ if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
1681
+ return false;
1682
+ }
1683
+ if (ch === 63 || ch === 45) {
1684
+ following = state.input.charCodeAt(state.position + 1);
1685
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1686
+ return false;
1687
+ }
1688
+ }
1689
+ state.kind = "scalar";
1690
+ state.result = "";
1691
+ captureStart = captureEnd = state.position;
1692
+ hasPendingContent = false;
1693
+ while (ch !== 0) {
1694
+ if (ch === 58) {
1695
+ following = state.input.charCodeAt(state.position + 1);
1696
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1697
+ break;
1698
+ }
1699
+ } else if (ch === 35) {
1700
+ preceding = state.input.charCodeAt(state.position - 1);
1701
+ if (is_WS_OR_EOL(preceding)) {
1702
+ break;
1703
+ }
1704
+ } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1705
+ break;
1706
+ } else if (is_EOL(ch)) {
1707
+ _line = state.line;
1708
+ _lineStart = state.lineStart;
1709
+ _lineIndent = state.lineIndent;
1710
+ skipSeparationSpace(state, false, -1);
1711
+ if (state.lineIndent >= nodeIndent) {
1712
+ hasPendingContent = true;
1713
+ ch = state.input.charCodeAt(state.position);
1714
+ continue;
1715
+ } else {
1716
+ state.position = captureEnd;
1717
+ state.line = _line;
1718
+ state.lineStart = _lineStart;
1719
+ state.lineIndent = _lineIndent;
1720
+ break;
1721
+ }
1722
+ }
1723
+ if (hasPendingContent) {
1724
+ captureSegment(state, captureStart, captureEnd, false);
1725
+ writeFoldedLines(state, state.line - _line);
1726
+ captureStart = captureEnd = state.position;
1727
+ hasPendingContent = false;
1728
+ }
1729
+ if (!is_WHITE_SPACE(ch)) {
1730
+ captureEnd = state.position + 1;
1731
+ }
1732
+ ch = state.input.charCodeAt(++state.position);
1733
+ }
1734
+ captureSegment(state, captureStart, captureEnd, false);
1735
+ if (state.result) {
1736
+ return true;
1737
+ }
1738
+ state.kind = _kind;
1739
+ state.result = _result;
1740
+ return false;
1741
+ }
1742
+ function readSingleQuotedScalar(state, nodeIndent) {
1743
+ var ch, captureStart, captureEnd;
1744
+ ch = state.input.charCodeAt(state.position);
1745
+ if (ch !== 39) {
1746
+ return false;
1747
+ }
1748
+ state.kind = "scalar";
1749
+ state.result = "";
1750
+ state.position++;
1751
+ captureStart = captureEnd = state.position;
1752
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1753
+ if (ch === 39) {
1754
+ captureSegment(state, captureStart, state.position, true);
1755
+ ch = state.input.charCodeAt(++state.position);
1756
+ if (ch === 39) {
1757
+ captureStart = state.position;
1758
+ state.position++;
1759
+ captureEnd = state.position;
1760
+ } else {
1761
+ return true;
1762
+ }
1763
+ } else if (is_EOL(ch)) {
1764
+ captureSegment(state, captureStart, captureEnd, true);
1765
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1766
+ captureStart = captureEnd = state.position;
1767
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1768
+ throwError(state, "unexpected end of the document within a single quoted scalar");
1769
+ } else {
1770
+ state.position++;
1771
+ captureEnd = state.position;
1772
+ }
1773
+ }
1774
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
1775
+ }
1776
+ function readDoubleQuotedScalar(state, nodeIndent) {
1777
+ var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
1778
+ ch = state.input.charCodeAt(state.position);
1779
+ if (ch !== 34) {
1780
+ return false;
1781
+ }
1782
+ state.kind = "scalar";
1783
+ state.result = "";
1784
+ state.position++;
1785
+ captureStart = captureEnd = state.position;
1786
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1787
+ if (ch === 34) {
1788
+ captureSegment(state, captureStart, state.position, true);
1789
+ state.position++;
1790
+ return true;
1791
+ } else if (ch === 92) {
1792
+ captureSegment(state, captureStart, state.position, true);
1793
+ ch = state.input.charCodeAt(++state.position);
1794
+ if (is_EOL(ch)) {
1795
+ skipSeparationSpace(state, false, nodeIndent);
1796
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
1797
+ state.result += simpleEscapeMap[ch];
1798
+ state.position++;
1799
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
1800
+ hexLength = tmp;
1801
+ hexResult = 0;
1802
+ for (; hexLength > 0; hexLength--) {
1803
+ ch = state.input.charCodeAt(++state.position);
1804
+ if ((tmp = fromHexCode(ch)) >= 0) {
1805
+ hexResult = (hexResult << 4) + tmp;
1806
+ } else {
1807
+ throwError(state, "expected hexadecimal character");
1808
+ }
1809
+ }
1810
+ state.result += charFromCodepoint(hexResult);
1811
+ state.position++;
1812
+ } else {
1813
+ throwError(state, "unknown escape sequence");
1814
+ }
1815
+ captureStart = captureEnd = state.position;
1816
+ } else if (is_EOL(ch)) {
1817
+ captureSegment(state, captureStart, captureEnd, true);
1818
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1819
+ captureStart = captureEnd = state.position;
1820
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1821
+ throwError(state, "unexpected end of the document within a double quoted scalar");
1822
+ } else {
1823
+ state.position++;
1824
+ captureEnd = state.position;
1825
+ }
1826
+ }
1827
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
1828
+ }
1829
+ function readFlowCollection(state, nodeIndent) {
1830
+ var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
1831
+ ch = state.input.charCodeAt(state.position);
1832
+ if (ch === 91) {
1833
+ terminator = 93;
1834
+ isMapping = false;
1835
+ _result = [];
1836
+ } else if (ch === 123) {
1837
+ terminator = 125;
1838
+ isMapping = true;
1839
+ _result = {};
1840
+ } else {
1841
+ return false;
1842
+ }
1843
+ if (state.anchor !== null) {
1844
+ state.anchorMap[state.anchor] = _result;
1845
+ }
1846
+ ch = state.input.charCodeAt(++state.position);
1847
+ while (ch !== 0) {
1848
+ skipSeparationSpace(state, true, nodeIndent);
1849
+ ch = state.input.charCodeAt(state.position);
1850
+ if (ch === terminator) {
1851
+ state.position++;
1852
+ state.tag = _tag;
1853
+ state.anchor = _anchor;
1854
+ state.kind = isMapping ? "mapping" : "sequence";
1855
+ state.result = _result;
1856
+ return true;
1857
+ } else if (!readNext) {
1858
+ throwError(state, "missed comma between flow collection entries");
1859
+ } else if (ch === 44) {
1860
+ throwError(state, "expected the node content, but found ','");
1861
+ }
1862
+ keyTag = keyNode = valueNode = null;
1863
+ isPair = isExplicitPair = false;
1864
+ if (ch === 63) {
1865
+ following = state.input.charCodeAt(state.position + 1);
1866
+ if (is_WS_OR_EOL(following)) {
1867
+ isPair = isExplicitPair = true;
1868
+ state.position++;
1869
+ skipSeparationSpace(state, true, nodeIndent);
1870
+ }
1871
+ }
1872
+ _line = state.line;
1873
+ _lineStart = state.lineStart;
1874
+ _pos = state.position;
1875
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1876
+ keyTag = state.tag;
1877
+ keyNode = state.result;
1878
+ skipSeparationSpace(state, true, nodeIndent);
1879
+ ch = state.input.charCodeAt(state.position);
1880
+ if ((isExplicitPair || state.line === _line) && ch === 58) {
1881
+ isPair = true;
1882
+ ch = state.input.charCodeAt(++state.position);
1883
+ skipSeparationSpace(state, true, nodeIndent);
1884
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1885
+ valueNode = state.result;
1886
+ }
1887
+ if (isMapping) {
1888
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
1889
+ } else if (isPair) {
1890
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
1891
+ } else {
1892
+ _result.push(keyNode);
1893
+ }
1894
+ skipSeparationSpace(state, true, nodeIndent);
1895
+ ch = state.input.charCodeAt(state.position);
1896
+ if (ch === 44) {
1897
+ readNext = true;
1898
+ ch = state.input.charCodeAt(++state.position);
1899
+ } else {
1900
+ readNext = false;
1901
+ }
1902
+ }
1903
+ throwError(state, "unexpected end of the stream within a flow collection");
1904
+ }
1905
+ function readBlockScalar(state, nodeIndent) {
1906
+ var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
1907
+ ch = state.input.charCodeAt(state.position);
1908
+ if (ch === 124) {
1909
+ folding = false;
1910
+ } else if (ch === 62) {
1911
+ folding = true;
1912
+ } else {
1913
+ return false;
1914
+ }
1915
+ state.kind = "scalar";
1916
+ state.result = "";
1917
+ while (ch !== 0) {
1918
+ ch = state.input.charCodeAt(++state.position);
1919
+ if (ch === 43 || ch === 45) {
1920
+ if (CHOMPING_CLIP === chomping) {
1921
+ chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
1922
+ } else {
1923
+ throwError(state, "repeat of a chomping mode identifier");
1924
+ }
1925
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
1926
+ if (tmp === 0) {
1927
+ throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1928
+ } else if (!detectedIndent) {
1929
+ textIndent = nodeIndent + tmp - 1;
1930
+ detectedIndent = true;
1931
+ } else {
1932
+ throwError(state, "repeat of an indentation width identifier");
1933
+ }
1934
+ } else {
1935
+ break;
1936
+ }
1937
+ }
1938
+ if (is_WHITE_SPACE(ch)) {
1939
+ do {
1940
+ ch = state.input.charCodeAt(++state.position);
1941
+ } while (is_WHITE_SPACE(ch));
1942
+ if (ch === 35) {
1943
+ do {
1944
+ ch = state.input.charCodeAt(++state.position);
1945
+ } while (!is_EOL(ch) && ch !== 0);
1946
+ }
1947
+ }
1948
+ while (ch !== 0) {
1949
+ readLineBreak(state);
1950
+ state.lineIndent = 0;
1951
+ ch = state.input.charCodeAt(state.position);
1952
+ while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
1953
+ state.lineIndent++;
1954
+ ch = state.input.charCodeAt(++state.position);
1955
+ }
1956
+ if (!detectedIndent && state.lineIndent > textIndent) {
1957
+ textIndent = state.lineIndent;
1958
+ }
1959
+ if (is_EOL(ch)) {
1960
+ emptyLines++;
1961
+ continue;
1962
+ }
1963
+ if (state.lineIndent < textIndent) {
1964
+ if (chomping === CHOMPING_KEEP) {
1965
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1966
+ } else if (chomping === CHOMPING_CLIP) {
1967
+ if (didReadContent) {
1968
+ state.result += "\n";
1969
+ }
1970
+ }
1971
+ break;
1972
+ }
1973
+ if (folding) {
1974
+ if (is_WHITE_SPACE(ch)) {
1975
+ atMoreIndented = true;
1976
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1977
+ } else if (atMoreIndented) {
1978
+ atMoreIndented = false;
1979
+ state.result += common.repeat("\n", emptyLines + 1);
1980
+ } else if (emptyLines === 0) {
1981
+ if (didReadContent) {
1982
+ state.result += " ";
1983
+ }
1984
+ } else {
1985
+ state.result += common.repeat("\n", emptyLines);
1986
+ }
1987
+ } else {
1988
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1989
+ }
1990
+ didReadContent = true;
1991
+ detectedIndent = true;
1992
+ emptyLines = 0;
1993
+ captureStart = state.position;
1994
+ while (!is_EOL(ch) && ch !== 0) {
1995
+ ch = state.input.charCodeAt(++state.position);
1996
+ }
1997
+ captureSegment(state, captureStart, state.position, false);
1998
+ }
1999
+ return true;
2000
+ }
2001
+ function readBlockSequence(state, nodeIndent) {
2002
+ var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
2003
+ if (state.firstTabInLine !== -1)
2004
+ return false;
2005
+ if (state.anchor !== null) {
2006
+ state.anchorMap[state.anchor] = _result;
2007
+ }
2008
+ ch = state.input.charCodeAt(state.position);
2009
+ while (ch !== 0) {
2010
+ if (state.firstTabInLine !== -1) {
2011
+ state.position = state.firstTabInLine;
2012
+ throwError(state, "tab characters must not be used in indentation");
2013
+ }
2014
+ if (ch !== 45) {
2015
+ break;
2016
+ }
2017
+ following = state.input.charCodeAt(state.position + 1);
2018
+ if (!is_WS_OR_EOL(following)) {
2019
+ break;
2020
+ }
2021
+ detected = true;
2022
+ state.position++;
2023
+ if (skipSeparationSpace(state, true, -1)) {
2024
+ if (state.lineIndent <= nodeIndent) {
2025
+ _result.push(null);
2026
+ ch = state.input.charCodeAt(state.position);
2027
+ continue;
2028
+ }
2029
+ }
2030
+ _line = state.line;
2031
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2032
+ _result.push(state.result);
2033
+ skipSeparationSpace(state, true, -1);
2034
+ ch = state.input.charCodeAt(state.position);
2035
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
2036
+ throwError(state, "bad indentation of a sequence entry");
2037
+ } else if (state.lineIndent < nodeIndent) {
2038
+ break;
2039
+ }
2040
+ }
2041
+ if (detected) {
2042
+ state.tag = _tag;
2043
+ state.anchor = _anchor;
2044
+ state.kind = "sequence";
2045
+ state.result = _result;
2046
+ return true;
2047
+ }
2048
+ return false;
2049
+ }
2050
+ function readBlockMapping(state, nodeIndent, flowIndent) {
2051
+ var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
2052
+ if (state.firstTabInLine !== -1)
2053
+ return false;
2054
+ if (state.anchor !== null) {
2055
+ state.anchorMap[state.anchor] = _result;
2056
+ }
2057
+ ch = state.input.charCodeAt(state.position);
2058
+ while (ch !== 0) {
2059
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
2060
+ state.position = state.firstTabInLine;
2061
+ throwError(state, "tab characters must not be used in indentation");
2062
+ }
2063
+ following = state.input.charCodeAt(state.position + 1);
2064
+ _line = state.line;
2065
+ if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
2066
+ if (ch === 63) {
2067
+ if (atExplicitKey) {
2068
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2069
+ keyTag = keyNode = valueNode = null;
2070
+ }
2071
+ detected = true;
2072
+ atExplicitKey = true;
2073
+ allowCompact = true;
2074
+ } else if (atExplicitKey) {
2075
+ atExplicitKey = false;
2076
+ allowCompact = true;
2077
+ } else {
2078
+ throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
2079
+ }
2080
+ state.position += 1;
2081
+ ch = following;
2082
+ } else {
2083
+ _keyLine = state.line;
2084
+ _keyLineStart = state.lineStart;
2085
+ _keyPos = state.position;
2086
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2087
+ break;
2088
+ }
2089
+ if (state.line === _line) {
2090
+ ch = state.input.charCodeAt(state.position);
2091
+ while (is_WHITE_SPACE(ch)) {
2092
+ ch = state.input.charCodeAt(++state.position);
2093
+ }
2094
+ if (ch === 58) {
2095
+ ch = state.input.charCodeAt(++state.position);
2096
+ if (!is_WS_OR_EOL(ch)) {
2097
+ throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
2098
+ }
2099
+ if (atExplicitKey) {
2100
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2101
+ keyTag = keyNode = valueNode = null;
2102
+ }
2103
+ detected = true;
2104
+ atExplicitKey = false;
2105
+ allowCompact = false;
2106
+ keyTag = state.tag;
2107
+ keyNode = state.result;
2108
+ } else if (detected) {
2109
+ throwError(state, "can not read an implicit mapping pair; a colon is missed");
2110
+ } else {
2111
+ state.tag = _tag;
2112
+ state.anchor = _anchor;
2113
+ return true;
2114
+ }
2115
+ } else if (detected) {
2116
+ throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
2117
+ } else {
2118
+ state.tag = _tag;
2119
+ state.anchor = _anchor;
2120
+ return true;
2121
+ }
2122
+ }
2123
+ if (state.line === _line || state.lineIndent > nodeIndent) {
2124
+ if (atExplicitKey) {
2125
+ _keyLine = state.line;
2126
+ _keyLineStart = state.lineStart;
2127
+ _keyPos = state.position;
2128
+ }
2129
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2130
+ if (atExplicitKey) {
2131
+ keyNode = state.result;
2132
+ } else {
2133
+ valueNode = state.result;
2134
+ }
2135
+ }
2136
+ if (!atExplicitKey) {
2137
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
2138
+ keyTag = keyNode = valueNode = null;
2139
+ }
2140
+ skipSeparationSpace(state, true, -1);
2141
+ ch = state.input.charCodeAt(state.position);
2142
+ }
2143
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
2144
+ throwError(state, "bad indentation of a mapping entry");
2145
+ } else if (state.lineIndent < nodeIndent) {
2146
+ break;
2147
+ }
2148
+ }
2149
+ if (atExplicitKey) {
2150
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2151
+ }
2152
+ if (detected) {
2153
+ state.tag = _tag;
2154
+ state.anchor = _anchor;
2155
+ state.kind = "mapping";
2156
+ state.result = _result;
2157
+ }
2158
+ return detected;
2159
+ }
2160
+ function readTagProperty(state) {
2161
+ var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
2162
+ ch = state.input.charCodeAt(state.position);
2163
+ if (ch !== 33)
2164
+ return false;
2165
+ if (state.tag !== null) {
2166
+ throwError(state, "duplication of a tag property");
2167
+ }
2168
+ ch = state.input.charCodeAt(++state.position);
2169
+ if (ch === 60) {
2170
+ isVerbatim = true;
2171
+ ch = state.input.charCodeAt(++state.position);
2172
+ } else if (ch === 33) {
2173
+ isNamed = true;
2174
+ tagHandle = "!!";
2175
+ ch = state.input.charCodeAt(++state.position);
2176
+ } else {
2177
+ tagHandle = "!";
2178
+ }
2179
+ _position = state.position;
2180
+ if (isVerbatim) {
2181
+ do {
2182
+ ch = state.input.charCodeAt(++state.position);
2183
+ } while (ch !== 0 && ch !== 62);
2184
+ if (state.position < state.length) {
2185
+ tagName = state.input.slice(_position, state.position);
2186
+ ch = state.input.charCodeAt(++state.position);
2187
+ } else {
2188
+ throwError(state, "unexpected end of the stream within a verbatim tag");
2189
+ }
2190
+ } else {
2191
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2192
+ if (ch === 33) {
2193
+ if (!isNamed) {
2194
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
2195
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
2196
+ throwError(state, "named tag handle cannot contain such characters");
2197
+ }
2198
+ isNamed = true;
2199
+ _position = state.position + 1;
2200
+ } else {
2201
+ throwError(state, "tag suffix cannot contain exclamation marks");
2202
+ }
2203
+ }
2204
+ ch = state.input.charCodeAt(++state.position);
2205
+ }
2206
+ tagName = state.input.slice(_position, state.position);
2207
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
2208
+ throwError(state, "tag suffix cannot contain flow indicator characters");
2209
+ }
2210
+ }
2211
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
2212
+ throwError(state, "tag name cannot contain such characters: " + tagName);
2213
+ }
2214
+ try {
2215
+ tagName = decodeURIComponent(tagName);
2216
+ } catch (err) {
2217
+ throwError(state, "tag name is malformed: " + tagName);
2218
+ }
2219
+ if (isVerbatim) {
2220
+ state.tag = tagName;
2221
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
2222
+ state.tag = state.tagMap[tagHandle] + tagName;
2223
+ } else if (tagHandle === "!") {
2224
+ state.tag = "!" + tagName;
2225
+ } else if (tagHandle === "!!") {
2226
+ state.tag = "tag:yaml.org,2002:" + tagName;
2227
+ } else {
2228
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
2229
+ }
2230
+ return true;
2231
+ }
2232
+ function readAnchorProperty(state) {
2233
+ var _position, ch;
2234
+ ch = state.input.charCodeAt(state.position);
2235
+ if (ch !== 38)
2236
+ return false;
2237
+ if (state.anchor !== null) {
2238
+ throwError(state, "duplication of an anchor property");
2239
+ }
2240
+ ch = state.input.charCodeAt(++state.position);
2241
+ _position = state.position;
2242
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2243
+ ch = state.input.charCodeAt(++state.position);
2244
+ }
2245
+ if (state.position === _position) {
2246
+ throwError(state, "name of an anchor node must contain at least one character");
2247
+ }
2248
+ state.anchor = state.input.slice(_position, state.position);
2249
+ return true;
2250
+ }
2251
+ function readAlias(state) {
2252
+ var _position, alias, ch;
2253
+ ch = state.input.charCodeAt(state.position);
2254
+ if (ch !== 42)
2255
+ return false;
2256
+ ch = state.input.charCodeAt(++state.position);
2257
+ _position = state.position;
2258
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2259
+ ch = state.input.charCodeAt(++state.position);
2260
+ }
2261
+ if (state.position === _position) {
2262
+ throwError(state, "name of an alias node must contain at least one character");
2263
+ }
2264
+ alias = state.input.slice(_position, state.position);
2265
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
2266
+ throwError(state, 'unidentified alias "' + alias + '"');
2267
+ }
2268
+ state.result = state.anchorMap[alias];
2269
+ skipSeparationSpace(state, true, -1);
2270
+ return true;
2271
+ }
2272
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
2273
+ var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
2274
+ if (state.listener !== null) {
2275
+ state.listener("open", state);
2276
+ }
2277
+ state.tag = null;
2278
+ state.anchor = null;
2279
+ state.kind = null;
2280
+ state.result = null;
2281
+ allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
2282
+ if (allowToSeek) {
2283
+ if (skipSeparationSpace(state, true, -1)) {
2284
+ atNewLine = true;
2285
+ if (state.lineIndent > parentIndent) {
2286
+ indentStatus = 1;
2287
+ } else if (state.lineIndent === parentIndent) {
2288
+ indentStatus = 0;
2289
+ } else if (state.lineIndent < parentIndent) {
2290
+ indentStatus = -1;
2291
+ }
2292
+ }
2293
+ }
2294
+ if (indentStatus === 1) {
2295
+ while (readTagProperty(state) || readAnchorProperty(state)) {
2296
+ if (skipSeparationSpace(state, true, -1)) {
2297
+ atNewLine = true;
2298
+ allowBlockCollections = allowBlockStyles;
2299
+ if (state.lineIndent > parentIndent) {
2300
+ indentStatus = 1;
2301
+ } else if (state.lineIndent === parentIndent) {
2302
+ indentStatus = 0;
2303
+ } else if (state.lineIndent < parentIndent) {
2304
+ indentStatus = -1;
2305
+ }
2306
+ } else {
2307
+ allowBlockCollections = false;
2308
+ }
2309
+ }
2310
+ }
2311
+ if (allowBlockCollections) {
2312
+ allowBlockCollections = atNewLine || allowCompact;
2313
+ }
2314
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
2315
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
2316
+ flowIndent = parentIndent;
2317
+ } else {
2318
+ flowIndent = parentIndent + 1;
2319
+ }
2320
+ blockIndent = state.position - state.lineStart;
2321
+ if (indentStatus === 1) {
2322
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
2323
+ hasContent = true;
2324
+ } else {
2325
+ if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
2326
+ hasContent = true;
2327
+ } else if (readAlias(state)) {
2328
+ hasContent = true;
2329
+ if (state.tag !== null || state.anchor !== null) {
2330
+ throwError(state, "alias node should not have any properties");
2331
+ }
2332
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
2333
+ hasContent = true;
2334
+ if (state.tag === null) {
2335
+ state.tag = "?";
2336
+ }
2337
+ }
2338
+ if (state.anchor !== null) {
2339
+ state.anchorMap[state.anchor] = state.result;
2340
+ }
2341
+ }
2342
+ } else if (indentStatus === 0) {
2343
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
2344
+ }
2345
+ }
2346
+ if (state.tag === null) {
2347
+ if (state.anchor !== null) {
2348
+ state.anchorMap[state.anchor] = state.result;
2349
+ }
2350
+ } else if (state.tag === "?") {
2351
+ if (state.result !== null && state.kind !== "scalar") {
2352
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
2353
+ }
2354
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
2355
+ type2 = state.implicitTypes[typeIndex];
2356
+ if (type2.resolve(state.result)) {
2357
+ state.result = type2.construct(state.result);
2358
+ state.tag = type2.tag;
2359
+ if (state.anchor !== null) {
2360
+ state.anchorMap[state.anchor] = state.result;
2361
+ }
2362
+ break;
2363
+ }
2364
+ }
2365
+ } else if (state.tag !== "!") {
2366
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
2367
+ type2 = state.typeMap[state.kind || "fallback"][state.tag];
2368
+ } else {
2369
+ type2 = null;
2370
+ typeList = state.typeMap.multi[state.kind || "fallback"];
2371
+ for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
2372
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
2373
+ type2 = typeList[typeIndex];
2374
+ break;
2375
+ }
2376
+ }
2377
+ }
2378
+ if (!type2) {
2379
+ throwError(state, "unknown tag !<" + state.tag + ">");
2380
+ }
2381
+ if (state.result !== null && type2.kind !== state.kind) {
2382
+ throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
2383
+ }
2384
+ if (!type2.resolve(state.result, state.tag)) {
2385
+ throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
2386
+ } else {
2387
+ state.result = type2.construct(state.result, state.tag);
2388
+ if (state.anchor !== null) {
2389
+ state.anchorMap[state.anchor] = state.result;
2390
+ }
2391
+ }
2392
+ }
2393
+ if (state.listener !== null) {
2394
+ state.listener("close", state);
2395
+ }
2396
+ return state.tag !== null || state.anchor !== null || hasContent;
2397
+ }
2398
+ function readDocument(state) {
2399
+ var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
2400
+ state.version = null;
2401
+ state.checkLineBreaks = state.legacy;
2402
+ state.tagMap = /* @__PURE__ */ Object.create(null);
2403
+ state.anchorMap = /* @__PURE__ */ Object.create(null);
2404
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2405
+ skipSeparationSpace(state, true, -1);
2406
+ ch = state.input.charCodeAt(state.position);
2407
+ if (state.lineIndent > 0 || ch !== 37) {
2408
+ break;
2409
+ }
2410
+ hasDirectives = true;
2411
+ ch = state.input.charCodeAt(++state.position);
2412
+ _position = state.position;
2413
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2414
+ ch = state.input.charCodeAt(++state.position);
2415
+ }
2416
+ directiveName = state.input.slice(_position, state.position);
2417
+ directiveArgs = [];
2418
+ if (directiveName.length < 1) {
2419
+ throwError(state, "directive name must not be less than one character in length");
2420
+ }
2421
+ while (ch !== 0) {
2422
+ while (is_WHITE_SPACE(ch)) {
2423
+ ch = state.input.charCodeAt(++state.position);
2424
+ }
2425
+ if (ch === 35) {
2426
+ do {
2427
+ ch = state.input.charCodeAt(++state.position);
2428
+ } while (ch !== 0 && !is_EOL(ch));
2429
+ break;
2430
+ }
2431
+ if (is_EOL(ch))
2432
+ break;
2433
+ _position = state.position;
2434
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2435
+ ch = state.input.charCodeAt(++state.position);
2436
+ }
2437
+ directiveArgs.push(state.input.slice(_position, state.position));
2438
+ }
2439
+ if (ch !== 0)
2440
+ readLineBreak(state);
2441
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
2442
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
2443
+ } else {
2444
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
2445
+ }
2446
+ }
2447
+ skipSeparationSpace(state, true, -1);
2448
+ if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
2449
+ state.position += 3;
2450
+ skipSeparationSpace(state, true, -1);
2451
+ } else if (hasDirectives) {
2452
+ throwError(state, "directives end mark is expected");
2453
+ }
2454
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
2455
+ skipSeparationSpace(state, true, -1);
2456
+ if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
2457
+ throwWarning(state, "non-ASCII line breaks are interpreted as content");
2458
+ }
2459
+ state.documents.push(state.result);
2460
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
2461
+ if (state.input.charCodeAt(state.position) === 46) {
2462
+ state.position += 3;
2463
+ skipSeparationSpace(state, true, -1);
2464
+ }
2465
+ return;
2466
+ }
2467
+ if (state.position < state.length - 1) {
2468
+ throwError(state, "end of the stream or a document separator is expected");
2469
+ } else {
2470
+ return;
2471
+ }
2472
+ }
2473
+ function loadDocuments(input, options) {
2474
+ input = String(input);
2475
+ options = options || {};
2476
+ if (input.length !== 0) {
2477
+ if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
2478
+ input += "\n";
2479
+ }
2480
+ if (input.charCodeAt(0) === 65279) {
2481
+ input = input.slice(1);
2482
+ }
2483
+ }
2484
+ var state = new State$1(input, options);
2485
+ var nullpos = input.indexOf("\0");
2486
+ if (nullpos !== -1) {
2487
+ state.position = nullpos;
2488
+ throwError(state, "null byte is not allowed in input");
2489
+ }
2490
+ state.input += "\0";
2491
+ while (state.input.charCodeAt(state.position) === 32) {
2492
+ state.lineIndent += 1;
2493
+ state.position += 1;
2494
+ }
2495
+ while (state.position < state.length - 1) {
2496
+ readDocument(state);
2497
+ }
2498
+ return state.documents;
2499
+ }
2500
+ function loadAll$1(input, iterator, options) {
2501
+ if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
2502
+ options = iterator;
2503
+ iterator = null;
2504
+ }
2505
+ var documents = loadDocuments(input, options);
2506
+ if (typeof iterator !== "function") {
2507
+ return documents;
2508
+ }
2509
+ for (var index = 0, length = documents.length; index < length; index += 1) {
2510
+ iterator(documents[index]);
2511
+ }
2512
+ }
2513
+ function load$1(input, options) {
2514
+ var documents = loadDocuments(input, options);
2515
+ if (documents.length === 0) {
2516
+ return void 0;
2517
+ } else if (documents.length === 1) {
2518
+ return documents[0];
2519
+ }
2520
+ throw new exception("expected a single document in the stream, but found more");
2521
+ }
2522
+ var loadAll_1 = loadAll$1;
2523
+ var load_1 = load$1;
2524
+ var loader = {
2525
+ loadAll: loadAll_1,
2526
+ load: load_1
2527
+ };
2528
+ var _toString = Object.prototype.toString;
2529
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
2530
+ var CHAR_BOM = 65279;
2531
+ var CHAR_TAB = 9;
2532
+ var CHAR_LINE_FEED = 10;
2533
+ var CHAR_CARRIAGE_RETURN = 13;
2534
+ var CHAR_SPACE = 32;
2535
+ var CHAR_EXCLAMATION = 33;
2536
+ var CHAR_DOUBLE_QUOTE = 34;
2537
+ var CHAR_SHARP = 35;
2538
+ var CHAR_PERCENT = 37;
2539
+ var CHAR_AMPERSAND = 38;
2540
+ var CHAR_SINGLE_QUOTE = 39;
2541
+ var CHAR_ASTERISK = 42;
2542
+ var CHAR_COMMA = 44;
2543
+ var CHAR_MINUS = 45;
2544
+ var CHAR_COLON = 58;
2545
+ var CHAR_EQUALS = 61;
2546
+ var CHAR_GREATER_THAN = 62;
2547
+ var CHAR_QUESTION = 63;
2548
+ var CHAR_COMMERCIAL_AT = 64;
2549
+ var CHAR_LEFT_SQUARE_BRACKET = 91;
2550
+ var CHAR_RIGHT_SQUARE_BRACKET = 93;
2551
+ var CHAR_GRAVE_ACCENT = 96;
2552
+ var CHAR_LEFT_CURLY_BRACKET = 123;
2553
+ var CHAR_VERTICAL_LINE = 124;
2554
+ var CHAR_RIGHT_CURLY_BRACKET = 125;
2555
+ var ESCAPE_SEQUENCES = {};
2556
+ ESCAPE_SEQUENCES[0] = "\\0";
2557
+ ESCAPE_SEQUENCES[7] = "\\a";
2558
+ ESCAPE_SEQUENCES[8] = "\\b";
2559
+ ESCAPE_SEQUENCES[9] = "\\t";
2560
+ ESCAPE_SEQUENCES[10] = "\\n";
2561
+ ESCAPE_SEQUENCES[11] = "\\v";
2562
+ ESCAPE_SEQUENCES[12] = "\\f";
2563
+ ESCAPE_SEQUENCES[13] = "\\r";
2564
+ ESCAPE_SEQUENCES[27] = "\\e";
2565
+ ESCAPE_SEQUENCES[34] = '\\"';
2566
+ ESCAPE_SEQUENCES[92] = "\\\\";
2567
+ ESCAPE_SEQUENCES[133] = "\\N";
2568
+ ESCAPE_SEQUENCES[160] = "\\_";
2569
+ ESCAPE_SEQUENCES[8232] = "\\L";
2570
+ ESCAPE_SEQUENCES[8233] = "\\P";
2571
+ var DEPRECATED_BOOLEANS_SYNTAX = [
2572
+ "y",
2573
+ "Y",
2574
+ "yes",
2575
+ "Yes",
2576
+ "YES",
2577
+ "on",
2578
+ "On",
2579
+ "ON",
2580
+ "n",
2581
+ "N",
2582
+ "no",
2583
+ "No",
2584
+ "NO",
2585
+ "off",
2586
+ "Off",
2587
+ "OFF"
2588
+ ];
2589
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
2590
+ function compileStyleMap(schema2, map2) {
2591
+ var result, keys, index, length, tag, style, type2;
2592
+ if (map2 === null)
2593
+ return {};
2594
+ result = {};
2595
+ keys = Object.keys(map2);
2596
+ for (index = 0, length = keys.length; index < length; index += 1) {
2597
+ tag = keys[index];
2598
+ style = String(map2[tag]);
2599
+ if (tag.slice(0, 2) === "!!") {
2600
+ tag = "tag:yaml.org,2002:" + tag.slice(2);
2601
+ }
2602
+ type2 = schema2.compiledTypeMap["fallback"][tag];
2603
+ if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
2604
+ style = type2.styleAliases[style];
2605
+ }
2606
+ result[tag] = style;
2607
+ }
2608
+ return result;
2609
+ }
2610
+ function encodeHex(character) {
2611
+ var string, handle, length;
2612
+ string = character.toString(16).toUpperCase();
2613
+ if (character <= 255) {
2614
+ handle = "x";
2615
+ length = 2;
2616
+ } else if (character <= 65535) {
2617
+ handle = "u";
2618
+ length = 4;
2619
+ } else if (character <= 4294967295) {
2620
+ handle = "U";
2621
+ length = 8;
2622
+ } else {
2623
+ throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
2624
+ }
2625
+ return "\\" + handle + common.repeat("0", length - string.length) + string;
2626
+ }
2627
+ var QUOTING_TYPE_SINGLE = 1;
2628
+ var QUOTING_TYPE_DOUBLE = 2;
2629
+ function State(options) {
2630
+ this.schema = options["schema"] || _default;
2631
+ this.indent = Math.max(1, options["indent"] || 2);
2632
+ this.noArrayIndent = options["noArrayIndent"] || false;
2633
+ this.skipInvalid = options["skipInvalid"] || false;
2634
+ this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
2635
+ this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
2636
+ this.sortKeys = options["sortKeys"] || false;
2637
+ this.lineWidth = options["lineWidth"] || 80;
2638
+ this.noRefs = options["noRefs"] || false;
2639
+ this.noCompatMode = options["noCompatMode"] || false;
2640
+ this.condenseFlow = options["condenseFlow"] || false;
2641
+ this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
2642
+ this.forceQuotes = options["forceQuotes"] || false;
2643
+ this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
2644
+ this.implicitTypes = this.schema.compiledImplicit;
2645
+ this.explicitTypes = this.schema.compiledExplicit;
2646
+ this.tag = null;
2647
+ this.result = "";
2648
+ this.duplicates = [];
2649
+ this.usedDuplicates = null;
2650
+ }
2651
+ function indentString(string, spaces) {
2652
+ var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
2653
+ while (position < length) {
2654
+ next = string.indexOf("\n", position);
2655
+ if (next === -1) {
2656
+ line = string.slice(position);
2657
+ position = length;
2658
+ } else {
2659
+ line = string.slice(position, next + 1);
2660
+ position = next + 1;
2661
+ }
2662
+ if (line.length && line !== "\n")
2663
+ result += ind;
2664
+ result += line;
2665
+ }
2666
+ return result;
2667
+ }
2668
+ function generateNextLine(state, level) {
2669
+ return "\n" + common.repeat(" ", state.indent * level);
2670
+ }
2671
+ function testImplicitResolving(state, str2) {
2672
+ var index, length, type2;
2673
+ for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
2674
+ type2 = state.implicitTypes[index];
2675
+ if (type2.resolve(str2)) {
2676
+ return true;
2677
+ }
2678
+ }
2679
+ return false;
2680
+ }
2681
+ function isWhitespace(c) {
2682
+ return c === CHAR_SPACE || c === CHAR_TAB;
2683
+ }
2684
+ function isPrintable(c) {
2685
+ return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
2686
+ }
2687
+ function isNsCharOrWhitespace(c) {
2688
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
2689
+ }
2690
+ function isPlainSafe(c, prev, inblock) {
2691
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
2692
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
2693
+ return (
2694
+ // ns-plain-safe
2695
+ (inblock ? (
2696
+ // c = flow-in
2697
+ cIsNsCharOrWhitespace
2698
+ ) : 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
2699
+ );
2700
+ }
2701
+ function isPlainSafeFirst(c) {
2702
+ 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;
2703
+ }
2704
+ function isPlainSafeLast(c) {
2705
+ return !isWhitespace(c) && c !== CHAR_COLON;
2706
+ }
2707
+ function codePointAt(string, pos) {
2708
+ var first = string.charCodeAt(pos), second;
2709
+ if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
2710
+ second = string.charCodeAt(pos + 1);
2711
+ if (second >= 56320 && second <= 57343) {
2712
+ return (first - 55296) * 1024 + second - 56320 + 65536;
2713
+ }
2714
+ }
2715
+ return first;
2716
+ }
2717
+ function needIndentIndicator(string) {
2718
+ var leadingSpaceRe = /^\n* /;
2719
+ return leadingSpaceRe.test(string);
2720
+ }
2721
+ var STYLE_PLAIN = 1;
2722
+ var STYLE_SINGLE = 2;
2723
+ var STYLE_LITERAL = 3;
2724
+ var STYLE_FOLDED = 4;
2725
+ var STYLE_DOUBLE = 5;
2726
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
2727
+ var i;
2728
+ var char = 0;
2729
+ var prevChar = null;
2730
+ var hasLineBreak = false;
2731
+ var hasFoldableLine = false;
2732
+ var shouldTrackWidth = lineWidth !== -1;
2733
+ var previousLineBreak = -1;
2734
+ var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
2735
+ if (singleLineOnly || forceQuotes) {
2736
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2737
+ char = codePointAt(string, i);
2738
+ if (!isPrintable(char)) {
2739
+ return STYLE_DOUBLE;
2740
+ }
2741
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2742
+ prevChar = char;
2743
+ }
2744
+ } else {
2745
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2746
+ char = codePointAt(string, i);
2747
+ if (char === CHAR_LINE_FEED) {
2748
+ hasLineBreak = true;
2749
+ if (shouldTrackWidth) {
2750
+ hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
2751
+ i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2752
+ previousLineBreak = i;
2753
+ }
2754
+ } else if (!isPrintable(char)) {
2755
+ return STYLE_DOUBLE;
2756
+ }
2757
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2758
+ prevChar = char;
2759
+ }
2760
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
2761
+ }
2762
+ if (!hasLineBreak && !hasFoldableLine) {
2763
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
2764
+ return STYLE_PLAIN;
2765
+ }
2766
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2767
+ }
2768
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
2769
+ return STYLE_DOUBLE;
2770
+ }
2771
+ if (!forceQuotes) {
2772
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
2773
+ }
2774
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2775
+ }
2776
+ function writeScalar(state, string, level, iskey, inblock) {
2777
+ state.dump = function() {
2778
+ if (string.length === 0) {
2779
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
2780
+ }
2781
+ if (!state.noCompatMode) {
2782
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
2783
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
2784
+ }
2785
+ }
2786
+ var indent = state.indent * Math.max(1, level);
2787
+ var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
2788
+ var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
2789
+ function testAmbiguity(string2) {
2790
+ return testImplicitResolving(state, string2);
2791
+ }
2792
+ switch (chooseScalarStyle(
2793
+ string,
2794
+ singleLineOnly,
2795
+ state.indent,
2796
+ lineWidth,
2797
+ testAmbiguity,
2798
+ state.quotingType,
2799
+ state.forceQuotes && !iskey,
2800
+ inblock
2801
+ )) {
2802
+ case STYLE_PLAIN:
2803
+ return string;
2804
+ case STYLE_SINGLE:
2805
+ return "'" + string.replace(/'/g, "''") + "'";
2806
+ case STYLE_LITERAL:
2807
+ return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
2808
+ case STYLE_FOLDED:
2809
+ return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
2810
+ case STYLE_DOUBLE:
2811
+ return '"' + escapeString(string) + '"';
2812
+ default:
2813
+ throw new exception("impossible error: invalid scalar style");
2814
+ }
2815
+ }();
2816
+ }
2817
+ function blockHeader(string, indentPerLevel) {
2818
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
2819
+ var clip = string[string.length - 1] === "\n";
2820
+ var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
2821
+ var chomp = keep ? "+" : clip ? "" : "-";
2822
+ return indentIndicator + chomp + "\n";
2823
+ }
2824
+ function dropEndingNewline(string) {
2825
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2826
+ }
2827
+ function foldString(string, width) {
2828
+ var lineRe = /(\n+)([^\n]*)/g;
2829
+ var result = function() {
2830
+ var nextLF = string.indexOf("\n");
2831
+ nextLF = nextLF !== -1 ? nextLF : string.length;
2832
+ lineRe.lastIndex = nextLF;
2833
+ return foldLine(string.slice(0, nextLF), width);
2834
+ }();
2835
+ var prevMoreIndented = string[0] === "\n" || string[0] === " ";
2836
+ var moreIndented;
2837
+ var match;
2838
+ while (match = lineRe.exec(string)) {
2839
+ var prefix = match[1], line = match[2];
2840
+ moreIndented = line[0] === " ";
2841
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2842
+ prevMoreIndented = moreIndented;
2843
+ }
2844
+ return result;
2845
+ }
2846
+ function foldLine(line, width) {
2847
+ if (line === "" || line[0] === " ")
2848
+ return line;
2849
+ var breakRe = / [^ ]/g;
2850
+ var match;
2851
+ var start = 0, end, curr = 0, next = 0;
2852
+ var result = "";
2853
+ while (match = breakRe.exec(line)) {
2854
+ next = match.index;
2855
+ if (next - start > width) {
2856
+ end = curr > start ? curr : next;
2857
+ result += "\n" + line.slice(start, end);
2858
+ start = end + 1;
2859
+ }
2860
+ curr = next;
2861
+ }
2862
+ result += "\n";
2863
+ if (line.length - start > width && curr > start) {
2864
+ result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
2865
+ } else {
2866
+ result += line.slice(start);
2867
+ }
2868
+ return result.slice(1);
2869
+ }
2870
+ function escapeString(string) {
2871
+ var result = "";
2872
+ var char = 0;
2873
+ var escapeSeq;
2874
+ for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2875
+ char = codePointAt(string, i);
2876
+ escapeSeq = ESCAPE_SEQUENCES[char];
2877
+ if (!escapeSeq && isPrintable(char)) {
2878
+ result += string[i];
2879
+ if (char >= 65536)
2880
+ result += string[i + 1];
2881
+ } else {
2882
+ result += escapeSeq || encodeHex(char);
2883
+ }
2884
+ }
2885
+ return result;
2886
+ }
2887
+ function writeFlowSequence(state, level, object) {
2888
+ var _result = "", _tag = state.tag, index, length, value;
2889
+ for (index = 0, length = object.length; index < length; index += 1) {
2890
+ value = object[index];
2891
+ if (state.replacer) {
2892
+ value = state.replacer.call(object, String(index), value);
2893
+ }
2894
+ if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
2895
+ if (_result !== "")
2896
+ _result += "," + (!state.condenseFlow ? " " : "");
2897
+ _result += state.dump;
2898
+ }
2899
+ }
2900
+ state.tag = _tag;
2901
+ state.dump = "[" + _result + "]";
2902
+ }
2903
+ function writeBlockSequence(state, level, object, compact) {
2904
+ var _result = "", _tag = state.tag, index, length, value;
2905
+ for (index = 0, length = object.length; index < length; index += 1) {
2906
+ value = object[index];
2907
+ if (state.replacer) {
2908
+ value = state.replacer.call(object, String(index), value);
2909
+ }
2910
+ if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
2911
+ if (!compact || _result !== "") {
2912
+ _result += generateNextLine(state, level);
2913
+ }
2914
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2915
+ _result += "-";
2916
+ } else {
2917
+ _result += "- ";
2918
+ }
2919
+ _result += state.dump;
2920
+ }
2921
+ }
2922
+ state.tag = _tag;
2923
+ state.dump = _result || "[]";
2924
+ }
2925
+ function writeFlowMapping(state, level, object) {
2926
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
2927
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2928
+ pairBuffer = "";
2929
+ if (_result !== "")
2930
+ pairBuffer += ", ";
2931
+ if (state.condenseFlow)
2932
+ pairBuffer += '"';
2933
+ objectKey = objectKeyList[index];
2934
+ objectValue = object[objectKey];
2935
+ if (state.replacer) {
2936
+ objectValue = state.replacer.call(object, objectKey, objectValue);
2937
+ }
2938
+ if (!writeNode(state, level, objectKey, false, false)) {
2939
+ continue;
2940
+ }
2941
+ if (state.dump.length > 1024)
2942
+ pairBuffer += "? ";
2943
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
2944
+ if (!writeNode(state, level, objectValue, false, false)) {
2945
+ continue;
2946
+ }
2947
+ pairBuffer += state.dump;
2948
+ _result += pairBuffer;
2949
+ }
2950
+ state.tag = _tag;
2951
+ state.dump = "{" + _result + "}";
2952
+ }
2953
+ function writeBlockMapping(state, level, object, compact) {
2954
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
2955
+ if (state.sortKeys === true) {
2956
+ objectKeyList.sort();
2957
+ } else if (typeof state.sortKeys === "function") {
2958
+ objectKeyList.sort(state.sortKeys);
2959
+ } else if (state.sortKeys) {
2960
+ throw new exception("sortKeys must be a boolean or a function");
2961
+ }
2962
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2963
+ pairBuffer = "";
2964
+ if (!compact || _result !== "") {
2965
+ pairBuffer += generateNextLine(state, level);
2966
+ }
2967
+ objectKey = objectKeyList[index];
2968
+ objectValue = object[objectKey];
2969
+ if (state.replacer) {
2970
+ objectValue = state.replacer.call(object, objectKey, objectValue);
2971
+ }
2972
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
2973
+ continue;
2974
+ }
2975
+ explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
2976
+ if (explicitPair) {
2977
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2978
+ pairBuffer += "?";
2979
+ } else {
2980
+ pairBuffer += "? ";
2981
+ }
2982
+ }
2983
+ pairBuffer += state.dump;
2984
+ if (explicitPair) {
2985
+ pairBuffer += generateNextLine(state, level);
2986
+ }
2987
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
2988
+ continue;
2989
+ }
2990
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2991
+ pairBuffer += ":";
2992
+ } else {
2993
+ pairBuffer += ": ";
2994
+ }
2995
+ pairBuffer += state.dump;
2996
+ _result += pairBuffer;
2997
+ }
2998
+ state.tag = _tag;
2999
+ state.dump = _result || "{}";
3000
+ }
3001
+ function detectType(state, object, explicit) {
3002
+ var _result, typeList, index, length, type2, style;
3003
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
3004
+ for (index = 0, length = typeList.length; index < length; index += 1) {
3005
+ type2 = typeList[index];
3006
+ if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
3007
+ if (explicit) {
3008
+ if (type2.multi && type2.representName) {
3009
+ state.tag = type2.representName(object);
3010
+ } else {
3011
+ state.tag = type2.tag;
3012
+ }
3013
+ } else {
3014
+ state.tag = "?";
3015
+ }
3016
+ if (type2.represent) {
3017
+ style = state.styleMap[type2.tag] || type2.defaultStyle;
3018
+ if (_toString.call(type2.represent) === "[object Function]") {
3019
+ _result = type2.represent(object, style);
3020
+ } else if (_hasOwnProperty.call(type2.represent, style)) {
3021
+ _result = type2.represent[style](object, style);
3022
+ } else {
3023
+ throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
3024
+ }
3025
+ state.dump = _result;
3026
+ }
3027
+ return true;
3028
+ }
3029
+ }
3030
+ return false;
3031
+ }
3032
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
3033
+ state.tag = null;
3034
+ state.dump = object;
3035
+ if (!detectType(state, object, false)) {
3036
+ detectType(state, object, true);
3037
+ }
3038
+ var type2 = _toString.call(state.dump);
3039
+ var inblock = block;
3040
+ var tagStr;
3041
+ if (block) {
3042
+ block = state.flowLevel < 0 || state.flowLevel > level;
3043
+ }
3044
+ var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
3045
+ if (objectOrArray) {
3046
+ duplicateIndex = state.duplicates.indexOf(object);
3047
+ duplicate = duplicateIndex !== -1;
3048
+ }
3049
+ if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
3050
+ compact = false;
3051
+ }
3052
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
3053
+ state.dump = "*ref_" + duplicateIndex;
3054
+ } else {
3055
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
3056
+ state.usedDuplicates[duplicateIndex] = true;
3057
+ }
3058
+ if (type2 === "[object Object]") {
3059
+ if (block && Object.keys(state.dump).length !== 0) {
3060
+ writeBlockMapping(state, level, state.dump, compact);
3061
+ if (duplicate) {
3062
+ state.dump = "&ref_" + duplicateIndex + state.dump;
3063
+ }
3064
+ } else {
3065
+ writeFlowMapping(state, level, state.dump);
3066
+ if (duplicate) {
3067
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
3068
+ }
3069
+ }
3070
+ } else if (type2 === "[object Array]") {
3071
+ if (block && state.dump.length !== 0) {
3072
+ if (state.noArrayIndent && !isblockseq && level > 0) {
3073
+ writeBlockSequence(state, level - 1, state.dump, compact);
3074
+ } else {
3075
+ writeBlockSequence(state, level, state.dump, compact);
3076
+ }
3077
+ if (duplicate) {
3078
+ state.dump = "&ref_" + duplicateIndex + state.dump;
3079
+ }
3080
+ } else {
3081
+ writeFlowSequence(state, level, state.dump);
3082
+ if (duplicate) {
3083
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
3084
+ }
3085
+ }
3086
+ } else if (type2 === "[object String]") {
3087
+ if (state.tag !== "?") {
3088
+ writeScalar(state, state.dump, level, iskey, inblock);
3089
+ }
3090
+ } else if (type2 === "[object Undefined]") {
3091
+ return false;
3092
+ } else {
3093
+ if (state.skipInvalid)
3094
+ return false;
3095
+ throw new exception("unacceptable kind of an object to dump " + type2);
3096
+ }
3097
+ if (state.tag !== null && state.tag !== "?") {
3098
+ tagStr = encodeURI(
3099
+ state.tag[0] === "!" ? state.tag.slice(1) : state.tag
3100
+ ).replace(/!/g, "%21");
3101
+ if (state.tag[0] === "!") {
3102
+ tagStr = "!" + tagStr;
3103
+ } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
3104
+ tagStr = "!!" + tagStr.slice(18);
3105
+ } else {
3106
+ tagStr = "!<" + tagStr + ">";
3107
+ }
3108
+ state.dump = tagStr + " " + state.dump;
3109
+ }
3110
+ }
3111
+ return true;
3112
+ }
3113
+ function getDuplicateReferences(object, state) {
3114
+ var objects = [], duplicatesIndexes = [], index, length;
3115
+ inspectNode(object, objects, duplicatesIndexes);
3116
+ for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
3117
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
3118
+ }
3119
+ state.usedDuplicates = new Array(length);
3120
+ }
3121
+ function inspectNode(object, objects, duplicatesIndexes) {
3122
+ var objectKeyList, index, length;
3123
+ if (object !== null && typeof object === "object") {
3124
+ index = objects.indexOf(object);
3125
+ if (index !== -1) {
3126
+ if (duplicatesIndexes.indexOf(index) === -1) {
3127
+ duplicatesIndexes.push(index);
3128
+ }
3129
+ } else {
3130
+ objects.push(object);
3131
+ if (Array.isArray(object)) {
3132
+ for (index = 0, length = object.length; index < length; index += 1) {
3133
+ inspectNode(object[index], objects, duplicatesIndexes);
3134
+ }
3135
+ } else {
3136
+ objectKeyList = Object.keys(object);
3137
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
3138
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
3139
+ }
3140
+ }
3141
+ }
3142
+ }
3143
+ }
3144
+ function dump$1(input, options) {
3145
+ options = options || {};
3146
+ var state = new State(options);
3147
+ if (!state.noRefs)
3148
+ getDuplicateReferences(input, state);
3149
+ var value = input;
3150
+ if (state.replacer) {
3151
+ value = state.replacer.call({ "": value }, "", value);
3152
+ }
3153
+ if (writeNode(state, 0, value, true, true))
3154
+ return state.dump + "\n";
3155
+ return "";
3156
+ }
3157
+ var dump_1 = dump$1;
3158
+ var dumper = {
3159
+ dump: dump_1
3160
+ };
3161
+ function renamed(from, to) {
3162
+ return function() {
3163
+ throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
3164
+ };
3165
+ }
3166
+ var Type = type;
3167
+ var Schema = schema;
3168
+ var FAILSAFE_SCHEMA = failsafe;
3169
+ var JSON_SCHEMA = json;
3170
+ var CORE_SCHEMA = core;
3171
+ var DEFAULT_SCHEMA = _default;
3172
+ var load = loader.load;
3173
+ var loadAll = loader.loadAll;
3174
+ var dump = dumper.dump;
3175
+ var YAMLException = exception;
3176
+ var types = {
3177
+ binary,
3178
+ float,
3179
+ map,
3180
+ null: _null,
3181
+ pairs,
3182
+ set,
3183
+ timestamp,
3184
+ bool,
3185
+ int,
3186
+ merge,
3187
+ omap,
3188
+ seq,
3189
+ str
3190
+ };
3191
+ var safeLoad = renamed("safeLoad", "load");
3192
+ var safeLoadAll = renamed("safeLoadAll", "loadAll");
3193
+ var safeDump = renamed("safeDump", "dump");
3194
+ var jsYaml = {
3195
+ Type,
3196
+ Schema,
3197
+ FAILSAFE_SCHEMA,
3198
+ JSON_SCHEMA,
3199
+ CORE_SCHEMA,
3200
+ DEFAULT_SCHEMA,
3201
+ load,
3202
+ loadAll,
3203
+ dump,
3204
+ YAMLException,
3205
+ types,
3206
+ safeLoad,
3207
+ safeLoadAll,
3208
+ safeDump
3209
+ };
3210
+ var js_yaml_default = jsYaml;
3211
+
3212
+ // src/yaml/utils.ts
3213
+ var import_node_assert2 = __toESM(require("assert"));
3214
+ function interpolateEnvVars(content) {
3215
+ return content.replace(/\$\{([^}]+)\}/g, (_, envVar) => {
3216
+ const value = process.env[envVar.trim()];
3217
+ if (value === void 0) {
3218
+ throw new Error(`Environment variable "${envVar.trim()}" is not defined`);
3219
+ }
3220
+ return value;
3221
+ });
3222
+ }
3223
+ function parseYamlScript(content, filePath, ignoreCheckingTarget) {
3224
+ const interpolatedContent = interpolateEnvVars(content);
3225
+ const obj = js_yaml_default.load(interpolatedContent);
3226
+ const pathTip = filePath ? `, failed to load ${filePath}` : "";
3227
+ if (!ignoreCheckingTarget) {
3228
+ (0, import_node_assert2.default)(
3229
+ obj.target,
3230
+ `property "target" is required in yaml script${pathTip}`
3231
+ );
3232
+ (0, import_node_assert2.default)(
3233
+ typeof obj.target === "object",
3234
+ `property "target" must be an object${pathTip}`
3235
+ );
3236
+ }
3237
+ (0, import_node_assert2.default)(obj.tasks, `property "tasks" is required in yaml script ${pathTip}`);
3238
+ (0, import_node_assert2.default)(
3239
+ Array.isArray(obj.tasks),
3240
+ `property "tasks" must be an array in yaml script, but got ${obj.tasks}`
3241
+ );
3242
+ return obj;
3243
+ }
3244
+
3245
+ // src/common/agent.ts
339
3246
  var import_env3 = require("@midscene/core/env");
340
3247
  var import_utils6 = require("@midscene/core/utils");
341
3248
 
342
3249
  // src/common/tasks.ts
343
- var import_node_assert = __toESM(require("assert"));
3250
+ var import_node_assert3 = __toESM(require("assert"));
344
3251
  var import_core = require("@midscene/core");
345
3252
  var import_ai_model = require("@midscene/core/ai-model");
346
3253
  var import_utils3 = require("@midscene/core/utils");
347
3254
 
348
3255
  // src/common/task-cache.ts
349
- var import_node_fs = require("fs");
350
- var import_node_path = require("path");
3256
+ var import_node_fs2 = require("fs");
3257
+ var import_node_path2 = require("path");
351
3258
  var import_env = require("@midscene/core/env");
352
3259
  var import_utils = require("@midscene/core/utils");
353
3260
  var import_fs = require("@midscene/shared/fs");
@@ -372,29 +3279,29 @@ var TaskCache = class {
372
3279
  tasks: newCacheGroup
373
3280
  });
374
3281
  return {
375
- readCache: (pageContext, type, actionPrompt) => {
3282
+ readCache: (pageContext, type2, actionPrompt) => {
376
3283
  if (index === -1) {
377
3284
  return false;
378
3285
  }
379
- if (type === "plan") {
3286
+ if (type2 === "plan") {
380
3287
  return this.readCache(
381
3288
  pageContext,
382
- type,
3289
+ type2,
383
3290
  actionPrompt,
384
3291
  aiTasks[index].tasks
385
3292
  );
386
3293
  }
387
- if (type === "ui-tars-plan") {
3294
+ if (type2 === "ui-tars-plan") {
388
3295
  return this.readCache(
389
3296
  pageContext,
390
- type,
3297
+ type2,
391
3298
  actionPrompt,
392
3299
  aiTasks[index].tasks
393
3300
  );
394
3301
  }
395
3302
  return this.readCache(
396
3303
  pageContext,
397
- type,
3304
+ type2,
398
3305
  actionPrompt,
399
3306
  aiTasks[index].tasks
400
3307
  );
@@ -405,7 +3312,7 @@ var TaskCache = class {
405
3312
  }
406
3313
  };
407
3314
  }
408
- readCache(pageContext, type, userPrompt, cacheGroup) {
3315
+ readCache(pageContext, type2, userPrompt, cacheGroup) {
409
3316
  var _a;
410
3317
  if (cacheGroup.length > 0) {
411
3318
  const index = cacheGroup.findIndex((item) => item.prompt === userPrompt);
@@ -424,7 +3331,7 @@ var TaskCache = class {
424
3331
  }))) {
425
3332
  return false;
426
3333
  }
427
- if (taskRes && taskRes.type === type && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
3334
+ if (taskRes && taskRes.type === type2 && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
428
3335
  return taskRes.response;
429
3336
  }
430
3337
  }
@@ -447,10 +3354,10 @@ var TaskCache = class {
447
3354
  if (import_utils2.ifInBrowser || !this.cacheId) {
448
3355
  return void 0;
449
3356
  }
450
- const cacheFile = (0, import_node_path.join)((0, import_utils.getLogDirByType)("cache"), `${this.cacheId}.json`);
451
- if ((0, import_env.getAIConfig)("MIDSCENE_CACHE") === "true" && (0, import_node_fs.existsSync)(cacheFile)) {
3357
+ const cacheFile = (0, import_node_path2.join)((0, import_utils.getLogDirByType)("cache"), `${this.cacheId}.json`);
3358
+ if ((0, import_env.getAIConfig)("MIDSCENE_CACHE") === "true" && (0, import_node_fs2.existsSync)(cacheFile)) {
452
3359
  try {
453
- const data = (0, import_node_fs.readFileSync)(cacheFile, "utf8");
3360
+ const data = (0, import_node_fs2.readFileSync)(cacheFile, "utf8");
454
3361
  const jsonData = JSON.parse(data);
455
3362
  if (!this.midscenePkgInfo) {
456
3363
  return void 0;
@@ -561,13 +3468,13 @@ var PageTaskExecutor = class {
561
3468
  locate: plan2.locate,
562
3469
  executor: async (param, taskContext) => {
563
3470
  const { task } = taskContext;
564
- (0, import_node_assert.default)(
3471
+ (0, import_node_assert3.default)(
565
3472
  (param == null ? void 0 : param.prompt) || (param == null ? void 0 : param.id) || (param == null ? void 0 : param.position),
566
3473
  "No prompt or id or position to locate"
567
3474
  );
568
3475
  let insightDump;
569
- const dumpCollector = (dump) => {
570
- insightDump = dump;
3476
+ const dumpCollector = (dump2) => {
3477
+ insightDump = dump2;
571
3478
  };
572
3479
  this.insight.onceDumpUpdatedFn = dumpCollector;
573
3480
  const shotTime = Date.now();
@@ -646,8 +3553,8 @@ var PageTaskExecutor = class {
646
3553
  executor: async (param, taskContext) => {
647
3554
  const { task } = taskContext;
648
3555
  let insightDump;
649
- const dumpCollector = (dump) => {
650
- insightDump = dump;
3556
+ const dumpCollector = (dump2) => {
3557
+ insightDump = dump2;
651
3558
  };
652
3559
  this.insight.onceDumpUpdatedFn = dumpCollector;
653
3560
  const assertion = await this.insight.assert(
@@ -702,7 +3609,7 @@ var PageTaskExecutor = class {
702
3609
  thought: plan2.thought,
703
3610
  locate: plan2.locate,
704
3611
  executor: async (taskParam) => {
705
- (0, import_node_assert.default)(taskParam == null ? void 0 : taskParam.value, "No key to press");
3612
+ (0, import_node_assert3.default)(taskParam == null ? void 0 : taskParam.value, "No key to press");
706
3613
  await this.page.keyboard.press(taskParam.value);
707
3614
  }
708
3615
  };
@@ -714,7 +3621,7 @@ var PageTaskExecutor = class {
714
3621
  thought: plan2.thought,
715
3622
  locate: plan2.locate,
716
3623
  executor: async (param, { element }) => {
717
- (0, import_node_assert.default)(element, "Element not found, cannot tap");
3624
+ (0, import_node_assert3.default)(element, "Element not found, cannot tap");
718
3625
  await this.page.mouse.click(element.center[0], element.center[1]);
719
3626
  }
720
3627
  };
@@ -727,7 +3634,7 @@ var PageTaskExecutor = class {
727
3634
  thought: plan2.thought,
728
3635
  locate: plan2.locate,
729
3636
  executor: async (taskParam) => {
730
- (0, import_node_assert.default)(
3637
+ (0, import_node_assert3.default)(
731
3638
  (taskParam == null ? void 0 : taskParam.start_box) && (taskParam == null ? void 0 : taskParam.end_box),
732
3639
  "No start_box or end_box to drag"
733
3640
  );
@@ -742,7 +3649,7 @@ var PageTaskExecutor = class {
742
3649
  thought: plan2.thought,
743
3650
  locate: plan2.locate,
744
3651
  executor: async (param, { element }) => {
745
- (0, import_node_assert.default)(element, "Element not found, cannot hover");
3652
+ (0, import_node_assert3.default)(element, "Element not found, cannot hover");
746
3653
  await this.page.mouse.move(element.center[0], element.center[1]);
747
3654
  }
748
3655
  };
@@ -928,7 +3835,7 @@ var PageTaskExecutor = class {
928
3835
  },
929
3836
  []
930
3837
  );
931
- (0, import_node_assert.default)(
3838
+ (0, import_node_assert3.default)(
932
3839
  finalActions.length > 0,
933
3840
  error ? `No plan: ${error}` : "No plans found"
934
3841
  );
@@ -1169,8 +4076,8 @@ var PageTaskExecutor = class {
1169
4076
  },
1170
4077
  executor: async (param) => {
1171
4078
  let insightDump;
1172
- const dumpCollector = (dump) => {
1173
- insightDump = dump;
4079
+ const dumpCollector = (dump2) => {
4080
+ insightDump = dump2;
1174
4081
  };
1175
4082
  this.insight.onceDumpUpdatedFn = dumpCollector;
1176
4083
  const data = await this.insight.extract(param.dataDemand);
@@ -1252,9 +4159,9 @@ var PageTaskExecutor = class {
1252
4159
  const description = `waitFor: ${assertion}`;
1253
4160
  const taskExecutor = new import_core.Executor(description);
1254
4161
  const { timeoutMs, checkIntervalMs } = opt;
1255
- (0, import_node_assert.default)(assertion, "No assertion for waitFor");
1256
- (0, import_node_assert.default)(timeoutMs, "No timeoutMs for waitFor");
1257
- (0, import_node_assert.default)(checkIntervalMs, "No checkIntervalMs for waitFor");
4162
+ (0, import_node_assert3.default)(assertion, "No assertion for waitFor");
4163
+ (0, import_node_assert3.default)(timeoutMs, "No timeoutMs for waitFor");
4164
+ (0, import_node_assert3.default)(checkIntervalMs, "No checkIntervalMs for waitFor");
1258
4165
  const overallStartTime = Date.now();
1259
4166
  let startTime = Date.now();
1260
4167
  let errorThought = "";
@@ -1366,9 +4273,9 @@ function paramStr(task) {
1366
4273
  }
1367
4274
 
1368
4275
  // src/common/utils.ts
1369
- var import_node_assert2 = __toESM(require("assert"));
1370
- var import_node_fs2 = require("fs");
1371
- var import_node_path2 = __toESM(require("path"));
4276
+ var import_node_assert4 = __toESM(require("assert"));
4277
+ var import_node_fs3 = require("fs");
4278
+ var import_node_path3 = __toESM(require("path"));
1372
4279
  var import_env2 = require("@midscene/core/env");
1373
4280
  var import_utils4 = require("@midscene/core/utils");
1374
4281
  var import_constants = require("@midscene/shared/constants");
@@ -1378,7 +4285,7 @@ var import_img = require("@midscene/shared/img");
1378
4285
  var import_utils5 = require("@midscene/shared/utils");
1379
4286
  var import_dayjs = __toESM(require_dayjs_min());
1380
4287
  async function parseContextFromWebPage(page, _opt) {
1381
- (0, import_node_assert2.default)(page, "page is required");
4288
+ (0, import_node_assert4.default)(page, "page is required");
1382
4289
  if (page._forceUsePageContext) {
1383
4290
  return await page._forceUsePageContext();
1384
4291
  }
@@ -1406,7 +4313,7 @@ async function parseContextFromWebPage(page, _opt) {
1406
4313
  });
1407
4314
  });
1408
4315
  const elementsInfo = (0, import_extractor.treeToList)(webTree);
1409
- (0, import_node_assert2.default)(screenshotBase64, "screenshotBase64 is required");
4316
+ (0, import_node_assert4.default)(screenshotBase64, "screenshotBase64 is required");
1410
4317
  const elementsPositionInfoWithoutText = elementsInfo.filter(
1411
4318
  (elementInfo) => {
1412
4319
  if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
@@ -1610,27 +4517,45 @@ ${reasonMsg}`);
1610
4517
  ${errorTask == null ? void 0 : errorTask.errorStack}`);
1611
4518
  }
1612
4519
  }
1613
- async ai(taskPrompt, type = "action") {
1614
- if (type === "action") {
4520
+ async ai(taskPrompt, type2 = "action") {
4521
+ if (type2 === "action") {
1615
4522
  return this.aiAction(taskPrompt);
1616
4523
  }
1617
- if (type === "query") {
4524
+ if (type2 === "query") {
1618
4525
  return this.aiQuery(taskPrompt);
1619
4526
  }
1620
- if (type === "assert") {
4527
+ if (type2 === "assert") {
1621
4528
  return this.aiAssert(taskPrompt);
1622
4529
  }
1623
4530
  throw new Error(
1624
- `Unknown type: ${type}, only support 'action', 'query', 'assert'`
4531
+ `Unknown type: ${type2}, only support 'action', 'query', 'assert'`
1625
4532
  );
1626
4533
  }
4534
+ async runYaml(yamlScriptContent) {
4535
+ const script = parseYamlScript(yamlScriptContent, "yaml", true);
4536
+ const player = new ScriptPlayer(script, async (target) => {
4537
+ return { agent: this, freeFn: [] };
4538
+ });
4539
+ await player.run();
4540
+ if (player.status === "error") {
4541
+ const errors = player.taskStatusList.filter((task) => task.status === "error").map((task) => {
4542
+ var _a;
4543
+ return `task - ${task.name}: ${(_a = task.error) == null ? void 0 : _a.message}`;
4544
+ }).join("\n");
4545
+ throw new Error(`Error(s) occurred in running yaml script:
4546
+ ${errors}`);
4547
+ }
4548
+ return {
4549
+ result: player.result
4550
+ };
4551
+ }
1627
4552
  async destroy() {
1628
4553
  await this.page.destroy();
1629
4554
  }
1630
4555
  };
1631
4556
 
1632
4557
  // src/appium/page.ts
1633
- var import_node_fs3 = __toESM(require("fs"));
4558
+ var import_node_fs4 = __toESM(require("fs"));
1634
4559
  var import_utils9 = require("@midscene/core/utils");
1635
4560
  var import_extractor2 = require("@midscene/shared/extractor");
1636
4561
  var import_img2 = require("@midscene/shared/img");
@@ -1667,7 +4592,7 @@ var Page = class {
1667
4592
  width,
1668
4593
  height
1669
4594
  });
1670
- import_node_fs3.default.writeFileSync(path2, resizedScreenshotBuffer);
4595
+ import_node_fs4.default.writeFileSync(path2, resizedScreenshotBuffer);
1671
4596
  return (0, import_img2.base64Encoded)(path2);
1672
4597
  }
1673
4598
  get mouse() {
@@ -1880,3 +4805,8 @@ var Page = class {
1880
4805
  AppiumAgent,
1881
4806
  AppiumPage
1882
4807
  });
4808
+ /*! Bundled license information:
4809
+
4810
+ js-yaml/dist/js-yaml.mjs:
4811
+ (*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
4812
+ */