@blac/core 2.0.5 → 2.0.6

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