@vueuse/shared 14.2.1 → 14.4.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.
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { computed, customRef, effectScope, getCurrentInstance, getCurrentScope, hasInjectionContext, inject, isReactive, isRef, nextTick, onBeforeMount, onBeforeUnmount, onMounted, onScopeDispose, onUnmounted, provide, reactive, readonly, ref, shallowReadonly, shallowRef, toRef as toRef$1, toRefs as toRefs$1, toValue, unref, watch, watchEffect } from "vue";
2
-
3
2
  //#region computedEager/index.ts
4
3
  /**
5
4
  *
@@ -27,7 +26,6 @@ function computedEager(fn, options) {
27
26
  }
28
27
  /** @deprecated use `computedEager` instead */
29
28
  const eagerComputed = computedEager;
30
-
31
29
  //#endregion
32
30
  //#region computedWithControl/index.ts
33
31
  /**
@@ -49,22 +47,22 @@ function computedWithControl(source, fn, options = {}) {
49
47
  flush: "sync",
50
48
  ...options
51
49
  });
52
- const get$1 = typeof fn === "function" ? fn : fn.get;
53
- const set$1 = typeof fn === "function" ? void 0 : fn.set;
50
+ const get = typeof fn === "function" ? fn : fn.get;
51
+ const set = typeof fn === "function" ? void 0 : fn.set;
54
52
  const result = customRef((_track, _trigger) => {
55
53
  track = _track;
56
54
  trigger = _trigger;
57
55
  return {
58
56
  get() {
59
57
  if (dirty) {
60
- v = get$1(v);
58
+ v = get(v);
61
59
  dirty = false;
62
60
  }
63
61
  track();
64
62
  return v;
65
63
  },
66
- set(v$1) {
67
- set$1 === null || set$1 === void 0 || set$1(v$1);
64
+ set(v) {
65
+ set === null || set === void 0 || set(v);
68
66
  }
69
67
  };
70
68
  });
@@ -73,7 +71,44 @@ function computedWithControl(source, fn, options = {}) {
73
71
  }
74
72
  /** @deprecated use `computedWithControl` instead */
75
73
  const controlledComputed = computedWithControl;
76
-
74
+ //#endregion
75
+ //#region createDisposableDirective/index.ts
76
+ /**
77
+ * Utility for authoring disposable directives. Reactive effects created within `mounted` directive hook will be tracked and automatically disposed when directive is unmounted.
78
+ *
79
+ * @see https://vueuse.org/createDisposableDirective
80
+ *
81
+ * @__NO_SIDE_EFFECTS__
82
+ */
83
+ function createDisposableDirective(origin = {}) {
84
+ function isFunc(fn) {
85
+ return typeof fn === "function";
86
+ }
87
+ const normalisedOrigin = isFunc(origin) ? {
88
+ mounted: origin,
89
+ updated: origin
90
+ } : origin;
91
+ const { mounted, unmounted } = normalisedOrigin;
92
+ if (!isFunc(mounted)) return origin;
93
+ const scopeWeakMap = /* @__PURE__ */ new WeakMap();
94
+ return {
95
+ ...normalisedOrigin,
96
+ mounted(el, binding, vNode, prevNode) {
97
+ var _scopeWeakMap$get;
98
+ const scope = (_scopeWeakMap$get = scopeWeakMap.get(el)) !== null && _scopeWeakMap$get !== void 0 ? _scopeWeakMap$get : effectScope();
99
+ scopeWeakMap.set(el, scope);
100
+ scope.run(() => {
101
+ mounted === null || mounted === void 0 || mounted(el, binding, vNode, prevNode);
102
+ });
103
+ },
104
+ unmounted(el, binding, vNode, prevNode) {
105
+ var _scopeWeakMap$get2;
106
+ (_scopeWeakMap$get2 = scopeWeakMap.get(el)) === null || _scopeWeakMap$get2 === void 0 || _scopeWeakMap$get2.stop();
107
+ scopeWeakMap.delete(el);
108
+ if (isFunc(unmounted)) unmounted(el, binding, vNode, prevNode);
109
+ }
110
+ };
111
+ }
77
112
  //#endregion
78
113
  //#region tryOnScopeDispose/index.ts
79
114
  /**
@@ -88,7 +123,6 @@ function tryOnScopeDispose(fn, failSilently) {
88
123
  }
89
124
  return false;
90
125
  }
91
-
92
126
  //#endregion
93
127
  //#region createEventHook/index.ts
94
128
  /**
@@ -122,7 +156,6 @@ function createEventHook() {
122
156
  clear
123
157
  };
124
158
  }
125
-
126
159
  //#endregion
127
160
  //#region createGlobalState/index.ts
128
161
  /**
@@ -145,11 +178,9 @@ function createGlobalState(stateFactory) {
145
178
  return state;
146
179
  });
147
180
  }
148
-
149
181
  //#endregion
150
182
  //#region provideLocal/map.ts
151
183
  const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
152
-
153
184
  //#endregion
154
185
  //#region injectLocal/index.ts
155
186
  /**
@@ -172,7 +203,6 @@ const injectLocal = (...args) => {
172
203
  if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)) return localProvidedStateMap.get(owner)[key];
173
204
  return inject(...args);
174
205
  };
175
-
176
206
  //#endregion
177
207
  //#region provideLocal/index.ts
178
208
  /**
@@ -194,16 +224,8 @@ function provideLocal(key, value) {
194
224
  localProvidedState[key] = value;
195
225
  return provide(key, value);
196
226
  }
197
-
198
227
  //#endregion
199
228
  //#region createInjectionState/index.ts
200
- /**
201
- * Create global state that can be injected into components.
202
- *
203
- * @see https://vueuse.org/createInjectionState
204
- *
205
- * @__NO_SIDE_EFFECTS__
206
- */
207
229
  function createInjectionState(composable, options) {
208
230
  const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
209
231
  const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
@@ -215,7 +237,6 @@ function createInjectionState(composable, options) {
215
237
  const useInjectedState = () => injectLocal(key, defaultValue);
216
238
  return [useProvidingState, useInjectedState];
217
239
  }
218
-
219
240
  //#endregion
220
241
  //#region createRef/index.ts
221
242
  /**
@@ -237,7 +258,6 @@ function createRef(value, deep) {
237
258
  if (deep === true) return ref(value);
238
259
  else return shallowRef(value);
239
260
  }
240
-
241
261
  //#endregion
242
262
  //#region utils/is.ts
243
263
  const isClient = typeof window !== "undefined" && typeof document !== "undefined";
@@ -258,13 +278,12 @@ const rand = (min, max) => {
258
278
  max = Math.floor(max);
259
279
  return Math.floor(Math.random() * (max - min + 1)) + min;
260
280
  };
261
- const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
262
- const isIOS = /* @__PURE__ */ getIsIOS();
281
+ const hasOwn = (val, key) => Object.hasOwn(val, key);
282
+ const isIOS = /* #__PURE__ */ getIsIOS();
263
283
  function getIsIOS() {
264
284
  var _window, _window2, _window3;
265
285
  return isClient && !!((_window = window) === null || _window === void 0 || (_window = _window.navigator) === null || _window === void 0 ? void 0 : _window.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.navigator) === null || _window2 === void 0 ? void 0 : _window2.maxTouchPoints) > 2 && /iPad|Macintosh/.test((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.navigator.userAgent));
266
286
  }
267
-
268
287
  //#endregion
269
288
  //#region toRef/index.ts
270
289
  function toRef(...args) {
@@ -275,12 +294,8 @@ function toRef(...args) {
275
294
  set: noop
276
295
  }))) : ref(r);
277
296
  }
278
-
279
297
  //#endregion
280
298
  //#region utils/filters.ts
281
- /**
282
- * @internal
283
- */
284
299
  function createFilterWrapper(filter, fn) {
285
300
  function wrapper(...args) {
286
301
  return new Promise((resolve, reject) => {
@@ -291,10 +306,15 @@ function createFilterWrapper(filter, fn) {
291
306
  })).then(resolve).catch(reject);
292
307
  });
293
308
  }
309
+ if ("cancel" in filter) Object.assign(wrapper, {
310
+ cancel: filter.cancel,
311
+ flush: filter.flush,
312
+ isPending: filter.isPending
313
+ });
294
314
  return wrapper;
295
315
  }
296
- const bypassFilter = (invoke$1) => {
297
- return invoke$1();
316
+ const bypassFilter = (invoke) => {
317
+ return invoke();
298
318
  };
299
319
  /**
300
320
  * Create an EventFilter that debounce the events
@@ -303,13 +323,15 @@ function debounceFilter(ms, options = {}) {
303
323
  let timer;
304
324
  let maxTimer;
305
325
  let lastRejector = noop;
306
- const _clearTimeout = (timer$1) => {
307
- clearTimeout(timer$1);
326
+ let lastResolve = noop;
327
+ const _pending = shallowRef(false);
328
+ const _clearTimeout = (timer) => {
329
+ clearTimeout(timer);
308
330
  lastRejector();
309
331
  lastRejector = noop;
310
332
  };
311
333
  let lastInvoker;
312
- const filter = (invoke$1) => {
334
+ const handler = (invoke) => {
313
335
  const duration = toValue(ms);
314
336
  const maxDuration = toValue(options.maxWait);
315
337
  if (timer) _clearTimeout(timer);
@@ -318,24 +340,60 @@ function debounceFilter(ms, options = {}) {
318
340
  _clearTimeout(maxTimer);
319
341
  maxTimer = void 0;
320
342
  }
321
- return Promise.resolve(invoke$1());
343
+ _pending.value = false;
344
+ return Promise.resolve(invoke());
322
345
  }
346
+ _pending.value = true;
323
347
  return new Promise((resolve, reject) => {
324
348
  lastRejector = options.rejectOnCancel ? reject : resolve;
325
- lastInvoker = invoke$1;
349
+ lastResolve = resolve;
350
+ lastInvoker = invoke;
326
351
  if (maxDuration && !maxTimer) maxTimer = setTimeout(() => {
327
352
  if (timer) _clearTimeout(timer);
328
353
  maxTimer = void 0;
354
+ _pending.value = false;
329
355
  resolve(lastInvoker());
330
356
  }, maxDuration);
331
357
  timer = setTimeout(() => {
332
358
  if (maxTimer) _clearTimeout(maxTimer);
333
359
  maxTimer = void 0;
334
- resolve(invoke$1());
360
+ _pending.value = false;
361
+ resolve(invoke());
335
362
  }, duration);
336
363
  });
337
364
  };
338
- return filter;
365
+ return Object.assign(handler, {
366
+ cancel: () => {
367
+ if (timer) {
368
+ _clearTimeout(timer);
369
+ timer = void 0;
370
+ }
371
+ if (maxTimer) {
372
+ _clearTimeout(maxTimer);
373
+ maxTimer = void 0;
374
+ }
375
+ _pending.value = false;
376
+ lastResolve = noop;
377
+ },
378
+ flush: () => {
379
+ if (_pending.value) {
380
+ if (timer) {
381
+ clearTimeout(timer);
382
+ timer = void 0;
383
+ }
384
+ if (maxTimer) {
385
+ clearTimeout(maxTimer);
386
+ maxTimer = void 0;
387
+ }
388
+ _pending.value = false;
389
+ const resolve = lastResolve;
390
+ lastRejector = noop;
391
+ lastResolve = noop;
392
+ resolve(lastInvoker());
393
+ }
394
+ },
395
+ isPending: shallowReadonly(_pending)
396
+ });
339
397
  }
340
398
  function throttleFilter(...args) {
341
399
  let lastExec = 0;
@@ -360,23 +418,23 @@ function throttleFilter(...args) {
360
418
  const filter = (_invoke) => {
361
419
  const duration = toValue(ms);
362
420
  const elapsed = Date.now() - lastExec;
363
- const invoke$1 = () => {
421
+ const invoke = () => {
364
422
  return lastValue = _invoke();
365
423
  };
366
424
  clear();
367
425
  if (duration <= 0) {
368
426
  lastExec = Date.now();
369
- return invoke$1();
427
+ return invoke();
370
428
  }
371
429
  if (elapsed > duration) {
372
430
  lastExec = Date.now();
373
- if (leading || !isLeading) invoke$1();
431
+ if (leading || !isLeading) invoke();
374
432
  } else if (trailing) lastValue = new Promise((resolve, reject) => {
375
433
  lastRejector = rejectOnCancel ? reject : resolve;
376
434
  timer = setTimeout(() => {
377
435
  lastExec = Date.now();
378
436
  isLeading = true;
379
- resolve(invoke$1());
437
+ resolve(invoke());
380
438
  clear();
381
439
  }, Math.max(0, duration - elapsed));
382
440
  });
@@ -405,18 +463,17 @@ function pausableFilter(extendFilter = bypassFilter, options = {}) {
405
463
  if (isActive.value) extendFilter(...args);
406
464
  };
407
465
  return {
408
- isActive: readonly(isActive),
466
+ isActive: shallowReadonly(isActive),
409
467
  pause,
410
468
  resume,
411
469
  eventFilter
412
470
  };
413
471
  }
414
-
415
472
  //#endregion
416
473
  //#region utils/general.ts
417
474
  function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
418
475
  return new Promise((resolve, reject) => {
419
- if (throwOnTimeout) setTimeout(() => reject(reason), ms);
476
+ if (throwOnTimeout) setTimeout(reject, ms, reason);
420
477
  else setTimeout(resolve, ms);
421
478
  });
422
479
  }
@@ -494,7 +551,6 @@ function objectEntries(obj) {
494
551
  function toArray(value) {
495
552
  return Array.isArray(value) ? value : [value];
496
553
  }
497
-
498
554
  //#endregion
499
555
  //#region utils/port.ts
500
556
  function cacheStringFunction(fn) {
@@ -509,13 +565,11 @@ const camelizeRE = /-(\w)/g;
509
565
  const camelize = cacheStringFunction((str) => {
510
566
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
511
567
  });
512
-
513
568
  //#endregion
514
569
  //#region utils/vue.ts
515
570
  function getLifeCycleTarget(target) {
516
571
  return target || getCurrentInstance();
517
572
  }
518
-
519
573
  //#endregion
520
574
  //#region createSharedComposable/index.ts
521
575
  /**
@@ -548,13 +602,12 @@ function createSharedComposable(composable) {
548
602
  return state;
549
603
  });
550
604
  }
551
-
552
605
  //#endregion
553
606
  //#region extendRef/index.ts
554
- function extendRef(ref$1, extend, { enumerable = false, unwrap = true } = {}) {
607
+ function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
555
608
  for (const [key, value] of Object.entries(extend)) {
556
609
  if (key === "value") continue;
557
- if (isRef(value) && unwrap) Object.defineProperty(ref$1, key, {
610
+ if (isRef(value) && unwrap) Object.defineProperty(ref, key, {
558
611
  get() {
559
612
  return value.value;
560
613
  },
@@ -563,27 +616,24 @@ function extendRef(ref$1, extend, { enumerable = false, unwrap = true } = {}) {
563
616
  },
564
617
  enumerable
565
618
  });
566
- else Object.defineProperty(ref$1, key, {
619
+ else Object.defineProperty(ref, key, {
567
620
  value,
568
621
  enumerable
569
622
  });
570
623
  }
571
- return ref$1;
624
+ return ref;
572
625
  }
573
-
574
626
  //#endregion
575
627
  //#region get/index.ts
576
628
  function get(obj, key) {
577
629
  if (key == null) return unref(obj);
578
630
  return unref(obj)[key];
579
631
  }
580
-
581
632
  //#endregion
582
633
  //#region isDefined/index.ts
583
634
  function isDefined(v) {
584
635
  return unref(v) != null;
585
636
  }
586
-
587
637
  //#endregion
588
638
  //#region makeDestructurable/index.ts
589
639
  /* @__NO_SIDE_EFFECTS__ */
@@ -603,7 +653,6 @@ function makeDestructurable(obj, arr) {
603
653
  return clone;
604
654
  } else return Object.assign([...arr], obj);
605
655
  }
606
-
607
656
  //#endregion
608
657
  //#region reactify/index.ts
609
658
  /**
@@ -624,7 +673,6 @@ function reactify(fn, options) {
624
673
  }
625
674
  /** @deprecated use `reactify` instead */
626
675
  const createReactiveFn = reactify;
627
-
628
676
  //#endregion
629
677
  //#region reactifyObject/index.ts
630
678
  /**
@@ -647,7 +695,6 @@ function reactifyObject(obj, optionsOrKeys = {}) {
647
695
  return [key, typeof value === "function" ? reactify(value.bind(obj), options) : value];
648
696
  }));
649
697
  }
650
-
651
698
  //#endregion
652
699
  //#region toReactive/index.ts
653
700
  /**
@@ -684,7 +731,6 @@ function toReactive(objectRef) {
684
731
  }
685
732
  }));
686
733
  }
687
-
688
734
  //#endregion
689
735
  //#region reactiveComputed/index.ts
690
736
  /**
@@ -693,7 +739,6 @@ function toReactive(objectRef) {
693
739
  function reactiveComputed(fn) {
694
740
  return toReactive(computed(fn));
695
741
  }
696
-
697
742
  //#endregion
698
743
  //#region reactiveOmit/index.ts
699
744
  /**
@@ -706,7 +751,6 @@ function reactiveOmit(obj, ...keys) {
706
751
  const predicate = flatKeys[0];
707
752
  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]))));
708
753
  }
709
-
710
754
  //#endregion
711
755
  //#region reactivePick/index.ts
712
756
  /**
@@ -719,7 +763,6 @@ function reactivePick(obj, ...keys) {
719
763
  const predicate = flatKeys[0];
720
764
  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)])));
721
765
  }
722
-
723
766
  //#endregion
724
767
  //#region refAutoReset/index.ts
725
768
  /**
@@ -756,7 +799,6 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
756
799
  }
757
800
  /** @deprecated use `refAutoReset` instead */
758
801
  const autoResetRef = refAutoReset;
759
-
760
802
  //#endregion
761
803
  //#region useDebounceFn/index.ts
762
804
  /**
@@ -767,14 +809,11 @@ const autoResetRef = refAutoReset;
767
809
  * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
768
810
  * @param options Options
769
811
  *
770
- * @return A new, debounce, function.
771
- *
772
- * @__NO_SIDE_EFFECTS__
812
+ * @return A new, debounced, function with isPending, cancel, and flush properties.
773
813
  */
774
814
  function useDebounceFn(fn, ms = 200, options = {}) {
775
815
  return createFilterWrapper(debounceFilter(ms, options), fn);
776
816
  }
777
-
778
817
  //#endregion
779
818
  //#region refDebounced/index.ts
780
819
  /**
@@ -794,7 +833,6 @@ function refDebounced(value, ms = 200, options = {}) {
794
833
  const debouncedRef = refDebounced;
795
834
  /** @deprecated use `refDebounced` instead */
796
835
  const useDebounce = refDebounced;
797
-
798
836
  //#endregion
799
837
  //#region refDefault/index.ts
800
838
  /**
@@ -813,7 +851,6 @@ function refDefault(source, defaultValue) {
813
851
  }
814
852
  });
815
853
  }
816
-
817
854
  //#endregion
818
855
  //#region refManualReset/index.ts
819
856
  /**
@@ -845,7 +882,6 @@ function refManualReset(defaultValue) {
845
882
  refValue.reset = reset;
846
883
  return refValue;
847
884
  }
848
-
849
885
  //#endregion
850
886
  //#region useThrottleFn/index.ts
851
887
  /**
@@ -870,7 +906,6 @@ function refManualReset(defaultValue) {
870
906
  function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
871
907
  return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
872
908
  }
873
-
874
909
  //#endregion
875
910
  //#region refThrottled/index.ts
876
911
  /**
@@ -895,7 +930,6 @@ function refThrottled(value, delay = 200, trailing = true, leading = true) {
895
930
  const throttledRef = refThrottled;
896
931
  /** @deprecated use `refThrottled` instead */
897
932
  const useThrottle = refThrottled;
898
-
899
933
  //#endregion
900
934
  //#region refWithControl/index.ts
901
935
  /**
@@ -907,23 +941,23 @@ function refWithControl(initial, options = {}) {
907
941
  let source = initial;
908
942
  let track;
909
943
  let trigger;
910
- const ref$1 = customRef((_track, _trigger) => {
944
+ const ref = customRef((_track, _trigger) => {
911
945
  track = _track;
912
946
  trigger = _trigger;
913
947
  return {
914
948
  get() {
915
- return get$1();
949
+ return get();
916
950
  },
917
951
  set(v) {
918
- set$1(v);
952
+ set(v);
919
953
  }
920
954
  };
921
955
  });
922
- function get$1(tracking = true) {
956
+ function get(tracking = true) {
923
957
  if (tracking) track();
924
958
  return source;
925
959
  }
926
- function set$1(value, triggering = true) {
960
+ function set(value, triggering = true) {
927
961
  var _options$onBeforeChan, _options$onChanged;
928
962
  if (value === source) return;
929
963
  const old = source;
@@ -935,26 +969,26 @@ function refWithControl(initial, options = {}) {
935
969
  /**
936
970
  * Get the value without tracked in the reactivity system
937
971
  */
938
- const untrackedGet = () => get$1(false);
972
+ const untrackedGet = () => get(false);
939
973
  /**
940
974
  * Set the value without triggering the reactivity system
941
975
  */
942
- const silentSet = (v) => set$1(v, false);
976
+ const silentSet = (v) => set(v, false);
943
977
  /**
944
978
  * Get the value without tracked in the reactivity system.
945
979
  *
946
980
  * Alias for `untrackedGet()`
947
981
  */
948
- const peek = () => get$1(false);
982
+ const peek = () => get(false);
949
983
  /**
950
984
  * Set the value without triggering the reactivity system
951
985
  *
952
986
  * Alias for `silentSet(v)`
953
987
  */
954
- const lay = (v) => set$1(v, false);
955
- return extendRef(ref$1, {
956
- get: get$1,
957
- set: set$1,
988
+ const lay = (v) => set(v, false);
989
+ return extendRef(ref, {
990
+ get,
991
+ set,
958
992
  untrackedGet,
959
993
  silentSet,
960
994
  peek,
@@ -963,7 +997,6 @@ function refWithControl(initial, options = {}) {
963
997
  }
964
998
  /** @deprecated use `refWithControl` instead */
965
999
  const controlledRef = refWithControl;
966
-
967
1000
  //#endregion
968
1001
  //#region set/index.ts
969
1002
  /**
@@ -971,27 +1004,25 @@ const controlledRef = refWithControl;
971
1004
  */
972
1005
  function set(...args) {
973
1006
  if (args.length === 2) {
974
- const [ref$1, value] = args;
975
- ref$1.value = value;
1007
+ const [ref, value] = args;
1008
+ ref.value = value;
976
1009
  }
977
1010
  if (args.length === 3) {
978
1011
  const [target, key, value] = args;
979
1012
  target[key] = value;
980
1013
  }
981
1014
  }
982
-
983
1015
  //#endregion
984
1016
  //#region watchWithFilter/index.ts
985
1017
  function watchWithFilter(source, cb, options = {}) {
986
- const { eventFilter = bypassFilter,...watchOptions } = options;
1018
+ const { eventFilter = bypassFilter, ...watchOptions } = options;
987
1019
  return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
988
1020
  }
989
-
990
1021
  //#endregion
991
1022
  //#region watchPausable/index.ts
992
1023
  /** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */
993
1024
  function watchPausable(source, cb, options = {}) {
994
- const { eventFilter: filter, initialState = "active",...watchOptions } = options;
1025
+ const { eventFilter: filter, initialState = "active", ...watchOptions } = options;
995
1026
  const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
996
1027
  return {
997
1028
  stop: watchWithFilter(source, cb, {
@@ -1005,7 +1036,6 @@ function watchPausable(source, cb, options = {}) {
1005
1036
  }
1006
1037
  /** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */
1007
1038
  const pausableWatch = watchPausable;
1008
-
1009
1039
  //#endregion
1010
1040
  //#region syncRef/index.ts
1011
1041
  /**
@@ -1045,7 +1075,6 @@ function syncRef(left, right, ...[options]) {
1045
1075
  };
1046
1076
  return stop;
1047
1077
  }
1048
-
1049
1078
  //#endregion
1050
1079
  //#region syncRefs/index.ts
1051
1080
  /**
@@ -1063,7 +1092,6 @@ function syncRefs(source, targets, options = {}) {
1063
1092
  immediate
1064
1093
  });
1065
1094
  }
1066
-
1067
1095
  //#endregion
1068
1096
  //#region toRefs/index.ts
1069
1097
  /**
@@ -1099,7 +1127,6 @@ function toRefs(objectRef, options = {}) {
1099
1127
  }));
1100
1128
  return result;
1101
1129
  }
1102
-
1103
1130
  //#endregion
1104
1131
  //#region tryOnBeforeMount/index.ts
1105
1132
  /**
@@ -1114,7 +1141,6 @@ function tryOnBeforeMount(fn, sync = true, target) {
1114
1141
  else if (sync) fn();
1115
1142
  else nextTick(fn);
1116
1143
  }
1117
-
1118
1144
  //#endregion
1119
1145
  //#region tryOnBeforeUnmount/index.ts
1120
1146
  /**
@@ -1126,7 +1152,6 @@ function tryOnBeforeMount(fn, sync = true, target) {
1126
1152
  function tryOnBeforeUnmount(fn, target) {
1127
1153
  if (getLifeCycleTarget(target)) onBeforeUnmount(fn, target);
1128
1154
  }
1129
-
1130
1155
  //#endregion
1131
1156
  //#region tryOnMounted/index.ts
1132
1157
  /**
@@ -1141,7 +1166,6 @@ function tryOnMounted(fn, sync = true, target) {
1141
1166
  else if (sync) fn();
1142
1167
  else nextTick(fn);
1143
1168
  }
1144
-
1145
1169
  //#endregion
1146
1170
  //#region tryOnUnmounted/index.ts
1147
1171
  /**
@@ -1153,7 +1177,6 @@ function tryOnMounted(fn, sync = true, target) {
1153
1177
  function tryOnUnmounted(fn, target) {
1154
1178
  if (getLifeCycleTarget(target)) onUnmounted(fn, target);
1155
1179
  }
1156
-
1157
1180
  //#endregion
1158
1181
  //#region until/index.ts
1159
1182
  function createUntil(r, isNot = false) {
@@ -1252,7 +1275,6 @@ function createUntil(r, isNot = false) {
1252
1275
  function until(r) {
1253
1276
  return createUntil(r);
1254
1277
  }
1255
-
1256
1278
  //#endregion
1257
1279
  //#region useArrayDifference/index.ts
1258
1280
  function defaultComparator(value, othVal) {
@@ -1282,7 +1304,6 @@ function useArrayDifference(...args) {
1282
1304
  return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1));
1283
1305
  } else return diff1;
1284
1306
  }
1285
-
1286
1307
  //#endregion
1287
1308
  //#region useArrayEvery/index.ts
1288
1309
  /**
@@ -1299,7 +1320,6 @@ function useArrayDifference(...args) {
1299
1320
  function useArrayEvery(list, fn) {
1300
1321
  return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
1301
1322
  }
1302
-
1303
1323
  //#endregion
1304
1324
  //#region useArrayFilter/index.ts
1305
1325
  /**
@@ -1316,7 +1336,6 @@ function useArrayEvery(list, fn) {
1316
1336
  function useArrayFilter(list, fn) {
1317
1337
  return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
1318
1338
  }
1319
-
1320
1339
  //#endregion
1321
1340
  //#region useArrayFind/index.ts
1322
1341
  /**
@@ -1333,7 +1352,6 @@ function useArrayFilter(list, fn) {
1333
1352
  function useArrayFind(list, fn) {
1334
1353
  return computed(() => toValue(toValue(list).find((element, index, array) => fn(toValue(element), index, array))));
1335
1354
  }
1336
-
1337
1355
  //#endregion
1338
1356
  //#region useArrayFindIndex/index.ts
1339
1357
  /**
@@ -1350,7 +1368,6 @@ function useArrayFind(list, fn) {
1350
1368
  function useArrayFindIndex(list, fn) {
1351
1369
  return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
1352
1370
  }
1353
-
1354
1371
  //#endregion
1355
1372
  //#region useArrayFindLast/index.ts
1356
1373
  function findLast(arr, cb) {
@@ -1371,7 +1388,6 @@ function findLast(arr, cb) {
1371
1388
  function useArrayFindLast(list, fn) {
1372
1389
  return computed(() => toValue(!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))));
1373
1390
  }
1374
-
1375
1391
  //#endregion
1376
1392
  //#region useArrayIncludes/index.ts
1377
1393
  function isArrayIncludesOptions(obj) {
@@ -1399,12 +1415,11 @@ function useArrayIncludes(...args) {
1399
1415
  }
1400
1416
  if (typeof comparator === "string") {
1401
1417
  const key = comparator;
1402
- comparator = (element, value$1) => element[key] === toValue(value$1);
1418
+ comparator = (element, value) => element[key] === toValue(value);
1403
1419
  }
1404
- comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value$1) => element === toValue(value$1));
1420
+ comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value) => element === toValue(value));
1405
1421
  return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))));
1406
1422
  }
1407
-
1408
1423
  //#endregion
1409
1424
  //#region useArrayJoin/index.ts
1410
1425
  /**
@@ -1421,7 +1436,6 @@ function useArrayIncludes(...args) {
1421
1436
  function useArrayJoin(list, separator) {
1422
1437
  return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
1423
1438
  }
1424
-
1425
1439
  //#endregion
1426
1440
  //#region useArrayMap/index.ts
1427
1441
  /**
@@ -1438,7 +1452,6 @@ function useArrayJoin(list, separator) {
1438
1452
  function useArrayMap(list, fn) {
1439
1453
  return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
1440
1454
  }
1441
-
1442
1455
  //#endregion
1443
1456
  //#region useArrayReduce/index.ts
1444
1457
  /**
@@ -1460,7 +1473,6 @@ function useArrayReduce(list, reducer, ...args) {
1460
1473
  return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
1461
1474
  });
1462
1475
  }
1463
-
1464
1476
  //#endregion
1465
1477
  //#region useArraySome/index.ts
1466
1478
  /**
@@ -1477,7 +1489,6 @@ function useArrayReduce(list, reducer, ...args) {
1477
1489
  function useArraySome(list, fn) {
1478
1490
  return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
1479
1491
  }
1480
-
1481
1492
  //#endregion
1482
1493
  //#region useArrayUnique/index.ts
1483
1494
  function uniq(array) {
@@ -1504,7 +1515,6 @@ function useArrayUnique(list, compareFn) {
1504
1515
  return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
1505
1516
  });
1506
1517
  }
1507
-
1508
1518
  //#endregion
1509
1519
  //#region useCounter/index.ts
1510
1520
  /**
@@ -1520,22 +1530,21 @@ function useCounter(initialValue = 0, options = {}) {
1520
1530
  const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } = options;
1521
1531
  const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
1522
1532
  const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
1523
- const get$1 = () => count.value;
1524
- const set$1 = (val) => count.value = Math.max(min, Math.min(max, val));
1533
+ const get = () => count.value;
1534
+ const set = (val) => count.value = Math.max(min, Math.min(max, val));
1525
1535
  const reset = (val = _initialValue) => {
1526
1536
  _initialValue = val;
1527
- return set$1(val);
1537
+ return set(val);
1528
1538
  };
1529
1539
  return {
1530
1540
  count: shallowReadonly(count),
1531
1541
  inc,
1532
1542
  dec,
1533
- get: get$1,
1534
- set: set$1,
1543
+ get,
1544
+ set,
1535
1545
  reset
1536
1546
  };
1537
1547
  }
1538
-
1539
1548
  //#endregion
1540
1549
  //#region useDateFormat/index.ts
1541
1550
  const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
@@ -1640,7 +1649,6 @@ function normalizeDate(date) {
1640
1649
  function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1641
1650
  return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
1642
1651
  }
1643
-
1644
1652
  //#endregion
1645
1653
  //#region useIntervalFn/index.ts
1646
1654
  /**
@@ -1684,7 +1692,6 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1684
1692
  resume
1685
1693
  };
1686
1694
  }
1687
-
1688
1695
  //#endregion
1689
1696
  //#region useInterval/index.ts
1690
1697
  function useInterval(interval = 1e3, options = {}) {
@@ -1705,7 +1712,6 @@ function useInterval(interval = 1e3, options = {}) {
1705
1712
  };
1706
1713
  else return shallowReadonly(counter);
1707
1714
  }
1708
-
1709
1715
  //#endregion
1710
1716
  //#region useLastChanged/index.ts
1711
1717
  function useLastChanged(source, options = {}) {
@@ -1714,7 +1720,6 @@ function useLastChanged(source, options = {}) {
1714
1720
  watch(source, () => ms.value = timestamp(), options);
1715
1721
  return shallowReadonly(ms);
1716
1722
  }
1717
-
1718
1723
  //#endregion
1719
1724
  //#region useTimeoutFn/index.ts
1720
1725
  /**
@@ -1759,7 +1764,6 @@ function useTimeoutFn(cb, interval, options = {}) {
1759
1764
  stop
1760
1765
  };
1761
1766
  }
1762
-
1763
1767
  //#endregion
1764
1768
  //#region useTimeout/index.ts
1765
1769
  function useTimeout(interval = 1e3, options = {}) {
@@ -1772,7 +1776,6 @@ function useTimeout(interval = 1e3, options = {}) {
1772
1776
  };
1773
1777
  else return ready;
1774
1778
  }
1775
-
1776
1779
  //#endregion
1777
1780
  //#region useToNumber/index.ts
1778
1781
  /**
@@ -1790,7 +1793,6 @@ function useToNumber(value, options = {}) {
1790
1793
  return resolved;
1791
1794
  });
1792
1795
  }
1793
-
1794
1796
  //#endregion
1795
1797
  //#region useToString/index.ts
1796
1798
  /**
@@ -1803,7 +1805,6 @@ function useToNumber(value, options = {}) {
1803
1805
  function useToString(value) {
1804
1806
  return computed(() => `${toValue(value)}`);
1805
1807
  }
1806
-
1807
1808
  //#endregion
1808
1809
  //#region useToggle/index.ts
1809
1810
  /**
@@ -1832,7 +1833,6 @@ function useToggle(initialValue = false, options = {}) {
1832
1833
  if (valueIsRef) return toggle;
1833
1834
  else return [_value, toggle];
1834
1835
  }
1835
-
1836
1836
  //#endregion
1837
1837
  //#region watchArray/index.ts
1838
1838
  /**
@@ -1854,16 +1854,15 @@ function watchArray(source, cb, options) {
1854
1854
  }
1855
1855
  if (!found) added.push(obj);
1856
1856
  }
1857
- const removed = oldList.filter((_$1, i) => !oldListRemains[i]);
1857
+ const removed = oldList.filter((_, i) => !oldListRemains[i]);
1858
1858
  cb(newList, oldList, added, removed, onCleanup);
1859
1859
  oldList = [...newList];
1860
1860
  }, options);
1861
1861
  }
1862
-
1863
1862
  //#endregion
1864
1863
  //#region watchAtMost/index.ts
1865
1864
  function watchAtMost(source, cb, options) {
1866
- const { count,...watchOptions } = options;
1865
+ const { count, ...watchOptions } = options;
1867
1866
  const current = shallowRef(0);
1868
1867
  const { stop, resume, pause } = watchWithFilter(source, (...args) => {
1869
1868
  current.value += 1;
@@ -1877,11 +1876,10 @@ function watchAtMost(source, cb, options) {
1877
1876
  pause
1878
1877
  };
1879
1878
  }
1880
-
1881
1879
  //#endregion
1882
1880
  //#region watchDebounced/index.ts
1883
1881
  function watchDebounced(source, cb, options = {}) {
1884
- const { debounce = 0, maxWait = void 0,...watchOptions } = options;
1882
+ const { debounce = 0, maxWait = void 0, ...watchOptions } = options;
1885
1883
  return watchWithFilter(source, cb, {
1886
1884
  ...watchOptions,
1887
1885
  eventFilter: debounceFilter(debounce, { maxWait })
@@ -1889,7 +1887,6 @@ function watchDebounced(source, cb, options = {}) {
1889
1887
  }
1890
1888
  /** @deprecated use `watchDebounced` instead */
1891
1889
  const debouncedWatch = watchDebounced;
1892
-
1893
1890
  //#endregion
1894
1891
  //#region watchDeep/index.ts
1895
1892
  /**
@@ -1903,11 +1900,10 @@ function watchDeep(source, cb, options) {
1903
1900
  deep: true
1904
1901
  });
1905
1902
  }
1906
-
1907
1903
  //#endregion
1908
1904
  //#region watchIgnorable/index.ts
1909
1905
  function watchIgnorable(source, cb, options = {}) {
1910
- const { eventFilter = bypassFilter,...watchOptions } = options;
1906
+ const { eventFilter = bypassFilter, ...watchOptions } = options;
1911
1907
  const filteredCb = createFilterWrapper(eventFilter, cb);
1912
1908
  let ignoreUpdates;
1913
1909
  let ignorePrevAsyncUpdates;
@@ -1960,7 +1956,6 @@ function watchIgnorable(source, cb, options = {}) {
1960
1956
  }
1961
1957
  /** @deprecated use `watchIgnorable` instead */
1962
1958
  const ignorableWatch = watchIgnorable;
1963
-
1964
1959
  //#endregion
1965
1960
  //#region watchImmediate/index.ts
1966
1961
  /**
@@ -1974,7 +1969,6 @@ function watchImmediate(source, cb, options) {
1974
1969
  immediate: true
1975
1970
  });
1976
1971
  }
1977
-
1978
1972
  //#endregion
1979
1973
  //#region watchOnce/index.ts
1980
1974
  /**
@@ -1988,11 +1982,10 @@ function watchOnce(source, cb, options) {
1988
1982
  once: true
1989
1983
  });
1990
1984
  }
1991
-
1992
1985
  //#endregion
1993
1986
  //#region watchThrottled/index.ts
1994
1987
  function watchThrottled(source, cb, options = {}) {
1995
- const { throttle = 0, trailing = true, leading = true,...watchOptions } = options;
1988
+ const { throttle = 0, trailing = true, leading = true, ...watchOptions } = options;
1996
1989
  return watchWithFilter(source, cb, {
1997
1990
  ...watchOptions,
1998
1991
  eventFilter: throttleFilter(throttle, trailing, leading)
@@ -2000,7 +1993,6 @@ function watchThrottled(source, cb, options = {}) {
2000
1993
  }
2001
1994
  /** @deprecated use `watchThrottled` instead */
2002
1995
  const throttledWatch = watchThrottled;
2003
-
2004
1996
  //#endregion
2005
1997
  //#region watchTriggerable/index.ts
2006
1998
  function watchTriggerable(source, cb, options = {}) {
@@ -2022,11 +2014,11 @@ function watchTriggerable(source, cb, options = {}) {
2022
2014
  const res = watchIgnorable(source, _cb, options);
2023
2015
  const { ignoreUpdates } = res;
2024
2016
  const trigger = () => {
2025
- let res$1;
2017
+ let res;
2026
2018
  ignoreUpdates(() => {
2027
- res$1 = _cb(getWatchSources(source), getOldValue(source));
2019
+ res = _cb(getWatchSources(source), getOldValue(source));
2028
2020
  });
2029
- return res$1;
2021
+ return res;
2030
2022
  };
2031
2023
  return {
2032
2024
  ...res,
@@ -2041,14 +2033,8 @@ function getWatchSources(sources) {
2041
2033
  function getOldValue(source) {
2042
2034
  return Array.isArray(source) ? source.map(() => void 0) : void 0;
2043
2035
  }
2044
-
2045
2036
  //#endregion
2046
2037
  //#region whenever/index.ts
2047
- /**
2048
- * Shorthand for watching value to be truthy
2049
- *
2050
- * @see https://vueuse.org/whenever
2051
- */
2052
2038
  function whenever(source, cb, options) {
2053
2039
  const stop = watch(source, (v, ov, onInvalidate) => {
2054
2040
  if (v) {
@@ -2061,6 +2047,5 @@ function whenever(source, cb, options) {
2061
2047
  });
2062
2048
  return stop;
2063
2049
  }
2064
-
2065
2050
  //#endregion
2066
- export { assert, autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, createReactiveFn, createRef, createSharedComposable, createSingletonPromise, debounceFilter, debouncedRef, debouncedWatch, eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, pausableWatch, promiseTimeout, provideLocal, pxValue, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refManualReset, refThrottled, refWithControl, set, syncRef, syncRefs, throttleFilter, throttledRef, throttledWatch, timestamp, toArray, toReactive, toRef, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
2051
+ export { assert, autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, controlledComputed, controlledRef, createDisposableDirective, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, createReactiveFn, createRef, createSharedComposable, createSingletonPromise, debounceFilter, debouncedRef, debouncedWatch, eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, pausableWatch, promiseTimeout, provideLocal, pxValue, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refManualReset, refThrottled, refWithControl, set, syncRef, syncRefs, throttleFilter, throttledRef, throttledWatch, timestamp, toArray, toReactive, toRef, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };