@kitbag/router 0.0.3 → 0.1.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/README.md +2 -2
- package/dist/kitbag-router.d.ts +73 -7
- package/dist/kitbag-router.js +2 -1
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A simple and versatile mapping utility for Typescript.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.org/package
|
|
5
|
+
[](https://www.npmjs.org/package/@kitbag/router)
|
|
6
6
|
[](https://app.netlify.com/sites/kitbag-router/deploys)
|
|
7
7
|
|
|
8
8
|
Get started with the [documentation](https://kitbag-router.netlify.app/)
|
|
@@ -137,7 +137,7 @@ Give your route components a place to be mounted
|
|
|
137
137
|
</div>
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
This component can be mounted anywhere you want route components to be mounted. Nested routes can also have a nested `RouterView` which would be responsible for rendering any children that route may have.
|
|
140
|
+
This component can be mounted anywhere you want route components to be mounted. Nested routes can also have a nested `RouterView` which would be responsible for rendering any children that route may have. Read more about [nested routes](https://kitbag-router.netlify.app/core-concepts/defining-routes#nested-routes).
|
|
141
141
|
|
|
142
142
|
## RouterLink
|
|
143
143
|
|
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -127,12 +127,30 @@ declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
|
127
127
|
/**
|
|
128
128
|
* Represents properties for child routes, including required component, name, and path.
|
|
129
129
|
*/
|
|
130
|
-
declare type ChildRouteProps = WithHooks & {
|
|
130
|
+
export declare type ChildRouteProps = WithHooks & {
|
|
131
|
+
/**
|
|
132
|
+
* Name for route, used to create route keys and in navigation.
|
|
133
|
+
*/
|
|
131
134
|
name: string;
|
|
135
|
+
/**
|
|
136
|
+
* Children routes, expected type comes from `createRoutes()`
|
|
137
|
+
*/
|
|
132
138
|
disabled?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Path part of URL.
|
|
141
|
+
*/
|
|
133
142
|
path: string | Path;
|
|
143
|
+
/**
|
|
144
|
+
* Query (aka search) part of URL.
|
|
145
|
+
*/
|
|
134
146
|
query?: string | Query;
|
|
147
|
+
/**
|
|
148
|
+
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
149
|
+
*/
|
|
135
150
|
component: RouteComponent;
|
|
151
|
+
/**
|
|
152
|
+
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
153
|
+
*/
|
|
136
154
|
meta?: RouteMeta;
|
|
137
155
|
};
|
|
138
156
|
|
|
@@ -304,6 +322,13 @@ export declare function isParamGetSet(value: Param): value is ParamGetSet;
|
|
|
304
322
|
*/
|
|
305
323
|
export declare function isParamGetter(value: Param): value is ParamGetter;
|
|
306
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Type guard function to determine if a given route configuration is a parent route, based on the presence of children.
|
|
327
|
+
* @param value - The route configuration to check.
|
|
328
|
+
* @returns True if the route configuration has children, indicating it is a parent route.
|
|
329
|
+
*/
|
|
330
|
+
export declare function isParentRoute(value: RouteProps): value is ParentRouteProps;
|
|
331
|
+
|
|
307
332
|
declare type MakeOptional<T> = {
|
|
308
333
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
309
334
|
} & {
|
|
@@ -395,13 +420,34 @@ export declare type ParamSetter<T = any> = (value: T, extras: ParamExtras) => st
|
|
|
395
420
|
/**
|
|
396
421
|
* Represents properties common to parent routes in a route configuration, including hooks, path, and optional query parameters.
|
|
397
422
|
*/
|
|
398
|
-
declare type ParentRouteProps = WithHooks & {
|
|
423
|
+
export declare type ParentRouteProps = WithHooks & {
|
|
424
|
+
/**
|
|
425
|
+
* Name for route, used to create route keys and in navigation.
|
|
426
|
+
*/
|
|
399
427
|
name?: string;
|
|
428
|
+
/**
|
|
429
|
+
* Path part of URL.
|
|
430
|
+
*/
|
|
400
431
|
path: string | Path;
|
|
432
|
+
/**
|
|
433
|
+
* Query (aka search) part of URL.
|
|
434
|
+
*/
|
|
401
435
|
query?: string | Query;
|
|
436
|
+
/**
|
|
437
|
+
* Disabled routes will not ever match but can still provide physical structure, nested children behave normally.
|
|
438
|
+
*/
|
|
402
439
|
disabled?: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Children routes, expected type comes from `createRoutes()`
|
|
442
|
+
*/
|
|
403
443
|
children: Routes;
|
|
444
|
+
/**
|
|
445
|
+
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
446
|
+
*/
|
|
404
447
|
component?: RouteComponent;
|
|
448
|
+
/**
|
|
449
|
+
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
450
|
+
*/
|
|
405
451
|
meta?: RouteMeta;
|
|
406
452
|
};
|
|
407
453
|
|
|
@@ -539,11 +585,31 @@ export declare type RegisteredRoutes = Register extends {
|
|
|
539
585
|
*/
|
|
540
586
|
export declare type RegisteredRoutesKey = RoutesKey<RegisteredRoutes>;
|
|
541
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Represents a route that the router has matched to current browser location.
|
|
590
|
+
* @template TRoute - Underlying Route that has been resolved.
|
|
591
|
+
*/
|
|
542
592
|
declare type ResolvedRoute<TRoute extends Route = BaseResolvedRoute> = DeepReadonly<{
|
|
593
|
+
/**
|
|
594
|
+
* The specific route properties that were matched in the current route.
|
|
595
|
+
*/
|
|
543
596
|
matched: TRoute['matched'];
|
|
597
|
+
/**
|
|
598
|
+
* The specific route properties that were matched in the current route, including any ancestors.
|
|
599
|
+
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
600
|
+
*/
|
|
544
601
|
matches: RouteProps[];
|
|
602
|
+
/**
|
|
603
|
+
* Unique identifier for the route, generated by joining route `name` by period. Key is used for routing and for matching.
|
|
604
|
+
*/
|
|
545
605
|
key: TRoute['key'];
|
|
606
|
+
/**
|
|
607
|
+
* Accessor for query string values from user in the current browser location.
|
|
608
|
+
*/
|
|
546
609
|
query: ResolvedRouteQuery;
|
|
610
|
+
/**
|
|
611
|
+
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
612
|
+
*/
|
|
547
613
|
params: ExtractRouteParamTypes<TRoute>;
|
|
548
614
|
}>;
|
|
549
615
|
|
|
@@ -553,7 +619,7 @@ declare type ResolvedRouteQuery = {
|
|
|
553
619
|
};
|
|
554
620
|
|
|
555
621
|
/**
|
|
556
|
-
* Represents the structure of a route within the application.
|
|
622
|
+
* Represents the structure of a route within the application. Return value of `createRoutes`
|
|
557
623
|
* @template TKey - Represents the unique key identifying the route, typically a string.
|
|
558
624
|
* @template TPath - The type or structure of the route's path.
|
|
559
625
|
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
@@ -591,7 +657,7 @@ export declare type Route<TKey extends string | undefined = any, TPath extends s
|
|
|
591
657
|
/**
|
|
592
658
|
* Type alias for Vue components, which can be either synchronous or asynchronous components.
|
|
593
659
|
*/
|
|
594
|
-
declare type RouteComponent = Component | DefineComponent | AsyncComponentLoader;
|
|
660
|
+
export declare type RouteComponent = Component | DefineComponent | AsyncComponentLoader;
|
|
595
661
|
|
|
596
662
|
declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesKey<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
597
663
|
|
|
@@ -663,7 +729,7 @@ declare type RouteHookSuccessResponse = {
|
|
|
663
729
|
};
|
|
664
730
|
|
|
665
731
|
/**
|
|
666
|
-
* Represents additional metadata associated with a route, customizable via
|
|
732
|
+
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
667
733
|
* @example
|
|
668
734
|
* ```ts
|
|
669
735
|
* declare module '@kitbag/router' {
|
|
@@ -673,7 +739,7 @@ declare type RouteHookSuccessResponse = {
|
|
|
673
739
|
* }
|
|
674
740
|
* ```
|
|
675
741
|
*/
|
|
676
|
-
declare interface RouteMeta extends Record<string, unknown> {
|
|
742
|
+
export declare interface RouteMeta extends Record<string, unknown> {
|
|
677
743
|
}
|
|
678
744
|
|
|
679
745
|
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypes<RouteGetByKey<TRoutes, TKey>>;
|
|
@@ -681,7 +747,7 @@ declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = Ext
|
|
|
681
747
|
/**
|
|
682
748
|
* Unifies the properties of both parent and child routes, ensuring type safety and consistency across route configurations.
|
|
683
749
|
*/
|
|
684
|
-
declare type RouteProps = Readonly<ParentRouteProps | ChildRouteProps>;
|
|
750
|
+
export declare type RouteProps = Readonly<ParentRouteProps | ChildRouteProps>;
|
|
685
751
|
|
|
686
752
|
/**
|
|
687
753
|
* The Route properties originally provided to `createRoutes`. The only change is normalizing meta to always default to an empty object.
|
package/dist/kitbag-router.js
CHANGED
|
@@ -314,7 +314,7 @@ const xn = Me("onBeforeRouteUpdate"), An = Me("onBeforeRouteLeave"), Ln = Re("on
|
|
|
314
314
|
}
|
|
315
315
|
return (g, A) => (ie(), pt("a", {
|
|
316
316
|
href: r.value,
|
|
317
|
-
class: dt(u.value),
|
|
317
|
+
class: dt(["router-link", u.value]),
|
|
318
318
|
onClick: m
|
|
319
319
|
}, [
|
|
320
320
|
_e(g.$slots, "default", mt(yt({ resolved: r.value, match: c.value, exactMatch: s.value, isExternal: d.value })))
|
|
@@ -1420,6 +1420,7 @@ export {
|
|
|
1420
1420
|
$n as createRoutes,
|
|
1421
1421
|
Fe as isParamGetSet,
|
|
1422
1422
|
Ct as isParamGetter,
|
|
1423
|
+
En as isParentRoute,
|
|
1423
1424
|
Ln as onAfterRouteEnter,
|
|
1424
1425
|
Bn as onAfterRouteLeave,
|
|
1425
1426
|
Un as onAfterRouteUpdate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(w=typeof globalThis<"u"?globalThis:w||self,f(w["@kitbag/router"]={},w.Vue))})(this,function(w,f){"use strict";var fn=Object.defineProperty;var ln=(w,f,$)=>f in w?fn(w,f,{enumerable:!0,configurable:!0,writable:!0,value:$}):w[f]=$;var N=(w,f,$)=>(ln(w,typeof f!="symbol"?f+"":f,$),$);class $ 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 Y extends Error{constructor(){super("Router not installed")}}class Pe extends Error{constructor(t,n){super(`useRoute called with incorrect route. Given ${t}, expected ${n}`)}}const ie=Symbol();function Se(){const e=f.inject(ie);if(!e)throw new Y;return e}const ue=Symbol();function X(){const e=f.inject(ue);if(!e)throw new Y;return e}function Ae(e,t){return[e,t].filter(n=>!!n).join(".")}function ot(e){const t=X();function n(){if(!e)return;const r=t.route.matches.map(c=>c.name);if(!at(r).includes(e))throw new Pe(e,t.route.key)}return f.watch(t.route,n,{immediate:!0,deep:!0}),t.route}function at(e){return e.reduce((t,n)=>{const r=t.pop(),o=n?[Ae(r,n)]:[];return r?[...t,r,...o]:o},[])}const xe=Symbol();function fe(){return f.inject(xe,0)}class Z{constructor(){N(this,"onBeforeRouteEnter",new Set);N(this,"onBeforeRouteUpdate",new Set);N(this,"onBeforeRouteLeave",new Set);N(this,"onAfterRouteEnter",new Set);N(this,"onAfterRouteUpdate",new Set);N(this,"onAfterRouteLeave",new Set)}}class Be extends Error{}class Q extends Error{constructor(n){super("Error occurred during a router push operation.");N(this,"to");this.to=n}}class le extends Error{constructor(n){super(`Routing action rejected: ${n}`);N(this,"type");this.type=n}}function I(e){return Array.isArray(e)?e:[e]}function ct(e,t){const n=new Z;return e.matches.forEach((r,o)=>{r.onBeforeRouteEnter&&he(e,t,o)&&I(r.onBeforeRouteEnter).forEach(a=>n.onBeforeRouteEnter.add(a)),r.onBeforeRouteUpdate&&de(e,t,o)&&I(r.onBeforeRouteUpdate).forEach(a=>n.onBeforeRouteUpdate.add(a))}),t.matches.forEach((r,o)=>{r.onBeforeRouteLeave&&pe(e,t,o)&&I(r.onBeforeRouteLeave).forEach(a=>n.onBeforeRouteLeave.add(a))}),n}function st(e,t){const n=new Z;return e.matches.forEach((r,o)=>{r.onAfterRouteEnter&&he(e,t,o)&&I(r.onAfterRouteEnter).forEach(a=>n.onAfterRouteEnter.add(a)),r.onAfterRouteUpdate&&de(e,t,o)&&I(r.onAfterRouteUpdate).forEach(a=>n.onAfterRouteUpdate.add(a))}),t.matches.forEach((r,o)=>{r.onAfterRouteLeave&&pe(e,t,o)&&I(r.onAfterRouteLeave).forEach(a=>n.onAfterRouteLeave.add(a))}),n}function J(e){return typeof e!="string"?!1:/^(https?:\/\/|\/).*/g.test(e)}function it(){const e=c=>{throw new le(c)},t=(...c)=>{throw new Q(c)},n=(c,s,u)=>{if(J(c)){const g=s??{};throw new Q([c,{...g,replace:!0}])}const m=s,R=u??{};throw new Q([c,m,{...R,replace:!0}])},r=()=>{throw new Be};async function o({to:c,from:s,hooks:u}){const{global:m,component:R}=u,g=ct(c,s),L=[...m.onBeforeRouteEnter,...g.onBeforeRouteEnter,...m.onBeforeRouteUpdate,...g.onBeforeRouteUpdate,...R.onBeforeRouteUpdate,...m.onBeforeRouteLeave,...g.onBeforeRouteLeave,...R.onBeforeRouteLeave];try{const p=L.map(A=>A(c,{from:s,reject:e,push:t,replace:n,abort:r}));await Promise.all(p)}catch(p){if(p instanceof Q)return{status:"PUSH",to:p.to};if(p instanceof le)return{status:"REJECT",type:p.type};if(p instanceof Be)return{status:"ABORT"};throw p}return{status:"SUCCESS"}}async function a({to:c,from:s,hooks:u}){const{global:m,component:R}=u,g=st(c,s),L=[...R.onAfterRouteLeave,...g.onAfterRouteLeave,...m.onAfterRouteLeave,...R.onAfterRouteUpdate,...g.onAfterRouteUpdate,...m.onAfterRouteUpdate,...R.onAfterRouteEnter,...g.onAfterRouteEnter,...m.onAfterRouteEnter];try{const p=L.map(A=>A(c,{from:s,reject:e,push:t,replace:n}));await Promise.all(p)}catch(p){if(p instanceof Q)return{status:"PUSH",to:p.to};if(p instanceof le)return{status:"REJECT",type:p.type};throw p}return{status:"SUCCESS"}}return{runBeforeRouteHooks:o,runAfterRouteHooks:a}}const he=(e,t,n)=>{const r=e.matches,o=(t==null?void 0:t.matches)??[];return r.length<n||r[n]!==o[n]},pe=(e,t,n)=>{const r=e.matches,o=(t==null?void 0:t.matches)??[];return r.length<n||r[n]!==o[n]},de=(e,t,n)=>e.matches[n]===(t==null?void 0:t.matches[n]);function Le(e){switch(e){case"onBeforeRouteEnter":case"onAfterRouteEnter":return he;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return de;case"onBeforeRouteLeave":case"onAfterRouteLeave":return pe;default:throw new Error(`Switch is not exhaustive for lifecycle: ${e}`)}}class ut{constructor(){N(this,"global",new Z);N(this,"component",new Z)}addBeforeRouteHook({lifecycle:t,timing:n,depth:r,hook:o}){const a=Le(t),c=this[n][t],s=(u,m)=>{if(a(u,m.from,r))return o(u,m)};return c.add(s),()=>c.delete(s)}addAfterRouteHook({lifecycle:t,timing:n,depth:r,hook:o}){const a=Le(t),c=this[n][t],s=(u,m)=>{if(a(u,m.from,r))return o(u,m)};return c.add(s),()=>c.delete(s)}}const Ue=Symbol();function ft(){const e=new ut;return{onBeforeRouteEnter:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteEnter",hook:s,timing:"global",depth:0}),onBeforeRouteUpdate:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteUpdate",hook:s,timing:"global",depth:0}),onBeforeRouteLeave:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteLeave",hook:s,timing:"global",depth:0}),onAfterRouteEnter:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteEnter",hook:s,timing:"global",depth:0}),onAfterRouteUpdate:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteUpdate",hook:s,timing:"global",depth:0}),onAfterRouteLeave:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteLeave",hook:s,timing:"global",depth:0}),hooks:e}}function je(){const e=f.inject(Ue);if(!e)throw new Y;return e}function He(e){return t=>{const n=fe(),o=je().addBeforeRouteHook({lifecycle:e,hook:t,depth:n,timing:"component"});return f.onUnmounted(o),o}}function me(e){return t=>{const n=fe(),o=je().addAfterRouteHook({lifecycle:e,hook:t,depth:n,timing:"component"});return f.onUnmounted(o),o}}const lt=He("onBeforeRouteUpdate"),ht=He("onBeforeRouteLeave"),pt=me("onAfterRouteEnter"),dt=me("onAfterRouteUpdate"),mt=me("onAfterRouteLeave"),Rt=["href"],$e=f.defineComponent({__name:"routerLink",props:{to:{type:[String,Function]},query:{},replace:{type:Boolean}},setup(e){const t=e,n=X(),r=f.computed(()=>J(t.to)?t.to:t.to(n.resolve)),o=f.computed(()=>{const{to:g,...L}=t;return L}),a=f.computed(()=>{var g;return(g=n.find(r.value,o.value))==null?void 0:g.matched}),c=f.computed(()=>!!a.value&&n.route.matches.includes(f.readonly(a.value))),s=f.computed(()=>!!a.value&&n.route.matched===a.value),u=f.computed(()=>({"router-link--match":c.value,"router-link--exact-match":s.value})),m=f.computed(()=>{const{host:g}=new URL(r.value,window.location.origin);return g!==window.location.host});function R(g){g.preventDefault(),n.push(r.value,o.value)}return(g,L)=>(f.openBlock(),f.createElementBlock("a",{href:r.value,class:f.normalizeClass(u.value),onClick:R},[f.renderSlot(g.$slots,"default",f.normalizeProps(f.guardReactiveProps({resolved:r.value,match:c.value,exactMatch:s.value,isExternal:m.value})))],10,Rt))}}),Re=f.defineComponent({__name:"routerView",setup(e){const t=X(),n=Se(),r=fe();f.provide(xe,r+1);const o=f.computed(()=>{var c;const a=(c=t.route.matches[r])==null?void 0:c.component;return a?typeof a=="function"?f.defineAsyncComponent(a):a:null});return(a,c)=>f.unref(n)?(f.openBlock(),f.createBlock(f.resolveDynamicComponent(f.unref(n).component),{key:0})):f.renderSlot(a.$slots,"default",{key:1,route:f.unref(t).route,component:o.value},()=>[(f.openBlock(),f.createBlock(f.resolveDynamicComponent(o.value)))])}});function q(){return q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},q.apply(this,arguments)}var U;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(U||(U={}));var W=process.env.NODE_ENV!=="production"?function(e){return Object.freeze(e)}:function(e){return e};function D(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}var ee="beforeunload",yt="hashchange",Ne="popstate";function Ce(e){e===void 0&&(e={});var t=e,n=t.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var h=r.location,i=h.pathname,l=h.search,E=h.hash,b=o.state||{};return[b.idx,W({pathname:i,search:l,hash:E,state:b.usr||null,key:b.key||"default"})]}var c=null;function s(){if(c)p.call(c),c=null;else{var h=U.Pop,i=a(),l=i[0],E=i[1];if(p.length)if(l!=null){var b=R-l;b&&(c={action:h,location:E,retry:function(){k(b*-1)}},k(b))}else process.env.NODE_ENV!=="production"&&D(!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 j(h)}}r.addEventListener(Ne,s);var u=U.Pop,m=a(),R=m[0],g=m[1],L=F(),p=F();R==null&&(R=0,o.replaceState(q({},o.state,{idx:R}),""));function A(h){return typeof h=="string"?h:M(h)}function C(h,i){return i===void 0&&(i=null),W(q({pathname:g.pathname,hash:"",search:""},typeof h=="string"?G(h):h,{state:i,key:ne()}))}function V(h,i){return[{usr:h.state,key:h.key,idx:i},A(h)]}function H(h,i,l){return!p.length||(p.call({action:h,location:i,retry:l}),!1)}function j(h){u=h;var i=a();R=i[0],g=i[1],L.call({action:u,location:g})}function d(h,i){var l=U.Push,E=C(h,i);function b(){d(h,i)}if(H(l,E,b)){var x=V(E,R+1),y=x[0],S=x[1];try{o.pushState(y,"",S)}catch{r.location.assign(S)}j(l)}}function v(h,i){var l=U.Replace,E=C(h,i);function b(){v(h,i)}if(H(l,E,b)){var x=V(E,R),y=x[0],S=x[1];o.replaceState(y,"",S),j(l)}}function k(h){o.go(h)}var P={get action(){return u},get location(){return g},createHref:A,push:d,replace:v,go:k,back:function(){k(-1)},forward:function(){k(1)},listen:function(i){return L.push(i)},block:function(i){var l=p.push(i);return p.length===1&&r.addEventListener(ee,te),function(){l(),p.length||r.removeEventListener(ee,te)}}};return P}function gt(e){e===void 0&&(e={});var t=e,n=t.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var i=G(r.location.hash.substr(1)),l=i.pathname,E=l===void 0?"/":l,b=i.search,x=b===void 0?"":b,y=i.hash,S=y===void 0?"":y,B=o.state||{};return[B.idx,W({pathname:E,search:x,hash:S,state:B.usr||null,key:B.key||"default"})]}var c=null;function s(){if(c)p.call(c),c=null;else{var i=U.Pop,l=a(),E=l[0],b=l[1];if(p.length)if(E!=null){var x=R-E;x&&(c={action:i,location:b,retry:function(){P(x*-1)}},P(x))}else process.env.NODE_ENV!=="production"&&D(!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(i)}}r.addEventListener(Ne,s),r.addEventListener(yt,function(){var i=a(),l=i[1];M(l)!==M(g)&&s()});var u=U.Pop,m=a(),R=m[0],g=m[1],L=F(),p=F();R==null&&(R=0,o.replaceState(q({},o.state,{idx:R}),""));function A(){var i=document.querySelector("base"),l="";if(i&&i.getAttribute("href")){var E=r.location.href,b=E.indexOf("#");l=b===-1?E:E.slice(0,b)}return l}function C(i){return A()+"#"+(typeof i=="string"?i:M(i))}function V(i,l){return l===void 0&&(l=null),W(q({pathname:g.pathname,hash:"",search:""},typeof i=="string"?G(i):i,{state:l,key:ne()}))}function H(i,l){return[{usr:i.state,key:i.key,idx:l},C(i)]}function j(i,l,E){return!p.length||(p.call({action:i,location:l,retry:E}),!1)}function d(i){u=i;var l=a();R=l[0],g=l[1],L.call({action:u,location:g})}function v(i,l){var E=U.Push,b=V(i,l);function x(){v(i,l)}if(process.env.NODE_ENV!=="production"&&D(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(i)+")"),j(E,b,x)){var y=H(b,R+1),S=y[0],B=y[1];try{o.pushState(S,"",B)}catch{r.location.assign(B)}d(E)}}function k(i,l){var E=U.Replace,b=V(i,l);function x(){k(i,l)}if(process.env.NODE_ENV!=="production"&&D(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(i)+")"),j(E,b,x)){var y=H(b,R),S=y[0],B=y[1];o.replaceState(S,"",B),d(E)}}function P(i){o.go(i)}var h={get action(){return u},get location(){return g},createHref:C,push:v,replace:k,go:P,back:function(){P(-1)},forward:function(){P(1)},listen:function(l){return L.push(l)},block:function(l){var E=p.push(l);return p.length===1&&r.addEventListener(ee,te),function(){E(),p.length||r.removeEventListener(ee,te)}}};return h}function Ve(e){e===void 0&&(e={});var t=e,n=t.initialEntries,r=n===void 0?["/"]:n,o=t.initialIndex,a=r.map(function(d){var v=W(q({pathname:"/",search:"",hash:"",state:null,key:ne()},typeof d=="string"?G(d):d));return process.env.NODE_ENV!=="production"&&D(v.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(d)+")"),v}),c=_e(o??a.length-1,0,a.length-1),s=U.Pop,u=a[c],m=F(),R=F();function g(d){return typeof d=="string"?d:M(d)}function L(d,v){return v===void 0&&(v=null),W(q({pathname:u.pathname,search:"",hash:""},typeof d=="string"?G(d):d,{state:v,key:ne()}))}function p(d,v,k){return!R.length||(R.call({action:d,location:v,retry:k}),!1)}function A(d,v){s=d,u=v,m.call({action:s,location:u})}function C(d,v){var k=U.Push,P=L(d,v);function h(){C(d,v)}process.env.NODE_ENV!=="production"&&D(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(d)+")"),p(k,P,h)&&(c+=1,a.splice(c,a.length,P),A(k,P))}function V(d,v){var k=U.Replace,P=L(d,v);function h(){V(d,v)}process.env.NODE_ENV!=="production"&&D(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(d)+")"),p(k,P,h)&&(a[c]=P,A(k,P))}function H(d){var v=_e(c+d,0,a.length-1),k=U.Pop,P=a[v];function h(){H(d)}p(k,P,h)&&(c=v,A(k,P))}var j={get index(){return c},get action(){return s},get location(){return u},createHref:g,push:C,replace:V,go:H,back:function(){H(-1)},forward:function(){H(1)},listen:function(v){return m.push(v)},block:function(v){return R.push(v)}};return j}function _e(e,t,n){return Math.min(Math.max(e,t),n)}function te(e){e.preventDefault(),e.returnValue=""}function F(){var e=[];return{get length(){return e.length},push:function(n){return e.push(n),function(){e=e.filter(function(r){return r!==n})}},call:function(n){e.forEach(function(r){return r&&r(n)})}}}function ne(){return Math.random().toString(36).substr(2,8)}function M(e){var t=e.pathname,n=t===void 0?"/":t,r=e.search,o=r===void 0?"":r,a=e.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 G(e){var t={};if(e){var n=e.indexOf("#");n>=0&&(t.hash=e.substr(n),e=e.substr(0,n));var r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function wt(e,t){function n(r,o,a){if(typeof r=="object"){const s={...e.params,...r};return t(e.key,s,o)}const c={...e.params,[r]:o};return t(e.key,c,a)}return new Proxy(e,{get:(r,o,a)=>o==="update"?n:o==="params"?new Proxy(e.params,{set(c,s,u){return n(s,u),!0}}):Reflect.get(r,o,a)})}function vt(e,t){const n=f.reactive({...e}),r=c=>{Object.assign(n,{...c})},o=f.readonly(n),a=wt(o,t);return{currentRoute:o,routerRoute:a,updateRoute:r}}class re extends Error{}function Et(e){return e!==String&&e!==Boolean&&e!==Number}function qe(e){return typeof e=="function"&&Et(e)}function ye(e){return typeof e=="object"&&"get"in e&&typeof e.get=="function"&&"set"in e&&typeof e.set=="function"}function oe(e){return typeof e=="string"&&e.length>0}function bt(e,t){return e[t]??String}const Oe=Symbol();function Te(e){return Oe in e}function kt(e){return{[Oe]:!0,get:t=>{if(oe(t))return ge(t,e)},set:t=>oe(t)?we(t,e):""}}const _={invalid:e=>{throw new re(e)}},Pt={get:e=>e,set:(e,{invalid:t})=>{if(typeof e!="string")throw t();return e}},De={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()}},Me={get:(e,{invalid:t})=>{const n=Number(e);if(isNaN(n))throw t();return n},set:(e,{invalid:t})=>{if(typeof e!="number")throw t();return e.toString()}};function ge(e,t){if(e===void 0){if(Te(t))return t.get(e,_);throw new re}if(t===String)return Pt.get(e,_);if(t===Boolean)return De.get(e,_);if(t===Number)return Me.get(e,_);if(qe(t))return t(e,_);if(ye(t))return t.get(e,_);if(t instanceof RegExp){if(t.test(e))return e;throw new re}return e}function we(e,t){if(t===Boolean)return De.set(e,_);if(t===Number)return Me.set(e,_);if(ye(t))return t.set(e,_);try{return e.toString()}catch{throw new re}}function St(e){const t=ve(e.path.toString());return new RegExp(`^${t}$`,"i")}function At(e){const t=new URLSearchParams(e.query.toString());return Array.from(t.entries()).filter(([,n])=>!Ie(n)).map(([n,r])=>new RegExp(`${n}=${ve(r)}(&|$)`,"i"))}function ve(e){return[xt,Bt].reduce((t,n)=>n(t),e)}const Ee=":\\?([\\w]+)(?=\\W|$)",Ke=":([\\w]+)(?=\\W|$)";function xt(e){return e.replace(new RegExp(Ee,"g"),"[^\\/]*")}function Ie(e){return new RegExp(Ee,"g").test(e)}function Bt(e){return e.replace(new RegExp(Ke,"g"),"[^\\/]+")}function Lt(e){const[t]=ae(e,new RegExp(Ee,"g")),[n]=ae(e,new RegExp(Ke,"g"));return t??n}function ae(e,t){return Array.from(e.matchAll(t)).flatMap(([,...r])=>r.map(o=>oe(o)?o:""))}function We(e,t,n){const r=Fe(t,n),[o]=ae(e,r);return o}function Ut(e,t){if(!t)return e;const{name:n,param:r,value:o}=t,a=Fe(e,n);return ae(e,a).reduce((s,u)=>u===void 0?s:s.replace(u,()=>we(o,r)),e)}function Fe(e,t){const n=[jt,Ht,ve].reduce((r,o)=>o(r,t),e);return new RegExp(n,"g")}function jt(e,t){const n=new RegExp(`(:\\?${t})(?=\\W|$)`,"g");return e.replace(n,"([^\\/]*)")}function Ht(e,t){const n=new RegExp(`(:${t})(?=\\W|$)`,"g");return e.replace(n,"([^\\/]+)")}function Qe(e,...t){return t.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}`},e)}function $t(e,t={}){const{params:n={},query:r}=t,o={...e.path.params,...e.query.params},a=e.path.toString(),c=e.query.toString(),s=Nt(a,o,n),u=Ct(c,o,n);return Qe(s,u,r)}function Nt(e,t,n){return e.length?Object.entries(t).reduce((r,[o,a])=>Ut(r,{name:o,param:a,value:n[o]}),e):e}function Ct(e,t,n){if(!e.length)return{};const r=new URLSearchParams(e);return Array.from(r.entries()).reduce((o,[a,c])=>{const s=Lt(c);if(!s)return{...o,[a]:c};const u=we(n[s],t[s]);return Ie(c)&&n[s]===void 0&&u===""?o:{...o,[a]:u}},{})}function Je(e){return(t,n,r)=>{if(J(t))return Qe(t,(n??{}).query);const o=n??{},a=r??{},c=e.find(u=>u.key===t);if(!c)throw`Route not found: "${String(t)}"`;if(c.matched.disabled)throw`Route disabled: "${String(t)}"`;return $t(c,{params:o,query:a.query})}}function z(e){return!e.startsWith("http")?_t(e):Vt(e)}function Vt(e){const{protocol:t,host:n,pathname:r,search:o,searchParams:a,hash:c}=new URL(e,e);return{protocol:t,host:n,pathname:r,search:o,searchParams:a,hash:c}}function _t(e){const{pathname:t,search:n,searchParams:r,hash:o}=new URL(e,"https://localhost");return{pathname:t,search:n,searchParams:r,hash:o}}function Ge(e){const t=new URLSearchParams(e);return{get:n=>t.get(n),getAll:n=>t.getAll(n)}}const qt=(e,t)=>{try{ze(e,t)}catch{return!1}return!0},ze=(e,t)=>{const{pathname:n,search:r}=z(t);return{...Ot(e.path,n),...Tt(e.query,r)}};function Ot(e,t){const n={},r=decodeURIComponent(t);for(const[o,a]of Object.entries(e.params)){const c=We(r,e.toString(),o),s=ge(c,a);n[o]=s}return n}function Tt(e,t){const n={},r=new URLSearchParams(t);for(const[o,a]of Object.entries(e.params)){const c=r.get(o)??void 0,s=ge(c,a);n[o]=s}return n}const Dt=(e,t)=>{const{pathname:n}=z(t);return St(e).test(n)},Mt=(e,t)=>{const{search:n}=z(t);return At(e).every(o=>o.test(n))};function Kt(e){const{searchParams:t,pathname:n}=z(e),r=-1,o=1;return(a,c)=>{const s=Xe(a,t),u=Ye(a,n),m=Xe(c,t),R=Ye(c,n);return s+u>m+R?r:s+u<m+R?o:a.depth>c.depth?r:a.depth<c.depth?o:0}}function Ye(e,t){const n=Object.entries(e.path.params).filter(([,o])=>Te(o)).map(([o])=>o),r=n.filter(o=>We(t,e.path.toString(),o)===void 0);return n.length-r.length}function Xe(e,t){const n=new URLSearchParams(e.query.toString()),r=Array.from(n.keys()),o=r.filter(a=>!t.has(a));return r.length-o.length}function Ze(e,t){const n=[It,Dt,Mt,qt],r=Kt(t),o=e.filter(m=>n.every(R=>R(m,t))).sort(r);if(o.length===0)return;const[a]=o,{search:c}=z(t),s=Ge(c),u=ze(a,t);return f.readonly({matched:a.matched,matches:a.matches,key:a.key,query:s,params:u})}const It=e=>"name"in e.matched&&!!e.matched.name;function Wt(e){return(t,n={})=>{const o=Je(e)(t,n);return Ze(e,o)}}function et(){return typeof window<"u"&&typeof window.document<"u"}function Ft({mode:e,listener:t}){const n=Qt(e),r=(u,m)=>{if(m!=null&&m.replace)return n.replace(u);n.push(u)},o=()=>{const u=M(n.location);return n.replace(u)};let a;return{...n,update:r,refresh:o,startListening:()=>{a==null||a(),a=n.listen(t)},stopListening:()=>{a==null||a()}}}function Qt(e="auto"){switch(e){case"auto":return et()?Ce():Ve();case"browser":return Ce();case"memory":return Ve();case"hash":return gt();default:const t=e;throw new Error(`Switch is not exhaustive for mode: ${t}`)}}function Jt(e){return f.defineComponent(()=>()=>f.h("h1",e),{name:e,props:[]})}const tt=Symbol();function Gt({rejections:e}){const t=c=>{const s={...e};return f.markRaw(s[c]??Jt(c))},n=c=>{const s=f.markRaw(t(c)),u={name:c,path:"",component:s,meta:{}};return f.readonly({matched:u,matches:[u],key:c,query:Ge(""),params:{},[tt]:!0})},r=c=>c[tt]===!0,o=c=>{if(!c){a.value=null;return}const s=t(c);a.value={type:c,component:s}},a=f.ref(null);return{setRejection:o,rejection:a,getRejectionRoute:n,isRejectionRoute:r}}class zt extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function Yt(e){if(e)return e;if(et())return window.location.toString();throw new zt}function Xt(e,t={}){const n=Je(e),r=Ft({mode:t.historyMode,listener:()=>{const y=M(location);p(y)}}),{runBeforeRouteHooks:o,runAfterRouteHooks:a}=it(),{hooks:c,onBeforeRouteEnter:s,onAfterRouteUpdate:u,onBeforeRouteLeave:m,onAfterRouteEnter:R,onBeforeRouteUpdate:g,onAfterRouteLeave:L}=ft();async function p(y,{replace:S}={}){r.stopListening();const B=Ze(e,y)??v("NotFound"),O={...P},K=await o({to:B,from:O,hooks:c});switch(K.status){case"ABORT":return;case"PUSH":r.update(y,{replace:S}),await A(...K.to);return;case"REJECT":r.update(y,{replace:S}),j(K.type),i(B);break;case"SUCCESS":r.update(y,{replace:S}),j(null),i(B);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(K)}`)}const T=await a({to:B,from:O,hooks:c});switch(T.status){case"PUSH":await A(...T.to);break;case"REJECT":j(T.type);break;case"SUCCESS":break;default:const se=T;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(se)}`)}r.startListening()}const A=(y,S,B)=>{if(J(y)){const se={...S},un=n(y,se);return p(un,{replace:se.replace})}const O={...B},T=n(y,S??{},O);return p(T,{replace:O.replace})},C=(y,S,B)=>{if(J(y)){const T={...S,replace:!0};return A(y,T)}const O=S??{},K={...B,replace:!0};return A(y,O,K)},V=y=>j(y),H=Wt(e),{setRejection:j,rejection:d,getRejectionRoute:v}=Gt(t),k=v("NotFound"),{currentRoute:P,routerRoute:h,updateRoute:i}=vt(k,A);r.startListening();const l=Yt(t.initialUrl),E=p(l,{replace:!0});function b(y){y.component("RouterView",Re),y.component("RouterLink",$e),y.provide(ue,x),y.provide(ie,d),y.provide(Ue,c)}const x={route:h,resolve:n,push:A,replace:C,reject:V,find:H,refresh:r.refresh,forward:r.forward,back:r.back,go:r.go,install:b,initialized:E,onBeforeRouteEnter:s,onAfterRouteUpdate:u,onBeforeRouteLeave:m,onAfterRouteEnter:R,onBeforeRouteUpdate:g,onAfterRouteLeave:L};return x}function nt(e,t){const n=/:\??([\w]+)(?=\W|$)/g;return Array.from(e.matchAll(n)).reduce((o,[a,c])=>{const s=a.startsWith(":?"),u=bt(t,c);if(c in o)throw new $(c);return o[c]=s?kt(u):u,o},{})}function be(e,t){return{path:e,params:nt(e,t),toString:()=>e}}function ke(e,t){const n=Object.keys(e),r=Object.keys(t),o=n.find(a=>r.includes(a));return o?{key:o,hasDuplicates:!0}:{key:void 0,hasDuplicates:!1}}function Zt(e,t){const{hasDuplicates:n,key:r}=ke(e.params,t.params);if(n)throw new $(r);return be(`${e.path}${t.path}`,{...e.params,...t.params})}function ce(e,t){return{query:e,params:nt(e,t),toString:()=>e}}function en(e,t){const{hasDuplicates:n,key:r}=ke(e.params,t.params);if(n)throw new $(r);const o=[e.query,t.query].filter(oe).join("&");return ce(o,{...e.params,...t.params})}function rt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function tn(e){return rt(e)&&typeof e.path=="string"}function nn(e){return tn(e)?e:be(e,{})}function rn(e){return rt(e)&&typeof e.query=="string"}function on(e){return e===void 0?ce("",{}):rn(e)?e:ce(e,{})}function an(e){return"children"in e}function cn(e){const t=e.reduce((n,r)=>{const o=sn({...r,component:r.component??Re});return an(r)&&n.push(...r.children.map(a=>({...a,key:Ae(o.key,a.key),path:Zt(o.path,a.path),query:en(o.query,a.query),matches:[o.matched,...a.matches],depth:a.depth+1}))),n.push(o),n},[]);return t.forEach(({path:n,query:r})=>{const{hasDuplicates:o,key:a}=ke(n.params,r.params);if(o)throw new $(a)}),t}function sn(e){const t=nn(e.path),n=on(e.query),r=f.markRaw({meta:{},...e});return{matched:r,matches:[r],key:e.name,path:t,query:n,depth:1,disabled:e.disabled??!1}}w.DuplicateParamsError=$,w.RouterLink=$e,w.RouterNotInstalledError=Y,w.RouterView=Re,w.UseRouteInvalidError=Pe,w.createRouter=Xt,w.createRoutes=cn,w.isParamGetSet=ye,w.isParamGetter=qe,w.onAfterRouteEnter=pt,w.onAfterRouteLeave=dt,w.onAfterRouteUpdate=mt,w.onBeforeRouteLeave=lt,w.onBeforeRouteUpdate=ht,w.path=be,w.query=ce,w.routerInjectionKey=ue,w.routerRejectionKey=ie,w.useRejection=Se,w.useRoute=ot,w.useRouter=X,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(g,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(g=typeof globalThis<"u"?globalThis:g||self,f(g["@kitbag/router"]={},g.Vue))})(this,function(g,f){"use strict";var fn=Object.defineProperty;var ln=(g,f,$)=>f in g?fn(g,f,{enumerable:!0,configurable:!0,writable:!0,value:$}):g[f]=$;var N=(g,f,$)=>(ln(g,typeof f!="symbol"?f+"":f,$),$);class $ 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 Y extends Error{constructor(){super("Router not installed")}}class Pe extends Error{constructor(t,n){super(`useRoute called with incorrect route. Given ${t}, expected ${n}`)}}const ie=Symbol();function Se(){const e=f.inject(ie);if(!e)throw new Y;return e}const ue=Symbol();function X(){const e=f.inject(ue);if(!e)throw new Y;return e}function Ae(e,t){return[e,t].filter(n=>!!n).join(".")}function at(e){const t=X();function n(){if(!e)return;const r=t.route.matches.map(c=>c.name);if(!ct(r).includes(e))throw new Pe(e,t.route.key)}return f.watch(t.route,n,{immediate:!0,deep:!0}),t.route}function ct(e){return e.reduce((t,n)=>{const r=t.pop(),o=n?[Ae(r,n)]:[];return r?[...t,r,...o]:o},[])}const xe=Symbol();function fe(){return f.inject(xe,0)}class Z{constructor(){N(this,"onBeforeRouteEnter",new Set);N(this,"onBeforeRouteUpdate",new Set);N(this,"onBeforeRouteLeave",new Set);N(this,"onAfterRouteEnter",new Set);N(this,"onAfterRouteUpdate",new Set);N(this,"onAfterRouteLeave",new Set)}}class Be extends Error{}class Q extends Error{constructor(n){super("Error occurred during a router push operation.");N(this,"to");this.to=n}}class le extends Error{constructor(n){super(`Routing action rejected: ${n}`);N(this,"type");this.type=n}}function I(e){return Array.isArray(e)?e:[e]}function st(e,t){const n=new Z;return e.matches.forEach((r,o)=>{r.onBeforeRouteEnter&&he(e,t,o)&&I(r.onBeforeRouteEnter).forEach(a=>n.onBeforeRouteEnter.add(a)),r.onBeforeRouteUpdate&&de(e,t,o)&&I(r.onBeforeRouteUpdate).forEach(a=>n.onBeforeRouteUpdate.add(a))}),t.matches.forEach((r,o)=>{r.onBeforeRouteLeave&&pe(e,t,o)&&I(r.onBeforeRouteLeave).forEach(a=>n.onBeforeRouteLeave.add(a))}),n}function it(e,t){const n=new Z;return e.matches.forEach((r,o)=>{r.onAfterRouteEnter&&he(e,t,o)&&I(r.onAfterRouteEnter).forEach(a=>n.onAfterRouteEnter.add(a)),r.onAfterRouteUpdate&&de(e,t,o)&&I(r.onAfterRouteUpdate).forEach(a=>n.onAfterRouteUpdate.add(a))}),t.matches.forEach((r,o)=>{r.onAfterRouteLeave&&pe(e,t,o)&&I(r.onAfterRouteLeave).forEach(a=>n.onAfterRouteLeave.add(a))}),n}function J(e){return typeof e!="string"?!1:/^(https?:\/\/|\/).*/g.test(e)}function ut(){const e=c=>{throw new le(c)},t=(...c)=>{throw new Q(c)},n=(c,s,u)=>{if(J(c)){const w=s??{};throw new Q([c,{...w,replace:!0}])}const m=s,R=u??{};throw new Q([c,m,{...R,replace:!0}])},r=()=>{throw new Be};async function o({to:c,from:s,hooks:u}){const{global:m,component:R}=u,w=st(c,s),L=[...m.onBeforeRouteEnter,...w.onBeforeRouteEnter,...m.onBeforeRouteUpdate,...w.onBeforeRouteUpdate,...R.onBeforeRouteUpdate,...m.onBeforeRouteLeave,...w.onBeforeRouteLeave,...R.onBeforeRouteLeave];try{const p=L.map(A=>A(c,{from:s,reject:e,push:t,replace:n,abort:r}));await Promise.all(p)}catch(p){if(p instanceof Q)return{status:"PUSH",to:p.to};if(p instanceof le)return{status:"REJECT",type:p.type};if(p instanceof Be)return{status:"ABORT"};throw p}return{status:"SUCCESS"}}async function a({to:c,from:s,hooks:u}){const{global:m,component:R}=u,w=it(c,s),L=[...R.onAfterRouteLeave,...w.onAfterRouteLeave,...m.onAfterRouteLeave,...R.onAfterRouteUpdate,...w.onAfterRouteUpdate,...m.onAfterRouteUpdate,...R.onAfterRouteEnter,...w.onAfterRouteEnter,...m.onAfterRouteEnter];try{const p=L.map(A=>A(c,{from:s,reject:e,push:t,replace:n}));await Promise.all(p)}catch(p){if(p instanceof Q)return{status:"PUSH",to:p.to};if(p instanceof le)return{status:"REJECT",type:p.type};throw p}return{status:"SUCCESS"}}return{runBeforeRouteHooks:o,runAfterRouteHooks:a}}const he=(e,t,n)=>{const r=e.matches,o=(t==null?void 0:t.matches)??[];return r.length<n||r[n]!==o[n]},pe=(e,t,n)=>{const r=e.matches,o=(t==null?void 0:t.matches)??[];return r.length<n||r[n]!==o[n]},de=(e,t,n)=>e.matches[n]===(t==null?void 0:t.matches[n]);function Le(e){switch(e){case"onBeforeRouteEnter":case"onAfterRouteEnter":return he;case"onBeforeRouteUpdate":case"onAfterRouteUpdate":return de;case"onBeforeRouteLeave":case"onAfterRouteLeave":return pe;default:throw new Error(`Switch is not exhaustive for lifecycle: ${e}`)}}class ft{constructor(){N(this,"global",new Z);N(this,"component",new Z)}addBeforeRouteHook({lifecycle:t,timing:n,depth:r,hook:o}){const a=Le(t),c=this[n][t],s=(u,m)=>{if(a(u,m.from,r))return o(u,m)};return c.add(s),()=>c.delete(s)}addAfterRouteHook({lifecycle:t,timing:n,depth:r,hook:o}){const a=Le(t),c=this[n][t],s=(u,m)=>{if(a(u,m.from,r))return o(u,m)};return c.add(s),()=>c.delete(s)}}const Ue=Symbol();function lt(){const e=new ft;return{onBeforeRouteEnter:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteEnter",hook:s,timing:"global",depth:0}),onBeforeRouteUpdate:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteUpdate",hook:s,timing:"global",depth:0}),onBeforeRouteLeave:s=>e.addBeforeRouteHook({lifecycle:"onBeforeRouteLeave",hook:s,timing:"global",depth:0}),onAfterRouteEnter:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteEnter",hook:s,timing:"global",depth:0}),onAfterRouteUpdate:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteUpdate",hook:s,timing:"global",depth:0}),onAfterRouteLeave:s=>e.addAfterRouteHook({lifecycle:"onAfterRouteLeave",hook:s,timing:"global",depth:0}),hooks:e}}function je(){const e=f.inject(Ue);if(!e)throw new Y;return e}function He(e){return t=>{const n=fe(),o=je().addBeforeRouteHook({lifecycle:e,hook:t,depth:n,timing:"component"});return f.onUnmounted(o),o}}function me(e){return t=>{const n=fe(),o=je().addAfterRouteHook({lifecycle:e,hook:t,depth:n,timing:"component"});return f.onUnmounted(o),o}}const ht=He("onBeforeRouteUpdate"),pt=He("onBeforeRouteLeave"),dt=me("onAfterRouteEnter"),mt=me("onAfterRouteUpdate"),Rt=me("onAfterRouteLeave"),yt=["href"],$e=f.defineComponent({__name:"routerLink",props:{to:{type:[String,Function]},query:{},replace:{type:Boolean}},setup(e){const t=e,n=X(),r=f.computed(()=>J(t.to)?t.to:t.to(n.resolve)),o=f.computed(()=>{const{to:w,...L}=t;return L}),a=f.computed(()=>{var w;return(w=n.find(r.value,o.value))==null?void 0:w.matched}),c=f.computed(()=>!!a.value&&n.route.matches.includes(f.readonly(a.value))),s=f.computed(()=>!!a.value&&n.route.matched===a.value),u=f.computed(()=>({"router-link--match":c.value,"router-link--exact-match":s.value})),m=f.computed(()=>{const{host:w}=new URL(r.value,window.location.origin);return w!==window.location.host});function R(w){w.preventDefault(),n.push(r.value,o.value)}return(w,L)=>(f.openBlock(),f.createElementBlock("a",{href:r.value,class:f.normalizeClass(["router-link",u.value]),onClick:R},[f.renderSlot(w.$slots,"default",f.normalizeProps(f.guardReactiveProps({resolved:r.value,match:c.value,exactMatch:s.value,isExternal:m.value})))],10,yt))}}),Re=f.defineComponent({__name:"routerView",setup(e){const t=X(),n=Se(),r=fe();f.provide(xe,r+1);const o=f.computed(()=>{var c;const a=(c=t.route.matches[r])==null?void 0:c.component;return a?typeof a=="function"?f.defineAsyncComponent(a):a:null});return(a,c)=>f.unref(n)?(f.openBlock(),f.createBlock(f.resolveDynamicComponent(f.unref(n).component),{key:0})):f.renderSlot(a.$slots,"default",{key:1,route:f.unref(t).route,component:o.value},()=>[(f.openBlock(),f.createBlock(f.resolveDynamicComponent(o.value)))])}});function q(){return q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},q.apply(this,arguments)}var U;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(U||(U={}));var W=process.env.NODE_ENV!=="production"?function(e){return Object.freeze(e)}:function(e){return e};function D(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}var ee="beforeunload",gt="hashchange",Ne="popstate";function Ce(e){e===void 0&&(e={});var t=e,n=t.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var h=r.location,i=h.pathname,l=h.search,E=h.hash,b=o.state||{};return[b.idx,W({pathname:i,search:l,hash:E,state:b.usr||null,key:b.key||"default"})]}var c=null;function s(){if(c)p.call(c),c=null;else{var h=U.Pop,i=a(),l=i[0],E=i[1];if(p.length)if(l!=null){var b=R-l;b&&(c={action:h,location:E,retry:function(){k(b*-1)}},k(b))}else process.env.NODE_ENV!=="production"&&D(!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 j(h)}}r.addEventListener(Ne,s);var u=U.Pop,m=a(),R=m[0],w=m[1],L=F(),p=F();R==null&&(R=0,o.replaceState(q({},o.state,{idx:R}),""));function A(h){return typeof h=="string"?h:M(h)}function C(h,i){return i===void 0&&(i=null),W(q({pathname:w.pathname,hash:"",search:""},typeof h=="string"?G(h):h,{state:i,key:ne()}))}function V(h,i){return[{usr:h.state,key:h.key,idx:i},A(h)]}function H(h,i,l){return!p.length||(p.call({action:h,location:i,retry:l}),!1)}function j(h){u=h;var i=a();R=i[0],w=i[1],L.call({action:u,location:w})}function d(h,i){var l=U.Push,E=C(h,i);function b(){d(h,i)}if(H(l,E,b)){var x=V(E,R+1),y=x[0],S=x[1];try{o.pushState(y,"",S)}catch{r.location.assign(S)}j(l)}}function v(h,i){var l=U.Replace,E=C(h,i);function b(){v(h,i)}if(H(l,E,b)){var x=V(E,R),y=x[0],S=x[1];o.replaceState(y,"",S),j(l)}}function k(h){o.go(h)}var P={get action(){return u},get location(){return w},createHref:A,push:d,replace:v,go:k,back:function(){k(-1)},forward:function(){k(1)},listen:function(i){return L.push(i)},block:function(i){var l=p.push(i);return p.length===1&&r.addEventListener(ee,te),function(){l(),p.length||r.removeEventListener(ee,te)}}};return P}function wt(e){e===void 0&&(e={});var t=e,n=t.window,r=n===void 0?document.defaultView:n,o=r.history;function a(){var i=G(r.location.hash.substr(1)),l=i.pathname,E=l===void 0?"/":l,b=i.search,x=b===void 0?"":b,y=i.hash,S=y===void 0?"":y,B=o.state||{};return[B.idx,W({pathname:E,search:x,hash:S,state:B.usr||null,key:B.key||"default"})]}var c=null;function s(){if(c)p.call(c),c=null;else{var i=U.Pop,l=a(),E=l[0],b=l[1];if(p.length)if(E!=null){var x=R-E;x&&(c={action:i,location:b,retry:function(){P(x*-1)}},P(x))}else process.env.NODE_ENV!=="production"&&D(!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(i)}}r.addEventListener(Ne,s),r.addEventListener(gt,function(){var i=a(),l=i[1];M(l)!==M(w)&&s()});var u=U.Pop,m=a(),R=m[0],w=m[1],L=F(),p=F();R==null&&(R=0,o.replaceState(q({},o.state,{idx:R}),""));function A(){var i=document.querySelector("base"),l="";if(i&&i.getAttribute("href")){var E=r.location.href,b=E.indexOf("#");l=b===-1?E:E.slice(0,b)}return l}function C(i){return A()+"#"+(typeof i=="string"?i:M(i))}function V(i,l){return l===void 0&&(l=null),W(q({pathname:w.pathname,hash:"",search:""},typeof i=="string"?G(i):i,{state:l,key:ne()}))}function H(i,l){return[{usr:i.state,key:i.key,idx:l},C(i)]}function j(i,l,E){return!p.length||(p.call({action:i,location:l,retry:E}),!1)}function d(i){u=i;var l=a();R=l[0],w=l[1],L.call({action:u,location:w})}function v(i,l){var E=U.Push,b=V(i,l);function x(){v(i,l)}if(process.env.NODE_ENV!=="production"&&D(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.push("+JSON.stringify(i)+")"),j(E,b,x)){var y=H(b,R+1),S=y[0],B=y[1];try{o.pushState(S,"",B)}catch{r.location.assign(B)}d(E)}}function k(i,l){var E=U.Replace,b=V(i,l);function x(){k(i,l)}if(process.env.NODE_ENV!=="production"&&D(b.pathname.charAt(0)==="/","Relative pathnames are not supported in hash history.replace("+JSON.stringify(i)+")"),j(E,b,x)){var y=H(b,R),S=y[0],B=y[1];o.replaceState(S,"",B),d(E)}}function P(i){o.go(i)}var h={get action(){return u},get location(){return w},createHref:C,push:v,replace:k,go:P,back:function(){P(-1)},forward:function(){P(1)},listen:function(l){return L.push(l)},block:function(l){var E=p.push(l);return p.length===1&&r.addEventListener(ee,te),function(){E(),p.length||r.removeEventListener(ee,te)}}};return h}function Ve(e){e===void 0&&(e={});var t=e,n=t.initialEntries,r=n===void 0?["/"]:n,o=t.initialIndex,a=r.map(function(d){var v=W(q({pathname:"/",search:"",hash:"",state:null,key:ne()},typeof d=="string"?G(d):d));return process.env.NODE_ENV!=="production"&&D(v.pathname.charAt(0)==="/","Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: "+JSON.stringify(d)+")"),v}),c=_e(o??a.length-1,0,a.length-1),s=U.Pop,u=a[c],m=F(),R=F();function w(d){return typeof d=="string"?d:M(d)}function L(d,v){return v===void 0&&(v=null),W(q({pathname:u.pathname,search:"",hash:""},typeof d=="string"?G(d):d,{state:v,key:ne()}))}function p(d,v,k){return!R.length||(R.call({action:d,location:v,retry:k}),!1)}function A(d,v){s=d,u=v,m.call({action:s,location:u})}function C(d,v){var k=U.Push,P=L(d,v);function h(){C(d,v)}process.env.NODE_ENV!=="production"&&D(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.push("+JSON.stringify(d)+")"),p(k,P,h)&&(c+=1,a.splice(c,a.length,P),A(k,P))}function V(d,v){var k=U.Replace,P=L(d,v);function h(){V(d,v)}process.env.NODE_ENV!=="production"&&D(u.pathname.charAt(0)==="/","Relative pathnames are not supported in memory history.replace("+JSON.stringify(d)+")"),p(k,P,h)&&(a[c]=P,A(k,P))}function H(d){var v=_e(c+d,0,a.length-1),k=U.Pop,P=a[v];function h(){H(d)}p(k,P,h)&&(c=v,A(k,P))}var j={get index(){return c},get action(){return s},get location(){return u},createHref:w,push:C,replace:V,go:H,back:function(){H(-1)},forward:function(){H(1)},listen:function(v){return m.push(v)},block:function(v){return R.push(v)}};return j}function _e(e,t,n){return Math.min(Math.max(e,t),n)}function te(e){e.preventDefault(),e.returnValue=""}function F(){var e=[];return{get length(){return e.length},push:function(n){return e.push(n),function(){e=e.filter(function(r){return r!==n})}},call:function(n){e.forEach(function(r){return r&&r(n)})}}}function ne(){return Math.random().toString(36).substr(2,8)}function M(e){var t=e.pathname,n=t===void 0?"/":t,r=e.search,o=r===void 0?"":r,a=e.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 G(e){var t={};if(e){var n=e.indexOf("#");n>=0&&(t.hash=e.substr(n),e=e.substr(0,n));var r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function vt(e,t){function n(r,o,a){if(typeof r=="object"){const s={...e.params,...r};return t(e.key,s,o)}const c={...e.params,[r]:o};return t(e.key,c,a)}return new Proxy(e,{get:(r,o,a)=>o==="update"?n:o==="params"?new Proxy(e.params,{set(c,s,u){return n(s,u),!0}}):Reflect.get(r,o,a)})}function Et(e,t){const n=f.reactive({...e}),r=c=>{Object.assign(n,{...c})},o=f.readonly(n),a=vt(o,t);return{currentRoute:o,routerRoute:a,updateRoute:r}}class re extends Error{}function bt(e){return e!==String&&e!==Boolean&&e!==Number}function qe(e){return typeof e=="function"&&bt(e)}function ye(e){return typeof e=="object"&&"get"in e&&typeof e.get=="function"&&"set"in e&&typeof e.set=="function"}function oe(e){return typeof e=="string"&&e.length>0}function kt(e,t){return e[t]??String}const Oe=Symbol();function Te(e){return Oe in e}function Pt(e){return{[Oe]:!0,get:t=>{if(oe(t))return ge(t,e)},set:t=>oe(t)?we(t,e):""}}const _={invalid:e=>{throw new re(e)}},St={get:e=>e,set:(e,{invalid:t})=>{if(typeof e!="string")throw t();return e}},De={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()}},Me={get:(e,{invalid:t})=>{const n=Number(e);if(isNaN(n))throw t();return n},set:(e,{invalid:t})=>{if(typeof e!="number")throw t();return e.toString()}};function ge(e,t){if(e===void 0){if(Te(t))return t.get(e,_);throw new re}if(t===String)return St.get(e,_);if(t===Boolean)return De.get(e,_);if(t===Number)return Me.get(e,_);if(qe(t))return t(e,_);if(ye(t))return t.get(e,_);if(t instanceof RegExp){if(t.test(e))return e;throw new re}return e}function we(e,t){if(t===Boolean)return De.set(e,_);if(t===Number)return Me.set(e,_);if(ye(t))return t.set(e,_);try{return e.toString()}catch{throw new re}}function At(e){const t=ve(e.path.toString());return new RegExp(`^${t}$`,"i")}function xt(e){const t=new URLSearchParams(e.query.toString());return Array.from(t.entries()).filter(([,n])=>!Ie(n)).map(([n,r])=>new RegExp(`${n}=${ve(r)}(&|$)`,"i"))}function ve(e){return[Bt,Lt].reduce((t,n)=>n(t),e)}const Ee=":\\?([\\w]+)(?=\\W|$)",Ke=":([\\w]+)(?=\\W|$)";function Bt(e){return e.replace(new RegExp(Ee,"g"),"[^\\/]*")}function Ie(e){return new RegExp(Ee,"g").test(e)}function Lt(e){return e.replace(new RegExp(Ke,"g"),"[^\\/]+")}function Ut(e){const[t]=ae(e,new RegExp(Ee,"g")),[n]=ae(e,new RegExp(Ke,"g"));return t??n}function ae(e,t){return Array.from(e.matchAll(t)).flatMap(([,...r])=>r.map(o=>oe(o)?o:""))}function We(e,t,n){const r=Fe(t,n),[o]=ae(e,r);return o}function jt(e,t){if(!t)return e;const{name:n,param:r,value:o}=t,a=Fe(e,n);return ae(e,a).reduce((s,u)=>u===void 0?s:s.replace(u,()=>we(o,r)),e)}function Fe(e,t){const n=[Ht,$t,ve].reduce((r,o)=>o(r,t),e);return new RegExp(n,"g")}function Ht(e,t){const n=new RegExp(`(:\\?${t})(?=\\W|$)`,"g");return e.replace(n,"([^\\/]*)")}function $t(e,t){const n=new RegExp(`(:${t})(?=\\W|$)`,"g");return e.replace(n,"([^\\/]+)")}function Qe(e,...t){return t.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}`},e)}function Nt(e,t={}){const{params:n={},query:r}=t,o={...e.path.params,...e.query.params},a=e.path.toString(),c=e.query.toString(),s=Ct(a,o,n),u=Vt(c,o,n);return Qe(s,u,r)}function Ct(e,t,n){return e.length?Object.entries(t).reduce((r,[o,a])=>jt(r,{name:o,param:a,value:n[o]}),e):e}function Vt(e,t,n){if(!e.length)return{};const r=new URLSearchParams(e);return Array.from(r.entries()).reduce((o,[a,c])=>{const s=Ut(c);if(!s)return{...o,[a]:c};const u=we(n[s],t[s]);return Ie(c)&&n[s]===void 0&&u===""?o:{...o,[a]:u}},{})}function Je(e){return(t,n,r)=>{if(J(t))return Qe(t,(n??{}).query);const o=n??{},a=r??{},c=e.find(u=>u.key===t);if(!c)throw`Route not found: "${String(t)}"`;if(c.matched.disabled)throw`Route disabled: "${String(t)}"`;return Nt(c,{params:o,query:a.query})}}function z(e){return!e.startsWith("http")?qt(e):_t(e)}function _t(e){const{protocol:t,host:n,pathname:r,search:o,searchParams:a,hash:c}=new URL(e,e);return{protocol:t,host:n,pathname:r,search:o,searchParams:a,hash:c}}function qt(e){const{pathname:t,search:n,searchParams:r,hash:o}=new URL(e,"https://localhost");return{pathname:t,search:n,searchParams:r,hash:o}}function Ge(e){const t=new URLSearchParams(e);return{get:n=>t.get(n),getAll:n=>t.getAll(n)}}const Ot=(e,t)=>{try{ze(e,t)}catch{return!1}return!0},ze=(e,t)=>{const{pathname:n,search:r}=z(t);return{...Tt(e.path,n),...Dt(e.query,r)}};function Tt(e,t){const n={},r=decodeURIComponent(t);for(const[o,a]of Object.entries(e.params)){const c=We(r,e.toString(),o),s=ge(c,a);n[o]=s}return n}function Dt(e,t){const n={},r=new URLSearchParams(t);for(const[o,a]of Object.entries(e.params)){const c=r.get(o)??void 0,s=ge(c,a);n[o]=s}return n}const Mt=(e,t)=>{const{pathname:n}=z(t);return At(e).test(n)},Kt=(e,t)=>{const{search:n}=z(t);return xt(e).every(o=>o.test(n))};function It(e){const{searchParams:t,pathname:n}=z(e),r=-1,o=1;return(a,c)=>{const s=Xe(a,t),u=Ye(a,n),m=Xe(c,t),R=Ye(c,n);return s+u>m+R?r:s+u<m+R?o:a.depth>c.depth?r:a.depth<c.depth?o:0}}function Ye(e,t){const n=Object.entries(e.path.params).filter(([,o])=>Te(o)).map(([o])=>o),r=n.filter(o=>We(t,e.path.toString(),o)===void 0);return n.length-r.length}function Xe(e,t){const n=new URLSearchParams(e.query.toString()),r=Array.from(n.keys()),o=r.filter(a=>!t.has(a));return r.length-o.length}function Ze(e,t){const n=[Wt,Mt,Kt,Ot],r=It(t),o=e.filter(m=>n.every(R=>R(m,t))).sort(r);if(o.length===0)return;const[a]=o,{search:c}=z(t),s=Ge(c),u=ze(a,t);return f.readonly({matched:a.matched,matches:a.matches,key:a.key,query:s,params:u})}const Wt=e=>"name"in e.matched&&!!e.matched.name;function Ft(e){return(t,n={})=>{const o=Je(e)(t,n);return Ze(e,o)}}function et(){return typeof window<"u"&&typeof window.document<"u"}function Qt({mode:e,listener:t}){const n=Jt(e),r=(u,m)=>{if(m!=null&&m.replace)return n.replace(u);n.push(u)},o=()=>{const u=M(n.location);return n.replace(u)};let a;return{...n,update:r,refresh:o,startListening:()=>{a==null||a(),a=n.listen(t)},stopListening:()=>{a==null||a()}}}function Jt(e="auto"){switch(e){case"auto":return et()?Ce():Ve();case"browser":return Ce();case"memory":return Ve();case"hash":return wt();default:const t=e;throw new Error(`Switch is not exhaustive for mode: ${t}`)}}function Gt(e){return f.defineComponent(()=>()=>f.h("h1",e),{name:e,props:[]})}const tt=Symbol();function zt({rejections:e}){const t=c=>{const s={...e};return f.markRaw(s[c]??Gt(c))},n=c=>{const s=f.markRaw(t(c)),u={name:c,path:"",component:s,meta:{}};return f.readonly({matched:u,matches:[u],key:c,query:Ge(""),params:{},[tt]:!0})},r=c=>c[tt]===!0,o=c=>{if(!c){a.value=null;return}const s=t(c);a.value={type:c,component:s}},a=f.ref(null);return{setRejection:o,rejection:a,getRejectionRoute:n,isRejectionRoute:r}}class Yt extends Error{constructor(){super("initialUrl must be set if window.location is unavailable")}}function Xt(e){if(e)return e;if(et())return window.location.toString();throw new Yt}function Zt(e,t={}){const n=Je(e),r=Qt({mode:t.historyMode,listener:()=>{const y=M(location);p(y)}}),{runBeforeRouteHooks:o,runAfterRouteHooks:a}=ut(),{hooks:c,onBeforeRouteEnter:s,onAfterRouteUpdate:u,onBeforeRouteLeave:m,onAfterRouteEnter:R,onBeforeRouteUpdate:w,onAfterRouteLeave:L}=lt();async function p(y,{replace:S}={}){r.stopListening();const B=Ze(e,y)??v("NotFound"),O={...P},K=await o({to:B,from:O,hooks:c});switch(K.status){case"ABORT":return;case"PUSH":r.update(y,{replace:S}),await A(...K.to);return;case"REJECT":r.update(y,{replace:S}),j(K.type),i(B);break;case"SUCCESS":r.update(y,{replace:S}),j(null),i(B);break;default:throw new Error(`Switch is not exhaustive for before hook response status: ${JSON.stringify(K)}`)}const T=await a({to:B,from:O,hooks:c});switch(T.status){case"PUSH":await A(...T.to);break;case"REJECT":j(T.type);break;case"SUCCESS":break;default:const se=T;throw new Error(`Switch is not exhaustive for after hook response status: ${JSON.stringify(se)}`)}r.startListening()}const A=(y,S,B)=>{if(J(y)){const se={...S},un=n(y,se);return p(un,{replace:se.replace})}const O={...B},T=n(y,S??{},O);return p(T,{replace:O.replace})},C=(y,S,B)=>{if(J(y)){const T={...S,replace:!0};return A(y,T)}const O=S??{},K={...B,replace:!0};return A(y,O,K)},V=y=>j(y),H=Ft(e),{setRejection:j,rejection:d,getRejectionRoute:v}=zt(t),k=v("NotFound"),{currentRoute:P,routerRoute:h,updateRoute:i}=Et(k,A);r.startListening();const l=Xt(t.initialUrl),E=p(l,{replace:!0});function b(y){y.component("RouterView",Re),y.component("RouterLink",$e),y.provide(ue,x),y.provide(ie,d),y.provide(Ue,c)}const x={route:h,resolve:n,push:A,replace:C,reject:V,find:H,refresh:r.refresh,forward:r.forward,back:r.back,go:r.go,install:b,initialized:E,onBeforeRouteEnter:s,onAfterRouteUpdate:u,onBeforeRouteLeave:m,onAfterRouteEnter:R,onBeforeRouteUpdate:w,onAfterRouteLeave:L};return x}function nt(e,t){const n=/:\??([\w]+)(?=\W|$)/g;return Array.from(e.matchAll(n)).reduce((o,[a,c])=>{const s=a.startsWith(":?"),u=kt(t,c);if(c in o)throw new $(c);return o[c]=s?Pt(u):u,o},{})}function be(e,t){return{path:e,params:nt(e,t),toString:()=>e}}function ke(e,t){const n=Object.keys(e),r=Object.keys(t),o=n.find(a=>r.includes(a));return o?{key:o,hasDuplicates:!0}:{key:void 0,hasDuplicates:!1}}function en(e,t){const{hasDuplicates:n,key:r}=ke(e.params,t.params);if(n)throw new $(r);return be(`${e.path}${t.path}`,{...e.params,...t.params})}function ce(e,t){return{query:e,params:nt(e,t),toString:()=>e}}function tn(e,t){const{hasDuplicates:n,key:r}=ke(e.params,t.params);if(n)throw new $(r);const o=[e.query,t.query].filter(oe).join("&");return ce(o,{...e.params,...t.params})}function rt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function nn(e){return rt(e)&&typeof e.path=="string"}function rn(e){return nn(e)?e:be(e,{})}function on(e){return rt(e)&&typeof e.query=="string"}function an(e){return e===void 0?ce("",{}):on(e)?e:ce(e,{})}function ot(e){return"children"in e}function cn(e){const t=e.reduce((n,r)=>{const o=sn({...r,component:r.component??Re});return ot(r)&&n.push(...r.children.map(a=>({...a,key:Ae(o.key,a.key),path:en(o.path,a.path),query:tn(o.query,a.query),matches:[o.matched,...a.matches],depth:a.depth+1}))),n.push(o),n},[]);return t.forEach(({path:n,query:r})=>{const{hasDuplicates:o,key:a}=ke(n.params,r.params);if(o)throw new $(a)}),t}function sn(e){const t=rn(e.path),n=an(e.query),r=f.markRaw({meta:{},...e});return{matched:r,matches:[r],key:e.name,path:t,query:n,depth:1,disabled:e.disabled??!1}}g.DuplicateParamsError=$,g.RouterLink=$e,g.RouterNotInstalledError=Y,g.RouterView=Re,g.UseRouteInvalidError=Pe,g.createRouter=Zt,g.createRoutes=cn,g.isParamGetSet=ye,g.isParamGetter=qe,g.isParentRoute=ot,g.onAfterRouteEnter=dt,g.onAfterRouteLeave=mt,g.onAfterRouteUpdate=Rt,g.onBeforeRouteLeave=ht,g.onBeforeRouteUpdate=pt,g.path=be,g.query=ce,g.routerInjectionKey=ue,g.routerRejectionKey=ie,g.useRejection=Se,g.useRoute=at,g.useRouter=X,Object.defineProperty(g,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.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/kitbagjs/router/issues"
|
|
7
7
|
},
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"types": "vue-tsc --noEmit",
|
|
17
17
|
"docs:dev": "vitepress dev docs",
|
|
18
18
|
"docs:build": "vitepress build docs",
|
|
19
|
-
"docs:preview": "vitepress preview docs"
|
|
19
|
+
"docs:preview": "vitepress preview docs",
|
|
20
|
+
"docs:generate": "typedoc"
|
|
20
21
|
},
|
|
21
22
|
"type": "module",
|
|
22
23
|
"files": [
|
|
@@ -37,6 +38,9 @@
|
|
|
37
38
|
"@vue/test-utils": "^2.4.3",
|
|
38
39
|
"eslint": "^8.54.0",
|
|
39
40
|
"happy-dom": "^12.10.3",
|
|
41
|
+
"typedoc": "^0.25.13",
|
|
42
|
+
"typedoc-plugin-markdown": "^4.0.0",
|
|
43
|
+
"typedoc-plugin-vue": "^1.1.0",
|
|
40
44
|
"typescript": "^5.4.3",
|
|
41
45
|
"vite": "^5.2.7",
|
|
42
46
|
"vite-plugin-dts": "^3.8.1",
|