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