@real-router/preact 0.22.0 → 0.24.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.
@@ -364,6 +364,33 @@ interface UseRouteEnterOptions {
364
364
  */
365
365
  export declare function useRouteEnter(handler: RouteEnterHandler, options?: UseRouteEnterOptions): void;
366
366
  //#endregion
367
+ //#region ../../shared/dom-utils/direction-tracker.d.ts
368
+ interface DirectionTracker {
369
+ destroy: () => void;
370
+ }
371
+ /**
372
+ * Track navigation direction (forward / back) and write it to
373
+ * `<html data-nav-direction>` on every leave. CSS / JS readers consume
374
+ * the attribute via `html[data-nav-direction="back"]` selectors or
375
+ * `document.documentElement.dataset.navDirection`.
376
+ *
377
+ * Mechanism-agnostic — works identically whether downstream UI uses CSS
378
+ * `@keyframes`, View Transitions pseudo-elements, or library state
379
+ * (motion's `motion.div initial={{ x: ... }}`).
380
+ *
381
+ * Implementation:
382
+ * - On install, set `data-nav-direction="forward"` baseline.
383
+ * - Attach a `popstate` listener that flips an internal flag to
384
+ * `true`. Browser back/forward navigation triggers popstate; user
385
+ * clicks on `<Link>` / programmatic `router.navigate(...)` do not.
386
+ * - On every `subscribeLeave`, write
387
+ * `popstateFlag ? "back" : "forward"` and reset the flag.
388
+ *
389
+ * Returns `{ destroy }` to clean up the listener and clear the dataset
390
+ * attribute.
391
+ */
392
+ export declare function createDirectionTracker(router: Router): DirectionTracker;
393
+ //#endregion
367
394
  //#region ../../shared/dom-utils/route-announcer.d.ts
368
395
  interface RouteAnnouncerOptions {
369
396
  prefix?: string;
@@ -479,5 +506,5 @@ export declare const RouteContext: Context<RouteContext$1 | null>;
479
506
  export declare const RouterContext: Context<Router<object> | null>;
480
507
  export declare const NavigatorContext: Context<Navigator$1 | null>;
481
508
  //#endregion
482
- export type { LinkProps, Navigator, RouteEnterContext, RouteEnterHandler, RouteExitContext, RouteExitHandler, MatchProps as RouteViewMatchProps, NotFoundProps as RouteViewNotFoundProps, RouteViewProps, SelfProps as RouteViewSelfProps, RouterErrorBoundaryProps, RouterTransitionSnapshot, UseRouteEnterOptions, UseRouteExitOptions };
509
+ export type { DirectionTracker, LinkProps, Navigator, RouteEnterContext, RouteEnterHandler, RouteExitContext, RouteExitHandler, MatchProps as RouteViewMatchProps, NotFoundProps as RouteViewNotFoundProps, RouteViewProps, SelfProps as RouteViewSelfProps, RouterErrorBoundaryProps, RouterTransitionSnapshot, UseRouteEnterOptions, UseRouteExitOptions };
483
510
  //# sourceMappingURL=index.d.mts.map
@@ -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;;qBAoCI,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;;;qBCNhC,MAAM,kBAAkB;;;UC/CpB;WACN,UAAU;WACV,WACP,OAAO,aACP,2BACG;WACI,WACP,OAAO,aACP,SAAS,cACT,WAAW;;;;;;;;;;;;;;;;;;wBAoBC,sBACd,UACA,UACA,WACC,2BAA2B;;;qBCvCjB,iBAAiB;;;qBCAjB,oBAAoB;;;qBCGpB,qBAAoB;;;qBCGpB,WAAY,UAAU,SAAS,aAAW,KACrD,eAAiB;EAEb,OAAO,MAAM;;;;wBCJH,aAAa,mBAAmB;;;wBCFhC,uBAAuB;;;UCAtB;;EAEf,OAAO;;EAEP,WAAW;;;;;;;;EAQX,QAAQ;;UAGO;;;;;;EAMf;;KAGU,oBACV,SAAS,4BACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiGI,aACd,SAAS,kBACT,UAAU;;;UC7HK;;EAEf,OAAO;;EAEP,eAAe;;KAGL,qBAAqB,SAAS;UAEzB;;;;;;EAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsFc,cACd,SAAS,mBACT,UAAU;;;UCrGK;EACf;EACA,uBAAuB,OAAO;;;;KCUpB;UAEK;EACf,OAAO;EACP;EACA,yBAAyB;;;;;;;;;;;;;EAazB,WAAW;;;;;;;;EAQX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCLe;;;;;;EAMf;;;;;;EAOA;;;;;;;;;;EAWA,yBAAyB;;;;UC7CV;EACf,QAAQ;EACR,UAAU;EACV,+BAA+B;EAC/B,oBAAoB;EACpB,YAAY;EACZ;;qBAGW,gBAAgB,kBAAkB;;;qBCvBlC,cAAY,QAAA;qBAEZ,eAAa,QAAA;qBAEb,kBAAgB,QAAA"}
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/direction-tracker.ts","../../../../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;;qBAoCI,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;;;qBCNhC,MAAM,kBAAkB;;;UC/CpB;WACN,UAAU;WACV,WACP,OAAO,aACP,2BACG;WACI,WACP,OAAO,aACP,SAAS,cACT,WAAW;;;;;;;;;;;;;;;;;;wBAoBC,sBACd,UACA,UACA,WACC,2BAA2B;;;qBCvCjB,iBAAiB;;;qBCAjB,oBAAoB;;;qBCGpB,qBAAoB;;;qBCGpB,WAAY,UAAU,SAAS,aAAW,KACrD,eAAiB;EAEb,OAAO,MAAM;;;;wBCJH,aAAa,mBAAmB;;;wBCFhC,uBAAuB;;;UCAtB;;EAEf,OAAO;;EAEP,WAAW;;;;;;;;EAQX,QAAQ;;UAGO;;;;;;EAMf;;KAGU,oBACV,SAAS,4BACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiGI,aACd,SAAS,kBACT,UAAU;;;UC7HK;;EAEf,OAAO;;EAEP,eAAe;;KAGL,qBAAqB,SAAS;UAEzB;;;;;;EAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsFc,cACd,SAAS,mBACT,UAAU;;;UCzGK;EACf;;;;;;;;;;;;;;;;;;;;;;;wBA8Bc,uBAAuB,QAAQ,SAAS;;;UC3BvC;EACf;EACA,uBAAuB,OAAO;;;;KCUpB;UAEK;EACf,OAAO;EACP;EACA,yBAAyB;;;;;;;;;;;;;EAazB,WAAW;;;;;;;;EAQX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCLe;;;;;;EAMf;;;;;;EAOA;;;;;;;;;;EAWA,yBAAyB;;;;UC7CV;EACf,QAAQ;EACR,UAAU;EACV,+BAA+B;EAC/B,oBAAoB;EACpB,YAAY;EACZ;;qBAGW,gBAAgB,kBAAkB;;;qBCvBlC,cAAY,QAAA;qBAEZ,eAAa,QAAA;qBAEb,kBAAgB,QAAA"}
@@ -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";import{putField as ne}from"@real-router/core/utils";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 re=new Set([k,A,j]);function ie(e,t,n){return t===``?!1:n?e===t:p(e,t)}function M(e,t){for(let n of g(e))h(n)&&(re.has(n.type)?t.push(n):M(n.props.children,t))}function N(e,t,n){return b(m,{children:n===void 0?e:b(_,{fallback:n,children:e})},t)}function ae(e){return e.type===j||e.type===A}function oe(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 se(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return r||!ie(t,c,a)?null:N(s,c,o)}function ce(e,t,n,r){if(r.selfFound&&t===n){e.push(N(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 le(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(ae(o)){oe(o,r);continue}let e=se(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||ce(a,t,n,r),{rendered:a,activeMatchFound:i}}function P(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 F=e(n,`useNavigator`),I=e(t,`useRouter`);function L(e){let t=I(),n=F(),r=T(t,e),{route:i,previousRoute:a}=P(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function R({nodeName:e,children:t}){let{route:n}=L(e),r=s(()=>{let e=[];return M(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:le(r,i,e).rendered,[r,i,e]);return a.length>0?b(y,{children:a}):null}R.displayName=`RouteView`;const ue=Object.assign(R,{Match:k,Self:A,NotFound:j}),de=Object.freeze({}),fe=Object.freeze({}),z=`data-real-router-announcer`,pe=Object.freeze({destroy:()=>{}}),B=`data-rr-announcer-refs`,V=`data-rr-announcer-generation`;function H(e){return Number(e.getAttribute(B))}function U(e,t){e.setAttribute(B,String(t))}function me(e,t){if(typeof document>`u`)return pe;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=ge();U(u,H(u)+1);let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ye(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=ve(e,n,r,t);if(i&&i!==s){if(!a){c=i;return}f(i,t)}})})});return{destroy(){if(o||(o=!0,m(),clearTimeout(l),clearTimeout(p),d!==W()))return;let e=H(u)-1;U(u,e),e===0&&_e(u)}}}function W(){return Number(document.documentElement.getAttribute(V))}function he(){let e=document.documentElement,t=W()+1;return e.setAttribute(V,String(t)),t}function ge(){let e=document.querySelector(`[${z}]`);if(e)return{element:e,generation:Number(e.getAttribute(V))};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(z,``),U(t,0),t.setAttribute(V,String(he())),(document.body??document.documentElement).prepend(t),{element:t,generation:Number(t.getAttribute(V))}}function _e(e){e.remove()}function ve(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 ye(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const G=Object.create,K=Object.freeze({destroy:()=>{}});function be(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),t=e?JSON.parse(e):void 0;s=Object.assign(G(null),t)}catch{s=G(null)}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=0,m=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=p+=1,r=()=>{if(g||n!==p)return;let o=i();if(o){if(o.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(o.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(r))};r()},h=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)},g=!1,_=!0,v=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;t&&_&&l(q(t),d()),_=!1,requestAnimationFrame(()=>{if(!g){if(_=!0,n===`top`){h(e);return}if(e.transition?.reload||r?.navigationType===`reload`){m(c()[q(e)]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){m(c()[q(e)]??0);return}e.transition?.replace||r?.navigationType===`replace`||h(e)}})}),y=()=>{let t=e.getState();t&&l(q(t),d())};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{g=!0,v(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}function q(e){return e.path}const J=Object.freeze({destroy:()=>{}}),Y=e=>e.context?.url,xe=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},Se=(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}}},Ce=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()}}},we=(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)}}},Te=(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 Ee(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=Se(e,()=>{s=!0}),p=Ce(a),m=we(()=>{u?.()},150),h=Te(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=xe(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 De=Object.freeze({destroy:()=>{}});function Oe(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return De;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()}}}const X=Object.keys;function ke(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 Ae(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function je(e){return!!e&&e!==`_self`}function Me(e){return encodeURI(e).replaceAll(`#`,`%23`)}function Ne(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;try{let i=O(e),a=i.forwardState(t,n,r);s=i.buildPathResolved(a.name,a.params,a.search)}catch{s=void 0}let c=s??e.buildPath(t,n,r);if(typeof c!=`string`||c.length===0){console.error(`[real-router] Route "${t}" yielded an empty path. The element will render without an href attribute.`);return}return a?`${c}#${Me(a)}`:c}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function Pe(e,t,n,r,i,a){let o={...a};i!==void 0&&ne(o,`hash`,i);let s=e.getState(),c=r;if(s!==void 0){let a=r??s.search;if(e.isActiveRoute(t,n,a,!0,!1)){let e=s.context?.url?.hash??``;e!==(i??e)&&(o.force=!0,o.hashChange=!0,c=a)}}return e.navigate(t,n,c,o)}const Fe=/\s/,Ie=/\S+/g;function Z(e){return Fe.test(e)?e.match(Ie)??[]:[e]}function Le(e,t,n){if(e&&t){let e=Z(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=Z(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 Q(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=X(e),r=X(t);if(n.length!==r.length)return!1;let i=e,a=t;for(let e of n)if(!r.includes(e)||!Object.is(i[e],a[e]))return!1;return!0}function Re(e,t,n,r=!1,i=!0,a){let o=I(),c=s(()=>S(o,e,t,n,r,i,a),[o,e,t,n,r,i,a]);return P(c.subscribe,c.getSnapshot,c.getSnapshot)}function ze(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&&Q(e.routeParams,t.routeParams)&&Q(e.routeSearch,t.routeSearch)&&Q(e.to,t.to)&&Q(e.routeOptions,t.routeOptions)}const $=v(({routeName:e,routeParams:t,routeSearch:n,to:r,routeOptions:i=fe,className:a,activeClassName:o=`active`,activeStrict:s=!1,ignoreQueryParams:c=!0,hash:l,onClick:u,target:d,children:f,...p})=>{let m=I(),{name:h,params:g,search:_}=ke(r,e??``,t,n),v=Re(h,g,_,s,c,l),y=g??de,x=Ne(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}Ae(e)&&!je(d)&&(e.preventDefault(),Pe(m,h,y,_,l,i).catch(()=>{}))},C=Le(v,o,a);return b(`a`,{...p,target:d,href:x,className:C,onClick:S,children:f})},ze);$.displayName=`Link`;function Be({children:e,fallback:t,onError:n}){let r=I(),i=C(r),s=P(i.subscribe,i.getSnapshot,i.getSnapshot),l=c(n);return o(()=>{l.current=n}),a(()=>{s.error&&l.current?.(s.error,s.toRoute,s.fromRoute)},[s.version]),x(m,{children:[e,s.error?t(s.error,s.resetError):null]})}const Ve=()=>{let e=I();return f(O(e).getTree())};function He(){let e=I(),t=E(e);return P(t.subscribe,t.getSnapshot,t.getSnapshot)}function Ue(e,t){let n=I(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(D(e=>r.current(e),{skipSameRoute:i})),[n,i])}function We(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 Ge=({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=me(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=be(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=Ee(e,{selector:x,rootMargin:S,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,C,x,S]),a(()=>{if(!u)return;let t=Oe(e);return()=>{t.destroy()}},[e,u]);let w=d(e),T=s(()=>ee(e),[e]);a(()=>{te(e)},[e]);let{route:E,previousRoute:D}=P(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,ue as RouteView,t as RouterContext,Be as RouterErrorBoundary,Ge as RouterProvider,F as useNavigator,i as useRoute,We as useRouteEnter,Ue as useRouteExit,L as useRouteNode,Ve as useRouteUtils,I as useRouter,He 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,events as d,getNavigator as f}from"@real-router/core";import{getRouteUtils as p,startsWithSegment as m}from"@real-router/route-utils";import{Fragment as h,isValidElement as g,toChildArray as _}from"preact";import{Suspense as v,memo as y}from"preact/compat";import{Fragment as b,jsx as x,jsxs as S}from"preact/jsx-runtime";import{createActiveSource as C,createDismissableError as w,createRouteEnterGate as T,createRouteNodeSource as E,createRouteSource as ee,getTransitionSource as D,guardLeaveListener as O,primeErrorSource as te}from"@real-router/sources";import{getPluginApi as k}from"@real-router/core/api";import{putField as ne}from"@real-router/core/utils";function A(e){return null}A.displayName=`RouteView.Match`;function j(e){return null}j.displayName=`RouteView.Self`;function M(e){return null}M.displayName=`RouteView.NotFound`;const re=new Set([A,j,M]);function ie(e,t,n){return t===``?!1:n?e===t:m(e,t)}function N(e,t){for(let n of _(e))g(n)&&(re.has(n.type)?t.push(n):N(n.props.children,t))}function P(e,t,n){return x(h,{children:n===void 0?e:x(v,{fallback:n,children:e})},t)}function ae(e){return e.type===M||e.type===j}function oe(e,t){if(e.type===M){t.notFoundFound||=(t.notFoundChildren=e.props.children,!0);return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function se(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return r||!ie(t,c,a)?null:P(s,c,o)}function ce(e,t,n,r){if(r.selfFound&&t===n){e.push(P(r.selfChildren,`__route-view-self__`,r.selfFallback));return}t===u&&r.notFoundChildren!==null&&e.push(x(h,{children:r.notFoundChildren},`__route-view-not-found__`))}function le(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(ae(o)){oe(o,r);continue}let e=se(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||ce(a,t,n,r),{rendered:a,activeMatchFound:i}}function F(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 I=e(n,`useNavigator`),L=e(t,`useRouter`);function R(e){let t=L(),n=I(),r=E(t,e),{route:i,previousRoute:a}=F(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function z({nodeName:e,children:t}){let{route:n}=R(e),r=s(()=>{let e=[];return N(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:le(r,i,e).rendered,[r,i,e]);return a.length>0?x(b,{children:a}):null}z.displayName=`RouteView`;const ue=Object.assign(z,{Match:A,Self:j,NotFound:M}),de=Object.freeze({}),fe=Object.freeze({}),pe=Object.freeze({destroy:()=>{}});function me(e){if(typeof document>`u`)return pe;let t=!1;document.documentElement.dataset.navDirection=`forward`;let n=!1,r=!1,i=()=>{t=!0,r=n};globalThis.addEventListener(`popstate`,i);let a=k(e),o=()=>{if(n=!1,r){r=!1;return}t=!1},s=[a.addEventListener(d.TRANSITION_START,()=>{n=!0}),a.addEventListener(d.TRANSITION_SUCCESS,o),a.addEventListener(d.TRANSITION_ERROR,o),a.addEventListener(d.TRANSITION_CANCEL,o),e.subscribeLeave(()=>{document.documentElement.dataset.navDirection=t?`back`:`forward`,t=!1,r=!1})];return{destroy:()=>{for(let e of s)e();globalThis.removeEventListener(`popstate`,i),delete document.documentElement.dataset.navDirection}}}const B=`data-real-router-announcer`,he=Object.freeze({destroy:()=>{}}),V=`data-rr-announcer-refs`,H=`data-rr-announcer-generation`;function U(e){return Number(e.getAttribute(V))}function W(e,t){e.setAttribute(V,String(t))}function ge(e,t){if(typeof document>`u`)return he;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=ve();W(u,U(u)+1);let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),xe(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=be(e,n,r,t);if(i&&i!==s){if(!a){c=i;return}f(i,t)}})})});return{destroy(){if(o||(o=!0,m(),clearTimeout(l),clearTimeout(p),d!==G()))return;let e=U(u)-1;W(u,e),e===0&&ye(u)}}}function G(){return Number(document.documentElement.getAttribute(H))}function _e(){let e=document.documentElement,t=G()+1;return e.setAttribute(H,String(t)),t}function ve(){let e=document.querySelector(`[${B}]`);if(e)return{element:e,generation:Number(e.getAttribute(H))};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(B,``),W(t,0),t.setAttribute(H,String(_e())),(document.body??document.documentElement).prepend(t),{element:t,generation:Number(t.getAttribute(H))}}function ye(e){e.remove()}function be(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 xe(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const K=Object.create,q=Object.freeze({destroy:()=>{}});function Se(e,t){if(globalThis.window===void 0)return q;let n=t?.mode??`restore`;if(n===`native`)return q;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),t=e?JSON.parse(e):void 0;s=Object.assign(K(null),t)}catch{s=K(null)}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=0,m=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=p+=1,r=()=>{if(g||n!==p)return;let o=i();if(o){if(o.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(o.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(r))};r()},h=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)},g=!1,_=!0,v=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;t&&_&&l(J(t),d()),_=!1,requestAnimationFrame(()=>{if(!g){if(_=!0,n===`top`){h(e);return}if(e.transition?.reload||r?.navigationType===`reload`){m(c()[J(e)]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){m(c()[J(e)]??0);return}e.transition?.replace||r?.navigationType===`replace`||h(e)}})}),y=()=>{let t=e.getState();t&&l(J(t),d())};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{g=!0,v(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}function J(e){return e.path}const Y=Object.freeze({destroy:()=>{}}),X=e=>e.context?.url,Ce=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},we=(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}}},Te=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()}}},Ee=(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)}}},De=(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 Oe(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return Y;let{selector:n}=t;if(!n)return Y;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=D(e),f=we(e,()=>{s=!0}),p=Te(a),m=Ee(()=>{u?.()},150),h=De(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=Ce(h.pending.values());if(h.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===X(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(),X(e)?.hashChanged&&p.start())});return{destroy(){o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy()}}}const ke=Object.freeze({destroy:()=>{}});function Ae(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return ke;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()}}}const Z=Object.keys,je=Symbol.for(`real-router.router`);function Me(e){try{return e?.[je]===!0}catch{return!1}}function Ne(e,t){try{return k(e)}catch{Me(e)&&console.error(`[real-router] Route "${t}" rendered its LITERAL path: this IS a router, but not one this copy of @real-router/core built, so \`forwardTo\` was not resolved. It is either wrapped in a Proxy (Vue \`reactive()\` / Pinia — store it with \`markRaw\`), or your dependency tree holds two copies of @real-router/core — dedupe it to one.`);return}}function Pe(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 Fe(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function Ie(e){return!!e&&e!==`_self`}function Le(e){return encodeURI(e).replaceAll(`#`,`%23`)}function Re(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,c=Ne(e,t);try{let e=c?.forwardState(t,n,r);s=e&&c?.buildPathResolved(e.name,e.params,e.search)}catch{s=void 0}let l=s??e.buildPath(t,n,r);if(typeof l!=`string`||l.length===0){console.error(`[real-router] Route "${t}" yielded an empty path. The element will render without an href attribute.`);return}return a?`${l}#${Le(a)}`:l}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function ze(e,t,n,r,i,a){let o={...a};i!==void 0&&ne(o,`hash`,i);let s=e.getState(),c=r;if(s!==void 0){let a=r??s.search;if(e.isActiveRoute(t,n,a,!0,!1)){let e=s.context?.url?.hash??``;e!==(i??e)&&(o.force=!0,o.hashChange=!0,c=a)}}return e.navigate(t,n,c,o)}const Be=/\s/,Ve=/\S+/g;function Q(e){return Be.test(e)?e.match(Ve)??[]:[e]}function He(e,t,n){if(e&&t){let e=Q(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=Q(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 $(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Z(e),r=Z(t);if(n.length!==r.length)return!1;let i=e,a=t;for(let e of n)if(!r.includes(e)||!Object.is(i[e],a[e]))return!1;return!0}function Ue(e,t,n,r=!1,i=!0,a){let o=L(),c=s(()=>C(o,e,t,n,r,i,a),[o,e,t,n,r,i,a]);return F(c.subscribe,c.getSnapshot,c.getSnapshot)}function We(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&&$(e.routeParams,t.routeParams)&&$(e.routeSearch,t.routeSearch)&&$(e.to,t.to)&&$(e.routeOptions,t.routeOptions)}const Ge=y(({routeName:e,routeParams:t,routeSearch:n,to:r,routeOptions:i=fe,className:a,activeClassName:o=`active`,activeStrict:s=!1,ignoreQueryParams:c=!0,hash:l,onClick:u,target:d,children:f,...p})=>{let m=L(),{name:h,params:g,search:_}=Pe(r,e??``,t,n),v=Ue(h,g,_,s,c,l),y=g??de,b=Re(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}Fe(e)&&!Ie(d)&&(e.preventDefault(),ze(m,h,y,_,l,i).catch(()=>{}))},C=He(v,o,a);return x(`a`,{...p,target:d,href:b,className:C,onClick:S,children:f})},We);Ge.displayName=`Link`;function Ke({children:e,fallback:t,onError:n}){let r=L(),i=w(r),s=F(i.subscribe,i.getSnapshot,i.getSnapshot),l=c(n);return o(()=>{l.current=n}),a(()=>{s.error&&l.current?.(s.error,s.toRoute,s.fromRoute)},[s.version]),S(h,{children:[e,s.error?t(s.error,s.resetError):null]})}const qe=()=>{let e=L();return p(k(e).getTree())};function Je(){let e=L(),t=D(e);return F(t.subscribe,t.getSnapshot,t.getSnapshot)}function Ye(e,t){let n=L(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(O(e=>r.current(e),{skipSameRoute:i})),[n,i])}function Xe(e,t){let{route:n,previousRoute:r}=i(),s=c(e),[u]=l(()=>T()),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 d=o!==void 0&&o!==!1,p=typeof o==`object`?o:void 0,m=p?.prefix;a(()=>{if(!d)return;let t=ge(e,p);return()=>{t.destroy()}},[e,d,m]);let h=c?.mode,g=c?.anchorScrolling,_=c?.behavior,v=c?.storageKey,y=c!==void 0;a(()=>{if(!y)return;let t=Se(e,{mode:h,anchorScrolling:g,behavior:_,storageKey:v,scrollContainer:c.scrollContainer});return()=>{t.destroy()}},[e,y,h,g,_,v]);let b=l?.selector,S=l?.rootMargin,C=l!==void 0&&b!==void 0&&b!==``;a(()=>{if(!C)return;let t=Oe(e,{selector:b,rootMargin:S,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,C,b,S]),a(()=>{if(!u)return;let t=Ae(e);return()=>{t.destroy()}},[e,u]);let w=f(e),T=s(()=>ee(e),[e]);a(()=>{te(e)},[e]);let{route:E,previousRoute:D}=F(T.subscribe,T.getSnapshot,T.getSnapshot),O=s(()=>({navigator:w,route:E,previousRoute:D}),[w,E,D]);return x(t.Provider,{value:e,children:x(n.Provider,{value:w,children:x(r.Provider,{value:O,children:i})})})};export{Ge as Link,n as NavigatorContext,r as RouteContext,ue as RouteView,t as RouterContext,Ke as RouterErrorBoundary,Ze as RouterProvider,me as createDirectionTracker,I as useNavigator,i as useRoute,Xe as useRouteEnter,Ye as useRouteExit,R as useRouteNode,qe as useRouteUtils,L as useRouter,Je as useRouterTransition};
2
2
  //# sourceMappingURL=index.mjs.map