import { e as q, d as P, b as R, c as D, _ as y, i as L, Y as Q, T as V, f as z, g as b, a as F, h as H, j as X, k as ee } from "./PlainValue-b8036b75.js";
import { parse as I } from "./parse-cst.js";
import { e as N, C as d, S as A, t as te, N as U, f as ne, P as W, c as re, Y as se, d as E, A as O, M as ie, r as ae, b as B, a as C, i as $, n as J, s as G } from "./resolveSeq-492ab440.js";
import { S as T } from "./Schema-e94716c8.js";
import { w as oe } from "./warnings-df54cb69.js";
var M = {
  anchorPrefix: "a",
  customTags: null,
  indent: 2,
  indentSeq: !0,
  keepCstNodes: !1,
  keepNodeTypes: !0,
  keepBlobsInJSON: !0,
  mapAsMap: !1,
  maxAliasCount: 100,
  prettyErrors: !1,
  simpleKeys: !1,
  version: "1.2"
}, fe = {
  get binary() {
    return B;
  },
  set binary(r) {
    Object.assign(B, r);
  },
  get bool() {
    return C;
  },
  set bool(r) {
    Object.assign(C, r);
  },
  get int() {
    return $;
  },
  set int(r) {
    Object.assign($, r);
  },
  get null() {
    return J;
  },
  set null(r) {
    Object.assign(J, r);
  },
  get str() {
    return G;
  },
  set str(r) {
    Object.assign(G, r);
  }
}, Z = {
  "1.0": {
    schema: "yaml-1.1",
    merge: !0,
    tagPrefixes: [{
      handle: "!",
      prefix: P
    }, {
      handle: "!!",
      prefix: "tag:private.yaml.org,2002:"
    }]
  },
  1.1: {
    schema: "yaml-1.1",
    merge: !0,
    tagPrefixes: [{
      handle: "!",
      prefix: "!"
    }, {
      handle: "!!",
      prefix: P
    }]
  },
  1.2: {
    schema: "core",
    merge: !1,
    tagPrefixes: [{
      handle: "!",
      prefix: "!"
    }, {
      handle: "!!",
      prefix: P
    }]
  }
};
function _(r, n) {
  if ((r.version || r.options.version) === "1.0") {
    var e = n.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
    if (e)
      return "!" + e[1];
    var t = n.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
    return t ? "!".concat(t[1], "/").concat(t[2]) : "!".concat(n.replace(/^tag:/, ""));
  }
  var s = r.tagPrefixes.find(function(i) {
    return n.indexOf(i.prefix) === 0;
  });
  if (!s) {
    var a = r.getDefaults().tagPrefixes;
    s = a && a.find(function(i) {
      return n.indexOf(i.prefix) === 0;
    });
  }
  if (!s)
    return n[0] === "!" ? n : "!<".concat(n, ">");
  var o = n.substr(s.prefix.length).replace(/[!,[\]{}]/g, function(i) {
    return {
      "!": "%21",
      ",": "%2C",
      "[": "%5B",
      "]": "%5D",
      "{": "%7B",
      "}": "%7D"
    }[i];
  });
  return s.handle + o;
}
function ce(r, n) {
  if (n instanceof O)
    return O;
  if (n.tag) {
    var e = r.filter(function(i) {
      return i.tag === n.tag;
    });
    if (e.length > 0)
      return e.find(function(i) {
        return i.format === n.format;
      }) || e[0];
  }
  var t, s;
  if (n instanceof A) {
    s = n.value;
    var a = r.filter(function(i) {
      return i.identify && i.identify(s) || i.class && s instanceof i.class;
    });
    t = a.find(function(i) {
      return i.format === n.format;
    }) || a.find(function(i) {
      return !i.format;
    });
  } else
    s = n, t = r.find(function(i) {
      return i.nodeClass && s instanceof i.nodeClass;
    });
  if (!t) {
    var o = s && s.constructor ? s.constructor.name : F(s);
    throw new Error("Tag not resolved for ".concat(o, " value"));
  }
  return t;
}
function ue(r, n, e) {
  var t = e.anchors, s = e.doc, a = [], o = s.anchors.getName(r);
  return o && (t[o] = r, a.push("&".concat(o))), r.tag ? a.push(_(s, r.tag)) : n.default || a.push(_(s, n.tag)), a.join(" ");
}
function x(r, n, e, t) {
  var s = n.doc, a = s.anchors, o = s.schema, i;
  if (!(r instanceof U)) {
    var h = {
      aliasNodes: [],
      onTagObj: function(g) {
        return i = g;
      },
      prevObjects: /* @__PURE__ */ new Map()
    };
    r = o.createNode(r, !0, null, h);
    var c = y(h.aliasNodes), u;
    try {
      for (c.s(); !(u = c.n()).done; ) {
        var l = u.value;
        l.source = l.source.node;
        var p = a.getName(l.source);
        p || (p = a.newName(), a.map[p] = l.source);
      }
    } catch (m) {
      c.e(m);
    } finally {
      c.f();
    }
  }
  if (r instanceof W)
    return r.toString(n, e, t);
  i || (i = ce(o.tags, r));
  var f = ue(r, i, n);
  f.length > 0 && (n.indentAtStart = (n.indentAtStart || 0) + f.length + 1);
  var v = typeof i.stringify == "function" ? i.stringify(r, n, e, t) : r instanceof A ? re(r, n, e, t) : r.toString(n, e, t);
  return f ? r instanceof A || v[0] === "{" || v[0] === "[" ? "".concat(f, " ").concat(v) : "".concat(f, `
`).concat(n.indent).concat(v) : v;
}
var le = /* @__PURE__ */ function() {
  function r(n) {
    D(this, r), q(this, "map", /* @__PURE__ */ Object.create(null)), this.prefix = n;
  }
  return R(r, [{
    key: "createAlias",
    value: function(e, t) {
      return this.setAnchor(e, t), new O(e);
    }
  }, {
    key: "createMergePair",
    value: function() {
      for (var e = this, t = new ie(), s = arguments.length, a = new Array(s), o = 0; o < s; o++)
        a[o] = arguments[o];
      return t.value.items = a.map(function(i) {
        if (i instanceof O) {
          if (i.source instanceof E)
            return i;
        } else if (i instanceof E)
          return e.createAlias(i);
        throw new Error("Merge sources must be Map nodes or their Aliases");
      }), t;
    }
  }, {
    key: "getName",
    value: function(e) {
      var t = this.map;
      return Object.keys(t).find(function(s) {
        return t[s] === e;
      });
    }
  }, {
    key: "getNames",
    value: function() {
      return Object.keys(this.map);
    }
  }, {
    key: "getNode",
    value: function(e) {
      return this.map[e];
    }
  }, {
    key: "newName",
    value: function(e) {
      e || (e = this.prefix);
      for (var t = Object.keys(this.map), s = 1; ; ++s) {
        var a = "".concat(e).concat(s);
        if (!t.includes(a))
          return a;
      }
    }
  }, {
    key: "resolveNodes",
    value: function() {
      var e = this.map, t = this._cstAliases;
      Object.keys(e).forEach(function(s) {
        e[s] = e[s].resolved;
      }), t.forEach(function(s) {
        s.source = s.source.resolved;
      }), delete this._cstAliases;
    }
  }, {
    key: "setAnchor",
    value: function(e, t) {
      if (e != null && !r.validAnchorNode(e))
        throw new Error("Anchors may only be set for Scalar, Seq and Map nodes");
      if (t && /[\x00-\x19\s,[\]{}]/.test(t))
        throw new Error("Anchor names must not contain whitespace or control characters");
      var s = this.map, a = e && Object.keys(s).find(function(o) {
        return s[o] === e;
      });
      if (a)
        if (t)
          a !== t && (delete s[a], s[t] = e);
        else
          return a;
      else {
        if (!t) {
          if (!e)
            return null;
          t = this.newName();
        }
        s[t] = e;
      }
      return t;
    }
  }], [{
    key: "validAnchorNode",
    value: function(e) {
      return e instanceof A || e instanceof se || e instanceof E;
    }
  }]), r;
}(), he = function r(n, e) {
  if (n && F(n) === "object") {
    var t = n.tag;
    n instanceof d ? (t && (e[t] = !0), n.items.forEach(function(s) {
      return r(s, e);
    })) : n instanceof W ? (r(n.key, e), r(n.value, e)) : n instanceof A && t && (e[t] = !0);
  }
  return e;
}, ve = function(n) {
  return Object.keys(he(n, {}));
};
function pe(r, n) {
  var e = {
    before: [],
    after: []
  }, t = void 0, s = !1, a = y(n), o;
  try {
    for (a.s(); !(o = a.n()).done; ) {
      var i = o.value;
      if (i.valueRange) {
        if (t !== void 0) {
          var h = "Document contains trailing content not separated by a ... or --- line";
          r.errors.push(new Q(i, h));
          break;
        }
        var c = ae(r, i);
        s && (c.spaceBefore = !0, s = !1), t = c;
      } else if (i.comment !== null) {
        var u = t === void 0 ? e.before : e.after;
        u.push(i.comment);
      } else
        i.type === V.BLANK_LINE && (s = !0, t === void 0 && e.before.length > 0 && !r.commentBefore && (r.commentBefore = e.before.join(`
`), e.before = []));
    }
  } catch (f) {
    a.e(f);
  } finally {
    a.f();
  }
  if (r.contents = t || null, !t)
    r.comment = e.before.concat(e.after).join(`
`) || null;
  else {
    var l = e.before.join(`
`);
    if (l) {
      var p = t instanceof d && t.items[0] ? t.items[0] : t;
      p.commentBefore = p.commentBefore ? "".concat(l, `
`).concat(p.commentBefore) : l;
    }
    r.comment = e.after.join(`
`) || null;
  }
}
function me(r, n) {
  var e = r.tagPrefixes, t = H(n.parameters, 2), s = t[0], a = t[1];
  if (!s || !a) {
    var o = "Insufficient parameters given for %TAG directive";
    throw new b(n, o);
  }
  if (e.some(function(h) {
    return h.handle === s;
  })) {
    var i = "The %TAG directive must only be given at most once per handle in the same document.";
    throw new b(n, i);
  }
  return {
    handle: s,
    prefix: a
  };
}
function ge(r, n) {
  var e = H(n.parameters, 1), t = e[0];
  if (n.name === "YAML:1.0" && (t = "1.0"), !t) {
    var s = "Insufficient parameters given for %YAML directive";
    throw new b(n, s);
  }
  if (!Z[t]) {
    var a = r.version || r.options.version, o = "Document will be parsed as YAML ".concat(a, " rather than YAML ").concat(t);
    r.warnings.push(new z(n, o));
  }
  return t;
}
function de(r, n, e) {
  var t = [], s = !1, a = y(n), o;
  try {
    for (a.s(); !(o = a.n()).done; ) {
      var i = o.value, h = i.comment, c = i.name;
      switch (c) {
        case "TAG":
          try {
            r.tagPrefixes.push(me(r, i));
          } catch (f) {
            r.errors.push(f);
          }
          s = !0;
          break;
        case "YAML":
        case "YAML:1.0":
          if (r.version) {
            var u = "The %YAML directive must only be given at most once per document.";
            r.errors.push(new b(i, u));
          }
          try {
            r.version = ge(r, i);
          } catch (f) {
            r.errors.push(f);
          }
          s = !0;
          break;
        default:
          if (c) {
            var l = "YAML only supports %TAG and %YAML directives, and not %".concat(c);
            r.warnings.push(new z(i, l));
          }
      }
      h && t.push(h);
    }
  } catch (f) {
    a.e(f);
  } finally {
    a.f();
  }
  if (e && !s && (r.version || e.version || r.options.version) === "1.1") {
    var p = function(v) {
      var m = v.handle, g = v.prefix;
      return {
        handle: m,
        prefix: g
      };
    };
    r.tagPrefixes = e.tagPrefixes.map(p), r.version = e.version;
  }
  r.commentBefore = t.join(`
`) || null;
}
function w(r) {
  if (r instanceof d)
    return !0;
  throw new Error("Expected a YAML collection as document contents");
}
var Y = /* @__PURE__ */ function() {
  function r(n) {
    D(this, r), this.anchors = new le(n.anchorPrefix), this.commentBefore = null, this.comment = null, this.contents = null, this.directivesEndMarker = null, this.errors = [], this.options = n, this.schema = null, this.tagPrefixes = [], this.version = null, this.warnings = [];
  }
  return R(r, [{
    key: "add",
    value: function(e) {
      return w(this.contents), this.contents.add(e);
    }
  }, {
    key: "addIn",
    value: function(e, t) {
      w(this.contents), this.contents.addIn(e, t);
    }
  }, {
    key: "delete",
    value: function(e) {
      return w(this.contents), this.contents.delete(e);
    }
  }, {
    key: "deleteIn",
    value: function(e) {
      return N(e) ? this.contents == null ? !1 : (this.contents = null, !0) : (w(this.contents), this.contents.deleteIn(e));
    }
  }, {
    key: "getDefaults",
    value: function() {
      return r.defaults[this.version] || r.defaults[this.options.version] || {};
    }
  }, {
    key: "get",
    value: function(e, t) {
      return this.contents instanceof d ? this.contents.get(e, t) : void 0;
    }
  }, {
    key: "getIn",
    value: function(e, t) {
      return N(e) ? !t && this.contents instanceof A ? this.contents.value : this.contents : this.contents instanceof d ? this.contents.getIn(e, t) : void 0;
    }
  }, {
    key: "has",
    value: function(e) {
      return this.contents instanceof d ? this.contents.has(e) : !1;
    }
  }, {
    key: "hasIn",
    value: function(e) {
      return N(e) ? this.contents !== void 0 : this.contents instanceof d ? this.contents.hasIn(e) : !1;
    }
  }, {
    key: "set",
    value: function(e, t) {
      w(this.contents), this.contents.set(e, t);
    }
  }, {
    key: "setIn",
    value: function(e, t) {
      N(e) ? this.contents = t : (w(this.contents), this.contents.setIn(e, t));
    }
  }, {
    key: "setSchema",
    value: function(e, t) {
      if (!(!e && !t && this.schema)) {
        typeof e == "number" && (e = e.toFixed(1)), e === "1.0" || e === "1.1" || e === "1.2" ? (this.version ? this.version = e : this.options.version = e, delete this.options.schema) : e && typeof e == "string" && (this.options.schema = e), Array.isArray(t) && (this.options.customTags = t);
        var s = Object.assign({}, this.getDefaults(), this.options);
        this.schema = new T(s);
      }
    }
  }, {
    key: "parse",
    value: function(e, t) {
      this.options.keepCstNodes && (this.cstNode = e), this.options.keepNodeTypes && (this.type = "DOCUMENT");
      var s = e.directives, a = s === void 0 ? [] : s, o = e.contents, i = o === void 0 ? [] : o, h = e.directivesEndMarker, c = e.error, u = e.valueRange;
      if (c && (c.source || (c.source = this), this.errors.push(c)), de(this, a, t), h && (this.directivesEndMarker = !0), this.range = u ? [u.start, u.end] : null, this.setSchema(), this.anchors._cstAliases = [], pe(this, i), this.anchors.resolveNodes(), this.options.prettyErrors) {
        var l = y(this.errors), p;
        try {
          for (l.s(); !(p = l.n()).done; ) {
            var f = p.value;
            f instanceof L && f.makePretty();
          }
        } catch (k) {
          l.e(k);
        } finally {
          l.f();
        }
        var v = y(this.warnings), m;
        try {
          for (v.s(); !(m = v.n()).done; ) {
            var g = m.value;
            g instanceof L && g.makePretty();
          }
        } catch (k) {
          v.e(k);
        } finally {
          v.f();
        }
      }
      return this;
    }
  }, {
    key: "listNonDefaultTags",
    value: function() {
      return ve(this.contents).filter(function(e) {
        return e.indexOf(T.defaultPrefix) !== 0;
      });
    }
  }, {
    key: "setTagPrefix",
    value: function(e, t) {
      if (e[0] !== "!" || e[e.length - 1] !== "!")
        throw new Error("Handle must start and end with !");
      if (t) {
        var s = this.tagPrefixes.find(function(a) {
          return a.handle === e;
        });
        s ? s.prefix = t : this.tagPrefixes.push({
          handle: e,
          prefix: t
        });
      } else
        this.tagPrefixes = this.tagPrefixes.filter(function(a) {
          return a.handle !== e;
        });
    }
  }, {
    key: "toJSON",
    value: function(e, t) {
      var s = this, a = this.options, o = a.keepBlobsInJSON, i = a.mapAsMap, h = a.maxAliasCount, c = o && (typeof e != "string" || !(this.contents instanceof A)), u = {
        doc: this,
        indentStep: "  ",
        keep: c,
        mapAsMap: c && !!i,
        maxAliasCount: h,
        stringify: x
      }, l = Object.keys(this.anchors.map);
      l.length > 0 && (u.anchors = new Map(l.map(function(j) {
        return [s.anchors.map[j], {
          alias: [],
          aliasCount: 0,
          count: 1
        }];
      })));
      var p = te(this.contents, e, u);
      if (typeof t == "function" && u.anchors) {
        var f = y(u.anchors.values()), v;
        try {
          for (f.s(); !(v = f.n()).done; ) {
            var m = v.value, g = m.count, k = m.res;
            t(k, g);
          }
        } catch (j) {
          f.e(j);
        } finally {
          f.f();
        }
      }
      return p;
    }
  }, {
    key: "toString",
    value: function() {
      if (this.errors.length > 0)
        throw new Error("Document with errors cannot be stringified");
      var e = this.options.indent;
      if (!Number.isInteger(e) || e <= 0) {
        var t = JSON.stringify(e);
        throw new Error('"indent" option must be a positive integer, not '.concat(t));
      }
      this.setSchema();
      var s = [], a = !1;
      if (this.version) {
        var o = "%YAML 1.2";
        this.schema.name === "yaml-1.1" && (this.version === "1.0" ? o = "%YAML:1.0" : this.version === "1.1" && (o = "%YAML 1.1")), s.push(o), a = !0;
      }
      var i = this.listNonDefaultTags();
      this.tagPrefixes.forEach(function(f) {
        var v = f.handle, m = f.prefix;
        i.some(function(g) {
          return g.indexOf(m) === 0;
        }) && (s.push("%TAG ".concat(v, " ").concat(m)), a = !0);
      }), (a || this.directivesEndMarker) && s.push("---"), this.commentBefore && ((a || !this.directivesEndMarker) && s.unshift(""), s.unshift(this.commentBefore.replace(/^/gm, "#")));
      var h = {
        anchors: /* @__PURE__ */ Object.create(null),
        doc: this,
        indent: "",
        indentStep: " ".repeat(e),
        stringify: x
      }, c = !1, u = null;
      if (this.contents) {
        this.contents instanceof U && (this.contents.spaceBefore && (a || this.directivesEndMarker) && s.push(""), this.contents.commentBefore && s.push(this.contents.commentBefore.replace(/^/gm, "#")), h.forceBlockIndent = !!this.comment, u = this.contents.comment);
        var l = u ? null : function() {
          return c = !0;
        }, p = x(this.contents, h, function() {
          return u = null;
        }, l);
        s.push(ne(p, "", u));
      } else
        this.contents !== void 0 && s.push(x(this.contents, h));
      return this.comment && ((!c || u) && s[s.length - 1] !== "" && s.push(""), s.push(this.comment.replace(/^/gm, "#"))), s.join(`
`) + `
`;
    }
  }]), r;
}();
q(Y, "defaults", Z);
function ye(r) {
  var n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0, e = arguments.length > 2 ? arguments[2] : void 0;
  e === void 0 && typeof n == "string" && (e = n, n = !0);
  var t = Object.assign({}, Y.defaults[M.version], M), s = new T(t);
  return s.createNode(r, n, e);
}
var S = /* @__PURE__ */ function(r) {
  X(e, r);
  var n = ee(e);
  function e(t) {
    return D(this, e), n.call(this, Object.assign({}, M, t));
  }
  return e;
}(Y);
function Ae(r, n) {
  var e = [], t, s = y(I(r)), a;
  try {
    for (s.s(); !(a = s.n()).done; ) {
      var o = a.value, i = new S(n);
      i.parse(o, t), e.push(i), t = i;
    }
  } catch (h) {
    s.e(h);
  } finally {
    s.f();
  }
  return e;
}
function K(r, n) {
  var e = I(r), t = new S(n).parse(e[0]);
  if (e.length > 1) {
    var s = "Source contains multiple documents; please use YAML.parseAllDocuments()";
    t.errors.unshift(new b(e[1], s));
  }
  return t;
}
function we(r, n) {
  var e = K(r, n);
  if (e.warnings.forEach(function(t) {
    return oe(t);
  }), e.errors.length > 0)
    throw e.errors[0];
  return e.toJSON();
}
function ke(r, n) {
  var e = new S(n);
  return e.contents = r, String(e);
}
var Se = {
  createNode: ye,
  defaultOptions: M,
  Document: S,
  parse: we,
  parseAllDocuments: Ae,
  parseCST: I,
  parseDocument: K,
  scalarOptions: fe,
  stringify: ke
};
export {
  Se as YAML
};
//# sourceMappingURL=index.js.map
