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