@modastar/z-router 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +38 -0
- package/README.md +12 -0
- package/demo/dist/assets/index-BnRxLDj4.js +23 -0
- package/demo/dist/assets/index-C0uITd16.css +1 -0
- package/demo/dist/assets/index-CejLCVJl.js +1 -0
- package/demo/dist/index.html +14 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/.oxlintrc.json +0 -24
- package/.vscode/settings.json +0 -6
- package/vite.config.ts +0 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{M as K,n as Be,a as xt,c as z,p as ve,i as Le,b as Mt,t as Ct,d as En,v as Rn,e as Kn,f as Nn,g as kn,h as Bn,j as N,k as Ln,l as _n,m as ce,o as tt,r as Pt,q as Un,s as Gn,u as jn,w as Ft,x as Wn,y as $n,z as Hn,A as zn,B as qn,C as Yn,D as Dt,E as It,F as Ot,G as Et}from"./index-BnRxLDj4.js";function Xn(t,e){t.indexOf(e)===-1&&t.push(e)}function Zn(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}let _e=()=>{};const Rt=t=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(t),Kt=t=>/^0[^.\s]+$/u.test(t);function Ue(t){let e;return()=>(e===void 0&&(e=t()),e)}const q=t=>t,Jn=(t,e)=>n=>e(t(n)),he=(...t)=>t.reduce(Jn),Nt=(t,e,n)=>{const s=e-t;return s===0?1:(n-t)/s};class kt{constructor(){this.subscriptions=[]}add(e){return Xn(this.subscriptions,e),()=>Zn(this.subscriptions,e)}notify(e,n,s){const i=this.subscriptions.length;if(i)if(i===1)this.subscriptions[0](e,n,s);else for(let r=0;r<i;r++){const o=this.subscriptions[r];o&&o(e,n,s)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}}const R=t=>t*1e3,O=t=>t/1e3;function Bt(t,e){return e?t*(1e3/e):0}const Lt=(t,e,n)=>(((1-3*n+3*e)*t+(3*n-6*e))*t+3*e)*t,Qn=1e-7,es=12;function ts(t,e,n,s,i){let r,o,a=0;do o=e+(n-e)/2,r=Lt(o,s,i)-t,r>0?n=o:e=o;while(Math.abs(r)>Qn&&++a<es);return o}function te(t,e,n,s){if(t===e&&n===s)return q;const i=r=>ts(r,0,1,t,n);return r=>r===0||r===1?r:Lt(i(r),e,s)}const _t=t=>e=>e<=.5?t(2*e)/2:(2-t(2*(1-e)))/2,Ut=t=>e=>1-t(1-e),Gt=te(.33,1.53,.69,.99),Ge=Ut(Gt),jt=_t(Ge),Wt=t=>(t*=2)<1?.5*Ge(t):.5*(2-Math.pow(2,-10*(t-1))),je=t=>1-Math.sin(Math.acos(t)),ns=Ut(je),$t=_t(je),ss=te(.42,0,1,1),is=te(0,0,.58,1),Ht=te(.42,0,.58,1),rs=t=>Array.isArray(t)&&typeof t[0]!="number",zt=t=>Array.isArray(t)&&typeof t[0]=="number",os={linear:q,easeIn:ss,easeInOut:Ht,easeOut:is,circIn:je,circInOut:$t,circOut:ns,backIn:Ge,backInOut:jt,backOut:Gt,anticipate:Wt},as=t=>typeof t=="string",nt=t=>{if(zt(t)){_e(t.length===4);const[e,n,s,i]=t;return te(e,n,s,i)}else if(as(t))return os[t];return t},ne=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function us(t,e){let n=new Set,s=new Set,i=!1,r=!1;const o=new WeakSet;let a={delta:0,timestamp:0,isProcessing:!1};function u(l){o.has(l)&&(c.schedule(l),t()),l(a)}const c={schedule:(l,h=!1,f=!1)=>{const v=f&&i?n:s;return h&&o.add(l),v.has(l)||v.add(l),l},cancel:l=>{s.delete(l),o.delete(l)},process:l=>{if(a=l,i){r=!0;return}i=!0,[n,s]=[s,n],n.forEach(u),n.clear(),i=!1,r&&(r=!1,c.process(l))}};return c}const ls=40;function qt(t,e){let n=!1,s=!0;const i={delta:0,timestamp:0,isProcessing:!1},r=()=>n=!0,o=ne.reduce((g,w)=>(g[w]=us(r),g),{}),{setup:a,read:u,resolveKeyframes:c,preUpdate:l,update:h,preRender:f,render:d,postRender:v}=o,T=()=>{const g=K.useManualTiming?i.timestamp:performance.now();n=!1,K.useManualTiming||(i.delta=s?1e3/60:Math.max(Math.min(g-i.timestamp,ls),1)),i.timestamp=g,i.isProcessing=!0,a.process(i),u.process(i),c.process(i),l.process(i),h.process(i),f.process(i),d.process(i),v.process(i),i.isProcessing=!1,n&&e&&(s=!1,t(T))},b=()=>{n=!0,s=!0,i.isProcessing||t(T)};return{schedule:ne.reduce((g,w)=>{const m=o[w];return g[w]=(A,M=!1,y=!1)=>(n||b(),m.schedule(A,M,y)),g},{}),cancel:g=>{for(let w=0;w<ne.length;w++)o[ne[w]].cancel(g)},state:i,steps:o}}const{schedule:E,cancel:Te,state:re}=qt(typeof requestAnimationFrame<"u"?requestAnimationFrame:q,!0);let se;function cs(){se=void 0}const I={now:()=>(se===void 0&&I.set(re.isProcessing||K.useManualTiming?re.timestamp:performance.now()),se),set:t=>{se=t,queueMicrotask(cs)}},J=t=>Math.round(t*1e5)/1e5,We=/-?(?:\d+(?:\.\d+)?|\.\d+)/gu;function hs(t){return t==null}const fs=/^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu,$e=(t,e)=>n=>!!(typeof n=="string"&&fs.test(n)&&n.startsWith(t)||e&&!hs(n)&&Object.prototype.hasOwnProperty.call(n,e)),Yt=(t,e,n)=>s=>{if(typeof s!="string")return s;const[i,r,o,a]=s.match(We);return{[t]:parseFloat(i),[e]:parseFloat(r),[n]:parseFloat(o),alpha:a!==void 0?parseFloat(a):1}},ds=t=>z(0,255,t),de={...Be,transform:t=>Math.round(ds(t))},L={test:$e("rgb","red"),parse:Yt("red","green","blue"),transform:({red:t,green:e,blue:n,alpha:s=1})=>"rgba("+de.transform(t)+", "+de.transform(e)+", "+de.transform(n)+", "+J(xt.transform(s))+")"};function ps(t){let e="",n="",s="",i="";return t.length>5?(e=t.substring(1,3),n=t.substring(3,5),s=t.substring(5,7),i=t.substring(7,9)):(e=t.substring(1,2),n=t.substring(2,3),s=t.substring(3,4),i=t.substring(4,5),e+=e,n+=n,s+=s,i+=i),{red:parseInt(e,16),green:parseInt(n,16),blue:parseInt(s,16),alpha:i?parseInt(i,16)/255:1}}const Ve={test:$e("#"),parse:ps,transform:L.transform},$={test:$e("hsl","hue"),parse:Yt("hue","saturation","lightness"),transform:({hue:t,saturation:e,lightness:n,alpha:s=1})=>"hsla("+Math.round(t)+", "+ve.transform(J(e))+", "+ve.transform(J(n))+", "+J(xt.transform(s))+")"},x={test:t=>L.test(t)||Ve.test(t)||$.test(t),parse:t=>L.test(t)?L.parse(t):$.test(t)?$.parse(t):Ve.parse(t),transform:t=>typeof t=="string"?t:t.hasOwnProperty("red")?L.transform(t):$.transform(t),getAnimatableNone:t=>{const e=x.parse(t);return e.alpha=0,x.transform(e)}},ms=/(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;function gs(t){return isNaN(t)&&typeof t=="string"&&(t.match(We)?.length||0)+(t.match(ms)?.length||0)>0}const Xt="number",Zt="color",ys="var",bs="var(",st="${}",vs=/var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;function ee(t){const e=t.toString(),n=[],s={color:[],number:[],var:[]},i=[];let r=0;const a=e.replace(vs,u=>(x.test(u)?(s.color.push(r),i.push(Zt),n.push(x.parse(u))):u.startsWith(bs)?(s.var.push(r),i.push(ys),n.push(u)):(s.number.push(r),i.push(Xt),n.push(parseFloat(u))),++r,st)).split(st);return{values:n,split:a,indexes:s,types:i}}function Jt(t){return ee(t).values}function Qt(t){const{split:e,types:n}=ee(t),s=e.length;return i=>{let r="";for(let o=0;o<s;o++)if(r+=e[o],i[o]!==void 0){const a=n[o];a===Xt?r+=J(i[o]):a===Zt?r+=x.transform(i[o]):r+=i[o]}return r}}const Ts=t=>typeof t=="number"?0:x.test(t)?x.getAnimatableNone(t):t;function Vs(t){const e=Jt(t);return Qt(t)(e.map(Ts))}const Y={test:gs,parse:Jt,createTransformer:Qt,getAnimatableNone:Vs};function pe(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+(e-t)*6*n:n<1/2?e:n<2/3?t+(e-t)*(2/3-n)*6:t}function As({hue:t,saturation:e,lightness:n,alpha:s}){t/=360,e/=100,n/=100;let i=0,r=0,o=0;if(!e)i=r=o=n;else{const a=n<.5?n*(1+e):n+e-n*e,u=2*n-a;i=pe(u,a,t+1/3),r=pe(u,a,t),o=pe(u,a,t-1/3)}return{red:Math.round(i*255),green:Math.round(r*255),blue:Math.round(o*255),alpha:s}}function oe(t,e){return n=>n>0?e:t}const fe=(t,e,n)=>t+(e-t)*n,me=(t,e,n)=>{const s=t*t,i=n*(e*e-s)+s;return i<0?0:Math.sqrt(i)},ws=[Ve,L,$],Ss=t=>ws.find(e=>e.test(t));function it(t){const e=Ss(t);if(!e)return!1;let n=e.parse(t);return e===$&&(n=As(n)),n}const rt=(t,e)=>{const n=it(t),s=it(e);if(!n||!s)return oe(t,e);const i={...n};return r=>(i.red=me(n.red,s.red,r),i.green=me(n.green,s.green,r),i.blue=me(n.blue,s.blue,r),i.alpha=fe(n.alpha,s.alpha,r),L.transform(i))},Ae=new Set(["none","hidden"]);function xs(t,e){return Ae.has(t)?n=>n<=0?t:e:n=>n>=1?e:t}function Ms(t,e){return n=>fe(t,e,n)}function He(t){return typeof t=="number"?Ms:typeof t=="string"?Le(t)?oe:x.test(t)?rt:Fs:Array.isArray(t)?en:typeof t=="object"?x.test(t)?rt:Cs:oe}function en(t,e){const n=[...t],s=n.length,i=t.map((r,o)=>He(r)(r,e[o]));return r=>{for(let o=0;o<s;o++)n[o]=i[o](r);return n}}function Cs(t,e){const n={...t,...e},s={};for(const i in n)t[i]!==void 0&&e[i]!==void 0&&(s[i]=He(t[i])(t[i],e[i]));return i=>{for(const r in s)n[r]=s[r](i);return n}}function Ps(t,e){const n=[],s={color:0,var:0,number:0};for(let i=0;i<e.values.length;i++){const r=e.types[i],o=t.indexes[r][s[r]],a=t.values[o]??0;n[i]=a,s[r]++}return n}const Fs=(t,e)=>{const n=Y.createTransformer(e),s=ee(t),i=ee(e);return s.indexes.var.length===i.indexes.var.length&&s.indexes.color.length===i.indexes.color.length&&s.indexes.number.length>=i.indexes.number.length?Ae.has(t)&&!i.values.length||Ae.has(e)&&!s.values.length?xs(t,e):he(en(Ps(s,i),i.values),n):oe(t,e)};function tn(t,e,n){return typeof t=="number"&&typeof e=="number"&&typeof n=="number"?fe(t,e,n):He(t)(t,e)}const Ds=t=>{const e=({timestamp:n})=>t(n);return{start:(n=!0)=>E.update(e,n),stop:()=>Te(e),now:()=>re.isProcessing?re.timestamp:I.now()}},nn=(t,e,n=10)=>{let s="";const i=Math.max(Math.round(e/n),2);for(let r=0;r<i;r++)s+=Math.round(t(r/(i-1))*1e4)/1e4+", ";return`linear(${s.substring(0,s.length-2)})`},ae=2e4;function ze(t){let e=0;const n=50;let s=t.next(e);for(;!s.done&&e<ae;)e+=n,s=t.next(e);return e>=ae?1/0:e}function Is(t,e=100,n){const s=n({...t,keyframes:[0,e]}),i=Math.min(ze(s),ae);return{type:"keyframes",ease:r=>s.next(i*r).value/e,duration:O(i)}}const Os=5;function sn(t,e,n){const s=Math.max(e-Os,0);return Bt(n-t(s),e-s)}const S={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1},ge=.001;function Es({duration:t=S.duration,bounce:e=S.bounce,velocity:n=S.velocity,mass:s=S.mass}){let i,r,o=1-e;o=z(S.minDamping,S.maxDamping,o),t=z(S.minDuration,S.maxDuration,O(t)),o<1?(i=c=>{const l=c*o,h=l*t,f=l-n,d=we(c,o),v=Math.exp(-h);return ge-f/d*v},r=c=>{const h=c*o*t,f=h*n+n,d=Math.pow(o,2)*Math.pow(c,2)*t,v=Math.exp(-h),T=we(Math.pow(c,2),o);return(-i(c)+ge>0?-1:1)*((f-d)*v)/T}):(i=c=>{const l=Math.exp(-c*t),h=(c-n)*t+1;return-ge+l*h},r=c=>{const l=Math.exp(-c*t),h=(n-c)*(t*t);return l*h});const a=5/t,u=Ks(i,r,a);if(t=R(t),isNaN(u))return{stiffness:S.stiffness,damping:S.damping,duration:t};{const c=Math.pow(u,2)*s;return{stiffness:c,damping:o*2*Math.sqrt(s*c),duration:t}}}const Rs=12;function Ks(t,e,n){let s=n;for(let i=1;i<Rs;i++)s=s-t(s)/e(s);return s}function we(t,e){return t*Math.sqrt(1-e*e)}const Ns=["duration","bounce"],ks=["stiffness","damping","mass"];function ot(t,e){return e.some(n=>t[n]!==void 0)}function Bs(t){let e={velocity:S.velocity,stiffness:S.stiffness,damping:S.damping,mass:S.mass,isResolvedFromDuration:!1,...t};if(!ot(t,ks)&&ot(t,Ns))if(t.visualDuration){const n=t.visualDuration,s=2*Math.PI/(n*1.2),i=s*s,r=2*z(.05,1,1-(t.bounce||0))*Math.sqrt(i);e={...e,mass:S.mass,stiffness:i,damping:r}}else{const n=Es(t);e={...e,...n,mass:S.mass},e.isResolvedFromDuration=!0}return e}function ue(t=S.visualDuration,e=S.bounce){const n=typeof t!="object"?{visualDuration:t,keyframes:[0,1],bounce:e}:t;let{restSpeed:s,restDelta:i}=n;const r=n.keyframes[0],o=n.keyframes[n.keyframes.length-1],a={done:!1,value:r},{stiffness:u,damping:c,mass:l,duration:h,velocity:f,isResolvedFromDuration:d}=Bs({...n,velocity:-O(n.velocity||0)}),v=f||0,T=c/(2*Math.sqrt(u*l)),b=o-r,p=O(Math.sqrt(u/l)),V=Math.abs(b)<5;s||(s=V?S.restSpeed.granular:S.restSpeed.default),i||(i=V?S.restDelta.granular:S.restDelta.default);let g;if(T<1){const m=we(p,T);g=A=>{const M=Math.exp(-T*p*A);return o-M*((v+T*p*b)/m*Math.sin(m*A)+b*Math.cos(m*A))}}else if(T===1)g=m=>o-Math.exp(-p*m)*(b+(v+p*b)*m);else{const m=p*Math.sqrt(T*T-1);g=A=>{const M=Math.exp(-T*p*A),y=Math.min(m*A,300);return o-M*((v+T*p*b)*Math.sinh(y)+m*b*Math.cosh(y))/m}}const w={calculatedDuration:d&&h||null,next:m=>{const A=g(m);if(d)a.done=m>=h;else{let M=m===0?v:0;T<1&&(M=m===0?R(v):sn(g,m,A));const y=Math.abs(M)<=s,P=Math.abs(o-A)<=i;a.done=y&&P}return a.value=a.done?o:A,a},toString:()=>{const m=Math.min(ze(w),ae),A=nn(M=>w.next(m*M).value,m,30);return m+"ms "+A},toTransition:()=>{}};return w}ue.applyToOptions=t=>{const e=Is(t,100,ue);return t.ease=e.ease,t.duration=R(e.duration),t.type="keyframes",t};function Se({keyframes:t,velocity:e=0,power:n=.8,timeConstant:s=325,bounceDamping:i=10,bounceStiffness:r=500,modifyTarget:o,min:a,max:u,restDelta:c=.5,restSpeed:l}){const h=t[0],f={done:!1,value:h},d=y=>a!==void 0&&y<a||u!==void 0&&y>u,v=y=>a===void 0?u:u===void 0||Math.abs(a-y)<Math.abs(u-y)?a:u;let T=n*e;const b=h+T,p=o===void 0?b:o(b);p!==b&&(T=p-h);const V=y=>-T*Math.exp(-y/s),g=y=>p+V(y),w=y=>{const P=V(y),F=g(y);f.done=Math.abs(P)<=c,f.value=f.done?p:F};let m,A;const M=y=>{d(f.value)&&(m=y,A=ue({keyframes:[f.value,v(f.value)],velocity:sn(g,y,f.value),damping:i,stiffness:r,restDelta:c,restSpeed:l}))};return M(0),{calculatedDuration:null,next:y=>{let P=!1;return!A&&m===void 0&&(P=!0,w(y),M(y)),m!==void 0&&y>=m?A.next(y-m):(!P&&w(y),f)}}}function Ls(t,e,n){const s=[],i=n||K.mix||tn,r=t.length-1;for(let o=0;o<r;o++){let a=i(t[o],t[o+1]);if(e){const u=Array.isArray(e)?e[o]||q:e;a=he(u,a)}s.push(a)}return s}function _s(t,e,{clamp:n=!0,ease:s,mixer:i}={}){const r=t.length;if(_e(r===e.length),r===1)return()=>e[0];if(r===2&&e[0]===e[1])return()=>e[1];const o=t[0]===t[1];t[0]>t[r-1]&&(t=[...t].reverse(),e=[...e].reverse());const a=Ls(e,s,i),u=a.length,c=l=>{if(o&&l<t[0])return e[0];let h=0;if(u>1)for(;h<t.length-2&&!(l<t[h+1]);h++);const f=Nt(t[h],t[h+1],l);return a[h](f)};return n?l=>c(z(t[0],t[r-1],l)):c}function Us(t,e){const n=t[t.length-1];for(let s=1;s<=e;s++){const i=Nt(0,e,s);t.push(fe(n,1,i))}}function Gs(t){const e=[0];return Us(e,t.length-1),e}function js(t,e){return t.map(n=>n*e)}function Ws(t,e){return t.map(()=>e||Ht).splice(0,t.length-1)}function Q({duration:t=300,keyframes:e,times:n,ease:s="easeInOut"}){const i=rs(s)?s.map(nt):nt(s),r={done:!1,value:e[0]},o=js(n&&n.length===e.length?n:Gs(e),t),a=_s(o,e,{ease:Array.isArray(i)?i:Ws(e,i)});return{calculatedDuration:t,next:u=>(r.value=a(u),r.done=u>=t,r)}}const $s=t=>t!==null;function qe(t,{repeat:e,repeatType:n="loop"},s,i=1){const r=t.filter($s),a=i<0||e&&n!=="loop"&&e%2===1?0:r.length-1;return!a||s===void 0?r[a]:s}const Hs={decay:Se,inertia:Se,tween:Q,keyframes:Q,spring:ue};function rn(t){typeof t.type=="string"&&(t.type=Hs[t.type])}class Ye{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(e=>{this.resolve=e})}notifyFinished(){this.resolve()}then(e,n){return this.finished.then(e,n)}}const zs=t=>t/100;class Xe extends Ye{constructor(e){super(),this.state="idle",this.startTime=null,this.isStopped=!1,this.currentTime=0,this.holdTime=null,this.playbackSpeed=1,this.stop=()=>{const{motionValue:n}=this.options;n&&n.updatedAt!==I.now()&&this.tick(I.now()),this.isStopped=!0,this.state!=="idle"&&(this.teardown(),this.options.onStop?.())},this.options=e,this.initAnimation(),this.play(),e.autoplay===!1&&this.pause()}initAnimation(){const{options:e}=this;rn(e);const{type:n=Q,repeat:s=0,repeatDelay:i=0,repeatType:r,velocity:o=0}=e;let{keyframes:a}=e;const u=n||Q;u!==Q&&typeof a[0]!="number"&&(this.mixKeyframes=he(zs,tn(a[0],a[1])),a=[0,100]);const c=u({...e,keyframes:a});r==="mirror"&&(this.mirroredGenerator=u({...e,keyframes:[...a].reverse(),velocity:-o})),c.calculatedDuration===null&&(c.calculatedDuration=ze(c));const{calculatedDuration:l}=c;this.calculatedDuration=l,this.resolvedDuration=l+i,this.totalDuration=this.resolvedDuration*(s+1)-i,this.generator=c}updateTime(e){const n=Math.round(e-this.startTime)*this.playbackSpeed;this.holdTime!==null?this.currentTime=this.holdTime:this.currentTime=n}tick(e,n=!1){const{generator:s,totalDuration:i,mixKeyframes:r,mirroredGenerator:o,resolvedDuration:a,calculatedDuration:u}=this;if(this.startTime===null)return s.next(0);const{delay:c=0,keyframes:l,repeat:h,repeatType:f,repeatDelay:d,type:v,onUpdate:T,finalKeyframe:b}=this.options;this.speed>0?this.startTime=Math.min(this.startTime,e):this.speed<0&&(this.startTime=Math.min(e-i/this.speed,this.startTime)),n?this.currentTime=e:this.updateTime(e);const p=this.currentTime-c*(this.playbackSpeed>=0?1:-1),V=this.playbackSpeed>=0?p<0:p>i;this.currentTime=Math.max(p,0),this.state==="finished"&&this.holdTime===null&&(this.currentTime=i);let g=this.currentTime,w=s;if(h){const y=Math.min(this.currentTime,i)/a;let P=Math.floor(y),F=y%1;!F&&y>=1&&(F=1),F===1&&P--,P=Math.min(P,h+1),!!(P%2)&&(f==="reverse"?(F=1-F,d&&(F-=d/a)):f==="mirror"&&(w=o)),g=z(0,1,F)*a}const m=V?{done:!1,value:l[0]}:w.next(g);r&&(m.value=r(m.value));let{done:A}=m;!V&&u!==null&&(A=this.playbackSpeed>=0?this.currentTime>=i:this.currentTime<=0);const M=this.holdTime===null&&(this.state==="finished"||this.state==="running"&&A);return M&&v!==Se&&(m.value=qe(l,this.options,b,this.speed)),T&&T(m.value),M&&this.finish(),m}then(e,n){return this.finished.then(e,n)}get duration(){return O(this.calculatedDuration)}get iterationDuration(){const{delay:e=0}=this.options||{};return this.duration+O(e)}get time(){return O(this.currentTime)}set time(e){e=R(e),this.currentTime=e,this.startTime===null||this.holdTime!==null||this.playbackSpeed===0?this.holdTime=e:this.driver&&(this.startTime=this.driver.now()-e/this.playbackSpeed),this.driver?.start(!1)}get speed(){return this.playbackSpeed}set speed(e){this.updateTime(I.now());const n=this.playbackSpeed!==e;this.playbackSpeed=e,n&&(this.time=O(this.currentTime))}play(){if(this.isStopped)return;const{driver:e=Ds,startTime:n}=this.options;this.driver||(this.driver=e(i=>this.tick(i))),this.options.onPlay?.();const s=this.driver.now();this.state==="finished"?(this.updateFinished(),this.startTime=s):this.holdTime!==null?this.startTime=s-this.holdTime:this.startTime||(this.startTime=n??s),this.state==="finished"&&this.speed<0&&(this.startTime+=this.calculatedDuration),this.holdTime=null,this.state="running",this.driver.start()}pause(){this.state="paused",this.updateTime(I.now()),this.holdTime=this.currentTime}complete(){this.state!=="running"&&this.play(),this.state="finished",this.holdTime=null}finish(){this.notifyFinished(),this.teardown(),this.state="finished",this.options.onComplete?.()}cancel(){this.holdTime=null,this.startTime=0,this.tick(0),this.teardown(),this.options.onCancel?.()}teardown(){this.state="idle",this.stopDriver(),this.startTime=this.holdTime=null}stopDriver(){this.driver&&(this.driver.stop(),this.driver=void 0)}sample(e){return this.startTime=0,this.tick(e,!0)}attachTimeline(e){return this.options.allowFlatten&&(this.options.type="keyframes",this.options.ease="linear",this.initAnimation()),this.driver?.stop(),e.observe(this)}}function qs(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}const _=t=>t*180/Math.PI,xe=t=>{const e=_(Math.atan2(t[1],t[0]));return Me(e)},Ys={x:4,y:5,translateX:4,translateY:5,scaleX:0,scaleY:3,scale:t=>(Math.abs(t[0])+Math.abs(t[3]))/2,rotate:xe,rotateZ:xe,skewX:t=>_(Math.atan(t[1])),skewY:t=>_(Math.atan(t[2])),skew:t=>(Math.abs(t[1])+Math.abs(t[2]))/2},Me=t=>(t=t%360,t<0&&(t+=360),t),at=xe,ut=t=>Math.sqrt(t[0]*t[0]+t[1]*t[1]),lt=t=>Math.sqrt(t[4]*t[4]+t[5]*t[5]),Xs={x:12,y:13,z:14,translateX:12,translateY:13,translateZ:14,scaleX:ut,scaleY:lt,scale:t=>(ut(t)+lt(t))/2,rotateX:t=>Me(_(Math.atan2(t[6],t[5]))),rotateY:t=>Me(_(Math.atan2(-t[2],t[0]))),rotateZ:at,rotate:at,skewX:t=>_(Math.atan(t[4])),skewY:t=>_(Math.atan(t[1])),skew:t=>(Math.abs(t[1])+Math.abs(t[4]))/2};function Ce(t){return t.includes("scale")?1:0}function Pe(t,e){if(!t||t==="none")return Ce(e);const n=t.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);let s,i;if(n)s=Xs,i=n;else{const a=t.match(/^matrix\(([-\d.e\s,]+)\)$/u);s=Ys,i=a}if(!i)return Ce(e);const r=s[e],o=i[1].split(",").map(Js);return typeof r=="function"?r(o):o[r]}const Zs=(t,e)=>{const{transform:n="none"}=getComputedStyle(t);return Pe(n,e)};function Js(t){return parseFloat(t.trim())}const ct=t=>t===Be||t===Mt,Qs=new Set(["x","y","z"]),ei=Ct.filter(t=>!Qs.has(t));function ti(t){const e=[];return ei.forEach(n=>{const s=t.getValue(n);s!==void 0&&(e.push([n,s.get()]),s.set(n.startsWith("scale")?1:0))}),e}const U={width:({x:t},{paddingLeft:e="0",paddingRight:n="0"})=>t.max-t.min-parseFloat(e)-parseFloat(n),height:({y:t},{paddingTop:e="0",paddingBottom:n="0"})=>t.max-t.min-parseFloat(e)-parseFloat(n),top:(t,{top:e})=>parseFloat(e),left:(t,{left:e})=>parseFloat(e),bottom:({y:t},{top:e})=>parseFloat(e)+(t.max-t.min),right:({x:t},{left:e})=>parseFloat(e)+(t.max-t.min),x:(t,{transform:e})=>Pe(e,"x"),y:(t,{transform:e})=>Pe(e,"y")};U.translateX=U.x;U.translateY=U.y;const G=new Set;let Fe=!1,De=!1,Ie=!1;function on(){if(De){const t=Array.from(G).filter(s=>s.needsMeasurement),e=new Set(t.map(s=>s.element)),n=new Map;e.forEach(s=>{const i=ti(s);i.length&&(n.set(s,i),s.render())}),t.forEach(s=>s.measureInitialState()),e.forEach(s=>{s.render();const i=n.get(s);i&&i.forEach(([r,o])=>{s.getValue(r)?.set(o)})}),t.forEach(s=>s.measureEndState()),t.forEach(s=>{s.suspendedScrollY!==void 0&&window.scrollTo(0,s.suspendedScrollY)})}De=!1,Fe=!1,G.forEach(t=>t.complete(Ie)),G.clear()}function an(){G.forEach(t=>{t.readKeyframes(),t.needsMeasurement&&(De=!0)})}function ni(){Ie=!0,an(),on(),Ie=!1}class Ze{constructor(e,n,s,i,r,o=!1){this.state="pending",this.isAsync=!1,this.needsMeasurement=!1,this.unresolvedKeyframes=[...e],this.onComplete=n,this.name=s,this.motionValue=i,this.element=r,this.isAsync=o}scheduleResolve(){this.state="scheduled",this.isAsync?(G.add(this),Fe||(Fe=!0,E.read(an),E.resolveKeyframes(on))):(this.readKeyframes(),this.complete())}readKeyframes(){const{unresolvedKeyframes:e,name:n,element:s,motionValue:i}=this;if(e[0]===null){const r=i?.get(),o=e[e.length-1];if(r!==void 0)e[0]=r;else if(s&&n){const a=s.readValue(n,o);a!=null&&(e[0]=a)}e[0]===void 0&&(e[0]=o),i&&r===void 0&&i.set(e[0])}qs(e)}setFinalKeyframe(){}measureInitialState(){}renderEndStyles(){}measureEndState(){}complete(e=!1){this.state="complete",this.onComplete(this.unresolvedKeyframes,this.finalKeyframe,e),G.delete(this)}cancel(){this.state==="scheduled"&&(G.delete(this),this.state="pending")}resume(){this.state==="pending"&&this.scheduleResolve()}}const si=t=>t.startsWith("--");function ii(t,e,n){si(e)?t.style.setProperty(e,n):t.style[e]=n}const ri=Ue(()=>window.ScrollTimeline!==void 0),oi={};function ai(t,e){const n=Ue(t);return()=>oi[e]??n()}const un=ai(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0},"linearEasing"),Z=([t,e,n,s])=>`cubic-bezier(${t}, ${e}, ${n}, ${s})`,ht={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:Z([0,.65,.55,1]),circOut:Z([.55,0,1,.45]),backIn:Z([.31,.01,.66,-.59]),backOut:Z([.33,1.53,.69,.99])};function ln(t,e){if(t)return typeof t=="function"?un()?nn(t,e):"ease-out":zt(t)?Z(t):Array.isArray(t)?t.map(n=>ln(n,e)||ht.easeOut):ht[t]}function ui(t,e,n,{delay:s=0,duration:i=300,repeat:r=0,repeatType:o="loop",ease:a="easeOut",times:u}={},c=void 0){const l={[e]:n};u&&(l.offset=u);const h=ln(a,i);Array.isArray(h)&&(l.easing=h);const f={delay:s,duration:i,easing:Array.isArray(h)?"linear":h,fill:"both",iterations:r+1,direction:o==="reverse"?"alternate":"normal"};return c&&(f.pseudoElement=c),t.animate(l,f)}function cn(t){return typeof t=="function"&&"applyToOptions"in t}function li({type:t,...e}){return cn(t)&&un()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}class ci extends Ye{constructor(e){if(super(),this.finishedTime=null,this.isStopped=!1,!e)return;const{element:n,name:s,keyframes:i,pseudoElement:r,allowFlatten:o=!1,finalKeyframe:a,onComplete:u}=e;this.isPseudoElement=!!r,this.allowFlatten=o,this.options=e,_e(typeof e.type!="string");const c=li(e);this.animation=ui(n,s,i,c,r),c.autoplay===!1&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!r){const l=qe(i,this.options,a,this.speed);this.updateMotionValue?this.updateMotionValue(l):ii(n,s,l),this.animation.cancel()}u?.(),this.notifyFinished()}}play(){this.isStopped||(this.animation.play(),this.state==="finished"&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch{}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:e}=this;e==="idle"||e==="finished"||(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const e=this.animation.effect?.getComputedTiming?.().duration||0;return O(Number(e))}get iterationDuration(){const{delay:e=0}=this.options||{};return this.duration+O(e)}get time(){return O(Number(this.animation.currentTime)||0)}set time(e){this.finishedTime=null,this.animation.currentTime=R(e)}get speed(){return this.animation.playbackRate}set speed(e){e<0&&(this.finishedTime=null),this.animation.playbackRate=e}get state(){return this.finishedTime!==null?"finished":this.animation.playState}get startTime(){return Number(this.animation.startTime)}set startTime(e){this.animation.startTime=e}attachTimeline({timeline:e,observe:n}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,e&&ri()?(this.animation.timeline=e,q):n(this)}}const hn={anticipate:Wt,backInOut:jt,circInOut:$t};function hi(t){return t in hn}function fi(t){typeof t.ease=="string"&&hi(t.ease)&&(t.ease=hn[t.ease])}const ft=10;class di extends ci{constructor(e){fi(e),rn(e),super(e),e.startTime&&(this.startTime=e.startTime),this.options=e}updateMotionValue(e){const{motionValue:n,onUpdate:s,onComplete:i,element:r,...o}=this.options;if(!n)return;if(e!==void 0){n.set(e);return}const a=new Xe({...o,autoplay:!1}),u=R(this.finishedTime??this.time);n.setWithVelocity(a.sample(u-ft).value,a.sample(u).value,ft),a.stop()}}const dt=(t,e)=>e==="zIndex"?!1:!!(typeof t=="number"||Array.isArray(t)||typeof t=="string"&&(Y.test(t)||t==="0")&&!t.startsWith("url("));function pi(t){const e=t[0];if(t.length===1)return!0;for(let n=0;n<t.length;n++)if(t[n]!==e)return!0}function mi(t,e,n,s){const i=t[0];if(i===null)return!1;if(e==="display"||e==="visibility")return!0;const r=t[t.length-1],o=dt(i,e),a=dt(r,e);return!o||!a?!1:pi(t)||(n==="spring"||cn(n))&&s}function Oe(t){t.duration=0,t.type="keyframes"}const gi=new Set(["opacity","clipPath","filter","transform"]),yi=Ue(()=>Object.hasOwnProperty.call(Element.prototype,"animate"));function bi(t){const{motionValue:e,name:n,repeatDelay:s,repeatType:i,damping:r,type:o}=t;if(!(e?.owner?.current instanceof HTMLElement))return!1;const{onUpdate:u,transformTemplate:c}=e.owner.getProps();return yi()&&n&&gi.has(n)&&(n!=="transform"||!c)&&!u&&!s&&i!=="mirror"&&r!==0&&o!=="inertia"}const vi=40;class Ti extends Ye{constructor({autoplay:e=!0,delay:n=0,type:s="keyframes",repeat:i=0,repeatDelay:r=0,repeatType:o="loop",keyframes:a,name:u,motionValue:c,element:l,...h}){super(),this.stop=()=>{this._animation&&(this._animation.stop(),this.stopTimeline?.()),this.keyframeResolver?.cancel()},this.createdAt=I.now();const f={autoplay:e,delay:n,type:s,repeat:i,repeatDelay:r,repeatType:o,name:u,motionValue:c,element:l,...h},d=l?.KeyframeResolver||Ze;this.keyframeResolver=new d(a,(v,T,b)=>this.onKeyframesResolved(v,T,f,!b),u,c,l),this.keyframeResolver?.scheduleResolve()}onKeyframesResolved(e,n,s,i){this.keyframeResolver=void 0;const{name:r,type:o,velocity:a,delay:u,isHandoff:c,onUpdate:l}=s;this.resolvedAt=I.now(),mi(e,r,o,a)||((K.instantAnimations||!u)&&l?.(qe(e,s,n)),e[0]=e[e.length-1],Oe(s),s.repeat=0);const f={startTime:i?this.resolvedAt?this.resolvedAt-this.createdAt>vi?this.resolvedAt:this.createdAt:this.createdAt:void 0,finalKeyframe:n,...s,keyframes:e},d=!c&&bi(f)?new di({...f,element:f.motionValue.owner.current}):new Xe(f);d.finished.then(()=>this.notifyFinished()).catch(q),this.pendingTimeline&&(this.stopTimeline=d.attachTimeline(this.pendingTimeline),this.pendingTimeline=void 0),this._animation=d}get finished(){return this._animation?this.animation.finished:this._finished}then(e,n){return this.finished.finally(e).then(()=>{})}get animation(){return this._animation||(this.keyframeResolver?.resume(),ni()),this._animation}get duration(){return this.animation.duration}get iterationDuration(){return this.animation.iterationDuration}get time(){return this.animation.time}set time(e){this.animation.time=e}get speed(){return this.animation.speed}get state(){return this.animation.state}set speed(e){this.animation.speed=e}get startTime(){return this.animation.startTime}attachTimeline(e){return this._animation?this.stopTimeline=this.animation.attachTimeline(e):this.pendingTimeline=e,()=>this.stop()}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.complete()}cancel(){this._animation&&this.animation.cancel(),this.keyframeResolver?.cancel()}}const Vi=/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;function Ai(t){const e=Vi.exec(t);if(!e)return[,];const[,n,s,i]=e;return[`--${n??s}`,i]}function fn(t,e,n=1){const[s,i]=Ai(t);if(!s)return;const r=window.getComputedStyle(e).getPropertyValue(s);if(r){const o=r.trim();return Rt(o)?parseFloat(o):o}return Le(i)?fn(i,e,n+1):i}function dn(t,e){return t?.[e]??t?.default??t}const pn=new Set(["width","height","top","left","right","bottom",...Ct]),wi={test:t=>t==="auto",parse:t=>t},mn=t=>e=>e.test(t),gn=[Be,Mt,ve,En,Rn,Kn,wi],pt=t=>gn.find(mn(t));function Si(t){return typeof t=="number"?t===0:t!==null?t==="none"||t==="0"||Kt(t):!0}const xi=new Set(["brightness","contrast","saturate","opacity"]);function Mi(t){const[e,n]=t.slice(0,-1).split("(");if(e==="drop-shadow")return t;const[s]=n.match(We)||[];if(!s)return t;const i=n.replace(s,"");let r=xi.has(e)?1:0;return s!==n&&(r*=100),e+"("+r+i+")"}const Ci=/\b([a-z-]*)\(.*?\)/gu,Ee={...Y,getAnimatableNone:t=>{const e=t.match(Ci);return e?e.map(Mi).join(" "):t}},Pi={...Nn,color:x,backgroundColor:x,outlineColor:x,fill:x,stroke:x,borderColor:x,borderTopColor:x,borderRightColor:x,borderBottomColor:x,borderLeftColor:x,filter:Ee,WebkitFilter:Ee},yn=t=>Pi[t];function bn(t,e){let n=yn(t);return n!==Ee&&(n=Y),n.getAnimatableNone?n.getAnimatableNone(e):void 0}const Fi=new Set(["auto","none","0"]);function Di(t,e,n){let s=0,i;for(;s<t.length&&!i;){const r=t[s];typeof r=="string"&&!Fi.has(r)&&ee(r).values.length&&(i=t[s]),s++}if(i&&n)for(const r of e)t[r]=bn(n,i)}class Ii extends Ze{constructor(e,n,s,i,r){super(e,n,s,i,r,!0)}readKeyframes(){const{unresolvedKeyframes:e,element:n,name:s}=this;if(!n||!n.current)return;super.readKeyframes();for(let u=0;u<e.length;u++){let c=e[u];if(typeof c=="string"&&(c=c.trim(),Le(c))){const l=fn(c,n.current);l!==void 0&&(e[u]=l),u===e.length-1&&(this.finalKeyframe=c)}}if(this.resolveNoneKeyframes(),!pn.has(s)||e.length!==2)return;const[i,r]=e,o=pt(i),a=pt(r);if(o!==a)if(ct(o)&&ct(a))for(let u=0;u<e.length;u++){const c=e[u];typeof c=="string"&&(e[u]=parseFloat(c))}else U[s]&&(this.needsMeasurement=!0)}resolveNoneKeyframes(){const{unresolvedKeyframes:e,name:n}=this,s=[];for(let i=0;i<e.length;i++)(e[i]===null||Si(e[i]))&&s.push(i);s.length&&Di(e,s,n)}measureInitialState(){const{element:e,unresolvedKeyframes:n,name:s}=this;if(!e||!e.current)return;s==="height"&&(this.suspendedScrollY=window.pageYOffset),this.measuredOrigin=U[s](e.measureViewportBox(),window.getComputedStyle(e.current)),n[0]=this.measuredOrigin;const i=n[n.length-1];i!==void 0&&e.getValue(s,i).jump(i,!1)}measureEndState(){const{element:e,name:n,unresolvedKeyframes:s}=this;if(!e||!e.current)return;const i=e.getValue(n);i&&i.jump(this.measuredOrigin,!1);const r=s.length-1,o=s[r];s[r]=U[n](e.measureViewportBox(),window.getComputedStyle(e.current)),o!==null&&this.finalKeyframe===void 0&&(this.finalKeyframe=o),this.removedTransforms?.length&&this.removedTransforms.forEach(([a,u])=>{e.getValue(a).set(u)}),this.resolveNoneKeyframes()}}function Oi(t,e,n){if(t instanceof EventTarget)return[t];if(typeof t=="string"){let s=document;const i=n?.[t]??s.querySelectorAll(t);return i?Array.from(i):[]}return Array.from(t)}const mt=30,Ei=t=>!isNaN(parseFloat(t));class Ri{constructor(e,n={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=s=>{const i=I.now();if(this.updatedAt!==i&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(s),this.current!==this.prev&&(this.events.change?.notify(this.current),this.dependents))for(const r of this.dependents)r.dirty()},this.hasAnimated=!1,this.setCurrent(e),this.owner=n.owner}setCurrent(e){this.current=e,this.updatedAt=I.now(),this.canTrackVelocity===null&&e!==void 0&&(this.canTrackVelocity=Ei(this.current))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on("change",e)}on(e,n){this.events[e]||(this.events[e]=new kt);const s=this.events[e].add(n);return e==="change"?()=>{s(),E.read(()=>{this.events.change.getSize()||this.stop()})}:s}clearListeners(){for(const e in this.events)this.events[e].clear()}attach(e,n){this.passiveEffect=e,this.stopPassiveEffect=n}set(e){this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e)}setWithVelocity(e,n,s){this.set(n),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-s}jump(e,n=!0){this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,n&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){this.events.change?.notify(this.current)}addDependent(e){this.dependents||(this.dependents=new Set),this.dependents.add(e)}removeDependent(e){this.dependents&&this.dependents.delete(e)}get(){return this.current}getPrevious(){return this.prev}getVelocity(){const e=I.now();if(!this.canTrackVelocity||this.prevFrameValue===void 0||e-this.updatedAt>mt)return 0;const n=Math.min(this.updatedAt-this.prevUpdatedAt,mt);return Bt(parseFloat(this.current)-parseFloat(this.prevFrameValue),n)}start(e){return this.stop(),new Promise(n=>{this.hasAnimated=!0,this.animation=e(n),this.events.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function le(t,e){return new Ri(t,e)}const{schedule:Ki}=qt(queueMicrotask,!1),Ni={y:!1};function ki(){return Ni.y}function vn(t,e){const n=Oi(t),s=new AbortController,i={passive:!0,...e,signal:s.signal};return[n,i,()=>s.abort()]}function gt(t){return!(t.pointerType==="touch"||ki())}function Bi(t,e,n={}){const[s,i,r]=vn(t,n),o=a=>{if(!gt(a))return;const{target:u}=a,c=e(u,a);if(typeof c!="function"||!u)return;const l=h=>{gt(h)&&(c(h),u.removeEventListener("pointerleave",l))};u.addEventListener("pointerleave",l,i)};return s.forEach(a=>{a.addEventListener("pointerenter",o,i)}),r}const Tn=(t,e)=>e?t===e?!0:Tn(t,e.parentElement):!1,Li=t=>t.pointerType==="mouse"?typeof t.button!="number"||t.button<=0:t.isPrimary!==!1,_i=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","A"]);function Ui(t){return _i.has(t.tagName)||t.tabIndex!==-1}const ie=new WeakSet;function yt(t){return e=>{e.key==="Enter"&&t(e)}}function ye(t,e){t.dispatchEvent(new PointerEvent("pointer"+e,{isPrimary:!0,bubbles:!0}))}const Gi=(t,e)=>{const n=t.currentTarget;if(!n)return;const s=yt(()=>{if(ie.has(n))return;ye(n,"down");const i=yt(()=>{ye(n,"up")}),r=()=>ye(n,"cancel");n.addEventListener("keyup",i,e),n.addEventListener("blur",r,e)});n.addEventListener("keydown",s,e),n.addEventListener("blur",()=>n.removeEventListener("keydown",s),e)};function bt(t){return Li(t)&&!0}function ji(t,e,n={}){const[s,i,r]=vn(t,n),o=a=>{const u=a.currentTarget;if(!bt(a))return;ie.add(u);const c=e(u,a),l=(d,v)=>{window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",f),ie.has(u)&&ie.delete(u),bt(d)&&typeof c=="function"&&c(d,{success:v})},h=d=>{l(d,u===window||u===document||n.useGlobalTarget||Tn(u,d.target))},f=d=>{l(d,!1)};window.addEventListener("pointerup",h,i),window.addEventListener("pointercancel",f,i)};return s.forEach(a=>{(n.useGlobalTarget?window:a).addEventListener("pointerdown",o,i),kn(a)&&(a.addEventListener("focus",c=>Gi(c,i)),!Ui(a)&&!a.hasAttribute("tabindex")&&(a.tabIndex=0))}),r}const Wi=[...gn,x,Y],$i=t=>Wi.find(mn(t));function Hi({top:t,left:e,right:n,bottom:s}){return{x:{min:e,max:n},y:{min:t,max:s}}}function zi(t,e){if(!e)return t;const n=e({x:t.left,y:t.top}),s=e({x:t.right,y:t.bottom});return{top:n.y,left:n.x,bottom:s.y,right:s.x}}function qi(t,e){return Hi(zi(t.getBoundingClientRect(),e))}const vt=()=>({min:0,max:0}),Vn=()=>({x:vt(),y:vt()}),Re={current:null},An={current:!1};function Yi(){if(An.current=!0,!!Bn)if(window.matchMedia){const t=window.matchMedia("(prefers-reduced-motion)"),e=()=>Re.current=t.matches;t.addEventListener("change",e),e()}else Re.current=!1}const Xi=new WeakMap;function Zi(t,e,n){for(const s in e){const i=e[s],r=n[s];if(N(i))t.addValue(s,i);else if(N(r))t.addValue(s,le(i,{owner:t}));else if(r!==i)if(t.hasValue(s)){const o=t.getValue(s);o.liveStyle===!0?o.jump(i):o.hasAnimated||o.set(i)}else{const o=t.getStaticValue(s);t.addValue(s,le(o!==void 0?o:i,{owner:t}))}}for(const s in n)e[s]===void 0&&t.removeValue(s);return e}const Tt=["AnimationStart","AnimationComplete","Update","BeforeLayoutMeasure","LayoutMeasure","LayoutAnimationStart","LayoutAnimationComplete"];class Ji{scrapeMotionValuesFromProps(e,n,s){return{}}constructor({parent:e,props:n,presenceContext:s,reducedMotionConfig:i,blockInitialAnimation:r,visualState:o},a={}){this.current=null,this.children=new Set,this.isVariantNode=!1,this.isControllingVariants=!1,this.shouldReduceMotion=null,this.values=new Map,this.KeyframeResolver=Ze,this.features={},this.valueSubscriptions=new Map,this.prevMotionValues={},this.events={},this.propEventSubscriptions={},this.notifyUpdate=()=>this.notify("Update",this.latestValues),this.render=()=>{this.current&&(this.triggerBuild(),this.renderInstance(this.current,this.renderState,this.props.style,this.projection))},this.renderScheduledAt=0,this.scheduleRender=()=>{const f=I.now();this.renderScheduledAt<f&&(this.renderScheduledAt=f,E.render(this.render,!1,!0))};const{latestValues:u,renderState:c}=o;this.latestValues=u,this.baseTarget={...u},this.initialValues=n.initial?{...u}:{},this.renderState=c,this.parent=e,this.props=n,this.presenceContext=s,this.depth=e?e.depth+1:0,this.reducedMotionConfig=i,this.options=a,this.blockInitialAnimation=!!r,this.isControllingVariants=Ln(n),this.isVariantNode=_n(n),this.isVariantNode&&(this.variantChildren=new Set),this.manuallyAnimateOnMount=!!(e&&e.current);const{willChange:l,...h}=this.scrapeMotionValuesFromProps(n,{},this);for(const f in h){const d=h[f];u[f]!==void 0&&N(d)&&d.set(u[f])}}mount(e){this.current=e,Xi.set(e,this),this.projection&&!this.projection.instance&&this.projection.mount(e),this.parent&&this.isVariantNode&&!this.isControllingVariants&&(this.removeFromVariantTree=this.parent.addVariantChild(this)),this.values.forEach((n,s)=>this.bindToMotionValue(s,n)),An.current||Yi(),this.shouldReduceMotion=this.reducedMotionConfig==="never"?!1:this.reducedMotionConfig==="always"?!0:Re.current,this.parent?.addChild(this),this.update(this.props,this.presenceContext)}unmount(){this.projection&&this.projection.unmount(),Te(this.notifyUpdate),Te(this.render),this.valueSubscriptions.forEach(e=>e()),this.valueSubscriptions.clear(),this.removeFromVariantTree&&this.removeFromVariantTree(),this.parent?.removeChild(this);for(const e in this.events)this.events[e].clear();for(const e in this.features){const n=this.features[e];n&&(n.unmount(),n.isMounted=!1)}this.current=null}addChild(e){this.children.add(e),this.enteringChildren??(this.enteringChildren=new Set),this.enteringChildren.add(e)}removeChild(e){this.children.delete(e),this.enteringChildren&&this.enteringChildren.delete(e)}bindToMotionValue(e,n){this.valueSubscriptions.has(e)&&this.valueSubscriptions.get(e)();const s=ce.has(e);s&&this.onBindTransform&&this.onBindTransform();const i=n.on("change",o=>{this.latestValues[e]=o,this.props.onUpdate&&E.preRender(this.notifyUpdate),s&&this.projection&&(this.projection.isTransformDirty=!0),this.scheduleRender()});let r;window.MotionCheckAppearSync&&(r=window.MotionCheckAppearSync(this,e,n)),this.valueSubscriptions.set(e,()=>{i(),r&&r(),n.owner&&n.stop()})}sortNodePosition(e){return!this.current||!this.sortInstanceNodePosition||this.type!==e.type?0:this.sortInstanceNodePosition(this.current,e.current)}updateFeatures(){let e="animation";for(e in tt){const n=tt[e];if(!n)continue;const{isEnabled:s,Feature:i}=n;if(!this.features[e]&&i&&s(this.props)&&(this.features[e]=new i(this)),this.features[e]){const r=this.features[e];r.isMounted?r.update():(r.mount(),r.isMounted=!0)}}}triggerBuild(){this.build(this.renderState,this.latestValues,this.props)}measureViewportBox(){return this.current?this.measureInstanceViewportBox(this.current,this.props):Vn()}getStaticValue(e){return this.latestValues[e]}setStaticValue(e,n){this.latestValues[e]=n}update(e,n){(e.transformTemplate||this.props.transformTemplate)&&this.scheduleRender(),this.prevProps=this.props,this.props=e,this.prevPresenceContext=this.presenceContext,this.presenceContext=n;for(let s=0;s<Tt.length;s++){const i=Tt[s];this.propEventSubscriptions[i]&&(this.propEventSubscriptions[i](),delete this.propEventSubscriptions[i]);const r="on"+i,o=e[r];o&&(this.propEventSubscriptions[i]=this.on(i,o))}this.prevMotionValues=Zi(this,this.scrapeMotionValuesFromProps(e,this.prevProps,this),this.prevMotionValues),this.handleChildMotionValue&&this.handleChildMotionValue()}getProps(){return this.props}getVariant(e){return this.props.variants?this.props.variants[e]:void 0}getDefaultTransition(){return this.props.transition}getTransformPagePoint(){return this.props.transformPagePoint}getClosestVariantNode(){return this.isVariantNode?this:this.parent?this.parent.getClosestVariantNode():void 0}addVariantChild(e){const n=this.getClosestVariantNode();if(n)return n.variantChildren&&n.variantChildren.add(e),()=>n.variantChildren.delete(e)}addValue(e,n){const s=this.values.get(e);n!==s&&(s&&this.removeValue(e),this.bindToMotionValue(e,n),this.values.set(e,n),this.latestValues[e]=n.get())}removeValue(e){this.values.delete(e);const n=this.valueSubscriptions.get(e);n&&(n(),this.valueSubscriptions.delete(e)),delete this.latestValues[e],this.removeValueFromRenderState(e,this.renderState)}hasValue(e){return this.values.has(e)}getValue(e,n){if(this.props.values&&this.props.values[e])return this.props.values[e];let s=this.values.get(e);return s===void 0&&n!==void 0&&(s=le(n===null?void 0:n,{owner:this}),this.addValue(e,s)),s}readValue(e,n){let s=this.latestValues[e]!==void 0||!this.current?this.latestValues[e]:this.getBaseTargetFromProps(this.props,e)??this.readValueFromInstance(this.current,e,this.options);return s!=null&&(typeof s=="string"&&(Rt(s)||Kt(s))?s=parseFloat(s):!$i(s)&&Y.test(n)&&(s=bn(e,n)),this.setBaseTarget(e,N(s)?s.get():s)),N(s)?s.get():s}setBaseTarget(e,n){this.baseTarget[e]=n}getBaseTarget(e){const{initial:n}=this.props;let s;if(typeof n=="string"||typeof n=="object"){const r=Pt(this.props,n,this.presenceContext?.custom);r&&(s=r[e])}if(n&&s!==void 0)return s;const i=this.getBaseTargetFromProps(this.props,e);return i!==void 0&&!N(i)?i:this.initialValues[e]!==void 0&&s===void 0?void 0:this.baseTarget[e]}on(e,n){return this.events[e]||(this.events[e]=new kt),this.events[e].add(n)}notify(e,...n){this.events[e]&&this.events[e].notify(...n)}scheduleRenderMicrotask(){Ki.render(this.render)}}class wn extends Ji{constructor(){super(...arguments),this.KeyframeResolver=Ii}sortInstanceNodePosition(e,n){return e.compareDocumentPosition(n)&2?1:-1}getBaseTargetFromProps(e,n){return e.style?e.style[n]:void 0}removeValueFromRenderState(e,{vars:n,style:s}){delete n[e],delete s[e]}handleChildMotionValue(){this.childSubscription&&(this.childSubscription(),delete this.childSubscription);const{children:e}=this.props;N(e)&&(this.childSubscription=e.on("change",n=>{this.current&&(this.current.textContent=`${n}`)}))}}function Sn(t,{style:e,vars:n},s,i){const r=t.style;let o;for(o in e)r[o]=e[o];i?.applyProjectionStyles(r,s);for(o in n)r.setProperty(o,n[o])}function Qi(t){return window.getComputedStyle(t)}class er extends wn{constructor(){super(...arguments),this.type="html",this.renderInstance=Sn}readValueFromInstance(e,n){if(ce.has(n))return this.projection?.isProjecting?Ce(n):Zs(e,n);{const s=Qi(e),i=(Un(n)?s.getPropertyValue(n):s[n])||0;return typeof i=="string"?i.trim():i}}measureInstanceViewportBox(e,{transformPagePoint:n}){return qi(e,n)}build(e,n,s){Gn(e,n,s.transformTemplate)}scrapeMotionValuesFromProps(e,n,s){return jn(e,n,s)}}const xn=new Set(["baseFrequency","diffuseConstant","kernelMatrix","kernelUnitLength","keySplines","keyTimes","limitingConeAngle","markerHeight","markerWidth","numOctaves","targetX","targetY","surfaceScale","specularConstant","specularExponent","stdDeviation","tableValues","viewBox","gradientTransform","pathLength","startOffset","textLength","lengthAdjust"]);function tr(t,e,n,s){Sn(t,e,void 0,s);for(const i in e.attrs)t.setAttribute(xn.has(i)?i:Ft(i),e.attrs[i])}class nr extends wn{constructor(){super(...arguments),this.type="svg",this.isSVGTag=!1,this.measureInstanceViewportBox=Vn}getBaseTargetFromProps(e,n){return e[n]}readValueFromInstance(e,n){if(ce.has(n)){const s=yn(n);return s&&s.default||0}return n=xn.has(n)?n:Ft(n),e.getAttribute(n)}scrapeMotionValuesFromProps(e,n,s){return Wn(e,n,s)}build(e,n,s){$n(e,n,this.isSVGTag,s.transformTemplate,s.style)}renderInstance(e,n,s,i){tr(e,n,s,i)}mount(e){this.isSVGTag=Hn(e.tagName),super.mount(e)}}const sr=(t,e)=>zn(t)?new nr(e):new er(e,{allowProjection:t!==qn.Fragment});function H(t,e,n){const s=t.getProps();return Pt(s,e,n!==void 0?n:s.custom,t)}const Ke=t=>Array.isArray(t);function ir(t,e,n){t.hasValue(e)?t.getValue(e).set(n):t.addValue(e,le(n))}function rr(t){return Ke(t)?t[t.length-1]||0:t}function or(t,e){const n=H(t,e);let{transitionEnd:s={},transition:i={},...r}=n||{};r={...r,...s};for(const o in r){const a=rr(r[o]);ir(t,o,a)}}function ar(t){return!!(N(t)&&t.add)}function ur(t,e){const n=t.getValue("willChange");if(ar(n))return n.add(e);if(!n&&K.WillChange){const s=new K.WillChange("auto");t.addValue("willChange",s),s.add(e)}}function lr(t){return t.props[Yn]}const cr=t=>t!==null;function hr(t,{repeat:e,repeatType:n="loop"},s){const i=t.filter(cr),r=e&&n!=="loop"&&e%2===1?0:i.length-1;return i[r]}const fr={type:"spring",stiffness:500,damping:25,restSpeed:10},dr=t=>({type:"spring",stiffness:550,damping:t===0?2*Math.sqrt(550):30,restSpeed:10}),pr={type:"keyframes",duration:.8},mr={type:"keyframes",ease:[.25,.1,.35,1],duration:.3},gr=(t,{keyframes:e})=>e.length>2?pr:ce.has(t)?t.startsWith("scale")?dr(e[1]):fr:mr;function yr({when:t,delay:e,delayChildren:n,staggerChildren:s,staggerDirection:i,repeat:r,repeatType:o,repeatDelay:a,from:u,elapsed:c,...l}){return!!Object.keys(l).length}const br=(t,e,n,s={},i,r)=>o=>{const a=dn(s,t)||{},u=a.delay||s.delay||0;let{elapsed:c=0}=s;c=c-R(u);const l={keyframes:Array.isArray(n)?n:[null,n],ease:"easeOut",velocity:e.getVelocity(),...a,delay:-c,onUpdate:f=>{e.set(f),a.onUpdate&&a.onUpdate(f)},onComplete:()=>{o(),a.onComplete&&a.onComplete()},name:t,motionValue:e,element:r?void 0:i};yr(a)||Object.assign(l,gr(t,l)),l.duration&&(l.duration=R(l.duration)),l.repeatDelay&&(l.repeatDelay=R(l.repeatDelay)),l.from!==void 0&&(l.keyframes[0]=l.from);let h=!1;if((l.type===!1||l.duration===0&&!l.repeatDelay)&&(Oe(l),l.delay===0&&(h=!0)),(K.instantAnimations||K.skipAnimations)&&(h=!0,Oe(l),l.delay=0),l.allowFlatten=!a.type&&!a.ease,h&&!r&&e.get()!==void 0){const f=hr(l.keyframes,a);if(f!==void 0){E.update(()=>{l.onUpdate(f),l.onComplete()});return}}return a.isSync?new Xe(l):new Ti(l)};function vr({protectedKeys:t,needsAnimating:e},n){const s=t.hasOwnProperty(n)&&e[n]!==!0;return e[n]=!1,s}function Mn(t,e,{delay:n=0,transitionOverride:s,type:i}={}){let{transition:r=t.getDefaultTransition(),transitionEnd:o,...a}=e;s&&(r=s);const u=[],c=i&&t.animationState&&t.animationState.getState()[i];for(const l in a){const h=t.getValue(l,t.latestValues[l]??null),f=a[l];if(f===void 0||c&&vr(c,l))continue;const d={delay:n,...dn(r||{},l)},v=h.get();if(v!==void 0&&!h.isAnimating&&!Array.isArray(f)&&f===v&&!d.velocity)continue;let T=!1;if(window.MotionHandoffAnimation){const p=lr(t);if(p){const V=window.MotionHandoffAnimation(p,l,E);V!==null&&(d.startTime=V,T=!0)}}ur(t,l),h.start(br(l,h,f,t.shouldReduceMotion&&pn.has(l)?{type:!1}:d,t,T));const b=h.animation;b&&u.push(b)}return o&&Promise.all(u).then(()=>{E.update(()=>{o&&or(t,o)})}),u}function Cn(t,e,n,s=0,i=1){const r=Array.from(t).sort((c,l)=>c.sortNodePosition(l)).indexOf(e),o=t.size,a=(o-1)*s;return typeof n=="function"?n(r,o):i===1?r*s:a-r*s}function Ne(t,e,n={}){const s=H(t,e,n.type==="exit"?t.presenceContext?.custom:void 0);let{transition:i=t.getDefaultTransition()||{}}=s||{};n.transitionOverride&&(i=n.transitionOverride);const r=s?()=>Promise.all(Mn(t,s,n)):()=>Promise.resolve(),o=t.variantChildren&&t.variantChildren.size?(u=0)=>{const{delayChildren:c=0,staggerChildren:l,staggerDirection:h}=i;return Tr(t,e,u,c,l,h,n)}:()=>Promise.resolve(),{when:a}=i;if(a){const[u,c]=a==="beforeChildren"?[r,o]:[o,r];return u().then(()=>c())}else return Promise.all([r(),o(n.delay)])}function Tr(t,e,n=0,s=0,i=0,r=1,o){const a=[];for(const u of t.variantChildren)u.notify("AnimationStart",e),a.push(Ne(u,e,{...o,delay:n+(typeof s=="function"?0:s)+Cn(t.variantChildren,u,s,i,r)}).then(()=>u.notify("AnimationComplete",e)));return Promise.all(a)}function Vr(t,e,n={}){t.notify("AnimationStart",e);let s;if(Array.isArray(e)){const i=e.map(r=>Ne(t,r,n));s=Promise.all(i)}else if(typeof e=="string")s=Ne(t,e,n);else{const i=typeof e=="function"?H(t,e,n.custom):e;s=Promise.all(Mn(t,i,n))}return s.then(()=>{t.notify("AnimationComplete",e)})}function Pn(t,e){if(!Array.isArray(e))return!1;const n=e.length;if(n!==t.length)return!1;for(let s=0;s<n;s++)if(e[s]!==t[s])return!1;return!0}const Ar=It.length;function Fn(t){if(!t)return;if(!t.isControllingVariants){const n=t.parent?Fn(t.parent)||{}:{};return t.props.initial!==void 0&&(n.initial=t.props.initial),n}const e={};for(let n=0;n<Ar;n++){const s=It[n],i=t.props[s];(Dt(i)||i===!1)&&(e[s]=i)}return e}const wr=[...Et].reverse(),Sr=Et.length;function xr(t){return e=>Promise.all(e.map(({animation:n,options:s})=>Vr(t,n,s)))}function Mr(t){let e=xr(t),n=Vt(),s=!0;const i=u=>(c,l)=>{const h=H(t,l,u==="exit"?t.presenceContext?.custom:void 0);if(h){const{transition:f,transitionEnd:d,...v}=h;c={...c,...v,...d}}return c};function r(u){e=u(t)}function o(u){const{props:c}=t,l=Fn(t.parent)||{},h=[],f=new Set;let d={},v=1/0;for(let b=0;b<Sr;b++){const p=wr[b],V=n[p],g=c[p]!==void 0?c[p]:l[p],w=Dt(g),m=p===u?V.isActive:null;m===!1&&(v=b);let A=g===l[p]&&g!==c[p]&&w;if(A&&s&&t.manuallyAnimateOnMount&&(A=!1),V.protectedKeys={...d},!V.isActive&&m===null||!g&&!V.prevProp||Ot(g)||typeof g=="boolean")continue;const M=Cr(V.prevProp,g);let y=M||p===u&&V.isActive&&!A&&w||b>v&&w,P=!1;const F=Array.isArray(g)?g:[g];let j=F.reduce(i(p),{});m===!1&&(j={});const{prevResolvedValues:Je={}}=V,In={...Je,...j},Qe=C=>{y=!0,f.has(C)&&(P=!0,f.delete(C)),V.needsAnimating[C]=!0;const D=t.getValue(C);D&&(D.liveStyle=!1)};for(const C in In){const D=j[C],k=Je[C];if(d.hasOwnProperty(C))continue;let W=!1;Ke(D)&&Ke(k)?W=!Pn(D,k):W=D!==k,W?D!=null?Qe(C):f.add(C):D!==void 0&&f.has(C)?Qe(C):V.protectedKeys[C]=!0}V.prevProp=g,V.prevResolvedValues=j,V.isActive&&(d={...d,...j}),s&&t.blockInitialAnimation&&(y=!1);const et=A&&M;y&&(!et||P)&&h.push(...F.map(C=>{const D={type:p};if(typeof C=="string"&&s&&!et&&t.manuallyAnimateOnMount&&t.parent){const{parent:k}=t,W=H(k,C);if(k.enteringChildren&&W){const{delayChildren:On}=W.transition||{};D.delay=Cn(k.enteringChildren,t,On)}}return{animation:C,options:D}}))}if(f.size){const b={};if(typeof c.initial!="boolean"){const p=H(t,Array.isArray(c.initial)?c.initial[0]:c.initial);p&&p.transition&&(b.transition=p.transition)}f.forEach(p=>{const V=t.getBaseTarget(p),g=t.getValue(p);g&&(g.liveStyle=!0),b[p]=V??null}),h.push({animation:b})}let T=!!h.length;return s&&(c.initial===!1||c.initial===c.animate)&&!t.manuallyAnimateOnMount&&(T=!1),s=!1,T?e(h):Promise.resolve()}function a(u,c){if(n[u].isActive===c)return Promise.resolve();t.variantChildren?.forEach(h=>h.animationState?.setActive(u,c)),n[u].isActive=c;const l=o(u);for(const h in n)n[h].protectedKeys={};return l}return{animateChanges:o,setActive:a,setAnimateFunction:r,getState:()=>n,reset:()=>{n=Vt()}}}function Cr(t,e){return typeof e=="string"?e!==t:Array.isArray(e)?!Pn(e,t):!1}function B(t=!1){return{isActive:t,protectedKeys:{},needsAnimating:{},prevResolvedValues:{}}}function Vt(){return{animate:B(!0),whileInView:B(),whileHover:B(),whileTap:B(),whileDrag:B(),whileFocus:B(),exit:B()}}class X{constructor(e){this.isMounted=!1,this.node=e}update(){}}class Pr extends X{constructor(e){super(e),e.animationState||(e.animationState=Mr(e))}updateAnimationControlsSubscription(){const{animate:e}=this.node.getProps();Ot(e)&&(this.unmountControls=e.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:e}=this.node.getProps(),{animate:n}=this.node.prevProps||{};e!==n&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let Fr=0;class Dr extends X{constructor(){super(...arguments),this.id=Fr++}update(){if(!this.node.presenceContext)return;const{isPresent:e,onExitComplete:n}=this.node.presenceContext,{isPresent:s}=this.node.prevPresenceContext||{};if(!this.node.animationState||e===s)return;const i=this.node.animationState.setActive("exit",!e);n&&!e&&i.then(()=>{n(this.id)})}mount(){const{register:e,onExitComplete:n}=this.node.presenceContext||{};n&&n(this.id),e&&(this.unmount=e(this.id))}unmount(){}}const Ir={animation:{Feature:Pr},exit:{Feature:Dr}};function At(t,e,n,s={passive:!0}){return t.addEventListener(e,n,s),()=>t.removeEventListener(e,n)}function Dn(t){return{point:{x:t.pageX,y:t.pageY}}}function wt(t,e,n){const{props:s}=t;t.animationState&&s.whileHover&&t.animationState.setActive("whileHover",n==="Start");const i="onHover"+n,r=s[i];r&&E.postRender(()=>r(e,Dn(e)))}class Or extends X{mount(){const{current:e}=this.node;e&&(this.unmount=Bi(e,(n,s)=>(wt(this.node,s,"Start"),i=>wt(this.node,i,"End"))))}unmount(){}}class Er extends X{constructor(){super(...arguments),this.isActive=!1}onFocus(){let e=!1;try{e=this.node.current.matches(":focus-visible")}catch{e=!0}!e||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=he(At(this.node.current,"focus",()=>this.onFocus()),At(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function St(t,e,n){const{props:s}=t;if(t.current instanceof HTMLButtonElement&&t.current.disabled)return;t.animationState&&s.whileTap&&t.animationState.setActive("whileTap",n==="Start");const i="onTap"+(n==="End"?"":n),r=s[i];r&&E.postRender(()=>r(e,Dn(e)))}class Rr extends X{mount(){const{current:e}=this.node;e&&(this.unmount=ji(e,(n,s)=>(St(this.node,s,"Start"),(i,{success:r})=>St(this.node,i,r?"End":"Cancel")),{useGlobalTarget:this.node.props.globalTapTarget}))}unmount(){}}const ke=new WeakMap,be=new WeakMap,Kr=t=>{const e=ke.get(t.target);e&&e(t)},Nr=t=>{t.forEach(Kr)};function kr({root:t,...e}){const n=t||document;be.has(n)||be.set(n,{});const s=be.get(n),i=JSON.stringify(e);return s[i]||(s[i]=new IntersectionObserver(Nr,{root:t,...e})),s[i]}function Br(t,e,n){const s=kr(e);return ke.set(t,n),s.observe(t),()=>{ke.delete(t),s.unobserve(t)}}const Lr={some:0,all:1};class _r extends X{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:e={}}=this.node.getProps(),{root:n,margin:s,amount:i="some",once:r}=e,o={root:n?n.current:void 0,rootMargin:s,threshold:typeof i=="number"?i:Lr[i]},a=u=>{const{isIntersecting:c}=u;if(this.isInView===c||(this.isInView=c,r&&!c&&this.hasEnteredView))return;c&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",c);const{onViewportEnter:l,onViewportLeave:h}=this.node.getProps(),f=c?l:h;f&&f(u)};return Br(this.node.current,o,a)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:e,prevProps:n}=this.node;["amount","margin","root"].some(Ur(e,n))&&this.startObserver()}unmount(){}}function Ur({viewport:t={}},{viewport:e={}}={}){return n=>t[n]!==e[n]}const Gr={inView:{Feature:_r},tap:{Feature:Rr},focus:{Feature:Er},hover:{Feature:Or}},jr={renderer:sr,...Ir,...Gr};var Hr=jr;export{Hr as default};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="icon" href="/favicon.ico" />
|
|
7
|
+
<title>Z-Router Example</title>
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BnRxLDj4.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-C0uITd16.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="app"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use strict";var at=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Yt=Object.prototype.hasOwnProperty;var zt=(t,o)=>{for(var n in o)at(t,n,{get:o[n],enumerable:!0})},_t=(t,o,n,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of qt(o))!Yt.call(t,e)&&e!==n&&at(t,e,{get:()=>o[e],enumerable:!(s=Ht(o,e))||s.enumerable});return t};var Kt=t=>_t(at({},"__esModule",{value:!0}),t);var re={};zt(re,{DefaultTransitionDuration:()=>Zt,Link:()=>Vt,LocationContext:()=>X,LocationProvider:()=>j,Outlet:()=>ut,RootRouteContext:()=>_,RouterContext:()=>I,RouterProvider:()=>te,Stack:()=>ne,buildPathnameFromMatches:()=>Gt,buildUrlFromLocation:()=>A,createRouterOptions:()=>Qt,matchPattern:()=>Wt,matchRoute:()=>dt,parseLocation:()=>lt,parseRoute:()=>ft,redirect:()=>Jt,resolveRelativeUrl:()=>Rt,useLocation:()=>q,useRootRoute:()=>K,useRoute:()=>ct,useRouteMatch:()=>H,useRouter:()=>w});module.exports=Kt(re);var xt=require("react");var gt=require("react"),I=(0,gt.createContext)(null);var w=()=>{let t=(0,xt.useContext)(I);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var yt=require("react"),vt=require("react/jsx-runtime"),Vt=(0,yt.memo)(({to:t,replace:o,transitionType:n,duration:s,onFinish:e,...u})=>{let a=w();return(0,vt.jsx)("a",{...u,href:t,onClick:i=>{i.preventDefault(),a.navigate({to:t,replace:o,transitionType:n,duration:s,onFinish:e})}})});var Tt=require("react"),X=(0,Tt.createContext)(null);var k=require("react"),Pt=require("react/jsx-runtime"),j=(0,k.memo)(({location:t,...o})=>{let n=w(),s=(0,k.useMemo)(()=>t.state,[t]),e=(0,k.useCallback)((i,r)=>{n.setLocationState(t.index,T=>({...T,[i]:r}))},[n,t]),u=(0,k.useCallback)(i=>{n.setLocationState(t.index,r=>(delete r[i],r))},[n,t]),a=(0,k.useCallback)((i,r)=>{n.setLocationSearch(t.index,{...t.search,[i]:r})},[n,t]);return(0,Pt.jsx)(X.Provider,{value:{...t,canGoBack:!n.isTransitioning&&t.index>0,canGoForward:!n.isTransitioning&&t.index+1<n.history.length,state:s,setState:e,deleteState:u,setSearch:a},...o})},(t,o)=>t.location===o.location);var Lt=require("react"),Q=(0,Lt.createContext)(0);var Ct=require("react"),St=()=>(0,Ct.useContext)(Q);var wt=require("react"),tt=(0,wt.createContext)(null);var bt=require("react"),H=()=>{let t=(0,bt.useContext)(tt);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var kt=require("react/jsx-runtime"),Ot=({depth:t,...o})=>(0,kt.jsx)(Q.Provider,{value:t,...o});var Mt=require("react");var q=()=>{let t=(0,Mt.useContext)(X);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var Nt=require("react"),Y=(0,Nt.createContext)(null);var At=require("react"),ct=()=>{let t=(0,At.useContext)(Y);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var Ft=require("react");var z=require("react/jsx-runtime"),et=({depth:t=0})=>{let o=w(),n=q(),s=H(),e=ct(),u=`_Z.${e.id}.pending`,a=!!e.beforeLoad&&e.getState(u)!==!1;if((0,Ft.useEffect)(()=>{e&&e.beforeLoad&&e.getState(u)===void 0&&(e.setState(u,!0),e.beforeLoad?.({location:n}).then(()=>e.setState(u,!1)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),o.navigate({...r,onFinish:()=>{e.setState(u,!1)}})):e.setState(u,!1)}))},[e]),!e)return null;if(a){let r=e.pendingComponent;return(0,z.jsx)(r,{})}if(t>=s.matches.length){let r=e.notFoundComponent;return(0,z.jsx)(r,{})}let i=e.component;return i?(0,z.jsx)(i,{}):(0,z.jsx)(ut,{})};var Dt=require("react");var Et=require("react"),_=(0,Et.createContext)(null);var K=()=>{let t=(0,Dt.useContext)(_);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};var pt=require("react"),mt=require("react/jsx-runtime"),ot=({route:t,...o})=>{if(!t)return(0,mt.jsx)(Y.Provider,{value:null,...o});let{state:n,getRouteState:s,setRouteState:e}=K(),u=(0,pt.useCallback)(i=>s(t.id,i),[s,t.id]),a=(0,pt.useCallback)((i,r)=>{e(t.id,i,r)},[e,t.id]);return(0,mt.jsx)(Y.Provider,{value:{...t,state:n[t.id],getState:u,setState:a},...o})};var nt=require("react/jsx-runtime"),ut=()=>{let t=H(),o=St()+1;return(0,nt.jsx)(Ot,{depth:o,children:(0,nt.jsx)(ot,{route:t.matches.at(o),children:(0,nt.jsx)(et,{depth:o})})})};var x=require("react");var $t={defaultTransitionDuration:300};var Zt=300,Jt=t=>new Error("",{cause:t}),Wt=(t,o)=>{try{let n,s;if(o.startsWith("http://")||o.startsWith("https://")){let l=new URL(o);n=l.pathname,s=l.searchParams}else{let[l,v]=o.split("?");if(!l)return null;n=l,s=new URLSearchParams(v||"")}let e=n.replaceAll(/^\/|\/$/g,""),u=t.replaceAll(/^\/|\/$/g,""),a=e.split("/"),i=u.split("/");if(a.length!==i.length)return null;let r={};for(let l=0;l<i.length;l++){let v=i[l],b=a[l];if(v.startsWith(":")){let E=v.slice(1);r[E]=decodeURIComponent(b)}else if(v!==b)return null}let T=Object.fromEntries(s.entries());return{params:r,query:T}}catch{return null}},dt=(t,o)=>{let n=(s,{children:e})=>{if(e&&e.length>0){for(let a of e){let i=n([...s,a],a);if(i)return i}return null}let u=Wt(Gt(s),o);return u?{matches:s,...u}:null};return n([t],t)||{matches:[],params:{},query:{}}},Gt=t=>{let o=[];for(let n of t)n.pathname!==void 0&&o.push(n.pathname.replaceAll(/^\/|\/$/g,""));return"/"+o.join("/")},lt=({href:t,pathname:o,search:n})=>({index:0,href:t,state:{index:0},pathname:o,search:Object.fromEntries(new URLSearchParams(n))}),Qt=t=>({...$t,...t}),ft=t=>{let o=(n,s)=>{let e=n.name??(n.pathname?`${s}/${n.pathname.replaceAll(/^\/|\/$/g,"")}`:s);return{...n,id:e,children:n.children?.map(a=>o(a,e))}};return o(t,"")},jt=t=>t.length>0,Rt=(t,o)=>{let n=t.split("/").filter(jt),s=o.split("/").filter(jt);for(let e of s)e!=="."&&(e===".."?n.pop():n.push(e));return"/"+n.join("/")},A=t=>{let o=new URLSearchParams(t.search).toString();return o?`${t.pathname}?${o}`:t.pathname};var ht=require("react/jsx-runtime"),te=({options:t,...o})=>{let[n,s]=(0,x.useState)([lt(window.location)]),[e,u]=(0,x.useState)(0),a=(0,x.useMemo)(()=>n.at(e),[n,e]),[i,r]=(0,x.useState)(!1),[T,l]=(0,x.useState)(),[v,b]=(0,x.useState)(),[E,S]=(0,x.useState)(0),M=!i&&e>0,W=!i&&e+1<n.length;(0,x.useEffect)(()=>{window.history.replaceState(a.state,"",A(a))},[]),(0,x.useEffect)(()=>{let p=({state:m})=>{console.log("popstate event:",m),u(m?.index)};return addEventListener("popstate",p),()=>{removeEventListener("popstate",p)}},[e]);let G=(0,x.useCallback)(({to:p,replace:m})=>{if(!p)return a;let R=m?e:e+1,d=p.startsWith("/")?p:Rt(a.pathname,p),[g,f]=d.split("?"),h=new URLSearchParams(f??""),C={index:R};return{index:R,href:origin+g+(f?`?${h.toString()}`:""),search:Object.fromEntries(h.entries()),state:C,pathname:g}},[e,a]),L=(p,m,R=t.defaultTransitionDuration,d)=>{r(!0),b(m),S(R),l(p),setTimeout(()=>{r(!1),b(void 0),l(void 0),d?.()},R)},V=(0,x.useCallback)(({to:p,replace:m,transitionType:R,duration:d,onFinish:g})=>{if(i)return;let f=m?e:e+1,h=G({to:p,replace:m}),C=()=>{m?(s(D=>[...D.slice(0,f),h,...D.slice(f+1)]),window.history.replaceState(h.state,"",A(h))):(s(D=>[...D.slice(0,f),h]),u(f),window.history.pushState(h.state,"",A(h))),g?.()},J=R??t.defaultTransitionType?.(a,h)??"slide-left";J?L(h,J,d,C):C()},[e,n,i,t]),O=(0,x.useCallback)(({transitionType:p,duration:m,onFinish:R,depth:d}={})=>{if(!M)return;let g=d??1,f=n.at(e-g);if(!f)return;let h=()=>{window.history.go(-g),R?.()},C=p??t.defaultTransitionType?.(a,f)??"slide-right";C?L(f,C,m,h):h()},[e,n,i,t]),U=(0,x.useCallback)(({transitionType:p,duration:m,depth:R,onFinish:d}={})=>{if(!W)return;let g=R??1,f=n.at(e+g);if(!f)return;let h=()=>{window.history.go(g),d?.()},C=p??t.defaultTransitionType?.(a,f)??"slide-left";C?L(f,C,m,h):h()},[e,n,i,t]),B=(0,x.useCallback)((p,m)=>{s(R=>R.map(d=>{if(d.index!==p)return d;let g=typeof m=="function"?m(d.state):m,f={...d,state:g};return p===e&&window.history.replaceState(g,"",A(f)),f}))},[e]),Z=(0,x.useCallback)((p,m)=>{s(R=>R.map(d=>{if(d.index!==p)return d;let g={...d,search:{...d.search,...m}};return p===e&&window.history.replaceState(g.state,"",A(g)),g}))},[]);return(0,ht.jsx)(I.Provider,{value:{options:t,history:n,location:a,canGoBack:M,canGoForward:W,isTransitioning:i,transitioningToLocation:T,transitionType:v,transitionDuration:E,buildLocation:G,navigate:V,back:O,forward:U,setLocationState:B,setLocationSearch:Z},children:(0,ht.jsx)(j,{location:a,...o})})};var y=require("react");var it=require("react");var rt=require("react/jsx-runtime"),st=(0,it.memo)(()=>{let t=K(),o=q(),n=(0,it.useMemo)(()=>dt(t,o.pathname),[t,o.pathname]);return(0,rt.jsx)(tt.Provider,{value:n,children:(0,rt.jsx)(ot,{route:t,children:(0,rt.jsx)(et,{})})})});var F=require("react"),Bt=require("react/jsx-runtime"),Ut=({route:t,...o})=>{let n=(0,F.useMemo)(()=>ft(t),[t]),[s,e]=(0,F.useState)({}),u=(0,F.useCallback)((i,r)=>s[i]?.[r],[s]),a=(0,F.useCallback)((i,r,T)=>{e(l=>({...l,[i]:{...l[i],[r]:T}}))},[]);return(0,Bt.jsx)(_.Provider,{value:{...n,state:s,getRouteState:u,setRouteState:a},...o})};var P=require("react/jsx-runtime"),ee={position:"absolute",inset:0,zIndex:-1},oe=({allowSwipeBack:t=!0,allowSwipeForward:o=!0,style:n,...s})=>{let{history:e,location:u,canGoBack:a,canGoForward:i,isTransitioning:r,transitioningToLocation:T,transitionType:l,transitionDuration:v,back:b,forward:E}=w(),S=u.index,M=(0,y.useRef)(!1),W=(0,y.useRef)(0),G=(0,y.useRef)(0),[L,V]=(0,y.useState)(!1),[O,U]=(0,y.useState)(0),[B,Z]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[R,d]=(0,y.useState)(!1),[g,f]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{!r||!T||(f(!0),setTimeout(()=>{f(!1)},v))},[r,T,v]),S===void 0)return;let h=()=>{V(!1),U(0),Z(!1),m(!1),d(!1)},C=(0,y.useCallback)(N=>{r||!i&&!a||(M.current=!0,W.current=N.touches[0].clientX,G.current=N.touches[0].clientY)},[r,a,i]),J=(0,y.useCallback)(N=>{if(!M.current)return;let{clientX:It,clientY:Xt}=N.touches[0];if(!L&&Math.abs(Xt-G.current)>30){M.current=!1;return}let $=It-W.current;if(!(Math.abs($)<10)){if(L||V(!0),$>0&&S===0||$<0&&S+1===e.length){U(0);return}!B&&$<0&&o&&Z(!0),!p&&$>0&&t&&m(!0),U(Math.max(Math.min($,window.innerWidth),-window.innerWidth))}},[L,S,e.length,B,p,t,o]),D=(0,y.useCallback)(()=>{if(M.current=!1,!L)return;let N={onFinish:h};O>innerWidth*.3&&a&&t?b(N):O<-innerWidth*.3&&i&&o?E(N):(d(!0),setTimeout(h,v))},[b,E,L,O,a,i,v]);return(0,P.jsxs)("div",{style:{position:"relative",overflow:"hidden",...n},...s,children:[(r&&l==="slide-right"||L&&p)&&(0,P.jsx)("div",{style:ee,children:(0,P.jsx)(j,{location:r?T:e.at(S-1),children:(0,P.jsx)(st,{},S-1)})}),(0,P.jsx)("div",{style:{background:"white",position:"absolute",inset:0,transform:r&&l==="slide-right"?"translateX(100%)":L&&O>0&&!R?`translateX(${O}px)`:"translateX(0px)",transition:R||r&&l==="slide-right"?`transform ${v}ms ease-out`:""},onTouchStart:C,onTouchMove:J,onTouchEnd:D,children:(0,P.jsx)(st,{})},S),(r&&l==="slide-left"||L&&B)&&(0,P.jsx)("div",{style:{background:"white",position:"absolute",inset:0,zIndex:1,transform:`translateX(${g?"0px":r||R?"100%":`${innerWidth+O}px`})`,transition:`transform ${r||R?v:0}ms ease-in`},children:(0,P.jsx)(j,{location:r?T:e.at(S+1),children:(0,P.jsx)(st,{},T?.index)})})]})},ne=({route:t,...o})=>(0,P.jsx)(Ut,{route:t,children:(0,P.jsx)(oe,{...o})});0&&(module.exports={DefaultTransitionDuration,Link,LocationContext,LocationProvider,Outlet,RootRouteContext,RouterContext,RouterProvider,Stack,buildPathnameFromMatches,buildUrlFromLocation,createRouterOptions,matchPattern,matchRoute,parseLocation,parseRoute,redirect,resolveRelativeUrl,useLocation,useRootRoute,useRoute,useRouteMatch,useRouter});
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var q=react.createContext(null);var w=()=>{let t=react.useContext(q);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var de=react.memo(({to:t,replace:n,transitionType:o,duration:a,onFinish:e,...u})=>{let s=w();return jsxRuntime.jsx("a",{...u,href:t,onClick:i=>{i.preventDefault(),s.navigate({to:t,replace:n,transitionType:o,duration:a,onFinish:e});}})});var Y=react.createContext(null);var U=react.memo(({location:t,...n})=>{let o=w(),a=react.useMemo(()=>t.state,[t]),e=react.useCallback((i,r)=>{o.setLocationState(t.index,y=>({...y,[i]:r}));},[o,t]),u=react.useCallback(i=>{o.setLocationState(t.index,r=>(delete r[i],r));},[o,t]),s=react.useCallback((i,r)=>{o.setLocationSearch(t.index,{...t.search,[i]:r});},[o,t]);return jsxRuntime.jsx(Y.Provider,{value:{...t,canGoBack:!o.isTransitioning&&t.index>0,canGoForward:!o.isTransitioning&&t.index+1<o.history.length,state:a,setState:e,deleteState:u,setSearch:s},...n})},(t,n)=>t.location===n.location);var z=react.createContext(0);var ct=()=>react.useContext(z);var _=react.createContext(null);var K=()=>{let t=react.useContext(_);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var ut=({depth:t,...n})=>jsxRuntime.jsx(z.Provider,{value:t,...n});var V=()=>{let t=react.useContext(Y);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var B=react.createContext(null);var pt=()=>{let t=react.useContext(B);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var J=({depth:t=0})=>{let n=w(),o=V(),a=K(),e=pt(),u=`_Z.${e.id}.pending`,s=!!e.beforeLoad&&e.getState(u)!==false;if(react.useEffect(()=>{e&&e.beforeLoad&&e.getState(u)===void 0&&(e.setState(u,true),e.beforeLoad?.({location:o}).then(()=>e.setState(u,false)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),n.navigate({...r,onFinish:()=>{e.setState(u,false);}})):e.setState(u,false);}));},[e]),!e)return null;if(s){let r=e.pendingComponent;return jsxRuntime.jsx(r,{})}if(t>=a.matches.length){let r=e.notFoundComponent;return jsxRuntime.jsx(r,{})}let i=e.component;return i?jsxRuntime.jsx(i,{}):jsxRuntime.jsx(mt,{})};var Q=react.createContext(null);var tt=()=>{let t=react.useContext(Q);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};var et=({route:t,...n})=>{if(!t)return jsxRuntime.jsx(B.Provider,{value:null,...n});let{state:o,getRouteState:a,setRouteState:e}=tt(),u=react.useCallback(i=>a(t.id,i),[a,t.id]),s=react.useCallback((i,r)=>{e(t.id,i,r);},[e,t.id]);return jsxRuntime.jsx(B.Provider,{value:{...t,state:o[t.id],getState:u,setState:s},...n})};var mt=()=>{let t=K(),n=ct()+1;return jsxRuntime.jsx(ut,{depth:n,children:jsxRuntime.jsx(et,{route:t.matches.at(n),children:jsxRuntime.jsx(J,{depth:n})})})};var ft={defaultTransitionDuration:300};var Eo=300,Do=t=>new Error("",{cause:t}),qt=(t,n)=>{try{let o,a;if(n.startsWith("http://")||n.startsWith("https://")){let l=new URL(n);o=l.pathname,a=l.searchParams;}else {let[l,x]=n.split("?");if(!l)return null;o=l,a=new URLSearchParams(x||"");}let e=o.replaceAll(/^\/|\/$/g,""),u=t.replaceAll(/^\/|\/$/g,""),s=e.split("/"),i=u.split("/");if(s.length!==i.length)return null;let r={};for(let l=0;l<i.length;l++){let x=i[l],C=s[l];if(x.startsWith(":")){let k=x.slice(1);r[k]=decodeURIComponent(C);}else if(x!==C)return null}let y=Object.fromEntries(a.entries());return {params:r,query:y}}catch{return null}},ht=(t,n)=>{let o=(a,{children:e})=>{if(e&&e.length>0){for(let s of e){let i=o([...a,s],s);if(i)return i}return null}let u=qt(Yt(a),n);return u?{matches:a,...u}:null};return o([t],t)||{matches:[],params:{},query:{}}},Yt=t=>{let n=[];for(let o of t)o.pathname!==void 0&&n.push(o.pathname.replaceAll(/^\/|\/$/g,""));return "/"+n.join("/")},gt=({href:t,pathname:n,search:o})=>({index:0,href:t,state:{index:0},pathname:n,search:Object.fromEntries(new URLSearchParams(o))}),$o=t=>({...ft,...t}),xt=t=>{let n=(o,a)=>{let e=o.name??(o.pathname?`${a}/${o.pathname.replaceAll(/^\/|\/$/g,"")}`:a);return {...o,id:e,children:o.children?.map(s=>n(s,e))}};return n(t,"")},Rt=t=>t.length>0,yt=(t,n)=>{let o=t.split("/").filter(Rt),a=n.split("/").filter(Rt);for(let e of a)e!=="."&&(e===".."?o.pop():o.push(e));return "/"+o.join("/")},A=t=>{let n=new URLSearchParams(t.search).toString();return n?`${t.pathname}?${n}`:t.pathname};var Xo=({options:t,...n})=>{let[o,a]=react.useState([gt(window.location)]),[e,u]=react.useState(0),s=react.useMemo(()=>o.at(e),[o,e]),[i,r]=react.useState(false),[y,l]=react.useState(),[x,C]=react.useState(),[k,P]=react.useState(0),O=!i&&e>0,$=!i&&e+1<o.length;react.useEffect(()=>{window.history.replaceState(s.state,"",A(s));},[]),react.useEffect(()=>{let p=({state:m})=>{u(m?.index);};return addEventListener("popstate",p),()=>{removeEventListener("popstate",p);}},[e]);let j=react.useCallback(({to:p,replace:m})=>{if(!p)return s;let R=m?e:e+1,d=p.startsWith("/")?p:yt(s.pathname,p),[g,f]=d.split("?"),h=new URLSearchParams(f??""),T={index:R};return {index:R,href:origin+g+(f?`?${h.toString()}`:""),search:Object.fromEntries(h.entries()),state:T,pathname:g}},[e,s]),v=(p,m,R=t.defaultTransitionDuration,d)=>{r(true),C(m),P(R),l(p),setTimeout(()=>{r(false),C(void 0),l(void 0),d?.();},R);},I=react.useCallback(({to:p,replace:m,transitionType:R,duration:d,onFinish:g})=>{if(i)return;let f=m?e:e+1,h=j({to:p,replace:m}),T=()=>{m?(a(M=>[...M.slice(0,f),h,...M.slice(f+1)]),window.history.replaceState(h.state,"",A(h))):(a(M=>[...M.slice(0,f),h]),u(f),window.history.pushState(h.state,"",A(h))),g?.();},H=R??t.defaultTransitionType?.(s,h)??"slide-left";H?v(h,H,d,T):T();},[e,o,i,t]),S=react.useCallback(({transitionType:p,duration:m,onFinish:R,depth:d}={})=>{if(!O)return;let g=d??1,f=o.at(e-g);if(!f)return;let h=()=>{window.history.go(-g),R?.();},T=p??t.defaultTransitionType?.(s,f)??"slide-right";T?v(f,T,m,h):h();},[e,o,i,t]),W=react.useCallback(({transitionType:p,duration:m,depth:R,onFinish:d}={})=>{if(!$)return;let g=R??1,f=o.at(e+g);if(!f)return;let h=()=>{window.history.go(g),d?.();},T=p??t.defaultTransitionType?.(s,f)??"slide-left";T?v(f,T,m,h):h();},[e,o,i,t]),G=react.useCallback((p,m)=>{a(R=>R.map(d=>{if(d.index!==p)return d;let g=typeof m=="function"?m(d.state):m,f={...d,state:g};return p===e&&window.history.replaceState(g,"",A(f)),f}));},[e]),X=react.useCallback((p,m)=>{a(R=>R.map(d=>{if(d.index!==p)return d;let g={...d,search:{...d.search,...m}};return p===e&&window.history.replaceState(g.state,"",A(g)),g}));},[]);return jsxRuntime.jsx(q.Provider,{value:{options:t,history:o,location:s,canGoBack:O,canGoForward:$,isTransitioning:i,transitioningToLocation:y,transitionType:x,transitionDuration:k,buildLocation:j,navigate:I,back:S,forward:W,setLocationState:G,setLocationSearch:X},children:jsxRuntime.jsx(U,{location:s,...n})})};var ot=react.memo(()=>{let t=tt(),n=V(),o=react.useMemo(()=>ht(t,n.pathname),[t,n.pathname]);return jsxRuntime.jsx(_.Provider,{value:o,children:jsxRuntime.jsx(et,{route:t,children:jsxRuntime.jsx(J,{})})})});var Lt=({route:t,...n})=>{let o=react.useMemo(()=>xt(t),[t]),[a,e]=react.useState({}),u=react.useCallback((i,r)=>a[i]?.[r],[a]),s=react.useCallback((i,r,y)=>{e(l=>({...l,[i]:{...l[i],[r]:y}}));},[]);return jsxRuntime.jsx(Q.Provider,{value:{...o,state:a,getRouteState:u,setRouteState:s},...n})};var te={position:"absolute",inset:0,zIndex:-1},ee=({allowSwipeBack:t=true,allowSwipeForward:n=true,style:o,...a})=>{let{history:e,location:u,canGoBack:s,canGoForward:i,isTransitioning:r,transitioningToLocation:y,transitionType:l,transitionDuration:x,back:C,forward:k}=w(),P=u.index,O=react.useRef(false),$=react.useRef(0),j=react.useRef(0),[v,I]=react.useState(false),[S,W]=react.useState(0),[G,X]=react.useState(false),[p,m]=react.useState(false),[R,d]=react.useState(false),[g,f]=react.useState(false);if(react.useEffect(()=>{!r||!y||(f(true),setTimeout(()=>{f(false);},x));},[r,y,x]),P===void 0)return;let h=()=>{I(false),W(0),X(false),m(false),d(false);},T=react.useCallback(b=>{r||!i&&!s||(O.current=true,$.current=b.touches[0].clientX,j.current=b.touches[0].clientY);},[r,s,i]),H=react.useCallback(b=>{if(!O.current)return;let{clientX:Ct,clientY:St}=b.touches[0];if(!v&&Math.abs(St-j.current)>30){O.current=false;return}let N=Ct-$.current;if(!(Math.abs(N)<10)){if(v||I(true),N>0&&P===0||N<0&&P+1===e.length){W(0);return}!G&&N<0&&n&&X(true),!p&&N>0&&t&&m(true),W(Math.max(Math.min(N,window.innerWidth),-window.innerWidth));}},[v,P,e.length,G,p,t,n]),M=react.useCallback(()=>{if(O.current=false,!v)return;let b={onFinish:h};S>innerWidth*.3&&s&&t?C(b):S<-innerWidth*.3&&i&&n?k(b):(d(true),setTimeout(h,x));},[C,k,v,S,s,i,x]);return jsxRuntime.jsxs("div",{style:{position:"relative",overflow:"hidden",...o},...a,children:[(r&&l==="slide-right"||v&&p)&&jsxRuntime.jsx("div",{style:te,children:jsxRuntime.jsx(U,{location:r?y:e.at(P-1),children:jsxRuntime.jsx(ot,{},P-1)})}),jsxRuntime.jsx("div",{style:{position:"absolute",inset:0,transform:r&&l==="slide-right"?"translateX(100%)":v&&S>0&&!R?`translateX(${S}px)`:"translateX(0px)",transition:R||r&&l==="slide-right"?`transform ${x}ms ease-out`:""},onTouchStart:T,onTouchMove:H,onTouchEnd:M,children:jsxRuntime.jsx(ot,{})},P),(r&&l==="slide-left"||v&&G)&&jsxRuntime.jsx("div",{style:{position:"absolute",inset:0,zIndex:1,transform:`translateX(${g?"0px":r||R?"100%":`${innerWidth+S}px`})`,transition:`transform ${r||R?x:0}ms ease-in`},children:jsxRuntime.jsx(U,{location:r?y:e.at(P+1),children:jsxRuntime.jsx(ot,{},y?.index)})})]})},Rn=({route:t,...n})=>jsxRuntime.jsx(Lt,{route:t,children:jsxRuntime.jsx(ee,{...n})});
|
|
2
|
+
exports.DefaultTransitionDuration=Eo;exports.Link=de;exports.LocationContext=Y;exports.LocationProvider=U;exports.Outlet=mt;exports.RootRouteContext=Q;exports.RouterContext=q;exports.RouterProvider=Xo;exports.Stack=Rn;exports.buildPathnameFromMatches=Yt;exports.buildUrlFromLocation=A;exports.createRouterOptions=$o;exports.matchPattern=qt;exports.matchRoute=ht;exports.parseLocation=gt;exports.parseRoute=xt;exports.redirect=Do;exports.resolveRelativeUrl=yt;exports.useLocation=V;exports.useRootRoute=tt;exports.useRoute=pt;exports.useRouteMatch=K;exports.useRouter=w;//# sourceMappingURL=index.cjs.map
|
|
2
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useRouter.ts","../src/context/router-context.ts","../src/components/link.tsx","../src/context/location-context.ts","../src/components/location-provider.tsx","../src/context/outlet-context.ts","../src/hooks/useOutlet.ts","../src/context/route-match-context.ts","../src/hooks/useRouteMatch.ts","../src/components/outlet-provider.tsx","../src/hooks/useLocation.ts","../src/context/route-context.ts","../src/hooks/useRoute.ts","../src/components/route-component.tsx","../src/hooks/useRootRoute.ts","../src/context/root-route-context.ts","../src/components/route-provider.tsx","../src/components/outlet.tsx","../src/components/router-provider.tsx","../src/constants.ts","../src/utils.ts","../src/components/stack.tsx","../src/components/page-renderer.tsx","../src/components/root-route-provider.tsx"],"sourcesContent":["export * from \"./components/index.js\";\nexport * from \"./context/index.js\";\nexport * from \"./hooks/index.js\";\nexport * from \"./types.d.js\";\nexport * from \"./utils.js\";\n","import { useContext } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\n\nexport const useRouter = () => {\n const router = useContext(RouterContext);\n if (router === null) {\n throw new Error(\"useRouter must be used within a Stack\");\n }\n return router;\n};\n","import { createContext } from \"react\";\n\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\n\nexport interface RouterContextType {\n // Router Config\n options: RouterOptions;\n\n // Navigation State\n history: Location[];\n location: Location;\n canGoBack: boolean;\n canGoForward: boolean;\n\n // Transition state\n isTransitioning: boolean;\n transitioningToLocation?: Location;\n transitionType?: TransitionType;\n transitionDuration: number;\n\n // Utilities\n buildLocation: (to: NavigationOptions) => Location;\n\n // Navigation Actions\n navigate: (options: NavigateActionOptions) => void;\n back: (options?: BackActionOptions) => void;\n forward: (options?: ForwardActionOptions) => void;\n\n // Low-level state action\n setLocationState: (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => void;\n setLocationSearch: (\n locationIndex: number,\n search: Record<string, string>\n ) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | null>(null);\n","import { useRouter } from \"@/hooks/useRouter.js\";\nimport type { NavigateActionOptions } from \"@/types.js\";\nimport { memo } from \"react\";\n\nexport type LinkProps = React.ComponentPropsWithoutRef<\"a\"> &\n NavigateActionOptions;\n\nexport const Link: React.FC<LinkProps> = memo(\n ({ to, replace, transitionType, duration, onFinish, ...props }) => {\n const router = useRouter();\n return (\n <a\n {...props}\n href={to}\n onClick={(e) => {\n e.preventDefault();\n router.navigate({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n });\n }}\n />\n );\n }\n);\n","import { createContext } from \"react\";\n\nimport type { Location } from \"@/types.js\";\n\nexport interface LocationContextType extends Location {\n canGoBack: boolean;\n canGoForward: boolean;\n state: Record<string, any>;\n setState: (key: string, value: any) => void;\n deleteState: (key: string) => void;\n setSearch: (key: string, value: string) => void;\n}\n\nexport const LocationContext = createContext<LocationContextType | null>(null);\n","import { LocationContext } from \"@/context/location-context.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Location } from \"@/types.js\";\nimport { memo, useCallback, useMemo } from \"react\";\n\nexport const LocationProvider = memo(\n ({\n location,\n ...props\n }: {\n location: Location;\n children: React.ReactNode;\n }) => {\n const router = useRouter();\n const state = useMemo(() => location.state, [location]);\n const setState = useCallback(\n (key: string, value: any) => {\n router.setLocationState(location.index, (prev) => ({\n ...prev,\n [key]: value,\n }));\n },\n [router, location]\n );\n const deleteState = useCallback(\n (key: string) => {\n router.setLocationState(location.index, (prev) => {\n delete prev[key];\n return prev;\n });\n },\n [router, location]\n );\n const setSearch = useCallback(\n (key: string, value: string) => {\n router.setLocationSearch(location.index, {\n ...location.search,\n [key]: value,\n });\n },\n [router, location]\n );\n return (\n <LocationContext.Provider\n value={{\n ...location,\n canGoBack: !router.isTransitioning && location.index > 0,\n canGoForward:\n !router.isTransitioning &&\n location.index + 1 < router.history.length,\n state,\n setState,\n deleteState,\n setSearch,\n }}\n {...props}\n />\n );\n },\n (a, b) => a.location === b.location\n);\n","import { createContext } from \"react\";\n\nexport const OutletContext = createContext<number>(0);\n","import { OutletContext } from \"@/context/outlet-context.js\";\nimport { useContext } from \"react\";\n\nexport const useOutlet = () => useContext(OutletContext);\n","import type { RouteMatch } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport const RouteMatchContext = createContext<RouteMatch | null>(null);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRouteMatch = () => {\n const routeMatch = useContext(RouteMatchContext);\n if (routeMatch === null) {\n throw new Error(\"useRouteMatch must be used within a RouteMatchProvider\");\n }\n return routeMatch;\n};\n","import { OutletContext } from \"@/context/outlet-context.js\";\n\nexport const OutletProvider = ({\n depth,\n ...props\n}: {\n depth: number;\n children?: React.ReactNode;\n}) => <OutletContext.Provider value={depth} {...props} />;\n","import { useContext } from \"react\";\n\nimport { LocationContext } from \"@/context/location-context.js\";\n\nexport const useLocation = () => {\n const context = useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a LocationProvider\");\n }\n return context;\n};\n","import type { ParsedRoute } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport interface RouteContextType extends ParsedRoute {\n state: Record<string, any>;\n getState: (key: string) => any;\n setState: (key: string, value: any) => void;\n}\n\nexport const RouteContext = createContext<RouteContextType | null>(null);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRoute = () => {\n const route = useContext(RouteContext);\n if (route === null) {\n throw new Error(\"useRoute must be used within a RouteProvider\");\n }\n return route;\n};\n","import { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRoute } from \"@/hooks/useRoute.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport { useEffect } from \"react\";\nimport { Outlet } from \"./outlet.js\";\n\nexport const RouteComponent = ({ depth = 0 }: { depth?: number }) => {\n const router = useRouter();\n const location = useLocation();\n const routeMatch = useRouteMatch();\n const route = useRoute();\n\n const pendingStateKey = `_Z.${route.id}.pending`;\n const pending =\n !!route.beforeLoad && route.getState(pendingStateKey) !== false;\n\n useEffect(() => {\n if (!route) {\n return;\n }\n if (route.beforeLoad && route.getState(pendingStateKey) === undefined) {\n route.setState(pendingStateKey, true);\n route\n .beforeLoad?.({ location })\n .then(() => route.setState(pendingStateKey, false))\n .catch(({ cause }: Error) => {\n if (!!cause && \"to\" in (cause as any)) {\n console.log(\"Redirecting to:\", (cause as any).to);\n router.navigate({\n ...(cause as any),\n onFinish: () => {\n route.setState(pendingStateKey, false);\n },\n });\n } else {\n route.setState(pendingStateKey, false);\n }\n });\n }\n }, [route]);\n\n if (!route) {\n return null;\n }\n\n if (pending) {\n const PendingComponent = route.pendingComponent!;\n return <PendingComponent />;\n }\n\n if (depth >= routeMatch.matches.length) {\n const NotFoundComponent = route.notFoundComponent!;\n return <NotFoundComponent />;\n }\n\n const Component = route.component;\n return Component ? <Component /> : <Outlet />;\n};\n","import { useContext } from \"react\";\n\nimport { RootRouteContext } from \"@/context/root-route-context.js\";\n\nexport const useRootRoute = () => {\n const route = useContext(RootRouteContext);\n if (route === null) {\n throw new Error(\"useRootRoute must be used within a RootRouteProvider\");\n }\n return route;\n};\n","import { createContext } from \"react\";\n\nimport type { ParsedRoute } from \"@/types.js\";\n\nexport interface RootRouteContextType extends ParsedRoute {\n state: Record<string, Record<string, any>>;\n getRouteState: (id: string, key: string) => any;\n setRouteState: (id: string, key: string, value: any) => void;\n}\n\nexport const RootRouteContext = createContext<RootRouteContextType | null>(\n null\n);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport type { ParsedRoute } from \"@/types.js\";\nimport { useCallback } from \"react\";\n\nexport const RouteProvider = ({\n route,\n ...props\n}: {\n route?: ParsedRoute;\n children?: React.ReactNode;\n}) => {\n if (!route) {\n return <RouteContext.Provider value={null} {...props} />;\n }\n\n const { state, getRouteState, setRouteState } = useRootRoute();\n\n const getState = useCallback(\n (key: string) => getRouteState(route.id, key),\n [getRouteState, route.id]\n );\n\n const setState = useCallback(\n (key: string, value: any) => {\n setRouteState(route.id, key, value);\n },\n [setRouteState, route.id]\n );\n\n return (\n <RouteContext.Provider\n value={{ ...route, state: state[route.id], getState, setState }}\n {...props}\n />\n );\n};\n","import { useOutlet } from \"@/hooks/useOutlet.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { OutletProvider } from \"./outlet-provider.js\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const Outlet = () => {\n const routeMatch = useRouteMatch();\n const depth = useOutlet() + 1;\n return (\n <OutletProvider depth={depth}>\n <RouteProvider route={routeMatch.matches.at(depth)}>\n <RouteComponent depth={depth} />\n </RouteProvider>\n </OutletProvider>\n );\n};\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\nimport {\n buildUrlFromLocation,\n parseLocation,\n resolveRelativeUrl,\n} from \"@/utils.js\";\nimport { LocationProvider } from \"./location-provider.js\";\n\nexport const RouterProvider = ({\n options,\n ...props\n}: {\n options: RouterOptions;\n children: React.ReactNode;\n}) => {\n const [history, setHistory] = useState<Location[]>([\n parseLocation(window.location),\n ]);\n const [currentLocationIndex, setCurrentLocationIndex] = useState<number>(0);\n const location = useMemo(\n () => history.at(currentLocationIndex)!,\n [history, currentLocationIndex]\n );\n const [isTransitioning, setIsTransitioning] = useState<boolean>(false);\n const [transitioningToLocation, setTransitioningToLocation] =\n useState<Location>();\n const [transitionType, setTransitionType] = useState<TransitionType>();\n const [transitionDuration, setTransitionDuration] = useState<number>(0);\n\n const canGoBack = !isTransitioning && currentLocationIndex > 0;\n const canGoForward =\n !isTransitioning && currentLocationIndex + 1 < history.length;\n\n useEffect(() => {\n window.history.replaceState(\n location.state,\n \"\",\n buildUrlFromLocation(location)\n );\n }, []);\n\n useEffect(() => {\n const handlePopState = ({ state }: PopStateEvent) => {\n console.log(\"popstate event:\", state);\n setCurrentLocationIndex(state?.index);\n };\n\n addEventListener(\"popstate\", handlePopState);\n return () => {\n removeEventListener(\"popstate\", handlePopState);\n };\n }, [currentLocationIndex]);\n\n // Utilities\n const buildLocation = useCallback(\n ({ to, replace }: NavigationOptions): Location => {\n if (!to) return location;\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n\n // Resolve to with absolute or relative paths like \"..\" or \".\"\n const url = to.startsWith(\"/\")\n ? to\n : resolveRelativeUrl(location.pathname, to);\n const [pathname, search] = url.split(\"?\");\n const searchParams = new URLSearchParams(search ?? \"\");\n const state = {\n index,\n };\n return {\n index,\n href: origin + pathname + (search ? `?${searchParams.toString()}` : \"\"),\n search: Object.fromEntries(searchParams.entries()),\n state,\n pathname,\n };\n },\n [currentLocationIndex, location]\n );\n\n // Transition helper\n const transitionTo = (\n location: Location,\n transitionType: TransitionType,\n duration: number = options.defaultTransitionDuration,\n callback?: () => void\n ) => {\n setIsTransitioning(true);\n setTransitionType(transitionType);\n setTransitionDuration(duration);\n setTransitioningToLocation(location);\n setTimeout(() => {\n setIsTransitioning(false);\n setTransitionType(undefined);\n setTransitioningToLocation(undefined);\n callback?.();\n }, duration);\n };\n\n // Navigation actions\n const navigate = useCallback(\n ({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n }: NavigateActionOptions) => {\n if (isTransitioning) return;\n\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n const newLocation = buildLocation({ to, replace });\n\n const updateHistory = () => {\n if (replace) {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ...prevHistory.slice(index + 1),\n ]);\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const back = useCallback(\n ({ transitionType, duration, onFinish, depth }: BackActionOptions = {}) => {\n if (!canGoBack) return;\n const backDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex - backDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(-backDepth);\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-right\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const forward = useCallback(\n ({\n transitionType,\n duration,\n depth,\n onFinish,\n }: ForwardActionOptions = {}) => {\n if (!canGoForward) return;\n const forwardDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex + forwardDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(forwardDepth);\n onFinish?.();\n };\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n // Low-level state action\n const setLocationState = useCallback(\n (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => {\n setHistory((prevHistory) =>\n prevHistory.map((location) => {\n if (location.index !== index) {\n return location;\n }\n const newState =\n typeof state === \"function\" ? state(location.state) : state;\n const newLocation = { ...location, state: newState };\n if (index === currentLocationIndex) {\n window.history.replaceState(\n newState,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n [currentLocationIndex]\n );\n\n const setLocationSearch = useCallback(\n (locationIndex: number, search: Record<string, string>) => {\n setHistory((prev) =>\n prev.map((location) => {\n if (location.index !== locationIndex) return location;\n const newLocation = {\n ...location,\n search: {\n ...location.search,\n ...search,\n },\n };\n if (locationIndex === currentLocationIndex) {\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n []\n );\n\n return (\n <RouterContext.Provider\n // oxlint-disable-next-line jsx-no-new-object-as-prop\n value={{\n options,\n\n history,\n location,\n canGoBack,\n canGoForward,\n\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n\n buildLocation,\n\n navigate,\n back,\n forward,\n\n setLocationState,\n setLocationSearch,\n }}\n >\n <LocationProvider location={location} {...props} />\n </RouterContext.Provider>\n );\n};\n","import type { RouterOptions } from \"./types.js\";\n\nexport const DefaultRouterOptions: RouterOptions = {\n defaultTransitionDuration: 300,\n};\n","import { DefaultRouterOptions } from \"./constants.js\";\nimport type {\n Location,\n NavigateActionOptions,\n ParsedRoute,\n Route,\n RouteMatch,\n RouterOptions,\n} from \"./types.js\";\n\nexport const DefaultTransitionDuration = 300;\n\nexport const redirect = (options: NavigateActionOptions) => {\n return new Error(\"\", { cause: options });\n};\n\n/**\n * @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.\n * @param url URL to match against the pattern. Can be href or pathname with query string.\n * @returns extracted params and query if matched, otherwise null\n */\nexport const matchPattern = (\n pattern: string,\n url: string\n): { params: Record<string, string>; query: Record<string, string> } | null => {\n try {\n // 解析 URL\n let pathname, searchParams;\n\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n const urlObj = new URL(url);\n pathname = urlObj.pathname;\n searchParams = urlObj.searchParams;\n } else {\n // 處理相對路徑\n const [path, queryString] = url.split(\"?\");\n if (!path) {\n return null;\n }\n pathname = path;\n searchParams = new URLSearchParams(queryString || \"\");\n }\n\n // 移除路徑首尾的斜線以便比較\n const cleanPath = pathname.replaceAll(/^\\/|\\/$/g, \"\");\n const cleanPattern = pattern.replaceAll(/^\\/|\\/$/g, \"\");\n\n // 分割路徑段\n const pathSegments = cleanPath.split(\"/\");\n const patternSegments = cleanPattern.split(\"/\");\n\n // 路徑段數量不同則不匹配\n if (pathSegments.length !== patternSegments.length) {\n return null;\n }\n\n // 提取路徑參數\n const params: Record<string, string> = {};\n for (let i = 0; i < patternSegments.length; i++) {\n const patternSegment = patternSegments[i];\n const pathSegment = pathSegments[i];\n\n if (patternSegment.startsWith(\":\")) {\n // 動態參數\n const paramName = patternSegment.slice(1);\n params[paramName] = decodeURIComponent(pathSegment);\n } else if (patternSegment !== pathSegment) {\n // 靜態段不匹配\n return null;\n }\n }\n\n // 提取查詢參數\n const query = Object.fromEntries(searchParams.entries());\n\n return { params, query };\n } catch {\n return null;\n }\n};\n\nexport const matchRoute = (route: ParsedRoute, url: string): RouteMatch => {\n const _matchRoute = (\n matches: ParsedRoute[],\n { children }: ParsedRoute\n ): RouteMatch | null => {\n if (children && children.length > 0) {\n for (const childRoute of children) {\n const matchesResult = _matchRoute([...matches, childRoute], childRoute);\n if (matchesResult) {\n return matchesResult;\n }\n }\n return null;\n }\n\n const result = matchPattern(buildPathnameFromMatches(matches), url);\n return result ? { matches, ...result } : null;\n };\n\n return (\n _matchRoute([route], route) || {\n matches: [],\n params: {},\n query: {},\n }\n );\n};\n\nexport const buildPathnameFromMatches = (matches: Route[]): string => {\n let cleanedPathnames: string[] = []; // pathnames without leading/trailing slashes\n for (const match of matches) {\n if (match.pathname === undefined) continue;\n cleanedPathnames.push(match.pathname.replaceAll(/^\\/|\\/$/g, \"\"));\n }\n return \"/\" + cleanedPathnames.join(\"/\");\n};\n\nexport const parseLocation = ({\n href,\n pathname,\n search,\n}: globalThis.Location): Location => ({\n index: 0,\n href,\n state: {\n index: 0,\n },\n pathname,\n search: Object.fromEntries(new URLSearchParams(search)),\n});\n\nexport const createRouterOptions = (\n options?: Partial<RouterOptions>\n): RouterOptions => ({\n ...DefaultRouterOptions,\n ...options,\n});\n\nexport const parseRoute = (route: Route): ParsedRoute => {\n const parseRouteRecursive = (route: Route, parentId: string): ParsedRoute => {\n const id =\n route.name ??\n (route.pathname\n ? `${parentId}/${route.pathname.replaceAll(/^\\/|\\/$/g, \"\")}`\n : parentId);\n\n const parsedRoute: ParsedRoute = {\n ...route,\n id,\n children: route.children?.map((child) => parseRouteRecursive(child, id)),\n };\n\n return parsedRoute;\n };\n return parseRouteRecursive(route, \"\");\n};\n\nconst isPathSegmentValid = (segment: string): boolean => segment.length > 0;\n\n/**\n * Resolves a relative path against a base url.\n * @param url The base url.\n * @param to The relative path to resolve.\n * @returns The resolved absolute url.\n */\nexport const resolveRelativeUrl = (url: string, to: string): string => {\n const currentPathSegments = url.split(\"/\").filter(isPathSegmentValid);\n const toPathSegments = to.split(\"/\").filter(isPathSegmentValid);\n for (const segment of toPathSegments) {\n if (segment === \".\") {\n continue;\n } else if (segment === \"..\") {\n currentPathSegments.pop();\n } else {\n currentPathSegments.push(segment);\n }\n }\n return \"/\" + currentPathSegments.join(\"/\");\n};\n\nexport const buildUrlFromLocation = (location: Location): string => {\n const searchParams = new URLSearchParams(location.search).toString();\n return searchParams\n ? `${location.pathname}?${searchParams}`\n : location.pathname;\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Route } from \"@/types.js\";\n\nimport { LocationProvider } from \"./location-provider.js\";\nimport { PageRenderer } from \"./page-renderer.js\";\nimport { RootRouteProvider } from \"./root-route-provider.js\";\n\nconst PreviousComponentStyle = {\n position: \"absolute\",\n inset: 0,\n zIndex: -1,\n} as const;\n\nexport interface StackComponentProps\n extends React.ComponentPropsWithoutRef<\"div\"> {\n allowSwipeForward?: boolean;\n allowSwipeBack?: boolean;\n}\n\nconst StackComponent: React.FC<StackComponentProps> = ({\n allowSwipeBack = true,\n allowSwipeForward = true,\n style,\n ...props\n}) => {\n const {\n history,\n location,\n canGoBack,\n canGoForward,\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n back,\n forward,\n } = useRouter();\n const currentLocationIndex = location.index;\n\n const isTouching = useRef(false);\n const startX = useRef(0);\n const startY = useRef(0);\n const [isDragging, setIsDragging] = useState(false);\n const [dragOffset, setDragOffset] = useState(0);\n const [showPreviousComponent, setShowPreviousComponent] = useState(false);\n const [showNextComponent, setShowNextComponent] = useState(false);\n const [isCanceling, setIsCanceling] = useState(false);\n const [isTransitionStarted, setIsTransitionStarted] = useState(false);\n\n useEffect(() => {\n if (!isTransitioning || !transitioningToLocation) return;\n setIsTransitionStarted(true);\n setTimeout(() => {\n setIsTransitionStarted(false);\n }, transitionDuration);\n }, [isTransitioning, transitioningToLocation, transitionDuration]);\n\n if (currentLocationIndex === undefined) return;\n\n const reset = () => {\n setIsDragging(false);\n setDragOffset(0);\n setShowPreviousComponent(false);\n setShowNextComponent(false);\n setIsCanceling(false);\n };\n\n const handleTouchStart = useCallback(\n (e: React.TouchEvent) => {\n if (isTransitioning || (!canGoForward && !canGoBack)) return;\n isTouching.current = true;\n startX.current = e.touches[0].clientX;\n startY.current = e.touches[0].clientY;\n },\n [isTransitioning, canGoBack, canGoForward]\n );\n\n const handleTouchMove = useCallback(\n (e: React.TouchEvent) => {\n if (!isTouching.current) return;\n // Skip vertical drag\n const { clientX, clientY } = e.touches[0];\n if (!isDragging && Math.abs(clientY - startY.current) > 30) {\n isTouching.current = false;\n return;\n }\n const offset = clientX - startX.current;\n if (Math.abs(offset) < 10) return;\n if (!isDragging) {\n setIsDragging(true);\n }\n if (\n (offset > 0 && currentLocationIndex === 0) ||\n (offset < 0 && currentLocationIndex + 1 === history.length)\n ) {\n setDragOffset(0);\n return;\n }\n if (!showPreviousComponent && offset < 0 && allowSwipeForward)\n setShowPreviousComponent(true);\n if (!showNextComponent && offset > 0 && allowSwipeBack)\n setShowNextComponent(true);\n setDragOffset(\n Math.max(Math.min(offset, window.innerWidth), -window.innerWidth)\n );\n },\n [\n isDragging,\n currentLocationIndex,\n history.length,\n showPreviousComponent,\n showNextComponent,\n allowSwipeBack,\n allowSwipeForward,\n ]\n );\n\n const handleTouchEnd = useCallback(() => {\n isTouching.current = false;\n if (!isDragging) return;\n\n const options = {\n onFinish: reset,\n };\n if (dragOffset > innerWidth * 0.3 && canGoBack && allowSwipeBack) {\n back(options);\n } else if (\n dragOffset < -innerWidth * 0.3 &&\n canGoForward &&\n allowSwipeForward\n ) {\n forward(options);\n } else {\n setIsCanceling(true);\n setTimeout(reset, transitionDuration);\n }\n }, [\n back,\n forward,\n isDragging,\n dragOffset,\n canGoBack,\n canGoForward,\n transitionDuration,\n ]);\n\n return (\n <div\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n ...style,\n }}\n {...props}\n >\n {((isTransitioning && transitionType === \"slide-right\") ||\n (isDragging && showNextComponent)) && (\n <div style={PreviousComponentStyle}>\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex - 1)!\n }\n >\n <PageRenderer key={currentLocationIndex - 1} />\n </LocationProvider>\n </div>\n )}\n <div\n key={currentLocationIndex}\n style={{\n background: \"white\",\n position: \"absolute\",\n inset: 0,\n transform:\n isTransitioning && transitionType === \"slide-right\"\n ? `translateX(100%)`\n : isDragging && dragOffset > 0 && !isCanceling\n ? `translateX(${dragOffset}px)`\n : \"translateX(0px)\",\n transition:\n isCanceling || (isTransitioning && transitionType === \"slide-right\")\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n {((isTransitioning && transitionType === \"slide-left\") ||\n (isDragging && showPreviousComponent)) && (\n <div\n style={{\n background: \"white\",\n position: \"absolute\",\n inset: 0,\n zIndex: 1,\n transform: `translateX(${\n isTransitionStarted\n ? \"0px\"\n : isTransitioning || isCanceling\n ? \"100%\"\n : `${innerWidth + dragOffset}px`\n })`,\n transition: `transform ${\n isTransitioning || isCanceling ? transitionDuration : 0\n }ms ease-in`,\n }}\n >\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex + 1)!\n }\n >\n <PageRenderer key={transitioningToLocation?.index} />\n </LocationProvider>\n </div>\n )}\n </div>\n );\n};\n\nexport interface StackProps extends StackComponentProps {\n route: Route;\n}\n\nexport const Stack: React.FC<StackProps> = ({ route, ...props }) => (\n <RootRouteProvider route={route}>\n <StackComponent {...props} />\n </RootRouteProvider>\n);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport { matchRoute } from \"@/utils.js\";\nimport { memo, useMemo } from \"react\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const PageRenderer = memo(() => {\n const rootRoute = useRootRoute();\n const location = useLocation();\n const routeMatch = useMemo(\n () => matchRoute(rootRoute, location.pathname),\n [rootRoute, location.pathname]\n );\n return (\n <RouteMatchContext.Provider value={routeMatch}>\n <RouteProvider route={rootRoute}>\n <RouteComponent />\n </RouteProvider>\n </RouteMatchContext.Provider>\n );\n});\n","import { RootRouteContext } from \"@/context/root-route-context.js\";\nimport type { Route } from \"@/types.js\";\nimport { parseRoute } from \"@/utils.js\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nexport const RootRouteProvider = ({\n route,\n ...props\n}: {\n route: Route;\n children: React.ReactNode;\n}) => {\n const parsedRoute = useMemo(() => parseRoute(route), [route]);\n const [state, setState] = useState<Record<string, Record<string, any>>>({});\n\n const getRouteState = useCallback(\n (id: string, key: string) => {\n return state[id]?.[key];\n },\n [state]\n );\n\n const setRouteState = useCallback((id: string, key: string, value: any) => {\n setState((prevState) => ({\n ...prevState,\n [id]: {\n ...prevState[id],\n [key]: value,\n },\n }));\n }, []);\n\n return (\n <RootRouteContext.Provider\n value={{ ...parsedRoute, state, getRouteState, setRouteState }}\n {...props}\n />\n );\n};\n"],"mappings":"ubAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,+BAAAE,GAAA,SAAAC,GAAA,oBAAAC,EAAA,qBAAAC,EAAA,WAAAC,GAAA,qBAAAC,EAAA,kBAAAC,EAAA,mBAAAC,GAAA,UAAAC,GAAA,6BAAAC,GAAA,yBAAAC,EAAA,wBAAAC,GAAA,iBAAAC,GA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B,EACd,YAAaE,EACb,WAAYI,EAEZ,mBAACG,GAAA,EAAa,GApBT1B,CAqBP,GACGP,GAAmBE,IAAmB,cACtCS,GAAcI,OACf,OAAC,OACC,MAAO,CACL,WAAY,QACZ,SAAU,WACV,MAAO,EACP,OAAQ,EACR,UAAW,cACTM,EACI,MACArB,GAAmBmB,EACnB,OACA,GAAG,WAAaN,CAAU,IAChC,IACA,WAAY,aACVb,GAAmBmB,EAAchB,EAAqB,CACxD,YACF,EAEA,mBAAC6B,EAAA,CACC,SACEhC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,mBAAC0B,GAAA,GAAkBhC,GAAyB,KAAO,EACrD,EACF,GAEJ,CAEJ,EAMaiC,GAA8B,CAAC,CAAE,MAAAC,EAAO,GAAGxC,CAAM,OAC5D,OAACyC,GAAA,CAAkB,MAAOD,EACxB,mBAAC5C,GAAA,CAAgB,GAAGI,EAAO,EAC7B","names":["index_exports","__export","DefaultTransitionDuration","Link","LocationContext","LocationProvider","Outlet","RootRouteContext","RouterContext","RouterProvider","Stack","buildPathnameFromMatches","buildUrlFromLocation","createRouterOptions","matchPattern","matchRoute","parseLocation","parseRoute","redirect","resolveRelativeUrl","useLocation","useRootRoute","useRoute","useRouteMatch","useRouter","__toCommonJS","import_react","import_react","RouterContext","useRouter","router","RouterContext","import_react","import_jsx_runtime","Link","to","replace","transitionType","duration","onFinish","props","router","useRouter","e","import_react","LocationContext","import_react","import_jsx_runtime","LocationProvider","location","props","router","useRouter","state","setState","key","value","prev","deleteState","setSearch","LocationContext","a","b","import_react","OutletContext","import_react","useOutlet","OutletContext","import_react","RouteMatchContext","import_react","useRouteMatch","routeMatch","RouteMatchContext","import_jsx_runtime","OutletProvider","depth","props","OutletContext","import_react","useLocation","context","LocationContext","import_react","RouteContext","import_react","useRoute","route","RouteContext","import_react","import_jsx_runtime","RouteComponent","depth","router","useRouter","location","useLocation","routeMatch","useRouteMatch","route","useRoute","pendingStateKey","pending","cause","PendingComponent","NotFoundComponent","Component","Outlet","import_react","import_react","RootRouteContext","useRootRoute","route","RootRouteContext","import_react","import_jsx_runtime","RouteProvider","route","props","RouteContext","state","getRouteState","setRouteState","useRootRoute","getState","key","setState","value","import_jsx_runtime","Outlet","routeMatch","useRouteMatch","depth","useOutlet","OutletProvider","RouteProvider","RouteComponent","import_react","DefaultRouterOptions","DefaultTransitionDuration","redirect","options","matchPattern","pattern","url","pathname","searchParams","urlObj","path","queryString","cleanPath","cleanPattern","pathSegments","patternSegments","params","i","patternSegment","pathSegment","paramName","query","matchRoute","route","_matchRoute","matches","children","childRoute","matchesResult","result","buildPathnameFromMatches","cleanedPathnames","match","parseLocation","href","search","createRouterOptions","DefaultRouterOptions","parseRoute","parseRouteRecursive","parentId","id","child","isPathSegmentValid","segment","resolveRelativeUrl","to","currentPathSegments","toPathSegments","buildUrlFromLocation","location","import_jsx_runtime","RouterProvider","options","props","history","setHistory","parseLocation","currentLocationIndex","setCurrentLocationIndex","location","isTransitioning","setIsTransitioning","transitioningToLocation","setTransitioningToLocation","transitionType","setTransitionType","transitionDuration","setTransitionDuration","canGoBack","canGoForward","buildUrlFromLocation","handlePopState","state","buildLocation","to","replace","index","url","resolveRelativeUrl","pathname","search","searchParams","transitionTo","duration","callback","navigate","onFinish","newLocation","updateHistory","prevHistory","finalTransitionType","back","depth","backDepth","forward","forwardDepth","setLocationState","newState","setLocationSearch","locationIndex","prev","RouterContext","LocationProvider","import_react","import_react","import_jsx_runtime","PageRenderer","rootRoute","useRootRoute","location","useLocation","routeMatch","matchRoute","RouteMatchContext","RouteProvider","RouteComponent","import_react","import_jsx_runtime","RootRouteProvider","route","props","parsedRoute","parseRoute","state","setState","getRouteState","id","key","setRouteState","value","prevState","RootRouteContext","import_jsx_runtime","PreviousComponentStyle","StackComponent","allowSwipeBack","allowSwipeForward","style","props","history","location","canGoBack","canGoForward","isTransitioning","transitioningToLocation","transitionType","transitionDuration","back","forward","useRouter","currentLocationIndex","isTouching","startX","startY","isDragging","setIsDragging","dragOffset","setDragOffset","showPreviousComponent","setShowPreviousComponent","showNextComponent","setShowNextComponent","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","reset","handleTouchStart","e","handleTouchMove","clientX","clientY","offset","handleTouchEnd","options","LocationProvider","PageRenderer","Stack","route","RootRouteProvider"]}
|
|
1
|
+
{"version":3,"sources":["../src/context/router-context.ts","../src/hooks/useRouter.ts","../src/components/link.tsx","../src/context/location-context.ts","../src/components/location-provider.tsx","../src/context/outlet-context.ts","../src/hooks/useOutlet.ts","../src/context/route-match-context.ts","../src/hooks/useRouteMatch.ts","../src/components/outlet-provider.tsx","../src/hooks/useLocation.ts","../src/context/route-context.ts","../src/hooks/useRoute.ts","../src/components/route-component.tsx","../src/context/root-route-context.ts","../src/hooks/useRootRoute.ts","../src/components/route-provider.tsx","../src/components/outlet.tsx","../src/constants.ts","../src/utils.ts","../src/components/router-provider.tsx","../src/components/page-renderer.tsx","../src/components/root-route-provider.tsx","../src/components/stack.tsx"],"names":["RouterContext","createContext","useRouter","router","useContext","Link","memo","to","replace","transitionType","duration","onFinish","props","jsx","e","LocationContext","LocationProvider","location","state","useMemo","setState","useCallback","key","value","prev","deleteState","setSearch","a","b","OutletContext","useOutlet","RouteMatchContext","useRouteMatch","routeMatch","OutletProvider","depth","useLocation","context","RouteContext","useRoute","route","RouteComponent","pendingStateKey","pending","useEffect","cause","PendingComponent","NotFoundComponent","Component","Outlet","RootRouteContext","useRootRoute","RouteProvider","getRouteState","setRouteState","getState","DefaultRouterOptions","DefaultTransitionDuration","redirect","options","matchPattern","pattern","url","pathname","searchParams","urlObj","path","queryString","cleanPath","cleanPattern","pathSegments","patternSegments","params","i","patternSegment","pathSegment","paramName","query","matchRoute","_matchRoute","matches","children","childRoute","matchesResult","result","buildPathnameFromMatches","cleanedPathnames","match","parseLocation","href","search","createRouterOptions","parseRoute","parseRouteRecursive","parentId","id","child","isPathSegmentValid","segment","resolveRelativeUrl","currentPathSegments","toPathSegments","buildUrlFromLocation","RouterProvider","history","setHistory","useState","currentLocationIndex","setCurrentLocationIndex","isTransitioning","setIsTransitioning","transitioningToLocation","setTransitioningToLocation","setTransitionType","transitionDuration","setTransitionDuration","canGoBack","canGoForward","handlePopState","buildLocation","index","transitionTo","callback","navigate","newLocation","updateHistory","prevHistory","finalTransitionType","back","backDepth","forward","forwardDepth","setLocationState","newState","setLocationSearch","locationIndex","PageRenderer","rootRoute","RootRouteProvider","parsedRoute","prevState","PreviousComponentStyle","StackComponent","allowSwipeBack","allowSwipeForward","style","isTouching","useRef","startX","startY","isDragging","setIsDragging","dragOffset","setDragOffset","showPreviousComponent","setShowPreviousComponent","showNextComponent","setShowNextComponent","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","reset","handleTouchStart","handleTouchMove","clientX","clientY","offset","handleTouchEnd","jsxs","Stack"],"mappings":"gFAiDO,IAAMA,CAAAA,CAAgBC,oBAAwC,IAAI,EC7ClE,IAAMC,CAAAA,CAAY,IAAM,CAC7B,IAAMC,CAAAA,CAASC,gBAAAA,CAAWJ,CAAa,CAAA,CACvC,GAAIG,CAAAA,GAAW,IAAA,CACb,MAAM,IAAI,KAAA,CAAM,uCAAuC,CAAA,CAEzD,OAAOA,CACT,MCHaE,EAAAA,CAA4BC,UAAAA,CACvC,CAAC,CAAE,GAAAC,CAAAA,CAAI,OAAA,CAAAC,CAAAA,CAAS,cAAA,CAAAC,EAAgB,QAAA,CAAAC,CAAAA,CAAU,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAM,CAAA,GAAM,CACjE,IAAMT,EAASD,CAAAA,EAAU,CACzB,OACEW,cAAAA,CAAC,KACE,GAAGD,CAAAA,CACJ,IAAA,CAAML,CAAAA,CACN,QAAUO,CAAAA,EAAM,CACdA,CAAAA,CAAE,cAAA,GACFX,CAAAA,CAAO,QAAA,CAAS,CACd,EAAA,CAAAI,EACA,OAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,SAAAC,CAAAA,C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E,EACAP,CAAAA,CAAQ,EAAA,CAAGG,CAAAA,CAAuB,CAAC,EAGzC,QAAA,CAAA9F,cAAAA,CAAC2H,EAAAA,CAAA,EAAA,CAAkBzB,GAAyB,KAAO,CAAA,CACrD,CAAA,CACF,CAAA,CAAA,CAEJ,CAEJ,CAAA,CAMa2D,EAAAA,CAA8B,CAAC,CAAE,MAAAlI,CAAAA,CAAO,GAAG5B,CAAM,CAAA,GAC5DC,eAAC6H,EAAAA,CAAA,CAAkB,KAAA,CAAOlG,CAAAA,CACxB,SAAA3B,cAAAA,CAACiI,EAAAA,CAAA,CAAgB,GAAGlI,EAAO,CAAA,CAC7B","file":"index.cjs","sourcesContent":["import { createContext } from \"react\";\n\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\n\nexport interface RouterContextType {\n // Router Config\n options: RouterOptions;\n\n // Navigation State\n history: Location[];\n location: Location;\n canGoBack: boolean;\n canGoForward: boolean;\n\n // Transition state\n isTransitioning: boolean;\n transitioningToLocation?: Location;\n transitionType?: TransitionType;\n transitionDuration: number;\n\n // Utilities\n buildLocation: (to: NavigationOptions) => Location;\n\n // Navigation Actions\n navigate: (options: NavigateActionOptions) => void;\n back: (options?: BackActionOptions) => void;\n forward: (options?: ForwardActionOptions) => void;\n\n // Low-level state action\n setLocationState: (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => void;\n setLocationSearch: (\n locationIndex: number,\n search: Record<string, string>\n ) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | null>(null);\n","import { useContext } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\n\nexport const useRouter = () => {\n const router = useContext(RouterContext);\n if (router === null) {\n throw new Error(\"useRouter must be used within a Stack\");\n }\n return router;\n};\n","import { useRouter } from \"@/hooks/useRouter.js\";\nimport type { NavigateActionOptions } from \"@/types.js\";\nimport { memo } from \"react\";\n\nexport type LinkProps = React.ComponentPropsWithoutRef<\"a\"> &\n NavigateActionOptions;\n\nexport const Link: React.FC<LinkProps> = memo(\n ({ to, replace, transitionType, duration, onFinish, ...props }) => {\n const router = useRouter();\n return (\n <a\n {...props}\n href={to}\n onClick={(e) => {\n e.preventDefault();\n router.navigate({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n });\n }}\n />\n );\n }\n);\n","import { createContext } from \"react\";\n\nimport type { Location } from \"@/types.js\";\n\nexport interface LocationContextType extends Location {\n canGoBack: boolean;\n canGoForward: boolean;\n state: Record<string, any>;\n setState: (key: string, value: any) => void;\n deleteState: (key: string) => void;\n setSearch: (key: string, value: string) => void;\n}\n\nexport const LocationContext = createContext<LocationContextType | null>(null);\n","import { LocationContext } from \"@/context/location-context.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Location } from \"@/types.js\";\nimport { memo, useCallback, useMemo } from \"react\";\n\nexport const LocationProvider = memo(\n ({\n location,\n ...props\n }: {\n location: Location;\n children: React.ReactNode;\n }) => {\n const router = useRouter();\n const state = useMemo(() => location.state, [location]);\n const setState = useCallback(\n (key: string, value: any) => {\n router.setLocationState(location.index, (prev) => ({\n ...prev,\n [key]: value,\n }));\n },\n [router, location]\n );\n const deleteState = useCallback(\n (key: string) => {\n router.setLocationState(location.index, (prev) => {\n delete prev[key];\n return prev;\n });\n },\n [router, location]\n );\n const setSearch = useCallback(\n (key: string, value: string) => {\n router.setLocationSearch(location.index, {\n ...location.search,\n [key]: value,\n });\n },\n [router, location]\n );\n return (\n <LocationContext.Provider\n value={{\n ...location,\n canGoBack: !router.isTransitioning && location.index > 0,\n canGoForward:\n !router.isTransitioning &&\n location.index + 1 < router.history.length,\n state,\n setState,\n deleteState,\n setSearch,\n }}\n {...props}\n />\n );\n },\n (a, b) => a.location === b.location\n);\n","import { createContext } from \"react\";\n\nexport const OutletContext = createContext<number>(0);\n","import { OutletContext } from \"@/context/outlet-context.js\";\nimport { useContext } from \"react\";\n\nexport const useOutlet = () => useContext(OutletContext);\n","import type { RouteMatch } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport const RouteMatchContext = createContext<RouteMatch | null>(null);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRouteMatch = () => {\n const routeMatch = useContext(RouteMatchContext);\n if (routeMatch === null) {\n throw new Error(\"useRouteMatch must be used within a RouteMatchProvider\");\n }\n return routeMatch;\n};\n","import { OutletContext } from \"@/context/outlet-context.js\";\n\nexport const OutletProvider = ({\n depth,\n ...props\n}: {\n depth: number;\n children?: React.ReactNode;\n}) => <OutletContext.Provider value={depth} {...props} />;\n","import { useContext } from \"react\";\n\nimport { LocationContext } from \"@/context/location-context.js\";\n\nexport const useLocation = () => {\n const context = useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a LocationProvider\");\n }\n return context;\n};\n","import type { ParsedRoute } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport interface RouteContextType extends ParsedRoute {\n state: Record<string, any>;\n getState: (key: string) => any;\n setState: (key: string, value: any) => void;\n}\n\nexport const RouteContext = createContext<RouteContextType | null>(null);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRoute = () => {\n const route = useContext(RouteContext);\n if (route === null) {\n throw new Error(\"useRoute must be used within a RouteProvider\");\n }\n return route;\n};\n","import { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRoute } from \"@/hooks/useRoute.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport { useEffect } from \"react\";\nimport { Outlet } from \"./outlet.js\";\n\nexport const RouteComponent = ({ depth = 0 }: { depth?: number }) => {\n const router = useRouter();\n const location = useLocation();\n const routeMatch = useRouteMatch();\n const route = useRoute();\n\n const pendingStateKey = `_Z.${route.id}.pending`;\n const pending =\n !!route.beforeLoad && route.getState(pendingStateKey) !== false;\n\n useEffect(() => {\n if (!route) {\n return;\n }\n if (route.beforeLoad && route.getState(pendingStateKey) === undefined) {\n route.setState(pendingStateKey, true);\n route\n .beforeLoad?.({ location })\n .then(() => route.setState(pendingStateKey, false))\n .catch(({ cause }: Error) => {\n if (!!cause && \"to\" in (cause as any)) {\n console.log(\"Redirecting to:\", (cause as any).to);\n router.navigate({\n ...(cause as any),\n onFinish: () => {\n route.setState(pendingStateKey, false);\n },\n });\n } else {\n route.setState(pendingStateKey, false);\n }\n });\n }\n }, [route]);\n\n if (!route) {\n return null;\n }\n\n if (pending) {\n const PendingComponent = route.pendingComponent!;\n return <PendingComponent />;\n }\n\n if (depth >= routeMatch.matches.length) {\n const NotFoundComponent = route.notFoundComponent!;\n return <NotFoundComponent />;\n }\n\n const Component = route.component;\n return Component ? <Component /> : <Outlet />;\n};\n","import { createContext } from \"react\";\n\nimport type { ParsedRoute } from \"@/types.js\";\n\nexport interface RootRouteContextType extends ParsedRoute {\n state: Record<string, Record<string, any>>;\n getRouteState: (id: string, key: string) => any;\n setRouteState: (id: string, key: string, value: any) => void;\n}\n\nexport const RootRouteContext = createContext<RootRouteContextType | null>(\n null\n);\n","import { useContext } from \"react\";\n\nimport { RootRouteContext } from \"@/context/root-route-context.js\";\n\nexport const useRootRoute = () => {\n const route = useContext(RootRouteContext);\n if (route === null) {\n throw new Error(\"useRootRoute must be used within a RootRouteProvider\");\n }\n return route;\n};\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport type { ParsedRoute } from \"@/types.js\";\nimport { useCallback } from \"react\";\n\nexport const RouteProvider = ({\n route,\n ...props\n}: {\n route?: ParsedRoute;\n children?: React.ReactNode;\n}) => {\n if (!route) {\n return <RouteContext.Provider value={null} {...props} />;\n }\n\n const { state, getRouteState, setRouteState } = useRootRoute();\n\n const getState = useCallback(\n (key: string) => getRouteState(route.id, key),\n [getRouteState, route.id]\n );\n\n const setState = useCallback(\n (key: string, value: any) => {\n setRouteState(route.id, key, value);\n },\n [setRouteState, route.id]\n );\n\n return (\n <RouteContext.Provider\n value={{ ...route, state: state[route.id], getState, setState }}\n {...props}\n />\n );\n};\n","import { useOutlet } from \"@/hooks/useOutlet.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { OutletProvider } from \"./outlet-provider.js\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const Outlet = () => {\n const routeMatch = useRouteMatch();\n const depth = useOutlet() + 1;\n return (\n <OutletProvider depth={depth}>\n <RouteProvider route={routeMatch.matches.at(depth)}>\n <RouteComponent depth={depth} />\n </RouteProvider>\n </OutletProvider>\n );\n};\n","import type { RouterOptions } from \"./types.js\";\n\nexport const DefaultRouterOptions: RouterOptions = {\n defaultTransitionDuration: 300,\n};\n","import { DefaultRouterOptions } from \"./constants.js\";\nimport type {\n Location,\n NavigateActionOptions,\n ParsedRoute,\n Route,\n RouteMatch,\n RouterOptions,\n} from \"./types.js\";\n\nexport const DefaultTransitionDuration = 300;\n\nexport const redirect = (options: NavigateActionOptions) => {\n return new Error(\"\", { cause: options });\n};\n\n/**\n * @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.\n * @param url URL to match against the pattern. Can be href or pathname with query string.\n * @returns extracted params and query if matched, otherwise null\n */\nexport const matchPattern = (\n pattern: string,\n url: string\n): { params: Record<string, string>; query: Record<string, string> } | null => {\n try {\n // 解析 URL\n let pathname, searchParams;\n\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n const urlObj = new URL(url);\n pathname = urlObj.pathname;\n searchParams = urlObj.searchParams;\n } else {\n // 處理相對路徑\n const [path, queryString] = url.split(\"?\");\n if (!path) {\n return null;\n }\n pathname = path;\n searchParams = new URLSearchParams(queryString || \"\");\n }\n\n // 移除路徑首尾的斜線以便比較\n const cleanPath = pathname.replaceAll(/^\\/|\\/$/g, \"\");\n const cleanPattern = pattern.replaceAll(/^\\/|\\/$/g, \"\");\n\n // 分割路徑段\n const pathSegments = cleanPath.split(\"/\");\n const patternSegments = cleanPattern.split(\"/\");\n\n // 路徑段數量不同則不匹配\n if (pathSegments.length !== patternSegments.length) {\n return null;\n }\n\n // 提取路徑參數\n const params: Record<string, string> = {};\n for (let i = 0; i < patternSegments.length; i++) {\n const patternSegment = patternSegments[i];\n const pathSegment = pathSegments[i];\n\n if (patternSegment.startsWith(\":\")) {\n // 動態參數\n const paramName = patternSegment.slice(1);\n params[paramName] = decodeURIComponent(pathSegment);\n } else if (patternSegment !== pathSegment) {\n // 靜態段不匹配\n return null;\n }\n }\n\n // 提取查詢參數\n const query = Object.fromEntries(searchParams.entries());\n\n return { params, query };\n } catch {\n return null;\n }\n};\n\nexport const matchRoute = (route: ParsedRoute, url: string): RouteMatch => {\n const _matchRoute = (\n matches: ParsedRoute[],\n { children }: ParsedRoute\n ): RouteMatch | null => {\n if (children && children.length > 0) {\n for (const childRoute of children) {\n const matchesResult = _matchRoute([...matches, childRoute], childRoute);\n if (matchesResult) {\n return matchesResult;\n }\n }\n return null;\n }\n\n const result = matchPattern(buildPathnameFromMatches(matches), url);\n return result ? { matches, ...result } : null;\n };\n\n return (\n _matchRoute([route], route) || {\n matches: [],\n params: {},\n query: {},\n }\n );\n};\n\nexport const buildPathnameFromMatches = (matches: Route[]): string => {\n let cleanedPathnames: string[] = []; // pathnames without leading/trailing slashes\n for (const match of matches) {\n if (match.pathname === undefined) continue;\n cleanedPathnames.push(match.pathname.replaceAll(/^\\/|\\/$/g, \"\"));\n }\n return \"/\" + cleanedPathnames.join(\"/\");\n};\n\nexport const parseLocation = ({\n href,\n pathname,\n search,\n}: globalThis.Location): Location => ({\n index: 0,\n href,\n state: {\n index: 0,\n },\n pathname,\n search: Object.fromEntries(new URLSearchParams(search)),\n});\n\nexport const createRouterOptions = (\n options?: Partial<RouterOptions>\n): RouterOptions => ({\n ...DefaultRouterOptions,\n ...options,\n});\n\nexport const parseRoute = (route: Route): ParsedRoute => {\n const parseRouteRecursive = (route: Route, parentId: string): ParsedRoute => {\n const id =\n route.name ??\n (route.pathname\n ? `${parentId}/${route.pathname.replaceAll(/^\\/|\\/$/g, \"\")}`\n : parentId);\n\n const parsedRoute: ParsedRoute = {\n ...route,\n id,\n children: route.children?.map((child) => parseRouteRecursive(child, id)),\n };\n\n return parsedRoute;\n };\n return parseRouteRecursive(route, \"\");\n};\n\nconst isPathSegmentValid = (segment: string): boolean => segment.length > 0;\n\n/**\n * Resolves a relative path against a base url.\n * @param url The base url.\n * @param to The relative path to resolve.\n * @returns The resolved absolute url.\n */\nexport const resolveRelativeUrl = (url: string, to: string): string => {\n const currentPathSegments = url.split(\"/\").filter(isPathSegmentValid);\n const toPathSegments = to.split(\"/\").filter(isPathSegmentValid);\n for (const segment of toPathSegments) {\n if (segment === \".\") {\n continue;\n } else if (segment === \"..\") {\n currentPathSegments.pop();\n } else {\n currentPathSegments.push(segment);\n }\n }\n return \"/\" + currentPathSegments.join(\"/\");\n};\n\nexport const buildUrlFromLocation = (location: Location): string => {\n const searchParams = new URLSearchParams(location.search).toString();\n return searchParams\n ? `${location.pathname}?${searchParams}`\n : location.pathname;\n};\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\nimport {\n buildUrlFromLocation,\n parseLocation,\n resolveRelativeUrl,\n} from \"@/utils.js\";\nimport { LocationProvider } from \"./location-provider.js\";\n\nexport const RouterProvider = ({\n options,\n ...props\n}: {\n options: RouterOptions;\n children: React.ReactNode;\n}) => {\n const [history, setHistory] = useState<Location[]>([\n parseLocation(window.location),\n ]);\n const [currentLocationIndex, setCurrentLocationIndex] = useState<number>(0);\n const location = useMemo(\n () => history.at(currentLocationIndex)!,\n [history, currentLocationIndex]\n );\n const [isTransitioning, setIsTransitioning] = useState<boolean>(false);\n const [transitioningToLocation, setTransitioningToLocation] =\n useState<Location>();\n const [transitionType, setTransitionType] = useState<TransitionType>();\n const [transitionDuration, setTransitionDuration] = useState<number>(0);\n\n const canGoBack = !isTransitioning && currentLocationIndex > 0;\n const canGoForward =\n !isTransitioning && currentLocationIndex + 1 < history.length;\n\n useEffect(() => {\n window.history.replaceState(\n location.state,\n \"\",\n buildUrlFromLocation(location)\n );\n }, []);\n\n useEffect(() => {\n const handlePopState = ({ state }: PopStateEvent) => {\n setCurrentLocationIndex(state?.index);\n };\n\n addEventListener(\"popstate\", handlePopState);\n return () => {\n removeEventListener(\"popstate\", handlePopState);\n };\n }, [currentLocationIndex]);\n\n // Utilities\n const buildLocation = useCallback(\n ({ to, replace }: NavigationOptions): Location => {\n if (!to) return location;\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n\n // Resolve to with absolute or relative paths like \"..\" or \".\"\n const url = to.startsWith(\"/\")\n ? to\n : resolveRelativeUrl(location.pathname, to);\n const [pathname, search] = url.split(\"?\");\n const searchParams = new URLSearchParams(search ?? \"\");\n const state = {\n index,\n };\n return {\n index,\n href: origin + pathname + (search ? `?${searchParams.toString()}` : \"\"),\n search: Object.fromEntries(searchParams.entries()),\n state,\n pathname,\n };\n },\n [currentLocationIndex, location]\n );\n\n // Transition helper\n const transitionTo = (\n location: Location,\n transitionType: TransitionType,\n duration: number = options.defaultTransitionDuration,\n callback?: () => void\n ) => {\n setIsTransitioning(true);\n setTransitionType(transitionType);\n setTransitionDuration(duration);\n setTransitioningToLocation(location);\n setTimeout(() => {\n setIsTransitioning(false);\n setTransitionType(undefined);\n setTransitioningToLocation(undefined);\n callback?.();\n }, duration);\n };\n\n // Navigation actions\n const navigate = useCallback(\n ({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n }: NavigateActionOptions) => {\n if (isTransitioning) return;\n\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n const newLocation = buildLocation({ to, replace });\n\n const updateHistory = () => {\n if (replace) {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ...prevHistory.slice(index + 1),\n ]);\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const back = useCallback(\n ({ transitionType, duration, onFinish, depth }: BackActionOptions = {}) => {\n if (!canGoBack) return;\n const backDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex - backDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(-backDepth);\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-right\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const forward = useCallback(\n ({\n transitionType,\n duration,\n depth,\n onFinish,\n }: ForwardActionOptions = {}) => {\n if (!canGoForward) return;\n const forwardDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex + forwardDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(forwardDepth);\n onFinish?.();\n };\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n // Low-level state action\n const setLocationState = useCallback(\n (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => {\n setHistory((prevHistory) =>\n prevHistory.map((location) => {\n if (location.index !== index) {\n return location;\n }\n const newState =\n typeof state === \"function\" ? state(location.state) : state;\n const newLocation = { ...location, state: newState };\n if (index === currentLocationIndex) {\n window.history.replaceState(\n newState,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n [currentLocationIndex]\n );\n\n const setLocationSearch = useCallback(\n (locationIndex: number, search: Record<string, string>) => {\n setHistory((prev) =>\n prev.map((location) => {\n if (location.index !== locationIndex) return location;\n const newLocation = {\n ...location,\n search: {\n ...location.search,\n ...search,\n },\n };\n if (locationIndex === currentLocationIndex) {\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n []\n );\n\n return (\n <RouterContext.Provider\n // oxlint-disable-next-line jsx-no-new-object-as-prop\n value={{\n options,\n\n history,\n location,\n canGoBack,\n canGoForward,\n\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n\n buildLocation,\n\n navigate,\n back,\n forward,\n\n setLocationState,\n setLocationSearch,\n }}\n >\n <LocationProvider location={location} {...props} />\n </RouterContext.Provider>\n );\n};\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport { matchRoute } from \"@/utils.js\";\nimport { memo, useMemo } from \"react\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const PageRenderer = memo(() => {\n const rootRoute = useRootRoute();\n const location = useLocation();\n const routeMatch = useMemo(\n () => matchRoute(rootRoute, location.pathname),\n [rootRoute, location.pathname]\n );\n return (\n <RouteMatchContext.Provider value={routeMatch}>\n <RouteProvider route={rootRoute}>\n <RouteComponent />\n </RouteProvider>\n </RouteMatchContext.Provider>\n );\n});\n","import { RootRouteContext } from \"@/context/root-route-context.js\";\nimport type { Route } from \"@/types.js\";\nimport { parseRoute } from \"@/utils.js\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nexport const RootRouteProvider = ({\n route,\n ...props\n}: {\n route: Route;\n children: React.ReactNode;\n}) => {\n const parsedRoute = useMemo(() => parseRoute(route), [route]);\n const [state, setState] = useState<Record<string, Record<string, any>>>({});\n\n const getRouteState = useCallback(\n (id: string, key: string) => {\n return state[id]?.[key];\n },\n [state]\n );\n\n const setRouteState = useCallback((id: string, key: string, value: any) => {\n setState((prevState) => ({\n ...prevState,\n [id]: {\n ...prevState[id],\n [key]: value,\n },\n }));\n }, []);\n\n return (\n <RootRouteContext.Provider\n value={{ ...parsedRoute, state, getRouteState, setRouteState }}\n {...props}\n />\n );\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Route } from \"@/types.js\";\n\nimport { LocationProvider } from \"./location-provider.js\";\nimport { PageRenderer } from \"./page-renderer.js\";\nimport { RootRouteProvider } from \"./root-route-provider.js\";\n\nconst PreviousComponentStyle = {\n position: \"absolute\",\n inset: 0,\n zIndex: -1,\n} as const;\n\nexport interface StackComponentProps\n extends React.ComponentPropsWithoutRef<\"div\"> {\n allowSwipeForward?: boolean;\n allowSwipeBack?: boolean;\n}\n\nconst StackComponent: React.FC<StackComponentProps> = ({\n allowSwipeBack = true,\n allowSwipeForward = true,\n style,\n ...props\n}) => {\n const {\n history,\n location,\n canGoBack,\n canGoForward,\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n back,\n forward,\n } = useRouter();\n const currentLocationIndex = location.index;\n\n const isTouching = useRef(false);\n const startX = useRef(0);\n const startY = useRef(0);\n const [isDragging, setIsDragging] = useState(false);\n const [dragOffset, setDragOffset] = useState(0);\n const [showPreviousComponent, setShowPreviousComponent] = useState(false);\n const [showNextComponent, setShowNextComponent] = useState(false);\n const [isCanceling, setIsCanceling] = useState(false);\n const [isTransitionStarted, setIsTransitionStarted] = useState(false);\n\n useEffect(() => {\n if (!isTransitioning || !transitioningToLocation) return;\n setIsTransitionStarted(true);\n setTimeout(() => {\n setIsTransitionStarted(false);\n }, transitionDuration);\n }, [isTransitioning, transitioningToLocation, transitionDuration]);\n\n if (currentLocationIndex === undefined) return;\n\n const reset = () => {\n setIsDragging(false);\n setDragOffset(0);\n setShowPreviousComponent(false);\n setShowNextComponent(false);\n setIsCanceling(false);\n };\n\n const handleTouchStart = useCallback(\n (e: React.TouchEvent) => {\n if (isTransitioning || (!canGoForward && !canGoBack)) return;\n isTouching.current = true;\n startX.current = e.touches[0].clientX;\n startY.current = e.touches[0].clientY;\n },\n [isTransitioning, canGoBack, canGoForward]\n );\n\n const handleTouchMove = useCallback(\n (e: React.TouchEvent) => {\n if (!isTouching.current) return;\n // Skip vertical drag\n const { clientX, clientY } = e.touches[0];\n if (!isDragging && Math.abs(clientY - startY.current) > 30) {\n isTouching.current = false;\n return;\n }\n const offset = clientX - startX.current;\n if (Math.abs(offset) < 10) return;\n if (!isDragging) {\n setIsDragging(true);\n }\n if (\n (offset > 0 && currentLocationIndex === 0) ||\n (offset < 0 && currentLocationIndex + 1 === history.length)\n ) {\n setDragOffset(0);\n return;\n }\n if (!showPreviousComponent && offset < 0 && allowSwipeForward)\n setShowPreviousComponent(true);\n if (!showNextComponent && offset > 0 && allowSwipeBack)\n setShowNextComponent(true);\n setDragOffset(\n Math.max(Math.min(offset, window.innerWidth), -window.innerWidth)\n );\n },\n [\n isDragging,\n currentLocationIndex,\n history.length,\n showPreviousComponent,\n showNextComponent,\n allowSwipeBack,\n allowSwipeForward,\n ]\n );\n\n const handleTouchEnd = useCallback(() => {\n isTouching.current = false;\n if (!isDragging) return;\n\n const options = {\n onFinish: reset,\n };\n if (dragOffset > innerWidth * 0.3 && canGoBack && allowSwipeBack) {\n back(options);\n } else if (\n dragOffset < -innerWidth * 0.3 &&\n canGoForward &&\n allowSwipeForward\n ) {\n forward(options);\n } else {\n setIsCanceling(true);\n setTimeout(reset, transitionDuration);\n }\n }, [\n back,\n forward,\n isDragging,\n dragOffset,\n canGoBack,\n canGoForward,\n transitionDuration,\n ]);\n\n return (\n <div\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n ...style,\n }}\n {...props}\n >\n {((isTransitioning && transitionType === \"slide-right\") ||\n (isDragging && showNextComponent)) && (\n <div style={PreviousComponentStyle}>\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex - 1)!\n }\n >\n <PageRenderer key={currentLocationIndex - 1} />\n </LocationProvider>\n </div>\n )}\n <div\n key={currentLocationIndex}\n style={{\n position: \"absolute\",\n inset: 0,\n transform:\n isTransitioning && transitionType === \"slide-right\"\n ? `translateX(100%)`\n : isDragging && dragOffset > 0 && !isCanceling\n ? `translateX(${dragOffset}px)`\n : \"translateX(0px)\",\n transition:\n isCanceling || (isTransitioning && transitionType === \"slide-right\")\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n {((isTransitioning && transitionType === \"slide-left\") ||\n (isDragging && showPreviousComponent)) && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: 1,\n transform: `translateX(${\n isTransitionStarted\n ? \"0px\"\n : isTransitioning || isCanceling\n ? \"100%\"\n : `${innerWidth + dragOffset}px`\n })`,\n transition: `transform ${\n isTransitioning || isCanceling ? transitionDuration : 0\n }ms ease-in`,\n }}\n >\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex + 1)!\n }\n >\n <PageRenderer key={transitioningToLocation?.index} />\n </LocationProvider>\n </div>\n )}\n </div>\n );\n};\n\nexport interface StackProps extends StackComponentProps {\n route: Route;\n}\n\nexport const Stack: React.FC<StackProps> = ({ route, ...props }) => (\n <RootRouteProvider route={route}>\n <StackComponent {...props} />\n </RootRouteProvider>\n);\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import{useContext as Ot}from"react";import{createContext as bt}from"react";var Y=bt(null);var b=()=>{let t=Ot(Y);if(t===null)throw new Error("useRouter must be used within a Stack");return t};import{memo as kt}from"react";import{jsx as Mt}from"react/jsx-runtime";var le=kt(({to:t,replace:n,transitionType:o,duration:a,onFinish:e,...p})=>{let s=b();return Mt("a",{...p,href:t,onClick:i=>{i.preventDefault(),s.navigate({to:t,replace:n,transitionType:o,duration:a,onFinish:e})}})});import{createContext as Nt}from"react";var z=Nt(null);import{memo as At,useCallback as rt,useMemo as Ft}from"react";import{jsx as Et}from"react/jsx-runtime";var B=At(({location:t,...n})=>{let o=b(),a=Ft(()=>t.state,[t]),e=rt((i,r)=>{o.setLocationState(t.index,v=>({...v,[i]:r}))},[o,t]),p=rt(i=>{o.setLocationState(t.index,r=>(delete r[i],r))},[o,t]),s=rt((i,r)=>{o.setLocationSearch(t.index,{...t.search,[i]:r})},[o,t]);return Et(z.Provider,{value:{...t,canGoBack:!o.isTransitioning&&t.index>0,canGoForward:!o.isTransitioning&&t.index+1<o.history.length,state:a,setState:e,deleteState:p,setSearch:s},...n})},(t,n)=>t.location===n.location);import{createContext as Dt}from"react";var _=Dt(0);import{useContext as $t}from"react";var ut=()=>$t(_);import{createContext as jt}from"react";var K=jt(null);import{useContext as Wt}from"react";var V=()=>{let t=Wt(K);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};import{jsx as Gt}from"react/jsx-runtime";var pt=({depth:t,...n})=>Gt(_.Provider,{value:t,...n});import{useContext as Ut}from"react";var Z=()=>{let t=Ut(z);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};import{createContext as Bt}from"react";var I=Bt(null);import{useContext as It}from"react";var mt=()=>{let t=It(I);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};import{useEffect as Xt}from"react";import{jsx as J}from"react/jsx-runtime";var Q=({depth:t=0})=>{let n=b(),o=Z(),a=V(),e=mt(),p=`_Z.${e.id}.pending`,s=!!e.beforeLoad&&e.getState(p)!==!1;if(Xt(()=>{e&&e.beforeLoad&&e.getState(p)===void 0&&(e.setState(p,!0),e.beforeLoad?.({location:o}).then(()=>e.setState(p,!1)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),n.navigate({...r,onFinish:()=>{e.setState(p,!1)}})):e.setState(p,!1)}))},[e]),!e)return null;if(s){let r=e.pendingComponent;return J(r,{})}if(t>=a.matches.length){let r=e.notFoundComponent;return J(r,{})}let i=e.component;return i?J(i,{}):J(dt,{})};import{useContext as qt}from"react";import{createContext as Ht}from"react";var tt=Ht(null);var et=()=>{let t=qt(tt);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};import{useCallback as lt}from"react";import{jsx as ft}from"react/jsx-runtime";var ot=({route:t,...n})=>{if(!t)return ft(I.Provider,{value:null,...n});let{state:o,getRouteState:a,setRouteState:e}=et(),p=lt(i=>a(t.id,i),[a,t.id]),s=lt((i,r)=>{e(t.id,i,r)},[e,t.id]);return ft(I.Provider,{value:{...t,state:o[t.id],getState:p,setState:s},...n})};import{jsx as it}from"react/jsx-runtime";var dt=()=>{let t=V(),n=ut()+1;return it(pt,{depth:n,children:it(ot,{route:t.matches.at(n),children:it(Q,{depth:n})})})};import{useCallback as E,useEffect as Tt,useMemo as _t,useState as D}from"react";var Rt={defaultTransitionDuration:300};var Do=300,$o=t=>new Error("",{cause:t}),Yt=(t,n)=>{try{let o,a;if(n.startsWith("http://")||n.startsWith("https://")){let f=new URL(n);o=f.pathname,a=f.searchParams}else{let[f,y]=n.split("?");if(!f)return null;o=f,a=new URLSearchParams(y||"")}let e=o.replaceAll(/^\/|\/$/g,""),p=t.replaceAll(/^\/|\/$/g,""),s=e.split("/"),i=p.split("/");if(s.length!==i.length)return null;let r={};for(let f=0;f<i.length;f++){let y=i[f],S=s[f];if(y.startsWith(":")){let M=y.slice(1);r[M]=decodeURIComponent(S)}else if(y!==S)return null}let v=Object.fromEntries(a.entries());return{params:r,query:v}}catch{return null}},gt=(t,n)=>{let o=(a,{children:e})=>{if(e&&e.length>0){for(let s of e){let i=o([...a,s],s);if(i)return i}return null}let p=Yt(zt(a),n);return p?{matches:a,...p}:null};return o([t],t)||{matches:[],params:{},query:{}}},zt=t=>{let n=[];for(let o of t)o.pathname!==void 0&&n.push(o.pathname.replaceAll(/^\/|\/$/g,""));return"/"+n.join("/")},xt=({href:t,pathname:n,search:o})=>({index:0,href:t,state:{index:0},pathname:n,search:Object.fromEntries(new URLSearchParams(o))}),jo=t=>({...Rt,...t}),yt=t=>{let n=(o,a)=>{let e=o.name??(o.pathname?`${a}/${o.pathname.replaceAll(/^\/|\/$/g,"")}`:a);return{...o,id:e,children:o.children?.map(s=>n(s,e))}};return n(t,"")},ht=t=>t.length>0,vt=(t,n)=>{let o=t.split("/").filter(ht),a=n.split("/").filter(ht);for(let e of a)e!=="."&&(e===".."?o.pop():o.push(e));return"/"+o.join("/")},F=t=>{let n=new URLSearchParams(t.search).toString();return n?`${t.pathname}?${n}`:t.pathname};import{jsx as Pt}from"react/jsx-runtime";var Ho=({options:t,...n})=>{let[o,a]=D([xt(window.location)]),[e,p]=D(0),s=_t(()=>o.at(e),[o,e]),[i,r]=D(!1),[v,f]=D(),[y,S]=D(),[M,L]=D(0),O=!i&&e>0,j=!i&&e+1<o.length;Tt(()=>{window.history.replaceState(s.state,"",F(s))},[]),Tt(()=>{let m=({state:d})=>{console.log("popstate event:",d),p(d?.index)};return addEventListener("popstate",m),()=>{removeEventListener("popstate",m)}},[e]);let W=E(({to:m,replace:d})=>{if(!m)return s;let h=d?e:e+1,l=m.startsWith("/")?m:vt(s.pathname,m),[x,R]=l.split("?"),g=new URLSearchParams(R??""),P={index:h};return{index:h,href:origin+x+(R?`?${g.toString()}`:""),search:Object.fromEntries(g.entries()),state:P,pathname:x}},[e,s]),T=(m,d,h=t.defaultTransitionDuration,l)=>{r(!0),S(d),L(h),f(m),setTimeout(()=>{r(!1),S(void 0),f(void 0),l?.()},h)},X=E(({to:m,replace:d,transitionType:h,duration:l,onFinish:x})=>{if(i)return;let R=d?e:e+1,g=W({to:m,replace:d}),P=()=>{d?(a(N=>[...N.slice(0,R),g,...N.slice(R+1)]),window.history.replaceState(g.state,"",F(g))):(a(N=>[...N.slice(0,R),g]),p(R),window.history.pushState(g.state,"",F(g))),x?.()},q=h??t.defaultTransitionType?.(s,g)??"slide-left";q?T(g,q,l,P):P()},[e,o,i,t]),w=E(({transitionType:m,duration:d,onFinish:h,depth:l}={})=>{if(!O)return;let x=l??1,R=o.at(e-x);if(!R)return;let g=()=>{window.history.go(-x),h?.()},P=m??t.defaultTransitionType?.(s,R)??"slide-right";P?T(R,P,d,g):g()},[e,o,i,t]),G=E(({transitionType:m,duration:d,depth:h,onFinish:l}={})=>{if(!j)return;let x=h??1,R=o.at(e+x);if(!R)return;let g=()=>{window.history.go(x),l?.()},P=m??t.defaultTransitionType?.(s,R)??"slide-left";P?T(R,P,d,g):g()},[e,o,i,t]),U=E((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x=typeof d=="function"?d(l.state):d,R={...l,state:x};return m===e&&window.history.replaceState(x,"",F(R)),R}))},[e]),H=E((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x={...l,search:{...l.search,...d}};return m===e&&window.history.replaceState(x.state,"",F(x)),x}))},[]);return Pt(Y.Provider,{value:{options:t,history:o,location:s,canGoBack:O,canGoForward:j,isTransitioning:i,transitioningToLocation:v,transitionType:y,transitionDuration:M,buildLocation:W,navigate:X,back:w,forward:G,setLocationState:U,setLocationSearch:H},children:Pt(B,{location:s,...n})})};import{useCallback as at,useEffect as te,useRef as ct,useState as $}from"react";import{memo as Kt,useMemo as Vt}from"react";import{jsx as st}from"react/jsx-runtime";var nt=Kt(()=>{let t=et(),n=Z(),o=Vt(()=>gt(t,n.pathname),[t,n.pathname]);return st(K.Provider,{value:o,children:st(ot,{route:t,children:st(Q,{})})})});import{useCallback as Lt,useMemo as Zt,useState as Jt}from"react";import{jsx as Qt}from"react/jsx-runtime";var Ct=({route:t,...n})=>{let o=Zt(()=>yt(t),[t]),[a,e]=Jt({}),p=Lt((i,r)=>a[i]?.[r],[a]),s=Lt((i,r,v)=>{e(f=>({...f,[i]:{...f[i],[r]:v}}))},[]);return Qt(tt.Provider,{value:{...o,state:a,getRouteState:p,setRouteState:s},...n})};import{jsx as C,jsxs as ne}from"react/jsx-runtime";var ee={position:"absolute",inset:0,zIndex:-1},oe=({allowSwipeBack:t=!0,allowSwipeForward:n=!0,style:o,...a})=>{let{history:e,location:p,canGoBack:s,canGoForward:i,isTransitioning:r,transitioningToLocation:v,transitionType:f,transitionDuration:y,back:S,forward:M}=b(),L=p.index,O=ct(!1),j=ct(0),W=ct(0),[T,X]=$(!1),[w,G]=$(0),[U,H]=$(!1),[m,d]=$(!1),[h,l]=$(!1),[x,R]=$(!1);if(te(()=>{!r||!v||(R(!0),setTimeout(()=>{R(!1)},y))},[r,v,y]),L===void 0)return;let g=()=>{X(!1),G(0),H(!1),d(!1),l(!1)},P=at(k=>{r||!i&&!s||(O.current=!0,j.current=k.touches[0].clientX,W.current=k.touches[0].clientY)},[r,s,i]),q=at(k=>{if(!O.current)return;let{clientX:St,clientY:wt}=k.touches[0];if(!T&&Math.abs(wt-W.current)>30){O.current=!1;return}let A=St-j.current;if(!(Math.abs(A)<10)){if(T||X(!0),A>0&&L===0||A<0&&L+1===e.length){G(0);return}!U&&A<0&&n&&H(!0),!m&&A>0&&t&&d(!0),G(Math.max(Math.min(A,window.innerWidth),-window.innerWidth))}},[T,L,e.length,U,m,t,n]),N=at(()=>{if(O.current=!1,!T)return;let k={onFinish:g};w>innerWidth*.3&&s&&t?S(k):w<-innerWidth*.3&&i&&n?M(k):(l(!0),setTimeout(g,y))},[S,M,T,w,s,i,y]);return ne("div",{style:{position:"relative",overflow:"hidden",...o},...a,children:[(r&&f==="slide-right"||T&&m)&&C("div",{style:ee,children:C(B,{location:r?v:e.at(L-1),children:C(nt,{},L-1)})}),C("div",{style:{background:"white",position:"absolute",inset:0,transform:r&&f==="slide-right"?"translateX(100%)":T&&w>0&&!h?`translateX(${w}px)`:"translateX(0px)",transition:h||r&&f==="slide-right"?`transform ${y}ms ease-out`:""},onTouchStart:P,onTouchMove:q,onTouchEnd:N,children:C(nt,{})},L),(r&&f==="slide-left"||T&&U)&&C("div",{style:{background:"white",position:"absolute",inset:0,zIndex:1,transform:`translateX(${x?"0px":r||h?"100%":`${innerWidth+w}px`})`,transition:`transform ${r||h?y:0}ms ease-in`},children:C(B,{location:r?v:e.at(L+1),children:C(nt,{},v?.index)})})]})},hn=({route:t,...n})=>C(Ct,{route:t,children:C(oe,{...n})});export{Do as DefaultTransitionDuration,le as Link,z as LocationContext,B as LocationProvider,dt as Outlet,tt as RootRouteContext,Y as RouterContext,Ho as RouterProvider,hn as Stack,zt as buildPathnameFromMatches,F as buildUrlFromLocation,jo as createRouterOptions,Yt as matchPattern,gt as matchRoute,xt as parseLocation,yt as parseRoute,$o as redirect,vt as resolveRelativeUrl,Z as useLocation,et as useRootRoute,mt as useRoute,V as useRouteMatch,b as useRouter};
|
|
1
|
+
import {createContext,memo,useMemo,useCallback,useContext,useEffect,useState,useRef}from'react';import {jsx,jsxs}from'react/jsx-runtime';var Y=createContext(null);var O=()=>{let t=useContext(Y);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var le=memo(({to:t,replace:n,transitionType:o,duration:a,onFinish:e,...p})=>{let s=O();return jsx("a",{...p,href:t,onClick:i=>{i.preventDefault(),s.navigate({to:t,replace:n,transitionType:o,duration:a,onFinish:e});}})});var z=createContext(null);var B=memo(({location:t,...n})=>{let o=O(),a=useMemo(()=>t.state,[t]),e=useCallback((i,r)=>{o.setLocationState(t.index,v=>({...v,[i]:r}));},[o,t]),p=useCallback(i=>{o.setLocationState(t.index,r=>(delete r[i],r));},[o,t]),s=useCallback((i,r)=>{o.setLocationSearch(t.index,{...t.search,[i]:r});},[o,t]);return jsx(z.Provider,{value:{...t,canGoBack:!o.isTransitioning&&t.index>0,canGoForward:!o.isTransitioning&&t.index+1<o.history.length,state:a,setState:e,deleteState:p,setSearch:s},...n})},(t,n)=>t.location===n.location);var _=createContext(0);var ut=()=>useContext(_);var K=createContext(null);var V=()=>{let t=useContext(K);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var pt=({depth:t,...n})=>jsx(_.Provider,{value:t,...n});var Z=()=>{let t=useContext(z);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var I=createContext(null);var mt=()=>{let t=useContext(I);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var Q=({depth:t=0})=>{let n=O(),o=Z(),a=V(),e=mt(),p=`_Z.${e.id}.pending`,s=!!e.beforeLoad&&e.getState(p)!==false;if(useEffect(()=>{e&&e.beforeLoad&&e.getState(p)===void 0&&(e.setState(p,true),e.beforeLoad?.({location:o}).then(()=>e.setState(p,false)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),n.navigate({...r,onFinish:()=>{e.setState(p,false);}})):e.setState(p,false);}));},[e]),!e)return null;if(s){let r=e.pendingComponent;return jsx(r,{})}if(t>=a.matches.length){let r=e.notFoundComponent;return jsx(r,{})}let i=e.component;return i?jsx(i,{}):jsx(dt,{})};var tt=createContext(null);var et=()=>{let t=useContext(tt);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};var ot=({route:t,...n})=>{if(!t)return jsx(I.Provider,{value:null,...n});let{state:o,getRouteState:a,setRouteState:e}=et(),p=useCallback(i=>a(t.id,i),[a,t.id]),s=useCallback((i,r)=>{e(t.id,i,r);},[e,t.id]);return jsx(I.Provider,{value:{...t,state:o[t.id],getState:p,setState:s},...n})};var dt=()=>{let t=V(),n=ut()+1;return jsx(pt,{depth:n,children:jsx(ot,{route:t.matches.at(n),children:jsx(Q,{depth:n})})})};var Rt={defaultTransitionDuration:300};var Do=300,$o=t=>new Error("",{cause:t}),Yt=(t,n)=>{try{let o,a;if(n.startsWith("http://")||n.startsWith("https://")){let f=new URL(n);o=f.pathname,a=f.searchParams;}else {let[f,y]=n.split("?");if(!f)return null;o=f,a=new URLSearchParams(y||"");}let e=o.replaceAll(/^\/|\/$/g,""),p=t.replaceAll(/^\/|\/$/g,""),s=e.split("/"),i=p.split("/");if(s.length!==i.length)return null;let r={};for(let f=0;f<i.length;f++){let y=i[f],S=s[f];if(y.startsWith(":")){let M=y.slice(1);r[M]=decodeURIComponent(S);}else if(y!==S)return null}let v=Object.fromEntries(a.entries());return {params:r,query:v}}catch{return null}},gt=(t,n)=>{let o=(a,{children:e})=>{if(e&&e.length>0){for(let s of e){let i=o([...a,s],s);if(i)return i}return null}let p=Yt(zt(a),n);return p?{matches:a,...p}:null};return o([t],t)||{matches:[],params:{},query:{}}},zt=t=>{let n=[];for(let o of t)o.pathname!==void 0&&n.push(o.pathname.replaceAll(/^\/|\/$/g,""));return "/"+n.join("/")},xt=({href:t,pathname:n,search:o})=>({index:0,href:t,state:{index:0},pathname:n,search:Object.fromEntries(new URLSearchParams(o))}),jo=t=>({...Rt,...t}),yt=t=>{let n=(o,a)=>{let e=o.name??(o.pathname?`${a}/${o.pathname.replaceAll(/^\/|\/$/g,"")}`:a);return {...o,id:e,children:o.children?.map(s=>n(s,e))}};return n(t,"")},ht=t=>t.length>0,vt=(t,n)=>{let o=t.split("/").filter(ht),a=n.split("/").filter(ht);for(let e of a)e!=="."&&(e===".."?o.pop():o.push(e));return "/"+o.join("/")},F=t=>{let n=new URLSearchParams(t.search).toString();return n?`${t.pathname}?${n}`:t.pathname};var Ho=({options:t,...n})=>{let[o,a]=useState([xt(window.location)]),[e,p]=useState(0),s=useMemo(()=>o.at(e),[o,e]),[i,r]=useState(false),[v,f]=useState(),[y,S]=useState(),[M,L]=useState(0),b=!i&&e>0,j=!i&&e+1<o.length;useEffect(()=>{window.history.replaceState(s.state,"",F(s));},[]),useEffect(()=>{let m=({state:d})=>{p(d?.index);};return addEventListener("popstate",m),()=>{removeEventListener("popstate",m);}},[e]);let W=useCallback(({to:m,replace:d})=>{if(!m)return s;let h=d?e:e+1,l=m.startsWith("/")?m:vt(s.pathname,m),[x,R]=l.split("?"),g=new URLSearchParams(R??""),P={index:h};return {index:h,href:origin+x+(R?`?${g.toString()}`:""),search:Object.fromEntries(g.entries()),state:P,pathname:x}},[e,s]),T=(m,d,h=t.defaultTransitionDuration,l)=>{r(true),S(d),L(h),f(m),setTimeout(()=>{r(false),S(void 0),f(void 0),l?.();},h);},X=useCallback(({to:m,replace:d,transitionType:h,duration:l,onFinish:x})=>{if(i)return;let R=d?e:e+1,g=W({to:m,replace:d}),P=()=>{d?(a(N=>[...N.slice(0,R),g,...N.slice(R+1)]),window.history.replaceState(g.state,"",F(g))):(a(N=>[...N.slice(0,R),g]),p(R),window.history.pushState(g.state,"",F(g))),x?.();},q=h??t.defaultTransitionType?.(s,g)??"slide-left";q?T(g,q,l,P):P();},[e,o,i,t]),w=useCallback(({transitionType:m,duration:d,onFinish:h,depth:l}={})=>{if(!b)return;let x=l??1,R=o.at(e-x);if(!R)return;let g=()=>{window.history.go(-x),h?.();},P=m??t.defaultTransitionType?.(s,R)??"slide-right";P?T(R,P,d,g):g();},[e,o,i,t]),G=useCallback(({transitionType:m,duration:d,depth:h,onFinish:l}={})=>{if(!j)return;let x=h??1,R=o.at(e+x);if(!R)return;let g=()=>{window.history.go(x),l?.();},P=m??t.defaultTransitionType?.(s,R)??"slide-left";P?T(R,P,d,g):g();},[e,o,i,t]),U=useCallback((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x=typeof d=="function"?d(l.state):d,R={...l,state:x};return m===e&&window.history.replaceState(x,"",F(R)),R}));},[e]),H=useCallback((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x={...l,search:{...l.search,...d}};return m===e&&window.history.replaceState(x.state,"",F(x)),x}));},[]);return jsx(Y.Provider,{value:{options:t,history:o,location:s,canGoBack:b,canGoForward:j,isTransitioning:i,transitioningToLocation:v,transitionType:y,transitionDuration:M,buildLocation:W,navigate:X,back:w,forward:G,setLocationState:U,setLocationSearch:H},children:jsx(B,{location:s,...n})})};var nt=memo(()=>{let t=et(),n=Z(),o=useMemo(()=>gt(t,n.pathname),[t,n.pathname]);return jsx(K.Provider,{value:o,children:jsx(ot,{route:t,children:jsx(Q,{})})})});var Ct=({route:t,...n})=>{let o=useMemo(()=>yt(t),[t]),[a,e]=useState({}),p=useCallback((i,r)=>a[i]?.[r],[a]),s=useCallback((i,r,v)=>{e(f=>({...f,[i]:{...f[i],[r]:v}}));},[]);return jsx(tt.Provider,{value:{...o,state:a,getRouteState:p,setRouteState:s},...n})};var ee={position:"absolute",inset:0,zIndex:-1},oe=({allowSwipeBack:t=true,allowSwipeForward:n=true,style:o,...a})=>{let{history:e,location:p,canGoBack:s,canGoForward:i,isTransitioning:r,transitioningToLocation:v,transitionType:f,transitionDuration:y,back:S,forward:M}=O(),L=p.index,b=useRef(false),j=useRef(0),W=useRef(0),[T,X]=useState(false),[w,G]=useState(0),[U,H]=useState(false),[m,d]=useState(false),[h,l]=useState(false),[x,R]=useState(false);if(useEffect(()=>{!r||!v||(R(true),setTimeout(()=>{R(false);},y));},[r,v,y]),L===void 0)return;let g=()=>{X(false),G(0),H(false),d(false),l(false);},P=useCallback(k=>{r||!i&&!s||(b.current=true,j.current=k.touches[0].clientX,W.current=k.touches[0].clientY);},[r,s,i]),q=useCallback(k=>{if(!b.current)return;let{clientX:St,clientY:wt}=k.touches[0];if(!T&&Math.abs(wt-W.current)>30){b.current=false;return}let A=St-j.current;if(!(Math.abs(A)<10)){if(T||X(true),A>0&&L===0||A<0&&L+1===e.length){G(0);return}!U&&A<0&&n&&H(true),!m&&A>0&&t&&d(true),G(Math.max(Math.min(A,window.innerWidth),-window.innerWidth));}},[T,L,e.length,U,m,t,n]),N=useCallback(()=>{if(b.current=false,!T)return;let k={onFinish:g};w>innerWidth*.3&&s&&t?S(k):w<-innerWidth*.3&&i&&n?M(k):(l(true),setTimeout(g,y));},[S,M,T,w,s,i,y]);return jsxs("div",{style:{position:"relative",overflow:"hidden",...o},...a,children:[(r&&f==="slide-right"||T&&m)&&jsx("div",{style:ee,children:jsx(B,{location:r?v:e.at(L-1),children:jsx(nt,{},L-1)})}),jsx("div",{style:{position:"absolute",inset:0,transform:r&&f==="slide-right"?"translateX(100%)":T&&w>0&&!h?`translateX(${w}px)`:"translateX(0px)",transition:h||r&&f==="slide-right"?`transform ${y}ms ease-out`:""},onTouchStart:P,onTouchMove:q,onTouchEnd:N,children:jsx(nt,{})},L),(r&&f==="slide-left"||T&&U)&&jsx("div",{style:{position:"absolute",inset:0,zIndex:1,transform:`translateX(${x?"0px":r||h?"100%":`${innerWidth+w}px`})`,transition:`transform ${r||h?y:0}ms ease-in`},children:jsx(B,{location:r?v:e.at(L+1),children:jsx(nt,{},v?.index)})})]})},hn=({route:t,...n})=>jsx(Ct,{route:t,children:jsx(oe,{...n})});
|
|
2
|
+
export{Do as DefaultTransitionDuration,le as Link,z as LocationContext,B as LocationProvider,dt as Outlet,tt as RootRouteContext,Y as RouterContext,Ho as RouterProvider,hn as Stack,zt as buildPathnameFromMatches,F as buildUrlFromLocation,jo as createRouterOptions,Yt as matchPattern,gt as matchRoute,xt as parseLocation,yt as parseRoute,$o as redirect,vt as resolveRelativeUrl,Z as useLocation,et as useRootRoute,mt as useRoute,V as useRouteMatch,O as useRouter};//# sourceMappingURL=index.js.map
|
|
2
3
|
//# sourceMappingURL=index.js.map
|