@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.
@@ -19,6 +19,9 @@ function materializeIterable(source) {
19
19
  }
20
20
 
21
21
  // src/compiler-runtime.tsx
22
+ function reversedCompilerKeyedArrayOrder(order) {
23
+ return order === 0 /* Reverse */ ? void 0 : order ?? 0 /* Reverse */;
24
+ }
22
25
  var COMPILER_KEYED_COLLECTION_TOKENS = /* @__PURE__ */ new WeakMap();
23
26
  var COMPILER_KEYED_MAP_UPDATES = /* @__PURE__ */ new WeakMap();
24
27
  var COMPILER_KEYED_ARRAY_APPENDS = /* @__PURE__ */ new WeakMap();
@@ -32,9 +35,11 @@ var COMPILER_KEYED_ARRAY_REORDERS = /* @__PURE__ */ new WeakMap();
32
35
  var COMPILER_KEYED_COLLECTION_DRAFTS = /* @__PURE__ */ new WeakMap();
33
36
  var COMPILER_KEYED_COLLECTION_UPDATES = /* @__PURE__ */ new WeakMap();
34
37
  var COMPILER_KEYED_COMMITTED_COLLECTIONS = /* @__PURE__ */ new WeakSet();
38
+ var COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS = /* @__PURE__ */ new WeakMap();
35
39
  var NATIVE_ARRAY_PROTOTYPE = Array.prototype;
36
40
  var NATIVE_ARRAY_ITERATOR = Array.prototype[Symbol.iterator];
37
41
  var NATIVE_ARRAY_FILTER = Array.prototype.filter;
42
+ var NATIVE_ARRAY_MAP = Array.prototype.map;
38
43
  var NATIVE_ARRAY_SLICE = Array.prototype.slice;
39
44
  var NATIVE_ARRAY_TO_SPLICED = Array.prototype.toSpliced;
40
45
  var NATIVE_ARRAY_WITH = Array.prototype.with;
@@ -60,6 +65,26 @@ function commitCompilerKeyedCollection(value) {
60
65
  COMPILER_KEYED_COMMITTED_COLLECTIONS.add(target);
61
66
  return compilerKeyedCollectionToken(target);
62
67
  }
68
+ function commitCompilerKeyedCollectionWithItemSnapshot(value, instances) {
69
+ const token = commitCompilerKeyedCollection(value);
70
+ if (!token) return void 0;
71
+ if (!instances) {
72
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.delete(token);
73
+ return token;
74
+ }
75
+ const items = [];
76
+ let index = 0;
77
+ for (const instance of instances.values()) {
78
+ if (instance.index !== index) {
79
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.delete(token);
80
+ return token;
81
+ }
82
+ items.push(instance.item);
83
+ index += 1;
84
+ }
85
+ COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.set(token, items);
86
+ return token;
87
+ }
63
88
  function compilerKeyedMapChangedIndices(value, sourceToken) {
64
89
  const target = compilerObject(value);
65
90
  if (!target || !sourceToken) return void 0;
@@ -89,11 +114,52 @@ function compilerKeyedArrayAppendStart(value, sourceToken, expectedStart) {
89
114
  }
90
115
  return length === value.length ? expectedStart : void 0;
91
116
  }
117
+ function compilerKeyedArrayStructuralAppendUpdate(value, sourceToken, expectedStart) {
118
+ const target = compilerObject(value);
119
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
120
+ const update = COMPILER_KEYED_ARRAY_APPENDS.get(target);
121
+ if (!update || update.sourceToken !== sourceToken) return void 0;
122
+ const updates = [];
123
+ for (let current = update; current; current = current.previous) {
124
+ if (current.sourceToken !== sourceToken) return void 0;
125
+ updates.push(current);
126
+ }
127
+ updates.reverse();
128
+ const structuralUpdate = update.structuralUpdate;
129
+ const first = updates[0];
130
+ const survivorResult = structuralUpdate ? compilerKeyedArrayFilterSurvivorsFromUpdate(
131
+ structuralUpdate,
132
+ sourceToken,
133
+ expectedStart,
134
+ first.startIndex
135
+ ) : void 0;
136
+ if (structuralUpdate && !survivorResult) return void 0;
137
+ let length = structuralUpdate ? first.startIndex : expectedStart;
138
+ const startIndex = length;
139
+ for (const current of updates) {
140
+ if (current.startIndex !== length || current.resultLength < length) return void 0;
141
+ length = current.resultLength;
142
+ }
143
+ return length === value.length ? {
144
+ startIndex,
145
+ structuralUpdate,
146
+ ...survivorResult ? { structuralSurvivors: survivorResult } : {}
147
+ } : void 0;
148
+ }
92
149
  function compilerKeyedArrayFilterSurvivors(value, sourceToken, expectedLength) {
93
150
  const target = compilerObject(value);
94
151
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
95
152
  const update = COMPILER_KEYED_ARRAY_FILTERS.get(target);
96
153
  if (!update || update.sourceToken !== sourceToken) return void 0;
154
+ return compilerKeyedArrayFilterSurvivorsFromUpdate(
155
+ update,
156
+ sourceToken,
157
+ expectedLength,
158
+ value.length
159
+ );
160
+ }
161
+ function compilerKeyedArrayFilterSurvivorsFromUpdate(update, sourceToken, expectedLength, resultLength) {
162
+ if (!sourceToken || update.sourceToken !== sourceToken) return void 0;
97
163
  const updates = [];
98
164
  for (let current = update; current; current = current.previous) {
99
165
  if (current.sourceToken !== sourceToken) return void 0;
@@ -123,7 +189,80 @@ function compilerKeyedArrayFilterSurvivors(value, sourceToken, expectedLength) {
123
189
  if (current.resultLength !== current.sourceLength - removed.size) return void 0;
124
190
  survivors = survivors.filter((_sourceIndex, index) => !removed.has(index));
125
191
  }
126
- return survivors.length === value.length ? { indices: survivors, keysStable } : void 0;
192
+ return survivors.length === resultLength ? { indices: survivors, keysStable } : void 0;
193
+ }
194
+ function compilerKeyedArraySliceSurvivorRangeFromUpdate(update, sourceToken, expectedLength, resultLength) {
195
+ if (!sourceToken || update.sourceToken !== sourceToken) return void 0;
196
+ const updates = [];
197
+ for (let current = update; current; current = current.previous) {
198
+ if (current.sourceToken !== sourceToken || current.kind !== "slice") return void 0;
199
+ updates.push(current);
200
+ }
201
+ let length = expectedLength;
202
+ let start = 0;
203
+ for (let index = updates.length - 1; index >= 0; index -= 1) {
204
+ const current = updates[index];
205
+ const retainedStart = current.retainedStart;
206
+ const retainedEnd = current.retainedEnd;
207
+ 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) {
208
+ return void 0;
209
+ }
210
+ start += retainedStart;
211
+ length = current.resultLength;
212
+ }
213
+ return length === resultLength ? { end: start + length, start } : void 0;
214
+ }
215
+ function compilerKeyedArrayStructuralAppendMapUpdate(value, sourceToken, expectedStart, requireMappedUpdate = false) {
216
+ const target = compilerObject(value);
217
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
218
+ const update = COMPILER_KEYED_ARRAY_APPENDS.get(target);
219
+ if (!update || update.sourceToken !== sourceToken || !update.structuralUpdate || requireMappedUpdate && !update.mappedItemSources) {
220
+ return void 0;
221
+ }
222
+ const updates = [];
223
+ for (let current = update; current; current = current.previous) {
224
+ if (current.sourceToken !== sourceToken) return void 0;
225
+ updates.push(current);
226
+ }
227
+ updates.reverse();
228
+ const first = updates[0];
229
+ const structuralSurvivorRange = compilerKeyedArraySliceSurvivorRangeFromUpdate(
230
+ update.structuralUpdate,
231
+ sourceToken,
232
+ expectedStart,
233
+ first.startIndex
234
+ );
235
+ const structuralSurvivors = structuralSurvivorRange ? void 0 : compilerKeyedArrayFilterSurvivorsFromUpdate(
236
+ update.structuralUpdate,
237
+ sourceToken,
238
+ expectedStart,
239
+ first.startIndex
240
+ )?.indices;
241
+ if (!structuralSurvivorRange && !structuralSurvivors) return void 0;
242
+ let length = first.startIndex;
243
+ const startIndex = length;
244
+ for (const current of updates) {
245
+ if (current.startIndex !== length || current.resultLength < length) return void 0;
246
+ length = current.resultLength;
247
+ }
248
+ return length === value.length ? {
249
+ startIndex,
250
+ ...structuralSurvivorRange ? { structuralSurvivorRange } : {},
251
+ ...structuralSurvivors ? { structuralSurvivors } : {},
252
+ ...update.mappedItemSources ? { mappedItemSources: update.mappedItemSources } : {},
253
+ ...update.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {}
254
+ } : void 0;
255
+ }
256
+ function compilerKeyedArrayFilterSource(update, resultLength) {
257
+ if (update.resultLength !== resultLength) return void 0;
258
+ let current = update;
259
+ while (current.previous) {
260
+ if (current.sourceToken !== current.previous.sourceToken || current.sourceLength !== current.previous.resultLength) {
261
+ return void 0;
262
+ }
263
+ current = current.previous;
264
+ }
265
+ return { sourceLength: current.sourceLength, sourceToken: current.sourceToken };
127
266
  }
128
267
  function compilerKeyedArrayPrependLength(value, sourceToken, expectedLength) {
129
268
  const target = compilerObject(value);
@@ -147,14 +286,104 @@ function compilerKeyedArrayPrependLength(value, sourceToken, expectedLength) {
147
286
  }
148
287
  return length === value.length ? prefixLength : void 0;
149
288
  }
150
- function compilerKeyedArrayRollingWindow(value, sourceToken, expectedLength) {
289
+ function compilerKeyedArrayStructuralPrependUpdate(value, sourceToken, expectedLength) {
151
290
  const target = compilerObject(value);
152
291
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
153
- const update = COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(target);
154
- 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) {
292
+ const update = COMPILER_KEYED_ARRAY_PREPENDS.get(target);
293
+ if (!update || update.sourceToken !== sourceToken) return void 0;
294
+ const updates = [];
295
+ for (let current = update; current; current = current.previous) {
296
+ if (current.sourceToken !== sourceToken) return void 0;
297
+ updates.push(current);
298
+ }
299
+ updates.reverse();
300
+ const structuralUpdate = update.structuralUpdate;
301
+ const first = updates[0];
302
+ const survivorResult = structuralUpdate ? compilerKeyedArrayFilterSurvivorsFromUpdate(
303
+ structuralUpdate,
304
+ sourceToken,
305
+ expectedLength,
306
+ first.sourceLength
307
+ ) : void 0;
308
+ if (structuralUpdate && !survivorResult) return void 0;
309
+ let length = structuralUpdate ? first.sourceLength : expectedLength;
310
+ let prefixLength = 0;
311
+ for (const current of updates) {
312
+ if (current.sourceLength !== length || current.prefixLength < 1 || current.resultLength !== current.sourceLength + current.prefixLength) {
313
+ return void 0;
314
+ }
315
+ length = current.resultLength;
316
+ prefixLength += current.prefixLength;
317
+ }
318
+ return length === value.length ? {
319
+ prefixLength,
320
+ structuralUpdate,
321
+ ...survivorResult ? { structuralSurvivors: survivorResult } : {}
322
+ } : void 0;
323
+ }
324
+ function compilerKeyedArrayStructuralPrependMapUpdate(value, sourceToken, expectedLength, requireMappedUpdate = false) {
325
+ const target = compilerObject(value);
326
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
327
+ const update = COMPILER_KEYED_ARRAY_PREPENDS.get(target);
328
+ if (!update || update.sourceToken !== sourceToken || !update.structuralUpdate || requireMappedUpdate && !update.mappedItemSources) {
155
329
  return void 0;
156
330
  }
157
- return update;
331
+ const updates = [];
332
+ for (let current = update; current; current = current.previous) {
333
+ if (current.sourceToken !== sourceToken) return void 0;
334
+ updates.push(current);
335
+ }
336
+ updates.reverse();
337
+ const first = updates[0];
338
+ const structuralSurvivorRange = compilerKeyedArraySliceSurvivorRangeFromUpdate(
339
+ update.structuralUpdate,
340
+ sourceToken,
341
+ expectedLength,
342
+ first.sourceLength
343
+ );
344
+ const structuralSurvivors = structuralSurvivorRange ? void 0 : compilerKeyedArrayFilterSurvivorsFromUpdate(
345
+ update.structuralUpdate,
346
+ sourceToken,
347
+ expectedLength,
348
+ first.sourceLength
349
+ )?.indices;
350
+ if (!structuralSurvivorRange && !structuralSurvivors) return void 0;
351
+ let length = first.sourceLength;
352
+ let prefixLength = 0;
353
+ for (const current of updates) {
354
+ if (current.sourceLength !== length || current.prefixLength < 1 || current.resultLength !== current.sourceLength + current.prefixLength) {
355
+ return void 0;
356
+ }
357
+ length = current.resultLength;
358
+ prefixLength += current.prefixLength;
359
+ }
360
+ return length === value.length ? {
361
+ prefixLength,
362
+ ...structuralSurvivorRange ? { structuralSurvivorRange } : {},
363
+ ...structuralSurvivors ? { structuralSurvivors } : {},
364
+ ...update.mappedItemSources ? { mappedItemSources: update.mappedItemSources } : {},
365
+ ...update.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {}
366
+ } : void 0;
367
+ }
368
+ function compilerKeyedArrayRollingWindows(value, sourceToken, expectedLength) {
369
+ const target = compilerObject(value);
370
+ if (!target || !sourceToken || !Array.isArray(value)) return void 0;
371
+ const update = COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(target);
372
+ if (!update || update.sourceToken !== sourceToken) return void 0;
373
+ const updates = [];
374
+ for (let current = update; current; current = current.previous) {
375
+ if (current.sourceToken !== sourceToken) return void 0;
376
+ updates.push(current);
377
+ }
378
+ updates.reverse();
379
+ let length = expectedLength;
380
+ for (const current of updates) {
381
+ if (current.sourceLength !== length || current.retainedStart < 1 || current.retainedStart > current.sourceLength || current.retainedEnd !== current.sourceLength || current.resultLength <= current.retainedEnd - current.retainedStart) {
382
+ return void 0;
383
+ }
384
+ length = current.resultLength;
385
+ }
386
+ return length === value.length ? updates : void 0;
158
387
  }
159
388
  function compilerKeyedArrayPosition(value, sourceToken, expectedLength) {
160
389
  const target = compilerObject(value);
@@ -198,7 +427,7 @@ function compilerKeyedArrayReorder(value, sourceToken, expectedLength) {
198
427
  const target = compilerObject(value);
199
428
  if (!target || !sourceToken || !Array.isArray(value)) return void 0;
200
429
  const update = COMPILER_KEYED_ARRAY_REORDERS.get(target);
201
- if (!update || update.sourceToken !== sourceToken || update.sourceLength !== expectedLength || update.resultLength !== expectedLength || update.resultLength !== value.length) {
430
+ if (!update || update.sourceToken !== sourceToken || update.sourceLength !== expectedLength || !update.structuralUpdate && update.resultLength !== expectedLength || update.resultLength !== value.length) {
202
431
  return void 0;
203
432
  }
204
433
  return update;
@@ -215,7 +444,7 @@ function compilerKeyedCollectionChangedKeys(value, sourceToken, kind) {
215
444
  }
216
445
  return changedKeys;
217
446
  }
218
- function createCompilerKeyedMapUpdate(previous, value, changedIndices) {
447
+ function recordCompilerKeyedMapUpdate(previous, value, changedIndices) {
219
448
  const previousTarget = compilerObject(previous);
220
449
  const valueTarget = compilerObject(value);
221
450
  const sourceToken = compilerKeyedCollectionToken(previousTarget);
@@ -229,6 +458,212 @@ function createCompilerKeyedMapUpdate(previous, value, changedIndices) {
229
458
  }
230
459
  return value;
231
460
  }
461
+ function executeCompilerKeyedMapPipeline(previous, pipeline, record) {
462
+ let eligible = true;
463
+ const applyMap = (collection, method, callback) => {
464
+ const value2 = NATIVE_REFLECT_APPLY(
465
+ method,
466
+ collection,
467
+ [callback]
468
+ );
469
+ if (method !== NATIVE_ARRAY_MAP) {
470
+ eligible = false;
471
+ return value2;
472
+ }
473
+ try {
474
+ if (!Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE) {
475
+ eligible = false;
476
+ }
477
+ } catch {
478
+ eligible = false;
479
+ }
480
+ return value2;
481
+ };
482
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
483
+ return eligible ? record(previous, value) : value;
484
+ }
485
+ function recordCompilerKeyedMapPipelineUpdate(previous, value) {
486
+ try {
487
+ if (!Array.isArray(previous) || !Array.isArray(value) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== previous.length) {
488
+ return value;
489
+ }
490
+ const finalChangedIndices = [];
491
+ for (let index = 0; index < previous.length; index += 1) {
492
+ const previousDescriptor = Object.getOwnPropertyDescriptor(previous, index);
493
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
494
+ if (!previousDescriptor || !("value" in previousDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
495
+ return value;
496
+ }
497
+ if (mappedDescriptor.value !== previousDescriptor.value) finalChangedIndices.push(index);
498
+ }
499
+ return recordCompilerKeyedMapUpdate(previous, value, finalChangedIndices);
500
+ } catch {
501
+ return value;
502
+ }
503
+ }
504
+ function createCompilerKeyedMapUpdate(previous, valueOrPipeline, changedIndices) {
505
+ if (Array.isArray(changedIndices)) {
506
+ return recordCompilerKeyedMapUpdate(previous, valueOrPipeline, changedIndices);
507
+ }
508
+ if (changedIndices !== void 0 || typeof valueOrPipeline !== "function") {
509
+ return valueOrPipeline;
510
+ }
511
+ return executeCompilerKeyedMapPipeline(
512
+ previous,
513
+ valueOrPipeline,
514
+ recordCompilerKeyedMapPipelineUpdate
515
+ );
516
+ }
517
+ function recordCompilerKeyedArrayMapPipeline(previous, value) {
518
+ try {
519
+ const previousTarget = compilerObject(previous);
520
+ const valueTarget = compilerObject(value);
521
+ 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) {
522
+ return value;
523
+ }
524
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
525
+ const previousReorder = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
526
+ const structuralUpdate = previousReorder?.structuralUpdate || (!previousReorder ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0);
527
+ const structuralSource = structuralUpdate ? compilerKeyedArrayFilterSource(structuralUpdate, previous.length) : void 0;
528
+ const previousSource = previousReorder && !previousReorder.structuralUpdate ? previousReorder : void 0;
529
+ if (!committedSource && (!previousSource || previousSource.resultLength !== previous.length) && !structuralSource) {
530
+ return value;
531
+ }
532
+ const sourceToken = previousSource?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
533
+ if (!sourceToken) return value;
534
+ const previousMappedItemSources = previousReorder?.mappedItemSources || structuralUpdate?.mappedItemSources;
535
+ const mappedItemSources = /* @__PURE__ */ new Map();
536
+ for (let index = 0; index < value.length; index += 1) {
537
+ const previousDescriptor = Object.getOwnPropertyDescriptor(previous, index);
538
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
539
+ if (!previousDescriptor || !("value" in previousDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
540
+ return value;
541
+ }
542
+ const previousItem = previousDescriptor.value;
543
+ const sourceItem = previousMappedItemSources?.has(previousItem) ? previousMappedItemSources.get(previousItem) : previousItem;
544
+ const mappedItem = mappedDescriptor.value;
545
+ if (!Object.is(mappedItem, sourceItem)) mappedItemSources.set(mappedItem, sourceItem);
546
+ }
547
+ const hint = {
548
+ kind: committedSource ? void 0 : previousReorder?.kind,
549
+ sourceToken,
550
+ sourceLength: previousSource?.sourceLength ?? structuralSource?.sourceLength ?? previous.length,
551
+ resultLength: value.length,
552
+ mapped: true,
553
+ mappedItemSources,
554
+ ...structuralUpdate ? { structuralUpdate } : {}
555
+ };
556
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, hint);
557
+ } catch {
558
+ }
559
+ return value;
560
+ }
561
+ function createCompilerKeyedArrayMapPipeline(previous, methodOrPipeline, callback) {
562
+ if (callback !== void 0) {
563
+ const value = NATIVE_REFLECT_APPLY(
564
+ methodOrPipeline,
565
+ previous,
566
+ [callback]
567
+ );
568
+ if (methodOrPipeline !== NATIVE_ARRAY_MAP) return value;
569
+ return recordCompilerKeyedArrayMapPipeline(previous, value);
570
+ }
571
+ return executeCompilerKeyedMapPipeline(
572
+ previous,
573
+ methodOrPipeline,
574
+ recordCompilerKeyedArrayMapPipeline
575
+ );
576
+ }
577
+ function recordCompilerKeyedArrayQueuedMapPipeline(previous, value) {
578
+ try {
579
+ const previousTarget = compilerObject(previous);
580
+ const valueTarget = compilerObject(value);
581
+ 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) {
582
+ return value;
583
+ }
584
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
585
+ const previousReorder = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
586
+ if (!committedSource && (!previousReorder || previousReorder.structuralUpdate || previousReorder.resultLength !== previous.length)) {
587
+ return value;
588
+ }
589
+ const sourceToken = previousReorder?.sourceToken || compilerKeyedCollectionToken(previousTarget);
590
+ if (!sourceToken) return value;
591
+ const sourceItems = previousReorder?.mappedItemSources?.queuedSourceItems || previous;
592
+ let mappedItemSources;
593
+ const readMappedItemSources = () => {
594
+ if (mappedItemSources) return mappedItemSources;
595
+ const sources = /* @__PURE__ */ new Map();
596
+ for (let index = 0; index < value.length; index += 1) {
597
+ const sourceDescriptor = Object.getOwnPropertyDescriptor(sourceItems, index);
598
+ const mappedDescriptor = Object.getOwnPropertyDescriptor(value, index);
599
+ if (!sourceDescriptor || !("value" in sourceDescriptor) || !mappedDescriptor || !("value" in mappedDescriptor)) {
600
+ throw new TypeError();
601
+ }
602
+ if (!Object.is(sourceDescriptor.value, mappedDescriptor.value)) {
603
+ sources.set(mappedDescriptor.value, sourceDescriptor.value);
604
+ }
605
+ }
606
+ mappedItemSources = sources;
607
+ return sources;
608
+ };
609
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
610
+ kind: previousReorder?.kind,
611
+ sourceToken,
612
+ sourceLength: previousReorder?.sourceLength ?? previous.length,
613
+ resultLength: value.length,
614
+ mapped: true,
615
+ // Array.map preserves positions. Retain the first queued source collection and validate its
616
+ // data properties against the final collection once, immediately before the DOM commit.
617
+ // This avoids rescanning every intermediate Array produced by separately queued setters.
618
+ mappedItemSources: {
619
+ queuedSourceItems: sourceItems,
620
+ get: (item) => readMappedItemSources().get(item),
621
+ has: (item) => readMappedItemSources().has(item)
622
+ }
623
+ });
624
+ } catch {
625
+ }
626
+ return value;
627
+ }
628
+ function createCompilerKeyedArrayQueuedMapPipeline(previous, pipeline) {
629
+ return executeCompilerKeyedMapPipeline(
630
+ previous,
631
+ pipeline,
632
+ recordCompilerKeyedArrayQueuedMapPipeline
633
+ );
634
+ }
635
+ function createCompilerKeyedArrayMapReorder(previous, method, ...args) {
636
+ const value = NATIVE_REFLECT_APPLY(
637
+ method,
638
+ previous,
639
+ args
640
+ );
641
+ try {
642
+ const previousTarget = compilerObject(previous);
643
+ const valueTarget = compilerObject(value);
644
+ 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")) {
645
+ return value;
646
+ }
647
+ for (let index = 0; index < previous.length; index += 1) {
648
+ if (!Object.prototype.hasOwnProperty.call(previous, index) || !Object.prototype.hasOwnProperty.call(value, index)) {
649
+ return value;
650
+ }
651
+ }
652
+ const previousReorder = COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
653
+ const source = previousReorder?.mapped ? previousReorder : void 0;
654
+ if (!source || source.resultLength !== previous.length) return value;
655
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
656
+ kind: method !== NATIVE_ARRAY_TO_REVERSED ? 1 /* Permutation */ : reversedCompilerKeyedArrayOrder(source.kind),
657
+ sourceToken: source.sourceToken,
658
+ sourceLength: source.sourceLength,
659
+ resultLength: value.length,
660
+ mapped: true,
661
+ mappedItemSources: source.mappedItemSources
662
+ });
663
+ } catch {
664
+ }
665
+ return value;
666
+ }
232
667
  function createCompilerKeyedArrayAppend(previous, value) {
233
668
  try {
234
669
  const previousTarget = compilerObject(previous);
@@ -252,6 +687,187 @@ function createCompilerKeyedArrayAppend(previous, value) {
252
687
  return value;
253
688
  }
254
689
  }
690
+ function createCompilerKeyedArrayStructuralAppend(previous, value) {
691
+ try {
692
+ const previousTarget = compilerObject(previous);
693
+ const valueTarget = compilerObject(value);
694
+ 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) {
695
+ return value;
696
+ }
697
+ const startIndex = previous.length;
698
+ if (value.length < startIndex) return value;
699
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
700
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget);
701
+ const directStructuralUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
702
+ const structuralSource = directStructuralUpdate ? compilerKeyedArrayFilterSource(directStructuralUpdate, previous.length) : void 0;
703
+ const structuralUpdate = previousUpdate?.structuralUpdate || (structuralSource ? directStructuralUpdate : void 0);
704
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
705
+ if (!sourceToken) return value;
706
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
707
+ sourceToken,
708
+ startIndex,
709
+ resultLength: value.length,
710
+ ...structuralUpdate ? { structuralUpdate } : {},
711
+ ...previousUpdate ? { previous: previousUpdate } : {}
712
+ });
713
+ return value;
714
+ } catch {
715
+ return value;
716
+ }
717
+ }
718
+ function createCompilerKeyedArrayMappedStructuralAppend(previous, value) {
719
+ try {
720
+ const previousTarget = compilerObject(previous);
721
+ const valueTarget = compilerObject(value);
722
+ 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) {
723
+ return value;
724
+ }
725
+ const startIndex = previous.length;
726
+ if (value.length < startIndex) return value;
727
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
728
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget);
729
+ const previousMappedUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget) : void 0;
730
+ const mappedStructuralUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.structuralUpdate && previousMappedUpdate.resultLength === previous.length ? previousMappedUpdate : void 0;
731
+ const structuralUpdate = previousUpdate?.structuralUpdate || mappedStructuralUpdate?.structuralUpdate;
732
+ const sourceToken = previousUpdate?.sourceToken || mappedStructuralUpdate?.sourceToken;
733
+ const mappedItemSources = previousUpdate?.mappedItemSources || mappedStructuralUpdate?.mappedItemSources;
734
+ if (!sourceToken || !structuralUpdate || !mappedItemSources) return value;
735
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
736
+ sourceToken,
737
+ startIndex,
738
+ resultLength: value.length,
739
+ structuralUpdate,
740
+ mappedItemSources,
741
+ ...previousUpdate?.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {},
742
+ ...previousUpdate?.mappedItemValues ? { mappedItemValues: previousUpdate.mappedItemValues } : {},
743
+ ...previousUpdate ? { previous: previousUpdate } : {}
744
+ });
745
+ return value;
746
+ } catch {
747
+ return value;
748
+ }
749
+ }
750
+ function createCompilerKeyedArrayStructuralAppendMapPipeline(previous, pipeline) {
751
+ let appendUpdate;
752
+ let committedItems;
753
+ let survivorRange;
754
+ let survivorIndices;
755
+ let mappedItemSources = /* @__PURE__ */ new Map();
756
+ let mappedItemValues = /* @__PURE__ */ new Map();
757
+ try {
758
+ const previousTarget = compilerObject(previous);
759
+ if (!previousTarget || !Array.isArray(previous) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || !(appendUpdate = COMPILER_KEYED_ARRAY_APPENDS.get(previousTarget)) || !appendUpdate.structuralUpdate || appendUpdate.resultLength !== previous.length) {
760
+ appendUpdate = void 0;
761
+ } else {
762
+ committedItems = COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.get(appendUpdate.sourceToken);
763
+ const structuralAppend = committedItems ? compilerKeyedArrayStructuralAppendMapUpdate(
764
+ previous,
765
+ appendUpdate.sourceToken,
766
+ committedItems.length
767
+ ) : void 0;
768
+ survivorRange = structuralAppend?.structuralSurvivorRange;
769
+ survivorIndices = structuralAppend?.structuralSurvivors;
770
+ if (!survivorRange && !survivorIndices) {
771
+ appendUpdate = void 0;
772
+ } else {
773
+ if (appendUpdate.mappedSurvivorsValidated && appendUpdate.mappedItemSources) {
774
+ mappedItemSources = new Map(
775
+ appendUpdate.mappedItemSources
776
+ );
777
+ }
778
+ if (appendUpdate.mappedItemValues) {
779
+ mappedItemValues = new Map(appendUpdate.mappedItemValues);
780
+ }
781
+ }
782
+ }
783
+ } catch {
784
+ appendUpdate = void 0;
785
+ }
786
+ let eligible = appendUpdate !== void 0;
787
+ const applyMap = (collection, method, callback) => {
788
+ if (method !== NATIVE_ARRAY_MAP || !eligible) {
789
+ const value3 = NATIVE_REFLECT_APPLY(
790
+ method,
791
+ collection,
792
+ [callback]
793
+ );
794
+ if (method !== NATIVE_ARRAY_MAP) eligible = false;
795
+ return value3;
796
+ }
797
+ let expectedIndex = 0;
798
+ let expectedLength = -1;
799
+ try {
800
+ if (!Array.isArray(collection) || Object.getPrototypeOf(collection) !== NATIVE_ARRAY_PROTOTYPE) {
801
+ eligible = false;
802
+ } else {
803
+ expectedLength = collection.length;
804
+ }
805
+ } catch {
806
+ eligible = false;
807
+ }
808
+ const wrappedCallback = (item, index, source) => {
809
+ if (index !== expectedIndex) eligible = false;
810
+ expectedIndex = index + 1;
811
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
812
+ let committedItem;
813
+ if (index < survivorCount) {
814
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices?.[index];
815
+ committedItem = sourceIndex === void 0 ? void 0 : committedItems?.[sourceIndex];
816
+ if (mappedItemValues.has(index)) {
817
+ if (!Object.is(item, mappedItemValues.get(index))) eligible = false;
818
+ } else if (appendUpdate?.mappedItemSources && !appendUpdate.mappedSurvivorsValidated) {
819
+ const mappedStructuralSources = appendUpdate.mappedItemSources;
820
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
821
+ if (!Object.is(sourceItem, committedItem)) eligible = false;
822
+ } else if (!Object.is(item, committedItem)) {
823
+ eligible = false;
824
+ }
825
+ }
826
+ const mappedItem = NATIVE_REFLECT_APPLY(
827
+ callback,
828
+ void 0,
829
+ [item, index, source]
830
+ );
831
+ if (index < survivorCount) {
832
+ if (Object.is(mappedItem, committedItem)) {
833
+ mappedItemSources.delete(index);
834
+ mappedItemValues.delete(index);
835
+ } else {
836
+ mappedItemSources.set(index, committedItem);
837
+ mappedItemValues.set(index, mappedItem);
838
+ }
839
+ }
840
+ return mappedItem;
841
+ };
842
+ const value2 = NATIVE_REFLECT_APPLY(
843
+ method,
844
+ collection,
845
+ [wrappedCallback]
846
+ );
847
+ try {
848
+ if (expectedIndex !== expectedLength || !Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE || value2.length !== expectedLength) {
849
+ eligible = false;
850
+ }
851
+ } catch {
852
+ eligible = false;
853
+ }
854
+ return value2;
855
+ };
856
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
857
+ if (!eligible || !appendUpdate) return value;
858
+ try {
859
+ const valueTarget = compilerObject(value);
860
+ if (!valueTarget) return value;
861
+ COMPILER_KEYED_ARRAY_APPENDS.set(valueTarget, {
862
+ ...appendUpdate,
863
+ mappedItemSources,
864
+ mappedItemValues,
865
+ mappedSurvivorsValidated: true
866
+ });
867
+ } catch {
868
+ }
869
+ return value;
870
+ }
255
871
  function createCompilerKeyedArrayPrepend(previous, value) {
256
872
  try {
257
873
  const previousTarget = compilerObject(previous);
@@ -259,23 +875,187 @@ function createCompilerKeyedArrayPrepend(previous, value) {
259
875
  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) {
260
876
  return value;
261
877
  }
262
- const sourceLength = previous.length;
263
- const prefixLength = value.length - sourceLength;
264
- if (prefixLength < 1) return value;
265
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
266
- if (!sourceToken) return value;
267
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget) : void 0;
878
+ const sourceLength = previous.length;
879
+ const prefixLength = value.length - sourceLength;
880
+ if (prefixLength < 1) return value;
881
+ const sourceToken = compilerKeyedCollectionToken(previousTarget);
882
+ if (!sourceToken) return value;
883
+ const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget) : void 0;
884
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
885
+ sourceToken: previousUpdate?.sourceToken || sourceToken,
886
+ sourceLength,
887
+ resultLength: value.length,
888
+ prefixLength,
889
+ ...previousUpdate ? { previous: previousUpdate } : {}
890
+ });
891
+ return value;
892
+ } catch {
893
+ return value;
894
+ }
895
+ }
896
+ function createCompilerKeyedArrayStructuralPrepend(previous, value) {
897
+ try {
898
+ const previousTarget = compilerObject(previous);
899
+ const valueTarget = compilerObject(value);
900
+ 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) {
901
+ return value;
902
+ }
903
+ const sourceLength = previous.length;
904
+ const prefixLength = value.length - sourceLength;
905
+ if (prefixLength < 1) return value;
906
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
907
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget);
908
+ const directStructuralUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
909
+ const structuralSource = directStructuralUpdate ? compilerKeyedArrayFilterSource(directStructuralUpdate, previous.length) : void 0;
910
+ const structuralUpdate = previousUpdate?.structuralUpdate || (structuralSource ? directStructuralUpdate : void 0);
911
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken || compilerKeyedCollectionToken(previousTarget);
912
+ if (!sourceToken) return value;
913
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
914
+ sourceToken,
915
+ sourceLength,
916
+ resultLength: value.length,
917
+ prefixLength,
918
+ ...structuralUpdate ? { structuralUpdate } : {},
919
+ ...previousUpdate ? { previous: previousUpdate } : {}
920
+ });
921
+ return value;
922
+ } catch {
923
+ return value;
924
+ }
925
+ }
926
+ function createCompilerKeyedArrayMappedStructuralPrepend(previous, value) {
927
+ try {
928
+ const previousTarget = compilerObject(previous);
929
+ const valueTarget = compilerObject(value);
930
+ 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) {
931
+ return value;
932
+ }
933
+ const sourceLength = previous.length;
934
+ const prefixLength = value.length - sourceLength;
935
+ if (prefixLength < 1) return value;
936
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
937
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget);
938
+ const previousMappedUpdate = !committedSource && !previousUpdate ? COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget) : void 0;
939
+ const mappedStructuralUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.structuralUpdate && previousMappedUpdate.resultLength === previous.length ? previousMappedUpdate : void 0;
940
+ const structuralUpdate = previousUpdate?.structuralUpdate || mappedStructuralUpdate?.structuralUpdate;
941
+ const sourceToken = previousUpdate?.sourceToken || mappedStructuralUpdate?.sourceToken;
942
+ const mappedItemSources = previousUpdate?.mappedItemSources || mappedStructuralUpdate?.mappedItemSources;
943
+ if (!sourceToken || !structuralUpdate || !mappedItemSources) return value;
944
+ COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
945
+ sourceToken,
946
+ sourceLength,
947
+ resultLength: value.length,
948
+ prefixLength,
949
+ structuralUpdate,
950
+ mappedItemSources,
951
+ ...previousUpdate?.mappedSurvivorsValidated ? { mappedSurvivorsValidated: true } : {},
952
+ ...previousUpdate?.mappedItemValues ? { mappedItemValues: previousUpdate.mappedItemValues } : {},
953
+ ...previousUpdate ? { previous: previousUpdate } : {}
954
+ });
955
+ return value;
956
+ } catch {
957
+ return value;
958
+ }
959
+ }
960
+ function createCompilerKeyedArrayStructuralPrependMapPipeline(previous, pipeline) {
961
+ let prependUpdate;
962
+ let committedItems;
963
+ let survivorRange;
964
+ let survivorIndices;
965
+ let prefixLength = 0;
966
+ try {
967
+ const previousTarget = compilerObject(previous);
968
+ if (!previousTarget || !Array.isArray(previous) || Object.getPrototypeOf(previous) !== NATIVE_ARRAY_PROTOTYPE || !(prependUpdate = COMPILER_KEYED_ARRAY_PREPENDS.get(previousTarget)) || !prependUpdate.structuralUpdate || prependUpdate.resultLength !== previous.length) {
969
+ prependUpdate = void 0;
970
+ } else {
971
+ committedItems = COMPILER_KEYED_COMMITTED_ITEM_SNAPSHOTS.get(prependUpdate.sourceToken);
972
+ const structuralPrepend = committedItems ? compilerKeyedArrayStructuralPrependMapUpdate(
973
+ previous,
974
+ prependUpdate.sourceToken,
975
+ committedItems.length
976
+ ) : void 0;
977
+ survivorRange = structuralPrepend?.structuralSurvivorRange;
978
+ survivorIndices = structuralPrepend?.structuralSurvivors;
979
+ prefixLength = structuralPrepend?.prefixLength || 0;
980
+ if (!survivorRange && !survivorIndices) {
981
+ prependUpdate = void 0;
982
+ }
983
+ }
984
+ } catch {
985
+ prependUpdate = void 0;
986
+ }
987
+ let eligible = prependUpdate !== void 0;
988
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
989
+ const applyMap = (collection, method, callback) => {
990
+ if (method !== NATIVE_ARRAY_MAP || !eligible) {
991
+ const value3 = NATIVE_REFLECT_APPLY(
992
+ method,
993
+ collection,
994
+ [callback]
995
+ );
996
+ if (method !== NATIVE_ARRAY_MAP) eligible = false;
997
+ return value3;
998
+ }
999
+ let expectedIndex = 0;
1000
+ let expectedLength = -1;
1001
+ try {
1002
+ if (!Array.isArray(collection) || Object.getPrototypeOf(collection) !== NATIVE_ARRAY_PROTOTYPE) {
1003
+ eligible = false;
1004
+ } else {
1005
+ expectedLength = collection.length;
1006
+ }
1007
+ } catch {
1008
+ eligible = false;
1009
+ }
1010
+ const wrappedCallback = (item, index, source) => {
1011
+ if (index !== expectedIndex) eligible = false;
1012
+ expectedIndex = index + 1;
1013
+ return NATIVE_REFLECT_APPLY(
1014
+ callback,
1015
+ void 0,
1016
+ [item, index, source]
1017
+ );
1018
+ };
1019
+ const value2 = NATIVE_REFLECT_APPLY(
1020
+ method,
1021
+ collection,
1022
+ [wrappedCallback]
1023
+ );
1024
+ try {
1025
+ if (expectedIndex !== expectedLength || !Array.isArray(value2) || Object.getPrototypeOf(value2) !== NATIVE_ARRAY_PROTOTYPE || value2.length !== expectedLength) {
1026
+ eligible = false;
1027
+ }
1028
+ } catch {
1029
+ eligible = false;
1030
+ }
1031
+ return value2;
1032
+ };
1033
+ const value = NATIVE_REFLECT_APPLY(pipeline, void 0, [previous, applyMap]);
1034
+ if (!eligible || !prependUpdate) return value;
1035
+ try {
1036
+ const valueTarget = compilerObject(value);
1037
+ if (!valueTarget || !Array.isArray(value) || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || value.length !== prefixLength + survivorCount) {
1038
+ return value;
1039
+ }
1040
+ const mappedItemSources = /* @__PURE__ */ new Map();
1041
+ const mappedItemValues = /* @__PURE__ */ new Map();
1042
+ for (let index = 0; index < survivorCount; index += 1) {
1043
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
1044
+ const committedItem = committedItems[sourceIndex];
1045
+ const mappedItem = value[prefixLength + index];
1046
+ if (Object.is(mappedItem, committedItem)) continue;
1047
+ mappedItemSources.set(index, committedItem);
1048
+ mappedItemValues.set(index, mappedItem);
1049
+ }
268
1050
  COMPILER_KEYED_ARRAY_PREPENDS.set(valueTarget, {
269
- sourceToken: previousUpdate?.sourceToken || sourceToken,
270
- sourceLength,
271
- resultLength: value.length,
272
- prefixLength,
273
- ...previousUpdate ? { previous: previousUpdate } : {}
1051
+ ...prependUpdate,
1052
+ mappedItemSources,
1053
+ mappedItemValues,
1054
+ mappedSurvivorsValidated: true
274
1055
  });
275
- return value;
276
1056
  } catch {
277
- return value;
278
1057
  }
1058
+ return value;
279
1059
  }
280
1060
  function createCompilerKeyedArrayFilter(previous, method, predicate) {
281
1061
  let canHint = false;
@@ -310,15 +1090,20 @@ function createCompilerKeyedArrayFilter(previous, method, predicate) {
310
1090
  if (!previousTarget || !valueTarget || !Array.isArray(value) || Object.getPrototypeOf(value) !== NATIVE_ARRAY_PROTOTYPE || visited !== sourceLength || value.length !== sourceLength - removedIndices.length) {
311
1091
  return value;
312
1092
  }
313
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1093
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1094
+ const previousMappedUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1095
+ const mappedUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.resultLength === sourceLength ? previousMappedUpdate : void 0;
1096
+ const sourceToken = mappedUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
314
1097
  if (!sourceToken) return value;
315
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
1098
+ const previousUpdate = !committedSource ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) || mappedUpdate?.structuralUpdate : void 0;
1099
+ const mappedItemSources = mappedUpdate?.mappedItemSources || previousUpdate?.mappedItemSources;
316
1100
  COMPILER_KEYED_ARRAY_FILTERS.set(valueTarget, {
317
1101
  kind: "filter",
318
1102
  sourceToken: previousUpdate?.sourceToken || sourceToken,
319
1103
  sourceLength,
320
1104
  resultLength: value.length,
321
1105
  removedIndices,
1106
+ ...mappedItemSources ? { mappedItemSources } : {},
322
1107
  ...previousUpdate ? { previous: previousUpdate } : {}
323
1108
  });
324
1109
  } catch {
@@ -347,9 +1132,13 @@ function createCompilerKeyedArraySlice(previous, method, ...args) {
347
1132
  const retainedEnd = args.length === 2 ? normalize(args[1]) : sourceLength;
348
1133
  const resultLength = Math.max(retainedEnd - retainedStart, 0);
349
1134
  if (value.length !== resultLength || resultLength >= sourceLength) return value;
350
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1135
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1136
+ const previousMappedUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1137
+ const mappedUpdate = previousMappedUpdate?.mapped && previousMappedUpdate.kind === void 0 && previousMappedUpdate.resultLength === sourceLength ? previousMappedUpdate : void 0;
1138
+ const sourceToken = mappedUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
351
1139
  if (!sourceToken) return value;
352
- const previousUpdate = !COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget) ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0;
1140
+ const previousUpdate = !committedSource ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) || mappedUpdate?.structuralUpdate : void 0;
1141
+ const mappedItemSources = mappedUpdate?.mappedItemSources || previousUpdate?.mappedItemSources;
353
1142
  COMPILER_KEYED_ARRAY_FILTERS.set(valueTarget, {
354
1143
  kind: "slice",
355
1144
  sourceToken: previousUpdate?.sourceToken || sourceToken,
@@ -357,23 +1146,48 @@ function createCompilerKeyedArraySlice(previous, method, ...args) {
357
1146
  resultLength,
358
1147
  retainedEnd: Math.max(retainedEnd, retainedStart),
359
1148
  retainedStart,
1149
+ ...mappedItemSources ? { mappedItemSources } : {},
360
1150
  ...previousUpdate ? { previous: previousUpdate } : {}
361
1151
  });
362
1152
  } catch {
363
1153
  }
364
1154
  return value;
365
1155
  }
1156
+ function finalizeCompilerKeyedArrayMappedStructuralUpdate(value) {
1157
+ try {
1158
+ const valueTarget = compilerObject(value);
1159
+ const structuralUpdate = valueTarget ? COMPILER_KEYED_ARRAY_FILTERS.get(valueTarget) : void 0;
1160
+ const mappedItemSources = structuralUpdate?.mappedItemSources;
1161
+ if (!valueTarget || !structuralUpdate || !mappedItemSources) return value;
1162
+ const source = compilerKeyedArrayFilterSource(structuralUpdate, structuralUpdate.resultLength);
1163
+ if (!source) return value;
1164
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
1165
+ sourceToken: source.sourceToken,
1166
+ sourceLength: source.sourceLength,
1167
+ resultLength: structuralUpdate.resultLength,
1168
+ mapped: true,
1169
+ mappedItemSources,
1170
+ structuralUpdate
1171
+ });
1172
+ } catch {
1173
+ }
1174
+ return value;
1175
+ }
366
1176
  function createCompilerKeyedArrayRollingWindow(previous, retained, value) {
367
1177
  try {
368
1178
  const previousTarget = compilerObject(previous);
369
1179
  const retainedTarget = compilerObject(retained);
370
1180
  const valueTarget = compilerObject(value);
371
- 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) {
1181
+ 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) {
372
1182
  return value;
373
1183
  }
374
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1184
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1185
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_ROLLING_WINDOWS.get(previousTarget);
1186
+ if (!committedSource && !previousUpdate) return value;
1187
+ const immediateSourceToken = compilerKeyedCollectionToken(previousTarget);
1188
+ const sourceToken = previousUpdate?.sourceToken || immediateSourceToken;
375
1189
  const slice = COMPILER_KEYED_ARRAY_FILTERS.get(retainedTarget);
376
- 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) {
1190
+ 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) {
377
1191
  return value;
378
1192
  }
379
1193
  for (let index = 0; index < retained.length; index += 1) {
@@ -384,7 +1198,8 @@ function createCompilerKeyedArrayRollingWindow(previous, retained, value) {
384
1198
  sourceLength: previous.length,
385
1199
  resultLength: value.length,
386
1200
  retainedEnd: slice.retainedEnd,
387
- retainedStart: slice.retainedStart
1201
+ retainedStart: slice.retainedStart,
1202
+ ...previousUpdate ? { previous: previousUpdate } : {}
388
1203
  });
389
1204
  } catch {
390
1205
  }
@@ -498,13 +1313,18 @@ function createCompilerKeyedArrayReorder(previous, method) {
498
1313
  try {
499
1314
  const previousTarget = compilerObject(previous);
500
1315
  const valueTarget = compilerObject(value);
501
- 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) {
1316
+ 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) {
502
1317
  return value;
503
1318
  }
504
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1319
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1320
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1321
+ if (!committedSource && (!previousUpdate || previousUpdate.sourceLength !== previous.length || previousUpdate.resultLength !== previous.length)) {
1322
+ return value;
1323
+ }
1324
+ const sourceToken = previousUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
505
1325
  if (!sourceToken) return value;
506
1326
  COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
507
- kind: "reverse",
1327
+ kind: reversedCompilerKeyedArrayOrder(previousUpdate?.kind),
508
1328
  sourceToken,
509
1329
  sourceLength: previous.length,
510
1330
  resultLength: value.length
@@ -522,16 +1342,21 @@ function createCompilerKeyedArraySort(previous, method, ...args) {
522
1342
  try {
523
1343
  const previousTarget = compilerObject(previous);
524
1344
  const valueTarget = compilerObject(value);
525
- 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) {
1345
+ 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) {
526
1346
  return value;
527
1347
  }
528
1348
  for (let index = 0; index < previous.length; index += 1) {
529
1349
  if (!(index in previous)) return value;
530
1350
  }
531
- const sourceToken = compilerKeyedCollectionToken(previousTarget);
1351
+ const committedSource = COMPILER_KEYED_COMMITTED_COLLECTIONS.has(previousTarget);
1352
+ const previousUpdate = committedSource ? void 0 : COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1353
+ if (!committedSource && (!previousUpdate || previousUpdate.sourceLength !== previous.length || previousUpdate.resultLength !== previous.length)) {
1354
+ return value;
1355
+ }
1356
+ const sourceToken = previousUpdate?.sourceToken || compilerKeyedCollectionToken(previousTarget);
532
1357
  if (!sourceToken) return value;
533
1358
  COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
534
- kind: "sort",
1359
+ kind: 1 /* Permutation */,
535
1360
  sourceToken,
536
1361
  sourceLength: previous.length,
537
1362
  resultLength: value.length
@@ -540,6 +1365,75 @@ function createCompilerKeyedArraySort(previous, method, ...args) {
540
1365
  }
541
1366
  return value;
542
1367
  }
1368
+ function recordCompilerKeyedArrayStructuralReorder(previous, value, kind) {
1369
+ try {
1370
+ const previousTarget = compilerObject(previous);
1371
+ const valueTarget = compilerObject(value);
1372
+ if (!previousTarget || !valueTarget || !Array.isArray(previous) || !Array.isArray(value)) {
1373
+ return value;
1374
+ }
1375
+ const previousUpdate = COMPILER_KEYED_ARRAY_REORDERS.get(previousTarget);
1376
+ const structuralUpdate = previousUpdate?.structuralUpdate || (!previousUpdate ? COMPILER_KEYED_ARRAY_FILTERS.get(previousTarget) : void 0);
1377
+ const structuralSource = structuralUpdate ? compilerKeyedArrayFilterSource(structuralUpdate, previous.length) : void 0;
1378
+ if (!structuralUpdate || !structuralSource || previousUpdate && previousUpdate.resultLength !== previous.length) {
1379
+ return value;
1380
+ }
1381
+ const sourceToken = previousUpdate?.sourceToken || structuralSource?.sourceToken;
1382
+ if (!sourceToken) return value;
1383
+ const mappedItemSources = previousUpdate?.mappedItemSources || structuralUpdate.mappedItemSources;
1384
+ COMPILER_KEYED_ARRAY_REORDERS.set(valueTarget, {
1385
+ kind: kind === 0 /* Reverse */ ? reversedCompilerKeyedArrayOrder(previousUpdate?.kind) : 1 /* Permutation */,
1386
+ sourceToken,
1387
+ sourceLength: previousUpdate?.sourceLength || structuralSource.sourceLength,
1388
+ resultLength: value.length,
1389
+ structuralUpdate,
1390
+ ...mappedItemSources ? { mappedItemSources } : {}
1391
+ });
1392
+ } catch {
1393
+ }
1394
+ return value;
1395
+ }
1396
+ function createCompilerKeyedArrayStructuralReorder(previous, method) {
1397
+ const value = NATIVE_REFLECT_APPLY(
1398
+ method,
1399
+ previous,
1400
+ []
1401
+ );
1402
+ try {
1403
+ 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) {
1404
+ return value;
1405
+ }
1406
+ } catch {
1407
+ return value;
1408
+ }
1409
+ return recordCompilerKeyedArrayStructuralReorder(
1410
+ previous,
1411
+ value,
1412
+ 0 /* Reverse */
1413
+ );
1414
+ }
1415
+ function createCompilerKeyedArrayStructuralSort(previous, method, ...args) {
1416
+ const value = NATIVE_REFLECT_APPLY(
1417
+ method,
1418
+ previous,
1419
+ args
1420
+ );
1421
+ try {
1422
+ 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) {
1423
+ return value;
1424
+ }
1425
+ for (let index = 0; index < previous.length; index += 1) {
1426
+ if (!(index in previous)) return value;
1427
+ }
1428
+ } catch {
1429
+ return value;
1430
+ }
1431
+ return recordCompilerKeyedArrayStructuralReorder(
1432
+ previous,
1433
+ value,
1434
+ 1 /* Permutation */
1435
+ );
1436
+ }
543
1437
  function applyCompilerKeyedCollectionMutation(collection, method, operation, key, value) {
544
1438
  const args = operation === "map-set" ? [key, value] : [key];
545
1439
  const result = NATIVE_REFLECT_APPLY(method, collection, args);
@@ -957,6 +1851,9 @@ function applyStaticRangeBindings(bindings, segments, values) {
957
1851
  }
958
1852
  return true;
959
1853
  }
1854
+ function keyedRowInstancesByKey(instances) {
1855
+ return new Map(instances.map((instance) => [instance.key, instance]));
1856
+ }
960
1857
  var UNSET_KEYED_ROW_BINDING = /* @__PURE__ */ Symbol("unset interactive keyed-row binding");
961
1858
  function keyedRowIdentity(key) {
962
1859
  return String(key);
@@ -1809,7 +2706,7 @@ var CompilerNestedKeyedRanges = class {
1809
2706
  }
1810
2707
  anchor = instance.element;
1811
2708
  }
1812
- this.instances[rangeIndex] = new Map(nextInstances.map((instance) => [instance.key, instance]));
2709
+ this.instances[rangeIndex] = keyedRowInstancesByKey(nextInstances);
1813
2710
  return true;
1814
2711
  }
1815
2712
  updateStaticScopes(descriptor, rowsByRange) {
@@ -2137,7 +3034,7 @@ var CompilerNestedMixedRanges = class {
2137
3034
  }
2138
3035
  anchor = row.element;
2139
3036
  }
2140
- instance.value = new Map(nextInstances.map((row) => [row.key, row]));
3037
+ instance.value = keyedRowInstancesByKey(nextInstances);
2141
3038
  return true;
2142
3039
  }
2143
3040
  reconcileRange(rangeIndex, snapshot) {
@@ -2693,8 +3590,7 @@ function longestIncreasingSubsequencePositions(sequence) {
2693
3590
  return positions;
2694
3591
  }
2695
3592
  function reorderCompilerKeyedRows(root, instances, sequence, anchor) {
2696
- const activeElement = root.ownerDocument.activeElement;
2697
- const restoreFocus = Boolean(activeElement && root.contains(activeElement));
3593
+ const activeElement = compilerFocusedElement(root);
2698
3594
  const stablePositions = longestIncreasingSubsequencePositions(sequence);
2699
3595
  for (let index = instances.length - 1; index >= 0; index -= 1) {
2700
3596
  const instance = instances[index];
@@ -2715,10 +3611,31 @@ function reorderCompilerKeyedRows(root, instances, sequence, anchor) {
2715
3611
  anchor = instance.element;
2716
3612
  }
2717
3613
  }
2718
- if (restoreFocus && activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
3614
+ restoreCompilerFocus(activeElement);
3615
+ }
3616
+ function compilerFocusedElement(root) {
3617
+ const activeElement = root.ownerDocument.activeElement;
3618
+ return activeElement && root.contains(activeElement) ? activeElement : null;
3619
+ }
3620
+ function restoreCompilerFocus(activeElement) {
3621
+ if (activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
2719
3622
  activeElement.focus({ preventScroll: true });
2720
3623
  }
2721
3624
  }
3625
+ function reverseCompilerKeyedRows(root, instances) {
3626
+ const activeElement = compilerFocusedElement(root);
3627
+ let anchor = instances[0]?.element || null;
3628
+ for (let sourceIndex = 1; sourceIndex < instances.length; sourceIndex += 1) {
3629
+ const element = instances[sourceIndex].element;
3630
+ root.insertBefore(element, anchor);
3631
+ anchor = element;
3632
+ }
3633
+ instances.reverse();
3634
+ for (let index = 0; index < instances.length; index += 1) {
3635
+ instances[index].index = index;
3636
+ }
3637
+ restoreCompilerFocus(activeElement);
3638
+ }
2722
3639
  var keyedUpdateRuntime = {
2723
3640
  append: reconcileCompilerKeyedArrayAppend,
2724
3641
  commit: commitCompilerKeyedCollection,
@@ -2736,6 +3653,10 @@ var keyedFilterPrependUpdateRuntime = {
2736
3653
  ...keyedFilterUpdateRuntime,
2737
3654
  prepend: reconcileCompilerKeyedArrayPrepend
2738
3655
  };
3656
+ var keyedStructuralPrependUpdateRuntime = {
3657
+ ...keyedFilterPrependUpdateRuntime,
3658
+ prepend: reconcileCompilerKeyedArrayPrependWithStructural
3659
+ };
2739
3660
  var keyedPositionUpdateRuntime = {
2740
3661
  ...keyedUpdateRuntime,
2741
3662
  position: reconcileCompilerKeyedArrayPosition
@@ -2752,6 +3673,10 @@ var keyedReorderUpdateRuntime = {
2752
3673
  ...keyedUpdateRuntime,
2753
3674
  reorder: reconcileCompilerKeyedArrayReorder
2754
3675
  };
3676
+ var keyedMapReorderUpdateRuntime = {
3677
+ ...keyedUpdateRuntime,
3678
+ reorder: reconcileCompilerKeyedArrayReorderWithMap
3679
+ };
2755
3680
  var keyedCompleteUpdateRuntime = {
2756
3681
  ...keyedFilterPrependUpdateRuntime,
2757
3682
  rollingWindow: reconcileCompilerKeyedArrayRollingWindow
@@ -2759,7 +3684,7 @@ var keyedCompleteUpdateRuntime = {
2759
3684
  var keyedEveryUpdateRuntime = {
2760
3685
  ...keyedCompleteUpdateRuntime,
2761
3686
  position: reconcileCompilerKeyedArrayPosition,
2762
- reorder: reconcileCompilerKeyedArrayReorder
3687
+ reorder: reconcileCompilerKeyedArrayReorderWithMapAndStructural
2763
3688
  };
2764
3689
  var keyedBatchEveryUpdateRuntime = {
2765
3690
  ...keyedEveryUpdateRuntime,
@@ -2769,6 +3694,23 @@ var keyedWindowEveryUpdateRuntime = {
2769
3694
  ...keyedEveryUpdateRuntime,
2770
3695
  position: reconcileCompilerKeyedArrayPositionWithWindow
2771
3696
  };
3697
+ var keyedWindowEveryStructuralAppendUpdateRuntime = {
3698
+ ...keyedWindowEveryUpdateRuntime,
3699
+ append: reconcileCompilerKeyedArrayAppendWithStructural
3700
+ };
3701
+ var keyedWindowEveryStructuralAppendMapUpdateRuntime = {
3702
+ ...keyedWindowEveryStructuralAppendUpdateRuntime,
3703
+ append: reconcileCompilerKeyedArrayAppendMapWithStructural,
3704
+ commit: commitCompilerKeyedCollectionWithItemSnapshot
3705
+ };
3706
+ var keyedCompleteCompatibilityUpdateRuntime = {
3707
+ ...keyedWindowEveryStructuralAppendMapUpdateRuntime,
3708
+ prepend: reconcileCompilerKeyedArrayPrependWithStructural
3709
+ };
3710
+ var keyedCompleteStructuralPrependMapUpdateRuntime = {
3711
+ ...keyedCompleteCompatibilityUpdateRuntime,
3712
+ prepend: reconcileCompilerKeyedArrayPrependMapWithStructural
3713
+ };
2772
3714
  function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, instances, conditionals) {
2773
3715
  const dependency = props.collectionDependency;
2774
3716
  if (dependency === void 0) return void 0;
@@ -2818,6 +3760,86 @@ function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, ins
2818
3760
  fallback: false
2819
3761
  };
2820
3762
  }
3763
+ function reconcileCompilerKeyedArrayMapReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
3764
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
3765
+ return void 0;
3766
+ }
3767
+ const collectionDependency = props.collectionDependency;
3768
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3769
+ return void 0;
3770
+ }
3771
+ const dependencies = props.dependencies || props.structureDependencies;
3772
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3773
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3774
+ return void 0;
3775
+ }
3776
+ const finalValue = preparedReorder?.value ?? props.items();
3777
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
3778
+ if (!update?.mapped || !update.mappedItemSources || update.structuralUpdate || !Array.isArray(finalValue)) {
3779
+ return void 0;
3780
+ }
3781
+ const previousInstances = [...instances.values()];
3782
+ const reverse = update.kind === 0 /* Reverse */;
3783
+ const prepared = (() => {
3784
+ const changed = [];
3785
+ try {
3786
+ const instancesByItem = update.kind === 1 /* Permutation */ ? /* @__PURE__ */ new Map() : void 0;
3787
+ if (instancesByItem) {
3788
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
3789
+ const instance = previousInstances[sourceIndex];
3790
+ if (instance.index !== sourceIndex || instancesByItem.has(instance.item))
3791
+ return void 0;
3792
+ instancesByItem.set(instance.item, instance);
3793
+ }
3794
+ }
3795
+ const nextInstances = instancesByItem ? [] : previousInstances;
3796
+ const sequence = instancesByItem ? [] : void 0;
3797
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
3798
+ const item = finalValue[targetIndex];
3799
+ let instance;
3800
+ if (!instancesByItem) {
3801
+ const sourceIndex = reverse ? finalValue.length - targetIndex - 1 : targetIndex;
3802
+ instance = previousInstances[sourceIndex];
3803
+ if (!instance || instance.index !== sourceIndex) return void 0;
3804
+ if (Object.is(instance.item, item)) continue;
3805
+ if (!update.mappedItemSources.has(item) || !Object.is(instance.item, update.mappedItemSources.get(item))) {
3806
+ return void 0;
3807
+ }
3808
+ } else {
3809
+ const sourceItem = update.mappedItemSources.has(item) ? update.mappedItemSources.get(item) : item;
3810
+ instance = instancesByItem.get(sourceItem);
3811
+ if (!instance) return void 0;
3812
+ instancesByItem.delete(sourceItem);
3813
+ nextInstances.push(instance);
3814
+ sequence.push(instance.index);
3815
+ if (Object.is(instance.item, item)) continue;
3816
+ }
3817
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
3818
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, targetIndex);
3819
+ if (!bindingUpdates) return void 0;
3820
+ changed.push({ bindingUpdates, instance, item });
3821
+ }
3822
+ if (instancesByItem?.size) return void 0;
3823
+ return { changed, nextInstances, sequence };
3824
+ } catch {
3825
+ return void 0;
3826
+ }
3827
+ })();
3828
+ if (!prepared) return void 0;
3829
+ if (prepared.sequence) {
3830
+ reorderCompilerKeyedRows(root, prepared.nextInstances, prepared.sequence, null);
3831
+ } else if (reverse) {
3832
+ reverseCompilerKeyedRows(root, prepared.nextInstances);
3833
+ }
3834
+ for (const { bindingUpdates, instance, item } of prepared.changed) {
3835
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
3836
+ instance.item = item;
3837
+ }
3838
+ for (let index = 0; index < prepared.nextInstances.length; index += 1) {
3839
+ prepared.nextInstances[index].index = index;
3840
+ }
3841
+ return reverse || prepared.sequence ? keyedRowInstancesByKey(prepared.nextInstances) : instances;
3842
+ }
2821
3843
  function reconcileCompilerKeyedArrayAppend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
2822
3844
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || props.collectionDependency === void 0) {
2823
3845
  return void 0;
@@ -2840,28 +3862,243 @@ function reconcileCompilerKeyedArrayAppend(props, dirtyState, collectionToken, i
2840
3862
  for (let index = startIndex; index < finalValue.length; index += 1) {
2841
3863
  const item = finalValue[index];
2842
3864
  const key = keyedRowIdentity(props.rowKey(item, index));
2843
- if (nextInstances.has(key)) return void 0;
3865
+ if (nextInstances.has(key)) return void 0;
3866
+ const descriptor = props.create(item, index);
3867
+ const instance = {
3868
+ key,
3869
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
3870
+ values: readKeyedRowBindingValues(props, item, index),
3871
+ item,
3872
+ index,
3873
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3874
+ };
3875
+ appended.push(instance);
3876
+ nextInstances.set(key, instance);
3877
+ }
3878
+ } catch {
3879
+ return void 0;
3880
+ }
3881
+ if (appended.length > 0) {
3882
+ const fragment = root.ownerDocument.createDocumentFragment();
3883
+ for (const instance of appended) fragment.append(instance.element);
3884
+ root.append(fragment);
3885
+ }
3886
+ return nextInstances;
3887
+ }
3888
+ function reconcileCompilerKeyedArrayStructuralAppend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3889
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
3890
+ return void 0;
3891
+ }
3892
+ const collectionDependency = props.collectionDependency;
3893
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3894
+ return void 0;
3895
+ }
3896
+ const dependencies = props.dependencies || props.structureDependencies;
3897
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3898
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3899
+ return void 0;
3900
+ }
3901
+ const finalValue = props.items();
3902
+ const update = compilerKeyedArrayStructuralAppendUpdate(
3903
+ finalValue,
3904
+ collectionToken,
3905
+ instances.size
3906
+ );
3907
+ const structuralUpdate = update?.structuralUpdate;
3908
+ const survivorResult = update?.structuralSurvivors;
3909
+ if (!update || !structuralUpdate || !survivorResult || structuralUpdate.mappedItemSources || !Array.isArray(finalValue)) {
3910
+ return void 0;
3911
+ }
3912
+ const previousInstances = [...instances.values()];
3913
+ const survivors = [];
3914
+ const knownKeys = new Set(instances.keys());
3915
+ const appended = [];
3916
+ try {
3917
+ for (let index = 0; index < survivorResult.indices.length; index += 1) {
3918
+ const sourceIndex = survivorResult.indices[index];
3919
+ const instance = previousInstances[sourceIndex];
3920
+ const item = finalValue[index];
3921
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, item) || !survivorResult.keysStable && keyedRowIdentity(props.rowKey(item, index)) !== instance.key) {
3922
+ return void 0;
3923
+ }
3924
+ survivors.push(instance);
3925
+ }
3926
+ for (let index = update.startIndex; index < finalValue.length; index += 1) {
3927
+ const item = finalValue[index];
3928
+ const key = keyedRowIdentity(props.rowKey(item, index));
3929
+ if (knownKeys.has(key)) return void 0;
3930
+ knownKeys.add(key);
3931
+ const descriptor = props.create(item, index);
3932
+ appended.push({
3933
+ key,
3934
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
3935
+ values: readKeyedRowBindingValues(props, item, index),
3936
+ item,
3937
+ index,
3938
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3939
+ });
3940
+ }
3941
+ } catch {
3942
+ return void 0;
3943
+ }
3944
+ const survivorSet = new Set(survivorResult.indices);
3945
+ for (let index = 0; index < previousInstances.length; index += 1) {
3946
+ if (survivorSet.has(index)) continue;
3947
+ previousInstances[index].scope?.cleanup();
3948
+ previousInstances[index].element.remove();
3949
+ }
3950
+ for (let index = 0; index < survivors.length; index += 1) survivors[index].index = index;
3951
+ if (appended.length > 0) {
3952
+ const fragment = root.ownerDocument.createDocumentFragment();
3953
+ for (const instance of appended) fragment.append(instance.element);
3954
+ root.append(fragment);
3955
+ }
3956
+ return keyedRowInstancesByKey([...survivors, ...appended]);
3957
+ }
3958
+ function reconcileCompilerKeyedArrayStructuralAppendMap(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3959
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
3960
+ return void 0;
3961
+ }
3962
+ const collectionDependency = props.collectionDependency;
3963
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
3964
+ return void 0;
3965
+ }
3966
+ const dependencies = props.dependencies || props.structureDependencies;
3967
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
3968
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
3969
+ return void 0;
3970
+ }
3971
+ const finalValue = props.items();
3972
+ const update = compilerKeyedArrayStructuralAppendMapUpdate(
3973
+ finalValue,
3974
+ collectionToken,
3975
+ instances.size,
3976
+ true
3977
+ );
3978
+ if (!update || !update.mappedItemSources || !Array.isArray(finalValue)) return void 0;
3979
+ const mappedItemSources = update.mappedSurvivorsValidated ? update.mappedItemSources : void 0;
3980
+ const mappedStructuralSources = update.mappedSurvivorsValidated ? void 0 : update.mappedItemSources;
3981
+ const previousInstances = [...instances.values()];
3982
+ const survivorRange = update.structuralSurvivorRange;
3983
+ const survivorIndices = update.structuralSurvivors;
3984
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
3985
+ if (!survivorRange && !survivorIndices) return void 0;
3986
+ const changed = [];
3987
+ const appendedKeys = /* @__PURE__ */ new Set();
3988
+ const appended = [];
3989
+ try {
3990
+ if (mappedStructuralSources) {
3991
+ for (let index = 0; index < survivorCount; index += 1) {
3992
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
3993
+ const instance = previousInstances[sourceIndex];
3994
+ const item = finalValue[index];
3995
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
3996
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, sourceItem)) {
3997
+ return void 0;
3998
+ }
3999
+ }
4000
+ for (let index = 0; index < survivorCount; index += 1) {
4001
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
4002
+ const instance = previousInstances[sourceIndex];
4003
+ const item = finalValue[index];
4004
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
4005
+ if (Object.is(item, sourceItem)) continue;
4006
+ if (keyedRowIdentity(props.rowKey(item, index)) !== instance.key) return void 0;
4007
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
4008
+ if (!bindingUpdates) return void 0;
4009
+ changed.push({ bindingUpdates, instance, item });
4010
+ }
4011
+ } else if (survivorIndices) {
4012
+ for (let index = 0; index < survivorCount; index += 1) {
4013
+ const sourceIndex = survivorIndices[index];
4014
+ const instance = previousInstances[sourceIndex];
4015
+ const item = finalValue[index];
4016
+ const expectedItem = mappedItemSources.has(index) ? mappedItemSources.get(index) : item;
4017
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, expectedItem)) {
4018
+ return void 0;
4019
+ }
4020
+ }
4021
+ }
4022
+ for (const [index, sourceItem] of mappedItemSources || []) {
4023
+ if (!Number.isSafeInteger(index) || index < 0 || index >= survivorCount) {
4024
+ return void 0;
4025
+ }
4026
+ const instance = previousInstances[survivorRange ? survivorRange.start + index : survivorIndices[index]];
4027
+ const item = finalValue[index];
4028
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, index)) !== instance.key) {
4029
+ return void 0;
4030
+ }
4031
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
4032
+ if (!bindingUpdates) return void 0;
4033
+ changed.push({ bindingUpdates, instance, item });
4034
+ }
4035
+ for (let index = update.startIndex; index < finalValue.length; index += 1) {
4036
+ const item = finalValue[index];
4037
+ const key = keyedRowIdentity(props.rowKey(item, index));
4038
+ if (instances.has(key) || appendedKeys.has(key)) return void 0;
4039
+ appendedKeys.add(key);
2844
4040
  const descriptor = props.create(item, index);
2845
- const instance = {
4041
+ appended.push({
2846
4042
  key,
2847
4043
  element: createCompilerHostElement(root.ownerDocument, descriptor),
2848
4044
  values: readKeyedRowBindingValues(props, item, index),
2849
4045
  item,
2850
4046
  index,
2851
4047
  conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2852
- };
2853
- appended.push(instance);
2854
- nextInstances.set(key, instance);
4048
+ });
2855
4049
  }
2856
4050
  } catch {
2857
4051
  return void 0;
2858
4052
  }
4053
+ const mutableInstances = instances;
4054
+ if (survivorRange) {
4055
+ for (let index = 0; index < survivorRange.start; index += 1) {
4056
+ const instance = previousInstances[index];
4057
+ instance.scope?.cleanup();
4058
+ instance.element.remove();
4059
+ mutableInstances.delete(instance.key);
4060
+ }
4061
+ for (let index = survivorRange.end; index < previousInstances.length; 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.start; index < survivorRange.end; index += 1) {
4068
+ previousInstances[index].index = index - survivorRange.start;
4069
+ }
4070
+ } else {
4071
+ const survivorSet = new Set(survivorIndices);
4072
+ for (let index = 0; index < previousInstances.length; index += 1) {
4073
+ if (survivorSet.has(index)) continue;
4074
+ const instance = previousInstances[index];
4075
+ instance.scope?.cleanup();
4076
+ instance.element.remove();
4077
+ mutableInstances.delete(instance.key);
4078
+ }
4079
+ for (let index = 0; index < survivorIndices.length; index += 1) {
4080
+ previousInstances[survivorIndices[index]].index = index;
4081
+ }
4082
+ }
2859
4083
  if (appended.length > 0) {
2860
4084
  const fragment = root.ownerDocument.createDocumentFragment();
2861
- for (const instance of appended) fragment.append(instance.element);
4085
+ for (const instance of appended) {
4086
+ fragment.append(instance.element);
4087
+ mutableInstances.set(instance.key, instance);
4088
+ }
2862
4089
  root.append(fragment);
2863
4090
  }
2864
- return nextInstances;
4091
+ for (const { bindingUpdates, instance, item } of changed) {
4092
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4093
+ instance.item = item;
4094
+ }
4095
+ return mutableInstances;
4096
+ }
4097
+ function reconcileCompilerKeyedArrayAppendWithStructural(...args) {
4098
+ return reconcileCompilerKeyedArrayStructuralAppend(...args) || reconcileCompilerKeyedArrayAppend(...args);
4099
+ }
4100
+ function reconcileCompilerKeyedArrayAppendMapWithStructural(...args) {
4101
+ return reconcileCompilerKeyedArrayStructuralAppendMap(...args) || reconcileCompilerKeyedArrayStructuralAppend(...args) || reconcileCompilerKeyedArrayAppend(...args);
2865
4102
  }
2866
4103
  function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
2867
4104
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
@@ -2877,14 +4114,18 @@ function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionT
2877
4114
  return void 0;
2878
4115
  }
2879
4116
  const finalValue = props.items();
2880
- const update = compilerKeyedArrayRollingWindow(finalValue, collectionToken, instances.size);
2881
- if (!update || !Array.isArray(finalValue)) return void 0;
4117
+ const updates = compilerKeyedArrayRollingWindows(finalValue, collectionToken, instances.size);
4118
+ if (!updates || !Array.isArray(finalValue)) return void 0;
2882
4119
  const previousInstances = [...instances.values()];
2883
- const retainedLength = update.retainedEnd - update.retainedStart;
4120
+ let retainedStart = 0;
4121
+ for (const update of updates) {
4122
+ retainedStart += Math.min(update.retainedStart, previousInstances.length - retainedStart);
4123
+ }
4124
+ const retainedLength = previousInstances.length - retainedStart;
2884
4125
  const survivors = [];
2885
4126
  try {
2886
4127
  for (let index = 0; index < retainedLength; index += 1) {
2887
- const sourceIndex = update.retainedStart + index;
4128
+ const sourceIndex = retainedStart + index;
2888
4129
  const instance = previousInstances[sourceIndex];
2889
4130
  if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, finalValue[index])) {
2890
4131
  return void 0;
@@ -2915,7 +4156,7 @@ function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionT
2915
4156
  } catch {
2916
4157
  return void 0;
2917
4158
  }
2918
- for (let index = 0; index < update.retainedStart; index += 1) {
4159
+ for (let index = 0; index < retainedStart; index += 1) {
2919
4160
  previousInstances[index].scope?.cleanup();
2920
4161
  previousInstances[index].element.remove();
2921
4162
  }
@@ -2962,7 +4203,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
2962
4203
  for (let index = update.position; index < previousInstances.length; index += 1) {
2963
4204
  previousInstances[index].index = index;
2964
4205
  }
2965
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4206
+ return keyedRowInstancesByKey(previousInstances);
2966
4207
  }
2967
4208
  let item;
2968
4209
  let key;
@@ -2993,7 +4234,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
2993
4234
  for (let index = update.position + 1; index < previousInstances.length; index += 1) {
2994
4235
  previousInstances[index].index = index;
2995
4236
  }
2996
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4237
+ return keyedRowInstancesByKey(previousInstances);
2997
4238
  }
2998
4239
  if (!previous || previous.index !== update.position) return void 0;
2999
4240
  if (key === previous.key) {
@@ -3023,7 +4264,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
3023
4264
  previous.scope?.cleanup();
3024
4265
  previous.element.replaceWith(replacement.element);
3025
4266
  previousInstances[update.position] = replacement;
3026
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4267
+ return keyedRowInstancesByKey(previousInstances);
3027
4268
  }
3028
4269
  function reconcileCompilerKeyedArrayBatchInsert(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3029
4270
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.positionIndexIndependent || props.collectionDependency === void 0) {
@@ -3079,7 +4320,111 @@ function reconcileCompilerKeyedArrayBatchInsert(props, dirtyState, collectionTok
3079
4320
  for (let index = update.position + insertCount; index < previousInstances.length; index += 1) {
3080
4321
  previousInstances[index].index = index;
3081
4322
  }
3082
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4323
+ return keyedRowInstancesByKey(previousInstances);
4324
+ }
4325
+ function normalizeCompilerKeyedArrayDisjointWindows(updates) {
4326
+ const windows = [];
4327
+ for (const update of updates) {
4328
+ const updateEnd = update.position + update.removedCount;
4329
+ let sourcePosition = update.position;
4330
+ for (const window of windows) {
4331
+ const windowStart = window[1];
4332
+ const windowEnd = windowStart + window[3];
4333
+ const before = updateEnd <= windowStart;
4334
+ const after = window[3] === 0 ? update.position >= windowStart : update.position >= windowEnd;
4335
+ if (!before && !after) return void 0;
4336
+ if (after) sourcePosition -= window[3] - window[2];
4337
+ }
4338
+ const delta = update.insertedCount - update.removedCount;
4339
+ for (const window of windows) {
4340
+ if (updateEnd <= window[1]) window[1] += delta;
4341
+ }
4342
+ windows.push([sourcePosition, update.position, update.removedCount, update.insertedCount]);
4343
+ }
4344
+ windows.sort((left, right) => left[0] - right[0]);
4345
+ return windows;
4346
+ }
4347
+ function readCompilerKeyedArrayWindowItems(props, finalValue, resultPosition, insertedCount) {
4348
+ const items = [];
4349
+ const keys = [];
4350
+ try {
4351
+ for (let offset = 0; offset < insertedCount; offset += 1) {
4352
+ const index = resultPosition + offset;
4353
+ const item = finalValue[index];
4354
+ items.push(item);
4355
+ keys.push(keyedRowIdentity(props.rowKey(item, index)));
4356
+ }
4357
+ } catch {
4358
+ return void 0;
4359
+ }
4360
+ return [items, keys];
4361
+ }
4362
+ function prepareCompilerKeyedArrayWindow(props, instances, previousInstances, root, window, incoming, preparedIncomingKeys) {
4363
+ const removedEnd = window[0] + window[2];
4364
+ const removed = previousInstances.slice(window[0], removedEnd);
4365
+ const anchor = previousInstances[removedEnd]?.element || null;
4366
+ if (removed.length !== window[2] || removed.some(
4367
+ (instance, offset) => instance.index !== window[0] + offset || instance.element.parentNode !== root
4368
+ ) || anchor && anchor.parentNode !== root) {
4369
+ return void 0;
4370
+ }
4371
+ const incomingKeySet = new Set(incoming[1]);
4372
+ if (incomingKeySet.size !== incoming[1].length) return void 0;
4373
+ for (const key of incomingKeySet) {
4374
+ if (preparedIncomingKeys.has(key)) return void 0;
4375
+ preparedIncomingKeys.add(key);
4376
+ }
4377
+ const hasLocalReuse = removed.some((instance) => incomingKeySet.has(instance.key));
4378
+ const removedByKey = hasLocalReuse ? new Map(removed.map((instance, offset) => [instance.key, { instance, offset }])) : void 0;
4379
+ const nextWindow = [];
4380
+ const sequence = [];
4381
+ const preparedBindings = [];
4382
+ try {
4383
+ for (let offset = 0; offset < window[3]; offset += 1) {
4384
+ const index = window[1] + offset;
4385
+ const item = incoming[0][offset];
4386
+ const key = incoming[1][offset];
4387
+ const retained = removedByKey?.get(key);
4388
+ if (retained) {
4389
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, retained.instance, item, index);
4390
+ if (!bindingUpdates) return void 0;
4391
+ nextWindow.push(retained.instance);
4392
+ sequence.push(retained.offset);
4393
+ preparedBindings.push(bindingUpdates);
4394
+ continue;
4395
+ }
4396
+ if (instances.has(key)) return void 0;
4397
+ const descriptor = props.create(item, index);
4398
+ nextWindow.push({
4399
+ key,
4400
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
4401
+ values: readKeyedRowBindingValues(props, item, index),
4402
+ item,
4403
+ index,
4404
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4405
+ });
4406
+ sequence.push(-1);
4407
+ preparedBindings.push(void 0);
4408
+ }
4409
+ } catch {
4410
+ return void 0;
4411
+ }
4412
+ return [removed, anchor, incoming[0], incomingKeySet, nextWindow, sequence, preparedBindings];
4413
+ }
4414
+ function commitCompilerKeyedArrayWindow(props, root, prepared) {
4415
+ for (const instance of prepared[0]) {
4416
+ if (prepared[3].has(instance.key)) continue;
4417
+ instance.scope?.cleanup();
4418
+ instance.element.remove();
4419
+ }
4420
+ for (let offset = 0; offset < prepared[4].length; offset += 1) {
4421
+ const bindingUpdates = prepared[6][offset];
4422
+ if (!bindingUpdates) continue;
4423
+ const instance = prepared[4][offset];
4424
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4425
+ instance.item = prepared[2][offset];
4426
+ }
4427
+ reorderCompilerKeyedRows(root, prepared[4], prepared[5], prepared[1]);
3083
4428
  }
3084
4429
  function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3085
4430
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.positionIndexIndependent || props.collectionDependency === void 0) {
@@ -3099,9 +4444,68 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3099
4444
  if (!updates || !Array.isArray(finalValue)) return void 0;
3100
4445
  const previousInstances = [...instances.values()];
3101
4446
  if (updates.length > 1) {
4447
+ if (updates.some((update2) => update2.insertedCount !== update2.removedCount)) {
4448
+ const windows = normalizeCompilerKeyedArrayDisjointWindows(updates);
4449
+ if (!windows) return void 0;
4450
+ let sourceCursor = 0;
4451
+ let resultCursor = 0;
4452
+ const preparedIncomingKeys = /* @__PURE__ */ new Set();
4453
+ const preparedWindows = [];
4454
+ const nextInstances = [];
4455
+ for (const window of windows) {
4456
+ if (window[0] < sourceCursor) return void 0;
4457
+ while (sourceCursor < window[0]) {
4458
+ const instance = previousInstances[sourceCursor];
4459
+ if (!instance || instance.index !== sourceCursor || !Object.is(instance.item, finalValue[resultCursor])) {
4460
+ return void 0;
4461
+ }
4462
+ nextInstances.push(instance);
4463
+ sourceCursor += 1;
4464
+ resultCursor += 1;
4465
+ }
4466
+ const incoming2 = readCompilerKeyedArrayWindowItems(
4467
+ props,
4468
+ finalValue,
4469
+ resultCursor,
4470
+ window[3]
4471
+ );
4472
+ if (!incoming2) return void 0;
4473
+ window[1] = resultCursor;
4474
+ const prepared3 = prepareCompilerKeyedArrayWindow(
4475
+ props,
4476
+ instances,
4477
+ previousInstances,
4478
+ root,
4479
+ window,
4480
+ incoming2,
4481
+ preparedIncomingKeys
4482
+ );
4483
+ if (!prepared3) return void 0;
4484
+ preparedWindows.push(prepared3);
4485
+ nextInstances.push(...prepared3[4]);
4486
+ sourceCursor += window[2];
4487
+ resultCursor += window[3];
4488
+ }
4489
+ while (sourceCursor < previousInstances.length) {
4490
+ const instance = previousInstances[sourceCursor];
4491
+ if (!instance || instance.index !== sourceCursor || !Object.is(instance.item, finalValue[resultCursor])) {
4492
+ return void 0;
4493
+ }
4494
+ nextInstances.push(instance);
4495
+ sourceCursor += 1;
4496
+ resultCursor += 1;
4497
+ }
4498
+ if (resultCursor !== finalValue.length) return void 0;
4499
+ for (const prepared3 of preparedWindows) {
4500
+ commitCompilerKeyedArrayWindow(props, root, prepared3);
4501
+ }
4502
+ for (let index = 0; index < nextInstances.length; index += 1) {
4503
+ nextInstances[index].index = index;
4504
+ }
4505
+ return keyedRowInstancesByKey(nextInstances);
4506
+ }
3102
4507
  const touchedIndices = /* @__PURE__ */ new Set();
3103
4508
  for (const update2 of updates) {
3104
- if (update2.insertedCount !== update2.removedCount) return void 0;
3105
4509
  for (let index = update2.position; index < update2.position + update2.removedCount; index += 1) {
3106
4510
  touchedIndices.add(index);
3107
4511
  }
@@ -3113,21 +4517,21 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3113
4517
  return void 0;
3114
4518
  }
3115
4519
  }
3116
- const knownKeys2 = new Set(instances.keys());
4520
+ const knownKeys = new Set(instances.keys());
3117
4521
  const incomingKeys2 = /* @__PURE__ */ new Set();
3118
4522
  let replacesRows = false;
3119
- const prepared = [];
4523
+ const prepared2 = [];
3120
4524
  try {
3121
4525
  for (const index of [...touchedIndices].sort((left, right) => left - right)) {
3122
4526
  const instance = previousInstances[index];
3123
4527
  const item = finalValue[index];
3124
4528
  const key = keyedRowIdentity(props.rowKey(item, index));
3125
4529
  if (key !== instance.key) {
3126
- if (knownKeys2.has(key) || incomingKeys2.has(key)) return void 0;
4530
+ if (knownKeys.has(key) || incomingKeys2.has(key)) return void 0;
3127
4531
  incomingKeys2.add(key);
3128
4532
  replacesRows = true;
3129
4533
  const descriptor = props.create(item, index);
3130
- prepared.push([
4534
+ prepared2.push([
3131
4535
  index,
3132
4536
  instance,
3133
4537
  item,
@@ -3145,12 +4549,12 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3145
4549
  }
3146
4550
  const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, index);
3147
4551
  if (!bindingUpdates) return void 0;
3148
- prepared.push([index, instance, item, bindingUpdates, void 0]);
4552
+ prepared2.push([index, instance, item, bindingUpdates, void 0]);
3149
4553
  }
3150
4554
  } catch {
3151
4555
  return void 0;
3152
4556
  }
3153
- for (const [index, instance, item, bindingUpdates, replacement] of prepared) {
4557
+ for (const [index, instance, item, bindingUpdates, replacement] of prepared2) {
3154
4558
  if (replacement) {
3155
4559
  instance.scope?.cleanup();
3156
4560
  instance.element.replaceWith(replacement.element);
@@ -3160,7 +4564,7 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3160
4564
  instance.item = item;
3161
4565
  }
3162
4566
  }
3163
- return replacesRows ? new Map(previousInstances.map((instance) => [instance.key, instance])) : instances;
4567
+ return replacesRows ? keyedRowInstancesByKey(previousInstances) : instances;
3164
4568
  }
3165
4569
  const update = updates[0];
3166
4570
  const removedEnd = update.position + update.removedCount;
@@ -3176,21 +4580,17 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3176
4580
  if (removed.length !== update.removedCount || removed.some((instance) => instance.element.parentNode !== root) || anchor && anchor.parentNode !== root) {
3177
4581
  return void 0;
3178
4582
  }
3179
- const incomingItems = [];
3180
- const incomingKeys = [];
3181
- try {
3182
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3183
- const index = update.position + offset;
3184
- const item = finalValue[index];
3185
- const key = keyedRowIdentity(props.rowKey(item, index));
3186
- incomingItems.push(item);
3187
- incomingKeys.push(key);
3188
- }
3189
- } catch {
3190
- return void 0;
3191
- }
4583
+ const incoming = readCompilerKeyedArrayWindowItems(
4584
+ props,
4585
+ finalValue,
4586
+ update.position,
4587
+ update.insertedCount
4588
+ );
4589
+ if (!incoming) return void 0;
4590
+ const incomingItems = incoming[0];
4591
+ const incomingKeys = incoming[1];
3192
4592
  if (update.insertedCount === update.removedCount && incomingKeys.every((key, offset) => key === removed[offset].key)) {
3193
- const prepared = [];
4593
+ const prepared2 = [];
3194
4594
  try {
3195
4595
  for (let offset = 0; offset < update.insertedCount; offset += 1) {
3196
4596
  const updates2 = prepareKeyedRowBindingUpdates(
@@ -3200,92 +4600,289 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3200
4600
  update.position + offset
3201
4601
  );
3202
4602
  if (!updates2) return void 0;
3203
- prepared.push(updates2);
4603
+ prepared2.push(updates2);
3204
4604
  }
3205
4605
  } catch {
3206
4606
  return void 0;
3207
4607
  }
3208
4608
  for (let offset = 0; offset < update.insertedCount; offset += 1) {
3209
- applyPreparedKeyedRowBindingUpdates(props, removed[offset], prepared[offset]);
4609
+ applyPreparedKeyedRowBindingUpdates(props, removed[offset], prepared2[offset]);
3210
4610
  removed[offset].item = incomingItems[offset];
3211
4611
  }
3212
4612
  return instances;
3213
4613
  }
3214
- if (update.insertedCount === update.removedCount) {
3215
- const incomingKeySet = new Set(incomingKeys);
3216
- if (incomingKeySet.size !== incomingKeys.length) return void 0;
3217
- const removedByKey = new Map(
3218
- removed.map((instance, offset) => [instance.key, { instance, offset }])
3219
- );
3220
- if (incomingKeys.some((key) => removedByKey.has(key))) {
3221
- const nextWindow = [];
3222
- const sequence = [];
3223
- const preparedBindings = [];
3224
- try {
3225
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3226
- const index = update.position + offset;
3227
- const item = incomingItems[offset];
3228
- const key = incomingKeys[offset];
3229
- const retained = removedByKey.get(key);
3230
- if (retained) {
3231
- const bindingUpdates = prepareKeyedRowBindingUpdates(
3232
- props,
3233
- retained.instance,
3234
- item,
3235
- index
3236
- );
3237
- if (!bindingUpdates) return void 0;
3238
- nextWindow.push(retained.instance);
3239
- sequence.push(retained.offset);
3240
- preparedBindings.push(bindingUpdates);
3241
- continue;
3242
- }
3243
- if (instances.has(key)) return void 0;
3244
- const descriptor = props.create(item, index);
3245
- nextWindow.push({
3246
- key,
3247
- element: createCompilerHostElement(root.ownerDocument, descriptor),
3248
- values: readKeyedRowBindingValues(props, item, index),
3249
- item,
3250
- index,
3251
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
3252
- });
3253
- sequence.push(-1);
3254
- preparedBindings.push(void 0);
4614
+ const prepared = prepareCompilerKeyedArrayWindow(
4615
+ props,
4616
+ instances,
4617
+ previousInstances,
4618
+ root,
4619
+ [update.position, update.position, update.removedCount, update.insertedCount],
4620
+ incoming,
4621
+ /* @__PURE__ */ new Set()
4622
+ );
4623
+ if (!prepared) return void 0;
4624
+ commitCompilerKeyedArrayWindow(props, root, prepared);
4625
+ previousInstances.splice(update.position, update.removedCount, ...prepared[4]);
4626
+ for (let index = update.position; index < previousInstances.length; index += 1) {
4627
+ previousInstances[index].index = index;
4628
+ }
4629
+ return keyedRowInstancesByKey(previousInstances);
4630
+ }
4631
+ function reconcileCompilerKeyedArrayPositionWithBatch(...args) {
4632
+ return reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4633
+ }
4634
+ function reconcileCompilerKeyedArrayPositionWithWindow(...args) {
4635
+ return reconcileCompilerKeyedArrayWindowReplace(...args) || reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4636
+ }
4637
+ function reconcileCompilerKeyedArrayStructuralReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
4638
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4639
+ return void 0;
4640
+ }
4641
+ const collectionDependency = props.collectionDependency;
4642
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4643
+ return void 0;
4644
+ }
4645
+ const dependencies = props.dependencies || props.structureDependencies;
4646
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4647
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4648
+ return void 0;
4649
+ }
4650
+ const finalValue = preparedReorder?.value ?? props.items();
4651
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
4652
+ if (!update?.structuralUpdate || !Array.isArray(finalValue)) return void 0;
4653
+ const survivorResult = compilerKeyedArrayFilterSurvivorsFromUpdate(
4654
+ update.structuralUpdate,
4655
+ collectionToken,
4656
+ instances.size,
4657
+ finalValue.length
4658
+ );
4659
+ if (!survivorResult) return void 0;
4660
+ const previousInstances = [...instances.values()];
4661
+ const mappedItemSources = update.mappedItemSources;
4662
+ const prepared = (() => {
4663
+ try {
4664
+ const survivors = [];
4665
+ let previousSourceIndex = -1;
4666
+ for (const sourceIndex of survivorResult.indices) {
4667
+ const instance = previousInstances[sourceIndex];
4668
+ if (sourceIndex <= previousSourceIndex || !instance || instance.index !== sourceIndex) {
4669
+ return void 0;
3255
4670
  }
3256
- } catch {
3257
- return void 0;
4671
+ previousSourceIndex = sourceIndex;
4672
+ survivors.push(instance);
4673
+ }
4674
+ const prepareChangedInstance = (instance, item, targetIndex) => {
4675
+ if (Object.is(instance.item, item)) return void 0;
4676
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, targetIndex);
4677
+ if (!bindingUpdates) throw new TypeError();
4678
+ return { bindingUpdates, instance, item };
4679
+ };
4680
+ let preservesSurvivorOrder = true;
4681
+ const directChanges = [];
4682
+ if (update.kind !== 1 /* Permutation */) {
4683
+ const positionalInstances = update.kind === 0 /* Reverse */ ? [...survivors].reverse() : survivors;
4684
+ const sequence2 = update.kind === 0 /* Reverse */ ? positionalInstances.map((instance) => instance.index) : void 0;
4685
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4686
+ const item = finalValue[targetIndex];
4687
+ const instance = positionalInstances[targetIndex];
4688
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
4689
+ const changed2 = prepareChangedInstance(instance, item, targetIndex);
4690
+ if (changed2) directChanges.push(changed2);
4691
+ }
4692
+ return { changed: directChanges, nextInstances: positionalInstances, sequence: sequence2 };
3258
4693
  }
3259
- for (const instance of removed) {
3260
- if (incomingKeySet.has(instance.key)) continue;
3261
- instance.scope?.cleanup();
3262
- instance.element.remove();
3263
- }
3264
- for (let offset = 0; offset < nextWindow.length; offset += 1) {
3265
- const bindingUpdates = preparedBindings[offset];
3266
- if (bindingUpdates) {
3267
- const instance = nextWindow[offset];
3268
- applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
3269
- instance.item = incomingItems[offset];
3270
- instance.index = update.position + offset;
4694
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4695
+ const item = finalValue[targetIndex];
4696
+ const instance = survivors[targetIndex];
4697
+ const sourceItem = mappedItemSources?.has(item) ? mappedItemSources.get(item) : item;
4698
+ if (!Object.is(instance.item, sourceItem)) {
4699
+ preservesSurvivorOrder = false;
4700
+ break;
3271
4701
  }
4702
+ if (keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) return void 0;
4703
+ const changed2 = prepareChangedInstance(instance, item, targetIndex);
4704
+ if (changed2) directChanges.push(changed2);
4705
+ }
4706
+ if (preservesSurvivorOrder) {
4707
+ return { changed: directChanges, nextInstances: survivors, sequence: void 0 };
4708
+ }
4709
+ const survivorInstances = /* @__PURE__ */ new Map();
4710
+ for (const instance of survivors) {
4711
+ if (survivorInstances.has(instance.item)) return void 0;
4712
+ survivorInstances.set(instance.item, instance);
4713
+ }
4714
+ const nextInstances = [];
4715
+ const sequence = [];
4716
+ const changed = [];
4717
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4718
+ const item = finalValue[targetIndex];
4719
+ const sourceItem = mappedItemSources?.has(item) ? mappedItemSources.get(item) : item;
4720
+ const instance = survivorInstances.get(sourceItem);
4721
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, targetIndex)) !== instance.key) {
4722
+ return void 0;
4723
+ }
4724
+ survivorInstances.delete(sourceItem);
4725
+ nextInstances.push(instance);
4726
+ sequence.push(instance.index);
4727
+ const changedInstance = prepareChangedInstance(instance, item, targetIndex);
4728
+ if (changedInstance) changed.push(changedInstance);
4729
+ }
4730
+ if (survivorInstances.size > 0) return void 0;
4731
+ return { changed, nextInstances, sequence };
4732
+ } catch {
4733
+ return void 0;
4734
+ }
4735
+ })();
4736
+ if (!prepared) return void 0;
4737
+ let survivorCursor = 0;
4738
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4739
+ if (survivorResult.indices[survivorCursor] === sourceIndex) {
4740
+ survivorCursor += 1;
4741
+ continue;
4742
+ }
4743
+ const instance = previousInstances[sourceIndex];
4744
+ instance.scope?.cleanup();
4745
+ instance.element.remove();
4746
+ }
4747
+ if (prepared.sequence) {
4748
+ reorderCompilerKeyedRows(root, prepared.nextInstances, prepared.sequence, null);
4749
+ }
4750
+ for (const { bindingUpdates, instance, item } of prepared.changed) {
4751
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
4752
+ instance.item = item;
4753
+ }
4754
+ for (let index = 0; index < prepared.nextInstances.length; index += 1) {
4755
+ prepared.nextInstances[index].index = index;
4756
+ }
4757
+ return keyedRowInstancesByKey(prepared.nextInstances);
4758
+ }
4759
+ function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows, preparedReorder) {
4760
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4761
+ return void 0;
4762
+ }
4763
+ const collectionDependency = props.collectionDependency;
4764
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4765
+ return void 0;
4766
+ }
4767
+ const dependencies = props.dependencies || props.structureDependencies;
4768
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4769
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4770
+ return void 0;
4771
+ }
4772
+ const finalValue = preparedReorder?.value ?? props.items();
4773
+ const update = preparedReorder?.update || compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
4774
+ if (!update || update.mapped || update.structuralUpdate || !Array.isArray(finalValue)) {
4775
+ return void 0;
4776
+ }
4777
+ const previousInstances = [...instances.values()];
4778
+ if (update.kind === 1 /* Permutation */) {
4779
+ const instancesByItem = /* @__PURE__ */ new Map();
4780
+ try {
4781
+ for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4782
+ const instance = previousInstances[sourceIndex];
4783
+ if (instance.index !== sourceIndex || instancesByItem.has(instance.item)) return void 0;
4784
+ instancesByItem.set(instance.item, instance);
3272
4785
  }
3273
- reorderCompilerKeyedRows(root, nextWindow, sequence, anchor || null);
3274
- previousInstances.splice(update.position, update.removedCount, ...nextWindow);
3275
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4786
+ const nextInstances = [];
4787
+ const sequence = [];
4788
+ for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
4789
+ const item = finalValue[targetIndex];
4790
+ const instance = instancesByItem.get(item);
4791
+ if (!instance || !Object.is(instance.item, item)) return void 0;
4792
+ instancesByItem.delete(item);
4793
+ nextInstances.push(instance);
4794
+ sequence.push(instance.index);
4795
+ }
4796
+ if (instancesByItem.size > 0) return void 0;
4797
+ reorderCompilerKeyedRows(root, nextInstances, sequence, null);
4798
+ for (let index = 0; index < nextInstances.length; index += 1) {
4799
+ nextInstances[index].index = index;
4800
+ }
4801
+ return keyedRowInstancesByKey(nextInstances);
4802
+ } catch {
4803
+ return void 0;
4804
+ }
4805
+ }
4806
+ try {
4807
+ for (let targetIndex = 0; targetIndex < previousInstances.length; targetIndex += 1) {
4808
+ const sourceIndex = update.kind === 0 /* Reverse */ ? previousInstances.length - targetIndex - 1 : targetIndex;
4809
+ const instance = previousInstances[sourceIndex];
4810
+ if (instance.index !== sourceIndex || !Object.is(instance.item, finalValue[targetIndex])) {
4811
+ return void 0;
4812
+ }
4813
+ }
4814
+ } catch {
4815
+ return void 0;
4816
+ }
4817
+ if (update.kind === void 0) return instances;
4818
+ reverseCompilerKeyedRows(root, previousInstances);
4819
+ return keyedRowInstancesByKey(previousInstances);
4820
+ }
4821
+ function prepareCompilerKeyedArrayReorder(args) {
4822
+ const [props, dirtyState, collectionToken, instances, , reactOwnedRows] = args;
4823
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4824
+ return void 0;
4825
+ }
4826
+ const collectionDependency = props.collectionDependency;
4827
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4828
+ return void 0;
4829
+ }
4830
+ const dependencies = props.dependencies || props.structureDependencies;
4831
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4832
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4833
+ return void 0;
4834
+ }
4835
+ const value = props.items();
4836
+ return {
4837
+ update: compilerKeyedArrayReorder(value, collectionToken, instances.size),
4838
+ value
4839
+ };
4840
+ }
4841
+ function reconcileCompilerKeyedArrayReorderWithMap(...args) {
4842
+ const prepared = prepareCompilerKeyedArrayReorder(args);
4843
+ if (!prepared) return void 0;
4844
+ const reconcile = prepared.update?.mapped ? reconcileCompilerKeyedArrayMapReorder : reconcileCompilerKeyedArrayReorder;
4845
+ return reconcile(args[0], args[1], args[2], args[3], args[4], args[5], prepared);
4846
+ }
4847
+ function reconcileCompilerKeyedArrayReorderWithMapAndStructural(...args) {
4848
+ const prepared = prepareCompilerKeyedArrayReorder(args);
4849
+ if (!prepared) return void 0;
4850
+ const reconcile = prepared.update?.structuralUpdate ? reconcileCompilerKeyedArrayStructuralReorder : prepared.update?.mapped ? reconcileCompilerKeyedArrayMapReorder : reconcileCompilerKeyedArrayReorder;
4851
+ return reconcile(args[0], args[1], args[2], args[3], args[4], args[5], prepared);
4852
+ }
4853
+ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4854
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.prependIndexIndependent || props.collectionDependency === void 0) {
4855
+ return void 0;
4856
+ }
4857
+ const collectionDependency = props.collectionDependency;
4858
+ if (props.bindings.some((binding) => binding.dependencies?.includes(collectionDependency))) {
4859
+ return void 0;
4860
+ }
4861
+ const dependencies = props.dependencies || props.structureDependencies;
4862
+ const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
4863
+ if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
4864
+ return void 0;
4865
+ }
4866
+ const finalValue = props.items();
4867
+ const prefixLength = compilerKeyedArrayPrependLength(finalValue, collectionToken, instances.size);
4868
+ if (prefixLength === void 0 || !Array.isArray(finalValue)) return void 0;
4869
+ const previousInstances = [...instances.values()];
4870
+ for (let index = 0; index < previousInstances.length; index += 1) {
4871
+ const instance = previousInstances[index];
4872
+ if (instance.index !== index || !Object.is(instance.item, finalValue[prefixLength + index])) {
4873
+ return void 0;
3276
4874
  }
3277
4875
  }
3278
4876
  const knownKeys = new Set(instances.keys());
3279
- const incoming = [];
4877
+ const prepended = [];
3280
4878
  try {
3281
- for (let offset = 0; offset < update.insertedCount; offset += 1) {
3282
- const index = update.position + offset;
3283
- const item = incomingItems[offset];
3284
- const key = incomingKeys[offset];
4879
+ for (let index = 0; index < prefixLength; index += 1) {
4880
+ const item = finalValue[index];
4881
+ const key = keyedRowIdentity(props.rowKey(item, index));
3285
4882
  if (knownKeys.has(key)) return void 0;
3286
4883
  knownKeys.add(key);
3287
4884
  const descriptor = props.create(item, index);
3288
- incoming.push({
4885
+ prepended.push({
3289
4886
  key,
3290
4887
  element: createCompilerHostElement(root.ownerDocument, descriptor),
3291
4888
  values: readKeyedRowBindingValues(props, item, index),
@@ -3297,29 +4894,18 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
3297
4894
  } catch {
3298
4895
  return void 0;
3299
4896
  }
3300
- for (const instance of removed) {
3301
- instance.scope?.cleanup();
3302
- instance.element.remove();
3303
- }
3304
- if (incoming.length > 0) {
4897
+ if (prepended.length > 0) {
3305
4898
  const fragment = root.ownerDocument.createDocumentFragment();
3306
- for (const instance of incoming) fragment.append(instance.element);
3307
- root.insertBefore(fragment, anchor || null);
4899
+ for (const instance of prepended) fragment.append(instance.element);
4900
+ root.insertBefore(fragment, root.firstChild);
3308
4901
  }
3309
- previousInstances.splice(update.position, update.removedCount, ...incoming);
3310
- for (let index = update.position + update.insertedCount; index < previousInstances.length; index += 1) {
3311
- previousInstances[index].index = index;
4902
+ for (let index = 0; index < previousInstances.length; index += 1) {
4903
+ previousInstances[index].index = prefixLength + index;
3312
4904
  }
3313
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
3314
- }
3315
- function reconcileCompilerKeyedArrayPositionWithBatch(...args) {
3316
- return reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
3317
- }
3318
- function reconcileCompilerKeyedArrayPositionWithWindow(...args) {
3319
- return reconcileCompilerKeyedArrayWindowReplace(...args) || reconcileCompilerKeyedArrayBatchInsert(...args) || reconcileCompilerKeyedArrayPosition(...args);
4905
+ return keyedRowInstancesByKey([...prepended, ...previousInstances]);
3320
4906
  }
3321
- function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3322
- if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.reorderIndexIndependent || props.collectionDependency === void 0) {
4907
+ function reconcileCompilerKeyedArrayStructuralPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4908
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.prependIndexIndependent || props.collectionDependency === void 0) {
3323
4909
  return void 0;
3324
4910
  }
3325
4911
  const collectionDependency = props.collectionDependency;
@@ -3332,78 +4918,66 @@ function reconcileCompilerKeyedArrayReorder(props, dirtyState, collectionToken,
3332
4918
  return void 0;
3333
4919
  }
3334
4920
  const finalValue = props.items();
3335
- const update = compilerKeyedArrayReorder(finalValue, collectionToken, instances.size);
3336
- if (!update || !Array.isArray(finalValue)) return void 0;
3337
- const previousInstances = [...instances.values()];
3338
- if (update.kind === "sort") {
3339
- const instancesByItem = /* @__PURE__ */ new Map();
3340
- try {
3341
- for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
3342
- const instance = previousInstances[sourceIndex];
3343
- if (instance.index !== sourceIndex || instancesByItem.has(instance.item)) return void 0;
3344
- instancesByItem.set(instance.item, instance);
3345
- }
3346
- const nextInstances = [];
3347
- const sequence = [];
3348
- for (let targetIndex = 0; targetIndex < finalValue.length; targetIndex += 1) {
3349
- const item = finalValue[targetIndex];
3350
- const instance = instancesByItem.get(item);
3351
- if (!instance || !Object.is(instance.item, item)) return void 0;
3352
- instancesByItem.delete(item);
3353
- nextInstances.push(instance);
3354
- sequence.push(instance.index);
3355
- }
3356
- if (instancesByItem.size > 0) return void 0;
3357
- const activeElement2 = root.ownerDocument.activeElement;
3358
- const restoreFocus2 = Boolean(activeElement2 && root.contains(activeElement2));
3359
- const stablePositions = longestIncreasingSubsequencePositions(sequence);
3360
- let anchor2 = null;
3361
- for (let index = nextInstances.length - 1; index >= 0; index -= 1) {
3362
- const instance = nextInstances[index];
3363
- if (!stablePositions.has(index) && instance.element.nextSibling !== anchor2) {
3364
- root.insertBefore(instance.element, anchor2);
3365
- }
3366
- anchor2 = instance.element;
3367
- instance.index = index;
3368
- }
3369
- if (restoreFocus2 && activeElement2?.isConnected && activeElement2.ownerDocument.activeElement !== activeElement2 && "focus" in activeElement2) {
3370
- activeElement2.focus({ preventScroll: true });
3371
- }
3372
- return new Map(nextInstances.map((instance) => [instance.key, instance]));
3373
- } catch {
3374
- return void 0;
3375
- }
4921
+ const update = compilerKeyedArrayStructuralPrependUpdate(
4922
+ finalValue,
4923
+ collectionToken,
4924
+ instances.size
4925
+ );
4926
+ const structuralUpdate = update?.structuralUpdate;
4927
+ const survivorResult = update?.structuralSurvivors;
4928
+ if (!update || !structuralUpdate || !survivorResult || structuralUpdate.mappedItemSources || !Array.isArray(finalValue)) {
4929
+ return void 0;
3376
4930
  }
4931
+ const previousInstances = [...instances.values()];
4932
+ const survivors = [];
4933
+ const knownKeys = new Set(instances.keys());
4934
+ const prepended = [];
3377
4935
  try {
3378
- for (let sourceIndex = 0; sourceIndex < previousInstances.length; sourceIndex += 1) {
4936
+ for (let index = 0; index < survivorResult.indices.length; index += 1) {
4937
+ const sourceIndex = survivorResult.indices[index];
3379
4938
  const instance = previousInstances[sourceIndex];
3380
- const targetIndex = previousInstances.length - sourceIndex - 1;
3381
- if (instance.index !== sourceIndex || !Object.is(instance.item, finalValue[targetIndex])) {
4939
+ const item = finalValue[update.prefixLength + index];
4940
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, item) || !survivorResult.keysStable && keyedRowIdentity(props.rowKey(item, update.prefixLength + index)) !== instance.key) {
3382
4941
  return void 0;
3383
4942
  }
4943
+ survivors.push(instance);
4944
+ }
4945
+ for (let index = 0; index < update.prefixLength; index += 1) {
4946
+ const item = finalValue[index];
4947
+ const key = keyedRowIdentity(props.rowKey(item, index));
4948
+ if (knownKeys.has(key)) return void 0;
4949
+ knownKeys.add(key);
4950
+ const descriptor = props.create(item, index);
4951
+ prepended.push({
4952
+ key,
4953
+ element: createCompilerHostElement(root.ownerDocument, descriptor),
4954
+ values: readKeyedRowBindingValues(props, item, index),
4955
+ item,
4956
+ index,
4957
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4958
+ });
3384
4959
  }
3385
4960
  } catch {
3386
4961
  return void 0;
3387
4962
  }
3388
- const activeElement = root.ownerDocument.activeElement;
3389
- const restoreFocus = Boolean(activeElement && root.contains(activeElement));
3390
- let anchor = previousInstances[0]?.element || null;
3391
- for (let sourceIndex = 1; sourceIndex < previousInstances.length; sourceIndex += 1) {
3392
- const element = previousInstances[sourceIndex].element;
3393
- root.insertBefore(element, anchor);
3394
- anchor = element;
3395
- }
3396
- previousInstances.reverse();
4963
+ const survivorSet = new Set(survivorResult.indices);
3397
4964
  for (let index = 0; index < previousInstances.length; index += 1) {
3398
- previousInstances[index].index = index;
4965
+ if (survivorSet.has(index)) continue;
4966
+ previousInstances[index].scope?.cleanup();
4967
+ previousInstances[index].element.remove();
3399
4968
  }
3400
- if (restoreFocus && activeElement?.isConnected && activeElement.ownerDocument.activeElement !== activeElement && "focus" in activeElement) {
3401
- activeElement.focus({ preventScroll: true });
4969
+ if (prepended.length > 0) {
4970
+ const fragment = root.ownerDocument.createDocumentFragment();
4971
+ for (const instance of prepended) fragment.append(instance.element);
4972
+ root.insertBefore(fragment, survivors[0]?.element || root.firstChild);
4973
+ }
4974
+ for (let index = 0; index < survivors.length; index += 1) {
4975
+ survivors[index].index = update.prefixLength + index;
3402
4976
  }
3403
- return new Map(previousInstances.map((instance) => [instance.key, instance]));
4977
+ return keyedRowInstancesByKey([...prepended, ...survivors]);
3404
4978
  }
3405
- function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
3406
- if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.prependIndexIndependent || props.collectionDependency === void 0) {
4979
+ function reconcileCompilerKeyedArrayStructuralPrependMap(props, dirtyState, collectionToken, instances, root, reactOwnedRows) {
4980
+ if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || !props.prependIndexIndependent || props.collectionDependency === void 0) {
3407
4981
  return void 0;
3408
4982
  }
3409
4983
  const collectionDependency = props.collectionDependency;
@@ -3416,19 +4990,78 @@ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken,
3416
4990
  return void 0;
3417
4991
  }
3418
4992
  const finalValue = props.items();
3419
- const prefixLength = compilerKeyedArrayPrependLength(finalValue, collectionToken, instances.size);
3420
- if (prefixLength === void 0 || !Array.isArray(finalValue)) return void 0;
4993
+ const update = compilerKeyedArrayStructuralPrependMapUpdate(
4994
+ finalValue,
4995
+ collectionToken,
4996
+ instances.size,
4997
+ true
4998
+ );
4999
+ if (!update || !update.mappedItemSources || !Array.isArray(finalValue)) return void 0;
5000
+ const mappedItemSources = update.mappedSurvivorsValidated ? update.mappedItemSources : void 0;
5001
+ const mappedStructuralSources = update.mappedSurvivorsValidated ? void 0 : update.mappedItemSources;
3421
5002
  const previousInstances = [...instances.values()];
3422
- for (let index = 0; index < previousInstances.length; index += 1) {
3423
- const instance = previousInstances[index];
3424
- if (instance.index !== index || !Object.is(instance.item, finalValue[prefixLength + index])) {
3425
- return void 0;
3426
- }
3427
- }
5003
+ const survivorRange = update.structuralSurvivorRange;
5004
+ const survivorIndices = update.structuralSurvivors;
5005
+ const survivorCount = survivorRange ? survivorRange.end - survivorRange.start : survivorIndices?.length ?? 0;
5006
+ if (!survivorRange && !survivorIndices) return void 0;
5007
+ const changed = [];
3428
5008
  const knownKeys = new Set(instances.keys());
3429
5009
  const prepended = [];
3430
5010
  try {
3431
- for (let index = 0; index < prefixLength; index += 1) {
5011
+ if (mappedStructuralSources) {
5012
+ for (let index = 0; index < survivorCount; index += 1) {
5013
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
5014
+ const instance = previousInstances[sourceIndex];
5015
+ const item = finalValue[update.prefixLength + index];
5016
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
5017
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, sourceItem)) {
5018
+ return void 0;
5019
+ }
5020
+ }
5021
+ for (let index = 0; index < survivorCount; index += 1) {
5022
+ const sourceIndex = survivorRange ? survivorRange.start + index : survivorIndices[index];
5023
+ const instance = previousInstances[sourceIndex];
5024
+ const item = finalValue[update.prefixLength + index];
5025
+ const sourceItem = mappedStructuralSources.has(item) ? mappedStructuralSources.get(item) : item;
5026
+ if (Object.is(item, sourceItem)) continue;
5027
+ if (keyedRowIdentity(props.rowKey(item, update.prefixLength + index)) !== instance.key) {
5028
+ return void 0;
5029
+ }
5030
+ const bindingUpdates = prepareKeyedRowBindingUpdates(
5031
+ props,
5032
+ instance,
5033
+ item,
5034
+ update.prefixLength + index
5035
+ );
5036
+ if (!bindingUpdates) return void 0;
5037
+ changed.push({ bindingUpdates, instance, item });
5038
+ }
5039
+ } else if (survivorIndices) {
5040
+ for (let index = 0; index < survivorCount; index += 1) {
5041
+ const sourceIndex = survivorIndices[index];
5042
+ const instance = previousInstances[sourceIndex];
5043
+ const item = finalValue[update.prefixLength + index];
5044
+ const expectedItem = mappedItemSources.has(index) ? mappedItemSources.get(index) : item;
5045
+ if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, expectedItem)) {
5046
+ return void 0;
5047
+ }
5048
+ }
5049
+ }
5050
+ for (const [index, sourceItem] of mappedItemSources || []) {
5051
+ if (!Number.isSafeInteger(index) || index < 0 || index >= survivorCount) {
5052
+ return void 0;
5053
+ }
5054
+ const instance = previousInstances[survivorRange ? survivorRange.start + index : survivorIndices[index]];
5055
+ const finalIndex = update.prefixLength + index;
5056
+ const item = finalValue[finalIndex];
5057
+ if (!instance || !Object.is(instance.item, sourceItem) || keyedRowIdentity(props.rowKey(item, finalIndex)) !== instance.key) {
5058
+ return void 0;
5059
+ }
5060
+ const bindingUpdates = prepareKeyedRowBindingUpdates(props, instance, item, finalIndex);
5061
+ if (!bindingUpdates) return void 0;
5062
+ changed.push({ bindingUpdates, instance, item });
5063
+ }
5064
+ for (let index = 0; index < update.prefixLength; index += 1) {
3432
5065
  const item = finalValue[index];
3433
5066
  const key = keyedRowIdentity(props.rowKey(item, index));
3434
5067
  if (knownKeys.has(key)) return void 0;
@@ -3446,15 +5079,43 @@ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken,
3446
5079
  } catch {
3447
5080
  return void 0;
3448
5081
  }
5082
+ if (survivorRange) {
5083
+ for (let index = 0; index < survivorRange.start; index += 1) {
5084
+ previousInstances[index].scope?.cleanup();
5085
+ previousInstances[index].element.remove();
5086
+ }
5087
+ for (let index = survivorRange.end; index < previousInstances.length; index += 1) {
5088
+ previousInstances[index].scope?.cleanup();
5089
+ previousInstances[index].element.remove();
5090
+ }
5091
+ } else {
5092
+ const survivorSet = new Set(survivorIndices);
5093
+ for (let index = 0; index < previousInstances.length; index += 1) {
5094
+ if (survivorSet.has(index)) continue;
5095
+ previousInstances[index].scope?.cleanup();
5096
+ previousInstances[index].element.remove();
5097
+ }
5098
+ }
5099
+ const survivors = survivorRange ? previousInstances.slice(survivorRange.start, survivorRange.end) : survivorIndices.map((index) => previousInstances[index]);
3449
5100
  if (prepended.length > 0) {
3450
5101
  const fragment = root.ownerDocument.createDocumentFragment();
3451
5102
  for (const instance of prepended) fragment.append(instance.element);
3452
- root.insertBefore(fragment, root.firstChild);
5103
+ root.insertBefore(fragment, survivors[0]?.element || root.firstChild);
3453
5104
  }
3454
- for (let index = 0; index < previousInstances.length; index += 1) {
3455
- previousInstances[index].index = prefixLength + index;
5105
+ for (let index = 0; index < survivors.length; index += 1) {
5106
+ survivors[index].index = update.prefixLength + index;
5107
+ }
5108
+ for (const { bindingUpdates, instance, item } of changed) {
5109
+ applyPreparedKeyedRowBindingUpdates(props, instance, bindingUpdates);
5110
+ instance.item = item;
3456
5111
  }
3457
- return new Map([...prepended, ...previousInstances].map((instance) => [instance.key, instance]));
5112
+ return keyedRowInstancesByKey([...prepended, ...survivors]);
5113
+ }
5114
+ function reconcileCompilerKeyedArrayPrependWithStructural(...args) {
5115
+ return reconcileCompilerKeyedArrayStructuralPrepend(...args) || reconcileCompilerKeyedArrayPrepend(...args);
5116
+ }
5117
+ function reconcileCompilerKeyedArrayPrependMapWithStructural(...args) {
5118
+ return reconcileCompilerKeyedArrayStructuralPrependMap(...args) || reconcileCompilerKeyedArrayStructuralPrepend(...args) || reconcileCompilerKeyedArrayPrepend(...args);
3458
5119
  }
3459
5120
  function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, instances, reactOwnedRows) {
3460
5121
  if (reactOwnedRows || props.hostBlocks || (props.conditionals?.length || 0) > 0 || !props.filterIndexIndependent || props.collectionDependency === void 0) {
@@ -3501,7 +5162,7 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
3501
5162
  for (let index = 0; index < survivors.length; index += 1) {
3502
5163
  survivors[index].index = index;
3503
5164
  }
3504
- return new Map(survivors.map((instance) => [instance.key, instance]));
5165
+ return keyedRowInstancesByKey(survivors);
3505
5166
  }
3506
5167
  function createKeyedRowConditionalRuntime() {
3507
5168
  class FarmKeyedRowConditional extends React.Component {
@@ -3675,7 +5336,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3675
5336
  this.hasReactOwnedRows()
3676
5337
  );
3677
5338
  if (appendedInstances) {
3678
- this.instances = new Map(appendedInstances);
5339
+ this.instances = appendedInstances instanceof Map ? appendedInstances : new Map(appendedInstances);
3679
5340
  this.rebuildElementIndex(this.instances);
3680
5341
  this.commitCurrentCollection(dirtyState);
3681
5342
  afterCommit?.();
@@ -3708,8 +5369,14 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3708
5369
  this.hasReactOwnedRows()
3709
5370
  );
3710
5371
  if (reorderedInstances) {
5372
+ const removedRows = reorderedInstances.size < this.instances.size;
3711
5373
  this.instances = new Map(reorderedInstances);
3712
5374
  this.rebuildElementIndex(this.instances);
5375
+ if (removedRows) {
5376
+ const keys = [...this.instances.keys()];
5377
+ this.pruneEventHandlers(keys);
5378
+ this.pruneConditionalListeners(keys);
5379
+ }
3713
5380
  this.commitCurrentCollection(dirtyState);
3714
5381
  afterCommit?.();
3715
5382
  return;
@@ -3865,7 +5532,10 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
3865
5532
  }
3866
5533
  }
3867
5534
  commitCurrentCollection(dirtyState) {
3868
- this.collectionToken = options.keyedUpdates?.commit(this.currentProps.items());
5535
+ this.collectionToken = options.keyedUpdates?.commit(
5536
+ this.currentProps.items(),
5537
+ this.instances
5538
+ );
3869
5539
  this.commitKeyedTargets(dirtyState);
3870
5540
  }
3871
5541
  hasSafeMembershipTargets(dirtyState) {
@@ -4376,7 +6046,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
4376
6046
  } else {
4377
6047
  reorderCompilerKeyedRows(this.root, nextInstances, sequence, null);
4378
6048
  }
4379
- this.instances = new Map(nextInstances.map((instance) => [instance.key, instance]));
6049
+ this.instances = keyedRowInstancesByKey(nextInstances);
4380
6050
  this.rebuildElementIndex(this.instances);
4381
6051
  this.pruneEventHandlers(rows.keys);
4382
6052
  this.pruneConditionalListeners(rows.keys);
@@ -4893,6 +6563,14 @@ var keyedRowsReorderHintedRuntimeFeature = {
4893
6563
  })
4894
6564
  })
4895
6565
  };
6566
+ var keyedRowsMapReorderHintedRuntimeFeature = {
6567
+ name: "keyed-rows:map-reorder-hinted",
6568
+ create: (owner) => ({
6569
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6570
+ keyedUpdates: keyedMapReorderUpdateRuntime
6571
+ })
6572
+ })
6573
+ };
4896
6574
  var keyedRowsAllHintedRuntimeFeature = {
4897
6575
  name: "keyed-rows:all-hinted",
4898
6576
  create: (owner) => ({
@@ -4933,6 +6611,38 @@ var keyedRowsFilterHintedRuntimeFeature = {
4933
6611
  })
4934
6612
  })
4935
6613
  };
6614
+ var keyedRowsStructuralAppendHintedRuntimeFeature = {
6615
+ name: "keyed-rows:structural-append-hinted",
6616
+ create: (owner) => ({
6617
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6618
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6619
+ })
6620
+ })
6621
+ };
6622
+ var keyedRowsStructuralAppendMapHintedRuntimeFeature = {
6623
+ name: "keyed-rows:structural-append-map-hinted",
6624
+ create: (owner) => ({
6625
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6626
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6627
+ })
6628
+ })
6629
+ };
6630
+ var keyedRowsStructuralPrependHintedRuntimeFeature = {
6631
+ name: "keyed-rows:structural-prepend-hinted",
6632
+ create: (owner) => ({
6633
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6634
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6635
+ })
6636
+ })
6637
+ };
6638
+ var keyedRowsStructuralPrependMapHintedRuntimeFeature = {
6639
+ name: "keyed-rows:structural-prepend-map-hinted",
6640
+ create: (owner) => ({
6641
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6642
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6643
+ })
6644
+ })
6645
+ };
4936
6646
  var keyedRowsPrependHintedRuntimeFeature = {
4937
6647
  name: "keyed-rows:prepend-hinted",
4938
6648
  create: (owner) => ({
@@ -4945,7 +6655,7 @@ var keyedRowsFilterPrependHintedRuntimeFeature = {
4945
6655
  name: "keyed-rows:filter-prepend-hinted",
4946
6656
  create: (owner) => ({
4947
6657
  KeyedRows: createKeyedRowsBlockComponent(owner, {
4948
- keyedUpdates: keyedFilterPrependUpdateRuntime
6658
+ keyedUpdates: keyedStructuralPrependUpdateRuntime
4949
6659
  })
4950
6660
  })
4951
6661
  };
@@ -5047,6 +6757,42 @@ var keyedRowsConditionalFilterHintedRuntimeFeature = {
5047
6757
  })
5048
6758
  })
5049
6759
  };
6760
+ var keyedRowsConditionalStructuralAppendHintedRuntimeFeature = {
6761
+ name: "keyed-rows:conditional:structural-append-hinted",
6762
+ create: (owner) => ({
6763
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6764
+ conditionals: createKeyedRowConditionalRuntime(),
6765
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6766
+ })
6767
+ })
6768
+ };
6769
+ var keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature = {
6770
+ name: "keyed-rows:conditional:structural-append-map-hinted",
6771
+ create: (owner) => ({
6772
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6773
+ conditionals: createKeyedRowConditionalRuntime(),
6774
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6775
+ })
6776
+ })
6777
+ };
6778
+ var keyedRowsConditionalStructuralPrependHintedRuntimeFeature = {
6779
+ name: "keyed-rows:conditional:structural-prepend-hinted",
6780
+ create: (owner) => ({
6781
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6782
+ conditionals: createKeyedRowConditionalRuntime(),
6783
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6784
+ })
6785
+ })
6786
+ };
6787
+ var keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature = {
6788
+ name: "keyed-rows:conditional:structural-prepend-map-hinted",
6789
+ create: (owner) => ({
6790
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6791
+ conditionals: createKeyedRowConditionalRuntime(),
6792
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6793
+ })
6794
+ })
6795
+ };
5050
6796
  var keyedRowsConditionalPrependHintedRuntimeFeature = {
5051
6797
  name: "keyed-rows:conditional:prepend-hinted",
5052
6798
  create: (owner) => ({
@@ -5163,6 +6909,42 @@ var keyedRowsHostFilterHintedRuntimeFeature = {
5163
6909
  })
5164
6910
  })
5165
6911
  };
6912
+ var keyedRowsHostStructuralAppendHintedRuntimeFeature = {
6913
+ name: "keyed-rows:host:structural-append-hinted",
6914
+ create: (owner) => ({
6915
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6916
+ hostBlocks: createKeyedRowHostRuntime(),
6917
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
6918
+ })
6919
+ })
6920
+ };
6921
+ var keyedRowsHostStructuralAppendMapHintedRuntimeFeature = {
6922
+ name: "keyed-rows:host:structural-append-map-hinted",
6923
+ create: (owner) => ({
6924
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6925
+ hostBlocks: createKeyedRowHostRuntime(),
6926
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
6927
+ })
6928
+ })
6929
+ };
6930
+ var keyedRowsHostStructuralPrependHintedRuntimeFeature = {
6931
+ name: "keyed-rows:host:structural-prepend-hinted",
6932
+ create: (owner) => ({
6933
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6934
+ hostBlocks: createKeyedRowHostRuntime(),
6935
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
6936
+ })
6937
+ })
6938
+ };
6939
+ var keyedRowsHostStructuralPrependMapHintedRuntimeFeature = {
6940
+ name: "keyed-rows:host:structural-prepend-map-hinted",
6941
+ create: (owner) => ({
6942
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
6943
+ hostBlocks: createKeyedRowHostRuntime(),
6944
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
6945
+ })
6946
+ })
6947
+ };
5166
6948
  var keyedRowsHostPrependHintedRuntimeFeature = {
5167
6949
  name: "keyed-rows:host:prepend-hinted",
5168
6950
  create: (owner) => ({
@@ -5290,6 +7072,46 @@ var keyedRowsCompleteFilterHintedRuntimeFeature = {
5290
7072
  })
5291
7073
  })
5292
7074
  };
7075
+ var keyedRowsCompleteStructuralAppendHintedRuntimeFeature = {
7076
+ name: "keyed-rows:complete:structural-append-hinted",
7077
+ create: (owner) => ({
7078
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7079
+ conditionals: createKeyedRowConditionalRuntime(),
7080
+ hostBlocks: createKeyedRowHostRuntime(),
7081
+ keyedUpdates: keyedWindowEveryStructuralAppendUpdateRuntime
7082
+ })
7083
+ })
7084
+ };
7085
+ var keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature = {
7086
+ name: "keyed-rows:complete:structural-append-map-hinted",
7087
+ create: (owner) => ({
7088
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7089
+ conditionals: createKeyedRowConditionalRuntime(),
7090
+ hostBlocks: createKeyedRowHostRuntime(),
7091
+ keyedUpdates: keyedWindowEveryStructuralAppendMapUpdateRuntime
7092
+ })
7093
+ })
7094
+ };
7095
+ var keyedRowsCompleteStructuralPrependHintedRuntimeFeature = {
7096
+ name: "keyed-rows:complete:structural-prepend-hinted",
7097
+ create: (owner) => ({
7098
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7099
+ conditionals: createKeyedRowConditionalRuntime(),
7100
+ hostBlocks: createKeyedRowHostRuntime(),
7101
+ keyedUpdates: keyedCompleteCompatibilityUpdateRuntime
7102
+ })
7103
+ })
7104
+ };
7105
+ var keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature = {
7106
+ name: "keyed-rows:complete:structural-prepend-map-hinted",
7107
+ create: (owner) => ({
7108
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7109
+ conditionals: createKeyedRowConditionalRuntime(),
7110
+ hostBlocks: createKeyedRowHostRuntime(),
7111
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
7112
+ })
7113
+ })
7114
+ };
5293
7115
  var keyedRowsCompletePrependHintedRuntimeFeature = {
5294
7116
  name: "keyed-rows:complete:prepend-hinted",
5295
7117
  create: (owner) => ({
@@ -5310,6 +7132,16 @@ var keyedRowsCompleteFilterPrependHintedRuntimeFeature = {
5310
7132
  })
5311
7133
  })
5312
7134
  };
7135
+ var keyedRowsCompleteCompatibilityRuntimeFeature = {
7136
+ name: "keyed-rows:complete:compatibility",
7137
+ create: (owner) => ({
7138
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
7139
+ conditionals: createKeyedRowConditionalRuntime(),
7140
+ hostBlocks: createKeyedRowHostRuntime(),
7141
+ keyedUpdates: keyedCompleteStructuralPrependMapUpdateRuntime
7142
+ })
7143
+ })
7144
+ };
5313
7145
  var keyedRangesRuntimeFeature = {
5314
7146
  name: "keyed-ranges",
5315
7147
  create: (owner) => ({
@@ -5782,7 +7614,7 @@ var COMPLETE_RUNTIME_FEATURES = [
5782
7614
  hostConditionalRuntimeFeature,
5783
7615
  conditionalRangesRuntimeFeature,
5784
7616
  keyedListRuntimeFeature,
5785
- keyedRowsCompleteWindowEveryHintedRuntimeFeature,
7617
+ keyedRowsCompleteCompatibilityRuntimeFeature,
5786
7618
  keyedRangesRuntimeFeature,
5787
7619
  mixedRangesRuntimeFeature,
5788
7620
  componentRuntimeFeature
@@ -5791,6 +7623,6 @@ function createCompiledComponent(definition) {
5791
7623
  return createCompiledComponentWithFeatures(definition, COMPLETE_RUNTIME_FEATURES);
5792
7624
  }
5793
7625
 
5794
- export { applyCompilerKeyedCollectionMutation, componentRuntimeFeature, conditionalRangesRuntimeFeature, conditionalRuntimeFeature, createCompiledComponent, createCompiledComponentWithFeatures, createCompilerKeyedArrayAppend, createCompilerKeyedArrayBatchInsert, createCompilerKeyedArrayFilter, createCompilerKeyedArrayPositionUpdate, createCompilerKeyedArrayPrepend, createCompilerKeyedArrayReorder, createCompilerKeyedArrayRollingWindow, createCompilerKeyedArraySlice, createCompilerKeyedArraySort, createCompilerKeyedArrayWindowReplace, createCompilerKeyedCollectionUpdate, createCompilerKeyedMapUpdate, hostConditionalRuntimeFeature, keyedListRuntimeFeature, keyedRangesRuntimeFeature, keyedRowsAllHintedRuntimeFeature, keyedRowsBatchEveryHintedRuntimeFeature, keyedRowsBatchPositionHintedRuntimeFeature, keyedRowsCompleteAllHintedRuntimeFeature, keyedRowsCompleteBatchEveryHintedRuntimeFeature, keyedRowsCompleteBatchPositionHintedRuntimeFeature, keyedRowsCompleteEveryHintedRuntimeFeature, keyedRowsCompleteFilterHintedRuntimeFeature, keyedRowsCompleteFilterPrependHintedRuntimeFeature, keyedRowsCompleteHintedRuntimeFeature, keyedRowsCompletePositionHintedRuntimeFeature, keyedRowsCompletePrependHintedRuntimeFeature, keyedRowsCompleteReorderHintedRuntimeFeature, keyedRowsCompleteRuntimeFeature, keyedRowsCompleteWindowEveryHintedRuntimeFeature, keyedRowsCompleteWindowPositionHintedRuntimeFeature, keyedRowsConditionalAllHintedRuntimeFeature, keyedRowsConditionalBatchEveryHintedRuntimeFeature, keyedRowsConditionalBatchPositionHintedRuntimeFeature, keyedRowsConditionalEveryHintedRuntimeFeature, keyedRowsConditionalFilterHintedRuntimeFeature, keyedRowsConditionalFilterPrependHintedRuntimeFeature, keyedRowsConditionalHintedRuntimeFeature, keyedRowsConditionalPositionHintedRuntimeFeature, keyedRowsConditionalPrependHintedRuntimeFeature, keyedRowsConditionalReorderHintedRuntimeFeature, keyedRowsConditionalRuntimeFeature, keyedRowsConditionalWindowEveryHintedRuntimeFeature, keyedRowsConditionalWindowPositionHintedRuntimeFeature, keyedRowsEveryHintedRuntimeFeature, keyedRowsFilterHintedRuntimeFeature, keyedRowsFilterPrependHintedRuntimeFeature, keyedRowsHintedRuntimeFeature, keyedRowsHostAllHintedRuntimeFeature, keyedRowsHostBatchEveryHintedRuntimeFeature, keyedRowsHostBatchPositionHintedRuntimeFeature, keyedRowsHostEveryHintedRuntimeFeature, keyedRowsHostFilterHintedRuntimeFeature, keyedRowsHostFilterPrependHintedRuntimeFeature, keyedRowsHostHintedRuntimeFeature, keyedRowsHostPositionHintedRuntimeFeature, keyedRowsHostPrependHintedRuntimeFeature, keyedRowsHostReorderHintedRuntimeFeature, keyedRowsHostRuntimeFeature, keyedRowsHostWindowEveryHintedRuntimeFeature, keyedRowsHostWindowPositionHintedRuntimeFeature, keyedRowsPositionHintedRuntimeFeature, keyedRowsPrependHintedRuntimeFeature, keyedRowsReorderHintedRuntimeFeature, keyedRowsRuntimeFeature, keyedRowsWindowEveryHintedRuntimeFeature, keyedRowsWindowPositionHintedRuntimeFeature, mixedRangesRuntimeFeature };
7626
+ export { applyCompilerKeyedCollectionMutation, componentRuntimeFeature, conditionalRangesRuntimeFeature, conditionalRuntimeFeature, createCompiledComponent, createCompiledComponentWithFeatures, createCompilerKeyedArrayAppend, createCompilerKeyedArrayBatchInsert, createCompilerKeyedArrayFilter, createCompilerKeyedArrayMapPipeline, createCompilerKeyedArrayMapReorder, createCompilerKeyedArrayMappedStructuralAppend, createCompilerKeyedArrayMappedStructuralPrepend, createCompilerKeyedArrayPositionUpdate, createCompilerKeyedArrayPrepend, createCompilerKeyedArrayQueuedMapPipeline, createCompilerKeyedArrayReorder, createCompilerKeyedArrayRollingWindow, createCompilerKeyedArraySlice, createCompilerKeyedArraySort, createCompilerKeyedArrayStructuralAppend, createCompilerKeyedArrayStructuralAppendMapPipeline, createCompilerKeyedArrayStructuralPrepend, createCompilerKeyedArrayStructuralPrependMapPipeline, createCompilerKeyedArrayStructuralReorder, createCompilerKeyedArrayStructuralSort, createCompilerKeyedArrayWindowReplace, createCompilerKeyedCollectionUpdate, createCompilerKeyedMapUpdate, finalizeCompilerKeyedArrayMappedStructuralUpdate, hostConditionalRuntimeFeature, keyedListRuntimeFeature, keyedRangesRuntimeFeature, keyedRowsAllHintedRuntimeFeature, keyedRowsBatchEveryHintedRuntimeFeature, keyedRowsBatchPositionHintedRuntimeFeature, keyedRowsCompleteAllHintedRuntimeFeature, keyedRowsCompleteBatchEveryHintedRuntimeFeature, keyedRowsCompleteBatchPositionHintedRuntimeFeature, keyedRowsCompleteEveryHintedRuntimeFeature, keyedRowsCompleteFilterHintedRuntimeFeature, keyedRowsCompleteFilterPrependHintedRuntimeFeature, keyedRowsCompleteHintedRuntimeFeature, keyedRowsCompletePositionHintedRuntimeFeature, keyedRowsCompletePrependHintedRuntimeFeature, keyedRowsCompleteReorderHintedRuntimeFeature, keyedRowsCompleteRuntimeFeature, keyedRowsCompleteStructuralAppendHintedRuntimeFeature, keyedRowsCompleteStructuralAppendMapHintedRuntimeFeature, keyedRowsCompleteStructuralPrependHintedRuntimeFeature, keyedRowsCompleteStructuralPrependMapHintedRuntimeFeature, keyedRowsCompleteWindowEveryHintedRuntimeFeature, keyedRowsCompleteWindowPositionHintedRuntimeFeature, keyedRowsConditionalAllHintedRuntimeFeature, keyedRowsConditionalBatchEveryHintedRuntimeFeature, keyedRowsConditionalBatchPositionHintedRuntimeFeature, keyedRowsConditionalEveryHintedRuntimeFeature, keyedRowsConditionalFilterHintedRuntimeFeature, keyedRowsConditionalFilterPrependHintedRuntimeFeature, keyedRowsConditionalHintedRuntimeFeature, keyedRowsConditionalPositionHintedRuntimeFeature, keyedRowsConditionalPrependHintedRuntimeFeature, keyedRowsConditionalReorderHintedRuntimeFeature, keyedRowsConditionalRuntimeFeature, keyedRowsConditionalStructuralAppendHintedRuntimeFeature, keyedRowsConditionalStructuralAppendMapHintedRuntimeFeature, keyedRowsConditionalStructuralPrependHintedRuntimeFeature, keyedRowsConditionalStructuralPrependMapHintedRuntimeFeature, keyedRowsConditionalWindowEveryHintedRuntimeFeature, keyedRowsConditionalWindowPositionHintedRuntimeFeature, keyedRowsEveryHintedRuntimeFeature, keyedRowsFilterHintedRuntimeFeature, keyedRowsFilterPrependHintedRuntimeFeature, keyedRowsHintedRuntimeFeature, keyedRowsHostAllHintedRuntimeFeature, keyedRowsHostBatchEveryHintedRuntimeFeature, keyedRowsHostBatchPositionHintedRuntimeFeature, keyedRowsHostEveryHintedRuntimeFeature, keyedRowsHostFilterHintedRuntimeFeature, keyedRowsHostFilterPrependHintedRuntimeFeature, keyedRowsHostHintedRuntimeFeature, keyedRowsHostPositionHintedRuntimeFeature, keyedRowsHostPrependHintedRuntimeFeature, keyedRowsHostReorderHintedRuntimeFeature, keyedRowsHostRuntimeFeature, keyedRowsHostStructuralAppendHintedRuntimeFeature, keyedRowsHostStructuralAppendMapHintedRuntimeFeature, keyedRowsHostStructuralPrependHintedRuntimeFeature, keyedRowsHostStructuralPrependMapHintedRuntimeFeature, keyedRowsHostWindowEveryHintedRuntimeFeature, keyedRowsHostWindowPositionHintedRuntimeFeature, keyedRowsMapReorderHintedRuntimeFeature, keyedRowsPositionHintedRuntimeFeature, keyedRowsPrependHintedRuntimeFeature, keyedRowsReorderHintedRuntimeFeature, keyedRowsRuntimeFeature, keyedRowsStructuralAppendHintedRuntimeFeature, keyedRowsStructuralAppendMapHintedRuntimeFeature, keyedRowsStructuralPrependHintedRuntimeFeature, keyedRowsStructuralPrependMapHintedRuntimeFeature, keyedRowsWindowEveryHintedRuntimeFeature, keyedRowsWindowPositionHintedRuntimeFeature, mixedRangesRuntimeFeature };
5795
7627
  //# sourceMappingURL=compiler-runtime.mjs.map
5796
7628
  //# sourceMappingURL=compiler-runtime.mjs.map