@omerdlw/base-framework 1.0.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 (383) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/dist/atoms/button.d.ts +11 -0
  4. package/dist/atoms/button.d.ts.map +1 -0
  5. package/dist/atoms/icon.d.ts +15 -0
  6. package/dist/atoms/icon.d.ts.map +1 -0
  7. package/dist/atoms/index.d.ts +6 -0
  8. package/dist/atoms/index.d.ts.map +1 -0
  9. package/dist/atoms/index.js +169 -0
  10. package/dist/atoms/index.js.map +1 -0
  11. package/dist/atoms/spinner.d.ts +9 -0
  12. package/dist/atoms/spinner.d.ts.map +1 -0
  13. package/dist/atoms/tooltip.d.ts +18 -0
  14. package/dist/atoms/tooltip.d.ts.map +1 -0
  15. package/dist/error/boundary.d.ts +14 -0
  16. package/dist/error/boundary.d.ts.map +1 -0
  17. package/dist/error/constants.d.ts +18 -0
  18. package/dist/error/constants.d.ts.map +1 -0
  19. package/dist/error/index.d.ts +9 -0
  20. package/dist/error/index.d.ts.map +1 -0
  21. package/dist/error/index.js +688 -0
  22. package/dist/error/index.js.map +1 -0
  23. package/dist/error/listener.d.ts +2 -0
  24. package/dist/error/listener.d.ts.map +1 -0
  25. package/dist/error/reporter.d.ts +32 -0
  26. package/dist/error/reporter.d.ts.map +1 -0
  27. package/dist/error/theme.d.ts +3 -0
  28. package/dist/error/theme.d.ts.map +1 -0
  29. package/dist/error/types.d.ts +91 -0
  30. package/dist/error/types.d.ts.map +1 -0
  31. package/dist/error/utils.d.ts +21 -0
  32. package/dist/error/utils.d.ts.map +1 -0
  33. package/dist/events.d.ts +51 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +88 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/hooks/index.d.ts +17 -0
  38. package/dist/hooks/index.d.ts.map +1 -0
  39. package/dist/hooks/index.js +804 -0
  40. package/dist/hooks/index.js.map +1 -0
  41. package/dist/hooks/types.d.ts +58 -0
  42. package/dist/hooks/types.d.ts.map +1 -0
  43. package/dist/hooks/use-async-action.d.ts +3 -0
  44. package/dist/hooks/use-async-action.d.ts.map +1 -0
  45. package/dist/hooks/use-click-outside.d.ts +3 -0
  46. package/dist/hooks/use-click-outside.d.ts.map +1 -0
  47. package/dist/hooks/use-controllable-state.d.ts +3 -0
  48. package/dist/hooks/use-controllable-state.d.ts.map +1 -0
  49. package/dist/hooks/use-debounce.d.ts +2 -0
  50. package/dist/hooks/use-debounce.d.ts.map +1 -0
  51. package/dist/hooks/use-fullscreen-state.d.ts +4 -0
  52. package/dist/hooks/use-fullscreen-state.d.ts.map +1 -0
  53. package/dist/hooks/use-global-event.d.ts +7 -0
  54. package/dist/hooks/use-global-event.d.ts.map +1 -0
  55. package/dist/hooks/use-hotkey.d.ts +4 -0
  56. package/dist/hooks/use-hotkey.d.ts.map +1 -0
  57. package/dist/hooks/use-intersection-observer.d.ts +4 -0
  58. package/dist/hooks/use-intersection-observer.d.ts.map +1 -0
  59. package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
  60. package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
  61. package/dist/hooks/use-media-query.d.ts +2 -0
  62. package/dist/hooks/use-media-query.d.ts.map +1 -0
  63. package/dist/hooks/use-mounted.d.ts +2 -0
  64. package/dist/hooks/use-mounted.d.ts.map +1 -0
  65. package/dist/hooks/use-required-context.d.ts +3 -0
  66. package/dist/hooks/use-required-context.d.ts.map +1 -0
  67. package/dist/hooks/use-server-action.d.ts +4 -0
  68. package/dist/hooks/use-server-action.d.ts.map +1 -0
  69. package/dist/hooks/use-storage-state.d.ts +5 -0
  70. package/dist/hooks/use-storage-state.d.ts.map +1 -0
  71. package/dist/hooks/use-store.d.ts +3 -0
  72. package/dist/hooks/use-store.d.ts.map +1 -0
  73. package/dist/index.d.ts +12 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +20415 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/kernel/adapters.d.ts +5 -0
  78. package/dist/kernel/adapters.d.ts.map +1 -0
  79. package/dist/kernel/compose.d.ts +15 -0
  80. package/dist/kernel/compose.d.ts.map +1 -0
  81. package/dist/kernel/constants.d.ts +12 -0
  82. package/dist/kernel/constants.d.ts.map +1 -0
  83. package/dist/kernel/context-registry.d.ts +3 -0
  84. package/dist/kernel/context-registry.d.ts.map +1 -0
  85. package/dist/kernel/handlers.d.ts +3 -0
  86. package/dist/kernel/handlers.d.ts.map +1 -0
  87. package/dist/kernel/hooks.d.ts +7 -0
  88. package/dist/kernel/hooks.d.ts.map +1 -0
  89. package/dist/kernel/index.d.ts +14 -0
  90. package/dist/kernel/index.d.ts.map +1 -0
  91. package/dist/kernel/index.js +2109 -0
  92. package/dist/kernel/index.js.map +1 -0
  93. package/dist/kernel/installed.d.ts +21 -0
  94. package/dist/kernel/installed.d.ts.map +1 -0
  95. package/dist/kernel/module.d.ts +32 -0
  96. package/dist/kernel/module.d.ts.map +1 -0
  97. package/dist/kernel/operations.d.ts +21 -0
  98. package/dist/kernel/operations.d.ts.map +1 -0
  99. package/dist/kernel/page-controller.d.ts +8 -0
  100. package/dist/kernel/page-controller.d.ts.map +1 -0
  101. package/dist/kernel/provider.d.ts +18 -0
  102. package/dist/kernel/provider.d.ts.map +1 -0
  103. package/dist/kernel/runtime.d.ts +30 -0
  104. package/dist/kernel/runtime.d.ts.map +1 -0
  105. package/dist/kernel/schema.d.ts +13 -0
  106. package/dist/kernel/schema.d.ts.map +1 -0
  107. package/dist/kernel/store.d.ts +4 -0
  108. package/dist/kernel/store.d.ts.map +1 -0
  109. package/dist/kernel/types.d.ts +233 -0
  110. package/dist/kernel/types.d.ts.map +1 -0
  111. package/dist/kernel/utils.d.ts +20 -0
  112. package/dist/kernel/utils.d.ts.map +1 -0
  113. package/dist/modules/ambient/constants.d.ts +23 -0
  114. package/dist/modules/ambient/constants.d.ts.map +1 -0
  115. package/dist/modules/ambient/context.d.ts +10 -0
  116. package/dist/modules/ambient/context.d.ts.map +1 -0
  117. package/dist/modules/ambient/index.d.ts +6 -0
  118. package/dist/modules/ambient/index.d.ts.map +1 -0
  119. package/dist/modules/ambient/index.js +896 -0
  120. package/dist/modules/ambient/index.js.map +1 -0
  121. package/dist/modules/ambient/module.d.ts +12 -0
  122. package/dist/modules/ambient/module.d.ts.map +1 -0
  123. package/dist/modules/ambient/types.d.ts +84 -0
  124. package/dist/modules/ambient/types.d.ts.map +1 -0
  125. package/dist/modules/ambient/utils.d.ts +18 -0
  126. package/dist/modules/ambient/utils.d.ts.map +1 -0
  127. package/dist/modules/background/constants.d.ts +12 -0
  128. package/dist/modules/background/constants.d.ts.map +1 -0
  129. package/dist/modules/background/context.d.ts +13 -0
  130. package/dist/modules/background/context.d.ts.map +1 -0
  131. package/dist/modules/background/hooks.d.ts +119 -0
  132. package/dist/modules/background/hooks.d.ts.map +1 -0
  133. package/dist/modules/background/index.d.ts +7 -0
  134. package/dist/modules/background/index.d.ts.map +1 -0
  135. package/dist/modules/background/index.js +3195 -0
  136. package/dist/modules/background/index.js.map +1 -0
  137. package/dist/modules/background/module.d.ts +14 -0
  138. package/dist/modules/background/module.d.ts.map +1 -0
  139. package/dist/modules/background/motion.d.ts +13 -0
  140. package/dist/modules/background/motion.d.ts.map +1 -0
  141. package/dist/modules/background/overlay.d.ts +49 -0
  142. package/dist/modules/background/overlay.d.ts.map +1 -0
  143. package/dist/modules/background/types.d.ts +153 -0
  144. package/dist/modules/background/types.d.ts.map +1 -0
  145. package/dist/modules/background/utils.d.ts +56 -0
  146. package/dist/modules/background/utils.d.ts.map +1 -0
  147. package/dist/modules/background/youtube/iframe.d.ts +52 -0
  148. package/dist/modules/background/youtube/iframe.d.ts.map +1 -0
  149. package/dist/modules/background/youtube/parse.d.ts +17 -0
  150. package/dist/modules/background/youtube/parse.d.ts.map +1 -0
  151. package/dist/modules/context-menu/constants.d.ts +8 -0
  152. package/dist/modules/context-menu/constants.d.ts.map +1 -0
  153. package/dist/modules/context-menu/context.d.ts +16 -0
  154. package/dist/modules/context-menu/context.d.ts.map +1 -0
  155. package/dist/modules/context-menu/hooks.d.ts +31 -0
  156. package/dist/modules/context-menu/hooks.d.ts.map +1 -0
  157. package/dist/modules/context-menu/index.d.ts +6 -0
  158. package/dist/modules/context-menu/index.d.ts.map +1 -0
  159. package/dist/modules/context-menu/index.js +2008 -0
  160. package/dist/modules/context-menu/index.js.map +1 -0
  161. package/dist/modules/context-menu/module.d.ts +12 -0
  162. package/dist/modules/context-menu/module.d.ts.map +1 -0
  163. package/dist/modules/context-menu/motion.d.ts +9 -0
  164. package/dist/modules/context-menu/motion.d.ts.map +1 -0
  165. package/dist/modules/context-menu/overlay.d.ts +15 -0
  166. package/dist/modules/context-menu/overlay.d.ts.map +1 -0
  167. package/dist/modules/context-menu/resolver.d.ts +7 -0
  168. package/dist/modules/context-menu/resolver.d.ts.map +1 -0
  169. package/dist/modules/context-menu/state.d.ts +4 -0
  170. package/dist/modules/context-menu/state.d.ts.map +1 -0
  171. package/dist/modules/context-menu/types.d.ts +171 -0
  172. package/dist/modules/context-menu/types.d.ts.map +1 -0
  173. package/dist/modules/context-menu/utils.d.ts +16 -0
  174. package/dist/modules/context-menu/utils.d.ts.map +1 -0
  175. package/dist/modules/controls/constants.d.ts +7 -0
  176. package/dist/modules/controls/constants.d.ts.map +1 -0
  177. package/dist/modules/controls/hooks.d.ts +15 -0
  178. package/dist/modules/controls/hooks.d.ts.map +1 -0
  179. package/dist/modules/controls/index.d.ts +6 -0
  180. package/dist/modules/controls/index.d.ts.map +1 -0
  181. package/dist/modules/controls/index.js +1242 -0
  182. package/dist/modules/controls/index.js.map +1 -0
  183. package/dist/modules/controls/module.d.ts +12 -0
  184. package/dist/modules/controls/module.d.ts.map +1 -0
  185. package/dist/modules/controls/overlay.d.ts +2 -0
  186. package/dist/modules/controls/overlay.d.ts.map +1 -0
  187. package/dist/modules/controls/types.d.ts +86 -0
  188. package/dist/modules/controls/types.d.ts.map +1 -0
  189. package/dist/modules/controls/utils.d.ts +9 -0
  190. package/dist/modules/controls/utils.d.ts.map +1 -0
  191. package/dist/modules/dock/cards.d.ts +1035 -0
  192. package/dist/modules/dock/cards.d.ts.map +1 -0
  193. package/dist/modules/dock/constants.d.ts +157 -0
  194. package/dist/modules/dock/constants.d.ts.map +1 -0
  195. package/dist/modules/dock/context.d.ts +26 -0
  196. package/dist/modules/dock/context.d.ts.map +1 -0
  197. package/dist/modules/dock/hooks.d.ts +957 -0
  198. package/dist/modules/dock/hooks.d.ts.map +1 -0
  199. package/dist/modules/dock/hud.d.ts +43 -0
  200. package/dist/modules/dock/hud.d.ts.map +1 -0
  201. package/dist/modules/dock/index.d.ts +27 -0
  202. package/dist/modules/dock/index.d.ts.map +1 -0
  203. package/dist/modules/dock/index.js +12111 -0
  204. package/dist/modules/dock/index.js.map +1 -0
  205. package/dist/modules/dock/module.d.ts +71 -0
  206. package/dist/modules/dock/module.d.ts.map +1 -0
  207. package/dist/modules/dock/motion.d.ts +986 -0
  208. package/dist/modules/dock/motion.d.ts.map +1 -0
  209. package/dist/modules/dock/overlay.d.ts +79 -0
  210. package/dist/modules/dock/overlay.d.ts.map +1 -0
  211. package/dist/modules/dock/provider.d.ts +3 -0
  212. package/dist/modules/dock/provider.d.ts.map +1 -0
  213. package/dist/modules/dock/routing/breadcrumbs.d.ts +43 -0
  214. package/dist/modules/dock/routing/breadcrumbs.d.ts.map +1 -0
  215. package/dist/modules/dock/routing/continuity.d.ts +19 -0
  216. package/dist/modules/dock/routing/continuity.d.ts.map +1 -0
  217. package/dist/modules/dock/routing/guards.d.ts +21 -0
  218. package/dist/modules/dock/routing/guards.d.ts.map +1 -0
  219. package/dist/modules/dock/routing/navigation.d.ts +37 -0
  220. package/dist/modules/dock/routing/navigation.d.ts.map +1 -0
  221. package/dist/modules/dock/routing/transactions.d.ts +21 -0
  222. package/dist/modules/dock/routing/transactions.d.ts.map +1 -0
  223. package/dist/modules/dock/runtime/commands.d.ts +18 -0
  224. package/dist/modules/dock/runtime/commands.d.ts.map +1 -0
  225. package/dist/modules/dock/runtime/display.d.ts +36 -0
  226. package/dist/modules/dock/runtime/display.d.ts.map +1 -0
  227. package/dist/modules/dock/runtime/dock.d.ts +123 -0
  228. package/dist/modules/dock/runtime/dock.d.ts.map +1 -0
  229. package/dist/modules/dock/state.d.ts +22 -0
  230. package/dist/modules/dock/state.d.ts.map +1 -0
  231. package/dist/modules/dock/status/events.d.ts +37 -0
  232. package/dist/modules/dock/status/events.d.ts.map +1 -0
  233. package/dist/modules/dock/status/hooks.d.ts +6 -0
  234. package/dist/modules/dock/status/hooks.d.ts.map +1 -0
  235. package/dist/modules/dock/status/model.d.ts +65 -0
  236. package/dist/modules/dock/status/model.d.ts.map +1 -0
  237. package/dist/modules/dock/surface/context.d.ts +43 -0
  238. package/dist/modules/dock/surface/context.d.ts.map +1 -0
  239. package/dist/modules/dock/surface/definition.d.ts +38 -0
  240. package/dist/modules/dock/surface/definition.d.ts.map +1 -0
  241. package/dist/modules/dock/surface/hooks.d.ts +123 -0
  242. package/dist/modules/dock/surface/hooks.d.ts.map +1 -0
  243. package/dist/modules/dock/surface/machine.d.ts +75 -0
  244. package/dist/modules/dock/surface/machine.d.ts.map +1 -0
  245. package/dist/modules/dock/surface/stack.d.ts +38 -0
  246. package/dist/modules/dock/surface/stack.d.ts.map +1 -0
  247. package/dist/modules/dock/surface/view-model.d.ts +3 -0
  248. package/dist/modules/dock/surface/view-model.d.ts.map +1 -0
  249. package/dist/modules/dock/types.d.ts +1158 -0
  250. package/dist/modules/dock/types.d.ts.map +1 -0
  251. package/dist/modules/dock/utils.d.ts +93 -0
  252. package/dist/modules/dock/utils.d.ts.map +1 -0
  253. package/dist/modules/index.d.ts +12 -0
  254. package/dist/modules/index.d.ts.map +1 -0
  255. package/dist/modules/index.js +18020 -0
  256. package/dist/modules/index.js.map +1 -0
  257. package/dist/modules/loading/constants.d.ts +5 -0
  258. package/dist/modules/loading/constants.d.ts.map +1 -0
  259. package/dist/modules/loading/context.d.ts +13 -0
  260. package/dist/modules/loading/context.d.ts.map +1 -0
  261. package/dist/modules/loading/hooks.d.ts +6 -0
  262. package/dist/modules/loading/hooks.d.ts.map +1 -0
  263. package/dist/modules/loading/index.d.ts +7 -0
  264. package/dist/modules/loading/index.d.ts.map +1 -0
  265. package/dist/modules/loading/index.js +1256 -0
  266. package/dist/modules/loading/index.js.map +1 -0
  267. package/dist/modules/loading/module.d.ts +14 -0
  268. package/dist/modules/loading/module.d.ts.map +1 -0
  269. package/dist/modules/loading/overlay.d.ts +2 -0
  270. package/dist/modules/loading/overlay.d.ts.map +1 -0
  271. package/dist/modules/loading/types.d.ts +47 -0
  272. package/dist/modules/loading/types.d.ts.map +1 -0
  273. package/dist/modules/loading/utils.d.ts +4 -0
  274. package/dist/modules/loading/utils.d.ts.map +1 -0
  275. package/dist/modules/media/constants.d.ts +7 -0
  276. package/dist/modules/media/constants.d.ts.map +1 -0
  277. package/dist/modules/media/context.d.ts +6 -0
  278. package/dist/modules/media/context.d.ts.map +1 -0
  279. package/dist/modules/media/hooks.d.ts +3 -0
  280. package/dist/modules/media/hooks.d.ts.map +1 -0
  281. package/dist/modules/media/index.d.ts +8 -0
  282. package/dist/modules/media/index.d.ts.map +1 -0
  283. package/dist/modules/media/index.js +728 -0
  284. package/dist/modules/media/index.js.map +1 -0
  285. package/dist/modules/media/module.d.ts +11 -0
  286. package/dist/modules/media/module.d.ts.map +1 -0
  287. package/dist/modules/media/overlay.d.ts +9 -0
  288. package/dist/modules/media/overlay.d.ts.map +1 -0
  289. package/dist/modules/media/types.d.ts +77 -0
  290. package/dist/modules/media/types.d.ts.map +1 -0
  291. package/dist/modules/media/utils.d.ts +17 -0
  292. package/dist/modules/media/utils.d.ts.map +1 -0
  293. package/dist/modules/modal/constants.d.ts +20 -0
  294. package/dist/modules/modal/constants.d.ts.map +1 -0
  295. package/dist/modules/modal/context.d.ts +20 -0
  296. package/dist/modules/modal/context.d.ts.map +1 -0
  297. package/dist/modules/modal/hooks.d.ts +41 -0
  298. package/dist/modules/modal/hooks.d.ts.map +1 -0
  299. package/dist/modules/modal/index.d.ts +7 -0
  300. package/dist/modules/modal/index.d.ts.map +1 -0
  301. package/dist/modules/modal/index.js +2672 -0
  302. package/dist/modules/modal/index.js.map +1 -0
  303. package/dist/modules/modal/module.d.ts +12 -0
  304. package/dist/modules/modal/module.d.ts.map +1 -0
  305. package/dist/modules/modal/motion.d.ts +16 -0
  306. package/dist/modules/modal/motion.d.ts.map +1 -0
  307. package/dist/modules/modal/overlay.d.ts +4 -0
  308. package/dist/modules/modal/overlay.d.ts.map +1 -0
  309. package/dist/modules/modal/state.d.ts +4 -0
  310. package/dist/modules/modal/state.d.ts.map +1 -0
  311. package/dist/modules/modal/types.d.ts +109 -0
  312. package/dist/modules/modal/types.d.ts.map +1 -0
  313. package/dist/modules/modal/utils.d.ts +31 -0
  314. package/dist/modules/modal/utils.d.ts.map +1 -0
  315. package/dist/modules/notification/constants.d.ts +9 -0
  316. package/dist/modules/notification/constants.d.ts.map +1 -0
  317. package/dist/modules/notification/context.d.ts +7 -0
  318. package/dist/modules/notification/context.d.ts.map +1 -0
  319. package/dist/modules/notification/hooks.d.ts +10 -0
  320. package/dist/modules/notification/hooks.d.ts.map +1 -0
  321. package/dist/modules/notification/index.d.ts +7 -0
  322. package/dist/modules/notification/index.d.ts.map +1 -0
  323. package/dist/modules/notification/index.js +905 -0
  324. package/dist/modules/notification/index.js.map +1 -0
  325. package/dist/modules/notification/module.d.ts +11 -0
  326. package/dist/modules/notification/module.d.ts.map +1 -0
  327. package/dist/modules/notification/motion.d.ts +15 -0
  328. package/dist/modules/notification/motion.d.ts.map +1 -0
  329. package/dist/modules/notification/overlay.d.ts +3 -0
  330. package/dist/modules/notification/overlay.d.ts.map +1 -0
  331. package/dist/modules/notification/types.d.ts +57 -0
  332. package/dist/modules/notification/types.d.ts.map +1 -0
  333. package/dist/modules/notification/utils.d.ts +9 -0
  334. package/dist/modules/notification/utils.d.ts.map +1 -0
  335. package/dist/modules/theme.d.ts +3 -0
  336. package/dist/modules/theme.d.ts.map +1 -0
  337. package/dist/provider.d.ts +23 -0
  338. package/dist/provider.d.ts.map +1 -0
  339. package/dist/provider.js +1973 -0
  340. package/dist/provider.js.map +1 -0
  341. package/dist/result.d.ts +50 -0
  342. package/dist/result.d.ts.map +1 -0
  343. package/dist/result.js +163 -0
  344. package/dist/result.js.map +1 -0
  345. package/dist/theme.d.ts +25 -0
  346. package/dist/theme.d.ts.map +1 -0
  347. package/dist/theme.js +44 -0
  348. package/dist/theme.js.map +1 -0
  349. package/dist/tokens/index.d.ts +3 -0
  350. package/dist/tokens/index.d.ts.map +1 -0
  351. package/dist/tokens/index.js +325 -0
  352. package/dist/tokens/index.js.map +1 -0
  353. package/dist/tokens/motion.d.ts +315 -0
  354. package/dist/tokens/motion.d.ts.map +1 -0
  355. package/dist/tokens/tokens.d.ts +34 -0
  356. package/dist/tokens/tokens.d.ts.map +1 -0
  357. package/dist/utils/cn.d.ts +3 -0
  358. package/dist/utils/cn.d.ts.map +1 -0
  359. package/dist/utils/dom.d.ts +5 -0
  360. package/dist/utils/dom.d.ts.map +1 -0
  361. package/dist/utils/index.d.ts +16 -0
  362. package/dist/utils/index.d.ts.map +1 -0
  363. package/dist/utils/index.js +485 -0
  364. package/dist/utils/index.js.map +1 -0
  365. package/dist/utils/json.d.ts +3 -0
  366. package/dist/utils/json.d.ts.map +1 -0
  367. package/dist/utils/number.d.ts +4 -0
  368. package/dist/utils/number.d.ts.map +1 -0
  369. package/dist/utils/object.d.ts +7 -0
  370. package/dist/utils/object.d.ts.map +1 -0
  371. package/dist/utils/report.d.ts +5 -0
  372. package/dist/utils/report.d.ts.map +1 -0
  373. package/dist/utils/scheduler.d.ts +34 -0
  374. package/dist/utils/scheduler.d.ts.map +1 -0
  375. package/dist/utils/store.d.ts +11 -0
  376. package/dist/utils/store.d.ts.map +1 -0
  377. package/dist/utils/string.d.ts +8 -0
  378. package/dist/utils/string.d.ts.map +1 -0
  379. package/dist/utils/timing.d.ts +8 -0
  380. package/dist/utils/timing.d.ts.map +1 -0
  381. package/dist/utils/user-message.d.ts +20 -0
  382. package/dist/utils/user-message.d.ts.map +1 -0
  383. package/package.json +113 -0
@@ -0,0 +1,2109 @@
1
+ "use client";
2
+ import 'clsx';
3
+ import 'tailwind-merge';
4
+ import { createContext, useState, useMemo, useCallback, useSyncExternalStore, use, useId, useRef, useEffect, createElement, Fragment as Fragment$1, useLayoutEffect, isValidElement, cloneElement, Children } from 'react';
5
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
+ import { usePathname } from 'next/navigation';
7
+
8
+ // src/kernel/constants.ts
9
+ var DEFAULT_SOURCE = "dynamic";
10
+ var REGISTRY_SOURCES = Object.freeze({
11
+ STATIC: "static",
12
+ DYNAMIC: "dynamic",
13
+ USER: "user"
14
+ });
15
+ var REGISTRY_LIFECYCLES = Object.freeze({
16
+ IMMEDIATE: "immediate",
17
+ GRACEFUL: "graceful",
18
+ PERSISTENT: "persistent",
19
+ ROUTE: "route"
20
+ });
21
+ var REGISTRY_VALIDATION_MODES = Object.freeze({
22
+ WARN: "warn",
23
+ STRICT: "strict"
24
+ });
25
+ var REGISTRY_METADATA_KEYS = Object.freeze([
26
+ "cleanup",
27
+ "cleanupDelayMs",
28
+ "instanceId",
29
+ "lifecycle",
30
+ "priority",
31
+ "source",
32
+ "scope",
33
+ "validation"
34
+ ]);
35
+ var REGISTRY_SOURCE_PRIORITY = Object.freeze({
36
+ [REGISTRY_SOURCES.STATIC]: 100,
37
+ [REGISTRY_SOURCES.DYNAMIC]: 200,
38
+ [REGISTRY_SOURCES.USER]: 300
39
+ });
40
+ var REGISTRY_SOURCE_RANK = Object.freeze({
41
+ [REGISTRY_SOURCES.STATIC]: 10,
42
+ [REGISTRY_SOURCES.DYNAMIC]: 20,
43
+ [REGISTRY_SOURCES.USER]: 30
44
+ });
45
+ var REGISTRY_LIFECYCLE_VALUES = new Set(
46
+ Object.values(REGISTRY_LIFECYCLES)
47
+ );
48
+ var REGISTRY_METADATA_KEY_SET = new Set(
49
+ REGISTRY_METADATA_KEYS
50
+ );
51
+ var REGISTRY_SCOPE_KINDS = Object.freeze({
52
+ APP: "app",
53
+ SESSION: "session",
54
+ ROUTE: "route",
55
+ INSTANCE: "instance",
56
+ WORKSPACE: "workspace"
57
+ });
58
+ var DEFAULT_REGISTRY_SCOPE = REGISTRY_SCOPE_KINDS.APP;
59
+
60
+ // src/utils/string.ts
61
+ function trimToNull(value) {
62
+ if (value === null || value === void 0) return null;
63
+ const trimmed = String(value).trim();
64
+ return trimmed.length > 0 ? trimmed : null;
65
+ }
66
+
67
+ // src/utils/dom.ts
68
+ var isBrowser = typeof window !== "undefined";
69
+
70
+ // src/utils/object.ts
71
+ function isObject(value) {
72
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
73
+ }
74
+ function isPlainObject(value) {
75
+ if (!isObject(value)) return false;
76
+ const proto = Object.getPrototypeOf(value);
77
+ return proto === Object.prototype || proto === null;
78
+ }
79
+ function shallowEqual(a, b) {
80
+ if (Object.is(a, b)) return true;
81
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
82
+ return false;
83
+ }
84
+ const keysA = Object.keys(a);
85
+ const keysB = Object.keys(b);
86
+ if (keysA.length !== keysB.length) return false;
87
+ for (const key of keysA) {
88
+ if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(
89
+ a[key],
90
+ b[key]
91
+ )) {
92
+ return false;
93
+ }
94
+ }
95
+ return true;
96
+ }
97
+ function report(scope, error, level = "error") {
98
+ if (process.env.NODE_ENV === "production" && typeof window !== "undefined") {
99
+ return;
100
+ }
101
+ console[level](`[${scope}]`, error);
102
+ }
103
+
104
+ // src/utils/store.ts
105
+ function freezeStoreSnapshot(state) {
106
+ if (process.env.NODE_ENV === "production" || !state || typeof state !== "object") {
107
+ return state;
108
+ }
109
+ const seen = /* @__PURE__ */ new WeakSet();
110
+ const freeze = (value) => {
111
+ if (seen.has(value) || Object.isFrozen(value)) return;
112
+ seen.add(value);
113
+ const prototype = Object.getPrototypeOf(value);
114
+ if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {
115
+ for (const key of Reflect.ownKeys(value)) {
116
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
117
+ if (descriptor && "value" in descriptor && descriptor.value !== null) {
118
+ if (typeof descriptor.value === "object") freeze(descriptor.value);
119
+ }
120
+ }
121
+ }
122
+ Object.freeze(value);
123
+ };
124
+ freeze(state);
125
+ return state;
126
+ }
127
+ function createStore(initialState, { freezeSnapshots = true } = {}) {
128
+ const listeners = /* @__PURE__ */ new Set();
129
+ const prepare = freezeSnapshots ? freezeStoreSnapshot : (state) => state;
130
+ let snapshot = prepare(initialState);
131
+ const publish = (nextStateOrUpdater) => {
132
+ const nextState = typeof nextStateOrUpdater === "function" ? nextStateOrUpdater(snapshot) : nextStateOrUpdater;
133
+ if (Object.is(snapshot, nextState)) return false;
134
+ snapshot = prepare(nextState);
135
+ for (const listener of listeners) {
136
+ try {
137
+ listener();
138
+ } catch (error) {
139
+ report("CoreStore subscriber", error, "warn");
140
+ }
141
+ }
142
+ return true;
143
+ };
144
+ const setState = (updater) => {
145
+ if (typeof updater === "function") {
146
+ return publish(updater);
147
+ }
148
+ if (snapshot && typeof snapshot === "object" && updater && typeof updater === "object") {
149
+ return publish({ ...snapshot, ...updater });
150
+ }
151
+ return publish(updater);
152
+ };
153
+ return Object.freeze({
154
+ getSnapshot() {
155
+ return snapshot;
156
+ },
157
+ publish,
158
+ setState,
159
+ subscribe(listener) {
160
+ if (typeof listener !== "function") return () => {
161
+ };
162
+ listeners.add(listener);
163
+ return () => listeners.delete(listener);
164
+ }
165
+ });
166
+ }
167
+
168
+ // src/kernel/utils.ts
169
+ function hasOwnProperty(target, key) {
170
+ return Object.prototype.hasOwnProperty.call(target, key);
171
+ }
172
+ function parseFiniteNumber(value) {
173
+ const parsed = Number(value);
174
+ return Number.isFinite(parsed) ? parsed : null;
175
+ }
176
+ function getValidString(value, fallback = null) {
177
+ return trimToNull(value) ?? fallback;
178
+ }
179
+ function resolveInstanceId(value) {
180
+ return isObject(value) && typeof value.instanceId === "string" ? value.instanceId : null;
181
+ }
182
+ function getSourceRank(source) {
183
+ return REGISTRY_SOURCE_RANK[source] ?? 0;
184
+ }
185
+ function resolveRegisterInput(sourceOrOptions, optionsArg) {
186
+ if (typeof sourceOrOptions === "string") {
187
+ return {
188
+ source: sourceOrOptions,
189
+ options: isObject(optionsArg) ? optionsArg : {}
190
+ };
191
+ }
192
+ if (isObject(sourceOrOptions)) {
193
+ return {
194
+ source: typeof sourceOrOptions.source === "string" ? sourceOrOptions.source : DEFAULT_SOURCE,
195
+ options: sourceOrOptions
196
+ };
197
+ }
198
+ return {
199
+ source: DEFAULT_SOURCE,
200
+ options: isObject(optionsArg) ? optionsArg : {}
201
+ };
202
+ }
203
+ function resolveScope(options) {
204
+ return typeof options?.scope === "string" && options.scope.trim() ? options.scope.trim() : DEFAULT_REGISTRY_SCOPE;
205
+ }
206
+ function resolveUnregisterInput(sourceOrOptions) {
207
+ if (typeof sourceOrOptions === "string") {
208
+ return { instanceId: null, scope: null, source: sourceOrOptions };
209
+ }
210
+ if (isObject(sourceOrOptions)) {
211
+ return {
212
+ instanceId: resolveInstanceId(sourceOrOptions),
213
+ scope: typeof sourceOrOptions.scope === "string" && sourceOrOptions.scope.trim() ? sourceOrOptions.scope.trim() : null,
214
+ source: typeof sourceOrOptions.source === "string" ? sourceOrOptions.source : DEFAULT_SOURCE
215
+ };
216
+ }
217
+ return { instanceId: null, scope: null, source: DEFAULT_SOURCE };
218
+ }
219
+ function mergeModuleConfigs(base, patch) {
220
+ const source = base;
221
+ const changes = patch;
222
+ const result = { ...source };
223
+ Object.keys(changes).forEach((key) => {
224
+ const baseVal = source[key];
225
+ const patchVal = changes[key];
226
+ if (baseVal && typeof baseVal === "object" && !Array.isArray(baseVal) && patchVal && typeof patchVal === "object" && !Array.isArray(patchVal)) {
227
+ result[key] = { ...baseVal, ...patchVal };
228
+ } else {
229
+ result[key] = patchVal;
230
+ }
231
+ });
232
+ return result;
233
+ }
234
+
235
+ // src/kernel/schema.ts
236
+ function resolveLifecycle(metadata, fallback) {
237
+ const lifecycle = metadata?.lifecycle ?? metadata?.cleanup;
238
+ return lifecycle && REGISTRY_LIFECYCLE_VALUES.has(lifecycle) ? lifecycle : fallback;
239
+ }
240
+ function validateRegistryMetadata(metadata) {
241
+ if (metadata === void 0 || metadata === null)
242
+ return { issues: [], valid: true };
243
+ if (!isObject(metadata))
244
+ return { issues: ["registry metadata must be an object"], valid: false };
245
+ const issues = [];
246
+ Object.keys(metadata).forEach((key) => {
247
+ if (!REGISTRY_METADATA_KEY_SET.has(key))
248
+ issues.push(`unknown registry metadata field: ${key}`);
249
+ });
250
+ if (metadata.source !== void 0 && !getValidString(metadata.source))
251
+ issues.push("source must be a non-empty string");
252
+ if (metadata.instanceId !== void 0 && !getValidString(metadata.instanceId))
253
+ issues.push("instanceId must be a non-empty string");
254
+ if (metadata.scope !== void 0 && !getValidString(metadata.scope))
255
+ issues.push("scope must be a non-empty string");
256
+ if (metadata.priority !== void 0 && parseFiniteNumber(metadata.priority) === null)
257
+ issues.push("priority must be a finite number");
258
+ if (metadata.cleanupDelayMs !== void 0) {
259
+ const delay = parseFiniteNumber(metadata.cleanupDelayMs);
260
+ if (delay === null || delay < 0)
261
+ issues.push("cleanupDelayMs must be a non-negative finite number");
262
+ }
263
+ const lifecycle = metadata.lifecycle ?? metadata.cleanup;
264
+ if (lifecycle !== void 0 && !REGISTRY_LIFECYCLE_VALUES.has(String(lifecycle))) {
265
+ issues.push(
266
+ `lifecycle must be one of: ${[...REGISTRY_LIFECYCLE_VALUES].join(", ")}`
267
+ );
268
+ }
269
+ if (metadata.validation !== void 0 && !Object.values(REGISTRY_VALIDATION_MODES).includes(
270
+ metadata.validation
271
+ )) {
272
+ issues.push(
273
+ `validation must be one of: ${Object.values(REGISTRY_VALIDATION_MODES).join(", ")}`
274
+ );
275
+ }
276
+ return { issues, valid: issues.length === 0 };
277
+ }
278
+ function validateRegistryKey(type, key, definitions) {
279
+ const definition = definitions.get(type);
280
+ const issues = [];
281
+ if (!definition) issues.push(`unknown registry type: ${String(type)}`);
282
+ if (!getValidString(key))
283
+ return {
284
+ issues: [...issues, "key must be a non-empty string"],
285
+ valid: false
286
+ };
287
+ const normalizedKey = String(key).trim();
288
+ if (definition?.keyPolicy === "singleton") {
289
+ const expectedKey = definition.singletonKey;
290
+ if (expectedKey && normalizedKey !== expectedKey)
291
+ issues.push(`${type} key must be ${expectedKey}`);
292
+ } else if (definition?.keyPolicy === "path") {
293
+ if (!normalizedKey.startsWith("/"))
294
+ issues.push(`${type} key must be an absolute path`);
295
+ } else if (definition?.keyPolicy === "route") {
296
+ if (!normalizedKey.startsWith("/") && !definition.reservedKeys?.includes(normalizedKey)) {
297
+ issues.push(`${type} key must be a route path or a reserved route key`);
298
+ }
299
+ }
300
+ return { issues, valid: issues.length === 0 };
301
+ }
302
+ function validateRegistryValue(type, key, value, definitions) {
303
+ const definition = definitions.get(type);
304
+ const issues = [...validateRegistryKey(type, key, definitions).issues];
305
+ const valueKind = definition?.valueKind ?? "object";
306
+ if (definition && valueKind === "object" && !isPlainObject(value)) {
307
+ issues.push(`${type} values must be plain objects`);
308
+ }
309
+ if (definition && valueKind === "component" && typeof value !== "function" && !isPlainObject(value)) {
310
+ issues.push(
311
+ `${type} values must be component functions or component objects`
312
+ );
313
+ }
314
+ const validation = definition?.validate?.(value);
315
+ if (validation && !validation.valid && Array.isArray(validation.issues)) {
316
+ issues.push(...validation.issues);
317
+ }
318
+ return { issues, valid: issues.length === 0 };
319
+ }
320
+ function normalizeRegistryMetadata(metadata, {
321
+ defaultCleanupDelayMs = null,
322
+ defaultLifecycle = null,
323
+ defaultSource = DEFAULT_SOURCE
324
+ } = {}) {
325
+ const registryMeta = isObject(metadata) ? metadata : {};
326
+ const normalizedDefaultDelay = parseFiniteNumber(defaultCleanupDelayMs);
327
+ const fallbackCleanupDelayMs = normalizedDefaultDelay !== null && normalizedDefaultDelay >= 0 ? normalizedDefaultDelay : null;
328
+ const fallbackLifecycle = defaultLifecycle && REGISTRY_LIFECYCLE_VALUES.has(defaultLifecycle) ? defaultLifecycle : null;
329
+ const source = getValidString(registryMeta.source) || getValidString(defaultSource, DEFAULT_SOURCE) || DEFAULT_SOURCE;
330
+ const scope = getValidString(registryMeta.scope);
331
+ const priority = parseFiniteNumber(registryMeta.priority);
332
+ const lifecycle = resolveLifecycle(registryMeta, fallbackLifecycle);
333
+ const validation = isValidationMode(registryMeta.validation) ? registryMeta.validation : null;
334
+ const cleanupDelayCandidate = parseFiniteNumber(registryMeta.cleanupDelayMs);
335
+ let cleanupDelayMs = cleanupDelayCandidate !== null && cleanupDelayCandidate >= 0 ? cleanupDelayCandidate : fallbackCleanupDelayMs;
336
+ if (lifecycle === REGISTRY_LIFECYCLES.IMMEDIATE) {
337
+ cleanupDelayMs = 0;
338
+ } else if ((lifecycle === REGISTRY_LIFECYCLES.GRACEFUL || lifecycle === REGISTRY_LIFECYCLES.ROUTE) && cleanupDelayMs === null) {
339
+ cleanupDelayMs = fallbackCleanupDelayMs;
340
+ }
341
+ return {
342
+ cleanupDelayMs,
343
+ lifecycle,
344
+ priority,
345
+ registerOptions: {
346
+ ...priority !== null && { priority },
347
+ ...validation === REGISTRY_VALIDATION_MODES.STRICT && { validation },
348
+ ...scope && { scope }
349
+ },
350
+ source,
351
+ ...scope && { scope },
352
+ ...validation && { validation }
353
+ };
354
+ }
355
+ function isValidationMode(value) {
356
+ return Object.values(REGISTRY_VALIDATION_MODES).includes(value);
357
+ }
358
+ function pickRegistryMetadata(options) {
359
+ if (!isObject(options)) return {};
360
+ return Object.fromEntries(
361
+ REGISTRY_METADATA_KEYS.filter((key) => options[key] !== void 0).map(
362
+ (key) => [key, options[key]]
363
+ )
364
+ );
365
+ }
366
+
367
+ // src/kernel/operations.ts
368
+ function createInitialRegistriesFor(definitions) {
369
+ return Object.fromEntries(
370
+ Array.from(definitions.keys(), (type) => [type, {}])
371
+ );
372
+ }
373
+ function buildSourceRecord({
374
+ source,
375
+ value,
376
+ instanceId = null,
377
+ priority,
378
+ timestamp,
379
+ sequence,
380
+ scope = DEFAULT_REGISTRY_SCOPE
381
+ }) {
382
+ return {
383
+ updatedAt: timestamp,
384
+ sequence: Number.isFinite(sequence) ? sequence : timestamp,
385
+ instanceId: typeof instanceId === "string" ? instanceId : null,
386
+ priority,
387
+ value,
388
+ source,
389
+ scope
390
+ };
391
+ }
392
+ function createRecordKey(source, instanceId = null, scope = DEFAULT_REGISTRY_SCOPE) {
393
+ if (scope === DEFAULT_REGISTRY_SCOPE) {
394
+ if (typeof instanceId === "string" && instanceId.length > 0) {
395
+ return `instance:${JSON.stringify([source, instanceId])}`;
396
+ }
397
+ return `source:${JSON.stringify(source)}`;
398
+ }
399
+ if (typeof instanceId === "string" && instanceId.length > 0) {
400
+ return `instance:${JSON.stringify([scope, source, instanceId])}`;
401
+ }
402
+ return `source:${JSON.stringify([scope, source])}`;
403
+ }
404
+ function getSourceRecords(entry, source, scope = null) {
405
+ if (!entry) return [];
406
+ return Object.entries(entry).map(([recordKey, rawRecord]) => ({
407
+ recordKey,
408
+ record: toSourceRecord(rawRecord, recordKey)
409
+ })).filter(
410
+ ({ record }) => record?.source === source && (scope === null || record.scope === scope)
411
+ );
412
+ }
413
+ function getSourceRecord(entry, source, instanceId = null, scope = DEFAULT_REGISTRY_SCOPE) {
414
+ const recordKey = createRecordKey(source, instanceId, scope);
415
+ return toSourceRecord(entry?.[recordKey], source);
416
+ }
417
+ function resolveRecordPriority(options, source) {
418
+ if (isObject(options) && hasOwnProperty(options, "priority")) {
419
+ const parsedPriority = Number(options.priority);
420
+ if (Number.isFinite(parsedPriority)) return parsedPriority;
421
+ }
422
+ return REGISTRY_SOURCE_PRIORITY[source] ?? 0;
423
+ }
424
+ function toSourceRecord(rawValue, source = DEFAULT_SOURCE) {
425
+ if (rawValue === void 0) return null;
426
+ const rawRecord = rawValue;
427
+ const isWrappedRecord = isObject(rawValue) && hasOwnProperty(rawRecord, "value") && hasOwnProperty(rawRecord, "updatedAt") && hasOwnProperty(rawRecord, "priority") && hasOwnProperty(rawRecord, "source");
428
+ if (isWrappedRecord) {
429
+ const parsedPriority = Number(rawRecord.priority);
430
+ return {
431
+ updatedAt: Number(rawRecord.updatedAt) || 0,
432
+ sequence: Number(rawRecord.sequence) || Number(rawRecord.updatedAt) || 0,
433
+ instanceId: typeof rawRecord.instanceId === "string" ? rawRecord.instanceId : null,
434
+ priority: Number.isFinite(parsedPriority) ? parsedPriority : REGISTRY_SOURCE_PRIORITY[source] ?? 0,
435
+ source: typeof rawRecord.source === "string" ? rawRecord.source : source,
436
+ scope: typeof rawRecord.scope === "string" ? rawRecord.scope : DEFAULT_REGISTRY_SCOPE,
437
+ value: rawRecord.value
438
+ };
439
+ }
440
+ return {
441
+ updatedAt: 0,
442
+ sequence: 0,
443
+ instanceId: null,
444
+ priority: REGISTRY_SOURCE_PRIORITY[source] ?? 0,
445
+ source,
446
+ scope: DEFAULT_REGISTRY_SCOPE,
447
+ value: rawValue
448
+ };
449
+ }
450
+ function compareRecords(a, b) {
451
+ if (a.priority !== b.priority) return a.priority - b.priority;
452
+ const rankDiff = getSourceRank(a.source) - getSourceRank(b.source);
453
+ if (rankDiff !== 0) return rankDiff;
454
+ return (a.sequence ?? a.updatedAt) - (b.sequence ?? b.updatedAt);
455
+ }
456
+ function recordsHaveSameValue(prevRecord, nextRecord) {
457
+ if (Object.is(prevRecord?.value, nextRecord?.value)) return true;
458
+ if (isObject(prevRecord?.value) && isObject(nextRecord?.value)) {
459
+ return shallowEqual(prevRecord.value, nextRecord.value);
460
+ }
461
+ return false;
462
+ }
463
+ function hasRecordChanged(prevRecord, nextRecord) {
464
+ if (!prevRecord) return true;
465
+ return prevRecord.priority !== nextRecord.priority || prevRecord.source !== nextRecord.source || prevRecord.instanceId !== nextRecord.instanceId || prevRecord.scope !== nextRecord.scope || !recordsHaveSameValue(prevRecord, nextRecord);
466
+ }
467
+ function hasAnySourceRecord(entry) {
468
+ return Object.values(entry || {}).some(
469
+ (rawRecord) => rawRecord !== void 0
470
+ );
471
+ }
472
+ function setSourceRecord(state, type, key, source, record) {
473
+ const typeRegistry = state[type] || {};
474
+ const currentEntry = typeRegistry[key] || {};
475
+ const recordKey = createRecordKey(source, record.instanceId, record.scope);
476
+ const prevRecord = toSourceRecord(currentEntry[recordKey], source);
477
+ if (!hasRecordChanged(prevRecord, record)) {
478
+ return state;
479
+ }
480
+ return {
481
+ ...state,
482
+ [type]: {
483
+ ...typeRegistry,
484
+ [key]: {
485
+ ...currentEntry,
486
+ [recordKey]: record
487
+ }
488
+ }
489
+ };
490
+ }
491
+ function removeSourceRecord(state, type, key, source, instanceId = null, scope = null) {
492
+ const typeRegistry = state[type];
493
+ const currentEntry = typeRegistry?.[key];
494
+ if (!typeRegistry || !currentEntry) return state;
495
+ let activeRecords = [];
496
+ if (typeof instanceId === "string" && instanceId.length > 0 && scope !== null) {
497
+ const safeScope = scope || DEFAULT_REGISTRY_SCOPE;
498
+ const recordKey = createRecordKey(source, instanceId, safeScope);
499
+ const record = getSourceRecord(currentEntry, source, instanceId, safeScope);
500
+ if (record) activeRecords.push({ recordKey, record });
501
+ } else {
502
+ activeRecords = getSourceRecords(currentEntry, source, scope).filter(({ record }) => !instanceId || record?.instanceId === instanceId).filter(
503
+ (entry) => Boolean(entry.record)
504
+ );
505
+ }
506
+ if (activeRecords.length === 0) return state;
507
+ const nextEntry = { ...currentEntry };
508
+ activeRecords.forEach(({ recordKey }) => {
509
+ delete nextEntry[recordKey];
510
+ });
511
+ if (!hasAnySourceRecord(nextEntry)) {
512
+ const nextTypeRegistry = { ...typeRegistry };
513
+ delete nextTypeRegistry[key];
514
+ return { ...state, [type]: nextTypeRegistry };
515
+ }
516
+ return {
517
+ ...state,
518
+ [type]: { ...typeRegistry, [key]: nextEntry }
519
+ };
520
+ }
521
+ function resolveEntryValueFor(definitions, type, entry, scope = null) {
522
+ if (!entry) return void 0;
523
+ const activeRecords = Object.entries(entry).map(([source, rawRecord]) => toSourceRecord(rawRecord, source)).filter(
524
+ (record) => record !== null && (scope === null || record.scope === scope)
525
+ );
526
+ if (activeRecords.length === 0) return void 0;
527
+ const merge = definitions.get(type)?.merge;
528
+ if (merge) {
529
+ const sortedRecords = [...activeRecords].sort(compareRecords);
530
+ const mergeCandidate = sortedRecords.every(
531
+ (record) => isObject(record.value)
532
+ );
533
+ if (mergeCandidate) {
534
+ const values = sortedRecords.map(
535
+ (record) => record.value
536
+ );
537
+ return merge(values);
538
+ }
539
+ return sortedRecords[sortedRecords.length - 1].value;
540
+ }
541
+ return activeRecords.reduce(
542
+ (winner, current) => compareRecords(current, winner) > 0 ? current : winner
543
+ ).value;
544
+ }
545
+ function createResolverCacheFor(definitions) {
546
+ const entryCache = /* @__PURE__ */ new WeakMap();
547
+ return (type, entry, scope = null) => {
548
+ if (!entry || typeof entry !== "object") {
549
+ return resolveEntryValueFor(definitions, type, entry, scope);
550
+ }
551
+ let typeCache = entryCache.get(entry);
552
+ if (!typeCache) {
553
+ typeCache = /* @__PURE__ */ new Map();
554
+ entryCache.set(entry, typeCache);
555
+ }
556
+ const cacheKey = scope || "default";
557
+ if (typeCache.has(cacheKey)) return typeCache.get(cacheKey);
558
+ const value = resolveEntryValueFor(definitions, type, entry, scope);
559
+ typeCache.set(cacheKey, value);
560
+ return value;
561
+ };
562
+ }
563
+ function createRegisterOperation(type, key, item, sourceOrOptions, optionsArg, timestamp, sequence = timestamp) {
564
+ const { source, options } = resolveRegisterInput(sourceOrOptions, optionsArg);
565
+ const instanceId = resolveInstanceId(options);
566
+ const scope = resolveScope(options);
567
+ return {
568
+ kind: "register",
569
+ validation: options.validation,
570
+ source,
571
+ scope,
572
+ record: buildSourceRecord({
573
+ source,
574
+ value: item,
575
+ instanceId,
576
+ priority: resolveRecordPriority(options, source),
577
+ scope,
578
+ timestamp,
579
+ sequence
580
+ }),
581
+ instanceId,
582
+ type,
583
+ key: typeof key === "string" ? key.trim() : key
584
+ };
585
+ }
586
+ function createUnregisterOperation(type, key, sourceOrOptions) {
587
+ const { scope, source, instanceId } = resolveUnregisterInput(sourceOrOptions);
588
+ return {
589
+ kind: "unregister",
590
+ instanceId,
591
+ scope,
592
+ source,
593
+ type,
594
+ key: typeof key === "string" ? key.trim() : key
595
+ };
596
+ }
597
+ function isValidRegistryTargetFor(definitions, type, key) {
598
+ return validateRegistryKey(type, key, definitions).valid;
599
+ }
600
+ function applyOperationFor(definitions, state, operation) {
601
+ if (!isValidRegistryTargetFor(definitions, operation?.type, operation?.key))
602
+ return state;
603
+ if (operation.kind === "register") {
604
+ return setSourceRecord(
605
+ state,
606
+ operation.type,
607
+ operation.key,
608
+ operation.source,
609
+ operation.record
610
+ );
611
+ }
612
+ if (operation.kind === "unregister") {
613
+ return removeSourceRecord(
614
+ state,
615
+ operation.type,
616
+ operation.key,
617
+ operation.source,
618
+ operation.instanceId,
619
+ operation.scope
620
+ );
621
+ }
622
+ return state;
623
+ }
624
+ function hasOperationEffectFor(definitions, state, operation) {
625
+ if (!isValidRegistryTargetFor(definitions, operation?.type, operation?.key))
626
+ return false;
627
+ if (operation.kind === "register") {
628
+ const currentRecord = getSourceRecord(
629
+ state[operation.type]?.[operation.key],
630
+ operation.source,
631
+ operation.instanceId,
632
+ operation.scope
633
+ );
634
+ return hasRecordChanged(currentRecord, operation.record);
635
+ }
636
+ if (operation.kind === "unregister") {
637
+ const entry = state[operation.type]?.[operation.key];
638
+ if (typeof operation.instanceId === "string" && operation.instanceId.length > 0) {
639
+ return operation.scope === null ? getSourceRecords(entry, operation.source).some(
640
+ ({ record }) => record?.instanceId === operation.instanceId
641
+ ) : Boolean(
642
+ getSourceRecord(
643
+ entry,
644
+ operation.source,
645
+ operation.instanceId,
646
+ operation.scope
647
+ )
648
+ );
649
+ }
650
+ return getSourceRecords(entry, operation.source, operation.scope).length > 0;
651
+ }
652
+ return false;
653
+ }
654
+ function resolveEffectiveOperationsFor(definitions, state, operations) {
655
+ const effectiveOperations = [];
656
+ let nextState = state;
657
+ operations.forEach((operation) => {
658
+ if (!hasOperationEffectFor(definitions, nextState, operation)) return;
659
+ effectiveOperations.push(operation);
660
+ nextState = applyOperationFor(definitions, nextState, operation);
661
+ });
662
+ return { effectiveOperations, nextState };
663
+ }
664
+ function createRegistryOperations(definitions) {
665
+ return Object.freeze({
666
+ applyOperation: (state, operation) => applyOperationFor(definitions, state, operation),
667
+ createInitialRegistries: () => createInitialRegistriesFor(definitions),
668
+ createResolverCache: () => createResolverCacheFor(definitions),
669
+ hasOperationEffect: (state, operation) => hasOperationEffectFor(definitions, state, operation),
670
+ isRegistryType: (type) => definitions.get(type) !== void 0,
671
+ isValidRegistryTarget: (type, key) => isValidRegistryTargetFor(definitions, type, key),
672
+ resolveEffectiveOperations: (state, operations) => resolveEffectiveOperationsFor(definitions, state, operations),
673
+ resolveEntryValue: (type, entry, scope = null) => resolveEntryValueFor(definitions, type, entry, scope)
674
+ });
675
+ }
676
+ function useRequiredContext(context, hookName, providerName) {
677
+ const value = use(context);
678
+ if (value === null) {
679
+ throw new Error(`${hookName} must be used within ${providerName}`);
680
+ }
681
+ return value;
682
+ }
683
+ function useStore(store, selector = (state) => state, isEqual = Object.is) {
684
+ const cacheRef = useRef({
685
+ isEqual: null,
686
+ selected: void 0,
687
+ selector: null,
688
+ snapshot: null
689
+ });
690
+ const getSelectedSnapshot = useCallback(() => {
691
+ const snapshot = store.getSnapshot();
692
+ const cache = cacheRef.current;
693
+ if (cache.snapshot === snapshot && cache.selector === selector && cache.isEqual === isEqual) {
694
+ return cache.selected;
695
+ }
696
+ const selected = selector(snapshot);
697
+ if (cache.snapshot !== null && cache.isEqual === isEqual && isEqual(cache.selected, selected)) {
698
+ cache.snapshot = snapshot;
699
+ cache.selector = selector;
700
+ return cache.selected;
701
+ }
702
+ cacheRef.current = {
703
+ isEqual,
704
+ selected,
705
+ selector,
706
+ snapshot
707
+ };
708
+ return selected;
709
+ }, [isEqual, selector, store]);
710
+ return useSyncExternalStore(
711
+ store.subscribe,
712
+ getSelectedSnapshot,
713
+ getSelectedSnapshot
714
+ );
715
+ }
716
+ var useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
717
+ var EventEmitter = class {
718
+ events = /* @__PURE__ */ new Map();
719
+ debounceTimers = /* @__PURE__ */ new Map();
720
+ subscribe(event, callback) {
721
+ if (typeof event !== "string" || !event || typeof callback !== "function") {
722
+ return () => {
723
+ };
724
+ }
725
+ const listeners = this.events.get(event) || /* @__PURE__ */ new Set();
726
+ listeners.add(callback);
727
+ this.events.set(event, listeners);
728
+ return () => {
729
+ listeners.delete(callback);
730
+ if (listeners.size === 0) this.events.delete(event);
731
+ };
732
+ }
733
+ emit(event, payload) {
734
+ const listeners = this.events.get(event);
735
+ if (!listeners || listeners.size === 0) return;
736
+ const snapshot = Array.from(listeners);
737
+ for (const callback of snapshot) {
738
+ try {
739
+ callback(payload);
740
+ } catch (error) {
741
+ report(`Event listener (${String(event)})`, error);
742
+ }
743
+ }
744
+ }
745
+ emitDebounced(event, payload, waitMs = 100) {
746
+ const existing = this.debounceTimers.get(event);
747
+ if (existing) clearTimeout(existing);
748
+ const timer = setTimeout(() => {
749
+ this.debounceTimers.delete(event);
750
+ this.emit(event, payload);
751
+ }, waitMs);
752
+ this.debounceTimers.set(event, timer);
753
+ }
754
+ cancelDebounced(event) {
755
+ if (event) {
756
+ const timer = this.debounceTimers.get(event);
757
+ if (timer) {
758
+ clearTimeout(timer);
759
+ this.debounceTimers.delete(event);
760
+ }
761
+ } else {
762
+ for (const timer of this.debounceTimers.values()) {
763
+ clearTimeout(timer);
764
+ }
765
+ this.debounceTimers.clear();
766
+ }
767
+ }
768
+ unsubscribeAll(event) {
769
+ this.cancelDebounced(event);
770
+ if (event) this.events.delete(event);
771
+ else this.events.clear();
772
+ }
773
+ hasListeners(event) {
774
+ return Boolean(this.events.get(event)?.size);
775
+ }
776
+ getListenerCount(event) {
777
+ return this.events.get(event)?.size || 0;
778
+ }
779
+ getAllEvents() {
780
+ return [...this.events.keys()];
781
+ }
782
+ };
783
+ var GLOBAL_EVENTS_KEY = /* @__PURE__ */ Symbol.for("__base_framework_global_events__");
784
+ var _global = globalThis;
785
+ _global[GLOBAL_EVENTS_KEY] ?? (_global[GLOBAL_EVENTS_KEY] = new EventEmitter());
786
+
787
+ // src/kernel/runtime.ts
788
+ function createRegistryTransaction(store, metadata = {}) {
789
+ const operations = [];
790
+ let status = "open";
791
+ const traceId = metadata.traceId || `tx-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
792
+ const ensureOpen = () => status === "open";
793
+ const mergeOptions = (options) => {
794
+ const baseOpts = options && typeof options === "object" ? options : {};
795
+ const needsSource = metadata.source && !baseOpts.source;
796
+ const needsScope = metadata.scope && !baseOpts.scope;
797
+ if (!needsSource && !needsScope) return baseOpts;
798
+ return {
799
+ ...baseOpts,
800
+ ...needsSource ? { source: metadata.source } : {},
801
+ ...needsScope ? { scope: metadata.scope } : {}
802
+ };
803
+ };
804
+ const register = (type, key, value, sourceOrOptions, optionsArg) => {
805
+ if (!ensureOpen()) return { index: -1, status, traceId };
806
+ const options = typeof sourceOrOptions === "string" ? mergeOptions({ ...optionsArg || {}, source: sourceOrOptions }) : mergeOptions(sourceOrOptions);
807
+ operations.push({ key, item: value, options, type });
808
+ return { index: operations.length - 1, status: "queued", traceId };
809
+ };
810
+ const unregister = (type, key, sourceOrOptions) => {
811
+ if (!ensureOpen()) return { index: -1, status, traceId };
812
+ const options = mergeOptions(
813
+ typeof sourceOrOptions === "string" ? { source: sourceOrOptions } : sourceOrOptions
814
+ );
815
+ operations.push({ key, options, type, unregister: true });
816
+ return { index: operations.length - 1, status: "queued", traceId };
817
+ };
818
+ const rollback = (_reason = "manual") => {
819
+ if (!ensureOpen()) return { index: -1, status, traceId };
820
+ status = "rolled-back";
821
+ operations.length = 0;
822
+ return { index: -1, status, traceId };
823
+ };
824
+ const commit = () => {
825
+ if (!ensureOpen()) return { status, traceId };
826
+ status = "committed";
827
+ const result = store.batch((queue) => {
828
+ operations.forEach((op) => {
829
+ if (op.unregister) queue.unregister(op.type, op.key, op.options);
830
+ else queue.register(op.type, op.key, op.item, op.options);
831
+ });
832
+ });
833
+ const applied = typeof result === "number" && Number.isFinite(result) ? result : 0;
834
+ return { applied, queued: operations.length, status, traceId };
835
+ };
836
+ const run = (executor) => {
837
+ if (typeof executor !== "function") {
838
+ rollback("invalid-executor");
839
+ return { status, traceId };
840
+ }
841
+ try {
842
+ executor({ register, unregister });
843
+ return commit();
844
+ } catch (error) {
845
+ rollback(error instanceof Error ? error.message : String(error));
846
+ throw error;
847
+ }
848
+ };
849
+ return {
850
+ commit,
851
+ get operations() {
852
+ return operations.slice();
853
+ },
854
+ register,
855
+ rollback,
856
+ run,
857
+ get status() {
858
+ return status;
859
+ },
860
+ traceId,
861
+ unregister
862
+ };
863
+ }
864
+
865
+ // src/kernel/store.ts
866
+ var NO_DEFINITIONS = /* @__PURE__ */ new Map();
867
+ function createNoopHandle(status = "rejected", reason = "unknown") {
868
+ const handle = Object.assign(() => false, {
869
+ active: false,
870
+ dispose: () => false,
871
+ instanceId: null,
872
+ key: "",
873
+ priority: 0,
874
+ reason,
875
+ source: "",
876
+ status,
877
+ type: "",
878
+ update: () => handle,
879
+ updatedAt: 0,
880
+ validation: "warn"
881
+ });
882
+ return handle;
883
+ }
884
+ var NOOP_HANDLE = createNoopHandle();
885
+ function isNoopHandle(handle) {
886
+ return handle === NOOP_HANDLE || handle?.status === "rejected" || handle?.status === "ignored";
887
+ }
888
+ function cloneRegistryValue(value, seen = /* @__PURE__ */ new WeakMap()) {
889
+ if (value === null || typeof value !== "object" || isValidElement(value)) {
890
+ return value;
891
+ }
892
+ const prototype = Object.getPrototypeOf(value);
893
+ const isPlainObject2 = !Array.isArray(value) && (prototype === Object.prototype || prototype === null);
894
+ if (!Array.isArray(value) && !isPlainObject2) return value;
895
+ if (seen.has(value)) return seen.get(value);
896
+ const source = value;
897
+ const clone = Array.isArray(value) ? [] : {};
898
+ seen.set(value, clone);
899
+ for (const key in source) {
900
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
901
+ clone[key] = cloneRegistryValue(source[key], seen);
902
+ }
903
+ }
904
+ return clone;
905
+ }
906
+ function normalizeInitialEntries(entries) {
907
+ return (Array.isArray(entries) ? entries : []).filter(
908
+ (entry) => entry?.type && entry?.items && typeof entry.items === "object"
909
+ );
910
+ }
911
+ function createInitialState(ops, definitions, entries) {
912
+ const normalizedEntries = normalizeInitialEntries(entries);
913
+ if (normalizedEntries.length === 0) return ops.createInitialRegistries();
914
+ const timestamp = Date.now();
915
+ let sequence = 0;
916
+ let state = ops.createInitialRegistries();
917
+ normalizedEntries.forEach((entry) => {
918
+ const source = entry.source || REGISTRY_SOURCES.STATIC;
919
+ const options = {
920
+ ...entry.options || {},
921
+ instanceId: entry.instanceId || entry.options?.instanceId || "registry-initial"
922
+ };
923
+ Object.entries(entry.items).forEach(([key, value]) => {
924
+ const validation = validateRegistration(
925
+ definitions,
926
+ entry.type,
927
+ key,
928
+ value,
929
+ source,
930
+ options
931
+ );
932
+ if (!validation.valid) return;
933
+ const operation = createRegisterOperation(
934
+ entry.type,
935
+ key,
936
+ cloneRegistryValue(value),
937
+ source,
938
+ options,
939
+ timestamp,
940
+ ++sequence
941
+ );
942
+ if (ops.hasOperationEffect(state, operation)) {
943
+ state = ops.applyOperation(state, operation);
944
+ }
945
+ });
946
+ });
947
+ return state;
948
+ }
949
+ function notifyListeners(listeners) {
950
+ if (!listeners) return;
951
+ for (const listener of listeners) {
952
+ try {
953
+ listener();
954
+ } catch (error) {
955
+ report("Registry listener", error);
956
+ }
957
+ }
958
+ }
959
+ function getOrCreateKeyListeners(listenersByType, type, key) {
960
+ let listeners = listenersByType.get(type);
961
+ if (!listeners) {
962
+ listeners = /* @__PURE__ */ new Map();
963
+ listenersByType.set(type, listeners);
964
+ }
965
+ let keyListeners = listeners.get(key);
966
+ if (!keyListeners) {
967
+ keyListeners = /* @__PURE__ */ new Set();
968
+ listeners.set(key, keyListeners);
969
+ }
970
+ return keyListeners;
971
+ }
972
+ function resolveRegistrationOptions(sourceOrOptions, optionsArg) {
973
+ if (sourceOrOptions && typeof sourceOrOptions === "object")
974
+ return sourceOrOptions;
975
+ return optionsArg && typeof optionsArg === "object" ? optionsArg : {};
976
+ }
977
+ function validateRegistration(definitions, type, key, value, sourceOrOptions, optionsArg) {
978
+ const options = resolveRegistrationOptions(sourceOrOptions, optionsArg);
979
+ const metadataValidation = validateRegistryMetadata(options);
980
+ const isStrict = options.validation === REGISTRY_VALIDATION_MODES.STRICT;
981
+ if (!metadataValidation.valid && isStrict) {
982
+ return {
983
+ issues: metadataValidation.issues,
984
+ reason: "invalid-metadata",
985
+ valid: false
986
+ };
987
+ }
988
+ const validation = validateRegistryValue(type, key, value, definitions);
989
+ if (validation.valid) return { valid: true };
990
+ if (!isStrict) {
991
+ report(`Registry ${type} "${key}" is invalid`, validation.issues, "warn");
992
+ }
993
+ return {
994
+ issues: validation.issues,
995
+ reason: "invalid-value",
996
+ valid: !isStrict
997
+ };
998
+ }
999
+ function createRegistrationHandle(store, operation) {
1000
+ let disposed = false;
1001
+ const dispose = (reason = "manual") => {
1002
+ if (disposed) return false;
1003
+ disposed = true;
1004
+ return store.dispose(operation, reason);
1005
+ };
1006
+ const handle = ((reason) => dispose(reason));
1007
+ handle.dispose = dispose;
1008
+ handle.update = (value, options = {}) => {
1009
+ if (disposed || !store.isCurrent(operation)) return NOOP_HANDLE;
1010
+ const nextHandle = store.register(
1011
+ operation.type,
1012
+ operation.key,
1013
+ value,
1014
+ operation.source,
1015
+ {
1016
+ ...typeof options === "object" ? options : {},
1017
+ instanceId: operation.instanceId,
1018
+ priority: operation.record.priority,
1019
+ ...operation.scope ? { scope: operation.scope } : {},
1020
+ ...operation.validation ? { validation: operation.validation } : {}
1021
+ }
1022
+ );
1023
+ if (isNoopHandle(nextHandle)) return handle;
1024
+ disposed = true;
1025
+ return nextHandle;
1026
+ };
1027
+ Object.defineProperties(handle, {
1028
+ active: {
1029
+ enumerable: true,
1030
+ get: () => !disposed && store.isCurrent(operation)
1031
+ },
1032
+ instanceId: { enumerable: true, value: operation.instanceId },
1033
+ key: { enumerable: true, value: operation.key },
1034
+ priority: { enumerable: true, value: operation.record.priority },
1035
+ source: { enumerable: true, value: operation.source },
1036
+ status: {
1037
+ enumerable: true,
1038
+ get: () => disposed ? "disposed" : store.isCurrent(operation) ? "active" : "superseded"
1039
+ },
1040
+ type: { enumerable: true, value: operation.type },
1041
+ updatedAt: { enumerable: true, value: operation.record.updatedAt },
1042
+ validation: { enumerable: true, value: operation.validation || "warn" }
1043
+ });
1044
+ return handle;
1045
+ }
1046
+ function prepareRegisterOperation(ops, definitions, type, key, item, sourceOrOptions, optionsArg, timestamp, sequence) {
1047
+ if (!ops.isValidRegistryTarget(type, key)) {
1048
+ return { rejected: createNoopHandle("rejected", "invalid-target") };
1049
+ }
1050
+ const validation = validateRegistration(
1051
+ definitions,
1052
+ type,
1053
+ key,
1054
+ item,
1055
+ sourceOrOptions,
1056
+ optionsArg
1057
+ );
1058
+ if (!validation.valid) {
1059
+ return { rejected: createNoopHandle("rejected", validation.reason) };
1060
+ }
1061
+ return {
1062
+ operation: createRegisterOperation(
1063
+ type,
1064
+ key,
1065
+ cloneRegistryValue(item),
1066
+ sourceOrOptions,
1067
+ optionsArg,
1068
+ timestamp,
1069
+ sequence
1070
+ )
1071
+ };
1072
+ }
1073
+ function createRegistryStore(initialEntries = [], definitions = NO_DEFINITIONS) {
1074
+ const ops = createRegistryOperations(definitions);
1075
+ let registries = createInitialState(ops, definitions, initialEntries);
1076
+ let sequence = normalizeInitialEntries(initialEntries).reduce(
1077
+ (count, entry) => count + Object.keys(entry.items).length,
1078
+ 0
1079
+ );
1080
+ const listenersByType = /* @__PURE__ */ new Map();
1081
+ const entrySnapshots = /* @__PURE__ */ new Map();
1082
+ const valueSnapshots = /* @__PURE__ */ new Map();
1083
+ const resolveCachedValue = ops.createResolverCache();
1084
+ const subscribe = (type, key, listener) => {
1085
+ const keyListeners = getOrCreateKeyListeners(
1086
+ listenersByType,
1087
+ type,
1088
+ key ?? null
1089
+ );
1090
+ keyListeners.add(listener);
1091
+ return () => {
1092
+ keyListeners.delete(listener);
1093
+ if (keyListeners.size > 0) return;
1094
+ const listeners = listenersByType.get(type);
1095
+ if (listeners) {
1096
+ listeners.delete(key ?? null);
1097
+ if (listeners.size === 0) listenersByType.delete(type);
1098
+ }
1099
+ };
1100
+ };
1101
+ const commit = (nextState, operations = []) => {
1102
+ if (registries === nextState) return;
1103
+ const previousState = registries;
1104
+ registries = nextState;
1105
+ const changedKeysByType = /* @__PURE__ */ new Map();
1106
+ for (const operation of operations) {
1107
+ if (!ops.isValidRegistryTarget(operation?.type, operation?.key)) continue;
1108
+ let keys = changedKeysByType.get(operation.type);
1109
+ if (!keys) {
1110
+ keys = /* @__PURE__ */ new Set();
1111
+ changedKeysByType.set(operation.type, keys);
1112
+ }
1113
+ keys.add(operation.key);
1114
+ }
1115
+ for (const [type, changedKeys] of changedKeysByType) {
1116
+ const previousRegistry = previousState[type] || {};
1117
+ const nextRegistry = nextState[type] || {};
1118
+ const typeListeners = listenersByType.get(type);
1119
+ let typeChanged = false;
1120
+ if (!typeListeners) continue;
1121
+ for (const key of changedKeys) {
1122
+ if (previousRegistry[key] === nextRegistry[key]) continue;
1123
+ typeChanged = true;
1124
+ notifyListeners(typeListeners.get(key));
1125
+ }
1126
+ if (typeChanged) {
1127
+ notifyListeners(typeListeners.get(null));
1128
+ }
1129
+ }
1130
+ };
1131
+ const isCurrent = (operation) => {
1132
+ const entry = registries[operation.type]?.[operation.key];
1133
+ const recordKey = createRecordKey(
1134
+ operation.source,
1135
+ operation.instanceId,
1136
+ operation.scope
1137
+ );
1138
+ return entry?.[recordKey] === operation.record;
1139
+ };
1140
+ const dispose = (operation, _reason = "manual") => {
1141
+ if (!isCurrent(operation)) return false;
1142
+ const unregisterOperation = createUnregisterOperation(
1143
+ operation.type,
1144
+ operation.key,
1145
+ {
1146
+ source: operation.source,
1147
+ instanceId: operation.instanceId,
1148
+ scope: operation.scope
1149
+ }
1150
+ );
1151
+ if (!ops.hasOperationEffect(registries, unregisterOperation)) return false;
1152
+ commit(ops.applyOperation(registries, unregisterOperation), [
1153
+ unregisterOperation
1154
+ ]);
1155
+ return true;
1156
+ };
1157
+ const register = (type, key, item, sourceOrOptions = DEFAULT_SOURCE, optionsArg = {}) => {
1158
+ const prepared = prepareRegisterOperation(
1159
+ ops,
1160
+ definitions,
1161
+ type,
1162
+ key,
1163
+ item,
1164
+ sourceOrOptions,
1165
+ optionsArg,
1166
+ Date.now(),
1167
+ ++sequence
1168
+ );
1169
+ if ("rejected" in prepared) return prepared.rejected;
1170
+ const { operation } = prepared;
1171
+ if (!ops.hasOperationEffect(registries, operation)) {
1172
+ return createNoopHandle("ignored", "unchanged");
1173
+ }
1174
+ commit(ops.applyOperation(registries, operation), [operation]);
1175
+ return createRegistrationHandle(store, operation);
1176
+ };
1177
+ const unregister = (type, key, sourceOrOptions = DEFAULT_SOURCE) => {
1178
+ if (!ops.isValidRegistryTarget(type, key)) return;
1179
+ const operation = createUnregisterOperation(type, key, sourceOrOptions);
1180
+ if (!ops.hasOperationEffect(registries, operation)) return;
1181
+ commit(ops.applyOperation(registries, operation), [operation]);
1182
+ };
1183
+ const batch = (executor) => {
1184
+ if (typeof executor !== "function") return 0;
1185
+ const timestamp = Date.now();
1186
+ const operations = [];
1187
+ const queue = {
1188
+ register: (type, key, item, sourceOrOptions = DEFAULT_SOURCE, optionsArg = {}) => {
1189
+ const prepared = prepareRegisterOperation(
1190
+ ops,
1191
+ definitions,
1192
+ type,
1193
+ key,
1194
+ item,
1195
+ sourceOrOptions,
1196
+ optionsArg,
1197
+ timestamp,
1198
+ ++sequence
1199
+ );
1200
+ if ("rejected" in prepared) return prepared.rejected;
1201
+ operations.push(prepared.operation);
1202
+ return createRegistrationHandle(store, prepared.operation);
1203
+ },
1204
+ unregister: (type, key, sourceOrOptions = DEFAULT_SOURCE) => {
1205
+ if (!ops.isValidRegistryTarget(type, key)) return;
1206
+ operations.push(createUnregisterOperation(type, key, sourceOrOptions));
1207
+ }
1208
+ };
1209
+ executor(queue);
1210
+ if (operations.length === 0) return 0;
1211
+ const { effectiveOperations, nextState } = ops.resolveEffectiveOperations(
1212
+ registries,
1213
+ operations
1214
+ );
1215
+ if (effectiveOperations.length === 0) return 0;
1216
+ commit(nextState, effectiveOperations);
1217
+ return effectiveOperations.length;
1218
+ };
1219
+ const getSnapshot = (type, key, scope = null) => {
1220
+ const entry = registries[type]?.[key];
1221
+ let snapshots = valueSnapshots.get(type);
1222
+ if (!snapshots) {
1223
+ snapshots = /* @__PURE__ */ new Map();
1224
+ valueSnapshots.set(type, snapshots);
1225
+ }
1226
+ const cacheKey = scope === null ? key : `${scope}\0${key}`;
1227
+ if (entry === void 0) {
1228
+ snapshots.delete(cacheKey);
1229
+ return void 0;
1230
+ }
1231
+ const cached = snapshots.get(cacheKey);
1232
+ if (cached && cached.entry === entry) return cached.value;
1233
+ const value = resolveCachedValue(type, entry, scope);
1234
+ snapshots.set(cacheKey, { entry, value });
1235
+ return value;
1236
+ };
1237
+ const getEntriesSnapshot = (type, scope = null) => {
1238
+ const typeRegistry = registries[type] || {};
1239
+ const cacheKey = `${type}::${scope ?? "null"}`;
1240
+ const cached = entrySnapshots.get(cacheKey);
1241
+ if (cached?.typeRegistry === typeRegistry) return cached.value;
1242
+ const resolved = {};
1243
+ for (const key in typeRegistry) {
1244
+ if (Object.prototype.hasOwnProperty.call(typeRegistry, key)) {
1245
+ const value = resolveCachedValue(type, typeRegistry[key], scope);
1246
+ if (value !== void 0) resolved[key] = value;
1247
+ }
1248
+ }
1249
+ const finalValue = Object.freeze(resolved);
1250
+ entrySnapshots.set(cacheKey, { typeRegistry, value: finalValue });
1251
+ return finalValue;
1252
+ };
1253
+ const store = {
1254
+ batch,
1255
+ dispose,
1256
+ getEntriesSnapshot,
1257
+ getSnapshot,
1258
+ isCurrent,
1259
+ register,
1260
+ subscribe,
1261
+ transaction: (executor, metadata = {}) => createRegistryTransaction(store, metadata).run(executor),
1262
+ unregister
1263
+ };
1264
+ return store;
1265
+ }
1266
+ function getOrCreateGlobalContext(name, defaultValue) {
1267
+ const sym = /* @__PURE__ */ Symbol.for(`@omerdlw/base-framework/context/${name}`);
1268
+ const store = globalThis;
1269
+ if (!store[sym]) {
1270
+ store[sym] = createContext(defaultValue);
1271
+ }
1272
+ return store[sym];
1273
+ }
1274
+ var RegistryContext = getOrCreateGlobalContext(
1275
+ "RegistryContext",
1276
+ null
1277
+ );
1278
+ function RegistryProvider({
1279
+ children,
1280
+ definitions,
1281
+ initialEntries = []
1282
+ }) {
1283
+ const [store] = useState(
1284
+ () => createRegistryStore(initialEntries, definitions)
1285
+ );
1286
+ const contextValue = useMemo(
1287
+ () => ({
1288
+ actions: {
1289
+ batch: store.batch,
1290
+ register: store.register,
1291
+ transaction: store.transaction,
1292
+ unregister: store.unregister
1293
+ },
1294
+ subscription: {
1295
+ getEntriesSnapshot: store.getEntriesSnapshot,
1296
+ getSnapshot: store.getSnapshot,
1297
+ subscribe: store.subscribe
1298
+ }
1299
+ }),
1300
+ [store]
1301
+ );
1302
+ return /* @__PURE__ */ jsx(RegistryContext, { value: contextValue, children });
1303
+ }
1304
+ function useRegistryActions() {
1305
+ return useRequiredContext(
1306
+ RegistryContext,
1307
+ "useRegistryActions",
1308
+ "RegistryProvider"
1309
+ ).actions;
1310
+ }
1311
+ function useRegistrySubscription() {
1312
+ return useRequiredContext(
1313
+ RegistryContext,
1314
+ "useRegistrySubscription",
1315
+ "RegistryProvider"
1316
+ ).subscription;
1317
+ }
1318
+ function useRegistryValue(type, key) {
1319
+ const { getSnapshot, subscribe } = useRegistrySubscription();
1320
+ const subscribeToKey = useCallback(
1321
+ (listener) => subscribe(type, key, listener),
1322
+ [key, subscribe, type]
1323
+ );
1324
+ const getValue = useCallback(
1325
+ () => getSnapshot(type, key),
1326
+ [getSnapshot, key, type]
1327
+ );
1328
+ return useSyncExternalStore(subscribeToKey, getValue, getValue);
1329
+ }
1330
+ function useRegistryEntries(type) {
1331
+ const { getEntriesSnapshot, subscribe } = useRegistrySubscription();
1332
+ const subscribeToType = useCallback(
1333
+ (listener) => subscribe(type, null, listener),
1334
+ [subscribe, type]
1335
+ );
1336
+ const getEntries = useCallback(
1337
+ () => getEntriesSnapshot(type),
1338
+ [getEntriesSnapshot, type]
1339
+ );
1340
+ return useSyncExternalStore(subscribeToType, getEntries, getEntries);
1341
+ }
1342
+ var EMPTY_MODULES = Object.freeze([]);
1343
+ var PassthroughBoundary = ({ children }) => children;
1344
+ var ModuleHostContext = getOrCreateGlobalContext("ModuleHostContext", null);
1345
+ function selectModuleSlice(coreModule, config) {
1346
+ const slice = coreModule.page?.select ? coreModule.page.select(config) : config[coreModule.id];
1347
+ return slice ?? null;
1348
+ }
1349
+ function createModulePayload(modules, config, metadata = {}) {
1350
+ const payload = {};
1351
+ let hasSlices = false;
1352
+ for (const coreModule of modules) {
1353
+ if (!coreModule.page?.entries) continue;
1354
+ const slice = selectModuleSlice(coreModule, config);
1355
+ if (slice === null) continue;
1356
+ payload[coreModule.id] = slice;
1357
+ hasSlices = true;
1358
+ }
1359
+ if (!hasSlices) return null;
1360
+ return {
1361
+ ...payload,
1362
+ registry: {
1363
+ ...metadata,
1364
+ ...isObject(config.registry) ? config.registry : {}
1365
+ }
1366
+ };
1367
+ }
1368
+ var MODULE_ID_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
1369
+ function sortModules(modules) {
1370
+ const byId = /* @__PURE__ */ new Map();
1371
+ for (const coreModule of modules) {
1372
+ if (!MODULE_ID_PATTERN.test(coreModule.id)) {
1373
+ throw new Error(
1374
+ `[Core] Invalid module id "${coreModule.id}": use a camelCase name such as "contextMenu".`
1375
+ );
1376
+ }
1377
+ if (byId.has(coreModule.id)) {
1378
+ throw new Error(`[Core] Module "${coreModule.id}" is installed twice.`);
1379
+ }
1380
+ byId.set(coreModule.id, coreModule);
1381
+ }
1382
+ const sorted = [];
1383
+ const state = /* @__PURE__ */ new Map();
1384
+ const visit = (coreModule, path) => {
1385
+ const current = state.get(coreModule.id);
1386
+ if (current === "done") return;
1387
+ if (current === "visiting") {
1388
+ throw new Error(
1389
+ `[Core] Module dependency cycle: ${[...path, coreModule.id].join(" -> ")}`
1390
+ );
1391
+ }
1392
+ state.set(coreModule.id, "visiting");
1393
+ for (const id of coreModule.uses ?? []) {
1394
+ const dependency = byId.get(id);
1395
+ if (dependency) visit(dependency, [...path, coreModule.id]);
1396
+ }
1397
+ state.set(coreModule.id, "done");
1398
+ sorted.push(coreModule);
1399
+ };
1400
+ modules.forEach((coreModule) => visit(coreModule, []));
1401
+ return sorted;
1402
+ }
1403
+ function createModuleRegistryDefinitions(modules) {
1404
+ const definitions = /* @__PURE__ */ new Map();
1405
+ for (const coreModule of modules) {
1406
+ if (coreModule.registry)
1407
+ definitions.set(coreModule.id, coreModule.registry);
1408
+ }
1409
+ return definitions;
1410
+ }
1411
+ function useInstalledModules() {
1412
+ return use(ModuleHostContext)?.modules ?? EMPTY_MODULES;
1413
+ }
1414
+
1415
+ // src/kernel/handlers.ts
1416
+ function isPersistentLifecycle(lifecycle) {
1417
+ return lifecycle === REGISTRY_LIFECYCLES.PERSISTENT;
1418
+ }
1419
+ function runRegistrationBatch(context, executor) {
1420
+ return typeof context.batch === "function" ? context.batch(executor) : executor(context);
1421
+ }
1422
+ function createEntryCleanupKey(type, key, source, instanceId, scope) {
1423
+ return JSON.stringify([
1424
+ "entry",
1425
+ type,
1426
+ key,
1427
+ scope ?? null,
1428
+ source,
1429
+ instanceId
1430
+ ]);
1431
+ }
1432
+ function getCleanupScope(context) {
1433
+ return context?.cleanupScope || /* @__PURE__ */ new Map();
1434
+ }
1435
+ function clearCleanupTimer(scope, cleanupKey) {
1436
+ const lifecycle = scope.get(cleanupKey);
1437
+ if (!lifecycle) return;
1438
+ lifecycle.cancelled = true;
1439
+ if (lifecycle.timerId !== null) clearTimeout(lifecycle.timerId);
1440
+ scope.delete(cleanupKey);
1441
+ }
1442
+ function scheduleCleanup(scope, cleanupKey, callback, delayMs) {
1443
+ clearCleanupTimer(scope, cleanupKey);
1444
+ const lifecycle = {
1445
+ cancelled: false,
1446
+ timerId: null
1447
+ };
1448
+ lifecycle.timerId = setTimeout(() => {
1449
+ if (lifecycle.cancelled || scope.get(cleanupKey) !== lifecycle) return;
1450
+ scope.delete(cleanupKey);
1451
+ callback();
1452
+ }, delayMs);
1453
+ scope.set(cleanupKey, lifecycle);
1454
+ }
1455
+ function collectModuleRegistrations(coreModule, slice, pageMetadata, context) {
1456
+ const definition = coreModule.registry;
1457
+ const toEntries = coreModule.page?.entries;
1458
+ if (!definition || !toEntries || slice == null || slice === false) return [];
1459
+ const type = coreModule.id;
1460
+ const items = Array.isArray(slice) ? slice : [slice];
1461
+ const registrations = [];
1462
+ for (const item of items) {
1463
+ if (item == null || item === false) continue;
1464
+ const itemMetadata = isObject(item) && isObject(item.registry) ? item.registry : {};
1465
+ const metadata = { ...pageMetadata, ...itemMetadata };
1466
+ if (metadata.validation === "strict" && !validateRegistryMetadata(metadata).valid) {
1467
+ continue;
1468
+ }
1469
+ const payload = isObject(item) ? Object.fromEntries(
1470
+ Object.entries(item).filter(([key]) => key !== "registry")
1471
+ ) : item;
1472
+ const { cleanupDelayMs, lifecycle, registerOptions, scope, source } = normalizeRegistryMetadata(metadata, {
1473
+ defaultCleanupDelayMs: definition.cleanupDelayMs ?? null,
1474
+ defaultLifecycle: definition.lifecycle,
1475
+ defaultSource: DEFAULT_SOURCE
1476
+ });
1477
+ for (const { key, value } of toEntries(payload, context) ?? []) {
1478
+ const validation = definition.validate?.(value);
1479
+ if (validation && !validation.valid) {
1480
+ report(`Registry ${type} config is invalid`, validation.issues, "warn");
1481
+ continue;
1482
+ }
1483
+ registrations.push({
1484
+ cleanupDelayMs,
1485
+ cleanupKey: createEntryCleanupKey(
1486
+ type,
1487
+ key,
1488
+ source,
1489
+ context.instanceId,
1490
+ scope
1491
+ ),
1492
+ key,
1493
+ lifecycle,
1494
+ registerOptions,
1495
+ scope,
1496
+ source,
1497
+ type,
1498
+ value
1499
+ });
1500
+ }
1501
+ }
1502
+ return registrations;
1503
+ }
1504
+ var NO_CLEANUP = () => {
1505
+ };
1506
+ function applyRegistryConfig(config, context) {
1507
+ const modules = context.modules ?? [];
1508
+ if (!config || modules.length === 0) return NO_CLEANUP;
1509
+ const pageMetadata = isObject(config.registry) ? config.registry : {};
1510
+ const slices = config;
1511
+ const registrations = modules.flatMap((coreModule) => {
1512
+ try {
1513
+ return collectModuleRegistrations(
1514
+ coreModule,
1515
+ slices[coreModule.id],
1516
+ pageMetadata,
1517
+ context
1518
+ );
1519
+ } catch (error) {
1520
+ report(`Registry apply (${coreModule.id})`, error);
1521
+ return [];
1522
+ }
1523
+ });
1524
+ if (registrations.length === 0) return NO_CLEANUP;
1525
+ const cleanupScope = getCleanupScope(context);
1526
+ const owner = (registration) => ({
1527
+ instanceId: context.instanceId,
1528
+ scope: registration.scope,
1529
+ source: registration.source
1530
+ });
1531
+ runRegistrationBatch(context, (queue) => {
1532
+ registrations.forEach(
1533
+ ({ cleanupKey, key, registerOptions, source, type, value }) => {
1534
+ clearCleanupTimer(cleanupScope, cleanupKey);
1535
+ queue.register(type, key, value, source, registerOptions);
1536
+ }
1537
+ );
1538
+ });
1539
+ return () => {
1540
+ const immediate = [];
1541
+ registrations.forEach((registration) => {
1542
+ if (isPersistentLifecycle(registration.lifecycle)) return;
1543
+ const { cleanupDelayMs, cleanupKey, key, type } = registration;
1544
+ if (typeof cleanupDelayMs === "number" && cleanupDelayMs > 0) {
1545
+ scheduleCleanup(
1546
+ cleanupScope,
1547
+ cleanupKey,
1548
+ () => context.unregister(type, key, owner(registration)),
1549
+ cleanupDelayMs
1550
+ );
1551
+ } else {
1552
+ immediate.push(registration);
1553
+ }
1554
+ });
1555
+ if (immediate.length === 0) return;
1556
+ runRegistrationBatch(context, (queue) => {
1557
+ immediate.forEach(
1558
+ (registration) => queue.unregister(
1559
+ registration.type,
1560
+ registration.key,
1561
+ owner(registration)
1562
+ )
1563
+ );
1564
+ });
1565
+ };
1566
+ }
1567
+
1568
+ // src/kernel/hooks.ts
1569
+ function withInstanceId(instanceId, sourceOrOptions, optionsArg) {
1570
+ if (typeof sourceOrOptions === "string") {
1571
+ return {
1572
+ optionsArg: { ...isObject(optionsArg) ? optionsArg : {}, instanceId },
1573
+ sourceOrOptions
1574
+ };
1575
+ }
1576
+ if (isObject(sourceOrOptions)) {
1577
+ return {
1578
+ optionsArg,
1579
+ sourceOrOptions: { ...sourceOrOptions, instanceId }
1580
+ };
1581
+ }
1582
+ return {
1583
+ optionsArg: void 0,
1584
+ sourceOrOptions: {
1585
+ ...isObject(optionsArg) ? optionsArg : {},
1586
+ instanceId
1587
+ }
1588
+ };
1589
+ }
1590
+ function withInstanceIdForUnregister(instanceId, sourceOrOptions) {
1591
+ if (typeof sourceOrOptions === "string") {
1592
+ return { instanceId, source: sourceOrOptions };
1593
+ }
1594
+ if (isObject(sourceOrOptions)) {
1595
+ return { ...sourceOrOptions, instanceId };
1596
+ }
1597
+ return { instanceId };
1598
+ }
1599
+ function resolveRegisterArgsWithInstance(instanceId, sourceOrOptions, optionsArg) {
1600
+ const input = withInstanceId(instanceId, sourceOrOptions, optionsArg);
1601
+ return [input.sourceOrOptions, input.optionsArg];
1602
+ }
1603
+ function useShallowStable(value) {
1604
+ const ref = useRef(value);
1605
+ if (ref.current !== value && !shallowEqual(ref.current, value)) {
1606
+ ref.current = value;
1607
+ }
1608
+ return ref.current;
1609
+ }
1610
+ var MAX_STABILIZATION_DEPTH = 64;
1611
+ function createStableFunctionEntry(fn) {
1612
+ const entry = {
1613
+ current: fn,
1614
+ stable(...args) {
1615
+ return entry.current?.apply(this, args);
1616
+ }
1617
+ };
1618
+ return entry;
1619
+ }
1620
+ function isDirectRegistryComponentPath(path, componentSlices) {
1621
+ const match = /^config\.([^.[]+)\.[^.[]+$/.exec(path);
1622
+ return Boolean(match && componentSlices.has(match[1]));
1623
+ }
1624
+ function isReactNodeLike(value) {
1625
+ return value === null || value === void 0 || typeof value === "boolean" || typeof value === "string" || typeof value === "number" || isValidElement(value);
1626
+ }
1627
+ function isStabilizableObject(value) {
1628
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isValidElement(value);
1629
+ }
1630
+ function hasSameObjectKeys(previousValue, nextValue) {
1631
+ if (!isStabilizableObject(previousValue) || !isStabilizableObject(nextValue)) {
1632
+ return false;
1633
+ }
1634
+ const previousKeys = Object.keys(previousValue);
1635
+ const nextKeys = Object.keys(nextValue);
1636
+ if (previousKeys.length !== nextKeys.length) return false;
1637
+ return nextKeys.every(
1638
+ (key) => Object.prototype.hasOwnProperty.call(previousValue, key)
1639
+ );
1640
+ }
1641
+ function stabilizeRegistryValue(value, path, scope, previousValue, seen = /* @__PURE__ */ new WeakSet(), depth = 0) {
1642
+ if (depth > MAX_STABILIZATION_DEPTH) return value;
1643
+ if (typeof value === "function") {
1644
+ const isComponent = value.name && /^[A-Z]/.test(value.name);
1645
+ if (isComponent || isDirectRegistryComponentPath(path, scope.componentSlices)) {
1646
+ return value;
1647
+ }
1648
+ scope.usedPaths.add(path);
1649
+ let entry = scope.functionEntries.get(path);
1650
+ if (!entry) {
1651
+ entry = createStableFunctionEntry(value);
1652
+ scope.functionEntries.set(path, entry);
1653
+ } else {
1654
+ entry.current = value;
1655
+ }
1656
+ return entry.stable;
1657
+ }
1658
+ if (value && typeof value === "object") {
1659
+ if (seen.has(value)) return value;
1660
+ seen.add(value);
1661
+ }
1662
+ if (isValidElement(value)) {
1663
+ const nextProps = stabilizeRegistryValue(
1664
+ value.props,
1665
+ `${path}.props`,
1666
+ scope,
1667
+ isValidElement(previousValue) ? previousValue.props : void 0,
1668
+ seen,
1669
+ depth + 1
1670
+ );
1671
+ if (isValidElement(previousValue) && previousValue.type === value.type && previousValue.key === value.key && previousValue.props === nextProps) {
1672
+ return previousValue;
1673
+ }
1674
+ return cloneElement(value, nextProps);
1675
+ }
1676
+ if (Array.isArray(value)) {
1677
+ const nextValue = value.every(isReactNodeLike) ? Children.toArray(value) : value;
1678
+ const previousArray = Array.isArray(previousValue) ? previousValue : null;
1679
+ let hasChanged2 = !previousArray || previousArray.length !== nextValue.length;
1680
+ const stabilizedValue2 = nextValue.map((item, index) => {
1681
+ const nextItem = stabilizeRegistryValue(
1682
+ item,
1683
+ `${path}[${index}]`,
1684
+ scope,
1685
+ previousArray?.[index],
1686
+ seen,
1687
+ depth + 1
1688
+ );
1689
+ if (!previousArray || nextItem !== previousArray[index]) {
1690
+ hasChanged2 = true;
1691
+ }
1692
+ return nextItem;
1693
+ });
1694
+ return !hasChanged2 ? previousArray : stabilizedValue2;
1695
+ }
1696
+ if (typeof value !== "object" || value === null) {
1697
+ return value;
1698
+ }
1699
+ const source = value;
1700
+ const previousRecord = previousValue;
1701
+ const stabilizedValue = {};
1702
+ const canReusePrevious = hasSameObjectKeys(previousValue, value);
1703
+ let hasChanged = !canReusePrevious;
1704
+ Object.keys(source).forEach((key) => {
1705
+ const nextValue = stabilizeRegistryValue(
1706
+ source[key],
1707
+ `${path}.${key}`,
1708
+ scope,
1709
+ previousRecord?.[key],
1710
+ seen,
1711
+ depth + 1
1712
+ );
1713
+ stabilizedValue[key] = nextValue;
1714
+ if (!canReusePrevious || nextValue !== previousRecord?.[key]) {
1715
+ hasChanged = true;
1716
+ }
1717
+ });
1718
+ return !hasChanged ? previousValue : stabilizedValue;
1719
+ }
1720
+ function useAppliedRegistryConfig(payload, context, componentSlices) {
1721
+ const functionEntriesRef = useRef(/* @__PURE__ */ new Map());
1722
+ const appliedRef = useRef(null);
1723
+ useIsomorphicLayoutEffect(() => {
1724
+ const previous = appliedRef.current;
1725
+ if (previous && previous.payload === payload && previous.context === context) {
1726
+ return;
1727
+ }
1728
+ const functionEntries = functionEntriesRef.current;
1729
+ const usedPaths = /* @__PURE__ */ new Set();
1730
+ const config = stabilizeRegistryValue(
1731
+ payload,
1732
+ "config",
1733
+ { componentSlices, functionEntries, usedPaths },
1734
+ previous?.config
1735
+ );
1736
+ functionEntries.forEach((_entry, path) => {
1737
+ if (!usedPaths.has(path)) functionEntries.delete(path);
1738
+ });
1739
+ if (previous && previous.config === config && previous.context === context) {
1740
+ previous.payload = payload;
1741
+ return;
1742
+ }
1743
+ previous?.cleanup();
1744
+ appliedRef.current = {
1745
+ cleanup: applyRegistryConfig(config, context),
1746
+ config,
1747
+ context,
1748
+ payload
1749
+ };
1750
+ });
1751
+ useIsomorphicLayoutEffect(
1752
+ () => () => {
1753
+ appliedRef.current?.cleanup();
1754
+ appliedRef.current = null;
1755
+ },
1756
+ []
1757
+ );
1758
+ }
1759
+ function createRegistryApplyContext(actions, {
1760
+ cleanupScope = /* @__PURE__ */ new Map(),
1761
+ instanceId,
1762
+ modules = [],
1763
+ pathname
1764
+ }) {
1765
+ const stamp = (queue) => ({
1766
+ register: (type, key, item, sourceOrOptions, optionsArg) => queue.register(
1767
+ type,
1768
+ key,
1769
+ item,
1770
+ ...resolveRegisterArgsWithInstance(
1771
+ instanceId,
1772
+ sourceOrOptions,
1773
+ optionsArg
1774
+ )
1775
+ ),
1776
+ unregister: (type, key, sourceOrOptions) => queue.unregister(
1777
+ type,
1778
+ key,
1779
+ withInstanceIdForUnregister(instanceId, sourceOrOptions)
1780
+ )
1781
+ });
1782
+ return {
1783
+ ...stamp(actions),
1784
+ batch: (executor) => typeof executor === "function" ? actions.batch((queue) => executor(stamp(queue))) : 0,
1785
+ cleanupScope,
1786
+ instanceId,
1787
+ modules,
1788
+ pathname
1789
+ };
1790
+ }
1791
+ function useRegistry(config, metadata) {
1792
+ const { batch, register, unregister } = useRegistryActions();
1793
+ const pathname = usePathname();
1794
+ const modules = useInstalledModules();
1795
+ const instanceId = `registry-instance-${useId()}`;
1796
+ const [cleanupScope] = useState(
1797
+ () => /* @__PURE__ */ new Map()
1798
+ );
1799
+ const context = useMemo(
1800
+ () => createRegistryApplyContext(
1801
+ { batch, register, unregister },
1802
+ {
1803
+ cleanupScope,
1804
+ instanceId,
1805
+ modules,
1806
+ pathname
1807
+ }
1808
+ ),
1809
+ [batch, cleanupScope, instanceId, modules, pathname, register, unregister]
1810
+ );
1811
+ const payload = useMemo(
1812
+ () => config ? createModulePayload(modules, config, metadata) : null,
1813
+ [config, metadata, modules]
1814
+ );
1815
+ const componentSlices = useMemo(
1816
+ () => new Set(
1817
+ modules.filter(
1818
+ (coreModule) => coreModule.registry?.valueKind === "component"
1819
+ ).map((coreModule) => coreModule.id)
1820
+ ),
1821
+ [modules]
1822
+ );
1823
+ useAppliedRegistryConfig(payload, context, componentSlices);
1824
+ }
1825
+ var EMPTY_OBJECT = Object.freeze({});
1826
+ function createPageControllerStore() {
1827
+ const listeners = /* @__PURE__ */ new Set();
1828
+ let stack = [];
1829
+ const notify = () => {
1830
+ listeners.forEach((listener) => {
1831
+ try {
1832
+ listener();
1833
+ } catch (error) {
1834
+ report("Page controller listener", error);
1835
+ }
1836
+ });
1837
+ };
1838
+ return {
1839
+ getSnapshot() {
1840
+ const top = stack[stack.length - 1];
1841
+ return top?.controllerRef?.current || null;
1842
+ },
1843
+ notify,
1844
+ register(id, controllerRef) {
1845
+ stack = stack.filter((item) => item.id !== id);
1846
+ stack.push({ controllerRef, id });
1847
+ notify();
1848
+ },
1849
+ subscribe(listener) {
1850
+ listeners.add(listener);
1851
+ return () => {
1852
+ listeners.delete(listener);
1853
+ };
1854
+ },
1855
+ unregister(id) {
1856
+ stack = stack.filter((item) => item.id !== id);
1857
+ notify();
1858
+ }
1859
+ };
1860
+ }
1861
+ function createControllerScope() {
1862
+ const listeners = /* @__PURE__ */ new Set();
1863
+ let current = null;
1864
+ const subscribe = (listener) => {
1865
+ listeners.add(listener);
1866
+ return () => {
1867
+ listeners.delete(listener);
1868
+ };
1869
+ };
1870
+ const getSnapshot = () => current;
1871
+ function PageProvider({ children }) {
1872
+ const controller = useSyncExternalStore(
1873
+ subscribe,
1874
+ getSnapshot,
1875
+ getSnapshot
1876
+ );
1877
+ return /* @__PURE__ */ jsx(PageControllerContext, { value: controller, children });
1878
+ }
1879
+ return {
1880
+ Provider: PageProvider,
1881
+ publish(controller) {
1882
+ if (current === controller) return;
1883
+ current = controller;
1884
+ listeners.forEach((listener) => listener());
1885
+ }
1886
+ };
1887
+ }
1888
+ var fallbackStandaloneStore = createPageControllerStore();
1889
+ var noopHook = () => {
1890
+ };
1891
+ var PassthroughProvider = ({ children }) => children;
1892
+ var PageControllerContext = getOrCreateGlobalContext(
1893
+ "PageControllerContext",
1894
+ null
1895
+ );
1896
+ var PageControllerStoreContext = getOrCreateGlobalContext(
1897
+ "PageControllerStoreContext",
1898
+ fallbackStandaloneStore
1899
+ );
1900
+ function PageControllerProvider({ children }) {
1901
+ const [store] = useState(
1902
+ () => createPageControllerStore()
1903
+ );
1904
+ return /* @__PURE__ */ jsx(PageControllerStoreContext, { value: store, children });
1905
+ }
1906
+ var emptySubscribe = () => () => {
1907
+ };
1908
+ var getNullSnapshot = () => null;
1909
+ var FALLBACK_PAGE_CONTROLLER = Object.freeze({
1910
+ Provider: PassthroughProvider,
1911
+ config: EMPTY_OBJECT,
1912
+ modules: Object.freeze({}),
1913
+ reset: noopHook,
1914
+ set: noopHook
1915
+ });
1916
+ function usePageController() {
1917
+ const scopedContext = use(PageControllerContext);
1918
+ const controllerStore = use(PageControllerStoreContext);
1919
+ const storeSubscribe = scopedContext ? emptySubscribe : controllerStore.subscribe;
1920
+ const storeSnapshot = scopedContext ? getNullSnapshot : controllerStore.getSnapshot;
1921
+ const storeController = useSyncExternalStore(
1922
+ storeSubscribe,
1923
+ storeSnapshot,
1924
+ getNullSnapshot
1925
+ );
1926
+ return scopedContext ?? storeController ?? FALLBACK_PAGE_CONTROLLER;
1927
+ }
1928
+ function usePage(pageConfig = EMPTY_OBJECT, options) {
1929
+ const instanceId = useId();
1930
+ const controllerStore = use(PageControllerStoreContext);
1931
+ const modules = useInstalledModules();
1932
+ const [overrides, setOverrides] = useState(EMPTY_OBJECT);
1933
+ const set = useCallback((partial) => {
1934
+ if (!partial || typeof partial !== "object") return;
1935
+ setOverrides((prev) => mergeModuleConfigs(prev, partial));
1936
+ }, []);
1937
+ const reset = useCallback(() => {
1938
+ setOverrides(EMPTY_OBJECT);
1939
+ }, []);
1940
+ const effectiveConfig = useMemo(() => {
1941
+ const base = pageConfig || EMPTY_OBJECT;
1942
+ if (Object.keys(overrides).length === 0) return base;
1943
+ return mergeModuleConfigs(base, overrides);
1944
+ }, [pageConfig, overrides]);
1945
+ const moduleSlices = useMemo(
1946
+ () => modules.map(
1947
+ (coreModule) => selectModuleSlice(coreModule, effectiveConfig)
1948
+ ),
1949
+ [effectiveConfig, modules]
1950
+ );
1951
+ const registryMetadata = useMemo(
1952
+ () => pickRegistryMetadata(options),
1953
+ [options]
1954
+ );
1955
+ useRegistry(effectiveConfig, registryMetadata);
1956
+ const pageApi = useMemo(() => ({ set }), [set]);
1957
+ const moduleControllers = {};
1958
+ for (let index = 0; index < modules.length; index += 1) {
1959
+ const coreModule = modules[index];
1960
+ if (coreModule.page?.use) {
1961
+ moduleControllers[coreModule.id] = coreModule.page.use(
1962
+ moduleSlices[index],
1963
+ pageApi
1964
+ );
1965
+ }
1966
+ }
1967
+ const pageModules = useShallowStable(moduleControllers);
1968
+ const [scope] = useState(createControllerScope);
1969
+ const controller = useMemo(
1970
+ () => ({
1971
+ Provider: scope.Provider,
1972
+ config: effectiveConfig,
1973
+ modules: pageModules,
1974
+ reset,
1975
+ set
1976
+ }),
1977
+ [effectiveConfig, pageModules, reset, scope, set]
1978
+ );
1979
+ const controllerRef = useRef(controller);
1980
+ useIsomorphicLayoutEffect(() => {
1981
+ controllerRef.current = controller;
1982
+ scope.publish(controller);
1983
+ controllerStore.notify();
1984
+ }, [controller, controllerStore, scope]);
1985
+ useEffect(() => {
1986
+ controllerStore.register(instanceId, controllerRef);
1987
+ return () => {
1988
+ controllerStore.unregister(instanceId);
1989
+ };
1990
+ }, [controllerStore, instanceId]);
1991
+ return controller;
1992
+ }
1993
+ function defineModule(coreModule) {
1994
+ return Object.freeze({ ...coreModule });
1995
+ }
1996
+ function warnMissingPeers(modules) {
1997
+ const installed = new Set(modules.map((coreModule) => coreModule.id));
1998
+ for (const { id, uses } of modules) {
1999
+ const missing = (uses ?? []).filter((peer) => !installed.has(peer));
2000
+ if (missing.length > 0) {
2001
+ report(
2002
+ `Module "${id}" runs without its optional peers`,
2003
+ missing.join(", "),
2004
+ "warn"
2005
+ );
2006
+ }
2007
+ }
2008
+ }
2009
+ function createModuleHost(modules, Boundary) {
2010
+ const sorted = sortModules(modules);
2011
+ if (process.env.NODE_ENV !== "production") warnMissingPeers(sorted);
2012
+ return {
2013
+ Boundary,
2014
+ byId: new Map(sorted.map((coreModule) => [coreModule.id, coreModule])),
2015
+ definitions: createModuleRegistryDefinitions(sorted),
2016
+ modules: Object.freeze(sorted)
2017
+ };
2018
+ }
2019
+ function ModuleHost({
2020
+ boundary = PassthroughBoundary,
2021
+ children,
2022
+ modules = EMPTY_MODULES,
2023
+ registryEntries
2024
+ }) {
2025
+ const [host] = useState(() => createModuleHost(modules, boundary));
2026
+ const { Boundary } = host;
2027
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2028
+ host.modules.map(
2029
+ ({ Backdrop, id }) => Backdrop ? /* @__PURE__ */ jsx(Boundary, { name: id, children: /* @__PURE__ */ jsx(Backdrop, {}) }, id) : null
2030
+ ),
2031
+ children,
2032
+ host.modules.map(
2033
+ ({ Overlay, id }) => Overlay ? /* @__PURE__ */ jsx(Boundary, { name: id, children: /* @__PURE__ */ jsx(Overlay, {}) }, id) : null
2034
+ )
2035
+ ] });
2036
+ const tree = host.modules.reduceRight(
2037
+ (inner, { Provider }) => Provider ? /* @__PURE__ */ jsx(Provider, { children: inner }) : inner,
2038
+ content
2039
+ );
2040
+ return /* @__PURE__ */ jsx(
2041
+ RegistryProvider,
2042
+ {
2043
+ definitions: host.definitions,
2044
+ initialEntries: registryEntries,
2045
+ children: /* @__PURE__ */ jsx(ModuleHostContext, { value: host, children: /* @__PURE__ */ jsx(PageControllerProvider, { children: tree }) })
2046
+ }
2047
+ );
2048
+ }
2049
+ function useModule(id) {
2050
+ const coreModule = use(ModuleHostContext)?.byId.get(id);
2051
+ return coreModule?.context ? use(coreModule.context) ?? null : null;
2052
+ }
2053
+ function definePeer(id, inert) {
2054
+ const useRuntime = () => useModule(id) ?? inert;
2055
+ return {
2056
+ useRuntime,
2057
+ useActions: () => useRuntime().actions,
2058
+ useState: (selector, isEqual) => useStore(
2059
+ useRuntime().store,
2060
+ selector,
2061
+ isEqual
2062
+ )
2063
+ };
2064
+ }
2065
+ var NO_MODULE_STORE = createStore(void 0);
2066
+ function useModuleState(id, selector, fallback, isEqual = Object.is) {
2067
+ const runtime = useModule(id);
2068
+ return useStore(
2069
+ runtime?.store ?? NO_MODULE_STORE,
2070
+ (state) => runtime ? selector(state) : fallback,
2071
+ isEqual
2072
+ );
2073
+ }
2074
+ function ModuleBoundary({
2075
+ children,
2076
+ name
2077
+ }) {
2078
+ const Boundary = use(ModuleHostContext)?.Boundary ?? PassthroughBoundary;
2079
+ return createElement(Boundary, { name }, children);
2080
+ }
2081
+ function useIsModuleInstalled(id) {
2082
+ return use(ModuleHostContext)?.byId.has(id) ?? false;
2083
+ }
2084
+
2085
+ // src/kernel/adapters.tsx
2086
+ function useModuleRegistration(id, value, options) {
2087
+ const coreModule = useInstalledModules().find(
2088
+ (candidate) => candidate.id === id
2089
+ );
2090
+ const config = coreModule && options?.enabled !== false && value != null ? { [id]: value } : null;
2091
+ useRegistry(config, pickRegistryMetadata(options));
2092
+ }
2093
+ function Compose({ providers, children }) {
2094
+ return providers.reduceRight(
2095
+ (acc, entry) => {
2096
+ if (Array.isArray(entry)) {
2097
+ const [Component2, props] = entry;
2098
+ return createElement(Component2, props, acc);
2099
+ }
2100
+ const Component = entry;
2101
+ return createElement(Component, null, acc);
2102
+ },
2103
+ createElement(Fragment$1, null, children)
2104
+ );
2105
+ }
2106
+
2107
+ export { Compose, ModuleBoundary, ModuleHost, PageControllerProvider, REGISTRY_SOURCES, RegistryProvider, applyRegistryConfig, createModuleRegistryDefinitions, createRegistryApplyContext, createRegistryOperations, createRegistryStore, defineModule, definePeer, hasOwnProperty, sortModules, useIsModuleInstalled, useModule, useModuleRegistration, useModuleState, usePage, usePageController, useRegistryEntries, useRegistryValue };
2108
+ //# sourceMappingURL=index.js.map
2109
+ //# sourceMappingURL=index.js.map