@solidjs/signals 2.0.0-beta.8 → 2.0.0-rc.0

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 (95) hide show
  1. package/README.md +13 -9
  2. package/dist/dev.js +6078 -1440
  3. package/dist/node.cjs +7684 -3248
  4. package/dist/prod/affects.js +126 -0
  5. package/dist/prod/boundaries.js +572 -0
  6. package/dist/prod/core/action.js +139 -0
  7. package/dist/prod/core/async.js +553 -0
  8. package/dist/prod/core/constants.js +92 -0
  9. package/dist/prod/core/context.js +67 -0
  10. package/dist/prod/core/core.js +817 -0
  11. package/dist/prod/core/dev.js +3 -0
  12. package/dist/prod/core/effect.js +145 -0
  13. package/dist/prod/core/error.js +68 -0
  14. package/dist/prod/core/external.js +98 -0
  15. package/dist/prod/core/graph.js +104 -0
  16. package/dist/prod/core/heap.js +140 -0
  17. package/dist/prod/core/invariants.js +42 -0
  18. package/dist/prod/core/lanes.js +140 -0
  19. package/dist/prod/core/optimistic.js +245 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +749 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +317 -0
  25. package/dist/prod/signals.js +375 -0
  26. package/dist/prod/store/optimistic.js +217 -0
  27. package/dist/prod/store/projection.js +231 -0
  28. package/dist/prod/store/reconcile.js +707 -0
  29. package/dist/prod/store/store.js +1081 -0
  30. package/dist/prod/store/storePath.js +103 -0
  31. package/dist/prod/store/utils.js +328 -0
  32. package/dist/types/affects.d.ts +47 -0
  33. package/dist/types/boundaries.d.ts +93 -11
  34. package/dist/types/core/action.d.ts +63 -0
  35. package/dist/types/core/async.d.ts +16 -1
  36. package/dist/types/core/constants.d.ts +46 -0
  37. package/dist/types/core/context.d.ts +10 -2
  38. package/dist/types/core/core.d.ts +111 -17
  39. package/dist/types/core/dev.d.ts +17 -2
  40. package/dist/types/core/effect.d.ts +1 -2
  41. package/dist/types/core/error.d.ts +33 -0
  42. package/dist/types/core/external.d.ts +0 -11
  43. package/dist/types/core/graph.d.ts +2 -1
  44. package/dist/types/core/heap.d.ts +8 -0
  45. package/dist/types/core/index.d.ts +3 -2
  46. package/dist/types/core/invariants.d.ts +59 -0
  47. package/dist/types/core/lanes.d.ts +2 -0
  48. package/dist/types/core/optimistic.d.ts +6 -0
  49. package/dist/types/core/owner.d.ts +101 -3
  50. package/dist/types/core/scheduler.d.ts +97 -9
  51. package/dist/types/core/types.d.ts +68 -6
  52. package/dist/types/core/verdict.d.ts +2 -0
  53. package/dist/types/index.d.ts +4 -3
  54. package/dist/types/map.d.ts +50 -5
  55. package/dist/types/signals.d.ts +424 -19
  56. package/dist/types/store/index.d.ts +1 -1
  57. package/dist/types/store/optimistic.d.ts +39 -13
  58. package/dist/types/store/projection.d.ts +48 -18
  59. package/dist/types/store/reconcile.d.ts +46 -1
  60. package/dist/types/store/store.d.ts +164 -19
  61. package/dist/types/store/storePath.d.ts +28 -0
  62. package/dist/types/store/utils.d.ts +78 -7
  63. package/dist/types-cjs/affects.d.cts +47 -0
  64. package/dist/types-cjs/boundaries.d.cts +93 -11
  65. package/dist/types-cjs/core/action.d.cts +63 -0
  66. package/dist/types-cjs/core/async.d.cts +16 -1
  67. package/dist/types-cjs/core/constants.d.cts +46 -0
  68. package/dist/types-cjs/core/context.d.cts +10 -2
  69. package/dist/types-cjs/core/core.d.cts +111 -17
  70. package/dist/types-cjs/core/dev.d.cts +17 -2
  71. package/dist/types-cjs/core/effect.d.cts +1 -2
  72. package/dist/types-cjs/core/error.d.cts +33 -0
  73. package/dist/types-cjs/core/external.d.cts +0 -11
  74. package/dist/types-cjs/core/graph.d.cts +2 -1
  75. package/dist/types-cjs/core/heap.d.cts +8 -0
  76. package/dist/types-cjs/core/index.d.cts +3 -2
  77. package/dist/types-cjs/core/invariants.d.cts +59 -0
  78. package/dist/types-cjs/core/lanes.d.cts +2 -0
  79. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  80. package/dist/types-cjs/core/owner.d.cts +101 -3
  81. package/dist/types-cjs/core/scheduler.d.cts +97 -9
  82. package/dist/types-cjs/core/types.d.cts +68 -6
  83. package/dist/types-cjs/core/verdict.d.cts +2 -0
  84. package/dist/types-cjs/index.d.cts +4 -3
  85. package/dist/types-cjs/map.d.cts +50 -5
  86. package/dist/types-cjs/signals.d.cts +424 -19
  87. package/dist/types-cjs/store/index.d.cts +1 -1
  88. package/dist/types-cjs/store/optimistic.d.cts +39 -13
  89. package/dist/types-cjs/store/projection.d.cts +48 -18
  90. package/dist/types-cjs/store/reconcile.d.cts +46 -1
  91. package/dist/types-cjs/store/store.d.cts +164 -19
  92. package/dist/types-cjs/store/storePath.d.cts +28 -0
  93. package/dist/types-cjs/store/utils.d.cts +78 -7
  94. package/package.json +14 -11
  95. package/dist/prod.js +0 -3577
package/dist/prod.js DELETED
@@ -1,3577 +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
- class NoOwnerError extends Error {
16
- constructor() {
17
- super("");
18
- }
19
- }
20
- class ContextNotFoundError extends Error {
21
- constructor() {
22
- super("");
23
- }
24
- }
25
- const REACTIVE_NONE = 0;
26
- const REACTIVE_CHECK = 1 << 0;
27
- const REACTIVE_DIRTY = 1 << 1;
28
- const REACTIVE_RECOMPUTING_DEPS = 1 << 2;
29
- const REACTIVE_IN_HEAP = 1 << 3;
30
- const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
31
- const REACTIVE_ZOMBIE = 1 << 5;
32
- const REACTIVE_DISPOSED = 1 << 6;
33
- const REACTIVE_OPTIMISTIC_DIRTY = 1 << 7;
34
- const REACTIVE_SNAPSHOT_STALE = 1 << 8;
35
- const REACTIVE_LAZY = 1 << 9;
36
- const STATUS_PENDING = 1 << 0;
37
- const STATUS_ERROR = 1 << 1;
38
- const STATUS_UNINITIALIZED = 1 << 2;
39
- const EFFECT_RENDER = 1;
40
- const EFFECT_USER = 2;
41
- const EFFECT_TRACKED = 3;
42
- const NOT_PENDING = {};
43
- const NO_SNAPSHOT = {};
44
- const STORE_SNAPSHOT_PROPS = "sp";
45
- const SUPPORTS_PROXY = typeof Proxy === "function";
46
- const defaultContext = {};
47
- const $REFRESH = Symbol("refresh");
48
- function actualInsertIntoHeap(e, t) {
49
- const n = (e.i?.t ? e.i.u?.o : e.i?.o) ?? -1;
50
- if (n >= e.o) e.o = n + 1;
51
- const i = e.o;
52
- const r = t.l[i];
53
- if (r === undefined) t.l[i] = e;
54
- else {
55
- const t = r.T;
56
- t.S = e;
57
- e.T = t;
58
- r.T = e;
59
- }
60
- if (i > t.R) t.R = i;
61
- }
62
- function insertIntoHeap(e, t) {
63
- let n = e.O;
64
- if (n & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS)) return;
65
- if (n & REACTIVE_CHECK) {
66
- e.O = (n & -4) | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
67
- } else e.O = n | REACTIVE_IN_HEAP;
68
- if (!(n & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
69
- }
70
- function insertIntoHeapHeight(e, t) {
71
- let n = e.O;
72
- if (n & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT)) return;
73
- e.O = n | REACTIVE_IN_HEAP_HEIGHT;
74
- actualInsertIntoHeap(e, t);
75
- }
76
- function deleteFromHeap(e, t) {
77
- const n = e.O;
78
- if (!(n & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
79
- e.O = n & -25;
80
- const i = e.o;
81
- if (e.T === e) t.l[i] = undefined;
82
- else {
83
- const n = e.S;
84
- const r = t.l[i];
85
- const s = n ?? r;
86
- if (e === r) t.l[i] = n;
87
- else e.T.S = n;
88
- s.T = e.T;
89
- }
90
- e.T = e;
91
- e.S = undefined;
92
- }
93
- function markHeap(e) {
94
- if (e._) return;
95
- e._ = true;
96
- for (let t = 0; t <= e.R; t++) {
97
- for (let n = e.l[t]; n !== undefined; n = n.S) {
98
- if (n.O & REACTIVE_IN_HEAP) markNode(n);
99
- }
100
- }
101
- }
102
- function markNode(e, t = REACTIVE_DIRTY) {
103
- const n = e.O;
104
- if ((n & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
105
- e.O = (n & -4) | t;
106
- for (let t = e.I; t !== null; t = t.h) {
107
- markNode(t.p, REACTIVE_CHECK);
108
- }
109
- if (e.A !== null) {
110
- for (let t = e.A; t !== null; t = t.N) {
111
- for (let e = t.I; e !== null; e = e.h) {
112
- markNode(e.p, REACTIVE_CHECK);
113
- }
114
- }
115
- }
116
- }
117
- function runHeap(e, t) {
118
- e._ = false;
119
- for (e.P = 0; e.P <= e.R; e.P++) {
120
- let n = e.l[e.P];
121
- while (n !== undefined) {
122
- if (n.O & REACTIVE_IN_HEAP) t(n);
123
- else adjustHeight(n, e);
124
- n = e.l[e.P];
125
- }
126
- }
127
- e.R = 0;
128
- }
129
- function adjustHeight(e, t) {
130
- deleteFromHeap(e, t);
131
- let n = e.o;
132
- for (let t = e.C; t; t = t.D) {
133
- const e = t.m;
134
- const i = e.V || e;
135
- if (i.L && i.o >= n) n = i.o + 1;
136
- }
137
- if (e.o !== n) {
138
- e.o = n;
139
- for (let n = e.I; n !== null; n = n.h) {
140
- insertIntoHeapHeight(n.p, t);
141
- }
142
- }
143
- }
144
- const DEV$1 = undefined;
145
- const transitions = new Set();
146
- const dirtyQueue = { l: new Array(2e3).fill(undefined), _: false, P: 0, R: 0 };
147
- const zombieQueue = { l: new Array(2e3).fill(undefined), _: false, P: 0, R: 0 };
148
- let clock = 0;
149
- let activeTransition = null;
150
- let scheduled = false;
151
- let projectionWriteActive = false;
152
- let stashedOptimisticReads = null;
153
- const transientStoreNodes = new Set();
154
- function registerTransientStoreNode(e) {
155
- transientStoreNodes.add(e);
156
- }
157
- function sweepTransientStoreNodes() {
158
- if (transientStoreNodes.size === 0) return;
159
- for (const e of transientStoreNodes) {
160
- if (e.I !== null) {
161
- transientStoreNodes.delete(e);
162
- continue;
163
- }
164
- if (e.U !== NOT_PENDING) continue;
165
- if (e.k !== undefined && e.k !== NOT_PENDING) continue;
166
- transientStoreNodes.delete(e);
167
- e.G?.();
168
- }
169
- }
170
- function enforceLoadingBoundary(e) {}
171
- function shouldReadStashedOptimisticValue(e) {
172
- return !!stashedOptimisticReads?.has(e);
173
- }
174
- function runLaneEffects(e) {
175
- for (const t of activeLanes) {
176
- if (t.W || t.H.size > 0) continue;
177
- const n = t.M[e - 1];
178
- if (n.length) {
179
- t.M[e - 1] = [];
180
- runQueue(n, e);
181
- }
182
- }
183
- }
184
- function queueStashedOptimisticEffects(e) {
185
- for (let t = e.I; t !== null; t = t.h) {
186
- const e = t.p;
187
- if (!e.F) continue;
188
- if (e.F === EFFECT_TRACKED) {
189
- if (!e.j) {
190
- e.j = true;
191
- e.$.enqueue(EFFECT_USER, e.K);
192
- }
193
- continue;
194
- }
195
- const n = e.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
196
- if (n.P > e.o) n.P = e.o;
197
- insertIntoHeap(e, n);
198
- }
199
- }
200
- function setProjectionWriteActive(e) {
201
- projectionWriteActive = e;
202
- }
203
- function mergeTransitionState(e, t) {
204
- t.Y = e;
205
- e.Z.push(...t.Z);
206
- for (const n of activeLanes) if (n.B === t) n.B = e;
207
- e.q.push(...t.q);
208
- for (const n of t.X) e.X.add(n);
209
- for (const [n, i] of t.J) {
210
- let t = e.J.get(n);
211
- if (!t) e.J.set(n, (t = new Set()));
212
- for (const e of i) t.add(e);
213
- }
214
- }
215
- function resolveOptimisticNodes(e) {
216
- for (let t = 0; t < e.length; t++) {
217
- const n = e[t];
218
- n.ee = undefined;
219
- if (n.U !== NOT_PENDING) {
220
- n.te = n.U;
221
- n.U = NOT_PENDING;
222
- }
223
- const i = n.k;
224
- n.k = NOT_PENDING;
225
- if (i !== NOT_PENDING && n.te !== i) insertSubs(n, true);
226
- n.B = null;
227
- }
228
- e.length = 0;
229
- }
230
- function cleanupCompletedLanes(e) {
231
- for (const t of activeLanes) {
232
- const n = e ? t.B === e : !t.B;
233
- if (!n) continue;
234
- if (!t.W) {
235
- if (t.M[0].length) runQueue(t.M[0], EFFECT_RENDER);
236
- if (t.M[1].length) runQueue(t.M[1], EFFECT_USER);
237
- }
238
- if (t.ne.ee === t) t.ne.ee = undefined;
239
- t.H.clear();
240
- t.M[0].length = 0;
241
- t.M[1].length = 0;
242
- activeLanes.delete(t);
243
- signalLanes.delete(t.ne);
244
- }
245
- }
246
- function schedule() {
247
- if (scheduled) return;
248
- scheduled = true;
249
- if (!globalQueue.ie && !projectionWriteActive) queueMicrotask(flush);
250
- }
251
- class Queue {
252
- i = null;
253
- re = [[], []];
254
- se = [];
255
- created = clock;
256
- addChild(e) {
257
- this.se.push(e);
258
- e.i = this;
259
- }
260
- removeChild(e) {
261
- const t = this.se.indexOf(e);
262
- if (t >= 0) {
263
- this.se.splice(t, 1);
264
- e.i = null;
265
- }
266
- }
267
- notify(e, t, n, i) {
268
- if (this.i) return this.i.notify(e, t, n, i);
269
- return false;
270
- }
271
- run(e) {
272
- if (this.re[e - 1].length) {
273
- const t = this.re[e - 1];
274
- this.re[e - 1] = [];
275
- runQueue(t, e);
276
- }
277
- for (let t = 0; t < this.se.length; t++) this.se[t].run?.(e);
278
- }
279
- enqueue(e, t) {
280
- if (e) {
281
- if (currentOptimisticLane) {
282
- const n = findLane(currentOptimisticLane);
283
- n.M[e - 1].push(t);
284
- } else {
285
- this.re[e - 1].push(t);
286
- }
287
- }
288
- schedule();
289
- }
290
- stashQueues(e) {
291
- e.re[0].push(...this.re[0]);
292
- e.re[1].push(...this.re[1]);
293
- this.re = [[], []];
294
- for (let t = 0; t < this.se.length; t++) {
295
- let n = this.se[t];
296
- let i = e.se[t];
297
- if (!i) {
298
- i = { re: [[], []], se: [] };
299
- e.se[t] = i;
300
- }
301
- n.stashQueues(i);
302
- }
303
- }
304
- restoreQueues(e) {
305
- this.re[0].push(...e.re[0]);
306
- this.re[1].push(...e.re[1]);
307
- for (let t = 0; t < e.se.length; t++) {
308
- const n = e.se[t];
309
- let i = this.se[t];
310
- if (i) i.restoreQueues(n);
311
- }
312
- }
313
- }
314
- class GlobalQueue extends Queue {
315
- ie = false;
316
- oe = [];
317
- q = [];
318
- X = new Set();
319
- static ue;
320
- static ce;
321
- static ae = null;
322
- flush() {
323
- if (this.ie) return;
324
- this.ie = true;
325
- try {
326
- runHeap(dirtyQueue, GlobalQueue.ue);
327
- if (activeTransition) {
328
- const e = transitionComplete(activeTransition);
329
- if (!e) {
330
- const e = activeTransition;
331
- runHeap(zombieQueue, GlobalQueue.ue);
332
- this.oe = [];
333
- this.q = [];
334
- this.X = new Set();
335
- runLaneEffects(EFFECT_RENDER);
336
- runLaneEffects(EFFECT_USER);
337
- this.stashQueues(e.le);
338
- clock++;
339
- scheduled = dirtyQueue.R >= dirtyQueue.P;
340
- reassignPendingTransition(e.oe);
341
- activeTransition = null;
342
- if (!e.Z.length && e.q.length) {
343
- stashedOptimisticReads = new Set();
344
- for (let t = 0; t < e.q.length; t++) {
345
- const n = e.q[t];
346
- if (n.L || n.fe) continue;
347
- stashedOptimisticReads.add(n);
348
- queueStashedOptimisticEffects(n);
349
- }
350
- }
351
- try {
352
- finalizePureQueue(null, true);
353
- } finally {
354
- stashedOptimisticReads = null;
355
- }
356
- return;
357
- }
358
- this.oe !== activeTransition.oe && this.oe.push(...activeTransition.oe);
359
- this.restoreQueues(activeTransition.le);
360
- transitions.delete(activeTransition);
361
- const t = activeTransition;
362
- activeTransition = null;
363
- reassignPendingTransition(this.oe);
364
- finalizePureQueue(t);
365
- } else {
366
- if (transitions.size) runHeap(zombieQueue, GlobalQueue.ue);
367
- finalizePureQueue();
368
- }
369
- clock++;
370
- scheduled = dirtyQueue.R >= dirtyQueue.P;
371
- runLaneEffects(EFFECT_RENDER);
372
- this.run(EFFECT_RENDER);
373
- runLaneEffects(EFFECT_USER);
374
- this.run(EFFECT_USER);
375
- if (false);
376
- } finally {
377
- this.ie = false;
378
- }
379
- }
380
- notify(e, t, n, i) {
381
- if (t & STATUS_PENDING) {
382
- if (n & STATUS_PENDING) {
383
- const t = i !== undefined ? i : e.Ee;
384
- if (activeTransition && t) {
385
- const n = t.source;
386
- let i = activeTransition.J.get(n);
387
- if (!i) activeTransition.J.set(n, (i = new Set()));
388
- const r = i.size;
389
- i.add(e);
390
- if (i.size !== r) schedule();
391
- }
392
- }
393
- return true;
394
- }
395
- return false;
396
- }
397
- initTransition(e) {
398
- if (e) e = currentTransition(e);
399
- if (e && e === activeTransition) return;
400
- if (!e && activeTransition && activeTransition.de === clock) return;
401
- if (!activeTransition) {
402
- activeTransition = e ?? {
403
- de: clock,
404
- oe: [],
405
- J: new Map(),
406
- q: [],
407
- X: new Set(),
408
- Z: [],
409
- le: { re: [[], []], se: [] },
410
- Y: false
411
- };
412
- } else if (e) {
413
- const t = activeTransition;
414
- mergeTransitionState(e, t);
415
- transitions.delete(t);
416
- activeTransition = e;
417
- }
418
- transitions.add(activeTransition);
419
- activeTransition.de = clock;
420
- if (this.oe !== activeTransition.oe) {
421
- for (let e = 0; e < this.oe.length; e++) {
422
- const t = this.oe[e];
423
- t.B = activeTransition;
424
- activeTransition.oe.push(t);
425
- }
426
- this.oe = activeTransition.oe;
427
- }
428
- if (this.q !== activeTransition.q) {
429
- for (let e = 0; e < this.q.length; e++) {
430
- const t = this.q[e];
431
- t.B = activeTransition;
432
- activeTransition.q.push(t);
433
- }
434
- this.q = activeTransition.q;
435
- }
436
- for (const e of activeLanes) {
437
- if (!e.B) e.B = activeTransition;
438
- }
439
- if (this.X !== activeTransition.X) {
440
- for (const e of this.X) activeTransition.X.add(e);
441
- this.X = activeTransition.X;
442
- }
443
- }
444
- }
445
- function insertSubs(e, t = false) {
446
- const n = e.ee || currentOptimisticLane;
447
- const i = e.Te !== undefined;
448
- for (let r = e.I; r !== null; r = r.h) {
449
- if (i && r.p.Se) {
450
- r.p.O |= REACTIVE_SNAPSHOT_STALE;
451
- continue;
452
- }
453
- if (t && n) {
454
- r.p.O |= REACTIVE_OPTIMISTIC_DIRTY;
455
- assignOrMergeLane(r.p, n);
456
- } else if (t) {
457
- r.p.O |= REACTIVE_OPTIMISTIC_DIRTY;
458
- r.p.ee = undefined;
459
- }
460
- const e = r.p;
461
- if (e.F === EFFECT_TRACKED) {
462
- if (!e.j) {
463
- e.j = true;
464
- e.$.enqueue(EFFECT_USER, e.K);
465
- }
466
- continue;
467
- }
468
- const s = r.p.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
469
- if (s.P > r.p.o) s.P = r.p.o;
470
- insertIntoHeap(r.p, s);
471
- }
472
- }
473
- function commitPendingNodes() {
474
- const e = globalQueue.oe;
475
- for (let t = 0; t < e.length; t++) {
476
- const n = e[t];
477
- if (n.U !== NOT_PENDING) {
478
- n.te = n.U;
479
- n.U = NOT_PENDING;
480
- if (n.F && n.F !== EFFECT_TRACKED) n.j = true;
481
- }
482
- if (!(n.Re & STATUS_PENDING)) n.Re &= ~STATUS_UNINITIALIZED;
483
- if (n.L) GlobalQueue.ce(n, false, true);
484
- }
485
- e.length = 0;
486
- }
487
- function finalizePureQueue(e = null, t = false) {
488
- const n = !t;
489
- if (n) commitPendingNodes();
490
- if (!t) checkBoundaryChildren(globalQueue);
491
- if (dirtyQueue.R >= dirtyQueue.P) runHeap(dirtyQueue, GlobalQueue.ue);
492
- if (n) {
493
- commitPendingNodes();
494
- resolveOptimisticNodes(e ? e.q : globalQueue.q);
495
- const t = e ? e.X : globalQueue.X;
496
- if (GlobalQueue.ae && t.size) {
497
- for (const e of t) {
498
- GlobalQueue.ae(e);
499
- }
500
- t.clear();
501
- schedule();
502
- }
503
- sweepTransientStoreNodes();
504
- cleanupCompletedLanes(e);
505
- }
506
- }
507
- function checkBoundaryChildren(e) {
508
- for (const t of e.se) {
509
- t.checkSources?.();
510
- checkBoundaryChildren(t);
511
- }
512
- }
513
- function trackOptimisticStore(e) {
514
- globalQueue.X.add(e);
515
- schedule();
516
- }
517
- function reassignPendingTransition(e) {
518
- for (let t = 0; t < e.length; t++) {
519
- e[t].B = activeTransition;
520
- }
521
- }
522
- const globalQueue = new GlobalQueue();
523
- function flush() {
524
- if (globalQueue.ie) {
525
- return;
526
- }
527
- while (scheduled || activeTransition) {
528
- globalQueue.flush();
529
- }
530
- }
531
- function runQueue(e, t) {
532
- for (let n = 0; n < e.length; n++) e[n](t);
533
- }
534
- function reporterBlocksSource(e, t) {
535
- if (e.O & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED)) return false;
536
- if (e.Oe === t || e._e?.has(t)) return true;
537
- for (let n = e.C; n; n = n.D) {
538
- let e = n.m;
539
- while (e) {
540
- if (e === t || e.V === t) return true;
541
- e = e.Ie;
542
- }
543
- }
544
- return !!(e.Re & STATUS_PENDING && e.Ee instanceof NotReadyError && e.Ee.source === t);
545
- }
546
- function transitionComplete(e) {
547
- if (e.Y) return true;
548
- if (e.Z.length) return false;
549
- let t = true;
550
- for (const [n, i] of e.J) {
551
- let r = false;
552
- for (const e of i) {
553
- if (reporterBlocksSource(e, n)) {
554
- r = true;
555
- break;
556
- }
557
- i.delete(e);
558
- }
559
- if (!r) e.J.delete(n);
560
- else if (n.Re & STATUS_PENDING && n.Ee?.source === n) {
561
- t = false;
562
- break;
563
- }
564
- }
565
- if (t) {
566
- for (let n = 0; n < e.q.length; n++) {
567
- const i = e.q[n];
568
- if (
569
- hasActiveOverride(i) &&
570
- "Re" in i &&
571
- i.Re & STATUS_PENDING &&
572
- i.Ee instanceof NotReadyError &&
573
- i.Ee.source !== i
574
- ) {
575
- t = false;
576
- break;
577
- }
578
- }
579
- }
580
- t && (e.Y = true);
581
- return t;
582
- }
583
- function currentTransition(e) {
584
- while (e.Y && typeof e.Y === "object") e = e.Y;
585
- return e;
586
- }
587
- function setActiveTransition(e) {
588
- activeTransition = e;
589
- }
590
- function runInTransition(e, t) {
591
- const n = activeTransition;
592
- try {
593
- activeTransition = currentTransition(e);
594
- return t();
595
- } finally {
596
- activeTransition = n;
597
- }
598
- }
599
- const signalLanes = new WeakMap();
600
- const activeLanes = new Set();
601
- function getOrCreateLane(e) {
602
- let t = signalLanes.get(e);
603
- if (t) {
604
- return findLane(t);
605
- }
606
- const n = e.Ie;
607
- const i = n?.ee ? findLane(n.ee) : null;
608
- t = { ne: e, H: new Set(), M: [[], []], W: null, B: activeTransition, he: i };
609
- signalLanes.set(e, t);
610
- activeLanes.add(t);
611
- e.pe = false;
612
- return t;
613
- }
614
- function findLane(e) {
615
- while (e.W) e = e.W;
616
- return e;
617
- }
618
- function mergeLanes(e, t) {
619
- e = findLane(e);
620
- t = findLane(t);
621
- if (e === t) return e;
622
- t.W = e;
623
- for (const n of t.H) e.H.add(n);
624
- e.M[0].push(...t.M[0]);
625
- e.M[1].push(...t.M[1]);
626
- return e;
627
- }
628
- function resolveLane(e) {
629
- const t = e.ee;
630
- if (!t) return undefined;
631
- const n = findLane(t);
632
- if (activeLanes.has(n)) return n;
633
- e.ee = undefined;
634
- return undefined;
635
- }
636
- function resolveTransition(e) {
637
- return resolveLane(e)?.B ?? e.B;
638
- }
639
- function hasActiveOverride(e) {
640
- return !!(e.k !== undefined && e.k !== NOT_PENDING);
641
- }
642
- function assignOrMergeLane(e, t) {
643
- const n = findLane(t);
644
- const i = e.ee;
645
- if (i) {
646
- if (i.W) {
647
- e.ee = t;
648
- return;
649
- }
650
- const r = findLane(i);
651
- if (activeLanes.has(r)) {
652
- if (r !== n && !hasActiveOverride(e)) {
653
- if (n.he && findLane(n.he) === r) {
654
- e.ee = t;
655
- } else if (r.he && findLane(r.he) === n);
656
- else mergeLanes(n, r);
657
- }
658
- return;
659
- }
660
- }
661
- e.ee = t;
662
- }
663
- function unlinkSubs(e) {
664
- const t = e.m;
665
- const n = e.D;
666
- const i = e.h;
667
- const r = e.Ae;
668
- if (i !== null) i.Ae = r;
669
- else t.Ne = r;
670
- if (r !== null) r.h = i;
671
- else {
672
- t.I = i;
673
- if (i === null) {
674
- t.G?.();
675
- t.L && !t.Pe && !(t.O & REACTIVE_ZOMBIE) && unobserved(t);
676
- }
677
- }
678
- return n;
679
- }
680
- function unobserved(e) {
681
- deleteFromHeap(e, e.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
682
- let t = e.C;
683
- while (t !== null) {
684
- t = unlinkSubs(t);
685
- }
686
- e.C = null;
687
- e.ge = null;
688
- disposeChildren(e, true);
689
- }
690
- function link(e, t) {
691
- const n = t.ge;
692
- if (n !== null && n.m === e) return;
693
- let i = null;
694
- const r = t.O & REACTIVE_RECOMPUTING_DEPS;
695
- if (r) {
696
- i = n !== null ? n.D : t.C;
697
- if (i !== null && i.m === e) {
698
- t.ge = i;
699
- return;
700
- }
701
- }
702
- const s = e.Ne;
703
- if (s !== null && s.p === t && (!r || isValidLink(s, t))) return;
704
- const o = (t.ge = e.Ne = { m: e, p: t, D: i, Ae: s, h: null });
705
- if (n !== null) n.D = o;
706
- else t.C = o;
707
- if (s !== null) s.h = o;
708
- else e.I = o;
709
- }
710
- function isValidLink(e, t) {
711
- const n = t.ge;
712
- if (n !== null) {
713
- let i = t.C;
714
- do {
715
- if (i === e) return true;
716
- if (i === n) break;
717
- i = i.D;
718
- } while (i !== null);
719
- }
720
- return false;
721
- }
722
- const PENDING_OWNER = {};
723
- function markDisposal(e) {
724
- let t = e.Ce;
725
- while (t) {
726
- t.O |= REACTIVE_ZOMBIE;
727
- if (t.O & REACTIVE_IN_HEAP) {
728
- deleteFromHeap(t, dirtyQueue);
729
- insertIntoHeap(t, zombieQueue);
730
- }
731
- markDisposal(t);
732
- t = t.De;
733
- }
734
- }
735
- function dispose(e) {
736
- let t = e.C || null;
737
- do {
738
- t = unlinkSubs(t);
739
- } while (t !== null);
740
- e.C = null;
741
- e.ge = null;
742
- disposeChildren(e, true);
743
- }
744
- function disposeChildren(e, t = false, n) {
745
- if (e.O & REACTIVE_DISPOSED) return;
746
- if (t) e.O = REACTIVE_DISPOSED;
747
- if (t && e.L) e.ye = null;
748
- let i = n ? e.ve : e.Ce;
749
- while (i) {
750
- const e = i.De;
751
- if (i.C) {
752
- const e = i;
753
- deleteFromHeap(e, e.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
754
- let t = e.C;
755
- do {
756
- t = unlinkSubs(t);
757
- } while (t !== null);
758
- e.C = null;
759
- e.ge = null;
760
- }
761
- disposeChildren(i, true);
762
- i = e;
763
- }
764
- if (n) {
765
- e.ve = null;
766
- } else {
767
- e.Ce = null;
768
- e.me = 0;
769
- }
770
- runDisposal(e, n);
771
- }
772
- function runDisposal(e, t) {
773
- let n = t ? e.we : e.Ve;
774
- if (!n) return;
775
- if (Array.isArray(n)) {
776
- for (let e = 0; e < n.length; e++) {
777
- const t = n[e];
778
- t.call(t);
779
- }
780
- } else {
781
- n.call(n);
782
- }
783
- t ? (e.we = null) : (e.Ve = null);
784
- }
785
- function childId(e, t) {
786
- let n = e;
787
- while (n.be && n.i) n = n.i;
788
- if (n.id != null) return formatId(n.id, t ? n.me++ : n.me);
789
- throw new Error("Cannot get child id from owner without an id");
790
- }
791
- function getNextChildId(e) {
792
- return childId(e, true);
793
- }
794
- function peekNextChildId(e) {
795
- return childId(e, false);
796
- }
797
- function formatId(e, t) {
798
- const n = t.toString(36),
799
- i = n.length - 1;
800
- return e + (i ? String.fromCharCode(64 + i) : "") + n;
801
- }
802
- function getObserver() {
803
- if (pendingCheckActive || latestReadActive) return PENDING_OWNER;
804
- return tracking ? context : null;
805
- }
806
- function getOwner() {
807
- return context;
808
- }
809
- function cleanup(e) {
810
- if (!context) return e;
811
- if (!context.Ve) context.Ve = e;
812
- else if (Array.isArray(context.Ve)) context.Ve.push(e);
813
- else context.Ve = [context.Ve, e];
814
- return e;
815
- }
816
- function isDisposed(e) {
817
- return !!(e.O & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE));
818
- }
819
- function createOwner(e) {
820
- const t = context;
821
- const n = e?.transparent ?? false;
822
- const i = {
823
- id: e?.id ?? (n ? t?.id : t?.id != null ? getNextChildId(t) : undefined),
824
- be: n || undefined,
825
- t: true,
826
- u: t?.t ? t.u : t,
827
- Ce: null,
828
- De: null,
829
- Ve: null,
830
- $: t?.$ ?? globalQueue,
831
- Le: t?.Le || defaultContext,
832
- me: 0,
833
- we: null,
834
- ve: null,
835
- i: t,
836
- dispose(e = true) {
837
- disposeChildren(i, e);
838
- }
839
- };
840
- if (t) {
841
- const e = t.Ce;
842
- if (e === null) {
843
- t.Ce = i;
844
- } else {
845
- i.De = e;
846
- t.Ce = i;
847
- }
848
- }
849
- return i;
850
- }
851
- function createRoot(e, t) {
852
- const n = createOwner(t);
853
- return runWithOwner(n, () => e(n.dispose));
854
- }
855
- function addPendingSource(e, t) {
856
- if (e.Oe === t || e._e?.has(t)) return false;
857
- if (!e.Oe) {
858
- e.Oe = t;
859
- return true;
860
- }
861
- if (!e._e) {
862
- e._e = new Set([e.Oe, t]);
863
- } else {
864
- e._e.add(t);
865
- }
866
- e.Oe = undefined;
867
- return true;
868
- }
869
- function removePendingSource(e, t) {
870
- if (e.Oe) {
871
- if (e.Oe !== t) return false;
872
- e.Oe = undefined;
873
- return true;
874
- }
875
- if (!e._e?.delete(t)) return false;
876
- if (e._e.size === 1) {
877
- e.Oe = e._e.values().next().value;
878
- e._e = undefined;
879
- } else if (e._e.size === 0) {
880
- e._e = undefined;
881
- }
882
- return true;
883
- }
884
- function clearPendingSources(e) {
885
- e.Oe = undefined;
886
- e._e?.clear();
887
- e._e = undefined;
888
- }
889
- function setPendingError(e, t, n) {
890
- if (!t) {
891
- e.Ee = null;
892
- return;
893
- }
894
- if (n instanceof NotReadyError && n.source === t) {
895
- e.Ee = n;
896
- return;
897
- }
898
- const i = e.Ee;
899
- if (!(i instanceof NotReadyError) || i.source !== t) {
900
- e.Ee = new NotReadyError(t);
901
- }
902
- }
903
- function forEachDependent(e, t) {
904
- for (let n = e.I; n !== null; n = n.h) t(n.p);
905
- for (let n = e.A; n !== null; n = n.N) {
906
- for (let e = n.I; e !== null; e = e.h) t(e.p);
907
- }
908
- }
909
- function settlePendingSource(e) {
910
- let t = false;
911
- const n = new Set();
912
- const settle = i => {
913
- if (n.has(i) || !removePendingSource(i, e)) return;
914
- n.add(i);
915
- i.de = clock;
916
- const r = i.Oe ?? i._e?.values().next().value;
917
- if (r) {
918
- setPendingError(i, r);
919
- updatePendingSignal(i);
920
- } else {
921
- i.Re &= ~STATUS_PENDING;
922
- setPendingError(i);
923
- updatePendingSignal(i);
924
- if (i.Ue) {
925
- if (i.F === EFFECT_TRACKED) {
926
- const e = i;
927
- if (!e.j) {
928
- e.j = true;
929
- e.$.enqueue(EFFECT_USER, e.K);
930
- }
931
- } else {
932
- const e = i.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
933
- if (e.P > i.o) e.P = i.o;
934
- insertIntoHeap(i, e);
935
- }
936
- t = true;
937
- }
938
- i.Ue = false;
939
- }
940
- forEachDependent(i, settle);
941
- };
942
- forEachDependent(e, settle);
943
- if (t) schedule();
944
- }
945
- function handleAsync(e, t, n) {
946
- const i = typeof t === "object" && t !== null;
947
- const r = i && untrack(() => t[Symbol.asyncIterator]);
948
- const s = !r && i && untrack(() => typeof t.then === "function");
949
- if (!s && !r) {
950
- e.ye = null;
951
- return t;
952
- }
953
- e.ye = t;
954
- let o;
955
- const handleError = n => {
956
- if (e.ye !== t) return;
957
- globalQueue.initTransition(resolveTransition(e));
958
- notifyStatus(e, n instanceof NotReadyError ? STATUS_PENDING : STATUS_ERROR, n);
959
- e.de = clock;
960
- };
961
- const asyncWrite = (i, r) => {
962
- if (e.ye !== t) return;
963
- if (e.O & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY)) return;
964
- globalQueue.initTransition(resolveTransition(e));
965
- const s = !!(e.Re & STATUS_UNINITIALIZED);
966
- clearStatus(e);
967
- const o = resolveLane(e);
968
- if (o) o.H.delete(e);
969
- if (n) n(i);
970
- else if (e.k !== undefined) {
971
- if (e.k !== undefined && e.k !== NOT_PENDING) e.U = i;
972
- else {
973
- e.te = i;
974
- insertSubs(e);
975
- }
976
- e.de = clock;
977
- } else if (o) {
978
- const t = e.F;
979
- const n = e.te;
980
- const r = e.ke;
981
- if ((!t && s) || !r || !r(i, n)) {
982
- e.te = i;
983
- e.de = clock;
984
- if (e.Ge) {
985
- setSignal(e.Ge, i);
986
- }
987
- insertSubs(e, true);
988
- }
989
- } else {
990
- setSignal(e, () => i);
991
- }
992
- settlePendingSource(e);
993
- schedule();
994
- flush();
995
- r?.();
996
- };
997
- if (s) {
998
- let n = false,
999
- i = true;
1000
- t.then(
1001
- e => {
1002
- if (i) {
1003
- o = e;
1004
- n = true;
1005
- } else asyncWrite(e);
1006
- },
1007
- e => {
1008
- if (!i) handleError(e);
1009
- }
1010
- );
1011
- i = false;
1012
- if (!n) {
1013
- globalQueue.initTransition(resolveTransition(e));
1014
- throw new NotReadyError(context);
1015
- }
1016
- }
1017
- if (r) {
1018
- const n = t[Symbol.asyncIterator]();
1019
- let i = false;
1020
- let r = false;
1021
- cleanup(() => {
1022
- if (r) return;
1023
- r = true;
1024
- try {
1025
- const e = n.return?.();
1026
- if (e && typeof e.then === "function") {
1027
- e.then(undefined, () => {});
1028
- }
1029
- } catch {}
1030
- });
1031
- const iterate = () => {
1032
- let s,
1033
- u = false,
1034
- c = true;
1035
- n.next().then(
1036
- n => {
1037
- if (c) {
1038
- s = n;
1039
- u = true;
1040
- if (n.done) r = true;
1041
- } else if (e.ye !== t) {
1042
- return;
1043
- } else if (!n.done) asyncWrite(n.value, iterate);
1044
- else {
1045
- r = true;
1046
- schedule();
1047
- flush();
1048
- }
1049
- },
1050
- n => {
1051
- if (!c && e.ye === t) {
1052
- r = true;
1053
- handleError(n);
1054
- }
1055
- }
1056
- );
1057
- c = false;
1058
- if (u && !s.done) {
1059
- o = s.value;
1060
- i = true;
1061
- return iterate();
1062
- }
1063
- return u && s.done;
1064
- };
1065
- const s = iterate();
1066
- if (!i && !s) {
1067
- globalQueue.initTransition(resolveTransition(e));
1068
- throw new NotReadyError(context);
1069
- }
1070
- }
1071
- return o;
1072
- }
1073
- function clearStatus(e, t = false) {
1074
- clearPendingSources(e);
1075
- e.Ue = false;
1076
- e.Re = t ? 0 : e.Re & STATUS_UNINITIALIZED;
1077
- setPendingError(e);
1078
- updatePendingSignal(e);
1079
- e.xe?.();
1080
- }
1081
- function notifyStatus(e, t, n, i, r) {
1082
- if (t === STATUS_ERROR && !(n instanceof StatusError) && !(n instanceof NotReadyError))
1083
- n = new StatusError(e, n);
1084
- const s = t === STATUS_PENDING && n instanceof NotReadyError ? n.source : undefined;
1085
- const o = s === e;
1086
- const u = t === STATUS_PENDING && e.k !== undefined && !o;
1087
- const c = u && hasActiveOverride(e);
1088
- if (!i) {
1089
- if (t === STATUS_PENDING && s) {
1090
- addPendingSource(e, s);
1091
- e.Re = STATUS_PENDING | (e.Re & STATUS_UNINITIALIZED);
1092
- setPendingError(e, s, n);
1093
- } else {
1094
- clearPendingSources(e);
1095
- e.Re = t | (t !== STATUS_ERROR ? e.Re & STATUS_UNINITIALIZED : 0);
1096
- e.Ee = n;
1097
- }
1098
- updatePendingSignal(e);
1099
- }
1100
- if (r && !i) {
1101
- assignOrMergeLane(e, r);
1102
- }
1103
- const a = i || c;
1104
- const l = i || u ? undefined : r;
1105
- if (e.xe) {
1106
- if (i && t === STATUS_PENDING) {
1107
- return;
1108
- }
1109
- if (a) {
1110
- e.xe(t, n);
1111
- } else {
1112
- e.xe();
1113
- }
1114
- return;
1115
- }
1116
- forEachDependent(e, e => {
1117
- e.de = clock;
1118
- if (
1119
- (t === STATUS_PENDING && s && e.Oe !== s && !e._e?.has(s)) ||
1120
- (t !== STATUS_PENDING && (e.Ee !== n || e.Oe || e._e))
1121
- ) {
1122
- if (!a && !e.B) globalQueue.oe.push(e);
1123
- notifyStatus(e, t, n, a, l);
1124
- }
1125
- });
1126
- }
1127
- let externalSourceConfig = null;
1128
- function enableExternalSource(e) {
1129
- const { factory: t, untrack: n = e => e() } = e;
1130
- if (externalSourceConfig) {
1131
- const { factory: e, untrack: i } = externalSourceConfig;
1132
- externalSourceConfig = {
1133
- factory: (n, i) => {
1134
- const r = e(n, i);
1135
- const s = t(e => r.track(e), i);
1136
- return {
1137
- track: e => s.track(e),
1138
- dispose() {
1139
- s.dispose();
1140
- r.dispose();
1141
- }
1142
- };
1143
- },
1144
- untrack: e => i(() => n(e))
1145
- };
1146
- } else {
1147
- externalSourceConfig = { factory: t, untrack: n };
1148
- }
1149
- }
1150
- GlobalQueue.ue = recompute;
1151
- GlobalQueue.ce = disposeChildren;
1152
- let tracking = false;
1153
- let stale = false;
1154
- let refreshing = false;
1155
- let pendingCheckActive = false;
1156
- let foundPending = false;
1157
- let latestReadActive = false;
1158
- let context = null;
1159
- let currentOptimisticLane = null;
1160
- let snapshotCaptureActive = false;
1161
- let snapshotSources = null;
1162
- function ownerInSnapshotScope(e) {
1163
- while (e) {
1164
- if (e.We) return true;
1165
- e = e.i;
1166
- }
1167
- return false;
1168
- }
1169
- function setSnapshotCapture(e) {
1170
- snapshotCaptureActive = e;
1171
- if (e && !snapshotSources) snapshotSources = new Set();
1172
- }
1173
- function markSnapshotScope(e) {
1174
- e.We = true;
1175
- }
1176
- function releaseSnapshotScope(e) {
1177
- e.We = false;
1178
- releaseSubtree(e);
1179
- schedule();
1180
- }
1181
- function releaseSubtree(e) {
1182
- let t = e.Ce;
1183
- while (t) {
1184
- if (t.We) {
1185
- t = t.De;
1186
- continue;
1187
- }
1188
- if (t.L) {
1189
- const e = t;
1190
- e.Se = false;
1191
- if (e.O & REACTIVE_SNAPSHOT_STALE) {
1192
- e.O &= ~REACTIVE_SNAPSHOT_STALE;
1193
- e.O |= REACTIVE_DIRTY;
1194
- if (dirtyQueue.P > e.o) dirtyQueue.P = e.o;
1195
- insertIntoHeap(e, dirtyQueue);
1196
- }
1197
- }
1198
- releaseSubtree(t);
1199
- t = t.De;
1200
- }
1201
- }
1202
- function clearSnapshots() {
1203
- if (snapshotSources) {
1204
- for (const e of snapshotSources) {
1205
- delete e.Te;
1206
- delete e[STORE_SNAPSHOT_PROPS];
1207
- }
1208
- snapshotSources = null;
1209
- }
1210
- snapshotCaptureActive = false;
1211
- }
1212
- function recompute(e, t = false) {
1213
- const n = e.F;
1214
- if (!t) {
1215
- if (e.B && (!n || activeTransition) && activeTransition !== e.B)
1216
- globalQueue.initTransition(e.B);
1217
- deleteFromHeap(e, e.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
1218
- e.ye = null;
1219
- if (e.B || n === EFFECT_TRACKED) disposeChildren(e);
1220
- else {
1221
- markDisposal(e);
1222
- e.we = e.Ve;
1223
- e.ve = e.Ce;
1224
- e.Ve = null;
1225
- e.Ce = null;
1226
- e.me = 0;
1227
- }
1228
- }
1229
- const i = !!(e.O & REACTIVE_OPTIMISTIC_DIRTY);
1230
- const r = e.k !== undefined && e.k !== NOT_PENDING;
1231
- const s = !!(e.Re & STATUS_PENDING);
1232
- const o = !!(e.Re & STATUS_UNINITIALIZED);
1233
- const u = context;
1234
- context = e;
1235
- e.ge = null;
1236
- e.O = REACTIVE_RECOMPUTING_DEPS;
1237
- e.de = clock;
1238
- let c = e.U === NOT_PENDING ? e.te : e.U;
1239
- let a = e.o;
1240
- let l = tracking;
1241
- let f = currentOptimisticLane;
1242
- tracking = true;
1243
- if (i) {
1244
- const t = resolveLane(e);
1245
- if (t) currentOptimisticLane = t;
1246
- }
1247
- try {
1248
- const n = e.ye;
1249
- const i = e.L(c);
1250
- c = e.ye !== n ? i : handleAsync(e, i);
1251
- clearStatus(e, t);
1252
- const r = resolveLane(e);
1253
- if (r) {
1254
- r.H.delete(e);
1255
- updatePendingSignal(r.ne);
1256
- }
1257
- } catch (t) {
1258
- if (t instanceof NotReadyError && currentOptimisticLane) {
1259
- const t = findLane(currentOptimisticLane);
1260
- if (t.ne !== e) {
1261
- t.H.add(e);
1262
- e.ee = t;
1263
- updatePendingSignal(t.ne);
1264
- }
1265
- }
1266
- if (t instanceof NotReadyError) e.Ue = true;
1267
- notifyStatus(
1268
- e,
1269
- t instanceof NotReadyError ? STATUS_PENDING : STATUS_ERROR,
1270
- t,
1271
- undefined,
1272
- t instanceof NotReadyError ? e.ee : undefined
1273
- );
1274
- } finally {
1275
- tracking = l;
1276
- e.O = REACTIVE_NONE | (t ? e.O & REACTIVE_SNAPSHOT_STALE : 0);
1277
- context = u;
1278
- }
1279
- if (!e.Ee) {
1280
- const u = e.ge;
1281
- let l = u !== null ? u.D : e.C;
1282
- if (l !== null) {
1283
- do {
1284
- l = unlinkSubs(l);
1285
- } while (l !== null);
1286
- if (u !== null) u.D = null;
1287
- else e.C = null;
1288
- }
1289
- const f = r ? e.k : e.U === NOT_PENDING ? e.te : e.U;
1290
- const E = (!n && o) || !e.ke || !e.ke(f, c);
1291
- if (E) {
1292
- const o = r ? e.k : undefined;
1293
- if (t || (n && activeTransition !== e.B) || i) {
1294
- e.te = c;
1295
- if (r && i) {
1296
- e.k = c;
1297
- e.U = c;
1298
- }
1299
- } else e.U = c;
1300
- if (r && !i && s && !e.pe) e.k = c;
1301
- if (!r || i || e.k !== o) insertSubs(e, i || r);
1302
- } else if (r) {
1303
- e.U = c;
1304
- } else if (e.o != a) {
1305
- for (let t = e.I; t !== null; t = t.h) {
1306
- insertIntoHeapHeight(t.p, t.p.O & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
1307
- }
1308
- }
1309
- }
1310
- currentOptimisticLane = f;
1311
- (!t || e.Re & STATUS_PENDING) && !e.B && !(activeTransition && r) && globalQueue.oe.push(e);
1312
- e.B && n && activeTransition !== e.B && runInTransition(e.B, () => recompute(e));
1313
- }
1314
- function updateIfNecessary(e) {
1315
- if (e.O & REACTIVE_CHECK) {
1316
- for (let t = e.C; t; t = t.D) {
1317
- const n = t.m;
1318
- const i = n.V || n;
1319
- if (i.L) {
1320
- updateIfNecessary(i);
1321
- }
1322
- if (e.O & REACTIVE_DIRTY) {
1323
- break;
1324
- }
1325
- }
1326
- }
1327
- if (e.O & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY) || (e.Ee && e.de < clock && !e.ye)) {
1328
- recompute(e);
1329
- }
1330
- e.O = e.O & (REACTIVE_SNAPSHOT_STALE | REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT);
1331
- }
1332
- function computed(e, t) {
1333
- const n = t?.transparent ?? false;
1334
- const i = {
1335
- id: t?.id ?? (n ? context?.id : context?.id != null ? getNextChildId(context) : undefined),
1336
- be: n || undefined,
1337
- ke: t?.equals != null ? t.equals : isEqual,
1338
- fe: !!t?.ownedWrite,
1339
- G: t?.unobserved,
1340
- Ve: null,
1341
- $: context?.$ ?? globalQueue,
1342
- Le: context?.Le ?? defaultContext,
1343
- me: 0,
1344
- L: e,
1345
- te: undefined,
1346
- o: 0,
1347
- A: null,
1348
- S: undefined,
1349
- T: null,
1350
- C: null,
1351
- ge: null,
1352
- I: null,
1353
- Ne: null,
1354
- i: context,
1355
- De: null,
1356
- Ce: null,
1357
- O: t?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
1358
- Re: STATUS_UNINITIALIZED,
1359
- de: clock,
1360
- U: NOT_PENDING,
1361
- we: null,
1362
- ve: null,
1363
- ye: null,
1364
- B: null
1365
- };
1366
- i.T = i;
1367
- const r = context?.t ? context.u : context;
1368
- if (context) {
1369
- const e = context.Ce;
1370
- if (e === null) {
1371
- context.Ce = i;
1372
- } else {
1373
- i.De = e;
1374
- context.Ce = i;
1375
- }
1376
- }
1377
- if (r) i.o = r.o + 1;
1378
- if (snapshotCaptureActive && ownerInSnapshotScope(context)) i.Se = true;
1379
- if (externalSourceConfig) {
1380
- const e = signal(undefined, { equals: false, ownedWrite: true });
1381
- const t = externalSourceConfig.factory(i.L, () => {
1382
- setSignal(e, undefined);
1383
- });
1384
- cleanup(() => t.dispose());
1385
- i.L = n => {
1386
- read(e);
1387
- return t.track(n);
1388
- };
1389
- }
1390
- !t?.lazy && recompute(i, true);
1391
- if (snapshotCaptureActive && !t?.lazy) {
1392
- if (!(i.Re & STATUS_PENDING)) {
1393
- i.Te = i.te === undefined ? NO_SNAPSHOT : i.te;
1394
- snapshotSources.add(i);
1395
- }
1396
- }
1397
- return i;
1398
- }
1399
- function signal(e, t, n = null) {
1400
- const i = {
1401
- ke: t?.equals != null ? t.equals : isEqual,
1402
- fe: !!t?.ownedWrite,
1403
- He: !!t?.He,
1404
- G: t?.unobserved,
1405
- te: e,
1406
- I: null,
1407
- Ne: null,
1408
- de: clock,
1409
- V: n,
1410
- N: n?.A || null,
1411
- U: NOT_PENDING
1412
- };
1413
- n && (n.A = i);
1414
- if (snapshotCaptureActive && !i.He && !((n?.Re ?? 0) & STATUS_PENDING)) {
1415
- i.Te = e === undefined ? NO_SNAPSHOT : e;
1416
- snapshotSources.add(i);
1417
- }
1418
- return i;
1419
- }
1420
- function optimisticSignal(e, t) {
1421
- const n = signal(e, t);
1422
- n.k = NOT_PENDING;
1423
- return n;
1424
- }
1425
- function optimisticComputed(e, t) {
1426
- const n = computed(e, t);
1427
- n.k = NOT_PENDING;
1428
- return n;
1429
- }
1430
- function isEqual(e, t) {
1431
- return e === t;
1432
- }
1433
- function untrack(e, t) {
1434
- if (!externalSourceConfig && !tracking && true) return e();
1435
- const n = tracking;
1436
- tracking = false;
1437
- try {
1438
- if (externalSourceConfig) return externalSourceConfig.untrack(e);
1439
- return e();
1440
- } finally {
1441
- tracking = n;
1442
- }
1443
- }
1444
- function read(e) {
1445
- if (latestReadActive) {
1446
- const t = getLatestValueComputed(e);
1447
- const n = latestReadActive;
1448
- latestReadActive = false;
1449
- const i = e.k !== undefined && e.k !== NOT_PENDING ? e.k : e.te;
1450
- let r;
1451
- try {
1452
- r = read(t);
1453
- } catch (e) {
1454
- if (!context && e instanceof NotReadyError) return i;
1455
- throw e;
1456
- } finally {
1457
- latestReadActive = n;
1458
- }
1459
- if (t.Re & STATUS_PENDING) return i;
1460
- if (stale && currentOptimisticLane && t.ee) {
1461
- const e = findLane(t.ee);
1462
- const n = findLane(currentOptimisticLane);
1463
- if (e !== n && e.H.size > 0) {
1464
- return i;
1465
- }
1466
- }
1467
- return r;
1468
- }
1469
- if (pendingCheckActive) {
1470
- const t = e.V;
1471
- const n = pendingCheckActive;
1472
- pendingCheckActive = false;
1473
- if (t && e.k !== undefined) {
1474
- if (e.k !== NOT_PENDING && (t.ye || !!(t.Re & STATUS_PENDING))) {
1475
- foundPending = true;
1476
- }
1477
- let n = context;
1478
- if (n?.t) n = n.u;
1479
- if (n && tracking) link(e, n);
1480
- read(getPendingSignal(e));
1481
- read(getPendingSignal(t));
1482
- } else {
1483
- if (read(getPendingSignal(e))) foundPending = true;
1484
- if (t && read(getPendingSignal(t))) foundPending = true;
1485
- }
1486
- pendingCheckActive = n;
1487
- return e.te;
1488
- }
1489
- let t = context;
1490
- if (t?.t) t = t.u;
1491
- const n = e;
1492
- if (typeof n.L === "function") {
1493
- const t = e;
1494
- if (refreshing && !(t.O & REACTIVE_DISPOSED)) recompute(t);
1495
- if (t.O & REACTIVE_LAZY) {
1496
- t.O &= ~REACTIVE_LAZY;
1497
- recompute(t, true);
1498
- } else if (t.O & REACTIVE_DISPOSED) {
1499
- recompute(t, true);
1500
- }
1501
- }
1502
- const i = e.V || e;
1503
- if (t && tracking) {
1504
- link(e, t);
1505
- if (i.L) {
1506
- const n = e.O & REACTIVE_ZOMBIE;
1507
- if (i.o >= (n ? zombieQueue.P : dirtyQueue.P)) {
1508
- markNode(t);
1509
- markHeap(n ? zombieQueue : dirtyQueue);
1510
- updateIfNecessary(i);
1511
- }
1512
- const r = i.o;
1513
- if (r >= t.o && e.i !== t) {
1514
- t.o = r + 1;
1515
- }
1516
- }
1517
- }
1518
- if (i.Re & STATUS_PENDING) {
1519
- if (t && !(stale && i.B && activeTransition !== i.B)) {
1520
- if (currentOptimisticLane) {
1521
- const n = i.ee;
1522
- const r = findLane(currentOptimisticLane);
1523
- if (n && findLane(n) === r && !hasActiveOverride(i)) {
1524
- if (!tracking && e !== t) link(e, t);
1525
- throw i.Ee;
1526
- }
1527
- } else {
1528
- if (!tracking && e !== t) link(e, t);
1529
- throw i.Ee;
1530
- }
1531
- } else if (t && i !== e && i.Re & STATUS_UNINITIALIZED) {
1532
- if (!tracking && e !== t) link(e, t);
1533
- throw i.Ee;
1534
- } else if (!t && i.Re & STATUS_UNINITIALIZED) {
1535
- throw i.Ee;
1536
- }
1537
- }
1538
- if (e.L && e.Re & STATUS_ERROR) {
1539
- if (e.de < clock) {
1540
- recompute(e);
1541
- return read(e);
1542
- } else throw e.Ee;
1543
- }
1544
- if (snapshotCaptureActive && t && t.Se) {
1545
- const n = e.Te;
1546
- if (n !== undefined) {
1547
- const i = n === NO_SNAPSHOT ? undefined : n;
1548
- const r = e.U !== NOT_PENDING ? e.U : e.te;
1549
- if (r !== i) t.O |= REACTIVE_SNAPSHOT_STALE;
1550
- return i;
1551
- }
1552
- }
1553
- if (e.k !== undefined && e.k !== NOT_PENDING) {
1554
- if (t && stale && shouldReadStashedOptimisticValue(e)) return e.te;
1555
- return e.k;
1556
- }
1557
- const r =
1558
- !t ||
1559
- (currentOptimisticLane !== null &&
1560
- (e.k !== undefined || e.ee || (i === e && stale) || !!(i.Re & STATUS_PENDING))) ||
1561
- e.U === NOT_PENDING ||
1562
- (stale && e.B && activeTransition !== e.B)
1563
- ? e.te
1564
- : e.U;
1565
- if (
1566
- !t &&
1567
- i === e &&
1568
- typeof n.L === "function" &&
1569
- !n.Pe &&
1570
- !(i.Re & STATUS_PENDING) &&
1571
- !n.i &&
1572
- !e.I
1573
- ) {
1574
- unobserved(e);
1575
- }
1576
- return r;
1577
- }
1578
- function setSignal(e, t) {
1579
- if (e.B && activeTransition !== e.B) globalQueue.initTransition(e.B);
1580
- const n = e.k !== undefined && !projectionWriteActive;
1581
- const i = e.k !== undefined && e.k !== NOT_PENDING;
1582
- const r = n ? (i ? e.k : e.te) : e.U === NOT_PENDING ? e.te : e.U;
1583
- if (typeof t === "function") t = t(r);
1584
- const s = !e.ke || !e.ke(r, t) || !!(e.Re & STATUS_UNINITIALIZED);
1585
- if (!s) {
1586
- if (n && i && e.L) {
1587
- insertSubs(e, true);
1588
- schedule();
1589
- }
1590
- return t;
1591
- }
1592
- if (n) {
1593
- const n = e.k === NOT_PENDING;
1594
- if (!n) globalQueue.initTransition(resolveTransition(e));
1595
- if (n) {
1596
- e.U = e.te;
1597
- globalQueue.q.push(e);
1598
- }
1599
- e.pe = true;
1600
- const i = getOrCreateLane(e);
1601
- e.ee = i;
1602
- e.k = t;
1603
- } else {
1604
- if (e.U === NOT_PENDING) globalQueue.oe.push(e);
1605
- e.U = t;
1606
- }
1607
- updatePendingSignal(e);
1608
- if (e.Ge) {
1609
- setSignal(e.Ge, t);
1610
- }
1611
- e.de = clock;
1612
- insertSubs(e, n);
1613
- schedule();
1614
- return t;
1615
- }
1616
- function runWithOwner(e, t) {
1617
- const n = context;
1618
- const i = tracking;
1619
- context = e;
1620
- tracking = false;
1621
- try {
1622
- return t();
1623
- } finally {
1624
- context = n;
1625
- tracking = i;
1626
- }
1627
- }
1628
- function getPendingSignal(e) {
1629
- if (!e.Me) {
1630
- e.Me = optimisticSignal(false, { ownedWrite: true });
1631
- if (e.Ie) {
1632
- e.Me.Ie = e;
1633
- }
1634
- if (computePendingState(e)) setSignal(e.Me, true);
1635
- }
1636
- return e.Me;
1637
- }
1638
- function computePendingState(e) {
1639
- const t = e;
1640
- const n = e.V;
1641
- if (n && e.U !== NOT_PENDING) {
1642
- return !n.ye && !(n.Re & STATUS_PENDING);
1643
- }
1644
- if (e.k !== undefined && e.k !== NOT_PENDING) {
1645
- if (t.Re & STATUS_PENDING && !(t.Re & STATUS_UNINITIALIZED)) return true;
1646
- if (e.Ie) {
1647
- const t = e.ee ? findLane(e.ee) : null;
1648
- return !!(t && t.H.size > 0);
1649
- }
1650
- return true;
1651
- }
1652
- if (e.k !== undefined && e.k === NOT_PENDING && !e.Ie) {
1653
- return false;
1654
- }
1655
- if (e.U !== NOT_PENDING && !(t.Re & STATUS_UNINITIALIZED)) return true;
1656
- return !!(t.Re & STATUS_PENDING && !(t.Re & STATUS_UNINITIALIZED));
1657
- }
1658
- function updatePendingSignal(e) {
1659
- if (e.Me) {
1660
- const t = computePendingState(e);
1661
- const n = e.Me;
1662
- setSignal(n, t);
1663
- if (!t && n.ee) {
1664
- const t = resolveLane(e);
1665
- if (t && t.H.size > 0) {
1666
- const e = findLane(n.ee);
1667
- if (e !== t) {
1668
- mergeLanes(t, e);
1669
- }
1670
- }
1671
- signalLanes.delete(n);
1672
- n.ee = undefined;
1673
- }
1674
- }
1675
- }
1676
- function getLatestValueComputed(e) {
1677
- if (!e.Ge) {
1678
- const t = latestReadActive;
1679
- latestReadActive = false;
1680
- const n = pendingCheckActive;
1681
- pendingCheckActive = false;
1682
- const i = context;
1683
- context = null;
1684
- e.Ge = optimisticComputed(() => read(e));
1685
- e.Ge.Ie = e;
1686
- context = i;
1687
- pendingCheckActive = n;
1688
- latestReadActive = t;
1689
- }
1690
- return e.Ge;
1691
- }
1692
- function staleValues(e, t = true) {
1693
- const n = stale;
1694
- stale = t;
1695
- try {
1696
- return e();
1697
- } finally {
1698
- stale = n;
1699
- }
1700
- }
1701
- function latest(e) {
1702
- const t = latestReadActive;
1703
- latestReadActive = true;
1704
- try {
1705
- return e();
1706
- } finally {
1707
- latestReadActive = t;
1708
- }
1709
- }
1710
- function isPending(e) {
1711
- const t = pendingCheckActive;
1712
- const n = foundPending;
1713
- pendingCheckActive = true;
1714
- foundPending = false;
1715
- try {
1716
- e();
1717
- return foundPending;
1718
- } catch {
1719
- return foundPending;
1720
- } finally {
1721
- pendingCheckActive = t;
1722
- foundPending = n;
1723
- }
1724
- }
1725
- function refresh(e) {
1726
- let t = refreshing;
1727
- refreshing = true;
1728
- try {
1729
- if (typeof e !== "function") {
1730
- recompute(e[$REFRESH]);
1731
- return e;
1732
- }
1733
- return untrack(e);
1734
- } finally {
1735
- refreshing = t;
1736
- if (!t) {
1737
- schedule();
1738
- }
1739
- }
1740
- }
1741
- function isRefreshing() {
1742
- return refreshing;
1743
- }
1744
- function createContext(e, t) {
1745
- return { id: Symbol(t), defaultValue: e };
1746
- }
1747
- function getContext(e, t = getOwner()) {
1748
- if (!t) {
1749
- throw new NoOwnerError();
1750
- }
1751
- const n = hasContext(e, t) ? t.Le[e.id] : e.defaultValue;
1752
- if (isUndefined(n)) {
1753
- throw new ContextNotFoundError();
1754
- }
1755
- return n;
1756
- }
1757
- function setContext(e, t, n = getOwner()) {
1758
- if (!n) {
1759
- throw new NoOwnerError();
1760
- }
1761
- n.Le = { ...n.Le, [e.id]: isUndefined(t) ? e.defaultValue : t };
1762
- }
1763
- function hasContext(e, t) {
1764
- return !isUndefined(t?.Le[e.id]);
1765
- }
1766
- function isUndefined(e) {
1767
- return typeof e === "undefined";
1768
- }
1769
- function effect(e, t, n, i) {
1770
- let r = false;
1771
- const s = !!i?.user;
1772
- const o = computed(s ? e : t => staleValues(() => e(t)), {
1773
- ...i,
1774
- equals: () => {
1775
- o.j = !o.Ee;
1776
- if (r) o.$.enqueue(o.F, runEffect.bind(o));
1777
- return false;
1778
- },
1779
- lazy: true
1780
- });
1781
- o.Qe = undefined;
1782
- o.Fe = t;
1783
- o.je = n;
1784
- o.$e = undefined;
1785
- o.F = s ? EFFECT_USER : EFFECT_RENDER;
1786
- o.xe = (e, t) => {
1787
- const n = e !== undefined ? e : o.Re;
1788
- const i = t !== undefined ? t : o.Ee;
1789
- if (n & STATUS_ERROR) {
1790
- let e = i;
1791
- o.$.notify(o, STATUS_PENDING, 0);
1792
- if (o.F === EFFECT_USER) {
1793
- try {
1794
- return o.je
1795
- ? o.je(e, () => {
1796
- o.$e?.();
1797
- o.$e = undefined;
1798
- })
1799
- : console.error(e);
1800
- } catch (t) {
1801
- e = t;
1802
- }
1803
- }
1804
- if (!o.$.notify(o, STATUS_ERROR, STATUS_ERROR)) throw e;
1805
- } else if (o.F === EFFECT_RENDER) {
1806
- o.$.notify(o, STATUS_PENDING | STATUS_ERROR, n, i);
1807
- }
1808
- };
1809
- recompute(o, true);
1810
- !i?.defer &&
1811
- (o.F === EFFECT_USER || i?.schedule ? o.$.enqueue(o.F, runEffect.bind(o)) : runEffect.call(o));
1812
- r = true;
1813
- cleanup(() => o.$e?.());
1814
- }
1815
- function runEffect() {
1816
- if (!this.j || this.O & REACTIVE_DISPOSED) return;
1817
- this.$e?.();
1818
- this.$e = undefined;
1819
- try {
1820
- const e = this.Fe(this.te, this.Qe);
1821
- if (false && e !== undefined && typeof e !== "function");
1822
- this.$e = e;
1823
- } catch (e) {
1824
- this.Ee = new StatusError(this, e);
1825
- this.Re |= STATUS_ERROR;
1826
- if (!this.$.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
1827
- } finally {
1828
- this.Qe = this.te;
1829
- this.j = false;
1830
- }
1831
- }
1832
- function trackedEffect(e, t) {
1833
- const run = () => {
1834
- if (!n.j || n.O & REACTIVE_DISPOSED) return;
1835
- try {
1836
- n.j = false;
1837
- recompute(n);
1838
- } finally {
1839
- }
1840
- };
1841
- const n = computed(
1842
- () => {
1843
- n.$e?.();
1844
- n.$e = undefined;
1845
- const t = staleValues(e);
1846
- n.$e = t;
1847
- },
1848
- { ...t, lazy: true }
1849
- );
1850
- n.$e = undefined;
1851
- n.Ke = true;
1852
- n.j = true;
1853
- n.F = EFFECT_TRACKED;
1854
- n.xe = (e, t) => {
1855
- const i = e !== undefined ? e : n.Re;
1856
- if (i & STATUS_ERROR) {
1857
- n.$.notify(n, STATUS_PENDING, 0);
1858
- const e = t !== undefined ? t : n.Ee;
1859
- if (!n.$.notify(n, STATUS_ERROR, STATUS_ERROR)) throw e;
1860
- }
1861
- };
1862
- n.K = run;
1863
- n.$.enqueue(EFFECT_USER, run);
1864
- cleanup(() => n.$e?.());
1865
- }
1866
- function restoreTransition(e, t) {
1867
- globalQueue.initTransition(e);
1868
- const n = t();
1869
- flush();
1870
- return n;
1871
- }
1872
- function action(e) {
1873
- return (...t) =>
1874
- new Promise((n, i) => {
1875
- const r = e(...t);
1876
- globalQueue.initTransition();
1877
- let s = activeTransition;
1878
- s.Z.push(r);
1879
- const done = (e, t) => {
1880
- s = currentTransition(s);
1881
- const o = s.Z.indexOf(r);
1882
- if (o >= 0) s.Z.splice(o, 1);
1883
- setActiveTransition(s);
1884
- schedule();
1885
- t ? i(t) : n(e);
1886
- };
1887
- const step = (e, t) => {
1888
- let n;
1889
- try {
1890
- n = t ? r.throw(e) : r.next(e);
1891
- } catch (e) {
1892
- return done(undefined, e);
1893
- }
1894
- if (n instanceof Promise)
1895
- return void n.then(run, e => restoreTransition(s, () => step(e, true)));
1896
- run(n);
1897
- };
1898
- const run = e => {
1899
- if (e.done) return done(e.value);
1900
- if (e.value instanceof Promise)
1901
- return void e.value.then(
1902
- e => restoreTransition(s, () => step(e)),
1903
- e => restoreTransition(s, () => step(e, true))
1904
- );
1905
- restoreTransition(s, () => step(e.value));
1906
- };
1907
- step();
1908
- });
1909
- }
1910
- function onCleanup(e) {
1911
- return cleanup(e);
1912
- }
1913
- function accessor(e) {
1914
- const t = read.bind(null, e);
1915
- t.$r = true;
1916
- return t;
1917
- }
1918
- function createSignal(e, t) {
1919
- if (typeof e === "function") {
1920
- const n = computed(e, t);
1921
- n.Pe = true;
1922
- return [accessor(n), setSignal.bind(null, n)];
1923
- }
1924
- const n = signal(e, t);
1925
- return [accessor(n), setSignal.bind(null, n)];
1926
- }
1927
- function createMemo(e, t) {
1928
- let n = computed(e, t);
1929
- return accessor(n);
1930
- }
1931
- function createEffect(e, t, n) {
1932
- effect(e, t.effect || t, t.error, { user: true, ...n });
1933
- }
1934
- function createRenderEffect(e, t, n) {
1935
- effect(e, t, undefined, n);
1936
- }
1937
- function createTrackedEffect(e, t) {
1938
- trackedEffect(e, t);
1939
- }
1940
- function createReaction(e, t) {
1941
- let n = undefined;
1942
- cleanup(() => n?.());
1943
- const i = getOwner();
1944
- return r => {
1945
- runWithOwner(i, () => {
1946
- effect(
1947
- () => (r(), getOwner()),
1948
- t => {
1949
- n?.();
1950
- const i = (e.effect || e)?.();
1951
- if (false && i !== undefined && typeof i !== "function");
1952
- n = i;
1953
- dispose(t);
1954
- },
1955
- e.error,
1956
- { ...(false ? { ...t, name: t?.name ?? "effect" } : t), user: true, defer: true }
1957
- );
1958
- });
1959
- };
1960
- }
1961
- function resolve(e) {
1962
- return new Promise((t, n) => {
1963
- createRoot(i => {
1964
- computed(() => {
1965
- try {
1966
- t(e());
1967
- } catch (e) {
1968
- if (e instanceof NotReadyError) throw e;
1969
- n(e);
1970
- }
1971
- i();
1972
- });
1973
- });
1974
- });
1975
- }
1976
- function createOptimistic(e, t) {
1977
- if (typeof e === "function") {
1978
- const n = optimisticComputed(e, t);
1979
- n.Pe = true;
1980
- return [accessor(n), setSignal.bind(null, n)];
1981
- }
1982
- const n = optimisticSignal(e, t);
1983
- return [accessor(n), setSignal.bind(null, n)];
1984
- }
1985
- function onSettled(e) {
1986
- const t = getOwner();
1987
- t && !t.Ke
1988
- ? createTrackedEffect(() => untrack(e), undefined)
1989
- : globalQueue.enqueue(EFFECT_USER, () => {
1990
- const t = e();
1991
- t?.();
1992
- });
1993
- }
1994
- function unwrap(e) {
1995
- return e?.[$TARGET]?.[STORE_NODE] ?? e;
1996
- }
1997
- function getOverrideValue(e, t, n, i, r) {
1998
- if (r && i in r) return r[i];
1999
- return t && i in t ? t[i] : e[i];
2000
- }
2001
- function getAllKeys(e, t, n) {
2002
- const i = getKeys(e, t);
2003
- const r = Object.keys(n);
2004
- return Array.from(new Set([...i, ...r]));
2005
- }
2006
- function applyState(e, t, n) {
2007
- const i = t?.[$TARGET];
2008
- if (!i) return;
2009
- const r = i[STORE_VALUE];
2010
- const s = i[STORE_OVERRIDE];
2011
- const o = i[STORE_OPTIMISTIC_OVERRIDE];
2012
- let u = i[STORE_NODE];
2013
- if (e === r && !s && !o) return;
2014
- (i[STORE_LOOKUP] || storeLookup).set(e, i[$PROXY]);
2015
- i[STORE_VALUE] = e;
2016
- i[STORE_OVERRIDE] = undefined;
2017
- if (Array.isArray(r)) {
2018
- let t = false;
2019
- const c = getOverrideValue(r, s, u, "length", o);
2020
- if (e.length && c && e[0] && n(e[0]) != null) {
2021
- let a, l, f, E, d, T, S, R;
2022
- for (
2023
- f = 0, E = Math.min(c, e.length);
2024
- f < E &&
2025
- ((T = getOverrideValue(r, s, u, f, o)) === e[f] || (T && e[f] && n(T) === n(e[f])));
2026
- f++
2027
- ) {
2028
- applyState(e[f], wrap(T, i), n);
2029
- }
2030
- const O = new Array(e.length),
2031
- _ = new Map();
2032
- for (
2033
- E = c - 1, d = e.length - 1;
2034
- E >= f &&
2035
- d >= f &&
2036
- ((T = getOverrideValue(r, s, u, E, o)) === e[d] || (T && e[d] && n(T) === n(e[d])));
2037
- E--, d--
2038
- ) {
2039
- O[d] = T;
2040
- }
2041
- if (f > d || f > E) {
2042
- for (l = f; l <= d; l++) {
2043
- t = true;
2044
- i[STORE_NODE][l] && setSignal(i[STORE_NODE][l], wrap(e[l], i));
2045
- }
2046
- for (; l < e.length; l++) {
2047
- t = true;
2048
- const r = wrap(O[l], i);
2049
- i[STORE_NODE][l] && setSignal(i[STORE_NODE][l], r);
2050
- applyState(e[l], r, n);
2051
- }
2052
- t && i[STORE_NODE][$TRACK] && setSignal(i[STORE_NODE][$TRACK], void 0);
2053
- c !== e.length && i[STORE_NODE].length && setSignal(i[STORE_NODE].length, e.length);
2054
- return;
2055
- }
2056
- S = new Array(d + 1);
2057
- for (l = d; l >= f; l--) {
2058
- T = e[l];
2059
- R = T ? n(T) : T;
2060
- a = _.get(R);
2061
- S[l] = a === undefined ? -1 : a;
2062
- _.set(R, l);
2063
- }
2064
- for (a = f; a <= E; a++) {
2065
- T = getOverrideValue(r, s, u, a, o);
2066
- R = T ? n(T) : T;
2067
- l = _.get(R);
2068
- if (l !== undefined && l !== -1) {
2069
- O[l] = T;
2070
- l = S[l];
2071
- _.set(R, l);
2072
- }
2073
- }
2074
- for (l = f; l < e.length; l++) {
2075
- if (l in O) {
2076
- const t = wrap(O[l], i);
2077
- i[STORE_NODE][l] && setSignal(i[STORE_NODE][l], t);
2078
- applyState(e[l], t, n);
2079
- } else i[STORE_NODE][l] && setSignal(i[STORE_NODE][l], wrap(e[l], i));
2080
- }
2081
- if (f < e.length) t = true;
2082
- } else if (e.length) {
2083
- for (let t = 0, c = e.length; t < c; t++) {
2084
- const c = getOverrideValue(r, s, u, t, o);
2085
- isWrappable(c)
2086
- ? applyState(e[t], wrap(c, i), n)
2087
- : i[STORE_NODE][t] && setSignal(i[STORE_NODE][t], e[t]);
2088
- }
2089
- }
2090
- if (c !== e.length) {
2091
- t = true;
2092
- i[STORE_NODE].length && setSignal(i[STORE_NODE].length, e.length);
2093
- }
2094
- t && i[STORE_NODE][$TRACK] && setSignal(i[STORE_NODE][$TRACK], void 0);
2095
- return;
2096
- }
2097
- if (u) {
2098
- const t = u[$TRACK];
2099
- const c = t ? getAllKeys(r, s, e) : Object.keys(u);
2100
- for (let a = 0, l = c.length; a < l; a++) {
2101
- const l = c[a];
2102
- const f = u[l];
2103
- const E = unwrap(getOverrideValue(r, s, u, l, o));
2104
- let d = unwrap(e[l]);
2105
- if (E === d) continue;
2106
- if (!E || !isWrappable(E) || !isWrappable(d) || (n(E) != null && n(E) !== n(d))) {
2107
- t && setSignal(t, void 0);
2108
- f && setSignal(f, isWrappable(d) ? wrap(d, i) : d);
2109
- } else applyState(d, wrap(E, i), n);
2110
- }
2111
- }
2112
- if ((u = i[STORE_HAS])) {
2113
- const t = Object.keys(u);
2114
- for (let n = 0, i = t.length; n < i; n++) {
2115
- const i = t[n];
2116
- setSignal(u[i], i in e);
2117
- }
2118
- }
2119
- }
2120
- function reconcile(e, t) {
2121
- return n => {
2122
- if (n == null) throw new Error("Cannot reconcile null or undefined state");
2123
- const i = typeof t === "string" ? e => e[t] : t;
2124
- const r = i(n);
2125
- if (r !== undefined && i(e) !== i(n))
2126
- throw new Error("Cannot reconcile states with different identity");
2127
- applyState(e, n, i);
2128
- };
2129
- }
2130
- function createProjectionInternal(e, t, n) {
2131
- let i;
2132
- const r = new WeakMap();
2133
- const wrapper = e => {
2134
- e[STORE_WRAP] = wrapProjection;
2135
- e[STORE_LOOKUP] = r;
2136
- Object.defineProperty(e, STORE_FIREWALL, {
2137
- get() {
2138
- return i;
2139
- },
2140
- configurable: true
2141
- });
2142
- };
2143
- const wrapProjection = e => {
2144
- if (r.has(e)) return r.get(e);
2145
- if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
2146
- const t = createStoreProxy(e, storeTraps, wrapper);
2147
- r.set(e, t);
2148
- return t;
2149
- };
2150
- const s = wrapProjection(t);
2151
- i = computed(() => {
2152
- if (!i) i = getOwner();
2153
- runProjectionComputed(s, e, n?.key || "id");
2154
- }, undefined);
2155
- i.Pe = true;
2156
- return { store: s, node: i };
2157
- }
2158
- function createProjection(e, t, n) {
2159
- return createProjectionInternal(e, t, n).store;
2160
- }
2161
- function runProjectionComputed(e, t, n, i) {
2162
- const r = getOwner();
2163
- let s = false;
2164
- let o;
2165
- const u = new Proxy(
2166
- e,
2167
- createWriteTraps(() => !s || r.ye === o)
2168
- );
2169
- storeSetter(u, u => {
2170
- o = t(u);
2171
- s = true;
2172
- const commit = t => {
2173
- if (t === u || t === undefined) return;
2174
- const write = () => storeSetter(e, reconcile(t, n));
2175
- i ? i(write) : write();
2176
- };
2177
- commit(handleAsync(r, o, commit));
2178
- });
2179
- return r;
2180
- }
2181
- function createWriteTraps(e) {
2182
- const t = {
2183
- get(e, n) {
2184
- let i;
2185
- setWriteOverride(true);
2186
- setProjectionWriteActive(true);
2187
- try {
2188
- i = e[n];
2189
- } finally {
2190
- setWriteOverride(false);
2191
- setProjectionWriteActive(false);
2192
- }
2193
- return typeof i === "object" && i !== null ? new Proxy(i, t) : i;
2194
- },
2195
- has(e, t) {
2196
- let n;
2197
- setWriteOverride(true);
2198
- setProjectionWriteActive(true);
2199
- try {
2200
- n = t in e;
2201
- } finally {
2202
- setWriteOverride(false);
2203
- setProjectionWriteActive(false);
2204
- }
2205
- return n;
2206
- },
2207
- set(t, n, i) {
2208
- if (e && !e()) return true;
2209
- setWriteOverride(true);
2210
- setProjectionWriteActive(true);
2211
- try {
2212
- t[n] = i;
2213
- } finally {
2214
- setWriteOverride(false);
2215
- setProjectionWriteActive(false);
2216
- }
2217
- return true;
2218
- },
2219
- deleteProperty(t, n) {
2220
- if (e && !e()) return true;
2221
- setWriteOverride(true);
2222
- setProjectionWriteActive(true);
2223
- try {
2224
- delete t[n];
2225
- } finally {
2226
- setWriteOverride(false);
2227
- setProjectionWriteActive(false);
2228
- }
2229
- return true;
2230
- }
2231
- };
2232
- return t;
2233
- }
2234
- const $TRACK = Symbol(0),
2235
- $TARGET = Symbol(0),
2236
- $PROXY = Symbol(0),
2237
- $DELETED = Symbol(0);
2238
- const STORE_VALUE = "v",
2239
- STORE_OVERRIDE = "o",
2240
- STORE_OPTIMISTIC_OVERRIDE = "x",
2241
- STORE_NODE = "n",
2242
- STORE_HAS = "h",
2243
- STORE_WRAP = "w",
2244
- STORE_LOOKUP = "l",
2245
- STORE_FIREWALL = "f",
2246
- STORE_OPTIMISTIC = "p";
2247
- function createStoreProxy(e, t = storeTraps, n) {
2248
- let i;
2249
- if (Array.isArray(e)) {
2250
- i = [];
2251
- i.v = e;
2252
- } else i = { v: e };
2253
- n && n(i);
2254
- return (i[$PROXY] = new Proxy(i, t));
2255
- }
2256
- const storeLookup = new WeakMap();
2257
- function wrap(e, t) {
2258
- if (t?.[STORE_WRAP]) return t[STORE_WRAP](e, t);
2259
- let n = e[$PROXY] || storeLookup.get(e);
2260
- if (!n) storeLookup.set(e, (n = createStoreProxy(e)));
2261
- return n;
2262
- }
2263
- function isWrappable(e) {
2264
- return (
2265
- e != null &&
2266
- typeof e === "object" &&
2267
- !Object.isFrozen(e) &&
2268
- !(typeof Node !== "undefined" && e instanceof Node)
2269
- );
2270
- }
2271
- let writeOverride = false;
2272
- function setWriteOverride(e) {
2273
- writeOverride = e;
2274
- }
2275
- function writeOnly(e) {
2276
- return writeOverride || !!Writing?.has(e);
2277
- }
2278
- function getNodes(e, t) {
2279
- let n = e[t];
2280
- if (!n) e[t] = n = Object.create(null);
2281
- return n;
2282
- }
2283
- function getNode(e, t, n, i, r = isEqual, s, o) {
2284
- if (e[t]) return e[t];
2285
- const u = signal(
2286
- n,
2287
- {
2288
- equals: r,
2289
- unobserved() {
2290
- if (e[t] === u) delete e[t];
2291
- }
2292
- },
2293
- i
2294
- );
2295
- if (s) {
2296
- u.k = NOT_PENDING;
2297
- }
2298
- if (o && t in o) {
2299
- const e = o[t];
2300
- u.Te = e === undefined ? NO_SNAPSHOT : e;
2301
- snapshotSources?.add(u);
2302
- }
2303
- return (e[t] = u);
2304
- }
2305
- function trackSelf(e, t = $TRACK) {
2306
- getObserver() &&
2307
- read(
2308
- getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL], false, e[STORE_OPTIMISTIC])
2309
- );
2310
- }
2311
- function getKeys(e, t, n = true) {
2312
- const i = untrack(() => (n ? Object.keys(e) : Reflect.ownKeys(e)));
2313
- if (!t) return i;
2314
- const r = new Set(i);
2315
- const s = Reflect.ownKeys(t);
2316
- for (const e of s) {
2317
- if (t[e] !== $DELETED) r.add(e);
2318
- else r.delete(e);
2319
- }
2320
- return Array.from(r);
2321
- }
2322
- function getPropertyDescriptor(e, t, n) {
2323
- if (t && n in t) {
2324
- if (t[n] === $DELETED) return void 0;
2325
- const i = Reflect.getOwnPropertyDescriptor(t, n);
2326
- if (i?.get || i?.set || !(n in e)) return i;
2327
- }
2328
- return Reflect.getOwnPropertyDescriptor(e, n);
2329
- }
2330
- function prepareStoreWrite(e, t, n) {
2331
- if (e[STORE_OPTIMISTIC]) {
2332
- const t = e[STORE_FIREWALL];
2333
- if (t?.B) {
2334
- globalQueue.initTransition(t.B);
2335
- }
2336
- }
2337
- const i = e[STORE_VALUE];
2338
- const r = i[n];
2339
- if (
2340
- snapshotCaptureActive &&
2341
- typeof n !== "symbol" &&
2342
- !((e[STORE_FIREWALL]?.Re ?? 0) & STATUS_PENDING)
2343
- ) {
2344
- if (!e[STORE_SNAPSHOT_PROPS]) {
2345
- e[STORE_SNAPSHOT_PROPS] = Object.create(null);
2346
- snapshotSources?.add(e);
2347
- }
2348
- if (!(n in e[STORE_SNAPSHOT_PROPS])) {
2349
- e[STORE_SNAPSHOT_PROPS][n] = r;
2350
- }
2351
- }
2352
- const s = e[STORE_OPTIMISTIC] && !projectionWriteActive;
2353
- const o = s ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
2354
- if (s) trackOptimisticStore(t);
2355
- return { base: r, overrideKey: o, state: i };
2356
- }
2357
- function upsertStoreNode(e, t, n, i, r) {
2358
- if (t[n]) return t[n];
2359
- const s = isWrappable(i) ? wrap(i, e) : i;
2360
- const o = getNode(t, n, s, e[STORE_FIREWALL], isEqual, e[STORE_OPTIMISTIC], r);
2361
- registerTransientStoreNode(o);
2362
- return o;
2363
- }
2364
- function notifyStoreProperty(e, t, n, i, r, s) {
2365
- const o = projectionWriteActive || e[STORE_OPTIMISTIC];
2366
- const u = n !== "delete";
2367
- const c = e[STORE_HAS]?.[t];
2368
- if (c) {
2369
- setSignal(c, u);
2370
- } else if (!o && n !== "invalidate" && s !== u) {
2371
- const n = upsertStoreNode(e, getNodes(e, STORE_HAS), t, s);
2372
- setSignal(n, u);
2373
- }
2374
- const a = getNodes(e, STORE_NODE);
2375
- if (n === "set") {
2376
- if (a[t]) {
2377
- setSignal(a[t], () => (isWrappable(i) ? wrap(i, e) : i));
2378
- } else if (!o) {
2379
- const n = upsertStoreNode(e, a, t, r, e[STORE_SNAPSHOT_PROPS]);
2380
- setSignal(n, () => (isWrappable(i) ? wrap(i, e) : i));
2381
- }
2382
- } else if (n === "invalidate") {
2383
- if (a[t]) {
2384
- setSignal(a[t], {});
2385
- delete a[t];
2386
- }
2387
- } else {
2388
- if (a[t]) {
2389
- setSignal(a[t], undefined);
2390
- } else if (!o) {
2391
- const n = upsertStoreNode(e, a, t, r, e[STORE_SNAPSHOT_PROPS]);
2392
- setSignal(n, undefined);
2393
- }
2394
- }
2395
- a[$TRACK] && setSignal(a[$TRACK], undefined);
2396
- }
2397
- let Writing = null;
2398
- const storeTraps = {
2399
- get(e, t, n) {
2400
- if (t === $TARGET) return e;
2401
- if (t === $PROXY) return n;
2402
- if (t === $REFRESH) return e[STORE_FIREWALL];
2403
- if (t === $TRACK) {
2404
- trackSelf(e);
2405
- return n;
2406
- }
2407
- const i = getNodes(e, STORE_NODE);
2408
- const r = i[t];
2409
- const s = e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE];
2410
- const o = s || (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]);
2411
- const u = !!e[STORE_VALUE][$TARGET];
2412
- const c = s
2413
- ? e[STORE_OPTIMISTIC_OVERRIDE]
2414
- : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
2415
- ? e[STORE_OVERRIDE]
2416
- : e[STORE_VALUE];
2417
- if (!r) {
2418
- const e = Object.getOwnPropertyDescriptor(c, t);
2419
- if (e && e.get) return e.get.call(n);
2420
- }
2421
- if (writeOnly(n)) {
2422
- let n =
2423
- r && (o || !u)
2424
- ? r.k !== undefined && r.k !== NOT_PENDING
2425
- ? r.k
2426
- : r.U !== NOT_PENDING
2427
- ? r.U
2428
- : r.te
2429
- : c[t];
2430
- n === $DELETED && (n = undefined);
2431
- if (!isWrappable(n)) return n;
2432
- const i = wrap(n, e);
2433
- Writing?.add(i);
2434
- return i;
2435
- }
2436
- let a = r ? (o || !u ? read(i[t]) : (read(i[t]), c[t])) : c[t];
2437
- a === $DELETED && (a = undefined);
2438
- if (!r) {
2439
- if (!o && typeof a === "function" && !c.hasOwnProperty(t)) {
2440
- let t;
2441
- return !Array.isArray(e[STORE_VALUE]) &&
2442
- (t = Object.getPrototypeOf(e[STORE_VALUE])) &&
2443
- t !== Object.prototype
2444
- ? a.bind(c)
2445
- : a;
2446
- } else if (getObserver()) {
2447
- return read(
2448
- getNode(
2449
- i,
2450
- t,
2451
- isWrappable(a) ? wrap(a, e) : a,
2452
- e[STORE_FIREWALL],
2453
- isEqual,
2454
- e[STORE_OPTIMISTIC],
2455
- e[STORE_SNAPSHOT_PROPS]
2456
- )
2457
- );
2458
- }
2459
- }
2460
- return isWrappable(a) ? wrap(a, e) : a;
2461
- },
2462
- has(e, t) {
2463
- if (t === $PROXY || t === $TRACK || t === "__proto__") return true;
2464
- const n =
2465
- e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
2466
- ? e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED
2467
- : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
2468
- ? e[STORE_OVERRIDE][t] !== $DELETED
2469
- : t in e[STORE_VALUE];
2470
- if (writeOnly(e[$PROXY])) return n;
2471
- const i = getNodes(e, STORE_HAS);
2472
- if (i[t]) return read(i[t]);
2473
- if (getObserver()) {
2474
- return read(getNode(i, t, n, e[STORE_FIREWALL], isEqual, e[STORE_OPTIMISTIC]));
2475
- }
2476
- return n;
2477
- },
2478
- set(e, t, n) {
2479
- const i = e[$PROXY];
2480
- if (writeOnly(i)) {
2481
- untrack(() => {
2482
- const { base: r, overrideKey: s, state: o } = prepareStoreWrite(e, i, t);
2483
- const u =
2484
- e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
2485
- ? e[STORE_OPTIMISTIC_OVERRIDE][t]
2486
- : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
2487
- ? e[STORE_OVERRIDE][t]
2488
- : r;
2489
- const c =
2490
- e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
2491
- ? e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED
2492
- : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
2493
- ? e[STORE_OVERRIDE][t] !== $DELETED
2494
- : t in e[STORE_VALUE];
2495
- const a = n?.[$TARGET]?.[STORE_VALUE] ?? n;
2496
- const l = Array.isArray(o) && t !== "length";
2497
- const f = l ? parseInt(t) + 1 : 0;
2498
- const E =
2499
- l &&
2500
- (e[STORE_OPTIMISTIC_OVERRIDE] && "length" in e[STORE_OPTIMISTIC_OVERRIDE]
2501
- ? e[STORE_OPTIMISTIC_OVERRIDE].length
2502
- : e[STORE_OVERRIDE] && "length" in e[STORE_OVERRIDE]
2503
- ? e[STORE_OVERRIDE].length
2504
- : o.length);
2505
- const d = l && f > E ? f : undefined;
2506
- if (u === a && d === undefined) return true;
2507
- if (a !== undefined && a === r && d === undefined) delete e[s]?.[t];
2508
- else {
2509
- const n = e[s] || (e[s] = Object.create(null));
2510
- n[t] = a;
2511
- if (d !== undefined) n.length = d;
2512
- }
2513
- notifyStoreProperty(e, t, "set", a, u, c);
2514
- if (Array.isArray(o) && t !== "length" && d !== undefined) {
2515
- const t = getNodes(e, STORE_NODE);
2516
- if (t.length) {
2517
- setSignal(t.length, d);
2518
- } else if (!projectionWriteActive && !e[STORE_OPTIMISTIC]) {
2519
- const n = upsertStoreNode(e, t, "length", E, e[STORE_SNAPSHOT_PROPS]);
2520
- setSignal(n, d);
2521
- }
2522
- }
2523
- if (false);
2524
- });
2525
- }
2526
- return true;
2527
- },
2528
- defineProperty(e, t, n) {
2529
- const i = e[$PROXY];
2530
- if (writeOnly(i)) {
2531
- untrack(() => {
2532
- const { base: r, overrideKey: s } = prepareStoreWrite(e, i, t);
2533
- const o = "value" in n ? { ...n, value: n.value?.[$TARGET]?.[STORE_VALUE] ?? n.value } : n;
2534
- Object.defineProperty(e[s] || (e[s] = Object.create(null)), t, o);
2535
- notifyStoreProperty(e, t, "invalidate");
2536
- if (false);
2537
- });
2538
- }
2539
- return true;
2540
- },
2541
- deleteProperty(e, t) {
2542
- const n = e[STORE_OPTIMISTIC_OVERRIDE]?.[t] === $DELETED;
2543
- const i = e[STORE_OVERRIDE]?.[t] === $DELETED;
2544
- if (writeOnly(e[$PROXY]) && !n && !i) {
2545
- untrack(() => {
2546
- const n = e[STORE_OPTIMISTIC] && !projectionWriteActive;
2547
- const i = n ? STORE_OPTIMISTIC_OVERRIDE : STORE_OVERRIDE;
2548
- if (n) trackOptimisticStore(e[$PROXY]);
2549
- const r =
2550
- e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]
2551
- ? e[STORE_OPTIMISTIC_OVERRIDE][t]
2552
- : e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
2553
- ? e[STORE_OVERRIDE][t]
2554
- : e[STORE_VALUE][t];
2555
- if (t in e[STORE_VALUE] || (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE])) {
2556
- (e[i] || (e[i] = Object.create(null)))[t] = $DELETED;
2557
- } else if (e[i] && t in e[i]) {
2558
- delete e[i][t];
2559
- } else return true;
2560
- notifyStoreProperty(e, t, "delete", undefined, r, true);
2561
- });
2562
- }
2563
- return true;
2564
- },
2565
- ownKeys(e) {
2566
- trackSelf(e);
2567
- let t = getKeys(e[STORE_VALUE], e[STORE_OVERRIDE], false);
2568
- if (e[STORE_OPTIMISTIC_OVERRIDE]) {
2569
- const n = new Set(t);
2570
- for (const t of Reflect.ownKeys(e[STORE_OPTIMISTIC_OVERRIDE])) {
2571
- if (e[STORE_OPTIMISTIC_OVERRIDE][t] !== $DELETED) n.add(t);
2572
- else n.delete(t);
2573
- }
2574
- t = Array.from(n);
2575
- }
2576
- return t;
2577
- },
2578
- getOwnPropertyDescriptor(e, t) {
2579
- if (t === $PROXY) return { value: e[$PROXY], writable: true, configurable: true };
2580
- if (e[STORE_OPTIMISTIC_OVERRIDE] && t in e[STORE_OPTIMISTIC_OVERRIDE]) {
2581
- if (e[STORE_OPTIMISTIC_OVERRIDE][t] === $DELETED) return undefined;
2582
- const n = Reflect.getOwnPropertyDescriptor(e[STORE_OPTIMISTIC_OVERRIDE], t);
2583
- if (n?.get || n?.set || !(t in e[STORE_VALUE])) return n;
2584
- const i = getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
2585
- if (i) {
2586
- return { ...i, value: e[STORE_OPTIMISTIC_OVERRIDE][t] };
2587
- }
2588
- return {
2589
- value: e[STORE_OPTIMISTIC_OVERRIDE][t],
2590
- writable: true,
2591
- enumerable: true,
2592
- configurable: true
2593
- };
2594
- }
2595
- return getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
2596
- },
2597
- getPrototypeOf(e) {
2598
- return Object.getPrototypeOf(e[STORE_VALUE]);
2599
- }
2600
- };
2601
- function storeSetter(e, t) {
2602
- const n = Writing;
2603
- Writing = new Set();
2604
- Writing.add(e);
2605
- try {
2606
- const n = t(e);
2607
- if (n !== e && n !== undefined) {
2608
- if (Array.isArray(n)) {
2609
- for (let t = 0, i = n.length; t < i; t++) e[t] = n[t];
2610
- e.length = n.length;
2611
- } else {
2612
- const t = new Set([...Object.keys(e), ...Object.keys(n)]);
2613
- t.forEach(t => {
2614
- if (t in n) e[t] = n[t];
2615
- else delete e[t];
2616
- });
2617
- }
2618
- }
2619
- } finally {
2620
- Writing.clear();
2621
- Writing = n;
2622
- }
2623
- }
2624
- function createStore(e, t, n) {
2625
- const i = typeof e === "function",
2626
- r = i ? createProjectionInternal(e, t, n).store : wrap(e);
2627
- return [r, e => storeSetter(r, e)];
2628
- }
2629
- function createOptimisticStore(e, t, n) {
2630
- GlobalQueue.ae ||= clearOptimisticStore;
2631
- const i = typeof e === "function";
2632
- const r = i ? t : e;
2633
- const s = i ? e : undefined;
2634
- const { store: o } = createOptimisticProjectionInternal(s, r, n);
2635
- return [o, e => storeSetter(o, e)];
2636
- }
2637
- function clearOptimisticStore(e) {
2638
- const t = e[$TARGET];
2639
- if (!t || !t[STORE_OPTIMISTIC_OVERRIDE]) return;
2640
- const n = t[STORE_OPTIMISTIC_OVERRIDE];
2641
- const i = t[STORE_NODE];
2642
- setProjectionWriteActive(true);
2643
- try {
2644
- if (i) {
2645
- for (const e of Reflect.ownKeys(n)) {
2646
- if (i[e]) {
2647
- i[e].ee = undefined;
2648
- const n =
2649
- t[STORE_OVERRIDE] && e in t[STORE_OVERRIDE] ? t[STORE_OVERRIDE][e] : t[STORE_VALUE][e];
2650
- const r = n === $DELETED ? undefined : n;
2651
- setSignal(i[e], isWrappable(r) ? wrap(r, t) : r);
2652
- }
2653
- }
2654
- if (i[$TRACK]) {
2655
- i[$TRACK].ee = undefined;
2656
- setSignal(i[$TRACK], undefined);
2657
- }
2658
- }
2659
- } finally {
2660
- setProjectionWriteActive(false);
2661
- }
2662
- delete t[STORE_OPTIMISTIC_OVERRIDE];
2663
- }
2664
- function createOptimisticProjectionInternal(e, t, n) {
2665
- let i;
2666
- const r = new WeakMap();
2667
- const wrapper = e => {
2668
- e[STORE_WRAP] = wrapProjection;
2669
- e[STORE_LOOKUP] = r;
2670
- e[STORE_OPTIMISTIC] = true;
2671
- Object.defineProperty(e, STORE_FIREWALL, {
2672
- get() {
2673
- return i;
2674
- },
2675
- configurable: true
2676
- });
2677
- };
2678
- const wrapProjection = e => {
2679
- if (r.has(e)) return r.get(e);
2680
- if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
2681
- const t = createStoreProxy(e, storeTraps, wrapper);
2682
- r.set(e, t);
2683
- return t;
2684
- };
2685
- const s = wrapProjection(t);
2686
- if (e) {
2687
- const wrapCommit = e => {
2688
- setProjectionWriteActive(true);
2689
- try {
2690
- e();
2691
- } finally {
2692
- setProjectionWriteActive(false);
2693
- }
2694
- };
2695
- i = computed(() => {
2696
- setProjectionWriteActive(true);
2697
- try {
2698
- runProjectionComputed(s, e, n?.key || "id", wrapCommit);
2699
- } finally {
2700
- setProjectionWriteActive(false);
2701
- }
2702
- }, undefined);
2703
- i.Pe = true;
2704
- }
2705
- return { store: s, node: i };
2706
- }
2707
- const DELETE = Symbol(0);
2708
- function updatePath(e, t, n = 0) {
2709
- let i,
2710
- r = e;
2711
- if (n < t.length - 1) {
2712
- i = t[n];
2713
- const s = typeof i;
2714
- const o = Array.isArray(e);
2715
- if (Array.isArray(i)) {
2716
- for (let r = 0; r < i.length; r++) {
2717
- t[n] = i[r];
2718
- updatePath(e, t, n);
2719
- }
2720
- t[n] = i;
2721
- return;
2722
- } else if (o && s === "function") {
2723
- for (let r = 0; r < e.length; r++) {
2724
- if (i(e[r], r)) {
2725
- t[n] = r;
2726
- updatePath(e, t, n);
2727
- }
2728
- }
2729
- t[n] = i;
2730
- return;
2731
- } else if (o && s === "object") {
2732
- const { from: r = 0, to: s = e.length - 1, by: o = 1 } = i;
2733
- for (let i = r; i <= s; i += o) {
2734
- t[n] = i;
2735
- updatePath(e, t, n);
2736
- }
2737
- t[n] = i;
2738
- return;
2739
- } else if (n < t.length - 2) {
2740
- updatePath(e[i], t, n + 1);
2741
- return;
2742
- }
2743
- r = e[i];
2744
- }
2745
- let s = t[t.length - 1];
2746
- if (typeof s === "function") {
2747
- s = s(r);
2748
- if (s === r) return;
2749
- }
2750
- if (i === undefined && s == undefined) return;
2751
- if (s === DELETE) {
2752
- delete e[i];
2753
- } else if (i === undefined || (isWrappable(r) && isWrappable(s) && !Array.isArray(s))) {
2754
- const t = i !== undefined ? e[i] : e;
2755
- const n = Object.keys(s);
2756
- for (let e = 0; e < n.length; e++) {
2757
- const i = n[e];
2758
- const r = Object.getOwnPropertyDescriptor(s, i);
2759
- if (r.get || r.set) Object.defineProperty(t, i, r);
2760
- else t[i] = r.value;
2761
- }
2762
- } else {
2763
- e[i] = s;
2764
- }
2765
- }
2766
- const storePath = Object.assign(
2767
- function storePath(...e) {
2768
- return t => {
2769
- updatePath(t, e);
2770
- };
2771
- },
2772
- { DELETE: DELETE }
2773
- );
2774
- function snapshotImpl(e, t, n, i) {
2775
- let r, s, o, u, c, a;
2776
- if (!isWrappable(e)) return e;
2777
- if (n && n.has(e)) return n.get(e);
2778
- if (!n) n = new Map();
2779
- if ((r = e[$TARGET] || i?.get(e)?.[$TARGET])) {
2780
- if (t) trackSelf(r, $TRACK);
2781
- o = r[STORE_OVERRIDE];
2782
- s = Array.isArray(r[STORE_VALUE]);
2783
- n.set(
2784
- e,
2785
- o ? (u = s ? [] : Object.create(Object.getPrototypeOf(r[STORE_VALUE]))) : r[STORE_VALUE]
2786
- );
2787
- e = r[STORE_VALUE];
2788
- i = storeLookup;
2789
- } else {
2790
- s = Array.isArray(e);
2791
- n.set(e, e);
2792
- }
2793
- if (s) {
2794
- const s = o?.length || e.length;
2795
- for (let l = 0; l < s; l++) {
2796
- a = o && l in o ? o[l] : e[l];
2797
- if (a === $DELETED) continue;
2798
- if (t && isWrappable(a)) wrap(a, r);
2799
- if ((c = snapshotImpl(a, t, n, i)) !== a || u) {
2800
- if (!u) n.set(e, (u = [...e]));
2801
- u[l] = c;
2802
- }
2803
- }
2804
- } else {
2805
- const s = getKeys(e, o);
2806
- for (let l = 0, f = s.length; l < f; l++) {
2807
- let f = s[l];
2808
- const E = getPropertyDescriptor(e, o, f);
2809
- if (E.get) continue;
2810
- a = o && f in o ? o[f] : e[f];
2811
- if (t && isWrappable(a)) wrap(a, r);
2812
- if ((c = snapshotImpl(a, t, n, i)) !== e[f] || u) {
2813
- if (!u) {
2814
- u = Object.create(Object.getPrototypeOf(e));
2815
- Object.assign(u, e);
2816
- }
2817
- u[f] = c;
2818
- }
2819
- }
2820
- }
2821
- return u || e;
2822
- }
2823
- function snapshot(e, t, n) {
2824
- return snapshotImpl(e, false, t, n);
2825
- }
2826
- function deep(e) {
2827
- return snapshotImpl(e, true);
2828
- }
2829
- function trueFn() {
2830
- return true;
2831
- }
2832
- const propTraps = {
2833
- get(e, t, n) {
2834
- if (t === $PROXY) return n;
2835
- return e.get(t);
2836
- },
2837
- has(e, t) {
2838
- if (t === $PROXY) return true;
2839
- return e.has(t);
2840
- },
2841
- set: trueFn,
2842
- deleteProperty: trueFn,
2843
- getOwnPropertyDescriptor(e, t) {
2844
- return {
2845
- configurable: true,
2846
- enumerable: true,
2847
- get() {
2848
- return e.get(t);
2849
- },
2850
- set: trueFn,
2851
- deleteProperty: trueFn
2852
- };
2853
- },
2854
- ownKeys(e) {
2855
- return e.keys();
2856
- }
2857
- };
2858
- function resolveSource(e) {
2859
- return !(e = typeof e === "function" ? e() : e) ? {} : e;
2860
- }
2861
- const $SOURCES = Symbol(0);
2862
- function merge(...e) {
2863
- if (e.length === 1 && typeof e[0] !== "function") return e[0];
2864
- let t = false;
2865
- const n = [];
2866
- for (let i = 0; i < e.length; i++) {
2867
- const r = e[i];
2868
- t = t || (!!r && $PROXY in r);
2869
- const s = !!r && r[$SOURCES];
2870
- if (s) n.push(...s);
2871
- else n.push(typeof r === "function" ? ((t = true), createMemo(r)) : r);
2872
- }
2873
- if (SUPPORTS_PROXY && t) {
2874
- return new Proxy(
2875
- {
2876
- get(e) {
2877
- if (e === $SOURCES) return n;
2878
- for (let t = n.length - 1; t >= 0; t--) {
2879
- const i = resolveSource(n[t]);
2880
- if (e in i) return i[e];
2881
- }
2882
- },
2883
- has(e) {
2884
- for (let t = n.length - 1; t >= 0; t--) {
2885
- if (e in resolveSource(n[t])) return true;
2886
- }
2887
- return false;
2888
- },
2889
- keys() {
2890
- const e = [];
2891
- for (let t = 0; t < n.length; t++) e.push(...Object.keys(resolveSource(n[t])));
2892
- return [...new Set(e)];
2893
- }
2894
- },
2895
- propTraps
2896
- );
2897
- }
2898
- const i = Object.create(null);
2899
- let r = false;
2900
- let s = n.length - 1;
2901
- for (let e = s; e >= 0; e--) {
2902
- const t = n[e];
2903
- if (!t) {
2904
- e === s && s--;
2905
- continue;
2906
- }
2907
- const o = Object.getOwnPropertyNames(t);
2908
- for (let n = o.length - 1; n >= 0; n--) {
2909
- const u = o[n];
2910
- if (u === "__proto__" || u === "constructor") continue;
2911
- if (!i[u]) {
2912
- r = r || e !== s;
2913
- const n = Object.getOwnPropertyDescriptor(t, u);
2914
- i[u] = n.get ? { enumerable: true, configurable: true, get: n.get.bind(t) } : n;
2915
- }
2916
- }
2917
- }
2918
- if (!r) return n[s];
2919
- const o = {};
2920
- const u = Object.keys(i);
2921
- for (let e = u.length - 1; e >= 0; e--) {
2922
- const t = u[e],
2923
- n = i[t];
2924
- if (n.get) Object.defineProperty(o, t, n);
2925
- else o[t] = n.value;
2926
- }
2927
- o[$SOURCES] = n;
2928
- return o;
2929
- }
2930
- function omit(e, ...t) {
2931
- const n = new Set(t);
2932
- if (SUPPORTS_PROXY && $PROXY in e) {
2933
- return new Proxy(
2934
- {
2935
- get(t) {
2936
- return n.has(t) ? undefined : e[t];
2937
- },
2938
- has(t) {
2939
- return !n.has(t) && t in e;
2940
- },
2941
- keys() {
2942
- return Object.keys(e).filter(e => !n.has(e));
2943
- }
2944
- },
2945
- propTraps
2946
- );
2947
- }
2948
- const i = {};
2949
- for (const t of Object.getOwnPropertyNames(e)) {
2950
- if (!n.has(t)) {
2951
- const n = Object.getOwnPropertyDescriptor(e, t);
2952
- !n.get && !n.set && n.enumerable && n.writable && n.configurable
2953
- ? (i[t] = n.value)
2954
- : Object.defineProperty(i, t, n);
2955
- }
2956
- }
2957
- return i;
2958
- }
2959
- function mapArray(e, t, n) {
2960
- const i = typeof n?.keyed === "function" ? n.keyed : undefined;
2961
- const r = t.length > 1;
2962
- const s = t;
2963
- const o = computed(
2964
- updateKeyedMap.bind({
2965
- Ye: createOwner(),
2966
- Ze: 0,
2967
- Be: e,
2968
- qe: [],
2969
- Xe: s,
2970
- ze: [],
2971
- Je: [],
2972
- et: i,
2973
- tt: i || n?.keyed === false ? [] : undefined,
2974
- nt: r ? [] : undefined,
2975
- it: n?.fallback
2976
- })
2977
- );
2978
- o.Pe = true;
2979
- return accessor(o);
2980
- }
2981
- const pureOptions = { ownedWrite: true };
2982
- function updateKeyedMap() {
2983
- const e = this.Be() || [],
2984
- t = e.length;
2985
- e[$TRACK];
2986
- runWithOwner(this.Ye, () => {
2987
- let n,
2988
- i,
2989
- r = this.tt
2990
- ? () => {
2991
- this.tt[i] = signal(e[i], pureOptions);
2992
- this.nt && (this.nt[i] = signal(i, pureOptions));
2993
- return this.Xe(accessor(this.tt[i]), this.nt ? accessor(this.nt[i]) : undefined);
2994
- }
2995
- : this.nt
2996
- ? () => {
2997
- const t = e[i];
2998
- this.nt[i] = signal(i, pureOptions);
2999
- return this.Xe(() => t, accessor(this.nt[i]));
3000
- }
3001
- : () => {
3002
- const t = e[i];
3003
- return this.Xe(() => t);
3004
- };
3005
- if (t === 0) {
3006
- if (this.Ze !== 0) {
3007
- this.Ye.dispose(false);
3008
- this.Je = [];
3009
- this.qe = [];
3010
- this.ze = [];
3011
- this.Ze = 0;
3012
- this.tt && (this.tt = []);
3013
- this.nt && (this.nt = []);
3014
- }
3015
- if (this.it && !this.ze[0]) {
3016
- this.ze[0] = runWithOwner((this.Je[0] = createOwner()), this.it);
3017
- }
3018
- } else if (this.Ze === 0) {
3019
- if (this.Je[0]) this.Je[0].dispose();
3020
- this.ze = new Array(t);
3021
- for (i = 0; i < t; i++) {
3022
- this.qe[i] = e[i];
3023
- this.ze[i] = runWithOwner((this.Je[i] = createOwner()), r);
3024
- }
3025
- this.Ze = t;
3026
- } else {
3027
- let s,
3028
- o,
3029
- u,
3030
- c,
3031
- a,
3032
- l,
3033
- f,
3034
- E = new Array(t),
3035
- d = new Array(t),
3036
- T = this.tt ? new Array(t) : undefined,
3037
- S = this.nt ? new Array(t) : undefined;
3038
- for (
3039
- s = 0, o = Math.min(this.Ze, t);
3040
- s < o && (this.qe[s] === e[s] || (this.tt && compare(this.et, this.qe[s], e[s])));
3041
- s++
3042
- ) {
3043
- if (this.tt) setSignal(this.tt[s], e[s]);
3044
- }
3045
- for (
3046
- o = this.Ze - 1, u = t - 1;
3047
- o >= s &&
3048
- u >= s &&
3049
- (this.qe[o] === e[u] || (this.tt && compare(this.et, this.qe[o], e[u])));
3050
- o--, u--
3051
- ) {
3052
- E[u] = this.ze[o];
3053
- d[u] = this.Je[o];
3054
- T && (T[u] = this.tt[o]);
3055
- S && (S[u] = this.nt[o]);
3056
- }
3057
- l = new Map();
3058
- f = new Array(u + 1);
3059
- for (i = u; i >= s; i--) {
3060
- c = e[i];
3061
- a = this.et ? this.et(c) : c;
3062
- n = l.get(a);
3063
- f[i] = n === undefined ? -1 : n;
3064
- l.set(a, i);
3065
- }
3066
- for (n = s; n <= o; n++) {
3067
- c = this.qe[n];
3068
- a = this.et ? this.et(c) : c;
3069
- i = l.get(a);
3070
- if (i !== undefined && i !== -1) {
3071
- E[i] = this.ze[n];
3072
- d[i] = this.Je[n];
3073
- T && (T[i] = this.tt[n]);
3074
- S && (S[i] = this.nt[n]);
3075
- i = f[i];
3076
- l.set(a, i);
3077
- } else this.Je[n].dispose();
3078
- }
3079
- for (i = s; i < t; i++) {
3080
- if (i in E) {
3081
- this.ze[i] = E[i];
3082
- this.Je[i] = d[i];
3083
- if (T) {
3084
- this.tt[i] = T[i];
3085
- setSignal(this.tt[i], e[i]);
3086
- }
3087
- if (S) {
3088
- this.nt[i] = S[i];
3089
- setSignal(this.nt[i], i);
3090
- }
3091
- } else {
3092
- this.ze[i] = runWithOwner((this.Je[i] = createOwner()), r);
3093
- }
3094
- }
3095
- this.ze = this.ze.slice(0, (this.Ze = t));
3096
- this.qe = e.slice(0);
3097
- }
3098
- });
3099
- return this.ze;
3100
- }
3101
- function repeat(e, t, n) {
3102
- const i = t;
3103
- const r = computed(
3104
- updateRepeat.bind({
3105
- Ye: createOwner(),
3106
- Ze: 0,
3107
- rt: 0,
3108
- st: e,
3109
- Xe: i,
3110
- Je: [],
3111
- ze: [],
3112
- ot: n?.from,
3113
- it: n?.fallback
3114
- })
3115
- );
3116
- r.Pe = true;
3117
- return accessor(r);
3118
- }
3119
- function updateRepeat() {
3120
- const e = this.st();
3121
- const t = this.ot?.() || 0;
3122
- runWithOwner(this.Ye, () => {
3123
- if (e === 0) {
3124
- if (this.Ze !== 0) {
3125
- this.Ye.dispose(false);
3126
- this.Je = [];
3127
- this.ze = [];
3128
- this.Ze = 0;
3129
- }
3130
- if (this.it && !this.ze[0]) {
3131
- this.ze[0] = runWithOwner((this.Je[0] = createOwner()), this.it);
3132
- }
3133
- return;
3134
- }
3135
- const n = t + e;
3136
- const i = this.rt + this.Ze;
3137
- if (this.Ze === 0 && this.Je[0]) this.Je[0].dispose();
3138
- for (let e = n; e < i; e++) this.Je[e - this.rt].dispose();
3139
- if (this.rt < t) {
3140
- let e = this.rt;
3141
- while (e < t && e < this.Ze) this.Je[e++].dispose();
3142
- this.Je.splice(0, t - this.rt);
3143
- this.ze.splice(0, t - this.rt);
3144
- } else if (this.rt > t) {
3145
- let n = i - this.rt - 1;
3146
- let r = this.rt - t;
3147
- this.Je.length = this.ze.length = e;
3148
- while (n >= r) {
3149
- this.Je[n] = this.Je[n - r];
3150
- this.ze[n] = this.ze[n - r];
3151
- n--;
3152
- }
3153
- for (let e = 0; e < r; e++) {
3154
- this.ze[e] = runWithOwner((this.Je[e] = createOwner()), () => this.Xe(e + t));
3155
- }
3156
- }
3157
- for (let e = i; e < n; e++) {
3158
- this.ze[e - t] = runWithOwner((this.Je[e - t] = createOwner()), () => this.Xe(e));
3159
- }
3160
- this.ze = this.ze.slice(0, e);
3161
- this.rt = t;
3162
- this.Ze = e;
3163
- });
3164
- return this.ze;
3165
- }
3166
- function compare(e, t, n) {
3167
- return e ? e(t) === e(n) : true;
3168
- }
3169
- function boundaryComputed(e, t) {
3170
- const n = computed(e, { lazy: true });
3171
- n.xe = (e, t) => {
3172
- const i = e !== undefined ? e : n.Re;
3173
- const r = t !== undefined ? t : n.Ee;
3174
- n.Re &= ~n.ut;
3175
- n.$.notify(n, n.ut, i, r);
3176
- };
3177
- n.ut = t;
3178
- n.Pe = true;
3179
- recompute(n, true);
3180
- return n;
3181
- }
3182
- function createBoundChildren(e, t, n, i) {
3183
- const r = e.$;
3184
- r.addChild((e.$ = n));
3185
- cleanup(() => r.removeChild(e.$));
3186
- return runWithOwner(e, () => {
3187
- const e = computed(t);
3188
- return boundaryComputed(() => staleValues(() => flatten(read(e))), i);
3189
- });
3190
- }
3191
- const ON_INIT = Symbol();
3192
- const RevealControllerContext = createContext(null);
3193
- let _revealUsed = false;
3194
- const FALSE_ACCESSOR = () => false;
3195
- const SEQUENTIAL_ACCESSOR = () => "sequential";
3196
- function isRevealController(e) {
3197
- return e instanceof RevealController;
3198
- }
3199
- function isSlotReady(e) {
3200
- return isRevealController(e) ? e.isReady() : e.ct.size === 0 && !e.lt;
3201
- }
3202
- function isSlotMinimallyReady(e) {
3203
- return isRevealController(e) ? e.isMinimallyReady() : isSlotReady(e);
3204
- }
3205
- function setSlotState(e, t, n, i) {
3206
- setSignal(e.ft, n);
3207
- setSignal(e.Et, i);
3208
- if (isRevealController(e)) {
3209
- if (!n && e.dt === t) e.dt = undefined;
3210
- return e.evaluate(n, i);
3211
- }
3212
- if (!n && e.Tt === t && e.St) e.Tt = undefined;
3213
- }
3214
- class RevealController {
3215
- Rt;
3216
- Ot;
3217
- _t = [];
3218
- dt;
3219
- ft = signal(false, { ownedWrite: true, He: true });
3220
- Et = signal(false, { ownedWrite: true, He: true });
3221
- It = true;
3222
- ht = true;
3223
- At = false;
3224
- constructor(e, t) {
3225
- this.Rt = e;
3226
- this.Ot = t;
3227
- }
3228
- Nt(e) {
3229
- for (let t = 0; t < this._t.length; t++) {
3230
- const n = this._t[t];
3231
- if ((isRevealController(n) ? n.dt : n.Tt) !== this) continue;
3232
- if (e(n) === false) return false;
3233
- }
3234
- return true;
3235
- }
3236
- isReady() {
3237
- return this.Nt(isSlotReady);
3238
- }
3239
- isMinimallyReady() {
3240
- const e = untrack(this.Rt);
3241
- if (e === "together") return this.isReady();
3242
- if (e === "natural") {
3243
- let e = false;
3244
- let t = false;
3245
- this.Nt(n => {
3246
- e = true;
3247
- if (isSlotMinimallyReady(n)) {
3248
- t = true;
3249
- return false;
3250
- }
3251
- });
3252
- return !e || t;
3253
- }
3254
- let t = true;
3255
- this.Nt(e => {
3256
- t = isSlotMinimallyReady(e);
3257
- return false;
3258
- });
3259
- return t;
3260
- }
3261
- register(e) {
3262
- if (this._t.includes(e)) return;
3263
- this._t.push(e);
3264
- const t = untrack(this.Rt);
3265
- (setSignal(e.ft, true), setSignal(e.Et, t === "sequential" ? !!untrack(this.Ot) : false));
3266
- untrack(() => this.evaluate());
3267
- }
3268
- unregister(e) {
3269
- const t = this._t.indexOf(e);
3270
- if (t >= 0) this._t.splice(t, 1);
3271
- untrack(() => this.evaluate());
3272
- }
3273
- evaluate(e, t) {
3274
- if (this.At) return;
3275
- this.At = true;
3276
- const n = this.It;
3277
- const i = this.ht;
3278
- try {
3279
- const n = e ?? read(this.ft),
3280
- i = untrack(this.Rt),
3281
- r = i === "sequential" && !!untrack(this.Ot),
3282
- s = t ?? r;
3283
- if (n) {
3284
- this.Nt(e => setSlotState(e, this, true, s));
3285
- } else if (i === "natural") {
3286
- this.Nt(e => {
3287
- if (isRevealController(e)) {
3288
- setSignal(e.Et, false);
3289
- setSignal(e.ft, false);
3290
- e.evaluate(false, false);
3291
- } else {
3292
- setSlotState(e, this, !isSlotReady(e), false);
3293
- }
3294
- });
3295
- } else if (i === "together") {
3296
- const e = this.Nt(isSlotMinimallyReady);
3297
- this.Nt(t => setSlotState(t, this, !e, false));
3298
- } else {
3299
- let e = false;
3300
- this.Nt(t => {
3301
- if (e) return setSlotState(t, this, true, r);
3302
- if (isSlotReady(t)) return setSlotState(t, this, false, false);
3303
- e = true;
3304
- if (isRevealController(t)) {
3305
- setSignal(t.Et, false);
3306
- setSignal(t.ft, false);
3307
- t.evaluate(false, false);
3308
- } else {
3309
- setSlotState(t, this, true, false);
3310
- }
3311
- });
3312
- }
3313
- } finally {
3314
- this.It = this.isReady();
3315
- this.ht = this.isMinimallyReady();
3316
- this.At = false;
3317
- }
3318
- if (this.dt && (n !== this.It || i !== this.ht)) this.dt.evaluate();
3319
- }
3320
- }
3321
- class CollectionQueue extends Queue {
3322
- Pt;
3323
- ct = new Set();
3324
- gt;
3325
- lt = true;
3326
- ft = signal(false, { ownedWrite: true, He: true });
3327
- Et = signal(false, { ownedWrite: true, He: true });
3328
- Tt;
3329
- St = false;
3330
- Ct;
3331
- Dt = ON_INIT;
3332
- constructor(e) {
3333
- super();
3334
- this.Pt = e;
3335
- }
3336
- run(e) {
3337
- if (!e || (read(this.ft) && (!_revealUsed || read(this.Et)))) return;
3338
- return super.run(e);
3339
- }
3340
- notify(e, t, n, i) {
3341
- if (!(t & this.Pt)) return super.notify(e, t, n, i);
3342
- if (this.St && this.Ct) {
3343
- const e = untrack(() => {
3344
- try {
3345
- return this.Ct();
3346
- } catch {
3347
- return ON_INIT;
3348
- }
3349
- });
3350
- if (e !== this.Dt) {
3351
- this.Dt = e;
3352
- this.St = false;
3353
- this.ct.clear();
3354
- }
3355
- }
3356
- if (this.Pt & STATUS_PENDING && this.St) return super.notify(e, t, n, i);
3357
- if (this.Pt & STATUS_PENDING && n & STATUS_ERROR) {
3358
- return super.notify(e, STATUS_ERROR, n, i);
3359
- }
3360
- if (n & this.Pt) {
3361
- this.lt = true;
3362
- const t = i?.source || e.Ee?.source;
3363
- if (t) {
3364
- const e = this.ct.size === 0;
3365
- this.ct.add(t);
3366
- if (e) setSignal(this.ft, true);
3367
- }
3368
- }
3369
- t &= ~this.Pt;
3370
- return t ? super.notify(e, t, n, i) : true;
3371
- }
3372
- checkSources() {
3373
- for (const e of this.ct) {
3374
- if (
3375
- e.O & REACTIVE_DISPOSED ||
3376
- (!(e.Re & this.Pt) && !(this.Pt & STATUS_ERROR && e.Re & STATUS_PENDING))
3377
- )
3378
- this.ct.delete(e);
3379
- }
3380
- if (!this.ct.size) {
3381
- if (this.Pt & STATUS_PENDING && this.lt && !this.St && this.gt) {
3382
- this.lt = !!(this.gt.Re & this.Pt);
3383
- } else {
3384
- this.lt = false;
3385
- }
3386
- if (!this.lt) {
3387
- setSignal(this.ft, false);
3388
- if (this.Ct) {
3389
- try {
3390
- this.Dt = untrack(() => this.Ct());
3391
- } catch {}
3392
- }
3393
- }
3394
- }
3395
- if (_revealUsed) this.Tt?.evaluate();
3396
- }
3397
- }
3398
- function createCollectionBoundary(e, t, n, i) {
3399
- const r = createOwner();
3400
- if (_revealUsed) setContext(RevealControllerContext, null, r);
3401
- const s = new CollectionQueue(e);
3402
- if (i) s.Ct = i;
3403
- const o = (s.gt = createBoundChildren(r, t, s, e));
3404
- untrack(() => {
3405
- let t = false;
3406
- try {
3407
- read(o);
3408
- } catch (e) {
3409
- if (e instanceof NotReadyError) t = true;
3410
- else throw e;
3411
- }
3412
- s.lt = t || !!(o.Re & e) || o.Ee instanceof NotReadyError;
3413
- });
3414
- const u = _revealUsed && e === STATUS_PENDING ? getContext(RevealControllerContext) : null;
3415
- if (u) {
3416
- s.Tt = u;
3417
- u.register(s);
3418
- cleanup(() => u.unregister(s));
3419
- }
3420
- const c = computed(() => {
3421
- if (!read(s.ft)) {
3422
- const e = read(o);
3423
- if (!untrack(() => read(s.ft))) return ((s.St = true), e);
3424
- }
3425
- if (_revealUsed && read(s.Et)) return undefined;
3426
- return n(s);
3427
- });
3428
- return accessor(c);
3429
- }
3430
- function createLoadingBoundary(e, t, n) {
3431
- return createCollectionBoundary(STATUS_PENDING, e, () => t(), n?.on);
3432
- }
3433
- function createErrorBoundary(e, t) {
3434
- return createCollectionBoundary(STATUS_ERROR, e, e => {
3435
- let n = e.ct.values().next().value;
3436
- const i = n.Ee?.cause ?? n.Ee;
3437
- return t(i, () => {
3438
- for (const t of e.ct) recompute(t);
3439
- schedule();
3440
- });
3441
- });
3442
- }
3443
- function createRevealOrder(e, t) {
3444
- _revealUsed = true;
3445
- const n = createOwner();
3446
- const i = getContext(RevealControllerContext);
3447
- const r = t?.order || SEQUENTIAL_ACCESSOR,
3448
- s = t?.collapsed || FALSE_ACCESSOR;
3449
- const o = new RevealController(r, s);
3450
- setContext(RevealControllerContext, o, n);
3451
- return runWithOwner(n, () => {
3452
- const t = e();
3453
- computed(() => {
3454
- r();
3455
- s();
3456
- o.evaluate();
3457
- });
3458
- if (i) {
3459
- o.dt = i;
3460
- i.register(o);
3461
- cleanup(() => i.unregister(o));
3462
- }
3463
- return t;
3464
- });
3465
- }
3466
- function flatten(e, t) {
3467
- if (typeof e === "function" && !e.length) {
3468
- if (t?.doNotUnwrap) return e;
3469
- do {
3470
- e = e();
3471
- } while (typeof e === "function" && !e.length);
3472
- }
3473
- if (t?.skipNonRendered && (e == null || e === true || e === false || e === "")) return;
3474
- if (Array.isArray(e)) {
3475
- let n = [];
3476
- if (flattenArray(e, n, t)) {
3477
- return () => {
3478
- let e = [];
3479
- flattenArray(n, e, { ...t, doNotUnwrap: false });
3480
- return e;
3481
- };
3482
- }
3483
- return n;
3484
- }
3485
- return e;
3486
- }
3487
- function flattenArray(e, t = [], n) {
3488
- let i = null;
3489
- let r = false;
3490
- for (let s = 0; s < e.length; s++) {
3491
- try {
3492
- let i = e[s];
3493
- if (typeof i === "function" && !i.length) {
3494
- if (n?.doNotUnwrap) {
3495
- t.push(i);
3496
- r = true;
3497
- continue;
3498
- }
3499
- do {
3500
- i = i();
3501
- } while (typeof i === "function" && !i.length);
3502
- }
3503
- if (Array.isArray(i)) {
3504
- r = flattenArray(i, t, n);
3505
- } else if (n?.skipNonRendered && (i == null || i === true || i === false || i === "")) {
3506
- } else t.push(i);
3507
- } catch (e) {
3508
- if (!(e instanceof NotReadyError)) throw e;
3509
- i = e;
3510
- }
3511
- }
3512
- if (i) throw i;
3513
- return r;
3514
- }
3515
- const DEV = undefined;
3516
- export {
3517
- $PROXY,
3518
- $REFRESH,
3519
- $TARGET,
3520
- $TRACK,
3521
- ContextNotFoundError,
3522
- DEV,
3523
- NoOwnerError,
3524
- NotReadyError,
3525
- SUPPORTS_PROXY,
3526
- action,
3527
- clearSnapshots,
3528
- createContext,
3529
- createEffect,
3530
- createErrorBoundary,
3531
- createLoadingBoundary,
3532
- createMemo,
3533
- createOptimistic,
3534
- createOptimisticStore,
3535
- createOwner,
3536
- createProjection,
3537
- createReaction,
3538
- createRenderEffect,
3539
- createRevealOrder,
3540
- createRoot,
3541
- createSignal,
3542
- createStore,
3543
- createTrackedEffect,
3544
- deep,
3545
- enableExternalSource,
3546
- enforceLoadingBoundary,
3547
- flatten,
3548
- flush,
3549
- getContext,
3550
- getNextChildId,
3551
- getObserver,
3552
- getOwner,
3553
- isDisposed,
3554
- isEqual,
3555
- isPending,
3556
- isRefreshing,
3557
- isWrappable,
3558
- latest,
3559
- mapArray,
3560
- markSnapshotScope,
3561
- merge,
3562
- omit,
3563
- onCleanup,
3564
- onSettled,
3565
- peekNextChildId,
3566
- reconcile,
3567
- refresh,
3568
- releaseSnapshotScope,
3569
- repeat,
3570
- resolve,
3571
- runWithOwner,
3572
- setContext,
3573
- setSnapshotCapture,
3574
- snapshot,
3575
- storePath,
3576
- untrack
3577
- };