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