import { __require as D } from "./scopedChars.js";
var o, v;
function H() {
  if (v) return o;
  v = 1;
  const { HEX: z } = D(), S = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u;
  function a(e) {
    if (h(e, ".") < 3)
      return { host: e, isIPV4: !1 };
    const i = e.match(S) || [], [r] = i;
    return r ? { host: k(r, "."), isIPV4: !0 } : { host: e, isIPV4: !1 };
  }
  function d(e, i = !1) {
    let r = "", t = !0;
    for (const s of e) {
      if (z[s] === void 0) return;
      s !== "0" && t === !0 && (t = !1), t || (r += s);
    }
    return i && r.length === 0 && (r = "0"), r;
  }
  function y(e) {
    let i = 0;
    const r = { error: !1, address: "", zone: "" }, t = [], s = [];
    let f = !1, u = !1, V = !1;
    function q() {
      if (s.length) {
        if (f === !1) {
          const n = d(s);
          if (n !== void 0)
            t.push(n);
          else
            return r.error = !0, !1;
        }
        s.length = 0;
      }
      return !0;
    }
    for (let n = 0; n < e.length; n++) {
      const l = e[n];
      if (!(l === "[" || l === "]"))
        if (l === ":") {
          if (u === !0 && (V = !0), !q())
            break;
          if (i++, t.push(":"), i > 7) {
            r.error = !0;
            break;
          }
          n - 1 >= 0 && e[n - 1] === ":" && (u = !0);
          continue;
        } else if (l === "%") {
          if (!q())
            break;
          f = !0;
        } else {
          s.push(l);
          continue;
        }
    }
    return s.length && (f ? r.zone = s.join("") : V ? t.push(s.join("")) : t.push(d(s))), r.address = t.join(""), r;
  }
  function c(e) {
    if (h(e, ":") < 2)
      return { host: e, isIPV6: !1 };
    const i = y(e);
    if (i.error)
      return { host: e, isIPV6: !1 };
    {
      let r = i.address, t = i.address;
      return i.zone && (r += "%" + i.zone, t += "%25" + i.zone), { host: r, escapedHost: t, isIPV6: !0 };
    }
  }
  function k(e, i) {
    let r = "", t = !0;
    const s = e.length;
    for (let f = 0; f < s; f++) {
      const u = e[f];
      u === "0" && t ? (f + 1 <= s && e[f + 1] === i || f + 1 === s) && (r += u, t = !1) : (u === i ? t = !0 : t = !1, r += u);
    }
    return r;
  }
  function h(e, i) {
    let r = 0;
    for (let t = 0; t < e.length; t++)
      e[t] === i && r++;
    return r;
  }
  const g = /^\.\.?\//u, I = /^\/\.(?:\/|$)/u, P = /^\/\.\.(?:\/|$)/u, R = /^\/?(?:.|\n)*?(?=\/|$)/u;
  function b(e) {
    const i = [];
    for (; e.length; )
      if (e.match(g))
        e = e.replace(g, "");
      else if (e.match(I))
        e = e.replace(I, "/");
      else if (e.match(P))
        e = e.replace(P, "/"), i.pop();
      else if (e === "." || e === "..")
        e = "";
      else {
        const r = e.match(R);
        if (r) {
          const t = r[0];
          e = e.slice(t.length), i.push(t);
        } else
          throw new Error("Unexpected dot segment condition");
      }
    return i.join("");
  }
  function j(e, i) {
    const r = i !== !0 ? escape : unescape;
    return e.scheme !== void 0 && (e.scheme = r(e.scheme)), e.userinfo !== void 0 && (e.userinfo = r(e.userinfo)), e.host !== void 0 && (e.host = r(e.host)), e.path !== void 0 && (e.path = r(e.path)), e.query !== void 0 && (e.query = r(e.query)), e.fragment !== void 0 && (e.fragment = r(e.fragment)), e;
  }
  function p(e) {
    const i = [];
    if (e.userinfo !== void 0 && (i.push(e.userinfo), i.push("@")), e.host !== void 0) {
      let r = unescape(e.host);
      const t = a(r);
      if (t.isIPV4)
        r = t.host;
      else {
        const s = c(t.host);
        s.isIPV6 === !0 ? r = `[${s.escapedHost}]` : r = e.host;
      }
      i.push(r);
    }
    return (typeof e.port == "number" || typeof e.port == "string") && (i.push(":"), i.push(String(e.port))), i.length ? i.join("") : void 0;
  }
  return o = {
    recomposeAuthority: p,
    normalizeComponentEncoding: j,
    removeDotSegments: b,
    normalizeIPv4: a,
    normalizeIPv6: c,
    stringArrayToHexStripped: d
  }, o;
}
export {
  H as __require
};
//# sourceMappingURL=utils.js.map
