@real-router/preact 0.15.2 → 0.15.3

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.
Files changed (36) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.mjs +1 -1
  4. package/dist/esm/index.mjs.map +1 -1
  5. package/package.json +5 -6
  6. package/src/RouterProvider.tsx +0 -152
  7. package/src/components/Await.tsx +0 -99
  8. package/src/components/ClientOnly.tsx +0 -25
  9. package/src/components/HttpStatusCode.tsx +0 -82
  10. package/src/components/HttpStatusProvider.tsx +0 -22
  11. package/src/components/Link.tsx +0 -141
  12. package/src/components/RouteView/RouteView.tsx +0 -57
  13. package/src/components/RouteView/components.tsx +0 -19
  14. package/src/components/RouteView/helpers.tsx +0 -174
  15. package/src/components/RouteView/index.ts +0 -8
  16. package/src/components/RouteView/types.ts +0 -24
  17. package/src/components/RouterErrorBoundary.tsx +0 -84
  18. package/src/components/ServerOnly.tsx +0 -26
  19. package/src/components/Streamed.tsx +0 -24
  20. package/src/constants.ts +0 -9
  21. package/src/context.ts +0 -27
  22. package/src/hooks/useDeferred.tsx +0 -26
  23. package/src/hooks/useIsActiveRoute.tsx +0 -46
  24. package/src/hooks/useNavigator.tsx +0 -8
  25. package/src/hooks/useRoute.tsx +0 -26
  26. package/src/hooks/useRouteEnter.tsx +0 -147
  27. package/src/hooks/useRouteExit.tsx +0 -159
  28. package/src/hooks/useRouteNode.tsx +0 -34
  29. package/src/hooks/useRouteUtils.tsx +0 -12
  30. package/src/hooks/useRouter.tsx +0 -8
  31. package/src/hooks/useRouterTransition.tsx +0 -17
  32. package/src/index.ts +0 -56
  33. package/src/ssr.ts +0 -39
  34. package/src/types.ts +0 -40
  35. package/src/useSyncExternalStore.ts +0 -60
  36. package/src/utils/createHttpStatusSink.ts +0 -27
@@ -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{createActiveRouteSource as S,createDismissableError as C,createRouteNodeSource as w,createRouteSource as ee,getTransitionSource as T}from"@real-router/sources";import{getPluginApi as te}from"@real-router/core/api";function E(e){return null}E.displayName=`RouteView.Match`;function D(e){return null}D.displayName=`RouteView.Self`;function O(e){return null}O.displayName=`RouteView.NotFound`;const ne=new Set([E,D,O]);function k(e,t,n){return t===``?!1:n?e===t:p(e,t)}function A(e,t){for(let n of g(e))h(n)&&(ne.has(n.type)?t.push(n):A(n.props.children,t))}function j(e,t,n){return b(m,{children:n===void 0?e:b(_,{fallback:n,children:e})},t)}function re(e){return e.type===O||e.type===D}function ie(e,t){if(e.type===O){t.notFoundChildren=e.props.children;return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function ae(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return!r&&k(t,c,a)?j(s,c,o):null}function oe(e,t,n,r){if(r.selfFound&&t===n){e.push(j(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 se(e,t,n){let r={selfChildren:null,selfFallback:void 0,selfFound:!1,notFoundChildren:null},i=!1,a=[];for(let o of e){if(re(o)){ie(o,r);continue}let e=ae(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||oe(a,t,n,r),{rendered:a,activeMatchFound:i}}function M(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 N=e(n,`useNavigator`),P=e(t,`useRouter`);function F(e){let t=P(),n=N(),r=w(t,e),{route:i,previousRoute:a}=M(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function I({nodeName:e,children:t}){let{route:n}=F(e),r=s(()=>{let e=[];return A(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:se(r,i,e).rendered,[r,i,e]);return a.length>0?b(y,{children:a}):null}I.displayName=`RouteView`;const ce=Object.assign(I,{Match:E,Self:D,NotFound:O}),L=Object.freeze({}),R=Object.freeze({}),z=`data-real-router-announcer`,B=Object.freeze({destroy:()=>{}});function V(e,t){if(typeof document>`u`)return B;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,u=H(),d=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),G(t)},f=setTimeout(()=>{if(a=!0,c!==null&&!o){let e=c;c=null,d(e,document.querySelector(`h1`))}},100),p=e.subscribe(({route:e})=>{if(i){i=!1;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(o)return;let t=document.querySelector(`h1`),i=W(e,n,r,t);if(!(!i||i===s)){if(!a){c=i;return}d(i,t)}})})});return{destroy(){o=!0,p(),clearTimeout(l),clearTimeout(f),U()}}}function H(){let e=document.querySelector(`[${z}]`);if(e)return e;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,``),(document.body??document.documentElement).prepend(t),t}function U(){document.querySelector(`[${z}]`)?.remove()}function W(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 G(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const K=Object.freeze({destroy:()=>{}});function le(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,_=e=>{try{return ue(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}},v=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;if(t){let e=_(t);e!==null&&l(e,d())}requestAnimationFrame(()=>{if(!h){if(n===`top`){m(e);return}if(e.transition.reload||r?.navigationType===`reload`){let t=_(e);p(t===null?0:c()[t]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){let t=_(e);p(t===null?0:c()[t]??0);return}e.transition.replace||r?.navigationType===`replace`||m(e)}})}),y=()=>{let t=e.getState();if(t){let e=_(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{if(!h){h=!0,v(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}}const q=new WeakMap;function ue(e){let t=q.get(e);if(t!==void 0)return t;let n=`${e.name}:${de(e.params)}`;return q.set(e,n),n}function de(e){return JSON.stringify(e,fe)}function fe(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,pe=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},X=(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}}},me=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()}}},he=(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)}}},ge=(e,t,n,r,i,a)=>{let o=new Set,s=new Map,c=!1,l=null,u=new IntersectionObserver(e=>{if(!a()){for(let t of e)s.set(t.target,t);r()}},{root:n(),rootMargin:t,threshold:0}),d=()=>{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)&&(u.observe(e),o.add(e))}},f=()=>{for(let e of o)e.isConnected||(u.unobserve(e),o.delete(e),s.delete(e));d()};d();let p=n()??document.body,m=new MutationObserver(()=>{l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,f()},250)});return m.observe(p,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`id`]}),{pending:s,destroy(){u.disconnect(),m.disconnect(),l!==null&&(clearTimeout(l),l=null),o.clear(),s.clear()}}};function _e(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=T(e),f=X(e,()=>{s=!0}),p=me(a),m=he(()=>{u?.()},150),h=ge(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||h.pending.size===0)return;let t=pe(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||Y(e)?.hashChanged&&p.start()});return{destroy(){o||(o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy())}}}const ve=Object.freeze({destroy:()=>{}});function ye(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return ve;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;r=!0,t=null,e===null?n=null:setTimeout(()=>{e(),n=null},0)});return{destroy:()=>{a(),o(),n?.skipTransition?.(),n=null,i()}}}function be(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}const xe=/%[\dA-Fa-f]{2}/;function Se(e){if(xe.test(e))try{return encodeURI(decodeURIComponent(e)).replaceAll(`#`,`%23`)}catch{}return encodeURI(e).replaceAll(`#`,`%23`)}function Ce(e,t,n,r){try{let i=r?.hash,a;i!==void 0&&(a=i.startsWith(`#`)?i.slice(1):i);let o=e.buildUrl;if(o){let e=o(t,n,a===void 0?void 0:{hash:a});if(typeof e==`string`&&e.length>0)return e}let s=e.buildPath(t,n);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}#${Se(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function we(e,t,n,r,i){let a={...i};r!==void 0&&(a.hash=r);let o=e.getState();if(o?.name===t&&Q(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 Te=/\s/,Ee=/\S+/g;function Z(e){return e?Te.test(e)?e.match(Ee)??[]:[e]:[]}function De(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=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 Oe(e,t,n=!1,r=!0,i){let a=P(),o=s(()=>i===void 0?{strict:n,ignoreQueryParams:r}:{strict:n,ignoreQueryParams:r,hash:i},[n,r,i]),c=s(()=>S(a,e,t,o),[a,e,t,o]);return M(c.subscribe,c.getSnapshot,c.getSnapshot)}function ke(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.routeOptions,t.routeOptions)}const $=v(({routeName:e,routeParams:t=L,routeOptions:n=R,className:r,activeClassName:i=`active`,activeStrict:a=!1,ignoreQueryParams:o=!0,hash:s,onClick:c,target:l,children:u,...d})=>{let f=P(),p=Oe(e,t,a,o,s),m=Ce(f,e,t,s===void 0?void 0:{hash:s}),h=r=>{c&&(c(r),r.defaultPrevented)||!be(r)||l===`_blank`||(r.preventDefault(),we(f,e,t,s,n).catch(()=>{}))},g=De(p,i,r);return b(`a`,{...d,href:m,className:g,onClick:h,children:u})},ke);$.displayName=`Link`;function Ae({children:e,fallback:t,onError:n}){let r=C(P()),i=M(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 je=()=>f(te(P()).getTree());function Me(){let e=T(P());return M(e.subscribe,e.getSnapshot,e.getSnapshot)}function Ne(e,t){let n=P(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(({route:e,nextRoute:t,signal:n})=>{if(!(i&&e.name===t.name)&&!n.aborted)return r.current({route:e,nextRoute:t,signal:n})}),[n,i])}function Pe(e,t){let{route:n,previousRoute:r}=i(),s=c(e),l=c(null),u=t?.skipSameRoute??!0;o(()=>{s.current=e}),a(()=>{n.transition.from&&(u&&n.transition.from===n.name||l.current===n||!r||(l.current=n,s.current({route:n,previousRoute:r})))},[n,r,u])}const Fe=({router:e,children:i,announceNavigation:o,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{a(()=>{if(!o)return;let t=V(e);return()=>{t.destroy()}},[o,e]);let f=c?.mode,p=c?.anchorScrolling,m=c?.behavior,h=c?.storageKey,g=c!==void 0;a(()=>{if(!g)return;let t=le(e,{mode:f,anchorScrolling:p,behavior:m,storageKey:h,scrollContainer:c.scrollContainer});return()=>{t.destroy()}},[e,g,f,p,m,h]);let _=l?.selector,v=l?.rootMargin,y=l!==void 0&&_!==void 0&&_!==``;a(()=>{if(!y)return;let t=_e(e,{selector:_,rootMargin:v,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,y,_,v]),a(()=>{if(!u)return;let t=ye(e);return()=>{t.destroy()}},[e,u]);let x=d(e),S=s(()=>ee(e),[e]),{route:C,previousRoute:w}=M(S.subscribe,S.getSnapshot,S.getSnapshot),T=s(()=>({navigator:x,route:C,previousRoute:w}),[x,C,w]);return b(t.Provider,{value:e,children:b(n.Provider,{value:x,children:b(r.Provider,{value:T,children:i})})})};export{$ as Link,n as NavigatorContext,r as RouteContext,ce as RouteView,t as RouterContext,Ae as RouterErrorBoundary,Fe as RouterProvider,N as useNavigator,i as useRoute,Pe as useRouteEnter,Ne as useRouteExit,F as useRouteNode,je as useRouteUtils,P as useRouter,Me 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{createActiveRouteSource as S,createDismissableError as C,createRouteNodeSource as w,createRouteSource as ee,getTransitionSource as T}from"@real-router/sources";import{getPluginApi as te}from"@real-router/core/api";function E(e){return null}E.displayName=`RouteView.Match`;function D(e){return null}D.displayName=`RouteView.Self`;function O(e){return null}O.displayName=`RouteView.NotFound`;const ne=new Set([E,D,O]);function k(e,t,n){return t===``?!1:n?e===t:p(e,t)}function A(e,t){for(let n of g(e))h(n)&&(ne.has(n.type)?t.push(n):A(n.props.children,t))}function j(e,t,n){return b(m,{children:n===void 0?e:b(_,{fallback:n,children:e})},t)}function re(e){return e.type===O||e.type===D}function ie(e,t){if(e.type===O){t.notFoundChildren=e.props.children;return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function ae(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return!r&&k(t,c,a)?j(s,c,o):null}function oe(e,t,n,r){if(r.selfFound&&t===n){e.push(j(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 se(e,t,n){let r={selfChildren:null,selfFallback:void 0,selfFound:!1,notFoundChildren:null},i=!1,a=[];for(let o of e){if(re(o)){ie(o,r);continue}let e=ae(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||oe(a,t,n,r),{rendered:a,activeMatchFound:i}}function M(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 N=e(n,`useNavigator`),P=e(t,`useRouter`);function F(e){let t=P(),n=N(),r=w(t,e),{route:i,previousRoute:a}=M(r.subscribe,r.getSnapshot,r.getSnapshot);return s(()=>({navigator:n,route:i,previousRoute:a}),[n,i,a])}function I({nodeName:e,children:t}){let{route:n}=F(e),r=s(()=>{let e=[];return A(t,e),e},[t]),i=n?.name,a=s(()=>i===void 0?[]:se(r,i,e).rendered,[r,i,e]);return a.length>0?b(y,{children:a}):null}I.displayName=`RouteView`;const ce=Object.assign(I,{Match:E,Self:D,NotFound:O}),L=Object.freeze({}),R=Object.freeze({}),z=`data-real-router-announcer`,B=Object.freeze({destroy:()=>{}});function V(e,t){if(typeof document>`u`)return B;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,u=H(),d=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),G(t)},f=setTimeout(()=>{if(a=!0,c!==null&&!o){let e=c;c=null,d(e,document.querySelector(`h1`))}},100),p=e.subscribe(({route:e})=>{if(i){i=!1;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(o)return;let t=document.querySelector(`h1`),i=W(e,n,r,t);if(!(!i||i===s)){if(!a){c=i;return}d(i,t)}})})});return{destroy(){o=!0,p(),clearTimeout(l),clearTimeout(f),U()}}}function H(){let e=document.querySelector(`[${z}]`);if(e)return e;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,``),(document.body??document.documentElement).prepend(t),t}function U(){document.querySelector(`[${z}]`)?.remove()}function W(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 G(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const K=Object.freeze({destroy:()=>{}});function le(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,_=e=>{try{return ue(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}},v=e.subscribe(({route:e,previousRoute:t})=>{let r=e.context.navigation;if(t){let e=_(t);e!==null&&l(e,d())}requestAnimationFrame(()=>{if(!h){if(n===`top`){m(e);return}if(e.transition.reload||r?.navigationType===`reload`){let t=_(e);p(t===null?0:c()[t]??0);return}if(r?.direction===`back`||r?.navigationType===`traverse`){let t=_(e);p(t===null?0:c()[t]??0);return}e.transition.replace||r?.navigationType===`replace`||m(e)}})}),y=()=>{let t=e.getState();if(t){let e=_(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{if(!h){h=!0,v(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}}const q=new WeakMap;function ue(e){let t=q.get(e);if(t!==void 0)return t;let n=`${e.name}:${de(e.params)}`;return q.set(e,n),n}function de(e){return JSON.stringify(e,fe)}function fe(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,pe=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},X=(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}}},me=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()}}},he=(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)}}},ge=(e,t,n,r,i,a)=>{let o=new Set,s=new Map,c=!1,l=null,u=new IntersectionObserver(e=>{if(!a()){for(let t of e)s.set(t.target,t);r()}},{root:n(),rootMargin:t,threshold:0}),d=()=>{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)&&(u.observe(e),o.add(e))}},f=()=>{for(let e of o)e.isConnected||(u.unobserve(e),o.delete(e),s.delete(e));d()};d();let p=n()??document.body,m=new MutationObserver(()=>{l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,f()},250)});return m.observe(p,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`id`]}),{pending:s,destroy(){u.disconnect(),m.disconnect(),l!==null&&(clearTimeout(l),l=null),o.clear(),s.clear()}}};function _e(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=T(e),f=X(e,()=>{s=!0}),p=me(a),m=he(()=>{u?.()},150),h=ge(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||h.pending.size===0)return;let t=pe(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||Y(e)?.hashChanged&&p.start()});return{destroy(){o||(o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy())}}}const ve=Object.freeze({destroy:()=>{}});function ye(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return ve;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;r=!0,t=null,e===null?n=null:setTimeout(()=>{e(),n=null},0)});return{destroy:()=>{a(),o(),n?.skipTransition?.(),n=null,i()}}}function be(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}const xe=/%[\dA-Fa-f]{2}/;function Se(e){if(xe.test(e))try{return encodeURI(decodeURIComponent(e)).replaceAll(`#`,`%23`)}catch{}return encodeURI(e).replaceAll(`#`,`%23`)}function Ce(e,t,n,r){try{let i=r?.hash,a;i!==void 0&&(a=i.startsWith(`#`)?i.slice(1):i);let o=e.buildUrl;if(o){let e=o(t,n,a===void 0?void 0:{hash:a});if(typeof e==`string`&&e.length>0)return e}let s=e.buildPath(t,n);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}#${Se(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function we(e,t,n,r,i){let a={...i};r!==void 0&&(a.hash=r);let o=e.getState();if(o?.name===t&&Q(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 Te=/\s/,Ee=/\S+/g;function Z(e){return Te.test(e)?e.match(Ee)??[]:[e]}function De(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=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 Oe(e,t,n=!1,r=!0,i){let a=P(),o=s(()=>i===void 0?{strict:n,ignoreQueryParams:r}:{strict:n,ignoreQueryParams:r,hash:i},[n,r,i]),c=s(()=>S(a,e,t,o),[a,e,t,o]);return M(c.subscribe,c.getSnapshot,c.getSnapshot)}function ke(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.routeOptions,t.routeOptions)}const $=v(({routeName:e,routeParams:t=L,routeOptions:n=R,className:r,activeClassName:i=`active`,activeStrict:a=!1,ignoreQueryParams:o=!0,hash:s,onClick:c,target:l,children:u,...d})=>{let f=P(),p=Oe(e,t,a,o,s),m=Ce(f,e,t,s===void 0?void 0:{hash:s}),h=r=>{c&&(c(r),r.defaultPrevented)||!be(r)||l===`_blank`||(r.preventDefault(),we(f,e,t,s,n).catch(()=>{}))},g=De(p,i,r);return b(`a`,{...d,href:m,className:g,onClick:h,children:u})},ke);$.displayName=`Link`;function Ae({children:e,fallback:t,onError:n}){let r=C(P()),i=M(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 je=()=>f(te(P()).getTree());function Me(){let e=T(P());return M(e.subscribe,e.getSnapshot,e.getSnapshot)}function Ne(e,t){let n=P(),r=c(e),i=t?.skipSameRoute??!0;o(()=>{r.current=e}),a(()=>n.subscribeLeave(({route:e,nextRoute:t,signal:n})=>{if(!(i&&e.name===t.name)&&!n.aborted)return r.current({route:e,nextRoute:t,signal:n})}),[n,i])}function Pe(e,t){let{route:n,previousRoute:r}=i(),s=c(e),l=c(null),u=t?.skipSameRoute??!0;o(()=>{s.current=e}),a(()=>{n.transition.from&&(u&&n.transition.from===n.name||l.current===n||!r||(l.current=n,s.current({route:n,previousRoute:r})))},[n,r,u])}const Fe=({router:e,children:i,announceNavigation:o,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{a(()=>{if(!o)return;let t=V(e);return()=>{t.destroy()}},[o,e]);let f=c?.mode,p=c?.anchorScrolling,m=c?.behavior,h=c?.storageKey,g=c!==void 0;a(()=>{if(!g)return;let t=le(e,{mode:f,anchorScrolling:p,behavior:m,storageKey:h,scrollContainer:c.scrollContainer});return()=>{t.destroy()}},[e,g,f,p,m,h]);let _=l?.selector,v=l?.rootMargin,y=l!==void 0&&_!==void 0&&_!==``;a(()=>{if(!y)return;let t=_e(e,{selector:_,rootMargin:v,scrollContainer:l.scrollContainer});return()=>{t.destroy()}},[e,y,_,v]),a(()=>{if(!u)return;let t=ye(e);return()=>{t.destroy()}},[e,u]);let x=d(e),S=s(()=>ee(e),[e]),{route:C,previousRoute:w}=M(S.subscribe,S.getSnapshot,S.getSnapshot),T=s(()=>({navigator:x,route:C,previousRoute:w}),[x,C,w]);return b(t.Provider,{value:e,children:b(n.Provider,{value:x,children:b(r.Provider,{value:T,children:i})})})};export{$ as Link,n as NavigatorContext,r as RouteContext,ce as RouteView,t as RouterContext,Ae as RouterErrorBoundary,Fe as RouterProvider,N as useNavigator,i as useRoute,Pe as useRouteEnter,Ne as useRouteExit,F as useRouteNode,je as useRouteUtils,P as useRouter,Me as useRouterTransition};
2
2
  //# sourceMappingURL=index.mjs.map