@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.
Files changed (63) hide show
  1. package/dist/cjs/Router-73rMK2YI.d.ts +409 -0
  2. package/dist/cjs/Router-NL2_9FQk.js +6 -0
  3. package/dist/cjs/Router-NL2_9FQk.js.map +1 -0
  4. package/dist/cjs/RouterError-BkgjTHQg.js +2 -0
  5. package/dist/cjs/RouterError-BkgjTHQg.js.map +1 -0
  6. package/dist/cjs/RouterValidator-TUi8eT8Q.d.ts +112 -0
  7. package/dist/cjs/api.d.ts +17 -12
  8. package/dist/cjs/api.js +2 -1
  9. package/dist/cjs/api.js.map +1 -1
  10. package/dist/cjs/getPluginApi-BXrM_Nwv.js +2 -0
  11. package/dist/cjs/getPluginApi-BXrM_Nwv.js.map +1 -0
  12. package/dist/cjs/index.d.ts +206 -196
  13. package/dist/cjs/index.js +2 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/internals-na15rxo_.js +2 -0
  16. package/dist/cjs/internals-na15rxo_.js.map +1 -0
  17. package/dist/cjs/utils.d.ts +6 -3
  18. package/dist/cjs/utils.js +2 -1
  19. package/dist/cjs/utils.js.map +1 -1
  20. package/dist/cjs/validation.d.ts +153 -152
  21. package/dist/cjs/validation.js +1 -1
  22. package/dist/esm/Router-BhDMI4UX.d.mts +409 -0
  23. package/dist/esm/Router-CUi2TqAr.mjs +6 -0
  24. package/dist/esm/Router-CUi2TqAr.mjs.map +1 -0
  25. package/dist/esm/RouterError-D0RlQE_5.mjs +2 -0
  26. package/dist/esm/RouterError-D0RlQE_5.mjs.map +1 -0
  27. package/dist/esm/RouterValidator-DphcVMEp.d.mts +112 -0
  28. package/dist/esm/api.d.mts +17 -12
  29. package/dist/esm/api.mjs +2 -1
  30. package/dist/esm/api.mjs.map +1 -1
  31. package/dist/esm/getPluginApi-D0bBPuLp.mjs +2 -0
  32. package/dist/esm/getPluginApi-D0bBPuLp.mjs.map +1 -0
  33. package/dist/esm/index.d.mts +206 -196
  34. package/dist/esm/index.mjs +2 -1
  35. package/dist/esm/index.mjs.map +1 -1
  36. package/dist/esm/internals-CCymabFj.mjs +2 -0
  37. package/dist/esm/internals-CCymabFj.mjs.map +1 -0
  38. package/dist/esm/utils.d.mts +6 -3
  39. package/dist/esm/utils.mjs +2 -1
  40. package/dist/esm/utils.mjs.map +1 -1
  41. package/dist/esm/validation.d.mts +153 -152
  42. package/dist/esm/validation.mjs +1 -1
  43. package/package.json +5 -7
  44. package/src/helpers.ts +9 -6
  45. package/src/namespaces/OptionsNamespace/constants.ts +3 -5
  46. package/dist/cjs/Router-DoJ3NWsT.d.ts +0 -46
  47. package/dist/cjs/RouterValidator-CaIeCVeB.d.ts +0 -136
  48. package/dist/cjs/index.d-y2b-8_3Y.d.ts +0 -236
  49. package/dist/cjs/metafile-cjs.json +0 -1
  50. package/dist/cjs/validation.js.map +0 -1
  51. package/dist/esm/Router-DoJ3NWsT.d.mts +0 -46
  52. package/dist/esm/RouterValidator-CaIeCVeB.d.mts +0 -136
  53. package/dist/esm/chunk-EPF2YSMX.mjs +0 -1
  54. package/dist/esm/chunk-EPF2YSMX.mjs.map +0 -1
  55. package/dist/esm/chunk-UPJLWPEL.mjs +0 -1
  56. package/dist/esm/chunk-UPJLWPEL.mjs.map +0 -1
  57. package/dist/esm/chunk-UUG7DSTN.mjs +0 -1
  58. package/dist/esm/chunk-UUG7DSTN.mjs.map +0 -1
  59. package/dist/esm/chunk-XQJDGUQE.mjs +0 -1
  60. package/dist/esm/chunk-XQJDGUQE.mjs.map +0 -1
  61. package/dist/esm/index.d-y2b-8_3Y.d.mts +0 -236
  62. package/dist/esm/metafile-esm.json +0 -1
  63. package/dist/esm/validation.mjs.map +0 -1
@@ -0,0 +1,2 @@
1
+ const e=require(`./RouterError-BkgjTHQg.js`),t=require(`./internals-na15rxo_.js`);function n(t){if(t())throw new e.t(e.c.ROUTER_DISPOSED)}function r(r){let i=t.r(r);return{makeState:(e,t,n,r)=>(i.validator?.state.validateMakeStateArgs(e,t,n),i.makeState(e,t,n,r?.params)),buildState:(e,t)=>{i.validator?.routes.validateStateBuilderArgs(e,t,`buildState`);let{name:n,params:r}=i.forwardState(e,t);return i.buildStateResolved(n,r)},forwardState:(e,t)=>(i.validator?.routes.validateStateBuilderArgs(e,t,`forwardState`),i.forwardState(e,t)),matchPath:e=>(i.validator?.routes.validateMatchPathArgs(e),i.matchPath(e,i.getOptions())),setRootPath:e=>{n(i.isDisposed),i.validator?.routes.validateSetRootPathArgs(e),i.setRootPath(e)},getRootPath:i.getRootPath,addEventListener:(e,t)=>(n(i.isDisposed),i.validator?.eventBus.validateListenerArgs(e,t),i.addEventListener(e,t)),buildNavigationState:(e,t={})=>{i.validator?.routes.validateStateBuilderArgs(e,t,`buildNavigationState`);let{name:n,params:r}=i.forwardState(e,t),a=i.buildStateResolved(n,r);if(a)return i.makeState(a.name,a.params,i.buildPath(a.name,a.params),a.meta)},getOptions:i.getOptions,getTree:i.getTree,addInterceptor:(e,t)=>{n(i.isDisposed),i.validator?.plugins.validateAddInterceptorArgs(e,t);let r=i.interceptors.get(e);return r||(r=[],i.interceptors.set(e,r)),r.push(t),()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}},getRouteConfig:e=>{let t=i.routeGetStore();if(t.matcher.hasRoute(e))return t.routeCustomFields[e]},extendRouter:t=>{n(i.isDisposed);let a=Object.keys(t);for(let t of a)if(t in r)throw new e.t(e.c.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${t}" already exists`});for(let e of a)r[e]=t[e];let o={keys:a};i.routerExtensions.push(o);let s=!1;return()=>{if(s)return;s=!0;for(let e of o.keys)delete r[e];let e=i.routerExtensions.indexOf(o);e!==-1&&i.routerExtensions.splice(e,1)}}}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
2
+ //# sourceMappingURL=getPluginApi-BXrM_Nwv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPluginApi-BXrM_Nwv.js","names":["RouterError","errorCodes","getInternals","RouterError","errorCodes"],"sources":["../../src/api/helpers.ts","../../src/api/getPluginApi.ts"],"sourcesContent":["// packages/core/src/api/helpers.ts\n\nimport { errorCodes } from \"../constants\";\nimport { RouterError } from \"../RouterError\";\n\nexport function throwIfDisposed(isDisposed: () => boolean): void {\n if (isDisposed()) {\n throw new RouterError(errorCodes.ROUTER_DISPOSED);\n }\n}\n","import { throwIfDisposed } from \"./helpers\";\nimport { errorCodes } from \"../constants\";\nimport { getInternals } from \"../internals\";\nimport { RouterError } from \"../RouterError\";\n\nimport type { PluginApi } from \"./types\";\nimport type { DefaultDependencies, Params, Router } from \"@real-router/types\";\n\nexport function getPluginApi<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(router: Router<Dependencies>): PluginApi {\n const ctx = getInternals(router);\n\n return {\n makeState: (name, params, path, meta) => {\n ctx.validator?.state.validateMakeStateArgs(name, params, path);\n\n return ctx.makeState(\n name,\n params,\n path,\n meta?.params as\n | Record<string, Record<string, \"url\" | \"query\">>\n | undefined,\n );\n },\n buildState: (routeName, routeParams) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"buildState\",\n );\n\n const { name, params } = ctx.forwardState(routeName, routeParams);\n\n return ctx.buildStateResolved(name, params);\n },\n forwardState: <P extends Params = Params>(\n routeName: string,\n routeParams: P,\n ) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"forwardState\",\n );\n\n return ctx.forwardState(routeName, routeParams);\n },\n matchPath: (path) => {\n ctx.validator?.routes.validateMatchPathArgs(path);\n\n return ctx.matchPath(path, ctx.getOptions());\n },\n setRootPath: (rootPath) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateSetRootPathArgs(rootPath);\n\n ctx.setRootPath(rootPath);\n },\n getRootPath: ctx.getRootPath,\n addEventListener: (eventName, cb) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.eventBus.validateListenerArgs(eventName, cb);\n\n return ctx.addEventListener(eventName, cb);\n },\n buildNavigationState: (name, params = {}) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n name,\n params,\n \"buildNavigationState\",\n );\n\n const { name: resolvedName, params: resolvedParams } = ctx.forwardState(\n name,\n params,\n );\n const routeInfo = ctx.buildStateResolved(resolvedName, resolvedParams);\n\n if (!routeInfo) {\n return;\n }\n\n return ctx.makeState(\n routeInfo.name,\n routeInfo.params,\n ctx.buildPath(routeInfo.name, routeInfo.params),\n routeInfo.meta,\n );\n },\n getOptions: ctx.getOptions,\n getTree: ctx.getTree,\n addInterceptor: (method, fn) => {\n throwIfDisposed(ctx.isDisposed);\n ctx.validator?.plugins.validateAddInterceptorArgs(method, fn);\n let list = ctx.interceptors.get(method);\n\n if (!list) {\n list = [];\n ctx.interceptors.set(method, list);\n }\n\n list.push(fn);\n\n return () => {\n const index = list.indexOf(fn);\n\n if (index !== -1) {\n list.splice(index, 1);\n }\n };\n },\n getRouteConfig: (name) => {\n const store = ctx.routeGetStore();\n\n if (!store.matcher.hasRoute(name)) {\n return;\n }\n\n return store.routeCustomFields[name];\n },\n extendRouter: (extensions: Record<string, unknown>) => {\n throwIfDisposed(ctx.isDisposed);\n\n const keys = Object.keys(extensions);\n\n for (const key of keys) {\n if (key in router) {\n throw new RouterError(errorCodes.PLUGIN_CONFLICT, {\n message: `Cannot extend router: property \"${key}\" already exists`,\n });\n }\n }\n\n for (const key of keys) {\n (router as Record<string, unknown>)[key] = extensions[key];\n }\n\n const extensionRecord = { keys };\n\n ctx.routerExtensions.push(extensionRecord);\n\n let removed = false;\n\n return () => {\n if (removed) {\n return;\n }\n\n removed = true;\n\n for (const key of extensionRecord.keys) {\n delete (router as Record<string, unknown>)[key];\n }\n\n const idx = ctx.routerExtensions.indexOf(extensionRecord);\n\n if (idx !== -1) {\n ctx.routerExtensions.splice(idx, 1);\n }\n };\n },\n };\n}\n"],"mappings":"kFAKA,SAAgB,EAAgB,EAAiC,CAC/D,GAAI,GAAY,CACd,MAAM,IAAIA,EAAAA,EAAYC,EAAAA,EAAW,gBAAgB,CCCrD,SAAgB,EAEd,EAAyC,CACzC,IAAM,EAAMC,EAAAA,EAAa,EAAO,CAEhC,MAAO,CACL,WAAY,EAAM,EAAQ,EAAM,KAC9B,EAAI,WAAW,MAAM,sBAAsB,EAAM,EAAQ,EAAK,CAEvD,EAAI,UACT,EACA,EACA,EACA,GAAM,OAGP,EAEH,YAAa,EAAW,IAAgB,CACtC,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,aACD,CAED,GAAM,CAAE,OAAM,UAAW,EAAI,aAAa,EAAW,EAAY,CAEjE,OAAO,EAAI,mBAAmB,EAAM,EAAO,EAE7C,cACE,EACA,KAEA,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,eACD,CAEM,EAAI,aAAa,EAAW,EAAY,EAEjD,UAAY,IACV,EAAI,WAAW,OAAO,sBAAsB,EAAK,CAE1C,EAAI,UAAU,EAAM,EAAI,YAAY,CAAC,EAE9C,YAAc,GAAa,CACzB,EAAgB,EAAI,WAAW,CAE/B,EAAI,WAAW,OAAO,wBAAwB,EAAS,CAEvD,EAAI,YAAY,EAAS,EAE3B,YAAa,EAAI,YACjB,kBAAmB,EAAW,KAC5B,EAAgB,EAAI,WAAW,CAE/B,EAAI,WAAW,SAAS,qBAAqB,EAAW,EAAG,CAEpD,EAAI,iBAAiB,EAAW,EAAG,EAE5C,sBAAuB,EAAM,EAAS,EAAE,GAAK,CAC3C,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,uBACD,CAED,GAAM,CAAE,KAAM,EAAc,OAAQ,GAAmB,EAAI,aACzD,EACA,EACD,CACK,EAAY,EAAI,mBAAmB,EAAc,EAAe,CAEjE,KAIL,OAAO,EAAI,UACT,EAAU,KACV,EAAU,OACV,EAAI,UAAU,EAAU,KAAM,EAAU,OAAO,CAC/C,EAAU,KACX,EAEH,WAAY,EAAI,WAChB,QAAS,EAAI,QACb,gBAAiB,EAAQ,IAAO,CAC9B,EAAgB,EAAI,WAAW,CAC/B,EAAI,WAAW,QAAQ,2BAA2B,EAAQ,EAAG,CAC7D,IAAI,EAAO,EAAI,aAAa,IAAI,EAAO,CASvC,OAPK,IACH,EAAO,EAAE,CACT,EAAI,aAAa,IAAI,EAAQ,EAAK,EAGpC,EAAK,KAAK,EAAG,KAEA,CACX,IAAM,EAAQ,EAAK,QAAQ,EAAG,CAE1B,IAAU,IACZ,EAAK,OAAO,EAAO,EAAE,GAI3B,eAAiB,GAAS,CACxB,IAAM,EAAQ,EAAI,eAAe,CAE5B,KAAM,QAAQ,SAAS,EAAK,CAIjC,OAAO,EAAM,kBAAkB,IAEjC,aAAe,GAAwC,CACrD,EAAgB,EAAI,WAAW,CAE/B,IAAM,EAAO,OAAO,KAAK,EAAW,CAEpC,IAAK,IAAM,KAAO,EAChB,GAAI,KAAO,EACT,MAAM,IAAIC,EAAAA,EAAYC,EAAAA,EAAW,gBAAiB,CAChD,QAAS,mCAAmC,EAAI,kBACjD,CAAC,CAIN,IAAK,IAAM,KAAO,EACf,EAAmC,GAAO,EAAW,GAGxD,IAAM,EAAkB,CAAE,OAAM,CAEhC,EAAI,iBAAiB,KAAK,EAAgB,CAE1C,IAAI,EAAU,GAEd,UAAa,CACX,GAAI,EACF,OAGF,EAAU,GAEV,IAAK,IAAM,KAAO,EAAgB,KAChC,OAAQ,EAAmC,GAG7C,IAAM,EAAM,EAAI,iBAAiB,QAAQ,EAAgB,CAErD,IAAQ,IACV,EAAI,iBAAiB,OAAO,EAAK,EAAE,GAI1C"}
@@ -1,9 +1,8 @@
1
- export { B as BuildStateResultWithSegments, R as RouterValidator } from './RouterValidator-CaIeCVeB.js';
2
- import { R as Router } from './Router-DoJ3NWsT.js';
3
- import { ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
4
- export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
5
- export { R as RouteTree } from './index.d-y2b-8_3Y.js';
1
+ import { c as RouteConfigUpdate, f as RouteTree, i as GuardFnFactory, n as BuildStateResultWithSegments, o as PluginFactory, s as Route, t as Router } from "./Router-73rMK2YI.js";
2
+ import { t as RouterValidator } from "./RouterValidator-TUi8eT8Q.js";
3
+ import { Config, DefaultDependencies, DefaultDependencies as DefaultDependencies$1, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventToNameMap, GuardFn, Listener, NavigationOptions, Navigator, Navigator as Navigator$1, Options, Options as Options$1, Params, Plugin, Router as Router$1, SimpleState, State, State as State$1, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from "@real-router/types";
6
4
 
5
+ //#region src/constants.d.ts
7
6
  type ConstantsKeys = "UNKNOWN_ROUTE";
8
7
  type Constants = Record<ConstantsKeys, string>;
9
8
  type ErrorCodes = Record<ErrorCodeKeys, ErrorCodeValues>;
@@ -24,194 +23,202 @@ declare const constants: Constants;
24
23
  * Used with addEventListener/removeEventListener for reactive subscriptions.
25
24
  */
26
25
  declare const events: EventToNameMap;
27
-
26
+ //#endregion
27
+ //#region src/RouterError.d.ts
28
28
  declare class RouterError extends Error {
29
+ [key: string]: unknown;
30
+ readonly segment: string | undefined;
31
+ readonly path: string | undefined;
32
+ readonly redirect: State$1 | undefined;
33
+ code: string;
34
+ /**
35
+ * Creates a new RouterError instance.
36
+ *
37
+ * The options object accepts built-in fields (message, segment, path, redirect)
38
+ * and any additional custom fields, which will all be attached to the error instance.
39
+ *
40
+ * @param code - The error code (e.g., "ROUTE_NOT_FOUND", "CANNOT_ACTIVATE")
41
+ * @param options - Optional configuration object
42
+ * @param options.message - Custom error message (defaults to code if not provided)
43
+ * @param options.segment - The route segment where the error occurred
44
+ * @param options.path - The full path where the error occurred
45
+ * @param options.redirect - Optional redirect state for navigation errors
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Basic error
50
+ * const err1 = new RouterError("ROUTE_NOT_FOUND");
51
+ *
52
+ * // Error with custom message
53
+ * const err2 = new RouterError("ERR", { message: "Something went wrong" });
54
+ *
55
+ * // Error with context and custom fields
56
+ * const err3 = new RouterError("CANNOT_ACTIVATE", {
57
+ * message: "Insufficient permissions",
58
+ * segment: "admin",
59
+ * path: "/admin/users",
60
+ * userId: "123" // custom field
61
+ * });
62
+ *
63
+ * // Error with redirect
64
+ * const err4 = new RouterError("TRANSITION_ERR", {
65
+ * redirect: { name: "home", path: "/", params: {} }
66
+ * });
67
+ * ```
68
+ */
69
+ constructor(code: string, {
70
+ message,
71
+ segment,
72
+ path,
73
+ redirect,
74
+ ...rest
75
+ }?: {
29
76
  [key: string]: unknown;
30
- readonly segment: string | undefined;
31
- readonly path: string | undefined;
32
- readonly redirect: State | undefined;
33
- code: string;
34
- /**
35
- * Creates a new RouterError instance.
36
- *
37
- * The options object accepts built-in fields (message, segment, path, redirect)
38
- * and any additional custom fields, which will all be attached to the error instance.
39
- *
40
- * @param code - The error code (e.g., "ROUTE_NOT_FOUND", "CANNOT_ACTIVATE")
41
- * @param options - Optional configuration object
42
- * @param options.message - Custom error message (defaults to code if not provided)
43
- * @param options.segment - The route segment where the error occurred
44
- * @param options.path - The full path where the error occurred
45
- * @param options.redirect - Optional redirect state for navigation errors
46
- *
47
- * @example
48
- * ```typescript
49
- * // Basic error
50
- * const err1 = new RouterError("ROUTE_NOT_FOUND");
51
- *
52
- * // Error with custom message
53
- * const err2 = new RouterError("ERR", { message: "Something went wrong" });
54
- *
55
- * // Error with context and custom fields
56
- * const err3 = new RouterError("CANNOT_ACTIVATE", {
57
- * message: "Insufficient permissions",
58
- * segment: "admin",
59
- * path: "/admin/users",
60
- * userId: "123" // custom field
61
- * });
62
- *
63
- * // Error with redirect
64
- * const err4 = new RouterError("TRANSITION_ERR", {
65
- * redirect: { name: "home", path: "/", params: {} }
66
- * });
67
- * ```
68
- */
69
- constructor(code: string, { message, segment, path, redirect, ...rest }?: {
70
- [key: string]: unknown;
71
- message?: string | undefined;
72
- segment?: string | undefined;
73
- path?: string | undefined;
74
- redirect?: State | undefined;
75
- });
76
- /**
77
- * Updates the error code and conditionally updates the message.
78
- *
79
- * If the current message is one of the standard error code values
80
- * (e.g., "ROUTE_NOT_FOUND", "SAME_STATES"), it will be replaced with the new code.
81
- * This allows keeping error messages in sync with codes when using standard error codes.
82
- *
83
- * If the message is custom (not a standard error code), it will be preserved.
84
- *
85
- * @param newCode - The new error code to set
86
- *
87
- * @example
88
- * // Message follows code (standard error code as message)
89
- * const err = new RouterError("ROUTE_NOT_FOUND", { message: "ROUTE_NOT_FOUND" });
90
- * err.setCode("CUSTOM_ERROR"); // message becomes "CUSTOM_ERROR"
91
- *
92
- * @example
93
- * // Custom message is preserved
94
- * const err = new RouterError("ERR", { message: "Custom error message" });
95
- * err.setCode("NEW_CODE"); // message stays "Custom error message"
96
- */
97
- setCode(newCode: string): void;
98
- /**
99
- * Copies properties from another Error instance to this RouterError.
100
- *
101
- * This method updates the message, cause, and stack trace from the provided error.
102
- * Useful for wrapping native errors while preserving error context.
103
- *
104
- * @param err - The Error instance to copy properties from
105
- * @throws {TypeError} If err is null or undefined
106
- *
107
- * @example
108
- * ```typescript
109
- * const routerErr = new RouterError("TRANSITION_ERR");
110
- * try {
111
- * // some operation that might fail
112
- * } catch (nativeErr) {
113
- * routerErr.setErrorInstance(nativeErr);
114
- * throw routerErr;
115
- * }
116
- * ```
117
- */
118
- setErrorInstance(err: Error): void;
119
- /**
120
- * Adds custom fields to the error object.
121
- *
122
- * This method allows attaching arbitrary data to the error for debugging or logging purposes.
123
- * All fields become accessible as properties on the error instance and are included in JSON serialization.
124
- *
125
- * Reserved method names (setCode, setErrorInstance, setAdditionalFields, hasField, getField, toJSON)
126
- * are automatically filtered out to prevent accidental overwriting of class methods.
127
- *
128
- * @param fields - Object containing custom fields to add to the error
129
- *
130
- * @example
131
- * ```typescript
132
- * const err = new RouterError("CANNOT_ACTIVATE");
133
- * err.setAdditionalFields({
134
- * userId: "123",
135
- * attemptedRoute: "/admin",
136
- * reason: "insufficient permissions"
137
- * });
138
- *
139
- * console.log(err.userId); // "123"
140
- * console.log(JSON.stringify(err)); // includes all custom fields
141
- * ```
142
- */
143
- setAdditionalFields(fields: Record<string, unknown>): void;
144
- /**
145
- * Checks if a custom field exists on the error object.
146
- *
147
- * This method checks for both custom fields added via setAdditionalFields()
148
- * and built-in fields (code, message, segment, etc.).
149
- *
150
- * @param key - The field name to check
151
- * @returns `true` if the field exists, `false` otherwise
152
- *
153
- * @example
154
- * ```typescript
155
- * const err = new RouterError("ERR", { segment: "users" });
156
- * err.setAdditionalFields({ userId: "123" });
157
- *
158
- * err.hasField("userId"); // true
159
- * err.hasField("segment"); // true
160
- * err.hasField("unknown"); // false
161
- * ```
162
- */
163
- hasField(key: string): boolean;
164
- /**
165
- * Retrieves a custom field value from the error object.
166
- *
167
- * This method can access both custom fields and built-in fields.
168
- * Returns `undefined` if the field doesn't exist.
169
- *
170
- * @param key - The field name to retrieve
171
- * @returns The field value, or `undefined` if it doesn't exist
172
- *
173
- * @example
174
- * ```typescript
175
- * const err = new RouterError("ERR");
176
- * err.setAdditionalFields({ userId: "123", role: "admin" });
177
- *
178
- * err.getField("userId"); // "123"
179
- * err.getField("role"); // "admin"
180
- * err.getField("code"); // "ERR" (built-in field)
181
- * err.getField("unknown"); // undefined
182
- * ```
183
- */
184
- getField(key: string): unknown;
185
- /**
186
- * Serializes the error to a JSON-compatible object.
187
- *
188
- * This method is automatically called by JSON.stringify() and includes:
189
- * - Built-in fields: code, message, segment (if set), path (if set), redirect (if set)
190
- * - All custom fields added via setAdditionalFields() or constructor
191
- * - Excludes: stack trace (for security/cleanliness)
192
- *
193
- * @returns A plain object representation of the error, suitable for JSON serialization
194
- *
195
- * @example
196
- * ```typescript
197
- * const err = new RouterError("ROUTE_NOT_FOUND", {
198
- * message: "Route not found",
199
- * path: "/admin/users/123"
200
- * });
201
- * err.setAdditionalFields({ userId: "123" });
202
- *
203
- * JSON.stringify(err);
204
- * // {
205
- * // "code": "ROUTE_NOT_FOUND",
206
- * // "message": "Route not found",
207
- * // "path": "/admin/users/123",
208
- * // "userId": "123"
209
- * // }
210
- * ```
211
- */
212
- toJSON(): Record<string, unknown>;
77
+ message?: string | undefined;
78
+ segment?: string | undefined;
79
+ path?: string | undefined;
80
+ redirect?: State$1 | undefined;
81
+ });
82
+ /**
83
+ * Updates the error code and conditionally updates the message.
84
+ *
85
+ * If the current message is one of the standard error code values
86
+ * (e.g., "ROUTE_NOT_FOUND", "SAME_STATES"), it will be replaced with the new code.
87
+ * This allows keeping error messages in sync with codes when using standard error codes.
88
+ *
89
+ * If the message is custom (not a standard error code), it will be preserved.
90
+ *
91
+ * @param newCode - The new error code to set
92
+ *
93
+ * @example
94
+ * // Message follows code (standard error code as message)
95
+ * const err = new RouterError("ROUTE_NOT_FOUND", { message: "ROUTE_NOT_FOUND" });
96
+ * err.setCode("CUSTOM_ERROR"); // message becomes "CUSTOM_ERROR"
97
+ *
98
+ * @example
99
+ * // Custom message is preserved
100
+ * const err = new RouterError("ERR", { message: "Custom error message" });
101
+ * err.setCode("NEW_CODE"); // message stays "Custom error message"
102
+ */
103
+ setCode(newCode: string): void;
104
+ /**
105
+ * Copies properties from another Error instance to this RouterError.
106
+ *
107
+ * This method updates the message, cause, and stack trace from the provided error.
108
+ * Useful for wrapping native errors while preserving error context.
109
+ *
110
+ * @param err - The Error instance to copy properties from
111
+ * @throws {TypeError} If err is null or undefined
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const routerErr = new RouterError("TRANSITION_ERR");
116
+ * try {
117
+ * // some operation that might fail
118
+ * } catch (nativeErr) {
119
+ * routerErr.setErrorInstance(nativeErr);
120
+ * throw routerErr;
121
+ * }
122
+ * ```
123
+ */
124
+ setErrorInstance(err: Error): void;
125
+ /**
126
+ * Adds custom fields to the error object.
127
+ *
128
+ * This method allows attaching arbitrary data to the error for debugging or logging purposes.
129
+ * All fields become accessible as properties on the error instance and are included in JSON serialization.
130
+ *
131
+ * Reserved method names (setCode, setErrorInstance, setAdditionalFields, hasField, getField, toJSON)
132
+ * are automatically filtered out to prevent accidental overwriting of class methods.
133
+ *
134
+ * @param fields - Object containing custom fields to add to the error
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const err = new RouterError("CANNOT_ACTIVATE");
139
+ * err.setAdditionalFields({
140
+ * userId: "123",
141
+ * attemptedRoute: "/admin",
142
+ * reason: "insufficient permissions"
143
+ * });
144
+ *
145
+ * console.log(err.userId); // "123"
146
+ * console.log(JSON.stringify(err)); // includes all custom fields
147
+ * ```
148
+ */
149
+ setAdditionalFields(fields: Record<string, unknown>): void;
150
+ /**
151
+ * Checks if a custom field exists on the error object.
152
+ *
153
+ * This method checks for both custom fields added via setAdditionalFields()
154
+ * and built-in fields (code, message, segment, etc.).
155
+ *
156
+ * @param key - The field name to check
157
+ * @returns `true` if the field exists, `false` otherwise
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const err = new RouterError("ERR", { segment: "users" });
162
+ * err.setAdditionalFields({ userId: "123" });
163
+ *
164
+ * err.hasField("userId"); // true
165
+ * err.hasField("segment"); // true
166
+ * err.hasField("unknown"); // false
167
+ * ```
168
+ */
169
+ hasField(key: string): boolean;
170
+ /**
171
+ * Retrieves a custom field value from the error object.
172
+ *
173
+ * This method can access both custom fields and built-in fields.
174
+ * Returns `undefined` if the field doesn't exist.
175
+ *
176
+ * @param key - The field name to retrieve
177
+ * @returns The field value, or `undefined` if it doesn't exist
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const err = new RouterError("ERR");
182
+ * err.setAdditionalFields({ userId: "123", role: "admin" });
183
+ *
184
+ * err.getField("userId"); // "123"
185
+ * err.getField("role"); // "admin"
186
+ * err.getField("code"); // "ERR" (built-in field)
187
+ * err.getField("unknown"); // undefined
188
+ * ```
189
+ */
190
+ getField(key: string): unknown;
191
+ /**
192
+ * Serializes the error to a JSON-compatible object.
193
+ *
194
+ * This method is automatically called by JSON.stringify() and includes:
195
+ * - Built-in fields: code, message, segment (if set), path (if set), redirect (if set)
196
+ * - All custom fields added via setAdditionalFields() or constructor
197
+ * - Excludes: stack trace (for security/cleanliness)
198
+ *
199
+ * @returns A plain object representation of the error, suitable for JSON serialization
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const err = new RouterError("ROUTE_NOT_FOUND", {
204
+ * message: "Route not found",
205
+ * path: "/admin/users/123"
206
+ * });
207
+ * err.setAdditionalFields({ userId: "123" });
208
+ *
209
+ * JSON.stringify(err);
210
+ * // {
211
+ * // "code": "ROUTE_NOT_FOUND",
212
+ * // "message": "Route not found",
213
+ * // "path": "/admin/users/123",
214
+ * // "userId": "123"
215
+ * // }
216
+ * ```
217
+ */
218
+ toJSON(): Record<string, unknown>;
213
219
  }
214
-
220
+ //#endregion
221
+ //#region src/createRouter.d.ts
215
222
  /**
216
223
  * Creates a new router instance.
217
224
  *
@@ -228,10 +235,13 @@ declare class RouterError extends Error {
228
235
  *
229
236
  * router.start('/');
230
237
  */
231
- declare const createRouter: <Dependencies extends DefaultDependencies = DefaultDependencies>(routes?: Route<Dependencies>[], options?: Partial<Options>, dependencies?: Dependencies) => Router<Dependencies>;
232
-
233
- declare const getNavigator: <Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router$1<Dependencies>) => Navigator;
234
-
238
+ declare const createRouter: <Dependencies extends DefaultDependencies$1 = DefaultDependencies$1>(routes?: Route<Dependencies>[], options?: Partial<Options$1>, dependencies?: Dependencies) => Router<Dependencies>;
239
+ //#endregion
240
+ //#region src/getNavigator.d.ts
241
+ declare const getNavigator: <Dependencies extends DefaultDependencies$1 = DefaultDependencies$1>(router: Router$1<Dependencies>) => Navigator$1;
242
+ //#endregion
243
+ //#region src/namespaces/RoutesNamespace/forwardChain.d.ts
235
244
  declare function resolveForwardChain(startRoute: string, forwardMap: Record<string, string>, maxDepth?: number): string;
236
-
237
- export { type Constants, type ErrorCodes, Router, RouterError, UNKNOWN_ROUTE, constants, createRouter, errorCodes, events, getNavigator, resolveForwardChain };
245
+ //#endregion
246
+ export { type BuildStateResultWithSegments, type Config, type Constants, type DefaultDependencies, type ErrorCodes, type GuardFn, type GuardFnFactory, type Listener, type NavigationOptions, type Navigator, type Options, type Params, type Plugin, type PluginFactory, type Route, type RouteConfigUpdate, type RouteTree, Router, RouterError, type RouterValidator, type SimpleState, type State, type SubscribeFn, type SubscribeState, type Subscription, UNKNOWN_ROUTE, type Unsubscribe, constants, createRouter, errorCodes, events, getNavigator, resolveForwardChain };
247
+ //# sourceMappingURL=index.d.ts.map
package/dist/cjs/index.js CHANGED
@@ -1 +1,2 @@
1
- var t=require("@real-router/logger"),e=require("@real-router/fsm"),n={maxListeners:0,warnListeners:0,maxEventDepth:0},r=class extends Error{},i=class{#t=new Map;#e=null;#n=n;#r;#i;constructor(t){t?.limits&&(this.#n=t.limits),this.#r=t?.onListenerError??null,this.#i=t?.onListenerWarn??null}static validateCallback(t,e){if("function"!=typeof t)throw new TypeError(`Expected callback to be a function for event ${e}`)}setLimits(t){this.#n=t}on(t,e){const n=this.#s(t);if(n.has(e))throw new Error(`Duplicate listener for "${t}"`);const{maxListeners:r,warnListeners:i}=this.#n;if(0!==i&&n.size===i&&this.#i?.(t,i),0!==r&&n.size>=r)throw new Error(`Listener limit (${r}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,r,i){const s=this.#t.get(t);if(!s||0===s.size)return;const a=arguments.length-1;0!==this.#n.maxEventDepth?this.#a(s,t,a,e,n,r,i):this.#o(s,t,a,e,n,r,i)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,r,i,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,r,i,s,a)}catch(t){this.#r?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,r,i,s,a)}catch(t){this.#r?.(e,t)}}#c(t,e,n,r,i,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,r);break;case 3:t(n,r,i);break;default:t(n,r,i,s)}}#a(t,e,n,i,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new r(`Maximum recursion depth (${this.#n.maxEventDepth}) exceeded for event: ${e}`);try{c.set(e,u+1);const l=1===t.size?t:[...t];for(const t of l)try{this.#c(t,n,i,s,a,o)}catch(t){if(t instanceof r)throw t;this.#r?.(e,t)}}finally{c.set(e,c.get(e)-1)}}#s(t){const e=this.#t.get(t);if(e)return e;const n=new Set;return this.#t.set(t,n),n}},s=Object.freeze({ROUTER_NOT_STARTED:"NOT_STARTED",NO_START_PATH_OR_STATE:"NO_START_PATH_OR_STATE",ROUTER_ALREADY_STARTED:"ALREADY_STARTED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",SAME_STATES:"SAME_STATES",CANNOT_DEACTIVATE:"CANNOT_DEACTIVATE",CANNOT_ACTIVATE:"CANNOT_ACTIVATE",TRANSITION_ERR:"TRANSITION_ERR",TRANSITION_CANCELLED:"CANCELLED",ROUTER_DISPOSED:"DISPOSED",PLUGIN_CONFLICT:"PLUGIN_CONFLICT"}),a="@@router/UNKNOWN_ROUTE",o={UNKNOWN_ROUTE:a},c="onStart",u="onStop",l="onTransitionStart",h="onTransitionCancel",d="onTransitionSuccess",f="onTransitionError",p={ROUTER_START:"$start",ROUTER_STOP:"$stop",TRANSITION_START:"$$start",TRANSITION_CANCEL:"$$cancel",TRANSITION_SUCCESS:"$$success",TRANSITION_ERROR:"$$error"},g={maxDependencies:100,maxPlugins:50,maxListeners:1e4,warnListeners:1e3,maxEventDepth:5,maxLifecycleHandlers:200},m=Object.freeze({}),v="IDLE",S="STARTING",T="READY",y="TRANSITIONING",w="DISPOSED",b="START",N="STARTED",A="NAVIGATE",O="COMPLETE",E="FAIL",P="CANCEL",R="STOP",C="DISPOSE",D={initial:v,context:null,transitions:{[v]:{[b]:S,[C]:w},[S]:{[N]:T,[E]:v},[T]:{[A]:y,[E]:T,[R]:v},[y]:{[A]:y,[O]:T,[P]:T,[E]:T},[w]:{}}};function F(t,e){for(const e of t){if(null===e||"object"!=typeof e||Array.isArray(e))throw new TypeError("route must be a non-array object");const t=e.children;t&&F(t)}}var j=new WeakSet;function L(t){if(null!==t&&"object"==typeof t&&!Object.isFrozen(t))if(Object.freeze(t),Array.isArray(t))for(const e of t)L(e);else for(const e in t)L(t[e])}function I(t){return t?(j.has(t)||(L(t),j.add(t)),t):t}var _=new WeakMap;function M(t){const e=_.get(t);if(!e)throw new TypeError("[real-router] Invalid router instance — not found in internals registry");return e}function U(t,e,n){let r=e;for(const e of t){const t=r;r=(...n)=>e(t,...n)}return r(...n)}function $(t,e,n){return(r,i)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[r,i]):e(r,i)}}var B={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function x(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&x(n)}return t}function k(t,e){return"function"==typeof t?t(e):t}var z=class{#u;constructor(t={}){this.#u=x({...B,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function q(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!q(t[n],e[n]))return!1;return!0}return!1}var G=new WeakMap;function W(t){return G.get(t)}var V=class{#l=void 0;#h=void 0;#d;#f=new Map;get(){return this.#l}set(t){this.#h=this.#l,this.#l=t?I(t):void 0}getPrevious(){return this.#h}reset(){this.#l=void 0,this.#h=void 0,this.#f.clear()}setDependencies(t){this.#d=t}makeState(t,e,n,r,i){const s=this.#d.getDefaultParams();let a;a=Object.hasOwn(s,t)?{...s[t],...e}:e&&e!==m?{...e}:m;const o={name:t,params:a,path:n??this.#d.buildPath(t,e)};return r&&function(t,e){G.set(t,e)}(o,r),i?o:I(o)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=this.#p(t.name);for(const r of n)if(!q(t.params[r],e.params[r]))return!1;return!0}const r=Object.keys(t.params),i=Object.keys(e.params);if(r.length!==i.length)return!1;for(const n of r)if(!(n in e.params)||!q(t.params[n],e.params[n]))return!1;return!0}#p(t){const e=this.#f.get(t);if(void 0!==e)return e;const n=this.#d.getUrlParams(t);return this.#f.set(t,n),n}},Q={[c]:p.ROUTER_START,[u]:p.ROUTER_STOP,[d]:p.TRANSITION_SUCCESS,[l]:p.TRANSITION_START,[f]:p.TRANSITION_ERROR,[h]:p.TRANSITION_CANCEL},K=Object.keys(Q),H="router.usePlugin",J=class e{#g=new Set;#m=new Set;#d;#v=g;#S=null;static validatePlugin(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.usePlugin] Plugin factory must return an object, got "+typeof t);if("function"==typeof t.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#d=t}setLimits(t){this.#v=t,this.#v}setValidatorGetter(t){this.#S=t}count(){return this.#g.size}use(...e){if(this.#S?.()?.plugins.validateCountThresholds(this.#g.size+e.length),1===e.length){const n=e[0],r=this.#T(n);this.#g.add(n);let i=!1;const s=()=>{if(!i){i=!0,this.#g.delete(n),this.#m.delete(s);try{r()}catch(e){t.logger.error(H,"Error during cleanup:",e)}}};return this.#m.add(s),s}const n=this.#y(e),r=[];try{for(const t of n){const e=this.#T(t);r.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(H,"Cleanup error:",e)}throw e}for(const{factory:t}of r)this.#g.add(t);let i=!1;const s=()=>{if(!i){i=!0,this.#m.delete(s);for(const{factory:t}of r)this.#g.delete(t);for(const{cleanup:e}of r)try{e()}catch(e){t.logger.error(H,"Error during cleanup:",e)}}};return this.#m.add(s),s}getAll(){return[...this.#g]}has(t){return this.#g.has(t)}disposeAll(){for(const t of this.#m)t();this.#g.clear(),this.#m.clear()}#y(t){const e=new Set;for(const n of t)e.has(n)?this.#S?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#T(t){const n=this.#d.compileFactory(t);e.validatePlugin(n),this.#S?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const r=[];for(const t of K)t in n&&("function"==typeof n[t]?(r.push(this.#d.addEventListener(Q[t],n[t])),"onStart"===t&&this.#d.canNavigate()&&this.#S?.()?.plugins.warnPluginAfterStart(t)):this.#S?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of r)t();"function"==typeof n.teardown&&n.teardown()}}},Y=class{#w=new Map;#b=new Map;#N=new Map;#A=new Map;#O=[this.#N,this.#A];#E=new Set;#P=new Set;#R=new Set;#d;#v=g;#S=null;setDependencies(t){this.#d=t}setLimits(t){this.#v=t,this.#v}setValidatorGetter(t){this.#S=t}getHandlerCount(t){return"activate"===t?this.#b.size:this.#w.size}addCanActivate(t,e,n=!1){n?this.#P.add(t):this.#P.delete(t);const r=this.#b.has(t);this.#C("activate",t,e,this.#b,this.#A,"canActivate",r)}addCanDeactivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const r=this.#w.has(t);this.#C("deactivate",t,e,this.#w,this.#N,"canDeactivate",r)}clearCanActivate(t){this.#b.delete(t),this.#A.delete(t),this.#P.delete(t)}clearCanDeactivate(t){this.#w.delete(t),this.#N.delete(t),this.#R.delete(t)}clearAll(){this.#b.clear(),this.#A.clear(),this.#w.clear(),this.#N.clear(),this.#P.clear(),this.#R.clear()}clearDefinitionGuards(){for(const t of this.#P)this.#b.delete(t),this.#A.delete(t);for(const t of this.#R)this.#w.delete(t),this.#N.delete(t);this.#P.clear(),this.#R.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#w)t[e]=n;for(const[t,n]of this.#b)e[t]=n;return[t,e]}getFunctions(){return this.#O}canNavigateTo(t,e,n,r){for(const e of t)if(!this.#D(this.#N,e,n,r,"canNavigateTo"))return!1;for(const t of e)if(!this.#D(this.#A,t,n,r,"canNavigateTo"))return!1;return!0}#C(t,e,n,r,i,s,a){a?this.#S?.()?.lifecycle.warnOverwrite(e,t,s):this.#S?.()?.lifecycle.validateCountThresholds(r.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;r.set(e,o),this.#E.add(e);try{const t=this.#d.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${s}] Factory must return a function, got ${typeof t}`);i.set(e,t)}catch(t){throw r.delete(e),t}finally{this.#E.delete(e)}}#D(t,e,n,r,i){const s=t.get(e);if(!s)return!0;try{const t=s(n,r);return"boolean"==typeof t?t:(this.#S?.()?.lifecycle.warnAsyncGuardSync(e,i),!1)}catch{return!1}}};function X(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Z(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Z(t))),e}function tt(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var et=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,nt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,rt=/\?(.+)$/,it=/[^\w!$'()*+,.:;|~-]/gu,st=/[^\w!$'()*+,.:;|~-]/u,at={default:t=>st.test(t)?t.replaceAll(it,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},ot={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function ct(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ut(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function lt(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function ht(t){const e=[];for(const n of Object.keys(t)){const r=t[n],i=encodeURIComponent(n);e.push(""===r?i:`${i}=${encodeURIComponent(String(r))}`)}return e.join("&")}function dt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ft(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,r=t.codePointAt(e+2)??0;if(!dt(n)||!dt(r))return!1;e+=3}else e++;return!0}var pt=/<[^>]*>/g;function gt(t,e,n,r,i){const s=""===e.fullName;s||r.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(pt,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=i;s||(f=function(t,e,n,r,i,s){const a=(m=r,ut(n)===ut(m)),o=Object.freeze([...i]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=ut(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,i),h=function(t){const e=new Map;for(const n of t)for(const[t,r]of n.paramMeta.constraintPatterns)e.set(t,r);return e}(i),d=a?ut(r):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const r=new Set,i=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)r.add(e);for(const e of t.paramMeta.spatParams)i.add(e)}if(0===r.size)return{buildStaticParts:[t],buildParamSlots:[]};const s=[],a=[],o=/[:*]([\w]+)(?:<[^>]*>)?(\?)?/gu;let c,u=0;for(;null!==(c=o.exec(t));){const e=c[1],r="?"===c[2];s.push(t.slice(u,c.index));const o=i.has(e);a.push({paramName:e,isOptional:r,encoder:o?t=>{const e=at[n],r=t.split("/");let i=e(r[0]);for(let t=1;t<r.length;t++)i+=`/${e(r[t])}`;return i}:at[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?i.slice(0,-1):i,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:i.length-1,matchSegments:o,meta:c,declaredQueryParams:l,declaredQueryParamsSet:new Set(l),hasTrailingSlash:n.length>1&&n.endsWith("/"),constraintPatterns:h,hasConstraints:h.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:new Set(p.map(t=>t.paramName))};var m;return t.routesByName.set(e.fullName,g),t.segmentsByName.set(e.fullName,o),t.metaByName.set(e.fullName,c),a?function(t,e,n){var r,i;r=e,(function(t,e,n){const r=ut(n);if("/"===r||""===r)return e;let i=e,s=1;const a=r.length;for(;s<=a;){const e=r.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;i=vt(t,i,r.slice(s,n)),s=n+1}return i}(i=t,i.root,n)).slashChildRoute=r;const s=ut(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,r):function(t,e,n,r,i){if(function(t,e,n){const r=ut(n);"/"!==r?mt(t,t.root,r,1,e):t.root.route=e}(t,e,n),0===i.paramMeta.urlParams.length){const n=t.options.caseSensitive?r:r.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,r,i));for(const n of e.children.values())gt(t,n,l,r,f);s||r.pop()}function mt(t,e,n,r,i){const s=n.length;for(;r<=s;){const a=n.indexOf("/",r),o=-1===a?s:a,c=n.slice(r,o);if(c.endsWith("?")){const r=c.slice(1).replaceAll(pt,"").replace(/\?$/,"");return e.paramChild??={node:ct(),name:r},mt(t,e.paramChild.node,n,o+1,i),void(o>=s?e.route??=i:mt(t,e,n,o+1,i))}e=vt(t,e,c),r=o+1}e.route=i}function vt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:ct(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(pt,"").replace(/\?$/,"");return e.paramChild??={node:ct(),name:t},e.paramChild.node}const r=t.options.caseSensitive?n:n.toLowerCase();return r in e.staticChildren||(e.staticChildren[r]=ct()),e.staticChildren[r]}var St=/[\u0080-\uFFFF]/,Tt=class{get options(){return this.#t}#t;#e=ct();#i=new Map;#s=new Map;#n=new Map;#a=new Map;#r="";#F=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??lt,buildQueryString:t?.buildQueryString??ht}}registerTree(t){this.#F=t.paramMeta.queryParams,gt({root:this.#e,options:this.#t,routesByName:this.#i,segmentsByName:this.#s,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#F},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,r,i]=e,s=this.#t.caseSensitive?r:r.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#j(a,{},i)}const o={},c=this.#L(r,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#I(o,c)||!this.#_(o)?void 0:this.#j(c,o,i)}buildPath(t,e,n){const r=this.#i.get(t);if(!r)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);r.hasConstraints&&e&&this.#M(r,t,e);const i=this.#U(r,e),s=this.#$(i,n?.trailingSlash),a=this.#B(r,e,n?.queryParamsMode);return s+(a?`?${a}`:"")}getSegmentsByName(t){return this.#s.get(t)}getMetaByName(t){return this.#n.get(t)}hasRoute(t){return this.#i.has(t)}setRootPath(t){this.#r=t}#M(t,e,n){for(const[r,i]of t.constraintPatterns){const t=n[r];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!i.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#U(t,e){const n=t.buildStaticParts,r=t.buildParamSlots;if(0===r.length)return this.#r+n[0];let i=this.#r+n[0];for(const[t,s]of r.entries()){const r=e?.[s.paramName];if(null==r){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i+=n[t+1];continue}const a="object"==typeof r?JSON.stringify(r):String(r);i+=s.encoder(a)+n[t+1]}return i}#$(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#B(t,e,n){if(!e)return"";const r={};let i=!1;for(const n of t.declaredQueryParams)n in e&&(r[n]=e[n],i=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(r[n]=e[n],i=!0);return i?this.#t.buildQueryString(r):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),St.test(t))return;if(this.#r.length>0){if(!t.startsWith(this.#r))return;t=t.slice(this.#r.length)||"/"}const n=t.indexOf("?"),r=-1===n?t:t.slice(0,n),i=-1===n?void 0:t.slice(n+1);return r.includes("//")?void 0:[r,ut(r),i]}#j(t,e,n){if(void 0!==n){const r=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(r))if(!e.has(t))return}for(const t of Object.keys(r))e[t]=r[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#L(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#x(this.#e,t,1,e)}#x(t,e,n,r){let i=t;const s=e.length;for(;n<=s;){const t=e.indexOf("/",n),a=-1===t?s:t,o=e.slice(n,a),c=this.#t.caseSensitive?o:o.toLowerCase();let u;if(c in i.staticChildren)u=i.staticChildren[c];else{if(!i.paramChild){if(i.splatChild){const t={},s=this.#x(i.splatChild.node,e,n,t);return s?(Object.assign(r,t),s):(r[i.splatChild.name]=e.slice(n),i.splatChild.node.route)}return}u=i.paramChild.node,r[i.paramChild.name]=o}i=u,n=a+1}return i.slashChildRoute??i.route}#_(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=ot[e];for(const e in t){const r=t[e];if(r.includes("%")){if(!ft(r))return!1;t[e]=n(r)}}return!0}#I(t,e){for(const[n,r]of e.constraintPatterns)if(!r.pattern.test(t[n]))return!1;return!0}},yt=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const r=-1===n?t:t.split("+").join(" ");return-1===e?r:decodeURIComponent(r)},wt=t=>{const e=typeof t;if("string"!==e&&"number"!==e&&"boolean"!==e)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===e&&null===t?"null":e}`);return encodeURIComponent(t)},bt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${wt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${wt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${wt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>wt(t)).join(",")}`}},Nt={none:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:t=>t},string:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:t=>"true"===t||"false"!==t&&null,decodeValue:t=>t},"empty-true":{encode:(t,e)=>e?t:`${t}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:t=>t}},At={default:{encode:t=>t},hidden:{encode:()=>""}},Ot=(t,e,n)=>({boolean:Nt[e],null:At[n],array:bt[t]}),Et={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:Nt.none,null:At.default,array:bt.none}},Pt=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return Et;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",r=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:r,strategies:Ot(e,n,r)}},Rt=t=>encodeURIComponent(t),Ct=(t,e,n)=>{const r=Rt(t);switch(typeof e){case"string":case"number":default:return`${r}=${Rt(e)}`;case"boolean":return n.strategies.boolean.encode(r,e);case"object":return null===e?n.strategies.null.encode(r):Array.isArray(e)?n.strategies.array.encodeArray(r,e):`${r}=${Rt(e)}`}};function Dt(t,e,n,r,i){const s=t.indexOf("=",e),a=-1!==s&&s<n,o=t.slice(e,a?s:n),{name:c,hasBrackets:u}=function(t){const e=t.indexOf("[");return-1===e?{name:t,hasBrackets:!1}:{name:t.slice(0,e),hasBrackets:!0}}(o);var l,h,d,f,p;!function(t,e,n,r){const i=t[e];void 0===i?t[e]=r?[n]:n:Array.isArray(i)?i.push(n):t[e]=[i,n]}(r,yt(c),(l=t,h=s,d=n,f=a,p=i,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const r=yt(t);return e.boolean.decodeValue(r)})(f?l.slice(h+1,d):void 0,p):f?yt(l.slice(h+1,d)):null),u)}function Ft(t,e){const n=t.path,r=n.startsWith("~"),i=r?n.slice(1):n,s={name:t.name,path:i,absolute:r,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ft(e,s);s.children.push(t)}return s}function jt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Lt(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function It(t,e,n){const r=function(t){const e=[],n=[],r=[],i={},s=new Map,a=t.replaceAll(nt,"$1"),o=rt.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),i[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=et.exec(t));){const t=c[2],n=c[3];if("*"===c[1])r.push(t),e.push(t),i[t]="url";else if(e.push(t),i[t]="url",n){const e=`^${tt(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:r,paramTypeMap:i,constraintPatterns:s,pathPattern:t}}(t.path),i=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(r),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:i};var a;s.fullName=(a=s,a.parent?.name?`${a.parent.fullName}.${a.name}`:a.name);const{childrenMap:o,nonAbsoluteChildren:c}=function(t,e,n){const r=[],i=[];for(const s of t){const t=It(s,e,n);r.push(t),t.absolute||i.push(t)}return{childrenMap:Lt(r),nonAbsoluteChildren:i}}(t.children,s,n);return s.children=o,s.nonAbsoluteChildren=c,s.staticPath=function(t){if(!t.path)return null;const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;const i=[];let s=t.parent;for(;s?.path;)i.unshift(s),s=s.parent;let a="";for(const t of i){const{urlParams:e,queryParams:n,spatParams:r}=t.paramMeta;if(e.length>0||n.length>0||r.length>0)return null;a=t.absolute?t.path:jt(a,t.path)}return t.absolute?t.path:jt(a,t.path)}(s),n&&(Object.freeze(c),Object.freeze(i),Object.freeze(s.children),Object.freeze(s)),s}function _t(t,e,n,r){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:r=>function(t,e=!0){return It(t,null,e)}(function(t,e,n){const r=Ft({name:t,path:e},null);for(const t of n){const e=Ft(t,r);r.children.push(e)}return r}(t,e,n),!r?.skipFreeze)}}(t,e).addMany(n).build(r)}function Mt(t){const e={name:t.name,path:t.absolute?`~${t.path}`:t.path};return t.children.size>0&&(e.children=[...t.children.values()].map(t=>Mt(t))),e}function Ut(t){const e=t?.queryParams;return new Tt({...void 0===t?.caseSensitive?void 0:{caseSensitive:t.caseSensitive},...void 0===t?.strictTrailingSlash?void 0:{strictTrailingSlash:t.strictTrailingSlash},...void 0===t?.strictQueryParams?void 0:{strictQueryParams:t.strictQueryParams},...void 0===t?.urlParamsEncoding?void 0:{urlParamsEncoding:t.urlParamsEncoding},parseQueryString:t=>((t,e)=>{const n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const r=t.length;for(;n<r;){let i=t.indexOf("&",n);-1===i&&(i=r),Dt(t,n,i,e),n=i+1}}(t,e),e}(n);const r=Pt(e),i={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Dt(n,s,t,i,r.strategies),s=t+1}return i})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const r=Pt(e),i=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Ct(e,n,r);s&&i.push(s)}return i.join("&")})(t,e)})}function $t(t,e,n=100){const r=new Set,i=[t];let s=t;for(;e[s];){const t=e[s];if(r.has(t)){const e=i.indexOf(t),n=[...i.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(r.add(s),i.push(t),s=t,i.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${i.join(" → ")}`)}return s}function Bt(t,e,n){const r=_t("",e,t),i=Ut(n);return i.registerTree(r),{tree:r,matcher:i}}function xt(t){const e=Bt(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=qt(t.config)}function kt(t){const e=Bt(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function zt(t){!function(t){t.definitions.length=0,Object.assign(t.config,X()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),kt(t)}function qt(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=$t(n,t.forwardMap);return e}function Gt(e,n,r,i,s,a,o){const c=new Set(["name","path","children","canActivate","canDeactivate","forwardTo","encodeParams","decodeParams","defaultParams"]),u=Object.fromEntries(Object.entries(e).filter(([t])=>!c.has(t)));Object.keys(u).length>0&&(i[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,r){if(e.canActivate&&t.logger.warn("real-router",`Route "${n}" has both forwardTo and canActivate. canActivate will be ignored because forwardTo creates a redirect (industry standard). Move canActivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),e.canDeactivate&&t.logger.warn("real-router",`Route "${n}" has both forwardTo and canDeactivate. canDeactivate will be ignored because forwardTo creates a redirect (industry standard). Move canDeactivate to the target route "${"string"==typeof e.forwardTo?e.forwardTo:"[dynamic]"}".`),"function"==typeof e.forwardTo){const t="AsyncFunction"===e.forwardTo.constructor.name,r=e.forwardTo.toString().includes("__awaiter");if(t||r)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?r.forwardMap[n]=e.forwardTo:r.forwardFnMap[n]=e.forwardTo}(e,n,r),e.decodeParams&&(r.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(r.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(r.defaultParams[n]=e.defaultParams)}function Wt(t,e,n,r,i,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;Gt(o,t,e,n,r,i),o.children&&Wt(o.children,e,n,r,i,s,t)}}function Vt(t,e){const n=[],r=X(),i=Object.create(null),s=new Map,a=new Map;for(const e of t)n.push(Z(e));const{tree:o,matcher:c}=Bt(n,"",e);return Wt(t,r,i,s,a,void 0,""),{definitions:n,config:r,tree:o,matcher:c,resolvedForwardMap:qt(r),routeCustomFields:i,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:s,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:xt,resetStore:zt,nodeToDefinition:Mt}}}var Qt=".",Kt=[];function Ht(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Jt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Yt(t,e,n,r){const i=e[t];if(!i||"object"!=typeof i)return!0;for(const t of Object.keys(i)){const e=n.params[t],i=r.params[t];if(Jt(e)&&Jt(i)&&String(e)!==String(i))return!1}return!0}Object.freeze(Kt);var Xt,Zt,te=new Map;function ee(t){const e=te.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(Qt);if(-1===e)return[t];const n=t.indexOf(Qt,e+1);if(-1===n)return[t.slice(0,e),t];const r=t.indexOf(Qt,n+1);if(-1===r)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Qt,r+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,r),t]:function(t){const e=t.split(Qt),n=e.length,r=[e[0]];let i=e[0].length;for(let s=1;s<n-1;s++)i+=1+e[s].length,r.push(t.slice(0,i));return r.push(t),r}(t)}(t);return Object.freeze(n),te.set(t,n),n}var ne,re,ie=null,se=null;function ae(t,e){if(null!==ie&&t===Xt&&e===Zt)return ie;if(null!==se&&t===ne&&e===re)return se;const n=function(t,e){if(!e)return{intersection:"",toActivate:ee(t.name),toDeactivate:Kt};const n=W(t),r=W(e);if(!n&&!r)return{intersection:"",toActivate:ee(t.name),toDeactivate:Ht(ee(e.name))};const i=ee(t.name),s=ee(e.name),a=function(t,e,n,r,i,s){for(let a=0;a<s;a++){const s=r[a];if(s!==i[a])return a;if(!Yt(s,t,e,n))return a}return s}(n??r,t,e,i,s,Math.min(s.length,i.length));let o;if(a>=s.length)o=Kt;else if(0===a&&1===s.length)o=s;else{o=[];for(let t=s.length-1;t>=a;t--)o.push(s[t])}const c=0===a?i:i.slice(a);return{intersection:a>0?s[a-1]:"",toDeactivate:o,toActivate:c}}(t,e);return ne=Xt,re=Zt,se=ie,Xt=t,Zt=e,ie=n,n}function oe(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var ce=class{#k;#z;get#d(){return this.#k.depsStore}constructor(t=[],e){this.#k=Vt(t,e)}static shouldUpdateNode(t){return(e,n)=>{if(!e||"object"!=typeof e||!("name"in e))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(e.transition?.reload)return!0;if(""===t&&!n)return!0;const{intersection:r,toActivate:i,toDeactivate:s}=ae(e,n);return t===r||!!i.includes(t)||s.includes(t)}}setDependencies(t){this.#k.depsStore=t;for(const[e,n]of this.#k.pendingCanActivate)t.addActivateGuard(e,n);this.#k.pendingCanActivate.clear();for(const[e,n]of this.#k.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#k.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#k.lifecycleNamespace=t}setRootPath(t){this.#k.rootPath=t,kt(this.#k)}hasRoute(t){return this.#k.matcher.hasRoute(t)}clearRoutes(){zt(this.#k)}buildPath(t,e,n){if(t===o.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const r=Object.hasOwn(this.#k.config.defaultParams,t)?{...this.#k.config.defaultParams[t],...e}:e??{},i="function"==typeof this.#k.config.encoders[t]?this.#k.config.encoders[t]({...r}):r;return this.#k.matcher.buildPath(t,i,this.#q(n))}matchPath(t,e){const n=e,r=this.#k.matcher.match(t);if(!r)return;const i=oe(r),{name:s,params:a,meta:o}=i,c="function"==typeof this.#k.config.decoders[s]?this.#k.config.decoders[s](a):a,{name:u,params:l}=this.#d.forwardState(s,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#k.config.encoders[u]?this.#k.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#k.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#d.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#k.config.forwardFnMap,t)){const n=this.#G(t,e),r=this.#k.config.forwardFnMap[t],i=this.#W(t,r,e);return{name:i,params:this.#G(i,n)}}const n=this.#k.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#k.config.forwardFnMap,n)){const r=this.#G(t,e),i=this.#k.config.forwardFnMap[n],s=this.#W(n,i,e);return{name:s,params:this.#G(s,r)}}if(n!==t){const r=this.#G(t,e);return{name:n,params:this.#G(n,r)}}return{name:t,params:this.#G(t,e)}}buildStateResolved(t,e){const n=this.#k.matcher.getSegmentsByName(t);if(n)return oe({segments:n,params:e,meta:this.#k.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,r=!0){const i=this.#d.getState();if(!i)return!1;const s=i.name;if(s!==t&&!s.startsWith(`${t}.`)&&!t.startsWith(`${s}.`))return!1;const a=this.#k.config.defaultParams[t];if(n||s===t){const n=a?{...a,...e}:e;return this.#d.areStatesEqual({name:t,params:n,path:""},i,r)}const o=i.params;return!!function(t,e){for(const n in t)if(t[n]!==e[n])return!1;return!0}(e,o)&&(!a||function(t,e,n){for(const r in t)if(!(r in n)&&t[r]!==e[r])return!1;return!0}(a,o,e))}getMetaForState(t){return this.#k.matcher.hasRoute(t)?this.#k.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#k.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#k}#G(t,e){return Object.hasOwn(this.#k.config.defaultParams,t)?{...this.#k.config.defaultParams[t],...e}:e}#q(t){if(this.#z)return this.#z;const e=t?.trailingSlash;return this.#z=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#z}#W(t,e,n){const r=new Set([t]);let i=e(this.#d.getDependency,n),s=0;if("string"!=typeof i)throw new TypeError("forwardTo callback must return a string, got "+typeof i);for(;s<100;){if(void 0===this.#k.matcher.getSegmentsByName(i))throw new Error(`Route "${i}" does not exist`);if(r.has(i)){const t=[...r,i].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(r.add(i),Object.hasOwn(this.#k.config.forwardFnMap,i)){i=(0,this.#k.config.forwardFnMap[i])(this.#d.getDependency,n),s++;continue}const t=this.#k.config.forwardMap[i];if(void 0===t)return i;i=t,s++}throw new Error("forwardTo exceeds maximum depth of 100")}},ue=new Set(Object.values(s)),le=new Set(["code","segment","path","redirect"]),he=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),de=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:n,path:r,redirect:i,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=r,this.redirect=i?function(t){if(!t)return t;if(null===(e=t)||"object"!=typeof e||"string"!=typeof e.name||"string"!=typeof e.path||"object"!=typeof e.params||null===e.params)throw new TypeError("[deepFreezeState] Expected valid State object, got: "+typeof t);var e;const n=structuredClone(t),r=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(r.has(e))return;r.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(i):void 0;for(const[t,e]of Object.entries(s)){if(le.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);he.has(t)||(this[t]=e)}}setCode(t){this.code=t,ue.has(this.message)&&(this.message=t)}setErrorInstance(t){if(!t)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=t.message,this.cause=t.cause,this.stack=t.stack??""}setAdditionalFields(t){for(const[e,n]of Object.entries(t)){if(le.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);he.has(e)||(this[e]=n)}}hasField(t){return t in this}getField(t){return this[t]}toJSON(){const t={code:this.code,message:this.message};void 0!==this.segment&&(t.segment=this.segment),void 0!==this.path&&(t.path=this.path),void 0!==this.redirect&&(t.redirect=this.redirect);const e=new Set(["code","message","segment","path","redirect","stack"]);for(const n in this)Object.hasOwn(this,n)&&!e.has(n)&&(t[n]=this[n]);return t}},fe=new de(s.ROUTER_NOT_STARTED),pe=new de(s.ROUTE_NOT_FOUND),ge=new de(s.SAME_STATES),me=Promise.reject(fe),ve=Promise.reject(pe),Se=Promise.reject(ge);function Te(t,e){const{toState:n,fromState:r,opts:i,toDeactivate:a,toActivate:c,intersection:u}=e;if(n.name!==o.UNKNOWN_ROUTE&&!t.hasRoute(n.name)){const e=new de(s.ROUTE_NOT_FOUND,{routeName:n.name});throw t.sendTransitionFail(n,r,e),e}if(r)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,r,i){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:r,intersection:i}};return void 0!==t?.name&&(s.from=t.name),void 0!==e.reload&&(s.reload=e.reload),void 0!==e.redirected&&(s.redirected=e.redirected),s}(r,i,a,c,u);const l=I(n);t.setState(l);const h=void 0===i.signal?i:function({signal:t,...e}){return e}(i);return t.sendTransitionDone(l,r,h),l}function ye(t,e,n,r){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,r,e)}function we(t,e,n){if(t instanceof DOMException&&"AbortError"===t.name)throw new de(s.TRANSITION_CANCELLED);!function(t,e,n){if(t instanceof de)throw t.setCode(e),t;throw new de(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,message:t.message,stack:t.stack,..."cause"in t&&void 0!==t.cause&&{cause:t.cause}};if(t&&"object"==typeof t){const e={};for(const[n,r]of Object.entries(t))be.has(n)||(e[n]=r);return{...n,...e}}return n}(t,n))}(t,e,n)}me.catch(()=>{}),ve.catch(()=>{}),Se.catch(()=>{});var be=new Set(["code","segment","path","redirect"]);async function Ne(t,e,n){let r;try{r=await t}catch(t){return void we(t,e,n)}if(!r)throw new de(e,{segment:n})}async function Ae(t,e,n,r,i,a,o,c,u,l){await Ne(u,n,l);for(let u=c;u<e.length;u++){if(!o())throw new de(s.TRANSITION_CANCELLED);const c=e[u],l=t.get(c);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){we(t,n,c)}if(h instanceof Promise)await Ne(h,n,c);else if(!h)throw new de(n,{segment:c})}}function Oe(t,e,n,r,i,a,o){for(const[c,u]of e.entries()){if(!o())throw new de(s.TRANSITION_CANCELLED);const l=t.get(u);if(!l)continue;let h=!1;try{h=l(r,i,a)}catch(t){we(t,n,u)}if(h instanceof Promise)return Ae(t,e,n,r,i,a,o,c+1,h,u);if(!h)throw new de(n,{segment:u})}}var Ee=[o.UNKNOWN_ROUTE];Object.freeze(Ee);var Pe={replace:!0};Object.freeze(Pe);var Re=class{lastSyncResolved=!1;lastSyncRejected=!1;#d;#V=null;#Q=0;setDependencies(t){this.#d=t}navigate(t,e,n){this.lastSyncResolved=!1;const r=this.#d;if(!r.canNavigate())return this.lastSyncRejected=!0,me;let i,a,c=!1,u=null;try{if(i=r.buildNavigateState(t,e),!i)return r.emitTransitionError(void 0,r.getState(),pe),this.lastSyncRejected=!0,ve;if(a=r.getState(),n=function(t,e){return e?.name!==o.UNKNOWN_ROUTE||t.replace?t:{...t,replace:!0}}(n,a),function(t,e,n){return!!t&&!e.reload&&!e.force&&t.path===n.path}(a,n,i))return r.emitTransitionError(i,a,ge),this.lastSyncRejected=!0,Se;if(this.#K(),n.signal?.aborted)throw new de(s.TRANSITION_CANCELLED,{reason:n.signal.reason});const l=++this.#Q;if(r.startTransition(i,a),c=!0,this.#Q!==l)throw new de(s.TRANSITION_CANCELLED);const[h,d]=r.getLifecycleFunctions(),f=i.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=ae(i,a),v=a&&!n.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(h.size>0||d.size>0){u=new AbortController,this.#V=u;const t=()=>this.#Q===l&&r.isActive(),e=function(t,e,n,r,i,a,o,c,u,l){if(i){const i=Oe(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==i)return async function(t,e,n,r,i,a,o,c){if(await t,!c())throw new de(s.TRANSITION_CANCELLED);if(r){const t=Oe(e,n,s.CANNOT_ACTIVATE,i,a,o,c);if(void 0!==t&&await t,!c())throw new de(s.TRANSITION_CANCELLED)}}(i,e,r,a,o,c,u,l)}if(!l())throw new de(s.TRANSITION_CANCELLED);if(a)return Oe(e,r,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,i,a,u.signal,t);if(void 0!==e)return this.#H(e,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h},u,l);if(!t())throw new de(s.TRANSITION_CANCELLED);this.#J(u)}return this.lastSyncResolved=!0,Promise.resolve(Te(r,{toState:i,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#Y(t,u,c,i,a),Promise.reject(t)}}navigateToDefault(t){const e=this.#d;if(!e.getOptions().defaultRoute)return Promise.reject(new de(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:n,params:r}=e.resolveDefault();return n?this.navigate(n,r,t):Promise.reject(new de(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#K();const e=this.#d.getState(),n=e?ee(e.name).toReversed():[];Object.freeze(n);const r={deactivated:n,activated:Ee,intersection:""};Object.freeze(r);const i={phase:"activating",...e&&{from:e.name},reason:"success",segments:r};Object.freeze(i);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:i};return Object.freeze(s),this.#d.setState(s),this.#d.emitTransitionSuccess(s,e,Pe),s}abortCurrentNavigation(){this.#V?.abort(new de(s.TRANSITION_CANCELLED)),this.#V=null}async#H(t,e,n,r){const i=this.#d,a=()=>this.#Q===r&&!n.signal.aborted&&i.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new de(s.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{n.abort(e.opts.signal?.reason)},{once:!0,signal:n.signal})}if(await t,!a())throw new de(s.TRANSITION_CANCELLED);return Te(i,e)}catch(t){throw ye(i,t,e.toState,e.fromState),t}finally{this.#J(n)}}#Y(t,e,n,r,i){e&&this.#J(e),n&&r&&ye(this.#d,t,r,i)}#J(t){t.abort(),this.#V===t&&(this.#V=null)}#K(){this.#d.isTransitioning()&&(t.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 de(s.TRANSITION_CANCELLED)),this.#d.cancelNavigation())}},Ce={replace:!0};Object.freeze(Ce);var De=class{#d;setDependencies(t){this.#d=t}async start(t){const e=this.#d,n=e.getOptions(),r=e.matchPath(t);if(!r&&!n.allowNotFound){const n=new de(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),r?e.navigate(r.name,r.params,Ce):e.navigateToNotFound(t)}stop(){this.#d.clearState()}},Fe=class{#X;#Z;#tt;#et;#nt;#rt;constructor(t){this.#X=t.routerFSM,this.#Z=t.emitter,this.#tt=void 0,this.#it()}static validateSubscribeListener(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#Z.emit(p.ROUTER_START)}emitRouterStop(){this.#Z.emit(p.ROUTER_STOP)}emitTransitionStart(t,e){this.#Z.emit(p.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,n){this.#Z.emit(p.TRANSITION_SUCCESS,t,e,n)}emitTransitionError(t,e,n){this.#Z.emit(p.TRANSITION_ERROR,t,e,n)}emitTransitionCancel(t,e){this.#Z.emit(p.TRANSITION_CANCEL,t,e)}sendStart(){this.#X.send(b)}sendStop(){this.#X.send(R)}sendDispose(){this.#X.send(C)}sendStarted(){this.#X.send(N)}sendNavigate(t,e){this.#tt=t,this.#X.forceState(y),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#X.forceState(T),this.emitTransitionSuccess(t,e,n),this.#tt===t&&(this.#tt=void 0)}sendFail(t,e,n){const r=this.#tt;this.#et=t,this.#nt=e,this.#rt=n,this.#X.send(E),this.#tt===r&&(this.#tt=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#tt;this.#et=t,this.#nt=e,this.#X.send(P),this.#tt===n&&(this.#tt=void 0)}canBeginTransition(){return this.#X.canSend(A)}canStart(){return this.#X.canSend(b)}canCancel(){return this.#X.canSend(P)}isActive(){const t=this.#X.getState();return t!==v&&t!==w}isDisposed(){return this.#X.getState()===w}isTransitioning(){return this.#X.getState()===y}isReady(){return this.#X.getState()===T}getCurrentToState(){return this.#tt}addEventListener(t,e){return this.#Z.on(t,e)}subscribe(t){return this.#Z.on(p.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#Z.clearAll()}setLimits(t){this.#Z.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#tt,t)}#st(){this.emitTransitionError(this.#et,this.#nt,this.#rt)}#it(){const t=this.#X;t.on(S,N,()=>{this.emitRouterStart()}),t.on(T,R,()=>{this.emitRouterStop()}),t.on(y,P,()=>{const t=this.#et;void 0!==t&&this.emitTransitionCancel(t,this.#nt)}),t.on(S,E,()=>{this.#st()}),t.on(T,E,()=>{this.#st()}),t.on(y,E,()=>{this.#st()})}},je=new de(s.ROUTER_ALREADY_STARTED),Le=new Set(["all","warn-error","error-only"]);var Ie=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(t){this.router=t.router,this.options=t.options,this.limits=t.limits,this.dependenciesStore=t.dependenciesStore,this.state=t.state,this.routes=t.routes,this.routeLifecycle=t.routeLifecycle,this.plugins=t.plugins,this.navigation=t.navigation,this.lifecycle=t.lifecycle,this.eventBus=t.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const t={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(t),this.routeLifecycle.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,r)=>this.state.makeState(t,e,n,r),getState:()=>this.state.get(),areStatesEqual:(t,e,n)=>this.state.areStatesEqual(t,e,n),getDependency:t=>this.dependenciesStore.dependencies[t],forwardState:(t,e)=>{const n=M(this.router);return n.validator?.routes.validateStateBuilderArgs(t,e,"forwardState"),n.forwardState(t,e)}}),this.routes.setLifecycleNamespace(this.routeLifecycle)}wirePluginsDeps(){const t={addEventListener:(t,e)=>this.eventBus.addEventListener(t,e),canNavigate:()=>this.eventBus.canBeginTransition(),compileFactory:this.createCompileFactory()};this.plugins.setDependencies(t),this.plugins.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireNavigationDeps(){this.navigation.setDependencies({getOptions:()=>this.options.get(),hasRoute:t=>this.routes.hasRoute(t),getState:()=>this.state.get(),setState:t=>{this.state.set(t)},buildNavigateState:(t,e)=>{const n=M(this.router);n.validator?.routes.validateStateBuilderArgs(t,e,"navigate");const{name:r,params:i}=n.forwardState(t,e),s=this.routes.getMetaForState(r);if(void 0===s)return;const a=n.buildPath(r,i);return this.state.makeState(r,i,a,s,!0)},resolveDefault:()=>{const t=this.options.get();return{route:k(t.defaultRoute,t=>this.dependenciesStore.dependencies[t]),params:k(t.defaultParams,t=>this.dependenciesStore.dependencies[t])}},startTransition:(t,e)=>{this.eventBus.sendNavigate(t,e)},cancelNavigation:()=>{const t=this.eventBus.getCurrentToState();void 0!==t&&this.eventBus.sendCancel(t,this.state.get())},sendTransitionDone:(t,e,n)=>{this.eventBus.sendComplete(t,e,n)},sendTransitionFail:(t,e,n)=>{this.eventBus.sendFail(t,e,n)},emitTransitionError:(t,e,n)=>{this.eventBus.sendFailSafe(t,e,n)},emitTransitionSuccess:(t,e,n)=>{this.eventBus.emitTransitionSuccess(t,e,n)},canNavigate:()=>this.eventBus.canBeginTransition(),getLifecycleFunctions:()=>this.routeLifecycle.getFunctions(),isActive:()=>this.router.isActive(),isTransitioning:()=>this.eventBus.isTransitioning(),clearCanDeactivate:t=>{this.routeLifecycle.clearCanDeactivate(t)}})}wireLifecycleDeps(){this.lifecycle.setDependencies({getOptions:()=>this.options.get(),navigate:(t,e,n)=>this.navigation.navigate(t,e,n),navigateToNotFound:t=>this.navigation.navigateToNotFound(t),clearState:()=>{this.state.set(void 0)},matchPath:t=>this.routes.matchPath(t,this.options.get()),completeStart:()=>{this.eventBus.sendStarted()},emitTransitionError:(t,e,n)=>{this.eventBus.sendFail(t,e,n)}})}wireStateDeps(){this.state.setDependencies({getDefaultParams:()=>this.routes.getStore().config.defaultParams,buildPath:(t,e)=>M(this.router).buildPath(t,e),getUrlParams:t=>this.routes.getUrlParams(t)})}createCompileFactory(){const{router:t,dependenciesStore:e}=this;return n=>n(t,t=>e.dependencies[t])}},_e=Object.freeze({}),Me=class n{#u;#v;#at;#ot;#ct;#ut;#g;#lt;#ht;#dt;constructor(n=[],r={},s={}){r.logger&&function(t){if("object"!=typeof t||null===t)throw new TypeError("Logger config must be an object");const e=t;for(const t of Object.keys(e))if("level"!==t&&"callback"!==t)throw new TypeError(`Unknown logger config property: "${t}"`);if("level"in e&&void 0!==e.level&&("string"!=typeof(n=e.level)||!Le.has(n)))throw new TypeError(`Invalid logger level: ${function(t){return"string"==typeof t?`"${t}"`:"object"==typeof t?JSON.stringify(t):String(t)}(e.level)}. Expected: "all" | "warn-error" | "error-only"`);var n;if("callback"in e&&void 0!==e.callback&&"function"!=typeof e.callback)throw new TypeError("Logger callback must be a function, got "+typeof e.callback);return!0}(r.logger)&&(t.logger.configure(r.logger),delete r.logger),z.validateOptionsIsObject(r),function(t){if(!t||"object"!=typeof t||t.constructor!==Object)throw new TypeError("dependencies must be a plain object");for(const e in t)if(Object.getOwnPropertyDescriptor(t,e)?.get)throw new TypeError(`dependencies cannot contain getters: "${e}"`)}(s),n.length>0&&F(n),this.#u=new z(r),this.#v=function(t={}){return{...g,...t}}(r.limits),this.#at=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:g}}(s),this.#ot=new V,this.#ct=new ce(n,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#ut=new Y,this.#g=new J,this.#lt=new Re,this.#ht=new De;const a=new e.FSM(D),o=new i({onListenerError:(e,n)=>{t.logger.error("Router",`Error in listener for ${e}:`,n)},onListenerWarn:(e,n)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${n} listeners — possible memory leak`)}});var c;this.#dt=new Fe({routerFSM:a,emitter:o}),(c=new Ie({router:this,options:this.#u,limits:this.#v,dependenciesStore:this.#at,state:this.#ot,routes:this.#ct,routeLifecycle:this.#ut,plugins:this.#g,navigation:this.#lt,lifecycle:this.#ht,eventBus:this.#dt})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const u=new Map;var l,h,d;l={makeState:(t,e,n,r)=>this.#ot.makeState(t,e,n,r),forwardState:$("forwardState",(t,e)=>this.#ct.forwardState(t,e),u),buildStateResolved:(t,e)=>this.#ct.buildStateResolved(t,e),matchPath:(t,e)=>this.#ct.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#dt.addEventListener(t,e),buildPath:$("buildPath",(t,e)=>this.#ct.buildPath(t,e??m,this.#u.get()),u),start:(h=t=>this.#ht.start(t),d=u,(...t)=>{const e=d.get("start");return e&&0!==e.length?U(e,h,t):h(...t)}),interceptors:u,setRootPath:t=>{this.#ct.setRootPath(t)},getRootPath:()=>this.#ct.getStore().rootPath,getTree:()=>this.#ct.getStore().tree,isDisposed:()=>this.#dt.isDisposed(),validator:null,dependenciesGetStore:()=>this.#at,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#at.dependencies}),getLifecycleFactories:()=>this.#ut.getFactories(),getPluginFactories:()=>this.#g.getAll(),routeGetStore:()=>this.#ct.getStore(),getStateName:()=>this.#ot.get()?.name,isTransitioning:()=>this.#dt.isTransitioning(),clearState:()=>{this.#ot.set(void 0)},setState:t=>{this.#ot.set(t)},routerExtensions:[]},_.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,n,r,i){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,r,i),M(this).validator?.routes.validateRouteName(e,"isActiveRoute"),""===e?(t.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ct.isActiveRoute(e,n,r,i)}buildPath(t,e){const n=M(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ot.get()}getPreviousState(){return this.#ot.getPrevious()}areStatesEqual(t,e,n=!0){return M(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ot.areStatesEqual(t,e,n)}shouldUpdateNode(t){return M(this).validator?.routes.validateShouldUpdateNodeArgs(t),ce.shouldUpdateNode(t)}isActive(){return this.#dt.isActive()}start(t){if(!this.#dt.canStart())return Promise.reject(je);M(this).validator?.navigation.validateStartArgs(t),this.#dt.sendStart();const e=M(this).start(t).catch(t=>{throw this.#dt.isReady()&&(this.#ht.stop(),this.#dt.sendStop()),t});return n.#ft(e),e}stop(){return this.#lt.abortCurrentNavigation(),this.#dt.sendCancelIfTransitioning(this.#ot.get()),this.#dt.isReady()||this.#dt.isTransitioning()?(this.#ht.stop(),this.#dt.sendStop(),this):this}dispose(){if(this.#dt.isDisposed())return;this.#lt.abortCurrentNavigation(),this.#dt.sendCancelIfTransitioning(this.#ot.get()),(this.#dt.isReady()||this.#dt.isTransitioning())&&(this.#ht.stop(),this.#dt.sendStop()),this.#dt.sendDispose(),this.#dt.clearAll(),this.#g.disposeAll();const t=M(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ct.clearRoutes(),this.#ut.clearAll(),this.#ot.reset(),this.#at.dependencies=Object.create(null),this.#pt()}canNavigateTo(t,e){const n=M(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ct.hasRoute(t))return!1;const{name:r,params:i}=n.forwardState(t,e??{}),s=this.#ot.makeState(r,i),a=this.#ot.get(),{toDeactivate:o,toActivate:c}=ae(s,a);return this.#ut.canNavigateTo(o,c,s,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=M(this);n.validator?.plugins.validatePluginLimit(this.#g.count(),this.#v);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#g.getAll());return this.#g.use(...e)}subscribe(t){return Fe.validateSubscribeListener(t),this.#dt.subscribe(t)}navigate(t,e,r){const i=M(this);i.validator?.navigation.validateNavigateArgs(t),i.validator?.navigation.validateParams(e,"navigate");const s=r??_e;i.validator?.navigation.validateNavigationOptions(s,"navigate");const a=this.#lt.navigate(t,e??m,s);return this.#lt.lastSyncResolved?this.#lt.lastSyncResolved=!1:this.#lt.lastSyncRejected?this.#lt.lastSyncRejected=!1:n.#ft(a),a}navigateToDefault(t){const e=M(this);e.validator?.navigation.validateNavigateToDefaultArgs(t);const r=t??_e;e.validator?.navigation.validateNavigationOptions(r,"navigateToDefault");const i=this.#lt.navigateToDefault(r);return this.#lt.lastSyncResolved?this.#lt.lastSyncResolved=!1:this.#lt.lastSyncRejected?this.#lt.lastSyncRejected=!1:n.#ft(i),i}navigateToNotFound(t){if(!this.#dt.isActive())throw new de(s.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ot.get().path;return this.#lt.navigateToNotFound(e)}static#gt=e=>{e instanceof de&&(e.code===s.SAME_STATES||e.code===s.TRANSITION_CANCELLED||e.code===s.ROUTER_NOT_STARTED||e.code===s.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#ft(t){t.catch(n.#gt)}#pt(){this.navigate=Ue,this.navigateToDefault=Ue,this.navigateToNotFound=Ue,this.start=Ue,this.stop=Ue,this.usePlugin=Ue,this.subscribe=Ue,this.canNavigateTo=Ue}};function Ue(){throw new de(s.ROUTER_DISPOSED)}var $e=new WeakMap;exports.Router=Me,exports.RouterError=de,exports.UNKNOWN_ROUTE=a,exports.constants=o,exports.createRouter=(t=[],e={},n={})=>new Me(t,e,n),exports.errorCodes=s,exports.events=p,exports.getNavigator=t=>{let e=$e.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),$e.set(t,e)),e},exports.resolveForwardChain=$t;//# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./Router-NL2_9FQk.js`),t=require(`./RouterError-BkgjTHQg.js`),n=(t=[],n={},r={})=>new e.t(t,n,r),r=new WeakMap,i=e=>{let t=r.get(e);return t||(t=Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe}),r.set(e,t)),t};exports.Router=e.t,exports.RouterError=t.t,exports.UNKNOWN_ROUTE=t.o,exports.constants=t.s,exports.createRouter=n,exports.errorCodes=t.c,exports.events=t.l,exports.getNavigator=i,exports.resolveForwardChain=e.a;
2
+ //# sourceMappingURL=index.js.map