// @bun
var Y=(A,b)=>{let v=b?.length?{}:null;if(v)for(let K of b)v[K.part.charCodeAt(0)]=K;return{part:A,store:null,inert:v,params:null,wildcardStore:null}},k=(A,b)=>({...A,part:b}),T=(A)=>({name:A,store:null,inert:null});class _{config;root={};history=[];deferred=[];constructor(A={}){this.config=A;if(A.lazy)this.find=this.lazyFind}static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g,optionalParams:/:.+?\?(?=\/|$)/g};lazyFind=(A,b)=>{if(!this.config.lazy)return this.find;return this.build(),this.find(A,b)};build(){if(!this.config.lazy)return;for(let[A,b,v]of this.deferred)this.add(A,b,v,{lazy:!1,ignoreHistory:!0});this.deferred=[],this.find=(A,b)=>{let v=this.root[A];if(!v)return null;return $(b,b.length,v,0)}}add(A,b,v,{ignoreError:K=!1,ignoreHistory:V=!1,lazy:U=this.config.lazy}={}){if(U)return this.find=this.lazyFind,this.deferred.push([A,b,v]),v;if(typeof b!=="string")throw new TypeError("Route path must be a string");if(b==="")b="/";else if(b[0]!=="/")b=`/${b}`;let J=b[b.length-1]==="*",F=b.match(_.regex.optionalParams);if(F){let S=b.replaceAll("?","");this.add(A,S,v,{ignoreError:K,ignoreHistory:V,lazy:U});for(let D=0;D<F.length;D++){let B=b.replace("/"+F[D],"");this.add(A,B,v,{ignoreError:!0,ignoreHistory:V,lazy:U})}return v}if(F)b=b.replaceAll("?","");if(this.history.find(([S,D,B])=>S===A&&D===b))return v;if(J||F&&b.charCodeAt(b.length-1)===63)b=b.slice(0,-1);if(!V)this.history.push([A,b,v]);let G=b.split(_.regex.static),X=b.match(_.regex.params)||[];if(G[G.length-1]==="")G.pop();let q;if(!this.root[A])q=this.root[A]=Y("/");else q=this.root[A];let O=0;for(let S=0;S<G.length;++S){let D=G[S];if(S>0){let B=X[O++].slice(1);if(q.params===null)q.params=T(B);else if(q.params.name!==B)if(K)return v;else throw new Error(`Cannot create route "${b}" with parameter "${B}" because a route already exists with a different parameter name ("${q.params.name}") in the same location`);let Q=q.params;if(Q.inert===null){q=Q.inert=Y(D);continue}q=Q.inert}for(let B=0;;){if(B===D.length){if(B<q.part.length){let Q=k(q,q.part.slice(B));Object.assign(q,Y(D,[Q]))}break}if(B===q.part.length){if(q.inert===null)q.inert={};let Q=q.inert[D.charCodeAt(B)];if(Q){q=Q,D=D.slice(B),B=0;continue}let Z=Y(D.slice(B));q.inert[D.charCodeAt(B)]=Z,q=Z;break}if(D[B]!==q.part[B]){let Q=k(q,q.part.slice(B)),Z=Y(D.slice(B));Object.assign(q,Y(q.part.slice(0,B),[Q,Z])),q=Z;break}++B}}if(O<X.length){let D=X[O].slice(1);if(q.params===null)q.params=T(D);else if(q.params.name!==D)if(K)return v;else throw new Error(`Cannot create route "${b}" with parameter "${D}" because a route already exists with a different parameter name ("${q.params.name}") in the same location`);if(q.params.store===null)q.params.store=v;return q.params.store}if(J){if(q.wildcardStore===null)q.wildcardStore=v;return q.wildcardStore}if(q.store===null)q.store=v;return q.store}find(A,b){let v=this.root[A];if(!v)return null;return $(b,b.length,v,0)}}var $=(A,b,v,K)=>{let V=v.part,U=V.length,J=K+U;if(U>1){if(J>b)return null;if(U<15){for(let F=1,G=K+1;F<U;++F,++G)if(V.charCodeAt(F)!==A.charCodeAt(G))return null}else if(A.slice(K,J)!==V)return null}if(J===b){if(v.store!==null)return{store:v.store,params:{}};if(v.wildcardStore!==null)return{store:v.wildcardStore,params:{"*":""}};return null}if(v.inert!==null){let F=v.inert[A.charCodeAt(J)];if(F!==void 0){let G=$(A,b,F,J);if(G!==null)return G}}if(v.params!==null){let{store:F,name:G,inert:X}=v.params,q=A.indexOf("/",J);if(q!==J){if(q===-1||q>=b){if(F!==null){let O={};return O[G]=A.substring(J,b),{store:F,params:O}}}else if(X!==null){let O=$(A,b,X,q);if(O!==null)return O.params[G]=A.substring(J,q),O}}}if(v.wildcardStore!==null)return{store:v.wildcardStore,params:{"*":A.substring(J,b)}};return null},w=_;export{w as default,_ as Memoirist};

//# debugId=AF0DA1C424179B9664756E2164756E21
