@reactive-vscode/vueuse 0.2.8 → 0.2.10

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, nextTick, isReactive, shallowRef, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
1
+ import { ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, toValue as toValue$1, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, nextTick, isReactive, shallowRef, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
2
2
  function computedWithControl(source, fn) {
3
3
  let v = void 0;
4
4
  let track;
@@ -44,6 +44,9 @@ function createEventHook() {
44
44
  const off = (fn) => {
45
45
  fns.delete(fn);
46
46
  };
47
+ const clear = () => {
48
+ fns.clear();
49
+ };
47
50
  const on = (fn) => {
48
51
  fns.add(fn);
49
52
  const offFn = () => off(fn);
@@ -58,7 +61,8 @@ function createEventHook() {
58
61
  return {
59
62
  on,
60
63
  off,
61
- trigger
64
+ trigger,
65
+ clear
62
66
  };
63
67
  }
64
68
  function createGlobalState(stateFactory) {
@@ -143,12 +147,8 @@ function makeDestructurable(obj, arr) {
143
147
  return Object.assign([...arr], obj);
144
148
  }
145
149
  }
146
- function toValue(r) {
147
- return typeof r === "function" ? r() : unref(r);
148
- }
149
- const resolveUnref = toValue;
150
150
  function reactify(fn, options) {
151
- const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue;
151
+ const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue$1;
152
152
  return function(...args) {
153
153
  return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
154
154
  };
@@ -213,7 +213,7 @@ function reactiveComputed(fn) {
213
213
  function reactiveOmit(obj, ...keys) {
214
214
  const flatKeys = keys.flat();
215
215
  const predicate = flatKeys[0];
216
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
216
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue$1(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
217
217
  }
218
218
  const isClient = typeof window !== "undefined" && typeof document !== "undefined";
219
219
  const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
@@ -256,9 +256,10 @@ function debounceFilter(ms, options = {}) {
256
256
  lastRejector();
257
257
  lastRejector = noop;
258
258
  };
259
+ let lastInvoker;
259
260
  const filter = (invoke2) => {
260
- const duration = toValue(ms);
261
- const maxDuration = toValue(options.maxWait);
261
+ const duration = toValue$1(ms);
262
+ const maxDuration = toValue$1(options.maxWait);
262
263
  if (timer)
263
264
  _clearTimeout(timer);
264
265
  if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
@@ -270,12 +271,13 @@ function debounceFilter(ms, options = {}) {
270
271
  }
271
272
  return new Promise((resolve, reject) => {
272
273
  lastRejector = options.rejectOnCancel ? reject : resolve;
274
+ lastInvoker = invoke2;
273
275
  if (maxDuration && !maxTimer) {
274
276
  maxTimer = setTimeout(() => {
275
277
  if (timer)
276
278
  _clearTimeout(timer);
277
279
  maxTimer = null;
278
- resolve(invoke2());
280
+ resolve(lastInvoker());
279
281
  }, maxDuration);
280
282
  }
281
283
  timer = setTimeout(() => {
@@ -311,7 +313,7 @@ function throttleFilter(...args) {
311
313
  }
312
314
  };
313
315
  const filter = (_invoke) => {
314
- const duration = toValue(ms);
316
+ const duration = toValue$1(ms);
315
317
  const elapsed = Date.now() - lastExec;
316
318
  const invoke2 = () => {
317
319
  return lastValue = _invoke();
@@ -432,6 +434,9 @@ function objectEntries(obj) {
432
434
  function getLifeCycleTarget(target) {
433
435
  return target || null;
434
436
  }
437
+ function toArray(value) {
438
+ return Array.isArray(value) ? value : [value];
439
+ }
435
440
  function toRef(...args) {
436
441
  if (args.length !== 1)
437
442
  return toRef$1(...args);
@@ -442,16 +447,16 @@ const resolveRef = toRef;
442
447
  function reactivePick(obj, ...keys) {
443
448
  const flatKeys = keys.flat();
444
449
  const predicate = flatKeys[0];
445
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
450
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue$1(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
446
451
  }
447
452
  function refAutoReset(defaultValue, afterMs = 1e4) {
448
453
  return customRef((track, trigger) => {
449
- let value = toValue(defaultValue);
454
+ let value = toValue$1(defaultValue);
450
455
  let timer;
451
456
  const resetAfter = () => setTimeout(() => {
452
- value = toValue(defaultValue);
457
+ value = toValue$1(defaultValue);
453
458
  trigger();
454
- }, toValue(afterMs));
459
+ }, toValue$1(afterMs));
455
460
  tryOnScopeDispose(() => {
456
461
  clearTimeout(timer);
457
462
  });
@@ -567,10 +572,8 @@ function set(...args) {
567
572
  ref2.value = value;
568
573
  }
569
574
  if (args.length === 3) {
570
- {
571
- const [target, key, value] = args;
572
- target[key] = value;
573
- }
575
+ const [target, key, value] = args;
576
+ target[key] = value;
574
577
  }
575
578
  }
576
579
  function watchWithFilter(source, cb, options = {}) {
@@ -647,8 +650,7 @@ function syncRefs(source, targets, options = {}) {
647
650
  deep = false,
648
651
  immediate = true
649
652
  } = options;
650
- if (!Array.isArray(targets))
651
- targets = [targets];
653
+ targets = toArray(targets);
652
654
  return watch(
653
655
  source,
654
656
  (newValue) => targets.forEach((target) => target.value = newValue),
@@ -666,7 +668,7 @@ function toRefs(objectRef, options = {}) {
666
668
  },
667
669
  set(v) {
668
670
  var _a;
669
- const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
671
+ const replaceRef = (_a = toValue$1(options.replaceRef)) != null ? _a : true;
670
672
  if (replaceRef) {
671
673
  if (Array.isArray(objectRef.value)) {
672
674
  const copy = [...objectRef.value];
@@ -685,6 +687,8 @@ function toRefs(objectRef, options = {}) {
685
687
  }
686
688
  return result;
687
689
  }
690
+ const toValue = toValue$1;
691
+ const resolveUnref = toValue$1;
688
692
  function tryOnMounted(fn, sync = true, target) {
689
693
  if (sync)
690
694
  fn();
@@ -716,7 +720,7 @@ function createUntil(r, isNot = false) {
716
720
  const promises = [watcher];
717
721
  if (timeout != null) {
718
722
  promises.push(
719
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
723
+ promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => stop == null ? void 0 : stop())
720
724
  );
721
725
  }
722
726
  return Promise.race(promises);
@@ -748,9 +752,9 @@ function createUntil(r, isNot = false) {
748
752
  const promises = [watcher];
749
753
  if (timeout != null) {
750
754
  promises.push(
751
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
755
+ promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => {
752
756
  stop == null ? void 0 : stop();
753
- return toValue(r);
757
+ return toValue$1(r);
754
758
  })
755
759
  );
756
760
  }
@@ -771,7 +775,7 @@ function createUntil(r, isNot = false) {
771
775
  function toContains(value, options) {
772
776
  return toMatch((v) => {
773
777
  const array = Array.from(v);
774
- return array.includes(value) || array.includes(toValue(value));
778
+ return array.includes(value) || array.includes(toValue$1(value));
775
779
  }, options);
776
780
  }
777
781
  function changed(options) {
@@ -784,7 +788,7 @@ function createUntil(r, isNot = false) {
784
788
  return count >= n;
785
789
  }, options);
786
790
  }
787
- if (Array.isArray(toValue(r))) {
791
+ if (Array.isArray(toValue$1(r))) {
788
792
  const instance = {
789
793
  toMatch,
790
794
  toContains,
@@ -819,29 +823,38 @@ function defaultComparator(value, othVal) {
819
823
  return value === othVal;
820
824
  }
821
825
  function useArrayDifference(...args) {
822
- var _a;
826
+ var _a, _b;
823
827
  const list = args[0];
824
828
  const values = args[1];
825
829
  let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
830
+ const {
831
+ symmetric = false
832
+ } = (_b = args[3]) != null ? _b : {};
826
833
  if (typeof compareFn === "string") {
827
834
  const key = compareFn;
828
835
  compareFn = (value, othVal) => value[key] === othVal[key];
829
836
  }
830
- return computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
837
+ const diff1 = computed(() => toValue$1(list).filter((x) => toValue$1(values).findIndex((y) => compareFn(x, y)) === -1));
838
+ if (symmetric) {
839
+ const diff2 = computed(() => toValue$1(values).filter((x) => toValue$1(list).findIndex((y) => compareFn(x, y)) === -1));
840
+ return computed(() => symmetric ? [...toValue$1(diff1), ...toValue$1(diff2)] : toValue$1(diff1));
841
+ } else {
842
+ return diff1;
843
+ }
831
844
  }
832
845
  function useArrayEvery(list, fn) {
833
- return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
846
+ return computed(() => toValue$1(list).every((element, index, array) => fn(toValue$1(element), index, array)));
834
847
  }
835
848
  function useArrayFilter(list, fn) {
836
- return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
849
+ return computed(() => toValue$1(list).map((i) => toValue$1(i)).filter(fn));
837
850
  }
838
851
  function useArrayFind(list, fn) {
839
- return computed(() => toValue(
840
- toValue(list).find((element, index, array) => fn(toValue(element), index, array))
852
+ return computed(() => toValue$1(
853
+ toValue$1(list).find((element, index, array) => fn(toValue$1(element), index, array))
841
854
  ));
842
855
  }
843
856
  function useArrayFindIndex(list, fn) {
844
- return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
857
+ return computed(() => toValue$1(list).findIndex((element, index, array) => fn(toValue$1(element), index, array)));
845
858
  }
846
859
  function findLast(arr, cb) {
847
860
  let index = arr.length;
@@ -852,8 +865,8 @@ function findLast(arr, cb) {
852
865
  return void 0;
853
866
  }
854
867
  function useArrayFindLast(list, fn) {
855
- return 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))
868
+ return computed(() => toValue$1(
869
+ !Array.prototype.findLast ? findLast(toValue$1(list), (element, index, array) => fn(toValue$1(element), index, array)) : toValue$1(list).findLast((element, index, array) => fn(toValue$1(element), index, array))
857
870
  ));
858
871
  }
859
872
  function isArrayIncludesOptions(obj) {
@@ -871,31 +884,31 @@ function useArrayIncludes(...args) {
871
884
  }
872
885
  if (typeof comparator === "string") {
873
886
  const key = comparator;
874
- comparator = (element, value2) => element[key] === toValue(value2);
887
+ comparator = (element, value2) => element[key] === toValue$1(value2);
875
888
  }
876
- comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
877
- return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
878
- toValue(element),
879
- toValue(value),
889
+ comparator = comparator != null ? comparator : (element, value2) => element === toValue$1(value2);
890
+ return computed(() => toValue$1(list).slice(formIndex).some((element, index, array) => comparator(
891
+ toValue$1(element),
892
+ toValue$1(value),
880
893
  index,
881
- toValue(array)
894
+ toValue$1(array)
882
895
  )));
883
896
  }
884
897
  function useArrayJoin(list, separator) {
885
- return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
898
+ return computed(() => toValue$1(list).map((i) => toValue$1(i)).join(toValue$1(separator)));
886
899
  }
887
900
  function useArrayMap(list, fn) {
888
- return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
901
+ return computed(() => toValue$1(list).map((i) => toValue$1(i)).map(fn));
889
902
  }
890
903
  function useArrayReduce(list, reducer, ...args) {
891
- const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
904
+ const reduceCallback = (sum, value, index) => reducer(toValue$1(sum), toValue$1(value), index);
892
905
  return computed(() => {
893
- const resolved = toValue(list);
894
- return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
906
+ const resolved = toValue$1(list);
907
+ return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue$1(args[0]()) : toValue$1(args[0])) : resolved.reduce(reduceCallback);
895
908
  });
896
909
  }
897
910
  function useArraySome(list, fn) {
898
- return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
911
+ return computed(() => toValue$1(list).some((element, index, array) => fn(toValue$1(element), index, array)));
899
912
  }
900
913
  function uniq(array) {
901
914
  return Array.from(new Set(array));
@@ -909,7 +922,7 @@ function uniqueElementsBy(array, fn) {
909
922
  }
910
923
  function useArrayUnique(list, compareFn) {
911
924
  return computed(() => {
912
- const resolvedList = toValue(list).map((element) => toValue(element));
925
+ const resolvedList = toValue$1(list).map((element) => toValue$1(element));
913
926
  return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
914
927
  });
915
928
  }
@@ -961,8 +974,8 @@ function formatDate(date, formatStr, options = {}) {
961
974
  M: () => month + 1,
962
975
  Mo: () => formatOrdinal(month + 1),
963
976
  MM: () => `${month + 1}`.padStart(2, "0"),
964
- MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
965
- MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
977
+ MMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "short" }),
978
+ MMMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "long" }),
966
979
  D: () => String(days),
967
980
  Do: () => formatOrdinal(days),
968
981
  DD: () => `${days}`.padStart(2, "0"),
@@ -980,9 +993,9 @@ function formatDate(date, formatStr, options = {}) {
980
993
  ss: () => `${seconds}`.padStart(2, "0"),
981
994
  SSS: () => `${milliseconds}`.padStart(3, "0"),
982
995
  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" }),
996
+ dd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "narrow" }),
997
+ ddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "short" }),
998
+ dddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "long" }),
986
999
  A: () => meridiem(hours, minutes),
987
1000
  AA: () => meridiem(hours, minutes, false, true),
988
1001
  a: () => meridiem(hours, minutes, true),
@@ -1011,7 +1024,7 @@ function normalizeDate(date) {
1011
1024
  return new Date(date);
1012
1025
  }
1013
1026
  function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1014
- return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
1027
+ return computed(() => formatDate(normalizeDate(toValue$1(date)), toValue$1(formatStr), options));
1015
1028
  }
1016
1029
  function useIntervalFn(cb, interval = 1e3, options = {}) {
1017
1030
  const {
@@ -1031,14 +1044,15 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1031
1044
  clean();
1032
1045
  }
1033
1046
  function resume() {
1034
- const intervalValue = toValue(interval);
1047
+ const intervalValue = toValue$1(interval);
1035
1048
  if (intervalValue <= 0)
1036
1049
  return;
1037
1050
  isActive.value = true;
1038
1051
  if (immediateCallback)
1039
1052
  cb();
1040
1053
  clean();
1041
- timer = setInterval(cb, intervalValue);
1054
+ if (isActive.value)
1055
+ timer = setInterval(cb, intervalValue);
1042
1056
  }
1043
1057
  if (immediate && isClient)
1044
1058
  resume();
@@ -1118,7 +1132,7 @@ function useTimeoutFn(cb, interval, options = {}) {
1118
1132
  isPending.value = false;
1119
1133
  timer = null;
1120
1134
  cb(...args);
1121
- }, toValue(interval));
1135
+ }, toValue$1(interval));
1122
1136
  }
1123
1137
  if (immediate) {
1124
1138
  isPending.value = true;
@@ -1159,8 +1173,10 @@ function useToNumber(value, options = {}) {
1159
1173
  nanToZero
1160
1174
  } = options;
1161
1175
  return computed(() => {
1162
- let resolved = toValue(value);
1163
- if (typeof resolved === "string")
1176
+ let resolved = toValue$1(value);
1177
+ if (typeof method === "function")
1178
+ resolved = method(resolved);
1179
+ else if (typeof resolved === "string")
1164
1180
  resolved = Number[method](resolved, radix);
1165
1181
  if (nanToZero && Number.isNaN(resolved))
1166
1182
  resolved = 0;
@@ -1168,7 +1184,7 @@ function useToNumber(value, options = {}) {
1168
1184
  });
1169
1185
  }
1170
1186
  function useToString(value) {
1171
- return computed(() => `${toValue(value)}`);
1187
+ return computed(() => `${toValue$1(value)}`);
1172
1188
  }
1173
1189
  function useToggle(initialValue = false, options = {}) {
1174
1190
  const {
@@ -1182,8 +1198,8 @@ function useToggle(initialValue = false, options = {}) {
1182
1198
  _value.value = value;
1183
1199
  return _value.value;
1184
1200
  } else {
1185
- const truthy = toValue(truthyValue);
1186
- _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
1201
+ const truthy = toValue$1(truthyValue);
1202
+ _value.value = _value.value === truthy ? toValue$1(falsyValue) : truthy;
1187
1203
  return _value.value;
1188
1204
  }
1189
1205
  }
@@ -1193,7 +1209,7 @@ function useToggle(initialValue = false, options = {}) {
1193
1209
  return [_value, toggle];
1194
1210
  }
1195
1211
  function watchArray(source, cb, options) {
1196
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
1212
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
1197
1213
  return watch(source, (newList, _, onCleanup) => {
1198
1214
  const oldListRemains = Array.from({ length: oldList.length });
1199
1215
  const added = [];
@@ -1224,7 +1240,7 @@ function watchAtMost(source, cb, options) {
1224
1240
  source,
1225
1241
  (...args) => {
1226
1242
  current.value += 1;
1227
- if (current.value >= toValue(count))
1243
+ if (current.value >= toValue$1(count))
1228
1244
  nextTick(() => stop());
1229
1245
  cb(...args);
1230
1246
  },
@@ -1394,8 +1410,8 @@ function getWatchSources(sources) {
1394
1410
  if (isReactive(sources))
1395
1411
  return sources;
1396
1412
  if (Array.isArray(sources))
1397
- return sources.map((item) => toValue(item));
1398
- return toValue(sources);
1413
+ return sources.map((item) => toValue$1(item));
1414
+ return toValue$1(sources);
1399
1415
  }
1400
1416
  function getOldValue(source) {
1401
1417
  return Array.isArray(source) ? source.map(() => void 0) : void 0;
@@ -1476,61 +1492,60 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1476
1492
  }
1477
1493
  function createUnrefFn(fn) {
1478
1494
  return function(...args) {
1479
- return fn.apply(this, args.map((i) => toValue(i)));
1495
+ return fn.apply(this, args.map((i) => toValue$1(i)));
1480
1496
  };
1481
1497
  }
1482
1498
  const defaultWindow = isClient ? window : void 0;
1483
1499
  function unrefElement(elRef) {
1484
1500
  var _a;
1485
- const plain = toValue(elRef);
1501
+ const plain = toValue$1(elRef);
1486
1502
  return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
1487
1503
  }
1488
1504
  function useEventListener(...args) {
1489
- let target;
1490
- let events2;
1491
- let listeners;
1492
- let options;
1493
- if (typeof args[0] === "string" || Array.isArray(args[0])) {
1494
- [events2, listeners, options] = args;
1495
- target = defaultWindow;
1496
- } else {
1497
- [target, events2, listeners, options] = args;
1498
- }
1499
- if (!target)
1500
- return noop;
1501
- if (!Array.isArray(events2))
1502
- events2 = [events2];
1503
- if (!Array.isArray(listeners))
1504
- listeners = [listeners];
1505
1505
  const cleanups = [];
1506
1506
  const cleanup = () => {
1507
1507
  cleanups.forEach((fn) => fn());
1508
1508
  cleanups.length = 0;
1509
1509
  };
1510
- const register = (el, event, listener, options2) => {
1511
- el.addEventListener(event, listener, options2);
1512
- return () => el.removeEventListener(event, listener, options2);
1510
+ const register = (el, event, listener, options) => {
1511
+ el.addEventListener(event, listener, options);
1512
+ return () => el.removeEventListener(event, listener, options);
1513
1513
  };
1514
- const stopWatch = watch(
1515
- () => [unrefElement(target), toValue(options)],
1516
- ([el, options2]) => {
1514
+ const firstParamTargets = computed(() => {
1515
+ const test = toArray(toValue$1(args[0])).filter((e) => e != null);
1516
+ return test.every((e) => typeof e !== "string") ? test : void 0;
1517
+ });
1518
+ const stopWatch = watchImmediate(
1519
+ () => {
1520
+ var _a, _b;
1521
+ return [
1522
+ (_b = (_a = firstParamTargets.value) == null ? void 0 : _a.map((e) => unrefElement(e))) != null ? _b : [defaultWindow].filter((e) => e != null),
1523
+ toArray(toValue$1(firstParamTargets.value ? args[1] : args[0])),
1524
+ toArray(unref(firstParamTargets.value ? args[2] : args[1])),
1525
+ // @ts-expect-error - TypeScript gets the correct types, but somehow still complains
1526
+ toValue$1(firstParamTargets.value ? args[3] : args[2])
1527
+ ];
1528
+ },
1529
+ ([raw_targets, raw_events, raw_listeners, raw_options]) => {
1517
1530
  cleanup();
1518
- if (!el)
1531
+ 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))
1519
1532
  return;
1520
- const optionsClone = isObject(options2) ? { ...options2 } : options2;
1533
+ const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
1521
1534
  cleanups.push(
1522
- ...events2.flatMap((event) => {
1523
- return listeners.map((listener) => register(el, event, listener, optionsClone));
1524
- })
1535
+ ...raw_targets.flatMap(
1536
+ (el) => raw_events.flatMap(
1537
+ (event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
1538
+ )
1539
+ )
1525
1540
  );
1526
1541
  },
1527
- { immediate: true, flush: "post" }
1542
+ { flush: "post" }
1528
1543
  );
1529
1544
  const stop = () => {
1530
1545
  stopWatch();
1531
1546
  cleanup();
1532
1547
  };
1533
- tryOnScopeDispose(stop);
1548
+ tryOnScopeDispose(cleanup);
1534
1549
  return stop;
1535
1550
  }
1536
1551
  function useMounted() {
@@ -1551,7 +1566,9 @@ function useRafFn(fn, options = {}) {
1551
1566
  window: window2 = defaultWindow
1552
1567
  } = options;
1553
1568
  const isActive = ref(false);
1554
- const intervalLimit = fpsLimit ? 1e3 / fpsLimit : null;
1569
+ const intervalLimit = computed(() => {
1570
+ return fpsLimit ? 1e3 / toValue$1(fpsLimit) : null;
1571
+ });
1555
1572
  let previousFrameTimestamp = 0;
1556
1573
  let rafId = null;
1557
1574
  function loop(timestamp2) {
@@ -1560,7 +1577,7 @@ function useRafFn(fn, options = {}) {
1560
1577
  if (!previousFrameTimestamp)
1561
1578
  previousFrameTimestamp = timestamp2;
1562
1579
  const delta = timestamp2 - previousFrameTimestamp;
1563
- if (intervalLimit && delta < intervalLimit) {
1580
+ if (intervalLimit.value && delta < intervalLimit.value) {
1564
1581
  rafId = window2.requestAnimationFrame(loop);
1565
1582
  return;
1566
1583
  }
@@ -1701,8 +1718,9 @@ function useAsyncState(promise, initialState, options) {
1701
1718
  }
1702
1719
  return state.value;
1703
1720
  }
1704
- if (immediate)
1721
+ if (immediate) {
1705
1722
  execute(delay);
1723
+ }
1706
1724
  const shell = {
1707
1725
  state,
1708
1726
  isReady,
@@ -1749,7 +1767,7 @@ function useBase64(target, options) {
1749
1767
  return;
1750
1768
  promise.value = new Promise((resolve, reject) => {
1751
1769
  try {
1752
- const _target = toValue(target);
1770
+ const _target = toValue$1(target);
1753
1771
  if (_target == null) {
1754
1772
  resolve("");
1755
1773
  } else if (typeof _target === "string") {
@@ -1782,7 +1800,9 @@ function useBase64(target, options) {
1782
1800
  reject(error);
1783
1801
  }
1784
1802
  });
1785
- promise.value.then((res) => base64.value = res);
1803
+ promise.value.then((res) => {
1804
+ base64.value = (options == null ? void 0 : options.dataUrl) === false ? res.replace(/^data:.*?;base64,/, "") : res;
1805
+ });
1786
1806
  return promise.value;
1787
1807
  }
1788
1808
  if (isRef(target) || typeof target === "function")
@@ -1840,15 +1860,18 @@ function useBroadcastChannel(options) {
1840
1860
  tryOnMounted(() => {
1841
1861
  error.value = null;
1842
1862
  channel.value = new BroadcastChannel(name);
1843
- channel.value.addEventListener("message", (e) => {
1863
+ const listenerOptions = {
1864
+ passive: true
1865
+ };
1866
+ useEventListener(channel, "message", (e) => {
1844
1867
  data.value = e.data;
1845
- }, { passive: true });
1846
- channel.value.addEventListener("messageerror", (e) => {
1868
+ }, listenerOptions);
1869
+ useEventListener(channel, "messageerror", (e) => {
1847
1870
  error.value = e;
1848
- }, { passive: true });
1849
- channel.value.addEventListener("close", () => {
1871
+ }, listenerOptions);
1872
+ useEventListener(channel, "close", () => {
1850
1873
  isClosed.value = true;
1851
- });
1874
+ }, listenerOptions);
1852
1875
  });
1853
1876
  }
1854
1877
  tryOnScopeDispose(() => {
@@ -1877,6 +1900,8 @@ function cloneFnJSON(source) {
1877
1900
  }
1878
1901
  function useCloned(source, options = {}) {
1879
1902
  const cloned = ref({});
1903
+ const isModified = ref(false);
1904
+ let _lastSync = false;
1880
1905
  const {
1881
1906
  manual,
1882
1907
  clone = cloneFnJSON,
@@ -1884,8 +1909,20 @@ function useCloned(source, options = {}) {
1884
1909
  deep = true,
1885
1910
  immediate = true
1886
1911
  } = options;
1912
+ watch(cloned, () => {
1913
+ if (_lastSync) {
1914
+ _lastSync = false;
1915
+ return;
1916
+ }
1917
+ isModified.value = true;
1918
+ }, {
1919
+ deep: true,
1920
+ flush: "sync"
1921
+ });
1887
1922
  function sync() {
1888
- cloned.value = clone(toValue(source));
1923
+ _lastSync = true;
1924
+ isModified.value = false;
1925
+ cloned.value = clone(toValue$1(source));
1889
1926
  }
1890
1927
  if (!manual && (isRef(source) || typeof source === "function")) {
1891
1928
  watch(source, sync, {
@@ -1896,7 +1933,7 @@ function useCloned(source, options = {}) {
1896
1933
  } else {
1897
1934
  sync();
1898
1935
  }
1899
- return { cloned, sync };
1936
+ return { cloned, isModified, sync };
1900
1937
  }
1901
1938
  function useCycleList(list, options) {
1902
1939
  const state = shallowRef(getInitialValue());
@@ -1933,7 +1970,7 @@ function useCycleList(list, options) {
1933
1970
  }
1934
1971
  function getInitialValue() {
1935
1972
  var _a, _b;
1936
- return (_b = toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue(list)[0])) != null ? _b : void 0;
1973
+ return (_b = toValue$1((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue$1(list)[0])) != null ? _b : void 0;
1937
1974
  }
1938
1975
  watch(listRef, () => set2(index.value));
1939
1976
  return {
@@ -2167,8 +2204,8 @@ function createFetch(config = {}) {
2167
2204
  const _fetchOptions = config.fetchOptions || {};
2168
2205
  function useFactoryFetch(url, ...args) {
2169
2206
  const computedUrl = computed(() => {
2170
- const baseUrl = toValue(config.baseUrl);
2171
- const targetUrl = toValue(url);
2207
+ const baseUrl = toValue$1(config.baseUrl);
2208
+ const targetUrl = toValue$1(url);
2172
2209
  return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
2173
2210
  });
2174
2211
  let options = _options;
@@ -2280,10 +2317,11 @@ function useFetch(url, ...args) {
2280
2317
  method: config.method,
2281
2318
  headers: {}
2282
2319
  };
2283
- if (config.payload) {
2320
+ const payload = toValue$1(config.payload);
2321
+ if (payload) {
2284
2322
  const headers = headersToObject(defaultFetchOptions.headers);
2285
- const payload = toValue(config.payload);
2286
- if (!config.payloadType && payload && Object.getPrototypeOf(payload) === Object.prototype && !(payload instanceof FormData))
2323
+ const proto = Object.getPrototypeOf(payload);
2324
+ if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
2287
2325
  config.payloadType = "json";
2288
2326
  if (config.payloadType)
2289
2327
  headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
@@ -2291,7 +2329,7 @@ function useFetch(url, ...args) {
2291
2329
  }
2292
2330
  let isCanceled = false;
2293
2331
  const context = {
2294
- url: toValue(url),
2332
+ url: toValue$1(url),
2295
2333
  options: {
2296
2334
  ...defaultFetchOptions,
2297
2335
  ...fetchOptions
@@ -2330,7 +2368,9 @@ function useFetch(url, ...args) {
2330
2368
  if (options.afterFetch) {
2331
2369
  ({ data: responseData } = await options.afterFetch({
2332
2370
  data: responseData,
2333
- response: fetchResponse
2371
+ response: fetchResponse,
2372
+ context,
2373
+ execute
2334
2374
  }));
2335
2375
  }
2336
2376
  data.value = responseData;
@@ -2342,7 +2382,9 @@ function useFetch(url, ...args) {
2342
2382
  ({ error: errorData, data: responseData } = await options.onFetchError({
2343
2383
  data: responseData,
2344
2384
  error: fetchError,
2345
- response: response.value
2385
+ response: response.value,
2386
+ context,
2387
+ execute
2346
2388
  }));
2347
2389
  }
2348
2390
  error.value = errorData;
@@ -2426,7 +2468,7 @@ function useFetch(url, ...args) {
2426
2468
  }
2427
2469
  function waitUntilFinished() {
2428
2470
  return new Promise((resolve, reject) => {
2429
- until(isFinished).toBe(true).then(() => resolve(shell)).catch((error2) => reject(error2));
2471
+ until(isFinished).toBe(true).then(() => resolve(shell)).catch(reject);
2430
2472
  });
2431
2473
  }
2432
2474
  function setType(type) {
@@ -2453,8 +2495,12 @@ function useFetch(url, ...args) {
2453
2495
  };
2454
2496
  }
2455
2497
  function joinPaths(start, end) {
2456
- if (!start.endsWith("/") && !end.startsWith("/"))
2498
+ if (!start.endsWith("/") && !end.startsWith("/")) {
2457
2499
  return `${start}/${end}`;
2500
+ }
2501
+ if (start.endsWith("/") && end.startsWith("/")) {
2502
+ return `${start.slice(0, -1)}${end}`;
2503
+ }
2458
2504
  return `${start}${end}`;
2459
2505
  }
2460
2506
  const defaultEvents$1 = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"];
@@ -2484,13 +2530,14 @@ function useIdle(timeout = oneMinute, options = {}) {
2484
2530
  );
2485
2531
  if (window2) {
2486
2532
  const document2 = window2.document;
2533
+ const listenerOptions = { passive: true };
2487
2534
  for (const event of events2)
2488
- useEventListener(window2, event, onEvent, { passive: true });
2535
+ useEventListener(window2, event, onEvent, listenerOptions);
2489
2536
  if (listenForVisibilityChange) {
2490
2537
  useEventListener(document2, "visibilitychange", () => {
2491
2538
  if (!document2.hidden)
2492
2539
  onEvent();
2493
- });
2540
+ }, listenerOptions);
2494
2541
  }
2495
2542
  reset();
2496
2543
  }
@@ -2525,7 +2572,7 @@ function useObjectUrl(object) {
2525
2572
  url.value = void 0;
2526
2573
  };
2527
2574
  watch(
2528
- () => toValue(object),
2575
+ () => toValue$1(object),
2529
2576
  (newObject) => {
2530
2577
  release();
2531
2578
  if (newObject)
@@ -2538,14 +2585,14 @@ function useObjectUrl(object) {
2538
2585
  }
2539
2586
  function useClamp(value, min, max) {
2540
2587
  if (typeof value === "function" || isReadonly(value))
2541
- return computed(() => clamp(toValue(value), toValue(min), toValue(max)));
2588
+ return computed(() => clamp(toValue$1(value), toValue$1(min), toValue$1(max)));
2542
2589
  const _value = ref(value);
2543
2590
  return computed({
2544
2591
  get() {
2545
- return _value.value = clamp(_value.value, toValue(min), toValue(max));
2592
+ return _value.value = clamp(_value.value, toValue$1(min), toValue$1(max));
2546
2593
  },
2547
2594
  set(value2) {
2548
- _value.value = clamp(value2, toValue(min), toValue(max));
2595
+ _value.value = clamp(value2, toValue$1(min), toValue$1(max));
2549
2596
  }
2550
2597
  });
2551
2598
  }
@@ -2561,7 +2608,7 @@ function useOffsetPagination(options) {
2561
2608
  const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
2562
2609
  const pageCount = computed(() => Math.max(
2563
2610
  1,
2564
- Math.ceil(toValue(total) / toValue(currentPageSize))
2611
+ Math.ceil(toValue$1(total) / toValue$1(currentPageSize))
2565
2612
  ));
2566
2613
  const currentPage = useClamp(page, 1, pageCount);
2567
2614
  const isFirstPage = computed(() => currentPage.value === 1);
@@ -2636,9 +2683,9 @@ function useSorted(...args) {
2636
2683
  sortFn = defaultSortFn
2637
2684
  } = options;
2638
2685
  if (!dirty)
2639
- return computed(() => sortFn([...toValue(source)], compareFn));
2686
+ return computed(() => sortFn([...toValue$1(source)], compareFn));
2640
2687
  watchEffect(() => {
2641
- const result = sortFn(toValue(source), compareFn);
2688
+ const result = sortFn(toValue$1(source), compareFn);
2642
2689
  if (isRef(source))
2643
2690
  source.value = result;
2644
2691
  else
@@ -2759,7 +2806,7 @@ function useTimeAgo(time, options = {}) {
2759
2806
  updateInterval = 3e4
2760
2807
  } = options;
2761
2808
  const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
2762
- const timeAgo = computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now2)));
2809
+ const timeAgo = computed(() => formatTimeAgo(new Date(toValue$1(time)), options, toValue$1(now2)));
2763
2810
  if (exposeControls) {
2764
2811
  return {
2765
2812
  timeAgo,
@@ -2815,7 +2862,10 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
2815
2862
  }
2816
2863
  return messages.invalid;
2817
2864
  }
2818
- function useTimeoutPoll(fn, interval, timeoutPollOptions) {
2865
+ function useTimeoutPoll(fn, interval, options = {}) {
2866
+ const {
2867
+ immediate = true
2868
+ } = options;
2819
2869
  const { start } = useTimeoutFn(loop, interval, { immediate: false });
2820
2870
  const isActive = ref(false);
2821
2871
  async function loop() {
@@ -2833,7 +2883,7 @@ function useTimeoutPoll(fn, interval, timeoutPollOptions) {
2833
2883
  function pause() {
2834
2884
  isActive.value = false;
2835
2885
  }
2836
- if (timeoutPollOptions == null ? void 0 : timeoutPollOptions.immediate)
2886
+ if (immediate && isClient)
2837
2887
  resume();
2838
2888
  tryOnScopeDispose(pause);
2839
2889
  return {
@@ -2872,6 +2922,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
2872
2922
  removeNullishValues = true,
2873
2923
  removeFalsyValues = false,
2874
2924
  write: enableWrite = true,
2925
+ writeMode = "replace",
2875
2926
  window: window2 = defaultWindow
2876
2927
  } = options;
2877
2928
  if (!window2)
@@ -2897,8 +2948,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
2897
2948
  const hash = window2.location.hash || "#";
2898
2949
  const index = hash.indexOf("?");
2899
2950
  if (index > 0)
2900
- return `${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2901
- return `${hash}${stringified ? `?${stringified}` : ""}`;
2951
+ return `${window2.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
2952
+ return `${window2.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
2902
2953
  }
2903
2954
  function read() {
2904
2955
  return new URLSearchParams(getRawParams());
@@ -2927,7 +2978,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
2927
2978
  else
2928
2979
  params.set(key, mapEntry);
2929
2980
  });
2930
- write(params);
2981
+ write(params, false);
2931
2982
  },
2932
2983
  { deep: true }
2933
2984
  );
@@ -2935,11 +2986,19 @@ function useUrlSearchParams(mode = "history", options = {}) {
2935
2986
  pause();
2936
2987
  if (shouldUpdate)
2937
2988
  updateState(params);
2938
- window2.history.replaceState(
2939
- window2.history.state,
2940
- window2.document.title,
2941
- window2.location.pathname + constructQuery(params)
2942
- );
2989
+ if (writeMode === "replace") {
2990
+ window2.history.replaceState(
2991
+ window2.history.state,
2992
+ window2.document.title,
2993
+ window2.location.pathname + constructQuery(params)
2994
+ );
2995
+ } else {
2996
+ window2.history.pushState(
2997
+ window2.history.state,
2998
+ window2.document.title,
2999
+ window2.location.pathname + constructQuery(params)
3000
+ );
3001
+ }
2943
3002
  resume();
2944
3003
  }
2945
3004
  function onChanged() {
@@ -2947,9 +3006,10 @@ function useUrlSearchParams(mode = "history", options = {}) {
2947
3006
  return;
2948
3007
  write(read(), true);
2949
3008
  }
2950
- useEventListener(window2, "popstate", onChanged, false);
3009
+ const listenerOptions = { passive: true };
3010
+ useEventListener(window2, "popstate", onChanged, listenerOptions);
2951
3011
  if (mode !== "history")
2952
- useEventListener(window2, "hashchange", onChanged, false);
3012
+ useEventListener(window2, "hashchange", onChanged, listenerOptions);
2953
3013
  const initial = read();
2954
3014
  if (initial.keys().next().value)
2955
3015
  updateState(initial);
@@ -2970,6 +3030,7 @@ function useWebSocket(url, options = {}) {
2970
3030
  onError,
2971
3031
  onMessage,
2972
3032
  immediate = true,
3033
+ autoConnect = true,
2973
3034
  autoClose = true,
2974
3035
  protocols = []
2975
3036
  } = options;
@@ -2982,6 +3043,7 @@ function useWebSocket(url, options = {}) {
2982
3043
  let explicitlyClosed = false;
2983
3044
  let retried = 0;
2984
3045
  let bufferedData = [];
3046
+ let retryTimeout;
2985
3047
  let pongTimeoutWait;
2986
3048
  const _sendBuffer = () => {
2987
3049
  if (bufferedData.length && wsRef.value && status.value === "OPEN") {
@@ -2990,12 +3052,19 @@ function useWebSocket(url, options = {}) {
2990
3052
  bufferedData = [];
2991
3053
  }
2992
3054
  };
3055
+ const resetRetry = () => {
3056
+ if (retryTimeout != null) {
3057
+ clearTimeout(retryTimeout);
3058
+ retryTimeout = void 0;
3059
+ }
3060
+ };
2993
3061
  const resetHeartbeat = () => {
2994
3062
  clearTimeout(pongTimeoutWait);
2995
3063
  pongTimeoutWait = void 0;
2996
3064
  };
2997
3065
  const close = (code = 1e3, reason) => {
2998
- if (!isClient || !wsRef.value)
3066
+ resetRetry();
3067
+ if (!isClient && !isWorker || !wsRef.value)
2999
3068
  return;
3000
3069
  explicitlyClosed = true;
3001
3070
  resetHeartbeat();
@@ -3029,7 +3098,7 @@ function useWebSocket(url, options = {}) {
3029
3098
  ws.onclose = (ev) => {
3030
3099
  status.value = "CLOSED";
3031
3100
  onDisconnected == null ? void 0 : onDisconnected(ws, ev);
3032
- if (!explicitlyClosed && options.autoReconnect && ws === wsRef.value) {
3101
+ if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
3033
3102
  const {
3034
3103
  retries = -1,
3035
3104
  delay = 1e3,
@@ -3037,9 +3106,9 @@ function useWebSocket(url, options = {}) {
3037
3106
  } = resolveNestedOptions(options.autoReconnect);
3038
3107
  if (typeof retries === "number" && (retries < 0 || retried < retries)) {
3039
3108
  retried += 1;
3040
- setTimeout(_init, delay);
3109
+ retryTimeout = setTimeout(_init, delay);
3041
3110
  } else if (typeof retries === "function" && retries()) {
3042
- setTimeout(_init, delay);
3111
+ retryTimeout = setTimeout(_init, delay);
3043
3112
  } else {
3044
3113
  onFailed == null ? void 0 : onFailed();
3045
3114
  }
@@ -3055,7 +3124,7 @@ function useWebSocket(url, options = {}) {
3055
3124
  message = DEFAULT_PING_MESSAGE,
3056
3125
  responseMessage = message
3057
3126
  } = resolveNestedOptions(options.heartbeat);
3058
- if (e.data === responseMessage)
3127
+ if (e.data === toValue$1(responseMessage))
3059
3128
  return;
3060
3129
  }
3061
3130
  data.value = e.data;
@@ -3070,7 +3139,7 @@ function useWebSocket(url, options = {}) {
3070
3139
  } = resolveNestedOptions(options.heartbeat);
3071
3140
  const { pause, resume } = useIntervalFn(
3072
3141
  () => {
3073
- send(message, false);
3142
+ send(toValue$1(message), false);
3074
3143
  if (pongTimeoutWait != null)
3075
3144
  return;
3076
3145
  pongTimeoutWait = setTimeout(() => {
@@ -3086,7 +3155,7 @@ function useWebSocket(url, options = {}) {
3086
3155
  }
3087
3156
  if (autoClose) {
3088
3157
  if (isClient)
3089
- useEventListener("beforeunload", () => close());
3158
+ useEventListener("beforeunload", () => close(), { passive: true });
3090
3159
  tryOnScopeDispose(close);
3091
3160
  }
3092
3161
  const open = () => {
@@ -3099,7 +3168,8 @@ function useWebSocket(url, options = {}) {
3099
3168
  };
3100
3169
  if (immediate)
3101
3170
  open();
3102
- watch(urlRef, open);
3171
+ if (autoConnect)
3172
+ watch(urlRef, open);
3103
3173
  return {
3104
3174
  data,
3105
3175
  status,