@farm.js/react 0.1.0-beta.8 → 0.1.0-beta.9

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.
@@ -25,6 +25,9 @@ function materializeIterable(source) {
25
25
  }
26
26
 
27
27
  // src/compiler-runtime.tsx
28
+ function reversedCompilerKeyedArrayOrder(order) {
29
+ return order === 0 /* Reverse */ ? void 0 : order ?? 0 /* Reverse */;
30
+ }
28
31
  var COMPILER_KEYED_COLLECTION_TOKENS = /* @__PURE__ */ new WeakMap();
29
32
  var COMPILER_KEYED_MAP_UPDATES = /* @__PURE__ */ new WeakMap();
30
33
  var COMPILER_KEYED_ARRAY_APPENDS = /* @__PURE__ */ new WeakMap();
@@ -38,9 +41,11 @@ var COMPILER_KEYED_ARRAY_REORDERS = /* @__PURE__ */ new WeakMap();
38
41
  var COMPILER_KEYED_COLLECTION_DRAFTS = /* @__PURE__ */ new WeakMap();
39
42
  var COMPILER_KEYED_COLLECTION_UPDATES = /* @__PURE__ */ new WeakMap();
40
43
  var COMPILER_KEYED_COMMITTED_COLLECTIONS = /* @__PURE__ */ new WeakSet();
44
+ var COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS = /* @__PURE__ */ new WeakMap();
41
45
  var NATIVE_ARRAY_PROTOTYPE = Array.prototype;
42
46
  var NATIVE_ARRAY_ITERATOR = Array.prototype[Symbol.iterator];
43
47
  var NATIVE_ARRAY_FILTER = Array.prototype.filter;
48
+ var NATIVE_ARRAY_MAP = Array.prototype.map;
44
49
  var NATIVE_ARRAY_SLICE = Array.prototype.slice;
45
50
  var NATIVE_ARRAY_TO_SPLICED = Array.prototype.toSpliced;
46
51
  var NATIVE_ARRAY_WITH = Array.prototype.with;
@@ -66,6 +71,26 @@ function commitCompilerKeyedCollection(value) {
66
71
  COMPILER_KEYED_COMMITTED_COLLECTIONS.add(target);
67
72
  return compilerKeyedCollectionToken(target);
68
73
  }
74
+ function commitCompilerKeyedCollectionWithItemSnapshot(value, instances) {
75
+ const token = commitCompilerKeyedCollection(value);
76
+ if (!token) return void 0;
77
+ if (!instances) {
78
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.delete(token);
79
+ return token;
80
+ }
81
+ const items = [];
82
+ let index = 0;
83
+ for (const instance of instances.values()) {
84
+ if (instance.index !== index) {
85
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.delete(token);
86
+ return token;
87
+ }
88
+ items.push(instance.item);
89
+ index += 1;
90
+ }
91
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.set(token, items);
92
+ return token;
93
+ }
69
94
  function compilerKeyedMapChangedIndices(value, sourceToken) {
70
95
  const target = compilerObject(value);
71
96
  if (!target || !sourceToken) return void 0;
@@ -95,11 +120,52 @@ function compilerKeyedArrayAppendStart(value, sourceToken, expectedStart) {
95
120
  }
96
121
  return length === value.length ? expectedStart : void 0;
97
122
  }
123
+ function compilerKeyedArrayStructuralAppendUpdate(value, sourceToken, expectedStart) {
124
+ const target = compilerObject(value);
125
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
126
+ const update = COMPILER_KEYED_ARRAY_APPENDS.get(target);
127
+ if (!update || update.sourceToken !== sourceToken) return void 0;
128
+ const updates = [];
129
+ for (let current = update; current; current = current.previous) {
130
+ if (current.sourceToken !== sourceToken) return void 0;
131
+ updates.push(current);
132
+ }
133
+ updates.reverse();
134
+ const structuralUpdate = update.structuralUpdate;
135
+ const first = updates[0];
136
+ const survivorResult = structuralUpdate ? compilerKeyedArrayFilterSurvivorsFromUpdate(
137
+ structuralUpdate,
138
+ sourceToken,
139
+ expectedStart,
140
+ first.startIndex
141
+ ) : void 0;
142
+ if (structuralUpdate && !survivorResult) return void 0;
143
+ let length = structuralUpdate ? first.startIndex : expectedStart;
144
+ const startIndex = length;
145
+ for (const current of updates) {
146
+ if (current.startIndex !== length || current.resultLength < length) return void 0;
147
+ length = current.resultLength;
148
+ }
149
+ return length === value.length ? {
150
+ startIndex,
151
+ structuralUpdate,
152
+ ...survivorResult ? { structuralSurvivors: survivorResult } : {}
153
+ } : void 0;
154
+ }
98
155
  function compilerKeyedArrayFilterSurvivors(value, sourceToken, expectedLength) {
99
156
  const target = compilerObject(value);
100
157
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
101
158
  const update = COMPILER_KEYED_ARRAY_FILTERS.get(target);
102
159
  if (!update || update.sourceToken !== sourceToken) return void 0;
160
+ return compilerKeyedArrayFilterSurvivorsFromUpdate(
161
+ update,
162
+ sourceToken,
163
+ expectedLength,
164
+ value.length
165
+ );
166
+ }
167
+ function compilerKeyedArrayFilterSurvivorsFromUpdate(update, sourceToken, expectedLength, resultLength) {
168
+ if (!sourceToken || update.sourceToken !== sourceToken) return void 0;
103
169
  const updates = [];
104
170
  for (let current = update; current; current = current.previous) {
105
171
  if (current.sourceToken !== sourceToken) return void 0;
@@ -129,7 +195,80 @@ function compilerKeyedArrayFilterSurvivors(value, sourceToken, expectedLength) {
129
195
  if (current.resultLength !== current.sourceLength - removed.size) return void 0;
130
196
  survivors = survivors.filter((_sourceIndex, index) => !removed.has(index));
131
197
  }
132
- return survivors.length === value.length ? { indices: survivors, keysStable } : void 0;
198
+ return survivors.length === resultLength ? { indices: survivors, keysStable } : void 0;
199
+ }
200
+ function compilerKeyedArraySliceSurvivorRangeFromUpdate(update, sourceToken, expectedLength, resultLength) {
201
+ if (!sourceToken || update.sourceToken !== sourceToken) return void 0;
202
+ const updates = [];
203
+ for (let current = update; current; current = current.previous) {
204
+ if (current.sourceToken !== sourceToken || current.kind !== "slice") return void 0;
205
+ updates.push(current);
206
+ }
207
+ let length = expectedLength;
208
+ let start = 0;
209
+ for (let index = updates.length - 1; index >= 0; index -= 1) {
210
+ const current = updates[index];
211
+ const retainedStart = current.retainedStart;
212
+ const retainedEnd = current.retainedEnd;
213
+ if (current.sourceLength !== length || retainedStart === void 0 || retainedEnd === void 0 || !Number.isSafeInteger(retainedStart) || !Number.isSafeInteger(retainedEnd) || retainedStart < 0 || retainedEnd < retainedStart || retainedEnd > current.sourceLength || current.resultLength !== retainedEnd - retainedStart) {
214
+ return void 0;
215
+ }
216
+ start += retainedStart;
217
+ length = current.resultLength;
218
+ }
219
+ return length === resultLength ? { end: start + length, start } : void 0;
220
+ }
221
+ function compilerKeyedArrayStructuralAppendMapUpdate(value, sourceToken, expectedStart, requireMappedUpdate = false) {
222
+ const target = compilerObject(value);
223
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
224
+ const update = COMPILER_KEYED_ARRAY_APPENDS.get(target);
225
+ if (!update || update.sourceToken !== sourceToken || !update.structuralUpdate || requireMappedUpdate && !update.mappedItemSources) {
226
+ return void 0;
227
+ }
228
+ const updates = [];
229
+ for (let current = update; current; current = current.previous) {
230
+ if (current.sourceToken !== sourceToken) return void 0;
231
+ updates.push(current);
232
+ }
233
+ updates.reverse();
234
+ const first = updates[0];
235
+ const structuralSurvivorRange = compilerKeyedArraySliceSurvivorRangeFromUpdate(
236
+ update.structuralUpdate,
237
+ sourceToken,
238
+ expectedStart,
239
+ first.startIndex
240
+ );
241
+ const structuralSurvivors = structuralSurvivorRange ? void 0 : compilerKeyedArrayFilterSurvivorsFromUpdate(
242
+ update.structuralUpdate,
243
+ sourceToken,
244
+ expectedStart,
245
+ first.startIndex
246
+ )?.indices;
247
+ if (!structuralSurvivorRange && !structuralSurvivors) return void 0;
248
+ let length = first.startIndex;
249
+ const startIndex = length;
250
+ for (const current of updates) {
251
+ if (current.startIndex !== length || current.resultLength < length) return void 0;
252
+ length = current.resultLength;
253
+ }
254
+ return length === value.length ? {
255
+ startIndex,
256
+ ...structuralSurvivorRange ? { structuralSurvivorRange } : {},
257
+ ...structuralSurvivors ? { structuralSurvivors } : {},
258
+ ...update.mappedItemSources ? { mappedItemSources: update.mappedItemSources } : {},
259
+ ...update.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {}
260
+ } : void 0;
261
+ }
262
+ function compilerKeyedArrayFilterSource(update, resultLength) {
263
+ if (update.resultLength !== resultLength) return void 0;
264
+ let current = update;
265
+ while (current.previous) {
266
+ if (current.sourceToken !== current.previous.sourceToken || current.sourceLength !== current.previous.resultLength) {
267
+ return void 0;
268
+ }
269
+ current = current.previous;
270
+ }
271
+ return { sourceLength: current.sourceLength, sourceToken: current.sourceToken };
133
272
  }
134
273
  function compilerKeyedArrayPrependLength(value, sourceToken, expectedLength) {
135
274
  const target = compilerObject(value);
@@ -153,14 +292,104 @@ function compilerKeyedArrayPrependLength(value, sourceToken, expectedLength) {
153
292
  }
154
293
  return length === value.length ? prefixLength : void 0;
155
294
  }
156
- function compilerKeyedArrayRollingWindow(value, sourceToken, expectedLength) {
295
+ function compilerKeyedArrayStructuralPrependUpdate(value, sourceToken, expectedLength) {
157
296
  const target = compilerObject(value);
158
297
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
159
- const update = COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(target);
160
- if (!update || update.sourceToken !== sourceToken || update.sourceLength !== expectedLength || update.resultLength !== value.length || update.retainedStart < 1 || update.retainedEnd !== update.sourceLength || update.resultLength <= update.retainedEnd - update.retainedStart) {
298
+ const update = COMPILER_KEYED_ARRAY_PREPENDS.get(target);
299
+ if (!update || update.sourceToken !== sourceToken) return void 0;
300
+ const updates = [];
301
+ for (let current = update; current; current = current.previous) {
302
+ if (current.sourceToken !== sourceToken) return void 0;
303
+ updates.push(current);
304
+ }
305
+ updates.reverse();
306
+ const structuralUpdate = update.structuralUpdate;
307
+ const first = updates[0];
308
+ const survivorResult = structuralUpdate ? compilerKeyedArrayFilterSurvivorsFromUpdate(
309
+ structuralUpdate,
310
+ sourceToken,
311
+ expectedLength,
312
+ first.sourceLength
313
+ ) : void 0;
314
+ if (structuralUpdate && !survivorResult) return void 0;
315
+ let length = structuralUpdate ? first.sourceLength : expectedLength;
316
+ let prefixLength = 0;
317
+ for (const current of updates) {
318
+ if (current.sourceLength !== length || current.prefixLength < 1 || current.resultLength !== current.sourceLength + current.prefixLength) {
319
+ return void 0;
320
+ }
321
+ length = current.resultLength;
322
+ prefixLength += current.prefixLength;
323
+ }
324
+ return length === value.length ? {
325
+ prefixLength,
326
+ structuralUpdate,
327
+ ...survivorResult ? { structuralSurvivors: survivorResult } : {}
328
+ } : void 0;
329
+ }
330
+ function compilerKeyedArrayStructuralPrependMapUpdate(value, sourceToken, expectedLength, requireMappedUpdate = false) {
331
+ const target = compilerObject(value);
332
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
333
+ const update = COMPILER_KEYED_ARRAY_PREPENDS.get(target);
334
+ if (!update || update.sourceToken !== sourceToken || !update.structuralUpdate || requireMappedUpdate && !update.mappedItemSources) {
161
335
  return void 0;
162
336
  }
163
- return update;
337
+ const updates = [];
338
+ for (let current = update; current; current = current.previous) {
339
+ if (current.sourceToken !== sourceToken) return void 0;
340
+ updates.push(current);
341
+ }
342
+ updates.reverse();
343
+ const first = updates[0];
344
+ const structuralSurvivorRange = compilerKeyedArraySliceSurvivorRangeFromUpdate(
345
+ update.structuralUpdate,
346
+ sourceToken,
347
+ expectedLength,
348
+ first.sourceLength
349
+ );
350
+ const structuralSurvivors = structuralSurvivorRange ? void 0 : compilerKeyedArrayFilterSurvivorsFromUpdate(
351
+ update.structuralUpdate,
352
+ sourceToken,
353
+ expectedLength,
354
+ first.sourceLength
355
+ )?.indices;
356
+ if (!structuralSurvivorRange && !structuralSurvivors) return void 0;
357
+ let length = first.sourceLength;
358
+ let prefixLength = 0;
359
+ for (const current of updates) {
360
+ if (current.sourceLength !== length || current.prefixLength < 1 || current.resultLength !== current.sourceLength + current.prefixLength) {
361
+ return void 0;
362
+ }
363
+ length = current.resultLength;
364
+ prefixLength += current.prefixLength;
365
+ }
366
+ return length === value.length ? {
367
+ prefixLength,
368
+ ...structuralSurvivorRange ? { structuralSurvivorRange } : {},
369
+ ...structuralSurvivors ? { structuralSurvivors } : {},
370
+ ...update.mappedItemSources ? { mappedItemSources: update.mappedItemSources } : {},
371
+ ...update.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {}
372
+ } : void 0;
373
+ }
374
+ function compilerKeyedArrayRollingWindows(value, sourceToken, expectedLength) {
375
+ const target = compilerObject(value);
376
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
377
+ const update = COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(target);
378
+ if (!update || update.sourceToken !== sourceToken) return void 0;
379
+ const updates = [];
380
+ for (let current = update; current; current = current.previous) {
381
+ if (current.sourceToken !== sourceToken) return void 0;
382
+ updates.push(current);
383
+ }
384
+ updates.reverse();
385
+ let length = expectedLength;
386
+ for (const current of updates) {
387
+ if (current.sourceLength !== length || current.retainedStart < 1 || current.retainedStart > current.sourceLength || current.retainedEnd !== current.sourceLength || current.resultLength <= current.retainedEnd - current.retainedStart) {
388
+ return void 0;
389
+ }
390
+ length = current.resultLength;
391
+ }
392
+ return length === value.length ? updates : void 0;
164
393
  }
165
394
  function compilerKeyedArrayPosition(value, sourceToken, expectedLength) {
166
395
  const target = compilerObject(value);
@@ -204,7 +433,7 @@ function compilerKeyedArrayReorder(value, sourceToken, expectedLength) {
204
433
  const target = compilerObject(value);
205
434
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
206
435
  const update = COMPILER_KEYED_ARRAY_REORDERS.get(target);
207
- if (!update || update.sourceToken !== sourceToken || update.sourceLength !== expectedLength || update.resultLength !== expectedLength || update.resultLength !== value.length) {
436
+ if (!update || update.sourceToken !== sourceToken || update.sourceLength !== expectedLength || !update.structuralUpdate && update.resultLength !== expectedLength || update.resultLength !== value.length) {
208
437
  return void 0;
209
438
  }
210
439
  return update;
@@ -221,7 +450,7 @@ function compilerKeyedCollectionChangedKeys(value, sourceToken, kind) {
221
450
  }
222
451
  return changedKeys;
223
452
  }
224
- function createCompilerKeyedMapUpdate(previous, value, changedIndices) {
453
+ function recordCompilerKeyedMapUpdate(previous, value, changedIndices) {
225
454
  const previousTarget = compilerObject(previous);
226
455
  const valueTarget = compilerObject(value);
227
456
  const sourceToken = compilerKeyedCollectionToken(previousTarget);
@@ -235,6 +464,212 @@ function createCompilerKeyedMapUpdate(previous, value, changedIndices) {
235
464
  }
236
465
  return value;
237
466
  }
467
+ function executeCompilerKeyedMapPipeline(previous, pipeline, record) {
468
+ let eligible = true;
469
+ const applyMap = (collection, method, callback) => {
470
+ const value2 = NATIVE_REFLECT_APPLY(
471
+ method,
472
+ collection,
473
+ [callback]
474
+ );
475
+ if (method !== NATIVE_ARRAY_MAP) {
476
+ eligible = false;
477
+ return value2;
478
+ }
479
+ try {
480
+ if (!Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE) {
481
+ eligible = false;
482
+ }
483
+ } catch {
484
+ eligible = false;
485
+ }
486
+ return value2;
487
+ };
488
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
489
+ return eligible ? record(previous, value) : value;
490
+ }
491
+ function recordCompilerKeyedMapPipelineUpdate(previous, value) {
492
+ try {
493
+ if (!Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== previous.length) {
494
+ return value;
495
+ }
496
+ const finalChangedIndices = [];
497
+ for (let index = 0; index < previous.length; index += 1) {
498
+ const previousDescriptor = Object.getOwnPropertyDescriptor(previous, index);
499
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
500
+ if (!previousDescriptor || !("value" in previousDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
501
+ return value;
502
+ }
503
+ if (mappedDescriptor.value !== previousDescriptor.value) finalChangedIndices.push(index);
504
+ }
505
+ return recordCompilerKeyedMapUpdate(previous, value, finalChangedIndices);
506
+ } catch {
507
+ return value;
508
+ }
509
+ }
510
+ function createCompilerKeyedMapUpdate(previous, valueOrPipeline, changedIndices) {
511
+ if (Array.isArray(changedIndices)) {
512
+ return recordCompilerKeyedMapUpdate(previous, valueOrPipeline, changedIndices);
513
+ }
514
+ if (changedIndices !== void 0 || typeof valueOrPipeline !== "function") {
515
+ return valueOrPipeline;
516
+ }
517
+ return executeCompilerKeyedMapPipeline(
518
+ previous,
519
+ valueOrPipeline,
520
+ recordCompilerKeyedMapPipelineUpdate
521
+ );
522
+ }
523
+ function recordCompilerKeyedArrayMapPipeline(previous, value) {
524
+ try {
525
+ const previousTarget = compilerObject(previous);
526
+ const valueTarget = compilerObject(value);
527
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== previous.length) {
528
+ return value;
529
+ }
530
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
531
+ const previousReorder = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
532
+ const structuralUpdate = previousReorder?.structuralUpdate || (!previousReorder ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0);
533
+ const structuralSource = structuralUpdate ? compilerKeyedArrayFilterSource(structuralUpdate, previous.length) : void 0;
534
+ const previousSource = previousReorder && !previousReorder.structuralUpdate ? previousReorder : void 0;
535
+ if (!committedSource && (!previousSource || previousSource.resultLength !== previous.length) && !structuralSource) {
536
+ return value;
537
+ }
538
+ const sourceToken = previousSource?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
539
+ if (!sourceToken) return value;
540
+ const previousMappedItemSources = previousReorder?.mappedItemSources || structuralUpdate?.mappedItemSources;
541
+ const mappedItemSources = /* @__PURE__ */ new Map();
542
+ for (let index = 0; index < value.length; index += 1) {
543
+ const previousDescriptor = Object.getOwnPropertyDescriptor(previous, index);
544
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
545
+ if (!previousDescriptor || !("value" in previousDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
546
+ return value;
547
+ }
548
+ const previousItem = previousDescriptor.value;
549
+ const sourceItem = previousMappedItemSources?.has(previousItem) ? previousMappedItemSources.get(previousItem) : previousItem;
550
+ const mappedItem = mappedDescriptor.value;
551
+ if (!Object.is(mappedItem, sourceItem)) mappedItemSources.set(mappedItem, sourceItem);
552
+ }
553
+ const hint = {
554
+ kind: committedSource ? void 0 : previousReorder?.kind,
555
+ sourceToken,
556
+ sourceLength: previousSource?.sourceLength ?? structuralSource?.sourceLength ?? previous.length,
557
+ resultLength: value.length,
558
+ mapped: true,
559
+ mappedItemSources,
560
+ ...structuralUpdate ? { structuralUpdate } : {}
561
+ };
562
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, hint);
563
+ } catch {
564
+ }
565
+ return value;
566
+ }
567
+ function createCompilerKeyedArrayMapPipeline(previous, methodOrPipeline, callback) {
568
+ if (callback !== void 0) {
569
+ const value = NATIVE_REFLECT_APPLY(
570
+ methodOrPipeline,
571
+ previous,
572
+ [callback]
573
+ );
574
+ if (methodOrPipeline !== NATIVE_ARRAY_MAP) return value;
575
+ return recordCompilerKeyedArrayMapPipeline(previous, value);
576
+ }
577
+ return executeCompilerKeyedMapPipeline(
578
+ previous,
579
+ methodOrPipeline,
580
+ recordCompilerKeyedArrayMapPipeline
581
+ );
582
+ }
583
+ function recordCompilerKeyedArrayQueuedMapPipeline(previous, value) {
584
+ try {
585
+ const previousTarget = compilerObject(previous);
586
+ const valueTarget = compilerObject(value);
587
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== previous.length) {
588
+ return value;
589
+ }
590
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
591
+ const previousReorder = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
592
+ if (!committedSource && (!previousReorder || previousReorder.structuralUpdate || previousReorder.resultLength !== previous.length)) {
593
+ return value;
594
+ }
595
+ const sourceToken = previousReorder?.sourceToken || compilerKeyedCollectionToken(previousTarget);
596
+ if (!sourceToken) return value;
597
+ const sourceItems = previousReorder?.mappedItemSources?.queuedSourceItems || previous;
598
+ let mappedItemSources;
599
+ const readMappedItemSources = () => {
600
+ if (mappedItemSources) return mappedItemSources;
601
+ const sources = /* @__PURE__ */ new Map();
602
+ for (let index = 0; index < value.length; index += 1) {
603
+ const sourceDescriptor = Object.getOwnPropertyDescriptor(sourceItems, index);
604
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
605
+ if (!sourceDescriptor || !("value" in sourceDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
606
+ throw new TypeError();
607
+ }
608
+ if (!Object.is(sourceDescriptor.value, mappedDescriptor.value)) {
609
+ sources.set(mappedDescriptor.value, sourceDescriptor.value);
610
+ }
611
+ }
612
+ mappedItemSources = sources;
613
+ return sources;
614
+ };
615
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
616
+ kind: previousReorder?.kind,
617
+ sourceToken,
618
+ sourceLength: previousReorder?.sourceLength ?? previous.length,
619
+ resultLength: value.length,
620
+ mapped: true,
621
+ // Array.map preserves positions. Retain the first queued source collection and validate its
622
+ // data properties against the final collection once, immediately before the DOM commit.
623
+ // This avoids rescanning every intermediate Array produced by separately queued setters.
624
+ mappedItemSources: {
625
+ queuedSourceItems: sourceItems,
626
+ get: (item) => readMappedItemSources().get(item),
627
+ has: (item) => readMappedItemSources().has(item)
628
+ }
629
+ });
630
+ } catch {
631
+ }
632
+ return value;
633
+ }
634
+ function createCompilerKeyedArrayQueuedMapPipeline(previous, pipeline) {
635
+ return executeCompilerKeyedMapPipeline(
636
+ previous,
637
+ pipeline,
638
+ recordCompilerKeyedArrayQueuedMapPipeline
639
+ );
640
+ }
641
+ function createCompilerKeyedArrayMapReorder(previous, method, ...args) {
642
+ const value = NATIVE_REFLECT_APPLY(
643
+ method,
644
+ previous,
645
+ args
646
+ );
647
+ try {
648
+ const previousTarget = compilerObject(previous);
649
+ const valueTarget = compilerObject(value);
650
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== previous.length || method !== NATIVE_ARRAY_TO_REVERSED && method !== NATIVE_ARRAY_TO_SORTED || method === NATIVE_ARRAY_TO_REVERSED && args.length !== 0 || method === NATIVE_ARRAY_TO_SORTED && (args.length > 1 || args.length === 1 && args[0] !== void 0 && typeof args[0] !== "function")) {
651
+ return value;
652
+ }
653
+ for (let index = 0; index < previous.length; index += 1) {
654
+ if (!Object.prototype.hasOwnProperty.call(previous, index) || !Object.prototype.hasOwnProperty.call(value, index)) {
655
+ return value;
656
+ }
657
+ }
658
+ const previousReorder = COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
659
+ const source = previousReorder?.mapped ? previousReorder : void 0;
660
+ if (!source || source.resultLength !== previous.length) return value;
661
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
662
+ kind: method !== NATIVE_ARRAY_TO_REVERSED ? 1 /* Permutation */ : reversedCompilerKeyedArrayOrder(source.kind),
663
+ sourceToken: source.sourceToken,
664
+ sourceLength: source.sourceLength,
665
+ resultLength: value.length,
666
+ mapped: true,
667
+ mappedItemSources: source.mappedItemSources
668
+ });
669
+ } catch {
670
+ }
671
+ return value;
672
+ }
238
673
  function createCompilerKeyedArrayAppend(previous, value) {
239
674
  try {
240
675
  const previousTarget = compilerObject(previous);
@@ -258,6 +693,187 @@ function createCompilerKeyedArrayAppend(previous, value) {
258
693
  return value;
259
694
  }
260
695
  }
696
+ function createCompilerKeyedArrayStructuralAppend(previous, value) {
697
+ try {
698
+ const previousTarget = compilerObject(previous);
699
+ const valueTarget = compilerObject(value);
700
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || previous[Symbol.iterator] !== NATIVE_ARRAY_ITERATOR) {
701
+ return value;
702
+ }
703
+ const startIndex = previous.length;
704
+ if (value.length < startIndex) return value;
705
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
706
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget);
707
+ const directStructuralUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
708
+ const structuralSource = directStructuralUpdate ? compilerKeyedArrayFilterSource(directStructuralUpdate, previous.length) : void 0;
709
+ const structuralUpdate = previousUpdate?.structuralUpdate || (structuralSource ? directStructuralUpdate : void 0);
710
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
711
+ if (!sourceToken) return value;
712
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
713
+ sourceToken,
714
+ startIndex,
715
+ resultLength: value.length,
716
+ ...structuralUpdate ? { structuralUpdate } : {},
717
+ ...previousUpdate ? { previous: previousUpdate } : {}
718
+ });
719
+ return value;
720
+ } catch {
721
+ return value;
722
+ }
723
+ }
724
+ function createCompilerKeyedArrayMappedStructuralAppend(previous, value) {
725
+ try {
726
+ const previousTarget = compilerObject(previous);
727
+ const valueTarget = compilerObject(value);
728
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || previous[Symbol.iterator] !== NATIVE_ARRAY_ITERATOR) {
729
+ return value;
730
+ }
731
+ const startIndex = previous.length;
732
+ if (value.length < startIndex) return value;
733
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
734
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget);
735
+ const previousMappedUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget) : void 0;
736
+ const mappedStructuralUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.structuralUpdate && previousMappedUpdate.resultLength === previous.length ? previousMappedUpdate : void 0;
737
+ const structuralUpdate = previousUpdate?.structuralUpdate || mappedStructuralUpdate?.structuralUpdate;
738
+ const sourceToken = previousUpdate?.sourceToken || mappedStructuralUpdate?.sourceToken;
739
+ const mappedItemSources = previousUpdate?.mappedItemSources || mappedStructuralUpdate?.mappedItemSources;
740
+ if (!sourceToken || !structuralUpdate || !mappedItemSources) return value;
741
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
742
+ sourceToken,
743
+ startIndex,
744
+ resultLength: value.length,
745
+ structuralUpdate,
746
+ mappedItemSources,
747
+ ...previousUpdate?.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {},
748
+ ...previousUpdate?.mappedItemValues ? { mappedItemValues: previousUpdate.mappedItemValues } : {},
749
+ ...previousUpdate ? { previous: previousUpdate } : {}
750
+ });
751
+ return value;
752
+ } catch {
753
+ return value;
754
+ }
755
+ }
756
+ function createCompilerKeyedArrayStructuralAppendMapPipeline(previous, pipeline) {
757
+ let appendUpdate;
758
+ let committedItems;
759
+ let survivorRange;
760
+ let survivorIndices;
761
+ let mappedItemSources = /* @__PURE__ */ new Map();
762
+ let mappedItemValues = /* @__PURE__ */ new Map();
763
+ try {
764
+ const previousTarget = compilerObject(previous);
765
+ if (!previousTarget || !Array.isArray(previous) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || !(appendUpdate = COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget)) || !appendUpdate.structuralUpdate || appendUpdate.resultLength !== previous.length) {
766
+ appendUpdate = void 0;
767
+ } else {
768
+ committedItems = COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.get(appendUpdate.sourceToken);
769
+ const structuralAppend = committedItems ? compilerKeyedArrayStructuralAppendMapUpdate(
770
+ previous,
771
+ appendUpdate.sourceToken,
772
+ committedItems.length
773
+ ) : void 0;
774
+ survivorRange = structuralAppend?.structuralSurvivorRange;
775
+ survivorIndices = structuralAppend?.structuralSurvivors;
776
+ if (!survivorRange && !survivorIndices) {
777
+ appendUpdate = void 0;
778
+ } else {
779
+ if (appendUpdate.mappedSurvivorsValidated && appendUpdate.mappedItemSources) {
780
+ mappedItemSources = new Map(
781
+ appendUpdate.mappedItemSources
782
+ );
783
+ }
784
+ if (appendUpdate.mappedItemValues) {
785
+ mappedItemValues = new Map(appendUpdate.mappedItemValues);
786
+ }
787
+ }
788
+ }
789
+ } catch {
790
+ appendUpdate = void 0;
791
+ }
792
+ let eligible = appendUpdate !== void 0;
793
+ const applyMap = (collection, method, callback) => {
794
+ if (method !== NATIVE_ARRAY_MAP || !eligible) {
795
+ const value3 = NATIVE_REFLECT_APPLY(
796
+ method,
797
+ collection,
798
+ [callback]
799
+ );
800
+ if (method !== NATIVE_ARRAY_MAP) eligible = false;
801
+ return value3;
802
+ }
803
+ let expectedIndex = 0;
804
+ let expectedLength = -1;
805
+ try {
806
+ if (!Array.isArray(collection) || Object.getPrototypeOf(collection) !== NATIVE_ARRAY_PROTOTYPE) {
807
+ eligible = false;
808
+ } else {
809
+ expectedLength = collection.length;
810
+ }
811
+ } catch {
812
+ eligible = false;
813
+ }
814
+ const wrappedCallback = (item, index, source) => {
815
+ if (index !== expectedIndex) eligible = false;
816
+ expectedIndex = index + 1;
817
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
818
+ let committedItem;
819
+ if (index < survivorCount) {
820
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices?.[index];
821
+ committedItem = sourceIndex === void 0 ? void 0 : committedItems?.[sourceIndex];
822
+ if (mappedItemValues.has(index)) {
823
+ if (!Object.is(item, mappedItemValues.get(index))) eligible = false;
824
+ } else if (appendUpdate?.mappedItemSources && !appendUpdate.mappedSurvivorsValidated) {
825
+ const mappedStructuralSources = appendUpdate.mappedItemSources;
826
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
827
+ if (!Object.is(sourceItem, committedItem)) eligible = false;
828
+ } else if (!Object.is(item, committedItem)) {
829
+ eligible = false;
830
+ }
831
+ }
832
+ const mappedItem = NATIVE_REFLECT_APPLY(
833
+ callback,
834
+ void 0,
835
+ [item, index, source]
836
+ );
837
+ if (index < survivorCount) {
838
+ if (Object.is(mappedItem, committedItem)) {
839
+ mappedItemSources.delete(index);
840
+ mappedItemValues.delete(index);
841
+ } else {
842
+ mappedItemSources.set(index, committedItem);
843
+ mappedItemValues.set(index, mappedItem);
844
+ }
845
+ }
846
+ return mappedItem;
847
+ };
848
+ const value2 = NATIVE_REFLECT_APPLY(
849
+ method,
850
+ collection,
851
+ [wrappedCallback]
852
+ );
853
+ try {
854
+ if (expectedIndex !== expectedLength || !Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE || value2.length !== expectedLength) {
855
+ eligible = false;
856
+ }
857
+ } catch {
858
+ eligible = false;
859
+ }
860
+ return value2;
861
+ };
862
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
863
+ if (!eligible || !appendUpdate) return value;
864
+ try {
865
+ const valueTarget = compilerObject(value);
866
+ if (!valueTarget) return value;
867
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
868
+ ...appendUpdate,
869
+ mappedItemSources,
870
+ mappedItemValues,
871
+ mappedSurvivorsValidated: true
872
+ });
873
+ } catch {
874
+ }
875
+ return value;
876
+ }
261
877
  function createCompilerKeyedArrayPrepend(previous, value) {
262
878
  try {
263
879
  const previousTarget = compilerObject(previous);
@@ -265,23 +881,187 @@ function createCompilerKeyedArrayPrepend(previous, value) {
265
881
  if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || previous[Symbol.iterator] !== NATIVE_ARRAY_ITERATOR) {
266
882
  return value;
267
883
  }
268
- const sourceLength = previous.length;
269
- const prefixLength = value.length - sourceLength;
270
- if (prefixLength < 1) return value;
271
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
272
- if (!sourceToken) return value;
273
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget) : void 0;
884
+ const sourceLength = previous.length;
885
+ const prefixLength = value.length - sourceLength;
886
+ if (prefixLength < 1) return value;
887
+ const sourceToken = compilerKeyedCollectionToken(previousTarget);
888
+ if (!sourceToken) return value;
889
+ const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget) : void 0;
890
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
891
+ sourceToken: previousUpdate?.sourceToken || sourceToken,
892
+ sourceLength,
893
+ resultLength: value.length,
894
+ prefixLength,
895
+ ...previousUpdate ? { previous: previousUpdate } : {}
896
+ });
897
+ return value;
898
+ } catch {
899
+ return value;
900
+ }
901
+ }
902
+ function createCompilerKeyedArrayStructuralPrepend(previous, value) {
903
+ try {
904
+ const previousTarget = compilerObject(previous);
905
+ const valueTarget = compilerObject(value);
906
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || previous[Symbol.iterator] !== NATIVE_ARRAY_ITERATOR) {
907
+ return value;
908
+ }
909
+ const sourceLength = previous.length;
910
+ const prefixLength = value.length - sourceLength;
911
+ if (prefixLength < 1) return value;
912
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
913
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget);
914
+ const directStructuralUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
915
+ const structuralSource = directStructuralUpdate ? compilerKeyedArrayFilterSource(directStructuralUpdate, previous.length) : void 0;
916
+ const structuralUpdate = previousUpdate?.structuralUpdate || (structuralSource ? directStructuralUpdate : void 0);
917
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
918
+ if (!sourceToken) return value;
919
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
920
+ sourceToken,
921
+ sourceLength,
922
+ resultLength: value.length,
923
+ prefixLength,
924
+ ...structuralUpdate ? { structuralUpdate } : {},
925
+ ...previousUpdate ? { previous: previousUpdate } : {}
926
+ });
927
+ return value;
928
+ } catch {
929
+ return value;
930
+ }
931
+ }
932
+ function createCompilerKeyedArrayMappedStructuralPrepend(previous, value) {
933
+ try {
934
+ const previousTarget = compilerObject(previous);
935
+ const valueTarget = compilerObject(value);
936
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || previous[Symbol.iterator] !== NATIVE_ARRAY_ITERATOR) {
937
+ return value;
938
+ }
939
+ const sourceLength = previous.length;
940
+ const prefixLength = value.length - sourceLength;
941
+ if (prefixLength < 1) return value;
942
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
943
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget);
944
+ const previousMappedUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget) : void 0;
945
+ const mappedStructuralUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.structuralUpdate && previousMappedUpdate.resultLength === previous.length ? previousMappedUpdate : void 0;
946
+ const structuralUpdate = previousUpdate?.structuralUpdate || mappedStructuralUpdate?.structuralUpdate;
947
+ const sourceToken = previousUpdate?.sourceToken || mappedStructuralUpdate?.sourceToken;
948
+ const mappedItemSources = previousUpdate?.mappedItemSources || mappedStructuralUpdate?.mappedItemSources;
949
+ if (!sourceToken || !structuralUpdate || !mappedItemSources) return value;
950
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
951
+ sourceToken,
952
+ sourceLength,
953
+ resultLength: value.length,
954
+ prefixLength,
955
+ structuralUpdate,
956
+ mappedItemSources,
957
+ ...previousUpdate?.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {},
958
+ ...previousUpdate?.mappedItemValues ? { mappedItemValues: previousUpdate.mappedItemValues } : {},
959
+ ...previousUpdate ? { previous: previousUpdate } : {}
960
+ });
961
+ return value;
962
+ } catch {
963
+ return value;
964
+ }
965
+ }
966
+ function createCompilerKeyedArrayStructuralPrependMapPipeline(previous, pipeline) {
967
+ let prependUpdate;
968
+ let committedItems;
969
+ let survivorRange;
970
+ let survivorIndices;
971
+ let prefixLength = 0;
972
+ try {
973
+ const previousTarget = compilerObject(previous);
974
+ if (!previousTarget || !Array.isArray(previous) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || !(prependUpdate = COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget)) || !prependUpdate.structuralUpdate || prependUpdate.resultLength !== previous.length) {
975
+ prependUpdate = void 0;
976
+ } else {
977
+ committedItems = COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.get(prependUpdate.sourceToken);
978
+ const structuralPrepend = committedItems ? compilerKeyedArrayStructuralPrependMapUpdate(
979
+ previous,
980
+ prependUpdate.sourceToken,
981
+ committedItems.length
982
+ ) : void 0;
983
+ survivorRange = structuralPrepend?.structuralSurvivorRange;
984
+ survivorIndices = structuralPrepend?.structuralSurvivors;
985
+ prefixLength = structuralPrepend?.prefixLength || 0;
986
+ if (!survivorRange && !survivorIndices) {
987
+ prependUpdate = void 0;
988
+ }
989
+ }
990
+ } catch {
991
+ prependUpdate = void 0;
992
+ }
993
+ let eligible = prependUpdate !== void 0;
994
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
995
+ const applyMap = (collection, method, callback) => {
996
+ if (method !== NATIVE_ARRAY_MAP || !eligible) {
997
+ const value3 = NATIVE_REFLECT_APPLY(
998
+ method,
999
+ collection,
1000
+ [callback]
1001
+ );
1002
+ if (method !== NATIVE_ARRAY_MAP) eligible = false;
1003
+ return value3;
1004
+ }
1005
+ let expectedIndex = 0;
1006
+ let expectedLength = -1;
1007
+ try {
1008
+ if (!Array.isArray(collection) || Object.getPrototypeOf(collection) !== NATIVE_ARRAY_PROTOTYPE) {
1009
+ eligible = false;
1010
+ } else {
1011
+ expectedLength = collection.length;
1012
+ }
1013
+ } catch {
1014
+ eligible = false;
1015
+ }
1016
+ const wrappedCallback = (item, index, source) => {
1017
+ if (index !== expectedIndex) eligible = false;
1018
+ expectedIndex = index + 1;
1019
+ return NATIVE_REFLECT_APPLY(
1020
+ callback,
1021
+ void 0,
1022
+ [item, index, source]
1023
+ );
1024
+ };
1025
+ const value2 = NATIVE_REFLECT_APPLY(
1026
+ method,
1027
+ collection,
1028
+ [wrappedCallback]
1029
+ );
1030
+ try {
1031
+ if (expectedIndex !== expectedLength || !Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE || value2.length !== expectedLength) {
1032
+ eligible = false;
1033
+ }
1034
+ } catch {
1035
+ eligible = false;
1036
+ }
1037
+ return value2;
1038
+ };
1039
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
1040
+ if (!eligible || !prependUpdate) return value;
1041
+ try {
1042
+ const valueTarget = compilerObject(value);
1043
+ if (!valueTarget || !Array.isArray(value) || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== prefixLength + survivorCount) {
1044
+ return value;
1045
+ }
1046
+ const mappedItemSources = /* @__PURE__ */ new Map();
1047
+ const mappedItemValues = /* @__PURE__ */ new Map();
1048
+ for (let index = 0; index < survivorCount; index += 1) {
1049
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
1050
+ const committedItem = committedItems[sourceIndex];
1051
+ const mappedItem = value[prefixLength + index];
1052
+ if (Object.is(mappedItem, committedItem)) continue;
1053
+ mappedItemSources.set(index, committedItem);
1054
+ mappedItemValues.set(index, mappedItem);
1055
+ }
274
1056
  COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
275
- sourceToken: previousUpdate?.sourceToken || sourceToken,
276
- sourceLength,
277
- resultLength: value.length,
278
- prefixLength,
279
- ...previousUpdate ? { previous: previousUpdate } : {}
1057
+ ...prependUpdate,
1058
+ mappedItemSources,
1059
+ mappedItemValues,
1060
+ mappedSurvivorsValidated: true
280
1061
  });
281
- return value;
282
1062
  } catch {
283
- return value;
284
1063
  }
1064
+ return value;
285
1065
  }
286
1066
  function createCompilerKeyedArrayFilter(previous, method, predicate) {
287
1067
  let canHint = false;
@@ -316,15 +1096,20 @@ function createCompilerKeyedArrayFilter(previous, method, predicate) {
316
1096
  if (!previousTarget || !valueTarget || !Array.isArray(value) || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || visited !== sourceLength || value.length !== sourceLength - removedIndices.length) {
317
1097
  return value;
318
1098
  }
319
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1099
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1100
+ const previousMappedUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1101
+ const mappedUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.resultLength === sourceLength ? previousMappedUpdate : void 0;
1102
+ const sourceToken = mappedUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
320
1103
  if (!sourceToken) return value;
321
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
1104
+ const previousUpdate = !committedSource ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) || mappedUpdate?.structuralUpdate : void 0;
1105
+ const mappedItemSources = mappedUpdate?.mappedItemSources || previousUpdate?.mappedItemSources;
322
1106
  COMPILER_KEYED_ARRAY_FILTERS.set(valueTarget, {
323
1107
  kind: "filter",
324
1108
  sourceToken: previousUpdate?.sourceToken || sourceToken,
325
1109
  sourceLength,
326
1110
  resultLength: value.length,
327
1111
  removedIndices,
1112
+ ...mappedItemSources ? { mappedItemSources } : {},
328
1113
  ...previousUpdate ? { previous: previousUpdate } : {}
329
1114
  });
330
1115
  } catch {
@@ -353,9 +1138,13 @@ function createCompilerKeyedArraySlice(previous, method, ...args) {
353
1138
  const retainedEnd = args.length === 2 ? normalize(args[1]) : sourceLength;
354
1139
  const resultLength = Math.max(retainedEnd - retainedStart, 0);
355
1140
  if (value.length !== resultLength || resultLength >= sourceLength) return value;
356
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1141
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1142
+ const previousMappedUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1143
+ const mappedUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.resultLength === sourceLength ? previousMappedUpdate : void 0;
1144
+ const sourceToken = mappedUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
357
1145
  if (!sourceToken) return value;
358
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
1146
+ const previousUpdate = !committedSource ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) || mappedUpdate?.structuralUpdate : void 0;
1147
+ const mappedItemSources = mappedUpdate?.mappedItemSources || previousUpdate?.mappedItemSources;
359
1148
  COMPILER_KEYED_ARRAY_FILTERS.set(valueTarget, {
360
1149
  kind: "slice",
361
1150
  sourceToken: previousUpdate?.sourceToken || sourceToken,
@@ -363,23 +1152,48 @@ function createCompilerKeyedArraySlice(previous, method, ...args) {
363
1152
  resultLength,
364
1153
  retainedEnd: Math.max(retainedEnd, retainedStart),
365
1154
  retainedStart,
1155
+ ...mappedItemSources ? { mappedItemSources } : {},
366
1156
  ...previousUpdate ? { previous: previousUpdate } : {}
367
1157
  });
368
1158
  } catch {
369
1159
  }
370
1160
  return value;
371
1161
  }
1162
+ function finalizeCompilerKeyedArrayMappedStructuralUpdate(value) {
1163
+ try {
1164
+ const valueTarget = compilerObject(value);
1165
+ const structuralUpdate = valueTarget ? COMPILER_KEYED_ARRAY_FILTERS.get(valueTarget) : void 0;
1166
+ const mappedItemSources = structuralUpdate?.mappedItemSources;
1167
+ if (!valueTarget || !structuralUpdate || !mappedItemSources) return value;
1168
+ const source = compilerKeyedArrayFilterSource(structuralUpdate, structuralUpdate.resultLength);
1169
+ if (!source) return value;
1170
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
1171
+ sourceToken: source.sourceToken,
1172
+ sourceLength: source.sourceLength,
1173
+ resultLength: structuralUpdate.resultLength,
1174
+ mapped: true,
1175
+ mappedItemSources,
1176
+ structuralUpdate
1177
+ });
1178
+ } catch {
1179
+ }
1180
+ return value;
1181
+ }
372
1182
  function createCompilerKeyedArrayRollingWindow(previous, retained, value) {
373
1183
  try {
374
1184
  const previousTarget = compilerObject(previous);
375
1185
  const retainedTarget = compilerObject(retained);
376
1186
  const valueTarget = compilerObject(value);
377
- if (!previousTarget || !retainedTarget || !valueTarget || !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) || !Array.isArray(previous) || !Array.isArray(retained) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(retained) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE) {
1187
+ if (!previousTarget || !retainedTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(retained) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(retained) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE) {
378
1188
  return value;
379
1189
  }
380
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1190
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1191
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(previousTarget);
1192
+ if (!committedSource && !previousUpdate) return value;
1193
+ const immediateSourceToken = compilerKeyedCollectionToken(previousTarget);
1194
+ const sourceToken = previousUpdate?.sourceToken || immediateSourceToken;
381
1195
  const slice = COMPILER_KEYED_ARRAY_FILTERS.get(retainedTarget);
382
- if (!sourceToken || !slice || slice.previous || slice.kind !== "slice" || slice.sourceToken !== sourceToken || slice.sourceLength !== previous.length || slice.retainedStart === void 0 || slice.retainedEnd !== previous.length || slice.retainedStart < 1 || slice.resultLength !== retained.length || value.length <= retained.length) {
1196
+ if (!immediateSourceToken || !sourceToken || !slice || slice.previous || slice.kind !== "slice" || slice.sourceToken !== immediateSourceToken || slice.sourceLength !== previous.length || slice.retainedStart === void 0 || slice.retainedEnd !== previous.length || slice.retainedStart < 1 || slice.resultLength !== retained.length || previousUpdate && previousUpdate.resultLength !== previous.length || value.length <= retained.length) {
383
1197
  return value;
384
1198
  }
385
1199
  for (let index = 0; index < retained.length; index += 1) {
@@ -390,7 +1204,8 @@ function createCompilerKeyedArrayRollingWindow(previous, retained, value) {
390
1204
  sourceLength: previous.length,
391
1205
  resultLength: value.length,
392
1206
  retainedEnd: slice.retainedEnd,
393
- retainedStart: slice.retainedStart
1207
+ retainedStart: slice.retainedStart,
1208
+ ...previousUpdate ? { previous: previousUpdate } : {}
394
1209
  });
395
1210
  } catch {
396
1211
  }
@@ -504,13 +1319,18 @@ function createCompilerKeyedArrayReorder(previous, method) {
504
1319
  try {
505
1320
  const previousTarget = compilerObject(previous);
506
1321
  const valueTarget = compilerObject(value);
507
- if (!previousTarget || !valueTarget || !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_REVERSED || value.length !== previous.length) {
1322
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_REVERSED || value.length !== previous.length) {
508
1323
  return value;
509
1324
  }
510
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1325
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1326
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1327
+ if (!committedSource && (!previousUpdate || previousUpdate.sourceLength !== previous.length || previousUpdate.resultLength !== previous.length)) {
1328
+ return value;
1329
+ }
1330
+ const sourceToken = previousUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
511
1331
  if (!sourceToken) return value;
512
1332
  COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
513
- kind: "reverse",
1333
+ kind: reversedCompilerKeyedArrayOrder(previousUpdate?.kind),
514
1334
  sourceToken,
515
1335
  sourceLength: previous.length,
516
1336
  resultLength: value.length
@@ -528,16 +1348,21 @@ function createCompilerKeyedArraySort(previous, method, ...args) {
528
1348
  try {
529
1349
  const previousTarget = compilerObject(previous);
530
1350
  const valueTarget = compilerObject(value);
531
- if (!previousTarget || !valueTarget || !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_SORTED || args.length > 1 || args.length === 1 && args[0] !== void 0 && typeof args[0] !== "function" || value.length !== previous.length) {
1351
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_SORTED || args.length > 1 || args.length === 1 && args[0] !== void 0 && typeof args[0] !== "function" || value.length !== previous.length) {
532
1352
  return value;
533
1353
  }
534
1354
  for (let index = 0; index < previous.length; index += 1) {
535
1355
  if (!(index in previous)) return value;
536
1356
  }
537
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1357
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1358
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1359
+ if (!committedSource && (!previousUpdate || previousUpdate.sourceLength !== previous.length || previousUpdate.resultLength !== previous.length)) {
1360
+ return value;
1361
+ }
1362
+ const sourceToken = previousUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
538
1363
  if (!sourceToken) return value;
539
1364
  COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
540
- kind: "sort",
1365
+ kind: 1 /* Permutation */,
541
1366
  sourceToken,
542
1367
  sourceLength: previous.length,
543
1368
  resultLength: value.length
@@ -546,6 +1371,75 @@ function createCompilerKeyedArraySort(previous, method, ...args) {
546
1371
  }
547
1372
  return value;
548
1373
  }
1374
+ function recordCompilerKeyedArrayStructuralReorder(previous, value, kind) {
1375
+ try {
1376
+ const previousTarget = compilerObject(previous);
1377
+ const valueTarget = compilerObject(value);
1378
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value)) {
1379
+ return value;
1380
+ }
1381
+ const previousUpdate = COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1382
+ const structuralUpdate = previousUpdate?.structuralUpdate || (!previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0);
1383
+ const structuralSource = structuralUpdate ? compilerKeyedArrayFilterSource(structuralUpdate, previous.length) : void 0;
1384
+ if (!structuralUpdate || !structuralSource || previousUpdate && previousUpdate.resultLength !== previous.length) {
1385
+ return value;
1386
+ }
1387
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken;
1388
+ if (!sourceToken) return value;
1389
+ const mappedItemSources = previousUpdate?.mappedItemSources || structuralUpdate.mappedItemSources;
1390
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
1391
+ kind: kind === 0 /* Reverse */ ? reversedCompilerKeyedArrayOrder(previousUpdate?.kind) : 1 /* Permutation */,
1392
+ sourceToken,
1393
+ sourceLength: previousUpdate?.sourceLength || structuralSource.sourceLength,
1394
+ resultLength: value.length,
1395
+ structuralUpdate,
1396
+ ...mappedItemSources ? { mappedItemSources } : {}
1397
+ });
1398
+ } catch {
1399
+ }
1400
+ return value;
1401
+ }
1402
+ function createCompilerKeyedArrayStructuralReorder(previous, method) {
1403
+ const value = NATIVE_REFLECT_APPLY(
1404
+ method,
1405
+ previous,
1406
+ []
1407
+ );
1408
+ try {
1409
+ if (!Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_REVERSED || value.length !== previous.length) {
1410
+ return value;
1411
+ }
1412
+ } catch {
1413
+ return value;
1414
+ }
1415
+ return recordCompilerKeyedArrayStructuralReorder(
1416
+ previous,
1417
+ value,
1418
+ 0 /* Reverse */
1419
+ );
1420
+ }
1421
+ function createCompilerKeyedArrayStructuralSort(previous, method, ...args) {
1422
+ const value = NATIVE_REFLECT_APPLY(
1423
+ method,
1424
+ previous,
1425
+ args
1426
+ );
1427
+ try {
1428
+ if (!Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || method !== NATIVE_ARRAY_TO_SORTED || args.length > 1 || args.length === 1 && args[0] !== void 0 && typeof args[0] !== "function" || value.length !== previous.length) {
1429
+ return value;
1430
+ }
1431
+ for (let index = 0; index < previous.length; index += 1) {
1432
+ if (!(index in previous)) return value;
1433
+ }
1434
+ } catch {
1435
+ return value;
1436
+ }
1437
+ return recordCompilerKeyedArrayStructuralReorder(
1438
+ previous,
1439
+ value,
1440
+ 1 /* Permutation */
1441
+ );
1442
+ }
549
1443
  function applyCompilerKeyedCollectionMutation(collection, method, operation, key, value) {
550
1444
  const args = operation === "map-set" ? [key, value] : [key];
551
1445
  const result = NATIVE_REFLECT_APPLY(method, collection, args);
@@ -963,6 +1857,9 @@ function applyStaticRangeBindings(bindings, segments, values) {
963
1857
  }
964
1858
  return true;
965
1859
  }
1860
+ function keyedRowInstancesByKey(instances) {
1861
+ return new Map(instances.map((instance) => [instance.key, instance]));
1862
+ }
966
1863
  var UNSET_KEYED_ROW_BINDING = /* @__PURE__ */ Symbol("unset interactive keyed-row binding");
967
1864
  function keyedRowIdentity(key) {
968
1865
  return String(key);
@@ -1815,7 +2712,7 @@ var CompilerNestedKeyedRanges = class {
1815
2712
  }
1816
2713
  anchor = instance.element;
1817
2714
  }
1818
- this.instances[rangeIndex] = new Map(nextInstances.map((instance) => [instance.key, instance]));
2715
+ this.instances[rangeIndex] = keyedRowInstancesByKey(nextInstances);
1819
2716
  return true;
1820
2717
  }
1821
2718
  updateStaticScopes(descriptor, rowsByRange) {
@@ -2143,7 +3040,7 @@ var CompilerNestedMixedRanges = class {
2143
3040
  }
2144
3041
  anchor = row.element;
2145
3042
  }
2146
- instance.value = new Map(nextInstances.map((row) => [row.key, row]));
3043
+ instance.value = keyedRowInstancesByKey(nextInstances);
2147
3044
  return true;
2148
3045
  }
2149
3046
  reconcileRange(rangeIndex, snapshot) {
@@ -2699,8 +3596,7 @@ function longestIncreasingSubsequencePositions(sequence) {
2699
3596
  return positions;
2700
3597
  }
2701
3598
  function reorderCompilerKeyedRows(root, instances, sequence, anchor) {
2702
- const activeElement = root.ownerDocument.activeElement;
2703
- const restoreFocus = Boolean(activeElement && root.contains(activeElement));
3599
+ const activeElement = compilerFocusedElement(root);
2704
3600
  const stablePositions = longestIncreasingSubsequencePositions(sequence);
2705
3601
  for (let index = instances.length - 1; index >= 0; index -= 1) {
2706
3602
  const instance = instances[index];
@@ -2721,10 +3617,31 @@ function reorderCompilerKeyedRows(root, instances, sequence, anchor) {
2721
3617
  anchor = instance.element;
2722
3618
  }
2723
3619
  }
2724
- if (restoreFocus && activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
3620
+ restoreCompilerFocus(activeElement);
3621
+ }
3622
+ function compilerFocusedElement(root) {
3623
+ const activeElement = root.ownerDocument.activeElement;
3624
+ return activeElement && root.contains(activeElement) ? activeElement : null;
3625
+ }
3626
+ function restoreCompilerFocus(activeElement) {
3627
+ if (activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
2725
3628
  activeElement.focus({ preventScroll: true });
2726
3629
  }
2727
3630
  }
3631
+ function reverseCompilerKeyedRows(root, instances) {
3632
+ const activeElement = compilerFocusedElement(root);
3633
+ let anchor = instances[0]?.element || null;
3634
+ for (let sourceIndex = 1; sourceIndex < instances.length; sourceIndex += 1) {
3635
+ const element = instances[sourceIndex].element;
3636
+ root.insertBefore(element, anchor);
3637
+ anchor = element;
3638
+ }
3639
+ instances.reverse();
3640
+ for (let index = 0; index < instances.length; index += 1) {
3641
+ instances[index].index = index;
3642
+ }
3643
+ restoreCompilerFocus(activeElement);
3644
+ }
2728
3645
  var keyedUpdateRuntime = {
2729
3646
  append: reconcileCompilerKeyedArrayAppend,
2730
3647
  commit: commitCompilerKeyedCollection,
@@ -2742,6 +3659,10 @@ var keyedFilterPrependUpdateRuntime = {
2742
3659
  ...keyedFilterUpdateRuntime,
2743
3660
  prepend: reconcileCompilerKeyedArrayPrepend
2744
3661
  };
3662
+ var keyedStructuralPrependUpdateRuntime = {
3663
+ ...keyedFilterPrependUpdateRuntime,
3664
+ prepend: reconcileCompilerKeyedArrayPrependWithStructural
3665
+ };
2745
3666
  var keyedPositionUpdateRuntime = {
2746
3667
  ...keyedUpdateRuntime,
2747
3668
  position: reconcileCompilerKeyedArrayPosition
@@ -2758,6 +3679,10 @@ var keyedReorderUpdateRuntime = {
2758
3679
  ...keyedUpdateRuntime,
2759
3680
  reorder: reconcileCompilerKeyedArrayReorder
2760
3681
  };
3682
+ var keyedMapReorderUpdateRuntime = {
3683
+ ...keyedUpdateRuntime,
3684
+ reorder: reconcileCompilerKeyedArrayReorderWithMap
3685
+ };
2761
3686
  var keyedCompleteUpdateRuntime = {
2762
3687
  ...keyedFilterPrependUpdateRuntime,
2763
3688
  rollingWindow: reconcileCompilerKeyedArrayRollingWindow
@@ -2765,7 +3690,7 @@ var keyedCompleteUpdateRuntime = {
2765
3690
  var keyedEveryUpdateRuntime = {
2766
3691
  ...keyedCompleteUpdateRuntime,
2767
3692
  position: reconcileCompilerKeyedArrayPosition,
2768
- reorder: reconcileCompilerKeyedArrayReorder
3693
+ reorder: reconcileCompilerKeyedArrayReorderWithMapAndStructural
2769
3694
  };
2770
3695
  var keyedBatchEveryUpdateRuntime = {
2771
3696
  ...keyedEveryUpdateRuntime,
@@ -2775,6 +3700,23 @@ var keyedWindowEveryUpdateRuntime = {
2775
3700
  ...keyedEveryUpdateRuntime,
2776
3701
  position: reconcileCompilerKeyedArrayPositionWithWindow
2777
3702
  };
3703
+ var keyedWindowEveryStructuralAppendUpdateRuntime = {
3704
+ ...keyedWindowEveryUpdateRuntime,
3705
+ append: reconcileCompilerKeyedArrayAppendWithStructural
3706
+ };
3707
+ var keyedWindowEveryStructuralAppendMapUpdateRuntime = {
3708
+ ...keyedWindowEveryStructuralAppendUpdateRuntime,
3709
+ append: reconcileCompilerKeyedArrayAppendMapWithStructural,
3710
+ commit: commitCompilerKeyedCollectionWithItemSnapshot
3711
+ };
3712
+ var keyedCompleteCompatibilityUpdateRuntime = {
3713
+ ...keyedWindowEveryStructuralAppendMapUpdateRuntime,
3714
+ prepend: reconcileCompilerKeyedArrayPrependWithStructural
3715
+ };
3716
+ var keyedCompleteStructuralPrependMapUpdateRuntime = {
3717
+ ...keyedCompleteCompatibilityUpdateRuntime,
3718
+ prepend: reconcileCompilerKeyedArrayPrependMapWithStructural
3719
+ };
2778
3720
  function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, instances, conditionals) {
2779
3721
  const dependency = props.collectionDependency;
2780
3722
  if (dependency === void 0) return void 0;
@@ -2824,6 +3766,86 @@ function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, ins
2824
3766
  fallback: false
2825
3767
  };
2826
3768
  }
3769
+ function reconcileCompilerKeyedArrayMapReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
3770
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
3771
+ return void 0;
3772
+ }
3773
+ const collectionDependency = props.collectionDependency;
3774
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3775
+ return void 0;
3776
+ }
3777
+ const dependencies = props.dependencies || props.structureDependencies;
3778
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3779
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3780
+ return void 0;
3781
+ }
3782
+ const finalValue = preparedReorder?.value ?? props.items();
3783
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
3784
+ if (!update?.mapped || !update.mappedItemSources || update.structuralUpdate || !Array.isArray(finalValue)) {
3785
+ return void 0;
3786
+ }
3787
+ const previousInstances = [...instances.values()];
3788
+ const reverse = update.kind === 0 /* Reverse */;
3789
+ const prepared = (() => {
3790
+ const changed = [];
3791
+ try {
3792
+ const instancesByItem = update.kind === 1 /* Permutation */ ? /* @__PURE__ */ new Map() : void 0;
3793
+ if (instancesByItem) {
3794
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
3795
+ const instance = previousInstances[sourceIndex];
3796
+ if (instance.index !== sourceIndex || instancesByItem.has(instance.item))
3797
+ return void 0;
3798
+ instancesByItem.set(instance.item, instance);
3799
+ }
3800
+ }
3801
+ const nextInstances = instancesByItem ? [] : previousInstances;
3802
+ const sequence = instancesByItem ? [] : void 0;
3803
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
3804
+ const item = finalValue[targetIndex];
3805
+ let instance;
3806
+ if (!instancesByItem) {
3807
+ const sourceIndex = reverse ? finalValue.length - targetIndex - 1 : targetIndex;
3808
+ instance = previousInstances[sourceIndex];
3809
+ if (!instance || instance.index !== sourceIndex) return void 0;
3810
+ if (Object.is(instance.item, item)) continue;
3811
+ if (!update.mappedItemSources.has(item) || !Object.is(instance.item, update.mappedItemSources.get(item))) {
3812
+ return void 0;
3813
+ }
3814
+ } else {
3815
+ const sourceItem = update.mappedItemSources.has(item) ? update.mappedItemSources.get(item) : item;
3816
+ instance = instancesByItem.get(sourceItem);
3817
+ if (!instance) return void 0;
3818
+ instancesByItem.delete(sourceItem);
3819
+ nextInstances.push(instance);
3820
+ sequence.push(instance.index);
3821
+ if (Object.is(instance.item, item)) continue;
3822
+ }
3823
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
3824
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, targetIndex);
3825
+ if (!bindingUpdates) return void 0;
3826
+ changed.push({ bindingUpdates, instance, item });
3827
+ }
3828
+ if (instancesByItem?.size) return void 0;
3829
+ return { changed, nextInstances, sequence };
3830
+ } catch {
3831
+ return void 0;
3832
+ }
3833
+ })();
3834
+ if (!prepared) return void 0;
3835
+ if (prepared.sequence) {
3836
+ reorderCompilerKeyedRows(root, prepared.nextInstances, prepared.sequence, null);
3837
+ } else if (reverse) {
3838
+ reverseCompilerKeyedRows(root, prepared.nextInstances);
3839
+ }
3840
+ for (const { bindingUpdates, instance, item } of prepared.changed) {
3841
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
3842
+ instance.item = item;
3843
+ }
3844
+ for (let index = 0; index < prepared.nextInstances.length; index += 1) {
3845
+ prepared.nextInstances[index].index = index;
3846
+ }
3847
+ return reverse || prepared.sequence ? keyedRowInstancesByKey(prepared.nextInstances) : instances;
3848
+ }
2827
3849
  function reconcileCompilerKeyedArrayAppend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
2828
3850
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || props.collectionDependency === void 0) {
2829
3851
  return void 0;
@@ -2846,28 +3868,243 @@ function reconcileCompilerKeyedArrayAppend(props, dirtyState, collectionToken, i
2846
3868
  for (let index = startIndex; index < finalValue.length; index += 1) {
2847
3869
  const item = finalValue[index];
2848
3870
  const key = keyedRowIdentity(props.rowKey(item, index));
2849
- if (nextInstances.has(key)) return void 0;
3871
+ if (nextInstances.has(key)) return void 0;
3872
+ const descriptor = props.create(item, index);
3873
+ const instance = {
3874
+ key,
3875
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
3876
+ values: readKeyedRowBindingValues(props, item, index),
3877
+ item,
3878
+ index,
3879
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3880
+ };
3881
+ appended.push(instance);
3882
+ nextInstances.set(key, instance);
3883
+ }
3884
+ } catch {
3885
+ return void 0;
3886
+ }
3887
+ if (appended.length > 0) {
3888
+ const fragment = root.ownerDocument.createDocumentFragment();
3889
+ for (const instance of appended) fragment.append(instance.element);
3890
+ root.append(fragment);
3891
+ }
3892
+ return nextInstances;
3893
+ }
3894
+ function reconcileCompilerKeyedArrayStructuralAppend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3895
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
3896
+ return void 0;
3897
+ }
3898
+ const collectionDependency = props.collectionDependency;
3899
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3900
+ return void 0;
3901
+ }
3902
+ const dependencies = props.dependencies || props.structureDependencies;
3903
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3904
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3905
+ return void 0;
3906
+ }
3907
+ const finalValue = props.items();
3908
+ const update = compilerKeyedArrayStructuralAppendUpdate(
3909
+ finalValue,
3910
+ collectionToken,
3911
+ instances.size
3912
+ );
3913
+ const structuralUpdate = update?.structuralUpdate;
3914
+ const survivorResult = update?.structuralSurvivors;
3915
+ if (!update || !structuralUpdate || !survivorResult || structuralUpdate.mappedItemSources || !Array.isArray(finalValue)) {
3916
+ return void 0;
3917
+ }
3918
+ const previousInstances = [...instances.values()];
3919
+ const survivors = [];
3920
+ const knownKeys = new Set(instances.keys());
3921
+ const appended = [];
3922
+ try {
3923
+ for (let index = 0; index < survivorResult.indices.length; index += 1) {
3924
+ const sourceIndex = survivorResult.indices[index];
3925
+ const instance = previousInstances[sourceIndex];
3926
+ const item = finalValue[index];
3927
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, item) || !survivorResult.keysStable && keyedRowIdentity(props.rowKey(item, index)) !== instance.key) {
3928
+ return void 0;
3929
+ }
3930
+ survivors.push(instance);
3931
+ }
3932
+ for (let index = update.startIndex; index < finalValue.length; index += 1) {
3933
+ const item = finalValue[index];
3934
+ const key = keyedRowIdentity(props.rowKey(item, index));
3935
+ if (knownKeys.has(key)) return void 0;
3936
+ knownKeys.add(key);
3937
+ const descriptor = props.create(item, index);
3938
+ appended.push({
3939
+ key,
3940
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
3941
+ values: readKeyedRowBindingValues(props, item, index),
3942
+ item,
3943
+ index,
3944
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3945
+ });
3946
+ }
3947
+ } catch {
3948
+ return void 0;
3949
+ }
3950
+ const survivorSet = new Set(survivorResult.indices);
3951
+ for (let index = 0; index < previousInstances.length; index += 1) {
3952
+ if (survivorSet.has(index)) continue;
3953
+ previousInstances[index].scope?.cleanup();
3954
+ previousInstances[index].element.remove();
3955
+ }
3956
+ for (let index = 0; index < survivors.length; index += 1) survivors[index].index = index;
3957
+ if (appended.length > 0) {
3958
+ const fragment = root.ownerDocument.createDocumentFragment();
3959
+ for (const instance of appended) fragment.append(instance.element);
3960
+ root.append(fragment);
3961
+ }
3962
+ return keyedRowInstancesByKey([...survivors, ...appended]);
3963
+ }
3964
+ function reconcileCompilerKeyedArrayStructuralAppendMap(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3965
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
3966
+ return void 0;
3967
+ }
3968
+ const collectionDependency = props.collectionDependency;
3969
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3970
+ return void 0;
3971
+ }
3972
+ const dependencies = props.dependencies || props.structureDependencies;
3973
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3974
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3975
+ return void 0;
3976
+ }
3977
+ const finalValue = props.items();
3978
+ const update = compilerKeyedArrayStructuralAppendMapUpdate(
3979
+ finalValue,
3980
+ collectionToken,
3981
+ instances.size,
3982
+ true
3983
+ );
3984
+ if (!update || !update.mappedItemSources || !Array.isArray(finalValue)) return void 0;
3985
+ const mappedItemSources = update.mappedSurvivorsValidated ? update.mappedItemSources : void 0;
3986
+ const mappedStructuralSources = update.mappedSurvivorsValidated ? void 0 : update.mappedItemSources;
3987
+ const previousInstances = [...instances.values()];
3988
+ const survivorRange = update.structuralSurvivorRange;
3989
+ const survivorIndices = update.structuralSurvivors;
3990
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
3991
+ if (!survivorRange && !survivorIndices) return void 0;
3992
+ const changed = [];
3993
+ const appendedKeys = /* @__PURE__ */ new Set();
3994
+ const appended = [];
3995
+ try {
3996
+ if (mappedStructuralSources) {
3997
+ for (let index = 0; index < survivorCount; index += 1) {
3998
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
3999
+ const instance = previousInstances[sourceIndex];
4000
+ const item = finalValue[index];
4001
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
4002
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, sourceItem)) {
4003
+ return void 0;
4004
+ }
4005
+ }
4006
+ for (let index = 0; index < survivorCount; index += 1) {
4007
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
4008
+ const instance = previousInstances[sourceIndex];
4009
+ const item = finalValue[index];
4010
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
4011
+ if (Object.is(item, sourceItem)) continue;
4012
+ if (keyedRowIdentity(props.rowKey(item, index)) !== instance.key) return void 0;
4013
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
4014
+ if (!bindingUpdates) return void 0;
4015
+ changed.push({ bindingUpdates, instance, item });
4016
+ }
4017
+ } else if (survivorIndices) {
4018
+ for (let index = 0; index < survivorCount; index += 1) {
4019
+ const sourceIndex = survivorIndices[index];
4020
+ const instance = previousInstances[sourceIndex];
4021
+ const item = finalValue[index];
4022
+ const expectedItem = mappedItemSources.has(index) ? mappedItemSources.get(index) : item;
4023
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, expectedItem)) {
4024
+ return void 0;
4025
+ }
4026
+ }
4027
+ }
4028
+ for (const [index, sourceItem] of mappedItemSources || []) {
4029
+ if (!Number.isSafeInteger(index) || index < 0 || index >= survivorCount) {
4030
+ return void 0;
4031
+ }
4032
+ const instance = previousInstances[survivorRange ? survivorRange.start + index : survivorIndices[index]];
4033
+ const item = finalValue[index];
4034
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, index)) !== instance.key) {
4035
+ return void 0;
4036
+ }
4037
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
4038
+ if (!bindingUpdates) return void 0;
4039
+ changed.push({ bindingUpdates, instance, item });
4040
+ }
4041
+ for (let index = update.startIndex; index < finalValue.length; index += 1) {
4042
+ const item = finalValue[index];
4043
+ const key = keyedRowIdentity(props.rowKey(item, index));
4044
+ if (instances.has(key) || appendedKeys.has(key)) return void 0;
4045
+ appendedKeys.add(key);
2850
4046
  const descriptor = props.create(item, index);
2851
- const instance = {
4047
+ appended.push({
2852
4048
  key,
2853
4049
  element: createCompilerHostElement(root.ownerDocument, descriptor),
2854
4050
  values: readKeyedRowBindingValues(props, item, index),
2855
4051
  item,
2856
4052
  index,
2857
4053
  conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2858
- };
2859
- appended.push(instance);
2860
- nextInstances.set(key, instance);
4054
+ });
2861
4055
  }
2862
4056
  } catch {
2863
4057
  return void 0;
2864
4058
  }
4059
+ const mutableInstances = instances;
4060
+ if (survivorRange) {
4061
+ for (let index = 0; index < survivorRange.start; index += 1) {
4062
+ const instance = previousInstances[index];
4063
+ instance.scope?.cleanup();
4064
+ instance.element.remove();
4065
+ mutableInstances.delete(instance.key);
4066
+ }
4067
+ for (let index = survivorRange.end; index < previousInstances.length; index += 1) {
4068
+ const instance = previousInstances[index];
4069
+ instance.scope?.cleanup();
4070
+ instance.element.remove();
4071
+ mutableInstances.delete(instance.key);
4072
+ }
4073
+ for (let index = survivorRange.start; index < survivorRange.end; index += 1) {
4074
+ previousInstances[index].index = index - survivorRange.start;
4075
+ }
4076
+ } else {
4077
+ const survivorSet = new Set(survivorIndices);
4078
+ for (let index = 0; index < previousInstances.length; index += 1) {
4079
+ if (survivorSet.has(index)) continue;
4080
+ const instance = previousInstances[index];
4081
+ instance.scope?.cleanup();
4082
+ instance.element.remove();
4083
+ mutableInstances.delete(instance.key);
4084
+ }
4085
+ for (let index = 0; index < survivorIndices.length; index += 1) {
4086
+ previousInstances[survivorIndices[index]].index = index;
4087
+ }
4088
+ }
2865
4089
  if (appended.length > 0) {
2866
4090
  const fragment = root.ownerDocument.createDocumentFragment();
2867
- for (const instance of appended) fragment.append(instance.element);
4091
+ for (const instance of appended) {
4092
+ fragment.append(instance.element);
4093
+ mutableInstances.set(instance.key, instance);
4094
+ }
2868
4095
  root.append(fragment);
2869
4096
  }
2870
- return nextInstances;
4097
+ for (const { bindingUpdates, instance, item } of changed) {
4098
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4099
+ instance.item = item;
4100
+ }
4101
+ return mutableInstances;
4102
+ }
4103
+ function reconcileCompilerKeyedArrayAppendWithStructural(...args) {
4104
+ return reconcileCompilerKeyedArrayStructuralAppend(...args) || reconcileCompilerKeyedArrayAppend(...args);
4105
+ }
4106
+ function reconcileCompilerKeyedArrayAppendMapWithStructural(...args) {
4107
+ return reconcileCompilerKeyedArrayStructuralAppendMap(...args) || reconcileCompilerKeyedArrayStructuralAppend(...args) || reconcileCompilerKeyedArrayAppend(...args);
2871
4108
  }
2872
4109
  function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
2873
4110
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
@@ -2883,14 +4120,18 @@ function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionT
2883
4120
  return void 0;
2884
4121
  }
2885
4122
  const finalValue = props.items();
2886
- const update = compilerKeyedArrayRollingWindow(finalValue, collectionToken, instances.size);
2887
- if (!update || !Array.isArray(finalValue)) return void 0;
4123
+ const updates = compilerKeyedArrayRollingWindows(finalValue, collectionToken, instances.size);
4124
+ if (!updates || !Array.isArray(finalValue)) return void 0;
2888
4125
  const previousInstances = [...instances.values()];
2889
- const retainedLength = update.retainedEnd - update.retainedStart;
4126
+ let retainedStart = 0;
4127
+ for (const update of updates) {
4128
+ retainedStart += Math.min(update.retainedStart, previousInstances.length - retainedStart);
4129
+ }
4130
+ const retainedLength = previousInstances.length - retainedStart;
2890
4131
  const survivors = [];
2891
4132
  try {
2892
4133
  for (let index = 0; index < retainedLength; index += 1) {
2893
- const sourceIndex = update.retainedStart + index;
4134
+ const sourceIndex = retainedStart + index;
2894
4135
  const instance = previousInstances[sourceIndex];
2895
4136
  if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, finalValue[index])) {
2896
4137
  return void 0;
@@ -2921,7 +4162,7 @@ function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionT
2921
4162
  } catch {
2922
4163
  return void 0;
2923
4164
  }
2924
- for (let index = 0; index < update.retainedStart; index += 1) {
4165
+ for (let index = 0; index < retainedStart; index += 1) {
2925
4166
  previousInstances[index].scope?.cleanup();
2926
4167
  previousInstances[index].element.remove();
2927
4168
  }
@@ -2968,7 +4209,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
2968
4209
  for (let index = update.position; index < previousInstances.length; index += 1) {
2969
4210
  previousInstances[index].index = index;
2970
4211
  }
2971
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4212
+ return keyedRowInstancesByKey(previousInstances);
2972
4213
  }
2973
4214
  let item;
2974
4215
  let key;
@@ -2999,7 +4240,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
2999
4240
  for (let index = update.position + 1; index < previousInstances.length; index += 1) {
3000
4241
  previousInstances[index].index = index;
3001
4242
  }
3002
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4243
+ return keyedRowInstancesByKey(previousInstances);
3003
4244
  }
3004
4245
  if (!previous || previous.index !== update.position) return void 0;
3005
4246
  if (key === previous.key) {
@@ -3029,7 +4270,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
3029
4270
  previous.scope?.cleanup();
3030
4271
  previous.element.replaceWith(replacement.element);
3031
4272
  previousInstances[update.position] = replacement;
3032
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4273
+ return keyedRowInstancesByKey(previousInstances);
3033
4274
  }
3034
4275
  function reconcileCompilerKeyedArrayBatchInsert(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3035
4276
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.positionIndexIndependent || props.collectionDependency === void 0) {
@@ -3085,7 +4326,111 @@ function reconcileCompilerKeyedArrayBatchInsert(props, dirtyState, collectionTok
3085
4326
  for (let index = update.position + insertCount; index < previousInstances.length; index += 1) {
3086
4327
  previousInstances[index].index = index;
3087
4328
  }
3088
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4329
+ return keyedRowInstancesByKey(previousInstances);
4330
+ }
4331
+ function normalizeCompilerKeyedArrayDisjointWindows(updates) {
4332
+ const windows = [];
4333
+ for (const update of updates) {
4334
+ const updateEnd = update.position + update.removedCount;
4335
+ let sourcePosition = update.position;
4336
+ for (const window of windows) {
4337
+ const windowStart = window[1];
4338
+ const windowEnd = windowStart + window[3];
4339
+ const before = updateEnd <= windowStart;
4340
+ const after = window[3] === 0 ? update.position >= windowStart : update.position >= windowEnd;
4341
+ if (!before && !after) return void 0;
4342
+ if (after) sourcePosition -= window[3] - window[2];
4343
+ }
4344
+ const delta = update.insertedCount - update.removedCount;
4345
+ for (const window of windows) {
4346
+ if (updateEnd <= window[1]) window[1] += delta;
4347
+ }
4348
+ windows.push([sourcePosition, update.position, update.removedCount, update.insertedCount]);
4349
+ }
4350
+ windows.sort((left, right) => left[0] - right[0]);
4351
+ return windows;
4352
+ }
4353
+ function readCompilerKeyedArrayWindowItems(props, finalValue, resultPosition, insertedCount) {
4354
+ const items = [];
4355
+ const keys = [];
4356
+ try {
4357
+ for (let offset = 0; offset < insertedCount; offset += 1) {
4358
+ const index = resultPosition + offset;
4359
+ const item = finalValue[index];
4360
+ items.push(item);
4361
+ keys.push(keyedRowIdentity(props.rowKey(item, index)));
4362
+ }
4363
+ } catch {
4364
+ return void 0;
4365
+ }
4366
+ return [items, keys];
4367
+ }
4368
+ function prepareCompilerKeyedArrayWindow(props, instances, previousInstances, root, window, incoming, preparedIncomingKeys) {
4369
+ const removedEnd = window[0] + window[2];
4370
+ const removed = previousInstances.slice(window[0], removedEnd);
4371
+ const anchor = previousInstances[removedEnd]?.element || null;
4372
+ if (removed.length !== window[2] || removed.some(
4373
+ (instance, offset) => instance.index !== window[0] + offset || instance.element.parentNode !== root
4374
+ ) || anchor && anchor.parentNode !== root) {
4375
+ return void 0;
4376
+ }
4377
+ const incomingKeySet = new Set(incoming[1]);
4378
+ if (incomingKeySet.size !== incoming[1].length) return void 0;
4379
+ for (const key of incomingKeySet) {
4380
+ if (preparedIncomingKeys.has(key)) return void 0;
4381
+ preparedIncomingKeys.add(key);
4382
+ }
4383
+ const hasLocalReuse = removed.some((instance) => incomingKeySet.has(instance.key));
4384
+ const removedByKey = hasLocalReuse ? new Map(removed.map((instance, offset) => [instance.key, { instance, offset }])) : void 0;
4385
+ const nextWindow = [];
4386
+ const sequence = [];
4387
+ const preparedBindings = [];
4388
+ try {
4389
+ for (let offset = 0; offset < window[3]; offset += 1) {
4390
+ const index = window[1] + offset;
4391
+ const item = incoming[0][offset];
4392
+ const key = incoming[1][offset];
4393
+ const retained = removedByKey?.get(key);
4394
+ if (retained) {
4395
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, retained.instance, item, index);
4396
+ if (!bindingUpdates) return void 0;
4397
+ nextWindow.push(retained.instance);
4398
+ sequence.push(retained.offset);
4399
+ preparedBindings.push(bindingUpdates);
4400
+ continue;
4401
+ }
4402
+ if (instances.has(key)) return void 0;
4403
+ const descriptor = props.create(item, index);
4404
+ nextWindow.push({
4405
+ key,
4406
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
4407
+ values: readKeyedRowBindingValues(props, item, index),
4408
+ item,
4409
+ index,
4410
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4411
+ });
4412
+ sequence.push(-1);
4413
+ preparedBindings.push(void 0);
4414
+ }
4415
+ } catch {
4416
+ return void 0;
4417
+ }
4418
+ return [removed, anchor, incoming[0], incomingKeySet, nextWindow, sequence, preparedBindings];
4419
+ }
4420
+ function commitCompilerKeyedArrayWindow(props, root, prepared) {
4421
+ for (const instance of prepared[0]) {
4422
+ if (prepared[3].has(instance.key)) continue;
4423
+ instance.scope?.cleanup();
4424
+ instance.element.remove();
4425
+ }
4426
+ for (let offset = 0; offset < prepared[4].length; offset += 1) {
4427
+ const bindingUpdates = prepared[6][offset];
4428
+ if (!bindingUpdates) continue;
4429
+ const instance = prepared[4][offset];
4430
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4431
+ instance.item = prepared[2][offset];
4432
+ }
4433
+ reorderCompilerKeyedRows(root, prepared[4], prepared[5], prepared[1]);
3089
4434
  }
3090
4435
  function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3091
4436
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.positionIndexIndependent || props.collectionDependency === void 0) {
@@ -3105,9 +4450,68 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3105
4450
  if (!updates || !Array.isArray(finalValue)) return void 0;
3106
4451
  const previousInstances = [...instances.values()];
3107
4452
  if (updates.length > 1) {
4453
+ if (updates.some((update2) => update2.insertedCount !== update2.removedCount)) {
4454
+ const windows = normalizeCompilerKeyedArrayDisjointWindows(updates);
4455
+ if (!windows) return void 0;
4456
+ let sourceCursor = 0;
4457
+ let resultCursor = 0;
4458
+ const preparedIncomingKeys = /* @__PURE__ */ new Set();
4459
+ const preparedWindows = [];
4460
+ const nextInstances = [];
4461
+ for (const window of windows) {
4462
+ if (window[0] < sourceCursor) return void 0;
4463
+ while (sourceCursor < window[0]) {
4464
+ const instance = previousInstances[sourceCursor];
4465
+ if (!instance || instance.index !== sourceCursor || !Object.is(instance.item, finalValue[resultCursor])) {
4466
+ return void 0;
4467
+ }
4468
+ nextInstances.push(instance);
4469
+ sourceCursor += 1;
4470
+ resultCursor += 1;
4471
+ }
4472
+ const incoming2 = readCompilerKeyedArrayWindowItems(
4473
+ props,
4474
+ finalValue,
4475
+ resultCursor,
4476
+ window[3]
4477
+ );
4478
+ if (!incoming2) return void 0;
4479
+ window[1] = resultCursor;
4480
+ const prepared3 = prepareCompilerKeyedArrayWindow(
4481
+ props,
4482
+ instances,
4483
+ previousInstances,
4484
+ root,
4485
+ window,
4486
+ incoming2,
4487
+ preparedIncomingKeys
4488
+ );
4489
+ if (!prepared3) return void 0;
4490
+ preparedWindows.push(prepared3);
4491
+ nextInstances.push(...prepared3[4]);
4492
+ sourceCursor += window[2];
4493
+ resultCursor += window[3];
4494
+ }
4495
+ while (sourceCursor < previousInstances.length) {
4496
+ const instance = previousInstances[sourceCursor];
4497
+ if (!instance || instance.index !== sourceCursor || !Object.is(instance.item, finalValue[resultCursor])) {
4498
+ return void 0;
4499
+ }
4500
+ nextInstances.push(instance);
4501
+ sourceCursor += 1;
4502
+ resultCursor += 1;
4503
+ }
4504
+ if (resultCursor !== finalValue.length) return void 0;
4505
+ for (const prepared3 of preparedWindows) {
4506
+ commitCompilerKeyedArrayWindow(props, root, prepared3);
4507
+ }
4508
+ for (let index = 0; index < nextInstances.length; index += 1) {
4509
+ nextInstances[index].index = index;
4510
+ }
4511
+ return keyedRowInstancesByKey(nextInstances);
4512
+ }
3108
4513
  const touchedIndices = /* @__PURE__ */ new Set();
3109
4514
  for (const update2 of updates) {
3110
- if (update2.insertedCount !== update2.removedCount) return void 0;
3111
4515
  for (let index = update2.position; index < update2.position + update2.removedCount; index += 1) {
3112
4516
  touchedIndices.add(index);
3113
4517
  }
@@ -3119,21 +4523,21 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3119
4523
  return void 0;
3120
4524
  }
3121
4525
  }
3122
- const knownKeys2 = new Set(instances.keys());
4526
+ const knownKeys = new Set(instances.keys());
3123
4527
  const incomingKeys2 = /* @__PURE__ */ new Set();
3124
4528
  let replacesRows = false;
3125
- const prepared = [];
4529
+ const prepared2 = [];
3126
4530
  try {
3127
4531
  for (const index of [...touchedIndices].sort((left, right) => left - right)) {
3128
4532
  const instance = previousInstances[index];
3129
4533
  const item = finalValue[index];
3130
4534
  const key = keyedRowIdentity(props.rowKey(item, index));
3131
4535
  if (key !== instance.key) {
3132
- if (knownKeys2.has(key) || incomingKeys2.has(key)) return void 0;
4536
+ if (knownKeys.has(key) || incomingKeys2.has(key)) return void 0;
3133
4537
  incomingKeys2.add(key);
3134
4538
  replacesRows = true;
3135
4539
  const descriptor = props.create(item, index);
3136
- prepared.push([
4540
+ prepared2.push([
3137
4541
  index,
3138
4542
  instance,
3139
4543
  item,
@@ -3151,12 +4555,12 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3151
4555
  }
3152
4556
  const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
3153
4557
  if (!bindingUpdates) return void 0;
3154
- prepared.push([index, instance, item, bindingUpdates, void 0]);
4558
+ prepared2.push([index, instance, item, bindingUpdates, void 0]);
3155
4559
  }
3156
4560
  } catch {
3157
4561
  return void 0;
3158
4562
  }
3159
- for (const [index, instance, item, bindingUpdates, replacement] of prepared) {
4563
+ for (const [index, instance, item, bindingUpdates, replacement] of prepared2) {
3160
4564
  if (replacement) {
3161
4565
  instance.scope?.cleanup();
3162
4566
  instance.element.replaceWith(replacement.element);
@@ -3166,7 +4570,7 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3166
4570
  instance.item = item;
3167
4571
  }
3168
4572
  }
3169
- return replacesRows ? new Map(previousInstances.map((instance) => [instance.key, instance])) : instances;
4573
+ return replacesRows ? keyedRowInstancesByKey(previousInstances) : instances;
3170
4574
  }
3171
4575
  const update = updates[0];
3172
4576
  const removedEnd = update.position + update.removedCount;
@@ -3182,21 +4586,17 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3182
4586
  if (removed.length !== update.removedCount || removed.some((instance) => instance.element.parentNode !== root) || anchor && anchor.parentNode !== root) {
3183
4587
  return void 0;
3184
4588
  }
3185
- const incomingItems = [];
3186
- const incomingKeys = [];
3187
- try {
3188
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3189
- const index = update.position + offset;
3190
- const item = finalValue[index];
3191
- const key = keyedRowIdentity(props.rowKey(item, index));
3192
- incomingItems.push(item);
3193
- incomingKeys.push(key);
3194
- }
3195
- } catch {
3196
- return void 0;
3197
- }
4589
+ const incoming = readCompilerKeyedArrayWindowItems(
4590
+ props,
4591
+ finalValue,
4592
+ update.position,
4593
+ update.insertedCount
4594
+ );
4595
+ if (!incoming) return void 0;
4596
+ const incomingItems = incoming[0];
4597
+ const incomingKeys = incoming[1];
3198
4598
  if (update.insertedCount === update.removedCount && incomingKeys.every((key, offset) => key === removed[offset].key)) {
3199
- const prepared = [];
4599
+ const prepared2 = [];
3200
4600
  try {
3201
4601
  for (let offset = 0; offset < update.insertedCount; offset += 1) {
3202
4602
  const updates2 = prepareKeyedRowBindingUpdates(
@@ -3206,92 +4606,289 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3206
4606
  update.position + offset
3207
4607
  );
3208
4608
  if (!updates2) return void 0;
3209
- prepared.push(updates2);
4609
+ prepared2.push(updates2);
3210
4610
  }
3211
4611
  } catch {
3212
4612
  return void 0;
3213
4613
  }
3214
4614
  for (let offset = 0; offset < update.insertedCount; offset += 1) {
3215
- applyPreparedKeyedRowBindingUpdates(props, removed[offset], prepared[offset]);
4615
+ applyPreparedKeyedRowBindingUpdates(props, removed[offset], prepared2[offset]);
3216
4616
  removed[offset].item = incomingItems[offset];
3217
4617
  }
3218
4618
  return instances;
3219
4619
  }
3220
- if (update.insertedCount === update.removedCount) {
3221
- const incomingKeySet = new Set(incomingKeys);
3222
- if (incomingKeySet.size !== incomingKeys.length) return void 0;
3223
- const removedByKey = new Map(
3224
- removed.map((instance, offset) => [instance.key, { instance, offset }])
3225
- );
3226
- if (incomingKeys.some((key) => removedByKey.has(key))) {
3227
- const nextWindow = [];
3228
- const sequence = [];
3229
- const preparedBindings = [];
3230
- try {
3231
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3232
- const index = update.position + offset;
3233
- const item = incomingItems[offset];
3234
- const key = incomingKeys[offset];
3235
- const retained = removedByKey.get(key);
3236
- if (retained) {
3237
- const bindingUpdates = prepareKeyedRowBindingUpdates(
3238
- props,
3239
- retained.instance,
3240
- item,
3241
- index
3242
- );
3243
- if (!bindingUpdates) return void 0;
3244
- nextWindow.push(retained.instance);
3245
- sequence.push(retained.offset);
3246
- preparedBindings.push(bindingUpdates);
3247
- continue;
3248
- }
3249
- if (instances.has(key)) return void 0;
3250
- const descriptor = props.create(item, index);
3251
- nextWindow.push({
3252
- key,
3253
- element: createCompilerHostElement(root.ownerDocument, descriptor),
3254
- values: readKeyedRowBindingValues(props, item, index),
3255
- item,
3256
- index,
3257
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3258
- });
3259
- sequence.push(-1);
3260
- preparedBindings.push(void 0);
4620
+ const prepared = prepareCompilerKeyedArrayWindow(
4621
+ props,
4622
+ instances,
4623
+ previousInstances,
4624
+ root,
4625
+ [update.position, update.position, update.removedCount, update.insertedCount],
4626
+ incoming,
4627
+ /* @__PURE__ */ new Set()
4628
+ );
4629
+ if (!prepared) return void 0;
4630
+ commitCompilerKeyedArrayWindow(props, root, prepared);
4631
+ previousInstances.splice(update.position, update.removedCount, ...prepared[4]);
4632
+ for (let index = update.position; index < previousInstances.length; index += 1) {
4633
+ previousInstances[index].index = index;
4634
+ }
4635
+ return keyedRowInstancesByKey(previousInstances);
4636
+ }
4637
+ function reconcileCompilerKeyedArrayPositionWithBatch(...args) {
4638
+ return reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4639
+ }
4640
+ function reconcileCompilerKeyedArrayPositionWithWindow(...args) {
4641
+ return reconcileCompilerKeyedArrayWindowReplace(...args) || reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4642
+ }
4643
+ function reconcileCompilerKeyedArrayStructuralReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
4644
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4645
+ return void 0;
4646
+ }
4647
+ const collectionDependency = props.collectionDependency;
4648
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4649
+ return void 0;
4650
+ }
4651
+ const dependencies = props.dependencies || props.structureDependencies;
4652
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4653
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4654
+ return void 0;
4655
+ }
4656
+ const finalValue = preparedReorder?.value ?? props.items();
4657
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
4658
+ if (!update?.structuralUpdate || !Array.isArray(finalValue)) return void 0;
4659
+ const survivorResult = compilerKeyedArrayFilterSurvivorsFromUpdate(
4660
+ update.structuralUpdate,
4661
+ collectionToken,
4662
+ instances.size,
4663
+ finalValue.length
4664
+ );
4665
+ if (!survivorResult) return void 0;
4666
+ const previousInstances = [...instances.values()];
4667
+ const mappedItemSources = update.mappedItemSources;
4668
+ const prepared = (() => {
4669
+ try {
4670
+ const survivors = [];
4671
+ let previousSourceIndex = -1;
4672
+ for (const sourceIndex of survivorResult.indices) {
4673
+ const instance = previousInstances[sourceIndex];
4674
+ if (sourceIndex <= previousSourceIndex || !instance || instance.index !== sourceIndex) {
4675
+ return void 0;
3261
4676
  }
3262
- } catch {
3263
- return void 0;
4677
+ previousSourceIndex = sourceIndex;
4678
+ survivors.push(instance);
4679
+ }
4680
+ const prepareChangedInstance = (instance, item, targetIndex) => {
4681
+ if (Object.is(instance.item, item)) return void 0;
4682
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, targetIndex);
4683
+ if (!bindingUpdates) throw new TypeError();
4684
+ return { bindingUpdates, instance, item };
4685
+ };
4686
+ let preservesSurvivorOrder = true;
4687
+ const directChanges = [];
4688
+ if (update.kind !== 1 /* Permutation */) {
4689
+ const positionalInstances = update.kind === 0 /* Reverse */ ? [...survivors].reverse() : survivors;
4690
+ const sequence2 = update.kind === 0 /* Reverse */ ? positionalInstances.map((instance) => instance.index) : void 0;
4691
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4692
+ const item = finalValue[targetIndex];
4693
+ const instance = positionalInstances[targetIndex];
4694
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
4695
+ const changed2 = prepareChangedInstance(instance, item, targetIndex);
4696
+ if (changed2) directChanges.push(changed2);
4697
+ }
4698
+ return { changed: directChanges, nextInstances: positionalInstances, sequence: sequence2 };
3264
4699
  }
3265
- for (const instance of removed) {
3266
- if (incomingKeySet.has(instance.key)) continue;
3267
- instance.scope?.cleanup();
3268
- instance.element.remove();
3269
- }
3270
- for (let offset = 0; offset < nextWindow.length; offset += 1) {
3271
- const bindingUpdates = preparedBindings[offset];
3272
- if (bindingUpdates) {
3273
- const instance = nextWindow[offset];
3274
- applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
3275
- instance.item = incomingItems[offset];
3276
- instance.index = update.position + offset;
4700
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4701
+ const item = finalValue[targetIndex];
4702
+ const instance = survivors[targetIndex];
4703
+ const sourceItem = mappedItemSources?.has(item) ? mappedItemSources.get(item) : item;
4704
+ if (!Object.is(instance.item, sourceItem)) {
4705
+ preservesSurvivorOrder = false;
4706
+ break;
3277
4707
  }
4708
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
4709
+ const changed2 = prepareChangedInstance(instance, item, targetIndex);
4710
+ if (changed2) directChanges.push(changed2);
4711
+ }
4712
+ if (preservesSurvivorOrder) {
4713
+ return { changed: directChanges, nextInstances: survivors, sequence: void 0 };
4714
+ }
4715
+ const survivorInstances = /* @__PURE__ */ new Map();
4716
+ for (const instance of survivors) {
4717
+ if (survivorInstances.has(instance.item)) return void 0;
4718
+ survivorInstances.set(instance.item, instance);
4719
+ }
4720
+ const nextInstances = [];
4721
+ const sequence = [];
4722
+ const changed = [];
4723
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4724
+ const item = finalValue[targetIndex];
4725
+ const sourceItem = mappedItemSources?.has(item) ? mappedItemSources.get(item) : item;
4726
+ const instance = survivorInstances.get(sourceItem);
4727
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) {
4728
+ return void 0;
4729
+ }
4730
+ survivorInstances.delete(sourceItem);
4731
+ nextInstances.push(instance);
4732
+ sequence.push(instance.index);
4733
+ const changedInstance = prepareChangedInstance(instance, item, targetIndex);
4734
+ if (changedInstance) changed.push(changedInstance);
4735
+ }
4736
+ if (survivorInstances.size > 0) return void 0;
4737
+ return { changed, nextInstances, sequence };
4738
+ } catch {
4739
+ return void 0;
4740
+ }
4741
+ })();
4742
+ if (!prepared) return void 0;
4743
+ let survivorCursor = 0;
4744
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4745
+ if (survivorResult.indices[survivorCursor] === sourceIndex) {
4746
+ survivorCursor += 1;
4747
+ continue;
4748
+ }
4749
+ const instance = previousInstances[sourceIndex];
4750
+ instance.scope?.cleanup();
4751
+ instance.element.remove();
4752
+ }
4753
+ if (prepared.sequence) {
4754
+ reorderCompilerKeyedRows(root, prepared.nextInstances, prepared.sequence, null);
4755
+ }
4756
+ for (const { bindingUpdates, instance, item } of prepared.changed) {
4757
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4758
+ instance.item = item;
4759
+ }
4760
+ for (let index = 0; index < prepared.nextInstances.length; index += 1) {
4761
+ prepared.nextInstances[index].index = index;
4762
+ }
4763
+ return keyedRowInstancesByKey(prepared.nextInstances);
4764
+ }
4765
+ function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
4766
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4767
+ return void 0;
4768
+ }
4769
+ const collectionDependency = props.collectionDependency;
4770
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4771
+ return void 0;
4772
+ }
4773
+ const dependencies = props.dependencies || props.structureDependencies;
4774
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4775
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4776
+ return void 0;
4777
+ }
4778
+ const finalValue = preparedReorder?.value ?? props.items();
4779
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
4780
+ if (!update || update.mapped || update.structuralUpdate || !Array.isArray(finalValue)) {
4781
+ return void 0;
4782
+ }
4783
+ const previousInstances = [...instances.values()];
4784
+ if (update.kind === 1 /* Permutation */) {
4785
+ const instancesByItem = /* @__PURE__ */ new Map();
4786
+ try {
4787
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4788
+ const instance = previousInstances[sourceIndex];
4789
+ if (instance.index !== sourceIndex || instancesByItem.has(instance.item)) return void 0;
4790
+ instancesByItem.set(instance.item, instance);
3278
4791
  }
3279
- reorderCompilerKeyedRows(root, nextWindow, sequence, anchor || null);
3280
- previousInstances.splice(update.position, update.removedCount, ...nextWindow);
3281
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4792
+ const nextInstances = [];
4793
+ const sequence = [];
4794
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4795
+ const item = finalValue[targetIndex];
4796
+ const instance = instancesByItem.get(item);
4797
+ if (!instance || !Object.is(instance.item, item)) return void 0;
4798
+ instancesByItem.delete(item);
4799
+ nextInstances.push(instance);
4800
+ sequence.push(instance.index);
4801
+ }
4802
+ if (instancesByItem.size > 0) return void 0;
4803
+ reorderCompilerKeyedRows(root, nextInstances, sequence, null);
4804
+ for (let index = 0; index < nextInstances.length; index += 1) {
4805
+ nextInstances[index].index = index;
4806
+ }
4807
+ return keyedRowInstancesByKey(nextInstances);
4808
+ } catch {
4809
+ return void 0;
4810
+ }
4811
+ }
4812
+ try {
4813
+ for (let targetIndex = 0; targetIndex < previousInstances.length; targetIndex += 1) {
4814
+ const sourceIndex = update.kind === 0 /* Reverse */ ? previousInstances.length - targetIndex - 1 : targetIndex;
4815
+ const instance = previousInstances[sourceIndex];
4816
+ if (instance.index !== sourceIndex || !Object.is(instance.item, finalValue[targetIndex])) {
4817
+ return void 0;
4818
+ }
4819
+ }
4820
+ } catch {
4821
+ return void 0;
4822
+ }
4823
+ if (update.kind === void 0) return instances;
4824
+ reverseCompilerKeyedRows(root, previousInstances);
4825
+ return keyedRowInstancesByKey(previousInstances);
4826
+ }
4827
+ function prepareCompilerKeyedArrayReorder(args) {
4828
+ const [props, dirtyState, collectionToken, instances, , reactOwnedRows] = args;
4829
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4830
+ return void 0;
4831
+ }
4832
+ const collectionDependency = props.collectionDependency;
4833
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4834
+ return void 0;
4835
+ }
4836
+ const dependencies = props.dependencies || props.structureDependencies;
4837
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4838
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4839
+ return void 0;
4840
+ }
4841
+ const value = props.items();
4842
+ return {
4843
+ update: compilerKeyedArrayReorder(value, collectionToken, instances.size),
4844
+ value
4845
+ };
4846
+ }
4847
+ function reconcileCompilerKeyedArrayReorderWithMap(...args) {
4848
+ const prepared = prepareCompilerKeyedArrayReorder(args);
4849
+ if (!prepared) return void 0;
4850
+ const reconcile = prepared.update?.mapped ? reconcileCompilerKeyedArrayMapReorder : reconcileCompilerKeyedArrayReorder;
4851
+ return reconcile(args[0], args[1], args[2], args[3], args[4], args[5], prepared);
4852
+ }
4853
+ function reconcileCompilerKeyedArrayReorderWithMapAndStructural(...args) {
4854
+ const prepared = prepareCompilerKeyedArrayReorder(args);
4855
+ if (!prepared) return void 0;
4856
+ const reconcile = prepared.update?.structuralUpdate ? reconcileCompilerKeyedArrayStructuralReorder : prepared.update?.mapped ? reconcileCompilerKeyedArrayMapReorder : reconcileCompilerKeyedArrayReorder;
4857
+ return reconcile(args[0], args[1], args[2], args[3], args[4], args[5], prepared);
4858
+ }
4859
+ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4860
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.prependIndexIndependent || props.collectionDependency === void 0) {
4861
+ return void 0;
4862
+ }
4863
+ const collectionDependency = props.collectionDependency;
4864
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4865
+ return void 0;
4866
+ }
4867
+ const dependencies = props.dependencies || props.structureDependencies;
4868
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4869
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4870
+ return void 0;
4871
+ }
4872
+ const finalValue = props.items();
4873
+ const prefixLength = compilerKeyedArrayPrependLength(finalValue, collectionToken, instances.size);
4874
+ if (prefixLength === void 0 || !Array.isArray(finalValue)) return void 0;
4875
+ const previousInstances = [...instances.values()];
4876
+ for (let index = 0; index < previousInstances.length; index += 1) {
4877
+ const instance = previousInstances[index];
4878
+ if (instance.index !== index || !Object.is(instance.item, finalValue[prefixLength + index])) {
4879
+ return void 0;
3282
4880
  }
3283
4881
  }
3284
4882
  const knownKeys = new Set(instances.keys());
3285
- const incoming = [];
4883
+ const prepended = [];
3286
4884
  try {
3287
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3288
- const index = update.position + offset;
3289
- const item = incomingItems[offset];
3290
- const key = incomingKeys[offset];
4885
+ for (let index = 0; index < prefixLength; index += 1) {
4886
+ const item = finalValue[index];
4887
+ const key = keyedRowIdentity(props.rowKey(item, index));
3291
4888
  if (knownKeys.has(key)) return void 0;
3292
4889
  knownKeys.add(key);
3293
4890
  const descriptor = props.create(item, index);
3294
- incoming.push({
4891
+ prepended.push({
3295
4892
  key,
3296
4893
  element: createCompilerHostElement(root.ownerDocument, descriptor),
3297
4894
  values: readKeyedRowBindingValues(props, item, index),
@@ -3303,29 +4900,18 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3303
4900
  } catch {
3304
4901
  return void 0;
3305
4902
  }
3306
- for (const instance of removed) {
3307
- instance.scope?.cleanup();
3308
- instance.element.remove();
3309
- }
3310
- if (incoming.length > 0) {
4903
+ if (prepended.length > 0) {
3311
4904
  const fragment = root.ownerDocument.createDocumentFragment();
3312
- for (const instance of incoming) fragment.append(instance.element);
3313
- root.insertBefore(fragment, anchor || null);
4905
+ for (const instance of prepended) fragment.append(instance.element);
4906
+ root.insertBefore(fragment, root.firstChild);
3314
4907
  }
3315
- previousInstances.splice(update.position, update.removedCount, ...incoming);
3316
- for (let index = update.position + update.insertedCount; index < previousInstances.length; index += 1) {
3317
- previousInstances[index].index = index;
4908
+ for (let index = 0; index < previousInstances.length; index += 1) {
4909
+ previousInstances[index].index = prefixLength + index;
3318
4910
  }
3319
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
3320
- }
3321
- function reconcileCompilerKeyedArrayPositionWithBatch(...args) {
3322
- return reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
3323
- }
3324
- function reconcileCompilerKeyedArrayPositionWithWindow(...args) {
3325
- return reconcileCompilerKeyedArrayWindowReplace(...args) || reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4911
+ return keyedRowInstancesByKey([...prepended, ...previousInstances]);
3326
4912
  }
3327
- function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3328
- if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4913
+ function reconcileCompilerKeyedArrayStructuralPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4914
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.prependIndexIndependent || props.collectionDependency === void 0) {
3329
4915
  return void 0;
3330
4916
  }
3331
4917
  const collectionDependency = props.collectionDependency;
@@ -3338,78 +4924,66 @@ function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken,
3338
4924
  return void 0;
3339
4925
  }
3340
4926
  const finalValue = props.items();
3341
- const update = compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
3342
- if (!update || !Array.isArray(finalValue)) return void 0;
3343
- const previousInstances = [...instances.values()];
3344
- if (update.kind === "sort") {
3345
- const instancesByItem = /* @__PURE__ */ new Map();
3346
- try {
3347
- for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
3348
- const instance = previousInstances[sourceIndex];
3349
- if (instance.index !== sourceIndex || instancesByItem.has(instance.item)) return void 0;
3350
- instancesByItem.set(instance.item, instance);
3351
- }
3352
- const nextInstances = [];
3353
- const sequence = [];
3354
- for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
3355
- const item = finalValue[targetIndex];
3356
- const instance = instancesByItem.get(item);
3357
- if (!instance || !Object.is(instance.item, item)) return void 0;
3358
- instancesByItem.delete(item);
3359
- nextInstances.push(instance);
3360
- sequence.push(instance.index);
3361
- }
3362
- if (instancesByItem.size > 0) return void 0;
3363
- const activeElement2 = root.ownerDocument.activeElement;
3364
- const restoreFocus2 = Boolean(activeElement2 && root.contains(activeElement2));
3365
- const stablePositions = longestIncreasingSubsequencePositions(sequence);
3366
- let anchor2 = null;
3367
- for (let index = nextInstances.length - 1; index >= 0; index -= 1) {
3368
- const instance = nextInstances[index];
3369
- if (!stablePositions.has(index) && instance.element.nextSibling !== anchor2) {
3370
- root.insertBefore(instance.element, anchor2);
3371
- }
3372
- anchor2 = instance.element;
3373
- instance.index = index;
3374
- }
3375
- if (restoreFocus2 && activeElement2?.isConnected && activeElement2.ownerDocument.activeElement !== activeElement2 && "focus" in activeElement2) {
3376
- activeElement2.focus({ preventScroll: true });
3377
- }
3378
- return new Map(nextInstances.map((instance) => [instance.key, instance]));
3379
- } catch {
3380
- return void 0;
3381
- }
4927
+ const update = compilerKeyedArrayStructuralPrependUpdate(
4928
+ finalValue,
4929
+ collectionToken,
4930
+ instances.size
4931
+ );
4932
+ const structuralUpdate = update?.structuralUpdate;
4933
+ const survivorResult = update?.structuralSurvivors;
4934
+ if (!update || !structuralUpdate || !survivorResult || structuralUpdate.mappedItemSources || !Array.isArray(finalValue)) {
4935
+ return void 0;
3382
4936
  }
4937
+ const previousInstances = [...instances.values()];
4938
+ const survivors = [];
4939
+ const knownKeys = new Set(instances.keys());
4940
+ const prepended = [];
3383
4941
  try {
3384
- for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4942
+ for (let index = 0; index < survivorResult.indices.length; index += 1) {
4943
+ const sourceIndex = survivorResult.indices[index];
3385
4944
  const instance = previousInstances[sourceIndex];
3386
- const targetIndex = previousInstances.length - sourceIndex - 1;
3387
- if (instance.index !== sourceIndex || !Object.is(instance.item, finalValue[targetIndex])) {
4945
+ const item = finalValue[update.prefixLength + index];
4946
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, item) || !survivorResult.keysStable && keyedRowIdentity(props.rowKey(item, update.prefixLength + index)) !== instance.key) {
3388
4947
  return void 0;
3389
4948
  }
4949
+ survivors.push(instance);
4950
+ }
4951
+ for (let index = 0; index < update.prefixLength; index += 1) {
4952
+ const item = finalValue[index];
4953
+ const key = keyedRowIdentity(props.rowKey(item, index));
4954
+ if (knownKeys.has(key)) return void 0;
4955
+ knownKeys.add(key);
4956
+ const descriptor = props.create(item, index);
4957
+ prepended.push({
4958
+ key,
4959
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
4960
+ values: readKeyedRowBindingValues(props, item, index),
4961
+ item,
4962
+ index,
4963
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4964
+ });
3390
4965
  }
3391
4966
  } catch {
3392
4967
  return void 0;
3393
4968
  }
3394
- const activeElement = root.ownerDocument.activeElement;
3395
- const restoreFocus = Boolean(activeElement && root.contains(activeElement));
3396
- let anchor = previousInstances[0]?.element || null;
3397
- for (let sourceIndex = 1; sourceIndex < previousInstances.length; sourceIndex += 1) {
3398
- const element = previousInstances[sourceIndex].element;
3399
- root.insertBefore(element, anchor);
3400
- anchor = element;
3401
- }
3402
- previousInstances.reverse();
4969
+ const survivorSet = new Set(survivorResult.indices);
3403
4970
  for (let index = 0; index < previousInstances.length; index += 1) {
3404
- previousInstances[index].index = index;
4971
+ if (survivorSet.has(index)) continue;
4972
+ previousInstances[index].scope?.cleanup();
4973
+ previousInstances[index].element.remove();
3405
4974
  }
3406
- if (restoreFocus && activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
3407
- activeElement.focus({ preventScroll: true });
4975
+ if (prepended.length > 0) {
4976
+ const fragment = root.ownerDocument.createDocumentFragment();
4977
+ for (const instance of prepended) fragment.append(instance.element);
4978
+ root.insertBefore(fragment, survivors[0]?.element || root.firstChild);
4979
+ }
4980
+ for (let index = 0; index < survivors.length; index += 1) {
4981
+ survivors[index].index = update.prefixLength + index;
3408
4982
  }
3409
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4983
+ return keyedRowInstancesByKey([...prepended, ...survivors]);
3410
4984
  }
3411
- function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3412
- if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.prependIndexIndependent || props.collectionDependency === void 0) {
4985
+ function reconcileCompilerKeyedArrayStructuralPrependMap(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4986
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.prependIndexIndependent || props.collectionDependency === void 0) {
3413
4987
  return void 0;
3414
4988
  }
3415
4989
  const collectionDependency = props.collectionDependency;
@@ -3422,19 +4996,78 @@ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken,
3422
4996
  return void 0;
3423
4997
  }
3424
4998
  const finalValue = props.items();
3425
- const prefixLength = compilerKeyedArrayPrependLength(finalValue, collectionToken, instances.size);
3426
- if (prefixLength === void 0 || !Array.isArray(finalValue)) return void 0;
4999
+ const update = compilerKeyedArrayStructuralPrependMapUpdate(
5000
+ finalValue,
5001
+ collectionToken,
5002
+ instances.size,
5003
+ true
5004
+ );
5005
+ if (!update || !update.mappedItemSources || !Array.isArray(finalValue)) return void 0;
5006
+ const mappedItemSources = update.mappedSurvivorsValidated ? update.mappedItemSources : void 0;
5007
+ const mappedStructuralSources = update.mappedSurvivorsValidated ? void 0 : update.mappedItemSources;
3427
5008
  const previousInstances = [...instances.values()];
3428
- for (let index = 0; index < previousInstances.length; index += 1) {
3429
- const instance = previousInstances[index];
3430
- if (instance.index !== index || !Object.is(instance.item, finalValue[prefixLength + index])) {
3431
- return void 0;
3432
- }
3433
- }
5009
+ const survivorRange = update.structuralSurvivorRange;
5010
+ const survivorIndices = update.structuralSurvivors;
5011
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
5012
+ if (!survivorRange && !survivorIndices) return void 0;
5013
+ const changed = [];
3434
5014
  const knownKeys = new Set(instances.keys());
3435
5015
  const prepended = [];
3436
5016
  try {
3437
- for (let index = 0; index < prefixLength; index += 1) {
5017
+ if (mappedStructuralSources) {
5018
+ for (let index = 0; index < survivorCount; index += 1) {
5019
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
5020
+ const instance = previousInstances[sourceIndex];
5021
+ const item = finalValue[update.prefixLength + index];
5022
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
5023
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, sourceItem)) {
5024
+ return void 0;
5025
+ }
5026
+ }
5027
+ for (let index = 0; index < survivorCount; index += 1) {
5028
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
5029
+ const instance = previousInstances[sourceIndex];
5030
+ const item = finalValue[update.prefixLength + index];
5031
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
5032
+ if (Object.is(item, sourceItem)) continue;
5033
+ if (keyedRowIdentity(props.rowKey(item, update.prefixLength + index)) !== instance.key) {
5034
+ return void 0;
5035
+ }
5036
+ const bindingUpdates = prepareKeyedRowBindingUpdates(
5037
+ props,
5038
+ instance,
5039
+ item,
5040
+ update.prefixLength + index
5041
+ );
5042
+ if (!bindingUpdates) return void 0;
5043
+ changed.push({ bindingUpdates, instance, item });
5044
+ }
5045
+ } else if (survivorIndices) {
5046
+ for (let index = 0; index < survivorCount; index += 1) {
5047
+ const sourceIndex = survivorIndices[index];
5048
+ const instance = previousInstances[sourceIndex];
5049
+ const item = finalValue[update.prefixLength + index];
5050
+ const expectedItem = mappedItemSources.has(index) ? mappedItemSources.get(index) : item;
5051
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, expectedItem)) {
5052
+ return void 0;
5053
+ }
5054
+ }
5055
+ }
5056
+ for (const [index, sourceItem] of mappedItemSources || []) {
5057
+ if (!Number.isSafeInteger(index) || index < 0 || index >= survivorCount) {
5058
+ return void 0;
5059
+ }
5060
+ const instance = previousInstances[survivorRange ? survivorRange.start + index : survivorIndices[index]];
5061
+ const finalIndex = update.prefixLength + index;
5062
+ const item = finalValue[finalIndex];
5063
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, finalIndex)) !== instance.key) {
5064
+ return void 0;
5065
+ }
5066
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, finalIndex);
5067
+ if (!bindingUpdates) return void 0;
5068
+ changed.push({ bindingUpdates, instance, item });
5069
+ }
5070
+ for (let index = 0; index < update.prefixLength; index += 1) {
3438
5071
  const item = finalValue[index];
3439
5072
  const key = keyedRowIdentity(props.rowKey(item, index));
3440
5073
  if (knownKeys.has(key)) return void 0;
@@ -3452,15 +5085,43 @@ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken,
3452
5085
  } catch {
3453
5086
  return void 0;
3454
5087
  }
5088
+ if (survivorRange) {
5089
+ for (let index = 0; index < survivorRange.start; index += 1) {
5090
+ previousInstances[index].scope?.cleanup();
5091
+ previousInstances[index].element.remove();
5092
+ }
5093
+ for (let index = survivorRange.end; index < previousInstances.length; index += 1) {
5094
+ previousInstances[index].scope?.cleanup();
5095
+ previousInstances[index].element.remove();
5096
+ }
5097
+ } else {
5098
+ const survivorSet = new Set(survivorIndices);
5099
+ for (let index = 0; index < previousInstances.length; index += 1) {
5100
+ if (survivorSet.has(index)) continue;
5101
+ previousInstances[index].scope?.cleanup();
5102
+ previousInstances[index].element.remove();
5103
+ }
5104
+ }
5105
+ const survivors = survivorRange ? previousInstances.slice(survivorRange.start, survivorRange.end) : survivorIndices.map((index) => previousInstances[index]);
3455
5106
  if (prepended.length > 0) {
3456
5107
  const fragment = root.ownerDocument.createDocumentFragment();
3457
5108
  for (const instance of prepended) fragment.append(instance.element);
3458
- root.insertBefore(fragment, root.firstChild);
5109
+ root.insertBefore(fragment, survivors[0]?.element || root.firstChild);
3459
5110
  }
3460
- for (let index = 0; index < previousInstances.length; index += 1) {
3461
- previousInstances[index].index = prefixLength + index;
5111
+ for (let index = 0; index < survivors.length; index += 1) {
5112
+ survivors[index].index = update.prefixLength + index;
5113
+ }
5114
+ for (const { bindingUpdates, instance, item } of changed) {
5115
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
5116
+ instance.item = item;
3462
5117
  }
3463
- return new Map([...prepended, ...previousInstances].map((instance) => [instance.key, instance]));
5118
+ return keyedRowInstancesByKey([...prepended, ...survivors]);
5119
+ }
5120
+ function reconcileCompilerKeyedArrayPrependWithStructural(...args) {
5121
+ return reconcileCompilerKeyedArrayStructuralPrepend(...args) || reconcileCompilerKeyedArrayPrepend(...args);
5122
+ }
5123
+ function reconcileCompilerKeyedArrayPrependMapWithStructural(...args) {
5124
+ return reconcileCompilerKeyedArrayStructuralPrependMap(...args) || reconcileCompilerKeyedArrayStructuralPrepend(...args) || reconcileCompilerKeyedArrayPrepend(...args);
3464
5125
  }
3465
5126
  function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, instances, reactOwnedRows) {
3466
5127
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
@@ -3507,7 +5168,7 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
3507
5168
  for (let index = 0; index < survivors.length; index += 1) {
3508
5169
  survivors[index].index = index;
3509
5170
  }
3510
- return new Map(survivors.map((instance) => [instance.key, instance]));
5171
+ return keyedRowInstancesByKey(survivors);
3511
5172
  }
3512
5173
  function createKeyedRowConditionalRuntime() {
3513
5174
  class FarmKeyedRowConditional extends React__default.default.Component {
@@ -3681,7 +5342,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3681
5342
  this.hasReactOwnedRows()
3682
5343
  );
3683
5344
  if (appendedInstances) {
3684
- this.instances = new Map(appendedInstances);
5345
+ this.instances = appendedInstances instanceof Map ? appendedInstances : new Map(appendedInstances);
3685
5346
  this.rebuildElementIndex(this.instances);
3686
5347
  this.commitCurrentCollection(dirtyState);
3687
5348
  afterCommit?.();
@@ -3714,8 +5375,14 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3714
5375
  this.hasReactOwnedRows()
3715
5376
  );
3716
5377
  if (reorderedInstances) {
5378
+ const removedRows = reorderedInstances.size < this.instances.size;
3717
5379
  this.instances = new Map(reorderedInstances);
3718
5380
  this.rebuildElementIndex(this.instances);
5381
+ if (removedRows) {
5382
+ const keys = [...this.instances.keys()];
5383
+ this.pruneEventHandlers(keys);
5384
+ this.pruneConditionalListeners(keys);
5385
+ }
3719
5386
  this.commitCurrentCollection(dirtyState);
3720
5387
  afterCommit?.();
3721
5388
  return;
@@ -3871,7 +5538,10 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3871
5538
  }
3872
5539
  }
3873
5540
  commitCurrentCollection(dirtyState) {
3874
- this.collectionToken = options.keyedUpdates?.commit(this.currentProps.items());
5541
+ this.collectionToken = options.keyedUpdates?.commit(
5542
+ this.currentProps.items(),
5543
+ this.instances
5544
+ );
3875
5545
  this.commitKeyedTargets(dirtyState);
3876
5546
  }
3877
5547
  hasSafeMembershipTargets(dirtyState) {
@@ -4382,7 +6052,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
4382
6052
  } else {
4383
6053
  reorderCompilerKeyedRows(this.root, nextInstances, sequence, null);
4384
6054
  }
4385
- this.instances = new Map(nextInstances.map((instance) => [instance.key, instance]));
6055
+ this.instances = keyedRowInstancesByKey(nextInstances);
4386
6056
  this.rebuildElementIndex(this.instances);
4387
6057
  this.pruneEventHandlers(rows.keys);
4388
6058
  this.pruneConditionalListeners(rows.keys);
@@ -4899,6 +6569,14 @@ var keyedRowsReorderHintedRuntimeFeature = {
4899
6569
  })
4900
6570
  })
4901
6571
  };
6572
+ var keyedRowsMapReorderHintedRuntimeFeature = {
6573
+ name: "keyed-rows:map-reorder-hinted",
6574
+ create: (owner) => ({
6575
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6576
+ keyedUpdates: keyedMapReorderUpdateRuntime
6577
+ })
6578
+ })
6579
+ };
4902
6580
  var keyedRowsAllHintedRuntimeFeature = {
4903
6581
  name: "keyed-rows:all-hinted",
4904
6582
  create: (owner) => ({
@@ -4939,6 +6617,38 @@ var keyedRowsFilterHintedRuntimeFeature = {
4939
6617
  })
4940
6618
  })
4941
6619
  };
6620
+ var keyedRowsStructuralAppendHintedRuntimeFeature = {
6621
+ name: "keyed-rows:structural-append-hinted",
6622
+ create: (owner) => ({
6623
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6624
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6625
+ })
6626
+ })
6627
+ };
6628
+ var keyedRowsStructuralAppendMapHintedRuntimeFeature = {
6629
+ name: "keyed-rows:structural-append-map-hinted",
6630
+ create: (owner) => ({
6631
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6632
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6633
+ })
6634
+ })
6635
+ };
6636
+ var keyedRowsStructuralPrependHintedRuntimeFeature = {
6637
+ name: "keyed-rows:structural-prepend-hinted",
6638
+ create: (owner) => ({
6639
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6640
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6641
+ })
6642
+ })
6643
+ };
6644
+ var keyedRowsStructuralPrependMapHintedRuntimeFeature = {
6645
+ name: "keyed-rows:structural-prepend-map-hinted",
6646
+ create: (owner) => ({
6647
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6648
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6649
+ })
6650
+ })
6651
+ };
4942
6652
  var keyedRowsPrependHintedRuntimeFeature = {
4943
6653
  name: "keyed-rows:prepend-hinted",
4944
6654
  create: (owner) => ({
@@ -4951,7 +6661,7 @@ var keyedRowsFilterPrependHintedRuntimeFeature = {
4951
6661
  name: "keyed-rows:filter-prepend-hinted",
4952
6662
  create: (owner) => ({
4953
6663
  KeyedRows: createKeyedRowsBlockComponent(owner, {
4954
- keyedUpdates: keyedFilterPrependUpdateRuntime
6664
+ keyedUpdates: keyedStructuralPrependUpdateRuntime
4955
6665
  })
4956
6666
  })
4957
6667
  };
@@ -5053,6 +6763,42 @@ var keyedRowsConditionalFilterHintedRuntimeFeature = {
5053
6763
  })
5054
6764
  })
5055
6765
  };
6766
+ var keyedRowsConditionalStructuralAppendHintedRuntimeFeature = {
6767
+ name: "keyed-rows:conditional:structural-append-hinted",
6768
+ create: (owner) => ({
6769
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6770
+ conditionals: createKeyedRowConditionalRuntime(),
6771
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6772
+ })
6773
+ })
6774
+ };
6775
+ var keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature = {
6776
+ name: "keyed-rows:conditional:structural-append-map-hinted",
6777
+ create: (owner) => ({
6778
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6779
+ conditionals: createKeyedRowConditionalRuntime(),
6780
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6781
+ })
6782
+ })
6783
+ };
6784
+ var keyedRowsConditionalStructuralPrependHintedRuntimeFeature = {
6785
+ name: "keyed-rows:conditional:structural-prepend-hinted",
6786
+ create: (owner) => ({
6787
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6788
+ conditionals: createKeyedRowConditionalRuntime(),
6789
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6790
+ })
6791
+ })
6792
+ };
6793
+ var keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature = {
6794
+ name: "keyed-rows:conditional:structural-prepend-map-hinted",
6795
+ create: (owner) => ({
6796
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6797
+ conditionals: createKeyedRowConditionalRuntime(),
6798
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6799
+ })
6800
+ })
6801
+ };
5056
6802
  var keyedRowsConditionalPrependHintedRuntimeFeature = {
5057
6803
  name: "keyed-rows:conditional:prepend-hinted",
5058
6804
  create: (owner) => ({
@@ -5169,6 +6915,42 @@ var keyedRowsHostFilterHintedRuntimeFeature = {
5169
6915
  })
5170
6916
  })
5171
6917
  };
6918
+ var keyedRowsHostStructuralAppendHintedRuntimeFeature = {
6919
+ name: "keyed-rows:host:structural-append-hinted",
6920
+ create: (owner) => ({
6921
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6922
+ hostBlocks: createKeyedRowHostRuntime(),
6923
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6924
+ })
6925
+ })
6926
+ };
6927
+ var keyedRowsHostStructuralAppendMapHintedRuntimeFeature = {
6928
+ name: "keyed-rows:host:structural-append-map-hinted",
6929
+ create: (owner) => ({
6930
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6931
+ hostBlocks: createKeyedRowHostRuntime(),
6932
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6933
+ })
6934
+ })
6935
+ };
6936
+ var keyedRowsHostStructuralPrependHintedRuntimeFeature = {
6937
+ name: "keyed-rows:host:structural-prepend-hinted",
6938
+ create: (owner) => ({
6939
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6940
+ hostBlocks: createKeyedRowHostRuntime(),
6941
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6942
+ })
6943
+ })
6944
+ };
6945
+ var keyedRowsHostStructuralPrependMapHintedRuntimeFeature = {
6946
+ name: "keyed-rows:host:structural-prepend-map-hinted",
6947
+ create: (owner) => ({
6948
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6949
+ hostBlocks: createKeyedRowHostRuntime(),
6950
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6951
+ })
6952
+ })
6953
+ };
5172
6954
  var keyedRowsHostPrependHintedRuntimeFeature = {
5173
6955
  name: "keyed-rows:host:prepend-hinted",
5174
6956
  create: (owner) => ({
@@ -5296,6 +7078,46 @@ var keyedRowsCompleteFilterHintedRuntimeFeature = {
5296
7078
  })
5297
7079
  })
5298
7080
  };
7081
+ var keyedRowsCompleteStructuralAppendHintedRuntimeFeature = {
7082
+ name: "keyed-rows:complete:structural-append-hinted",
7083
+ create: (owner) => ({
7084
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7085
+ conditionals: createKeyedRowConditionalRuntime(),
7086
+ hostBlocks: createKeyedRowHostRuntime(),
7087
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
7088
+ })
7089
+ })
7090
+ };
7091
+ var keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature = {
7092
+ name: "keyed-rows:complete:structural-append-map-hinted",
7093
+ create: (owner) => ({
7094
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7095
+ conditionals: createKeyedRowConditionalRuntime(),
7096
+ hostBlocks: createKeyedRowHostRuntime(),
7097
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
7098
+ })
7099
+ })
7100
+ };
7101
+ var keyedRowsCompleteStructuralPrependHintedRuntimeFeature = {
7102
+ name: "keyed-rows:complete:structural-prepend-hinted",
7103
+ create: (owner) => ({
7104
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7105
+ conditionals: createKeyedRowConditionalRuntime(),
7106
+ hostBlocks: createKeyedRowHostRuntime(),
7107
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
7108
+ })
7109
+ })
7110
+ };
7111
+ var keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature = {
7112
+ name: "keyed-rows:complete:structural-prepend-map-hinted",
7113
+ create: (owner) => ({
7114
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7115
+ conditionals: createKeyedRowConditionalRuntime(),
7116
+ hostBlocks: createKeyedRowHostRuntime(),
7117
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
7118
+ })
7119
+ })
7120
+ };
5299
7121
  var keyedRowsCompletePrependHintedRuntimeFeature = {
5300
7122
  name: "keyed-rows:complete:prepend-hinted",
5301
7123
  create: (owner) => ({
@@ -5316,6 +7138,16 @@ var keyedRowsCompleteFilterPrependHintedRuntimeFeature = {
5316
7138
  })
5317
7139
  })
5318
7140
  };
7141
+ var keyedRowsCompleteCompatibilityRuntimeFeature = {
7142
+ name: "keyed-rows:complete:compatibility",
7143
+ create: (owner) => ({
7144
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7145
+ conditionals: createKeyedRowConditionalRuntime(),
7146
+ hostBlocks: createKeyedRowHostRuntime(),
7147
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
7148
+ })
7149
+ })
7150
+ };
5319
7151
  var keyedRangesRuntimeFeature = {
5320
7152
  name: "keyed-ranges",
5321
7153
  create: (owner) => ({
@@ -5788,7 +7620,7 @@ var COMPLETE_RUNTIME_FEATURES = [
5788
7620
  hostConditionalRuntimeFeature,
5789
7621
  conditionalRangesRuntimeFeature,
5790
7622
  keyedListRuntimeFeature,
5791
- keyedRowsCompleteWindowEveryHintedRuntimeFeature,
7623
+ keyedRowsCompleteCompatibilityRuntimeFeature,
5792
7624
  keyedRangesRuntimeFeature,
5793
7625
  mixedRangesRuntimeFeature,
5794
7626
  componentRuntimeFeature
@@ -5806,15 +7638,27 @@ exports.createCompiledComponentWithFeatures = createCompiledComponentWithFeature
5806
7638
  exports.createCompilerKeyedArrayAppend = createCompilerKeyedArrayAppend;
5807
7639
  exports.createCompilerKeyedArrayBatchInsert = createCompilerKeyedArrayBatchInsert;
5808
7640
  exports.createCompilerKeyedArrayFilter = createCompilerKeyedArrayFilter;
7641
+ exports.createCompilerKeyedArrayMapPipeline = createCompilerKeyedArrayMapPipeline;
7642
+ exports.createCompilerKeyedArrayMapReorder = createCompilerKeyedArrayMapReorder;
7643
+ exports.createCompilerKeyedArrayMappedStructuralAppend = createCompilerKeyedArrayMappedStructuralAppend;
7644
+ exports.createCompilerKeyedArrayMappedStructuralPrepend = createCompilerKeyedArrayMappedStructuralPrepend;
5809
7645
  exports.createCompilerKeyedArrayPositionUpdate = createCompilerKeyedArrayPositionUpdate;
5810
7646
  exports.createCompilerKeyedArrayPrepend = createCompilerKeyedArrayPrepend;
7647
+ exports.createCompilerKeyedArrayQueuedMapPipeline = createCompilerKeyedArrayQueuedMapPipeline;
5811
7648
  exports.createCompilerKeyedArrayReorder = createCompilerKeyedArrayReorder;
5812
7649
  exports.createCompilerKeyedArrayRollingWindow = createCompilerKeyedArrayRollingWindow;
5813
7650
  exports.createCompilerKeyedArraySlice = createCompilerKeyedArraySlice;
5814
7651
  exports.createCompilerKeyedArraySort = createCompilerKeyedArraySort;
7652
+ exports.createCompilerKeyedArrayStructuralAppend = createCompilerKeyedArrayStructuralAppend;
7653
+ exports.createCompilerKeyedArrayStructuralAppendMapPipeline = createCompilerKeyedArrayStructuralAppendMapPipeline;
7654
+ exports.createCompilerKeyedArrayStructuralPrepend = createCompilerKeyedArrayStructuralPrepend;
7655
+ exports.createCompilerKeyedArrayStructuralPrependMapPipeline = createCompilerKeyedArrayStructuralPrependMapPipeline;
7656
+ exports.createCompilerKeyedArrayStructuralReorder = createCompilerKeyedArrayStructuralReorder;
7657
+ exports.createCompilerKeyedArrayStructuralSort = createCompilerKeyedArrayStructuralSort;
5815
7658
  exports.createCompilerKeyedArrayWindowReplace = createCompilerKeyedArrayWindowReplace;
5816
7659
  exports.createCompilerKeyedCollectionUpdate = createCompilerKeyedCollectionUpdate;
5817
7660
  exports.createCompilerKeyedMapUpdate = createCompilerKeyedMapUpdate;
7661
+ exports.finalizeCompilerKeyedArrayMappedStructuralUpdate = finalizeCompilerKeyedArrayMappedStructuralUpdate;
5818
7662
  exports.hostConditionalRuntimeFeature = hostConditionalRuntimeFeature;
5819
7663
  exports.keyedListRuntimeFeature = keyedListRuntimeFeature;
5820
7664
  exports.keyedRangesRuntimeFeature = keyedRangesRuntimeFeature;
@@ -5832,6 +7676,10 @@ exports.keyedRowsCompletePositionHintedRuntimeFeature = keyedRowsCompletePositio
5832
7676
  exports.keyedRowsCompletePrependHintedRuntimeFeature = keyedRowsCompletePrependHintedRuntimeFeature;
5833
7677
  exports.keyedRowsCompleteReorderHintedRuntimeFeature = keyedRowsCompleteReorderHintedRuntimeFeature;
5834
7678
  exports.keyedRowsCompleteRuntimeFeature = keyedRowsCompleteRuntimeFeature;
7679
+ exports.keyedRowsCompleteStructuralAppendHintedRuntimeFeature = keyedRowsCompleteStructuralAppendHintedRuntimeFeature;
7680
+ exports.keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature = keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature;
7681
+ exports.keyedRowsCompleteStructuralPrependHintedRuntimeFeature = keyedRowsCompleteStructuralPrependHintedRuntimeFeature;
7682
+ exports.keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature = keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature;
5835
7683
  exports.keyedRowsCompleteWindowEveryHintedRuntimeFeature = keyedRowsCompleteWindowEveryHintedRuntimeFeature;
5836
7684
  exports.keyedRowsCompleteWindowPositionHintedRuntimeFeature = keyedRowsCompleteWindowPositionHintedRuntimeFeature;
5837
7685
  exports.keyedRowsConditionalAllHintedRuntimeFeature = keyedRowsConditionalAllHintedRuntimeFeature;
@@ -5845,6 +7693,10 @@ exports.keyedRowsConditionalPositionHintedRuntimeFeature = keyedRowsConditionalP
5845
7693
  exports.keyedRowsConditionalPrependHintedRuntimeFeature = keyedRowsConditionalPrependHintedRuntimeFeature;
5846
7694
  exports.keyedRowsConditionalReorderHintedRuntimeFeature = keyedRowsConditionalReorderHintedRuntimeFeature;
5847
7695
  exports.keyedRowsConditionalRuntimeFeature = keyedRowsConditionalRuntimeFeature;
7696
+ exports.keyedRowsConditionalStructuralAppendHintedRuntimeFeature = keyedRowsConditionalStructuralAppendHintedRuntimeFeature;
7697
+ exports.keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature = keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature;
7698
+ exports.keyedRowsConditionalStructuralPrependHintedRuntimeFeature = keyedRowsConditionalStructuralPrependHintedRuntimeFeature;
7699
+ exports.keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature = keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature;
5848
7700
  exports.keyedRowsConditionalWindowEveryHintedRuntimeFeature = keyedRowsConditionalWindowEveryHintedRuntimeFeature;
5849
7701
  exports.keyedRowsConditionalWindowPositionHintedRuntimeFeature = keyedRowsConditionalWindowPositionHintedRuntimeFeature;
5850
7702
  exports.keyedRowsEveryHintedRuntimeFeature = keyedRowsEveryHintedRuntimeFeature;
@@ -5862,12 +7714,21 @@ exports.keyedRowsHostPositionHintedRuntimeFeature = keyedRowsHostPositionHintedR
5862
7714
  exports.keyedRowsHostPrependHintedRuntimeFeature = keyedRowsHostPrependHintedRuntimeFeature;
5863
7715
  exports.keyedRowsHostReorderHintedRuntimeFeature = keyedRowsHostReorderHintedRuntimeFeature;
5864
7716
  exports.keyedRowsHostRuntimeFeature = keyedRowsHostRuntimeFeature;
7717
+ exports.keyedRowsHostStructuralAppendHintedRuntimeFeature = keyedRowsHostStructuralAppendHintedRuntimeFeature;
7718
+ exports.keyedRowsHostStructuralAppendMapHintedRuntimeFeature = keyedRowsHostStructuralAppendMapHintedRuntimeFeature;
7719
+ exports.keyedRowsHostStructuralPrependHintedRuntimeFeature = keyedRowsHostStructuralPrependHintedRuntimeFeature;
7720
+ exports.keyedRowsHostStructuralPrependMapHintedRuntimeFeature = keyedRowsHostStructuralPrependMapHintedRuntimeFeature;
5865
7721
  exports.keyedRowsHostWindowEveryHintedRuntimeFeature = keyedRowsHostWindowEveryHintedRuntimeFeature;
5866
7722
  exports.keyedRowsHostWindowPositionHintedRuntimeFeature = keyedRowsHostWindowPositionHintedRuntimeFeature;
7723
+ exports.keyedRowsMapReorderHintedRuntimeFeature = keyedRowsMapReorderHintedRuntimeFeature;
5867
7724
  exports.keyedRowsPositionHintedRuntimeFeature = keyedRowsPositionHintedRuntimeFeature;
5868
7725
  exports.keyedRowsPrependHintedRuntimeFeature = keyedRowsPrependHintedRuntimeFeature;
5869
7726
  exports.keyedRowsReorderHintedRuntimeFeature = keyedRowsReorderHintedRuntimeFeature;
5870
7727
  exports.keyedRowsRuntimeFeature = keyedRowsRuntimeFeature;
7728
+ exports.keyedRowsStructuralAppendHintedRuntimeFeature = keyedRowsStructuralAppendHintedRuntimeFeature;
7729
+ exports.keyedRowsStructuralAppendMapHintedRuntimeFeature = keyedRowsStructuralAppendMapHintedRuntimeFeature;
7730
+ exports.keyedRowsStructuralPrependHintedRuntimeFeature = keyedRowsStructuralPrependHintedRuntimeFeature;
7731
+ exports.keyedRowsStructuralPrependMapHintedRuntimeFeature = keyedRowsStructuralPrependMapHintedRuntimeFeature;
5871
7732
  exports.keyedRowsWindowEveryHintedRuntimeFeature = keyedRowsWindowEveryHintedRuntimeFeature;
5872
7733
  exports.keyedRowsWindowPositionHintedRuntimeFeature = keyedRowsWindowPositionHintedRuntimeFeature;
5873
7734
  exports.mixedRangesRuntimeFeature = mixedRangesRuntimeFeature;