@vueuse/shared 14.0.0-alpha.0 → 14.0.0-alpha.2

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 ADDED
@@ -0,0 +1,2061 @@
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
+ //#region computedEager/index.ts
4
+ /**
5
+ * Note: If you are using Vue 3.4+, you can straight use computed instead.
6
+ * Because in Vue 3.4+, if computed new value does not change,
7
+ * computed, effect, watch, watchEffect, render dependencies will not be triggered.
8
+ * refer: https://github.com/vuejs/core/pull/5912
9
+ *
10
+ * @param fn effect function
11
+ * @param options WatchOptionsBase
12
+ * @returns readonly shallowRef
13
+ */
14
+ function computedEager(fn, options) {
15
+ var _options$flush;
16
+ const result = shallowRef();
17
+ watchEffect(() => {
18
+ result.value = fn();
19
+ }, {
20
+ ...options,
21
+ flush: (_options$flush = options === null || options === void 0 ? void 0 : options.flush) !== null && _options$flush !== void 0 ? _options$flush : "sync"
22
+ });
23
+ return readonly(result);
24
+ }
25
+ /** @deprecated use `computedEager` instead */
26
+ const eagerComputed = computedEager;
27
+
28
+ //#endregion
29
+ //#region computedWithControl/index.ts
30
+ /**
31
+ * Explicitly define the deps of computed.
32
+ *
33
+ * @param source
34
+ * @param fn
35
+ */
36
+ function computedWithControl(source, fn, options = {}) {
37
+ let v = void 0;
38
+ let track;
39
+ let trigger;
40
+ let dirty = true;
41
+ const update = () => {
42
+ dirty = true;
43
+ trigger();
44
+ };
45
+ watch(source, update, {
46
+ flush: "sync",
47
+ ...options
48
+ });
49
+ const get$1 = typeof fn === "function" ? fn : fn.get;
50
+ const set$1 = typeof fn === "function" ? void 0 : fn.set;
51
+ const result = customRef((_track, _trigger) => {
52
+ track = _track;
53
+ trigger = _trigger;
54
+ return {
55
+ get() {
56
+ if (dirty) {
57
+ v = get$1(v);
58
+ dirty = false;
59
+ }
60
+ track();
61
+ return v;
62
+ },
63
+ set(v$1) {
64
+ set$1 === null || set$1 === void 0 || set$1(v$1);
65
+ }
66
+ };
67
+ });
68
+ result.trigger = update;
69
+ return result;
70
+ }
71
+ /** @deprecated use `computedWithControl` instead */
72
+ const controlledComputed = computedWithControl;
73
+
74
+ //#endregion
75
+ //#region tryOnScopeDispose/index.ts
76
+ /**
77
+ * Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
78
+ *
79
+ * @param fn
80
+ */
81
+ function tryOnScopeDispose(fn) {
82
+ if (getCurrentScope()) {
83
+ onScopeDispose(fn);
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+
89
+ //#endregion
90
+ //#region createEventHook/index.ts
91
+ /**
92
+ * Utility for creating event hooks
93
+ *
94
+ * @see https://vueuse.org/createEventHook
95
+ *
96
+ * @__NO_SIDE_EFFECTS__
97
+ */
98
+ function createEventHook() {
99
+ const fns = /* @__PURE__ */ new Set();
100
+ const off = (fn) => {
101
+ fns.delete(fn);
102
+ };
103
+ const clear = () => {
104
+ fns.clear();
105
+ };
106
+ const on = (fn) => {
107
+ fns.add(fn);
108
+ const offFn = () => off(fn);
109
+ tryOnScopeDispose(offFn);
110
+ return { off: offFn };
111
+ };
112
+ const trigger = (...args) => {
113
+ return Promise.all(Array.from(fns).map((fn) => fn(...args)));
114
+ };
115
+ return {
116
+ on,
117
+ off,
118
+ trigger,
119
+ clear
120
+ };
121
+ }
122
+
123
+ //#endregion
124
+ //#region createGlobalState/index.ts
125
+ /**
126
+ * Keep states in the global scope to be reusable across Vue instances.
127
+ *
128
+ * @see https://vueuse.org/createGlobalState
129
+ * @param stateFactory A factory function to create the state
130
+ *
131
+ * @__NO_SIDE_EFFECTS__
132
+ */
133
+ function createGlobalState(stateFactory) {
134
+ let initialized = false;
135
+ let state;
136
+ const scope = effectScope(true);
137
+ return ((...args) => {
138
+ if (!initialized) {
139
+ state = scope.run(() => stateFactory(...args));
140
+ initialized = true;
141
+ }
142
+ return state;
143
+ });
144
+ }
145
+
146
+ //#endregion
147
+ //#region provideLocal/map.ts
148
+ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
149
+
150
+ //#endregion
151
+ //#region injectLocal/index.ts
152
+ /**
153
+ * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * injectLocal('MyInjectionKey', 1)
158
+ * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
159
+ * ```
160
+ *
161
+ * @__NO_SIDE_EFFECTS__
162
+ */
163
+ const injectLocal = (...args) => {
164
+ var _getCurrentInstance;
165
+ const key = args[0];
166
+ const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
167
+ if (instance == null && !hasInjectionContext()) throw new Error("injectLocal must be called in setup");
168
+ if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance)) return localProvidedStateMap.get(instance)[key];
169
+ return inject(...args);
170
+ };
171
+
172
+ //#endregion
173
+ //#region provideLocal/index.ts
174
+ /**
175
+ * On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * provideLocal('MyInjectionKey', 1)
180
+ * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
181
+ * ```
182
+ */
183
+ function provideLocal(key, value) {
184
+ var _getCurrentInstance;
185
+ const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
186
+ if (instance == null) throw new Error("provideLocal must be called in setup");
187
+ if (!localProvidedStateMap.has(instance)) localProvidedStateMap.set(instance, Object.create(null));
188
+ const localProvidedState = localProvidedStateMap.get(instance);
189
+ localProvidedState[key] = value;
190
+ return provide(key, value);
191
+ }
192
+
193
+ //#endregion
194
+ //#region createInjectionState/index.ts
195
+ /**
196
+ * Create global state that can be injected into components.
197
+ *
198
+ * @see https://vueuse.org/createInjectionState
199
+ *
200
+ * @__NO_SIDE_EFFECTS__
201
+ */
202
+ function createInjectionState(composable, options) {
203
+ const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
204
+ const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
205
+ const useProvidingState = (...args) => {
206
+ const state = composable(...args);
207
+ provideLocal(key, state);
208
+ return state;
209
+ };
210
+ const useInjectedState = () => injectLocal(key, defaultValue);
211
+ return [useProvidingState, useInjectedState];
212
+ }
213
+
214
+ //#endregion
215
+ //#region createRef/index.ts
216
+ /**
217
+ * Returns a `deepRef` or `shallowRef` depending on the `deep` param.
218
+ *
219
+ * @example createRef(1) // ShallowRef<number>
220
+ * @example createRef(1, false) // ShallowRef<number>
221
+ * @example createRef(1, true) // Ref<number>
222
+ * @example createRef("string") // ShallowRef<string>
223
+ * @example createRef<"A"|"B">("A", true) // Ref<"A"|"B">
224
+ *
225
+ * @param value
226
+ * @param deep
227
+ * @returns the `deepRef` or `shallowRef`
228
+ *
229
+ * @__NO_SIDE_EFFECTS__
230
+ */
231
+ function createRef(value, deep) {
232
+ if (deep === true) return ref(value);
233
+ else return shallowRef(value);
234
+ }
235
+
236
+ //#endregion
237
+ //#region createSharedComposable/index.ts
238
+ /**
239
+ * Make a composable function usable with multiple Vue instances.
240
+ *
241
+ * @see https://vueuse.org/createSharedComposable
242
+ *
243
+ * @__NO_SIDE_EFFECTS__
244
+ */
245
+ function createSharedComposable(composable) {
246
+ let subscribers = 0;
247
+ let state;
248
+ let scope;
249
+ const dispose = () => {
250
+ subscribers -= 1;
251
+ if (scope && subscribers <= 0) {
252
+ scope.stop();
253
+ state = void 0;
254
+ scope = void 0;
255
+ }
256
+ };
257
+ return ((...args) => {
258
+ subscribers += 1;
259
+ if (!scope) {
260
+ scope = effectScope(true);
261
+ state = scope.run(() => composable(...args));
262
+ }
263
+ tryOnScopeDispose(dispose);
264
+ return state;
265
+ });
266
+ }
267
+
268
+ //#endregion
269
+ //#region extendRef/index.ts
270
+ function extendRef(ref$1, extend, { enumerable = false, unwrap = true } = {}) {
271
+ for (const [key, value] of Object.entries(extend)) {
272
+ if (key === "value") continue;
273
+ if (isRef(value) && unwrap) Object.defineProperty(ref$1, key, {
274
+ get() {
275
+ return value.value;
276
+ },
277
+ set(v) {
278
+ value.value = v;
279
+ },
280
+ enumerable
281
+ });
282
+ else Object.defineProperty(ref$1, key, {
283
+ value,
284
+ enumerable
285
+ });
286
+ }
287
+ return ref$1;
288
+ }
289
+
290
+ //#endregion
291
+ //#region get/index.ts
292
+ function get(obj, key) {
293
+ if (key == null) return unref(obj);
294
+ return unref(obj)[key];
295
+ }
296
+
297
+ //#endregion
298
+ //#region isDefined/index.ts
299
+ function isDefined(v) {
300
+ return unref(v) != null;
301
+ }
302
+
303
+ //#endregion
304
+ //#region makeDestructurable/index.ts
305
+ /* @__NO_SIDE_EFFECTS__ */
306
+ function makeDestructurable(obj, arr) {
307
+ if (typeof Symbol !== "undefined") {
308
+ const clone = { ...obj };
309
+ Object.defineProperty(clone, Symbol.iterator, {
310
+ enumerable: false,
311
+ value() {
312
+ let index = 0;
313
+ return { next: () => ({
314
+ value: arr[index++],
315
+ done: index > arr.length
316
+ }) };
317
+ }
318
+ });
319
+ return clone;
320
+ } else return Object.assign([...arr], obj);
321
+ }
322
+
323
+ //#endregion
324
+ //#region reactify/index.ts
325
+ /**
326
+ * Converts plain function into a reactive function.
327
+ * The converted function accepts refs as it's arguments
328
+ * and returns a ComputedRef, with proper typing.
329
+ *
330
+ * @param fn - Source function
331
+ * @param options - Options
332
+ *
333
+ * @__NO_SIDE_EFFECTS__
334
+ */
335
+ function reactify(fn, options) {
336
+ const unrefFn = (options === null || options === void 0 ? void 0 : options.computedGetter) === false ? unref : toValue;
337
+ return function(...args) {
338
+ return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
339
+ };
340
+ }
341
+ /** @deprecated use `reactify` instead */
342
+ const createReactiveFn = reactify;
343
+
344
+ //#endregion
345
+ //#region reactifyObject/index.ts
346
+ /**
347
+ * Apply `reactify` to an object
348
+ *
349
+ * @__NO_SIDE_EFFECTS__
350
+ */
351
+ function reactifyObject(obj, optionsOrKeys = {}) {
352
+ let keys = [];
353
+ let options;
354
+ if (Array.isArray(optionsOrKeys)) keys = optionsOrKeys;
355
+ else {
356
+ options = optionsOrKeys;
357
+ const { includeOwnProperties = true } = optionsOrKeys;
358
+ keys.push(...Object.keys(obj));
359
+ if (includeOwnProperties) keys.push(...Object.getOwnPropertyNames(obj));
360
+ }
361
+ return Object.fromEntries(keys.map((key) => {
362
+ const value = obj[key];
363
+ return [key, typeof value === "function" ? reactify(value.bind(obj), options) : value];
364
+ }));
365
+ }
366
+
367
+ //#endregion
368
+ //#region toReactive/index.ts
369
+ /**
370
+ * Converts ref to reactive.
371
+ *
372
+ * @see https://vueuse.org/toReactive
373
+ * @param objectRef A ref of object
374
+ */
375
+ function toReactive(objectRef) {
376
+ if (!isRef(objectRef)) return reactive(objectRef);
377
+ const proxy = new Proxy({}, {
378
+ get(_, p, receiver) {
379
+ return unref(Reflect.get(objectRef.value, p, receiver));
380
+ },
381
+ set(_, p, value) {
382
+ if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
383
+ else objectRef.value[p] = value;
384
+ return true;
385
+ },
386
+ deleteProperty(_, p) {
387
+ return Reflect.deleteProperty(objectRef.value, p);
388
+ },
389
+ has(_, p) {
390
+ return Reflect.has(objectRef.value, p);
391
+ },
392
+ ownKeys() {
393
+ return Object.keys(objectRef.value);
394
+ },
395
+ getOwnPropertyDescriptor() {
396
+ return {
397
+ enumerable: true,
398
+ configurable: true
399
+ };
400
+ }
401
+ });
402
+ return reactive(proxy);
403
+ }
404
+
405
+ //#endregion
406
+ //#region reactiveComputed/index.ts
407
+ /**
408
+ * Computed reactive object.
409
+ */
410
+ function reactiveComputed(fn) {
411
+ return toReactive(computed(fn));
412
+ }
413
+
414
+ //#endregion
415
+ //#region reactiveOmit/index.ts
416
+ /**
417
+ * Reactively omit fields from a reactive object
418
+ *
419
+ * @see https://vueuse.org/reactiveOmit
420
+ */
421
+ function reactiveOmit(obj, ...keys) {
422
+ const flatKeys = keys.flat();
423
+ const predicate = flatKeys[0];
424
+ 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]))));
425
+ }
426
+
427
+ //#endregion
428
+ //#region utils/is.ts
429
+ const isClient = typeof window !== "undefined" && typeof document !== "undefined";
430
+ const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
431
+ const isDef = (val) => typeof val !== "undefined";
432
+ const notNullish = (val) => val != null;
433
+ const assert = (condition, ...infos) => {
434
+ if (!condition) console.warn(...infos);
435
+ };
436
+ const toString = Object.prototype.toString;
437
+ const isObject = (val) => toString.call(val) === "[object Object]";
438
+ const now = () => Date.now();
439
+ const timestamp = () => +Date.now();
440
+ const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
441
+ const noop = () => {};
442
+ const rand = (min, max) => {
443
+ min = Math.ceil(min);
444
+ max = Math.floor(max);
445
+ return Math.floor(Math.random() * (max - min + 1)) + min;
446
+ };
447
+ const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
448
+ const isIOS = /* @__PURE__ */ getIsIOS();
449
+ function getIsIOS() {
450
+ var _window, _window2, _window3;
451
+ 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));
452
+ }
453
+
454
+ //#endregion
455
+ //#region toRef/index.ts
456
+ function toRef(...args) {
457
+ if (args.length !== 1) return toRef$1(...args);
458
+ const r = args[0];
459
+ return typeof r === "function" ? readonly(customRef(() => ({
460
+ get: r,
461
+ set: noop
462
+ }))) : ref(r);
463
+ }
464
+
465
+ //#endregion
466
+ //#region reactivePick/index.ts
467
+ /**
468
+ * Reactively pick fields from a reactive object
469
+ *
470
+ * @see https://vueuse.org/reactivePick
471
+ */
472
+ function reactivePick(obj, ...keys) {
473
+ const flatKeys = keys.flat();
474
+ const predicate = flatKeys[0];
475
+ 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)])));
476
+ }
477
+
478
+ //#endregion
479
+ //#region refAutoReset/index.ts
480
+ /**
481
+ * Create a ref which will be reset to the default value after some time.
482
+ *
483
+ * @see https://vueuse.org/refAutoReset
484
+ * @param defaultValue The value which will be set.
485
+ * @param afterMs A zero-or-greater delay in milliseconds.
486
+ */
487
+ function refAutoReset(defaultValue, afterMs = 1e4) {
488
+ return customRef((track, trigger) => {
489
+ let value = toValue(defaultValue);
490
+ let timer;
491
+ const resetAfter = () => setTimeout(() => {
492
+ value = toValue(defaultValue);
493
+ trigger();
494
+ }, toValue(afterMs));
495
+ tryOnScopeDispose(() => {
496
+ clearTimeout(timer);
497
+ });
498
+ return {
499
+ get() {
500
+ track();
501
+ return value;
502
+ },
503
+ set(newValue) {
504
+ value = newValue;
505
+ trigger();
506
+ clearTimeout(timer);
507
+ timer = resetAfter();
508
+ }
509
+ };
510
+ });
511
+ }
512
+ /** @deprecated use `refAutoReset` instead */
513
+ const autoResetRef = refAutoReset;
514
+
515
+ //#endregion
516
+ //#region utils/filters.ts
517
+ /**
518
+ * @internal
519
+ */
520
+ function createFilterWrapper(filter, fn) {
521
+ function wrapper(...args) {
522
+ return new Promise((resolve, reject) => {
523
+ Promise.resolve(filter(() => fn.apply(this, args), {
524
+ fn,
525
+ thisArg: this,
526
+ args
527
+ })).then(resolve).catch(reject);
528
+ });
529
+ }
530
+ return wrapper;
531
+ }
532
+ const bypassFilter = (invoke$1) => {
533
+ return invoke$1();
534
+ };
535
+ /**
536
+ * Create an EventFilter that debounce the events
537
+ */
538
+ function debounceFilter(ms, options = {}) {
539
+ let timer;
540
+ let maxTimer;
541
+ let lastRejector = noop;
542
+ const _clearTimeout = (timer$1) => {
543
+ clearTimeout(timer$1);
544
+ lastRejector();
545
+ lastRejector = noop;
546
+ };
547
+ let lastInvoker;
548
+ const filter = (invoke$1) => {
549
+ const duration = toValue(ms);
550
+ const maxDuration = toValue(options.maxWait);
551
+ if (timer) _clearTimeout(timer);
552
+ if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
553
+ if (maxTimer) {
554
+ _clearTimeout(maxTimer);
555
+ maxTimer = void 0;
556
+ }
557
+ return Promise.resolve(invoke$1());
558
+ }
559
+ return new Promise((resolve, reject) => {
560
+ lastRejector = options.rejectOnCancel ? reject : resolve;
561
+ lastInvoker = invoke$1;
562
+ if (maxDuration && !maxTimer) maxTimer = setTimeout(() => {
563
+ if (timer) _clearTimeout(timer);
564
+ maxTimer = void 0;
565
+ resolve(lastInvoker());
566
+ }, maxDuration);
567
+ timer = setTimeout(() => {
568
+ if (maxTimer) _clearTimeout(maxTimer);
569
+ maxTimer = void 0;
570
+ resolve(invoke$1());
571
+ }, duration);
572
+ });
573
+ };
574
+ return filter;
575
+ }
576
+ function throttleFilter(...args) {
577
+ let lastExec = 0;
578
+ let timer;
579
+ let isLeading = true;
580
+ let lastRejector = noop;
581
+ let lastValue;
582
+ let ms;
583
+ let trailing;
584
+ let leading;
585
+ let rejectOnCancel;
586
+ if (!isRef(args[0]) && typeof args[0] === "object") ({delay: ms, trailing = true, leading = true, rejectOnCancel = false} = args[0]);
587
+ else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
588
+ const clear = () => {
589
+ if (timer) {
590
+ clearTimeout(timer);
591
+ timer = void 0;
592
+ lastRejector();
593
+ lastRejector = noop;
594
+ }
595
+ };
596
+ const filter = (_invoke) => {
597
+ const duration = toValue(ms);
598
+ const elapsed = Date.now() - lastExec;
599
+ const invoke$1 = () => {
600
+ return lastValue = _invoke();
601
+ };
602
+ clear();
603
+ if (duration <= 0) {
604
+ lastExec = Date.now();
605
+ return invoke$1();
606
+ }
607
+ if (elapsed > duration) {
608
+ lastExec = Date.now();
609
+ if (leading || !isLeading) invoke$1();
610
+ } else if (trailing) lastValue = new Promise((resolve, reject) => {
611
+ lastRejector = rejectOnCancel ? reject : resolve;
612
+ timer = setTimeout(() => {
613
+ lastExec = Date.now();
614
+ isLeading = true;
615
+ resolve(invoke$1());
616
+ clear();
617
+ }, Math.max(0, duration - elapsed));
618
+ });
619
+ if (!leading && !timer) timer = setTimeout(() => isLeading = true, duration);
620
+ isLeading = false;
621
+ return lastValue;
622
+ };
623
+ return filter;
624
+ }
625
+ /**
626
+ * EventFilter that gives extra controls to pause and resume the filter
627
+ *
628
+ * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
629
+ * @param options Options to configure the filter
630
+ */
631
+ function pausableFilter(extendFilter = bypassFilter, options = {}) {
632
+ const { initialState = "active" } = options;
633
+ const isActive = toRef(initialState === "active");
634
+ function pause() {
635
+ isActive.value = false;
636
+ }
637
+ function resume() {
638
+ isActive.value = true;
639
+ }
640
+ const eventFilter = (...args) => {
641
+ if (isActive.value) extendFilter(...args);
642
+ };
643
+ return {
644
+ isActive: readonly(isActive),
645
+ pause,
646
+ resume,
647
+ eventFilter
648
+ };
649
+ }
650
+
651
+ //#endregion
652
+ //#region utils/general.ts
653
+ function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
654
+ return new Promise((resolve, reject) => {
655
+ if (throwOnTimeout) setTimeout(() => reject(reason), ms);
656
+ else setTimeout(resolve, ms);
657
+ });
658
+ }
659
+ function identity(arg) {
660
+ return arg;
661
+ }
662
+ /**
663
+ * Create singleton promise function
664
+ *
665
+ * @example
666
+ * ```
667
+ * const promise = createSingletonPromise(async () => { ... })
668
+ *
669
+ * await promise()
670
+ * await promise() // all of them will be bind to a single promise instance
671
+ * await promise() // and be resolved together
672
+ * ```
673
+ */
674
+ function createSingletonPromise(fn) {
675
+ let _promise;
676
+ function wrapper() {
677
+ if (!_promise) _promise = fn();
678
+ return _promise;
679
+ }
680
+ wrapper.reset = async () => {
681
+ const _prev = _promise;
682
+ _promise = void 0;
683
+ if (_prev) await _prev;
684
+ };
685
+ return wrapper;
686
+ }
687
+ function invoke(fn) {
688
+ return fn();
689
+ }
690
+ function containsProp(obj, ...props) {
691
+ return props.some((k) => k in obj);
692
+ }
693
+ function increaseWithUnit(target, delta) {
694
+ var _target$match;
695
+ if (typeof target === "number") return target + delta;
696
+ const value = ((_target$match = target.match(/^-?\d+\.?\d*/)) === null || _target$match === void 0 ? void 0 : _target$match[0]) || "";
697
+ const unit = target.slice(value.length);
698
+ const result = Number.parseFloat(value) + delta;
699
+ if (Number.isNaN(result)) return target;
700
+ return result + unit;
701
+ }
702
+ /**
703
+ * Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client
704
+ */
705
+ function pxValue(px) {
706
+ return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
707
+ }
708
+ /**
709
+ * Create a new subset object by giving keys
710
+ */
711
+ function objectPick(obj, keys, omitUndefined = false) {
712
+ return keys.reduce((n, k) => {
713
+ if (k in obj) {
714
+ if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
715
+ }
716
+ return n;
717
+ }, {});
718
+ }
719
+ /**
720
+ * Create a new subset object by omit giving keys
721
+ */
722
+ function objectOmit(obj, keys, omitUndefined = false) {
723
+ return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
724
+ return (!omitUndefined || value !== void 0) && !keys.includes(key);
725
+ }));
726
+ }
727
+ function objectEntries(obj) {
728
+ return Object.entries(obj);
729
+ }
730
+ function toArray(value) {
731
+ return Array.isArray(value) ? value : [value];
732
+ }
733
+
734
+ //#endregion
735
+ //#region utils/port.ts
736
+ function cacheStringFunction(fn) {
737
+ const cache = Object.create(null);
738
+ return ((str) => {
739
+ return cache[str] || (cache[str] = fn(str));
740
+ });
741
+ }
742
+ const hyphenateRE = /\B([A-Z])/g;
743
+ const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
744
+ const camelizeRE = /-(\w)/g;
745
+ const camelize = cacheStringFunction((str) => {
746
+ return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
747
+ });
748
+
749
+ //#endregion
750
+ //#region utils/vue.ts
751
+ function getLifeCycleTarget(target) {
752
+ return target || getCurrentInstance();
753
+ }
754
+
755
+ //#endregion
756
+ //#region useDebounceFn/index.ts
757
+ /**
758
+ * Debounce execution of a function.
759
+ *
760
+ * @see https://vueuse.org/useDebounceFn
761
+ * @param fn A function to be executed after delay milliseconds debounced.
762
+ * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
763
+ * @param options Options
764
+ *
765
+ * @return A new, debounce, function.
766
+ *
767
+ * @__NO_SIDE_EFFECTS__
768
+ */
769
+ function useDebounceFn(fn, ms = 200, options = {}) {
770
+ return createFilterWrapper(debounceFilter(ms, options), fn);
771
+ }
772
+
773
+ //#endregion
774
+ //#region refDebounced/index.ts
775
+ /**
776
+ * Debounce updates of a ref.
777
+ *
778
+ * @return A new debounced ref.
779
+ */
780
+ function refDebounced(value, ms = 200, options = {}) {
781
+ const debounced = ref(toValue(value));
782
+ const updater = useDebounceFn(() => {
783
+ debounced.value = value.value;
784
+ }, ms, options);
785
+ watch(value, () => updater());
786
+ return shallowReadonly(debounced);
787
+ }
788
+ /** @deprecated use `refDebounced` instead */
789
+ const debouncedRef = refDebounced;
790
+ /** @deprecated use `refDebounced` instead */
791
+ const useDebounce = refDebounced;
792
+
793
+ //#endregion
794
+ //#region refDefault/index.ts
795
+ /**
796
+ * Apply default value to a ref.
797
+ *
798
+ * @__NO_SIDE_EFFECTS__
799
+ */
800
+ function refDefault(source, defaultValue) {
801
+ return computed({
802
+ get() {
803
+ var _source$value;
804
+ return (_source$value = source.value) !== null && _source$value !== void 0 ? _source$value : defaultValue;
805
+ },
806
+ set(value) {
807
+ source.value = value;
808
+ }
809
+ });
810
+ }
811
+
812
+ //#endregion
813
+ //#region refManualReset/index.ts
814
+ /**
815
+ * Create a ref with manual reset functionality.
816
+ *
817
+ * @see https://vueuse.org/refManualReset
818
+ * @param defaultValue The value which will be set.
819
+ */
820
+ function refManualReset(defaultValue) {
821
+ let value = toValue(defaultValue);
822
+ let trigger;
823
+ const reset = () => {
824
+ value = toValue(defaultValue);
825
+ trigger();
826
+ };
827
+ const refValue = customRef((track, _trigger) => {
828
+ trigger = _trigger;
829
+ return {
830
+ get() {
831
+ track();
832
+ return value;
833
+ },
834
+ set(newValue) {
835
+ value = newValue;
836
+ trigger();
837
+ }
838
+ };
839
+ });
840
+ refValue.reset = reset;
841
+ return refValue;
842
+ }
843
+
844
+ //#endregion
845
+ //#region useThrottleFn/index.ts
846
+ /**
847
+ * Throttle execution of a function. Especially useful for rate limiting
848
+ * execution of handlers on events like resize and scroll.
849
+ *
850
+ * @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
851
+ * to `callback` when the throttled-function is executed.
852
+ * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
853
+ * (default value: 200)
854
+ *
855
+ * @param [trailing] if true, call fn again after the time is up (default value: false)
856
+ *
857
+ * @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
858
+ *
859
+ * @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
860
+ *
861
+ * @return A new, throttled, function.
862
+ *
863
+ * @__NO_SIDE_EFFECTS__
864
+ */
865
+ function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
866
+ return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
867
+ }
868
+
869
+ //#endregion
870
+ //#region refThrottled/index.ts
871
+ /**
872
+ * Throttle execution of a function. Especially useful for rate limiting
873
+ * execution of handlers on events like resize and scroll.
874
+ *
875
+ * @param value Ref value to be watched with throttle effect
876
+ * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
877
+ * @param trailing if true, update the value again after the delay time is up
878
+ * @param leading if true, update the value on the leading edge of the ms timeout
879
+ */
880
+ function refThrottled(value, delay = 200, trailing = true, leading = true) {
881
+ if (delay <= 0) return value;
882
+ const throttled = ref(toValue(value));
883
+ const updater = useThrottleFn(() => {
884
+ throttled.value = value.value;
885
+ }, delay, trailing, leading);
886
+ watch(value, () => updater());
887
+ return throttled;
888
+ }
889
+ /** @deprecated use `refThrottled` instead */
890
+ const throttledRef = refThrottled;
891
+ /** @deprecated use `refThrottled` instead */
892
+ const useThrottle = refThrottled;
893
+
894
+ //#endregion
895
+ //#region refWithControl/index.ts
896
+ /**
897
+ * Fine-grained controls over ref and its reactivity.
898
+ *
899
+ * @__NO_SIDE_EFFECTS__
900
+ */
901
+ function refWithControl(initial, options = {}) {
902
+ let source = initial;
903
+ let track;
904
+ let trigger;
905
+ const ref$1 = customRef((_track, _trigger) => {
906
+ track = _track;
907
+ trigger = _trigger;
908
+ return {
909
+ get() {
910
+ return get$1();
911
+ },
912
+ set(v) {
913
+ set$1(v);
914
+ }
915
+ };
916
+ });
917
+ function get$1(tracking = true) {
918
+ if (tracking) track();
919
+ return source;
920
+ }
921
+ function set$1(value, triggering = true) {
922
+ var _options$onBeforeChan, _options$onChanged;
923
+ if (value === source) return;
924
+ const old = source;
925
+ if (((_options$onBeforeChan = options.onBeforeChange) === null || _options$onBeforeChan === void 0 ? void 0 : _options$onBeforeChan.call(options, value, old)) === false) return;
926
+ source = value;
927
+ (_options$onChanged = options.onChanged) === null || _options$onChanged === void 0 || _options$onChanged.call(options, value, old);
928
+ if (triggering) trigger();
929
+ }
930
+ /**
931
+ * Get the value without tracked in the reactivity system
932
+ */
933
+ const untrackedGet = () => get$1(false);
934
+ /**
935
+ * Set the value without triggering the reactivity system
936
+ */
937
+ const silentSet = (v) => set$1(v, false);
938
+ /**
939
+ * Get the value without tracked in the reactivity system.
940
+ *
941
+ * Alias for `untrackedGet()`
942
+ */
943
+ const peek = () => get$1(false);
944
+ /**
945
+ * Set the value without triggering the reactivity system
946
+ *
947
+ * Alias for `silentSet(v)`
948
+ */
949
+ const lay = (v) => set$1(v, false);
950
+ return extendRef(ref$1, {
951
+ get: get$1,
952
+ set: set$1,
953
+ untrackedGet,
954
+ silentSet,
955
+ peek,
956
+ lay
957
+ }, { enumerable: true });
958
+ }
959
+ /** @deprecated use `refWithControl` instead */
960
+ const controlledRef = refWithControl;
961
+
962
+ //#endregion
963
+ //#region set/index.ts
964
+ /**
965
+ * Shorthand for `ref.value = x`
966
+ */
967
+ function set(...args) {
968
+ if (args.length === 2) {
969
+ const [ref$1, value] = args;
970
+ ref$1.value = value;
971
+ }
972
+ if (args.length === 3) {
973
+ const [target, key, value] = args;
974
+ target[key] = value;
975
+ }
976
+ }
977
+
978
+ //#endregion
979
+ //#region watchWithFilter/index.ts
980
+ function watchWithFilter(source, cb, options = {}) {
981
+ const { eventFilter = bypassFilter,...watchOptions } = options;
982
+ return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
983
+ }
984
+
985
+ //#endregion
986
+ //#region watchPausable/index.ts
987
+ function watchPausable(source, cb, options = {}) {
988
+ const { eventFilter: filter, initialState = "active",...watchOptions } = options;
989
+ const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
990
+ return {
991
+ stop: watchWithFilter(source, cb, {
992
+ ...watchOptions,
993
+ eventFilter
994
+ }),
995
+ pause,
996
+ resume,
997
+ isActive
998
+ };
999
+ }
1000
+ /** @deprecated use `watchPausable` instead */
1001
+ const pausableWatch = watchPausable;
1002
+
1003
+ //#endregion
1004
+ //#region syncRef/index.ts
1005
+ /**
1006
+ * Two-way refs synchronization.
1007
+ * From the set theory perspective to restrict the option's type
1008
+ * Check in the following order:
1009
+ * 1. L = R
1010
+ * 2. L ∩ R ≠ ∅
1011
+ * 3. L ⊆ R
1012
+ * 4. L ∩ R = ∅
1013
+ */
1014
+ function syncRef(left, right, ...[options]) {
1015
+ const { flush = "sync", deep = false, immediate = true, direction = "both", transform = {} } = options || {};
1016
+ const watchers = [];
1017
+ const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
1018
+ const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
1019
+ if (direction === "both" || direction === "ltr") watchers.push(pausableWatch(left, (newValue) => {
1020
+ watchers.forEach((w) => w.pause());
1021
+ right.value = transformLTR(newValue);
1022
+ watchers.forEach((w) => w.resume());
1023
+ }, {
1024
+ flush,
1025
+ deep,
1026
+ immediate
1027
+ }));
1028
+ if (direction === "both" || direction === "rtl") watchers.push(pausableWatch(right, (newValue) => {
1029
+ watchers.forEach((w) => w.pause());
1030
+ left.value = transformRTL(newValue);
1031
+ watchers.forEach((w) => w.resume());
1032
+ }, {
1033
+ flush,
1034
+ deep,
1035
+ immediate
1036
+ }));
1037
+ const stop = () => {
1038
+ watchers.forEach((w) => w.stop());
1039
+ };
1040
+ return stop;
1041
+ }
1042
+
1043
+ //#endregion
1044
+ //#region syncRefs/index.ts
1045
+ /**
1046
+ * Keep target ref(s) in sync with the source ref
1047
+ *
1048
+ * @param source source ref
1049
+ * @param targets
1050
+ */
1051
+ function syncRefs(source, targets, options = {}) {
1052
+ const { flush = "sync", deep = false, immediate = true } = options;
1053
+ const targetsArray = toArray(targets);
1054
+ return watch(source, (newValue) => targetsArray.forEach((target) => target.value = newValue), {
1055
+ flush,
1056
+ deep,
1057
+ immediate
1058
+ });
1059
+ }
1060
+
1061
+ //#endregion
1062
+ //#region toRefs/index.ts
1063
+ /**
1064
+ * Extended `toRefs` that also accepts refs of an object.
1065
+ *
1066
+ * @see https://vueuse.org/toRefs
1067
+ * @param objectRef A ref or normal object or array.
1068
+ * @param options Options
1069
+ */
1070
+ function toRefs(objectRef, options = {}) {
1071
+ if (!isRef(objectRef)) return toRefs$1(objectRef);
1072
+ const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
1073
+ for (const key in objectRef.value) result[key] = customRef(() => ({
1074
+ get() {
1075
+ return objectRef.value[key];
1076
+ },
1077
+ set(v) {
1078
+ var _toValue;
1079
+ if ((_toValue = toValue(options.replaceRef)) !== null && _toValue !== void 0 ? _toValue : true) if (Array.isArray(objectRef.value)) {
1080
+ const copy = [...objectRef.value];
1081
+ copy[key] = v;
1082
+ objectRef.value = copy;
1083
+ } else {
1084
+ const newObject = {
1085
+ ...objectRef.value,
1086
+ [key]: v
1087
+ };
1088
+ Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
1089
+ objectRef.value = newObject;
1090
+ }
1091
+ else objectRef.value[key] = v;
1092
+ }
1093
+ }));
1094
+ return result;
1095
+ }
1096
+
1097
+ //#endregion
1098
+ //#region tryOnBeforeMount/index.ts
1099
+ /**
1100
+ * Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
1101
+ *
1102
+ * @param fn
1103
+ * @param sync if set to false, it will run in the nextTick() of Vue
1104
+ * @param target
1105
+ */
1106
+ function tryOnBeforeMount(fn, sync = true, target) {
1107
+ if (getLifeCycleTarget(target)) onBeforeMount(fn, target);
1108
+ else if (sync) fn();
1109
+ else nextTick(fn);
1110
+ }
1111
+
1112
+ //#endregion
1113
+ //#region tryOnBeforeUnmount/index.ts
1114
+ /**
1115
+ * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
1116
+ *
1117
+ * @param fn
1118
+ * @param target
1119
+ */
1120
+ function tryOnBeforeUnmount(fn, target) {
1121
+ if (getLifeCycleTarget(target)) onBeforeUnmount(fn, target);
1122
+ }
1123
+
1124
+ //#endregion
1125
+ //#region tryOnMounted/index.ts
1126
+ /**
1127
+ * Call onMounted() if it's inside a component lifecycle, if not, just call the function
1128
+ *
1129
+ * @param fn
1130
+ * @param sync if set to false, it will run in the nextTick() of Vue
1131
+ * @param target
1132
+ */
1133
+ function tryOnMounted(fn, sync = true, target) {
1134
+ if (getLifeCycleTarget(target)) onMounted(fn, target);
1135
+ else if (sync) fn();
1136
+ else nextTick(fn);
1137
+ }
1138
+
1139
+ //#endregion
1140
+ //#region tryOnUnmounted/index.ts
1141
+ /**
1142
+ * Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
1143
+ *
1144
+ * @param fn
1145
+ * @param target
1146
+ */
1147
+ function tryOnUnmounted(fn, target) {
1148
+ if (getLifeCycleTarget(target)) onUnmounted(fn, target);
1149
+ }
1150
+
1151
+ //#endregion
1152
+ //#region until/index.ts
1153
+ function createUntil(r, isNot = false) {
1154
+ function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
1155
+ let stop = null;
1156
+ const promises = [new Promise((resolve) => {
1157
+ stop = watch(r, (v) => {
1158
+ if (condition(v) !== isNot) {
1159
+ if (stop) stop();
1160
+ else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
1161
+ resolve(v);
1162
+ }
1163
+ }, {
1164
+ flush,
1165
+ deep,
1166
+ immediate: true
1167
+ });
1168
+ })];
1169
+ if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop === null || stop === void 0 ? void 0 : stop()));
1170
+ return Promise.race(promises);
1171
+ }
1172
+ function toBe(value, options) {
1173
+ if (!isRef(value)) return toMatch((v) => v === value, options);
1174
+ const { flush = "sync", deep = false, timeout, throwOnTimeout } = options !== null && options !== void 0 ? options : {};
1175
+ let stop = null;
1176
+ const promises = [new Promise((resolve) => {
1177
+ stop = watch([r, value], ([v1, v2]) => {
1178
+ if (isNot !== (v1 === v2)) {
1179
+ if (stop) stop();
1180
+ else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
1181
+ resolve(v1);
1182
+ }
1183
+ }, {
1184
+ flush,
1185
+ deep,
1186
+ immediate: true
1187
+ });
1188
+ })];
1189
+ if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
1190
+ stop === null || stop === void 0 || stop();
1191
+ return toValue(r);
1192
+ }));
1193
+ return Promise.race(promises);
1194
+ }
1195
+ function toBeTruthy(options) {
1196
+ return toMatch((v) => Boolean(v), options);
1197
+ }
1198
+ function toBeNull(options) {
1199
+ return toBe(null, options);
1200
+ }
1201
+ function toBeUndefined(options) {
1202
+ return toBe(void 0, options);
1203
+ }
1204
+ function toBeNaN(options) {
1205
+ return toMatch(Number.isNaN, options);
1206
+ }
1207
+ function toContains(value, options) {
1208
+ return toMatch((v) => {
1209
+ const array = Array.from(v);
1210
+ return array.includes(value) || array.includes(toValue(value));
1211
+ }, options);
1212
+ }
1213
+ function changed(options) {
1214
+ return changedTimes(1, options);
1215
+ }
1216
+ function changedTimes(n = 1, options) {
1217
+ let count = -1;
1218
+ return toMatch(() => {
1219
+ count += 1;
1220
+ return count >= n;
1221
+ }, options);
1222
+ }
1223
+ if (Array.isArray(toValue(r))) return {
1224
+ toMatch,
1225
+ toContains,
1226
+ changed,
1227
+ changedTimes,
1228
+ get not() {
1229
+ return createUntil(r, !isNot);
1230
+ }
1231
+ };
1232
+ else return {
1233
+ toMatch,
1234
+ toBe,
1235
+ toBeTruthy,
1236
+ toBeNull,
1237
+ toBeNaN,
1238
+ toBeUndefined,
1239
+ changed,
1240
+ changedTimes,
1241
+ get not() {
1242
+ return createUntil(r, !isNot);
1243
+ }
1244
+ };
1245
+ }
1246
+ function until(r) {
1247
+ return createUntil(r);
1248
+ }
1249
+
1250
+ //#endregion
1251
+ //#region useArrayDifference/index.ts
1252
+ function defaultComparator(value, othVal) {
1253
+ return value === othVal;
1254
+ }
1255
+ /**
1256
+ * Reactive get array difference of two array
1257
+ * @see https://vueuse.org/useArrayDifference
1258
+ * @returns - the difference of two array
1259
+ * @param args
1260
+ *
1261
+ * @__NO_SIDE_EFFECTS__
1262
+ */
1263
+ function useArrayDifference(...args) {
1264
+ var _args$, _args$2;
1265
+ const list = args[0];
1266
+ const values = args[1];
1267
+ let compareFn = (_args$ = args[2]) !== null && _args$ !== void 0 ? _args$ : defaultComparator;
1268
+ const { symmetric = false } = (_args$2 = args[3]) !== null && _args$2 !== void 0 ? _args$2 : {};
1269
+ if (typeof compareFn === "string") {
1270
+ const key = compareFn;
1271
+ compareFn = (value, othVal) => value[key] === othVal[key];
1272
+ }
1273
+ const diff1 = computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
1274
+ if (symmetric) {
1275
+ const diff2 = computed(() => toValue(values).filter((x) => toValue(list).findIndex((y) => compareFn(x, y)) === -1));
1276
+ return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1));
1277
+ } else return diff1;
1278
+ }
1279
+
1280
+ //#endregion
1281
+ //#region useArrayEvery/index.ts
1282
+ /**
1283
+ * Reactive `Array.every`
1284
+ *
1285
+ * @see https://vueuse.org/useArrayEvery
1286
+ * @param list - the array was called upon.
1287
+ * @param fn - a function to test each element.
1288
+ *
1289
+ * @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**.
1290
+ *
1291
+ * @__NO_SIDE_EFFECTS__
1292
+ */
1293
+ function useArrayEvery(list, fn) {
1294
+ return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
1295
+ }
1296
+
1297
+ //#endregion
1298
+ //#region useArrayFilter/index.ts
1299
+ /**
1300
+ * Reactive `Array.filter`
1301
+ *
1302
+ * @see https://vueuse.org/useArrayFilter
1303
+ * @param list - the array was called upon.
1304
+ * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
1305
+ *
1306
+ * @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
1307
+ *
1308
+ * @__NO_SIDE_EFFECTS__
1309
+ */
1310
+ function useArrayFilter(list, fn) {
1311
+ return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
1312
+ }
1313
+
1314
+ //#endregion
1315
+ //#region useArrayFind/index.ts
1316
+ /**
1317
+ * Reactive `Array.find`
1318
+ *
1319
+ * @see https://vueuse.org/useArrayFind
1320
+ * @param list - the array was called upon.
1321
+ * @param fn - a function to test each element.
1322
+ *
1323
+ * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
1324
+ *
1325
+ * @__NO_SIDE_EFFECTS__
1326
+ */
1327
+ function useArrayFind(list, fn) {
1328
+ return computed(() => toValue(toValue(list).find((element, index, array) => fn(toValue(element), index, array))));
1329
+ }
1330
+
1331
+ //#endregion
1332
+ //#region useArrayFindIndex/index.ts
1333
+ /**
1334
+ * Reactive `Array.findIndex`
1335
+ *
1336
+ * @see https://vueuse.org/useArrayFindIndex
1337
+ * @param list - the array was called upon.
1338
+ * @param fn - a function to test each element.
1339
+ *
1340
+ * @returns the index of the first element in the array that passes the test. Otherwise, "-1".
1341
+ *
1342
+ * @__NO_SIDE_EFFECTS__
1343
+ */
1344
+ function useArrayFindIndex(list, fn) {
1345
+ return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
1346
+ }
1347
+
1348
+ //#endregion
1349
+ //#region useArrayFindLast/index.ts
1350
+ function findLast(arr, cb) {
1351
+ let index = arr.length;
1352
+ while (index-- > 0) if (cb(arr[index], index, arr)) return arr[index];
1353
+ }
1354
+ /**
1355
+ * Reactive `Array.findLast`
1356
+ *
1357
+ * @see https://vueuse.org/useArrayFindLast
1358
+ * @param list - the array was called upon.
1359
+ * @param fn - a function to test each element.
1360
+ *
1361
+ * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
1362
+ *
1363
+ * @__NO_SIDE_EFFECTS__
1364
+ */
1365
+ function useArrayFindLast(list, fn) {
1366
+ 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))));
1367
+ }
1368
+
1369
+ //#endregion
1370
+ //#region useArrayIncludes/index.ts
1371
+ function isArrayIncludesOptions(obj) {
1372
+ return isObject(obj) && containsProp(obj, "formIndex", "comparator");
1373
+ }
1374
+ /**
1375
+ * Reactive `Array.includes`
1376
+ *
1377
+ * @see https://vueuse.org/useArrayIncludes
1378
+ *
1379
+ * @returns true if the `value` is found in the array. Otherwise, false.
1380
+ *
1381
+ * @__NO_SIDE_EFFECTS__
1382
+ */
1383
+ function useArrayIncludes(...args) {
1384
+ var _comparator;
1385
+ const list = args[0];
1386
+ const value = args[1];
1387
+ let comparator = args[2];
1388
+ let formIndex = 0;
1389
+ if (isArrayIncludesOptions(comparator)) {
1390
+ var _comparator$fromIndex;
1391
+ formIndex = (_comparator$fromIndex = comparator.fromIndex) !== null && _comparator$fromIndex !== void 0 ? _comparator$fromIndex : 0;
1392
+ comparator = comparator.comparator;
1393
+ }
1394
+ if (typeof comparator === "string") {
1395
+ const key = comparator;
1396
+ comparator = (element, value$1) => element[key] === toValue(value$1);
1397
+ }
1398
+ comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value$1) => element === toValue(value$1));
1399
+ return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))));
1400
+ }
1401
+
1402
+ //#endregion
1403
+ //#region useArrayJoin/index.ts
1404
+ /**
1405
+ * Reactive `Array.join`
1406
+ *
1407
+ * @see https://vueuse.org/useArrayJoin
1408
+ * @param list - the array was called upon.
1409
+ * @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (",").
1410
+ *
1411
+ * @returns a string with all array elements joined. If arr.length is 0, the empty string is returned.
1412
+ *
1413
+ * @__NO_SIDE_EFFECTS__
1414
+ */
1415
+ function useArrayJoin(list, separator) {
1416
+ return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
1417
+ }
1418
+
1419
+ //#endregion
1420
+ //#region useArrayMap/index.ts
1421
+ /**
1422
+ * Reactive `Array.map`
1423
+ *
1424
+ * @see https://vueuse.org/useArrayMap
1425
+ * @param list - the array was called upon.
1426
+ * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
1427
+ *
1428
+ * @returns a new array with each element being the result of the callback function.
1429
+ *
1430
+ * @__NO_SIDE_EFFECTS__
1431
+ */
1432
+ function useArrayMap(list, fn) {
1433
+ return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
1434
+ }
1435
+
1436
+ //#endregion
1437
+ //#region useArrayReduce/index.ts
1438
+ /**
1439
+ * Reactive `Array.reduce`
1440
+ *
1441
+ * @see https://vueuse.org/useArrayReduce
1442
+ * @param list - the array was called upon.
1443
+ * @param reducer - a "reducer" function.
1444
+ * @param args
1445
+ *
1446
+ * @returns the value that results from running the "reducer" callback function to completion over the entire array.
1447
+ *
1448
+ * @__NO_SIDE_EFFECTS__
1449
+ */
1450
+ function useArrayReduce(list, reducer, ...args) {
1451
+ const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
1452
+ return computed(() => {
1453
+ const resolved = toValue(list);
1454
+ return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
1455
+ });
1456
+ }
1457
+
1458
+ //#endregion
1459
+ //#region useArraySome/index.ts
1460
+ /**
1461
+ * Reactive `Array.some`
1462
+ *
1463
+ * @see https://vueuse.org/useArraySome
1464
+ * @param list - the array was called upon.
1465
+ * @param fn - a function to test each element.
1466
+ *
1467
+ * @returns **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**.
1468
+ *
1469
+ * @__NO_SIDE_EFFECTS__
1470
+ */
1471
+ function useArraySome(list, fn) {
1472
+ return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
1473
+ }
1474
+
1475
+ //#endregion
1476
+ //#region useArrayUnique/index.ts
1477
+ function uniq(array) {
1478
+ return Array.from(new Set(array));
1479
+ }
1480
+ function uniqueElementsBy(array, fn) {
1481
+ return array.reduce((acc, v) => {
1482
+ if (!acc.some((x) => fn(v, x, array))) acc.push(v);
1483
+ return acc;
1484
+ }, []);
1485
+ }
1486
+ /**
1487
+ * reactive unique array
1488
+ * @see https://vueuse.org/useArrayUnique
1489
+ * @param list - the array was called upon.
1490
+ * @param compareFn
1491
+ * @returns A computed ref that returns a unique array of items.
1492
+ *
1493
+ * @__NO_SIDE_EFFECTS__
1494
+ */
1495
+ function useArrayUnique(list, compareFn) {
1496
+ return computed(() => {
1497
+ const resolvedList = toValue(list).map((element) => toValue(element));
1498
+ return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
1499
+ });
1500
+ }
1501
+
1502
+ //#endregion
1503
+ //#region useCounter/index.ts
1504
+ /**
1505
+ * Basic counter with utility functions.
1506
+ *
1507
+ * @see https://vueuse.org/useCounter
1508
+ * @param [initialValue]
1509
+ * @param options
1510
+ */
1511
+ function useCounter(initialValue = 0, options = {}) {
1512
+ let _initialValue = unref(initialValue);
1513
+ const count = shallowRef(initialValue);
1514
+ const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } = options;
1515
+ const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
1516
+ const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
1517
+ const get$1 = () => count.value;
1518
+ const set$1 = (val) => count.value = Math.max(min, Math.min(max, val));
1519
+ const reset = (val = _initialValue) => {
1520
+ _initialValue = val;
1521
+ return set$1(val);
1522
+ };
1523
+ return {
1524
+ count: shallowReadonly(count),
1525
+ inc,
1526
+ dec,
1527
+ get: get$1,
1528
+ set: set$1,
1529
+ reset
1530
+ };
1531
+ }
1532
+
1533
+ //#endregion
1534
+ //#region useDateFormat/index.ts
1535
+ const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
1536
+ const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
1537
+ function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
1538
+ let m = hours < 12 ? "AM" : "PM";
1539
+ if (hasPeriod) m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
1540
+ return isLowercase ? m.toLowerCase() : m;
1541
+ }
1542
+ function formatOrdinal(num) {
1543
+ const suffixes = [
1544
+ "th",
1545
+ "st",
1546
+ "nd",
1547
+ "rd"
1548
+ ];
1549
+ const v = num % 100;
1550
+ return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
1551
+ }
1552
+ function formatDate(date, formatStr, options = {}) {
1553
+ var _options$customMeridi;
1554
+ const years = date.getFullYear();
1555
+ const month = date.getMonth();
1556
+ const days = date.getDate();
1557
+ const hours = date.getHours();
1558
+ const minutes = date.getMinutes();
1559
+ const seconds = date.getSeconds();
1560
+ const milliseconds = date.getMilliseconds();
1561
+ const day = date.getDay();
1562
+ const meridiem = (_options$customMeridi = options.customMeridiem) !== null && _options$customMeridi !== void 0 ? _options$customMeridi : defaultMeridiem;
1563
+ const stripTimeZone = (dateString) => {
1564
+ var _dateString$split$;
1565
+ return (_dateString$split$ = dateString.split(" ")[1]) !== null && _dateString$split$ !== void 0 ? _dateString$split$ : "";
1566
+ };
1567
+ const matches = {
1568
+ Yo: () => formatOrdinal(years),
1569
+ YY: () => String(years).slice(-2),
1570
+ YYYY: () => years,
1571
+ M: () => month + 1,
1572
+ Mo: () => formatOrdinal(month + 1),
1573
+ MM: () => `${month + 1}`.padStart(2, "0"),
1574
+ MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
1575
+ MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
1576
+ D: () => String(days),
1577
+ Do: () => formatOrdinal(days),
1578
+ DD: () => `${days}`.padStart(2, "0"),
1579
+ H: () => String(hours),
1580
+ Ho: () => formatOrdinal(hours),
1581
+ HH: () => `${hours}`.padStart(2, "0"),
1582
+ h: () => `${hours % 12 || 12}`.padStart(1, "0"),
1583
+ ho: () => formatOrdinal(hours % 12 || 12),
1584
+ hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
1585
+ m: () => String(minutes),
1586
+ mo: () => formatOrdinal(minutes),
1587
+ mm: () => `${minutes}`.padStart(2, "0"),
1588
+ s: () => String(seconds),
1589
+ so: () => formatOrdinal(seconds),
1590
+ ss: () => `${seconds}`.padStart(2, "0"),
1591
+ SSS: () => `${milliseconds}`.padStart(3, "0"),
1592
+ d: () => day,
1593
+ dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
1594
+ ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
1595
+ dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
1596
+ A: () => meridiem(hours, minutes),
1597
+ AA: () => meridiem(hours, minutes, false, true),
1598
+ a: () => meridiem(hours, minutes, true),
1599
+ aa: () => meridiem(hours, minutes, true, true),
1600
+ z: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
1601
+ zz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
1602
+ zzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
1603
+ zzzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "longOffset" }))
1604
+ };
1605
+ return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1606
+ var _ref, _matches$match;
1607
+ return (_ref = $1 !== null && $1 !== void 0 ? $1 : (_matches$match = matches[match]) === null || _matches$match === void 0 ? void 0 : _matches$match.call(matches)) !== null && _ref !== void 0 ? _ref : match;
1608
+ });
1609
+ }
1610
+ function normalizeDate(date) {
1611
+ if (date === null) return /* @__PURE__ */ new Date(NaN);
1612
+ if (date === void 0) return /* @__PURE__ */ new Date();
1613
+ if (date instanceof Date) return new Date(date);
1614
+ if (typeof date === "string" && !/Z$/i.test(date)) {
1615
+ const d = date.match(REGEX_PARSE);
1616
+ if (d) {
1617
+ const m = d[2] - 1 || 0;
1618
+ const ms = (d[7] || "0").substring(0, 3);
1619
+ return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
1620
+ }
1621
+ }
1622
+ return new Date(date);
1623
+ }
1624
+ /**
1625
+ * Get the formatted date according to the string of tokens passed in.
1626
+ *
1627
+ * @see https://vueuse.org/useDateFormat
1628
+ * @param date - The date to format, can either be a `Date` object, a timestamp, or a string
1629
+ * @param formatStr - The combination of tokens to format the date
1630
+ * @param options - UseDateFormatOptions
1631
+ *
1632
+ * @__NO_SIDE_EFFECTS__
1633
+ */
1634
+ function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1635
+ return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
1636
+ }
1637
+
1638
+ //#endregion
1639
+ //#region useIntervalFn/index.ts
1640
+ /**
1641
+ * Wrapper for `setInterval` with controls
1642
+ *
1643
+ * @see https://vueuse.org/useIntervalFn
1644
+ * @param cb
1645
+ * @param interval
1646
+ * @param options
1647
+ */
1648
+ function useIntervalFn(cb, interval = 1e3, options = {}) {
1649
+ const { immediate = true, immediateCallback = false } = options;
1650
+ let timer = null;
1651
+ const isActive = shallowRef(false);
1652
+ function clean() {
1653
+ if (timer) {
1654
+ clearInterval(timer);
1655
+ timer = null;
1656
+ }
1657
+ }
1658
+ function pause() {
1659
+ isActive.value = false;
1660
+ clean();
1661
+ }
1662
+ function resume() {
1663
+ const intervalValue = toValue(interval);
1664
+ if (intervalValue <= 0) return;
1665
+ isActive.value = true;
1666
+ if (immediateCallback) cb();
1667
+ clean();
1668
+ if (isActive.value) timer = setInterval(cb, intervalValue);
1669
+ }
1670
+ if (immediate && isClient) resume();
1671
+ if (isRef(interval) || typeof interval === "function") {
1672
+ const stopWatch = watch(interval, () => {
1673
+ if (isActive.value && isClient) resume();
1674
+ });
1675
+ tryOnScopeDispose(stopWatch);
1676
+ }
1677
+ tryOnScopeDispose(pause);
1678
+ return {
1679
+ isActive: shallowReadonly(isActive),
1680
+ pause,
1681
+ resume
1682
+ };
1683
+ }
1684
+
1685
+ //#endregion
1686
+ //#region useInterval/index.ts
1687
+ function useInterval(interval = 1e3, options = {}) {
1688
+ const { controls: exposeControls = false, immediate = true, callback } = options;
1689
+ const counter = shallowRef(0);
1690
+ const update = () => counter.value += 1;
1691
+ const reset = () => {
1692
+ counter.value = 0;
1693
+ };
1694
+ const controls = useIntervalFn(callback ? () => {
1695
+ update();
1696
+ callback(counter.value);
1697
+ } : update, interval, { immediate });
1698
+ if (exposeControls) return {
1699
+ counter: shallowReadonly(counter),
1700
+ reset,
1701
+ ...controls
1702
+ };
1703
+ else return shallowReadonly(counter);
1704
+ }
1705
+
1706
+ //#endregion
1707
+ //#region useLastChanged/index.ts
1708
+ function useLastChanged(source, options = {}) {
1709
+ var _options$initialValue;
1710
+ const ms = shallowRef((_options$initialValue = options.initialValue) !== null && _options$initialValue !== void 0 ? _options$initialValue : null);
1711
+ watch(source, () => ms.value = timestamp(), options);
1712
+ return shallowReadonly(ms);
1713
+ }
1714
+
1715
+ //#endregion
1716
+ //#region useTimeoutFn/index.ts
1717
+ /**
1718
+ * Wrapper for `setTimeout` with controls.
1719
+ *
1720
+ * @param cb
1721
+ * @param interval
1722
+ * @param options
1723
+ */
1724
+ function useTimeoutFn(cb, interval, options = {}) {
1725
+ const { immediate = true, immediateCallback = false } = options;
1726
+ const isPending = shallowRef(false);
1727
+ let timer;
1728
+ function clear() {
1729
+ if (timer) {
1730
+ clearTimeout(timer);
1731
+ timer = void 0;
1732
+ }
1733
+ }
1734
+ function stop() {
1735
+ isPending.value = false;
1736
+ clear();
1737
+ }
1738
+ function start(...args) {
1739
+ if (immediateCallback) cb();
1740
+ clear();
1741
+ isPending.value = true;
1742
+ timer = setTimeout(() => {
1743
+ isPending.value = false;
1744
+ timer = void 0;
1745
+ cb(...args);
1746
+ }, toValue(interval));
1747
+ }
1748
+ if (immediate) {
1749
+ isPending.value = true;
1750
+ if (isClient) start();
1751
+ }
1752
+ tryOnScopeDispose(stop);
1753
+ return {
1754
+ isPending: shallowReadonly(isPending),
1755
+ start,
1756
+ stop
1757
+ };
1758
+ }
1759
+
1760
+ //#endregion
1761
+ //#region useTimeout/index.ts
1762
+ function useTimeout(interval = 1e3, options = {}) {
1763
+ const { controls: exposeControls = false, callback } = options;
1764
+ const controls = useTimeoutFn(callback !== null && callback !== void 0 ? callback : noop, interval, options);
1765
+ const ready = computed(() => !controls.isPending.value);
1766
+ if (exposeControls) return {
1767
+ ready,
1768
+ ...controls
1769
+ };
1770
+ else return ready;
1771
+ }
1772
+
1773
+ //#endregion
1774
+ //#region useToNumber/index.ts
1775
+ /**
1776
+ * Reactively convert a string ref to number.
1777
+ *
1778
+ * @__NO_SIDE_EFFECTS__
1779
+ */
1780
+ function useToNumber(value, options = {}) {
1781
+ const { method = "parseFloat", radix, nanToZero } = options;
1782
+ return computed(() => {
1783
+ let resolved = toValue(value);
1784
+ if (typeof method === "function") resolved = method(resolved);
1785
+ else if (typeof resolved === "string") resolved = Number[method](resolved, radix);
1786
+ if (nanToZero && Number.isNaN(resolved)) resolved = 0;
1787
+ return resolved;
1788
+ });
1789
+ }
1790
+
1791
+ //#endregion
1792
+ //#region useToString/index.ts
1793
+ /**
1794
+ * Reactively convert a ref to string.
1795
+ *
1796
+ * @see https://vueuse.org/useToString
1797
+ *
1798
+ * @__NO_SIDE_EFFECTS__
1799
+ */
1800
+ function useToString(value) {
1801
+ return computed(() => `${toValue(value)}`);
1802
+ }
1803
+
1804
+ //#endregion
1805
+ //#region useToggle/index.ts
1806
+ /**
1807
+ * A boolean ref with a toggler
1808
+ *
1809
+ * @see https://vueuse.org/useToggle
1810
+ * @param [initialValue]
1811
+ * @param options
1812
+ *
1813
+ * @__NO_SIDE_EFFECTS__
1814
+ */
1815
+ function useToggle(initialValue = false, options = {}) {
1816
+ const { truthyValue = true, falsyValue = false } = options;
1817
+ const valueIsRef = isRef(initialValue);
1818
+ const _value = shallowRef(initialValue);
1819
+ function toggle(value) {
1820
+ if (arguments.length) {
1821
+ _value.value = value;
1822
+ return _value.value;
1823
+ } else {
1824
+ const truthy = toValue(truthyValue);
1825
+ _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
1826
+ return _value.value;
1827
+ }
1828
+ }
1829
+ if (valueIsRef) return toggle;
1830
+ else return [_value, toggle];
1831
+ }
1832
+
1833
+ //#endregion
1834
+ //#region watchArray/index.ts
1835
+ /**
1836
+ * Watch for an array with additions and removals.
1837
+ *
1838
+ * @see https://vueuse.org/watchArray
1839
+ */
1840
+ function watchArray(source, cb, options) {
1841
+ let oldList = (options === null || options === void 0 ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : toValue(source)];
1842
+ return watch(source, (newList, _, onCleanup) => {
1843
+ const oldListRemains = Array.from({ length: oldList.length });
1844
+ const added = [];
1845
+ for (const obj of newList) {
1846
+ let found = false;
1847
+ for (let i = 0; i < oldList.length; i++) if (!oldListRemains[i] && obj === oldList[i]) {
1848
+ oldListRemains[i] = true;
1849
+ found = true;
1850
+ break;
1851
+ }
1852
+ if (!found) added.push(obj);
1853
+ }
1854
+ const removed = oldList.filter((_$1, i) => !oldListRemains[i]);
1855
+ cb(newList, oldList, added, removed, onCleanup);
1856
+ oldList = [...newList];
1857
+ }, options);
1858
+ }
1859
+
1860
+ //#endregion
1861
+ //#region watchAtMost/index.ts
1862
+ function watchAtMost(source, cb, options) {
1863
+ const { count,...watchOptions } = options;
1864
+ const current = shallowRef(0);
1865
+ const stop = watchWithFilter(source, (...args) => {
1866
+ current.value += 1;
1867
+ if (current.value >= toValue(count)) nextTick(() => stop());
1868
+ cb(...args);
1869
+ }, watchOptions);
1870
+ return {
1871
+ count: current,
1872
+ stop
1873
+ };
1874
+ }
1875
+
1876
+ //#endregion
1877
+ //#region watchDebounced/index.ts
1878
+ function watchDebounced(source, cb, options = {}) {
1879
+ const { debounce = 0, maxWait = void 0,...watchOptions } = options;
1880
+ return watchWithFilter(source, cb, {
1881
+ ...watchOptions,
1882
+ eventFilter: debounceFilter(debounce, { maxWait })
1883
+ });
1884
+ }
1885
+ /** @deprecated use `watchDebounced` instead */
1886
+ const debouncedWatch = watchDebounced;
1887
+
1888
+ //#endregion
1889
+ //#region watchDeep/index.ts
1890
+ /**
1891
+ * Shorthand for watching value with {deep: true}
1892
+ *
1893
+ * @see https://vueuse.org/watchDeep
1894
+ */
1895
+ function watchDeep(source, cb, options) {
1896
+ return watch(source, cb, {
1897
+ ...options,
1898
+ deep: true
1899
+ });
1900
+ }
1901
+
1902
+ //#endregion
1903
+ //#region watchIgnorable/index.ts
1904
+ function watchIgnorable(source, cb, options = {}) {
1905
+ const { eventFilter = bypassFilter,...watchOptions } = options;
1906
+ const filteredCb = createFilterWrapper(eventFilter, cb);
1907
+ let ignoreUpdates;
1908
+ let ignorePrevAsyncUpdates;
1909
+ let stop;
1910
+ if (watchOptions.flush === "sync") {
1911
+ let ignore = false;
1912
+ ignorePrevAsyncUpdates = () => {};
1913
+ ignoreUpdates = (updater) => {
1914
+ ignore = true;
1915
+ updater();
1916
+ ignore = false;
1917
+ };
1918
+ stop = watch(source, (...args) => {
1919
+ if (!ignore) filteredCb(...args);
1920
+ }, watchOptions);
1921
+ } else {
1922
+ const disposables = [];
1923
+ let ignoreCounter = 0;
1924
+ let syncCounter = 0;
1925
+ ignorePrevAsyncUpdates = () => {
1926
+ ignoreCounter = syncCounter;
1927
+ };
1928
+ disposables.push(watch(source, () => {
1929
+ syncCounter++;
1930
+ }, {
1931
+ ...watchOptions,
1932
+ flush: "sync"
1933
+ }));
1934
+ ignoreUpdates = (updater) => {
1935
+ const syncCounterPrev = syncCounter;
1936
+ updater();
1937
+ ignoreCounter += syncCounter - syncCounterPrev;
1938
+ };
1939
+ disposables.push(watch(source, (...args) => {
1940
+ const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
1941
+ ignoreCounter = 0;
1942
+ syncCounter = 0;
1943
+ if (ignore) return;
1944
+ filteredCb(...args);
1945
+ }, watchOptions));
1946
+ stop = () => {
1947
+ disposables.forEach((fn) => fn());
1948
+ };
1949
+ }
1950
+ return {
1951
+ stop,
1952
+ ignoreUpdates,
1953
+ ignorePrevAsyncUpdates
1954
+ };
1955
+ }
1956
+ /** @deprecated use `watchIgnorable` instead */
1957
+ const ignorableWatch = watchIgnorable;
1958
+
1959
+ //#endregion
1960
+ //#region watchImmediate/index.ts
1961
+ /**
1962
+ * Shorthand for watching value with {immediate: true}
1963
+ *
1964
+ * @see https://vueuse.org/watchImmediate
1965
+ */
1966
+ function watchImmediate(source, cb, options) {
1967
+ return watch(source, cb, {
1968
+ ...options,
1969
+ immediate: true
1970
+ });
1971
+ }
1972
+
1973
+ //#endregion
1974
+ //#region watchOnce/index.ts
1975
+ /**
1976
+ * Shorthand for watching value with { once: true }
1977
+ *
1978
+ * @see https://vueuse.org/watchOnce
1979
+ */
1980
+ function watchOnce(source, cb, options) {
1981
+ return watch(source, cb, {
1982
+ ...options,
1983
+ once: true
1984
+ });
1985
+ }
1986
+
1987
+ //#endregion
1988
+ //#region watchThrottled/index.ts
1989
+ function watchThrottled(source, cb, options = {}) {
1990
+ const { throttle = 0, trailing = true, leading = true,...watchOptions } = options;
1991
+ return watchWithFilter(source, cb, {
1992
+ ...watchOptions,
1993
+ eventFilter: throttleFilter(throttle, trailing, leading)
1994
+ });
1995
+ }
1996
+ /** @deprecated use `watchThrottled` instead */
1997
+ const throttledWatch = watchThrottled;
1998
+
1999
+ //#endregion
2000
+ //#region watchTriggerable/index.ts
2001
+ function watchTriggerable(source, cb, options = {}) {
2002
+ let cleanupFn;
2003
+ function onEffect() {
2004
+ if (!cleanupFn) return;
2005
+ const fn = cleanupFn;
2006
+ cleanupFn = void 0;
2007
+ fn();
2008
+ }
2009
+ /** Register the function `cleanupFn` */
2010
+ function onCleanup(callback) {
2011
+ cleanupFn = callback;
2012
+ }
2013
+ const _cb = (value, oldValue) => {
2014
+ onEffect();
2015
+ return cb(value, oldValue, onCleanup);
2016
+ };
2017
+ const res = watchIgnorable(source, _cb, options);
2018
+ const { ignoreUpdates } = res;
2019
+ const trigger = () => {
2020
+ let res$1;
2021
+ ignoreUpdates(() => {
2022
+ res$1 = _cb(getWatchSources(source), getOldValue(source));
2023
+ });
2024
+ return res$1;
2025
+ };
2026
+ return {
2027
+ ...res,
2028
+ trigger
2029
+ };
2030
+ }
2031
+ function getWatchSources(sources) {
2032
+ if (isReactive(sources)) return sources;
2033
+ if (Array.isArray(sources)) return sources.map((item) => toValue(item));
2034
+ return toValue(sources);
2035
+ }
2036
+ function getOldValue(source) {
2037
+ return Array.isArray(source) ? source.map(() => void 0) : void 0;
2038
+ }
2039
+
2040
+ //#endregion
2041
+ //#region whenever/index.ts
2042
+ /**
2043
+ * Shorthand for watching value to be truthy
2044
+ *
2045
+ * @see https://vueuse.org/whenever
2046
+ */
2047
+ function whenever(source, cb, options) {
2048
+ const stop = watch(source, (v, ov, onInvalidate) => {
2049
+ if (v) {
2050
+ if (options === null || options === void 0 ? void 0 : options.once) nextTick(() => stop());
2051
+ cb(v, ov, onInvalidate);
2052
+ }
2053
+ }, {
2054
+ ...options,
2055
+ once: false
2056
+ });
2057
+ return stop;
2058
+ }
2059
+
2060
+ //#endregion
2061
+ 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 };