@real-router/core 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Router-73rMK2YI.d.ts +409 -0
- package/dist/cjs/Router-NL2_9FQk.js +6 -0
- package/dist/cjs/Router-NL2_9FQk.js.map +1 -0
- package/dist/cjs/RouterError-BkgjTHQg.js +2 -0
- package/dist/cjs/RouterError-BkgjTHQg.js.map +1 -0
- package/dist/cjs/RouterValidator-TUi8eT8Q.d.ts +112 -0
- package/dist/cjs/api.d.ts +17 -12
- package/dist/cjs/api.js +2 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/getPluginApi-BXrM_Nwv.js +2 -0
- package/dist/cjs/getPluginApi-BXrM_Nwv.js.map +1 -0
- package/dist/cjs/index.d.ts +206 -196
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internals-na15rxo_.js +2 -0
- package/dist/cjs/internals-na15rxo_.js.map +1 -0
- package/dist/cjs/utils.d.ts +6 -3
- package/dist/cjs/utils.js +2 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/validation.d.ts +153 -152
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/Router-BhDMI4UX.d.mts +409 -0
- package/dist/esm/Router-CUi2TqAr.mjs +6 -0
- package/dist/esm/Router-CUi2TqAr.mjs.map +1 -0
- package/dist/esm/RouterError-D0RlQE_5.mjs +2 -0
- package/dist/esm/RouterError-D0RlQE_5.mjs.map +1 -0
- package/dist/esm/RouterValidator-DphcVMEp.d.mts +112 -0
- package/dist/esm/api.d.mts +17 -12
- package/dist/esm/api.mjs +2 -1
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/getPluginApi-D0bBPuLp.mjs +2 -0
- package/dist/esm/getPluginApi-D0bBPuLp.mjs.map +1 -0
- package/dist/esm/index.d.mts +206 -196
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internals-CCymabFj.mjs +2 -0
- package/dist/esm/internals-CCymabFj.mjs.map +1 -0
- package/dist/esm/utils.d.mts +6 -3
- package/dist/esm/utils.mjs +2 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/validation.d.mts +153 -152
- package/dist/esm/validation.mjs +1 -1
- package/package.json +5 -7
- package/src/helpers.ts +9 -6
- package/src/namespaces/OptionsNamespace/constants.ts +3 -5
- package/dist/cjs/Router-DoJ3NWsT.d.ts +0 -46
- package/dist/cjs/RouterValidator-CaIeCVeB.d.ts +0 -136
- package/dist/cjs/index.d-y2b-8_3Y.d.ts +0 -236
- package/dist/cjs/metafile-cjs.json +0 -1
- package/dist/cjs/validation.js.map +0 -1
- package/dist/esm/Router-DoJ3NWsT.d.mts +0 -46
- package/dist/esm/RouterValidator-CaIeCVeB.d.mts +0 -136
- package/dist/esm/chunk-EPF2YSMX.mjs +0 -1
- package/dist/esm/chunk-EPF2YSMX.mjs.map +0 -1
- package/dist/esm/chunk-UPJLWPEL.mjs +0 -1
- package/dist/esm/chunk-UPJLWPEL.mjs.map +0 -1
- package/dist/esm/chunk-UUG7DSTN.mjs +0 -1
- package/dist/esm/chunk-UUG7DSTN.mjs.map +0 -1
- package/dist/esm/chunk-XQJDGUQE.mjs +0 -1
- package/dist/esm/chunk-XQJDGUQE.mjs.map +0 -1
- package/dist/esm/index.d-y2b-8_3Y.d.mts +0 -236
- package/dist/esm/metafile-esm.json +0 -1
- package/dist/esm/validation.mjs.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=Object.freeze({ROUTER_NOT_STARTED:`NOT_STARTED`,NO_START_PATH_OR_STATE:`NO_START_PATH_OR_STATE`,ROUTER_ALREADY_STARTED:`ALREADY_STARTED`,ROUTE_NOT_FOUND:`ROUTE_NOT_FOUND`,SAME_STATES:`SAME_STATES`,CANNOT_DEACTIVATE:`CANNOT_DEACTIVATE`,CANNOT_ACTIVATE:`CANNOT_ACTIVATE`,TRANSITION_ERR:`TRANSITION_ERR`,TRANSITION_CANCELLED:`CANCELLED`,ROUTER_DISPOSED:`DISPOSED`,PLUGIN_CONFLICT:`PLUGIN_CONFLICT`}),t=`@@router/UNKNOWN_ROUTE`,n={UNKNOWN_ROUTE:t},r={ROUTER_START:`onStart`,ROUTER_STOP:`onStop`,TRANSITION_START:`onTransitionStart`,TRANSITION_CANCEL:`onTransitionCancel`,TRANSITION_SUCCESS:`onTransitionSuccess`,TRANSITION_ERROR:`onTransitionError`},i={ROUTER_START:`$start`,ROUTER_STOP:`$stop`,TRANSITION_START:`$$start`,TRANSITION_CANCEL:`$$cancel`,TRANSITION_SUCCESS:`$$success`,TRANSITION_ERROR:`$$error`},a={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},o=Object.freeze({});function s(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.name==`string`&&typeof t.path==`string`&&typeof t.params==`object`&&t.params!==null}function c(e){if(!e)return e;if(!s(e))throw TypeError(`[deepFreezeState] Expected valid State object, got: ${typeof e}`);let t=structuredClone(e),n=new WeakSet;function r(e){if(!(typeof e!=`object`||!e)&&!n.has(e))if(n.add(e),Object.freeze(e),Array.isArray(e))for(let t of e)r(t);else for(let t in e)r(e[t])}return r(t),t}const l=new WeakSet;function u(e){if(!(typeof e!=`object`||!e)&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(let t of e)u(t);else for(let t in e)u(e[t])}function d(e){return!e||l.has(e)?e:(u(e),l.add(e),e)}function f(e={}){return{...a,...e}}const p=new Set(Object.values(e)),m=new Set([`code`,`segment`,`path`,`redirect`]),h=new Set([`setCode`,`setErrorInstance`,`setAdditionalFields`,`hasField`,`getField`,`toJSON`]);var g=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:n,path:r,redirect:i,...a}={}){super(t??e),this.code=e,this.segment=n,this.path=r,this.redirect=i?c(i):void 0;for(let[e,t]of Object.entries(a)){if(m.has(e))throw TypeError(`[RouterError] Cannot set reserved property "${e}"`);h.has(e)||(this[e]=t)}}setCode(e){this.code=e,p.has(this.message)&&(this.message=e)}setErrorInstance(e){if(!e)throw 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(let[t,n]of Object.entries(e)){if(m.has(t))throw TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);h.has(t)||(this[t]=n)}}hasField(e){return e in this}getField(e){return this[e]}toJSON(){let e={code:this.code,message:this.message};this.segment!==void 0&&(e.segment=this.segment),this.path!==void 0&&(e.path=this.path),this.redirect!==void 0&&(e.redirect=this.redirect);let t=new Set([`code`,`message`,`segment`,`path`,`redirect`,`stack`]);for(let n in this)Object.hasOwn(this,n)&&!t.has(n)&&(e[n]=this[n]);return e}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return r}});
|
|
2
|
+
//# sourceMappingURL=RouterError-BkgjTHQg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouterError-BkgjTHQg.js","names":[],"sources":["../../src/constants.ts","../../src/helpers.ts","../../src/RouterError.ts"],"sourcesContent":["// packages/core/src/constants.ts\n\nimport type {\n EventToNameMap,\n EventToPluginMap,\n ErrorCodeToValueMap,\n ErrorCodeKeys,\n ErrorCodeValues,\n} from \"@real-router/types\";\n\nexport type ConstantsKeys = \"UNKNOWN_ROUTE\";\n\nexport type Constants = Record<ConstantsKeys, string>;\n\n// =============================================================================\n// Error Codes (migrated from router-error)\n// =============================================================================\n\nexport type ErrorCodes = Record<ErrorCodeKeys, ErrorCodeValues>;\n\n/**\n * Error codes for router operations.\n * Used to identify specific failure scenarios in navigation and lifecycle.\n * Frozen to prevent accidental modifications.\n */\nexport const errorCodes: ErrorCodeToValueMap = Object.freeze({\n ROUTER_NOT_STARTED: \"NOT_STARTED\", // navigate() called before start()\n NO_START_PATH_OR_STATE: \"NO_START_PATH_OR_STATE\", // start() without initial route\n ROUTER_ALREADY_STARTED: \"ALREADY_STARTED\", // start() called twice\n ROUTE_NOT_FOUND: \"ROUTE_NOT_FOUND\", // Navigation to non-existent route\n SAME_STATES: \"SAME_STATES\", // Navigate to current route without reload\n CANNOT_DEACTIVATE: \"CANNOT_DEACTIVATE\", // canDeactivate guard blocked navigation\n CANNOT_ACTIVATE: \"CANNOT_ACTIVATE\", // canActivate guard blocked navigation\n TRANSITION_ERR: \"TRANSITION_ERR\", // Generic transition failure\n TRANSITION_CANCELLED: \"CANCELLED\", // Navigation cancelled by user or new navigation\n ROUTER_DISPOSED: \"DISPOSED\", // Router has been disposed\n PLUGIN_CONFLICT: \"PLUGIN_CONFLICT\", // Plugin tried to extend router with already-existing property\n});\n\n/**\n * General router constants.\n * Special route names and identifiers.\n */\nexport const UNKNOWN_ROUTE = \"@@router/UNKNOWN_ROUTE\";\n\nexport const constants: Constants = {\n UNKNOWN_ROUTE,\n};\n\n/**\n * Plugin method names.\n * Maps to methods that plugins can implement to hook into router lifecycle.\n */\nexport const plugins: EventToPluginMap = {\n ROUTER_START: \"onStart\", // Plugin method called when router starts\n ROUTER_STOP: \"onStop\", // Plugin method called when router stops\n TRANSITION_START: \"onTransitionStart\", // Plugin method called when navigation begins\n TRANSITION_CANCEL: \"onTransitionCancel\", // Plugin method called when navigation cancelled\n TRANSITION_SUCCESS: \"onTransitionSuccess\", // Plugin method called when navigation succeeds\n TRANSITION_ERROR: \"onTransitionError\", // Plugin method called when navigation fails\n};\n\n/**\n * Event names for router event system.\n * Used with addEventListener/removeEventListener for reactive subscriptions.\n */\nexport const events: EventToNameMap = {\n ROUTER_START: \"$start\", // Emitted when router.start() succeeds\n ROUTER_STOP: \"$stop\", // Emitted when router.stop() is called\n TRANSITION_START: \"$$start\", // Emitted when navigation begins\n TRANSITION_CANCEL: \"$$cancel\", // Emitted when navigation is cancelled\n TRANSITION_SUCCESS: \"$$success\", // Emitted when navigation completes successfully\n TRANSITION_ERROR: \"$$error\", // Emitted when navigation fails\n};\n\nexport const DEFAULT_LIMITS = {\n maxDependencies: 100,\n maxPlugins: 50,\n maxListeners: 10_000,\n warnListeners: 1000,\n maxEventDepth: 5,\n maxLifecycleHandlers: 200,\n} as const;\n\nexport const EMPTY_PARAMS: Readonly<Record<string, never>> = Object.freeze({});\n","// packages/core/src/helpers.ts\n\nimport { DEFAULT_LIMITS } from \"./constants\";\n\nimport type { Limits } from \"./types\";\nimport type { State, LimitsConfig } from \"@real-router/types\";\n\n// =============================================================================\n// State Helpers\n// =============================================================================\n\n/**\n * Structural type guard for State object.\n * Only checks required fields exist with correct types.\n * Does NOT validate params serializability (allows circular refs).\n *\n * Use `isState` from type-guards for full validation (serializable params).\n * Use this for internal operations like deepFreezeState that handle any object structure.\n *\n * @param value - Value to check\n * @returns true if value has State structure\n * @internal\n */\nfunction isStateStructural(value: unknown): value is State {\n if (value === null || typeof value !== \"object\") {\n return false;\n }\n\n const obj = value as Record<string, unknown>;\n\n return (\n typeof obj.name === \"string\" &&\n typeof obj.path === \"string\" &&\n typeof obj.params === \"object\" &&\n obj.params !== null\n );\n}\n\n/**\n * Deep freezes State object to prevent mutations.\n * Creates a deep clone first, then recursively freezes the clone and all nested objects.\n * Uses simple recursive freezing after cloning (no need for WeakSet since clone has no circular refs).\n *\n * @param state - The State object to freeze\n * @returns A frozen deep clone of the state\n * @throws {TypeError} If state is not a valid State object\n *\n * @example\n * const state = { name: 'home', params: {}, path: '/' };\n * const frozen = deepFreezeState(state);\n * // frozen.params is now immutable\n * // original state is unchanged\n */\nexport function deepFreezeState<T extends State>(state: T): T {\n // Early return for null/undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!state) {\n return state;\n }\n\n // Validate State structure (structural check, allows circular refs)\n if (!isStateStructural(state)) {\n throw new TypeError(\n `[deepFreezeState] Expected valid State object, got: ${typeof state}`,\n );\n }\n\n // Create a deep clone to avoid mutating the original\n // structuredClone preserves circular references, so we need to track visited objects\n const clonedState = structuredClone(state);\n\n // WeakSet to track visited objects (prevent infinite recursion with circular refs)\n const visited = new WeakSet<object>();\n\n // Recursive freeze function with circular reference protection\n function freezeClonedRecursive(obj: unknown): void {\n // Skip primitives, null, undefined\n // Note: typeof undefined === \"undefined\" !== \"object\", so checking undefined is redundant\n if (obj === null || typeof obj !== \"object\") {\n return;\n }\n\n // Skip already visited objects (circular reference protection)\n if (visited.has(obj)) {\n return;\n }\n\n // Mark as visited\n visited.add(obj);\n\n // Freeze the object/array itself\n Object.freeze(obj);\n\n // Iterate without Object.values() allocation\n if (Array.isArray(obj)) {\n for (const item of obj) {\n freezeClonedRecursive(item);\n }\n } else {\n for (const key in obj) {\n freezeClonedRecursive((obj as Record<string, unknown>)[key]);\n }\n }\n }\n\n // Freeze the entire cloned state tree\n freezeClonedRecursive(clonedState);\n\n return clonedState;\n}\n\n// WeakSet to track already frozen root objects for O(1) re-freeze check\nconst frozenRoots = new WeakSet<object>();\n\n// Module-scope recursive freeze function - better JIT optimization, no allocation per call\nfunction freezeRecursive(obj: unknown): void {\n // Skip primitives, null\n if (obj === null || typeof obj !== \"object\") {\n return;\n }\n\n // Skip already frozen objects (handles potential shared refs)\n if (Object.isFrozen(obj)) {\n return;\n }\n\n // Freeze the object/array\n Object.freeze(obj);\n\n // Iterate without Object.values() allocation\n if (Array.isArray(obj)) {\n for (const item of obj) {\n freezeRecursive(item);\n }\n } else {\n for (const key in obj) {\n freezeRecursive((obj as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Freezes State object in-place without cloning.\n * Optimized for hot paths where state is known to be a fresh object.\n *\n * IMPORTANT: Only use this when you know the state is a fresh object\n * that hasn't been exposed to external code yet (e.g., from makeState()).\n *\n * @param state - The State object to freeze (must be a fresh object)\n * @returns The same state object, now frozen\n * @internal\n */\nexport function freezeStateInPlace<T extends State>(state: T): T {\n // Early return for null/undefined - state from makeState() is never null\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!state) {\n return state;\n }\n\n // Fast path: already processed root object - O(1) check\n if (frozenRoots.has(state)) {\n return state;\n }\n\n freezeRecursive(state);\n\n // Mark root as processed for future calls\n frozenRoots.add(state);\n\n return state;\n}\n\n/**\n * Merges user limits with defaults.\n * Returns frozen object for immutability.\n */\nexport function createLimits(userLimits: Partial<LimitsConfig> = {}): Limits {\n return { ...DEFAULT_LIMITS, ...userLimits };\n}\n","// packages/core/src/RouterError.ts\n\nimport { errorCodes } from \"./constants\";\nimport { deepFreezeState } from \"./helpers\";\n\nimport type { State } from \"@real-router/types\";\n\n// Pre-compute Set of error code values for O(1) lookup in setCode()\n// This avoids creating array and doing linear search on every setCode() call\nconst errorCodeValues = new Set(Object.values(errorCodes));\n\n// Reserved built-in properties - throw error if user tries to set these\nconst reservedProperties = new Set([\"code\", \"segment\", \"path\", \"redirect\"]);\n\n// Reserved method names - silently ignore attempts to overwrite these\nconst reservedMethods = new Set([\n \"setCode\",\n \"setErrorInstance\",\n \"setAdditionalFields\",\n \"hasField\",\n \"getField\",\n \"toJSON\",\n]);\n\nexport class RouterError extends Error {\n [key: string]: unknown;\n\n // Using public properties to ensure structural compatibility\n // with RouterError interface in core-types\n readonly segment: string | undefined;\n readonly path: string | undefined;\n readonly redirect: State | undefined;\n\n // Note: code appears to be writable but setCode() should be used\n // to properly update both code and message together\n code: string;\n\n /**\n * Creates a new RouterError instance.\n *\n * The options object accepts built-in fields (message, segment, path, redirect)\n * and any additional custom fields, which will all be attached to the error instance.\n *\n * @param code - The error code (e.g., \"ROUTE_NOT_FOUND\", \"CANNOT_ACTIVATE\")\n * @param options - Optional configuration object\n * @param options.message - Custom error message (defaults to code if not provided)\n * @param options.segment - The route segment where the error occurred\n * @param options.path - The full path where the error occurred\n * @param options.redirect - Optional redirect state for navigation errors\n *\n * @example\n * ```typescript\n * // Basic error\n * const err1 = new RouterError(\"ROUTE_NOT_FOUND\");\n *\n * // Error with custom message\n * const err2 = new RouterError(\"ERR\", { message: \"Something went wrong\" });\n *\n * // Error with context and custom fields\n * const err3 = new RouterError(\"CANNOT_ACTIVATE\", {\n * message: \"Insufficient permissions\",\n * segment: \"admin\",\n * path: \"/admin/users\",\n * userId: \"123\" // custom field\n * });\n *\n * // Error with redirect\n * const err4 = new RouterError(\"TRANSITION_ERR\", {\n * redirect: { name: \"home\", path: \"/\", params: {} }\n * });\n * ```\n */\n constructor(\n code: string,\n {\n message,\n segment,\n path,\n redirect,\n ...rest\n }: {\n [key: string]: unknown;\n message?: string | undefined;\n segment?: string | undefined;\n path?: string | undefined;\n redirect?: State | undefined;\n } = {},\n ) {\n super(message ?? code);\n\n this.code = code;\n this.segment = segment;\n this.path = path;\n // Deep freeze redirect to prevent mutations (creates a frozen clone)\n this.redirect = redirect ? deepFreezeState(redirect) : undefined;\n\n // Assign custom fields, checking reserved properties and filtering out reserved method names\n // Issue #39: Throw for reserved properties to match setAdditionalFields behavior\n for (const [key, value] of Object.entries(rest)) {\n if (reservedProperties.has(key)) {\n throw new TypeError(\n `[RouterError] Cannot set reserved property \"${key}\"`,\n );\n }\n\n if (!reservedMethods.has(key)) {\n this[key] = value;\n }\n }\n }\n\n /**\n * Updates the error code and conditionally updates the message.\n *\n * If the current message is one of the standard error code values\n * (e.g., \"ROUTE_NOT_FOUND\", \"SAME_STATES\"), it will be replaced with the new code.\n * This allows keeping error messages in sync with codes when using standard error codes.\n *\n * If the message is custom (not a standard error code), it will be preserved.\n *\n * @param newCode - The new error code to set\n *\n * @example\n * // Message follows code (standard error code as message)\n * const err = new RouterError(\"ROUTE_NOT_FOUND\", { message: \"ROUTE_NOT_FOUND\" });\n * err.setCode(\"CUSTOM_ERROR\"); // message becomes \"CUSTOM_ERROR\"\n *\n * @example\n * // Custom message is preserved\n * const err = new RouterError(\"ERR\", { message: \"Custom error message\" });\n * err.setCode(\"NEW_CODE\"); // message stays \"Custom error message\"\n */\n setCode(newCode: string): void {\n this.code = newCode;\n\n // Only update message if it's a standard error code value (not a custom message)\n if (errorCodeValues.has(this.message)) {\n this.message = newCode;\n }\n }\n\n /**\n * Copies properties from another Error instance to this RouterError.\n *\n * This method updates the message, cause, and stack trace from the provided error.\n * Useful for wrapping native errors while preserving error context.\n *\n * @param err - The Error instance to copy properties from\n * @throws {TypeError} If err is null or undefined\n *\n * @example\n * ```typescript\n * const routerErr = new RouterError(\"TRANSITION_ERR\");\n * try {\n * // some operation that might fail\n * } catch (nativeErr) {\n * routerErr.setErrorInstance(nativeErr);\n * throw routerErr;\n * }\n * ```\n */\n setErrorInstance(err: Error): void {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!err) {\n throw new TypeError(\n \"[RouterError.setErrorInstance] err parameter is required and must be an Error instance\",\n );\n }\n\n this.message = err.message;\n this.cause = err.cause;\n this.stack = err.stack ?? \"\";\n }\n\n /**\n * Adds custom fields to the error object.\n *\n * This method allows attaching arbitrary data to the error for debugging or logging purposes.\n * All fields become accessible as properties on the error instance and are included in JSON serialization.\n *\n * Reserved method names (setCode, setErrorInstance, setAdditionalFields, hasField, getField, toJSON)\n * are automatically filtered out to prevent accidental overwriting of class methods.\n *\n * @param fields - Object containing custom fields to add to the error\n *\n * @example\n * ```typescript\n * const err = new RouterError(\"CANNOT_ACTIVATE\");\n * err.setAdditionalFields({\n * userId: \"123\",\n * attemptedRoute: \"/admin\",\n * reason: \"insufficient permissions\"\n * });\n *\n * console.log(err.userId); // \"123\"\n * console.log(JSON.stringify(err)); // includes all custom fields\n * ```\n */\n setAdditionalFields(fields: Record<string, unknown>): void {\n // Assign fields, throwing for reserved properties, silently ignoring methods\n for (const [key, value] of Object.entries(fields)) {\n if (reservedProperties.has(key)) {\n throw new TypeError(\n `[RouterError.setAdditionalFields] Cannot set reserved property \"${key}\"`,\n );\n }\n\n if (!reservedMethods.has(key)) {\n this[key] = value;\n }\n }\n }\n\n /**\n * Checks if a custom field exists on the error object.\n *\n * This method checks for both custom fields added via setAdditionalFields()\n * and built-in fields (code, message, segment, etc.).\n *\n * @param key - The field name to check\n * @returns `true` if the field exists, `false` otherwise\n *\n * @example\n * ```typescript\n * const err = new RouterError(\"ERR\", { segment: \"users\" });\n * err.setAdditionalFields({ userId: \"123\" });\n *\n * err.hasField(\"userId\"); // true\n * err.hasField(\"segment\"); // true\n * err.hasField(\"unknown\"); // false\n * ```\n */\n hasField(key: string): boolean {\n return key in this;\n }\n\n /**\n * Retrieves a custom field value from the error object.\n *\n * This method can access both custom fields and built-in fields.\n * Returns `undefined` if the field doesn't exist.\n *\n * @param key - The field name to retrieve\n * @returns The field value, or `undefined` if it doesn't exist\n *\n * @example\n * ```typescript\n * const err = new RouterError(\"ERR\");\n * err.setAdditionalFields({ userId: \"123\", role: \"admin\" });\n *\n * err.getField(\"userId\"); // \"123\"\n * err.getField(\"role\"); // \"admin\"\n * err.getField(\"code\"); // \"ERR\" (built-in field)\n * err.getField(\"unknown\"); // undefined\n * ```\n */\n getField(key: string): unknown {\n return this[key];\n }\n\n /**\n * Serializes the error to a JSON-compatible object.\n *\n * This method is automatically called by JSON.stringify() and includes:\n * - Built-in fields: code, message, segment (if set), path (if set), redirect (if set)\n * - All custom fields added via setAdditionalFields() or constructor\n * - Excludes: stack trace (for security/cleanliness)\n *\n * @returns A plain object representation of the error, suitable for JSON serialization\n *\n * @example\n * ```typescript\n * const err = new RouterError(\"ROUTE_NOT_FOUND\", {\n * message: \"Route not found\",\n * path: \"/admin/users/123\"\n * });\n * err.setAdditionalFields({ userId: \"123\" });\n *\n * JSON.stringify(err);\n * // {\n * // \"code\": \"ROUTE_NOT_FOUND\",\n * // \"message\": \"Route not found\",\n * // \"path\": \"/admin/users/123\",\n * // \"userId\": \"123\"\n * // }\n * ```\n */\n toJSON(): Record<string, unknown> {\n const result: Record<string, unknown> = {\n code: this.code,\n message: this.message,\n };\n\n if (this.segment !== undefined) {\n result.segment = this.segment;\n }\n if (this.path !== undefined) {\n result.path = this.path;\n }\n if (this.redirect !== undefined) {\n result.redirect = this.redirect;\n }\n\n // add all public fields\n // Using Set.has() for O(1) lookup instead of Array.includes() O(n)\n // Overall complexity: O(n) instead of O(n*m)\n const excludeKeys = new Set([\n \"code\",\n \"message\",\n \"segment\",\n \"path\",\n \"redirect\",\n \"stack\",\n ]);\n\n for (const key in this) {\n if (Object.hasOwn(this, key) && !excludeKeys.has(key)) {\n result[key] = this[key];\n }\n }\n\n return result;\n }\n}\n"],"mappings":"AAyBA,MAAa,EAAkC,OAAO,OAAO,CAC3D,mBAAoB,cACpB,uBAAwB,yBACxB,uBAAwB,kBACxB,gBAAiB,kBACjB,YAAa,cACb,kBAAmB,oBACnB,gBAAiB,kBACjB,eAAgB,iBAChB,qBAAsB,YACtB,gBAAiB,WACjB,gBAAiB,kBAClB,CAAC,CAMW,EAAgB,yBAEhB,EAAuB,CAClC,gBACD,CAMY,EAA4B,CACvC,aAAc,UACd,YAAa,SACb,iBAAkB,oBAClB,kBAAmB,qBACnB,mBAAoB,sBACpB,iBAAkB,oBACnB,CAMY,EAAyB,CACpC,aAAc,SACd,YAAa,QACb,iBAAkB,UAClB,kBAAmB,WACnB,mBAAoB,YACpB,iBAAkB,UACnB,CAEY,EAAiB,CAC5B,gBAAiB,IACjB,WAAY,GACZ,aAAc,IACd,cAAe,IACf,cAAe,EACf,qBAAsB,IACvB,CAEY,EAAgD,OAAO,OAAO,EAAE,CAAC,CC7D9E,SAAS,EAAkB,EAAgC,CACzD,GAAsB,OAAO,GAAU,WAAnC,EACF,MAAO,GAGT,IAAM,EAAM,EAEZ,OACE,OAAO,EAAI,MAAS,UACpB,OAAO,EAAI,MAAS,UACpB,OAAO,EAAI,QAAW,UACtB,EAAI,SAAW,KAmBnB,SAAgB,EAAiC,EAAa,CAG5D,GAAI,CAAC,EACH,OAAO,EAIT,GAAI,CAAC,EAAkB,EAAM,CAC3B,MAAU,UACR,uDAAuD,OAAO,IAC/D,CAKH,IAAM,EAAc,gBAAgB,EAAM,CAGpC,EAAU,IAAI,QAGpB,SAAS,EAAsB,EAAoB,CAG7C,KAAgB,OAAO,GAAQ,WAA/B,IAKA,GAAQ,IAAI,EAAI,CAWpB,GANA,EAAQ,IAAI,EAAI,CAGhB,OAAO,OAAO,EAAI,CAGd,MAAM,QAAQ,EAAI,CACpB,IAAK,IAAM,KAAQ,EACjB,EAAsB,EAAK,MAG7B,IAAK,IAAM,KAAO,EAChB,EAAuB,EAAgC,GAAK,CAQlE,OAFA,EAAsB,EAAY,CAE3B,EAIT,MAAM,EAAc,IAAI,QAGxB,SAAS,EAAgB,EAAoB,CAEvC,KAAgB,OAAO,GAAQ,WAA/B,IAKA,QAAO,SAAS,EAAI,CAQxB,GAHA,OAAO,OAAO,EAAI,CAGd,MAAM,QAAQ,EAAI,CACpB,IAAK,IAAM,KAAQ,EACjB,EAAgB,EAAK,MAGvB,IAAK,IAAM,KAAO,EAChB,EAAiB,EAAgC,GAAK,CAgB5D,SAAgB,EAAoC,EAAa,CAiB/D,MAdI,CAAC,GAKD,EAAY,IAAI,EAAM,CACjB,GAGT,EAAgB,EAAM,CAGtB,EAAY,IAAI,EAAM,CAEf,GAOT,SAAgB,EAAa,EAAoC,EAAE,CAAU,CAC3E,MAAO,CAAE,GAAG,EAAgB,GAAG,EAAY,CCxK7C,MAAM,EAAkB,IAAI,IAAI,OAAO,OAAO,EAAW,CAAC,CAGpD,EAAqB,IAAI,IAAI,CAAC,OAAQ,UAAW,OAAQ,WAAW,CAAC,CAGrE,EAAkB,IAAI,IAAI,CAC9B,UACA,mBACA,sBACA,WACA,WACA,SACD,CAAC,CAEF,IAAa,EAAb,cAAiC,KAAM,CAKrC,QACA,KACA,SAIA,KAqCA,YACE,EACA,CACE,UACA,UACA,OACA,WACA,GAAG,GAOD,EAAE,CACN,CACA,MAAM,GAAW,EAAK,CAEtB,KAAK,KAAO,EACZ,KAAK,QAAU,EACf,KAAK,KAAO,EAEZ,KAAK,SAAW,EAAW,EAAgB,EAAS,CAAG,IAAA,GAIvD,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAK,CAAE,CAC/C,GAAI,EAAmB,IAAI,EAAI,CAC7B,MAAU,UACR,+CAA+C,EAAI,GACpD,CAGE,EAAgB,IAAI,EAAI,GAC3B,KAAK,GAAO,IA0BlB,QAAQ,EAAuB,CAC7B,KAAK,KAAO,EAGR,EAAgB,IAAI,KAAK,QAAQ,GACnC,KAAK,QAAU,GAwBnB,iBAAiB,EAAkB,CAEjC,GAAI,CAAC,EACH,MAAU,UACR,yFACD,CAGH,KAAK,QAAU,EAAI,QACnB,KAAK,MAAQ,EAAI,MACjB,KAAK,MAAQ,EAAI,OAAS,GA2B5B,oBAAoB,EAAuC,CAEzD,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAAE,CACjD,GAAI,EAAmB,IAAI,EAAI,CAC7B,MAAU,UACR,mEAAmE,EAAI,GACxE,CAGE,EAAgB,IAAI,EAAI,GAC3B,KAAK,GAAO,IAwBlB,SAAS,EAAsB,CAC7B,OAAO,KAAO,KAuBhB,SAAS,EAAsB,CAC7B,OAAO,KAAK,GA8Bd,QAAkC,CAChC,IAAM,EAAkC,CACtC,KAAM,KAAK,KACX,QAAS,KAAK,QACf,CAEG,KAAK,UAAY,IAAA,KACnB,EAAO,QAAU,KAAK,SAEpB,KAAK,OAAS,IAAA,KAChB,EAAO,KAAO,KAAK,MAEjB,KAAK,WAAa,IAAA,KACpB,EAAO,SAAW,KAAK,UAMzB,IAAM,EAAc,IAAI,IAAI,CAC1B,OACA,UACA,UACA,OACA,WACA,QACD,CAAC,CAEF,IAAK,IAAM,KAAO,KACZ,OAAO,OAAO,KAAM,EAAI,EAAI,CAAC,EAAY,IAAI,EAAI,GACnD,EAAO,GAAO,KAAK,IAIvB,OAAO"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//#region src/types/RouterValidator.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* RouterValidator interface - defines all validation methods used by the router.
|
|
4
|
+
*
|
|
5
|
+
* This interface is implemented by the validation plugin and injected into RouterInternals.
|
|
6
|
+
* When ctx.validator is null (default), validation is skipped.
|
|
7
|
+
* When ctx.validator is set (by validation plugin), all methods are called.
|
|
8
|
+
*
|
|
9
|
+
* All parameters use `unknown` type to avoid coupling to internal type names.
|
|
10
|
+
*/
|
|
11
|
+
interface RouterValidator {
|
|
12
|
+
/**
|
|
13
|
+
* Route validation methods
|
|
14
|
+
*/
|
|
15
|
+
routes: {
|
|
16
|
+
validateBuildPathArgs: (route: unknown) => void;
|
|
17
|
+
validateMatchPathArgs: (path: unknown) => void;
|
|
18
|
+
validateIsActiveRouteArgs: (name: unknown, params: unknown, strict: unknown, ignoreQP: unknown) => void;
|
|
19
|
+
validateShouldUpdateNodeArgs: (name: unknown) => void;
|
|
20
|
+
validateStateBuilderArgs: (name: unknown, params: unknown, caller: string) => void;
|
|
21
|
+
validateAddRouteArgs: (routes: unknown) => void;
|
|
22
|
+
validateRoutes: (routes: unknown[], tree: unknown) => void;
|
|
23
|
+
validateRemoveRouteArgs: (name: unknown) => void;
|
|
24
|
+
validateUpdateRouteBasicArgs: (name: unknown, updates: unknown) => void;
|
|
25
|
+
validateUpdateRoutePropertyTypes: (name: string, updates: unknown) => void;
|
|
26
|
+
validateUpdateRoute: (name: string, updates: unknown, tree: unknown) => void;
|
|
27
|
+
validateParentOption: (parent: unknown, tree: unknown) => void;
|
|
28
|
+
validateRouteName: (name: unknown, caller: string) => void;
|
|
29
|
+
throwIfInternalRoute: (name: unknown, caller: string) => void;
|
|
30
|
+
throwIfInternalRouteInArray: (routes: unknown[], caller: string) => void;
|
|
31
|
+
validateExistingRoutes: (store: unknown) => void;
|
|
32
|
+
validateForwardToConsistency: (store: unknown) => void;
|
|
33
|
+
validateSetRootPathArgs: (rootPath: unknown) => void;
|
|
34
|
+
guardRouteCallbacks: (route: unknown) => void;
|
|
35
|
+
guardNoAsyncCallbacks: (route: unknown) => void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Options validation methods
|
|
39
|
+
*/
|
|
40
|
+
options: {
|
|
41
|
+
validateLimitValue: (name: string, value: unknown) => void;
|
|
42
|
+
validateLimits: (limits: unknown) => void;
|
|
43
|
+
validateOptions: (options: unknown, methodName: string) => void;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Dependencies validation methods
|
|
47
|
+
*/
|
|
48
|
+
dependencies: {
|
|
49
|
+
validateDependencyName: (name: unknown, caller: string) => void;
|
|
50
|
+
validateSetDependencyArgs: (name: unknown, value: unknown, caller: string) => void;
|
|
51
|
+
validateDependenciesObject: (deps: unknown, caller: string) => void;
|
|
52
|
+
validateDependencyExists: (name: string, store: unknown) => void;
|
|
53
|
+
validateDependencyLimit: (store: unknown, limits: unknown) => void;
|
|
54
|
+
validateDependenciesStructure: (store: unknown) => void;
|
|
55
|
+
validateDependencyCount: (store: unknown, methodName: string) => void;
|
|
56
|
+
validateCloneArgs: (dependencies: unknown) => void;
|
|
57
|
+
warnOverwrite: (name: string, methodName: string) => void;
|
|
58
|
+
warnBatchOverwrite: (keys: string[], methodName: string) => void;
|
|
59
|
+
warnRemoveNonExistent: (name: unknown) => void;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Plugin validation methods
|
|
63
|
+
*/
|
|
64
|
+
plugins: {
|
|
65
|
+
validatePluginLimit: (count: number, limits: unknown) => void;
|
|
66
|
+
validateNoDuplicatePlugins: (factory: unknown, factories: unknown[]) => void;
|
|
67
|
+
validatePluginKeys: (plugin: unknown) => void;
|
|
68
|
+
validateCountThresholds: (count: number) => void;
|
|
69
|
+
warnBatchDuplicates: (plugins: unknown[]) => void;
|
|
70
|
+
warnPluginMethodType: (methodName: string) => void;
|
|
71
|
+
warnPluginAfterStart: (methodName: string) => void;
|
|
72
|
+
validateAddInterceptorArgs: (method: unknown, fn: unknown) => void;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Lifecycle guard validation methods
|
|
76
|
+
*/
|
|
77
|
+
lifecycle: {
|
|
78
|
+
validateHandler: (handler: unknown, caller: string) => void;
|
|
79
|
+
validateNotRegistering: (name: string, guards: unknown, caller: string) => void;
|
|
80
|
+
validateHandlerLimit: (count: number, limits: unknown, caller: string) => void;
|
|
81
|
+
validateCountThresholds: (count: number, methodName: string) => void;
|
|
82
|
+
warnOverwrite: (name: string, type: string, methodName: string) => void;
|
|
83
|
+
warnAsyncGuardSync: (name: string, methodName: string) => void;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Navigation validation methods
|
|
87
|
+
*/
|
|
88
|
+
navigation: {
|
|
89
|
+
validateNavigateArgs: (name: unknown) => void;
|
|
90
|
+
validateNavigateToDefaultArgs: (options: unknown) => void;
|
|
91
|
+
validateNavigationOptions: (options: unknown, caller: string) => void;
|
|
92
|
+
validateParams: (params: unknown, methodName: string) => void;
|
|
93
|
+
validateStartArgs: (path: unknown) => void;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* State validation methods
|
|
97
|
+
*/
|
|
98
|
+
state: {
|
|
99
|
+
validateMakeStateArgs: (name: unknown, params: unknown, path: unknown) => void;
|
|
100
|
+
validateAreStatesEqualArgs: (s1: unknown, s2: unknown, ignoreQP: unknown) => void;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Event bus validation methods
|
|
104
|
+
*/
|
|
105
|
+
eventBus: {
|
|
106
|
+
validateEventName: (name: unknown) => void;
|
|
107
|
+
validateListenerArgs: (name: unknown, cb: unknown) => void;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { RouterValidator as t };
|
|
112
|
+
//# sourceMappingURL=RouterValidator-TUi8eT8Q.d.ts.map
|
package/dist/cjs/api.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { R as RouteTree } from './index.d-y2b-8_3Y.js';
|
|
4
|
-
import { R as Router$1 } from './Router-DoJ3NWsT.js';
|
|
1
|
+
import { f as RouteTree, t as Router$1 } from "./Router-73rMK2YI.js";
|
|
2
|
+
import { DefaultDependencies, DependenciesApi, LifecycleApi, PluginApi as PluginApi$1, Router, RoutesApi } from "@real-router/types";
|
|
5
3
|
|
|
4
|
+
//#region src/api/types.d.ts
|
|
6
5
|
interface PluginApi extends Omit<PluginApi$1, "getTree"> {
|
|
7
|
-
|
|
6
|
+
getTree: () => RouteTree;
|
|
8
7
|
}
|
|
9
|
-
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/api/getPluginApi.d.ts
|
|
10
10
|
declare function getPluginApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>): PluginApi;
|
|
11
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/api/getRoutesApi.d.ts
|
|
12
13
|
declare function getRoutesApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>): RoutesApi<Dependencies>;
|
|
13
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/api/getDependenciesApi.d.ts
|
|
14
16
|
declare function getDependenciesApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>): DependenciesApi<Dependencies>;
|
|
15
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/api/getLifecycleApi.d.ts
|
|
16
19
|
declare function getLifecycleApi<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>): LifecycleApi<Dependencies>;
|
|
17
|
-
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/api/cloneRouter.d.ts
|
|
18
22
|
declare function cloneRouter<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>, dependencies?: Dependencies): Router$1<Dependencies>;
|
|
19
|
-
|
|
20
|
-
export { type PluginApi, cloneRouter, getDependenciesApi, getLifecycleApi, getPluginApi, getRoutesApi };
|
|
23
|
+
//#endregion
|
|
24
|
+
export { type DependenciesApi, type LifecycleApi, type PluginApi, type RoutesApi, cloneRouter, getDependenciesApi, getLifecycleApi, getPluginApi, getRoutesApi };
|
|
25
|
+
//# sourceMappingURL=api.d.ts.map
|
package/dist/cjs/api.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var e=require("@real-router/logger"),t=require("@real-router/fsm"),n=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),r="@@router/UNKNOWN_ROUTE",i="onStart",a="onStop",s="onTransitionStart",o="onTransitionCancel",c="onTransitionSuccess",d="onTransitionError",l="$start",u="$stop",h="$$start",f="$$cancel",p="$$success",g="$$error",m={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},v=Object.freeze({}),S=new WeakSet;function y(e){if(null!==e&&"object"==typeof e&&!Object.isFrozen(e))if(Object.freeze(e),Array.isArray(e))for(const t of e)y(t);else for(const t in e)y(e[t])}function w(e){return e?(S.has(e)||(y(e),S.add(e)),e):e}var T=new Set(Object.values(n)),b=new Set(["code","segment","path","redirect"]),A=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),P=class extends Error{segment;path;redirect;code;constructor(e,{message:t,segment:n,path:r,redirect:i,...a}={}){super(t??e),this.code=e,this.segment=n,this.path=r,this.redirect=i?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 n=structuredClone(e),r=new WeakSet;return function e(t){if(null===t||"object"!=typeof t)return;if(r.has(t))return;r.add(t),Object.freeze(t);const n=Array.isArray(t)?t:Object.values(t);for(const t of n)e(t)}(n),n}(i):void 0;for(const[e,t]of Object.entries(a)){if(b.has(e))throw new TypeError(`[RouterError] Cannot set reserved property "${e}"`);A.has(e)||(this[e]=t)}}setCode(e){this.code=e,T.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,n]of Object.entries(e)){if(b.has(t))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${t}"`);A.has(t)||(this[t]=n)}}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 n in this)Object.hasOwn(this,n)&&!t.has(n)&&(e[n]=this[n]);return e}};function N(e){if(e())throw new P(n.ROUTER_DISPOSED)}var O=new WeakMap;function D(e){const t=O.get(e);if(!t)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return t}function E(e,t,n){let r=t;for(const t of e){const e=r;r=(...n)=>t(e,...n)}return r(...n)}function R(e,t,n){return(r,i)=>{const a=n.get(e);return a&&0!==a.length?E(a,t,[r,i]):t(r,i)}}function C(e,t){for(const n of e){if(null===n||"object"!=typeof n||Array.isArray(n))throw new TypeError("route must be a non-array object");t?.routes.guardRouteCallbacks(n),t?.routes.guardNoAsyncCallbacks(n);const e=n.children;e&&C(e,t)}}function F(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function j(e){const t={name:e.name,path:e.path};return e.children&&(t.children=e.children.map(e=>j(e))),t}function L(e,t,n=""){for(let r=0;r<e.length;r++){const i=e[r],a=n?`${n}.${i.name}`:i.name;if(a===t)return e.splice(r,1),!0;if(i.children&&t.startsWith(`${a}.`)&&L(i.children,t,a))return!0}return!1}function M(e,t){for(const n of Object.keys(e))t(n)&&delete e[n]}function I(t){return!t||(e.logger.error("router.clearRoutes","Cannot clear routes while navigation is in progress. Wait for navigation to complete."),!1)}function $(e){return`(${e.replaceAll(/(^<|>$)/g,"")})`}var B=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,x=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,_=/\?(.+)$/,k=/[^\w!$'()*+,.:;|~-]/gu,U=/[^\w!$'()*+,.:;|~-]/u,G={default:e=>U.test(e)?e.replaceAll(k,e=>encodeURIComponent(e)):e,uri:encodeURI,uriComponent:encodeURIComponent,none:e=>e},z={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e};function q(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function W(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function V(e){const t={};if(0===e.length)return t;const n=e.split("&");for(const e of n){const n=e.indexOf("=");-1===n?t[e]="":t[e.slice(0,n)]=e.slice(n+1)}return t}function Q(e){const t=[];for(const n of Object.keys(e)){const r=e[n],i=encodeURIComponent(n);t.push(""===r?i:`${i}=${encodeURIComponent(String(r))}`)}return t.join("&")}function H(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function J(e){let t=0;for(;t<e.length;)if("%"===e[t]){if(t+2>=e.length)return!1;const n=e.codePointAt(t+1)??0,r=e.codePointAt(t+2)??0;if(!H(n)||!H(r))return!1;t+=3}else t++;return!0}var Y=/<[^>]*>/g;function K(e,t,n,r,i){const a=""===t.fullName;a||r.push(t);const s=t.absolute,o=t.paramMeta.pathPattern,c=s&&o.startsWith("~")?o.slice(1):o,d=(s?c:o).replaceAll(Y,""),l=s?d:(h=d,""===(u=n)?h:""===h?u:u+h);var u,h;let f=i;a||(f=function(e,t,n,r,i,a){const s=(m=r,W(n)===W(m)),o=Object.freeze([...i]),c=function(e){const t={};for(const n of e)t[n.fullName]=n.paramTypeMap;return Object.freeze(t)}(o),d=W(n),l=function(e,t){const n=[];e.length>0&&n.push(...e);for(const e of t)e.paramMeta.queryParams.length>0&&n.push(...e.paramMeta.queryParams);return n}(e.rootQueryParams,i),u=function(e){const t=new Map;for(const n of e)for(const[e,r]of n.paramMeta.constraintPatterns)t.set(e,r);return t}(i),h=s?W(r):d,{buildStaticParts:f,buildParamSlots:p}=function(e,t,n){const r=new Set,i=new Set;for(const e of t){for(const t of e.paramMeta.urlParams)r.add(t);for(const t of e.paramMeta.spatParams)i.add(t)}if(0===r.size)return{buildStaticParts:[e],buildParamSlots:[]};const a=[],s=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,d=0;for(;null!==(c=o.exec(e));){const t=c[1],r="?"===c[2];a.push(e.slice(d,c.index));const o=i.has(t);s.push({paramName:t,isOptional:r,encoder:o?e=>{const t=G[n],r=e.split("/");let i=t(r[0]);for(let e=1;e<r.length;e++)i+=`/${t(r[e])}`;return i}:G[n]}),d=c.index+c[0].length}return a.push(e.slice(d)),{buildStaticParts:a,buildParamSlots:s}}(h,s?i.slice(0,-1):i,e.options.urlParamsEncoding),g={name:t.fullName,parent:a,depth:i.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:u,hasConstraints:u.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(e=>e.paramName))};var m;return e.routesByName.set(t.fullName,g),e.segmentsByName.set(t.fullName,o),e.metaByName.set(t.fullName,c),s?function(e,t,n){var r,i;r=t,(function(e,t,n){const r=W(n);if("/"===r||""===r)return t;let i=t,a=1;const s=r.length;for(;a<=s;){const t=r.indexOf("/",a),n=-1===t?s:t;if(n<=a)break;i=Z(e,i,r.slice(a,n)),a=n+1}return i}(i=e,i.root,n)).slashChildRoute=r;const a=W(n),s=e.options.caseSensitive?a:a.toLowerCase();e.staticCache.has(s)&&e.staticCache.set(s,t)}(e,g,r):function(e,t,n,r,i){if(function(e,t,n){const r=W(n);"/"!==r?X(e,e.root,r,1,t):e.root.route=t}(e,t,n),0===i.paramMeta.urlParams.length){const n=e.options.caseSensitive?r:r.toLowerCase();e.staticCache.set(n,t)}}(e,g,n,d,t),g}(e,t,l,s?"":n,r,i));for(const n of t.children.values())K(e,n,l,r,f);a||r.pop()}function X(e,t,n,r,i){const a=n.length;for(;r<=a;){const s=n.indexOf("/",r),o=-1===s?a:s,c=n.slice(r,o);if(c.endsWith("?")){const r=c.slice(1).replaceAll(Y,"").replace(/\?$/,"");return t.paramChild??={node:q(),name:r},X(e,t.paramChild.node,n,o+1,i),void(o>=a?t.route??=i:X(e,t,n,o+1,i))}t=Z(e,t,c),r=o+1}t.route=i}function Z(e,t,n){if(n.startsWith("*")){const e=n.slice(1);return t.splatChild??={node:q(),name:e},t.splatChild.node}if(n.startsWith(":")){const e=n.slice(1).replaceAll(Y,"").replace(/\?$/,"");return t.paramChild??={node:q(),name:e},t.paramChild.node}const r=e.options.caseSensitive?n:n.toLowerCase();return r in t.staticChildren||(t.staticChildren[r]=q()),t.staticChildren[r]}var ee=/[\u0080-\uFFFF]/,te=class{get options(){return this.#e}#e;#t=q();#n=new Map;#r=new Map;#i=new Map;#a=new Map;#s="";#o=[];constructor(e){this.#e={caseSensitive:e?.caseSensitive??!0,strictTrailingSlash:e?.strictTrailingSlash??!1,strictQueryParams:e?.strictQueryParams??!1,urlParamsEncoding:e?.urlParamsEncoding??"default",parseQueryString:e?.parseQueryString??V,buildQueryString:e?.buildQueryString??Q}}registerTree(e){this.#o=e.paramMeta.queryParams,K({root:this.#t,options:this.#e,routesByName:this.#n,segmentsByName:this.#r,metaByName:this.#i,staticCache:this.#a,rootQueryParams:this.#o},e,"",[],null)}match(e){const t=this.#c(e);if(!t)return;const[n,r,i]=t,a=this.#e.caseSensitive?r:r.toLowerCase(),s=this.#a.get(a);if(s){if(this.#e.strictTrailingSlash&&!this.#d(n,s))return;return this.#l(s,{},i)}const o={},c=this.#u(r,o);return!c||this.#e.strictTrailingSlash&&!this.#d(n,c)||c.hasConstraints&&!this.#h(o,c)||!this.#f(o)?void 0:this.#l(c,o,i)}buildPath(e,t,n){const r=this.#n.get(e);if(!r)throw new Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);r.hasConstraints&&t&&this.#p(r,e,t);const i=this.#g(r,t),a=this.#m(i,n?.trailingSlash),s=this.#v(r,t,n?.queryParamsMode);return a+(s?`?${s}`:"")}getSegmentsByName(e){return this.#r.get(e)}getMetaByName(e){return this.#i.get(e)}hasRoute(e){return this.#n.has(e)}setRootPath(e){this.#s=e}#p(e,t,n){for(const[r,i]of e.constraintPatterns){const e=n[r];if(null!=e){const n="object"==typeof e?JSON.stringify(e):String(e);if(!i.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${t}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#g(e,t){const n=e.buildStaticParts,r=e.buildParamSlots;if(0===r.length)return this.#s+n[0];let i=this.#s+n[0];for(const[e,a]of r.entries()){const r=t?.[a.paramName];if(null==r){if(!a.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=n[e+1];continue}const s="object"==typeof r?JSON.stringify(r):String(r);i+=a.encoder(s)+n[e+1]}return i}#m(e,t){return"always"!==t||e.endsWith("/")?"never"===t&&"/"!==e&&e.endsWith("/")?e.slice(0,-1):e:`${e}/`}#v(e,t,n){if(!t)return"";const r={};let i=!1;for(const n of e.declaredQueryParams)n in t&&(r[n]=t[n],i=!0);if("loose"===n)for(const n in t)!Object.hasOwn(t,n)||e.declaredQueryParamsSet.has(n)||e.buildParamNamesSet.has(n)||(r[n]=t[n],i=!0);return i?this.#e.buildQueryString(r):""}#c(e){if(""===e&&(e="/"),!e.startsWith("/"))return;const t=e.indexOf("#");if(-1!==t&&(e=e.slice(0,t)),ee.test(e))return;if(this.#s.length>0){if(!e.startsWith(this.#s))return;e=e.slice(this.#s.length)||"/"}const n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),i=-1===n?void 0:e.slice(n+1);return r.includes("//")?void 0:[r,W(r),i]}#l(e,t,n){if(void 0!==n){const r=this.#e.parseQueryString(n);if(this.#e.strictQueryParams){const t=e.declaredQueryParamsSet;for(const e of Object.keys(r))if(!t.has(e))return}for(const e of Object.keys(r))t[e]=r[e]}return{segments:e.matchSegments,params:t,meta:e.meta}}#d(e,t){return(e.length>1&&e.endsWith("/"))===t.hasTrailingSlash}#u(e,t){return 1===e.length?this.#t.slashChildRoute??this.#t.route:this.#S(this.#t,e,1,t)}#S(e,t,n,r){let i=e;const a=t.length;for(;n<=a;){const e=t.indexOf("/",n),s=-1===e?a:e,o=t.slice(n,s),c=this.#e.caseSensitive?o:o.toLowerCase();let d;if(c in i.staticChildren)d=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const e={},a=this.#S(i.splatChild.node,t,n,e);return a?(Object.assign(r,e),a):(r[i.splatChild.name]=t.slice(n),i.splatChild.node.route)}return}d=i.paramChild.node,r[i.paramChild.name]=o}i=d,n=s+1}return i.slashChildRoute??i.route}#f(e){const t=this.#e.urlParamsEncoding;if("none"===t)return!0;const n=z[t];for(const t in e){const r=e[t];if(r.includes("%")){if(!J(r))return!1;e[t]=n(r)}}return!0}#h(e,t){for(const[n,r]of t.constraintPatterns)if(!r.pattern.test(e[n]))return!1;return!0}},ne=e=>{const t=e.indexOf("%"),n=e.indexOf("+");if(-1===t&&-1===n)return e;const r=-1===n?e:e.split("+").join(" ");return-1===t?r:decodeURIComponent(r)},re=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)},ie={none:{encodeArray:(e,t)=>t.map(t=>`${e}=${re(t)}`).join("&")},brackets:{encodeArray:(e,t)=>t.map(t=>`${e}[]=${re(t)}`).join("&")},index:{encodeArray:(e,t)=>t.map((t,n)=>`${e}[${n}]=${re(t)}`).join("&")},comma:{encodeArray:(e,t)=>`${e}=${t.map(e=>re(e)).join(",")}`}},ae={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}},se={default:{encode:e=>e},hidden:{encode:()=>""}},oe=(e,t,n)=>({boolean:ae[t],null:se[n],array:ie[e]}),ce={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:ae.none,null:se.default,array:ie.none}},de=e=>{if(!e||void 0===e.arrayFormat&&void 0===e.booleanFormat&&void 0===e.nullFormat)return ce;const t=e.arrayFormat??"none",n=e.booleanFormat??"none",r=e.nullFormat??"default";return{arrayFormat:t,booleanFormat:n,nullFormat:r,strategies:oe(t,n,r)}},le=e=>encodeURIComponent(e),ue=(e,t,n)=>{const r=le(e);switch(typeof t){case"string":case"number":default:return`${r}=${le(t)}`;case"boolean":return n.strategies.boolean.encode(r,t);case"object":return null===t?n.strategies.null.encode(r):Array.isArray(t)?n.strategies.array.encodeArray(r,t):`${r}=${le(t)}`}};function he(e,t,n,r,i){const a=e.indexOf("=",t),s=-1!==a&&a<n,o=e.slice(t,s?a:n),{name:c,hasBrackets:d}=function(e){const t=e.indexOf("[");return-1===t?{name:e,hasBrackets:!1}:{name:e.slice(0,t),hasBrackets:!0}}(o);var l,u,h,f,p;!function(e,t,n,r){const i=e[t];void 0===i?e[t]=r?[n]:n:Array.isArray(i)?i.push(n):e[t]=[i,n]}(r,ne(c),(l=e,u=a,h=n,f=s,p=i,p?((e,t)=>{if(void 0===e)return t.boolean.decodeUndefined();const n=t.boolean.decodeRaw(e);if(null!==n)return n;const r=ne(e);return t.boolean.decodeValue(r)})(f?l.slice(u+1,h):void 0,p):f?ne(l.slice(u+1,h)):null),d)}function fe(e,t){const n=e.path,r=n.startsWith("~"),i=r?n.slice(1):n,a={name:e.name,path:i,absolute:r,children:[],parent:t,nonAbsoluteChildren:[],fullName:""};if(e.children)for(const t of e.children){const e=fe(t,a);a.children.push(e)}return a}function pe(e,t){return e.endsWith("/")&&t.startsWith("/")?e+t.slice(1):e+t}function ge(e){const t=new Map;for(const n of e)t.set(n.name,n);return t}function me(e,t,n){const r=function(e){const t=[],n=[],r=[],i={},a=new Map,s=e.replaceAll(x,"$1"),o=_.exec(s);if(null!==o){const t=o[1].split("&");for(const e of t){const t=e.trim();t.length>0&&(n.push(t),i[t]="query")}e=e.slice(0,o.index)}let c;for(;null!==(c=B.exec(e));){const e=c[2],n=c[3];if("*"===c[1])r.push(e),t.push(e),i[e]="url";else if(t.push(e),i[e]="url",n){const t=`^${$(n)}$`;a.set(e,{pattern:new RegExp(t),constraint:n})}}return{urlParams:t,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:a,pathPattern:e}}(e.path),i=function(e){const t={};for(const n of e.urlParams)t[n]="url";for(const n of e.queryParams)t[n]="query";return t}(r),a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var s;a.fullName=(s=a,s.parent?.name?`${s.parent.fullName}.${s.name}`:s.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(e,t,n){const r=[],i=[];for(const a of e){const e=me(a,t,n);r.push(e),e.absolute||i.push(e)}return{childrenMap:ge(r),nonAbsoluteChildren:i}}(e.children,a,n);return a.children=o,a.nonAbsoluteChildren=c,a.staticPath=function(e){if(!e.path)return null;const{urlParams:t,queryParams:n,spatParams:r}=e.paramMeta;if(t.length>0||n.length>0||r.length>0)return null;const i=[];let a=e.parent;for(;a?.path;)i.unshift(a),a=a.parent;let s="";for(const e of i){const{urlParams:t,queryParams:n,spatParams:r}=e.paramMeta;if(t.length>0||n.length>0||r.length>0)return null;s=e.absolute?e.path:pe(s,e.path)}return e.absolute?e.path:pe(s,e.path)}(a),n&&(Object.freeze(c),Object.freeze(i),Object.freeze(a.children),Object.freeze(a)),a}function ve(e,t,n,r){return function(e,t){const n=[];return{add(e){return n.push(e),this},addMany(e){return n.push(...e),this},build:r=>function(e,t=!0){return me(e,null,t)}(function(e,t,n){const r=fe({name:e,path:t},null);for(const e of n){const t=fe(e,r);r.children.push(t)}return r}(e,t,n),!r?.skipFreeze)}}(e,t).addMany(n).build(r)}function Se(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=>Se(e))),t}function ye(e){const t=e?.queryParams;return new te({...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 n=(e=>{const t=e.indexOf("?");return-1===t?e:e.slice(t+1)})(e);if(""===n||"?"===n)return{};if(!t)return function(e){const t={};return function(e,t){let n=0;const r=e.length;for(;n<r;){let i=e.indexOf("&",n);-1===i&&(i=r),he(e,n,i,t),n=i+1}}(e,t),t}(n);const r=de(t),i={};let a=0;const s=n.length;for(;a<s;){let e=n.indexOf("&",a);-1===e&&(e=s),he(n,a,e,i,r.strategies),a=e+1}return i})(e,t),buildQueryString:e=>((e,t)=>{const n=Object.keys(e);if(0===n.length)return"";const r=de(t),i=[];for(const t of n){const n=e[t];if(void 0===n)continue;const a=ue(t,n,r);a&&i.push(a)}return i.join("&")})(e,t)})}function we(e,t,n=100){const r=new Set,i=[e];let a=e;for(;t[a];){const e=t[a];if(r.has(e)){const t=i.indexOf(e),n=[...i.slice(t),e];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(r.add(a),i.push(e),a=e,i.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${i.join(" → ")}`)}return a}function Te(e,t,n){const r=ve("",t,e),i=ye(n);return i.registerTree(r),{tree:r,matcher:i}}function be(e){const t=Te(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher,e.resolvedForwardMap=Oe(e.config)}function Ae(e){const t=Te(e.definitions,e.rootPath,e.matcherOptions);e.tree=t.tree,e.matcher=t.matcher}function Pe(e){Ne(e),Ae(e)}function Ne(e){e.definitions.length=0,Object.assign(e.config,F()),e.resolvedForwardMap=Object.create(null),e.routeCustomFields=Object.create(null)}function Oe(e){const t=Object.create(null);for(const n of Object.keys(e.forwardMap))t[n]=we(n,e.forwardMap);return t}function De(t,n,r,i,a,s,o){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),d=Object.fromEntries(Object.entries(t).filter(([e])=>!c.has(e)));Object.keys(d).length>0&&(i[n]=d),t.canActivate&&(o?o.addActivateGuard(n,t.canActivate):a.set(n,t.canActivate)),t.canDeactivate&&(o?o.addDeactivateGuard(n,t.canDeactivate):s.set(n,t.canDeactivate)),t.forwardTo&&function(t,n,r){if(t.canActivate&&e.logger.warn("real-router",`Route "${n}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),t.canDeactivate&&e.logger.warn("real-router",`Route "${n}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof t.forwardTo?t.forwardTo:"[dynamic]"}".`),"function"==typeof t.forwardTo){const e="AsyncFunction"===t.forwardTo.constructor.name,r=t.forwardTo.toString().includes("__awaiter");if(e||r)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof t.forwardTo?r.forwardMap[n]=t.forwardTo:r.forwardFnMap[n]=t.forwardTo}(t,n,r),t.decodeParams&&(r.decoders[n]=e=>t.decodeParams?.(e)??e),t.encodeParams&&(r.encoders[n]=e=>t.encodeParams?.(e)??e),t.defaultParams&&(r.defaultParams[n]=t.defaultParams)}function Ee(e,t,n,r,i,a,s=""){for(const o of e){const e=s?`${s}.${o.name}`:o.name;De(o,e,t,n,r,i,a),o.children&&Ee(o.children,t,n,r,i,a,e)}}function Re(e,t,n=""){for(const r of e){const e=n?`${n}.${r.name}`:r.name;if(e===t)return r;if(r.children&&t.startsWith(`${e}.`))return Re(r.children,t,e)}}function Ce(e,t,n,r){const i={name:e.name,path:e.path},a=n.forwardFnMap[t],s=n.forwardMap[t];void 0!==a?i.forwardTo=a:void 0!==s&&(i.forwardTo=s),t in n.defaultParams&&(i.defaultParams=n.defaultParams[t]),t in n.decoders&&(i.decodeParams=n.decoders[t]),t in n.encoders&&(i.encodeParams=n.encoders[t]);const[o,c]=r;return t in c&&(i.canActivate=c[t]),t in o&&(i.canDeactivate=o[t]),e.children&&(i.children=e.children.map(e=>Ce(e,`${t}.${e.name}`,n,r))),i}function Fe(e,t,n){if(n){const r=Re(e.definitions,n);r.children??=[];for(const e of t)r.children.push(j(e))}else for(const n of t)e.definitions.push(j(n));Ee(t,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,n??""),e.treeOperations.commitTreeChanges(e)}function je(e,t){return!!L(e.definitions,t)&&(function(e,t,n,r){const i=t=>t===e||t.startsWith(`${e}.`);M(t.decoders,i),M(t.encoders,i),M(t.defaultParams,i),M(t.forwardMap,i),M(t.forwardFnMap,i),M(n,i),M(t.forwardMap,e=>i(t.forwardMap[e]));const[a,s]=r.getFactories();for(const e of Object.keys(s))i(e)&&r.clearCanActivate(e);for(const e of Object.keys(a))i(e)&&r.clearCanDeactivate(e)}(t,e.config,e.routeCustomFields,e.lifecycleNamespace),e.treeOperations.commitTreeChanges(e),!0)}function Le(e,t){const n=e.matcher.getSegmentsByName(t);if(!n)return;const r=n.at(-1),i=e.treeOperations.nodeToDefinition(r),a=e.lifecycleNamespace.getFactories();return Ce(i,t,e.config,a)}function Me(e){const t=D(e),n=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,r){N(t.isDisposed),t.validator?.routes.validateRouteName(e,"addActivateGuard"),t.validator?.lifecycle.validateHandler(r,"addActivateGuard");const i=n.getHandlerCount("activate");t.validator?.lifecycle.validateHandlerLimit(i,t.dependenciesGetStore().limits,"canActivate"),n.addCanActivate(e,r)},addDeactivateGuard(e,r){N(t.isDisposed),t.validator?.routes.validateRouteName(e,"addDeactivateGuard"),t.validator?.lifecycle.validateHandler(r,"addDeactivateGuard");const i=n.getHandlerCount("deactivate");t.validator?.lifecycle.validateHandlerLimit(i,t.dependenciesGetStore().limits,"canDeactivate"),n.addCanDeactivate(e,r)},removeActivateGuard(e){N(t.isDisposed),t.validator?.routes.validateRouteName(e,"removeActivateGuard"),n.clearCanActivate(e)},removeDeactivateGuard(e){N(t.isDisposed),t.validator?.routes.validateRouteName(e,"removeDeactivateGuard"),n.clearCanDeactivate(e)}}}var Ie={maxListeners:0,warnListeners:0,maxEventDepth:0},$e=class extends Error{},Be=class{#e=new Map;#t=null;#i=Ie;#s;#n;constructor(e){e?.limits&&(this.#i=e.limits),this.#s=e?.onListenerError??null,this.#n=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.#i=e}on(e,t){const n=this.#r(e);if(n.has(t))throw new Error(`Duplicate listener for "${e}"`);const{maxListeners:r,warnListeners:i}=this.#i;if(0!==i&&n.size===i&&this.#n?.(e,i),0!==r&&n.size>=r)throw new Error(`Listener limit (${r}) reached for "${e}"`);return n.add(t),()=>{this.off(e,t)}}off(e,t){this.#e.get(e)?.delete(t)}emit(e,t,n,r,i){const a=this.#e.get(e);if(!a||0===a.size)return;const s=arguments.length-1;0!==this.#i.maxEventDepth?this.#a(a,e,s,t,n,r,i):this.#d(a,e,s,t,n,r,i)}clearAll(){this.#e.clear(),this.#t=null}listenerCount(e){return this.#e.get(e)?.size??0}#d(e,t,n,r,i,a,s){if(1===e.size){const[o]=e;try{this.#c(o,n,r,i,a,s)}catch(e){this.#s?.(t,e)}return}const o=[...e];for(const e of o)try{this.#c(e,n,r,i,a,s)}catch(e){this.#s?.(t,e)}}#c(e,t,n,r,i,a){switch(t){case 0:e();break;case 1:e(n);break;case 2:e(n,r);break;case 3:e(n,r,i);break;default:e(n,r,i,a)}}#a(e,t,n,r,i,a,s){this.#t??=new Map;const o=this.#t,c=o.get(t)??0;if(c>=this.#i.maxEventDepth)throw new $e(`Maximum recursion depth (${this.#i.maxEventDepth}) exceeded for event: ${t}`);try{o.set(t,c+1);const d=1===e.size?e:[...e];for(const e of d)try{this.#c(e,n,r,i,a,s)}catch(e){if(e instanceof $e)throw e;this.#s?.(t,e)}}finally{o.set(t,o.get(t)-1)}}#r(e){const t=this.#e.get(e);if(t)return t;const n=new Set;return this.#e.set(e,n),n}},xe="IDLE",_e="STARTING",ke="READY",Ue="TRANSITIONING",Ge="DISPOSED",ze="START",qe="STARTED",We="NAVIGATE",Ve="COMPLETE",Qe="FAIL",He="CANCEL",Je="STOP",Ye="DISPOSE",Ke={initial:xe,context:null,transitions:{[xe]:{[ze]:_e,[Ye]:Ge},[_e]:{[qe]:ke,[Qe]:xe},[ke]:{[We]:Ue,[Qe]:ke,[Je]:xe},[Ue]:{[We]:Ue,[Ve]:ke,[He]:ke,[Qe]:ke},[Ge]:{}}},Xe={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function Ze(e){Object.freeze(e);for(const t of Object.keys(e)){const n=e[t];n&&"object"==typeof n&&n.constructor===Object&&Ze(n)}return e}function et(e,t){return"function"==typeof e?e(t):e}var tt=class{#y;constructor(e={}){this.#y=Ze({...Xe,...e})}static validateOptionsIsObject(e){!function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError("[router.constructor] options must be a plain object")}(e)}get(){return this.#y}};function nt(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!nt(e[n],t[n]))return!1;return!0}return!1}var rt=new WeakMap;function it(e){return rt.get(e)}var at=class{#w=void 0;#T=void 0;#b;#A=new Map;get(){return this.#w}set(e){this.#T=this.#w,this.#w=e?w(e):void 0}getPrevious(){return this.#T}reset(){this.#w=void 0,this.#T=void 0,this.#A.clear()}setDependencies(e){this.#b=e}makeState(e,t,n,r,i){const a=this.#b.getDefaultParams();let s;s=Object.hasOwn(a,e)?{...a[e],...t}:t&&t!==v?{...t}:v;const o={name:e,params:s,path:n??this.#b.buildPath(e,t)};return r&&function(e,t){rt.set(e,t)}(o,r),i?o:w(o)}areStatesEqual(e,t,n=!0){if(!e||!t)return!!e==!!t;if(e.name!==t.name)return!1;if(n){const n=this.#P(e.name);for(const r of n)if(!nt(e.params[r],t.params[r]))return!1;return!0}const r=Object.keys(e.params),i=Object.keys(t.params);if(r.length!==i.length)return!1;for(const n of r)if(!(n in t.params)||!nt(e.params[n],t.params[n]))return!1;return!0}#P(e){const t=this.#A.get(e);if(void 0!==t)return t;const n=this.#b.getUrlParams(e);return this.#A.set(e,n),n}},st={[i]:l,[a]:u,[c]:p,[s]:h,[d]:g,[o]:f},ot=Object.keys(st),ct="router.usePlugin",dt=class t{#N=new Set;#O=new Set;#b;#D=m;#E=null;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 "+typeof 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.")}(e)}static validateNoDuplicatePlugins(e,t){for(const n of e)if(t(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(e){this.#b=e}setLimits(e){this.#D=e,this.#D}setValidatorGetter(e){this.#E=e}count(){return this.#N.size}use(...t){if(this.#E?.()?.plugins.validateCountThresholds(this.#N.size+t.length),1===t.length){const n=t[0],r=this.#R(n);this.#N.add(n);let i=!1;const a=()=>{if(!i){i=!0,this.#N.delete(n),this.#O.delete(a);try{r()}catch(t){e.logger.error(ct,"Error during cleanup:",t)}}};return this.#O.add(a),a}const n=this.#C(t),r=[];try{for(const e of n){const t=this.#R(e);r.push({factory:e,cleanup:t})}}catch(t){for(const{cleanup:t}of r)try{t()}catch(t){e.logger.error(ct,"Cleanup error:",t)}throw t}for(const{factory:e}of r)this.#N.add(e);let i=!1;const a=()=>{if(!i){i=!0,this.#O.delete(a);for(const{factory:e}of r)this.#N.delete(e);for(const{cleanup:t}of r)try{t()}catch(t){e.logger.error(ct,"Error during cleanup:",t)}}};return this.#O.add(a),a}getAll(){return[...this.#N]}has(e){return this.#N.has(e)}disposeAll(){for(const e of this.#O)e();this.#N.clear(),this.#O.clear()}#C(e){const t=new Set;for(const n of e)t.has(n)?this.#E?.()?.plugins.warnBatchDuplicates(e):t.add(n);return t}#R(e){const n=this.#b.compileFactory(e);t.validatePlugin(n),this.#E?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const r=[];for(const e of ot)e in n&&("function"==typeof n[e]?(r.push(this.#b.addEventListener(st[e],n[e])),"onStart"===e&&this.#b.canNavigate()&&this.#E?.()?.plugins.warnPluginAfterStart(e)):this.#E?.()?.plugins.warnPluginMethodType(e));return()=>{for(const e of r)e();"function"==typeof n.teardown&&n.teardown()}}},lt=class{#F=new Map;#j=new Map;#L=new Map;#M=new Map;#I=[this.#L,this.#M];#$=new Set;#B=new Set;#x=new Set;#b;#D=m;#E=null;setDependencies(e){this.#b=e}setLimits(e){this.#D=e,this.#D}setValidatorGetter(e){this.#E=e}getHandlerCount(e){return"activate"===e?this.#j.size:this.#F.size}addCanActivate(e,t,n=!1){n?this.#B.add(e):this.#B.delete(e);const r=this.#j.has(e);this.#_("activate",e,t,this.#j,this.#M,"canActivate",r)}addCanDeactivate(e,t,n=!1){n?this.#x.add(e):this.#x.delete(e);const r=this.#F.has(e);this.#_("deactivate",e,t,this.#F,this.#L,"canDeactivate",r)}clearCanActivate(e){this.#j.delete(e),this.#M.delete(e),this.#B.delete(e)}clearCanDeactivate(e){this.#F.delete(e),this.#L.delete(e),this.#x.delete(e)}clearAll(){this.#j.clear(),this.#M.clear(),this.#F.clear(),this.#L.clear(),this.#B.clear(),this.#x.clear()}clearDefinitionGuards(){for(const e of this.#B)this.#j.delete(e),this.#M.delete(e);for(const e of this.#x)this.#F.delete(e),this.#L.delete(e);this.#B.clear(),this.#x.clear()}getFactories(){const e={},t={};for(const[t,n]of this.#F)e[t]=n;for(const[e,n]of this.#j)t[e]=n;return[e,t]}getFunctions(){return this.#I}canNavigateTo(e,t,n,r){for(const t of e)if(!this.#k(this.#L,t,n,r,"canNavigateTo"))return!1;for(const e of t)if(!this.#k(this.#M,e,n,r,"canNavigateTo"))return!1;return!0}#_(e,t,n,r,i,a,s){s?this.#E?.()?.lifecycle.warnOverwrite(t,e,a):this.#E?.()?.lifecycle.validateCountThresholds(r.size+1,a);const o="boolean"==typeof n?function(e){const t=()=>e;return()=>t}(n):n;r.set(t,o),this.#$.add(t);try{const e=this.#b.compileFactory(o);if("function"!=typeof e)throw new TypeError(`[router.${a}] Factory must return a function, got ${typeof e}`);i.set(t,e)}catch(e){throw r.delete(t),e}finally{this.#$.delete(t)}}#k(e,t,n,r,i){const a=e.get(t);if(!a)return!0;try{const e=a(n,r);return"boolean"==typeof e?e:(this.#E?.()?.lifecycle.warnAsyncGuardSync(t,i),!1)}catch{return!1}}},ut=".",ht=[];function ft(e){const t=[];for(let n=e.length-1;n>=0;n--)t.push(e[n]);return t}function pt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t}function gt(e,t,n,r){const i=t[e];if(!i||"object"!=typeof i)return!0;for(const e of Object.keys(i)){const t=n.params[e],i=r.params[e];if(pt(t)&&pt(i)&&String(t)!==String(i))return!1}return!0}Object.freeze(ht);var mt,vt,St=new Map;function yt(e){const t=St.get(e);if(t)return t;const n=function(e){if(!e)return[""];const t=e.indexOf(ut);if(-1===t)return[e];const n=e.indexOf(ut,t+1);if(-1===n)return[e.slice(0,t),e];const r=e.indexOf(ut,n+1);if(-1===r)return[e.slice(0,t),e.slice(0,n),e];return-1===e.indexOf(ut,r+1)?[e.slice(0,t),e.slice(0,n),e.slice(0,r),e]:function(e){const t=e.split(ut),n=t.length,r=[t[0]];let i=t[0].length;for(let a=1;a<n-1;a++)i+=1+t[a].length,r.push(e.slice(0,i));return r.push(e),r}(e)}(e);return Object.freeze(n),St.set(e,n),n}var wt,Tt,bt=null,At=null;function Pt(e,t){if(null!==bt&&e===mt&&t===vt)return bt;if(null!==At&&e===wt&&t===Tt)return At;const n=function(e,t){if(!t)return{intersection:"",toActivate:yt(e.name),toDeactivate:ht};const n=it(e),r=it(t);if(!n&&!r)return{intersection:"",toActivate:yt(e.name),toDeactivate:ft(yt(t.name))};const i=yt(e.name),a=yt(t.name),s=function(e,t,n,r,i,a){for(let s=0;s<a;s++){const a=r[s];if(a!==i[s])return s;if(!gt(a,e,t,n))return s}return a}(n??r,e,t,i,a,Math.min(a.length,i.length));let o;if(s>=a.length)o=ht;else if(0===s&&1===a.length)o=a;else{o=[];for(let e=a.length-1;e>=s;e--)o.push(a[e])}const c=0===s?i:i.slice(s);return{intersection:s>0?a[s-1]:"",toDeactivate:o,toActivate:c}}(e,t);return wt=mt,Tt=vt,At=bt,mt=e,vt=t,bt=n,n}function Nt(e,t){var n;return{name:t??(n=e.segments,n.at(-1)?.fullName??""),params:e.params,meta:e.meta}}var Ot=class{#U;#G;get#b(){return this.#U.depsStore}constructor(e=[],t){this.#U=function(e,t){const n=[],r=F(),i=Object.create(null),a=new Map,s=new Map;for(const t of e)n.push(j(t));const{tree:o,matcher:c}=Te(n,"",t);return Ee(e,r,i,a,s,void 0,""),{definitions:n,config:r,tree:o,matcher:c,resolvedForwardMap:Oe(r),routeCustomFields:i,rootPath:"",matcherOptions:t,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:a,pendingCanDeactivate:s,treeOperations:{commitTreeChanges:be,resetStore:Pe,nodeToDefinition:Se}}}(e,t)}static shouldUpdateNode(e){return(t,n)=>{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&&!n)return!0;const{intersection:r,toActivate:i,toDeactivate:a}=Pt(t,n);return e===r||!!i.includes(e)||a.includes(e)}}setDependencies(e){this.#U.depsStore=e;for(const[t,n]of this.#U.pendingCanActivate)e.addActivateGuard(t,n);this.#U.pendingCanActivate.clear();for(const[t,n]of this.#U.pendingCanDeactivate)e.addDeactivateGuard(t,n);this.#U.pendingCanDeactivate.clear()}setLifecycleNamespace(e){this.#U.lifecycleNamespace=e}setRootPath(e){this.#U.rootPath=e,Ae(this.#U)}hasRoute(e){return this.#U.matcher.hasRoute(e)}clearRoutes(){Pe(this.#U)}buildPath(e,t,n){if(e===r)return"string"==typeof t?.path?t.path:"";const i=Object.hasOwn(this.#U.config.defaultParams,e)?{...this.#U.config.defaultParams[e],...t}:t??{},a="function"==typeof this.#U.config.encoders[e]?this.#U.config.encoders[e]({...i}):i;return this.#U.matcher.buildPath(e,a,this.#z(n))}matchPath(e,t){const n=t,r=this.#U.matcher.match(e);if(!r)return;const i=Nt(r),{name:a,params:s,meta:o}=i,c="function"==typeof this.#U.config.decoders[a]?this.#U.config.decoders[a](s):s,{name:d,params:l}=this.#b.forwardState(a,c);let u=e;if(n.rewritePathOnMatch){const e="function"==typeof this.#U.config.encoders[d]?this.#U.config.encoders[d]({...l}):l,t=n.trailingSlash;u=this.#U.matcher.buildPath(d,e,{trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:n.queryParamsMode})}return this.#b.makeState(d,l,u,o)}forwardState(e,t){if(Object.hasOwn(this.#U.config.forwardFnMap,e)){const n=this.#q(e,t),r=this.#U.config.forwardFnMap[e],i=this.#W(e,r,t);return{name:i,params:this.#q(i,n)}}const n=this.#U.resolvedForwardMap[e]??e;if(n!==e&&Object.hasOwn(this.#U.config.forwardFnMap,n)){const r=this.#q(e,t),i=this.#U.config.forwardFnMap[n],a=this.#W(n,i,t);return{name:a,params:this.#q(a,r)}}if(n!==e){const r=this.#q(e,t);return{name:n,params:this.#q(n,r)}}return{name:e,params:this.#q(e,t)}}buildStateResolved(e,t){const n=this.#U.matcher.getSegmentsByName(e);if(n)return Nt({segments:n,params:t,meta:this.#U.matcher.getMetaByName(e)},e)}isActiveRoute(e,t={},n=!1,r=!0){const i=this.#b.getState();if(!i)return!1;const a=i.name;if(a!==e&&!a.startsWith(`${e}.`)&&!e.startsWith(`${a}.`))return!1;const s=this.#U.config.defaultParams[e];if(n||a===e){const n=s?{...s,...t}:t;return this.#b.areStatesEqual({name:e,params:n,path:""},i,r)}const o=i.params;return!!function(e,t){for(const n in e)if(e[n]!==t[n])return!1;return!0}(t,o)&&(!s||function(e,t,n){for(const r in e)if(!(r in n)&&e[r]!==t[r])return!1;return!0}(s,o,t))}getMetaForState(e){return this.#U.matcher.hasRoute(e)?this.#U.matcher.getMetaByName(e):void 0}getUrlParams(e){const t=this.#U.matcher.getSegmentsByName(e);return t?function(e){const t=[];for(const n of e)for(const e of n.paramMeta.urlParams)t.push(e);return t}(t):[]}getStore(){return this.#U}#q(e,t){return Object.hasOwn(this.#U.config.defaultParams,e)?{...this.#U.config.defaultParams[e],...t}:t}#z(e){if(this.#G)return this.#G;const t=e?.trailingSlash;return this.#G=Object.freeze({trailingSlash:"never"===t||"always"===t?t:void 0,queryParamsMode:e?.queryParamsMode}),this.#G}#W(e,t,n){const r=new Set([e]);let i=t(this.#b.getDependency,n),a=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;a<100;){if(void 0===this.#U.matcher.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(r.has(i)){const e=[...r,i].join(" → ");throw new Error(`Circular forwardTo detected: ${e}`)}if(r.add(i),Object.hasOwn(this.#U.config.forwardFnMap,i)){i=(0,this.#U.config.forwardFnMap[i])(this.#b.getDependency,n),a++;continue}const e=this.#U.config.forwardMap[i];if(void 0===e)return i;i=e,a++}throw new Error("forwardTo exceeds maximum depth of 100")}},Dt=new P(n.ROUTER_NOT_STARTED),Et=new P(n.ROUTE_NOT_FOUND),Rt=new P(n.SAME_STATES),Ct=Promise.reject(Dt),Ft=Promise.reject(Et),jt=Promise.reject(Rt);function Lt(e,t){const{toState:i,fromState:a,opts:s,toDeactivate:o,toActivate:c,intersection:d}=t;if(i.name!==r&&!e.hasRoute(i.name)){const t=new P(n.ROUTE_NOT_FOUND,{routeName:i.name});throw e.sendTransitionFail(i,a,t),t}if(a)for(const n of o)!c.includes(n)&&t.canDeactivateFunctions.has(n)&&e.clearCanDeactivate(n);i.transition=function(e,t,n,r,i){const a={phase:"activating",reason:"success",segments:{deactivated:n,activated:r,intersection:i}};return void 0!==e?.name&&(a.from=e.name),void 0!==t.reload&&(a.reload=t.reload),void 0!==t.redirected&&(a.redirected=t.redirected),a}(a,s,o,c,d);const l=w(i);e.setState(l);const u=void 0===s.signal?s:function({signal:e,...t}){return t}(s);return e.sendTransitionDone(l,a,u),l}function Mt(e,t,r,i){t.code!==n.TRANSITION_CANCELLED&&t.code!==n.ROUTE_NOT_FOUND&&e.sendTransitionFail(r,i,t)}function It(e,t,r){if(e instanceof DOMException&&"AbortError"===e.name)throw new P(n.TRANSITION_CANCELLED);!function(e,t,n){if(e instanceof P)throw e.setCode(t),e;throw new P(t,function(e,t){const n={segment:t};if(e instanceof Error)return{...n,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[n,r]of Object.entries(e))$t.has(n)||(t[n]=r);return{...n,...t}}return n}(e,n))}(e,t,r)}Ct.catch(()=>{}),Ft.catch(()=>{}),jt.catch(()=>{});var $t=new Set(["code","segment","path","redirect"]);async function Bt(e,t,n){let r;try{r=await e}catch(e){return void It(e,t,n)}if(!r)throw new P(t,{segment:n})}async function xt(e,t,r,i,a,s,o,c,d,l){await Bt(d,r,l);for(let d=c;d<t.length;d++){if(!o())throw new P(n.TRANSITION_CANCELLED);const c=t[d],l=e.get(c);if(!l)continue;let u=!1;try{u=l(i,a,s)}catch(e){It(e,r,c)}if(u instanceof Promise)await Bt(u,r,c);else if(!u)throw new P(r,{segment:c})}}function _t(e,t,r,i,a,s,o){for(const[c,d]of t.entries()){if(!o())throw new P(n.TRANSITION_CANCELLED);const l=e.get(d);if(!l)continue;let u=!1;try{u=l(i,a,s)}catch(e){It(e,r,d)}if(u instanceof Promise)return xt(e,t,r,i,a,s,o,c+1,u,d);if(!u)throw new P(r,{segment:d})}}var kt=[r];Object.freeze(kt);var Ut={replace:!0};Object.freeze(Ut);var Gt=class{lastSyncResolved=!1;lastSyncRejected=!1;#b;#V=null;#Q=0;setDependencies(e){this.#b=e}navigate(e,t,i){this.lastSyncResolved=!1;const a=this.#b;if(!a.canNavigate())return this.lastSyncRejected=!0,Ct;let s,o,c=!1,d=null;try{if(s=a.buildNavigateState(e,t),!s)return a.emitTransitionError(void 0,a.getState(),Et),this.lastSyncRejected=!0,Ft;if(o=a.getState(),i=function(e,t){return t?.name!==r||e.replace?e:{...e,replace:!0}}(i,o),function(e,t,n){return!!e&&!t.reload&&!t.force&&e.path===n.path}(o,i,s))return a.emitTransitionError(s,o,Rt),this.lastSyncRejected=!0,jt;if(this.#H(),i.signal?.aborted)throw new P(n.TRANSITION_CANCELLED,{reason:i.signal.reason});const l=++this.#Q;if(a.startTransition(s,o),c=!0,this.#Q!==l)throw new P(n.TRANSITION_CANCELLED);const[u,h]=a.getLifecycleFunctions(),f=s.name===r,{toDeactivate:p,toActivate:g,intersection:m}=Pt(s,o),v=o&&!i.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(u.size>0||h.size>0){d=new AbortController,this.#V=d;const e=()=>this.#Q===l&&a.isActive(),t=function(e,t,r,i,a,s,o,c,d,l){if(a){const a=_t(e,r,n.CANNOT_DEACTIVATE,o,c,d,l);if(void 0!==a)return async function(e,t,r,i,a,s,o,c){if(await e,!c())throw new P(n.TRANSITION_CANCELLED);if(i){const e=_t(t,r,n.CANNOT_ACTIVATE,a,s,o,c);if(void 0!==e&&await e,!c())throw new P(n.TRANSITION_CANCELLED)}}(a,t,i,s,o,c,d,l)}if(!l())throw new P(n.TRANSITION_CANCELLED);if(s)return _t(t,i,n.CANNOT_ACTIVATE,o,c,d,l)}(u,h,p,g,!!v,S,s,o,d.signal,e);if(void 0!==t)return this.#J(t,{toState:s,fromState:o,opts:i,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:u},d,l);if(!e())throw new P(n.TRANSITION_CANCELLED);this.#Y(d)}return this.lastSyncResolved=!0,Promise.resolve(Lt(a,{toState:s,fromState:o,opts:i,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:u}))}catch(e){return this.#K(e,d,c,s,o),Promise.reject(e)}}navigateToDefault(e){const t=this.#b;if(!t.getOptions().defaultRoute)return Promise.reject(new P(n.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:r,params:i}=t.resolveDefault();return r?this.navigate(r,i,e):Promise.reject(new P(n.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(e){this.#H();const t=this.#b.getState(),n=t?yt(t.name).toReversed():[];Object.freeze(n);const i={deactivated:n,activated:kt,intersection:""};Object.freeze(i);const a={phase:"activating",...t&&{from:t.name},reason:"success",segments:i};Object.freeze(a);const s={name:r,params:{},path:e,transition:a};return Object.freeze(s),this.#b.setState(s),this.#b.emitTransitionSuccess(s,t,Ut),s}abortCurrentNavigation(){this.#V?.abort(new P(n.TRANSITION_CANCELLED)),this.#V=null}async#J(e,t,r,i){const a=this.#b,s=()=>this.#Q===i&&!r.signal.aborted&&a.isActive();try{if(t.opts.signal){if(t.opts.signal.aborted)throw new P(n.TRANSITION_CANCELLED,{reason:t.opts.signal.reason});t.opts.signal.addEventListener("abort",()=>{r.abort(t.opts.signal?.reason)},{once:!0,signal:r.signal})}if(await e,!s())throw new P(n.TRANSITION_CANCELLED);return Lt(a,t)}catch(e){throw Mt(a,e,t.toState,t.fromState),e}finally{this.#Y(r)}}#K(e,t,n,r,i){t&&this.#Y(t),n&&r&&Mt(this.#b,e,r,i)}#Y(e){e.abort(),this.#V===e&&(this.#V=null)}#H(){this.#b.isTransitioning()&&(e.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#V?.abort(new P(n.TRANSITION_CANCELLED)),this.#b.cancelNavigation())}},zt={replace:!0};Object.freeze(zt);var qt=class{#b;setDependencies(e){this.#b=e}async start(e){const t=this.#b,r=t.getOptions(),i=t.matchPath(e);if(!i&&!r.allowNotFound){const r=new P(n.ROUTE_NOT_FOUND,{path:e});throw t.emitTransitionError(void 0,void 0,r),r}return t.completeStart(),i?t.navigate(i.name,i.params,zt):t.navigateToNotFound(e)}stop(){this.#b.clearState()}},Wt=class{#X;#Z;#ee;#te;#ne;#re;constructor(e){this.#X=e.routerFSM,this.#Z=e.emitter,this.#ee=void 0,this.#ie()}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.#Z.emit(l)}emitRouterStop(){this.#Z.emit(u)}emitTransitionStart(e,t){this.#Z.emit(h,e,t)}emitTransitionSuccess(e,t,n){this.#Z.emit(p,e,t,n)}emitTransitionError(e,t,n){this.#Z.emit(g,e,t,n)}emitTransitionCancel(e,t){this.#Z.emit(f,e,t)}sendStart(){this.#X.send(ze)}sendStop(){this.#X.send(Je)}sendDispose(){this.#X.send(Ye)}sendStarted(){this.#X.send(qe)}sendNavigate(e,t){this.#ee=e,this.#X.forceState(Ue),this.emitTransitionStart(e,t)}sendComplete(e,t,n={}){this.#X.forceState(ke),this.emitTransitionSuccess(e,t,n),this.#ee===e&&(this.#ee=void 0)}sendFail(e,t,n){const r=this.#ee;this.#te=e,this.#ne=t,this.#re=n,this.#X.send(Qe),this.#ee===r&&(this.#ee=void 0)}sendFailSafe(e,t,n){this.isReady()?this.sendFail(e,t,n):this.emitTransitionError(e,t,n)}sendCancel(e,t){const n=this.#ee;this.#te=e,this.#ne=t,this.#X.send(He),this.#ee===n&&(this.#ee=void 0)}canBeginTransition(){return this.#X.canSend(We)}canStart(){return this.#X.canSend(ze)}canCancel(){return this.#X.canSend(He)}isActive(){const e=this.#X.getState();return e!==xe&&e!==Ge}isDisposed(){return this.#X.getState()===Ge}isTransitioning(){return this.#X.getState()===Ue}isReady(){return this.#X.getState()===ke}getCurrentToState(){return this.#ee}addEventListener(e,t){return this.#Z.on(e,t)}subscribe(e){return this.#Z.on(p,(t,n)=>{e({route:t,previousRoute:n})})}clearAll(){this.#Z.clearAll()}setLimits(e){this.#Z.setLimits(e)}sendCancelIfTransitioning(e){this.canCancel()&&this.sendCancel(this.#ee,e)}#ae(){this.emitTransitionError(this.#te,this.#ne,this.#re)}#ie(){const e=this.#X;e.on(_e,qe,()=>{this.emitRouterStart()}),e.on(ke,Je,()=>{this.emitRouterStop()}),e.on(Ue,He,()=>{const e=this.#te;void 0!==e&&this.emitTransitionCancel(e,this.#ne)}),e.on(_e,Qe,()=>{this.#ae()}),e.on(ke,Qe,()=>{this.#ae()}),e.on(Ue,Qe,()=>{this.#ae()})}},Vt=new P(n.ROUTER_ALREADY_STARTED),Qt=new Set(["all","warn-error","error-only"]);var Ht=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(){const e={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(e),this.routeLifecycle.setValidatorGetter(()=>{try{return D(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(e,t)=>{this.routeLifecycle.addCanActivate(e,t,!0)},addDeactivateGuard:(e,t)=>{this.routeLifecycle.addCanDeactivate(e,t,!0)},makeState:(e,t,n,r)=>this.state.makeState(e,t,n,r),getState:()=>this.state.get(),areStatesEqual:(e,t,n)=>this.state.areStatesEqual(e,t,n),getDependency:e=>this.dependenciesStore.dependencies[e],forwardState:(e,t)=>{const n=D(this.router);return n.validator?.routes.validateStateBuilderArgs(e,t,"forwardState"),n.forwardState(e,t)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const e={addEventListener:(e,t)=>this.eventBus.addEventListener(e,t),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(e),this.plugins.setValidatorGetter(()=>{try{return D(this.router).validator}catch{return null}})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:e=>this.routes.hasRoute(e),getState:()=>this.state.get(),setState:e=>{this.state.set(e)},buildNavigateState:(e,t)=>{const n=D(this.router);n.validator?.routes.validateStateBuilderArgs(e,t,"navigate");const{name:r,params:i}=n.forwardState(e,t),a=this.routes.getMetaForState(r);if(void 0===a)return;const s=n.buildPath(r,i);return this.state.makeState(r,i,s,a,!0)},resolveDefault:()=>{const e=this.options.get();return{route:et(e.defaultRoute,e=>this.dependenciesStore.dependencies[e]),params:et(e.defaultParams,e=>this.dependenciesStore.dependencies[e])}},startTransition:(e,t)=>{this.eventBus.sendNavigate(e,t)},cancelNavigation:()=>{const e=this.eventBus.getCurrentToState();void 0!==e&&this.eventBus.sendCancel(e,this.state.get())},sendTransitionDone:(e,t,n)=>{this.eventBus.sendComplete(e,t,n)},sendTransitionFail:(e,t,n)=>{this.eventBus.sendFail(e,t,n)},emitTransitionError:(e,t,n)=>{this.eventBus.sendFailSafe(e,t,n)},emitTransitionSuccess:(e,t,n)=>{this.eventBus.emitTransitionSuccess(e,t,n)},canNavigate:()=>this.eventBus.canBeginTransition(),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(),navigate:(e,t,n)=>this.navigation.navigate(e,t,n),navigateToNotFound:e=>this.navigation.navigateToNotFound(e),clearState:()=>{this.state.set(void 0)},matchPath:e=>this.routes.matchPath(e,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(e,t,n)=>{this.eventBus.sendFail(e,t,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(e,t)=>D(this.router).buildPath(e,t),getUrlParams:e=>this.routes.getUrlParams(e)})}createCompileFactory(){const{router:e,dependenciesStore:t}=this;return n=>n(e,e=>t.dependencies[e])}},Jt=Object.freeze({}),Yt=class r{#y;#D;#se;#oe;#ce;#de;#N;#le;#ue;#he;constructor(n=[],r={},i={}){r.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(n=t.level)||!Qt.has(n)))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 n;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}(r.logger)&&(e.logger.configure(r.logger),delete r.logger),tt.validateOptionsIsObject(r),function(e){if(!e||"object"!=typeof e||e.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const t in e)if(Object.getOwnPropertyDescriptor(e,t)?.get)throw new TypeError(`dependencies cannot contain getters: "${t}"`)}(i),n.length>0&&C(n),this.#y=new tt(r),this.#D=function(e={}){return{...m,...e}}(r.limits),this.#se=function(e={}){const t=Object.create(null);for(const n in e)void 0!==e[n]&&(t[n]=e[n]);return{dependencies:t,limits:m}}(i),this.#oe=new at,this.#ce=new Ot(n,function(e){return{strictTrailingSlash:"strict"===e.trailingSlash,strictQueryParams:"strict"===e.queryParamsMode,urlParamsEncoding:e.urlParamsEncoding,queryParams:e.queryParams}}(this.#y.get())),this.#de=new lt,this.#N=new dt,this.#le=new Gt,this.#ue=new qt;const a=new t.FSM(Ke),s=new Be({onListenerError:(t,n)=>{e.logger.error("Router",`Error in listener for ${t}:`,n)},onListenerWarn:(t,n)=>{e.logger.warn("router.addEventListener",`Event "${t}" has ${n} listeners — possible memory leak`)}});var o;this.#he=new Wt({routerFSM:a,emitter:s}),(o=new Ht({router:this,options:this.#y,limits:this.#D,dependenciesStore:this.#se,state:this.#oe,routes:this.#ce,routeLifecycle:this.#de,plugins:this.#N,navigation:this.#le,lifecycle:this.#ue,eventBus:this.#he})).wireLimits(),o.wireRouteLifecycleDeps(),o.wireRoutesDeps(),o.wirePluginsDeps(),o.wireNavigationDeps(),o.wireLifecycleDeps(),o.wireStateDeps();const c=new Map;var d,l,u;d={makeState:(e,t,n,r)=>this.#oe.makeState(e,t,n,r),forwardState:R("forwardState",(e,t)=>this.#ce.forwardState(e,t),c),buildStateResolved:(e,t)=>this.#ce.buildStateResolved(e,t),matchPath:(e,t)=>this.#ce.matchPath(e,t),getOptions:()=>this.#y.get(),addEventListener:(e,t)=>this.#he.addEventListener(e,t),buildPath:R("buildPath",(e,t)=>this.#ce.buildPath(e,t??v,this.#y.get()),c),start:(l=e=>this.#ue.start(e),u=c,(...e)=>{const t=u.get("start");return t&&0!==t.length?E(t,l,e):l(...e)}),interceptors:c,setRootPath:e=>{this.#ce.setRootPath(e)},getRootPath:()=>this.#ce.getStore().rootPath,getTree:()=>this.#ce.getStore().tree,isDisposed:()=>this.#he.isDisposed(),validator:null,dependenciesGetStore:()=>this.#se,cloneOptions:()=>({...this.#y.get()}),cloneDependencies:()=>({...this.#se.dependencies}),getLifecycleFactories:()=>this.#de.getFactories(),getPluginFactories:()=>this.#N.getAll(),routeGetStore:()=>this.#ce.getStore(),getStateName:()=>this.#oe.get()?.name,isTransitioning:()=>this.#he.isTransitioning(),clearState:()=>{this.#oe.set(void 0)},setState:e=>{this.#oe.set(e)},routerExtensions:[]},O.set(this,d),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(t,n,r,i){return D(this).validator?.routes.validateIsActiveRouteArgs(t,n,r,i),D(this).validator?.routes.validateRouteName(t,"isActiveRoute"),""===t?(e.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ce.isActiveRoute(t,n,r,i)}buildPath(e,t){const n=D(this);return n.validator?.routes.validateBuildPathArgs(e),n.validator?.navigation.validateParams(t,"buildPath"),n.buildPath(e,t)}getState(){return this.#oe.get()}getPreviousState(){return this.#oe.getPrevious()}areStatesEqual(e,t,n=!0){return D(this).validator?.state.validateAreStatesEqualArgs(e,t,n),this.#oe.areStatesEqual(e,t,n)}shouldUpdateNode(e){return D(this).validator?.routes.validateShouldUpdateNodeArgs(e),Ot.shouldUpdateNode(e)}isActive(){return this.#he.isActive()}start(e){if(!this.#he.canStart())return Promise.reject(Vt);D(this).validator?.navigation.validateStartArgs(e),this.#he.sendStart();const t=D(this).start(e).catch(e=>{throw this.#he.isReady()&&(this.#ue.stop(),this.#he.sendStop()),e});return r.#fe(t),t}stop(){return this.#le.abortCurrentNavigation(),this.#he.sendCancelIfTransitioning(this.#oe.get()),this.#he.isReady()||this.#he.isTransitioning()?(this.#ue.stop(),this.#he.sendStop(),this):this}dispose(){if(this.#he.isDisposed())return;this.#le.abortCurrentNavigation(),this.#he.sendCancelIfTransitioning(this.#oe.get()),(this.#he.isReady()||this.#he.isTransitioning())&&(this.#ue.stop(),this.#he.sendStop()),this.#he.sendDispose(),this.#he.clearAll(),this.#N.disposeAll();const e=D(this);for(const t of e.routerExtensions)for(const e of t.keys)delete this[e];e.routerExtensions.length=0,this.#ce.clearRoutes(),this.#de.clearAll(),this.#oe.reset(),this.#se.dependencies=Object.create(null),this.#pe()}canNavigateTo(e,t){const n=D(this);if(n.validator?.routes.validateRouteName(e,"canNavigateTo"),n.validator?.navigation.validateParams(t,"canNavigateTo"),!this.#ce.hasRoute(e))return!1;const{name:r,params:i}=n.forwardState(e,t??{}),a=this.#oe.makeState(r,i),s=this.#oe.get(),{toDeactivate:o,toActivate:c}=Pt(a,s);return this.#de.canNavigateTo(o,c,a,s)}usePlugin(...e){const t=e.filter(Boolean);if(0===t.length)return()=>{};const n=D(this);n.validator?.plugins.validatePluginLimit(this.#N.count(),this.#D);for(const e of t)n.validator?.plugins.validateNoDuplicatePlugins(e,this.#N.getAll());return this.#N.use(...t)}subscribe(e){return Wt.validateSubscribeListener(e),this.#he.subscribe(e)}navigate(e,t,n){const i=D(this);i.validator?.navigation.validateNavigateArgs(e),i.validator?.navigation.validateParams(t,"navigate");const a=n??Jt;i.validator?.navigation.validateNavigationOptions(a,"navigate");const s=this.#le.navigate(e,t??v,a);return this.#le.lastSyncResolved?this.#le.lastSyncResolved=!1:this.#le.lastSyncRejected?this.#le.lastSyncRejected=!1:r.#fe(s),s}navigateToDefault(e){const t=D(this);t.validator?.navigation.validateNavigateToDefaultArgs(e);const n=e??Jt;t.validator?.navigation.validateNavigationOptions(n,"navigateToDefault");const i=this.#le.navigateToDefault(n);return this.#le.lastSyncResolved?this.#le.lastSyncResolved=!1:this.#le.lastSyncRejected?this.#le.lastSyncRejected=!1:r.#fe(i),i}navigateToNotFound(e){if(!this.#he.isActive())throw new P(n.ROUTER_NOT_STARTED);if(void 0!==e&&"string"!=typeof e)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof e);const t=e??this.#oe.get().path;return this.#le.navigateToNotFound(t)}static#ge=t=>{t instanceof P&&(t.code===n.SAME_STATES||t.code===n.TRANSITION_CANCELLED||t.code===n.ROUTER_NOT_STARTED||t.code===n.ROUTE_NOT_FOUND)||e.logger.error("router.navigate","Unexpected navigation error",t)};static#fe(e){e.catch(r.#ge)}#pe(){this.navigate=Kt,this.navigateToDefault=Kt,this.navigateToNotFound=Kt,this.start=Kt,this.stop=Kt,this.usePlugin=Kt,this.subscribe=Kt,this.canNavigateTo=Kt}};function Kt(){throw new P(n.ROUTER_DISPOSED)}exports.cloneRouter=function(e,t){const r=D(e);if(r.isDisposed())throw new P(n.ROUTER_DISPOSED);r.validator?.dependencies.validateCloneArgs(t);const i=r.routeGetStore(),a=[...i.tree.children.values()].map(e=>Se(e)),s=i.config,o=i.resolvedForwardMap,c=i.routeCustomFields,d=r.cloneOptions(),l=r.cloneDependencies(),[u,h]=r.getLifecycleFactories(),f=r.getPluginFactories(),p={...l,...t},g=new Yt(a,d,p),m=Me(g);for(const[e,t]of Object.entries(u))m.addDeactivateGuard(e,t);for(const[e,t]of Object.entries(h))m.addActivateGuard(e,t);f.length>0&&g.usePlugin(...f);const v=D(g).routeGetStore();return Object.assign(v.config.decoders,s.decoders),Object.assign(v.config.encoders,s.encoders),Object.assign(v.config.defaultParams,s.defaultParams),Object.assign(v.config.forwardMap,s.forwardMap),Object.assign(v.config.forwardFnMap,s.forwardFnMap),Object.assign(v.resolvedForwardMap,o),Object.assign(v.routeCustomFields,c),g},exports.getDependenciesApi=function(e){const t=D(e);return{get:e=>{t.validator?.dependencies.validateDependencyName(e,"getDependency");const n=t.dependenciesGetStore(),r=n.dependencies[e];return t.validator?.dependencies.validateDependencyExists(e,n),r},getAll:()=>({...t.dependenciesGetStore().dependencies}),set:(e,n)=>{N(t.isDisposed),t.validator?.dependencies.validateSetDependencyArgs(e,n,"setDependency"),function(e,t,n,r){if(void 0===n)return!1;if(Object.hasOwn(e.dependencies,t)){const i=e.dependencies[t],a=i!==n,s=Number.isNaN(i)&&Number.isNaN(n);a&&!s&&r?.dependencies.warnOverwrite(t,"setDependency")}else r?.dependencies.validateDependencyCount(e,"setDependency");e.dependencies[t]=n}(t.dependenciesGetStore(),e,n,t.validator)},setAll:e=>{N(t.isDisposed);const n=t.dependenciesGetStore();t.validator?.dependencies.validateDependenciesObject(e,"setDependencies"),t.validator?.dependencies.validateDependencyLimit(n,n.limits),function(e,t,n){const r=[];for(const i in t)void 0!==t[i]&&(Object.hasOwn(e.dependencies,i)?r.push(i):n?.dependencies.validateDependencyCount(e,"setDependencies"),e.dependencies[i]=t[i]);r.length>0&&n?.dependencies.warnBatchOverwrite(r,"setDependencies")}(n,e,t.validator)},remove:e=>{N(t.isDisposed),t.validator?.dependencies.validateDependencyName(e,"removeDependency");const n=t.dependenciesGetStore();Object.hasOwn(n.dependencies,e)||t.validator?.dependencies.warnRemoveNonExistent(e),delete n.dependencies[e]},reset:()=>{N(t.isDisposed),t.dependenciesGetStore().dependencies=Object.create(null)},has:e=>(t.validator?.dependencies.validateDependencyName(e,"hasDependency"),Object.hasOwn(t.dependenciesGetStore().dependencies,e))}},exports.getLifecycleApi=Me,exports.getPluginApi=function(e){const t=D(e);return{makeState:(e,n,r,i)=>(t.validator?.state.validateMakeStateArgs(e,n,r),t.makeState(e,n,r,i?.params)),buildState:(e,n)=>{t.validator?.routes.validateStateBuilderArgs(e,n,"buildState");const{name:r,params:i}=t.forwardState(e,n);return t.buildStateResolved(r,i)},forwardState:(e,n)=>(t.validator?.routes.validateStateBuilderArgs(e,n,"forwardState"),t.forwardState(e,n)),matchPath:e=>(t.validator?.routes.validateMatchPathArgs(e),t.matchPath(e,t.getOptions())),setRootPath:e=>{N(t.isDisposed),t.validator?.routes.validateSetRootPathArgs(e),t.setRootPath(e)},getRootPath:t.getRootPath,addEventListener:(e,n)=>(N(t.isDisposed),t.validator?.eventBus.validateListenerArgs(e,n),t.addEventListener(e,n)),buildNavigationState:(e,n={})=>{t.validator?.routes.validateStateBuilderArgs(e,n,"buildNavigationState");const{name:r,params:i}=t.forwardState(e,n),a=t.buildStateResolved(r,i);if(a)return t.makeState(a.name,a.params,t.buildPath(a.name,a.params),a.meta)},getOptions:t.getOptions,getTree:t.getTree,addInterceptor:(e,n)=>{N(t.isDisposed),t.validator?.plugins.validateAddInterceptorArgs(e,n);let r=t.interceptors.get(e);return r||(r=[],t.interceptors.set(e,r)),r.push(n),()=>{const e=r.indexOf(n);-1!==e&&r.splice(e,1)}},getRouteConfig:e=>{const n=t.routeGetStore();if(n.matcher.hasRoute(e))return n.routeCustomFields[e]},extendRouter:r=>{N(t.isDisposed);const i=Object.keys(r);for(const t of i)if(t in e)throw new P(n.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${t}" already exists`});for(const t of i)e[t]=r[t];const a={keys:i};t.routerExtensions.push(a);let s=!1;return()=>{if(s)return;s=!0;for(const t of a.keys)delete e[t];const n=t.routerExtensions.indexOf(a);-1!==n&&t.routerExtensions.splice(n,1)}}}},exports.getRoutesApi=function(t){const n=D(t),r=n.routeGetStore();return{add:(e,t)=>{N(n.isDisposed);const i=Array.isArray(e)?e:[e],a=t?.parent;C(i,n.validator),void 0!==a&&n.validator?.routes.validateParentOption(a,r.tree),n.validator?.routes.throwIfInternalRouteInArray(i,"addRoute"),n.validator?.routes.validateAddRouteArgs(i),n.validator?.routes.validateRoutes(i,r),Fe(r,i,a)},remove:t=>{N(n.isDisposed),n.validator?.routes.validateRemoveRouteArgs(t),n.validator?.routes.throwIfInternalRoute(t,"removeRoute");const i=function(t,n,r){if(n){const r=n===t,i=n.startsWith(`${t}.`);if(r||i)return e.logger.warn("router.removeRoute",`Cannot remove route "${t}" — it is currently active${r?"":` (current: "${n}")`}. Navigate away first.`),!1}return r&&e.logger.warn("router.removeRoute",`Route "${t}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}(t,n.getStateName(),n.isTransitioning());i&&(je(r,t)||e.logger.warn("router.removeRoute",`Route "${t}" not found. No changes made.`))},update:(t,i)=>{N(n.isDisposed),n.validator?.routes.validateUpdateRouteBasicArgs(t,i),n.validator?.routes.throwIfInternalRoute(t,"updateRoute");const{forwardTo:a,defaultParams:s,decodeParams:o,encodeParams:c,canActivate:d,canDeactivate:l}=i;n.validator?.routes.validateUpdateRoutePropertyTypes(t,i),n.isTransitioning()&&e.logger.error("router.updateRoute",`Updating route "${t}" while navigation is in progress. This may cause unexpected behavior.`),n.validator?.routes.validateUpdateRoute(t,i,r),function(e,t,n){if(void 0!==n.forwardTo&&(e.resolvedForwardMap=function(e,t,n){return null===t?(delete n.forwardMap[e],delete n.forwardFnMap[e]):"string"==typeof t?(delete n.forwardFnMap[e],n.forwardMap[e]=t):(delete n.forwardMap[e],n.forwardFnMap[e]=t),(e=>Oe(e))(n)}(t,n.forwardTo,e.config)),void 0!==n.defaultParams&&(null===n.defaultParams?delete e.config.defaultParams[t]:e.config.defaultParams[t]=n.defaultParams),void 0!==n.decodeParams)if(null===n.decodeParams)delete e.config.decoders[t];else{const r=n.decodeParams;e.config.decoders[t]=e=>r(e)??e}if(void 0!==n.encodeParams)if(null===n.encodeParams)delete e.config.encoders[t];else{const r=n.encodeParams;e.config.encoders[t]=e=>r(e)??e}}(r,t,{forwardTo:a,defaultParams:s,decodeParams:o,encodeParams:c}),void 0!==d&&(null===d?r.lifecycleNamespace.clearCanActivate(t):r.lifecycleNamespace.addCanActivate(t,d,!0)),void 0!==l&&(null===l?r.lifecycleNamespace.clearCanDeactivate(t):r.lifecycleNamespace.addCanDeactivate(t,l,!0))},clear:()=>{N(n.isDisposed),I(n.isTransitioning())&&(r.treeOperations.resetStore(r),r.lifecycleNamespace.clearAll(),n.clearState())},has:e=>(n.validator?.routes.validateRouteName(e,"hasRoute"),r.matcher.hasRoute(e)),get:e=>(n.validator?.routes.validateRouteName(e,"getRoute"),Le(r,e)),replace:e=>{N(n.isDisposed);const i=Array.isArray(e)?e:[e];if(!I(n.isTransitioning()))return;C(i,n.validator),n.validator?.routes.throwIfInternalRouteInArray(i,"replaceRoutes"),n.validator?.routes.validateAddRouteArgs(i),n.validator?.routes.validateRoutes(i,r);const a=t.getState()?.path;!function(e,t,n,r){Ne(e),e.lifecycleNamespace.clearDefinitionGuards();for(const n of t)e.definitions.push(j(n));if(Ee(t,e.config,e.routeCustomFields,e.pendingCanActivate,e.pendingCanDeactivate,e.depsStore,""),e.treeOperations.commitTreeChanges(e),void 0!==r){const e=n.matchPath(r,n.getOptions());e?n.setState(e):n.clearState()}}(r,i,n,a)}}};//# sourceMappingURL=api.js.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./Router-NL2_9FQk.js`),t=require(`./RouterError-BkgjTHQg.js`),n=require(`./internals-na15rxo_.js`),r=require(`./getPluginApi-BXrM_Nwv.js`);let i=require(`@real-router/logger`);function a(e,t,n){if(t){let n=t===e,r=t.startsWith(`${e}.`);if(n||r){let r=n?``:` (current: "${t}")`;return i.logger.warn(`router.removeRoute`,`Cannot remove route "${e}" — it is currently active${r}. Navigate away first.`),!1}}return n&&i.logger.warn(`router.removeRoute`,`Route "${e}" removed while navigation is in progress. This may cause unexpected behavior.`),!0}function o(e){return e?(i.logger.error(`router.clearRoutes`,`Cannot clear routes while navigation is in progress. Wait for navigation to complete.`),!1):!0}function s(e,t,n=``){for(let r of e){let e=n?`${n}.${r.name}`:r.name;if(e===t)return r;if(r.children&&t.startsWith(`${e}.`))return s(r.children,t,e)}}function c(t,n,r,i){let a=e=>e===t||e.startsWith(`${t}.`);e.o(n.decoders,a),e.o(n.encoders,a),e.o(n.defaultParams,a),e.o(n.forwardMap,a),e.o(n.forwardFnMap,a),e.o(r,a),e.o(n.forwardMap,e=>a(n.forwardMap[e]));let[o,s]=i.getFactories();for(let e of Object.keys(s))a(e)&&i.clearCanActivate(e);for(let e of Object.keys(o))a(e)&&i.clearCanDeactivate(e)}function l(e,t,n,r){return t===null?(delete n.forwardMap[e],delete n.forwardFnMap[e]):typeof t==`string`?(delete n.forwardFnMap[e],n.forwardMap[e]=t):(delete n.forwardMap[e],n.forwardFnMap[e]=t),r(n)}function u(e,t,n,r){let i={name:e.name,path:e.path},a=n.forwardFnMap[t],o=n.forwardMap[t];a===void 0?o!==void 0&&(i.forwardTo=o):i.forwardTo=a,t in n.defaultParams&&(i.defaultParams=n.defaultParams[t]),t in n.decoders&&(i.decodeParams=n.decoders[t]),t in n.encoders&&(i.encodeParams=n.encoders[t]);let[s,c]=r;return t in c&&(i.canActivate=c[t]),t in s&&(i.canDeactivate=s[t]),e.children&&(i.children=e.children.map(e=>u(e,`${t}.${e.name}`,n,r))),i}function d(t,n,r){if(r){let i=s(t.definitions,r);i.children??=[];for(let t of n)i.children.push(e.c(t))}else for(let r of n)t.definitions.push(e.c(r));e.i(n,t.config,t.routeCustomFields,t.pendingCanActivate,t.pendingCanDeactivate,t.depsStore,r??``),t.treeOperations.commitTreeChanges(t)}function f(t,n,r,i){e.n(t),t.lifecycleNamespace.clearDefinitionGuards();for(let r of n)t.definitions.push(e.c(r));if(e.i(n,t.config,t.routeCustomFields,t.pendingCanActivate,t.pendingCanDeactivate,t.depsStore,``),t.treeOperations.commitTreeChanges(t),i!==void 0){let e=r.matchPath(i,r.getOptions());e?r.setState(e):r.clearState()}}function p(t,n){return e.s(t.definitions,n)?(c(n,t.config,t.routeCustomFields,t.lifecycleNamespace),t.treeOperations.commitTreeChanges(t),!0):!1}function m(t,n,r){if(r.forwardTo!==void 0&&(t.resolvedForwardMap=l(n,r.forwardTo,t.config,t=>e.r(t))),r.defaultParams!==void 0&&(r.defaultParams===null?delete t.config.defaultParams[n]:t.config.defaultParams[n]=r.defaultParams),r.decodeParams!==void 0)if(r.decodeParams===null)delete t.config.decoders[n];else{let e=r.decodeParams;t.config.decoders[n]=t=>e(t)??t}if(r.encodeParams!==void 0)if(r.encodeParams===null)delete t.config.encoders[n];else{let e=r.encodeParams;t.config.encoders[n]=t=>e(t)??t}}function h(e,t){let n=e.matcher.getSegmentsByName(t);if(!n)return;let r=n.at(-1),i=e.treeOperations.nodeToDefinition(r),a=e.lifecycleNamespace.getFactories();return u(i,t,e.config,a)}function g(t){let s=n.r(t),c=s.routeGetStore();return{add:(t,n)=>{r.n(s.isDisposed);let i=Array.isArray(t)?t:[t],a=n?.parent;e.u(i,s.validator),a!==void 0&&s.validator?.routes.validateParentOption(a,c.tree),s.validator?.routes.throwIfInternalRouteInArray(i,`addRoute`),s.validator?.routes.validateAddRouteArgs(i),s.validator?.routes.validateRoutes(i,c),d(c,i,a)},remove:e=>{r.n(s.isDisposed),s.validator?.routes.validateRemoveRouteArgs(e),s.validator?.routes.throwIfInternalRoute(e,`removeRoute`),a(e,s.getStateName(),s.isTransitioning())&&(p(c,e)||i.logger.warn(`router.removeRoute`,`Route "${e}" not found. No changes made.`))},update:(e,t)=>{r.n(s.isDisposed),s.validator?.routes.validateUpdateRouteBasicArgs(e,t),s.validator?.routes.throwIfInternalRoute(e,`updateRoute`);let{forwardTo:n,defaultParams:a,decodeParams:o,encodeParams:l,canActivate:u,canDeactivate:d}=t;s.validator?.routes.validateUpdateRoutePropertyTypes(e,t),s.isTransitioning()&&i.logger.error(`router.updateRoute`,`Updating route "${e}" while navigation is in progress. This may cause unexpected behavior.`),s.validator?.routes.validateUpdateRoute(e,t,c),m(c,e,{forwardTo:n,defaultParams:a,decodeParams:o,encodeParams:l}),u!==void 0&&(u===null?c.lifecycleNamespace.clearCanActivate(e):c.lifecycleNamespace.addCanActivate(e,u,!0)),d!==void 0&&(d===null?c.lifecycleNamespace.clearCanDeactivate(e):c.lifecycleNamespace.addCanDeactivate(e,d,!0))},clear:()=>{r.n(s.isDisposed),o(s.isTransitioning())&&(c.treeOperations.resetStore(c),c.lifecycleNamespace.clearAll(),s.clearState())},has:e=>(s.validator?.routes.validateRouteName(e,`hasRoute`),c.matcher.hasRoute(e)),get:e=>(s.validator?.routes.validateRouteName(e,`getRoute`),h(c,e)),replace:n=>{r.n(s.isDisposed);let i=Array.isArray(n)?n:[n];if(!o(s.isTransitioning()))return;e.u(i,s.validator),s.validator?.routes.throwIfInternalRouteInArray(i,`replaceRoutes`),s.validator?.routes.validateAddRouteArgs(i),s.validator?.routes.validateRoutes(i,c);let a=t.getState()?.path;f(c,i,s,a)}}}function _(e,t,n,r){if(n===void 0)return!1;if(!Object.hasOwn(e.dependencies,t))r?.dependencies.validateDependencyCount(e,`setDependency`);else{let i=e.dependencies[t];i!==n&&!(Number.isNaN(i)&&Number.isNaN(n))&&r?.dependencies.warnOverwrite(t,`setDependency`)}return e.dependencies[t]=n,!0}function v(e,t,n){let r=[];for(let i in t)t[i]!==void 0&&(Object.hasOwn(e.dependencies,i)?r.push(i):n?.dependencies.validateDependencyCount(e,`setDependencies`),e.dependencies[i]=t[i]);r.length>0&&n?.dependencies.warnBatchOverwrite(r,`setDependencies`)}function y(e){let t=n.r(e);return{get:e=>{t.validator?.dependencies.validateDependencyName(e,`getDependency`);let n=t.dependenciesGetStore(),r=n.dependencies[e];return t.validator?.dependencies.validateDependencyExists(e,n),r},getAll:()=>({...t.dependenciesGetStore().dependencies}),set:(e,n)=>{r.n(t.isDisposed),t.validator?.dependencies.validateSetDependencyArgs(e,n,`setDependency`),_(t.dependenciesGetStore(),e,n,t.validator)},setAll:e=>{r.n(t.isDisposed);let n=t.dependenciesGetStore();t.validator?.dependencies.validateDependenciesObject(e,`setDependencies`),t.validator?.dependencies.validateDependencyLimit(n,n.limits),v(n,e,t.validator)},remove:e=>{r.n(t.isDisposed),t.validator?.dependencies.validateDependencyName(e,`removeDependency`);let n=t.dependenciesGetStore();Object.hasOwn(n.dependencies,e)||t.validator?.dependencies.warnRemoveNonExistent(e),delete n.dependencies[e]},reset:()=>{r.n(t.isDisposed);let e=t.dependenciesGetStore();e.dependencies=Object.create(null)},has:e=>(t.validator?.dependencies.validateDependencyName(e,`hasDependency`),Object.hasOwn(t.dependenciesGetStore().dependencies,e))}}function b(e){let t=n.r(e),i=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,n){r.n(t.isDisposed),t.validator?.routes.validateRouteName(e,`addActivateGuard`),t.validator?.lifecycle.validateHandler(n,`addActivateGuard`);let a=i.getHandlerCount(`activate`);t.validator?.lifecycle.validateHandlerLimit(a,t.dependenciesGetStore().limits,`canActivate`),i.addCanActivate(e,n)},addDeactivateGuard(e,n){r.n(t.isDisposed),t.validator?.routes.validateRouteName(e,`addDeactivateGuard`),t.validator?.lifecycle.validateHandler(n,`addDeactivateGuard`);let a=i.getHandlerCount(`deactivate`);t.validator?.lifecycle.validateHandlerLimit(a,t.dependenciesGetStore().limits,`canDeactivate`),i.addCanDeactivate(e,n)},removeActivateGuard(e){r.n(t.isDisposed),t.validator?.routes.validateRouteName(e,`removeActivateGuard`),i.clearCanActivate(e)},removeDeactivateGuard(e){r.n(t.isDisposed),t.validator?.routes.validateRouteName(e,`removeDeactivateGuard`),i.clearCanDeactivate(e)}}}function x(r,i){let a=n.r(r);if(a.isDisposed())throw new t.t(t.c.ROUTER_DISPOSED);a.validator?.dependencies.validateCloneArgs(i);let o=a.routeGetStore(),s=e.l(o.tree),c=o.config,l=o.resolvedForwardMap,u=o.routeCustomFields,d=a.cloneOptions(),f=a.cloneDependencies(),[p,m]=a.getLifecycleFactories(),h=a.getPluginFactories(),g=new e.t(s,d,{...f,...i}),_=b(g);for(let[e,t]of Object.entries(p))_.addDeactivateGuard(e,t);for(let[e,t]of Object.entries(m))_.addActivateGuard(e,t);h.length>0&&g.usePlugin(...h);let v=n.r(g).routeGetStore();return Object.assign(v.config.decoders,c.decoders),Object.assign(v.config.encoders,c.encoders),Object.assign(v.config.defaultParams,c.defaultParams),Object.assign(v.config.forwardMap,c.forwardMap),Object.assign(v.config.forwardFnMap,c.forwardFnMap),Object.assign(v.resolvedForwardMap,l),Object.assign(v.routeCustomFields,u),g}exports.cloneRouter=x,exports.getDependenciesApi=y,exports.getLifecycleApi=b,exports.getPluginApi=r.t,exports.getRoutesApi=g;
|
|
2
|
+
//# sourceMappingURL=api.js.map
|