@modastar/z-router 0.0.8 → 0.0.10
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/.oxlintrc.json +24 -0
- package/.vscode/settings.json +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -20
- package/dist/index.d.ts +34 -20
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/example/README.md +3 -0
- 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/example/package.json +10 -2
- package/example/pnpm-lock.yaml +3967 -564
- package/package.json +3 -2
package/.oxlintrc.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
"import",
|
|
4
|
+
"typescript",
|
|
5
|
+
"unicorn",
|
|
6
|
+
"vitest",
|
|
7
|
+
"oxc",
|
|
8
|
+
"eslint",
|
|
9
|
+
"react",
|
|
10
|
+
"react-perf"
|
|
11
|
+
],
|
|
12
|
+
"categories": {
|
|
13
|
+
"correctness": "error",
|
|
14
|
+
"suspicious": "warn",
|
|
15
|
+
"perf": "warn"
|
|
16
|
+
},
|
|
17
|
+
"env": {
|
|
18
|
+
"browser": true
|
|
19
|
+
},
|
|
20
|
+
"rules": {
|
|
21
|
+
"react/react-in-jsx-scope": "off",
|
|
22
|
+
"react/exhaustive-deps": "off"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var tt=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var $t=Object.prototype.hasOwnProperty;var Bt=(t,n)=>{for(var o in n)tt(t,o,{get:n[o],enumerable:!0})},Gt=(t,n,o,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of Nt(n))!$t.call(t,e)&&e!==o&&tt(t,e,{get:()=>n[e],enumerable:!(s=Ft(n,e))||s.enumerable});return t};var It=t=>Gt(tt({},"__esModule",{value:!0}),t);var zt={};Bt(zt,{DefaultTransitionDuration:()=>Wt,Link:()=>Xt,LocationContext:()=>$,LocationProvider:()=>E,Outlet:()=>ot,RootRouteContext:()=>X,RouterContext:()=>N,RouterProvider:()=>qt,Stack:()=>Ht,buildPathnameFromMatches:()=>kt,createRouterOptions:()=>Ut,matchPattern:()=>Tt,matchRoute:()=>it,parseLocation:()=>st,parseRoute:()=>at,redirect:()=>jt,useLocation:()=>B,useRootRoute:()=>W,useRoute:()=>et,useRouter:()=>w});module.exports=It(zt);var mt=require("react");var pt=require("react"),N=(0,pt.createContext)(null);var w=()=>{let t=(0,mt.useContext)(N);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var dt=require("react/jsx-runtime"),Xt=({to:t,replace:n,transition:o,duration:s,onFinish:e,...r})=>{let i=w();return(0,dt.jsx)("a",{...r,href:t,onClick:u=>{u.preventDefault(),i.navigate({to:t,replace:n,transition:o,duration:s,onFinish:e})}})};var lt=require("react"),$=(0,lt.createContext)(null);var q=require("react"),ft=require("react/jsx-runtime"),E=({location:t,...n})=>{let o=w(),s=(0,q.useCallback)(i=>t.state[i],[t]),e=(0,q.useCallback)((i,u)=>{o.setLocationState(t.index,{...t.state,[i]:u})},[o,t]),r=(0,q.useCallback)(i=>{delete t.state[i],o.setLocationState(t.index,t.state)},[o,t]);return(0,ft.jsx)($.Provider,{value:{...t,canGoBack:t.index>0,canGoForward:t.index<o.history.length-1,getState:s,setState:e,deleteState:r},...n})};var Rt=require("react"),A=(0,Rt.createContext)(0);var ht=require("react"),gt=()=>(0,ht.useContext)(A);var xt=require("react"),H=(0,xt.createContext)(null);var yt=require("react"),z=()=>{let t=(0,yt.useContext)(H);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var Pt=require("react/jsx-runtime"),vt=({depth:t,...n})=>(0,Pt.jsx)(A.Provider,{value:t,...n});var Ct=require("react");var B=()=>{let t=(0,Ct.useContext)($);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var Lt=require("react"),G=(0,Lt.createContext)(null);var wt=require("react"),et=()=>{let t=(0,wt.useContext)(G);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var _=require("react");var I=require("react/jsx-runtime"),K=({depth:t=0})=>{let n=w(),o=B(),s=z(),e=et(),r=`_Z.${e.id}.pending`,[i,u]=(0,_.useState)(!!e?.beforeLoad&&e?.getState(r)!==!1);if((0,_.useEffect)(()=>{!e||t>=s.matches.length||i&&e?.beforeLoad&&(e.setState(r,!0),e.beforeLoad({location:o}).catch(({cause:c})=>{"to"in c&&n.navigate(c)}).finally(()=>{e.setState(r,!1),u(!1)}))},[]),!e)return null;if(t>=s.matches.length){let c=e.notFoundComponent;return(0,I.jsx)(c,{})}if(i){let c=e.pendingComponent;return(0,I.jsx)(c,{})}let l=e.component;return l?(0,I.jsx)(l,{}):(0,I.jsx)(ot,{})};var St=require("react");var bt=require("react"),X=(0,bt.createContext)(null);var W=()=>{let t=(0,St.useContext)(X);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 o=W(),s=(0,nt.useCallback)(r=>o.getRouteState(t.id,r),[o.getRouteState]),e=(0,nt.useCallback)((r,i)=>{o.setRouteState(t.id,r,i)},[o.setRouteState]);return(0,rt.jsx)(G.Provider,{value:{...t,getState:s,setState:e},...n})};var J=require("react/jsx-runtime"),ot=()=>{let t=z(),n=gt()+1;return(0,J.jsx)(vt,{depth:n,children:(0,J.jsx)(Z,{route:t.matches.at(n),children:(0,J.jsx)(K,{depth:n})})})};var g=require("react");var Ot={defaultTransitionDuration:300};var Wt=300,jt=t=>new Error("",{cause:t}),Tt=(t,n)=>{try{let o,s;if(n.startsWith("http://")||n.startsWith("https://")){let m=new URL(n);o=m.pathname,s=m.searchParams}else{let[m,f]=n.split("?");if(!m)return null;o=m,s=new URLSearchParams(f||"")}let e=o.replaceAll(/^\/|\/$/g,""),r=t.replaceAll(/^\/|\/$/g,""),i=e.split("/"),u=r.split("/");if(i.length!==u.length)return null;let l={};for(let m=0;m<u.length;m++){let f=u[m],b=i[m];if(f.startsWith(":")){let T=f.slice(1);l[T]=decodeURIComponent(b)}else if(f!==b)return null}let c=Object.fromEntries(s.entries());return{params:l,query:c}}catch{return null}},it=(t,n)=>{let o=(s,{children:e})=>{if(e&&e.length>0){for(let i of e){let u=o([...s,i],i);if(u)return u}return null}let r=Tt(kt(s),n);return r?{matches:s,...r}:null};return o([t],t)||{matches:[],params:{},query:{}}},kt=t=>{let n=[];for(let o of t)o.pathname!==void 0&&n.push(o.pathname.replaceAll(/^\/|\/$/g,""));return"/"+n.join("/")},st=t=>({index:0,state:{index:0},pathname:t.pathname,search:Object.fromEntries(new URLSearchParams(t.search))}),Ut=t=>({...Ot,...t}),at=t=>{let n=(o,s)=>{let e=o.name??(o.pathname?`${s}/${o.pathname.replaceAll(/^\/|\/$/g,"")}`:s);return{...o,id:e,children:o.children?.map(i=>n(i,e))}};return n(t,"")};var ut=require("react/jsx-runtime"),qt=({options:t,...n})=>{let[o,s]=(0,g.useState)([st(window.location)]),[e,r]=(0,g.useState)(0),i=o.at(e),[u,l]=(0,g.useState)(!1),[c,m]=(0,g.useState)(0),[f,b]=(0,g.useState)();(0,g.useEffect)(()=>{window.history.replaceState(o[0].state,"",o[0].pathname);let p=({state:d})=>{r(d?.index??0)};return addEventListener("popstate",p),()=>{removeEventListener("popstate",p)}},[]);let T=(p,d=t.defaultTransitionDuration,y)=>{l(!0),m(d),b(p),setTimeout(()=>{l(!1),b(void 0),r(p.index),y?.()},d)},Y=(0,g.useCallback)((p,d)=>{s(y=>y.map(h=>h.index===p?{...h,state:d}:h)),p===e&&window.history.replaceState(d,"",i.pathname)},[e]),P=(0,g.useCallback)(({to:p,replace:d,transition:y,duration:h,onFinish:C,...v})=>{if(u)return;let R=d?e:e+1,L;if(p.startsWith("/"))L=p;else{let S=i.pathname.split("/").filter(M=>M.length>0),Dt=p.split("/").filter(M=>M.length>0);for(let M of Dt)M!=="."&&(M===".."?S.pop():S.push(M));L="/"+S.join("/")}let k={index:R},U={index:R,search:{},state:k,pathname:L,...v},ct=()=>{d?(s(S=>[...S.slice(0,R),U,...S.slice(R+1)]),window.history.replaceState(k,"",L)):(s(S=>[...S.slice(0,R),U]),r(R),window.history.pushState(k,"",L)),C?.()};y??t.defaultUseTransition?.(i,U)?T(U,h,ct):ct()},[e,o,u,t]),D=(0,g.useCallback)(({transition:p,duration:d,onFinish:y,depth:h}={})=>{if(e===0||u)return;let C=h??1,v=o.at(e-C),R=()=>{window.history.go(-C),y?.()};v&&(p??t.defaultUseTransition?.(i,v))?T(v,d,R):R()},[e,o,u,t]),F=(0,g.useCallback)(({transition:p,duration:d,depth:y,onFinish:h}={})=>{if(e+1>=o.length||u)return;let C=y??1,v=o.at(e+C),R=()=>{window.history.go(C),h?.()};v&&(p??t.defaultUseTransition?.(i,v))?T(v,d,R):R()},[e,o,u,t]);return(0,ut.jsx)(N.Provider,{value:{options:t,history:o,location:i,canGoBack:e>0,canGoForward:e<o.length-1,isTransitioning:u,transitionDuration:c,transitioningToLocation:f,navigate:P,back:D,forward:F,setLocationState:Y},children:(0,ut.jsx)(E,{location:i,...n})})};var O=require("react");var Q=require("react/jsx-runtime"),V=()=>{let t=W(),n=B(),o=it(t,n.pathname);return(0,Q.jsx)(H.Provider,{value:o,children:(0,Q.jsx)(Z,{route:t,children:(0,Q.jsx)(K,{})})})};var j=require("react"),Et=require("react/jsx-runtime"),Mt=({rootRoute:t,...n})=>{let o=at(t),[s,e]=(0,j.useState)({}),r=(0,j.useCallback)((u,l)=>s[u]?.[l],[s]),i=(0,j.useCallback)((u,l,c)=>{e(m=>({...m,[u]:{...m[u],[l]:c}}))},[]);return(0,Et.jsx)(X.Provider,{value:{...o,getRouteState:r,setRouteState:i},...n})};var x=require("react/jsx-runtime"),At=()=>{let{history:t,location:n,canGoBack:o,canGoForward:s,isTransitioning:e,transitioningToLocation:r,transitionDuration:i,back:u,forward:l}=w(),c=n?.index,m=r?.index,[f,b]=(0,O.useState)(!1),[T,Y]=(0,O.useState)(0),[P,D]=(0,O.useState)(0),[F,p]=(0,O.useState)(!1),[d,y]=(0,O.useState)(!1);if((0,O.useEffect)(()=>{!e||!r||(y(!0),setTimeout(()=>{y(!1)},i))},[e,r]),c===void 0)return;let h=()=>{b(!1),D(0),p(!1)},C=L=>{e||!s&&!o||(b(!0),Y(L.touches[0].clientX))},v=L=>{if(!f)return;let k=L.touches[0].clientX-T;if(k>0&&c===0||k<0&&c+1===t.length){D(0);return}D(Math.min(innerWidth,k))},R=()=>{f&&(P>innerWidth*.3&&o?u({onFinish:h}):P<-innerWidth*.3&&s?l({onFinish:h}):(p(!0),setTimeout(h,i)))};return(0,x.jsxs)("div",{style:{position:"relative",inset:0,height:"100%",width:"100%",overflow:"hidden"},children:[c>=1&&(f&&P>0||e&&r&&r.index<c)&&(0,x.jsx)("div",{style:{position:"absolute",inset:0,zIndex:-10},children:(0,x.jsx)(E,{location:t.at(c-1),children:(0,x.jsx)(V,{},c-1)})}),(0,x.jsx)("div",{style:{background:"white",position:"absolute",inset:0,overflow:"hidden",transform:e&&r&&r.index<c?"translateX(100%)":f&&P>0&&!F?`translateX(${P}px)`:"translateX(0px)",transition:F||e&&r&&r.index<c?`transform ${i}ms ease-out`:"",boxShadow:f&&P>0?"-4px 0 8px rgba(0,0,0,0.1)":"none"},onTouchStart:C,onTouchMove:v,onTouchEnd:R,children:(0,x.jsx)(V,{})},c),(f&&P<0||e&&r&&c<=r.index)&&(0,x.jsx)("div",{style:{background:"white",position:"absolute",inset:0,zIndex:10,overflow:"hidden",transition:"transform ease-in",transform:d?"translateX(0px)":e?"translateX(100%)":`translateX(${innerWidth+P}px)`,transitionDuration:e||F?`${i}ms`:"0ms"},children:(0,x.jsx)(E,{location:e?r:t.at(c+1),children:(0,x.jsx)(V,{},m)})})]})},Ht=({rootRoute:t})=>(0,x.jsx)(Mt,{rootRoute:t,children:(0,x.jsx)(At,{})});0&&(module.exports={DefaultTransitionDuration,Link,LocationContext,LocationProvider,Outlet,RootRouteContext,RouterContext,RouterProvider,Stack,buildPathnameFromMatches,createRouterOptions,matchPattern,matchRoute,parseLocation,parseRoute,redirect,useLocation,useRootRoute,useRoute,useRouter});
|
|
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.getState(c)!==!0&&(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]),!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});
|
|
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 BackOptions,\n ForwardOptions,\n Location,\n NavigateOptions,\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 // Actions\n navigate: (options: NavigateOptions) => void;\n back: (options?: BackOptions) => void;\n forward: (options?: ForwardOptions) => 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 { NavigateOptions } from \"@/types.js\";\n\nexport type LinkProps = React.ComponentPropsWithoutRef<\"a\"> & NavigateOptions;\n\nexport const Link: React.FC<LinkProps> = ({\n to,\n replace,\n transition,\n duration,\n onFinish,\n ...props\n}) => {\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","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 { useCallback } from \"react\";\n\nexport const LocationProvider = ({\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","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 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 // TODO: push location still loading. Maybe store state in route () instead of location\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 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 rootRoute = useRootRoute();\n\n const getState = useCallback(\n (key: string) => {\n return rootRoute.getRouteState(route.id, key);\n },\n [rootRoute.getRouteState]\n );\n\n const setState = useCallback(\n (key: string, value: any) => {\n rootRoute.setRouteState(route.id, key, value);\n },\n [rootRoute.setRouteState]\n );\n\n return (\n <RouteContext.Provider\n value={{ ...route, 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 BackOptions,\n ForwardOptions,\n Location,\n NavigateOptions,\n RouterOptions,\n} from \"@/types.js\";\nimport { parseLocation } 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(history[0].state, \"\", history[0].pathname);\n const handlePopState = ({ state }: PopStateEvent) => {\n setCurrentLocationIndex(state?.index ?? 0);\n };\n\n addEventListener(\"popstate\", handlePopState);\n return () => {\n removeEventListener(\"popstate\", handlePopState);\n };\n }, []);\n\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 // TODO: May can be deleted\n setCurrentLocationIndex(location.index);\n callback?.();\n }, duration);\n };\n\n // Update location state\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 const navigate = useCallback(\n ({\n to,\n replace,\n transition,\n duration,\n onFinish,\n ...locationOptions\n }: NavigateOptions) => {\n if (isTransitioning) return;\n\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n\n // Resolve to with absolute or relative paths like \"..\" or \".\"\n // TODO: Wrap into a utility function\n let pathname: string;\n if (to.startsWith(\"/\")) {\n pathname = to;\n } else {\n const currentPathSegments = location.pathname\n .split(\"/\")\n .filter((seg) => seg.length > 0);\n const toPathSegments = to.split(\"/\").filter((seg) => seg.length > 0);\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 pathname = \"/\" + currentPathSegments.join(\"/\");\n }\n const state = {\n index,\n };\n const newLocation = {\n index,\n search: {},\n state,\n pathname,\n ...locationOptions,\n };\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(state, \"\", pathname);\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(state, \"\", 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 }: BackOptions = {}) => {\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 }: ForwardOptions = {}) => {\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 return (\n <RouterContext.Provider\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 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 = (location: globalThis.Location): Location => ({\n index: 0,\n state: {\n index: 0,\n },\n pathname: location.pathname,\n search: Object.fromEntries(new URLSearchParams(location.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","import { useEffect, 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 StackComponent = () => {\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 const transitioningToLocationIndex = transitioningToLocation?.index;\n\n const [isDragging, setIsDragging] = useState(false);\n const [startX, setStartX] = useState(0);\n const [dragOffset, setDragOffset] = useState(0);\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]);\n\n if (currentLocationIndex === undefined) return;\n\n const reset = () => {\n setIsDragging(false);\n setDragOffset(0);\n setIsCanceling(false);\n };\n\n const handleTouchStart = (e: React.TouchEvent) => {\n if (isTransitioning || (!canGoForward && !canGoBack)) return;\n setIsDragging(true);\n setStartX(e.touches[0].clientX);\n };\n\n const handleTouchMove = (e: React.TouchEvent) => {\n if (!isDragging) return;\n const offset = e.touches[0].clientX - startX;\n if (\n (offset > 0 && currentLocationIndex === 0) ||\n (offset < 0 && currentLocationIndex + 1 === history.length)\n ) {\n setDragOffset(0);\n return;\n }\n setDragOffset(Math.min(innerWidth, offset));\n };\n\n const handleTouchEnd = () => {\n if (!isDragging) return;\n\n if (dragOffset > innerWidth * 0.3 && canGoBack) {\n back({\n onFinish: reset,\n });\n } else if (dragOffset < -innerWidth * 0.3 && canGoForward) {\n forward({\n onFinish: reset,\n });\n } else {\n setIsCanceling(true);\n setTimeout(reset, transitionDuration);\n }\n };\n\n return (\n <div\n style={{\n position: \"relative\",\n inset: 0,\n height: \"100%\",\n width: \"100%\",\n overflow: \"hidden\",\n }}\n >\n {currentLocationIndex >= 1 &&\n ((isDragging && dragOffset > 0) ||\n (isTransitioning &&\n transitioningToLocation &&\n transitioningToLocation.index < currentLocationIndex)) && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: -10,\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 overflow: \"hidden\",\n transform:\n isTransitioning &&\n transitioningToLocation &&\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 &&\n transitioningToLocation.index < currentLocationIndex)\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n boxShadow:\n isDragging && dragOffset > 0\n ? \"-4px 0 8px rgba(0,0,0,0.1)\"\n : \"none\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n {((isDragging && dragOffset < 0) ||\n (isTransitioning &&\n transitioningToLocation &&\n currentLocationIndex <= transitioningToLocation.index)) && (\n <div\n style={{\n background: \"white\",\n position: \"absolute\",\n inset: 0,\n zIndex: 10,\n overflow: \"hidden\",\n transition: \"transform ease-in\",\n transform: isTransitionStarted\n ? `translateX(0px)`\n : isTransitioning\n ? \"translateX(100%)\"\n : `translateX(${innerWidth + dragOffset}px)`,\n transitionDuration:\n isTransitioning || isCanceling\n ? `${transitionDuration}ms`\n : \"0ms\",\n }}\n >\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex + 1)!\n }\n >\n <PageRenderer key={transitioningToLocationIndex} />\n </LocationProvider>\n </div>\n )}\n </div>\n );\n};\n\nexport const Stack = ({ rootRoute }: { rootRoute: Route }) => (\n <RootRouteProvider rootRoute={rootRoute}>\n <StackComponent />\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, 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,gBAAAC,EAAA,iBAAAC,EAAA,aAAAC,GAAA,cAAAC,IAAA,eAAAC,GAAAtB,ICAA,IAAAuB,GAA2B,iBCA3B,IAAAC,GAA8B,iBAkCjBC,KAAgB,kBAAwC,IAAI,ED9BlE,IAAMC,EAAY,IAAM,CAC7B,IAAMC,KAAS,eAAWC,CAAa,EACvC,GAAID,IAAW,KACb,MAAM,IAAI,MAAM,uCAAuC,EAEzD,OAAOA,CACT,EEKI,IAAAE,GAAA,6BAVSC,GAA4B,CAAC,CACxC,GAAAC,EACA,QAAAC,EACA,WAAAC,EACA,SAAAC,EACA,SAAAC,EACA,GAAGC,CACL,IAAM,CACJ,IAAMC,EAASC,EAAU,EACzB,SACE,QAAC,KACE,GAAGF,EACJ,KAAML,EACN,QAAUQ,GAAM,CACdA,EAAE,eAAe,EACjBF,EAAO,SAAS,CAAE,GAAAN,EAAI,QAAAC,EAAS,WAAAC,EAAY,SAAAC,EAAU,SAAAC,CAAS,CAAC,CACjE,EACF,CAEJ,ECxBA,IAAAK,GAA8B,iBAYjBC,KAAkB,kBAA0C,IAAI,ECT7E,IAAAC,EAA4B,iBAiCxBC,GAAA,6BA/BSC,EAAmB,CAAC,CAC/B,SAAAC,EACA,GAAGC,CACL,IAGM,CACJ,IAAMC,EAASC,EAAU,E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,QACZ,SAAU,WACV,MAAO,EACP,OAAQ,GACR,SAAU,SACV,WAAY,oBACZ,UAAWe,EACP,kBACAhB,EACA,mBACA,cAAc,WAAaY,CAAU,MACzC,mBACEZ,GAAmBc,EACf,GAAGZ,CAAkB,KACrB,KACR,EAEA,mBAACsB,EAAA,CACC,SACExB,EACIC,EACAL,EAAQ,GAAGU,EAAuB,CAAC,EAGzC,mBAACmB,EAAA,GAAkBlB,CAA8B,EACnD,EACF,GAEJ,CAEJ,EAEamB,GAAQ,CAAC,CAAE,UAAAC,CAAU,OAChC,OAACC,GAAA,CAAkB,UAAWD,EAC5B,mBAAChC,GAAA,EAAe,EAClB","names":["index_exports","__export","DefaultTransitionDuration","Link","LocationContext","LocationProvider","Outlet","RootRouteContext","RouterContext","RouterProvider","Stack","buildPathnameFromMatches","createRouterOptions","matchPattern","matchRoute","parseLocation","parseRoute","redirect","useLocation","useRootRoute","useRoute","useRouter","__toCommonJS","import_react","import_react","RouterContext","useRouter","router","RouterContext","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","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","rootRoute","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","location","createRouterOptions","DefaultRouterOptions","parseRoute","parseRouteRecursive","parentId","id","child","import_jsx_runtime","RouterProvider","options","props","history","setHistory","parseLocation","currentLocationIndex","setCurrentLocationIndex","location","isTransitioning","setIsTransitioning","transitionDuration","setTransitionDuration","transitioningToLocation","setTransitioningToLocation","handlePopState","state","transitionTo","duration","callback","setLocationState","index","prevHistory","navigate","to","replace","transition","onFinish","locationOptions","pathname","currentPathSegments","seg","toPathSegments","segment","newLocation","updateHistory","back","depth","backDepth","forward","forwardDepth","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","history","location","canGoBack","canGoForward","isTransitioning","transitioningToLocation","transitionDuration","back","forward","useRouter","currentLocationIndex","transitioningToLocationIndex","isDragging","setIsDragging","startX","setStartX","dragOffset","setDragOffset","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","reset","handleTouchStart","e","handleTouchMove","offset","handleTouchEnd","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} 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 (\n pending &&\n route?.beforeLoad &&\n route.getState(pendingStateKey) !== true\n ) {\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 }, [route]);\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,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,CAAiB,SAAUnC,EAAQ,GAAGU,EAAuB,CAAC,EAC7D,mBAAC0B,EAAA,GAAkB1B,EAAuB,CAAG,EAC/C,EACF,KAEJ,OAAC,OAEC,MAAO,CACL,WAAY,QACZ,SAAU,WACV,MAAO,EACP,UACEN,GACAC,EAAyB,MAAQK,EAC7B,mBACAI,GAAcE,EAAa,GAAK,CAACM,EACjC,cAAcN,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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import * as react from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
interface Route {
|
|
5
5
|
name?: string;
|
|
@@ -18,6 +18,7 @@ interface ParsedRoute extends Route {
|
|
|
18
18
|
|
|
19
19
|
interface Location {
|
|
20
20
|
index: number;
|
|
21
|
+
href: string;
|
|
21
22
|
pathname: string;
|
|
22
23
|
search: Record<string, string>;
|
|
23
24
|
state: Record<string, any>;
|
|
@@ -46,27 +47,26 @@ interface TransitionOptions {
|
|
|
46
47
|
onFinish?: () => void;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
interface NavigationOptions {
|
|
50
51
|
to: string;
|
|
51
52
|
replace?: boolean;
|
|
52
|
-
|
|
53
|
-
} & TransitionOptions;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
interface HistoryTraversalOptions {
|
|
56
56
|
depth?: number;
|
|
57
|
-
}
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
type
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
type NavigateActionOptions = TransitionOptions & NavigationOptions;
|
|
60
|
+
type BackActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
61
|
+
type ForwardActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
62
62
|
|
|
63
|
-
type LinkProps = React.ComponentPropsWithoutRef<"a"> &
|
|
63
|
+
type LinkProps = React.ComponentPropsWithoutRef<"a"> & NavigateActionOptions;
|
|
64
64
|
declare const Link: React.FC<LinkProps>;
|
|
65
65
|
|
|
66
|
-
declare const LocationProvider: ({ location, ...props }: {
|
|
66
|
+
declare const LocationProvider: react.MemoExoticComponent<({ location, ...props }: {
|
|
67
67
|
location: Location;
|
|
68
68
|
children: React.ReactNode;
|
|
69
|
-
}) => react_jsx_runtime.JSX.Element
|
|
69
|
+
}) => react_jsx_runtime.JSX.Element>;
|
|
70
70
|
|
|
71
71
|
declare const Outlet: () => react_jsx_runtime.JSX.Element;
|
|
72
72
|
|
|
@@ -75,9 +75,11 @@ declare const RouterProvider: ({ options, ...props }: {
|
|
|
75
75
|
children: React.ReactNode;
|
|
76
76
|
}) => react_jsx_runtime.JSX.Element;
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
type StackComponentProps = React.ComponentPropsWithoutRef<"div">;
|
|
79
|
+
interface StackProps extends StackComponentProps {
|
|
79
80
|
rootRoute: Route;
|
|
80
|
-
}
|
|
81
|
+
}
|
|
82
|
+
declare const Stack: React.FC<StackProps>;
|
|
81
83
|
|
|
82
84
|
interface LocationContextType extends Location {
|
|
83
85
|
canGoBack: boolean;
|
|
@@ -89,6 +91,7 @@ interface LocationContextType extends Location {
|
|
|
89
91
|
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
90
92
|
|
|
91
93
|
interface RootRouteContextType extends ParsedRoute {
|
|
94
|
+
state: Record<string, Record<string, any>>;
|
|
92
95
|
getRouteState: (id: string, key: string) => any;
|
|
93
96
|
setRouteState: (id: string, key: string, value: any) => void;
|
|
94
97
|
}
|
|
@@ -97,15 +100,16 @@ declare const RootRouteContext: react.Context<RootRouteContextType | null>;
|
|
|
97
100
|
interface RouterContextType {
|
|
98
101
|
options: RouterOptions;
|
|
99
102
|
history: Location[];
|
|
100
|
-
location
|
|
103
|
+
location: Location;
|
|
101
104
|
canGoBack: boolean;
|
|
102
105
|
canGoForward: boolean;
|
|
103
106
|
isTransitioning: boolean;
|
|
104
107
|
transitionDuration: number;
|
|
105
108
|
transitioningToLocation?: Location;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
buildLocation: (to: NavigationOptions) => Location;
|
|
110
|
+
navigate: (options: NavigateActionOptions) => void;
|
|
111
|
+
back: (options?: BackActionOptions) => void;
|
|
112
|
+
forward: (options?: ForwardActionOptions) => void;
|
|
109
113
|
setLocationState: (index: number, state: Record<string, any>) => void;
|
|
110
114
|
}
|
|
111
115
|
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
@@ -115,12 +119,15 @@ declare const useLocation: () => LocationContextType;
|
|
|
115
119
|
declare const useRootRoute: () => RootRouteContextType;
|
|
116
120
|
|
|
117
121
|
interface RouteContextType extends ParsedRoute {
|
|
122
|
+
state: Record<string, any>;
|
|
118
123
|
getState: (key: string) => any;
|
|
119
124
|
setState: (key: string, value: any) => void;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
declare const useRoute: () => RouteContextType;
|
|
123
128
|
|
|
129
|
+
declare const useRouteMatch: () => RouteMatch;
|
|
130
|
+
|
|
124
131
|
declare const useRouter: () => RouterContextType;
|
|
125
132
|
|
|
126
133
|
declare const DefaultTransitionDuration = 300;
|
|
@@ -139,8 +146,15 @@ declare const matchPattern: (pattern: string, url: string) => {
|
|
|
139
146
|
} | null;
|
|
140
147
|
declare const matchRoute: (route: ParsedRoute, url: string) => RouteMatch;
|
|
141
148
|
declare const buildPathnameFromMatches: (matches: Route[]) => string;
|
|
142
|
-
declare const parseLocation: (
|
|
149
|
+
declare const parseLocation: ({ href, pathname, search, }: globalThis.Location) => Location;
|
|
143
150
|
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
144
151
|
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
152
|
+
/**
|
|
153
|
+
* Resolves a relative path against a base pathname.
|
|
154
|
+
* @param pathname The base pathname.
|
|
155
|
+
* @param to The relative path to resolve.
|
|
156
|
+
* @returns The resolved absolute pathname.
|
|
157
|
+
*/
|
|
158
|
+
declare const resolveRelativePathname: (pathname: string, to: string) => string;
|
|
145
159
|
|
|
146
|
-
export { type
|
|
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, resolveRelativePathname, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import * as react from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
interface Route {
|
|
5
5
|
name?: string;
|
|
@@ -18,6 +18,7 @@ interface ParsedRoute extends Route {
|
|
|
18
18
|
|
|
19
19
|
interface Location {
|
|
20
20
|
index: number;
|
|
21
|
+
href: string;
|
|
21
22
|
pathname: string;
|
|
22
23
|
search: Record<string, string>;
|
|
23
24
|
state: Record<string, any>;
|
|
@@ -46,27 +47,26 @@ interface TransitionOptions {
|
|
|
46
47
|
onFinish?: () => void;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
interface NavigationOptions {
|
|
50
51
|
to: string;
|
|
51
52
|
replace?: boolean;
|
|
52
|
-
|
|
53
|
-
} & TransitionOptions;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
interface HistoryTraversalOptions {
|
|
56
56
|
depth?: number;
|
|
57
|
-
}
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
type
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
type NavigateActionOptions = TransitionOptions & NavigationOptions;
|
|
60
|
+
type BackActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
61
|
+
type ForwardActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
62
62
|
|
|
63
|
-
type LinkProps = React.ComponentPropsWithoutRef<"a"> &
|
|
63
|
+
type LinkProps = React.ComponentPropsWithoutRef<"a"> & NavigateActionOptions;
|
|
64
64
|
declare const Link: React.FC<LinkProps>;
|
|
65
65
|
|
|
66
|
-
declare const LocationProvider: ({ location, ...props }: {
|
|
66
|
+
declare const LocationProvider: react.MemoExoticComponent<({ location, ...props }: {
|
|
67
67
|
location: Location;
|
|
68
68
|
children: React.ReactNode;
|
|
69
|
-
}) => react_jsx_runtime.JSX.Element
|
|
69
|
+
}) => react_jsx_runtime.JSX.Element>;
|
|
70
70
|
|
|
71
71
|
declare const Outlet: () => react_jsx_runtime.JSX.Element;
|
|
72
72
|
|
|
@@ -75,9 +75,11 @@ declare const RouterProvider: ({ options, ...props }: {
|
|
|
75
75
|
children: React.ReactNode;
|
|
76
76
|
}) => react_jsx_runtime.JSX.Element;
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
type StackComponentProps = React.ComponentPropsWithoutRef<"div">;
|
|
79
|
+
interface StackProps extends StackComponentProps {
|
|
79
80
|
rootRoute: Route;
|
|
80
|
-
}
|
|
81
|
+
}
|
|
82
|
+
declare const Stack: React.FC<StackProps>;
|
|
81
83
|
|
|
82
84
|
interface LocationContextType extends Location {
|
|
83
85
|
canGoBack: boolean;
|
|
@@ -89,6 +91,7 @@ interface LocationContextType extends Location {
|
|
|
89
91
|
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
90
92
|
|
|
91
93
|
interface RootRouteContextType extends ParsedRoute {
|
|
94
|
+
state: Record<string, Record<string, any>>;
|
|
92
95
|
getRouteState: (id: string, key: string) => any;
|
|
93
96
|
setRouteState: (id: string, key: string, value: any) => void;
|
|
94
97
|
}
|
|
@@ -97,15 +100,16 @@ declare const RootRouteContext: react.Context<RootRouteContextType | null>;
|
|
|
97
100
|
interface RouterContextType {
|
|
98
101
|
options: RouterOptions;
|
|
99
102
|
history: Location[];
|
|
100
|
-
location
|
|
103
|
+
location: Location;
|
|
101
104
|
canGoBack: boolean;
|
|
102
105
|
canGoForward: boolean;
|
|
103
106
|
isTransitioning: boolean;
|
|
104
107
|
transitionDuration: number;
|
|
105
108
|
transitioningToLocation?: Location;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
buildLocation: (to: NavigationOptions) => Location;
|
|
110
|
+
navigate: (options: NavigateActionOptions) => void;
|
|
111
|
+
back: (options?: BackActionOptions) => void;
|
|
112
|
+
forward: (options?: ForwardActionOptions) => void;
|
|
109
113
|
setLocationState: (index: number, state: Record<string, any>) => void;
|
|
110
114
|
}
|
|
111
115
|
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
@@ -115,12 +119,15 @@ declare const useLocation: () => LocationContextType;
|
|
|
115
119
|
declare const useRootRoute: () => RootRouteContextType;
|
|
116
120
|
|
|
117
121
|
interface RouteContextType extends ParsedRoute {
|
|
122
|
+
state: Record<string, any>;
|
|
118
123
|
getState: (key: string) => any;
|
|
119
124
|
setState: (key: string, value: any) => void;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
declare const useRoute: () => RouteContextType;
|
|
123
128
|
|
|
129
|
+
declare const useRouteMatch: () => RouteMatch;
|
|
130
|
+
|
|
124
131
|
declare const useRouter: () => RouterContextType;
|
|
125
132
|
|
|
126
133
|
declare const DefaultTransitionDuration = 300;
|
|
@@ -139,8 +146,15 @@ declare const matchPattern: (pattern: string, url: string) => {
|
|
|
139
146
|
} | null;
|
|
140
147
|
declare const matchRoute: (route: ParsedRoute, url: string) => RouteMatch;
|
|
141
148
|
declare const buildPathnameFromMatches: (matches: Route[]) => string;
|
|
142
|
-
declare const parseLocation: (
|
|
149
|
+
declare const parseLocation: ({ href, pathname, search, }: globalThis.Location) => Location;
|
|
143
150
|
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
144
151
|
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
152
|
+
/**
|
|
153
|
+
* Resolves a relative path against a base pathname.
|
|
154
|
+
* @param pathname The base pathname.
|
|
155
|
+
* @param to The relative path to resolve.
|
|
156
|
+
* @returns The resolved absolute pathname.
|
|
157
|
+
*/
|
|
158
|
+
declare const resolveRelativePathname: (pathname: string, to: string) => string;
|
|
145
159
|
|
|
146
|
-
export { type
|
|
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, resolveRelativePathname, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|