voodoojs 0.12.5 → 0.13.0

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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-D45ZEXUO.js → chunk-2LGAXVD7.js} +4 -4
  3. package/dist/{chunk-L3JNHLTI.js → chunk-4IJE5BWY.js} +5 -5
  4. package/dist/{chunk-PPT7RDKJ.js → chunk-FMDHZ5GI.js} +139 -9
  5. package/dist/{chunk-JB72AX7G.js → chunk-GE4JWATC.js} +5 -5
  6. package/dist/{chunk-TUXGS7XW.js → chunk-H2NGDLMD.js} +363 -76
  7. package/dist/{chunk-YH3IDF6L.js → chunk-IBIZ6OUI.js} +4 -4
  8. package/dist/{chunk-PO6REBDJ.js → chunk-IJQ2PFXU.js} +3 -3
  9. package/dist/{chunk-6QFKV444.js → chunk-JBUNTP7F.js} +7 -7
  10. package/dist/{chunk-IWHK6Y32.js → chunk-MV73OSCS.js} +4 -4
  11. package/dist/{chunk-X3FZPWI6.js → chunk-OIH4BR2H.js} +6 -6
  12. package/dist/{chunk-OH6FIDTW.js → chunk-TEVCUTTC.js} +3 -3
  13. package/dist/essential.cjs +496 -74
  14. package/dist/essential.js +10 -10
  15. package/dist/gpu.cjs +1 -1
  16. package/dist/gpu.js +10 -10
  17. package/dist/http.cjs +1 -1
  18. package/dist/http.js +5 -5
  19. package/dist/index.cjs +544 -122
  20. package/dist/index.js +20 -20
  21. package/dist/reactivity.cjs +138 -5
  22. package/dist/reactivity.d.cts +32 -1
  23. package/dist/reactivity.d.ts +32 -1
  24. package/dist/reactivity.js +2 -2
  25. package/dist/socket.cjs +115 -5
  26. package/dist/socket.d.cts +1 -1
  27. package/dist/socket.d.ts +1 -1
  28. package/dist/socket.js +9 -9
  29. package/dist/style-E22XVZ33.js +5 -0
  30. package/dist/utils.cjs +1 -1
  31. package/dist/utils.js +2 -2
  32. package/dist/voodoo.core.js +560 -72
  33. package/dist/voodoo.core.min.js +17 -17
  34. package/dist/voodoo.full.js +609 -121
  35. package/dist/voodoo.full.min.js +62 -62
  36. package/dist/voodoo.js +563 -75
  37. package/dist/voodoo.min.js +26 -26
  38. package/package.json +1 -1
  39. package/dist/style-YWBYOE6T.js +0 -5
package/dist/voodoo.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Voodoo.js v0.12.5
2
+ * Voodoo.js v0.13.0
3
3
  * JavaScript feels like magic.
4
4
  * (c) 2026 Voodoo.js contributors. MIT License.
5
5
  */
@@ -31,10 +31,12 @@ var Voodoo = (() => {
31
31
  // src/reactivity/index.ts
32
32
  var reactivity_exports = {};
33
33
  __export(reactivity_exports, {
34
+ ArrayOp: () => ArrayOp,
34
35
  EffectScope: () => EffectScope,
35
36
  ITERATE_KEY: () => ITERATE_KEY,
36
37
  ReactiveEffect: () => ReactiveEffect,
37
38
  TriggerType: () => TriggerType,
39
+ arrayVersion: () => arrayVersion,
38
40
  computed: () => computed,
39
41
  effect: () => effect,
40
42
  effectScope: () => effectScope,
@@ -47,6 +49,7 @@ var Voodoo = (() => {
47
49
  isReactive: () => isReactive,
48
50
  isRef: () => isRef,
49
51
  markRaw: () => markRaw,
52
+ mutationsSince: () => mutationsSince,
50
53
  nextTick: () => nextTick,
51
54
  pauseTracking: () => pauseTracking,
52
55
  queueJob: () => queueJob,
@@ -210,7 +213,9 @@ var Voodoo = (() => {
210
213
  if (!isArr) add(depsMap.get(ITERATE_KEY));
211
214
  else if (isIntegerKey(key)) add(depsMap.get("length"));
212
215
  } else if (type === "delete" /* DELETE */) {
213
- if (!isArr) add(depsMap.get(ITERATE_KEY));
216
+ add(depsMap.get(ITERATE_KEY));
217
+ } else if (isArr && isIntegerKey(key)) {
218
+ add(depsMap.get(ITERATE_KEY));
214
219
  } else if (isArr && key === "length") {
215
220
  const newLen = Number(_newValue);
216
221
  depsMap.forEach((dep, k) => {
@@ -223,12 +228,61 @@ var Voodoo = (() => {
223
228
  else queueJob(e);
224
229
  }
225
230
  }
231
+ function triggerArrayRange(target, from) {
232
+ const depsMap = targetMap.get(target);
233
+ if (!depsMap) return;
234
+ const effects = /* @__PURE__ */ new Set();
235
+ const add = (dep) => {
236
+ if (!dep) return;
237
+ for (const e of dep) if (e !== activeEffect) effects.add(e);
238
+ };
239
+ add(depsMap.get("length"));
240
+ add(depsMap.get(ITERATE_KEY));
241
+ if (from >= 0) {
242
+ depsMap.forEach((dep, k) => {
243
+ if (typeof k === "string" && isIntegerKey(k) && Number(k) >= from) add(dep);
244
+ });
245
+ }
246
+ for (const e of effects) {
247
+ if (e.scheduler) e.scheduler();
248
+ else queueJob(e);
249
+ }
250
+ }
251
+ function record(target, type, index, removed, added) {
252
+ let log = mutationLogs.get(target);
253
+ if (!log) mutationLogs.set(target, log = { version: 0, ops: [] });
254
+ log.version++;
255
+ if (type === 3 /* RESET */) {
256
+ log.ops.length = 0;
257
+ return;
258
+ }
259
+ log.ops.push({ type, index, removed, added });
260
+ if (log.ops.length > LOG_LIMIT) log.ops.shift();
261
+ }
262
+ function arrayVersion(target) {
263
+ const log = mutationLogs.get(target);
264
+ return log ? log.version : 0;
265
+ }
266
+ function mutationsSince(target, since) {
267
+ const log = mutationLogs.get(target);
268
+ if (!log) return since === 0 ? NO_MUTATIONS : null;
269
+ if (since > log.version) return null;
270
+ const missing = log.version - since;
271
+ if (missing === 0) return NO_MUTATIONS;
272
+ if (missing > log.ops.length) return null;
273
+ return log.ops.slice(log.ops.length - missing);
274
+ }
226
275
  function isIntegerKey(key) {
227
276
  return typeof key === "string" && key !== "NaN" && key[0] !== "-" && String(parseInt(key, 10)) === key;
228
277
  }
229
278
  function isObject(val) {
230
279
  return val !== null && typeof val === "object";
231
280
  }
281
+ function spliceStart(raw, length) {
282
+ const n = Math.trunc(Number(raw)) || 0;
283
+ if (n < 0) return Math.max(length + n, 0);
284
+ return Math.min(n, length);
285
+ }
232
286
  function canObserve(value) {
233
287
  if (!isObject(value)) return false;
234
288
  if (value[SKIP]) return false;
@@ -238,6 +292,23 @@ var Voodoo = (() => {
238
292
  if (NON_REACTIVE.has(tag)) return false;
239
293
  return tag === "Object" || tag === "Array" || tag === "Map" || tag === "Set";
240
294
  }
295
+ function recordDirectWrite(target, key, lengthBefore, hadKey, oldValue, value) {
296
+ if (key === "length") {
297
+ const next = target.length;
298
+ if (next < lengthBefore) record(target, 1 /* SPLICE */, next, lengthBefore - next, 0);
299
+ else if (next > lengthBefore) record(target, 3 /* RESET */, 0, 0, 0);
300
+ return;
301
+ }
302
+ if (!isIntegerKey(key)) return;
303
+ const index = Number(key);
304
+ if (hadKey) {
305
+ if (hasChanged(value, oldValue)) record(target, 2 /* SET */, index, 1, 1);
306
+ } else if (index === lengthBefore) {
307
+ record(target, 1 /* SPLICE */, index, 0, 1);
308
+ } else {
309
+ record(target, 3 /* RESET */, 0, 0, 0);
310
+ }
311
+ }
241
312
  function markRaw(value) {
242
313
  Object.defineProperty(value, SKIP, { value: true, enumerable: false, configurable: true });
243
314
  return value;
@@ -360,7 +431,7 @@ var Voodoo = (() => {
360
431
  else for (const key of Object.keys(value)) traverse(value[key], seen);
361
432
  return value;
362
433
  }
363
- var resolvedPromise, queue, postQueue, isFlushing, isFlushPending, flushPromise, RECURSION_LIMIT, errorHandler, activeEffect, shouldTrack, trackStack, effectId, ReactiveEffect, activeScope, EffectScope, ITERATE_KEY, targetMap, TriggerType, RAW, IS_REACTIVE, SKIP, reactiveMap, arrayInstrumentations, NON_REACTIVE, baseHandlers, collectionHandlers, RefImpl, ComputedRefImpl;
434
+ var resolvedPromise, queue, postQueue, isFlushing, isFlushPending, flushPromise, RECURSION_LIMIT, errorHandler, activeEffect, shouldTrack, trackStack, effectId, ReactiveEffect, activeScope, EffectScope, ITERATE_KEY, targetMap, TriggerType, ArrayOp, LOG_LIMIT, mutationLogs, NO_MUTATIONS, RAW, IS_REACTIVE, SKIP, reactiveMap, arrayInstrumentations, NON_REACTIVE, baseHandlers, collectionHandlers, RefImpl, ComputedRefImpl;
364
435
  var init_reactivity = __esm({
365
436
  "src/reactivity/index.ts"() {
366
437
  "use strict";
@@ -490,6 +561,15 @@ var Voodoo = (() => {
490
561
  TriggerType2["CLEAR"] = "clear";
491
562
  return TriggerType2;
492
563
  })(TriggerType || {});
564
+ ArrayOp = /* @__PURE__ */ ((ArrayOp2) => {
565
+ ArrayOp2[ArrayOp2["SPLICE"] = 1] = "SPLICE";
566
+ ArrayOp2[ArrayOp2["SET"] = 2] = "SET";
567
+ ArrayOp2[ArrayOp2["RESET"] = 3] = "RESET";
568
+ return ArrayOp2;
569
+ })(ArrayOp || {});
570
+ LOG_LIMIT = 32;
571
+ mutationLogs = /* @__PURE__ */ new WeakMap();
572
+ NO_MUTATIONS = [];
493
573
  RAW = /* @__PURE__ */ Symbol("voodoo:raw");
494
574
  IS_REACTIVE = /* @__PURE__ */ Symbol("voodoo:isReactive");
495
575
  SKIP = /* @__PURE__ */ Symbol("voodoo:skip");
@@ -507,14 +587,61 @@ var Voodoo = (() => {
507
587
  return res;
508
588
  };
509
589
  }
510
- for (const key of ["push", "pop", "shift", "unshift", "splice"]) {
590
+ for (const key of ["push", "pop", "shift", "unshift", "splice", "reverse", "sort"]) {
511
591
  inst[key] = function(...args) {
592
+ const raw = toRaw(this);
593
+ const before = raw.length;
594
+ for (let i = 0; i < args.length; i++) args[i] = toRaw(args[i]);
512
595
  pauseTracking();
596
+ let result;
513
597
  try {
514
- return toRaw(this)[key].apply(this, args);
598
+ result = raw[key].apply(raw, args);
515
599
  } finally {
516
600
  resetTracking();
517
601
  }
602
+ const after = raw.length;
603
+ let from = -1;
604
+ if (key === "push") {
605
+ if (args.length) {
606
+ record(raw, 1 /* SPLICE */, before, 0, args.length);
607
+ from = before;
608
+ }
609
+ } else if (key === "unshift") {
610
+ if (args.length) {
611
+ record(raw, 1 /* SPLICE */, 0, 0, args.length);
612
+ from = 0;
613
+ }
614
+ } else if (key === "pop") {
615
+ if (before > 0) {
616
+ record(raw, 1 /* SPLICE */, after, 1, 0);
617
+ from = after;
618
+ }
619
+ } else if (key === "shift") {
620
+ if (before > 0) {
621
+ record(raw, 1 /* SPLICE */, 0, 1, 0);
622
+ from = 0;
623
+ }
624
+ } else if (key === "splice") {
625
+ const removed = result.length;
626
+ const added = args.length > 2 ? args.length - 2 : 0;
627
+ if (removed || added) {
628
+ record(raw, 1 /* SPLICE */, spliceStart(args[0], before), removed, added);
629
+ from = spliceStart(args[0], before);
630
+ }
631
+ } else {
632
+ if (before > 1) {
633
+ record(raw, 3 /* RESET */, 0, before, after);
634
+ from = 0;
635
+ }
636
+ }
637
+ if (from >= 0) triggerArrayRange(raw, from);
638
+ if (key === "pop" || key === "shift") return isObject(result) ? reactive(result) : result;
639
+ if (key === "splice") {
640
+ const out = result;
641
+ for (let i = 0; i < out.length; i++) if (isObject(out[i])) out[i] = reactive(out[i]);
642
+ return out;
643
+ }
644
+ return key === "reverse" || key === "sort" ? this : result;
518
645
  };
519
646
  }
520
647
  return inst;
@@ -556,8 +683,11 @@ var Voodoo = (() => {
556
683
  return true;
557
684
  }
558
685
  const hadKey = Array.isArray(target) && isIntegerKey(key) ? Number(key) < target.length : Object.prototype.hasOwnProperty.call(target, key);
686
+ const isArr = Array.isArray(target);
687
+ const arrayLength = isArr ? target.length : 0;
559
688
  const result = Reflect.set(target, key, value, receiver);
560
689
  if (target === toRaw(receiver)) {
690
+ if (isArr) recordDirectWrite(target, key, arrayLength, hadKey, oldValue, value);
561
691
  if (!hadKey) trigger(target, "add" /* ADD */, key, value);
562
692
  else if (hasChanged(value, oldValue)) trigger(target, "set" /* SET */, key, value);
563
693
  }
@@ -566,7 +696,10 @@ var Voodoo = (() => {
566
696
  deleteProperty(target, key) {
567
697
  const hadKey = Object.prototype.hasOwnProperty.call(target, key);
568
698
  const result = Reflect.deleteProperty(target, key);
569
- if (result && hadKey) trigger(target, "delete" /* DELETE */, key);
699
+ if (result && hadKey) {
700
+ if (Array.isArray(target)) record(target, 3 /* RESET */, 0, 0, 0);
701
+ trigger(target, "delete" /* DELETE */, key);
702
+ }
570
703
  return result;
571
704
  },
572
705
  has(target, key) {
@@ -5717,6 +5850,35 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5717
5850
  // src/directives/core.ts
5718
5851
  init_reactivity();
5719
5852
  init_registry();
5853
+
5854
+ // src/runtime/metrics.ts
5855
+ function blank() {
5856
+ return {
5857
+ on: false,
5858
+ itemsVisited: 0,
5859
+ keyEvaluations: 0,
5860
+ prefixScanned: 0,
5861
+ suffixScanned: 0,
5862
+ middleReconciled: 0,
5863
+ scopeAllocations: 0,
5864
+ proxyWrites: 0,
5865
+ arrayAllocations: 0,
5866
+ keyMapLookups: 0,
5867
+ domCreates: 0,
5868
+ domRemoves: 0,
5869
+ domMoves: 0,
5870
+ domInserts: 0,
5871
+ lisRuns: 0,
5872
+ lisElements: 0,
5873
+ paths: {}
5874
+ };
5875
+ }
5876
+ var metrics = /* @__PURE__ */ blank();
5877
+ function countPath(name) {
5878
+ metrics.paths[name] = (metrics.paths[name] || 0) + 1;
5879
+ }
5880
+
5881
+ // src/directives/core.ts
5720
5882
  function setValue(expression, scope, value) {
5721
5883
  try {
5722
5884
  const target = parse(expression);
@@ -5862,7 +6024,7 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5862
6024
  },
5863
6025
  { priority: PRIORITY.IF, terminal: true }
5864
6026
  );
5865
- function renderTemplate(source, anchor, scope, batch) {
6027
+ function renderTemplate(source, anchor, scope) {
5866
6028
  const parent = anchor.parentNode;
5867
6029
  if (!parent) return [];
5868
6030
  const nodes = [];
@@ -5879,21 +6041,64 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5879
6041
  }
5880
6042
  } else {
5881
6043
  const clone2 = source.cloneNode(true);
6044
+ if (metrics.on) metrics.domCreates++;
5882
6045
  nodes.push(clone2);
5883
6046
  markNodeScope(clone2, scope);
5884
- if (batch) {
5885
- batch.fragment.appendChild(clone2);
5886
- batch.pending.push([clone2, scope]);
5887
- } else {
5888
- parent.insertBefore(clone2, anchor);
5889
- walk(clone2, scope);
5890
- }
6047
+ parent.insertBefore(clone2, anchor);
6048
+ walk(clone2, scope);
5891
6049
  }
5892
6050
  return nodes;
5893
6051
  }
5894
6052
  defineDirective("else-if", () => void 0, { priority: PRIORITY.IF, terminal: true });
5895
6053
  defineDirective("else", () => void 0, { priority: PRIORITY.IF, terminal: true });
5896
6054
  var FOR_PATTERN = /^\s*\(?\s*([^)]*?)\s*\)?\s+(?:in|of)\s+(.+?)\s*$/;
6055
+ var KEY_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
6056
+ var NO_BLOCKS = [];
6057
+ function sameStored(stored, incoming) {
6058
+ if (stored === incoming) return true;
6059
+ return incoming !== null && typeof incoming === "object" && stored === toRaw(incoming);
6060
+ }
6061
+ function sameKey(a, b) {
6062
+ return a === b || a !== a && b !== b;
6063
+ }
6064
+ function longestIncreasing(arr) {
6065
+ const length = arr.length;
6066
+ const previous = new Int32Array(length);
6067
+ const tails = [];
6068
+ for (let i = 0; i < length; i++) {
6069
+ const value = arr[i];
6070
+ if (value === 0) continue;
6071
+ if (tails.length === 0) {
6072
+ tails.push(i);
6073
+ continue;
6074
+ }
6075
+ const last = tails[tails.length - 1];
6076
+ if (arr[last] < value) {
6077
+ previous[i] = last;
6078
+ tails.push(i);
6079
+ continue;
6080
+ }
6081
+ let low = 0;
6082
+ let high = tails.length - 1;
6083
+ while (low < high) {
6084
+ const mid = low + high >> 1;
6085
+ if (arr[tails[mid]] < value) low = mid + 1;
6086
+ else high = mid;
6087
+ }
6088
+ if (value < arr[tails[low]]) {
6089
+ if (low > 0) previous[i] = tails[low - 1];
6090
+ tails[low] = i;
6091
+ }
6092
+ }
6093
+ let cursor = tails.length;
6094
+ const out = new Int32Array(cursor);
6095
+ let node = tails[cursor - 1];
6096
+ while (cursor-- > 0) {
6097
+ out[cursor] = node;
6098
+ node = previous[node];
6099
+ }
6100
+ return out;
6101
+ }
5897
6102
  defineDirective(
5898
6103
  "for",
5899
6104
  ({ el, scope, expression, effect: effect2 }) => {
@@ -5919,78 +6124,361 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5919
6124
  template.removeAttribute(`${p2}bind:key`);
5920
6125
  template.removeAttribute(`${p2}key`);
5921
6126
  removeQuietly(el);
6127
+ const isTemplateRow = template.tagName === "TEMPLATE";
6128
+ let keyIsItem = false;
6129
+ let keyIsIndex = false;
6130
+ let keyProp = null;
6131
+ let keyPath = null;
6132
+ if (keyExpression && KEY_PATH.test(keyExpression)) {
6133
+ const parts = keyExpression.split(".");
6134
+ if (parts[0] === itemAlias) {
6135
+ if (parts.length === 1) keyIsItem = true;
6136
+ else if (parts.length === 2) keyProp = parts[1];
6137
+ else keyPath = parts.slice(1);
6138
+ } else if (indexAlias && parts.length === 1 && parts[0] === indexAlias) {
6139
+ keyIsIndex = true;
6140
+ }
6141
+ }
5922
6142
  let blocks = [];
5923
- const clearAll = () => {
5924
- for (const block2 of blocks) {
5925
- for (const node of block2.nodes) {
5926
- destroy(node);
5927
- node.remove();
6143
+ let rows = [];
6144
+ let entries = null;
6145
+ let count = 0;
6146
+ let keyScope = null;
6147
+ let lastSource = null;
6148
+ let lastVersion = 0;
6149
+ const pending = [];
6150
+ const pendingRuns = [];
6151
+ const varsAt = (i) => {
6152
+ if (entries) return entries[i];
6153
+ const vars = { [itemAlias]: rows[i] };
6154
+ if (indexAlias) vars[indexAlias] = i;
6155
+ return vars;
6156
+ };
6157
+ const keyAt = (i) => {
6158
+ if (metrics.on) metrics.keyEvaluations++;
6159
+ if (keyIsIndex) return i;
6160
+ if (!keyExpression) {
6161
+ return i;
6162
+ }
6163
+ const item = entries ? entries[i][itemAlias] : rows[i];
6164
+ if (keyIsItem) return item;
6165
+ if (keyProp !== null) return item == null ? void 0 : item[keyProp];
6166
+ if (keyPath !== null) {
6167
+ let value = item;
6168
+ for (let d = 0; d < keyPath.length; d++) {
6169
+ if (value == null) return void 0;
6170
+ value = value[keyPath[d]];
5928
6171
  }
6172
+ return value;
5929
6173
  }
5930
- blocks = [];
6174
+ if (!keyScope) keyScope = scope.child({});
6175
+ keyScope.data = varsAt(i);
6176
+ return evaluateIn(keyExpression, keyScope, ":key");
5931
6177
  };
5932
- addCleanup(anchor, clearAll);
5933
- effect2(() => {
5934
- var _a3, _b, _c;
5935
- const source = evaluateIn(sourceExpression, scope, "v-for");
5936
- const entries = normalizeSource(source, itemAlias, indexAlias, thirdAlias);
5937
- const previous = /* @__PURE__ */ new Map();
5938
- for (const block2 of blocks) previous.set(block2.key, block2);
5939
- const next = [];
5940
- const used = /* @__PURE__ */ new Set();
5941
- const batch = {
5942
- fragment: document.createDocumentFragment(),
5943
- pending: []
5944
- };
5945
- entries.forEach((vars, index) => {
5946
- const key = keyExpression ? evaluateIn(keyExpression, scope.child(vars), ":key") : `__index_${index}`;
5947
- if (keyExpression && used.has(key)) warnDuplicateKey(el, key, expression);
5948
- const existing = previous.get(key);
5949
- if (existing && !used.has(key)) {
5950
- used.add(key);
5951
- for (const [name, value] of Object.entries(vars)) existing.data[name] = value;
5952
- next.push(existing);
5953
- return;
6178
+ const syncData = (block2, i) => {
6179
+ const raw = toRaw(block2.data);
6180
+ if (entries) {
6181
+ const vars = entries[i];
6182
+ for (const name in vars) {
6183
+ if (!sameStored(raw[name], vars[name])) {
6184
+ if (metrics.on) metrics.proxyWrites++;
6185
+ block2.data[name] = vars[name];
6186
+ }
5954
6187
  }
5955
- const childScope = scope.reactiveChild(vars);
5956
- const nodes = renderTemplate(template, anchor, childScope, batch);
5957
- used.add(key);
5958
- next.push({ key, scope: childScope, nodes, data: childScope.data });
5959
- });
5960
- if (batch.fragment.firstChild) (_a3 = anchor.parentNode) == null ? void 0 : _a3.insertBefore(batch.fragment, anchor);
5961
- for (const [node, rowScope] of batch.pending) walk(node, rowScope);
5962
- const reused = new Set(next);
5963
- for (const block2 of blocks) {
5964
- if (used.has(block2.key) && reused.has(block2)) continue;
5965
- for (const node of block2.nodes) {
5966
- destroy(node);
5967
- node.remove();
6188
+ return;
6189
+ }
6190
+ const item = rows[i];
6191
+ if (!sameStored(raw[itemAlias], item)) {
6192
+ if (metrics.on) metrics.proxyWrites++;
6193
+ block2.data[itemAlias] = item;
6194
+ }
6195
+ if (indexAlias !== void 0 && raw[indexAlias] !== i) {
6196
+ if (metrics.on) metrics.proxyWrites++;
6197
+ block2.data[indexAlias] = i;
6198
+ }
6199
+ };
6200
+ const buildRange = (from, to, before, out) => {
6201
+ if (from >= to) return;
6202
+ const parent = anchor.parentNode;
6203
+ if (!parent) return;
6204
+ pendingRuns.push(pending.length);
6205
+ if (isTemplateRow) {
6206
+ for (let i = from; i < to; i++) {
6207
+ const childScope = scope.reactiveChild(varsAt(i));
6208
+ if (metrics.on) {
6209
+ metrics.scopeAllocations++;
6210
+ metrics.itemsVisited++;
6211
+ }
6212
+ const nodes = renderTemplate(template, before, childScope);
6213
+ out.push({ key: keyAt(i), scope: childScope, nodes, data: childScope.data });
5968
6214
  }
6215
+ return;
5969
6216
  }
5970
- let cursor = anchor;
5971
- for (let i = next.length - 1; i >= 0; i--) {
5972
- const block2 = next[i];
5973
- const last = block2.nodes[block2.nodes.length - 1];
5974
- if (last && last.nextSibling !== cursor) {
5975
- for (const node of block2.nodes) (_b = anchor.parentNode) == null ? void 0 : _b.insertBefore(node, cursor);
6217
+ const fragment = document.createDocumentFragment();
6218
+ for (let i = from; i < to; i++) {
6219
+ const childScope = scope.reactiveChild(varsAt(i));
6220
+ const clone2 = template.cloneNode(true);
6221
+ markNodeScope(clone2, childScope);
6222
+ fragment.appendChild(clone2);
6223
+ pending.push([clone2, childScope]);
6224
+ out.push({ key: keyAt(i), scope: childScope, nodes: [clone2], data: childScope.data });
6225
+ if (metrics.on) {
6226
+ metrics.scopeAllocations++;
6227
+ metrics.domCreates++;
6228
+ metrics.itemsVisited++;
6229
+ }
6230
+ }
6231
+ if (metrics.on) metrics.domInserts++;
6232
+ parent.insertBefore(fragment, before);
6233
+ };
6234
+ const destroyBlock = (block2) => {
6235
+ const nodes = block2.nodes;
6236
+ for (let j = 0; j < nodes.length; j++) {
6237
+ if (metrics.on) metrics.domRemoves++;
6238
+ destroy(nodes[j]);
6239
+ nodes[j].remove();
6240
+ }
6241
+ };
6242
+ const moveBlock = (block2, before) => {
6243
+ const parent = anchor.parentNode;
6244
+ if (!parent) return;
6245
+ const nodes = block2.nodes;
6246
+ if (nodes[nodes.length - 1].nextSibling === before) return;
6247
+ for (let j = 0; j < nodes.length; j++) {
6248
+ if (metrics.on) metrics.domMoves++;
6249
+ parent.insertBefore(nodes[j], before);
6250
+ }
6251
+ };
6252
+ const nodeAfter = (oldIndex) => oldIndex < blocks.length ? blocks[oldIndex].nodes[0] : anchor;
6253
+ const spliceBlocks = (index, remove, added) => {
6254
+ const addCount = added.length;
6255
+ if (remove === 0 && addCount === 0) return;
6256
+ if (blocks.length === 0) {
6257
+ blocks = added;
6258
+ return;
6259
+ }
6260
+ if (addCount === 0) {
6261
+ blocks.splice(index, remove);
6262
+ return;
6263
+ }
6264
+ if (addCount <= 1024) {
6265
+ blocks.splice(index, remove, ...added);
6266
+ return;
6267
+ }
6268
+ const out = new Array(blocks.length - remove + addCount);
6269
+ let w = 0;
6270
+ for (let k = 0; k < index; k++) out[w++] = blocks[k];
6271
+ for (let k = 0; k < addCount; k++) out[w++] = added[k];
6272
+ for (let k = index + remove; k < blocks.length; k++) out[w++] = blocks[k];
6273
+ blocks = out;
6274
+ };
6275
+ const flushPending = () => {
6276
+ for (let r = pendingRuns.length - 1; r >= 0; r--) {
6277
+ const start2 = pendingRuns[r];
6278
+ const end = r + 1 < pendingRuns.length ? pendingRuns[r + 1] : pending.length;
6279
+ for (let k = start2; k < end; k++) walk(pending[k][0], pending[k][1]);
6280
+ }
6281
+ pending.length = 0;
6282
+ pendingRuns.length = 0;
6283
+ };
6284
+ let lo = 0;
6285
+ let oldHi = 0;
6286
+ let newHi = 0;
6287
+ const regionFromMutations = (source) => {
6288
+ const ops = mutationsSince(source, lastVersion);
6289
+ if (!ops) return false;
6290
+ const oldLen = blocks.length;
6291
+ lo = 0;
6292
+ oldHi = 0;
6293
+ newHi = 0;
6294
+ let current2 = oldLen;
6295
+ for (let k = 0; k < ops.length; k++) {
6296
+ const op = ops[k];
6297
+ const index = op.index;
6298
+ const removed = op.type === 2 /* SET */ ? 1 : op.removed;
6299
+ const added = op.type === 2 /* SET */ ? 1 : op.added;
6300
+ const end = index + removed;
6301
+ if (k === 0) {
6302
+ lo = index;
6303
+ oldHi = end;
6304
+ newHi = index + added;
6305
+ } else if (end <= newHi) {
6306
+ if (index < lo) lo = index;
6307
+ newHi += added - removed;
6308
+ } else {
6309
+ if (index < lo) lo = index;
6310
+ oldHi = end - newHi + oldHi;
6311
+ newHi = index + added;
5976
6312
  }
5977
- cursor = (_c = block2.nodes[0]) != null ? _c : cursor;
6313
+ if (oldHi < lo) oldHi = lo;
6314
+ if (newHi < lo) newHi = lo;
6315
+ current2 += added - removed;
5978
6316
  }
5979
- blocks = next;
6317
+ if (current2 !== count) return false;
6318
+ if (lo > oldHi || lo > newHi) return false;
6319
+ if (oldHi > oldLen || newHi > count) return false;
6320
+ if (metrics.on) countPath(ops.length === 0 ? "unchanged" : "mutation");
6321
+ if (indexAlias !== void 0 && oldHi - newHi !== 0) {
6322
+ for (let i = newHi; i < count; i++) syncData(blocks[i - newHi + oldHi], i);
6323
+ }
6324
+ return true;
6325
+ };
6326
+ const regionFromScan = () => {
6327
+ const oldLen = blocks.length;
6328
+ const newLen = count;
6329
+ let i = 0;
6330
+ const shared = oldLen < newLen ? oldLen : newLen;
6331
+ while (i < shared) {
6332
+ const block2 = blocks[i];
6333
+ if (!sameKey(block2.key, keyAt(i))) break;
6334
+ syncData(block2, i);
6335
+ i++;
6336
+ }
6337
+ if (metrics.on) {
6338
+ metrics.prefixScanned += i;
6339
+ metrics.itemsVisited += i;
6340
+ }
6341
+ let oe = oldLen - 1;
6342
+ let ne = newLen - 1;
6343
+ while (oe >= i && ne >= i) {
6344
+ const block2 = blocks[oe];
6345
+ if (!sameKey(block2.key, keyAt(ne))) break;
6346
+ syncData(block2, ne);
6347
+ oe--;
6348
+ ne--;
6349
+ }
6350
+ if (metrics.on) {
6351
+ const scanned = oldLen - 1 - oe;
6352
+ metrics.suffixScanned += scanned;
6353
+ metrics.itemsVisited += scanned;
6354
+ countPath("scan");
6355
+ }
6356
+ lo = i;
6357
+ oldHi = oe + 1;
6358
+ newHi = ne + 1;
6359
+ };
6360
+ const reconcileRegion = () => {
6361
+ const toPatch = newHi - lo;
6362
+ if (lo >= oldHi) {
6363
+ if (toPatch > 0) {
6364
+ const created = [];
6365
+ buildRange(lo, newHi, nodeAfter(lo), created);
6366
+ spliceBlocks(lo, 0, created);
6367
+ }
6368
+ return;
6369
+ }
6370
+ if (toPatch === 0) {
6371
+ if (metrics.on) metrics.itemsVisited += oldHi - lo;
6372
+ for (let j = lo; j < oldHi; j++) destroyBlock(blocks[j]);
6373
+ spliceBlocks(lo, oldHi - lo, NO_BLOCKS);
6374
+ return;
6375
+ }
6376
+ if (metrics.on) {
6377
+ metrics.arrayAllocations += 3;
6378
+ metrics.middleReconciled += toPatch;
6379
+ metrics.itemsVisited += toPatch + (oldHi - lo);
6380
+ }
6381
+ const keyToNew = /* @__PURE__ */ new Map();
6382
+ for (let n = lo; n < newHi; n++) {
6383
+ const key = keyAt(n);
6384
+ if (keyExpression && keyToNew.has(key)) warnDuplicateKey(el, key, expression);
6385
+ keyToNew.set(key, n);
6386
+ }
6387
+ const oldOfNew = new Int32Array(toPatch);
6388
+ const reused = new Array(toPatch);
6389
+ let matched = 0;
6390
+ let moved = false;
6391
+ let highestSoFar = 0;
6392
+ for (let o = lo; o < oldHi; o++) {
6393
+ const block2 = blocks[o];
6394
+ if (metrics.on) metrics.keyMapLookups++;
6395
+ const target = matched >= toPatch ? void 0 : keyToNew.get(block2.key);
6396
+ if (target === void 0 || reused[target - lo] !== void 0) {
6397
+ destroyBlock(block2);
6398
+ continue;
6399
+ }
6400
+ oldOfNew[target - lo] = o + 1;
6401
+ reused[target - lo] = block2;
6402
+ if (target >= highestSoFar) highestSoFar = target;
6403
+ else moved = true;
6404
+ syncData(block2, target);
6405
+ matched++;
6406
+ }
6407
+ const stay = moved ? longestIncreasing(oldOfNew) : null;
6408
+ if (metrics.on && moved) {
6409
+ metrics.lisRuns++;
6410
+ metrics.lisElements += toPatch;
6411
+ }
6412
+ let s = stay ? stay.length - 1 : -1;
6413
+ const region = new Array(toPatch);
6414
+ let before = nodeAfter(oldHi);
6415
+ let runEnd = -1;
6416
+ for (let n = toPatch - 1; n >= 0; n--) {
6417
+ const newIndex = lo + n;
6418
+ const block2 = reused[n];
6419
+ if (block2 === void 0) {
6420
+ if (runEnd < 0) runEnd = newIndex + 1;
6421
+ continue;
6422
+ }
6423
+ if (runEnd >= 0) {
6424
+ const created = [];
6425
+ buildRange(newIndex + 1, runEnd, before, created);
6426
+ for (let c = 0; c < created.length; c++) region[n + 1 + c] = created[c];
6427
+ if (created.length) before = created[0].nodes[0];
6428
+ runEnd = -1;
6429
+ }
6430
+ region[n] = block2;
6431
+ if (moved && (s < 0 || n !== stay[s])) moveBlock(block2, before);
6432
+ else if (moved) s--;
6433
+ before = block2.nodes[0];
6434
+ }
6435
+ if (runEnd >= 0) {
6436
+ const created = [];
6437
+ buildRange(lo, runEnd, before, created);
6438
+ for (let c = 0; c < created.length; c++) region[c] = created[c];
6439
+ }
6440
+ spliceBlocks(lo, oldHi - lo, region);
6441
+ };
6442
+ const clearAll = () => {
6443
+ for (const block2 of blocks) destroyBlock(block2);
6444
+ blocks = [];
6445
+ lastSource = null;
6446
+ lastVersion = 0;
6447
+ };
6448
+ addCleanup(anchor, clearAll);
6449
+ effect2(() => {
6450
+ const source = evaluateIn(sourceExpression, scope, "v-for");
6451
+ const raw = toRaw(source);
6452
+ let fromMutations = false;
6453
+ if (Array.isArray(raw)) {
6454
+ track(raw, "length");
6455
+ track(raw, ITERATE_KEY);
6456
+ rows = raw;
6457
+ entries = null;
6458
+ count = raw.length;
6459
+ const version3 = arrayVersion(raw);
6460
+ if (raw === lastSource && keyExpression && !keyIsIndex) {
6461
+ fromMutations = regionFromMutations(raw);
6462
+ }
6463
+ lastSource = raw;
6464
+ lastVersion = version3;
6465
+ } else {
6466
+ entries = normalizeSource(source, itemAlias, indexAlias, thirdAlias);
6467
+ rows = entries;
6468
+ count = entries.length;
6469
+ lastSource = null;
6470
+ lastVersion = 0;
6471
+ if (metrics.on) metrics.arrayAllocations += count + 1;
6472
+ }
6473
+ if (!fromMutations) regionFromScan();
6474
+ reconcileRegion();
6475
+ flushPending();
5980
6476
  });
5981
6477
  },
5982
6478
  { priority: PRIORITY.FOR, terminal: true }
5983
6479
  );
5984
6480
  function normalizeSource(source, itemAlias, indexAlias, thirdAlias) {
5985
6481
  const out = [];
5986
- if (Array.isArray(source)) {
5987
- source.forEach((item, index) => {
5988
- const vars = { [itemAlias]: item };
5989
- if (indexAlias) vars[indexAlias] = index;
5990
- out.push(vars);
5991
- });
5992
- return out;
5993
- }
5994
6482
  if (typeof source === "number") {
5995
6483
  for (let i = 1; i <= source; i++) {
5996
6484
  const vars = { [itemAlias]: i };
@@ -7136,7 +7624,7 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
7136
7624
  Object.defineProperties(rootScope.data, Object.getOwnPropertyDescriptors(values));
7137
7625
  return rootScope.data;
7138
7626
  }
7139
- var version2 = "0.12.5";
7627
+ var version2 = "0.13.0";
7140
7628
  var core = {
7141
7629
  // Utilities first: Voodoo's own names can override.
7142
7630
  ...utils_exports,
@@ -12608,7 +13096,7 @@ form.v-loading [type="submit"],form.v-loading button[disabled]{opacity:.6}
12608
13096
  restoring = false;
12609
13097
  });
12610
13098
  }
12611
- const record = debounce(() => {
13099
+ const record2 = debounce(() => {
12612
13100
  if (restoring) return;
12613
13101
  const current2 = JSON.stringify(serializable(scope.data));
12614
13102
  if (current2 === JSON.stringify(snapshots[position])) return;
@@ -12618,12 +13106,12 @@ form.v-loading [type="submit"],form.v-loading button[disabled]{opacity:.6}
12618
13106
  position = snapshots.length - 1;
12619
13107
  sync();
12620
13108
  }, parseDuration((_a2 = el.getAttribute("v-history-debounce")) != null ? _a2 : void 0, 300));
12621
- const stopWatching = watch(scope.data, () => record(), { deep: true });
13109
+ const stopWatching = watch(scope.data, () => record2(), { deep: true });
12622
13110
  controllers.set(el, controller);
12623
13111
  scope.set("$history", controller);
12624
13112
  cleanup(() => {
12625
13113
  stopWatching();
12626
- record.cancel();
13114
+ record2.cancel();
12627
13115
  controllers.delete(el);
12628
13116
  });
12629
13117
  },