@reactive-vscode/vueuse 0.2.9 → 0.2.13

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.
package/dist/index.cjs CHANGED
@@ -46,6 +46,9 @@ function createEventHook() {
46
46
  const off = (fn) => {
47
47
  fns.delete(fn);
48
48
  };
49
+ const clear = () => {
50
+ fns.clear();
51
+ };
49
52
  const on = (fn) => {
50
53
  fns.add(fn);
51
54
  const offFn = () => off(fn);
@@ -60,7 +63,8 @@ function createEventHook() {
60
63
  return {
61
64
  on,
62
65
  off,
63
- trigger
66
+ trigger,
67
+ clear
64
68
  };
65
69
  }
66
70
  function createGlobalState(stateFactory) {
@@ -145,12 +149,8 @@ function makeDestructurable(obj, arr) {
145
149
  return Object.assign([...arr], obj);
146
150
  }
147
151
  }
148
- function toValue(r) {
149
- return typeof r === "function" ? r() : reactivity.unref(r);
150
- }
151
- const resolveUnref = toValue;
152
152
  function reactify(fn, options) {
153
- const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? reactivity.unref : toValue;
153
+ const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? reactivity.unref : reactivity.toValue;
154
154
  return function(...args) {
155
155
  return reactivity.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
156
156
  };
@@ -215,7 +215,7 @@ function reactiveComputed(fn) {
215
215
  function reactiveOmit(obj, ...keys) {
216
216
  const flatKeys = keys.flat();
217
217
  const predicate = flatKeys[0];
218
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
218
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => !predicate(reactivity.toValue(v), k))) : Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
219
219
  }
220
220
  const isClient = typeof window !== "undefined" && typeof document !== "undefined";
221
221
  const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
@@ -258,9 +258,10 @@ function debounceFilter(ms, options = {}) {
258
258
  lastRejector();
259
259
  lastRejector = noop;
260
260
  };
261
+ let lastInvoker;
261
262
  const filter = (invoke2) => {
262
- const duration = toValue(ms);
263
- const maxDuration = toValue(options.maxWait);
263
+ const duration = reactivity.toValue(ms);
264
+ const maxDuration = reactivity.toValue(options.maxWait);
264
265
  if (timer)
265
266
  _clearTimeout(timer);
266
267
  if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
@@ -272,12 +273,13 @@ function debounceFilter(ms, options = {}) {
272
273
  }
273
274
  return new Promise((resolve, reject) => {
274
275
  lastRejector = options.rejectOnCancel ? reject : resolve;
276
+ lastInvoker = invoke2;
275
277
  if (maxDuration && !maxTimer) {
276
278
  maxTimer = setTimeout(() => {
277
279
  if (timer)
278
280
  _clearTimeout(timer);
279
281
  maxTimer = null;
280
- resolve(invoke2());
282
+ resolve(lastInvoker());
281
283
  }, maxDuration);
282
284
  }
283
285
  timer = setTimeout(() => {
@@ -313,7 +315,7 @@ function throttleFilter(...args) {
313
315
  }
314
316
  };
315
317
  const filter = (_invoke) => {
316
- const duration = toValue(ms);
318
+ const duration = reactivity.toValue(ms);
317
319
  const elapsed = Date.now() - lastExec;
318
320
  const invoke2 = () => {
319
321
  return lastValue = _invoke();
@@ -434,6 +436,9 @@ function objectEntries(obj) {
434
436
  function getLifeCycleTarget(target) {
435
437
  return target || null;
436
438
  }
439
+ function toArray(value) {
440
+ return Array.isArray(value) ? value : [value];
441
+ }
437
442
  function toRef(...args) {
438
443
  if (args.length !== 1)
439
444
  return reactivity.toRef(...args);
@@ -444,16 +449,16 @@ const resolveRef = toRef;
444
449
  function reactivePick(obj, ...keys) {
445
450
  const flatKeys = keys.flat();
446
451
  const predicate = flatKeys[0];
447
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
452
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(reactivity.toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
448
453
  }
449
454
  function refAutoReset(defaultValue, afterMs = 1e4) {
450
455
  return reactivity.customRef((track, trigger) => {
451
- let value = toValue(defaultValue);
456
+ let value = reactivity.toValue(defaultValue);
452
457
  let timer;
453
458
  const resetAfter = () => setTimeout(() => {
454
- value = toValue(defaultValue);
459
+ value = reactivity.toValue(defaultValue);
455
460
  trigger();
456
- }, toValue(afterMs));
461
+ }, reactivity.toValue(afterMs));
457
462
  tryOnScopeDispose(() => {
458
463
  clearTimeout(timer);
459
464
  });
@@ -647,8 +652,7 @@ function syncRefs(source, targets, options = {}) {
647
652
  deep = false,
648
653
  immediate = true
649
654
  } = options;
650
- if (!Array.isArray(targets))
651
- targets = [targets];
655
+ targets = toArray(targets);
652
656
  return reactivity.watch(
653
657
  source,
654
658
  (newValue) => targets.forEach((target) => target.value = newValue),
@@ -666,7 +670,7 @@ function toRefs(objectRef, options = {}) {
666
670
  },
667
671
  set(v) {
668
672
  var _a;
669
- const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
673
+ const replaceRef = (_a = reactivity.toValue(options.replaceRef)) != null ? _a : true;
670
674
  if (replaceRef) {
671
675
  if (Array.isArray(objectRef.value)) {
672
676
  const copy = [...objectRef.value];
@@ -685,6 +689,8 @@ function toRefs(objectRef, options = {}) {
685
689
  }
686
690
  return result;
687
691
  }
692
+ const toValue = reactivity.toValue;
693
+ const resolveUnref = reactivity.toValue;
688
694
  function tryOnMounted(fn, sync = true, target) {
689
695
  if (sync)
690
696
  fn();
@@ -716,7 +722,7 @@ function createUntil(r, isNot = false) {
716
722
  const promises = [watcher];
717
723
  if (timeout != null) {
718
724
  promises.push(
719
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
725
+ promiseTimeout(timeout, throwOnTimeout).then(() => reactivity.toValue(r)).finally(() => stop == null ? void 0 : stop())
720
726
  );
721
727
  }
722
728
  return Promise.race(promises);
@@ -748,9 +754,9 @@ function createUntil(r, isNot = false) {
748
754
  const promises = [watcher];
749
755
  if (timeout != null) {
750
756
  promises.push(
751
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
757
+ promiseTimeout(timeout, throwOnTimeout).then(() => reactivity.toValue(r)).finally(() => {
752
758
  stop == null ? void 0 : stop();
753
- return toValue(r);
759
+ return reactivity.toValue(r);
754
760
  })
755
761
  );
756
762
  }
@@ -771,7 +777,7 @@ function createUntil(r, isNot = false) {
771
777
  function toContains(value, options) {
772
778
  return toMatch((v) => {
773
779
  const array = Array.from(v);
774
- return array.includes(value) || array.includes(toValue(value));
780
+ return array.includes(value) || array.includes(reactivity.toValue(value));
775
781
  }, options);
776
782
  }
777
783
  function changed(options) {
@@ -784,7 +790,7 @@ function createUntil(r, isNot = false) {
784
790
  return count >= n;
785
791
  }, options);
786
792
  }
787
- if (Array.isArray(toValue(r))) {
793
+ if (Array.isArray(reactivity.toValue(r))) {
788
794
  const instance = {
789
795
  toMatch,
790
796
  toContains,
@@ -819,29 +825,38 @@ function defaultComparator(value, othVal) {
819
825
  return value === othVal;
820
826
  }
821
827
  function useArrayDifference(...args) {
822
- var _a;
828
+ var _a, _b;
823
829
  const list = args[0];
824
830
  const values = args[1];
825
831
  let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
832
+ const {
833
+ symmetric = false
834
+ } = (_b = args[3]) != null ? _b : {};
826
835
  if (typeof compareFn === "string") {
827
836
  const key = compareFn;
828
837
  compareFn = (value, othVal) => value[key] === othVal[key];
829
838
  }
830
- return reactivity.computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
839
+ const diff1 = reactivity.computed(() => reactivity.toValue(list).filter((x) => reactivity.toValue(values).findIndex((y) => compareFn(x, y)) === -1));
840
+ if (symmetric) {
841
+ const diff2 = reactivity.computed(() => reactivity.toValue(values).filter((x) => reactivity.toValue(list).findIndex((y) => compareFn(x, y)) === -1));
842
+ return reactivity.computed(() => symmetric ? [...reactivity.toValue(diff1), ...reactivity.toValue(diff2)] : reactivity.toValue(diff1));
843
+ } else {
844
+ return diff1;
845
+ }
831
846
  }
832
847
  function useArrayEvery(list, fn) {
833
- return reactivity.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
848
+ return reactivity.computed(() => reactivity.toValue(list).every((element, index, array) => fn(reactivity.toValue(element), index, array)));
834
849
  }
835
850
  function useArrayFilter(list, fn) {
836
- return reactivity.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
851
+ return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).filter(fn));
837
852
  }
838
853
  function useArrayFind(list, fn) {
839
- return reactivity.computed(() => toValue(
840
- toValue(list).find((element, index, array) => fn(toValue(element), index, array))
854
+ return reactivity.computed(() => reactivity.toValue(
855
+ reactivity.toValue(list).find((element, index, array) => fn(reactivity.toValue(element), index, array))
841
856
  ));
842
857
  }
843
858
  function useArrayFindIndex(list, fn) {
844
- return reactivity.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
859
+ return reactivity.computed(() => reactivity.toValue(list).findIndex((element, index, array) => fn(reactivity.toValue(element), index, array)));
845
860
  }
846
861
  function findLast(arr, cb) {
847
862
  let index = arr.length;
@@ -852,8 +867,8 @@ function findLast(arr, cb) {
852
867
  return void 0;
853
868
  }
854
869
  function useArrayFindLast(list, fn) {
855
- return reactivity.computed(() => toValue(
856
- !Array.prototype.findLast ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array)) : toValue(list).findLast((element, index, array) => fn(toValue(element), index, array))
870
+ return reactivity.computed(() => reactivity.toValue(
871
+ !Array.prototype.findLast ? findLast(reactivity.toValue(list), (element, index, array) => fn(reactivity.toValue(element), index, array)) : reactivity.toValue(list).findLast((element, index, array) => fn(reactivity.toValue(element), index, array))
857
872
  ));
858
873
  }
859
874
  function isArrayIncludesOptions(obj) {
@@ -871,31 +886,31 @@ function useArrayIncludes(...args) {
871
886
  }
872
887
  if (typeof comparator === "string") {
873
888
  const key = comparator;
874
- comparator = (element, value2) => element[key] === toValue(value2);
889
+ comparator = (element, value2) => element[key] === reactivity.toValue(value2);
875
890
  }
876
- comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
877
- return reactivity.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
878
- toValue(element),
879
- toValue(value),
891
+ comparator = comparator != null ? comparator : (element, value2) => element === reactivity.toValue(value2);
892
+ return reactivity.computed(() => reactivity.toValue(list).slice(formIndex).some((element, index, array) => comparator(
893
+ reactivity.toValue(element),
894
+ reactivity.toValue(value),
880
895
  index,
881
- toValue(array)
896
+ reactivity.toValue(array)
882
897
  )));
883
898
  }
884
899
  function useArrayJoin(list, separator) {
885
- return reactivity.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
900
+ return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).join(reactivity.toValue(separator)));
886
901
  }
887
902
  function useArrayMap(list, fn) {
888
- return reactivity.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
903
+ return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).map(fn));
889
904
  }
890
905
  function useArrayReduce(list, reducer, ...args) {
891
- const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
906
+ const reduceCallback = (sum, value, index) => reducer(reactivity.toValue(sum), reactivity.toValue(value), index);
892
907
  return reactivity.computed(() => {
893
- const resolved = toValue(list);
894
- return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
908
+ const resolved = reactivity.toValue(list);
909
+ return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? reactivity.toValue(args[0]()) : reactivity.toValue(args[0])) : resolved.reduce(reduceCallback);
895
910
  });
896
911
  }
897
912
  function useArraySome(list, fn) {
898
- return reactivity.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
913
+ return reactivity.computed(() => reactivity.toValue(list).some((element, index, array) => fn(reactivity.toValue(element), index, array)));
899
914
  }
900
915
  function uniq(array) {
901
916
  return Array.from(new Set(array));
@@ -909,7 +924,7 @@ function uniqueElementsBy(array, fn) {
909
924
  }
910
925
  function useArrayUnique(list, compareFn) {
911
926
  return reactivity.computed(() => {
912
- const resolvedList = toValue(list).map((element) => toValue(element));
927
+ const resolvedList = reactivity.toValue(list).map((element) => reactivity.toValue(element));
913
928
  return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
914
929
  });
915
930
  }
@@ -961,8 +976,8 @@ function formatDate(date, formatStr, options = {}) {
961
976
  M: () => month + 1,
962
977
  Mo: () => formatOrdinal(month + 1),
963
978
  MM: () => `${month + 1}`.padStart(2, "0"),
964
- MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
965
- MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
979
+ MMM: () => date.toLocaleDateString(reactivity.toValue(options.locales), { month: "short" }),
980
+ MMMM: () => date.toLocaleDateString(reactivity.toValue(options.locales), { month: "long" }),
966
981
  D: () => String(days),
967
982
  Do: () => formatOrdinal(days),
968
983
  DD: () => `${days}`.padStart(2, "0"),
@@ -980,9 +995,9 @@ function formatDate(date, formatStr, options = {}) {
980
995
  ss: () => `${seconds}`.padStart(2, "0"),
981
996
  SSS: () => `${milliseconds}`.padStart(3, "0"),
982
997
  d: () => day,
983
- dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
984
- ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
985
- dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
998
+ dd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "narrow" }),
999
+ ddd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "short" }),
1000
+ dddd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "long" }),
986
1001
  A: () => meridiem(hours, minutes),
987
1002
  AA: () => meridiem(hours, minutes, false, true),
988
1003
  a: () => meridiem(hours, minutes, true),
@@ -1011,7 +1026,7 @@ function normalizeDate(date) {
1011
1026
  return new Date(date);
1012
1027
  }
1013
1028
  function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1014
- return reactivity.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
1029
+ return reactivity.computed(() => formatDate(normalizeDate(reactivity.toValue(date)), reactivity.toValue(formatStr), options));
1015
1030
  }
1016
1031
  function useIntervalFn(cb, interval = 1e3, options = {}) {
1017
1032
  const {
@@ -1031,7 +1046,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1031
1046
  clean();
1032
1047
  }
1033
1048
  function resume() {
1034
- const intervalValue = toValue(interval);
1049
+ const intervalValue = reactivity.toValue(interval);
1035
1050
  if (intervalValue <= 0)
1036
1051
  return;
1037
1052
  isActive.value = true;
@@ -1119,7 +1134,7 @@ function useTimeoutFn(cb, interval, options = {}) {
1119
1134
  isPending.value = false;
1120
1135
  timer = null;
1121
1136
  cb(...args);
1122
- }, toValue(interval));
1137
+ }, reactivity.toValue(interval));
1123
1138
  }
1124
1139
  if (immediate) {
1125
1140
  isPending.value = true;
@@ -1160,8 +1175,10 @@ function useToNumber(value, options = {}) {
1160
1175
  nanToZero
1161
1176
  } = options;
1162
1177
  return reactivity.computed(() => {
1163
- let resolved = toValue(value);
1164
- if (typeof resolved === "string")
1178
+ let resolved = reactivity.toValue(value);
1179
+ if (typeof method === "function")
1180
+ resolved = method(resolved);
1181
+ else if (typeof resolved === "string")
1165
1182
  resolved = Number[method](resolved, radix);
1166
1183
  if (nanToZero && Number.isNaN(resolved))
1167
1184
  resolved = 0;
@@ -1169,7 +1186,7 @@ function useToNumber(value, options = {}) {
1169
1186
  });
1170
1187
  }
1171
1188
  function useToString(value) {
1172
- return reactivity.computed(() => `${toValue(value)}`);
1189
+ return reactivity.computed(() => `${reactivity.toValue(value)}`);
1173
1190
  }
1174
1191
  function useToggle(initialValue = false, options = {}) {
1175
1192
  const {
@@ -1183,8 +1200,8 @@ function useToggle(initialValue = false, options = {}) {
1183
1200
  _value.value = value;
1184
1201
  return _value.value;
1185
1202
  } else {
1186
- const truthy = toValue(truthyValue);
1187
- _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
1203
+ const truthy = reactivity.toValue(truthyValue);
1204
+ _value.value = _value.value === truthy ? reactivity.toValue(falsyValue) : truthy;
1188
1205
  return _value.value;
1189
1206
  }
1190
1207
  }
@@ -1194,7 +1211,7 @@ function useToggle(initialValue = false, options = {}) {
1194
1211
  return [_value, toggle];
1195
1212
  }
1196
1213
  function watchArray(source, cb, options) {
1197
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
1214
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : reactivity.toValue(source)];
1198
1215
  return reactivity.watch(source, (newList, _, onCleanup) => {
1199
1216
  const oldListRemains = Array.from({ length: oldList.length });
1200
1217
  const added = [];
@@ -1225,7 +1242,7 @@ function watchAtMost(source, cb, options) {
1225
1242
  source,
1226
1243
  (...args) => {
1227
1244
  current.value += 1;
1228
- if (current.value >= toValue(count))
1245
+ if (current.value >= reactivity.toValue(count))
1229
1246
  reactivity.nextTick(() => stop());
1230
1247
  cb(...args);
1231
1248
  },
@@ -1395,8 +1412,8 @@ function getWatchSources(sources) {
1395
1412
  if (reactivity.isReactive(sources))
1396
1413
  return sources;
1397
1414
  if (Array.isArray(sources))
1398
- return sources.map((item) => toValue(item));
1399
- return toValue(sources);
1415
+ return sources.map((item) => reactivity.toValue(item));
1416
+ return reactivity.toValue(sources);
1400
1417
  }
1401
1418
  function getOldValue(source) {
1402
1419
  return Array.isArray(source) ? source.map(() => void 0) : void 0;
@@ -1477,61 +1494,60 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1477
1494
  }
1478
1495
  function createUnrefFn(fn) {
1479
1496
  return function(...args) {
1480
- return fn.apply(this, args.map((i) => toValue(i)));
1497
+ return fn.apply(this, args.map((i) => reactivity.toValue(i)));
1481
1498
  };
1482
1499
  }
1483
1500
  const defaultWindow = isClient ? window : void 0;
1484
1501
  function unrefElement(elRef) {
1485
1502
  var _a;
1486
- const plain = toValue(elRef);
1503
+ const plain = reactivity.toValue(elRef);
1487
1504
  return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
1488
1505
  }
1489
1506
  function useEventListener(...args) {
1490
- let target;
1491
- let events2;
1492
- let listeners;
1493
- let options;
1494
- if (typeof args[0] === "string" || Array.isArray(args[0])) {
1495
- [events2, listeners, options] = args;
1496
- target = defaultWindow;
1497
- } else {
1498
- [target, events2, listeners, options] = args;
1499
- }
1500
- if (!target)
1501
- return noop;
1502
- if (!Array.isArray(events2))
1503
- events2 = [events2];
1504
- if (!Array.isArray(listeners))
1505
- listeners = [listeners];
1506
1507
  const cleanups = [];
1507
1508
  const cleanup = () => {
1508
1509
  cleanups.forEach((fn) => fn());
1509
1510
  cleanups.length = 0;
1510
1511
  };
1511
- const register = (el, event, listener, options2) => {
1512
- el.addEventListener(event, listener, options2);
1513
- return () => el.removeEventListener(event, listener, options2);
1512
+ const register = (el, event, listener, options) => {
1513
+ el.addEventListener(event, listener, options);
1514
+ return () => el.removeEventListener(event, listener, options);
1514
1515
  };
1515
- const stopWatch = reactivity.watch(
1516
- () => [unrefElement(target), toValue(options)],
1517
- ([el, options2]) => {
1516
+ const firstParamTargets = reactivity.computed(() => {
1517
+ const test = toArray(reactivity.toValue(args[0])).filter((e) => e != null);
1518
+ return test.every((e) => typeof e !== "string") ? test : void 0;
1519
+ });
1520
+ const stopWatch = watchImmediate(
1521
+ () => {
1522
+ var _a, _b;
1523
+ return [
1524
+ (_b = (_a = firstParamTargets.value) == null ? void 0 : _a.map((e) => unrefElement(e))) != null ? _b : [defaultWindow].filter((e) => e != null),
1525
+ toArray(reactivity.toValue(firstParamTargets.value ? args[1] : args[0])),
1526
+ toArray(reactivity.unref(firstParamTargets.value ? args[2] : args[1])),
1527
+ // @ts-expect-error - TypeScript gets the correct types, but somehow still complains
1528
+ reactivity.toValue(firstParamTargets.value ? args[3] : args[2])
1529
+ ];
1530
+ },
1531
+ ([raw_targets, raw_events, raw_listeners, raw_options]) => {
1518
1532
  cleanup();
1519
- if (!el)
1533
+ if (!(raw_targets == null ? void 0 : raw_targets.length) || !(raw_events == null ? void 0 : raw_events.length) || !(raw_listeners == null ? void 0 : raw_listeners.length))
1520
1534
  return;
1521
- const optionsClone = isObject(options2) ? { ...options2 } : options2;
1535
+ const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
1522
1536
  cleanups.push(
1523
- ...events2.flatMap((event) => {
1524
- return listeners.map((listener) => register(el, event, listener, optionsClone));
1525
- })
1537
+ ...raw_targets.flatMap(
1538
+ (el) => raw_events.flatMap(
1539
+ (event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
1540
+ )
1541
+ )
1526
1542
  );
1527
1543
  },
1528
- { immediate: true, flush: "post" }
1544
+ { flush: "post" }
1529
1545
  );
1530
1546
  const stop = () => {
1531
1547
  stopWatch();
1532
1548
  cleanup();
1533
1549
  };
1534
- tryOnScopeDispose(stop);
1550
+ tryOnScopeDispose(cleanup);
1535
1551
  return stop;
1536
1552
  }
1537
1553
  function useMounted() {
@@ -1552,7 +1568,9 @@ function useRafFn(fn, options = {}) {
1552
1568
  window: window2 = defaultWindow
1553
1569
  } = options;
1554
1570
  const isActive = reactivity.ref(false);
1555
- const intervalLimit = fpsLimit ? 1e3 / fpsLimit : null;
1571
+ const intervalLimit = reactivity.computed(() => {
1572
+ return fpsLimit ? 1e3 / reactivity.toValue(fpsLimit) : null;
1573
+ });
1556
1574
  let previousFrameTimestamp = 0;
1557
1575
  let rafId = null;
1558
1576
  function loop(timestamp2) {
@@ -1561,7 +1579,7 @@ function useRafFn(fn, options = {}) {
1561
1579
  if (!previousFrameTimestamp)
1562
1580
  previousFrameTimestamp = timestamp2;
1563
1581
  const delta = timestamp2 - previousFrameTimestamp;
1564
- if (intervalLimit && delta < intervalLimit) {
1582
+ if (intervalLimit.value && delta < intervalLimit.value) {
1565
1583
  rafId = window2.requestAnimationFrame(loop);
1566
1584
  return;
1567
1585
  }
@@ -1702,8 +1720,9 @@ function useAsyncState(promise, initialState, options) {
1702
1720
  }
1703
1721
  return state.value;
1704
1722
  }
1705
- if (immediate)
1723
+ if (immediate) {
1706
1724
  execute(delay);
1725
+ }
1707
1726
  const shell = {
1708
1727
  state,
1709
1728
  isReady,
@@ -1750,7 +1769,7 @@ function useBase64(target, options) {
1750
1769
  return;
1751
1770
  promise.value = new Promise((resolve, reject) => {
1752
1771
  try {
1753
- const _target = toValue(target);
1772
+ const _target = reactivity.toValue(target);
1754
1773
  if (_target == null) {
1755
1774
  resolve("");
1756
1775
  } else if (typeof _target === "string") {
@@ -1783,7 +1802,9 @@ function useBase64(target, options) {
1783
1802
  reject(error);
1784
1803
  }
1785
1804
  });
1786
- promise.value.then((res) => base64.value = res);
1805
+ promise.value.then((res) => {
1806
+ base64.value = (options == null ? void 0 : options.dataUrl) === false ? res.replace(/^data:.*?;base64,/, "") : res;
1807
+ });
1787
1808
  return promise.value;
1788
1809
  }
1789
1810
  if (reactivity.isRef(target) || typeof target === "function")
@@ -1841,15 +1862,18 @@ function useBroadcastChannel(options) {
1841
1862
  tryOnMounted(() => {
1842
1863
  error.value = null;
1843
1864
  channel.value = new BroadcastChannel(name);
1844
- channel.value.addEventListener("message", (e) => {
1865
+ const listenerOptions = {
1866
+ passive: true
1867
+ };
1868
+ useEventListener(channel, "message", (e) => {
1845
1869
  data.value = e.data;
1846
- }, { passive: true });
1847
- channel.value.addEventListener("messageerror", (e) => {
1870
+ }, listenerOptions);
1871
+ useEventListener(channel, "messageerror", (e) => {
1848
1872
  error.value = e;
1849
- }, { passive: true });
1850
- channel.value.addEventListener("close", () => {
1873
+ }, listenerOptions);
1874
+ useEventListener(channel, "close", () => {
1851
1875
  isClosed.value = true;
1852
- });
1876
+ }, listenerOptions);
1853
1877
  });
1854
1878
  }
1855
1879
  tryOnScopeDispose(() => {
@@ -1878,6 +1902,8 @@ function cloneFnJSON(source) {
1878
1902
  }
1879
1903
  function useCloned(source, options = {}) {
1880
1904
  const cloned = reactivity.ref({});
1905
+ const isModified = reactivity.ref(false);
1906
+ let _lastSync = false;
1881
1907
  const {
1882
1908
  manual,
1883
1909
  clone = cloneFnJSON,
@@ -1885,8 +1911,20 @@ function useCloned(source, options = {}) {
1885
1911
  deep = true,
1886
1912
  immediate = true
1887
1913
  } = options;
1914
+ reactivity.watch(cloned, () => {
1915
+ if (_lastSync) {
1916
+ _lastSync = false;
1917
+ return;
1918
+ }
1919
+ isModified.value = true;
1920
+ }, {
1921
+ deep: true,
1922
+ flush: "sync"
1923
+ });
1888
1924
  function sync() {
1889
- cloned.value = clone(toValue(source));
1925
+ _lastSync = true;
1926
+ isModified.value = false;
1927
+ cloned.value = clone(reactivity.toValue(source));
1890
1928
  }
1891
1929
  if (!manual && (reactivity.isRef(source) || typeof source === "function")) {
1892
1930
  reactivity.watch(source, sync, {
@@ -1897,7 +1935,7 @@ function useCloned(source, options = {}) {
1897
1935
  } else {
1898
1936
  sync();
1899
1937
  }
1900
- return { cloned, sync };
1938
+ return { cloned, isModified, sync };
1901
1939
  }
1902
1940
  function useCycleList(list, options) {
1903
1941
  const state = reactivity.shallowRef(getInitialValue());
@@ -1934,7 +1972,7 @@ function useCycleList(list, options) {
1934
1972
  }
1935
1973
  function getInitialValue() {
1936
1974
  var _a, _b;
1937
- return (_b = toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue(list)[0])) != null ? _b : void 0;
1975
+ return (_b = reactivity.toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : reactivity.toValue(list)[0])) != null ? _b : void 0;
1938
1976
  }
1939
1977
  reactivity.watch(listRef, () => set2(index.value));
1940
1978
  return {
@@ -2168,8 +2206,8 @@ function createFetch(config = {}) {
2168
2206
  const _fetchOptions = config.fetchOptions || {};
2169
2207
  function useFactoryFetch(url, ...args) {
2170
2208
  const computedUrl = reactivity.computed(() => {
2171
- const baseUrl = toValue(config.baseUrl);
2172
- const targetUrl = toValue(url);
2209
+ const baseUrl = reactivity.toValue(config.baseUrl);
2210
+ const targetUrl = reactivity.toValue(url);
2173
2211
  return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
2174
2212
  });
2175
2213
  let options = _options;
@@ -2281,9 +2319,9 @@ function useFetch(url, ...args) {
2281
2319
  method: config.method,
2282
2320
  headers: {}
2283
2321
  };
2284
- if (config.payload) {
2322
+ const payload = reactivity.toValue(config.payload);
2323
+ if (payload) {
2285
2324
  const headers = headersToObject(defaultFetchOptions.headers);
2286
- const payload = toValue(config.payload);
2287
2325
  const proto = Object.getPrototypeOf(payload);
2288
2326
  if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
2289
2327
  config.payloadType = "json";
@@ -2293,7 +2331,7 @@ function useFetch(url, ...args) {
2293
2331
  }
2294
2332
  let isCanceled = false;
2295
2333
  const context = {
2296
- url: toValue(url),
2334
+ url: reactivity.toValue(url),
2297
2335
  options: {
2298
2336
  ...defaultFetchOptions,
2299
2337
  ...fetchOptions
@@ -2332,7 +2370,9 @@ function useFetch(url, ...args) {
2332
2370
  if (options.afterFetch) {
2333
2371
  ({ data: responseData } = await options.afterFetch({
2334
2372
  data: responseData,
2335
- response: fetchResponse
2373
+ response: fetchResponse,
2374
+ context,
2375
+ execute
2336
2376
  }));
2337
2377
  }
2338
2378
  data.value = responseData;
@@ -2344,7 +2384,9 @@ function useFetch(url, ...args) {
2344
2384
  ({ error: errorData, data: responseData } = await options.onFetchError({
2345
2385
  data: responseData,
2346
2386
  error: fetchError,
2347
- response: response.value
2387
+ response: response.value,
2388
+ context,
2389
+ execute
2348
2390
  }));
2349
2391
  }
2350
2392
  error.value = errorData;
@@ -2490,13 +2532,14 @@ function useIdle(timeout = oneMinute, options = {}) {
2490
2532
  );
2491
2533
  if (window2) {
2492
2534
  const document2 = window2.document;
2535
+ const listenerOptions = { passive: true };
2493
2536
  for (const event of events2)
2494
- useEventListener(window2, event, onEvent, { passive: true });
2537
+ useEventListener(window2, event, onEvent, listenerOptions);
2495
2538
  if (listenForVisibilityChange) {
2496
2539
  useEventListener(document2, "visibilitychange", () => {
2497
2540
  if (!document2.hidden)
2498
2541
  onEvent();
2499
- });
2542
+ }, listenerOptions);
2500
2543
  }
2501
2544
  reset();
2502
2545
  }
@@ -2531,7 +2574,7 @@ function useObjectUrl(object) {
2531
2574
  url.value = void 0;
2532
2575
  };
2533
2576
  reactivity.watch(
2534
- () => toValue(object),
2577
+ () => reactivity.toValue(object),
2535
2578
  (newObject) => {
2536
2579
  release();
2537
2580
  if (newObject)
@@ -2544,14 +2587,14 @@ function useObjectUrl(object) {
2544
2587
  }
2545
2588
  function useClamp(value, min, max) {
2546
2589
  if (typeof value === "function" || reactivity.isReadonly(value))
2547
- return reactivity.computed(() => clamp(toValue(value), toValue(min), toValue(max)));
2590
+ return reactivity.computed(() => clamp(reactivity.toValue(value), reactivity.toValue(min), reactivity.toValue(max)));
2548
2591
  const _value = reactivity.ref(value);
2549
2592
  return reactivity.computed({
2550
2593
  get() {
2551
- return _value.value = clamp(_value.value, toValue(min), toValue(max));
2594
+ return _value.value = clamp(_value.value, reactivity.toValue(min), reactivity.toValue(max));
2552
2595
  },
2553
2596
  set(value2) {
2554
- _value.value = clamp(value2, toValue(min), toValue(max));
2597
+ _value.value = clamp(value2, reactivity.toValue(min), reactivity.toValue(max));
2555
2598
  }
2556
2599
  });
2557
2600
  }
@@ -2567,7 +2610,7 @@ function useOffsetPagination(options) {
2567
2610
  const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
2568
2611
  const pageCount = reactivity.computed(() => Math.max(
2569
2612
  1,
2570
- Math.ceil(toValue(total) / toValue(currentPageSize))
2613
+ Math.ceil(reactivity.toValue(total) / reactivity.toValue(currentPageSize))
2571
2614
  ));
2572
2615
  const currentPage = useClamp(page, 1, pageCount);
2573
2616
  const isFirstPage = reactivity.computed(() => currentPage.value === 1);
@@ -2642,9 +2685,9 @@ function useSorted(...args) {
2642
2685
  sortFn = defaultSortFn
2643
2686
  } = options;
2644
2687
  if (!dirty)
2645
- return reactivity.computed(() => sortFn([...toValue(source)], compareFn));
2688
+ return reactivity.computed(() => sortFn([...reactivity.toValue(source)], compareFn));
2646
2689
  reactivity.watchEffect(() => {
2647
- const result = sortFn(toValue(source), compareFn);
2690
+ const result = sortFn(reactivity.toValue(source), compareFn);
2648
2691
  if (reactivity.isRef(source))
2649
2692
  source.value = result;
2650
2693
  else
@@ -2765,7 +2808,7 @@ function useTimeAgo(time, options = {}) {
2765
2808
  updateInterval = 3e4
2766
2809
  } = options;
2767
2810
  const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
2768
- const timeAgo = reactivity.computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now2)));
2811
+ const timeAgo = reactivity.computed(() => formatTimeAgo(new Date(reactivity.toValue(time)), options, reactivity.toValue(now2)));
2769
2812
  if (exposeControls) {
2770
2813
  return {
2771
2814
  timeAgo,
@@ -2821,7 +2864,10 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
2821
2864
  }
2822
2865
  return messages.invalid;
2823
2866
  }
2824
- function useTimeoutPoll(fn, interval, timeoutPollOptions) {
2867
+ function useTimeoutPoll(fn, interval, options = {}) {
2868
+ const {
2869
+ immediate = true
2870
+ } = options;
2825
2871
  const { start } = useTimeoutFn(loop, interval, { immediate: false });
2826
2872
  const isActive = reactivity.ref(false);
2827
2873
  async function loop() {
@@ -2839,7 +2885,7 @@ function useTimeoutPoll(fn, interval, timeoutPollOptions) {
2839
2885
  function pause() {
2840
2886
  isActive.value = false;
2841
2887
  }
2842
- if (timeoutPollOptions == null ? void 0 : timeoutPollOptions.immediate)
2888
+ if (immediate && isClient)
2843
2889
  resume();
2844
2890
  tryOnScopeDispose(pause);
2845
2891
  return {
@@ -2878,6 +2924,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
2878
2924
  removeNullishValues = true,
2879
2925
  removeFalsyValues = false,
2880
2926
  write: enableWrite = true,
2927
+ writeMode = "replace",
2881
2928
  window: window2 = defaultWindow
2882
2929
  } = options;
2883
2930
  if (!window2)
@@ -2933,7 +2980,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
2933
2980
  else
2934
2981
  params.set(key, mapEntry);
2935
2982
  });
2936
- write(params);
2983
+ write(params, false);
2937
2984
  },
2938
2985
  { deep: true }
2939
2986
  );
@@ -2941,11 +2988,19 @@ function useUrlSearchParams(mode = "history", options = {}) {
2941
2988
  pause();
2942
2989
  if (shouldUpdate)
2943
2990
  updateState(params);
2944
- window2.history.replaceState(
2945
- window2.history.state,
2946
- window2.document.title,
2947
- window2.location.pathname + constructQuery(params)
2948
- );
2991
+ if (writeMode === "replace") {
2992
+ window2.history.replaceState(
2993
+ window2.history.state,
2994
+ window2.document.title,
2995
+ window2.location.pathname + constructQuery(params)
2996
+ );
2997
+ } else {
2998
+ window2.history.pushState(
2999
+ window2.history.state,
3000
+ window2.document.title,
3001
+ window2.location.pathname + constructQuery(params)
3002
+ );
3003
+ }
2949
3004
  resume();
2950
3005
  }
2951
3006
  function onChanged() {
@@ -2953,9 +3008,10 @@ function useUrlSearchParams(mode = "history", options = {}) {
2953
3008
  return;
2954
3009
  write(read(), true);
2955
3010
  }
2956
- useEventListener(window2, "popstate", onChanged, false);
3011
+ const listenerOptions = { passive: true };
3012
+ useEventListener(window2, "popstate", onChanged, listenerOptions);
2957
3013
  if (mode !== "history")
2958
- useEventListener(window2, "hashchange", onChanged, false);
3014
+ useEventListener(window2, "hashchange", onChanged, listenerOptions);
2959
3015
  const initial = read();
2960
3016
  if (initial.keys().next().value)
2961
3017
  updateState(initial);
@@ -2976,6 +3032,7 @@ function useWebSocket(url, options = {}) {
2976
3032
  onError,
2977
3033
  onMessage,
2978
3034
  immediate = true,
3035
+ autoConnect = true,
2979
3036
  autoClose = true,
2980
3037
  protocols = []
2981
3038
  } = options;
@@ -2988,6 +3045,7 @@ function useWebSocket(url, options = {}) {
2988
3045
  let explicitlyClosed = false;
2989
3046
  let retried = 0;
2990
3047
  let bufferedData = [];
3048
+ let retryTimeout;
2991
3049
  let pongTimeoutWait;
2992
3050
  const _sendBuffer = () => {
2993
3051
  if (bufferedData.length && wsRef.value && status.value === "OPEN") {
@@ -2996,12 +3054,19 @@ function useWebSocket(url, options = {}) {
2996
3054
  bufferedData = [];
2997
3055
  }
2998
3056
  };
3057
+ const resetRetry = () => {
3058
+ if (retryTimeout != null) {
3059
+ clearTimeout(retryTimeout);
3060
+ retryTimeout = void 0;
3061
+ }
3062
+ };
2999
3063
  const resetHeartbeat = () => {
3000
3064
  clearTimeout(pongTimeoutWait);
3001
3065
  pongTimeoutWait = void 0;
3002
3066
  };
3003
3067
  const close = (code = 1e3, reason) => {
3004
- if (!isClient || !wsRef.value)
3068
+ resetRetry();
3069
+ if (!isClient && !isWorker || !wsRef.value)
3005
3070
  return;
3006
3071
  explicitlyClosed = true;
3007
3072
  resetHeartbeat();
@@ -3043,9 +3108,9 @@ function useWebSocket(url, options = {}) {
3043
3108
  } = resolveNestedOptions(options.autoReconnect);
3044
3109
  if (typeof retries === "number" && (retries < 0 || retried < retries)) {
3045
3110
  retried += 1;
3046
- setTimeout(_init, delay);
3111
+ retryTimeout = setTimeout(_init, delay);
3047
3112
  } else if (typeof retries === "function" && retries()) {
3048
- setTimeout(_init, delay);
3113
+ retryTimeout = setTimeout(_init, delay);
3049
3114
  } else {
3050
3115
  onFailed == null ? void 0 : onFailed();
3051
3116
  }
@@ -3061,7 +3126,7 @@ function useWebSocket(url, options = {}) {
3061
3126
  message = DEFAULT_PING_MESSAGE,
3062
3127
  responseMessage = message
3063
3128
  } = resolveNestedOptions(options.heartbeat);
3064
- if (e.data === responseMessage)
3129
+ if (e.data === reactivity.toValue(responseMessage))
3065
3130
  return;
3066
3131
  }
3067
3132
  data.value = e.data;
@@ -3076,7 +3141,7 @@ function useWebSocket(url, options = {}) {
3076
3141
  } = resolveNestedOptions(options.heartbeat);
3077
3142
  const { pause, resume } = useIntervalFn(
3078
3143
  () => {
3079
- send(message, false);
3144
+ send(reactivity.toValue(message), false);
3080
3145
  if (pongTimeoutWait != null)
3081
3146
  return;
3082
3147
  pongTimeoutWait = setTimeout(() => {
@@ -3092,7 +3157,7 @@ function useWebSocket(url, options = {}) {
3092
3157
  }
3093
3158
  if (autoClose) {
3094
3159
  if (isClient)
3095
- useEventListener("beforeunload", () => close());
3160
+ useEventListener("beforeunload", () => close(), { passive: true });
3096
3161
  tryOnScopeDispose(close);
3097
3162
  }
3098
3163
  const open = () => {
@@ -3105,7 +3170,8 @@ function useWebSocket(url, options = {}) {
3105
3170
  };
3106
3171
  if (immediate)
3107
3172
  open();
3108
- reactivity.watch(urlRef, open);
3173
+ if (autoConnect)
3174
+ reactivity.watch(urlRef, open);
3109
3175
  return {
3110
3176
  data,
3111
3177
  status,