@vueuse/shared 6.8.0 → 7.0.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/index.cjs +47 -46
- package/index.d.ts +51 -33
- package/index.iife.js +47 -46
- package/index.iife.min.js +1 -1
- package/index.mjs +45 -47
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -166,6 +166,12 @@ function createGlobalState(stateFactory) {
|
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
function reactify(fn) {
|
|
170
|
+
return function(...args) {
|
|
171
|
+
return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
169
175
|
function tryOnScopeDispose(fn) {
|
|
170
176
|
if (vueDemi.getCurrentScope()) {
|
|
171
177
|
vueDemi.onScopeDispose(fn);
|
|
@@ -368,6 +374,21 @@ function objectPick(obj, keys, omitUndefined = false) {
|
|
|
368
374
|
}, {});
|
|
369
375
|
}
|
|
370
376
|
|
|
377
|
+
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
378
|
+
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function useDebounce(value, ms = 200, options = {}) {
|
|
382
|
+
if (ms <= 0)
|
|
383
|
+
return value;
|
|
384
|
+
const debounced = vueDemi.ref(value.value);
|
|
385
|
+
const updater = useDebounceFn(() => {
|
|
386
|
+
debounced.value = value.value;
|
|
387
|
+
}, ms, options);
|
|
388
|
+
vueDemi.watch(value, () => updater());
|
|
389
|
+
return debounced;
|
|
390
|
+
}
|
|
391
|
+
|
|
371
392
|
var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
|
|
372
393
|
var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
|
|
373
394
|
var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
|
|
@@ -625,12 +646,6 @@ function pausableWatch(source, cb, options = {}) {
|
|
|
625
646
|
return { stop, pause, resume, isActive };
|
|
626
647
|
}
|
|
627
648
|
|
|
628
|
-
function reactify(fn) {
|
|
629
|
-
return function(...args) {
|
|
630
|
-
return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
|
|
634
649
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
635
650
|
let keys = [];
|
|
636
651
|
if (Array.isArray(optionsOrKeys)) {
|
|
@@ -688,13 +703,22 @@ function syncRef(source, targets, {
|
|
|
688
703
|
} = {}) {
|
|
689
704
|
if (!Array.isArray(targets))
|
|
690
705
|
targets = [targets];
|
|
691
|
-
return vueDemi.watch(source, (newValue) => {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
706
|
+
return vueDemi.watch(source, (newValue) => targets.forEach((target) => target.value = newValue), { flush, deep, immediate });
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
710
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
714
|
+
if (delay <= 0)
|
|
715
|
+
return value;
|
|
716
|
+
const throttled = vueDemi.ref(value.value);
|
|
717
|
+
const updater = useThrottleFn(() => {
|
|
718
|
+
throttled.value = value.value;
|
|
719
|
+
}, delay, trailing, leading);
|
|
720
|
+
vueDemi.watch(value, () => updater());
|
|
721
|
+
return throttled;
|
|
698
722
|
}
|
|
699
723
|
|
|
700
724
|
var __defProp$3 = Object.defineProperty;
|
|
@@ -920,10 +944,14 @@ function until(r) {
|
|
|
920
944
|
}
|
|
921
945
|
}
|
|
922
946
|
|
|
923
|
-
function useCounter(initialValue = 0) {
|
|
947
|
+
function useCounter(initialValue = 0, options = {}) {
|
|
924
948
|
const count = vueDemi.ref(initialValue);
|
|
925
|
-
const
|
|
926
|
-
|
|
949
|
+
const {
|
|
950
|
+
max = Infinity,
|
|
951
|
+
min = -Infinity
|
|
952
|
+
} = options;
|
|
953
|
+
const inc = (delta = 1) => count.value = Math.min(max, count.value + delta);
|
|
954
|
+
const dec = (delta = 1) => count.value = Math.max(min, count.value - delta);
|
|
927
955
|
const get = () => count.value;
|
|
928
956
|
const set = (val) => count.value = val;
|
|
929
957
|
const reset = (val = initialValue) => {
|
|
@@ -933,21 +961,6 @@ function useCounter(initialValue = 0) {
|
|
|
933
961
|
return { count, inc, dec, get, set, reset };
|
|
934
962
|
}
|
|
935
963
|
|
|
936
|
-
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
937
|
-
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
function useDebounce(value, ms = 200, options = {}) {
|
|
941
|
-
if (ms <= 0)
|
|
942
|
-
return value;
|
|
943
|
-
const debounced = vueDemi.ref(value.value);
|
|
944
|
-
const updater = useDebounceFn(() => {
|
|
945
|
-
debounced.value = value.value;
|
|
946
|
-
}, ms, options);
|
|
947
|
-
vueDemi.watch(value, () => updater());
|
|
948
|
-
return debounced;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
964
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
952
965
|
const {
|
|
953
966
|
immediate = true,
|
|
@@ -1023,21 +1036,6 @@ function useLastChanged(source, options = {}) {
|
|
|
1023
1036
|
return ms;
|
|
1024
1037
|
}
|
|
1025
1038
|
|
|
1026
|
-
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
1027
|
-
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
1031
|
-
if (delay <= 0)
|
|
1032
|
-
return value;
|
|
1033
|
-
const throttled = vueDemi.ref(value.value);
|
|
1034
|
-
const updater = useThrottleFn(() => {
|
|
1035
|
-
throttled.value = value.value;
|
|
1036
|
-
}, delay, trailing, leading);
|
|
1037
|
-
vueDemi.watch(value, () => updater());
|
|
1038
|
-
return throttled;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
1039
|
function useTimeoutFn(cb, interval, options = {}) {
|
|
1042
1040
|
const {
|
|
1043
1041
|
immediate = true
|
|
@@ -1177,9 +1175,11 @@ exports.controlledRef = controlledRef;
|
|
|
1177
1175
|
exports.createEventHook = createEventHook;
|
|
1178
1176
|
exports.createFilterWrapper = createFilterWrapper;
|
|
1179
1177
|
exports.createGlobalState = createGlobalState;
|
|
1178
|
+
exports.createReactiveFn = reactify;
|
|
1180
1179
|
exports.createSharedComposable = createSharedComposable;
|
|
1181
1180
|
exports.createSingletonPromise = createSingletonPromise;
|
|
1182
1181
|
exports.debounceFilter = debounceFilter;
|
|
1182
|
+
exports.debouncedRef = useDebounce;
|
|
1183
1183
|
exports.debouncedWatch = debouncedWatch;
|
|
1184
1184
|
exports.eagerComputed = eagerComputed;
|
|
1185
1185
|
exports.extendRef = extendRef;
|
|
@@ -1214,6 +1214,7 @@ exports.refDefault = refDefault;
|
|
|
1214
1214
|
exports.set = set;
|
|
1215
1215
|
exports.syncRef = syncRef;
|
|
1216
1216
|
exports.throttleFilter = throttleFilter;
|
|
1217
|
+
exports.throttledRef = useThrottle;
|
|
1217
1218
|
exports.throttledWatch = throttledWatch;
|
|
1218
1219
|
exports.timestamp = timestamp;
|
|
1219
1220
|
exports.toReactive = toReactive;
|
package/index.d.ts
CHANGED
|
@@ -31,10 +31,14 @@ declare type MaybeRef<T> = T | Ref<T>;
|
|
|
31
31
|
/**
|
|
32
32
|
* A ref that allow to set null or undefined
|
|
33
33
|
*/
|
|
34
|
-
declare type
|
|
34
|
+
declare type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
|
|
35
35
|
get value(): T;
|
|
36
36
|
set value(value: T | null | undefined);
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `RemovableRef`
|
|
40
|
+
*/
|
|
41
|
+
declare type RemoveableRef<T> = RemovableRef<T>;
|
|
38
42
|
/**
|
|
39
43
|
* Make all the nested attributes of an object or array to MaybeRef<T>
|
|
40
44
|
*
|
|
@@ -66,9 +70,9 @@ interface Pausable {
|
|
|
66
70
|
*/
|
|
67
71
|
resume: Fn;
|
|
68
72
|
}
|
|
69
|
-
interface
|
|
73
|
+
interface Stoppable {
|
|
70
74
|
/**
|
|
71
|
-
* A ref indicate whether a
|
|
75
|
+
* A ref indicate whether a stoppable instance is executing
|
|
72
76
|
*/
|
|
73
77
|
isPending: Ref<boolean>;
|
|
74
78
|
/**
|
|
@@ -80,6 +84,10 @@ interface Stopable {
|
|
|
80
84
|
*/
|
|
81
85
|
start: Fn;
|
|
82
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Use `Stoppable`
|
|
89
|
+
*/
|
|
90
|
+
declare type Stopable = Stoppable;
|
|
83
91
|
interface ConfigurableFlush {
|
|
84
92
|
/**
|
|
85
93
|
* Timing for monitoring changes, refer to WatchOptions for more details
|
|
@@ -279,6 +287,18 @@ declare type CreateGlobalStateReturn<T> = () => T;
|
|
|
279
287
|
*/
|
|
280
288
|
declare function createGlobalState<T>(stateFactory: () => T): CreateGlobalStateReturn<T>;
|
|
281
289
|
|
|
290
|
+
declare type Reactify<T> = T extends (...args: infer A) => infer R ? (...args: {
|
|
291
|
+
[K in keyof A]: MaybeRef<A[K]>;
|
|
292
|
+
}) => ComputedRef<R> : never;
|
|
293
|
+
/**
|
|
294
|
+
* Converts plain function into a reactive function.
|
|
295
|
+
* The converted function accepts refs as it's arguments
|
|
296
|
+
* and returns a ComputedRef, with proper typing.
|
|
297
|
+
*
|
|
298
|
+
* @param fn - Source function
|
|
299
|
+
*/
|
|
300
|
+
declare function reactify<T extends Function>(fn: T): Reactify<T>;
|
|
301
|
+
|
|
282
302
|
/**
|
|
283
303
|
* Make a composable function usable with multiple Vue instances.
|
|
284
304
|
*
|
|
@@ -286,6 +306,13 @@ declare function createGlobalState<T>(stateFactory: () => T): CreateGlobalStateR
|
|
|
286
306
|
*/
|
|
287
307
|
declare function createSharedComposable<Fn extends ((...args: any[]) => any)>(composable: Fn): Fn;
|
|
288
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Debounce updates of a ref.
|
|
311
|
+
*
|
|
312
|
+
* @return A new debounced ref.
|
|
313
|
+
*/
|
|
314
|
+
declare function useDebounce<T>(value: Ref<T>, ms?: number, options?: DebounceFilterOptions): Readonly<Ref<T>>;
|
|
315
|
+
|
|
289
316
|
interface DebouncedWatchOptions<Immediate> extends WatchOptions<Immediate> {
|
|
290
317
|
debounce?: MaybeRef<number>;
|
|
291
318
|
}
|
|
@@ -367,18 +394,6 @@ declare function pausableWatch<T extends Readonly<WatchSource<unknown>[]>, Immed
|
|
|
367
394
|
declare function pausableWatch<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): PausableWatchReturn;
|
|
368
395
|
declare function pausableWatch<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): PausableWatchReturn;
|
|
369
396
|
|
|
370
|
-
declare type Reactify<T> = T extends (...args: infer A) => infer R ? (...args: {
|
|
371
|
-
[K in keyof A]: MaybeRef<A[K]>;
|
|
372
|
-
}) => ComputedRef<R> : never;
|
|
373
|
-
/**
|
|
374
|
-
* Converts plain function into a reactive function.
|
|
375
|
-
* The converted function accepts refs as it's arguments
|
|
376
|
-
* and returns a ComputedRef, with proper typing.
|
|
377
|
-
*
|
|
378
|
-
* @param fn - Source function
|
|
379
|
-
*/
|
|
380
|
-
declare function reactify<T extends Function>(fn: T): Reactify<T>;
|
|
381
|
-
|
|
382
397
|
declare type ReactifyNested<T, Keys extends keyof T = keyof T> = {
|
|
383
398
|
[K in Keys]: T[K] extends (...args: any[]) => any ? Reactify<T[K]> : T[K];
|
|
384
399
|
};
|
|
@@ -436,7 +451,18 @@ interface SyncRefOptions extends ConfigurableFlushSync {
|
|
|
436
451
|
* @param source source ref
|
|
437
452
|
* @param targets
|
|
438
453
|
*/
|
|
439
|
-
declare function syncRef<
|
|
454
|
+
declare function syncRef<T>(source: WatchSource<T>, targets: Ref<T> | Ref<T>[], { flush, deep, immediate, }?: SyncRefOptions): vue_demi.WatchStopHandle;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Throttle execution of a function. Especially useful for rate limiting
|
|
458
|
+
* execution of handlers on events like resize and scroll.
|
|
459
|
+
*
|
|
460
|
+
* @param value Ref value to be watched with throttle effect
|
|
461
|
+
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
462
|
+
* @param [trailing=true] if true, update the value again after the delay time is up
|
|
463
|
+
* @param [leading=true] if true, update the value on the leading edge of the ms timeout
|
|
464
|
+
*/
|
|
465
|
+
declare function useThrottle<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
|
|
440
466
|
|
|
441
467
|
interface ThrottledWatchOptions<Immediate> extends WatchOptions<Immediate> {
|
|
442
468
|
throttle?: MaybeRef<number>;
|
|
@@ -552,13 +578,18 @@ interface UntilArrayInstance<T> extends UntilBaseInstance<T> {
|
|
|
552
578
|
declare function until<T extends unknown[]>(r: WatchSource<T> | MaybeRef<T>): UntilArrayInstance<T>;
|
|
553
579
|
declare function until<T>(r: WatchSource<T> | MaybeRef<T>): UntilValueInstance<T>;
|
|
554
580
|
|
|
581
|
+
interface UseCounterOptions {
|
|
582
|
+
min?: number;
|
|
583
|
+
max?: number;
|
|
584
|
+
}
|
|
555
585
|
/**
|
|
556
586
|
* Basic counter with utility functions.
|
|
557
587
|
*
|
|
558
588
|
* @see https://vueuse.org/useCounter
|
|
559
589
|
* @param [initialValue=0]
|
|
590
|
+
* @param {Object} options
|
|
560
591
|
*/
|
|
561
|
-
declare function useCounter(initialValue?: number): {
|
|
592
|
+
declare function useCounter(initialValue?: number, options?: UseCounterOptions): {
|
|
562
593
|
count: vue_demi.Ref<number>;
|
|
563
594
|
inc: (delta?: number) => number;
|
|
564
595
|
dec: (delta?: number) => number;
|
|
@@ -567,8 +598,6 @@ declare function useCounter(initialValue?: number): {
|
|
|
567
598
|
reset: (val?: number) => number;
|
|
568
599
|
};
|
|
569
600
|
|
|
570
|
-
declare function useDebounce<T>(value: Ref<T>, ms?: number, options?: DebounceFilterOptions): Readonly<Ref<T>>;
|
|
571
|
-
|
|
572
601
|
/**
|
|
573
602
|
* Debounce execution of a function.
|
|
574
603
|
*
|
|
@@ -634,17 +663,6 @@ declare function useLastChanged(source: WatchSource, options?: UseLastChangedOpt
|
|
|
634
663
|
declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true>): Ref<number>;
|
|
635
664
|
declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<boolean, number>): Ref<number>;
|
|
636
665
|
|
|
637
|
-
/**
|
|
638
|
-
* Throttle execution of a function. Especially useful for rate limiting
|
|
639
|
-
* execution of handlers on events like resize and scroll.
|
|
640
|
-
*
|
|
641
|
-
* @param value Ref value to be watched with throttle effect
|
|
642
|
-
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
643
|
-
* @param [trailing=true] if true, update the value again after the delay time is up
|
|
644
|
-
* @param [leading=true] if true, update the value on the leading edge of the ms timeout
|
|
645
|
-
*/
|
|
646
|
-
declare function useThrottle<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T>;
|
|
647
|
-
|
|
648
666
|
/**
|
|
649
667
|
* Throttle execution of a function. Especially useful for rate limiting
|
|
650
668
|
* execution of handlers on events like resize and scroll.
|
|
@@ -676,7 +694,7 @@ interface TimeoutFnOptions {
|
|
|
676
694
|
* @param interval
|
|
677
695
|
* @param immediate
|
|
678
696
|
*/
|
|
679
|
-
declare function useTimeoutFn(cb: (...args: unknown[]) => any, interval: MaybeRef<number>, options?: TimeoutFnOptions):
|
|
697
|
+
declare function useTimeoutFn(cb: (...args: unknown[]) => any, interval: MaybeRef<number>, options?: TimeoutFnOptions): Stoppable;
|
|
680
698
|
|
|
681
699
|
interface TimeoutOptions<Controls extends boolean> extends TimeoutFnOptions {
|
|
682
700
|
/**
|
|
@@ -696,7 +714,7 @@ interface TimeoutOptions<Controls extends boolean> extends TimeoutFnOptions {
|
|
|
696
714
|
declare function useTimeout(interval?: number, options?: TimeoutOptions<false>): ComputedRef<boolean>;
|
|
697
715
|
declare function useTimeout(interval: number, options: TimeoutOptions<true>): {
|
|
698
716
|
ready: ComputedRef<boolean>;
|
|
699
|
-
} &
|
|
717
|
+
} & Stoppable;
|
|
700
718
|
|
|
701
719
|
/**
|
|
702
720
|
* A boolean ref with a toggler
|
|
@@ -729,4 +747,4 @@ declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sourc
|
|
|
729
747
|
*/
|
|
730
748
|
declare function whenever<T>(source: WatchSource<T>, cb: WatchCallback, options?: WatchOptions): vue_demi.WatchStopHandle;
|
|
731
749
|
|
|
732
|
-
export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebounceFilterOptions, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseLastChangedOptions, WatchAtMostOptions, WatchAtMostReturn, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
|
|
750
|
+
export { ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DebounceFilterOptions, DebouncedWatchOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnorableWatchReturn, IgnoredUpdater, IntervalFnOptions, IntervalOptions, MapOldSources, MapSources, MaybeRef, Pausable, PausableWatchReturn, Reactify, ReactifyNested, ReactifyObjectOptions, RemovableRef, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, Stoppable, SyncRefOptions, ThrottledWatchOptions, TimeoutFnOptions, TimeoutOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseCounterOptions, UseLastChangedOptions, WatchAtMostOptions, WatchAtMostReturn, WatchWithFilterOptions, and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, useDebounce as debouncedRef, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, useThrottle as throttledRef, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
|
package/index.iife.js
CHANGED
|
@@ -224,6 +224,12 @@
|
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
function reactify(fn) {
|
|
228
|
+
return function(...args) {
|
|
229
|
+
return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
227
233
|
function tryOnScopeDispose(fn) {
|
|
228
234
|
if (vueDemi.getCurrentScope()) {
|
|
229
235
|
vueDemi.onScopeDispose(fn);
|
|
@@ -426,6 +432,21 @@
|
|
|
426
432
|
}, {});
|
|
427
433
|
}
|
|
428
434
|
|
|
435
|
+
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
436
|
+
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function useDebounce(value, ms = 200, options = {}) {
|
|
440
|
+
if (ms <= 0)
|
|
441
|
+
return value;
|
|
442
|
+
const debounced = vueDemi.ref(value.value);
|
|
443
|
+
const updater = useDebounceFn(() => {
|
|
444
|
+
debounced.value = value.value;
|
|
445
|
+
}, ms, options);
|
|
446
|
+
vueDemi.watch(value, () => updater());
|
|
447
|
+
return debounced;
|
|
448
|
+
}
|
|
449
|
+
|
|
429
450
|
var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
|
|
430
451
|
var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
|
|
431
452
|
var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
|
|
@@ -683,12 +704,6 @@
|
|
|
683
704
|
return { stop, pause, resume, isActive };
|
|
684
705
|
}
|
|
685
706
|
|
|
686
|
-
function reactify(fn) {
|
|
687
|
-
return function(...args) {
|
|
688
|
-
return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
|
|
692
707
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
693
708
|
let keys = [];
|
|
694
709
|
if (Array.isArray(optionsOrKeys)) {
|
|
@@ -746,13 +761,22 @@
|
|
|
746
761
|
} = {}) {
|
|
747
762
|
if (!Array.isArray(targets))
|
|
748
763
|
targets = [targets];
|
|
749
|
-
return vueDemi.watch(source, (newValue) => {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
764
|
+
return vueDemi.watch(source, (newValue) => targets.forEach((target) => target.value = newValue), { flush, deep, immediate });
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
768
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
772
|
+
if (delay <= 0)
|
|
773
|
+
return value;
|
|
774
|
+
const throttled = vueDemi.ref(value.value);
|
|
775
|
+
const updater = useThrottleFn(() => {
|
|
776
|
+
throttled.value = value.value;
|
|
777
|
+
}, delay, trailing, leading);
|
|
778
|
+
vueDemi.watch(value, () => updater());
|
|
779
|
+
return throttled;
|
|
756
780
|
}
|
|
757
781
|
|
|
758
782
|
var __defProp$3 = Object.defineProperty;
|
|
@@ -978,10 +1002,14 @@
|
|
|
978
1002
|
}
|
|
979
1003
|
}
|
|
980
1004
|
|
|
981
|
-
function useCounter(initialValue = 0) {
|
|
1005
|
+
function useCounter(initialValue = 0, options = {}) {
|
|
982
1006
|
const count = vueDemi.ref(initialValue);
|
|
983
|
-
const
|
|
984
|
-
|
|
1007
|
+
const {
|
|
1008
|
+
max = Infinity,
|
|
1009
|
+
min = -Infinity
|
|
1010
|
+
} = options;
|
|
1011
|
+
const inc = (delta = 1) => count.value = Math.min(max, count.value + delta);
|
|
1012
|
+
const dec = (delta = 1) => count.value = Math.max(min, count.value - delta);
|
|
985
1013
|
const get = () => count.value;
|
|
986
1014
|
const set = (val) => count.value = val;
|
|
987
1015
|
const reset = (val = initialValue) => {
|
|
@@ -991,21 +1019,6 @@
|
|
|
991
1019
|
return { count, inc, dec, get, set, reset };
|
|
992
1020
|
}
|
|
993
1021
|
|
|
994
|
-
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
995
|
-
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
function useDebounce(value, ms = 200, options = {}) {
|
|
999
|
-
if (ms <= 0)
|
|
1000
|
-
return value;
|
|
1001
|
-
const debounced = vueDemi.ref(value.value);
|
|
1002
|
-
const updater = useDebounceFn(() => {
|
|
1003
|
-
debounced.value = value.value;
|
|
1004
|
-
}, ms, options);
|
|
1005
|
-
vueDemi.watch(value, () => updater());
|
|
1006
|
-
return debounced;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
1022
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1010
1023
|
const {
|
|
1011
1024
|
immediate = true,
|
|
@@ -1081,21 +1094,6 @@
|
|
|
1081
1094
|
return ms;
|
|
1082
1095
|
}
|
|
1083
1096
|
|
|
1084
|
-
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
1085
|
-
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
1089
|
-
if (delay <= 0)
|
|
1090
|
-
return value;
|
|
1091
|
-
const throttled = vueDemi.ref(value.value);
|
|
1092
|
-
const updater = useThrottleFn(() => {
|
|
1093
|
-
throttled.value = value.value;
|
|
1094
|
-
}, delay, trailing, leading);
|
|
1095
|
-
vueDemi.watch(value, () => updater());
|
|
1096
|
-
return throttled;
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
1097
|
function useTimeoutFn(cb, interval, options = {}) {
|
|
1100
1098
|
const {
|
|
1101
1099
|
immediate = true
|
|
@@ -1235,9 +1233,11 @@
|
|
|
1235
1233
|
exports.createEventHook = createEventHook;
|
|
1236
1234
|
exports.createFilterWrapper = createFilterWrapper;
|
|
1237
1235
|
exports.createGlobalState = createGlobalState;
|
|
1236
|
+
exports.createReactiveFn = reactify;
|
|
1238
1237
|
exports.createSharedComposable = createSharedComposable;
|
|
1239
1238
|
exports.createSingletonPromise = createSingletonPromise;
|
|
1240
1239
|
exports.debounceFilter = debounceFilter;
|
|
1240
|
+
exports.debouncedRef = useDebounce;
|
|
1241
1241
|
exports.debouncedWatch = debouncedWatch;
|
|
1242
1242
|
exports.eagerComputed = eagerComputed;
|
|
1243
1243
|
exports.extendRef = extendRef;
|
|
@@ -1272,6 +1272,7 @@
|
|
|
1272
1272
|
exports.set = set;
|
|
1273
1273
|
exports.syncRef = syncRef;
|
|
1274
1274
|
exports.throttleFilter = throttleFilter;
|
|
1275
|
+
exports.throttledRef = useThrottle;
|
|
1275
1276
|
exports.throttledWatch = throttledWatch;
|
|
1276
1277
|
exports.timestamp = timestamp;
|
|
1277
1278
|
exports.toReactive = toReactive;
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i){if(!i.VueDemi){var o={},O=i.Vue;if(O)if(O.version.slice(0,2)==="2."){var m=i.VueCompositionAPI;if(m){for(var g in m)o[g]=m[g];o.isVue2=!0,o.isVue3=!1,o.install=function(){},o.Vue=O,o.Vue2=O,o.version=O.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.")}else if(O.version.slice(0,2)==="3."){for(var g in O)o[g]=O[g];o.isVue2=!1,o.isVue3=!0,o.install=function(){},o.Vue=O,o.Vue2=void 0,o.version=O.version,o.set=function(h,w,b){return Array.isArray(h)?(h.length=Math.max(h.length,w),h.splice(w,1,b),b):(h[w]=b,b)},o.del=function(h,w){if(Array.isArray(h)){h.splice(w,1);return}delete h[w]}}else console.error("[vue-demi] Vue version "+O.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");i.VueDemi=o}})(window),function(i,o){"use strict";function O(...e){return o.computed(()=>e.every(t=>o.unref(t)))}function m(e,t){const r="sync",n=o.watch(e,u=>{t.value=u},{flush:r,immediate:!0}),a=o.watch(t,u=>{e.value=u},{flush:r,immediate:!0});return()=>{n(),a()}}function g(e,t){let r,n,a;const u=o.ref(!0);return o.watch(e,()=>{u.value=!0,a()},{flush:"sync"}),o.customRef((c,l)=>(n=c,a=l,{get(){return u.value&&(r=t(),u.value=!1),n(),r},set(){}}))}function h(e="this function"){if(!o.isVue3)throw new Error(`[VueUse] ${e} is only works on Vue 3.`)}function w(e,t,{enumerable:r=!1,unwrap:n=!0}={}){h();for(const[a,u]of Object.entries(t))a!=="value"&&(o.isRef(u)&&n?Object.defineProperty(e,a,{get(){return u.value},set(c){u.value=c},enumerable:r}):Object.defineProperty(e,a,{value:u,enumerable:r}));return e}function b(e,t={}){let r=e,n,a;const u=o.customRef((s,_)=>(n=s,a=_,{get(){return c()},set(y){l(y)}}));function c(s=!0){return s&&n(),r}function l(s,_=!0){var y,C;if(s===r)return;const P=r;((y=t.onBeforeChange)==null?void 0:y.call(t,s,P))!==!1&&(r=s,(C=t.onChanged)==null||C.call(t,s,P),_&&a())}return w(u,{get:c,set:l,untrackedGet:()=>c(!1),silentSet:s=>l(s,!1),peek:()=>c(!1),lay:s=>l(s,!1)},{enumerable:!0})}function ve(){const e=[],t=a=>{const u=e.indexOf(a);u!==-1&&e.splice(u,1)};return{on:a=>(e.push(a),{off:()=>t(a)}),off:t,trigger:a=>{e.forEach(u=>u(a))}}}function ye(e){let t=!1,r;const n=o.effectScope(!0);return()=>(t||(r=n.run(e),t=!0),r)}function j(e){return o.getCurrentScope()?(o.onScopeDispose(e),!0):!1}function Oe(e){let t=0,r,n;const a=()=>{t-=1,n&&t<=0&&(n.stop(),r=void 0,n=void 0)};return(...u)=>(t+=1,r||(n=o.effectScope(!0),r=n.run(()=>e(...u))),j(a),r)}const A=typeof window!="undefined",he=e=>typeof e!="undefined",we=(e,...t)=>{e||console.warn(...t)},R=Object.prototype.toString,Pe=e=>typeof e=="boolean",ge=e=>typeof e=="function",be=e=>typeof e=="number",me=e=>typeof e=="string",$e=e=>R.call(e)==="[object Object]",Se=e=>typeof window!="undefined"&&R.call(e)==="[object Window]",je=()=>Date.now(),M=()=>+Date.now(),Fe=(e,t,r)=>Math.min(r,Math.max(t,e)),U=()=>{},Ee=(e,t)=>(e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e);function $(e,t){function r(...n){e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})}return r}const F=e=>e();function N(e,t={}){let r,n;return u=>{const c=o.unref(e),l=o.unref(t.maxWait);if(r&&clearTimeout(r),c<=0||l!==void 0&&l<=0)return n&&(clearTimeout(n),n=null),u();l&&!n&&(n=setTimeout(()=>{r&&clearTimeout(r),n=null,u()},l)),r=setTimeout(()=>{n&&clearTimeout(n),n=null,u()},c)}}function W(e,t=!0,r=!0){let n=0,a,u=!r;const c=()=>{a&&(clearTimeout(a),a=void 0)};return p=>{const d=o.unref(e),v=Date.now()-n;if(c(),d<=0)return n=Date.now(),p();v>d?(n=Date.now(),u?u=!1:p()):t&&(a=setTimeout(()=>{n=Date.now(),r||(u=!0),c(),p()},d)),!r&&!a&&(a=setTimeout(()=>u=!0,d))}}function B(e=F){const t=o.ref(!0);function r(){t.value=!1}function n(){t.value=!0}return{isActive:t,pause:r,resume:n,eventFilter:(...u)=>{t.value&&e(...u)}}}function G(e,t=!1,r="Timeout"){return new Promise((n,a)=>{setTimeout(t?()=>a(r):n,e)})}function Te(e){return e}function Ie(e){let t;function r(){return t||(t=e()),t}return r.reset=async()=>{const n=t;t=void 0,n&&await n},r}function Ve(e){return e()}function Ce(e,...t){return t.some(r=>r in e)}function Ae(e,t){var r;if(typeof e=="number")return e+t;const n=((r=e.match(/^-?[0-9]+\.?[0-9]*/))==null?void 0:r[0])||"",a=e.slice(n.length),u=parseFloat(n)+t;return Number.isNaN(u)?e:u+a}function Ne(e,t,r=!1){return t.reduce((n,a)=>(a in e&&(!r||!e[a]===void 0)&&(n[a]=e[a]),n),{})}var L=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,Me=(e,t)=>{var r={};for(var n in e)We.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&L)for(var n of L(e))t.indexOf(n)<0&&Re.call(e,n)&&(r[n]=e[n]);return r};function S(e,t,r={}){const n=r,{eventFilter:a=F}=n,u=Me(n,["eventFilter"]);return o.watch(e,$(a,t),u)}var Ue=Object.defineProperty,Be=Object.defineProperties,Ge=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,q=(e,t,r)=>t in e?Ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Le=(e,t)=>{for(var r in t||(t={}))H.call(t,r)&&q(e,r,t[r]);if(E)for(var r of E(t))z.call(t,r)&&q(e,r,t[r]);return e},He=(e,t)=>Be(e,Ge(t)),ze=(e,t)=>{var r={};for(var n in e)H.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&E)for(var n of E(e))t.indexOf(n)<0&&z.call(e,n)&&(r[n]=e[n]);return r};function qe(e,t,r={}){const n=r,{debounce:a=0}=n,u=ze(n,["debounce"]);return S(e,t,He(Le({},u),{eventFilter:N(a)}))}function Je(e){const t=o.shallowRef();return o.watchSyncEffect(()=>{t.value=e()}),o.readonly(t)}function Qe(e,t){return t==null?o.unref(e):o.unref(e)[t]}var Xe=Object.defineProperty,Ye=Object.defineProperties,Ze=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,X=(e,t,r)=>t in e?Xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ke=(e,t)=>{for(var r in t||(t={}))J.call(t,r)&&X(e,r,t[r]);if(T)for(var r of T(t))Q.call(t,r)&&X(e,r,t[r]);return e},ke=(e,t)=>Ye(e,Ze(t)),De=(e,t)=>{var r={};for(var n in e)J.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&T)for(var n of T(e))t.indexOf(n)<0&&Q.call(e,n)&&(r[n]=e[n]);return r};function xe(e,t,r={}){const n=r,{eventFilter:a=F}=n,u=De(n,["eventFilter"]),c=$(a,t);let l,p,d;if(u.flush==="sync"){const v=o.ref(!1);p=()=>{},l=f=>{v.value=!0,f(),v.value=!1},d=o.watch(e,(...f)=>{v.value||c(...f)},u)}else{const v=[],f=o.ref(0),s=o.ref(0);p=()=>{f.value=s.value},v.push(o.watch(e,()=>{s.value++},ke(Ke({},u),{flush:"sync"}))),l=_=>{const y=s.value;_(),f.value+=s.value-y},v.push(o.watch(e,(..._)=>{const y=f.value>0&&f.value===s.value;f.value=0,s.value=0,!y&&c(..._)},u)),d=()=>{v.forEach(_=>_())}}return{stop:d,ignoreUpdates:l,ignorePrevAsyncUpdates:p}}function et(e){return o.unref(e)!=null}var tt=Object.defineProperty,Y=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,Z=(e,t,r)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ot=(e,t)=>{for(var r in t||(t={}))rt.call(t,r)&&Z(e,r,t[r]);if(Y)for(var r of Y(t))nt.call(t,r)&&Z(e,r,t[r]);return e};function at(e,t){if(typeof Symbol!="undefined"){const r=ot({},e);return Object.defineProperty(r,Symbol.iterator,{enumerable:!1,value(){let n=0;return{next:()=>({value:t[n++],done:n>t.length})}}}),r}else return Object.assign([...t],e)}function it(e){return o.computed(()=>!o.unref(e))}function ut(...e){return o.computed(()=>e.some(t=>o.unref(t)))}var lt=Object.defineProperty,ct=Object.defineProperties,ft=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,D=(e,t,r)=>t in e?lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,st=(e,t)=>{for(var r in t||(t={}))K.call(t,r)&&D(e,r,t[r]);if(I)for(var r of I(t))k.call(t,r)&&D(e,r,t[r]);return e},pt=(e,t)=>ct(e,ft(t)),dt=(e,t)=>{var r={};for(var n in e)K.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&I)for(var n of I(e))t.indexOf(n)<0&&k.call(e,n)&&(r[n]=e[n]);return r};function _t(e,t,r={}){const n=r,{eventFilter:a}=n,u=dt(n,["eventFilter"]),{eventFilter:c,pause:l,resume:p,isActive:d}=B(a);return{stop:S(e,t,pt(st({},u),{eventFilter:c})),pause:l,resume:p,isActive:d}}function x(e){return function(...t){return o.computed(()=>e.apply(this,t.map(r=>o.unref(r))))}}function vt(e,t={}){let r=[];if(Array.isArray(t))r=t;else{const{includeOwnProperties:n=!0}=t;r.push(...Object.keys(e)),n&&r.push(...Object.getOwnPropertyNames(e))}return Object.fromEntries(r.map(n=>{const a=e[n];return[n,typeof a=="function"?x(a.bind(e)):a]}))}function yt(e,...t){return o.reactive(Object.fromEntries(t.map(r=>[r,o.toRef(e,r)])))}function Ot(e,t){return o.computed({get(){var r;return(r=e.value)!=null?r:t},set(r){e.value=r}})}function ht(...e){if(e.length===2){const[t,r]=e;t.value=r}if(e.length===3)if(o.isVue2)o.set(...e);else{const[t,r,n]=e;t[r]=n}}function wt(e,t,{flush:r="sync",deep:n=!1,immediate:a=!0}={}){return Array.isArray(t)||(t=[t]),o.watch(e,u=>{t.forEach(c=>c.value=u)},{flush:r,deep:n,immediate:a})}var Pt=Object.defineProperty,gt=Object.defineProperties,bt=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable,re=(e,t,r)=>t in e?Pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,mt=(e,t)=>{for(var r in t||(t={}))ee.call(t,r)&&re(e,r,t[r]);if(V)for(var r of V(t))te.call(t,r)&&re(e,r,t[r]);return e},$t=(e,t)=>gt(e,bt(t)),St=(e,t)=>{var r={};for(var n in e)ee.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&V)for(var n of V(e))t.indexOf(n)<0&&te.call(e,n)&&(r[n]=e[n]);return r};function jt(e,t,r={}){const n=r,{throttle:a=0,trailing:u=!0,leading:c=!0}=n,l=St(n,["throttle","trailing","leading"]);return S(e,t,$t(mt({},l),{eventFilter:W(a,u,c)}))}function Ft(e){if(!o.isRef(e))return o.reactive(e);const t=new Proxy({},{get(r,n,a){return Reflect.get(e.value,n,a)},set(r,n,a){return e.value[n]=a,!0},deleteProperty(r,n){return Reflect.deleteProperty(e.value,n)},has(r,n){return Reflect.has(e.value,n)},ownKeys(){return Object.keys(e.value)},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}}});return o.reactive(t)}var Et=Object.defineProperty,Tt=Object.defineProperties,It=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Vt=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable,oe=(e,t,r)=>t in e?Et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,At=(e,t)=>{for(var r in t||(t={}))Vt.call(t,r)&&oe(e,r,t[r]);if(ne)for(var r of ne(t))Ct.call(t,r)&&oe(e,r,t[r]);return e},Nt=(e,t)=>Tt(e,It(t));function Wt(e){if(!o.isRef(e))return o.toRefs(e);const t=Array.isArray(e.value)?new Array(e.value.length):{};for(const r in e.value)t[r]=o.customRef(()=>({get(){return e.value[r]},set(n){if(Array.isArray(e.value)){const a=[...e.value];a[r]=n,e.value=a}else e.value=Nt(At({},e.value),{[r]:n})}}));return t}function Rt(e){o.getCurrentInstance()&&o.onBeforeUnmount(e)}function Mt(e,t=!0){o.getCurrentInstance()?o.onMounted(e):t?e():o.nextTick(e)}function Ut(e){o.getCurrentInstance()&&o.onUnmounted(e)}function Bt(e){let t=!1;function r(f,{flush:s="sync",deep:_=!1,timeout:y,throwOnTimeout:C}={}){let P=null;const _e=[new Promise(ur=>{P=o.watch(e,lr=>{f(lr)===!t&&(P==null||P(),ur())},{flush:s,deep:_,immediate:!0})})];return y&&_e.push(G(y,C).finally(()=>{P==null||P()})),Promise.race(_e)}function n(f,s){return r(_=>_===o.unref(f),s)}function a(f){return r(s=>Boolean(s),f)}function u(f){return n(null,f)}function c(f){return n(void 0,f)}function l(f){return r(Number.isNaN,f)}function p(f,s){return r(_=>{const y=Array.from(_);return y.includes(f)||y.includes(o.unref(f))},s)}function d(f){return v(1,f)}function v(f=1,s){let _=-1;return r(()=>(_+=1,_>=f),s)}return Array.isArray(o.unref(e))?{toMatch:r,toContains:p,changed:d,changedTimes:v,get not(){return t=!t,this}}:{toMatch:r,toBe:n,toBeTruthy:a,toBeNull:u,toBeNaN:l,toBeUndefined:c,changed:d,changedTimes:v,get not(){return t=!t,this}}}function Gt(e=0){const t=o.ref(e),r=(l=1)=>t.value+=l,n=(l=1)=>t.value-=l,a=()=>t.value,u=l=>t.value=l;return{count:t,inc:r,dec:n,get:a,set:u,reset:(l=e)=>(e=l,u(l))}}function ae(e,t=200,r={}){return $(N(t,r),e)}function Lt(e,t=200,r={}){if(t<=0)return e;const n=o.ref(e.value),a=ae(()=>{n.value=e.value},t,r);return o.watch(e,()=>a()),n}function ie(e,t=1e3,r={}){const{immediate:n=!0,immediateCallback:a=!1}=r;let u=null;const c=o.ref(!1);function l(){u&&(clearInterval(u),u=null)}function p(){c.value=!1,l()}function d(){t<=0||(c.value=!0,a&&e(),l(),u=setInterval(e,t))}return n&&A&&d(),j(p),{isActive:c,pause:p,resume:d}}var Ht=Object.defineProperty,ue=Object.getOwnPropertySymbols,zt=Object.prototype.hasOwnProperty,qt=Object.prototype.propertyIsEnumerable,le=(e,t,r)=>t in e?Ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Jt=(e,t)=>{for(var r in t||(t={}))zt.call(t,r)&&le(e,r,t[r]);if(ue)for(var r of ue(t))qt.call(t,r)&&le(e,r,t[r]);return e};function Qt(e=1e3,t={}){const{controls:r=!1,immediate:n=!0}=t,a=o.ref(0),u=ie(()=>a.value+=1,e,{immediate:n});return r?Jt({counter:a},u):a}function Xt(e,t={}){var r;const n=o.ref((r=t.initialValue)!=null?r:null);return o.watch(e,()=>n.value=M(),t),n}function ce(e,t=200,r=!0,n=!0){return $(W(t,r,n),e)}function Yt(e,t=200,r=!0,n=!0){if(t<=0)return e;const a=o.ref(e.value),u=ce(()=>{a.value=e.value},t,r,n);return o.watch(e,()=>u()),a}function fe(e,t,r={}){const{immediate:n=!0}=r,a=o.ref(!1);let u=null;function c(){u&&(clearTimeout(u),u=null)}function l(){a.value=!1,c()}function p(...d){c(),a.value=!0,u=setTimeout(()=>{a.value=!1,u=null,e(...d)},o.unref(t))}return n&&(a.value=!0,A&&p()),j(l),{isPending:a,start:p,stop:l}}var Zt=Object.defineProperty,se=Object.getOwnPropertySymbols,Kt=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable,pe=(e,t,r)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Dt=(e,t)=>{for(var r in t||(t={}))Kt.call(t,r)&&pe(e,r,t[r]);if(se)for(var r of se(t))kt.call(t,r)&&pe(e,r,t[r]);return e};function xt(e=1e3,t={}){const{controls:r=!1}=t,n=fe(U,e,t),a=o.computed(()=>!n.isPending.value);return r?Dt({ready:a},n):a}function er(e=!1){if(o.isRef(e))return t=>{e.value=typeof t=="boolean"?t:!e.value};{const t=o.ref(e);return[t,n=>{t.value=typeof n=="boolean"?n:!t.value}]}}var de=Object.getOwnPropertySymbols,tr=Object.prototype.hasOwnProperty,rr=Object.prototype.propertyIsEnumerable,nr=(e,t)=>{var r={};for(var n in e)tr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&de)for(var n of de(e))t.indexOf(n)<0&&rr.call(e,n)&&(r[n]=e[n]);return r};function or(e,t,r){const n=r,{count:a}=n,u=nr(n,["count"]),c=o.ref(0),l=S(e,(...p)=>{c.value+=1,c.value>=o.unref(a)&&l(),t(...p)},u);return{count:c,stop:l}}function ar(e,t,r){const n=o.watch(e,(...a)=>(n(),t(...a)),r)}function ir(e,t,r){return o.watch(e,(n,a,u)=>{n&&t(n,a,u)},r)}i.and=O,i.assert=we,i.biSyncRef=m,i.bypassFilter=F,i.clamp=Fe,i.containsProp=Ce,i.controlledComputed=g,i.controlledRef=b,i.createEventHook=ve,i.createFilterWrapper=$,i.createGlobalState=ye,i.createSharedComposable=Oe,i.createSingletonPromise=Ie,i.debounceFilter=N,i.debouncedWatch=qe,i.eagerComputed=Je,i.extendRef=w,i.get=Qe,i.identity=Te,i.ignorableWatch=xe,i.increaseWithUnit=Ae,i.invoke=Ve,i.isBoolean=Pe,i.isClient=A,i.isDef=he,i.isDefined=et,i.isFunction=ge,i.isNumber=be,i.isObject=$e,i.isString=me,i.isWindow=Se,i.makeDestructurable=at,i.noop=U,i.not=it,i.now=je,i.objectPick=Ne,i.or=ut,i.pausableFilter=B,i.pausableWatch=_t,i.promiseTimeout=G,i.rand=Ee,i.reactify=x,i.reactifyObject=vt,i.reactivePick=yt,i.refDefault=Ot,i.set=ht,i.syncRef=wt,i.throttleFilter=W,i.throttledWatch=jt,i.timestamp=M,i.toReactive=Ft,i.toRefs=Wt,i.tryOnBeforeUnmount=Rt,i.tryOnMounted=Mt,i.tryOnScopeDispose=j,i.tryOnUnmounted=Ut,i.until=Bt,i.useCounter=Gt,i.useDebounce=Lt,i.useDebounceFn=ae,i.useInterval=Qt,i.useIntervalFn=ie,i.useLastChanged=Xt,i.useThrottle=Yt,i.useThrottleFn=ce,i.useTimeout=xt,i.useTimeoutFn=fe,i.useToggle=er,i.watchAtMost=or,i.watchOnce=ar,i.watchWithFilter=S,i.whenever=ir,Object.defineProperty(i,"__esModule",{value:!0})}(this.VueUse=this.VueUse||{},VueDemi);
|
|
1
|
+
(function(i){if(!i.VueDemi){var o={},O=i.Vue;if(O)if(O.version.slice(0,2)==="2."){var b=i.VueCompositionAPI;if(b){for(var g in b)o[g]=b[g];o.isVue2=!0,o.isVue3=!1,o.install=function(){},o.Vue=O,o.Vue2=O,o.version=O.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.")}else if(O.version.slice(0,2)==="3."){for(var g in O)o[g]=O[g];o.isVue2=!1,o.isVue3=!0,o.install=function(){},o.Vue=O,o.Vue2=void 0,o.version=O.version,o.set=function(h,w,m){return Array.isArray(h)?(h.length=Math.max(h.length,w),h.splice(w,1,m),m):(h[w]=m,m)},o.del=function(h,w){if(Array.isArray(h)){h.splice(w,1);return}delete h[w]}}else console.error("[vue-demi] Vue version "+O.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");i.VueDemi=o}})(window),function(i,o){"use strict";function O(...e){return o.computed(()=>e.every(t=>o.unref(t)))}function b(e,t){const r="sync",n=o.watch(e,u=>{t.value=u},{flush:r,immediate:!0}),a=o.watch(t,u=>{e.value=u},{flush:r,immediate:!0});return()=>{n(),a()}}function g(e,t){let r,n,a;const u=o.ref(!0);return o.watch(e,()=>{u.value=!0,a()},{flush:"sync"}),o.customRef((l,c)=>(n=l,a=c,{get(){return u.value&&(r=t(),u.value=!1),n(),r},set(){}}))}function h(e="this function"){if(!o.isVue3)throw new Error(`[VueUse] ${e} is only works on Vue 3.`)}function w(e,t,{enumerable:r=!1,unwrap:n=!0}={}){h();for(const[a,u]of Object.entries(t))a!=="value"&&(o.isRef(u)&&n?Object.defineProperty(e,a,{get(){return u.value},set(l){u.value=l},enumerable:r}):Object.defineProperty(e,a,{value:u,enumerable:r}));return e}function m(e,t={}){let r=e,n,a;const u=o.customRef((s,v)=>(n=s,a=v,{get(){return l()},set(y){c(y)}}));function l(s=!0){return s&&n(),r}function c(s,v=!0){var y,C;if(s===r)return;const P=r;((y=t.onBeforeChange)==null?void 0:y.call(t,s,P))!==!1&&(r=s,(C=t.onChanged)==null||C.call(t,s,P),v&&a())}return w(u,{get:l,set:c,untrackedGet:()=>l(!1),silentSet:s=>c(s,!1),peek:()=>l(!1),lay:s=>c(s,!1)},{enumerable:!0})}function Oe(){const e=[],t=a=>{const u=e.indexOf(a);u!==-1&&e.splice(u,1)};return{on:a=>(e.push(a),{off:()=>t(a)}),off:t,trigger:a=>{e.forEach(u=>u(a))}}}function he(e){let t=!1,r;const n=o.effectScope(!0);return()=>(t||(r=n.run(e),t=!0),r)}function A(e){return function(...t){return o.computed(()=>e.apply(this,t.map(r=>o.unref(r))))}}function j(e){return o.getCurrentScope()?(o.onScopeDispose(e),!0):!1}function we(e){let t=0,r,n;const a=()=>{t-=1,n&&t<=0&&(n.stop(),r=void 0,n=void 0)};return(...u)=>(t+=1,r||(n=o.effectScope(!0),r=n.run(()=>e(...u))),j(a),r)}const N=typeof window!="undefined",Pe=e=>typeof e!="undefined",ge=(e,...t)=>{e||console.warn(...t)},M=Object.prototype.toString,me=e=>typeof e=="boolean",be=e=>typeof e=="function",$e=e=>typeof e=="number",Se=e=>typeof e=="string",je=e=>M.call(e)==="[object Object]",Fe=e=>typeof window!="undefined"&&M.call(e)==="[object Window]",Ie=()=>Date.now(),U=()=>+Date.now(),Ee=(e,t,r)=>Math.min(r,Math.max(t,e)),B=()=>{},Te=(e,t)=>(e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e);function $(e,t){function r(...n){e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})}return r}const F=e=>e();function R(e,t={}){let r,n;return u=>{const l=o.unref(e),c=o.unref(t.maxWait);if(r&&clearTimeout(r),l<=0||c!==void 0&&c<=0)return n&&(clearTimeout(n),n=null),u();c&&!n&&(n=setTimeout(()=>{r&&clearTimeout(r),n=null,u()},c)),r=setTimeout(()=>{n&&clearTimeout(n),n=null,u()},l)}}function W(e,t=!0,r=!0){let n=0,a,u=!r;const l=()=>{a&&(clearTimeout(a),a=void 0)};return d=>{const _=o.unref(e),p=Date.now()-n;if(l(),_<=0)return n=Date.now(),d();p>_?(n=Date.now(),u?u=!1:d()):t&&(a=setTimeout(()=>{n=Date.now(),r||(u=!0),l(),d()},_)),!r&&!a&&(a=setTimeout(()=>u=!0,_))}}function G(e=F){const t=o.ref(!0);function r(){t.value=!1}function n(){t.value=!0}return{isActive:t,pause:r,resume:n,eventFilter:(...u)=>{t.value&&e(...u)}}}function L(e,t=!1,r="Timeout"){return new Promise((n,a)=>{setTimeout(t?()=>a(r):n,e)})}function Ve(e){return e}function Ce(e){let t;function r(){return t||(t=e()),t}return r.reset=async()=>{const n=t;t=void 0,n&&await n},r}function Ae(e){return e()}function Ne(e,...t){return t.some(r=>r in e)}function Re(e,t){var r;if(typeof e=="number")return e+t;const n=((r=e.match(/^-?[0-9]+\.?[0-9]*/))==null?void 0:r[0])||"",a=e.slice(n.length),u=parseFloat(n)+t;return Number.isNaN(u)?e:u+a}function We(e,t,r=!1){return t.reduce((n,a)=>(a in e&&(!r||!e[a]===void 0)&&(n[a]=e[a]),n),{})}function H(e,t=200,r={}){return $(R(t,r),e)}function z(e,t=200,r={}){if(t<=0)return e;const n=o.ref(e.value),a=H(()=>{n.value=e.value},t,r);return o.watch(e,()=>a()),n}var q=Object.getOwnPropertySymbols,Me=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable,Be=(e,t)=>{var r={};for(var n in e)Me.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&q)for(var n of q(e))t.indexOf(n)<0&&Ue.call(e,n)&&(r[n]=e[n]);return r};function S(e,t,r={}){const n=r,{eventFilter:a=F}=n,u=Be(n,["eventFilter"]);return o.watch(e,$(a,t),u)}var Ge=Object.defineProperty,Le=Object.defineProperties,He=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,X=(e,t,r)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ze=(e,t)=>{for(var r in t||(t={}))J.call(t,r)&&X(e,r,t[r]);if(I)for(var r of I(t))Q.call(t,r)&&X(e,r,t[r]);return e},qe=(e,t)=>Le(e,He(t)),Je=(e,t)=>{var r={};for(var n in e)J.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&I)for(var n of I(e))t.indexOf(n)<0&&Q.call(e,n)&&(r[n]=e[n]);return r};function Qe(e,t,r={}){const n=r,{debounce:a=0}=n,u=Je(n,["debounce"]);return S(e,t,qe(ze({},u),{eventFilter:R(a)}))}function Xe(e){const t=o.shallowRef();return o.watchSyncEffect(()=>{t.value=e()}),o.readonly(t)}function Ye(e,t){return t==null?o.unref(e):o.unref(e)[t]}var Ze=Object.defineProperty,Ke=Object.defineProperties,ke=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,K=(e,t,r)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,De=(e,t)=>{for(var r in t||(t={}))Y.call(t,r)&&K(e,r,t[r]);if(E)for(var r of E(t))Z.call(t,r)&&K(e,r,t[r]);return e},xe=(e,t)=>Ke(e,ke(t)),et=(e,t)=>{var r={};for(var n in e)Y.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&E)for(var n of E(e))t.indexOf(n)<0&&Z.call(e,n)&&(r[n]=e[n]);return r};function tt(e,t,r={}){const n=r,{eventFilter:a=F}=n,u=et(n,["eventFilter"]),l=$(a,t);let c,d,_;if(u.flush==="sync"){const p=o.ref(!1);d=()=>{},c=f=>{p.value=!0,f(),p.value=!1},_=o.watch(e,(...f)=>{p.value||l(...f)},u)}else{const p=[],f=o.ref(0),s=o.ref(0);d=()=>{f.value=s.value},p.push(o.watch(e,()=>{s.value++},xe(De({},u),{flush:"sync"}))),c=v=>{const y=s.value;v(),f.value+=s.value-y},p.push(o.watch(e,(...v)=>{const y=f.value>0&&f.value===s.value;f.value=0,s.value=0,!y&&l(...v)},u)),_=()=>{p.forEach(v=>v())}}return{stop:_,ignoreUpdates:c,ignorePrevAsyncUpdates:d}}function rt(e){return o.unref(e)!=null}var nt=Object.defineProperty,k=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,D=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,it=(e,t)=>{for(var r in t||(t={}))ot.call(t,r)&&D(e,r,t[r]);if(k)for(var r of k(t))at.call(t,r)&&D(e,r,t[r]);return e};function ut(e,t){if(typeof Symbol!="undefined"){const r=it({},e);return Object.defineProperty(r,Symbol.iterator,{enumerable:!1,value(){let n=0;return{next:()=>({value:t[n++],done:n>t.length})}}}),r}else return Object.assign([...t],e)}function lt(e){return o.computed(()=>!o.unref(e))}function ct(...e){return o.computed(()=>e.some(t=>o.unref(t)))}var ft=Object.defineProperty,st=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable,te=(e,t,r)=>t in e?ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,dt=(e,t)=>{for(var r in t||(t={}))x.call(t,r)&&te(e,r,t[r]);if(T)for(var r of T(t))ee.call(t,r)&&te(e,r,t[r]);return e},_t=(e,t)=>st(e,pt(t)),vt=(e,t)=>{var r={};for(var n in e)x.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&T)for(var n of T(e))t.indexOf(n)<0&&ee.call(e,n)&&(r[n]=e[n]);return r};function yt(e,t,r={}){const n=r,{eventFilter:a}=n,u=vt(n,["eventFilter"]),{eventFilter:l,pause:c,resume:d,isActive:_}=G(a);return{stop:S(e,t,_t(dt({},u),{eventFilter:l})),pause:c,resume:d,isActive:_}}function Ot(e,t={}){let r=[];if(Array.isArray(t))r=t;else{const{includeOwnProperties:n=!0}=t;r.push(...Object.keys(e)),n&&r.push(...Object.getOwnPropertyNames(e))}return Object.fromEntries(r.map(n=>{const a=e[n];return[n,typeof a=="function"?A(a.bind(e)):a]}))}function ht(e,...t){return o.reactive(Object.fromEntries(t.map(r=>[r,o.toRef(e,r)])))}function wt(e,t){return o.computed({get(){var r;return(r=e.value)!=null?r:t},set(r){e.value=r}})}function Pt(...e){if(e.length===2){const[t,r]=e;t.value=r}if(e.length===3)if(o.isVue2)o.set(...e);else{const[t,r,n]=e;t[r]=n}}function gt(e,t,{flush:r="sync",deep:n=!1,immediate:a=!0}={}){return Array.isArray(t)||(t=[t]),o.watch(e,u=>t.forEach(l=>l.value=u),{flush:r,deep:n,immediate:a})}function re(e,t=200,r=!0,n=!0){return $(W(t,r,n),e)}function ne(e,t=200,r=!0,n=!0){if(t<=0)return e;const a=o.ref(e.value),u=re(()=>{a.value=e.value},t,r,n);return o.watch(e,()=>u()),a}var mt=Object.defineProperty,bt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,oe=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable,ie=(e,t,r)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,St=(e,t)=>{for(var r in t||(t={}))oe.call(t,r)&&ie(e,r,t[r]);if(V)for(var r of V(t))ae.call(t,r)&&ie(e,r,t[r]);return e},jt=(e,t)=>bt(e,$t(t)),Ft=(e,t)=>{var r={};for(var n in e)oe.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&V)for(var n of V(e))t.indexOf(n)<0&&ae.call(e,n)&&(r[n]=e[n]);return r};function It(e,t,r={}){const n=r,{throttle:a=0,trailing:u=!0,leading:l=!0}=n,c=Ft(n,["throttle","trailing","leading"]);return S(e,t,jt(St({},c),{eventFilter:W(a,u,l)}))}function Et(e){if(!o.isRef(e))return o.reactive(e);const t=new Proxy({},{get(r,n,a){return Reflect.get(e.value,n,a)},set(r,n,a){return e.value[n]=a,!0},deleteProperty(r,n){return Reflect.deleteProperty(e.value,n)},has(r,n){return Reflect.has(e.value,n)},ownKeys(){return Object.keys(e.value)},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}}});return o.reactive(t)}var Tt=Object.defineProperty,Vt=Object.defineProperties,Ct=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Nt=Object.prototype.propertyIsEnumerable,le=(e,t,r)=>t in e?Tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Rt=(e,t)=>{for(var r in t||(t={}))At.call(t,r)&&le(e,r,t[r]);if(ue)for(var r of ue(t))Nt.call(t,r)&&le(e,r,t[r]);return e},Wt=(e,t)=>Vt(e,Ct(t));function Mt(e){if(!o.isRef(e))return o.toRefs(e);const t=Array.isArray(e.value)?new Array(e.value.length):{};for(const r in e.value)t[r]=o.customRef(()=>({get(){return e.value[r]},set(n){if(Array.isArray(e.value)){const a=[...e.value];a[r]=n,e.value=a}else e.value=Wt(Rt({},e.value),{[r]:n})}}));return t}function Ut(e){o.getCurrentInstance()&&o.onBeforeUnmount(e)}function Bt(e,t=!0){o.getCurrentInstance()?o.onMounted(e):t?e():o.nextTick(e)}function Gt(e){o.getCurrentInstance()&&o.onUnmounted(e)}function Lt(e){let t=!1;function r(f,{flush:s="sync",deep:v=!1,timeout:y,throwOnTimeout:C}={}){let P=null;const ye=[new Promise(ur=>{P=o.watch(e,lr=>{f(lr)===!t&&(P==null||P(),ur())},{flush:s,deep:v,immediate:!0})})];return y&&ye.push(L(y,C).finally(()=>{P==null||P()})),Promise.race(ye)}function n(f,s){return r(v=>v===o.unref(f),s)}function a(f){return r(s=>Boolean(s),f)}function u(f){return n(null,f)}function l(f){return n(void 0,f)}function c(f){return r(Number.isNaN,f)}function d(f,s){return r(v=>{const y=Array.from(v);return y.includes(f)||y.includes(o.unref(f))},s)}function _(f){return p(1,f)}function p(f=1,s){let v=-1;return r(()=>(v+=1,v>=f),s)}return Array.isArray(o.unref(e))?{toMatch:r,toContains:d,changed:_,changedTimes:p,get not(){return t=!t,this}}:{toMatch:r,toBe:n,toBeTruthy:a,toBeNull:u,toBeNaN:c,toBeUndefined:l,changed:_,changedTimes:p,get not(){return t=!t,this}}}function Ht(e=0,t={}){const r=o.ref(e),{max:n=1/0,min:a=-1/0}=t,u=(p=1)=>r.value=Math.min(n,r.value+p),l=(p=1)=>r.value=Math.max(a,r.value-p),c=()=>r.value,d=p=>r.value=p;return{count:r,inc:u,dec:l,get:c,set:d,reset:(p=e)=>(e=p,d(p))}}function ce(e,t=1e3,r={}){const{immediate:n=!0,immediateCallback:a=!1}=r;let u=null;const l=o.ref(!1);function c(){u&&(clearInterval(u),u=null)}function d(){l.value=!1,c()}function _(){t<=0||(l.value=!0,a&&e(),c(),u=setInterval(e,t))}return n&&N&&_(),j(d),{isActive:l,pause:d,resume:_}}var zt=Object.defineProperty,fe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,se=(e,t,r)=>t in e?zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Qt=(e,t)=>{for(var r in t||(t={}))qt.call(t,r)&&se(e,r,t[r]);if(fe)for(var r of fe(t))Jt.call(t,r)&&se(e,r,t[r]);return e};function Xt(e=1e3,t={}){const{controls:r=!1,immediate:n=!0}=t,a=o.ref(0),u=ce(()=>a.value+=1,e,{immediate:n});return r?Qt({counter:a},u):a}function Yt(e,t={}){var r;const n=o.ref((r=t.initialValue)!=null?r:null);return o.watch(e,()=>n.value=U(),t),n}function pe(e,t,r={}){const{immediate:n=!0}=r,a=o.ref(!1);let u=null;function l(){u&&(clearTimeout(u),u=null)}function c(){a.value=!1,l()}function d(..._){l(),a.value=!0,u=setTimeout(()=>{a.value=!1,u=null,e(..._)},o.unref(t))}return n&&(a.value=!0,N&&d()),j(c),{isPending:a,start:d,stop:c}}var Zt=Object.defineProperty,de=Object.getOwnPropertySymbols,Kt=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable,_e=(e,t,r)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Dt=(e,t)=>{for(var r in t||(t={}))Kt.call(t,r)&&_e(e,r,t[r]);if(de)for(var r of de(t))kt.call(t,r)&&_e(e,r,t[r]);return e};function xt(e=1e3,t={}){const{controls:r=!1}=t,n=pe(B,e,t),a=o.computed(()=>!n.isPending.value);return r?Dt({ready:a},n):a}function er(e=!1){if(o.isRef(e))return t=>{e.value=typeof t=="boolean"?t:!e.value};{const t=o.ref(e);return[t,n=>{t.value=typeof n=="boolean"?n:!t.value}]}}var ve=Object.getOwnPropertySymbols,tr=Object.prototype.hasOwnProperty,rr=Object.prototype.propertyIsEnumerable,nr=(e,t)=>{var r={};for(var n in e)tr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&ve)for(var n of ve(e))t.indexOf(n)<0&&rr.call(e,n)&&(r[n]=e[n]);return r};function or(e,t,r){const n=r,{count:a}=n,u=nr(n,["count"]),l=o.ref(0),c=S(e,(...d)=>{l.value+=1,l.value>=o.unref(a)&&c(),t(...d)},u);return{count:l,stop:c}}function ar(e,t,r){const n=o.watch(e,(...a)=>(n(),t(...a)),r)}function ir(e,t,r){return o.watch(e,(n,a,u)=>{n&&t(n,a,u)},r)}i.and=O,i.assert=ge,i.biSyncRef=b,i.bypassFilter=F,i.clamp=Ee,i.containsProp=Ne,i.controlledComputed=g,i.controlledRef=m,i.createEventHook=Oe,i.createFilterWrapper=$,i.createGlobalState=he,i.createReactiveFn=A,i.createSharedComposable=we,i.createSingletonPromise=Ce,i.debounceFilter=R,i.debouncedRef=z,i.debouncedWatch=Qe,i.eagerComputed=Xe,i.extendRef=w,i.get=Ye,i.identity=Ve,i.ignorableWatch=tt,i.increaseWithUnit=Re,i.invoke=Ae,i.isBoolean=me,i.isClient=N,i.isDef=Pe,i.isDefined=rt,i.isFunction=be,i.isNumber=$e,i.isObject=je,i.isString=Se,i.isWindow=Fe,i.makeDestructurable=ut,i.noop=B,i.not=lt,i.now=Ie,i.objectPick=We,i.or=ct,i.pausableFilter=G,i.pausableWatch=yt,i.promiseTimeout=L,i.rand=Te,i.reactify=A,i.reactifyObject=Ot,i.reactivePick=ht,i.refDefault=wt,i.set=Pt,i.syncRef=gt,i.throttleFilter=W,i.throttledRef=ne,i.throttledWatch=It,i.timestamp=U,i.toReactive=Et,i.toRefs=Mt,i.tryOnBeforeUnmount=Ut,i.tryOnMounted=Bt,i.tryOnScopeDispose=j,i.tryOnUnmounted=Gt,i.until=Lt,i.useCounter=Ht,i.useDebounce=z,i.useDebounceFn=H,i.useInterval=Xt,i.useIntervalFn=ce,i.useLastChanged=Yt,i.useThrottle=ne,i.useThrottleFn=re,i.useTimeout=xt,i.useTimeoutFn=pe,i.useToggle=er,i.watchAtMost=or,i.watchOnce=ar,i.watchWithFilter=S,i.whenever=ir,Object.defineProperty(i,"__esModule",{value:!0})}(this.VueUse=this.VueUse||{},VueDemi);
|
package/index.mjs
CHANGED
|
@@ -162,6 +162,12 @@ function createGlobalState(stateFactory) {
|
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
function reactify(fn) {
|
|
166
|
+
return function(...args) {
|
|
167
|
+
return computed(() => fn.apply(this, args.map((i) => unref(i))));
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
function tryOnScopeDispose(fn) {
|
|
166
172
|
if (getCurrentScope()) {
|
|
167
173
|
onScopeDispose(fn);
|
|
@@ -364,6 +370,21 @@ function objectPick(obj, keys, omitUndefined = false) {
|
|
|
364
370
|
}, {});
|
|
365
371
|
}
|
|
366
372
|
|
|
373
|
+
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
374
|
+
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function useDebounce(value, ms = 200, options = {}) {
|
|
378
|
+
if (ms <= 0)
|
|
379
|
+
return value;
|
|
380
|
+
const debounced = ref(value.value);
|
|
381
|
+
const updater = useDebounceFn(() => {
|
|
382
|
+
debounced.value = value.value;
|
|
383
|
+
}, ms, options);
|
|
384
|
+
watch(value, () => updater());
|
|
385
|
+
return debounced;
|
|
386
|
+
}
|
|
387
|
+
|
|
367
388
|
var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
|
|
368
389
|
var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
|
|
369
390
|
var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
|
|
@@ -621,12 +642,6 @@ function pausableWatch(source, cb, options = {}) {
|
|
|
621
642
|
return { stop, pause, resume, isActive };
|
|
622
643
|
}
|
|
623
644
|
|
|
624
|
-
function reactify(fn) {
|
|
625
|
-
return function(...args) {
|
|
626
|
-
return computed(() => fn.apply(this, args.map((i) => unref(i))));
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
|
|
630
645
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
631
646
|
let keys = [];
|
|
632
647
|
if (Array.isArray(optionsOrKeys)) {
|
|
@@ -684,13 +699,22 @@ function syncRef(source, targets, {
|
|
|
684
699
|
} = {}) {
|
|
685
700
|
if (!Array.isArray(targets))
|
|
686
701
|
targets = [targets];
|
|
687
|
-
return watch(source, (newValue) => {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
702
|
+
return watch(source, (newValue) => targets.forEach((target) => target.value = newValue), { flush, deep, immediate });
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
706
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
710
|
+
if (delay <= 0)
|
|
711
|
+
return value;
|
|
712
|
+
const throttled = ref(value.value);
|
|
713
|
+
const updater = useThrottleFn(() => {
|
|
714
|
+
throttled.value = value.value;
|
|
715
|
+
}, delay, trailing, leading);
|
|
716
|
+
watch(value, () => updater());
|
|
717
|
+
return throttled;
|
|
694
718
|
}
|
|
695
719
|
|
|
696
720
|
var __defProp$3 = Object.defineProperty;
|
|
@@ -916,10 +940,14 @@ function until(r) {
|
|
|
916
940
|
}
|
|
917
941
|
}
|
|
918
942
|
|
|
919
|
-
function useCounter(initialValue = 0) {
|
|
943
|
+
function useCounter(initialValue = 0, options = {}) {
|
|
920
944
|
const count = ref(initialValue);
|
|
921
|
-
const
|
|
922
|
-
|
|
945
|
+
const {
|
|
946
|
+
max = Infinity,
|
|
947
|
+
min = -Infinity
|
|
948
|
+
} = options;
|
|
949
|
+
const inc = (delta = 1) => count.value = Math.min(max, count.value + delta);
|
|
950
|
+
const dec = (delta = 1) => count.value = Math.max(min, count.value - delta);
|
|
923
951
|
const get = () => count.value;
|
|
924
952
|
const set = (val) => count.value = val;
|
|
925
953
|
const reset = (val = initialValue) => {
|
|
@@ -929,21 +957,6 @@ function useCounter(initialValue = 0) {
|
|
|
929
957
|
return { count, inc, dec, get, set, reset };
|
|
930
958
|
}
|
|
931
959
|
|
|
932
|
-
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
933
|
-
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
function useDebounce(value, ms = 200, options = {}) {
|
|
937
|
-
if (ms <= 0)
|
|
938
|
-
return value;
|
|
939
|
-
const debounced = ref(value.value);
|
|
940
|
-
const updater = useDebounceFn(() => {
|
|
941
|
-
debounced.value = value.value;
|
|
942
|
-
}, ms, options);
|
|
943
|
-
watch(value, () => updater());
|
|
944
|
-
return debounced;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
960
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
948
961
|
const {
|
|
949
962
|
immediate = true,
|
|
@@ -1019,21 +1032,6 @@ function useLastChanged(source, options = {}) {
|
|
|
1019
1032
|
return ms;
|
|
1020
1033
|
}
|
|
1021
1034
|
|
|
1022
|
-
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
1023
|
-
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
1027
|
-
if (delay <= 0)
|
|
1028
|
-
return value;
|
|
1029
|
-
const throttled = ref(value.value);
|
|
1030
|
-
const updater = useThrottleFn(() => {
|
|
1031
|
-
throttled.value = value.value;
|
|
1032
|
-
}, delay, trailing, leading);
|
|
1033
|
-
watch(value, () => updater());
|
|
1034
|
-
return throttled;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
1035
|
function useTimeoutFn(cb, interval, options = {}) {
|
|
1038
1036
|
const {
|
|
1039
1037
|
immediate = true
|
|
@@ -1162,4 +1160,4 @@ function whenever(source, cb, options) {
|
|
|
1162
1160
|
}, options);
|
|
1163
1161
|
}
|
|
1164
1162
|
|
|
1165
|
-
export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createSharedComposable, createSingletonPromise, debounceFilter, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
|
|
1163
|
+
export { and, assert, biSyncRef, bypassFilter, clamp, containsProp, controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, useDebounce as debouncedRef, debouncedWatch, eagerComputed, extendRef, get, identity, ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, not, now, objectPick, or, pausableFilter, pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactivePick, refDefault, set, syncRef, throttleFilter, useThrottle as throttledRef, throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchAtMost, watchOnce, watchWithFilter, whenever };
|