import { __exports as c } from "../../../../../../../_virtual/index5.js";
import { __require as v } from "./constants.js";
var m;
function g() {
  if (m) return c;
  m = 1, Object.defineProperty(c, "__esModule", { value: !0 }), c.sanitizeUrl = void 0;
  var e = v();
  function d(r) {
    return e.relativeFirstCharacters.indexOf(r[0]) > -1;
  }
  function R(r) {
    var i = r.replace(e.ctrlCharactersRegex, "");
    return i.replace(e.htmlEntitiesRegex, function(t, a) {
      return String.fromCharCode(a);
    });
  }
  function f(r) {
    return URL.canParse(r);
  }
  function l(r) {
    try {
      return decodeURIComponent(r);
    } catch {
      return r;
    }
  }
  function p(r) {
    if (!r)
      return e.BLANK_URL;
    var i, t = l(r.trim());
    do
      t = R(t).replace(e.htmlCtrlEntityRegex, "").replace(e.ctrlCharactersRegex, "").replace(e.whitespaceEscapeCharsRegex, "").trim(), t = l(t), i = t.match(e.ctrlCharactersRegex) || t.match(e.htmlEntitiesRegex) || t.match(e.htmlCtrlEntityRegex) || t.match(e.whitespaceEscapeCharsRegex);
    while (i && i.length > 0);
    var a = t;
    if (!a)
      return e.BLANK_URL;
    if (d(a))
      return a;
    var h = a.trimStart(), u = h.match(e.urlSchemeRegex);
    if (!u)
      return a;
    var n = u[0].toLowerCase().trim();
    if (e.invalidProtocolRegex.test(n))
      return e.BLANK_URL;
    var s = h.replace(/\\/g, "/");
    if (n === "mailto:" || n.includes("://"))
      return s;
    if (n === "http:" || n === "https:") {
      if (!f(s))
        return e.BLANK_URL;
      var o = new URL(s);
      return o.protocol = o.protocol.toLowerCase(), o.hostname = o.hostname.toLowerCase(), o.toString();
    }
    return s;
  }
  return c.sanitizeUrl = p, c;
}
export {
  g as __require
};
