@kitbag/router 0.15.3 → 0.16.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.
- package/dist/kitbag-router.d.ts +70 -58
- package/dist/kitbag-router.js +606 -600
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(A=typeof globalThis<"u"?globalThis:A||self,c(A["@kitbag/router"]={},A.Vue))})(this,function(A,c){"use strict";var Wn=Object.defineProperty;var Jn=(A,c,N)=>c in A?Wn(A,c,{enumerable:!0,configurable:!0,writable:!0,value:N}):A[c]=N;var F=(A,c,N)=>Jn(A,typeof c!="symbol"?c+"":c,N);function N(e){return typeof e!="string"?!1:/^(https?:\/\/|\/).*/g.test(e)}function xe(e){return N(e)?e:`/${e}`}class Ye extends Error{constructor(t){super(`Invalid Param "${t}": Router does not support multiple params by the same name. All param names must be unique.`)}}class Xe extends Error{constructor(t){super(`Child property on meta for ${t} conflicts with the parent meta.`)}}class te extends Error{constructor(){super("Router not installed")}}class Ze extends Error{constructor(t,r){super(`useRoute called with incorrect route. Given ${t}, expected ${r}`)}}const et=Symbol();function ye(){const e=c.inject(et);if(!e)throw new te;return e}function ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return typeof e=="string"&&e.length>0}function ge(e){return{value:W(e)?e.replace(/^#*/,""):void 0}}function or(e,t){return ge(`${e.value??""}${t.value??""}`)}function ar(e,t){return sr(e,t),{...e,...t}}function sr(e,t){const r=Object.keys(e).find(n=>n in t&&typeof t[n]!=typeof e[n]);if(r)throw new Xe(r)}function re(e){return Array.isArray(e)?e:[e]}function tt(e,t){return e.filter(r=>t===r).length}function ne(...e){const t=e.flatMap(r=>Array.isArray(r)?r:Object.keys(r).map(cr));for(const r of t)if(tt(t,r)>1)throw new Ye(r)}function cr(e){return e.startsWith("?")?e.slice(1):e}function ur(e,t){return ne(e.params,t.params),{value:`${e.value}${t.value}`,params:{...e.params,...t.params}}}function ir(e,t){return ne(e.params,t.params),{value:[e.value,t.value].filter(W).join("&"),params:{...e.params,...t.params}}}function fr(e,t){return ne(e,t),{...e,...t}}function lr(e){return"host"in e&&!!e.host}function rt(e){return"parent"in e&&!!e.parent}function Be(e){return"component"in e&&!!e.component}function Ce(e){return"components"in e&&!!e.components}function hr(e){return"state"in e&&!!e.state}function nt(e,t){return{...t,path:ur(e.path,t.path),query:ir(e.query,t.query),meta:ar(e.meta,t.meta),state:fr(e.state,t.state),hash:or(e.hash,t.hash),matches:[...e.matches,t.matched],host:e.host,depth:e.depth+1}}function Ve(){return typeof window<"u"&&typeof window.document<"u"}class ie extends Error{}const J="[",Q="]";function dr(e){return e!==String&&e!==Boolean&&e!==Number&&e!==Date}function pr(e){return typeof e=="function"&&dr(e)}function we(e){return typeof e=="object"&&"get"in e&&typeof e.get=="function"&&"set"in e&&typeof e.set=="function"}function mr(e){return we(e)&&e.defaultValue!==void 0}function Rr(e,t){return ut(e,t)}function yr(e,t){return e[t]??String}const $={invalid:e=>{throw new ie(e)}},gr={get:e=>e,set:(e,{invalid:t})=>{if(typeof e!="string")throw t();return e}},ot={get:(e,{invalid:t})=>{if(e==="true")return!0;if(e==="false")return!1;throw t()},set:(e,{invalid:t})=>{if(typeof e!="boolean")throw t();return e.toString()}},at={get:(e,{invalid:t})=>{const r=Number(e);if(isNaN(r))throw t();return r},set:(e,{invalid:t})=>{if(typeof e!="number")throw t();return e.toString()}},st={get:(e,{invalid:t})=>{const r=new Date(e);if(isNaN(r.getTime()))throw t();return r},set:(e,{invalid:t})=>{if(typeof e!="object"||!(e instanceof Date))throw t();return e.toISOString()}},ct={get:(e,{invalid:t})=>{try{return JSON.parse(e)}catch{throw t()}},set:(e,{invalid:t})=>{try{return JSON.stringify(e)}catch{throw t()}}};function fe(e,t,r=!1){if(e===void 0||!W(e)){if(mr(t))return t.defaultValue;if(r)return;throw new ie}if(t===String)return gr.get(e,$);if(t===Boolean)return ot.get(e,$);if(t===Number)return at.get(e,$);if(t===Date)return st.get(e,$);if(t===JSON)return ct.get(e,$);if(pr(t))return t(e,$);if(we(t))return t.get(e,$);if(t instanceof RegExp){if(t.test(e))return e;throw new ie}return e}function le(e,t,r=!1){if(e===void 0){if(r)return"";throw new ie}if(t===Boolean)return ot.set(e,$);if(t===Number)return at.set(e,$);if(t===Date)return st.set(e,$);if(t===JSON)return ct.set(e,$);if(we(t))return t.set(e,$);try{return e.toString()}catch{throw new ie}}function ut(e,t){return we(e)?{...e,defaultValue:t??e.defaultValue}:{get:r=>fe(r,e),set:r=>le(r,e),defaultValue:t}}function z(){return z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},z.apply(null,arguments)}var H;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(H||(H={}));var oe=process.env.NODE_ENV!=="production"?function(e){return Object.freeze(e)}:function(e){return e};function Y(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}var ve="beforeunload",wr="hashchange",it="popstate";function ft(e){e===void 0&&(e={});var t=e,r=t.window,n=r===void 0?document.defaultView:r,o=n.history;function a(){var p=n.location,d=p.pathname,v=p.search,x=p.hash,B=o.state||{};return[B.idx,oe({pathname:d,search:v,hash:x,state:B.usr||null,key:B.key||"default"})]}var s=null;function l(){if(s)b.call(s),s=null;else{var p=H.Pop,d=a(),v=d[0],x=d[1];if(b.length)if(v!=null){var B=h-v;B&&(s={action:p,location:x,retry:function(){k(B*-1)}},k(B))}else process.env.NODE_ENV!=="production"&&Y(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else U(p)}}n.addEventListener(it,l);var i=H.Pop,u=a(),h=u[0],g=u[1],P=ae(),b=ae();h==null&&(h=0,o.replaceState(z({},o.state,{idx:h}),""));function R(p){return typeof p=="string"?p:X(p)}function w(p,d){return d===void 0&&(d=null),oe(z({pathname:g.pathname,hash:"",search:""},typeof p=="string"?he(p):p,{state:d,key:Pe()}))}function f(p,d){return[{usr:p.state,key:p.key,idx:d},R(p)]}function m(p,d,v){return!b.length||(b.call({action:p,location:d,retry:v}),!1)}function U(p){i=p;var d=a();h=d[0],g=d[1],P.call({action:i,location:g})}function y(p,d){var v=H.Push,x=w(p,d);function B(){y(p,d)}if(m(v,x,B)){var V=f(x,h+1),j=V[0],_=V[1];try{o.pushState(j,"",_)}catch{n.location.assign(_)}U(v)}}function E(p,d){var v=H.Replace,x=w(p,d);function B(){E(p,d)}if(m(v,x,B)){var V=f(x,h),j=V[0],_=V[1];o.replaceState(j,"",_),U(v)}}function k(p){o.go(p)}var L={get action(){return i},get location(){return g},createHref:R,push:y,replace:E,go:k,back:function(){k(-1)},forward:function(){k(1)},listen:function(d){return P.push(d)},block:function(d){var v=b.push(d);return b.length===1&&n.addEventListener(ve,Ee),function(){v(),b.length||n.removeEventListener(ve,Ee)}}};return L}function vr(e){e===void 0&&(e={});var t=e,r=t.window,n=r===void 0?document.defaultView:r,o=n.history;function a(){var d=he(n.location.hash.substr(1)),v=d.pathname,x=v===void 0?"/":v,B=d.search,V=B===void 0?"":B,j=d.hash,_=j===void 0?"":j,O=o.state||{};return[O.idx,oe({pathname:x,search:V,hash:_,state:O.usr||null,key:O.key||"default"})]}var s=null;function l(){if(s)b.call(s),s=null;else{var d=H.Pop,v=a(),x=v[0],B=v[1];if(b.length)if(x!=null){var V=h-x;V&&(s={action:d,location:B,retry:function(){L(V*-1)}},L(V))}else process.env.NODE_ENV!=="production"&&Y(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else y(d)}}n.addEventListener(it,l),n.addEventListener(wr,function(){var d=a(),v=d[1];X(v)!==X(g)&&l()});var i=H.Pop,u=a(),h=u[0],g=u[1],P=ae(),b=ae();h==null&&(h=0,o.replaceState(z({},o.state,{idx:h}),""));function R(){var d=document.querySelector("base"),v="";if(d&&d.getAttribute("href")){var x=n.location.href,B=x.indexOf("#");v=B===-1?x:x.slice(0,B)}return v}function w(d){return R()+"#"+(typeof d=="string"?d:X(d))}function f(d,v){return v===void 0&&(v=null),oe(z({pathname:g.pathname,hash:"",search:""},typeof d=="string"?he(d):d,{state:v,key:Pe()}))}function m(d,v){return[{usr:d.state,key:d.key,idx:v},w(d)]}function U(d,v,x){return!b.length||(b.call({action:d,location:v,retry:x}),!1)}function y(d){i=d;var v=a();h=v[0],g=v[1],P.call({action:i,location:g})}function E(d,v){var x=H.Push,B=f(d,v);function V(){E(d,v)}if(process.env.NODE_ENV!=="production"&&Y(B.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(d)+")"),U(x,B,V)){var j=m(B,h+1),_=j[0],O=j[1];try{o.pushState(_,"",O)}catch{n.location.assign(O)}y(x)}}function k(d,v){var x=H.Replace,B=f(d,v);function V(){k(d,v)}if(process.env.NODE_ENV!=="production"&&Y(B.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(d)+")"),U(x,B,V)){var j=m(B,h),_=j[0],O=j[1];o.replaceState(_,"",O),y(x)}}function L(d){o.go(d)}var p={get action(){return i},get location(){return g},createHref:w,push:E,replace:k,go:L,back:function(){L(-1)},forward:function(){L(1)},listen:function(v){return P.push(v)},block:function(v){var x=b.push(v);return b.length===1&&n.addEventListener(ve,Ee),function(){x(),b.length||n.removeEventListener(ve,Ee)}}};return p}function lt(e){e===void 0&&(e={});var t=e,r=t.initialEntries,n=r===void 0?["/"]:r,o=t.initialIndex,a=n.map(function(y){var E=oe(z({pathname:"/",search:"",hash:"",state:null,key:Pe()},typeof y=="string"?he(y):y));return process.env.NODE_ENV!=="production"&&Y(E.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(y)+")"),E}),s=ht(o??a.length-1,0,a.length-1),l=H.Pop,i=a[s],u=ae(),h=ae();function g(y){return typeof y=="string"?y:X(y)}function P(y,E){return E===void 0&&(E=null),oe(z({pathname:i.pathname,search:"",hash:""},typeof y=="string"?he(y):y,{state:E,key:Pe()}))}function b(y,E,k){return!h.length||(h.call({action:y,location:E,retry:k}),!1)}function R(y,E){l=y,i=E,u.call({action:l,location:i})}function w(y,E){var k=H.Push,L=P(y,E);function p(){w(y,E)}process.env.NODE_ENV!=="production"&&Y(i.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(y)+")"),b(k,L,p)&&(s+=1,a.splice(s,a.length,L),R(k,L))}function f(y,E){var k=H.Replace,L=P(y,E);function p(){f(y,E)}process.env.NODE_ENV!=="production"&&Y(i.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(y)+")"),b(k,L,p)&&(a[s]=L,R(k,L))}function m(y){var E=ht(s+y,0,a.length-1),k=H.Pop,L=a[E];function p(){m(y)}b(k,L,p)&&(s=E,R(k,L))}var U={get index(){return s},get action(){return l},get location(){return i},createHref:g,push:w,replace:f,go:m,back:function(){m(-1)},forward:function(){m(1)},listen:function(E){return u.push(E)},block:function(E){return h.push(E)}};return U}function ht(e,t,r){return Math.min(Math.max(e,t),r)}function Ee(e){e.preventDefault(),e.returnValue=""}function ae(){var e=[];return{get length(){return e.length},push:function(r){return e.push(r),function(){e=e.filter(function(n){return n!==r})}},call:function(r){e.forEach(function(n){return n&&n(r)})}}}function Pe(){return Math.random().toString(36).substr(2,8)}function X(e){var t=e.pathname,r=t===void 0?"/":t,n=e.search,o=n===void 0?"":n,a=e.hash,s=a===void 0?"":a;return o&&o!=="?"&&(r+=o.charAt(0)==="?"?o:"?"+o),s&&s!=="#"&&(r+=s.charAt(0)==="#"?s:"#"+s),r}function he(e){var t={};if(e){var r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));var n=e.indexOf("?");n>=0&&(t.search=e.substr(n),e=e.substr(0,n)),e&&(t.pathname=e)}return t}const dt=Symbol();function Er(){const e=c.inject(dt);if(!e)throw new te;return e}const pt=Symbol("isRouterRouteSymbol");function Pr(e){return typeof e=="object"&&e!==null&&pt in e}function br(e,t){function r(f,m,U){if(typeof f=="object"){const E={...e.params,...f};return t(e.name,E,m)}const y={...e.params,[f]:m};return t(e.name,y,U)}const n=(...f)=>{const m=new URLSearchParams(e.query);m.set(...f),r({},{query:m})},o=(...f)=>{const m=new URLSearchParams(e.query);m.append(...f),r({},{query:m})},a=(...f)=>{const m=new URLSearchParams(e.query);m.delete(...f),r({},{query:m})},{id:s,matched:l,matches:i,name:u,hash:h,href:g}=c.toRefs(e),P=c.computed({get(){return new Proxy(e.params,{set(f,m,U){return r(m,U),!0}})},set(f){r(f)}}),b=c.computed({get(){return new Proxy(e.query,{get(f,m,U){switch(m){case"append":return o;case"set":return n;case"delete":return a;default:return Reflect.get(f,m,U)}}})},set(f){r({},{query:f})}}),R=c.computed({get(){return new Proxy(e.state,{set(f,m,U){return r({},{state:{...e.state,[m]:U}}),!0}})},set(f){r({},{state:f})}});return c.reactive({id:s,matched:l,matches:i,state:R,query:b,hash:h,params:P,name:u,href:g,update:r,[pt]:!0})}const mt=Symbol();function Sr(e,t){const r=c.reactive({...e}),n=s=>{Object.assign(r,{[mt]:!1,...s})},o=r,a=br(o,t);return{currentRoute:o,routerRoute:a,updateRoute:n}}function q(e){return!e.startsWith("http")?kr(e):Ar(e)}function Ar(e){const{protocol:t,host:r,pathname:n,search:o,searchParams:a,hash:s}=new URL(e,e);return{protocol:t,host:r,pathname:n,search:o,searchParams:a,hash:s}}function kr(e){const{pathname:t,search:r,searchParams:n,hash:o}=new URL(e,"https://localhost");return{pathname:t,search:r,searchParams:n,hash:o}}function Ur(e){return t=>{const{host:r}=q(t);return!(r===void 0||r===e)}}function Lr({mode:e,listener:t}){const r=xr(e),n=(i,u)=>{if(u!=null&&u.replace){r.replace(i,u.state);return}r.push(i,u==null?void 0:u.state)},o=()=>{const i=X(r.location);r.replace(i)};let a;return{...r,update:n,refresh:o,startListening:()=>{a==null||a(),a=r.listen(t)},stopListening:()=>{a==null||a()}}}function xr(e="auto"){switch(e){case"auto":return Ve()?ft():lt();case"browser":return ft();case"memory":return lt();case"hash":return vr();default:const t=e;throw new Error(`Switch is not exhaustive for mode: ${t}`)}}class Rt extends Error{constructor(){super("Uncaught CallbackContextAbortError");F(this,"response");this.response={status:"ABORT"}}}class se extends Error{constructor(r){super("Uncaught CallbackContextPushError");F(this,"response");this.response={status:"PUSH",to:r}}}class be extends Error{constructor(r){super("Uncaught CallbackContextRejectionError");F(this,"response");this.response={status:"REJECT",type:r}}}function yt(){return{reject:o=>{throw new be(o)},push:(...o)=>{throw new se(o)},replace:(o,a,s)=>{if(N(o)){const u=a??{};throw new se([o,{...u,replace:!0}])}const l=a,i=s??{};throw new se([o,l,{...i,replace:!0}])},abort:()=>{throw new Rt}}}class Z{constructor(){F(this,"onBeforeRouteEnter",new Set);F(this,"onBeforeRouteUpdate",new Set);F(this,"onBeforeRouteLeave",new Set);F(this,"onAfterRouteEnter",new Set);F(this,"onAfterRouteUpdate",new Set);F(this,"onAfterRouteLeave",new Set)}}const de=(e,t,r)=>{var a,s;const n=e.matches,o=(t==null?void 0:t.matches)??[];return((a=n.at(r))==null?void 0:a.id)!==((s=o.at(r))==null?void 0:s.id)},pe=(e,t,r)=>{var a,s;const n=e.matches,o=(t==null?void 0:t.matches)??[];return((a=n.at(r))==null?void 0:a.id)!==((s=o.at(r))==null?void 0:s.id)},me=(e,t,r)=>{var n,o;return((n=e.matches.at(r))==null?void 0:n.id)===((o=t==null?void 0:t.matches.at(r))==null?void 0:o.id)};function gt(e){switch(e){case"onBeforeRouteEnter":case"onAfterRouteEnter":return de;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return me;case"onBeforeRouteLeave":case"onAfterRouteLeave":return pe;default:throw new Error(`Switch is not exhaustive for lifecycle: ${e}`)}}function Br(e,t){const r=new Z;return e.matches.forEach((n,o)=>{n.onBeforeRouteEnter&&de(e,t,o)&&re(n.onBeforeRouteEnter).forEach(a=>r.onBeforeRouteEnter.add(a)),n.onBeforeRouteUpdate&&me(e,t,o)&&re(n.onBeforeRouteUpdate).forEach(a=>r.onBeforeRouteUpdate.add(a))}),t==null||t.matches.forEach((n,o)=>{n.onBeforeRouteLeave&&pe(e,t,o)&&re(n.onBeforeRouteLeave).forEach(a=>r.onBeforeRouteLeave.add(a))}),r}function Cr(e,t){const r=new Z;return e.matches.forEach((n,o)=>{n.onAfterRouteEnter&&de(e,t,o)&&re(n.onAfterRouteEnter).forEach(a=>r.onAfterRouteEnter.add(a)),n.onAfterRouteUpdate&&me(e,t,o)&&re(n.onAfterRouteUpdate).forEach(a=>r.onAfterRouteUpdate.add(a))}),t==null||t.matches.forEach((n,o)=>{n.onAfterRouteLeave&&pe(e,t,o)&&re(n.onAfterRouteLeave).forEach(a=>r.onAfterRouteLeave.add(a))}),r}function Vr(e,t,r){const n=new Z;return e.matches.forEach((o,a)=>{de(e,t,a)&&r.onBeforeRouteEnter.forEach(s=>n.onBeforeRouteEnter.add(s)),me(e,t,a)&&r.onBeforeRouteUpdate.forEach(s=>n.onBeforeRouteUpdate.add(s))}),t==null||t.matches.forEach((o,a)=>{pe(e,t,a)&&r.onBeforeRouteLeave.forEach(s=>n.onBeforeRouteLeave.add(s))}),n}function Nr(e,t,r){const n=new Z;return e.matches.forEach((o,a)=>{de(e,t,a)&&r.onAfterRouteEnter.forEach(s=>n.onAfterRouteEnter.add(s)),me(e,t,a)&&r.onAfterRouteUpdate.forEach(s=>n.onAfterRouteUpdate.add(s))}),t==null||t.matches.forEach((o,a)=>{pe(e,t,a)&&r.onAfterRouteLeave.forEach(s=>n.onAfterRouteLeave.add(s))}),n}const wt=Symbol();function jr(){const e={global:new Z,component:new Z},{reject:t,push:r,replace:n,abort:o}=yt(),a=f=>(e.global.onBeforeRouteEnter.add(f),()=>e.global.onBeforeRouteEnter.delete(f)),s=f=>(e.global.onBeforeRouteUpdate.add(f),()=>e.global.onBeforeRouteUpdate.delete(f)),l=f=>(e.global.onBeforeRouteLeave.add(f),()=>e.global.onBeforeRouteLeave.delete(f)),i=f=>(e.global.onAfterRouteEnter.add(f),()=>e.global.onAfterRouteEnter.delete(f)),u=f=>(e.global.onAfterRouteUpdate.add(f),()=>e.global.onAfterRouteUpdate.delete(f)),h=f=>(e.global.onAfterRouteLeave.add(f),()=>e.global.onAfterRouteLeave.delete(f));async function g({to:f,from:m}){const{global:U,component:y}=e,E=Br(f,m),k=Vr(f,m,U),L=[...k.onBeforeRouteEnter,...E.onBeforeRouteEnter,...k.onBeforeRouteUpdate,...E.onBeforeRouteUpdate,...y.onBeforeRouteUpdate,...k.onBeforeRouteLeave,...E.onBeforeRouteLeave,...y.onBeforeRouteLeave];try{const p=L.map(d=>d(f,{from:m,reject:t,push:r,replace:n,abort:o}));await Promise.all(p)}catch(p){if(p instanceof se||p instanceof be||p instanceof Rt)return p.response;throw p}return{status:"SUCCESS"}}async function P({to:f,from:m}){const{global:U,component:y}=e,E=Cr(f,m),k=Nr(f,m,U),L=[...y.onAfterRouteLeave,...E.onAfterRouteLeave,...k.onAfterRouteLeave,...y.onAfterRouteUpdate,...E.onAfterRouteUpdate,...k.onAfterRouteUpdate,...y.onAfterRouteEnter,...E.onAfterRouteEnter,...k.onAfterRouteEnter];try{const p=L.map(d=>d(f,{from:m,reject:t,push:r,replace:n}));await Promise.all(p)}catch(p){if(p instanceof se||p instanceof be)return p.response;throw p}return{status:"SUCCESS"}}return{runBeforeRouteHooks:g,runAfterRouteHooks:P,addComponentBeforeRouteHook:({lifecycle:f,depth:m,hook:U})=>{const y=gt(f),E=e.component[f],k=(L,p)=>{if(y(L,p.from,m))return U(L,p)};return E.add(k),()=>E.delete(k)},addComponentAfterRouteHook:({lifecycle:f,depth:m,hook:U})=>{const y=gt(f),E=e.component[f],k=(L,p)=>{if(y(L,p.from,m))return U(L,p)};return E.add(k),()=>E.delete(k)},addGlobalRouteHooks:f=>{f.onBeforeRouteEnter.forEach(m=>a(m)),f.onBeforeRouteUpdate.forEach(m=>s(m)),f.onBeforeRouteLeave.forEach(m=>l(m)),f.onAfterRouteEnter.forEach(m=>i(m)),f.onAfterRouteUpdate.forEach(m=>u(m)),f.onAfterRouteLeave.forEach(m=>h(m))},onBeforeRouteEnter:a,onBeforeRouteUpdate:s,onBeforeRouteLeave:l,onAfterRouteEnter:i,onAfterRouteUpdate:u,onAfterRouteLeave:h}}function Hr(e){return c.defineComponent(()=>()=>c.h("h1",e),{name:e,props:[]})}function Ne(e){const t=new URLSearchParams(e);return{get:(...r)=>t.get(...r),getAll:(...r)=>t.getAll(...r),set:(...r)=>{t.set(...r)},append:(...r)=>{t.append(...r)},delete:(...r)=>{t.delete(...r)},toString:(...r)=>t.toString(...r),forEach:(...r)=>{t.forEach(...r)},entries:(...r)=>t.entries(...r),keys:(...r)=>t.keys(...r),values:(...r)=>t.values(...r),has:(...r)=>t.has(...r),size:t.size,sort:()=>{t.sort()},[Symbol.iterator]:()=>t[Symbol.iterator]()}}function je(){let e=0;return()=>(++e).toString()}const $r=je()();function qr(e){return e===$r}const He=je();function _r(e){const t=a=>c.markRaw(e[a]??Hr(a)),r=a=>{const s=c.markRaw(t(a)),l={id:He(),component:s,meta:{},state:{}};return{id:l.id,matched:l,matches:[l],name:a,query:Ne(""),params:{},state:{},href:"/",hash:"",[mt]:!0}},n=a=>{if(!a){o.value=null;return}const s=t(a);o.value={type:a,component:s}},o=c.ref(null);return{setRejection:n,rejection:o,getRejectionRoute:r}}class Ir extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function Or(e){if(e)return e;if(Ve())return window.location.toString();throw new Ir}function vt(e){return!!e&&typeof e=="object"}const Se=!0;function Tr(e,t,r){if(vt(e)&&t in e){const n=e[t];return typeof n=="string"?fe(n,r,Se):n}return fe(void 0,r,Se)}function Et(e,t){const r={};for(const[n,o]of Object.entries(e)){const a=Tr(t,n,o);r[n]=a}return r}function Dr(e,t,r){if(vt(e)&&t in e){const n=e[t];return le(n,r,Se)}return le(void 0,r,Se)}const Pt=(e,t)=>{const r={};for(const[n,o]of Object.entries(e)){const a=Dr(t,n,o);r[n]=a}return r};function Mr(){const e=c.reactive(new Map),t=Ve()?s():null,r=l=>{e.set(l,!1),t==null||t.observe(l)},n=l=>{e.delete(l),t==null||t.unobserve(l)},o=()=>{t==null||t.disconnect()},a=l=>e.get(l)??!1;function s(){return new IntersectionObserver(l=>{l.forEach(i=>{e.set(i.target,i.isIntersecting)})})}return{observe:r,unobserve:n,disconnect:o,isElementVisible:a}}const bt=Symbol("visibilityObserver");function Fr(e){const t=c.inject(bt);if(!t)throw new te;return c.watch(e,(n,o)=>{n&&t.observe(n),o&&t.unobserve(o)},{immediate:!0}),c.onUnmounted(()=>{e.value&&t.unobserve(e.value)}),{isElementVisible:c.computed(()=>e.value?t.isElementVisible(e.value):!1)}}class Wr extends Error{constructor(t){super(`Route not found: "${t}"`)}}function $e(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Jr(e,t){const r=Array.from(e.matchAll(t));if(r.length===0)return[e];let n=0;const o=r.reduce((s,l)=>{const i=$e(e.slice(n,l.index));i.length&&s.push(i);const[u]=l;return s.push(u),n=l.index+u.length,s},[]),a=e.slice(n);return a&&o.push(a),o}function Gr(e){const t=St(e.path.value);return new RegExp(`^${t}$`,"i")}function Qr(e){const t=new URLSearchParams(e.query.value);return Array.from(t.entries()).filter(([,r])=>!_e(r)).map(([r,n])=>{const o=St(n);return new RegExp(`${$e(r)}=${o}(&|$)`,"i")})}function St(e){return Jr(e,new RegExp(zr,"g")).map(t=>t.startsWith(J)?At(t):$e(t)).join("")}function At(e){return[Kr,Yr].reduce((t,r)=>r(t),e)}const zr=`\\${J}\\??([\\w-_]+)\\${Q}`,qe=`\\${J}\\?([\\w-_]+)\\${Q}`,kt=`\\${J}([\\w-_]+)\\${Q}`;function Kr(e){return e.replace(new RegExp(qe,"g"),".*")}function _e(e){return new RegExp(qe,"g").test(e)}function Yr(e){return e.replace(new RegExp(kt,"g"),".+")}function Re(e){const[t]=Ae(e,new RegExp(qe,"g")),[r]=Ae(e,new RegExp(kt,"g"));return t??r}function Ae(e,t){return Array.from(e.matchAll(t)).flatMap(([,...n])=>n.map(o=>W(o)?o:""))}function Ut(e,t,r){const n=xt(t,r),[o]=Ae(e,n);return o}function Lt(e,t){if(!t)return e;const{name:r,param:n,value:o}=t,a=xt(e,r);return Ae(e,a).reduce((l,i)=>i===void 0?l:l.replace(i,()=>le(o,n,r.startsWith("?"))),e)}function xt(e,t){const r=[Xr,Zr,At].reduce((n,o)=>o(n,t),e);return new RegExp(r,"g")}function Xr(e,t){if(!t.startsWith("?"))return e;const r=new RegExp(`\\${J}\\${t}\\${Q}`,"g");return e.replace(r,"(.*)")}function Zr(e,t){if(t.startsWith("?"))return e;const r=new RegExp(`\\${J}${t}\\${Q}`,"g");return e.replace(r,"(.+)")}function Bt({protocol:e,host:t,pathname:r,search:n,searchParams:o,hash:a}){const s=new URL("https://localhost");e&&(s.protocol=e),t&&(s.host=t),r&&(s.pathname=r),o?s.search=new URLSearchParams(o).toString():n&&(s.search=n),a&&(s.hash=a);const l=s.toString().replace(/^https:\/\/localhost\/*/,"/");return xe(l)}function Ie(...e){const t=new URLSearchParams;for(const r of e){const n=new URLSearchParams(r);for(const[o,a]of n.entries())t.append(o,a)}return t}function en(e,t={}){const{params:r={},query:n}=t,o=nn(e.query,r),a=Ie(o,n),s=rn(e.path,r),l=ge(e.hash.value??t.hash).value,i=tn(e.host,r),{protocol:u,host:h}=q(i);return Bt({protocol:u,host:h,pathname:s,searchParams:a,hash:l})}function tn(e,t){const r=e.value&&!e.value.startsWith("http")?`https://${e.value}`:e.value;return Object.entries(e.params).reduce((n,[o,a])=>{const s=Re(`${J}${o}${Q}`);return s?Lt(n,{name:o,param:a,value:t[s]}):n},r)}function rn(e,t){return Object.entries(e.params).reduce((r,[n,o])=>{const a=Re(`${J}${n}${Q}`);return a?Lt(r,{name:n,param:o,value:t[a]}):r},e.value)}function nn(e,t){const r=new URLSearchParams(e.value);if(!e.value)return r;for(const[n,o]of Array.from(r.entries())){const a=Re(o);if(!a)continue;const l=_e(o),i=l?`?${a}`:a,u=le(t[a],e.params[i],l),h=t[a]===void 0&&u==="";l&&h?r.delete(n,o):r.set(n,u)}return r}const on=(e,t)=>{try{Oe(e,t)}catch{return!1}return!0},Oe=(e,t)=>{const{pathname:r,search:n}=q(t);return{...an(e.path,r),...sn(e.query,n)}};function an(e,t){const r={},n=decodeURIComponent(t);for(const[o,a]of Object.entries(e.params)){const s=o.startsWith("?"),l=s?o.slice(1):o,i=Ut(n,e.value,o),u=fe(i,a,s);r[l]=u}return r}function sn(e,t){const r={},n=new URLSearchParams(e.value),o=new URLSearchParams(t);for(const[a,s]of Array.from(n.entries())){const l=Re(s);if(!l)continue;const u=_e(s),h=u?`?${l}`:l,g=o.get(a)??void 0,P=fe(g,e.params[h],u);r[l]=P}return r}function cn(e,t={},r={}){const n=en(e,{params:t,query:r.query,hash:r.hash}),{search:o,hash:a}=q(n);return{id:e.id,matched:e.matched,matches:e.matches,name:e.name,query:Ne(o),params:Oe(e,n),state:Et(e.state,r.state),hash:a,href:n}}const un=e=>"name"in e.matched&&!!e.matched.name,fn=(e,t)=>{const{pathname:r}=q(t);return Gr(e).test(r)},ln=(e,t)=>{const{search:r}=q(t);return Qr(e).every(o=>o.test(r))},Te=(e,t)=>{const{hash:r}=q(t),{value:n}=e.hash;return n===void 0||`#${n.toLowerCase()}`===r.toLowerCase()};function hn(e){const{searchParams:t,pathname:r}=q(e),n=-1,o=1;return(a,s)=>{const l=Vt(a,t),i=Ct(a,r),u=Vt(s,t),h=Ct(s,r);return a.depth>s.depth?n:a.depth<s.depth?o:l+i>u+h?n:l+i<u+h?o:Te(a,e)?n:Te(s,e)?o:0}}function Ct(e,t){const r=Object.keys(e.path.params).filter(o=>o.startsWith("?")).map(o=>o),n=r.filter(o=>Ut(t,e.path.value,o)===void 0);return r.length-n.length}function Vt(e,t){const r=new URLSearchParams(t),n=new URLSearchParams(e.query.value),o=Array.from(n.keys()),a=o.filter(s=>!r.has(s));return o.length-a.length}const dn=[un,fn,ln,Te,on];function pn(e,t){const r=hn(t);return e.filter(n=>dn.every(o=>o(n,t))).sort(r)}function mn(e,t,r){const n=pn(e,t);if(!n.length)return;const[o]=n,{searchParams:a,hash:s}=q(t);return{id:o.id,matched:o.matched,matches:o.matches,name:o.name,query:Ne(a),params:Oe(o,t),state:Et(o.state,r),hash:s,href:xe(t)}}function Nt(e,t){const r=typeof e=="string"?q(e):e,n=typeof t=="string"?q(t):t,o=r.searchParams??new URLSearchParams(r.search),a=n.searchParams??new URLSearchParams(n.search);return Bt({protocol:W(n.protocol)?n.protocol:r.protocol,host:W(n.host)?n.host:r.host,pathname:W(n.pathname)?n.pathname:r.pathname,searchParams:Ie(a,o),hash:W(n.hash)?n.hash:r.hash})}function De(e,t){const r=new RegExp(`\\${J}(\\??[\\w-_]+)\\${Q}`,"g");return Array.from(e.matchAll(r)).reduce((o,[a,s])=>{const l=Re(a);if(!l)return o;const i=yr(t,l);return ne([l],o),o[s]=i,o},{})}function ke(e,t){return{value:e,params:De(e,t)}}function Rn(e,t){return W(t)?e.map(r=>{const n=`${t}${r.path.value}`;return{...r,path:ke(n,r.path.params)}}):e}class yn extends Error{constructor(t){super(`Invalid Name "${t}": Router does not support multiple routes with the same name. All name names must be unique.`)}}function gn(e){const t=e.map(({name:r})=>r);for(const r of t)if(tt(t,r)>1)throw new yn(r)}function wn(e,t=[],r){const n=[...e,...t.map(o=>o.routes)].flat();return gn(n),Rn(n,r)}function vn(e={},t=[]){const r=new Z;return ce("onBeforeRouteEnter",e,t).forEach(n=>r.onBeforeRouteEnter.add(n)),ce("onBeforeRouteUpdate",e,t).forEach(n=>r.onBeforeRouteUpdate.add(n)),ce("onBeforeRouteLeave",e,t).forEach(n=>r.onBeforeRouteLeave.add(n)),ce("onAfterRouteEnter",e,t).forEach(n=>r.onAfterRouteEnter.add(n)),ce("onAfterRouteUpdate",e,t).forEach(n=>r.onAfterRouteUpdate.add(n)),ce("onAfterRouteLeave",e,t).forEach(n=>r.onAfterRouteLeave.add(n)),r}function ce(e,t,r){return[t[e],...r.map(o=>o[e])].flat().filter(o=>o!==void 0)}function En(e,t,r=[]){const n=wn(e,r,t==null?void 0:t.base),o=jr();o.addGlobalRouteHooks(vn(t,r));const a=je(),s=Bn(),l=Mr(),i=Lr({mode:t==null?void 0:t.historyMode,listener:({location:S})=>{const C=X(S);h(C,{state:S.state,replace:!0})}});function u(S,C={}){return mn(n,S,C.state)}async function h(S,C={}){const G=a();if(i.stopListening(),v(S)){i.update(S,C);return}const T=u(S,C)??m("NotFound"),I=O(G),K=await o.runBeforeRouteHooks({to:T,from:I});switch(K.status){case"ABORT":return;case"PUSH":i.update(S,C),await P(...K.to);return;case"REJECT":i.update(S,C),w(K.type);break;case"SUCCESS":i.update(S,C),w(null);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(K)}`)}const Qe=G;s.setProps(T).then(D=>{if(Qe===G)switch(D.status){case"SUCCESS":break;case"PUSH":P(...D.to);break;case"REJECT":w(D.type);break;default:const ze=D;throw new Error(`Switch is not exhaustive for prop store response status: ${JSON.stringify(ze)}`)}}),k(T);const M=await o.runAfterRouteHooks({to:T,from:I});switch(M.status){case"PUSH":await P(...M.to);break;case"REJECT":w(M.type);break;case"SUCCESS":break;default:const D=M;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(D)}`)}i.startListening()}const g=(S,C={},G={})=>{const T=n.find(I=>I.name===S);if(!T)throw new Wr(String(S));return cn(T,C,G)},P=(S,C,G)=>{if(N(S)){const M={...C},D=Nt(S,{searchParams:M.query,hash:M.hash});return h(D,M)}if(typeof S=="string"){const{replace:M,...D}={...G},ze={...C},Ke=g(S,ze,D),Fn=Pt({...Ke.matched.state},{...Ke.state,...D.state});return h(Ke.href,{replace:M,state:Fn})}const{replace:T,...I}={...C},K=Pt({...S.matched.state},{...S.state,...I.state}),Qe=Nt(S.href,{searchParams:I.query,hash:I.hash});return h(Qe,{replace:T,state:K})},b=(S,C,G)=>{if(N(S)){const I={...C,replace:!0};return P(S,I)}if(typeof S=="string"){const I={...G,replace:!0},K={...C};return P(S,K,I)}const T={...C,replace:!0};return P(S,T)},R=S=>{w(S)},{setRejection:w,rejection:f,getRejectionRoute:m}=_r({...r.reduce((S,C)=>({...S,...C.rejections}),{}),...t==null?void 0:t.rejections}),U=m("NotFound"),{currentRoute:y,routerRoute:E,updateRoute:k}=Sr(U,P),L=Or(t==null?void 0:t.initialUrl),p=i.location.state,{host:d}=q(L),v=Ur(d);let x=!1;const{promise:B,resolve:V}=Promise.withResolvers();async function j(){if(x)return B;x=!0,await h(L,{replace:!0,state:p}),i.startListening(),V()}function _(){i.stopListening()}function O(S){return qr(S)?null:{...y}}function rr(S){S.component("RouterView",Yt),S.component("RouterLink",Qt),S.provide(dt,f),S.provide(wt,o),S.provide(Mt,s),S.provide(bt,l),S.provide(et,nr),j()}const nr={route:E,resolve:g,find:u,push:P,replace:b,reject:R,refresh:i.refresh,forward:i.forward,back:i.back,go:i.go,install:rr,isExternal:v,onBeforeRouteEnter:o.onBeforeRouteEnter,onBeforeRouteUpdate:o.onBeforeRouteUpdate,onBeforeRouteLeave:o.onBeforeRouteLeave,onAfterRouteEnter:o.onAfterRouteEnter,onAfterRouteUpdate:o.onAfterRouteUpdate,onAfterRouteLeave:o.onAfterRouteLeave,prefetch:t==null?void 0:t.prefetch,start:j,stop:_};return nr}function Me(e,t){return{value:e,params:De(e,t)}}function Pn(e){return{routes:e.routes??[],rejections:e.rejections??{},...e}}function jt(e,t){return{value:e,params:De(e,t)}}function bn(e){return ue(e)&&typeof e.hash=="string"}function Ht(e){return e===void 0?ge():bn(e)?e:ge(e)}function $t(e){return e===void 0?"":e}function Sn(e){return ue(e)&&typeof e.value=="string"}function qt(e){return e===void 0?ke("",{}):Sn(e)?e:ke(e,{})}function An(e){return ue(e)&&typeof e.value=="string"}function _t(e){return e===void 0?Me("",{}):An(e)?e:Me(e,{})}function ee(e){const t=He(),r=$t(e.name),n=qt(e.path),o=_t(e.query),a=Ht(e.hash),s=e.meta??{},l=hr(e)?e.state:{},i=c.markRaw({id:t,meta:{},state:{},...e}),u={id:t,matched:i,matches:[i],name:r,path:n,query:o,hash:a,meta:s,state:l,depth:1,host:jt("",{}),prefetch:e.prefetch},h=rt(e)?nt(e.parent,u):u;return ne(h.path.params,h.query.params),h}const Ue={template:"<div>This is component</div>"},Fe=ee({name:"parentA",path:"/parentA/[paramA]"}),It=ee({parent:Fe,name:"parentA.childA",path:"/childA/[?paramB]"}),kn=ee({parent:Fe,name:"parentA.childB",path:"/childB/[paramD]",component:Ue}),Un=ee({parent:It,name:"parentA.childA.grandChildA",path:"/[paramC]",component:Ue});ee({name:"parentB",path:"/parentB",component:Ue}),ee({name:"parentC",path:"/",component:Ue});const Ln="lazy",xn={components:!0,props:!1};function Le(e){return["eager","lazy","intent"].includes(e)}function Ot({routerPrefetch:e,routePrefetch:t,linkPrefetch:r},n){const o=We(r,n),a=We(t,n),s=We(e,n),l=[o,a,s,xn[n],Ln].reduce((i,u)=>Le(i)?i:i===!0&&Le(u)?u:i===!0&&!Le(u)?i:i===void 0?u:i,void 0);return Le(l)?l:!1}function We(e,t){return ue(e)?e[t]:e}function Tt(e){return typeof e=="object"&&e!==null&&"then"in e}function Dt(e){try{const t=e();return Tt(t)?t.catch(r=>r):t}catch(t){return t}}const Mt=Symbol();function Bn(){const e=c.reactive(new Map),{push:t,replace:r,reject:n}=yt(),o=(g,P,b)=>P.matches.filter(R=>Ot({...b,routePrefetch:R.prefetch},"props")===g).flatMap(R=>u(R)).reduce((R,{id:w,name:f,props:m})=>{if(!m)return R;const U=i(w,f,P),y=Dt(()=>m(P,{push:t,replace:r,reject:n}));return R[U]=y,R},{}),a=g=>{Object.entries(g).forEach(([P,b])=>{e.set(P,b)})},s=async g=>{const P=g.matches.flatMap(u),b=[],R=[];for(const{id:w,name:f,props:m}of P){if(!m)continue;const U=i(w,f,g);if(b.push(U),!e.has(U)){const y=Dt(()=>m(g,{push:t,replace:r,reject:n}));e.set(U,y)}R.push((async()=>{const y=await e.get(U);if(y instanceof Error)throw y})())}h(b);try{return await Promise.all(R),{status:"SUCCESS"}}catch(w){if(w instanceof se||w instanceof be)return w.response;throw w}},l=(g,P,b)=>{const R=i(g,P,b);return e.get(R)};function i(g,P,b){return[g,P,b.id,JSON.stringify(b.params)].join("-")}function u(g){return Ce(g)?Object.entries(g.props??{}).map(([P,b])=>({id:g.id,name:P,props:b})):Be(g)?[{id:g.id,name:"default",props:g.props}]:[]}function h(g){for(const P in e.keys())g.includes(P)||e.delete(P)}return{getPrefetchProps:o,setPrefetchProps:a,getProps:l,setProps:s}}function Ft(){const e=c.inject(Mt);if(!e)throw new te;return e}const Cn=c.defineAsyncComponent(()=>new Promise(e=>{e({default:{template:"foo"}})}));function Wt(e){return e.name===Cn.name&&"__asyncLoader"in e}function Jt(e,t,r){c.watch(e,(n,o)=>{n&&n.addEventListener(t,r),o&&o.removeEventListener(t,r)},{immediate:!0}),c.onUnmounted(()=>{e.value&&e.value.removeEventListener(t,r)})}function Vn(e){const t=new Map,r=c.ref(),{getPrefetchProps:n,setPrefetchProps:o}=Ft(),{isElementVisible:a}=Fr(r),s=()=>{const u=Array.from(t.values()).reduce((h,g)=>(Object.assign(h,g),h),{});o(u)};c.watch(()=>c.toValue(e),({route:u,...h})=>{t.clear(),u&&i("eager",u,h)},{immediate:!0}),c.watch(a,u=>{const{route:h,...g}=c.toValue(e);!h||!u||i("lazy",h,g)},{immediate:!0}),Jt(r,"focusin",l),Jt(r,"mouseover",l);function l(){const{route:u,...h}=c.toValue(e);u&&i("intent",u,h)}function i(u,h,g){Nn(u,h,g),t.has(u)||t.set(u,n(u,h,g))}return{element:r,commit:s}}function Nn(e,t,r){t.matches.forEach(n=>{Ot({...r,routePrefetch:n.prefetch},"components")===e&&(Be(n)&&Wt(n.component)&&n.component.__asyncLoader(),Ce(n)&&Object.values(n.components).forEach(a=>{Wt(a)&&a.__asyncLoader()}))})}function Je(e,t,{exact:r}={}){return Pr(e)?t===void 0?!0:r?e.matched.name===t:e.matches.map(n=>n.name).includes(t):!1}function Gt(e,t={},r={}){const n=ye(),o=c.computed(()=>{const R=c.toValue(e);return typeof R!="string"?R:N(R)?n.find(R,c.toValue(r)):n.resolve(R,c.toValue(t),c.toValue(r))}),a=c.computed(()=>{if(o.value)return o.value.href;const R=c.toValue(e);if(N(R))return R;console.error(new Error("Failed to resolve route in RouterLink."))}),s=c.computed(()=>Je(n.route)&&n.route.matches.some(R=>{var w;return R.id===((w=o.value)==null?void 0:w.id)})),l=c.computed(()=>{var R;return n.route.id===((R=o.value)==null?void 0:R.id)}),i=c.computed(()=>!!a.value&&n.isExternal(a.value)),u=c.computed(()=>{const R=c.toValue(e);return typeof R!="string"||N(R)?c.toValue(t):c.toValue(r)}),{element:h,commit:g}=Vn(()=>({route:o.value,routerPrefetch:n.prefetch,linkPrefetch:u.value.prefetch})),P=R=>{g();const w={replace:(R==null?void 0:R.replace)??u.value.replace,query:Ie(u.value.query,R==null?void 0:R.query),hash:(R==null?void 0:R.hash)??u.value.hash,state:{...u.value.state,...R==null?void 0:R.state}},f=c.toValue(e);return N(f)||typeof f=="object"?n.push(f,w):n.push(f,c.toValue(t),w)};return{element:h,route:o,href:a,isMatch:s,isExactMatch:l,isExternal:i,push:P,replace:R=>P({...R,replace:!0})}}const jn=["href"],Qt=c.defineComponent({__name:"routerLink",props:{to:{},prefetch:{type:[Boolean,String,Object],default:void 0},query:{},hash:{},replace:{type:Boolean},state:{}},setup(e){const t=e,r=ye(),n=c.computed(()=>P(t.to)),o=c.computed(()=>b(t.to)),a=c.computed(()=>{const{to:w,...f}=t;return f}),{element:s,isMatch:l,isExactMatch:i,isExternal:u,push:h}=Gt(()=>typeof t.to=="function"?t.to(r.resolve):t.to,a),g=c.computed(()=>({"router-link--match":l.value,"router-link--exact-match":i.value}));function P(w){if(typeof w=="function"){const f=w(r.resolve);return P(f)}return N(w)?r.find(w):w}function b(w){if(typeof w=="function"){const f=w(r.resolve);return b(f)}return N(w)?w:w==null?void 0:w.href}function R(w){w.preventDefault(),h()}return(w,f)=>(c.openBlock(),c.createElementBlock("a",{ref_key:"element",ref:s,href:o.value,class:c.normalizeClass(["router-link",g.value]),onClick:R},[c.renderSlot(w.$slots,"default",c.normalizeProps(c.guardReactiveProps({route:n.value,isMatch:c.unref(l),isExactMatch:c.unref(i),isExternal:c.unref(u)})))],10,jn))}});function zt(e,t){const r=ye();function n(){if(!e)return;if(!Je(r.route,e,t))throw new Ze(e,r.route.name)}return c.watch(r.route,n,{immediate:!0,deep:!0}),r.route}const Kt=Symbol();function Ge(){return c.inject(Kt,0)}function Hn(e,t){return c.defineComponent({name:"PropsWrapper",expose:[],setup(){const r=t(),n=c.getCurrentInstance();return()=>r instanceof Error?"":Tt(r)?n!=null&&n.suspense?c.h(qn(e,r)):c.h($n(e,r)):c.h(e,r)}})}function $n(e,t){return c.defineComponent({name:"AsyncPropsWrapper",expose:[],setup(){const r=c.ref();return(async()=>r.value=await t)(),()=>r.value instanceof Error?"":r.value?c.h(e,r.value):""}})}function qn(e,t){return c.defineComponent({name:"SuspenseAsyncPropsWrapper",expose:[],async setup(){const r=await t;return()=>c.h(e,r)}})}const Yt=c.defineComponent({__name:"routerView",props:{name:{default:"default"}},setup(e){const t=zt(),r=Er(),n=Ge(),{getProps:o}=Ft(),a=c.resolveComponent("RouterView",!0);c.provide(Kt,n+1);const s=c.computed(()=>{if(r.value)return r.value.component;const u=t.matches.at(n);if(!u)return null;const h=l(u),g=o(u.id,e.name,t);return h?g?Hn(h,()=>g):h:null});function l(u){return i(u)[e.name]}function i(u){return Ce(u)?u.components:Be(u)?{default:u.component}:typeof a=="string"?{}:{default:a}}return(u,h)=>s.value?c.renderSlot(u.$slots,"default",c.normalizeProps(c.mergeProps({key:0},{route:c.unref(t),component:s.value,rejection:c.unref(r)})),()=>[(c.openBlock(),c.createBlock(c.resolveDynamicComponent(s.value)))]):c.createCommentVNode("",!0)}});function Xt(){const e=c.inject(wt);if(!e)throw new te;return e}function Zt(e){return t=>{const r=Ge(),o=Xt().addComponentBeforeRouteHook({lifecycle:e,hook:t,depth:r-1});return c.onUnmounted(o),o}}function er(e){return t=>{const r=Ge(),o=Xt().addComponentAfterRouteHook({lifecycle:e,hook:t,depth:r-1});return c.onUnmounted(o),o}}const _n=Zt("onBeforeRouteLeave"),In=Zt("onBeforeRouteUpdate"),On=er("onAfterRouteLeave"),Tn=er("onAfterRouteUpdate");function Dn(e){return ue(e)&&typeof e.value=="string"}function tr(e){return Dn(e)?e:jt(e,{})}function Mn(e){const t=He(),r=$t(e.name),n=qt(e.path),o=_t(e.query),a=Ht(e.hash),s=e.meta??{},l=lr(e)?tr(e.host):tr(""),i=c.markRaw({id:t,meta:{},state:{},...e}),u={id:t,matched:i,matches:[i],name:r,host:l,path:n,query:o,hash:a,meta:s,depth:1,state:{}},h=rt(e)?nt(e.parent,u):u;return ne(h.path.params,h.query.params,h.host.params),h}A.DuplicateParamsError=Ye,A.MetaPropertyConflict=Xe,A.RouterLink=Qt,A.RouterNotInstalledError=te,A.RouterView=Yt,A.UseRouteInvalidError=Ze,A.asUrl=xe,A.createExternalRoute=Mn,A.createParam=ut,A.createRoute=ee,A.createRouter=En,A.createRouterPlugin=Pn,A.isRoute=Je,A.isUrl=N,A.onAfterRouteLeave=On,A.onAfterRouteUpdate=Tn,A.onBeforeRouteLeave=_n,A.onBeforeRouteUpdate=In,A.path=ke,A.query=Me,A.useLink=Gt,A.useRoute=zt,A.useRouter=ye,A.withDefault=Rr,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(A,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(A=typeof globalThis<"u"?globalThis:A||self,c(A["@kitbag/router"]={},A.Vue))})(this,function(A,c){"use strict";var Gn=Object.defineProperty;var Qn=(A,c,N)=>c in A?Gn(A,c,{enumerable:!0,configurable:!0,writable:!0,value:N}):A[c]=N;var W=(A,c,N)=>Qn(A,typeof c!="symbol"?c+"":c,N);function N(e){return typeof e!="string"?!1:/^(https?:\/\/|\/).*/g.test(e)}function xe(e){return N(e)?e:`/${e}`}class ze extends Error{constructor(t){super(`Invalid Param "${t}": Router does not support multiple params by the same name. All param names must be unique.`)}}class Ke extends Error{constructor(t){super(`Child property on meta for ${t} conflicts with the parent meta.`)}}class te extends Error{constructor(){super("Router not installed")}}class Ye extends Error{constructor(t,r){super(`useRoute called with incorrect route. Given ${t}, expected ${r}`)}}const Xe=Symbol();function ye(){const e=c.inject(Xe);if(!e)throw new te;return e}function ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e){return typeof e=="string"&&e.length>0}function ge(e){return{value:F(e)?e.replace(/^#*/,""):void 0}}function or(e,t){return ge(`${e.value??""}${t.value??""}`)}function ar(e,t){return sr(e,t),{...e,...t}}function sr(e,t){const r=Object.keys(e).find(n=>n in t&&typeof t[n]!=typeof e[n]);if(r)throw new Ke(r)}function re(e){return Array.isArray(e)?e:[e]}function Ze(e,t){return e.filter(r=>t===r).length}function ne(...e){const t=e.flatMap(r=>Array.isArray(r)?r:Object.keys(r).map(cr));for(const r of t)if(Ze(t,r)>1)throw new ze(r)}function cr(e){return e.startsWith("?")?e.slice(1):e}function ur(e,t){return ne(e.params,t.params),{value:`${e.value}${t.value}`,params:{...e.params,...t.params}}}function ir(e,t){return ne(e.params,t.params),{value:[e.value,t.value].filter(F).join("&"),params:{...e.params,...t.params}}}function fr(e,t){return ne(e,t),{...e,...t}}function lr(e){return"host"in e&&!!e.host}function et(e){return"parent"in e&&!!e.parent}function tt(e){return"component"in e&&!!e.component}function hr(e){return"props"in e&&typeof e.props=="function"}function rt(e){return"components"in e&&!!e.components}function dr(e){return"props"in e&&typeof e.props=="object"}function pr(e){return"state"in e&&!!e.state}function nt(e,t){return{...t,path:ur(e.path,t.path),query:ir(e.query,t.query),meta:ar(e.meta,t.meta),state:fr(e.state,t.state),hash:or(e.hash,t.hash),matches:[...e.matches,t.matched],host:e.host,depth:e.depth+1}}function Be(){return typeof window<"u"&&typeof window.document<"u"}class ie extends Error{}const J="[",Q="]";function mr(e){return e!==String&&e!==Boolean&&e!==Number&&e!==Date}function Rr(e){return typeof e=="function"&&mr(e)}function we(e){return typeof e=="object"&&"get"in e&&typeof e.get=="function"&&"set"in e&&typeof e.set=="function"}function yr(e){return we(e)&&e.defaultValue!==void 0}function gr(e,t){return ut(e,t)}function wr(e,t){return e[t]??String}const $={invalid:e=>{throw new ie(e)}},vr={get:e=>e,set:(e,{invalid:t})=>{if(typeof e!="string")throw t();return e}},ot={get:(e,{invalid:t})=>{if(e==="true")return!0;if(e==="false")return!1;throw t()},set:(e,{invalid:t})=>{if(typeof e!="boolean")throw t();return e.toString()}},at={get:(e,{invalid:t})=>{const r=Number(e);if(isNaN(r))throw t();return r},set:(e,{invalid:t})=>{if(typeof e!="number")throw t();return e.toString()}},st={get:(e,{invalid:t})=>{const r=new Date(e);if(isNaN(r.getTime()))throw t();return r},set:(e,{invalid:t})=>{if(typeof e!="object"||!(e instanceof Date))throw t();return e.toISOString()}},ct={get:(e,{invalid:t})=>{try{return JSON.parse(e)}catch{throw t()}},set:(e,{invalid:t})=>{try{return JSON.stringify(e)}catch{throw t()}}};function fe(e,t,r=!1){if(e===void 0||!F(e)){if(yr(t))return t.defaultValue;if(r)return;throw new ie}if(t===String)return vr.get(e,$);if(t===Boolean)return ot.get(e,$);if(t===Number)return at.get(e,$);if(t===Date)return st.get(e,$);if(t===JSON)return ct.get(e,$);if(Rr(t))return t(e,$);if(we(t))return t.get(e,$);if(t instanceof RegExp){if(t.test(e))return e;throw new ie}return e}function le(e,t,r=!1){if(e===void 0){if(r)return"";throw new ie}if(t===Boolean)return ot.set(e,$);if(t===Number)return at.set(e,$);if(t===Date)return st.set(e,$);if(t===JSON)return ct.set(e,$);if(we(t))return t.set(e,$);try{return e.toString()}catch{throw new ie}}function ut(e,t){return we(e)?{...e,defaultValue:t??e.defaultValue}:{get:r=>fe(r,e),set:r=>le(r,e),defaultValue:t}}function z(){return z=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},z.apply(null,arguments)}var H;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(H||(H={}));var oe=process.env.NODE_ENV!=="production"?function(e){return Object.freeze(e)}:function(e){return e};function Y(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}var ve="beforeunload",Er="hashchange",it="popstate";function ft(e){e===void 0&&(e={});var t=e,r=t.window,n=r===void 0?document.defaultView:r,o=n.history;function a(){var p=n.location,h=p.pathname,v=p.search,x=p.hash,B=o.state||{};return[B.idx,oe({pathname:h,search:v,hash:x,state:B.usr||null,key:B.key||"default"})]}var s=null;function l(){if(s)b.call(s),s=null;else{var p=H.Pop,h=a(),v=h[0],x=h[1];if(b.length)if(v!=null){var B=d-v;B&&(s={action:p,location:x,retry:function(){k(B*-1)}},k(B))}else process.env.NODE_ENV!=="production"&&Y(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else U(p)}}n.addEventListener(it,l);var i=H.Pop,u=a(),d=u[0],R=u[1],P=ae(),b=ae();d==null&&(d=0,o.replaceState(z({},o.state,{idx:d}),""));function y(p){return typeof p=="string"?p:X(p)}function w(p,h){return h===void 0&&(h=null),oe(z({pathname:R.pathname,hash:"",search:""},typeof p=="string"?he(p):p,{state:h,key:Pe()}))}function f(p,h){return[{usr:p.state,key:p.key,idx:h},y(p)]}function m(p,h,v){return!b.length||(b.call({action:p,location:h,retry:v}),!1)}function U(p){i=p;var h=a();d=h[0],R=h[1],P.call({action:i,location:R})}function g(p,h){var v=H.Push,x=w(p,h);function B(){g(p,h)}if(m(v,x,B)){var V=f(x,d+1),j=V[0],_=V[1];try{o.pushState(j,"",_)}catch{n.location.assign(_)}U(v)}}function E(p,h){var v=H.Replace,x=w(p,h);function B(){E(p,h)}if(m(v,x,B)){var V=f(x,d),j=V[0],_=V[1];o.replaceState(j,"",_),U(v)}}function k(p){o.go(p)}var L={get action(){return i},get location(){return R},createHref:y,push:g,replace:E,go:k,back:function(){k(-1)},forward:function(){k(1)},listen:function(h){return P.push(h)},block:function(h){var v=b.push(h);return b.length===1&&n.addEventListener(ve,Ee),function(){v(),b.length||n.removeEventListener(ve,Ee)}}};return L}function Pr(e){e===void 0&&(e={});var t=e,r=t.window,n=r===void 0?document.defaultView:r,o=n.history;function a(){var h=he(n.location.hash.substr(1)),v=h.pathname,x=v===void 0?"/":v,B=h.search,V=B===void 0?"":B,j=h.hash,_=j===void 0?"":j,O=o.state||{};return[O.idx,oe({pathname:x,search:V,hash:_,state:O.usr||null,key:O.key||"default"})]}var s=null;function l(){if(s)b.call(s),s=null;else{var h=H.Pop,v=a(),x=v[0],B=v[1];if(b.length)if(x!=null){var V=d-x;V&&(s={action:h,location:B,retry:function(){L(V*-1)}},L(V))}else process.env.NODE_ENV!=="production"&&Y(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.");else g(h)}}n.addEventListener(it,l),n.addEventListener(Er,function(){var h=a(),v=h[1];X(v)!==X(R)&&l()});var i=H.Pop,u=a(),d=u[0],R=u[1],P=ae(),b=ae();d==null&&(d=0,o.replaceState(z({},o.state,{idx:d}),""));function y(){var h=document.querySelector("base"),v="";if(h&&h.getAttribute("href")){var x=n.location.href,B=x.indexOf("#");v=B===-1?x:x.slice(0,B)}return v}function w(h){return y()+"#"+(typeof h=="string"?h:X(h))}function f(h,v){return v===void 0&&(v=null),oe(z({pathname:R.pathname,hash:"",search:""},typeof h=="string"?he(h):h,{state:v,key:Pe()}))}function m(h,v){return[{usr:h.state,key:h.key,idx:v},w(h)]}function U(h,v,x){return!b.length||(b.call({action:h,location:v,retry:x}),!1)}function g(h){i=h;var v=a();d=v[0],R=v[1],P.call({action:i,location:R})}function E(h,v){var x=H.Push,B=f(h,v);function V(){E(h,v)}if(process.env.NODE_ENV!=="production"&&Y(B.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(h)+")"),U(x,B,V)){var j=m(B,d+1),_=j[0],O=j[1];try{o.pushState(_,"",O)}catch{n.location.assign(O)}g(x)}}function k(h,v){var x=H.Replace,B=f(h,v);function V(){k(h,v)}if(process.env.NODE_ENV!=="production"&&Y(B.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(h)+")"),U(x,B,V)){var j=m(B,d),_=j[0],O=j[1];o.replaceState(_,"",O),g(x)}}function L(h){o.go(h)}var p={get action(){return i},get location(){return R},createHref:w,push:E,replace:k,go:L,back:function(){L(-1)},forward:function(){L(1)},listen:function(v){return P.push(v)},block:function(v){var x=b.push(v);return b.length===1&&n.addEventListener(ve,Ee),function(){x(),b.length||n.removeEventListener(ve,Ee)}}};return p}function lt(e){e===void 0&&(e={});var t=e,r=t.initialEntries,n=r===void 0?["/"]:r,o=t.initialIndex,a=n.map(function(g){var E=oe(z({pathname:"/",search:"",hash:"",state:null,key:Pe()},typeof g=="string"?he(g):g));return process.env.NODE_ENV!=="production"&&Y(E.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(g)+")"),E}),s=ht(o??a.length-1,0,a.length-1),l=H.Pop,i=a[s],u=ae(),d=ae();function R(g){return typeof g=="string"?g:X(g)}function P(g,E){return E===void 0&&(E=null),oe(z({pathname:i.pathname,search:"",hash:""},typeof g=="string"?he(g):g,{state:E,key:Pe()}))}function b(g,E,k){return!d.length||(d.call({action:g,location:E,retry:k}),!1)}function y(g,E){l=g,i=E,u.call({action:l,location:i})}function w(g,E){var k=H.Push,L=P(g,E);function p(){w(g,E)}process.env.NODE_ENV!=="production"&&Y(i.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(g)+")"),b(k,L,p)&&(s+=1,a.splice(s,a.length,L),y(k,L))}function f(g,E){var k=H.Replace,L=P(g,E);function p(){f(g,E)}process.env.NODE_ENV!=="production"&&Y(i.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(g)+")"),b(k,L,p)&&(a[s]=L,y(k,L))}function m(g){var E=ht(s+g,0,a.length-1),k=H.Pop,L=a[E];function p(){m(g)}b(k,L,p)&&(s=E,y(k,L))}var U={get index(){return s},get action(){return l},get location(){return i},createHref:R,push:w,replace:f,go:m,back:function(){m(-1)},forward:function(){m(1)},listen:function(E){return u.push(E)},block:function(E){return d.push(E)}};return U}function ht(e,t,r){return Math.min(Math.max(e,t),r)}function Ee(e){e.preventDefault(),e.returnValue=""}function ae(){var e=[];return{get length(){return e.length},push:function(r){return e.push(r),function(){e=e.filter(function(n){return n!==r})}},call:function(r){e.forEach(function(n){return n&&n(r)})}}}function Pe(){return Math.random().toString(36).substr(2,8)}function X(e){var t=e.pathname,r=t===void 0?"/":t,n=e.search,o=n===void 0?"":n,a=e.hash,s=a===void 0?"":a;return o&&o!=="?"&&(r+=o.charAt(0)==="?"?o:"?"+o),s&&s!=="#"&&(r+=s.charAt(0)==="#"?s:"#"+s),r}function he(e){var t={};if(e){var r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));var n=e.indexOf("?");n>=0&&(t.search=e.substr(n),e=e.substr(0,n)),e&&(t.pathname=e)}return t}const dt=Symbol();function br(){const e=c.inject(dt);if(!e)throw new te;return e}const pt=Symbol("isRouterRouteSymbol");function Sr(e){return typeof e=="object"&&e!==null&&pt in e}function Ar(e,t){function r(f,m,U){if(typeof f=="object"){const E={...e.params,...f};return t(e.name,E,m)}const g={...e.params,[f]:m};return t(e.name,g,U)}const n=(...f)=>{const m=new URLSearchParams(e.query);m.set(...f),r({},{query:m})},o=(...f)=>{const m=new URLSearchParams(e.query);m.append(...f),r({},{query:m})},a=(...f)=>{const m=new URLSearchParams(e.query);m.delete(...f),r({},{query:m})},{id:s,matched:l,matches:i,name:u,hash:d,href:R}=c.toRefs(e),P=c.computed({get(){return new Proxy(e.params,{set(f,m,U){return r(m,U),!0}})},set(f){r(f)}}),b=c.computed({get(){return new Proxy(e.query,{get(f,m,U){switch(m){case"append":return o;case"set":return n;case"delete":return a;default:return Reflect.get(f,m,U)}}})},set(f){r({},{query:f})}}),y=c.computed({get(){return new Proxy(e.state,{set(f,m,U){return r({},{state:{...e.state,[m]:U}}),!0}})},set(f){r({},{state:f})}});return c.reactive({id:s,matched:l,matches:i,state:y,query:b,hash:d,params:P,name:u,href:R,update:r,[pt]:!0})}const mt=Symbol();function kr(e,t){const r=c.reactive({...e}),n=s=>{Object.assign(r,{[mt]:!1,...s})},o=r,a=Ar(o,t);return{currentRoute:o,routerRoute:a,updateRoute:n}}function q(e){return!e.startsWith("http")?Lr(e):Ur(e)}function Ur(e){const{protocol:t,host:r,pathname:n,search:o,searchParams:a,hash:s}=new URL(e,e);return{protocol:t,host:r,pathname:n,search:o,searchParams:a,hash:s}}function Lr(e){const{pathname:t,search:r,searchParams:n,hash:o}=new URL(e,"https://localhost");return{pathname:t,search:r,searchParams:n,hash:o}}function xr(e){return t=>{const{host:r}=q(t);return!(r===void 0||r===e)}}function Br({mode:e,listener:t}){const r=Cr(e),n=(i,u)=>{if(u!=null&&u.replace){r.replace(i,u.state);return}r.push(i,u==null?void 0:u.state)},o=()=>{const i=X(r.location);r.replace(i)};let a;return{...r,update:n,refresh:o,startListening:()=>{a==null||a(),a=r.listen(t)},stopListening:()=>{a==null||a()}}}function Cr(e="auto"){switch(e){case"auto":return Be()?ft():lt();case"browser":return ft();case"memory":return lt();case"hash":return Pr();default:const t=e;throw new Error(`Switch is not exhaustive for mode: ${t}`)}}class Rt extends Error{constructor(){super("Uncaught CallbackContextAbortError");W(this,"response");this.response={status:"ABORT"}}}class se extends Error{constructor(r){super("Uncaught CallbackContextPushError");W(this,"response");this.response={status:"PUSH",to:r}}}class be extends Error{constructor(r){super("Uncaught CallbackContextRejectionError");W(this,"response");this.response={status:"REJECT",type:r}}}function yt(){return{reject:o=>{throw new be(o)},push:(...o)=>{throw new se(o)},replace:(o,a,s)=>{if(N(o)){const u=a??{};throw new se([o,{...u,replace:!0}])}const l=a,i=s??{};throw new se([o,l,{...i,replace:!0}])},abort:()=>{throw new Rt}}}class Z{constructor(){W(this,"onBeforeRouteEnter",new Set);W(this,"onBeforeRouteUpdate",new Set);W(this,"onBeforeRouteLeave",new Set);W(this,"onAfterRouteEnter",new Set);W(this,"onAfterRouteUpdate",new Set);W(this,"onAfterRouteLeave",new Set)}}const de=(e,t,r)=>{var a,s;const n=e.matches,o=(t==null?void 0:t.matches)??[];return((a=n.at(r))==null?void 0:a.id)!==((s=o.at(r))==null?void 0:s.id)},pe=(e,t,r)=>{var a,s;const n=e.matches,o=(t==null?void 0:t.matches)??[];return((a=n.at(r))==null?void 0:a.id)!==((s=o.at(r))==null?void 0:s.id)},me=(e,t,r)=>{var n,o;return((n=e.matches.at(r))==null?void 0:n.id)===((o=t==null?void 0:t.matches.at(r))==null?void 0:o.id)};function gt(e){switch(e){case"onBeforeRouteEnter":case"onAfterRouteEnter":return de;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return me;case"onBeforeRouteLeave":case"onAfterRouteLeave":return pe;default:throw new Error(`Switch is not exhaustive for lifecycle: ${e}`)}}function Vr(e,t){const r=new Z;return e.matches.forEach((n,o)=>{n.onBeforeRouteEnter&&de(e,t,o)&&re(n.onBeforeRouteEnter).forEach(a=>r.onBeforeRouteEnter.add(a)),n.onBeforeRouteUpdate&&me(e,t,o)&&re(n.onBeforeRouteUpdate).forEach(a=>r.onBeforeRouteUpdate.add(a))}),t==null||t.matches.forEach((n,o)=>{n.onBeforeRouteLeave&&pe(e,t,o)&&re(n.onBeforeRouteLeave).forEach(a=>r.onBeforeRouteLeave.add(a))}),r}function Nr(e,t){const r=new Z;return e.matches.forEach((n,o)=>{n.onAfterRouteEnter&&de(e,t,o)&&re(n.onAfterRouteEnter).forEach(a=>r.onAfterRouteEnter.add(a)),n.onAfterRouteUpdate&&me(e,t,o)&&re(n.onAfterRouteUpdate).forEach(a=>r.onAfterRouteUpdate.add(a))}),t==null||t.matches.forEach((n,o)=>{n.onAfterRouteLeave&&pe(e,t,o)&&re(n.onAfterRouteLeave).forEach(a=>r.onAfterRouteLeave.add(a))}),r}function jr(e,t,r){const n=new Z;return e.matches.forEach((o,a)=>{de(e,t,a)&&r.onBeforeRouteEnter.forEach(s=>n.onBeforeRouteEnter.add(s)),me(e,t,a)&&r.onBeforeRouteUpdate.forEach(s=>n.onBeforeRouteUpdate.add(s))}),t==null||t.matches.forEach((o,a)=>{pe(e,t,a)&&r.onBeforeRouteLeave.forEach(s=>n.onBeforeRouteLeave.add(s))}),n}function Hr(e,t,r){const n=new Z;return e.matches.forEach((o,a)=>{de(e,t,a)&&r.onAfterRouteEnter.forEach(s=>n.onAfterRouteEnter.add(s)),me(e,t,a)&&r.onAfterRouteUpdate.forEach(s=>n.onAfterRouteUpdate.add(s))}),t==null||t.matches.forEach((o,a)=>{pe(e,t,a)&&r.onAfterRouteLeave.forEach(s=>n.onAfterRouteLeave.add(s))}),n}const wt=Symbol();function $r(){const e={global:new Z,component:new Z},{reject:t,push:r,replace:n,abort:o}=yt(),a=f=>(e.global.onBeforeRouteEnter.add(f),()=>e.global.onBeforeRouteEnter.delete(f)),s=f=>(e.global.onBeforeRouteUpdate.add(f),()=>e.global.onBeforeRouteUpdate.delete(f)),l=f=>(e.global.onBeforeRouteLeave.add(f),()=>e.global.onBeforeRouteLeave.delete(f)),i=f=>(e.global.onAfterRouteEnter.add(f),()=>e.global.onAfterRouteEnter.delete(f)),u=f=>(e.global.onAfterRouteUpdate.add(f),()=>e.global.onAfterRouteUpdate.delete(f)),d=f=>(e.global.onAfterRouteLeave.add(f),()=>e.global.onAfterRouteLeave.delete(f));async function R({to:f,from:m}){const{global:U,component:g}=e,E=Vr(f,m),k=jr(f,m,U),L=[...k.onBeforeRouteEnter,...E.onBeforeRouteEnter,...k.onBeforeRouteUpdate,...E.onBeforeRouteUpdate,...g.onBeforeRouteUpdate,...k.onBeforeRouteLeave,...E.onBeforeRouteLeave,...g.onBeforeRouteLeave];try{const p=L.map(h=>h(f,{from:m,reject:t,push:r,replace:n,abort:o}));await Promise.all(p)}catch(p){if(p instanceof se||p instanceof be||p instanceof Rt)return p.response;throw p}return{status:"SUCCESS"}}async function P({to:f,from:m}){const{global:U,component:g}=e,E=Nr(f,m),k=Hr(f,m,U),L=[...g.onAfterRouteLeave,...E.onAfterRouteLeave,...k.onAfterRouteLeave,...g.onAfterRouteUpdate,...E.onAfterRouteUpdate,...k.onAfterRouteUpdate,...g.onAfterRouteEnter,...E.onAfterRouteEnter,...k.onAfterRouteEnter];try{const p=L.map(h=>h(f,{from:m,reject:t,push:r,replace:n}));await Promise.all(p)}catch(p){if(p instanceof se||p instanceof be)return p.response;throw p}return{status:"SUCCESS"}}return{runBeforeRouteHooks:R,runAfterRouteHooks:P,addComponentBeforeRouteHook:({lifecycle:f,depth:m,hook:U})=>{const g=gt(f),E=e.component[f],k=(L,p)=>{if(g(L,p.from,m))return U(L,p)};return E.add(k),()=>E.delete(k)},addComponentAfterRouteHook:({lifecycle:f,depth:m,hook:U})=>{const g=gt(f),E=e.component[f],k=(L,p)=>{if(g(L,p.from,m))return U(L,p)};return E.add(k),()=>E.delete(k)},addGlobalRouteHooks:f=>{f.onBeforeRouteEnter.forEach(m=>a(m)),f.onBeforeRouteUpdate.forEach(m=>s(m)),f.onBeforeRouteLeave.forEach(m=>l(m)),f.onAfterRouteEnter.forEach(m=>i(m)),f.onAfterRouteUpdate.forEach(m=>u(m)),f.onAfterRouteLeave.forEach(m=>d(m))},onBeforeRouteEnter:a,onBeforeRouteUpdate:s,onBeforeRouteLeave:l,onAfterRouteEnter:i,onAfterRouteUpdate:u,onAfterRouteLeave:d}}function qr(e){return c.defineComponent(()=>()=>c.h("h1",e),{name:e,props:[]})}function Ce(e){const t=new URLSearchParams(e);return{get:(...r)=>t.get(...r),getAll:(...r)=>t.getAll(...r),set:(...r)=>{t.set(...r)},append:(...r)=>{t.append(...r)},delete:(...r)=>{t.delete(...r)},toString:(...r)=>t.toString(...r),forEach:(...r)=>{t.forEach(...r)},entries:(...r)=>t.entries(...r),keys:(...r)=>t.keys(...r),values:(...r)=>t.values(...r),has:(...r)=>t.has(...r),size:t.size,sort:()=>{t.sort()},[Symbol.iterator]:()=>t[Symbol.iterator]()}}function Ve(){let e=0;return()=>(++e).toString()}const _r=Ve()();function Ir(e){return e===_r}const Ne=Ve();function Or(e){const t=a=>c.markRaw(e[a]??qr(a)),r=a=>{const s=c.markRaw(t(a)),l={id:Ne(),component:s,meta:{},state:{}};return{id:l.id,matched:l,matches:[l],name:a,query:Ce(""),params:{},state:{},href:"/",hash:"",[mt]:!0}},n=a=>{if(!a){o.value=null;return}const s=t(a);o.value={type:a,component:s}},o=c.ref(null);return{setRejection:n,rejection:o,getRejectionRoute:r}}class Tr extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function Dr(e){if(e)return e;if(Be())return window.location.toString();throw new Tr}function vt(e){return!!e&&typeof e=="object"}const Se=!0;function Mr(e,t,r){if(vt(e)&&t in e){const n=e[t];return typeof n=="string"?fe(n,r,Se):n}return fe(void 0,r,Se)}function Et(e,t){const r={};for(const[n,o]of Object.entries(e)){const a=Mr(t,n,o);r[n]=a}return r}function Wr(e,t,r){if(vt(e)&&t in e){const n=e[t];return le(n,r,Se)}return le(void 0,r,Se)}const Pt=(e,t)=>{const r={};for(const[n,o]of Object.entries(e)){const a=Wr(t,n,o);r[n]=a}return r};function Fr(){const e=c.reactive(new Map),t=Be()?s():null,r=l=>{e.set(l,!1),t==null||t.observe(l)},n=l=>{e.delete(l),t==null||t.unobserve(l)},o=()=>{t==null||t.disconnect()},a=l=>e.get(l)??!1;function s(){return new IntersectionObserver(l=>{l.forEach(i=>{e.set(i.target,i.isIntersecting)})})}return{observe:r,unobserve:n,disconnect:o,isElementVisible:a}}const bt=Symbol("visibilityObserver");function Jr(e){const t=c.inject(bt);if(!t)throw new te;return c.watch(e,(n,o)=>{n&&t.observe(n),o&&t.unobserve(o)},{immediate:!0}),c.onUnmounted(()=>{e.value&&t.unobserve(e.value)}),{isElementVisible:c.computed(()=>e.value?t.isElementVisible(e.value):!1)}}class Gr extends Error{constructor(t){super(`Route not found: "${t}"`)}}function je(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qr(e,t){const r=Array.from(e.matchAll(t));if(r.length===0)return[e];let n=0;const o=r.reduce((s,l)=>{const i=je(e.slice(n,l.index));i.length&&s.push(i);const[u]=l;return s.push(u),n=l.index+u.length,s},[]),a=e.slice(n);return a&&o.push(a),o}function zr(e){const t=St(e.path.value);return new RegExp(`^${t}$`,"i")}function Kr(e){const t=new URLSearchParams(e.query.value);return Array.from(t.entries()).filter(([,r])=>!$e(r)).map(([r,n])=>{const o=St(n);return new RegExp(`${je(r)}=${o}(&|$)`,"i")})}function St(e){return Qr(e,new RegExp(Yr,"g")).map(t=>t.startsWith(J)?At(t):je(t)).join("")}function At(e){return[Xr,Zr].reduce((t,r)=>r(t),e)}const Yr=`\\${J}\\??([\\w-_]+)\\${Q}`,He=`\\${J}\\?([\\w-_]+)\\${Q}`,kt=`\\${J}([\\w-_]+)\\${Q}`;function Xr(e){return e.replace(new RegExp(He,"g"),".*")}function $e(e){return new RegExp(He,"g").test(e)}function Zr(e){return e.replace(new RegExp(kt,"g"),".+")}function Re(e){const[t]=Ae(e,new RegExp(He,"g")),[r]=Ae(e,new RegExp(kt,"g"));return t??r}function Ae(e,t){return Array.from(e.matchAll(t)).flatMap(([,...n])=>n.map(o=>F(o)?o:""))}function Ut(e,t,r){const n=xt(t,r),[o]=Ae(e,n);return o}function Lt(e,t){if(!t)return e;const{name:r,param:n,value:o}=t,a=xt(e,r);return Ae(e,a).reduce((l,i)=>i===void 0?l:l.replace(i,()=>le(o,n,r.startsWith("?"))),e)}function xt(e,t){const r=[en,tn,At].reduce((n,o)=>o(n,t),e);return new RegExp(r,"g")}function en(e,t){if(!t.startsWith("?"))return e;const r=new RegExp(`\\${J}\\${t}\\${Q}`,"g");return e.replace(r,"(.*)")}function tn(e,t){if(t.startsWith("?"))return e;const r=new RegExp(`\\${J}${t}\\${Q}`,"g");return e.replace(r,"(.+)")}function Bt({protocol:e,host:t,pathname:r,search:n,searchParams:o,hash:a}){const s=new URL("https://localhost");e&&(s.protocol=e),t&&(s.host=t),r&&(s.pathname=r),o?s.search=new URLSearchParams(o).toString():n&&(s.search=n),a&&(s.hash=a);const l=s.toString().replace(/^https:\/\/localhost\/*/,"/");return xe(l)}function qe(...e){const t=new URLSearchParams;for(const r of e){const n=new URLSearchParams(r);for(const[o,a]of n.entries())t.append(o,a)}return t}function rn(e,t={}){const{params:r={},query:n}=t,o=an(e.query,r),a=qe(o,n),s=on(e.path,r),l=ge(e.hash.value??t.hash).value,i=nn(e.host,r),{protocol:u,host:d}=q(i);return Bt({protocol:u,host:d,pathname:s,searchParams:a,hash:l})}function nn(e,t){const r=e.value&&!e.value.startsWith("http")?`https://${e.value}`:e.value;return Object.entries(e.params).reduce((n,[o,a])=>{const s=Re(`${J}${o}${Q}`);return s?Lt(n,{name:o,param:a,value:t[s]}):n},r)}function on(e,t){return Object.entries(e.params).reduce((r,[n,o])=>{const a=Re(`${J}${n}${Q}`);return a?Lt(r,{name:n,param:o,value:t[a]}):r},e.value)}function an(e,t){const r=new URLSearchParams(e.value);if(!e.value)return r;for(const[n,o]of Array.from(r.entries())){const a=Re(o);if(!a)continue;const l=$e(o),i=l?`?${a}`:a,u=le(t[a],e.params[i],l),d=t[a]===void 0&&u==="";l&&d?r.delete(n,o):r.set(n,u)}return r}const sn=(e,t)=>{try{_e(e,t)}catch{return!1}return!0},_e=(e,t)=>{const{pathname:r,search:n}=q(t);return{...cn(e.path,r),...un(e.query,n)}};function cn(e,t){const r={},n=decodeURIComponent(t);for(const[o,a]of Object.entries(e.params)){const s=o.startsWith("?"),l=s?o.slice(1):o,i=Ut(n,e.value,o),u=fe(i,a,s);r[l]=u}return r}function un(e,t){const r={},n=new URLSearchParams(e.value),o=new URLSearchParams(t);for(const[a,s]of Array.from(n.entries())){const l=Re(s);if(!l)continue;const u=$e(s),d=u?`?${l}`:l,R=o.get(a)??void 0,P=fe(R,e.params[d],u);r[l]=P}return r}function fn(e,t={},r={}){const n=rn(e,{params:t,query:r.query,hash:r.hash}),{search:o,hash:a}=q(n);return{id:e.id,matched:e.matched,matches:e.matches,name:e.name,query:Ce(o),params:_e(e,n),state:Et(e.state,r.state),hash:a,href:n}}const ln=e=>"name"in e.matched&&!!e.matched.name,hn=(e,t)=>{const{pathname:r}=q(t);return zr(e).test(r)},dn=(e,t)=>{const{search:r}=q(t);return Kr(e).every(o=>o.test(r))},Ie=(e,t)=>{const{hash:r}=q(t),{value:n}=e.hash;return n===void 0||`#${n.toLowerCase()}`===r.toLowerCase()};function pn(e){const{searchParams:t,pathname:r}=q(e),n=-1,o=1;return(a,s)=>{const l=Vt(a,t),i=Ct(a,r),u=Vt(s,t),d=Ct(s,r);return a.depth>s.depth?n:a.depth<s.depth?o:l+i>u+d?n:l+i<u+d?o:Ie(a,e)?n:Ie(s,e)?o:0}}function Ct(e,t){const r=Object.keys(e.path.params).filter(o=>o.startsWith("?")).map(o=>o),n=r.filter(o=>Ut(t,e.path.value,o)===void 0);return r.length-n.length}function Vt(e,t){const r=new URLSearchParams(t),n=new URLSearchParams(e.query.value),o=Array.from(n.keys()),a=o.filter(s=>!r.has(s));return o.length-a.length}const mn=[ln,hn,dn,Ie,sn];function Rn(e,t){const r=pn(t);return e.filter(n=>mn.every(o=>o(n,t))).sort(r)}function yn(e,t,r){const n=Rn(e,t);if(!n.length)return;const[o]=n,{searchParams:a,hash:s}=q(t);return{id:o.id,matched:o.matched,matches:o.matches,name:o.name,query:Ce(a),params:_e(o,t),state:Et(o.state,r),hash:s,href:xe(t)}}function Nt(e,t){const r=typeof e=="string"?q(e):e,n=typeof t=="string"?q(t):t,o=r.searchParams??new URLSearchParams(r.search),a=n.searchParams??new URLSearchParams(n.search);return Bt({protocol:F(n.protocol)?n.protocol:r.protocol,host:F(n.host)?n.host:r.host,pathname:F(n.pathname)?n.pathname:r.pathname,searchParams:qe(a,o),hash:F(n.hash)?n.hash:r.hash})}function Oe(e,t){const r=new RegExp(`\\${J}(\\??[\\w-_]+)\\${Q}`,"g");return Array.from(e.matchAll(r)).reduce((o,[a,s])=>{const l=Re(a);if(!l)return o;const i=wr(t,l);return ne([l],o),o[s]=i,o},{})}function ke(e,t){return{value:e,params:Oe(e,t)}}function gn(e,t){return F(t)?e.map(r=>{const n=`${t}${r.path.value}`;return{...r,path:ke(n,r.path.params)}}):e}class wn extends Error{constructor(t){super(`Invalid Name "${t}": Router does not support multiple routes with the same name. All name names must be unique.`)}}function vn(e){const t=e.map(({name:r})=>r);for(const r of t)if(Ze(t,r)>1)throw new wn(r)}function En(e,t=[],r){const n=[...e,...t.map(o=>o.routes)].flat();return vn(n),gn(n,r)}function Pn(e={},t=[]){const r=new Z;return ce("onBeforeRouteEnter",e,t).forEach(n=>r.onBeforeRouteEnter.add(n)),ce("onBeforeRouteUpdate",e,t).forEach(n=>r.onBeforeRouteUpdate.add(n)),ce("onBeforeRouteLeave",e,t).forEach(n=>r.onBeforeRouteLeave.add(n)),ce("onAfterRouteEnter",e,t).forEach(n=>r.onAfterRouteEnter.add(n)),ce("onAfterRouteUpdate",e,t).forEach(n=>r.onAfterRouteUpdate.add(n)),ce("onAfterRouteLeave",e,t).forEach(n=>r.onAfterRouteLeave.add(n)),r}function ce(e,t,r){return[t[e],...r.map(o=>o[e])].flat().filter(o=>o!==void 0)}function bn(e,t,r=[]){const n=En(e,r,t==null?void 0:t.base),o=$r();o.addGlobalRouteHooks(Pn(t,r));const a=Ve(),s=Vn(),l=Fr(),i=Br({mode:t==null?void 0:t.historyMode,listener:({location:S})=>{const C=X(S);d(C,{state:S.state,replace:!0})}});function u(S,C={}){return yn(n,S,C.state)}async function d(S,C={}){const G=a();if(i.stopListening(),v(S)){i.update(S,C);return}const T=u(S,C)??m("NotFound"),I=O(G),K=await o.runBeforeRouteHooks({to:T,from:I});switch(K.status){case"ABORT":return;case"PUSH":i.update(S,C),await P(...K.to);return;case"REJECT":i.update(S,C),w(K.type);break;case"SUCCESS":i.update(S,C),w(null);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(K)}`)}const Je=G;s.setProps(T).then(D=>{if(Je===G)switch(D.status){case"SUCCESS":break;case"PUSH":P(...D.to);break;case"REJECT":w(D.type);break;default:const Ge=D;throw new Error(`Switch is not exhaustive for prop store response status: ${JSON.stringify(Ge)}`)}}),k(T);const M=await o.runAfterRouteHooks({to:T,from:I});switch(M.status){case"PUSH":await P(...M.to);break;case"REJECT":w(M.type);break;case"SUCCESS":break;default:const D=M;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(D)}`)}i.startListening()}const R=(S,C={},G={})=>{const T=n.find(I=>I.name===S);if(!T)throw new Gr(String(S));return fn(T,C,G)},P=(S,C,G)=>{if(N(S)){const M={...C},D=Nt(S,{searchParams:M.query,hash:M.hash});return d(D,M)}if(typeof S=="string"){const{replace:M,...D}={...G},Ge={...C},Qe=R(S,Ge,D),Jn=Pt({...Qe.matched.state},{...Qe.state,...D.state});return d(Qe.href,{replace:M,state:Jn})}const{replace:T,...I}={...C},K=Pt({...S.matched.state},{...S.state,...I.state}),Je=Nt(S.href,{searchParams:I.query,hash:I.hash});return d(Je,{replace:T,state:K})},b=(S,C,G)=>{if(N(S)){const I={...C,replace:!0};return P(S,I)}if(typeof S=="string"){const I={...G,replace:!0},K={...C};return P(S,K,I)}const T={...C,replace:!0};return P(S,T)},y=S=>{w(S)},{setRejection:w,rejection:f,getRejectionRoute:m}=Or({...r.reduce((S,C)=>({...S,...C.rejections}),{}),...t==null?void 0:t.rejections}),U=m("NotFound"),{currentRoute:g,routerRoute:E,updateRoute:k}=kr(U,P),L=Dr(t==null?void 0:t.initialUrl),p=i.location.state,{host:h}=q(L),v=xr(h);let x=!1;const{promise:B,resolve:V}=Promise.withResolvers();async function j(){if(x)return B;x=!0,await d(L,{replace:!0,state:p}),i.startListening(),V()}function _(){i.stopListening()}function O(S){return Ir(S)?null:{...g}}function rr(S){S.component("RouterView",Yt),S.component("RouterLink",Qt),S.provide(dt,f),S.provide(wt,o),S.provide(Mt,s),S.provide(bt,l),S.provide(Xe,nr),j()}const nr={route:E,resolve:R,find:u,push:P,replace:b,reject:y,refresh:i.refresh,forward:i.forward,back:i.back,go:i.go,install:rr,isExternal:v,onBeforeRouteEnter:o.onBeforeRouteEnter,onBeforeRouteUpdate:o.onBeforeRouteUpdate,onBeforeRouteLeave:o.onBeforeRouteLeave,onAfterRouteEnter:o.onAfterRouteEnter,onAfterRouteUpdate:o.onAfterRouteUpdate,onAfterRouteLeave:o.onAfterRouteLeave,prefetch:t==null?void 0:t.prefetch,start:j,stop:_};return nr}function Te(e,t){return{value:e,params:Oe(e,t)}}function Sn(e){return{routes:e.routes??[],rejections:e.rejections??{},...e}}function jt(e,t){return{value:e,params:Oe(e,t)}}function An(e){return ue(e)&&typeof e.hash=="string"}function Ht(e){return e===void 0?ge():An(e)?e:ge(e)}function $t(e){return e===void 0?"":e}function kn(e){return ue(e)&&typeof e.value=="string"}function qt(e){return e===void 0?ke("",{}):kn(e)?e:ke(e,{})}function Un(e){return ue(e)&&typeof e.value=="string"}function _t(e){return e===void 0?Te("",{}):Un(e)?e:Te(e,{})}function ee(e,t){const r=Ne(),n=$t(e.name),o=qt(e.path),a=_t(e.query),s=Ht(e.hash),l=e.meta??{},i=pr(e)?e.state:{},u=c.markRaw({id:r,meta:{},state:{},...e,props:t}),d={id:r,matched:u,matches:[u],name:n,path:o,query:a,hash:s,meta:l,state:i,depth:1,host:jt("",{}),prefetch:e.prefetch},R=et(e)?nt(e.parent,d):d;return ne(R.path.params,R.query.params),R}const Ue={template:"<div>This is component</div>"},De=ee({name:"parentA",path:"/parentA/[paramA]"}),It=ee({parent:De,name:"parentA.childA",path:"/childA/[?paramB]"}),Ln=ee({parent:De,name:"parentA.childB",path:"/childB/[paramD]",component:Ue}),xn=ee({parent:It,name:"parentA.childA.grandChildA",path:"/[paramC]",component:Ue});ee({name:"parentB",path:"/parentB",component:Ue}),ee({name:"parentC",path:"/",component:Ue});const Bn="lazy",Cn={components:!0,props:!1};function Le(e){return["eager","lazy","intent"].includes(e)}function Ot({routerPrefetch:e,routePrefetch:t,linkPrefetch:r},n){const o=Me(r,n),a=Me(t,n),s=Me(e,n),l=[o,a,s,Cn[n],Bn].reduce((i,u)=>Le(i)?i:i===!0&&Le(u)?u:i===!0&&!Le(u)?i:i===void 0?u:i,void 0);return Le(l)?l:!1}function Me(e,t){return ue(e)?e[t]:e}function Tt(e){return typeof e=="object"&&e!==null&&"then"in e}function Dt(e){try{const t=e();return Tt(t)?t.catch(r=>r):t}catch(t){return t}}const Mt=Symbol();function Vn(){const e=c.reactive(new Map),{push:t,replace:r,reject:n}=yt(),o=(R,P,b)=>P.matches.filter(y=>Ot({...b,routePrefetch:y.prefetch},"props")===R).flatMap(y=>u(y)).reduce((y,{id:w,name:f,props:m})=>{if(!m)return y;const U=i(w,f,P),g=Dt(()=>m(P,{push:t,replace:r,reject:n}));return y[U]=g,y},{}),a=R=>{Object.entries(R).forEach(([P,b])=>{e.set(P,b)})},s=async R=>{const P=R.matches.flatMap(u),b=[],y=[];for(const{id:w,name:f,props:m}of P){if(!m)continue;const U=i(w,f,R);if(b.push(U),!e.has(U)){const g=Dt(()=>m(R,{push:t,replace:r,reject:n}));e.set(U,g)}y.push((async()=>{const g=await e.get(U);if(g instanceof Error)throw g})())}d(b);try{return await Promise.all(y),{status:"SUCCESS"}}catch(w){if(w instanceof se||w instanceof be)return w.response;throw w}},l=(R,P,b)=>{const y=i(R,P,b);return e.get(y)};function i(R,P,b){return[R,P,b.id,JSON.stringify(b.params)].join("-")}function u(R){return hr(R)?[{id:R.id,name:"default",props:R.props}]:dr(R)?Object.entries(R.props).map(([P,b])=>({id:R.id,name:P,props:b})):[]}function d(R){for(const P in e.keys())R.includes(P)||e.delete(P)}return{getPrefetchProps:o,setPrefetchProps:a,getProps:l,setProps:s}}function Wt(){const e=c.inject(Mt);if(!e)throw new te;return e}const Nn=c.defineAsyncComponent(()=>new Promise(e=>{e({default:{template:"foo"}})}));function Ft(e){return e.name===Nn.name&&"__asyncLoader"in e}function Jt(e,t,r){c.watch(e,(n,o)=>{n&&n.addEventListener(t,r),o&&o.removeEventListener(t,r)},{immediate:!0}),c.onUnmounted(()=>{e.value&&e.value.removeEventListener(t,r)})}function jn(e){const t=new Map,r=c.ref(),{getPrefetchProps:n,setPrefetchProps:o}=Wt(),{isElementVisible:a}=Jr(r),s=()=>{const u=Array.from(t.values()).reduce((d,R)=>(Object.assign(d,R),d),{});o(u)};c.watch(()=>c.toValue(e),({route:u,...d})=>{t.clear(),u&&i("eager",u,d)},{immediate:!0}),c.watch(a,u=>{const{route:d,...R}=c.toValue(e);!d||!u||i("lazy",d,R)},{immediate:!0}),Jt(r,"focusin",l),Jt(r,"mouseover",l);function l(){const{route:u,...d}=c.toValue(e);u&&i("intent",u,d)}function i(u,d,R){Hn(u,d,R),t.has(u)||t.set(u,n(u,d,R))}return{element:r,commit:s}}function Hn(e,t,r){t.matches.forEach(n=>{Ot({...r,routePrefetch:n.prefetch},"components")===e&&(tt(n)&&Ft(n.component)&&n.component.__asyncLoader(),rt(n)&&Object.values(n.components).forEach(a=>{Ft(a)&&a.__asyncLoader()}))})}function We(e,t,{exact:r}={}){return Sr(e)?t===void 0?!0:r?e.matched.name===t:e.matches.map(n=>n.name).includes(t):!1}function Gt(e,t={},r={}){const n=ye(),o=c.computed(()=>{const y=c.toValue(e);return typeof y!="string"?y:N(y)?n.find(y,c.toValue(r)):n.resolve(y,c.toValue(t),c.toValue(r))}),a=c.computed(()=>{if(o.value)return o.value.href;const y=c.toValue(e);if(N(y))return y;console.error(new Error("Failed to resolve route in RouterLink."))}),s=c.computed(()=>We(n.route)&&n.route.matches.some(y=>{var w;return y.id===((w=o.value)==null?void 0:w.id)})),l=c.computed(()=>{var y;return n.route.id===((y=o.value)==null?void 0:y.id)}),i=c.computed(()=>!!a.value&&n.isExternal(a.value)),u=c.computed(()=>{const y=c.toValue(e);return typeof y!="string"||N(y)?c.toValue(t):c.toValue(r)}),{element:d,commit:R}=jn(()=>({route:o.value,routerPrefetch:n.prefetch,linkPrefetch:u.value.prefetch})),P=y=>{R();const w={replace:(y==null?void 0:y.replace)??u.value.replace,query:qe(u.value.query,y==null?void 0:y.query),hash:(y==null?void 0:y.hash)??u.value.hash,state:{...u.value.state,...y==null?void 0:y.state}},f=c.toValue(e);return N(f)||typeof f=="object"?n.push(f,w):n.push(f,c.toValue(t),w)};return{element:d,route:o,href:a,isMatch:s,isExactMatch:l,isExternal:i,push:P,replace:y=>P({...y,replace:!0})}}const $n=["href"],Qt=c.defineComponent({__name:"routerLink",props:{to:{},prefetch:{type:[Boolean,String,Object],default:void 0},query:{},hash:{},replace:{type:Boolean},state:{}},setup(e){const t=e,r=ye(),n=c.computed(()=>P(t.to)),o=c.computed(()=>b(t.to)),a=c.computed(()=>{const{to:w,...f}=t;return f}),{element:s,isMatch:l,isExactMatch:i,isExternal:u,push:d}=Gt(()=>typeof t.to=="function"?t.to(r.resolve):t.to,a),R=c.computed(()=>({"router-link--match":l.value,"router-link--exact-match":i.value}));function P(w){if(typeof w=="function"){const f=w(r.resolve);return P(f)}return N(w)?r.find(w):w}function b(w){if(typeof w=="function"){const f=w(r.resolve);return b(f)}return N(w)?w:w==null?void 0:w.href}function y(w){w.preventDefault(),d()}return(w,f)=>(c.openBlock(),c.createElementBlock("a",{ref_key:"element",ref:s,href:o.value,class:c.normalizeClass(["router-link",R.value]),onClick:y},[c.renderSlot(w.$slots,"default",c.normalizeProps(c.guardReactiveProps({route:n.value,isMatch:c.unref(l),isExactMatch:c.unref(i),isExternal:c.unref(u)})))],10,$n))}});function zt(e,t){const r=ye();function n(){if(!e)return;if(!We(r.route,e,t))throw new Ye(e,r.route.name)}return c.watch(r.route,n,{immediate:!0,deep:!0}),r.route}const Kt=Symbol();function Fe(){return c.inject(Kt,0)}function qn(e,t){return c.defineComponent({name:"PropsWrapper",expose:[],setup(){const r=t(),n=c.getCurrentInstance();return()=>r instanceof Error?"":Tt(r)?n!=null&&n.suspense?c.h(In(e,r)):c.h(_n(e,r)):c.h(e,r)}})}function _n(e,t){return c.defineComponent({name:"AsyncPropsWrapper",expose:[],setup(){const r=c.ref();return(async()=>r.value=await t)(),()=>r.value instanceof Error?"":r.value?c.h(e,r.value):""}})}function In(e,t){return c.defineComponent({name:"SuspenseAsyncPropsWrapper",expose:[],async setup(){const r=await t;return()=>c.h(e,r)}})}const Yt=c.defineComponent({__name:"routerView",props:{name:{default:"default"}},setup(e){const t=zt(),r=br(),n=Fe(),{getProps:o}=Wt(),a=c.resolveComponent("RouterView",!0);c.provide(Kt,n+1);const s=c.computed(()=>{if(r.value)return r.value.component;const u=t.matches.at(n);if(!u)return null;const d=l(u),R=o(u.id,e.name,t);return d?R?qn(d,()=>R):d:null});function l(u){return i(u)[e.name]}function i(u){return rt(u)?u.components:tt(u)?{default:u.component}:typeof a=="string"?{}:{default:a}}return(u,d)=>s.value?c.renderSlot(u.$slots,"default",c.normalizeProps(c.mergeProps({key:0},{route:c.unref(t),component:s.value,rejection:c.unref(r)})),()=>[(c.openBlock(),c.createBlock(c.resolveDynamicComponent(s.value)))]):c.createCommentVNode("",!0)}});function Xt(){const e=c.inject(wt);if(!e)throw new te;return e}function Zt(e){return t=>{const r=Fe(),o=Xt().addComponentBeforeRouteHook({lifecycle:e,hook:t,depth:r-1});return c.onUnmounted(o),o}}function er(e){return t=>{const r=Fe(),o=Xt().addComponentAfterRouteHook({lifecycle:e,hook:t,depth:r-1});return c.onUnmounted(o),o}}const On=Zt("onBeforeRouteLeave"),Tn=Zt("onBeforeRouteUpdate"),Dn=er("onAfterRouteLeave"),Mn=er("onAfterRouteUpdate");function Wn(e){return ue(e)&&typeof e.value=="string"}function tr(e){return Wn(e)?e:jt(e,{})}function Fn(e){const t=Ne(),r=$t(e.name),n=qt(e.path),o=_t(e.query),a=Ht(e.hash),s=e.meta??{},l=lr(e)?tr(e.host):tr(""),i=c.markRaw({id:t,meta:{},state:{},...e}),u={id:t,matched:i,matches:[i],name:r,host:l,path:n,query:o,hash:a,meta:s,depth:1,state:{}},d=et(e)?nt(e.parent,u):u;return ne(d.path.params,d.query.params,d.host.params),d}A.DuplicateParamsError=ze,A.MetaPropertyConflict=Ke,A.RouterLink=Qt,A.RouterNotInstalledError=te,A.RouterView=Yt,A.UseRouteInvalidError=Ye,A.asUrl=xe,A.createExternalRoute=Fn,A.createParam=ut,A.createRoute=ee,A.createRouter=bn,A.createRouterPlugin=Sn,A.isRoute=We,A.isUrl=N,A.onAfterRouteLeave=Dn,A.onAfterRouteUpdate=Mn,A.onBeforeRouteLeave=On,A.onBeforeRouteUpdate=Tn,A.path=ke,A.query=Te,A.useLink=Gt,A.useRoute=zt,A.useRouter=ye,A.withDefault=gr,Object.defineProperty(A,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.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/kitbagjs/router/issues"
|
|
7
7
|
},
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"@kitbag/eslint-config": "1.0.2",
|
|
36
36
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
37
37
|
"@vue/test-utils": "^2.4.6",
|
|
38
|
-
"eslint": "^9.
|
|
38
|
+
"eslint": "^9.18.0",
|
|
39
39
|
"globals": "^15.14.0",
|
|
40
|
-
"happy-dom": "^16.3
|
|
40
|
+
"happy-dom": "^16.5.3",
|
|
41
41
|
"typedoc": "^0.27.6",
|
|
42
42
|
"typedoc-plugin-markdown": "^4.4.1",
|
|
43
|
-
"typedoc-vitepress-theme": "^1.1.
|
|
44
|
-
"typescript": "^5.
|
|
43
|
+
"typedoc-vitepress-theme": "^1.1.2",
|
|
44
|
+
"typescript": "^5.7.3",
|
|
45
45
|
"vite": "^6.0.7",
|
|
46
|
-
"vite-plugin-dts": "^4.
|
|
46
|
+
"vite-plugin-dts": "^4.5.0",
|
|
47
47
|
"vitepress": "^1.5.0",
|
|
48
48
|
"vitest": "^2.1.6",
|
|
49
49
|
"vue-tsc": "^2.2.0"
|