@kitbag/router 0.7.2 → 0.8.0

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.
@@ -1 +1 @@
1
- (function(y,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(y=typeof globalThis<"u"?globalThis:y||self,i(y["@kitbag/router"]={},y.Vue))})(this,function(y,i){"use strict";var or=Object.defineProperty;var ar=(y,i,T)=>i in y?or(y,i,{enumerable:!0,configurable:!0,writable:!0,value:T}):y[i]=T;var O=(y,i,T)=>(ar(y,typeof i!="symbol"?i+"":i,T),T);class T extends Error{constructor(e){super(`Invalid Param "${e}": Router does not support multiple params by the same name. All param names must be unique.`)}}class ut extends Error{constructor(){super("Router not installed")}}class Wt extends Error{constructor(e,n){super(`useRoute called with incorrect route. Given ${e}, expected ${n}`)}}const wt=Symbol();function it(){const t=i.inject(wt);if(!t)throw new ut;return t}class Y extends Error{}function Q(t){return typeof t!="string"?!1:/^(https?:\/\/|\/).*/g.test(t)}function Dt(t,e={},n={}){const r=it(),o=i.computed(()=>i.toValue(t)),a=i.computed(()=>i.toValue(e)),s=i.computed(()=>i.toValue(n)),c=i.computed(()=>{if(Q(o.value))return o.value;try{return r.resolve(o.value,a.value,s.value)}catch(l){throw l instanceof Y&&console.error(`Failed to resolve route "${o.value.toString()}" in RouterLink.`,l),l}}),u=i.computed(()=>r.find(c.value,s.value)),h=i.computed(()=>!!u.value&&r.route.matches.includes(u.value.matched)),d=i.computed(()=>!!u.value&&r.route.matched===u.value.matched);return{route:u,href:c,isMatch:h,isExactMatch:d,push:l=>r.push(c.value,{},{...s.value,...l}),replace:l=>r.replace(c.value,{},{...s.value,...l})}}const vt=Symbol();function Mt(){const t=i.inject(vt);if(!t)throw new ut;return t}const Tt=Symbol("isRouterRouteSymbol");function Ce(t){return typeof t=="object"&&t!==null&&Tt in t}function Oe(t,e){function n(d,l,S){if(typeof d=="object"){const k={...t.params,...d};return e(t.name,k,l)}const m={...t.params,[d]:l};return e(t.name,m,S)}const{matched:r,matches:o,name:a,query:s,params:c,state:u}=i.toRefs(t),h=i.reactive({matched:r,matches:o,state:u,query:s,params:c,name:a,update:n,[Tt]:!0});return new Proxy(h,{get:(d,l,S)=>l==="params"?new Proxy(t.params,{set(m,k,x){return n(k,x),!0}}):l==="state"?new Proxy(t.state,{set(m,k,x){return n({},{state:{...t.state,[k]:x}}),!0}}):Reflect.get(d,l,S)})}function Et(t){return t===void 0?"":t}function It(t,e,{exact:n}={}){if(!Ce(t))return!1;if(e===void 0)return!0;const r=t.matches.map(o=>Et(o.name));if(n){const o=r.at(-1);return e===o}return r.includes(e)}function Ft(t,e){const n=it();function r(){if(!t)return;if(!It(n.route,t,e))throw new Wt(t,n.route.name)}return i.watch(n.route,r,{immediate:!0,deep:!0}),n.route}const Jt=Symbol();function Pt(){return i.inject(Jt,0)}class ft{constructor(){O(this,"onBeforeRouteEnter",new Set);O(this,"onBeforeRouteUpdate",new Set);O(this,"onBeforeRouteLeave",new Set);O(this,"onAfterRouteEnter",new Set);O(this,"onAfterRouteUpdate",new Set);O(this,"onAfterRouteLeave",new Set)}}class Qt extends Error{}class rt extends Error{constructor(n){super("Error occurred during a router push operation.");O(this,"to");this.to=n}}class St extends Error{constructor(n){super(`Routing action rejected: ${n}`);O(this,"type");this.type=n}}function X(t){return Array.isArray(t)?t:[t]}function Kt(t,e){return t.filter(n=>e===n).length}function qe(t,e){const n=new ft;return t.matches.forEach((r,o)=>{r.onBeforeRouteEnter&&bt(t,e,o)&&X(r.onBeforeRouteEnter).forEach(a=>n.onBeforeRouteEnter.add(a)),r.onBeforeRouteUpdate&&kt(t,e,o)&&X(r.onBeforeRouteUpdate).forEach(a=>n.onBeforeRouteUpdate.add(a))}),e.matches.forEach((r,o)=>{r.onBeforeRouteLeave&&At(t,e,o)&&X(r.onBeforeRouteLeave).forEach(a=>n.onBeforeRouteLeave.add(a))}),n}function _e(t,e){const n=new ft;return t.matches.forEach((r,o)=>{r.onAfterRouteEnter&&bt(t,e,o)&&X(r.onAfterRouteEnter).forEach(a=>n.onAfterRouteEnter.add(a)),r.onAfterRouteUpdate&&kt(t,e,o)&&X(r.onAfterRouteUpdate).forEach(a=>n.onAfterRouteUpdate.add(a))}),e.matches.forEach((r,o)=>{r.onAfterRouteLeave&&At(t,e,o)&&X(r.onAfterRouteLeave).forEach(a=>n.onAfterRouteLeave.add(a))}),n}function We(){const t=s=>{throw new St(s)},e=(...s)=>{throw new rt(s)},n=(s,c,u)=>{if(Q(s)){const l=c??{};throw new rt([s,{...l,replace:!0}])}const h=c,d=u??{};throw new rt([s,h,{...d,replace:!0}])},r=()=>{throw new Qt};async function o({to:s,from:c,hooks:u}){const{global:h,component:d}=u,l=qe(s,c),S=[...h.onBeforeRouteEnter,...l.onBeforeRouteEnter,...h.onBeforeRouteUpdate,...l.onBeforeRouteUpdate,...d.onBeforeRouteUpdate,...h.onBeforeRouteLeave,...l.onBeforeRouteLeave,...d.onBeforeRouteLeave];try{const m=S.map(k=>k(s,{from:c,reject:t,push:e,replace:n,abort:r}));await Promise.all(m)}catch(m){if(m instanceof rt)return{status:"PUSH",to:m.to};if(m instanceof St)return{status:"REJECT",type:m.type};if(m instanceof Qt)return{status:"ABORT"};throw m}return{status:"SUCCESS"}}async function a({to:s,from:c,hooks:u}){const{global:h,component:d}=u,l=_e(s,c),S=[...d.onAfterRouteLeave,...l.onAfterRouteLeave,...h.onAfterRouteLeave,...d.onAfterRouteUpdate,...l.onAfterRouteUpdate,...h.onAfterRouteUpdate,...d.onAfterRouteEnter,...l.onAfterRouteEnter,...h.onAfterRouteEnter];try{const m=S.map(k=>k(s,{from:c,reject:t,push:e,replace:n}));await Promise.all(m)}catch(m){if(m instanceof rt)return{status:"PUSH",to:m.to};if(m instanceof St)return{status:"REJECT",type:m.type};throw m}return{status:"SUCCESS"}}return{runBeforeRouteHooks:o,runAfterRouteHooks:a}}const bt=(t,e,n)=>{const r=t.matches,o=(e==null?void 0:e.matches)??[];return r.length<n||r[n]!==o[n]},At=(t,e,n)=>{const r=t.matches,o=(e==null?void 0:e.matches)??[];return r.length<n||r[n]!==o[n]},kt=(t,e,n)=>t.matches[n]===(e==null?void 0:e.matches[n]);function Gt(t){switch(t){case"onBeforeRouteEnter":case"onAfterRouteEnter":return bt;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return kt;case"onBeforeRouteLeave":case"onAfterRouteLeave":return At;default:throw new Error(`Switch is not exhaustive for lifecycle: ${t}`)}}class De{constructor(){O(this,"global",new ft);O(this,"component",new ft)}addBeforeRouteHook({lifecycle:e,timing:n,depth:r,hook:o}){const a=Gt(e),s=this[n][e],c=(u,h)=>{if(a(u,h.from,r))return o(u,h)};return s.add(c),()=>s.delete(c)}addAfterRouteHook({lifecycle:e,timing:n,depth:r,hook:o}){const a=Gt(e),s=this[n][e],c=(u,h)=>{if(a(u,h.from,r))return o(u,h)};return s.add(c),()=>s.delete(c)}}const zt=Symbol();function Me(){const t=new De;return{onBeforeRouteEnter:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteEnter",hook:c,timing:"global",depth:0}),onBeforeRouteUpdate:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteUpdate",hook:c,timing:"global",depth:0}),onBeforeRouteLeave:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteLeave",hook:c,timing:"global",depth:0}),onAfterRouteEnter:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteEnter",hook:c,timing:"global",depth:0}),onAfterRouteUpdate:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteUpdate",hook:c,timing:"global",depth:0}),onAfterRouteLeave:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteLeave",hook:c,timing:"global",depth:0}),hooks:t}}function Yt(){const t=i.inject(zt);if(!t)throw new ut;return t}function Xt(t){return e=>{const n=Pt(),o=Yt().addBeforeRouteHook({lifecycle:t,hook:e,depth:n,timing:"component"});return i.onUnmounted(o),o}}function xt(t){return e=>{const n=Pt(),o=Yt().addAfterRouteHook({lifecycle:t,hook:e,depth:n,timing:"component"});return i.onUnmounted(o),o}}const Te=Xt("onBeforeRouteUpdate"),Ie=Xt("onBeforeRouteLeave"),Fe=xt("onAfterRouteEnter"),Je=xt("onAfterRouteUpdate"),Qe=xt("onAfterRouteLeave"),Ke=["href"],Zt=i.defineComponent({__name:"routerLink",props:{to:{type:[String,Function]},query:{},replace:{type:Boolean},state:{}},setup(t){const e=t,n=it(),r=i.computed(()=>Q(e.to)?e.to:e.to(n.resolve)),o=i.computed(()=>{const{to:l,...S}=e;return S}),{href:a,isMatch:s,isExactMatch:c}=Dt(r),u=i.computed(()=>({"router-link--match":s.value,"router-link--exact-match":c.value})),h=i.computed(()=>n.isExternal(r.value));function d(l){l.preventDefault(),n.push(a.value,o.value)}return(l,S)=>(i.openBlock(),i.createElementBlock("a",{href:r.value,class:i.normalizeClass(["router-link",u.value]),onClick:d},[i.renderSlot(l.$slots,"default",i.normalizeProps(i.guardReactiveProps({resolved:r.value,isMatch:i.unref(s),isExactMatch:i.unref(c),isExternal:h.value})))],10,Ke))}});function te(t,e){return i.defineComponent({name:"PropsWrapper",expose:[],setup(){const n=e();return"then"in n?()=>i.h(Ge(t,n)):()=>i.h(t,n)}})}function Ge(t,e){return i.defineComponent({name:"AsyncPropsWrapper",expose:[],async setup(){const n=await e;return()=>i.h(t,n)}})}class ze extends Error{constructor(e){super(`Child property on meta for ${e} conflicts with the parent meta.`)}}function Ye(t,e){return Xe(t,e),{...t,...e}}function Xe(t,e){const n=Object.keys(t).find(r=>r in e&&typeof e[r]!=typeof t[r]);if(n)throw new ze(n)}function Z(...t){const e=t.flatMap(n=>Array.isArray(n)?n:Object.keys(n).map(Ze));for(const n of e)if(Kt(e,n)>1)throw new T(n)}function Ze(t){return t.startsWith("?")?t.slice(1):t}function tn(t,e){Z(t.params,e.params);const n=`${t.path}${e.path}`;return{path:n,params:{...t.params,...e.params},toString:()=>n}}function Bt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function en(t){return t.every(e=>Array.isArray(e))}function lt(t){return typeof t=="string"&&t.length>0}function nn(t,e){Z(t.params,e.params);const n=[t.query,e.query].filter(lt).join("&");return{query:n,params:{...t.params,...e.params},toString:()=>n}}function rn(t,e){return Z(t,e),{...t,...e}}function on(t){return"host"in t&&!!t.host}function ee(t){return"parent"in t&&!!t.parent}function ne(t){return"component"in t&&!!t.component}function re(t){return"components"in t&&!!t.components}function an(t){return"state"in t&&!!t.state}function oe(t,e){return{...e,path:tn(t.path,e.path),query:nn(t.query,e.query),meta:Ye(t.meta,e.meta),state:rn(t.state,e.state),matches:[...t.matches,e.matched],host:t.host,depth:t.depth+1}}const ae=i.defineComponent({__name:"routerView",props:{name:{}},setup(t){const{name:e="default"}=t,n=Ft(),r=Mt(),o=Pt(),a=i.resolveComponent("RouterView",!0);i.provide(Jt,o+1);const s=i.computed(()=>{if(r.value)return r.value.component;const l=n.matches.at(o);if(!l)return null;const S=c(l),m=h(l);return S?m?te(S,()=>m(n.params)):S:null});function c(l){return u(l)[e]}function u(l){return re(l)?l.components:ne(l)?{default:l.component}:typeof a=="string"?{}:{default:a}}function h(l){return d(l)[e]}function d(l){return re(l)?l.props??{}:ne(l)?{default:l.props}:{}}return(l,S)=>s.value?i.renderSlot(l.$slots,"default",i.normalizeProps(i.mergeProps({key:0},{route:i.unref(n),component:s.value,rejection:i.unref(r)})),()=>[(i.openBlock(),i.createBlock(i.resolveDynamicComponent(s.value)))]):i.createCommentVNode("",!0)}}),D="[",I="]";function sn(t){return t!==String&&t!==Boolean&&t!==Number&&t!==Date}function cn(t){return typeof t=="function"&&sn(t)}function ht(t){return typeof t=="object"&&"get"in t&&typeof t.get=="function"&&"set"in t&&typeof t.set=="function"}function se(t){return ht(t)&&t.defaultValue!==void 0}function un(t,e){return le(t,e)}function fn(t,e){return t[e]??String}const H={invalid:t=>{throw new Y(t)}},ln={get:t=>t,set:(t,{invalid:e})=>{if(typeof t!="string")throw e();return t}},ce={get:(t,{invalid:e})=>{if(t==="true")return!0;if(t==="false")return!1;throw e()},set:(t,{invalid:e})=>{if(typeof t!="boolean")throw e();return t.toString()}},ue={get:(t,{invalid:e})=>{const n=Number(t);if(isNaN(n))throw e();return n},set:(t,{invalid:e})=>{if(typeof t!="number")throw e();return t.toString()}},ie={get:(t,{invalid:e})=>{const n=new Date(t);if(isNaN(n.getTime()))throw e();return n},set:(t,{invalid:e})=>{if(typeof t!="object"||!(t instanceof Date))throw e();return t.toISOString()}},fe={get:(t,{invalid:e})=>{try{return JSON.parse(t)}catch{throw e()}},set:(t,{invalid:e})=>{try{return JSON.stringify(t)}catch{throw e()}}};function ot(t,e,n=!1){if(t===void 0||!lt(t)){if(se(e))return e.defaultValue;if(n)return;throw new Y}if(e===String)return ln.get(t,H);if(e===Boolean)return ce.get(t,H);if(e===Number)return ue.get(t,H);if(e===Date)return ie.get(t,H);if(e===JSON)return fe.get(t,H);if(cn(e))return e(t,H);if(ht(e))return e.get(t,H);if(e instanceof RegExp){if(e.test(t))return t;throw new Y}return t}function at(t,e,n=!1){if(t===void 0){if(n)return"";throw new Y}if(e===Boolean)return ce.set(t,H);if(e===Number)return ue.set(t,H);if(e===Date)return ie.set(t,H);if(e===JSON)return fe.set(t,H);if(ht(e))return e.set(t,H);try{return t.toString()}catch{throw new Y}}function le(t,e){return ht(t)?{...t,defaultValue:e??t.defaultValue}:{get:n=>ot(n,t),set:n=>at(n,t),defaultValue:e}}function F(){return F=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},F.apply(this,arguments)}var N;(function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"})(N||(N={}));var tt=process.env.NODE_ENV!=="production"?function(t){return Object.freeze(t)}:function(t){return t};function K(t,e){if(!t){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}var pt="beforeunload",hn="hashchange",he="popstate";function pe(t){t===void 0&&(t={});var e=t,n=e.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var R=r.location,f=R.pathname,p=R.search,E=R.hash,P=o.state||{};return[P.idx,tt({pathname:f,search:p,hash:E,state:P.usr||null,key:P.key||"default"})]}var s=null;function c(){if(s)m.call(s),s=null;else{var R=N.Pop,f=a(),p=f[0],E=f[1];if(m.length)if(p!=null){var P=d-p;P&&(s={action:R,location:E,retry:function(){b(P*-1)}},b(P))}else process.env.NODE_ENV!=="production"&&K(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else q(R)}}r.addEventListener(he,c);var u=N.Pop,h=a(),d=h[0],l=h[1],S=et(),m=et();d==null&&(d=0,o.replaceState(F({},o.state,{idx:d}),""));function k(R){return typeof R=="string"?R:G(R)}function x(R,f){return f===void 0&&(f=null),tt(F({pathname:l.pathname,hash:"",search:""},typeof R=="string"?st(R):R,{state:f,key:mt()}))}function j(R,f){return[{usr:R.state,key:R.key,idx:f},k(R)]}function V(R,f,p){return!m.length||(m.call({action:R,location:f,retry:p}),!1)}function q(R){u=R;var f=a();d=f[0],l=f[1],S.call({action:u,location:l})}function g(R,f){var p=N.Push,E=x(R,f);function P(){g(R,f)}if(V(p,E,P)){var B=j(E,d+1),U=B[0],$=B[1];try{o.pushState(U,"",$)}catch{r.location.assign($)}q(p)}}function w(R,f){var p=N.Replace,E=x(R,f);function P(){w(R,f)}if(V(p,E,P)){var B=j(E,d),U=B[0],$=B[1];o.replaceState(U,"",$),q(p)}}function b(R){o.go(R)}var A={get action(){return u},get location(){return l},createHref:k,push:g,replace:w,go:b,back:function(){b(-1)},forward:function(){b(1)},listen:function(f){return S.push(f)},block:function(f){var p=m.push(f);return m.length===1&&r.addEventListener(pt,dt),function(){p(),m.length||r.removeEventListener(pt,dt)}}};return A}function pn(t){t===void 0&&(t={});var e=t,n=e.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var f=st(r.location.hash.substr(1)),p=f.pathname,E=p===void 0?"/":p,P=f.search,B=P===void 0?"":P,U=f.hash,$=U===void 0?"":U,C=o.state||{};return[C.idx,tt({pathname:E,search:B,hash:$,state:C.usr||null,key:C.key||"default"})]}var s=null;function c(){if(s)m.call(s),s=null;else{var f=N.Pop,p=a(),E=p[0],P=p[1];if(m.length)if(E!=null){var B=d-E;B&&(s={action:f,location:P,retry:function(){A(B*-1)}},A(B))}else process.env.NODE_ENV!=="production"&&K(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else g(f)}}r.addEventListener(he,c),r.addEventListener(hn,function(){var f=a(),p=f[1];G(p)!==G(l)&&c()});var u=N.Pop,h=a(),d=h[0],l=h[1],S=et(),m=et();d==null&&(d=0,o.replaceState(F({},o.state,{idx:d}),""));function k(){var f=document.querySelector("base"),p="";if(f&&f.getAttribute("href")){var E=r.location.href,P=E.indexOf("#");p=P===-1?E:E.slice(0,P)}return p}function x(f){return k()+"#"+(typeof f=="string"?f:G(f))}function j(f,p){return p===void 0&&(p=null),tt(F({pathname:l.pathname,hash:"",search:""},typeof f=="string"?st(f):f,{state:p,key:mt()}))}function V(f,p){return[{usr:f.state,key:f.key,idx:p},x(f)]}function q(f,p,E){return!m.length||(m.call({action:f,location:p,retry:E}),!1)}function g(f){u=f;var p=a();d=p[0],l=p[1],S.call({action:u,location:l})}function w(f,p){var E=N.Push,P=j(f,p);function B(){w(f,p)}if(process.env.NODE_ENV!=="production"&&K(P.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(f)+")"),q(E,P,B)){var U=V(P,d+1),$=U[0],C=U[1];try{o.pushState($,"",C)}catch{r.location.assign(C)}g(E)}}function b(f,p){var E=N.Replace,P=j(f,p);function B(){b(f,p)}if(process.env.NODE_ENV!=="production"&&K(P.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(f)+")"),q(E,P,B)){var U=V(P,d),$=U[0],C=U[1];o.replaceState($,"",C),g(E)}}function A(f){o.go(f)}var R={get action(){return u},get location(){return l},createHref:x,push:w,replace:b,go:A,back:function(){A(-1)},forward:function(){A(1)},listen:function(p){return S.push(p)},block:function(p){var E=m.push(p);return m.length===1&&r.addEventListener(pt,dt),function(){E(),m.length||r.removeEventListener(pt,dt)}}};return R}function de(t){t===void 0&&(t={});var e=t,n=e.initialEntries,r=n===void 0?["/"]:n,o=e.initialIndex,a=r.map(function(g){var w=tt(F({pathname:"/",search:"",hash:"",state:null,key:mt()},typeof g=="string"?st(g):g));return process.env.NODE_ENV!=="production"&&K(w.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(g)+")"),w}),s=me(o??a.length-1,0,a.length-1),c=N.Pop,u=a[s],h=et(),d=et();function l(g){return typeof g=="string"?g:G(g)}function S(g,w){return w===void 0&&(w=null),tt(F({pathname:u.pathname,search:"",hash:""},typeof g=="string"?st(g):g,{state:w,key:mt()}))}function m(g,w,b){return!d.length||(d.call({action:g,location:w,retry:b}),!1)}function k(g,w){c=g,u=w,h.call({action:c,location:u})}function x(g,w){var b=N.Push,A=S(g,w);function R(){x(g,w)}process.env.NODE_ENV!=="production"&&K(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(g)+")"),m(b,A,R)&&(s+=1,a.splice(s,a.length,A),k(b,A))}function j(g,w){var b=N.Replace,A=S(g,w);function R(){j(g,w)}process.env.NODE_ENV!=="production"&&K(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(g)+")"),m(b,A,R)&&(a[s]=A,k(b,A))}function V(g){var w=me(s+g,0,a.length-1),b=N.Pop,A=a[w];function R(){V(g)}m(b,A,R)&&(s=w,k(b,A))}var q={get index(){return s},get action(){return c},get location(){return u},createHref:l,push:x,replace:j,go:V,back:function(){V(-1)},forward:function(){V(1)},listen:function(w){return h.push(w)},block:function(w){return d.push(w)}};return q}function me(t,e,n){return Math.min(Math.max(t,e),n)}function dt(t){t.preventDefault(),t.returnValue=""}function et(){var t=[];return{get length(){return t.length},push:function(n){return t.push(n),function(){t=t.filter(function(r){return r!==n})}},call:function(n){t.forEach(function(r){return r&&r(n)})}}}function mt(){return Math.random().toString(36).substr(2,8)}function G(t){var e=t.pathname,n=e===void 0?"/":e,r=t.search,o=r===void 0?"":r,a=t.hash,s=a===void 0?"":a;return o&&o!=="?"&&(n+=o.charAt(0)==="?"?o:"?"+o),s&&s!=="#"&&(n+=s.charAt(0)==="#"?s:"#"+s),n}function st(t){var e={};if(t){var n=t.indexOf("#");n>=0&&(e.hash=t.substr(n),t=t.substr(0,n));var r=t.indexOf("?");r>=0&&(e.search=t.substr(r),t=t.substr(0,r)),t&&(e.pathname=t)}return e}function dn(t,e){const n=i.reactive({...t}),r=s=>{Object.assign(n,{...s})},o=n,a=Oe(o,e);return{currentRoute:o,routerRoute:a,updateRoute:r}}function z(t){return!t.startsWith("http")?Rn(t):mn(t)}function mn(t){const{protocol:e,host:n,pathname:r,search:o,searchParams:a,hash:s}=new URL(t,t);return{protocol:e,host:n,pathname:r,search:o,searchParams:a,hash:s}}function Rn(t){const{pathname:e,search:n,searchParams:r,hash:o}=new URL(t,"https://localhost");return{pathname:e,search:n,searchParams:r,hash:o}}function gn(t){return e=>{const{host:n}=z(e);return!(n===void 0||n===t)}}function Re(){return typeof window<"u"&&typeof window.document<"u"}function yn({mode:t,listener:e}){const n=wn(t),r=(u,h)=>{if(h!=null&&h.replace)return n.replace(u,h.state);n.push(u,h==null?void 0:h.state)},o=()=>{const u=G(n.location);return n.replace(u)};let a;return{...n,update:r,refresh:o,startListening:()=>{a==null||a(),a=n.listen(e)},stopListening:()=>{a==null||a()}}}function wn(t="auto"){switch(t){case"auto":return Re()?pe():de();case"browser":return pe();case"memory":return de();case"hash":return pn();default:const e=t;throw new Error(`Switch is not exhaustive for mode: ${e}`)}}function vn(t){return i.defineComponent(()=>()=>i.h("h1",t),{name:t,props:[]})}function ge(t){const e=new URLSearchParams(t);return{get:n=>e.get(n),getAll:n=>e.getAll(n)}}const ye=Symbol();function En({rejections:t}){const e=s=>{const c={...t};return i.markRaw(c[s]??vn(s))},n=s=>{const c=i.markRaw(e(s)),u={name:s,component:c,meta:{},state:{}};return{matched:u,matches:[u],name:s,query:ge(""),params:{},state:{},[ye]:!0}},r=s=>ye in s,o=s=>{if(!s){a.value=null;return}const c=e(s);a.value={type:s,component:c}},a=i.ref(null);return{setRejection:o,rejection:a,getRejectionRoute:n,isRejectionRoute:r}}class Pn extends Error{constructor(e){super(`Route not found: "${e}"`)}}function Lt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Sn(t,e){const n=Array.from(t.matchAll(e));if(n.length===0)return[t];let r=0;const o=n.reduce((s,c)=>{const u=Lt(t.slice(r,c.index));u.length&&s.push(u);const[h]=c;return s.push(h),r=c.index+h.length,s},[]),a=t.slice(r);return a&&o.push(a),o}function bn(t){const e=we(t.path.toString());return new RegExp(`^${e}$`,"i")}function An(t){const e=new URLSearchParams(t.query.toString());return Array.from(e.entries()).filter(([,n])=>!Nt(n)).map(([n,r])=>{const o=we(r);return new RegExp(`${Lt(n)}=${o}(&|$)`,"i")})}function we(t){return Sn(t,new RegExp(kn,"g")).map(e=>e.startsWith(D)?ve(e):Lt(e)).join("")}function ve(t){return[xn,Bn].reduce((e,n)=>n(e),t)}const kn=`\\${D}\\??([\\w-_]+)\\${I}`,Ut=`\\${D}\\?([\\w-_]+)\\${I}`,Ee=`\\${D}([\\w-_]+)\\${I}`;function xn(t){return t.replace(new RegExp(Ut,"g"),".*")}function Nt(t){return new RegExp(Ut,"g").test(t)}function Bn(t){return t.replace(new RegExp(Ee,"g"),".+")}function Rt(t){const[e]=gt(t,new RegExp(Ut,"g")),[n]=gt(t,new RegExp(Ee,"g"));return e??n}function gt(t,e){return Array.from(t.matchAll(e)).flatMap(([,...r])=>r.map(o=>lt(o)?o:""))}function Pe(t,e,n){const r=be(e,n),[o]=gt(t,r);return o}function Se(t,e){if(!e)return t;const{name:n,param:r,value:o}=e,a=be(t,n);return gt(t,a).reduce((c,u)=>u===void 0?c:c.replace(u,()=>at(o,r,n.startsWith("?"))),t)}function be(t,e){const n=[Ln,Un,ve].reduce((r,o)=>o(r,e),t);return new RegExp(n,"g")}function Ln(t,e){if(!e.startsWith("?"))return t;const n=new RegExp(`\\${D}\\${e}\\${I}`,"g");return t.replace(n,"(.*)")}function Un(t,e){if(e.startsWith("?"))return t;const n=new RegExp(`\\${D}${e}\\${I}`,"g");return t.replace(n,"(.+)")}function Ae(t,...e){return e.reduce((n,r)=>{if(!r)return n;const o=new URLSearchParams(r).toString();return Object.keys(o).length===0?n:n.includes("?")?`${n}&${o}`:`${n}?${o}`},t)}function Nn(t,e={}){const{params:n={},query:r}=e,o=$n(t.host,n),a=jn(t.path,n),s=Hn(t.query,n);return Ae(`${o}${a}`,s,r)}function $n(t,e){const n=t.toString();return Object.entries(t.params).reduce((r,[o,a])=>{const s=Rt(`${D}${o}${I}`);return s?Se(r,{name:o,param:a,value:e[s]}):r},n)}function jn(t,e){const n=t.toString();return Object.entries(t.params).reduce((r,[o,a])=>{const s=Rt(`${D}${o}${I}`);return s?Se(r,{name:o,param:a,value:e[s]}):r},n)}function Hn(t,e){const n=t.toString();if(!n)return{};const r=new URLSearchParams(n);return Array.from(r.entries()).reduce((o,[a,s])=>{const c=Rt(s);if(!c)return{...o,[a]:s};const h=at(e[c],t.params[c],Nt(s)),d=e[c]===void 0&&h==="";return Nt(s)&&d?o:{...o,[a]:h}},{})}function Vn(t){return(e,n,r)=>{if(Q(e))return Ae(e,(n??{}).query);const o=n??{},a=r??{},s=t.find(u=>u.name===e);if(!s)throw new Pn(String(e));return Nn(s,{params:o,query:a.query})}}class Cn extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function On(t){if(t)return t;if(Re())return window.location.toString();throw new Cn}const qn=(t,e)=>{try{ke(t,e)}catch{return!1}return!0},ke=(t,e)=>{const{pathname:n,search:r}=z(e);return{..._n(t.path,n),...Wn(t.query,r)}};function _n(t,e){const n={},r=decodeURIComponent(e);for(const[o,a]of Object.entries(t.params)){const s=o.startsWith("?"),c=s?o.slice(1):o,u=Pe(r,t.toString(),o),h=ot(u,a,s);n[c]=h}return n}function Wn(t,e){const n={},r=new URLSearchParams(e);for(const[o,a]of Object.entries(t.params)){const s=o.startsWith("?"),c=s?o.slice(1):o,u=r.get(c)??void 0,h=ot(u,a,s);n[c]=h}return n}const Dn=t=>"name"in t.matched&&!!t.matched.name,Mn=(t,e)=>{const{pathname:n}=z(e);return bn(t).test(n)},Tn=(t,e)=>{const{search:n}=z(e);return An(t).every(o=>o.test(n))};function In(t){const{searchParams:e,pathname:n}=z(t),r=-1,o=1;return(a,s)=>{const c=Be(a,e),u=xe(a,n),h=Be(s,e),d=xe(s,n);return a.depth>s.depth?r:a.depth<s.depth?o:c+u>h+d?r:c+u<h+d?o:0}}function xe(t,e){const n=Object.keys(t.path.params).filter(o=>o.startsWith("?")).map(o=>o),r=n.filter(o=>Pe(e,t.path.toString(),o)===void 0);return n.length-r.length}function Be(t,e){const n=new URLSearchParams(t.query.toString()),r=Array.from(n.keys()),o=r.filter(a=>!e.has(a));return r.length-o.length}function Le(t){return!!t&&typeof t=="object"}const yt=!0;function Fn(t,e,n){if(Le(t)&&e in t){const r=t[e];if(typeof r=="string")return ot(r,n,yt)}return ot(void 0,n,yt)}function Jn(t,e){const n={};for(const[r,o]of Object.entries(t)){const a=Fn(e,r,o);n[r]=a}return n}function Qn(t,e,n){if(Le(t)&&e in t){const r=t[e];return at(r,n,yt)}return at(void 0,n,yt)}const Ue=(t,e)=>{const n={};for(const[r,o]of Object.entries(t)){const a=Qn(e,r,o);n[r]=a}return n},Kn=[Dn,Mn,Tn,qn];function $t(t,e,n){const r=In(e),o=t.filter(c=>Kn.every(u=>u(c,e))).sort(r);if(o.length===0)return;const[a]=o,{search:s}=z(e);return{matched:a.matched,matches:a.matches,name:a.name,query:ge(s),params:ke(a,e),state:Jn(a.state,n)}}function jt(t,e){const n=new RegExp(`\\${D}(\\??[\\w-_]+)\\${I}`,"g");return Array.from(t.matchAll(n)).reduce((o,[a,s])=>{const c=Rt(a);if(!c)return o;const u=fn(e,c);return Z([c],o),o[s]=u,o},{})}function Ne(t,e){return{host:t,params:jt(t,e),toString:()=>t}}function Ht(t,e){return{path:t,params:jt(t,e),toString:()=>t}}function Gn(t){return Bt(t)&&typeof t.path=="string"}function $e(t){return t===void 0?Ht("",{}):Gn(t)?t:Ht(t,{})}function Vt(t,e){return{query:t,params:jt(t,e),toString:()=>t}}function zn(t){return Bt(t)&&typeof t.query=="string"}function je(t){return t===void 0?Vt("",{}):zn(t)?t:Vt(t,{})}function Ct(t){const e=Et(t.name),n=$e(t.path),r=je(t.query),o=t.meta??{},a=an(t)?t.state:{},s=i.markRaw({meta:{},state:{},...t}),c={matched:s,matches:[s],name:e,path:n,query:r,meta:o,state:a,depth:1,host:Ne("",{})},u=ee(t)?oe(t.parent,c):c;return Z(u.path.params,u.query.params),u}function Yn(t,e){if(!lt(e))return t;const n=Ct({path:e});return t.map(r=>Ct({parent:n,...r}))}class Xn extends Error{constructor(e){super(`Invalid Name "${e}": Router does not support multiple routes with the same name. All name names must be unique.`)}}function Zn(t){const e=t.map(({name:n})=>n);for(const n of e)if(Kt(e,n)>1)throw new Xn(n)}function tr(t,e={}){const n=en(t)?t.flat():t,r=Yn(n,e.base);Zn(r);const o=Vn(r),a=yn({mode:e.historyMode,listener:({location:v})=>{const L=G(v);x(L,{state:v.state})}}),{runBeforeRouteHooks:s,runAfterRouteHooks:c}=We(),{hooks:u,onBeforeRouteEnter:h,onAfterRouteUpdate:d,onBeforeRouteLeave:l,onAfterRouteEnter:S,onBeforeRouteUpdate:m,onAfterRouteLeave:k}=Me();async function x(v,L={}){if(a.stopListening(),$(v))return a.update(v,L);const _=$t(r,v,L.state)??A("NotFound"),W={...f},nt=await s({to:_,from:W,hooks:u});switch(nt.status){case"ABORT":return;case"PUSH":a.update(v,L),await j(...nt.to);return;case"REJECT":a.update(v,L),w(nt.type),E(_);break;case"SUCCESS":a.update(v,L),w(null),E(_);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(nt)}`)}const J=await c({to:_,from:W,hooks:u});switch(J.status){case"PUSH":await j(...J.to);break;case"REJECT":w(J.type);break;case"SUCCESS":break;default:const M=J;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(M)}`)}a.startListening()}const j=(v,L,_)=>{if(Q(v)){const ct={...L},_t=o(v,ct);return x(_t,ct)}const W={..._},J=o(v,L??{},W),M=Ot(v),qt=Ue((M==null?void 0:M.state)??{},W.state);return x(J,{...W,state:qt})},V=(v,L,_)=>{if(Q(v)){const ct={...L,replace:!0},_t=o(v,ct);return x(_t,ct)}const W={..._,replace:!0},J=o(v,L??{},W),M=Ot(v),qt=Ue((M==null?void 0:M.state)??{},W.state);return x(J,{...W,state:qt})},q=v=>w(v),g=(v,L={})=>{if(!Q(v)){const _=o(v,L);return $t(r,_)}if(!$(v))return $t(r,v)},{setRejection:w,rejection:b,getRejectionRoute:A}=En(e),R=A("NotFound"),{currentRoute:f,routerRoute:p,updateRoute:E}=dn(R,j);a.startListening();const P=On(e.initialUrl),B=a.location.state,{host:U}=z(P),$=gn(U),C=x(P,{replace:!0,state:B});function Ot(v){return r.find(L=>L.name===v)}function rr(v){v.component("RouterView",ae),v.component("RouterLink",Zt),v.provide(vt,b),v.provide(zt,u),v.provide(wt,Ve)}const Ve={route:p,resolve:o,push:j,replace:V,reject:q,find:g,refresh:a.refresh,forward:a.forward,back:a.back,go:a.go,install:rr,initialized:C,isExternal:$,onBeforeRouteEnter:h,onAfterRouteUpdate:d,onBeforeRouteLeave:l,onAfterRouteEnter:S,onBeforeRouteUpdate:m,onAfterRouteLeave:k};return Ve}function er(t){return Bt(t)&&typeof t.host=="string"}function He(t){return er(t)?t:Ne(t,{})}function nr(t){const e=Et(t.name),n=$e(t.path),r=je(t.query),o=t.meta??{},a=on(t)?He(t.host):He(""),s=i.markRaw({meta:{},state:{},...t}),c={matched:s,matches:[s],name:e,host:a,path:n,query:r,meta:o,depth:1,state:{}},u=ee(t)?oe(t.parent,c):c;return Z(u.path.params,u.query.params,u.host.params),u}y.DuplicateParamsError=T,y.RouterLink=Zt,y.RouterNotInstalledError=ut,y.RouterView=ae,y.UseRouteInvalidError=Wt,y.component=te,y.createExternalRoute=nr,y.createParam=le,y.createRoute=Ct,y.createRouter=tr,y.isParamWithDefault=se,y.isRoute=It,y.onAfterRouteEnter=Fe,y.onAfterRouteLeave=Je,y.onAfterRouteUpdate=Qe,y.onBeforeRouteLeave=Te,y.onBeforeRouteUpdate=Ie,y.path=Ht,y.query=Vt,y.routerInjectionKey=wt,y.routerRejectionKey=vt,y.useLink=Dt,y.useRejection=Mt,y.useRoute=Ft,y.useRouter=it,y.withDefault=un,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(y=typeof globalThis<"u"?globalThis:y||self,i(y["@kitbag/router"]={},y.Vue))})(this,function(y,i){"use strict";var dr=Object.defineProperty;var Rr=(y,i,F)=>i in y?dr(y,i,{enumerable:!0,configurable:!0,writable:!0,value:F}):y[i]=F;var O=(y,i,F)=>(Rr(y,typeof i!="symbol"?i+"":i,F),F);class F extends Error{constructor(e){super(`Invalid Param "${e}": Router does not support multiple params by the same name. All param names must be unique.`)}}class it extends Error{constructor(){super("Router not installed")}}class Ft extends Error{constructor(e,n){super(`useRoute called with incorrect route. Given ${e}, expected ${n}`)}}const Pt=Symbol();function ft(){const t=i.inject(Pt);if(!t)throw new it;return t}class X extends Error{}class We extends Error{constructor(e){super(`Child property on meta for ${e} conflicts with the parent meta.`)}}function Te(t,e){return Me(t,e),{...t,...e}}function Me(t,e){const n=Object.keys(t).find(r=>r in e&&typeof e[r]!=typeof t[r]);if(n)throw new We(n)}function Z(t){return Array.isArray(t)?t:[t]}function Jt(t,e){return t.filter(n=>e===n).length}function tt(...t){const e=t.flatMap(n=>Array.isArray(n)?n:Object.keys(n).map(Ie));for(const n of e)if(Jt(e,n)>1)throw new F(n)}function Ie(t){return t.startsWith("?")?t.slice(1):t}function Fe(t,e){tt(t.params,e.params);const n=`${t.path}${e.path}`;return{path:n,params:{...t.params,...e.params},toString:()=>n}}function lt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Je(t){return t.every(e=>Array.isArray(e))}function ht(t){return typeof t=="string"&&t.length>0}function Qe(t,e){tt(t.params,e.params);const n=[t.query,e.query].filter(ht).join("&");return{query:n,params:{...t.params,...e.params},toString:()=>n}}function Ge(t,e){return tt(t,e),{...t,...e}}function Ke(t){return"host"in t&&!!t.host}function Qt(t){return"parent"in t&&!!t.parent}function bt(t){return"component"in t&&!!t.component}function St(t){return"components"in t&&!!t.components}function ze(t){return"state"in t&&!!t.state}function Gt(t,e){return{...e,path:Fe(t.path,e.path),query:Qe(t.query,e.query),meta:Te(t.meta,e.meta),state:Ge(t.state,e.state),matches:[...t.matches,e.matched],host:t.host,depth:t.depth+1}}function Kt(){return typeof window<"u"&&typeof window.document<"u"}function zt(t,e){return i.defineComponent({name:"PropsWrapper",expose:[],setup(){const n=e();return"then"in n?()=>i.h(Ye(t,n)):()=>i.h(t,n)}})}function Ye(t,e){return i.defineComponent({name:"AsyncPropsWrapper",expose:[],async setup(){const n=await e;return()=>i.h(t,n)}})}const W="[",J="]";function Xe(t){return t!==String&&t!==Boolean&&t!==Number&&t!==Date}function Ze(t){return typeof t=="function"&&Xe(t)}function pt(t){return typeof t=="object"&&"get"in t&&typeof t.get=="function"&&"set"in t&&typeof t.set=="function"}function Yt(t){return pt(t)&&t.defaultValue!==void 0}function tn(t,e){return ne(t,e)}function en(t,e){return t[e]??String}const j={invalid:t=>{throw new X(t)}},nn={get:t=>t,set:(t,{invalid:e})=>{if(typeof t!="string")throw e();return t}},Xt={get:(t,{invalid:e})=>{if(t==="true")return!0;if(t==="false")return!1;throw e()},set:(t,{invalid:e})=>{if(typeof t!="boolean")throw e();return t.toString()}},Zt={get:(t,{invalid:e})=>{const n=Number(t);if(isNaN(n))throw e();return n},set:(t,{invalid:e})=>{if(typeof t!="number")throw e();return t.toString()}},te={get:(t,{invalid:e})=>{const n=new Date(t);if(isNaN(n.getTime()))throw e();return n},set:(t,{invalid:e})=>{if(typeof t!="object"||!(t instanceof Date))throw e();return t.toISOString()}},ee={get:(t,{invalid:e})=>{try{return JSON.parse(t)}catch{throw e()}},set:(t,{invalid:e})=>{try{return JSON.stringify(t)}catch{throw e()}}};function ot(t,e,n=!1){if(t===void 0||!ht(t)){if(Yt(e))return e.defaultValue;if(n)return;throw new X}if(e===String)return nn.get(t,j);if(e===Boolean)return Xt.get(t,j);if(e===Number)return Zt.get(t,j);if(e===Date)return te.get(t,j);if(e===JSON)return ee.get(t,j);if(Ze(e))return e(t,j);if(pt(e))return e.get(t,j);if(e instanceof RegExp){if(e.test(t))return t;throw new X}return t}function at(t,e,n=!1){if(t===void 0){if(n)return"";throw new X}if(e===Boolean)return Xt.set(t,j);if(e===Number)return Zt.set(t,j);if(e===Date)return te.set(t,j);if(e===JSON)return ee.set(t,j);if(pt(e))return e.set(t,j);try{return t.toString()}catch{throw new X}}function ne(t,e){return pt(t)?{...t,defaultValue:e??t.defaultValue}:{get:n=>ot(n,t),set:n=>at(n,t),defaultValue:e}}function Q(){return Q=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Q.apply(this,arguments)}var N;(function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"})(N||(N={}));var et=process.env.NODE_ENV!=="production"?function(t){return Object.freeze(t)}:function(t){return t};function K(t,e){if(!t){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}var mt="beforeunload",rn="hashchange",re="popstate";function oe(t){t===void 0&&(t={});var e=t,n=e.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var R=r.location,f=R.pathname,p=R.search,E=R.hash,b=o.state||{};return[b.idx,et({pathname:f,search:p,hash:E,state:b.usr||null,key:b.key||"default"})]}var s=null;function c(){if(s)d.call(s),s=null;else{var R=N.Pop,f=a(),p=f[0],E=f[1];if(d.length)if(p!=null){var b=m-p;b&&(s={action:R,location:E,retry:function(){S(b*-1)}},S(b))}else process.env.NODE_ENV!=="production"&&K(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else _(R)}}r.addEventListener(re,c);var u=N.Pop,h=a(),m=h[0],l=h[1],P=nt(),d=nt();m==null&&(m=0,o.replaceState(Q({},o.state,{idx:m}),""));function k(R){return typeof R=="string"?R:z(R)}function x(R,f){return f===void 0&&(f=null),et(Q({pathname:l.pathname,hash:"",search:""},typeof R=="string"?st(R):R,{state:f,key:Rt()}))}function $(R,f){return[{usr:R.state,key:R.key,idx:f},k(R)]}function H(R,f,p){return!d.length||(d.call({action:R,location:f,retry:p}),!1)}function _(R){u=R;var f=a();m=f[0],l=f[1],P.call({action:u,location:l})}function g(R,f){var p=N.Push,E=x(R,f);function b(){g(R,f)}if(H(p,E,b)){var B=$(E,m+1),U=B[0],C=B[1];try{o.pushState(U,"",C)}catch{r.location.assign(C)}_(p)}}function w(R,f){var p=N.Replace,E=x(R,f);function b(){w(R,f)}if(H(p,E,b)){var B=$(E,m),U=B[0],C=B[1];o.replaceState(U,"",C),_(p)}}function S(R){o.go(R)}var A={get action(){return u},get location(){return l},createHref:k,push:g,replace:w,go:S,back:function(){S(-1)},forward:function(){S(1)},listen:function(f){return P.push(f)},block:function(f){var p=d.push(f);return d.length===1&&r.addEventListener(mt,dt),function(){p(),d.length||r.removeEventListener(mt,dt)}}};return A}function on(t){t===void 0&&(t={});var e=t,n=e.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var f=st(r.location.hash.substr(1)),p=f.pathname,E=p===void 0?"/":p,b=f.search,B=b===void 0?"":b,U=f.hash,C=U===void 0?"":U,V=o.state||{};return[V.idx,et({pathname:E,search:B,hash:C,state:V.usr||null,key:V.key||"default"})]}var s=null;function c(){if(s)d.call(s),s=null;else{var f=N.Pop,p=a(),E=p[0],b=p[1];if(d.length)if(E!=null){var B=m-E;B&&(s={action:f,location:b,retry:function(){A(B*-1)}},A(B))}else process.env.NODE_ENV!=="production"&&K(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else g(f)}}r.addEventListener(re,c),r.addEventListener(rn,function(){var f=a(),p=f[1];z(p)!==z(l)&&c()});var u=N.Pop,h=a(),m=h[0],l=h[1],P=nt(),d=nt();m==null&&(m=0,o.replaceState(Q({},o.state,{idx:m}),""));function k(){var f=document.querySelector("base"),p="";if(f&&f.getAttribute("href")){var E=r.location.href,b=E.indexOf("#");p=b===-1?E:E.slice(0,b)}return p}function x(f){return k()+"#"+(typeof f=="string"?f:z(f))}function $(f,p){return p===void 0&&(p=null),et(Q({pathname:l.pathname,hash:"",search:""},typeof f=="string"?st(f):f,{state:p,key:Rt()}))}function H(f,p){return[{usr:f.state,key:f.key,idx:p},x(f)]}function _(f,p,E){return!d.length||(d.call({action:f,location:p,retry:E}),!1)}function g(f){u=f;var p=a();m=p[0],l=p[1],P.call({action:u,location:l})}function w(f,p){var E=N.Push,b=$(f,p);function B(){w(f,p)}if(process.env.NODE_ENV!=="production"&&K(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(f)+")"),_(E,b,B)){var U=H(b,m+1),C=U[0],V=U[1];try{o.pushState(C,"",V)}catch{r.location.assign(V)}g(E)}}function S(f,p){var E=N.Replace,b=$(f,p);function B(){S(f,p)}if(process.env.NODE_ENV!=="production"&&K(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(f)+")"),_(E,b,B)){var U=H(b,m),C=U[0],V=U[1];o.replaceState(C,"",V),g(E)}}function A(f){o.go(f)}var R={get action(){return u},get location(){return l},createHref:x,push:w,replace:S,go:A,back:function(){A(-1)},forward:function(){A(1)},listen:function(p){return P.push(p)},block:function(p){var E=d.push(p);return d.length===1&&r.addEventListener(mt,dt),function(){E(),d.length||r.removeEventListener(mt,dt)}}};return R}function ae(t){t===void 0&&(t={});var e=t,n=e.initialEntries,r=n===void 0?["/"]:n,o=e.initialIndex,a=r.map(function(g){var w=et(Q({pathname:"/",search:"",hash:"",state:null,key:Rt()},typeof g=="string"?st(g):g));return process.env.NODE_ENV!=="production"&&K(w.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(g)+")"),w}),s=se(o??a.length-1,0,a.length-1),c=N.Pop,u=a[s],h=nt(),m=nt();function l(g){return typeof g=="string"?g:z(g)}function P(g,w){return w===void 0&&(w=null),et(Q({pathname:u.pathname,search:"",hash:""},typeof g=="string"?st(g):g,{state:w,key:Rt()}))}function d(g,w,S){return!m.length||(m.call({action:g,location:w,retry:S}),!1)}function k(g,w){c=g,u=w,h.call({action:c,location:u})}function x(g,w){var S=N.Push,A=P(g,w);function R(){x(g,w)}process.env.NODE_ENV!=="production"&&K(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(g)+")"),d(S,A,R)&&(s+=1,a.splice(s,a.length,A),k(S,A))}function $(g,w){var S=N.Replace,A=P(g,w);function R(){$(g,w)}process.env.NODE_ENV!=="production"&&K(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(g)+")"),d(S,A,R)&&(a[s]=A,k(S,A))}function H(g){var w=se(s+g,0,a.length-1),S=N.Pop,A=a[w];function R(){H(g)}d(S,A,R)&&(s=w,k(S,A))}var _={get index(){return s},get action(){return c},get location(){return u},createHref:l,push:x,replace:$,go:H,back:function(){H(-1)},forward:function(){H(1)},listen:function(w){return h.push(w)},block:function(w){return m.push(w)}};return _}function se(t,e,n){return Math.min(Math.max(t,e),n)}function dt(t){t.preventDefault(),t.returnValue=""}function nt(){var t=[];return{get length(){return t.length},push:function(n){return t.push(n),function(){t=t.filter(function(r){return r!==n})}},call:function(n){t.forEach(function(r){return r&&r(n)})}}}function Rt(){return Math.random().toString(36).substr(2,8)}function z(t){var e=t.pathname,n=e===void 0?"/":e,r=t.search,o=r===void 0?"":r,a=t.hash,s=a===void 0?"":a;return o&&o!=="?"&&(n+=o.charAt(0)==="?"?o:"?"+o),s&&s!=="#"&&(n+=s.charAt(0)==="#"?s:"#"+s),n}function st(t){var e={};if(t){var n=t.indexOf("#");n>=0&&(e.hash=t.substr(n),t=t.substr(0,n));var r=t.indexOf("?");r>=0&&(e.search=t.substr(r),t=t.substr(0,r)),t&&(e.pathname=t)}return e}const At=Symbol();function ce(){const t=i.inject(At);if(!t)throw new it;return t}const ue=Symbol("isRouterRouteSymbol");function an(t){return typeof t=="object"&&t!==null&&ue in t}function sn(t,e){function n(m,l,P){if(typeof m=="object"){const k={...t.params,...m};return e(t.name,k,l)}const d={...t.params,[m]:l};return e(t.name,d,P)}const{matched:r,matches:o,name:a,query:s,params:c,state:u}=i.toRefs(t),h=i.reactive({matched:r,matches:o,state:u,query:s,params:c,name:a,update:n,[ue]:!0});return new Proxy(h,{get:(m,l,P)=>l==="params"?new Proxy(t.params,{set(d,k,x){return n(k,x),!0}}):l==="state"?new Proxy(t.state,{set(d,k,x){return n({},{state:{...t.state,[k]:x}}),!0}}):Reflect.get(m,l,P)})}function cn(t,e){const n=i.reactive({...t}),r=s=>{Object.assign(n,{...s})},o=n,a=sn(o,e);return{currentRoute:o,routerRoute:a,updateRoute:r}}function Y(t){return!t.startsWith("http")?fn(t):un(t)}function un(t){const{protocol:e,host:n,pathname:r,search:o,searchParams:a,hash:s}=new URL(t,t);return{protocol:e,host:n,pathname:r,search:o,searchParams:a,hash:s}}function fn(t){const{pathname:e,search:n,searchParams:r,hash:o}=new URL(t,"https://localhost");return{pathname:e,search:n,searchParams:r,hash:o}}function ln(t){return e=>{const{host:n}=Y(e);return!(n===void 0||n===t)}}function hn({mode:t,listener:e}){const n=pn(t),r=(u,h)=>{if(h!=null&&h.replace)return n.replace(u,h.state);n.push(u,h==null?void 0:h.state)},o=()=>{const u=z(n.location);return n.replace(u)};let a;return{...n,update:r,refresh:o,startListening:()=>{a==null||a(),a=n.listen(e)},stopListening:()=>{a==null||a()}}}function pn(t="auto"){switch(t){case"auto":return Kt()?oe():ae();case"browser":return oe();case"memory":return ae();case"hash":return on();default:const e=t;throw new Error(`Switch is not exhaustive for mode: ${e}`)}}class gt{constructor(){O(this,"onBeforeRouteEnter",new Set);O(this,"onBeforeRouteUpdate",new Set);O(this,"onBeforeRouteLeave",new Set);O(this,"onAfterRouteEnter",new Set);O(this,"onAfterRouteUpdate",new Set);O(this,"onAfterRouteLeave",new Set)}}class ie extends Error{}class ct extends Error{constructor(n){super("Error occurred during a router push operation.");O(this,"to");this.to=n}}class kt extends Error{constructor(n){super(`Routing action rejected: ${n}`);O(this,"type");this.type=n}}function mn(t,e){const n=new gt;return t.matches.forEach((r,o)=>{r.onBeforeRouteEnter&&xt(t,e,o)&&Z(r.onBeforeRouteEnter).forEach(a=>n.onBeforeRouteEnter.add(a)),r.onBeforeRouteUpdate&&Lt(t,e,o)&&Z(r.onBeforeRouteUpdate).forEach(a=>n.onBeforeRouteUpdate.add(a))}),e.matches.forEach((r,o)=>{r.onBeforeRouteLeave&&Bt(t,e,o)&&Z(r.onBeforeRouteLeave).forEach(a=>n.onBeforeRouteLeave.add(a))}),n}function dn(t,e){const n=new gt;return t.matches.forEach((r,o)=>{r.onAfterRouteEnter&&xt(t,e,o)&&Z(r.onAfterRouteEnter).forEach(a=>n.onAfterRouteEnter.add(a)),r.onAfterRouteUpdate&&Lt(t,e,o)&&Z(r.onAfterRouteUpdate).forEach(a=>n.onAfterRouteUpdate.add(a))}),e.matches.forEach((r,o)=>{r.onAfterRouteLeave&&Bt(t,e,o)&&Z(r.onAfterRouteLeave).forEach(a=>n.onAfterRouteLeave.add(a))}),n}function T(t){return typeof t!="string"?!1:/^(https?:\/\/|\/).*/g.test(t)}function Rn(){const t=s=>{throw new kt(s)},e=(...s)=>{throw new ct(s)},n=(s,c,u)=>{if(T(s)){const l=c??{};throw new ct([s,{...l,replace:!0}])}const h=c,m=u??{};throw new ct([s,h,{...m,replace:!0}])},r=()=>{throw new ie};async function o({to:s,from:c,hooks:u}){const{global:h,component:m}=u,l=mn(s,c),P=[...h.onBeforeRouteEnter,...l.onBeforeRouteEnter,...h.onBeforeRouteUpdate,...l.onBeforeRouteUpdate,...m.onBeforeRouteUpdate,...h.onBeforeRouteLeave,...l.onBeforeRouteLeave,...m.onBeforeRouteLeave];try{const d=P.map(k=>k(s,{from:c,reject:t,push:e,replace:n,abort:r}));await Promise.all(d)}catch(d){if(d instanceof ct)return{status:"PUSH",to:d.to};if(d instanceof kt)return{status:"REJECT",type:d.type};if(d instanceof ie)return{status:"ABORT"};throw d}return{status:"SUCCESS"}}async function a({to:s,from:c,hooks:u}){const{global:h,component:m}=u,l=dn(s,c),P=[...m.onAfterRouteLeave,...l.onAfterRouteLeave,...h.onAfterRouteLeave,...m.onAfterRouteUpdate,...l.onAfterRouteUpdate,...h.onAfterRouteUpdate,...m.onAfterRouteEnter,...l.onAfterRouteEnter,...h.onAfterRouteEnter];try{const d=P.map(k=>k(s,{from:c,reject:t,push:e,replace:n}));await Promise.all(d)}catch(d){if(d instanceof ct)return{status:"PUSH",to:d.to};if(d instanceof kt)return{status:"REJECT",type:d.type};throw d}return{status:"SUCCESS"}}return{runBeforeRouteHooks:o,runAfterRouteHooks:a}}const xt=(t,e,n)=>{const r=t.matches,o=(e==null?void 0:e.matches)??[];return r.length<n||r[n]!==o[n]},Bt=(t,e,n)=>{const r=t.matches,o=(e==null?void 0:e.matches)??[];return r.length<n||r[n]!==o[n]},Lt=(t,e,n)=>t.matches[n]===(e==null?void 0:e.matches[n]);function fe(t){switch(t){case"onBeforeRouteEnter":case"onAfterRouteEnter":return xt;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return Lt;case"onBeforeRouteLeave":case"onAfterRouteLeave":return Bt;default:throw new Error(`Switch is not exhaustive for lifecycle: ${t}`)}}class gn{constructor(){O(this,"global",new gt);O(this,"component",new gt)}addBeforeRouteHook({lifecycle:e,timing:n,depth:r,hook:o}){const a=fe(e),s=this[n][e],c=(u,h)=>{if(a(u,h.from,r))return o(u,h)};return s.add(c),()=>s.delete(c)}addAfterRouteHook({lifecycle:e,timing:n,depth:r,hook:o}){const a=fe(e),s=this[n][e],c=(u,h)=>{if(a(u,h.from,r))return o(u,h)};return s.add(c),()=>s.delete(c)}}const le=Symbol();function yn(){const t=new gn;return{onBeforeRouteEnter:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteEnter",hook:c,timing:"global",depth:0}),onBeforeRouteUpdate:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteUpdate",hook:c,timing:"global",depth:0}),onBeforeRouteLeave:c=>t.addBeforeRouteHook({lifecycle:"onBeforeRouteLeave",hook:c,timing:"global",depth:0}),onAfterRouteEnter:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteEnter",hook:c,timing:"global",depth:0}),onAfterRouteUpdate:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteUpdate",hook:c,timing:"global",depth:0}),onAfterRouteLeave:c=>t.addAfterRouteHook({lifecycle:"onAfterRouteLeave",hook:c,timing:"global",depth:0}),hooks:t}}function wn(t){return i.defineComponent(()=>()=>i.h("h1",t),{name:t,props:[]})}function he(t){const e=new URLSearchParams(t);return{get:n=>e.get(n),getAll:n=>e.getAll(n)}}const pe=Symbol();function vn({rejections:t}){const e=s=>{const c={...t};return i.markRaw(c[s]??wn(s))},n=s=>{const c=i.markRaw(e(s)),u={name:s,component:c,meta:{},state:{}};return{matched:u,matches:[u],name:s,query:he(""),params:{},state:{},[pe]:!0}},r=s=>pe in s,o=s=>{if(!s){a.value=null;return}const c=e(s);a.value={type:s,component:c}},a=i.ref(null);return{setRejection:o,rejection:a,getRejectionRoute:n,isRejectionRoute:r}}class En extends Error{constructor(e){super(`Route not found: "${e}"`)}}function Ut(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pn(t,e){const n=Array.from(t.matchAll(e));if(n.length===0)return[t];let r=0;const o=n.reduce((s,c)=>{const u=Ut(t.slice(r,c.index));u.length&&s.push(u);const[h]=c;return s.push(h),r=c.index+h.length,s},[]),a=t.slice(r);return a&&o.push(a),o}function bn(t){const e=me(t.path.toString());return new RegExp(`^${e}$`,"i")}function Sn(t){const e=new URLSearchParams(t.query.toString());return Array.from(e.entries()).filter(([,n])=>!Ct(n)).map(([n,r])=>{const o=me(r);return new RegExp(`${Ut(n)}=${o}(&|$)`,"i")})}function me(t){return Pn(t,new RegExp(An,"g")).map(e=>e.startsWith(W)?de(e):Ut(e)).join("")}function de(t){return[kn,xn].reduce((e,n)=>n(e),t)}const An=`\\${W}\\??([\\w-_]+)\\${J}`,Nt=`\\${W}\\?([\\w-_]+)\\${J}`,Re=`\\${W}([\\w-_]+)\\${J}`;function kn(t){return t.replace(new RegExp(Nt,"g"),".*")}function Ct(t){return new RegExp(Nt,"g").test(t)}function xn(t){return t.replace(new RegExp(Re,"g"),".+")}function yt(t){const[e]=wt(t,new RegExp(Nt,"g")),[n]=wt(t,new RegExp(Re,"g"));return e??n}function wt(t,e){return Array.from(t.matchAll(e)).flatMap(([,...r])=>r.map(o=>ht(o)?o:""))}function ge(t,e,n){const r=we(e,n),[o]=wt(t,r);return o}function ye(t,e){if(!e)return t;const{name:n,param:r,value:o}=e,a=we(t,n);return wt(t,a).reduce((c,u)=>u===void 0?c:c.replace(u,()=>at(o,r,n.startsWith("?"))),t)}function we(t,e){const n=[Bn,Ln,de].reduce((r,o)=>o(r,e),t);return new RegExp(n,"g")}function Bn(t,e){if(!e.startsWith("?"))return t;const n=new RegExp(`\\${W}\\${e}\\${J}`,"g");return t.replace(n,"(.*)")}function Ln(t,e){if(e.startsWith("?"))return t;const n=new RegExp(`\\${W}${e}\\${J}`,"g");return t.replace(n,"(.+)")}function ve(t,...e){return e.reduce((n,r)=>{if(!r)return n;const o=new URLSearchParams(r).toString();return Object.keys(o).length===0?n:n.includes("?")?`${n}&${o}`:`${n}?${o}`},t)}function Un(t,e={}){const{params:n={},query:r}=e,o=Nn(t.host,n),a=Cn(t.path,n),s=$n(t.query,n);return ve(`${o}${a}`,s,r)}function Nn(t,e){const n=t.toString();return Object.entries(t.params).reduce((r,[o,a])=>{const s=yt(`${W}${o}${J}`);return s?ye(r,{name:o,param:a,value:e[s]}):r},n)}function Cn(t,e){const n=t.toString();return Object.entries(t.params).reduce((r,[o,a])=>{const s=yt(`${W}${o}${J}`);return s?ye(r,{name:o,param:a,value:e[s]}):r},n)}function $n(t,e){const n=t.toString();if(!n)return{};const r=new URLSearchParams(n);return Array.from(r.entries()).reduce((o,[a,s])=>{const c=yt(s);if(!c)return{...o,[a]:s};const h=at(e[c],t.params[c],Ct(s)),m=e[c]===void 0&&h==="";return Ct(s)&&m?o:{...o,[a]:h}},{})}function jn(t){return(e,n,r)=>{if(T(e))return ve(e,(n??{}).query);const o=n??{},a=r??{},s=t.find(u=>u.name===e);if(!s)throw new En(String(e));return Un(s,{params:o,query:a.query})}}class Hn extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function Vn(t){if(t)return t;if(Kt())return window.location.toString();throw new Hn}const On=(t,e)=>{try{Ee(t,e)}catch{return!1}return!0},Ee=(t,e)=>{const{pathname:n,search:r}=Y(e);return{..._n(t.path,n),...qn(t.query,r)}};function _n(t,e){const n={},r=decodeURIComponent(e);for(const[o,a]of Object.entries(t.params)){const s=o.startsWith("?"),c=s?o.slice(1):o,u=ge(r,t.toString(),o),h=ot(u,a,s);n[c]=h}return n}function qn(t,e){const n={},r=new URLSearchParams(e);for(const[o,a]of Object.entries(t.params)){const s=o.startsWith("?"),c=s?o.slice(1):o,u=r.get(c)??void 0,h=ot(u,a,s);n[c]=h}return n}const Dn=t=>"name"in t.matched&&!!t.matched.name,Wn=(t,e)=>{const{pathname:n}=Y(e);return bn(t).test(n)},Tn=(t,e)=>{const{search:n}=Y(e);return Sn(t).every(o=>o.test(n))};function Mn(t){const{searchParams:e,pathname:n}=Y(t),r=-1,o=1;return(a,s)=>{const c=be(a,e),u=Pe(a,n),h=be(s,e),m=Pe(s,n);return a.depth>s.depth?r:a.depth<s.depth?o:c+u>h+m?r:c+u<h+m?o:0}}function Pe(t,e){const n=Object.keys(t.path.params).filter(o=>o.startsWith("?")).map(o=>o),r=n.filter(o=>ge(e,t.path.toString(),o)===void 0);return n.length-r.length}function be(t,e){const n=new URLSearchParams(t.query.toString()),r=Array.from(n.keys()),o=r.filter(a=>!e.has(a));return r.length-o.length}function Se(t){return!!t&&typeof t=="object"}const vt=!0;function In(t,e,n){if(Se(t)&&e in t){const r=t[e];if(typeof r=="string")return ot(r,n,vt)}return ot(void 0,n,vt)}function Fn(t,e){const n={};for(const[r,o]of Object.entries(t)){const a=In(e,r,o);n[r]=a}return n}function Jn(t,e,n){if(Se(t)&&e in t){const r=t[e];return at(r,n,vt)}return at(void 0,n,vt)}const Ae=(t,e)=>{const n={};for(const[r,o]of Object.entries(t)){const a=Jn(e,r,o);n[r]=a}return n},Qn=[Dn,Wn,Tn,On];function $t(t,e,n){const r=Mn(e),o=t.filter(c=>Qn.every(u=>u(c,e))).sort(r);if(o.length===0)return;const[a]=o,{search:s}=Y(e);return{matched:a.matched,matches:a.matches,name:a.name,query:he(s),params:Ee(a,e),state:Fn(a.state,n)}}function jt(t,e){const n=new RegExp(`\\${W}(\\??[\\w-_]+)\\${J}`,"g");return Array.from(t.matchAll(n)).reduce((o,[a,s])=>{const c=yt(a);if(!c)return o;const u=en(e,c);return tt([c],o),o[s]=u,o},{})}function ke(t,e){return{host:t,params:jt(t,e),toString:()=>t}}function Ht(t){return t===void 0?"":t}function Vt(t,e){return{path:t,params:jt(t,e),toString:()=>t}}function Gn(t){return lt(t)&&typeof t.path=="string"}function xe(t){return t===void 0?Vt("",{}):Gn(t)?t:Vt(t,{})}function Ot(t,e){return{query:t,params:jt(t,e),toString:()=>t}}function Kn(t){return lt(t)&&typeof t.query=="string"}function Be(t){return t===void 0?Ot("",{}):Kn(t)?t:Ot(t,{})}function M(t){const e=Ht(t.name),n=xe(t.path),r=Be(t.query),o=t.meta??{},a=ze(t)?t.state:{},s=i.markRaw({meta:{},state:{},...t}),c={matched:s,matches:[s],name:e,path:n,query:r,meta:o,state:a,depth:1,host:ke("",{}),prefetch:t.prefetch},u=Qt(t)?Gt(t.parent,c):c;return tt(u.path.params,u.query.params),u}function zn(t,e){if(!ht(e))return t;const n=M({path:e});return t.map(r=>M({parent:n,...r}))}class Yn extends Error{constructor(e){super(`Invalid Name "${e}": Router does not support multiple routes with the same name. All name names must be unique.`)}}function Xn(t){const e=t.map(({name:n})=>n);for(const n of e)if(Jt(e,n)>1)throw new Yn(n)}function Zn(t,e={}){const n=Je(t)?t.flat():t,r=zn(n,e.base);Xn(r);const o=jn(r),a=hn({mode:e.historyMode,listener:({location:v})=>{const L=z(v);x(L,{state:v.state})}}),{runBeforeRouteHooks:s,runAfterRouteHooks:c}=Rn(),{hooks:u,onBeforeRouteEnter:h,onAfterRouteUpdate:m,onBeforeRouteLeave:l,onAfterRouteEnter:P,onBeforeRouteUpdate:d,onAfterRouteLeave:k}=yn();async function x(v,L={}){if(a.stopListening(),C(v))return a.update(v,L);const q=$t(r,v,L.state)??A("NotFound"),D={...f},rt=await s({to:q,from:D,hooks:u});switch(rt.status){case"ABORT":return;case"PUSH":a.update(v,L),await $(...rt.to);return;case"REJECT":a.update(v,L),w(rt.type),E(q);break;case"SUCCESS":a.update(v,L),w(null),E(q);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(rt)}`)}const G=await c({to:q,from:D,hooks:u});switch(G.status){case"PUSH":await $(...G.to);break;case"REJECT":w(G.type);break;case"SUCCESS":break;default:const I=G;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(I)}`)}a.startListening()}const $=(v,L,q)=>{if(T(v)){const ut={...L},It=o(v,ut);return x(It,ut)}const D={...q},G=o(v,L??{},D),I=Tt(v),Mt=Ae((I==null?void 0:I.state)??{},D.state);return x(G,{...D,state:Mt})},H=(v,L,q)=>{if(T(v)){const ut={...L,replace:!0},It=o(v,ut);return x(It,ut)}const D={...q,replace:!0},G=o(v,L??{},D),I=Tt(v),Mt=Ae((I==null?void 0:I.state)??{},D.state);return x(G,{...D,state:Mt})},_=v=>w(v),g=(v,L={})=>{if(!T(v)){const q=o(v,L);return $t(r,q)}if(!C(v))return $t(r,v)},{setRejection:w,rejection:S,getRejectionRoute:A}=vn(e),R=A("NotFound"),{currentRoute:f,routerRoute:p,updateRoute:E}=cn(R,$);a.startListening();const b=Vn(e.initialUrl),B=a.location.state,{host:U}=Y(b),C=ln(U),V=x(b,{replace:!0,state:B});function Tt(v){return r.find(L=>L.name===v)}function mr(v){v.component("RouterView",_e),v.component("RouterLink",Oe),v.provide(At,S),v.provide(le,u),v.provide(Pt,De)}const De={route:p,resolve:o,push:$,replace:H,reject:_,find:g,refresh:a.refresh,forward:a.forward,back:a.back,go:a.go,install:mr,initialized:V,isExternal:C,onBeforeRouteEnter:h,onAfterRouteUpdate:m,onBeforeRouteLeave:l,onAfterRouteEnter:P,onBeforeRouteUpdate:d,onAfterRouteLeave:k,prefetch:e.prefetch};return De}const Et={template:"<div>This is component</div>"},_t=M({name:"parentA",path:"/parentA/[paramA]"}),Le=M({parent:_t,name:"parentA.childA",path:"/[?paramB]"}),tr=M({parent:_t,name:"parentA.childB",path:"/[paramD]",component:Et}),er=M({parent:Le,name:"parentA.childA.grandChildA",path:"/[paramC]",component:Et});M({name:"parentB",path:"/parentB",component:Et}),M({name:"parentC",path:"/",component:Et});const nr={components:!0};function rr({routerPrefetch:t,routePrefetch:e,linkPrefetch:n},r){return qt(n,r)??qt(e,r)??qt(t,r)??nr[r]}function qt(t,e){return lt(t)?t[e]:t}const or=i.defineAsyncComponent(()=>new Promise(t=>{t({default:{template:""}})}));function Ue(t){return t.name===or.name&&"setup"in t}function Ne(t,e={},n={}){const r=ft(),o=i.toRef(t),a=i.computed(()=>T(o.value)?{}:i.toValue(e)),s=i.computed(()=>T(o.value)?i.toValue(e):i.toValue(n)),c=i.computed(()=>{if(T(o.value))return o.value;try{return r.resolve(o.value,a.value,s.value)}catch(l){throw l instanceof X&&console.error(`Failed to resolve route "${o.value.toString()}" in RouterLink.`,l),l}}),u=i.computed(()=>r.find(c.value,s.value)),h=i.computed(()=>!!u.value&&r.route.matches.includes(u.value.matched)),m=i.computed(()=>!!u.value&&r.route.matched===u.value.matched);return i.watch(u,l=>{if(!l)return;const{prefetch:P}=r,{prefetch:d}=s.value;ar(l,{routerPrefetch:P,linkPrefetch:d})},{immediate:!0}),{route:u,href:c,isMatch:h,isExactMatch:m,push:l=>r.push(c.value,{},{...s.value,...l}),replace:l=>r.replace(c.value,{},{...s.value,...l})}}function ar(t,{routerPrefetch:e,linkPrefetch:n}){t.matches.forEach(r=>{rr({routePrefetch:r.prefetch,routerPrefetch:e,linkPrefetch:n},"components")&&(bt(r)&&Ue(r.component)&&r.component.setup(),St(r)&&Object.values(r.components).forEach(a=>{Ue(a)&&a.setup()}))})}function Ce(t,e,{exact:n}={}){if(!an(t))return!1;if(e===void 0)return!0;const r=t.matches.map(o=>Ht(o.name));if(n){const o=r.at(-1);return e===o}return r.includes(e)}function $e(t,e){const n=ft();function r(){if(!t)return;if(!Ce(n.route,t,e))throw new Ft(t,n.route.name)}return i.watch(n.route,r,{immediate:!0,deep:!0}),n.route}const je=Symbol();function Dt(){return i.inject(je,0)}function He(){const t=i.inject(le);if(!t)throw new it;return t}function Ve(t){return e=>{const n=Dt(),o=He().addBeforeRouteHook({lifecycle:t,hook:e,depth:n,timing:"component"});return i.onUnmounted(o),o}}function Wt(t){return e=>{const n=Dt(),o=He().addAfterRouteHook({lifecycle:t,hook:e,depth:n,timing:"component"});return i.onUnmounted(o),o}}const sr=Ve("onBeforeRouteUpdate"),cr=Ve("onBeforeRouteLeave"),ur=Wt("onAfterRouteEnter"),ir=Wt("onAfterRouteUpdate"),fr=Wt("onAfterRouteLeave"),lr=["href"],Oe=i.defineComponent({__name:"routerLink",props:{to:{},prefetch:{type:[Boolean,Object],default:void 0},query:{},replace:{type:Boolean},state:{}},setup(t){const e=t,n=ft(),r=i.computed(()=>T(e.to)?e.to:e.to(n.resolve)),o=i.computed(()=>{const{to:l,...P}=e;return P}),{href:a,isMatch:s,isExactMatch:c}=Ne(r,o),u=i.computed(()=>({"router-link--match":s.value,"router-link--exact-match":c.value})),h=i.computed(()=>n.isExternal(r.value));function m(l){l.preventDefault(),n.push(a.value,o.value)}return(l,P)=>(i.openBlock(),i.createElementBlock("a",{href:r.value,class:i.normalizeClass(["router-link",u.value]),onClick:m},[i.renderSlot(l.$slots,"default",i.normalizeProps(i.guardReactiveProps({resolved:r.value,isMatch:i.unref(s),isExactMatch:i.unref(c),isExternal:h.value})))],10,lr))}}),_e=i.defineComponent({__name:"routerView",props:{name:{}},setup(t){const{name:e="default"}=t,n=$e(),r=ce(),o=Dt(),a=i.resolveComponent("RouterView",!0);i.provide(je,o+1);const s=i.computed(()=>{if(r.value)return r.value.component;const l=n.matches.at(o);if(!l)return null;const P=c(l),d=h(l);return P?d?zt(P,()=>d(n.params)):P:null});function c(l){return u(l)[e]}function u(l){return St(l)?l.components:bt(l)?{default:l.component}:typeof a=="string"?{}:{default:a}}function h(l){return m(l)[e]}function m(l){return St(l)?l.props??{}:bt(l)?{default:l.props}:{}}return(l,P)=>s.value?i.renderSlot(l.$slots,"default",i.normalizeProps(i.mergeProps({key:0},{route:i.unref(n),component:s.value,rejection:i.unref(r)})),()=>[(i.openBlock(),i.createBlock(i.resolveDynamicComponent(s.value)))]):i.createCommentVNode("",!0)}});function hr(t){return lt(t)&&typeof t.host=="string"}function qe(t){return hr(t)?t:ke(t,{})}function pr(t){const e=Ht(t.name),n=xe(t.path),r=Be(t.query),o=t.meta??{},a=Ke(t)?qe(t.host):qe(""),s=i.markRaw({meta:{},state:{},...t}),c={matched:s,matches:[s],name:e,host:a,path:n,query:r,meta:o,depth:1,state:{}},u=Qt(t)?Gt(t.parent,c):c;return tt(u.path.params,u.query.params,u.host.params),u}y.DuplicateParamsError=F,y.RouterLink=Oe,y.RouterNotInstalledError=it,y.RouterView=_e,y.UseRouteInvalidError=Ft,y.component=zt,y.createExternalRoute=pr,y.createParam=ne,y.createRoute=M,y.createRouter=Zn,y.isParamWithDefault=Yt,y.isRoute=Ce,y.onAfterRouteEnter=ur,y.onAfterRouteLeave=ir,y.onAfterRouteUpdate=fr,y.onBeforeRouteLeave=sr,y.onBeforeRouteUpdate=cr,y.path=Vt,y.query=Ot,y.routerInjectionKey=Pt,y.routerRejectionKey=At,y.useLink=Ne,y.useRejection=ce,y.useRoute=$e,y.useRouter=ft,y.withDefault=tn,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kitbag/router",
3
3
  "private": false,
4
- "version": "0.7.2",
4
+ "version": "0.8.0",
5
5
  "bugs": {
6
6
  "url": "https://github.com/kitbagjs/router/issues"
7
7
  },