@modastar/z-router 0.0.9 → 0.0.11
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/.vscode/settings.json +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -19
- package/dist/index.d.ts +25 -19
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/example/dist/assets/index-BnRxLDj4.js +23 -0
- package/example/dist/assets/index-C0uITd16.css +1 -0
- package/example/dist/assets/index-CejLCVJl.js +1 -0
- package/example/dist/index.html +14 -0
- package/package.json +1 -1
package/.vscode/settings.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var tt=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Ut=Object.prototype.hasOwnProperty;var It=(t,n)=>{for(var e in n)tt(t,e,{get:n[e],enumerable:!0})},Xt=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Gt(n))!Ut.call(t,o)&&o!==e&&tt(t,o,{get:()=>n[o],enumerable:!(s=Bt(n,o))||s.enumerable});return t};var Ht=t=>Xt(tt({},"__esModule",{value:!0}),t);var Jt={};It(Jt,{DefaultTransitionDuration:()=>Yt,Link:()=>qt,LocationContext:()=>W,LocationProvider:()=>D,Outlet:()=>et,RootRouteContext:()=>I,RouterContext:()=>$,RouterProvider:()=>Vt,Stack:()=>zt,buildPathnameFromMatches:()=>At,createRouterOptions:()=>Kt,matchPattern:()=>Mt,matchRoute:()=>it,parseLocation:()=>st,parseRoute:()=>at,redirect:()=>_t,resolveRelativePathname:()=>ct,useLocation:()=>B,useRootRoute:()=>X,useRoute:()=>ot,useRouteMatch:()=>j,useRouter:()=>w});module.exports=Ht(Jt);var mt=require("react");var pt=require("react"),$=(0,pt.createContext)(null);var w=()=>{let t=(0,mt.useContext)($);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var dt=require("react"),lt=require("react/jsx-runtime"),qt=(0,dt.memo)(({to:t,replace:n,transition:e,duration:s,onFinish:o,...c})=>{let r=w();return(0,lt.jsx)("a",{...c,href:t,onClick:i=>{i.preventDefault(),r.navigate({to:t,replace:n,transition:e,duration:s,onFinish:o})}})});var ft=require("react"),W=(0,ft.createContext)(null);var N=require("react"),Rt=require("react/jsx-runtime"),D=(0,N.memo)(({location:t,...n})=>{let e=w(),s=(0,N.useCallback)(r=>t.state[r],[t]),o=(0,N.useCallback)((r,i)=>{e.setLocationState(t.index,{...t.state,[r]:i})},[e,t]),c=(0,N.useCallback)(r=>{delete t.state[r],e.setLocationState(t.index,t.state)},[e,t]);return(0,Rt.jsx)(W.Provider,{value:{...t,canGoBack:t.index>0,canGoForward:t.index<e.history.length-1,getState:s,setState:o,deleteState:c},...n})},(t,n)=>t.location===n.location);var ht=require("react"),Y=(0,ht.createContext)(0);var gt=require("react"),xt=()=>(0,gt.useContext)(Y);var yt=require("react"),_=(0,yt.createContext)(null);var vt=require("react"),j=()=>{let t=(0,vt.useContext)(_);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var Ct=require("react/jsx-runtime"),Pt=({depth:t,...n})=>(0,Ct.jsx)(Y.Provider,{value:t,...n});var Lt=require("react");var B=()=>{let t=(0,Lt.useContext)(W);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var bt=require("react"),G=(0,bt.createContext)(null);var wt=require("react"),ot=()=>{let t=(0,wt.useContext)(G);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var K=require("react");var U=require("react/jsx-runtime"),V=({depth:t=0})=>{let n=w(),e=B(),s=j(),o=ot(),c=`_Z.${o.id}.pending`,[r,i]=(0,K.useState)(!!o?.beforeLoad&&o?.getState(c)!==!1);if((0,K.useEffect)(()=>{!o||t>=s.matches.length||r&&o?.beforeLoad&&(o.setState(c,!0),o.beforeLoad({location:e}).catch(({cause:R})=>{"to"in R&&n.navigate(R)}).finally(()=>{o.setState(c,!1),i(!1)}))},[]),!o)return null;if(t>=s.matches.length){let R=o.notFoundComponent;return(0,U.jsx)(R,{})}if(r){let R=o.pendingComponent;return(0,U.jsx)(R,{})}let u=o.component;return u?(0,U.jsx)(u,{}):(0,U.jsx)(et,{})};var St=require("react");var Ot=require("react"),I=(0,Ot.createContext)(null);var X=()=>{let t=(0,St.useContext)(I);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};var nt=require("react"),rt=require("react/jsx-runtime"),Z=({route:t,...n})=>{if(!t)return(0,rt.jsx)(G.Provider,{value:null,...n});let{state:e,getRouteState:s,setRouteState:o}=X(),c=(0,nt.useCallback)(i=>s(t.id,i),[s,t.id]),r=(0,nt.useCallback)((i,u)=>{o(t.id,i,u)},[o,t.id]);return(0,rt.jsx)(G.Provider,{value:{...t,state:e[t.id],getState:c,setState:r},...n})};var z=require("react/jsx-runtime"),et=()=>{let t=j(),n=xt()+1;return(0,z.jsx)(Pt,{depth:n,children:(0,z.jsx)(Z,{route:t.matches.at(n),children:(0,z.jsx)(V,{depth:n})})})};var y=require("react");var Tt={defaultTransitionDuration:300};var Yt=300,_t=t=>new Error("",{cause:t}),Mt=(t,n)=>{try{let e,s;if(n.startsWith("http://")||n.startsWith("https://")){let l=new URL(n);e=l.pathname,s=l.searchParams}else{let[l,m]=n.split("?");if(!l)return null;e=l,s=new URLSearchParams(m||"")}let o=e.replaceAll(/^\/|\/$/g,""),c=t.replaceAll(/^\/|\/$/g,""),r=o.split("/"),i=c.split("/");if(r.length!==i.length)return null;let u={};for(let l=0;l<i.length;l++){let m=i[l],L=r[l];if(m.startsWith(":")){let S=m.slice(1);u[S]=decodeURIComponent(L)}else if(m!==L)return null}let R=Object.fromEntries(s.entries());return{params:u,query:R}}catch{return null}},it=(t,n)=>{let e=(s,{children:o})=>{if(o&&o.length>0){for(let r of o){let i=e([...s,r],r);if(i)return i}return null}let c=Mt(At(s),n);return c?{matches:s,...c}:null};return e([t],t)||{matches:[],params:{},query:{}}},At=t=>{let n=[];for(let e of t)e.pathname!==void 0&&n.push(e.pathname.replaceAll(/^\/|\/$/g,""));return"/"+n.join("/")},st=({href:t,pathname:n,search:e})=>({index:0,href:t,state:{index:0},pathname:n,search:Object.fromEntries(new URLSearchParams(e))}),Kt=t=>({...Tt,...t}),at=t=>{let n=(e,s)=>{let o=e.name??(e.pathname?`${s}/${e.pathname.replaceAll(/^\/|\/$/g,"")}`:s);return{...e,id:o,children:e.children?.map(r=>n(r,o))}};return n(t,"")},kt=t=>t.length>0,ct=(t,n)=>{let e=t.split("/").filter(kt),s=n.split("/").filter(kt);for(let o of s)o!=="."&&(o===".."?e.pop():e.push(o));return"/"+e.join("/")};var ut=require("react/jsx-runtime"),Vt=({options:t,...n})=>{let[e,s]=(0,y.useState)([st(window.location)]),[o,c]=(0,y.useState)(0),r=e.at(o),[i,u]=(0,y.useState)(!1),[R,l]=(0,y.useState)(0),[m,L]=(0,y.useState)();(0,y.useEffect)(()=>{window.history.replaceState(r.state,"",r.pathname)},[]),(0,y.useEffect)(()=>{let p=({state:d})=>{c(d?.index)};return addEventListener("popstate",p),()=>{removeEventListener("popstate",p)}},[o]);let S=(0,y.useCallback)(({to:p,replace:d})=>{if(!p)return r;let h=d?o:o+1,g=p.startsWith("/")?p:ct(r.pathname,p),P={index:h};return{index:h,href:origin+g,search:{},state:P,pathname:g}},[o,r]),M=(p,d=t.defaultTransitionDuration,h)=>{u(!0),l(d),L(p),setTimeout(()=>{u(!1),L(void 0),h?.()},d)},b=(0,y.useCallback)(({to:p,replace:d,transition:h,duration:g,onFinish:P})=>{if(i)return;let x=d?o:o+1,f=S({to:p,replace:d}),F=()=>{d?(s(T=>[...T.slice(0,x),f,...T.slice(x+1)]),window.history.replaceState(f.state,"",f.pathname)):(s(T=>[...T.slice(0,x),f]),c(x),window.history.pushState(f.state,"",f.pathname)),P?.()};h??t.defaultUseTransition?.(r,f)?M(f,g,F):F()},[o,e,i,t]),q=(0,y.useCallback)(({transition:p,duration:d,onFinish:h,depth:g}={})=>{if(o===0||i)return;let P=g??1,x=e.at(o-P),f=()=>{window.history.go(-P),h?.()};x&&(p??t.defaultUseTransition?.(r,x))?M(x,d,f):f()},[o,e,i,t]),O=(0,y.useCallback)(({transition:p,duration:d,depth:h,onFinish:g}={})=>{if(o+1>=e.length||i)return;let P=h??1,x=e.at(o+P),f=()=>{window.history.go(P),g?.()};x&&(p??t.defaultUseTransition?.(r,x))?M(x,d,f):f()},[o,e,i,t]),E=(0,y.useCallback)((p,d)=>{s(h=>h.map(g=>g.index===p?{...g,state:d}:g)),p===o&&window.history.replaceState(d,"",r.pathname)},[o]);return(0,ut.jsx)($.Provider,{value:{options:t,history:e,location:r,canGoBack:o>0,canGoForward:o<e.length-1,isTransitioning:i,transitionDuration:R,transitioningToLocation:m,buildLocation:S,navigate:b,back:q,forward:O,setLocationState:E},children:(0,ut.jsx)(D,{location:r,...n})})};var v=require("react");var J=require("react/jsx-runtime"),Q=()=>{let t=X(),n=B(),e=it(t,n.pathname);return(0,J.jsx)(_.Provider,{value:e,children:(0,J.jsx)(Z,{route:t,children:(0,J.jsx)(V,{})})})};var H=require("react"),Dt=require("react/jsx-runtime"),Nt=({rootRoute:t,...n})=>{let e=at(t),[s,o]=(0,H.useState)({}),c=(0,H.useCallback)((i,u)=>s[i]?.[u],[s]),r=(0,H.useCallback)((i,u,R)=>{o(l=>({...l,[i]:{...l[i],[u]:R}}))},[]);return(0,Dt.jsx)(I.Provider,{value:{...e,state:s,getRouteState:c,setRouteState:r},...n})};var C=require("react/jsx-runtime"),Zt=({style:t,...n})=>{let{history:e,location:s,canGoBack:o,canGoForward:c,isTransitioning:r,transitioningToLocation:i,transitionDuration:u,back:R,forward:l}=w(),m=s.index,L=(0,v.useRef)(!1),S=(0,v.useRef)(0),M=(0,v.useRef)(0),[b,q]=(0,v.useState)(!1),[O,E]=(0,v.useState)(0),[p,d]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[P,x]=(0,v.useState)(!1),[f,F]=(0,v.useState)(!1);if((0,v.useEffect)(()=>{!r||!i||(F(!0),setTimeout(()=>{F(!1)},u))},[r,i,u]),m===void 0)return;let T=()=>{q(!1),E(0),d(!1),g(!1),x(!1)},Et=k=>{r||!c&&!o||(L.current=!0,S.current=k.touches[0].clientX,M.current=k.touches[0].clientY)},Ft=k=>{if(!L.current)return;let{clientX:Wt,clientY:jt}=k.touches[0];if(!b&&Math.abs(jt-M.current)>30){L.current=!1;return}let A=Wt-S.current;if(!(Math.abs(A)<10)){if(b||q(!0),A>0&&m===0||A<0&&m+1===e.length){E(0);return}!p&&A<0&&d(!0),!h&&A>0&&g(!0),E(Math.max(Math.min(A,window.innerWidth),-window.innerWidth))}},$t=(0,v.useCallback)(()=>{if(L.current=!1,!b)return;let k={onFinish:T};O>innerWidth*.3&&o?R(k):O<-innerWidth*.3&&c?l(k):(x(!0),setTimeout(T,u))},[R,l,b,O,o,c,u]);return(0,C.jsxs)("div",{style:{position:"relative",overflow:"hidden",...t},...n,children:[m>=1&&(b&&h||r&&i.index<m)&&(0,C.jsx)("div",{style:{position:"absolute",inset:0},children:(0,C.jsx)(D,{location:e.at(m-1),children:(0,C.jsx)(Q,{},m-1)})}),(0,C.jsx)("div",{style:{background:"white",position:"absolute",inset:0,transform:r&&i.index<m?"translateX(100%)":b&&O>0&&!P?`translateX(${O}px)`:"translateX(0px)",transition:P||r&&i.index<m?`transform ${u}ms ease-out`:""},onTouchStart:Et,onTouchMove:Ft,onTouchEnd:$t,children:(0,C.jsx)(Q,{})},m),(b&&p||r&&m<=i.index)&&(0,C.jsx)("div",{style:{background:"white",position:"absolute",inset:0,transform:`translateX(${f?"0px":r||P?"100%":`${innerWidth+O}px`})`,transition:`transform ${r||P?u:0}ms ease-in`},children:(0,C.jsx)(D,{location:r?i:e.at(m+1),children:(0,C.jsx)(Q,{},i?.index)})})]})},zt=({rootRoute:t,...n})=>(0,C.jsx)(Nt,{rootRoute:t,children:(0,C.jsx)(Zt,{...n})});0&&(module.exports={DefaultTransitionDuration,Link,LocationContext,LocationProvider,Outlet,RootRouteContext,RouterContext,RouterProvider,Stack,buildPathnameFromMatches,createRouterOptions,matchPattern,matchRoute,parseLocation,parseRoute,redirect,resolveRelativePathname,useLocation,useRootRoute,useRoute,useRouteMatch,useRouter});
|
|
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})=>{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});
|
|
2
2
|
//# 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} 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 transitionDuration: number;\n transitioningToLocation?: Location;\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: (index: number, state: Record<string, any>) => 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, transition, 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({ to, replace, transition, duration, onFinish });\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 getState: (key: string) => any;\n setState: (key: string, value: any) => void;\n deleteState: (key: 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 } 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 getState = useCallback(\n (key: string) => {\n return location.state[key];\n },\n [location]\n );\n const setState = useCallback(\n (key: string, value: any) => {\n router.setLocationState(location.index, {\n ...location.state,\n [key]: value,\n });\n },\n [router, location]\n );\n const deleteState = useCallback(\n (key: string) => {\n delete location.state[key];\n router.setLocationState(location.index, location.state);\n },\n [router, location]\n );\n return (\n <LocationContext.Provider\n value={{\n ...location,\n canGoBack: location.index > 0,\n canGoForward: location.index < router.history.length - 1,\n getState,\n setState,\n deleteState,\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, useState } 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\n const [pending, setPending] = useState(\n !!route?.beforeLoad && route?.getState(pendingStateKey) !== false\n );\n\n useEffect(() => {\n if (!route || depth >= routeMatch.matches.length) {\n return;\n }\n if (pending && route?.beforeLoad) {\n route.setState(pendingStateKey, true);\n route\n .beforeLoad({ location })\n .catch(({ cause }: Error) => {\n if (\"to\" in (cause as any)) {\n router.navigate(cause as any);\n }\n })\n .finally(() => {\n route.setState(pendingStateKey, false);\n setPending(false);\n });\n }\n }, []);\n\n if (!route) {\n return null;\n }\n\n if (depth >= routeMatch.matches.length) {\n const NotFoundComponent = route.notFoundComponent!;\n return <NotFoundComponent />;\n }\n\n if (pending) {\n const PendingComponent = route.pendingComponent!;\n return <PendingComponent />;\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, 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} from \"@/types.js\";\nimport { parseLocation, resolveRelativePathname } 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 = history.at(currentLocationIndex)!;\n const [isTransitioning, setIsTransitioning] = useState<boolean>(false);\n const [transitionDuration, setTransitionDuration] = useState<number>(0);\n const [transitioningToLocation, setTransitioningToLocation] =\n useState<Location>();\n\n useEffect(() => {\n window.history.replaceState(location.state, \"\", location.pathname);\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 pathname = to.startsWith(\"/\")\n ? to\n : resolveRelativePathname(location.pathname, to);\n const state = {\n index,\n };\n return {\n index,\n href: origin + pathname,\n search: {},\n state,\n pathname,\n };\n },\n [currentLocationIndex, location]\n );\n\n // Transition helper\n const transitionTo = (\n location: Location,\n duration: number = options.defaultTransitionDuration,\n callback?: () => void\n ) => {\n setIsTransitioning(true);\n setTransitionDuration(duration);\n setTransitioningToLocation(location);\n setTimeout(() => {\n setIsTransitioning(false);\n setTransitioningToLocation(undefined);\n callback?.();\n }, duration);\n };\n\n // Navigation actions\n const navigate = useCallback(\n ({\n to,\n replace,\n transition,\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 newLocation.pathname\n );\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(newLocation.state, \"\", newLocation.pathname);\n }\n onFinish?.();\n };\n\n if (transition ?? options.defaultUseTransition?.(location, newLocation)) {\n transitionTo(newLocation, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const back = useCallback(\n ({ transition, duration, onFinish, depth }: BackActionOptions = {}) => {\n if (currentLocationIndex === 0 || isTransitioning) return;\n const backDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex - backDepth);\n\n const updateHistory = () => {\n window.history.go(-backDepth);\n onFinish?.();\n };\n\n if (\n newLocation &&\n (transition ?? options.defaultUseTransition?.(location, newLocation))\n ) {\n transitionTo(newLocation, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const forward = useCallback(\n ({ transition, duration, depth, onFinish }: ForwardActionOptions = {}) => {\n if (currentLocationIndex + 1 >= history.length || isTransitioning) return;\n const forwardDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex + forwardDepth);\n\n const updateHistory = () => {\n window.history.go(forwardDepth);\n onFinish?.();\n };\n\n if (\n newLocation &&\n (transition ?? options.defaultUseTransition?.(location, newLocation))\n ) {\n transitionTo(newLocation, 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 (index: number, state: Record<string, any>) => {\n setHistory((prevHistory) =>\n prevHistory.map((location) =>\n location.index === index ? { ...location, state } : location\n )\n );\n if (index === currentLocationIndex) {\n window.history.replaceState(state, \"\", location.pathname);\n }\n },\n [currentLocationIndex]\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: currentLocationIndex > 0,\n canGoForward: currentLocationIndex < history.length - 1,\n\n isTransitioning,\n transitionDuration,\n transitioningToLocation,\n\n buildLocation,\n\n navigate,\n back,\n forward,\n\n setLocationState,\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 ParsedRoute,\n Route,\n RouteMatch,\n RouterOptions,\n} from \"./types.js\";\n\nexport const DefaultTransitionDuration = 300;\n\nexport const redirect = (options: { to: string; replace?: boolean }) => {\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 pathname.\n * @param pathname The base pathname.\n * @param to The relative path to resolve.\n * @returns The resolved absolute pathname.\n */\nexport const resolveRelativePathname = (\n pathname: string,\n to: string\n): string => {\n const currentPathSegments = pathname.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","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\ntype StackComponentProps = React.ComponentPropsWithoutRef<\"div\">;\n\nconst StackComponent: React.FC<StackComponentProps> = ({ style, ...props }) => {\n const {\n history,\n location,\n canGoBack,\n canGoForward,\n isTransitioning,\n transitioningToLocation,\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 [draggedLeft, setDraggedLeft] = useState(false);\n const [draggedRight, setDraggedRight] = 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 setDraggedLeft(false);\n setDraggedRight(false);\n setIsCanceling(false);\n };\n\n const handleTouchStart = (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\n const handleTouchMove = (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 (!draggedLeft && offset < 0) setDraggedLeft(true);\n if (!draggedRight && offset > 0) setDraggedRight(true);\n setDragOffset(\n Math.max(Math.min(offset, window.innerWidth), -window.innerWidth)\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) {\n back(options);\n } else if (dragOffset < -innerWidth * 0.3 && canGoForward) {\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 {currentLocationIndex >= 1 &&\n ((isDragging && draggedRight) ||\n (isTransitioning &&\n transitioningToLocation!.index < currentLocationIndex)) && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n }}\n >\n <LocationProvider location={history.at(currentLocationIndex - 1)!}>\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 &&\n transitioningToLocation!.index < currentLocationIndex\n ? `translateX(100%)`\n : isDragging && dragOffset > 0 && !isCanceling\n ? `translateX(${dragOffset}px)`\n : \"translateX(0px)\",\n transition:\n isCanceling ||\n (isTransitioning &&\n transitioningToLocation!.index < currentLocationIndex)\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n\n {((isDragging && draggedLeft) ||\n (isTransitioning &&\n currentLocationIndex <= transitioningToLocation!.index)) && (\n <div\n style={{\n background: \"white\",\n position: \"absolute\",\n inset: 0,\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 rootRoute: Route;\n}\n\nexport const Stack: React.FC<StackProps> = ({ rootRoute, ...props }) => (\n <RootRouteProvider rootRoute={rootRoute}>\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 { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const PageRenderer = () => {\n const rootRoute = useRootRoute();\n const location = useLocation();\n const routeMatch = matchRoute(rootRoute, location.pathname);\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, useState } from \"react\";\n\nexport const RootRouteProvider = ({\n rootRoute,\n ...props\n}: {\n rootRoute: Route;\n children: React.ReactNode;\n}) => {\n const parsedRoute = parseRoute(rootRoute);\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,wBAAAC,GAAA,iBAAAC,GAAA,eAAAC,GAAA,kBAAAC,GAAA,eAAAC,GAAA,aAAAC,GAAA,4BAAAC,GAAA,gBAAAC,EAAA,iBAAAC,EAAA,aAAAC,GAAA,kBAAAC,EAAA,cAAAC,IAAA,eAAAC,GAAAxB,ICAA,IAAAyB,GAA2B,iBCA3B,IAAAC,GAA8B,iBAsCjBC,KAAgB,kBAAwC,IAAI,EDlClE,IAAMC,EAAY,IAAM,CAC7B,IAAMC,KAAS,eAAWC,CAAa,EACvC,GAAID,IAAW,KACb,MAAM,IAAI,MAAM,uCAAuC,EAEzD,OAAOA,CACT,EERA,IAAAE,GAAqB,iBASfC,GAAA,6BAJOC,MAA4B,SACvC,CAAC,CAAE,GAAAC,EAAI,QAAAC,EAAS,WAAAC,EAAY,SAAAC,EAAU,SAAAC,EAAU,GAAGC,CAAM,IAAM,CAC7D,IAAMC,EAASC,EAAU,EACzB,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cN,CAAU,MACxB,kBACN,WACEM,GACClB,GACCC,EAAyB,MAAQK,EAC/B,aAAaJ,CAAkB,cAC/B,EACR,EACA,aAAcqB,GACd,YAAaE,GACb,WAAYI,GAEZ,mBAACG,EAAA,EAAa,GAvBT1B,CAwBP,GAEGI,GAAcI,GACdd,GACCM,GAAwBL,EAAyB,WACnD,OAAC,OACC,MAAO,CACL,WAAY,QACZ,SAAU,WACV,MAAO,EACP,UAAW,cACTmB,EACI,MACApB,GAAmBkB,EACnB,OACA,GAAG,WAAaN,CAAU,IAChC,IACA,WAAY,aACVZ,GAAmBkB,EAAchB,EAAqB,CACxD,YACF,EAEA,mBAAC6B,EAAA,CACC,SACE/B,EACIC,EACAL,EAAQ,GAAGU,EAAuB,CAAC,EAGzC,mBAAC0B,EAAA,GAAkB/B,GAAyB,KAAO,EACrD,EACF,GAEJ,CAEJ,EAMagC,GAA8B,CAAC,CAAE,UAAAC,EAAW,GAAGvC,CAAM,OAChE,OAACwC,GAAA,CAAkB,UAAWD,EAC5B,mBAACzC,GAAA,CAAgB,GAAGE,EAAO,EAC7B","names":["index_exports","__export","DefaultTransitionDuration","Link","LocationContext","LocationProvider","Outlet","RootRouteContext","RouterContext","RouterProvider","Stack","buildPathnameFromMatches","createRouterOptions","matchPattern","matchRoute","parseLocation","parseRoute","redirect","resolveRelativePathname","useLocation","useRootRoute","useRoute","useRouteMatch","useRouter","__toCommonJS","import_react","import_react","RouterContext","useRouter","router","RouterContext","import_react","import_jsx_runtime","Link","to","replace","transition","duration","onFinish","props","router","useRouter","e","import_react","LocationContext","import_react","import_jsx_runtime","LocationProvider","location","props","router","useRouter","getState","key","setState","value","deleteState","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","setPending","cause","NotFoundComponent","PendingComponent","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","resolveRelativePathname","to","currentPathSegments","toPathSegments","import_jsx_runtime","RouterProvider","options","props","history","setHistory","parseLocation","currentLocationIndex","setCurrentLocationIndex","location","isTransitioning","setIsTransitioning","transitionDuration","setTransitionDuration","transitioningToLocation","setTransitioningToLocation","handlePopState","state","buildLocation","to","replace","index","pathname","resolveRelativePathname","transitionTo","duration","callback","navigate","transition","onFinish","newLocation","updateHistory","prevHistory","back","depth","backDepth","forward","forwardDepth","setLocationState","RouterContext","LocationProvider","import_react","import_jsx_runtime","PageRenderer","rootRoute","useRootRoute","location","useLocation","routeMatch","matchRoute","RouteMatchContext","RouteProvider","RouteComponent","import_react","import_jsx_runtime","RootRouteProvider","rootRoute","props","parsedRoute","parseRoute","state","setState","getRouteState","id","key","setRouteState","value","prevState","RootRouteContext","import_jsx_runtime","StackComponent","style","props","history","location","canGoBack","canGoForward","isTransitioning","transitioningToLocation","transitionDuration","back","forward","useRouter","currentLocationIndex","isTouching","startX","startY","isDragging","setIsDragging","dragOffset","setDragOffset","draggedLeft","setDraggedLeft","draggedRight","setDraggedRight","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","reset","handleTouchStart","e","handleTouchMove","clientX","clientY","offset","handleTouchEnd","options","LocationProvider","PageRenderer","Stack","rootRoute","RootRouteProvider"]}
|
|
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 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,GAAA,eAAAC,GAAA,kBAAAC,GAAA,eAAAC,GAAA,aAAAC,GAAA,uBAAAC,GAAA,gBAAAC,EAAA,iBAAAC,EAAA,aAAAC,GAAA,kBAAAC,EAAA,cAAAC,IAAA,eAAAC,GAAAzB,ICAA,IAAA0B,GAA2B,iBCA3B,IAAAC,GAA8B,iBAiDjBC,KAAgB,kBAAwC,IAAI,ED7ClE,IAAMC,EAAY,IAAM,CAC7B,IAAMC,KAAS,eAAWC,CAAa,EACvC,GAAID,IAAW,KACb,MAAM,IAAI,MAAM,uCAAuC,EAEzD,OAAOA,CACT,EERA,IAAAE,GAAqB,iBASfC,GAAA,6BAJOC,MAA4B,SACvC,CAAC,CAAE,GAAAC,EAAI,QAAAC,EAAS,eAAAC,EAAgB,SAAAC,EAAU,SAAAC,EAAU,GAAGC,CAAM,IAAM,CACjE,IAAMC,EAASC,EAAU,EACzB,SACE,QAAC,KACE,GAAGF,EACJ,KAAML,EACN,QAAUQ,GAAM,CACdA,EAAE,eAAe,EACjBF,EAAO,SAAS,CACd,GAAAN,EACA,QAAAC,EACA,eAAAC,EACA,SAAAC,EACA,SAAAC,CACF,CAAC,CACH,EACF,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CACL,SAAU,WACV,SAAU,SACV,GAAGT,CACL,EACC,GAAGC,EAED,WAAAK,GAAmBE,IAAmB,eACtCS,GAAcM,OACf,OAAC,OAAI,MAAO3B,GACV,mBAAC0C,EAAA,CACC,SACEhC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,mBAAC0B,GAAA,GAAkB1B,EAAuB,CAAG,EAC/C,EACF,KAEF,OAAC,OAEC,MAAO,CACL,WAAY,QACZ,SAAU,WACV,MAAO,EACP,UACEP,GAAmBE,IAAmB,cAClC,mBACAS,GAAcE,EAAa,GAAK,CAACM,EACjC,cAAcN,CAAU,MACxB,kBACN,WACEM,GAAgBnB,GAAmBE,IAAmB,cAClD,aAAaC,CAAkB,cAC/B,EACR,EACA,aAAcqB,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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -31,18 +31,20 @@ interface RouteMatch {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
interface RouterOptions {
|
|
34
|
-
|
|
35
|
-
fromLocation: Location
|
|
36
|
-
toLocation: Location
|
|
37
|
-
) =>
|
|
34
|
+
defaultTransitionType?: (
|
|
35
|
+
fromLocation: Location,
|
|
36
|
+
toLocation: Location
|
|
37
|
+
) => TransitionType;
|
|
38
38
|
/**
|
|
39
39
|
* @default 300
|
|
40
40
|
*/
|
|
41
41
|
defaultTransitionDuration: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
type TransitionType = "slide-left" | "slide-right" | "none" | undefined;
|
|
45
|
+
|
|
44
46
|
interface TransitionOptions {
|
|
45
|
-
|
|
47
|
+
transitionType?: TransitionType;
|
|
46
48
|
duration?: number;
|
|
47
49
|
onFinish?: () => void;
|
|
48
50
|
}
|
|
@@ -75,18 +77,22 @@ declare const RouterProvider: ({ options, ...props }: {
|
|
|
75
77
|
children: React.ReactNode;
|
|
76
78
|
}) => react_jsx_runtime.JSX.Element;
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
interface StackComponentProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
81
|
+
allowSwipeForward?: boolean;
|
|
82
|
+
allowSwipeBack?: boolean;
|
|
83
|
+
}
|
|
79
84
|
interface StackProps extends StackComponentProps {
|
|
80
|
-
|
|
85
|
+
route: Route;
|
|
81
86
|
}
|
|
82
87
|
declare const Stack: React.FC<StackProps>;
|
|
83
88
|
|
|
84
89
|
interface LocationContextType extends Location {
|
|
85
90
|
canGoBack: boolean;
|
|
86
91
|
canGoForward: boolean;
|
|
87
|
-
|
|
92
|
+
state: Record<string, any>;
|
|
88
93
|
setState: (key: string, value: any) => void;
|
|
89
94
|
deleteState: (key: string) => void;
|
|
95
|
+
setSearch: (key: string, value: string) => void;
|
|
90
96
|
}
|
|
91
97
|
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
92
98
|
|
|
@@ -104,13 +110,15 @@ interface RouterContextType {
|
|
|
104
110
|
canGoBack: boolean;
|
|
105
111
|
canGoForward: boolean;
|
|
106
112
|
isTransitioning: boolean;
|
|
107
|
-
transitionDuration: number;
|
|
108
113
|
transitioningToLocation?: Location;
|
|
114
|
+
transitionType?: TransitionType;
|
|
115
|
+
transitionDuration: number;
|
|
109
116
|
buildLocation: (to: NavigationOptions) => Location;
|
|
110
117
|
navigate: (options: NavigateActionOptions) => void;
|
|
111
118
|
back: (options?: BackActionOptions) => void;
|
|
112
119
|
forward: (options?: ForwardActionOptions) => void;
|
|
113
|
-
setLocationState: (index: number, state: Record<string, any>) => void;
|
|
120
|
+
setLocationState: (index: number, state: Record<string, any> | ((prev: Record<string, any>) => Record<string, any>)) => void;
|
|
121
|
+
setLocationSearch: (locationIndex: number, search: Record<string, string>) => void;
|
|
114
122
|
}
|
|
115
123
|
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
116
124
|
|
|
@@ -131,10 +139,7 @@ declare const useRouteMatch: () => RouteMatch;
|
|
|
131
139
|
declare const useRouter: () => RouterContextType;
|
|
132
140
|
|
|
133
141
|
declare const DefaultTransitionDuration = 300;
|
|
134
|
-
declare const redirect: (options:
|
|
135
|
-
to: string;
|
|
136
|
-
replace?: boolean;
|
|
137
|
-
}) => Error;
|
|
142
|
+
declare const redirect: (options: NavigateActionOptions) => Error;
|
|
138
143
|
/**
|
|
139
144
|
* @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.
|
|
140
145
|
* @param url URL to match against the pattern. Can be href or pathname with query string.
|
|
@@ -150,11 +155,12 @@ declare const parseLocation: ({ href, pathname, search, }: globalThis.Location)
|
|
|
150
155
|
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
151
156
|
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
152
157
|
/**
|
|
153
|
-
* Resolves a relative path against a base
|
|
154
|
-
* @param
|
|
158
|
+
* Resolves a relative path against a base url.
|
|
159
|
+
* @param url The base url.
|
|
155
160
|
* @param to The relative path to resolve.
|
|
156
|
-
* @returns The resolved absolute
|
|
161
|
+
* @returns The resolved absolute url.
|
|
157
162
|
*/
|
|
158
|
-
declare const
|
|
163
|
+
declare const resolveRelativeUrl: (url: string, to: string) => string;
|
|
164
|
+
declare const buildUrlFromLocation: (location: Location) => string;
|
|
159
165
|
|
|
160
|
-
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackProps, type TransitionOptions, buildPathnameFromMatches, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect,
|
|
166
|
+
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackComponentProps, type StackProps, type TransitionOptions, type TransitionType, buildPathnameFromMatches, buildUrlFromLocation, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect, resolveRelativeUrl, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,18 +31,20 @@ interface RouteMatch {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
interface RouterOptions {
|
|
34
|
-
|
|
35
|
-
fromLocation: Location
|
|
36
|
-
toLocation: Location
|
|
37
|
-
) =>
|
|
34
|
+
defaultTransitionType?: (
|
|
35
|
+
fromLocation: Location,
|
|
36
|
+
toLocation: Location
|
|
37
|
+
) => TransitionType;
|
|
38
38
|
/**
|
|
39
39
|
* @default 300
|
|
40
40
|
*/
|
|
41
41
|
defaultTransitionDuration: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
type TransitionType = "slide-left" | "slide-right" | "none" | undefined;
|
|
45
|
+
|
|
44
46
|
interface TransitionOptions {
|
|
45
|
-
|
|
47
|
+
transitionType?: TransitionType;
|
|
46
48
|
duration?: number;
|
|
47
49
|
onFinish?: () => void;
|
|
48
50
|
}
|
|
@@ -75,18 +77,22 @@ declare const RouterProvider: ({ options, ...props }: {
|
|
|
75
77
|
children: React.ReactNode;
|
|
76
78
|
}) => react_jsx_runtime.JSX.Element;
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
interface StackComponentProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
81
|
+
allowSwipeForward?: boolean;
|
|
82
|
+
allowSwipeBack?: boolean;
|
|
83
|
+
}
|
|
79
84
|
interface StackProps extends StackComponentProps {
|
|
80
|
-
|
|
85
|
+
route: Route;
|
|
81
86
|
}
|
|
82
87
|
declare const Stack: React.FC<StackProps>;
|
|
83
88
|
|
|
84
89
|
interface LocationContextType extends Location {
|
|
85
90
|
canGoBack: boolean;
|
|
86
91
|
canGoForward: boolean;
|
|
87
|
-
|
|
92
|
+
state: Record<string, any>;
|
|
88
93
|
setState: (key: string, value: any) => void;
|
|
89
94
|
deleteState: (key: string) => void;
|
|
95
|
+
setSearch: (key: string, value: string) => void;
|
|
90
96
|
}
|
|
91
97
|
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
92
98
|
|
|
@@ -104,13 +110,15 @@ interface RouterContextType {
|
|
|
104
110
|
canGoBack: boolean;
|
|
105
111
|
canGoForward: boolean;
|
|
106
112
|
isTransitioning: boolean;
|
|
107
|
-
transitionDuration: number;
|
|
108
113
|
transitioningToLocation?: Location;
|
|
114
|
+
transitionType?: TransitionType;
|
|
115
|
+
transitionDuration: number;
|
|
109
116
|
buildLocation: (to: NavigationOptions) => Location;
|
|
110
117
|
navigate: (options: NavigateActionOptions) => void;
|
|
111
118
|
back: (options?: BackActionOptions) => void;
|
|
112
119
|
forward: (options?: ForwardActionOptions) => void;
|
|
113
|
-
setLocationState: (index: number, state: Record<string, any>) => void;
|
|
120
|
+
setLocationState: (index: number, state: Record<string, any> | ((prev: Record<string, any>) => Record<string, any>)) => void;
|
|
121
|
+
setLocationSearch: (locationIndex: number, search: Record<string, string>) => void;
|
|
114
122
|
}
|
|
115
123
|
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
116
124
|
|
|
@@ -131,10 +139,7 @@ declare const useRouteMatch: () => RouteMatch;
|
|
|
131
139
|
declare const useRouter: () => RouterContextType;
|
|
132
140
|
|
|
133
141
|
declare const DefaultTransitionDuration = 300;
|
|
134
|
-
declare const redirect: (options:
|
|
135
|
-
to: string;
|
|
136
|
-
replace?: boolean;
|
|
137
|
-
}) => Error;
|
|
142
|
+
declare const redirect: (options: NavigateActionOptions) => Error;
|
|
138
143
|
/**
|
|
139
144
|
* @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.
|
|
140
145
|
* @param url URL to match against the pattern. Can be href or pathname with query string.
|
|
@@ -150,11 +155,12 @@ declare const parseLocation: ({ href, pathname, search, }: globalThis.Location)
|
|
|
150
155
|
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
151
156
|
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
152
157
|
/**
|
|
153
|
-
* Resolves a relative path against a base
|
|
154
|
-
* @param
|
|
158
|
+
* Resolves a relative path against a base url.
|
|
159
|
+
* @param url The base url.
|
|
155
160
|
* @param to The relative path to resolve.
|
|
156
|
-
* @returns The resolved absolute
|
|
161
|
+
* @returns The resolved absolute url.
|
|
157
162
|
*/
|
|
158
|
-
declare const
|
|
163
|
+
declare const resolveRelativeUrl: (url: string, to: string) => string;
|
|
164
|
+
declare const buildUrlFromLocation: (location: Location) => string;
|
|
159
165
|
|
|
160
|
-
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackProps, type TransitionOptions, buildPathnameFromMatches, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect,
|
|
166
|
+
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackComponentProps, type StackProps, type TransitionOptions, type TransitionType, buildPathnameFromMatches, buildUrlFromLocation, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect, resolveRelativeUrl, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useContext as Lt}from"react";import{createContext as Ct}from"react";var B=Ct(null);var w=()=>{let t=Lt(B);if(t===null)throw new Error("useRouter must be used within a Stack");return t};import{memo as bt}from"react";import{jsx as wt}from"react/jsx-runtime";var ro=bt(({to:t,replace:r,transition:e,duration:s,onFinish:o,...u})=>{let n=w();return wt("a",{...u,href:t,onClick:i=>{i.preventDefault(),n.navigate({to:t,replace:r,transition:e,duration:s,onFinish:o})}})});import{createContext as Ot}from"react";var G=Ot(null);import{memo as St,useCallback as z}from"react";import{jsx as Tt}from"react/jsx-runtime";var E=St(({location:t,...r})=>{let e=w(),s=z(n=>t.state[n],[t]),o=z((n,i)=>{e.setLocationState(t.index,{...t.state,[n]:i})},[e,t]),u=z(n=>{delete t.state[n],e.setLocationState(t.index,t.state)},[e,t]);return Tt(G.Provider,{value:{...t,canGoBack:t.index>0,canGoForward:t.index<e.history.length-1,getState:s,setState:o,deleteState:u},...r})},(t,r)=>t.location===r.location);import{createContext as kt}from"react";var U=kt(0);import{useContext as Mt}from"react";var ot=()=>Mt(U);import{createContext as At}from"react";var I=At(null);import{useContext as Nt}from"react";var X=()=>{let t=Nt(I);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};import{jsx as Dt}from"react/jsx-runtime";var et=({depth:t,...r})=>Dt(U.Provider,{value:t,...r});import{useContext as Et}from"react";var H=()=>{let t=Et(G);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};import{createContext as Ft}from"react";var F=Ft(null);import{useContext as $t}from"react";var nt=()=>{let t=$t(F);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};import{useEffect as Wt,useState as jt}from"react";import{jsx as q}from"react/jsx-runtime";var Y=({depth:t=0})=>{let r=w(),e=H(),s=X(),o=nt(),u=`_Z.${o.id}.pending`,[n,i]=jt(!!o?.beforeLoad&&o?.getState(u)!==!1);if(Wt(()=>{!o||t>=s.matches.length||n&&o?.beforeLoad&&(o.setState(u,!0),o.beforeLoad({location:e}).catch(({cause:h})=>{"to"in h&&r.navigate(h)}).finally(()=>{o.setState(u,!1),i(!1)}))},[]),!o)return null;if(t>=s.matches.length){let h=o.notFoundComponent;return q(h,{})}if(n){let h=o.pendingComponent;return q(h,{})}let p=o.component;return p?q(p,{}):q(rt,{})};import{useContext as Gt}from"react";import{createContext as Bt}from"react";var _=Bt(null);var K=()=>{let t=Gt(_);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};import{useCallback as it}from"react";import{jsx as st}from"react/jsx-runtime";var V=({route:t,...r})=>{if(!t)return st(F.Provider,{value:null,...r});let{state:e,getRouteState:s,setRouteState:o}=K(),u=it(i=>s(t.id,i),[s,t.id]),n=it((i,p)=>{o(t.id,i,p)},[o,t.id]);return st(F.Provider,{value:{...t,state:e[t.id],getState:u,setState:n},...r})};import{jsx as J}from"react/jsx-runtime";var rt=()=>{let t=X(),r=ot()+1;return J(et,{depth:r,children:J(V,{route:t.matches.at(r),children:J(Y,{depth:r})})})};import{useCallback as $,useEffect as lt,useState as W}from"react";var at={defaultTransitionDuration:300};var Oe=300,Se=t=>new Error("",{cause:t}),Ut=(t,r)=>{try{let e,s;if(r.startsWith("http://")||r.startsWith("https://")){let f=new URL(r);e=f.pathname,s=f.searchParams}else{let[f,d]=r.split("?");if(!f)return null;e=f,s=new URLSearchParams(d||"")}let o=e.replaceAll(/^\/|\/$/g,""),u=t.replaceAll(/^\/|\/$/g,""),n=o.split("/"),i=u.split("/");if(n.length!==i.length)return null;let p={};for(let f=0;f<i.length;f++){let d=i[f],P=n[f];if(d.startsWith(":")){let O=d.slice(1);p[O]=decodeURIComponent(P)}else if(d!==P)return null}let h=Object.fromEntries(s.entries());return{params:p,query:h}}catch{return null}},ut=(t,r)=>{let e=(s,{children:o})=>{if(o&&o.length>0){for(let n of o){let i=e([...s,n],n);if(i)return i}return null}let u=Ut(It(s),r);return u?{matches:s,...u}:null};return e([t],t)||{matches:[],params:{},query:{}}},It=t=>{let r=[];for(let e of t)e.pathname!==void 0&&r.push(e.pathname.replaceAll(/^\/|\/$/g,""));return"/"+r.join("/")},pt=({href:t,pathname:r,search:e})=>({index:0,href:t,state:{index:0},pathname:r,search:Object.fromEntries(new URLSearchParams(e))}),Te=t=>({...at,...t}),mt=t=>{let r=(e,s)=>{let o=e.name??(e.pathname?`${s}/${e.pathname.replaceAll(/^\/|\/$/g,"")}`:s);return{...e,id:o,children:e.children?.map(n=>r(n,o))}};return r(t,"")},ct=t=>t.length>0,dt=(t,r)=>{let e=t.split("/").filter(ct),s=r.split("/").filter(ct);for(let o of s)o!=="."&&(o===".."?e.pop():e.push(o));return"/"+e.join("/")};import{jsx as ft}from"react/jsx-runtime";var Fe=({options:t,...r})=>{let[e,s]=W([pt(window.location)]),[o,u]=W(0),n=e.at(o),[i,p]=W(!1),[h,f]=W(0),[d,P]=W();lt(()=>{window.history.replaceState(n.state,"",n.pathname)},[]),lt(()=>{let m=({state:l})=>{u(l?.index)};return addEventListener("popstate",m),()=>{removeEventListener("popstate",m)}},[o]);let O=$(({to:m,replace:l})=>{if(!m)return n;let g=l?o:o+1,x=m.startsWith("/")?m:dt(n.pathname,m),v={index:g};return{index:g,href:origin+x,search:{},state:v,pathname:x}},[o,n]),k=(m,l=t.defaultTransitionDuration,g)=>{p(!0),f(l),P(m),setTimeout(()=>{p(!1),P(void 0),g?.()},l)},L=$(({to:m,replace:l,transition:g,duration:x,onFinish:v})=>{if(i)return;let y=l?o:o+1,R=O({to:m,replace:l}),D=()=>{l?(s(S=>[...S.slice(0,y),R,...S.slice(y+1)]),window.history.replaceState(R.state,"",R.pathname)):(s(S=>[...S.slice(0,y),R]),u(y),window.history.pushState(R.state,"",R.pathname)),v?.()};g??t.defaultUseTransition?.(n,R)?k(R,x,D):D()},[o,e,i,t]),j=$(({transition:m,duration:l,onFinish:g,depth:x}={})=>{if(o===0||i)return;let v=x??1,y=e.at(o-v),R=()=>{window.history.go(-v),g?.()};y&&(m??t.defaultUseTransition?.(n,y))?k(y,l,R):R()},[o,e,i,t]),b=$(({transition:m,duration:l,depth:g,onFinish:x}={})=>{if(o+1>=e.length||i)return;let v=g??1,y=e.at(o+v),R=()=>{window.history.go(v),x?.()};y&&(m??t.defaultUseTransition?.(n,y))?k(y,l,R):R()},[o,e,i,t]),N=$((m,l)=>{s(g=>g.map(x=>x.index===m?{...x,state:l}:x)),m===o&&window.history.replaceState(l,"",n.pathname)},[o]);return ft(B.Provider,{value:{options:t,history:e,location:n,canGoBack:o>0,canGoForward:o<e.length-1,isTransitioning:i,transitionDuration:h,transitioningToLocation:d,buildLocation:O,navigate:L,back:j,forward:b,setLocationState:N},children:ft(E,{location:n,...r})})};import{useCallback as qt,useEffect as Yt,useRef as tt,useState as A}from"react";import{jsx as Q}from"react/jsx-runtime";var Z=()=>{let t=K(),r=H(),e=ut(t,r.pathname);return Q(I.Provider,{value:e,children:Q(V,{route:t,children:Q(Y,{})})})};import{useCallback as Rt,useState as Xt}from"react";import{jsx as Ht}from"react/jsx-runtime";var ht=({rootRoute:t,...r})=>{let e=mt(t),[s,o]=Xt({}),u=Rt((i,p)=>s[i]?.[p],[s]),n=Rt((i,p,h)=>{o(f=>({...f,[i]:{...f[i],[p]:h}}))},[]);return Ht(_.Provider,{value:{...e,state:s,getRouteState:u,setRouteState:n},...r})};import{jsx as C,jsxs as Kt}from"react/jsx-runtime";var _t=({style:t,...r})=>{let{history:e,location:s,canGoBack:o,canGoForward:u,isTransitioning:n,transitioningToLocation:i,transitionDuration:p,back:h,forward:f}=w(),d=s.index,P=tt(!1),O=tt(0),k=tt(0),[L,j]=A(!1),[b,N]=A(0),[m,l]=A(!1),[g,x]=A(!1),[v,y]=A(!1),[R,D]=A(!1);if(Yt(()=>{!n||!i||(D(!0),setTimeout(()=>{D(!1)},p))},[n,i,p]),d===void 0)return;let S=()=>{j(!1),N(0),l(!1),x(!1),y(!1)},gt=T=>{n||!u&&!o||(P.current=!0,O.current=T.touches[0].clientX,k.current=T.touches[0].clientY)},xt=T=>{if(!P.current)return;let{clientX:vt,clientY:Pt}=T.touches[0];if(!L&&Math.abs(Pt-k.current)>30){P.current=!1;return}let M=vt-O.current;if(!(Math.abs(M)<10)){if(L||j(!0),M>0&&d===0||M<0&&d+1===e.length){N(0);return}!m&&M<0&&l(!0),!g&&M>0&&x(!0),N(Math.max(Math.min(M,window.innerWidth),-window.innerWidth))}},yt=qt(()=>{if(P.current=!1,!L)return;let T={onFinish:S};b>innerWidth*.3&&o?h(T):b<-innerWidth*.3&&u?f(T):(y(!0),setTimeout(S,p))},[h,f,L,b,o,u,p]);return Kt("div",{style:{position:"relative",overflow:"hidden",...t},...r,children:[d>=1&&(L&&g||n&&i.index<d)&&C("div",{style:{position:"absolute",inset:0},children:C(E,{location:e.at(d-1),children:C(Z,{},d-1)})}),C("div",{style:{background:"white",position:"absolute",inset:0,transform:n&&i.index<d?"translateX(100%)":L&&b>0&&!v?`translateX(${b}px)`:"translateX(0px)",transition:v||n&&i.index<d?`transform ${p}ms ease-out`:""},onTouchStart:gt,onTouchMove:xt,onTouchEnd:yt,children:C(Z,{})},d),(L&&m||n&&d<=i.index)&&C("div",{style:{background:"white",position:"absolute",inset:0,transform:`translateX(${R?"0px":n||v?"100%":`${innerWidth+b}px`})`,transition:`transform ${n||v?p:0}ms ease-in`},children:C(E,{location:n?i:e.at(d+1),children:C(Z,{},i?.index)})})]})},sn=({rootRoute:t,...r})=>C(ht,{rootRoute:t,children:C(_t,{...r})});export{Oe as DefaultTransitionDuration,ro as Link,G as LocationContext,E as LocationProvider,rt as Outlet,_ as RootRouteContext,B as RouterContext,Fe as RouterProvider,sn as Stack,It as buildPathnameFromMatches,Te as createRouterOptions,Ut as matchPattern,ut as matchRoute,pt as parseLocation,mt as parseRoute,Se as redirect,dt as resolveRelativePathname,H as useLocation,K as useRootRoute,nt as useRoute,X as useRouteMatch,w as useRouter};
|
|
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})=>{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};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|