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