@blac/core 2.0.16 → 2.0.18

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 (101) hide show
  1. package/README.md +7 -1
  2. package/dist/StateContainerRegistry-4Ljd9EJx.js +1018 -0
  3. package/dist/StateContainerRegistry-4Ljd9EJx.js.map +1 -0
  4. package/dist/StateContainerRegistry-B1GYx9Xo.js +975 -0
  5. package/dist/StateContainerRegistry-B1GYx9Xo.js.map +1 -0
  6. package/dist/StateContainerRegistry-CEWpc1bj.cjs +1113 -0
  7. package/dist/StateContainerRegistry-CEWpc1bj.cjs.map +1 -0
  8. package/dist/StateContainerRegistry-CSNm2Ws5.cjs +1085 -0
  9. package/dist/StateContainerRegistry-CSNm2Ws5.cjs.map +1 -0
  10. package/dist/StateContainerRegistry-CvBOhAT2.js +996 -0
  11. package/dist/StateContainerRegistry-CvBOhAT2.js.map +1 -0
  12. package/dist/StateContainerRegistry-DJQqLrli.cjs +1046 -0
  13. package/dist/StateContainerRegistry-DJQqLrli.cjs.map +1 -0
  14. package/dist/acquire-B1Wuqla6.cjs +46 -0
  15. package/dist/acquire-B1Wuqla6.cjs.map +1 -0
  16. package/dist/acquire-BP-ZfUH2.js +35 -0
  17. package/dist/acquire-BP-ZfUH2.js.map +1 -0
  18. package/dist/acquire-BZIs6tpN.cjs +46 -0
  19. package/dist/acquire-BZIs6tpN.cjs.map +1 -0
  20. package/dist/acquire-CbMz7gWs.cjs +46 -0
  21. package/dist/acquire-CbMz7gWs.cjs.map +1 -0
  22. package/dist/acquire-CwB083au.js +35 -0
  23. package/dist/acquire-CwB083au.js.map +1 -0
  24. package/dist/acquire-G8aB3GAx.js +35 -0
  25. package/dist/acquire-G8aB3GAx.js.map +1 -0
  26. package/dist/config-C7Ktkjh2.cjs +32 -0
  27. package/dist/config-C7Ktkjh2.cjs.map +1 -0
  28. package/dist/config-COT4Xkbc.js +16 -0
  29. package/dist/config-COT4Xkbc.js.map +1 -0
  30. package/dist/config-Dk1FxfXj.js +16 -0
  31. package/dist/config-Dk1FxfXj.js.map +1 -0
  32. package/dist/config-b2z51Y_C.cjs +32 -0
  33. package/dist/config-b2z51Y_C.cjs.map +1 -0
  34. package/dist/config-buwpT7l3.js +16 -0
  35. package/dist/config-buwpT7l3.js.map +1 -0
  36. package/dist/config-sCPKPYxZ.cjs +32 -0
  37. package/dist/config-sCPKPYxZ.cjs.map +1 -0
  38. package/dist/core/Cubit.d.ts +4 -4
  39. package/dist/core/StateContainer.d.ts +85 -48
  40. package/dist/core/StateContainerRegistry.d.ts +3 -3
  41. package/dist/core/meta.d.ts +73 -0
  42. package/dist/core/symbols.d.ts +10 -17
  43. package/dist/debug.cjs +3 -3
  44. package/dist/debug.js +3 -3
  45. package/dist/ensure-B9oOqpOB.cjs +558 -0
  46. package/dist/ensure-B9oOqpOB.cjs.map +1 -0
  47. package/dist/ensure-BfYnvAsI.js +709 -0
  48. package/dist/ensure-BfYnvAsI.js.map +1 -0
  49. package/dist/ensure-C1a8IFWy.js +535 -0
  50. package/dist/ensure-C1a8IFWy.js.map +1 -0
  51. package/dist/ensure-DEXSmA-N.js +526 -0
  52. package/dist/ensure-DEXSmA-N.js.map +1 -0
  53. package/dist/ensure-Dx86f80B.cjs +567 -0
  54. package/dist/ensure-Dx86f80B.cjs.map +1 -0
  55. package/dist/ensure-DzqGej43.js +526 -0
  56. package/dist/ensure-DzqGej43.js.map +1 -0
  57. package/dist/ensure-_Oh8XPm4.cjs +732 -0
  58. package/dist/ensure-_Oh8XPm4.cjs.map +1 -0
  59. package/dist/ensure-fsQMjaQL.cjs +567 -0
  60. package/dist/ensure-fsQMjaQL.cjs.map +1 -0
  61. package/dist/index.cjs +10 -9
  62. package/dist/index.d.cts +6 -9
  63. package/dist/index.d.ts +6 -9
  64. package/dist/index.js +7 -7
  65. package/dist/management-14vsHr4t.cjs +85 -0
  66. package/dist/management-14vsHr4t.cjs.map +1 -0
  67. package/dist/management-444tdCBG.js +38 -0
  68. package/dist/management-444tdCBG.js.map +1 -0
  69. package/dist/management-BqGBdL01.js +38 -0
  70. package/dist/management-BqGBdL01.js.map +1 -0
  71. package/dist/management-BvUAjril.js +38 -0
  72. package/dist/management-BvUAjril.js.map +1 -0
  73. package/dist/management-DAV9sN-k.cjs +85 -0
  74. package/dist/management-DAV9sN-k.cjs.map +1 -0
  75. package/dist/management-Df7Y2sF1.cjs +85 -0
  76. package/dist/management-Df7Y2sF1.cjs.map +1 -0
  77. package/dist/plugin/BlacPlugin.d.ts +11 -12
  78. package/dist/plugin/PluginManager.d.ts +3 -4
  79. package/dist/plugins.cjs +1 -1
  80. package/dist/plugins.js +1 -1
  81. package/dist/testing.cjs +10 -15
  82. package/dist/testing.cjs.map +1 -1
  83. package/dist/testing.d.cts +4 -6
  84. package/dist/testing.d.ts +4 -6
  85. package/dist/testing.js +10 -14
  86. package/dist/testing.js.map +1 -1
  87. package/dist/watch-B91opmva.cjs +70 -0
  88. package/dist/watch-B91opmva.cjs.map +1 -0
  89. package/dist/watch-CfrSSrRY.js +59 -0
  90. package/dist/watch-CfrSSrRY.js.map +1 -0
  91. package/dist/watch-Cnh3PtQA.cjs +70 -0
  92. package/dist/watch-Cnh3PtQA.cjs.map +1 -0
  93. package/dist/watch-D8hwbFU1.js +59 -0
  94. package/dist/watch-D8hwbFU1.js.map +1 -0
  95. package/dist/watch-DPVUwPUY.js +59 -0
  96. package/dist/watch-DPVUwPUY.js.map +1 -0
  97. package/dist/watch-DVmvZBMD.cjs +70 -0
  98. package/dist/watch-DVmvZBMD.cjs.map +1 -0
  99. package/dist/watch-entry.cjs +1 -1
  100. package/dist/watch-entry.js +1 -1
  101. package/package.json +3 -3
@@ -0,0 +1,1085 @@
1
+ let _dirtytalk_structural = require("@dirtytalk/structural");
2
+ //#region src/config.ts
3
+ /**
4
+ * Default equality: shallow per-key `Object.is` comparison.
5
+ * Falls through to `false` for primitives/null so reference-only state still
6
+ * behaves correctly.
7
+ */
8
+ const shallowEqualState = (prev, next) => {
9
+ if (Object.is(prev, next)) return true;
10
+ if (typeof prev !== "object" || prev === null) return false;
11
+ if (typeof next !== "object" || next === null) return false;
12
+ const prevKeys = Object.keys(prev);
13
+ if (prevKeys.length !== Object.keys(next).length) return false;
14
+ for (let i = 0; i < prevKeys.length; i++) {
15
+ const key = prevKeys[i];
16
+ if (!Object.is(prev[key], next[key])) return false;
17
+ }
18
+ return true;
19
+ };
20
+ const defaultConfig = {
21
+ equality: shallowEqualState,
22
+ maxInstancesPerType: 1e3,
23
+ maxRefsPerInstance: 1e3,
24
+ maxEmitsPerSecond: 100
25
+ };
26
+ let globalConfig = { ...defaultConfig };
27
+ /**
28
+ * Configure global defaults for @blac/core.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { configureBlac, shallowEqualState } from '@blac/core';
33
+ *
34
+ * // Swap in a deep-equality check for all blocs
35
+ * configureBlac({ equality: myDeepEqual });
36
+ * ```
37
+ */
38
+ function configureBlac(config) {
39
+ globalConfig = {
40
+ ...globalConfig,
41
+ ...config
42
+ };
43
+ }
44
+ /**
45
+ * Get the current global configuration.
46
+ * @internal
47
+ */
48
+ function getBlacConfig() {
49
+ return globalConfig;
50
+ }
51
+ /**
52
+ * Reset configuration to defaults (useful for testing).
53
+ * @internal
54
+ */
55
+ function resetBlacConfig() {
56
+ globalConfig = { ...defaultConfig };
57
+ }
58
+ //#endregion
59
+ //#region src/plugin/PluginManager.ts
60
+ /**
61
+ * Manages plugin lifecycle for the BlaC state management system.
62
+ *
63
+ * The manager hooks into two surfaces:
64
+ *
65
+ * 1. **Registry lifecycle events** (`created`, `disposed`, `refAcquired`,
66
+ * `refReleased`, `depsChanged`) — synchronous, fired by the registry.
67
+ *
68
+ * 2. **Per-container channel flushes** — microtask-coalesced. For each
69
+ * container, the manager subscribes once at create-time with
70
+ * `ALL_PATHS` interest and stashes `prevState`. On every flush it
71
+ * captures the new state + the changed `PathSet` and dispatches
72
+ * `onStateChange(ctx, prev, next, paths)` to every enabled plugin.
73
+ *
74
+ * The `ALL_PATHS` subscription cost: plugins counted as a consumer with
75
+ * `ALL_PATHS` interest will defeat the single-consumer-skip optimization
76
+ * in `StructuralContainer`. This is the intended trade-off — devtools /
77
+ * persist plugins genuinely want every change, and stateful plugins
78
+ * (logging) can decode `paths` via `container.interner.lookup(id)` to log
79
+ * only relevant fields. Plugins that want low overhead should remain
80
+ * uninstalled or environment-gated.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const manager = createPluginManager(registry);
85
+ * manager.install(myPlugin, { environment: 'development' });
86
+ * ```
87
+ */
88
+ var PluginManager = class {
89
+ /**
90
+ * Create a new PluginManager
91
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
92
+ */
93
+ constructor(registry) {
94
+ this.plugins = /* @__PURE__ */ new Map();
95
+ this.lifecycleUnsubscribers = [];
96
+ this.containerBridges = /* @__PURE__ */ new WeakMap();
97
+ this.registry = registry;
98
+ this.setupLifecycleHooks();
99
+ }
100
+ /**
101
+ * Install a plugin with optional configuration
102
+ * @param plugin - The plugin to install
103
+ * @param config - Optional plugin configuration
104
+ * @throws Error if plugin is already installed
105
+ */
106
+ install(plugin, config = {}) {
107
+ const effectiveConfig = {
108
+ enabled: true,
109
+ environment: "all",
110
+ ...config
111
+ };
112
+ if (!this.shouldEnablePlugin(effectiveConfig)) {
113
+ console.log(`[BlaC] Plugin "${plugin.name}" skipped (environment mismatch)`);
114
+ return;
115
+ }
116
+ if (this.plugins.has(plugin.name)) throw new Error(`Plugin "${plugin.name}" is already installed`);
117
+ const installContext = this.buildContext(void 0);
118
+ this.plugins.set(plugin.name, {
119
+ plugin,
120
+ config: effectiveConfig,
121
+ installContext
122
+ });
123
+ if (plugin.onInstall) try {
124
+ plugin.onInstall(installContext);
125
+ } catch (error) {
126
+ console.error(`[BlaC] Error installing plugin "${plugin.name}":`, error);
127
+ this.plugins.delete(plugin.name);
128
+ throw error;
129
+ }
130
+ console.log(`[BlaC] Plugin "${plugin.name}" v${plugin.version} installed`);
131
+ }
132
+ /**
133
+ * Uninstall a plugin by name
134
+ * @param pluginName - The name of the plugin to uninstall
135
+ * @throws Error if plugin is not installed
136
+ */
137
+ uninstall(pluginName) {
138
+ const installed = this.plugins.get(pluginName);
139
+ if (!installed) throw new Error(`Plugin "${pluginName}" is not installed`);
140
+ if (installed.plugin.onUninstall) try {
141
+ installed.plugin.onUninstall();
142
+ } catch (error) {
143
+ console.error(`[BlaC] Error uninstalling plugin "${pluginName}":`, error);
144
+ }
145
+ this.plugins.delete(pluginName);
146
+ console.log(`[BlaC] Plugin "${pluginName}" uninstalled`);
147
+ }
148
+ /**
149
+ * Get an installed plugin by name
150
+ * @param pluginName - The name of the plugin to retrieve
151
+ * @returns The plugin instance or undefined if not found
152
+ */
153
+ getPlugin(pluginName) {
154
+ return this.plugins.get(pluginName)?.plugin;
155
+ }
156
+ /**
157
+ * Get all installed plugins
158
+ * @returns Array of all installed plugins
159
+ */
160
+ getAllPlugins() {
161
+ return Array.from(this.plugins.values()).map((p) => p.plugin);
162
+ }
163
+ /**
164
+ * Check if a plugin is installed
165
+ * @param pluginName - The name of the plugin to check
166
+ * @returns true if the plugin is installed
167
+ */
168
+ hasPlugin(pluginName) {
169
+ return this.plugins.has(pluginName);
170
+ }
171
+ /**
172
+ * Uninstall all plugins
173
+ */
174
+ clear() {
175
+ for (const name of this.plugins.keys()) this.uninstall(name);
176
+ }
177
+ destroy() {
178
+ this.clear();
179
+ for (const unsub of this.lifecycleUnsubscribers) unsub();
180
+ this.lifecycleUnsubscribers = [];
181
+ }
182
+ /**
183
+ * Wire registry lifecycle events into plugin dispatch.
184
+ *
185
+ * `onStateChange` is NOT wired through `registry.on('stateChanged', …)` —
186
+ * that event lacks the `PathSet` payload. Instead, on each `created` we
187
+ * subscribe to the container's channel directly so we get
188
+ * `(paths)` and capture `(prev, next)` via the per-container snapshot.
189
+ */
190
+ setupLifecycleHooks() {
191
+ this.lifecycleUnsubscribers = [
192
+ this.registry.on("created", (instance) => {
193
+ this.attachStateBridge(instance);
194
+ this.notifyPlugins("onCreated", instance);
195
+ }),
196
+ this.registry.on("disposed", (instance) => {
197
+ this.notifyPlugins("onDestroyed", instance);
198
+ this.detachStateBridge(instance);
199
+ }),
200
+ this.registry.on("refAcquired", (instance, refId) => {
201
+ this.notifyPlugins("onRefAcquired", instance, refId);
202
+ }),
203
+ this.registry.on("refReleased", (instance, refId) => {
204
+ this.notifyPlugins("onRefReleased", instance, refId);
205
+ }),
206
+ this.registry.on("depsChanged", (instance, previousDeps, currentDeps) => {
207
+ this.notifyPlugins("onDepsChanged", instance, previousDeps, currentDeps);
208
+ })
209
+ ];
210
+ }
211
+ /**
212
+ * Subscribe to the container's channel with `ALL_PATHS` interest, so we
213
+ * fire on every flush. Capture `prev` from the snapshot taken on the
214
+ * previous flush (or at create-time for the first flush) and pass the
215
+ * channel's `paths` argument straight through to plugins.
216
+ *
217
+ * Per-container bookkeeping is stored in a `WeakMap` keyed by the
218
+ * container itself, so a disposed/GC'd container drops cleanly.
219
+ */
220
+ attachStateBridge(container) {
221
+ if (this.containerBridges.has(container)) return;
222
+ const bridge = {
223
+ unsub: () => {},
224
+ prevState: container.state
225
+ };
226
+ this.containerBridges.set(container, bridge);
227
+ bridge.unsub = container.channel.subscribe(() => _dirtytalk_structural.ALL_PATHS, (paths) => this.dispatchStateChange(container, paths));
228
+ }
229
+ detachStateBridge(container) {
230
+ const bridge = this.containerBridges.get(container);
231
+ if (!bridge) return;
232
+ bridge.unsub();
233
+ this.containerBridges.delete(container);
234
+ }
235
+ /**
236
+ * Channel-flush callback. Snapshots `next`, hands `(prev, next, paths)`
237
+ * to every enabled plugin's `onStateChange`, then updates `prevState`
238
+ * for the next flush.
239
+ *
240
+ * Note: `prev` is captured once and reused across plugins — every
241
+ * plugin sees the same `prev`/`next`/`paths` regardless of dispatch
242
+ * order, matching the "snapshot prev once per flush" invariant.
243
+ */
244
+ dispatchStateChange(container, paths) {
245
+ const bridge = this.containerBridges.get(container);
246
+ if (!bridge) return;
247
+ const prev = bridge.prevState;
248
+ const next = container.state;
249
+ bridge.prevState = next;
250
+ for (const { plugin, config } of this.plugins.values()) {
251
+ if (!config.enabled) continue;
252
+ const hook = plugin.onStateChange;
253
+ if (typeof hook !== "function") continue;
254
+ try {
255
+ hook.call(plugin, this.buildContext(container), prev, next, paths);
256
+ } catch (error) {
257
+ console.error(`[BlaC] Error in plugin "${plugin.name}" onStateChange:`, error);
258
+ }
259
+ }
260
+ }
261
+ /**
262
+ * Notify all plugins of a lifecycle event.
263
+ *
264
+ * Builds a fresh `PluginContext` per dispatch (instance becomes
265
+ * `ctx.container`), so plugins can reach the focal bloc through
266
+ * `ctx.container`.
267
+ */
268
+ notifyPlugins(hookName, instance, ...extraArgs) {
269
+ for (const { plugin, config } of this.plugins.values()) {
270
+ if (!config.enabled) continue;
271
+ const hook = plugin[hookName];
272
+ if (typeof hook !== "function") continue;
273
+ try {
274
+ hook.call(plugin, this.buildContext(instance), ...extraArgs);
275
+ } catch (error) {
276
+ console.error(`[BlaC] Error in plugin "${plugin.name}" ${hookName}:`, error);
277
+ }
278
+ }
279
+ }
280
+ /**
281
+ * Build a `PluginContext` for a given focal container. The context is
282
+ * cheap to build — its methods close over `this.registry` directly —
283
+ * so we create one per dispatch rather than caching per container.
284
+ * This sidesteps the lifetime question of "when do we evict a cached
285
+ * context?" and keeps `paths`-vs-`container` lifetimes cleanly
286
+ * separated.
287
+ */
288
+ buildContext(container) {
289
+ const registry = this.registry;
290
+ return {
291
+ container,
292
+ getInstanceMetadata: (instance) => {
293
+ return {
294
+ id: instance.$blac.id,
295
+ className: instance.constructor.name,
296
+ isDisposed: instance.$blac.disposed,
297
+ name: instance.$blac.name,
298
+ createdAt: instance.$blac.createdAt,
299
+ state: instance.state,
300
+ hydrationStatus: instance.$blac.hydration.status,
301
+ isHydrated: instance.$blac.hydration.isHydrated,
302
+ hydrationError: instance.$blac.hydration.error,
303
+ changedWhileHydrating: instance.$blac.hydration.changedWhileHydrating,
304
+ args: instance.args
305
+ };
306
+ },
307
+ getState: (instance) => {
308
+ return instance.state;
309
+ },
310
+ getHydrationStatus: (instance) => {
311
+ return instance.$blac.hydration.status;
312
+ },
313
+ startHydration: (instance) => {
314
+ instance.$blac.hydration.begin();
315
+ },
316
+ applyHydratedState: (instance, state) => {
317
+ return instance.$blac.hydration.apply(state);
318
+ },
319
+ finishHydration: (instance) => {
320
+ instance.$blac.hydration.finish();
321
+ },
322
+ failHydration: (instance, error) => {
323
+ instance.$blac.hydration.fail(error);
324
+ },
325
+ waitForHydration: (instance) => {
326
+ return instance.$blac.hydration.wait();
327
+ },
328
+ queryInstances: (typeClass) => {
329
+ return registry.getAll(typeClass);
330
+ },
331
+ getAllTypes: () => {
332
+ return registry.getTypes();
333
+ },
334
+ getStats: () => {
335
+ return registry.getStats();
336
+ },
337
+ getRefIds: (instanceId) => {
338
+ for (const Type of registry.getTypes()) {
339
+ const map = registry.getInstancesMap(Type);
340
+ for (const [, entry] of map) if (entry.instance.$blac.id === instanceId) return Array.from(entry.refs.keys());
341
+ }
342
+ return [];
343
+ }
344
+ };
345
+ }
346
+ /**
347
+ * Check if plugin should be enabled based on environment
348
+ */
349
+ shouldEnablePlugin(config) {
350
+ if (!config.enabled) return false;
351
+ if (config.environment === "all") return true;
352
+ return this.getCurrentEnvironment() === config.environment;
353
+ }
354
+ /**
355
+ * Get current environment
356
+ */
357
+ getCurrentEnvironment() {
358
+ if (typeof process !== "undefined") {
359
+ if (process.env.NODE_ENV === "test") return "test";
360
+ if (process.env.NODE_ENV === "production") return "production";
361
+ return "development";
362
+ }
363
+ return "development";
364
+ }
365
+ };
366
+ /**
367
+ * Create a plugin manager instance
368
+ * @param registry - The StateContainerRegistry to monitor for lifecycle events
369
+ * @returns A new PluginManager instance
370
+ */
371
+ function createPluginManager(registry) {
372
+ return new PluginManager(registry);
373
+ }
374
+ //#endregion
375
+ //#region src/constants.ts
376
+ /**
377
+ * Default configuration constants for BlaC
378
+ *
379
+ * Centralized location for all magic numbers and default values.
380
+ */
381
+ /**
382
+ * Default configuration constants for BlaC
383
+ */
384
+ const BLAC_DEFAULTS = {
385
+ /**
386
+ * Default instance key for shared instances
387
+ */
388
+ DEFAULT_INSTANCE_KEY: "default",
389
+ /**
390
+ * Maximum getter nesting depth (prevents infinite recursion)
391
+ */
392
+ MAX_GETTER_DEPTH: 10
393
+ };
394
+ /**
395
+ * Static property names for StateContainer classes
396
+ * Used for feature flags and configuration on bloc classes
397
+ */
398
+ const BLAC_STATIC_PROPS = {
399
+ /**
400
+ * Mark a bloc to never be auto-disposed (kept alive permanently)
401
+ */
402
+ KEEP_ALIVE: "keepAlive",
403
+ /**
404
+ * Exclude a bloc from DevTools reporting (prevents infinite loops)
405
+ */
406
+ EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools",
407
+ /**
408
+ * Per-class equality function used to short-circuit `emit`/`patch` when the
409
+ * new state is structurally equal to the previous state. Falls back to the
410
+ * global `configureBlac({ equality })` value when unset.
411
+ */
412
+ EQUALITY: "__equality",
413
+ /**
414
+ * Per-class key function: `static key = (args) => string`.
415
+ * When set, the registry calls `Type.key(args)` to derive the instance key
416
+ * instead of using a structural hash of `args`. Allows blocs to ignore
417
+ * non-identity fields (e.g., `readonly` flags) while still keying by id.
418
+ */
419
+ KEY: "key"
420
+ };
421
+ /**
422
+ * Standard error message prefix
423
+ */
424
+ const BLAC_ERROR_PREFIX = "[BlaC]";
425
+ //#endregion
426
+ //#region src/utils/static-props.ts
427
+ /**
428
+ * Utility functions for accessing static properties on StateContainer classes
429
+ */
430
+ /**
431
+ * Get a static property from a class constructor
432
+ * Type-safe helper that avoids (Type as any) casts
433
+ *
434
+ * @param Type - The class constructor
435
+ * @param propName - The property name to access
436
+ * @param defaultValue - Optional default value if property is undefined
437
+ * @returns The property value or default
438
+ */
439
+ function getStaticProp(Type, propName, defaultValue) {
440
+ return Type[propName] ?? defaultValue;
441
+ }
442
+ /**
443
+ * Check if a class is marked as keepAlive.
444
+ * KeepAlive classes are never auto-disposed when ref count reaches 0.
445
+ * @param Type - The class constructor to check
446
+ * @returns true if the class has `static keepAlive = true`
447
+ */
448
+ function isKeepAliveClass(Type) {
449
+ return getStaticProp(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;
450
+ }
451
+ /**
452
+ * Check if a class should be excluded from DevTools.
453
+ * Used to prevent infinite loops when DevTools tracks itself.
454
+ * @param Type - The class constructor to check
455
+ * @returns true if the class has `static __excludeFromDevTools = true`
456
+ */
457
+ function isExcludedFromDevTools(Type) {
458
+ return getStaticProp(Type, BLAC_STATIC_PROPS.EXCLUDE_FROM_DEVTOOLS) === true;
459
+ }
460
+ /**
461
+ * Get the per-class equality function set via `@blac({ equality })`, if any.
462
+ * @param Type - The class constructor to check
463
+ * @returns the equality function or `undefined`
464
+ */
465
+ function getClassEquality(Type) {
466
+ const fn = getStaticProp(Type, BLAC_STATIC_PROPS.EQUALITY);
467
+ return typeof fn === "function" ? fn : void 0;
468
+ }
469
+ /**
470
+ * Get the per-class key function set via `@blac({ key })` or `static key = …`, if any.
471
+ * Used by the registry to derive a stable instance key from `args`.
472
+ * @param Type - The class constructor to check
473
+ * @returns the key function or `undefined`
474
+ */
475
+ function getClassKey(Type) {
476
+ const fn = getStaticProp(Type, BLAC_STATIC_PROPS.KEY, void 0);
477
+ return typeof fn === "function" ? fn : void 0;
478
+ }
479
+ //#endregion
480
+ //#region src/utils/structural-key.ts
481
+ /**
482
+ * Deterministic, order-independent hash of serializable args.
483
+ * Sorts object keys so {a,b} === {b,a}.
484
+ * Throws (dev) if it encounters a function or non-plain object — those belong in `deps`.
485
+ */
486
+ const DEFAULT_STRUCTURAL_KEY = "default";
487
+ /**
488
+ * Produce a stable string key for serializable args.
489
+ * - `undefined` / `void` args → `'default'` sentinel (no-args blocs stay on the default key).
490
+ * - Object keys are sorted for order-independence.
491
+ * - Arrays keep their insertion order.
492
+ * - Functions throw — they must be passed via `deps`, not `args`.
493
+ */
494
+ function structuralKey(args) {
495
+ if (args === void 0 || args === null) return DEFAULT_STRUCTURAL_KEY;
496
+ return JSON.stringify(args, function(_k, v) {
497
+ if (typeof v === "function") throw new Error("[blac] args must be serializable; put refs/callbacks in `deps`");
498
+ if (v && typeof v === "object" && !Array.isArray(v)) return Object.keys(v).sort().reduce((o, k) => {
499
+ o[k] = v[k];
500
+ return o;
501
+ }, {});
502
+ return v;
503
+ });
504
+ }
505
+ //#endregion
506
+ //#region src/core/symbols.ts
507
+ /**
508
+ * @internal Apply one owner's (consumer's) deps slice to an instance.
509
+ * Called by framework adapters (e.g. @blac/react useBloc) — not public API.
510
+ */
511
+ const APPLY_DEPS = Symbol("blac.applyDeps");
512
+ /**
513
+ * @internal Withdraw one owner's entire deps slice (consumer unmounted).
514
+ * Called by framework adapters — not public API.
515
+ */
516
+ const REMOVE_DEPS_OWNER = Symbol("blac.removeDepsOwner");
517
+ /**
518
+ * @internal Symbol-keyed configuration entry point on `StateContainer`.
519
+ * Writes the instance's identity fields (`_name`/`_debug`/`_instanceId`),
520
+ * resolves per-class equality, emits the registry `created` event, and runs
521
+ * `init()` once.
522
+ *
523
+ * Framework-only — the registry (`StateContainerRegistry.ensure`) and testing
524
+ * helpers are the sole callers, mirroring the `APPLY_DEPS` precedent.
525
+ */
526
+ const INIT_CONFIG = Symbol("blac.initConfig");
527
+ //#endregion
528
+ //#region src/core/StateContainerRegistry.ts
529
+ /**
530
+ * Central registry for managing StateContainer instances.
531
+ * Handles instance lifecycle, named ref tracking, and lifecycle event emission.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * const registry = new StateContainerRegistry();
536
+ * const instance = registry.acquire(MyBloc); // ownership, must release
537
+ * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
538
+ * registry.on('stateChanged', (container, prev, next) => {
539
+ * console.log('State changed:', prev, '->', next);
540
+ * });
541
+ * ```
542
+ */
543
+ var StateContainerRegistry = class {
544
+ constructor() {
545
+ this.instancesByConstructor = /* @__PURE__ */ new WeakMap();
546
+ this.types = /* @__PURE__ */ new Set();
547
+ this.registeredTypeNames = /* @__PURE__ */ new Set();
548
+ this.listeners = /* @__PURE__ */ new Map();
549
+ this._stateChangedListenerCount = 0;
550
+ this._pendingStateChanges = null;
551
+ this._autoRefIdCounter = 0;
552
+ }
553
+ get hasStateChangedListeners() {
554
+ return this._stateChangedListenerCount > 0;
555
+ }
556
+ /**
557
+ * Register a type for lifecycle event tracking
558
+ * @param constructor - The StateContainer class constructor
559
+ */
560
+ registerType(constructor) {
561
+ this.types.add(constructor);
562
+ }
563
+ /**
564
+ * Register a StateContainer class with configuration
565
+ * @param constructor - The StateContainer class constructor
566
+ * @throws Error if type is already registered
567
+ */
568
+ register(constructor) {
569
+ const className = constructor.name;
570
+ if (this.registeredTypeNames.has(className)) throw new Error(`${BLAC_ERROR_PREFIX} Type "${className}" is already registered`);
571
+ this.registeredTypeNames.add(className);
572
+ this.registerType(constructor);
573
+ }
574
+ ensureInstancesMap(Type) {
575
+ let instances = this.instancesByConstructor.get(Type);
576
+ if (!instances) {
577
+ instances = /* @__PURE__ */ new Map();
578
+ this.instancesByConstructor.set(Type, instances);
579
+ }
580
+ return instances;
581
+ }
582
+ /**
583
+ * Get the instances Map for a specific class (public API for stats/debugging)
584
+ */
585
+ getInstancesMap(Type) {
586
+ return this.instancesByConstructor.get(Type) || /* @__PURE__ */ new Map();
587
+ }
588
+ /**
589
+ * Directly insert an instance entry into the registry without going through
590
+ * acquire/release. Creates the internal WeakMap bucket for the constructor if
591
+ * it does not exist yet. Replaces any existing entry for the same key.
592
+ *
593
+ * The provided instance is NOT configured or disposed here — callers are
594
+ * responsible for any initConfig / dispose calls. Intended for testing
595
+ * helpers that create stubs outside the normal acquisition path.
596
+ *
597
+ * @internal Used by testing helpers only.
598
+ */
599
+ insertInstance(Type, instanceKey, instance, refs = /* @__PURE__ */ new Map()) {
600
+ const instances = this.ensureInstancesMap(Type);
601
+ const existingEntry = instances.get(instanceKey);
602
+ if (existingEntry && existingEntry.instance !== instance && !existingEntry.instance.$blac.disposed) existingEntry.instance.dispose();
603
+ instances.set(instanceKey, {
604
+ instance,
605
+ refs
606
+ });
607
+ }
608
+ /**
609
+ * Resolve the storage key for an instance. This is the single source of truth
610
+ * for keying — `acquire` and `release` MUST agree, otherwise a ref taken under
611
+ * an args-derived key is never dropped (instance leaks).
612
+ *
613
+ * Resolution order (explicit beats derived):
614
+ * explicit key > `static key(args)` > structural hash of args > default sentinel.
615
+ *
616
+ * @param Type - The StateContainer class constructor
617
+ * @param instanceKey - Explicit key, or undefined to derive from args
618
+ * @param args - Construction args used for structural/`static key` derivation
619
+ */
620
+ resolveKey(Type, instanceKey, args) {
621
+ if (instanceKey !== void 0) return instanceKey;
622
+ const keyFn = getClassKey(Type);
623
+ if (keyFn) return keyFn(args);
624
+ if (args !== void 0) return structuralKey(args);
625
+ return DEFAULT_STRUCTURAL_KEY;
626
+ }
627
+ /**
628
+ * Circuit breaker for runaway instance creation. Throws when a single
629
+ * constructor would exceed `maxInstancesPerType` live instances — almost
630
+ * always an unstable instance key (e.g. a new object/array passed as `args`
631
+ * every render, or a missing `static key`) leaking an instance per render.
632
+ */
633
+ assertInstanceLimit(Type, currentCount) {
634
+ const limit = getBlacConfig().maxInstancesPerType;
635
+ if (limit > 0 && currentCount >= limit) throw new Error(`${BLAC_ERROR_PREFIX} ${Type.name} exceeded the maximum of ${limit} live instances. This usually means the instance key is unstable — e.g. \`args\` that change identity every render, or a missing \`static key\` — so a new instance is created and never disposed (memory leak). Stabilize the key, add a \`static key(args)\`, or raise \`configureBlac({ maxInstancesPerType })\`.`);
636
+ }
637
+ /**
638
+ * Circuit breaker for runaway reference growth. Throws when one instance
639
+ * accumulates more than `maxRefsPerInstance` distinct live refs — almost
640
+ * always consumer cleanup (e.g. `useBloc`'s unmount `release`) never firing.
641
+ */
642
+ assertRefLimit(Type, resolvedKey, refCount) {
643
+ const limit = getBlacConfig().maxRefsPerInstance;
644
+ if (limit > 0 && refCount > limit) throw new Error(`${BLAC_ERROR_PREFIX} ${Type.name} instance "${resolvedKey}" exceeded the maximum of ${limit} live references. This usually means references are acquired without a matching release (e.g. a consumer that never unmounts/cleans up), leaking refs that keep the instance alive forever. Ensure every acquire is paired with a release, or raise \`configureBlac({ maxRefsPerInstance })\`.`);
645
+ }
646
+ /**
647
+ * Acquire an instance with ref tracking (ownership semantics).
648
+ * Creates a new instance if one doesn't exist, or returns existing and adds a ref.
649
+ * You must call `release()` with the same refId when done.
650
+ *
651
+ * @internal Internal key tier. Public callers use the args-based `acquire`
652
+ * wrapper; `useBloc` and `watch` address a pre-resolved key here.
653
+ * @param Type - The StateContainer class constructor
654
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
655
+ * @param options - Acquisition options
656
+ * @param options.canCreate - Whether to create new instance if not found (default: true)
657
+ * @param options.countRef - Whether to add a reference (default: true)
658
+ * @param options.refId - Named reference ID for debugging; auto-generated if omitted
659
+ * @returns The state container instance
660
+ */
661
+ acquire(Type, instanceKey, options = {}) {
662
+ const { canCreate = true, countRef = true } = options;
663
+ const args = options.args;
664
+ const resolvedKey = this.resolveKey(Type, instanceKey, args);
665
+ const config = {
666
+ instanceId: resolvedKey,
667
+ args
668
+ };
669
+ const instances = this.ensureInstancesMap(Type);
670
+ let entry = instances.get(resolvedKey);
671
+ if (entry?.instance.$blac.disposed) {
672
+ instances.delete(resolvedKey);
673
+ entry = void 0;
674
+ }
675
+ if (entry) {
676
+ if (process.env.NODE_ENV !== "production" && args !== void 0 && entry.args !== void 0) {
677
+ const incomingKey = structuralKey(args);
678
+ const storedKey = structuralKey(entry.args);
679
+ if (incomingKey !== storedKey) console.warn(`${BLAC_ERROR_PREFIX} ${Type.name} instance key "${resolvedKey}" was acquired with different args. Existing args: ${storedKey}, new args: ${incomingKey}. The existing instance will be reused. If distinct args should produce distinct instances, either remove the explicit instanceKey or provide a \`static key\` function that reflects the difference.`);
680
+ }
681
+ if (countRef) {
682
+ const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
683
+ entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);
684
+ this.assertRefLimit(Type, resolvedKey, entry.refs.size);
685
+ this.emit("refAcquired", entry.instance, refId);
686
+ }
687
+ return entry.instance;
688
+ }
689
+ if (!canCreate) throw new Error(`${BLAC_ERROR_PREFIX} ${Type.name} instance "${resolvedKey}" not found and creation is disabled.`);
690
+ this.assertInstanceLimit(Type, instances.size);
691
+ const instance = new Type();
692
+ instance[INIT_CONFIG](config);
693
+ const initialRefs = /* @__PURE__ */ new Map();
694
+ let initialRefId;
695
+ if (countRef) {
696
+ initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;
697
+ initialRefs.set(initialRefId, 1);
698
+ }
699
+ instances.set(resolvedKey, {
700
+ instance,
701
+ refs: initialRefs,
702
+ args
703
+ });
704
+ this.registerType(Type);
705
+ if (initialRefId) this.emit("refAcquired", instance, initialRefId);
706
+ return instance;
707
+ }
708
+ /**
709
+ * Borrow an existing instance without adding a ref (borrowing semantics).
710
+ * Tracks cross-bloc dependency for reactive updates.
711
+ *
712
+ * @internal Internal key tier; public callers use the args-based `borrow`.
713
+ * @param Type - The StateContainer class constructor
714
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
715
+ * @returns The state container instance
716
+ * @throws Error if instance doesn't exist
717
+ */
718
+ borrow(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
719
+ return this.acquire(Type, instanceKey, {
720
+ canCreate: false,
721
+ countRef: false
722
+ });
723
+ }
724
+ /**
725
+ * Safely borrow an existing instance (borrowing semantics with error handling).
726
+ * Returns discriminated union for type-safe conditional access.
727
+ *
728
+ * @internal Internal key tier; public callers use the args-based `borrowSafe`.
729
+ * @param Type - The StateContainer class constructor
730
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
731
+ * @returns Discriminated union with either the instance or an error
732
+ */
733
+ borrowSafe(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
734
+ try {
735
+ return {
736
+ error: null,
737
+ instance: this.borrow(Type, instanceKey)
738
+ };
739
+ } catch (error) {
740
+ return {
741
+ error,
742
+ instance: null
743
+ };
744
+ }
745
+ }
746
+ /**
747
+ * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
748
+ * Gets existing instance OR creates it if it doesn't exist, without adding a ref.
749
+ * Tracks cross-bloc dependency for reactive updates.
750
+ *
751
+ * Use this in bloc-to-bloc communication when you need to ensure an instance exists
752
+ * but don't want to claim ownership (no ref added).
753
+ *
754
+ * @internal Internal key tier; public callers use the args-based `ensure`.
755
+ * @param Type - The StateContainer class constructor
756
+ * @param instanceKey - Pre-resolved instance key, or undefined to derive from `args`
757
+ * (`static key(args)` / structural hash), matching `acquire`.
758
+ * @param args - Construction args; used for keying when no explicit key is given
759
+ * @returns The state container instance
760
+ */
761
+ ensure(Type, instanceKey, args) {
762
+ return this.acquire(Type, instanceKey, {
763
+ canCreate: true,
764
+ countRef: false,
765
+ args
766
+ });
767
+ }
768
+ /**
769
+ * Release a reference to an instance.
770
+ * Removes the ref and disposes when refs is empty (unless keepAlive).
771
+ * Releasing an already-removed refId is a no-op (idempotent).
772
+ *
773
+ * @internal Internal key tier; public callers use the args-based `release`.
774
+ * @param Type - The StateContainer class constructor
775
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
776
+ * @param forceDispose - Force immediate disposal regardless of refs
777
+ * @param refId - The specific ref to remove; removes one arbitrary ref if omitted
778
+ */
779
+ release(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY, forceDispose = false, refId) {
780
+ const instances = this.ensureInstancesMap(Type);
781
+ const entry = instances.get(instanceKey);
782
+ if (!entry) return;
783
+ if (forceDispose) {
784
+ if (!entry.instance.$blac.disposed) entry.instance.dispose();
785
+ instances.delete(instanceKey);
786
+ return;
787
+ }
788
+ let releasedRefId;
789
+ if (refId !== void 0) {
790
+ const count = entry.refs.get(refId) ?? 0;
791
+ if (count <= 1) entry.refs.delete(refId);
792
+ else entry.refs.set(refId, count - 1);
793
+ releasedRefId = refId;
794
+ } else {
795
+ const firstKey = entry.refs.keys().next().value;
796
+ if (firstKey !== void 0) {
797
+ const count = entry.refs.get(firstKey) ?? 0;
798
+ if (count <= 1) entry.refs.delete(firstKey);
799
+ else entry.refs.set(firstKey, count - 1);
800
+ releasedRefId = firstKey;
801
+ }
802
+ }
803
+ if (releasedRefId) this.emit("refReleased", entry.instance, releasedRefId);
804
+ const keepAlive = isKeepAliveClass(Type);
805
+ if (entry.refs.size === 0 && !keepAlive) {
806
+ const deps = entry.instance.$blac.dependencies;
807
+ if (!entry.instance.$blac.disposed) entry.instance.dispose();
808
+ instances.delete(instanceKey);
809
+ for (const [DepType, depKey] of deps) {
810
+ const depInstances = this.ensureInstancesMap(DepType);
811
+ const depEntry = depInstances.get(depKey);
812
+ if (depEntry && depEntry.refs.size === 0 && !isKeepAliveClass(DepType) && !depEntry.instance.$blac.disposed) {
813
+ depEntry.instance.dispose();
814
+ depInstances.delete(depKey);
815
+ }
816
+ }
817
+ }
818
+ }
819
+ /**
820
+ * Get all instances of a specific type.
821
+ * @param Type - The StateContainer class constructor
822
+ * @returns Array of all instances
823
+ */
824
+ getAll(Type) {
825
+ const instances = this.ensureInstancesMap(Type);
826
+ const result = [];
827
+ for (const entry of instances.values()) result.push(entry.instance);
828
+ return result;
829
+ }
830
+ /**
831
+ * Safely iterate over all instances of a type.
832
+ * Skips disposed instances and catches callback errors.
833
+ * @param Type - The StateContainer class constructor
834
+ * @param callback - Function to call for each instance
835
+ */
836
+ forEach(Type, callback) {
837
+ const instances = this.ensureInstancesMap(Type);
838
+ for (const entry of instances.values()) {
839
+ const instance = entry.instance;
840
+ if (!instance.$blac.disposed) try {
841
+ callback(instance);
842
+ } catch (error) {
843
+ console.error(`${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`, error);
844
+ }
845
+ }
846
+ }
847
+ /**
848
+ * Clear all instances of a specific type (disposes them).
849
+ * @param Type - The StateContainer class constructor
850
+ */
851
+ clear(Type) {
852
+ const instances = this.ensureInstancesMap(Type);
853
+ for (const entry of instances.values()) if (!entry.instance.$blac.disposed) entry.instance.dispose();
854
+ instances.clear();
855
+ }
856
+ /**
857
+ * Get reference count for an instance (number of active refs).
858
+ *
859
+ * @internal Internal key tier; public callers use the args-based `getRefCount`.
860
+ * @param Type - The StateContainer class constructor
861
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
862
+ * @returns Current ref count (0 if instance doesn't exist)
863
+ */
864
+ getRefCount(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
865
+ return this.ensureInstancesMap(Type).get(instanceKey)?.refs.size ?? 0;
866
+ }
867
+ /**
868
+ * Get all active reference IDs for an instance.
869
+ *
870
+ * @internal Internal key tier; public callers use the args-based `getRefIds`.
871
+ * @param Type - The StateContainer class constructor
872
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
873
+ * @returns Array of ref ID strings (empty if instance doesn't exist)
874
+ */
875
+ getRefIds(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
876
+ const instances = this.instancesByConstructor.get(Type);
877
+ if (!instances) return [];
878
+ const entry = instances.get(instanceKey);
879
+ return entry ? Array.from(entry.refs.keys()) : [];
880
+ }
881
+ /**
882
+ * Check if an instance exists.
883
+ *
884
+ * @internal Internal key tier; public callers use the args-based `hasInstance`.
885
+ * @param Type - The StateContainer class constructor
886
+ * @param instanceKey - Pre-resolved instance key (defaults to 'default')
887
+ * @returns true if instance exists
888
+ */
889
+ hasInstance(Type, instanceKey = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY) {
890
+ return this.ensureInstancesMap(Type).has(instanceKey);
891
+ }
892
+ /**
893
+ * Clear all instances from all types (for testing)
894
+ *
895
+ * Iterates all registered types and clears their instances.
896
+ * Also clears type tracking to reset the registry state.
897
+ */
898
+ clearAll() {
899
+ for (const Type of this.types) this.clear(Type);
900
+ this.types.clear();
901
+ this.registeredTypeNames.clear();
902
+ }
903
+ /**
904
+ * Get registry statistics for debugging.
905
+ * @returns Object with registeredTypes, totalInstances, and typeBreakdown
906
+ */
907
+ getStats() {
908
+ const typeBreakdown = {};
909
+ let totalInstances = 0;
910
+ for (const Type of this.types) {
911
+ const typeName = Type.name;
912
+ const count = this.getInstancesMap(Type).size;
913
+ typeBreakdown[typeName] = count;
914
+ totalInstances += count;
915
+ }
916
+ return {
917
+ registeredTypes: this.types.size,
918
+ totalInstances,
919
+ typeBreakdown
920
+ };
921
+ }
922
+ /**
923
+ * Get all registered types (for plugin system).
924
+ * @returns Array of all registered StateContainer class constructors
925
+ */
926
+ getTypes() {
927
+ return Array.from(this.types);
928
+ }
929
+ /**
930
+ * Subscribe to lifecycle events
931
+ * @param event - The lifecycle event to listen for
932
+ * @param listener - The listener function to call when the event occurs
933
+ * @returns Unsubscribe function
934
+ */
935
+ on(event, listener) {
936
+ if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
937
+ const instance = this.listeners.get(event);
938
+ if (!instance) throw new Error(`${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`);
939
+ instance.add(listener);
940
+ if (event === "stateChanged") this._stateChangedListenerCount++;
941
+ return () => {
942
+ if (this.listeners.get(event)?.delete(listener) && event === "stateChanged") this._stateChangedListenerCount--;
943
+ };
944
+ }
945
+ emit(event, ...args) {
946
+ const listeners = this.listeners.get(event);
947
+ if (!listeners || listeners.size === 0) return;
948
+ for (const listener of listeners) try {
949
+ listener(...args);
950
+ } catch (error) {
951
+ console.error(`${BLAC_ERROR_PREFIX} Listener error for '${event}':`, error);
952
+ }
953
+ }
954
+ /**
955
+ * Schedule a deferred stateChanged notification via microtask.
956
+ * Skips entirely when no stateChanged listeners are registered.
957
+ * @internal - Called by StateContainer.applyState
958
+ */
959
+ notifyStateChanged(container, previousState, newState) {
960
+ if (this._stateChangedListenerCount === 0) return;
961
+ if (!this._pendingStateChanges) {
962
+ this._pendingStateChanges = [];
963
+ queueMicrotask(() => this.flushStateChanged());
964
+ }
965
+ this._pendingStateChanges.push([
966
+ container,
967
+ previousState,
968
+ newState
969
+ ]);
970
+ }
971
+ flushStateChanged() {
972
+ const pending = this._pendingStateChanges;
973
+ this._pendingStateChanges = null;
974
+ if (!pending) return;
975
+ for (const [container, prev, next] of pending) this.emit("stateChanged", container, prev, next);
976
+ }
977
+ };
978
+ /**
979
+ * Global default registry instance
980
+ */
981
+ const globalRegistry = new StateContainerRegistry();
982
+ /**
983
+ * Global plugin manager (initialized lazily)
984
+ */
985
+ let _globalPluginManager = null;
986
+ /**
987
+ * Get the global plugin manager
988
+ */
989
+ function getPluginManager() {
990
+ if (!_globalPluginManager) _globalPluginManager = createPluginManager(globalRegistry);
991
+ return _globalPluginManager;
992
+ }
993
+ //#endregion
994
+ Object.defineProperty(exports, "APPLY_DEPS", {
995
+ enumerable: true,
996
+ get: function() {
997
+ return APPLY_DEPS;
998
+ }
999
+ });
1000
+ Object.defineProperty(exports, "BLAC_STATIC_PROPS", {
1001
+ enumerable: true,
1002
+ get: function() {
1003
+ return BLAC_STATIC_PROPS;
1004
+ }
1005
+ });
1006
+ Object.defineProperty(exports, "INIT_CONFIG", {
1007
+ enumerable: true,
1008
+ get: function() {
1009
+ return INIT_CONFIG;
1010
+ }
1011
+ });
1012
+ Object.defineProperty(exports, "PluginManager", {
1013
+ enumerable: true,
1014
+ get: function() {
1015
+ return PluginManager;
1016
+ }
1017
+ });
1018
+ Object.defineProperty(exports, "REMOVE_DEPS_OWNER", {
1019
+ enumerable: true,
1020
+ get: function() {
1021
+ return REMOVE_DEPS_OWNER;
1022
+ }
1023
+ });
1024
+ Object.defineProperty(exports, "StateContainerRegistry", {
1025
+ enumerable: true,
1026
+ get: function() {
1027
+ return StateContainerRegistry;
1028
+ }
1029
+ });
1030
+ Object.defineProperty(exports, "configureBlac", {
1031
+ enumerable: true,
1032
+ get: function() {
1033
+ return configureBlac;
1034
+ }
1035
+ });
1036
+ Object.defineProperty(exports, "getBlacConfig", {
1037
+ enumerable: true,
1038
+ get: function() {
1039
+ return getBlacConfig;
1040
+ }
1041
+ });
1042
+ Object.defineProperty(exports, "getClassEquality", {
1043
+ enumerable: true,
1044
+ get: function() {
1045
+ return getClassEquality;
1046
+ }
1047
+ });
1048
+ Object.defineProperty(exports, "getPluginManager", {
1049
+ enumerable: true,
1050
+ get: function() {
1051
+ return getPluginManager;
1052
+ }
1053
+ });
1054
+ Object.defineProperty(exports, "globalRegistry", {
1055
+ enumerable: true,
1056
+ get: function() {
1057
+ return globalRegistry;
1058
+ }
1059
+ });
1060
+ Object.defineProperty(exports, "isExcludedFromDevTools", {
1061
+ enumerable: true,
1062
+ get: function() {
1063
+ return isExcludedFromDevTools;
1064
+ }
1065
+ });
1066
+ Object.defineProperty(exports, "isKeepAliveClass", {
1067
+ enumerable: true,
1068
+ get: function() {
1069
+ return isKeepAliveClass;
1070
+ }
1071
+ });
1072
+ Object.defineProperty(exports, "resetBlacConfig", {
1073
+ enumerable: true,
1074
+ get: function() {
1075
+ return resetBlacConfig;
1076
+ }
1077
+ });
1078
+ Object.defineProperty(exports, "shallowEqualState", {
1079
+ enumerable: true,
1080
+ get: function() {
1081
+ return shallowEqualState;
1082
+ }
1083
+ });
1084
+
1085
+ //# sourceMappingURL=StateContainerRegistry-CSNm2Ws5.cjs.map