@solidjs/signals 0.8.3 → 0.8.4

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.
package/dist/prod.js CHANGED
@@ -1,728 +1,641 @@
1
- // src/core/error.ts
2
- var NotReadyError = class extends Error {
3
- constructor(cause) {
1
+ class NotReadyError extends Error {
2
+ cause;
3
+ constructor(e) {
4
4
  super();
5
- this.cause = cause;
5
+ this.cause = e;
6
6
  }
7
- };
8
- var NoOwnerError = class extends Error {
7
+ }
8
+ class NoOwnerError extends Error {
9
9
  constructor() {
10
10
  super("");
11
11
  }
12
- };
13
- var ContextNotFoundError = class extends Error {
14
- constructor() {
15
- super(
16
- ""
17
- );
18
- }
19
- };
20
-
21
- // src/core/constants.ts
22
- var NOT_PENDING = {};
23
- var SUPPORTS_PROXY = typeof Proxy === "function";
24
-
25
- // src/core/heap.ts
26
- function actualInsertIntoHeap(n, heap) {
27
- const parentHeight = (n.w?.$ ? n.w.aa?.c : n.w?.c) ?? -1;
28
- if (parentHeight >= n.c)
29
- n.c = parentHeight + 1;
30
- const height = n.c;
31
- const heapAtHeight = heap.s[height];
32
- if (heapAtHeight === void 0) {
33
- heap.s[height] = n;
34
- } else {
35
- const tail = heapAtHeight.z;
36
- tail.Q = n;
37
- n.z = tail;
38
- heapAtHeight.z = n;
39
- }
40
- if (height > heap.L) {
41
- heap.L = height;
42
- }
43
- }
44
- function insertIntoHeap(n, heap) {
45
- let flags = n.b;
46
- if (flags & (8 /* InHeap */ | 4 /* RecomputingDeps */))
47
- return;
48
- if (flags & 1 /* Check */) {
49
- n.b = flags & ~(1 /* Check */ | 2 /* Dirty */) | 2 /* Dirty */ | 8 /* InHeap */;
50
- } else
51
- n.b = flags | 8 /* InHeap */;
52
- if (!(flags & 16 /* InHeapHeight */)) {
53
- actualInsertIntoHeap(n, heap);
54
- }
55
- }
56
- function insertIntoHeapHeight(n, heap) {
57
- let flags = n.b;
58
- if (flags & (8 /* InHeap */ | 4 /* RecomputingDeps */ | 16 /* InHeapHeight */))
59
- return;
60
- n.b = flags | 16 /* InHeapHeight */;
61
- actualInsertIntoHeap(n, heap);
62
- }
63
- function deleteFromHeap(n, heap) {
64
- const flags = n.b;
65
- if (!(flags & (8 /* InHeap */ | 16 /* InHeapHeight */)))
66
- return;
67
- n.b = flags & ~(8 /* InHeap */ | 16 /* InHeapHeight */);
68
- const height = n.c;
69
- if (n.z === n) {
70
- heap.s[height] = void 0;
71
- } else {
72
- const next = n.Q;
73
- const dhh = heap.s[height];
74
- const end = next ?? dhh;
75
- if (n === dhh) {
76
- heap.s[height] = next;
77
- } else {
78
- n.z.Q = next;
79
- }
80
- end.z = n.z;
81
- }
82
- n.z = n;
83
- n.Q = void 0;
84
12
  }
85
- function markHeap(heap) {
86
- if (heap.ba)
87
- return;
88
- heap.ba = true;
89
- for (let i = 0; i <= heap.L; i++) {
90
- for (let el = heap.s[i]; el !== void 0; el = el.Q) {
91
- if (el.b & 8 /* InHeap */)
92
- markNode(el);
93
- }
13
+ class ContextNotFoundError extends Error {
14
+ constructor() {
15
+ super("");
94
16
  }
95
17
  }
96
- function markNode(el, newState = 2 /* Dirty */) {
97
- const flags = el.b;
98
- if ((flags & (1 /* Check */ | 2 /* Dirty */)) >= newState)
99
- return;
100
- el.b = flags & ~(1 /* Check */ | 2 /* Dirty */) | newState;
101
- for (let link2 = el.x; link2 !== null; link2 = link2.A) {
102
- markNode(link2.j, 1 /* Check */);
103
- }
104
- if (el.ca !== null) {
105
- for (let child = el.ca; child !== null; child = child.sa) {
106
- for (let link2 = child.x; link2 !== null; link2 = link2.A) {
107
- markNode(link2.j, 1 /* Check */);
18
+ const REACTIVE_NONE = 0;
19
+ const REACTIVE_CHECK = 1 << 0;
20
+ const REACTIVE_DIRTY = 1 << 1;
21
+ const REACTIVE_RECOMPUTING_DEPS = 1 << 2;
22
+ const REACTIVE_IN_HEAP = 1 << 3;
23
+ const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
24
+ const REACTIVE_ZOMBIE = 1 << 5;
25
+ const REACTIVE_DISPOSED = 1 << 6;
26
+ const STATUS_NONE = 0;
27
+ const STATUS_PENDING = 1 << 0;
28
+ const STATUS_ERROR = 1 << 1;
29
+ const STATUS_UNINITIALIZED = 1 << 2;
30
+ const EFFECT_RENDER = 1;
31
+ const EFFECT_USER = 2;
32
+ const NOT_PENDING = {};
33
+ const SUPPORTS_PROXY = typeof Proxy === "function";
34
+ const defaultContext = {};
35
+ function actualInsertIntoHeap(e, t) {
36
+ const n = (e.i?.t ? e.i.u?.o : e.i?.o) ?? -1;
37
+ if (n >= e.o) e.o = n + 1;
38
+ const i = e.o;
39
+ const r = t.l[i];
40
+ if (r === undefined) t.l[i] = e;
41
+ else {
42
+ const t = r.T;
43
+ t.R = e;
44
+ e.T = t;
45
+ r.T = e;
46
+ }
47
+ if (i > t.h) t.h = i;
48
+ }
49
+ function insertIntoHeap(e, t) {
50
+ let n = e._;
51
+ if (n & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS)) return;
52
+ if (n & REACTIVE_CHECK) {
53
+ e._ = (n & -4) | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
54
+ } else e._ = n | REACTIVE_IN_HEAP;
55
+ if (!(n & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
56
+ }
57
+ function insertIntoHeapHeight(e, t) {
58
+ let n = e._;
59
+ if (n & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT)) return;
60
+ e._ = n | REACTIVE_IN_HEAP_HEIGHT;
61
+ actualInsertIntoHeap(e, t);
62
+ }
63
+ function deleteFromHeap(e, t) {
64
+ const n = e._;
65
+ if (!(n & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
66
+ e._ = n & -25;
67
+ const i = e.o;
68
+ if (e.T === e) t.l[i] = undefined;
69
+ else {
70
+ const n = e.R;
71
+ const r = t.l[i];
72
+ const s = n ?? r;
73
+ if (e === r) t.l[i] = n;
74
+ else e.T.R = n;
75
+ s.T = e.T;
76
+ }
77
+ e.T = e;
78
+ e.R = undefined;
79
+ }
80
+ function markHeap(e) {
81
+ if (e.S) return;
82
+ e.S = true;
83
+ for (let t = 0; t <= e.h; t++) {
84
+ for (let n = e.l[t]; n !== undefined; n = n.R) {
85
+ if (n._ & REACTIVE_IN_HEAP) markNode(n);
86
+ }
87
+ }
88
+ }
89
+ function markNode(e, t = REACTIVE_DIRTY) {
90
+ const n = e._;
91
+ if ((n & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
92
+ e._ = (n & -4) | t;
93
+ for (let t = e.O; t !== null; t = t.p) {
94
+ markNode(t.A, REACTIVE_CHECK);
95
+ }
96
+ if (e.N !== null) {
97
+ for (let t = e.N; t !== null; t = t.I) {
98
+ for (let e = t.O; e !== null; e = e.p) {
99
+ markNode(e.A, REACTIVE_CHECK);
108
100
  }
109
101
  }
110
102
  }
111
103
  }
112
- function runHeap(heap, recompute2) {
113
- heap.ba = false;
114
- for (heap.q = 0; heap.q <= heap.L; heap.q++) {
115
- let el = heap.s[heap.q];
116
- while (el !== void 0) {
117
- if (el.b & 8 /* InHeap */)
118
- recompute2(el);
119
- else {
120
- adjustHeight(el, heap);
121
- }
122
- el = heap.s[heap.q];
104
+ function runHeap(e, t) {
105
+ e.S = false;
106
+ for (e.C = 0; e.C <= e.h; e.C++) {
107
+ let n = e.l[e.C];
108
+ while (n !== undefined) {
109
+ if (n._ & REACTIVE_IN_HEAP) t(n);
110
+ else adjustHeight(n, e);
111
+ n = e.l[e.C];
123
112
  }
124
113
  }
125
- heap.L = 0;
114
+ e.h = 0;
126
115
  }
127
- function adjustHeight(el, heap) {
128
- deleteFromHeap(el, heap);
129
- let newHeight = el.c;
130
- for (let d = el.l; d; d = d.E) {
131
- const dep1 = d.R;
132
- const dep = dep1.ia || dep1;
133
- if (dep.H) {
134
- if (dep.c >= newHeight) {
135
- newHeight = dep.c + 1;
136
- }
137
- }
116
+ function adjustHeight(e, t) {
117
+ deleteFromHeap(e, t);
118
+ let n = e.o;
119
+ for (let t = e.D; t; t = t.P) {
120
+ const e = t.V;
121
+ const i = e.U || e;
122
+ if (i.m && i.o >= n) n = i.o + 1;
138
123
  }
139
- if (el.c !== newHeight) {
140
- el.c = newHeight;
141
- for (let s = el.x; s !== null; s = s.A) {
142
- insertIntoHeapHeight(s.j, heap);
124
+ if (e.o !== n) {
125
+ e.o = n;
126
+ for (let n = e.O; n !== null; n = n.p) {
127
+ insertIntoHeapHeight(n.A, t);
143
128
  }
144
129
  }
145
130
  }
146
-
147
- // src/core/scheduler.ts
148
- var clock = 0;
149
- var activeTransition = null;
150
- var transitions = /* @__PURE__ */ new Set();
151
- var scheduled = false;
131
+ const transitions = new Set();
132
+ const dirtyQueue = { l: new Array(2e3).fill(undefined), S: false, C: 0, h: 0 };
133
+ const zombieQueue = { l: new Array(2e3).fill(undefined), S: false, C: 0, h: 0 };
134
+ let clock = 0;
135
+ let activeTransition = null;
136
+ let scheduled = false;
152
137
  function schedule() {
153
- if (scheduled)
154
- return;
138
+ if (scheduled) return;
155
139
  scheduled = true;
156
- if (!globalQueue.da)
157
- queueMicrotask(flush);
158
- }
159
- var dirtyQueue = {
160
- s: new Array(2e3).fill(void 0),
161
- ba: false,
162
- q: 0,
163
- L: 0
164
- };
165
- var zombieQueue = {
166
- s: new Array(2e3).fill(void 0),
167
- ba: false,
168
- q: 0,
169
- L: 0
170
- };
171
- var Queue = class {
172
- w = null;
173
- k = [[], []];
174
- m = [];
140
+ if (!globalQueue.k) queueMicrotask(flush);
141
+ }
142
+ class Queue {
143
+ i = null;
144
+ G = [[], []];
145
+ H = [];
175
146
  created = clock;
176
- addChild(child) {
177
- this.m.push(child);
178
- child.w = this;
147
+ addChild(e) {
148
+ this.H.push(e);
149
+ e.i = this;
179
150
  }
180
- removeChild(child) {
181
- const index = this.m.indexOf(child);
182
- if (index >= 0) {
183
- this.m.splice(index, 1);
184
- child.w = null;
151
+ removeChild(e) {
152
+ const t = this.H.indexOf(e);
153
+ if (t >= 0) {
154
+ this.H.splice(t, 1);
155
+ e.i = null;
185
156
  }
186
157
  }
187
- notify(node, mask, flags) {
188
- if (this.w)
189
- return this.w.notify(node, mask, flags);
158
+ notify(e, t, n) {
159
+ if (this.i) return this.i.notify(e, t, n);
190
160
  return false;
191
161
  }
192
- run(type) {
193
- if (this.k[type - 1].length) {
194
- const effects = this.k[type - 1];
195
- this.k[type - 1] = [];
196
- runQueue(effects, type);
162
+ run(e) {
163
+ if (this.G[e - 1].length) {
164
+ const t = this.G[e - 1];
165
+ this.G[e - 1] = [];
166
+ runQueue(t, e);
197
167
  }
198
- for (let i = 0; i < this.m.length; i++) {
199
- this.m[i].run(type);
168
+ for (let t = 0; t < this.H.length; t++) {
169
+ this.H[t].run(e);
200
170
  }
201
171
  }
202
- enqueue(type, fn) {
203
- if (type)
204
- this.k[type - 1].push(fn);
172
+ enqueue(e, t) {
173
+ if (e) this.G[e - 1].push(t);
205
174
  schedule();
206
175
  }
207
- stashQueues(stub) {
208
- stub.k[0].push(...this.k[0]);
209
- stub.k[1].push(...this.k[1]);
210
- this.k = [[], []];
211
- for (let i = 0; i < this.m.length; i++) {
212
- let child = this.m[i];
213
- let childStub = stub.m[i];
214
- if (!childStub) {
215
- childStub = { k: [[], []], m: [] };
216
- stub.m[i] = childStub;
176
+ stashQueues(e) {
177
+ e.G[0].push(...this.G[0]);
178
+ e.G[1].push(...this.G[1]);
179
+ this.G = [[], []];
180
+ for (let t = 0; t < this.H.length; t++) {
181
+ let n = this.H[t];
182
+ let i = e.H[t];
183
+ if (!i) {
184
+ i = { G: [[], []], H: [] };
185
+ e.H[t] = i;
217
186
  }
218
- child.stashQueues(childStub);
187
+ n.stashQueues(i);
219
188
  }
220
189
  }
221
- restoreQueues(stub) {
222
- this.k[0].push(...stub.k[0]);
223
- this.k[1].push(...stub.k[1]);
224
- for (let i = 0; i < stub.m.length; i++) {
225
- const childStub = stub.m[i];
226
- let child = this.m[i];
227
- if (child)
228
- child.restoreQueues(childStub);
190
+ restoreQueues(e) {
191
+ this.G[0].push(...e.G[0]);
192
+ this.G[1].push(...e.G[1]);
193
+ for (let t = 0; t < e.H.length; t++) {
194
+ const n = e.H[t];
195
+ let i = this.H[t];
196
+ if (i) i.restoreQueues(n);
229
197
  }
230
198
  }
231
- };
232
- var GlobalQueue = class _GlobalQueue extends Queue {
233
- da = false;
234
- h = [];
235
- static S;
236
- static la;
199
+ }
200
+ class GlobalQueue extends Queue {
201
+ k = false;
202
+ $ = [];
203
+ static L;
204
+ static F;
237
205
  flush() {
238
- if (this.da)
239
- return;
240
- this.da = true;
206
+ if (this.k) return;
207
+ this.k = true;
241
208
  try {
242
- runHeap(dirtyQueue, _GlobalQueue.S);
209
+ runHeap(dirtyQueue, GlobalQueue.L);
243
210
  if (activeTransition) {
244
211
  if (!transitionComplete(activeTransition)) {
245
- runHeap(zombieQueue, _GlobalQueue.S);
246
- globalQueue.h = [];
247
- globalQueue.stashQueues(activeTransition.queueStash);
212
+ runHeap(zombieQueue, GlobalQueue.L);
213
+ this.$ = [];
214
+ this.stashQueues(activeTransition.queueStash);
248
215
  clock++;
249
216
  scheduled = false;
250
217
  runPending(activeTransition.pendingNodes, true);
251
218
  activeTransition = null;
252
219
  return;
253
220
  }
254
- globalQueue.h.push(...activeTransition.pendingNodes);
255
- globalQueue.restoreQueues(activeTransition.queueStash);
221
+ this.$.push(...activeTransition.pendingNodes);
222
+ this.restoreQueues(activeTransition.queueStash);
256
223
  transitions.delete(activeTransition);
257
224
  activeTransition = null;
258
- if (runPending(globalQueue.h, false))
259
- runHeap(dirtyQueue, _GlobalQueue.S);
260
- } else if (transitions.size)
261
- runHeap(zombieQueue, _GlobalQueue.S);
262
- for (let i = 0; i < globalQueue.h.length; i++) {
263
- const n = globalQueue.h[i];
264
- if (n.e !== NOT_PENDING) {
265
- n.g = n.e;
266
- n.e = NOT_PENDING;
225
+ if (runPending(this.$, false)) runHeap(dirtyQueue, GlobalQueue.L);
226
+ } else if (transitions.size) runHeap(zombieQueue, GlobalQueue.L);
227
+ for (let e = 0; e < this.$.length; e++) {
228
+ const t = this.$[e];
229
+ if (t.W !== NOT_PENDING) {
230
+ t.j = t.W;
231
+ t.W = NOT_PENDING;
232
+ if (t.K) t.M = true;
267
233
  }
268
- if (n.H)
269
- _GlobalQueue.la(n, false, true);
234
+ if (t.m) GlobalQueue.F(t, false, true);
270
235
  }
271
- globalQueue.h.length = 0;
236
+ this.$.length = 0;
272
237
  clock++;
273
238
  scheduled = false;
274
- this.run(1 /* Render */);
275
- this.run(2 /* User */);
239
+ this.run(EFFECT_RENDER);
240
+ this.run(EFFECT_USER);
276
241
  } finally {
277
- this.da = false;
242
+ this.k = false;
278
243
  }
279
244
  }
280
- notify(node, mask, flags) {
281
- if (mask & 1 /* Pending */) {
282
- if (flags & 1 /* Pending */) {
283
- if (activeTransition && !activeTransition.asyncNodes.includes(node.B.cause))
284
- activeTransition.asyncNodes.push(node.B.cause);
245
+ notify(e, t, n) {
246
+ if (t & STATUS_PENDING) {
247
+ if (n & STATUS_PENDING) {
248
+ if (activeTransition && !activeTransition.asyncNodes.includes(e.Y.cause))
249
+ activeTransition.asyncNodes.push(e.Y.cause);
285
250
  }
286
251
  return true;
287
252
  }
288
253
  return false;
289
254
  }
290
- initTransition(node) {
291
- if (activeTransition && activeTransition.time === clock)
292
- return;
255
+ initTransition(e) {
256
+ if (activeTransition && activeTransition.time === clock) return;
293
257
  if (!activeTransition) {
294
- activeTransition = node.T ?? {
258
+ activeTransition = e.B ?? {
295
259
  time: clock,
296
260
  pendingNodes: [],
297
261
  asyncNodes: [],
298
- queueStash: { k: [[], []], m: [] }
262
+ queueStash: { G: [[], []], H: [] }
299
263
  };
300
264
  }
301
265
  transitions.add(activeTransition);
302
266
  activeTransition.time = clock;
303
- for (let i = 0; i < globalQueue.h.length; i++) {
304
- const n = globalQueue.h[i];
305
- n.T = activeTransition;
306
- activeTransition.pendingNodes.push(n);
267
+ for (let e = 0; e < this.$.length; e++) {
268
+ const t = this.$[e];
269
+ t.B = activeTransition;
270
+ activeTransition.pendingNodes.push(t);
307
271
  }
308
- globalQueue.h = activeTransition.pendingNodes;
272
+ this.$ = activeTransition.pendingNodes;
309
273
  }
310
- };
311
- function runPending(pendingNodes, value) {
312
- let needsReset = false;
313
- const p = pendingNodes.slice();
314
- for (let i = 0; i < p.length; i++) {
315
- const n = p[i];
316
- n.T = activeTransition;
317
- if (n.I) {
318
- n.I.ea(value);
319
- needsReset = true;
274
+ }
275
+ function runPending(e, t) {
276
+ let n = false;
277
+ const i = e.slice();
278
+ for (let e = 0; e < i.length; e++) {
279
+ const r = i[e];
280
+ r.B = activeTransition;
281
+ if (r.X) {
282
+ r.X.q(t);
283
+ n = true;
284
+ }
285
+ if (r.Z && r.Z.W !== NOT_PENDING) {
286
+ r.Z.q(r.Z.W);
287
+ r.Z.W = NOT_PENDING;
288
+ n = true;
320
289
  }
321
290
  }
322
- return needsReset;
291
+ return n;
323
292
  }
324
- var globalQueue = new GlobalQueue();
293
+ const globalQueue = new GlobalQueue();
325
294
  function flush() {
326
295
  while (scheduled) {
327
296
  globalQueue.flush();
328
297
  }
329
298
  }
330
- function runQueue(queue, type) {
331
- for (let i = 0; i < queue.length; i++)
332
- queue[i](type);
299
+ function runQueue(e, t) {
300
+ for (let n = 0; n < e.length; n++) e[n](t);
333
301
  }
334
- function transitionComplete(transition) {
335
- let done = true;
336
- for (let i = 0; i < transition.asyncNodes.length; i++) {
337
- if (transition.asyncNodes[i].f & 1 /* Pending */) {
338
- done = false;
302
+ function transitionComplete(e) {
303
+ let t = true;
304
+ for (let n = 0; n < e.asyncNodes.length; n++) {
305
+ if (e.asyncNodes[n].J & STATUS_PENDING) {
306
+ t = false;
339
307
  break;
340
308
  }
341
309
  }
342
- return done;
343
- }
344
-
345
- // src/core/core.ts
346
- GlobalQueue.S = recompute;
347
- GlobalQueue.la = disposeChildren;
348
- var tracking = false;
349
- var stale = false;
350
- var pendingValueCheck = false;
351
- var pendingCheck = null;
352
- var context = null;
353
- var defaultContext = {};
354
- function notifySubs(node) {
355
- for (let s = node.x; s !== null; s = s.A) {
356
- const queue = s.j.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue;
357
- if (queue.q > s.j.c)
358
- queue.q = s.j.c;
359
- insertIntoHeap(s.j, queue);
360
- }
361
- }
362
- function recompute(el, create = false) {
363
- deleteFromHeap(el, el.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
364
- if (el.e !== NOT_PENDING || el.U || el.V)
365
- disposeChildren(el);
310
+ return t;
311
+ }
312
+ function runInTransition(e, t) {
313
+ const n = activeTransition;
314
+ activeTransition = e.B;
315
+ t(e);
316
+ activeTransition = n;
317
+ }
318
+ GlobalQueue.L = recompute;
319
+ GlobalQueue.F = disposeChildren;
320
+ let tracking = false;
321
+ let stale = false;
322
+ let pendingValueCheck = false;
323
+ let pendingCheck = null;
324
+ let context = null;
325
+ function notifySubs(e) {
326
+ for (let t = e.O; t !== null; t = t.p) {
327
+ const e = t.A._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
328
+ if (e.C > t.A.o) e.C = t.A.o;
329
+ insertIntoHeap(t.A, e);
330
+ }
331
+ }
332
+ function recompute(e, t = false) {
333
+ deleteFromHeap(e, e._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
334
+ if (e.W !== NOT_PENDING || e.ee || e.te) disposeChildren(e);
366
335
  else {
367
- markDisposal(el);
368
- globalQueue.h.push(el);
369
- el.V = el.t;
370
- el.U = el.r;
371
- el.t = null;
372
- el.r = null;
373
- }
374
- const oldcontext = context;
375
- context = el;
376
- el.F = null;
377
- el.b = 4 /* RecomputingDeps */;
378
- el.J = clock;
379
- let value = el.e === NOT_PENDING ? el.g : el.e;
380
- let oldHeight = el.c;
381
- let prevStatusFlags = el.f;
382
- let prevError = el.B;
383
- let prevTracking = tracking;
384
- clearStatusFlags(el);
336
+ markDisposal(e);
337
+ globalQueue.$.push(e);
338
+ e.te = e.ne;
339
+ e.ee = e.ie;
340
+ e.ne = null;
341
+ e.ie = null;
342
+ }
343
+ const n = context;
344
+ context = e;
345
+ e.re = null;
346
+ e._ = REACTIVE_RECOMPUTING_DEPS;
347
+ e.se = clock;
348
+ let i = e.W === NOT_PENDING ? e.j : e.W;
349
+ let r = e.o;
350
+ let s = e.J;
351
+ let o = e.Y;
352
+ let u = tracking;
353
+ setStatusFlags(e, STATUS_NONE | (s & STATUS_UNINITIALIZED));
385
354
  tracking = true;
386
355
  try {
387
- value = el.H(value);
388
- } catch (e) {
389
- if (e instanceof NotReadyError) {
390
- if (e.cause !== el)
391
- link(e.cause, el);
392
- setStatusFlags(el, prevStatusFlags & ~2 /* Error */ | 1 /* Pending */, e);
393
- } else {
394
- setError(el, e);
395
- }
356
+ i = e.m(i);
357
+ e.J &= ~STATUS_UNINITIALIZED;
358
+ } catch (t) {
359
+ if (t instanceof NotReadyError) {
360
+ if (t.cause !== e) link(t.cause, e);
361
+ setStatusFlags(e, (s & ~STATUS_ERROR) | STATUS_PENDING, t);
362
+ } else setStatusFlags(e, STATUS_ERROR, t);
396
363
  } finally {
397
- tracking = prevTracking;
364
+ tracking = u;
398
365
  }
399
- el.b = 0 /* None */;
400
- context = oldcontext;
401
- const depsTail = el.F;
402
- let toRemove = depsTail !== null ? depsTail.E : el.l;
403
- if (toRemove !== null) {
366
+ e._ = REACTIVE_NONE;
367
+ context = n;
368
+ const l = e.re;
369
+ let c = l !== null ? l.P : e.D;
370
+ if (c !== null) {
404
371
  do {
405
- toRemove = unlinkSubs(toRemove);
406
- } while (toRemove !== null);
407
- if (depsTail !== null) {
408
- depsTail.E = null;
409
- } else {
410
- el.l = null;
411
- }
412
- }
413
- const valueChanged = !el.fa || !el.fa(el.e === NOT_PENDING ? el.g : el.e, value);
414
- const statusFlagsChanged = el.f !== prevStatusFlags || el.B !== prevError;
415
- el.ma?.(statusFlagsChanged, prevStatusFlags);
416
- if (valueChanged || statusFlagsChanged) {
417
- if (valueChanged) {
418
- if (create || el.ja || el.K)
419
- el.g = value;
372
+ c = unlinkSubs(c);
373
+ } while (c !== null);
374
+ if (l !== null) l.P = null;
375
+ else e.D = null;
376
+ }
377
+ const a = !e.oe || !e.oe(e.W === NOT_PENDING || e.ue ? e.j : e.W, i);
378
+ const f = e.J !== s || e.Y !== o;
379
+ e.le?.(f, s);
380
+ if (a || f) {
381
+ if (a) {
382
+ if (t || e.ue || (e.K && e.B != activeTransition)) e.j = i;
420
383
  else {
421
- if (el.e === NOT_PENDING)
422
- globalQueue.h.push(el);
423
- el.e = value;
384
+ if (e.W === NOT_PENDING) globalQueue.$.push(e);
385
+ e.W = i;
424
386
  }
425
- if (el.C)
426
- el.C.ea(value);
387
+ if (e.Z) e.Z.q(i);
427
388
  }
428
- for (let s = el.x; s !== null; s = s.A) {
429
- const queue = s.j.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue;
430
- if (s.j.c < el.c && queue.q > s.j.c)
431
- queue.q = s.j.c;
432
- insertIntoHeap(s.j, queue);
389
+ for (let t = e.O; t !== null; t = t.p) {
390
+ const n = t.A._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
391
+ if (t.A.o < e.o && n.C > t.A.o) n.C = t.A.o;
392
+ insertIntoHeap(t.A, n);
433
393
  }
434
- } else if (el.c != oldHeight) {
435
- for (let s = el.x; s !== null; s = s.A) {
436
- insertIntoHeapHeight(s.j, s.j.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
394
+ } else if (e.o != r) {
395
+ for (let t = e.O; t !== null; t = t.p) {
396
+ insertIntoHeapHeight(t.A, t.A._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
437
397
  }
438
398
  }
399
+ if (e.K && e.B && activeTransition !== e.B) runInTransition(e, recompute);
439
400
  }
440
- function updateIfNecessary(el) {
441
- if (el.b & 1 /* Check */) {
442
- for (let d = el.l; d; d = d.E) {
443
- const dep1 = d.R;
444
- const dep = dep1.ia || dep1;
445
- if (dep.H) {
446
- updateIfNecessary(dep);
401
+ function updateIfNecessary(e) {
402
+ if (e._ & REACTIVE_CHECK) {
403
+ for (let t = e.D; t; t = t.P) {
404
+ const n = t.V;
405
+ const i = n.U || n;
406
+ if (i.m) {
407
+ updateIfNecessary(i);
447
408
  }
448
- if (el.b & 2 /* Dirty */) {
409
+ if (e._ & REACTIVE_DIRTY) {
449
410
  break;
450
411
  }
451
412
  }
452
413
  }
453
- if (el.b & 2 /* Dirty */) {
454
- recompute(el);
455
- }
456
- el.b = 0 /* None */;
457
- }
458
- function unlinkSubs(link2) {
459
- const dep = link2.R;
460
- const nextDep = link2.E;
461
- const nextSub = link2.A;
462
- const prevSub = link2.na;
463
- if (nextSub !== null) {
464
- nextSub.na = prevSub;
465
- } else {
466
- dep.W = prevSub;
467
- }
468
- if (prevSub !== null) {
469
- prevSub.A = nextSub;
470
- } else {
471
- dep.x = nextSub;
472
- if (nextSub === null) {
473
- dep.ta?.();
474
- dep.H && unobserved(dep);
475
- }
476
- }
477
- return nextDep;
478
- }
479
- function unobserved(el) {
480
- deleteFromHeap(el, el.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
481
- let dep = el.l;
482
- while (dep !== null) {
483
- dep = unlinkSubs(dep);
414
+ if (e._ & REACTIVE_DIRTY) {
415
+ recompute(e);
484
416
  }
485
- el.l = null;
486
- runDisposal(el);
417
+ e._ = REACTIVE_NONE;
487
418
  }
488
- function link(dep, sub) {
489
- const prevDep = sub.F;
490
- if (prevDep !== null && prevDep.R === dep) {
491
- return;
492
- }
493
- let nextDep = null;
494
- const isRecomputing = sub.b & 4 /* RecomputingDeps */;
495
- if (isRecomputing) {
496
- nextDep = prevDep !== null ? prevDep.E : sub.l;
497
- if (nextDep !== null && nextDep.R === dep) {
498
- sub.F = nextDep;
419
+ function unlinkSubs(e) {
420
+ const t = e.V;
421
+ const n = e.P;
422
+ const i = e.p;
423
+ const r = e.ce;
424
+ if (i !== null) i.ce = r;
425
+ else t.ae = r;
426
+ if (r !== null) r.p = i;
427
+ else {
428
+ t.O = i;
429
+ if (i === null) {
430
+ t.fe?.();
431
+ t.m && unobserved(t);
432
+ }
433
+ }
434
+ return n;
435
+ }
436
+ function unobserved(e) {
437
+ deleteFromHeap(e, e._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
438
+ let t = e.D;
439
+ while (t !== null) {
440
+ t = unlinkSubs(t);
441
+ }
442
+ e.D = null;
443
+ runDisposal(e);
444
+ }
445
+ function link(e, t) {
446
+ const n = t.re;
447
+ if (n !== null && n.V === e) return;
448
+ let i = null;
449
+ const r = t._ & REACTIVE_RECOMPUTING_DEPS;
450
+ if (r) {
451
+ i = n !== null ? n.P : t.D;
452
+ if (i !== null && i.V === e) {
453
+ t.re = i;
499
454
  return;
500
455
  }
501
456
  }
502
- const prevSub = dep.W;
503
- if (prevSub !== null && prevSub.j === sub && (!isRecomputing || isValidLink(prevSub, sub))) {
504
- return;
505
- }
506
- const newLink = sub.F = dep.W = {
507
- R: dep,
508
- j: sub,
509
- E: nextDep,
510
- na: prevSub,
511
- A: null
512
- };
513
- if (prevDep !== null) {
514
- prevDep.E = newLink;
515
- } else {
516
- sub.l = newLink;
517
- }
518
- if (prevSub !== null) {
519
- prevSub.A = newLink;
520
- } else {
521
- dep.x = newLink;
522
- }
457
+ const s = e.ae;
458
+ if (s !== null && s.A === t && (!r || isValidLink(s, t))) return;
459
+ const o = (t.re = e.ae = { V: e, A: t, P: i, ce: s, p: null });
460
+ if (n !== null) n.P = o;
461
+ else t.D = o;
462
+ if (s !== null) s.p = o;
463
+ else e.O = o;
523
464
  }
524
- function isValidLink(checkLink, sub) {
525
- const depsTail = sub.F;
526
- if (depsTail !== null) {
527
- let link2 = sub.l;
465
+ function isValidLink(e, t) {
466
+ const n = t.re;
467
+ if (n !== null) {
468
+ let i = t.D;
528
469
  do {
529
- if (link2 === checkLink) {
530
- return true;
531
- }
532
- if (link2 === depsTail) {
533
- break;
534
- }
535
- link2 = link2.E;
536
- } while (link2 !== null);
470
+ if (i === e) return true;
471
+ if (i === n) break;
472
+ i = i.P;
473
+ } while (i !== null);
537
474
  }
538
475
  return false;
539
476
  }
540
- function setStatusFlags(signal2, flags, error = null) {
541
- signal2.f = flags;
542
- signal2.B = error;
543
- }
544
- function setError(signal2, error) {
545
- setStatusFlags(signal2, 2 /* Error */, error);
477
+ function setStatusFlags(e, t, n = null) {
478
+ e.J = t;
479
+ e.Y = n;
546
480
  }
547
- function clearStatusFlags(signal2) {
548
- setStatusFlags(signal2, 0 /* None */);
549
- }
550
- function markDisposal(el) {
551
- let child = el.r;
552
- while (child) {
553
- child.b |= 32 /* Zombie */;
554
- const inHeap = child.b & 8 /* InHeap */;
555
- if (inHeap) {
556
- deleteFromHeap(child, dirtyQueue);
557
- insertIntoHeap(child, zombieQueue);
481
+ function markDisposal(e) {
482
+ let t = e.ie;
483
+ while (t) {
484
+ t._ |= REACTIVE_ZOMBIE;
485
+ if (t._ & REACTIVE_IN_HEAP) {
486
+ deleteFromHeap(t, dirtyQueue);
487
+ insertIntoHeap(t, zombieQueue);
558
488
  }
559
- markDisposal(child);
560
- child = child.M;
489
+ markDisposal(t);
490
+ t = t.Ee;
561
491
  }
562
492
  }
563
- function dispose(node) {
564
- let toRemove = node.l || null;
493
+ function dispose(e) {
494
+ let t = e.D || null;
565
495
  do {
566
- toRemove = unlinkSubs(toRemove);
567
- } while (toRemove !== null);
568
- node.l = null;
569
- node.F = null;
570
- disposeChildren(node, true);
571
- }
572
- function disposeChildren(node, self = false, zombie) {
573
- if (node.b & 64 /* Disposed */)
574
- return;
575
- if (self)
576
- node.b = 64 /* Disposed */;
577
- let child = zombie ? node.U : node.r;
578
- while (child) {
579
- const nextChild = child.M;
580
- if (child.l) {
581
- const n = child;
582
- deleteFromHeap(n, n.b & 32 /* Zombie */ ? zombieQueue : dirtyQueue);
583
- let toRemove = n.l;
496
+ t = unlinkSubs(t);
497
+ } while (t !== null);
498
+ e.D = null;
499
+ e.re = null;
500
+ disposeChildren(e, true);
501
+ }
502
+ function disposeChildren(e, t = false, n) {
503
+ if (e._ & REACTIVE_DISPOSED) return;
504
+ if (t) e._ = REACTIVE_DISPOSED;
505
+ let i = n ? e.ee : e.ie;
506
+ while (i) {
507
+ const e = i.Ee;
508
+ if (i.D) {
509
+ const e = i;
510
+ deleteFromHeap(e, e._ & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
511
+ let t = e.D;
584
512
  do {
585
- toRemove = unlinkSubs(toRemove);
586
- } while (toRemove !== null);
587
- n.l = null;
588
- n.F = null;
513
+ t = unlinkSubs(t);
514
+ } while (t !== null);
515
+ e.D = null;
516
+ e.re = null;
589
517
  }
590
- disposeChildren(child, true);
591
- child = nextChild;
518
+ disposeChildren(i, true);
519
+ i = e;
592
520
  }
593
- if (zombie) {
594
- node.U = null;
521
+ if (n) {
522
+ e.ee = null;
595
523
  } else {
596
- node.r = null;
597
- node.M = null;
524
+ e.ie = null;
525
+ e.Ee = null;
598
526
  }
599
- runDisposal(node, zombie);
527
+ runDisposal(e, n);
600
528
  }
601
- function runDisposal(node, zombie) {
602
- let disposal = zombie ? node.V : node.t;
603
- if (!disposal)
604
- return;
605
- if (Array.isArray(disposal)) {
606
- for (let i = 0; i < disposal.length; i++) {
607
- const callable = disposal[i];
608
- callable.call(callable);
529
+ function runDisposal(e, t) {
530
+ let n = t ? e.te : e.ne;
531
+ if (!n) return;
532
+ if (Array.isArray(n)) {
533
+ for (let e = 0; e < n.length; e++) {
534
+ const t = n[e];
535
+ t.call(t);
609
536
  }
610
537
  } else {
611
- disposal.call(disposal);
612
- }
613
- zombie ? node.V = null : node.t = null;
614
- }
615
- function withOptions(obj, options) {
616
- obj.id = options?.id ?? (context?.id != null ? getNextChildId(context) : void 0);
617
- obj.fa = options?.equals != null ? options.equals : isEqual;
618
- obj.za = !!options?.pureWrite;
619
- obj.ta = options?.unobserved;
620
- if (options?.ka)
621
- Object.assign(obj, options.ka);
622
- return obj;
623
- }
624
- function getNextChildId(owner) {
625
- if (owner.id != null)
626
- return formatId(owner.id, owner.oa++);
627
- throw new Error("Cannot get child id from owner without an id");
538
+ n.call(n);
539
+ }
540
+ t ? (e.te = null) : (e.ne = null);
628
541
  }
629
- function formatId(prefix, id) {
630
- const num = id.toString(36), len = num.length - 1;
631
- return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
542
+ function getNextChildId(e) {
543
+ if (e.id != null) return formatId(e.id, e.de++);
544
+ throw new Error("Cannot get child id from owner without an id");
632
545
  }
633
- function computed(fn, initialValue, options) {
634
- const self = withOptions(
635
- {
636
- t: null,
637
- i: globalQueue,
638
- D: defaultContext,
639
- oa: 0,
640
- H: fn,
641
- g: initialValue,
642
- c: 0,
643
- ca: null,
644
- Q: void 0,
645
- z: null,
646
- l: null,
647
- F: null,
648
- x: null,
649
- W: null,
650
- w: context,
651
- M: null,
652
- r: null,
653
- b: 0 /* None */,
654
- f: 4 /* Uninitialized */,
655
- J: clock,
656
- e: NOT_PENDING,
657
- V: null,
658
- U: null
659
- },
660
- options
661
- );
662
- self.z = self;
663
- const parent = context?.$ ? context.aa : context;
546
+ function formatId(e, t) {
547
+ const n = t.toString(36),
548
+ i = n.length - 1;
549
+ return e + (i ? String.fromCharCode(64 + i) : "") + n;
550
+ }
551
+ function computed(e, t, n) {
552
+ const i = {
553
+ id: n?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
554
+ oe: n?.equals != null ? n.equals : isEqual,
555
+ Te: !!n?.pureWrite,
556
+ fe: n?.unobserved,
557
+ ne: null,
558
+ Re: context?.Re ?? globalQueue,
559
+ he: context?.he ?? defaultContext,
560
+ de: 0,
561
+ m: e,
562
+ j: t,
563
+ o: 0,
564
+ N: null,
565
+ R: undefined,
566
+ T: null,
567
+ D: null,
568
+ re: null,
569
+ O: null,
570
+ ae: null,
571
+ i: context,
572
+ Ee: null,
573
+ ie: null,
574
+ _: REACTIVE_NONE,
575
+ J: STATUS_UNINITIALIZED,
576
+ se: clock,
577
+ W: NOT_PENDING,
578
+ te: null,
579
+ ee: null
580
+ };
581
+ if (n?._e) Object.assign(i, n._e);
582
+ i.T = i;
583
+ const r = context?.t ? context.u : context;
664
584
  if (context) {
665
- context.i && (self.i = context.i);
666
- context.D && (self.D = context.D);
667
- const lastChild = context.r;
668
- if (lastChild === null) {
669
- context.r = self;
585
+ const e = context.ie;
586
+ if (e === null) {
587
+ context.ie = i;
670
588
  } else {
671
- self.M = lastChild;
672
- context.r = self;
673
- }
674
- }
675
- if (parent)
676
- self.c = parent.c + 1;
677
- recompute(self, true);
678
- return self;
679
- }
680
- function asyncComputed(asyncFn, initialValue, options) {
681
- let lastResult = void 0;
682
- let refreshing = false;
683
- const fn = (prev) => {
684
- const result = asyncFn(prev, refreshing);
685
- refreshing = false;
686
- lastResult = result;
687
- const isPromise = result instanceof Promise;
688
- const iterator = result[Symbol.asyncIterator];
689
- if (!isPromise && !iterator) {
690
- return result;
691
- }
692
- if (isPromise) {
693
- result.then((v) => {
694
- if (lastResult !== result)
695
- return;
696
- globalQueue.initTransition(self);
697
- setSignal(self, () => v);
589
+ i.Ee = e;
590
+ context.ie = i;
591
+ }
592
+ }
593
+ if (r) i.o = r.o + 1;
594
+ recompute(i, true);
595
+ return i;
596
+ }
597
+ function asyncComputed(e, t, n) {
598
+ let i = undefined;
599
+ let r = false;
600
+ const fn = t => {
601
+ const n = e(t, r);
602
+ r = false;
603
+ i = n;
604
+ const o = n instanceof Promise;
605
+ const u = n[Symbol.asyncIterator];
606
+ if (!o && !u) {
607
+ return n;
608
+ }
609
+ if (o) {
610
+ n.then(e => {
611
+ if (i !== n) return;
612
+ globalQueue.initTransition(s);
613
+ setSignal(s, () => e);
698
614
  flush();
699
- }).catch((e) => {
700
- if (lastResult !== result)
701
- return;
702
- globalQueue.initTransition(self);
703
- setError(self, e);
704
- self.J = clock;
705
- notifySubs(self);
615
+ }).catch(e => {
616
+ if (i !== n) return;
617
+ globalQueue.initTransition(s);
618
+ setStatusFlags(s, STATUS_ERROR, e);
619
+ s.se = clock;
620
+ notifySubs(s);
706
621
  schedule();
707
622
  flush();
708
623
  });
709
624
  } else {
710
625
  (async () => {
711
626
  try {
712
- for await (let value of result) {
713
- if (lastResult !== result)
714
- return;
715
- globalQueue.initTransition(self);
716
- setSignal(self, () => value);
627
+ for await (let e of n) {
628
+ if (i !== n) return;
629
+ globalQueue.initTransition(s);
630
+ setSignal(s, () => e);
717
631
  flush();
718
632
  }
719
- } catch (error) {
720
- if (lastResult !== result)
721
- return;
722
- globalQueue.initTransition(self);
723
- setError(self, error);
724
- self.J = clock;
725
- notifySubs(self);
633
+ } catch (e) {
634
+ if (i !== n) return;
635
+ globalQueue.initTransition(s);
636
+ setStatusFlags(s, STATUS_ERROR, e);
637
+ s.se = clock;
638
+ notifySubs(s);
726
639
  schedule();
727
640
  flush();
728
641
  }
@@ -731,150 +644,128 @@ function asyncComputed(asyncFn, initialValue, options) {
731
644
  globalQueue.initTransition(context);
732
645
  throw new NotReadyError(context);
733
646
  };
734
- const self = computed(fn, initialValue, options);
735
- self.ua = () => {
736
- refreshing = true;
737
- recompute(self);
647
+ const s = computed(fn, t, n);
648
+ s.Se = () => {
649
+ r = true;
650
+ recompute(s);
651
+ schedule();
738
652
  flush();
739
653
  };
740
- return self;
741
- }
742
- function signal(v, options, firewall = null) {
743
- if (firewall !== null) {
744
- return firewall.ca = withOptions(
745
- {
746
- g: v,
747
- x: null,
748
- W: null,
749
- ia: firewall,
750
- sa: firewall.ca,
751
- f: 0 /* None */,
752
- J: clock,
753
- e: NOT_PENDING
754
- },
755
- options
756
- );
757
- } else {
758
- return withOptions(
759
- {
760
- g: v,
761
- x: null,
762
- W: null,
763
- f: 0 /* None */,
764
- J: clock,
765
- e: NOT_PENDING
766
- },
767
- options
768
- );
769
- }
654
+ return s;
655
+ }
656
+ function signal(e, t, n = null) {
657
+ const i = {
658
+ id: t?.id ?? (context?.id != null ? getNextChildId(context) : undefined),
659
+ oe: t?.equals != null ? t.equals : isEqual,
660
+ Te: !!t?.pureWrite,
661
+ fe: t?.unobserved,
662
+ j: e,
663
+ O: null,
664
+ ae: null,
665
+ J: STATUS_NONE,
666
+ se: clock,
667
+ U: n,
668
+ I: n?.N || null,
669
+ W: NOT_PENDING
670
+ };
671
+ n && (n.N = i);
672
+ return i;
770
673
  }
771
- function isEqual(a, b) {
772
- return a === b;
674
+ function isEqual(e, t) {
675
+ return e === t;
773
676
  }
774
- function untrack(fn) {
775
- if (!tracking)
776
- return fn();
677
+ function untrack(e) {
678
+ if (!tracking) return e();
777
679
  tracking = false;
778
680
  try {
779
- return fn();
681
+ return e();
780
682
  } finally {
781
683
  tracking = true;
782
684
  }
783
685
  }
784
- function read(el) {
785
- let c = context;
786
- if (c?.$)
787
- c = c.aa;
788
- if (c && tracking) {
789
- link(el, c);
790
- const owner = el.ia || el;
791
- if (owner.H) {
792
- const isZombie = el.b & 32 /* Zombie */;
793
- if (owner.c >= (isZombie ? zombieQueue.q : dirtyQueue.q)) {
794
- markNode(c);
795
- markHeap(isZombie ? zombieQueue : dirtyQueue);
796
- updateIfNecessary(owner);
686
+ function read(e) {
687
+ let t = context;
688
+ if (t?.t) t = t.u;
689
+ if (t && tracking && !pendingCheck && !pendingValueCheck) {
690
+ link(e, t);
691
+ const n = e.U || e;
692
+ if (n.m) {
693
+ const i = e._ & REACTIVE_ZOMBIE;
694
+ if (n.o >= (i ? zombieQueue.C : dirtyQueue.C)) {
695
+ markNode(t);
696
+ markHeap(i ? zombieQueue : dirtyQueue);
697
+ updateIfNecessary(n);
797
698
  }
798
- const height = owner.c;
799
- if (height >= c.c && el.w !== c) {
800
- c.c = height + 1;
699
+ const r = n.o;
700
+ if (r >= t.o && e.i !== t) {
701
+ t.o = r + 1;
801
702
  }
802
703
  }
803
704
  }
804
705
  if (pendingCheck) {
805
- const pendingResult = (el.f & 1 /* Pending */) !== 0 || !!el.T || false;
806
- if (!el.I) {
807
- el.I = signal(pendingResult);
808
- el.I.ja = true;
809
- el.I.ea = (v) => setSignal(el.I, v);
706
+ if (!e.X) {
707
+ e.X = signal(false);
708
+ e.X.ue = true;
709
+ e.X.q = t => setSignal(e.X, t);
810
710
  }
811
- const prev = pendingCheck;
711
+ const t = pendingCheck;
812
712
  pendingCheck = null;
813
- read(el.I);
814
- pendingCheck = prev;
815
- prev.g = pendingResult || prev.g;
713
+ t.j = read(e.X) || t.j;
714
+ pendingCheck = t;
816
715
  }
817
716
  if (pendingValueCheck) {
818
- if (!el.C) {
819
- el.C = signal(
820
- el.e === NOT_PENDING ? el.g : el.e
821
- );
822
- el.C.ja = true;
823
- el.C.ea = (v) => queueMicrotask(() => queueMicrotask(() => setSignal(el.C, v)));
717
+ if (!e.Z) {
718
+ e.Z = signal(e.j);
719
+ e.Z.ue = true;
720
+ e.Z.q = t => setSignal(e.Z, t);
824
721
  }
825
722
  pendingValueCheck = false;
826
723
  try {
827
- return read(el.C);
724
+ return read(e.Z);
828
725
  } finally {
829
726
  pendingValueCheck = true;
830
727
  }
831
728
  }
832
- if (el.f & 1 /* Pending */) {
833
- if (c && !stale || el.f & 4 /* Uninitialized */)
834
- throw el.B;
835
- else if (c && stale && !pendingCheck) {
836
- setStatusFlags(
837
- c,
838
- c.f | 1,
839
- el.B
840
- );
729
+ if (e.J & STATUS_PENDING) {
730
+ if ((t && !stale) || e.J & STATUS_UNINITIALIZED) throw e.Y;
731
+ else if (t && stale && !pendingCheck) {
732
+ setStatusFlags(t, t.J | 1, e.Y);
841
733
  }
842
734
  }
843
- if (el.f & 2 /* Error */) {
844
- if (el.J < clock) {
845
- recompute(el, true);
846
- return read(el);
735
+ if (e.J & STATUS_ERROR) {
736
+ if (e.se < clock) {
737
+ recompute(e, true);
738
+ return read(e);
847
739
  } else {
848
- throw el.B;
740
+ throw e.Y;
849
741
  }
850
742
  }
851
- return !c || el.e === NOT_PENDING || stale && !pendingCheck && el.T && activeTransition !== el.T ? el.g : el.e;
743
+ return !t ||
744
+ e.ue ||
745
+ e.W === NOT_PENDING ||
746
+ (stale && !pendingCheck && e.B && activeTransition !== e.B)
747
+ ? e.j
748
+ : e.W;
852
749
  }
853
- function setSignal(el, v) {
854
- if (typeof v === "function") {
855
- v = v(
856
- el.e === NOT_PENDING ? el.g : el.e
857
- );
750
+ function setSignal(e, t) {
751
+ if (typeof t === "function") {
752
+ t = t(e.W === NOT_PENDING ? e.j : e.W);
858
753
  }
859
- const valueChanged = !el.fa || !el.fa(el.e === NOT_PENDING ? el.g : el.e, v);
860
- if (!valueChanged && !el.f)
861
- return v;
862
- if (valueChanged) {
863
- if (el.ja)
864
- el.g = v;
754
+ const n = !e.oe || !e.oe(e.W === NOT_PENDING || e.ue ? e.j : e.W, t);
755
+ if (!n && !e.J) return t;
756
+ if (n) {
757
+ if (e.ue) e.j = t;
865
758
  else {
866
- if (el.e === NOT_PENDING)
867
- globalQueue.h.push(el);
868
- el.e = v;
759
+ if (e.W === NOT_PENDING) globalQueue.$.push(e);
760
+ e.W = t;
869
761
  }
870
- if (el.C)
871
- el.C.ea(v);
762
+ if (e.Z) e.Z.W = t;
872
763
  }
873
- clearStatusFlags(el);
874
- el.J = clock;
875
- notifySubs(el);
764
+ setStatusFlags(e, STATUS_NONE);
765
+ e.se = clock;
766
+ notifySubs(e);
876
767
  schedule();
877
- return v;
768
+ return t;
878
769
  }
879
770
  function getObserver() {
880
771
  return tracking ? context : null;
@@ -882,1351 +773,1302 @@ function getObserver() {
882
773
  function getOwner() {
883
774
  return context;
884
775
  }
885
- function onCleanup(fn) {
886
- if (!context)
887
- return fn;
888
- const node = context;
889
- if (!node.t) {
890
- node.t = fn;
891
- } else if (Array.isArray(node.t)) {
892
- node.t.push(fn);
776
+ function onCleanup(e) {
777
+ if (!context) return e;
778
+ const t = context;
779
+ if (!t.ne) {
780
+ t.ne = e;
781
+ } else if (Array.isArray(t.ne)) {
782
+ t.ne.push(e);
893
783
  } else {
894
- node.t = [node.t, fn];
895
- }
896
- return fn;
897
- }
898
- function createOwner(options) {
899
- const parent = context;
900
- const owner = {
901
- $: true,
902
- aa: parent?.$ ? parent.aa : parent,
903
- r: null,
904
- M: null,
905
- t: null,
906
- id: options?.id ?? (parent?.id != null ? getNextChildId(parent) : void 0),
907
- i: parent?.i ?? globalQueue,
908
- D: parent?.D || defaultContext,
909
- oa: 0,
910
- V: null,
911
- U: null,
912
- w: parent,
913
- dispose(self = true) {
914
- disposeChildren(owner, self);
784
+ t.ne = [t.ne, e];
785
+ }
786
+ return e;
787
+ }
788
+ function createOwner(e) {
789
+ const t = context;
790
+ const n = {
791
+ t: true,
792
+ u: t?.t ? t.u : t,
793
+ ie: null,
794
+ Ee: null,
795
+ ne: null,
796
+ id: e?.id ?? (t?.id != null ? getNextChildId(t) : undefined),
797
+ Re: t?.Re ?? globalQueue,
798
+ he: t?.he || defaultContext,
799
+ de: 0,
800
+ te: null,
801
+ ee: null,
802
+ i: t,
803
+ dispose(e = true) {
804
+ disposeChildren(n, e);
915
805
  }
916
806
  };
917
- if (parent) {
918
- const lastChild = parent.r;
919
- if (lastChild === null) {
920
- parent.r = owner;
807
+ if (t) {
808
+ const e = t.ie;
809
+ if (e === null) {
810
+ t.ie = n;
921
811
  } else {
922
- owner.M = lastChild;
923
- parent.r = owner;
812
+ n.Ee = e;
813
+ t.ie = n;
924
814
  }
925
815
  }
926
- return owner;
816
+ return n;
927
817
  }
928
- function createRoot(init, options) {
929
- const owner = createOwner(options);
930
- return runWithOwner(owner, () => init(owner.dispose));
818
+ function createRoot(e, t) {
819
+ const n = createOwner(t);
820
+ return runWithOwner(n, () => e(n.dispose));
931
821
  }
932
- function runWithOwner(owner, fn) {
933
- const oldContext = context;
934
- context = owner;
822
+ function runWithOwner(e, t) {
823
+ const n = context;
824
+ context = e;
935
825
  try {
936
- return fn();
826
+ return t();
937
827
  } finally {
938
- context = oldContext;
828
+ context = n;
939
829
  }
940
830
  }
941
- function staleValues(fn, set = true) {
942
- const prevStale = stale;
943
- stale = set;
831
+ function staleValues(e, t = true) {
832
+ const n = stale;
833
+ stale = t;
944
834
  try {
945
- return fn();
835
+ return e();
946
836
  } finally {
947
- stale = prevStale;
837
+ stale = n;
948
838
  }
949
839
  }
950
- function pending(fn) {
951
- const prevLatest = pendingValueCheck;
840
+ function pending(e) {
841
+ const t = pendingValueCheck;
952
842
  pendingValueCheck = true;
953
843
  try {
954
- return staleValues(fn, false);
844
+ return staleValues(e, false);
955
845
  } finally {
956
- pendingValueCheck = prevLatest;
846
+ pendingValueCheck = t;
957
847
  }
958
848
  }
959
- function isPending(fn, loadingValue) {
960
- const current = pendingCheck;
961
- pendingCheck = { g: false };
849
+ function isPending(e, t) {
850
+ const n = pendingCheck;
851
+ pendingCheck = { j: false };
962
852
  try {
963
- staleValues(fn);
964
- return pendingCheck.g;
965
- } catch (err) {
966
- if (!(err instanceof NotReadyError))
967
- return false;
968
- if (loadingValue !== void 0)
969
- return loadingValue;
970
- throw err;
853
+ staleValues(e);
854
+ return pendingCheck.j;
855
+ } catch (e) {
856
+ if (!(e instanceof NotReadyError)) return false;
857
+ if (t !== undefined) return t;
858
+ throw e;
971
859
  } finally {
972
- pendingCheck = current;
860
+ pendingCheck = n;
973
861
  }
974
862
  }
975
-
976
- // src/core/context.ts
977
- function createContext(defaultValue, description) {
978
- return { id: Symbol(description), defaultValue };
863
+ function createContext(e, t) {
864
+ return { id: Symbol(t), defaultValue: e };
979
865
  }
980
- function getContext(context2, owner = getOwner()) {
981
- if (!owner) {
866
+ function getContext(e, t = getOwner()) {
867
+ if (!t) {
982
868
  throw new NoOwnerError();
983
869
  }
984
- const value = hasContext(context2, owner) ? owner.D[context2.id] : context2.defaultValue;
985
- if (isUndefined(value)) {
870
+ const n = hasContext(e, t) ? t.he[e.id] : e.defaultValue;
871
+ if (isUndefined(n)) {
986
872
  throw new ContextNotFoundError();
987
873
  }
988
- return value;
874
+ return n;
989
875
  }
990
- function setContext(context2, value, owner = getOwner()) {
991
- if (!owner) {
876
+ function setContext(e, t, n = getOwner()) {
877
+ if (!n) {
992
878
  throw new NoOwnerError();
993
879
  }
994
- owner.D = {
995
- ...owner.D,
996
- [context2.id]: isUndefined(value) ? context2.defaultValue : value
997
- };
998
- }
999
- function hasContext(context2, owner) {
1000
- return !isUndefined(owner?.D[context2.id]);
1001
- }
1002
- function isUndefined(value) {
1003
- return typeof value === "undefined";
1004
- }
1005
-
1006
- // src/core/effect.ts
1007
- function effect(compute, effect2, error, initialValue, options) {
1008
- let initialized = false;
1009
- const node = computed(compute, initialValue, {
1010
- ...options,
1011
- ka: {
1012
- ga: true,
1013
- pa: initialValue,
1014
- va: effect2,
1015
- qa: error,
1016
- N: void 0,
1017
- i: getOwner()?.i ?? globalQueue,
1018
- K: options?.render ? 1 /* Render */ : 2 /* User */,
1019
- ma(statusFlagsChanged, prevStatusFlags) {
1020
- if (initialized) {
1021
- const errorChanged = this.f && this.f === prevStatusFlags && statusFlagsChanged;
1022
- this.ga = !(this.f & 2 /* Error */) && !(this.f & 1 /* Pending */ & ~prevStatusFlags) && !errorChanged;
1023
- if (this.ga)
1024
- this.i.enqueue(this.K, runEffect.bind(this));
880
+ n.he = { ...n.he, [e.id]: isUndefined(t) ? e.defaultValue : t };
881
+ }
882
+ function hasContext(e, t) {
883
+ return !isUndefined(t?.he[e.id]);
884
+ }
885
+ function isUndefined(e) {
886
+ return typeof e === "undefined";
887
+ }
888
+ function effect(e, t, n, i, r) {
889
+ let s = false;
890
+ const o = computed(e, i, {
891
+ ...r,
892
+ _e: {
893
+ M: true,
894
+ Oe: i,
895
+ pe: t,
896
+ Ae: n,
897
+ Ne: undefined,
898
+ K: r?.render ? EFFECT_RENDER : EFFECT_USER,
899
+ le(e, t) {
900
+ if (s) {
901
+ const n = this.J && this.J === t && e;
902
+ this.M = !(this.J & STATUS_ERROR) && !(this.J & STATUS_PENDING & ~t) && !n;
903
+ if (this.M) this.Re.enqueue(this.K, runEffect.bind(this));
1025
904
  }
1026
- if (this.f & 2 /* Error */) {
1027
- let error2 = this.B;
1028
- this.i.notify(this, 1 /* Pending */, 0);
1029
- if (this.K === 2 /* User */) {
905
+ if (this.J & STATUS_ERROR) {
906
+ let e = this.Y;
907
+ this.Re.notify(this, STATUS_PENDING, 0);
908
+ if (this.K === EFFECT_USER) {
1030
909
  try {
1031
- return this.qa ? this.qa(error2, () => {
1032
- this.N?.();
1033
- this.N = void 0;
1034
- }) : console.error(error2);
1035
- } catch (e) {
1036
- error2 = e;
910
+ return this.Ae
911
+ ? this.Ae(e, () => {
912
+ this.Ne?.();
913
+ this.Ne = undefined;
914
+ })
915
+ : console.error(e);
916
+ } catch (t) {
917
+ e = t;
1037
918
  }
1038
919
  }
1039
- if (!this.i.notify(this, 2 /* Error */, 2 /* Error */))
1040
- throw error2;
1041
- } else if (this.K === 1 /* Render */) {
1042
- this.i.notify(
1043
- this,
1044
- 1 /* Pending */ | 2 /* Error */,
1045
- this.f
1046
- );
920
+ if (!this.Re.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
921
+ } else if (this.K === EFFECT_RENDER) {
922
+ this.Re.notify(this, STATUS_PENDING | STATUS_ERROR, this.J);
1047
923
  }
1048
924
  }
1049
925
  }
1050
926
  });
1051
- initialized = true;
1052
- if (node.K === 1 /* Render */)
1053
- node.H = (p) => staleValues(() => compute(p));
1054
- !options?.defer && !(node.f & (2 /* Error */ | 1 /* Pending */)) && (node.K === 2 /* User */ ? node.i.enqueue(node.K, runEffect.bind(node)) : runEffect.call(node));
1055
- onCleanup(() => node.N?.());
927
+ s = true;
928
+ if (o.K === EFFECT_RENDER) o.m = t => staleValues(() => e(t));
929
+ !r?.defer &&
930
+ !(o.J & (STATUS_ERROR | STATUS_PENDING)) &&
931
+ (o.K === EFFECT_USER ? o.Re.enqueue(o.K, runEffect.bind(o)) : runEffect.call(o));
932
+ onCleanup(() => o.Ne?.());
1056
933
  }
1057
934
  function runEffect() {
1058
- if (!this.ga || this.b & 64 /* Disposed */)
1059
- return;
1060
- this.N?.();
1061
- this.N = void 0;
935
+ if (!this.M || this._ & REACTIVE_DISPOSED) return;
936
+ this.Ne?.();
937
+ this.Ne = undefined;
1062
938
  try {
1063
- this.N = this.va(this.g, this.pa);
1064
- } catch (error) {
1065
- if (!this.i.notify(this, 2 /* Error */, 2 /* Error */))
1066
- throw error;
939
+ this.Ne = this.pe(this.j, this.Oe);
940
+ } catch (e) {
941
+ if (!this.Re.notify(this, STATUS_ERROR, STATUS_ERROR)) throw e;
1067
942
  } finally {
1068
- this.pa = this.g;
1069
- this.ga = false;
1070
- }
1071
- }
1072
-
1073
- // src/signals.ts
1074
- function createSignal(first, second, third) {
1075
- if (typeof first === "function") {
1076
- const node2 = computed(first, second, third);
1077
- return [
1078
- read.bind(null, node2),
1079
- setSignal.bind(null, node2)
1080
- ];
1081
- }
1082
- const o = getOwner();
1083
- const needsId = o?.id != null;
1084
- const node = signal(
1085
- first,
1086
- needsId ? { id: getNextChildId(o), ...second } : second
1087
- );
1088
- return [
1089
- read.bind(null, node),
1090
- setSignal.bind(null, node)
1091
- ];
1092
- }
1093
- function createMemo(compute, value, options) {
1094
- let node = computed(compute, value, options);
1095
- return read.bind(null, node);
1096
- }
1097
- function createAsync(compute, value, options) {
1098
- const node = asyncComputed(compute, value, options);
1099
- const ret = read.bind(null, node);
1100
- ret.refresh = node.ua;
1101
- return ret;
1102
- }
1103
- function createEffect(compute, effectFn, value, options) {
1104
- void effect(
1105
- compute,
1106
- effectFn.effect || effectFn,
1107
- effectFn.error,
1108
- value,
1109
- options
1110
- );
1111
- }
1112
- function createRenderEffect(compute, effectFn, value, options) {
1113
- void effect(compute, effectFn, void 0, value, {
1114
- render: true,
1115
- ...options
1116
- });
1117
- }
1118
- function createTrackedEffect(compute, options) {
1119
- }
1120
- function createReaction(effectFn, options) {
1121
- let cleanup = void 0;
1122
- onCleanup(() => cleanup?.());
1123
- return (tracking2) => {
1124
- effect(
1125
- () => (tracking2(), getOwner()),
1126
- (node) => {
1127
- cleanup?.();
1128
- cleanup = (effectFn.effect || effectFn)?.();
1129
- dispose(node);
1130
- },
1131
- effectFn.error,
1132
- void 0,
1133
- {
1134
- defer: true,
1135
- ...options
1136
- }
1137
- );
943
+ this.Oe = this.j;
944
+ this.M = false;
945
+ }
946
+ }
947
+ function createSignal(e, t, n) {
948
+ if (typeof e === "function") {
949
+ const i = computed(e, t, n);
950
+ return [read.bind(null, i), setSignal.bind(null, i)];
951
+ }
952
+ const i = getOwner();
953
+ const r = i?.id != null;
954
+ const s = signal(e, r ? { id: getNextChildId(i), ...t } : t);
955
+ return [read.bind(null, s), setSignal.bind(null, s)];
956
+ }
957
+ function createMemo(e, t, n) {
958
+ let i = computed(e, t, n);
959
+ return read.bind(null, i);
960
+ }
961
+ function createAsync(e, t, n) {
962
+ const i = asyncComputed(e, t, n);
963
+ const r = read.bind(null, i);
964
+ r.refresh = i.Se;
965
+ return r;
966
+ }
967
+ function createEffect(e, t, n, i) {
968
+ void effect(e, t.effect || t, t.error, n, i);
969
+ }
970
+ function createRenderEffect(e, t, n, i) {
971
+ void effect(e, t, undefined, n, { render: true, ...i });
972
+ }
973
+ function createTrackedEffect(e, t) {}
974
+ function createReaction(e, t) {
975
+ let n = undefined;
976
+ onCleanup(() => n?.());
977
+ const i = getOwner();
978
+ return r => {
979
+ runWithOwner(i, () => {
980
+ effect(
981
+ () => (r(), getOwner()),
982
+ t => {
983
+ n?.();
984
+ n = (e.effect || e)?.();
985
+ dispose(t);
986
+ },
987
+ e.error,
988
+ undefined,
989
+ { defer: true, ...(false ? { ...t, name: t?.name ?? "effect" } : t) }
990
+ );
991
+ });
1138
992
  };
1139
993
  }
1140
- function resolve(fn) {
1141
- return new Promise((res, rej) => {
1142
- createRoot((dispose2) => {
994
+ function resolve(e) {
995
+ return new Promise((t, n) => {
996
+ createRoot(i => {
1143
997
  computed(() => {
1144
998
  try {
1145
- res(fn());
1146
- } catch (err) {
1147
- if (err instanceof NotReadyError)
1148
- throw err;
1149
- rej(err);
999
+ t(e());
1000
+ } catch (e) {
1001
+ if (e instanceof NotReadyError) throw e;
1002
+ n(e);
1150
1003
  }
1151
- dispose2();
1004
+ i();
1152
1005
  });
1153
1006
  });
1154
1007
  });
1155
1008
  }
1156
- function createOptimistic(first, second, third) {
1009
+ function createOptimistic(e, t, n) {
1157
1010
  return {};
1158
1011
  }
1159
- function onSettled(callback) {
1160
- let cleanup;
1161
- const o = getOwner();
1162
- if (o)
1163
- onCleanup(() => cleanup?.());
1164
- globalQueue.enqueue(2 /* User */, () => {
1165
- cleanup = callback();
1166
- !o && cleanup?.();
1012
+ function onSettled(e) {
1013
+ let t;
1014
+ const n = getOwner();
1015
+ if (n) onCleanup(() => t?.());
1016
+ globalQueue.enqueue(EFFECT_USER, () => {
1017
+ t = e();
1018
+ !n && t?.();
1167
1019
  });
1168
1020
  }
1169
-
1170
- // src/store/reconcile.ts
1171
- function unwrap(value) {
1172
- return value?.[$TARGET]?.[STORE_NODE] ?? value;
1173
- }
1174
- function getOverrideValue(value, override, nodes, key) {
1175
- return nodes && key in nodes ? read(nodes[key]) : override && key in override ? override[key] : value[key];
1176
- }
1177
- function getAllKeys(value, override, next) {
1178
- const keys = getKeys(value, override);
1179
- const nextKeys = Object.keys(next);
1180
- return Array.from(/* @__PURE__ */ new Set([...keys, ...nextKeys]));
1181
- }
1182
- function applyState(next, state, keyFn, all) {
1183
- const target = state?.[$TARGET];
1184
- if (!target)
1185
- return;
1186
- const previous = target[STORE_VALUE];
1187
- const override = target[STORE_OVERRIDE];
1188
- let nodes = target[STORE_NODE];
1189
- if (next === previous && !override)
1190
- return;
1191
- (target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
1192
- target[STORE_VALUE] = next;
1193
- target[STORE_OVERRIDE] = void 0;
1194
- if (Array.isArray(previous)) {
1195
- let changed = false;
1196
- const prevLength = getOverrideValue(previous, override, nodes, "length");
1197
- if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
1198
- let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1199
- for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, nodes, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
1200
- applyState(next[start], wrap(item, target), keyFn, all);
1021
+ function unwrap(e) {
1022
+ return e?.[$TARGET]?.[STORE_NODE] ?? e;
1023
+ }
1024
+ function getOverrideValue(e, t, n, i) {
1025
+ return n && i in n ? read(n[i]) : t && i in t ? t[i] : e[i];
1026
+ }
1027
+ function getAllKeys(e, t, n) {
1028
+ const i = getKeys(e, t);
1029
+ const r = Object.keys(n);
1030
+ return Array.from(new Set([...i, ...r]));
1031
+ }
1032
+ function applyState(e, t, n, i) {
1033
+ const r = t?.[$TARGET];
1034
+ if (!r) return;
1035
+ const s = r[STORE_VALUE];
1036
+ const o = r[STORE_OVERRIDE];
1037
+ let u = r[STORE_NODE];
1038
+ if (e === s && !o) return;
1039
+ (r[STORE_LOOKUP] || storeLookup).set(e, r[$PROXY]);
1040
+ r[STORE_VALUE] = e;
1041
+ r[STORE_OVERRIDE] = undefined;
1042
+ if (Array.isArray(s)) {
1043
+ let t = false;
1044
+ const l = getOverrideValue(s, o, u, "length");
1045
+ if (e.length && l && e[0] && n(e[0]) != null) {
1046
+ let c, a, f, E, d, T, R, h;
1047
+ for (
1048
+ f = 0, E = Math.min(l, e.length);
1049
+ f < E && ((T = getOverrideValue(s, o, u, f)) === e[f] || (T && e[f] && n(T) === n(e[f])));
1050
+ f++
1051
+ ) {
1052
+ applyState(e[f], wrap(T, r), n, i);
1201
1053
  }
1202
- const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1203
- for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, nodes, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
1204
- temp[newEnd] = item;
1054
+ const _ = new Array(e.length),
1055
+ S = new Map();
1056
+ for (
1057
+ E = l - 1, d = e.length - 1;
1058
+ E >= f &&
1059
+ d >= f &&
1060
+ ((T = getOverrideValue(s, o, u, E)) === e[d] || (T && e[d] && n(T) === n(e[d])));
1061
+ E--, d--
1062
+ ) {
1063
+ _[d] = T;
1205
1064
  }
1206
- if (start > newEnd || start > end) {
1207
- for (j = start; j <= newEnd; j++) {
1208
- changed = true;
1209
- target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrap(next[j], target));
1065
+ if (f > d || f > E) {
1066
+ for (a = f; a <= d; a++) {
1067
+ t = true;
1068
+ r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], wrap(e[a], r));
1210
1069
  }
1211
- for (; j < next.length; j++) {
1212
- changed = true;
1213
- const wrapped = wrap(temp[j], target);
1214
- target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrapped);
1215
- applyState(next[j], wrapped, keyFn, all);
1070
+ for (; a < e.length; a++) {
1071
+ t = true;
1072
+ const s = wrap(_[a], r);
1073
+ r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], s);
1074
+ applyState(e[a], s, n, i);
1216
1075
  }
1217
- changed && target[STORE_NODE][$TRACK] && setSignal(target[STORE_NODE][$TRACK], void 0);
1218
- prevLength !== next.length && target[STORE_NODE].length && setSignal(target[STORE_NODE].length, next.length);
1076
+ t && r[STORE_NODE][$TRACK] && setSignal(r[STORE_NODE][$TRACK], void 0);
1077
+ l !== e.length && r[STORE_NODE].length && setSignal(r[STORE_NODE].length, e.length);
1219
1078
  return;
1220
1079
  }
1221
- newIndicesNext = new Array(newEnd + 1);
1222
- for (j = newEnd; j >= start; j--) {
1223
- item = next[j];
1224
- keyVal = item ? keyFn(item) : item;
1225
- i = newIndices.get(keyVal);
1226
- newIndicesNext[j] = i === void 0 ? -1 : i;
1227
- newIndices.set(keyVal, j);
1080
+ R = new Array(d + 1);
1081
+ for (a = d; a >= f; a--) {
1082
+ T = e[a];
1083
+ h = T ? n(T) : T;
1084
+ c = S.get(h);
1085
+ R[a] = c === undefined ? -1 : c;
1086
+ S.set(h, a);
1228
1087
  }
1229
- for (i = start; i <= end; i++) {
1230
- item = getOverrideValue(previous, override, nodes, i);
1231
- keyVal = item ? keyFn(item) : item;
1232
- j = newIndices.get(keyVal);
1233
- if (j !== void 0 && j !== -1) {
1234
- temp[j] = item;
1235
- j = newIndicesNext[j];
1236
- newIndices.set(keyVal, j);
1088
+ for (c = f; c <= E; c++) {
1089
+ T = getOverrideValue(s, o, u, c);
1090
+ h = T ? n(T) : T;
1091
+ a = S.get(h);
1092
+ if (a !== undefined && a !== -1) {
1093
+ _[a] = T;
1094
+ a = R[a];
1095
+ S.set(h, a);
1237
1096
  }
1238
1097
  }
1239
- for (j = start; j < next.length; j++) {
1240
- if (j in temp) {
1241
- const wrapped = wrap(temp[j], target);
1242
- target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrapped);
1243
- applyState(next[j], wrapped, keyFn, all);
1244
- } else
1245
- target[STORE_NODE][j] && setSignal(target[STORE_NODE][j], wrap(next[j], target));
1098
+ for (a = f; a < e.length; a++) {
1099
+ if (a in _) {
1100
+ const t = wrap(_[a], r);
1101
+ r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], t);
1102
+ applyState(e[a], t, n, i);
1103
+ } else r[STORE_NODE][a] && setSignal(r[STORE_NODE][a], wrap(e[a], r));
1246
1104
  }
1247
- if (start < next.length)
1248
- changed = true;
1249
- } else if (prevLength && next.length) {
1250
- for (let i = 0, len = next.length; i < len; i++) {
1251
- const item = getOverrideValue(previous, override, nodes, i);
1252
- isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
1105
+ if (f < e.length) t = true;
1106
+ } else if (l && e.length) {
1107
+ for (let t = 0, l = e.length; t < l; t++) {
1108
+ const l = getOverrideValue(s, o, u, t);
1109
+ isWrappable(l) && applyState(e[t], wrap(l, r), n, i);
1253
1110
  }
1254
1111
  }
1255
- if (prevLength !== next.length) {
1256
- changed = true;
1257
- target[STORE_NODE].length && setSignal(target[STORE_NODE].length, next.length);
1112
+ if (l !== e.length) {
1113
+ t = true;
1114
+ r[STORE_NODE].length && setSignal(r[STORE_NODE].length, e.length);
1258
1115
  }
1259
- changed && target[STORE_NODE][$TRACK] && setSignal(target[STORE_NODE][$TRACK], void 0);
1116
+ t && r[STORE_NODE][$TRACK] && setSignal(r[STORE_NODE][$TRACK], void 0);
1260
1117
  return;
1261
1118
  }
1262
- if (nodes) {
1263
- const tracked = nodes[$TRACK];
1264
- const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
1265
- for (let i = 0, len = keys.length; i < len; i++) {
1266
- const key = keys[i];
1267
- const node = nodes[key];
1268
- const previousValue = unwrap(getOverrideValue(previous, override, nodes, key));
1269
- let nextValue = unwrap(next[key]);
1270
- if (previousValue === nextValue)
1271
- continue;
1272
- if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue)) {
1273
- tracked && setSignal(tracked, void 0);
1274
- node && setSignal(node, isWrappable(nextValue) ? wrap(nextValue, target) : nextValue);
1275
- } else
1276
- applyState(nextValue, wrap(previousValue, target), keyFn, all);
1277
- }
1278
- }
1279
- if (nodes = target[STORE_HAS]) {
1280
- const keys = Object.keys(nodes);
1281
- for (let i = 0, len = keys.length; i < len; i++) {
1282
- const key = keys[i];
1283
- setSignal(nodes[key], key in next);
1284
- }
1285
- }
1286
- }
1287
- function reconcile(value, key, all = false) {
1288
- return (state) => {
1289
- if (state == null)
1290
- throw new Error("Cannot reconcile null or undefined state");
1291
- const keyFn = typeof key === "string" ? (item) => item[key] : key;
1292
- const eq = keyFn(state);
1293
- if (eq !== void 0 && keyFn(value) !== keyFn(state))
1119
+ if (u) {
1120
+ const t = u[$TRACK];
1121
+ const l = t || i ? getAllKeys(s, o, e) : Object.keys(u);
1122
+ for (let c = 0, a = l.length; c < a; c++) {
1123
+ const a = l[c];
1124
+ const f = u[a];
1125
+ const E = unwrap(getOverrideValue(s, o, u, a));
1126
+ let d = unwrap(e[a]);
1127
+ if (E === d) continue;
1128
+ if (!E || !isWrappable(E) || (n(E) != null && n(E) !== n(d))) {
1129
+ t && setSignal(t, void 0);
1130
+ f && setSignal(f, isWrappable(d) ? wrap(d, r) : d);
1131
+ } else applyState(d, wrap(E, r), n, i);
1132
+ }
1133
+ }
1134
+ if ((u = r[STORE_HAS])) {
1135
+ const t = Object.keys(u);
1136
+ for (let n = 0, i = t.length; n < i; n++) {
1137
+ const i = t[n];
1138
+ setSignal(u[i], i in e);
1139
+ }
1140
+ }
1141
+ }
1142
+ function reconcile(e, t, n = false) {
1143
+ return i => {
1144
+ if (i == null) throw new Error("Cannot reconcile null or undefined state");
1145
+ const r = typeof t === "string" ? e => e[t] : t;
1146
+ const s = r(i);
1147
+ if (s !== undefined && r(e) !== r(i))
1294
1148
  throw new Error("Cannot reconcile states with different identity");
1295
- applyState(value, state, keyFn, all);
1149
+ applyState(e, i, r, n);
1296
1150
  };
1297
1151
  }
1298
-
1299
- // src/store/projection.ts
1300
- function createProjectionInternal(fn, initialValue = {}, options) {
1301
- let node;
1302
- const wrappedMap = /* @__PURE__ */ new WeakMap();
1303
- const wrapProjection = (source) => {
1304
- if (wrappedMap.has(source))
1305
- return wrappedMap.get(source);
1306
- if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
1307
- return source;
1308
- const wrapped = createStoreProxy(source, storeTraps, {
1152
+ function createProjectionInternal(e, t = {}, n) {
1153
+ let i;
1154
+ const r = new WeakMap();
1155
+ const wrapProjection = e => {
1156
+ if (r.has(e)) return r.get(e);
1157
+ if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
1158
+ const t = createStoreProxy(e, storeTraps, {
1309
1159
  [STORE_WRAP]: wrapProjection,
1310
- [STORE_LOOKUP]: wrappedMap,
1160
+ [STORE_LOOKUP]: r,
1311
1161
  [STORE_FIREWALL]() {
1312
- return node;
1162
+ return i;
1313
1163
  }
1314
1164
  });
1315
- wrappedMap.set(source, wrapped);
1316
- return wrapped;
1165
+ r.set(e, t);
1166
+ return t;
1317
1167
  };
1318
- const wrappedStore = wrapProjection(initialValue);
1319
- node = computed(() => {
1320
- storeSetter(wrappedStore, (s) => {
1321
- const value = fn(s);
1322
- if (value !== s && value !== void 0) {
1323
- reconcile(value, options?.key || "id", options?.all)(s);
1168
+ const s = wrapProjection(t);
1169
+ i = computed(() => {
1170
+ storeSetter(s, t => {
1171
+ const i = e(t);
1172
+ if (i !== t && i !== undefined) {
1173
+ reconcile(i, n?.key || "id", n?.all)(t);
1324
1174
  }
1325
1175
  });
1326
1176
  });
1327
- return { store: wrappedStore, node };
1328
- }
1329
- function createProjection(fn, initialValue = {}, options) {
1330
- return createProjectionInternal(fn, initialValue, options).store;
1331
- }
1332
-
1333
- // src/store/store.ts
1334
- var $TRACK = Symbol(0);
1335
- var $DEEP = Symbol(0);
1336
- var $TARGET = Symbol(0);
1337
- var $PROXY = Symbol(0);
1338
- var $DELETED = Symbol(0);
1339
- var PARENTS = /* @__PURE__ */ new WeakMap();
1340
- var STORE_VALUE = "v";
1341
- var STORE_OVERRIDE = "o";
1342
- var STORE_NODE = "n";
1343
- var STORE_HAS = "h";
1344
- var STORE_WRAP = "w";
1345
- var STORE_LOOKUP = "l";
1346
- var STORE_FIREWALL = "f";
1347
- function createStoreProxy(value, traps = storeTraps, extend) {
1348
- let newTarget;
1349
- if (Array.isArray(value)) {
1350
- newTarget = [];
1351
- newTarget.v = value;
1352
- } else
1353
- newTarget = { v: value };
1354
- extend && Object.assign(newTarget, extend);
1355
- return newTarget[$PROXY] = new Proxy(newTarget, traps);
1356
- }
1357
- var storeLookup = /* @__PURE__ */ new WeakMap();
1358
- function wrap(value, target) {
1359
- if (target?.[STORE_WRAP])
1360
- return target[STORE_WRAP](value, target);
1361
- let p = value[$PROXY] || storeLookup.get(value);
1362
- if (!p)
1363
- storeLookup.set(value, p = createStoreProxy(value));
1364
- return p;
1365
- }
1366
- function isWrappable(obj) {
1367
- return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
1368
- }
1369
- function getNodes(target, type) {
1370
- let nodes = target[type];
1371
- if (!nodes)
1372
- target[type] = nodes = /* @__PURE__ */ Object.create(null);
1373
- return nodes;
1374
- }
1375
- function getNode(nodes, property, value, firewall, equals = isEqual) {
1376
- if (nodes[property])
1377
- return nodes[property];
1378
- return nodes[property] = signal(
1379
- value,
1177
+ return { store: s, node: i };
1178
+ }
1179
+ function createProjection(e, t = {}, n) {
1180
+ return createProjectionInternal(e, t, n).store;
1181
+ }
1182
+ const $TRACK = Symbol(0),
1183
+ $DEEP = Symbol(0),
1184
+ $TARGET = Symbol(0),
1185
+ $PROXY = Symbol(0),
1186
+ $DELETED = Symbol(0);
1187
+ const PARENTS = new WeakMap();
1188
+ const STORE_VALUE = "v",
1189
+ STORE_OVERRIDE = "o",
1190
+ STORE_NODE = "n",
1191
+ STORE_HAS = "h",
1192
+ STORE_WRAP = "w",
1193
+ STORE_LOOKUP = "l",
1194
+ STORE_FIREWALL = "f";
1195
+ function createStoreProxy(e, t = storeTraps, n) {
1196
+ let i;
1197
+ if (Array.isArray(e)) {
1198
+ i = [];
1199
+ i.v = e;
1200
+ } else i = { v: e };
1201
+ n && Object.assign(i, n);
1202
+ return (i[$PROXY] = new Proxy(i, t));
1203
+ }
1204
+ const storeLookup = new WeakMap();
1205
+ function wrap(e, t) {
1206
+ if (t?.[STORE_WRAP]) return t[STORE_WRAP](e, t);
1207
+ let n = e[$PROXY] || storeLookup.get(e);
1208
+ if (!n) storeLookup.set(e, (n = createStoreProxy(e)));
1209
+ return n;
1210
+ }
1211
+ function isWrappable(e) {
1212
+ return e != null && typeof e === "object" && !Object.isFrozen(e);
1213
+ }
1214
+ function getNodes(e, t) {
1215
+ let n = e[t];
1216
+ if (!n) e[t] = n = Object.create(null);
1217
+ return n;
1218
+ }
1219
+ function getNode(e, t, n, i, r = isEqual) {
1220
+ if (e[t]) return e[t];
1221
+ return (e[t] = signal(
1222
+ n,
1380
1223
  {
1381
- equals,
1224
+ equals: r,
1382
1225
  unobserved() {
1383
- delete nodes[property];
1226
+ delete e[t];
1384
1227
  }
1385
1228
  },
1386
- firewall
1387
- );
1388
- }
1389
- function trackSelf(target, symbol = $TRACK) {
1390
- getObserver() && read(
1391
- getNode(getNodes(target, STORE_NODE), symbol, void 0, target[STORE_FIREWALL]?.(), false)
1392
- );
1393
- }
1394
- function getKeys(source, override, enumerable = true) {
1395
- const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
1396
- if (!override)
1397
- return baseKeys;
1398
- const keys = new Set(baseKeys);
1399
- const overrides = Reflect.ownKeys(override);
1400
- for (const key of overrides) {
1401
- if (override[key] !== $DELETED)
1402
- keys.add(key);
1403
- else
1404
- keys.delete(key);
1405
- }
1406
- return Array.from(keys);
1407
- }
1408
- function getPropertyDescriptor(source, override, property) {
1409
- let value = source;
1410
- if (override && property in override) {
1411
- if (value[property] === $DELETED)
1412
- return void 0;
1413
- if (!(property in value))
1414
- value = override;
1415
- }
1416
- return Reflect.getOwnPropertyDescriptor(value, property);
1417
- }
1418
- var Writing = null;
1419
- var storeTraps = {
1420
- get(target, property, receiver) {
1421
- if (property === $TARGET)
1422
- return target;
1423
- if (property === $PROXY)
1424
- return receiver;
1425
- if (property === $TRACK || property === $DEEP) {
1426
- trackSelf(target, property);
1427
- return receiver;
1428
- }
1429
- const nodes = getNodes(target, STORE_NODE);
1430
- const tracked = nodes[property];
1431
- const overridden = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE];
1432
- const proxySource = !!target[STORE_VALUE][$TARGET];
1433
- const storeValue = overridden ? target[STORE_OVERRIDE] : target[STORE_VALUE];
1434
- if (!tracked) {
1435
- const desc = Object.getOwnPropertyDescriptor(storeValue, property);
1436
- if (desc && desc.get)
1437
- return desc.get.call(receiver);
1438
- }
1439
- if (Writing?.has(receiver)) {
1440
- let value2 = tracked && (overridden || !proxySource) ? tracked.e !== NOT_PENDING ? tracked.e : tracked.g : storeValue[property];
1441
- value2 === $DELETED && (value2 = void 0);
1442
- if (!isWrappable(value2))
1443
- return value2;
1444
- const wrapped = wrap(value2, target);
1445
- Writing.add(wrapped);
1446
- return wrapped;
1447
- }
1448
- let value = tracked ? overridden || !proxySource ? read(nodes[property]) : (read(nodes[property]), storeValue[property]) : storeValue[property];
1449
- value === $DELETED && (value = void 0);
1450
- if (!tracked) {
1451
- if (!overridden && typeof value === "function" && !storeValue.hasOwnProperty(property)) {
1452
- let proto;
1453
- return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
1229
+ i
1230
+ ));
1231
+ }
1232
+ function trackSelf(e, t = $TRACK) {
1233
+ getObserver() &&
1234
+ read(getNode(getNodes(e, STORE_NODE), t, undefined, e[STORE_FIREWALL]?.(), false));
1235
+ }
1236
+ function getKeys(e, t, n = true) {
1237
+ const i = untrack(() => (n ? Object.keys(e) : Reflect.ownKeys(e)));
1238
+ if (!t) return i;
1239
+ const r = new Set(i);
1240
+ const s = Reflect.ownKeys(t);
1241
+ for (const e of s) {
1242
+ if (t[e] !== $DELETED) r.add(e);
1243
+ else r.delete(e);
1244
+ }
1245
+ return Array.from(r);
1246
+ }
1247
+ function getPropertyDescriptor(e, t, n) {
1248
+ let i = e;
1249
+ if (t && n in t) {
1250
+ if (i[n] === $DELETED) return void 0;
1251
+ if (!(n in i)) i = t;
1252
+ }
1253
+ return Reflect.getOwnPropertyDescriptor(i, n);
1254
+ }
1255
+ let Writing = null;
1256
+ const storeTraps = {
1257
+ get(e, t, n) {
1258
+ if (t === $TARGET) return e;
1259
+ if (t === $PROXY) return n;
1260
+ if (t === $TRACK || t === $DEEP) {
1261
+ trackSelf(e, t);
1262
+ return n;
1263
+ }
1264
+ const i = getNodes(e, STORE_NODE);
1265
+ const r = i[t];
1266
+ const s = e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE];
1267
+ const o = !!e[STORE_VALUE][$TARGET];
1268
+ const u = s ? e[STORE_OVERRIDE] : e[STORE_VALUE];
1269
+ if (!r) {
1270
+ const e = Object.getOwnPropertyDescriptor(u, t);
1271
+ if (e && e.get) return e.get.call(n);
1272
+ }
1273
+ if (Writing?.has(n)) {
1274
+ let n = r && (s || !o) ? (r.W !== NOT_PENDING ? r.W : r.j) : u[t];
1275
+ n === $DELETED && (n = undefined);
1276
+ if (!isWrappable(n)) return n;
1277
+ const i = wrap(n, e);
1278
+ Writing.add(i);
1279
+ return i;
1280
+ }
1281
+ let l = r ? (s || !o ? read(i[t]) : (read(i[t]), u[t])) : u[t];
1282
+ l === $DELETED && (l = undefined);
1283
+ if (!r) {
1284
+ if (!s && typeof l === "function" && !u.hasOwnProperty(t)) {
1285
+ let t;
1286
+ return !Array.isArray(e[STORE_VALUE]) &&
1287
+ (t = Object.getPrototypeOf(e[STORE_VALUE])) &&
1288
+ t !== Object.prototype
1289
+ ? l.bind(u)
1290
+ : l;
1454
1291
  } else if (getObserver()) {
1455
- return read(
1456
- getNode(
1457
- nodes,
1458
- property,
1459
- isWrappable(value) ? wrap(value, target) : value,
1460
- target[STORE_FIREWALL]?.()
1461
- )
1462
- );
1292
+ return read(getNode(i, t, isWrappable(l) ? wrap(l, e) : l, e[STORE_FIREWALL]?.()));
1463
1293
  }
1464
1294
  }
1465
- return isWrappable(value) ? wrap(value, target) : value;
1295
+ return isWrappable(l) ? wrap(l, e) : l;
1466
1296
  },
1467
- has(target, property) {
1468
- if (property === $PROXY || property === $TRACK || property === "__proto__")
1469
- return true;
1470
- const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
1471
- getObserver() && read(getNode(getNodes(target, STORE_HAS), property, has, target[STORE_FIREWALL]?.()));
1472
- return has;
1297
+ has(e, t) {
1298
+ if (t === $PROXY || t === $TRACK || t === "__proto__") return true;
1299
+ const n =
1300
+ e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]
1301
+ ? e[STORE_OVERRIDE][t] !== $DELETED
1302
+ : t in e[STORE_VALUE];
1303
+ getObserver() && read(getNode(getNodes(e, STORE_HAS), t, n, e[STORE_FIREWALL]?.()));
1304
+ return n;
1473
1305
  },
1474
- set(target, property, rawValue) {
1475
- const store = target[$PROXY];
1476
- if (Writing?.has(target[$PROXY])) {
1306
+ set(e, t, n) {
1307
+ const i = e[$PROXY];
1308
+ if (Writing?.has(e[$PROXY])) {
1477
1309
  untrack(() => {
1478
- const state = target[STORE_VALUE];
1479
- const base = state[property];
1480
- const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : base;
1481
- const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
1482
- if (prev === value)
1483
- return true;
1484
- const len = target[STORE_OVERRIDE]?.length || state.length;
1485
- if (value !== void 0 && value === base)
1486
- delete target[STORE_OVERRIDE][property];
1487
- else
1488
- (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = value;
1489
- const wrappable = isWrappable(value);
1490
- if (isWrappable(prev)) {
1491
- const parents = PARENTS.get(prev);
1492
- parents && (parents instanceof Set ? parents.delete(store) : PARENTS.delete(prev));
1310
+ const r = e[STORE_VALUE];
1311
+ const s = r[t];
1312
+ const o = e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE] ? e[STORE_OVERRIDE][t] : s;
1313
+ const u = n?.[$TARGET]?.[STORE_VALUE] ?? n;
1314
+ if (o === u) return true;
1315
+ const l = e[STORE_OVERRIDE]?.length || r.length;
1316
+ if (u !== undefined && u === s) delete e[STORE_OVERRIDE][t];
1317
+ else (e[STORE_OVERRIDE] || (e[STORE_OVERRIDE] = Object.create(null)))[t] = u;
1318
+ const c = isWrappable(u);
1319
+ if (isWrappable(o)) {
1320
+ const e = PARENTS.get(o);
1321
+ e && (e instanceof Set ? e.delete(i) : PARENTS.delete(o));
1493
1322
  }
1494
- if (recursivelyNotify(store, storeLookup) && wrappable)
1495
- recursivelyAddParent(value, store);
1496
- target[STORE_HAS]?.[property] && setSignal(target[STORE_HAS][property], true);
1497
- const nodes = getNodes(target, STORE_NODE);
1498
- nodes[property] && setSignal(nodes[property], () => wrappable ? wrap(value, target) : value);
1499
- if (Array.isArray(state)) {
1500
- const index = parseInt(property) + 1;
1501
- if (index > len)
1502
- nodes.length && setSignal(nodes.length, index);
1323
+ if (recursivelyNotify(i, storeLookup) && c) recursivelyAddParent(u, i);
1324
+ e[STORE_HAS]?.[t] && setSignal(e[STORE_HAS][t], true);
1325
+ const a = getNodes(e, STORE_NODE);
1326
+ a[t] && setSignal(a[t], () => (c ? wrap(u, e) : u));
1327
+ if (Array.isArray(r)) {
1328
+ const e = parseInt(t) + 1;
1329
+ if (e > l) a.length && setSignal(a.length, e);
1503
1330
  }
1504
- nodes[$TRACK] && setSignal(nodes[$TRACK], void 0);
1331
+ a[$TRACK] && setSignal(a[$TRACK], undefined);
1505
1332
  });
1506
1333
  }
1507
1334
  return true;
1508
1335
  },
1509
- deleteProperty(target, property) {
1510
- if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
1336
+ deleteProperty(e, t) {
1337
+ if (Writing?.has(e[$PROXY]) && e[STORE_OVERRIDE]?.[t] !== $DELETED) {
1511
1338
  untrack(() => {
1512
- const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : target[STORE_VALUE][property];
1513
- if (property in target[STORE_VALUE]) {
1514
- (target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
1515
- } else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
1516
- delete target[STORE_OVERRIDE][property];
1517
- } else
1518
- return true;
1519
- if (isWrappable(prev)) {
1520
- const parents = PARENTS.get(prev);
1521
- parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
1339
+ const n =
1340
+ e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE] ? e[STORE_OVERRIDE][t] : e[STORE_VALUE][t];
1341
+ if (t in e[STORE_VALUE]) {
1342
+ (e[STORE_OVERRIDE] || (e[STORE_OVERRIDE] = Object.create(null)))[t] = $DELETED;
1343
+ } else if (e[STORE_OVERRIDE] && t in e[STORE_OVERRIDE]) {
1344
+ delete e[STORE_OVERRIDE][t];
1345
+ } else return true;
1346
+ if (isWrappable(n)) {
1347
+ const t = PARENTS.get(n);
1348
+ t && (t instanceof Set ? t.delete(e) : PARENTS.delete(n));
1522
1349
  }
1523
- if (target[STORE_HAS]?.[property])
1524
- setSignal(target[STORE_HAS][property], false);
1525
- const nodes = getNodes(target, STORE_NODE);
1526
- nodes[property] && setSignal(nodes[property], void 0);
1527
- nodes[$TRACK] && setSignal(nodes[$TRACK], void 0);
1350
+ if (e[STORE_HAS]?.[t]) setSignal(e[STORE_HAS][t], false);
1351
+ const i = getNodes(e, STORE_NODE);
1352
+ i[t] && setSignal(i[t], undefined);
1353
+ i[$TRACK] && setSignal(i[$TRACK], undefined);
1528
1354
  });
1529
1355
  }
1530
1356
  return true;
1531
1357
  },
1532
- ownKeys(target) {
1533
- trackSelf(target);
1534
- return getKeys(target[STORE_VALUE], target[STORE_OVERRIDE], false);
1358
+ ownKeys(e) {
1359
+ trackSelf(e);
1360
+ return getKeys(e[STORE_VALUE], e[STORE_OVERRIDE], false);
1535
1361
  },
1536
- getOwnPropertyDescriptor(target, property) {
1537
- if (property === $PROXY)
1538
- return { value: target[$PROXY], writable: true, configurable: true };
1539
- return getPropertyDescriptor(target[STORE_VALUE], target[STORE_OVERRIDE], property);
1362
+ getOwnPropertyDescriptor(e, t) {
1363
+ if (t === $PROXY) return { value: e[$PROXY], writable: true, configurable: true };
1364
+ return getPropertyDescriptor(e[STORE_VALUE], e[STORE_OVERRIDE], t);
1540
1365
  },
1541
- getPrototypeOf(target) {
1542
- return Object.getPrototypeOf(target[STORE_VALUE]);
1366
+ getPrototypeOf(e) {
1367
+ return Object.getPrototypeOf(e[STORE_VALUE]);
1543
1368
  }
1544
1369
  };
1545
- function storeSetter(store, fn) {
1546
- const prevWriting = Writing;
1547
- Writing = /* @__PURE__ */ new Set();
1548
- Writing.add(store);
1370
+ function storeSetter(e, t) {
1371
+ const n = Writing;
1372
+ Writing = new Set();
1373
+ Writing.add(e);
1549
1374
  try {
1550
- const value = fn(store);
1551
- if (value !== store && value !== void 0) {
1552
- if (Array.isArray(value)) {
1553
- for (let i = 0, len = value.length; i < len; i++)
1554
- store[i] = value[i];
1555
- store.length = value.length;
1375
+ const n = t(e);
1376
+ if (n !== e && n !== undefined) {
1377
+ if (Array.isArray(n)) {
1378
+ for (let t = 0, i = n.length; t < i; t++) e[t] = n[t];
1379
+ e.length = n.length;
1556
1380
  } else {
1557
- const keys = /* @__PURE__ */ new Set([...Object.keys(store), ...Object.keys(value)]);
1558
- keys.forEach((key) => {
1559
- if (key in value)
1560
- store[key] = value[key];
1561
- else
1562
- delete store[key];
1381
+ const t = new Set([...Object.keys(e), ...Object.keys(n)]);
1382
+ t.forEach(t => {
1383
+ if (t in n) e[t] = n[t];
1384
+ else delete e[t];
1563
1385
  });
1564
1386
  }
1565
1387
  }
1566
1388
  } finally {
1567
1389
  Writing.clear();
1568
- Writing = prevWriting;
1569
- }
1570
- }
1571
- function createStore(first, second, options) {
1572
- const derived = typeof first === "function", wrappedStore = derived ? createProjectionInternal(first, second, options).store : wrap(first);
1573
- return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
1574
- }
1575
- function recursivelyNotify(state, lookup) {
1576
- let target = state[$TARGET] || lookup?.get(state)?.[$TARGET];
1577
- let notified = false;
1578
- if (target) {
1579
- const deep2 = getNodes(target, STORE_NODE)[$DEEP];
1580
- if (deep2) {
1581
- setSignal(deep2, void 0);
1582
- notified = true;
1583
- }
1584
- lookup = target[STORE_LOOKUP] || lookup;
1585
- }
1586
- const parents = PARENTS.get(target?.[STORE_VALUE] || state);
1587
- if (!parents)
1588
- return notified;
1589
- if (parents instanceof Set) {
1590
- for (let parent of parents)
1591
- notified = recursivelyNotify(parent, lookup) || notified;
1592
- } else
1593
- notified = recursivelyNotify(parents, lookup) || notified;
1594
- return notified;
1595
- }
1596
- function recursivelyAddParent(state, parent) {
1597
- let override;
1598
- const target = state[$TARGET];
1599
- if (target) {
1600
- override = target[STORE_OVERRIDE];
1601
- state = target[STORE_VALUE];
1602
- }
1603
- if (parent) {
1604
- let parents = PARENTS.get(state);
1605
- if (!parents)
1606
- PARENTS.set(state, parent);
1607
- else if (parents !== parent) {
1608
- if (!(parents instanceof Set))
1609
- PARENTS.set(state, parents = /* @__PURE__ */ new Set([parents]));
1610
- else if (parents.has(parent))
1611
- return;
1612
- parents.add(parent);
1613
- } else
1614
- return;
1615
- }
1616
- if (Array.isArray(state)) {
1617
- const len = override?.length || state.length;
1618
- for (let i = 0; i < len; i++) {
1619
- const item = override && i in override ? override[i] : state[i];
1620
- isWrappable(item) && recursivelyAddParent(item, state);
1390
+ Writing = n;
1391
+ }
1392
+ }
1393
+ function createStore(e, t, n) {
1394
+ const i = typeof e === "function",
1395
+ r = i ? createProjectionInternal(e, t, n).store : wrap(e);
1396
+ return [r, e => storeSetter(r, e)];
1397
+ }
1398
+ function recursivelyNotify(e, t) {
1399
+ let n = e[$TARGET] || t?.get(e)?.[$TARGET];
1400
+ let i = false;
1401
+ if (n) {
1402
+ const e = getNodes(n, STORE_NODE)[$DEEP];
1403
+ if (e) {
1404
+ setSignal(e, undefined);
1405
+ i = true;
1406
+ }
1407
+ t = n[STORE_LOOKUP] || t;
1408
+ }
1409
+ const r = PARENTS.get(n?.[STORE_VALUE] || e);
1410
+ if (!r) return i;
1411
+ if (r instanceof Set) {
1412
+ for (let e of r) i = recursivelyNotify(e, t) || i;
1413
+ } else i = recursivelyNotify(r, t) || i;
1414
+ return i;
1415
+ }
1416
+ function recursivelyAddParent(e, t) {
1417
+ let n;
1418
+ const i = e[$TARGET];
1419
+ if (i) {
1420
+ n = i[STORE_OVERRIDE];
1421
+ e = i[STORE_VALUE];
1422
+ }
1423
+ if (t) {
1424
+ let n = PARENTS.get(e);
1425
+ if (!n) PARENTS.set(e, t);
1426
+ else if (n !== t) {
1427
+ if (!(n instanceof Set)) PARENTS.set(e, (n = new Set([n])));
1428
+ else if (n.has(t)) return;
1429
+ n.add(t);
1430
+ } else return;
1431
+ }
1432
+ if (Array.isArray(e)) {
1433
+ const t = n?.length || e.length;
1434
+ for (let i = 0; i < t; i++) {
1435
+ const t = n && i in n ? n[i] : e[i];
1436
+ isWrappable(t) && recursivelyAddParent(t, e);
1621
1437
  }
1622
1438
  } else {
1623
- const keys = getKeys(state, override);
1624
- for (let i = 0; i < keys.length; i++) {
1625
- const key = keys[i];
1626
- const item = override && key in override ? override[key] : state[key];
1627
- isWrappable(item) && recursivelyAddParent(item, state);
1439
+ const t = getKeys(e, n);
1440
+ for (let i = 0; i < t.length; i++) {
1441
+ const r = t[i];
1442
+ const s = n && r in n ? n[r] : e[r];
1443
+ isWrappable(s) && recursivelyAddParent(s, e);
1628
1444
  }
1629
1445
  }
1630
1446
  }
1631
- function deep(store) {
1632
- recursivelyAddParent(store);
1633
- return store[$DEEP];
1447
+ function deep(e) {
1448
+ recursivelyAddParent(e);
1449
+ return e[$DEEP];
1634
1450
  }
1635
-
1636
- // src/store/optimistic.ts
1637
- function createOptimisticStore(first, second, options) {
1451
+ function createOptimisticStore(e, t, n) {
1638
1452
  return [];
1639
1453
  }
1640
-
1641
- // src/store/utils.ts
1642
- function snapshot(item, map, lookup) {
1643
- let target, isArray, override, result, unwrapped, v;
1644
- if (!isWrappable(item))
1645
- return item;
1646
- if (map && map.has(item))
1647
- return map.get(item);
1648
- if (!map)
1649
- map = /* @__PURE__ */ new Map();
1650
- if (target = item[$TARGET] || lookup?.get(item)?.[$TARGET]) {
1651
- override = target[STORE_OVERRIDE];
1652
- isArray = Array.isArray(target[STORE_VALUE]);
1653
- map.set(
1654
- item,
1655
- override ? result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])) : target[STORE_VALUE]
1454
+ function snapshot(e, t, n) {
1455
+ let i, r, s, o, u, l;
1456
+ if (!isWrappable(e)) return e;
1457
+ if (t && t.has(e)) return t.get(e);
1458
+ if (!t) t = new Map();
1459
+ if ((i = e[$TARGET] || n?.get(e)?.[$TARGET])) {
1460
+ s = i[STORE_OVERRIDE];
1461
+ r = Array.isArray(i[STORE_VALUE]);
1462
+ t.set(
1463
+ e,
1464
+ s ? (o = r ? [] : Object.create(Object.getPrototypeOf(i[STORE_VALUE]))) : i[STORE_VALUE]
1656
1465
  );
1657
- item = target[STORE_VALUE];
1658
- lookup = storeLookup;
1466
+ e = i[STORE_VALUE];
1467
+ n = storeLookup;
1659
1468
  } else {
1660
- isArray = Array.isArray(item);
1661
- map.set(item, item);
1662
- }
1663
- if (isArray) {
1664
- const len = override?.length || item.length;
1665
- for (let i = 0; i < len; i++) {
1666
- v = override && i in override ? override[i] : item[i];
1667
- if (v === $DELETED)
1668
- continue;
1669
- if ((unwrapped = snapshot(v, map, lookup)) !== v || result) {
1670
- if (!result)
1671
- map.set(item, result = [...item]);
1672
- result[i] = unwrapped;
1469
+ r = Array.isArray(e);
1470
+ t.set(e, e);
1471
+ }
1472
+ if (r) {
1473
+ const i = s?.length || e.length;
1474
+ for (let r = 0; r < i; r++) {
1475
+ l = s && r in s ? s[r] : e[r];
1476
+ if (l === $DELETED) continue;
1477
+ if ((u = snapshot(l, t, n)) !== l || o) {
1478
+ if (!o) t.set(e, (o = [...e]));
1479
+ o[r] = u;
1673
1480
  }
1674
1481
  }
1675
1482
  } else {
1676
- const keys = getKeys(item, override);
1677
- for (let i = 0, l = keys.length; i < l; i++) {
1678
- let prop = keys[i];
1679
- const desc = getPropertyDescriptor(item, override, prop);
1680
- if (desc.get)
1681
- continue;
1682
- v = override && prop in override ? override[prop] : item[prop];
1683
- if ((unwrapped = snapshot(v, map, lookup)) !== item[prop] || result) {
1684
- if (!result) {
1685
- result = Object.create(Object.getPrototypeOf(item));
1686
- Object.assign(result, item);
1483
+ const i = getKeys(e, s);
1484
+ for (let r = 0, c = i.length; r < c; r++) {
1485
+ let c = i[r];
1486
+ const a = getPropertyDescriptor(e, s, c);
1487
+ if (a.get) continue;
1488
+ l = s && c in s ? s[c] : e[c];
1489
+ if ((u = snapshot(l, t, n)) !== e[c] || o) {
1490
+ if (!o) {
1491
+ o = Object.create(Object.getPrototypeOf(e));
1492
+ Object.assign(o, e);
1687
1493
  }
1688
- result[prop] = unwrapped;
1494
+ o[c] = u;
1689
1495
  }
1690
1496
  }
1691
1497
  }
1692
- return result || item;
1498
+ return o || e;
1693
1499
  }
1694
1500
  function trueFn() {
1695
1501
  return true;
1696
1502
  }
1697
- var propTraps = {
1698
- get(_, property, receiver) {
1699
- if (property === $PROXY)
1700
- return receiver;
1701
- return _.get(property);
1503
+ const propTraps = {
1504
+ get(e, t, n) {
1505
+ if (t === $PROXY) return n;
1506
+ return e.get(t);
1702
1507
  },
1703
- has(_, property) {
1704
- if (property === $PROXY)
1705
- return true;
1706
- return _.has(property);
1508
+ has(e, t) {
1509
+ if (t === $PROXY) return true;
1510
+ return e.has(t);
1707
1511
  },
1708
1512
  set: trueFn,
1709
1513
  deleteProperty: trueFn,
1710
- getOwnPropertyDescriptor(_, property) {
1514
+ getOwnPropertyDescriptor(e, t) {
1711
1515
  return {
1712
1516
  configurable: true,
1713
1517
  enumerable: true,
1714
1518
  get() {
1715
- return _.get(property);
1519
+ return e.get(t);
1716
1520
  },
1717
1521
  set: trueFn,
1718
1522
  deleteProperty: trueFn
1719
1523
  };
1720
1524
  },
1721
- ownKeys(_) {
1722
- return _.keys();
1525
+ ownKeys(e) {
1526
+ return e.keys();
1723
1527
  }
1724
1528
  };
1725
- function resolveSource(s) {
1726
- return !(s = typeof s === "function" ? s() : s) ? {} : s;
1727
- }
1728
- var $SOURCES = Symbol(0);
1729
- function merge(...sources) {
1730
- if (sources.length === 1 && typeof sources[0] !== "function")
1731
- return sources[0];
1732
- let proxy = false;
1733
- const flattened = [];
1734
- for (let i = 0; i < sources.length; i++) {
1735
- const s = sources[i];
1736
- proxy = proxy || !!s && $PROXY in s;
1737
- const childSources = !!s && s[$SOURCES];
1738
- if (childSources)
1739
- flattened.push(...childSources);
1740
- else
1741
- flattened.push(
1742
- typeof s === "function" ? (proxy = true, createMemo(s)) : s
1743
- );
1744
- }
1745
- if (SUPPORTS_PROXY && proxy) {
1529
+ function resolveSource(e) {
1530
+ return !(e = typeof e === "function" ? e() : e) ? {} : e;
1531
+ }
1532
+ const $SOURCES = Symbol(0);
1533
+ function merge(...e) {
1534
+ if (e.length === 1 && typeof e[0] !== "function") return e[0];
1535
+ let t = false;
1536
+ const n = [];
1537
+ for (let i = 0; i < e.length; i++) {
1538
+ const r = e[i];
1539
+ t = t || (!!r && $PROXY in r);
1540
+ const s = !!r && r[$SOURCES];
1541
+ if (s) n.push(...s);
1542
+ else n.push(typeof r === "function" ? ((t = true), createMemo(r)) : r);
1543
+ }
1544
+ if (SUPPORTS_PROXY && t) {
1746
1545
  return new Proxy(
1747
1546
  {
1748
- get(property) {
1749
- if (property === $SOURCES)
1750
- return flattened;
1751
- for (let i = flattened.length - 1; i >= 0; i--) {
1752
- const s = resolveSource(flattened[i]);
1753
- if (property in s)
1754
- return s[property];
1547
+ get(e) {
1548
+ if (e === $SOURCES) return n;
1549
+ for (let t = n.length - 1; t >= 0; t--) {
1550
+ const i = resolveSource(n[t]);
1551
+ if (e in i) return i[e];
1755
1552
  }
1756
1553
  },
1757
- has(property) {
1758
- for (let i = flattened.length - 1; i >= 0; i--) {
1759
- if (property in resolveSource(flattened[i]))
1760
- return true;
1554
+ has(e) {
1555
+ for (let t = n.length - 1; t >= 0; t--) {
1556
+ if (e in resolveSource(n[t])) return true;
1761
1557
  }
1762
1558
  return false;
1763
1559
  },
1764
1560
  keys() {
1765
- const keys = [];
1766
- for (let i = 0; i < flattened.length; i++)
1767
- keys.push(...Object.keys(resolveSource(flattened[i])));
1768
- return [...new Set(keys)];
1561
+ const e = [];
1562
+ for (let t = 0; t < n.length; t++) e.push(...Object.keys(resolveSource(n[t])));
1563
+ return [...new Set(e)];
1769
1564
  }
1770
1565
  },
1771
1566
  propTraps
1772
1567
  );
1773
1568
  }
1774
- const defined = /* @__PURE__ */ Object.create(null);
1775
- let nonTargetKey = false;
1776
- let lastIndex = flattened.length - 1;
1777
- for (let i = lastIndex; i >= 0; i--) {
1778
- const source = flattened[i];
1779
- if (!source) {
1780
- i === lastIndex && lastIndex--;
1569
+ const i = Object.create(null);
1570
+ let r = false;
1571
+ let s = n.length - 1;
1572
+ for (let e = s; e >= 0; e--) {
1573
+ const t = n[e];
1574
+ if (!t) {
1575
+ e === s && s--;
1781
1576
  continue;
1782
1577
  }
1783
- const sourceKeys = Object.getOwnPropertyNames(source);
1784
- for (let j = sourceKeys.length - 1; j >= 0; j--) {
1785
- const key = sourceKeys[j];
1786
- if (key === "__proto__" || key === "constructor")
1787
- continue;
1788
- if (!defined[key]) {
1789
- nonTargetKey = nonTargetKey || i !== lastIndex;
1790
- const desc = Object.getOwnPropertyDescriptor(source, key);
1791
- defined[key] = desc.get ? {
1792
- enumerable: true,
1793
- configurable: true,
1794
- get: desc.get.bind(source)
1795
- } : desc;
1578
+ const o = Object.getOwnPropertyNames(t);
1579
+ for (let n = o.length - 1; n >= 0; n--) {
1580
+ const u = o[n];
1581
+ if (u === "__proto__" || u === "constructor") continue;
1582
+ if (!i[u]) {
1583
+ r = r || e !== s;
1584
+ const n = Object.getOwnPropertyDescriptor(t, u);
1585
+ i[u] = n.get ? { enumerable: true, configurable: true, get: n.get.bind(t) } : n;
1796
1586
  }
1797
1587
  }
1798
1588
  }
1799
- if (!nonTargetKey)
1800
- return flattened[lastIndex];
1801
- const target = {};
1802
- const definedKeys = Object.keys(defined);
1803
- for (let i = definedKeys.length - 1; i >= 0; i--) {
1804
- const key = definedKeys[i], desc = defined[key];
1805
- if (desc.get)
1806
- Object.defineProperty(target, key, desc);
1807
- else
1808
- target[key] = desc.value;
1589
+ if (!r) return n[s];
1590
+ const o = {};
1591
+ const u = Object.keys(i);
1592
+ for (let e = u.length - 1; e >= 0; e--) {
1593
+ const t = u[e],
1594
+ n = i[t];
1595
+ if (n.get) Object.defineProperty(o, t, n);
1596
+ else o[t] = n.value;
1809
1597
  }
1810
- target[$SOURCES] = flattened;
1811
- return target;
1598
+ o[$SOURCES] = n;
1599
+ return o;
1812
1600
  }
1813
- function omit(props, ...keys) {
1814
- const blocked = new Set(keys);
1815
- if (SUPPORTS_PROXY && $PROXY in props) {
1601
+ function omit(e, ...t) {
1602
+ const n = new Set(t);
1603
+ if (SUPPORTS_PROXY && $PROXY in e) {
1816
1604
  return new Proxy(
1817
1605
  {
1818
- get(property) {
1819
- return blocked.has(property) ? void 0 : props[property];
1606
+ get(t) {
1607
+ return n.has(t) ? undefined : e[t];
1820
1608
  },
1821
- has(property) {
1822
- return !blocked.has(property) && property in props;
1609
+ has(t) {
1610
+ return !n.has(t) && t in e;
1823
1611
  },
1824
1612
  keys() {
1825
- return Object.keys(props).filter((k) => !blocked.has(k));
1613
+ return Object.keys(e).filter(e => !n.has(e));
1826
1614
  }
1827
1615
  },
1828
1616
  propTraps
1829
1617
  );
1830
1618
  }
1831
- const result = {};
1832
- for (const propName of Object.getOwnPropertyNames(props)) {
1833
- if (!blocked.has(propName)) {
1834
- const desc = Object.getOwnPropertyDescriptor(props, propName);
1835
- !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable ? result[propName] = desc.value : Object.defineProperty(result, propName, desc);
1619
+ const i = {};
1620
+ for (const t of Object.getOwnPropertyNames(e)) {
1621
+ if (!n.has(t)) {
1622
+ const n = Object.getOwnPropertyDescriptor(e, t);
1623
+ !n.get && !n.set && n.enumerable && n.writable && n.configurable
1624
+ ? (i[t] = n.value)
1625
+ : Object.defineProperty(i, t, n);
1836
1626
  }
1837
1627
  }
1838
- return result;
1628
+ return i;
1839
1629
  }
1840
-
1841
- // src/map.ts
1842
- function mapArray(list, map, options) {
1843
- const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1630
+ function mapArray(e, t, n) {
1631
+ const i = typeof n?.keyed === "function" ? n.keyed : undefined;
1844
1632
  return createMemo(
1845
1633
  updateKeyedMap.bind({
1846
- X: createOwner(),
1847
- n: 0,
1848
- wa: list,
1849
- G: [],
1850
- O: map,
1851
- d: [],
1852
- a: [],
1853
- P: keyFn,
1854
- o: keyFn || options?.keyed === false ? [] : void 0,
1855
- p: map.length > 1 ? [] : void 0,
1856
- Y: options?.fallback
1634
+ Ie: createOwner(),
1635
+ ge: 0,
1636
+ ye: e,
1637
+ Ce: [],
1638
+ De: t,
1639
+ Pe: [],
1640
+ we: [],
1641
+ be: i,
1642
+ Ve: i || n?.keyed === false ? [] : undefined,
1643
+ Ue: t.length > 1 ? [] : undefined,
1644
+ me: n?.fallback
1857
1645
  })
1858
1646
  );
1859
1647
  }
1860
- var pureOptions = { pureWrite: true };
1648
+ const pureOptions = { pureWrite: true };
1861
1649
  function updateKeyedMap() {
1862
- const newItems = this.wa() || [], newLen = newItems.length;
1863
- newItems[$TRACK];
1864
- runWithOwner(this.X, () => {
1865
- let i, j, mapper = this.o ? () => {
1866
- this.o[j] = signal(newItems[j], pureOptions);
1867
- this.p && (this.p[j] = signal(j, pureOptions));
1868
- return this.O(
1869
- read.bind(null, this.o[j]),
1870
- this.p ? read.bind(null, this.p[j]) : void 0
1871
- );
1872
- } : this.p ? () => {
1873
- const item = newItems[j];
1874
- this.p[j] = signal(j, pureOptions);
1875
- return this.O(
1876
- () => item,
1877
- read.bind(null, this.p[j])
1878
- );
1879
- } : () => {
1880
- const item = newItems[j];
1881
- return this.O(() => item);
1882
- };
1883
- if (newLen === 0) {
1884
- if (this.n !== 0) {
1885
- this.X.dispose(false);
1886
- this.a = [];
1887
- this.G = [];
1888
- this.d = [];
1889
- this.n = 0;
1890
- this.o && (this.o = []);
1891
- this.p && (this.p = []);
1650
+ const e = this.ye() || [],
1651
+ t = e.length;
1652
+ e[$TRACK];
1653
+ runWithOwner(this.Ie, () => {
1654
+ let n,
1655
+ i,
1656
+ r = this.Ve
1657
+ ? () => {
1658
+ this.Ve[i] = signal(e[i], pureOptions);
1659
+ this.Ue && (this.Ue[i] = signal(i, pureOptions));
1660
+ return this.De(
1661
+ read.bind(null, this.Ve[i]),
1662
+ this.Ue ? read.bind(null, this.Ue[i]) : undefined
1663
+ );
1664
+ }
1665
+ : this.Ue
1666
+ ? () => {
1667
+ const t = e[i];
1668
+ this.Ue[i] = signal(i, pureOptions);
1669
+ return this.De(() => t, read.bind(null, this.Ue[i]));
1670
+ }
1671
+ : () => {
1672
+ const t = e[i];
1673
+ return this.De(() => t);
1674
+ };
1675
+ if (t === 0) {
1676
+ if (this.ge !== 0) {
1677
+ this.Ie.dispose(false);
1678
+ this.we = [];
1679
+ this.Ce = [];
1680
+ this.Pe = [];
1681
+ this.ge = 0;
1682
+ this.Ve && (this.Ve = []);
1683
+ this.Ue && (this.Ue = []);
1892
1684
  }
1893
- if (this.Y && !this.d[0]) {
1894
- this.d[0] = runWithOwner(
1895
- this.a[0] = createOwner(),
1896
- this.Y
1897
- );
1685
+ if (this.me && !this.Pe[0]) {
1686
+ this.Pe[0] = runWithOwner((this.we[0] = createOwner()), this.me);
1898
1687
  }
1899
- } else if (this.n === 0) {
1900
- if (this.a[0])
1901
- this.a[0].dispose();
1902
- this.d = new Array(newLen);
1903
- for (j = 0; j < newLen; j++) {
1904
- this.G[j] = newItems[j];
1905
- this.d[j] = runWithOwner(this.a[j] = createOwner(), mapper);
1688
+ } else if (this.ge === 0) {
1689
+ if (this.we[0]) this.we[0].dispose();
1690
+ this.Pe = new Array(t);
1691
+ for (i = 0; i < t; i++) {
1692
+ this.Ce[i] = e[i];
1693
+ this.Pe[i] = runWithOwner((this.we[i] = createOwner()), r);
1906
1694
  }
1907
- this.n = newLen;
1695
+ this.ge = t;
1908
1696
  } else {
1909
- let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.o ? new Array(newLen) : void 0, tempIndexes = this.p ? new Array(newLen) : void 0;
1910
- for (start = 0, end = Math.min(this.n, newLen); start < end && (this.G[start] === newItems[start] || this.o && compare(this.P, this.G[start], newItems[start])); start++) {
1911
- if (this.o)
1912
- setSignal(this.o[start], newItems[start]);
1697
+ let s,
1698
+ o,
1699
+ u,
1700
+ l,
1701
+ c,
1702
+ a,
1703
+ f,
1704
+ E = new Array(t),
1705
+ d = new Array(t),
1706
+ T = this.Ve ? new Array(t) : undefined,
1707
+ R = this.Ue ? new Array(t) : undefined;
1708
+ for (
1709
+ s = 0, o = Math.min(this.ge, t);
1710
+ s < o && (this.Ce[s] === e[s] || (this.Ve && compare(this.be, this.Ce[s], e[s])));
1711
+ s++
1712
+ ) {
1713
+ if (this.Ve) setSignal(this.Ve[s], e[s]);
1913
1714
  }
1914
- for (end = this.n - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.G[end] === newItems[newEnd] || this.o && compare(this.P, this.G[end], newItems[newEnd])); end--, newEnd--) {
1915
- temp[newEnd] = this.d[end];
1916
- tempNodes[newEnd] = this.a[end];
1917
- tempRows && (tempRows[newEnd] = this.o[end]);
1918
- tempIndexes && (tempIndexes[newEnd] = this.p[end]);
1715
+ for (
1716
+ o = this.ge - 1, u = t - 1;
1717
+ o >= s &&
1718
+ u >= s &&
1719
+ (this.Ce[o] === e[u] || (this.Ve && compare(this.be, this.Ce[o], e[u])));
1720
+ o--, u--
1721
+ ) {
1722
+ E[u] = this.Pe[o];
1723
+ d[u] = this.we[o];
1724
+ T && (T[u] = this.Ve[o]);
1725
+ R && (R[u] = this.Ue[o]);
1919
1726
  }
1920
- newIndices = /* @__PURE__ */ new Map();
1921
- newIndicesNext = new Array(newEnd + 1);
1922
- for (j = newEnd; j >= start; j--) {
1923
- item = newItems[j];
1924
- key = this.P ? this.P(item) : item;
1925
- i = newIndices.get(key);
1926
- newIndicesNext[j] = i === void 0 ? -1 : i;
1927
- newIndices.set(key, j);
1727
+ a = new Map();
1728
+ f = new Array(u + 1);
1729
+ for (i = u; i >= s; i--) {
1730
+ l = e[i];
1731
+ c = this.be ? this.be(l) : l;
1732
+ n = a.get(c);
1733
+ f[i] = n === undefined ? -1 : n;
1734
+ a.set(c, i);
1928
1735
  }
1929
- for (i = start; i <= end; i++) {
1930
- item = this.G[i];
1931
- key = this.P ? this.P(item) : item;
1932
- j = newIndices.get(key);
1933
- if (j !== void 0 && j !== -1) {
1934
- temp[j] = this.d[i];
1935
- tempNodes[j] = this.a[i];
1936
- tempRows && (tempRows[j] = this.o[i]);
1937
- tempIndexes && (tempIndexes[j] = this.p[i]);
1938
- j = newIndicesNext[j];
1939
- newIndices.set(key, j);
1940
- } else
1941
- this.a[i].dispose();
1736
+ for (n = s; n <= o; n++) {
1737
+ l = this.Ce[n];
1738
+ c = this.be ? this.be(l) : l;
1739
+ i = a.get(c);
1740
+ if (i !== undefined && i !== -1) {
1741
+ E[i] = this.Pe[n];
1742
+ d[i] = this.we[n];
1743
+ T && (T[i] = this.Ve[n]);
1744
+ R && (R[i] = this.Ue[n]);
1745
+ i = f[i];
1746
+ a.set(c, i);
1747
+ } else this.we[n].dispose();
1942
1748
  }
1943
- for (j = start; j < newLen; j++) {
1944
- if (j in temp) {
1945
- this.d[j] = temp[j];
1946
- this.a[j] = tempNodes[j];
1947
- if (tempRows) {
1948
- this.o[j] = tempRows[j];
1949
- setSignal(this.o[j], newItems[j]);
1749
+ for (i = s; i < t; i++) {
1750
+ if (i in E) {
1751
+ this.Pe[i] = E[i];
1752
+ this.we[i] = d[i];
1753
+ if (T) {
1754
+ this.Ve[i] = T[i];
1755
+ setSignal(this.Ve[i], e[i]);
1950
1756
  }
1951
- if (tempIndexes) {
1952
- this.p[j] = tempIndexes[j];
1953
- setSignal(this.p[j], j);
1757
+ if (R) {
1758
+ this.Ue[i] = R[i];
1759
+ setSignal(this.Ue[i], i);
1954
1760
  }
1955
1761
  } else {
1956
- this.d[j] = runWithOwner(this.a[j] = createOwner(), mapper);
1762
+ this.Pe[i] = runWithOwner((this.we[i] = createOwner()), r);
1957
1763
  }
1958
1764
  }
1959
- this.d = this.d.slice(0, this.n = newLen);
1960
- this.G = newItems.slice(0);
1765
+ this.Pe = this.Pe.slice(0, (this.ge = t));
1766
+ this.Ce = e.slice(0);
1961
1767
  }
1962
1768
  });
1963
- return this.d;
1769
+ return this.Pe;
1964
1770
  }
1965
- function repeat(count, map, options) {
1771
+ function repeat(e, t, n) {
1966
1772
  return updateRepeat.bind({
1967
- X: createOwner(),
1968
- n: 0,
1969
- y: 0,
1970
- xa: count,
1971
- O: map,
1972
- a: [],
1973
- d: [],
1974
- ya: options?.from,
1975
- Y: options?.fallback
1773
+ Ie: createOwner(),
1774
+ ge: 0,
1775
+ ke: 0,
1776
+ ve: e,
1777
+ De: t,
1778
+ we: [],
1779
+ Pe: [],
1780
+ xe: n?.from,
1781
+ me: n?.fallback
1976
1782
  });
1977
1783
  }
1978
1784
  function updateRepeat() {
1979
- const newLen = this.xa();
1980
- const from = this.ya?.() || 0;
1981
- runWithOwner(this.X, () => {
1982
- if (newLen === 0) {
1983
- if (this.n !== 0) {
1984
- this.X.dispose(false);
1985
- this.a = [];
1986
- this.d = [];
1987
- this.n = 0;
1785
+ const e = this.ve();
1786
+ const t = this.xe?.() || 0;
1787
+ runWithOwner(this.Ie, () => {
1788
+ if (e === 0) {
1789
+ if (this.ge !== 0) {
1790
+ this.Ie.dispose(false);
1791
+ this.we = [];
1792
+ this.Pe = [];
1793
+ this.ge = 0;
1988
1794
  }
1989
- if (this.Y && !this.d[0]) {
1990
- this.d[0] = runWithOwner(
1991
- this.a[0] = createOwner(),
1992
- this.Y
1993
- );
1795
+ if (this.me && !this.Pe[0]) {
1796
+ this.Pe[0] = runWithOwner((this.we[0] = createOwner()), this.me);
1994
1797
  }
1995
1798
  return;
1996
1799
  }
1997
- const to = from + newLen;
1998
- const prevTo = this.y + this.n;
1999
- if (this.n === 0 && this.a[0])
2000
- this.a[0].dispose();
2001
- for (let i = to; i < prevTo; i++)
2002
- this.a[i - this.y].dispose();
2003
- if (this.y < from) {
2004
- let i = this.y;
2005
- while (i < from && i < this.n)
2006
- this.a[i++].dispose();
2007
- this.a.splice(0, from - this.y);
2008
- this.d.splice(0, from - this.y);
2009
- } else if (this.y > from) {
2010
- let i = prevTo - this.y - 1;
2011
- let difference = this.y - from;
2012
- this.a.length = this.d.length = newLen;
2013
- while (i >= difference) {
2014
- this.a[i] = this.a[i - difference];
2015
- this.d[i] = this.d[i - difference];
2016
- i--;
1800
+ const n = t + e;
1801
+ const i = this.ke + this.ge;
1802
+ if (this.ge === 0 && this.we[0]) this.we[0].dispose();
1803
+ for (let e = n; e < i; e++) this.we[e - this.ke].dispose();
1804
+ if (this.ke < t) {
1805
+ let e = this.ke;
1806
+ while (e < t && e < this.ge) this.we[e++].dispose();
1807
+ this.we.splice(0, t - this.ke);
1808
+ this.Pe.splice(0, t - this.ke);
1809
+ } else if (this.ke > t) {
1810
+ let n = i - this.ke - 1;
1811
+ let r = this.ke - t;
1812
+ this.we.length = this.Pe.length = e;
1813
+ while (n >= r) {
1814
+ this.we[n] = this.we[n - r];
1815
+ this.Pe[n] = this.Pe[n - r];
1816
+ n--;
2017
1817
  }
2018
- for (let i2 = 0; i2 < difference; i2++) {
2019
- this.d[i2] = runWithOwner(
2020
- this.a[i2] = createOwner(),
2021
- () => this.O(i2 + from)
2022
- );
1818
+ for (let e = 0; e < r; e++) {
1819
+ this.Pe[e] = runWithOwner((this.we[e] = createOwner()), () => this.De(e + t));
2023
1820
  }
2024
1821
  }
2025
- for (let i = prevTo; i < to; i++) {
2026
- this.d[i - from] = runWithOwner(
2027
- this.a[i - from] = createOwner(),
2028
- () => this.O(i)
2029
- );
1822
+ for (let e = i; e < n; e++) {
1823
+ this.Pe[e - t] = runWithOwner((this.we[e - t] = createOwner()), () => this.De(e));
2030
1824
  }
2031
- this.d = this.d.slice(0, newLen);
2032
- this.y = from;
2033
- this.n = newLen;
1825
+ this.Pe = this.Pe.slice(0, e);
1826
+ this.ke = t;
1827
+ this.ge = e;
2034
1828
  });
2035
- return this.d;
2036
- }
2037
- function compare(key, a, b) {
2038
- return key ? key(a) === key(b) : true;
2039
- }
2040
-
2041
- // src/boundaries.ts
2042
- function boundaryComputed(fn, propagationMask) {
2043
- const node = computed(fn, void 0, {
2044
- ka: {
2045
- ma() {
2046
- let flags = this.f;
2047
- this.f &= ~this.Z;
2048
- if (this.Z & 1 /* Pending */ && !(this.f & 4 /* Uninitialized */)) {
2049
- flags &= ~1 /* Pending */;
1829
+ return this.Pe;
1830
+ }
1831
+ function compare(e, t, n) {
1832
+ return e ? e(t) === e(n) : true;
1833
+ }
1834
+ function boundaryComputed(e, t) {
1835
+ const n = computed(e, undefined, {
1836
+ _e: {
1837
+ le() {
1838
+ let e = this.J;
1839
+ this.J &= ~this.Ge;
1840
+ if (this.Ge & STATUS_PENDING && !(this.J & STATUS_UNINITIALIZED)) {
1841
+ e &= ~STATUS_PENDING;
2050
1842
  }
2051
- this.i.notify(this, this.Z, flags);
1843
+ this.Re.notify(this, this.Ge, e);
2052
1844
  },
2053
- Z: propagationMask
1845
+ Ge: t
2054
1846
  }
2055
1847
  });
2056
- node.Z = propagationMask;
2057
- return node;
2058
- }
2059
- function createBoundChildren(owner, fn, queue, mask) {
2060
- const parentQueue = owner.i;
2061
- parentQueue.addChild(owner.i = queue);
2062
- onCleanup(() => parentQueue.removeChild(owner.i));
2063
- return runWithOwner(owner, () => {
2064
- const c = computed(fn);
2065
- return boundaryComputed(() => staleValues(() => flatten(read(c))), mask);
1848
+ n.Ge = t;
1849
+ return n;
1850
+ }
1851
+ function createBoundChildren(e, t, n, i) {
1852
+ const r = e.Re;
1853
+ r.addChild((e.Re = n));
1854
+ onCleanup(() => r.removeChild(e.Re));
1855
+ return runWithOwner(e, () => {
1856
+ const e = computed(t);
1857
+ return boundaryComputed(() => staleValues(() => flatten(read(e))), i);
2066
1858
  });
2067
1859
  }
2068
- var ConditionalQueue = class extends Queue {
2069
- u;
2070
- ha = /* @__PURE__ */ new Set();
2071
- h = /* @__PURE__ */ new Set();
2072
- constructor(disabled) {
1860
+ class ConditionalQueue extends Queue {
1861
+ He;
1862
+ Qe = new Set();
1863
+ $ = new Set();
1864
+ constructor(e) {
2073
1865
  super();
2074
- this.u = disabled;
2075
- }
2076
- run(type) {
2077
- if (!type || read(this.u))
2078
- return;
2079
- return super.run(type);
2080
- }
2081
- notify(node, type, flags) {
2082
- if (read(this.u)) {
2083
- if (type & 1 /* Pending */) {
2084
- if (flags & 1 /* Pending */) {
2085
- this.h.add(node);
2086
- type &= ~1 /* Pending */;
2087
- } else if (this.h.delete(node))
2088
- type &= ~1 /* Pending */;
1866
+ this.He = e;
1867
+ }
1868
+ run(e) {
1869
+ if (!e || read(this.He)) return;
1870
+ return super.run(e);
1871
+ }
1872
+ notify(e, t, n) {
1873
+ if (read(this.He)) {
1874
+ if (t & STATUS_PENDING) {
1875
+ if (n & STATUS_PENDING) {
1876
+ this.$.add(e);
1877
+ t &= ~STATUS_PENDING;
1878
+ } else if (this.$.delete(e)) t &= ~STATUS_PENDING;
2089
1879
  }
2090
- if (type & 2 /* Error */) {
2091
- if (flags & 2 /* Error */) {
2092
- this.ha.add(node);
2093
- type &= ~2 /* Error */;
2094
- } else if (this.ha.delete(node))
2095
- type &= ~2 /* Error */;
1880
+ if (t & STATUS_ERROR) {
1881
+ if (n & STATUS_ERROR) {
1882
+ this.Qe.add(e);
1883
+ t &= ~STATUS_ERROR;
1884
+ } else if (this.Qe.delete(e)) t &= ~STATUS_ERROR;
2096
1885
  }
2097
1886
  }
2098
- return type ? super.notify(node, type, flags) : true;
1887
+ return t ? super.notify(e, t, n) : true;
2099
1888
  }
2100
- };
2101
- var CollectionQueue = class extends Queue {
2102
- _;
2103
- a = /* @__PURE__ */ new Set();
2104
- u = signal(false, { pureWrite: true });
2105
- ra = false;
2106
- constructor(type) {
1889
+ }
1890
+ class CollectionQueue extends Queue {
1891
+ $e;
1892
+ we = new Set();
1893
+ He = signal(false, { pureWrite: true });
1894
+ Le = false;
1895
+ constructor(e) {
2107
1896
  super();
2108
- this._ = type;
2109
- }
2110
- run(type) {
2111
- if (!type || read(this.u))
2112
- return;
2113
- return super.run(type);
2114
- }
2115
- notify(node, type, flags) {
2116
- if (!(type & this._) || this._ & 1 /* Pending */ && this.ra)
2117
- return super.notify(node, type, flags);
2118
- if (flags & this._) {
2119
- this.a.add(node);
2120
- if (this.a.size === 1)
2121
- setSignal(this.u, true);
2122
- } else if (this.a.size > 0) {
2123
- this.a.delete(node);
2124
- if (this.a.size === 0)
2125
- setSignal(this.u, false);
2126
- }
2127
- type &= ~this._;
2128
- return type ? super.notify(node, type, flags) : true;
2129
- }
2130
- };
2131
- function createBoundary(fn, condition) {
2132
- const owner = createOwner();
2133
- const queue = new ConditionalQueue(computed(() => condition() === "hidden" /* HIDDEN */));
2134
- const tree = createBoundChildren(owner, fn, queue, 0);
1897
+ this.$e = e;
1898
+ }
1899
+ run(e) {
1900
+ if (!e || read(this.He)) return;
1901
+ return super.run(e);
1902
+ }
1903
+ notify(e, t, n) {
1904
+ if (!(t & this.$e) || (this.$e & STATUS_PENDING && this.Le)) return super.notify(e, t, n);
1905
+ if (n & this.$e) {
1906
+ this.we.add(e);
1907
+ if (this.we.size === 1) setSignal(this.He, true);
1908
+ } else if (this.we.size > 0) {
1909
+ this.we.delete(e);
1910
+ if (this.we.size === 0) setSignal(this.He, false);
1911
+ }
1912
+ t &= ~this.$e;
1913
+ return t ? super.notify(e, t, n) : true;
1914
+ }
1915
+ }
1916
+ var BoundaryMode;
1917
+ (function (e) {
1918
+ e["VISIBLE"] = "visible";
1919
+ e["HIDDEN"] = "hidden";
1920
+ })(BoundaryMode || (BoundaryMode = {}));
1921
+ function createBoundary(e, t) {
1922
+ const n = createOwner();
1923
+ const i = new ConditionalQueue(computed(() => t() === BoundaryMode.HIDDEN));
1924
+ const r = createBoundChildren(n, e, i, 0);
2135
1925
  computed(() => {
2136
- const disabled = read(queue.u);
2137
- tree.Z = disabled ? 2 /* Error */ | 1 /* Pending */ : 0;
2138
- if (!disabled) {
2139
- queue.h.forEach(
2140
- (node) => queue.notify(node, 1 /* Pending */, 1 /* Pending */)
2141
- );
2142
- queue.ha.forEach((node) => queue.notify(node, 2 /* Error */, 2 /* Error */));
2143
- queue.h.clear();
2144
- queue.ha.clear();
1926
+ const e = read(i.He);
1927
+ r.Ge = e ? STATUS_ERROR | STATUS_PENDING : 0;
1928
+ if (!e) {
1929
+ i.$.forEach(e => i.notify(e, STATUS_PENDING, STATUS_PENDING));
1930
+ i.Qe.forEach(e => i.notify(e, STATUS_ERROR, STATUS_ERROR));
1931
+ i.$.clear();
1932
+ i.Qe.clear();
2145
1933
  }
2146
1934
  });
2147
- return () => read(queue.u) ? void 0 : read(tree);
2148
- }
2149
- function createCollectionBoundary(type, fn, fallback) {
2150
- const owner = createOwner();
2151
- const queue = new CollectionQueue(type);
2152
- const tree = createBoundChildren(owner, fn, queue, type);
2153
- const decision = computed(() => {
2154
- if (!read(queue.u)) {
2155
- const resolved = read(tree);
2156
- if (!untrack(() => read(queue.u)))
2157
- queue.ra = true;
2158
- return resolved;
2159
- }
2160
- return fallback(queue);
1935
+ return () => (read(i.He) ? undefined : read(r));
1936
+ }
1937
+ function createCollectionBoundary(e, t, n) {
1938
+ const i = createOwner();
1939
+ const r = new CollectionQueue(e);
1940
+ const s = createBoundChildren(i, t, r, e);
1941
+ const o = computed(() => {
1942
+ if (!read(r.He)) {
1943
+ const e = read(s);
1944
+ if (!untrack(() => read(r.He))) r.Le = true;
1945
+ return e;
1946
+ }
1947
+ return n(r);
2161
1948
  });
2162
- return read.bind(null, decision);
2163
- }
2164
- function createLoadBoundary(fn, fallback) {
2165
- return createCollectionBoundary(1 /* Pending */, fn, () => fallback());
2166
- }
2167
- function createErrorBoundary(fn, fallback) {
2168
- return createCollectionBoundary(2 /* Error */, fn, (queue) => {
2169
- let node = queue.a.values().next().value;
2170
- return fallback(node.B, () => {
2171
- for (let node2 of queue.a) {
2172
- recompute(node2, true);
2173
- }
1949
+ return read.bind(null, o);
1950
+ }
1951
+ function createLoadBoundary(e, t) {
1952
+ return createCollectionBoundary(STATUS_PENDING, e, () => t());
1953
+ }
1954
+ function collectErrorSources(e, t) {
1955
+ let n = true;
1956
+ let i = e.D;
1957
+ while (i !== null) {
1958
+ const e = i.V;
1959
+ if (e.D && e.J & STATUS_ERROR) {
1960
+ n = false;
1961
+ collectErrorSources(e, t);
1962
+ }
1963
+ i = i.P;
1964
+ }
1965
+ n && t.push(e);
1966
+ }
1967
+ function createErrorBoundary(e, t) {
1968
+ return createCollectionBoundary(STATUS_ERROR, e, e => {
1969
+ let n = e.we.values().next().value;
1970
+ return t(n.Y, () => {
1971
+ const t = [];
1972
+ for (const n of e.we) collectErrorSources(n, t);
1973
+ for (const e of t) recompute(e);
1974
+ schedule();
2174
1975
  });
2175
1976
  });
2176
1977
  }
2177
- function flatten(children, options) {
2178
- if (typeof children === "function" && !children.length) {
2179
- if (options?.doNotUnwrap)
2180
- return children;
1978
+ function flatten(e, t) {
1979
+ if (typeof e === "function" && !e.length) {
1980
+ if (t?.doNotUnwrap) return e;
2181
1981
  do {
2182
- children = children();
2183
- } while (typeof children === "function" && !children.length);
1982
+ e = e();
1983
+ } while (typeof e === "function" && !e.length);
2184
1984
  }
2185
- if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
2186
- return;
2187
- if (Array.isArray(children)) {
2188
- let results = [];
2189
- if (flattenArray(children, results, options)) {
1985
+ if (t?.skipNonRendered && (e == null || e === true || e === false || e === "")) return;
1986
+ if (Array.isArray(e)) {
1987
+ let n = [];
1988
+ if (flattenArray(e, n, t)) {
2190
1989
  return () => {
2191
- let nested = [];
2192
- flattenArray(results, nested, { ...options, doNotUnwrap: false });
2193
- return nested;
1990
+ let e = [];
1991
+ flattenArray(n, e, { ...t, doNotUnwrap: false });
1992
+ return e;
2194
1993
  };
2195
1994
  }
2196
- return results;
1995
+ return n;
2197
1996
  }
2198
- return children;
1997
+ return e;
2199
1998
  }
2200
- function flattenArray(children, results = [], options) {
2201
- let notReady = null;
2202
- let needsUnwrap = false;
2203
- for (let i = 0; i < children.length; i++) {
1999
+ function flattenArray(e, t = [], n) {
2000
+ let i = null;
2001
+ let r = false;
2002
+ for (let s = 0; s < e.length; s++) {
2204
2003
  try {
2205
- let child = children[i];
2206
- if (typeof child === "function" && !child.length) {
2207
- if (options?.doNotUnwrap) {
2208
- results.push(child);
2209
- needsUnwrap = true;
2004
+ let i = e[s];
2005
+ if (typeof i === "function" && !i.length) {
2006
+ if (n?.doNotUnwrap) {
2007
+ t.push(i);
2008
+ r = true;
2210
2009
  continue;
2211
2010
  }
2212
2011
  do {
2213
- child = child();
2214
- } while (typeof child === "function" && !child.length);
2012
+ i = i();
2013
+ } while (typeof i === "function" && !i.length);
2215
2014
  }
2216
- if (Array.isArray(child)) {
2217
- needsUnwrap = flattenArray(child, results, options);
2218
- } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
2219
- } else
2220
- results.push(child);
2015
+ if (Array.isArray(i)) {
2016
+ r = flattenArray(i, t, n);
2017
+ } else if (n?.skipNonRendered && (i == null || i === true || i === false || i === "")) {
2018
+ } else t.push(i);
2221
2019
  } catch (e) {
2222
- if (!(e instanceof NotReadyError))
2223
- throw e;
2224
- notReady = e;
2225
- }
2226
- }
2227
- if (notReady)
2228
- throw notReady;
2229
- return needsUnwrap;
2230
- }
2231
-
2232
- export { $PROXY, $TARGET, $TRACK, ContextNotFoundError, NoOwnerError, NotReadyError, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createLoadBoundary, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, createTrackedEffect, deep, flatten, flush, getContext, getNextChildId, getObserver, getOwner, isEqual, isPending, isWrappable, mapArray, merge, omit, onCleanup, onSettled, pending, reconcile, repeat, resolve, runWithOwner, setContext, snapshot, untrack };
2020
+ if (!(e instanceof NotReadyError)) throw e;
2021
+ i = e;
2022
+ }
2023
+ }
2024
+ if (i) throw i;
2025
+ return r;
2026
+ }
2027
+ export {
2028
+ $PROXY,
2029
+ $TARGET,
2030
+ $TRACK,
2031
+ ContextNotFoundError,
2032
+ NoOwnerError,
2033
+ NotReadyError,
2034
+ SUPPORTS_PROXY,
2035
+ createAsync,
2036
+ createBoundary,
2037
+ createContext,
2038
+ createEffect,
2039
+ createErrorBoundary,
2040
+ createLoadBoundary,
2041
+ createMemo,
2042
+ createOptimistic,
2043
+ createOptimisticStore,
2044
+ createProjection,
2045
+ createReaction,
2046
+ createRenderEffect,
2047
+ createRoot,
2048
+ createSignal,
2049
+ createStore,
2050
+ createTrackedEffect,
2051
+ deep,
2052
+ flatten,
2053
+ flush,
2054
+ getContext,
2055
+ getNextChildId,
2056
+ getObserver,
2057
+ getOwner,
2058
+ isEqual,
2059
+ isPending,
2060
+ isWrappable,
2061
+ mapArray,
2062
+ merge,
2063
+ omit,
2064
+ onCleanup,
2065
+ onSettled,
2066
+ pending,
2067
+ reconcile,
2068
+ repeat,
2069
+ resolve,
2070
+ runWithOwner,
2071
+ setContext,
2072
+ snapshot,
2073
+ untrack
2074
+ };