@real-router/preact 0.18.53 → 0.19.1
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.js +1 -1
- package/dist/cjs/index.js.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/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useRoute-B0pDCgZw.js");let t=require("preact/hooks"),n=require("@real-router/core"),r=require("@real-router/route-utils"),i=require("preact"),a=require("preact/compat"),o=require("preact/jsx-runtime"),s=require("@real-router/sources"),c=require("@real-router/core/utils"),l=require("@real-router/core/api");function u(e){return null}u.displayName=`RouteView.Match`;function d(e){return null}d.displayName=`RouteView.Self`;function f(e){return null}f.displayName=`RouteView.NotFound`;const p=new Set([u,d,f]);function m(e,t,n){return t===``?!1:n?e===t:(0,r.startsWithSegment)(e,t)}function h(e,t){for(let n of(0,i.toChildArray)(e))(0,i.isValidElement)(n)&&(p.has(n.type)?t.push(n):h(n.props.children,t))}function g(e,t,n){return(0,o.jsx)(i.Fragment,{children:n===void 0?e:(0,o.jsx)(a.Suspense,{fallback:n,children:e})},t)}function _(e){return e.type===f||e.type===d}function v(e,t){if(e.type===f){t.notFoundFound||=(t.notFoundChildren=e.props.children,!0);return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function y(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return r||!m(t,c,a)?null:g(s,c,o)}function b(e,t,r,a){if(a.selfFound&&t===r){e.push(g(a.selfChildren,`__route-view-self__`,a.selfFallback));return}t===n.UNKNOWN_ROUTE&&a.notFoundChildren!==null&&e.push((0,o.jsx)(i.Fragment,{children:a.notFoundChildren},`__route-view-not-found__`))}function x(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(_(o)){v(o,r);continue}let e=y(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||b(a,t,n,r),{rendered:a,activeMatchFound:i}}function S(e,n,r){let[i,a]=(0,t.useState)(n);return(0,t.useEffect)(()=>{let t=()=>{a(e=>{let t=n();return Object.is(e,t)?e:t})};return t(),e(t)},[e,n]),i}const C=e.a(e.n,`useNavigator`),w=e.a(e.i,`useRouter`);function T(e){let n=w(),r=C(),i=(0,s.createRouteNodeSource)(n,e),{route:a,previousRoute:o}=S(i.subscribe,i.getSnapshot,i.getSnapshot);return(0,t.useMemo)(()=>({navigator:r,route:a,previousRoute:o}),[r,a,o])}function E({nodeName:e,children:n}){let{route:r}=T(e),i=(0,t.useMemo)(()=>{let e=[];return h(n,e),e},[n]),a=r?.name,s=(0,t.useMemo)(()=>a===void 0?[]:x(i,a,e).rendered,[i,a,e]);return s.length>0?(0,o.jsx)(o.Fragment,{children:s}):null}E.displayName=`RouteView`;const D=Object.assign(E,{Match:u,Self:d,NotFound:f}),ee=Object.freeze({}),te=Object.freeze({}),O=`data-real-router-announcer`,ne=Object.freeze({destroy:()=>{}});let k=0,A=0;function re(e,t){if(typeof document>`u`)return ne;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=j();k+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ie(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=N(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===A&&(--k,k===0&&M(u)))}}}function j(){let e=document.querySelector(`[${O}]`);if(e)return{element:e,generation:A};k=0,A+=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(O,``),(document.body??document.documentElement).prepend(t),{element:t,generation:A}}function M(e){e.remove()}function N(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 ie(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const P=Object.create,ae=Object.keys,F=Object.freeze({destroy:()=>{}});function I(e,t){if(globalThis.window===void 0)return F;let n=t?.mode??`restore`;if(n===`native`)return F;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(P(null),t)}catch{s=P(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=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 R(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 L=new WeakMap;function R(e){let t=L.get(e);if(t!==void 0)return t;let n=`${e.name}:${z({...e.params,...e.search})}`;return L.set(e,n),n}function z(e){return JSON.stringify(e,B)}function B(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=P(null),n=ae(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const V=Object.freeze({destroy:()=>{}}),H=e=>e.context?.url,U=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},W=(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}}},G=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()}}},K=(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)}}},q=(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 J(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return V;let{selector:n}=t;if(!n)return V;let r=t.rootMargin??`-20% 0px -60% 0px`,i=t.scrollContainer,a=()=>i?.()??null,o=!1,c=!1,l=!1,u=()=>c||o,d=null,f=(0,s.getTransitionSource)(e),p=W(e,()=>{c=!0}),m=G(a),h=K(()=>{d?.()},150),g=q(n,r,a,()=>{h.schedule()},()=>{c||(c=!0,console.warn(`[real-router] scroll-spy: invalid selector "${n}". Disabling.`))},u);d=()=>{if(o||c){g.pending.clear();return}if(f.getSnapshot().isTransitioning||m.active)return;let t=U(g.pending.values());if(g.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===H(r)?.hash)return;let i={hash:n,replace:!0,force:!0,hashChange:!0};l=!0,e.navigate(r.name,r.params,r.search,i).catch(()=>{}).finally(()=>{l=!1})};let _=e.subscribe(({route:e})=>{l||(g.isContainerDetached()&&g.reconcile(),H(e)?.hashChanged&&m.start())});return{destroy(){o=!0,_(),g.destroy(),h.destroy(),m.destroy(),p.destroy()}}}const oe=Object.freeze({destroy:()=>{}});function Y(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return oe;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 se(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 ce(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function le(e){return encodeURI(e).replaceAll(`#`,`%23`)}function ue(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}#${le(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function de(e,t,n,r,i,a){let o={...a};i!==void 0&&(0,c.putField)(o,`hash`,i);let s=e.getState(),l=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,l=a)}}return e.navigate(t,n,l,o)}const fe=/\s/,pe=/\S+/g;function Z(e){return fe.test(e)?e.match(pe)??[]:[e]}function me(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 he(e,n,r,i=!1,a=!0,o){let c=w(),l=(0,t.useMemo)(()=>(0,s.createActiveSource)(c,e,n,r,i,a,o),[c,e,n,r,i,a,o]);return S(l.subscribe,l.getSnapshot,l.getSnapshot)}function ge(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 $=(0,a.memo)(({routeName:e,routeParams:t,routeSearch:n,to:r,routeOptions:i=te,className:a,activeClassName:s=`active`,activeStrict:c=!1,ignoreQueryParams:l=!0,hash:u,onClick:d,target:f,children:p,...m})=>{let h=w(),{name:g,params:_,search:v}=se(r,e??``,t,n),y=he(g,_,v,c,l,u),b=_??ee,x=ue(h,g,b,v,u),S=e=>{if(d){try{d(e)}catch(e){console.error(`[real-router] A <Link> onClick handler threw; navigation is unaffected.`,e)}if(e.defaultPrevented)return}ce(e)&&f!==`_blank`&&(e.preventDefault(),de(h,g,b,v,u,i).catch(()=>{}))},C=me(y,s,a);return(0,o.jsx)(`a`,{...m,href:x,className:C,onClick:S,children:p})},ge);$.displayName=`Link`;function _e({children:e,fallback:n,onError:r}){let a=w(),c=(0,s.createDismissableError)(a),l=S(c.subscribe,c.getSnapshot,c.getSnapshot),u=(0,t.useRef)(r);return(0,t.useLayoutEffect)(()=>{u.current=r}),(0,t.useEffect)(()=>{l.error&&u.current?.(l.error,l.toRoute,l.fromRoute)},[l.version]),(0,o.jsxs)(i.Fragment,{children:[e,l.error?n(l.error,l.resetError):null]})}const ve=()=>{let e=w();return(0,r.getRouteUtils)((0,l.getPluginApi)(e).getTree())};function ye(){let e=w(),t=(0,s.getTransitionSource)(e);return S(t.subscribe,t.getSnapshot,t.getSnapshot)}function be(e,n){let r=w(),i=(0,t.useRef)(e),a=n?.skipSameRoute??!0;(0,t.useLayoutEffect)(()=>{i.current=e}),(0,t.useEffect)(()=>r.subscribeLeave((0,s.guardLeaveListener)(e=>i.current(e),{skipSameRoute:a})),[r,a])}function xe(n,r){let{route:i,previousRoute:a}=e.t(),o=(0,t.useRef)(n),[c]=(0,t.useState)(()=>(0,s.createRouteEnterGate)()),l=r?.skipSameRoute??!0;(0,t.useLayoutEffect)(()=>{o.current=n}),(0,t.useEffect)(()=>{let e=c(i,a,l);e&&o.current(e)},[c,i,a,l])}const Se=({router:r,children:i,announceNavigation:a,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{let d=a!==void 0&&a!==!1,f=typeof a==`object`?a:void 0,p=f?.prefix;(0,t.useEffect)(()=>{if(!d)return;let e=re(r,f);return()=>{e.destroy()}},[r,d,p]);let m=c?.mode,h=c?.anchorScrolling,g=c?.behavior,_=c?.storageKey,v=c!==void 0;(0,t.useEffect)(()=>{if(!v)return;let e=I(r,{mode:m,anchorScrolling:h,behavior:g,storageKey:_,scrollContainer:c.scrollContainer});return()=>{e.destroy()}},[r,v,m,h,g,_]);let y=l?.selector,b=l?.rootMargin,x=l!==void 0&&y!==void 0&&y!==``;(0,t.useEffect)(()=>{if(!x)return;let e=J(r,{selector:y,rootMargin:b,scrollContainer:l.scrollContainer});return()=>{e.destroy()}},[r,x,y,b]),(0,t.useEffect)(()=>{if(!u)return;let e=Y(r);return()=>{e.destroy()}},[r,u]);let C=(0,n.getNavigator)(r),w=(0,t.useMemo)(()=>(0,s.createRouteSource)(r),[r]);(0,t.useEffect)(()=>{(0,s.primeErrorSource)(r)},[r]);let{route:T,previousRoute:E}=S(w.subscribe,w.getSnapshot,w.getSnapshot),D=(0,t.useMemo)(()=>({navigator:C,route:T,previousRoute:E}),[C,T,E]);return(0,o.jsx)(e.i.Provider,{value:r,children:(0,o.jsx)(e.n.Provider,{value:C,children:(0,o.jsx)(e.r.Provider,{value:D,children:i})})})};exports.Link=$,exports.NavigatorContext=e.n,exports.RouteContext=e.r,exports.RouteView=D,exports.RouterContext=e.i,exports.RouterErrorBoundary=_e,exports.RouterProvider=Se,exports.useNavigator=C,exports.useRoute=e.t,exports.useRouteEnter=xe,exports.useRouteExit=be,exports.useRouteNode=T,exports.useRouteUtils=ve,exports.useRouter=w,exports.useRouterTransition=ye;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useRoute-B0pDCgZw.js");let t=require("preact/hooks"),n=require("@real-router/core"),r=require("@real-router/route-utils"),i=require("preact"),a=require("preact/compat"),o=require("preact/jsx-runtime"),s=require("@real-router/sources"),c=require("@real-router/core/utils"),l=require("@real-router/core/api");function u(e){return null}u.displayName=`RouteView.Match`;function d(e){return null}d.displayName=`RouteView.Self`;function f(e){return null}f.displayName=`RouteView.NotFound`;const p=new Set([u,d,f]);function m(e,t,n){return t===``?!1:n?e===t:(0,r.startsWithSegment)(e,t)}function h(e,t){for(let n of(0,i.toChildArray)(e))(0,i.isValidElement)(n)&&(p.has(n.type)?t.push(n):h(n.props.children,t))}function g(e,t,n){return(0,o.jsx)(i.Fragment,{children:n===void 0?e:(0,o.jsx)(a.Suspense,{fallback:n,children:e})},t)}function _(e){return e.type===f||e.type===d}function v(e,t){if(e.type===f){t.notFoundFound||=(t.notFoundChildren=e.props.children,!0);return}t.selfFound||=(t.selfChildren=e.props.children,t.selfFallback=e.props.fallback,!0)}function y(e,t,n,r){let{segment:i,exact:a=!1,fallback:o,children:s}=e.props,c=n?`${n}.${i}`:i;return r||!m(t,c,a)?null:g(s,c,o)}function b(e,t,r,a){if(a.selfFound&&t===r){e.push(g(a.selfChildren,`__route-view-self__`,a.selfFallback));return}t===n.UNKNOWN_ROUTE&&a.notFoundChildren!==null&&e.push((0,o.jsx)(i.Fragment,{children:a.notFoundChildren},`__route-view-not-found__`))}function x(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(_(o)){v(o,r);continue}let e=y(o,t,n,i);e!==null&&(i=!0,a.push(e))}return i||b(a,t,n,r),{rendered:a,activeMatchFound:i}}function S(e,n,r){let[i,a]=(0,t.useState)(n);return(0,t.useEffect)(()=>{let t=()=>{a(e=>{let t=n();return Object.is(e,t)?e:t})};return t(),e(t)},[e,n]),i}const C=e.a(e.n,`useNavigator`),w=e.a(e.i,`useRouter`);function T(e){let n=w(),r=C(),i=(0,s.createRouteNodeSource)(n,e),{route:a,previousRoute:o}=S(i.subscribe,i.getSnapshot,i.getSnapshot);return(0,t.useMemo)(()=>({navigator:r,route:a,previousRoute:o}),[r,a,o])}function E({nodeName:e,children:n}){let{route:r}=T(e),i=(0,t.useMemo)(()=>{let e=[];return h(n,e),e},[n]),a=r?.name,s=(0,t.useMemo)(()=>a===void 0?[]:x(i,a,e).rendered,[i,a,e]);return s.length>0?(0,o.jsx)(o.Fragment,{children:s}):null}E.displayName=`RouteView`;const D=Object.assign(E,{Match:u,Self:d,NotFound:f}),O=Object.freeze({}),ee=Object.freeze({}),k=`data-real-router-announcer`,te=Object.freeze({destroy:()=>{}});let A=0,j=0;function M(e,t){if(typeof document>`u`)return te;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=N();A+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ie(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=re(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===j&&(--A,A===0&&ne(u)))}}}function N(){let e=document.querySelector(`[${k}]`);if(e)return{element:e,generation:j};A=0,j+=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(k,``),(document.body??document.documentElement).prepend(t),{element:t,generation:j}}function ne(e){e.remove()}function re(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 ie(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const P=Object.create,ae=Object.keys,F=Object.freeze({destroy:()=>{}});function I(e,t){if(globalThis.window===void 0)return F;let n=t?.mode??`restore`;if(n===`native`)return F;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(P(null),t)}catch{s=P(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=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 R(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 L=new WeakMap;function R(e){let t=L.get(e);if(t!==void 0)return t;let n=`${e.name}:${z({...e.params,...e.search})}`;return L.set(e,n),n}function z(e){return JSON.stringify(e,B)}function B(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=P(null),n=ae(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const V=Object.freeze({destroy:()=>{}}),H=e=>e.context?.url,U=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},W=(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}}},G=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()}}},K=(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)}}},q=(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 J(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return V;let{selector:n}=t;if(!n)return V;let r=t.rootMargin??`-20% 0px -60% 0px`,i=t.scrollContainer,a=()=>i?.()??null,o=!1,c=!1,l=!1,u=()=>c||o,d=null,f=(0,s.getTransitionSource)(e),p=W(e,()=>{c=!0}),m=G(a),h=K(()=>{d?.()},150),g=q(n,r,a,()=>{h.schedule()},()=>{c||(c=!0,console.warn(`[real-router] scroll-spy: invalid selector "${n}". Disabling.`))},u);d=()=>{if(o||c){g.pending.clear();return}if(f.getSnapshot().isTransitioning||m.active)return;let t=U(g.pending.values());if(g.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===H(r)?.hash)return;let i={hash:n,replace:!0,force:!0,hashChange:!0};l=!0,e.navigate(r.name,r.params,r.search,i).catch(()=>{}).finally(()=>{l=!1})};let _=e.subscribe(({route:e})=>{l||(g.isContainerDetached()&&g.reconcile(),H(e)?.hashChanged&&m.start())});return{destroy(){o=!0,_(),g.destroy(),h.destroy(),m.destroy(),p.destroy()}}}const oe=Object.freeze({destroy:()=>{}});function se(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return oe;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 Y=Object.keys;function ce(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 le(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function ue(e){return!!e&&e!==`_self`}function de(e){return encodeURI(e).replaceAll(`#`,`%23`)}function fe(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}#${de(a)}`:s}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&&(0,c.putField)(o,`hash`,i);let s=e.getState(),l=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,l=a)}}return e.navigate(t,n,l,o)}const me=/\s/,he=/\S+/g;function X(e){return me.test(e)?e.match(he)??[]:[e]}function Z(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 Q(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Y(e),r=Y(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 ge(e,n,r,i=!1,a=!0,o){let c=w(),l=(0,t.useMemo)(()=>(0,s.createActiveSource)(c,e,n,r,i,a,o),[c,e,n,r,i,a,o]);return S(l.subscribe,l.getSnapshot,l.getSnapshot)}function _e(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 $=(0,a.memo)(({routeName:e,routeParams:t,routeSearch:n,to:r,routeOptions:i=ee,className:a,activeClassName:s=`active`,activeStrict:c=!1,ignoreQueryParams:l=!0,hash:u,onClick:d,target:f,children:p,...m})=>{let h=w(),{name:g,params:_,search:v}=ce(r,e??``,t,n),y=ge(g,_,v,c,l,u),b=_??O,x=fe(h,g,b,v,u),S=e=>{if(d){try{d(e)}catch(e){console.error(`[real-router] A <Link> onClick handler threw; navigation is unaffected.`,e)}if(e.defaultPrevented)return}le(e)&&!ue(f)&&(e.preventDefault(),pe(h,g,b,v,u,i).catch(()=>{}))},C=Z(y,s,a);return(0,o.jsx)(`a`,{...m,target:f,href:x,className:C,onClick:S,children:p})},_e);$.displayName=`Link`;function ve({children:e,fallback:n,onError:r}){let a=w(),c=(0,s.createDismissableError)(a),l=S(c.subscribe,c.getSnapshot,c.getSnapshot),u=(0,t.useRef)(r);return(0,t.useLayoutEffect)(()=>{u.current=r}),(0,t.useEffect)(()=>{l.error&&u.current?.(l.error,l.toRoute,l.fromRoute)},[l.version]),(0,o.jsxs)(i.Fragment,{children:[e,l.error?n(l.error,l.resetError):null]})}const ye=()=>{let e=w();return(0,r.getRouteUtils)((0,l.getPluginApi)(e).getTree())};function be(){let e=w(),t=(0,s.getTransitionSource)(e);return S(t.subscribe,t.getSnapshot,t.getSnapshot)}function xe(e,n){let r=w(),i=(0,t.useRef)(e),a=n?.skipSameRoute??!0;(0,t.useLayoutEffect)(()=>{i.current=e}),(0,t.useEffect)(()=>r.subscribeLeave((0,s.guardLeaveListener)(e=>i.current(e),{skipSameRoute:a})),[r,a])}function Se(n,r){let{route:i,previousRoute:a}=e.t(),o=(0,t.useRef)(n),[c]=(0,t.useState)(()=>(0,s.createRouteEnterGate)()),l=r?.skipSameRoute??!0;(0,t.useLayoutEffect)(()=>{o.current=n}),(0,t.useEffect)(()=>{let e=c(i,a,l);e&&o.current(e)},[c,i,a,l])}const Ce=({router:r,children:i,announceNavigation:a,scrollRestoration:c,scrollSpy:l,viewTransitions:u})=>{let d=a!==void 0&&a!==!1,f=typeof a==`object`?a:void 0,p=f?.prefix;(0,t.useEffect)(()=>{if(!d)return;let e=M(r,f);return()=>{e.destroy()}},[r,d,p]);let m=c?.mode,h=c?.anchorScrolling,g=c?.behavior,_=c?.storageKey,v=c!==void 0;(0,t.useEffect)(()=>{if(!v)return;let e=I(r,{mode:m,anchorScrolling:h,behavior:g,storageKey:_,scrollContainer:c.scrollContainer});return()=>{e.destroy()}},[r,v,m,h,g,_]);let y=l?.selector,b=l?.rootMargin,x=l!==void 0&&y!==void 0&&y!==``;(0,t.useEffect)(()=>{if(!x)return;let e=J(r,{selector:y,rootMargin:b,scrollContainer:l.scrollContainer});return()=>{e.destroy()}},[r,x,y,b]),(0,t.useEffect)(()=>{if(!u)return;let e=se(r);return()=>{e.destroy()}},[r,u]);let C=(0,n.getNavigator)(r),w=(0,t.useMemo)(()=>(0,s.createRouteSource)(r),[r]);(0,t.useEffect)(()=>{(0,s.primeErrorSource)(r)},[r]);let{route:T,previousRoute:E}=S(w.subscribe,w.getSnapshot,w.getSnapshot),D=(0,t.useMemo)(()=>({navigator:C,route:T,previousRoute:E}),[C,T,E]);return(0,o.jsx)(e.i.Provider,{value:r,children:(0,o.jsx)(e.n.Provider,{value:C,children:(0,o.jsx)(e.r.Provider,{value:D,children:i})})})};exports.Link=$,exports.NavigatorContext=e.n,exports.RouteContext=e.r,exports.RouteView=D,exports.RouterContext=e.i,exports.RouterErrorBoundary=ve,exports.RouterProvider=Ce,exports.useNavigator=C,exports.useRoute=e.t,exports.useRouteEnter=Se,exports.useRouteExit=xe,exports.useRouteNode=T,exports.useRouteUtils=ye,exports.useRouter=w,exports.useRouterTransition=be;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|