@solidjs/signals 2.0.0-beta.9 → 2.0.0-rc.1

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