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
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  /**
6
- * Voodoo.js v0.12.5
6
+ * Voodoo.js v0.13.0
7
7
  * JavaScript feels like magic.
8
8
  * (c) 2026 Voodoo.js contributors. MIT License.
9
9
  */
@@ -22,10 +22,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22
22
  // src/reactivity/index.ts
23
23
  var reactivity_exports = {};
24
24
  __export(reactivity_exports, {
25
+ ArrayOp: () => ArrayOp,
25
26
  EffectScope: () => EffectScope,
26
27
  ITERATE_KEY: () => ITERATE_KEY,
27
28
  ReactiveEffect: () => ReactiveEffect,
28
29
  TriggerType: () => TriggerType,
30
+ arrayVersion: () => arrayVersion,
29
31
  computed: () => computed,
30
32
  effect: () => effect,
31
33
  effectScope: () => effectScope,
@@ -38,6 +40,7 @@ __export(reactivity_exports, {
38
40
  isReactive: () => isReactive,
39
41
  isRef: () => isRef,
40
42
  markRaw: () => markRaw,
43
+ mutationsSince: () => mutationsSince,
41
44
  nextTick: () => nextTick,
42
45
  pauseTracking: () => pauseTracking,
43
46
  queueJob: () => queueJob,
@@ -200,7 +203,9 @@ function trigger(target, type, key, _newValue) {
200
203
  if (!isArr) add(depsMap.get(ITERATE_KEY));
201
204
  else if (isIntegerKey(key)) add(depsMap.get("length"));
202
205
  } else if (type === "delete" /* DELETE */) {
203
- if (!isArr) add(depsMap.get(ITERATE_KEY));
206
+ add(depsMap.get(ITERATE_KEY));
207
+ } else if (isArr && isIntegerKey(key)) {
208
+ add(depsMap.get(ITERATE_KEY));
204
209
  } else if (isArr && key === "length") {
205
210
  const newLen = Number(_newValue);
206
211
  depsMap.forEach((dep, k) => {
@@ -213,12 +218,61 @@ function trigger(target, type, key, _newValue) {
213
218
  else queueJob(e);
214
219
  }
215
220
  }
221
+ function triggerArrayRange(target, from) {
222
+ const depsMap = targetMap.get(target);
223
+ if (!depsMap) return;
224
+ const effects = /* @__PURE__ */ new Set();
225
+ const add = (dep) => {
226
+ if (!dep) return;
227
+ for (const e of dep) if (e !== activeEffect) effects.add(e);
228
+ };
229
+ add(depsMap.get("length"));
230
+ add(depsMap.get(ITERATE_KEY));
231
+ if (from >= 0) {
232
+ depsMap.forEach((dep, k) => {
233
+ if (typeof k === "string" && isIntegerKey(k) && Number(k) >= from) add(dep);
234
+ });
235
+ }
236
+ for (const e of effects) {
237
+ if (e.scheduler) e.scheduler();
238
+ else queueJob(e);
239
+ }
240
+ }
241
+ function record(target, type, index, removed, added) {
242
+ let log = mutationLogs.get(target);
243
+ if (!log) mutationLogs.set(target, log = { version: 0, ops: [] });
244
+ log.version++;
245
+ if (type === 3 /* RESET */) {
246
+ log.ops.length = 0;
247
+ return;
248
+ }
249
+ log.ops.push({ type, index, removed, added });
250
+ if (log.ops.length > LOG_LIMIT) log.ops.shift();
251
+ }
252
+ function arrayVersion(target) {
253
+ const log = mutationLogs.get(target);
254
+ return log ? log.version : 0;
255
+ }
256
+ function mutationsSince(target, since) {
257
+ const log = mutationLogs.get(target);
258
+ if (!log) return since === 0 ? NO_MUTATIONS : null;
259
+ if (since > log.version) return null;
260
+ const missing = log.version - since;
261
+ if (missing === 0) return NO_MUTATIONS;
262
+ if (missing > log.ops.length) return null;
263
+ return log.ops.slice(log.ops.length - missing);
264
+ }
216
265
  function isIntegerKey(key) {
217
266
  return typeof key === "string" && key !== "NaN" && key[0] !== "-" && String(parseInt(key, 10)) === key;
218
267
  }
219
268
  function isObject(val) {
220
269
  return val !== null && typeof val === "object";
221
270
  }
271
+ function spliceStart(raw, length) {
272
+ const n = Math.trunc(Number(raw)) || 0;
273
+ if (n < 0) return Math.max(length + n, 0);
274
+ return Math.min(n, length);
275
+ }
222
276
  function canObserve(value) {
223
277
  if (!isObject(value)) return false;
224
278
  if (value[SKIP]) return false;
@@ -228,6 +282,23 @@ function canObserve(value) {
228
282
  if (NON_REACTIVE.has(tag)) return false;
229
283
  return tag === "Object" || tag === "Array" || tag === "Map" || tag === "Set";
230
284
  }
285
+ function recordDirectWrite(target, key, lengthBefore, hadKey, oldValue, value) {
286
+ if (key === "length") {
287
+ const next = target.length;
288
+ if (next < lengthBefore) record(target, 1 /* SPLICE */, next, lengthBefore - next, 0);
289
+ else if (next > lengthBefore) record(target, 3 /* RESET */, 0, 0, 0);
290
+ return;
291
+ }
292
+ if (!isIntegerKey(key)) return;
293
+ const index = Number(key);
294
+ if (hadKey) {
295
+ if (hasChanged(value, oldValue)) record(target, 2 /* SET */, index, 1, 1);
296
+ } else if (index === lengthBefore) {
297
+ record(target, 1 /* SPLICE */, index, 0, 1);
298
+ } else {
299
+ record(target, 3 /* RESET */, 0, 0, 0);
300
+ }
301
+ }
231
302
  function markRaw(value) {
232
303
  Object.defineProperty(value, SKIP, { value: true, enumerable: false, configurable: true });
233
304
  return value;
@@ -350,7 +421,7 @@ function traverse(value, seen = /* @__PURE__ */ new Set()) {
350
421
  else for (const key of Object.keys(value)) traverse(value[key], seen);
351
422
  return value;
352
423
  }
353
- 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;
424
+ 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;
354
425
  var init_reactivity = __esm({
355
426
  "src/reactivity/index.ts"() {
356
427
  resolvedPromise = /* @__PURE__ */ Promise.resolve();
@@ -477,6 +548,15 @@ var init_reactivity = __esm({
477
548
  TriggerType2["CLEAR"] = "clear";
478
549
  return TriggerType2;
479
550
  })(TriggerType || {});
551
+ ArrayOp = /* @__PURE__ */ ((ArrayOp2) => {
552
+ ArrayOp2[ArrayOp2["SPLICE"] = 1] = "SPLICE";
553
+ ArrayOp2[ArrayOp2["SET"] = 2] = "SET";
554
+ ArrayOp2[ArrayOp2["RESET"] = 3] = "RESET";
555
+ return ArrayOp2;
556
+ })(ArrayOp || {});
557
+ LOG_LIMIT = 32;
558
+ mutationLogs = /* @__PURE__ */ new WeakMap();
559
+ NO_MUTATIONS = [];
480
560
  RAW = /* @__PURE__ */ Symbol("voodoo:raw");
481
561
  IS_REACTIVE = /* @__PURE__ */ Symbol("voodoo:isReactive");
482
562
  SKIP = /* @__PURE__ */ Symbol("voodoo:skip");
@@ -494,14 +574,61 @@ var init_reactivity = __esm({
494
574
  return res;
495
575
  };
496
576
  }
497
- for (const key of ["push", "pop", "shift", "unshift", "splice"]) {
577
+ for (const key of ["push", "pop", "shift", "unshift", "splice", "reverse", "sort"]) {
498
578
  inst[key] = function(...args) {
579
+ const raw = toRaw(this);
580
+ const before = raw.length;
581
+ for (let i = 0; i < args.length; i++) args[i] = toRaw(args[i]);
499
582
  pauseTracking();
583
+ let result;
500
584
  try {
501
- return toRaw(this)[key].apply(this, args);
585
+ result = raw[key].apply(raw, args);
502
586
  } finally {
503
587
  resetTracking();
504
588
  }
589
+ const after = raw.length;
590
+ let from = -1;
591
+ if (key === "push") {
592
+ if (args.length) {
593
+ record(raw, 1 /* SPLICE */, before, 0, args.length);
594
+ from = before;
595
+ }
596
+ } else if (key === "unshift") {
597
+ if (args.length) {
598
+ record(raw, 1 /* SPLICE */, 0, 0, args.length);
599
+ from = 0;
600
+ }
601
+ } else if (key === "pop") {
602
+ if (before > 0) {
603
+ record(raw, 1 /* SPLICE */, after, 1, 0);
604
+ from = after;
605
+ }
606
+ } else if (key === "shift") {
607
+ if (before > 0) {
608
+ record(raw, 1 /* SPLICE */, 0, 1, 0);
609
+ from = 0;
610
+ }
611
+ } else if (key === "splice") {
612
+ const removed = result.length;
613
+ const added = args.length > 2 ? args.length - 2 : 0;
614
+ if (removed || added) {
615
+ record(raw, 1 /* SPLICE */, spliceStart(args[0], before), removed, added);
616
+ from = spliceStart(args[0], before);
617
+ }
618
+ } else {
619
+ if (before > 1) {
620
+ record(raw, 3 /* RESET */, 0, before, after);
621
+ from = 0;
622
+ }
623
+ }
624
+ if (from >= 0) triggerArrayRange(raw, from);
625
+ if (key === "pop" || key === "shift") return isObject(result) ? reactive(result) : result;
626
+ if (key === "splice") {
627
+ const out = result;
628
+ for (let i = 0; i < out.length; i++) if (isObject(out[i])) out[i] = reactive(out[i]);
629
+ return out;
630
+ }
631
+ return key === "reverse" || key === "sort" ? this : result;
505
632
  };
506
633
  }
507
634
  return inst;
@@ -543,8 +670,11 @@ var init_reactivity = __esm({
543
670
  return true;
544
671
  }
545
672
  const hadKey = Array.isArray(target) && isIntegerKey(key) ? Number(key) < target.length : Object.prototype.hasOwnProperty.call(target, key);
673
+ const isArr = Array.isArray(target);
674
+ const arrayLength = isArr ? target.length : 0;
546
675
  const result = Reflect.set(target, key, value, receiver);
547
676
  if (target === toRaw(receiver)) {
677
+ if (isArr) recordDirectWrite(target, key, arrayLength, hadKey, oldValue, value);
548
678
  if (!hadKey) trigger(target, "add" /* ADD */, key, value);
549
679
  else if (hasChanged(value, oldValue)) trigger(target, "set" /* SET */, key, value);
550
680
  }
@@ -553,7 +683,10 @@ var init_reactivity = __esm({
553
683
  deleteProperty(target, key) {
554
684
  const hadKey = Object.prototype.hasOwnProperty.call(target, key);
555
685
  const result = Reflect.deleteProperty(target, key);
556
- if (result && hadKey) trigger(target, "delete" /* DELETE */, key);
686
+ if (result && hadKey) {
687
+ if (Array.isArray(target)) record(target, 3 /* RESET */, 0, 0, 0);
688
+ trigger(target, "delete" /* DELETE */, key);
689
+ }
557
690
  return result;
558
691
  },
559
692
  has(target, key) {
@@ -5635,6 +5768,8 @@ function viewTransition(update) {
5635
5768
  // src/directives/core.ts
5636
5769
  init_reactivity();
5637
5770
  init_registry();
5771
+
5772
+ // src/directives/core.ts
5638
5773
  function setValue(expression, scope, value) {
5639
5774
  try {
5640
5775
  const target = parse(expression);
@@ -5779,7 +5914,7 @@ defineDirective(
5779
5914
  },
5780
5915
  { priority: PRIORITY.IF, terminal: true }
5781
5916
  );
5782
- function renderTemplate(source, anchor, scope, batch) {
5917
+ function renderTemplate(source, anchor, scope) {
5783
5918
  const parent = anchor.parentNode;
5784
5919
  if (!parent) return [];
5785
5920
  const nodes = [];
@@ -5798,19 +5933,61 @@ function renderTemplate(source, anchor, scope, batch) {
5798
5933
  const clone2 = source.cloneNode(true);
5799
5934
  nodes.push(clone2);
5800
5935
  markNodeScope(clone2, scope);
5801
- if (batch) {
5802
- batch.fragment.appendChild(clone2);
5803
- batch.pending.push([clone2, scope]);
5804
- } else {
5805
- parent.insertBefore(clone2, anchor);
5806
- walk(clone2, scope);
5807
- }
5936
+ parent.insertBefore(clone2, anchor);
5937
+ walk(clone2, scope);
5808
5938
  }
5809
5939
  return nodes;
5810
5940
  }
5811
5941
  defineDirective("else-if", () => void 0, { priority: PRIORITY.IF, terminal: true });
5812
5942
  defineDirective("else", () => void 0, { priority: PRIORITY.IF, terminal: true });
5813
5943
  var FOR_PATTERN = /^\s*\(?\s*([^)]*?)\s*\)?\s+(?:in|of)\s+(.+?)\s*$/;
5944
+ var KEY_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
5945
+ var NO_BLOCKS = [];
5946
+ function sameStored(stored, incoming) {
5947
+ if (stored === incoming) return true;
5948
+ return incoming !== null && typeof incoming === "object" && stored === toRaw(incoming);
5949
+ }
5950
+ function sameKey(a, b) {
5951
+ return a === b || a !== a && b !== b;
5952
+ }
5953
+ function longestIncreasing(arr) {
5954
+ const length = arr.length;
5955
+ const previous = new Int32Array(length);
5956
+ const tails = [];
5957
+ for (let i = 0; i < length; i++) {
5958
+ const value = arr[i];
5959
+ if (value === 0) continue;
5960
+ if (tails.length === 0) {
5961
+ tails.push(i);
5962
+ continue;
5963
+ }
5964
+ const last = tails[tails.length - 1];
5965
+ if (arr[last] < value) {
5966
+ previous[i] = last;
5967
+ tails.push(i);
5968
+ continue;
5969
+ }
5970
+ let low = 0;
5971
+ let high = tails.length - 1;
5972
+ while (low < high) {
5973
+ const mid = low + high >> 1;
5974
+ if (arr[tails[mid]] < value) low = mid + 1;
5975
+ else high = mid;
5976
+ }
5977
+ if (value < arr[tails[low]]) {
5978
+ if (low > 0) previous[i] = tails[low - 1];
5979
+ tails[low] = i;
5980
+ }
5981
+ }
5982
+ let cursor = tails.length;
5983
+ const out = new Int32Array(cursor);
5984
+ let node = tails[cursor - 1];
5985
+ while (cursor-- > 0) {
5986
+ out[cursor] = node;
5987
+ node = previous[node];
5988
+ }
5989
+ return out;
5990
+ }
5814
5991
  defineDirective(
5815
5992
  "for",
5816
5993
  ({ el, scope, expression, effect: effect2 }) => {
@@ -5835,77 +6012,322 @@ defineDirective(
5835
6012
  template.removeAttribute(`${p2}bind:key`);
5836
6013
  template.removeAttribute(`${p2}key`);
5837
6014
  removeQuietly(el);
6015
+ const isTemplateRow = template.tagName === "TEMPLATE";
6016
+ let keyIsItem = false;
6017
+ let keyIsIndex = false;
6018
+ let keyProp = null;
6019
+ let keyPath = null;
6020
+ if (keyExpression && KEY_PATH.test(keyExpression)) {
6021
+ const parts = keyExpression.split(".");
6022
+ if (parts[0] === itemAlias) {
6023
+ if (parts.length === 1) keyIsItem = true;
6024
+ else if (parts.length === 2) keyProp = parts[1];
6025
+ else keyPath = parts.slice(1);
6026
+ } else if (indexAlias && parts.length === 1 && parts[0] === indexAlias) {
6027
+ keyIsIndex = true;
6028
+ }
6029
+ }
5838
6030
  let blocks = [];
5839
- const clearAll = () => {
5840
- for (const block2 of blocks) {
5841
- for (const node of block2.nodes) {
5842
- destroy(node);
5843
- node.remove();
6031
+ let rows = [];
6032
+ let entries = null;
6033
+ let count = 0;
6034
+ let keyScope = null;
6035
+ let lastSource = null;
6036
+ let lastVersion = 0;
6037
+ const pending = [];
6038
+ const pendingRuns = [];
6039
+ const varsAt = (i) => {
6040
+ if (entries) return entries[i];
6041
+ const vars = { [itemAlias]: rows[i] };
6042
+ if (indexAlias) vars[indexAlias] = i;
6043
+ return vars;
6044
+ };
6045
+ const keyAt = (i) => {
6046
+ if (keyIsIndex) return i;
6047
+ if (!keyExpression) {
6048
+ return i;
6049
+ }
6050
+ const item = entries ? entries[i][itemAlias] : rows[i];
6051
+ if (keyIsItem) return item;
6052
+ if (keyProp !== null) return item == null ? void 0 : item[keyProp];
6053
+ if (keyPath !== null) {
6054
+ let value = item;
6055
+ for (let d = 0; d < keyPath.length; d++) {
6056
+ if (value == null) return void 0;
6057
+ value = value[keyPath[d]];
5844
6058
  }
6059
+ return value;
5845
6060
  }
5846
- blocks = [];
6061
+ if (!keyScope) keyScope = scope.child({});
6062
+ keyScope.data = varsAt(i);
6063
+ return evaluateIn(keyExpression, keyScope, ":key");
5847
6064
  };
5848
- addCleanup(anchor, clearAll);
5849
- effect2(() => {
5850
- const source = evaluateIn(sourceExpression, scope, "v-for");
5851
- const entries = normalizeSource(source, itemAlias, indexAlias, thirdAlias);
5852
- const previous = /* @__PURE__ */ new Map();
5853
- for (const block2 of blocks) previous.set(block2.key, block2);
5854
- const next = [];
5855
- const used = /* @__PURE__ */ new Set();
5856
- const batch = {
5857
- fragment: document.createDocumentFragment(),
5858
- pending: []
5859
- };
5860
- entries.forEach((vars, index) => {
5861
- const key = keyExpression ? evaluateIn(keyExpression, scope.child(vars), ":key") : `__index_${index}`;
5862
- if (keyExpression && used.has(key)) warnDuplicateKey(el, key, expression);
5863
- const existing = previous.get(key);
5864
- if (existing && !used.has(key)) {
5865
- used.add(key);
5866
- for (const [name, value] of Object.entries(vars)) existing.data[name] = value;
5867
- next.push(existing);
5868
- return;
6065
+ const syncData = (block2, i) => {
6066
+ const raw = toRaw(block2.data);
6067
+ if (entries) {
6068
+ const vars = entries[i];
6069
+ for (const name in vars) {
6070
+ if (!sameStored(raw[name], vars[name])) {
6071
+ block2.data[name] = vars[name];
6072
+ }
5869
6073
  }
5870
- const childScope = scope.reactiveChild(vars);
5871
- const nodes = renderTemplate(template, anchor, childScope, batch);
5872
- used.add(key);
5873
- next.push({ key, scope: childScope, nodes, data: childScope.data });
5874
- });
5875
- if (batch.fragment.firstChild) anchor.parentNode?.insertBefore(batch.fragment, anchor);
5876
- for (const [node, rowScope] of batch.pending) walk(node, rowScope);
5877
- const reused = new Set(next);
5878
- for (const block2 of blocks) {
5879
- if (used.has(block2.key) && reused.has(block2)) continue;
5880
- for (const node of block2.nodes) {
5881
- destroy(node);
5882
- node.remove();
6074
+ return;
6075
+ }
6076
+ const item = rows[i];
6077
+ if (!sameStored(raw[itemAlias], item)) {
6078
+ block2.data[itemAlias] = item;
6079
+ }
6080
+ if (indexAlias !== void 0 && raw[indexAlias] !== i) {
6081
+ block2.data[indexAlias] = i;
6082
+ }
6083
+ };
6084
+ const buildRange = (from, to, before, out) => {
6085
+ if (from >= to) return;
6086
+ const parent = anchor.parentNode;
6087
+ if (!parent) return;
6088
+ pendingRuns.push(pending.length);
6089
+ if (isTemplateRow) {
6090
+ for (let i = from; i < to; i++) {
6091
+ const childScope = scope.reactiveChild(varsAt(i));
6092
+ const nodes = renderTemplate(template, before, childScope);
6093
+ out.push({ key: keyAt(i), scope: childScope, nodes, data: childScope.data });
5883
6094
  }
6095
+ return;
6096
+ }
6097
+ const fragment = document.createDocumentFragment();
6098
+ for (let i = from; i < to; i++) {
6099
+ const childScope = scope.reactiveChild(varsAt(i));
6100
+ const clone2 = template.cloneNode(true);
6101
+ markNodeScope(clone2, childScope);
6102
+ fragment.appendChild(clone2);
6103
+ pending.push([clone2, childScope]);
6104
+ out.push({ key: keyAt(i), scope: childScope, nodes: [clone2], data: childScope.data });
5884
6105
  }
5885
- let cursor = anchor;
5886
- for (let i = next.length - 1; i >= 0; i--) {
5887
- const block2 = next[i];
5888
- const last = block2.nodes[block2.nodes.length - 1];
5889
- if (last && last.nextSibling !== cursor) {
5890
- for (const node of block2.nodes) anchor.parentNode?.insertBefore(node, cursor);
6106
+ parent.insertBefore(fragment, before);
6107
+ };
6108
+ const destroyBlock = (block2) => {
6109
+ const nodes = block2.nodes;
6110
+ for (let j = 0; j < nodes.length; j++) {
6111
+ destroy(nodes[j]);
6112
+ nodes[j].remove();
6113
+ }
6114
+ };
6115
+ const moveBlock = (block2, before) => {
6116
+ const parent = anchor.parentNode;
6117
+ if (!parent) return;
6118
+ const nodes = block2.nodes;
6119
+ if (nodes[nodes.length - 1].nextSibling === before) return;
6120
+ for (let j = 0; j < nodes.length; j++) {
6121
+ parent.insertBefore(nodes[j], before);
6122
+ }
6123
+ };
6124
+ const nodeAfter = (oldIndex) => oldIndex < blocks.length ? blocks[oldIndex].nodes[0] : anchor;
6125
+ const spliceBlocks = (index, remove, added) => {
6126
+ const addCount = added.length;
6127
+ if (remove === 0 && addCount === 0) return;
6128
+ if (blocks.length === 0) {
6129
+ blocks = added;
6130
+ return;
6131
+ }
6132
+ if (addCount === 0) {
6133
+ blocks.splice(index, remove);
6134
+ return;
6135
+ }
6136
+ if (addCount <= 1024) {
6137
+ blocks.splice(index, remove, ...added);
6138
+ return;
6139
+ }
6140
+ const out = new Array(blocks.length - remove + addCount);
6141
+ let w = 0;
6142
+ for (let k = 0; k < index; k++) out[w++] = blocks[k];
6143
+ for (let k = 0; k < addCount; k++) out[w++] = added[k];
6144
+ for (let k = index + remove; k < blocks.length; k++) out[w++] = blocks[k];
6145
+ blocks = out;
6146
+ };
6147
+ const flushPending = () => {
6148
+ for (let r = pendingRuns.length - 1; r >= 0; r--) {
6149
+ const start2 = pendingRuns[r];
6150
+ const end = r + 1 < pendingRuns.length ? pendingRuns[r + 1] : pending.length;
6151
+ for (let k = start2; k < end; k++) walk(pending[k][0], pending[k][1]);
6152
+ }
6153
+ pending.length = 0;
6154
+ pendingRuns.length = 0;
6155
+ };
6156
+ let lo = 0;
6157
+ let oldHi = 0;
6158
+ let newHi = 0;
6159
+ const regionFromMutations = (source) => {
6160
+ const ops = mutationsSince(source, lastVersion);
6161
+ if (!ops) return false;
6162
+ const oldLen = blocks.length;
6163
+ lo = 0;
6164
+ oldHi = 0;
6165
+ newHi = 0;
6166
+ let current2 = oldLen;
6167
+ for (let k = 0; k < ops.length; k++) {
6168
+ const op = ops[k];
6169
+ const index = op.index;
6170
+ const removed = op.type === 2 /* SET */ ? 1 : op.removed;
6171
+ const added = op.type === 2 /* SET */ ? 1 : op.added;
6172
+ const end = index + removed;
6173
+ if (k === 0) {
6174
+ lo = index;
6175
+ oldHi = end;
6176
+ newHi = index + added;
6177
+ } else if (end <= newHi) {
6178
+ if (index < lo) lo = index;
6179
+ newHi += added - removed;
6180
+ } else {
6181
+ if (index < lo) lo = index;
6182
+ oldHi = end - newHi + oldHi;
6183
+ newHi = index + added;
5891
6184
  }
5892
- cursor = block2.nodes[0] ?? cursor;
6185
+ if (oldHi < lo) oldHi = lo;
6186
+ if (newHi < lo) newHi = lo;
6187
+ current2 += added - removed;
6188
+ }
6189
+ if (current2 !== count) return false;
6190
+ if (lo > oldHi || lo > newHi) return false;
6191
+ if (oldHi > oldLen || newHi > count) return false;
6192
+ if (indexAlias !== void 0 && oldHi - newHi !== 0) {
6193
+ for (let i = newHi; i < count; i++) syncData(blocks[i - newHi + oldHi], i);
5893
6194
  }
5894
- blocks = next;
6195
+ return true;
6196
+ };
6197
+ const regionFromScan = () => {
6198
+ const oldLen = blocks.length;
6199
+ const newLen = count;
6200
+ let i = 0;
6201
+ const shared = oldLen < newLen ? oldLen : newLen;
6202
+ while (i < shared) {
6203
+ const block2 = blocks[i];
6204
+ if (!sameKey(block2.key, keyAt(i))) break;
6205
+ syncData(block2, i);
6206
+ i++;
6207
+ }
6208
+ let oe = oldLen - 1;
6209
+ let ne = newLen - 1;
6210
+ while (oe >= i && ne >= i) {
6211
+ const block2 = blocks[oe];
6212
+ if (!sameKey(block2.key, keyAt(ne))) break;
6213
+ syncData(block2, ne);
6214
+ oe--;
6215
+ ne--;
6216
+ }
6217
+ lo = i;
6218
+ oldHi = oe + 1;
6219
+ newHi = ne + 1;
6220
+ };
6221
+ const reconcileRegion = () => {
6222
+ const toPatch = newHi - lo;
6223
+ if (lo >= oldHi) {
6224
+ if (toPatch > 0) {
6225
+ const created = [];
6226
+ buildRange(lo, newHi, nodeAfter(lo), created);
6227
+ spliceBlocks(lo, 0, created);
6228
+ }
6229
+ return;
6230
+ }
6231
+ if (toPatch === 0) {
6232
+ for (let j = lo; j < oldHi; j++) destroyBlock(blocks[j]);
6233
+ spliceBlocks(lo, oldHi - lo, NO_BLOCKS);
6234
+ return;
6235
+ }
6236
+ const keyToNew = /* @__PURE__ */ new Map();
6237
+ for (let n = lo; n < newHi; n++) {
6238
+ const key = keyAt(n);
6239
+ if (keyExpression && keyToNew.has(key)) warnDuplicateKey(el, key, expression);
6240
+ keyToNew.set(key, n);
6241
+ }
6242
+ const oldOfNew = new Int32Array(toPatch);
6243
+ const reused = new Array(toPatch);
6244
+ let matched = 0;
6245
+ let moved = false;
6246
+ let highestSoFar = 0;
6247
+ for (let o = lo; o < oldHi; o++) {
6248
+ const block2 = blocks[o];
6249
+ const target = matched >= toPatch ? void 0 : keyToNew.get(block2.key);
6250
+ if (target === void 0 || reused[target - lo] !== void 0) {
6251
+ destroyBlock(block2);
6252
+ continue;
6253
+ }
6254
+ oldOfNew[target - lo] = o + 1;
6255
+ reused[target - lo] = block2;
6256
+ if (target >= highestSoFar) highestSoFar = target;
6257
+ else moved = true;
6258
+ syncData(block2, target);
6259
+ matched++;
6260
+ }
6261
+ const stay = moved ? longestIncreasing(oldOfNew) : null;
6262
+ let s = stay ? stay.length - 1 : -1;
6263
+ const region = new Array(toPatch);
6264
+ let before = nodeAfter(oldHi);
6265
+ let runEnd = -1;
6266
+ for (let n = toPatch - 1; n >= 0; n--) {
6267
+ const newIndex = lo + n;
6268
+ const block2 = reused[n];
6269
+ if (block2 === void 0) {
6270
+ if (runEnd < 0) runEnd = newIndex + 1;
6271
+ continue;
6272
+ }
6273
+ if (runEnd >= 0) {
6274
+ const created = [];
6275
+ buildRange(newIndex + 1, runEnd, before, created);
6276
+ for (let c = 0; c < created.length; c++) region[n + 1 + c] = created[c];
6277
+ if (created.length) before = created[0].nodes[0];
6278
+ runEnd = -1;
6279
+ }
6280
+ region[n] = block2;
6281
+ if (moved && (s < 0 || n !== stay[s])) moveBlock(block2, before);
6282
+ else if (moved) s--;
6283
+ before = block2.nodes[0];
6284
+ }
6285
+ if (runEnd >= 0) {
6286
+ const created = [];
6287
+ buildRange(lo, runEnd, before, created);
6288
+ for (let c = 0; c < created.length; c++) region[c] = created[c];
6289
+ }
6290
+ spliceBlocks(lo, oldHi - lo, region);
6291
+ };
6292
+ const clearAll = () => {
6293
+ for (const block2 of blocks) destroyBlock(block2);
6294
+ blocks = [];
6295
+ lastSource = null;
6296
+ lastVersion = 0;
6297
+ };
6298
+ addCleanup(anchor, clearAll);
6299
+ effect2(() => {
6300
+ const source = evaluateIn(sourceExpression, scope, "v-for");
6301
+ const raw = toRaw(source);
6302
+ let fromMutations = false;
6303
+ if (Array.isArray(raw)) {
6304
+ track(raw, "length");
6305
+ track(raw, ITERATE_KEY);
6306
+ rows = raw;
6307
+ entries = null;
6308
+ count = raw.length;
6309
+ const version3 = arrayVersion(raw);
6310
+ if (raw === lastSource && keyExpression && !keyIsIndex) {
6311
+ fromMutations = regionFromMutations(raw);
6312
+ }
6313
+ lastSource = raw;
6314
+ lastVersion = version3;
6315
+ } else {
6316
+ entries = normalizeSource(source, itemAlias, indexAlias, thirdAlias);
6317
+ rows = entries;
6318
+ count = entries.length;
6319
+ lastSource = null;
6320
+ lastVersion = 0;
6321
+ }
6322
+ if (!fromMutations) regionFromScan();
6323
+ reconcileRegion();
6324
+ flushPending();
5895
6325
  });
5896
6326
  },
5897
6327
  { priority: PRIORITY.FOR, terminal: true }
5898
6328
  );
5899
6329
  function normalizeSource(source, itemAlias, indexAlias, thirdAlias) {
5900
6330
  const out = [];
5901
- if (Array.isArray(source)) {
5902
- source.forEach((item, index) => {
5903
- const vars = { [itemAlias]: item };
5904
- if (indexAlias) vars[indexAlias] = index;
5905
- out.push(vars);
5906
- });
5907
- return out;
5908
- }
5909
6331
  if (typeof source === "number") {
5910
6332
  for (let i = 1; i <= source; i++) {
5911
6333
  const vars = { [itemAlias]: i };
@@ -7028,7 +7450,7 @@ function data(values) {
7028
7450
  Object.defineProperties(rootScope.data, Object.getOwnPropertyDescriptors(values));
7029
7451
  return rootScope.data;
7030
7452
  }
7031
- var version2 = "0.12.5";
7453
+ var version2 = "0.13.0";
7032
7454
  var core = {
7033
7455
  // Utilities first: Voodoo's own names can override.
7034
7456
  ...utils_exports,
@@ -12418,7 +12840,7 @@ defineDirective(
12418
12840
  restoring = false;
12419
12841
  });
12420
12842
  }
12421
- const record = debounce(() => {
12843
+ const record2 = debounce(() => {
12422
12844
  if (restoring) return;
12423
12845
  const current2 = JSON.stringify(serializable(scope.data));
12424
12846
  if (current2 === JSON.stringify(snapshots[position])) return;
@@ -12428,12 +12850,12 @@ defineDirective(
12428
12850
  position = snapshots.length - 1;
12429
12851
  sync();
12430
12852
  }, parseDuration(el.getAttribute("v-history-debounce") ?? void 0, 300));
12431
- const stopWatching = watch(scope.data, () => record(), { deep: true });
12853
+ const stopWatching = watch(scope.data, () => record2(), { deep: true });
12432
12854
  controllers.set(el, controller);
12433
12855
  scope.set("$history", controller);
12434
12856
  cleanup(() => {
12435
12857
  stopWatching();
12436
- record.cancel();
12858
+ record2.cancel();
12437
12859
  controllers.delete(el);
12438
12860
  });
12439
12861
  },