const C = {};
function s(o) {
  let n = C[o];
  if (n)
    return n;
  n = C[o] = [];
  for (let e = 0; e < 128; e++) {
    const i = String.fromCharCode(e);
    /^[0-9a-z]$/i.test(i) ? n.push(i) : n.push("%" + ("0" + e.toString(16).toUpperCase()).slice(-2));
  }
  for (let e = 0; e < o.length; e++)
    n[o.charCodeAt(e)] = o[e];
  return n;
}
function h(o, n, e) {
  typeof n != "string" && (e = n, n = h.defaultChars), typeof e > "u" && (e = !0);
  const i = s(n);
  let c = "";
  for (let t = 0, r = o.length; t < r; t++) {
    const f = o.charCodeAt(t);
    if (e && f === 37 && t + 2 < r && /^[0-9a-f]{2}$/i.test(o.slice(t + 1, t + 3))) {
      c += o.slice(t, t + 3), t += 2;
      continue;
    }
    if (f < 128) {
      c += i[f];
      continue;
    }
    if (f >= 55296 && f <= 57343) {
      if (f >= 55296 && f <= 56319 && t + 1 < r) {
        const a = o.charCodeAt(t + 1);
        if (a >= 56320 && a <= 57343) {
          c += encodeURIComponent(o[t] + o[t + 1]), t++;
          continue;
        }
      }
      c += "%EF%BF%BD";
      continue;
    }
    c += encodeURIComponent(o[t]);
  }
  return c;
}
h.defaultChars = ";/?:@&=+$,-_.!~*'()#";
h.componentChars = "-_.!~*'()";
export {
  h as default
};
