voodoojs 0.12.4 → 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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-XGZ7SXD3.js → chunk-2LGAXVD7.js} +4 -4
  3. package/dist/{chunk-XIMSOXWF.js → chunk-4IJE5BWY.js} +5 -5
  4. package/dist/{chunk-FAWOJTRM.js → chunk-FMDHZ5GI.js} +139 -9
  5. package/dist/{chunk-OHISQWSW.js → chunk-GE4JWATC.js} +5 -5
  6. package/dist/{chunk-2GSZT3CX.js → chunk-H2NGDLMD.js} +363 -76
  7. package/dist/{chunk-AR6WDY7K.js → chunk-IBIZ6OUI.js} +4 -4
  8. package/dist/{chunk-7XRFOONN.js → chunk-IJQ2PFXU.js} +3 -3
  9. package/dist/{chunk-ELIX2DRQ.js → chunk-JBUNTP7F.js} +19 -7
  10. package/dist/{chunk-NKQGUWVF.js → chunk-MV73OSCS.js} +4 -4
  11. package/dist/{chunk-3MPIJH5X.js → chunk-OIH4BR2H.js} +6 -6
  12. package/dist/{chunk-FNTYILLW.js → chunk-TEVCUTTC.js} +3 -3
  13. package/dist/essential.cjs +508 -74
  14. package/dist/essential.d.cts +1 -1
  15. package/dist/essential.d.ts +1 -1
  16. package/dist/essential.js +10 -10
  17. package/dist/gpu.cjs +7 -1
  18. package/dist/gpu.js +10 -10
  19. package/dist/http.cjs +1 -1
  20. package/dist/http.js +5 -5
  21. package/dist/index.cjs +556 -122
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +20 -20
  25. package/dist/reactivity.cjs +138 -5
  26. package/dist/reactivity.d.cts +32 -1
  27. package/dist/reactivity.d.ts +32 -1
  28. package/dist/reactivity.js +2 -2
  29. package/dist/socket.cjs +115 -5
  30. package/dist/socket.d.cts +1 -1
  31. package/dist/socket.d.ts +1 -1
  32. package/dist/socket.js +9 -9
  33. package/dist/style-E22XVZ33.js +5 -0
  34. package/dist/utils.cjs +1 -1
  35. package/dist/utils.js +2 -2
  36. package/dist/voodoo.core.js +572 -72
  37. package/dist/voodoo.core.min.js +17 -17
  38. package/dist/voodoo.full.js +621 -121
  39. package/dist/voodoo.full.min.js +62 -62
  40. package/dist/voodoo.js +575 -75
  41. package/dist/voodoo.min.js +26 -26
  42. package/package.json +1 -1
  43. package/dist/style-DA6RFLKO.js +0 -5
  44. package/dist/{query-XooOh4vB.d.cts → query-D_BGQw8m.d.cts} +28 -28
  45. package/dist/{query-DzHfm8Kg.d.ts → query-Dl6Urlwd.d.ts} +28 -28
package/dist/voodoo.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Voodoo.js v0.12.4
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) {
@@ -2510,8 +2643,15 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
2510
2643
  list.push(scope);
2511
2644
  }
2512
2645
  var ignoredRemovals = /* @__PURE__ */ new WeakSet();
2646
+ var detachedTemplates = /* @__PURE__ */ new WeakMap();
2513
2647
  function removeQuietly(node) {
2514
2648
  ignoredRemovals.add(node);
2649
+ const parent = node.parentNode;
2650
+ if (parent) {
2651
+ let kept = detachedTemplates.get(parent);
2652
+ if (!kept) detachedTemplates.set(parent, kept = /* @__PURE__ */ new Set());
2653
+ kept.add(node);
2654
+ }
2515
2655
  node.remove();
2516
2656
  }
2517
2657
  function addCleanup(node, fn) {
@@ -2527,6 +2667,11 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
2527
2667
  }
2528
2668
  for (let i = children.length - 1; i >= 0; i--) destroy(children[i]);
2529
2669
  }
2670
+ const detached = detachedTemplates.get(node);
2671
+ if (detached) {
2672
+ detachedTemplates.delete(node);
2673
+ for (const template of detached) destroy(template);
2674
+ }
2530
2675
  const list = nodeCleanups.get(node);
2531
2676
  if (list) {
2532
2677
  nodeCleanups.delete(node);
@@ -5705,6 +5850,35 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5705
5850
  // src/directives/core.ts
5706
5851
  init_reactivity();
5707
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
5708
5882
  function setValue(expression, scope, value) {
5709
5883
  try {
5710
5884
  const target = parse(expression);
@@ -5850,7 +6024,7 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5850
6024
  },
5851
6025
  { priority: PRIORITY.IF, terminal: true }
5852
6026
  );
5853
- function renderTemplate(source, anchor, scope, batch) {
6027
+ function renderTemplate(source, anchor, scope) {
5854
6028
  const parent = anchor.parentNode;
5855
6029
  if (!parent) return [];
5856
6030
  const nodes = [];
@@ -5867,21 +6041,64 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5867
6041
  }
5868
6042
  } else {
5869
6043
  const clone2 = source.cloneNode(true);
6044
+ if (metrics.on) metrics.domCreates++;
5870
6045
  nodes.push(clone2);
5871
6046
  markNodeScope(clone2, scope);
5872
- if (batch) {
5873
- batch.fragment.appendChild(clone2);
5874
- batch.pending.push([clone2, scope]);
5875
- } else {
5876
- parent.insertBefore(clone2, anchor);
5877
- walk(clone2, scope);
5878
- }
6047
+ parent.insertBefore(clone2, anchor);
6048
+ walk(clone2, scope);
5879
6049
  }
5880
6050
  return nodes;
5881
6051
  }
5882
6052
  defineDirective("else-if", () => void 0, { priority: PRIORITY.IF, terminal: true });
5883
6053
  defineDirective("else", () => void 0, { priority: PRIORITY.IF, terminal: true });
5884
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
+ }
5885
6102
  defineDirective(
5886
6103
  "for",
5887
6104
  ({ el, scope, expression, effect: effect2 }) => {
@@ -5907,78 +6124,361 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
5907
6124
  template.removeAttribute(`${p2}bind:key`);
5908
6125
  template.removeAttribute(`${p2}key`);
5909
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
+ }
5910
6142
  let blocks = [];
5911
- const clearAll = () => {
5912
- for (const block2 of blocks) {
5913
- for (const node of block2.nodes) {
5914
- destroy(node);
5915
- 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]];
5916
6171
  }
6172
+ return value;
5917
6173
  }
5918
- blocks = [];
6174
+ if (!keyScope) keyScope = scope.child({});
6175
+ keyScope.data = varsAt(i);
6176
+ return evaluateIn(keyExpression, keyScope, ":key");
5919
6177
  };
5920
- addCleanup(anchor, clearAll);
5921
- effect2(() => {
5922
- var _a3, _b, _c;
5923
- const source = evaluateIn(sourceExpression, scope, "v-for");
5924
- const entries = normalizeSource(source, itemAlias, indexAlias, thirdAlias);
5925
- const previous = /* @__PURE__ */ new Map();
5926
- for (const block2 of blocks) previous.set(block2.key, block2);
5927
- const next = [];
5928
- const used = /* @__PURE__ */ new Set();
5929
- const batch = {
5930
- fragment: document.createDocumentFragment(),
5931
- pending: []
5932
- };
5933
- entries.forEach((vars, index) => {
5934
- const key = keyExpression ? evaluateIn(keyExpression, scope.child(vars), ":key") : `__index_${index}`;
5935
- if (keyExpression && used.has(key)) warnDuplicateKey(el, key, expression);
5936
- const existing = previous.get(key);
5937
- if (existing && !used.has(key)) {
5938
- used.add(key);
5939
- for (const [name, value] of Object.entries(vars)) existing.data[name] = value;
5940
- next.push(existing);
5941
- 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
+ }
5942
6187
  }
5943
- const childScope = scope.reactiveChild(vars);
5944
- const nodes = renderTemplate(template, anchor, childScope, batch);
5945
- used.add(key);
5946
- next.push({ key, scope: childScope, nodes, data: childScope.data });
5947
- });
5948
- if (batch.fragment.firstChild) (_a3 = anchor.parentNode) == null ? void 0 : _a3.insertBefore(batch.fragment, anchor);
5949
- for (const [node, rowScope] of batch.pending) walk(node, rowScope);
5950
- const reused = new Set(next);
5951
- for (const block2 of blocks) {
5952
- if (used.has(block2.key) && reused.has(block2)) continue;
5953
- for (const node of block2.nodes) {
5954
- destroy(node);
5955
- 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 });
6214
+ }
6215
+ return;
6216
+ }
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;
6312
+ }
6313
+ if (oldHi < lo) oldHi = lo;
6314
+ if (newHi < lo) newHi = lo;
6315
+ current2 += added - removed;
6316
+ }
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);
5956
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;
5957
6375
  }
5958
- let cursor = anchor;
5959
- for (let i = next.length - 1; i >= 0; i--) {
5960
- const block2 = next[i];
5961
- const last = block2.nodes[block2.nodes.length - 1];
5962
- if (last && last.nextSibling !== cursor) {
5963
- for (const node of block2.nodes) (_b = anchor.parentNode) == null ? void 0 : _b.insertBefore(node, cursor);
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;
5964
6429
  }
5965
- cursor = (_c = block2.nodes[0]) != null ? _c : cursor;
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];
5966
6434
  }
5967
- blocks = next;
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();
5968
6476
  });
5969
6477
  },
5970
6478
  { priority: PRIORITY.FOR, terminal: true }
5971
6479
  );
5972
6480
  function normalizeSource(source, itemAlias, indexAlias, thirdAlias) {
5973
6481
  const out = [];
5974
- if (Array.isArray(source)) {
5975
- source.forEach((item, index) => {
5976
- const vars = { [itemAlias]: item };
5977
- if (indexAlias) vars[indexAlias] = index;
5978
- out.push(vars);
5979
- });
5980
- return out;
5981
- }
5982
6482
  if (typeof source === "number") {
5983
6483
  for (let i = 1; i <= source; i++) {
5984
6484
  const vars = { [itemAlias]: i };
@@ -7124,7 +7624,7 @@ Suggestion: attribute expressions accept a single value. If the logic spans more
7124
7624
  Object.defineProperties(rootScope.data, Object.getOwnPropertyDescriptors(values));
7125
7625
  return rootScope.data;
7126
7626
  }
7127
- var version2 = "0.12.4";
7627
+ var version2 = "0.13.0";
7128
7628
  var core = {
7129
7629
  // Utilities first: Voodoo's own names can override.
7130
7630
  ...utils_exports,
@@ -12596,7 +13096,7 @@ form.v-loading [type="submit"],form.v-loading button[disabled]{opacity:.6}
12596
13096
  restoring = false;
12597
13097
  });
12598
13098
  }
12599
- const record = debounce(() => {
13099
+ const record2 = debounce(() => {
12600
13100
  if (restoring) return;
12601
13101
  const current2 = JSON.stringify(serializable(scope.data));
12602
13102
  if (current2 === JSON.stringify(snapshots[position])) return;
@@ -12606,12 +13106,12 @@ form.v-loading [type="submit"],form.v-loading button[disabled]{opacity:.6}
12606
13106
  position = snapshots.length - 1;
12607
13107
  sync();
12608
13108
  }, parseDuration((_a2 = el.getAttribute("v-history-debounce")) != null ? _a2 : void 0, 300));
12609
- const stopWatching = watch(scope.data, () => record(), { deep: true });
13109
+ const stopWatching = watch(scope.data, () => record2(), { deep: true });
12610
13110
  controllers.set(el, controller);
12611
13111
  scope.set("$history", controller);
12612
13112
  cleanup(() => {
12613
13113
  stopWatching();
12614
- record.cancel();
13114
+ record2.cancel();
12615
13115
  controllers.delete(el);
12616
13116
  });
12617
13117
  },