@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,687 +1,742 @@
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,
13
- CLEANUP_INTERVAL_MS: 3e4,
14
- WEAKREF_CLEANUP_INTERVAL_MS: 1e4,
15
- MAX_SUBSCRIPTIONS: 1e3,
16
- MAX_SUBSCRIPTIONS_HIGH_PERF: 1e4,
17
- PIPELINE_TIMEOUT_MS: 5e3,
18
- CLEANUP_INTERVAL_HIGH_PERF_MS: 5e3,
19
- MAX_PIPELINE_STAGES: 30
11
+ DEFAULT_INSTANCE_KEY: 'default',
12
+ MAX_GETTER_DEPTH: 10,
13
+ CLEANUP_INTERVAL_MS: 3e4,
14
+ WEAKREF_CLEANUP_INTERVAL_MS: 1e4,
15
+ MAX_SUBSCRIPTIONS: 1e3,
16
+ MAX_SUBSCRIPTIONS_HIGH_PERF: 1e4,
17
+ PIPELINE_TIMEOUT_MS: 5e3,
18
+ CLEANUP_INTERVAL_HIGH_PERF_MS: 5e3,
19
+ MAX_PIPELINE_STAGES: 30,
20
20
  };
21
21
  /**
22
- * Static property names for StateContainer classes
23
- * Used for feature flags and configuration on bloc classes
24
- */
22
+ * Static property names for StateContainer classes
23
+ * Used for feature flags and configuration on bloc classes
24
+ */
25
25
  const BLAC_STATIC_PROPS = {
26
- KEEP_ALIVE: "keepAlive",
27
- EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools"
26
+ KEEP_ALIVE: 'keepAlive',
27
+ EXCLUDE_FROM_DEVTOOLS: '__excludeFromDevTools',
28
28
  };
29
29
  /**
30
- * Standard error message prefix
31
- */
32
- const BLAC_ERROR_PREFIX = "[BlaC]";
30
+ * Standard error message prefix
31
+ */
32
+ const BLAC_ERROR_PREFIX = '[BlaC]';
33
33
  //#endregion
34
34
  //#region src/plugin/PluginManager.ts
35
35
  /**
36
- * Manages plugin lifecycle for the BlaC state management system.
37
- * Plugins receive notifications about state container lifecycle events.
38
- *
39
- * @example
40
- * ```ts
41
- * const manager = createPluginManager(registry);
42
- * manager.install(myPlugin, { environment: 'development' });
43
- * ```
44
- */
36
+ * Manages plugin lifecycle for the BlaC state management system.
37
+ * Plugins receive notifications about state container lifecycle events.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const manager = createPluginManager(registry);
42
+ * manager.install(myPlugin, { environment: 'development' });
43
+ * ```
44
+ */
45
45
  var PluginManager = class {
46
- /**
47
- * Create a new PluginManager
48
- * @param registry - The StateContainerRegistry to monitor for lifecycle events
49
- */
50
- constructor(registry) {
51
- this.plugins = /* @__PURE__ */ new Map();
52
- this.registry = registry;
53
- this.setupLifecycleHooks();
54
- }
55
- /**
56
- * Install a plugin with optional configuration
57
- * @param plugin - The plugin to install
58
- * @param config - Optional plugin configuration
59
- * @throws Error if plugin is already installed
60
- */
61
- install(plugin, config = {}) {
62
- const effectiveConfig = {
63
- enabled: true,
64
- environment: "all",
65
- ...config
66
- };
67
- if (!this.shouldEnablePlugin(effectiveConfig)) {
68
- console.log(`[BlaC] Plugin "${plugin.name}" skipped (environment mismatch)`);
69
- return;
70
- }
71
- if (this.plugins.has(plugin.name)) throw new Error(`Plugin "${plugin.name}" is already installed`);
72
- const context = this.createPluginContext();
73
- this.plugins.set(plugin.name, {
74
- plugin,
75
- config: effectiveConfig,
76
- context
77
- });
78
- if (plugin.onInstall) try {
79
- plugin.onInstall(context);
80
- } catch (error) {
81
- console.error(`[BlaC] Error installing plugin "${plugin.name}":`, error);
82
- this.plugins.delete(plugin.name);
83
- throw error;
84
- }
85
- console.log(`[BlaC] Plugin "${plugin.name}" v${plugin.version} installed`);
86
- }
87
- /**
88
- * Uninstall a plugin by name
89
- * @param pluginName - The name of the plugin to uninstall
90
- * @throws Error if plugin is not installed
91
- */
92
- uninstall(pluginName) {
93
- const installed = this.plugins.get(pluginName);
94
- if (!installed) throw new Error(`Plugin "${pluginName}" is not installed`);
95
- if (installed.plugin.onUninstall) try {
96
- installed.plugin.onUninstall();
97
- } catch (error) {
98
- console.error(`[BlaC] Error uninstalling plugin "${pluginName}":`, error);
99
- }
100
- this.plugins.delete(pluginName);
101
- console.log(`[BlaC] Plugin "${pluginName}" uninstalled`);
102
- }
103
- /**
104
- * Get an installed plugin by name
105
- * @param pluginName - The name of the plugin to retrieve
106
- * @returns The plugin instance or undefined if not found
107
- */
108
- getPlugin(pluginName) {
109
- return this.plugins.get(pluginName)?.plugin;
110
- }
111
- /**
112
- * Get all installed plugins
113
- * @returns Array of all installed plugins
114
- */
115
- getAllPlugins() {
116
- return Array.from(this.plugins.values()).map((p) => p.plugin);
117
- }
118
- /**
119
- * Check if a plugin is installed
120
- * @param pluginName - The name of the plugin to check
121
- * @returns true if the plugin is installed
122
- */
123
- hasPlugin(pluginName) {
124
- return this.plugins.has(pluginName);
125
- }
126
- /**
127
- * Uninstall all plugins
128
- */
129
- clear() {
130
- for (const name of this.plugins.keys()) this.uninstall(name);
131
- }
132
- /**
133
- * Setup lifecycle hooks to notify plugins
134
- */
135
- setupLifecycleHooks() {
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
- * Notify all plugins of a lifecycle event
154
- */
155
- notifyPlugins(hookName, ...args) {
156
- for (const { plugin, config, context } of this.plugins.values()) {
157
- if (!config.enabled) continue;
158
- const hook = plugin[hookName];
159
- if (typeof hook === "function") try {
160
- hook.apply(plugin, [...args, context]);
161
- } catch (error) {
162
- console.error(`[BlaC] Error in plugin "${plugin.name}" ${hookName}:`, error);
163
- }
164
- }
165
- }
166
- /**
167
- * Create plugin context with safe API access
168
- */
169
- createPluginContext() {
170
- return {
171
- getInstanceMetadata: (instance) => {
172
- return {
173
- id: instance.instanceId,
174
- className: instance.constructor.name,
175
- isDisposed: instance.isDisposed,
176
- name: instance.name,
177
- createdAt: instance.createdAt,
178
- state: instance.state,
179
- hydrationStatus: instance.hydrationStatus,
180
- isHydrated: instance.isHydrated,
181
- hydrationError: instance.hydrationError,
182
- changedWhileHydrating: instance.changedWhileHydrating
183
- };
184
- },
185
- getState: (instance) => {
186
- return instance.state;
187
- },
188
- getHydrationStatus: (instance) => {
189
- return instance.hydrationStatus;
190
- },
191
- startHydration: (instance) => {
192
- instance.beginHydration();
193
- },
194
- applyHydratedState: (instance, state) => {
195
- return instance.applyHydratedState(state);
196
- },
197
- finishHydration: (instance) => {
198
- instance.finishHydration();
199
- },
200
- failHydration: (instance, error) => {
201
- instance.failHydration(error);
202
- },
203
- waitForHydration: (instance) => {
204
- return instance.waitForHydration();
205
- },
206
- queryInstances: (typeClass) => {
207
- return this.registry.getAll(typeClass);
208
- },
209
- getAllTypes: () => {
210
- return this.registry.getTypes();
211
- },
212
- getStats: () => {
213
- return this.registry.getStats();
214
- },
215
- getRefIds: (instanceId) => {
216
- for (const Type of this.registry.getTypes()) {
217
- const map = this.registry.getInstancesMap(Type);
218
- for (const [, entry] of map) if (entry.instance.instanceId === instanceId) return Array.from(entry.refs.keys());
219
- }
220
- return [];
221
- }
222
- };
223
- }
224
- /**
225
- * Check if plugin should be enabled based on environment
226
- */
227
- shouldEnablePlugin(config) {
228
- if (!config.enabled) return false;
229
- if (config.environment === "all") return true;
230
- return this.getCurrentEnvironment() === config.environment;
231
- }
232
- /**
233
- * Get current environment
234
- */
235
- getCurrentEnvironment() {
236
- if (typeof process !== "undefined") {
237
- if (process.env.NODE_ENV === "test") return "test";
238
- if (process.env.NODE_ENV === "production") return "production";
239
- return "development";
240
- }
241
- return "development";
242
- }
46
+ /**
47
+ * Create a new PluginManager
48
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
49
+ */
50
+ constructor(registry) {
51
+ this.plugins = /* @__PURE__ */ new Map();
52
+ this.registry = registry;
53
+ this.setupLifecycleHooks();
54
+ }
55
+ /**
56
+ * Install a plugin with optional configuration
57
+ * @param plugin - The plugin to install
58
+ * @param config - Optional plugin configuration
59
+ * @throws Error if plugin is already installed
60
+ */
61
+ install(plugin, config = {}) {
62
+ const effectiveConfig = {
63
+ enabled: true,
64
+ environment: 'all',
65
+ ...config,
66
+ };
67
+ if (!this.shouldEnablePlugin(effectiveConfig)) {
68
+ console.log(
69
+ `[BlaC] Plugin "${plugin.name}" skipped (environment mismatch)`,
70
+ );
71
+ return;
72
+ }
73
+ if (this.plugins.has(plugin.name))
74
+ throw new Error(`Plugin "${plugin.name}" is already installed`);
75
+ const context = this.createPluginContext();
76
+ this.plugins.set(plugin.name, {
77
+ plugin,
78
+ config: effectiveConfig,
79
+ context,
80
+ });
81
+ if (plugin.onInstall)
82
+ try {
83
+ plugin.onInstall(context);
84
+ } catch (error) {
85
+ console.error(
86
+ `[BlaC] Error installing plugin "${plugin.name}":`,
87
+ error,
88
+ );
89
+ this.plugins.delete(plugin.name);
90
+ throw error;
91
+ }
92
+ console.log(`[BlaC] Plugin "${plugin.name}" v${plugin.version} installed`);
93
+ }
94
+ /**
95
+ * Uninstall a plugin by name
96
+ * @param pluginName - The name of the plugin to uninstall
97
+ * @throws Error if plugin is not installed
98
+ */
99
+ uninstall(pluginName) {
100
+ const installed = this.plugins.get(pluginName);
101
+ if (!installed) throw new Error(`Plugin "${pluginName}" is not installed`);
102
+ if (installed.plugin.onUninstall)
103
+ try {
104
+ installed.plugin.onUninstall();
105
+ } catch (error) {
106
+ console.error(
107
+ `[BlaC] Error uninstalling plugin "${pluginName}":`,
108
+ error,
109
+ );
110
+ }
111
+ this.plugins.delete(pluginName);
112
+ console.log(`[BlaC] Plugin "${pluginName}" uninstalled`);
113
+ }
114
+ /**
115
+ * Get an installed plugin by name
116
+ * @param pluginName - The name of the plugin to retrieve
117
+ * @returns The plugin instance or undefined if not found
118
+ */
119
+ getPlugin(pluginName) {
120
+ return this.plugins.get(pluginName)?.plugin;
121
+ }
122
+ /**
123
+ * Get all installed plugins
124
+ * @returns Array of all installed plugins
125
+ */
126
+ getAllPlugins() {
127
+ return Array.from(this.plugins.values()).map((p) => p.plugin);
128
+ }
129
+ /**
130
+ * Check if a plugin is installed
131
+ * @param pluginName - The name of the plugin to check
132
+ * @returns true if the plugin is installed
133
+ */
134
+ hasPlugin(pluginName) {
135
+ return this.plugins.has(pluginName);
136
+ }
137
+ /**
138
+ * Uninstall all plugins
139
+ */
140
+ clear() {
141
+ for (const name of this.plugins.keys()) this.uninstall(name);
142
+ }
143
+ /**
144
+ * Setup lifecycle hooks to notify plugins
145
+ */
146
+ setupLifecycleHooks() {
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
+ * Notify all plugins of a lifecycle event
173
+ */
174
+ notifyPlugins(hookName, ...args) {
175
+ for (const { plugin, config, context } of this.plugins.values()) {
176
+ if (!config.enabled) continue;
177
+ const hook = plugin[hookName];
178
+ if (typeof hook === 'function')
179
+ try {
180
+ hook.apply(plugin, [...args, context]);
181
+ } catch (error) {
182
+ console.error(
183
+ `[BlaC] Error in plugin "${plugin.name}" ${hookName}:`,
184
+ error,
185
+ );
186
+ }
187
+ }
188
+ }
189
+ /**
190
+ * Create plugin context with safe API access
191
+ */
192
+ createPluginContext() {
193
+ return {
194
+ getInstanceMetadata: (instance) => {
195
+ return {
196
+ id: instance.instanceId,
197
+ className: instance.constructor.name,
198
+ isDisposed: instance.isDisposed,
199
+ name: instance.name,
200
+ createdAt: instance.createdAt,
201
+ state: instance.state,
202
+ hydrationStatus: instance.hydrationStatus,
203
+ isHydrated: instance.isHydrated,
204
+ hydrationError: instance.hydrationError,
205
+ changedWhileHydrating: instance.changedWhileHydrating,
206
+ };
207
+ },
208
+ getState: (instance) => {
209
+ return instance.state;
210
+ },
211
+ getHydrationStatus: (instance) => {
212
+ return instance.hydrationStatus;
213
+ },
214
+ startHydration: (instance) => {
215
+ instance.beginHydration();
216
+ },
217
+ applyHydratedState: (instance, state) => {
218
+ return instance.applyHydratedState(state);
219
+ },
220
+ finishHydration: (instance) => {
221
+ instance.finishHydration();
222
+ },
223
+ failHydration: (instance, error) => {
224
+ instance.failHydration(error);
225
+ },
226
+ waitForHydration: (instance) => {
227
+ return instance.waitForHydration();
228
+ },
229
+ queryInstances: (typeClass) => {
230
+ return this.registry.getAll(typeClass);
231
+ },
232
+ getAllTypes: () => {
233
+ return this.registry.getTypes();
234
+ },
235
+ getStats: () => {
236
+ return this.registry.getStats();
237
+ },
238
+ getRefIds: (instanceId) => {
239
+ for (const Type of this.registry.getTypes()) {
240
+ const map = this.registry.getInstancesMap(Type);
241
+ for (const [, entry] of map)
242
+ if (entry.instance.instanceId === instanceId)
243
+ return Array.from(entry.refs.keys());
244
+ }
245
+ return [];
246
+ },
247
+ };
248
+ }
249
+ /**
250
+ * Check if plugin should be enabled based on environment
251
+ */
252
+ shouldEnablePlugin(config) {
253
+ if (!config.enabled) return false;
254
+ if (config.environment === 'all') return true;
255
+ return this.getCurrentEnvironment() === config.environment;
256
+ }
257
+ /**
258
+ * Get current environment
259
+ */
260
+ getCurrentEnvironment() {
261
+ if (typeof process !== 'undefined') {
262
+ if (process.env.NODE_ENV === 'test') return 'test';
263
+ if (process.env.NODE_ENV === 'production') return 'production';
264
+ return 'development';
265
+ }
266
+ return 'development';
267
+ }
243
268
  };
244
269
  /**
245
- * Create a plugin manager instance
246
- * @param registry - The StateContainerRegistry to monitor for lifecycle events
247
- * @returns A new PluginManager instance
248
- */
270
+ * Create a plugin manager instance
271
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
272
+ * @returns A new PluginManager instance
273
+ */
249
274
  function createPluginManager(registry) {
250
- return new PluginManager(registry);
275
+ return new PluginManager(registry);
251
276
  }
252
277
  //#endregion
253
278
  //#region src/utils/static-props.ts
254
279
  /**
255
- * Utility functions for accessing static properties on StateContainer classes
256
- */
280
+ * Utility functions for accessing static properties on StateContainer classes
281
+ */
257
282
  /**
258
- * Get a static property from a class constructor
259
- * Type-safe helper that avoids (Type as any) casts
260
- *
261
- * @param Type - The class constructor
262
- * @param propName - The property name to access
263
- * @param defaultValue - Optional default value if property is undefined
264
- * @returns The property value or default
265
- */
283
+ * Get a static property from a class constructor
284
+ * Type-safe helper that avoids (Type as any) casts
285
+ *
286
+ * @param Type - The class constructor
287
+ * @param propName - The property name to access
288
+ * @param defaultValue - Optional default value if property is undefined
289
+ * @returns The property value or default
290
+ */
266
291
  function getStaticProp(Type, propName, defaultValue) {
267
- return Type[propName] ?? defaultValue;
292
+ return Type[propName] ?? defaultValue;
268
293
  }
269
294
  /**
270
- * Check if a class is marked as keepAlive.
271
- * KeepAlive classes are never auto-disposed when ref count reaches 0.
272
- * @param Type - The class constructor to check
273
- * @returns true if the class has `static keepAlive = true`
274
- */
295
+ * Check if a class is marked as keepAlive.
296
+ * KeepAlive classes are never auto-disposed when ref count reaches 0.
297
+ * @param Type - The class constructor to check
298
+ * @returns true if the class has `static keepAlive = true`
299
+ */
275
300
  function isKeepAliveClass(Type) {
276
- return getStaticProp(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;
301
+ return getStaticProp(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;
277
302
  }
278
303
  //#endregion
279
304
  //#region src/core/StateContainerRegistry.ts
280
305
  /**
281
- * Central registry for managing StateContainer instances.
282
- * Handles instance lifecycle, named ref tracking, and lifecycle event emission.
283
- *
284
- * @example
285
- * ```ts
286
- * const registry = new StateContainerRegistry();
287
- * const instance = registry.acquire(MyBloc); // ownership, must release
288
- * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
289
- * registry.on('stateChanged', (container, prev, next) => {
290
- * console.log('State changed:', prev, '->', next);
291
- * });
292
- * ```
293
- */
306
+ * Central registry for managing StateContainer instances.
307
+ * Handles instance lifecycle, named ref tracking, and lifecycle event emission.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * const registry = new StateContainerRegistry();
312
+ * const instance = registry.acquire(MyBloc); // ownership, must release
313
+ * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
314
+ * registry.on('stateChanged', (container, prev, next) => {
315
+ * console.log('State changed:', prev, '->', next);
316
+ * });
317
+ * ```
318
+ */
294
319
  var StateContainerRegistry = class {
295
- constructor() {
296
- this.instancesByConstructor = /* @__PURE__ */ new WeakMap();
297
- this.types = /* @__PURE__ */ new Set();
298
- this.registeredTypeNames = /* @__PURE__ */ new Set();
299
- this.listeners = /* @__PURE__ */ new Map();
300
- this._stateChangedListenerCount = 0;
301
- this._pendingStateChanges = null;
302
- this._autoRefIdCounter = 0;
303
- }
304
- /**
305
- * Register a type for lifecycle event tracking
306
- * @param constructor - The StateContainer class constructor
307
- */
308
- registerType(constructor) {
309
- this.types.add(constructor);
310
- }
311
- /**
312
- * Register a StateContainer class with configuration
313
- * @param constructor - The StateContainer class constructor
314
- * @throws Error if type is already registered
315
- */
316
- register(constructor) {
317
- const className = constructor.name;
318
- if (this.registeredTypeNames.has(className)) throw new Error(`${BLAC_ERROR_PREFIX} Type "${className}" is already registered`);
319
- this.registeredTypeNames.add(className);
320
- this.registerType(constructor);
321
- }
322
- ensureInstancesMap(Type) {
323
- let instances = this.instancesByConstructor.get(Type);
324
- if (!instances) {
325
- instances = /* @__PURE__ */ new Map();
326
- this.instancesByConstructor.set(Type, instances);
327
- }
328
- return instances;
329
- }
330
- /**
331
- * Get the instances Map for a specific class (public API for stats/debugging)
332
- */
333
- getInstancesMap(Type) {
334
- return this.instancesByConstructor.get(Type) || /* @__PURE__ */ new Map();
335
- }
336
- /**
337
- * Acquire an instance with ref tracking (ownership semantics).
338
- * Creates a new instance if one doesn't exist, or returns existing and adds a ref.
339
- * You must call `release()` with the same refId when done.
340
- * @param Type - The StateContainer class constructor
341
- * @param instanceKey - Instance key (defaults to 'default')
342
- * @param options - Acquisition options
343
- * @param options.canCreate - Whether to create new instance if not found (default: true)
344
- * @param options.countRef - Whether to add a reference (default: true)
345
- * @param options.refId - Named reference ID for debugging; auto-generated if omitted
346
- * @returns The state container instance
347
- */
348
- acquire(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY, options = {}) {
349
- const { canCreate = true, countRef = true } = options;
350
- const config = { instanceId: instanceKey };
351
- const instances = this.ensureInstancesMap(Type);
352
- let entry = instances.get(instanceKey);
353
- if (entry?.instance.isDisposed) {
354
- instances.delete(instanceKey);
355
- entry = void 0;
356
- }
357
- if (entry && countRef) {
358
- const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
359
- entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);
360
- this.emit("refAcquired", entry.instance, refId);
361
- }
362
- if (entry) return entry.instance;
363
- if (!canCreate) throw new Error(`${BLAC_ERROR_PREFIX} ${Type.name} instance "${instanceKey}" not found and creation is disabled.`);
364
- const instance = new Type();
365
- instance.initConfig(config);
366
- const initialRefs = /* @__PURE__ */ new Map();
367
- let initialRefId;
368
- if (countRef) {
369
- initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
370
- initialRefs.set(initialRefId, 1);
371
- }
372
- instances.set(instanceKey, {
373
- instance,
374
- refs: initialRefs
375
- });
376
- this.registerType(Type);
377
- if (initialRefId) this.emit("refAcquired", instance, initialRefId);
378
- return instance;
379
- }
380
- /**
381
- * Borrow an existing instance without adding a ref (borrowing semantics).
382
- * Tracks cross-bloc dependency for reactive updates.
383
- * @param Type - The StateContainer class constructor
384
- * @param instanceKey - Instance key (defaults to 'default')
385
- * @returns The state container instance
386
- * @throws Error if instance doesn't exist
387
- */
388
- borrow(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
389
- return this.acquire(Type, instanceKey, {
390
- canCreate: false,
391
- countRef: false
392
- });
393
- }
394
- /**
395
- * Safely borrow an existing instance (borrowing semantics with error handling).
396
- * Returns discriminated union for type-safe conditional access.
397
- * @param Type - The StateContainer class constructor
398
- * @param instanceKey - Instance key (defaults to 'default')
399
- * @returns Discriminated union with either the instance or an error
400
- */
401
- borrowSafe(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
402
- try {
403
- return {
404
- error: null,
405
- instance: this.borrow(Type, instanceKey)
406
- };
407
- } catch (error) {
408
- return {
409
- error,
410
- instance: null
411
- };
412
- }
413
- }
414
- /**
415
- * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
416
- * Gets existing instance OR creates it if it doesn't exist, without adding a ref.
417
- * Tracks cross-bloc dependency for reactive updates.
418
- *
419
- * Use this in bloc-to-bloc communication when you need to ensure an instance exists
420
- * but don't want to claim ownership (no ref added).
421
- * @param Type - The StateContainer class constructor
422
- * @param instanceKey - Instance key (defaults to 'default')
423
- * @returns The state container instance
424
- */
425
- ensure(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
426
- return this.acquire(Type, instanceKey, {
427
- canCreate: true,
428
- countRef: false
429
- });
430
- }
431
- /**
432
- * Release a reference to an instance.
433
- * Removes the ref and disposes when refs is empty (unless keepAlive).
434
- * Releasing an already-removed refId is a no-op (idempotent).
435
- * @param Type - The StateContainer class constructor
436
- * @param instanceKey - Instance key (defaults to 'default')
437
- * @param forceDispose - Force immediate disposal regardless of refs
438
- * @param refId - The specific ref to remove; removes one arbitrary ref if omitted
439
- */
440
- release(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY, forceDispose = false, refId) {
441
- const instances = this.ensureInstancesMap(Type);
442
- const entry = instances.get(instanceKey);
443
- if (!entry) return;
444
- if (forceDispose) {
445
- if (!entry.instance.isDisposed) entry.instance.dispose();
446
- instances.delete(instanceKey);
447
- return;
448
- }
449
- let releasedRefId;
450
- if (refId !== void 0) {
451
- const count = entry.refs.get(refId) ?? 0;
452
- if (count <= 1) entry.refs.delete(refId);
453
- else entry.refs.set(refId, count - 1);
454
- releasedRefId = refId;
455
- } else {
456
- const firstKey = entry.refs.keys().next().value;
457
- if (firstKey !== void 0) {
458
- const count = entry.refs.get(firstKey);
459
- if (count <= 1) entry.refs.delete(firstKey);
460
- else entry.refs.set(firstKey, count - 1);
461
- releasedRefId = firstKey;
462
- }
463
- }
464
- if (releasedRefId) this.emit("refReleased", entry.instance, releasedRefId);
465
- const keepAlive = isKeepAliveClass(Type);
466
- if (entry.refs.size === 0 && !keepAlive) {
467
- if (!entry.instance.isDisposed) entry.instance.dispose();
468
- instances.delete(instanceKey);
469
- }
470
- }
471
- /**
472
- * Get all instances of a specific type.
473
- * @param Type - The StateContainer class constructor
474
- * @returns Array of all instances
475
- */
476
- getAll(Type) {
477
- const instances = this.ensureInstancesMap(Type);
478
- const result = [];
479
- for (const entry of instances.values()) result.push(entry.instance);
480
- return result;
481
- }
482
- /**
483
- * Safely iterate over all instances of a type.
484
- * Skips disposed instances and catches callback errors.
485
- * @param Type - The StateContainer class constructor
486
- * @param callback - Function to call for each instance
487
- */
488
- forEach(Type, callback) {
489
- const instances = this.ensureInstancesMap(Type);
490
- for (const entry of instances.values()) {
491
- const instance = entry.instance;
492
- if (!instance.isDisposed) try {
493
- callback(instance);
494
- } catch (error) {
495
- console.error(`${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`, error);
496
- }
497
- }
498
- }
499
- /**
500
- * Clear all instances of a specific type (disposes them).
501
- * @param Type - The StateContainer class constructor
502
- */
503
- clear(Type) {
504
- const instances = this.ensureInstancesMap(Type);
505
- for (const entry of instances.values()) if (!entry.instance.isDisposed) entry.instance.dispose();
506
- instances.clear();
507
- }
508
- /**
509
- * Get reference count for an instance (number of active refs).
510
- * @param Type - The StateContainer class constructor
511
- * @param instanceKey - Instance key (defaults to 'default')
512
- * @returns Current ref count (0 if instance doesn't exist)
513
- */
514
- getRefCount(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
515
- return this.ensureInstancesMap(Type).get(instanceKey)?.refs.size ?? 0;
516
- }
517
- /**
518
- * Get all active reference IDs for an instance.
519
- * @param Type - The StateContainer class constructor
520
- * @param instanceKey - Instance key (defaults to 'default')
521
- * @returns Array of ref ID strings (empty if instance doesn't exist)
522
- */
523
- getRefIds(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
524
- const instances = this.instancesByConstructor.get(Type);
525
- if (!instances) return [];
526
- const entry = instances.get(instanceKey);
527
- return entry ? Array.from(entry.refs.keys()) : [];
528
- }
529
- /**
530
- * Check if an instance exists.
531
- * @param Type - The StateContainer class constructor
532
- * @param instanceKey - Instance key (defaults to 'default')
533
- * @returns true if instance exists
534
- */
535
- hasInstance(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
536
- return this.ensureInstancesMap(Type).has(instanceKey);
537
- }
538
- /**
539
- * Clear all instances from all types (for testing)
540
- *
541
- * Iterates all registered types and clears their instances.
542
- * Also clears type tracking to reset the registry state.
543
- */
544
- clearAll() {
545
- for (const Type of this.types) this.clear(Type);
546
- this.types.clear();
547
- this.registeredTypeNames.clear();
548
- }
549
- /**
550
- * Get registry statistics for debugging.
551
- * @returns Object with registeredTypes, totalInstances, and typeBreakdown
552
- */
553
- getStats() {
554
- const typeBreakdown = {};
555
- let totalInstances = 0;
556
- for (const Type of this.types) {
557
- const typeName = Type.name;
558
- const count = this.getInstancesMap(Type).size;
559
- typeBreakdown[typeName] = count;
560
- totalInstances += count;
561
- }
562
- return {
563
- registeredTypes: this.types.size,
564
- totalInstances,
565
- typeBreakdown
566
- };
567
- }
568
- /**
569
- * Get all registered types (for plugin system).
570
- * @returns Array of all registered StateContainer class constructors
571
- */
572
- getTypes() {
573
- return Array.from(this.types);
574
- }
575
- /**
576
- * Subscribe to lifecycle events
577
- * @param event - The lifecycle event to listen for
578
- * @param listener - The listener function to call when the event occurs
579
- * @returns Unsubscribe function
580
- */
581
- on(event, listener) {
582
- if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
583
- const instance = this.listeners.get(event);
584
- if (!instance) throw new Error(`${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`);
585
- instance.add(listener);
586
- if (event === "stateChanged") this._stateChangedListenerCount++;
587
- return () => {
588
- if (this.listeners.get(event)?.delete(listener) && event === "stateChanged") this._stateChangedListenerCount--;
589
- };
590
- }
591
- /**
592
- * Emit lifecycle event to all listeners
593
- * @internal - Called by StateContainer lifecycle methods
594
- */
595
- emit(event, ...args) {
596
- const listeners = this.listeners.get(event);
597
- if (!listeners || listeners.size === 0) return;
598
- for (const listener of listeners) try {
599
- listener(...args);
600
- } catch (error) {
601
- console.error(`${BLAC_ERROR_PREFIX} Listener error for '${event}':`, error);
602
- }
603
- }
604
- /**
605
- * Schedule a deferred stateChanged notification via microtask.
606
- * Skips entirely when no stateChanged listeners are registered.
607
- * @internal - Called by StateContainer.applyState
608
- */
609
- notifyStateChanged(container, previousState, newState) {
610
- if (this._stateChangedListenerCount === 0) return;
611
- if (!this._pendingStateChanges) {
612
- this._pendingStateChanges = [];
613
- queueMicrotask(() => this.flushStateChanged());
614
- }
615
- this._pendingStateChanges.push([
616
- container,
617
- previousState,
618
- newState
619
- ]);
620
- }
621
- flushStateChanged() {
622
- const pending = this._pendingStateChanges;
623
- this._pendingStateChanges = null;
624
- if (!pending) return;
625
- for (const [container, prev, next] of pending) this.emit("stateChanged", container, prev, next);
626
- }
320
+ constructor() {
321
+ this.instancesByConstructor = /* @__PURE__ */ new WeakMap();
322
+ this.types = /* @__PURE__ */ new Set();
323
+ this.registeredTypeNames = /* @__PURE__ */ new Set();
324
+ this.listeners = /* @__PURE__ */ new Map();
325
+ this._stateChangedListenerCount = 0;
326
+ this._pendingStateChanges = null;
327
+ this._autoRefIdCounter = 0;
328
+ }
329
+ /**
330
+ * Register a type for lifecycle event tracking
331
+ * @param constructor - The StateContainer class constructor
332
+ */
333
+ registerType(constructor) {
334
+ this.types.add(constructor);
335
+ }
336
+ /**
337
+ * Register a StateContainer class with configuration
338
+ * @param constructor - The StateContainer class constructor
339
+ * @throws Error if type is already registered
340
+ */
341
+ register(constructor) {
342
+ const className = constructor.name;
343
+ if (this.registeredTypeNames.has(className))
344
+ throw new Error(
345
+ `${BLAC_ERROR_PREFIX} Type "${className}" is already registered`,
346
+ );
347
+ this.registeredTypeNames.add(className);
348
+ this.registerType(constructor);
349
+ }
350
+ ensureInstancesMap(Type) {
351
+ let instances = this.instancesByConstructor.get(Type);
352
+ if (!instances) {
353
+ instances = /* @__PURE__ */ new Map();
354
+ this.instancesByConstructor.set(Type, instances);
355
+ }
356
+ return instances;
357
+ }
358
+ /**
359
+ * Get the instances Map for a specific class (public API for stats/debugging)
360
+ */
361
+ getInstancesMap(Type) {
362
+ return this.instancesByConstructor.get(Type) || /* @__PURE__ */ new Map();
363
+ }
364
+ /**
365
+ * Acquire an instance with ref tracking (ownership semantics).
366
+ * Creates a new instance if one doesn't exist, or returns existing and adds a ref.
367
+ * You must call `release()` with the same refId when done.
368
+ * @param Type - The StateContainer class constructor
369
+ * @param instanceKey - Instance key (defaults to 'default')
370
+ * @param options - Acquisition options
371
+ * @param options.canCreate - Whether to create new instance if not found (default: true)
372
+ * @param options.countRef - Whether to add a reference (default: true)
373
+ * @param options.refId - Named reference ID for debugging; auto-generated if omitted
374
+ * @returns The state container instance
375
+ */
376
+ acquire(
377
+ Type,
378
+ instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,
379
+ options = {},
380
+ ) {
381
+ const { canCreate = true, countRef = true } = options;
382
+ const config = { instanceId: instanceKey };
383
+ const instances = this.ensureInstancesMap(Type);
384
+ let entry = instances.get(instanceKey);
385
+ if (entry?.instance.isDisposed) {
386
+ instances.delete(instanceKey);
387
+ entry = void 0;
388
+ }
389
+ if (entry && countRef) {
390
+ const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
391
+ entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);
392
+ this.emit('refAcquired', entry.instance, refId);
393
+ }
394
+ if (entry) return entry.instance;
395
+ if (!canCreate)
396
+ throw new Error(
397
+ `${BLAC_ERROR_PREFIX} ${Type.name} instance "${instanceKey}" not found and creation is disabled.`,
398
+ );
399
+ const instance = new Type();
400
+ instance.initConfig(config);
401
+ const initialRefs = /* @__PURE__ */ new Map();
402
+ let initialRefId;
403
+ if (countRef) {
404
+ initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
405
+ initialRefs.set(initialRefId, 1);
406
+ }
407
+ instances.set(instanceKey, {
408
+ instance,
409
+ refs: initialRefs,
410
+ });
411
+ this.registerType(Type);
412
+ if (initialRefId) this.emit('refAcquired', instance, initialRefId);
413
+ return instance;
414
+ }
415
+ /**
416
+ * Borrow an existing instance without adding a ref (borrowing semantics).
417
+ * Tracks cross-bloc dependency for reactive updates.
418
+ * @param Type - The StateContainer class constructor
419
+ * @param instanceKey - Instance key (defaults to 'default')
420
+ * @returns The state container instance
421
+ * @throws Error if instance doesn't exist
422
+ */
423
+ borrow(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
424
+ return this.acquire(Type, instanceKey, {
425
+ canCreate: false,
426
+ countRef: false,
427
+ });
428
+ }
429
+ /**
430
+ * Safely borrow an existing instance (borrowing semantics with error handling).
431
+ * Returns discriminated union for type-safe conditional access.
432
+ * @param Type - The StateContainer class constructor
433
+ * @param instanceKey - Instance key (defaults to 'default')
434
+ * @returns Discriminated union with either the instance or an error
435
+ */
436
+ borrowSafe(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
437
+ try {
438
+ return {
439
+ error: null,
440
+ instance: this.borrow(Type, instanceKey),
441
+ };
442
+ } catch (error) {
443
+ return {
444
+ error,
445
+ instance: null,
446
+ };
447
+ }
448
+ }
449
+ /**
450
+ * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
451
+ * Gets existing instance OR creates it if it doesn't exist, without adding a ref.
452
+ * Tracks cross-bloc dependency for reactive updates.
453
+ *
454
+ * Use this in bloc-to-bloc communication when you need to ensure an instance exists
455
+ * but don't want to claim ownership (no ref added).
456
+ * @param Type - The StateContainer class constructor
457
+ * @param instanceKey - Instance key (defaults to 'default')
458
+ * @returns The state container instance
459
+ */
460
+ ensure(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
461
+ return this.acquire(Type, instanceKey, {
462
+ canCreate: true,
463
+ countRef: false,
464
+ });
465
+ }
466
+ /**
467
+ * Release a reference to an instance.
468
+ * Removes the ref and disposes when refs is empty (unless keepAlive).
469
+ * Releasing an already-removed refId is a no-op (idempotent).
470
+ * @param Type - The StateContainer class constructor
471
+ * @param instanceKey - Instance key (defaults to 'default')
472
+ * @param forceDispose - Force immediate disposal regardless of refs
473
+ * @param refId - The specific ref to remove; removes one arbitrary ref if omitted
474
+ */
475
+ release(
476
+ Type,
477
+ instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,
478
+ forceDispose = false,
479
+ refId,
480
+ ) {
481
+ const instances = this.ensureInstancesMap(Type);
482
+ const entry = instances.get(instanceKey);
483
+ if (!entry) return;
484
+ if (forceDispose) {
485
+ if (!entry.instance.isDisposed) entry.instance.dispose();
486
+ instances.delete(instanceKey);
487
+ return;
488
+ }
489
+ let releasedRefId;
490
+ if (refId !== void 0) {
491
+ const count = entry.refs.get(refId) ?? 0;
492
+ if (count <= 1) entry.refs.delete(refId);
493
+ else entry.refs.set(refId, count - 1);
494
+ releasedRefId = refId;
495
+ } else {
496
+ const firstKey = entry.refs.keys().next().value;
497
+ if (firstKey !== void 0) {
498
+ const count = entry.refs.get(firstKey);
499
+ if (count <= 1) entry.refs.delete(firstKey);
500
+ else entry.refs.set(firstKey, count - 1);
501
+ releasedRefId = firstKey;
502
+ }
503
+ }
504
+ if (releasedRefId) this.emit('refReleased', entry.instance, releasedRefId);
505
+ const keepAlive = isKeepAliveClass(Type);
506
+ if (entry.refs.size === 0 && !keepAlive) {
507
+ if (!entry.instance.isDisposed) entry.instance.dispose();
508
+ instances.delete(instanceKey);
509
+ }
510
+ }
511
+ /**
512
+ * Get all instances of a specific type.
513
+ * @param Type - The StateContainer class constructor
514
+ * @returns Array of all instances
515
+ */
516
+ getAll(Type) {
517
+ const instances = this.ensureInstancesMap(Type);
518
+ const result = [];
519
+ for (const entry of instances.values()) result.push(entry.instance);
520
+ return result;
521
+ }
522
+ /**
523
+ * Safely iterate over all instances of a type.
524
+ * Skips disposed instances and catches callback errors.
525
+ * @param Type - The StateContainer class constructor
526
+ * @param callback - Function to call for each instance
527
+ */
528
+ forEach(Type, callback) {
529
+ const instances = this.ensureInstancesMap(Type);
530
+ for (const entry of instances.values()) {
531
+ const instance = entry.instance;
532
+ if (!instance.isDisposed)
533
+ try {
534
+ callback(instance);
535
+ } catch (error) {
536
+ console.error(
537
+ `${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`,
538
+ error,
539
+ );
540
+ }
541
+ }
542
+ }
543
+ /**
544
+ * Clear all instances of a specific type (disposes them).
545
+ * @param Type - The StateContainer class constructor
546
+ */
547
+ clear(Type) {
548
+ const instances = this.ensureInstancesMap(Type);
549
+ for (const entry of instances.values())
550
+ if (!entry.instance.isDisposed) entry.instance.dispose();
551
+ instances.clear();
552
+ }
553
+ /**
554
+ * Get reference count for an instance (number of active refs).
555
+ * @param Type - The StateContainer class constructor
556
+ * @param instanceKey - Instance key (defaults to 'default')
557
+ * @returns Current ref count (0 if instance doesn't exist)
558
+ */
559
+ getRefCount(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
560
+ return this.ensureInstancesMap(Type).get(instanceKey)?.refs.size ?? 0;
561
+ }
562
+ /**
563
+ * Get all active reference IDs for an instance.
564
+ * @param Type - The StateContainer class constructor
565
+ * @param instanceKey - Instance key (defaults to 'default')
566
+ * @returns Array of ref ID strings (empty if instance doesn't exist)
567
+ */
568
+ getRefIds(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
569
+ const instances = this.instancesByConstructor.get(Type);
570
+ if (!instances) return [];
571
+ const entry = instances.get(instanceKey);
572
+ return entry ? Array.from(entry.refs.keys()) : [];
573
+ }
574
+ /**
575
+ * Check if an instance exists.
576
+ * @param Type - The StateContainer class constructor
577
+ * @param instanceKey - Instance key (defaults to 'default')
578
+ * @returns true if instance exists
579
+ */
580
+ hasInstance(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
581
+ return this.ensureInstancesMap(Type).has(instanceKey);
582
+ }
583
+ /**
584
+ * Clear all instances from all types (for testing)
585
+ *
586
+ * Iterates all registered types and clears their instances.
587
+ * Also clears type tracking to reset the registry state.
588
+ */
589
+ clearAll() {
590
+ for (const Type of this.types) this.clear(Type);
591
+ this.types.clear();
592
+ this.registeredTypeNames.clear();
593
+ }
594
+ /**
595
+ * Get registry statistics for debugging.
596
+ * @returns Object with registeredTypes, totalInstances, and typeBreakdown
597
+ */
598
+ getStats() {
599
+ const typeBreakdown = {};
600
+ let totalInstances = 0;
601
+ for (const Type of this.types) {
602
+ const typeName = Type.name;
603
+ const count = this.getInstancesMap(Type).size;
604
+ typeBreakdown[typeName] = count;
605
+ totalInstances += count;
606
+ }
607
+ return {
608
+ registeredTypes: this.types.size,
609
+ totalInstances,
610
+ typeBreakdown,
611
+ };
612
+ }
613
+ /**
614
+ * Get all registered types (for plugin system).
615
+ * @returns Array of all registered StateContainer class constructors
616
+ */
617
+ getTypes() {
618
+ return Array.from(this.types);
619
+ }
620
+ /**
621
+ * Subscribe to lifecycle events
622
+ * @param event - The lifecycle event to listen for
623
+ * @param listener - The listener function to call when the event occurs
624
+ * @returns Unsubscribe function
625
+ */
626
+ on(event, listener) {
627
+ if (!this.listeners.has(event))
628
+ this.listeners.set(event, /* @__PURE__ */ new Set());
629
+ const instance = this.listeners.get(event);
630
+ if (!instance)
631
+ throw new Error(
632
+ `${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`,
633
+ );
634
+ instance.add(listener);
635
+ if (event === 'stateChanged') this._stateChangedListenerCount++;
636
+ return () => {
637
+ if (
638
+ this.listeners.get(event)?.delete(listener) &&
639
+ event === 'stateChanged'
640
+ )
641
+ this._stateChangedListenerCount--;
642
+ };
643
+ }
644
+ /**
645
+ * Emit lifecycle event to all listeners
646
+ * @internal - Called by StateContainer lifecycle methods
647
+ */
648
+ emit(event, ...args) {
649
+ const listeners = this.listeners.get(event);
650
+ if (!listeners || listeners.size === 0) return;
651
+ for (const listener of listeners)
652
+ try {
653
+ listener(...args);
654
+ } catch (error) {
655
+ console.error(
656
+ `${BLAC_ERROR_PREFIX} Listener error for '${event}':`,
657
+ error,
658
+ );
659
+ }
660
+ }
661
+ /**
662
+ * Schedule a deferred stateChanged notification via microtask.
663
+ * Skips entirely when no stateChanged listeners are registered.
664
+ * @internal - Called by StateContainer.applyState
665
+ */
666
+ notifyStateChanged(container, previousState, newState) {
667
+ if (this._stateChangedListenerCount === 0) return;
668
+ if (!this._pendingStateChanges) {
669
+ this._pendingStateChanges = [];
670
+ queueMicrotask(() => this.flushStateChanged());
671
+ }
672
+ this._pendingStateChanges.push([container, previousState, newState]);
673
+ }
674
+ flushStateChanged() {
675
+ const pending = this._pendingStateChanges;
676
+ this._pendingStateChanges = null;
677
+ if (!pending) return;
678
+ for (const [container, prev, next] of pending)
679
+ this.emit('stateChanged', container, prev, next);
680
+ }
627
681
  };
628
682
  /**
629
- * Global default registry instance
630
- */
683
+ * Global default registry instance
684
+ */
631
685
  const globalRegistry = new StateContainerRegistry();
632
686
  /**
633
- * Global plugin manager (initialized lazily)
634
- */
687
+ * Global plugin manager (initialized lazily)
688
+ */
635
689
  let _globalPluginManager = null;
636
690
  /**
637
- * Get the global plugin manager
638
- */
691
+ * Get the global plugin manager
692
+ */
639
693
  function getPluginManager() {
640
- if (!_globalPluginManager) _globalPluginManager = createPluginManager(globalRegistry);
641
- return _globalPluginManager;
694
+ if (!_globalPluginManager)
695
+ _globalPluginManager = createPluginManager(globalRegistry);
696
+ return _globalPluginManager;
642
697
  }
643
698
  //#endregion
644
- Object.defineProperty(exports, "BLAC_DEFAULTS", {
645
- enumerable: true,
646
- get: function() {
647
- return BLAC_DEFAULTS;
648
- }
699
+ Object.defineProperty(exports, 'BLAC_DEFAULTS', {
700
+ enumerable: true,
701
+ get: function () {
702
+ return BLAC_DEFAULTS;
703
+ },
649
704
  });
650
- Object.defineProperty(exports, "BLAC_ERROR_PREFIX", {
651
- enumerable: true,
652
- get: function() {
653
- return BLAC_ERROR_PREFIX;
654
- }
705
+ Object.defineProperty(exports, 'BLAC_ERROR_PREFIX', {
706
+ enumerable: true,
707
+ get: function () {
708
+ return BLAC_ERROR_PREFIX;
709
+ },
655
710
  });
656
- Object.defineProperty(exports, "BLAC_STATIC_PROPS", {
657
- enumerable: true,
658
- get: function() {
659
- return BLAC_STATIC_PROPS;
660
- }
711
+ Object.defineProperty(exports, 'BLAC_STATIC_PROPS', {
712
+ enumerable: true,
713
+ get: function () {
714
+ return BLAC_STATIC_PROPS;
715
+ },
661
716
  });
662
- Object.defineProperty(exports, "PluginManager", {
663
- enumerable: true,
664
- get: function() {
665
- return PluginManager;
666
- }
717
+ Object.defineProperty(exports, 'PluginManager', {
718
+ enumerable: true,
719
+ get: function () {
720
+ return PluginManager;
721
+ },
667
722
  });
668
- Object.defineProperty(exports, "StateContainerRegistry", {
669
- enumerable: true,
670
- get: function() {
671
- return StateContainerRegistry;
672
- }
723
+ Object.defineProperty(exports, 'StateContainerRegistry', {
724
+ enumerable: true,
725
+ get: function () {
726
+ return StateContainerRegistry;
727
+ },
673
728
  });
674
- Object.defineProperty(exports, "getPluginManager", {
675
- enumerable: true,
676
- get: function() {
677
- return getPluginManager;
678
- }
729
+ Object.defineProperty(exports, 'getPluginManager', {
730
+ enumerable: true,
731
+ get: function () {
732
+ return getPluginManager;
733
+ },
679
734
  });
680
- Object.defineProperty(exports, "globalRegistry", {
681
- enumerable: true,
682
- get: function() {
683
- return globalRegistry;
684
- }
735
+ Object.defineProperty(exports, 'globalRegistry', {
736
+ enumerable: true,
737
+ get: function () {
738
+ return globalRegistry;
739
+ },
685
740
  });
686
741
 
687
- //# sourceMappingURL=StateContainerRegistry-CTOXUf75.cjs.map
742
+ //# sourceMappingURL=StateContainerRegistry-CTOXUf75.cjs.map