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