@vueuse/shared 13.9.0 → 14.0.0-alpha.1

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