@solidjs/signals 2.0.0-beta.18 → 2.0.0-beta.20

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 (68) hide show
  1. package/dist/dev.js +3276 -928
  2. package/dist/node.cjs +6646 -4189
  3. package/dist/prod/affects.js +218 -0
  4. package/dist/prod/boundaries.js +568 -0
  5. package/dist/prod/core/action.js +96 -0
  6. package/dist/prod/core/async.js +380 -0
  7. package/dist/prod/core/constants.js +92 -0
  8. package/dist/prod/core/context.js +67 -0
  9. package/dist/prod/core/core.js +772 -0
  10. package/dist/prod/core/dev.js +3 -0
  11. package/dist/prod/core/effect.js +145 -0
  12. package/dist/prod/core/error.js +59 -0
  13. package/dist/prod/core/external.js +98 -0
  14. package/dist/prod/core/graph.js +91 -0
  15. package/dist/prod/core/heap.js +132 -0
  16. package/dist/prod/core/invariants.js +42 -0
  17. package/dist/prod/core/lanes.js +140 -0
  18. package/dist/prod/core/optimistic.js +273 -0
  19. package/dist/prod/core/owner.js +293 -0
  20. package/dist/prod/core/scheduler.js +689 -0
  21. package/dist/prod/core/verdict.js +292 -0
  22. package/dist/prod/index.js +45 -0
  23. package/dist/prod/map.js +293 -0
  24. package/dist/prod/signals.js +389 -0
  25. package/dist/prod/store/optimistic.js +184 -0
  26. package/dist/prod/store/projection.js +184 -0
  27. package/dist/prod/store/reconcile.js +426 -0
  28. package/dist/prod/store/store.js +870 -0
  29. package/dist/prod/store/storePath.js +103 -0
  30. package/dist/prod/store/utils.js +316 -0
  31. package/dist/types/affects.d.ts +1 -1
  32. package/dist/types/boundaries.d.ts +6 -6
  33. package/dist/types/core/action.d.ts +19 -6
  34. package/dist/types/core/async.d.ts +4 -38
  35. package/dist/types/core/constants.d.ts +12 -0
  36. package/dist/types/core/core.d.ts +12 -78
  37. package/dist/types/core/dev.d.ts +7 -0
  38. package/dist/types/core/external.d.ts +0 -30
  39. package/dist/types/core/heap.d.ts +8 -0
  40. package/dist/types/core/index.d.ts +3 -2
  41. package/dist/types/core/lanes.d.ts +2 -0
  42. package/dist/types/core/optimistic.d.ts +6 -0
  43. package/dist/types/core/owner.d.ts +8 -0
  44. package/dist/types/core/scheduler.d.ts +40 -39
  45. package/dist/types/core/types.d.ts +9 -1
  46. package/dist/types/core/verdict.d.ts +2 -0
  47. package/dist/types/store/projection.d.ts +0 -1
  48. package/dist/types/store/store.d.ts +8 -2
  49. package/dist/types-cjs/affects.d.cts +1 -1
  50. package/dist/types-cjs/boundaries.d.cts +6 -6
  51. package/dist/types-cjs/core/action.d.cts +19 -6
  52. package/dist/types-cjs/core/async.d.cts +4 -38
  53. package/dist/types-cjs/core/constants.d.cts +12 -0
  54. package/dist/types-cjs/core/core.d.cts +12 -78
  55. package/dist/types-cjs/core/dev.d.cts +7 -0
  56. package/dist/types-cjs/core/external.d.cts +0 -30
  57. package/dist/types-cjs/core/heap.d.cts +8 -0
  58. package/dist/types-cjs/core/index.d.cts +3 -2
  59. package/dist/types-cjs/core/lanes.d.cts +2 -0
  60. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  61. package/dist/types-cjs/core/owner.d.cts +8 -0
  62. package/dist/types-cjs/core/scheduler.d.cts +40 -39
  63. package/dist/types-cjs/core/types.d.cts +9 -1
  64. package/dist/types-cjs/core/verdict.d.cts +2 -0
  65. package/dist/types-cjs/store/projection.d.cts +0 -1
  66. package/dist/types-cjs/store/store.d.cts +8 -2
  67. package/package.json +8 -6
  68. package/dist/prod.js +0 -4637
package/dist/prod.js DELETED
@@ -1,4637 +0,0 @@
1
- class NotReadyError extends Error {
2
- source;
3
- constructor(e) {
4
- super();
5
- this.source = e;
6
- }
7
- }
8
- class StatusError extends Error {
9
- source;
10
- constructor(e, t) {
11
- super(t instanceof Error ? t.message : String(t), { cause: t });
12
- this.source = e;
13
- }
14
- }
15
- function unwrapStatusError(e) {
16
- return e instanceof StatusError ? e.cause : e;
17
- }
18
- class NoOwnerError extends Error {
19
- constructor() {
20
- super("");
21
- }
22
- }
23
- class ContextNotFoundError extends Error {
24
- constructor() {
25
- super("");
26
- }
27
- }
28
- const REACTIVE_NONE = 0;
29
- const REACTIVE_CHECK = 1 << 0;
30
- const REACTIVE_DIRTY = 1 << 1;
31
- const REACTIVE_RECOMPUTING_DEPS = 1 << 2;
32
- const REACTIVE_IN_HEAP = 1 << 3;
33
- const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
34
- const REACTIVE_ZOMBIE = 1 << 5;
35
- const REACTIVE_DISPOSED = 1 << 6;
36
- const REACTIVE_OPTIMISTIC_DIRTY = 1 << 7;
37
- const REACTIVE_SNAPSHOT_STALE = 1 << 8;
38
- const REACTIVE_LAZY = 1 << 9;
39
- const REACTIVE_MANUAL_WRITE = 1 << 10;
40
- const REACTIVE_REASK = 1 << 11;
41
- const CONFIG_OWNED_WRITE = 1 << 0;
42
- const CONFIG_NO_SNAPSHOT = 1 << 1;
43
- const CONFIG_TRANSPARENT = 1 << 2;
44
- const CONFIG_IN_SNAPSHOT_SCOPE = 1 << 3;
45
- const CONFIG_CHILDREN_FORBIDDEN = 1 << 4;
46
- const CONFIG_AUTO_DISPOSE = 1 << 5;
47
- const CONFIG_SYNC = 1 << 6;
48
- const STATUS_PENDING = 1 << 0;
49
- const STATUS_ERROR = 1 << 1;
50
- const STATUS_UNINITIALIZED = 1 << 2;
51
- const EFFECT_RENDER = 1;
52
- const EFFECT_USER = 2;
53
- const EFFECT_TRACKED = 3;
54
- const NOT_PENDING = {};
55
- const NO_SNAPSHOT = {};
56
- const STORE_SNAPSHOT_PROPS = "sp";
57
- const SUPPORTS_PROXY = typeof Proxy === "function";
58
- const defaultContext = {};
59
- const $REFRESH = Symbol("refresh");
60
- const DEV$1 = undefined;
61
- function devCheckActiveOverrides(e) {
62
- return;
63
- }
64
- function devCheckFlushStart() {
65
- return;
66
- }
67
- typeof globalThis !== "undefined" && !!globalThis.process?.env?.COMPANION_CENSUS;
68
- function devCensusCompanions(e) {
69
- return;
70
- }
71
- function devCheckQuiescent(e) {
72
- return;
73
- }
74
- const signalLanes = new WeakMap();
75
- const activeLanes = new Set();
76
- function getOrCreateLane(e) {
77
- let t = signalLanes.get(e);
78
- if (t) {
79
- return findLane(t);
80
- }
81
- const n = e.t;
82
- const i = n?.i ? findLane(n.i) : null;
83
- t = { o: e, u: new Set(), l: [[], []], S: null, T: activeTransition, _: i };
84
- signalLanes.set(e, t);
85
- activeLanes.add(t);
86
- return t;
87
- }
88
- function findLane(e) {
89
- while (e.S) e = e.S;
90
- return e;
91
- }
92
- function mergeLanes(e, t) {
93
- e = findLane(e);
94
- t = findLane(t);
95
- if (e === t) return e;
96
- t.S = e;
97
- for (const n of t.u) e.u.add(n);
98
- t.u.clear();
99
- e.l[0].push(...t.l[0]);
100
- e.l[1].push(...t.l[1]);
101
- t.l[0].length = 0;
102
- t.l[1].length = 0;
103
- return e;
104
- }
105
- function resolveLane(e) {
106
- const t = e.i;
107
- if (!t) return undefined;
108
- const n = findLane(t);
109
- if (activeLanes.has(n)) return n;
110
- e.i = undefined;
111
- return undefined;
112
- }
113
- function resolveTransition(e) {
114
- return resolveLane(e)?.T ?? e.T;
115
- }
116
- function hasActiveOverride(e) {
117
- return !!(e.p !== undefined && e.p !== NOT_PENDING);
118
- }
119
- function assignOrMergeLane(e, t) {
120
- const n = findLane(t);
121
- const i = e.i;
122
- if (i) {
123
- if (i.S) {
124
- e.i = t;
125
- return;
126
- }
127
- const r = findLane(i);
128
- if (activeLanes.has(r)) {
129
- if (r !== n && !hasActiveOverride(e)) {
130
- if (n._ && findLane(n._) === r) {
131
- e.i = t;
132
- } else if (r._ && findLane(r._) === n);
133
- else mergeLanes(n, r);
134
- }
135
- return;
136
- }
137
- }
138
- e.i = t;
139
- }
140
- const transitions = new Set();
141
- const dirtyQueue = { O: new Array(2e3).fill(undefined), R: false, I: 0, A: 0 };
142
- const zombieQueue = { O: new Array(2e3).fill(undefined), R: false, I: 0, A: 0 };
143
- let clock = 0;
144
- let activeTransition = null;
145
- let scheduled = false;
146
- let halted = false;
147
- let haltNotified = false;
148
- let syncDepth = 0;
149
- let projectionWriteActive = false;
150
- let stashedOptimisticReads = null;
151
- const transientStoreNodes = new Set();
152
- function registerTransientStoreNode(e) {
153
- transientStoreNodes.add(e);
154
- }
155
- function canUseSimpleSyncFlush(e) {
156
- return (
157
- transitions.size === 0 &&
158
- activeLanes.size === 0 &&
159
- e.h.length === 0 &&
160
- e.N.length === 0 &&
161
- e.C.length === 0 &&
162
- e.P.size === 0 &&
163
- transientStoreNodes.size === 0
164
- );
165
- }
166
- function sweepTransientStoreNodes() {
167
- if (transientStoreNodes.size === 0) return;
168
- for (const e of transientStoreNodes) {
169
- if (e.D !== null) {
170
- transientStoreNodes.delete(e);
171
- continue;
172
- }
173
- if (e.m !== NOT_PENDING) continue;
174
- if (e.p !== undefined && e.p !== NOT_PENDING) continue;
175
- if (e.L) continue;
176
- transientStoreNodes.delete(e);
177
- e.V?.();
178
- }
179
- }
180
- function enforceLoadingBoundary(e) {}
181
- function shouldReadStashedOptimisticValue(e) {
182
- return !!stashedOptimisticReads?.has(e);
183
- }
184
- function runLaneEffects(e) {
185
- for (const t of activeLanes) {
186
- if (t.S || t.u.size > 0) continue;
187
- const n = t.l[e - 1];
188
- if (n.length) {
189
- t.l[e - 1] = [];
190
- runQueue(n, e);
191
- }
192
- }
193
- }
194
- function queueStashedOptimisticEffects(e) {
195
- for (let t = e.D; t !== null; t = t.U) {
196
- const e = t.k;
197
- if (!e.G) continue;
198
- if (e.G === EFFECT_TRACKED) {
199
- if (!e.F) {
200
- e.F = true;
201
- e.W.enqueue(EFFECT_USER, e.M);
202
- }
203
- continue;
204
- }
205
- const n = e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
206
- if (n.I > e.$) n.I = e.$;
207
- insertIntoHeap(e, n);
208
- }
209
- }
210
- function setProjectionWriteActive(e) {
211
- projectionWriteActive = e;
212
- }
213
- function mergeTransitionState(e, t) {
214
- t.j = e;
215
- e.K.push(...t.K);
216
- for (const n of activeLanes) if (n.T === t) n.T = e;
217
- e.N.push(...t.N);
218
- if (t.C.length) {
219
- e.C.push(...t.C);
220
- t.C.length = 0;
221
- }
222
- for (const n of t.P) e.P.add(n);
223
- for (const [n, i] of t.Y) {
224
- let t = e.Y.get(n);
225
- if (!t) e.Y.set(n, (t = new Set()));
226
- for (const e of i) t.add(e);
227
- }
228
- for (const n of t.Z) e.Z.add(n);
229
- }
230
- function resolveOptimisticNodes(e) {
231
- const t = e.length;
232
- for (let n = 0; n < t; n++) {
233
- const t = e[n];
234
- t.i = undefined;
235
- if (!(t.q & STATUS_PENDING)) t.q &= ~STATUS_UNINITIALIZED;
236
- const i = t.p;
237
- t.p = NOT_PENDING;
238
- if (i !== NOT_PENDING && t.B !== i) insertSubs(t, true);
239
- t.T = null;
240
- }
241
- for (let n = 0; n < t; n++) {
242
- const t = e[n];
243
- if (t.X || t.J) snapCompanionsToState(t);
244
- const i = t.t;
245
- if (i && (i.X === t || i.J === t)) snapCompanionsToState(i);
246
- }
247
- e.splice(0, t);
248
- }
249
- function cleanupCompletedLanes(e) {
250
- for (const t of activeLanes) {
251
- const n = e ? t.T === e : !t.T;
252
- if (!n) continue;
253
- if (!t.S) {
254
- if (t.l[0].length) runQueue(t.l[0], EFFECT_RENDER);
255
- if (t.l[1].length) runQueue(t.l[1], EFFECT_USER);
256
- }
257
- if (t.o.i === t) t.o.i = undefined;
258
- t.u.clear();
259
- t.l[0].length = 0;
260
- t.l[1].length = 0;
261
- activeLanes.delete(t);
262
- signalLanes.delete(t.o);
263
- }
264
- }
265
- function schedule() {
266
- if (halted) {
267
- notifyHalted();
268
- return;
269
- }
270
- if (scheduled) return;
271
- scheduled = true;
272
- if (!syncDepth && !globalQueue.ee && !projectionWriteActive) queueMicrotask(flush);
273
- }
274
- function haltReactivity() {
275
- if (halted) return;
276
- halted = true;
277
- let e = "[REACTIVITY_HALTED] An uncaught error halted the reactive system.";
278
- console.error(e);
279
- }
280
- function notifyHalted() {
281
- if (haltNotified) return;
282
- haltNotified = true;
283
- console.error("[REACTIVITY_HALTED] Update ignored.");
284
- }
285
- function resetErrorHalt() {
286
- halted = false;
287
- haltNotified = false;
288
- }
289
- class Queue {
290
- te = null;
291
- ne = [[], []];
292
- h = [];
293
- created = clock;
294
- addChild(e) {
295
- this.h.push(e);
296
- e.te = this;
297
- }
298
- removeChild(e) {
299
- const t = this.h.indexOf(e);
300
- if (t >= 0) {
301
- this.h.splice(t, 1);
302
- e.te = null;
303
- }
304
- }
305
- notify(e, t, n, i) {
306
- if (this.te) return this.te.notify(e, t, n, i);
307
- return false;
308
- }
309
- run(e) {
310
- if (this.ne[e - 1].length) {
311
- const t = this.ne[e - 1];
312
- this.ne[e - 1] = [];
313
- runQueue(t, e);
314
- }
315
- for (let t = 0; t < this.h.length; t++) this.h[t].run?.(e);
316
- }
317
- enqueue(e, t) {
318
- if (e) {
319
- if (currentOptimisticLane) {
320
- const n = findLane(currentOptimisticLane);
321
- n.l[e - 1].push(t);
322
- } else {
323
- this.ne[e - 1].push(t);
324
- }
325
- }
326
- schedule();
327
- }
328
- stashQueues(e) {
329
- e.ne[0].push(...this.ne[0]);
330
- e.ne[1].push(...this.ne[1]);
331
- this.ne = [[], []];
332
- for (let t = 0; t < this.h.length; t++) {
333
- let n = this.h[t];
334
- let i = e.h[t];
335
- if (!i) {
336
- i = { ne: [[], []], h: [] };
337
- e.h[t] = i;
338
- }
339
- n.stashQueues(i);
340
- }
341
- }
342
- restoreQueues(e) {
343
- this.ne[0].push(...e.ne[0]);
344
- this.ne[1].push(...e.ne[1]);
345
- for (let t = 0; t < e.h.length; t++) {
346
- const n = e.h[t];
347
- let i = this.h[t];
348
- if (i) i.restoreQueues(n);
349
- }
350
- }
351
- }
352
- class GlobalQueue extends Queue {
353
- ee = false;
354
- ie = null;
355
- re = [];
356
- N = [];
357
- C = [];
358
- P = new Set();
359
- static se;
360
- static oe;
361
- static ue;
362
- static ce = null;
363
- static ae = null;
364
- static le = null;
365
- static fe = null;
366
- flush() {
367
- if (this.ee) return;
368
- this.ee = true;
369
- try {
370
- if (false);
371
- runHeap(dirtyQueue, GlobalQueue.se);
372
- if (activeTransition) {
373
- const e = transitionComplete(activeTransition);
374
- if (!e) {
375
- const e = activeTransition;
376
- runHeap(zombieQueue, GlobalQueue.se);
377
- this.ie = null;
378
- this.re = [];
379
- this.N = [];
380
- this.C = [];
381
- this.P = new Set();
382
- runLaneEffects(EFFECT_RENDER);
383
- runLaneEffects(EFFECT_USER);
384
- this.stashQueues(e.Ee);
385
- clock++;
386
- scheduled = dirtyQueue.A >= dirtyQueue.I;
387
- reassignPendingTransition(e.re);
388
- activeTransition = null;
389
- if (!e.K.length && !e.Y.size && e.N.length) {
390
- stashedOptimisticReads = new Set();
391
- for (let t = 0; t < e.N.length; t++) {
392
- const n = e.N[t];
393
- if (n.de || n.Se & CONFIG_OWNED_WRITE) continue;
394
- stashedOptimisticReads.add(n);
395
- queueStashedOptimisticEffects(n);
396
- }
397
- }
398
- try {
399
- finalizePureQueue(null, true);
400
- } finally {
401
- stashedOptimisticReads = null;
402
- }
403
- return;
404
- }
405
- this.re !== activeTransition.re && this.re.push(...activeTransition.re);
406
- this.restoreQueues(activeTransition.Ee);
407
- transitions.delete(activeTransition);
408
- const t = activeTransition;
409
- activeTransition = null;
410
- reassignPendingTransition(this.re);
411
- finalizePureQueue(t);
412
- } else {
413
- if (canUseSimpleSyncFlush(this)) {
414
- commitPendingNodes();
415
- if (dirtyQueue.A >= dirtyQueue.I) {
416
- runHeap(dirtyQueue, GlobalQueue.se);
417
- commitPendingNodes();
418
- }
419
- } else {
420
- if (transitions.size) runHeap(zombieQueue, GlobalQueue.se);
421
- finalizePureQueue();
422
- }
423
- }
424
- clock++;
425
- scheduled = dirtyQueue.A >= dirtyQueue.I;
426
- activeLanes.size && runLaneEffects(EFFECT_RENDER);
427
- this.run(EFFECT_RENDER);
428
- activeLanes.size && runLaneEffects(EFFECT_USER);
429
- this.run(EFFECT_USER);
430
- if (false);
431
- if (
432
- false &&
433
- !scheduled &&
434
- !activeTransition &&
435
- transitions.size === 0 &&
436
- activeLanes.size === 0
437
- );
438
- if (false);
439
- } finally {
440
- this.ee = false;
441
- }
442
- }
443
- notify(e, t, n, i) {
444
- if (t & STATUS_PENDING) {
445
- if (n & STATUS_PENDING) {
446
- const t = i !== undefined ? i : e.Te;
447
- if (activeTransition && t) {
448
- const n = t.source;
449
- let i = activeTransition.Y.get(n);
450
- if (!i) activeTransition.Y.set(n, (i = new Set()));
451
- const r = i.size;
452
- i.add(e);
453
- if (i.size !== r) schedule();
454
- }
455
- }
456
- return true;
457
- }
458
- return false;
459
- }
460
- initTransition(e) {
461
- if (e) e = currentTransition(e);
462
- if (e && e === activeTransition) return;
463
- if (!e && activeTransition && activeTransition._e === clock) return;
464
- if (!activeTransition) {
465
- activeTransition = e ?? {
466
- _e: clock,
467
- re: [],
468
- Y: new Map(),
469
- N: [],
470
- C: [],
471
- P: new Set(),
472
- K: [],
473
- Ee: { ne: [[], []], h: [] },
474
- j: false,
475
- Z: new Set()
476
- };
477
- } else if (e) {
478
- const t = activeTransition;
479
- mergeTransitionState(e, t);
480
- transitions.delete(t);
481
- activeTransition = e;
482
- }
483
- transitions.add(activeTransition);
484
- activeTransition._e = clock;
485
- if (this.ie !== null) {
486
- this.ie.T = activeTransition;
487
- activeTransition.re.push(this.ie);
488
- this.ie = null;
489
- }
490
- if (this.re !== activeTransition.re) {
491
- for (let e = 0; e < this.re.length; e++) {
492
- const t = this.re[e];
493
- t.T = activeTransition;
494
- activeTransition.re.push(t);
495
- }
496
- this.re = activeTransition.re;
497
- }
498
- if (this.N !== activeTransition.N) {
499
- for (let e = 0; e < this.N.length; e++) {
500
- const t = this.N[e];
501
- t.T = activeTransition;
502
- activeTransition.N.push(t);
503
- }
504
- this.N = activeTransition.N;
505
- }
506
- if (this.C !== activeTransition.C) {
507
- activeTransition.C.push(...this.C);
508
- this.C = activeTransition.C;
509
- }
510
- for (const e of activeLanes) {
511
- if (!e.T) e.T = activeTransition;
512
- }
513
- if (this.P !== activeTransition.P) {
514
- for (const e of this.P) activeTransition.P.add(e);
515
- this.P = activeTransition.P;
516
- }
517
- }
518
- }
519
- function queuePendingNode(e) {
520
- if (activeTransition) {
521
- globalQueue.re.push(e);
522
- return;
523
- }
524
- if (globalQueue.ie === null && globalQueue.re.length === 0) {
525
- globalQueue.ie = e;
526
- return;
527
- }
528
- if (globalQueue.ie !== null) {
529
- globalQueue.re.push(globalQueue.ie);
530
- globalQueue.ie = null;
531
- }
532
- globalQueue.re.push(e);
533
- }
534
- let reaskArmed = false;
535
- function armReaskClear() {
536
- reaskArmed = true;
537
- }
538
- function insertSubs(e, t = false) {
539
- const n = e.i || currentOptimisticLane;
540
- const i = e.pe !== undefined;
541
- const r = reaskArmed;
542
- for (let s = e.D; s !== null; s = s.U) {
543
- if (r) s.k.H &= ~REACTIVE_REASK;
544
- if (i && s.k.Se & CONFIG_IN_SNAPSHOT_SCOPE) {
545
- s.k.H |= REACTIVE_SNAPSHOT_STALE;
546
- continue;
547
- }
548
- if (t && n) {
549
- s.k.H |= REACTIVE_OPTIMISTIC_DIRTY;
550
- assignOrMergeLane(s.k, n);
551
- } else if (t) {
552
- s.k.H |= REACTIVE_OPTIMISTIC_DIRTY;
553
- s.k.i = undefined;
554
- }
555
- const e = s.k;
556
- if (e.G === EFFECT_TRACKED) {
557
- if (!e.F) {
558
- e.F = true;
559
- e.W.enqueue(EFFECT_USER, e.M);
560
- }
561
- continue;
562
- }
563
- const o = s.k.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
564
- if (o.I > s.k.$) o.I = s.k.$;
565
- insertIntoHeap(s.k, o);
566
- }
567
- }
568
- function commitPendingNode(e) {
569
- const t = e;
570
- if (!t.de) {
571
- if (e.m !== NOT_PENDING) {
572
- e.B = e.m;
573
- e.m = NOT_PENDING;
574
- }
575
- if (e.X || e.J) snapCompanionsToState(e);
576
- return;
577
- }
578
- if (e.m !== NOT_PENDING) {
579
- e.B = e.m;
580
- e.m = NOT_PENDING;
581
- if (e.G && e.G !== EFFECT_TRACKED) e.F = true;
582
- }
583
- t.H &= ~REACTIVE_MANUAL_WRITE;
584
- if (!(t.q & STATUS_PENDING)) t.q &= ~STATUS_UNINITIALIZED;
585
- if (t.Oe !== null || t.Re !== null) GlobalQueue.oe(t, false, true);
586
- if (e.X || e.J) snapCompanionsToState(e);
587
- }
588
- function commitPendingNodes() {
589
- if (globalQueue.ie !== null) {
590
- commitPendingNode(globalQueue.ie);
591
- globalQueue.ie = null;
592
- }
593
- const e = globalQueue.re;
594
- for (let t = 0; t < e.length; t++) {
595
- commitPendingNode(e[t]);
596
- }
597
- e.length = 0;
598
- }
599
- function finalizePureQueue(e = null, t = false) {
600
- const n = !t;
601
- if (n) commitPendingNodes();
602
- if (!t && globalQueue.h.length) checkBoundaryChildren(globalQueue);
603
- const i = dirtyQueue.A >= dirtyQueue.I;
604
- if (i) runHeap(dirtyQueue, GlobalQueue.se);
605
- if (n) {
606
- if (i) commitPendingNodes();
607
- resolveOptimisticNodes(e ? e.N : globalQueue.N);
608
- if (e && e.Z.size) {
609
- for (const t of e.Z) {
610
- if (t.H & REACTIVE_DISPOSED) continue;
611
- if (t.G === EFFECT_TRACKED) {
612
- if (!t.F) {
613
- t.F = true;
614
- t.W.enqueue(EFFECT_USER, t.M);
615
- }
616
- continue;
617
- }
618
- const e = t.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
619
- if (e.I > t.$) e.I = t.$;
620
- insertIntoHeap(t, e);
621
- }
622
- e.Z.clear();
623
- }
624
- releaseAffectsMarks(e ? e.C : globalQueue.C);
625
- const t = e ? e.P : globalQueue.P;
626
- if (GlobalQueue.ce && t.size) {
627
- for (const e of t) {
628
- GlobalQueue.ce(e);
629
- }
630
- t.clear();
631
- schedule();
632
- }
633
- sweepTransientStoreNodes();
634
- cleanupCompletedLanes(e);
635
- }
636
- }
637
- function checkBoundaryChildren(e) {
638
- for (const t of e.h) {
639
- t.checkSources?.();
640
- checkBoundaryChildren(t);
641
- }
642
- }
643
- function trackOptimisticStore(e) {
644
- globalQueue.P.add(e);
645
- schedule();
646
- }
647
- let activeAffectsMarks = 0;
648
- function markAffects(e) {
649
- e.L = (e.L || 0) + 1;
650
- activeAffectsMarks++;
651
- if (e.L === 1) updatePendingSignal(e);
652
- }
653
- function registerAffectsMark(e) {
654
- markAffects(e);
655
- globalQueue.C.push(e);
656
- GlobalQueue.le?.(e);
657
- schedule();
658
- }
659
- function releaseAffectsMark(e) {
660
- activeAffectsMarks--;
661
- e.L--;
662
- if (!e.L) {
663
- GlobalQueue.fe?.(e);
664
- snapCompanionsToState(e);
665
- GlobalQueue.ae?.(e);
666
- }
667
- }
668
- function releaseAffectsMarks(e) {
669
- if (!e.length) return;
670
- for (let t = 0; t < e.length; t++) releaseAffectsMark(e[t]);
671
- e.length = 0;
672
- }
673
- function reassignPendingTransition(e) {
674
- for (let t = 0; t < e.length; t++) {
675
- e[t].T = activeTransition;
676
- }
677
- }
678
- const globalQueue = new GlobalQueue();
679
- function flush(e) {
680
- if (e) {
681
- syncDepth++;
682
- try {
683
- return e();
684
- } finally {
685
- try {
686
- flush();
687
- } finally {
688
- syncDepth--;
689
- }
690
- }
691
- }
692
- if (globalQueue.ee) {
693
- return;
694
- }
695
- if (halted) return;
696
- while (scheduled || activeTransition) {
697
- globalQueue.flush();
698
- }
699
- }
700
- function runQueue(e, t) {
701
- for (let n = 0; n < e.length; n++) e[n](t);
702
- }
703
- function reporterBlocksSource(e, t) {
704
- if (e.H & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED)) return false;
705
- if (e.Ie === t || e.Ae?.has(t)) return true;
706
- for (let n = e.he; n; n = n.Ne) {
707
- let e = n.Ce;
708
- while (e) {
709
- if (e === t || e.ye === t) return true;
710
- e = e.t;
711
- }
712
- }
713
- return !!(e.q & STATUS_PENDING && e.Te instanceof NotReadyError && e.Te.source === t);
714
- }
715
- function transitionComplete(e) {
716
- if (e.j) return true;
717
- if (e.K.length) return false;
718
- let t = true;
719
- for (const [n, i] of e.Y) {
720
- let r = false;
721
- for (const e of i) {
722
- if (reporterBlocksSource(e, n)) {
723
- r = true;
724
- break;
725
- }
726
- i.delete(e);
727
- }
728
- if (!r) e.Y.delete(n);
729
- else if (n.q & STATUS_PENDING && n.Te?.source === n) {
730
- t = false;
731
- break;
732
- }
733
- }
734
- if (t) {
735
- for (let n = 0; n < e.N.length; n++) {
736
- const i = e.N[n];
737
- if (
738
- hasActiveOverride(i) &&
739
- "q" in i &&
740
- i.q & STATUS_PENDING &&
741
- i.Te instanceof NotReadyError &&
742
- !i.Te.source?.ge
743
- ) {
744
- t = false;
745
- break;
746
- }
747
- }
748
- }
749
- t && (e.j = true);
750
- return t;
751
- }
752
- function currentTransition(e) {
753
- while (e.j && typeof e.j === "object") e = e.j;
754
- return e;
755
- }
756
- function setActiveTransition(e) {
757
- activeTransition = e;
758
- }
759
- function runInTransition(e, t) {
760
- const n = activeTransition;
761
- try {
762
- activeTransition = currentTransition(e);
763
- return t();
764
- } finally {
765
- activeTransition = n;
766
- }
767
- }
768
- function actualInsertIntoHeap(e, t) {
769
- const n = (e.te?.Pe ? e.te.De?.$ : e.te?.$) ?? -1;
770
- if (n >= e.$) e.$ = n + 1;
771
- const i = e.$;
772
- const r = t.O[i];
773
- if (r === undefined) t.O[i] = e;
774
- else {
775
- const t = r.be;
776
- t.me = e;
777
- e.be = t;
778
- r.be = e;
779
- }
780
- if (i > t.A) t.A = i;
781
- }
782
- function insertIntoHeap(e, t) {
783
- let n = e.H;
784
- if (n & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_MANUAL_WRITE)) return;
785
- if (n & REACTIVE_CHECK) {
786
- e.H = (n & -4) | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
787
- } else e.H = n | REACTIVE_IN_HEAP;
788
- if (!(n & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
789
- }
790
- function insertIntoHeapHeight(e, t) {
791
- let n = e.H;
792
- if (
793
- n &
794
- (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT | REACTIVE_MANUAL_WRITE)
795
- )
796
- return;
797
- e.H = n | REACTIVE_IN_HEAP_HEIGHT;
798
- actualInsertIntoHeap(e, t);
799
- }
800
- function deleteFromHeap(e, t) {
801
- const n = e.H;
802
- if (!(n & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
803
- e.H = n & -25;
804
- const i = e.$;
805
- if (e.be === e) t.O[i] = undefined;
806
- else {
807
- const n = e.me;
808
- const r = t.O[i];
809
- const s = n ?? r;
810
- if (e === r) t.O[i] = n;
811
- else e.be.me = n;
812
- s.be = e.be;
813
- }
814
- e.be = e;
815
- e.me = undefined;
816
- }
817
- function markHeap(e) {
818
- if (e.R) return;
819
- e.R = true;
820
- for (let t = 0; t <= e.A; t++) {
821
- for (let n = e.O[t]; n !== undefined; n = n.me) {
822
- if (n.H & REACTIVE_IN_HEAP) markNode(n);
823
- }
824
- }
825
- }
826
- function markNode(e, t = REACTIVE_DIRTY) {
827
- const n = e.H;
828
- if ((n & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
829
- e.H = (n & -4) | t;
830
- for (let t = e.D; t !== null; t = t.U) {
831
- markNode(t.k, REACTIVE_CHECK);
832
- }
833
- if (e.ve !== null) {
834
- for (let t = e.ve; t !== null; t = t.we) {
835
- for (let e = t.D; e !== null; e = e.U) {
836
- markNode(e.k, REACTIVE_CHECK);
837
- }
838
- }
839
- }
840
- }
841
- function runHeap(e, t) {
842
- e.R = false;
843
- for (e.I = 0; e.I <= e.A; e.I++) {
844
- let n = e.O[e.I];
845
- while (n !== undefined) {
846
- if (n.H & REACTIVE_IN_HEAP) t(n);
847
- else adjustHeight(n, e);
848
- n = e.O[e.I];
849
- }
850
- }
851
- e.A = 0;
852
- }
853
- function adjustHeight(e, t) {
854
- deleteFromHeap(e, t);
855
- let n = e.$;
856
- for (let t = e.he; t; t = t.Ne) {
857
- const e = t.Ce;
858
- const i = e.ye || e;
859
- if (i.de && i.$ >= n) n = i.$ + 1;
860
- }
861
- if (e.$ !== n) {
862
- e.$ = n;
863
- for (let t = e.D; t !== null; t = t.U) {
864
- insertIntoHeapHeight(t.k, t.k.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
865
- }
866
- }
867
- }
868
- const PENDING_OWNER = {};
869
- function markDisposal(e) {
870
- let t = e.Le;
871
- while (t) {
872
- const e = t.H;
873
- t.H = e | REACTIVE_ZOMBIE;
874
- if (e & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT)) {
875
- deleteFromHeap(t, e & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
876
- if (e & REACTIVE_IN_HEAP) insertIntoHeap(t, zombieQueue);
877
- else insertIntoHeapHeight(t, zombieQueue);
878
- }
879
- markDisposal(t);
880
- t = t.Ve;
881
- }
882
- }
883
- function dispose(e) {
884
- let t = e.he;
885
- while (t !== null) {
886
- t = unlinkSubs(t);
887
- }
888
- e.he = null;
889
- e.Ue = null;
890
- disposeChildren(e, true);
891
- }
892
- function disposeChildren(e, t = false, n) {
893
- const i = e.H;
894
- if (i & REACTIVE_DISPOSED) return;
895
- if (t) {
896
- e.H = i | REACTIVE_DISPOSED;
897
- const t = e;
898
- if (t.X || t.J) snapCompanionsToState(t);
899
- }
900
- if (t && e.de) e.ke = null;
901
- let r = n ? e.Oe : e.Le;
902
- while (r) {
903
- const e = r.Ve;
904
- if (r.he) {
905
- const e = r;
906
- deleteFromHeap(e, e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
907
- let t = e.he;
908
- do {
909
- t = unlinkSubs(t);
910
- } while (t !== null);
911
- e.he = null;
912
- e.Ue = null;
913
- }
914
- disposeChildren(r, true);
915
- r = e;
916
- }
917
- if (n) {
918
- e.Oe = null;
919
- } else {
920
- e.Le = null;
921
- e.Ge = 0;
922
- }
923
- if (t && !n && !(i & REACTIVE_ZOMBIE) && e.te !== null && !(e.te.H & REACTIVE_DISPOSED)) {
924
- const t = e.Fe;
925
- const n = e.Ve;
926
- if (t !== null) t.Ve = n;
927
- else e.te.Le = n;
928
- if (n !== null) n.Fe = t;
929
- e.Fe = null;
930
- }
931
- runDisposal(e, n);
932
- if (t && e.We) {
933
- const t = e.We;
934
- e.We = undefined;
935
- t();
936
- }
937
- }
938
- function runDisposal(e, t) {
939
- let n = t ? e.Re : e.Me;
940
- if (!n) return;
941
- if (Array.isArray(n)) {
942
- for (let e = 0; e < n.length; e++) {
943
- const t = n[e];
944
- t.call(t);
945
- }
946
- } else {
947
- n.call(n);
948
- }
949
- t ? (e.Re = null) : (e.Me = null);
950
- }
951
- function childId(e, t) {
952
- let n = e;
953
- while (n.Se & CONFIG_TRANSPARENT && n.te) n = n.te;
954
- if (n.id != null) return formatId(n.id, t ? n.Ge++ : n.Ge);
955
- throw new Error("Cannot get child id from owner without an id");
956
- }
957
- function getNextChildId(e) {
958
- return childId(e, true);
959
- }
960
- function peekNextChildId(e) {
961
- return childId(e, false);
962
- }
963
- function formatId(e, t) {
964
- const n = t.toString(36),
965
- i = n.length - 1;
966
- return e + (i ? String.fromCharCode(64 + i) : "") + n;
967
- }
968
- function getObserver() {
969
- if (pendingCheckActive || latestReadActive) return PENDING_OWNER;
970
- return tracking ? context : null;
971
- }
972
- function getOwner() {
973
- return context;
974
- }
975
- function cleanup(e) {
976
- if (!context) return e;
977
- if (!context.Me) context.Me = e;
978
- else if (Array.isArray(context.Me)) context.Me.push(e);
979
- else context.Me = [context.Me, e];
980
- return e;
981
- }
982
- function isDisposed(e) {
983
- return !!(e.H & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE));
984
- }
985
- function disposeRootSelf(e = true) {
986
- disposeChildren(this, e);
987
- }
988
- function createOwner(e) {
989
- const t = context;
990
- const n = e?.transparent ?? false;
991
- const i = {
992
- id: e?.id ?? (n ? t?.id : t?.id != null ? getNextChildId(t) : undefined),
993
- Se: n ? CONFIG_TRANSPARENT : 0,
994
- Pe: true,
995
- De: t?.Pe ? t.De : t,
996
- Le: null,
997
- Ve: null,
998
- Fe: null,
999
- Me: null,
1000
- W: t?.W ?? globalQueue,
1001
- He: t?.He || defaultContext,
1002
- Ge: 0,
1003
- Re: null,
1004
- Oe: null,
1005
- te: t,
1006
- dispose: disposeRootSelf
1007
- };
1008
- if (t) {
1009
- const e = t.Le;
1010
- if (e === null) {
1011
- t.Le = i;
1012
- } else {
1013
- i.Ve = e;
1014
- e.Fe = i;
1015
- t.Le = i;
1016
- }
1017
- }
1018
- return i;
1019
- }
1020
- function createRoot(e, t) {
1021
- const n = createOwner(t);
1022
- return runWithOwner(n, () => e(() => n.dispose()));
1023
- }
1024
- function unlinkSubs(e) {
1025
- const t = e.Ce;
1026
- const n = e.Ne;
1027
- const i = e.U;
1028
- const r = e.Qe;
1029
- if (i !== null) i.Qe = r;
1030
- else t.xe = r;
1031
- if (r !== null) r.U = i;
1032
- else {
1033
- t.D = i;
1034
- if (i === null) {
1035
- t.V?.();
1036
- const e = t;
1037
- e.de && e.Se & CONFIG_AUTO_DISPOSE && !(e.H & REACTIVE_ZOMBIE) && unobserved(e);
1038
- }
1039
- }
1040
- return n;
1041
- }
1042
- function trimStaleDeps(e) {
1043
- const t = e.Ue;
1044
- let n = t !== null ? t.Ne : e.he;
1045
- if (n !== null) {
1046
- do {
1047
- n = unlinkSubs(n);
1048
- } while (n !== null);
1049
- if (t !== null) t.Ne = null;
1050
- else e.he = null;
1051
- }
1052
- }
1053
- function unobserved(e) {
1054
- deleteFromHeap(e, e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
1055
- let t = e.he;
1056
- while (t !== null) {
1057
- t = unlinkSubs(t);
1058
- }
1059
- e.he = null;
1060
- e.Ue = null;
1061
- disposeChildren(e, true);
1062
- }
1063
- function link(e, t, n = false) {
1064
- const i = t.Ue;
1065
- if (i !== null && i.Ce === e) {
1066
- i.$e = n;
1067
- return;
1068
- }
1069
- let r = null;
1070
- const s = t.H & REACTIVE_RECOMPUTING_DEPS;
1071
- if (s) {
1072
- r = i !== null ? i.Ne : t.he;
1073
- if (r !== null && r.Ce === e) {
1074
- r.je = t.Ke;
1075
- t.Ue = r;
1076
- r.$e = n;
1077
- return;
1078
- }
1079
- }
1080
- const o = e.xe;
1081
- if (o !== null && o.k === t && (!s || o.je === t.Ke)) {
1082
- o.$e = n;
1083
- return;
1084
- }
1085
- const u = (t.Ue = e.xe = { Ce: e, k: t, Ne: r, Qe: o, U: null, je: t.Ke, $e: n });
1086
- if (i !== null) i.Ne = u;
1087
- else t.he = u;
1088
- if (o !== null) o.U = u;
1089
- else e.D = u;
1090
- }
1091
- function addPendingSource(e, t) {
1092
- if (e.Ie === t || e.Ae?.has(t)) return false;
1093
- if (!e.Ie) {
1094
- e.Ie = t;
1095
- return true;
1096
- }
1097
- if (!e.Ae) {
1098
- e.Ae = new Set([e.Ie, t]);
1099
- } else {
1100
- e.Ae.add(t);
1101
- }
1102
- e.Ie = undefined;
1103
- return true;
1104
- }
1105
- function removePendingSource(e, t) {
1106
- if (e.Ie) {
1107
- if (e.Ie !== t) return false;
1108
- e.Ie = undefined;
1109
- return true;
1110
- }
1111
- if (!e.Ae?.delete(t)) return false;
1112
- if (e.Ae.size === 1) {
1113
- e.Ie = e.Ae.values().next().value;
1114
- e.Ae = undefined;
1115
- } else if (e.Ae.size === 0) {
1116
- e.Ae = undefined;
1117
- }
1118
- return true;
1119
- }
1120
- function clearPendingSources(e) {
1121
- e.Ie = undefined;
1122
- e.Ae?.clear();
1123
- e.Ae = undefined;
1124
- }
1125
- function setPendingError(e, t, n) {
1126
- if (!t) {
1127
- e.Te = null;
1128
- return;
1129
- }
1130
- if (n instanceof NotReadyError && n.source === t) {
1131
- e.Te = n;
1132
- return;
1133
- }
1134
- const i = e.Te;
1135
- if (!(i instanceof NotReadyError) || i.source !== t) {
1136
- e.Te = new NotReadyError(t);
1137
- }
1138
- }
1139
- function forEachDependent(e, t) {
1140
- for (let n = e.D; n !== null; n = n.U) t(n.k, n);
1141
- for (let n = e.ve ?? null; n !== null; n = n.we) {
1142
- for (let e = n.D; e !== null; e = e.U) t(e.k, e);
1143
- }
1144
- }
1145
- function enqueueForRerun(e) {
1146
- if (e.G === EFFECT_TRACKED) {
1147
- const t = e;
1148
- if (!t.F) {
1149
- t.F = true;
1150
- t.W.enqueue(EFFECT_USER, t.M);
1151
- }
1152
- } else {
1153
- const t = e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
1154
- if (t.I > e.$) t.I = e.$;
1155
- insertIntoHeap(e, t);
1156
- }
1157
- }
1158
- function settlePendingSource(e, t = e, n = false) {
1159
- let i = false;
1160
- const r = new Set();
1161
- const s = n ? snapCompanionsToState : updatePendingSignal;
1162
- const settle = e => {
1163
- if (r.has(e) || !removePendingSource(e, t)) return;
1164
- r.add(e);
1165
- e._e = clock;
1166
- const n = e.Ie ?? e.Ae?.values().next().value;
1167
- if (n) {
1168
- setPendingError(e, n);
1169
- s(e);
1170
- } else {
1171
- e.q &= ~STATUS_PENDING;
1172
- setPendingError(e);
1173
- s(e);
1174
- if (e.Ye) {
1175
- enqueueForRerun(e);
1176
- i = true;
1177
- }
1178
- e.Ye = false;
1179
- }
1180
- forEachDependent(e, settle);
1181
- };
1182
- forEachDependent(e, settle);
1183
- if (i) schedule();
1184
- }
1185
- function isThenable(e) {
1186
- return e != null && typeof e === "object" && typeof e.then === "function";
1187
- }
1188
- function handleAsync(e, t, n) {
1189
- let i = false;
1190
- let r = false;
1191
- if (typeof t === "object" && t !== null) {
1192
- untrack(() => {
1193
- i = t[Symbol.asyncIterator];
1194
- r = !i && isThenable(t);
1195
- });
1196
- }
1197
- if (!r && !i) {
1198
- e.ke = null;
1199
- return t;
1200
- }
1201
- e.ke = t;
1202
- let s;
1203
- const handleError = n => {
1204
- if (e.ke !== t) return;
1205
- globalQueue.initTransition(resolveTransition(e));
1206
- notifyStatus(e, n instanceof NotReadyError ? STATUS_PENDING : STATUS_ERROR, n);
1207
- e._e = clock;
1208
- };
1209
- const asyncWrite = (i, r) => {
1210
- if (e.ke !== t) return;
1211
- if (e.H & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY)) return;
1212
- globalQueue.initTransition(resolveTransition(e));
1213
- const s = !!(e.q & STATUS_UNINITIALIZED);
1214
- trimStaleDeps(e);
1215
- clearStatus(e);
1216
- const o = resolveLane(e);
1217
- if (o) o.u.delete(e);
1218
- if (n) {
1219
- n(i);
1220
- if (s) clearStatus(e, true);
1221
- } else if (e.p !== undefined) {
1222
- if (e.m === NOT_PENDING) queuePendingNode(e);
1223
- e.m = i;
1224
- syncCompanions(e, i);
1225
- if (!hasActiveOverride(e)) insertSubs(e);
1226
- e._e = clock;
1227
- } else if (o) {
1228
- const t = e.G;
1229
- const n = e.B;
1230
- const r = e.Ze;
1231
- try {
1232
- if ((!t && s) || !r || !r(i, n)) {
1233
- e.B = i;
1234
- e._e = clock;
1235
- syncCompanions(e, i);
1236
- insertSubs(e, true);
1237
- }
1238
- } catch (t) {
1239
- notifyStatus(e, STATUS_ERROR, t);
1240
- }
1241
- } else {
1242
- try {
1243
- setSignal(e, () => i);
1244
- } catch (t) {
1245
- notifyStatus(e, STATUS_ERROR, t);
1246
- }
1247
- }
1248
- settlePendingSource(e);
1249
- schedule();
1250
- flush();
1251
- r?.();
1252
- };
1253
- if (r) {
1254
- let n = false,
1255
- i = false,
1256
- r,
1257
- o = true;
1258
- t.then(
1259
- e => {
1260
- if (o) {
1261
- s = e;
1262
- n = true;
1263
- } else asyncWrite(e);
1264
- },
1265
- e => {
1266
- if (o) {
1267
- r = e;
1268
- i = true;
1269
- } else handleError(e);
1270
- }
1271
- );
1272
- o = false;
1273
- if (i) {
1274
- handleError(r);
1275
- throw r;
1276
- } else if (!n) {
1277
- globalQueue.initTransition(resolveTransition(e));
1278
- throw new NotReadyError(context);
1279
- }
1280
- }
1281
- if (i) {
1282
- const n = t[Symbol.asyncIterator]();
1283
- let i = false;
1284
- let r = false;
1285
- let o = true;
1286
- cleanup(() => {
1287
- if (r) return;
1288
- r = true;
1289
- try {
1290
- const e = n.return?.();
1291
- if (isThenable(e)) e.then(undefined, () => {});
1292
- } catch {}
1293
- });
1294
- const iterate = () => {
1295
- let u,
1296
- c,
1297
- a = false,
1298
- l = false,
1299
- f = true;
1300
- n.next().then(
1301
- n => {
1302
- if (f) {
1303
- u = n;
1304
- a = true;
1305
- if (n.done) r = true;
1306
- } else if (e.ke !== t) {
1307
- return;
1308
- } else if (!n.done) {
1309
- i = true;
1310
- asyncWrite(n.value, iterate);
1311
- } else {
1312
- r = true;
1313
- if (i) {
1314
- schedule();
1315
- flush();
1316
- } else {
1317
- asyncWrite(undefined);
1318
- }
1319
- }
1320
- },
1321
- n => {
1322
- if (f) {
1323
- c = n;
1324
- l = true;
1325
- } else if (e.ke === t) {
1326
- r = true;
1327
- handleError(n);
1328
- }
1329
- }
1330
- );
1331
- f = false;
1332
- if (l) {
1333
- r = true;
1334
- handleError(c);
1335
- if (o) throw c;
1336
- return true;
1337
- }
1338
- if (a && !u.done) {
1339
- s = u.value;
1340
- i = true;
1341
- return iterate();
1342
- }
1343
- return a && u.done;
1344
- };
1345
- const u = iterate();
1346
- o = false;
1347
- if (!i && !u) {
1348
- globalQueue.initTransition(resolveTransition(e));
1349
- throw new NotReadyError(context);
1350
- }
1351
- }
1352
- return s;
1353
- }
1354
- function clearStatus(e, t = false) {
1355
- if (e.Ie || e.Ae) clearPendingSources(e);
1356
- if (e.Ye) e.Ye = false;
1357
- e.qe = false;
1358
- e.q = t ? 0 : e.q & STATUS_UNINITIALIZED;
1359
- if (e.Te) setPendingError(e);
1360
- if (e.X || e.J) updatePendingSignal(e);
1361
- if (e.ve) updateChildCompanions(e);
1362
- if (e.Be) e.Be();
1363
- }
1364
- function notifyStatus(e, t, n, i, r) {
1365
- if (t === STATUS_ERROR && !(n instanceof StatusError) && !(n instanceof NotReadyError))
1366
- n = new StatusError(e, n);
1367
- const s = t === STATUS_PENDING && n instanceof NotReadyError ? n.source : undefined;
1368
- const o = s === e;
1369
- const u = t === STATUS_PENDING && e.p !== undefined && !o;
1370
- const c = u && hasActiveOverride(e);
1371
- if (!i) {
1372
- if (t === STATUS_PENDING && s) {
1373
- addPendingSource(e, s);
1374
- e.q = STATUS_PENDING | (e.q & STATUS_UNINITIALIZED);
1375
- setPendingError(e, s, n);
1376
- } else {
1377
- clearPendingSources(e);
1378
- e.q = t | (t !== STATUS_ERROR ? e.q & STATUS_UNINITIALIZED : 0);
1379
- e.Te = n;
1380
- }
1381
- updatePendingSignal(e);
1382
- if (e.ve) updateChildCompanions(e);
1383
- }
1384
- if (r && !i) {
1385
- assignOrMergeLane(e, r);
1386
- }
1387
- const a = i || c;
1388
- const l = i || u ? undefined : r;
1389
- if (e.Be) {
1390
- if (i && t === STATUS_PENDING) {
1391
- return;
1392
- }
1393
- if (a) {
1394
- e.Be(t, n);
1395
- } else {
1396
- e.Be();
1397
- }
1398
- return;
1399
- }
1400
- forEachDependent(e, (e, i) => {
1401
- e._e = clock;
1402
- if (
1403
- (t === STATUS_PENDING && s && e.Ie !== s && !e.Ae?.has(s)) ||
1404
- (t !== STATUS_PENDING && (e.Te !== n || e.Ie || e.Ae))
1405
- ) {
1406
- if (i.$e && t !== STATUS_PENDING && !(n instanceof NotReadyError)) {
1407
- enqueueForRerun(e);
1408
- schedule();
1409
- return;
1410
- }
1411
- if (!a && !e.T) queuePendingNode(e);
1412
- notifyStatus(e, t, n, a, l);
1413
- }
1414
- });
1415
- }
1416
- function getAffectsSentinel(e) {
1417
- return (e.ze ??= {
1418
- Xe: undefined,
1419
- ge: e,
1420
- H: 0,
1421
- q: 0,
1422
- qe: false,
1423
- Te: undefined,
1424
- D: null,
1425
- he: null
1426
- });
1427
- }
1428
- function propagateAffectsMark(e) {
1429
- if (!e.D && !e.ve) return;
1430
- const t = getAffectsSentinel(e);
1431
- const n = new NotReadyError(t);
1432
- forEachDependent(e, e => {
1433
- if (e.Ie !== t && !e.Ae?.has(t)) {
1434
- if (!e.T) queuePendingNode(e);
1435
- notifyStatus(e, STATUS_PENDING, n);
1436
- }
1437
- });
1438
- }
1439
- function applyAffectsReads(e, t) {
1440
- let n = false;
1441
- for (let i = 0; i < t.length; i++) {
1442
- const r = t[i];
1443
- if (!r.L) continue;
1444
- const s = getAffectsSentinel(r);
1445
- if (addPendingSource(e, s)) {
1446
- e.q |= STATUS_PENDING;
1447
- setPendingError(e, s);
1448
- n = true;
1449
- }
1450
- }
1451
- if (n) updatePendingSignal(e);
1452
- }
1453
- GlobalQueue.le = propagateAffectsMark;
1454
- GlobalQueue.fe = e => {
1455
- const t = e.ze;
1456
- if (t) settlePendingSource(e, t, true);
1457
- };
1458
- let externalSourceConfig = null;
1459
- function enableExternalSource(e) {
1460
- const { factory: t, untrack: n = e => e() } = e;
1461
- if (externalSourceConfig) {
1462
- const { factory: e, untrack: i } = externalSourceConfig;
1463
- externalSourceConfig = {
1464
- factory: (n, i) => {
1465
- const r = e(n, i);
1466
- const s = t(e => r.track(e), i);
1467
- return {
1468
- track: e => s.track(e),
1469
- dispose() {
1470
- s.dispose();
1471
- r.dispose();
1472
- }
1473
- };
1474
- },
1475
- untrack: e => i(() => n(e))
1476
- };
1477
- } else {
1478
- externalSourceConfig = { factory: t, untrack: n };
1479
- }
1480
- }
1481
- GlobalQueue.se = recompute;
1482
- GlobalQueue.oe = disposeChildren;
1483
- let tracking = false;
1484
- let stale = false;
1485
- let pendingCheckActive = false;
1486
- let latestReadActive = false;
1487
- let context = null;
1488
- let currentOptimisticLane = null;
1489
- let pendingProbe = null;
1490
- let affectsReads = null;
1491
- let snapshotCaptureActive = false;
1492
- let snapshotSources = null;
1493
- function ownerInSnapshotScope(e) {
1494
- while (e) {
1495
- if (e.Je) return true;
1496
- e = e.te;
1497
- }
1498
- return false;
1499
- }
1500
- function setSnapshotCapture(e) {
1501
- snapshotCaptureActive = e;
1502
- if (e && !snapshotSources) snapshotSources = new Set();
1503
- }
1504
- function markSnapshotScope(e) {
1505
- e.Je = true;
1506
- }
1507
- function releaseSnapshotScope(e) {
1508
- e.Je = false;
1509
- releaseSubtree(e);
1510
- schedule();
1511
- }
1512
- function releaseSubtree(e) {
1513
- let t = e.Le;
1514
- while (t) {
1515
- if (t.Je) {
1516
- t = t.Ve;
1517
- continue;
1518
- }
1519
- if (t.de) {
1520
- const e = t;
1521
- e.Se &= ~CONFIG_IN_SNAPSHOT_SCOPE;
1522
- if (e.H & REACTIVE_SNAPSHOT_STALE) {
1523
- e.H &= ~REACTIVE_SNAPSHOT_STALE;
1524
- e.H |= REACTIVE_DIRTY;
1525
- if (dirtyQueue.I > e.$) dirtyQueue.I = e.$;
1526
- insertIntoHeap(e, dirtyQueue);
1527
- }
1528
- }
1529
- releaseSubtree(t);
1530
- t = t.Ve;
1531
- }
1532
- }
1533
- function clearSnapshots() {
1534
- if (snapshotSources) {
1535
- for (const e of snapshotSources) {
1536
- delete e.pe;
1537
- delete e[STORE_SNAPSHOT_PROPS];
1538
- }
1539
- snapshotSources = null;
1540
- }
1541
- snapshotCaptureActive = false;
1542
- }
1543
- function recompute(e, t = false) {
1544
- const n = e.G;
1545
- if (!t) {
1546
- if (e.T && (!n || activeTransition) && activeTransition !== e.T)
1547
- globalQueue.initTransition(e.T);
1548
- deleteFromHeap(e, e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
1549
- e.ke = null;
1550
- if (e.T || n === EFFECT_TRACKED) disposeChildren(e);
1551
- else if (e.Le !== null || e.Me !== null) {
1552
- markDisposal(e);
1553
- e.Re = e.Me;
1554
- e.Oe = e.Le;
1555
- e.Me = null;
1556
- e.Le = null;
1557
- e.Ge = 0;
1558
- } else;
1559
- }
1560
- let i = !!(e.H & REACTIVE_OPTIMISTIC_DIRTY);
1561
- const r = e.p !== undefined && e.p !== NOT_PENDING;
1562
- const s = !!(e.q & STATUS_PENDING);
1563
- const o = !!(e.q & STATUS_UNINITIALIZED);
1564
- const u = !!(e.H & REACTIVE_REASK) && !(s && !e.qe);
1565
- const c = context;
1566
- context = e;
1567
- e.Ue = null;
1568
- e.Ke++;
1569
- e.H = REACTIVE_RECOMPUTING_DEPS;
1570
- e._e = clock;
1571
- let a = e.m === NOT_PENDING ? e.B : e.m;
1572
- let l = e.$;
1573
- let f = tracking;
1574
- const E = affectsReads;
1575
- affectsReads = null;
1576
- let d = null;
1577
- let S = currentOptimisticLane;
1578
- tracking = true;
1579
- if (i) {
1580
- const t = resolveLane(e);
1581
- if (t) currentOptimisticLane = t;
1582
- } else if (activeTransition && !t && activeTransition.N.length) {
1583
- for (let t = e.he; t; t = t.Ne) {
1584
- const n = t.Ce;
1585
- if (n.H & REACTIVE_OPTIMISTIC_DIRTY) {
1586
- const t = resolveLane(n);
1587
- if (t) {
1588
- i = true;
1589
- currentOptimisticLane = t;
1590
- e.H |= REACTIVE_OPTIMISTIC_DIRTY;
1591
- assignOrMergeLane(e, t);
1592
- break;
1593
- }
1594
- }
1595
- }
1596
- }
1597
- const T = n && n !== EFFECT_USER;
1598
- const _ = stale;
1599
- if (T) stale = true;
1600
- try {
1601
- if (!false && e.Se & CONFIG_SYNC) {
1602
- a = e.de(a);
1603
- e.ke = null;
1604
- } else {
1605
- const t = e.ke;
1606
- const n = e.de(a);
1607
- const i = typeof n === "object" && n !== null;
1608
- const r = e.ke !== t;
1609
- a = r || !i ? n : handleAsync(e, n);
1610
- if (!r && !i) e.ke = null;
1611
- }
1612
- clearStatus(e, t);
1613
- if (e.i) {
1614
- const t = resolveLane(e);
1615
- if (t) {
1616
- t.u.delete(e);
1617
- updatePendingSignal(t.o);
1618
- }
1619
- }
1620
- } catch (t) {
1621
- if (t instanceof NotReadyError && currentOptimisticLane) {
1622
- const t = findLane(currentOptimisticLane);
1623
- if (t.o !== e) {
1624
- t.u.add(e);
1625
- e.i = t;
1626
- updatePendingSignal(t.o);
1627
- }
1628
- }
1629
- let n = false;
1630
- if (t instanceof NotReadyError) {
1631
- e.Ye = true;
1632
- n = s && e.qe !== u;
1633
- e.qe = u;
1634
- }
1635
- notifyStatus(
1636
- e,
1637
- t instanceof NotReadyError ? STATUS_PENDING : STATUS_ERROR,
1638
- t,
1639
- undefined,
1640
- t instanceof NotReadyError ? e.i : undefined
1641
- );
1642
- if (n) repollDownstreamVerdicts(e);
1643
- } finally {
1644
- tracking = f;
1645
- if (T) stale = _;
1646
- e.H = REACTIVE_NONE | (t ? e.H & REACTIVE_SNAPSHOT_STALE : 0);
1647
- context = c;
1648
- d = affectsReads;
1649
- affectsReads = E;
1650
- }
1651
- if (!e.Te) {
1652
- trimStaleDeps(e);
1653
- const s = r ? e.p : e.m === NOT_PENDING ? e.B : e.m;
1654
- let u = false;
1655
- try {
1656
- u = (!n && o) || !e.Ze || !e.Ze(s, a);
1657
- } catch (t) {
1658
- notifyStatus(e, STATUS_ERROR, t);
1659
- }
1660
- if (n && u) {
1661
- e.F = !e.Te;
1662
- if (!t) e.W.enqueue(n, (e.et ??= GlobalQueue.ue.bind(null, e)));
1663
- }
1664
- if (e.Te);
1665
- else if (u) {
1666
- const s = r ? e.p : undefined;
1667
- if (t || (n && activeTransition !== e.T) || i) {
1668
- e.B = a;
1669
- if (r && i) {
1670
- e.p = a;
1671
- e.m = NOT_PENDING;
1672
- }
1673
- } else {
1674
- e.m = a;
1675
- if (activeTransition || e.T) syncCompanions(e, a);
1676
- }
1677
- if (!r || i || e.p !== s) insertSubs(e, i || r);
1678
- } else if (r) {
1679
- if (e.m === NOT_PENDING) queuePendingNode(e);
1680
- e.m = a;
1681
- } else if (e.$ != l) {
1682
- for (let t = e.D; t !== null; t = t.U) {
1683
- insertIntoHeapHeight(t.k, t.k.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
1684
- }
1685
- }
1686
- }
1687
- currentOptimisticLane = S;
1688
- if (d) applyAffectsReads(e, d);
1689
- const p =
1690
- e.m !== NOT_PENDING ||
1691
- e.Oe !== null ||
1692
- e.Re !== null ||
1693
- !!(e.q & (STATUS_PENDING | STATUS_UNINITIALIZED));
1694
- p && (!t || e.q & STATUS_PENDING) && (!e.T || r) && queuePendingNode(e);
1695
- e.T && n && activeTransition !== e.T && runInTransition(e.T, () => recompute(e));
1696
- }
1697
- function updateIfNecessary(e) {
1698
- if (e.H & REACTIVE_CHECK) {
1699
- for (let t = e.he; t; t = t.Ne) {
1700
- const n = t.Ce;
1701
- const i = n.ye || n;
1702
- if (i.de) {
1703
- updateIfNecessary(i);
1704
- }
1705
- if (e.H & REACTIVE_DIRTY) {
1706
- break;
1707
- }
1708
- }
1709
- }
1710
- if (e.H & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY) || (e.Te && e._e < clock && !e.ke)) {
1711
- recompute(e);
1712
- }
1713
- e.H = e.H & (REACTIVE_SNAPSHOT_STALE | REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT);
1714
- }
1715
- function computed(e, t) {
1716
- const n = t?.transparent ?? false;
1717
- const i = {
1718
- id: t?.id ?? (n ? context?.id : context?.id != null ? getNextChildId(context) : undefined),
1719
- Se:
1720
- (n ? CONFIG_TRANSPARENT : 0) |
1721
- (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) |
1722
- (!context || t?.lazy ? CONFIG_AUTO_DISPOSE : 0) |
1723
- (t?.sync ? CONFIG_SYNC : 0) |
1724
- (t?.tt ? CONFIG_NO_SNAPSHOT : 0) |
1725
- (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
1726
- Ze: t?.equals != null ? t.equals : isEqual,
1727
- V: t?.unobserved,
1728
- Me: null,
1729
- W: context?.W ?? globalQueue,
1730
- He: context?.He ?? defaultContext,
1731
- Ge: 0,
1732
- de: e,
1733
- B: undefined,
1734
- $: 0,
1735
- ve: null,
1736
- me: undefined,
1737
- be: null,
1738
- he: null,
1739
- Ue: null,
1740
- Ke: 0,
1741
- D: null,
1742
- xe: null,
1743
- te: context,
1744
- Ve: null,
1745
- Fe: null,
1746
- Le: null,
1747
- H: t?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
1748
- q: STATUS_UNINITIALIZED,
1749
- _e: clock,
1750
- m: NOT_PENDING,
1751
- Re: null,
1752
- Oe: null,
1753
- ke: null,
1754
- T: null,
1755
- qe: false
1756
- };
1757
- setupComputedNode(i, t);
1758
- return i;
1759
- }
1760
- function createEffectNode(e, t, n, i, r, s) {
1761
- const o = s?.transparent ?? false;
1762
- const u = {
1763
- id: s?.id ?? (o ? context?.id : context?.id != null ? getNextChildId(context) : undefined),
1764
- Se:
1765
- (o ? CONFIG_TRANSPARENT : 0) |
1766
- (s?.ownedWrite ? CONFIG_OWNED_WRITE : 0) |
1767
- (s?.sync ? CONFIG_SYNC : 0) |
1768
- (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
1769
- Ze: false,
1770
- V: s?.unobserved,
1771
- Me: null,
1772
- W: context?.W ?? globalQueue,
1773
- He: context?.He ?? defaultContext,
1774
- Ge: 0,
1775
- de: e,
1776
- B: undefined,
1777
- $: 0,
1778
- ve: null,
1779
- me: undefined,
1780
- be: null,
1781
- he: null,
1782
- Ue: null,
1783
- Ke: 0,
1784
- D: null,
1785
- xe: null,
1786
- te: context,
1787
- Ve: null,
1788
- Fe: null,
1789
- Le: null,
1790
- H: REACTIVE_LAZY,
1791
- q: STATUS_UNINITIALIZED,
1792
- _e: clock,
1793
- m: NOT_PENDING,
1794
- Re: null,
1795
- Oe: null,
1796
- ke: null,
1797
- T: null,
1798
- qe: false,
1799
- F: false,
1800
- nt: undefined,
1801
- it: t,
1802
- rt: n,
1803
- We: undefined,
1804
- G: i,
1805
- Be: r
1806
- };
1807
- setupComputedNode(u, lazyOptions);
1808
- return u;
1809
- }
1810
- const lazyOptions = { lazy: true };
1811
- function setupComputedNode(e, t) {
1812
- e.be = e;
1813
- const n = context?.Pe ? context.De : context;
1814
- if (context) {
1815
- const t = context.Le;
1816
- if (t === null) {
1817
- context.Le = e;
1818
- } else {
1819
- e.Ve = t;
1820
- t.Fe = e;
1821
- context.Le = e;
1822
- }
1823
- }
1824
- if (n) e.$ = n.$ + 1;
1825
- if (externalSourceConfig) {
1826
- const t = signal(undefined, { equals: false, ownedWrite: true });
1827
- const n = externalSourceConfig.factory(e.de, () => {
1828
- setSignal(t, undefined);
1829
- });
1830
- cleanup(() => n.dispose());
1831
- e.de = e => {
1832
- read(t);
1833
- return n.track(e);
1834
- };
1835
- }
1836
- !t?.lazy && recompute(e, true);
1837
- if (snapshotCaptureActive && !t?.lazy) {
1838
- if (!(e.q & STATUS_PENDING) && !(e.Se & CONFIG_NO_SNAPSHOT)) {
1839
- e.pe = e.B === undefined ? NO_SNAPSHOT : e.B;
1840
- snapshotSources.add(e);
1841
- }
1842
- }
1843
- }
1844
- function signal(e, t, n = null) {
1845
- const i = {
1846
- Ze: t?.equals != null ? t.equals : isEqual,
1847
- Se: (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (t?.tt ? CONFIG_NO_SNAPSHOT : 0),
1848
- V: t?.unobserved,
1849
- B: e,
1850
- D: null,
1851
- xe: null,
1852
- _e: clock,
1853
- ye: n,
1854
- we: n?.ve || null,
1855
- m: NOT_PENDING
1856
- };
1857
- n && (n.ve = i);
1858
- if (snapshotCaptureActive && !(i.Se & CONFIG_NO_SNAPSHOT) && !((n?.q ?? 0) & STATUS_PENDING)) {
1859
- i.pe = e === undefined ? NO_SNAPSHOT : e;
1860
- snapshotSources.add(i);
1861
- }
1862
- return i;
1863
- }
1864
- function optimisticSignal(e, t) {
1865
- const n = signal(e, t);
1866
- n.p = NOT_PENDING;
1867
- return n;
1868
- }
1869
- function optimisticComputed(e, t) {
1870
- const n = computed(e, t);
1871
- n.p = NOT_PENDING;
1872
- return n;
1873
- }
1874
- function isEqual(e, t) {
1875
- return e === t;
1876
- }
1877
- function untrack(e, t) {
1878
- if (!externalSourceConfig && !tracking && true) return e();
1879
- const n = tracking;
1880
- tracking = false;
1881
- try {
1882
- if (externalSourceConfig) return externalSourceConfig.untrack(e);
1883
- return e();
1884
- } finally {
1885
- tracking = n;
1886
- }
1887
- }
1888
- function prepareComputed(e, t) {
1889
- if (e.H & REACTIVE_LAZY) {
1890
- e.H &= ~REACTIVE_LAZY;
1891
- recompute(e, true);
1892
- } else if (e.H & REACTIVE_DISPOSED) {
1893
- recompute(e, true);
1894
- } else if (t) {
1895
- updateIfNecessary(e);
1896
- }
1897
- }
1898
- function read(e) {
1899
- if (latestReadActive) {
1900
- const t = getLatestValueComputed(e);
1901
- const n = latestReadActive;
1902
- latestReadActive = false;
1903
- const i = e.p !== undefined && e.p !== NOT_PENDING ? e.p : e.B;
1904
- let r;
1905
- try {
1906
- r = read(t);
1907
- } catch (t) {
1908
- if (t instanceof NotReadyError && (!context || !(e.q & STATUS_UNINITIALIZED))) return i;
1909
- throw t;
1910
- } finally {
1911
- latestReadActive = n;
1912
- }
1913
- if (t.q & STATUS_PENDING) return i;
1914
- if (stale && currentOptimisticLane && t.i) {
1915
- const e = findLane(t.i);
1916
- const n = findLane(currentOptimisticLane);
1917
- if (e !== n && e.u.size > 0) {
1918
- return i;
1919
- }
1920
- }
1921
- return r;
1922
- }
1923
- let t = context;
1924
- if (t?.Pe) t = t.De;
1925
- const n = e;
1926
- const i = e.ye;
1927
- const r = i || e;
1928
- if (pendingCheckActive) {
1929
- pendingCheckActive = false;
1930
- if (typeof n.de === "function") prepareComputed(e, true);
1931
- if (t && r.q & STATUS_PENDING && r.q & STATUS_UNINITIALIZED) {
1932
- if (tracking && e !== t) link(e, t);
1933
- pendingCheckActive = true;
1934
- throw r.Te;
1935
- }
1936
- collectPendingSources(e);
1937
- if (i) collectPendingSources(i);
1938
- pendingCheckActive = true;
1939
- } else if (typeof n.de === "function") {
1940
- prepareComputed(e, false);
1941
- }
1942
- if (
1943
- !n.de &&
1944
- r === e &&
1945
- e.p === undefined &&
1946
- e.pe === undefined &&
1947
- activeTransition === null &&
1948
- currentOptimisticLane === null &&
1949
- !snapshotCaptureActive &&
1950
- true
1951
- ) {
1952
- if (t && tracking) {
1953
- link(e, t);
1954
- if (activeAffectsMarks !== 0 && e.L && !pendingCheckActive) (affectsReads ??= []).push(e);
1955
- }
1956
- return !t || e.m === NOT_PENDING ? e.B : e.m;
1957
- }
1958
- if (t && tracking) {
1959
- link(e, t, pendingCheckActive);
1960
- if (activeAffectsMarks !== 0 && e.L && !pendingCheckActive) (affectsReads ??= []).push(e);
1961
- if (r.de) {
1962
- const n = e.H & REACTIVE_ZOMBIE;
1963
- if (r.$ >= (n ? zombieQueue.I : dirtyQueue.I)) {
1964
- markNode(t);
1965
- markHeap(n ? zombieQueue : dirtyQueue);
1966
- updateIfNecessary(r);
1967
- }
1968
- const i = r.$;
1969
- if (i >= t.$ && e.te !== t) {
1970
- t.$ = i + 1;
1971
- }
1972
- }
1973
- }
1974
- if (r.q & STATUS_PENDING) {
1975
- if (t && !(stale && r.T && activeTransition !== r.T)) {
1976
- if (currentOptimisticLane) {
1977
- const n = r.i;
1978
- const i = findLane(currentOptimisticLane);
1979
- if (n && findLane(n) === i && !hasActiveOverride(r)) {
1980
- if (!tracking && e !== t) link(e, t);
1981
- throw r.Te;
1982
- }
1983
- } else {
1984
- if (!tracking && e !== t) link(e, t);
1985
- throw r.Te;
1986
- }
1987
- } else if (t && r !== e && r.q & STATUS_UNINITIALIZED) {
1988
- if (!tracking && e !== t) link(e, t);
1989
- throw r.Te;
1990
- } else if (!t && r.q & STATUS_UNINITIALIZED) {
1991
- throw r.Te;
1992
- }
1993
- }
1994
- if (e.de && e.q & STATUS_ERROR) {
1995
- if (tracking && !pendingCheckActive && e._e < clock) {
1996
- recompute(e);
1997
- return read(e);
1998
- } else throw e.Te;
1999
- }
2000
- if (snapshotCaptureActive && t && t.Se & CONFIG_IN_SNAPSHOT_SCOPE) {
2001
- const n = e.pe;
2002
- if (n !== undefined) {
2003
- const i = n === NO_SNAPSHOT ? undefined : n;
2004
- const r = e.m !== NOT_PENDING ? e.m : e.B;
2005
- if (r !== i) t.H |= REACTIVE_SNAPSHOT_STALE;
2006
- return i;
2007
- }
2008
- }
2009
- if (e.p !== undefined && e.p !== NOT_PENDING) {
2010
- if (t && stale && shouldReadStashedOptimisticValue(e)) return e.B;
2011
- return e.p;
2012
- }
2013
- if (
2014
- activeTransition !== null &&
2015
- currentOptimisticLane !== null &&
2016
- !latestReadActive &&
2017
- e.m !== NOT_PENDING &&
2018
- (r === e || !!(r.H & REACTIVE_MANUAL_WRITE)) &&
2019
- !e.de &&
2020
- t
2021
- ) {
2022
- activeTransition.Z.add(t);
2023
- return e.B;
2024
- }
2025
- const s =
2026
- !t ||
2027
- (currentOptimisticLane !== null &&
2028
- (e.p !== undefined || e.i || (r === e && stale && t.t !== e) || !!(r.q & STATUS_PENDING))) ||
2029
- e.m === NOT_PENDING ||
2030
- (stale && e.T && activeTransition !== e.T)
2031
- ? e.B
2032
- : e.m;
2033
- if (pendingCheckActive && pendingProbe !== null && e.m !== NOT_PENDING && s === e.m)
2034
- pendingProbe.freshReads.add(e);
2035
- if (
2036
- !t &&
2037
- r === e &&
2038
- typeof n.de === "function" &&
2039
- e.Se & CONFIG_AUTO_DISPOSE &&
2040
- !(r.q & STATUS_PENDING) &&
2041
- !e.D
2042
- ) {
2043
- unobserved(e);
2044
- }
2045
- return s;
2046
- }
2047
- function setSignal(e, t) {
2048
- if (e.T && activeTransition !== e.T) globalQueue.initTransition(e.T);
2049
- const n = e.p !== undefined && !projectionWriteActive;
2050
- const i = e.p !== undefined && e.p !== NOT_PENDING;
2051
- const r = n ? (i ? e.p : e.B) : e.m === NOT_PENDING ? e.B : e.m;
2052
- if (typeof t === "function") t = t(r);
2053
- const s = !!(e.q & STATUS_UNINITIALIZED) || !e.Ze || !e.Ze(r, t);
2054
- if (!s) {
2055
- if (n && i) {
2056
- const t = resolveTransition(e);
2057
- if (t && activeTransition !== t) globalQueue.initTransition(t);
2058
- }
2059
- return t;
2060
- }
2061
- if (n) {
2062
- const n = e.p === NOT_PENDING;
2063
- if (!n) globalQueue.initTransition(resolveTransition(e));
2064
- if (n) globalQueue.N.push(e);
2065
- const i = getOrCreateLane(e);
2066
- e.i = i;
2067
- e.p = t;
2068
- } else {
2069
- if (e.m === NOT_PENDING) queuePendingNode(e);
2070
- e.m = t;
2071
- }
2072
- syncCompanions(e, t);
2073
- e._e = clock;
2074
- insertSubs(e, n);
2075
- schedule();
2076
- return t;
2077
- }
2078
- function suppressComputedRecompute(e) {
2079
- deleteFromHeap(e, e.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
2080
- if (!(e.H & REACTIVE_MANUAL_WRITE) && e.m === NOT_PENDING) {
2081
- queuePendingNode(e);
2082
- schedule();
2083
- }
2084
- e.H = (e.H & -4) | REACTIVE_MANUAL_WRITE;
2085
- }
2086
- function setMemo(e, t) {
2087
- const n = setSignal(e, t);
2088
- suppressComputedRecompute(e);
2089
- return n;
2090
- }
2091
- function runWithOwner(e, t) {
2092
- const n = context;
2093
- const i = tracking;
2094
- context = e;
2095
- tracking = false;
2096
- try {
2097
- return t();
2098
- } finally {
2099
- context = n;
2100
- tracking = i;
2101
- }
2102
- }
2103
- function getPendingSignal(e) {
2104
- if (!e.X) {
2105
- e.X = optimisticSignal(false, { ownedWrite: true });
2106
- e.X.t = e;
2107
- if (computePendingState(e)) setSignal(e.X, true);
2108
- }
2109
- return e.X;
2110
- }
2111
- function collectPendingSources(e) {
2112
- if (!pendingProbe) return;
2113
- pendingProbe.sources.add(e);
2114
- const t = e.ye || e;
2115
- if (t !== e) pendingProbe.sources.add(t);
2116
- }
2117
- function witnessAffects(e) {
2118
- pendingProbe?.sources.add(e);
2119
- }
2120
- function quietPending(e) {
2121
- if (e.Ae) {
2122
- for (const t of e.Ae) if (!t.qe) return false;
2123
- return true;
2124
- }
2125
- if (e.Ie) return e.Ie.qe;
2126
- return e.qe;
2127
- }
2128
- function newQuestionInFlight(e) {
2129
- return !!(e.q & STATUS_PENDING) && !(e.q & STATUS_UNINITIALIZED) && !quietPending(e);
2130
- }
2131
- function computePendingState(e) {
2132
- const t = e;
2133
- if (t.H & REACTIVE_DISPOSED) return false;
2134
- if (e.L) return true;
2135
- const n = e.ye;
2136
- if (e.t) {
2137
- const t = e.t;
2138
- if (t.L) return true;
2139
- const n = t.ye || t;
2140
- return newQuestionInFlight(n);
2141
- }
2142
- if (n && e.m !== NOT_PENDING && !hasActiveOverride(e)) {
2143
- return (
2144
- !!(n.H & REACTIVE_MANUAL_WRITE) ||
2145
- (!n.ke && !(n.q & STATUS_PENDING)) ||
2146
- (!!(n.q & STATUS_PENDING) && quietPending(n))
2147
- );
2148
- }
2149
- if (e.m !== NOT_PENDING && !(t.q & STATUS_UNINITIALIZED)) {
2150
- if (hasActiveOverride(e)) return !e.Ze || !e.Ze(e.m, e.p);
2151
- return true;
2152
- }
2153
- return newQuestionInFlight(t);
2154
- }
2155
- function syncCompanions(e, t) {
2156
- if (e.X) updatePendingSignal(e);
2157
- if (e.J) setSignal(e.J, t);
2158
- }
2159
- function updatePendingSignal(e) {
2160
- if (e.X) {
2161
- setSignal(e.X, computePendingState(e));
2162
- }
2163
- if (e.J) updatePendingSignal(e.J);
2164
- }
2165
- function updateChildCompanions(e) {
2166
- for (let t = e.ve; t !== null; t = t.we) {
2167
- if (t.X || t.J) updatePendingSignal(t);
2168
- }
2169
- }
2170
- function repollDownstreamVerdicts(e) {
2171
- const t = new Set();
2172
- const visit = e => {
2173
- if (t.has(e)) return;
2174
- t.add(e);
2175
- if (e.X || e.J) updatePendingSignal(e);
2176
- for (let t = e.D; t !== null; t = t.U) visit(t.k);
2177
- for (let t = e.ve ?? null; t !== null; t = t.we) {
2178
- visit(t);
2179
- }
2180
- };
2181
- visit(e);
2182
- }
2183
- function snapCompanionsToState(e) {
2184
- const t = e.X;
2185
- if (t && (t.p === undefined || t.p === NOT_PENDING)) {
2186
- const n = computePendingState(e);
2187
- if (t.B !== n || t.m !== NOT_PENDING) {
2188
- t.B = n;
2189
- t.m = NOT_PENDING;
2190
- t._e = clock;
2191
- insertSubs(t);
2192
- schedule();
2193
- }
2194
- }
2195
- const n = e.J;
2196
- if (n && !(n.H & REACTIVE_DISPOSED)) {
2197
- if (
2198
- (n.p === undefined || n.p === NOT_PENDING) &&
2199
- n.m === NOT_PENDING &&
2200
- !Object.is(n.B, e.B) &&
2201
- !(n.H & (REACTIVE_DIRTY | REACTIVE_CHECK))
2202
- ) {
2203
- n.H |= REACTIVE_DIRTY;
2204
- insertIntoHeap(n, n.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
2205
- insertSubs(n);
2206
- schedule();
2207
- }
2208
- snapCompanionsToState(n);
2209
- }
2210
- }
2211
- function getLatestValueComputed(e) {
2212
- if (!e.J) {
2213
- const t = latestReadActive;
2214
- latestReadActive = false;
2215
- const n = pendingCheckActive;
2216
- pendingCheckActive = false;
2217
- const i = context;
2218
- context = null;
2219
- e.J = optimisticComputed(() => read(e));
2220
- e.J.t = e;
2221
- context = i;
2222
- pendingCheckActive = n;
2223
- latestReadActive = t;
2224
- }
2225
- return e.J;
2226
- }
2227
- function staleValues(e, t = true) {
2228
- const n = stale;
2229
- stale = t;
2230
- try {
2231
- return e();
2232
- } finally {
2233
- stale = n;
2234
- }
2235
- }
2236
- function latest(e) {
2237
- const t = latestReadActive;
2238
- latestReadActive = true;
2239
- try {
2240
- return e();
2241
- } finally {
2242
- latestReadActive = t;
2243
- }
2244
- }
2245
- function isPending(e) {
2246
- const t = pendingCheckActive;
2247
- const n = pendingProbe;
2248
- pendingCheckActive = true;
2249
- const i = (pendingProbe = { found: false, sources: new Set(), freshReads: new Set() });
2250
- const collectPending = () => {
2251
- pendingCheckActive = false;
2252
- try {
2253
- i.sources.forEach(e => {
2254
- if (read(getPendingSignal(e)) && !i.freshReads.has(e)) i.found = true;
2255
- });
2256
- } finally {
2257
- pendingCheckActive = true;
2258
- }
2259
- };
2260
- try {
2261
- e();
2262
- collectPending();
2263
- return i.found;
2264
- } catch (e) {
2265
- collectPending();
2266
- if (e instanceof NotReadyError) {
2267
- const t = !!(e.source?.q & STATUS_UNINITIALIZED);
2268
- if (i.found && !t) return true;
2269
- if (context && t) throw e;
2270
- }
2271
- return i.found;
2272
- } finally {
2273
- pendingCheckActive = t;
2274
- pendingProbe = n;
2275
- }
2276
- }
2277
- function refresh(e) {
2278
- const t = e?.[$REFRESH];
2279
- if (!t) {
2280
- return;
2281
- }
2282
- if (typeof t.de === "function" && !(t.H & (REACTIVE_DISPOSED | REACTIVE_MANUAL_WRITE))) {
2283
- if (!(t.H & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP))) {
2284
- t.H |= REACTIVE_REASK;
2285
- armReaskClear();
2286
- }
2287
- t.H = (t.H & ~REACTIVE_CHECK) | REACTIVE_DIRTY;
2288
- insertIntoHeap(t, t.H & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
2289
- schedule();
2290
- }
2291
- }
2292
- function createContext(e, t) {
2293
- return { id: Symbol(t), defaultValue: e };
2294
- }
2295
- function getContext(e, t = getOwner()) {
2296
- if (!t) {
2297
- throw new NoOwnerError();
2298
- }
2299
- const n = hasContext(e, t) ? t.He[e.id] : e.defaultValue;
2300
- if (isUndefined(n)) {
2301
- throw new ContextNotFoundError();
2302
- }
2303
- return n;
2304
- }
2305
- function setContext(e, t, n = getOwner()) {
2306
- if (!n) {
2307
- throw new NoOwnerError();
2308
- }
2309
- n.He = { ...n.He, [e.id]: isUndefined(t) ? e.defaultValue : t };
2310
- }
2311
- function hasContext(e, t) {
2312
- return !isUndefined(t?.He[e.id]);
2313
- }
2314
- function isUndefined(e) {
2315
- return typeof e === "undefined";
2316
- }
2317
- function effect(e, t, n, i) {
2318
- const r = !!i?.user;
2319
- const s = createEffectNode(e, t, n, r ? EFFECT_USER : EFFECT_RENDER, notifyEffectStatus, i);
2320
- recompute(s, true);
2321
- !i?.defer &&
2322
- (s.G === EFFECT_USER || i?.schedule ? s.W.enqueue(s.G, runEffect.bind(null, s)) : runEffect(s));
2323
- }
2324
- function notifyEffectStatus(e, t) {
2325
- const n = e !== undefined ? e : this.q;
2326
- const i = t !== undefined ? t : this.Te;
2327
- if (n & STATUS_ERROR) {
2328
- this.W.notify(this, STATUS_PENDING, 0);
2329
- if (this.G === EFFECT_USER) {
2330
- if (this.q & STATUS_ERROR) {
2331
- this.F = true;
2332
- this.W.enqueue(this.G, (this.et ??= runEffect.bind(null, this)));
2333
- }
2334
- return;
2335
- }
2336
- if (!this.W.notify(this, STATUS_ERROR, STATUS_ERROR)) {
2337
- haltReactivity();
2338
- throw i;
2339
- }
2340
- } else if (this.G === EFFECT_RENDER) {
2341
- this.W.notify(this, STATUS_PENDING | STATUS_ERROR, n, i);
2342
- }
2343
- }
2344
- function runEffect(e) {
2345
- if (!e.F || e.H & REACTIVE_DISPOSED) return;
2346
- if (e.q & STATUS_ERROR && e.G === EFFECT_USER) {
2347
- const t = unwrapStatusError(e.Te);
2348
- e.nt = e.B;
2349
- e.F = false;
2350
- try {
2351
- e.rt
2352
- ? e.rt(t, () => {
2353
- const t = e.We;
2354
- e.We = undefined;
2355
- t?.();
2356
- })
2357
- : console.error(t);
2358
- } catch (t) {
2359
- if (!e.W.notify(e, STATUS_ERROR, STATUS_ERROR)) {
2360
- haltReactivity();
2361
- throw t;
2362
- }
2363
- }
2364
- return;
2365
- }
2366
- const t = e.We;
2367
- e.We = undefined;
2368
- try {
2369
- t?.();
2370
- const n = e.it(e.B, e.nt);
2371
- if (false && n !== undefined && typeof n !== "function");
2372
- e.We = n;
2373
- } catch (t) {
2374
- e.Te = new StatusError(e, t);
2375
- e.q |= STATUS_ERROR;
2376
- if (!e.W.notify(e, STATUS_ERROR, STATUS_ERROR)) {
2377
- haltReactivity();
2378
- throw t;
2379
- }
2380
- } finally {
2381
- e.nt = e.B;
2382
- e.F = false;
2383
- }
2384
- }
2385
- GlobalQueue.ue = runEffect;
2386
- function trackedEffect(e, t) {
2387
- const run = () => {
2388
- if (!n.F || n.H & REACTIVE_DISPOSED) return;
2389
- try {
2390
- n.F = false;
2391
- recompute(n);
2392
- } finally {
2393
- }
2394
- };
2395
- const n = computed(
2396
- () => {
2397
- const t = n.We;
2398
- n.We = undefined;
2399
- t?.();
2400
- const i = staleValues(e);
2401
- n.We = i;
2402
- },
2403
- { ...t, lazy: true }
2404
- );
2405
- n.We = undefined;
2406
- n.Se = (n.Se & ~CONFIG_AUTO_DISPOSE) | CONFIG_CHILDREN_FORBIDDEN;
2407
- n.F = true;
2408
- n.G = EFFECT_TRACKED;
2409
- n.Be = (e, t) => {
2410
- const i = e !== undefined ? e : n.q;
2411
- if (i & STATUS_ERROR) {
2412
- n.W.notify(n, STATUS_PENDING, 0);
2413
- const e = t !== undefined ? t : n.Te;
2414
- if (!n.W.notify(n, STATUS_ERROR, STATUS_ERROR)) {
2415
- haltReactivity();
2416
- throw e;
2417
- }
2418
- }
2419
- };
2420
- n.M = run;
2421
- n.W.enqueue(EFFECT_USER, run);
2422
- }
2423
- function restoreTransition(e, t) {
2424
- globalQueue.initTransition(e);
2425
- const n = t();
2426
- flush();
2427
- return n;
2428
- }
2429
- function action(e) {
2430
- return (...t) =>
2431
- new Promise((n, i) => {
2432
- const r = e(...t);
2433
- globalQueue.initTransition();
2434
- let s = activeTransition;
2435
- s.K.push(r);
2436
- const done = (e, t, o = false) => {
2437
- s = currentTransition(s);
2438
- const u = s.K.indexOf(r);
2439
- if (u >= 0) s.K.splice(u, 1);
2440
- setActiveTransition(s);
2441
- schedule();
2442
- o ? i(t) : n(e);
2443
- };
2444
- const step = (e, t) => {
2445
- let n;
2446
- try {
2447
- n = t ? r.throw(e) : r.next(e);
2448
- } catch (e) {
2449
- return done(undefined, e, true);
2450
- }
2451
- if (isThenable(n)) return void n.then(run, e => done(undefined, e, true));
2452
- run(n);
2453
- };
2454
- const run = e => {
2455
- if (e.done) return done(e.value);
2456
- if (isThenable(e.value))
2457
- return void e.value.then(
2458
- e => restoreTransition(s, () => step(e)),
2459
- e => restoreTransition(s, () => step(e, true))
2460
- );
2461
- restoreTransition(s, () => step(e.value));
2462
- };
2463
- step();
2464
- });
2465
- }
2466
- function onCleanup(e) {
2467
- return cleanup(e);
2468
- }
2469
- function accessor(e) {
2470
- const t = read.bind(null, e);
2471
- t[$REFRESH] = e;
2472
- return t;
2473
- }
2474
- function createSignal(e, t) {
2475
- if (typeof e === "function") {
2476
- const n = computed(e, t);
2477
- n.Se &= ~CONFIG_AUTO_DISPOSE;
2478
- return [accessor(n), setMemo.bind(null, n)];
2479
- }
2480
- const n = signal(e, t);
2481
- return [accessor(n), setSignal.bind(null, n)];
2482
- }
2483
- function createMemo(e, t) {
2484
- return accessor(computed(e, t));
2485
- }
2486
- function createEffect(e, t, n) {
2487
- effect(e, t.effect || t, t.error, { user: true, ...n });
2488
- }
2489
- function createRenderEffect(e, t, n) {
2490
- effect(e, t, undefined, n);
2491
- }
2492
- function createTrackedEffect(e, t) {
2493
- trackedEffect(e, t);
2494
- }
2495
- function createReaction(e, t) {
2496
- let n = undefined;
2497
- cleanup(() => n?.());
2498
- const i = getOwner();
2499
- let r;
2500
- return s => {
2501
- if (r) {
2502
- dispose(r);
2503
- r = undefined;
2504
- }
2505
- runWithOwner(i, () => {
2506
- effect(
2507
- () => (s(), (r = getOwner())),
2508
- t => {
2509
- r = undefined;
2510
- n?.();
2511
- const i = (e.effect || e)?.();
2512
- if (false && i !== undefined && typeof i !== "function");
2513
- n = i;
2514
- dispose(t);
2515
- },
2516
- e.error,
2517
- { ...(false ? { ...t, name: t?.name ?? "effect" } : t), user: true, defer: true }
2518
- );
2519
- });
2520
- };
2521
- }
2522
- function resolve(e) {
2523
- return new Promise((t, n) => {
2524
- createRoot(i => {
2525
- effect(
2526
- e,
2527
- e => {
2528
- t(e);
2529
- i();
2530
- },
2531
- e => {
2532
- n(e);
2533
- i();
2534
- },
2535
- { user: true }
2536
- );
2537
- });
2538
- });
2539
- }
2540
- function createOptimistic(e, t) {
2541
- if (typeof e === "function") {
2542
- const n = optimisticComputed(e, t);
2543
- n.Se &= ~CONFIG_AUTO_DISPOSE;
2544
- return [accessor(n), setSignal.bind(null, n)];
2545
- }
2546
- const n = optimisticSignal(e, t);
2547
- return [accessor(n), setSignal.bind(null, n)];
2548
- }
2549
- function onSettled(e) {
2550
- const t = getOwner();
2551
- t && !(t.Se & CONFIG_CHILDREN_FORBIDDEN)
2552
- ? createTrackedEffect(() => untrack(e), undefined)
2553
- : globalQueue.enqueue(EFFECT_USER, () => {
2554
- e();
2555
- });
2556
- }
2557
- function nodeKeys(e) {
2558
- const t = Object.keys(e);
2559
- if (symbolKeyedRecords.has(e)) {
2560
- const n = Object.getOwnPropertySymbols(e);
2561
- for (let e = 0, i = n.length; e < i; e++) {
2562
- if (n[e] !== $TRACK) t.push(n[e]);
2563
- }
2564
- }
2565
- return t;
2566
- }
2567
- function unwrap(e) {
2568
- if (e === null || typeof e !== "object") return e;
2569
- return e[$TARGET]?.[STORE_VALUE] ?? e;
2570
- }
2571
- function getOverrideValue(e, t, n, i) {
2572
- if (i && n in i) return i[n];
2573
- return t && n in t ? t[n] : e[n];
2574
- }
2575
- function addEnumSymbols(e, t, n) {
2576
- for (let i = 0, r = t.length; i < r; i++) {
2577
- if (Object.prototype.propertyIsEnumerable.call(e, t[i])) n.add(t[i]);
2578
- }
2579
- }
2580
- function getAllKeys(e, t, n) {
2581
- const i = getKeys(e, t);
2582
- const r = Object.keys(n);
2583
- const s = e[$TARGET]
2584
- ? untrack(() => Object.getOwnPropertySymbols(e))
2585
- : Object.getOwnPropertySymbols(e);
2586
- const o = Object.getOwnPropertySymbols(n);
2587
- if (s.length === 0 && o.length === 0) {
2588
- if (i.length === r.length) {
2589
- let e = true;
2590
- for (let t = 0; t < i.length; t++) {
2591
- if (i[t] !== r[t]) {
2592
- e = false;
2593
- break;
2594
- }
2595
- }
2596
- if (e) return i;
2597
- }
2598
- const e = new Set(i);
2599
- for (let t = 0; t < r.length; t++) e.add(r[t]);
2600
- return Array.from(e);
2601
- }
2602
- const u = new Set(i);
2603
- addEnumSymbols(e, s, u);
2604
- if (t) {
2605
- for (const e of Reflect.ownKeys(t)) {
2606
- t[e] === $DELETED ? u.delete(e) : u.add(e);
2607
- }
2608
- }
2609
- for (let e = 0; e < r.length; e++) u.add(r[e]);
2610
- addEnumSymbols(n, o, u);
2611
- return Array.from(u);
2612
- }
2613
- function wrapValue(e, t) {
2614
- return isWrappable(e) ? wrap(e, t) : e;
2615
- }
2616
- function itemKey(e, t) {
2617
- return isWrappable(e) ? t(e) : e;
2618
- }
2619
- function keyedMatch(e, t, n) {
2620
- return e === t || (isWrappable(e) && isWrappable(t) && n(e) === n(t));
2621
- }
2622
- function syncArrayNodeMembership(e, t) {
2623
- let n = e[STORE_NODE];
2624
- if (n) {
2625
- const e = nodeKeys(n);
2626
- for (let i = 0, r = e.length; i < r; i++) {
2627
- const r = e[i];
2628
- r in t || setSignal(n[r], undefined);
2629
- }
2630
- }
2631
- if ((n = e[STORE_HAS])) {
2632
- const e = nodeKeys(n);
2633
- for (let i = 0, r = e.length; i < r; i++) {
2634
- const r = e[i];
2635
- setSignal(n[r], r in t);
2636
- }
2637
- }
2638
- }
2639
- function applyArrayItem(e, t, n, i, r) {
2640
- if (isWrappable(e) && isWrappable(t)) {
2641
- const s = wrap(t, n);
2642
- i && setSignal(i, s);
2643
- applyState(e, s, r);
2644
- } else i && setSignal(i, wrapValue(e, n));
2645
- }
2646
- function applyState(e, t, n) {
2647
- e = unwrap(e);
2648
- const i = t?.[$TARGET];
2649
- if (!i) return;
2650
- if (i[STORE_OVERRIDE] || i[STORE_OPTIMISTIC_OVERRIDE]) {
2651
- applyStateSlow(e, i, n);
2652
- } else {
2653
- applyStateFast(e, i, n);
2654
- }
2655
- }
2656
- function applyStateFast(e, t, n) {
2657
- const i = t[STORE_VALUE];
2658
- if (e === i) return;
2659
- const r = t[STORE_NODE];
2660
- (t[STORE_LOOKUP] || storeLookup).set(e, t[$PROXY]);
2661
- t[STORE_VALUE] = e;
2662
- if (Array.isArray(i)) {
2663
- let s = false;
2664
- const o = i.length;
2665
- if (e.length && o && isWrappable(e[0]) && n(e[0]) != null) {
2666
- let u, c, a, l, f, E, d, S;
2667
- for (a = 0, l = Math.min(o, e.length); a < l && keyedMatch((E = i[a]), e[a], n); a++) {
2668
- isWrappable(E) && isWrappable(e[a]) && applyState(e[a], wrap(E, t), n);
2669
- }
2670
- const T = new Array(e.length),
2671
- _ = new Map();
2672
- for (
2673
- l = o - 1, f = e.length - 1;
2674
- l >= a && f >= a && keyedMatch((E = i[l]), e[f], n);
2675
- l--, f--
2676
- ) {
2677
- T[f] = E;
2678
- }
2679
- if (a > f || a > l) {
2680
- for (c = a; c <= f; c++) {
2681
- s = true;
2682
- r?.[c] && setSignal(r[c], wrapValue(e[c], t));
2683
- }
2684
- for (; c < e.length; c++) {
2685
- s = true;
2686
- applyArrayItem(e[c], T[c], t, r?.[c], n);
2687
- }
2688
- syncArrayNodeMembership(t, e);
2689
- (s || o !== e.length) && notifySelf(t);
2690
- o !== e.length && r?.length && setSignal(r.length, e.length);
2691
- return;
2692
- }
2693
- d = new Array(f + 1);
2694
- for (c = f; c >= a; c--) {
2695
- E = e[c];
2696
- S = itemKey(E, n);
2697
- u = _.get(S);
2698
- d[c] = u === undefined ? -1 : u;
2699
- _.set(S, c);
2700
- }
2701
- for (u = a; u <= l; u++) {
2702
- E = i[u];
2703
- S = itemKey(E, n);
2704
- c = _.get(S);
2705
- if (c !== undefined && c !== -1) {
2706
- T[c] = E;
2707
- c = d[c];
2708
- _.set(S, c);
2709
- }
2710
- }
2711
- for (c = a; c < e.length; c++) {
2712
- if (c in T) {
2713
- applyArrayItem(e[c], T[c], t, r?.[c], n);
2714
- } else r?.[c] && setSignal(r[c], wrapValue(e[c], t));
2715
- }
2716
- if (a < e.length) s = true;
2717
- } else if (e.length) {
2718
- for (let o = 0, u = e.length; o < u; o++) {
2719
- const u = i[o];
2720
- if (isWrappable(u) && isWrappable(e[o])) applyState(e[o], wrap(u, t), n);
2721
- else {
2722
- if (u !== e[o]) s = true;
2723
- r?.[o] && setSignal(r[o], wrapValue(e[o], t));
2724
- }
2725
- }
2726
- }
2727
- syncArrayNodeMembership(t, e);
2728
- if (o !== e.length) {
2729
- s = true;
2730
- r?.length && setSignal(r.length, e.length);
2731
- }
2732
- s && notifySelf(t);
2733
- return;
2734
- }
2735
- let s = t[STORE_NODE];
2736
- if (s) {
2737
- const r = s[$TRACK];
2738
- const o = r ? getAllKeys(i, undefined, e) : nodeKeys(s);
2739
- for (let u = 0, c = o.length; u < c; u++) {
2740
- const c = o[u];
2741
- const a = s[c];
2742
- const l = unwrap(i[c]);
2743
- let f = unwrap(e[c]);
2744
- if (l === f) continue;
2745
- if (
2746
- !l ||
2747
- !isWrappable(l) ||
2748
- !isWrappable(f) ||
2749
- Array.isArray(l) !== Array.isArray(f) ||
2750
- (n(l) != null && n(l) !== n(f))
2751
- ) {
2752
- r && setSignal(r, void 0);
2753
- a && setSignal(a, isWrappable(f) ? wrap(f, t) : f);
2754
- } else applyState(f, wrap(l, t), n);
2755
- }
2756
- }
2757
- if ((s = t[STORE_HAS])) {
2758
- const t = nodeKeys(s);
2759
- for (let n = 0, i = t.length; n < i; n++) {
2760
- const i = t[n];
2761
- setSignal(s[i], i in e);
2762
- }
2763
- }
2764
- }
2765
- function applyStateSlow(e, t, n) {
2766
- const i = t[STORE_VALUE];
2767
- const r = t[STORE_OVERRIDE];
2768
- const s = t[STORE_OPTIMISTIC_OVERRIDE];
2769
- let o = t[STORE_NODE];
2770
- (t[STORE_LOOKUP] || storeLookup).set(e, t[$PROXY]);
2771
- t[STORE_VALUE] = e;
2772
- t[STORE_OVERRIDE] = undefined;
2773
- if (Array.isArray(i)) {
2774
- let u = false;
2775
- const c = getOverrideValue(i, r, "length", s);
2776
- if (e.length && c && isWrappable(e[0]) && n(e[0]) != null) {
2777
- let a, l, f, E, d, S, T, _;
2778
- for (
2779
- f = 0, E = Math.min(c, e.length);
2780
- f < E && keyedMatch((S = getOverrideValue(i, r, f, s)), e[f], n);
2781
- f++
2782
- ) {
2783
- isWrappable(S) && isWrappable(e[f]) && applyState(e[f], wrap(S, t), n);
2784
- }
2785
- const p = new Array(e.length),
2786
- O = new Map();
2787
- for (
2788
- E = c - 1, d = e.length - 1;
2789
- E >= f && d >= f && keyedMatch((S = getOverrideValue(i, r, E, s)), e[d], n);
2790
- E--, d--
2791
- ) {
2792
- p[d] = S;
2793
- }
2794
- if (f > d || f > E) {
2795
- for (l = f; l <= d; l++) {
2796
- u = true;
2797
- o?.[l] && setSignal(o[l], wrapValue(e[l], t));
2798
- }
2799
- for (; l < e.length; l++) {
2800
- u = true;
2801
- applyArrayItem(e[l], p[l], t, o?.[l], n);
2802
- }
2803
- const i = e.length;
2804
- syncArrayNodeMembership(t, e);
2805
- (u || c !== i) && notifySelf(t);
2806
- c !== i && o?.length && setSignal(o.length, i);
2807
- return;
2808
- }
2809
- T = new Array(d + 1);
2810
- for (l = d; l >= f; l--) {
2811
- S = e[l];
2812
- _ = itemKey(S, n);
2813
- a = O.get(_);
2814
- T[l] = a === undefined ? -1 : a;
2815
- O.set(_, l);
2816
- }
2817
- for (a = f; a <= E; a++) {
2818
- S = getOverrideValue(i, r, a, s);
2819
- _ = itemKey(S, n);
2820
- l = O.get(_);
2821
- if (l !== undefined && l !== -1) {
2822
- p[l] = S;
2823
- l = T[l];
2824
- O.set(_, l);
2825
- }
2826
- }
2827
- for (l = f; l < e.length; l++) {
2828
- if (l in p) {
2829
- applyArrayItem(e[l], p[l], t, o?.[l], n);
2830
- } else o?.[l] && setSignal(o[l], wrapValue(e[l], t));
2831
- }
2832
- if (f < e.length) u = true;
2833
- } else if (e.length) {
2834
- for (let c = 0, a = e.length; c < a; c++) {
2835
- const a = getOverrideValue(i, r, c, s);
2836
- if (isWrappable(a) && isWrappable(e[c])) applyState(e[c], wrap(a, t), n);
2837
- else {
2838
- if (a !== e[c]) u = true;
2839
- o?.[c] && setSignal(o[c], wrapValue(e[c], t));
2840
- }
2841
- }
2842
- }
2843
- const a = e.length;
2844
- syncArrayNodeMembership(t, e);
2845
- if (c !== a) {
2846
- u = true;
2847
- o?.length && setSignal(o.length, a);
2848
- }
2849
- u && notifySelf(t);
2850
- return;
2851
- }
2852
- if (o) {
2853
- const u = o[$TRACK];
2854
- const c = u ? getAllKeys(i, r, e) : nodeKeys(o);
2855
- for (let a = 0, l = c.length; a < l; a++) {
2856
- const l = c[a];
2857
- const f = o[l];
2858
- const E = unwrap(getOverrideValue(i, r, l, s));
2859
- let d = unwrap(e[l]);
2860
- if (E === d) continue;
2861
- if (
2862
- !E ||
2863
- !isWrappable(E) ||
2864
- !isWrappable(d) ||
2865
- Array.isArray(E) !== Array.isArray(d) ||
2866
- (n(E) != null && n(E) !== n(d))
2867
- ) {
2868
- u && setSignal(u, void 0);
2869
- f && setSignal(f, isWrappable(d) ? wrap(d, t) : d);
2870
- } else applyState(d, wrap(E, t), n);
2871
- }
2872
- }
2873
- if ((o = t[STORE_HAS])) {
2874
- const t = nodeKeys(o);
2875
- for (let n = 0, i = t.length; n < i; n++) {
2876
- const i = t[n];
2877
- setSignal(o[i], i in e);
2878
- }
2879
- }
2880
- }
2881
- function reconcile(e, t) {
2882
- return n => {
2883
- if (n == null) throw new Error("Cannot reconcile null or undefined state");
2884
- const i = typeof t === "string" ? e => e[t] : t;
2885
- const r = i(n);
2886
- if (r !== undefined && i(e) !== r)
2887
- throw new Error("Cannot reconcile states with different identity");
2888
- applyState(e, n, i);
2889
- };
2890
- }
2891
- function createProjectionInternal(e, t, n) {
2892
- let i;
2893
- const r = new WeakMap();
2894
- const wrapper = e => {
2895
- e[STORE_WRAP] = wrapProjection;
2896
- e[STORE_LOOKUP] = r;
2897
- Object.defineProperty(e, STORE_FIREWALL, {
2898
- get() {
2899
- return i;
2900
- },
2901
- configurable: true
2902
- });
2903
- };
2904
- const wrapProjection = e => {
2905
- if (r.has(e)) return r.get(e);
2906
- if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
2907
- const t = createStoreProxy(e, storeTraps, wrapper);
2908
- r.set(e, t);
2909
- return t;
2910
- };
2911
- const s = wrapProjection(t);
2912
- i = computed(() => {
2913
- if (!i) i = getOwner();
2914
- runProjectionComputed(s, e, n?.key || "id");
2915
- }, undefined);
2916
- i.Se &= ~CONFIG_AUTO_DISPOSE;
2917
- return { store: s, node: i };
2918
- }
2919
- function createProjection(e, t, n) {
2920
- return createProjectionInternal(e, t, n).store;
2921
- }
2922
- function runProjectionComputed(e, t, n, i, r) {
2923
- const s = getOwner();
2924
- let o = false;
2925
- let u;
2926
- const c = new Proxy(
2927
- e,
2928
- createWriteTraps(() => !o || s.ke === u, r)
2929
- );
2930
- storeSetter(c, r => {
2931
- u = t(r);
2932
- o = true;
2933
- const commit = t => {
2934
- if (t === r || t === undefined) return;
2935
- const write = () => storeSetter(e, reconcile(t, n));
2936
- i ? i(write) : write();
2937
- };
2938
- commit(handleAsync(s, u, commit));
2939
- });
2940
- return s;
2941
- }
2942
- function createWriteTraps(e, t) {
2943
- const n = {
2944
- get(e, t) {
2945
- let i;
2946
- setWriteOverride(true);
2947
- setProjectionWriteActive(true);
2948
- try {
2949
- i = e[t];
2950
- } finally {
2951
- setWriteOverride(false);
2952
- setProjectionWriteActive(false);
2953
- }
2954
- if (t === $TARGET) return i;
2955
- return typeof i === "object" && i !== null ? new Proxy(i, n) : i;
2956
- },
2957
- has(e, t) {
2958
- let n;
2959
- setWriteOverride(true);
2960
- setProjectionWriteActive(true);
2961
- try {
2962
- n = t in e;
2963
- } finally {
2964
- setWriteOverride(false);
2965
- setProjectionWriteActive(false);
2966
- }
2967
- return n;
2968
- },
2969
- set(n, i, r) {
2970
- if (e && !e()) return true;
2971
- setWriteOverride(true);
2972
- setProjectionWriteActive(true);
2973
- try {
2974
- n[i] = r;
2975
- t?.();
2976
- } finally {
2977
- setWriteOverride(false);
2978
- setProjectionWriteActive(false);
2979
- }
2980
- return true;
2981
- },
2982
- deleteProperty(n, i) {
2983
- if (e && !e()) return true;
2984
- setWriteOverride(true);
2985
- setProjectionWriteActive(true);
2986
- try {
2987
- delete n[i];
2988
- t?.();
2989
- } finally {
2990
- setWriteOverride(false);
2991
- setProjectionWriteActive(false);
2992
- }
2993
- return true;
2994
- }
2995
- };
2996
- return n;
2997
- }
2998
- const $TRACK = Symbol(0),
2999
- $TARGET = Symbol(0),
3000
- $PROXY = Symbol(0),
3001
- $DELETED = Symbol(0),
3002
- $AFFECTS = Symbol(0);
3003
- const STORE_VALUE = "v",
3004
- STORE_OVERRIDE = "o",
3005
- STORE_OPTIMISTIC_OVERRIDE = "x",
3006
- STORE_NODE = "n",
3007
- STORE_HAS = "h",
3008
- STORE_CUSTOM_PROTO = "c",
3009
- STORE_WRAP = "w",
3010
- STORE_LOOKUP = "l",
3011
- STORE_FIREWALL = "f",
3012
- STORE_OPTIMISTIC = "p";
3013
- const STORE_SELF_PENDING = Symbol(0);
3014
- function createStoreProxy(e, t = storeTraps, n) {
3015
- let i;
3016
- if (Array.isArray(e)) {
3017
- i = [];
3018
- i.v = e;
3019
- } else {
3020
- i = { v: e };
3021
- const t = e?.[$TARGET]?.[STORE_VALUE] ?? e;
3022
- const n = Object.getPrototypeOf(t);
3023
- if (n !== null && n !== Object.prototype) {
3024
- i[STORE_CUSTOM_PROTO] = true;
3025
- }
3026
- }
3027
- n && n(i);
3028
- return (i[$PROXY] = new Proxy(i, t));
3029
- }
3030
- const storeLookup = new WeakMap();
3031
- const symbolKeyedRecords = new WeakSet();
3032
- function wrap(e, t) {
3033
- if (t?.[STORE_WRAP]) return t[STORE_WRAP](e, t);
3034
- let n = e[$PROXY] || storeLookup.get(e);
3035
- if (!n) storeLookup.set(e, (n = createStoreProxy(e)));
3036
- return n;
3037
- }
3038
- function isWrappable(e) {
3039
- if (e == null || typeof e !== "object" || Object.isFrozen(e)) return false;
3040
- return typeof Node === "undefined" || !(e instanceof Node);
3041
- }
3042
- let writeOverride = false;
3043
- function setWriteOverride(e) {
3044
- writeOverride = e;
3045
- }
3046
- function writeOnly(e) {
3047
- return writeOverride || !!Writing?.has(e);
3048
- }
3049
- function unwrapStoreValue(e, t, n) {
3050
- const i = e?.[$TARGET] || n?.get(e)?.[$TARGET];
3051
- if (!i) return e;
3052
- const r = i[STORE_OVERRIDE];
3053
- if (!r) return i[STORE_VALUE];
3054
- if (!t) t = new Map();
3055
- if (t.has(e)) return t.get(e);
3056
- const s = i[STORE_VALUE];
3057
- const o = Array.isArray(s);
3058
- const u = o ? [] : Object.create(Object.getPrototypeOf(s));
3059
- t.set(e, u);
3060
- n = i[STORE_LOOKUP] ?? storeLookup;
3061
- for (const e of getKeys(s, r)) {
3062
- if (o && e === "length") continue;
3063
- const i = e in r ? r[e] : s[e];
3064
- if (i !== $DELETED) u[e] = unwrapStoreValue(i, t, n);
3065
- }
3066
- if (o) u.length = r.length ?? s.length;
3067
- return u;
3068
- }
3069
- function isPrototypePollutionKey$1(e) {
3070
- return e === "__proto__" || e === "constructor" || e === "prototype";
3071
- }
3072
- function ownEnumerableKeys(e) {
3073
- return Reflect.ownKeys(e).filter(t => Object.prototype.propertyIsEnumerable.call(e, t));
3074
- }
3075
- function getOverlayLayer(e, t) {
3076
- const n = e[STORE_OPTIMISTIC_OVERRIDE];
3077
- if (n && t in n) return n;
3078
- const i = e[STORE_OVERRIDE];
3079
- if (i && t in i) return i;
3080
- return undefined;
3081
- }
3082
- function visibleNodeValue(e) {
3083
- return e.p !== undefined && e.p !== NOT_PENDING ? e.p : e.m !== NOT_PENDING ? e.m : e.B;
3084
- }
3085
- function hasOwnStoreProperty(e, t) {
3086
- const n = getOverlayLayer(e, t);
3087
- if (n) return n[t] !== $DELETED;
3088
- return Object.prototype.hasOwnProperty.call(unwrapStoreValue(e[STORE_VALUE]), t);
3089
- }
3090
- function hasInheritedAccessor(e, t) {
3091
- let n = Object.getPrototypeOf(e);
3092
- while (n && n !== Object.prototype) {
3093
- const e = Reflect.getOwnPropertyDescriptor(n, t);
3094
- if (e) return !!e.get;
3095
- n = Object.getPrototypeOf(n);
3096
- }
3097
- return false;
3098
- }
3099
- function getNodes(e, t) {
3100
- let n = e[t];
3101
- if (!n) e[t] = n = Object.create(null);
3102
- return n;
3103
- }
3104
- function getNode(e, t, n, i, r = isEqual, s) {
3105
- if (t[n]) return t[n];
3106
- const o = signal(
3107
- i,
3108
- {
3109
- equals: r,
3110
- unobserved() {
3111
- if (t[n] === o) {
3112
- delete t[n];
3113
- if (
3114
- typeof n === "symbol" &&
3115
- n !== $TRACK &&
3116
- n !== $AFFECTS &&
3117
- symbolKeyedRecords.has(t)
3118
- ) {
3119
- const e = Object.getOwnPropertySymbols(t);
3120
- let n = false;
3121
- for (let t = 0, i = e.length; t < i; t++) {
3122
- if (e[t] !== $TRACK && e[t] !== $AFFECTS) {
3123
- n = true;
3124
- break;
3125
- }
3126
- }
3127
- if (!n) symbolKeyedRecords.delete(t);
3128
- }
3129
- }
3130
- }
3131
- },
3132
- e[STORE_FIREWALL]
3133
- );
3134
- if (e[STORE_OPTIMISTIC]) {
3135
- o.p = NOT_PENDING;
3136
- }
3137
- if (s && n in s) {
3138
- const e = s[n];
3139
- o.pe = e === undefined ? NO_SNAPSHOT : e;
3140
- snapshotSources?.add(o);
3141
- }
3142
- if (typeof n === "symbol" && n !== $TRACK && n !== $AFFECTS) symbolKeyedRecords.add(t);
3143
- if (n !== $AFFECTS && affectsScopes.size) inheritAffectsMarks(o, e[STORE_VALUE]);
3144
- return (t[n] = o);
3145
- }
3146
- function inheritAffectsMarks(e, t) {
3147
- for (const [n, i] of affectsScopes) {
3148
- if (n.L && i.scope.has(t)) {
3149
- markAffects(e);
3150
- i.inherited.push(e);
3151
- }
3152
- }
3153
- }
3154
- const affectsScopes = new Map();
3155
- function walkAffectsScope(e, t, n, i, r) {
3156
- if (!isWrappable(e)) return;
3157
- const s = e[$TARGET] || (i ?? storeLookup).get(e)?.[$TARGET];
3158
- const o = s ? s[STORE_VALUE] : e;
3159
- if (r.has(o)) return;
3160
- r.add(o);
3161
- t.scope.add(o);
3162
- let u;
3163
- if (s) {
3164
- collectRecordNodes(s[STORE_NODE], n);
3165
- collectRecordNodes(s[STORE_HAS], n);
3166
- u = mergedOverlay(s);
3167
- i = s[STORE_LOOKUP] ?? i;
3168
- }
3169
- if (Array.isArray(o)) {
3170
- const e = u?.length ?? o.length;
3171
- for (let s = 0; s < e; s++) {
3172
- const e = u && s in u ? u[s] : o[s];
3173
- if (e !== $DELETED) walkAffectsScope(e, t, n, i, r);
3174
- }
3175
- } else {
3176
- const e = getKeys(o, u);
3177
- for (let s = 0, c = e.length; s < c; s++) {
3178
- const c = getPropertyDescriptor(o, u, e[s]);
3179
- if (!c || c.get) continue;
3180
- walkAffectsScope(c.value, t, n, i, r);
3181
- }
3182
- }
3183
- }
3184
- function collectRecordNodes(e, t) {
3185
- if (!e) return;
3186
- for (const n of Object.keys(e)) t.push(e[n]);
3187
- const n = Object.getOwnPropertySymbols(e);
3188
- for (let i = 0, r = n.length; i < r; i++) {
3189
- if (n[i] !== $AFFECTS) t.push(e[n[i]]);
3190
- }
3191
- }
3192
- function witnessAffectsMark(e) {
3193
- const t = e[STORE_NODE]?.[$AFFECTS];
3194
- if (t?.L) witnessAffects(t);
3195
- if (affectsScopes.size) {
3196
- const n = e[STORE_VALUE];
3197
- for (const [e, i] of affectsScopes) {
3198
- if (e !== t && e.L && i.scope.has(n)) witnessAffects(e);
3199
- }
3200
- }
3201
- }
3202
- function getStoreAffectsNodes(e, t) {
3203
- const n = getNodes(e, STORE_NODE);
3204
- if (t === undefined) {
3205
- const t = getNode(e, n, $AFFECTS, undefined, false);
3206
- GlobalQueue.ae ||= e => {
3207
- const t = affectsScopes.get(e);
3208
- if (!t) return;
3209
- affectsScopes.delete(e);
3210
- for (let e = 0; e < t.inherited.length; e++) releaseAffectsMark(t.inherited[e]);
3211
- };
3212
- let i = affectsScopes.get(t);
3213
- if (!i) affectsScopes.set(t, (i = { scope: new Set(), inherited: [] }));
3214
- const r = [t];
3215
- walkAffectsScope(e[$PROXY], i, r, e[STORE_LOOKUP], new Set());
3216
- return r;
3217
- }
3218
- if (n[t]) return [n[t]];
3219
- const i = getOverlayLayer(e, t);
3220
- const r = i ? i[t] : e[STORE_VALUE][t];
3221
- const s = r === $DELETED ? undefined : r;
3222
- return [upsertStoreNode(e, n, t, s, e[STORE_SNAPSHOT_PROPS])];
3223
- }
3224
- function trackSelf(e, t = $TRACK) {
3225
- if (!getObserver()) return;
3226
- read(getNode(e, getNodes(e, STORE_NODE), t, undefined, false));
3227
- if (
3228
- t === $TRACK &&
3229
- !e[STORE_OVERRIDE] &&
3230
- !e[STORE_OPTIMISTIC_OVERRIDE] &&
3231
- e[STORE_VALUE][$TARGET]
3232
- )
3233
- e[STORE_VALUE][$TRACK];
3234
- }
3235
- function notifySelf(e) {
3236
- const t = e[STORE_NODE]?.[$TRACK];
3237
- t && setSignal(t, e[STORE_OPTIMISTIC] && !projectionWriteActive ? STORE_SELF_PENDING : undefined);
3238
- }
3239
- function mergedOverlay(e) {
3240
- const t = e[STORE_OVERRIDE];
3241
- const n = e[STORE_OPTIMISTIC_OVERRIDE];
3242
- return t && n ? { ...t, ...n } : (n ?? t);
3243
- }
3244
- function getKeys(e, t, n = true) {
3245
- const i = e[$TARGET]
3246
- ? untrack(() => (n ? Object.keys(e) : Reflect.ownKeys(e)))
3247
- : n
3248
- ? Object.keys(e)
3249
- : Reflect.ownKeys(e);
3250
- if (!t) return i;
3251
- const r = new Set(i);
3252
- const s = Reflect.ownKeys(t);
3253
- for (const e of s) {
3254
- if (t[e] !== $DELETED) r.add(e);
3255
- else r.delete(e);
3256
- }
3257
- return Array.from(r);
3258
- }
3259
- function getPropertyDescriptor(e, t, n) {
3260
- if (t && n in t) {
3261
- if (t[n] === $DELETED) return void 0;
3262
- const i = Reflect.getOwnPropertyDescriptor(t, n);
3263
- if (i?.get || i?.set) return i;
3264
- const r = Reflect.getOwnPropertyDescriptor(e, n);
3265
- if (!r) return i;
3266
- if (r.get || r.set) return r;
3267
- r.value = t[n];
3268
- return r;
3269
- }
3270
- return Reflect.getOwnPropertyDescriptor(e, n);
3271
- }
3272
- function prepareStoreWrite(e, t, n) {
3273
- if (e[STORE_OPTIMISTIC]) {
3274
- const t = e[STORE_FIREWALL];
3275
- if (t?.T) {
3276
- globalQueue.initTransition(t.T);
3277
- }
3278
- }
3279
- const i = e[STORE_VALUE];
3280
- const r = i[n];
3281
- if (
3282
- snapshotCaptureActive &&
3283
- typeof n !== "symbol" &&
3284
- !((e[STORE_FIREWALL]?.q ?? 0) & STATUS_PENDING)
3285
- ) {
3286
- if (!e[STORE_SNAPSHOT_PROPS]) {
3287
- e[STORE_SNAPSHOT_PROPS] = Object.create(null);
3288
- snapshotSources?.add(e);
3289
- }
3290
- if (!(n in e[STORE_SNAPSHOT_PROPS])) {
3291
- e[STORE_SNAPSHOT_PROPS][n] = r;
3292
- }
3293
- }
3294
- const s = e[STORE_OPTIMISTIC] && !projectionWriteActive;
3295
- const o = s ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
3296
- return { base: r, overrideKey: o, state: i };
3297
- }
3298
- function armOptimisticStoreWrite(e, t) {
3299
- if (e[STORE_OPTIMISTIC] && !projectionWriteActive) {
3300
- trackOptimisticStore(t);
3301
- }
3302
- }
3303
- function upsertStoreNode(e, t, n, i, r) {
3304
- if (t[n]) return t[n];
3305
- const s = isWrappable(i) ? wrap(i, e) : i;
3306
- const o = getNode(e, t, n, s, isEqual, r);
3307
- registerTransientStoreNode(o);
3308
- return o;
3309
- }
3310
- function notifyStoreProperty(e, t, n, i, r, s) {
3311
- const o = projectionWriteActive || e[STORE_OPTIMISTIC];
3312
- const u = n !== "delete";
3313
- const c = e[STORE_HAS]?.[t];
3314
- if (c) {
3315
- setSignal(c, u);
3316
- } else if (!o && n !== "invalidate" && s !== u) {
3317
- const n = upsertStoreNode(e, getNodes(e, STORE_HAS), t, s);
3318
- setSignal(n, u);
3319
- }
3320
- const a = getNodes(e, STORE_NODE);
3321
- if (n === "set") {
3322
- if (a[t]) {
3323
- setSignal(a[t], () => (isWrappable(i) ? wrap(i, e) : i));
3324
- } else if (!o) {
3325
- const n = upsertStoreNode(e, a, t, r, e[STORE_SNAPSHOT_PROPS]);
3326
- setSignal(n, () => (isWrappable(i) ? wrap(i, e) : i));
3327
- }
3328
- } else if (n === "invalidate") {
3329
- if (a[t]) {
3330
- setSignal(a[t], {});
3331
- delete a[t];
3332
- }
3333
- } else {
3334
- if (a[t]) {
3335
- setSignal(a[t], undefined);
3336
- } else if (!o) {
3337
- const n = upsertStoreNode(e, a, t, r, e[STORE_SNAPSHOT_PROPS]);
3338
- setSignal(n, undefined);
3339
- }
3340
- }
3341
- notifySelf(e);
3342
- }
3343
- let Writing = null;
3344
- const storeTraps = {
3345
- get(e, t, n) {
3346
- if (t === $TARGET) return e;
3347
- if (t === $PROXY) return n;
3348
- if (t === $REFRESH) return e[STORE_FIREWALL];
3349
- if (pendingCheckActive) witnessAffectsMark(e);
3350
- if (t === $TRACK) {
3351
- trackSelf(e);
3352
- return n;
3353
- }
3354
- const i = getObserver() === e[STORE_FIREWALL];
3355
- const r = getNodes(e, STORE_NODE);
3356
- const s = i ? undefined : r[t];
3357
- const o = e[STORE_VALUE];
3358
- if (
3359
- !s &&
3360
- !e[STORE_OVERRIDE] &&
3361
- !e[STORE_OPTIMISTIC_OVERRIDE] &&
3362
- !e[STORE_CUSTOM_PROTO] &&
3363
- !e[STORE_OPTIMISTIC] &&
3364
- !e[STORE_SNAPSHOT_PROPS] &&
3365
- !o[$TARGET] &&
3366
- !(t in o) &&
3367
- getObserver() &&
3368
- !i &&
3369
- !writeOnly(n)
3370
- ) {
3371
- return read(getNode(e, r, t, undefined));
3372
- }
3373
- const u = getOverlayLayer(e, t);
3374
- const c = !!u;
3375
- const a = !!e[STORE_VALUE][$TARGET];
3376
- const l = u ?? e[STORE_VALUE];
3377
- if (!s) {
3378
- const i = Object.getOwnPropertyDescriptor(l, t);
3379
- if (i && i.get) return i.get.call(n);
3380
- if (!i && !c && e[STORE_CUSTOM_PROTO]) {
3381
- const e = unwrapStoreValue(l);
3382
- if (hasInheritedAccessor(e, t)) {
3383
- return Reflect.get(l, t, n);
3384
- }
3385
- }
3386
- }
3387
- if (writeOnly(n)) {
3388
- if (isPrototypePollutionKey$1(t) && !hasOwnStoreProperty(e, t)) return undefined;
3389
- let n = s && (c || !a) ? visibleNodeValue(s) : l[t];
3390
- n === $DELETED && (n = undefined);
3391
- if (!isWrappable(n)) return n;
3392
- const i = wrap(n, e);
3393
- Writing?.add(i);
3394
- return i;
3395
- }
3396
- let f = s ? (c || !a ? read(r[t]) : (read(r[t]), l[t])) : l[t];
3397
- f === $DELETED && (f = undefined);
3398
- if (!s) {
3399
- if (!c && typeof f === "function" && !Object.prototype.hasOwnProperty.call(l, t)) {
3400
- let t;
3401
- return !Array.isArray(e[STORE_VALUE]) &&
3402
- (t = Object.getPrototypeOf(e[STORE_VALUE])) &&
3403
- t !== Object.prototype
3404
- ? f.bind(l)
3405
- : f;
3406
- } else if (getObserver() && !i) {
3407
- return read(
3408
- getNode(e, r, t, isWrappable(f) ? wrap(f, e) : f, isEqual, e[STORE_SNAPSHOT_PROPS])
3409
- );
3410
- }
3411
- }
3412
- return isWrappable(f) ? wrap(f, e) : f;
3413
- },
3414
- has(e, t) {
3415
- if (t === $PROXY || t === $TRACK || t === "__proto__") return true;
3416
- if (pendingCheckActive) witnessAffectsMark(e);
3417
- const n = getOverlayLayer(e, t);
3418
- const i = n ? n[t] !== $DELETED : t in e[STORE_VALUE];
3419
- if (writeOnly(e[$PROXY]) || getObserver() === e[STORE_FIREWALL]) return i;
3420
- const r = getNodes(e, STORE_HAS);
3421
- if (r[t]) return read(r[t]);
3422
- if (getObserver()) {
3423
- return read(getNode(e, r, t, i));
3424
- }
3425
- return i;
3426
- },
3427
- set(e, t, n) {
3428
- if (t === "__proto__") return true;
3429
- const i = e[$PROXY];
3430
- if (writeOnly(i)) {
3431
- untrack(() => {
3432
- const { base: r, overrideKey: s, state: o } = prepareStoreWrite(e, i, t);
3433
- const u = getOverlayLayer(e, t);
3434
- const c = u ? u[t] : r;
3435
- const a = u ? u[t] !== $DELETED : t in e[STORE_VALUE];
3436
- const l = unwrapStoreValue(n);
3437
- const f = typeof t === "string" ? Number(t) : -1;
3438
- const E =
3439
- Array.isArray(o) && Number.isInteger(f) && f >= 0 && f < 4294967295 && String(f) === t;
3440
- const d = E ? f + 1 : 0;
3441
- const S = E && (getOverlayLayer(e, "length") ?? o).length;
3442
- const T = E && d > S ? d : undefined;
3443
- if (c === l && T === undefined) return true;
3444
- armOptimisticStoreWrite(e, i);
3445
- if (l !== undefined && l === r && T === undefined) delete e[s]?.[t];
3446
- else {
3447
- const n = e[s] || (e[s] = Object.create(null));
3448
- n[t] = l;
3449
- if (T !== undefined) n.length = T;
3450
- }
3451
- notifyStoreProperty(e, t, "set", l, c, a);
3452
- if (
3453
- Array.isArray(o) &&
3454
- t === "length" &&
3455
- typeof l === "number" &&
3456
- typeof c === "number" &&
3457
- l < c
3458
- ) {
3459
- const t = e[s] || (e[s] = Object.create(null));
3460
- for (let n = l; n < c; n++) {
3461
- if (t[n] === $DELETED) continue;
3462
- const i = n in t ? t[n] : o[n];
3463
- if (!(n in t) && !(n in o)) continue;
3464
- t[n] = $DELETED;
3465
- notifyStoreProperty(e, n, "delete", undefined, i, true);
3466
- }
3467
- }
3468
- if (Array.isArray(o) && t !== "length" && T !== undefined) {
3469
- const t = getNodes(e, STORE_NODE);
3470
- if (t.length) {
3471
- setSignal(t.length, T);
3472
- } else if (!projectionWriteActive && !e[STORE_OPTIMISTIC]) {
3473
- const n = upsertStoreNode(e, t, "length", S, e[STORE_SNAPSHOT_PROPS]);
3474
- setSignal(n, T);
3475
- }
3476
- }
3477
- if (false);
3478
- });
3479
- }
3480
- return true;
3481
- },
3482
- defineProperty(e, t, n) {
3483
- if (t === "__proto__") return true;
3484
- const i = e[$PROXY];
3485
- if (writeOnly(i)) {
3486
- untrack(() => {
3487
- const { base: r, overrideKey: s } = prepareStoreWrite(e, i, t);
3488
- armOptimisticStoreWrite(e, i);
3489
- const o = "value" in n ? { ...n, value: unwrapStoreValue(n.value) } : n;
3490
- Object.defineProperty(e[s] || (e[s] = Object.create(null)), t, o);
3491
- notifyStoreProperty(e, t, "invalidate");
3492
- if (false);
3493
- });
3494
- }
3495
- return true;
3496
- },
3497
- deleteProperty(e, t) {
3498
- if (t === "__proto__") return true;
3499
- const n = e[STORE_OPTIMISTIC_OVERRIDE]?.[t] === $DELETED;
3500
- const i = e[STORE_OVERRIDE]?.[t] === $DELETED;
3501
- if (writeOnly(e[$PROXY]) && !n && !i) {
3502
- untrack(() => {
3503
- const n = e[STORE_OPTIMISTIC] && !projectionWriteActive;
3504
- const i = n ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
3505
- const r = getOverlayLayer(e, t);
3506
- const s = r ? r[t] : e[STORE_VALUE][t];
3507
- if (t in e[STORE_VALUE] || (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE])) {
3508
- armOptimisticStoreWrite(e, e[$PROXY]);
3509
- (e[i] || (e[i] = Object.create(null)))[t] = $DELETED;
3510
- } else if (e[i] && t in e[i]) {
3511
- armOptimisticStoreWrite(e, e[$PROXY]);
3512
- delete e[i][t];
3513
- } else return true;
3514
- notifyStoreProperty(e, t, "delete", undefined, s, true);
3515
- });
3516
- }
3517
- return true;
3518
- },
3519
- ownKeys(e) {
3520
- if (pendingCheckActive) witnessAffectsMark(e);
3521
- if (getObserver() !== e[STORE_FIREWALL]) trackSelf(e);
3522
- let t = getKeys(e[STORE_VALUE], e[STORE_OVERRIDE], false);
3523
- if (e[STORE_OPTIMISTIC_OVERRIDE]) {
3524
- const n = new Set(t);
3525
- for (const t of Reflect.ownKeys(e[STORE_OPTIMISTIC_OVERRIDE])) {
3526
- if (e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED) n.add(t);
3527
- else n.delete(t);
3528
- }
3529
- t = Array.from(n);
3530
- }
3531
- return t;
3532
- },
3533
- getOwnPropertyDescriptor(e, t) {
3534
- if (t === $PROXY) return { value: e[$PROXY], writable: true, configurable: true };
3535
- if (e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]) {
3536
- if (e[STORE_OPTIMISTIC_OVERRIDE][t] === $DELETED) return undefined;
3537
- const n = Reflect.getOwnPropertyDescriptor(e[STORE_OPTIMISTIC_OVERRIDE], t);
3538
- if (n?.get || n?.set || !(t in e[STORE_VALUE])) return n;
3539
- const i = getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
3540
- if (i) {
3541
- const n = Reflect.getOwnPropertyDescriptor(e, t);
3542
- const r = !n || n.configurable ? true : i.configurable;
3543
- return { ...i, configurable: r, value: e[STORE_OPTIMISTIC_OVERRIDE][t] };
3544
- }
3545
- return {
3546
- value: e[STORE_OPTIMISTIC_OVERRIDE][t],
3547
- writable: true,
3548
- enumerable: true,
3549
- configurable: true
3550
- };
3551
- }
3552
- const n = getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
3553
- if (n && !n.configurable) {
3554
- const i = Reflect.getOwnPropertyDescriptor(e, t);
3555
- if (!i || i.configurable) return { ...n, configurable: true };
3556
- }
3557
- return n;
3558
- },
3559
- getPrototypeOf(e) {
3560
- return Object.getPrototypeOf(e[STORE_VALUE]);
3561
- }
3562
- };
3563
- function storeSetter(e, t) {
3564
- const n = Writing;
3565
- Writing = new Set();
3566
- Writing.add(e);
3567
- try {
3568
- const n = t(e);
3569
- if (n !== e && n !== undefined) {
3570
- if (Array.isArray(n)) {
3571
- for (let t = 0, i = n.length; t < i; t++) e[t] = n[t];
3572
- e.length = n.length;
3573
- } else {
3574
- const t = new Set([...ownEnumerableKeys(e), ...ownEnumerableKeys(n)]);
3575
- t.forEach(t => {
3576
- if (t in n) e[t] = n[t];
3577
- else delete e[t];
3578
- });
3579
- }
3580
- }
3581
- } finally {
3582
- Writing.clear();
3583
- Writing = n;
3584
- }
3585
- }
3586
- function createStore(e, t, n) {
3587
- const i = typeof e === "function",
3588
- r = i ? createProjectionInternal(e, t, n).store : wrap(e);
3589
- return [
3590
- r,
3591
- i
3592
- ? e => {
3593
- suppressComputedRecompute(r[$REFRESH]);
3594
- storeSetter(r, e);
3595
- }
3596
- : e => storeSetter(r, e)
3597
- ];
3598
- }
3599
- function affects(e, t) {
3600
- const n = e?.[$TARGET];
3601
- if (n) {
3602
- const e = getStoreAffectsNodes(n, t);
3603
- for (let t = 0; t < e.length; t++) registerAffectsMark(e[t]);
3604
- return;
3605
- }
3606
- const i = e?.[$REFRESH];
3607
- if (i) {
3608
- registerAffectsMark(i);
3609
- return;
3610
- }
3611
- }
3612
- function createOptimisticStore(e, t, n) {
3613
- GlobalQueue.ce ||= clearOptimisticStore;
3614
- const i = typeof e === "function";
3615
- const r = i ? t : e;
3616
- const s = i ? e : undefined;
3617
- const { store: o } = createOptimisticProjectionInternal(s, r, n);
3618
- return [o, e => storeSetter(o, e)];
3619
- }
3620
- function clearOptimisticStore(e) {
3621
- const t = e[$TARGET];
3622
- if (!t?.[STORE_OPTIMISTIC_OVERRIDE]) return;
3623
- clearOptimisticOverride(t);
3624
- }
3625
- function clearOptimisticOverride(e) {
3626
- const t = e[STORE_OPTIMISTIC_OVERRIDE];
3627
- if (!t) return;
3628
- const n = e[STORE_NODE];
3629
- delete e[STORE_OPTIMISTIC_OVERRIDE];
3630
- const i = projectionWriteActive;
3631
- setProjectionWriteActive(true);
3632
- try {
3633
- if (n) {
3634
- for (const i of Reflect.ownKeys(t)) {
3635
- if (n[i]) {
3636
- const t = n[i];
3637
- t.i = undefined;
3638
- const r = getOverlayLayer(e, i);
3639
- const s = r ? r[i] : e[STORE_VALUE][i];
3640
- const o = s === $DELETED ? undefined : s;
3641
- const u = isWrappable(o) ? wrap(o, e) : o;
3642
- const c = visibleNodeValue(t);
3643
- t.p = NOT_PENDING;
3644
- t.m = NOT_PENDING;
3645
- t.B = u;
3646
- if (!t.Ze || !t.Ze(c, u)) {
3647
- insertSubs(t, true);
3648
- schedule();
3649
- }
3650
- }
3651
- }
3652
- if (n[$TRACK]) {
3653
- n[$TRACK].i = undefined;
3654
- notifySelf(e);
3655
- }
3656
- }
3657
- } finally {
3658
- setProjectionWriteActive(i);
3659
- }
3660
- }
3661
- function createOptimisticProjectionInternal(e, t, n) {
3662
- let i;
3663
- const r = new WeakMap();
3664
- const wrapper = e => {
3665
- e[STORE_WRAP] = wrapProjection;
3666
- e[STORE_LOOKUP] = r;
3667
- e[STORE_OPTIMISTIC] = true;
3668
- Object.defineProperty(e, STORE_FIREWALL, {
3669
- get() {
3670
- return i;
3671
- },
3672
- configurable: true
3673
- });
3674
- };
3675
- const wrapProjection = e => {
3676
- if (r.has(e)) return r.get(e);
3677
- if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
3678
- const t = createStoreProxy(e, storeTraps, wrapper);
3679
- r.set(e, t);
3680
- return t;
3681
- };
3682
- const s = wrapProjection(t);
3683
- if (e) {
3684
- const clearProjectionOverride = () => {
3685
- const e = s[$TARGET];
3686
- if (e?.[STORE_OPTIMISTIC_OVERRIDE]) clearOptimisticOverride(e);
3687
- };
3688
- const wrapCommit = e => {
3689
- const t = projectionWriteActive;
3690
- setProjectionWriteActive(true);
3691
- try {
3692
- e();
3693
- clearProjectionOverride();
3694
- } finally {
3695
- setProjectionWriteActive(t);
3696
- }
3697
- };
3698
- i = computed(() => {
3699
- setProjectionWriteActive(true);
3700
- try {
3701
- runProjectionComputed(s, e, n?.key || "id", wrapCommit, clearProjectionOverride);
3702
- } finally {
3703
- setProjectionWriteActive(false);
3704
- }
3705
- }, undefined);
3706
- i.Se &= ~CONFIG_AUTO_DISPOSE;
3707
- }
3708
- return { store: s, node: i };
3709
- }
3710
- const DELETE = Symbol(0);
3711
- function isPrototypePollutionKey(e) {
3712
- return e === "__proto__" || e === "constructor" || e === "prototype";
3713
- }
3714
- function updatePath(e, t, n = 0) {
3715
- let i,
3716
- r = e;
3717
- if (n < t.length - 1) {
3718
- i = t[n];
3719
- const s = typeof i;
3720
- const o = Array.isArray(e);
3721
- if (s === "string" && isPrototypePollutionKey(i)) return;
3722
- if (Array.isArray(i)) {
3723
- for (let r = 0; r < i.length; r++) {
3724
- t[n] = i[r];
3725
- updatePath(e, t, n);
3726
- }
3727
- t[n] = i;
3728
- return;
3729
- } else if (o && s === "function") {
3730
- for (let r = 0; r < e.length; r++) {
3731
- if (i(e[r], r)) {
3732
- t[n] = r;
3733
- updatePath(e, t, n);
3734
- }
3735
- }
3736
- t[n] = i;
3737
- return;
3738
- } else if (o && s === "object") {
3739
- const { from: r = 0, to: s = e.length - 1, by: o = 1 } = i;
3740
- for (let i = r; i <= s; i += o) {
3741
- t[n] = i;
3742
- updatePath(e, t, n);
3743
- }
3744
- t[n] = i;
3745
- return;
3746
- } else if (n < t.length - 2) {
3747
- updatePath(e[i], t, n + 1);
3748
- return;
3749
- }
3750
- r = e[i];
3751
- }
3752
- let s = t[t.length - 1];
3753
- if (typeof s === "function") {
3754
- s = s(r);
3755
- if (s === r) return;
3756
- }
3757
- if (i === undefined && s == undefined) return;
3758
- if (s === DELETE) {
3759
- delete e[i];
3760
- } else if (i === undefined || (isWrappable(r) && isWrappable(s) && !Array.isArray(s))) {
3761
- const t = i !== undefined ? e[i] : e;
3762
- const n = ownEnumerableKeys(s);
3763
- for (let e = 0; e < n.length; e++) {
3764
- const i = n[e];
3765
- if (typeof i === "string" && isPrototypePollutionKey(i)) continue;
3766
- const r = Object.getOwnPropertyDescriptor(s, i);
3767
- if (r.get || r.set) Object.defineProperty(t, i, r);
3768
- else t[i] = r.value;
3769
- }
3770
- } else {
3771
- e[i] = s;
3772
- }
3773
- }
3774
- const storePath = Object.assign(
3775
- function storePath(...e) {
3776
- return t => {
3777
- updatePath(t, e);
3778
- };
3779
- },
3780
- { DELETE: DELETE }
3781
- );
3782
- function snapshotImpl(e, t, n, i) {
3783
- let r, s, o, u, c, a;
3784
- if (!isWrappable(e)) return e;
3785
- if (n && n.has(e)) return n.get(e);
3786
- if (!n) n = new Map();
3787
- if ((r = e[$TARGET] || i?.get(e)?.[$TARGET])) {
3788
- if (t) {
3789
- trackSelf(r, $TRACK);
3790
- if (pendingCheckActive) witnessAffectsMark(r);
3791
- }
3792
- o = mergedOverlay(r);
3793
- s = Array.isArray(r[STORE_VALUE]);
3794
- n.set(
3795
- e,
3796
- o ? (u = s ? [] : Object.create(Object.getPrototypeOf(r[STORE_VALUE]))) : r[STORE_VALUE]
3797
- );
3798
- e = r[STORE_VALUE];
3799
- i = r[STORE_LOOKUP] ?? storeLookup;
3800
- } else {
3801
- s = Array.isArray(e);
3802
- n.set(e, e);
3803
- }
3804
- if (s) {
3805
- const s = o?.length ?? e.length;
3806
- for (let l = 0; l < s; l++) {
3807
- a = o && l in o ? o[l] : e[l];
3808
- if (a === $DELETED) continue;
3809
- if (t && isWrappable(a)) wrap(a, r);
3810
- if ((c = snapshotImpl(a, t, n, i)) !== a || u) {
3811
- if (!u) n.set(e, (u = [...e]));
3812
- u[l] = c;
3813
- }
3814
- }
3815
- if (u) u.length = s;
3816
- } else if (!o) {
3817
- const s = getKeys(e, undefined);
3818
- for (let o = 0, l = s.length; o < l; o++) {
3819
- const l = s[o];
3820
- const f = Object.getOwnPropertyDescriptor(e, l);
3821
- if (f.get) continue;
3822
- a = f.value;
3823
- if (t && isWrappable(a)) wrap(a, r);
3824
- if ((c = snapshotImpl(a, t, n, i)) !== a || u) {
3825
- if (!u) {
3826
- u = Object.create(Object.getPrototypeOf(e));
3827
- Object.assign(u, e);
3828
- }
3829
- u[l] = c;
3830
- }
3831
- }
3832
- } else {
3833
- const s = getKeys(e, o);
3834
- for (let l = 0, f = s.length; l < f; l++) {
3835
- let f = s[l];
3836
- const E = getPropertyDescriptor(e, o, f);
3837
- if (E.get) continue;
3838
- a = f in o ? o[f] : e[f];
3839
- if (t && isWrappable(a)) wrap(a, r);
3840
- if ((c = snapshotImpl(a, t, n, i)) !== e[f] || u) {
3841
- if (!u) {
3842
- u = Object.create(Object.getPrototypeOf(e));
3843
- Object.assign(u, e);
3844
- }
3845
- u[f] = c;
3846
- }
3847
- }
3848
- }
3849
- return u || e;
3850
- }
3851
- function snapshot(e, t, n) {
3852
- return snapshotImpl(e, false, t, n);
3853
- }
3854
- function deep(e) {
3855
- return snapshotImpl(e, true);
3856
- }
3857
- function trueFn() {
3858
- return true;
3859
- }
3860
- const propTraps = {
3861
- get(e, t, n) {
3862
- if (t === $PROXY) return n;
3863
- return e.get(t);
3864
- },
3865
- has(e, t) {
3866
- if (t === $PROXY) return true;
3867
- return e.has(t);
3868
- },
3869
- set: trueFn,
3870
- deleteProperty: trueFn,
3871
- getOwnPropertyDescriptor(e, t) {
3872
- return {
3873
- configurable: true,
3874
- enumerable: true,
3875
- get() {
3876
- return e.get(t);
3877
- },
3878
- set: trueFn,
3879
- deleteProperty: trueFn
3880
- };
3881
- },
3882
- ownKeys(e) {
3883
- return e.keys();
3884
- }
3885
- };
3886
- function resolveSource(e) {
3887
- return !(e = typeof e === "function" ? e() : e) ? {} : e;
3888
- }
3889
- const $SOURCES = Symbol(0);
3890
- function merge(...e) {
3891
- if (e.length === 1 && typeof e[0] !== "function") return e[0];
3892
- let t = false;
3893
- const n = [];
3894
- for (let i = 0; i < e.length; i++) {
3895
- const r = e[i];
3896
- t = t || (!!r && $PROXY in r);
3897
- const s = !!r && r[$SOURCES];
3898
- if (s) {
3899
- for (let e = 0; e < s.length; e++) n.push(s[e]);
3900
- } else n.push(typeof r === "function" ? ((t = true), createMemo(r)) : r);
3901
- }
3902
- if (SUPPORTS_PROXY && t) {
3903
- return new Proxy(
3904
- {
3905
- get(e) {
3906
- if (e === $SOURCES) return n;
3907
- for (let t = n.length - 1; t >= 0; t--) {
3908
- const i = resolveSource(n[t]);
3909
- if (e in i) return i[e];
3910
- }
3911
- },
3912
- has(e) {
3913
- for (let t = n.length - 1; t >= 0; t--) {
3914
- if (e in resolveSource(n[t])) return true;
3915
- }
3916
- return false;
3917
- },
3918
- keys() {
3919
- const e = new Set();
3920
- for (let t = 0; t < n.length; t++) {
3921
- const i = ownEnumerableKeys(resolveSource(n[t]));
3922
- for (let t = 0; t < i.length; t++) e.add(i[t]);
3923
- }
3924
- return [...e];
3925
- }
3926
- },
3927
- propTraps
3928
- );
3929
- }
3930
- const i = Object.create(null);
3931
- let r = false;
3932
- let s = n.length - 1;
3933
- for (let e = s; e >= 0; e--) {
3934
- const t = n[e];
3935
- if (!t) {
3936
- e === s && s--;
3937
- continue;
3938
- }
3939
- const o = Object.getOwnPropertyNames(t);
3940
- for (let n = o.length - 1; n >= 0; n--) {
3941
- const u = o[n];
3942
- if (u === "__proto__" || u === "constructor") continue;
3943
- if (!i[u]) {
3944
- r = r || e !== s;
3945
- const n = Object.getOwnPropertyDescriptor(t, u);
3946
- i[u] = n.get ? { enumerable: true, configurable: true, get: n.get.bind(t) } : n;
3947
- }
3948
- }
3949
- }
3950
- if (!r) return n[s];
3951
- const o = {};
3952
- const u = Object.keys(i);
3953
- for (let e = u.length - 1; e >= 0; e--) {
3954
- const t = u[e],
3955
- n = i[t];
3956
- if (n.get) Object.defineProperty(o, t, n);
3957
- else o[t] = n.value;
3958
- }
3959
- o[$SOURCES] = n;
3960
- return o;
3961
- }
3962
- function omit(e, ...t) {
3963
- if (SUPPORTS_PROXY && $PROXY in e) {
3964
- return new Proxy(
3965
- {
3966
- get(n) {
3967
- return t.includes(n) ? undefined : e[n];
3968
- },
3969
- has(n) {
3970
- return !t.includes(n) && n in e;
3971
- },
3972
- keys() {
3973
- return ownEnumerableKeys(e).filter(e => !t.includes(e));
3974
- }
3975
- },
3976
- propTraps
3977
- );
3978
- }
3979
- const n = {};
3980
- const i = Object.getOwnPropertyNames(e);
3981
- const r = t.length > 4 && i.length > t.length ? new Set(t) : undefined;
3982
- for (const s of i) {
3983
- if (r ? !r.has(s) : !t.includes(s)) {
3984
- const t = Object.getOwnPropertyDescriptor(e, s);
3985
- !t.get && !t.set && t.enumerable && t.writable && t.configurable
3986
- ? (n[s] = t.value)
3987
- : Object.defineProperty(n, s, t);
3988
- }
3989
- }
3990
- return n;
3991
- }
3992
- function mapArray(e, t, n) {
3993
- const i = typeof n?.keyed === "function" ? n.keyed : undefined;
3994
- const r = t.length > 1;
3995
- const s = t;
3996
- const o = {
3997
- st: createOwner(),
3998
- ot: 0,
3999
- ut: e,
4000
- ct: [],
4001
- lt: s,
4002
- ft: [],
4003
- Et: [],
4004
- dt: i,
4005
- St: i || n?.keyed === false ? [] : undefined,
4006
- Tt: r && n?.keyed !== false ? [] : undefined,
4007
- _t: n?.keyed === false,
4008
- Ot: n?.fallback
4009
- };
4010
- const u = computed(updateKeyedMap.bind(o));
4011
- o.st.De = u;
4012
- u.Se &= ~CONFIG_AUTO_DISPOSE;
4013
- return accessor(u);
4014
- }
4015
- const pureOptions = { ownedWrite: true };
4016
- function updateKeyedMap() {
4017
- const e = this.ut() || [],
4018
- t = e.length;
4019
- e[$TRACK];
4020
- runWithOwner(this.st, () => {
4021
- let n,
4022
- i,
4023
- r = this.St
4024
- ? this._t
4025
- ? () => {
4026
- this.St[i] = signal(e[i], pureOptions);
4027
- return this.lt(accessor(this.St[i]), i);
4028
- }
4029
- : () => {
4030
- this.St[i] = signal(e[i], pureOptions);
4031
- this.Tt && (this.Tt[i] = signal(i, pureOptions));
4032
- return this.lt(accessor(this.St[i]), this.Tt ? accessor(this.Tt[i]) : undefined);
4033
- }
4034
- : this.Tt
4035
- ? () => {
4036
- const t = e[i];
4037
- this.Tt[i] = signal(i, pureOptions);
4038
- return this.lt(t, accessor(this.Tt[i]));
4039
- }
4040
- : () => {
4041
- const t = e[i];
4042
- return this.lt(t);
4043
- };
4044
- if (t === 0) {
4045
- if (this.ot !== 0) {
4046
- this.st.dispose(false);
4047
- this.Et = [];
4048
- this.ct = [];
4049
- this.ft = [];
4050
- this.ot = 0;
4051
- this.St && (this.St = []);
4052
- this.Tt && (this.Tt = []);
4053
- }
4054
- if (this.Ot && !this.ft[0]) {
4055
- this.ft[0] = runWithOwner((this.Et[0] = createOwner()), this.Ot);
4056
- }
4057
- } else if (this.ot === 0) {
4058
- if (this.Et[0]) this.Et[0].dispose();
4059
- this.ft = new Array(t);
4060
- for (i = 0; i < t; i++) {
4061
- this.ct[i] = e[i];
4062
- this.ft[i] = runWithOwner((this.Et[i] = createOwner()), r);
4063
- }
4064
- this.ot = t;
4065
- } else {
4066
- let s,
4067
- o,
4068
- u,
4069
- c,
4070
- a,
4071
- l,
4072
- f,
4073
- E = new Array(t),
4074
- d = new Array(t),
4075
- S = this.St ? new Array(t) : undefined,
4076
- T = this.Tt ? new Array(t) : undefined;
4077
- for (
4078
- s = 0, o = Math.min(this.ot, t);
4079
- s < o && (this.ct[s] === e[s] || (this.St && compare(this.dt, this.ct[s], e[s])));
4080
- s++
4081
- ) {
4082
- if (this.St) setSignal(this.St[s], e[s]);
4083
- }
4084
- for (
4085
- o = this.ot - 1, u = t - 1;
4086
- o >= s &&
4087
- u >= s &&
4088
- (this.ct[o] === e[u] || (this.St && compare(this.dt, this.ct[o], e[u])));
4089
- o--, u--
4090
- ) {
4091
- E[u] = this.ft[o];
4092
- d[u] = this.Et[o];
4093
- S && (S[u] = this.St[o]);
4094
- T && (T[u] = this.Tt[o]);
4095
- }
4096
- l = new Map();
4097
- f = new Array(u + 1);
4098
- for (i = u; i >= s; i--) {
4099
- c = e[i];
4100
- a = this.dt ? this.dt(c) : c;
4101
- n = l.get(a);
4102
- f[i] = n === undefined ? -1 : n;
4103
- l.set(a, i);
4104
- }
4105
- for (n = s; n <= o; n++) {
4106
- c = this.ct[n];
4107
- a = this.dt ? this.dt(c) : c;
4108
- i = l.get(a);
4109
- if (i !== undefined && i !== -1) {
4110
- E[i] = this.ft[n];
4111
- d[i] = this.Et[n];
4112
- S && (S[i] = this.St[n]);
4113
- T && (T[i] = this.Tt[n]);
4114
- i = f[i];
4115
- l.set(a, i);
4116
- } else this.Et[n].dispose();
4117
- }
4118
- for (i = s; i < t; i++) {
4119
- if (i in E) {
4120
- this.ft[i] = E[i];
4121
- this.Et[i] = d[i];
4122
- if (S) {
4123
- this.St[i] = S[i];
4124
- setSignal(this.St[i], e[i]);
4125
- }
4126
- if (T) {
4127
- this.Tt[i] = T[i];
4128
- setSignal(this.Tt[i], i);
4129
- }
4130
- } else {
4131
- this.ft[i] = runWithOwner((this.Et[i] = createOwner()), r);
4132
- }
4133
- }
4134
- this.ft = this.ft.slice(0, (this.ot = t));
4135
- this.ct = e.slice(0);
4136
- }
4137
- });
4138
- return this.ft;
4139
- }
4140
- function repeat(e, t, n) {
4141
- const i = t;
4142
- const r = computed(
4143
- updateRepeat.bind({
4144
- st: createOwner(),
4145
- ot: 0,
4146
- Rt: 0,
4147
- It: e,
4148
- lt: i,
4149
- Et: [],
4150
- ft: [],
4151
- At: n?.from,
4152
- Ot: n?.fallback
4153
- })
4154
- );
4155
- r.Se &= ~CONFIG_AUTO_DISPOSE;
4156
- return accessor(r);
4157
- }
4158
- function updateRepeat() {
4159
- const e = this.It();
4160
- const t = this.At?.() || 0;
4161
- runWithOwner(this.st, () => {
4162
- if (e === 0) {
4163
- if (this.ot !== 0) {
4164
- this.st.dispose(false);
4165
- this.Et = [];
4166
- this.ft = [];
4167
- this.ot = 0;
4168
- this.Rt = 0;
4169
- }
4170
- if (this.Ot && !this.ft[0]) {
4171
- this.ft[0] = runWithOwner((this.Et[0] = createOwner()), this.Ot);
4172
- }
4173
- return;
4174
- }
4175
- const n = t + e;
4176
- const i = this.Rt + this.ot;
4177
- if (this.ot === 0 && this.Et[0]) this.Et[0].dispose();
4178
- if (t >= i || n <= this.Rt) {
4179
- for (let e = 0; e < this.ot; e++) this.Et[e].dispose();
4180
- this.Et = new Array(e);
4181
- this.ft = new Array(e);
4182
- for (let n = 0; n < e; n++)
4183
- this.ft[n] = runWithOwner((this.Et[n] = createOwner()), () => this.lt(t + n));
4184
- this.Rt = t;
4185
- this.ot = e;
4186
- return;
4187
- }
4188
- for (let e = n; e < i; e++) this.Et[e - this.Rt].dispose();
4189
- if (this.Rt < t) {
4190
- const e = t - this.Rt;
4191
- for (let t = 0; t < e && t < this.ot; t++) this.Et[t].dispose();
4192
- this.Et.splice(0, e);
4193
- this.ft.splice(0, e);
4194
- } else if (this.Rt > t) {
4195
- let n = i - this.Rt - 1;
4196
- let r = this.Rt - t;
4197
- this.Et.length = this.ft.length = e;
4198
- while (n >= r) {
4199
- this.Et[n] = this.Et[n - r];
4200
- this.ft[n] = this.ft[n - r];
4201
- n--;
4202
- }
4203
- for (let e = 0; e < r; e++) {
4204
- this.ft[e] = runWithOwner((this.Et[e] = createOwner()), () => this.lt(e + t));
4205
- }
4206
- }
4207
- for (let e = i; e < n; e++) {
4208
- this.ft[e - t] = runWithOwner((this.Et[e - t] = createOwner()), () => this.lt(e));
4209
- }
4210
- this.ft = this.ft.slice(0, e);
4211
- this.Rt = t;
4212
- this.ot = e;
4213
- });
4214
- return this.ft;
4215
- }
4216
- function compare(e, t, n) {
4217
- return e ? e(t) === e(n) : true;
4218
- }
4219
- function boundaryComputed(e, t) {
4220
- const n = computed(e, { lazy: true });
4221
- n.Be = (e, t) => {
4222
- const i = e !== undefined ? e : n.q;
4223
- const r = t !== undefined ? t : n.Te;
4224
- n.q &= ~n.ht;
4225
- n.W.notify(n, STATUS_PENDING | STATUS_ERROR, i, r);
4226
- const s = i & ~n.ht & (STATUS_PENDING | STATUS_ERROR);
4227
- if (s) {
4228
- n.q &= ~s;
4229
- if (n.Te === r && !(n.q & (STATUS_PENDING | STATUS_ERROR))) n.Te = undefined;
4230
- }
4231
- };
4232
- n.ht = t;
4233
- n.Se &= ~CONFIG_AUTO_DISPOSE;
4234
- recompute(n, true);
4235
- return n;
4236
- }
4237
- function createBoundChildren(e, t, n, i) {
4238
- const r = e.W;
4239
- r.addChild((e.W = n));
4240
- cleanup(() => r.removeChild(e.W));
4241
- return runWithOwner(e, () => {
4242
- const e = computed(t);
4243
- return boundaryComputed(() => flatten(read(e)), i);
4244
- });
4245
- }
4246
- const ON_INIT = Symbol();
4247
- const RevealControllerContext = createContext(null);
4248
- let _revealUsed = false;
4249
- const FALSE_ACCESSOR = () => false;
4250
- const SEQUENTIAL_ACCESSOR = () => "sequential";
4251
- function isRevealController(e) {
4252
- return e instanceof RevealController;
4253
- }
4254
- function isSlotReady(e) {
4255
- return isRevealController(e) ? e.isReady() : e.Nt.size === 0 && !e.Ct;
4256
- }
4257
- function isSlotMinimallyReady(e) {
4258
- return isRevealController(e) ? e.isMinimallyReady() : isSlotReady(e);
4259
- }
4260
- function setSlotState(e, t, n, i) {
4261
- setSignal(e.yt, n);
4262
- setSignal(e.gt, i);
4263
- if (isRevealController(e)) {
4264
- if (!n && e.Pt === t) e.Pt = undefined;
4265
- return e.evaluate(n, i);
4266
- }
4267
- if (!n && e.Dt === t && e.bt) e.Dt = undefined;
4268
- }
4269
- class RevealController {
4270
- vt;
4271
- wt;
4272
- Lt = [];
4273
- Pt;
4274
- yt = signal(false, { ownedWrite: true, tt: true });
4275
- gt = signal(false, { ownedWrite: true, tt: true });
4276
- Vt = true;
4277
- Ut = true;
4278
- kt = false;
4279
- constructor(e, t) {
4280
- this.vt = e;
4281
- this.wt = t;
4282
- }
4283
- Gt(e) {
4284
- for (let t = 0; t < this.Lt.length; t++) {
4285
- const n = this.Lt[t];
4286
- if ((isRevealController(n) ? n.Pt : n.Dt) !== this) continue;
4287
- if (e(n) === false) return false;
4288
- }
4289
- return true;
4290
- }
4291
- isReady() {
4292
- return this.Gt(isSlotReady);
4293
- }
4294
- isMinimallyReady() {
4295
- const e = untrack(this.vt);
4296
- if (e === "together") return this.Gt(isSlotMinimallyReady);
4297
- if (e === "natural") {
4298
- let e = false;
4299
- let t = false;
4300
- this.Gt(n => {
4301
- e = true;
4302
- if (isSlotMinimallyReady(n)) {
4303
- t = true;
4304
- return false;
4305
- }
4306
- });
4307
- return !e || t;
4308
- }
4309
- let t = true;
4310
- this.Gt(e => {
4311
- t = isSlotMinimallyReady(e);
4312
- return false;
4313
- });
4314
- return t;
4315
- }
4316
- register(e) {
4317
- if (this.Lt.includes(e)) return;
4318
- this.Lt.push(e);
4319
- const t = untrack(this.vt);
4320
- (setSignal(e.yt, true), setSignal(e.gt, t === "sequential" ? !!untrack(this.wt) : false));
4321
- untrack(() => this.evaluate());
4322
- }
4323
- unregister(e) {
4324
- const t = this.Lt.indexOf(e);
4325
- if (t >= 0) this.Lt.splice(t, 1);
4326
- untrack(() => this.evaluate());
4327
- }
4328
- evaluate(e, t) {
4329
- if (this.kt) return;
4330
- this.kt = true;
4331
- const n = this.Vt;
4332
- const i = this.Ut;
4333
- try {
4334
- const n = e ?? read(this.yt),
4335
- i = untrack(this.vt),
4336
- r = i === "sequential" && !!untrack(this.wt),
4337
- s = t ?? r;
4338
- if (n) {
4339
- this.Gt(e => setSlotState(e, this, true, s));
4340
- } else if (i === "natural") {
4341
- this.Gt(e => {
4342
- if (isRevealController(e)) {
4343
- setSignal(e.gt, false);
4344
- setSignal(e.yt, false);
4345
- e.evaluate(false, false);
4346
- } else {
4347
- setSlotState(e, this, !isSlotReady(e), false);
4348
- }
4349
- });
4350
- } else if (i === "together") {
4351
- const e = this.Gt(isSlotMinimallyReady);
4352
- this.Gt(t => setSlotState(t, this, !e, false));
4353
- } else {
4354
- let e = false;
4355
- this.Gt(t => {
4356
- if (e) return setSlotState(t, this, true, r);
4357
- if (isSlotReady(t)) return setSlotState(t, this, false, false);
4358
- e = true;
4359
- if (isRevealController(t)) {
4360
- setSignal(t.gt, false);
4361
- setSignal(t.yt, false);
4362
- t.evaluate(false, false);
4363
- } else {
4364
- setSlotState(t, this, true, false);
4365
- }
4366
- });
4367
- }
4368
- } finally {
4369
- this.Vt = this.isReady();
4370
- this.Ut = this.isMinimallyReady();
4371
- this.kt = false;
4372
- }
4373
- if (this.Pt && (n !== this.Vt || i !== this.Ut)) this.Pt.evaluate();
4374
- }
4375
- }
4376
- class CollectionQueue extends Queue {
4377
- Ft;
4378
- Nt = new Set();
4379
- Wt;
4380
- Ct = true;
4381
- yt = signal(false, { ownedWrite: true, tt: true });
4382
- Te;
4383
- gt = signal(false, { ownedWrite: true, tt: true });
4384
- Dt;
4385
- bt = false;
4386
- Mt;
4387
- Ht = ON_INIT;
4388
- constructor(e) {
4389
- super();
4390
- this.Ft = e;
4391
- }
4392
- run(e) {
4393
- if (!e || (read(this.yt) && (!_revealUsed || read(this.gt)))) return;
4394
- return super.run(e);
4395
- }
4396
- notify(e, t, n, i) {
4397
- if (!(t & this.Ft)) return super.notify(e, t, n, i);
4398
- if (this.bt && this.Mt) {
4399
- const e = untrack(() => {
4400
- try {
4401
- return this.Mt();
4402
- } catch {
4403
- return ON_INIT;
4404
- }
4405
- });
4406
- if (e !== this.Ht) {
4407
- this.Ht = e;
4408
- this.bt = false;
4409
- this.Nt.clear();
4410
- }
4411
- }
4412
- if (this.Ft & STATUS_PENDING && this.bt) return super.notify(e, t, n, i);
4413
- if (n & this.Ft) {
4414
- this.Ct = true;
4415
- const t = i?.source || e.Te?.source;
4416
- if (t) {
4417
- const e = this.Nt.size === 0;
4418
- this.Nt.add(t);
4419
- if (e) setSignal(this.yt, true);
4420
- if (this.Ft & STATUS_ERROR) {
4421
- setSignal(this.Te, unwrapStatusError(t.Te));
4422
- }
4423
- }
4424
- }
4425
- t &= ~this.Ft;
4426
- return t ? super.notify(e, t, n, i) : true;
4427
- }
4428
- checkSources() {
4429
- for (const e of this.Nt) {
4430
- if (
4431
- e.H & REACTIVE_DISPOSED ||
4432
- (!(e.q & this.Ft) && !(this.Ft & STATUS_ERROR && e.q & STATUS_PENDING))
4433
- )
4434
- this.Nt.delete(e);
4435
- }
4436
- if (!this.Nt.size) {
4437
- if (this.Ft & STATUS_PENDING && this.Ct && !this.bt && this.Wt) {
4438
- this.Ct = !!(this.Wt.q & this.Ft);
4439
- } else {
4440
- this.Ct = false;
4441
- }
4442
- if (!this.Ct) {
4443
- setSignal(this.yt, false);
4444
- if (this.Mt) {
4445
- try {
4446
- this.Ht = untrack(() => this.Mt());
4447
- } catch {}
4448
- }
4449
- }
4450
- }
4451
- if (_revealUsed) this.Dt?.evaluate();
4452
- }
4453
- }
4454
- function createCollectionBoundary(e, t, n, i) {
4455
- const r = createOwner();
4456
- if (_revealUsed) setContext(RevealControllerContext, null, r);
4457
- const s = new CollectionQueue(e);
4458
- if (e === STATUS_ERROR) s.Te = signal(undefined, { ownedWrite: true, tt: true });
4459
- if (i) s.Mt = i;
4460
- const o = (s.Wt = createBoundChildren(r, t, s, e));
4461
- untrack(() => {
4462
- let t = false;
4463
- try {
4464
- read(o);
4465
- } catch (e) {
4466
- if (e instanceof NotReadyError) t = true;
4467
- else throw e;
4468
- }
4469
- s.Ct = t || !!(o.q & e) || o.Te instanceof NotReadyError;
4470
- });
4471
- const u = _revealUsed && e === STATUS_PENDING ? getContext(RevealControllerContext) : null;
4472
- if (u) {
4473
- s.Dt = u;
4474
- u.register(s);
4475
- cleanup(() => u.unregister(s));
4476
- }
4477
- return accessor(
4478
- computed(
4479
- () => {
4480
- if (!read(s.yt)) {
4481
- const e = read(o);
4482
- if (!untrack(() => read(s.yt))) return ((s.bt = true), e);
4483
- }
4484
- if (_revealUsed && read(s.gt)) return undefined;
4485
- return n(s);
4486
- },
4487
- { tt: true }
4488
- )
4489
- );
4490
- }
4491
- function createLoadingBoundary(e, t, n) {
4492
- return createCollectionBoundary(STATUS_PENDING, e, () => t(), n?.on);
4493
- }
4494
- function createErrorBoundary(e, t) {
4495
- return createCollectionBoundary(STATUS_ERROR, e, e =>
4496
- t(accessor(e.Te), () => {
4497
- for (const t of e.Nt) recompute(t);
4498
- schedule();
4499
- })
4500
- );
4501
- }
4502
- function createRevealOrder(e, t) {
4503
- _revealUsed = true;
4504
- const n = createOwner();
4505
- const i = getContext(RevealControllerContext);
4506
- const r = t?.order || SEQUENTIAL_ACCESSOR,
4507
- s = t?.collapsed || FALSE_ACCESSOR;
4508
- const o = new RevealController(r, s);
4509
- setContext(RevealControllerContext, o, n);
4510
- return runWithOwner(n, () => {
4511
- const t = e();
4512
- computed(() => {
4513
- r();
4514
- s();
4515
- o.evaluate();
4516
- });
4517
- if (i) {
4518
- o.Pt = i;
4519
- i.register(o);
4520
- cleanup(() => i.unregister(o));
4521
- }
4522
- return t;
4523
- });
4524
- }
4525
- function flatten(e, t) {
4526
- if (typeof e === "function" && !e.length) {
4527
- if (t?.doNotUnwrap) return e;
4528
- do {
4529
- e = e();
4530
- } while (typeof e === "function" && !e.length);
4531
- }
4532
- if (t?.skipNonRendered && (e == null || e === true || e === false || e === "")) return;
4533
- if (Array.isArray(e)) {
4534
- let n = [];
4535
- if (flattenArray(e, n, t)) {
4536
- return () => {
4537
- let e = [];
4538
- flattenArray(n, e, { ...t, doNotUnwrap: false });
4539
- return e;
4540
- };
4541
- }
4542
- return n;
4543
- }
4544
- return e;
4545
- }
4546
- function flattenArray(e, t = [], n) {
4547
- let i = null;
4548
- let r = false;
4549
- for (let s = 0; s < e.length; s++) {
4550
- try {
4551
- let i = e[s];
4552
- if (typeof i === "function" && !i.length) {
4553
- if (n?.doNotUnwrap) {
4554
- t.push(i);
4555
- r = true;
4556
- continue;
4557
- }
4558
- do {
4559
- i = i();
4560
- } while (typeof i === "function" && !i.length);
4561
- }
4562
- if (Array.isArray(i)) {
4563
- r = flattenArray(i, t, n);
4564
- } else if (n?.skipNonRendered && (i == null || i === true || i === false || i === "")) {
4565
- } else t.push(i);
4566
- } catch (e) {
4567
- if (!(e instanceof NotReadyError)) throw e;
4568
- i = e;
4569
- }
4570
- }
4571
- if (i) throw i;
4572
- return r;
4573
- }
4574
- const DEV = undefined;
4575
- export {
4576
- $PROXY,
4577
- $REFRESH,
4578
- $TARGET,
4579
- $TRACK,
4580
- ContextNotFoundError,
4581
- DEV,
4582
- NoOwnerError,
4583
- NotReadyError,
4584
- SUPPORTS_PROXY,
4585
- action,
4586
- affects,
4587
- clearSnapshots,
4588
- createContext,
4589
- createEffect,
4590
- createErrorBoundary,
4591
- createLoadingBoundary,
4592
- createMemo,
4593
- createOptimistic,
4594
- createOptimisticStore,
4595
- createOwner,
4596
- createProjection,
4597
- createReaction,
4598
- createRenderEffect,
4599
- createRevealOrder,
4600
- createRoot,
4601
- createSignal,
4602
- createStore,
4603
- createTrackedEffect,
4604
- deep,
4605
- enableExternalSource,
4606
- enforceLoadingBoundary,
4607
- flatten,
4608
- flush,
4609
- getContext,
4610
- getNextChildId,
4611
- getObserver,
4612
- getOwner,
4613
- isDisposed,
4614
- isEqual,
4615
- isPending,
4616
- isWrappable,
4617
- latest,
4618
- mapArray,
4619
- markSnapshotScope,
4620
- merge,
4621
- omit,
4622
- onCleanup,
4623
- onSettled,
4624
- peekNextChildId,
4625
- reconcile,
4626
- refresh,
4627
- releaseSnapshotScope,
4628
- repeat,
4629
- resetErrorHalt,
4630
- resolve,
4631
- runWithOwner,
4632
- setContext,
4633
- setSnapshotCapture,
4634
- snapshot,
4635
- storePath,
4636
- untrack
4637
- };