@real-router/core 0.40.1 → 0.42.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 (77) hide show
  1. package/dist/cjs/Router-B2tmtNiM.d.ts +353 -0
  2. package/dist/cjs/Router-CVNR-dug.js +6 -0
  3. package/dist/cjs/Router-CVNR-dug.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-4JRfQLMM.d.mts +353 -0
  23. package/dist/esm/Router-C_k70gHi.mjs +6 -0
  24. package/dist/esm/Router-C_k70gHi.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/{cjs/validation.js.map → esm/internals-CCymabFj.mjs.map} +1 -1
  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/Router.ts +4 -6
  45. package/src/api/getPluginApi.ts +2 -3
  46. package/src/helpers.ts +9 -7
  47. package/src/index.ts +0 -1
  48. package/src/internals.ts +4 -5
  49. package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -1
  50. package/src/namespaces/OptionsNamespace/constants.ts +1 -0
  51. package/src/namespaces/OptionsNamespace/helpers.ts +0 -1
  52. package/src/namespaces/RouterLifecycleNamespace/types.ts +1 -3
  53. package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -3
  54. package/src/namespaces/RoutesNamespace/types.ts +2 -2
  55. package/src/namespaces/StateNamespace/StateNamespace.ts +30 -34
  56. package/src/namespaces/StateNamespace/helpers.ts +8 -27
  57. package/src/stateMetaStore.ts +15 -0
  58. package/src/transitionPath.ts +13 -16
  59. package/src/types/RouterValidator.ts +0 -1
  60. package/src/wiring/RouterWiringBuilder.ts +1 -1
  61. package/dist/cjs/Router-B-Pev7K2.d.ts +0 -46
  62. package/dist/cjs/RouterValidator-mx2Zooya.d.ts +0 -136
  63. package/dist/cjs/index.d-y2b-8_3Y.d.ts +0 -236
  64. package/dist/cjs/metafile-cjs.json +0 -1
  65. package/dist/esm/Router-B-Pev7K2.d.mts +0 -46
  66. package/dist/esm/RouterValidator-mx2Zooya.d.mts +0 -136
  67. package/dist/esm/chunk-5QXFUUDL.mjs +0 -1
  68. package/dist/esm/chunk-5QXFUUDL.mjs.map +0 -1
  69. package/dist/esm/chunk-HHIXK5UM.mjs +0 -1
  70. package/dist/esm/chunk-HHIXK5UM.mjs.map +0 -1
  71. package/dist/esm/chunk-MNRZAE7T.mjs +0 -1
  72. package/dist/esm/chunk-MNRZAE7T.mjs.map +0 -1
  73. package/dist/esm/chunk-QUUNDESP.mjs +0 -1
  74. package/dist/esm/chunk-QUUNDESP.mjs.map +0 -1
  75. package/dist/esm/index.d-y2b-8_3Y.d.mts +0 -236
  76. package/dist/esm/metafile-esm.json +0 -1
  77. 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-mx2Zooya.js';
2
- import { R as Router } from './Router-B-Pev7K2.js';
3
- import { ErrorCodeKeys, ErrorCodeValues, ErrorCodeToValueMap, EventToNameMap, State, DefaultDependencies, Route, Options, Router as Router$1, Navigator } from '@real-router/types';
4
- export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
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-B2tmtNiM.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},i=class extends Error{},r=class{#t=new Map;#e=null;#n=n;#i;#r;constructor(t){t?.limits&&(this.#n=t.limits),this.#i=t?.onListenerError??null,this.#r=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:i,warnListeners:r}=this.#n;if(0!==r&&n.size===r&&this.#r?.(t,r),0!==i&&n.size>=i)throw new Error(`Listener limit (${i}) reached for "${t}"`);return n.add(e),()=>{this.off(t,e)}}off(t,e){this.#t.get(t)?.delete(e)}emit(t,e,n,i,r){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,i,r):this.#o(s,t,a,e,n,i,r)}clearAll(){this.#t.clear(),this.#e=null}listenerCount(t){return this.#t.get(t)?.size??0}#o(t,e,n,i,r,s,a){if(1===t.size){const[o]=t;try{this.#c(o,n,i,r,s,a)}catch(t){this.#i?.(e,t)}return}const o=[...t];for(const t of o)try{this.#c(t,n,i,r,s,a)}catch(t){this.#i?.(e,t)}}#c(t,e,n,i,r,s){switch(e){case 0:t();break;case 1:t(n);break;case 2:t(n,i);break;case 3:t(n,i,r);break;default:t(n,i,r,s)}}#a(t,e,n,r,s,a,o){this.#e??=new Map;const c=this.#e,u=c.get(e)??0;if(u>=this.#n.maxEventDepth)throw new i(`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,r,s,a,o)}catch(t){if(t instanceof i)throw t;this.#i?.(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 i=e;for(const e of t){const t=i;i=(...n)=>e(t,...n)}return i(...n)}function $(t,e,n){return(i,r)=>{const s=n.get(t);return s&&0!==s.length?U(s,e,[i,r]):e(i,r)}}var B={defaultRoute:"",defaultParams:{},trailingSlash:"preserve",queryParamsMode:"loose",queryParams:{arrayFormat:"none",booleanFormat:"none",nullFormat:"default"},urlParamsEncoding:"default",allowNotFound:!0,rewritePathOnMatch:!0};function x(t){Object.freeze(t);for(const e of Object.keys(t)){const n=t[e];n&&"object"==typeof n&&n.constructor===Object&&x(n)}return t}function k(t,e){return"function"==typeof t?t(e):t}var z=class{#u;constructor(t={}){this.#u=x({...B,...t})}static validateOptionsIsObject(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.constructor] options must be a plain object")}(t)}get(){return this.#u}};function q(t,e){return t===e||!(!Array.isArray(t)||!Array.isArray(e))&&t.length===e.length&&t.every((t,n)=>q(t,e[n]))}var G=class{#l=0;#h=void 0;#d=void 0;#f;#p=new Map;get(){return this.#h}set(t){this.#d=this.#h,this.#h=t?I(t):void 0}getPrevious(){return this.#d}reset(){this.#h=void 0,this.#d=void 0,this.#p.clear(),this.#l=0}setDependencies(t){this.#f=t}makeState(t,e,n,i,r,s){const a=i?{id:r??++this.#l,params:i}:void 0,o=this.#f.getDefaultParams();let c;c=Object.hasOwn(o,t)?{...o[t],...e}:e&&e!==m?{...e}:m;const u={name:t,params:c,path:n??this.#f.buildPath(t,e),meta:a};return s?u:I(u)}areStatesEqual(t,e,n=!0){if(!t||!e)return!!t==!!e;if(t.name!==e.name)return!1;if(n){const n=t.meta?.params??e.meta?.params;return(n?function(t){const e=[];for(const n in t){const i=t[n];for(const t in i)"url"===i[t]&&e.push(t)}return e}(n):this.#g(t.name)).every(n=>q(t.params[n],e.params[n]))}const i=Object.keys(t.params),r=Object.keys(e.params);return i.length===r.length&&i.every(n=>n in e.params&&q(t.params[n],e.params[n]))}#g(t){const e=this.#p.get(t);if(void 0!==e)return e;const n=this.#f.getUrlParams(t);return this.#p.set(t,n),n}},W={[c]:p.ROUTER_START,[u]:p.ROUTER_STOP,[d]:p.TRANSITION_SUCCESS,[l]:p.TRANSITION_START,[f]:p.TRANSITION_ERROR,[h]:p.TRANSITION_CANCEL},V=Object.keys(W),Q="router.usePlugin",K=class e{#m=new Set;#v=new Set;#f;#S=g;#T=null;static validatePlugin(t){!function(t){if(!t||"object"!=typeof t||Array.isArray(t))throw new TypeError("[router.usePlugin] Plugin factory must return an object, got "+typeof t);if("function"==typeof t.then)throw new TypeError("[router.usePlugin] Async plugin factories are not supported. Factory returned a Promise instead of a plugin object.")}(t)}static validateNoDuplicatePlugins(t,e){for(const n of t)if(e(n))throw new Error("[router.usePlugin] Plugin factory already registered. To re-register, first unsubscribe the existing plugin.")}setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#T=t}count(){return this.#m.size}use(...e){if(this.#T?.()?.plugins.validateCountThresholds(this.#m.size+e.length),1===e.length){const n=e[0],i=this.#y(n);this.#m.add(n);let r=!1;const s=()=>{if(!r){r=!0,this.#m.delete(n),this.#v.delete(s);try{i()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}const n=this.#w(e),i=[];try{for(const t of n){const e=this.#y(t);i.push({factory:t,cleanup:e})}}catch(e){for(const{cleanup:e}of i)try{e()}catch(e){t.logger.error(Q,"Cleanup error:",e)}throw e}for(const{factory:t}of i)this.#m.add(t);let r=!1;const s=()=>{if(!r){r=!0,this.#v.delete(s);for(const{factory:t}of i)this.#m.delete(t);for(const{cleanup:e}of i)try{e()}catch(e){t.logger.error(Q,"Error during cleanup:",e)}}};return this.#v.add(s),s}getAll(){return[...this.#m]}has(t){return this.#m.has(t)}disposeAll(){for(const t of this.#v)t();this.#m.clear(),this.#v.clear()}#w(t){const e=new Set;for(const n of t)e.has(n)?this.#T?.()?.plugins.warnBatchDuplicates(t):e.add(n);return e}#y(t){const n=this.#f.compileFactory(t);e.validatePlugin(n),this.#T?.()?.plugins.validatePluginKeys(n),Object.freeze(n);const i=[];for(const t of V)t in n&&("function"==typeof n[t]?(i.push(this.#f.addEventListener(W[t],n[t])),"onStart"===t&&this.#f.canNavigate()&&this.#T?.()?.plugins.warnPluginAfterStart(t)):this.#T?.()?.plugins.warnPluginMethodType(t));return()=>{for(const t of i)t();"function"==typeof n.teardown&&n.teardown()}}},H=class{#b=new Map;#N=new Map;#A=new Map;#O=new Map;#E=[this.#A,this.#O];#P=new Set;#R=new Set;#C=new Set;#f;#S=g;#T=null;setDependencies(t){this.#f=t}setLimits(t){this.#S=t,this.#S}setValidatorGetter(t){this.#T=t}getHandlerCount(t){return"activate"===t?this.#N.size:this.#b.size}addCanActivate(t,e,n=!1){n?this.#R.add(t):this.#R.delete(t);const i=this.#N.has(t);this.#D("activate",t,e,this.#N,this.#O,"canActivate",i)}addCanDeactivate(t,e,n=!1){n?this.#C.add(t):this.#C.delete(t);const i=this.#b.has(t);this.#D("deactivate",t,e,this.#b,this.#A,"canDeactivate",i)}clearCanActivate(t){this.#N.delete(t),this.#O.delete(t),this.#R.delete(t)}clearCanDeactivate(t){this.#b.delete(t),this.#A.delete(t),this.#C.delete(t)}clearAll(){this.#N.clear(),this.#O.clear(),this.#b.clear(),this.#A.clear(),this.#R.clear(),this.#C.clear()}clearDefinitionGuards(){for(const t of this.#R)this.#N.delete(t),this.#O.delete(t);for(const t of this.#C)this.#b.delete(t),this.#A.delete(t);this.#R.clear(),this.#C.clear()}getFactories(){const t={},e={};for(const[e,n]of this.#b)t[e]=n;for(const[t,n]of this.#N)e[t]=n;return[t,e]}getFunctions(){return this.#E}canNavigateTo(t,e,n,i){for(const e of t)if(!this.#F(this.#A,e,n,i,"canNavigateTo"))return!1;for(const t of e)if(!this.#F(this.#O,t,n,i,"canNavigateTo"))return!1;return!0}#D(t,e,n,i,r,s,a){a?this.#T?.()?.lifecycle.warnOverwrite(e,t,s):this.#T?.()?.lifecycle.validateCountThresholds(i.size+1,s);const o="boolean"==typeof n?function(t){const e=()=>t;return()=>e}(n):n;i.set(e,o),this.#P.add(e);try{const t=this.#f.compileFactory(o);if("function"!=typeof t)throw new TypeError(`[router.${s}] Factory must return a function, got ${typeof t}`);r.set(e,t)}catch(t){throw i.delete(e),t}finally{this.#P.delete(e)}}#F(t,e,n,i,r){const s=t.get(e);if(!s)return!0;try{const t=s(n,i);return"boolean"==typeof t?t:(this.#T?.()?.lifecycle.warnAsyncGuardSync(e,r),!1)}catch{return!1}}};function J(){return{decoders:Object.create(null),encoders:Object.create(null),defaultParams:Object.create(null),forwardMap:Object.create(null),forwardFnMap:Object.create(null)}}function Y(t){const e={name:t.name,path:t.path};return t.children&&(e.children=t.children.map(t=>Y(t))),e}function X(t){return`(${t.replaceAll(/(^<|>$)/g,"")})`}var Z=/([:*])([^/?<]+)(<[^>]+>)?(\?)?/g,tt=/([:*][^/?<]+(?:<[^>]+>)?)\?(?=\/|$)/g,et=/\?(.+)$/,nt=/[^\w!$'()*+,.:;|~-]/gu,it=/[^\w!$'()*+,.:;|~-]/u,rt={default:t=>it.test(t)?t.replaceAll(nt,t=>encodeURIComponent(t)):t,uri:encodeURI,uriComponent:encodeURIComponent,none:t=>t},st={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:t=>t};function at(){return{staticChildren:Object.create(null),paramChild:void 0,splatChild:void 0,route:void 0,slashChildRoute:void 0}}function ot(t){return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function ct(t){const e={};if(0===t.length)return e;const n=t.split("&");for(const t of n){const n=t.indexOf("=");-1===n?e[t]="":e[t.slice(0,n)]=t.slice(n+1)}return e}function ut(t){const e=[];for(const n of Object.keys(t)){const i=t[n],r=encodeURIComponent(n);e.push(""===i?r:`${r}=${encodeURIComponent(String(i))}`)}return e.join("&")}function lt(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ht(t){let e=0;for(;e<t.length;)if("%"===t[e]){if(e+2>=t.length)return!1;const n=t.codePointAt(e+1)??0,i=t.codePointAt(e+2)??0;if(!lt(n)||!lt(i))return!1;e+=3}else e++;return!0}var dt=/<[^>]*>/g;function ft(t,e,n,i,r){const s=""===e.fullName;s||i.push(e);const a=e.absolute,o=e.paramMeta.pathPattern,c=a&&o.startsWith("~")?o.slice(1):o,u=(a?c:o).replaceAll(dt,""),l=a?u:(d=u,""===(h=n)?d:""===d?h:h+d);var h,d;let f=r;s||(f=function(t,e,n,i,r,s){const a=(m=i,ot(n)===ot(m)),o=Object.freeze([...r]),c=function(t){const e={};for(const n of t)e[n.fullName]=n.paramTypeMap;return Object.freeze(e)}(o),u=ot(n),l=function(t,e){const n=[];t.length>0&&n.push(...t);for(const t of e)t.paramMeta.queryParams.length>0&&n.push(...t.paramMeta.queryParams);return n}(t.rootQueryParams,r),h=function(t){const e=new Map;for(const n of t)for(const[t,i]of n.paramMeta.constraintPatterns)e.set(t,i);return e}(r),d=a?ot(i):u,{buildStaticParts:f,buildParamSlots:p}=function(t,e,n){const i=new Set,r=new Set;for(const t of e){for(const e of t.paramMeta.urlParams)i.add(e);for(const e of t.paramMeta.spatParams)r.add(e)}if(0===i.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],i="?"===c[2];s.push(t.slice(u,c.index));const o=r.has(e);a.push({paramName:e,isOptional:i,encoder:o?t=>{const e=rt[n],i=t.split("/");let r=e(i[0]);for(let t=1;t<i.length;t++)r+=`/${e(i[t])}`;return r}:rt[n]}),u=c.index+c[0].length}return s.push(t.slice(u)),{buildStaticParts:s,buildParamSlots:a}}(d,a?r.slice(0,-1):r,t.options.urlParamsEncoding),g={name:e.fullName,parent:s,depth:r.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 i,r;i=e,(function(t,e,n){const i=ot(n);if("/"===i||""===i)return e;let r=e,s=1;const a=i.length;for(;s<=a;){const e=i.indexOf("/",s),n=-1===e?a:e;if(n<=s)break;r=gt(t,r,i.slice(s,n)),s=n+1}return r}(r=t,r.root,n)).slashChildRoute=i;const s=ot(n),a=t.options.caseSensitive?s:s.toLowerCase();t.staticCache.has(a)&&t.staticCache.set(a,e)}(t,g,i):function(t,e,n,i,r){if(function(t,e,n){const i=ot(n);"/"!==i?pt(t,t.root,i,1,e):t.root.route=e}(t,e,n),0===r.paramMeta.urlParams.length){const n=t.options.caseSensitive?i:i.toLowerCase();t.staticCache.set(n,e)}}(t,g,n,u,e),g}(t,e,l,a?"":n,i,r));for(const n of e.children.values())ft(t,n,l,i,f);s||i.pop()}function pt(t,e,n,i,r){const s=n.length;for(;i<=s;){const a=n.indexOf("/",i),o=-1===a?s:a,c=n.slice(i,o);if(c.endsWith("?")){const i=c.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:i},pt(t,e.paramChild.node,n,o+1,r),void(o>=s?e.route??=r:pt(t,e,n,o+1,r))}e=gt(t,e,c),i=o+1}e.route=r}function gt(t,e,n){if(n.startsWith("*")){const t=n.slice(1);return e.splatChild??={node:at(),name:t},e.splatChild.node}if(n.startsWith(":")){const t=n.slice(1).replaceAll(dt,"").replace(/\?$/,"");return e.paramChild??={node:at(),name:t},e.paramChild.node}const i=t.options.caseSensitive?n:n.toLowerCase();return i in e.staticChildren||(e.staticChildren[i]=at()),e.staticChildren[i]}var mt=/[\u0080-\uFFFF]/,vt=class{get options(){return this.#t}#t;#e=at();#r=new Map;#s=new Map;#n=new Map;#a=new Map;#i="";#j=[];constructor(t){this.#t={caseSensitive:t?.caseSensitive??!0,strictTrailingSlash:t?.strictTrailingSlash??!1,strictQueryParams:t?.strictQueryParams??!1,urlParamsEncoding:t?.urlParamsEncoding??"default",parseQueryString:t?.parseQueryString??ct,buildQueryString:t?.buildQueryString??ut}}registerTree(t){this.#j=t.paramMeta.queryParams,ft({root:this.#e,options:this.#t,routesByName:this.#r,segmentsByName:this.#s,metaByName:this.#n,staticCache:this.#a,rootQueryParams:this.#j},t,"",[],null)}match(t){const e=this.#c(t);if(!e)return;const[n,i,r]=e,s=this.#t.caseSensitive?i:i.toLowerCase(),a=this.#a.get(s);if(a){if(this.#t.strictTrailingSlash&&!this.#o(n,a))return;return this.#L(a,{},r)}const o={},c=this.#I(i,o);return!c||this.#t.strictTrailingSlash&&!this.#o(n,c)||c.hasConstraints&&!this.#_(o,c)||!this.#M(o)?void 0:this.#L(c,o,r)}buildPath(t,e,n){const i=this.#r.get(t);if(!i)throw new Error(`[SegmentMatcher.buildPath] '${t}' is not defined`);i.hasConstraints&&e&&this.#U(i,t,e);const r=this.#$(i,e),s=this.#B(r,n?.trailingSlash),a=this.#x(i,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.#r.has(t)}setRootPath(t){this.#i=t}#U(t,e,n){for(const[i,r]of t.constraintPatterns){const t=n[i];if(null!=t){const n="object"==typeof t?JSON.stringify(t):String(t);if(!r.pattern.test(n))throw new Error(`[SegmentMatcher.buildPath] '${e}' — param '${i}' value '${n}' does not match constraint '${r.constraint}'`)}}}#$(t,e){const n=t.buildStaticParts,i=t.buildParamSlots;if(0===i.length)return this.#i+n[0];let r=this.#i+n[0];for(const[t,s]of i.entries()){const i=e?.[s.paramName];if(null==i){if(!s.isOptional)throw new Error(`[SegmentMatcher.buildPath] Missing required param '${s.paramName}'`);r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r+=n[t+1];continue}const a="object"==typeof i?JSON.stringify(i):String(i);r+=s.encoder(a)+n[t+1]}return r}#B(t,e){return"always"!==e||t.endsWith("/")?"never"===e&&"/"!==t&&t.endsWith("/")?t.slice(0,-1):t:`${t}/`}#x(t,e,n){if(!e)return"";const i={};let r=!1;for(const n of t.declaredQueryParams)n in e&&(i[n]=e[n],r=!0);if("loose"===n)for(const n in e)!Object.hasOwn(e,n)||t.declaredQueryParamsSet.has(n)||t.buildParamNamesSet.has(n)||(i[n]=e[n],r=!0);return r?this.#t.buildQueryString(i):""}#c(t){if(""===t&&(t="/"),!t.startsWith("/"))return;const e=t.indexOf("#");if(-1!==e&&(t=t.slice(0,e)),mt.test(t))return;if(this.#i.length>0){if(!t.startsWith(this.#i))return;t=t.slice(this.#i.length)||"/"}const n=t.indexOf("?"),i=-1===n?t:t.slice(0,n),r=-1===n?void 0:t.slice(n+1);return i.includes("//")?void 0:[i,ot(i),r]}#L(t,e,n){if(void 0!==n){const i=this.#t.parseQueryString(n);if(this.#t.strictQueryParams){const e=t.declaredQueryParamsSet;for(const t of Object.keys(i))if(!e.has(t))return}for(const t of Object.keys(i))e[t]=i[t]}return{segments:t.matchSegments,params:e,meta:t.meta}}#o(t,e){return(t.length>1&&t.endsWith("/"))===e.hasTrailingSlash}#I(t,e){return 1===t.length?this.#e.slashChildRoute??this.#e.route:this.#k(this.#e,t,1,e)}#k(t,e,n,i){let r=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 r.staticChildren)u=r.staticChildren[c];else{if(!r.paramChild){if(r.splatChild){const t={},s=this.#k(r.splatChild.node,e,n,t);return s?(Object.assign(i,t),s):(i[r.splatChild.name]=e.slice(n),r.splatChild.node.route)}return}u=r.paramChild.node,i[r.paramChild.name]=o}r=u,n=a+1}return r.slashChildRoute??r.route}#M(t){const e=this.#t.urlParamsEncoding;if("none"===e)return!0;const n=st[e];for(const e in t){const i=t[e];if(i.includes("%")){if(!ht(i))return!1;t[e]=n(i)}}return!0}#_(t,e){for(const[n,i]of e.constraintPatterns)if(!i.pattern.test(t[n]))return!1;return!0}},St=t=>{const e=t.indexOf("%"),n=t.indexOf("+");if(-1===e&&-1===n)return t;const i=-1===n?t:t.split("+").join(" ");return-1===e?i:decodeURIComponent(i)},Tt=t=>{const e=typeof t;if("string"!==e&&"number"!==e&&"boolean"!==e)throw new TypeError(`[search-params] Array element must be a string, number, or boolean — received ${"object"===e&&null===t?"null":e}`);return encodeURIComponent(t)},yt={none:{encodeArray:(t,e)=>e.map(e=>`${t}=${Tt(e)}`).join("&")},brackets:{encodeArray:(t,e)=>e.map(e=>`${t}[]=${Tt(e)}`).join("&")},index:{encodeArray:(t,e)=>e.map((e,n)=>`${t}[${n}]=${Tt(e)}`).join("&")},comma:{encodeArray:(t,e)=>`${t}=${e.map(t=>Tt(t)).join(",")}`}},wt={none:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:t=>t},string:{encode:(t,e)=>`${t}=${e}`,decodeUndefined:()=>null,decodeRaw:t=>"true"===t||"false"!==t&&null,decodeValue:t=>t},"empty-true":{encode:(t,e)=>e?t:`${t}=false`,decodeUndefined:()=>!0,decodeRaw:()=>null,decodeValue:t=>t}},bt={default:{encode:t=>t},hidden:{encode:()=>""}},Nt=(t,e,n)=>({boolean:wt[e],null:bt[n],array:yt[t]}),At={arrayFormat:"none",booleanFormat:"none",nullFormat:"default",strategies:{boolean:wt.none,null:bt.default,array:yt.none}},Ot=t=>{if(!t||void 0===t.arrayFormat&&void 0===t.booleanFormat&&void 0===t.nullFormat)return At;const e=t.arrayFormat??"none",n=t.booleanFormat??"none",i=t.nullFormat??"default";return{arrayFormat:e,booleanFormat:n,nullFormat:i,strategies:Nt(e,n,i)}},Et=t=>encodeURIComponent(t),Pt=(t,e,n)=>{const i=Et(t);switch(typeof e){case"string":case"number":default:return`${i}=${Et(e)}`;case"boolean":return n.strategies.boolean.encode(i,e);case"object":return null===e?n.strategies.null.encode(i):Array.isArray(e)?n.strategies.array.encodeArray(i,e):`${i}=${Et(e)}`}};function Rt(t,e,n,i,r){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,i){const r=t[e];void 0===r?t[e]=i?[n]:n:Array.isArray(r)?r.push(n):t[e]=[r,n]}(i,St(c),(l=t,h=s,d=n,f=a,p=r,p?((t,e)=>{if(void 0===t)return e.boolean.decodeUndefined();const n=e.boolean.decodeRaw(t);if(null!==n)return n;const i=St(t);return e.boolean.decodeValue(i)})(f?l.slice(h+1,d):void 0,p):f?St(l.slice(h+1,d)):null),u)}function Ct(t,e){const n=t.path,i=n.startsWith("~"),r=i?n.slice(1):n,s={name:t.name,path:r,absolute:i,children:[],parent:e,nonAbsoluteChildren:[],fullName:""};if(t.children)for(const e of t.children){const t=Ct(e,s);s.children.push(t)}return s}function Dt(t,e){return t.endsWith("/")&&e.startsWith("/")?t+e.slice(1):t+e}function Ft(t){const e=new Map;for(const n of t)e.set(n.name,n);return e}function jt(t,e,n){const i=function(t){const e=[],n=[],i=[],r={},s=new Map,a=t.replaceAll(tt,"$1"),o=et.exec(a);if(null!==o){const e=o[1].split("&");for(const t of e){const e=t.trim();e.length>0&&(n.push(e),r[e]="query")}t=t.slice(0,o.index)}let c;for(;null!==(c=Z.exec(t));){const t=c[2],n=c[3];if("*"===c[1])i.push(t),e.push(t),r[t]="url";else if(e.push(t),r[t]="url",n){const e=`^${X(n)}$`;s.set(t,{pattern:new RegExp(e),constraint:n})}}return{urlParams:e,queryParams:n,spatParams:i,paramTypeMap:r,constraintPatterns:s,pathPattern:t}}(t.path),r=function(t){const e={};for(const n of t.urlParams)e[n]="url";for(const n of t.queryParams)e[n]="query";return e}(i),s={name:t.name,path:t.path,absolute:t.absolute,parent:e,children:void 0,paramMeta:i,nonAbsoluteChildren:void 0,fullName:"",staticPath:null,paramTypeMap:r};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 i=[],r=[];for(const s of t){const t=jt(s,e,n);i.push(t),t.absolute||r.push(t)}return{childrenMap:Ft(i),nonAbsoluteChildren:r}}(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:i}=t.paramMeta;if(e.length>0||n.length>0||i.length>0)return null;const r=[];let s=t.parent;for(;s?.path;)r.unshift(s),s=s.parent;let a="";for(const t of r){const{urlParams:e,queryParams:n,spatParams:i}=t.paramMeta;if(e.length>0||n.length>0||i.length>0)return null;a=t.absolute?t.path:Dt(a,t.path)}return t.absolute?t.path:Dt(a,t.path)}(s),n&&(Object.freeze(c),Object.freeze(r),Object.freeze(s.children),Object.freeze(s)),s}function Lt(t,e,n,i){return function(t,e){const n=[];return{add(t){return n.push(t),this},addMany(t){return n.push(...t),this},build:i=>function(t,e=!0){return jt(t,null,e)}(function(t,e,n){const i=Ct({name:t,path:e},null);for(const t of n){const e=Ct(t,i);i.children.push(e)}return i}(t,e,n),!i?.skipFreeze)}}(t,e).addMany(n).build(i)}function It(t){const e={name:t.name,path:t.absolute?`~${t.path}`:t.path};return t.children.size>0&&(e.children=[...t.children.values()].map(t=>It(t))),e}function _t(t){const e=t?.queryParams;return new vt({...void 0===t?.caseSensitive?void 0:{caseSensitive:t.caseSensitive},...void 0===t?.strictTrailingSlash?void 0:{strictTrailingSlash:t.strictTrailingSlash},...void 0===t?.strictQueryParams?void 0:{strictQueryParams:t.strictQueryParams},...void 0===t?.urlParamsEncoding?void 0:{urlParamsEncoding:t.urlParamsEncoding},parseQueryString:t=>((t,e)=>{const n=(t=>{const e=t.indexOf("?");return-1===e?t:t.slice(e+1)})(t);if(""===n||"?"===n)return{};if(!e)return function(t){const e={};return function(t,e){let n=0;const i=t.length;for(;n<i;){let r=t.indexOf("&",n);-1===r&&(r=i),Rt(t,n,r,e),n=r+1}}(t,e),e}(n);const i=Ot(e),r={};let s=0;const a=n.length;for(;s<a;){let t=n.indexOf("&",s);-1===t&&(t=a),Rt(n,s,t,r,i.strategies),s=t+1}return r})(t,e),buildQueryString:t=>((t,e)=>{const n=Object.keys(t);if(0===n.length)return"";const i=Ot(e),r=[];for(const e of n){const n=t[e];if(void 0===n)continue;const s=Pt(e,n,i);s&&r.push(s)}return r.join("&")})(t,e)})}function Mt(t,e,n=100){const i=new Set,r=[t];let s=t;for(;e[s];){const t=e[s];if(i.has(t)){const e=r.indexOf(t),n=[...r.slice(e),t];throw new Error(`Circular forwardTo: ${n.join(" → ")}`)}if(i.add(s),r.push(t),s=t,r.length>n)throw new Error(`forwardTo chain exceeds maximum depth (${n}): ${r.join(" → ")}`)}return s}function Ut(t,e,n){const i=Lt("",e,t),r=_t(n);return r.registerTree(i),{tree:i,matcher:r}}function $t(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher,t.resolvedForwardMap=kt(t.config)}function Bt(t){const e=Ut(t.definitions,t.rootPath,t.matcherOptions);t.tree=e.tree,t.matcher=e.matcher}function xt(t){!function(t){t.definitions.length=0,Object.assign(t.config,J()),t.resolvedForwardMap=Object.create(null),t.routeCustomFields=Object.create(null)}(t),Bt(t)}function kt(t){const e=Object.create(null);for(const n of Object.keys(t.forwardMap))e[n]=Mt(n,t.forwardMap);return e}function zt(e,n,i,r,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&&(r[n]=u),e.canActivate&&s.set(n,e.canActivate),e.canDeactivate&&a.set(n,e.canDeactivate),e.forwardTo&&function(e,n,i){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,i=e.forwardTo.toString().includes("__awaiter");if(t||i)throw new TypeError(`forwardTo callback cannot be async for route "${n}". Async functions break matchPath/buildPath.`)}"string"==typeof e.forwardTo?i.forwardMap[n]=e.forwardTo:i.forwardFnMap[n]=e.forwardTo}(e,n,i),e.decodeParams&&(i.decoders[n]=t=>e.decodeParams?.(t)??t),e.encodeParams&&(i.encoders[n]=t=>e.encodeParams?.(t)??t),e.defaultParams&&(i.defaultParams[n]=e.defaultParams)}function qt(t,e,n,i,r,s,a=""){for(const o of t){const t=a?`${a}.${o.name}`:o.name;zt(o,t,e,n,i,r),o.children&&qt(o.children,e,n,i,r,s,t)}}function Gt(t,e){const n=[],i=J(),r=Object.create(null),s=new Map,a=new Map;for(const e of t)n.push(Y(e));const{tree:o,matcher:c}=Ut(n,"",e);return qt(t,i,r,s,a,void 0,""),{definitions:n,config:i,tree:o,matcher:c,resolvedForwardMap:kt(i),routeCustomFields:r,rootPath:"",matcherOptions:e,depsStore:void 0,lifecycleNamespace:void 0,pendingCanActivate:s,pendingCanDeactivate:a,treeOperations:{commitTreeChanges:$t,resetStore:xt,nodeToDefinition:It}}}var Wt=".",Vt=[];function Qt(t){const e=[];for(let n=t.length-1;n>=0;n--)e.push(t[n]);return e}function Kt(t){const e=typeof t;return"string"===e||"number"===e||"boolean"===e}function Ht(t,e,n){const i=e.meta?.params[t];if(!i||"object"!=typeof i)return!0;for(const t of Object.keys(i)){const i=e.params[t],r=n.params[t];if(Kt(i)&&Kt(r)&&String(i)!==String(r))return!1}return!0}Object.freeze(Vt);var Jt,Yt,Xt=new Map;function Zt(t){const e=Xt.get(t);if(e)return e;const n=function(t){if(!t)return[""];const e=t.indexOf(Wt);if(-1===e)return[t];const n=t.indexOf(Wt,e+1);if(-1===n)return[t.slice(0,e),t];const i=t.indexOf(Wt,n+1);if(-1===i)return[t.slice(0,e),t.slice(0,n),t];return-1===t.indexOf(Wt,i+1)?[t.slice(0,e),t.slice(0,n),t.slice(0,i),t]:function(t){const e=t.split(Wt),n=e.length,i=[e[0]];let r=e[0].length;for(let s=1;s<n-1;s++)r+=1+e[s].length,i.push(t.slice(0,r));return i.push(t),i}(t)}(t);return Object.freeze(n),Xt.set(t,n),n}var te,ee,ne=null,ie=null;function re(t,e){if(!e)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Vt};if(void 0===t.meta?.params&&void 0===e.meta?.params)return{intersection:"",toActivate:Zt(t.name),toDeactivate:Qt(Zt(e.name))};const n=Zt(t.name),i=Zt(e.name),r=function(t,e,n,i,r){for(let s=0;s<r;s++){const r=n[s];if(r!==i[s])return s;if(!Ht(r,t,e))return s}return r}(t,e,n,i,Math.min(i.length,n.length));let s;if(r>=i.length)s=Vt;else if(0===r&&1===i.length)s=i;else{s=[];for(let t=i.length-1;t>=r;t--)s.push(i[t])}const a=0===r?n:n.slice(r);return{intersection:r>0?i[r-1]:"",toDeactivate:s,toActivate:a}}function se(t,e,n){if(n)return re(t,e);if(null!==ne&&t===Jt&&e===Yt)return ne;if(null!==ie&&t===te&&e===ee)return ie;const i=re(t,e);return te=Jt,ee=Yt,ie=ne,Jt=t,Yt=e,ne=i,i}function ae(t,e){var n;return{name:e??(n=t.segments,n.at(-1)?.fullName??""),params:t.params,meta:t.meta}}var oe=class{#z;#q;get#f(){return this.#z.depsStore}constructor(t=[],e){this.#z=Gt(t,e)}static shouldUpdateNode(t){return(e,n)=>{if(!e||"object"!=typeof e||!("name"in e))throw new TypeError("[router.shouldUpdateNode] toState must be valid State object");if(e.transition?.reload)return!0;if(""===t&&!n)return!0;const{intersection:i,toActivate:r,toDeactivate:s}=se(e,n);return t===i||!!r.includes(t)||s.includes(t)}}setDependencies(t){this.#z.depsStore=t;for(const[e,n]of this.#z.pendingCanActivate)t.addActivateGuard(e,n);this.#z.pendingCanActivate.clear();for(const[e,n]of this.#z.pendingCanDeactivate)t.addDeactivateGuard(e,n);this.#z.pendingCanDeactivate.clear()}setLifecycleNamespace(t){this.#z.lifecycleNamespace=t}setRootPath(t){this.#z.rootPath=t,Bt(this.#z)}hasRoute(t){return this.#z.matcher.hasRoute(t)}clearRoutes(){xt(this.#z)}buildPath(t,e,n){if(t===o.UNKNOWN_ROUTE)return"string"==typeof e?.path?e.path:"";const i=Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e??{},r="function"==typeof this.#z.config.encoders[t]?this.#z.config.encoders[t]({...i}):i;return this.#z.matcher.buildPath(t,r,this.#G(n))}matchPath(t,e){const n=e,i=this.#z.matcher.match(t);if(!i)return;const r=ae(i),{name:s,params:a,meta:o}=r,c="function"==typeof this.#z.config.decoders[s]?this.#z.config.decoders[s](a):a,{name:u,params:l}=this.#f.forwardState(s,c);let h=t;if(n.rewritePathOnMatch){const t="function"==typeof this.#z.config.encoders[u]?this.#z.config.encoders[u]({...l}):l,e=n.trailingSlash;h=this.#z.matcher.buildPath(u,t,{trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:n.queryParamsMode})}return this.#f.makeState(u,l,h,o)}forwardState(t,e){if(Object.hasOwn(this.#z.config.forwardFnMap,t)){const n=this.#W(t,e),i=this.#z.config.forwardFnMap[t],r=this.#V(t,i,e);return{name:r,params:this.#W(r,n)}}const n=this.#z.resolvedForwardMap[t]??t;if(n!==t&&Object.hasOwn(this.#z.config.forwardFnMap,n)){const i=this.#W(t,e),r=this.#z.config.forwardFnMap[n],s=this.#V(n,r,e);return{name:s,params:this.#W(s,i)}}if(n!==t){const i=this.#W(t,e);return{name:n,params:this.#W(n,i)}}return{name:t,params:this.#W(t,e)}}buildStateResolved(t,e){const n=this.#z.matcher.getSegmentsByName(t);if(n)return ae({segments:n,params:e,meta:this.#z.matcher.getMetaByName(t)},t)}isActiveRoute(t,e={},n=!1,i=!0){const r=this.#f.getState();if(!r)return!1;const s=r.name;if(s!==t&&!s.startsWith(`${t}.`)&&!t.startsWith(`${s}.`))return!1;const a=this.#z.config.defaultParams[t];if(n||s===t){const n=a?{...a,...e}:e;return this.#f.areStatesEqual({name:t,params:n,path:""},r,i)}const o=r.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 i in t)if(!(i in n)&&t[i]!==e[i])return!1;return!0}(a,o,e))}getMetaForState(t){return this.#z.matcher.hasRoute(t)?this.#z.matcher.getMetaByName(t):void 0}getUrlParams(t){const e=this.#z.matcher.getSegmentsByName(t);return e?function(t){const e=[];for(const n of t)for(const t of n.paramMeta.urlParams)e.push(t);return e}(e):[]}getStore(){return this.#z}#W(t,e){return Object.hasOwn(this.#z.config.defaultParams,t)?{...this.#z.config.defaultParams[t],...e}:e}#G(t){if(this.#q)return this.#q;const e=t?.trailingSlash;return this.#q=Object.freeze({trailingSlash:"never"===e||"always"===e?e:void 0,queryParamsMode:t?.queryParamsMode}),this.#q}#V(t,e,n){const i=new Set([t]);let r=e(this.#f.getDependency,n),s=0;if("string"!=typeof r)throw new TypeError("forwardTo callback must return a string, got "+typeof r);for(;s<100;){if(void 0===this.#z.matcher.getSegmentsByName(r))throw new Error(`Route "${r}" does not exist`);if(i.has(r)){const t=[...i,r].join(" → ");throw new Error(`Circular forwardTo detected: ${t}`)}if(i.add(r),Object.hasOwn(this.#z.config.forwardFnMap,r)){r=(0,this.#z.config.forwardFnMap[r])(this.#f.getDependency,n),s++;continue}const t=this.#z.config.forwardMap[r];if(void 0===t)return r;r=t,s++}throw new Error("forwardTo exceeds maximum depth of 100")}},ce=new Set(Object.values(s)),ue=new Set(["code","segment","path","redirect"]),le=new Set(["setCode","setErrorInstance","setAdditionalFields","hasField","getField","toJSON"]),he=class extends Error{segment;path;redirect;code;constructor(t,{message:e,segment:n,path:i,redirect:r,...s}={}){super(e??t),this.code=t,this.segment=n,this.path=i,this.redirect=r?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),i=new WeakSet;return function t(e){if(null===e||"object"!=typeof e)return;if(i.has(e))return;i.add(e),Object.freeze(e);const n=Array.isArray(e)?e:Object.values(e);for(const e of n)t(e)}(n),n}(r):void 0;for(const[t,e]of Object.entries(s)){if(ue.has(t))throw new TypeError(`[RouterError] Cannot set reserved property "${t}"`);le.has(t)||(this[t]=e)}}setCode(t){this.code=t,ce.has(this.message)&&(this.message=t)}setErrorInstance(t){if(!t)throw new TypeError("[RouterError.setErrorInstance] err parameter is required and must be an Error instance");this.message=t.message,this.cause=t.cause,this.stack=t.stack??""}setAdditionalFields(t){for(const[e,n]of Object.entries(t)){if(ue.has(e))throw new TypeError(`[RouterError.setAdditionalFields] Cannot set reserved property "${e}"`);le.has(e)||(this[e]=n)}}hasField(t){return t in this}getField(t){return this[t]}toJSON(){const t={code:this.code,message:this.message};void 0!==this.segment&&(t.segment=this.segment),void 0!==this.path&&(t.path=this.path),void 0!==this.redirect&&(t.redirect=this.redirect);const e=new Set(["code","message","segment","path","redirect","stack"]);for(const n in this)Object.hasOwn(this,n)&&!e.has(n)&&(t[n]=this[n]);return t}},de=new he(s.ROUTER_NOT_STARTED),fe=new he(s.ROUTE_NOT_FOUND),pe=new he(s.SAME_STATES),ge=Promise.reject(de),me=Promise.reject(fe),ve=Promise.reject(pe);function Se(t,e){const{toState:n,fromState:i,opts:r,toDeactivate:a,toActivate:c,intersection:u}=e;if(n.name!==o.UNKNOWN_ROUTE&&!t.hasRoute(n.name)){const e=new he(s.ROUTE_NOT_FOUND,{routeName:n.name});throw t.sendTransitionFail(n,i,e),e}if(i)for(const n of a)!c.includes(n)&&e.canDeactivateFunctions.has(n)&&t.clearCanDeactivate(n);n.transition=function(t,e,n,i,r){const s={phase:"activating",reason:"success",segments:{deactivated:n,activated:i,intersection:r}};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}(i,r,a,c,u);const l=I(n);t.setState(l);const h=void 0===r.signal?r:function({signal:t,...e}){return e}(r);return t.sendTransitionDone(l,i,h),l}function Te(t,e,n,i){e.code!==s.TRANSITION_CANCELLED&&e.code!==s.ROUTE_NOT_FOUND&&t.sendTransitionFail(n,i,e)}function ye(t,e,n){if(t instanceof DOMException&&"AbortError"===t.name)throw new he(s.TRANSITION_CANCELLED);!function(t,e,n){if(t instanceof he)throw t.setCode(e),t;throw new he(e,function(t,e){const n={segment:e};if(t instanceof Error)return{...n,message:t.message,stack:t.stack,..."cause"in t&&void 0!==t.cause&&{cause:t.cause}};if(t&&"object"==typeof t){const e={};for(const[n,i]of Object.entries(t))we.has(n)||(e[n]=i);return{...n,...e}}return n}(t,n))}(t,e,n)}ge.catch(()=>{}),me.catch(()=>{}),ve.catch(()=>{});var we=new Set(["code","segment","path","redirect"]);async function be(t,e,n){let i;try{i=await t}catch(t){return void ye(t,e,n)}if(!i)throw new he(e,{segment:n})}async function Ne(t,e,n,i,r,a,o,c,u,l){await be(u,n,l);for(let u=c;u<e.length;u++){if(!o())throw new he(s.TRANSITION_CANCELLED);const c=e[u],l=t.get(c);if(!l)continue;let h=!1;try{h=l(i,r,a)}catch(t){ye(t,n,c)}if(h instanceof Promise)await be(h,n,c);else if(!h)throw new he(n,{segment:c})}}function Ae(t,e,n,i,r,a,o){for(const[c,u]of e.entries()){if(!o())throw new he(s.TRANSITION_CANCELLED);const l=t.get(u);if(!l)continue;let h=!1;try{h=l(i,r,a)}catch(t){ye(t,n,u)}if(h instanceof Promise)return Ne(t,e,n,i,r,a,o,c+1,h,u);if(!h)throw new he(n,{segment:u})}}var Oe=[o.UNKNOWN_ROUTE];Object.freeze(Oe);var Ee={replace:!0};Object.freeze(Ee);var Pe=class{lastSyncResolved=!1;lastSyncRejected=!1;#f;#Q=null;#K=0;setDependencies(t){this.#f=t}navigate(t,e,n){this.lastSyncResolved=!1;const i=this.#f;if(!i.canNavigate())return this.lastSyncRejected=!0,ge;let r,a,c=!1,u=null;try{if(r=i.buildNavigateState(t,e),!r)return i.emitTransitionError(void 0,i.getState(),fe),this.lastSyncRejected=!0,me;if(a=i.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,r))return i.emitTransitionError(r,a,pe),this.lastSyncRejected=!0,ve;if(this.#H(),n.signal?.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:n.signal.reason});const l=++this.#K;if(i.startTransition(r,a),c=!0,this.#K!==l)throw new he(s.TRANSITION_CANCELLED);const[h,d]=i.getLifecycleFunctions(),f=r.name===o.UNKNOWN_ROUTE,{toDeactivate:p,toActivate:g,intersection:m}=se(r,a,n.reload),v=a&&!n.forceDeactivate&&p.length>0,S=!f&&g.length>0;if(h.size>0||d.size>0){u=new AbortController,this.#Q=u;const t=()=>this.#K===l&&i.isActive(),e=function(t,e,n,i,r,a,o,c,u,l){if(r){const r=Ae(t,n,s.CANNOT_DEACTIVATE,o,c,u,l);if(void 0!==r)return async function(t,e,n,i,r,a,o,c){if(await t,!c())throw new he(s.TRANSITION_CANCELLED);if(i){const t=Ae(e,n,s.CANNOT_ACTIVATE,r,a,o,c);if(void 0!==t&&await t,!c())throw new he(s.TRANSITION_CANCELLED)}}(r,e,i,a,o,c,u,l)}if(!l())throw new he(s.TRANSITION_CANCELLED);if(a)return Ae(e,i,s.CANNOT_ACTIVATE,o,c,u,l)}(h,d,p,g,!!v,S,r,a,u.signal,t);if(void 0!==e)return this.#J(e,{toState:r,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h},u,l);if(!t())throw new he(s.TRANSITION_CANCELLED);this.#Y(u)}return this.lastSyncResolved=!0,Promise.resolve(Se(i,{toState:r,fromState:a,opts:n,toDeactivate:p,toActivate:g,intersection:m,canDeactivateFunctions:h}))}catch(t){return this.#X(t,u,c,r,a),Promise.reject(t)}}navigateToDefault(t){const e=this.#f;if(!e.getOptions().defaultRoute)return Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute not configured"}));const{route:n,params:i}=e.resolveDefault();return n?this.navigate(n,i,t):Promise.reject(new he(s.ROUTE_NOT_FOUND,{routeName:"defaultRoute resolved to empty"}))}navigateToNotFound(t){this.#H();const e=this.#f.getState(),n=e?Zt(e.name).toReversed():[];Object.freeze(n);const i={deactivated:n,activated:Oe,intersection:""};Object.freeze(i);const r={phase:"activating",...e&&{from:e.name},reason:"success",segments:i};Object.freeze(r);const s={name:o.UNKNOWN_ROUTE,params:{},path:t,transition:r};return Object.freeze(s),this.#f.setState(s),this.#f.emitTransitionSuccess(s,e,Ee),s}abortCurrentNavigation(){this.#Q?.abort(new he(s.TRANSITION_CANCELLED)),this.#Q=null}async#J(t,e,n,i){const r=this.#f,a=()=>this.#K===i&&!n.signal.aborted&&r.isActive();try{if(e.opts.signal){if(e.opts.signal.aborted)throw new he(s.TRANSITION_CANCELLED,{reason:e.opts.signal.reason});e.opts.signal.addEventListener("abort",()=>{n.abort(e.opts.signal?.reason)},{once:!0,signal:n.signal})}if(await t,!a())throw new he(s.TRANSITION_CANCELLED);return Se(r,e)}catch(t){throw Te(r,t,e.toState,e.fromState),t}finally{this.#Y(n)}}#X(t,e,n,i,r){e&&this.#Y(e),n&&i&&Te(this.#f,t,i,r)}#Y(t){t.abort(),this.#Q===t&&(this.#Q=null)}#H(){this.#f.isTransitioning()&&(t.logger.warn("router.navigate","Concurrent navigation detected on shared router instance. For SSR, use cloneRouter() to create isolated instance per request."),this.#Q?.abort(new he(s.TRANSITION_CANCELLED)),this.#f.cancelNavigation())}},Re={replace:!0};Object.freeze(Re);var Ce=class{#f;setDependencies(t){this.#f=t}async start(t){const e=this.#f,n=e.getOptions(),i=e.matchPath(t);if(!i&&!n.allowNotFound){const n=new he(s.ROUTE_NOT_FOUND,{path:t});throw e.emitTransitionError(void 0,void 0,n),n}return e.completeStart(),i?e.navigate(i.name,i.params,Re):e.navigateToNotFound(t)}stop(){this.#f.clearState()}},De=class{#Z;#tt;#et;#nt;#it;#rt;constructor(t){this.#Z=t.routerFSM,this.#tt=t.emitter,this.#et=void 0,this.#st()}static validateSubscribeListener(t){if("function"!=typeof t)throw new TypeError("[router.subscribe] Expected a function. For Observable pattern use @real-router/rx package")}emitRouterStart(){this.#tt.emit(p.ROUTER_START)}emitRouterStop(){this.#tt.emit(p.ROUTER_STOP)}emitTransitionStart(t,e){this.#tt.emit(p.TRANSITION_START,t,e)}emitTransitionSuccess(t,e,n){this.#tt.emit(p.TRANSITION_SUCCESS,t,e,n)}emitTransitionError(t,e,n){this.#tt.emit(p.TRANSITION_ERROR,t,e,n)}emitTransitionCancel(t,e){this.#tt.emit(p.TRANSITION_CANCEL,t,e)}sendStart(){this.#Z.send(b)}sendStop(){this.#Z.send(R)}sendDispose(){this.#Z.send(C)}sendStarted(){this.#Z.send(N)}sendNavigate(t,e){this.#et=t,this.#Z.forceState(y),this.emitTransitionStart(t,e)}sendComplete(t,e,n={}){this.#Z.forceState(T),this.emitTransitionSuccess(t,e,n),this.#et===t&&(this.#et=void 0)}sendFail(t,e,n){const i=this.#et;this.#nt=t,this.#it=e,this.#rt=n,this.#Z.send(E),this.#et===i&&(this.#et=void 0)}sendFailSafe(t,e,n){this.isReady()?this.sendFail(t,e,n):this.emitTransitionError(t,e,n)}sendCancel(t,e){const n=this.#et;this.#nt=t,this.#it=e,this.#Z.send(P),this.#et===n&&(this.#et=void 0)}canBeginTransition(){return this.#Z.canSend(A)}canStart(){return this.#Z.canSend(b)}canCancel(){return this.#Z.canSend(P)}isActive(){const t=this.#Z.getState();return t!==v&&t!==w}isDisposed(){return this.#Z.getState()===w}isTransitioning(){return this.#Z.getState()===y}isReady(){return this.#Z.getState()===T}getCurrentToState(){return this.#et}addEventListener(t,e){return this.#tt.on(t,e)}subscribe(t){return this.#tt.on(p.TRANSITION_SUCCESS,(e,n)=>{t({route:e,previousRoute:n})})}clearAll(){this.#tt.clearAll()}setLimits(t){this.#tt.setLimits(t)}sendCancelIfTransitioning(t){this.canCancel()&&this.sendCancel(this.#et,t)}#at(){this.emitTransitionError(this.#nt,this.#it,this.#rt)}#st(){const t=this.#Z;t.on(S,N,()=>{this.emitRouterStart()}),t.on(T,R,()=>{this.emitRouterStop()}),t.on(y,P,()=>{const t=this.#nt;void 0!==t&&this.emitTransitionCancel(t,this.#it)}),t.on(S,E,()=>{this.#at()}),t.on(T,E,()=>{this.#at()}),t.on(y,E,()=>{this.#at()})}},Fe=new he(s.ROUTER_ALREADY_STARTED),je=new Set(["all","warn-error","error-only"]);var Le=class{router;options;limits;dependenciesStore;state;routes;routeLifecycle;plugins;navigation;lifecycle;eventBus;constructor(t){this.router=t.router,this.options=t.options,this.limits=t.limits,this.dependenciesStore=t.dependenciesStore,this.state=t.state,this.routes=t.routes,this.routeLifecycle=t.routeLifecycle,this.plugins=t.plugins,this.navigation=t.navigation,this.lifecycle=t.lifecycle,this.eventBus=t.eventBus}wireLimits(){this.dependenciesStore.limits=this.limits,this.plugins.setLimits(this.limits),this.eventBus.setLimits({maxListeners:this.limits.maxListeners,warnListeners:this.limits.warnListeners,maxEventDepth:this.limits.maxEventDepth}),this.routeLifecycle.setLimits(this.limits)}wireRouteLifecycleDeps(){const t={compileFactory:this.createCompileFactory()};this.routeLifecycle.setDependencies(t),this.routeLifecycle.setValidatorGetter(()=>{try{return M(this.router).validator}catch{return null}})}wireRoutesDeps(){this.routes.setDependencies({addActivateGuard:(t,e)=>{this.routeLifecycle.addCanActivate(t,e,!0)},addDeactivateGuard:(t,e)=>{this.routeLifecycle.addCanDeactivate(t,e,!0)},makeState:(t,e,n,i)=>this.state.makeState(t,e,n,i),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:i,params:r}=n.forwardState(t,e),s=this.routes.getMetaForState(i);if(void 0===s)return;const a=n.buildPath(i,r);return this.state.makeState(i,r,a,s,void 0,!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])}},Ie=Object.freeze({}),_e=class n{#u;#S;#ot;#ct;#ut;#lt;#m;#ht;#dt;#ft;constructor(n=[],i={},s={}){i.logger&&function(t){if("object"!=typeof t||null===t)throw new TypeError("Logger config must be an object");const e=t;for(const t of Object.keys(e))if("level"!==t&&"callback"!==t)throw new TypeError(`Unknown logger config property: "${t}"`);if("level"in e&&void 0!==e.level&&("string"!=typeof(n=e.level)||!je.has(n)))throw new TypeError(`Invalid logger level: ${function(t){return"string"==typeof t?`"${t}"`:"object"==typeof t?JSON.stringify(t):String(t)}(e.level)}. Expected: "all" | "warn-error" | "error-only"`);var n;if("callback"in e&&void 0!==e.callback&&"function"!=typeof e.callback)throw new TypeError("Logger callback must be a function, got "+typeof e.callback);return!0}(i.logger)&&(t.logger.configure(i.logger),delete i.logger),z.validateOptionsIsObject(i),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(i),this.#S=function(t={}){return{...g,...t}}(i.limits),this.#ot=function(t={}){const e=Object.create(null);for(const n in t)void 0!==t[n]&&(e[n]=t[n]);return{dependencies:e,limits:g}}(s),this.#ct=new G,this.#ut=new oe(n,function(t){return{strictTrailingSlash:"strict"===t.trailingSlash,strictQueryParams:"strict"===t.queryParamsMode,urlParamsEncoding:t.urlParamsEncoding,queryParams:t.queryParams}}(this.#u.get())),this.#lt=new H,this.#m=new K,this.#ht=new Pe,this.#dt=new Ce;const a=new e.FSM(D),o=new r({onListenerError:(e,n)=>{t.logger.error("Router",`Error in listener for ${e}:`,n)},onListenerWarn:(e,n)=>{t.logger.warn("router.addEventListener",`Event "${e}" has ${n} listeners — possible memory leak`)}});var c;this.#ft=new De({routerFSM:a,emitter:o}),(c=new Le({router:this,options:this.#u,limits:this.#S,dependenciesStore:this.#ot,state:this.#ct,routes:this.#ut,routeLifecycle:this.#lt,plugins:this.#m,navigation:this.#ht,lifecycle:this.#dt,eventBus:this.#ft})).wireLimits(),c.wireRouteLifecycleDeps(),c.wireRoutesDeps(),c.wirePluginsDeps(),c.wireNavigationDeps(),c.wireLifecycleDeps(),c.wireStateDeps();const u=new Map;var l,h,d;l={makeState:(t,e,n,i,r)=>this.#ct.makeState(t,e,n,i,r),forwardState:$("forwardState",(t,e)=>this.#ut.forwardState(t,e),u),buildStateResolved:(t,e)=>this.#ut.buildStateResolved(t,e),matchPath:(t,e)=>this.#ut.matchPath(t,e),getOptions:()=>this.#u.get(),addEventListener:(t,e)=>this.#ft.addEventListener(t,e),buildPath:$("buildPath",(t,e)=>this.#ut.buildPath(t,e??m,this.#u.get()),u),start:(h=t=>this.#dt.start(t),d=u,(...t)=>{const e=d.get("start");return e&&0!==e.length?U(e,h,t):h(...t)}),interceptors:u,setRootPath:t=>{this.#ut.setRootPath(t)},getRootPath:()=>this.#ut.getStore().rootPath,getTree:()=>this.#ut.getStore().tree,isDisposed:()=>this.#ft.isDisposed(),validator:null,dependenciesGetStore:()=>this.#ot,cloneOptions:()=>({...this.#u.get()}),cloneDependencies:()=>({...this.#ot.dependencies}),getLifecycleFactories:()=>this.#lt.getFactories(),getPluginFactories:()=>this.#m.getAll(),routeGetStore:()=>this.#ut.getStore(),getStateName:()=>this.#ct.get()?.name,isTransitioning:()=>this.#ft.isTransitioning(),clearState:()=>{this.#ct.set(void 0)},setState:t=>{this.#ct.set(t)},routerExtensions:[]},_.set(this,l),this.isActiveRoute=this.isActiveRoute.bind(this),this.buildPath=this.buildPath.bind(this),this.getState=this.getState.bind(this),this.getPreviousState=this.getPreviousState.bind(this),this.areStatesEqual=this.areStatesEqual.bind(this),this.shouldUpdateNode=this.shouldUpdateNode.bind(this),this.isActive=this.isActive.bind(this),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this.dispose=this.dispose.bind(this),this.canNavigateTo=this.canNavigateTo.bind(this),this.usePlugin=this.usePlugin.bind(this),this.navigate=this.navigate.bind(this),this.navigateToDefault=this.navigateToDefault.bind(this),this.navigateToNotFound=this.navigateToNotFound.bind(this),this.subscribe=this.subscribe.bind(this)}isActiveRoute(e,n,i,r){return M(this).validator?.routes.validateIsActiveRouteArgs(e,n,i,r),M(this).validator?.routes.validateRouteName(e,"isActiveRoute"),""===e?(t.logger.warn("real-router",'isActiveRoute("") called with empty string. Root node is not considered a parent of any route.'),!1):this.#ut.isActiveRoute(e,n,i,r)}buildPath(t,e){const n=M(this);return n.validator?.routes.validateBuildPathArgs(t),n.validator?.navigation.validateParams(e,"buildPath"),n.buildPath(t,e)}getState(){return this.#ct.get()}getPreviousState(){return this.#ct.getPrevious()}areStatesEqual(t,e,n=!0){return M(this).validator?.state.validateAreStatesEqualArgs(t,e,n),this.#ct.areStatesEqual(t,e,n)}shouldUpdateNode(t){return M(this).validator?.routes.validateShouldUpdateNodeArgs(t),oe.shouldUpdateNode(t)}isActive(){return this.#ft.isActive()}start(t){if(!this.#ft.canStart())return Promise.reject(Fe);M(this).validator?.navigation.validateStartArgs(t),this.#ft.sendStart();const e=M(this).start(t).catch(t=>{throw this.#ft.isReady()&&(this.#dt.stop(),this.#ft.sendStop()),t});return n.#pt(e),e}stop(){return this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),this.#ft.isReady()||this.#ft.isTransitioning()?(this.#dt.stop(),this.#ft.sendStop(),this):this}dispose(){if(this.#ft.isDisposed())return;this.#ht.abortCurrentNavigation(),this.#ft.sendCancelIfTransitioning(this.#ct.get()),(this.#ft.isReady()||this.#ft.isTransitioning())&&(this.#dt.stop(),this.#ft.sendStop()),this.#ft.sendDispose(),this.#ft.clearAll(),this.#m.disposeAll();const t=M(this);for(const e of t.routerExtensions)for(const t of e.keys)delete this[t];t.routerExtensions.length=0,this.#ut.clearRoutes(),this.#lt.clearAll(),this.#ct.reset(),this.#ot.dependencies=Object.create(null),this.#gt()}canNavigateTo(t,e){const n=M(this);if(n.validator?.routes.validateRouteName(t,"canNavigateTo"),n.validator?.navigation.validateParams(e,"canNavigateTo"),!this.#ut.hasRoute(t))return!1;const{name:i,params:r}=n.forwardState(t,e??{}),s=this.#ct.makeState(i,r),a=this.#ct.get(),{toDeactivate:o,toActivate:c}=se(s,a);return this.#lt.canNavigateTo(o,c,s,a)}usePlugin(...t){const e=t.filter(Boolean);if(0===e.length)return()=>{};const n=M(this);n.validator?.plugins.validatePluginLimit(this.#m.count(),this.#S);for(const t of e)n.validator?.plugins.validateNoDuplicatePlugins(t,this.#m.getAll());return this.#m.use(...e)}subscribe(t){return De.validateSubscribeListener(t),this.#ft.subscribe(t)}navigate(t,e,i){const r=M(this);r.validator?.navigation.validateNavigateArgs(t),r.validator?.navigation.validateParams(e,"navigate");const s=i??Ie;r.validator?.navigation.validateNavigationOptions(s,"navigate");const a=this.#ht.navigate(t,e??m,s);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(a),a}navigateToDefault(t){const e=M(this);e.validator?.navigation.validateNavigateToDefaultArgs(t);const i=t??Ie;e.validator?.navigation.validateNavigationOptions(i,"navigateToDefault");const r=this.#ht.navigateToDefault(i);return this.#ht.lastSyncResolved?this.#ht.lastSyncResolved=!1:this.#ht.lastSyncRejected?this.#ht.lastSyncRejected=!1:n.#pt(r),r}navigateToNotFound(t){if(!this.#ft.isActive())throw new he(s.ROUTER_NOT_STARTED);if(void 0!==t&&"string"!=typeof t)throw new TypeError("[router.navigateToNotFound] path must be a string, got "+typeof t);const e=t??this.#ct.get().path;return this.#ht.navigateToNotFound(e)}static#mt=e=>{e instanceof he&&(e.code===s.SAME_STATES||e.code===s.TRANSITION_CANCELLED||e.code===s.ROUTER_NOT_STARTED||e.code===s.ROUTE_NOT_FOUND)||t.logger.error("router.navigate","Unexpected navigation error",e)};static#pt(t){t.catch(n.#mt)}#gt(){this.navigate=Me,this.navigateToDefault=Me,this.navigateToNotFound=Me,this.start=Me,this.stop=Me,this.usePlugin=Me,this.subscribe=Me,this.canNavigateTo=Me}};function Me(){throw new he(s.ROUTER_DISPOSED)}var Ue=new WeakMap;exports.Router=_e,exports.RouterError=he,exports.UNKNOWN_ROUTE=a,exports.constants=o,exports.createRouter=(t=[],e={},n={})=>new _e(t,e,n),exports.errorCodes=s,exports.events=p,exports.getNavigator=t=>{let e=Ue.get(t);return e||(e=Object.freeze({navigate:t.navigate,getState:t.getState,isActiveRoute:t.isActiveRoute,canNavigateTo:t.canNavigateTo,subscribe:t.subscribe}),Ue.set(t,e)),e},exports.resolveForwardChain=Mt;//# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./Router-CVNR-dug.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