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