@vlian/framework 1.2.61 → 1.2.62

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 (260) hide show
  1. package/dist/analytics.umd.js +1 -1
  2. package/dist/components/index.cjs +1 -1
  3. package/dist/components/index.d.ts +0 -4
  4. package/dist/components/index.js +1 -1
  5. package/dist/core-bak/Test.cjs +1 -0
  6. package/dist/core-bak/Test.d.ts +5 -0
  7. package/dist/core-bak/Test.js +1 -0
  8. package/dist/core-bak/app/AppContext.cjs +1 -0
  9. package/dist/core-bak/app/AppContext.d.ts +113 -0
  10. package/dist/core-bak/app/AppContext.js +1 -0
  11. package/dist/core-bak/app/AppContext.types.cjs +1 -0
  12. package/dist/core-bak/app/AppContext.types.d.ts +146 -0
  13. package/dist/core-bak/app/AppContext.types.js +1 -0
  14. package/dist/core-bak/app/BasicLayout.cjs +1 -0
  15. package/dist/core-bak/app/BasicLayout.d.ts +15 -0
  16. package/dist/core-bak/app/BasicLayout.js +1 -0
  17. package/dist/core-bak/app/DefaultApp.cjs +1 -0
  18. package/dist/core-bak/app/DefaultApp.d.ts +10 -0
  19. package/dist/core-bak/app/DefaultApp.js +1 -0
  20. package/dist/core-bak/app/index.cjs +1 -0
  21. package/dist/core-bak/app/index.d.ts +8 -0
  22. package/dist/core-bak/app/index.js +1 -0
  23. package/dist/core-bak/config/AppConfig.cjs +1 -0
  24. package/dist/core-bak/config/AppConfig.d.ts +88 -0
  25. package/dist/core-bak/config/AppConfig.js +1 -0
  26. package/dist/core-bak/config/ConfigLoader.cjs +1 -0
  27. package/dist/core-bak/config/ConfigLoader.d.ts +118 -0
  28. package/dist/core-bak/config/ConfigLoader.js +1 -0
  29. package/dist/core-bak/config/ConfigValidator.cjs +2 -0
  30. package/dist/core-bak/config/ConfigValidator.d.ts +84 -0
  31. package/dist/core-bak/config/ConfigValidator.js +2 -0
  32. package/dist/core-bak/config/index.cjs +1 -0
  33. package/dist/core-bak/config/index.d.ts +6 -0
  34. package/dist/core-bak/config/index.js +1 -0
  35. package/dist/core-bak/dev/DevTools.cjs +1 -0
  36. package/dist/core-bak/dev/DevTools.d.ts +16 -0
  37. package/dist/core-bak/dev/DevTools.js +1 -0
  38. package/dist/core-bak/error/ErrorBoundary.cjs +1 -0
  39. package/dist/core-bak/error/ErrorBoundary.d.ts +121 -0
  40. package/dist/core-bak/error/ErrorBoundary.js +1 -0
  41. package/dist/core-bak/error/ErrorHandler.cjs +1 -0
  42. package/dist/core-bak/error/ErrorHandler.d.ts +171 -0
  43. package/dist/core-bak/error/ErrorHandler.js +1 -0
  44. package/dist/core-bak/error/index.cjs +1 -0
  45. package/dist/core-bak/error/index.d.ts +7 -0
  46. package/dist/core-bak/error/index.js +1 -0
  47. package/dist/core-bak/event/AppEventBus.cjs +1 -0
  48. package/dist/core-bak/event/AppEventBus.d.ts +178 -0
  49. package/dist/core-bak/event/AppEventBus.js +1 -0
  50. package/dist/core-bak/event/frameworkEvents.cjs +1 -0
  51. package/dist/core-bak/event/frameworkEvents.d.ts +69 -0
  52. package/dist/core-bak/event/frameworkEvents.js +1 -0
  53. package/dist/core-bak/event/hooks.cjs +1 -0
  54. package/dist/core-bak/event/hooks.d.ts +57 -0
  55. package/dist/core-bak/event/hooks.js +1 -0
  56. package/dist/core-bak/event/index.cjs +1 -0
  57. package/dist/core-bak/event/index.d.ts +10 -0
  58. package/dist/core-bak/event/index.js +1 -0
  59. package/dist/core-bak/event/types.cjs +1 -0
  60. package/dist/core-bak/event/types.d.ts +269 -0
  61. package/dist/core-bak/event/types.js +1 -0
  62. package/dist/core-bak/event/useEventBus.cjs +1 -0
  63. package/dist/core-bak/event/useEventBus.d.ts +28 -0
  64. package/dist/core-bak/event/useEventBus.js +1 -0
  65. package/dist/core-bak/index.cjs +1 -0
  66. package/dist/core-bak/index.d.ts +54 -0
  67. package/dist/core-bak/index.js +1 -0
  68. package/dist/core-bak/initialization/InitializationErrorThrower.cjs +1 -0
  69. package/dist/core-bak/initialization/InitializationErrorThrower.d.ts +7 -0
  70. package/dist/core-bak/initialization/InitializationErrorThrower.js +1 -0
  71. package/dist/core-bak/initialization/index.cjs +1 -0
  72. package/dist/core-bak/initialization/index.d.ts +7 -0
  73. package/dist/core-bak/initialization/index.js +1 -0
  74. package/dist/core-bak/initialization/initialization.cjs +1 -0
  75. package/dist/core-bak/initialization/initialization.d.ts +69 -0
  76. package/dist/core-bak/initialization/initialization.js +1 -0
  77. package/dist/core-bak/initialization/initializationErrorState.cjs +1 -0
  78. package/dist/core-bak/initialization/initializationErrorState.d.ts +35 -0
  79. package/dist/core-bak/initialization/initializationErrorState.js +1 -0
  80. package/dist/core-bak/kernel/defaultAdapters.cjs +1 -0
  81. package/dist/core-bak/kernel/defaultAdapters.d.ts +2 -0
  82. package/dist/core-bak/kernel/defaultAdapters.js +1 -0
  83. package/dist/core-bak/kernel/errors.cjs +1 -0
  84. package/dist/core-bak/kernel/errors.d.ts +18 -0
  85. package/dist/core-bak/kernel/errors.js +1 -0
  86. package/dist/core-bak/kernel/index.cjs +1 -0
  87. package/dist/core-bak/kernel/index.d.ts +3 -0
  88. package/dist/core-bak/kernel/index.js +1 -0
  89. package/dist/core-bak/kernel/startKernel.cjs +1 -0
  90. package/dist/core-bak/kernel/startKernel.d.ts +2 -0
  91. package/dist/core-bak/kernel/startKernel.js +1 -0
  92. package/dist/core-bak/kernel/types.cjs +1 -0
  93. package/dist/core-bak/kernel/types.d.ts +114 -0
  94. package/dist/core-bak/kernel/types.js +1 -0
  95. package/dist/core-bak/middleware.cjs +1 -0
  96. package/dist/core-bak/middleware.d.ts +36 -0
  97. package/dist/core-bak/middleware.js +1 -0
  98. package/dist/core-bak/plugin/PluginEventBus.cjs +1 -0
  99. package/dist/core-bak/plugin/PluginEventBus.d.ts +169 -0
  100. package/dist/core-bak/plugin/PluginEventBus.js +1 -0
  101. package/dist/core-bak/plugin/PluginSandbox.cjs +1 -0
  102. package/dist/core-bak/plugin/PluginSandbox.d.ts +101 -0
  103. package/dist/core-bak/plugin/PluginSandbox.js +1 -0
  104. package/dist/core-bak/plugin.cjs +1 -0
  105. package/dist/core-bak/plugin.d.ts +224 -0
  106. package/dist/core-bak/plugin.js +1 -0
  107. package/dist/core-bak/router/RouterManager.cjs +1 -0
  108. package/dist/core-bak/router/RouterManager.d.ts +87 -0
  109. package/dist/core-bak/router/RouterManager.js +1 -0
  110. package/dist/core-bak/router/adapter/AdapterManager.cjs +1 -0
  111. package/dist/core-bak/router/adapter/AdapterManager.d.ts +94 -0
  112. package/dist/core-bak/router/adapter/AdapterManager.js +1 -0
  113. package/dist/core-bak/router/adapter/index.cjs +1 -0
  114. package/dist/core-bak/router/adapter/index.d.ts +6 -0
  115. package/dist/core-bak/router/adapter/index.js +1 -0
  116. package/dist/core-bak/router/adapter/react-router/ReactRouterAdapter.cjs +1 -0
  117. package/dist/core-bak/router/adapter/react-router/ReactRouterAdapter.d.ts +43 -0
  118. package/dist/core-bak/router/adapter/react-router/ReactRouterAdapter.js +1 -0
  119. package/dist/core-bak/router/adapter/react-router/index.cjs +1 -0
  120. package/dist/core-bak/router/adapter/react-router/index.d.ts +4 -0
  121. package/dist/core-bak/router/adapter/react-router/index.js +1 -0
  122. package/dist/core-bak/router/adapter/types.cjs +1 -0
  123. package/dist/core-bak/router/adapter/types.d.ts +111 -0
  124. package/dist/core-bak/router/adapter/types.js +1 -0
  125. package/dist/core-bak/router/dev/RouterDevTools.cjs +1 -0
  126. package/dist/core-bak/router/dev/RouterDevTools.d.ts +5 -0
  127. package/dist/core-bak/router/dev/RouterDevTools.js +1 -0
  128. package/dist/core-bak/router/dev/index.cjs +1 -0
  129. package/dist/core-bak/router/dev/index.d.ts +4 -0
  130. package/dist/core-bak/router/dev/index.js +1 -0
  131. package/dist/core-bak/router/dynamic/DynamicRouteManager.cjs +1 -0
  132. package/dist/core-bak/router/dynamic/DynamicRouteManager.d.ts +71 -0
  133. package/dist/core-bak/router/dynamic/DynamicRouteManager.js +1 -0
  134. package/dist/core-bak/router/dynamic/index.cjs +1 -0
  135. package/dist/core-bak/router/dynamic/index.d.ts +4 -0
  136. package/dist/core-bak/router/dynamic/index.js +1 -0
  137. package/dist/core-bak/router/errors/RouterError.cjs +1 -0
  138. package/dist/core-bak/router/errors/RouterError.d.ts +48 -0
  139. package/dist/core-bak/router/errors/RouterError.js +1 -0
  140. package/dist/core-bak/router/errors/index.cjs +1 -0
  141. package/dist/core-bak/router/errors/index.d.ts +4 -0
  142. package/dist/core-bak/router/errors/index.js +1 -0
  143. package/dist/core-bak/router/index.cjs +1 -0
  144. package/dist/core-bak/router/index.d.ts +16 -0
  145. package/dist/core-bak/router/index.js +1 -0
  146. package/dist/core-bak/router/lifecycle/RouterLifecycleManager.cjs +1 -0
  147. package/dist/core-bak/router/lifecycle/RouterLifecycleManager.d.ts +56 -0
  148. package/dist/core-bak/router/lifecycle/RouterLifecycleManager.js +1 -0
  149. package/dist/core-bak/router/lifecycle/index.cjs +1 -0
  150. package/dist/core-bak/router/lifecycle/index.d.ts +4 -0
  151. package/dist/core-bak/router/lifecycle/index.js +1 -0
  152. package/dist/core-bak/router/middleware/RouterMiddlewareManager.cjs +1 -0
  153. package/dist/core-bak/router/middleware/RouterMiddlewareManager.d.ts +61 -0
  154. package/dist/core-bak/router/middleware/RouterMiddlewareManager.js +1 -0
  155. package/dist/core-bak/router/middleware/auth.cjs +1 -0
  156. package/dist/core-bak/router/middleware/auth.d.ts +54 -0
  157. package/dist/core-bak/router/middleware/auth.js +1 -0
  158. package/dist/core-bak/router/middleware/index.cjs +1 -0
  159. package/dist/core-bak/router/middleware/index.d.ts +6 -0
  160. package/dist/core-bak/router/middleware/index.js +1 -0
  161. package/dist/core-bak/router/middleware/types.cjs +1 -0
  162. package/dist/core-bak/router/middleware/types.d.ts +82 -0
  163. package/dist/core-bak/router/middleware/types.js +1 -0
  164. package/dist/core-bak/router/monitoring/RouterMonitoring.cjs +1 -0
  165. package/dist/core-bak/router/monitoring/RouterMonitoring.d.ts +134 -0
  166. package/dist/core-bak/router/monitoring/RouterMonitoring.js +1 -0
  167. package/dist/core-bak/router/monitoring/index.cjs +1 -0
  168. package/dist/core-bak/router/monitoring/index.d.ts +4 -0
  169. package/dist/core-bak/router/monitoring/index.js +1 -0
  170. package/dist/core-bak/router/navigation/RouterNavigation.cjs +1 -0
  171. package/dist/core-bak/router/navigation/RouterNavigation.d.ts +43 -0
  172. package/dist/core-bak/router/navigation/RouterNavigation.js +1 -0
  173. package/dist/core-bak/router/navigation/index.cjs +1 -0
  174. package/dist/core-bak/router/navigation/index.d.ts +4 -0
  175. package/dist/core-bak/router/navigation/index.js +1 -0
  176. package/dist/core-bak/router/performance/RouteCache.cjs +1 -0
  177. package/dist/core-bak/router/performance/RouteCache.d.ts +113 -0
  178. package/dist/core-bak/router/performance/RouteCache.js +1 -0
  179. package/dist/core-bak/router/performance/RoutePreloader.cjs +1 -0
  180. package/dist/core-bak/router/performance/RoutePreloader.d.ts +111 -0
  181. package/dist/core-bak/router/performance/RoutePreloader.js +1 -0
  182. package/dist/core-bak/router/performance/index.cjs +1 -0
  183. package/dist/core-bak/router/performance/index.d.ts +5 -0
  184. package/dist/core-bak/router/performance/index.js +1 -0
  185. package/dist/core-bak/router/plugin/RouterPluginManager.cjs +1 -0
  186. package/dist/core-bak/router/plugin/RouterPluginManager.d.ts +74 -0
  187. package/dist/core-bak/router/plugin/RouterPluginManager.js +1 -0
  188. package/dist/core-bak/router/plugin/index.cjs +1 -0
  189. package/dist/core-bak/router/plugin/index.d.ts +5 -0
  190. package/dist/core-bak/router/plugin/index.js +1 -0
  191. package/dist/core-bak/router/plugin/types.cjs +1 -0
  192. package/dist/core-bak/router/plugin/types.d.ts +153 -0
  193. package/dist/core-bak/router/plugin/types.js +1 -0
  194. package/dist/core-bak/router/types.cjs +1 -0
  195. package/dist/core-bak/router/types.d.ts +464 -0
  196. package/dist/core-bak/router/types.js +1 -0
  197. package/dist/core-bak/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -0
  198. package/dist/core-bak/router/utils/adapters/react-router/RouteErrorBoundary.d.ts +2 -0
  199. package/dist/core-bak/router/utils/adapters/react-router/RouteErrorBoundary.js +1 -0
  200. package/dist/core-bak/router/utils/adapters/react-router/transform.cjs +1 -0
  201. package/dist/core-bak/router/utils/adapters/react-router/transform.d.ts +5 -0
  202. package/dist/core-bak/router/utils/adapters/react-router/transform.js +1 -0
  203. package/dist/core-bak/router/utils/transform.cjs +1 -0
  204. package/dist/core-bak/router/utils/transform.d.ts +348 -0
  205. package/dist/core-bak/router/utils/transform.js +1 -0
  206. package/dist/core-bak/router/validation/RouterConfigValidator.cjs +2 -0
  207. package/dist/core-bak/router/validation/RouterConfigValidator.d.ts +121 -0
  208. package/dist/core-bak/router/validation/RouterConfigValidator.js +2 -0
  209. package/dist/core-bak/router/validation/index.cjs +1 -0
  210. package/dist/core-bak/router/validation/index.d.ts +5 -0
  211. package/dist/core-bak/router/validation/index.js +1 -0
  212. package/dist/core-bak/router/validation/schema.cjs +1 -0
  213. package/dist/core-bak/router/validation/schema.d.ts +180 -0
  214. package/dist/core-bak/router/validation/schema.js +1 -0
  215. package/dist/core-bak/router/version/RouteVersionManager.cjs +1 -0
  216. package/dist/core-bak/router/version/RouteVersionManager.d.ts +124 -0
  217. package/dist/core-bak/router/version/RouteVersionManager.js +1 -0
  218. package/dist/core-bak/router/version/index.cjs +1 -0
  219. package/dist/core-bak/router/version/index.d.ts +4 -0
  220. package/dist/core-bak/router/version/index.js +1 -0
  221. package/dist/core-bak/splash/SplashScreen.cjs +1 -0
  222. package/dist/core-bak/splash/SplashScreen.d.ts +14 -0
  223. package/dist/core-bak/splash/SplashScreen.js +1 -0
  224. package/dist/core-bak/splash/index.cjs +1 -0
  225. package/dist/core-bak/splash/index.d.ts +5 -0
  226. package/dist/core-bak/splash/index.js +1 -0
  227. package/dist/core-bak/splash/splashScreenUtils.cjs +1 -0
  228. package/dist/core-bak/splash/splashScreenUtils.d.ts +7 -0
  229. package/dist/core-bak/splash/splashScreenUtils.js +1 -0
  230. package/dist/core-bak/startup/AppInstance.cjs +1 -0
  231. package/dist/core-bak/startup/AppInstance.d.ts +138 -0
  232. package/dist/core-bak/startup/AppInstance.js +1 -0
  233. package/dist/core-bak/startup/environment.cjs +1 -0
  234. package/dist/core-bak/startup/environment.d.ts +87 -0
  235. package/dist/core-bak/startup/environment.js +1 -0
  236. package/dist/core-bak/startup/index.cjs +1 -0
  237. package/dist/core-bak/startup/index.d.ts +7 -0
  238. package/dist/core-bak/startup/index.js +1 -0
  239. package/dist/core-bak/startup/initializeServices.cjs +1 -0
  240. package/dist/core-bak/startup/initializeServices.d.ts +68 -0
  241. package/dist/core-bak/startup/initializeServices.js +1 -0
  242. package/dist/core-bak/startup/performanceTracker.cjs +1 -0
  243. package/dist/core-bak/startup/performanceTracker.d.ts +104 -0
  244. package/dist/core-bak/startup/performanceTracker.js +1 -0
  245. package/dist/core-bak/startup/renderApp.cjs +1 -0
  246. package/dist/core-bak/startup/renderApp.d.ts +70 -0
  247. package/dist/core-bak/startup/renderApp.js +1 -0
  248. package/dist/core-bak/startup/startApp.cjs +1 -0
  249. package/dist/core-bak/startup/startApp.d.ts +14 -0
  250. package/dist/core-bak/startup/startApp.js +1 -0
  251. package/dist/core-bak/types.cjs +1 -0
  252. package/dist/core-bak/types.d.ts +501 -0
  253. package/dist/core-bak/types.js +1 -0
  254. package/dist/index.cjs +1 -1
  255. package/dist/index.d.ts +0 -1
  256. package/dist/index.js +1 -1
  257. package/dist/index.umd.js +31 -246
  258. package/dist/kernel/types.d.ts +46 -3
  259. package/dist/state.umd.js +1 -1
  260. package/package.json +1 -11
@@ -0,0 +1,169 @@
1
+ /**
2
+ * 插件事件总线
3
+ * 用于插件间通信
4
+ */
5
+ /**
6
+ * 事件监听器类型
7
+ */
8
+ export type EventListener<T = unknown> = (data: T) => void | Promise<void>;
9
+ /**
10
+ * 事件元数据
11
+ */
12
+ export interface EventMetadata {
13
+ /**
14
+ * 事件来源(插件名称)
15
+ */
16
+ source?: string;
17
+ /**
18
+ * 事件时间戳
19
+ */
20
+ timestamp: number;
21
+ /**
22
+ * 事件ID(用于追踪)
23
+ */
24
+ eventId?: string;
25
+ /**
26
+ * 事件优先级
27
+ */
28
+ priority?: number;
29
+ }
30
+ /**
31
+ * 事件包装器
32
+ */
33
+ export interface EventWrapper<T = unknown> {
34
+ /**
35
+ * 事件数据
36
+ */
37
+ data: T;
38
+ /**
39
+ * 事件元数据
40
+ */
41
+ metadata: EventMetadata;
42
+ }
43
+ /**
44
+ * 事件总线配置
45
+ */
46
+ export interface PluginEventBusConfig {
47
+ /**
48
+ * 是否启用事件追踪
49
+ */
50
+ enableTracking?: boolean;
51
+ /**
52
+ * 最大事件历史记录数
53
+ */
54
+ maxHistorySize?: number;
55
+ /**
56
+ * 是否启用事件验证
57
+ */
58
+ enableValidation?: boolean;
59
+ /**
60
+ * 事件验证函数
61
+ */
62
+ validator?: (event: string, data: unknown) => boolean;
63
+ }
64
+ /**
65
+ * 事件总线
66
+ */
67
+ export declare class PluginEventBus {
68
+ private listeners;
69
+ private eventHistory;
70
+ private config;
71
+ private eventCounter;
72
+ /**
73
+ * 订阅事件
74
+ *
75
+ * @param event - 事件名称
76
+ * @param listener - 事件监听器(可以接收 EventWrapper 或直接数据)
77
+ * @returns 取消订阅函数
78
+ */
79
+ on<T = unknown>(event: string, listener: EventListener<T | EventWrapper<T>>): () => void;
80
+ /**
81
+ * 取消订阅事件
82
+ *
83
+ * @param event - 事件名称
84
+ * @param listener - 事件监听器
85
+ */
86
+ off<T = unknown>(event: string, listener: EventListener<T>): void;
87
+ constructor(config?: PluginEventBusConfig);
88
+ /**
89
+ * 发布事件
90
+ *
91
+ * @param event - 事件名称
92
+ * @param data - 事件数据
93
+ * @param metadata - 事件元数据(可选)
94
+ */
95
+ emit<T = unknown>(event: string, data?: T, metadata?: Partial<EventMetadata>): Promise<void>;
96
+ /**
97
+ * 发布事件(仅数据,向后兼容)
98
+ *
99
+ * @param event - 事件名称
100
+ * @param data - 事件数据
101
+ */
102
+ emitData<T = unknown>(event: string, data?: T): Promise<void>;
103
+ /**
104
+ * 一次性订阅事件
105
+ *
106
+ * @param event - 事件名称
107
+ * @param listener - 事件监听器
108
+ */
109
+ once<T = unknown>(event: string, listener: EventListener<T>): void;
110
+ /**
111
+ * 清空所有事件监听器
112
+ */
113
+ clear(): void;
114
+ /**
115
+ * 获取事件监听器数量
116
+ *
117
+ * @param event - 事件名称,如果不提供则返回所有事件的监听器总数
118
+ */
119
+ listenerCount(event?: string): number;
120
+ /**
121
+ * 获取所有事件名称
122
+ */
123
+ eventNames(): string[];
124
+ /**
125
+ * 获取事件历史记录
126
+ *
127
+ * @param event - 事件名称(可选,如果提供则只返回该事件的历史)
128
+ * @param limit - 限制返回的记录数
129
+ * @returns 事件历史记录
130
+ */
131
+ getEventHistory(event?: string, limit?: number): Array<{
132
+ event: string;
133
+ data: unknown;
134
+ metadata: EventMetadata;
135
+ }>;
136
+ /**
137
+ * 清空事件历史记录
138
+ */
139
+ clearHistory(): void;
140
+ /**
141
+ * 请求-响应模式:发送请求并等待响应
142
+ *
143
+ * @param event - 事件名称
144
+ * @param data - 请求数据
145
+ * @param timeout - 超时时间(毫秒)
146
+ * @returns 响应数据
147
+ */
148
+ request<TRequest = unknown, TResponse = unknown>(event: string, data?: TRequest, timeout?: number): Promise<TResponse>;
149
+ /**
150
+ * 请求-响应模式:注册请求处理器
151
+ *
152
+ * @param event - 事件名称
153
+ * @param handler - 请求处理器
154
+ * @returns 取消注册函数
155
+ */
156
+ onRequest<TRequest = unknown, TResponse = unknown>(event: string, handler: (data: TRequest, metadata: EventMetadata) => Promise<TResponse> | TResponse): () => void;
157
+ /**
158
+ * 获取配置
159
+ */
160
+ getConfig(): PluginEventBusConfig;
161
+ /**
162
+ * 更新配置
163
+ */
164
+ updateConfig(config: Partial<PluginEventBusConfig>): void;
165
+ }
166
+ /**
167
+ * 全局插件事件总线实例
168
+ */
169
+ export declare const pluginEventBus: PluginEventBus;
@@ -0,0 +1 @@
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export class PluginEventBus{on(event,listener){if(!this.listeners.has(event)){this.listeners.set(event,new Set)}const listeners=this.listeners.get(event);listeners.add(listener);return()=>{listeners.delete(listener);if(listeners.size===0){this.listeners.delete(event)}}}off(event,listener){const listeners=this.listeners.get(event);if(listeners){listeners.delete(listener);if(listeners.size===0){this.listeners.delete(event)}}}async emit(event,data,metadata){if(this.config.enableValidation&&!this.config.validator(event,data)){console.warn(`事件 ${event} 验证失败,已忽略`);return}const eventMetadata={source:metadata?.source,timestamp:metadata?.timestamp??Date.now(),eventId:metadata?.eventId??`event_${++this.eventCounter}`,priority:metadata?.priority??0};if(this.config.enableTracking){this.eventHistory.push({event,data,metadata:eventMetadata});if(this.eventHistory.length>this.config.maxHistorySize){this.eventHistory.shift()}}const listeners=this.listeners.get(event);if(!listeners||listeners.size===0){return}const eventWrapper={data:data,metadata:eventMetadata};const sortedListeners=Array.from(listeners);const promises=sortedListeners.map(listener=>{try{return Promise.resolve(listener(eventWrapper))}catch(error){console.error(`事件 ${event} 的监听器执行失败:`,error);return Promise.resolve()}});await Promise.allSettled(promises)}async emitData(event,data){return this.emit(event,data)}once(event,listener){const wrappedListener=async data=>{const actualData=data.data!==undefined?data.data:data;await listener(actualData);this.off(event,wrappedListener)};this.on(event,wrappedListener)}clear(){this.listeners.clear()}listenerCount(event){if(event){return this.listeners.get(event)?.size||0}let count=0;for(const listeners of this.listeners.values()){count+=listeners.size}return count}eventNames(){return Array.from(this.listeners.keys())}getEventHistory(event,limit){if(!this.config.enableTracking){return[]}let history=this.eventHistory;if(event){history=history.filter(h=>h.event===event)}if(limit){history=history.slice(-limit)}return[...history]}clearHistory(){this.eventHistory=[]}async request(event,data,timeout=5e3){return new Promise((resolve,reject)=>{const responseEvent=`${event}:response`;const requestId=`req_${Date.now()}_${Math.random()}`;const timeoutId=setTimeout(()=>{this.off(responseEvent,responseHandler);reject(new Error(`请求 ${event} 超时`))},timeout);const responseHandler=response=>{const actualResponse=response.data!==undefined?response.data:response;if(actualResponse.requestId===requestId){clearTimeout(timeoutId);this.off(responseEvent,responseHandler);resolve(actualResponse.data)}};this.on(responseEvent,responseHandler);this.emit(`${event}:request`,{requestId,data})})}onRequest(event,handler){const requestEvent=`${event}:request`;const responseEvent=`${event}:response`;return this.on(requestEvent,async wrapper=>{try{const actualWrapper=wrapper.data!==undefined?wrapper:{data:wrapper,metadata:{timestamp:Date.now()}};const response=await handler(actualWrapper.data.data,actualWrapper.metadata);this.emit(responseEvent,{requestId:actualWrapper.data.requestId,data:response})}catch(error){const actualWrapper=wrapper.data!==undefined?wrapper:{data:wrapper};this.emit(`${responseEvent}:error`,{requestId:actualWrapper.data.requestId,error:error instanceof Error?error.message:String(error)})}})}getConfig(){return{...this.config}}updateConfig(config){this.config={...this.config,...config}}constructor(config={}){_define_property(this,"listeners",new Map);_define_property(this,"eventHistory",[]);_define_property(this,"config",void 0);_define_property(this,"eventCounter",0);this.config={enableTracking:config.enableTracking??false,maxHistorySize:config.maxHistorySize??100,enableValidation:config.enableValidation??false,validator:config.validator??(()=>true)}}}export const pluginEventBus=new PluginEventBus({enableTracking:process.env.NODE_ENV==="development",maxHistorySize:100,enableValidation:false});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get PluginPermission(){return PluginPermission},get PluginSandbox(){return PluginSandbox}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}var PluginPermission=/*#__PURE__*/function(PluginPermission){PluginPermission["ACCESS_CONFIG"]="access_config";PluginPermission["ACCESS_STATE_MANAGER"]="access_state_manager";PluginPermission["ACCESS_STORAGE"]="access_storage";PluginPermission["EMIT_EVENTS"]="emit_events";PluginPermission["SUBSCRIBE_EVENTS"]="subscribe_events";return PluginPermission}({});let PluginSandbox=class PluginSandbox{hasPermission(permission){if(!this.config.strictMode){return true}return this.permissions.has(permission)}canAccessConfig(key){if(!this.hasPermission("access_config")){return false}if(this.config.configWhitelist&&this.config.configWhitelist.length>0){return this.config.configWhitelist.includes(key)}return true}canAccessStateScope(scope){if(!this.hasPermission("access_state_manager")){return false}if(this.config.stateScopeWhitelist&&this.config.stateScopeWhitelist.length>0){return this.config.stateScopeWhitelist.includes(scope)}return true}filterConfig(config){if(!this.hasPermission("access_config")){return{}}if(!this.config.configWhitelist||this.config.configWhitelist.length===0){return config}const filtered={};for(const key of this.config.configWhitelist){if(key in config){filtered[key]=config[key]}}return filtered}getConfig(){return{...this.config}}updatePermissions(permissions){this.permissions=new Set(permissions);this.config.permissions=permissions}constructor(config){_define_property(this,"config",void 0);_define_property(this,"permissions",void 0);this.config={strictMode:true,...config};this.permissions=new Set(config.permissions||[])}};
@@ -0,0 +1,101 @@
1
+ /**
2
+ * 插件沙箱
3
+ * 用于插件隔离和权限控制
4
+ */
5
+ import type { StartOptions } from '../types';
6
+ /**
7
+ * 插件权限
8
+ */
9
+ export declare enum PluginPermission {
10
+ /**
11
+ * 访问配置
12
+ */
13
+ ACCESS_CONFIG = "access_config",
14
+ /**
15
+ * 访问状态管理器
16
+ */
17
+ ACCESS_STATE_MANAGER = "access_state_manager",
18
+ /**
19
+ * 访问存储
20
+ */
21
+ ACCESS_STORAGE = "access_storage",
22
+ /**
23
+ * 发布事件
24
+ */
25
+ EMIT_EVENTS = "emit_events",
26
+ /**
27
+ * 订阅事件
28
+ */
29
+ SUBSCRIBE_EVENTS = "subscribe_events"
30
+ }
31
+ /**
32
+ * 插件沙箱配置
33
+ */
34
+ export interface PluginSandboxConfig {
35
+ /**
36
+ * 插件名称
37
+ */
38
+ name: string;
39
+ /**
40
+ * 允许的权限列表
41
+ */
42
+ permissions?: PluginPermission[];
43
+ /**
44
+ * 允许访问的配置键(白名单)
45
+ */
46
+ configWhitelist?: string[];
47
+ /**
48
+ * 允许访问的状态作用域(白名单)
49
+ */
50
+ stateScopeWhitelist?: (string | symbol)[];
51
+ /**
52
+ * 是否启用严格模式(默认true)
53
+ */
54
+ strictMode?: boolean;
55
+ }
56
+ /**
57
+ * 插件沙箱
58
+ */
59
+ export declare class PluginSandbox {
60
+ private config;
61
+ private permissions;
62
+ constructor(config: PluginSandboxConfig);
63
+ /**
64
+ * 检查权限
65
+ *
66
+ * @param permission - 权限
67
+ * @returns 是否有权限
68
+ */
69
+ hasPermission(permission: PluginPermission): boolean;
70
+ /**
71
+ * 检查是否可以访问配置键
72
+ *
73
+ * @param key - 配置键
74
+ * @returns 是否可以访问
75
+ */
76
+ canAccessConfig(key: string): boolean;
77
+ /**
78
+ * 检查是否可以访问状态作用域
79
+ *
80
+ * @param scope - 状态作用域
81
+ * @returns 是否可以访问
82
+ */
83
+ canAccessStateScope(scope: string | symbol): boolean;
84
+ /**
85
+ * 过滤配置(根据白名单)
86
+ *
87
+ * @param config - 完整配置
88
+ * @returns 过滤后的配置
89
+ */
90
+ filterConfig(config: StartOptions): Partial<StartOptions>;
91
+ /**
92
+ * 获取沙箱配置
93
+ */
94
+ getConfig(): PluginSandboxConfig;
95
+ /**
96
+ * 更新权限
97
+ *
98
+ * @param permissions - 权限列表
99
+ */
100
+ updatePermissions(permissions: PluginPermission[]): void;
101
+ }
@@ -0,0 +1 @@
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export var PluginPermission=/*#__PURE__*/function(PluginPermission){PluginPermission["ACCESS_CONFIG"]="access_config";PluginPermission["ACCESS_STATE_MANAGER"]="access_state_manager";PluginPermission["ACCESS_STORAGE"]="access_storage";PluginPermission["EMIT_EVENTS"]="emit_events";PluginPermission["SUBSCRIBE_EVENTS"]="subscribe_events";return PluginPermission}({});export class PluginSandbox{hasPermission(permission){if(!this.config.strictMode){return true}return this.permissions.has(permission)}canAccessConfig(key){if(!this.hasPermission("access_config")){return false}if(this.config.configWhitelist&&this.config.configWhitelist.length>0){return this.config.configWhitelist.includes(key)}return true}canAccessStateScope(scope){if(!this.hasPermission("access_state_manager")){return false}if(this.config.stateScopeWhitelist&&this.config.stateScopeWhitelist.length>0){return this.config.stateScopeWhitelist.includes(scope)}return true}filterConfig(config){if(!this.hasPermission("access_config")){return{}}if(!this.config.configWhitelist||this.config.configWhitelist.length===0){return config}const filtered={};for(const key of this.config.configWhitelist){if(key in config){filtered[key]=config[key]}}return filtered}getConfig(){return{...this.config}}updatePermissions(permissions){this.permissions=new Set(permissions);this.config.permissions=permissions}constructor(config){_define_property(this,"config",void 0);_define_property(this,"permissions",void 0);this.config={strictMode:true,...config};this.permissions=new Set(config.permissions||[])}}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get PluginEventBus(){return _PluginEventBus.PluginEventBus},get PluginManager(){return PluginManager},get PluginPermission(){return _PluginSandbox.PluginPermission},get PluginSandbox(){return _PluginSandbox.PluginSandbox},get pluginEventBus(){return _PluginEventBus.pluginEventBus},get pluginManager(){return pluginManager}});const _PluginSandbox=require("./plugin/PluginSandbox");const _PluginEventBus=require("./plugin/PluginEventBus");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}let PluginManager=class PluginManager{register(plugin){if(this.plugins.has(plugin.name)){console.warn(`插件 ${plugin.name} 已存在,将被覆盖`)}if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){console.warn(`插件 ${plugin.name} 的依赖未注册: ${missingDeps.join(", ")}`)}}this.plugins.set(plugin.name,plugin);this.pluginStatus.set(plugin.name,"registered");if(plugin.sandbox){const sandbox=new _PluginSandbox.PluginSandbox({...plugin.sandbox,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}else{const sandbox=new _PluginSandbox.PluginSandbox({strictMode:false,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}}getLoadOrder(){const plugins=Array.from(this.plugins.values());const sortedPlugins=plugins.sort((a,b)=>{const priorityA=a.priority??100;const priorityB=b.priority??100;return priorityA-priorityB});const visited=new Set;const visiting=new Set;const result=[];const visit=pluginName=>{if(visiting.has(pluginName)){console.warn(`检测到循环依赖,涉及插件: ${pluginName}`);return}if(visited.has(pluginName)){return}visiting.add(pluginName);const plugin=this.plugins.get(pluginName);if(plugin?.dependencies){for(const dep of plugin.dependencies){visit(dep)}}visiting.delete(pluginName);visited.add(pluginName);result.push(pluginName)};for(const plugin of sortedPlugins){visit(plugin.name)}return result}unregister(name){const plugin=this.plugins.get(name);if(plugin&&plugin.destroy){plugin.destroy()}this.plugins.delete(name);this.sandboxes.delete(name);this.pluginStatus.delete(name);this.pluginLoaders.delete(name)}async loadPlugin(options){let plugin;if(options.url){const response=await fetch(options.url);if(!response.ok){throw new Error(`无法加载插件: ${options.url} (${response.status})`)}const pluginModule=await response.json();plugin=pluginModule.default||pluginModule}else if(options.modulePath){const pluginModule=await Promise.resolve(options.modulePath).then(p=>/*#__PURE__*/_interop_require_wildcard(require(p)));plugin=pluginModule.default||pluginModule}else{throw new Error("必须提供 url 或 modulePath")}if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(this.plugins.has(plugin.name)){throw new Error(`插件 ${plugin.name} 已加载`)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}async initializePlugin(name,options,context){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未注册`)}const status=this.pluginStatus.get(name);if(status==="initialized"){return}try{const sandbox=this.sandboxes.get(name);if(!sandbox){throw new Error(`插件 ${name} 的沙箱未找到`)}if(plugin.init){const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,_PluginEventBus.pluginEventBus)}this.pluginStatus.set(name,"initialized")}catch(error){console.error(`插件 ${name} 初始化失败:`,error);throw error}}async unloadPlugin(name,force=false){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未加载`)}if(!force){const dependents=Array.from(this.plugins.values()).filter(p=>p.dependencies&&p.dependencies.includes(name));if(dependents.length>0){throw new Error(`无法卸载插件 ${name},以下插件依赖它: ${dependents.map(p=>p.name).join(", ")}`)}}if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${name} 的 destroy 钩子执行失败:`,error)}}this.unregister(name);this.pluginStatus.set(name,"destroyed")}canHotLoad(plugin){if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){return false}}return true}registerLoader(name,loader){this.pluginLoaders.set(name,loader)}async loadPluginByLoader(name,options){const loader=this.pluginLoaders.get(name);if(!loader){throw new Error(`插件 ${name} 的加载器未注册`)}const plugin=await loader();if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(plugin.name!==name){throw new Error(`插件名称不匹配: 期望 ${name},实际 ${plugin.name}`)}if(this.plugins.has(plugin.name)){return this.plugins.get(plugin.name)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options?.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}get(name){return this.plugins.get(name)}getAll(){return Array.from(this.plugins.values())}async executeBeforeInit(options){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.beforeInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.beforeInit(filteredOptions,sandbox,_PluginEventBus.pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 beforeInit 钩子执行失败:`,error)}}}async executeInit(options,context){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.init){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,_PluginEventBus.pluginEventBus);this.pluginStatus.set(plugin.name,"initialized")}catch(error){console.error(`插件 ${plugin.name} 的 init 钩子执行失败:`,error)}}}async executeAfterInit(options,context){const loadOrder=this.getLoadOrder();const reverseOrder=[...loadOrder].reverse();for(const pluginName of reverseOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.afterInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.afterInit(filteredOptions,context,sandbox,_PluginEventBus.pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 afterInit 钩子执行失败:`,error)}}}getPluginStatus(name){return this.pluginStatus.get(name)}isLoaded(name){return this.plugins.has(name)}getLoadedPlugins(){return Array.from(this.plugins.keys())}getAllPluginStatus(){return new Map(this.pluginStatus)}getSandbox(name){return this.sandboxes.get(name)}getEventBus(){return _PluginEventBus.pluginEventBus}async destroyAll(){for(const plugin of this.plugins.values()){if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${plugin.name} 的 destroy 钩子执行失败:`,error)}}}this.plugins.clear()}constructor(){_define_property(this,"plugins",new Map);_define_property(this,"sandboxes",new Map);_define_property(this,"pluginStatus",new Map);_define_property(this,"pluginLoaders",new Map)}};const pluginManager=new PluginManager;
@@ -0,0 +1,224 @@
1
+ import type { StartOptions } from './types';
2
+ import type { InitializationContext } from './initialization';
3
+ import { PluginSandbox, type PluginSandboxConfig } from './plugin/PluginSandbox';
4
+ import { type PluginEventBus } from './plugin/PluginEventBus';
5
+ /**
6
+ * 插件接口
7
+ */
8
+ export interface Plugin<TOption = unknown> {
9
+ /**
10
+ * 插件名称
11
+ */
12
+ name: string;
13
+ /**
14
+ * 插件版本
15
+ */
16
+ version?: string;
17
+ /**
18
+ * 插件依赖列表(插件名称数组)
19
+ * 优化:支持插件依赖管理
20
+ */
21
+ dependencies?: string[];
22
+ /**
23
+ * 插件优先级(数字越小优先级越高)
24
+ * 优化:支持插件加载顺序控制
25
+ */
26
+ priority?: number;
27
+ /**
28
+ * 插件沙箱配置(用于权限控制)
29
+ */
30
+ sandbox?: PluginSandboxConfig;
31
+ /**
32
+ * 初始化前钩子
33
+ */
34
+ beforeInit?: (options: Partial<StartOptions>, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
35
+ /**
36
+ * 初始化钩子
37
+ */
38
+ init?: (options: Partial<StartOptions>, context: InitializationContext, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
39
+ /**
40
+ * 初始化后钩子
41
+ */
42
+ afterInit?: (options: Partial<StartOptions>, context: InitializationContext, sandbox: PluginSandbox, eventBus: PluginEventBus) => Promise<void> | void;
43
+ /**
44
+ * 销毁钩子
45
+ */
46
+ destroy?: () => Promise<void> | void;
47
+ /**
48
+ * 自定义属性
49
+ */
50
+ readonly option?: Readonly<TOption>;
51
+ }
52
+ /**
53
+ * 插件加载选项
54
+ */
55
+ export interface PluginLoadOptions {
56
+ /**
57
+ * 插件URL(用于动态加载)
58
+ */
59
+ url?: string;
60
+ /**
61
+ * 插件模块路径(用于动态导入)
62
+ */
63
+ modulePath?: string;
64
+ /**
65
+ * 是否立即初始化
66
+ */
67
+ initialize?: boolean;
68
+ /**
69
+ * 初始化上下文(如果立即初始化)
70
+ */
71
+ initContext?: InitializationContext;
72
+ /**
73
+ * 启动选项(如果立即初始化)
74
+ */
75
+ startOptions?: StartOptions;
76
+ }
77
+ /**
78
+ * 插件管理器
79
+ *
80
+ * 优化:
81
+ * 1. 支持插件依赖管理
82
+ * 2. 支持插件优先级控制
83
+ * 3. 支持插件生命周期管理
84
+ * 4. 支持插件热插拔(动态加载/卸载)
85
+ */
86
+ export declare class PluginManager {
87
+ private plugins;
88
+ private sandboxes;
89
+ private pluginStatus;
90
+ private pluginLoaders;
91
+ /**
92
+ * 注册插件
93
+ *
94
+ * 优化:检查插件依赖是否已注册
95
+ */
96
+ register(plugin: Plugin): void;
97
+ /**
98
+ * 获取插件加载顺序(考虑依赖和优先级)
99
+ *
100
+ * @returns 插件名称数组,按加载顺序排列
101
+ */
102
+ private getLoadOrder;
103
+ /**
104
+ * 注销插件
105
+ */
106
+ unregister(name: string): void;
107
+ /**
108
+ * 动态加载插件(热插拔)
109
+ *
110
+ * @param options - 插件加载选项
111
+ * @returns 加载的插件
112
+ */
113
+ loadPlugin(options: PluginLoadOptions): Promise<Plugin>;
114
+ /**
115
+ * 初始化单个插件
116
+ *
117
+ * @param name - 插件名称
118
+ * @param options - 启动选项
119
+ * @param context - 初始化上下文
120
+ */
121
+ initializePlugin(name: string, options: StartOptions, context: InitializationContext): Promise<void>;
122
+ /**
123
+ * 卸载插件(热插拔)
124
+ *
125
+ * @param name - 插件名称
126
+ * @param force - 是否强制卸载(即使有依赖)
127
+ */
128
+ unloadPlugin(name: string, force?: boolean): Promise<void>;
129
+ /**
130
+ * 检查插件是否可以热加载
131
+ *
132
+ * @param plugin - 插件
133
+ * @returns 是否可以热加载
134
+ */
135
+ canHotLoad(plugin: Plugin): boolean;
136
+ /**
137
+ * 注册插件加载器(用于延迟加载)
138
+ *
139
+ * @param name - 插件名称
140
+ * @param loader - 加载器函数
141
+ */
142
+ registerLoader(name: string, loader: () => Promise<Plugin>): void;
143
+ /**
144
+ * 使用加载器加载插件
145
+ *
146
+ * @param name - 插件名称
147
+ * @param options - 加载选项
148
+ * @returns 加载的插件
149
+ */
150
+ loadPluginByLoader(name: string, options?: Omit<PluginLoadOptions, 'url' | 'modulePath'>): Promise<Plugin>;
151
+ /**
152
+ * 获取插件
153
+ */
154
+ get(name: string): Plugin | undefined;
155
+ /**
156
+ * 获取所有插件
157
+ */
158
+ getAll(): Plugin[];
159
+ /**
160
+ * 执行初始化前钩子
161
+ *
162
+ * 优化:按依赖顺序执行
163
+ */
164
+ executeBeforeInit(options: StartOptions): Promise<void>;
165
+ /**
166
+ * 执行初始化钩子
167
+ *
168
+ * 优化:按依赖顺序执行,并更新插件状态
169
+ */
170
+ executeInit(options: StartOptions, context: InitializationContext): Promise<void>;
171
+ /**
172
+ * 执行初始化后钩子
173
+ *
174
+ * 优化:按依赖顺序执行(逆序,确保依赖插件先执行)
175
+ */
176
+ executeAfterInit(options: StartOptions, context: InitializationContext): Promise<void>;
177
+ /**
178
+ * 获取插件状态
179
+ *
180
+ * @param name - 插件名称
181
+ * @returns 插件状态
182
+ */
183
+ getPluginStatus(name: string): 'registered' | 'initialized' | 'destroyed' | 'loading' | undefined;
184
+ /**
185
+ * 检查插件是否已加载
186
+ *
187
+ * @param name - 插件名称
188
+ * @returns 是否已加载
189
+ */
190
+ isLoaded(name: string): boolean;
191
+ /**
192
+ * 获取已加载的插件列表
193
+ *
194
+ * @returns 插件名称数组
195
+ */
196
+ getLoadedPlugins(): string[];
197
+ /**
198
+ * 获取所有插件状态
199
+ *
200
+ * @returns 插件状态映射
201
+ */
202
+ getAllPluginStatus(): Map<string, 'registered' | 'initialized' | 'destroyed' | 'loading'>;
203
+ /**
204
+ * 获取插件沙箱
205
+ *
206
+ * @param name - 插件名称
207
+ * @returns 插件沙箱或undefined
208
+ */
209
+ getSandbox(name: string): PluginSandbox | undefined;
210
+ /**
211
+ * 获取事件总线
212
+ */
213
+ getEventBus(): PluginEventBus;
214
+ /**
215
+ * 销毁所有插件
216
+ */
217
+ destroyAll(): Promise<void>;
218
+ }
219
+ /**
220
+ * 默认插件管理器
221
+ */
222
+ export declare const pluginManager: PluginManager;
223
+ export { PluginSandbox, PluginPermission, type PluginSandboxConfig } from './plugin/PluginSandbox';
224
+ export { PluginEventBus, pluginEventBus, type EventListener, type EventMetadata, type EventWrapper, type PluginEventBusConfig, } from './plugin/PluginEventBus';
@@ -0,0 +1 @@
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{PluginSandbox}from"./plugin/PluginSandbox";import{pluginEventBus}from"./plugin/PluginEventBus";export class PluginManager{register(plugin){if(this.plugins.has(plugin.name)){console.warn(`插件 ${plugin.name} 已存在,将被覆盖`)}if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){console.warn(`插件 ${plugin.name} 的依赖未注册: ${missingDeps.join(", ")}`)}}this.plugins.set(plugin.name,plugin);this.pluginStatus.set(plugin.name,"registered");if(plugin.sandbox){const sandbox=new PluginSandbox({...plugin.sandbox,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}else{const sandbox=new PluginSandbox({strictMode:false,name:plugin.name});this.sandboxes.set(plugin.name,sandbox)}}getLoadOrder(){const plugins=Array.from(this.plugins.values());const sortedPlugins=plugins.sort((a,b)=>{const priorityA=a.priority??100;const priorityB=b.priority??100;return priorityA-priorityB});const visited=new Set;const visiting=new Set;const result=[];const visit=pluginName=>{if(visiting.has(pluginName)){console.warn(`检测到循环依赖,涉及插件: ${pluginName}`);return}if(visited.has(pluginName)){return}visiting.add(pluginName);const plugin=this.plugins.get(pluginName);if(plugin?.dependencies){for(const dep of plugin.dependencies){visit(dep)}}visiting.delete(pluginName);visited.add(pluginName);result.push(pluginName)};for(const plugin of sortedPlugins){visit(plugin.name)}return result}unregister(name){const plugin=this.plugins.get(name);if(plugin&&plugin.destroy){plugin.destroy()}this.plugins.delete(name);this.sandboxes.delete(name);this.pluginStatus.delete(name);this.pluginLoaders.delete(name)}async loadPlugin(options){let plugin;if(options.url){const response=await fetch(options.url);if(!response.ok){throw new Error(`无法加载插件: ${options.url} (${response.status})`)}const pluginModule=await response.json();plugin=pluginModule.default||pluginModule}else if(options.modulePath){const pluginModule=await import(options.modulePath);plugin=pluginModule.default||pluginModule}else{throw new Error("必须提供 url 或 modulePath")}if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(this.plugins.has(plugin.name)){throw new Error(`插件 ${plugin.name} 已加载`)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}async initializePlugin(name,options,context){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未注册`)}const status=this.pluginStatus.get(name);if(status==="initialized"){return}try{const sandbox=this.sandboxes.get(name);if(!sandbox){throw new Error(`插件 ${name} 的沙箱未找到`)}if(plugin.init){const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,pluginEventBus)}this.pluginStatus.set(name,"initialized")}catch(error){console.error(`插件 ${name} 初始化失败:`,error);throw error}}async unloadPlugin(name,force=false){const plugin=this.plugins.get(name);if(!plugin){throw new Error(`插件 ${name} 未加载`)}if(!force){const dependents=Array.from(this.plugins.values()).filter(p=>p.dependencies&&p.dependencies.includes(name));if(dependents.length>0){throw new Error(`无法卸载插件 ${name},以下插件依赖它: ${dependents.map(p=>p.name).join(", ")}`)}}if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${name} 的 destroy 钩子执行失败:`,error)}}this.unregister(name);this.pluginStatus.set(name,"destroyed")}canHotLoad(plugin){if(plugin.dependencies&&plugin.dependencies.length>0){const missingDeps=plugin.dependencies.filter(dep=>!this.plugins.has(dep));if(missingDeps.length>0){return false}}return true}registerLoader(name,loader){this.pluginLoaders.set(name,loader)}async loadPluginByLoader(name,options){const loader=this.pluginLoaders.get(name);if(!loader){throw new Error(`插件 ${name} 的加载器未注册`)}const plugin=await loader();if(!plugin||!plugin.name){throw new Error("插件格式无效:必须包含 name 属性")}if(plugin.name!==name){throw new Error(`插件名称不匹配: 期望 ${name},实际 ${plugin.name}`)}if(this.plugins.has(plugin.name)){return this.plugins.get(plugin.name)}this.pluginStatus.set(plugin.name,"loading");try{this.register(plugin);if(options?.initialize&&options.initContext&&options.startOptions){await this.initializePlugin(plugin.name,options.startOptions,options.initContext)}return plugin}catch(error){this.pluginStatus.delete(plugin.name);throw error}}get(name){return this.plugins.get(name)}getAll(){return Array.from(this.plugins.values())}async executeBeforeInit(options){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.beforeInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.beforeInit(filteredOptions,sandbox,pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 beforeInit 钩子执行失败:`,error)}}}async executeInit(options,context){const loadOrder=this.getLoadOrder();for(const pluginName of loadOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.init){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.init(filteredOptions,context,sandbox,pluginEventBus);this.pluginStatus.set(plugin.name,"initialized")}catch(error){console.error(`插件 ${plugin.name} 的 init 钩子执行失败:`,error)}}}async executeAfterInit(options,context){const loadOrder=this.getLoadOrder();const reverseOrder=[...loadOrder].reverse();for(const pluginName of reverseOrder){const plugin=this.plugins.get(pluginName);if(!plugin||!plugin.afterInit){continue}try{const sandbox=this.sandboxes.get(plugin.name);if(!sandbox){console.warn(`插件 ${plugin.name} 的沙箱未找到`);continue}const filteredOptions=sandbox.filterConfig(options);await plugin.afterInit(filteredOptions,context,sandbox,pluginEventBus)}catch(error){console.error(`插件 ${plugin.name} 的 afterInit 钩子执行失败:`,error)}}}getPluginStatus(name){return this.pluginStatus.get(name)}isLoaded(name){return this.plugins.has(name)}getLoadedPlugins(){return Array.from(this.plugins.keys())}getAllPluginStatus(){return new Map(this.pluginStatus)}getSandbox(name){return this.sandboxes.get(name)}getEventBus(){return pluginEventBus}async destroyAll(){for(const plugin of this.plugins.values()){if(plugin.destroy){try{await plugin.destroy()}catch(error){console.error(`插件 ${plugin.name} 的 destroy 钩子执行失败:`,error)}}}this.plugins.clear()}constructor(){_define_property(this,"plugins",new Map);_define_property(this,"sandboxes",new Map);_define_property(this,"pluginStatus",new Map);_define_property(this,"pluginLoaders",new Map)}}export const pluginManager=new PluginManager;export{PluginSandbox,PluginPermission}from"./plugin/PluginSandbox";export{PluginEventBus,pluginEventBus}from"./plugin/PluginEventBus";
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get RouterManager(){return RouterManager},get getRouterManager(){return getRouterManager}});const _logger=require("@vlian/logger");const _transform=require("./utils/transform");const _transform1=require("./utils/adapters/react-router/transform");const _reactrouterdom=require("react-router-dom");const _validation=require("./validation");const _lifecycle=require("./lifecycle");const _middleware=require("./middleware");const _errors=require("./errors");const _RouteCache=require("./performance/RouteCache");const _RoutePreloader=require("./performance/RoutePreloader");const _plugin=require("./plugin");const _monitoring=require("./monitoring");const _adapter=require("./adapter");const _reactrouter=require("./adapter/react-router");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let RouterManager=class RouterManager{static getInstance(){if(!RouterManager.instance){RouterManager.instance=new RouterManager}return RouterManager.instance}async initialize(config){if(config.enabled===false||config.enabled==="disabled"){_logger.logger.info("路由系统已禁用");return}if(config.enableValidation!==false){try{_validation.RouterConfigValidator.validate(config);_logger.logger.debug("路由配置验证通过")}catch(error){_logger.logger.error("路由配置验证失败",error);if(process.env.NODE_ENV==="development"){throw error}}}await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.BEFORE_INIT,{config});if(config.hooks){const lifecycleManager=(0,_lifecycle.getRouterLifecycleManager)();lifecycleManager.register(config.hooks);_logger.logger.debug("路由生命周期钩子已注册")}if(!config.routes){throw new _errors.RouterError("路由配置不能为空",_errors.RouterErrorCode.ROUTER_CONFIG_ERROR)}this.preloader.updateConfig(config.preload);this.preloader.clear();let result;const cacheKey=config.routes;const cachedResult=this.cache.get(cacheKey);if(cachedResult){_logger.logger.debug("使用缓存的路由转换结果");result=cachedResult}else{await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.BEFORE_TRANSFORM,{config});result=await (0,_transform.transformRoutes)(config.routes,config.transformOptions);await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.AFTER_TRANSFORM,{config,routes:result.routes});this.cache.set(cacheKey,result)}const enableHydrateFallback=config.enableHydrateFallback??Boolean(config.options?.hydrationData);const reactRoutes=await (0,_transform1.transformRoutesToReactRoutes)(result.routes,result,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,enableHydrateFallback);if(result.routes){this.preloader.registerRoutes(result.routes,result);this.preloader.startPreload()}await this.resolveInitialLazyRoutes(reactRoutes,!enableHydrateFallback);let routerInstance=null;if(config.mode==="browser"){routerInstance=(0,_reactrouterdom.createBrowserRouter)(reactRoutes,config.options)}else if(config.mode==="hash"){routerInstance=(0,_reactrouterdom.createHashRouter)(reactRoutes,config.options)}else if(config.mode==="memory"){routerInstance=(0,_reactrouterdom.createMemoryRouter)(reactRoutes,config.options)}if(!routerInstance){throw new _errors.RouterError("路由模式不支持",_errors.RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{mode:config.mode})}this.router=routerInstance;this.initialized=true;await this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.AFTER_INIT,{config,routes:result.routes});const initialPath=typeof window!=="undefined"?`${window.location.pathname}${window.location.search}${window.location.hash}`:this.router?.state?.location?.pathname??"/";this.monitoring.trackRouteAccess({path:initialPath,meta:{name:"router-init"}},undefined,true);_logger.logger.info("路由管理器初始化完成")}async resolveInitialLazyRoutes(routes,resolveAll=false){if(typeof window==="undefined"){return}let targetRoutes=[];if(resolveAll){const stack=[...routes];while(stack.length>0){const current=stack.shift();if(!current){continue}targetRoutes.push(current);if(current.children&&current.children.length>0){stack.push(...current.children)}}}else{const matches=(0,_reactrouterdom.matchRoutes)(routes,window.location.pathname)??[];if(matches.length===0){return}targetRoutes=matches.map(match=>match.route)}await Promise.all(targetRoutes.map(async route=>{const lazy=route.lazy;if(typeof lazy!=="function"){return}try{const resolved=await lazy();Object.assign(route,resolved);delete route.lazy}catch(error){_logger.logger.warn("首屏路由懒加载预解析失败,回退到 Router 默认懒加载",error)}}))}getRouter(){return this.router}isInitialized(){return this.initialized}destroy(){this.pluginManager.executeHooks(_plugin.PluginLifecycleStage.DESTROY,{config:{}});this.preloader.stopPreload();this.router=null;this.initialized=false;const lifecycleManager=(0,_lifecycle.getRouterLifecycleManager)();lifecycleManager.clear();const middlewareManager=(0,_middleware.getRouterMiddlewareManager)();middlewareManager.clear();_logger.logger.info("路由管理器已销毁")}getCache(){return this.cache}getPreloader(){return this.preloader}getPluginManager(){return this.pluginManager}getMonitoring(){return this.monitoring}constructor(){_define_property(this,"router",null);_define_property(this,"initialized",false);_define_property(this,"cache",(0,_RouteCache.getRouteCache)());_define_property(this,"preloader",(0,_RoutePreloader.getRoutePreloader)());_define_property(this,"pluginManager",(0,_plugin.getRouterPluginManager)());_define_property(this,"monitoring",(0,_monitoring.getRouterMonitoring)());_define_property(this,"adapterManager",(0,_adapter.getAdapterManager)());this.adapterManager.register({name:"react-router",factory:(0,_reactrouter.createReactRouterAdapter)(),priority:10})}};_define_property(RouterManager,"instance",null);function getRouterManager(){return RouterManager.getInstance()}
@@ -0,0 +1,87 @@
1
+ import type { RouterConfig } from './types';
2
+ import { createBrowserRouter } from 'react-router-dom';
3
+ export declare class RouterManager {
4
+ private static instance;
5
+ /**
6
+ * 路由实例
7
+ * 只能在 initialize 方法中赋值
8
+ */
9
+ private router;
10
+ /**
11
+ * 是否已初始化
12
+ */
13
+ private initialized;
14
+ /**
15
+ * 路由缓存实例
16
+ */
17
+ private cache;
18
+ /**
19
+ * 路由预加载器实例
20
+ */
21
+ private preloader;
22
+ /**
23
+ * 路由插件管理器实例
24
+ */
25
+ private pluginManager;
26
+ /**
27
+ * 路由监控服务实例
28
+ */
29
+ private monitoring;
30
+ /**
31
+ * 路由适配器管理器实例
32
+ */
33
+ private adapterManager;
34
+ private constructor();
35
+ /**
36
+ * 获取单例实例
37
+ */
38
+ static getInstance(): RouterManager;
39
+ /**
40
+ * 初始化路由管理器
41
+ *
42
+ * @param config - 路由配置
43
+ * @param _appInstance - 应用实例(保留用于兼容性,当前未使用)
44
+ */
45
+ initialize(config: RouterConfig): Promise<void>;
46
+ /**
47
+ * 预解析 lazy 路由,避免首屏或重定向链路长时间停留在 hydrate fallback。
48
+ * resolveAll=true 时会在初始化阶段解析全部 lazy 路由。
49
+ */
50
+ private resolveInitialLazyRoutes;
51
+ /**
52
+ * 获取路由实例
53
+ *
54
+ * @returns 路由实例,如果未初始化则返回 null
55
+ */
56
+ getRouter(): ReturnType<typeof createBrowserRouter> | null;
57
+ /**
58
+ * 检查是否已初始化
59
+ *
60
+ * @returns 如果已初始化返回 true,否则返回 false
61
+ */
62
+ isInitialized(): boolean;
63
+ /**
64
+ * 销毁路由管理器
65
+ */
66
+ destroy(): void;
67
+ /**
68
+ * 获取路由缓存实例
69
+ */
70
+ getCache(): import("./performance").RouteCache;
71
+ /**
72
+ * 获取路由预加载器实例
73
+ */
74
+ getPreloader(): import("./performance").RoutePreloader;
75
+ /**
76
+ * 获取路由插件管理器实例
77
+ */
78
+ getPluginManager(): import("./plugin").RouterPluginManager;
79
+ /**
80
+ * 获取路由监控服务实例
81
+ */
82
+ getMonitoring(): import("./monitoring").RouterMonitoring;
83
+ }
84
+ /**
85
+ * 获取路由管理器
86
+ */
87
+ export declare function getRouterManager(): RouterManager;
@@ -0,0 +1 @@
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{logger}from"@vlian/logger";import{transformRoutes}from"./utils/transform";import{transformRoutesToReactRoutes}from"./utils/adapters/react-router/transform";import{createBrowserRouter,createHashRouter,createMemoryRouter,matchRoutes}from"react-router-dom";import{RouterConfigValidator}from"./validation";import{getRouterLifecycleManager}from"./lifecycle";import{getRouterMiddlewareManager}from"./middleware";import{RouterError,RouterErrorCode}from"./errors";import{getRouteCache}from"./performance/RouteCache";import{getRoutePreloader}from"./performance/RoutePreloader";import{getRouterPluginManager,PluginLifecycleStage}from"./plugin";import{getRouterMonitoring}from"./monitoring";import{getAdapterManager}from"./adapter";import{createReactRouterAdapter}from"./adapter/react-router";export class RouterManager{static getInstance(){if(!RouterManager.instance){RouterManager.instance=new RouterManager}return RouterManager.instance}async initialize(config){if(config.enabled===false||config.enabled==="disabled"){logger.info("路由系统已禁用");return}if(config.enableValidation!==false){try{RouterConfigValidator.validate(config);logger.debug("路由配置验证通过")}catch(error){logger.error("路由配置验证失败",error);if(process.env.NODE_ENV==="development"){throw error}}}await this.pluginManager.executeHooks(PluginLifecycleStage.BEFORE_INIT,{config});if(config.hooks){const lifecycleManager=getRouterLifecycleManager();lifecycleManager.register(config.hooks);logger.debug("路由生命周期钩子已注册")}if(!config.routes){throw new RouterError("路由配置不能为空",RouterErrorCode.ROUTER_CONFIG_ERROR)}this.preloader.updateConfig(config.preload);this.preloader.clear();let result;const cacheKey=config.routes;const cachedResult=this.cache.get(cacheKey);if(cachedResult){logger.debug("使用缓存的路由转换结果");result=cachedResult}else{await this.pluginManager.executeHooks(PluginLifecycleStage.BEFORE_TRANSFORM,{config});result=await transformRoutes(config.routes,config.transformOptions);await this.pluginManager.executeHooks(PluginLifecycleStage.AFTER_TRANSFORM,{config,routes:result.routes});this.cache.set(cacheKey,result)}const enableHydrateFallback=config.enableHydrateFallback??Boolean(config.options?.hydrationData);const reactRoutes=await transformRoutesToReactRoutes(result.routes,result,config.defaultRouteErrorComponent,config.defaultRouteLoadingComponent,enableHydrateFallback);if(result.routes){this.preloader.registerRoutes(result.routes,result);this.preloader.startPreload()}await this.resolveInitialLazyRoutes(reactRoutes,!enableHydrateFallback);let routerInstance=null;if(config.mode==="browser"){routerInstance=createBrowserRouter(reactRoutes,config.options)}else if(config.mode==="hash"){routerInstance=createHashRouter(reactRoutes,config.options)}else if(config.mode==="memory"){routerInstance=createMemoryRouter(reactRoutes,config.options)}if(!routerInstance){throw new RouterError("路由模式不支持",RouterErrorCode.ROUTER_CONFIG_ERROR,undefined,undefined,{mode:config.mode})}this.router=routerInstance;this.initialized=true;await this.pluginManager.executeHooks(PluginLifecycleStage.AFTER_INIT,{config,routes:result.routes});const initialPath=typeof window!=="undefined"?`${window.location.pathname}${window.location.search}${window.location.hash}`:this.router?.state?.location?.pathname??"/";this.monitoring.trackRouteAccess({path:initialPath,meta:{name:"router-init"}},undefined,true);logger.info("路由管理器初始化完成")}async resolveInitialLazyRoutes(routes,resolveAll=false){if(typeof window==="undefined"){return}let targetRoutes=[];if(resolveAll){const stack=[...routes];while(stack.length>0){const current=stack.shift();if(!current){continue}targetRoutes.push(current);if(current.children&&current.children.length>0){stack.push(...current.children)}}}else{const matches=matchRoutes(routes,window.location.pathname)??[];if(matches.length===0){return}targetRoutes=matches.map(match=>match.route)}await Promise.all(targetRoutes.map(async route=>{const lazy=route.lazy;if(typeof lazy!=="function"){return}try{const resolved=await lazy();Object.assign(route,resolved);delete route.lazy}catch(error){logger.warn("首屏路由懒加载预解析失败,回退到 Router 默认懒加载",error)}}))}getRouter(){return this.router}isInitialized(){return this.initialized}destroy(){this.pluginManager.executeHooks(PluginLifecycleStage.DESTROY,{config:{}});this.preloader.stopPreload();this.router=null;this.initialized=false;const lifecycleManager=getRouterLifecycleManager();lifecycleManager.clear();const middlewareManager=getRouterMiddlewareManager();middlewareManager.clear();logger.info("路由管理器已销毁")}getCache(){return this.cache}getPreloader(){return this.preloader}getPluginManager(){return this.pluginManager}getMonitoring(){return this.monitoring}constructor(){_define_property(this,"router",null);_define_property(this,"initialized",false);_define_property(this,"cache",getRouteCache());_define_property(this,"preloader",getRoutePreloader());_define_property(this,"pluginManager",getRouterPluginManager());_define_property(this,"monitoring",getRouterMonitoring());_define_property(this,"adapterManager",getAdapterManager());this.adapterManager.register({name:"react-router",factory:createReactRouterAdapter(),priority:10})}}_define_property(RouterManager,"instance",null);export function getRouterManager(){return RouterManager.getInstance()}