@blac/core 2.0.4 → 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 (81) 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/constants.d.ts +81 -0
  16. package/dist/core/Cubit.d.ts +24 -0
  17. package/dist/core/StateContainer.d.ts +177 -0
  18. package/dist/core/StateContainerRegistry.d.ts +189 -0
  19. package/dist/debug.cjs +11 -26
  20. package/dist/debug.d.cts +35 -0
  21. package/dist/debug.d.ts +35 -0
  22. package/dist/debug.js +2 -18
  23. package/dist/decorators/blac.d.ts +40 -0
  24. package/dist/decorators/index.d.ts +1 -0
  25. package/dist/index.cjs +162 -55
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +17 -794
  28. package/dist/index.d.ts +17 -794
  29. package/dist/index.js +145 -31
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugin/BlacPlugin.d.ts +143 -0
  32. package/dist/plugin/PluginManager.d.ts +81 -0
  33. package/dist/plugins.cjs +3 -3
  34. package/dist/plugins.d.cts +25 -0
  35. package/dist/plugins.d.ts +25 -0
  36. package/dist/plugins.js +2 -3
  37. package/dist/registry/acquire.d.ts +2 -0
  38. package/dist/registry/borrow.d.ts +9 -0
  39. package/dist/registry/config.d.ts +8 -0
  40. package/dist/registry/ensure.d.ts +2 -0
  41. package/dist/registry/index.d.ts +7 -0
  42. package/dist/registry/management.d.ts +4 -0
  43. package/dist/registry/queries.d.ts +5 -0
  44. package/dist/registry/release.d.ts +2 -0
  45. package/dist/resolve-dependencies-B22YjFGk.cjs +773 -0
  46. package/dist/resolve-dependencies-B22YjFGk.cjs.map +1 -0
  47. package/dist/resolve-dependencies-Cvq0glJF.js +648 -0
  48. package/dist/resolve-dependencies-Cvq0glJF.js.map +1 -0
  49. package/dist/tracked-B_MUXIpe.cjs +216 -0
  50. package/dist/tracked-B_MUXIpe.cjs.map +1 -0
  51. package/dist/tracked-I_q9buYg.js +181 -0
  52. package/dist/tracked-I_q9buYg.js.map +1 -0
  53. package/dist/tracking.cjs +3 -3
  54. package/dist/tracking.js +2 -3
  55. package/dist/types/branded.d.ts +26 -0
  56. package/dist/types/utilities.d.ts +51 -0
  57. package/dist/types.cjs +3 -14
  58. package/dist/types.js +1 -12
  59. package/dist/utils/idGenerator.d.ts +73 -0
  60. package/dist/utils/static-props.d.ts +35 -0
  61. package/dist/watch/index.d.ts +2 -0
  62. package/dist/watch/watch.d.ts +50 -0
  63. package/dist/watch-entry.cjs +7 -109
  64. package/dist/watch-entry.d.cts +26 -0
  65. package/dist/watch-entry.d.ts +26 -0
  66. package/dist/watch-entry.js +1 -104
  67. package/package.json +29 -51
  68. package/dist/StateContainerRegistry.cjs.map +0 -1
  69. package/dist/StateContainerRegistry.js.map +0 -1
  70. package/dist/debug.cjs.map +0 -1
  71. package/dist/debug.js.map +0 -1
  72. package/dist/management.cjs.map +0 -1
  73. package/dist/management.js.map +0 -1
  74. package/dist/resolve-dependencies.cjs.map +0 -1
  75. package/dist/resolve-dependencies.js.map +0 -1
  76. package/dist/types.cjs.map +0 -1
  77. package/dist/types.js.map +0 -1
  78. package/dist/watch-entry.cjs.map +0 -1
  79. package/dist/watch-entry.js.map +0 -1
  80. package/dist/watch.cjs.map +0 -1
  81. package/dist/watch.js.map +0 -1
@@ -0,0 +1,773 @@
1
+ const require_StateContainerRegistry = require("./StateContainerRegistry-CVPTMaHn.cjs");
2
+ //#region src/tracking/path-utils.ts
3
+ /**
4
+ * Path utilities for dependency tracking
5
+ *
6
+ * Provides utilities for parsing property paths and extracting values
7
+ * from nested objects using path strings.
8
+ *
9
+ * @internal
10
+ */
11
+ /**
12
+ * Parse a property path string into an array of segments
13
+ *
14
+ * @internal
15
+ *
16
+ * Handles both dot notation (a.b.c) and bracket notation (a[0].b)
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * parsePath('user.name') // ['user', 'name']
21
+ * parsePath('items[0].name') // ['items', '0', 'name']
22
+ * parsePath('data.users[2].address.city') // ['data', 'users', '2', 'address', 'city']
23
+ * ```
24
+ */
25
+ function parsePath(path) {
26
+ const segments = [];
27
+ let current = "";
28
+ let i = 0;
29
+ while (i < path.length) {
30
+ const char = path[i];
31
+ if (char === ".") {
32
+ if (current) segments.push(current);
33
+ current = "";
34
+ } else if (char === "[") {
35
+ if (current) segments.push(current);
36
+ current = "";
37
+ i++;
38
+ while (i < path.length && path[i] !== "]") current += path[i++];
39
+ if (current) segments.push(current);
40
+ current = "";
41
+ } else current += char;
42
+ i++;
43
+ }
44
+ if (current) segments.push(current);
45
+ return segments;
46
+ }
47
+ /**
48
+ * Get a value from an object using a path of segments
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const obj = { user: { name: 'Alice', age: 30 } }
53
+ * getValueAtPath(obj, ['user', 'name']) // 'Alice'
54
+ * getValueAtPath(obj, ['user', 'age']) // 30
55
+ * getValueAtPath(obj, ['user', 'missing']) // undefined
56
+ * ```
57
+ *
58
+ * @internal
59
+ */
60
+ function getValueAtPath(obj, segments) {
61
+ if (obj == null) return void 0;
62
+ let current = obj;
63
+ for (let i = 0; i < segments.length; i++) {
64
+ current = current[segments[i]];
65
+ if (current == null) return void 0;
66
+ }
67
+ return current;
68
+ }
69
+ /**
70
+ * Shallow equality comparison for arrays
71
+ *
72
+ * Compares two arrays element-by-element using Object.is
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * shallowEqual([1, 2, 3], [1, 2, 3]) // true
77
+ * shallowEqual([1, 2, 3], [1, 2, 4]) // false
78
+ * shallowEqual([1, 2], [1, 2, 3]) // false
79
+ * ```
80
+ *
81
+ * @internal
82
+ */
83
+ function shallowEqual(arr1, arr2) {
84
+ if (arr1.length !== arr2.length) return false;
85
+ for (let i = 0; i < arr1.length; i++) if (!Object.is(arr1[i], arr2[i])) return false;
86
+ return true;
87
+ }
88
+ //#endregion
89
+ //#region src/tracking/tracking-proxy.ts
90
+ /**
91
+ * Consolidated Tracking System
92
+ *
93
+ * This module provides all dependency and getter tracking functionality:
94
+ * - Proxy creation for automatic property access tracking
95
+ * - Dependency path tracking and change detection
96
+ * - Getter execution tracking for computed properties
97
+ * - Combined tracking proxy for watch/waitUntil use cases
98
+ */
99
+ /**
100
+ * Check if a value can be proxied
101
+ * Returns true for plain objects and arrays only.
102
+ * @internal
103
+ */
104
+ function isProxyable(value) {
105
+ if (typeof value !== "object" || value === null) return false;
106
+ const proto = Object.getPrototypeOf(value);
107
+ return proto === Object.prototype || proto === Array.prototype;
108
+ }
109
+ /**
110
+ * Create a new proxy tracker state
111
+ * @internal
112
+ */
113
+ function createProxyState() {
114
+ return {
115
+ trackedPaths: /* @__PURE__ */ new Set(),
116
+ isTracking: false,
117
+ proxyCache: /* @__PURE__ */ new WeakMap(),
118
+ boundFunctionsCache: null,
119
+ lastProxiedState: null,
120
+ lastProxy: null,
121
+ maxDepth: 10
122
+ };
123
+ }
124
+ /**
125
+ * Start tracking property accesses
126
+ * @internal
127
+ */
128
+ function startProxy(state) {
129
+ state.isTracking = true;
130
+ state.trackedPaths.clear();
131
+ }
132
+ /**
133
+ * Stop tracking and return the tracked paths
134
+ * @internal
135
+ */
136
+ function stopProxy(state) {
137
+ state.isTracking = false;
138
+ return new Set(state.trackedPaths);
139
+ }
140
+ /**
141
+ * Create a proxy for an array with property access tracking
142
+ * @internal
143
+ */
144
+ function createArrayProxy(state, target, path, depth = 0) {
145
+ const proxy = new Proxy(target, { get: (arr, prop) => {
146
+ if (typeof prop === "symbol") return Reflect.get(arr, prop);
147
+ const value = Reflect.get(arr, prop);
148
+ if (typeof value === "function") {
149
+ if (!state.boundFunctionsCache) state.boundFunctionsCache = /* @__PURE__ */ new WeakMap();
150
+ const cached = state.boundFunctionsCache.get(value);
151
+ if (cached) return cached;
152
+ const bound = value.bind(arr);
153
+ state.boundFunctionsCache.set(value, bound);
154
+ return bound;
155
+ }
156
+ if (prop === "length") {
157
+ if (state.isTracking) {
158
+ const fullPath = path ? `${path}.length` : "length";
159
+ state.trackedPaths.add(fullPath);
160
+ }
161
+ return value;
162
+ }
163
+ let fullPath;
164
+ if (typeof prop === "string") {
165
+ const index = Number(prop);
166
+ if (!isNaN(index) && index >= 0) fullPath = path ? `${path}[${index}]` : `[${index}]`;
167
+ else fullPath = path ? `${path}.${prop}` : prop;
168
+ } else return value;
169
+ if (isProxyable(value)) return createInternal(state, value, fullPath, depth + 1);
170
+ if (state.isTracking) state.trackedPaths.add(fullPath);
171
+ return value;
172
+ } });
173
+ state.proxyCache.set(target, proxy);
174
+ return proxy;
175
+ }
176
+ /**
177
+ * Create a proxy for an object with property access tracking
178
+ * @internal
179
+ */
180
+ function createInternal(state, target, path = "", depth = 0) {
181
+ if (!state.isTracking || !isProxyable(target)) return target;
182
+ if (depth >= state.maxDepth) {
183
+ console.warn(`${require_StateContainerRegistry.BLAC_ERROR_PREFIX} Proxy depth limit (${state.maxDepth}) reached at path "${path}". Deeper property accesses won't be tracked for re-renders.`);
184
+ return target;
185
+ }
186
+ if (state.proxyCache.has(target)) return state.proxyCache.get(target);
187
+ if (Array.isArray(target)) return createArrayProxy(state, target, path, depth);
188
+ const proxy = new Proxy(target, {
189
+ get: (obj, prop) => {
190
+ if (typeof prop === "symbol") return Reflect.get(obj, prop);
191
+ const value = Reflect.get(obj, prop);
192
+ if (typeof value === "function") {
193
+ if (!state.boundFunctionsCache) state.boundFunctionsCache = /* @__PURE__ */ new WeakMap();
194
+ const cached = state.boundFunctionsCache.get(value);
195
+ if (cached) return cached;
196
+ const bound = value.bind(obj);
197
+ state.boundFunctionsCache.set(value, bound);
198
+ return bound;
199
+ }
200
+ const fullPath = path ? `${path}.${String(prop)}` : String(prop);
201
+ if (typeof prop === "string" && state.isTracking) {
202
+ if (!prop.startsWith("_") && !prop.startsWith("$$")) state.trackedPaths.add(fullPath);
203
+ }
204
+ if (isProxyable(value)) return createInternal(state, value, fullPath, depth + 1);
205
+ return value;
206
+ },
207
+ has: (obj, prop) => {
208
+ if (typeof prop === "string" && state.isTracking) {
209
+ const fullPath = path ? `${path}.${prop}` : prop;
210
+ state.trackedPaths.add(fullPath);
211
+ }
212
+ return Reflect.has(obj, prop);
213
+ },
214
+ ownKeys: (obj) => {
215
+ if (state.isTracking && path) state.trackedPaths.add(path);
216
+ return Reflect.ownKeys(obj);
217
+ }
218
+ });
219
+ state.proxyCache.set(target, proxy);
220
+ return proxy;
221
+ }
222
+ /**
223
+ * Create a proxy for a target with caching
224
+ * @internal
225
+ */
226
+ function createForTarget(state, target) {
227
+ if (state.lastProxiedState === target && state.lastProxy) return state.lastProxy;
228
+ state.proxyCache = /* @__PURE__ */ new WeakMap();
229
+ state.boundFunctionsCache = null;
230
+ const proxy = createInternal(state, target, "", 0);
231
+ state.lastProxiedState = target;
232
+ state.lastProxy = proxy;
233
+ return proxy;
234
+ }
235
+ function isChildPath(child, parent) {
236
+ if (child === parent) return false;
237
+ return child.startsWith(parent + ".") || child.startsWith(parent + "[");
238
+ }
239
+ function getArrayParentPath(path) {
240
+ if (path.endsWith(".length")) return path.slice(0, -7);
241
+ const arrayIndexMatch = path.match(/^(.+?)\[\d+\]/);
242
+ if (arrayIndexMatch) return arrayIndexMatch[1];
243
+ return null;
244
+ }
245
+ /**
246
+ * @internal
247
+ */
248
+ function optimizeTrackedPaths(paths) {
249
+ if (paths.size === 0) return /* @__PURE__ */ new Set();
250
+ if (paths.size === 1) return new Set(paths);
251
+ const sortedPaths = Array.from(paths).sort((a, b) => b.length - a.length);
252
+ const optimized = /* @__PURE__ */ new Set();
253
+ for (const path of sortedPaths) {
254
+ let hasMoreSpecificChild = false;
255
+ for (const optimizedPath of optimized) if (isChildPath(optimizedPath, path)) {
256
+ hasMoreSpecificChild = true;
257
+ break;
258
+ }
259
+ if (!hasMoreSpecificChild) optimized.add(path);
260
+ }
261
+ const arrayParents = /* @__PURE__ */ new Set();
262
+ for (const path of optimized) {
263
+ const arrayParent = getArrayParentPath(path);
264
+ if (arrayParent) arrayParents.add(arrayParent);
265
+ }
266
+ for (const arrayParent of arrayParents) optimized.add(arrayParent);
267
+ return optimized;
268
+ }
269
+ /**
270
+ * @internal
271
+ */
272
+ function createDependencyState() {
273
+ return {
274
+ proxyState: createProxyState(),
275
+ previousRenderPaths: /* @__PURE__ */ new Set(),
276
+ currentRenderPaths: /* @__PURE__ */ new Set(),
277
+ pathCache: /* @__PURE__ */ new Map(),
278
+ lastCheckedState: null,
279
+ lastCheckedValues: /* @__PURE__ */ new Map()
280
+ };
281
+ }
282
+ /**
283
+ * @internal
284
+ */
285
+ function startDependency(tracker) {
286
+ startProxy(tracker.proxyState);
287
+ }
288
+ /**
289
+ * @internal
290
+ */
291
+ function createDependencyProxy(tracker, state) {
292
+ return createForTarget(tracker.proxyState, state);
293
+ }
294
+ /**
295
+ * @internal
296
+ */
297
+ function capturePaths(tracker, state) {
298
+ tracker.previousRenderPaths = tracker.currentRenderPaths;
299
+ tracker.currentRenderPaths = optimizeTrackedPaths(stopProxy(tracker.proxyState));
300
+ if (tracker.previousRenderPaths.size === 0 && tracker.currentRenderPaths.size === 0) return;
301
+ const trackedPathsUnion = new Set(tracker.previousRenderPaths);
302
+ for (const path of tracker.currentRenderPaths) trackedPathsUnion.add(path);
303
+ const canReuseCache = tracker.lastCheckedState === state;
304
+ for (const path of trackedPathsUnion) if (!tracker.pathCache.has(path)) {
305
+ const segments = parsePath(path);
306
+ const value = canReuseCache && tracker.lastCheckedValues.has(path) ? tracker.lastCheckedValues.get(path) : getValueAtPath(state, segments);
307
+ tracker.pathCache.set(path, {
308
+ segments,
309
+ value
310
+ });
311
+ } else {
312
+ const info = tracker.pathCache.get(path);
313
+ if (!info) continue;
314
+ info.value = canReuseCache && tracker.lastCheckedValues.has(path) ? tracker.lastCheckedValues.get(path) : getValueAtPath(state, info.segments);
315
+ }
316
+ tracker.lastCheckedValues.clear();
317
+ }
318
+ /**
319
+ * @internal
320
+ */
321
+ function hasDependencyChanges(tracker, state) {
322
+ if (tracker.pathCache.size === 0) return true;
323
+ tracker.lastCheckedValues.clear();
324
+ for (const [path, info] of tracker.pathCache.entries()) {
325
+ const currentValue = getValueAtPath(state, info.segments);
326
+ tracker.lastCheckedValues.set(path, currentValue);
327
+ if (!Object.is(currentValue, info.value)) {
328
+ tracker.lastCheckedState = state;
329
+ return true;
330
+ }
331
+ }
332
+ tracker.lastCheckedState = state;
333
+ return false;
334
+ }
335
+ /**
336
+ * @internal
337
+ */
338
+ function hasTrackedData(tracker) {
339
+ return tracker.proxyState.trackedPaths.size > 0 || tracker.pathCache.size > 0 || tracker.previousRenderPaths.size > 0;
340
+ }
341
+ const descriptorCache = /* @__PURE__ */ new WeakMap();
342
+ const blocProxyCache = /* @__PURE__ */ new WeakMap();
343
+ const activeTrackerMap = /* @__PURE__ */ new WeakMap();
344
+ const MAX_GETTER_DEPTH = require_StateContainerRegistry.BLAC_DEFAULTS.MAX_GETTER_DEPTH;
345
+ /**
346
+ * @internal
347
+ */
348
+ function getDescriptor(obj, prop) {
349
+ const constructor = obj.constructor;
350
+ let constructorCache = descriptorCache.get(constructor);
351
+ if (constructorCache?.has(prop)) return constructorCache.get(prop);
352
+ let current = obj;
353
+ let descriptor;
354
+ while (current && current !== Object.prototype) {
355
+ descriptor = Object.getOwnPropertyDescriptor(current, prop);
356
+ if (descriptor) break;
357
+ current = Object.getPrototypeOf(current);
358
+ }
359
+ if (!constructorCache) {
360
+ constructorCache = /* @__PURE__ */ new Map();
361
+ descriptorCache.set(constructor, constructorCache);
362
+ }
363
+ constructorCache.set(prop, descriptor);
364
+ return descriptor;
365
+ }
366
+ /**
367
+ * @internal
368
+ */
369
+ function isGetter(obj, prop) {
370
+ return getDescriptor(obj, prop)?.get !== void 0;
371
+ }
372
+ /**
373
+ * @internal
374
+ */
375
+ function createGetterState() {
376
+ return {
377
+ trackedValues: /* @__PURE__ */ new Map(),
378
+ currentlyAccessing: /* @__PURE__ */ new Set(),
379
+ trackedGetters: /* @__PURE__ */ new Set(),
380
+ isTracking: false,
381
+ renderCache: /* @__PURE__ */ new Map(),
382
+ cacheValid: false,
383
+ depth: 0,
384
+ visitedBlocs: /* @__PURE__ */ new Set()
385
+ };
386
+ }
387
+ /**
388
+ * @internal
389
+ */
390
+ function setActiveTracker(bloc, tracker) {
391
+ activeTrackerMap.set(bloc, tracker);
392
+ }
393
+ /**
394
+ * @internal
395
+ */
396
+ function clearActiveTracker(bloc) {
397
+ activeTrackerMap.delete(bloc);
398
+ }
399
+ /**
400
+ * @internal
401
+ */
402
+ function commitTrackedGetters(tracker) {
403
+ if (tracker.currentlyAccessing.size > 0) tracker.trackedGetters = new Set(tracker.currentlyAccessing);
404
+ tracker.currentlyAccessing.clear();
405
+ }
406
+ /**
407
+ * Execute a tracked getter with depth/circular dependency checks and context management.
408
+ * @internal
409
+ */
410
+ function executeTrackedGetter(target, prop, tracker) {
411
+ tracker.currentlyAccessing.add(prop);
412
+ if (tracker.cacheValid && tracker.renderCache.has(prop)) {
413
+ const cachedValue = tracker.renderCache.get(prop);
414
+ tracker.trackedValues.set(prop, cachedValue);
415
+ return cachedValue;
416
+ }
417
+ if (tracker.depth >= MAX_GETTER_DEPTH) throw new Error(`${require_StateContainerRegistry.BLAC_ERROR_PREFIX} Maximum getter depth (${MAX_GETTER_DEPTH}) exceeded. Possible circular dependency in getter "${String(prop)}" on ${target.constructor.name}.`);
418
+ if (tracker.visitedBlocs.has(target)) throw new Error(`${require_StateContainerRegistry.BLAC_ERROR_PREFIX} Circular dependency detected: getter "${String(prop)}" on ${target.constructor.name}.`);
419
+ const prevDepth = tracker.depth;
420
+ const prevVisited = new Set(tracker.visitedBlocs);
421
+ tracker.depth++;
422
+ tracker.visitedBlocs.add(target);
423
+ try {
424
+ const descriptor = getDescriptor(target, prop);
425
+ if (!descriptor?.get) return target[prop];
426
+ const value = descriptor.get.call(target);
427
+ tracker.trackedValues.set(prop, value);
428
+ return value;
429
+ } catch (error) {
430
+ tracker.currentlyAccessing.delete(prop);
431
+ throw error;
432
+ } finally {
433
+ tracker.depth = prevDepth;
434
+ tracker.visitedBlocs = prevVisited;
435
+ }
436
+ }
437
+ /**
438
+ * @internal
439
+ */
440
+ function createBlocProxy(bloc) {
441
+ const cached = blocProxyCache.get(bloc);
442
+ if (cached) return cached;
443
+ const proxy = new Proxy(bloc, { get(target, prop, receiver) {
444
+ const tracker = activeTrackerMap.get(target);
445
+ if (tracker?.isTracking && isGetter(target, prop)) return executeTrackedGetter(target, prop, tracker);
446
+ return Reflect.get(target, prop, receiver);
447
+ } });
448
+ blocProxyCache.set(bloc, proxy);
449
+ return proxy;
450
+ }
451
+ /**
452
+ * @internal
453
+ */
454
+ function hasGetterChanges(bloc, tracker) {
455
+ if (!tracker || tracker.trackedGetters.size === 0) return false;
456
+ tracker.renderCache.clear();
457
+ let hasAnyChange = false;
458
+ for (const prop of tracker.trackedGetters) try {
459
+ const descriptor = getDescriptor(bloc, prop);
460
+ if (!descriptor?.get) continue;
461
+ const newValue = descriptor.get.call(bloc);
462
+ const oldValue = tracker.trackedValues.get(prop);
463
+ tracker.renderCache.set(prop, newValue);
464
+ tracker.trackedValues.set(prop, newValue);
465
+ if (!Object.is(newValue, oldValue)) hasAnyChange = true;
466
+ } catch (error) {
467
+ console.warn(`${require_StateContainerRegistry.BLAC_ERROR_PREFIX} Getter "${String(prop)}" threw error during change detection. Stopping tracking for this getter.`, error);
468
+ tracker.trackedGetters.delete(prop);
469
+ tracker.trackedValues.delete(prop);
470
+ tracker.cacheValid = false;
471
+ return true;
472
+ }
473
+ tracker.cacheValid = true;
474
+ return hasAnyChange;
475
+ }
476
+ /**
477
+ * @internal
478
+ */
479
+ function invalidateRenderCache(tracker) {
480
+ tracker.cacheValid = false;
481
+ }
482
+ /**
483
+ * Create a new tracking proxy state.
484
+ */
485
+ function createState() {
486
+ return {
487
+ dependencyState: createDependencyState(),
488
+ getterState: createGetterState(),
489
+ dependencies: /* @__PURE__ */ new Set(),
490
+ isTracking: false
491
+ };
492
+ }
493
+ /**
494
+ * Start tracking on a tracking proxy.
495
+ */
496
+ function startTracking(tracker) {
497
+ tracker.isTracking = true;
498
+ tracker.dependencies.clear();
499
+ tracker.getterState.isTracking = true;
500
+ startDependency(tracker.dependencyState);
501
+ }
502
+ /**
503
+ * Stop tracking and collect all dependencies.
504
+ */
505
+ function stopTracking(tracker, bloc) {
506
+ tracker.isTracking = false;
507
+ tracker.getterState.isTracking = false;
508
+ capturePaths(tracker.dependencyState, bloc.state);
509
+ commitTrackedGetters(tracker.getterState);
510
+ return new Set(tracker.dependencies);
511
+ }
512
+ /**
513
+ * Check if tracked state or getters have changed.
514
+ */
515
+ function hasChanges(tracker, bloc) {
516
+ invalidateRenderCache(tracker.getterState);
517
+ const stateChanged = hasDependencyChanges(tracker.dependencyState, bloc.state);
518
+ const getterChanged = hasGetterChanges(bloc, tracker.getterState);
519
+ return stateChanged || getterChanged;
520
+ }
521
+ /**
522
+ * Create a tracking proxy for a bloc instance.
523
+ * Tracks both state property access and getter access.
524
+ */
525
+ function createTrackingProxy(bloc, tracker) {
526
+ tracker.dependencies.add(bloc);
527
+ const stateProxyCache = /* @__PURE__ */ new WeakMap();
528
+ return new Proxy(bloc, { get(target, prop, receiver) {
529
+ if (prop === "state") {
530
+ if (!tracker.isTracking) return target.state;
531
+ const rawState = target.state;
532
+ if (rawState === null || typeof rawState !== "object") return rawState;
533
+ if (stateProxyCache.has(rawState)) return stateProxyCache.get(rawState);
534
+ const stateProxy = createDependencyProxy(tracker.dependencyState, rawState);
535
+ stateProxyCache.set(rawState, stateProxy);
536
+ return stateProxy;
537
+ }
538
+ if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
539
+ const value = Reflect.get(target, prop, receiver);
540
+ if (typeof value === "function") return value.bind(target);
541
+ if (tracker.isTracking && isGetter(target, prop)) return executeTrackedGetter(target, prop, tracker.getterState);
542
+ return value;
543
+ } });
544
+ }
545
+ //#endregion
546
+ //#region src/tracking/dependency-manager.ts
547
+ /**
548
+ * Manages subscriptions to state container dependencies.
549
+ * Provides efficient sync mechanism to add/remove subscriptions
550
+ * as dependencies change between callback invocations.
551
+ */
552
+ var DependencyManager = class {
553
+ constructor() {
554
+ this.subscriptions = /* @__PURE__ */ new Map();
555
+ this.currentDeps = /* @__PURE__ */ new Set();
556
+ }
557
+ /**
558
+ * Sync subscriptions with a new set of dependencies.
559
+ * Adds subscriptions for new deps, removes subscriptions for stale deps.
560
+ *
561
+ * @param newDeps - The new set of dependencies to subscribe to
562
+ * @param onChange - Callback to invoke when any dependency changes
563
+ * @param exclude - Optional instance to exclude from subscriptions (e.g., primary bloc)
564
+ * @returns true if the dependency set changed, false if unchanged
565
+ */
566
+ sync(newDeps, onChange, exclude) {
567
+ const filteredNewDeps = /* @__PURE__ */ new Set();
568
+ for (const dep of newDeps) if (dep !== exclude && !dep.isDisposed) filteredNewDeps.add(dep);
569
+ if (this.areSetsEqual(this.currentDeps, filteredNewDeps)) return false;
570
+ for (const dep of this.currentDeps) if (!filteredNewDeps.has(dep)) {
571
+ const unsub = this.subscriptions.get(dep);
572
+ if (unsub) {
573
+ unsub();
574
+ this.subscriptions.delete(dep);
575
+ }
576
+ }
577
+ for (const dep of filteredNewDeps) if (!this.currentDeps.has(dep) && !this.subscriptions.has(dep)) {
578
+ const unsub = dep.subscribe(onChange);
579
+ this.subscriptions.set(dep, unsub);
580
+ }
581
+ this.currentDeps = filteredNewDeps;
582
+ return true;
583
+ }
584
+ /**
585
+ * Add a single dependency subscription.
586
+ */
587
+ add(dep, onChange) {
588
+ if (this.subscriptions.has(dep) || dep.isDisposed) return;
589
+ const unsub = dep.subscribe(onChange);
590
+ this.subscriptions.set(dep, unsub);
591
+ this.currentDeps.add(dep);
592
+ }
593
+ /**
594
+ * Check if a dependency is currently subscribed.
595
+ */
596
+ has(dep) {
597
+ return this.currentDeps.has(dep);
598
+ }
599
+ /**
600
+ * Get the current set of dependencies.
601
+ */
602
+ getDependencies() {
603
+ return new Set(this.currentDeps);
604
+ }
605
+ /**
606
+ * Clean up all active subscriptions.
607
+ */
608
+ cleanup() {
609
+ for (const unsub of this.subscriptions.values()) unsub();
610
+ this.subscriptions.clear();
611
+ this.currentDeps.clear();
612
+ }
613
+ areSetsEqual(a, b) {
614
+ if (a.size !== b.size) return false;
615
+ for (const item of a) if (!b.has(item)) return false;
616
+ return true;
617
+ }
618
+ };
619
+ //#endregion
620
+ //#region src/tracking/resolve-dependencies.ts
621
+ /**
622
+ * Resolve all transitive dependencies of a bloc via BFS over `dependencies` maps.
623
+ * Uses cycle detection to avoid infinite loops.
624
+ * @internal
625
+ */
626
+ function resolveDependencies(bloc) {
627
+ const result = /* @__PURE__ */ new Set();
628
+ const visited = /* @__PURE__ */ new Set();
629
+ const queue = [bloc];
630
+ while (queue.length > 0) {
631
+ const current = queue.shift();
632
+ if (!current) break;
633
+ for (const [Type, key] of current.dependencies) {
634
+ const visitKey = `${Type.name}::${key}`;
635
+ if (visited.has(visitKey)) continue;
636
+ visited.add(visitKey);
637
+ const dep = require_StateContainerRegistry.globalRegistry.ensure(Type, key);
638
+ result.add(dep);
639
+ if (dep.dependencies.size > 0) queue.push(dep);
640
+ }
641
+ }
642
+ result.delete(bloc);
643
+ return result;
644
+ }
645
+ //#endregion
646
+ Object.defineProperty(exports, "DependencyManager", {
647
+ enumerable: true,
648
+ get: function() {
649
+ return DependencyManager;
650
+ }
651
+ });
652
+ Object.defineProperty(exports, "capturePaths", {
653
+ enumerable: true,
654
+ get: function() {
655
+ return capturePaths;
656
+ }
657
+ });
658
+ Object.defineProperty(exports, "clearActiveTracker", {
659
+ enumerable: true,
660
+ get: function() {
661
+ return clearActiveTracker;
662
+ }
663
+ });
664
+ Object.defineProperty(exports, "commitTrackedGetters", {
665
+ enumerable: true,
666
+ get: function() {
667
+ return commitTrackedGetters;
668
+ }
669
+ });
670
+ Object.defineProperty(exports, "createBlocProxy", {
671
+ enumerable: true,
672
+ get: function() {
673
+ return createBlocProxy;
674
+ }
675
+ });
676
+ Object.defineProperty(exports, "createDependencyProxy", {
677
+ enumerable: true,
678
+ get: function() {
679
+ return createDependencyProxy;
680
+ }
681
+ });
682
+ Object.defineProperty(exports, "createDependencyState", {
683
+ enumerable: true,
684
+ get: function() {
685
+ return createDependencyState;
686
+ }
687
+ });
688
+ Object.defineProperty(exports, "createGetterState", {
689
+ enumerable: true,
690
+ get: function() {
691
+ return createGetterState;
692
+ }
693
+ });
694
+ Object.defineProperty(exports, "createState", {
695
+ enumerable: true,
696
+ get: function() {
697
+ return createState;
698
+ }
699
+ });
700
+ Object.defineProperty(exports, "createTrackingProxy", {
701
+ enumerable: true,
702
+ get: function() {
703
+ return createTrackingProxy;
704
+ }
705
+ });
706
+ Object.defineProperty(exports, "hasChanges", {
707
+ enumerable: true,
708
+ get: function() {
709
+ return hasChanges;
710
+ }
711
+ });
712
+ Object.defineProperty(exports, "hasDependencyChanges", {
713
+ enumerable: true,
714
+ get: function() {
715
+ return hasDependencyChanges;
716
+ }
717
+ });
718
+ Object.defineProperty(exports, "hasGetterChanges", {
719
+ enumerable: true,
720
+ get: function() {
721
+ return hasGetterChanges;
722
+ }
723
+ });
724
+ Object.defineProperty(exports, "hasTrackedData", {
725
+ enumerable: true,
726
+ get: function() {
727
+ return hasTrackedData;
728
+ }
729
+ });
730
+ Object.defineProperty(exports, "invalidateRenderCache", {
731
+ enumerable: true,
732
+ get: function() {
733
+ return invalidateRenderCache;
734
+ }
735
+ });
736
+ Object.defineProperty(exports, "resolveDependencies", {
737
+ enumerable: true,
738
+ get: function() {
739
+ return resolveDependencies;
740
+ }
741
+ });
742
+ Object.defineProperty(exports, "setActiveTracker", {
743
+ enumerable: true,
744
+ get: function() {
745
+ return setActiveTracker;
746
+ }
747
+ });
748
+ Object.defineProperty(exports, "shallowEqual", {
749
+ enumerable: true,
750
+ get: function() {
751
+ return shallowEqual;
752
+ }
753
+ });
754
+ Object.defineProperty(exports, "startDependency", {
755
+ enumerable: true,
756
+ get: function() {
757
+ return startDependency;
758
+ }
759
+ });
760
+ Object.defineProperty(exports, "startTracking", {
761
+ enumerable: true,
762
+ get: function() {
763
+ return startTracking;
764
+ }
765
+ });
766
+ Object.defineProperty(exports, "stopTracking", {
767
+ enumerable: true,
768
+ get: function() {
769
+ return stopTracking;
770
+ }
771
+ });
772
+
773
+ //# sourceMappingURL=resolve-dependencies-B22YjFGk.cjs.map