import { commonjsGlobal as x } from "../../../../../../_virtual/_commonjsHelpers.js";
import { __require as O } from "../../../requires-port@1.0.0/node_modules/requires-port/index.js";
import { __require as N } from "../../../querystringify@2.2.0/node_modules/querystringify/index.js";
var g, k;
function F() {
  if (k) return g;
  k = 1;
  var C = O(), c = N(), S = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/, q = /[\n\r\t]/g, A = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//, R = /:\d+$/, L = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i, j = /^[a-zA-Z]:/;
  function u(o) {
    return (o || "").toString().replace(S, "");
  }
  var m = [
    ["#", "hash"],
    // Extract from the back.
    ["?", "query"],
    // Extract from the back.
    function(r, t) {
      return p(t.protocol) ? r.replace(/\\/g, "/") : r;
    },
    ["/", "pathname"],
    // Extract from the back.
    ["@", "auth", 1],
    // Extract from the front.
    [NaN, "host", void 0, 1, 1],
    // Set left over value.
    [/:(\d*)$/, "port", void 0, 1],
    // RegExp the back.
    [NaN, "hostname", void 0, 1, 1]
    // Set left over.
  ], U = { hash: 1, query: 1 };
  function b(o) {
    var r;
    typeof window < "u" ? r = window : typeof x < "u" ? r = x : typeof self < "u" ? r = self : r = {};
    var t = r.location || {};
    o = o || t;
    var e = {}, i = typeof o, s;
    if (o.protocol === "blob:")
      e = new h(unescape(o.pathname), {});
    else if (i === "string") {
      e = new h(o, {});
      for (s in U) delete e[s];
    } else if (i === "object") {
      for (s in o)
        s in U || (e[s] = o[s]);
      e.slashes === void 0 && (e.slashes = A.test(o.href));
    }
    return e;
  }
  function p(o) {
    return o === "file:" || o === "ftp:" || o === "http:" || o === "https:" || o === "ws:" || o === "wss:";
  }
  function I(o, r) {
    o = u(o), o = o.replace(q, ""), r = r || {};
    var t = L.exec(o), e = t[1] ? t[1].toLowerCase() : "", i = !!t[2], s = !!t[3], a = 0, f;
    return i ? s ? (f = t[2] + t[3] + t[4], a = t[2].length + t[3].length) : (f = t[2] + t[4], a = t[2].length) : s ? (f = t[3] + t[4], a = t[3].length) : f = t[4], e === "file:" ? a >= 2 && (f = f.slice(2)) : p(e) ? f = t[4] : e ? i && (f = f.slice(2)) : a >= 2 && p(r.protocol) && (f = t[4]), {
      protocol: e,
      slashes: i || p(e),
      slashesCount: a,
      rest: f
    };
  }
  function z(o, r) {
    if (o === "") return r;
    for (var t = (r || "/").split("/").slice(0, -1).concat(o.split("/")), e = t.length, i = t[e - 1], s = !1, a = 0; e--; )
      t[e] === "." ? t.splice(e, 1) : t[e] === ".." ? (t.splice(e, 1), a++) : a && (e === 0 && (s = !0), t.splice(e, 1), a--);
    return s && t.unshift(""), (i === "." || i === "..") && t.push(""), t.join("/");
  }
  function h(o, r, t) {
    if (o = u(o), o = o.replace(q, ""), !(this instanceof h))
      return new h(o, r, t);
    var e, i, s, a, f, l, w = m.slice(), d = typeof r, n = this, y = 0;
    for (d !== "object" && d !== "string" && (t = r, r = null), t && typeof t != "function" && (t = c.parse), r = b(r), i = I(o || "", r), e = !i.protocol && !i.slashes, n.slashes = i.slashes || e && r.slashes, n.protocol = i.protocol || r.protocol || "", o = i.rest, (i.protocol === "file:" && (i.slashesCount !== 2 || j.test(o)) || !i.slashes && (i.protocol || i.slashesCount < 2 || !p(n.protocol))) && (w[3] = [/(.*)/, "pathname"]); y < w.length; y++) {
      if (a = w[y], typeof a == "function") {
        o = a(o, n);
        continue;
      }
      s = a[0], l = a[1], s !== s ? n[l] = o : typeof s == "string" ? (f = s === "@" ? o.lastIndexOf(s) : o.indexOf(s), ~f && (typeof a[2] == "number" ? (n[l] = o.slice(0, f), o = o.slice(f + a[2])) : (n[l] = o.slice(f), o = o.slice(0, f)))) : (f = s.exec(o)) && (n[l] = f[1], o = o.slice(0, f.index)), n[l] = n[l] || e && a[3] && r[l] || "", a[4] && (n[l] = n[l].toLowerCase());
    }
    t && (n.query = t(n.query)), e && r.slashes && n.pathname.charAt(0) !== "/" && (n.pathname !== "" || r.pathname !== "") && (n.pathname = z(n.pathname, r.pathname)), n.pathname.charAt(0) !== "/" && p(n.protocol) && (n.pathname = "/" + n.pathname), C(n.port, n.protocol) || (n.host = n.hostname, n.port = ""), n.username = n.password = "", n.auth && (f = n.auth.indexOf(":"), ~f ? (n.username = n.auth.slice(0, f), n.username = encodeURIComponent(decodeURIComponent(n.username)), n.password = n.auth.slice(f + 1), n.password = encodeURIComponent(decodeURIComponent(n.password))) : n.username = encodeURIComponent(decodeURIComponent(n.auth)), n.auth = n.password ? n.username + ":" + n.password : n.username), n.origin = n.protocol !== "file:" && p(n.protocol) && n.host ? n.protocol + "//" + n.host : "null", n.href = n.toString();
  }
  function P(o, r, t) {
    var e = this;
    switch (o) {
      case "query":
        typeof r == "string" && r.length && (r = (t || c.parse)(r)), e[o] = r;
        break;
      case "port":
        e[o] = r, C(r, e.protocol) ? r && (e.host = e.hostname + ":" + r) : (e.host = e.hostname, e[o] = "");
        break;
      case "hostname":
        e[o] = r, e.port && (r += ":" + e.port), e.host = r;
        break;
      case "host":
        e[o] = r, R.test(r) ? (r = r.split(":"), e.port = r.pop(), e.hostname = r.join(":")) : (e.hostname = r, e.port = "");
        break;
      case "protocol":
        e.protocol = r.toLowerCase(), e.slashes = !t;
        break;
      case "pathname":
      case "hash":
        if (r) {
          var i = o === "pathname" ? "/" : "#";
          e[o] = r.charAt(0) !== i ? i + r : r;
        } else
          e[o] = r;
        break;
      case "username":
      case "password":
        e[o] = encodeURIComponent(r);
        break;
      case "auth":
        var s = r.indexOf(":");
        ~s ? (e.username = r.slice(0, s), e.username = encodeURIComponent(decodeURIComponent(e.username)), e.password = r.slice(s + 1), e.password = encodeURIComponent(decodeURIComponent(e.password))) : e.username = encodeURIComponent(decodeURIComponent(r));
    }
    for (var a = 0; a < m.length; a++) {
      var f = m[a];
      f[4] && (e[f[1]] = e[f[1]].toLowerCase());
    }
    return e.auth = e.password ? e.username + ":" + e.password : e.username, e.origin = e.protocol !== "file:" && p(e.protocol) && e.host ? e.protocol + "//" + e.host : "null", e.href = e.toString(), e;
  }
  function _(o) {
    (!o || typeof o != "function") && (o = c.stringify);
    var r, t = this, e = t.host, i = t.protocol;
    i && i.charAt(i.length - 1) !== ":" && (i += ":");
    var s = i + (t.protocol && t.slashes || p(t.protocol) ? "//" : "");
    return t.username ? (s += t.username, t.password && (s += ":" + t.password), s += "@") : t.password ? (s += ":" + t.password, s += "@") : t.protocol !== "file:" && p(t.protocol) && !e && t.pathname !== "/" && (s += "@"), (e[e.length - 1] === ":" || R.test(t.hostname) && !t.port) && (e += ":"), s += e + t.pathname, r = typeof t.query == "object" ? o(t.query) : t.query, r && (s += r.charAt(0) !== "?" ? "?" + r : r), t.hash && (s += t.hash), s;
  }
  return h.prototype = { set: P, toString: _ }, h.extractProtocol = I, h.location = b, h.trimLeft = u, h.qs = c, g = h, g;
}
export {
  F as __require
};
//# sourceMappingURL=index.js.map
