@modastar/z-router 0.0.15 → 0.0.17
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/README.md +12 -0
- package/package.json +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -166
- package/dist/index.d.ts +0 -166
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/vite.config.ts +0 -10
package/README.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Z-Router
|
|
2
|
+
|
|
3
|
+
[![npm package][npm-badge]][npm]
|
|
4
|
+
|
|
5
|
+
[npm-badge]: https://img.shields.io/npm/v/@modastar/z-router.svg
|
|
6
|
+
[npm]: https://www.npmjs.org/package/@modastar/z-router
|
|
7
|
+
|
|
8
|
+
Z-Router is a lightweight stack routing library for modern web applications. It provides an easy way to manage navigation and URL handling in your React projects.
|
|
9
|
+
|
|
10
|
+
# License
|
|
11
|
+
|
|
12
|
+
[MIT](LICENSE)
|
package/package.json
CHANGED
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var at=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Yt=Object.prototype.hasOwnProperty;var zt=(t,o)=>{for(var n in o)at(t,n,{get:o[n],enumerable:!0})},_t=(t,o,n,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of qt(o))!Yt.call(t,e)&&e!==n&&at(t,e,{get:()=>o[e],enumerable:!(s=Ht(o,e))||s.enumerable});return t};var Kt=t=>_t(at({},"__esModule",{value:!0}),t);var re={};zt(re,{DefaultTransitionDuration:()=>Zt,Link:()=>Vt,LocationContext:()=>X,LocationProvider:()=>j,Outlet:()=>ut,RootRouteContext:()=>_,RouterContext:()=>I,RouterProvider:()=>te,Stack:()=>ne,buildPathnameFromMatches:()=>Gt,buildUrlFromLocation:()=>A,createRouterOptions:()=>Qt,matchPattern:()=>Wt,matchRoute:()=>dt,parseLocation:()=>lt,parseRoute:()=>ft,redirect:()=>Jt,resolveRelativeUrl:()=>Rt,useLocation:()=>q,useRootRoute:()=>K,useRoute:()=>ct,useRouteMatch:()=>H,useRouter:()=>w});module.exports=Kt(re);var xt=require("react");var gt=require("react"),I=(0,gt.createContext)(null);var w=()=>{let t=(0,xt.useContext)(I);if(t===null)throw new Error("useRouter must be used within a Stack");return t};var yt=require("react"),vt=require("react/jsx-runtime"),Vt=(0,yt.memo)(({to:t,replace:o,transitionType:n,duration:s,onFinish:e,...u})=>{let a=w();return(0,vt.jsx)("a",{...u,href:t,onClick:i=>{i.preventDefault(),a.navigate({to:t,replace:o,transitionType:n,duration:s,onFinish:e})}})});var Tt=require("react"),X=(0,Tt.createContext)(null);var k=require("react"),Pt=require("react/jsx-runtime"),j=(0,k.memo)(({location:t,...o})=>{let n=w(),s=(0,k.useMemo)(()=>t.state,[t]),e=(0,k.useCallback)((i,r)=>{n.setLocationState(t.index,T=>({...T,[i]:r}))},[n,t]),u=(0,k.useCallback)(i=>{n.setLocationState(t.index,r=>(delete r[i],r))},[n,t]),a=(0,k.useCallback)((i,r)=>{n.setLocationSearch(t.index,{...t.search,[i]:r})},[n,t]);return(0,Pt.jsx)(X.Provider,{value:{...t,canGoBack:!n.isTransitioning&&t.index>0,canGoForward:!n.isTransitioning&&t.index+1<n.history.length,state:s,setState:e,deleteState:u,setSearch:a},...o})},(t,o)=>t.location===o.location);var Lt=require("react"),Q=(0,Lt.createContext)(0);var Ct=require("react"),St=()=>(0,Ct.useContext)(Q);var wt=require("react"),tt=(0,wt.createContext)(null);var Ot=require("react"),H=()=>{let t=(0,Ot.useContext)(tt);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};var kt=require("react/jsx-runtime"),bt=({depth:t,...o})=>(0,kt.jsx)(Q.Provider,{value:t,...o});var Mt=require("react");var q=()=>{let t=(0,Mt.useContext)(X);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};var Nt=require("react"),Y=(0,Nt.createContext)(null);var At=require("react"),ct=()=>{let t=(0,At.useContext)(Y);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};var Ft=require("react");var z=require("react/jsx-runtime"),et=({depth:t=0})=>{let o=w(),n=q(),s=H(),e=ct(),u=`_Z.${e.id}.pending`,a=!!e.beforeLoad&&e.getState(u)!==!1;if((0,Ft.useEffect)(()=>{e&&e.beforeLoad&&e.getState(u)===void 0&&(e.setState(u,!0),e.beforeLoad?.({location:n}).then(()=>e.setState(u,!1)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),o.navigate({...r,onFinish:()=>{e.setState(u,!1)}})):e.setState(u,!1)}))},[e]),!e)return null;if(a){let r=e.pendingComponent;return(0,z.jsx)(r,{})}if(t>=s.matches.length){let r=e.notFoundComponent;return(0,z.jsx)(r,{})}let i=e.component;return i?(0,z.jsx)(i,{}):(0,z.jsx)(ut,{})};var Dt=require("react");var Et=require("react"),_=(0,Et.createContext)(null);var K=()=>{let t=(0,Dt.useContext)(_);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};var pt=require("react"),mt=require("react/jsx-runtime"),ot=({route:t,...o})=>{if(!t)return(0,mt.jsx)(Y.Provider,{value:null,...o});let{state:n,getRouteState:s,setRouteState:e}=K(),u=(0,pt.useCallback)(i=>s(t.id,i),[s,t.id]),a=(0,pt.useCallback)((i,r)=>{e(t.id,i,r)},[e,t.id]);return(0,mt.jsx)(Y.Provider,{value:{...t,state:n[t.id],getState:u,setState:a},...o})};var nt=require("react/jsx-runtime"),ut=()=>{let t=H(),o=St()+1;return(0,nt.jsx)(bt,{depth:o,children:(0,nt.jsx)(ot,{route:t.matches.at(o),children:(0,nt.jsx)(et,{depth:o})})})};var x=require("react");var $t={defaultTransitionDuration:300};var Zt=300,Jt=t=>new Error("",{cause:t}),Wt=(t,o)=>{try{let n,s;if(o.startsWith("http://")||o.startsWith("https://")){let l=new URL(o);n=l.pathname,s=l.searchParams}else{let[l,v]=o.split("?");if(!l)return null;n=l,s=new URLSearchParams(v||"")}let e=n.replaceAll(/^\/|\/$/g,""),u=t.replaceAll(/^\/|\/$/g,""),a=e.split("/"),i=u.split("/");if(a.length!==i.length)return null;let r={};for(let l=0;l<i.length;l++){let v=i[l],O=a[l];if(v.startsWith(":")){let E=v.slice(1);r[E]=decodeURIComponent(O)}else if(v!==O)return null}let T=Object.fromEntries(s.entries());return{params:r,query:T}}catch{return null}},dt=(t,o)=>{let n=(s,{children:e})=>{if(e&&e.length>0){for(let a of e){let i=n([...s,a],a);if(i)return i}return null}let u=Wt(Gt(s),o);return u?{matches:s,...u}:null};return n([t],t)||{matches:[],params:{},query:{}}},Gt=t=>{let o=[];for(let n of t)n.pathname!==void 0&&o.push(n.pathname.replaceAll(/^\/|\/$/g,""));return"/"+o.join("/")},lt=({href:t,pathname:o,search:n})=>({index:0,href:t,state:{index:0},pathname:o,search:Object.fromEntries(new URLSearchParams(n))}),Qt=t=>({...$t,...t}),ft=t=>{let o=(n,s)=>{let e=n.name??(n.pathname?`${s}/${n.pathname.replaceAll(/^\/|\/$/g,"")}`:s);return{...n,id:e,children:n.children?.map(a=>o(a,e))}};return o(t,"")},jt=t=>t.length>0,Rt=(t,o)=>{let n=t.split("/").filter(jt),s=o.split("/").filter(jt);for(let e of s)e!=="."&&(e===".."?n.pop():n.push(e));return"/"+n.join("/")},A=t=>{let o=new URLSearchParams(t.search).toString();return o?`${t.pathname}?${o}`:t.pathname};var ht=require("react/jsx-runtime"),te=({options:t,...o})=>{let[n,s]=(0,x.useState)([lt(window.location)]),[e,u]=(0,x.useState)(0),a=(0,x.useMemo)(()=>n.at(e),[n,e]),[i,r]=(0,x.useState)(!1),[T,l]=(0,x.useState)(),[v,O]=(0,x.useState)(),[E,S]=(0,x.useState)(0),M=!i&&e>0,W=!i&&e+1<n.length;(0,x.useEffect)(()=>{window.history.replaceState(a.state,"",A(a))},[]),(0,x.useEffect)(()=>{let p=({state:m})=>{u(m?.index)};return addEventListener("popstate",p),()=>{removeEventListener("popstate",p)}},[e]);let G=(0,x.useCallback)(({to:p,replace:m})=>{if(!p)return a;let R=m?e:e+1,d=p.startsWith("/")?p:Rt(a.pathname,p),[g,f]=d.split("?"),h=new URLSearchParams(f??""),C={index:R};return{index:R,href:origin+g+(f?`?${h.toString()}`:""),search:Object.fromEntries(h.entries()),state:C,pathname:g}},[e,a]),L=(p,m,R=t.defaultTransitionDuration,d)=>{r(!0),O(m),S(R),l(p),setTimeout(()=>{r(!1),O(void 0),l(void 0),d?.()},R)},V=(0,x.useCallback)(({to:p,replace:m,transitionType:R,duration:d,onFinish:g})=>{if(i)return;let f=m?e:e+1,h=G({to:p,replace:m}),C=()=>{m?(s(D=>[...D.slice(0,f),h,...D.slice(f+1)]),window.history.replaceState(h.state,"",A(h))):(s(D=>[...D.slice(0,f),h]),u(f),window.history.pushState(h.state,"",A(h))),g?.()},J=R??t.defaultTransitionType?.(a,h)??"slide-left";J?L(h,J,d,C):C()},[e,n,i,t]),b=(0,x.useCallback)(({transitionType:p,duration:m,onFinish:R,depth:d}={})=>{if(!M)return;let g=d??1,f=n.at(e-g);if(!f)return;let h=()=>{window.history.go(-g),R?.()},C=p??t.defaultTransitionType?.(a,f)??"slide-right";C?L(f,C,m,h):h()},[e,n,i,t]),U=(0,x.useCallback)(({transitionType:p,duration:m,depth:R,onFinish:d}={})=>{if(!W)return;let g=R??1,f=n.at(e+g);if(!f)return;let h=()=>{window.history.go(g),d?.()},C=p??t.defaultTransitionType?.(a,f)??"slide-left";C?L(f,C,m,h):h()},[e,n,i,t]),B=(0,x.useCallback)((p,m)=>{s(R=>R.map(d=>{if(d.index!==p)return d;let g=typeof m=="function"?m(d.state):m,f={...d,state:g};return p===e&&window.history.replaceState(g,"",A(f)),f}))},[e]),Z=(0,x.useCallback)((p,m)=>{s(R=>R.map(d=>{if(d.index!==p)return d;let g={...d,search:{...d.search,...m}};return p===e&&window.history.replaceState(g.state,"",A(g)),g}))},[]);return(0,ht.jsx)(I.Provider,{value:{options:t,history:n,location:a,canGoBack:M,canGoForward:W,isTransitioning:i,transitioningToLocation:T,transitionType:v,transitionDuration:E,buildLocation:G,navigate:V,back:b,forward:U,setLocationState:B,setLocationSearch:Z},children:(0,ht.jsx)(j,{location:a,...o})})};var y=require("react");var it=require("react");var rt=require("react/jsx-runtime"),st=(0,it.memo)(()=>{let t=K(),o=q(),n=(0,it.useMemo)(()=>dt(t,o.pathname),[t,o.pathname]);return(0,rt.jsx)(tt.Provider,{value:n,children:(0,rt.jsx)(ot,{route:t,children:(0,rt.jsx)(et,{})})})});var F=require("react"),Bt=require("react/jsx-runtime"),Ut=({route:t,...o})=>{let n=(0,F.useMemo)(()=>ft(t),[t]),[s,e]=(0,F.useState)({}),u=(0,F.useCallback)((i,r)=>s[i]?.[r],[s]),a=(0,F.useCallback)((i,r,T)=>{e(l=>({...l,[i]:{...l[i],[r]:T}}))},[]);return(0,Bt.jsx)(_.Provider,{value:{...n,state:s,getRouteState:u,setRouteState:a},...o})};var P=require("react/jsx-runtime"),ee={position:"absolute",inset:0,zIndex:-1},oe=({allowSwipeBack:t=!0,allowSwipeForward:o=!0,style:n,...s})=>{let{history:e,location:u,canGoBack:a,canGoForward:i,isTransitioning:r,transitioningToLocation:T,transitionType:l,transitionDuration:v,back:O,forward:E}=w(),S=u.index,M=(0,y.useRef)(!1),W=(0,y.useRef)(0),G=(0,y.useRef)(0),[L,V]=(0,y.useState)(!1),[b,U]=(0,y.useState)(0),[B,Z]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[R,d]=(0,y.useState)(!1),[g,f]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{!r||!T||(f(!0),setTimeout(()=>{f(!1)},v))},[r,T,v]),S===void 0)return;let h=()=>{V(!1),U(0),Z(!1),m(!1),d(!1)},C=(0,y.useCallback)(N=>{r||!i&&!a||(M.current=!0,W.current=N.touches[0].clientX,G.current=N.touches[0].clientY)},[r,a,i]),J=(0,y.useCallback)(N=>{if(!M.current)return;let{clientX:It,clientY:Xt}=N.touches[0];if(!L&&Math.abs(Xt-G.current)>30){M.current=!1;return}let $=It-W.current;if(!(Math.abs($)<10)){if(L||V(!0),$>0&&S===0||$<0&&S+1===e.length){U(0);return}!B&&$<0&&o&&Z(!0),!p&&$>0&&t&&m(!0),U(Math.max(Math.min($,window.innerWidth),-window.innerWidth))}},[L,S,e.length,B,p,t,o]),D=(0,y.useCallback)(()=>{if(M.current=!1,!L)return;let N={onFinish:h};b>innerWidth*.3&&a&&t?O(N):b<-innerWidth*.3&&i&&o?E(N):(d(!0),setTimeout(h,v))},[O,E,L,b,a,i,v]);return(0,P.jsxs)("div",{style:{position:"relative",overflow:"hidden",...n},...s,children:[(r&&l==="slide-right"||L&&p)&&(0,P.jsx)("div",{style:ee,children:(0,P.jsx)(j,{location:r?T:e.at(S-1),children:(0,P.jsx)(st,{},S-1)})}),(0,P.jsx)("div",{style:{position:"absolute",inset:0,transform:r&&l==="slide-right"?"translateX(100%)":L&&b>0&&!R?`translateX(${b}px)`:"translateX(0px)",transition:R||r&&l==="slide-right"?`transform ${v}ms ease-out`:""},onTouchStart:C,onTouchMove:J,onTouchEnd:D,children:(0,P.jsx)(st,{})},S),(r&&l==="slide-left"||L&&B)&&(0,P.jsx)("div",{style:{position:"absolute",inset:0,zIndex:1,transform:`translateX(${g?"0px":r||R?"100%":`${innerWidth+b}px`})`,transition:`transform ${r||R?v:0}ms ease-in`},children:(0,P.jsx)(j,{location:r?T:e.at(S+1),children:(0,P.jsx)(st,{},T?.index)})})]})},ne=({route:t,...o})=>(0,P.jsx)(Ut,{route:t,children:(0,P.jsx)(oe,{...o})});0&&(module.exports={DefaultTransitionDuration,Link,LocationContext,LocationProvider,Outlet,RootRouteContext,RouterContext,RouterProvider,Stack,buildPathnameFromMatches,buildUrlFromLocation,createRouterOptions,matchPattern,matchRoute,parseLocation,parseRoute,redirect,resolveRelativeUrl,useLocation,useRootRoute,useRoute,useRouteMatch,useRouter});
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useRouter.ts","../src/context/router-context.ts","../src/components/link.tsx","../src/context/location-context.ts","../src/components/location-provider.tsx","../src/context/outlet-context.ts","../src/hooks/useOutlet.ts","../src/context/route-match-context.ts","../src/hooks/useRouteMatch.ts","../src/components/outlet-provider.tsx","../src/hooks/useLocation.ts","../src/context/route-context.ts","../src/hooks/useRoute.ts","../src/components/route-component.tsx","../src/hooks/useRootRoute.ts","../src/context/root-route-context.ts","../src/components/route-provider.tsx","../src/components/outlet.tsx","../src/components/router-provider.tsx","../src/constants.ts","../src/utils.ts","../src/components/stack.tsx","../src/components/page-renderer.tsx","../src/components/root-route-provider.tsx"],"sourcesContent":["export * from \"./components/index.js\";\nexport * from \"./context/index.js\";\nexport * from \"./hooks/index.js\";\nexport * from \"./types.d.js\";\nexport * from \"./utils.js\";\n","import { useContext } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\n\nexport const useRouter = () => {\n const router = useContext(RouterContext);\n if (router === null) {\n throw new Error(\"useRouter must be used within a Stack\");\n }\n return router;\n};\n","import { createContext } from \"react\";\n\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\n\nexport interface RouterContextType {\n // Router Config\n options: RouterOptions;\n\n // Navigation State\n history: Location[];\n location: Location;\n canGoBack: boolean;\n canGoForward: boolean;\n\n // Transition state\n isTransitioning: boolean;\n transitioningToLocation?: Location;\n transitionType?: TransitionType;\n transitionDuration: number;\n\n // Utilities\n buildLocation: (to: NavigationOptions) => Location;\n\n // Navigation Actions\n navigate: (options: NavigateActionOptions) => void;\n back: (options?: BackActionOptions) => void;\n forward: (options?: ForwardActionOptions) => void;\n\n // Low-level state action\n setLocationState: (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => void;\n setLocationSearch: (\n locationIndex: number,\n search: Record<string, string>\n ) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | null>(null);\n","import { useRouter } from \"@/hooks/useRouter.js\";\nimport type { NavigateActionOptions } from \"@/types.js\";\nimport { memo } from \"react\";\n\nexport type LinkProps = React.ComponentPropsWithoutRef<\"a\"> &\n NavigateActionOptions;\n\nexport const Link: React.FC<LinkProps> = memo(\n ({ to, replace, transitionType, duration, onFinish, ...props }) => {\n const router = useRouter();\n return (\n <a\n {...props}\n href={to}\n onClick={(e) => {\n e.preventDefault();\n router.navigate({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n });\n }}\n />\n );\n }\n);\n","import { createContext } from \"react\";\n\nimport type { Location } from \"@/types.js\";\n\nexport interface LocationContextType extends Location {\n canGoBack: boolean;\n canGoForward: boolean;\n state: Record<string, any>;\n setState: (key: string, value: any) => void;\n deleteState: (key: string) => void;\n setSearch: (key: string, value: string) => void;\n}\n\nexport const LocationContext = createContext<LocationContextType | null>(null);\n","import { LocationContext } from \"@/context/location-context.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Location } from \"@/types.js\";\nimport { memo, useCallback, useMemo } from \"react\";\n\nexport const LocationProvider = memo(\n ({\n location,\n ...props\n }: {\n location: Location;\n children: React.ReactNode;\n }) => {\n const router = useRouter();\n const state = useMemo(() => location.state, [location]);\n const setState = useCallback(\n (key: string, value: any) => {\n router.setLocationState(location.index, (prev) => ({\n ...prev,\n [key]: value,\n }));\n },\n [router, location]\n );\n const deleteState = useCallback(\n (key: string) => {\n router.setLocationState(location.index, (prev) => {\n delete prev[key];\n return prev;\n });\n },\n [router, location]\n );\n const setSearch = useCallback(\n (key: string, value: string) => {\n router.setLocationSearch(location.index, {\n ...location.search,\n [key]: value,\n });\n },\n [router, location]\n );\n return (\n <LocationContext.Provider\n value={{\n ...location,\n canGoBack: !router.isTransitioning && location.index > 0,\n canGoForward:\n !router.isTransitioning &&\n location.index + 1 < router.history.length,\n state,\n setState,\n deleteState,\n setSearch,\n }}\n {...props}\n />\n );\n },\n (a, b) => a.location === b.location\n);\n","import { createContext } from \"react\";\n\nexport const OutletContext = createContext<number>(0);\n","import { OutletContext } from \"@/context/outlet-context.js\";\nimport { useContext } from \"react\";\n\nexport const useOutlet = () => useContext(OutletContext);\n","import type { RouteMatch } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport const RouteMatchContext = createContext<RouteMatch | null>(null);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRouteMatch = () => {\n const routeMatch = useContext(RouteMatchContext);\n if (routeMatch === null) {\n throw new Error(\"useRouteMatch must be used within a RouteMatchProvider\");\n }\n return routeMatch;\n};\n","import { OutletContext } from \"@/context/outlet-context.js\";\n\nexport const OutletProvider = ({\n depth,\n ...props\n}: {\n depth: number;\n children?: React.ReactNode;\n}) => <OutletContext.Provider value={depth} {...props} />;\n","import { useContext } from \"react\";\n\nimport { LocationContext } from \"@/context/location-context.js\";\n\nexport const useLocation = () => {\n const context = useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a LocationProvider\");\n }\n return context;\n};\n","import type { ParsedRoute } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport interface RouteContextType extends ParsedRoute {\n state: Record<string, any>;\n getState: (key: string) => any;\n setState: (key: string, value: any) => void;\n}\n\nexport const RouteContext = createContext<RouteContextType | null>(null);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRoute = () => {\n const route = useContext(RouteContext);\n if (route === null) {\n throw new Error(\"useRoute must be used within a RouteProvider\");\n }\n return route;\n};\n","import { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRoute } from \"@/hooks/useRoute.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport { useEffect } from \"react\";\nimport { Outlet } from \"./outlet.js\";\n\nexport const RouteComponent = ({ depth = 0 }: { depth?: number }) => {\n const router = useRouter();\n const location = useLocation();\n const routeMatch = useRouteMatch();\n const route = useRoute();\n\n const pendingStateKey = `_Z.${route.id}.pending`;\n const pending =\n !!route.beforeLoad && route.getState(pendingStateKey) !== false;\n\n useEffect(() => {\n if (!route) {\n return;\n }\n if (route.beforeLoad && route.getState(pendingStateKey) === undefined) {\n route.setState(pendingStateKey, true);\n route\n .beforeLoad?.({ location })\n .then(() => route.setState(pendingStateKey, false))\n .catch(({ cause }: Error) => {\n if (!!cause && \"to\" in (cause as any)) {\n console.log(\"Redirecting to:\", (cause as any).to);\n router.navigate({\n ...(cause as any),\n onFinish: () => {\n route.setState(pendingStateKey, false);\n },\n });\n } else {\n route.setState(pendingStateKey, false);\n }\n });\n }\n }, [route]);\n\n if (!route) {\n return null;\n }\n\n if (pending) {\n const PendingComponent = route.pendingComponent!;\n return <PendingComponent />;\n }\n\n if (depth >= routeMatch.matches.length) {\n const NotFoundComponent = route.notFoundComponent!;\n return <NotFoundComponent />;\n }\n\n const Component = route.component;\n return Component ? <Component /> : <Outlet />;\n};\n","import { useContext } from \"react\";\n\nimport { RootRouteContext } from \"@/context/root-route-context.js\";\n\nexport const useRootRoute = () => {\n const route = useContext(RootRouteContext);\n if (route === null) {\n throw new Error(\"useRootRoute must be used within a RootRouteProvider\");\n }\n return route;\n};\n","import { createContext } from \"react\";\n\nimport type { ParsedRoute } from \"@/types.js\";\n\nexport interface RootRouteContextType extends ParsedRoute {\n state: Record<string, Record<string, any>>;\n getRouteState: (id: string, key: string) => any;\n setRouteState: (id: string, key: string, value: any) => void;\n}\n\nexport const RootRouteContext = createContext<RootRouteContextType | null>(\n null\n);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport type { ParsedRoute } from \"@/types.js\";\nimport { useCallback } from \"react\";\n\nexport const RouteProvider = ({\n route,\n ...props\n}: {\n route?: ParsedRoute;\n children?: React.ReactNode;\n}) => {\n if (!route) {\n return <RouteContext.Provider value={null} {...props} />;\n }\n\n const { state, getRouteState, setRouteState } = useRootRoute();\n\n const getState = useCallback(\n (key: string) => getRouteState(route.id, key),\n [getRouteState, route.id]\n );\n\n const setState = useCallback(\n (key: string, value: any) => {\n setRouteState(route.id, key, value);\n },\n [setRouteState, route.id]\n );\n\n return (\n <RouteContext.Provider\n value={{ ...route, state: state[route.id], getState, setState }}\n {...props}\n />\n );\n};\n","import { useOutlet } from \"@/hooks/useOutlet.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { OutletProvider } from \"./outlet-provider.js\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const Outlet = () => {\n const routeMatch = useRouteMatch();\n const depth = useOutlet() + 1;\n return (\n <OutletProvider depth={depth}>\n <RouteProvider route={routeMatch.matches.at(depth)}>\n <RouteComponent depth={depth} />\n </RouteProvider>\n </OutletProvider>\n );\n};\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\nimport {\n buildUrlFromLocation,\n parseLocation,\n resolveRelativeUrl,\n} from \"@/utils.js\";\nimport { LocationProvider } from \"./location-provider.js\";\n\nexport const RouterProvider = ({\n options,\n ...props\n}: {\n options: RouterOptions;\n children: React.ReactNode;\n}) => {\n const [history, setHistory] = useState<Location[]>([\n parseLocation(window.location),\n ]);\n const [currentLocationIndex, setCurrentLocationIndex] = useState<number>(0);\n const location = useMemo(\n () => history.at(currentLocationIndex)!,\n [history, currentLocationIndex]\n );\n const [isTransitioning, setIsTransitioning] = useState<boolean>(false);\n const [transitioningToLocation, setTransitioningToLocation] =\n useState<Location>();\n const [transitionType, setTransitionType] = useState<TransitionType>();\n const [transitionDuration, setTransitionDuration] = useState<number>(0);\n\n const canGoBack = !isTransitioning && currentLocationIndex > 0;\n const canGoForward =\n !isTransitioning && currentLocationIndex + 1 < history.length;\n\n useEffect(() => {\n window.history.replaceState(\n location.state,\n \"\",\n buildUrlFromLocation(location)\n );\n }, []);\n\n useEffect(() => {\n const handlePopState = ({ state }: PopStateEvent) => {\n setCurrentLocationIndex(state?.index);\n };\n\n addEventListener(\"popstate\", handlePopState);\n return () => {\n removeEventListener(\"popstate\", handlePopState);\n };\n }, [currentLocationIndex]);\n\n // Utilities\n const buildLocation = useCallback(\n ({ to, replace }: NavigationOptions): Location => {\n if (!to) return location;\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n\n // Resolve to with absolute or relative paths like \"..\" or \".\"\n const url = to.startsWith(\"/\")\n ? to\n : resolveRelativeUrl(location.pathname, to);\n const [pathname, search] = url.split(\"?\");\n const searchParams = new URLSearchParams(search ?? \"\");\n const state = {\n index,\n };\n return {\n index,\n href: origin + pathname + (search ? `?${searchParams.toString()}` : \"\"),\n search: Object.fromEntries(searchParams.entries()),\n state,\n pathname,\n };\n },\n [currentLocationIndex, location]\n );\n\n // Transition helper\n const transitionTo = (\n location: Location,\n transitionType: TransitionType,\n duration: number = options.defaultTransitionDuration,\n callback?: () => void\n ) => {\n setIsTransitioning(true);\n setTransitionType(transitionType);\n setTransitionDuration(duration);\n setTransitioningToLocation(location);\n setTimeout(() => {\n setIsTransitioning(false);\n setTransitionType(undefined);\n setTransitioningToLocation(undefined);\n callback?.();\n }, duration);\n };\n\n // Navigation actions\n const navigate = useCallback(\n ({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n }: NavigateActionOptions) => {\n if (isTransitioning) return;\n\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n const newLocation = buildLocation({ to, replace });\n\n const updateHistory = () => {\n if (replace) {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ...prevHistory.slice(index + 1),\n ]);\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const back = useCallback(\n ({ transitionType, duration, onFinish, depth }: BackActionOptions = {}) => {\n if (!canGoBack) return;\n const backDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex - backDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(-backDepth);\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-right\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const forward = useCallback(\n ({\n transitionType,\n duration,\n depth,\n onFinish,\n }: ForwardActionOptions = {}) => {\n if (!canGoForward) return;\n const forwardDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex + forwardDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(forwardDepth);\n onFinish?.();\n };\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n // Low-level state action\n const setLocationState = useCallback(\n (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => {\n setHistory((prevHistory) =>\n prevHistory.map((location) => {\n if (location.index !== index) {\n return location;\n }\n const newState =\n typeof state === \"function\" ? state(location.state) : state;\n const newLocation = { ...location, state: newState };\n if (index === currentLocationIndex) {\n window.history.replaceState(\n newState,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n [currentLocationIndex]\n );\n\n const setLocationSearch = useCallback(\n (locationIndex: number, search: Record<string, string>) => {\n setHistory((prev) =>\n prev.map((location) => {\n if (location.index !== locationIndex) return location;\n const newLocation = {\n ...location,\n search: {\n ...location.search,\n ...search,\n },\n };\n if (locationIndex === currentLocationIndex) {\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n []\n );\n\n return (\n <RouterContext.Provider\n // oxlint-disable-next-line jsx-no-new-object-as-prop\n value={{\n options,\n\n history,\n location,\n canGoBack,\n canGoForward,\n\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n\n buildLocation,\n\n navigate,\n back,\n forward,\n\n setLocationState,\n setLocationSearch,\n }}\n >\n <LocationProvider location={location} {...props} />\n </RouterContext.Provider>\n );\n};\n","import type { RouterOptions } from \"./types.js\";\n\nexport const DefaultRouterOptions: RouterOptions = {\n defaultTransitionDuration: 300,\n};\n","import { DefaultRouterOptions } from \"./constants.js\";\nimport type {\n Location,\n NavigateActionOptions,\n ParsedRoute,\n Route,\n RouteMatch,\n RouterOptions,\n} from \"./types.js\";\n\nexport const DefaultTransitionDuration = 300;\n\nexport const redirect = (options: NavigateActionOptions) => {\n return new Error(\"\", { cause: options });\n};\n\n/**\n * @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.\n * @param url URL to match against the pattern. Can be href or pathname with query string.\n * @returns extracted params and query if matched, otherwise null\n */\nexport const matchPattern = (\n pattern: string,\n url: string\n): { params: Record<string, string>; query: Record<string, string> } | null => {\n try {\n // 解析 URL\n let pathname, searchParams;\n\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n const urlObj = new URL(url);\n pathname = urlObj.pathname;\n searchParams = urlObj.searchParams;\n } else {\n // 處理相對路徑\n const [path, queryString] = url.split(\"?\");\n if (!path) {\n return null;\n }\n pathname = path;\n searchParams = new URLSearchParams(queryString || \"\");\n }\n\n // 移除路徑首尾的斜線以便比較\n const cleanPath = pathname.replaceAll(/^\\/|\\/$/g, \"\");\n const cleanPattern = pattern.replaceAll(/^\\/|\\/$/g, \"\");\n\n // 分割路徑段\n const pathSegments = cleanPath.split(\"/\");\n const patternSegments = cleanPattern.split(\"/\");\n\n // 路徑段數量不同則不匹配\n if (pathSegments.length !== patternSegments.length) {\n return null;\n }\n\n // 提取路徑參數\n const params: Record<string, string> = {};\n for (let i = 0; i < patternSegments.length; i++) {\n const patternSegment = patternSegments[i];\n const pathSegment = pathSegments[i];\n\n if (patternSegment.startsWith(\":\")) {\n // 動態參數\n const paramName = patternSegment.slice(1);\n params[paramName] = decodeURIComponent(pathSegment);\n } else if (patternSegment !== pathSegment) {\n // 靜態段不匹配\n return null;\n }\n }\n\n // 提取查詢參數\n const query = Object.fromEntries(searchParams.entries());\n\n return { params, query };\n } catch {\n return null;\n }\n};\n\nexport const matchRoute = (route: ParsedRoute, url: string): RouteMatch => {\n const _matchRoute = (\n matches: ParsedRoute[],\n { children }: ParsedRoute\n ): RouteMatch | null => {\n if (children && children.length > 0) {\n for (const childRoute of children) {\n const matchesResult = _matchRoute([...matches, childRoute], childRoute);\n if (matchesResult) {\n return matchesResult;\n }\n }\n return null;\n }\n\n const result = matchPattern(buildPathnameFromMatches(matches), url);\n return result ? { matches, ...result } : null;\n };\n\n return (\n _matchRoute([route], route) || {\n matches: [],\n params: {},\n query: {},\n }\n );\n};\n\nexport const buildPathnameFromMatches = (matches: Route[]): string => {\n let cleanedPathnames: string[] = []; // pathnames without leading/trailing slashes\n for (const match of matches) {\n if (match.pathname === undefined) continue;\n cleanedPathnames.push(match.pathname.replaceAll(/^\\/|\\/$/g, \"\"));\n }\n return \"/\" + cleanedPathnames.join(\"/\");\n};\n\nexport const parseLocation = ({\n href,\n pathname,\n search,\n}: globalThis.Location): Location => ({\n index: 0,\n href,\n state: {\n index: 0,\n },\n pathname,\n search: Object.fromEntries(new URLSearchParams(search)),\n});\n\nexport const createRouterOptions = (\n options?: Partial<RouterOptions>\n): RouterOptions => ({\n ...DefaultRouterOptions,\n ...options,\n});\n\nexport const parseRoute = (route: Route): ParsedRoute => {\n const parseRouteRecursive = (route: Route, parentId: string): ParsedRoute => {\n const id =\n route.name ??\n (route.pathname\n ? `${parentId}/${route.pathname.replaceAll(/^\\/|\\/$/g, \"\")}`\n : parentId);\n\n const parsedRoute: ParsedRoute = {\n ...route,\n id,\n children: route.children?.map((child) => parseRouteRecursive(child, id)),\n };\n\n return parsedRoute;\n };\n return parseRouteRecursive(route, \"\");\n};\n\nconst isPathSegmentValid = (segment: string): boolean => segment.length > 0;\n\n/**\n * Resolves a relative path against a base url.\n * @param url The base url.\n * @param to The relative path to resolve.\n * @returns The resolved absolute url.\n */\nexport const resolveRelativeUrl = (url: string, to: string): string => {\n const currentPathSegments = url.split(\"/\").filter(isPathSegmentValid);\n const toPathSegments = to.split(\"/\").filter(isPathSegmentValid);\n for (const segment of toPathSegments) {\n if (segment === \".\") {\n continue;\n } else if (segment === \"..\") {\n currentPathSegments.pop();\n } else {\n currentPathSegments.push(segment);\n }\n }\n return \"/\" + currentPathSegments.join(\"/\");\n};\n\nexport const buildUrlFromLocation = (location: Location): string => {\n const searchParams = new URLSearchParams(location.search).toString();\n return searchParams\n ? `${location.pathname}?${searchParams}`\n : location.pathname;\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Route } from \"@/types.js\";\n\nimport { LocationProvider } from \"./location-provider.js\";\nimport { PageRenderer } from \"./page-renderer.js\";\nimport { RootRouteProvider } from \"./root-route-provider.js\";\n\nconst PreviousComponentStyle = {\n position: \"absolute\",\n inset: 0,\n zIndex: -1,\n} as const;\n\nexport interface StackComponentProps\n extends React.ComponentPropsWithoutRef<\"div\"> {\n allowSwipeForward?: boolean;\n allowSwipeBack?: boolean;\n}\n\nconst StackComponent: React.FC<StackComponentProps> = ({\n allowSwipeBack = true,\n allowSwipeForward = true,\n style,\n ...props\n}) => {\n const {\n history,\n location,\n canGoBack,\n canGoForward,\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n back,\n forward,\n } = useRouter();\n const currentLocationIndex = location.index;\n\n const isTouching = useRef(false);\n const startX = useRef(0);\n const startY = useRef(0);\n const [isDragging, setIsDragging] = useState(false);\n const [dragOffset, setDragOffset] = useState(0);\n const [showPreviousComponent, setShowPreviousComponent] = useState(false);\n const [showNextComponent, setShowNextComponent] = useState(false);\n const [isCanceling, setIsCanceling] = useState(false);\n const [isTransitionStarted, setIsTransitionStarted] = useState(false);\n\n useEffect(() => {\n if (!isTransitioning || !transitioningToLocation) return;\n setIsTransitionStarted(true);\n setTimeout(() => {\n setIsTransitionStarted(false);\n }, transitionDuration);\n }, [isTransitioning, transitioningToLocation, transitionDuration]);\n\n if (currentLocationIndex === undefined) return;\n\n const reset = () => {\n setIsDragging(false);\n setDragOffset(0);\n setShowPreviousComponent(false);\n setShowNextComponent(false);\n setIsCanceling(false);\n };\n\n const handleTouchStart = useCallback(\n (e: React.TouchEvent) => {\n if (isTransitioning || (!canGoForward && !canGoBack)) return;\n isTouching.current = true;\n startX.current = e.touches[0].clientX;\n startY.current = e.touches[0].clientY;\n },\n [isTransitioning, canGoBack, canGoForward]\n );\n\n const handleTouchMove = useCallback(\n (e: React.TouchEvent) => {\n if (!isTouching.current) return;\n // Skip vertical drag\n const { clientX, clientY } = e.touches[0];\n if (!isDragging && Math.abs(clientY - startY.current) > 30) {\n isTouching.current = false;\n return;\n }\n const offset = clientX - startX.current;\n if (Math.abs(offset) < 10) return;\n if (!isDragging) {\n setIsDragging(true);\n }\n if (\n (offset > 0 && currentLocationIndex === 0) ||\n (offset < 0 && currentLocationIndex + 1 === history.length)\n ) {\n setDragOffset(0);\n return;\n }\n if (!showPreviousComponent && offset < 0 && allowSwipeForward)\n setShowPreviousComponent(true);\n if (!showNextComponent && offset > 0 && allowSwipeBack)\n setShowNextComponent(true);\n setDragOffset(\n Math.max(Math.min(offset, window.innerWidth), -window.innerWidth)\n );\n },\n [\n isDragging,\n currentLocationIndex,\n history.length,\n showPreviousComponent,\n showNextComponent,\n allowSwipeBack,\n allowSwipeForward,\n ]\n );\n\n const handleTouchEnd = useCallback(() => {\n isTouching.current = false;\n if (!isDragging) return;\n\n const options = {\n onFinish: reset,\n };\n if (dragOffset > innerWidth * 0.3 && canGoBack && allowSwipeBack) {\n back(options);\n } else if (\n dragOffset < -innerWidth * 0.3 &&\n canGoForward &&\n allowSwipeForward\n ) {\n forward(options);\n } else {\n setIsCanceling(true);\n setTimeout(reset, transitionDuration);\n }\n }, [\n back,\n forward,\n isDragging,\n dragOffset,\n canGoBack,\n canGoForward,\n transitionDuration,\n ]);\n\n return (\n <div\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n ...style,\n }}\n {...props}\n >\n {((isTransitioning && transitionType === \"slide-right\") ||\n (isDragging && showNextComponent)) && (\n <div style={PreviousComponentStyle}>\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex - 1)!\n }\n >\n <PageRenderer key={currentLocationIndex - 1} />\n </LocationProvider>\n </div>\n )}\n <div\n key={currentLocationIndex}\n style={{\n position: \"absolute\",\n inset: 0,\n transform:\n isTransitioning && transitionType === \"slide-right\"\n ? `translateX(100%)`\n : isDragging && dragOffset > 0 && !isCanceling\n ? `translateX(${dragOffset}px)`\n : \"translateX(0px)\",\n transition:\n isCanceling || (isTransitioning && transitionType === \"slide-right\")\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n {((isTransitioning && transitionType === \"slide-left\") ||\n (isDragging && showPreviousComponent)) && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: 1,\n transform: `translateX(${\n isTransitionStarted\n ? \"0px\"\n : isTransitioning || isCanceling\n ? \"100%\"\n : `${innerWidth + dragOffset}px`\n })`,\n transition: `transform ${\n isTransitioning || isCanceling ? transitionDuration : 0\n }ms ease-in`,\n }}\n >\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex + 1)!\n }\n >\n <PageRenderer key={transitioningToLocation?.index} />\n </LocationProvider>\n </div>\n )}\n </div>\n );\n};\n\nexport interface StackProps extends StackComponentProps {\n route: Route;\n}\n\nexport const Stack: React.FC<StackProps> = ({ route, ...props }) => (\n <RootRouteProvider route={route}>\n <StackComponent {...props} />\n </RootRouteProvider>\n);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport { matchRoute } from \"@/utils.js\";\nimport { memo, useMemo } from \"react\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const PageRenderer = memo(() => {\n const rootRoute = useRootRoute();\n const location = useLocation();\n const routeMatch = useMemo(\n () => matchRoute(rootRoute, location.pathname),\n [rootRoute, location.pathname]\n );\n return (\n <RouteMatchContext.Provider value={routeMatch}>\n <RouteProvider route={rootRoute}>\n <RouteComponent />\n </RouteProvider>\n </RouteMatchContext.Provider>\n );\n});\n","import { RootRouteContext } from \"@/context/root-route-context.js\";\nimport type { Route } from \"@/types.js\";\nimport { parseRoute } from \"@/utils.js\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nexport const RootRouteProvider = ({\n route,\n ...props\n}: {\n route: Route;\n children: React.ReactNode;\n}) => {\n const parsedRoute = useMemo(() => parseRoute(route), [route]);\n const [state, setState] = useState<Record<string, Record<string, any>>>({});\n\n const getRouteState = useCallback(\n (id: string, key: string) => {\n return state[id]?.[key];\n },\n [state]\n );\n\n const setRouteState = useCallback((id: string, key: string, value: any) => {\n setState((prevState) => ({\n ...prevState,\n [id]: {\n ...prevState[id],\n [key]: value,\n },\n }));\n }, []);\n\n return (\n <RootRouteContext.Provider\n value={{ ...parsedRoute, state, getRouteState, setRouteState }}\n {...props}\n />\n );\n};\n"],"mappings":"ubAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,+BAAAE,GAAA,SAAAC,GAAA,oBAAAC,EAAA,qBAAAC,EAAA,WAAAC,GAAA,qBAAAC,EAAA,kBAAAC,EAAA,mBAAAC,GAAA,UAAAC,GAAA,6BAAAC,GAAA,yBAAAC,EAAA,wBAAAC,GAAA,iBAAAC,GAAA,eAAAC,GAAA,kBAAAC,GAAA,eAAAC,GAAA,aAAAC,GAAA,uBAAAC,GAAA,gBAAAC,EAAA,iBAAAC,EAAA,aAAAC,GAAA,kBAAAC,EAAA,cAAAC,IAAA,eAAAC,GAAAzB,ICAA,IAAA0B,GAA2B,iBCA3B,IAAAC,GAA8B,iBAiDjBC,KAAgB,kBAAwC,IAAI,ED7ClE,IAAMC,EAAY,IAAM,CAC7B,IAAMC,KAAS,eAAWC,CAAa,EACvC,GAAID,IAAW,KACb,MAAM,IAAI,MAAM,uCAAuC,EAEzD,OAAOA,CACT,EERA,IAAAE,GAAqB,iBASfC,GAAA,6BAJOC,MAA4B,SACvC,CAAC,CAAE,GAAAC,EAAI,QAAAC,EAAS,eAAAC,EAAgB,SAAAC,EAAU,SAAAC,EAAU,GAAGC,CAAM,IAAM,CACjE,IAAMC,EAASC,EAAU,EACzB,SACE,QAAC,KACE,GAAGF,EACJ,KAAML,EACN,QAAUQ,GAAM,CACdA,EAAE,eAAe,EACjBF,EAAO,SAAS,CACd,GAAAN,EACA,QAAAC,EACA,eAAAC,EACA,SAAAC,EACA,SAAAC,CACF,CAAC,CACH,EACF,CAEJ,CACF,EC3BA,IAAAK,GAA8B,iBAajBC,KAAkB,kBAA0C,IAAI,ECV7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E,IAAmB,eACtCS,GAAcM,OACf,OAAC,OAAI,MAAO3B,GACV,mBAAC0C,EAAA,CACC,SACEhC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,mBAAC0B,GAAA,GAAkB1B,EAAuB,CAAG,EAC/C,EACF,KAEF,OAAC,OAEC,MAAO,CACL,SAAU,WACV,MAAO,EACP,UACEP,GAAmBE,IAAmB,cAClC,mBACAS,GAAcE,EAAa,GAAK,CAACM,EACjC,cAAcN,CAAU,MACxB,kBACN,WACEM,GAAgBnB,GAAmBE,IAAmB,cAClD,aAAaC,CAAkB,cAC/B,EACR,EACA,aAAcqB,EACd,YAAaE,EACb,WAAYI,EAEZ,mBAACG,GAAA,EAAa,GAnBT1B,CAoBP,GACGP,GAAmBE,IAAmB,cACtCS,GAAcI,OACf,OAAC,OACC,MAAO,CACL,SAAU,WACV,MAAO,EACP,OAAQ,EACR,UAAW,cACTM,EACI,MACArB,GAAmBmB,EACnB,OACA,GAAG,WAAaN,CAAU,IAChC,IACA,WAAY,aACVb,GAAmBmB,EAAchB,EAAqB,CACxD,YACF,EAEA,mBAAC6B,EAAA,CACC,SACEhC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,mBAAC0B,GAAA,GAAkBhC,GAAyB,KAAO,EACrD,EACF,GAEJ,CAEJ,EAMaiC,GAA8B,CAAC,CAAE,MAAAC,EAAO,GAAGxC,CAAM,OAC5D,OAACyC,GAAA,CAAkB,MAAOD,EACxB,mBAAC5C,GAAA,CAAgB,GAAGI,EAAO,EAC7B","names":["index_exports","__export","DefaultTransitionDuration","Link","LocationContext","LocationProvider","Outlet","RootRouteContext","RouterContext","RouterProvider","Stack","buildPathnameFromMatches","buildUrlFromLocation","createRouterOptions","matchPattern","matchRoute","parseLocation","parseRoute","redirect","resolveRelativeUrl","useLocation","useRootRoute","useRoute","useRouteMatch","useRouter","__toCommonJS","import_react","import_react","RouterContext","useRouter","router","RouterContext","import_react","import_jsx_runtime","Link","to","replace","transitionType","duration","onFinish","props","router","useRouter","e","import_react","LocationContext","import_react","import_jsx_runtime","LocationProvider","location","props","router","useRouter","state","setState","key","value","prev","deleteState","setSearch","LocationContext","a","b","import_react","OutletContext","import_react","useOutlet","OutletContext","import_react","RouteMatchContext","import_react","useRouteMatch","routeMatch","RouteMatchContext","import_jsx_runtime","OutletProvider","depth","props","OutletContext","import_react","useLocation","context","LocationContext","import_react","RouteContext","import_react","useRoute","route","RouteContext","import_react","import_jsx_runtime","RouteComponent","depth","router","useRouter","location","useLocation","routeMatch","useRouteMatch","route","useRoute","pendingStateKey","pending","cause","PendingComponent","NotFoundComponent","Component","Outlet","import_react","import_react","RootRouteContext","useRootRoute","route","RootRouteContext","import_react","import_jsx_runtime","RouteProvider","route","props","RouteContext","state","getRouteState","setRouteState","useRootRoute","getState","key","setState","value","import_jsx_runtime","Outlet","routeMatch","useRouteMatch","depth","useOutlet","OutletProvider","RouteProvider","RouteComponent","import_react","DefaultRouterOptions","DefaultTransitionDuration","redirect","options","matchPattern","pattern","url","pathname","searchParams","urlObj","path","queryString","cleanPath","cleanPattern","pathSegments","patternSegments","params","i","patternSegment","pathSegment","paramName","query","matchRoute","route","_matchRoute","matches","children","childRoute","matchesResult","result","buildPathnameFromMatches","cleanedPathnames","match","parseLocation","href","search","createRouterOptions","DefaultRouterOptions","parseRoute","parseRouteRecursive","parentId","id","child","isPathSegmentValid","segment","resolveRelativeUrl","to","currentPathSegments","toPathSegments","buildUrlFromLocation","location","import_jsx_runtime","RouterProvider","options","props","history","setHistory","parseLocation","currentLocationIndex","setCurrentLocationIndex","location","isTransitioning","setIsTransitioning","transitioningToLocation","setTransitioningToLocation","transitionType","setTransitionType","transitionDuration","setTransitionDuration","canGoBack","canGoForward","buildUrlFromLocation","handlePopState","state","buildLocation","to","replace","index","url","resolveRelativeUrl","pathname","search","searchParams","transitionTo","duration","callback","navigate","onFinish","newLocation","updateHistory","prevHistory","finalTransitionType","back","depth","backDepth","forward","forwardDepth","setLocationState","newState","setLocationSearch","locationIndex","prev","RouterContext","LocationProvider","import_react","import_react","import_jsx_runtime","PageRenderer","rootRoute","useRootRoute","location","useLocation","routeMatch","matchRoute","RouteMatchContext","RouteProvider","RouteComponent","import_react","import_jsx_runtime","RootRouteProvider","route","props","parsedRoute","parseRoute","state","setState","getRouteState","id","key","setRouteState","value","prevState","RootRouteContext","import_jsx_runtime","PreviousComponentStyle","StackComponent","allowSwipeBack","allowSwipeForward","style","props","history","location","canGoBack","canGoForward","isTransitioning","transitioningToLocation","transitionType","transitionDuration","back","forward","useRouter","currentLocationIndex","isTouching","startX","startY","isDragging","setIsDragging","dragOffset","setDragOffset","showPreviousComponent","setShowPreviousComponent","showNextComponent","setShowNextComponent","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","reset","handleTouchStart","e","handleTouchMove","clientX","clientY","offset","handleTouchEnd","options","LocationProvider","PageRenderer","Stack","route","RootRouteProvider"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
interface Route {
|
|
5
|
-
name?: string;
|
|
6
|
-
pathname?: string;
|
|
7
|
-
beforeLoad?: ({ location }: { location: Location }) => Promise<void>;
|
|
8
|
-
pendingComponent?: React.ComponentType;
|
|
9
|
-
component?: React.ComponentType<{ children?: React.ReactNode }>;
|
|
10
|
-
notFoundComponent?: React.ComponentType;
|
|
11
|
-
children?: Route[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface ParsedRoute extends Route {
|
|
15
|
-
id: string;
|
|
16
|
-
children?: ParsedRoute[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface Location {
|
|
20
|
-
index: number;
|
|
21
|
-
href: string;
|
|
22
|
-
pathname: string;
|
|
23
|
-
search: Record<string, string>;
|
|
24
|
-
state: Record<string, any>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface RouteMatch {
|
|
28
|
-
matches: ParsedRoute[];
|
|
29
|
-
params: Record<string, string>;
|
|
30
|
-
query: Record<string, string>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RouterOptions {
|
|
34
|
-
defaultTransitionType?: (
|
|
35
|
-
fromLocation: Location,
|
|
36
|
-
toLocation: Location
|
|
37
|
-
) => TransitionType;
|
|
38
|
-
/**
|
|
39
|
-
* @default 300
|
|
40
|
-
*/
|
|
41
|
-
defaultTransitionDuration: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type TransitionType = "slide-left" | "slide-right" | "none" | undefined;
|
|
45
|
-
|
|
46
|
-
interface TransitionOptions {
|
|
47
|
-
transitionType?: TransitionType;
|
|
48
|
-
duration?: number;
|
|
49
|
-
onFinish?: () => void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface NavigationOptions {
|
|
53
|
-
to: string;
|
|
54
|
-
replace?: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface HistoryTraversalOptions {
|
|
58
|
-
depth?: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type NavigateActionOptions = TransitionOptions & NavigationOptions;
|
|
62
|
-
type BackActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
63
|
-
type ForwardActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
64
|
-
|
|
65
|
-
type LinkProps = React.ComponentPropsWithoutRef<"a"> & NavigateActionOptions;
|
|
66
|
-
declare const Link: React.FC<LinkProps>;
|
|
67
|
-
|
|
68
|
-
declare const LocationProvider: react.MemoExoticComponent<({ location, ...props }: {
|
|
69
|
-
location: Location;
|
|
70
|
-
children: React.ReactNode;
|
|
71
|
-
}) => react_jsx_runtime.JSX.Element>;
|
|
72
|
-
|
|
73
|
-
declare const Outlet: () => react_jsx_runtime.JSX.Element;
|
|
74
|
-
|
|
75
|
-
declare const RouterProvider: ({ options, ...props }: {
|
|
76
|
-
options: RouterOptions;
|
|
77
|
-
children: React.ReactNode;
|
|
78
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
79
|
-
|
|
80
|
-
interface StackComponentProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
81
|
-
allowSwipeForward?: boolean;
|
|
82
|
-
allowSwipeBack?: boolean;
|
|
83
|
-
}
|
|
84
|
-
interface StackProps extends StackComponentProps {
|
|
85
|
-
route: Route;
|
|
86
|
-
}
|
|
87
|
-
declare const Stack: React.FC<StackProps>;
|
|
88
|
-
|
|
89
|
-
interface LocationContextType extends Location {
|
|
90
|
-
canGoBack: boolean;
|
|
91
|
-
canGoForward: boolean;
|
|
92
|
-
state: Record<string, any>;
|
|
93
|
-
setState: (key: string, value: any) => void;
|
|
94
|
-
deleteState: (key: string) => void;
|
|
95
|
-
setSearch: (key: string, value: string) => void;
|
|
96
|
-
}
|
|
97
|
-
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
98
|
-
|
|
99
|
-
interface RootRouteContextType extends ParsedRoute {
|
|
100
|
-
state: Record<string, Record<string, any>>;
|
|
101
|
-
getRouteState: (id: string, key: string) => any;
|
|
102
|
-
setRouteState: (id: string, key: string, value: any) => void;
|
|
103
|
-
}
|
|
104
|
-
declare const RootRouteContext: react.Context<RootRouteContextType | null>;
|
|
105
|
-
|
|
106
|
-
interface RouterContextType {
|
|
107
|
-
options: RouterOptions;
|
|
108
|
-
history: Location[];
|
|
109
|
-
location: Location;
|
|
110
|
-
canGoBack: boolean;
|
|
111
|
-
canGoForward: boolean;
|
|
112
|
-
isTransitioning: boolean;
|
|
113
|
-
transitioningToLocation?: Location;
|
|
114
|
-
transitionType?: TransitionType;
|
|
115
|
-
transitionDuration: number;
|
|
116
|
-
buildLocation: (to: NavigationOptions) => Location;
|
|
117
|
-
navigate: (options: NavigateActionOptions) => void;
|
|
118
|
-
back: (options?: BackActionOptions) => void;
|
|
119
|
-
forward: (options?: ForwardActionOptions) => void;
|
|
120
|
-
setLocationState: (index: number, state: Record<string, any> | ((prev: Record<string, any>) => Record<string, any>)) => void;
|
|
121
|
-
setLocationSearch: (locationIndex: number, search: Record<string, string>) => void;
|
|
122
|
-
}
|
|
123
|
-
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
124
|
-
|
|
125
|
-
declare const useLocation: () => LocationContextType;
|
|
126
|
-
|
|
127
|
-
declare const useRootRoute: () => RootRouteContextType;
|
|
128
|
-
|
|
129
|
-
interface RouteContextType extends ParsedRoute {
|
|
130
|
-
state: Record<string, any>;
|
|
131
|
-
getState: (key: string) => any;
|
|
132
|
-
setState: (key: string, value: any) => void;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
declare const useRoute: () => RouteContextType;
|
|
136
|
-
|
|
137
|
-
declare const useRouteMatch: () => RouteMatch;
|
|
138
|
-
|
|
139
|
-
declare const useRouter: () => RouterContextType;
|
|
140
|
-
|
|
141
|
-
declare const DefaultTransitionDuration = 300;
|
|
142
|
-
declare const redirect: (options: NavigateActionOptions) => Error;
|
|
143
|
-
/**
|
|
144
|
-
* @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.
|
|
145
|
-
* @param url URL to match against the pattern. Can be href or pathname with query string.
|
|
146
|
-
* @returns extracted params and query if matched, otherwise null
|
|
147
|
-
*/
|
|
148
|
-
declare const matchPattern: (pattern: string, url: string) => {
|
|
149
|
-
params: Record<string, string>;
|
|
150
|
-
query: Record<string, string>;
|
|
151
|
-
} | null;
|
|
152
|
-
declare const matchRoute: (route: ParsedRoute, url: string) => RouteMatch;
|
|
153
|
-
declare const buildPathnameFromMatches: (matches: Route[]) => string;
|
|
154
|
-
declare const parseLocation: ({ href, pathname, search, }: globalThis.Location) => Location;
|
|
155
|
-
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
156
|
-
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
157
|
-
/**
|
|
158
|
-
* Resolves a relative path against a base url.
|
|
159
|
-
* @param url The base url.
|
|
160
|
-
* @param to The relative path to resolve.
|
|
161
|
-
* @returns The resolved absolute url.
|
|
162
|
-
*/
|
|
163
|
-
declare const resolveRelativeUrl: (url: string, to: string) => string;
|
|
164
|
-
declare const buildUrlFromLocation: (location: Location) => string;
|
|
165
|
-
|
|
166
|
-
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackComponentProps, type StackProps, type TransitionOptions, type TransitionType, buildPathnameFromMatches, buildUrlFromLocation, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect, resolveRelativeUrl, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|
package/dist/index.d.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
interface Route {
|
|
5
|
-
name?: string;
|
|
6
|
-
pathname?: string;
|
|
7
|
-
beforeLoad?: ({ location }: { location: Location }) => Promise<void>;
|
|
8
|
-
pendingComponent?: React.ComponentType;
|
|
9
|
-
component?: React.ComponentType<{ children?: React.ReactNode }>;
|
|
10
|
-
notFoundComponent?: React.ComponentType;
|
|
11
|
-
children?: Route[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface ParsedRoute extends Route {
|
|
15
|
-
id: string;
|
|
16
|
-
children?: ParsedRoute[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface Location {
|
|
20
|
-
index: number;
|
|
21
|
-
href: string;
|
|
22
|
-
pathname: string;
|
|
23
|
-
search: Record<string, string>;
|
|
24
|
-
state: Record<string, any>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface RouteMatch {
|
|
28
|
-
matches: ParsedRoute[];
|
|
29
|
-
params: Record<string, string>;
|
|
30
|
-
query: Record<string, string>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RouterOptions {
|
|
34
|
-
defaultTransitionType?: (
|
|
35
|
-
fromLocation: Location,
|
|
36
|
-
toLocation: Location
|
|
37
|
-
) => TransitionType;
|
|
38
|
-
/**
|
|
39
|
-
* @default 300
|
|
40
|
-
*/
|
|
41
|
-
defaultTransitionDuration: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type TransitionType = "slide-left" | "slide-right" | "none" | undefined;
|
|
45
|
-
|
|
46
|
-
interface TransitionOptions {
|
|
47
|
-
transitionType?: TransitionType;
|
|
48
|
-
duration?: number;
|
|
49
|
-
onFinish?: () => void;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface NavigationOptions {
|
|
53
|
-
to: string;
|
|
54
|
-
replace?: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface HistoryTraversalOptions {
|
|
58
|
-
depth?: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type NavigateActionOptions = TransitionOptions & NavigationOptions;
|
|
62
|
-
type BackActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
63
|
-
type ForwardActionOptions = TransitionOptions & HistoryTraversalOptions;
|
|
64
|
-
|
|
65
|
-
type LinkProps = React.ComponentPropsWithoutRef<"a"> & NavigateActionOptions;
|
|
66
|
-
declare const Link: React.FC<LinkProps>;
|
|
67
|
-
|
|
68
|
-
declare const LocationProvider: react.MemoExoticComponent<({ location, ...props }: {
|
|
69
|
-
location: Location;
|
|
70
|
-
children: React.ReactNode;
|
|
71
|
-
}) => react_jsx_runtime.JSX.Element>;
|
|
72
|
-
|
|
73
|
-
declare const Outlet: () => react_jsx_runtime.JSX.Element;
|
|
74
|
-
|
|
75
|
-
declare const RouterProvider: ({ options, ...props }: {
|
|
76
|
-
options: RouterOptions;
|
|
77
|
-
children: React.ReactNode;
|
|
78
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
79
|
-
|
|
80
|
-
interface StackComponentProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
81
|
-
allowSwipeForward?: boolean;
|
|
82
|
-
allowSwipeBack?: boolean;
|
|
83
|
-
}
|
|
84
|
-
interface StackProps extends StackComponentProps {
|
|
85
|
-
route: Route;
|
|
86
|
-
}
|
|
87
|
-
declare const Stack: React.FC<StackProps>;
|
|
88
|
-
|
|
89
|
-
interface LocationContextType extends Location {
|
|
90
|
-
canGoBack: boolean;
|
|
91
|
-
canGoForward: boolean;
|
|
92
|
-
state: Record<string, any>;
|
|
93
|
-
setState: (key: string, value: any) => void;
|
|
94
|
-
deleteState: (key: string) => void;
|
|
95
|
-
setSearch: (key: string, value: string) => void;
|
|
96
|
-
}
|
|
97
|
-
declare const LocationContext: react.Context<LocationContextType | null>;
|
|
98
|
-
|
|
99
|
-
interface RootRouteContextType extends ParsedRoute {
|
|
100
|
-
state: Record<string, Record<string, any>>;
|
|
101
|
-
getRouteState: (id: string, key: string) => any;
|
|
102
|
-
setRouteState: (id: string, key: string, value: any) => void;
|
|
103
|
-
}
|
|
104
|
-
declare const RootRouteContext: react.Context<RootRouteContextType | null>;
|
|
105
|
-
|
|
106
|
-
interface RouterContextType {
|
|
107
|
-
options: RouterOptions;
|
|
108
|
-
history: Location[];
|
|
109
|
-
location: Location;
|
|
110
|
-
canGoBack: boolean;
|
|
111
|
-
canGoForward: boolean;
|
|
112
|
-
isTransitioning: boolean;
|
|
113
|
-
transitioningToLocation?: Location;
|
|
114
|
-
transitionType?: TransitionType;
|
|
115
|
-
transitionDuration: number;
|
|
116
|
-
buildLocation: (to: NavigationOptions) => Location;
|
|
117
|
-
navigate: (options: NavigateActionOptions) => void;
|
|
118
|
-
back: (options?: BackActionOptions) => void;
|
|
119
|
-
forward: (options?: ForwardActionOptions) => void;
|
|
120
|
-
setLocationState: (index: number, state: Record<string, any> | ((prev: Record<string, any>) => Record<string, any>)) => void;
|
|
121
|
-
setLocationSearch: (locationIndex: number, search: Record<string, string>) => void;
|
|
122
|
-
}
|
|
123
|
-
declare const RouterContext: react.Context<RouterContextType | null>;
|
|
124
|
-
|
|
125
|
-
declare const useLocation: () => LocationContextType;
|
|
126
|
-
|
|
127
|
-
declare const useRootRoute: () => RootRouteContextType;
|
|
128
|
-
|
|
129
|
-
interface RouteContextType extends ParsedRoute {
|
|
130
|
-
state: Record<string, any>;
|
|
131
|
-
getState: (key: string) => any;
|
|
132
|
-
setState: (key: string, value: any) => void;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
declare const useRoute: () => RouteContextType;
|
|
136
|
-
|
|
137
|
-
declare const useRouteMatch: () => RouteMatch;
|
|
138
|
-
|
|
139
|
-
declare const useRouter: () => RouterContextType;
|
|
140
|
-
|
|
141
|
-
declare const DefaultTransitionDuration = 300;
|
|
142
|
-
declare const redirect: (options: NavigateActionOptions) => Error;
|
|
143
|
-
/**
|
|
144
|
-
* @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.
|
|
145
|
-
* @param url URL to match against the pattern. Can be href or pathname with query string.
|
|
146
|
-
* @returns extracted params and query if matched, otherwise null
|
|
147
|
-
*/
|
|
148
|
-
declare const matchPattern: (pattern: string, url: string) => {
|
|
149
|
-
params: Record<string, string>;
|
|
150
|
-
query: Record<string, string>;
|
|
151
|
-
} | null;
|
|
152
|
-
declare const matchRoute: (route: ParsedRoute, url: string) => RouteMatch;
|
|
153
|
-
declare const buildPathnameFromMatches: (matches: Route[]) => string;
|
|
154
|
-
declare const parseLocation: ({ href, pathname, search, }: globalThis.Location) => Location;
|
|
155
|
-
declare const createRouterOptions: (options?: Partial<RouterOptions>) => RouterOptions;
|
|
156
|
-
declare const parseRoute: (route: Route) => ParsedRoute;
|
|
157
|
-
/**
|
|
158
|
-
* Resolves a relative path against a base url.
|
|
159
|
-
* @param url The base url.
|
|
160
|
-
* @param to The relative path to resolve.
|
|
161
|
-
* @returns The resolved absolute url.
|
|
162
|
-
*/
|
|
163
|
-
declare const resolveRelativeUrl: (url: string, to: string) => string;
|
|
164
|
-
declare const buildUrlFromLocation: (location: Location) => string;
|
|
165
|
-
|
|
166
|
-
export { type BackActionOptions, DefaultTransitionDuration, type ForwardActionOptions, type HistoryTraversalOptions, Link, type LinkProps, type Location, LocationContext, type LocationContextType, LocationProvider, type NavigateActionOptions, type NavigationOptions, Outlet, type ParsedRoute, RootRouteContext, type RootRouteContextType, type Route, type RouteMatch, RouterContext, type RouterContextType, type RouterOptions, RouterProvider, Stack, type StackComponentProps, type StackProps, type TransitionOptions, type TransitionType, buildPathnameFromMatches, buildUrlFromLocation, createRouterOptions, matchPattern, matchRoute, parseLocation, parseRoute, redirect, resolveRelativeUrl, useLocation, useRootRoute, useRoute, useRouteMatch, useRouter };
|
package/dist/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{useContext as bt}from"react";import{createContext as Ot}from"react";var Y=Ot(null);var O=()=>{let t=bt(Y);if(t===null)throw new Error("useRouter must be used within a Stack");return t};import{memo as kt}from"react";import{jsx as Mt}from"react/jsx-runtime";var le=kt(({to:t,replace:n,transitionType:o,duration:a,onFinish:e,...p})=>{let s=O();return Mt("a",{...p,href:t,onClick:i=>{i.preventDefault(),s.navigate({to:t,replace:n,transitionType:o,duration:a,onFinish:e})}})});import{createContext as Nt}from"react";var z=Nt(null);import{memo as At,useCallback as rt,useMemo as Ft}from"react";import{jsx as Et}from"react/jsx-runtime";var B=At(({location:t,...n})=>{let o=O(),a=Ft(()=>t.state,[t]),e=rt((i,r)=>{o.setLocationState(t.index,v=>({...v,[i]:r}))},[o,t]),p=rt(i=>{o.setLocationState(t.index,r=>(delete r[i],r))},[o,t]),s=rt((i,r)=>{o.setLocationSearch(t.index,{...t.search,[i]:r})},[o,t]);return Et(z.Provider,{value:{...t,canGoBack:!o.isTransitioning&&t.index>0,canGoForward:!o.isTransitioning&&t.index+1<o.history.length,state:a,setState:e,deleteState:p,setSearch:s},...n})},(t,n)=>t.location===n.location);import{createContext as Dt}from"react";var _=Dt(0);import{useContext as $t}from"react";var ut=()=>$t(_);import{createContext as jt}from"react";var K=jt(null);import{useContext as Wt}from"react";var V=()=>{let t=Wt(K);if(t===null)throw new Error("useRouteMatch must be used within a RouteMatchProvider");return t};import{jsx as Gt}from"react/jsx-runtime";var pt=({depth:t,...n})=>Gt(_.Provider,{value:t,...n});import{useContext as Ut}from"react";var Z=()=>{let t=Ut(z);if(t===null)throw new Error("useLocation must be used within a LocationProvider");return t};import{createContext as Bt}from"react";var I=Bt(null);import{useContext as It}from"react";var mt=()=>{let t=It(I);if(t===null)throw new Error("useRoute must be used within a RouteProvider");return t};import{useEffect as Xt}from"react";import{jsx as J}from"react/jsx-runtime";var Q=({depth:t=0})=>{let n=O(),o=Z(),a=V(),e=mt(),p=`_Z.${e.id}.pending`,s=!!e.beforeLoad&&e.getState(p)!==!1;if(Xt(()=>{e&&e.beforeLoad&&e.getState(p)===void 0&&(e.setState(p,!0),e.beforeLoad?.({location:o}).then(()=>e.setState(p,!1)).catch(({cause:r})=>{r&&"to"in r?(console.log("Redirecting to:",r.to),n.navigate({...r,onFinish:()=>{e.setState(p,!1)}})):e.setState(p,!1)}))},[e]),!e)return null;if(s){let r=e.pendingComponent;return J(r,{})}if(t>=a.matches.length){let r=e.notFoundComponent;return J(r,{})}let i=e.component;return i?J(i,{}):J(dt,{})};import{useContext as qt}from"react";import{createContext as Ht}from"react";var tt=Ht(null);var et=()=>{let t=qt(tt);if(t===null)throw new Error("useRootRoute must be used within a RootRouteProvider");return t};import{useCallback as lt}from"react";import{jsx as ft}from"react/jsx-runtime";var ot=({route:t,...n})=>{if(!t)return ft(I.Provider,{value:null,...n});let{state:o,getRouteState:a,setRouteState:e}=et(),p=lt(i=>a(t.id,i),[a,t.id]),s=lt((i,r)=>{e(t.id,i,r)},[e,t.id]);return ft(I.Provider,{value:{...t,state:o[t.id],getState:p,setState:s},...n})};import{jsx as it}from"react/jsx-runtime";var dt=()=>{let t=V(),n=ut()+1;return it(pt,{depth:n,children:it(ot,{route:t.matches.at(n),children:it(Q,{depth:n})})})};import{useCallback as E,useEffect as Tt,useMemo as _t,useState as D}from"react";var Rt={defaultTransitionDuration:300};var Do=300,$o=t=>new Error("",{cause:t}),Yt=(t,n)=>{try{let o,a;if(n.startsWith("http://")||n.startsWith("https://")){let f=new URL(n);o=f.pathname,a=f.searchParams}else{let[f,y]=n.split("?");if(!f)return null;o=f,a=new URLSearchParams(y||"")}let e=o.replaceAll(/^\/|\/$/g,""),p=t.replaceAll(/^\/|\/$/g,""),s=e.split("/"),i=p.split("/");if(s.length!==i.length)return null;let r={};for(let f=0;f<i.length;f++){let y=i[f],S=s[f];if(y.startsWith(":")){let M=y.slice(1);r[M]=decodeURIComponent(S)}else if(y!==S)return null}let v=Object.fromEntries(a.entries());return{params:r,query:v}}catch{return null}},gt=(t,n)=>{let o=(a,{children:e})=>{if(e&&e.length>0){for(let s of e){let i=o([...a,s],s);if(i)return i}return null}let p=Yt(zt(a),n);return p?{matches:a,...p}:null};return o([t],t)||{matches:[],params:{},query:{}}},zt=t=>{let n=[];for(let o of t)o.pathname!==void 0&&n.push(o.pathname.replaceAll(/^\/|\/$/g,""));return"/"+n.join("/")},xt=({href:t,pathname:n,search:o})=>({index:0,href:t,state:{index:0},pathname:n,search:Object.fromEntries(new URLSearchParams(o))}),jo=t=>({...Rt,...t}),yt=t=>{let n=(o,a)=>{let e=o.name??(o.pathname?`${a}/${o.pathname.replaceAll(/^\/|\/$/g,"")}`:a);return{...o,id:e,children:o.children?.map(s=>n(s,e))}};return n(t,"")},ht=t=>t.length>0,vt=(t,n)=>{let o=t.split("/").filter(ht),a=n.split("/").filter(ht);for(let e of a)e!=="."&&(e===".."?o.pop():o.push(e));return"/"+o.join("/")},F=t=>{let n=new URLSearchParams(t.search).toString();return n?`${t.pathname}?${n}`:t.pathname};import{jsx as Pt}from"react/jsx-runtime";var Ho=({options:t,...n})=>{let[o,a]=D([xt(window.location)]),[e,p]=D(0),s=_t(()=>o.at(e),[o,e]),[i,r]=D(!1),[v,f]=D(),[y,S]=D(),[M,L]=D(0),b=!i&&e>0,j=!i&&e+1<o.length;Tt(()=>{window.history.replaceState(s.state,"",F(s))},[]),Tt(()=>{let m=({state:d})=>{p(d?.index)};return addEventListener("popstate",m),()=>{removeEventListener("popstate",m)}},[e]);let W=E(({to:m,replace:d})=>{if(!m)return s;let h=d?e:e+1,l=m.startsWith("/")?m:vt(s.pathname,m),[x,R]=l.split("?"),g=new URLSearchParams(R??""),P={index:h};return{index:h,href:origin+x+(R?`?${g.toString()}`:""),search:Object.fromEntries(g.entries()),state:P,pathname:x}},[e,s]),T=(m,d,h=t.defaultTransitionDuration,l)=>{r(!0),S(d),L(h),f(m),setTimeout(()=>{r(!1),S(void 0),f(void 0),l?.()},h)},X=E(({to:m,replace:d,transitionType:h,duration:l,onFinish:x})=>{if(i)return;let R=d?e:e+1,g=W({to:m,replace:d}),P=()=>{d?(a(N=>[...N.slice(0,R),g,...N.slice(R+1)]),window.history.replaceState(g.state,"",F(g))):(a(N=>[...N.slice(0,R),g]),p(R),window.history.pushState(g.state,"",F(g))),x?.()},q=h??t.defaultTransitionType?.(s,g)??"slide-left";q?T(g,q,l,P):P()},[e,o,i,t]),w=E(({transitionType:m,duration:d,onFinish:h,depth:l}={})=>{if(!b)return;let x=l??1,R=o.at(e-x);if(!R)return;let g=()=>{window.history.go(-x),h?.()},P=m??t.defaultTransitionType?.(s,R)??"slide-right";P?T(R,P,d,g):g()},[e,o,i,t]),G=E(({transitionType:m,duration:d,depth:h,onFinish:l}={})=>{if(!j)return;let x=h??1,R=o.at(e+x);if(!R)return;let g=()=>{window.history.go(x),l?.()},P=m??t.defaultTransitionType?.(s,R)??"slide-left";P?T(R,P,d,g):g()},[e,o,i,t]),U=E((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x=typeof d=="function"?d(l.state):d,R={...l,state:x};return m===e&&window.history.replaceState(x,"",F(R)),R}))},[e]),H=E((m,d)=>{a(h=>h.map(l=>{if(l.index!==m)return l;let x={...l,search:{...l.search,...d}};return m===e&&window.history.replaceState(x.state,"",F(x)),x}))},[]);return Pt(Y.Provider,{value:{options:t,history:o,location:s,canGoBack:b,canGoForward:j,isTransitioning:i,transitioningToLocation:v,transitionType:y,transitionDuration:M,buildLocation:W,navigate:X,back:w,forward:G,setLocationState:U,setLocationSearch:H},children:Pt(B,{location:s,...n})})};import{useCallback as at,useEffect as te,useRef as ct,useState as $}from"react";import{memo as Kt,useMemo as Vt}from"react";import{jsx as st}from"react/jsx-runtime";var nt=Kt(()=>{let t=et(),n=Z(),o=Vt(()=>gt(t,n.pathname),[t,n.pathname]);return st(K.Provider,{value:o,children:st(ot,{route:t,children:st(Q,{})})})});import{useCallback as Lt,useMemo as Zt,useState as Jt}from"react";import{jsx as Qt}from"react/jsx-runtime";var Ct=({route:t,...n})=>{let o=Zt(()=>yt(t),[t]),[a,e]=Jt({}),p=Lt((i,r)=>a[i]?.[r],[a]),s=Lt((i,r,v)=>{e(f=>({...f,[i]:{...f[i],[r]:v}}))},[]);return Qt(tt.Provider,{value:{...o,state:a,getRouteState:p,setRouteState:s},...n})};import{jsx as C,jsxs as ne}from"react/jsx-runtime";var ee={position:"absolute",inset:0,zIndex:-1},oe=({allowSwipeBack:t=!0,allowSwipeForward:n=!0,style:o,...a})=>{let{history:e,location:p,canGoBack:s,canGoForward:i,isTransitioning:r,transitioningToLocation:v,transitionType:f,transitionDuration:y,back:S,forward:M}=O(),L=p.index,b=ct(!1),j=ct(0),W=ct(0),[T,X]=$(!1),[w,G]=$(0),[U,H]=$(!1),[m,d]=$(!1),[h,l]=$(!1),[x,R]=$(!1);if(te(()=>{!r||!v||(R(!0),setTimeout(()=>{R(!1)},y))},[r,v,y]),L===void 0)return;let g=()=>{X(!1),G(0),H(!1),d(!1),l(!1)},P=at(k=>{r||!i&&!s||(b.current=!0,j.current=k.touches[0].clientX,W.current=k.touches[0].clientY)},[r,s,i]),q=at(k=>{if(!b.current)return;let{clientX:St,clientY:wt}=k.touches[0];if(!T&&Math.abs(wt-W.current)>30){b.current=!1;return}let A=St-j.current;if(!(Math.abs(A)<10)){if(T||X(!0),A>0&&L===0||A<0&&L+1===e.length){G(0);return}!U&&A<0&&n&&H(!0),!m&&A>0&&t&&d(!0),G(Math.max(Math.min(A,window.innerWidth),-window.innerWidth))}},[T,L,e.length,U,m,t,n]),N=at(()=>{if(b.current=!1,!T)return;let k={onFinish:g};w>innerWidth*.3&&s&&t?S(k):w<-innerWidth*.3&&i&&n?M(k):(l(!0),setTimeout(g,y))},[S,M,T,w,s,i,y]);return ne("div",{style:{position:"relative",overflow:"hidden",...o},...a,children:[(r&&f==="slide-right"||T&&m)&&C("div",{style:ee,children:C(B,{location:r?v:e.at(L-1),children:C(nt,{},L-1)})}),C("div",{style:{position:"absolute",inset:0,transform:r&&f==="slide-right"?"translateX(100%)":T&&w>0&&!h?`translateX(${w}px)`:"translateX(0px)",transition:h||r&&f==="slide-right"?`transform ${y}ms ease-out`:""},onTouchStart:P,onTouchMove:q,onTouchEnd:N,children:C(nt,{})},L),(r&&f==="slide-left"||T&&U)&&C("div",{style:{position:"absolute",inset:0,zIndex:1,transform:`translateX(${x?"0px":r||h?"100%":`${innerWidth+w}px`})`,transition:`transform ${r||h?y:0}ms ease-in`},children:C(B,{location:r?v:e.at(L+1),children:C(nt,{},v?.index)})})]})},hn=({route:t,...n})=>C(Ct,{route:t,children:C(oe,{...n})});export{Do as DefaultTransitionDuration,le as Link,z as LocationContext,B as LocationProvider,dt as Outlet,tt as RootRouteContext,Y as RouterContext,Ho as RouterProvider,hn as Stack,zt as buildPathnameFromMatches,F as buildUrlFromLocation,jo as createRouterOptions,Yt as matchPattern,gt as matchRoute,xt as parseLocation,yt as parseRoute,$o as redirect,vt as resolveRelativeUrl,Z as useLocation,et as useRootRoute,mt as useRoute,V as useRouteMatch,O as useRouter};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../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":["import { useContext } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\n\nexport const useRouter = () => {\n const router = useContext(RouterContext);\n if (router === null) {\n throw new Error(\"useRouter must be used within a Stack\");\n }\n return router;\n};\n","import { createContext } from \"react\";\n\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\n\nexport interface RouterContextType {\n // Router Config\n options: RouterOptions;\n\n // Navigation State\n history: Location[];\n location: Location;\n canGoBack: boolean;\n canGoForward: boolean;\n\n // Transition state\n isTransitioning: boolean;\n transitioningToLocation?: Location;\n transitionType?: TransitionType;\n transitionDuration: number;\n\n // Utilities\n buildLocation: (to: NavigationOptions) => Location;\n\n // Navigation Actions\n navigate: (options: NavigateActionOptions) => void;\n back: (options?: BackActionOptions) => void;\n forward: (options?: ForwardActionOptions) => void;\n\n // Low-level state action\n setLocationState: (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => void;\n setLocationSearch: (\n locationIndex: number,\n search: Record<string, string>\n ) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | null>(null);\n","import { useRouter } from \"@/hooks/useRouter.js\";\nimport type { NavigateActionOptions } from \"@/types.js\";\nimport { memo } from \"react\";\n\nexport type LinkProps = React.ComponentPropsWithoutRef<\"a\"> &\n NavigateActionOptions;\n\nexport const Link: React.FC<LinkProps> = memo(\n ({ to, replace, transitionType, duration, onFinish, ...props }) => {\n const router = useRouter();\n return (\n <a\n {...props}\n href={to}\n onClick={(e) => {\n e.preventDefault();\n router.navigate({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n });\n }}\n />\n );\n }\n);\n","import { createContext } from \"react\";\n\nimport type { Location } from \"@/types.js\";\n\nexport interface LocationContextType extends Location {\n canGoBack: boolean;\n canGoForward: boolean;\n state: Record<string, any>;\n setState: (key: string, value: any) => void;\n deleteState: (key: string) => void;\n setSearch: (key: string, value: string) => void;\n}\n\nexport const LocationContext = createContext<LocationContextType | null>(null);\n","import { LocationContext } from \"@/context/location-context.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Location } from \"@/types.js\";\nimport { memo, useCallback, useMemo } from \"react\";\n\nexport const LocationProvider = memo(\n ({\n location,\n ...props\n }: {\n location: Location;\n children: React.ReactNode;\n }) => {\n const router = useRouter();\n const state = useMemo(() => location.state, [location]);\n const setState = useCallback(\n (key: string, value: any) => {\n router.setLocationState(location.index, (prev) => ({\n ...prev,\n [key]: value,\n }));\n },\n [router, location]\n );\n const deleteState = useCallback(\n (key: string) => {\n router.setLocationState(location.index, (prev) => {\n delete prev[key];\n return prev;\n });\n },\n [router, location]\n );\n const setSearch = useCallback(\n (key: string, value: string) => {\n router.setLocationSearch(location.index, {\n ...location.search,\n [key]: value,\n });\n },\n [router, location]\n );\n return (\n <LocationContext.Provider\n value={{\n ...location,\n canGoBack: !router.isTransitioning && location.index > 0,\n canGoForward:\n !router.isTransitioning &&\n location.index + 1 < router.history.length,\n state,\n setState,\n deleteState,\n setSearch,\n }}\n {...props}\n />\n );\n },\n (a, b) => a.location === b.location\n);\n","import { createContext } from \"react\";\n\nexport const OutletContext = createContext<number>(0);\n","import { OutletContext } from \"@/context/outlet-context.js\";\nimport { useContext } from \"react\";\n\nexport const useOutlet = () => useContext(OutletContext);\n","import type { RouteMatch } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport const RouteMatchContext = createContext<RouteMatch | null>(null);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRouteMatch = () => {\n const routeMatch = useContext(RouteMatchContext);\n if (routeMatch === null) {\n throw new Error(\"useRouteMatch must be used within a RouteMatchProvider\");\n }\n return routeMatch;\n};\n","import { OutletContext } from \"@/context/outlet-context.js\";\n\nexport const OutletProvider = ({\n depth,\n ...props\n}: {\n depth: number;\n children?: React.ReactNode;\n}) => <OutletContext.Provider value={depth} {...props} />;\n","import { useContext } from \"react\";\n\nimport { LocationContext } from \"@/context/location-context.js\";\n\nexport const useLocation = () => {\n const context = useContext(LocationContext);\n if (context === null) {\n throw new Error(\"useLocation must be used within a LocationProvider\");\n }\n return context;\n};\n","import type { ParsedRoute } from \"@/types.js\";\nimport { createContext } from \"react\";\n\nexport interface RouteContextType extends ParsedRoute {\n state: Record<string, any>;\n getState: (key: string) => any;\n setState: (key: string, value: any) => void;\n}\n\nexport const RouteContext = createContext<RouteContextType | null>(null);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useContext } from \"react\";\n\nexport const useRoute = () => {\n const route = useContext(RouteContext);\n if (route === null) {\n throw new Error(\"useRoute must be used within a RouteProvider\");\n }\n return route;\n};\n","import { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRoute } from \"@/hooks/useRoute.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport { useEffect } from \"react\";\nimport { Outlet } from \"./outlet.js\";\n\nexport const RouteComponent = ({ depth = 0 }: { depth?: number }) => {\n const router = useRouter();\n const location = useLocation();\n const routeMatch = useRouteMatch();\n const route = useRoute();\n\n const pendingStateKey = `_Z.${route.id}.pending`;\n const pending =\n !!route.beforeLoad && route.getState(pendingStateKey) !== false;\n\n useEffect(() => {\n if (!route) {\n return;\n }\n if (route.beforeLoad && route.getState(pendingStateKey) === undefined) {\n route.setState(pendingStateKey, true);\n route\n .beforeLoad?.({ location })\n .then(() => route.setState(pendingStateKey, false))\n .catch(({ cause }: Error) => {\n if (!!cause && \"to\" in (cause as any)) {\n console.log(\"Redirecting to:\", (cause as any).to);\n router.navigate({\n ...(cause as any),\n onFinish: () => {\n route.setState(pendingStateKey, false);\n },\n });\n } else {\n route.setState(pendingStateKey, false);\n }\n });\n }\n }, [route]);\n\n if (!route) {\n return null;\n }\n\n if (pending) {\n const PendingComponent = route.pendingComponent!;\n return <PendingComponent />;\n }\n\n if (depth >= routeMatch.matches.length) {\n const NotFoundComponent = route.notFoundComponent!;\n return <NotFoundComponent />;\n }\n\n const Component = route.component;\n return Component ? <Component /> : <Outlet />;\n};\n","import { useContext } from \"react\";\n\nimport { RootRouteContext } from \"@/context/root-route-context.js\";\n\nexport const useRootRoute = () => {\n const route = useContext(RootRouteContext);\n if (route === null) {\n throw new Error(\"useRootRoute must be used within a RootRouteProvider\");\n }\n return route;\n};\n","import { createContext } from \"react\";\n\nimport type { ParsedRoute } from \"@/types.js\";\n\nexport interface RootRouteContextType extends ParsedRoute {\n state: Record<string, Record<string, any>>;\n getRouteState: (id: string, key: string) => any;\n setRouteState: (id: string, key: string, value: any) => void;\n}\n\nexport const RootRouteContext = createContext<RootRouteContextType | null>(\n null\n);\n","import { RouteContext } from \"@/context/route-context.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport type { ParsedRoute } from \"@/types.js\";\nimport { useCallback } from \"react\";\n\nexport const RouteProvider = ({\n route,\n ...props\n}: {\n route?: ParsedRoute;\n children?: React.ReactNode;\n}) => {\n if (!route) {\n return <RouteContext.Provider value={null} {...props} />;\n }\n\n const { state, getRouteState, setRouteState } = useRootRoute();\n\n const getState = useCallback(\n (key: string) => getRouteState(route.id, key),\n [getRouteState, route.id]\n );\n\n const setState = useCallback(\n (key: string, value: any) => {\n setRouteState(route.id, key, value);\n },\n [setRouteState, route.id]\n );\n\n return (\n <RouteContext.Provider\n value={{ ...route, state: state[route.id], getState, setState }}\n {...props}\n />\n );\n};\n","import { useOutlet } from \"@/hooks/useOutlet.js\";\nimport { useRouteMatch } from \"@/hooks/useRouteMatch.js\";\nimport { OutletProvider } from \"./outlet-provider.js\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const Outlet = () => {\n const routeMatch = useRouteMatch();\n const depth = useOutlet() + 1;\n return (\n <OutletProvider depth={depth}>\n <RouteProvider route={routeMatch.matches.at(depth)}>\n <RouteComponent depth={depth} />\n </RouteProvider>\n </OutletProvider>\n );\n};\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { RouterContext } from \"@/context/router-context.js\";\nimport type {\n BackActionOptions,\n ForwardActionOptions,\n Location,\n NavigateActionOptions,\n NavigationOptions,\n RouterOptions,\n TransitionType,\n} from \"@/types.js\";\nimport {\n buildUrlFromLocation,\n parseLocation,\n resolveRelativeUrl,\n} from \"@/utils.js\";\nimport { LocationProvider } from \"./location-provider.js\";\n\nexport const RouterProvider = ({\n options,\n ...props\n}: {\n options: RouterOptions;\n children: React.ReactNode;\n}) => {\n const [history, setHistory] = useState<Location[]>([\n parseLocation(window.location),\n ]);\n const [currentLocationIndex, setCurrentLocationIndex] = useState<number>(0);\n const location = useMemo(\n () => history.at(currentLocationIndex)!,\n [history, currentLocationIndex]\n );\n const [isTransitioning, setIsTransitioning] = useState<boolean>(false);\n const [transitioningToLocation, setTransitioningToLocation] =\n useState<Location>();\n const [transitionType, setTransitionType] = useState<TransitionType>();\n const [transitionDuration, setTransitionDuration] = useState<number>(0);\n\n const canGoBack = !isTransitioning && currentLocationIndex > 0;\n const canGoForward =\n !isTransitioning && currentLocationIndex + 1 < history.length;\n\n useEffect(() => {\n window.history.replaceState(\n location.state,\n \"\",\n buildUrlFromLocation(location)\n );\n }, []);\n\n useEffect(() => {\n const handlePopState = ({ state }: PopStateEvent) => {\n setCurrentLocationIndex(state?.index);\n };\n\n addEventListener(\"popstate\", handlePopState);\n return () => {\n removeEventListener(\"popstate\", handlePopState);\n };\n }, [currentLocationIndex]);\n\n // Utilities\n const buildLocation = useCallback(\n ({ to, replace }: NavigationOptions): Location => {\n if (!to) return location;\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n\n // Resolve to with absolute or relative paths like \"..\" or \".\"\n const url = to.startsWith(\"/\")\n ? to\n : resolveRelativeUrl(location.pathname, to);\n const [pathname, search] = url.split(\"?\");\n const searchParams = new URLSearchParams(search ?? \"\");\n const state = {\n index,\n };\n return {\n index,\n href: origin + pathname + (search ? `?${searchParams.toString()}` : \"\"),\n search: Object.fromEntries(searchParams.entries()),\n state,\n pathname,\n };\n },\n [currentLocationIndex, location]\n );\n\n // Transition helper\n const transitionTo = (\n location: Location,\n transitionType: TransitionType,\n duration: number = options.defaultTransitionDuration,\n callback?: () => void\n ) => {\n setIsTransitioning(true);\n setTransitionType(transitionType);\n setTransitionDuration(duration);\n setTransitioningToLocation(location);\n setTimeout(() => {\n setIsTransitioning(false);\n setTransitionType(undefined);\n setTransitioningToLocation(undefined);\n callback?.();\n }, duration);\n };\n\n // Navigation actions\n const navigate = useCallback(\n ({\n to,\n replace,\n transitionType,\n duration,\n onFinish,\n }: NavigateActionOptions) => {\n if (isTransitioning) return;\n\n const index = replace ? currentLocationIndex : currentLocationIndex + 1;\n const newLocation = buildLocation({ to, replace });\n\n const updateHistory = () => {\n if (replace) {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ...prevHistory.slice(index + 1),\n ]);\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n } else {\n setHistory((prevHistory) => [\n ...prevHistory.slice(0, index),\n newLocation,\n ]);\n setCurrentLocationIndex(index);\n window.history.pushState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const back = useCallback(\n ({ transitionType, duration, onFinish, depth }: BackActionOptions = {}) => {\n if (!canGoBack) return;\n const backDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex - backDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(-backDepth);\n onFinish?.();\n };\n\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-right\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n const forward = useCallback(\n ({\n transitionType,\n duration,\n depth,\n onFinish,\n }: ForwardActionOptions = {}) => {\n if (!canGoForward) return;\n const forwardDepth = depth ?? 1;\n const newLocation = history.at(currentLocationIndex + forwardDepth);\n if (!newLocation) return;\n\n const updateHistory = () => {\n window.history.go(forwardDepth);\n onFinish?.();\n };\n const finalTransitionType =\n transitionType ??\n options.defaultTransitionType?.(location, newLocation) ??\n \"slide-left\";\n if (finalTransitionType) {\n transitionTo(newLocation, finalTransitionType, duration, updateHistory);\n } else {\n updateHistory();\n }\n },\n [currentLocationIndex, history, isTransitioning, options]\n );\n\n // Low-level state action\n const setLocationState = useCallback(\n (\n index: number,\n state:\n | Record<string, any>\n | ((prev: Record<string, any>) => Record<string, any>)\n ) => {\n setHistory((prevHistory) =>\n prevHistory.map((location) => {\n if (location.index !== index) {\n return location;\n }\n const newState =\n typeof state === \"function\" ? state(location.state) : state;\n const newLocation = { ...location, state: newState };\n if (index === currentLocationIndex) {\n window.history.replaceState(\n newState,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n [currentLocationIndex]\n );\n\n const setLocationSearch = useCallback(\n (locationIndex: number, search: Record<string, string>) => {\n setHistory((prev) =>\n prev.map((location) => {\n if (location.index !== locationIndex) return location;\n const newLocation = {\n ...location,\n search: {\n ...location.search,\n ...search,\n },\n };\n if (locationIndex === currentLocationIndex) {\n window.history.replaceState(\n newLocation.state,\n \"\",\n buildUrlFromLocation(newLocation)\n );\n }\n return newLocation;\n })\n );\n },\n []\n );\n\n return (\n <RouterContext.Provider\n // oxlint-disable-next-line jsx-no-new-object-as-prop\n value={{\n options,\n\n history,\n location,\n canGoBack,\n canGoForward,\n\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n\n buildLocation,\n\n navigate,\n back,\n forward,\n\n setLocationState,\n setLocationSearch,\n }}\n >\n <LocationProvider location={location} {...props} />\n </RouterContext.Provider>\n );\n};\n","import type { RouterOptions } from \"./types.js\";\n\nexport const DefaultRouterOptions: RouterOptions = {\n defaultTransitionDuration: 300,\n};\n","import { DefaultRouterOptions } from \"./constants.js\";\nimport type {\n Location,\n NavigateActionOptions,\n ParsedRoute,\n Route,\n RouteMatch,\n RouterOptions,\n} from \"./types.js\";\n\nexport const DefaultTransitionDuration = 300;\n\nexport const redirect = (options: NavigateActionOptions) => {\n return new Error(\"\", { cause: options });\n};\n\n/**\n * @param pattern pathname pattern like `/users/:id`. Leading and trailing slashes are optional.\n * @param url URL to match against the pattern. Can be href or pathname with query string.\n * @returns extracted params and query if matched, otherwise null\n */\nexport const matchPattern = (\n pattern: string,\n url: string\n): { params: Record<string, string>; query: Record<string, string> } | null => {\n try {\n // 解析 URL\n let pathname, searchParams;\n\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n const urlObj = new URL(url);\n pathname = urlObj.pathname;\n searchParams = urlObj.searchParams;\n } else {\n // 處理相對路徑\n const [path, queryString] = url.split(\"?\");\n if (!path) {\n return null;\n }\n pathname = path;\n searchParams = new URLSearchParams(queryString || \"\");\n }\n\n // 移除路徑首尾的斜線以便比較\n const cleanPath = pathname.replaceAll(/^\\/|\\/$/g, \"\");\n const cleanPattern = pattern.replaceAll(/^\\/|\\/$/g, \"\");\n\n // 分割路徑段\n const pathSegments = cleanPath.split(\"/\");\n const patternSegments = cleanPattern.split(\"/\");\n\n // 路徑段數量不同則不匹配\n if (pathSegments.length !== patternSegments.length) {\n return null;\n }\n\n // 提取路徑參數\n const params: Record<string, string> = {};\n for (let i = 0; i < patternSegments.length; i++) {\n const patternSegment = patternSegments[i];\n const pathSegment = pathSegments[i];\n\n if (patternSegment.startsWith(\":\")) {\n // 動態參數\n const paramName = patternSegment.slice(1);\n params[paramName] = decodeURIComponent(pathSegment);\n } else if (patternSegment !== pathSegment) {\n // 靜態段不匹配\n return null;\n }\n }\n\n // 提取查詢參數\n const query = Object.fromEntries(searchParams.entries());\n\n return { params, query };\n } catch {\n return null;\n }\n};\n\nexport const matchRoute = (route: ParsedRoute, url: string): RouteMatch => {\n const _matchRoute = (\n matches: ParsedRoute[],\n { children }: ParsedRoute\n ): RouteMatch | null => {\n if (children && children.length > 0) {\n for (const childRoute of children) {\n const matchesResult = _matchRoute([...matches, childRoute], childRoute);\n if (matchesResult) {\n return matchesResult;\n }\n }\n return null;\n }\n\n const result = matchPattern(buildPathnameFromMatches(matches), url);\n return result ? { matches, ...result } : null;\n };\n\n return (\n _matchRoute([route], route) || {\n matches: [],\n params: {},\n query: {},\n }\n );\n};\n\nexport const buildPathnameFromMatches = (matches: Route[]): string => {\n let cleanedPathnames: string[] = []; // pathnames without leading/trailing slashes\n for (const match of matches) {\n if (match.pathname === undefined) continue;\n cleanedPathnames.push(match.pathname.replaceAll(/^\\/|\\/$/g, \"\"));\n }\n return \"/\" + cleanedPathnames.join(\"/\");\n};\n\nexport const parseLocation = ({\n href,\n pathname,\n search,\n}: globalThis.Location): Location => ({\n index: 0,\n href,\n state: {\n index: 0,\n },\n pathname,\n search: Object.fromEntries(new URLSearchParams(search)),\n});\n\nexport const createRouterOptions = (\n options?: Partial<RouterOptions>\n): RouterOptions => ({\n ...DefaultRouterOptions,\n ...options,\n});\n\nexport const parseRoute = (route: Route): ParsedRoute => {\n const parseRouteRecursive = (route: Route, parentId: string): ParsedRoute => {\n const id =\n route.name ??\n (route.pathname\n ? `${parentId}/${route.pathname.replaceAll(/^\\/|\\/$/g, \"\")}`\n : parentId);\n\n const parsedRoute: ParsedRoute = {\n ...route,\n id,\n children: route.children?.map((child) => parseRouteRecursive(child, id)),\n };\n\n return parsedRoute;\n };\n return parseRouteRecursive(route, \"\");\n};\n\nconst isPathSegmentValid = (segment: string): boolean => segment.length > 0;\n\n/**\n * Resolves a relative path against a base url.\n * @param url The base url.\n * @param to The relative path to resolve.\n * @returns The resolved absolute url.\n */\nexport const resolveRelativeUrl = (url: string, to: string): string => {\n const currentPathSegments = url.split(\"/\").filter(isPathSegmentValid);\n const toPathSegments = to.split(\"/\").filter(isPathSegmentValid);\n for (const segment of toPathSegments) {\n if (segment === \".\") {\n continue;\n } else if (segment === \"..\") {\n currentPathSegments.pop();\n } else {\n currentPathSegments.push(segment);\n }\n }\n return \"/\" + currentPathSegments.join(\"/\");\n};\n\nexport const buildUrlFromLocation = (location: Location): string => {\n const searchParams = new URLSearchParams(location.search).toString();\n return searchParams\n ? `${location.pathname}?${searchParams}`\n : location.pathname;\n};\n","import { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { useRouter } from \"@/hooks/useRouter.js\";\nimport type { Route } from \"@/types.js\";\n\nimport { LocationProvider } from \"./location-provider.js\";\nimport { PageRenderer } from \"./page-renderer.js\";\nimport { RootRouteProvider } from \"./root-route-provider.js\";\n\nconst PreviousComponentStyle = {\n position: \"absolute\",\n inset: 0,\n zIndex: -1,\n} as const;\n\nexport interface StackComponentProps\n extends React.ComponentPropsWithoutRef<\"div\"> {\n allowSwipeForward?: boolean;\n allowSwipeBack?: boolean;\n}\n\nconst StackComponent: React.FC<StackComponentProps> = ({\n allowSwipeBack = true,\n allowSwipeForward = true,\n style,\n ...props\n}) => {\n const {\n history,\n location,\n canGoBack,\n canGoForward,\n isTransitioning,\n transitioningToLocation,\n transitionType,\n transitionDuration,\n back,\n forward,\n } = useRouter();\n const currentLocationIndex = location.index;\n\n const isTouching = useRef(false);\n const startX = useRef(0);\n const startY = useRef(0);\n const [isDragging, setIsDragging] = useState(false);\n const [dragOffset, setDragOffset] = useState(0);\n const [showPreviousComponent, setShowPreviousComponent] = useState(false);\n const [showNextComponent, setShowNextComponent] = useState(false);\n const [isCanceling, setIsCanceling] = useState(false);\n const [isTransitionStarted, setIsTransitionStarted] = useState(false);\n\n useEffect(() => {\n if (!isTransitioning || !transitioningToLocation) return;\n setIsTransitionStarted(true);\n setTimeout(() => {\n setIsTransitionStarted(false);\n }, transitionDuration);\n }, [isTransitioning, transitioningToLocation, transitionDuration]);\n\n if (currentLocationIndex === undefined) return;\n\n const reset = () => {\n setIsDragging(false);\n setDragOffset(0);\n setShowPreviousComponent(false);\n setShowNextComponent(false);\n setIsCanceling(false);\n };\n\n const handleTouchStart = useCallback(\n (e: React.TouchEvent) => {\n if (isTransitioning || (!canGoForward && !canGoBack)) return;\n isTouching.current = true;\n startX.current = e.touches[0].clientX;\n startY.current = e.touches[0].clientY;\n },\n [isTransitioning, canGoBack, canGoForward]\n );\n\n const handleTouchMove = useCallback(\n (e: React.TouchEvent) => {\n if (!isTouching.current) return;\n // Skip vertical drag\n const { clientX, clientY } = e.touches[0];\n if (!isDragging && Math.abs(clientY - startY.current) > 30) {\n isTouching.current = false;\n return;\n }\n const offset = clientX - startX.current;\n if (Math.abs(offset) < 10) return;\n if (!isDragging) {\n setIsDragging(true);\n }\n if (\n (offset > 0 && currentLocationIndex === 0) ||\n (offset < 0 && currentLocationIndex + 1 === history.length)\n ) {\n setDragOffset(0);\n return;\n }\n if (!showPreviousComponent && offset < 0 && allowSwipeForward)\n setShowPreviousComponent(true);\n if (!showNextComponent && offset > 0 && allowSwipeBack)\n setShowNextComponent(true);\n setDragOffset(\n Math.max(Math.min(offset, window.innerWidth), -window.innerWidth)\n );\n },\n [\n isDragging,\n currentLocationIndex,\n history.length,\n showPreviousComponent,\n showNextComponent,\n allowSwipeBack,\n allowSwipeForward,\n ]\n );\n\n const handleTouchEnd = useCallback(() => {\n isTouching.current = false;\n if (!isDragging) return;\n\n const options = {\n onFinish: reset,\n };\n if (dragOffset > innerWidth * 0.3 && canGoBack && allowSwipeBack) {\n back(options);\n } else if (\n dragOffset < -innerWidth * 0.3 &&\n canGoForward &&\n allowSwipeForward\n ) {\n forward(options);\n } else {\n setIsCanceling(true);\n setTimeout(reset, transitionDuration);\n }\n }, [\n back,\n forward,\n isDragging,\n dragOffset,\n canGoBack,\n canGoForward,\n transitionDuration,\n ]);\n\n return (\n <div\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n ...style,\n }}\n {...props}\n >\n {((isTransitioning && transitionType === \"slide-right\") ||\n (isDragging && showNextComponent)) && (\n <div style={PreviousComponentStyle}>\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex - 1)!\n }\n >\n <PageRenderer key={currentLocationIndex - 1} />\n </LocationProvider>\n </div>\n )}\n <div\n key={currentLocationIndex}\n style={{\n position: \"absolute\",\n inset: 0,\n transform:\n isTransitioning && transitionType === \"slide-right\"\n ? `translateX(100%)`\n : isDragging && dragOffset > 0 && !isCanceling\n ? `translateX(${dragOffset}px)`\n : \"translateX(0px)\",\n transition:\n isCanceling || (isTransitioning && transitionType === \"slide-right\")\n ? `transform ${transitionDuration}ms ease-out`\n : \"\",\n }}\n onTouchStart={handleTouchStart}\n onTouchMove={handleTouchMove}\n onTouchEnd={handleTouchEnd}\n >\n <PageRenderer />\n </div>\n {((isTransitioning && transitionType === \"slide-left\") ||\n (isDragging && showPreviousComponent)) && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: 1,\n transform: `translateX(${\n isTransitionStarted\n ? \"0px\"\n : isTransitioning || isCanceling\n ? \"100%\"\n : `${innerWidth + dragOffset}px`\n })`,\n transition: `transform ${\n isTransitioning || isCanceling ? transitionDuration : 0\n }ms ease-in`,\n }}\n >\n <LocationProvider\n location={\n isTransitioning\n ? transitioningToLocation!\n : history.at(currentLocationIndex + 1)!\n }\n >\n <PageRenderer key={transitioningToLocation?.index} />\n </LocationProvider>\n </div>\n )}\n </div>\n );\n};\n\nexport interface StackProps extends StackComponentProps {\n route: Route;\n}\n\nexport const Stack: React.FC<StackProps> = ({ route, ...props }) => (\n <RootRouteProvider route={route}>\n <StackComponent {...props} />\n </RootRouteProvider>\n);\n","import { RouteMatchContext } from \"@/context/route-match-context.js\";\nimport { useLocation } from \"@/hooks/useLocation.js\";\nimport { useRootRoute } from \"@/hooks/useRootRoute.js\";\nimport { matchRoute } from \"@/utils.js\";\nimport { memo, useMemo } from \"react\";\nimport { RouteComponent } from \"./route-component.js\";\nimport { RouteProvider } from \"./route-provider.js\";\n\nexport const PageRenderer = memo(() => {\n const rootRoute = useRootRoute();\n const location = useLocation();\n const routeMatch = useMemo(\n () => matchRoute(rootRoute, location.pathname),\n [rootRoute, location.pathname]\n );\n return (\n <RouteMatchContext.Provider value={routeMatch}>\n <RouteProvider route={rootRoute}>\n <RouteComponent />\n </RouteProvider>\n </RouteMatchContext.Provider>\n );\n});\n","import { RootRouteContext } from \"@/context/root-route-context.js\";\nimport type { Route } from \"@/types.js\";\nimport { parseRoute } from \"@/utils.js\";\nimport { useCallback, useMemo, useState } from \"react\";\n\nexport const RootRouteProvider = ({\n route,\n ...props\n}: {\n route: Route;\n children: React.ReactNode;\n}) => {\n const parsedRoute = useMemo(() => parseRoute(route), [route]);\n const [state, setState] = useState<Record<string, Record<string, any>>>({});\n\n const getRouteState = useCallback(\n (id: string, key: string) => {\n return state[id]?.[key];\n },\n [state]\n );\n\n const setRouteState = useCallback((id: string, key: string, value: any) => {\n setState((prevState) => ({\n ...prevState,\n [id]: {\n ...prevState[id],\n [key]: value,\n },\n }));\n }, []);\n\n return (\n <RootRouteContext.Provider\n value={{ ...parsedRoute, state, getRoute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eACtCU,GAAcO,IACf/B,EAAC,OAAI,MAAOE,GACV,SAAAF,EAACgD,EAAA,CACC,SACEpC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,SAAAnB,EAACiD,GAAA,GAAkB9B,EAAuB,CAAG,EAC/C,EACF,EAEFnB,EAAC,OAEC,MAAO,CACL,SAAU,WACV,MAAO,EACP,UACEY,GAAmBE,IAAmB,cAClC,mBACAU,GAAcG,EAAa,GAAK,CAACM,EACjC,cAAcN,CAAU,MACxB,kBACN,WACEM,GAAgBrB,GAAmBE,IAAmB,cAClD,aAAaC,CAAkB,cAC/B,EACR,EACA,aAAcwB,EACd,YAAaG,EACb,WAAYI,EAEZ,SAAA9C,EAACiD,GAAA,EAAa,GAnBT9B,CAoBP,GACGP,GAAmBE,IAAmB,cACtCU,GAAcK,IACf7B,EAAC,OACC,MAAO,CACL,SAAU,WACV,MAAO,EACP,OAAQ,EACR,UAAW,cACTmC,EACI,MACAvB,GAAmBqB,EACnB,OACA,GAAG,WAAaN,CAAU,IAChC,IACA,WAAY,aACVf,GAAmBqB,EAAclB,EAAqB,CACxD,YACF,EAEA,SAAAf,EAACgD,EAAA,CACC,SACEpC,EACIC,EACAL,EAAQ,GAAGW,EAAuB,CAAC,EAGzC,SAAAnB,EAACiD,GAAA,GAAkBpC,GAAyB,KAAO,EACrD,EACF,GAEJ,CAEJ,EAMaqC,GAA8B,CAAC,CAAE,MAAAC,EAAO,GAAG5C,CAAM,IAC5DP,EAACoD,GAAA,CAAkB,MAAOD,EACxB,SAAAnD,EAACG,GAAA,CAAgB,GAAGI,EAAO,EAC7B","names":["useContext","createContext","RouterContext","useRouter","router","useContext","RouterContext","memo","jsx","Link","to","replace","transitionType","duration","onFinish","props","router","useRouter","e","createContext","LocationContext","memo","useCallback","useMemo","jsx","LocationProvider","location","props","router","useRouter","state","setState","key","value","prev","deleteState","setSearch","LocationContext","a","b","createContext","OutletContext","useContext","useOutlet","OutletContext","createContext","RouteMatchContext","useContext","useRouteMatch","routeMatch","RouteMatchContext","jsx","OutletProvider","depth","props","OutletContext","useContext","useLocation","context","useContext","LocationContext","createContext","RouteContext","useContext","useRoute","route","RouteContext","useEffect","jsx","RouteComponent","depth","router","useRouter","location","useLocation","routeMatch","useRouteMatch","route","useRoute","pendingStateKey","pending","useEffect","cause","PendingComponent","NotFoundComponent","Component","Outlet","useContext","createContext","RootRouteContext","useRootRoute","route","useContext","RootRouteContext","useCallback","jsx","RouteProvider","route","props","RouteContext","state","getRouteState","setRouteState","useRootRoute","getState","key","setState","value","jsx","Outlet","routeMatch","useRouteMatch","depth","useOutlet","OutletProvider","RouteProvider","RouteComponent","useCallback","useEffect","useMemo","useState","DefaultRouterOptions","DefaultTransitionDuration","redirect","options","matchPattern","pattern","url","pathname","searchParams","urlObj","path","queryString","cleanPath","cleanPattern","pathSegments","patternSegments","params","i","patternSegment","pathSegment","paramName","query","matchRoute","route","_matchRoute","matches","children","childRoute","matchesResult","result","buildPathnameFromMatches","cleanedPathnames","match","parseLocation","href","search","createRouterOptions","DefaultRouterOptions","parseRoute","parseRouteRecursive","parentId","id","child","isPathSegmentValid","segment","resolveRelativeUrl","to","currentPathSegments","toPathSegments","buildUrlFromLocation","location","jsx","RouterProvider","options","props","history","setHistory","useState","parseLocation","currentLocationIndex","setCurrentLocationIndex","location","useMemo","isTransitioning","setIsTransitioning","transitioningToLocation","setTransitioningToLocation","transitionType","setTransitionType","transitionDuration","setTransitionDuration","canGoBack","canGoForward","useEffect","buildUrlFromLocation","handlePopState","state","buildLocation","useCallback","to","replace","index","url","resolveRelativeUrl","pathname","search","searchParams","transitionTo","duration","callback","navigate","onFinish","newLocation","updateHistory","prevHistory","finalTransitionType","back","depth","backDepth","forward","forwardDepth","setLocationState","newState","setLocationSearch","locationIndex","prev","RouterContext","LocationProvider","useCallback","useEffect","useRef","useState","memo","useMemo","jsx","PageRenderer","memo","rootRoute","useRootRoute","location","useLocation","routeMatch","useMemo","matchRoute","RouteMatchContext","RouteProvider","RouteComponent","useCallback","useMemo","useState","jsx","RootRouteProvider","route","props","parsedRoute","parseRoute","state","setState","getRouteState","id","key","setRouteState","value","prevState","RootRouteContext","jsx","jsxs","PreviousComponentStyle","StackComponent","allowSwipeBack","allowSwipeForward","style","props","history","location","canGoBack","canGoForward","isTransitioning","transitioningToLocation","transitionType","transitionDuration","back","forward","useRouter","currentLocationIndex","isTouching","useRef","startX","startY","isDragging","setIsDragging","useState","dragOffset","setDragOffset","showPreviousComponent","setShowPreviousComponent","showNextComponent","setShowNextComponent","isCanceling","setIsCanceling","isTransitionStarted","setIsTransitionStarted","useEffect","reset","handleTouchStart","useCallback","e","handleTouchMove","clientX","clientY","offset","handleTouchEnd","options","LocationProvider","PageRenderer","Stack","route","RootRouteProvider"]}
|