@kitbag/router 0.10.0 → 0.11.0

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