@real-router/core 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -419,7 +419,7 @@ See the [Migration Guide](https://github.com/greydragon888/real-router/wiki/migr
419
419
  - [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) — Browser history
420
420
  - [@real-router/logger-plugin](https://www.npmjs.com/package/@real-router/logger-plugin) — Debug logging
421
421
  - [@real-router/persistent-params-plugin](https://www.npmjs.com/package/@real-router/persistent-params-plugin) — Persistent params
422
- - [@real-router/helpers](https://www.npmjs.com/package/@real-router/helpers) — Utilities
422
+ - [@real-router/route-utils](https://www.npmjs.com/package/@real-router/route-utils) — Route tree queries and segment testing utilities
423
423
 
424
424
  ## License
425
425
 
@@ -1,5 +1,5 @@
1
- import { Params, RouteTreeState, DefaultDependencies, Router as Router$1, Route, Options, State, PluginFactory, Unsubscribe, SubscribeFn, NavigationOptions, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, Navigator, PluginApi, RoutesApi, DependenciesApi, LifecycleApi } from '@real-router/types';
2
- export { Config, DefaultDependencies, DependenciesApi, GuardFn, GuardFnFactory, LifecycleApi, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginApi, PluginFactory, Route, RouteConfigUpdate, RoutesApi, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
1
+ import { Params, RouteTreeState, DefaultDependencies, Router as Router$1, Route, Options, State, PluginFactory, Unsubscribe, SubscribeFn, NavigationOptions, ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, Navigator, PluginApi as PluginApi$1, RoutesApi, DependenciesApi, LifecycleApi } from '@real-router/types';
2
+ export { Config, DefaultDependencies, DependenciesApi, GuardFn, GuardFnFactory, LifecycleApi, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, RoutesApi, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
3
3
 
4
4
  /**
5
5
  * Core-internal types + re-exports from @real-router/types.
@@ -290,6 +290,129 @@ declare const createRouter: <Dependencies extends DefaultDependencies = DefaultD
290
290
 
291
291
  declare const getNavigator: <Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>) => Navigator;
292
292
 
293
+ /**
294
+ * Path Matcher Type Definitions.
295
+ *
296
+ * Core types for path matching and parameter extraction.
297
+ *
298
+ * @module path-matcher/types
299
+ */
300
+ /**
301
+ * Constraint pattern for a URL parameter.
302
+ */
303
+ interface ConstraintPattern {
304
+ /**
305
+ * Compiled RegExp for validating the parameter value.
306
+ *
307
+ * @example /^(\d+)$/ for constraint "<\\d+>"
308
+ */
309
+ readonly pattern: RegExp;
310
+ /**
311
+ * Raw constraint string from the route pattern.
312
+ *
313
+ * @example "<\\d+>"
314
+ */
315
+ readonly constraint: string;
316
+ }
317
+ /**
318
+ * Parameter metadata extracted from a route path pattern.
319
+ */
320
+ interface ParamMeta {
321
+ /**
322
+ * URL parameter names extracted from the path pattern.
323
+ *
324
+ * @example [":id", ":postId"] from "/users/:id/posts/:postId"
325
+ */
326
+ readonly urlParams: readonly string[];
327
+ /**
328
+ * Query parameter names extracted from the path pattern.
329
+ *
330
+ * @example ["q", "page"] from "/search?q&page"
331
+ */
332
+ readonly queryParams: readonly string[];
333
+ /**
334
+ * Splat parameter names extracted from the path pattern.
335
+ *
336
+ * @example ["path"] from "/files/*path"
337
+ */
338
+ readonly spatParams: readonly string[];
339
+ /**
340
+ * Map of parameter names to their type (url or query).
341
+ *
342
+ * @example { id: "url", q: "query" }
343
+ */
344
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
345
+ /**
346
+ * Map of parameter names to their constraint patterns.
347
+ *
348
+ * Only includes parameters with explicit constraints (e.g., `:id<\\d+>`).
349
+ * Parameters without constraints are not included in this map.
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * buildParamMeta("/users/:id<\\d+>").constraintPatterns.get("id")
354
+ * // → { pattern: /^(\d+)$/, constraint: "<\\d+>" }
355
+ *
356
+ * buildParamMeta("/users/:id").constraintPatterns.size
357
+ * // → 0 (no constraints)
358
+ * ```
359
+ */
360
+ readonly constraintPatterns: ReadonlyMap<string, ConstraintPattern>;
361
+ /**
362
+ * Path pattern without query string, pre-computed for buildPath.
363
+ *
364
+ * @example "/users/:id" from "/users/:id?q&page"
365
+ */
366
+ readonly pathPattern: string;
367
+ }
368
+
369
+ /**
370
+ * Immutable route tree node.
371
+ *
372
+ * This is the core data structure of the new route-tree architecture.
373
+ * It contains only data (no methods) and is created by the builder.
374
+ *
375
+ * All caches are pre-computed at build time:
376
+ * - nonAbsoluteChildren: filtered children without absolute paths
377
+ * - absoluteDescendants: all descendants with absolute paths (recursive)
378
+ * - parentSegments: array from root to parent
379
+ * - fullName: pre-computed "users.profile" instead of runtime join
380
+ */
381
+ interface RouteTree {
382
+ /** Route segment name (e.g., "users" in "users.profile") */
383
+ readonly name: string;
384
+ /** Route path pattern (e.g., "/users/:id") */
385
+ readonly path: string;
386
+ /** Whether this route uses absolute path matching (path starts with "~") */
387
+ readonly absolute: boolean;
388
+ /** Child route nodes (Map for O(1) lookup by name) */
389
+ readonly children: ReadonlyMap<string, RouteTree>;
390
+ /** Parameter metadata extracted from path pattern (replaces parser dependency) */
391
+ readonly paramMeta: ParamMeta;
392
+ /** Parent node (null for root) */
393
+ readonly parent: RouteTree | null;
394
+ /** Children without absolute paths (for regular matching) */
395
+ readonly nonAbsoluteChildren: readonly RouteTree[];
396
+ /** Pre-computed full name (e.g., "users.profile") */
397
+ readonly fullName: string;
398
+ /**
399
+ * Pre-computed static path for routes without parameters.
400
+ * Used by buildPath fast path to avoid inject() overhead.
401
+ * Only set when route has no URL params, query params, or splat params.
402
+ */
403
+ readonly staticPath: string | null;
404
+ /**
405
+ * Pre-computed parameter type map for this segment.
406
+ * Cached to avoid recomputing on every navigation.
407
+ * Maps param name → "url" | "query".
408
+ */
409
+ readonly paramTypeMap: Readonly<Record<string, "url" | "query">>;
410
+ }
411
+
412
+ interface PluginApi extends Omit<PluginApi$1, "getTree"> {
413
+ getTree: () => RouteTree;
414
+ }
415
+
293
416
  declare function getPluginApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): PluginApi;
294
417
 
295
418
  declare function getRoutesApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>): RoutesApi<Dependencies>;
@@ -300,4 +423,4 @@ declare function getLifecycleApi<Dependencies extends DefaultDependencies = Defa
300
423
 
301
424
  declare function cloneRouter<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>, dependencies?: Dependencies): Router<Dependencies>;
302
425
 
303
- export { type BuildStateResultWithSegments, type Constants, type ErrorCodes, Router, RouterError, cloneRouter, constants, createRouter, errorCodes, events, getDependenciesApi, getLifecycleApi, getNavigator, getPluginApi, getRoutesApi };
426
+ export { type BuildStateResultWithSegments, type Constants, type ErrorCodes, type PluginApi, type RouteTree, Router, RouterError, cloneRouter, constants, createRouter, errorCodes, events, getDependenciesApi, getLifecycleApi, getNavigator, getPluginApi, getRoutesApi };
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- var e=require("@real-router/logger"),t=require("@real-router/fsm"),r={maxListeners:0,warnListeners:0,maxEventDepth:0},n=class extends Error{},o=class{#e=new Map;#t=null;#r=r;#n;#o;constructor(e){e?.limits&&(this.#r=e.limits),this.#n=e?.onListenerError??null,this.#o=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#i(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:n,warnListeners:o}=this.#r;if(0!==o&&r.size===o&&this.#o?.(e,o),0!==n&&r.size>=n)throw new Error(`Listener limit (${n}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#a(r,e,t):this.#s(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#s(e,t,r){const n=[...e];for(const e of n)try{this.#c(e,r)}catch(e){this.#n?.(t,e)}}#c(e,t){switch(t.length){case 0:e();break;case 1:e(t[0]);break;case 2:e(t[0],t[1]);break;case 3:e(t[0],t[1],t[2]);break;default:Function.prototype.apply.call(e,void 0,t)}}#a(e,t,r){this.#t??=new Map;const o=this.#t,i=o.get(t)??0;if(i>=this.#r.maxEventDepth)throw new n(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{o.set(t,i+1);const a=[...e];for(const e of a)try{this.#c(e,r)}catch(e){if(e instanceof n)throw e;this.#n?.(t,e)}}finally{o.set(t,o.get(t)-1)}}#i(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},i=["replace","reload","force","forceDeactivate","redirected"],a=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function u(e,t=new WeakSet){if(null==e)return!0;const r=typeof e;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(e);if("function"===r||"symbol"===r)return!1;if(Array.isArray(e))return!t.has(e)&&(t.add(e),e.every(e=>u(e,t)));if("object"===r){if(t.has(e))return!1;t.add(e);const r=Object.getPrototypeOf(e);return(null===r||r===Object.prototype)&&Object.values(e).every(e=>u(e,t))}return!1}function d(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const n=e[t];if(!d(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||u(e)}function f(e){return"string"==typeof e}function h(e){return"boolean"==typeof e}function p(e,t){return e in t}function m(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!a.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!s.test(e))throw c(t,`Invalid route name "${e}". 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 g(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function v(e,t){if(!function(e){return"object"==typeof e&&null!==e&&function(e){return function(e){return"string"==typeof e&&(""===e||!(e.length>1e4)&&(!!e.startsWith("@@")||s.test(e)))}(e.name)&&"string"==typeof e.path&&l(e.params)}(e)}(e))throw new TypeError(`[${t}] Invalid state structure: ${g(e)}. Expected State object with name, params, and path properties.`)}var w=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"}),y={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},S="onStart",T="onStop",b="onTransitionStart",E="onTransitionCancel",O="onTransitionSuccess",A="onTransitionError",P={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},R=new Set([P.ROUTER_START,P.TRANSITION_START,P.TRANSITION_SUCCESS,P.TRANSITION_ERROR,P.TRANSITION_CANCEL,P.ROUTER_STOP]),$={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},N={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}},D="IDLE",C="STARTING",j="READY",F="TRANSITIONING",x="DISPOSED",I="START",L="STARTED",M="NAVIGATE",k="COMPLETE",_="FAIL",U="CANCEL",B="STOP",G="DISPOSE",V={initial:D,context:null,transitions:{[D]:{[I]:C,[G]:x},[C]:{[L]:j,[_]:D},[j]:{[M]:F,[_]:j,[B]:D},[F]:{[M]:F,[k]:j,[U]:j,[_]:j},[x]:{}}},q=new WeakSet;function W(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)W(t);else for(const t in e)W(e[t])}function z(e){return e?(q.has(e)||(W(e),q.add(e)),e):e}function Q(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var H=new WeakMap;function K(e){const t=H.get(e);if(!t)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return t}var J={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},Y={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},Z={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function X(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&X(r)}return e}function ee(e,t){return"function"==typeof e?e(t):e}function te(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=J[e];if(n&&"object"==typeof n)return function(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${g(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!p(r,Z)){const e=Object.keys(Z).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],o=Z[r];if(!o.includes(n)){const e=o.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(n)}"`)}}}(t,r));if(typeof t!=typeof n)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof n}, got ${typeof t}`);e in Y&&function(e,t,r){const n=Y[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(e,t,r)}function re(e,t,r){if("limits"===e)return void 0!==t&&function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}]: invalid limits: expected plain object, got ${typeof e}`);for(const[r,n]of Object.entries(e)){if(!Object.hasOwn(N,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&ne(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ne(e,t,r){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError(`[router.${r}]: limit "${e}" must be an integer, got ${String(t)}`);const n=N[e];if(t<n.min||t>n.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${n.min} and ${n.max}, got ${t}`)}var oe=class{#u;constructor(e={}){this.#u=X({...J,...e})}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${g(e)}`);for(const[r,n]of Object.entries(e))p(r,J)?void 0!==n&&te(r,n,t):re(r,n,t)}(e,t)}get(){return this.#u}};function ie(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>ie(e,t[r]))}var ae=class{#d=0;#l=void 0;#f=void 0;#h;#p=new Map;static validateAreStatesEqualArgs(e,t,r){if(null!=e&&v(e,"areStatesEqual"),null!=t&&v(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(r)}. Expected boolean.`)}get(){return this.#l}set(e){this.#f=this.#l,this.#l=e?z(e):void 0}getPrevious(){return this.#f}reset(){this.#l=void 0,this.#f=void 0,this.#p.clear(),this.#d=0}setDependencies(e){this.#h=e}makeState(e,t,r,n,o){const i=n?{...n,id:o??++this.#d,params:n.params}:void 0,a=this.#h.getDefaultParams();let s;return s=Object.hasOwn(a,e)?{...a[e],...t}:t?{...t}:{},z({name:e,params:s,path:r??this.#h.buildPath(e,t),meta:i})}makeNotFoundState(e){return this.makeState(y.UNKNOWN_ROUTE,{path:e},e,{params:{}})}areStatesEqual(e,t,r=!0){if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):this.#m(e.name)).every(r=>ie(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&ie(e.params[r],t.params[r]))}#m(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#h.getUrlParams(e);return this.#p.set(e,r),r}},se={[S]:P.ROUTER_START,[T]:P.ROUTER_STOP,[O]:P.TRANSITION_SUCCESS,[b]:P.TRANSITION_START,[A]:P.TRANSITION_ERROR,[E]:P.TRANSITION_CANCEL},ce=Object.keys(se).filter(e=>p(e,se)),ue="router.usePlugin",de=class t{#g=new Set;#v=new Set;#w;#h;#y=$;static validateUsePluginArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.usePlugin] Expected plugin factory function at index ${t}, got ${g(r)}`)}(e)}static validatePlugin(e){!function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${g(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!p(t,se))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t,r){!function(e,t,r=$.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}count(){return this.#g.size}use(...t){if(this.#S(t.length),1===t.length){const r=t[0],n=this.#T(r);this.#g.add(r);let o=!1;const i=()=>{if(!o){o=!0,this.#g.delete(r),this.#v.delete(i);try{n()}catch(t){e.logger.error(ue,"Error during cleanup:",t)}}};return this.#v.add(i),i}const r=this.#b(t),n=[];try{for(const e of r){const t=this.#T(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(ue,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#g.add(e);let o=!1;const i=()=>{if(!o){o=!0,this.#v.delete(i);for(const{factory:e}of n)this.#g.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(ue,"Error during cleanup:",t)}}};return this.#v.add(i),i}getAll(){return[...this.#g]}has(e){return this.#g.has(e)}disposeAll(){for(const e of this.#v)e();this.#g.clear(),this.#v.clear()}#S(t){const r=this.#y.maxPlugins;if(0===r)return;const n=t+this.#g.size,{warn:o,error:i}=Q(r);n>=i?e.logger.error(ue,`${n} plugins registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=o&&e.logger.warn(ue,`${n} plugins registered. Consider if all are necessary.`)}#b(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(ue,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#T(r){const n=r(this.#w,this.#h.getDependency);t.validatePlugin(n),Object.freeze(n);const o=[];for(const t of ce)t in n&&("function"==typeof n[t]?(o.push(this.#h.addEventListener(se[t],n[t])),"onStart"===t&&this.#h.canNavigate()&&e.logger.warn(ue,"Router already started, onStart will not be called")):e.logger.warn(ue,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof n.teardown&&n.teardown()}}};function le(e,t){if(!h(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function fe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function he(e,t,r=$.maxLifecycleHandlers){if(0!==r&&e>=r)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}var pe=class{#E=new Map;#O=new Map;#A=new Map;#P=new Map;#R=new Set;#$=new Set;#N=new Set;#w;#h;#y=$;setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}addCanActivate(e,t,r,n=!1){n?this.#$.add(e):this.#$.delete(e),r||fe(this.#R.has(e),e,"addActivateGuard");const o=this.#O.has(e);o||r||he(this.#O.size+1,"addActivateGuard",this.#y.maxLifecycleHandlers),this.#D("activate",e,t,this.#O,this.#P,"canActivate",o)}addCanDeactivate(e,t,r,n=!1){n?this.#N.add(e):this.#N.delete(e),r||fe(this.#R.has(e),e,"addDeactivateGuard");const o=this.#E.has(e);o||r||he(this.#E.size+1,"addDeactivateGuard",this.#y.maxLifecycleHandlers),this.#D("deactivate",e,t,this.#E,this.#A,"canDeactivate",o)}clearCanActivate(e){this.#O.delete(e),this.#P.delete(e),this.#$.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#A.delete(e),this.#N.delete(e)}clearAll(){this.#O.clear(),this.#P.clear(),this.#E.clear(),this.#A.clear(),this.#$.clear(),this.#N.clear()}clearDefinitionGuards(){for(const e of this.#$)this.#O.delete(e),this.#P.delete(e);for(const e of this.#N)this.#E.delete(e),this.#A.delete(e);this.#$.clear(),this.#N.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#E)e[t]=r;for(const[e,r]of this.#O)t[e]=r;return[e,t]}getFunctions(){return[this.#A,this.#P]}checkActivateGuardSync(e,t,r){return this.#C(this.#P,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#C(this.#A,e,t,r,"checkDeactivateGuardSync")}#D(t,r,n,o,i,a,s){s?e.logger.warn(`router.${a}`,`Overwriting existing ${t} handler for route "${r}"`):this.#S(o.size+1,a);const c=h(n)?function(e){const t=()=>e;return()=>t}(n):n;o.set(r,c),this.#R.add(r);try{const e=c(this.#w,this.#h.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${a}] Factory must return a function, got ${g(e)}`);i.set(r,e)}catch(e){throw o.delete(r),e}finally{this.#R.delete(r)}}#C(t,r,n,o,i){const a=t.get(r);if(!a)return!0;try{const t=a(n,o);return"boolean"==typeof t?t:(e.logger.warn(`router.${i}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#S(t,r){const n=this.#y.maxLifecycleHandlers;if(0===n)return;const{warn:o,error:i}=Q(n);t>=i?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=o&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},me=new Set;function ge(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function ve(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>ve(e))),t}function we(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],i=r?`${r}.${o.name}`:o.name;if(i===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${i}.`)&&we(o.children,t,i))return!0}return!1}function ye(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Se(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var Te=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,be=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Ee=/\?(.+)$/,Oe=/[^\w!$'()*+,.:;|~-]/gu,Ae=/[^\w!$'()*+,.:;|~-]/u,Pe={default:e=>Ae.test(e)?e.replaceAll(Oe,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Re={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function $e(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Ne(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function De(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function Ce(e){const t=[];for(const r of Object.keys(e)){const n=e[r],o=encodeURIComponent(r);t.push(""===n?o:`${o}=${encodeURIComponent(String(n))}`)}return t.join("&")}function je(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Fe(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,n=e.codePointAt(t+2)??0;if(!je(r)||!je(n))return!1;t+=3}else t++;return!0}var xe=/<[^>]*>/g;function Ie(e,t,r,n,o){const i=""===t.fullName;i||n.push(t);const a=t.absolute,s=t.paramMeta.pathPattern,c=a&&s.startsWith("~")?s.slice(1):s,u=(a?c:s).replaceAll(xe,""),d=a?u:(f=u,""===(l=r)?f:""===f?l:l+f);var l,f;let h=o;i||(h=function(e,t,r,n,o,i){const a=(g=n,Ne(r)===Ne(g)),s=Object.freeze([...o]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),u=Ne(r),d=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,o),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(o),f=a?Ne(n):u,{buildStaticParts:h,buildParamSlots:p}=function(e,t,r){const n=new Set,o=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)o.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const i=[],a=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];i.push(e.slice(u,c.index));const s=o.has(t);a.push({paramName:t,isOptional:n,encoder:s?e=>{const t=Pe[r],n=e.split("/");let o=t(n[0]);for(let e=1;e<n.length;e++)o+=`/${t(n[e])}`;return o}:Pe[r]}),u=c.index+c[0].length}return i.push(e.slice(u)),{buildStaticParts:i,buildParamSlots:a}}(f,a?o.slice(0,-1):o,e.options.urlParamsEncoding),m={name:t.fullName,parent:i,depth:o.length-1,matchSegments:s,meta:c,declaredQueryParams:d,declaredQueryParamsSet:new Set(d),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:h,buildParamSlots:p,buildParamNamesSet:new Set(p.map(e=>e.paramName))};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),a?function(e,t,r){var n,o;n=t,(function(e,t,r){const n=Ne(r);if("/"===n||""===n)return t;let o=t,i=1;const a=n.length;for(;i<=a;){const t=n.indexOf("/",i),r=-1===t?a:t;if(r<=i)break;o=Me(e,o,n.slice(i,r)),i=r+1}return o}(o=e,o.root,r)).slashChildRoute=n;const i=Ne(r),a=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.has(a)&&e.staticCache.set(a,t)}(e,m,n):function(e,t,r,n,o){if(function(e,t,r){const n=Ne(r);"/"!==n?Le(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===o.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,u,t),m}(e,t,d,a?"":r,n,o));for(const r of t.children.values())Ie(e,r,d,n,h);i||n.pop()}function Le(e,t,r,n,o){const i=r.length;for(;n<=i;){const a=r.indexOf("/",n),s=-1===a?i:a,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(xe,"").replace(/\?$/,"");return t.paramChild??={node:$e(),name:n},Le(e,t.paramChild.node,r,s+1,o),void(s>=i?t.route??=o:Le(e,t,r,s+1,o))}t=Me(e,t,c),n=s+1}t.route=o}function Me(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:$e(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(xe,"").replace(/\?$/,"");return t.paramChild??={node:$e(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=$e()),t.staticChildren[n]}var ke=/[\u0080-\uFFFF]/,_e=class{get options(){return this.#e}#e;#t=$e();#o=new Map;#i=new Map;#r=new Map;#a=new Map;#n="";#j=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??De,buildQueryString:e?.buildQueryString??Ce}}registerTree(e){this.#j=e.paramMeta.queryParams,Ie({root:this.#t,options:this.#e,routesByName:this.#o,segmentsByName:this.#i,metaByName:this.#r,staticCache:this.#a,rootQueryParams:this.#j},e,"",[],null)}match(e){const t=this.#s(e);if(!t)return;const[r,n,o]=t,i=this.#e.caseSensitive?n:n.toLowerCase(),a=this.#a.get(i);if(a){if(this.#e.strictTrailingSlash&&!this.#c(r,a))return;return this.#F(a,{},o)}const s={},c=this.#x(n,s);return!c||this.#e.strictTrailingSlash&&!this.#c(r,c)||c.hasConstraints&&!this.#I(s,c)||!this.#L(s)?void 0:this.#F(c,s,o)}buildPath(e,t,r){const n=this.#o.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#M(n,e,t);const o=this.#k(n,t),i=this.#_(o,r?.trailingSlash),a=this.#U(n,t,r?.queryParamsMode);return i+(a?`?${a}`:"")}getSegmentsByName(e){return this.#i.get(e)}getMetaByName(e){return this.#r.get(e)}hasRoute(e){return this.#o.has(e)}setRootPath(e){this.#n=e}#M(e,t,r){for(const[n,o]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!o.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${o.constraint}'`)}}}#k(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#n+r[0];let o=this.#n+r[0];for(const[e,i]of n.entries()){const n=t?.[i.paramName];if(null==n){if(!i.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${i.paramName}'`);o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1)),o+=r[e+1];continue}const a="object"==typeof n?JSON.stringify(n):String(n);o+=i.encoder(a)+r[e+1]}return o}#_(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#U(e,t,r){if(!t)return"";const n={};let o=!1;for(const r of e.declaredQueryParams)r in t&&(n[r]=t[r],o=!0);if("loose"===r)for(const r in t)!Object.hasOwn(t,r)||e.declaredQueryParamsSet.has(r)||e.buildParamNamesSet.has(r)||(n[r]=t[r],o=!0);return o?this.#e.buildQueryString(n):""}#s(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ke.test(e))return;if(this.#n.length>0){if(!e.startsWith(this.#n))return;e=e.slice(this.#n.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),o=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,Ne(n),o]}#F(e,t,r){if(void 0!==r){const n=this.#e.parseQueryString(r);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#c(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#x(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#B(this.#t,e,1,t)}#B(e,t,r,n){let o=e;const i=t.length;for(;r<=i;){const e=t.indexOf("/",r),a=-1===e?i:e,s=t.slice(r,a),c=this.#e.caseSensitive?s:s.toLowerCase();let u;if(c in o.staticChildren)u=o.staticChildren[c];else{if(!o.paramChild){if(o.splatChild){const e={},i=this.#B(o.splatChild.node,t,r,e);return i?(Object.assign(n,e),i):(n[o.splatChild.name]=t.slice(r),o.splatChild.node.route)}return}u=o.paramChild.node,n[o.paramChild.name]=s}o=u,r=a+1}return o.slashChildRoute??o.route}#L(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const r=Re[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!Fe(n))return!1;e[t]=r(n)}}return!0}#I(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}},Ue=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Be=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},Ge={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Be(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Be(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Be(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Be(e)).join(",")}`}},Ve={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},qe={default:{encode:e=>e},hidden:{encode:()=>""}},We=(e,t,r)=>({boolean:Ve[t],null:qe[r],array:Ge[e]}),ze={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Ve.none,null:qe.default,array:Ge.none}},Qe=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return ze;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:We(t,r,n)}},He=e=>encodeURIComponent(e),Ke=(e,t,r)=>{const n=He(e);switch(typeof t){case"string":case"number":default:return`${n}=${He(t)}`;case"boolean":return r.strategies.boolean.encode(n,t);case"object":return null===t?r.strategies.null.encode(n):Array.isArray(t)?r.strategies.array.encodeArray(n,t):`${n}=${He(t)}`}};function Je(e,t,r,n,o){const i=e.indexOf("=",t),a=-1!==i&&i<r,s=e.slice(t,a?i:r),{name:c,hasBrackets:u}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(s);var d,l,f,h,p;!function(e,t,r,n){const o=e[t];void 0===o?e[t]=n?[r]:r:Array.isArray(o)?o.push(r):e[t]=[o,r]}(n,Ue(c),(d=e,l=i,f=r,h=a,p=o,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=Ue(e);return t.boolean.decodeValue(n)})(h?d.slice(l+1,f):void 0,p):h?Ue(d.slice(l+1,f)):null),u)}function Ye(e,t){const r=e.path,n=r.startsWith("~"),o=n?r.slice(1):r,i={name:e.name,path:o,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=Ye(t,i);i.children.push(e)}return i}function Ze(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Xe(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function et(e,t,r){const n=function(e){const t=[],r=[],n=[],o={},i=new Map,a=e.replaceAll(be,"$1"),s=Ee.exec(a);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),o[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=Te.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),o[e]="url";else if(t.push(e),o[e]="url",r){const t=`^${Se(r)}$`;i.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:o,constraintPatterns:i,pathPattern:e}}(e.path),o=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),i={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:o};var a;i.fullName=(a=i,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:s,nonAbsoluteChildren:c}=function(e,t,r){const n=[],o=[];for(const i of e){const e=et(i,t,r);n.push(e),e.absolute||o.push(e)}return{childrenMap:Xe(n),nonAbsoluteChildren:o}}(e.children,i,r);return i.children=s,i.nonAbsoluteChildren=c,i.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;const o=[];let i=e.parent;for(;i?.path;)o.unshift(i),i=i.parent;let a="";for(const e of o){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;a=e.absolute?e.path:Ze(a,e.path)}return e.absolute?e.path:Ze(a,e.path)}(i),r&&(Object.freeze(c),Object.freeze(o),Object.freeze(i.children),Object.freeze(i)),i}function tt(e,t,r,n){return function(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build:n=>function(e,t=!0){return et(e,null,t)}(function(e,t,r){const n=Ye({name:e,path:t},null);for(const e of r){const t=Ye(e,n);n.children.push(t)}return n}(e,t,r),!n?.skipFreeze)}}(e,t).addMany(r).build(n)}function rt(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.size>0&&(t.children=[...e.children.values()].map(e=>rt(e))),t}function nt(e){const t=e?.queryParams;return new _e({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),Je(e,r,o,t),r=o+1}}(e,t),t}(r);const n=Qe(t),o={};let i=0;const a=r.length;for(;i<a;){let e=r.indexOf("&",i);-1===e&&(e=a),Je(r,i,e,o,n.strategies),i=e+1}return o})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=Qe(t),o=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=Ke(t,r,n);i&&o.push(i)}return o.join("&")})(e,t)})}function ot(e,t){return new TypeError(`[router.${e}] ${t}`)}var it=/^[A-Z_a-z][\w-]*$/,at=/\S/;function st(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function ct(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function ut(e,t,r,n="",o,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${st(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${st(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const a=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${st(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!at.test(r))throw new TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${t}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!it.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(a,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,ot(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw ot(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw ot(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw ot(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const o=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&o)throw ot(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(a.path,a.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(a,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(a,t);const s=a.name,c=n?`${n}.${s}`:s;r&&c&&function(e,t,r){if(ct(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),o&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(o,c,t);const u=a.path,d=n;if(r&&function(e,t,r,n){const o=""===t?e:ct(e,t);if(o)for(const e of o.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,d,u,t),i&&function(e,t,r,n){const o=e.get(t);if(o?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);o?o.add(r):e.set(t,new Set([r]))}(i,d,u,t),void 0!==a.children){if(!Array.isArray(a.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${st(a.children)}`);for(const e of a.children)ut(e,t,r,c,o,i)}}function dt(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${g(e.canActivate)}`);if(void 0!==e.canDeactivate&&"function"!=typeof e.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${g(e.canDeactivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${g(e.defaultParams)}`)}if("AsyncFunction"===e.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===e.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)dt(r,`${t}.${r.name}`)}function lt(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function ft(e){const t=new Set;for(const r of e)for(const e of lt(r))t.add(e);return t}function ht(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,i=[...n,o.path];if(e===t)return i;if(o.children&&t.startsWith(`${e}.`))return ht(o.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function pt(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of pt(n.children,e))r.add(t)}return r}function mt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of mt(n.children,e))r.set(t,o)}return r}function gt(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.paramMeta.urlParams)t.add(e);for(const e of r.paramMeta.spatParams)t.add(e)}return t}(function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let o=e;for(const e of n){const t=o.children.get(e);if(!t)return null;r.push(t),o=t}return r}(r,e)):ft(ht(n,e))}function vt(e,t,r,n,o){const i=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.children.get(e),!n)return!1;return!0}(o,t),a=n.has(t);if(!i&&!a)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=ft(ht(r,e)),c=[...gt(t,i,o,r)].filter(e=>!s.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function wt(e,t,r=100){const n=new Set,o=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),o.push(e),i=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return i}function yt(e,t,r){const n=pt(e),o=mt(e),i={...t};for(const[e,t]of o)i[e]=t;for(const[t,i]of o)vt(t,i,e,n,r);for(const e of Object.keys(i))wt(e,i)}function St(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${g(t)}`);dt(t,t.name)}}function Tt(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${g(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function bt(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function Et(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);bt(e,t)}}function Ot(e,t,r,n){if(n&&t){let e=t;for(const t of n.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${n}" does not exist`)}const o=new Set,i=new Map;for(const r of e)ut(r,"addRoute",t,n??"",o,i);t&&r&&yt(e,r,t)}function At(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}function Pt(e,t,r,n,o){if(!r(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!r(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);(function(e,t,r){const n=r.getSegmentsByName(e),o=r.getSegmentsByName(t),i=function(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}(n),a=[];for(const e of o)for(const t of e.paramMeta.urlParams)a.push(t);const s=a.filter(e=>!i.has(e));if(s.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${s.join(", ")}] that are not available in source route "${e}"`)})(e,t,n),function(e,t,r){wt(e,{...r.forwardMap,[e]:t})}(e,t,o)}}function Rt(e,t,r){const n=tt("",t,e),o=nt(r);return o.registerTree(n),{tree:n,matcher:o}}function $t(e,t){const r=Rt(e.definitions,e.rootPath,e.matcherOptions);e.tree=r.tree,e.matcher=r.matcher,e.resolvedForwardMap=jt(e.config,t)}function Nt(e){const t=Rt(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher}function Dt(e){Ct(e),Nt(e)}function Ct(e){e.definitions.length=0,Object.assign(e.config,ge()),e.resolvedForwardMap=Object.create(null),e.routeCustomFields=Object.create(null)}function jt(e,t){return t?xt(e):Ft(e)}function Ft(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap))t[r]=wt(r,e.forwardMap);return t}function xt(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap)){let n=r;for(;e.forwardMap[n];)n=e.forwardMap[n];t[r]=n}return t}function It(t,r,n,o,i,a,s){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(t).filter(([e])=>!c.has(e)));Object.keys(u).length>0&&(o[r]=u),t.canActivate&&(s?s.addActivateGuard(r,t.canActivate):i.set(r,t.canActivate)),t.canDeactivate&&(s?s.addDeactivateGuard(r,t.canDeactivate):a.set(r,t.canDeactivate)),t.forwardTo&&function(t,r,n){if(t.canActivate&&e.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 t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&e.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 t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const e="AsyncFunction"===t.forwardTo.constructor.name,n=t.forwardTo.toString().includes("__awaiter");if(e||n)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?n.forwardMap[r]=t.forwardTo:n.forwardFnMap[r]=t.forwardTo}(t,r,n),t.decodeParams&&(n.decoders[r]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(n.encoders[r]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(n.defaultParams[r]=t.defaultParams)}function Lt(e,t,r,n,o,i,a=""){for(const s of e){const e=a?`${a}.${s.name}`:s.name;It(s,e,t,r,n,o,i),s.children&&Lt(s.children,t,r,n,o,i,e)}}var Mt,kt,_t=".";function Ut(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Bt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t}function Gt(e,t,r){const n=t.meta?.params[e];if(!n||"object"!=typeof n)return!0;for(const e of Object.keys(n)){const n=t.params[e],o=r.params[e];if(Bt(n)&&Bt(o)&&String(n)!==String(o))return!1}return!0}function Vt(e){if(!e)return[""];const t=e.indexOf(_t);if(-1===t)return[e];const r=e.indexOf(_t,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(_t,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(_t,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(_t),r=t.length,n=[t[0]];let o=t[0].length;for(let i=1;i<r-1;i++)o+=1+t[i].length,n.push(e.slice(0,o));return n.push(e),n}(e)}var qt=null;function Wt(e,t){if(!t)return{intersection:"",toActivate:Vt(e.name),toDeactivate:[]};if(void 0===e.meta?.params&&void 0===t.meta?.params)return{intersection:"",toActivate:Vt(e.name),toDeactivate:Ut(Vt(t.name))};const r=Vt(e.name),n=Vt(t.name),o=function(e,t,r,n,o){for(let i=0;i<o;i++){const o=r[i];if(o!==n[i])return i;if(!Gt(o,e,t))return i}return o}(e,t,r,n,Math.min(n.length,r.length)),i=[];for(let e=n.length-1;e>=o;e--)i.push(n[e]);const a=r.slice(o);return{intersection:o>0?n[o-1]:"",toDeactivate:i,toActivate:a}}function zt(e,t,r){if(r?.reload)return Wt(e,t);if(null!==qt&&e===Mt&&t===kt)return qt;const n=Wt(e,t);return Mt=e,kt=t,qt=n,n}function Qt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var Ht=class{#G;get#h(){return this.#G.depsStore}constructor(e=[],t=!1,r){this.#G=function(e,t,r){const n=[],o=ge(),i=Object.create(null),a=new Map,s=new Map;for(const t of e)n.push(ve(t));const{tree:c,matcher:u}=Rt(n,"",r);return Lt(e,o,i,a,s,void 0,""),{definitions:n,config:o,tree:c,matcher:u,resolvedForwardMap:t?xt(o):Ft(o),routeCustomFields:i,rootPath:"",matcherOptions:r,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:a,pendingCanDeactivate:s,treeOperations:{commitTreeChanges:$t,resetStore:Dt,nodeToDefinition:rt,validateRoutes:Ot}}}(e,t,r)}static shouldUpdateNode(e){return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.transition?.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:i}=zt(t,r);return e===n||!!o.includes(e)||i.includes(e)}}setDependencies(e){this.#G.depsStore=e;for(const[t,r]of this.#G.pendingCanActivate)e.addActivateGuard(t,r);this.#G.pendingCanActivate.clear();for(const[t,r]of this.#G.pendingCanDeactivate)e.addDeactivateGuard(t,r);this.#G.pendingCanDeactivate.clear()}setLifecycleNamespace(e){this.#G.lifecycleNamespace=e}setRootPath(e){this.#G.rootPath=e,Nt(this.#G)}hasRoute(e){return this.#G.matcher.hasRoute(e)}clearRoutes(){Dt(this.#G)}buildPath(e,t,r){if(e===y.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const n=Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t??{},o="function"==typeof this.#G.config.encoders[e]?this.#G.config.encoders[e]({...n}):n,i=r?.trailingSlash;return this.#G.matcher.buildPath(e,o,{trailingSlash:"never"===i||"always"===i?i:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t){const r=t,n=this.#G.matcher.match(e);if(!n)return;const o=Qt(n),{name:i,params:a,meta:s}=o,c="function"==typeof this.#G.config.decoders[i]?this.#G.config.decoders[i](a):a,{name:u,params:d}=this.#h.forwardState(i,c);let l=e;if(r.rewritePathOnMatch){const e="function"==typeof this.#G.config.encoders[u]?this.#G.config.encoders[u]({...d}):d,t=r.trailingSlash;l=this.#G.matcher.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:r.queryParamsMode})}return this.#h.makeState(u,d,l,{params:s})}forwardState(e,t){if(Object.hasOwn(this.#G.config.forwardFnMap,e)){const r=this.#V(e,t),n=this.#G.config.forwardFnMap[e],o=this.#q(e,n,t);return{name:o,params:this.#V(o,r)}}const r=this.#G.resolvedForwardMap[e]??e;if(r!==e&&Object.hasOwn(this.#G.config.forwardFnMap,r)){const n=this.#V(e,t),o=this.#G.config.forwardFnMap[r],i=this.#q(r,o,t);return{name:i,params:this.#V(i,n)}}if(r!==e){const n=this.#V(e,t);return{name:r,params:this.#V(r,n)}}return{name:e,params:this.#V(e,t)}}buildStateResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return Qt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return{state:Qt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){me.has(e)||(m(e,"isActiveRoute"),me.add(e));const o=this.#h.getState();if(!o)return!1;const i=o.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const a=this.#G.config.defaultParams[e];if(r||i===e){const r=a?{...a,...t}:t;return this.#h.areStatesEqual({name:e,params:r,path:""},o,n)}const s=o.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!a||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(a,s,t))}getUrlParams(e){const t=this.#G.matcher.getSegmentsByName(e);return t?function(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}(t):[]}getStore(){return this.#G}#V(e,t){return Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t}#q(e,t,r){const n=new Set([e]);let o=t(this.#h.getDependency,r),i=0;if("string"!=typeof o)throw new TypeError("forwardTo callback must return a string, got "+typeof o);for(;i<100;){if(void 0===this.#G.matcher.getSegmentsByName(o))throw new Error(`Route "${o}" does not exist`);if(n.has(o)){const e=[...n,o].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(o),Object.hasOwn(this.#G.config.forwardFnMap,o)){o=(0,this.#G.config.forwardFnMap[o])(this.#h.getDependency,r),i++;continue}const e=this.#G.config.forwardMap[o];if(void 0===e)return o;o=e,i++}throw new Error("forwardTo exceeds maximum depth of 100")}},Kt=new Set(Object.values(w)),Jt=new Set(["code","segment","path","redirect"]),Yt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Zt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(o):void 0;for(const[e,t]of Object.entries(i)){if(Jt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Yt.has(e)||(this[e]=t)}}setCode(e){this.code=e,Kt.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(Jt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Yt.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function Xt(e,t,r){if(e instanceof Zt)throw e.setCode(t),e;throw new Zt(t,function(e,t){const r={segment:t};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))er.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var er=new Set(["code","segment","path","redirect"]);async function tr(e,t,r,n,o,i,a){const s=n.filter(t=>e.has(t));if(0===s.length)return;let c;for(const n of s){if(i())throw new Zt(w.TRANSITION_CANCELLED);const s=e.get(n);try{c=await s(t,r,a)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw new Zt(w.TRANSITION_CANCELLED,{reason:a.reason});Xt(e,o,n)}if(!c)throw new Zt(o,{segment:n})}}var rr=class t{#W;#h;#z;#Q=null;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}(e)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of i){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}const r=t.signal;return!(void 0!==r&&!(r instanceof AbortSignal))}(e))throw new TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e,t)}setCanNavigate(e){this.#W=e}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#z=e}async navigate(e,t,r){if(!this.#W())throw new Zt(w.ROUTER_NOT_STARTED);const n=this.#h,o=n.buildStateWithSegments(e,t);if(!o){const e=new Zt(w.ROUTE_NOT_FOUND);throw n.emitTransitionError(void 0,n.getState(),e),e}const{state:i}=o,a=n.makeState(i.name,i.params,n.buildPath(i.name,i.params),{params:i.meta}),s=n.getState();if(!r.reload&&!r.force&&n.areStatesEqual(s,a,!1)){const e=new Zt(w.SAME_STATES);throw n.emitTransitionError(a,s,e),e}return this.navigateToState(a,s,r)}async navigateToState(r,n,o){const i=this.#h,a=this.#z;a.isTransitioning()&&(e.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 Zt(w.TRANSITION_CANCELLED)),i.cancelNavigation());const s=new AbortController;if(this.#Q=s,o.signal){if(o.signal.aborted)throw this.#Q=null,new Zt(w.TRANSITION_CANCELLED,{reason:o.signal.reason});o.signal.addEventListener("abort",()=>{s.abort(o.signal?.reason)},{once:!0,signal:s.signal})}i.startTransition(r,n);try{const{state:e,meta:c}=await async function(e,t,r,n,o){const[i,a]=e.getLifecycleFunctions(),s=t.name===y.UNKNOWN_ROUTE,c=()=>o.aborted||!e.isActive(),{toDeactivate:u,toActivate:d,intersection:l}=zt(t,r,void 0===n.reload?void 0:{reload:n.reload}),f=!s&&d.length>0;if(r&&!n.forceDeactivate&&u.length>0&&await tr(i,t,r,u,w.CANNOT_DEACTIVATE,c,o),c())throw new Zt(w.TRANSITION_CANCELLED);if(f&&await tr(a,t,r,d,w.CANNOT_ACTIVATE,c,o),c())throw new Zt(w.TRANSITION_CANCELLED);if(r)for(const t of u)!d.includes(t)&&i.has(t)&&e.clearCanDeactivate(t);return{state:t,meta:{phase:"activating",segments:{deactivated:u,activated:d,intersection:l}}}}(a,r,n,o,s.signal);if(e.name===y.UNKNOWN_ROUTE||i.hasRoute(e.name)){const r=t.#H(e,c,n,o);i.setState(r);const a=void 0===o.signal?o:t.#K(o);return i.sendTransitionDone(r,n,a),r}{const t=new Zt(w.ROUTE_NOT_FOUND,{routeName:e.name});throw i.sendTransitionError(e,n,t),t}}catch(e){throw this.#J(e,r,n),e}finally{s.abort(),this.#Q===s&&(this.#Q=null)}}async navigateToDefault(e){const t=this.#h,r=t.getOptions();if(!r.defaultRoute)throw new Zt(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const n=ee(r.defaultRoute,t.getDependency);if(!n)throw new Zt(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});const o=ee(r.defaultParams,t.getDependency);return this.navigate(n,o,e)}abortCurrentNavigation(){this.#Q?.abort(new Zt(w.TRANSITION_CANCELLED)),this.#Q=null}static#K(e){const{signal:t,...r}=e;return r}static#H(e,t,r,n){const o={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments,...void 0!==n.reload&&{reload:n.reload},...void 0!==n.redirected&&{redirected:n.redirected}};return Object.freeze(o.segments.deactivated),Object.freeze(o.segments.activated),Object.freeze(o.segments),Object.freeze(o),{...e,transition:o}}#J(e,t,r){const n=e;n.code!==w.TRANSITION_CANCELLED&&n.code!==w.ROUTE_NOT_FOUND&&(n.code===w.CANNOT_ACTIVATE||n.code===w.CANNOT_DEACTIVATE?this.#h.sendTransitionBlocked(t,r,n):this.#h.sendTransitionError(t,r,n))}},nr=class{#Y;#h;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setNavigateToState(e){this.#Y=e}setDependencies(e){this.#h=e}async start(e){const t=this.#h,r=t.getOptions(),n={replace:!0},o=t.matchPath(e);if(!o&&!r.allowNotFound){const r=new Zt(w.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}let i;if(t.completeStart(),o)i=await this.#Y(o,void 0,n);else{const r=t.makeNotFoundState(e);i=await this.#Y(r,void 0,n)}return i}stop(){this.#h.clearState()}},or=class{#Z;#X;#ee;constructor(e){this.#Z=e.routerFSM,this.#X=e.emitter,this.#ee=void 0,this.#te()}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#X.emit(P.ROUTER_START)}emitRouterStop(){this.#X.emit(P.ROUTER_STOP)}emitTransitionStart(e,t){this.#X.emit(P.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#X.emit(P.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#X.emit(P.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#X.emit(P.TRANSITION_CANCEL,e,t)}sendStart(){this.#Z.send(I)}sendStop(){this.#Z.send(B)}sendDispose(){this.#Z.send(G)}completeStart(){this.#Z.send(L)}beginTransition(e,t){this.#ee=e,this.#Z.send(M,{toState:e,fromState:t})}completeTransition(e,t,r={}){this.#Z.send(k,{state:e,fromState:t,opts:r}),this.#ee=void 0}failTransition(e,t,r){this.#Z.send(_,{toState:e,fromState:t,error:r}),this.#ee=void 0}cancelTransition(e,t){this.#Z.send(U,{toState:e,fromState:t}),this.#ee=void 0}emitOrFailTransitionError(e,t,r){this.#Z.getState()===j?this.#Z.send(_,{toState:e,fromState:t,error:r}):this.emitTransitionError(e,t,r)}canBeginTransition(){return this.#Z.canSend(M)}canStart(){return this.#Z.canSend(I)}canCancel(){return this.#Z.canSend(U)}isActive(){const e=this.#Z.getState();return e!==D&&e!==x}isDisposed(){return this.#Z.getState()===x}isTransitioning(){return this.#Z.getState()===F}isReady(){return this.#Z.getState()===j}getCurrentToState(){return this.#ee}addEventListener(e,t){return this.#X.on(e,t)}subscribe(e){return this.#X.on(P.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#X.clearAll()}setLimits(e){this.#X.setLimits(e)}cancelTransitionIfRunning(e){this.canCancel()&&this.cancelTransition(this.#ee,e)}#te(){const e=this.#Z;e.on(C,L,()=>{this.emitRouterStart()}),e.on(j,B,()=>{this.emitRouterStop()}),e.on(j,M,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(F,k,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(F,U,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(C,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(j,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}};function ir(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}function ar(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}var sr=new Zt(w.ROUTER_ALREADY_STARTED),cr=new Set(["all","warn-error","error-only"]);var ur=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependenciesStore=e.dependenciesStore,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.eventBus=e.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(){this.routeLifecycle.setRouter(this.router),this.routeLifecycle.setDependencies({getDependency:e=>this.dependenciesStore.dependencies[e]})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.routeLifecycle.addCanActivate(e,t,!0,!0)},addDeactivateGuard:(e,t)=>{this.routeLifecycle.addCanDeactivate(e,t,!0,!0)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],forwardState:(e,t)=>{const r=K(this.router);return r.noValidate||Tt(e,t,"forwardState"),r.forwardState(e,t)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){this.plugins.setRouter(this.router),this.plugins.setDependencies({addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),getDependency:e=>this.dependenciesStore.dependencies[e]})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const r=K(this.router);r.noValidate||Tt(e,t,"navigate");const{name:n,params:o}=r.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(n,o)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],startTransition:(e,t)=>{this.eventBus.beginTransition(e,t)},cancelNavigation:()=>{this.eventBus.cancelTransition(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.completeTransition(e,t,r)},sendTransitionBlocked:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},sendTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.emitOrFailTransitionError(e,t,r)}}),this.navigation.setTransitionDependencies({getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),makeNotFoundState:e=>this.state.makeNotFoundState(e),clearState:()=>{this.state.set(void 0)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.completeStart()},emitTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),getUrlParams:e=>this.routes.getUrlParams(e)})}wireCyclicDeps(){this.navigation.setCanNavigate(()=>this.eventBus.canBeginTransition()),this.lifecycle.setNavigateToState((e,t,r)=>this.navigation.navigateToState(e,t,r))}},dr=class r{#u;#y;#re;#ne;#oe;#ie;#g;#ae;#se;#ce;#ue;constructor(r=[],n={},i={}){n.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!cr.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(n.logger)&&(e.logger.configure(n.logger),delete n.logger),oe.validateOptions(n,"constructor");const a=n.noValidate??!1;a||ar(i,"constructor"),!a&&r.length>0&&(St(r),Ot(r)),this.#u=new oe(n),this.#y=function(e={}){return{...$,...e}}(n.limits),this.#re=function(e={}){const t=Object.create(null);for(const r in e)void 0!==e[r]&&(t[r]=e[r]);return{dependencies:t,limits:$}}(i),this.#ne=new ae,this.#oe=new Ht(r,a,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#u.get())),this.#ie=new pe,this.#g=new de,this.#ae=new rr,this.#se=new nr,this.#ue=a;const s=new t.FSM(V),c=new o({onListenerError:(t,r)=>{e.logger.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.logger.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var u;this.#ce=new or({routerFSM:s,emitter:c}),(u=new ur({router:this,options:this.#u,limits:this.#y,dependenciesStore:this.#re,state:this.#ne,routes:this.#oe,routeLifecycle:this.#ie,plugins:this.#g,navigation:this.#ae,lifecycle:this.#se,eventBus:this.#ce})).wireLimits(),u.wireRouteLifecycleDeps(),u.wireRoutesDeps(),u.wirePluginsDeps(),u.wireNavigationDeps(),u.wireLifecycleDeps(),u.wireStateDeps(),u.wireCyclicDeps(),H.set(this,{makeState:(e,t,r,n,o)=>this.#ne.makeState(e,t,r,n,o),forwardState:(e,t)=>this.#oe.forwardState(e,t),buildStateResolved:(e,t)=>this.#oe.buildStateResolved(e,t),matchPath:(e,t)=>this.#oe.matchPath(e,t),getOptions:()=>this.#u.get(),navigateToState:(e,t,r)=>this.#ae.navigateToState(e,t,r),addEventListener:(e,t)=>this.#ce.addEventListener(e,t),buildPath:(e,t)=>this.#oe.buildPath(e,t,this.#u.get()),setRootPath:e=>{this.#oe.setRootPath(e)},getRootPath:()=>this.#oe.getStore().rootPath,getTree:()=>this.#oe.getStore().tree,isDisposed:()=>this.#ce.isDisposed(),noValidate:a,dependenciesGetStore:()=>this.#re,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#re.dependencies}),getLifecycleFactories:()=>this.#ie.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#oe.getStore(),getStateName:()=>this.#ne.get()?.name,isTransitioning:()=>this.#ce.isTransitioning(),clearState:()=>{this.#ne.set(void 0)},setState:e=>{this.#ne.set(e)}}),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.subscribe=this.subscribe.bind(this)}isActiveRoute(t,r,n,o){return this.#ue||function(e,t,r,n){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(t))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)}(t,r,n,o),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#oe.isActiveRoute(t,r,n,o)}buildPath(e,t){return this.#ue||function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e),this.#oe.buildPath(e,t,this.#u.get())}getState(){return this.#ne.get()}getPreviousState(){return this.#ne.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ue||ae.validateAreStatesEqualArgs(e,t,r),this.#ne.areStatesEqual(e,t,r)}shouldUpdateNode(e){return this.#ue||function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e),Ht.shouldUpdateNode(e)}isActive(){return this.#ce.isActive()}async start(e){if(this.#ue||nr.validateStartArgs([e]),!this.#ce.canStart())throw sr;this.#ce.sendStart();try{return await this.#se.start(e)}catch(e){throw this.#ce.isReady()&&(this.#se.stop(),this.#ce.sendStop()),e}}stop(){return this.#ae.abortCurrentNavigation(),this.#ce.cancelTransitionIfRunning(this.#ne.get()),this.#ce.isReady()||this.#ce.isTransitioning()?(this.#se.stop(),this.#ce.sendStop(),this):this}dispose(){this.#ce.isDisposed()||(this.#ae.abortCurrentNavigation(),this.#ce.cancelTransitionIfRunning(this.#ne.get()),(this.#ce.isReady()||this.#ce.isTransitioning())&&(this.#se.stop(),this.#ce.sendStop()),this.#ce.sendDispose(),this.#ce.clearAll(),this.#g.disposeAll(),this.#oe.clearRoutes(),this.#ie.clearAll(),this.#ne.reset(),this.#re.dependencies=Object.create(null),this.#de())}canNavigateTo(e,t){if(this.#ue||m(e,"canNavigateTo"),!this.#oe.hasRoute(e))return!1;const r=K(this),{name:n,params:o}=r.forwardState(e,t??{}),i=this.#ne.makeState(n,o),a=this.#ne.get(),{toDeactivate:s,toActivate:c}=zt(i,a);for(const e of s)if(!this.#ie.checkDeactivateGuardSync(e,i,a))return!1;for(const e of c)if(!this.#ie.checkActivateGuardSync(e,i,a))return!1;return!0}usePlugin(...e){return this.#ue||(de.validateUsePluginArgs(e),de.validatePluginLimit(this.#g.count(),e.length,this.#y.maxPlugins),de.validateNoDuplicatePlugins(e,this.#g.has.bind(this.#g))),this.#g.use(...e)}subscribe(e){return this.#ue||or.validateSubscribeListener(e),this.#ce.subscribe(e)}navigate(e,t,n){this.#ue||rr.validateNavigateArgs(e);const o=n??{};this.#ue||rr.validateNavigationOptions(o,"navigate");const i=this.#ae.navigate(e,t??{},o);return r.#le(i),i}navigateToDefault(e){this.#ue||rr.validateNavigateToDefaultArgs(e);const t=e??{};this.#ue||rr.validateNavigationOptions(t,"navigateToDefault");const n=this.#ae.navigateToDefault(t);return r.#le(n),n}static#fe=t=>{t instanceof Zt&&(t.code===w.SAME_STATES||t.code===w.TRANSITION_CANCELLED||t.code===w.ROUTER_NOT_STARTED||t.code===w.ROUTE_NOT_FOUND)||e.logger.error("router.navigate","Unexpected navigation error",t)};static#le(e){e.catch(r.#fe)}#de(){this.navigate=lr,this.navigateToDefault=lr,this.start=lr,this.stop=lr,this.usePlugin=lr,this.subscribe=lr,this.canNavigateTo=lr}};function lr(){throw new Zt(w.ROUTER_DISPOSED)}function fr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function hr(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name;if(e===t)return n;if(n.children&&t.startsWith(`${e}.`))return hr(n.children,t,e)}}function pr(e,t,r,n){const o={name:e.name,path:e.path},i=r.forwardFnMap[t],a=r.forwardMap[t];void 0!==i?o.forwardTo=i:void 0!==a&&(o.forwardTo=a),t in r.defaultParams&&(o.defaultParams=r.defaultParams[t]),t in r.decoders&&(o.decodeParams=r.decoders[t]),t in r.encoders&&(o.encodeParams=r.encoders[t]);const[s,c]=n;return t in c&&(o.canActivate=c[t]),t in s&&(o.canDeactivate=s[t]),e.children&&(o.children=e.children.map(e=>pr(e,`${t}.${e.name}`,r,n))),o}function mr(e,t,r,n){if(n){const t=hr(e.definitions,n);t.children??=[];for(const e of r)t.children.push(ve(e))}else for(const t of r)e.definitions.push(ve(t));Lt(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,n??""),e.treeOperations.commitTreeChanges(e,t)}function gr(e,t,r){return!!we(e.definitions,r)&&(function(e,t,r,n){const o=t=>t===e||t.startsWith(`${e}.`);ye(t.decoders,o),ye(t.encoders,o),ye(t.defaultParams,o),ye(t.forwardMap,o),ye(t.forwardFnMap,o),ye(r,o),ye(t.forwardMap,e=>o(t.forwardMap[e]));const[i,a]=n.getFactories();for(const e of Object.keys(a))o(e)&&n.clearCanActivate(e);for(const e of Object.keys(i))o(e)&&n.clearCanDeactivate(e)}(r,e.config,e.routeCustomFields,e.lifecycleNamespace),e.treeOperations.commitTreeChanges(e,t),!0)}function vr(e,t){const r=e.matcher.getSegmentsByName(t);if(!r)return;const n=r.at(-1),o=e.treeOperations.nodeToDefinition(n),i=e.lifecycleNamespace.getFactories();return pr(o,t,e.config,i)}function wr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function yr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function Sr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function Tr(e){const t=K(e),r=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addActivateGuard"),le(n,"addActivateGuard")),r.addCanActivate(e,n,t.noValidate)},addDeactivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addDeactivateGuard"),le(n,"addDeactivateGuard")),r.addCanDeactivate(e,n,t.noValidate)},removeActivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeActivateGuard"),r.clearCanActivate(e)},removeDeactivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeDeactivateGuard"),r.clearCanDeactivate(e)}}}exports.Router=dr,exports.RouterError=Zt,exports.cloneRouter=function(e,t){const r=K(e);if(r.isDisposed())throw new Zt(w.ROUTER_DISPOSED);r.noValidate||function(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${g(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}(t);const n=r.routeGetStore(),o=[...n.tree.children.values()].map(e=>rt(e)),i=n.config,a=n.resolvedForwardMap,s=n.routeCustomFields,c=r.cloneOptions(),u=r.cloneDependencies(),[d,l]=r.getLifecycleFactories(),f=r.getPluginFactories(),h={...u,...t},p=new dr(o,c,h),m=Tr(p);for(const[e,t]of Object.entries(d))m.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(l))m.addActivateGuard(e,t);f.length>0&&p.usePlugin(...f);const v=K(p).routeGetStore();return Object.assign(v.config.decoders,i.decoders),Object.assign(v.config.encoders,i.encoders),Object.assign(v.config.defaultParams,i.defaultParams),Object.assign(v.config.forwardMap,i.forwardMap),Object.assign(v.config.forwardFnMap,i.forwardFnMap),Object.assign(v.resolvedForwardMap,a),Object.assign(v.routeCustomFields,s),p},exports.constants=y,exports.createRouter=(e=[],t={},r={})=>new dr(e,t,r),exports.errorCodes=w,exports.events=P,exports.getDependenciesApi=function(t){const r=K(t);return{get:e=>{r.noValidate||ir(e,"getDependency");const t=r.dependenciesGetStore().dependencies[e];return r.noValidate||function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(t,e),t},getAll:()=>({...r.dependenciesGetStore().dependencies}),set:(t,n)=>{yr(r.isDisposed),r.noValidate||function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(t),function(t,r,n){if(void 0===n)return!1;if(Object.hasOwn(t.dependencies,r)){const o=t.dependencies[r],i=o!==n,a=Number.isNaN(o)&&Number.isNaN(n);i&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",r)}else!function(t,r){const n=t.limits.maxDependencies;if(0===n)return;const o=Object.keys(t.dependencies).length,{warn:i,error:a}=Q(n);if(o===i)e.logger.warn(`router.${r}`,`${i} dependencies registered. Consider if all are necessary.`);else if(o===a)e.logger.error(`router.${r}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`);else if(o>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}(t,"setDependency");t.dependencies[r]=n}(r.dependenciesGetStore(),t,n)},setAll:t=>{yr(r.isDisposed);const n=r.dependenciesGetStore();r.noValidate||(ar(t,"setDependencies"),function(e,t,r,n=$.maxDependencies){if(0===n)return;const o=e+t;if(o>=n)throw new Error(`[router.${"setDependencies"}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code.`)}(Object.keys(n.dependencies).length,Object.keys(t).length,0,n.limits.maxDependencies)),function(t,r){const n=[];for(const e in r)void 0!==r[e]&&(Object.hasOwn(t.dependencies,e)&&n.push(e),t.dependencies[e]=r[e]);n.length>0&&e.logger.warn("router.setDependencies","Overwritten:",n.join(", "))}(n,t)},remove:t=>{yr(r.isDisposed),r.noValidate||ir(t,"removeDependency");const n=r.dependenciesGetStore();Object.hasOwn(n.dependencies,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${g(t)}"`),delete n.dependencies[t]},reset:()=>{yr(r.isDisposed),r.dependenciesGetStore().dependencies=Object.create(null)},has:e=>(r.noValidate||ir(e,"hasDependency"),Object.hasOwn(r.dependenciesGetStore().dependencies,e))}},exports.getLifecycleApi=Tr,exports.getNavigator=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe}),exports.getPluginApi=function(e){const t=K(e);return{makeState:(e,r,n,o,i)=>(t.noValidate||function(e,t,r,n){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${g(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${g(n)}. Expected number.`)}(e,r,n,i),t.makeState(e,r,n,o,i)),buildState:(e,r)=>{t.noValidate||Tt(e,r,"buildState");const{name:n,params:o}=t.forwardState(e,r);return t.buildStateResolved(n,o)},forwardState:(e,r)=>(t.noValidate||Tt(e,r,"forwardState"),t.forwardState(e,r)),matchPath:e=>(t.noValidate||function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e),t.matchPath(e,t.getOptions())),setRootPath:e=>{fr(t.isDisposed),t.noValidate||function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}(e),t.setRootPath(e)},getRootPath:t.getRootPath,navigateToState:(e,r,n)=>(fr(t.isDisposed),t.noValidate||function(e,t,r){if(!e||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path)throw new TypeError("[router.navigateToState] Invalid toState: expected State object with name and path");if(void 0!==t&&(!t||"object"!=typeof t||"string"!=typeof t.name))throw new TypeError("[router.navigateToState] Invalid fromState: expected State object or undefined");if("object"!=typeof r||null===r)throw new TypeError(`[router.navigateToState] Invalid opts: expected NavigationOptions object, got ${g(r)}`)}(e,r,n),t.navigateToState(e,r,n)),addEventListener:(e,r)=>(fr(t.isDisposed),t.noValidate||function(e,t){if(function(e){if(!R.has(e))throw new Error(`Invalid event name: ${String(e)}`)}(e),"function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}(e,r),t.addEventListener(e,r)),buildNavigationState:(e,r={})=>{t.noValidate||Tt(e,r,"buildNavigationState");const{name:n,params:o}=t.forwardState(e,r),i=t.buildStateResolved(n,o);if(i)return t.makeState(i.name,i.params,t.buildPath(i.name,i.params),{params:i.meta})},getOptions:t.getOptions,getTree:t.getTree,getForwardState:()=>t.forwardState,setForwardState:e=>{t.forwardState=e}}},exports.getRoutesApi=function(t){const r=K(t),n=r.routeGetStore(),o=r.noValidate;return{add:(e,t)=>{wr(r.isDisposed);const i=Array.isArray(e)?e:[e],a=t?.parent;r.noValidate||(void 0!==a&&function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);m(e,"addRoute")}(a),St(i),n.treeOperations.validateRoutes(i,n.tree,n.config.forwardMap,a)),mr(n,o,i,a)},remove:t=>{wr(r.isDisposed),r.noValidate||function(e){m(e,"removeRoute")}(t);const i=function(t,r,n){if(r){const n=r===t,o=r.startsWith(`${t}.`);if(n||o)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}(t,r.getStateName(),r.isTransitioning());i&&(gr(n,o,t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`))},update:(t,i)=>{wr(r.isDisposed),r.noValidate||function(e,t){if(m(e,"updateRoute"),""===e)throw new ReferenceError("[router.updateRoute] Invalid name: empty string. Cannot update root node.");if(null===t)throw new TypeError("[real-router] updateRoute: updates must be an object, got null");if("object"!=typeof t||Array.isArray(t))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${g(t)}`)}(t,i);const{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u,canActivate:d,canDeactivate:l}=i;r.noValidate||function(e,t,r,n){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${g(e)}`);"function"==typeof e&&bt(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${g(t)}`);Et(r,"decodeParams"),Et(n,"encodeParams")}(a,s,c,u),r.isTransitioning()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),r.noValidate||Pt(t,a,e=>n.matcher.hasRoute(e),n.matcher,n.config),function(e,t,r,n){if(void 0!==n.forwardTo&&(e.resolvedForwardMap=function(e,t,r,n,o){return null===t?(delete r.forwardMap[e],delete r.forwardFnMap[e]):"string"==typeof t?(delete r.forwardFnMap[e],r.forwardMap[e]=t):(delete r.forwardMap[e],r.forwardFnMap[e]=t),o(r,n)}(r,n.forwardTo,e.config,t,jt)),void 0!==n.defaultParams&&(null===n.defaultParams?delete e.config.defaultParams[r]:e.config.defaultParams[r]=n.defaultParams),void 0!==n.decodeParams)if(null===n.decodeParams)delete e.config.decoders[r];else{const t=n.decodeParams;e.config.decoders[r]=e=>t(e)??e}if(void 0!==n.encodeParams)if(null===n.encodeParams)delete e.config.encoders[r];else{const t=n.encodeParams;e.config.encoders[r]=e=>t(e)??e}}(n,o,t,{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u}),void 0!==d&&(null===d?n.lifecycleNamespace.clearCanActivate(t):n.lifecycleNamespace.addCanActivate(t,d,o,!0)),void 0!==l&&(null===l?n.lifecycleNamespace.clearCanDeactivate(t):n.lifecycleNamespace.addCanDeactivate(t,l,o,!0))},clear:()=>{wr(r.isDisposed),At(r.isTransitioning())&&(n.treeOperations.resetStore(n),n.lifecycleNamespace.clearAll(),r.clearState())},has:e=>(r.noValidate||m(e,"hasRoute"),n.matcher.hasRoute(e)),get:e=>(r.noValidate||m(e,"getRoute"),vr(n,e)),getConfig:e=>function(e,t){if(e.matcher.hasRoute(t))return e.routeCustomFields[t]}(n,e),replace:e=>{wr(r.isDisposed);const i=Array.isArray(e)?e:[e];if(!At(r.isTransitioning()))return;r.noValidate||(St(i),n.treeOperations.validateRoutes(i));const a=t.getState()?.path;!function(e,t,r,n,o){Ct(e),e.lifecycleNamespace.clearDefinitionGuards();for(const t of r)e.definitions.push(ve(t));if(Lt(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,""),e.treeOperations.commitTreeChanges(e,t),void 0!==o){const e=n.matchPath(o,n.getOptions());e?n.setState(e):n.clearState()}}(n,o,i,r,a)}}};//# sourceMappingURL=index.js.map
1
+ "use strict";var e=require("@real-router/logger"),t=require("@real-router/fsm"),r={maxListeners:0,warnListeners:0,maxEventDepth:0},n=class extends Error{},o=class{#e=new Map;#t=null;#r=r;#n;#o;constructor(e){e?.limits&&(this.#r=e.limits),this.#n=e?.onListenerError??null,this.#o=e?.onListenerWarn??null}static validateCallback(e,t){if("function"!=typeof e)throw new TypeError(`Expected callback to be a function for event ${t}`)}setLimits(e){this.#r=e}on(e,t){const r=this.#i(e);if(r.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:n,warnListeners:o}=this.#r;if(0!==o&&r.size===o&&this.#o?.(e,o),0!==n&&r.size>=n)throw new Error(`Listener limit (${n}) reached for "${e}"`);return r.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,...t){const r=this.#e.get(e);r&&0!==r.size&&(0!==this.#r.maxEventDepth?this.#a(r,e,t):this.#s(r,e,t))}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#s(e,t,r){const n=[...e];for(const e of n)try{this.#c(e,r)}catch(e){this.#n?.(t,e)}}#c(e,t){switch(t.length){case 0:e();break;case 1:e(t[0]);break;case 2:e(t[0],t[1]);break;case 3:e(t[0],t[1],t[2]);break;default:Function.prototype.apply.call(e,void 0,t)}}#a(e,t,r){this.#t??=new Map;const o=this.#t,i=o.get(t)??0;if(i>=this.#r.maxEventDepth)throw new n(`Maximum recursion depth (${this.#r.maxEventDepth}) exceeded for event: ${t}`);try{o.set(t,i+1);const a=[...e];for(const e of a)try{this.#c(e,r)}catch(e){if(e instanceof n)throw e;this.#n?.(t,e)}}finally{o.set(t,o.get(t)-1)}}#i(e){const t=this.#e.get(e);if(t)return t;const r=new Set;return this.#e.set(e,r),r}},i=["replace","reload","force","forceDeactivate","redirected"],a=/\S/,s=/^[A-Z_a-z][\w-]*(?:\.[A-Z_a-z][\w-]*)*$/;function c(e,t){return new TypeError(`[router.${e}] ${t}`)}function u(e,t=new WeakSet){if(null==e)return!0;const r=typeof e;if("string"===r||"boolean"===r)return!0;if("number"===r)return Number.isFinite(e);if("function"===r||"symbol"===r)return!1;if(Array.isArray(e))return!t.has(e)&&(t.add(e),e.every(e=>u(e,t)));if("object"===r){if(t.has(e))return!1;t.add(e);const r=Object.getPrototypeOf(e);return(null===r||r===Object.prototype)&&Object.values(e).every(e=>u(e,t))}return!1}function d(e){if(null==e)return!0;const t=typeof e;return"string"===t||"boolean"===t||"number"===t&&Number.isFinite(e)}function l(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);if(null!==t&&t!==Object.prototype)return!1;let r=!1;for(const t in e){if(!Object.hasOwn(e,t))continue;const n=e[t];if(!d(n)){const e=typeof n;if("function"===e||"symbol"===e)return!1;r=!0;break}}return!r||u(e)}function f(e){return"string"==typeof e}function h(e){return"boolean"==typeof e}function p(e,t){return e in t}function m(e,t){if("string"!=typeof e)throw c(t,"Route name must be a string, got "+typeof e);if(""!==e){if(!a.test(e))throw c(t,"Route name cannot contain only whitespace");if(e.length>1e4)throw c(t,"Route name exceeds maximum length of 10000 characters. This is a technical safety limit.");if(!e.startsWith("@@")&&!s.test(e))throw c(t,`Invalid route name "${e}". 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 g(e){return null===e?"null":Array.isArray(e)?`array[${e.length}]`:"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function v(e,t){if(!function(e){return"object"==typeof e&&null!==e&&function(e){return function(e){return"string"==typeof e&&(""===e||!(e.length>1e4)&&(!!e.startsWith("@@")||s.test(e)))}(e.name)&&"string"==typeof e.path&&l(e.params)}(e)}(e))throw new TypeError(`[${t}] Invalid state structure: ${g(e)}. Expected State object with name, params, and path properties.`)}var w=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"}),y={UNKNOWN_ROUTE:"@@router/UNKNOWN_ROUTE"},S="onStart",T="onStop",b="onTransitionStart",E="onTransitionCancel",O="onTransitionSuccess",A="onTransitionError",P={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},R=new Set([P.ROUTER_START,P.TRANSITION_START,P.TRANSITION_SUCCESS,P.TRANSITION_ERROR,P.TRANSITION_CANCEL,P.ROUTER_STOP]),$={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},N={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}},D="IDLE",C="STARTING",j="READY",F="TRANSITIONING",x="DISPOSED",I="START",L="STARTED",M="NAVIGATE",k="COMPLETE",_="FAIL",U="CANCEL",B="STOP",G="DISPOSE",V={initial:D,context:null,transitions:{[D]:{[I]:C,[G]:x},[C]:{[L]:j,[_]:D},[j]:{[M]:F,[_]:j,[B]:D},[F]:{[M]:F,[k]:j,[U]:j,[_]:j},[x]:{}}},q=new WeakSet;function W(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)W(t);else for(const t in e)W(e[t])}function z(e){return e?(q.has(e)||(W(e),q.add(e)),e):e}function Q(e){return{warn:Math.floor(.2*e),error:Math.floor(.5*e)}}var H=new WeakMap;function K(e){const t=H.get(e);if(!t)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return t}var J={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0,noValidate:!1},Y={trailingSlash:["strict","never","always","preserve"],queryParamsMode:["default","strict","loose"],urlParamsEncoding:["default","uri","uriComponent","none"]},Z={arrayFormat:["none","brackets","index","comma"],booleanFormat:["none","string","empty-true"],nullFormat:["default","hidden"]};function X(e){Object.freeze(e);for(const t of Object.keys(e)){const r=e[t];r&&"object"==typeof r&&r.constructor===Object&&X(r)}return e}function ee(e,t){return"function"==typeof e?e(t):e}function te(e,t,r){if("function"==typeof t&&("defaultRoute"===e||"defaultParams"===e))return;const n=J[e];if(n&&"object"==typeof n)return function(e,t,r){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${r}] Invalid type for "${t}": expected plain object, got ${g(e)}`);for(const n in e)if(Object.getOwnPropertyDescriptor(e,n)?.get)throw new TypeError(`[router.${r}] Getters not allowed in "${t}": "${n}"`)}(t,e,r),void("queryParams"===e&&function(e,t){for(const r in e){if(!p(r,Z)){const e=Object.keys(Z).map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Unknown queryParams key: "${r}". Valid keys: ${e}`)}const n=e[r],o=Z[r];if(!o.includes(n)){const e=o.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${t}] Invalid value for queryParams.${r}: expected one of ${e}, got "${String(n)}"`)}}}(t,r));if(typeof t!=typeof n)throw new TypeError(`[router.${r}] Invalid type for "${e}": expected ${typeof n}, got ${typeof t}`);e in Y&&function(e,t,r){const n=Y[e];if(!n.includes(t)){const o=n.map(e=>`"${e}"`).join(", ");throw new TypeError(`[router.${r}] Invalid value for "${e}": expected one of ${o}, got "${String(t)}"`)}}(e,t,r)}function re(e,t,r){if("limits"===e)return void 0!==t&&function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}]: invalid limits: expected plain object, got ${typeof e}`);for(const[r,n]of Object.entries(e)){if(!Object.hasOwn(N,r))throw new TypeError(`[router.${t}]: unknown limit: "${r}"`);void 0!==n&&ne(r,n,t)}}(t,r),!0;throw new TypeError(`[router.${r}] Unknown option: "${e}"`)}function ne(e,t,r){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError(`[router.${r}]: limit "${e}" must be an integer, got ${String(t)}`);const n=N[e];if(t<n.min||t>n.max)throw new RangeError(`[router.${r}]: limit "${e}" must be between ${n.min} and ${n.max}, got ${t}`)}var oe=class{#u;constructor(e={}){this.#u=X({...J,...e})}static validateOptions(e,t){!function(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid options: expected plain object, got ${g(e)}`);for(const[r,n]of Object.entries(e))p(r,J)?void 0!==n&&te(r,n,t):re(r,n,t)}(e,t)}get(){return this.#u}};function ie(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&e.length===t.length&&e.every((e,r)=>ie(e,t[r]))}var ae=class{#d=0;#l=void 0;#f=void 0;#h;#p=new Map;static validateAreStatesEqualArgs(e,t,r){if(null!=e&&v(e,"areStatesEqual"),null!=t&&v(t,"areStatesEqual"),void 0!==r&&"boolean"!=typeof r)throw new TypeError(`[router.areStatesEqual] Invalid ignoreQueryParams: ${g(r)}. Expected boolean.`)}get(){return this.#l}set(e){this.#f=this.#l,this.#l=e?z(e):void 0}getPrevious(){return this.#f}reset(){this.#l=void 0,this.#f=void 0,this.#p.clear(),this.#d=0}setDependencies(e){this.#h=e}makeState(e,t,r,n,o){const i=n?{...n,id:o??++this.#d,params:n.params}:void 0,a=this.#h.getDefaultParams();let s;return s=Object.hasOwn(a,e)?{...a[e],...t}:t?{...t}:{},z({name:e,params:s,path:r??this.#h.buildPath(e,t),meta:i})}makeNotFoundState(e){return this.makeState(y.UNKNOWN_ROUTE,{path:e},e,{params:{}})}areStatesEqual(e,t,r=!0){if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(r){const r=e.meta?.params??t.meta?.params;return(r?function(e){const t=[];for(const r in e){const n=e[r];for(const e in n)"url"===n[e]&&t.push(e)}return t}(r):this.#m(e.name)).every(r=>ie(e.params[r],t.params[r]))}const n=Object.keys(e.params),o=Object.keys(t.params);return n.length===o.length&&n.every(r=>r in t.params&&ie(e.params[r],t.params[r]))}#m(e){const t=this.#p.get(e);if(void 0!==t)return t;const r=this.#h.getUrlParams(e);return this.#p.set(e,r),r}},se={[S]:P.ROUTER_START,[T]:P.ROUTER_STOP,[O]:P.TRANSITION_SUCCESS,[b]:P.TRANSITION_START,[A]:P.TRANSITION_ERROR,[E]:P.TRANSITION_CANCEL},ce=Object.keys(se).filter(e=>p(e,se)),ue="router.usePlugin",de=class t{#g=new Set;#v=new Set;#w;#h;#y=$;static validateUsePluginArgs(e){!function(e){for(const[t,r]of e.entries())if("function"!=typeof r)throw new TypeError(`[router.usePlugin] Expected plugin factory function at index ${t}, got ${g(r)}`)}(e)}static validatePlugin(e){!function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError(`[router.usePlugin] Plugin factory must return an object, got ${g(e)}`);if("function"==typeof e.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.");for(const t in e)if("teardown"!==t&&!p(t,se))throw new TypeError(`[router.usePlugin] Unknown property '${t}'. Plugin must only contain event handlers and optional teardown.`)}(e)}static validatePluginLimit(e,t,r){!function(e,t,r=$.maxPlugins){if(0!==r&&e+t>r)throw new Error(`[router.usePlugin] Plugin limit exceeded (${r}). Current: ${e}, Attempting to add: ${t}. This indicates an architectural problem. Consider consolidating plugins.`)}(e,t,r)}static validateNoDuplicatePlugins(e,t){for(const r of e)if(t(r))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}count(){return this.#g.size}use(...t){if(this.#S(t.length),1===t.length){const r=t[0],n=this.#T(r);this.#g.add(r);let o=!1;const i=()=>{if(!o){o=!0,this.#g.delete(r),this.#v.delete(i);try{n()}catch(t){e.logger.error(ue,"Error during cleanup:",t)}}};return this.#v.add(i),i}const r=this.#b(t),n=[];try{for(const e of r){const t=this.#T(e);n.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(ue,"Cleanup error:",t)}throw t}for(const{factory:e}of n)this.#g.add(e);let o=!1;const i=()=>{if(!o){o=!0,this.#v.delete(i);for(const{factory:e}of n)this.#g.delete(e);for(const{cleanup:t}of n)try{t()}catch(t){e.logger.error(ue,"Error during cleanup:",t)}}};return this.#v.add(i),i}getAll(){return[...this.#g]}has(e){return this.#g.has(e)}disposeAll(){for(const e of this.#v)e();this.#g.clear(),this.#v.clear()}#S(t){const r=this.#y.maxPlugins;if(0===r)return;const n=t+this.#g.size,{warn:o,error:i}=Q(r);n>=i?e.logger.error(ue,`${n} plugins registered! This is excessive and will impact performance. Hard limit at ${r}.`):n>=o&&e.logger.warn(ue,`${n} plugins registered. Consider if all are necessary.`)}#b(t){const r=new Set;for(const n of t)r.has(n)?e.logger.warn(ue,"Duplicate factory in batch, will be registered once"):r.add(n);return r}#T(r){const n=r(this.#w,this.#h.getDependency);t.validatePlugin(n),Object.freeze(n);const o=[];for(const t of ce)t in n&&("function"==typeof n[t]?(o.push(this.#h.addEventListener(se[t],n[t])),"onStart"===t&&this.#h.canNavigate()&&e.logger.warn(ue,"Router already started, onStart will not be called")):e.logger.warn(ue,`Property '${t}' is not a function, skipping`));return()=>{for(const e of o)e();"function"==typeof n.teardown&&n.teardown()}}};function le(e,t){if(!h(e)&&"function"!=typeof e)throw new TypeError(`[router.${t}] Handler must be a boolean or factory function, got ${g(e)}`)}function fe(e,t,r){if(e)throw new Error(`[router.${r}] Cannot modify route "${t}" during its own registration`)}function he(e,t,r=$.maxLifecycleHandlers){if(0!==r&&e>=r)throw new Error(`[router.${t}] Lifecycle handler limit exceeded (${r}). This indicates too many routes with individual handlers. Consider using plugins for cross-cutting concerns.`)}var pe=class{#E=new Map;#O=new Map;#A=new Map;#P=new Map;#R=new Set;#$=new Set;#N=new Set;#w;#h;#y=$;setRouter(e){this.#w=e}setDependencies(e){this.#h=e}setLimits(e){this.#y=e}addCanActivate(e,t,r,n=!1){n?this.#$.add(e):this.#$.delete(e),r||fe(this.#R.has(e),e,"addActivateGuard");const o=this.#O.has(e);o||r||he(this.#O.size+1,"addActivateGuard",this.#y.maxLifecycleHandlers),this.#D("activate",e,t,this.#O,this.#P,"canActivate",o)}addCanDeactivate(e,t,r,n=!1){n?this.#N.add(e):this.#N.delete(e),r||fe(this.#R.has(e),e,"addDeactivateGuard");const o=this.#E.has(e);o||r||he(this.#E.size+1,"addDeactivateGuard",this.#y.maxLifecycleHandlers),this.#D("deactivate",e,t,this.#E,this.#A,"canDeactivate",o)}clearCanActivate(e){this.#O.delete(e),this.#P.delete(e),this.#$.delete(e)}clearCanDeactivate(e){this.#E.delete(e),this.#A.delete(e),this.#N.delete(e)}clearAll(){this.#O.clear(),this.#P.clear(),this.#E.clear(),this.#A.clear(),this.#$.clear(),this.#N.clear()}clearDefinitionGuards(){for(const e of this.#$)this.#O.delete(e),this.#P.delete(e);for(const e of this.#N)this.#E.delete(e),this.#A.delete(e);this.#$.clear(),this.#N.clear()}getFactories(){const e={},t={};for(const[t,r]of this.#E)e[t]=r;for(const[e,r]of this.#O)t[e]=r;return[e,t]}getFunctions(){return[this.#A,this.#P]}checkActivateGuardSync(e,t,r){return this.#C(this.#P,e,t,r,"checkActivateGuardSync")}checkDeactivateGuardSync(e,t,r){return this.#C(this.#A,e,t,r,"checkDeactivateGuardSync")}#D(t,r,n,o,i,a,s){s?e.logger.warn(`router.${a}`,`Overwriting existing ${t} handler for route "${r}"`):this.#S(o.size+1,a);const c=h(n)?function(e){const t=()=>e;return()=>t}(n):n;o.set(r,c),this.#R.add(r);try{const e=c(this.#w,this.#h.getDependency);if("function"!=typeof e)throw new TypeError(`[router.${a}] Factory must return a function, got ${g(e)}`);i.set(r,e)}catch(e){throw o.delete(r),e}finally{this.#R.delete(r)}}#C(t,r,n,o,i){const a=t.get(r);if(!a)return!0;try{const t=a(n,o);return"boolean"==typeof t?t:(e.logger.warn(`router.${i}`,`Guard for "${r}" returned a Promise. Sync check cannot resolve async guards — returning false.`),!1)}catch{return!1}}#S(t,r){const n=this.#y.maxLifecycleHandlers;if(0===n)return;const{warn:o,error:i}=Q(n);t>=i?e.logger.error(`router.${r}`,`${t} lifecycle handlers registered! This is excessive. Hard limit at ${n}.`):t>=o&&e.logger.warn(`router.${r}`,`${t} lifecycle handlers registered. Consider consolidating logic.`)}},me=new Set;function ge(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function ve(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>ve(e))),t}function we(e,t,r=""){for(let n=0;n<e.length;n++){const o=e[n],i=r?`${r}.${o.name}`:o.name;if(i===t)return e.splice(n,1),!0;if(o.children&&t.startsWith(`${i}.`)&&we(o.children,t,i))return!0}return!1}function ye(e,t){for(const r of Object.keys(e))t(r)&&delete e[r]}function Se(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var Te=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,be=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,Ee=/\?(.+)$/,Oe=/[^\w!$'()*+,.:;|~-]/gu,Ae=/[^\w!$'()*+,.:;|~-]/u,Pe={default:e=>Ae.test(e)?e.replaceAll(Oe,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},Re={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function $e(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function Ne(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function De(e){const t={};if(0===e.length)return t;const r=e.split("&");for(const e of r){const r=e.indexOf("=");-1===r?t[e]="":t[e.slice(0,r)]=e.slice(r+1)}return t}function Ce(e){const t=[];for(const r of Object.keys(e)){const n=e[r],o=encodeURIComponent(r);t.push(""===n?o:`${o}=${encodeURIComponent(String(n))}`)}return t.join("&")}function je(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Fe(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const r=e.codePointAt(t+1)??0,n=e.codePointAt(t+2)??0;if(!je(r)||!je(n))return!1;t+=3}else t++;return!0}var xe=/<[^>]*>/g;function Ie(e,t,r,n,o){const i=""===t.fullName;i||n.push(t);const a=t.absolute,s=t.paramMeta.pathPattern,c=a&&s.startsWith("~")?s.slice(1):s,u=(a?c:s).replaceAll(xe,""),d=a?u:(f=u,""===(l=r)?f:""===f?l:l+f);var l,f;let h=o;i||(h=function(e,t,r,n,o,i){const a=(g=n,Ne(r)===Ne(g)),s=Object.freeze([...o]),c=function(e){const t={};for(const r of e)t[r.fullName]=r.paramTypeMap;return Object.freeze(t)}(s),u=Ne(r),d=function(e,t){const r=[];e.length>0&&r.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&r.push(...e.paramMeta.queryParams);return r}(e.rootQueryParams,o),l=function(e){const t=new Map;for(const r of e)for(const[e,n]of r.paramMeta.constraintPatterns)t.set(e,n);return t}(o),f=a?Ne(n):u,{buildStaticParts:h,buildParamSlots:p}=function(e,t,r){const n=new Set,o=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)n.add(t);for(const t of e.paramMeta.spatParams)o.add(t)}if(0===n.size)return{buildStaticParts:[e],buildParamSlots:[]};const i=[],a=[],s=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=s.exec(e));){const t=c[1],n="?"===c[2];i.push(e.slice(u,c.index));const s=o.has(t);a.push({paramName:t,isOptional:n,encoder:s?e=>{const t=Pe[r],n=e.split("/");let o=t(n[0]);for(let e=1;e<n.length;e++)o+=`/${t(n[e])}`;return o}:Pe[r]}),u=c.index+c[0].length}return i.push(e.slice(u)),{buildStaticParts:i,buildParamSlots:a}}(f,a?o.slice(0,-1):o,e.options.urlParamsEncoding),m={name:t.fullName,parent:i,depth:o.length-1,matchSegments:s,meta:c,declaredQueryParams:d,declaredQueryParamsSet:new Set(d),hasTrailingSlash:r.length>1&&r.endsWith("/"),constraintPatterns:l,hasConstraints:l.size>0,buildStaticParts:h,buildParamSlots:p,buildParamNamesSet:new Set(p.map(e=>e.paramName))};var g;return e.routesByName.set(t.fullName,m),e.segmentsByName.set(t.fullName,s),e.metaByName.set(t.fullName,c),a?function(e,t,r){var n,o;n=t,(function(e,t,r){const n=Ne(r);if("/"===n||""===n)return t;let o=t,i=1;const a=n.length;for(;i<=a;){const t=n.indexOf("/",i),r=-1===t?a:t;if(r<=i)break;o=Me(e,o,n.slice(i,r)),i=r+1}return o}(o=e,o.root,r)).slashChildRoute=n;const i=Ne(r),a=e.options.caseSensitive?i:i.toLowerCase();e.staticCache.has(a)&&e.staticCache.set(a,t)}(e,m,n):function(e,t,r,n,o){if(function(e,t,r){const n=Ne(r);"/"!==n?Le(e,e.root,n,1,t):e.root.route=t}(e,t,r),0===o.paramMeta.urlParams.length){const r=e.options.caseSensitive?n:n.toLowerCase();e.staticCache.set(r,t)}}(e,m,r,u,t),m}(e,t,d,a?"":r,n,o));for(const r of t.children.values())Ie(e,r,d,n,h);i||n.pop()}function Le(e,t,r,n,o){const i=r.length;for(;n<=i;){const a=r.indexOf("/",n),s=-1===a?i:a,c=r.slice(n,s);if(c.endsWith("?")){const n=c.slice(1).replaceAll(xe,"").replace(/\?$/,"");return t.paramChild??={node:$e(),name:n},Le(e,t.paramChild.node,r,s+1,o),void(s>=i?t.route??=o:Le(e,t,r,s+1,o))}t=Me(e,t,c),n=s+1}t.route=o}function Me(e,t,r){if(r.startsWith("*")){const e=r.slice(1);return t.splatChild??={node:$e(),name:e},t.splatChild.node}if(r.startsWith(":")){const e=r.slice(1).replaceAll(xe,"").replace(/\?$/,"");return t.paramChild??={node:$e(),name:e},t.paramChild.node}const n=e.options.caseSensitive?r:r.toLowerCase();return n in t.staticChildren||(t.staticChildren[n]=$e()),t.staticChildren[n]}var ke=/[\u0080-\uFFFF]/,_e=class{get options(){return this.#e}#e;#t=$e();#o=new Map;#i=new Map;#r=new Map;#a=new Map;#n="";#j=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??De,buildQueryString:e?.buildQueryString??Ce}}registerTree(e){this.#j=e.paramMeta.queryParams,Ie({root:this.#t,options:this.#e,routesByName:this.#o,segmentsByName:this.#i,metaByName:this.#r,staticCache:this.#a,rootQueryParams:this.#j},e,"",[],null)}match(e){const t=this.#s(e);if(!t)return;const[r,n,o]=t,i=this.#e.caseSensitive?n:n.toLowerCase(),a=this.#a.get(i);if(a){if(this.#e.strictTrailingSlash&&!this.#c(r,a))return;return this.#F(a,{},o)}const s={},c=this.#x(n,s);return!c||this.#e.strictTrailingSlash&&!this.#c(r,c)||c.hasConstraints&&!this.#I(s,c)||!this.#L(s)?void 0:this.#F(c,s,o)}buildPath(e,t,r){const n=this.#o.get(e);if(!n)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);n.hasConstraints&&t&&this.#M(n,e,t);const o=this.#k(n,t),i=this.#_(o,r?.trailingSlash),a=this.#U(n,t,r?.queryParamsMode);return i+(a?`?${a}`:"")}getSegmentsByName(e){return this.#i.get(e)}getMetaByName(e){return this.#r.get(e)}hasRoute(e){return this.#o.has(e)}setRootPath(e){this.#n=e}#M(e,t,r){for(const[n,o]of e.constraintPatterns){const e=r[n];if(null!=e){const r="object"==typeof e?JSON.stringify(e):String(e);if(!o.pattern.test(r))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${n}' value '${r}' does not match constraint '${o.constraint}'`)}}}#k(e,t){const r=e.buildStaticParts,n=e.buildParamSlots;if(0===n.length)return this.#n+r[0];let o=this.#n+r[0];for(const[e,i]of n.entries()){const n=t?.[i.paramName];if(null==n){if(!i.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${i.paramName}'`);o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1)),o+=r[e+1];continue}const a="object"==typeof n?JSON.stringify(n):String(n);o+=i.encoder(a)+r[e+1]}return o}#_(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#U(e,t,r){if(!t)return"";const n={};let o=!1;for(const r of e.declaredQueryParams)r in t&&(n[r]=t[r],o=!0);if("loose"===r)for(const r in t)!Object.hasOwn(t,r)||e.declaredQueryParamsSet.has(r)||e.buildParamNamesSet.has(r)||(n[r]=t[r],o=!0);return o?this.#e.buildQueryString(n):""}#s(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ke.test(e))return;if(this.#n.length>0){if(!e.startsWith(this.#n))return;e=e.slice(this.#n.length)||"/"}const r=e.indexOf("?"),n=-1===r?e:e.slice(0,r),o=-1===r?void 0:e.slice(r+1);return n.includes("//")?void 0:[n,Ne(n),o]}#F(e,t,r){if(void 0!==r){const n=this.#e.parseQueryString(r);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(n))if(!t.has(e))return}for(const e of Object.keys(n))t[e]=n[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#c(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#x(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#B(this.#t,e,1,t)}#B(e,t,r,n){let o=e;const i=t.length;for(;r<=i;){const e=t.indexOf("/",r),a=-1===e?i:e,s=t.slice(r,a),c=this.#e.caseSensitive?s:s.toLowerCase();let u;if(c in o.staticChildren)u=o.staticChildren[c];else{if(!o.paramChild){if(o.splatChild){const e={},i=this.#B(o.splatChild.node,t,r,e);return i?(Object.assign(n,e),i):(n[o.splatChild.name]=t.slice(r),o.splatChild.node.route)}return}u=o.paramChild.node,n[o.paramChild.name]=s}o=u,r=a+1}return o.slashChildRoute??o.route}#L(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const r=Re[t];for(const t in e){const n=e[t];if(n.includes("%")){if(!Fe(n))return!1;e[t]=r(n)}}return!0}#I(e,t){for(const[r,n]of t.constraintPatterns)if(!n.pattern.test(e[r]))return!1;return!0}},Ue=e=>{const t=e.indexOf("%"),r=e.indexOf("+");if(-1===t&&-1===r)return e;const n=-1===r?e:e.split("+").join(" ");return-1===t?n:decodeURIComponent(n)},Be=e=>{const t=typeof e;if("string"!==t&&"number"!==t&&"boolean"!==t)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===t&&null===e?"null":t}`);return encodeURIComponent(e)},Ge={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${Be(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${Be(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,r)=>`${e}[${r}]=${Be(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>Be(e)).join(",")}`}},Ve={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},string:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>"true"===e||"false"!==e&&null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:e=>e}},qe={default:{encode:e=>e},hidden:{encode:()=>""}},We=(e,t,r)=>({boolean:Ve[t],null:qe[r],array:Ge[e]}),ze={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Ve.none,null:qe.default,array:Ge.none}},Qe=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return ze;const t=e.arrayFormat??"none",r=e.booleanFormat??"none",n=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:r,nullFormat:n,strategies:We(t,r,n)}},He=e=>encodeURIComponent(e),Ke=(e,t,r)=>{const n=He(e);switch(typeof t){case"string":case"number":default:return`${n}=${He(t)}`;case"boolean":return r.strategies.boolean.encode(n,t);case"object":return null===t?r.strategies.null.encode(n):Array.isArray(t)?r.strategies.array.encodeArray(n,t):`${n}=${He(t)}`}};function Je(e,t,r,n,o){const i=e.indexOf("=",t),a=-1!==i&&i<r,s=e.slice(t,a?i:r),{name:c,hasBrackets:u}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(s);var d,l,f,h,p;!function(e,t,r,n){const o=e[t];void 0===o?e[t]=n?[r]:r:Array.isArray(o)?o.push(r):e[t]=[o,r]}(n,Ue(c),(d=e,l=i,f=r,h=a,p=o,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const r=t.boolean.decodeRaw(e);if(null!==r)return r;const n=Ue(e);return t.boolean.decodeValue(n)})(h?d.slice(l+1,f):void 0,p):h?Ue(d.slice(l+1,f)):null),u)}function Ye(e,t){const r=e.path,n=r.startsWith("~"),o=n?r.slice(1):r,i={name:e.name,path:o,absolute:n,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=Ye(t,i);i.children.push(e)}return i}function Ze(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function Xe(e){const t=new Map;for(const r of e)t.set(r.name,r);return t}function et(e,t,r){const n=function(e){const t=[],r=[],n=[],o={},i=new Map,a=e.replaceAll(be,"$1"),s=Ee.exec(a);if(null!==s){const t=s[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(r.push(t),o[t]="query")}e=e.slice(0,s.index)}let c;for(;null!==(c=Te.exec(e));){const e=c[2],r=c[3];if("*"===c[1])n.push(e),t.push(e),o[e]="url";else if(t.push(e),o[e]="url",r){const t=`^${Se(r)}$`;i.set(e,{pattern:new RegExp(t),constraint:r})}}return{urlParams:t,queryParams:r,spatParams:n,paramTypeMap:o,constraintPatterns:i,pathPattern:e}}(e.path),o=function(e){const t={};for(const r of e.urlParams)t[r]="url";for(const r of e.queryParams)t[r]="query";return t}(n),i={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:n,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:o};var a;i.fullName=(a=i,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:s,nonAbsoluteChildren:c}=function(e,t,r){const n=[],o=[];for(const i of e){const e=et(i,t,r);n.push(e),e.absolute||o.push(e)}return{childrenMap:Xe(n),nonAbsoluteChildren:o}}(e.children,i,r);return i.children=s,i.nonAbsoluteChildren=c,i.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;const o=[];let i=e.parent;for(;i?.path;)o.unshift(i),i=i.parent;let a="";for(const e of o){const{urlParams:t,queryParams:r,spatParams:n}=e.paramMeta;if(t.length>0||r.length>0||n.length>0)return null;a=e.absolute?e.path:Ze(a,e.path)}return e.absolute?e.path:Ze(a,e.path)}(i),r&&(Object.freeze(c),Object.freeze(o),Object.freeze(i.children),Object.freeze(i)),i}function tt(e,t,r,n){return function(e,t){const r=[];return{add(e){return r.push(e),this},addMany(e){return r.push(...e),this},build:n=>function(e,t=!0){return et(e,null,t)}(function(e,t,r){const n=Ye({name:e,path:t},null);for(const e of r){const t=Ye(e,n);n.children.push(t)}return n}(e,t,r),!n?.skipFreeze)}}(e,t).addMany(r).build(n)}function rt(e){const t={name:e.name,path:e.absolute?`~${e.path}`:e.path};return e.children.size>0&&(t.children=[...e.children.values()].map(e=>rt(e))),t}function nt(e){const t=e?.queryParams;return new _e({...void 0===e?.caseSensitive?void 0:{caseSensitive:e.caseSensitive},...void 0===e?.strictTrailingSlash?void 0:{strictTrailingSlash:e.strictTrailingSlash},...void 0===e?.strictQueryParams?void 0:{strictQueryParams:e.strictQueryParams},...void 0===e?.urlParamsEncoding?void 0:{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>((e,t)=>{const r=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===r||"?"===r)return{};if(!t)return function(e){const t={};return function(e,t){let r=0;const n=e.length;for(;r<n;){let o=e.indexOf("&",r);-1===o&&(o=n),Je(e,r,o,t),r=o+1}}(e,t),t}(r);const n=Qe(t),o={};let i=0;const a=r.length;for(;i<a;){let e=r.indexOf("&",i);-1===e&&(e=a),Je(r,i,e,o,n.strategies),i=e+1}return o})(e,t),buildQueryString:e=>((e,t)=>{const r=Object.keys(e);if(0===r.length)return"";const n=Qe(t),o=[];for(const t of r){const r=e[t];if(void 0===r)continue;const i=Ke(t,r,n);i&&o.push(i)}return o.join("&")})(e,t)})}function ot(e,t){return new TypeError(`[router.${e}] ${t}`)}var it=/^[A-Z_a-z][\w-]*$/,at=/\S/;function st(e){return null===e?"null":"object"==typeof e?"constructor"in e&&"Object"!==e.constructor.name?e.constructor.name:"object":typeof e}function ct(e,t){if(!t.includes("."))return e.children.get(t);let r=e;for(const e of t.split("."))if(r=r.children.get(e),!r)return;return r}function ut(e,t,r,n="",o,i){!function(e,t){if(!e||"object"!=typeof e)throw new TypeError(`[router.${t}] Route must be an object, got ${st(e)}`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&null!==r)throw new TypeError(`[router.${t}] Route must be a plain object, got ${st(e)}`);if(function(e){for(const t of Object.keys(e)){const r=Object.getOwnPropertyDescriptor(e,t);if(r&&(r.get||r.set))return!0}return!1}(e))throw new TypeError(`[router.${t}] Route must not have getters or setters`)}(e,t);const a=e;!function(e,t){if("string"!=typeof e.name)throw new TypeError(`[router.${t}] Route name must be a string, got ${st(e.name)}`);const r=e.name;if(""===r)throw new TypeError(`[router.${t}] Route name cannot be empty`);if(!at.test(r))throw new TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(r.length>1e4)throw new TypeError(`[router.${t}] Route name exceeds maximum length of 10000 characters`);if(!r.startsWith("@@")){if(r.includes("."))throw new TypeError(`[router.${t}] Route name "${r}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!it.test(r))throw new TypeError(`[router.${t}] Invalid route name "${r}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}(a,t),function(e,t,r,n){if("string"!=typeof e){let t;throw t=null===e?"null":Array.isArray(e)?"array":typeof e,ot(r,`Route path must be a string, got ${t}`)}if(""===e)return;if(/\s/.test(e))throw ot(r,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw ot(r,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes("//"))throw ot(r,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);const o=n&&Object.values(n.paramTypeMap).includes("url");if(e.startsWith("~")&&o)throw ot(r,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}(a.path,a.name,t,r),function(e,t){if(void 0!==e.encodeParams&&"function"!=typeof e.encodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}(a,t),function(e,t){if(void 0!==e.decodeParams&&"function"!=typeof e.decodeParams)throw new TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}(a,t);const s=a.name,c=n?`${n}.${s}`:s;r&&c&&function(e,t,r){if(ct(e,t))throw new Error(`[router.${r}] Route "${t}" already exists`)}(r,c,t),o&&function(e,t,r){if(e.has(t))throw new Error(`[router.${r}] Duplicate route "${t}" in batch`);e.add(t)}(o,c,t);const u=a.path,d=n;if(r&&function(e,t,r,n){const o=""===t?e:ct(e,t);if(o)for(const e of o.children.values())if(e.path===r)throw new Error(`[router.${n}] Path "${r}" is already defined`)}(r,d,u,t),i&&function(e,t,r,n){const o=e.get(t);if(o?.has(r))throw new Error(`[router.${n}] Path "${r}" is already defined`);o?o.add(r):e.set(t,new Set([r]))}(i,d,u,t),void 0!==a.children){if(!Array.isArray(a.children))throw new TypeError(`[router.${t}] Route "${s}" children must be an array, got ${st(a.children)}`);for(const e of a.children)ut(e,t,r,c,o,i)}}function dt(e,t){if(void 0!==e.canActivate&&"function"!=typeof e.canActivate)throw new TypeError(`[router.addRoute] canActivate must be a function for route "${t}", got ${g(e.canActivate)}`);if(void 0!==e.canDeactivate&&"function"!=typeof e.canDeactivate)throw new TypeError(`[router.addRoute] canDeactivate must be a function for route "${t}", got ${g(e.canDeactivate)}`);if(void 0!==e.defaultParams){const r=e.defaultParams;if(null===r||"object"!=typeof r||Array.isArray(r))throw new TypeError(`[router.addRoute] defaultParams must be an object for route "${t}", got ${g(e.defaultParams)}`)}if("AsyncFunction"===e.decodeParams?.constructor.name)throw new TypeError(`[router.addRoute] decodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if("AsyncFunction"===e.encodeParams?.constructor.name)throw new TypeError(`[router.addRoute] encodeParams cannot be async for route "${t}". Async functions break matchPath/buildPath.`);if(function(e,t){if(void 0!==e&&"function"==typeof e){const r="AsyncFunction"===e.constructor.name,n=e.toString().includes("__awaiter");if(r||n)throw new TypeError(`[router.addRoute] forwardTo callback cannot be async for route "${t}". Async functions break matchPath/buildPath.`)}}(e.forwardTo,t),e.children)for(const r of e.children)dt(r,`${t}.${r.name}`)}function lt(e){const t=new Set,r=/[*:]([A-Z_a-z]\w*)/g;let n;for(;null!==(n=r.exec(e));)t.add(n[1]);return t}function ft(e){const t=new Set;for(const r of e)for(const e of lt(r))t.add(e);return t}function ht(e,t,r="",n=[]){for(const o of e){const e=r?`${r}.${o.name}`:o.name,i=[...n,o.path];if(e===t)return i;if(o.children&&t.startsWith(`${e}.`))return ht(o.children,t,e,i)}throw new Error(`[internal] collectPathsToRoute: route "${t}" not found`)}function pt(e,t=""){const r=new Set;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(r.add(e),n.children)for(const t of pt(n.children,e))r.add(t)}return r}function mt(e,t=""){const r=new Map;for(const n of e){const e=t?`${t}.${n.name}`:n.name;if(n.forwardTo&&"string"==typeof n.forwardTo&&r.set(e,n.forwardTo),n.children)for(const[t,o]of mt(n.children,e))r.set(t,o)}return r}function gt(e,t,r,n){return t?function(e){const t=new Set;for(const r of e){for(const e of r.paramMeta.urlParams)t.add(e);for(const e of r.paramMeta.spatParams)t.add(e)}return t}(function(e,t){const r=[],n=t.includes(".")?t.split("."):[t];""!==e.path&&r.push(e);let o=e;for(const e of n){const t=o.children.get(e);if(!t)return null;r.push(t),o=t}return r}(r,e)):ft(ht(n,e))}function vt(e,t,r,n,o){const i=function(e,t){const r=t.split(".");let n=e;for(const e of r)if(n=n.children.get(e),!n)return!1;return!0}(o,t),a=n.has(t);if(!i&&!a)throw new Error(`[router.addRoute] forwardTo target "${t}" does not exist for route "${e}"`);const s=ft(ht(r,e)),c=[...gt(t,i,o,r)].filter(e=>!s.has(e));if(c.length>0)throw new Error(`[router.addRoute] forwardTo target "${t}" requires params [${c.join(", ")}] that are not available in source route "${e}"`)}function wt(e,t,r=100){const n=new Set,o=[e];let i=e;for(;t[i];){const e=t[i];if(n.has(e)){const t=o.indexOf(e),r=[...o.slice(t),e];throw new Error(`Circular forwardTo: ${r.join(" → ")}`)}if(n.add(i),o.push(e),i=e,o.length>r)throw new Error(`forwardTo chain exceeds maximum depth (${r}): ${o.join(" → ")}`)}return i}function yt(e,t,r){const n=pt(e),o=mt(e),i={...t};for(const[e,t]of o)i[e]=t;for(const[t,i]of o)vt(t,i,e,n,r);for(const e of Object.keys(i))wt(e,i)}function St(e){for(const t of e){if(null===t||"object"!=typeof t||Array.isArray(t))throw new TypeError(`[router.addRoute] Route must be an object, got ${g(t)}`);dt(t,t.name)}}function Tt(e,t,r){if(!f(e))throw new TypeError(`[router.${r}] Invalid routeName: ${g(e)}. Expected string.`);if(!l(t))throw new TypeError(`[router.${r}] Invalid routeParams: ${g(t)}. Expected plain object.`)}function bt(e,t){if("AsyncFunction"===e.constructor.name||e.toString().includes("__awaiter"))throw new TypeError(`[real-router] updateRoute: ${t} cannot be an async function`)}function Et(e,t){if(null!=e){if("function"!=typeof e)throw new TypeError(`[real-router] updateRoute: ${t} must be a function or null, got ${typeof e}`);bt(e,t)}}function Ot(e,t,r,n){if(n&&t){let e=t;for(const t of n.split("."))if(e=e.children.get(t),!e)throw new Error(`[router.addRoute] Parent route "${n}" does not exist`)}const o=new Set,i=new Map;for(const r of e)ut(r,"addRoute",t,n??"",o,i);t&&r&&yt(e,r,t)}function At(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}function Pt(e,t,r,n,o){if(!r(e))throw new ReferenceError(`[real-router] updateRoute: route "${e}" does not exist`);if(null!=t&&"string"==typeof t){if(!r(t))throw new Error(`[real-router] updateRoute: forwardTo target "${t}" does not exist`);(function(e,t,r){const n=r.getSegmentsByName(e),o=r.getSegmentsByName(t),i=function(e){const t=new Set;for(const r of e)for(const e of r.paramMeta.urlParams)t.add(e);return t}(n),a=[];for(const e of o)for(const t of e.paramMeta.urlParams)a.push(t);const s=a.filter(e=>!i.has(e));if(s.length>0)throw new Error(`[real-router] forwardTo target "${t}" requires params [${s.join(", ")}] that are not available in source route "${e}"`)})(e,t,n),function(e,t,r){wt(e,{...r.forwardMap,[e]:t})}(e,t,o)}}function Rt(e,t,r){const n=tt("",t,e),o=nt(r);return o.registerTree(n),{tree:n,matcher:o}}function $t(e,t){const r=Rt(e.definitions,e.rootPath,e.matcherOptions);e.tree=r.tree,e.matcher=r.matcher,e.resolvedForwardMap=jt(e.config,t)}function Nt(e){const t=Rt(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher}function Dt(e){Ct(e),Nt(e)}function Ct(e){e.definitions.length=0,Object.assign(e.config,ge()),e.resolvedForwardMap=Object.create(null),e.routeCustomFields=Object.create(null)}function jt(e,t){return t?xt(e):Ft(e)}function Ft(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap))t[r]=wt(r,e.forwardMap);return t}function xt(e){const t=Object.create(null);for(const r of Object.keys(e.forwardMap)){let n=r;for(;e.forwardMap[n];)n=e.forwardMap[n];t[r]=n}return t}function It(t,r,n,o,i,a,s){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(t).filter(([e])=>!c.has(e)));Object.keys(u).length>0&&(o[r]=u),t.canActivate&&(s?s.addActivateGuard(r,t.canActivate):i.set(r,t.canActivate)),t.canDeactivate&&(s?s.addDeactivateGuard(r,t.canDeactivate):a.set(r,t.canDeactivate)),t.forwardTo&&function(t,r,n){if(t.canActivate&&e.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 t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&e.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 t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const e="AsyncFunction"===t.forwardTo.constructor.name,n=t.forwardTo.toString().includes("__awaiter");if(e||n)throw new TypeError(`forwardTo callback cannot be async for route "${r}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?n.forwardMap[r]=t.forwardTo:n.forwardFnMap[r]=t.forwardTo}(t,r,n),t.decodeParams&&(n.decoders[r]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(n.encoders[r]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(n.defaultParams[r]=t.defaultParams)}function Lt(e,t,r,n,o,i,a=""){for(const s of e){const e=a?`${a}.${s.name}`:s.name;It(s,e,t,r,n,o,i),s.children&&Lt(s.children,t,r,n,o,i,e)}}var Mt,kt,_t=".";function Ut(e){const t=[];for(let r=e.length-1;r>=0;r--)t.push(e[r]);return t}function Bt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t}function Gt(e,t,r){const n=t.meta?.params[e];if(!n||"object"!=typeof n)return!0;for(const e of Object.keys(n)){const n=t.params[e],o=r.params[e];if(Bt(n)&&Bt(o)&&String(n)!==String(o))return!1}return!0}function Vt(e){if(!e)return[""];const t=e.indexOf(_t);if(-1===t)return[e];const r=e.indexOf(_t,t+1);if(-1===r)return[e.slice(0,t),e];const n=e.indexOf(_t,r+1);return-1===n?[e.slice(0,t),e.slice(0,r),e]:-1===e.indexOf(_t,n+1)?[e.slice(0,t),e.slice(0,r),e.slice(0,n),e]:function(e){const t=e.split(_t),r=t.length,n=[t[0]];let o=t[0].length;for(let i=1;i<r-1;i++)o+=1+t[i].length,n.push(e.slice(0,o));return n.push(e),n}(e)}var qt=null;function Wt(e,t){if(!t)return{intersection:"",toActivate:Vt(e.name),toDeactivate:[]};if(void 0===e.meta?.params&&void 0===t.meta?.params)return{intersection:"",toActivate:Vt(e.name),toDeactivate:Ut(Vt(t.name))};const r=Vt(e.name),n=Vt(t.name),o=function(e,t,r,n,o){for(let i=0;i<o;i++){const o=r[i];if(o!==n[i])return i;if(!Gt(o,e,t))return i}return o}(e,t,r,n,Math.min(n.length,r.length)),i=[];for(let e=n.length-1;e>=o;e--)i.push(n[e]);const a=r.slice(o);return{intersection:o>0?n[o-1]:"",toDeactivate:i,toActivate:a}}function zt(e,t,r){if(r?.reload)return Wt(e,t);if(null!==qt&&e===Mt&&t===kt)return qt;const n=Wt(e,t);return Mt=e,kt=t,qt=n,n}function Qt(e,t){var r;return{name:t??(r=e.segments,r.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var Ht=class{#G;get#h(){return this.#G.depsStore}constructor(e=[],t=!1,r){this.#G=function(e,t,r){const n=[],o=ge(),i=Object.create(null),a=new Map,s=new Map;for(const t of e)n.push(ve(t));const{tree:c,matcher:u}=Rt(n,"",r);return Lt(e,o,i,a,s,void 0,""),{definitions:n,config:o,tree:c,matcher:u,resolvedForwardMap:t?xt(o):Ft(o),routeCustomFields:i,rootPath:"",matcherOptions:r,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:a,pendingCanDeactivate:s,treeOperations:{commitTreeChanges:$t,resetStore:Dt,nodeToDefinition:rt,validateRoutes:Ot}}}(e,t,r)}static shouldUpdateNode(e){return(t,r)=>{if(!t||"object"!=typeof t||!("name"in t))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(t.transition?.reload)return!0;if(""===e&&!r)return!0;const{intersection:n,toActivate:o,toDeactivate:i}=zt(t,r);return e===n||!!o.includes(e)||i.includes(e)}}setDependencies(e){this.#G.depsStore=e;for(const[t,r]of this.#G.pendingCanActivate)e.addActivateGuard(t,r);this.#G.pendingCanActivate.clear();for(const[t,r]of this.#G.pendingCanDeactivate)e.addDeactivateGuard(t,r);this.#G.pendingCanDeactivate.clear()}setLifecycleNamespace(e){this.#G.lifecycleNamespace=e}setRootPath(e){this.#G.rootPath=e,Nt(this.#G)}hasRoute(e){return this.#G.matcher.hasRoute(e)}clearRoutes(){Dt(this.#G)}buildPath(e,t,r){if(e===y.UNKNOWN_ROUTE)return f(t?.path)?t.path:"";const n=Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t??{},o="function"==typeof this.#G.config.encoders[e]?this.#G.config.encoders[e]({...n}):n,i=r?.trailingSlash;return this.#G.matcher.buildPath(e,o,{trailingSlash:"never"===i||"always"===i?i:void 0,queryParamsMode:r?.queryParamsMode})}matchPath(e,t){const r=t,n=this.#G.matcher.match(e);if(!n)return;const o=Qt(n),{name:i,params:a,meta:s}=o,c="function"==typeof this.#G.config.decoders[i]?this.#G.config.decoders[i](a):a,{name:u,params:d}=this.#h.forwardState(i,c);let l=e;if(r.rewritePathOnMatch){const e="function"==typeof this.#G.config.encoders[u]?this.#G.config.encoders[u]({...d}):d,t=r.trailingSlash;l=this.#G.matcher.buildPath(u,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:r.queryParamsMode})}return this.#h.makeState(u,d,l,{params:s})}forwardState(e,t){if(Object.hasOwn(this.#G.config.forwardFnMap,e)){const r=this.#V(e,t),n=this.#G.config.forwardFnMap[e],o=this.#q(e,n,t);return{name:o,params:this.#V(o,r)}}const r=this.#G.resolvedForwardMap[e]??e;if(r!==e&&Object.hasOwn(this.#G.config.forwardFnMap,r)){const n=this.#V(e,t),o=this.#G.config.forwardFnMap[r],i=this.#q(r,o,t);return{name:i,params:this.#V(i,n)}}if(r!==e){const n=this.#V(e,t);return{name:r,params:this.#V(r,n)}}return{name:e,params:this.#V(e,t)}}buildStateResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return Qt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e)}buildStateWithSegmentsResolved(e,t){const r=this.#G.matcher.getSegmentsByName(e);if(r)return{state:Qt({segments:r,params:t,meta:this.#G.matcher.getMetaByName(e)},e),segments:r}}isActiveRoute(e,t={},r=!1,n=!0){me.has(e)||(m(e,"isActiveRoute"),me.add(e));const o=this.#h.getState();if(!o)return!1;const i=o.name;if(i!==e&&!i.startsWith(`${e}.`)&&!e.startsWith(`${i}.`))return!1;const a=this.#G.config.defaultParams[e];if(r||i===e){const r=a?{...a,...t}:t;return this.#h.areStatesEqual({name:e,params:r,path:""},o,n)}const s=o.params;return!!function(e,t){for(const r in e)if(e[r]!==t[r])return!1;return!0}(t,s)&&(!a||function(e,t,r){for(const n in e)if(!(n in r)&&e[n]!==t[n])return!1;return!0}(a,s,t))}getUrlParams(e){const t=this.#G.matcher.getSegmentsByName(e);return t?function(e){const t=[];for(const r of e)for(const e of r.paramMeta.urlParams)t.push(e);return t}(t):[]}getStore(){return this.#G}#V(e,t){return Object.hasOwn(this.#G.config.defaultParams,e)?{...this.#G.config.defaultParams[e],...t}:t}#q(e,t,r){const n=new Set([e]);let o=t(this.#h.getDependency,r),i=0;if("string"!=typeof o)throw new TypeError("forwardTo callback must return a string, got "+typeof o);for(;i<100;){if(void 0===this.#G.matcher.getSegmentsByName(o))throw new Error(`Route "${o}" does not exist`);if(n.has(o)){const e=[...n,o].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(n.add(o),Object.hasOwn(this.#G.config.forwardFnMap,o)){o=(0,this.#G.config.forwardFnMap[o])(this.#h.getDependency,r),i++;continue}const e=this.#G.config.forwardMap[o];if(void 0===e)return o;o=e,i++}throw new Error("forwardTo exceeds maximum depth of 100")}},Kt=new Set(Object.values(w)),Jt=new Set(["code","segment","path","redirect"]),Yt=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),Zt=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:r,path:n,redirect:o,...i}={}){super(t??e),this.code=e,this.segment=r,this.path=n,this.redirect=o?function(e){if(!e)return e;if(null===(t=e)||"object"!=typeof t||"string"!=typeof t.name||"string"!=typeof t.path||"object"!=typeof t.params||null===t.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof e);var t;const r=structuredClone(e),n=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(n.has(t))return;n.add(t),Object.freeze(t);const r=Array.isArray(t)?t:Object.values(t);for(const t of r)e(t)}(r),r}(o):void 0;for(const[e,t]of Object.entries(i)){if(Jt.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);Yt.has(e)||(this[e]=t)}}setCode(e){this.code=e,Kt.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=e.message,this.cause=e.cause,this.stack=e.stack??""}setAdditionalFields(e){for(const[t,r]of Object.entries(e)){if(Jt.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);Yt.has(t)||(this[t]=r)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){const e={code:this.code,message:this.message};void 0!==this.segment&&(e.segment=this.segment),void 0!==this.path&&(e.path=this.path),void 0!==this.redirect&&(e.redirect=this.redirect);const t=new Set(["code","message","segment","path","redirect","stack"]);for(const r in this)Object.hasOwn(this,r)&&!t.has(r)&&(e[r]=this[r]);return e}};function Xt(e,t,r){if(e instanceof Zt)throw e.setCode(t),e;throw new Zt(t,function(e,t){const r={segment:t};if(e instanceof Error)return{...r,message:e.message,stack:e.stack,..."cause"in e&&void 0!==e.cause&&{cause:e.cause}};if(e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))er.has(r)||(t[r]=n);return{...r,...t}}return r}(e,r))}var er=new Set(["code","segment","path","redirect"]);async function tr(e,t,r,n,o,i,a){const s=n.filter(t=>e.has(t));if(0===s.length)return;let c;for(const n of s){if(i())throw new Zt(w.TRANSITION_CANCELLED);const s=e.get(n);try{c=await s(t,r,a)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw new Zt(w.TRANSITION_CANCELLED,{reason:a.reason});Xt(e,o,n)}if(!c)throw new Zt(o,{segment:n})}}var rr=class t{#W;#h;#z;#Q=null;static validateNavigateArgs(e){!function(e){if("string"!=typeof e)throw new TypeError(`[router.navigate] Invalid route name: expected string, got ${g(e)}`)}(e)}static validateNavigateToDefaultArgs(e){!function(e){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`[router.navigateToDefault] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e)}static validateNavigationOptions(e,t){!function(e,t){if(!function(e){if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=e;for(const e of i){const r=t[e];if(void 0!==r&&"boolean"!=typeof r)return!1}const r=t.signal;return!(void 0!==r&&!(r instanceof AbortSignal))}(e))throw new TypeError(`[router.${t}] Invalid options: ${g(e)}. Expected NavigationOptions object.`)}(e,t)}setCanNavigate(e){this.#W=e}setDependencies(e){this.#h=e}setTransitionDependencies(e){this.#z=e}async navigate(e,t,r){if(!this.#W())throw new Zt(w.ROUTER_NOT_STARTED);const n=this.#h,o=n.buildStateWithSegments(e,t);if(!o){const e=new Zt(w.ROUTE_NOT_FOUND);throw n.emitTransitionError(void 0,n.getState(),e),e}const{state:i}=o,a=n.makeState(i.name,i.params,n.buildPath(i.name,i.params),{params:i.meta}),s=n.getState();if(!r.reload&&!r.force&&n.areStatesEqual(s,a,!1)){const e=new Zt(w.SAME_STATES);throw n.emitTransitionError(a,s,e),e}return this.navigateToState(a,s,r)}async navigateToState(r,n,o){const i=this.#h,a=this.#z;a.isTransitioning()&&(e.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 Zt(w.TRANSITION_CANCELLED)),i.cancelNavigation());const s=new AbortController;if(this.#Q=s,o.signal){if(o.signal.aborted)throw this.#Q=null,new Zt(w.TRANSITION_CANCELLED,{reason:o.signal.reason});o.signal.addEventListener("abort",()=>{s.abort(o.signal?.reason)},{once:!0,signal:s.signal})}i.startTransition(r,n);try{const{state:e,meta:c}=await async function(e,t,r,n,o){const[i,a]=e.getLifecycleFunctions(),s=t.name===y.UNKNOWN_ROUTE,c=()=>o.aborted||!e.isActive(),{toDeactivate:u,toActivate:d,intersection:l}=zt(t,r,void 0===n.reload?void 0:{reload:n.reload}),f=!s&&d.length>0;if(r&&!n.forceDeactivate&&u.length>0&&await tr(i,t,r,u,w.CANNOT_DEACTIVATE,c,o),c())throw new Zt(w.TRANSITION_CANCELLED);if(f&&await tr(a,t,r,d,w.CANNOT_ACTIVATE,c,o),c())throw new Zt(w.TRANSITION_CANCELLED);if(r)for(const t of u)!d.includes(t)&&i.has(t)&&e.clearCanDeactivate(t);return{state:t,meta:{phase:"activating",segments:{deactivated:u,activated:d,intersection:l}}}}(a,r,n,o,s.signal);if(e.name===y.UNKNOWN_ROUTE||i.hasRoute(e.name)){const r=t.#H(e,c,n,o);i.setState(r);const a=void 0===o.signal?o:t.#K(o);return i.sendTransitionDone(r,n,a),r}{const t=new Zt(w.ROUTE_NOT_FOUND,{routeName:e.name});throw i.sendTransitionError(e,n,t),t}}catch(e){throw this.#J(e,r,n),e}finally{s.abort(),this.#Q===s&&(this.#Q=null)}}async navigateToDefault(e){const t=this.#h,r=t.getOptions();if(!r.defaultRoute)throw new Zt(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"});const n=ee(r.defaultRoute,t.getDependency);if(!n)throw new Zt(w.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"});const o=ee(r.defaultParams,t.getDependency);return this.navigate(n,o,e)}abortCurrentNavigation(){this.#Q?.abort(new Zt(w.TRANSITION_CANCELLED)),this.#Q=null}static#K(e){const{signal:t,...r}=e;return r}static#H(e,t,r,n){const o={phase:t.phase,...void 0!==r?.name&&{from:r.name},reason:"success",segments:t.segments,...void 0!==n.reload&&{reload:n.reload},...void 0!==n.redirected&&{redirected:n.redirected}};return Object.freeze(o.segments.deactivated),Object.freeze(o.segments.activated),Object.freeze(o.segments),Object.freeze(o),{...e,transition:o}}#J(e,t,r){const n=e;n.code!==w.TRANSITION_CANCELLED&&n.code!==w.ROUTE_NOT_FOUND&&(n.code===w.CANNOT_ACTIVATE||n.code===w.CANNOT_DEACTIVATE?this.#h.sendTransitionBlocked(t,r,n):this.#h.sendTransitionError(t,r,n))}},nr=class{#Y;#h;static validateStartArgs(e){if(1!==e.length||"string"!=typeof e[0])throw new Error("[router.start] Expected exactly 1 string argument (startPath).")}setNavigateToState(e){this.#Y=e}setDependencies(e){this.#h=e}async start(e){const t=this.#h,r=t.getOptions(),n={replace:!0},o=t.matchPath(e);if(!o&&!r.allowNotFound){const r=new Zt(w.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}let i;if(t.completeStart(),o)i=await this.#Y(o,void 0,n);else{const r=t.makeNotFoundState(e);i=await this.#Y(r,void 0,n)}return i}stop(){this.#h.clearState()}},or=class{#Z;#X;#ee;constructor(e){this.#Z=e.routerFSM,this.#X=e.emitter,this.#ee=void 0,this.#te()}static validateSubscribeListener(e){if("function"!=typeof e)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#X.emit(P.ROUTER_START)}emitRouterStop(){this.#X.emit(P.ROUTER_STOP)}emitTransitionStart(e,t){this.#X.emit(P.TRANSITION_START,e,t)}emitTransitionSuccess(e,t,r){this.#X.emit(P.TRANSITION_SUCCESS,e,t,r)}emitTransitionError(e,t,r){this.#X.emit(P.TRANSITION_ERROR,e,t,r)}emitTransitionCancel(e,t){this.#X.emit(P.TRANSITION_CANCEL,e,t)}sendStart(){this.#Z.send(I)}sendStop(){this.#Z.send(B)}sendDispose(){this.#Z.send(G)}completeStart(){this.#Z.send(L)}beginTransition(e,t){this.#ee=e,this.#Z.send(M,{toState:e,fromState:t})}completeTransition(e,t,r={}){this.#Z.send(k,{state:e,fromState:t,opts:r}),this.#ee=void 0}failTransition(e,t,r){this.#Z.send(_,{toState:e,fromState:t,error:r}),this.#ee=void 0}cancelTransition(e,t){this.#Z.send(U,{toState:e,fromState:t}),this.#ee=void 0}emitOrFailTransitionError(e,t,r){this.#Z.getState()===j?this.#Z.send(_,{toState:e,fromState:t,error:r}):this.emitTransitionError(e,t,r)}canBeginTransition(){return this.#Z.canSend(M)}canStart(){return this.#Z.canSend(I)}canCancel(){return this.#Z.canSend(U)}isActive(){const e=this.#Z.getState();return e!==D&&e!==x}isDisposed(){return this.#Z.getState()===x}isTransitioning(){return this.#Z.getState()===F}isReady(){return this.#Z.getState()===j}getCurrentToState(){return this.#ee}addEventListener(e,t){return this.#X.on(e,t)}subscribe(e){return this.#X.on(P.TRANSITION_SUCCESS,(t,r)=>{e({route:t,previousRoute:r})})}clearAll(){this.#X.clearAll()}setLimits(e){this.#X.setLimits(e)}cancelTransitionIfRunning(e){this.canCancel()&&this.cancelTransition(this.#ee,e)}#te(){const e=this.#Z;e.on(C,L,()=>{this.emitRouterStart()}),e.on(j,B,()=>{this.emitRouterStop()}),e.on(j,M,e=>{this.emitTransitionStart(e.toState,e.fromState)}),e.on(F,k,e=>{this.emitTransitionSuccess(e.state,e.fromState,e.opts)}),e.on(F,U,e=>{this.emitTransitionCancel(e.toState,e.fromState)}),e.on(C,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(j,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)}),e.on(F,_,e=>{this.emitTransitionError(e.toState,e.fromState,e.error)})}};function ir(e,t){if("string"!=typeof e)throw new TypeError(`[router.${t}]: dependency name must be a string, got ${typeof e}`)}function ar(e,t){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[router.${t}] Invalid argument: expected plain object, received ${g(e)}`);for(const r in e)if(Object.getOwnPropertyDescriptor(e,r)?.get)throw new TypeError(`[router.${t}] Getters not allowed: "${r}"`)}var sr=new Zt(w.ROUTER_ALREADY_STARTED),cr=new Set(["all","warn-error","error-only"]);var ur=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(e){this.router=e.router,this.options=e.options,this.limits=e.limits,this.dependenciesStore=e.dependenciesStore,this.state=e.state,this.routes=e.routes,this.routeLifecycle=e.routeLifecycle,this.plugins=e.plugins,this.navigation=e.navigation,this.lifecycle=e.lifecycle,this.eventBus=e.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(){this.routeLifecycle.setRouter(this.router),this.routeLifecycle.setDependencies({getDependency:e=>this.dependenciesStore.dependencies[e]})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.routeLifecycle.addCanActivate(e,t,!0,!0)},addDeactivateGuard:(e,t)=>{this.routeLifecycle.addCanDeactivate(e,t,!0,!0)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),getState:()=>this.state.get(),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],forwardState:(e,t)=>{const r=K(this.router);return r.noValidate||Tt(e,t,"forwardState"),r.forwardState(e,t)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){this.plugins.setRouter(this.router),this.plugins.setDependencies({addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),getDependency:e=>this.dependenciesStore.dependencies[e]})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildStateWithSegments:(e,t)=>{const r=K(this.router);r.noValidate||Tt(e,t,"navigate");const{name:n,params:o}=r.forwardState(e,t);return this.routes.buildStateWithSegmentsResolved(n,o)},makeState:(e,t,r,n)=>this.state.makeState(e,t,r,n),buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),areStatesEqual:(e,t,r)=>this.state.areStatesEqual(e,t,r),getDependency:e=>this.dependenciesStore.dependencies[e],startTransition:(e,t)=>{this.eventBus.beginTransition(e,t)},cancelNavigation:()=>{this.eventBus.cancelTransition(this.eventBus.getCurrentToState(),this.state.get())},sendTransitionDone:(e,t,r)=>{this.eventBus.completeTransition(e,t,r)},sendTransitionBlocked:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},sendTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)},emitTransitionError:(e,t,r)=>{this.eventBus.emitOrFailTransitionError(e,t,r)}}),this.navigation.setTransitionDependencies({getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:e=>{this.routeLifecycle.clearCanDeactivate(e)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),makeNotFoundState:e=>this.state.makeNotFoundState(e),clearState:()=>{this.state.set(void 0)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.completeStart()},emitTransitionError:(e,t,r)=>{this.eventBus.failTransition(e,t,r)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(e,t)=>this.routes.buildPath(e,t,this.options.get()),getUrlParams:e=>this.routes.getUrlParams(e)})}wireCyclicDeps(){this.navigation.setCanNavigate(()=>this.eventBus.canBeginTransition()),this.lifecycle.setNavigateToState((e,t,r)=>this.navigation.navigateToState(e,t,r))}},dr=class r{#u;#y;#re;#ne;#oe;#ie;#g;#ae;#se;#ce;#ue;constructor(r=[],n={},i={}){n.logger&&function(e){if("object"!=typeof e||null===e)throw new TypeError("Logger config must be an object");const t=e;for(const e of Object.keys(t))if("level"!==e&&"callback"!==e)throw new TypeError(`Unknown logger config property: "${e}"`);if("level"in t&&void 0!==t.level&&("string"!=typeof(r=t.level)||!cr.has(r)))throw new TypeError(`Invalid logger level: ${function(e){return"string"==typeof e?`"${e}"`:"object"==typeof e?JSON.stringify(e):String(e)}(t.level)}. Expected: "all" | "warn-error" | "error-only"`);var r;if("callback"in t&&void 0!==t.callback&&"function"!=typeof t.callback)throw new TypeError("Logger callback must be a function, got "+typeof t.callback);return!0}(n.logger)&&(e.logger.configure(n.logger),delete n.logger),oe.validateOptions(n,"constructor");const a=n.noValidate??!1;a||ar(i,"constructor"),!a&&r.length>0&&(St(r),Ot(r)),this.#u=new oe(n),this.#y=function(e={}){return{...$,...e}}(n.limits),this.#re=function(e={}){const t=Object.create(null);for(const r in e)void 0!==e[r]&&(t[r]=e[r]);return{dependencies:t,limits:$}}(i),this.#ne=new ae,this.#oe=new Ht(r,a,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#u.get())),this.#ie=new pe,this.#g=new de,this.#ae=new rr,this.#se=new nr,this.#ue=a;const s=new t.FSM(V),c=new o({onListenerError:(t,r)=>{e.logger.error("Router",`Error in listener for ${t}:`,r)},onListenerWarn:(t,r)=>{e.logger.warn("router.addEventListener",`Event "${t}" has ${r} listeners — possible memory leak`)}});var u;this.#ce=new or({routerFSM:s,emitter:c}),(u=new ur({router:this,options:this.#u,limits:this.#y,dependenciesStore:this.#re,state:this.#ne,routes:this.#oe,routeLifecycle:this.#ie,plugins:this.#g,navigation:this.#ae,lifecycle:this.#se,eventBus:this.#ce})).wireLimits(),u.wireRouteLifecycleDeps(),u.wireRoutesDeps(),u.wirePluginsDeps(),u.wireNavigationDeps(),u.wireLifecycleDeps(),u.wireStateDeps(),u.wireCyclicDeps(),H.set(this,{makeState:(e,t,r,n,o)=>this.#ne.makeState(e,t,r,n,o),forwardState:(e,t)=>this.#oe.forwardState(e,t),buildStateResolved:(e,t)=>this.#oe.buildStateResolved(e,t),matchPath:(e,t)=>this.#oe.matchPath(e,t),getOptions:()=>this.#u.get(),navigateToState:(e,t,r)=>this.#ae.navigateToState(e,t,r),addEventListener:(e,t)=>this.#ce.addEventListener(e,t),buildPath:(e,t)=>this.#oe.buildPath(e,t,this.#u.get()),setRootPath:e=>{this.#oe.setRootPath(e)},getRootPath:()=>this.#oe.getStore().rootPath,getTree:()=>this.#oe.getStore().tree,isDisposed:()=>this.#ce.isDisposed(),noValidate:a,dependenciesGetStore:()=>this.#re,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#re.dependencies}),getLifecycleFactories:()=>this.#ie.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#oe.getStore(),getStateName:()=>this.#ne.get()?.name,isTransitioning:()=>this.#ce.isTransitioning(),clearState:()=>{this.#ne.set(void 0)},setState:e=>{this.#ne.set(e)}}),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.subscribe=this.subscribe.bind(this)}isActiveRoute(t,r,n,o){return this.#ue||function(e,t,r,n){if(!f(e))throw new TypeError("Route name must be a string");if(void 0!==t&&!l(t))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)}(t,r,n,o),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#oe.isActiveRoute(t,r,n,o)}buildPath(e,t){return this.#ue||function(e){if(!f(e)||""===e)throw new TypeError("[real-router] buildPath: route must be a non-empty string, got "+("string"==typeof e?'""':typeof e))}(e),this.#oe.buildPath(e,t,this.#u.get())}getState(){return this.#ne.get()}getPreviousState(){return this.#ne.getPrevious()}areStatesEqual(e,t,r=!0){return this.#ue||ae.validateAreStatesEqualArgs(e,t,r),this.#ne.areStatesEqual(e,t,r)}shouldUpdateNode(e){return this.#ue||function(e){if(!f(e))throw new TypeError("[router.shouldUpdateNode] nodeName must be a string, got "+typeof e)}(e),Ht.shouldUpdateNode(e)}isActive(){return this.#ce.isActive()}start(e){if(this.#ue||nr.validateStartArgs([e]),!this.#ce.canStart())return Promise.reject(sr);this.#ce.sendStart();const t=this.#se.start(e).catch(e=>{throw this.#ce.isReady()&&(this.#se.stop(),this.#ce.sendStop()),e});return r.#de(t),t}stop(){return this.#ae.abortCurrentNavigation(),this.#ce.cancelTransitionIfRunning(this.#ne.get()),this.#ce.isReady()||this.#ce.isTransitioning()?(this.#se.stop(),this.#ce.sendStop(),this):this}dispose(){this.#ce.isDisposed()||(this.#ae.abortCurrentNavigation(),this.#ce.cancelTransitionIfRunning(this.#ne.get()),(this.#ce.isReady()||this.#ce.isTransitioning())&&(this.#se.stop(),this.#ce.sendStop()),this.#ce.sendDispose(),this.#ce.clearAll(),this.#g.disposeAll(),this.#oe.clearRoutes(),this.#ie.clearAll(),this.#ne.reset(),this.#re.dependencies=Object.create(null),this.#le())}canNavigateTo(e,t){if(this.#ue||m(e,"canNavigateTo"),!this.#oe.hasRoute(e))return!1;const r=K(this),{name:n,params:o}=r.forwardState(e,t??{}),i=this.#ne.makeState(n,o),a=this.#ne.get(),{toDeactivate:s,toActivate:c}=zt(i,a);for(const e of s)if(!this.#ie.checkDeactivateGuardSync(e,i,a))return!1;for(const e of c)if(!this.#ie.checkActivateGuardSync(e,i,a))return!1;return!0}usePlugin(...e){return this.#ue||(de.validateUsePluginArgs(e),de.validatePluginLimit(this.#g.count(),e.length,this.#y.maxPlugins),de.validateNoDuplicatePlugins(e,this.#g.has.bind(this.#g))),this.#g.use(...e)}subscribe(e){return this.#ue||or.validateSubscribeListener(e),this.#ce.subscribe(e)}navigate(e,t,n){this.#ue||rr.validateNavigateArgs(e);const o=n??{};this.#ue||rr.validateNavigationOptions(o,"navigate");const i=this.#ae.navigate(e,t??{},o);return r.#de(i),i}navigateToDefault(e){this.#ue||rr.validateNavigateToDefaultArgs(e);const t=e??{};this.#ue||rr.validateNavigationOptions(t,"navigateToDefault");const n=this.#ae.navigateToDefault(t);return r.#de(n),n}static#fe=t=>{t instanceof Zt&&(t.code===w.SAME_STATES||t.code===w.TRANSITION_CANCELLED||t.code===w.ROUTER_NOT_STARTED||t.code===w.ROUTE_NOT_FOUND)||e.logger.error("router.navigate","Unexpected navigation error",t)};static#de(e){e.catch(r.#fe)}#le(){this.navigate=lr,this.navigateToDefault=lr,this.start=lr,this.stop=lr,this.usePlugin=lr,this.subscribe=lr,this.canNavigateTo=lr}};function lr(){throw new Zt(w.ROUTER_DISPOSED)}function fr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function hr(e,t,r=""){for(const n of e){const e=r?`${r}.${n.name}`:n.name;if(e===t)return n;if(n.children&&t.startsWith(`${e}.`))return hr(n.children,t,e)}}function pr(e,t,r,n){const o={name:e.name,path:e.path},i=r.forwardFnMap[t],a=r.forwardMap[t];void 0!==i?o.forwardTo=i:void 0!==a&&(o.forwardTo=a),t in r.defaultParams&&(o.defaultParams=r.defaultParams[t]),t in r.decoders&&(o.decodeParams=r.decoders[t]),t in r.encoders&&(o.encodeParams=r.encoders[t]);const[s,c]=n;return t in c&&(o.canActivate=c[t]),t in s&&(o.canDeactivate=s[t]),e.children&&(o.children=e.children.map(e=>pr(e,`${t}.${e.name}`,r,n))),o}function mr(e,t,r,n){if(n){const t=hr(e.definitions,n);t.children??=[];for(const e of r)t.children.push(ve(e))}else for(const t of r)e.definitions.push(ve(t));Lt(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,n??""),e.treeOperations.commitTreeChanges(e,t)}function gr(e,t,r){return!!we(e.definitions,r)&&(function(e,t,r,n){const o=t=>t===e||t.startsWith(`${e}.`);ye(t.decoders,o),ye(t.encoders,o),ye(t.defaultParams,o),ye(t.forwardMap,o),ye(t.forwardFnMap,o),ye(r,o),ye(t.forwardMap,e=>o(t.forwardMap[e]));const[i,a]=n.getFactories();for(const e of Object.keys(a))o(e)&&n.clearCanActivate(e);for(const e of Object.keys(i))o(e)&&n.clearCanDeactivate(e)}(r,e.config,e.routeCustomFields,e.lifecycleNamespace),e.treeOperations.commitTreeChanges(e,t),!0)}function vr(e,t){const r=e.matcher.getSegmentsByName(t);if(!r)return;const n=r.at(-1),o=e.treeOperations.nodeToDefinition(n),i=e.lifecycleNamespace.getFactories();return pr(o,t,e.config,i)}function wr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function yr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function Sr(e){if(e())throw new Zt(w.ROUTER_DISPOSED)}function Tr(e){const t=K(e),r=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addActivateGuard"),le(n,"addActivateGuard")),r.addCanActivate(e,n,t.noValidate)},addDeactivateGuard(e,n){Sr(t.isDisposed),t.noValidate||(m(e,"addDeactivateGuard"),le(n,"addDeactivateGuard")),r.addCanDeactivate(e,n,t.noValidate)},removeActivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeActivateGuard"),r.clearCanActivate(e)},removeDeactivateGuard(e){Sr(t.isDisposed),t.noValidate||m(e,"removeDeactivateGuard"),r.clearCanDeactivate(e)}}}exports.Router=dr,exports.RouterError=Zt,exports.cloneRouter=function(e,t){const r=K(e);if(r.isDisposed())throw new Zt(w.ROUTER_DISPOSED);r.noValidate||function(e){if(void 0!==e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError(`[cloneRouter] Invalid dependencies: expected plain object or undefined, received ${g(e)}`);for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`[cloneRouter] Getters not allowed in dependencies: "${t}"`)}}(t);const n=r.routeGetStore(),o=[...n.tree.children.values()].map(e=>rt(e)),i=n.config,a=n.resolvedForwardMap,s=n.routeCustomFields,c=r.cloneOptions(),u=r.cloneDependencies(),[d,l]=r.getLifecycleFactories(),f=r.getPluginFactories(),h={...u,...t},p=new dr(o,c,h),m=Tr(p);for(const[e,t]of Object.entries(d))m.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(l))m.addActivateGuard(e,t);f.length>0&&p.usePlugin(...f);const v=K(p).routeGetStore();return Object.assign(v.config.decoders,i.decoders),Object.assign(v.config.encoders,i.encoders),Object.assign(v.config.defaultParams,i.defaultParams),Object.assign(v.config.forwardMap,i.forwardMap),Object.assign(v.config.forwardFnMap,i.forwardFnMap),Object.assign(v.resolvedForwardMap,a),Object.assign(v.routeCustomFields,s),p},exports.constants=y,exports.createRouter=(e=[],t={},r={})=>new dr(e,t,r),exports.errorCodes=w,exports.events=P,exports.getDependenciesApi=function(t){const r=K(t);return{get:e=>{r.noValidate||ir(e,"getDependency");const t=r.dependenciesGetStore().dependencies[e];return r.noValidate||function(e,t){if(void 0===e)throw new ReferenceError(`[router.getDependency]: dependency "${t}" not found`)}(t,e),t},getAll:()=>({...r.dependenciesGetStore().dependencies}),set:(t,n)=>{yr(r.isDisposed),r.noValidate||function(e){if("string"!=typeof e)throw new TypeError("[router.setDependency]: dependency name must be a string, got "+typeof e)}(t),function(t,r,n){if(void 0===n)return!1;if(Object.hasOwn(t.dependencies,r)){const o=t.dependencies[r],i=o!==n,a=Number.isNaN(o)&&Number.isNaN(n);i&&!a&&e.logger.warn("router.setDependency","Router dependency already exists and is being overwritten:",r)}else!function(t,r){const n=t.limits.maxDependencies;if(0===n)return;const o=Object.keys(t.dependencies).length,{warn:i,error:a}=Q(n);if(o===i)e.logger.warn(`router.${r}`,`${i} dependencies registered. Consider if all are necessary.`);else if(o===a)e.logger.error(`router.${r}`,`${a} dependencies registered! This indicates architectural problems. Hard limit at ${n}.`);else if(o>=n)throw new Error(`[router.${r}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code. If you genuinely need more dependencies, your architecture needs refactoring.`)}(t,"setDependency");t.dependencies[r]=n}(r.dependenciesGetStore(),t,n)},setAll:t=>{yr(r.isDisposed);const n=r.dependenciesGetStore();r.noValidate||(ar(t,"setDependencies"),function(e,t,r,n=$.maxDependencies){if(0===n)return;const o=e+t;if(o>=n)throw new Error(`[router.${"setDependencies"}] Dependency limit exceeded (${n}). Current: ${o}. This is likely a bug in your code.`)}(Object.keys(n.dependencies).length,Object.keys(t).length,0,n.limits.maxDependencies)),function(t,r){const n=[];for(const e in r)void 0!==r[e]&&(Object.hasOwn(t.dependencies,e)&&n.push(e),t.dependencies[e]=r[e]);n.length>0&&e.logger.warn("router.setDependencies","Overwritten:",n.join(", "))}(n,t)},remove:t=>{yr(r.isDisposed),r.noValidate||ir(t,"removeDependency");const n=r.dependenciesGetStore();Object.hasOwn(n.dependencies,t)||e.logger.warn("router.removeDependency",`Attempted to remove non-existent dependency: "${g(t)}"`),delete n.dependencies[t]},reset:()=>{yr(r.isDisposed),r.dependenciesGetStore().dependencies=Object.create(null)},has:e=>(r.noValidate||ir(e,"hasDependency"),Object.hasOwn(r.dependenciesGetStore().dependencies,e))}},exports.getLifecycleApi=Tr,exports.getNavigator=e=>Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe}),exports.getPluginApi=function(e){const t=K(e);return{makeState:(e,r,n,o,i)=>(t.noValidate||function(e,t,r,n){if(!f(e))throw new TypeError(`[router.makeState] Invalid name: ${g(e)}. Expected string.`);if(void 0!==t&&!l(t))throw new TypeError(`[router.makeState] Invalid params: ${g(t)}. Expected plain object.`);if(void 0!==r&&!f(r))throw new TypeError(`[router.makeState] Invalid path: ${g(r)}. Expected string.`);if(void 0!==n&&"number"!=typeof n)throw new TypeError(`[router.makeState] Invalid forceId: ${g(n)}. Expected number.`)}(e,r,n,i),t.makeState(e,r,n,o,i)),buildState:(e,r)=>{t.noValidate||Tt(e,r,"buildState");const{name:n,params:o}=t.forwardState(e,r);return t.buildStateResolved(n,o)},forwardState:(e,r)=>(t.noValidate||Tt(e,r,"forwardState"),t.forwardState(e,r)),matchPath:e=>(t.noValidate||function(e){if(!f(e))throw new TypeError("[real-router] matchPath: path must be a string, got "+typeof e)}(e),t.matchPath(e,t.getOptions())),setRootPath:e=>{fr(t.isDisposed),t.noValidate||function(e){if("string"!=typeof e)throw new TypeError(`[router.setRootPath] rootPath must be a string, got ${g(e)}`)}(e),t.setRootPath(e)},getRootPath:t.getRootPath,navigateToState:(e,r,n)=>(fr(t.isDisposed),t.noValidate||function(e,t,r){if(!e||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path)throw new TypeError("[router.navigateToState] Invalid toState: expected State object with name and path");if(void 0!==t&&(!t||"object"!=typeof t||"string"!=typeof t.name))throw new TypeError("[router.navigateToState] Invalid fromState: expected State object or undefined");if("object"!=typeof r||null===r)throw new TypeError(`[router.navigateToState] Invalid opts: expected NavigationOptions object, got ${g(r)}`)}(e,r,n),t.navigateToState(e,r,n)),addEventListener:(e,r)=>(fr(t.isDisposed),t.noValidate||function(e,t){if(function(e){if(!R.has(e))throw new Error(`Invalid event name: ${String(e)}`)}(e),"function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}(e,r),t.addEventListener(e,r)),buildNavigationState:(e,r={})=>{t.noValidate||Tt(e,r,"buildNavigationState");const{name:n,params:o}=t.forwardState(e,r),i=t.buildStateResolved(n,o);if(i)return t.makeState(i.name,i.params,t.buildPath(i.name,i.params),{params:i.meta})},getOptions:t.getOptions,getTree:t.getTree,getForwardState:()=>t.forwardState,setForwardState:e=>{t.forwardState=e}}},exports.getRoutesApi=function(t){const r=K(t),n=r.routeGetStore(),o=r.noValidate;return{add:(e,t)=>{wr(r.isDisposed);const i=Array.isArray(e)?e:[e],a=t?.parent;r.noValidate||(void 0!==a&&function(e){if("string"!=typeof e||""===e)throw new TypeError(`[router.addRoute] parent option must be a non-empty string, got ${g(e)}`);m(e,"addRoute")}(a),St(i),n.treeOperations.validateRoutes(i,n.tree,n.config.forwardMap,a)),mr(n,o,i,a)},remove:t=>{wr(r.isDisposed),r.noValidate||function(e){m(e,"removeRoute")}(t);const i=function(t,r,n){if(r){const n=r===t,o=r.startsWith(`${t}.`);if(n||o)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${n?"":` (current: "${r}")`}. Navigate away first.`),!1}return n&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}(t,r.getStateName(),r.isTransitioning());i&&(gr(n,o,t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`))},update:(t,i)=>{wr(r.isDisposed),r.noValidate||function(e,t){if(m(e,"updateRoute"),""===e)throw new ReferenceError("[router.updateRoute] Invalid name: empty string. Cannot update root node.");if(null===t)throw new TypeError("[real-router] updateRoute: updates must be an object, got null");if("object"!=typeof t||Array.isArray(t))throw new TypeError(`[real-router] updateRoute: updates must be an object, got ${g(t)}`)}(t,i);const{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u,canActivate:d,canDeactivate:l}=i;r.noValidate||function(e,t,r,n){if(null!=e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError(`[real-router] updateRoute: forwardTo must be a string, function, or null, got ${g(e)}`);"function"==typeof e&&bt(e,"forwardTo callback")}if(null!=t&&("object"!=typeof t||Array.isArray(t)))throw new TypeError(`[real-router] updateRoute: defaultParams must be an object or null, got ${g(t)}`);Et(r,"decodeParams"),Et(n,"encodeParams")}(a,s,c,u),r.isTransitioning()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),r.noValidate||Pt(t,a,e=>n.matcher.hasRoute(e),n.matcher,n.config),function(e,t,r,n){if(void 0!==n.forwardTo&&(e.resolvedForwardMap=function(e,t,r,n,o){return null===t?(delete r.forwardMap[e],delete r.forwardFnMap[e]):"string"==typeof t?(delete r.forwardFnMap[e],r.forwardMap[e]=t):(delete r.forwardMap[e],r.forwardFnMap[e]=t),o(r,n)}(r,n.forwardTo,e.config,t,jt)),void 0!==n.defaultParams&&(null===n.defaultParams?delete e.config.defaultParams[r]:e.config.defaultParams[r]=n.defaultParams),void 0!==n.decodeParams)if(null===n.decodeParams)delete e.config.decoders[r];else{const t=n.decodeParams;e.config.decoders[r]=e=>t(e)??e}if(void 0!==n.encodeParams)if(null===n.encodeParams)delete e.config.encoders[r];else{const t=n.encodeParams;e.config.encoders[r]=e=>t(e)??e}}(n,o,t,{forwardTo:a,defaultParams:s,decodeParams:c,encodeParams:u}),void 0!==d&&(null===d?n.lifecycleNamespace.clearCanActivate(t):n.lifecycleNamespace.addCanActivate(t,d,o,!0)),void 0!==l&&(null===l?n.lifecycleNamespace.clearCanDeactivate(t):n.lifecycleNamespace.addCanDeactivate(t,l,o,!0))},clear:()=>{wr(r.isDisposed),At(r.isTransitioning())&&(n.treeOperations.resetStore(n),n.lifecycleNamespace.clearAll(),r.clearState())},has:e=>(r.noValidate||m(e,"hasRoute"),n.matcher.hasRoute(e)),get:e=>(r.noValidate||m(e,"getRoute"),vr(n,e)),getConfig:e=>function(e,t){if(e.matcher.hasRoute(t))return e.routeCustomFields[t]}(n,e),replace:e=>{wr(r.isDisposed);const i=Array.isArray(e)?e:[e];if(!At(r.isTransitioning()))return;r.noValidate||(St(i),n.treeOperations.validateRoutes(i));const a=t.getState()?.path;!function(e,t,r,n,o){Ct(e),e.lifecycleNamespace.clearDefinitionGuards();for(const t of r)e.definitions.push(ve(t));if(Lt(r,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,""),e.treeOperations.commitTreeChanges(e,t),void 0!==o){const e=n.matchPath(o,n.getOptions());e?n.setState(e):n.clearState()}}(n,o,i,r,a)}}};//# sourceMappingURL=index.js.map