@real-router/vue 0.19.32 → 0.19.33
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 +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,i as t,r as n,t as r}from"./useRoute-BBfRYSpV.mjs";import{Fragment as i,KeepAlive as a,Suspense as o,computed as s,defineComponent as c,h as l,inject as u,isVNode as d,markRaw as f,onActivated as p,onDeactivated as m,onScopeDispose as h,provide as g,shallowRef as _,watch as v}from"vue";import{UNKNOWN_ROUTE as ee,getNavigator as y}from"@real-router/core";import{getRouteUtils as te,startsWithSegment as ne}from"@real-router/route-utils";import{createActiveSource as re,createDismissableError as ie,createRouteEnterGate as ae,createRouteNodeSource as oe,createRouteSource as se,getTransitionSource as b,guardLeaveListener as ce,primeErrorSource as le}from"@real-router/sources";import{getPluginApi as ue}from"@real-router/core/api";function x(){return null}const S=c({name:`RouteView.Match`,props:{segment:{type:String,required:!0},exact:{type:Boolean,default:!1},fallback:{type:[Object,Function],default:void 0},keepAlive:{type:Boolean,default:!1}},render:x}),C=c({name:`RouteView.Self`,props:{fallback:{type:[Object,Function],default:void 0}},render:x}),w=c({name:`RouteView.NotFound`,render:x}),de=new Set([S,C,w]),fe=new Set([!0,``,`keep-alive`]);function pe(e,t,n){return n?e===t:ne(e,t)}function T(e){return fe.has(e)}function E(e){if(Array.isArray(e)){let t=[];for(let n of e)Array.isArray(n)?t.push(...E(n)):d(n)&&t.push(n);return t}return d(e)?[e]:[]}function D(e,t){let n=E(e);for(let e of n)de.has(e.type)?t.push(e):e.type===i&&D(e.children,t)}function me(e,t){return e.type===w?(t.notFoundVNode??=e,!0):e.type===C?(t.selfVNode===null&&(t.selfVNode=e,t.selfFallback=e.props?.fallback),!0):!1}function he(e,t,n){let r=e.props,i=r?.segment??``,a=r?.exact??!1;return{isActive:pe(t,n?`${n}.${i}`:i,a),fallback:r?.fallback}}function ge(e,t,n,r){if(r.selfVNode!==null&&t===n)return e.push(r.selfVNode),r.selfFallback;t===ee&&r.notFoundVNode!==null&&e.push(r.notFoundVNode)}function _e(e,t,n){let r={selfVNode:null,selfFallback:void 0,notFoundVNode:null},i=!1,a,o=!1,s=[];for(let c of e){if(!o&&c.type===S){let e=c.props;T(e?.keepAlive)&&(o=!0)}if(me(c,r)||i)continue;let e=he(c,t,n);e.isActive&&(i=!0,a=e.fallback,s.push(c))}return i||(a=ge(s,t,n,r)),{rendered:s,activeMatchFound:i,fallback:a,hasPerMatchKA:o}}function O(e){let t=_(e.getSnapshot());return h(e.subscribe(()=>{t.value=e.getSnapshot()})),t}const k=()=>{let t=u(e);if(!t)throw Error(`useRouter must be used within a RouterProvider`);return t};function A(e){let t=k(),n=O(oe(t,e));return{navigator:y(t),route:s(()=>n.value.route),previousRoute:s(()=>n.value.previousRoute)}}function j(e){return e.children?.default?.()??null}function M(e,t){let n=e.get(t);if(n)return n;let r=f(c({name:`KeepAlive-${t}`,setup(e,t){return()=>t.slots.default?.()}}));return e.set(t,r),r}function N(e,t){if(t===void 0)return e;let n=typeof t==`function`?t():t;return l(o,{},{default:()=>e,fallback:()=>n})}let P=null;function ve(){return P??=f(c({name:`KeepAlive-placeholder`,render(){return null}})),P}function ye(e,t,n){let r=e.props?.segment??`__not-found__`,i=M(t,r),o=j(e)??[];return N(l(a,null,{default:()=>l(i,{key:r},{default:()=>o})}),n)}function be(e,t,n){let r=e.props;if(T(r?.keepAlive)&&e.type===S){let n=r?.segment??`__not-found__`,o=M(t,n),s=j(e)??[];return l(i,[l(a,null,{default:()=>l(o,{key:n},{default:()=>s})})])}let o=j(e);return o?l(i,[l(a,null,{default:()=>l(ve())}),N(l(i,o),n)]):null}const xe=c({name:`RouteView`,props:{nodeName:{type:String,required:!0},keepAlive:{type:Boolean,default:!1}},setup(e,{slots:t}){let n=A(e.nodeName),r=new Map;return()=>{let a=n.route.value;if(!a)return null;let o=t.default?.(),s=[];D(o,s);let{rendered:c,fallback:u,hasPerMatchKA:d}=_e(s,a.name,e.nodeName);if(c.length===0)return null;let f=c[0];if(e.keepAlive)return ye(f,r,u);if(f.type!==S&&f.type!==C&&f.type!==w)return null;if(d)return be(f,r,u);let p=j(f);return p?N(l(i,p),u):null}}}),Se=Object.assign(xe,{Match:S,Self:C,NotFound:w}),F=Object.freeze({}),Ce=Object.freeze({}),I=`data-real-router-announcer`,we=Object.freeze({destroy:()=>{}});let L=0,R=0;function Te(e,t){if(typeof document>`u`)return we;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=Ee();L+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ke(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=Oe(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===R&&(--L,L===0&&De(u)))}}}function Ee(){let e=document.querySelector(`[${I}]`);if(e)return{element:e,generation:R};L=0,R+=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(I,``),(document.body??document.documentElement).prepend(t),{element:t,generation:R}}function De(e){e.remove()}function Oe(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 ke(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const Ae=Object.keys,z=Object.freeze({destroy:()=>{}});function je(e,t){if(globalThis.window===void 0)return z;let n=t?.mode??`restore`;if(n===`native`)return z;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(Object.create(null),t)}catch{s=Object.create(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 Me(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}},ee=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)}})}),y=()=>{let t=e.getState();if(t){let e=v(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{h=!0,ee(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}const B=new WeakMap;function Me(e){let t=B.get(e);if(t!==void 0)return t;let n=`${e.name}:${Ne({...e.params,...e.search})}`;return B.set(e,n),n}function Ne(e){return JSON.stringify(e,Pe)}function Pe(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=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,Fe=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},Ie=(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}}},Le=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()}}},Re=(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)}}},ze=(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 Be(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,s=!1,c=!1,l=()=>s||o,u=null,d=b(e),f=Ie(e,()=>{s=!0}),p=Le(a),m=Re(()=>{u?.()},150),h=ze(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=Fe(h.pending.values());if(h.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};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(),H(e)?.hashChanged&&p.start())});return{destroy(){o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy()}}}const Ve=Object.freeze({destroy:()=>{}});function He(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;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 U=Object.keys;function W(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 G(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function Ue(e){return encodeURI(e).replaceAll(`#`,`%23`)}function We(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}#${Ue(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function Ge(e,t,n,r,i,a){let o={...a};i!==void 0&&(o.hash=i);let s=e.getState();if(s!==void 0&&e.isActiveRoute(t,n,r??s.search,!0,!1)){let e=s.context?.url?.hash??``;e!==(i??e)&&(o.force=!0,o.hashChange=!0)}return e.navigate(t,n,r,o)}const Ke=/\s/,qe=/\S+/g;function K(e){return Ke.test(e)?e.match(qe)??[]:[e]}function Je(e,t,n){if(e&&t){let e=K(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=K(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 Ye(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=U(e);if(n.length!==U(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 Xe(e){if(!e)return;let t=e.tagName;t!==`A`&&t!==`BUTTON`&&(e.hasAttribute(`role`)||e.setAttribute(`role`,`link`),e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`0`))}function q(e,t){try{e(t)}catch(e){console.error(`[real-router] A <Link> @click handler threw; navigation is unaffected.`,e)}}function Ze(e,t){if(typeof e==`function`){q(e,t);return}if(Array.isArray(e)){let n=e;for(let e of n)if(typeof e==`function`&&(q(e,t),t.defaultPrevented))return}}const Qe=c({name:`Link`,inheritAttrs:!1,props:{routeName:{type:String,default:void 0},to:{type:Object,default:void 0},routeParams:{type:Object,default:void 0},routeSearch:{type:Object,default:void 0},routeOptions:{type:Object,default:()=>Ce},class:{type:String,default:void 0},activeClassName:{type:String,default:`active`},activeStrict:{type:Boolean,default:!1},ignoreQueryParams:{type:Boolean,default:!0},target:{type:String,default:void 0},hash:{type:String,default:void 0}},setup(e,{slots:t,attrs:n}){let r=k(),i=_(!1),a=e.routeParams,o=s(()=>{let t=e.routeParams;return Ye(a,t)||(a=t),a});v(()=>[e.routeName,o.value,e.routeSearch,e.to,e.activeStrict,e.ignoreQueryParams,e.hash],([e,t,n,a,o,s,c],l,u)=>{let d=W(a,e??``,t,n),f=re(r,d.name,d.params,d.search,o,s,c);i.value=f.getSnapshot(),u(f.subscribe(()=>{i.value=f.getSnapshot()}))},{immediate:!0,flush:`sync`});let c=s(()=>{let t=W(e.to,e.routeName??``,o.value,e.routeSearch);return We(r,t.name,t.params??F,t.search,e.hash)}),u=s(()=>Je(i.value,e.activeClassName,e.class)),d=t=>{if(n.onClick!==void 0&&n.onClick!==null&&(Ze(n.onClick,t),t.defaultPrevented)||!G(t)||e.target===`_blank`)return;t.preventDefault();let i=W(e.to,e.routeName??``,e.routeParams,e.routeSearch);Ge(r,i.name,i.params??F,i.search,e.hash,e.routeOptions).catch(()=>{})};return()=>{let r={...n};return delete r.onClick,l(`a`,{...r,href:c.value,class:u.value,target:e.target,onClick:d},t.default?.())}}}),$e=c({name:`RouterErrorBoundary`,props:{fallback:{type:Function,required:!0},onError:{type:Function,default:void 0}},setup(e,{slots:t}){let n=O(ie(k()));return v(()=>n.value.version,()=>{n.value.error&&e.onError?.(n.value.error,n.value.toRoute,n.value.fromRoute)},{immediate:!0}),()=>{let r=t.default?.()??[],a=n.value.error?e.fallback(n.value.error,n.value.resetError):null;return l(i,null,[...r,a])}}}),J=[];function Y(e){return J.push(e),()=>{let t=J.lastIndexOf(e);t!==-1&&J.splice(t,1)}}function et(){let e=J.at(-1);if(!e)throw Error(`v-link directive requires a RouterProvider ancestor. Make sure RouterProvider is mounted.`);return e}const X=new WeakMap;function tt(e){return e==null?(console.error(`[real-router] v-link directive received null/undefined value. The element will not be wired for navigation.`),!1):typeof e.name==`string`?!0:(console.error("[real-router] v-link directive value is missing a string `name` field. The element will not be wired for navigation."),!1)}function nt(e,t){return n=>{G(n)&&(n.preventDefault(),e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{}))}}function rt(e,t,n){return r=>{r.key===`Enter`&&!(n instanceof HTMLButtonElement)&&e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{})}}function Z(e,t,n){let r=nt(t,n),i=rt(t,n,e);e.addEventListener(`click`,r),e.addEventListener(`keydown`,i),X.set(e,{click:r,keydown:i})}function it(e){let t=X.get(e);t&&(e.removeEventListener(`click`,t.click),e.removeEventListener(`keydown`,t.keydown),X.delete(e))}const at={mounted(e,t){let n=et();Xe(e),e.style.cursor=`pointer`,tt(t.value)&&Z(e,n,t.value)},updated(e,t){if(t.value===t.oldValue)return;let n=et();it(e),tt(t.value)&&Z(e,n,t.value)},beforeUnmount(e){it(e)}},ot=()=>{let e=u(n);if(!e)throw Error(`useNavigator must be used within a RouterProvider`);return e},st=()=>te(ue(k()).getTree());function ct(){return O(b(k()))}function lt(e,t){let n=k(),r=t?.skipSameRoute??!0,i=!1;p(()=>{i=!1}),m(()=>{i=!0});let a=ce(e,{skipSameRoute:r});h(n.subscribeLeave(e=>{if(!i)return a(e)}))}function ut(e,t){let{route:n,previousRoute:i}=r(),a=t?.skipSameRoute??!0,o=ae(),s=!1;p(()=>{s=!1}),m(()=>{s=!0}),v(n,t=>{if(s)return;let n=o(t,i.value,a);n&&e(n)})}function Q(e){let t=y(e),n=se(e),r=n.getSnapshot(),i=_(r.route),a=_(r.previousRoute);return{navigator:t,route:i,previousRoute:a,unsubscribe:n.subscribe(()=>{let e=n.getSnapshot();i.value=e.route,a.value=e.previousRoute})}}function dt(r){return{install(i){let a=Y(r),{navigator:o,route:s,previousRoute:c,unsubscribe:l}=Q(r);`onUnmount`in i&&i.onUnmount(()=>{a(),l()}),i.provide(e,r),i.provide(n,o),i.provide(t,{navigator:o,route:s,previousRoute:c})}}}function $(e,t){v(e,(e,n,r)=>{let i=t(e);i&&r(()=>{i.destroy()})},{immediate:!0})}const ft=c({name:`RouterProvider`,props:{router:{type:Object,required:!0},announceNavigation:{type:[Boolean,Object],default:!1},scrollRestoration:{type:Object},scrollSpy:{type:Object},viewTransitions:{type:Boolean,default:!1}},setup(r,{slots:i}){$(()=>{let e=r.announceNavigation,t=e!==!1,n=typeof e==`object`?e.prefix:void 0;return[r.router,t,n]},([e,t])=>{let n=r.announceNavigation;return t?Te(e,typeof n==`object`?n:void 0):void 0}),$(()=>[r.router,r.scrollRestoration!==void 0,r.scrollRestoration?.mode,r.scrollRestoration?.anchorScrolling,r.scrollRestoration?.behavior,r.scrollRestoration?.storageKey],([e,t,n,i,a,o])=>{if(t)return je(e,{mode:n,anchorScrolling:i,behavior:a,storageKey:o,scrollContainer:r.scrollRestoration?.scrollContainer})}),$(()=>[r.router,r.scrollSpy!==void 0&&r.scrollSpy.selector!==``,r.scrollSpy?.selector,r.scrollSpy?.rootMargin],([e,t,n,i])=>{if(!(!t||!n))return Be(e,{selector:n,rootMargin:i,scrollContainer:r.scrollSpy?.scrollContainer})}),$(()=>[r.router,r.viewTransitions],([e,t])=>t?He(e):void 0);let a=typeof document>`u`?void 0:Y(r.router);a&&h(a),le(r.router);let{navigator:o,route:s,previousRoute:c,unsubscribe:l}=Q(r.router);return h(l),g(e,r.router),g(n,o),g(t,{navigator:o,route:s,previousRoute:c}),()=>i.default?.()}});export{Qe as Link,n as NavigatorKey,t as RouteKey,Se as RouteView,$e as RouterErrorBoundary,e as RouterKey,ft as RouterProvider,dt as createRouterPlugin,ot as useNavigator,r as useRoute,ut as useRouteEnter,lt as useRouteExit,A as useRouteNode,st as useRouteUtils,k as useRouter,ct as useRouterTransition,at as vLink};
|
|
1
|
+
import{a as e,i as t,r as n,t as r}from"./useRoute-BBfRYSpV.mjs";import{Fragment as i,KeepAlive as a,Suspense as o,computed as s,defineComponent as c,h as l,inject as u,isVNode as d,markRaw as f,onActivated as p,onDeactivated as m,onScopeDispose as h,provide as g,shallowRef as _,watch as v}from"vue";import{UNKNOWN_ROUTE as ee,getNavigator as y}from"@real-router/core";import{getRouteUtils as te,startsWithSegment as ne}from"@real-router/route-utils";import{createActiveSource as re,createDismissableError as ie,createRouteEnterGate as ae,createRouteNodeSource as oe,createRouteSource as se,getTransitionSource as b,guardLeaveListener as ce,primeErrorSource as le}from"@real-router/sources";import{getPluginApi as ue}from"@real-router/core/api";function x(){return null}const S=c({name:`RouteView.Match`,props:{segment:{type:String,required:!0},exact:{type:Boolean,default:!1},fallback:{type:[Object,Function],default:void 0},keepAlive:{type:Boolean,default:!1}},render:x}),C=c({name:`RouteView.Self`,props:{fallback:{type:[Object,Function],default:void 0}},render:x}),w=c({name:`RouteView.NotFound`,render:x}),de=new Set([S,C,w]),fe=new Set([!0,``,`keep-alive`]);function pe(e,t,n){return n?e===t:ne(e,t)}function T(e){return fe.has(e)}function E(e){if(Array.isArray(e)){let t=[];for(let n of e)Array.isArray(n)?t.push(...E(n)):d(n)&&t.push(n);return t}return d(e)?[e]:[]}function D(e,t){let n=E(e);for(let e of n)de.has(e.type)?t.push(e):e.type===i&&D(e.children,t)}function me(e,t){return e.type===w?(t.notFoundVNode??=e,!0):e.type===C?(t.selfVNode===null&&(t.selfVNode=e,t.selfFallback=e.props?.fallback),!0):!1}function he(e,t,n){let r=e.props,i=r?.segment??``,a=r?.exact??!1;return{isActive:pe(t,n?`${n}.${i}`:i,a),fallback:r?.fallback}}function ge(e,t,n,r){if(r.selfVNode!==null&&t===n)return e.push(r.selfVNode),r.selfFallback;t===ee&&r.notFoundVNode!==null&&e.push(r.notFoundVNode)}function _e(e,t,n){let r={selfVNode:null,selfFallback:void 0,notFoundVNode:null},i=!1,a,o=!1,s=[];for(let c of e){if(!o&&c.type===S){let e=c.props;T(e?.keepAlive)&&(o=!0)}if(me(c,r)||i)continue;let e=he(c,t,n);e.isActive&&(i=!0,a=e.fallback,s.push(c))}return i||(a=ge(s,t,n,r)),{rendered:s,activeMatchFound:i,fallback:a,hasPerMatchKA:o}}function O(e){let t=_(e.getSnapshot());return h(e.subscribe(()=>{t.value=e.getSnapshot()})),t}const k=()=>{let t=u(e);if(!t)throw Error(`useRouter must be used within a RouterProvider`);return t};function A(e){let t=k(),n=O(oe(t,e));return{navigator:y(t),route:s(()=>n.value.route),previousRoute:s(()=>n.value.previousRoute)}}function j(e){return e.children?.default?.()??null}function M(e,t){let n=e.get(t);if(n)return n;let r=f(c({name:`KeepAlive-${t}`,setup(e,t){return()=>t.slots.default?.()}}));return e.set(t,r),r}function N(e,t){if(t===void 0)return e;let n=typeof t==`function`?t():t;return l(o,{},{default:()=>e,fallback:()=>n})}let P=null;function ve(){return P??=f(c({name:`KeepAlive-placeholder`,render(){return null}})),P}function ye(e,t,n){let r=e.props?.segment??`__not-found__`,i=M(t,r),o=j(e)??[];return N(l(a,null,{default:()=>l(i,{key:r},{default:()=>o})}),n)}function be(e,t,n){let r=e.props;if(T(r?.keepAlive)&&e.type===S){let n=r?.segment??`__not-found__`,o=M(t,n),s=j(e)??[];return l(i,[l(a,null,{default:()=>l(o,{key:n},{default:()=>s})})])}let o=j(e);return o?l(i,[l(a,null,{default:()=>l(ve())}),N(l(i,o),n)]):null}const xe=c({name:`RouteView`,props:{nodeName:{type:String,required:!0},keepAlive:{type:Boolean,default:!1}},setup(e,{slots:t}){let n=A(e.nodeName),r=new Map;return()=>{let a=n.route.value;if(!a)return null;let o=t.default?.(),s=[];D(o,s);let{rendered:c,fallback:u,hasPerMatchKA:d}=_e(s,a.name,e.nodeName);if(c.length===0)return null;let f=c[0];if(e.keepAlive)return ye(f,r,u);if(f.type!==S&&f.type!==C&&f.type!==w)return null;if(d)return be(f,r,u);let p=j(f);return p?N(l(i,p),u):null}}}),Se=Object.assign(xe,{Match:S,Self:C,NotFound:w}),F=Object.freeze({}),Ce=Object.freeze({}),I=`data-real-router-announcer`,we=Object.freeze({destroy:()=>{}});let L=0,R=0;function Te(e,t){if(typeof document>`u`)return we;let n=t?.prefix??`Navigated to `,r=t?.getAnnouncementText,i=!0,a=!1,o=!1,s=``,c=null,l,{element:u,generation:d}=Ee();L+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ke(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=Oe(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===R&&(--L,L===0&&De(u)))}}}function Ee(){let e=document.querySelector(`[${I}]`);if(e)return{element:e,generation:R};L=0,R+=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(I,``),(document.body??document.documentElement).prepend(t),{element:t,generation:R}}function De(e){e.remove()}function Oe(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 ke(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const Ae=Object.keys,z=Object.freeze({destroy:()=>{}});function je(e,t){if(globalThis.window===void 0)return z;let n=t?.mode??`restore`;if(n===`native`)return z;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(Object.create(null),t)}catch{s=Object.create(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 Me(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}},ee=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)}})}),y=()=>{let t=e.getState();if(t){let e=v(t);e!==null&&l(e,d())}};return globalThis.addEventListener(`pagehide`,y),{destroy:()=>{h=!0,ee(),globalThis.removeEventListener(`pagehide`,y);try{history.scrollRestoration=u}catch{}}}}const B=new WeakMap;function Me(e){let t=B.get(e);if(t!==void 0)return t;let n=`${e.name}:${Ne({...e.params,...e.search})}`;return B.set(e,n),n}function Ne(e){return JSON.stringify(e,Pe)}function Pe(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=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,Fe=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},Ie=(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}}},Le=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()}}},Re=(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)}}},ze=(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 Be(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,s=!1,c=!1,l=()=>s||o,u=null,d=b(e),f=Ie(e,()=>{s=!0}),p=Le(a),m=Re(()=>{u?.()},150),h=ze(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=Fe(h.pending.values());if(h.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};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(),H(e)?.hashChanged&&p.start())});return{destroy(){o=!0,g(),h.destroy(),m.destroy(),p.destroy(),f.destroy()}}}const Ve=Object.freeze({destroy:()=>{}});function He(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;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 U=Object.keys;function W(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 G(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function Ue(e){return encodeURI(e).replaceAll(`#`,`%23`)}function We(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}#${Ue(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function Ge(e,t,n,r,i,a){let o={...a};i!==void 0&&(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 Ke=/\s/,qe=/\S+/g;function K(e){return Ke.test(e)?e.match(qe)??[]:[e]}function Je(e,t,n){if(e&&t){let e=K(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=K(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 Ye(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=U(e);if(n.length!==U(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 Xe(e){if(!e)return;let t=e.tagName;t!==`A`&&t!==`BUTTON`&&(e.hasAttribute(`role`)||e.setAttribute(`role`,`link`),e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`0`))}function q(e,t){try{e(t)}catch(e){console.error(`[real-router] A <Link> @click handler threw; navigation is unaffected.`,e)}}function Ze(e,t){if(typeof e==`function`){q(e,t);return}if(Array.isArray(e)){let n=e;for(let e of n)if(typeof e==`function`&&(q(e,t),t.defaultPrevented))return}}const Qe=c({name:`Link`,inheritAttrs:!1,props:{routeName:{type:String,default:void 0},to:{type:Object,default:void 0},routeParams:{type:Object,default:void 0},routeSearch:{type:Object,default:void 0},routeOptions:{type:Object,default:()=>Ce},class:{type:String,default:void 0},activeClassName:{type:String,default:`active`},activeStrict:{type:Boolean,default:!1},ignoreQueryParams:{type:Boolean,default:!0},target:{type:String,default:void 0},hash:{type:String,default:void 0}},setup(e,{slots:t,attrs:n}){let r=k(),i=_(!1),a=e.routeParams,o=s(()=>{let t=e.routeParams;return Ye(a,t)||(a=t),a});v(()=>[e.routeName,o.value,e.routeSearch,e.to,e.activeStrict,e.ignoreQueryParams,e.hash],([e,t,n,a,o,s,c],l,u)=>{let d=W(a,e??``,t,n),f=re(r,d.name,d.params,d.search,o,s,c);i.value=f.getSnapshot(),u(f.subscribe(()=>{i.value=f.getSnapshot()}))},{immediate:!0,flush:`sync`});let c=s(()=>{let t=W(e.to,e.routeName??``,o.value,e.routeSearch);return We(r,t.name,t.params??F,t.search,e.hash)}),u=s(()=>Je(i.value,e.activeClassName,e.class)),d=t=>{if(n.onClick!==void 0&&n.onClick!==null&&(Ze(n.onClick,t),t.defaultPrevented)||!G(t)||e.target===`_blank`)return;t.preventDefault();let i=W(e.to,e.routeName??``,e.routeParams,e.routeSearch);Ge(r,i.name,i.params??F,i.search,e.hash,e.routeOptions).catch(()=>{})};return()=>{let r={...n};return delete r.onClick,l(`a`,{...r,href:c.value,class:u.value,target:e.target,onClick:d},t.default?.())}}}),$e=c({name:`RouterErrorBoundary`,props:{fallback:{type:Function,required:!0},onError:{type:Function,default:void 0}},setup(e,{slots:t}){let n=O(ie(k()));return v(()=>n.value.version,()=>{n.value.error&&e.onError?.(n.value.error,n.value.toRoute,n.value.fromRoute)},{immediate:!0}),()=>{let r=t.default?.()??[],a=n.value.error?e.fallback(n.value.error,n.value.resetError):null;return l(i,null,[...r,a])}}}),J=[];function Y(e){return J.push(e),()=>{let t=J.lastIndexOf(e);t!==-1&&J.splice(t,1)}}function et(){let e=J.at(-1);if(!e)throw Error(`v-link directive requires a RouterProvider ancestor. Make sure RouterProvider is mounted.`);return e}const X=new WeakMap;function tt(e){return e==null?(console.error(`[real-router] v-link directive received null/undefined value. The element will not be wired for navigation.`),!1):typeof e.name==`string`?!0:(console.error("[real-router] v-link directive value is missing a string `name` field. The element will not be wired for navigation."),!1)}function nt(e,t){return n=>{G(n)&&(n.preventDefault(),e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{}))}}function rt(e,t,n){return r=>{r.key===`Enter`&&!(n instanceof HTMLButtonElement)&&e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{})}}function Z(e,t,n){let r=nt(t,n),i=rt(t,n,e);e.addEventListener(`click`,r),e.addEventListener(`keydown`,i),X.set(e,{click:r,keydown:i})}function it(e){let t=X.get(e);t&&(e.removeEventListener(`click`,t.click),e.removeEventListener(`keydown`,t.keydown),X.delete(e))}const at={mounted(e,t){let n=et();Xe(e),e.style.cursor=`pointer`,tt(t.value)&&Z(e,n,t.value)},updated(e,t){if(t.value===t.oldValue)return;let n=et();it(e),tt(t.value)&&Z(e,n,t.value)},beforeUnmount(e){it(e)}},ot=()=>{let e=u(n);if(!e)throw Error(`useNavigator must be used within a RouterProvider`);return e},st=()=>te(ue(k()).getTree());function ct(){return O(b(k()))}function lt(e,t){let n=k(),r=t?.skipSameRoute??!0,i=!1;p(()=>{i=!1}),m(()=>{i=!0});let a=ce(e,{skipSameRoute:r});h(n.subscribeLeave(e=>{if(!i)return a(e)}))}function ut(e,t){let{route:n,previousRoute:i}=r(),a=t?.skipSameRoute??!0,o=ae(),s=!1;p(()=>{s=!1}),m(()=>{s=!0}),v(n,t=>{if(s)return;let n=o(t,i.value,a);n&&e(n)})}function Q(e){let t=y(e),n=se(e),r=n.getSnapshot(),i=_(r.route),a=_(r.previousRoute);return{navigator:t,route:i,previousRoute:a,unsubscribe:n.subscribe(()=>{let e=n.getSnapshot();i.value=e.route,a.value=e.previousRoute})}}function dt(r){return{install(i){let a=Y(r),{navigator:o,route:s,previousRoute:c,unsubscribe:l}=Q(r);`onUnmount`in i&&i.onUnmount(()=>{a(),l()}),i.provide(e,r),i.provide(n,o),i.provide(t,{navigator:o,route:s,previousRoute:c})}}}function $(e,t){v(e,(e,n,r)=>{let i=t(e);i&&r(()=>{i.destroy()})},{immediate:!0})}const ft=c({name:`RouterProvider`,props:{router:{type:Object,required:!0},announceNavigation:{type:[Boolean,Object],default:!1},scrollRestoration:{type:Object},scrollSpy:{type:Object},viewTransitions:{type:Boolean,default:!1}},setup(r,{slots:i}){$(()=>{let e=r.announceNavigation,t=e!==!1,n=typeof e==`object`?e.prefix:void 0;return[r.router,t,n]},([e,t])=>{let n=r.announceNavigation;return t?Te(e,typeof n==`object`?n:void 0):void 0}),$(()=>[r.router,r.scrollRestoration!==void 0,r.scrollRestoration?.mode,r.scrollRestoration?.anchorScrolling,r.scrollRestoration?.behavior,r.scrollRestoration?.storageKey],([e,t,n,i,a,o])=>{if(t)return je(e,{mode:n,anchorScrolling:i,behavior:a,storageKey:o,scrollContainer:r.scrollRestoration?.scrollContainer})}),$(()=>[r.router,r.scrollSpy!==void 0&&r.scrollSpy.selector!==``,r.scrollSpy?.selector,r.scrollSpy?.rootMargin],([e,t,n,i])=>{if(!(!t||!n))return Be(e,{selector:n,rootMargin:i,scrollContainer:r.scrollSpy?.scrollContainer})}),$(()=>[r.router,r.viewTransitions],([e,t])=>t?He(e):void 0);let a=typeof document>`u`?void 0:Y(r.router);a&&h(a),le(r.router);let{navigator:o,route:s,previousRoute:c,unsubscribe:l}=Q(r.router);return h(l),g(e,r.router),g(n,o),g(t,{navigator:o,route:s,previousRoute:c}),()=>i.default?.()}});export{Qe as Link,n as NavigatorKey,t as RouteKey,Se as RouteView,$e as RouterErrorBoundary,e as RouterKey,ft as RouterProvider,dt as createRouterPlugin,ot as useNavigator,r as useRoute,ut as useRouteEnter,lt as useRouteExit,A as useRouteNode,st as useRouteUtils,k as useRouter,ct as useRouterTransition,at as vLink};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|