import { __module as p } from "../../../../../_virtual/index27.js";
import { __require as j } from "./lib/utils.js";
import { __require as L } from "./lib/schemes.js";
var q;
function H() {
  if (q) return p.exports;
  q = 1;
  const { normalizeIPv6: I, normalizeIPv4: C, removeDotSegments: c, recomposeAuthority: x, normalizeComponentEncoding: d } = j(), m = L();
  function U(n, t) {
    return typeof n == "string" ? n = h(u(n, t), t) : typeof n == "object" && (n = u(h(n, t), t)), n;
  }
  function E(n, t, r) {
    const e = Object.assign({ scheme: "null" }, r), s = y(u(n, e), u(t, e), e, !0);
    return h(s, { ...e, skipEscape: !0 });
  }
  function y(n, t, r, e) {
    const s = {};
    return e || (n = u(h(n, r), r), t = u(h(t, r), r)), r = r || {}, !r.tolerant && t.scheme ? (s.scheme = t.scheme, s.userinfo = t.userinfo, s.host = t.host, s.port = t.port, s.path = c(t.path || ""), s.query = t.query) : (t.userinfo !== void 0 || t.host !== void 0 || t.port !== void 0 ? (s.userinfo = t.userinfo, s.host = t.host, s.port = t.port, s.path = c(t.path || ""), s.query = t.query) : (t.path ? (t.path.charAt(0) === "/" ? s.path = c(t.path) : ((n.userinfo !== void 0 || n.host !== void 0 || n.port !== void 0) && !n.path ? s.path = "/" + t.path : n.path ? s.path = n.path.slice(0, n.path.lastIndexOf("/") + 1) + t.path : s.path = t.path, s.path = c(s.path)), s.query = t.query) : (s.path = n.path, t.query !== void 0 ? s.query = t.query : s.query = n.query), s.userinfo = n.userinfo, s.host = n.host, s.port = n.port), s.scheme = n.scheme), s.fragment = t.fragment, s;
  }
  function S(n, t, r) {
    return typeof n == "string" ? (n = unescape(n), n = h(d(u(n, r), !0), { ...r, skipEscape: !0 })) : typeof n == "object" && (n = h(d(n, !0), { ...r, skipEscape: !0 })), typeof t == "string" ? (t = unescape(t), t = h(d(u(t, r), !0), { ...r, skipEscape: !0 })) : typeof t == "object" && (t = h(d(t, !0), { ...r, skipEscape: !0 })), n.toLowerCase() === t.toLowerCase();
  }
  function h(n, t) {
    const r = {
      host: n.host,
      scheme: n.scheme,
      userinfo: n.userinfo,
      port: n.port,
      path: n.path,
      query: n.query,
      nid: n.nid,
      nss: n.nss,
      uuid: n.uuid,
      fragment: n.fragment,
      reference: n.reference,
      resourceName: n.resourceName,
      secure: n.secure,
      error: ""
    }, e = Object.assign({}, t), s = [], i = m[(e.scheme || r.scheme || "").toLowerCase()];
    i && i.serialize && i.serialize(r, e), r.path !== void 0 && (e.skipEscape ? r.path = unescape(r.path) : (r.path = escape(r.path), r.scheme !== void 0 && (r.path = r.path.split("%3A").join(":")))), e.reference !== "suffix" && r.scheme && s.push(r.scheme, ":");
    const f = x(r);
    if (f !== void 0 && (e.reference !== "suffix" && s.push("//"), s.push(f), r.path && r.path.charAt(0) !== "/" && s.push("/")), r.path !== void 0) {
      let o = r.path;
      !e.absolutePath && (!i || !i.absolutePath) && (o = c(o)), f === void 0 && (o = o.replace(/^\/\//u, "/%2F")), s.push(o);
    }
    return r.query !== void 0 && s.push("?", r.query), r.fragment !== void 0 && s.push("#", r.fragment), s.join("");
  }
  const _ = Array.from({ length: 127 }, (n, t) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(t)));
  function k(n) {
    let t = 0;
    for (let r = 0, e = n.length; r < e; ++r)
      if (t = n.charCodeAt(r), t > 126 || _[t])
        return !0;
    return !1;
  }
  const z = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
  function u(n, t) {
    const r = Object.assign({}, t), e = {
      scheme: void 0,
      userinfo: void 0,
      host: "",
      port: void 0,
      path: "",
      query: void 0,
      fragment: void 0
    }, s = n.indexOf("%") !== -1;
    let i = !1;
    r.reference === "suffix" && (n = (r.scheme ? r.scheme + ":" : "") + "//" + n);
    const f = n.match(z);
    if (f) {
      if (e.scheme = f[1], e.userinfo = f[3], e.host = f[4], e.port = parseInt(f[5], 10), e.path = f[6] || "", e.query = f[7], e.fragment = f[8], isNaN(e.port) && (e.port = f[5]), e.host) {
        const a = C(e.host);
        if (a.isIPV4 === !1) {
          const g = I(a.host);
          e.host = g.host.toLowerCase(), i = g.isIPV6;
        } else
          e.host = a.host, i = !0;
      }
      e.scheme === void 0 && e.userinfo === void 0 && e.host === void 0 && e.port === void 0 && e.query === void 0 && !e.path ? e.reference = "same-document" : e.scheme === void 0 ? e.reference = "relative" : e.fragment === void 0 ? e.reference = "absolute" : e.reference = "uri", r.reference && r.reference !== "suffix" && r.reference !== e.reference && (e.error = e.error || "URI is not a " + r.reference + " reference.");
      const o = m[(r.scheme || e.scheme || "").toLowerCase()];
      if (!r.unicodeSupport && (!o || !o.unicodeSupport) && e.host && (r.domainHost || o && o.domainHost) && i === !1 && k(e.host))
        try {
          e.host = URL.domainToASCII(e.host.toLowerCase());
        } catch (a) {
          e.error = e.error || "Host's domain name can not be converted to ASCII: " + a;
        }
      (!o || o && !o.skipNormalize) && (s && e.scheme !== void 0 && (e.scheme = unescape(e.scheme)), s && e.host !== void 0 && (e.host = unescape(e.host)), e.path && (e.path = escape(unescape(e.path))), e.fragment && (e.fragment = encodeURI(decodeURIComponent(e.fragment)))), o && o.parse && o.parse(e, r);
    } else
      e.error = e.error || "URI can not be parsed.";
    return e;
  }
  const l = {
    SCHEMES: m,
    normalize: U,
    resolve: E,
    resolveComponents: y,
    equal: S,
    serialize: h,
    parse: u
  };
  return p.exports = l, p.exports.default = l, p.exports.fastUri = l, p.exports;
}
export {
  H as __require
};
//# sourceMappingURL=index.js.map
