const I={};function w(e){let s=I[e];if(s)return s;s=I[e]=[];for(let n=0;n<128;n++){const i=String.fromCharCode(n);s.push(i)}for(let n=0;n<e.length;n++){const i=e.charCodeAt(n);s[i]="%"+("0"+i.toString(16).toUpperCase()).slice(-2)}return s}function F(e,s){typeof s!="string"&&(s=F.defaultChars);const n=w(s);return e.replace(/(%[a-f0-9]{2})+/gi,function(i){let a="";for(let t=0,h=i.length;t<h;t+=3){const r=parseInt(i.slice(t+1,t+3),16);if(r<128){a+=n[r];continue}if((r&224)===192&&t+3<h){const f=parseInt(i.slice(t+4,t+6),16);if((f&192)===128){const o=r<<6&1984|f&63;o<128?a+="��":a+=String.fromCharCode(o),t+=3;continue}}if((r&240)===224&&t+6<h){const f=parseInt(i.slice(t+4,t+6),16),o=parseInt(i.slice(t+7,t+9),16);if((f&192)===128&&(o&192)===128){const u=r<<12&61440|f<<6&4032|o&63;u<2048||u>=55296&&u<=57343?a+="���":a+=String.fromCharCode(u),t+=6;continue}}if((r&248)===240&&t+9<h){const f=parseInt(i.slice(t+4,t+6),16),o=parseInt(i.slice(t+7,t+9),16),u=parseInt(i.slice(t+10,t+12),16);if((f&192)===128&&(o&192)===128&&(u&192)===128){let l=r<<18&1835008|f<<12&258048|o<<6&4032|u&63;l<65536||l>1114111?a+="����":(l-=65536,a+=String.fromCharCode(55296+(l>>10),56320+(l&1023))),t+=9;continue}}a+="�"}return a})}F.defaultChars=";/?:@&=+$,#";F.componentChars="";const S={};function z(e){let s=S[e];if(s)return s;s=S[e]=[];for(let n=0;n<128;n++){const i=String.fromCharCode(n);/^[0-9a-z]$/i.test(i)?s.push(i):s.push("%"+("0"+n.toString(16).toUpperCase()).slice(-2))}for(let n=0;n<e.length;n++)s[e.charCodeAt(n)]=e[n];return s}function g(e,s,n){typeof s!="string"&&(n=s,s=g.defaultChars),typeof n>"u"&&(n=!0);const i=z(s);let a="";for(let t=0,h=e.length;t<h;t++){const r=e.charCodeAt(t);if(n&&r===37&&t+2<h&&/^[0-9a-f]{2}$/i.test(e.slice(t+1,t+3))){a+=e.slice(t,t+3),t+=2;continue}if(r<128){a+=i[r];continue}if(r>=55296&&r<=57343){if(r>=55296&&r<=56319&&t+1<h){const f=e.charCodeAt(t+1);if(f>=56320&&f<=57343){a+=encodeURIComponent(e[t]+e[t+1]),t++;continue}}a+="%EF%BF%BD";continue}a+=encodeURIComponent(e[t])}return a}g.defaultChars=";/?:@&=+$,-_.!~*'()#";g.componentChars="-_.!~*'()";function U(e){let s="";return s+=e.protocol||"",s+=e.slashes?"//":"",s+=e.auth?e.auth+"@":"",e.hostname&&e.hostname.indexOf(":")!==-1?s+="["+e.hostname+"]":s+=e.hostname||"",s+=e.port?":"+e.port:"",s+=e.pathname||"",s+=e.search||"",s+=e.hash||"",s}function d(){this.protocol=null,this.slashes=null,this.auth=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.pathname=null}const E=/^([a-z0-9.+-]+:)/i,H=/:[0-9]*$/,B=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,L=["<",">",'"',"`"," ","\r",`
`,"	"],M=["{","}","|","\\","^","`"].concat(L),R=["'"].concat(M),O=["%","/","?",";","#"].concat(R),_=["/","?","#"],Z=255,$=/^[+a-z0-9A-Z_-]{0,63}$/,T=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,j={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0};function G(e,s){if(e&&e instanceof d)return e;const n=new d;return n.parse(e,s),n}d.prototype.parse=function(e,s){let n,i,a,t=e;if(t=t.trim(),!s&&e.split("#").length===1){const o=B.exec(t);if(o)return this.pathname=o[1],o[2]&&(this.search=o[2]),this}let h=E.exec(t);if(h&&(h=h[0],n=h.toLowerCase(),this.protocol=h,t=t.substr(h.length)),(s||h||t.match(/^\/\/[^@\/]+@[^@\/]+/))&&(a=t.substr(0,2)==="//",a&&!(h&&j[h])&&(t=t.substr(2),this.slashes=!0)),!j[h]&&(a||h&&!y[h])){let o=-1;for(let c=0;c<_.length;c++)i=t.indexOf(_[c]),i!==-1&&(o===-1||i<o)&&(o=i);let u,l;o===-1?l=t.lastIndexOf("@"):l=t.lastIndexOf("@",o),l!==-1&&(u=t.slice(0,l),t=t.slice(l+1),this.auth=u),o=-1;for(let c=0;c<O.length;c++)i=t.indexOf(O[c]),i!==-1&&(o===-1||i<o)&&(o=i);o===-1&&(o=t.length),t[o-1]===":"&&o--;const A=t.slice(0,o);t=t.slice(o),this.parseHost(A),this.hostname=this.hostname||"";const D=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!D){const c=this.hostname.split(/\./);for(let x=0,v=c.length;x<v;x++){const m=c[x];if(m&&!m.match($)){let b="";for(let p=0,C=m.length;p<C;p++)m.charCodeAt(p)>127?b+="x":b+=m[p];if(!b.match($)){const p=c.slice(0,x),C=c.slice(x+1),P=m.match(T);P&&(p.push(P[1]),C.unshift(P[2])),C.length&&(t=C.join(".")+t),this.hostname=p.join(".");break}}}}this.hostname.length>Z&&(this.hostname=""),D&&(this.hostname=this.hostname.substr(1,this.hostname.length-2))}const r=t.indexOf("#");r!==-1&&(this.hash=t.substr(r),t=t.slice(0,r));const f=t.indexOf("?");return f!==-1&&(this.search=t.substr(f),t=t.slice(0,f)),t&&(this.pathname=t),y[n]&&this.hostname&&!this.pathname&&(this.pathname=""),this};d.prototype.parseHost=function(e){let s=H.exec(e);s&&(s=s[0],s!==":"&&(this.port=s.substr(1)),e=e.substr(0,e.length-s.length)),e&&(this.hostname=e)};const J=Object.freeze(Object.defineProperty({__proto__:null,decode:F,encode:g,format:U,parse:G},Symbol.toStringTag,{value:"Module"}));export{F as d,g as e,U as f,J as m,G as u};
