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