var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,a,i={},n={};var l=function(){if(a)return i;a=1,Object.defineProperty(i,"__esModule",{value:!0}),i.sanitizeUrl=void 0;var e=(r||(r=1,Object.defineProperty(n,"__esModule",{value:!0}),n.BLANK_URL=n.relativeFirstCharacters=n.whitespaceEscapeCharsRegex=n.urlSchemeRegex=n.ctrlCharactersRegex=n.htmlCtrlEntityRegex=n.htmlEntitiesRegex=n.invalidProtocolRegex=void 0,n.invalidProtocolRegex=/^([^\w]*)(javascript|data|vbscript)/im,n.htmlEntitiesRegex=/&#(\w+)(^\w|;)?/g,n.htmlCtrlEntityRegex=/&(newline|tab);/gi,n.ctrlCharactersRegex=/[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim,n.urlSchemeRegex=/^.+(:|&colon;)/gim,n.whitespaceEscapeCharsRegex=/(\\|%5[cC])((%(6[eE]|72|74))|[nrt])/g,n.relativeFirstCharacters=[".","/"],n.BLANK_URL="about:blank"),n);function t(t){return t.replace(e.ctrlCharactersRegex,"").replace(e.htmlEntitiesRegex,function(e,t){return String.fromCharCode(t)})}function l(e){try{return decodeURIComponent(e)}catch(t){return e}}return i.sanitizeUrl=function(r){if(!r)return e.BLANK_URL;var a,i=l(r.trim());do{a=(i=l(i=t(i).replace(e.htmlCtrlEntityRegex,"").replace(e.ctrlCharactersRegex,"").replace(e.whitespaceEscapeCharsRegex,"").trim())).match(e.ctrlCharactersRegex)||i.match(e.htmlEntitiesRegex)||i.match(e.htmlCtrlEntityRegex)||i.match(e.whitespaceEscapeCharsRegex)}while(a&&a.length>0);var n=i;if(!n)return e.BLANK_URL;if(function(t){return e.relativeFirstCharacters.indexOf(t[0])>-1}(n))return n;var o=n.trimStart(),c=o.match(e.urlSchemeRegex);if(!c)return n;var s=c[0].toLowerCase().trim();if(e.invalidProtocolRegex.test(s))return e.BLANK_URL;var u=o.replace(/\\/g,"/");if("mailto:"===s||s.includes("://"))return u;if("http:"===s||"https:"===s){if(!function(e){return URL.canParse(e)}(u))return e.BLANK_URL;var h=new URL(u);return h.protocol=h.protocol.toLowerCase(),h.hostname=h.hostname.toLowerCase(),h.toString()}return u},i}();export{e as c,l as d,t as g};
