@real-router/core 0.38.0 → 0.40.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.
Files changed (89) hide show
  1. package/README.md +27 -5
  2. package/dist/cjs/Router-B-Pev7K2.d.ts +46 -0
  3. package/dist/cjs/RouterValidator-mx2Zooya.d.ts +136 -0
  4. package/dist/cjs/api.d.ts +2 -1
  5. package/dist/cjs/api.js +1 -1
  6. package/dist/cjs/api.js.map +1 -1
  7. package/dist/cjs/index.d-y2b-8_3Y.d.ts +236 -0
  8. package/dist/cjs/index.d.ts +7 -24
  9. package/dist/cjs/index.js +1 -1
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/metafile-cjs.json +1 -1
  12. package/dist/cjs/utils.d.ts +6 -1
  13. package/dist/cjs/utils.js +1 -1
  14. package/dist/cjs/utils.js.map +1 -1
  15. package/dist/cjs/validation.d.ts +184 -0
  16. package/dist/cjs/validation.js +1 -0
  17. package/dist/cjs/validation.js.map +1 -0
  18. package/dist/esm/Router-B-Pev7K2.d.mts +46 -0
  19. package/dist/esm/RouterValidator-mx2Zooya.d.mts +136 -0
  20. package/dist/esm/api.d.mts +2 -1
  21. package/dist/esm/api.mjs +1 -1
  22. package/dist/esm/api.mjs.map +1 -1
  23. package/dist/esm/chunk-5QXFUUDL.mjs +1 -0
  24. package/dist/esm/chunk-5QXFUUDL.mjs.map +1 -0
  25. package/dist/esm/chunk-HHIXK5UM.mjs +1 -0
  26. package/dist/esm/chunk-HHIXK5UM.mjs.map +1 -0
  27. package/dist/esm/chunk-QUUNDESP.mjs +1 -0
  28. package/dist/esm/chunk-QUUNDESP.mjs.map +1 -0
  29. package/dist/esm/chunk-RA5VYM7M.mjs +1 -0
  30. package/dist/esm/chunk-RA5VYM7M.mjs.map +1 -0
  31. package/dist/esm/index.d-y2b-8_3Y.d.mts +236 -0
  32. package/dist/esm/index.d.mts +7 -24
  33. package/dist/esm/index.mjs +1 -1
  34. package/dist/esm/metafile-esm.json +1 -1
  35. package/dist/esm/utils.d.mts +6 -1
  36. package/dist/esm/utils.mjs +1 -1
  37. package/dist/esm/utils.mjs.map +1 -1
  38. package/dist/esm/validation.d.mts +184 -0
  39. package/dist/esm/validation.mjs +1 -0
  40. package/dist/esm/validation.mjs.map +1 -0
  41. package/package.json +18 -5
  42. package/src/Router.ts +73 -99
  43. package/src/api/cloneRouter.ts +1 -30
  44. package/src/api/getDependenciesApi.ts +45 -86
  45. package/src/api/getLifecycleApi.ts +24 -19
  46. package/src/api/getPluginApi.ts +20 -28
  47. package/src/api/getRoutesApi.ts +49 -106
  48. package/src/constants.ts +0 -30
  49. package/src/guards.ts +46 -0
  50. package/src/helpers.ts +0 -17
  51. package/src/index.ts +4 -0
  52. package/src/internals.ts +6 -5
  53. package/src/namespaces/EventBusNamespace/EventBusNamespace.ts +2 -2
  54. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -25
  55. package/src/namespaces/OptionsNamespace/OptionsNamespace.ts +4 -26
  56. package/src/namespaces/OptionsNamespace/constants.ts +0 -20
  57. package/src/namespaces/OptionsNamespace/index.ts +1 -5
  58. package/src/namespaces/OptionsNamespace/validators.ts +6 -245
  59. package/src/namespaces/PluginsNamespace/PluginsNamespace.ts +18 -59
  60. package/src/namespaces/PluginsNamespace/constants.ts +3 -6
  61. package/src/namespaces/PluginsNamespace/validators.ts +2 -57
  62. package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +27 -84
  63. package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +0 -16
  64. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -12
  65. package/src/namespaces/RoutesNamespace/constants.ts +0 -8
  66. package/src/namespaces/RoutesNamespace/forwardChain.ts +34 -0
  67. package/src/namespaces/RoutesNamespace/index.ts +1 -1
  68. package/src/namespaces/RoutesNamespace/routeGuards.ts +62 -0
  69. package/src/namespaces/RoutesNamespace/routesStore.ts +7 -51
  70. package/src/namespaces/StateNamespace/StateNamespace.ts +0 -33
  71. package/src/namespaces/StateNamespace/helpers.ts +1 -1
  72. package/src/namespaces/index.ts +0 -3
  73. package/src/typeGuards.ts +1 -15
  74. package/src/types/RouterValidator.ts +155 -0
  75. package/src/utils/getStaticPaths.ts +50 -0
  76. package/src/utils/index.ts +4 -0
  77. package/src/validation.ts +12 -0
  78. package/src/wiring/RouterWiringBuilder.ts +32 -9
  79. package/dist/cjs/index.d-DDimDpYc.d.ts +0 -165
  80. package/dist/esm/chunk-CG7TKDP3.mjs +0 -1
  81. package/dist/esm/chunk-CG7TKDP3.mjs.map +0 -1
  82. package/dist/esm/index.d-DDimDpYc.d.mts +0 -165
  83. package/src/namespaces/DependenciesNamespace/validators.ts +0 -103
  84. package/src/namespaces/EventBusNamespace/validators.ts +0 -36
  85. package/src/namespaces/NavigationNamespace/validators.ts +0 -47
  86. package/src/namespaces/RouteLifecycleNamespace/validators.ts +0 -65
  87. package/src/namespaces/RoutesNamespace/forwardToValidation.ts +0 -408
  88. package/src/namespaces/RoutesNamespace/validators.ts +0 -566
  89. package/src/namespaces/StateNamespace/validators.ts +0 -46
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Path Matcher Type Definitions.
3
+ *
4
+ * Core types for path matching and parameter extraction.
5
+ *
6
+ * @module path-matcher/types
7
+ */
8
+ /**
9
+ * Constraint pattern for a URL parameter.
10
+ */
11
+ interface ConstraintPattern {
12
+ /**
13
+ * Compiled RegExp for validating the parameter value.
14
+ *
15
+ * @example /^(\d+)$/ for constraint "<\\d+>"
16
+ */
17
+ readonly pattern: RegExp;
18
+ /**
19
+ * Raw constraint string from the route pattern.
20
+ *
21
+ * @example "<\\d+>"
22
+ */
23
+ readonly constraint: string;
24
+ }
25
+ /**
26
+ * Parameter metadata extracted from a route path pattern.
27
+ */
28
+ interface ParamMeta {
29
+ /**
30
+ * URL parameter names extracted from the path pattern.
31
+ *
32
+ * @example [":id", ":postId"] from "/users/:id/posts/:postId"
33
+ */
34
+ readonly urlParams: readonly string[];
35
+ /**
36
+ * Query parameter names extracted from the path pattern.
37
+ *
38
+ * @example ["q", "page"] from "/search?q&page"
39
+ */
40
+ readonly queryParams: readonly string[];
41
+ /**
42
+ * Splat parameter names extracted from the path pattern.
43
+ *
44
+ * @example ["path"] from "/files/*path"
45
+ */
46
+ readonly spatParams: readonly string[];
47
+ /**
48
+ * Map of parameter names to their type (url or query).
49
+ *
50
+ * @example { id: "url", q: "query" }
51
+ */
52
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
53
+ /**
54
+ * Map of parameter names to their constraint patterns.
55
+ *
56
+ * Only includes parameters with explicit constraints (e.g., `:id<\\d+>`).
57
+ * Parameters without constraints are not included in this map.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * buildParamMeta("/users/:id<\\d+>").constraintPatterns.get("id")
62
+ * // → { pattern: /^(\d+)$/, constraint: "<\\d+>" }
63
+ *
64
+ * buildParamMeta("/users/:id").constraintPatterns.size
65
+ * // → 0 (no constraints)
66
+ * ```
67
+ */
68
+ readonly constraintPatterns: ReadonlyMap<string, ConstraintPattern>;
69
+ /**
70
+ * Path pattern without query string, pre-computed for buildPath.
71
+ *
72
+ * @example "/users/:id" from "/users/:id?q&page"
73
+ */
74
+ readonly pathPattern: string;
75
+ }
76
+ /**
77
+ * URL parameter encoding strategies.
78
+ *
79
+ * - `default` - encodeURIComponent preserving sub-delimiters (+, :, ', !, ,, ;, *)
80
+ * - `uri` - encodeURI/decodeURI
81
+ * - `uriComponent` - encodeURIComponent/decodeURIComponent
82
+ * - `none` - no encoding/decoding
83
+ */
84
+ type URLParamsEncodingType = "default" | "uri" | "uriComponent" | "none";
85
+ interface MatcherInputNode {
86
+ readonly name: string;
87
+ readonly path: string;
88
+ readonly fullName: string;
89
+ readonly absolute: boolean;
90
+ readonly children: ReadonlyMap<string, MatcherInputNode>;
91
+ readonly nonAbsoluteChildren: readonly MatcherInputNode[];
92
+ readonly paramMeta: ParamMeta;
93
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
94
+ readonly staticPath: string | null;
95
+ }
96
+ /**
97
+ * Per-call options for buildPath.
98
+ */
99
+ interface BuildPathOptions {
100
+ readonly queryParamsMode?: "default" | "strict" | "loose" | undefined;
101
+ readonly trailingSlash?: "default" | "always" | "never" | undefined;
102
+ }
103
+ interface MatchResult {
104
+ readonly segments: readonly MatcherInputNode[];
105
+ readonly params: Readonly<Record<string, unknown>>;
106
+ readonly meta: Readonly<Record<string, Record<string, "url" | "query">>>;
107
+ }
108
+ interface SegmentMatcherOptions {
109
+ caseSensitive?: boolean;
110
+ strictTrailingSlash?: boolean;
111
+ strictQueryParams?: boolean;
112
+ urlParamsEncoding?: URLParamsEncodingType;
113
+ parseQueryString?: (queryString: string) => Record<string, unknown>;
114
+ buildQueryString?: (params: Record<string, unknown>) => string;
115
+ }
116
+ interface ResolvedMatcherOptions {
117
+ readonly caseSensitive: boolean;
118
+ readonly strictTrailingSlash: boolean;
119
+ readonly strictQueryParams: boolean;
120
+ readonly urlParamsEncoding: URLParamsEncodingType;
121
+ readonly parseQueryString: (queryString: string) => Record<string, unknown>;
122
+ readonly buildQueryString: (params: Record<string, unknown>) => string;
123
+ }
124
+
125
+ declare class SegmentMatcher {
126
+ #private;
127
+ get options(): ResolvedMatcherOptions;
128
+ constructor(options?: SegmentMatcherOptions);
129
+ registerTree(node: MatcherInputNode): void;
130
+ match(path: string): MatchResult | undefined;
131
+ buildPath(name: string, params?: Record<string, unknown>, options?: BuildPathOptions): string;
132
+ getSegmentsByName(name: string): readonly MatcherInputNode[] | undefined;
133
+ getMetaByName(name: string): Readonly<Record<string, Record<string, "url" | "query">>> | undefined;
134
+ hasRoute(name: string): boolean;
135
+ setRootPath(rootPath: string): void;
136
+ }
137
+
138
+ /**
139
+ * Builder Module Type Definitions.
140
+ *
141
+ * Types for route tree construction and data structures.
142
+ *
143
+ * @module builder/types
144
+ */
145
+
146
+ /**
147
+ * Definition of a route for configuration.
148
+ */
149
+ interface RouteDefinition {
150
+ [key: string]: unknown;
151
+ name: string;
152
+ path: string;
153
+ children?: RouteDefinition[] | undefined;
154
+ }
155
+ /**
156
+ * Immutable route tree node.
157
+ *
158
+ * This is the core data structure of the new route-tree architecture.
159
+ * It contains only data (no methods) and is created by the builder.
160
+ *
161
+ * All caches are pre-computed at build time:
162
+ * - nonAbsoluteChildren: filtered children without absolute paths
163
+ * - absoluteDescendants: all descendants with absolute paths (recursive)
164
+ * - parentSegments: array from root to parent
165
+ * - fullName: pre-computed "users.profile" instead of runtime join
166
+ */
167
+ interface RouteTree {
168
+ /** Route segment name (e.g., "users" in "users.profile") */
169
+ readonly name: string;
170
+ /** Route path pattern (e.g., "/users/:id") */
171
+ readonly path: string;
172
+ /** Whether this route uses absolute path matching (path starts with "~") */
173
+ readonly absolute: boolean;
174
+ /** Child route nodes (Map for O(1) lookup by name) */
175
+ readonly children: ReadonlyMap<string, RouteTree>;
176
+ /** Parameter metadata extracted from path pattern (replaces parser dependency) */
177
+ readonly paramMeta: ParamMeta;
178
+ /** Parent node (null for root) */
179
+ readonly parent: RouteTree | null;
180
+ /** Children without absolute paths (for regular matching) */
181
+ readonly nonAbsoluteChildren: readonly RouteTree[];
182
+ /** Pre-computed full name (e.g., "users.profile") */
183
+ readonly fullName: string;
184
+ /**
185
+ * Pre-computed static path for routes without parameters.
186
+ * Used by buildPath fast path to avoid inject() overhead.
187
+ * Only set when route has no URL params, query params, or splat params.
188
+ */
189
+ readonly staticPath: string | null;
190
+ /**
191
+ * Pre-computed parameter type map for this segment.
192
+ * Cached to avoid recomputing on every navigation.
193
+ * Maps param name → "url" | "query".
194
+ */
195
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
196
+ }
197
+
198
+ /**
199
+ * Matcher Factory.
200
+ *
201
+ * Creates a pre-configured path matcher with search-params DI baked in.
202
+ * This is the public API for creating matchers — SegmentMatcher class
203
+ * and search-params functions are internal implementation details.
204
+ *
205
+ * @module route-tree/createMatcher
206
+ */
207
+
208
+ /**
209
+ * Query string formatting options.
210
+ *
211
+ * Controls how arrays, booleans, and nulls are serialized in query strings.
212
+ */
213
+ interface QueryParamsConfig {
214
+ readonly arrayFormat?: "none" | "brackets" | "index" | "comma";
215
+ readonly booleanFormat?: "none" | "string" | "empty-true";
216
+ readonly nullFormat?: "default" | "hidden";
217
+ }
218
+ /**
219
+ * Options for creating a path matcher.
220
+ */
221
+ interface CreateMatcherOptions {
222
+ readonly caseSensitive?: boolean;
223
+ readonly strictTrailingSlash?: boolean;
224
+ readonly strictQueryParams?: boolean;
225
+ readonly urlParamsEncoding?: "default" | "uri" | "uriComponent" | "none";
226
+ readonly queryParams?: QueryParamsConfig;
227
+ }
228
+ /**
229
+ * Path matcher instance type.
230
+ *
231
+ * Opaque type — consumers use methods (match, buildPath, hasRoute, etc.)
232
+ * without knowing the underlying SegmentMatcher implementation.
233
+ */
234
+ type Matcher = SegmentMatcher;
235
+
236
+ export type { CreateMatcherOptions as C, Matcher as M, RouteTree as R, RouteDefinition as a };
@@ -1,27 +1,8 @@
1
- import { Params, RouteTreeState, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
1
+ export { B as BuildStateResultWithSegments, R as RouterValidator } from './RouterValidator-mx2Zooya.js';
2
+ import { R as Router } from './Router-B-Pev7K2.js';
3
+ import { ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
2
4
  export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
3
- import { R as Router } from './index.d-DDimDpYc.js';
4
- export { a as RouteTree } from './index.d-DDimDpYc.js';
5
-
6
- /**
7
- * Core-internal types + re-exports from @real-router/types.
8
- *
9
- * Factory types (PluginFactory, GuardFnFactory) and
10
- * route config types (Route, RouteConfigUpdate) are canonical in @real-router/types
11
- * and re-exported here for backward compatibility.
12
- */
13
-
14
- /**
15
- * Extended build result that includes segments for path building.
16
- * Used internally to avoid duplicate getSegmentsByName calls.
17
- *
18
- * @param segments - Route segments from getSegmentsByName (typed as unknown[] for cross-package compatibility)
19
- * @internal
20
- */
21
- interface BuildStateResultWithSegments<P extends Params = Params> {
22
- readonly state: RouteTreeState<P>;
23
- readonly segments: readonly unknown[];
24
- }
5
+ export { R as RouteTree } from './index.d-y2b-8_3Y.js';
25
6
 
26
7
  type ConstantsKeys = "UNKNOWN_ROUTE";
27
8
  type Constants = Record<ConstantsKeys, string>;
@@ -251,4 +232,6 @@ declare const createRouter: <Dependencies extends DefaultDependencies = DefaultD
251
232
 
252
233
  declare const getNavigator: <Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>) => Navigator;
253
234
 
254
- export { type BuildStateResultWithSegments, type Constants, type ErrorCodes, Router, RouterError, UNKNOWN_ROUTE, constants, createRouter, errorCodes, events, getNavigator };
235
+ declare function resolveForwardChain(startRoute: string, forwardMap: Record<string, string>, maxDepth?: number): string;
236
+
237
+ export { type Constants, type ErrorCodes, Router, RouterError, UNKNOWN_ROUTE, constants, createRouter, errorCodes, events, getNavigator, resolveForwardChain };
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- var t=require("@real-router/logger"),e=require("@real-router/fsm"),r={maxListeners:0,warnListeners:0,maxEventDepth:0},n=class extends Error{},i=class{#t=new Map;#e=null;#r=r;#n;#i;constructor(t){t?.limits&&(this.#r=t.limits),this.#n=t?.onListenerError??null,this.#i=t?.onListenerWarn??null}static validateCallback(t,e){if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}setLimits(t){this.#r=t}on(t,e){const r=this.#s(t);if(r.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:n,warnListeners:i}=this.#r;if(0!==i&&r.size===i&&this.#i?.(t,i),0!==n&&r.size>=n)throw new Error(`Listener limit (${n}) reached for "${t}"`);return r.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,r,n,i){const s=this.#t.get(t);if(!s||0===s.size)return;const o=arguments.length-1;0!==this.#r.maxEventDepth?this.#o(s,t,o,e,r,n,i):this.#a(s,t,o,e,r,n,i)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#a(t,e,r,n,i,s,o){if(1===t.size){const[a]=t;try{this.#c(a,r,n,i,s,o)}catch(t){this.#n?.(e,t)}return}const a=[...t];for(const t of a)try{this.#c(t,r,n,i,s,o)}catch(t){this.#n?.(e,t)}}#c(t,e,r,n,i,s){switch(e){case 0:t();break;case 1:t(r);break;case 2:t(r,n);break;case 3:t(r,n,i);break;default:t(r,n,i,s)}}#o(t,e,r,i,s,o,a){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#r.maxEventDepth)throw new n(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${e}`);try{c.set(e,u+1);const l=1===t.size?t:[...t];for(const t of l)try{this.#c(t,r,i,s,o,a)}catch(t){if(t instanceof n)throw t;this.#n?.(e,t)}}finally{c.set(e,c.get(e)-1)}}#s(t){const e=this.#t.get(t);if(e)return e;const r=new Set;return this.#t.set(t,r),r}},s=["replace","reload","force","forceDeactivate","redirected"],o=/\S/,a=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(t,e){return new TypeError(`[router.${t}] ${e}`)}function u(t,e=new WeakSet){if(null==t)return!0;const r=typeof t;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(t);if("function"===r||"symbol"===r)return!1;if(Array.isArray(t))return!e.has(t)&&(e.add(t),t.every(t=>u(t,e)));if("object"===r){if(e.has(t))return!1;e.add(t);const r=Object.getPrototypeOf(t);return(null===r||r===Object.prototype)&&Object.values(t).every(t=>u(t,e))}return!1}function l(t){if(null==t)return!0;const e=typeof t;return"string"===e||"boolean"===e||"number"===e&&Number.isFinite(t)}function h(t){if("object"!=typeof t||null===t||Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);if(null!==e&&e!==Object.prototype)return!1;let r=!1;for(const e in t){if(!Object.hasOwn(t,e))continue;const n=t[e];if(!l(n)){const t=typeof n;if("function"===t||"symbol"===t)return!1;r=!0;break}}return!r||u(t)}function d(t){return"string"==typeof t}function f(t,e){return t in e}function p(t,e){if("string"!=typeof t)throw c(e,"Route name must be a string, got "+typeof t);if(""!==t){if(!o.test(t))throw c(e,"Route name cannot contain only whitespace");if(t.length>1e4)throw c(e,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!t.startsWith("@@")&&!a.test(t))throw c(e,`Invalid route name "${t}". Each segment must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens. Segments are separated by dots (e.g., "users.profile").`)}}function m(t){return null===t?"null":Array.isArray(t)?`array[${t.length}]`:"object"==typeof t?"constructor"in t&&"Object"!==t.constructor.name?t.constructor.name:"object":typeof t}function g(t,e){if(!function(t){return"object"==typeof t&&null!==t&&function(t){return function(t){return"string"==typeof t&&(""===t||!(t.length>1e4)&&(!!t.startsWith("@@")||a.test(t)))}(t.name)&&"string"==typeof t.path&&h(t.params)}(t)}(t))throw new TypeError(`[${e}] Invalid state structure: ${m(t)}. Expected State object with name, params, and path properties.`)}var v=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),y="@@router/UNKNOWN_ROUTE",w={UNKNOWN_ROUTE:y},S="onStart",T="onStop",b="onTransitionStart",E="onTransitionCancel",A="onTransitionSuccess",O="onTransitionError",N={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},P={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},R=Object.freeze({}),$={maxDependencies:{min:0,max:1e4},maxPlugins:{min:0,max:1e3},maxListeners:{min:0,max:1e5},warnListeners:{min:0,max:1e5},maxEventDepth:{min:0,max:100},maxLifecycleHandlers:{min:0,max:1e4}},C="IDLE",D="STARTING",j="READY",F="TRANSITIONING",I="DISPOSED",L="START",x="STARTED",_="NAVIGATE",M="COMPLETE",U="FAIL",k="CANCEL",B="STOP",z="DISPOSE",q={initial:C,context:null,transitions:{[C]:{[L]:D,[z]:I},[D]:{[x]:j,[U]:C},[j]:{[_]:F,[U]:j,[B]:C},[F]:{[_]:F,[M]:j,[k]:j,[U]:j},[I]:{}}},W=new WeakSet;function G(t){if(null!==t&&"object"==typeof t&&!Object.isFrozen(t))if(Object.freeze(t),Array.isArray(t))for(const e of t)G(e);else for(const e in t)G(t[e])}function V(t){return t?(W.has(t)||(G(t),W.add(t)),t):t}function Q(t){return{warn:Math.floor(.2*t),error:Math.floor(.5*t)}}var H=new WeakMap;function K(t){const e=H.get(t);if(!e)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return e}function J(t,e,r){let n=e;for(const e of t){const t=n;n=(...r)=>e(t,...r)}return n(...r)}function Y(t,e,r){return(n,i)=>{const s=r.get(t);return s&&0!==s.length?J(s,e,[n,i]):e(n,i)}}var Z={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},X={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},tt={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function et(t){Object.freeze(t);for(const e of Object.keys(t)){const r=t[e];r&&"object"==typeof r&&r.constructor===Object&&et(r)}return t}function rt(t,e){return"function"==typeof t?t(e):t}function nt(t,e,r){if("function"==typeof e&&("defaultRoute"===t||"defaultParams"===t))return;const n=Z[t];if(n&&"object"==typeof n)return function(t,e,r){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected plain object, got ${m(t)}`);for(const n in t)if(Object.getOwnPropertyDescriptor(t,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${e}": "${n}"`)}(e,t,r),void("queryParams"===t&&function(t,e){for(const r in t){if(!f(r,tt)){const t=Object.keys(tt).map(t=>`"${t}"`).join(", ");throw new TypeError(`[router.${e}] Unknown queryParams key: "${r}". Valid keys: ${t}`)}const n=t[r],i=tt[r];if(!i.includes(n)){const t=i.map(t=>`"${t}"`).join(", ");throw new TypeError(`[router.${e}] Invalid value for queryParams.${r}: expected one of ${t}, got "${String(n)}"`)}}}(e,r));if(typeof e!=typeof n)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected ${typeof n}, got ${typeof e}`);t in X&&function(t,e,r){const n=X[t];if(!n.includes(e)){const i=n.map(t=>`"${t}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${t}": expected one of ${i}, got "${String(e)}"`)}}(t,e,r)}function it(t,e,r){if("limits"===t)return void 0!==e&&function(t,e){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.${e}]: invalid limits: expected plain object, got ${typeof t}`);for(const[r,n]of Object.entries(t)){if(!Object.hasOwn($,r))throw new TypeError(`[router.${e}]: unknown limit: "${r}"`);void 0!==n&&st(r,n,e)}}(e,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${t}"`)}function st(t,e,r){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError(`[router.${r}]: limit "${t}" must be an integer, got ${String(e)}`);const n=$[t];if(e<n.min||e>n.max)throw new RangeError(`[router.${r}]: limit "${t}" must be between ${n.min} and ${n.max}, got ${e}`)}var ot=class{#u;constructor(t={}){this.#u=et({...Z,...t})}static validateOptions(t,e){!function(t,e){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.${e}] Invalid options: expected plain object, got ${m(t)}`);for(const[r,n]of Object.entries(t))f(r,Z)?void 0!==n&&nt(r,n,e):it(r,n,e)}(t,e)}get(){return this.#u}};function at(t,e){return t===e||!(!Array.isArray(t)||!Array.isArray(e))&&t.length===e.length&&t.every((t,r)=>at(t,e[r]))}var ct=class{#l=0;#h=void 0;#d=void 0;#f;#p=new Map;static validateAreStatesEqualArgs(t,e,r){if(null!=t&&g(t,"areStatesEqual"),null!=e&&g(e,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${m(r)}. Expected boolean.`)}get(){return this.#h}set(t){this.#d=this.#h,this.#h=t?V(t):void 0}getPrevious(){return this.#d}reset(){this.#h=void 0,this.#d=void 0,this.#p.clear(),this.#l=0}setDependencies(t){this.#f=t}makeState(t,e,r,n,i,s){const o=n?{id:i??++this.#l,params:n}:void 0,a=this.#f.getDefaultParams();let c;c=Object.hasOwn(a,t)?{...a[t],...e}:e&&e!==R?{...e}:R;const u={name:t,params:c,path:r??this.#f.buildPath(t,e),meta:o};return s?u:V(u)}areStatesEqual(t,e,r=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(r){const r=t.meta?.params??e.meta?.params;return(r?function(t){const e=[];for(const r in t){const n=t[r];for(const t in n)"url"===n[t]&&e.push(t)}return e}(r):this.#m(t.name)).every(r=>at(t.params[r],e.params[r]))}const n=Object.keys(t.params),i=Object.keys(e.params);return n.length===i.length&&n.every(r=>r in e.params&&at(t.params[r],e.params[r]))}#m(t){const e=this.#p.get(t);if(void 0!==e)return e;const r=this.#f.getUrlParams(t);return this.#p.set(t,r),r}},ut={[S]:N.ROUTER_START,[T]:N.ROUTER_STOP,[A]:N.TRANSITION_SUCCESS,[b]:N.TRANSITION_START,[O]:N.TRANSITION_ERROR,[E]:N.TRANSITION_CANCEL},lt=Object.keys(ut).filter(t=>f(t,ut)),ht="router.usePlugin",dt=class e{#g=new Set;#v=new Set;#f;#y=P;static validateUsePluginArgs(t){!function(t){for(const[e,r]of t.entries())if("function"!=typeof r)throw new TypeError(`[router.usePlugin] Expected plugin factory function at index ${e}, got ${m(r)}`)}(t)}static validatePlugin(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${m(t)}`);if("function"==typeof t.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const e in t)if("teardown"!==e&&!f(e,ut))throw new TypeError(`[router.usePlugin] Unknown property '${e}'. Plugin must only contain event handlers and optional teardown.`)}(t)}static validatePluginLimit(t,e,r){!function(t,e,r=P.maxPlugins){if(0!==r&&t+e>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r}). Current: ${t}, Attempting to add: ${e}. This indicates an architectural problem. Consider consolidating plugins.`)}(t,e,r)}static validateNoDuplicatePlugins(t,e){for(const r of t)if(e(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#f=t}setLimits(t){this.#y=t}count(){return this.#g.size}use(...e){if(this.#w(e.length),1===e.length){const r=e[0],n=this.#S(r);this.#g.add(r);let i=!1;const s=()=>{if(!i){i=!0,this.#g.delete(r),this.#v.delete(s);try{n()}catch(e){t.logger.error(ht,"Error during cleanup:",e)}}};return this.#v.add(s),s}const r=this.#T(e),n=[];try{for(const t of r){const e=this.#S(t);n.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of n)try{e()}catch(e){t.logger.error(ht,"Cleanup error:",e)}throw e}for(const{factory:t}of n)this.#g.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#v.delete(s);for(const{factory:t}of n)this.#g.delete(t);for(const{cleanup:e}of n)try{e()}catch(e){t.logger.error(ht,"Error during cleanup:",e)}}};return this.#v.add(s),s}getAll(){return[...this.#g]}has(t){return this.#g.has(t)}disposeAll(){for(const t of this.#v)t();this.#g.clear(),this.#v.clear()}#w(e){const r=this.#y.maxPlugins;if(0===r)return;const n=e+this.#g.size,{warn:i,error:s}=Q(r);n>=s?t.logger.error(ht,`${n} plugins registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=i&&t.logger.warn(ht,`${n} plugins registered. Consider if all are necessary.`)}#T(e){const r=new Set;for(const n of e)r.has(n)?t.logger.warn(ht,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#S(r){const n=this.#f.compileFactory(r);e.validatePlugin(n),Object.freeze(n);const i=[];for(const e of lt)e in n&&("function"==typeof n[e]?(i.push(this.#f.addEventListener(ut[e],n[e])),"onStart"===e&&this.#f.canNavigate()&&t.logger.warn(ht,"Router already started, onStart will not be called")):t.logger.warn(ht,`Property '${e}' is not a function, skipping`));return()=>{for(const t of i)t();"function"==typeof n.teardown&&n.teardown()}}};function ft(t,e,r){if(t)throw new Error(`[router.${r}] Cannot modify route "${e}" during its own registration`)}function pt(t,e,r=P.maxLifecycleHandlers){if(0!==r&&t>=r)throw new Error(`[router.${e}] Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}var mt=class{#b=new Map;#E=new Map;#A=new Map;#O=new Map;#N=[this.#A,this.#O];#P=new Set;#R=new Set;#$=new Set;#f;#y=P;setDependencies(t){this.#f=t}setLimits(t){this.#y=t}addCanActivate(t,e,r,n=!1){n?this.#R.add(t):this.#R.delete(t),r||ft(this.#P.has(t),t,"addActivateGuard");const i=this.#E.has(t);i||r||pt(this.#E.size+1,"addActivateGuard",this.#y.maxLifecycleHandlers),this.#C("activate",t,e,this.#E,this.#O,"canActivate",i)}addCanDeactivate(t,e,r,n=!1){n?this.#$.add(t):this.#$.delete(t),r||ft(this.#P.has(t),t,"addDeactivateGuard");const i=this.#b.has(t);i||r||pt(this.#b.size+1,"addDeactivateGuard",this.#y.maxLifecycleHandlers),this.#C("deactivate",t,e,this.#b,this.#A,"canDeactivate",i)}clearCanActivate(t){this.#E.delete(t),this.#O.delete(t),this.#R.delete(t)}clearCanDeactivate(t){this.#b.delete(t),this.#A.delete(t),this.#$.delete(t)}clearAll(){this.#E.clear(),this.#O.clear(),this.#b.clear(),this.#A.clear(),this.#R.clear(),this.#$.clear()}clearDefinitionGuards(){for(const t of this.#R)this.#E.delete(t),this.#O.delete(t);for(const t of this.#$)this.#b.delete(t),this.#A.delete(t);this.#R.clear(),this.#$.clear()}getFactories(){const t={},e={};for(const[e,r]of this.#b)t[e]=r;for(const[t,r]of this.#E)e[t]=r;return[t,e]}getFunctions(){return this.#N}canNavigateTo(t,e,r,n){for(const e of t)if(!this.#D(this.#A,e,r,n,"canNavigateTo"))return!1;for(const t of e)if(!this.#D(this.#O,t,r,n,"canNavigateTo"))return!1;return!0}#C(e,r,n,i,s,o,a){a?t.logger.warn(`router.${o}`,`Overwriting existing ${e} handler for route "${r}"`):this.#w(i.size+1,o);const c="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;i.set(r,c),this.#P.add(r);try{const t=this.#f.compileFactory(c);if("function"!=typeof t)throw new TypeError(`[router.${o}] Factory must return a function, got ${m(t)}`);s.set(r,t)}catch(t){throw i.delete(r),t}finally{this.#P.delete(r)}}#D(e,r,n,i,s){const o=e.get(r);if(!o)return!0;try{const e=o(n,i);return"boolean"==typeof e?e:(t.logger.warn(`router.${s}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#w(e,r){const n=this.#y.maxLifecycleHandlers;if(0===n)return;const{warn:i,error:s}=Q(n);e>=s?t.logger.error(`router.${r}`,`${e} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):e>=i&&t.logger.warn(`router.${r}`,`${e} lifecycle handlers registered. Consider consolidating logic.`)}},gt=new Set;function vt(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function yt(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>yt(t))),e}function wt(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var St=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,Tt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,bt=/\?(.+)$/,Et=/[^\w!$'()*+,.:;|~-]/gu,At=/[^\w!$'()*+,.:;|~-]/u,Ot={default:t=>At.test(t)?t.replaceAll(Et,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},Nt={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function Pt(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Rt(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function $t(t){const e={};if(0===t.length)return e;const r=t.split("&");for(const t of r){const r=t.indexOf("=");-1===r?e[t]="":e[t.slice(0,r)]=t.slice(r+1)}return e}function Ct(t){const e=[];for(const r of Object.keys(t)){const n=t[r],i=encodeURIComponent(r);e.push(""===n?i:`${i}=${encodeURIComponent(String(n))}`)}return e.join("&")}function Dt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function jt(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const r=t.codePointAt(e+1)??0,n=t.codePointAt(e+2)??0;if(!Dt(r)||!Dt(n))return!1;e+=3}else e++;return!0}var Ft=/<[^>]*>/g;function It(t,e,r,n,i){const s=""===e.fullName;s||n.push(e);const o=e.absolute,a=e.paramMeta.pathPattern,c=o&&a.startsWith("~")?a.slice(1):a,u=(o?c:a).replaceAll(Ft,""),l=o?u:(d=u,""===(h=r)?d:""===d?h:h+d);var h,d;let f=i;s||(f=function(t,e,r,n,i,s){const o=(g=n,Rt(r)===Rt(g)),a=Object.freeze([...i]),c=function(t){const e={};for(const r of t)e[r.fullName]=r.paramTypeMap;return Object.freeze(e)}(a),u=Rt(r),l=function(t,e){const r=[];t.length>0&&r.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&r.push(...t.paramMeta.queryParams);return r}(t.rootQueryParams,i),h=function(t){const e=new Map;for(const r of t)for(const[t,n]of r.paramMeta.constraintPatterns)e.set(t,n);return e}(i),d=o?Rt(n):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,r){const n=new Set,i=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)n.add(e);for(const e of t.paramMeta.spatParams)i.add(e)}if(0===n.size)return{buildStaticParts:[t],buildParamSlots:[]};const s=[],o=[],a=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=a.exec(t));){const e=c[1],n="?"===c[2];s.push(t.slice(u,c.index));const a=i.has(e);o.push({paramName:e,isOptional:n,encoder:a?t=>{const e=Ot[r],n=t.split("/");let i=e(n[0]);for(let t=1;t<n.length;t++)i+=`/${e(n[t])}`;return i}:Ot[r]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:o}}(d,o?i.slice(0,-1):i,t.options.urlParamsEncoding),m={name:e.fullName,parent:s,depth:i.length-1,matchSegments:a,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var g;return t.routesByName.set(e.fullName,m),t.segmentsByName.set(e.fullName,a),t.metaByName.set(e.fullName,c),o?function(t,e,r){var n,i;n=e,(function(t,e,r){const n=Rt(r);if("/"===n||""===n)return e;let i=e,s=1;const o=n.length;for(;s<=o;){const e=n.indexOf("/",s),r=-1===e?o:e;if(r<=s)break;i=xt(t,i,n.slice(s,r)),s=r+1}return i}(i=t,i.root,r)).slashChildRoute=n;const s=Rt(r),o=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(o)&&t.staticCache.set(o,e)}(t,m,n):function(t,e,r,n,i){if(function(t,e,r){const n=Rt(r);"/"!==n?Lt(t,t.root,n,1,e):t.root.route=e}(t,e,r),0===i.paramMeta.urlParams.length){const r=t.options.caseSensitive?n:n.toLowerCase();t.staticCache.set(r,e)}}(t,m,r,u,e),m}(t,e,l,o?"":r,n,i));for(const r of e.children.values())It(t,r,l,n,f);s||n.pop()}function Lt(t,e,r,n,i){const s=r.length;for(;n<=s;){const o=r.indexOf("/",n),a=-1===o?s:o,c=r.slice(n,a);if(c.endsWith("?")){const n=c.slice(1).replaceAll(Ft,"").replace(/\?$/,"");return e.paramChild??={node:Pt(),name:n},Lt(t,e.paramChild.node,r,a+1,i),void(a>=s?e.route??=i:Lt(t,e,r,a+1,i))}e=xt(t,e,c),n=a+1}e.route=i}function xt(t,e,r){if(r.startsWith("*")){const t=r.slice(1);return e.splatChild??={node:Pt(),name:t},e.splatChild.node}if(r.startsWith(":")){const t=r.slice(1).replaceAll(Ft,"").replace(/\?$/,"");return e.paramChild??={node:Pt(),name:t},e.paramChild.node}const n=t.options.caseSensitive?r:r.toLowerCase();return n in e.staticChildren||(e.staticChildren[n]=Pt()),e.staticChildren[n]}var _t=/[\u0080-\uFFFF]/,Mt=class{get options(){return this.#t}#t;#e=Pt();#i=new Map;#s=new Map;#r=new Map;#o=new Map;#n="";#j=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??$t,buildQueryString:t?.buildQueryString??Ct}}registerTree(t){this.#j=t.paramMeta.queryParams,It({root:this.#e,options:this.#t,routesByName:this.#i,segmentsByName:this.#s,metaByName:this.#r,staticCache:this.#o,rootQueryParams:this.#j},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[r,n,i]=e,s=this.#t.caseSensitive?n:n.toLowerCase(),o=this.#o.get(s);if(o){if(this.#t.strictTrailingSlash&&!this.#a(r,o))return;return this.#F(o,{},i)}const a={},c=this.#I(n,a);return!c||this.#t.strictTrailingSlash&&!this.#a(r,c)||c.hasConstraints&&!this.#L(a,c)||!this.#x(a)?void 0:this.#F(c,a,i)}buildPath(t,e,r){const n=this.#i.get(t);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);n.hasConstraints&&e&&this.#_(n,t,e);const i=this.#M(n,e),s=this.#U(i,r?.trailingSlash),o=this.#k(n,e,r?.queryParamsMode);return s+(o?`?${o}`:"")}getSegmentsByName(t){return this.#s.get(t)}getMetaByName(t){return this.#r.get(t)}hasRoute(t){return this.#i.has(t)}setRootPath(t){this.#n=t}#_(t,e,r){for(const[n,i]of t.constraintPatterns){const t=r[n];if(null!=t){const r="object"==typeof t?JSON.stringify(t):String(t);if(!i.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${n}' value '${r}' does not match constraint '${i.constraint}'`)}}}#M(t,e){const r=t.buildStaticParts,n=t.buildParamSlots;if(0===n.length)return this.#n+r[0];let i=this.#n+r[0];for(const[t,s]of n.entries()){const n=e?.[s.paramName];if(null==n){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=r[t+1];continue}const o="object"==typeof n?JSON.stringify(n):String(n);i+=s.encoder(o)+r[t+1]}return i}#U(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#k(t,e,r){if(!e)return"";const n={};let i=!1;for(const r of t.declaredQueryParams)r in e&&(n[r]=e[r],i=!0);if("loose"===r)for(const r in e)!Object.hasOwn(e,r)||t.declaredQueryParamsSet.has(r)||t.buildParamNamesSet.has(r)||(n[r]=e[r],i=!0);return i?this.#t.buildQueryString(n):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),_t.test(t))return;if(this.#n.length>0){if(!t.startsWith(this.#n))return;t=t.slice(this.#n.length)||"/"}const r=t.indexOf("?"),n=-1===r?t:t.slice(0,r),i=-1===r?void 0:t.slice(r+1);return n.includes("//")?void 0:[n,Rt(n),i]}#F(t,e,r){if(void 0!==r){const n=this.#t.parseQueryString(r);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(n))if(!e.has(t))return}for(const t of Object.keys(n))e[t]=n[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#a(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#I(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#B(this.#e,t,1,e)}#B(t,e,r,n){let i=t;const s=e.length;for(;r<=s;){const t=e.indexOf("/",r),o=-1===t?s:t,a=e.slice(r,o),c=this.#t.caseSensitive?a:a.toLowerCase();let u;if(c in i.staticChildren)u=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const t={},s=this.#B(i.splatChild.node,e,r,t);return s?(Object.assign(n,t),s):(n[i.splatChild.name]=e.slice(r),i.splatChild.node.route)}return}u=i.paramChild.node,n[i.paramChild.name]=a}i=u,r=o+1}return i.slashChildRoute??i.route}#x(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const r=Nt[e];for(const e in t){const n=t[e];if(n.includes("%")){if(!jt(n))return!1;t[e]=r(n)}}return!0}#L(t,e){for(const[r,n]of e.constraintPatterns)if(!n.pattern.test(t[r]))return!1;return!0}},Ut=t=>{const e=t.indexOf("%"),r=t.indexOf("+");if(-1===e&&-1===r)return t;const n=-1===r?t:t.split("+").join(" ");return-1===e?n:decodeURIComponent(n)},kt=t=>{const e=typeof t;if("string"!==e&&"number"!==e&&"boolean"!==e)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===e&&null===t?"null":e}`);return encodeURIComponent(t)},Bt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${kt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${kt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,r)=>`${t}[${r}]=${kt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>kt(t)).join(",")}`}},zt={none:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:t=>t},string:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:t=>"true"===t||"false"!==t&&null,decodeValue:t=>t},"empty-true":{encode:(t,e)=>e?t:`${t}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:t=>t}},qt={default:{encode:t=>t},hidden:{encode:()=>""}},Wt=(t,e,r)=>({boolean:zt[e],null:qt[r],array:Bt[t]}),Gt={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:zt.none,null:qt.default,array:Bt.none}},Vt=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return Gt;const e=t.arrayFormat??"none",r=t.booleanFormat??"none",n=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:r,nullFormat:n,strategies:Wt(e,r,n)}},Qt=t=>encodeURIComponent(t),Ht=(t,e,r)=>{const n=Qt(t);switch(typeof e){case"string":case"number":default:return`${n}=${Qt(e)}`;case"boolean":return r.strategies.boolean.encode(n,e);case"object":return null===e?r.strategies.null.encode(n):Array.isArray(e)?r.strategies.array.encodeArray(n,e):`${n}=${Qt(e)}`}};function Kt(t,e,r,n,i){const s=t.indexOf("=",e),o=-1!==s&&s<r,a=t.slice(e,o?s:r),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(a);var l,h,d,f,p;!function(t,e,r,n){const i=t[e];void 0===i?t[e]=n?[r]:r:Array.isArray(i)?i.push(r):t[e]=[i,r]}(n,Ut(c),(l=t,h=s,d=r,f=o,p=i,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const r=e.boolean.decodeRaw(t);if(null!==r)return r;const n=Ut(t);return e.boolean.decodeValue(n)})(f?l.slice(h+1,d):void 0,p):f?Ut(l.slice(h+1,d)):null),u)}function Jt(t,e){const r=t.path,n=r.startsWith("~"),i=n?r.slice(1):r,s={name:t.name,path:i,absolute:n,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Jt(e,s);s.children.push(t)}return s}function Yt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Zt(t){const e=new Map;for(const r of t)e.set(r.name,r);return e}function Xt(t,e,r){const n=function(t){const e=[],r=[],n=[],i={},s=new Map,o=t.replaceAll(Tt,"$1"),a=bt.exec(o);if(null!==a){const e=a[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(r.push(e),i[e]="query")}t=t.slice(0,a.index)}let c;for(;null!==(c=St.exec(t));){const t=c[2],r=c[3];if("*"===c[1])n.push(t),e.push(t),i[t]="url";else if(e.push(t),i[t]="url",r){const e=`^${wt(r)}$`;s.set(t,{pattern:new RegExp(e),constraint:r})}}return{urlParams:e,queryParams:r,spatParams:n,paramTypeMap:i,constraintPatterns:s,pathPattern:t}}(t.path),i=function(t){const e={};for(const r of t.urlParams)e[r]="url";for(const r of t.queryParams)e[r]="query";return e}(n),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var o;s.fullName=(o=s,o.parent?.name?`${o.parent.fullName}.${o.name}`:o.name);const{childrenMap:a,nonAbsoluteChildren:c}=function(t,e,r){const n=[],i=[];for(const s of t){const t=Xt(s,e,r);n.push(t),t.absolute||i.push(t)}return{childrenMap:Zt(n),nonAbsoluteChildren:i}}(t.children,s,r);return s.children=a,s.nonAbsoluteChildren=c,s.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:r,spatParams:n}=t.paramMeta;if(e.length>0||r.length>0||n.length>0)return null;const i=[];let s=t.parent;for(;s?.path;)i.unshift(s),s=s.parent;let o="";for(const t of i){const{urlParams:e,queryParams:r,spatParams:n}=t.paramMeta;if(e.length>0||r.length>0||n.length>0)return null;o=t.absolute?t.path:Yt(o,t.path)}return t.absolute?t.path:Yt(o,t.path)}(s),r&&(Object.freeze(c),Object.freeze(i),Object.freeze(s.children),Object.freeze(s)),s}function te(t,e,r,n){return function(t,e){const r=[];return{add(t){return r.push(t),this},addMany(t){return r.push(...t),this},build:n=>function(t,e=!0){return Xt(t,null,e)}(function(t,e,r){const n=Jt({name:t,path:e},null);for(const t of r){const e=Jt(t,n);n.children.push(e)}return n}(t,e,r),!n?.skipFreeze)}}(t,e).addMany(r).build(n)}function ee(t){const e={name:t.name,path:t.absolute?`~${t.path}`:t.path};return t.children.size>0&&(e.children=[...t.children.values()].map(t=>ee(t))),e}function re(t){const e=t?.queryParams;return new Mt({...void 0===t?.caseSensitive?void 0:{caseSensitive:t.caseSensitive},...void 0===t?.strictTrailingSlash?void 0:{strictTrailingSlash:t.strictTrailingSlash},...void 0===t?.strictQueryParams?void 0:{strictQueryParams:t.strictQueryParams},...void 0===t?.urlParamsEncoding?void 0:{urlParamsEncoding:t.urlParamsEncoding},parseQueryString:t=>((t,e)=>{const r=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===r||"?"===r)return{};if(!e)return function(t){const e={};return function(t,e){let r=0;const n=t.length;for(;r<n;){let i=t.indexOf("&",r);-1===i&&(i=n),Kt(t,r,i,e),r=i+1}}(t,e),e}(r);const n=Vt(e),i={};let s=0;const o=r.length;for(;s<o;){let t=r.indexOf("&",s);-1===t&&(t=o),Kt(r,s,t,i,n.strategies),s=t+1}return i})(t,e),buildQueryString:t=>((t,e)=>{const r=Object.keys(t);if(0===r.length)return"";const n=Vt(e),i=[];for(const e of r){const r=t[e];if(void 0===r)continue;const s=Ht(e,r,n);s&&i.push(s)}return i.join("&")})(t,e)})}function ne(t,e){return new TypeError(`[router.${t}] ${e}`)}var ie=/^[A-Z_a-z][\w-]*$/,se=/\S/;function oe(t){return null===t?"null":"object"==typeof t?"constructor"in t&&"Object"!==t.constructor.name?t.constructor.name:"object":typeof t}function ae(t,e){if(!e.includes("."))return t.children.get(e);let r=t;for(const t of e.split("."))if(r=r.children.get(t),!r)return;return r}function ce(t,e,r,n="",i,s){!function(t,e){if(!t||"object"!=typeof t)throw new TypeError(`[router.${e}] Route must be an object, got ${oe(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${e}] Route must be a plain object, got ${oe(t)}`);if(function(t){for(const e of Object.keys(t)){const r=Object.getOwnPropertyDescriptor(t,e);if(r&&(r.get||r.set))return!0}return!1}(t))throw new TypeError(`[router.${e}] Route must not have getters or setters`)}(t,e);const o=t;!function(t,e){if("string"!=typeof t.name)throw new TypeError(`[router.${e}] Route name must be a string, got ${oe(t.name)}`);const r=t.name;if(""===r)throw new TypeError(`[router.${e}] Route name cannot be empty`);if(!se.test(r))throw new TypeError(`[router.${e}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${e}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")){if(r.includes("."))throw new TypeError(`[router.${e}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!ie.test(r))throw new TypeError(`[router.${e}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(o,e),function(t,e,r,n){if("string"!=typeof t){let e;throw e=null===t?"null":Array.isArray(t)?"array":typeof t,ne(r,`Route path must be a string, got ${e}`)}if(""===t)return;if(/\s/.test(t))throw ne(r,`Invalid path for route "${e}": whitespace not allowed in "${t}"`);if(!/^([/?~]|[^/]+$)/.test(t))throw ne(r,`Route "${e}" has invalid path format: "${t}". Path should start with '/', '~', '?' or be a relative segment.`);if(t.includes("//"))throw ne(r,`Invalid path for route "${e}": double slashes not allowed in "${t}"`);const i=n&&Object.values(n.paramTypeMap).includes("url");if(t.startsWith("~")&&i)throw ne(r,`Absolute path "${t}" cannot be used under parent route with URL parameters`)}(o.path,o.name,e,r),function(t,e){if(void 0!==t.encodeParams&&"function"!=typeof t.encodeParams)throw new TypeError(`[router.${e}] Route "${String(t.name)}" encodeParams must be a function`)}(o,e),function(t,e){if(void 0!==t.decodeParams&&"function"!=typeof t.decodeParams)throw new TypeError(`[router.${e}] Route "${String(t.name)}" decodeParams must be a function`)}(o,e);const a=o.name,c=n?`${n}.${a}`:a;r&&c&&function(t,e,r){if(ae(t,e))throw new Error(`[router.${r}] Route "${e}" already exists`)}(r,c,e),i&&function(t,e,r){if(t.has(e))throw new Error(`[router.${r}] Duplicate route "${e}" in batch`);t.add(e)}(i,c,e);const u=o.path,l=n;if(r&&function(t,e,r,n){const i=""===e?t:ae(t,e);if(i)for(const t of i.children.values())if(t.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,l,u,e),s&&function(t,e,r,n){const i=t.get(e);if(i?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);i?i.add(r):t.set(e,new Set([r]))}(s,l,u,e),void 0!==o.children){if(!Array.isArray(o.children))throw new TypeError(`[router.${e}] Route "${a}" children must be an array, got ${oe(o.children)}`);for(const t of o.children)ce(t,e,r,c,i,s)}}function ue(t,e){if(void 0!==t.canActivate&&"function"!=typeof t.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${e}", got ${m(t.canActivate)}`);if(void 0!==t.canDeactivate&&"function"!=typeof t.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${e}", got ${m(t.canDeactivate)}`);if(void 0!==t.defaultParams){const r=t.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${e}", got ${m(t.defaultParams)}`)}if("AsyncFunction"===t.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${e}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===t.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${e}". Async functions break matchPath/buildPath.`);if(function(t,e){if(void 0!==t&&"function"==typeof t){const r="AsyncFunction"===t.constructor.name,n=t.toString().includes("__awaiter");if(r||n)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${e}". Async functions break matchPath/buildPath.`)}}(t.forwardTo,e),t.children)for(const r of t.children)ue(r,`${e}.${r.name}`)}function le(t){const e=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(t));)e.add(n[1]);return e}function he(t){const e=new Set;for(const r of t)for(const t of le(r))e.add(t);return e}function de(t,e,r="",n=[]){for(const i of t){const t=r?`${r}.${i.name}`:i.name,s=[...n,i.path];if(t===e)return s;if(i.children&&e.startsWith(`${t}.`))return de(i.children,e,t,s)}throw new Error(`[internal] collectPathsToRoute: route "${e}" not found`)}function fe(t,e=""){const r=new Set;for(const n of t){const t=e?`${e}.${n.name}`:n.name;if(r.add(t),n.children)for(const e of fe(n.children,t))r.add(e)}return r}function pe(t,e=""){const r=new Map;for(const n of t){const t=e?`${e}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(t,n.forwardTo),n.children)for(const[e,i]of pe(n.children,t))r.set(e,i)}return r}function me(t,e,r,n){return e?function(t){const e=new Set;for(const r of t){for(const t of r.paramMeta.urlParams)e.add(t);for(const t of r.paramMeta.spatParams)e.add(t)}return e}(function(t,e){const r=[],n=e.includes(".")?e.split("."):[e];""!==t.path&&r.push(t);let i=t;for(const t of n){const e=i.children.get(t);if(!e)return null;r.push(e),i=e}return r}(r,t)??[]):he(de(n,t))}function ge(t,e,r,n,i){const s=function(t,e){const r=e.split(".");let n=t;for(const t of r)if(n=n.children.get(t),!n)return!1;return!0}(i,e),o=n.has(e);if(!s&&!o)throw new Error(`[router.addRoute] forwardTo target "${e}" does not exist for route "${t}"`);const a=he(de(r,t)),c=[...me(e,s,i,r)].filter(t=>!a.has(t));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${e}" requires params [${c.join(", ")}] that are not available in source route "${t}"`)}function ve(t,e,r=100){const n=new Set,i=[t];let s=t;for(;e[s];){const t=e[s];if(n.has(t)){const e=i.indexOf(t),r=[...i.slice(e),t];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(s),i.push(t),s=t,i.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${i.join(" → ")}`)}return s}function ye(t,e,r){const n=fe(t),i=pe(t),s={...e};for(const[t,e]of i)s[t]=e;for(const[e,s]of i)ge(e,s,t,n,r);for(const t of Object.keys(s))ve(t,s)}function we(t,e,r){if(!d(t))throw new TypeError(`[router.${r}] Invalid routeName: ${m(t)}. Expected string.`);if(!h(e))throw new TypeError(`[router.${r}] Invalid routeParams: ${m(e)}. Expected plain object.`)}function Se(t,e,r,n){if(n&&e){let t=e;for(const e of n.split("."))if(t=t.children.get(e),!t)throw new Error(`[router.addRoute] Parent route "${n}" does not exist`)}const i=new Set,s=new Map;for(const r of t)ce(r,"addRoute",e,n??"",i,s);e&&r&&ye(t,r,e)}function Te(t,e,r){const n=te("",e,t),i=re(r);return i.registerTree(n),{tree:n,matcher:i}}function be(t,e){const r=Te(t.definitions,t.rootPath,t.matcherOptions);t.tree=r.tree,t.matcher=r.matcher,t.resolvedForwardMap=function(t,e){return e?Ne(t):Oe(t)}(t.config,e)}function Ee(t){const e=Te(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function Ae(t){!function(t){t.definitions.length=0,Object.assign(t.config,vt()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),Ee(t)}function Oe(t){const e=Object.create(null);for(const r of Object.keys(t.forwardMap))e[r]=ve(r,t.forwardMap);return e}function Ne(t){const e=Object.create(null);for(const r of Object.keys(t.forwardMap)){let n=r;for(;t.forwardMap[n];)n=t.forwardMap[n];e[r]=n}return e}function Pe(e,r,n,i,s,o,a){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(e).filter(([t])=>!c.has(t)));Object.keys(u).length>0&&(i[r]=u),e.canActivate&&s.set(r,e.canActivate),e.canDeactivate&&o.set(r,e.canDeactivate),e.forwardTo&&function(e,r,n){if(e.canActivate&&t.logger.warn("real-router",`Route "${r}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),e.canDeactivate&&t.logger.warn("real-router",`Route "${r}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),"function"==typeof e.forwardTo){const t="AsyncFunction"===e.forwardTo.constructor.name,n=e.forwardTo.toString().includes("__awaiter");if(t||n)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?n.forwardMap[r]=e.forwardTo:n.forwardFnMap[r]=e.forwardTo}(e,r,n),e.decodeParams&&(n.decoders[r]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(n.encoders[r]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(n.defaultParams[r]=e.defaultParams)}function Re(t,e,r,n,i,s,o=""){for(const a of t){const t=o?`${o}.${a.name}`:a.name;Pe(a,t,e,r,n,i),a.children&&Re(a.children,e,r,n,i,s,t)}}function $e(t,e,r){const n=[],i=vt(),s=Object.create(null),o=new Map,a=new Map;for(const e of t)n.push(yt(e));const{tree:c,matcher:u}=Te(n,"",r);return Re(t,i,s,o,a,void 0,""),{definitions:n,config:i,tree:c,matcher:u,resolvedForwardMap:e?Ne(i):Oe(i),routeCustomFields:s,rootPath:"",matcherOptions:r,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:o,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:be,resetStore:Ae,nodeToDefinition:ee,validateRoutes:Se}}}var Ce=".",De=[];function je(t){const e=[];for(let r=t.length-1;r>=0;r--)e.push(t[r]);return e}function Fe(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Ie(t,e,r){const n=e.meta?.params[t];if(!n||"object"!=typeof n)return!0;for(const t of Object.keys(n)){const n=e.params[t],i=r.params[t];if(Fe(n)&&Fe(i)&&String(n)!==String(i))return!1}return!0}Object.freeze(De);var Le,xe,_e=new Map;function Me(t){const e=_e.get(t);if(e)return e;const r=function(t){if(!t)return[""];const e=t.indexOf(Ce);if(-1===e)return[t];const r=t.indexOf(Ce,e+1);if(-1===r)return[t.slice(0,e),t];const n=t.indexOf(Ce,r+1);if(-1===n)return[t.slice(0,e),t.slice(0,r),t];return-1===t.indexOf(Ce,n+1)?[t.slice(0,e),t.slice(0,r),t.slice(0,n),t]:function(t){const e=t.split(Ce),r=e.length,n=[e[0]];let i=e[0].length;for(let s=1;s<r-1;s++)i+=1+e[s].length,n.push(t.slice(0,i));return n.push(t),n}(t)}(t);return Object.freeze(r),_e.set(t,r),r}var Ue,ke,Be=null,ze=null;function qe(t,e){if(!e)return{intersection:"",toActivate:Me(t.name),toDeactivate:De};if(void 0===t.meta?.params&&void 0===e.meta?.params)return{intersection:"",toActivate:Me(t.name),toDeactivate:je(Me(e.name))};const r=Me(t.name),n=Me(e.name),i=function(t,e,r,n,i){for(let s=0;s<i;s++){const i=r[s];if(i!==n[s])return s;if(!Ie(i,t,e))return s}return i}(t,e,r,n,Math.min(n.length,r.length));let s;if(i>=n.length)s=De;else if(0===i&&1===n.length)s=n;else{s=[];for(let t=n.length-1;t>=i;t--)s.push(n[t])}const o=0===i?r:r.slice(i);return{intersection:i>0?n[i-1]:"",toDeactivate:s,toActivate:o}}function We(t,e,r){if(r)return qe(t,e);if(null!==Be&&t===Le&&e===xe)return Be;if(null!==ze&&t===Ue&&e===ke)return ze;const n=qe(t,e);return Ue=Le,ke=xe,ze=Be,Le=t,xe=e,Be=n,n}function Ge(t,e){var r;return{name:e??(r=t.segments,r.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var Ve=class{#z;#q;get#f(){return this.#z.depsStore}constructor(t=[],e=!1,r){this.#z=$e(t,e,r)}static shouldUpdateNode(t){return(e,r)=>{if(!e||"object"!=typeof e||!("name"in e))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(e.transition?.reload)return!0;if(""===t&&!r)return!0;const{intersection:n,toActivate:i,toDeactivate:s}=We(e,r);return t===n||!!i.includes(t)||s.includes(t)}}setDependencies(t){this.#z.depsStore=t;for(const[e,r]of this.#z.pendingCanActivate)t.addActivateGuard(e,r);this.#z.pendingCanActivate.clear();for(const[e,r]of this.#z.pendingCanDeactivate)t.addDeactivateGuard(e,r);this.#z.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#z.lifecycleNamespace=t}setRootPath(t){this.#z.rootPath=t,Ee(this.#z)}hasRoute(t){return this.#z.matcher.hasRoute(t)}clearRoutes(){Ae(this.#z)}buildPath(t,e,r){if(t===w.UNKNOWN_ROUTE)return d(e?.path)?e.path:"";const n=Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e??{},i="function"==typeof this.#z.config.encoders[t]?this.#z.config.encoders[t]({...n}):n;return this.#z.matcher.buildPath(t,i,this.#W(r))}matchPath(t,e){const r=e,n=this.#z.matcher.match(t);if(!n)return;const i=Ge(n),{name:s,params:o,meta:a}=i,c="function"==typeof this.#z.config.decoders[s]?this.#z.config.decoders[s](o):o,{name:u,params:l}=this.#f.forwardState(s,c);let h=t;if(r.rewritePathOnMatch){const t="function"==typeof this.#z.config.encoders[u]?this.#z.config.encoders[u]({...l}):l,e=r.trailingSlash;h=this.#z.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:r.queryParamsMode})}return this.#f.makeState(u,l,h,a)}forwardState(t,e){if(Object.hasOwn(this.#z.config.forwardFnMap,t)){const r=this.#G(t,e),n=this.#z.config.forwardFnMap[t],i=this.#V(t,n,e);return{name:i,params:this.#G(i,r)}}const r=this.#z.resolvedForwardMap[t]??t;if(r!==t&&Object.hasOwn(this.#z.config.forwardFnMap,r)){const n=this.#G(t,e),i=this.#z.config.forwardFnMap[r],s=this.#V(r,i,e);return{name:s,params:this.#G(s,n)}}if(r!==t){const n=this.#G(t,e);return{name:r,params:this.#G(r,n)}}return{name:t,params:this.#G(t,e)}}buildStateResolved(t,e){const r=this.#z.matcher.getSegmentsByName(t);if(r)return Ge({segments:r,params:e,meta:this.#z.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},r=!1,n=!0){gt.has(t)||(p(t,"isActiveRoute"),gt.add(t));const i=this.#f.getState();if(!i)return!1;const s=i.name;if(s!==t&&!s.startsWith(`${t}.`)&&!t.startsWith(`${s}.`))return!1;const o=this.#z.config.defaultParams[t];if(r||s===t){const r=o?{...o,...e}:e;return this.#f.areStatesEqual({name:t,params:r,path:""},i,n)}const a=i.params;return!!function(t,e){for(const r in t)if(t[r]!==e[r])return!1;return!0}(e,a)&&(!o||function(t,e,r){for(const n in t)if(!(n in r)&&t[n]!==e[n])return!1;return!0}(o,a,e))}getMetaForState(t){return this.#z.matcher.hasRoute(t)?this.#z.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#z.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const r of t)for(const t of r.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#z}#G(t,e){return Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e}#W(t){if(this.#q)return this.#q;const e=t?.trailingSlash;return this.#q=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#q}#V(t,e,r){const n=new Set([t]);let i=e(this.#f.getDependency,r),s=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;s<100;){if(void 0===this.#z.matcher.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(n.has(i)){const t=[...n,i].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(n.add(i),Object.hasOwn(this.#z.config.forwardFnMap,i)){i=(0,this.#z.config.forwardFnMap[i])(this.#f.getDependency,r),s++;continue}const t=this.#z.config.forwardMap[i];if(void 0===t)return i;i=t,s++}throw new Error("forwardTo exceeds maximum depth of 100")}},Qe=new Set(Object.values(v)),He=new Set(["code","segment","path","redirect"]),Ke=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Je=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:r,path:n,redirect:i,...s}={}){super(e??t),this.code=t,this.segment=r,this.path=n,this.redirect=i?function(t){if(!t)return t;if(null===(e=t)||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path||"object"!=typeof e.params||null===e.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof t);var e;const r=structuredClone(t),n=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(n.has(e))return;n.add(e),Object.freeze(e);const r=Array.isArray(e)?e:Object.values(e);for(const e of r)t(e)}(r),r}(i):void 0;for(const[t,e]of Object.entries(s)){if(He.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);Ke.has(t)||(this[t]=e)}}setCode(t){this.code=t,Qe.has(this.message)&&(this.message=t)}setErrorInstance(t){if(!t)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=t.message,this.cause=t.cause,this.stack=t.stack??""}setAdditionalFields(t){for(const[e,r]of Object.entries(t)){if(He.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);Ke.has(e)||(this[e]=r)}}hasField(t){return t in this}getField(t){return this[t]}toJSON(){const t={code:this.code,message:this.message};void 0!==this.segment&&(t.segment=this.segment),void 0!==this.path&&(t.path=this.path),void 0!==this.redirect&&(t.redirect=this.redirect);const e=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!e.has(r)&&(t[r]=this[r]);return t}},Ye=new Je(v.ROUTER_NOT_STARTED),Ze=new Je(v.ROUTE_NOT_FOUND),Xe=new Je(v.SAME_STATES),tr=Promise.reject(Ye),er=Promise.reject(Ze),rr=Promise.reject(Xe);function nr(t,e){const{toState:r,fromState:n,opts:i,toDeactivate:s,toActivate:o,intersection:a}=e;if(r.name!==w.UNKNOWN_ROUTE&&!t.hasRoute(r.name)){const e=new Je(v.ROUTE_NOT_FOUND,{routeName:r.name});throw t.sendTransitionFail(r,n,e),e}if(n)for(const r of s)!o.includes(r)&&e.canDeactivateFunctions.has(r)&&t.clearCanDeactivate(r);r.transition=function(t,e,r,n,i){const s={phase:"activating",reason:"success",segments:{deactivated:r,activated:n,intersection:i}};return void 0!==t?.name&&(s.from=t.name),void 0!==e.reload&&(s.reload=e.reload),void 0!==e.redirected&&(s.redirected=e.redirected),s}(n,i,s,o,a);const c=V(r);t.setState(c);const u=void 0===i.signal?i:function({signal:t,...e}){return e}(i);return t.sendTransitionDone(c,n,u),c}function ir(t,e,r,n){e.code!==v.TRANSITION_CANCELLED&&e.code!==v.ROUTE_NOT_FOUND&&t.sendTransitionFail(r,n,e)}function sr(t,e,r){if(t instanceof DOMException&&"AbortError"===t.name)throw new Je(v.TRANSITION_CANCELLED);!function(t,e,r){if(t instanceof Je)throw t.setCode(e),t;throw new Je(e,function(t,e){const r={segment:e};if(t instanceof Error)return{...r,message:t.message,stack:t.stack,..."cause"in t&&void 0!==t.cause&&{cause:t.cause}};if(t&&"object"==typeof t){const e={};for(const[r,n]of Object.entries(t))or.has(r)||(e[r]=n);return{...r,...e}}return r}(t,r))}(t,e,r)}tr.catch(()=>{}),er.catch(()=>{}),rr.catch(()=>{});var or=new Set(["code","segment","path","redirect"]);async function ar(t,e,r){let n;try{n=await t}catch(t){return void sr(t,e,r)}if(!n)throw new Je(e,{segment:r})}async function cr(t,e,r,n,i,s,o,a,c,u){await ar(c,r,u);for(let c=a;c<e.length;c++){if(!o())throw new Je(v.TRANSITION_CANCELLED);const a=e[c],u=t.get(a);if(!u)continue;let l=!1;try{l=u(n,i,s)}catch(t){sr(t,r,a)}if(l instanceof Promise)await ar(l,r,a);else if(!l)throw new Je(r,{segment:a})}}function ur(t,e,r,n,i,s,o){for(const[a,c]of e.entries()){if(!o())throw new Je(v.TRANSITION_CANCELLED);const u=t.get(c);if(!u)continue;let l=!1;try{l=u(n,i,s)}catch(t){sr(t,r,c)}if(l instanceof Promise)return cr(t,e,r,n,i,s,o,a+1,l,c);if(!l)throw new Je(r,{segment:c})}}var lr=[w.UNKNOWN_ROUTE];Object.freeze(lr);var hr={replace:!0};Object.freeze(hr);var dr=class{lastSyncResolved=!1;lastSyncRejected=!1;#f;#Q=null;#H=0;static validateNavigateArgs(t){!function(t){if("string"!=typeof t)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${m(t)}`)}(t)}static validateNavigateToDefaultArgs(t){!function(t){if(void 0!==t&&("object"!=typeof t||null===t))throw new TypeError(`[router.navigateToDefault] Invalid options: ${m(t)}. Expected NavigationOptions object.`)}(t)}static validateNavigationOptions(t,e){!function(t,e){if(!function(t){if("object"!=typeof t||null===t||Array.isArray(t))return!1;const e=t;for(const t of s){const r=e[t];if(void 0!==r&&"boolean"!=typeof r)return!1}const r=e.signal;return!(void 0!==r&&!(r instanceof AbortSignal))}(t))throw new TypeError(`[router.${e}] Invalid options: ${m(t)}. Expected NavigationOptions object.`)}(t,e)}setDependencies(t){this.#f=t}navigate(t,e,r){this.lastSyncResolved=!1;const n=this.#f;if(!n.canNavigate())return this.lastSyncRejected=!0,tr;let i,s,o=!1,a=null;try{if(i=n.buildNavigateState(t,e),!i)return n.emitTransitionError(void 0,n.getState(),Ze),this.lastSyncRejected=!0,er;if(s=n.getState(),r=function(t,e){return e?.name!==w.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(r,s),function(t,e,r,n){return!!t&&!e.reload&&!e.force&&n(t,r,!1)}(s,r,i,n.areStatesEqual))return n.emitTransitionError(i,s,Xe),this.lastSyncRejected=!0,rr;if(this.#K(),r.signal?.aborted)throw new Je(v.TRANSITION_CANCELLED,{reason:r.signal.reason});const c=++this.#H;if(n.startTransition(i,s),o=!0,this.#H!==c)throw new Je(v.TRANSITION_CANCELLED);const[u,l]=n.getLifecycleFunctions(),h=i.name===w.UNKNOWN_ROUTE,{toDeactivate:d,toActivate:f,intersection:p}=We(i,s,r.reload),m=s&&!r.forceDeactivate&&d.length>0,g=!h&&f.length>0;if(u.size>0||l.size>0){a=new AbortController,this.#Q=a;const t=()=>this.#H===c&&n.isActive(),e=function(t,e,r,n,i,s,o,a,c,u){if(i){const i=ur(t,r,v.CANNOT_DEACTIVATE,o,a,c,u);if(void 0!==i)return async function(t,e,r,n,i,s,o,a){if(await t,!a())throw new Je(v.TRANSITION_CANCELLED);if(n){const t=ur(e,r,v.CANNOT_ACTIVATE,i,s,o,a);if(void 0!==t&&await t,!a())throw new Je(v.TRANSITION_CANCELLED)}}(i,e,n,s,o,a,c,u)}if(!u())throw new Je(v.TRANSITION_CANCELLED);if(s)return ur(e,n,v.CANNOT_ACTIVATE,o,a,c,u)}(u,l,d,f,!!m,g,i,s,a.signal,t);if(void 0!==e)return this.#J(e,{toState:i,fromState:s,opts:r,toDeactivate:d,toActivate:f,intersection:p,canDeactivateFunctions:u},a,c);if(!t())throw new Je(v.TRANSITION_CANCELLED);this.#Y(a)}return this.lastSyncResolved=!0,Promise.resolve(nr(n,{toState:i,fromState:s,opts:r,toDeactivate:d,toActivate:f,intersection:p,canDeactivateFunctions:u}))}catch(t){return this.#Z(t,a,o,i,s),Promise.reject(t)}}navigateToDefault(t){const e=this.#f;if(!e.getOptions().defaultRoute)return Promise.reject(new Je(v.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:r,params:n}=e.resolveDefault();return r?this.navigate(r,n,t):Promise.reject(new Je(v.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#K();const e=this.#f.getState(),r=e?Me(e.name).toReversed():[];Object.freeze(r);const n={deactivated:r,activated:lr,intersection:""};Object.freeze(n);const i={phase:"activating",...e&&{from:e.name},reason:"success",segments:n};Object.freeze(i);const s={name:w.UNKNOWN_ROUTE,params:{},path:t,transition:i};return Object.freeze(s),this.#f.setState(s),this.#f.emitTransitionSuccess(s,e,hr),s}abortCurrentNavigation(){this.#Q?.abort(new Je(v.TRANSITION_CANCELLED)),this.#Q=null}async#J(t,e,r,n){const i=this.#f,s=()=>this.#H===n&&!r.signal.aborted&&i.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new Je(v.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{r.abort(e.opts.signal?.reason)},{once:!0,signal:r.signal})}if(await t,!s())throw new Je(v.TRANSITION_CANCELLED);return nr(i,e)}catch(t){throw ir(i,t,e.toState,e.fromState),t}finally{this.#Y(r)}}#Z(t,e,r,n,i){e&&this.#Y(e),r&&n&&ir(this.#f,t,n,i)}#Y(t){t.abort(),this.#Q===t&&(this.#Q=null)}#K(){this.#f.isTransitioning()&&(t.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#Q?.abort(new Je(v.TRANSITION_CANCELLED)),this.#f.cancelNavigation())}},fr={replace:!0};Object.freeze(fr);var pr=class{#f;static validateStartArgs(t){if(1!==t.length||"string"!=typeof t[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setDependencies(t){this.#f=t}async start(t){const e=this.#f,r=e.getOptions(),n=e.matchPath(t);if(!n&&!r.allowNotFound){const r=new Je(v.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,r),r}return e.completeStart(),n?e.navigate(n.name,n.params,fr):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},mr=class{#X;#tt;#et;#rt;#nt;#it;constructor(t){this.#X=t.routerFSM,this.#tt=t.emitter,this.#et=void 0,this.#st()}static validateSubscribeListener(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#tt.emit(N.ROUTER_START)}emitRouterStop(){this.#tt.emit(N.ROUTER_STOP)}emitTransitionStart(t,e){this.#tt.emit(N.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,r){this.#tt.emit(N.TRANSITION_SUCCESS,t,e,r)}emitTransitionError(t,e,r){this.#tt.emit(N.TRANSITION_ERROR,t,e,r)}emitTransitionCancel(t,e){this.#tt.emit(N.TRANSITION_CANCEL,t,e)}sendStart(){this.#X.send(L)}sendStop(){this.#X.send(B)}sendDispose(){this.#X.send(z)}sendStarted(){this.#X.send(x)}sendNavigate(t,e){this.#et=t,this.#X.forceState(F),this.emitTransitionStart(t,e)}sendComplete(t,e,r={}){this.#X.forceState(j),this.emitTransitionSuccess(t,e,r),this.#et===t&&(this.#et=void 0)}sendFail(t,e,r){const n=this.#et;this.#rt=t,this.#nt=e,this.#it=r,this.#X.send(U),this.#et===n&&(this.#et=void 0)}sendFailSafe(t,e,r){this.isReady()?this.sendFail(t,e,r):this.emitTransitionError(t,e,r)}sendCancel(t,e){const r=this.#et;this.#rt=t,this.#nt=e,this.#X.send(k),this.#et===r&&(this.#et=void 0)}canBeginTransition(){return this.#X.canSend(_)}canStart(){return this.#X.canSend(L)}canCancel(){return this.#X.canSend(k)}isActive(){const t=this.#X.getState();return t!==C&&t!==I}isDisposed(){return this.#X.getState()===I}isTransitioning(){return this.#X.getState()===F}isReady(){return this.#X.getState()===j}getCurrentToState(){return this.#et}addEventListener(t,e){return this.#tt.on(t,e)}subscribe(t){return this.#tt.on(N.TRANSITION_SUCCESS,(e,r)=>{t({route:e,previousRoute:r})})}clearAll(){this.#tt.clearAll()}setLimits(t){this.#tt.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#et,t)}#ot(){this.emitTransitionError(this.#rt,this.#nt,this.#it)}#st(){const t=this.#X;t.on(D,x,()=>{this.emitRouterStart()}),t.on(j,B,()=>{this.emitRouterStop()}),t.on(F,k,()=>{const t=this.#rt;void 0!==t&&this.emitTransitionCancel(t,this.#nt)}),t.on(D,U,()=>{this.#ot()}),t.on(j,U,()=>{this.#ot()}),t.on(F,U,()=>{this.#ot()})}},gr=new Je(v.ROUTER_ALREADY_STARTED),vr=new Set(["all","warn-error","error-only"]);var yr=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(t){this.router=t.router,this.options=t.options,this.limits=t.limits,this.dependenciesStore=t.dependenciesStore,this.state=t.state,this.routes=t.routes,this.routeLifecycle=t.routeLifecycle,this.plugins=t.plugins,this.navigation=t.navigation,this.lifecycle=t.lifecycle,this.eventBus=t.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const t={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(t)}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0,!0)},makeState:(t,e,r,n)=>this.state.makeState(t,e,r,n),getState:()=>this.state.get(),areStatesEqual:(t,e,r)=>this.state.areStatesEqual(t,e,r),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const r=K(this.router);return r.noValidate||we(t,e,"forwardState"),r.forwardState(t,e)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const t={addEventListener:(t,e)=>this.eventBus.addEventListener(t,e),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(t)}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:t=>this.routes.hasRoute(t),getState:()=>this.state.get(),setState:t=>{this.state.set(t)},buildNavigateState:(t,e)=>{const r=K(this.router);r.noValidate||we(t,e,"navigate");const{name:n,params:i}=r.forwardState(t,e),s=this.routes.getMetaForState(n);if(void 0===s)return;const o=r.buildPath(n,i);return this.state.makeState(n,i,o,s,void 0,!0)},areStatesEqual:(t,e,r)=>this.state.areStatesEqual(t,e,r),resolveDefault:()=>{const t=this.options.get();return{route:rt(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:rt(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,r)=>{this.eventBus.sendComplete(t,e,r)},sendTransitionFail:(t,e,r)=>{this.eventBus.sendFail(t,e,r)},emitTransitionError:(t,e,r)=>{this.eventBus.sendFailSafe(t,e,r)},emitTransitionSuccess:(t,e,r)=>{this.eventBus.emitTransitionSuccess(t,e,r)},canNavigate:()=>this.eventBus.canBeginTransition(),getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:t=>{this.routeLifecycle.clearCanDeactivate(t)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(t,e,r)=>this.navigation.navigate(t,e,r),navigateToNotFound:t=>this.navigation.navigateToNotFound(t),clearState:()=>{this.state.set(void 0)},matchPath:t=>this.routes.matchPath(t,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(t,e,r)=>{this.eventBus.sendFail(t,e,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>K(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return r=>r(t,t=>e.dependencies[t])}},wr=Object.freeze({}),Sr=class r{#u;#y;#at;#ct;#ut;#lt;#g;#ht;#dt;#ft;#pt;constructor(r=[],n={},s={}){n.logger&&function(t){if("object"!=typeof t||null===t)throw new TypeError("Logger config must be an object");const e=t;for(const t of Object.keys(e))if("level"!==t&&"callback"!==t)throw new TypeError(`Unknown logger config property: "${t}"`);if("level"in e&&void 0!==e.level&&("string"!=typeof(r=e.level)||!vr.has(r)))throw new TypeError(`Invalid logger level: ${function(t){return"string"==typeof t?`"${t}"`:"object"==typeof t?JSON.stringify(t):String(t)}(e.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in e&&void 0!==e.callback&&"function"!=typeof e.callback)throw new TypeError("Logger callback must be a function, got "+typeof e.callback);return!0}(n.logger)&&(t.logger.configure(n.logger),delete n.logger),ot.validateOptions(n,"constructor");const o=n.noValidate??!1;o||function(t,e){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError(`[router.${e}] Invalid argument: expected plain object, received ${m(t)}`);for(const r in t)if(Object.getOwnPropertyDescriptor(t,r)?.get)throw new TypeError(`[router.${e}] Getters not allowed: "${r}"`)}(s,"constructor"),!o&&r.length>0&&(function(t){for(const e of t){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.addRoute] Route must be an object, got ${m(e)}`);ue(e,e.name)}}(r),Se(r)),this.#u=new ot(n),this.#y=function(t={}){return{...P,...t}}(n.limits),this.#at=function(t={}){const e=Object.create(null);for(const r in t)void 0!==t[r]&&(e[r]=t[r]);return{dependencies:e,limits:P}}(s),this.#ct=new ct,this.#ut=new Ve(r,o,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#lt=new mt,this.#g=new dt,this.#ht=new dr,this.#dt=new pr,this.#pt=o;const a=new e.FSM(q),c=new i({onListenerError:(e,r)=>{t.logger.error("Router",`Error in listener for ${e}:`,r)},onListenerWarn:(e,r)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${r} listeners — possible memory leak`)}});var u;this.#ft=new mr({routerFSM:a,emitter:c}),(u=new yr({router:this,options:this.#u,limits:this.#y,dependenciesStore:this.#at,state:this.#ct,routes:this.#ut,routeLifecycle:this.#lt,plugins:this.#g,navigation:this.#ht,lifecycle:this.#dt,eventBus:this.#ft})).wireLimits(),u.wireRouteLifecycleDeps(),u.wireRoutesDeps(),u.wirePluginsDeps(),u.wireNavigationDeps(),u.wireLifecycleDeps(),u.wireStateDeps();const l=new Map;var h,d,f;h={makeState:(t,e,r,n,i)=>this.#ct.makeState(t,e,r,n,i),forwardState:Y("forwardState",(t,e)=>this.#ut.forwardState(t,e),l),buildStateResolved:(t,e)=>this.#ut.buildStateResolved(t,e),matchPath:(t,e)=>this.#ut.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#ft.addEventListener(t,e),buildPath:Y("buildPath",(t,e)=>this.#ut.buildPath(t,e??R,this.#u.get()),l),start:(d=t=>(o||pr.validateStartArgs([t]),this.#dt.start(t)),f=l,(...t)=>{const e=f.get("start");return e&&0!==e.length?J(e,d,t):d(...t)}),interceptors:l,setRootPath:t=>{this.#ut.setRootPath(t)},getRootPath:()=>this.#ut.getStore().rootPath,getTree:()=>this.#ut.getStore().tree,isDisposed:()=>this.#ft.isDisposed(),noValidate:o,dependenciesGetStore:()=>this.#at,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#at.dependencies}),getLifecycleFactories:()=>this.#lt.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#ut.getStore(),getStateName:()=>this.#ct.get()?.name,isTransitioning:()=>this.#ft.isTransitioning(),clearState:()=>{this.#ct.set(void 0)},setState:t=>{this.#ct.set(t)},routerExtensions:[]},H.set(this,h),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,r,n,i){return this.#pt||function(t,e,r,n){if(!d(t))throw new TypeError("Route name must be a string");if(void 0!==e&&!h(e))throw new TypeError("[router.isActiveRoute] Invalid params structure");if(void 0!==r&&"boolean"!=typeof r)throw new TypeError("[router.isActiveRoute] strictEquality must be a boolean, got "+typeof r);if(void 0!==n&&"boolean"!=typeof n)throw new TypeError("[router.isActiveRoute] ignoreQueryParams must be a boolean, got "+typeof n)}(e,r,n,i),""===e?(t.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ut.isActiveRoute(e,r,n,i)}buildPath(t,e){return this.#pt||function(t){if(!d(t)||""===t)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof t?'""':typeof t))}(t),K(this).buildPath(t,e)}getState(){return this.#ct.get()}getPreviousState(){return this.#ct.getPrevious()}areStatesEqual(t,e,r=!0){return this.#pt||ct.validateAreStatesEqualArgs(t,e,r),this.#ct.areStatesEqual(t,e,r)}shouldUpdateNode(t){return this.#pt||function(t){if(!d(t))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof t)}(t),Ve.shouldUpdateNode(t)}isActive(){return this.#ft.isActive()}start(t){if(!this.#ft.canStart())return Promise.reject(gr);this.#ft.sendStart();const e=K(this).start(t).catch(t=>{throw this.#ft.isReady()&&(this.#dt.stop(),this.#ft.sendStop()),t});return r.#mt(e),e}stop(){return this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),this.#ft.isReady()||this.#ft.isTransitioning()?(this.#dt.stop(),this.#ft.sendStop(),this):this}dispose(){if(this.#ft.isDisposed())return;this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),(this.#ft.isReady()||this.#ft.isTransitioning())&&(this.#dt.stop(),this.#ft.sendStop()),this.#ft.sendDispose(),this.#ft.clearAll(),this.#g.disposeAll();const t=K(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ut.clearRoutes(),this.#lt.clearAll(),this.#ct.reset(),this.#at.dependencies=Object.create(null),this.#gt()}canNavigateTo(t,e){if(this.#pt||p(t,"canNavigateTo"),!this.#ut.hasRoute(t))return!1;const r=K(this),{name:n,params:i}=r.forwardState(t,e??{}),s=this.#ct.makeState(n,i),o=this.#ct.get(),{toDeactivate:a,toActivate:c}=We(s,o);return this.#lt.canNavigateTo(a,c,s,o)}usePlugin(...t){return this.#pt||(dt.validateUsePluginArgs(t),dt.validatePluginLimit(this.#g.count(),t.length,this.#y.maxPlugins),dt.validateNoDuplicatePlugins(t,this.#g.has.bind(this.#g))),this.#g.use(...t)}subscribe(t){return this.#pt||mr.validateSubscribeListener(t),this.#ft.subscribe(t)}navigate(t,e,n){this.#pt||dr.validateNavigateArgs(t);const i=n??wr;this.#pt||dr.validateNavigationOptions(i,"navigate");const s=this.#ht.navigate(t,e??R,i);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:r.#mt(s),s}navigateToDefault(t){this.#pt||dr.validateNavigateToDefaultArgs(t);const e=t??wr;this.#pt||dr.validateNavigationOptions(e,"navigateToDefault");const n=this.#ht.navigateToDefault(e);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:r.#mt(n),n}navigateToNotFound(t){if(!this.#ft.isActive())throw new Je(v.ROUTER_NOT_STARTED);const e=t??this.#ct.get().path;return this.#ht.navigateToNotFound(e)}static#vt=e=>{e instanceof Je&&(e.code===v.SAME_STATES||e.code===v.TRANSITION_CANCELLED||e.code===v.ROUTER_NOT_STARTED||e.code===v.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#mt(t){t.catch(r.#vt)}#gt(){this.navigate=Tr,this.navigateToDefault=Tr,this.navigateToNotFound=Tr,this.start=Tr,this.stop=Tr,this.usePlugin=Tr,this.subscribe=Tr,this.canNavigateTo=Tr}};function Tr(){throw new Je(v.ROUTER_DISPOSED)}var br=new WeakMap;exports.Router=Sr,exports.RouterError=Je,exports.UNKNOWN_ROUTE=y,exports.constants=w,exports.createRouter=(t=[],e={},r={})=>new Sr(t,e,r),exports.errorCodes=v,exports.events=N,exports.getNavigator=t=>{let e=br.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),br.set(t,e)),e};//# sourceMappingURL=index.js.map
1
+ var t=require("@real-router/logger"),e=require("@real-router/fsm"),n={maxListeners:0,warnListeners:0,maxEventDepth:0},r=class extends Error{},i=class{#t=new Map;#e=null;#n=n;#r;#i;constructor(t){t?.limits&&(this.#n=t.limits),this.#r=t?.onListenerError??null,this.#i=t?.onListenerWarn??null}static validateCallback(t,e){if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}setLimits(t){this.#n=t}on(t,e){const n=this.#s(t);if(n.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:r,warnListeners:i}=this.#n;if(0!==i&&n.size===i&&this.#i?.(t,i),0!==r&&n.size>=r)throw new Error(`Listener limit (${r}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,r,i){const s=this.#t.get(t);if(!s||0===s.size)return;const a=arguments.length-1;0!==this.#n.maxEventDepth?this.#a(s,t,a,e,n,r,i):this.#o(s,t,a,e,n,r,i)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,r,i,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,r,i,s,a)}catch(t){this.#r?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,r,i,s,a)}catch(t){this.#r?.(e,t)}}#c(t,e,n,r,i,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,r);break;case 3:t(n,r,i);break;default:t(n,r,i,s)}}#a(t,e,n,i,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new r(`Maximum recursion depth (${this.#n.maxEventDepth}) exceeded for event: ${e}`);try{c.set(e,u+1);const l=1===t.size?t:[...t];for(const t of l)try{this.#c(t,n,i,s,a,o)}catch(t){if(t instanceof r)throw t;this.#r?.(e,t)}}finally{c.set(e,c.get(e)-1)}}#s(t){const e=this.#t.get(t);if(e)return e;const n=new Set;return this.#t.set(t,n),n}},s=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),a="@@router/UNKNOWN_ROUTE",o={UNKNOWN_ROUTE:a},c="onStart",u="onStop",l="onTransitionStart",h="onTransitionCancel",d="onTransitionSuccess",f="onTransitionError",p={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},g={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},m=Object.freeze({}),v="IDLE",S="STARTING",T="READY",y="TRANSITIONING",w="DISPOSED",b="START",N="STARTED",A="NAVIGATE",O="COMPLETE",E="FAIL",P="CANCEL",R="STOP",C="DISPOSE",D={initial:v,context:null,transitions:{[v]:{[b]:S,[C]:w},[S]:{[N]:T,[E]:v},[T]:{[A]:y,[E]:T,[R]:v},[y]:{[A]:y,[O]:T,[P]:T,[E]:T},[w]:{}}};function F(t,e){for(const e of t){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError("route must be a non-array object");const t=e.children;t&&F(t)}}var j=new WeakSet;function L(t){if(null!==t&&"object"==typeof t&&!Object.isFrozen(t))if(Object.freeze(t),Array.isArray(t))for(const e of t)L(e);else for(const e in t)L(t[e])}function I(t){return t?(j.has(t)||(L(t),j.add(t)),t):t}var _=new WeakMap;function M(t){const e=_.get(t);if(!e)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return e}function U(t,e,n){let r=e;for(const e of t){const t=r;r=(...n)=>e(t,...n)}return r(...n)}function $(t,e,n){return(r,i)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[r,i]):e(r,i)}}var B={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function x(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&x(n)}return t}function k(t,e){return"function"==typeof t?t(e):t}var z=class{#u;constructor(t={}){this.#u=x({...B,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function q(t,e){return t===e||!(!Array.isArray(t)||!Array.isArray(e))&&t.length===e.length&&t.every((t,n)=>q(t,e[n]))}var G=class{#l=0;#h=void 0;#d=void 0;#f;#p=new Map;get(){return this.#h}set(t){this.#d=this.#h,this.#h=t?I(t):void 0}getPrevious(){return this.#d}reset(){this.#h=void 0,this.#d=void 0,this.#p.clear(),this.#l=0}setDependencies(t){this.#f=t}makeState(t,e,n,r,i,s){const a=r?{id:i??++this.#l,params:r}:void 0,o=this.#f.getDefaultParams();let c;c=Object.hasOwn(o,t)?{...o[t],...e}:e&&e!==m?{...e}:m;const u={name:t,params:c,path:n??this.#f.buildPath(t,e),meta:a};return s?u:I(u)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=t.meta?.params??e.meta?.params;return(n?function(t){const e=[];for(const n in t){const r=t[n];for(const t in r)"url"===r[t]&&e.push(t)}return e}(n):this.#g(t.name)).every(n=>q(t.params[n],e.params[n]))}const r=Object.keys(t.params),i=Object.keys(e.params);return r.length===i.length&&r.every(n=>n in e.params&&q(t.params[n],e.params[n]))}#g(t){const e=this.#p.get(t);if(void 0!==e)return e;const n=this.#f.getUrlParams(t);return this.#p.set(t,n),n}},W={[c]:p.ROUTER_START,[u]:p.ROUTER_STOP,[d]:p.TRANSITION_SUCCESS,[l]:p.TRANSITION_START,[f]:p.TRANSITION_ERROR,[h]:p.TRANSITION_CANCEL},V=Object.keys(W),Q="router.usePlugin",K=class e{#m=new Set;#v=new Set;#f;#S=g;#T=null;static validatePlugin(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.usePlugin] Plugin factory must return an object, got "+typeof t);if("function"==typeof t.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#T=t}count(){return this.#m.size}use(...e){if(this.#T?.()?.plugins.validateCountThresholds(this.#m.size+e.length),1===e.length){const n=e[0],r=this.#y(n);this.#m.add(n);let i=!1;const s=()=>{if(!i){i=!0,this.#m.delete(n),this.#v.delete(s);try{r()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}const n=this.#w(e),r=[];try{for(const t of n){const e=this.#y(t);r.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(Q,"Cleanup error:",e)}throw e}for(const{factory:t}of r)this.#m.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#v.delete(s);for(const{factory:t}of r)this.#m.delete(t);for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}getAll(){return[...this.#m]}has(t){return this.#m.has(t)}disposeAll(){for(const t of this.#v)t();this.#m.clear(),this.#v.clear()}#w(t){const e=new Set;for(const n of t)e.has(n)?this.#T?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#y(t){const n=this.#f.compileFactory(t);e.validatePlugin(n),this.#T?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const r=[];for(const t of V)t in n&&("function"==typeof n[t]?(r.push(this.#f.addEventListener(W[t],n[t])),"onStart"===t&&this.#f.canNavigate()&&this.#T?.()?.plugins.warnPluginAfterStart(t)):this.#T?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of r)t();"function"==typeof n.teardown&&n.teardown()}}},H=class{#b=new Map;#N=new Map;#A=new Map;#O=new Map;#E=[this.#A,this.#O];#P=new Set;#R=new Set;#C=new Set;#f;#S=g;#T=null;setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#T=t}getHandlerCount(t){return"activate"===t?this.#N.size:this.#b.size}addCanActivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const r=this.#N.has(t);this.#D("activate",t,e,this.#N,this.#O,"canActivate",r)}addCanDeactivate(t,e,n=!1){n?this.#C.add(t):this.#C.delete(t);const r=this.#b.has(t);this.#D("deactivate",t,e,this.#b,this.#A,"canDeactivate",r)}clearCanActivate(t){this.#N.delete(t),this.#O.delete(t),this.#R.delete(t)}clearCanDeactivate(t){this.#b.delete(t),this.#A.delete(t),this.#C.delete(t)}clearAll(){this.#N.clear(),this.#O.clear(),this.#b.clear(),this.#A.clear(),this.#R.clear(),this.#C.clear()}clearDefinitionGuards(){for(const t of this.#R)this.#N.delete(t),this.#O.delete(t);for(const t of this.#C)this.#b.delete(t),this.#A.delete(t);this.#R.clear(),this.#C.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#b)t[e]=n;for(const[t,n]of this.#N)e[t]=n;return[t,e]}getFunctions(){return this.#E}canNavigateTo(t,e,n,r){for(const e of t)if(!this.#F(this.#A,e,n,r,"canNavigateTo"))return!1;for(const t of e)if(!this.#F(this.#O,t,n,r,"canNavigateTo"))return!1;return!0}#D(t,e,n,r,i,s,a){a?this.#T?.()?.lifecycle.warnOverwrite(e,t,s):this.#T?.()?.lifecycle.validateCountThresholds(r.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;r.set(e,o),this.#P.add(e);try{const t=this.#f.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${s}] Factory must return a function, got ${typeof t}`);i.set(e,t)}catch(t){throw r.delete(e),t}finally{this.#P.delete(e)}}#F(t,e,n,r,i){const s=t.get(e);if(!s)return!0;try{const t=s(n,r);return"boolean"==typeof t?t:(this.#T?.()?.lifecycle.warnAsyncGuardSync(e,i),!1)}catch{return!1}}};function J(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Y(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Y(t))),e}function X(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var Z=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,tt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,et=/\?(.+)$/,nt=/[^\w!$'()*+,.:;|~-]/gu,rt=/[^\w!$'()*+,.:;|~-]/u,it={default:t=>rt.test(t)?t.replaceAll(nt,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},st={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function at(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ot(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function ct(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function ut(t){const e=[];for(const n of Object.keys(t)){const r=t[n],i=encodeURIComponent(n);e.push(""===r?i:`${i}=${encodeURIComponent(String(r))}`)}return e.join("&")}function lt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ht(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,r=t.codePointAt(e+2)??0;if(!lt(n)||!lt(r))return!1;e+=3}else e++;return!0}var dt=/<[^>]*>/g;function ft(t,e,n,r,i){const s=""===e.fullName;s||r.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(dt,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=i;s||(f=function(t,e,n,r,i,s){const a=(m=r,ot(n)===ot(m)),o=Object.freeze([...i]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=ot(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,i),h=function(t){const e=new Map;for(const n of t)for(const[t,r]of n.paramMeta.constraintPatterns)e.set(t,r);return e}(i),d=a?ot(r):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const r=new Set,i=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)r.add(e);for(const e of t.paramMeta.spatParams)i.add(e)}if(0===r.size)return{buildStaticParts:[t],buildParamSlots:[]};const s=[],a=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=o.exec(t));){const e=c[1],r="?"===c[2];s.push(t.slice(u,c.index));const o=i.has(e);a.push({paramName:e,isOptional:r,encoder:o?t=>{const e=it[n],r=t.split("/");let i=e(r[0]);for(let t=1;t<r.length;t++)i+=`/${e(r[t])}`;return i}:it[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?i.slice(0,-1):i,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:i.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var m;return t.routesByName.set(e.fullName,g),t.segmentsByName.set(e.fullName,o),t.metaByName.set(e.fullName,c),a?function(t,e,n){var r,i;r=e,(function(t,e,n){const r=ot(n);if("/"===r||""===r)return e;let i=e,s=1;const a=r.length;for(;s<=a;){const e=r.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;i=gt(t,i,r.slice(s,n)),s=n+1}return i}(i=t,i.root,n)).slashChildRoute=r;const s=ot(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,r):function(t,e,n,r,i){if(function(t,e,n){const r=ot(n);"/"!==r?pt(t,t.root,r,1,e):t.root.route=e}(t,e,n),0===i.paramMeta.urlParams.length){const n=t.options.caseSensitive?r:r.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,r,i));for(const n of e.children.values())ft(t,n,l,r,f);s||r.pop()}function pt(t,e,n,r,i){const s=n.length;for(;r<=s;){const a=n.indexOf("/",r),o=-1===a?s:a,c=n.slice(r,o);if(c.endsWith("?")){const r=c.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:r},pt(t,e.paramChild.node,n,o+1,i),void(o>=s?e.route??=i:pt(t,e,n,o+1,i))}e=gt(t,e,c),r=o+1}e.route=i}function gt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:at(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:t},e.paramChild.node}const r=t.options.caseSensitive?n:n.toLowerCase();return r in e.staticChildren||(e.staticChildren[r]=at()),e.staticChildren[r]}var mt=/[\u0080-\uFFFF]/,vt=class{get options(){return this.#t}#t;#e=at();#i=new Map;#s=new Map;#n=new Map;#a=new Map;#r="";#j=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??ct,buildQueryString:t?.buildQueryString??ut}}registerTree(t){this.#j=t.paramMeta.queryParams,ft({root:this.#e,options:this.#t,routesByName:this.#i,segmentsByName:this.#s,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#j},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,r,i]=e,s=this.#t.caseSensitive?r:r.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#L(a,{},i)}const o={},c=this.#I(r,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#_(o,c)||!this.#M(o)?void 0:this.#L(c,o,i)}buildPath(t,e,n){const r=this.#i.get(t);if(!r)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);r.hasConstraints&&e&&this.#U(r,t,e);const i=this.#$(r,e),s=this.#B(i,n?.trailingSlash),a=this.#x(r,e,n?.queryParamsMode);return s+(a?`?${a}`:"")}getSegmentsByName(t){return this.#s.get(t)}getMetaByName(t){return this.#n.get(t)}hasRoute(t){return this.#i.has(t)}setRootPath(t){this.#r=t}#U(t,e,n){for(const[r,i]of t.constraintPatterns){const t=n[r];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!i.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#$(t,e){const n=t.buildStaticParts,r=t.buildParamSlots;if(0===r.length)return this.#r+n[0];let i=this.#r+n[0];for(const[t,s]of r.entries()){const r=e?.[s.paramName];if(null==r){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=n[t+1];continue}const a="object"==typeof r?JSON.stringify(r):String(r);i+=s.encoder(a)+n[t+1]}return i}#B(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#x(t,e,n){if(!e)return"";const r={};let i=!1;for(const n of t.declaredQueryParams)n in e&&(r[n]=e[n],i=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(r[n]=e[n],i=!0);return i?this.#t.buildQueryString(r):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),mt.test(t))return;if(this.#r.length>0){if(!t.startsWith(this.#r))return;t=t.slice(this.#r.length)||"/"}const n=t.indexOf("?"),r=-1===n?t:t.slice(0,n),i=-1===n?void 0:t.slice(n+1);return r.includes("//")?void 0:[r,ot(r),i]}#L(t,e,n){if(void 0!==n){const r=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(r))if(!e.has(t))return}for(const t of Object.keys(r))e[t]=r[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#I(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#k(this.#e,t,1,e)}#k(t,e,n,r){let i=t;const s=e.length;for(;n<=s;){const t=e.indexOf("/",n),a=-1===t?s:t,o=e.slice(n,a),c=this.#t.caseSensitive?o:o.toLowerCase();let u;if(c in i.staticChildren)u=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const t={},s=this.#k(i.splatChild.node,e,n,t);return s?(Object.assign(r,t),s):(r[i.splatChild.name]=e.slice(n),i.splatChild.node.route)}return}u=i.paramChild.node,r[i.paramChild.name]=o}i=u,n=a+1}return i.slashChildRoute??i.route}#M(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=st[e];for(const e in t){const r=t[e];if(r.includes("%")){if(!ht(r))return!1;t[e]=n(r)}}return!0}#_(t,e){for(const[n,r]of e.constraintPatterns)if(!r.pattern.test(t[n]))return!1;return!0}},St=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const r=-1===n?t:t.split("+").join(" ");return-1===e?r:decodeURIComponent(r)},Tt=t=>{const e=typeof t;if("string"!==e&&"number"!==e&&"boolean"!==e)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===e&&null===t?"null":e}`);return encodeURIComponent(t)},yt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${Tt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${Tt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${Tt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>Tt(t)).join(",")}`}},wt={none:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:t=>t},string:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:t=>"true"===t||"false"!==t&&null,decodeValue:t=>t},"empty-true":{encode:(t,e)=>e?t:`${t}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:t=>t}},bt={default:{encode:t=>t},hidden:{encode:()=>""}},Nt=(t,e,n)=>({boolean:wt[e],null:bt[n],array:yt[t]}),At={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:wt.none,null:bt.default,array:yt.none}},Ot=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return At;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",r=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:r,strategies:Nt(e,n,r)}},Et=t=>encodeURIComponent(t),Pt=(t,e,n)=>{const r=Et(t);switch(typeof e){case"string":case"number":default:return`${r}=${Et(e)}`;case"boolean":return n.strategies.boolean.encode(r,e);case"object":return null===e?n.strategies.null.encode(r):Array.isArray(e)?n.strategies.array.encodeArray(r,e):`${r}=${Et(e)}`}};function Rt(t,e,n,r,i){const s=t.indexOf("=",e),a=-1!==s&&s<n,o=t.slice(e,a?s:n),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(o);var l,h,d,f,p;!function(t,e,n,r){const i=t[e];void 0===i?t[e]=r?[n]:n:Array.isArray(i)?i.push(n):t[e]=[i,n]}(r,St(c),(l=t,h=s,d=n,f=a,p=i,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const r=St(t);return e.boolean.decodeValue(r)})(f?l.slice(h+1,d):void 0,p):f?St(l.slice(h+1,d)):null),u)}function Ct(t,e){const n=t.path,r=n.startsWith("~"),i=r?n.slice(1):n,s={name:t.name,path:i,absolute:r,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ct(e,s);s.children.push(t)}return s}function Dt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Ft(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function jt(t,e,n){const r=function(t){const e=[],n=[],r=[],i={},s=new Map,a=t.replaceAll(tt,"$1"),o=et.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),i[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=Z.exec(t));){const t=c[2],n=c[3];if("*"===c[1])r.push(t),e.push(t),i[t]="url";else if(e.push(t),i[t]="url",n){const e=`^${X(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:s,pathPattern:t}}(t.path),i=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(r),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var a;s.fullName=(a=s,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(t,e,n){const r=[],i=[];for(const s of t){const t=jt(s,e,n);r.push(t),t.absolute||i.push(t)}return{childrenMap:Ft(r),nonAbsoluteChildren:i}}(t.children,s,n);return s.children=o,s.nonAbsoluteChildren=c,s.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;const i=[];let s=t.parent;for(;s?.path;)i.unshift(s),s=s.parent;let a="";for(const t of i){const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;a=t.absolute?t.path:Dt(a,t.path)}return t.absolute?t.path:Dt(a,t.path)}(s),n&&(Object.freeze(c),Object.freeze(i),Object.freeze(s.children),Object.freeze(s)),s}function Lt(t,e,n,r){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:r=>function(t,e=!0){return jt(t,null,e)}(function(t,e,n){const r=Ct({name:t,path:e},null);for(const t of n){const e=Ct(t,r);r.children.push(e)}return r}(t,e,n),!r?.skipFreeze)}}(t,e).addMany(n).build(r)}function It(t){const e={name:t.name,path:t.absolute?`~${t.path}`:t.path};return t.children.size>0&&(e.children=[...t.children.values()].map(t=>It(t))),e}function _t(t){const e=t?.queryParams;return new vt({...void 0===t?.caseSensitive?void 0:{caseSensitive:t.caseSensitive},...void 0===t?.strictTrailingSlash?void 0:{strictTrailingSlash:t.strictTrailingSlash},...void 0===t?.strictQueryParams?void 0:{strictQueryParams:t.strictQueryParams},...void 0===t?.urlParamsEncoding?void 0:{urlParamsEncoding:t.urlParamsEncoding},parseQueryString:t=>((t,e)=>{const n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const r=t.length;for(;n<r;){let i=t.indexOf("&",n);-1===i&&(i=r),Rt(t,n,i,e),n=i+1}}(t,e),e}(n);const r=Ot(e),i={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Rt(n,s,t,i,r.strategies),s=t+1}return i})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const r=Ot(e),i=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Pt(e,n,r);s&&i.push(s)}return i.join("&")})(t,e)})}function Mt(t,e,n=100){const r=new Set,i=[t];let s=t;for(;e[s];){const t=e[s];if(r.has(t)){const e=i.indexOf(t),n=[...i.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(r.add(s),i.push(t),s=t,i.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${i.join(" → ")}`)}return s}function Ut(t,e,n){const r=Lt("",e,t),i=_t(n);return i.registerTree(r),{tree:r,matcher:i}}function $t(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=kt(t.config)}function Bt(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function xt(t){!function(t){t.definitions.length=0,Object.assign(t.config,J()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),Bt(t)}function kt(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=Mt(n,t.forwardMap);return e}function zt(e,n,r,i,s,a,o){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(e).filter(([t])=>!c.has(t)));Object.keys(u).length>0&&(i[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,r){if(e.canActivate&&t.logger.warn("real-router",`Route "${n}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),e.canDeactivate&&t.logger.warn("real-router",`Route "${n}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),"function"==typeof e.forwardTo){const t="AsyncFunction"===e.forwardTo.constructor.name,r=e.forwardTo.toString().includes("__awaiter");if(t||r)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?r.forwardMap[n]=e.forwardTo:r.forwardFnMap[n]=e.forwardTo}(e,n,r),e.decodeParams&&(r.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(r.defaultParams[n]=e.defaultParams)}function qt(t,e,n,r,i,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;zt(o,t,e,n,r,i),o.children&&qt(o.children,e,n,r,i,s,t)}}function Gt(t,e){const n=[],r=J(),i=Object.create(null),s=new Map,a=new Map;for(const e of t)n.push(Y(e));const{tree:o,matcher:c}=Ut(n,"",e);return qt(t,r,i,s,a,void 0,""),{definitions:n,config:r,tree:o,matcher:c,resolvedForwardMap:kt(r),routeCustomFields:i,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:s,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:$t,resetStore:xt,nodeToDefinition:It}}}var Wt=".",Vt=[];function Qt(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Kt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Ht(t,e,n){const r=e.meta?.params[t];if(!r||"object"!=typeof r)return!0;for(const t of Object.keys(r)){const r=e.params[t],i=n.params[t];if(Kt(r)&&Kt(i)&&String(r)!==String(i))return!1}return!0}Object.freeze(Vt);var Jt,Yt,Xt=new Map;function Zt(t){const e=Xt.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(Wt);if(-1===e)return[t];const n=t.indexOf(Wt,e+1);if(-1===n)return[t.slice(0,e),t];const r=t.indexOf(Wt,n+1);if(-1===r)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Wt,r+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,r),t]:function(t){const e=t.split(Wt),n=e.length,r=[e[0]];let i=e[0].length;for(let s=1;s<n-1;s++)i+=1+e[s].length,r.push(t.slice(0,i));return r.push(t),r}(t)}(t);return Object.freeze(n),Xt.set(t,n),n}var te,ee,ne=null,re=null;function ie(t,e){if(!e)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Vt};if(void 0===t.meta?.params&&void 0===e.meta?.params)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Qt(Zt(e.name))};const n=Zt(t.name),r=Zt(e.name),i=function(t,e,n,r,i){for(let s=0;s<i;s++){const i=n[s];if(i!==r[s])return s;if(!Ht(i,t,e))return s}return i}(t,e,n,r,Math.min(r.length,n.length));let s;if(i>=r.length)s=Vt;else if(0===i&&1===r.length)s=r;else{s=[];for(let t=r.length-1;t>=i;t--)s.push(r[t])}const a=0===i?n:n.slice(i);return{intersection:i>0?r[i-1]:"",toDeactivate:s,toActivate:a}}function se(t,e,n){if(n)return ie(t,e);if(null!==ne&&t===Jt&&e===Yt)return ne;if(null!==re&&t===te&&e===ee)return re;const r=ie(t,e);return te=Jt,ee=Yt,re=ne,Jt=t,Yt=e,ne=r,r}function ae(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var oe=class{#z;#q;get#f(){return this.#z.depsStore}constructor(t=[],e){this.#z=Gt(t,e)}static shouldUpdateNode(t){return(e,n)=>{if(!e||"object"!=typeof e||!("name"in e))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(e.transition?.reload)return!0;if(""===t&&!n)return!0;const{intersection:r,toActivate:i,toDeactivate:s}=se(e,n);return t===r||!!i.includes(t)||s.includes(t)}}setDependencies(t){this.#z.depsStore=t;for(const[e,n]of this.#z.pendingCanActivate)t.addActivateGuard(e,n);this.#z.pendingCanActivate.clear();for(const[e,n]of this.#z.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#z.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#z.lifecycleNamespace=t}setRootPath(t){this.#z.rootPath=t,Bt(this.#z)}hasRoute(t){return this.#z.matcher.hasRoute(t)}clearRoutes(){xt(this.#z)}buildPath(t,e,n){if(t===o.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const r=Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e??{},i="function"==typeof this.#z.config.encoders[t]?this.#z.config.encoders[t]({...r}):r;return this.#z.matcher.buildPath(t,i,this.#G(n))}matchPath(t,e){const n=e,r=this.#z.matcher.match(t);if(!r)return;const i=ae(r),{name:s,params:a,meta:o}=i,c="function"==typeof this.#z.config.decoders[s]?this.#z.config.decoders[s](a):a,{name:u,params:l}=this.#f.forwardState(s,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#z.config.encoders[u]?this.#z.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#z.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#f.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#z.config.forwardFnMap,t)){const n=this.#W(t,e),r=this.#z.config.forwardFnMap[t],i=this.#V(t,r,e);return{name:i,params:this.#W(i,n)}}const n=this.#z.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#z.config.forwardFnMap,n)){const r=this.#W(t,e),i=this.#z.config.forwardFnMap[n],s=this.#V(n,i,e);return{name:s,params:this.#W(s,r)}}if(n!==t){const r=this.#W(t,e);return{name:n,params:this.#W(n,r)}}return{name:t,params:this.#W(t,e)}}buildStateResolved(t,e){const n=this.#z.matcher.getSegmentsByName(t);if(n)return ae({segments:n,params:e,meta:this.#z.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,r=!0){const i=this.#f.getState();if(!i)return!1;const s=i.name;if(s!==t&&!s.startsWith(`${t}.`)&&!t.startsWith(`${s}.`))return!1;const a=this.#z.config.defaultParams[t];if(n||s===t){const n=a?{...a,...e}:e;return this.#f.areStatesEqual({name:t,params:n,path:""},i,r)}const o=i.params;return!!function(t,e){for(const n in t)if(t[n]!==e[n])return!1;return!0}(e,o)&&(!a||function(t,e,n){for(const r in t)if(!(r in n)&&t[r]!==e[r])return!1;return!0}(a,o,e))}getMetaForState(t){return this.#z.matcher.hasRoute(t)?this.#z.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#z.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#z}#W(t,e){return Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e}#G(t){if(this.#q)return this.#q;const e=t?.trailingSlash;return this.#q=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#q}#V(t,e,n){const r=new Set([t]);let i=e(this.#f.getDependency,n),s=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;s<100;){if(void 0===this.#z.matcher.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(r.has(i)){const t=[...r,i].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(r.add(i),Object.hasOwn(this.#z.config.forwardFnMap,i)){i=(0,this.#z.config.forwardFnMap[i])(this.#f.getDependency,n),s++;continue}const t=this.#z.config.forwardMap[i];if(void 0===t)return i;i=t,s++}throw new Error("forwardTo exceeds maximum depth of 100")}},ce=new Set(Object.values(s)),ue=new Set(["code","segment","path","redirect"]),le=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),he=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:n,path:r,redirect:i,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=r,this.redirect=i?function(t){if(!t)return t;if(null===(e=t)||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path||"object"!=typeof e.params||null===e.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof t);var e;const n=structuredClone(t),r=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(r.has(e))return;r.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(i):void 0;for(const[t,e]of Object.entries(s)){if(ue.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);le.has(t)||(this[t]=e)}}setCode(t){this.code=t,ce.has(this.message)&&(this.message=t)}setErrorInstance(t){if(!t)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=t.message,this.cause=t.cause,this.stack=t.stack??""}setAdditionalFields(t){for(const[e,n]of Object.entries(t)){if(ue.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);le.has(e)||(this[e]=n)}}hasField(t){return t in this}getField(t){return this[t]}toJSON(){const t={code:this.code,message:this.message};void 0!==this.segment&&(t.segment=this.segment),void 0!==this.path&&(t.path=this.path),void 0!==this.redirect&&(t.redirect=this.redirect);const e=new Set(["code","message","segment","path","redirect","stack"]);for(const n in this)Object.hasOwn(this,n)&&!e.has(n)&&(t[n]=this[n]);return t}},de=new he(s.ROUTER_NOT_STARTED),fe=new he(s.ROUTE_NOT_FOUND),pe=new he(s.SAME_STATES),ge=Promise.reject(de),me=Promise.reject(fe),ve=Promise.reject(pe);function Se(t,e){const{toState:n,fromState:r,opts:i,toDeactivate:a,toActivate:c,intersection:u}=e;if(n.name!==o.UNKNOWN_ROUTE&&!t.hasRoute(n.name)){const e=new he(s.ROUTE_NOT_FOUND,{routeName:n.name});throw t.sendTransitionFail(n,r,e),e}if(r)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,r,i){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:r,intersection:i}};return void 0!==t?.name&&(s.from=t.name),void 0!==e.reload&&(s.reload=e.reload),void 0!==e.redirected&&(s.redirected=e.redirected),s}(r,i,a,c,u);const l=I(n);t.setState(l);const h=void 0===i.signal?i:function({signal:t,...e}){return e}(i);return t.sendTransitionDone(l,r,h),l}function Te(t,e,n,r){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,r,e)}function ye(t,e,n){if(t instanceof DOMException&&"AbortError"===t.name)throw new he(s.TRANSITION_CANCELLED);!function(t,e,n){if(t instanceof he)throw t.setCode(e),t;throw new he(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,message:t.message,stack:t.stack,..."cause"in t&&void 0!==t.cause&&{cause:t.cause}};if(t&&"object"==typeof t){const e={};for(const[n,r]of Object.entries(t))we.has(n)||(e[n]=r);return{...n,...e}}return n}(t,n))}(t,e,n)}ge.catch(()=>{}),me.catch(()=>{}),ve.catch(()=>{});var we=new Set(["code","segment","path","redirect"]);async function be(t,e,n){let r;try{r=await t}catch(t){return void ye(t,e,n)}if(!r)throw new he(e,{segment:n})}async function Ne(t,e,n,r,i,a,o,c,u,l){await be(u,n,l);for(let u=c;u<e.length;u++){if(!o())throw new he(s.TRANSITION_CANCELLED);const c=e[u],l=t.get(c);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){ye(t,n,c)}if(h instanceof Promise)await be(h,n,c);else if(!h)throw new he(n,{segment:c})}}function Ae(t,e,n,r,i,a,o){for(const[c,u]of e.entries()){if(!o())throw new he(s.TRANSITION_CANCELLED);const l=t.get(u);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){ye(t,n,u)}if(h instanceof Promise)return Ne(t,e,n,r,i,a,o,c+1,h,u);if(!h)throw new he(n,{segment:u})}}var Oe=[o.UNKNOWN_ROUTE];Object.freeze(Oe);var Ee={replace:!0};Object.freeze(Ee);var Pe=class{lastSyncResolved=!1;lastSyncRejected=!1;#f;#Q=null;#K=0;setDependencies(t){this.#f=t}navigate(t,e,n){this.lastSyncResolved=!1;const r=this.#f;if(!r.canNavigate())return this.lastSyncRejected=!0,ge;let i,a,c=!1,u=null;try{if(i=r.buildNavigateState(t,e),!i)return r.emitTransitionError(void 0,r.getState(),fe),this.lastSyncRejected=!0,me;if(a=r.getState(),n=function(t,e){return e?.name!==o.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(n,a),function(t,e,n,r){return!!t&&!e.reload&&!e.force&&r(t,n,!1)}(a,n,i,r.areStatesEqual))return r.emitTransitionError(i,a,pe),this.lastSyncRejected=!0,ve;if(this.#H(),n.signal?.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:n.signal.reason});const l=++this.#K;if(r.startTransition(i,a),c=!0,this.#K!==l)throw new he(s.TRANSITION_CANCELLED);const[h,d]=r.getLifecycleFunctions(),f=i.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=se(i,a,n.reload),v=a&&!n.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(h.size>0||d.size>0){u=new AbortController,this.#Q=u;const t=()=>this.#K===l&&r.isActive(),e=function(t,e,n,r,i,a,o,c,u,l){if(i){const i=Ae(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==i)return async function(t,e,n,r,i,a,o,c){if(await t,!c())throw new he(s.TRANSITION_CANCELLED);if(r){const t=Ae(e,n,s.CANNOT_ACTIVATE,i,a,o,c);if(void 0!==t&&await t,!c())throw new he(s.TRANSITION_CANCELLED)}}(i,e,r,a,o,c,u,l)}if(!l())throw new he(s.TRANSITION_CANCELLED);if(a)return Ae(e,r,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,i,a,u.signal,t);if(void 0!==e)return this.#J(e,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h},u,l);if(!t())throw new he(s.TRANSITION_CANCELLED);this.#Y(u)}return this.lastSyncResolved=!0,Promise.resolve(Se(r,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#X(t,u,c,i,a),Promise.reject(t)}}navigateToDefault(t){const e=this.#f;if(!e.getOptions().defaultRoute)return Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:n,params:r}=e.resolveDefault();return n?this.navigate(n,r,t):Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#H();const e=this.#f.getState(),n=e?Zt(e.name).toReversed():[];Object.freeze(n);const r={deactivated:n,activated:Oe,intersection:""};Object.freeze(r);const i={phase:"activating",...e&&{from:e.name},reason:"success",segments:r};Object.freeze(i);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:i};return Object.freeze(s),this.#f.setState(s),this.#f.emitTransitionSuccess(s,e,Ee),s}abortCurrentNavigation(){this.#Q?.abort(new he(s.TRANSITION_CANCELLED)),this.#Q=null}async#J(t,e,n,r){const i=this.#f,a=()=>this.#K===r&&!n.signal.aborted&&i.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{n.abort(e.opts.signal?.reason)},{once:!0,signal:n.signal})}if(await t,!a())throw new he(s.TRANSITION_CANCELLED);return Se(i,e)}catch(t){throw Te(i,t,e.toState,e.fromState),t}finally{this.#Y(n)}}#X(t,e,n,r,i){e&&this.#Y(e),n&&r&&Te(this.#f,t,r,i)}#Y(t){t.abort(),this.#Q===t&&(this.#Q=null)}#H(){this.#f.isTransitioning()&&(t.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#Q?.abort(new he(s.TRANSITION_CANCELLED)),this.#f.cancelNavigation())}},Re={replace:!0};Object.freeze(Re);var Ce=class{#f;setDependencies(t){this.#f=t}async start(t){const e=this.#f,n=e.getOptions(),r=e.matchPath(t);if(!r&&!n.allowNotFound){const n=new he(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),r?e.navigate(r.name,r.params,Re):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},De=class{#Z;#tt;#et;#nt;#rt;#it;constructor(t){this.#Z=t.routerFSM,this.#tt=t.emitter,this.#et=void 0,this.#st()}static validateSubscribeListener(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#tt.emit(p.ROUTER_START)}emitRouterStop(){this.#tt.emit(p.ROUTER_STOP)}emitTransitionStart(t,e){this.#tt.emit(p.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,n){this.#tt.emit(p.TRANSITION_SUCCESS,t,e,n)}emitTransitionError(t,e,n){this.#tt.emit(p.TRANSITION_ERROR,t,e,n)}emitTransitionCancel(t,e){this.#tt.emit(p.TRANSITION_CANCEL,t,e)}sendStart(){this.#Z.send(b)}sendStop(){this.#Z.send(R)}sendDispose(){this.#Z.send(C)}sendStarted(){this.#Z.send(N)}sendNavigate(t,e){this.#et=t,this.#Z.forceState(y),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#Z.forceState(T),this.emitTransitionSuccess(t,e,n),this.#et===t&&(this.#et=void 0)}sendFail(t,e,n){const r=this.#et;this.#nt=t,this.#rt=e,this.#it=n,this.#Z.send(E),this.#et===r&&(this.#et=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#et;this.#nt=t,this.#rt=e,this.#Z.send(P),this.#et===n&&(this.#et=void 0)}canBeginTransition(){return this.#Z.canSend(A)}canStart(){return this.#Z.canSend(b)}canCancel(){return this.#Z.canSend(P)}isActive(){const t=this.#Z.getState();return t!==v&&t!==w}isDisposed(){return this.#Z.getState()===w}isTransitioning(){return this.#Z.getState()===y}isReady(){return this.#Z.getState()===T}getCurrentToState(){return this.#et}addEventListener(t,e){return this.#tt.on(t,e)}subscribe(t){return this.#tt.on(p.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#tt.clearAll()}setLimits(t){this.#tt.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#et,t)}#at(){this.emitTransitionError(this.#nt,this.#rt,this.#it)}#st(){const t=this.#Z;t.on(S,N,()=>{this.emitRouterStart()}),t.on(T,R,()=>{this.emitRouterStop()}),t.on(y,P,()=>{const t=this.#nt;void 0!==t&&this.emitTransitionCancel(t,this.#rt)}),t.on(S,E,()=>{this.#at()}),t.on(T,E,()=>{this.#at()}),t.on(y,E,()=>{this.#at()})}},Fe=new he(s.ROUTER_ALREADY_STARTED),je=new Set(["all","warn-error","error-only"]);var Le=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(t){this.router=t.router,this.options=t.options,this.limits=t.limits,this.dependenciesStore=t.dependenciesStore,this.state=t.state,this.routes=t.routes,this.routeLifecycle=t.routeLifecycle,this.plugins=t.plugins,this.navigation=t.navigation,this.lifecycle=t.lifecycle,this.eventBus=t.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const t={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(t),this.routeLifecycle.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,r)=>this.state.makeState(t,e,n,r),getState:()=>this.state.get(),areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const n=M(this.router);return n.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),n.forwardState(t,e)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const t={addEventListener:(t,e)=>this.eventBus.addEventListener(t,e),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(t),this.plugins.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:t=>this.routes.hasRoute(t),getState:()=>this.state.get(),setState:t=>{this.state.set(t)},buildNavigateState:(t,e)=>{const n=M(this.router);n.validator?.routes.validateStateBuilderArgs(t,e,"navigate");const{name:r,params:i}=n.forwardState(t,e),s=this.routes.getMetaForState(r);if(void 0===s)return;const a=n.buildPath(r,i);return this.state.makeState(r,i,a,s,void 0,!0)},areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),resolveDefault:()=>{const t=this.options.get();return{route:k(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:k(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,n)=>{this.eventBus.sendComplete(t,e,n)},sendTransitionFail:(t,e,n)=>{this.eventBus.sendFail(t,e,n)},emitTransitionError:(t,e,n)=>{this.eventBus.sendFailSafe(t,e,n)},emitTransitionSuccess:(t,e,n)=>{this.eventBus.emitTransitionSuccess(t,e,n)},canNavigate:()=>this.eventBus.canBeginTransition(),getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:t=>{this.routeLifecycle.clearCanDeactivate(t)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(t,e,n)=>this.navigation.navigate(t,e,n),navigateToNotFound:t=>this.navigation.navigateToNotFound(t),clearState:()=>{this.state.set(void 0)},matchPath:t=>this.routes.matchPath(t,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(t,e,n)=>{this.eventBus.sendFail(t,e,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>M(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return n=>n(t,t=>e.dependencies[t])}},Ie=Object.freeze({}),_e=class n{#u;#S;#ot;#ct;#ut;#lt;#m;#ht;#dt;#ft;constructor(n=[],r={},s={}){r.logger&&function(t){if("object"!=typeof t||null===t)throw new TypeError("Logger config must be an object");const e=t;for(const t of Object.keys(e))if("level"!==t&&"callback"!==t)throw new TypeError(`Unknown logger config property: "${t}"`);if("level"in e&&void 0!==e.level&&("string"!=typeof(n=e.level)||!je.has(n)))throw new TypeError(`Invalid logger level: ${function(t){return"string"==typeof t?`"${t}"`:"object"==typeof t?JSON.stringify(t):String(t)}(e.level)}. Expected: "all" | "warn-error" | "error-only"`);var n;if("callback"in e&&void 0!==e.callback&&"function"!=typeof e.callback)throw new TypeError("Logger callback must be a function, got "+typeof e.callback);return!0}(r.logger)&&(t.logger.configure(r.logger),delete r.logger),z.validateOptionsIsObject(r),function(t){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`dependencies cannot contain getters: "${e}"`)}(s),n.length>0&&F(n),this.#u=new z(r),this.#S=function(t={}){return{...g,...t}}(r.limits),this.#ot=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:g}}(s),this.#ct=new G,this.#ut=new oe(n,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#lt=new H,this.#m=new K,this.#ht=new Pe,this.#dt=new Ce;const a=new e.FSM(D),o=new i({onListenerError:(e,n)=>{t.logger.error("Router",`Error in listener for ${e}:`,n)},onListenerWarn:(e,n)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${n} listeners — possible memory leak`)}});var c;this.#ft=new De({routerFSM:a,emitter:o}),(c=new Le({router:this,options:this.#u,limits:this.#S,dependenciesStore:this.#ot,state:this.#ct,routes:this.#ut,routeLifecycle:this.#lt,plugins:this.#m,navigation:this.#ht,lifecycle:this.#dt,eventBus:this.#ft})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const u=new Map;var l,h,d;l={makeState:(t,e,n,r,i)=>this.#ct.makeState(t,e,n,r,i),forwardState:$("forwardState",(t,e)=>this.#ut.forwardState(t,e),u),buildStateResolved:(t,e)=>this.#ut.buildStateResolved(t,e),matchPath:(t,e)=>this.#ut.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#ft.addEventListener(t,e),buildPath:$("buildPath",(t,e)=>this.#ut.buildPath(t,e??m,this.#u.get()),u),start:(h=t=>this.#dt.start(t),d=u,(...t)=>{const e=d.get("start");return e&&0!==e.length?U(e,h,t):h(...t)}),interceptors:u,setRootPath:t=>{this.#ut.setRootPath(t)},getRootPath:()=>this.#ut.getStore().rootPath,getTree:()=>this.#ut.getStore().tree,isDisposed:()=>this.#ft.isDisposed(),validator:null,dependenciesGetStore:()=>this.#ot,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#ot.dependencies}),getLifecycleFactories:()=>this.#lt.getFactories(),getPluginFactories:()=>this.#m.getAll(),routeGetStore:()=>this.#ut.getStore(),getStateName:()=>this.#ct.get()?.name,isTransitioning:()=>this.#ft.isTransitioning(),clearState:()=>{this.#ct.set(void 0)},setState:t=>{this.#ct.set(t)},routerExtensions:[]},_.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,n,r,i){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,r,i),M(this).validator?.routes.validateRouteName(e,"isActiveRoute"),""===e?(t.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ut.isActiveRoute(e,n,r,i)}buildPath(t,e){const n=M(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ct.get()}getPreviousState(){return this.#ct.getPrevious()}areStatesEqual(t,e,n=!0){return M(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ct.areStatesEqual(t,e,n)}shouldUpdateNode(t){return M(this).validator?.routes.validateShouldUpdateNodeArgs(t),oe.shouldUpdateNode(t)}isActive(){return this.#ft.isActive()}start(t){if(!this.#ft.canStart())return Promise.reject(Fe);M(this).validator?.navigation.validateStartArgs(t),this.#ft.sendStart();const e=M(this).start(t).catch(t=>{throw this.#ft.isReady()&&(this.#dt.stop(),this.#ft.sendStop()),t});return n.#pt(e),e}stop(){return this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),this.#ft.isReady()||this.#ft.isTransitioning()?(this.#dt.stop(),this.#ft.sendStop(),this):this}dispose(){if(this.#ft.isDisposed())return;this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),(this.#ft.isReady()||this.#ft.isTransitioning())&&(this.#dt.stop(),this.#ft.sendStop()),this.#ft.sendDispose(),this.#ft.clearAll(),this.#m.disposeAll();const t=M(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ut.clearRoutes(),this.#lt.clearAll(),this.#ct.reset(),this.#ot.dependencies=Object.create(null),this.#gt()}canNavigateTo(t,e){const n=M(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ut.hasRoute(t))return!1;const{name:r,params:i}=n.forwardState(t,e??{}),s=this.#ct.makeState(r,i),a=this.#ct.get(),{toDeactivate:o,toActivate:c}=se(s,a);return this.#lt.canNavigateTo(o,c,s,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=M(this);n.validator?.plugins.validatePluginLimit(this.#m.count(),this.#S);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#m.getAll());return this.#m.use(...e)}subscribe(t){return De.validateSubscribeListener(t),this.#ft.subscribe(t)}navigate(t,e,r){const i=M(this);i.validator?.navigation.validateNavigateArgs(t),i.validator?.navigation.validateParams(e,"navigate");const s=r??Ie;i.validator?.navigation.validateNavigationOptions(s,"navigate");const a=this.#ht.navigate(t,e??m,s);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(a),a}navigateToDefault(t){const e=M(this);e.validator?.navigation.validateNavigateToDefaultArgs(t);const r=t??Ie;e.validator?.navigation.validateNavigationOptions(r,"navigateToDefault");const i=this.#ht.navigateToDefault(r);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(i),i}navigateToNotFound(t){if(!this.#ft.isActive())throw new he(s.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ct.get().path;return this.#ht.navigateToNotFound(e)}static#mt=e=>{e instanceof he&&(e.code===s.SAME_STATES||e.code===s.TRANSITION_CANCELLED||e.code===s.ROUTER_NOT_STARTED||e.code===s.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#pt(t){t.catch(n.#mt)}#gt(){this.navigate=Me,this.navigateToDefault=Me,this.navigateToNotFound=Me,this.start=Me,this.stop=Me,this.usePlugin=Me,this.subscribe=Me,this.canNavigateTo=Me}};function Me(){throw new he(s.ROUTER_DISPOSED)}var Ue=new WeakMap;exports.Router=_e,exports.RouterError=he,exports.UNKNOWN_ROUTE=a,exports.constants=o,exports.createRouter=(t=[],e={},n={})=>new _e(t,e,n),exports.errorCodes=s,exports.events=p,exports.getNavigator=t=>{let e=Ue.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),Ue.set(t,e)),e},exports.resolveForwardChain=Mt;//# sourceMappingURL=index.js.map