!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).rawth={})}(this,(function(e){"use strict";function r(e,r){void 0===r&&(r={});for(var t=function(e){for(var r=[],t=0;t=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||95===s))break;f+=e[a++]}if(!f)throw new TypeError("Missing parameter name at "+t);r.push({type:"NAME",index:t,value:f}),t=a}else r.push({type:"CLOSE",index:t,value:e[t++]});else r.push({type:"OPEN",index:t,value:e[t++]});else r.push({type:"ESCAPED_CHAR",index:t++,value:e[t++]});else r.push({type:"MODIFIER",index:t,value:e[t++]})}return r.push({type:"END",index:t,value:""}),r}(e),i=r.prefixes,o=void 0===i?"./":i,f="[^"+n(r.delimiter||"/#?")+"]+?",a=[],s=0,u=0,p="",c=function(e){if(u-1:void 0===b;f||(h+="(?:"+v+"(?="+l+"))?"),R||(h+="(?="+v+"|"+l+")")}return new RegExp(h,i(t))}(r(e,o),t,o)}function f(e,r,t){return e instanceof RegExp?function(e,r){if(!r)return e;for(var t=/\((?:\?<(.*?)>)?(?!\?)/g,n=0,i=t.exec(e.source);i;)r.push({name:i[1]||n++,prefix:"",suffix:"",modifier:"",pattern:""}),i=t.exec(e.source);return e}(e,r):Array.isArray(e)?function(e,r,t){var n=e.map((function(e){return f(e,r,t).source}));return new RegExp("(?:"+n.join("|")+")",i(t))}(e,r,t):o(e,r,t)}const a=Symbol();function s(...e){return new Promise((r,t)=>function e(n,i){if(!n.length)return r(i);const[o,...f]=n,s="function"==typeof o?o(i):o,u=r=>e(f,r);if(null!=s){if(s===a)return;if(s.then)return s.then(u,t)}return Promise.resolve(u(s))}(e))}s.cancel=()=>a,s.compose=(...e)=>s(...e.reverse());const u=new Set,p=Symbol();function c(e,r){return e.forEach(t=>{t(r)===p&&e.delete(t)}),e}function d(e){throw new Error(e)}function l(...e){const[r,t,n,i]=[new Set,new Set,new Set,new Set(e)],o=function(e){const r=function*(){for(;;){const r=yield;yield s(r,...e)}}();return r.next(),r}(i),f=Object.create(o),a=e=>r=>e.add(r)&&f,u=e=>r=>e.delete(r)?f:d("Couldn't remove handler passed by reference");return Object.assign(f,{on:Object.freeze({value:a(r),error:a(t),end:a(n)}),off:Object.freeze({value:u(r),error:u(t),end:u(n)}),connect:a(i),push(e){const{value:n,done:i}=f.next(e);return i||n.then(e=>c(r,e),e=>c(t,e)),f},end:()=>(o.return(),c(n),[r,t,n,i].forEach(e=>e.clear()),f),fork:()=>l(...i),next(e){const r=o.next(e);return o.next(),r}})}l.install=function(e,r){return e&&"string"==typeof e||d("Please provide a name (as string) for your erre plugin"),r&&"function"==typeof r||d("Please provide a function for your erre plugin"),u.has(e)?d(`The ${e} is already part of the erre API, please provide a different name`):(l[e]=r,u.add(e)),l},l.install("cancel",s.cancel),l.install("off",()=>p);const v="undefined"!=typeof process,h=e=>e.replace(g.base,""),y=e=>r=>R(r,e)?r:l.cancel(),m=e=>{if(!g.silentErrors)throw new Error(e)},x=e=>(e=>"string"==typeof e)(e)?e:l.cancel(),E=l(x).on.error(m),g={base:"",silentErrors:!1,sensitive:!1,strict:!1,end:!0,start:!0,delimiter:"/#?",encode:void 0,endsWith:void 0,prefixes:"./"},w=e=>({...g,...e}),b=(e,r,t={})=>{const{base:n}=w(t),[,...i]=r.exec(e),o=((...e)=>v?require("url").parse(...e):new URL(...e))(e,n);return o.params=i.reduce((e,r,n)=>{const i=t.keys&&t.keys[n];return i&&(e[i.name]=r?decodeURIComponent(r):r),e},{}),o},R=(e,r)=>r.test(e),A=(e,r)=>[decodeURI,h,y(e),t=>b(t,e,r)];e.createURLStreamPipe=A,e.default=function(e,r){const t=[],n=f(e,t,r),i=l(...A(n,{...r,keys:t}));return(o=E,a=i,o.on.value(a.push),a.on.end(()=>{o.off.value(a.push)}),a).on.error(m);var o,a},e.defaults=g,e.filterStrings=x,e.match=R,e.mergeOptions=w,e.router=E,e.toPath=(e,r,n)=>t(e,w(n))(r),e.toRegexp=(e,r,t)=>f(e,r,w(t)),e.toURL=b,Object.defineProperty(e,"__esModule",{value:!0})}));