@kitbag/router 0.11.2 → 0.11.3

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