@real-router/preact 0.17.4 → 0.18.0
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/dist/cjs/index.d.ts +22 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +22 -4
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NavigationOptions, Navigator, Navigator as Navigator$1, Params, Router, RouterError, State } from "@real-router/core";
|
|
1
|
+
import { NavigationOptions, NavigationTarget, Navigator, Navigator as Navigator$1, Params, Router, RouterError, SearchParams, State } from "@real-router/core";
|
|
2
2
|
import { RouteUtils } from "@real-router/route-utils";
|
|
3
3
|
import { ComponentChildren, Context, FunctionComponent, HTMLAttributes, VNode } from "preact";
|
|
4
4
|
import { RouterTransitionSnapshot, RouterTransitionSnapshot as RouterTransitionSnapshot$1 } from "@real-router/sources";
|
|
@@ -56,9 +56,8 @@ interface RouteState<P extends Params = Params> {
|
|
|
56
56
|
type RouteContext$1<P extends Params = Params> = RouteState<P> & {
|
|
57
57
|
navigator: Navigator$1;
|
|
58
58
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
routeParams?: P;
|
|
59
|
+
/** Props shared by both `<Link>` forms (see react `LinkProps` for the rationale). */
|
|
60
|
+
interface LinkCommonProps extends Omit<HTMLAttributes<HTMLAnchorElement>, "className"> {
|
|
62
61
|
routeOptions?: NavigationOptions;
|
|
63
62
|
className?: string;
|
|
64
63
|
activeClassName?: string;
|
|
@@ -76,6 +75,25 @@ interface LinkProps<P extends Params = Params> extends Omit<HTMLAttributes<HTMLA
|
|
|
76
75
|
hash?: string;
|
|
77
76
|
target?: string;
|
|
78
77
|
}
|
|
78
|
+
/** Channel form: `routeName` + optional `routeParams` / `routeSearch`. */
|
|
79
|
+
interface LinkChannelProps<P extends Params = Params> {
|
|
80
|
+
routeName: string;
|
|
81
|
+
routeParams?: P;
|
|
82
|
+
/**
|
|
83
|
+
* Query (search) params for the link's target (RFC-4 M2, #1548) — parallel to
|
|
84
|
+
* `routeParams`, the path/query split's view-layer channel.
|
|
85
|
+
*/
|
|
86
|
+
routeSearch?: SearchParams;
|
|
87
|
+
to?: never;
|
|
88
|
+
}
|
|
89
|
+
/** Descriptor form (RFC-4 M2 B2, #1548): `to={NavigationTarget}`, exclusive with channel props. */
|
|
90
|
+
interface LinkDescriptorProps<P extends Params = Params> {
|
|
91
|
+
to: NavigationTarget<P>;
|
|
92
|
+
routeName?: never;
|
|
93
|
+
routeParams?: never;
|
|
94
|
+
routeSearch?: never;
|
|
95
|
+
}
|
|
96
|
+
type LinkProps<P extends Params = Params> = LinkCommonProps & (LinkChannelProps<P> | LinkDescriptorProps<P>);
|
|
79
97
|
//#endregion
|
|
80
98
|
//#region src/components/Link.d.ts
|
|
81
99
|
declare const Link: FunctionComponent<LinkProps>;
|
package/dist/esm/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/components/RouteView/types.ts","../../src/components/RouteView/components.tsx","../../src/components/RouteView/RouteView.tsx","../../src/types.ts","../../src/components/Link.tsx","../../src/components/RouterErrorBoundary.tsx","../../src/hooks/useRouter.tsx","../../src/hooks/useNavigator.tsx","../../src/hooks/useRouteUtils.tsx","../../src/hooks/useRoute.tsx","../../src/hooks/useRouteNode.tsx","../../src/hooks/useRouterTransition.tsx","../../src/hooks/useRouteExit.tsx","../../src/hooks/useRouteEnter.tsx","../../../../shared/dom-utils/route-announcer.ts","../../../../shared/dom-utils/scroll-restore.ts","../../../../shared/dom-utils/scroll-spy.ts","../../src/RouterProvider.tsx","../../src/context.ts"],"mappings":";;;;;UAEiB;WACN;WACA,UAAU;;UAGJ;WACN;WACA;WACA,WAAW;WACX,UAAU;;UAGJ;;WAEN,WAAW;;WAEX,UAAU;;UAGJ;WACN,UAAU;;;;iBCpBL,MAAM,QAAQ;kBAAd;MAAA;;iBAMA,KAAK,QAAQ;kBAAb;MAAA;;iBAMA,SAAS,QAAQ;kBAAjB;MAAA;;;;iBCLP,gBACP,UACA,YACC,SAAS,kBAAkB;kBAHrB;MAAA;;cAoCI,kBAAS;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/components/RouteView/types.ts","../../src/components/RouteView/components.tsx","../../src/components/RouteView/RouteView.tsx","../../src/types.ts","../../src/components/Link.tsx","../../src/components/RouterErrorBoundary.tsx","../../src/hooks/useRouter.tsx","../../src/hooks/useNavigator.tsx","../../src/hooks/useRouteUtils.tsx","../../src/hooks/useRoute.tsx","../../src/hooks/useRouteNode.tsx","../../src/hooks/useRouterTransition.tsx","../../src/hooks/useRouteExit.tsx","../../src/hooks/useRouteEnter.tsx","../../../../shared/dom-utils/route-announcer.ts","../../../../shared/dom-utils/scroll-restore.ts","../../../../shared/dom-utils/scroll-spy.ts","../../src/RouterProvider.tsx","../../src/context.ts"],"mappings":";;;;;UAEiB;WACN;WACA,UAAU;;UAGJ;WACN;WACA;WACA,WAAW;WACX,UAAU;;UAGJ;;WAEN,WAAW;;WAEX,UAAU;;UAGJ;WACN,UAAU;;;;iBCpBL,MAAM,QAAQ;kBAAd;MAAA;;iBAMA,KAAK,QAAQ;kBAAb;MAAA;;iBAMA,SAAS,QAAQ;kBAAjB;MAAA;;;;iBCLP,gBACP,UACA,YACC,SAAS,kBAAkB;kBAHrB;MAAA;;cAoCI,kBAAS;;;;;;;UCnCL,WAAW,UAAU,SAAS;EAC7C,OAAO,MAAM;EACb,gBAAgB;;KAGN,eAAa,UAAU,SAAS,UAAU,WAAW;EAC/D,WAAW;;;UAIH,wBAAwB,KAChC,eAAe;EAGf,eAAe;EACf;EACA;EACA;EACA;;;;;;;;;;EAUA;EACA;;;UAIQ,iBAAiB,UAAU,SAAS;EAC5C;EACA,cAAc;;;;;EAKd,cAAc;EACd;;;UAIQ,oBAAoB,UAAU,SAAS;EAC/C,IAAI,iBAAiB;EACrB;EACA;EACA;;KAGU,UAAU,UAAU,SAAS,UAAU,mBAChD,iBAAiB,KAAK,oBAAoB;;;cCNhC,MAAM,kBAAkB;;;UC/CpB;WACN,UAAU;WACV,WACP,OAAO,aACP,2BACG;WACI,WACP,OAAO,aACP,SAAS,cACT,WAAW;;;;;;;;;;;;;;;;;;iBAoBC,sBACd,UACA,UACA,WACC,2BAA2B;;;cCvCjB,iBAAiB;;;cCAjB,oBAAoB;;;cCGpB,qBAAoB;;;cCGpB,WAAY,UAAU,SAAS,aAAW,KACrD,eAAiB;EAEb,OAAO,MAAM;;;;iBCJH,aAAa,mBAAmB;;;iBCFhC,uBAAuB;;;UCAtB;;EAEf,OAAO;;EAEP,WAAW;;;;;;;;EAQX,QAAQ;;UAGO;;;;;;EAMf;;KAGU,oBACV,SAAS,4BACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4FI,aACd,SAAS,kBACT,UAAU;;;UCxHK;;EAEf,OAAO;;EAEP,eAAe;;KAGL,qBAAqB,SAAS;UAEzB;;;;;;EAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoFc,cACd,SAAS,mBACT,UAAU;;;UCnGK;EACf;EACA,uBAAuB,OAAO;;;;KCOpB;UAEK;EACf,OAAO;EACP;EACA,yBAAyB;;;;;;;;;;;;;EAazB,WAAW;;;;;;;;EAQX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCFe;;;;;;EAMf;;;;;;EAOA;;;;;;;;;;EAWA,yBAAyB;;;;UC7CV;EACf,QAAQ;EACR,UAAU;EACV,+BAA+B;EAC/B,oBAAoB;EACpB,YAAY;EACZ;;cAGW,gBAAgB,kBAAkB;;;cCvBlC,cAAY,QAAA;cAEZ,eAAa,QAAA;cAEb,kBAAgB,QAAA"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"./useRoute-DdZuiE4J.mjs";import{useEffect as a,useLayoutEffect as o,useMemo as s,useRef as c,useState as l}from"preact/hooks";import{UNKNOWN_ROUTE as u,getNavigator as d}from"@real-router/core";import{getRouteUtils as f,startsWithSegment as p}from"@real-router/route-utils";import{Fragment as m,isValidElement as h,toChildArray as g}from"preact";import{Suspense as _,memo as v}from"preact/compat";import{Fragment as y,jsx as b,jsxs as x}from"preact/jsx-runtime";import{createActiveSource as S,createDismissableError as C,createRouteEnterGate as w,createRouteNodeSource as T,createRouteSource as ee,getTransitionSource as E,guardLeaveListener as D,primeErrorSource as te}from"@real-router/sources";import{getPluginApi as O}from"@real-router/core/api";function k(e){return null}k.displayName=`RouteView.Match`;function A(e){return null}A.displayName=`RouteView.Self`;function j(e){return null}j.displayName=`RouteView.NotFound`;const M=new Set([k,A,j]);function N(e,t,n){return t===``?!1:n?e===t:p(e,t)}function P(e,t){for(let n of g(e))h(n)&&(M.has(n.type)?t.push(n):P(n.props.children,t))}function F(e,t,n){return b(m,{children:n===void 0?e:b(_,{fallback:n,children:e})},t)}function ne(e){return e.type===j||e.type===A}function re(e,t){if(e.type===j){t.notFoundFound||=(t.notFoundChildren=e.props.children,!0);return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function ie(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return!r&&N(t,c,a)?F(s,c,o):null}function ae(e,t,n,r){if(r.selfFound&&t===n){e.push(F(r.selfChildren,`__route-view-self__`,r.selfFallback));return}t===u&&r.notFoundChildren!==null&&e.push(b(m,{children:r.notFoundChildren},`__route-view-not-found__`))}function I(e,t,n){let r={selfChildren:null,selfFallback:void 0,selfFound:!1,notFoundChildren:null,notFoundFound:!1},i=!1,a=[];for(let o of e){if(ne(o)){re(o,r);continue}let e=ie(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||ae(a,t,n,r),{rendered:a,activeMatchFound:i}}function L(e,t,n){let[r,i]=l(t);return a(()=>{let n=()=>{i(e=>{let n=t();return Object.is(e,n)?e:n})};return n(),e(n)},[e,t]),r}const R=e(n,`useNavigator`),z=e(t,`useRouter`);function B(e){let t=z(),n=R(),r=T(t,e),{route:i,previousRoute:a}=L(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function V({nodeName:e,children:t}){let{route:n}=B(e),r=s(()=>{let e=[];return P(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:I(r,i,e).rendered,[r,i,e]);return a.length>0?b(y,{children:a}):null}V.displayName=`RouteView`;const oe=Object.assign(V,{Match:k,Self:A,NotFound:j}),se=Object.freeze({}),ce=Object.freeze({}),H=`data-real-router-announcer`,U=Object.freeze({destroy:()=>{}});let W=0,G=0;function le(e,t){if(typeof document>`u`)return U;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=ue();W+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),pe(t)},p=setTimeout(()=>{if(a=!0,c!==null&&!o){let e=c;c=null,f(e,document.querySelector(`h1`))}},100),m=e.subscribe(({route:e})=>{if(i){i=!1;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(o)return;let t=document.querySelector(`h1`),i=fe(e,n,r,t);if(!(!i||i===s)){if(!a){c=i;return}f(i,t)}})})});return{destroy(){o||(o=!0,m(),clearTimeout(l),clearTimeout(p),d===G&&(--W,W===0&&de(u)))}}}function ue(){let e=document.querySelector(`[${H}]`);if(e)return{element:e,generation:G};W=0,G+=1;let t=document.createElement(`div`);return t.setAttribute(`style`,`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap;border:0`),t.setAttribute(`aria-live`,`assertive`),t.setAttribute(`aria-atomic`,`true`),t.setAttribute(H,``),(document.body??document.documentElement).prepend(t),{element:t,generation:G}}function de(e){e.remove()}function fe(e,t,n,r){if(n)try{let t=n(e);if(t)return t}catch(e){console.error(`[real-router] getAnnouncementText threw; falling back to default resolution.`,e)}let i=(r?.textContent??``).trim(),a=e.name.startsWith(`@@`)?``:e.name;return`${t}${i||document.title||a||globalThis.location.pathname}`}function pe(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const K=Object.freeze({destroy:()=>{}});function me(e,t){if(globalThis.window===void 0)return K;let n=t?.mode??`restore`;if(n===`native`)return K;let r=t?.anchorScrolling??!0,i=t?.scrollContainer,a=t?.behavior??`auto`,o=t?.storageKey??`real-router:scroll`,s,c=()=>{if(s!==void 0)return s;try{let e=sessionStorage.getItem(o);s=e?JSON.parse(e):{}}catch{s={}}return s},l=(e,t)=>{try{let n=c();if(n[e]===t)return;n[e]=t,sessionStorage.setItem(o,JSON.stringify(n))}catch{}},u=history.scrollRestoration;try{history.scrollRestoration=`manual`}catch{}let d=()=>{let e=i?.();return e?e.scrollTop:globalThis.scrollY},f=e=>{let t=i?.();t?t.scrollTo({top:e,left:0,behavior:a}):globalThis.scrollTo({top:e,left:0,behavior:a})},p=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=()=>{if(h)return;let r=i();if(r){if(r.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(r.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(n))};n()},m=e=>{let t=e.context?.url?.hash;if(t!==void 0){if(r&&t.length>0){let e=document.getElementById(t);if(e){e.scrollIntoView({behavior:a});return}}f(0);return}let n=globalThis.location.hash;if(r&&n.length>1){let e;try{e=decodeURIComponent(n.slice(1))}catch{e=n.slice(1)}let t=document.getElementById(e);if(t){t.scrollIntoView({behavior:a});return}}f(0)},h=!1,g=!1,_=!0,v=e=>{try{return he(e)}catch{return g||(g=!0,console.error(`[real-router] scroll-restore: route "${e.name}" has params that cannot be canonicalized (e.g. BigInt or cyclic structure). Scroll position will not be captured or restored for this route.`)),null}},y=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;if(t&&_){let e=v(t);e!==null&&l(e,d())}_=!1,requestAnimationFrame(()=>{if(!h){if(_=!0,n===`top`){m(e);return}if(e.transition.reload||r?.navigationType===`reload`){let t=v(e);p(t===null?0:c()[t]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){let t=v(e);p(t===null?0:c()[t]??0);return}e.transition.replace||r?.navigationType===`replace`||m(e)}})}),b=()=>{let t=e.getState();if(t){let e=v(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,b),{destroy:()=>{h=!0,y(),globalThis.removeEventListener(`pagehide`,b);try{history.scrollRestoration=u}catch{}}}}const q=new WeakMap;function he(e){let t=q.get(e);if(t!==void 0)return t;let n=`${e.name}:${ge(e.params)}`;return q.set(e,n),n}function ge(e){return JSON.stringify(e,_e)}function _e(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.create(null),n=Object.keys(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const J=Object.freeze({destroy:()=>{}}),Y=e=>e.context?.url,ve=e=>{let t=null,n=1/0,r=null,i=-1/0;for(let a of e){if(!a.isIntersecting)continue;let e=a.rootBounds?.top??0,o=a.boundingClientRect.top-e;o>=0?o<n&&(t=a,n=o):o>i&&(r=a,i=o)}return t??r},ye=(e,t)=>{let n=null,r=e=>{let n=e.context;n&&n.url===void 0&&(console.warn(`[real-router] scroll-spy: state.context.url is not claimed. Spy requires browser-plugin or navigation-plugin. Disabling.`),t())},i=e.getState();if(i)r(i);else{let t=!1;n=e.subscribe(({route:e})=>{t||(t=!0,r(e),n?.(),n=null)})}return{destroy(){n?.(),n=null}}},be=e=>{let t=!1,n=null,r=null,i=null,a=()=>{n!==null&&(clearTimeout(n),n=null),i&&(r??globalThis).removeEventListener(`scrollend`,i),i=null,r=null,t=!1};return{get active(){return t},start(){a(),t=!0;let o=()=>{a()};i=o,r=e(),(r??globalThis).addEventListener(`scrollend`,o,{once:!0}),n=setTimeout(o,500)},destroy(){a()}}},xe=(e,t)=>{let n=null,r=null;return{schedule(){n===null&&(n=requestAnimationFrame(()=>{n=null,r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,e()},t)}))},destroy(){n!==null&&(cancelAnimationFrame(n),n=null),r!==null&&(clearTimeout(r),r=null)}}},Se=(e,t,n,r,i,a)=>{let o=new Set,s=new Map,c=!1,l=null,u=e=>{if(!a()){for(let t of e)s.set(t.target,t);r()}},d=e=>new IntersectionObserver(u,{root:e,rootMargin:t,threshold:0}),f=n(),p=d(f),m=()=>{let t=n()??document,r;try{r=t.querySelectorAll(e)}catch{i();return}let a=new Set;for(let e of r){let t=e.id;t&&!c&&(a.has(t)&&(c=!0,console.warn(`[real-router] scroll-spy: duplicate id "${t}" observed. Selection picks the topmost visible match deterministically.`)),a.add(t)),!o.has(e)&&(p.observe(e),o.add(e))}},h={childList:!0,subtree:!0,attributes:!0,attributeFilter:[`id`]},g=null,_=()=>{for(let e of o)e.isConnected||(p.unobserve(e),o.delete(e),s.delete(e));let e=n();e!==f&&(f=e,p.disconnect(),p=d(e),o.clear(),s.clear(),g?.disconnect(),g?.observe(e??document.body,h)),m()};return m(),g=new MutationObserver(()=>{l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,_()},250)}),g.observe(f??document.body,h),{pending:s,isContainerDetached:()=>f!==null&&!f.isConnected,reconcile:_,destroy(){p.disconnect(),g.disconnect(),l!==null&&(clearTimeout(l),l=null),o.clear(),s.clear()}}};function Ce(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return J;let{selector:n}=t;if(!n)return J;let r=t.rootMargin??`-20% 0px -60% 0px`,i=t.scrollContainer,a=()=>i?.()??null,o=!1,s=!1,c=!1,l=()=>s||o,u=null,d=E(e),f=ye(e,()=>{s=!0}),p=be(a),m=xe(()=>{u?.()},150),h=Se(n,r,a,()=>{m.schedule()},()=>{s||(s=!0,console.warn(`[real-router] scroll-spy: invalid selector "${n}". Disabling.`))},l);u=()=>{if(o||s){h.pending.clear();return}if(d.getSnapshot().isTransitioning||p.active)return;let t=ve(h.pending.values());if(h.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===Y(r)?.hash)return;let i={hash:n,replace:!0,force:!0,hashChange:!0};c=!0,e.navigate(r.name,r.params,i).catch(()=>{}).finally(()=>{c=!1})};let g=e.subscribe(({route:e})=>{c||(h.isContainerDetached()&&h.reconcile(),Y(e)?.hashChanged&&p.start())});return{destroy(){o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy()}}}const we=Object.freeze({destroy:()=>{}});function Te(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return we;let t=null,n=null,r=!1,i=()=>{t?.(),t=null},a=e.subscribeLeave(({signal:e})=>{if(!e.aborted)return r=!1,i(),new Promise(a=>{let o=new Promise(e=>{t=e});e.addEventListener(`abort`,()=>{r||(i(),n?.skipTransition?.(),a())},{once:!0});try{n=document.startViewTransition(()=>(a(),o))}catch{i(),a()}})}),o=e.subscribe(()=>{let e=t;if(r=!0,t=null,e===null)n=null;else{let t=n;setTimeout(()=>{e(),n===t&&(n=null)},0)}});return{destroy:()=>{a(),o(),n?.skipTransition?.(),n=null,i()}}}function Ee(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function De(e){return encodeURI(e).replaceAll(`#`,`%23`)}function Oe(e,t,n,r){try{let i;r!==void 0&&(i=r.startsWith(`#`)?r.slice(1):r);let a=e.buildUrl;if(a){let e=a(t,n,i===void 0?void 0:{hash:i});if(typeof e==`string`&&e.length>0)return e}let o=e.buildPath(t,n);if(typeof o!=`string`||o.length===0){console.error(`[real-router] Route "${t}" yielded an empty path. The element will render without an href attribute.`);return}return i?`${o}#${De(i)}`:o}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function ke(e,t,n,r,i){let a={...i};r!==void 0&&(a.hash=r);let o=e.getState();if(o?.name===t&&Z(o.params,n)){let e=o.context?.url?.hash??``;e!==(r??e)&&(a.force=!0,a.hashChange=!0)}return e.navigate(t,n,a)}const Ae=/\s/,je=/\S+/g;function X(e){return Ae.test(e)?e.match(je)??[]:[e]}function Me(e,t,n){if(e&&t){let e=X(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=X(n),i=new Set(r);for(let t of e)i.has(t)||(i.add(t),r.push(t));return r.join(` `)}return n??void 0}function Z(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(!Object.prototype.hasOwnProperty.call(t,e)||!Object.is(r[e],i[e]))return!1;return!0}function Ne(e,t,n=!1,r=!0,i){let a=z(),o=s(()=>S(a,e,t,n,r,i),[a,e,t,n,r,i]);return L(o.subscribe,o.getSnapshot,o.getSnapshot)}function Q(e,t){return e.routeName===t.routeName&&e.className===t.className&&e.activeClassName===t.activeClassName&&e.activeStrict===t.activeStrict&&e.ignoreQueryParams===t.ignoreQueryParams&&e.onClick===t.onClick&&e.target===t.target&&e.style===t.style&&e.children===t.children&&e.hash===t.hash&&Z(e.routeParams,t.routeParams)&&Z(e.routeOptions,t.routeOptions)}const $=v(({routeName:e,routeParams:t,routeOptions:n=ce,className:r,activeClassName:i=`active`,activeStrict:a=!1,ignoreQueryParams:o=!0,hash:s,onClick:c,target:l,children:u,...d})=>{let f=z(),p=Ne(e,t,a,o,s),m=t??se,h=Oe(f,e,m,s),g=t=>{if(c){try{c(t)}catch(e){console.error(`[real-router] A <Link> onClick handler threw; navigation is unaffected.`,e)}if(t.defaultPrevented)return}!Ee(t)||l===`_blank`||(t.preventDefault(),ke(f,e,m,s,n).catch(()=>{}))},_=Me(p,i,r);return b(`a`,{...d,href:h,className:_,onClick:g,children:u})},Q);$.displayName=`Link`;function Pe({children:e,fallback:t,onError:n}){let r=C(z()),i=L(r.subscribe,r.getSnapshot,r.getSnapshot),s=c(n);return o(()=>{s.current=n}),a(()=>{i.error&&s.current?.(i.error,i.toRoute,i.fromRoute)},[i.version]),x(m,{children:[e,i.error?t(i.error,i.resetError):null]})}const Fe=()=>f(O(z()).getTree());function Ie(){let e=E(z());return L(e.subscribe,e.getSnapshot,e.getSnapshot)}function Le(e,t){let n=z(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(D(e=>r.current(e),{skipSameRoute:i})),[n,i])}function Re(e,t){let{route:n,previousRoute:r}=i(),s=c(e),[u]=l(()=>w()),d=t?.skipSameRoute??!0;o(()=>{s.current=e}),a(()=>{let e=u(n,r,d);e&&s.current(e)},[u,n,r,d])}const ze=({router:e,children:i,announceNavigation:o,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{let f=o!==void 0&&o!==!1,p=typeof o==`object`?o:void 0,m=p?.prefix;a(()=>{if(!f)return;let t=le(e,p);return()=>{t.destroy()}},[e,f,m]);let h=c?.mode,g=c?.anchorScrolling,_=c?.behavior,v=c?.storageKey,y=c!==void 0;a(()=>{if(!y)return;let t=me(e,{mode:h,anchorScrolling:g,behavior:_,storageKey:v,scrollContainer:c.scrollContainer});return()=>{t.destroy()}},[e,y,h,g,_,v]);let x=l?.selector,S=l?.rootMargin,C=l!==void 0&&x!==void 0&&x!==``;a(()=>{if(!C)return;let t=Ce(e,{selector:x,rootMargin:S,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,C,x,S]),a(()=>{if(!u)return;let t=Te(e);return()=>{t.destroy()}},[e,u]);let w=d(e),T=s(()=>ee(e),[e]);a(()=>{te(e)},[e]);let{route:E,previousRoute:D}=L(T.subscribe,T.getSnapshot,T.getSnapshot),O=s(()=>({navigator:w,route:E,previousRoute:D}),[w,E,D]);return b(t.Provider,{value:e,children:b(n.Provider,{value:w,children:b(r.Provider,{value:O,children:i})})})};export{$ as Link,n as NavigatorContext,r as RouteContext,oe as RouteView,t as RouterContext,Pe as RouterErrorBoundary,ze as RouterProvider,R as useNavigator,i as useRoute,Re as useRouteEnter,Le as useRouteExit,B as useRouteNode,Fe as useRouteUtils,z as useRouter,Ie as useRouterTransition};
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"./useRoute-DdZuiE4J.mjs";import{useEffect as a,useLayoutEffect as o,useMemo as s,useRef as c,useState as l}from"preact/hooks";import{UNKNOWN_ROUTE as u,getNavigator as d}from"@real-router/core";import{getRouteUtils as f,startsWithSegment as p}from"@real-router/route-utils";import{Fragment as m,isValidElement as h,toChildArray as g}from"preact";import{Suspense as _,memo as v}from"preact/compat";import{Fragment as y,jsx as b,jsxs as x}from"preact/jsx-runtime";import{createActiveSource as S,createDismissableError as C,createRouteEnterGate as w,createRouteNodeSource as T,createRouteSource as ee,getTransitionSource as E,guardLeaveListener as D,primeErrorSource as te}from"@real-router/sources";import{getPluginApi as O}from"@real-router/core/api";function k(e){return null}k.displayName=`RouteView.Match`;function A(e){return null}A.displayName=`RouteView.Self`;function j(e){return null}j.displayName=`RouteView.NotFound`;const M=new Set([k,A,j]);function N(e,t,n){return t===``?!1:n?e===t:p(e,t)}function P(e,t){for(let n of g(e))h(n)&&(M.has(n.type)?t.push(n):P(n.props.children,t))}function F(e,t,n){return b(m,{children:n===void 0?e:b(_,{fallback:n,children:e})},t)}function ne(e){return e.type===j||e.type===A}function re(e,t){if(e.type===j){t.notFoundFound||=(t.notFoundChildren=e.props.children,!0);return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function ie(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return!r&&N(t,c,a)?F(s,c,o):null}function ae(e,t,n,r){if(r.selfFound&&t===n){e.push(F(r.selfChildren,`__route-view-self__`,r.selfFallback));return}t===u&&r.notFoundChildren!==null&&e.push(b(m,{children:r.notFoundChildren},`__route-view-not-found__`))}function I(e,t,n){let r={selfChildren:null,selfFallback:void 0,selfFound:!1,notFoundChildren:null,notFoundFound:!1},i=!1,a=[];for(let o of e){if(ne(o)){re(o,r);continue}let e=ie(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||ae(a,t,n,r),{rendered:a,activeMatchFound:i}}function L(e,t,n){let[r,i]=l(t);return a(()=>{let n=()=>{i(e=>{let n=t();return Object.is(e,n)?e:n})};return n(),e(n)},[e,t]),r}const R=e(n,`useNavigator`),z=e(t,`useRouter`);function B(e){let t=z(),n=R(),r=T(t,e),{route:i,previousRoute:a}=L(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function V({nodeName:e,children:t}){let{route:n}=B(e),r=s(()=>{let e=[];return P(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:I(r,i,e).rendered,[r,i,e]);return a.length>0?b(y,{children:a}):null}V.displayName=`RouteView`;const oe=Object.assign(V,{Match:k,Self:A,NotFound:j}),se=Object.freeze({}),ce=Object.freeze({}),H=`data-real-router-announcer`,U=Object.freeze({destroy:()=>{}});let W=0,G=0;function le(e,t){if(typeof document>`u`)return U;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=ue();W+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),pe(t)},p=setTimeout(()=>{if(a=!0,c!==null&&!o){let e=c;c=null,f(e,document.querySelector(`h1`))}},100),m=e.subscribe(({route:e})=>{if(i){i=!1;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(o)return;let t=document.querySelector(`h1`),i=fe(e,n,r,t);if(!(!i||i===s)){if(!a){c=i;return}f(i,t)}})})});return{destroy(){o||(o=!0,m(),clearTimeout(l),clearTimeout(p),d===G&&(--W,W===0&&de(u)))}}}function ue(){let e=document.querySelector(`[${H}]`);if(e)return{element:e,generation:G};W=0,G+=1;let t=document.createElement(`div`);return t.setAttribute(`style`,`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap;border:0`),t.setAttribute(`aria-live`,`assertive`),t.setAttribute(`aria-atomic`,`true`),t.setAttribute(H,``),(document.body??document.documentElement).prepend(t),{element:t,generation:G}}function de(e){e.remove()}function fe(e,t,n,r){if(n)try{let t=n(e);if(t)return t}catch(e){console.error(`[real-router] getAnnouncementText threw; falling back to default resolution.`,e)}let i=(r?.textContent??``).trim(),a=e.name.startsWith(`@@`)?``:e.name;return`${t}${i||document.title||a||globalThis.location.pathname}`}function pe(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const K=Object.freeze({destroy:()=>{}});function me(e,t){if(globalThis.window===void 0)return K;let n=t?.mode??`restore`;if(n===`native`)return K;let r=t?.anchorScrolling??!0,i=t?.scrollContainer,a=t?.behavior??`auto`,o=t?.storageKey??`real-router:scroll`,s,c=()=>{if(s!==void 0)return s;try{let e=sessionStorage.getItem(o);s=e?JSON.parse(e):{}}catch{s={}}return s},l=(e,t)=>{try{let n=c();if(n[e]===t)return;n[e]=t,sessionStorage.setItem(o,JSON.stringify(n))}catch{}},u=history.scrollRestoration;try{history.scrollRestoration=`manual`}catch{}let d=()=>{let e=i?.();return e?e.scrollTop:globalThis.scrollY},f=e=>{let t=i?.();t?t.scrollTo({top:e,left:0,behavior:a}):globalThis.scrollTo({top:e,left:0,behavior:a})},p=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=()=>{if(h)return;let r=i();if(r){if(r.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(r.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(n))};n()},m=e=>{let t=e.context?.url?.hash;if(t!==void 0){if(r&&t.length>0){let e=document.getElementById(t);if(e){e.scrollIntoView({behavior:a});return}}f(0);return}let n=globalThis.location.hash;if(r&&n.length>1){let e;try{e=decodeURIComponent(n.slice(1))}catch{e=n.slice(1)}let t=document.getElementById(e);if(t){t.scrollIntoView({behavior:a});return}}f(0)},h=!1,g=!1,_=!0,v=e=>{try{return he(e)}catch{return g||(g=!0,console.error(`[real-router] scroll-restore: route "${e.name}" has params that cannot be canonicalized (e.g. BigInt or cyclic structure). Scroll position will not be captured or restored for this route.`)),null}},y=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;if(t&&_){let e=v(t);e!==null&&l(e,d())}_=!1,requestAnimationFrame(()=>{if(!h){if(_=!0,n===`top`){m(e);return}if(e.transition.reload||r?.navigationType===`reload`){let t=v(e);p(t===null?0:c()[t]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){let t=v(e);p(t===null?0:c()[t]??0);return}e.transition.replace||r?.navigationType===`replace`||m(e)}})}),b=()=>{let t=e.getState();if(t){let e=v(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,b),{destroy:()=>{h=!0,y(),globalThis.removeEventListener(`pagehide`,b);try{history.scrollRestoration=u}catch{}}}}const q=new WeakMap;function he(e){let t=q.get(e);if(t!==void 0)return t;let n=`${e.name}:${ge({...e.params,...e.search})}`;return q.set(e,n),n}function ge(e){return JSON.stringify(e,_e)}function _e(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.create(null),n=Object.keys(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const J=Object.freeze({destroy:()=>{}}),Y=e=>e.context?.url,ve=e=>{let t=null,n=1/0,r=null,i=-1/0;for(let a of e){if(!a.isIntersecting)continue;let e=a.rootBounds?.top??0,o=a.boundingClientRect.top-e;o>=0?o<n&&(t=a,n=o):o>i&&(r=a,i=o)}return t??r},ye=(e,t)=>{let n=null,r=e=>{let n=e.context;n&&n.url===void 0&&(console.warn(`[real-router] scroll-spy: state.context.url is not claimed. Spy requires browser-plugin or navigation-plugin. Disabling.`),t())},i=e.getState();if(i)r(i);else{let t=!1;n=e.subscribe(({route:e})=>{t||(t=!0,r(e),n?.(),n=null)})}return{destroy(){n?.(),n=null}}},be=e=>{let t=!1,n=null,r=null,i=null,a=()=>{n!==null&&(clearTimeout(n),n=null),i&&(r??globalThis).removeEventListener(`scrollend`,i),i=null,r=null,t=!1};return{get active(){return t},start(){a(),t=!0;let o=()=>{a()};i=o,r=e(),(r??globalThis).addEventListener(`scrollend`,o,{once:!0}),n=setTimeout(o,500)},destroy(){a()}}},xe=(e,t)=>{let n=null,r=null;return{schedule(){n===null&&(n=requestAnimationFrame(()=>{n=null,r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,e()},t)}))},destroy(){n!==null&&(cancelAnimationFrame(n),n=null),r!==null&&(clearTimeout(r),r=null)}}},Se=(e,t,n,r,i,a)=>{let o=new Set,s=new Map,c=!1,l=null,u=e=>{if(!a()){for(let t of e)s.set(t.target,t);r()}},d=e=>new IntersectionObserver(u,{root:e,rootMargin:t,threshold:0}),f=n(),p=d(f),m=()=>{let t=n()??document,r;try{r=t.querySelectorAll(e)}catch{i();return}let a=new Set;for(let e of r){let t=e.id;t&&!c&&(a.has(t)&&(c=!0,console.warn(`[real-router] scroll-spy: duplicate id "${t}" observed. Selection picks the topmost visible match deterministically.`)),a.add(t)),!o.has(e)&&(p.observe(e),o.add(e))}},h={childList:!0,subtree:!0,attributes:!0,attributeFilter:[`id`]},g=null,_=()=>{for(let e of o)e.isConnected||(p.unobserve(e),o.delete(e),s.delete(e));let e=n();e!==f&&(f=e,p.disconnect(),p=d(e),o.clear(),s.clear(),g?.disconnect(),g?.observe(e??document.body,h)),m()};return m(),g=new MutationObserver(()=>{l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,_()},250)}),g.observe(f??document.body,h),{pending:s,isContainerDetached:()=>f!==null&&!f.isConnected,reconcile:_,destroy(){p.disconnect(),g.disconnect(),l!==null&&(clearTimeout(l),l=null),o.clear(),s.clear()}}};function Ce(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return J;let{selector:n}=t;if(!n)return J;let r=t.rootMargin??`-20% 0px -60% 0px`,i=t.scrollContainer,a=()=>i?.()??null,o=!1,s=!1,c=!1,l=()=>s||o,u=null,d=E(e),f=ye(e,()=>{s=!0}),p=be(a),m=xe(()=>{u?.()},150),h=Se(n,r,a,()=>{m.schedule()},()=>{s||(s=!0,console.warn(`[real-router] scroll-spy: invalid selector "${n}". Disabling.`))},l);u=()=>{if(o||s){h.pending.clear();return}if(d.getSnapshot().isTransitioning||p.active)return;let t=ve(h.pending.values());if(h.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===Y(r)?.hash)return;let i={hash:n,replace:!0,force:!0,hashChange:!0};c=!0,e.navigate(r.name,r.params,r.search,i).catch(()=>{}).finally(()=>{c=!1})};let g=e.subscribe(({route:e})=>{c||(h.isContainerDetached()&&h.reconcile(),Y(e)?.hashChanged&&p.start())});return{destroy(){o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy()}}}const we=Object.freeze({destroy:()=>{}});function Te(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return we;let t=null,n=null,r=!1,i=()=>{t?.(),t=null},a=e.subscribeLeave(({signal:e})=>{if(!e.aborted)return r=!1,i(),new Promise(a=>{let o=new Promise(e=>{t=e});e.addEventListener(`abort`,()=>{r||(i(),n?.skipTransition?.(),a())},{once:!0});try{n=document.startViewTransition(()=>(a(),o))}catch{i(),a()}})}),o=e.subscribe(()=>{let e=t;if(r=!0,t=null,e===null)n=null;else{let t=n;setTimeout(()=>{e(),n===t&&(n=null)},0)}});return{destroy:()=>{a(),o(),n?.skipTransition?.(),n=null,i()}}}function Ee(e,t,n,r){return e===void 0?{name:t,params:n,search:r}:((t!==``||n!==void 0||r!==void 0)&&console.warn("[real-router] <Link> received both `to` and channel props (routeName / routeParams / routeSearch). `to` wins; the channel props are ignored. Use one form or the other."),{name:e.name,params:e.params,search:e.search})}function De(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function Oe(e){return encodeURI(e).replaceAll(`#`,`%23`)}function ke(e,t,n,r,i){try{let a;i!==void 0&&(a=i.startsWith(`#`)?i.slice(1):i);let o=e.buildUrl;if(o){let e=o(t,n,r,a===void 0?void 0:{hash:a});if(typeof e==`string`&&e.length>0)return e}let s=e.buildPath(t,n,r);if(typeof s!=`string`||s.length===0){console.error(`[real-router] Route "${t}" yielded an empty path. The element will render without an href attribute.`);return}return a?`${s}#${Oe(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function Ae(e,t,n,r,i,a){let o={...a};i!==void 0&&(o.hash=i);let s=e.getState();if(s?.name===t&&Z(s.params,n)&&Z(s.search,r??s.search)){let e=s.context?.url?.hash??``;e!==(i??e)&&(o.force=!0,o.hashChange=!0)}return e.navigate(t,n,r,o)}const je=/\s/,Me=/\S+/g;function X(e){return je.test(e)?e.match(Me)??[]:[e]}function Ne(e,t,n){if(e&&t){let e=X(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=X(n),i=new Set(r);for(let t of e)i.has(t)||(i.add(t),r.push(t));return r.join(` `)}return n??void 0}function Z(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(!Object.prototype.hasOwnProperty.call(t,e)||!Object.is(r[e],i[e]))return!1;return!0}function Q(e,t,n,r=!1,i=!0,a){let o=z(),c=s(()=>S(o,e,t,n,r,i,a),[o,e,t,n,r,i,a]);return L(c.subscribe,c.getSnapshot,c.getSnapshot)}function Pe(e,t){return e.routeName===t.routeName&&e.className===t.className&&e.activeClassName===t.activeClassName&&e.activeStrict===t.activeStrict&&e.ignoreQueryParams===t.ignoreQueryParams&&e.onClick===t.onClick&&e.target===t.target&&e.style===t.style&&e.children===t.children&&e.hash===t.hash&&Z(e.routeParams,t.routeParams)&&Z(e.routeSearch,t.routeSearch)&&Z(e.to,t.to)&&Z(e.routeOptions,t.routeOptions)}const $=v(({routeName:e,routeParams:t,routeSearch:n,to:r,routeOptions:i=ce,className:a,activeClassName:o=`active`,activeStrict:s=!1,ignoreQueryParams:c=!0,hash:l,onClick:u,target:d,children:f,...p})=>{let m=z(),{name:h,params:g,search:_}=Ee(r,e??``,t,n),v=Q(h,g,_,s,c,l),y=g??se,x=ke(m,h,y,_,l),S=e=>{if(u){try{u(e)}catch(e){console.error(`[real-router] A <Link> onClick handler threw; navigation is unaffected.`,e)}if(e.defaultPrevented)return}!De(e)||d===`_blank`||(e.preventDefault(),Ae(m,h,y,_,l,i).catch(()=>{}))},C=Ne(v,o,a);return b(`a`,{...p,href:x,className:C,onClick:S,children:f})},Pe);$.displayName=`Link`;function Fe({children:e,fallback:t,onError:n}){let r=C(z()),i=L(r.subscribe,r.getSnapshot,r.getSnapshot),s=c(n);return o(()=>{s.current=n}),a(()=>{i.error&&s.current?.(i.error,i.toRoute,i.fromRoute)},[i.version]),x(m,{children:[e,i.error?t(i.error,i.resetError):null]})}const Ie=()=>f(O(z()).getTree());function Le(){let e=E(z());return L(e.subscribe,e.getSnapshot,e.getSnapshot)}function Re(e,t){let n=z(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(D(e=>r.current(e),{skipSameRoute:i})),[n,i])}function ze(e,t){let{route:n,previousRoute:r}=i(),s=c(e),[u]=l(()=>w()),d=t?.skipSameRoute??!0;o(()=>{s.current=e}),a(()=>{let e=u(n,r,d);e&&s.current(e)},[u,n,r,d])}const Be=({router:e,children:i,announceNavigation:o,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{let f=o!==void 0&&o!==!1,p=typeof o==`object`?o:void 0,m=p?.prefix;a(()=>{if(!f)return;let t=le(e,p);return()=>{t.destroy()}},[e,f,m]);let h=c?.mode,g=c?.anchorScrolling,_=c?.behavior,v=c?.storageKey,y=c!==void 0;a(()=>{if(!y)return;let t=me(e,{mode:h,anchorScrolling:g,behavior:_,storageKey:v,scrollContainer:c.scrollContainer});return()=>{t.destroy()}},[e,y,h,g,_,v]);let x=l?.selector,S=l?.rootMargin,C=l!==void 0&&x!==void 0&&x!==``;a(()=>{if(!C)return;let t=Ce(e,{selector:x,rootMargin:S,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,C,x,S]),a(()=>{if(!u)return;let t=Te(e);return()=>{t.destroy()}},[e,u]);let w=d(e),T=s(()=>ee(e),[e]);a(()=>{te(e)},[e]);let{route:E,previousRoute:D}=L(T.subscribe,T.getSnapshot,T.getSnapshot),O=s(()=>({navigator:w,route:E,previousRoute:D}),[w,E,D]);return b(t.Provider,{value:e,children:b(n.Provider,{value:w,children:b(r.Provider,{value:O,children:i})})})};export{$ as Link,n as NavigatorContext,r as RouteContext,oe as RouteView,t as RouterContext,Fe as RouterErrorBoundary,Be as RouterProvider,R as useNavigator,i as useRoute,ze as useRouteEnter,Re as useRouteExit,B as useRouteNode,Ie as useRouteUtils,z as useRouter,Le as useRouterTransition};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|