@kitbag/router 0.13.1 → 0.13.2

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