@blac/core 2.0.13 → 2.0.15

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 (379) hide show
  1. package/README.md +85 -3
  2. package/dist/Cubit-9jal5zdZ.cjs +1 -1
  3. package/dist/Cubit-BAUPiUF7.cjs +359 -286
  4. package/dist/Cubit-BBKF3PIg.js +269 -230
  5. package/dist/Cubit-BC70gaiA.js +453 -0
  6. package/dist/Cubit-BC70gaiA.js.map +1 -0
  7. package/dist/Cubit-BOgUZva7.js +342 -266
  8. package/dist/Cubit-BOxMvpfc.js +273 -232
  9. package/dist/Cubit-BTznt8zg.js +1 -1
  10. package/dist/Cubit-BogJXkLm.js +260 -225
  11. package/dist/Cubit-C-8R_8db.cjs +475 -0
  12. package/dist/Cubit-C-8R_8db.cjs.map +1 -0
  13. package/dist/Cubit-C3Mw3EoO.cjs +401 -0
  14. package/dist/Cubit-C3Mw3EoO.cjs.map +1 -0
  15. package/dist/Cubit-CO8Fr72L.cjs +447 -0
  16. package/dist/Cubit-CO8Fr72L.cjs.map +1 -0
  17. package/dist/Cubit-COfHT1Bm.cjs +300 -259
  18. package/dist/Cubit-CROWjjs9.js +481 -0
  19. package/dist/Cubit-CROWjjs9.js.map +1 -0
  20. package/dist/Cubit-CWP8Ddzx.cjs +510 -0
  21. package/dist/Cubit-CWP8Ddzx.cjs.map +1 -0
  22. package/dist/Cubit-CXxh9iol.js +284 -242
  23. package/dist/Cubit-CYOWfzQt.cjs +297 -254
  24. package/dist/Cubit-CZaf_fp4.cjs +1 -1
  25. package/dist/Cubit-C_dUEUdd.cjs +359 -286
  26. package/dist/Cubit-C_rxRCTN.cjs +523 -0
  27. package/dist/Cubit-C_rxRCTN.cjs.map +1 -0
  28. package/dist/Cubit-CcKgMEBO.js +281 -239
  29. package/dist/Cubit-CfT6Y1jl.js +328 -280
  30. package/dist/Cubit-CynJruuO.js +369 -0
  31. package/dist/Cubit-CynJruuO.js.map +1 -0
  32. package/dist/Cubit-D2vQ6nMb.js +342 -266
  33. package/dist/Cubit-D7jOZCoZ.js +342 -266
  34. package/dist/Cubit-D9j3IGPc.cjs +523 -0
  35. package/dist/Cubit-D9j3IGPc.cjs.map +1 -0
  36. package/dist/Cubit-DKEY9WYq.cjs +276 -240
  37. package/dist/Cubit-DMV_0TCp.js +481 -0
  38. package/dist/Cubit-DMV_0TCp.js.map +1 -0
  39. package/dist/Cubit-DP5DXPUK.js +342 -266
  40. package/dist/Cubit-DRFkzD2h.js +426 -0
  41. package/dist/Cubit-DRFkzD2h.js.map +1 -0
  42. package/dist/Cubit-DbnhTUaZ.cjs +359 -286
  43. package/dist/Cubit-DrqG3SP3.cjs +349 -300
  44. package/dist/Cubit-DsDkCo42.cjs +292 -250
  45. package/dist/Cubit-DwRw1E9D.cjs +289 -247
  46. package/dist/Cubit-Dw_kFBgc.js +1 -1
  47. package/dist/Cubit-KiXZCubP.cjs +1 -1
  48. package/dist/Cubit-Ksj7G4uR.js +342 -266
  49. package/dist/Cubit-MkjbpcPf.cjs +359 -286
  50. package/dist/Cubit-NRhvdDQ6.js +279 -239
  51. package/dist/Cubit-PMTXxI_u.js +1 -1
  52. package/dist/Cubit-VJuu2tt9.js +481 -0
  53. package/dist/Cubit-VJuu2tt9.js.map +1 -0
  54. package/dist/Cubit-jz922NKf.cjs +300 -257
  55. package/dist/Cubit-kU5_4jgC.cjs +359 -286
  56. package/dist/StateContainerRegistry-B4yVMYbx.cjs +1057 -0
  57. package/dist/StateContainerRegistry-B4yVMYbx.cjs.map +1 -0
  58. package/dist/StateContainerRegistry-BAcxouCu.js +683 -615
  59. package/dist/StateContainerRegistry-BK57H92E.js +701 -630
  60. package/dist/StateContainerRegistry-BRBATSrx.cjs +1030 -0
  61. package/dist/StateContainerRegistry-BRBATSrx.cjs.map +1 -0
  62. package/dist/StateContainerRegistry-BgBIKcQF.js +956 -0
  63. package/dist/StateContainerRegistry-BgBIKcQF.js.map +1 -0
  64. package/dist/StateContainerRegistry-BglEhqdA.js +669 -606
  65. package/dist/StateContainerRegistry-BhcnG0DF.js +625 -562
  66. package/dist/StateContainerRegistry-BpO5t-0i.js +642 -580
  67. package/dist/StateContainerRegistry-BqS-wpb_.js +957 -0
  68. package/dist/StateContainerRegistry-BqS-wpb_.js.map +1 -0
  69. package/dist/StateContainerRegistry-BrEGYPZT.cjs +1029 -0
  70. package/dist/StateContainerRegistry-BrEGYPZT.cjs.map +1 -0
  71. package/dist/StateContainerRegistry-Bxfne4A7.cjs +908 -0
  72. package/dist/StateContainerRegistry-Bxfne4A7.cjs.map +1 -0
  73. package/dist/StateContainerRegistry-C0E7vsgy.js +758 -0
  74. package/dist/StateContainerRegistry-C0E7vsgy.js.map +1 -0
  75. package/dist/StateContainerRegistry-C0I77Ndz.cjs +920 -0
  76. package/dist/StateContainerRegistry-C0I77Ndz.cjs.map +1 -0
  77. package/dist/StateContainerRegistry-CDH9mnQS.cjs +668 -614
  78. package/dist/StateContainerRegistry-CTOXUf75.cjs +695 -640
  79. package/dist/StateContainerRegistry-CX2CBOmv.cjs +739 -679
  80. package/dist/StateContainerRegistry-CXnnf2-l.js +867 -0
  81. package/dist/StateContainerRegistry-CXnnf2-l.js.map +1 -0
  82. package/dist/StateContainerRegistry-CehuIpK_.cjs +811 -0
  83. package/dist/StateContainerRegistry-CehuIpK_.cjs.map +1 -0
  84. package/dist/StateContainerRegistry-Ci0ajc5g.js +680 -612
  85. package/dist/StateContainerRegistry-Ck2-XmT_.js +587 -527
  86. package/dist/StateContainerRegistry-D1lVJFGL.cjs +706 -646
  87. package/dist/StateContainerRegistry-DC4N73O6.js +632 -569
  88. package/dist/StateContainerRegistry-DOuGI-l5.js +645 -582
  89. package/dist/StateContainerRegistry-DT66lr3I.cjs +651 -596
  90. package/dist/StateContainerRegistry-DmmzYa7S.js +974 -0
  91. package/dist/StateContainerRegistry-DmmzYa7S.js.map +1 -0
  92. package/dist/StateContainerRegistry-Upsrlg9G.cjs +709 -649
  93. package/dist/StateContainerRegistry-WznfcA-Q.js +855 -0
  94. package/dist/StateContainerRegistry-WznfcA-Q.js.map +1 -0
  95. package/dist/StateContainerRegistry-Yph6UCA_.js +637 -569
  96. package/dist/StateContainerRegistry-mseeTqSA.cjs +671 -616
  97. package/dist/StateContainerRegistry-pRNxHNFD.cjs +658 -603
  98. package/dist/StateContainerRegistry-vXMWtG7J.cjs +613 -561
  99. package/dist/StateContainerRegistry-v_prqMcI.cjs +663 -603
  100. package/dist/branded-BSeA_mZO.cjs.map +1 -1
  101. package/dist/branded-DCqi3De1.cjs +11 -11
  102. package/dist/branded-DwtzSsg0.js.map +1 -1
  103. package/dist/branded-Max3xOTA.js +6 -6
  104. package/dist/config-0ZD9i3wy.js +16 -0
  105. package/dist/config-0ZD9i3wy.js.map +1 -0
  106. package/dist/config-B3NIwDQv.cjs +20 -20
  107. package/dist/config-BKGHop0V.js +5 -5
  108. package/dist/config-BKoaAlmb.js +5 -5
  109. package/dist/config-BPj08-8h.cjs +32 -0
  110. package/dist/config-BPj08-8h.cjs.map +1 -0
  111. package/dist/config-BR0Xy-Tn.cjs +20 -20
  112. package/dist/config-B_4xXpvK.cjs +32 -0
  113. package/dist/config-B_4xXpvK.cjs.map +1 -0
  114. package/dist/config-BflrQM4_.cjs +32 -0
  115. package/dist/config-BflrQM4_.cjs.map +1 -0
  116. package/dist/config-BzObBsk2.cjs +32 -0
  117. package/dist/config-BzObBsk2.cjs.map +1 -0
  118. package/dist/config-C0yumL1H.cjs +32 -0
  119. package/dist/config-C0yumL1H.cjs.map +1 -0
  120. package/dist/config-C8xqVHTf.js +16 -0
  121. package/dist/config-C8xqVHTf.js.map +1 -0
  122. package/dist/config-CCUhIYIF.js +5 -5
  123. package/dist/config-CGo__MAt.js +16 -0
  124. package/dist/config-CGo__MAt.js.map +1 -0
  125. package/dist/config-CQH9fTY-.cjs +20 -20
  126. package/dist/config-CR_Bz7RD.js +5 -5
  127. package/dist/config-CTOa-yPN.cjs +20 -20
  128. package/dist/config-Cd7Q-B4g.js +16 -0
  129. package/dist/config-Cd7Q-B4g.js.map +1 -0
  130. package/dist/config-CmDEX-1o.js +16 -0
  131. package/dist/config-CmDEX-1o.js.map +1 -0
  132. package/dist/config-CoNMTnMA.cjs +32 -0
  133. package/dist/config-CoNMTnMA.cjs.map +1 -0
  134. package/dist/config-Cwj8-C1J.js +5 -5
  135. package/dist/config-D3jisfdj.cjs +20 -20
  136. package/dist/config-D4GifZQ4.js +5 -5
  137. package/dist/config-DDrSQGpQ.cjs +20 -20
  138. package/dist/config-DEcslxan.cjs +20 -20
  139. package/dist/config-DMNZ2YLV.cjs +20 -20
  140. package/dist/config-De9oQ6Ki.js +5 -5
  141. package/dist/config-DoHx0Xsl.js +16 -0
  142. package/dist/config-DoHx0Xsl.js.map +1 -0
  143. package/dist/config-DokTzpr8.cjs +20 -20
  144. package/dist/config-DslYBm4Z.js +5 -5
  145. package/dist/config-H6FAqbW4.cjs +20 -20
  146. package/dist/config-Yp645dGK.js +5 -5
  147. package/dist/config-ispAzOZV.js +5 -5
  148. package/dist/config.d.cts +72 -0
  149. package/dist/config.d.ts +72 -0
  150. package/dist/constants.d.cts +13 -0
  151. package/dist/constants.d.ts +13 -0
  152. package/dist/core/Cubit.d.ts +14 -4
  153. package/dist/core/StateContainer.d.ts +111 -11
  154. package/dist/core/StateContainerRegistry.d.ts +55 -11
  155. package/dist/core/symbols.d.ts +26 -0
  156. package/dist/debug.cjs +3 -3
  157. package/dist/debug.js +3 -3
  158. package/dist/decorators/blac.d.ts +17 -0
  159. package/dist/ensure-9VEq5H0L.js +3 -3
  160. package/dist/ensure-BB6xHQAF.cjs +14 -0
  161. package/dist/ensure-BB6xHQAF.cjs.map +1 -0
  162. package/dist/ensure-BNDfTzqg.cjs +8 -8
  163. package/dist/ensure-BVCnjU7r.js +343 -267
  164. package/dist/ensure-BbzGXjep.cjs +8 -8
  165. package/dist/ensure-BlIaQai6.js +9 -0
  166. package/dist/ensure-BlIaQai6.js.map +1 -0
  167. package/dist/ensure-Bm3oHxga.js +9 -0
  168. package/dist/ensure-Bm3oHxga.js.map +1 -0
  169. package/dist/ensure-C3eIRs6e.cjs +8 -8
  170. package/dist/ensure-CJZL7bcA.cjs +365 -292
  171. package/dist/ensure-CN6unBOe.cjs +8 -8
  172. package/dist/ensure-CU-B1ywv.js +3 -3
  173. package/dist/ensure-CWKzeno7.js +3 -3
  174. package/dist/ensure-CkENsuQ9.js +9 -0
  175. package/dist/ensure-CkENsuQ9.js.map +1 -0
  176. package/dist/ensure-Cm-4_LSh.cjs +14 -0
  177. package/dist/ensure-Cm-4_LSh.cjs.map +1 -0
  178. package/dist/ensure-Cqex5r1P.cjs +14 -0
  179. package/dist/ensure-Cqex5r1P.cjs.map +1 -0
  180. package/dist/ensure-Cv5AbNGZ.js +9 -0
  181. package/dist/ensure-Cv5AbNGZ.js.map +1 -0
  182. package/dist/ensure-D63lEMUK.cjs +8 -8
  183. package/dist/ensure-DGEtPU9A.cjs +8 -8
  184. package/dist/ensure-DM3qb336.cjs +14 -0
  185. package/dist/ensure-DM3qb336.cjs.map +1 -0
  186. package/dist/ensure-DME-_T0j.cjs +8 -8
  187. package/dist/ensure-DWd0GCYB.js +3 -3
  188. package/dist/ensure-DamKOP6q.cjs +8 -8
  189. package/dist/ensure-Dcfptl-A.js +9 -0
  190. package/dist/ensure-Dcfptl-A.js.map +1 -0
  191. package/dist/ensure-Def-EBWG.js +3 -3
  192. package/dist/ensure-DnHL5QiQ.cjs +14 -0
  193. package/dist/ensure-DnHL5QiQ.cjs.map +1 -0
  194. package/dist/ensure-Dr7I78Ku.cjs +8 -8
  195. package/dist/ensure-SLVdGd5b.js +3 -3
  196. package/dist/ensure-Sb92MCXu.js +3 -3
  197. package/dist/ensure-gFlvevGm.cjs +14 -0
  198. package/dist/ensure-gFlvevGm.cjs.map +1 -0
  199. package/dist/ensure-l2-H7S5W.js +3 -3
  200. package/dist/ensure-mkL-3qh8.js +9 -0
  201. package/dist/ensure-mkL-3qh8.js.map +1 -0
  202. package/dist/ensure-n80crSlX.js +3 -3
  203. package/dist/ensure-nCxg7MCN.js +3 -3
  204. package/dist/ensure-vS71MV4q.cjs +8 -8
  205. package/dist/index.cjs +37 -14
  206. package/dist/index.cjs.map +1 -1
  207. package/dist/index.d.cts +14 -4
  208. package/dist/index.d.ts +14 -4
  209. package/dist/index.js +23 -10
  210. package/dist/index.js.map +1 -1
  211. package/dist/management-6oQbmf0z.js +41 -0
  212. package/dist/management-6oQbmf0z.js.map +1 -0
  213. package/dist/management-B46QwA9Y.js +20 -11
  214. package/dist/management-B9yrRpeg.js +41 -0
  215. package/dist/management-B9yrRpeg.js.map +1 -0
  216. package/dist/management-BCKTEZ8Q.js +20 -11
  217. package/dist/management-BbMzdXbT.js +41 -0
  218. package/dist/management-BbMzdXbT.js.map +1 -0
  219. package/dist/management-Bg652agq.js +20 -11
  220. package/dist/management-BnedF5ZD.cjs +50 -50
  221. package/dist/management-BoUa99eB.cjs +79 -0
  222. package/dist/management-BoUa99eB.cjs.map +1 -0
  223. package/dist/management-C4SHcrJm.cjs +79 -0
  224. package/dist/management-C4SHcrJm.cjs.map +1 -0
  225. package/dist/management-CK-GL3wY.js +20 -11
  226. package/dist/management-CPhgY8OE.js +41 -0
  227. package/dist/management-CPhgY8OE.js.map +1 -0
  228. package/dist/management-CU_V3LIP.js +20 -11
  229. package/dist/management-CUwXDSi9.cjs +79 -0
  230. package/dist/management-CUwXDSi9.cjs.map +1 -0
  231. package/dist/management-CaqiyNzB.js +20 -11
  232. package/dist/management-Cin-JvYe.js +20 -11
  233. package/dist/management-ClaXym0F.cjs +50 -50
  234. package/dist/management-DL0Uzsoz.js +20 -11
  235. package/dist/management-DLdAQfqk.cjs +79 -0
  236. package/dist/management-DLdAQfqk.cjs.map +1 -0
  237. package/dist/management-DMZ8qpwr.cjs +50 -50
  238. package/dist/management-DTzcC6aD.cjs +79 -0
  239. package/dist/management-DTzcC6aD.cjs.map +1 -0
  240. package/dist/management-DYLNyj9p.cjs +50 -50
  241. package/dist/management-Dag9u4t6.cjs +50 -50
  242. package/dist/management-DbMRdDBo.cjs +50 -50
  243. package/dist/management-DfnDAKmP.js +41 -0
  244. package/dist/management-DfnDAKmP.js.map +1 -0
  245. package/dist/management-DjBU1gtb.cjs +50 -50
  246. package/dist/management-DwCozsY8.js +20 -11
  247. package/dist/management-H4m3ciJO.js +32 -0
  248. package/dist/management-H4m3ciJO.js.map +1 -0
  249. package/dist/management-Xo3A6Za3.cjs +79 -0
  250. package/dist/management-Xo3A6Za3.cjs.map +1 -0
  251. package/dist/management-ZU2YzOkr.js +18 -10
  252. package/dist/management-baPDwA9n.cjs +50 -50
  253. package/dist/management-jQGCvZNN.cjs +44 -44
  254. package/dist/management-ry_KteFK.cjs +50 -50
  255. package/dist/plugin/BlacPlugin.d.ts +89 -15
  256. package/dist/plugin/PluginManager.d.ts +65 -5
  257. package/dist/plugins.cjs +1 -1
  258. package/dist/plugins.d.cts +2 -2
  259. package/dist/plugins.d.ts +2 -2
  260. package/dist/plugins.js +1 -1
  261. package/dist/registry/acquire.d.ts +9 -2
  262. package/dist/registry/ensure.d.ts +2 -2
  263. package/dist/registry/index.d.ts +1 -1
  264. package/dist/resolve-dependencies-B2QggQAi.js +641 -558
  265. package/dist/resolve-dependencies-B6JDXvpr.js +651 -566
  266. package/dist/resolve-dependencies-BAKAoD0U.js +878 -0
  267. package/dist/resolve-dependencies-BAKAoD0U.js.map +1 -0
  268. package/dist/resolve-dependencies-BFZQq60Y.cjs +724 -666
  269. package/dist/resolve-dependencies-BGafS3Ww.js +643 -561
  270. package/dist/resolve-dependencies-BHd34gS3.cjs +724 -666
  271. package/dist/resolve-dependencies-BNeayhbQ.cjs +732 -671
  272. package/dist/resolve-dependencies-BWEMpuDy.js +641 -558
  273. package/dist/resolve-dependencies-BiWkW2eS.js +643 -561
  274. package/dist/resolve-dependencies-BjxCztYD.js +739 -0
  275. package/dist/resolve-dependencies-BjxCztYD.js.map +1 -0
  276. package/dist/resolve-dependencies-BlyBV0hB.cjs +969 -0
  277. package/dist/resolve-dependencies-BlyBV0hB.cjs.map +1 -0
  278. package/dist/resolve-dependencies-By26rT_i.js +651 -566
  279. package/dist/resolve-dependencies-C9Kf7AzY.cjs +724 -666
  280. package/dist/resolve-dependencies-CTzV1txG.js +643 -561
  281. package/dist/resolve-dependencies-CWjuGHiF.cjs +969 -0
  282. package/dist/resolve-dependencies-CWjuGHiF.cjs.map +1 -0
  283. package/dist/resolve-dependencies-ClSsP0DJ.cjs +722 -663
  284. package/dist/resolve-dependencies-D0vTzZgs.js +643 -561
  285. package/dist/resolve-dependencies-D2WnZMF-.cjs +724 -666
  286. package/dist/resolve-dependencies-DCBLTeza.cjs +969 -0
  287. package/dist/resolve-dependencies-DCBLTeza.cjs.map +1 -0
  288. package/dist/resolve-dependencies-DMlqYJR2.js +643 -561
  289. package/dist/resolve-dependencies-DP6U1EYB.cjs +840 -0
  290. package/dist/resolve-dependencies-DP6U1EYB.cjs.map +1 -0
  291. package/dist/resolve-dependencies-DSQNXvnV.cjs +724 -666
  292. package/dist/resolve-dependencies-DV3HO_uH.js +878 -0
  293. package/dist/resolve-dependencies-DV3HO_uH.js.map +1 -0
  294. package/dist/resolve-dependencies-DXwMhP0Y.js +878 -0
  295. package/dist/resolve-dependencies-DXwMhP0Y.js.map +1 -0
  296. package/dist/resolve-dependencies-DbRWlt9u.js +878 -0
  297. package/dist/resolve-dependencies-DbRWlt9u.js.map +1 -0
  298. package/dist/resolve-dependencies-DcUUva2P.cjs +724 -666
  299. package/dist/resolve-dependencies-Dd8T6TLt.cjs +724 -666
  300. package/dist/resolve-dependencies-Dfdp_DZd.cjs +732 -671
  301. package/dist/resolve-dependencies-GJ8PNyNB.cjs +969 -0
  302. package/dist/resolve-dependencies-GJ8PNyNB.cjs.map +1 -0
  303. package/dist/resolve-dependencies-KSpTt4jy.cjs +722 -663
  304. package/dist/resolve-dependencies-Nvjp4CwS.js +643 -561
  305. package/dist/resolve-dependencies-f-QUqYiL.js +643 -561
  306. package/dist/testing.cjs +27 -20
  307. package/dist/testing.cjs.map +1 -1
  308. package/dist/testing.d.cts +22 -1
  309. package/dist/testing.d.ts +22 -1
  310. package/dist/testing.js +27 -21
  311. package/dist/testing.js.map +1 -1
  312. package/dist/tracked-B77j2g9M.js +171 -151
  313. package/dist/tracked-BDVi2LKM.cjs +196 -175
  314. package/dist/tracked-BFdJCzL0.cjs +242 -0
  315. package/dist/tracked-BFdJCzL0.cjs.map +1 -0
  316. package/dist/tracked-BH-gX4T1.cjs +196 -175
  317. package/dist/tracked-BTHok3Dl.cjs +196 -175
  318. package/dist/tracked-BTbFkFeM.js +186 -166
  319. package/dist/tracked-BU_OBWqM.cjs +242 -0
  320. package/dist/tracked-BU_OBWqM.cjs.map +1 -0
  321. package/dist/tracked-BfctH2es.cjs +242 -0
  322. package/dist/tracked-BfctH2es.cjs.map +1 -0
  323. package/dist/tracked-BhQtzUhZ.js +186 -166
  324. package/dist/tracked-BnqrYXiO.js +212 -0
  325. package/dist/tracked-BnqrYXiO.js.map +1 -0
  326. package/dist/tracked-BtgFOGup.js +212 -0
  327. package/dist/tracked-BtgFOGup.js.map +1 -0
  328. package/dist/tracked-C3nIS4J7.cjs +242 -0
  329. package/dist/tracked-C3nIS4J7.cjs.map +1 -0
  330. package/dist/tracked-C52awNV9.js +171 -151
  331. package/dist/tracked-CGzduF2m.js +186 -166
  332. package/dist/tracked-CK_-ixtX.cjs +196 -175
  333. package/dist/tracked-CLlvURln.js +186 -166
  334. package/dist/tracked-CgHWmuGC.cjs +211 -190
  335. package/dist/tracked-CoAlC8fs.js +171 -151
  336. package/dist/tracked-D3Xjm1H1.cjs +211 -190
  337. package/dist/tracked-DB6yMV5F.js +212 -0
  338. package/dist/tracked-DB6yMV5F.js.map +1 -0
  339. package/dist/tracked-DBn-bs_G.js +171 -151
  340. package/dist/tracked-DMBTDF0P.js +171 -151
  341. package/dist/tracked-DN3h3Rp1.js +171 -151
  342. package/dist/tracked-DOGh1Q5Z.cjs +242 -0
  343. package/dist/tracked-DOGh1Q5Z.cjs.map +1 -0
  344. package/dist/tracked-DUkp4zve.cjs +196 -175
  345. package/dist/tracked-D_ou7mYG.js +212 -0
  346. package/dist/tracked-D_ou7mYG.js.map +1 -0
  347. package/dist/tracked-Dcu6EATB.js +171 -151
  348. package/dist/tracked-GvAJQVAI.cjs +227 -196
  349. package/dist/tracked-O2lv-kJV.cjs +211 -190
  350. package/dist/tracked-WF6aXuAo.js +186 -162
  351. package/dist/tracked-d_sQWU3c.cjs +196 -175
  352. package/dist/tracked-n9TMK-30.cjs +196 -175
  353. package/dist/tracked-njU-_pVa.cjs +211 -190
  354. package/dist/tracked-zAgmKIlC.js +212 -0
  355. package/dist/tracked-zAgmKIlC.js.map +1 -0
  356. package/dist/tracking/dependency-manager.d.ts +33 -29
  357. package/dist/tracking/index.d.ts +16 -1
  358. package/dist/tracking/iteration-perf.bench.d.ts +1 -0
  359. package/dist/tracking/path-utils.d.ts +18 -1
  360. package/dist/tracking/resolve-dependencies.d.ts +3 -1
  361. package/dist/tracking/tracked.d.ts +37 -34
  362. package/dist/tracking/tracking-proxy.d.ts +94 -47
  363. package/dist/tracking.cjs +12 -9
  364. package/dist/tracking.js +32 -2
  365. package/dist/types/utilities.d.ts +15 -3
  366. package/dist/types.cjs +1 -1
  367. package/dist/types.js +1 -1
  368. package/dist/utils/static-props.d.ts +14 -0
  369. package/dist/utils/structural-key.d.ts +14 -0
  370. package/dist/watch/watch.d.ts +1 -1
  371. package/dist/watch-BpwaUL8r.cjs +68 -0
  372. package/dist/watch-BpwaUL8r.cjs.map +1 -0
  373. package/dist/watch-DWCqXllW.js +57 -0
  374. package/dist/watch-DWCqXllW.js.map +1 -0
  375. package/dist/watch-entry.cjs +3 -6
  376. package/dist/watch-entry.d.cts +1 -3
  377. package/dist/watch-entry.d.ts +1 -3
  378. package/dist/watch-entry.js +2 -2
  379. package/package.json +4 -14
@@ -1,693 +1,753 @@
1
1
  //#region src/constants.ts
2
2
  /**
3
- * Default configuration constants for BlaC
4
- *
5
- * Centralized location for all magic numbers and default values.
6
- */
3
+ * Default configuration constants for BlaC
4
+ *
5
+ * Centralized location for all magic numbers and default values.
6
+ */
7
7
  /**
8
- * Default configuration constants for BlaC
9
- */
8
+ * Default configuration constants for BlaC
9
+ */
10
10
  const BLAC_DEFAULTS = {
11
- DEFAULT_INSTANCE_KEY: "default",
12
- MAX_GETTER_DEPTH: 10
11
+ DEFAULT_INSTANCE_KEY: 'default',
12
+ MAX_GETTER_DEPTH: 10,
13
13
  };
14
14
  /**
15
- * Static property names for StateContainer classes
16
- * Used for feature flags and configuration on bloc classes
17
- */
15
+ * Static property names for StateContainer classes
16
+ * Used for feature flags and configuration on bloc classes
17
+ */
18
18
  const BLAC_STATIC_PROPS = {
19
- KEEP_ALIVE: "keepAlive",
20
- EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools"
19
+ KEEP_ALIVE: 'keepAlive',
20
+ EXCLUDE_FROM_DEVTOOLS: '__excludeFromDevTools',
21
21
  };
22
22
  /**
23
- * Standard error message prefix
24
- */
25
- const BLAC_ERROR_PREFIX = "[BlaC]";
23
+ * Standard error message prefix
24
+ */
25
+ const BLAC_ERROR_PREFIX = '[BlaC]';
26
26
  //#endregion
27
27
  //#region src/plugin/PluginManager.ts
28
28
  /**
29
- * Manages plugin lifecycle for the BlaC state management system.
30
- * Plugins receive notifications about state container lifecycle events.
31
- *
32
- * @example
33
- * ```ts
34
- * const manager = createPluginManager(registry);
35
- * manager.install(myPlugin, { environment: 'development' });
36
- * ```
37
- */
29
+ * Manages plugin lifecycle for the BlaC state management system.
30
+ * Plugins receive notifications about state container lifecycle events.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const manager = createPluginManager(registry);
35
+ * manager.install(myPlugin, { environment: 'development' });
36
+ * ```
37
+ */
38
38
  var PluginManager = class {
39
- /**
40
- * Create a new PluginManager
41
- * @param registry - The StateContainerRegistry to monitor for lifecycle events
42
- */
43
- constructor(registry) {
44
- this.plugins = /* @__PURE__ */ new Map();
45
- this.lifecycleUnsubscribers = [];
46
- this.registry = registry;
47
- this.setupLifecycleHooks();
48
- }
49
- /**
50
- * Install a plugin with optional configuration
51
- * @param plugin - The plugin to install
52
- * @param config - Optional plugin configuration
53
- * @throws Error if plugin is already installed
54
- */
55
- install(plugin, config = {}) {
56
- const effectiveConfig = {
57
- enabled: true,
58
- environment: "all",
59
- ...config
60
- };
61
- if (!this.shouldEnablePlugin(effectiveConfig)) {
62
- console.log(`[BlaC] Plugin "${plugin.name}" skipped (environment mismatch)`);
63
- return;
64
- }
65
- if (this.plugins.has(plugin.name)) throw new Error(`Plugin "${plugin.name}" is already installed`);
66
- const context = this.createPluginContext();
67
- this.plugins.set(plugin.name, {
68
- plugin,
69
- config: effectiveConfig,
70
- context
71
- });
72
- if (plugin.onInstall) try {
73
- plugin.onInstall(context);
74
- } catch (error) {
75
- console.error(`[BlaC] Error installing plugin "${plugin.name}":`, error);
76
- this.plugins.delete(plugin.name);
77
- throw error;
78
- }
79
- console.log(`[BlaC] Plugin "${plugin.name}" v${plugin.version} installed`);
80
- }
81
- /**
82
- * Uninstall a plugin by name
83
- * @param pluginName - The name of the plugin to uninstall
84
- * @throws Error if plugin is not installed
85
- */
86
- uninstall(pluginName) {
87
- const installed = this.plugins.get(pluginName);
88
- if (!installed) throw new Error(`Plugin "${pluginName}" is not installed`);
89
- if (installed.plugin.onUninstall) try {
90
- installed.plugin.onUninstall();
91
- } catch (error) {
92
- console.error(`[BlaC] Error uninstalling plugin "${pluginName}":`, error);
93
- }
94
- this.plugins.delete(pluginName);
95
- console.log(`[BlaC] Plugin "${pluginName}" uninstalled`);
96
- }
97
- /**
98
- * Get an installed plugin by name
99
- * @param pluginName - The name of the plugin to retrieve
100
- * @returns The plugin instance or undefined if not found
101
- */
102
- getPlugin(pluginName) {
103
- return this.plugins.get(pluginName)?.plugin;
104
- }
105
- /**
106
- * Get all installed plugins
107
- * @returns Array of all installed plugins
108
- */
109
- getAllPlugins() {
110
- return Array.from(this.plugins.values()).map((p) => p.plugin);
111
- }
112
- /**
113
- * Check if a plugin is installed
114
- * @param pluginName - The name of the plugin to check
115
- * @returns true if the plugin is installed
116
- */
117
- hasPlugin(pluginName) {
118
- return this.plugins.has(pluginName);
119
- }
120
- /**
121
- * Uninstall all plugins
122
- */
123
- clear() {
124
- for (const name of this.plugins.keys()) this.uninstall(name);
125
- }
126
- destroy() {
127
- this.clear();
128
- for (const unsub of this.lifecycleUnsubscribers) unsub();
129
- this.lifecycleUnsubscribers = [];
130
- }
131
- /**
132
- * Setup lifecycle hooks to notify plugins
133
- */
134
- setupLifecycleHooks() {
135
- this.lifecycleUnsubscribers = [
136
- this.registry.on("created", (instance) => {
137
- this.notifyPlugins("onInstanceCreated", instance);
138
- }),
139
- this.registry.on("stateChanged", (instance, previousState, currentState) => {
140
- this.notifyPlugins("onStateChanged", instance, previousState, currentState);
141
- }),
142
- this.registry.on("disposed", (instance) => {
143
- this.notifyPlugins("onInstanceDisposed", instance);
144
- }),
145
- this.registry.on("refAcquired", (instance, refId) => {
146
- this.notifyPlugins("onRefAcquired", instance, refId);
147
- }),
148
- this.registry.on("refReleased", (instance, refId) => {
149
- this.notifyPlugins("onRefReleased", instance, refId);
150
- })
151
- ];
152
- }
153
- /**
154
- * Notify all plugins of a lifecycle event
155
- */
156
- notifyPlugins(hookName, ...args) {
157
- for (const { plugin, config, context } of this.plugins.values()) {
158
- if (!config.enabled) continue;
159
- const hook = plugin[hookName];
160
- if (typeof hook === "function") try {
161
- hook.apply(plugin, [...args, context]);
162
- } catch (error) {
163
- console.error(`[BlaC] Error in plugin "${plugin.name}" ${hookName}:`, error);
164
- }
165
- }
166
- }
167
- /**
168
- * Create plugin context with safe API access
169
- */
170
- createPluginContext() {
171
- return {
172
- getInstanceMetadata: (instance) => {
173
- return {
174
- id: instance.instanceId,
175
- className: instance.constructor.name,
176
- isDisposed: instance.isDisposed,
177
- name: instance.name,
178
- createdAt: instance.createdAt,
179
- state: instance.state,
180
- hydrationStatus: instance.hydrationStatus,
181
- isHydrated: instance.isHydrated,
182
- hydrationError: instance.hydrationError,
183
- changedWhileHydrating: instance.changedWhileHydrating
184
- };
185
- },
186
- getState: (instance) => {
187
- return instance.state;
188
- },
189
- getHydrationStatus: (instance) => {
190
- return instance.hydrationStatus;
191
- },
192
- startHydration: (instance) => {
193
- instance.beginHydration();
194
- },
195
- applyHydratedState: (instance, state) => {
196
- return instance.applyHydratedState(state);
197
- },
198
- finishHydration: (instance) => {
199
- instance.finishHydration();
200
- },
201
- failHydration: (instance, error) => {
202
- instance.failHydration(error);
203
- },
204
- waitForHydration: (instance) => {
205
- return instance.waitForHydration();
206
- },
207
- queryInstances: (typeClass) => {
208
- return this.registry.getAll(typeClass);
209
- },
210
- getAllTypes: () => {
211
- return this.registry.getTypes();
212
- },
213
- getStats: () => {
214
- return this.registry.getStats();
215
- },
216
- getRefIds: (instanceId) => {
217
- for (const Type of this.registry.getTypes()) {
218
- const map = this.registry.getInstancesMap(Type);
219
- for (const [, entry] of map) if (entry.instance.instanceId === instanceId) return Array.from(entry.refs.keys());
220
- }
221
- return [];
222
- }
223
- };
224
- }
225
- /**
226
- * Check if plugin should be enabled based on environment
227
- */
228
- shouldEnablePlugin(config) {
229
- if (!config.enabled) return false;
230
- if (config.environment === "all") return true;
231
- return this.getCurrentEnvironment() === config.environment;
232
- }
233
- /**
234
- * Get current environment
235
- */
236
- getCurrentEnvironment() {
237
- if (typeof process !== "undefined") {
238
- if (process.env.NODE_ENV === "test") return "test";
239
- if (process.env.NODE_ENV === "production") return "production";
240
- return "development";
241
- }
242
- return "development";
243
- }
39
+ /**
40
+ * Create a new PluginManager
41
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
42
+ */
43
+ constructor(registry) {
44
+ this.plugins = /* @__PURE__ */ new Map();
45
+ this.lifecycleUnsubscribers = [];
46
+ this.registry = registry;
47
+ this.setupLifecycleHooks();
48
+ }
49
+ /**
50
+ * Install a plugin with optional configuration
51
+ * @param plugin - The plugin to install
52
+ * @param config - Optional plugin configuration
53
+ * @throws Error if plugin is already installed
54
+ */
55
+ install(plugin, config = {}) {
56
+ const effectiveConfig = {
57
+ enabled: true,
58
+ environment: 'all',
59
+ ...config,
60
+ };
61
+ if (!this.shouldEnablePlugin(effectiveConfig)) {
62
+ console.log(
63
+ `[BlaC] Plugin "${plugin.name}" skipped (environment mismatch)`,
64
+ );
65
+ return;
66
+ }
67
+ if (this.plugins.has(plugin.name))
68
+ throw new Error(`Plugin "${plugin.name}" is already installed`);
69
+ const context = this.createPluginContext();
70
+ this.plugins.set(plugin.name, {
71
+ plugin,
72
+ config: effectiveConfig,
73
+ context,
74
+ });
75
+ if (plugin.onInstall)
76
+ try {
77
+ plugin.onInstall(context);
78
+ } catch (error) {
79
+ console.error(
80
+ `[BlaC] Error installing plugin "${plugin.name}":`,
81
+ error,
82
+ );
83
+ this.plugins.delete(plugin.name);
84
+ throw error;
85
+ }
86
+ console.log(`[BlaC] Plugin "${plugin.name}" v${plugin.version} installed`);
87
+ }
88
+ /**
89
+ * Uninstall a plugin by name
90
+ * @param pluginName - The name of the plugin to uninstall
91
+ * @throws Error if plugin is not installed
92
+ */
93
+ uninstall(pluginName) {
94
+ const installed = this.plugins.get(pluginName);
95
+ if (!installed) throw new Error(`Plugin "${pluginName}" is not installed`);
96
+ if (installed.plugin.onUninstall)
97
+ try {
98
+ installed.plugin.onUninstall();
99
+ } catch (error) {
100
+ console.error(
101
+ `[BlaC] Error uninstalling plugin "${pluginName}":`,
102
+ error,
103
+ );
104
+ }
105
+ this.plugins.delete(pluginName);
106
+ console.log(`[BlaC] Plugin "${pluginName}" uninstalled`);
107
+ }
108
+ /**
109
+ * Get an installed plugin by name
110
+ * @param pluginName - The name of the plugin to retrieve
111
+ * @returns The plugin instance or undefined if not found
112
+ */
113
+ getPlugin(pluginName) {
114
+ return this.plugins.get(pluginName)?.plugin;
115
+ }
116
+ /**
117
+ * Get all installed plugins
118
+ * @returns Array of all installed plugins
119
+ */
120
+ getAllPlugins() {
121
+ return Array.from(this.plugins.values()).map((p) => p.plugin);
122
+ }
123
+ /**
124
+ * Check if a plugin is installed
125
+ * @param pluginName - The name of the plugin to check
126
+ * @returns true if the plugin is installed
127
+ */
128
+ hasPlugin(pluginName) {
129
+ return this.plugins.has(pluginName);
130
+ }
131
+ /**
132
+ * Uninstall all plugins
133
+ */
134
+ clear() {
135
+ for (const name of this.plugins.keys()) this.uninstall(name);
136
+ }
137
+ destroy() {
138
+ this.clear();
139
+ for (const unsub of this.lifecycleUnsubscribers) unsub();
140
+ this.lifecycleUnsubscribers = [];
141
+ }
142
+ /**
143
+ * Setup lifecycle hooks to notify plugins
144
+ */
145
+ setupLifecycleHooks() {
146
+ this.lifecycleUnsubscribers = [
147
+ this.registry.on('created', (instance) => {
148
+ this.notifyPlugins('onInstanceCreated', instance);
149
+ }),
150
+ this.registry.on(
151
+ 'stateChanged',
152
+ (instance, previousState, currentState) => {
153
+ this.notifyPlugins(
154
+ 'onStateChanged',
155
+ instance,
156
+ previousState,
157
+ currentState,
158
+ );
159
+ },
160
+ ),
161
+ this.registry.on('disposed', (instance) => {
162
+ this.notifyPlugins('onInstanceDisposed', instance);
163
+ }),
164
+ this.registry.on('refAcquired', (instance, refId) => {
165
+ this.notifyPlugins('onRefAcquired', instance, refId);
166
+ }),
167
+ this.registry.on('refReleased', (instance, refId) => {
168
+ this.notifyPlugins('onRefReleased', instance, refId);
169
+ }),
170
+ ];
171
+ }
172
+ /**
173
+ * Notify all plugins of a lifecycle event
174
+ */
175
+ notifyPlugins(hookName, ...args) {
176
+ for (const { plugin, config, context } of this.plugins.values()) {
177
+ if (!config.enabled) continue;
178
+ const hook = plugin[hookName];
179
+ if (typeof hook === 'function')
180
+ try {
181
+ hook.apply(plugin, [...args, context]);
182
+ } catch (error) {
183
+ console.error(
184
+ `[BlaC] Error in plugin "${plugin.name}" ${hookName}:`,
185
+ error,
186
+ );
187
+ }
188
+ }
189
+ }
190
+ /**
191
+ * Create plugin context with safe API access
192
+ */
193
+ createPluginContext() {
194
+ return {
195
+ getInstanceMetadata: (instance) => {
196
+ return {
197
+ id: instance.instanceId,
198
+ className: instance.constructor.name,
199
+ isDisposed: instance.isDisposed,
200
+ name: instance.name,
201
+ createdAt: instance.createdAt,
202
+ state: instance.state,
203
+ hydrationStatus: instance.hydrationStatus,
204
+ isHydrated: instance.isHydrated,
205
+ hydrationError: instance.hydrationError,
206
+ changedWhileHydrating: instance.changedWhileHydrating,
207
+ };
208
+ },
209
+ getState: (instance) => {
210
+ return instance.state;
211
+ },
212
+ getHydrationStatus: (instance) => {
213
+ return instance.hydrationStatus;
214
+ },
215
+ startHydration: (instance) => {
216
+ instance.beginHydration();
217
+ },
218
+ applyHydratedState: (instance, state) => {
219
+ return instance.applyHydratedState(state);
220
+ },
221
+ finishHydration: (instance) => {
222
+ instance.finishHydration();
223
+ },
224
+ failHydration: (instance, error) => {
225
+ instance.failHydration(error);
226
+ },
227
+ waitForHydration: (instance) => {
228
+ return instance.waitForHydration();
229
+ },
230
+ queryInstances: (typeClass) => {
231
+ return this.registry.getAll(typeClass);
232
+ },
233
+ getAllTypes: () => {
234
+ return this.registry.getTypes();
235
+ },
236
+ getStats: () => {
237
+ return this.registry.getStats();
238
+ },
239
+ getRefIds: (instanceId) => {
240
+ for (const Type of this.registry.getTypes()) {
241
+ const map = this.registry.getInstancesMap(Type);
242
+ for (const [, entry] of map)
243
+ if (entry.instance.instanceId === instanceId)
244
+ return Array.from(entry.refs.keys());
245
+ }
246
+ return [];
247
+ },
248
+ };
249
+ }
250
+ /**
251
+ * Check if plugin should be enabled based on environment
252
+ */
253
+ shouldEnablePlugin(config) {
254
+ if (!config.enabled) return false;
255
+ if (config.environment === 'all') return true;
256
+ return this.getCurrentEnvironment() === config.environment;
257
+ }
258
+ /**
259
+ * Get current environment
260
+ */
261
+ getCurrentEnvironment() {
262
+ if (typeof process !== 'undefined') {
263
+ if (process.env.NODE_ENV === 'test') return 'test';
264
+ if (process.env.NODE_ENV === 'production') return 'production';
265
+ return 'development';
266
+ }
267
+ return 'development';
268
+ }
244
269
  };
245
270
  /**
246
- * Create a plugin manager instance
247
- * @param registry - The StateContainerRegistry to monitor for lifecycle events
248
- * @returns A new PluginManager instance
249
- */
271
+ * Create a plugin manager instance
272
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
273
+ * @returns A new PluginManager instance
274
+ */
250
275
  function createPluginManager(registry) {
251
- return new PluginManager(registry);
276
+ return new PluginManager(registry);
252
277
  }
253
278
  //#endregion
254
279
  //#region src/utils/static-props.ts
255
280
  /**
256
- * Utility functions for accessing static properties on StateContainer classes
257
- */
281
+ * Utility functions for accessing static properties on StateContainer classes
282
+ */
258
283
  /**
259
- * Get a static property from a class constructor
260
- * Type-safe helper that avoids (Type as any) casts
261
- *
262
- * @param Type - The class constructor
263
- * @param propName - The property name to access
264
- * @param defaultValue - Optional default value if property is undefined
265
- * @returns The property value or default
266
- */
284
+ * Get a static property from a class constructor
285
+ * Type-safe helper that avoids (Type as any) casts
286
+ *
287
+ * @param Type - The class constructor
288
+ * @param propName - The property name to access
289
+ * @param defaultValue - Optional default value if property is undefined
290
+ * @returns The property value or default
291
+ */
267
292
  function getStaticProp(Type, propName, defaultValue) {
268
- return Type[propName] ?? defaultValue;
293
+ return Type[propName] ?? defaultValue;
269
294
  }
270
295
  /**
271
- * Check if a class is marked as keepAlive.
272
- * KeepAlive classes are never auto-disposed when ref count reaches 0.
273
- * @param Type - The class constructor to check
274
- * @returns true if the class has `static keepAlive = true`
275
- */
296
+ * Check if a class is marked as keepAlive.
297
+ * KeepAlive classes are never auto-disposed when ref count reaches 0.
298
+ * @param Type - The class constructor to check
299
+ * @returns true if the class has `static keepAlive = true`
300
+ */
276
301
  function isKeepAliveClass(Type) {
277
- return getStaticProp(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;
302
+ return getStaticProp(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;
278
303
  }
279
304
  //#endregion
280
305
  //#region src/core/StateContainerRegistry.ts
281
306
  /**
282
- * Central registry for managing StateContainer instances.
283
- * Handles instance lifecycle, named ref tracking, and lifecycle event emission.
284
- *
285
- * @example
286
- * ```ts
287
- * const registry = new StateContainerRegistry();
288
- * const instance = registry.acquire(MyBloc); // ownership, must release
289
- * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
290
- * registry.on('stateChanged', (container, prev, next) => {
291
- * console.log('State changed:', prev, '->', next);
292
- * });
293
- * ```
294
- */
307
+ * Central registry for managing StateContainer instances.
308
+ * Handles instance lifecycle, named ref tracking, and lifecycle event emission.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * const registry = new StateContainerRegistry();
313
+ * const instance = registry.acquire(MyBloc); // ownership, must release
314
+ * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
315
+ * registry.on('stateChanged', (container, prev, next) => {
316
+ * console.log('State changed:', prev, '->', next);
317
+ * });
318
+ * ```
319
+ */
295
320
  var StateContainerRegistry = class {
296
- constructor() {
297
- this.instancesByConstructor = /* @__PURE__ */ new WeakMap();
298
- this.types = /* @__PURE__ */ new Set();
299
- this.registeredTypeNames = /* @__PURE__ */ new Set();
300
- this.listeners = /* @__PURE__ */ new Map();
301
- this._stateChangedListenerCount = 0;
302
- this._pendingStateChanges = null;
303
- this._autoRefIdCounter = 0;
304
- }
305
- /**
306
- * Register a type for lifecycle event tracking
307
- * @param constructor - The StateContainer class constructor
308
- */
309
- registerType(constructor) {
310
- this.types.add(constructor);
311
- }
312
- /**
313
- * Register a StateContainer class with configuration
314
- * @param constructor - The StateContainer class constructor
315
- * @throws Error if type is already registered
316
- */
317
- register(constructor) {
318
- const className = constructor.name;
319
- if (this.registeredTypeNames.has(className)) throw new Error(`${BLAC_ERROR_PREFIX} Type "${className}" is already registered`);
320
- this.registeredTypeNames.add(className);
321
- this.registerType(constructor);
322
- }
323
- ensureInstancesMap(Type) {
324
- let instances = this.instancesByConstructor.get(Type);
325
- if (!instances) {
326
- instances = /* @__PURE__ */ new Map();
327
- this.instancesByConstructor.set(Type, instances);
328
- }
329
- return instances;
330
- }
331
- /**
332
- * Get the instances Map for a specific class (public API for stats/debugging)
333
- */
334
- getInstancesMap(Type) {
335
- return this.instancesByConstructor.get(Type) || /* @__PURE__ */ new Map();
336
- }
337
- /**
338
- * Acquire an instance with ref tracking (ownership semantics).
339
- * Creates a new instance if one doesn't exist, or returns existing and adds a ref.
340
- * You must call `release()` with the same refId when done.
341
- * @param Type - The StateContainer class constructor
342
- * @param instanceKey - Instance key (defaults to 'default')
343
- * @param options - Acquisition options
344
- * @param options.canCreate - Whether to create new instance if not found (default: true)
345
- * @param options.countRef - Whether to add a reference (default: true)
346
- * @param options.refId - Named reference ID for debugging; auto-generated if omitted
347
- * @returns The state container instance
348
- */
349
- acquire(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY, options = {}) {
350
- const { canCreate = true, countRef = true } = options;
351
- const config = { instanceId: instanceKey };
352
- const instances = this.ensureInstancesMap(Type);
353
- let entry = instances.get(instanceKey);
354
- if (entry?.instance.isDisposed) {
355
- instances.delete(instanceKey);
356
- entry = void 0;
357
- }
358
- if (entry && countRef) {
359
- const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
360
- entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);
361
- this.emit("refAcquired", entry.instance, refId);
362
- }
363
- if (entry) return entry.instance;
364
- if (!canCreate) throw new Error(`${BLAC_ERROR_PREFIX} ${Type.name} instance "${instanceKey}" not found and creation is disabled.`);
365
- const instance = new Type();
366
- instance.initConfig(config);
367
- const initialRefs = /* @__PURE__ */ new Map();
368
- let initialRefId;
369
- if (countRef) {
370
- initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
371
- initialRefs.set(initialRefId, 1);
372
- }
373
- instances.set(instanceKey, {
374
- instance,
375
- refs: initialRefs
376
- });
377
- this.registerType(Type);
378
- if (initialRefId) this.emit("refAcquired", instance, initialRefId);
379
- return instance;
380
- }
381
- /**
382
- * Borrow an existing instance without adding a ref (borrowing semantics).
383
- * Tracks cross-bloc dependency for reactive updates.
384
- * @param Type - The StateContainer class constructor
385
- * @param instanceKey - Instance key (defaults to 'default')
386
- * @returns The state container instance
387
- * @throws Error if instance doesn't exist
388
- */
389
- borrow(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
390
- return this.acquire(Type, instanceKey, {
391
- canCreate: false,
392
- countRef: false
393
- });
394
- }
395
- /**
396
- * Safely borrow an existing instance (borrowing semantics with error handling).
397
- * Returns discriminated union for type-safe conditional access.
398
- * @param Type - The StateContainer class constructor
399
- * @param instanceKey - Instance key (defaults to 'default')
400
- * @returns Discriminated union with either the instance or an error
401
- */
402
- borrowSafe(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
403
- try {
404
- return {
405
- error: null,
406
- instance: this.borrow(Type, instanceKey)
407
- };
408
- } catch (error) {
409
- return {
410
- error,
411
- instance: null
412
- };
413
- }
414
- }
415
- /**
416
- * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
417
- * Gets existing instance OR creates it if it doesn't exist, without adding a ref.
418
- * Tracks cross-bloc dependency for reactive updates.
419
- *
420
- * Use this in bloc-to-bloc communication when you need to ensure an instance exists
421
- * but don't want to claim ownership (no ref added).
422
- * @param Type - The StateContainer class constructor
423
- * @param instanceKey - Instance key (defaults to 'default')
424
- * @returns The state container instance
425
- */
426
- ensure(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
427
- return this.acquire(Type, instanceKey, {
428
- canCreate: true,
429
- countRef: false
430
- });
431
- }
432
- /**
433
- * Release a reference to an instance.
434
- * Removes the ref and disposes when refs is empty (unless keepAlive).
435
- * Releasing an already-removed refId is a no-op (idempotent).
436
- * @param Type - The StateContainer class constructor
437
- * @param instanceKey - Instance key (defaults to 'default')
438
- * @param forceDispose - Force immediate disposal regardless of refs
439
- * @param refId - The specific ref to remove; removes one arbitrary ref if omitted
440
- */
441
- release(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY, forceDispose = false, refId) {
442
- const instances = this.ensureInstancesMap(Type);
443
- const entry = instances.get(instanceKey);
444
- if (!entry) return;
445
- if (forceDispose) {
446
- if (!entry.instance.isDisposed) entry.instance.dispose();
447
- instances.delete(instanceKey);
448
- return;
449
- }
450
- let releasedRefId;
451
- if (refId !== void 0) {
452
- const count = entry.refs.get(refId) ?? 0;
453
- if (count <= 1) entry.refs.delete(refId);
454
- else entry.refs.set(refId, count - 1);
455
- releasedRefId = refId;
456
- } else {
457
- const firstKey = entry.refs.keys().next().value;
458
- if (firstKey !== void 0) {
459
- const count = entry.refs.get(firstKey) ?? 0;
460
- if (count <= 1) entry.refs.delete(firstKey);
461
- else entry.refs.set(firstKey, count - 1);
462
- releasedRefId = firstKey;
463
- }
464
- }
465
- if (releasedRefId) this.emit("refReleased", entry.instance, releasedRefId);
466
- const keepAlive = isKeepAliveClass(Type);
467
- if (entry.refs.size === 0 && !keepAlive) {
468
- const deps = entry.instance.dependencies;
469
- if (!entry.instance.isDisposed) entry.instance.dispose();
470
- instances.delete(instanceKey);
471
- for (const [DepType, depKey] of deps) {
472
- const depInstances = this.ensureInstancesMap(DepType);
473
- const depEntry = depInstances.get(depKey);
474
- if (depEntry && depEntry.refs.size === 0 && !isKeepAliveClass(DepType) && !depEntry.instance.isDisposed) {
475
- depEntry.instance.dispose();
476
- depInstances.delete(depKey);
477
- }
478
- }
479
- }
480
- }
481
- /**
482
- * Get all instances of a specific type.
483
- * @param Type - The StateContainer class constructor
484
- * @returns Array of all instances
485
- */
486
- getAll(Type) {
487
- const instances = this.ensureInstancesMap(Type);
488
- const result = [];
489
- for (const entry of instances.values()) result.push(entry.instance);
490
- return result;
491
- }
492
- /**
493
- * Safely iterate over all instances of a type.
494
- * Skips disposed instances and catches callback errors.
495
- * @param Type - The StateContainer class constructor
496
- * @param callback - Function to call for each instance
497
- */
498
- forEach(Type, callback) {
499
- const instances = this.ensureInstancesMap(Type);
500
- for (const entry of instances.values()) {
501
- const instance = entry.instance;
502
- if (!instance.isDisposed) try {
503
- callback(instance);
504
- } catch (error) {
505
- console.error(`${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`, error);
506
- }
507
- }
508
- }
509
- /**
510
- * Clear all instances of a specific type (disposes them).
511
- * @param Type - The StateContainer class constructor
512
- */
513
- clear(Type) {
514
- const instances = this.ensureInstancesMap(Type);
515
- for (const entry of instances.values()) if (!entry.instance.isDisposed) entry.instance.dispose();
516
- instances.clear();
517
- }
518
- /**
519
- * Get reference count for an instance (number of active refs).
520
- * @param Type - The StateContainer class constructor
521
- * @param instanceKey - Instance key (defaults to 'default')
522
- * @returns Current ref count (0 if instance doesn't exist)
523
- */
524
- getRefCount(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
525
- return this.ensureInstancesMap(Type).get(instanceKey)?.refs.size ?? 0;
526
- }
527
- /**
528
- * Get all active reference IDs for an instance.
529
- * @param Type - The StateContainer class constructor
530
- * @param instanceKey - Instance key (defaults to 'default')
531
- * @returns Array of ref ID strings (empty if instance doesn't exist)
532
- */
533
- getRefIds(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
534
- const instances = this.instancesByConstructor.get(Type);
535
- if (!instances) return [];
536
- const entry = instances.get(instanceKey);
537
- return entry ? Array.from(entry.refs.keys()) : [];
538
- }
539
- /**
540
- * Check if an instance exists.
541
- * @param Type - The StateContainer class constructor
542
- * @param instanceKey - Instance key (defaults to 'default')
543
- * @returns true if instance exists
544
- */
545
- hasInstance(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
546
- return this.ensureInstancesMap(Type).has(instanceKey);
547
- }
548
- /**
549
- * Clear all instances from all types (for testing)
550
- *
551
- * Iterates all registered types and clears their instances.
552
- * Also clears type tracking to reset the registry state.
553
- */
554
- clearAll() {
555
- for (const Type of this.types) this.clear(Type);
556
- this.types.clear();
557
- this.registeredTypeNames.clear();
558
- }
559
- /**
560
- * Get registry statistics for debugging.
561
- * @returns Object with registeredTypes, totalInstances, and typeBreakdown
562
- */
563
- getStats() {
564
- const typeBreakdown = {};
565
- let totalInstances = 0;
566
- for (const Type of this.types) {
567
- const typeName = Type.name;
568
- const count = this.getInstancesMap(Type).size;
569
- typeBreakdown[typeName] = count;
570
- totalInstances += count;
571
- }
572
- return {
573
- registeredTypes: this.types.size,
574
- totalInstances,
575
- typeBreakdown
576
- };
577
- }
578
- /**
579
- * Get all registered types (for plugin system).
580
- * @returns Array of all registered StateContainer class constructors
581
- */
582
- getTypes() {
583
- return Array.from(this.types);
584
- }
585
- /**
586
- * Subscribe to lifecycle events
587
- * @param event - The lifecycle event to listen for
588
- * @param listener - The listener function to call when the event occurs
589
- * @returns Unsubscribe function
590
- */
591
- on(event, listener) {
592
- if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
593
- const instance = this.listeners.get(event);
594
- if (!instance) throw new Error(`${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`);
595
- instance.add(listener);
596
- if (event === "stateChanged") this._stateChangedListenerCount++;
597
- return () => {
598
- if (this.listeners.get(event)?.delete(listener) && event === "stateChanged") this._stateChangedListenerCount--;
599
- };
600
- }
601
- emit(event, ...args) {
602
- const listeners = this.listeners.get(event);
603
- if (!listeners || listeners.size === 0) return;
604
- for (const listener of listeners) try {
605
- listener(...args);
606
- } catch (error) {
607
- console.error(`${BLAC_ERROR_PREFIX} Listener error for '${event}':`, error);
608
- }
609
- }
610
- /**
611
- * Schedule a deferred stateChanged notification via microtask.
612
- * Skips entirely when no stateChanged listeners are registered.
613
- * @internal - Called by StateContainer.applyState
614
- */
615
- notifyStateChanged(container, previousState, newState) {
616
- if (this._stateChangedListenerCount === 0) return;
617
- if (!this._pendingStateChanges) {
618
- this._pendingStateChanges = [];
619
- queueMicrotask(() => this.flushStateChanged());
620
- }
621
- this._pendingStateChanges.push([
622
- container,
623
- previousState,
624
- newState
625
- ]);
626
- }
627
- flushStateChanged() {
628
- const pending = this._pendingStateChanges;
629
- this._pendingStateChanges = null;
630
- if (!pending) return;
631
- for (const [container, prev, next] of pending) this.emit("stateChanged", container, prev, next);
632
- }
321
+ constructor() {
322
+ this.instancesByConstructor = /* @__PURE__ */ new WeakMap();
323
+ this.types = /* @__PURE__ */ new Set();
324
+ this.registeredTypeNames = /* @__PURE__ */ new Set();
325
+ this.listeners = /* @__PURE__ */ new Map();
326
+ this._stateChangedListenerCount = 0;
327
+ this._pendingStateChanges = null;
328
+ this._autoRefIdCounter = 0;
329
+ }
330
+ /**
331
+ * Register a type for lifecycle event tracking
332
+ * @param constructor - The StateContainer class constructor
333
+ */
334
+ registerType(constructor) {
335
+ this.types.add(constructor);
336
+ }
337
+ /**
338
+ * Register a StateContainer class with configuration
339
+ * @param constructor - The StateContainer class constructor
340
+ * @throws Error if type is already registered
341
+ */
342
+ register(constructor) {
343
+ const className = constructor.name;
344
+ if (this.registeredTypeNames.has(className))
345
+ throw new Error(
346
+ `${BLAC_ERROR_PREFIX} Type "${className}" is already registered`,
347
+ );
348
+ this.registeredTypeNames.add(className);
349
+ this.registerType(constructor);
350
+ }
351
+ ensureInstancesMap(Type) {
352
+ let instances = this.instancesByConstructor.get(Type);
353
+ if (!instances) {
354
+ instances = /* @__PURE__ */ new Map();
355
+ this.instancesByConstructor.set(Type, instances);
356
+ }
357
+ return instances;
358
+ }
359
+ /**
360
+ * Get the instances Map for a specific class (public API for stats/debugging)
361
+ */
362
+ getInstancesMap(Type) {
363
+ return this.instancesByConstructor.get(Type) || /* @__PURE__ */ new Map();
364
+ }
365
+ /**
366
+ * Acquire an instance with ref tracking (ownership semantics).
367
+ * Creates a new instance if one doesn't exist, or returns existing and adds a ref.
368
+ * You must call `release()` with the same refId when done.
369
+ * @param Type - The StateContainer class constructor
370
+ * @param instanceKey - Instance key (defaults to 'default')
371
+ * @param options - Acquisition options
372
+ * @param options.canCreate - Whether to create new instance if not found (default: true)
373
+ * @param options.countRef - Whether to add a reference (default: true)
374
+ * @param options.refId - Named reference ID for debugging; auto-generated if omitted
375
+ * @returns The state container instance
376
+ */
377
+ acquire(
378
+ Type,
379
+ instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,
380
+ options = {},
381
+ ) {
382
+ const { canCreate = true, countRef = true } = options;
383
+ const config = { instanceId: instanceKey };
384
+ const instances = this.ensureInstancesMap(Type);
385
+ let entry = instances.get(instanceKey);
386
+ if (entry?.instance.isDisposed) {
387
+ instances.delete(instanceKey);
388
+ entry = void 0;
389
+ }
390
+ if (entry && countRef) {
391
+ const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
392
+ entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);
393
+ this.emit('refAcquired', entry.instance, refId);
394
+ }
395
+ if (entry) return entry.instance;
396
+ if (!canCreate)
397
+ throw new Error(
398
+ `${BLAC_ERROR_PREFIX} ${Type.name} instance "${instanceKey}" not found and creation is disabled.`,
399
+ );
400
+ const instance = new Type();
401
+ instance.initConfig(config);
402
+ const initialRefs = /* @__PURE__ */ new Map();
403
+ let initialRefId;
404
+ if (countRef) {
405
+ initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
406
+ initialRefs.set(initialRefId, 1);
407
+ }
408
+ instances.set(instanceKey, {
409
+ instance,
410
+ refs: initialRefs,
411
+ });
412
+ this.registerType(Type);
413
+ if (initialRefId) this.emit('refAcquired', instance, initialRefId);
414
+ return instance;
415
+ }
416
+ /**
417
+ * Borrow an existing instance without adding a ref (borrowing semantics).
418
+ * Tracks cross-bloc dependency for reactive updates.
419
+ * @param Type - The StateContainer class constructor
420
+ * @param instanceKey - Instance key (defaults to 'default')
421
+ * @returns The state container instance
422
+ * @throws Error if instance doesn't exist
423
+ */
424
+ borrow(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
425
+ return this.acquire(Type, instanceKey, {
426
+ canCreate: false,
427
+ countRef: false,
428
+ });
429
+ }
430
+ /**
431
+ * Safely borrow an existing instance (borrowing semantics with error handling).
432
+ * Returns discriminated union for type-safe conditional access.
433
+ * @param Type - The StateContainer class constructor
434
+ * @param instanceKey - Instance key (defaults to 'default')
435
+ * @returns Discriminated union with either the instance or an error
436
+ */
437
+ borrowSafe(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
438
+ try {
439
+ return {
440
+ error: null,
441
+ instance: this.borrow(Type, instanceKey),
442
+ };
443
+ } catch (error) {
444
+ return {
445
+ error,
446
+ instance: null,
447
+ };
448
+ }
449
+ }
450
+ /**
451
+ * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
452
+ * Gets existing instance OR creates it if it doesn't exist, without adding a ref.
453
+ * Tracks cross-bloc dependency for reactive updates.
454
+ *
455
+ * Use this in bloc-to-bloc communication when you need to ensure an instance exists
456
+ * but don't want to claim ownership (no ref added).
457
+ * @param Type - The StateContainer class constructor
458
+ * @param instanceKey - Instance key (defaults to 'default')
459
+ * @returns The state container instance
460
+ */
461
+ ensure(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
462
+ return this.acquire(Type, instanceKey, {
463
+ canCreate: true,
464
+ countRef: false,
465
+ });
466
+ }
467
+ /**
468
+ * Release a reference to an instance.
469
+ * Removes the ref and disposes when refs is empty (unless keepAlive).
470
+ * Releasing an already-removed refId is a no-op (idempotent).
471
+ * @param Type - The StateContainer class constructor
472
+ * @param instanceKey - Instance key (defaults to 'default')
473
+ * @param forceDispose - Force immediate disposal regardless of refs
474
+ * @param refId - The specific ref to remove; removes one arbitrary ref if omitted
475
+ */
476
+ release(
477
+ Type,
478
+ instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,
479
+ forceDispose = false,
480
+ refId,
481
+ ) {
482
+ const instances = this.ensureInstancesMap(Type);
483
+ const entry = instances.get(instanceKey);
484
+ if (!entry) return;
485
+ if (forceDispose) {
486
+ if (!entry.instance.isDisposed) entry.instance.dispose();
487
+ instances.delete(instanceKey);
488
+ return;
489
+ }
490
+ let releasedRefId;
491
+ if (refId !== void 0) {
492
+ const count = entry.refs.get(refId) ?? 0;
493
+ if (count <= 1) entry.refs.delete(refId);
494
+ else entry.refs.set(refId, count - 1);
495
+ releasedRefId = refId;
496
+ } else {
497
+ const firstKey = entry.refs.keys().next().value;
498
+ if (firstKey !== void 0) {
499
+ const count = entry.refs.get(firstKey) ?? 0;
500
+ if (count <= 1) entry.refs.delete(firstKey);
501
+ else entry.refs.set(firstKey, count - 1);
502
+ releasedRefId = firstKey;
503
+ }
504
+ }
505
+ if (releasedRefId) this.emit('refReleased', entry.instance, releasedRefId);
506
+ const keepAlive = isKeepAliveClass(Type);
507
+ if (entry.refs.size === 0 && !keepAlive) {
508
+ const deps = entry.instance.dependencies;
509
+ if (!entry.instance.isDisposed) entry.instance.dispose();
510
+ instances.delete(instanceKey);
511
+ for (const [DepType, depKey] of deps) {
512
+ const depInstances = this.ensureInstancesMap(DepType);
513
+ const depEntry = depInstances.get(depKey);
514
+ if (
515
+ depEntry &&
516
+ depEntry.refs.size === 0 &&
517
+ !isKeepAliveClass(DepType) &&
518
+ !depEntry.instance.isDisposed
519
+ ) {
520
+ depEntry.instance.dispose();
521
+ depInstances.delete(depKey);
522
+ }
523
+ }
524
+ }
525
+ }
526
+ /**
527
+ * Get all instances of a specific type.
528
+ * @param Type - The StateContainer class constructor
529
+ * @returns Array of all instances
530
+ */
531
+ getAll(Type) {
532
+ const instances = this.ensureInstancesMap(Type);
533
+ const result = [];
534
+ for (const entry of instances.values()) result.push(entry.instance);
535
+ return result;
536
+ }
537
+ /**
538
+ * Safely iterate over all instances of a type.
539
+ * Skips disposed instances and catches callback errors.
540
+ * @param Type - The StateContainer class constructor
541
+ * @param callback - Function to call for each instance
542
+ */
543
+ forEach(Type, callback) {
544
+ const instances = this.ensureInstancesMap(Type);
545
+ for (const entry of instances.values()) {
546
+ const instance = entry.instance;
547
+ if (!instance.isDisposed)
548
+ try {
549
+ callback(instance);
550
+ } catch (error) {
551
+ console.error(
552
+ `${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`,
553
+ error,
554
+ );
555
+ }
556
+ }
557
+ }
558
+ /**
559
+ * Clear all instances of a specific type (disposes them).
560
+ * @param Type - The StateContainer class constructor
561
+ */
562
+ clear(Type) {
563
+ const instances = this.ensureInstancesMap(Type);
564
+ for (const entry of instances.values())
565
+ if (!entry.instance.isDisposed) entry.instance.dispose();
566
+ instances.clear();
567
+ }
568
+ /**
569
+ * Get reference count for an instance (number of active refs).
570
+ * @param Type - The StateContainer class constructor
571
+ * @param instanceKey - Instance key (defaults to 'default')
572
+ * @returns Current ref count (0 if instance doesn't exist)
573
+ */
574
+ getRefCount(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
575
+ return this.ensureInstancesMap(Type).get(instanceKey)?.refs.size ?? 0;
576
+ }
577
+ /**
578
+ * Get all active reference IDs for an instance.
579
+ * @param Type - The StateContainer class constructor
580
+ * @param instanceKey - Instance key (defaults to 'default')
581
+ * @returns Array of ref ID strings (empty if instance doesn't exist)
582
+ */
583
+ getRefIds(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
584
+ const instances = this.instancesByConstructor.get(Type);
585
+ if (!instances) return [];
586
+ const entry = instances.get(instanceKey);
587
+ return entry ? Array.from(entry.refs.keys()) : [];
588
+ }
589
+ /**
590
+ * Check if an instance exists.
591
+ * @param Type - The StateContainer class constructor
592
+ * @param instanceKey - Instance key (defaults to 'default')
593
+ * @returns true if instance exists
594
+ */
595
+ hasInstance(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
596
+ return this.ensureInstancesMap(Type).has(instanceKey);
597
+ }
598
+ /**
599
+ * Clear all instances from all types (for testing)
600
+ *
601
+ * Iterates all registered types and clears their instances.
602
+ * Also clears type tracking to reset the registry state.
603
+ */
604
+ clearAll() {
605
+ for (const Type of this.types) this.clear(Type);
606
+ this.types.clear();
607
+ this.registeredTypeNames.clear();
608
+ }
609
+ /**
610
+ * Get registry statistics for debugging.
611
+ * @returns Object with registeredTypes, totalInstances, and typeBreakdown
612
+ */
613
+ getStats() {
614
+ const typeBreakdown = {};
615
+ let totalInstances = 0;
616
+ for (const Type of this.types) {
617
+ const typeName = Type.name;
618
+ const count = this.getInstancesMap(Type).size;
619
+ typeBreakdown[typeName] = count;
620
+ totalInstances += count;
621
+ }
622
+ return {
623
+ registeredTypes: this.types.size,
624
+ totalInstances,
625
+ typeBreakdown,
626
+ };
627
+ }
628
+ /**
629
+ * Get all registered types (for plugin system).
630
+ * @returns Array of all registered StateContainer class constructors
631
+ */
632
+ getTypes() {
633
+ return Array.from(this.types);
634
+ }
635
+ /**
636
+ * Subscribe to lifecycle events
637
+ * @param event - The lifecycle event to listen for
638
+ * @param listener - The listener function to call when the event occurs
639
+ * @returns Unsubscribe function
640
+ */
641
+ on(event, listener) {
642
+ if (!this.listeners.has(event))
643
+ this.listeners.set(event, /* @__PURE__ */ new Set());
644
+ const instance = this.listeners.get(event);
645
+ if (!instance)
646
+ throw new Error(
647
+ `${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`,
648
+ );
649
+ instance.add(listener);
650
+ if (event === 'stateChanged') this._stateChangedListenerCount++;
651
+ return () => {
652
+ if (
653
+ this.listeners.get(event)?.delete(listener) &&
654
+ event === 'stateChanged'
655
+ )
656
+ this._stateChangedListenerCount--;
657
+ };
658
+ }
659
+ emit(event, ...args) {
660
+ const listeners = this.listeners.get(event);
661
+ if (!listeners || listeners.size === 0) return;
662
+ for (const listener of listeners)
663
+ try {
664
+ listener(...args);
665
+ } catch (error) {
666
+ console.error(
667
+ `${BLAC_ERROR_PREFIX} Listener error for '${event}':`,
668
+ error,
669
+ );
670
+ }
671
+ }
672
+ /**
673
+ * Schedule a deferred stateChanged notification via microtask.
674
+ * Skips entirely when no stateChanged listeners are registered.
675
+ * @internal - Called by StateContainer.applyState
676
+ */
677
+ notifyStateChanged(container, previousState, newState) {
678
+ if (this._stateChangedListenerCount === 0) return;
679
+ if (!this._pendingStateChanges) {
680
+ this._pendingStateChanges = [];
681
+ queueMicrotask(() => this.flushStateChanged());
682
+ }
683
+ this._pendingStateChanges.push([container, previousState, newState]);
684
+ }
685
+ flushStateChanged() {
686
+ const pending = this._pendingStateChanges;
687
+ this._pendingStateChanges = null;
688
+ if (!pending) return;
689
+ for (const [container, prev, next] of pending)
690
+ this.emit('stateChanged', container, prev, next);
691
+ }
633
692
  };
634
693
  /**
635
- * Global default registry instance
636
- */
694
+ * Global default registry instance
695
+ */
637
696
  const globalRegistry = new StateContainerRegistry();
638
697
  /**
639
- * Global plugin manager (initialized lazily)
640
- */
698
+ * Global plugin manager (initialized lazily)
699
+ */
641
700
  let _globalPluginManager = null;
642
701
  /**
643
- * Get the global plugin manager
644
- */
702
+ * Get the global plugin manager
703
+ */
645
704
  function getPluginManager() {
646
- if (!_globalPluginManager) _globalPluginManager = createPluginManager(globalRegistry);
647
- return _globalPluginManager;
705
+ if (!_globalPluginManager)
706
+ _globalPluginManager = createPluginManager(globalRegistry);
707
+ return _globalPluginManager;
648
708
  }
649
709
  //#endregion
650
- Object.defineProperty(exports, "BLAC_DEFAULTS", {
651
- enumerable: true,
652
- get: function() {
653
- return BLAC_DEFAULTS;
654
- }
710
+ Object.defineProperty(exports, 'BLAC_DEFAULTS', {
711
+ enumerable: true,
712
+ get: function () {
713
+ return BLAC_DEFAULTS;
714
+ },
655
715
  });
656
- Object.defineProperty(exports, "BLAC_ERROR_PREFIX", {
657
- enumerable: true,
658
- get: function() {
659
- return BLAC_ERROR_PREFIX;
660
- }
716
+ Object.defineProperty(exports, 'BLAC_ERROR_PREFIX', {
717
+ enumerable: true,
718
+ get: function () {
719
+ return BLAC_ERROR_PREFIX;
720
+ },
661
721
  });
662
- Object.defineProperty(exports, "BLAC_STATIC_PROPS", {
663
- enumerable: true,
664
- get: function() {
665
- return BLAC_STATIC_PROPS;
666
- }
722
+ Object.defineProperty(exports, 'BLAC_STATIC_PROPS', {
723
+ enumerable: true,
724
+ get: function () {
725
+ return BLAC_STATIC_PROPS;
726
+ },
667
727
  });
668
- Object.defineProperty(exports, "PluginManager", {
669
- enumerable: true,
670
- get: function() {
671
- return PluginManager;
672
- }
728
+ Object.defineProperty(exports, 'PluginManager', {
729
+ enumerable: true,
730
+ get: function () {
731
+ return PluginManager;
732
+ },
673
733
  });
674
- Object.defineProperty(exports, "StateContainerRegistry", {
675
- enumerable: true,
676
- get: function() {
677
- return StateContainerRegistry;
678
- }
734
+ Object.defineProperty(exports, 'StateContainerRegistry', {
735
+ enumerable: true,
736
+ get: function () {
737
+ return StateContainerRegistry;
738
+ },
679
739
  });
680
- Object.defineProperty(exports, "getPluginManager", {
681
- enumerable: true,
682
- get: function() {
683
- return getPluginManager;
684
- }
740
+ Object.defineProperty(exports, 'getPluginManager', {
741
+ enumerable: true,
742
+ get: function () {
743
+ return getPluginManager;
744
+ },
685
745
  });
686
- Object.defineProperty(exports, "globalRegistry", {
687
- enumerable: true,
688
- get: function() {
689
- return globalRegistry;
690
- }
746
+ Object.defineProperty(exports, 'globalRegistry', {
747
+ enumerable: true,
748
+ get: function () {
749
+ return globalRegistry;
750
+ },
691
751
  });
692
752
 
693
- //# sourceMappingURL=StateContainerRegistry-D1lVJFGL.cjs.map
753
+ //# sourceMappingURL=StateContainerRegistry-D1lVJFGL.cjs.map