@real-router/vue 0.19.0 → 0.19.2
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/README.md +3 -3
- 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/README.md
CHANGED
|
@@ -242,9 +242,9 @@ In a template:
|
|
|
242
242
|
```
|
|
243
243
|
|
|
244
244
|
`routeSearch` is the query (search) channel of the path/query split — parallel
|
|
245
|
-
to `routeParams`, the path channel.
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
to `routeParams`, the path channel. It is the only channel a route's declared
|
|
246
|
+
`?query` may travel in — passing it inside `routeParams` is refused by core's
|
|
247
|
+
channel guard (#1572), since the slot IS the channel. `<Link>` also accepts a single `to={{ name, params?, search?
|
|
248
248
|
}}` descriptor as an alternative to the `routeName`/`routeParams`/`routeSearch`
|
|
249
249
|
channel props — see [CLAUDE.md](./CLAUDE.md) → "`routeSearch` Prop" / "`to`
|
|
250
250
|
Descriptor Prop" for the full breakdown.
|
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/api");function o(){return null}const s=(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:o}),c=(0,t.defineComponent)({name:`RouteView.Self`,props:{fallback:{type:[Object,Function],default:void 0}},render:o}),l=(0,t.defineComponent)({name:`RouteView.NotFound`,render:o}),u=new Set([s,c,l]),d=new Set([!0,``,`keep-alive`]);function f(e,t,n){return n?e===t:(0,r.startsWithSegment)(e,t)}function p(e){return d.has(e)}function m(e){if(Array.isArray(e)){let n=[];for(let r of e)Array.isArray(r)?n.push(...m(r)):(0,t.isVNode)(r)&&n.push(r);return n}return(0,t.isVNode)(e)?[e]:[]}function h(e,n){let r=m(e);for(let e of r)u.has(e.type)?n.push(e):e.type===t.Fragment&&h(e.children,n)}function g(e,t){return e.type===l?(t.notFoundVNode??=e,!0):e.type===c?(t.selfVNode===null&&(t.selfVNode=e,t.selfFallback=e.props?.fallback),!0):!1}function _(e,t,n){let r=e.props,i=r?.segment??``,a=r?.exact??!1;return{isActive:f(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,c=[];for(let l of e){if(!o&&l.type===s){let e=l.props;p(e?.keepAlive)&&(o=!0)}if(g(l,r)||i)continue;let e=_(l,t,n);e.isActive&&(i=!0,a=e.fallback,c.push(l))}return i||(a=v(c,t,n,r)),{rendered:c,activeMatchFound:i,fallback:a,hasPerMatchKA:o}}function b(e){let n=(0,t.shallowRef)(e.getSnapshot());return(0,t.onScopeDispose)(e.subscribe(()=>{n.value=e.getSnapshot()})),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(p(i?.keepAlive)&&e.type===s){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?.(),u=[];h(o,u);let{rendered:d,fallback:f,hasPerMatchKA:p}=y(u,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!==s&&m.type!==c&&m.type!==l)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:s,Self:c,NotFound:l}),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.freeze({destroy:()=>{}});function fe(e,t){if(globalThis.window===void 0)return j;let n=t?.mode??`restore`;if(n===`native`)return j;let r=t?.anchorScrolling??!0,i=t?.scrollContainer,a=t?.behavior??`auto`,o=t?.storageKey??`real-router:scroll`,s,c=()=>{if(s!==void 0)return s;try{let e=sessionStorage.getItem(o);s=e?JSON.parse(e):{}}catch{s={}}return s},l=(e,t)=>{try{let n=c();if(n[e]===t)return;n[e]=t,sessionStorage.setItem(o,JSON.stringify(n))}catch{}},u=history.scrollRestoration;try{history.scrollRestoration=`manual`}catch{}let d=()=>{let e=i?.();return e?e.scrollTop:globalThis.scrollY},f=e=>{let t=i?.();t?t.scrollTo({top:e,left:0,behavior:a}):globalThis.scrollTo({top:e,left:0,behavior:a})},p=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=()=>{if(h)return;let r=i();if(r){if(r.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(r.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(n))};n()},m=e=>{let t=e.context?.url?.hash;if(t!==void 0){if(r&&t.length>0){let e=document.getElementById(t);if(e){e.scrollIntoView({behavior:a});return}}f(0);return}let n=globalThis.location.hash;if(r&&n.length>1){let e;try{e=decodeURIComponent(n.slice(1))}catch{e=n.slice(1)}let t=document.getElementById(e);if(t){t.scrollIntoView({behavior:a});return}}f(0)},h=!1,g=!1,_=!0,v=e=>{try{return pe(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 M=new WeakMap;function pe(e){let t=M.get(e);if(t!==void 0)return t;let n=`${e.name}:${me({...e.params,...e.search})}`;return M.set(e,n),n}function me(e){return JSON.stringify(e,he)}function he(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.create(null),n=Object.keys(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const N=Object.freeze({destroy:()=>{}}),P=e=>e.context?.url,F=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}}},L=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()}}},R=(e,t)=>{let n=null,r=null;return{schedule(){n===null&&(n=requestAnimationFrame(()=>{n=null,r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,e()},t)}))},destroy(){n!==null&&(cancelAnimationFrame(n),n=null),r!==null&&(clearTimeout(r),r=null)}}},ge=(e,t,n,r,i,a)=>{let o=new Set,s=new Map,c=!1,l=null,u=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 _e(e,t){if(typeof document>`u`||typeof IntersectionObserver>`u`)return N;let{selector:n}=t;if(!n)return N;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=L(o),h=R(()=>{d?.()},150),g=ge(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=F(g.pending.values());if(g.pending.clear(),!t)return;let n=t.target.id;if(!n)return;let r=e.getState();if(!r||n===P(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(),P(e)?.hashChanged&&m.start())});return{destroy(){s=!0,_(),g.destroy(),h.destroy(),m.destroy(),p.destroy()}}}const ve=Object.freeze({destroy:()=>{}});function ye(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return ve;let t=null,n=null,r=!1,i=()=>{t?.(),t=null},a=e.subscribeLeave(({signal:e})=>{if(!e.aborted)return r=!1,i(),new Promise(a=>{let o=new Promise(e=>{t=e});e.addEventListener(`abort`,()=>{r||(i(),n?.skipTransition?.(),a())},{once:!0});try{n=document.startViewTransition(()=>(a(),o))}catch{i(),a()}})}),o=e.subscribe(()=>{let e=t;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()}}}function z(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 B(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function be(e){return encodeURI(e).replaceAll(`#`,`%23`)}function xe(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}#${be(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function Se(e,t,n,r,i,a){let o={...a};i!==void 0&&(o.hash=i);let s=e.getState();if(s?.name===t&&H(s.params,n)&&H(s.search,r??s.search)){let e=s.context?.url?.hash??``;e!==(i??e)&&(o.force=!0,o.hashChange=!0)}return e.navigate(t,n,r,o)}const Ce=/\s/,we=/\S+/g;function V(e){return Ce.test(e)?e.match(we)??[]:[e]}function Te(e,t,n){if(e&&t){let e=V(t);if(e.length===0)return n??void 0;if(!n)return e.join(` `);let r=V(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 H(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(!Object.prototype.hasOwnProperty.call(t,e)||!Object.is(r[e],i[e]))return!1;return!0}function Ee(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 De(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 Oe=(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 H(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=z(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=z(e.to,e.routeName??``,c.value,e.routeSearch);return xe(a,t.name,t.params??D,t.search,e.hash)}),u=(0,t.computed)(()=>Te(o.value,e.activeClassName,e.class)),d=t=>{if(r.onClick!==void 0&&r.onClick!==null&&(De(r.onClick,t),t.defaultPrevented)||!B(t)||e.target===`_blank`)return;t.preventDefault();let n=z(e.to,e.routeName??``,e.routeParams,e.routeSearch);Se(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?.())}}}),ke=(0,t.defineComponent)({name:`RouterErrorBoundary`,props:{fallback:{type:Function,required:!0},onError:{type:Function,default:void 0}},setup(e,{slots:n}){let r=b((0,i.createDismissableError)(x()));return(0,t.watch)(()=>r.value.version,()=>{r.value.error&&e.onError?.(r.value.error,r.value.toRoute,r.value.fromRoute)},{immediate:!0}),()=>{let i=n.default?.()??[],a=r.value.error?e.fallback(r.value.error,r.value.resetError):null;return(0,t.h)(t.Fragment,null,[...i,a])}}}),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`?!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 Ae(e,t){return n=>{B(n)&&(n.preventDefault(),e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{}))}}function Y(e,t,n){return r=>{r.key===`Enter`&&!(n instanceof HTMLButtonElement)&&e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{})}}function X(e,t,n){let r=Ae(t,n),i=Y(t,n,e);e.addEventListener(`click`,r),e.addEventListener(`keydown`,i),q.set(e,{click:r,keydown:i})}function Z(e){let t=q.get(e);t&&(e.removeEventListener(`click`,t.click),e.removeEventListener(`keydown`,t.keydown),q.delete(e))}const je={mounted(e,t){let n=K();Ee(e),e.style.cursor=`pointer`,J(t.value)&&X(e,n,t.value)},updated(e,t){if(t.value===t.oldValue)return;let n=K();Z(e),J(t.value)&&X(e,n,t.value)},beforeUnmount(e){Z(e)}},Me=()=>{let n=(0,t.inject)(e.r);if(!n)throw Error(`useNavigator must be used within a RouterProvider`);return n},Ne=()=>(0,r.getRouteUtils)((0,a.getPluginApi)(x()).getTree());function Pe(){return b((0,i.getTransitionSource)(x()))}function Fe(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});(0,t.onScopeDispose)(r.subscribeLeave(e=>{if(!o)return s(e)}))}function Ie(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 Le(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 Re=(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 fe(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 _e(e,{selector:r,rootMargin:i,scrollContainer:n.scrollSpy?.scrollContainer})}),$(()=>[n.router,n.viewTransitions],([e,t])=>t?ye(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=Oe,exports.NavigatorKey=e.r,exports.RouteKey=e.i,exports.RouteView=ie,exports.RouterErrorBoundary=ke,exports.RouterKey=e.a,exports.RouterProvider=Re,exports.createRouterPlugin=Le,exports.useNavigator=Me,exports.useRoute=e.t,exports.useRouteEnter=Ie,exports.useRouteExit=Fe,exports.useRouteNode=S,exports.useRouteUtils=Ne,exports.useRouter=x,exports.useRouterTransition=Pe,exports.vLink=je;
|
|
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/api");function o(){return null}const s=(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:o}),c=(0,t.defineComponent)({name:`RouteView.Self`,props:{fallback:{type:[Object,Function],default:void 0}},render:o}),l=(0,t.defineComponent)({name:`RouteView.NotFound`,render:o}),u=new Set([s,c,l]),d=new Set([!0,``,`keep-alive`]);function f(e,t,n){return n?e===t:(0,r.startsWithSegment)(e,t)}function p(e){return d.has(e)}function m(e){if(Array.isArray(e)){let n=[];for(let r of e)Array.isArray(r)?n.push(...m(r)):(0,t.isVNode)(r)&&n.push(r);return n}return(0,t.isVNode)(e)?[e]:[]}function h(e,n){let r=m(e);for(let e of r)u.has(e.type)?n.push(e):e.type===t.Fragment&&h(e.children,n)}function g(e,t){return e.type===l?(t.notFoundVNode??=e,!0):e.type===c?(t.selfVNode===null&&(t.selfVNode=e,t.selfFallback=e.props?.fallback),!0):!1}function _(e,t,n){let r=e.props,i=r?.segment??``,a=r?.exact??!1;return{isActive:f(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,c=[];for(let l of e){if(!o&&l.type===s){let e=l.props;p(e?.keepAlive)&&(o=!0)}if(g(l,r)||i)continue;let e=_(l,t,n);e.isActive&&(i=!0,a=e.fallback,c.push(l))}return i||(a=v(c,t,n,r)),{rendered:c,activeMatchFound:i,fallback:a,hasPerMatchKA:o}}function b(e){let n=(0,t.shallowRef)(e.getSnapshot());return(0,t.onScopeDispose)(e.subscribe(()=>{n.value=e.getSnapshot()})),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(p(i?.keepAlive)&&e.type===s){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?.(),u=[];h(o,u);let{rendered:d,fallback:f,hasPerMatchKA:p}=y(u,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!==s&&m.type!==c&&m.type!==l)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:s,Self:c,NotFound:l}),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}=j();k+=1;let f=(e,t)=>{s=e,clearTimeout(l),u.textContent=e,l=setTimeout(()=>{u.textContent=``,s=``},7e3),ue(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=le(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&&ce(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 ce(e){e.remove()}function le(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 ue(e){e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:!0}))}const M=Object.freeze({destroy:()=>{}});function de(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);s=e?JSON.parse(e):{}}catch{s={}}return s},l=(e,t)=>{try{let n=c();if(n[e]===t)return;n[e]=t,sessionStorage.setItem(o,JSON.stringify(n))}catch{}},u=history.scrollRestoration;try{history.scrollRestoration=`manual`}catch{}let d=()=>{let e=i?.();return e?e.scrollTop:globalThis.scrollY},f=e=>{let t=i?.();t?t.scrollTo({top:e,left:0,behavior:a}):globalThis.scrollTo({top:e,left:0,behavior:a})},p=e=>{if(!i){globalThis.scrollTo({top:e,left:0,behavior:a});return}let t=0,n=()=>{if(h)return;let r=i();if(r){if(r.scrollTo({top:e,left:0,behavior:a}),a!==`smooth`&&Math.abs(r.scrollTop-e)<=1)return}else globalThis.scrollTo({top:e,left:0,behavior:a});t>=10||(t+=1,requestAnimationFrame(n))};n()},m=e=>{let t=e.context?.url?.hash;if(t!==void 0){if(r&&t.length>0){let e=document.getElementById(t);if(e){e.scrollIntoView({behavior:a});return}}f(0);return}let n=globalThis.location.hash;if(r&&n.length>1){let e;try{e=decodeURIComponent(n.slice(1))}catch{e=n.slice(1)}let t=document.getElementById(e);if(t){t.scrollIntoView({behavior:a});return}}f(0)},h=!1,g=!1,_=!0,v=e=>{try{return fe(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 fe(e){let t=N.get(e);if(t!==void 0)return t;let n=`${e.name}:${pe({...e.params,...e.search})}`;return N.set(e,n),n}function pe(e){return JSON.stringify(e,me)}function me(e,t){if(typeof t==`function`)return`<fn>`;if(typeof t==`symbol`)return`<sym>`;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.create(null),n=Object.keys(t).sort((e,t)=>e.localeCompare(t));for(let r of n)e[r]=t[r];return e}return t}const P=Object.freeze({destroy:()=>{}}),F=e=>e.context?.url,I=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},L=(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}}},R=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()}}},z=(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)}}},he=(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 ge(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=L(e,()=>{c=!0}),m=R(o),h=z(()=>{d?.()},150),g=he(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=I(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 _e=Object.freeze({destroy:()=>{}});function B(e){if(typeof document>`u`||typeof document.startViewTransition!=`function`)return _e;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()}}}function V(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 H(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function ve(e){return encodeURI(e).replaceAll(`#`,`%23`)}function ye(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}#${ve(a)}`:s}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function be(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 xe=/\s/,Se=/\S+/g;function U(e){return xe.test(e)?e.match(Se)??[]:[e]}function Ce(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 we(e,t){if(Object.is(e,t))return!0;if(!e||!t)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(!Object.prototype.hasOwnProperty.call(t,e)||!Object.is(r[e],i[e]))return!1;return!0}function Te(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 Ee(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 De=(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 we(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=V(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=V(e.to,e.routeName??``,c.value,e.routeSearch);return ye(a,t.name,t.params??D,t.search,e.hash)}),u=(0,t.computed)(()=>Ce(o.value,e.activeClassName,e.class)),d=t=>{if(r.onClick!==void 0&&r.onClick!==null&&(Ee(r.onClick,t),t.defaultPrevented)||!H(t)||e.target===`_blank`)return;t.preventDefault();let n=V(e.to,e.routeName??``,e.routeParams,e.routeSearch);be(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?.())}}}),Oe=(0,t.defineComponent)({name:`RouterErrorBoundary`,props:{fallback:{type:Function,required:!0},onError:{type:Function,default:void 0}},setup(e,{slots:n}){let r=b((0,i.createDismissableError)(x()));return(0,t.watch)(()=>r.value.version,()=>{r.value.error&&e.onError?.(r.value.error,r.value.toRoute,r.value.fromRoute)},{immediate:!0}),()=>{let i=n.default?.()??[],a=r.value.error?e.fallback(r.value.error,r.value.resetError):null;return(0,t.h)(t.Fragment,null,[...i,a])}}}),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`?!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 ke(e,t){return n=>{H(n)&&(n.preventDefault(),e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{}))}}function Ae(e,t,n){return r=>{r.key===`Enter`&&!(n instanceof HTMLButtonElement)&&e.navigate(t.name,t.params??{},void 0,t.options??{}).catch(()=>{})}}function X(e,t,n){let r=ke(t,n),i=Ae(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 je={mounted(e,t){let n=q();Te(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)}},Me=()=>{let n=(0,t.inject)(e.r);if(!n)throw Error(`useNavigator must be used within a RouterProvider`);return n},Ne=()=>(0,r.getRouteUtils)((0,a.getPluginApi)(x()).getTree());function Pe(){return b((0,i.getTransitionSource)(x()))}function Fe(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});(0,t.onScopeDispose)(r.subscribeLeave(e=>{if(!o)return s(e)}))}function Ie(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 Le(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 Re=(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 de(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 ge(e,{selector:r,rootMargin:i,scrollContainer:n.scrollSpy?.scrollContainer})}),$(()=>[n.router,n.viewTransitions],([e,t])=>t?B(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=De,exports.NavigatorKey=e.r,exports.RouteKey=e.i,exports.RouteView=ie,exports.RouterErrorBoundary=Oe,exports.RouterKey=e.a,exports.RouterProvider=Re,exports.createRouterPlugin=Le,exports.useNavigator=Me,exports.useRoute=e.t,exports.useRouteEnter=Ie,exports.useRouteExit=Fe,exports.useRouteNode=S,exports.useRouteUtils=Ne,exports.useRouter=x,exports.useRouterTransition=Pe,exports.vLink=je;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|