@solidjs/signals 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.cjs ADDED
@@ -0,0 +1,1452 @@
1
+ 'use strict';
2
+
3
+ // src/core/error.ts
4
+ var NotReadyError = class extends Error {
5
+ };
6
+ var NoOwnerError = class extends Error {
7
+ constructor() {
8
+ super(
9
+ ""
10
+ );
11
+ }
12
+ };
13
+ var ContextNotFoundError = class extends Error {
14
+ constructor() {
15
+ super(
16
+ ""
17
+ );
18
+ }
19
+ };
20
+
21
+ // src/utils.ts
22
+ function isUndefined(value) {
23
+ return typeof value === "undefined";
24
+ }
25
+
26
+ // src/core/constants.ts
27
+ var STATE_CLEAN = 0;
28
+ var STATE_CHECK = 1;
29
+ var STATE_DIRTY = 2;
30
+ var STATE_DISPOSED = 3;
31
+ var EFFECT_PURE = 0;
32
+ var EFFECT_RENDER = 1;
33
+ var EFFECT_USER = 2;
34
+ var SUPPORTS_PROXY = typeof Proxy === "function";
35
+
36
+ // src/core/owner.ts
37
+ var currentOwner = null;
38
+ var defaultContext = {};
39
+ function getOwner() {
40
+ return currentOwner;
41
+ }
42
+ function setOwner(owner) {
43
+ const out = currentOwner;
44
+ currentOwner = owner;
45
+ return out;
46
+ }
47
+ var Owner = class {
48
+ // We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
49
+ // However, the children are actually added in reverse creation order
50
+ // See comment at the top of the file for an example of the _nextSibling traversal
51
+ q = null;
52
+ l = null;
53
+ o = null;
54
+ a = STATE_CLEAN;
55
+ g = null;
56
+ m = defaultContext;
57
+ h = null;
58
+ e = null;
59
+ constructor(signal = false) {
60
+ if (currentOwner && !signal)
61
+ currentOwner.append(this);
62
+ }
63
+ append(child) {
64
+ child.q = this;
65
+ child.o = this;
66
+ if (this.l)
67
+ this.l.o = child;
68
+ child.l = this.l;
69
+ this.l = child;
70
+ if (child.m !== this.m) {
71
+ child.m = { ...this.m, ...child.m };
72
+ }
73
+ if (this.h) {
74
+ child.h = !child.h ? this.h : [...child.h, ...this.h];
75
+ }
76
+ if (this.e)
77
+ child.e = this.e;
78
+ }
79
+ dispose(self = true) {
80
+ if (this.a === STATE_DISPOSED)
81
+ return;
82
+ let head = self ? this.o || this.q : this, current = this.l, next = null;
83
+ while (current && current.q === this) {
84
+ current.dispose(true);
85
+ current.w();
86
+ next = current.l;
87
+ current.l = null;
88
+ current = next;
89
+ }
90
+ if (self)
91
+ this.w();
92
+ if (current)
93
+ current.o = !self ? this : this.o;
94
+ if (head)
95
+ head.l = current;
96
+ }
97
+ w() {
98
+ if (this.o)
99
+ this.o.l = null;
100
+ this.q = null;
101
+ this.o = null;
102
+ this.m = defaultContext;
103
+ this.h = null;
104
+ this.a = STATE_DISPOSED;
105
+ this.emptyDisposal();
106
+ }
107
+ emptyDisposal() {
108
+ if (!this.g)
109
+ return;
110
+ if (Array.isArray(this.g)) {
111
+ for (let i = 0; i < this.g.length; i++) {
112
+ const callable = this.g[i];
113
+ callable.call(callable);
114
+ }
115
+ } else {
116
+ this.g.call(this.g);
117
+ }
118
+ this.g = null;
119
+ }
120
+ handleError(error) {
121
+ if (!this.h)
122
+ throw error;
123
+ let i = 0, len = this.h.length;
124
+ for (i = 0; i < len; i++) {
125
+ try {
126
+ this.h[i](error);
127
+ break;
128
+ } catch (e) {
129
+ error = e;
130
+ }
131
+ }
132
+ if (i === len)
133
+ throw error;
134
+ }
135
+ };
136
+ function createContext(defaultValue, description) {
137
+ return { id: Symbol(description), defaultValue };
138
+ }
139
+ function getContext(context, owner = currentOwner) {
140
+ if (!owner) {
141
+ throw new NoOwnerError();
142
+ }
143
+ const value = hasContext(context, owner) ? owner.m[context.id] : context.defaultValue;
144
+ if (isUndefined(value)) {
145
+ throw new ContextNotFoundError();
146
+ }
147
+ return value;
148
+ }
149
+ function setContext(context, value, owner = currentOwner) {
150
+ if (!owner) {
151
+ throw new NoOwnerError();
152
+ }
153
+ owner.m = {
154
+ ...owner.m,
155
+ [context.id]: isUndefined(value) ? context.defaultValue : value
156
+ };
157
+ }
158
+ function hasContext(context, owner = currentOwner) {
159
+ return !isUndefined(owner == null ? void 0 : owner.m[context.id]);
160
+ }
161
+ function onCleanup(disposable) {
162
+ if (!currentOwner)
163
+ return;
164
+ const node = currentOwner;
165
+ if (!node.g) {
166
+ node.g = disposable;
167
+ } else if (Array.isArray(node.g)) {
168
+ node.g.push(disposable);
169
+ } else {
170
+ node.g = [node.g, disposable];
171
+ }
172
+ }
173
+
174
+ // src/core/flags.ts
175
+ var ERROR_OFFSET = 0;
176
+ var ERROR_BIT = 1 << ERROR_OFFSET;
177
+ var LOADING_OFFSET = 1;
178
+ var LOADING_BIT = 1 << LOADING_OFFSET;
179
+ var DEFAULT_FLAGS = ERROR_BIT;
180
+
181
+ // src/core/core.ts
182
+ var currentObserver = null;
183
+ var currentMask = DEFAULT_FLAGS;
184
+ var newSources = null;
185
+ var newSourcesIndex = 0;
186
+ var newFlags = 0;
187
+ var clock = 0;
188
+ var syncResolve = false;
189
+ var updateCheck = null;
190
+ function getObserver() {
191
+ return currentObserver;
192
+ }
193
+ function incrementClock() {
194
+ clock++;
195
+ }
196
+ var UNCHANGED = Symbol(0);
197
+ var Computation = class extends Owner {
198
+ b = null;
199
+ c = null;
200
+ d;
201
+ C;
202
+ // Used in __DEV__ mode, hopefully removed in production
203
+ U;
204
+ // Using false is an optimization as an alternative to _equals: () => false
205
+ // which could enable more efficient DIRTY notification
206
+ D = isEqual;
207
+ N;
208
+ /** Whether the computation is an error or has ancestors that are unresolved */
209
+ i = 0;
210
+ /** Which flags raised by sources are handled, vs. being passed through. */
211
+ A = DEFAULT_FLAGS;
212
+ E = null;
213
+ F = null;
214
+ G = -1;
215
+ constructor(initialValue, compute2, options) {
216
+ super(compute2 === null);
217
+ this.C = compute2;
218
+ this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
219
+ this.d = initialValue;
220
+ if ((options == null ? void 0 : options.equals) !== void 0)
221
+ this.D = options.equals;
222
+ if (options == null ? void 0 : options.unobserved)
223
+ this.N = options == null ? void 0 : options.unobserved;
224
+ }
225
+ O() {
226
+ if (this.C)
227
+ this.r();
228
+ if (!this.b || this.b.length)
229
+ track(this);
230
+ newFlags |= this.i & ~currentMask;
231
+ if (this.i & ERROR_BIT) {
232
+ throw this.d;
233
+ } else {
234
+ return this.d;
235
+ }
236
+ }
237
+ /**
238
+ * Return the current value of this computation
239
+ * Automatically re-executes the surrounding computation when the value changes
240
+ */
241
+ read() {
242
+ return this.O();
243
+ }
244
+ /**
245
+ * Return the current value of this computation
246
+ * Automatically re-executes the surrounding computation when the value changes
247
+ *
248
+ * If the computation has any unresolved ancestors, this function waits for the value to resolve
249
+ * before continuing
250
+ */
251
+ wait() {
252
+ if (!syncResolve && this.loading()) {
253
+ throw new NotReadyError();
254
+ }
255
+ return this.O();
256
+ }
257
+ /**
258
+ * Return true if the computation is the value is dependent on an unresolved promise
259
+ * Triggers re-execution of the computation when the loading state changes
260
+ *
261
+ * This is useful especially when effects want to re-execute when a computation's
262
+ * loading state changes
263
+ */
264
+ loading() {
265
+ if (this.F === null) {
266
+ this.F = loadingState(this);
267
+ }
268
+ return this.F.read();
269
+ }
270
+ /**
271
+ * Return true if the computation is the computation threw an error
272
+ * Triggers re-execution of the computation when the error state changes
273
+ */
274
+ error() {
275
+ if (this.E === null) {
276
+ this.E = errorState(this);
277
+ }
278
+ return this.E.read();
279
+ }
280
+ /** Update the computation with a new value. */
281
+ write(value, flags = 0, raw = false) {
282
+ const newValue = !raw && typeof value === "function" ? value(this.d) : value;
283
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.D === false || !this.D(this.d, newValue));
284
+ if (valueChanged)
285
+ this.d = newValue;
286
+ const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
287
+ this.i = flags;
288
+ this.G = clock + 1;
289
+ if (this.c) {
290
+ for (let i = 0; i < this.c.length; i++) {
291
+ if (valueChanged) {
292
+ this.c[i].s(STATE_DIRTY);
293
+ } else if (changedFlagsMask) {
294
+ this.c[i].P(changedFlagsMask, changedFlags);
295
+ }
296
+ }
297
+ }
298
+ return this.d;
299
+ }
300
+ /**
301
+ * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
302
+ */
303
+ s(state) {
304
+ if (this.a >= state)
305
+ return;
306
+ this.a = state;
307
+ if (this.c) {
308
+ for (let i = 0; i < this.c.length; i++) {
309
+ this.c[i].s(STATE_CHECK);
310
+ }
311
+ }
312
+ }
313
+ /**
314
+ * Notify the computation that one of its sources has changed flags.
315
+ *
316
+ * @param mask A bitmask for which flag(s) were changed.
317
+ * @param newFlags The source's new flags, masked to just the changed ones.
318
+ */
319
+ P(mask, newFlags2) {
320
+ if (this.a >= STATE_DIRTY)
321
+ return;
322
+ if (mask & this.A) {
323
+ this.s(STATE_DIRTY);
324
+ return;
325
+ }
326
+ if (this.a >= STATE_CHECK)
327
+ return;
328
+ const prevFlags = this.i & mask;
329
+ const deltaFlags = prevFlags ^ newFlags2;
330
+ if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
331
+ this.s(STATE_CHECK);
332
+ } else {
333
+ this.i ^= deltaFlags;
334
+ if (this.c) {
335
+ for (let i = 0; i < this.c.length; i++) {
336
+ this.c[i].P(mask, newFlags2);
337
+ }
338
+ }
339
+ }
340
+ }
341
+ Q(error) {
342
+ this.write(error, this.i | ERROR_BIT);
343
+ }
344
+ /**
345
+ * This is the core part of the reactivity system, which makes sure that the values are updated
346
+ * before they are read. We've also adapted it to return the loading state of the computation,
347
+ * so that we can propagate that to the computation's observers.
348
+ *
349
+ * This function will ensure that the value and states we read from the computation are up to date
350
+ */
351
+ r() {
352
+ if (this.a === STATE_DISPOSED) {
353
+ throw new Error("Tried to read a disposed computation");
354
+ }
355
+ if (this.a === STATE_CLEAN) {
356
+ return;
357
+ }
358
+ let observerFlags = 0;
359
+ if (this.a === STATE_CHECK) {
360
+ for (let i = 0; i < this.b.length; i++) {
361
+ this.b[i].r();
362
+ observerFlags |= this.b[i].i;
363
+ if (this.a === STATE_DIRTY) {
364
+ break;
365
+ }
366
+ }
367
+ }
368
+ if (this.a === STATE_DIRTY) {
369
+ update(this);
370
+ } else {
371
+ this.write(UNCHANGED, observerFlags);
372
+ this.a = STATE_CLEAN;
373
+ }
374
+ }
375
+ /**
376
+ * Remove ourselves from the owner graph and the computation graph
377
+ */
378
+ w() {
379
+ if (this.a === STATE_DISPOSED)
380
+ return;
381
+ if (this.b)
382
+ removeSourceObservers(this, 0);
383
+ super.w();
384
+ }
385
+ };
386
+ function loadingState(node) {
387
+ const prevOwner = setOwner(node.q);
388
+ const options = void 0;
389
+ const computation = new Computation(
390
+ void 0,
391
+ () => {
392
+ track(node);
393
+ node.r();
394
+ return !!(node.i & LOADING_BIT);
395
+ },
396
+ options
397
+ );
398
+ computation.A = ERROR_BIT | LOADING_BIT;
399
+ setOwner(prevOwner);
400
+ return computation;
401
+ }
402
+ function errorState(node) {
403
+ const prevOwner = setOwner(node.q);
404
+ const options = void 0;
405
+ const computation = new Computation(
406
+ void 0,
407
+ () => {
408
+ track(node);
409
+ node.r();
410
+ return !!(node.i & ERROR_BIT);
411
+ },
412
+ options
413
+ );
414
+ computation.A = ERROR_BIT;
415
+ setOwner(prevOwner);
416
+ return computation;
417
+ }
418
+ function track(computation) {
419
+ if (currentObserver) {
420
+ if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
421
+ newSourcesIndex++;
422
+ } else if (!newSources)
423
+ newSources = [computation];
424
+ else if (computation !== newSources[newSources.length - 1]) {
425
+ newSources.push(computation);
426
+ }
427
+ if (updateCheck) {
428
+ updateCheck.d = computation.G > currentObserver.G;
429
+ }
430
+ }
431
+ }
432
+ function update(node) {
433
+ const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
434
+ newSources = null;
435
+ newSourcesIndex = 0;
436
+ newFlags = 0;
437
+ try {
438
+ node.dispose(false);
439
+ node.emptyDisposal();
440
+ const result = compute(node, node.C, node);
441
+ node.write(result, newFlags, true);
442
+ } catch (error) {
443
+ if (error instanceof NotReadyError) {
444
+ node.write(UNCHANGED, newFlags | LOADING_BIT);
445
+ } else {
446
+ node.Q(error);
447
+ }
448
+ } finally {
449
+ if (newSources) {
450
+ if (node.b)
451
+ removeSourceObservers(node, newSourcesIndex);
452
+ if (node.b && newSourcesIndex > 0) {
453
+ node.b.length = newSourcesIndex + newSources.length;
454
+ for (let i = 0; i < newSources.length; i++) {
455
+ node.b[newSourcesIndex + i] = newSources[i];
456
+ }
457
+ } else {
458
+ node.b = newSources;
459
+ }
460
+ let source;
461
+ for (let i = newSourcesIndex; i < node.b.length; i++) {
462
+ source = node.b[i];
463
+ if (!source.c)
464
+ source.c = [node];
465
+ else
466
+ source.c.push(node);
467
+ }
468
+ } else if (node.b && newSourcesIndex < node.b.length) {
469
+ removeSourceObservers(node, newSourcesIndex);
470
+ node.b.length = newSourcesIndex;
471
+ }
472
+ newSources = prevSources;
473
+ newSourcesIndex = prevSourcesIndex;
474
+ newFlags = prevFlags;
475
+ node.a = STATE_CLEAN;
476
+ }
477
+ }
478
+ function removeSourceObservers(node, index) {
479
+ var _a;
480
+ let source;
481
+ let swap;
482
+ for (let i = index; i < node.b.length; i++) {
483
+ source = node.b[i];
484
+ if (source.c) {
485
+ swap = source.c.indexOf(node);
486
+ source.c[swap] = source.c[source.c.length - 1];
487
+ source.c.pop();
488
+ if (!source.c.length)
489
+ (_a = source.N) == null ? void 0 : _a.call(source);
490
+ }
491
+ }
492
+ }
493
+ function isEqual(a, b) {
494
+ return a === b;
495
+ }
496
+ function untrack(fn) {
497
+ if (currentObserver === null)
498
+ return fn();
499
+ return compute(getOwner(), fn, null);
500
+ }
501
+ function hasUpdated(fn) {
502
+ const current = updateCheck;
503
+ updateCheck = { d: false };
504
+ try {
505
+ fn();
506
+ return updateCheck.d;
507
+ } finally {
508
+ updateCheck = current;
509
+ }
510
+ }
511
+ function isPending(fn) {
512
+ try {
513
+ fn();
514
+ return false;
515
+ } catch (e) {
516
+ return e instanceof NotReadyError;
517
+ }
518
+ }
519
+ function latest(fn) {
520
+ const prevFlags = newFlags;
521
+ syncResolve = true;
522
+ try {
523
+ return fn();
524
+ } catch {
525
+ } finally {
526
+ newFlags = prevFlags;
527
+ syncResolve = false;
528
+ }
529
+ }
530
+ function compute(owner, compute2, observer) {
531
+ const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
532
+ currentObserver = observer;
533
+ currentMask = (observer == null ? void 0 : observer.A) ?? DEFAULT_FLAGS;
534
+ try {
535
+ return compute2(observer ? observer.d : void 0);
536
+ } finally {
537
+ setOwner(prevOwner);
538
+ currentObserver = prevObserver;
539
+ currentMask = prevMask;
540
+ }
541
+ }
542
+
543
+ // src/core/scheduler.ts
544
+ var scheduled = false;
545
+ function schedule() {
546
+ if (scheduled)
547
+ return;
548
+ scheduled = true;
549
+ queueMicrotask(flushSync);
550
+ }
551
+ var Queue = class {
552
+ H = false;
553
+ t = [[], [], []];
554
+ y = [];
555
+ enqueue(type, node) {
556
+ this.t[0].push(node);
557
+ if (type)
558
+ this.t[type].push(node);
559
+ schedule();
560
+ }
561
+ run(type) {
562
+ if (this.t[type].length) {
563
+ if (type === EFFECT_PURE) {
564
+ runPureQueue(this.t[type]);
565
+ this.t[type] = [];
566
+ } else {
567
+ const effects = this.t[type];
568
+ this.t[type] = [];
569
+ runEffectQueue(effects);
570
+ }
571
+ }
572
+ for (let i = 0; i < this.y.length; i++) {
573
+ this.y[i].run(type);
574
+ }
575
+ }
576
+ flush() {
577
+ if (this.H)
578
+ return;
579
+ this.H = true;
580
+ try {
581
+ this.run(EFFECT_PURE);
582
+ incrementClock();
583
+ this.run(EFFECT_RENDER);
584
+ this.run(EFFECT_USER);
585
+ } finally {
586
+ this.H = false;
587
+ }
588
+ }
589
+ addChild(child) {
590
+ this.y.push(child);
591
+ }
592
+ removeChild(child) {
593
+ const index = this.y.indexOf(child);
594
+ if (index >= 0)
595
+ this.y.splice(index, 1);
596
+ }
597
+ };
598
+ var globalQueue = new Queue();
599
+ function flushSync() {
600
+ globalQueue.flush();
601
+ scheduled = false;
602
+ }
603
+ function createBoundary(fn, queue) {
604
+ const owner = new Owner();
605
+ const parentQueue = owner.e || globalQueue;
606
+ parentQueue.addChild(owner.e = queue);
607
+ onCleanup(() => parentQueue.removeChild(owner.e));
608
+ return compute(owner, fn, null);
609
+ }
610
+ function runTop(node) {
611
+ const ancestors = [];
612
+ for (let current = node; current !== null; current = current.q) {
613
+ if (current.a !== STATE_CLEAN) {
614
+ ancestors.push(current);
615
+ }
616
+ }
617
+ for (let i = ancestors.length - 1; i >= 0; i--) {
618
+ if (ancestors[i].a !== STATE_DISPOSED)
619
+ ancestors[i].r();
620
+ }
621
+ }
622
+ function runPureQueue(queue) {
623
+ for (let i = 0; i < queue.length; i++) {
624
+ if (queue[i].a !== STATE_CLEAN)
625
+ runTop(queue[i]);
626
+ }
627
+ }
628
+ function runEffectQueue(queue) {
629
+ for (let i = 0; i < queue.length; i++) {
630
+ if (queue[i].I && queue[i].a !== STATE_DISPOSED) {
631
+ queue[i].J(queue[i].d, queue[i].B);
632
+ queue[i].I = false;
633
+ queue[i].B = queue[i].d;
634
+ }
635
+ }
636
+ }
637
+
638
+ // src/core/effect.ts
639
+ var Effect = class extends Computation {
640
+ J;
641
+ I = false;
642
+ B;
643
+ K;
644
+ e;
645
+ constructor(initialValue, compute2, effect, options) {
646
+ var _a;
647
+ super(initialValue, compute2, options);
648
+ this.J = effect;
649
+ this.B = initialValue;
650
+ this.K = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
651
+ this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
652
+ this.e.enqueue(this.K, this);
653
+ this.r();
654
+ }
655
+ write(value, flags = 0) {
656
+ var _a, _b;
657
+ const currentFlags = this.i;
658
+ this.i = flags;
659
+ if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
660
+ (_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
661
+ }
662
+ if (value === UNCHANGED)
663
+ return this.d;
664
+ this.d = value;
665
+ this.I = true;
666
+ return value;
667
+ }
668
+ s(state) {
669
+ if (this.a >= state)
670
+ return;
671
+ if (this.a === STATE_CLEAN)
672
+ this.e.enqueue(this.K, this);
673
+ this.a = state;
674
+ }
675
+ Q(error) {
676
+ this.handleError(error);
677
+ }
678
+ w() {
679
+ this.J = void 0;
680
+ this.B = void 0;
681
+ super.w();
682
+ }
683
+ };
684
+ var EagerComputation = class extends Computation {
685
+ e;
686
+ constructor(initialValue, compute2, options) {
687
+ var _a;
688
+ super(initialValue, compute2, options);
689
+ this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
690
+ this.r();
691
+ }
692
+ s(state) {
693
+ if (this.a >= state)
694
+ return;
695
+ if (this.a === STATE_CLEAN)
696
+ this.e.enqueue(EFFECT_PURE, this);
697
+ super.s(state);
698
+ }
699
+ };
700
+
701
+ // src/core/suspense.ts
702
+ var SuspenseQueue = class extends Queue {
703
+ k = /* @__PURE__ */ new Set();
704
+ z = false;
705
+ L = new Computation(false, null);
706
+ run(type) {
707
+ if (type && this.z)
708
+ return;
709
+ super.run(type);
710
+ }
711
+ S(node) {
712
+ if (node.i & LOADING_BIT) {
713
+ this.k.add(node);
714
+ if (!this.z) {
715
+ this.z = true;
716
+ queueMicrotask(() => this.L.write(true));
717
+ }
718
+ } else {
719
+ this.k.delete(node);
720
+ if (this.k.size === 0) {
721
+ this.z = false;
722
+ queueMicrotask(() => this.L.write(false));
723
+ }
724
+ }
725
+ }
726
+ };
727
+ function createSuspense(fn, fallbackFn) {
728
+ const queue = new SuspenseQueue();
729
+ const tree = createBoundary(fn, queue);
730
+ const equality = new Computation(null, () => queue.L.read() || queue.z);
731
+ const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
732
+ return comp.read.bind(comp);
733
+ }
734
+
735
+ // src/signals.ts
736
+ function createSignal(first, second, third) {
737
+ if (typeof first === "function") {
738
+ const memo = createMemo((p) => {
739
+ const node2 = new Computation(
740
+ first(p ? untrack(p[0]) : second),
741
+ null,
742
+ third
743
+ );
744
+ return [node2.read.bind(node2), node2.write.bind(node2)];
745
+ });
746
+ return [() => memo()[0](), (value) => memo()[1](value)];
747
+ }
748
+ const node = new Computation(first, null, second);
749
+ return [node.read.bind(node), node.write.bind(node)];
750
+ }
751
+ function createAsync(fn, initial, options) {
752
+ const lhs = new EagerComputation(
753
+ {
754
+ d: initial
755
+ },
756
+ (p) => {
757
+ const value = p == null ? void 0 : p.d;
758
+ const source = fn(value);
759
+ const isPromise = source instanceof Promise;
760
+ const iterator = source[Symbol.asyncIterator];
761
+ if (!isPromise && !iterator) {
762
+ return {
763
+ wait() {
764
+ return source;
765
+ },
766
+ d: source
767
+ };
768
+ }
769
+ const signal = new Computation(value, null, options);
770
+ signal.write(UNCHANGED, LOADING_BIT);
771
+ if (isPromise) {
772
+ source.then(
773
+ (value2) => {
774
+ signal.write(value2, 0);
775
+ },
776
+ (error) => {
777
+ signal.write(error, ERROR_BIT);
778
+ }
779
+ );
780
+ } else {
781
+ let abort = false;
782
+ onCleanup(() => abort = true);
783
+ (async () => {
784
+ try {
785
+ for await (let value2 of source) {
786
+ if (abort)
787
+ return;
788
+ signal.write(value2, 0);
789
+ }
790
+ } catch (error) {
791
+ signal.write(error, ERROR_BIT);
792
+ }
793
+ })();
794
+ }
795
+ return signal;
796
+ }
797
+ );
798
+ return () => lhs.wait().wait();
799
+ }
800
+ function createMemo(compute2, initialValue, options) {
801
+ let node = new Computation(initialValue, compute2, options);
802
+ let value;
803
+ return () => {
804
+ var _a;
805
+ if (node) {
806
+ value = node.wait();
807
+ if (!((_a = node.b) == null ? void 0 : _a.length))
808
+ node = void 0;
809
+ }
810
+ return value;
811
+ };
812
+ }
813
+ function createEffect(compute2, effect, initialValue, options) {
814
+ void new Effect(
815
+ initialValue,
816
+ compute2,
817
+ effect,
818
+ void 0
819
+ );
820
+ }
821
+ function createRenderEffect(compute2, effect, initialValue, options) {
822
+ void new Effect(initialValue, compute2, effect, {
823
+ render: true,
824
+ ...void 0
825
+ });
826
+ }
827
+ function createRoot(init) {
828
+ const owner = new Owner();
829
+ return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
830
+ }
831
+ function runWithOwner(owner, run) {
832
+ try {
833
+ return compute(owner, run, null);
834
+ } catch (error) {
835
+ owner == null ? void 0 : owner.handleError(error);
836
+ return void 0;
837
+ }
838
+ }
839
+ function catchError(fn, handler) {
840
+ const owner = new Owner();
841
+ owner.h = owner.h ? [handler, ...owner.h] : [handler];
842
+ try {
843
+ compute(owner, fn, null);
844
+ } catch (error) {
845
+ owner.handleError(error);
846
+ }
847
+ }
848
+
849
+ // src/store/store.ts
850
+ var $RAW = Symbol(0);
851
+ var $TRACK = Symbol(0);
852
+ var $TARGET = Symbol(0);
853
+ var $PROXY = Symbol(0);
854
+ var STORE_VALUE = "v";
855
+ var STORE_NODE = "n";
856
+ var STORE_HAS = "h";
857
+ function wrap(value) {
858
+ let p = value[$PROXY];
859
+ if (!p)
860
+ Object.defineProperty(value, $PROXY, {
861
+ value: p = new Proxy({ v: value }, proxyTraps),
862
+ writable: true
863
+ });
864
+ return p;
865
+ }
866
+ function isWrappable(obj) {
867
+ return obj != null && typeof obj === "object";
868
+ }
869
+ function unwrap(item, deep = true, set) {
870
+ let result, unwrapped, v, prop;
871
+ if (result = item != null && item[$RAW])
872
+ return result;
873
+ if (!deep)
874
+ return item;
875
+ if (!isWrappable(item) || (set == null ? void 0 : set.has(item)))
876
+ return item;
877
+ if (!set)
878
+ set = /* @__PURE__ */ new Set();
879
+ set.add(item);
880
+ if (Array.isArray(item)) {
881
+ for (let i = 0, l = item.length; i < l; i++) {
882
+ v = item[i];
883
+ if ((unwrapped = unwrap(v, deep, set)) !== v)
884
+ item[i] = unwrapped;
885
+ }
886
+ } else {
887
+ if (!deep)
888
+ return item;
889
+ const keys = Object.keys(item);
890
+ for (let i = 0, l = keys.length; i < l; i++) {
891
+ prop = keys[i];
892
+ const desc = Object.getOwnPropertyDescriptor(item, prop);
893
+ if (desc.get)
894
+ continue;
895
+ v = item[prop];
896
+ if ((unwrapped = unwrap(v, deep, set)) !== v)
897
+ item[prop] = unwrapped;
898
+ }
899
+ }
900
+ return item;
901
+ }
902
+ function getNodes(target, type) {
903
+ let nodes = target[type];
904
+ if (!nodes)
905
+ target[type] = nodes = /* @__PURE__ */ Object.create(null);
906
+ return nodes;
907
+ }
908
+ function getNode(nodes, property, value, equals = isEqual) {
909
+ if (nodes[property])
910
+ return nodes[property];
911
+ return nodes[property] = new Computation(value, null, {
912
+ equals,
913
+ unobserved() {
914
+ delete nodes[property];
915
+ }
916
+ });
917
+ }
918
+ function proxyDescriptor(target, property) {
919
+ const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
920
+ if (!desc || desc.get || !desc.configurable || property === $PROXY)
921
+ return desc;
922
+ delete desc.value;
923
+ delete desc.writable;
924
+ desc.get = () => target[STORE_VALUE][$PROXY][property];
925
+ return desc;
926
+ }
927
+ function trackSelf(target) {
928
+ getObserver() && getNode(getNodes(target, STORE_NODE), $TRACK, void 0, false).read();
929
+ }
930
+ function ownKeys(target) {
931
+ trackSelf(target);
932
+ return Reflect.ownKeys(target[STORE_VALUE]);
933
+ }
934
+ var Writing = /* @__PURE__ */ new Set();
935
+ var proxyTraps = {
936
+ get(target, property, receiver) {
937
+ if (property === $TARGET)
938
+ return target;
939
+ if (property === $RAW)
940
+ return target[STORE_VALUE];
941
+ if (property === $PROXY)
942
+ return receiver;
943
+ if (property === $TRACK) {
944
+ trackSelf(target);
945
+ return receiver;
946
+ }
947
+ const nodes = getNodes(target, STORE_NODE);
948
+ const storeValue = target[STORE_VALUE];
949
+ const tracked = nodes[property];
950
+ if (!tracked) {
951
+ const desc = Object.getOwnPropertyDescriptor(storeValue, property);
952
+ if (desc && desc.get)
953
+ return desc.get.call(receiver);
954
+ }
955
+ if (Writing.has(storeValue)) {
956
+ const value2 = tracked ? tracked.d : storeValue[property];
957
+ return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap(value2)) : value2;
958
+ }
959
+ let value = tracked ? nodes[property].read() : storeValue[property];
960
+ if (!tracked) {
961
+ if (typeof value === "function" && !storeValue.hasOwnProperty(property)) {
962
+ let proto;
963
+ return !Array.isArray(storeValue) && (proto = Object.getPrototypeOf(storeValue)) && proto !== Object.prototype ? value.bind(storeValue) : value;
964
+ } else if (getObserver()) {
965
+ value = getNode(nodes, property, isWrappable(value) ? wrap(value) : value).read();
966
+ }
967
+ }
968
+ return isWrappable(value) ? wrap(value) : value;
969
+ },
970
+ has(target, property) {
971
+ if (property === $RAW || property === $PROXY || property === $TRACK || property === "__proto__")
972
+ return true;
973
+ const has = property in target[STORE_VALUE];
974
+ getObserver() && getNode(getNodes(target, STORE_HAS), property, has).read();
975
+ return has;
976
+ },
977
+ set(target, property, value) {
978
+ Writing.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, unwrap(value, false));
979
+ return true;
980
+ },
981
+ deleteProperty(target, property) {
982
+ Writing.has(target[STORE_VALUE]) && setProperty(target[STORE_VALUE], property, void 0, true);
983
+ return true;
984
+ },
985
+ ownKeys,
986
+ getOwnPropertyDescriptor: proxyDescriptor
987
+ };
988
+ function setProperty(state, property, value, deleting = false) {
989
+ var _a, _b, _c, _d, _e;
990
+ const prev = state[property];
991
+ if (!deleting && prev === value)
992
+ return;
993
+ const len = state.length;
994
+ if (deleting)
995
+ delete state[property];
996
+ else
997
+ state[property] = value;
998
+ const target = (_a = state[$PROXY]) == null ? void 0 : _a[$TARGET];
999
+ if (!target)
1000
+ return;
1001
+ if (deleting)
1002
+ (_c = (_b = target[STORE_HAS]) == null ? void 0 : _b[property]) == null ? void 0 : _c.write(false);
1003
+ else
1004
+ (_e = (_d = target[STORE_HAS]) == null ? void 0 : _d[property]) == null ? void 0 : _e.write(true);
1005
+ const nodes = getNodes(target, STORE_NODE);
1006
+ let node;
1007
+ if (node = nodes[property])
1008
+ node.write(isWrappable(value) ? wrap(value) : value);
1009
+ Array.isArray(state) && state.length !== len && (node = nodes.length) && node.write(state.length);
1010
+ (node = nodes[$TRACK]) && node.write(void 0);
1011
+ }
1012
+ function createStore(first, second) {
1013
+ const derived = typeof first === "function", store = derived ? second : first, unwrappedStore = unwrap(store, false);
1014
+ const wrappedStore = wrap(unwrappedStore);
1015
+ const setStore = (fn) => {
1016
+ try {
1017
+ Writing.add(unwrappedStore);
1018
+ fn(wrappedStore);
1019
+ } finally {
1020
+ Writing.clear();
1021
+ }
1022
+ };
1023
+ if (derived) {
1024
+ new EagerComputation(void 0, () => setStore(first));
1025
+ }
1026
+ return [wrappedStore, setStore];
1027
+ }
1028
+ function createProjection(fn, initialValue = {}) {
1029
+ const [store] = createStore(fn, initialValue);
1030
+ return store;
1031
+ }
1032
+
1033
+ // src/store/reconcile.ts
1034
+ function applyState(next, state, keyFn) {
1035
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1036
+ const target = state == null ? void 0 : state[$TARGET];
1037
+ if (!target)
1038
+ return;
1039
+ const previous = target[STORE_VALUE];
1040
+ if (next === previous)
1041
+ return;
1042
+ Object.defineProperty(next, $PROXY, {
1043
+ value: previous[$PROXY],
1044
+ writable: true
1045
+ });
1046
+ previous[$PROXY] = null;
1047
+ target[STORE_VALUE] = next;
1048
+ if (Array.isArray(previous)) {
1049
+ let changed = false;
1050
+ if (next.length && previous.length && next[0] && keyFn(next[0]) != null) {
1051
+ let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
1052
+ for (start = 0, end = Math.min(previous.length, next.length); start < end && (previous[start] === next[start] || previous[start] && next[start] && keyFn(previous[start]) === keyFn(next[start])); start++) {
1053
+ applyState(next[start], wrap(previous[start]), keyFn);
1054
+ }
1055
+ const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
1056
+ for (end = previous.length - 1, newEnd = next.length - 1; end >= start && newEnd >= start && (previous[end] === next[newEnd] || previous[end] && next[newEnd] && keyFn(previous[end]) === keyFn(next[newEnd])); end--, newEnd--) {
1057
+ temp[newEnd] = previous[end];
1058
+ }
1059
+ if (start > newEnd || start > end) {
1060
+ for (j = start; j <= newEnd; j++) {
1061
+ changed = true;
1062
+ (_a = target[STORE_NODE][j]) == null ? void 0 : _a.write(wrap(next[j]));
1063
+ }
1064
+ for (; j < next.length; j++) {
1065
+ changed = true;
1066
+ const wrapped = wrap(temp[j]);
1067
+ (_b = target[STORE_NODE][j]) == null ? void 0 : _b.write(wrapped);
1068
+ applyState(next[j], wrapped, keyFn);
1069
+ }
1070
+ changed && ((_c = target[STORE_NODE][$TRACK]) == null ? void 0 : _c.write(void 0));
1071
+ previous.length !== next.length && ((_d = target[STORE_NODE].length) == null ? void 0 : _d.write(next.length));
1072
+ return;
1073
+ }
1074
+ newIndicesNext = new Array(newEnd + 1);
1075
+ for (j = newEnd; j >= start; j--) {
1076
+ item = next[j];
1077
+ keyVal = item ? keyFn(item) : item;
1078
+ i = newIndices.get(keyVal);
1079
+ newIndicesNext[j] = i === void 0 ? -1 : i;
1080
+ newIndices.set(keyVal, j);
1081
+ }
1082
+ for (i = start; i <= end; i++) {
1083
+ item = previous[i];
1084
+ keyVal = item ? keyFn(item) : item;
1085
+ j = newIndices.get(keyVal);
1086
+ if (j !== void 0 && j !== -1) {
1087
+ temp[j] = previous[i];
1088
+ j = newIndicesNext[j];
1089
+ newIndices.set(keyVal, j);
1090
+ }
1091
+ }
1092
+ for (j = start; j < next.length; j++) {
1093
+ if (j in temp) {
1094
+ const wrapped = wrap(temp[j]);
1095
+ (_e = target[STORE_NODE][j]) == null ? void 0 : _e.write(wrapped);
1096
+ applyState(next[j], wrapped, keyFn);
1097
+ } else
1098
+ (_f = target[STORE_NODE][j]) == null ? void 0 : _f.write(wrap(next[j]));
1099
+ }
1100
+ if (start < next.length)
1101
+ changed = true;
1102
+ } else if (previous.length && next.length) {
1103
+ for (let i = 0, len = next.length; i < len; i++) {
1104
+ isWrappable(previous[i]) && applyState(next[i], wrap(previous[i]), keyFn);
1105
+ }
1106
+ }
1107
+ if (previous.length !== next.length) {
1108
+ changed = true;
1109
+ (_g = target[STORE_NODE].length) == null ? void 0 : _g.write(next.length);
1110
+ }
1111
+ changed && ((_h = target[STORE_NODE][$TRACK]) == null ? void 0 : _h.write(void 0));
1112
+ return;
1113
+ }
1114
+ let nodes = target[STORE_NODE];
1115
+ if (nodes) {
1116
+ const keys = Object.keys(nodes);
1117
+ for (let i = 0, len = keys.length; i < len; i++) {
1118
+ const node = nodes[keys[i]];
1119
+ const previousValue = unwrap(previous[keys[i]], false);
1120
+ let nextValue = unwrap(next[keys[i]], false);
1121
+ if (previousValue === nextValue)
1122
+ continue;
1123
+ if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
1124
+ node.write(isWrappable(nextValue) ? wrap(nextValue) : nextValue);
1125
+ else
1126
+ applyState(nextValue, wrap(previousValue), keyFn);
1127
+ }
1128
+ }
1129
+ if (nodes = target[STORE_HAS]) {
1130
+ const keys = Object.keys(nodes);
1131
+ for (let i = 0, len = keys.length; i < len; i++) {
1132
+ nodes[keys[i]].write(keys[i] in next);
1133
+ }
1134
+ }
1135
+ }
1136
+ function reconcile(value, key) {
1137
+ return (state) => {
1138
+ const keyFn = typeof key === "string" ? (item) => item[key] : key;
1139
+ if (keyFn(value) !== keyFn(state))
1140
+ throw new Error("Cannot reconcile states with different identity");
1141
+ applyState(value, state, keyFn);
1142
+ };
1143
+ }
1144
+
1145
+ // src/store/utilities.ts
1146
+ function trueFn() {
1147
+ return true;
1148
+ }
1149
+ var propTraps = {
1150
+ get(_, property, receiver) {
1151
+ if (property === $PROXY)
1152
+ return receiver;
1153
+ return _.get(property);
1154
+ },
1155
+ has(_, property) {
1156
+ if (property === $PROXY)
1157
+ return true;
1158
+ return _.has(property);
1159
+ },
1160
+ set: trueFn,
1161
+ deleteProperty: trueFn,
1162
+ getOwnPropertyDescriptor(_, property) {
1163
+ return {
1164
+ configurable: true,
1165
+ enumerable: true,
1166
+ get() {
1167
+ return _.get(property);
1168
+ },
1169
+ set: trueFn,
1170
+ deleteProperty: trueFn
1171
+ };
1172
+ },
1173
+ ownKeys(_) {
1174
+ return _.keys();
1175
+ }
1176
+ };
1177
+ function resolveSource(s) {
1178
+ return !(s = typeof s === "function" ? s() : s) ? {} : s;
1179
+ }
1180
+ var $SOURCES = Symbol(0);
1181
+ function merge(...sources) {
1182
+ if (sources.length === 1)
1183
+ return sources[0];
1184
+ let proxy = false;
1185
+ const flattened = [];
1186
+ for (let i = 0; i < sources.length; i++) {
1187
+ const s = sources[i];
1188
+ proxy = proxy || !!s && $PROXY in s;
1189
+ const childSources = !!s && s[$SOURCES];
1190
+ if (childSources)
1191
+ flattened.push(...childSources);
1192
+ else
1193
+ flattened.push(
1194
+ typeof s === "function" ? (proxy = true, createMemo(s)) : s
1195
+ );
1196
+ }
1197
+ if (SUPPORTS_PROXY && proxy) {
1198
+ return new Proxy(
1199
+ {
1200
+ get(property) {
1201
+ if (property === $SOURCES)
1202
+ return flattened;
1203
+ for (let i = flattened.length - 1; i >= 0; i--) {
1204
+ const s = resolveSource(flattened[i]);
1205
+ if (property in s)
1206
+ return s[property];
1207
+ }
1208
+ },
1209
+ has(property) {
1210
+ for (let i = flattened.length - 1; i >= 0; i--) {
1211
+ if (property in resolveSource(flattened[i]))
1212
+ return true;
1213
+ }
1214
+ return false;
1215
+ },
1216
+ keys() {
1217
+ const keys = [];
1218
+ for (let i = 0; i < flattened.length; i++)
1219
+ keys.push(...Object.keys(resolveSource(flattened[i])));
1220
+ return [...new Set(keys)];
1221
+ }
1222
+ },
1223
+ propTraps
1224
+ );
1225
+ }
1226
+ const defined = /* @__PURE__ */ Object.create(null);
1227
+ let nonTargetKey = false;
1228
+ let lastIndex = flattened.length - 1;
1229
+ for (let i = lastIndex; i >= 0; i--) {
1230
+ const source = flattened[i];
1231
+ if (!source) {
1232
+ i === lastIndex && lastIndex--;
1233
+ continue;
1234
+ }
1235
+ const sourceKeys = Object.getOwnPropertyNames(source);
1236
+ for (let j = sourceKeys.length - 1; j >= 0; j--) {
1237
+ const key = sourceKeys[j];
1238
+ if (key === "__proto__" || key === "constructor")
1239
+ continue;
1240
+ if (!defined[key]) {
1241
+ nonTargetKey = nonTargetKey || i !== lastIndex;
1242
+ const desc = Object.getOwnPropertyDescriptor(source, key);
1243
+ defined[key] = desc.get ? {
1244
+ enumerable: true,
1245
+ configurable: true,
1246
+ get: desc.get.bind(source)
1247
+ } : desc;
1248
+ }
1249
+ }
1250
+ }
1251
+ if (!nonTargetKey)
1252
+ return flattened[lastIndex];
1253
+ const target = {};
1254
+ const definedKeys = Object.keys(defined);
1255
+ for (let i = definedKeys.length - 1; i >= 0; i--) {
1256
+ const key = definedKeys[i], desc = defined[key];
1257
+ if (desc.get)
1258
+ Object.defineProperty(target, key, desc);
1259
+ else
1260
+ target[key] = desc.value;
1261
+ }
1262
+ target[$SOURCES] = flattened;
1263
+ return target;
1264
+ }
1265
+ function omit(props, ...keys) {
1266
+ const blocked = new Set(keys);
1267
+ if (SUPPORTS_PROXY && $PROXY in props) {
1268
+ return new Proxy(
1269
+ {
1270
+ get(property) {
1271
+ return blocked.has(property) ? void 0 : props[property];
1272
+ },
1273
+ has(property) {
1274
+ return !blocked.has(property) && property in props;
1275
+ },
1276
+ keys() {
1277
+ return Object.keys(props).filter((k) => !blocked.has(k));
1278
+ }
1279
+ },
1280
+ propTraps
1281
+ );
1282
+ }
1283
+ const result = {};
1284
+ for (const propName of Object.getOwnPropertyNames(props)) {
1285
+ if (!blocked.has(propName)) {
1286
+ const desc = Object.getOwnPropertyDescriptor(props, propName);
1287
+ !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable ? result[propName] = desc.value : Object.defineProperty(result, propName, desc);
1288
+ }
1289
+ }
1290
+ return result;
1291
+ }
1292
+
1293
+ // src/map.ts
1294
+ function mapArray(list, map, options) {
1295
+ const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
1296
+ return Computation.prototype.read.bind(
1297
+ new Computation(
1298
+ [],
1299
+ updateKeyedMap.bind({
1300
+ R: new Owner(),
1301
+ u: 0,
1302
+ T: list,
1303
+ p: [],
1304
+ M: map,
1305
+ n: [],
1306
+ k: [],
1307
+ x: keyFn,
1308
+ f: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
1309
+ j: map.length > 1 ? [] : void 0
1310
+ }),
1311
+ options
1312
+ )
1313
+ );
1314
+ }
1315
+ function updateKeyedMap() {
1316
+ const newItems = this.T() || [], newLen = newItems.length;
1317
+ newItems[$TRACK];
1318
+ runWithOwner(this.R, () => {
1319
+ let i, j, mapper = this.f ? () => {
1320
+ this.f[j] = new Computation(newItems[j], null);
1321
+ this.j[j] = new Computation(j, null);
1322
+ return this.M(
1323
+ Computation.prototype.read.bind(this.f[j]),
1324
+ Computation.prototype.read.bind(this.j[j])
1325
+ );
1326
+ } : this.j ? () => {
1327
+ const item = newItems[j];
1328
+ this.j[j] = new Computation(j, null);
1329
+ return this.M(() => item, Computation.prototype.read.bind(this.j[j]));
1330
+ } : () => {
1331
+ const item = newItems[j];
1332
+ return this.M(() => item);
1333
+ };
1334
+ if (newLen === 0) {
1335
+ if (this.u !== 0) {
1336
+ this.R.dispose(false);
1337
+ this.k = [];
1338
+ this.p = [];
1339
+ this.n = [];
1340
+ this.u = 0;
1341
+ this.f && (this.f = []);
1342
+ this.j && (this.j = []);
1343
+ }
1344
+ } else if (this.u === 0) {
1345
+ this.n = new Array(newLen);
1346
+ for (j = 0; j < newLen; j++) {
1347
+ this.p[j] = newItems[j];
1348
+ this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1349
+ }
1350
+ this.u = newLen;
1351
+ } else {
1352
+ let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.f ? new Array(newLen) : void 0, tempIndexes = this.j ? new Array(newLen) : void 0;
1353
+ for (start = 0, end = Math.min(this.u, newLen); start < end && (this.p[start] === newItems[start] || this.f && compare(this.x, this.p[start], newItems[start])); start++) {
1354
+ if (this.f)
1355
+ this.f[start].write(newItems[start]);
1356
+ }
1357
+ for (end = this.u - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.p[end] === newItems[newEnd] || this.f && compare(this.x, this.p[end], newItems[newEnd])); end--, newEnd--) {
1358
+ temp[newEnd] = this.n[end];
1359
+ tempNodes[newEnd] = this.k[end];
1360
+ tempRows && (tempRows[newEnd] = this.f[end]);
1361
+ tempIndexes && (tempIndexes[newEnd] = this.j[end]);
1362
+ }
1363
+ newIndices = /* @__PURE__ */ new Map();
1364
+ newIndicesNext = new Array(newEnd + 1);
1365
+ for (j = newEnd; j >= start; j--) {
1366
+ item = newItems[j];
1367
+ key = this.x ? this.x(item) : item;
1368
+ i = newIndices.get(key);
1369
+ newIndicesNext[j] = i === void 0 ? -1 : i;
1370
+ newIndices.set(key, j);
1371
+ }
1372
+ for (i = start; i <= end; i++) {
1373
+ item = this.p[i];
1374
+ key = this.x ? this.x(item) : item;
1375
+ j = newIndices.get(key);
1376
+ if (j !== void 0 && j !== -1) {
1377
+ temp[j] = this.n[i];
1378
+ tempNodes[j] = this.k[i];
1379
+ tempRows && (tempRows[j] = this.f[i]);
1380
+ tempIndexes && (tempIndexes[j] = this.j[i]);
1381
+ j = newIndicesNext[j];
1382
+ newIndices.set(key, j);
1383
+ } else
1384
+ this.k[i].dispose();
1385
+ }
1386
+ for (j = start; j < newLen; j++) {
1387
+ if (j in temp) {
1388
+ this.n[j] = temp[j];
1389
+ this.k[j] = tempNodes[j];
1390
+ if (tempRows) {
1391
+ this.f[j] = tempRows[j];
1392
+ this.f[j].write(newItems[j]);
1393
+ }
1394
+ if (tempIndexes) {
1395
+ this.j[j] = tempIndexes[j];
1396
+ this.j[j].write(j);
1397
+ }
1398
+ } else {
1399
+ this.n[j] = compute(this.k[j] = new Owner(), mapper, null);
1400
+ }
1401
+ }
1402
+ this.n = this.n.slice(0, this.u = newLen);
1403
+ this.p = newItems.slice(0);
1404
+ }
1405
+ });
1406
+ return this.n;
1407
+ }
1408
+ function compare(key, a, b) {
1409
+ return key ? key(a) === key(b) : true;
1410
+ }
1411
+
1412
+ exports.$PROXY = $PROXY;
1413
+ exports.$RAW = $RAW;
1414
+ exports.$TARGET = $TARGET;
1415
+ exports.$TRACK = $TRACK;
1416
+ exports.Computation = Computation;
1417
+ exports.ContextNotFoundError = ContextNotFoundError;
1418
+ exports.NoOwnerError = NoOwnerError;
1419
+ exports.NotReadyError = NotReadyError;
1420
+ exports.Owner = Owner;
1421
+ exports.Queue = Queue;
1422
+ exports.catchError = catchError;
1423
+ exports.createAsync = createAsync;
1424
+ exports.createBoundary = createBoundary;
1425
+ exports.createContext = createContext;
1426
+ exports.createEffect = createEffect;
1427
+ exports.createMemo = createMemo;
1428
+ exports.createProjection = createProjection;
1429
+ exports.createRenderEffect = createRenderEffect;
1430
+ exports.createRoot = createRoot;
1431
+ exports.createSignal = createSignal;
1432
+ exports.createStore = createStore;
1433
+ exports.createSuspense = createSuspense;
1434
+ exports.flushSync = flushSync;
1435
+ exports.getContext = getContext;
1436
+ exports.getObserver = getObserver;
1437
+ exports.getOwner = getOwner;
1438
+ exports.hasContext = hasContext;
1439
+ exports.hasUpdated = hasUpdated;
1440
+ exports.isEqual = isEqual;
1441
+ exports.isPending = isPending;
1442
+ exports.isWrappable = isWrappable;
1443
+ exports.latest = latest;
1444
+ exports.mapArray = mapArray;
1445
+ exports.merge = merge;
1446
+ exports.omit = omit;
1447
+ exports.onCleanup = onCleanup;
1448
+ exports.reconcile = reconcile;
1449
+ exports.runWithOwner = runWithOwner;
1450
+ exports.setContext = setContext;
1451
+ exports.untrack = untrack;
1452
+ exports.unwrap = unwrap;