UNPKG

js-yaml

Version:

YAML 1.2 parser and serializer

1,389 lines 121 kB
/*! js-yaml 5.2.0 https://github.com/nodeca/js-yaml @license MIT */ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); //#region src/tag.ts var NOT_RESOLVED = Symbol("NOT_RESOLVED"); var MERGE_KEY = Symbol("MERGE_KEY"); function defineScalarTag(tagName, options) { var _options$implicit, _options$matchByTagPr, _options$implicitFirs, _options$identify, _options$represent, _options$representTag; return { tagName, nodeKind: "scalar", implicit: (_options$implicit = options.implicit) !== null && _options$implicit !== void 0 ? _options$implicit : false, matchByTagPrefix: (_options$matchByTagPr = options.matchByTagPrefix) !== null && _options$matchByTagPr !== void 0 ? _options$matchByTagPr : false, implicitFirstChars: (_options$implicitFirs = options.implicitFirstChars) !== null && _options$implicitFirs !== void 0 ? _options$implicitFirs : null, resolve: options.resolve, identify: (_options$identify = options.identify) !== null && _options$identify !== void 0 ? _options$identify : null, represent: (_options$represent = options.represent) !== null && _options$represent !== void 0 ? _options$represent : ((data) => String(data)), representTagName: (_options$representTag = options.representTagName) !== null && _options$representTag !== void 0 ? _options$representTag : null }; } function defineSequenceTag(tagName, options) { var _options$matchByTagPr2, _options$finalize, _options$identify2, _options$represent2, _options$representTag2; const carrierIsResult = options.finalize === void 0; return { tagName, nodeKind: "sequence", implicit: false, matchByTagPrefix: (_options$matchByTagPr2 = options.matchByTagPrefix) !== null && _options$matchByTagPr2 !== void 0 ? _options$matchByTagPr2 : false, create: options.create, addItem: options.addItem, finalize: (_options$finalize = options.finalize) !== null && _options$finalize !== void 0 ? _options$finalize : ((carrier) => carrier), carrierIsResult, identify: (_options$identify2 = options.identify) !== null && _options$identify2 !== void 0 ? _options$identify2 : null, represent: (_options$represent2 = options.represent) !== null && _options$represent2 !== void 0 ? _options$represent2 : ((data) => data), representTagName: (_options$representTag2 = options.representTagName) !== null && _options$representTag2 !== void 0 ? _options$representTag2 : null }; } function defineMappingTag(tagName, options) { var _options$matchByTagPr3, _options$finalize2, _options$identify3, _options$represent3, _options$representTag3; const carrierIsResult = options.finalize === void 0; return { tagName, nodeKind: "mapping", implicit: false, matchByTagPrefix: (_options$matchByTagPr3 = options.matchByTagPrefix) !== null && _options$matchByTagPr3 !== void 0 ? _options$matchByTagPr3 : false, create: options.create, addPair: options.addPair, has: options.has, keys: options.keys, get: options.get, finalize: (_options$finalize2 = options.finalize) !== null && _options$finalize2 !== void 0 ? _options$finalize2 : ((carrier) => carrier), carrierIsResult, identify: (_options$identify3 = options.identify) !== null && _options$identify3 !== void 0 ? _options$identify3 : null, represent: (_options$represent3 = options.represent) !== null && _options$represent3 !== void 0 ? _options$represent3 : ((data) => data), representTagName: (_options$representTag3 = options.representTagName) !== null && _options$representTag3 !== void 0 ? _options$representTag3 : null }; } //#endregion //#region src/tag/scalar/str.ts var strTag = defineScalarTag("tag:yaml.org,2002:str", { resolve: (source) => source, identify: (data) => typeof data === "string" }); //#endregion //#region src/tag/scalar/null_core.ts var NULL_VALUES$1 = [ "", "~", "null", "Null", "NULL" ]; var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", { implicit: true, implicitFirstChars: [ "", "~", "n", "N" ], resolve: (source) => { if (NULL_VALUES$1.indexOf(source) !== -1) return null; return NOT_RESOLVED; }, identify: (object) => object === null, represent: () => "null" }); //#endregion //#region src/tag/scalar/null_json.ts var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", { implicit: true, implicitFirstChars: ["n"], resolve: (source, isExplicit) => { if (source === "null" || isExplicit && source === "") return null; return NOT_RESOLVED; }, identify: (object) => object === null, represent: () => "null" }); //#endregion //#region src/tag/scalar/null_yaml11.ts var NULL_VALUES = [ "", "~", "null", "Null", "NULL" ]; var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", { implicit: true, implicitFirstChars: [ "", "~", "n", "N" ], resolve: (source) => { if (NULL_VALUES.indexOf(source) !== -1) return null; return NOT_RESOLVED; }, identify: (object) => object === null, represent: () => "null" }); //#endregion //#region src/tag/scalar/bool_core.ts var TRUE_VALUES$2 = [ "true", "True", "TRUE" ]; var FALSE_VALUES$2 = [ "false", "False", "FALSE" ]; var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", { implicit: true, implicitFirstChars: [ "t", "T", "f", "F" ], resolve: (source) => { if (TRUE_VALUES$2.indexOf(source) !== -1) return true; if (FALSE_VALUES$2.indexOf(source) !== -1) return false; return NOT_RESOLVED; }, identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]", represent: (object) => object ? "true" : "false" }); //#endregion //#region src/tag/scalar/bool_json.ts var TRUE_VALUES$1 = ["true"]; var FALSE_VALUES$1 = ["false"]; var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", { implicit: true, implicitFirstChars: ["t", "f"], resolve: (source) => { if (TRUE_VALUES$1.indexOf(source) !== -1) return true; if (FALSE_VALUES$1.indexOf(source) !== -1) return false; return NOT_RESOLVED; }, identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]", represent: (object) => object ? "true" : "false" }); //#endregion //#region src/tag/scalar/bool_yaml11.ts var TRUE_VALUES = [ "true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES", "on", "On", "ON" ]; var FALSE_VALUES = [ "false", "False", "FALSE", "n", "N", "no", "No", "NO", "off", "Off", "OFF" ]; var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", { implicit: true, implicitFirstChars: [ "y", "Y", "n", "N", "t", "T", "f", "F", "o", "O" ], resolve: (source) => { if (TRUE_VALUES.indexOf(source) !== -1) return true; if (FALSE_VALUES.indexOf(source) !== -1) return false; return NOT_RESOLVED; }, identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]", represent: (object) => object ? "true" : "false" }); //#endregion //#region src/tag/scalar/int_core.ts var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$"); var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$"); function parseYamlInteger$2(source) { let value = source; let sign = 1; if (value[0] === "-" || value[0] === "+") { if (value[0] === "-") sign = -1; value = value.slice(1); } if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2); if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8); if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16); return sign * parseInt(value, 10); } function resolveYamlInteger$2(source, isExplicit) { if (isExplicit) { if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED; } else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED; const result = parseYamlInteger$2(source); return Number.isFinite(result) ? result : NOT_RESOLVED; } var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", { implicit: true, implicitFirstChars: [ "-", "+", ..."0123456789" ], resolve: resolveYamlInteger$2, identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0, represent: (object) => object.toString(10) }); //#endregion //#region src/tag/scalar/int_json.ts var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$"); var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$"); function parseYamlInteger$1(source) { let value = source; let sign = 1; if (value[0] === "-" || value[0] === "+") { if (value[0] === "-") sign = -1; value = value.slice(1); } if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2); if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8); if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16); return sign * parseInt(value, 10); } function resolveYamlInteger$1(source, isExplicit) { if (isExplicit) { if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED; } else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED; const result = parseYamlInteger$1(source); return Number.isFinite(result) ? result : NOT_RESOLVED; } var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", { implicit: true, implicitFirstChars: ["-", ..."0123456789"], resolve: resolveYamlInteger$1, identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0, represent: (object) => object.toString(10) }); //#endregion //#region src/tag/scalar/int_yaml11.ts var YAML_INTEGER_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?0x[0-9a-fA-F_]+|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+|[-+]?(?:0|[1-9][0-9_]*))$"); function parseYamlInteger(source) { let value = source.replace(/_/g, ""); let sign = 1; if (value[0] === "-" || value[0] === "+") { if (value[0] === "-") sign = -1; value = value.slice(1); } if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2); if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16); if (value.includes(":")) { let result = 0; for (const part of value.split(":")) result = result * 60 + Number(part); return sign * result; } if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8); return sign * parseInt(value, 10); } function resolveYamlInteger(source) { if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED; const result = parseYamlInteger(source); return Number.isFinite(result) ? result : NOT_RESOLVED; } var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", { implicit: true, implicitFirstChars: [ "-", "+", ..."0123456789" ], resolve: resolveYamlInteger, identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0, represent: (object) => object.toString(10) }); //#endregion //#region src/tag/scalar/float_core.ts var YAML_FLOAT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); function resolveYamlFloat$2(source) { if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED; let value = source.toLowerCase(); const sign = value[0] === "-" ? -1 : 1; if ("+-".includes(value[0])) value = value.slice(1); if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; if (value === ".nan") return NaN; const result = sign * parseFloat(value); if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result; return NOT_RESOLVED; } function representYamlFloat$2(object) { if (isNaN(object)) return ".nan"; if (object === Number.POSITIVE_INFINITY) return ".inf"; if (object === Number.NEGATIVE_INFINITY) return "-.inf"; if (Object.is(object, -0)) return "-0.0"; const result = object.toString(10); return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result; } var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", { implicit: true, implicitFirstChars: [ "-", "+", ".", ..."0123456789" ], resolve: resolveYamlFloat$2, identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0), represent: representYamlFloat$2 }); //#endregion //#region src/tag/scalar/float_json.ts var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$"); var YAML_FLOAT_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); function resolveYamlFloat$1(source, isExplicit) { if (isExplicit) { if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED; let value = source.toLowerCase(); const sign = value[0] === "-" ? -1 : 1; if ("+-".includes(value[0])) value = value.slice(1); if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; if (value === ".nan") return NaN; const result = sign * parseFloat(value); return Number.isFinite(result) ? result : NOT_RESOLVED; } if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED; const result = Number(source); if (Number.isFinite(result)) return result; return NOT_RESOLVED; } function representYamlFloat$1(object) { if (isNaN(object)) return ".nan"; if (object === Number.POSITIVE_INFINITY) return ".inf"; if (object === Number.NEGATIVE_INFINITY) return "-.inf"; if (Object.is(object, -0)) return "-0.0"; const result = object.toString(10); return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result; } var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", { implicit: true, implicitFirstChars: ["-", ..."0123456789"], resolve: resolveYamlFloat$1, identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0), represent: representYamlFloat$1 }); //#endregion //#region src/tag/scalar/float_yaml11.ts var YAML_FLOAT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:(?:[0-9][0-9_]*)?\\.[0-9_]*)(?:[eE][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); function resolveYamlFloat(source) { if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED; let value = source.toLowerCase().replace(/_/g, ""); const sign = value[0] === "-" ? -1 : 1; if ("+-".includes(value[0])) value = value.slice(1); if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; if (value === ".nan") return NaN; let result = 0; if (value.includes(":")) { for (const part of value.split(":")) result = result * 60 + Number(part); result *= sign; } else result = sign * parseFloat(value); if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result; return NOT_RESOLVED; } function representYamlFloat(object) { if (isNaN(object)) return ".nan"; if (object === Number.POSITIVE_INFINITY) return ".inf"; if (object === Number.NEGATIVE_INFINITY) return "-.inf"; if (Object.is(object, -0)) return "-0.0"; const result = object.toString(10); return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result; } var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", { implicit: true, implicitFirstChars: [ "-", "+", ".", ..."0123456789" ], resolve: resolveYamlFloat, identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0), represent: representYamlFloat }); //#endregion //#region src/tag/scalar/merge.ts var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", { implicit: true, implicitFirstChars: ["<"], resolve: (source, isExplicit) => { if (source === "<<" || isExplicit && source === "") return MERGE_KEY; return NOT_RESOLVED; } }); //#endregion //#region src/tag/scalar/binary.ts var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/; function resolveYamlBinary(source) { const input = source.replace(/\s/g, ""); if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED; const binary = atob(input); const result = new Uint8Array(binary.length); for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index); return result; } function representYamlBinary(object) { let binary = ""; for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]); return btoa(binary); } var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", { resolve: resolveYamlBinary, identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]", represent: representYamlBinary }); //#endregion //#region src/tag/scalar/timestamp.ts var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"); var YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"); function resolveYamlTimestamp(source) { let match = YAML_DATE_REGEXP.exec(source); if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source); if (match === null) return NOT_RESOLVED; const year = +match[1]; const month = +match[2] - 1; const day = +match[3]; if (!match[4]) { const date = new Date(Date.UTC(year, month, day)); if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED; return date; } const hour = +match[4]; const minute = +match[5]; const second = +match[6]; let fraction = 0; if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED; if (match[7]) { let value = match[7].slice(0, 3); while (value.length < 3) value += "0"; fraction = +value; } const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED; if (match[9]) { const offsetHour = +match[10]; const offsetMinute = +(match[11] || 0); if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED; const offset = (offsetHour * 60 + offsetMinute) * 6e4; date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset)); } return date; } var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", { implicit: true, implicitFirstChars: [..."0123456789"], resolve: resolveYamlTimestamp, identify: (object) => object instanceof Date, represent: (object) => object.toISOString() }); //#endregion //#region src/tag/sequence/seq.ts var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", { create: () => [], addItem: (container, item) => { container.push(item); }, identify: Array.isArray }); //#endregion //#region src/tag/sequence/omap.ts var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", { create: () => [], addItem: (container, item) => { if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve an ordered map item"; const object = item; const itemKeys = Object.keys(object); if (itemKeys.length !== 1) return "cannot resolve an ordered map item"; for (const existing of container) if (Object.prototype.hasOwnProperty.call(existing, itemKeys[0])) return "cannot resolve an ordered map item"; container.push(object); return ""; } }); //#endregion //#region src/tag/sequence/pairs.ts var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", { create: () => [], addItem: (container, item) => { if (item instanceof Map) { if (item.size !== 1) return "cannot resolve a pairs item"; container.push(item.entries().next().value); return ""; } if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item"; const object = item; const keys = Object.keys(object); if (keys.length !== 1) return "cannot resolve a pairs item"; container.push([keys[0], object[keys[0]]]); return ""; } }); //#endregion //#region src/common/object.ts function isPlainObject(data) { if (data === null || typeof data !== "object" || Array.isArray(data)) return false; const prototype = Object.getPrototypeOf(data); return prototype === null || prototype === Object.prototype; } function pick(object, keys) { const result = {}; for (const key of keys) if (object[key] !== void 0) result[key] = object[key]; return result; } //#endregion //#region src/tag/mapping/map.ts var mapTag = defineMappingTag("tag:yaml.org,2002:map", { create: () => ({}), identify: isPlainObject, represent: (o) => { const map = /* @__PURE__ */ new Map(); for (const key of Object.keys(o)) map.set(key, o[key]); return map; }, addPair: (container, key, value) => { if (key !== null && typeof key === "object") return "object-based map does not support complex keys"; const normalizedKey = String(key); if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, { value, enumerable: true, configurable: true, writable: true }); else container[normalizedKey] = value; return ""; }, has: (container, key) => { if (key !== null && typeof key === "object") return false; return Object.prototype.hasOwnProperty.call(container, String(key)); }, keys: (container) => Object.keys(container), get: (container, key) => container[String(key)] }); //#endregion //#region src/tag/mapping/set.ts var setTag = defineMappingTag("tag:yaml.org,2002:set", { create: () => /* @__PURE__ */ new Set(), identify: (data) => data instanceof Set, represent: (data) => { const map = /* @__PURE__ */ new Map(); for (const key of data) map.set(key, null); return map; }, addPair: (container, key, value) => { if (value !== null) return "cannot resolve a set item"; container.add(key); return ""; }, has: (container, key) => container.has(key), keys: (container) => container.keys(), get: () => null }); //#endregion //#region \0@oxc-project+runtime@0.132.0/helpers/typeof.js function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) { return typeof o; } : function(o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } //#endregion //#region \0@oxc-project+runtime@0.132.0/helpers/toPrimitive.js function toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } //#endregion //#region \0@oxc-project+runtime@0.132.0/helpers/toPropertyKey.js function toPropertyKey(t) { var i = toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } //#endregion //#region \0@oxc-project+runtime@0.132.0/helpers/defineProperty.js function _defineProperty(e, r, t) { return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } //#endregion //#region src/schema.ts function createTagDefinitionMap() { return { scalar: {}, sequence: {}, mapping: {} }; } function createTagDefinitionListMap() { return { scalar: [], sequence: [], mapping: [] }; } function compileTags(tags) { const result = []; for (const tag of tags) { let index = result.length; for (let previousIndex = 0; previousIndex < result.length; previousIndex++) { const previous = result[previousIndex]; if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) { index = previousIndex; break; } } result[index] = tag; } return result; } var Schema = class Schema { constructor(tags) { _defineProperty(this, "tags", void 0); _defineProperty(this, "implicitScalarTags", void 0); _defineProperty(this, "implicitScalarByFirstChar", void 0); _defineProperty(this, "implicitScalarAnyFirstChar", void 0); _defineProperty(this, "defaultScalarTag", void 0); _defineProperty(this, "defaultSequenceTag", void 0); _defineProperty(this, "defaultMappingTag", void 0); _defineProperty(this, "exact", void 0); _defineProperty(this, "prefix", void 0); const compiledTags = compileTags(tags); const implicitScalarTags = []; const exact = createTagDefinitionMap(); const prefix = createTagDefinitionListMap(); for (const tag of compiledTags) { if (tag.nodeKind === "scalar" && tag.implicit) { if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix"); implicitScalarTags.push(tag); } switch (tag.nodeKind) { case "scalar": if (tag.matchByTagPrefix) prefix.scalar.push(tag); else exact.scalar[tag.tagName] = tag; break; case "sequence": if (tag.matchByTagPrefix) prefix.sequence.push(tag); else exact.sequence[tag.tagName] = tag; break; case "mapping": if (tag.matchByTagPrefix) prefix.mapping.push(tag); else exact.mapping[tag.tagName] = tag; break; } } const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null); const keys = /* @__PURE__ */ new Set(); for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key); const implicitScalarByFirstChar = /* @__PURE__ */ new Map(); for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1)); const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"]; if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)"); this.tags = compiledTags; this.implicitScalarTags = implicitScalarTags; this.implicitScalarByFirstChar = implicitScalarByFirstChar; this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar; this.defaultScalarTag = defaultScalarTag; this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"]; this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"]; this.exact = exact; this.prefix = prefix; } withTags(...tags) { let flatTags = []; for (const tag of tags) flatTags = flatTags.concat(tag); return new Schema([...this.tags, ...flatTags]); } }; var FAILSAFE_SCHEMA = new Schema([ strTag, seqTag, mapTag ]); var JSON_SCHEMA = new Schema([ ...FAILSAFE_SCHEMA.tags, nullJsonTag, boolJsonTag, intJsonTag, floatJsonTag ]); var CORE_SCHEMA = new Schema([ ...FAILSAFE_SCHEMA.tags, nullCoreTag, boolCoreTag, intCoreTag, floatCoreTag ]); var YAML11_SCHEMA = new Schema([ ...FAILSAFE_SCHEMA.tags, nullYaml11Tag, boolYaml11Tag, intYaml11Tag, floatYaml11Tag, timestampTag, mergeTag, binaryTag, omapTag, pairsTag, setTag ]); //#endregion //#region src/tag/mapping/real_map.ts var realMapTag = defineMappingTag("tag:yaml.org,2002:map", { create: () => /* @__PURE__ */ new Map(), addPair: (container, key, value) => { container.set(key, value); return ""; }, has: (container, key) => container.has(key), keys: (container) => container.keys(), get: (container, key) => container.get(key), identify: (data) => data instanceof Map || isPlainObject(data), represent: (data) => { if (data instanceof Map) return data; const map = /* @__PURE__ */ new Map(); const obj = data; for (const key of Object.keys(obj)) map.set(key, obj[key]); return map; } }); //#endregion //#region src/tag/mapping/legacy_map.ts function normalizeKey(key) { if (Array.isArray(key)) { const array = Array.prototype.slice.call(key); for (let index = 0; index < array.length; index++) { if (Array.isArray(array[index])) return null; if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]"; } return String(array); } if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]"; return String(key); } var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", { create: () => ({}), identify: isPlainObject, represent: (o) => { const map = /* @__PURE__ */ new Map(); for (const key of Object.keys(o)) map.set(key, o[key]); return map; }, addPair: (container, key, value) => { const normalizedKey = normalizeKey(key); if (normalizedKey === null) return "nested arrays are not supported inside keys"; if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, { value, enumerable: true, configurable: true, writable: true }); else container[normalizedKey] = value; return ""; }, has: (container, key) => { const normalizedKey = normalizeKey(key); return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey); }, keys: (container) => Object.keys(container), get: (container, key) => container[String(key)] }); //#endregion //#region \0@oxc-project+runtime@0.132.0/helpers/objectSpread2.js function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function(r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function(r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } //#endregion //#region src/common/snippet.ts var DEFAULT_SNIPPET_OPTIONS = { maxLength: 79, indent: 1, linesBefore: 3, linesAfter: 2 }; function getLine(buffer, lineStart, lineEnd, position, maxLineLength) { let head = ""; let tail = ""; const maxHalfLength = Math.floor(maxLineLength / 2) - 1; if (position - lineStart > maxHalfLength) { head = " ... "; lineStart = position - maxHalfLength + head.length; } if (lineEnd - position > maxHalfLength) { tail = " ..."; lineEnd = position + maxHalfLength - tail.length; } return { str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail, pos: position - lineStart + head.length }; } function padStart(string, max) { return " ".repeat(Math.max(max - string.length, 0)) + string; } function makeSnippet(mark, options) { if (!mark.buffer) return null; const opts = _objectSpread2(_objectSpread2({}, DEFAULT_SNIPPET_OPTIONS), options); const re = /\r?\n|\r|\0/g; const lineStarts = [0]; const lineEnds = []; let match; let foundLineNo = -1; while (match = re.exec(mark.buffer)) { lineEnds.push(match.index); lineStarts.push(match.index + match[0].length); if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2; } if (foundLineNo < 0) foundLineNo = lineStarts.length - 1; let result = ""; const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length; const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3); for (let i = 1; i <= opts.linesBefore; i++) { if (foundLineNo - i < 0) break; const line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength); result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line.str}\n${result}`; } const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}\n`; result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^\n`; for (let i = 1; i <= opts.linesAfter; i++) { if (foundLineNo + i >= lineEnds.length) break; const line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength); result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line.str}\n`; } return result.replace(/\n$/, ""); } //#endregion //#region src/common/exception.ts function formatError(exception, compact) { let where = ""; if (!exception.mark) return exception.reason; if (exception.mark.name) where += `in "${exception.mark.name}" `; where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`; if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`; return `${exception.reason} ${where}`; } var YAMLException = class extends Error { constructor(reason, mark) { super(); _defineProperty(this, "reason", void 0); _defineProperty(this, "mark", void 0); this.name = "YAMLException"; this.reason = reason; this.mark = mark; this.message = formatError(this, false); if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor); } toString(compact) { return `${this.name}: ${formatError(this, compact)}`; } }; function throwErrorAt(source, position, message, filename = "") { let line = 0; let lineStart = 0; for (let index = 0; index < position; index++) { const ch = source.charCodeAt(index); if (ch === 10) { line++; lineStart = index + 1; } else if (ch === 13) { line++; if (source.charCodeAt(index + 1) === 10) index++; lineStart = index + 1; } } const mark = { name: filename, buffer: source, position, line, column: position - lineStart }; mark.snippet = makeSnippet(mark); throw new YAMLException(message, mark); } //#endregion //#region src/parser/events.ts var EVENT_DOCUMENT = 1; var EVENT_SEQUENCE = 2; var EVENT_MAPPING = 3; var EVENT_SCALAR = 4; var EVENT_ALIAS = 5; var EVENT_POP = 6; var SCALAR_STYLE_PLAIN = 1; var SCALAR_STYLE_SINGLE_QUOTED = 2; var SCALAR_STYLE_DOUBLE_QUOTED = 3; var SCALAR_STYLE_LITERAL_BLOCK = 4; var SCALAR_STYLE_FOLDED_BLOCK = 5; var COLLECTION_STYLE_BLOCK = 1; var COLLECTION_STYLE_FLOW = 2; var CHOMPING_CLIP = 1; var CHOMPING_STRIP = 2; var CHOMPING_KEEP = 3; //#endregion //#region src/parser/parser_scalar.ts var NO_RANGE$3 = -1; function simpleEscapeSequence(c) { switch (c) { case 48: return "\0"; case 97: return "\x07"; case 98: return "\b"; case 116: return " "; case 9: return " "; case 110: return "\n"; case 118: return "\v"; case 102: return "\f"; case 114: return "\r"; case 101: return "\x1B"; case 32: return " "; case 34: return "\""; case 47: return "/"; case 92: return "\\"; case 78: return "…"; case 95: return "\xA0"; case 76: return "\u2028"; case 80: return "\u2029"; default: return ""; } } var simpleEscapeCheck = new Array(256); var simpleEscapeMap = new Array(256); for (let i = 0; i < 256; i++) { simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0; simpleEscapeMap[i] = simpleEscapeSequence(i); } function charFromCodepoint(c) { if (c <= 65535) return String.fromCharCode(c); return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320); } function fromHexCode$1(c) { if (c >= 48 && c <= 57) return c - 48; return (c | 32) - 97 + 10; } function escapedHexLen$1(c) { if (c === 120) return 2; if (c === 117) return 4; return 8; } function skipFoldedBreaks(input, position, end) { let breaks = 0; while (position < end) { const ch = input.charCodeAt(position); if (ch === 10) { breaks++; position++; } else if (ch === 13) { breaks++; position++; if (input.charCodeAt(position) === 10) position++; } else if (ch === 32 || ch === 9) position++; else break; } return { position, breaks }; } function foldedBreaks(count) { if (count === 1) return " "; return "\n".repeat(count - 1); } function getPlainValue(input, start, end) { let result = ""; let position = start; let captureStart = start; let captureEnd = start; while (position < end) { const ch = input.charCodeAt(position); if (ch === 10 || ch === 13) { result += input.slice(captureStart, captureEnd); const fold = skipFoldedBreaks(input, position, end); result += foldedBreaks(fold.breaks); position = captureStart = captureEnd = fold.position; } else { position++; if (ch !== 32 && ch !== 9) captureEnd = position; } } return result + input.slice(captureStart, captureEnd); } function getSingleQuotedValue(input, start, end) { let result = ""; let position = start; let captureStart = start; let captureEnd = start; while (position < end) { const ch = input.charCodeAt(position); if (ch === 39) { result += input.slice(captureStart, position) + "'"; position += 2; captureStart = captureEnd = position; } else if (ch === 10 || ch === 13) { result += input.slice(captureStart, captureEnd); const fold = skipFoldedBreaks(input, position, end); result += foldedBreaks(fold.breaks); position = captureStart = captureEnd = fold.position; } else { position++; if (ch !== 32 && ch !== 9) captureEnd = position; } } return result + input.slice(captureStart, end); } function getDoubleQuotedValue(input, start, end) { let result = ""; let position = start; let captureStart = start; let captureEnd = start; while (position < end) { const ch = input.charCodeAt(position); if (ch === 92) { result += input.slice(captureStart, position); position++; const escaped = input.charCodeAt(position); if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position; else if (escaped < 256 && simpleEscapeCheck[escaped]) { result += simpleEscapeMap[escaped]; position++; } else { let hexLength = escapedHexLen$1(escaped); let hexResult = 0; for (; hexLength > 0; hexLength--) { position++; const digit = fromHexCode$1(input.charCodeAt(position)); hexResult = (hexResult << 4) + digit; } result += charFromCodepoint(hexResult); position++; } captureStart = captureEnd = position; } else if (ch === 10 || ch === 13) { result += input.slice(captureStart, captureEnd); const fold = skipFoldedBreaks(input, position, end); result += foldedBreaks(fold.breaks); position = captureStart = captureEnd = fold.position; } else { position++; if (ch !== 32 && ch !== 9) captureEnd = position; } } return result + input.slice(captureStart, end); } function getBlockValue(input, start, end, indent, chomping, folded) { const textIndent = indent < 0 ? 0 : indent; const region = input.slice(start, end).replace(/\r\n?/g, "\n"); const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n"); let result = ""; let didReadContent = false; let emptyLines = 0; let atMoreIndented = false; for (const line of lines) { let column = 0; while (column < textIndent && line.charCodeAt(column) === 32) column++; if (indent < 0 || column >= line.length) { emptyLines++; continue; } const content = line.slice(textIndent); const first = content.charCodeAt(0); if (folded) if (first === 32 || first === 9) { atMoreIndented = true; result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines); } else if (atMoreIndented) { atMoreIndented = false; result += "\n".repeat(emptyLines + 1); } else if (emptyLines === 0) { if (didReadContent) result += " "; } else result += "\n".repeat(emptyLines); else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines); result += content; didReadContent = true; emptyLines = 0; } if (chomping === 3) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines); else if (chomping !== 2) { if (didReadContent) result += "\n"; } return result; } function getScalarValue(input, scalar) { if (scalar.valueStart === NO_RANGE$3) return ""; const { valueStart, valueEnd } = scalar; if (scalar.fast) return input.slice(valueStart, valueEnd); switch (scalar.style) { case 2: return getSingleQuotedValue(input, valueStart, valueEnd); case 3: return getDoubleQuotedValue(input, valueStart, valueEnd); case 4: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false); case 5: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true); default: return getPlainValue(input, valueStart, valueEnd); } } //#endregion //#region src/common/tagname.ts var DEFAULT_TAG_HANDLERS = { "!": "!", "!!": "tag:yaml.org,2002:" }; function tagPercentEncode(source) { return encodeURI(source).replace(/!/g, "%21"); } function tagNameFull(rawTag, tagHandlers) { var _ref, _tagHandlers$handle; if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return decodeURIComponent(rawTag.slice(2, -1)); const handleEnd = rawTag.indexOf("!", 1); const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1); const prefix = (_ref = (_tagHandlers$handle = tagHandlers === null || tagHandlers === void 0 ? void 0 : tagHandlers[handle]) !== null && _tagHandlers$handle !== void 0 ? _tagHandlers$handle : DEFAULT_TAG_HANDLERS[handle]) !== null && _ref !== void 0 ? _ref : handle; return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length)); } function tagNameShort(fullTag) { let tag = fullTag; if (tag.charCodeAt(0) === 33) { tag = tag.slice(1); return `!${tagPercentEncode(tag)}`; } if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18))}`; return `!<${tagPercentEncode(tag)}>`; } //#endregion //#region src/parser/constructor.ts var NO_RANGE$2 = -1; var DEFAULT_CONSTRUCTOR_OPTIONS = { filename: "", schema: CORE_SCHEMA, json: false, maxTotalMergeKeys: 1e4, maxAliases: -1 }; function eventPosition$1(event) { if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart; if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart; if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart; if ("start" in event) return event.start; return 0; } function throwError$1(state, message) { throwErrorAt(state.source, state.position, message, state.filename); } function finalizeCollection(state, position, tag, carrier) { try { return tag.finalize(carrier); } catch (error) { if (error instanceof YAMLException) throw error; throwErrorAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename); } } function lookupTag(exact, prefix, tagName) { const exactTag = exact[tagName]; if (exactTag) return exactTag; for (const tag of prefix) if (tagName.startsWith(tag.tagName)) return tag; } function findExplicitTag(state, exact, prefix, tagName, nodeKind) { const tag = lookupTag(exact, prefix, tagName); if (tag) return tag; throwError$1(state, `unknown ${nodeKind} tag !<${tagName}>`); } function constructScalar(state, event) { const source = getScalarValue(state.source, event); const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd); const strTag = state.schema.defaultScalarTag; if (rawTag !== "") { var _lookupTag; if (rawTag === "!") return { value: source, tag: strTag }; const tagName = tagNameFull(rawTag, state.tagHandlers); const scalarTag = lookupTag(state.schema.exact.scalar, state.schema.prefix.scalar, tagName); if (scalarTag) { const result = scalarTag.resolve(source, true, tagName); if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`); return { value: result, tag: scalarTag }; } const collectionTagDef = (_lookupTag = lookupTag(state.schema.exact.mapping, state.schema.prefix.mapping, tagName)) !== null && _lookupTag !== void 0 ? _lookupTag : lookupTag(state.schema.exact.sequence, state.schema.prefix.sequence, tagName); if (collectionTagDef) { if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`); const carrier = collectionTagDef.create(tagName); return { value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier), tag: collectionTagDef }; } throwError$1(state, `unknown scalar tag !<${tagName}>`); } if (event.style === 1) { var _state$schema$implici; const candidates = (_state$schema$implici = state.schema.implicitScalarByFirstChar.get(source.charAt(0))) !== null && _state$schema$implici !== void 0 ? _state$schema$implici : state.schema.implicitScalarAnyFirstChar; for (const tag of candidates) { const result = tag.resolve(source, false, tag.tagName); if (result !== NOT_RESOLVED) return { value: result, tag }; } } return { value: strTag.resolve(source, false, strTag.tagName), tag: strTag }; } function collectionTag(state, event, exact, prefix, defaultTagName, nodeKind) { const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd); const tagName = rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers); return { tagName, tag: findExplicitTag(state, exact, prefix, tagName, nodeKind) }; } function isMappingTag(tag) { return tag.nodeKind === "mapping"; } function mergeKeys(state, frame, source, sourceTag) { for (const sourceKey of sourceTag.keys(source)) { var _frame$overridable; if (state.maxTotalMergeKeys !== -1 && ++state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`); if (frame.tag.has(frame.value, sourceKey)) continue; const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey)); if (err) throwError$1(state, err); ((_frame$overridable = frame.overridable) !== null && _frame$overridable !== void 0 ? _frame$overridable : frame.overridable = /* @__PURE__ */ new Set()).add(sourceKey); } } function mergeSource(state, frame, source, sourceTag) { state.position = frame.keyPosition; if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag); else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) for (const element of source) mergeKeys(state, frame, element, frame.tag); else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable"); } function addMappingValue(state, frame, key, value, tag) { var _frame$overridable2, _frame$overridable3; state.position = frame.keyPosition; if (key === MERGE_KEY) { mergeSource(state, frame, value, tag); return; } if (!state.json && frame.tag.has(frame.value, key) && !((_frame$overridable2 = frame.overridable) === null || _frame$overridable2 === void 0 ? void 0 : _frame$overridable2.has(key))) throwError$1(state, "duplicated mapping key"); const err = frame.tag.addPair(frame.value, key, value); if (err) throwError$1(state, err); (_frame$overridable3 = frame.overridable) === null || _frame$overridable3 === void 0 || _frame$overridable3.delete(key); } function addValue(state, value, tag) { const frame = state.frames[state.frames.length - 1]; if (frame.kind === "document") { frame.value = value; frame.hasValue = true; } else if (frame.kind === "sequence") { if (frame.merge) { if (!isMappingTag(tag)) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable"); } const err = frame.tag.addItem(frame.value, value, frame.index++); if (err) throwError$1(state, err); } else if (frame.hasKey) { const key = frame.key; frame.key = void 0; frame.hasKey = false; addMappingValue(state, frame, key, value, tag); } else { frame.key = value; frame.keyPosition = state.position; frame.hasKey = true; } } function storeAnchor(state, event, value, tag, isValueFinal) { if (event.anchorStart !== NO_RANGE$2) { const anchor = { value, tag, isValueFinal }; state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor); return anchor; } return null; } function constructFromEvents(events, options) { const state = _objectSpread2(_objectSpread2(_objectSpread2({}, DEFAULT_CONSTRUCTOR_OPTIONS), options), {}, { events, documents: [], eventIndex: 0, position: 0, frames: [], anchors: /* @__PURE__ */ new Map(), tagHandlers: Object.create(null), totalMergeKeys: 0, aliasCount: 0 }); while (state.eventIndex < state.events.length) { const event = state.events[state.eventIndex++]; state.position = eventPosition$1(event); switch (event.type) { case 1: state.anchors = /* @__PURE__ */ new Map(); state.aliasCount = 0; state.tagHandlers = Object.create(null); for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix; state.frames.push({ kind: "document", position: state.position, value: void 0, hasValue: false }); break; case 4: { const { value, tag } = constructScalar(state, event); storeAnchor(state, event, value, tag, true); addValue(state, value, tag); break; } case 2: { const definition = collectionTag(state, event, state.schema.exact.sequence, state.schema.prefix.sequence, "tag:yaml.org,2002:seq", "sequence"); const value = definition.tag.create(d