export class Uri{static _keys=["scheme","user","password","host","port","path","query","fragment"];static _queryRegex=/(?:^|&)(?:([^&=]*)=)?([^&]*)/g;static _uriRegex=/^(?:([^:/?#]+):)?(?:\/\/(?:([^:@]*)(?::([^:@]*))?@)?([^:/?#]*)(?::(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;scheme;get authority(){const t=this.password?`:${encodeURIComponent(this.password)}`:"";return`${this.user?`${encodeURIComponent(this.user)}${t}@`:""}${encodeURIComponent(this.host)||""}${this.port?`:${this.port}`:""}`}user;password;host;port;path;get query(){const t=Array.from(this.queryValues).filter((([t])=>"string"==typeof t)).map((([t,e])=>`${encodeURIComponent(`${t}`)}=${encodeURIComponent(e)}`)),e=Array.from(this.queryValues).filter((([t])=>"number"==typeof t)).sort((([t],[e])=>t-e)).map((([t,e])=>`${encodeURIComponent(e)}`));return[].concat(t,e).join("&")}set query(t){if(this.queryValues.clear(),!t)return;let e=0;t.replace(Uri._queryRegex,((t,...r)=>(r[0]?this.queryValues.set(decodeURIComponent(r[0]),decodeURIComponent(r[1])):r[1]&&this.queryValues.set(e++,decodeURIComponent(r[1])),t)))}queryValues=new Map;fragment;get isRelative(){return!this.scheme}get isAbsolute(){return!this.isRelative}constructor(t){t&&this._parseUri(t)}clone(){return new Uri(this.toString())}toString(){const t=this.scheme?`${encodeURIComponent(this.scheme)}:`:"",e=this.authority?`//${this.authority}`:"";return`${t}${e}${e&&this.path&&!this.path.startsWith("/")?`/${this.path}`:this.path}${this.queryValues.size?`?${this.query}`:""}${this.fragment?`#${encodeURIComponent(this.fragment)}`:""}`}toAbsoluteUri(t){if(!t||this.isAbsolute)return this.clone();const e="string"==typeof t?new Uri(t):t,r=new Uri;if(this.authority)r.host=this.host,r.port=this.port,r.user=this.user,r.password=this.password,r.path=this.path,r.query=this.query;else{if(this.path){if(this.path.startsWith("/"))r.path=this.path;else{const t=e.path.split("/");t.pop();const s=this.path.split("/");for(const e of s)"."!==e&&(".."===e?t.pop():t.push(e));r.path=t.join("/")}r.query=this.query}else r.path=e.path,r.query=this.query?this.query:e.query;r.host=e.host,r.port=e.port,r.user=e.user,r.password=e.password}return r.scheme=e.scheme,r.fragment=this.fragment,r}_parseUri(t){const e=Uri._uriRegex.exec(t);for(let t=0;t<Uri._keys.length;t++)this[Uri._keys[t]]=decodeURIComponent(e[t+1]||"")}}export function isRelativeUri(t){return!t?.match(/^\w+:\/\//)}export function isAbsoluteUri(t){return!isRelativeUri(t)}export function isPackageUri(t){return!(!t||"string"!=typeof t)&&t.startsWith("@")}export function toAbsoluteUri(t,e){return t?new Uri(t).toAbsoluteUri(e).toString():t}export function addQueryParameter(t,e,r){const s="string"==typeof t?new Uri(t):t.clone();return s.queryValues.set(e,r),s.toString()}export function removeQueryParameter(t,e){const r="string"==typeof t?new Uri(t):t.clone();return r.queryValues.delete(e),r.toString()}