@vueuse/shared 12.8.1 → 13.0.0-beta.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.
Files changed (4) hide show
  1. package/package.json +4 -10
  2. package/index.cjs +0 -1732
  3. package/index.d.cts +0 -1260
  4. package/index.d.ts +0 -1260
package/index.cjs DELETED
@@ -1,1732 +0,0 @@
1
- 'use strict';
2
-
3
- var vue = require('vue');
4
-
5
- function computedEager(fn, options) {
6
- var _a;
7
- const result = vue.shallowRef();
8
- vue.watchEffect(() => {
9
- result.value = fn();
10
- }, {
11
- ...options,
12
- flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
13
- });
14
- return vue.readonly(result);
15
- }
16
-
17
- function computedWithControl(source, fn) {
18
- let v = void 0;
19
- let track;
20
- let trigger;
21
- const dirty = vue.shallowRef(true);
22
- const update = () => {
23
- dirty.value = true;
24
- trigger();
25
- };
26
- vue.watch(source, update, { flush: "sync" });
27
- const get = typeof fn === "function" ? fn : fn.get;
28
- const set = typeof fn === "function" ? void 0 : fn.set;
29
- const result = vue.customRef((_track, _trigger) => {
30
- track = _track;
31
- trigger = _trigger;
32
- return {
33
- get() {
34
- if (dirty.value) {
35
- v = get(v);
36
- dirty.value = false;
37
- }
38
- track();
39
- return v;
40
- },
41
- set(v2) {
42
- set == null ? void 0 : set(v2);
43
- }
44
- };
45
- });
46
- if (Object.isExtensible(result))
47
- result.trigger = update;
48
- return result;
49
- }
50
-
51
- function tryOnScopeDispose(fn) {
52
- if (vue.getCurrentScope()) {
53
- vue.onScopeDispose(fn);
54
- return true;
55
- }
56
- return false;
57
- }
58
-
59
- function createEventHook() {
60
- const fns = /* @__PURE__ */ new Set();
61
- const off = (fn) => {
62
- fns.delete(fn);
63
- };
64
- const clear = () => {
65
- fns.clear();
66
- };
67
- const on = (fn) => {
68
- fns.add(fn);
69
- const offFn = () => off(fn);
70
- tryOnScopeDispose(offFn);
71
- return {
72
- off: offFn
73
- };
74
- };
75
- const trigger = (...args) => {
76
- return Promise.all(Array.from(fns).map((fn) => fn(...args)));
77
- };
78
- return {
79
- on,
80
- off,
81
- trigger,
82
- clear
83
- };
84
- }
85
-
86
- function createGlobalState(stateFactory) {
87
- let initialized = false;
88
- let state;
89
- const scope = vue.effectScope(true);
90
- return (...args) => {
91
- if (!initialized) {
92
- state = scope.run(() => stateFactory(...args));
93
- initialized = true;
94
- }
95
- return state;
96
- };
97
- }
98
-
99
- const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
100
-
101
- const injectLocal = (...args) => {
102
- var _a;
103
- const key = args[0];
104
- const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy;
105
- if (instance == null && !vue.hasInjectionContext())
106
- throw new Error("injectLocal must be called in setup");
107
- if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
108
- return localProvidedStateMap.get(instance)[key];
109
- return vue.inject(...args);
110
- };
111
-
112
- const provideLocal = (key, value) => {
113
- var _a;
114
- const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy;
115
- if (instance == null)
116
- throw new Error("provideLocal must be called in setup");
117
- if (!localProvidedStateMap.has(instance))
118
- localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
119
- const localProvidedState = localProvidedStateMap.get(instance);
120
- localProvidedState[key] = value;
121
- vue.provide(key, value);
122
- };
123
-
124
- function createInjectionState(composable, options) {
125
- const key = (options == null ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
126
- const defaultValue = options == null ? void 0 : options.defaultValue;
127
- const useProvidingState = (...args) => {
128
- const state = composable(...args);
129
- provideLocal(key, state);
130
- return state;
131
- };
132
- const useInjectedState = () => injectLocal(key, defaultValue);
133
- return [useProvidingState, useInjectedState];
134
- }
135
-
136
- function createRef(value, deep) {
137
- if (deep === true) {
138
- return vue.ref(value);
139
- } else {
140
- return vue.shallowRef(value);
141
- }
142
- }
143
-
144
- function createSharedComposable(composable) {
145
- let subscribers = 0;
146
- let state;
147
- let scope;
148
- const dispose = () => {
149
- subscribers -= 1;
150
- if (scope && subscribers <= 0) {
151
- scope.stop();
152
- state = void 0;
153
- scope = void 0;
154
- }
155
- };
156
- return (...args) => {
157
- subscribers += 1;
158
- if (!scope) {
159
- scope = vue.effectScope(true);
160
- state = scope.run(() => composable(...args));
161
- }
162
- tryOnScopeDispose(dispose);
163
- return state;
164
- };
165
- }
166
-
167
- function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
168
- for (const [key, value] of Object.entries(extend)) {
169
- if (key === "value")
170
- continue;
171
- if (vue.isRef(value) && unwrap) {
172
- Object.defineProperty(ref, key, {
173
- get() {
174
- return value.value;
175
- },
176
- set(v) {
177
- value.value = v;
178
- },
179
- enumerable
180
- });
181
- } else {
182
- Object.defineProperty(ref, key, { value, enumerable });
183
- }
184
- }
185
- return ref;
186
- }
187
-
188
- function get(obj, key) {
189
- if (key == null)
190
- return vue.unref(obj);
191
- return vue.unref(obj)[key];
192
- }
193
-
194
- function isDefined(v) {
195
- return vue.unref(v) != null;
196
- }
197
-
198
- function makeDestructurable(obj, arr) {
199
- if (typeof Symbol !== "undefined") {
200
- const clone = { ...obj };
201
- Object.defineProperty(clone, Symbol.iterator, {
202
- enumerable: false,
203
- value() {
204
- let index = 0;
205
- return {
206
- next: () => ({
207
- value: arr[index++],
208
- done: index > arr.length
209
- })
210
- };
211
- }
212
- });
213
- return clone;
214
- } else {
215
- return Object.assign([...arr], obj);
216
- }
217
- }
218
-
219
- function reactify(fn, options) {
220
- const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vue.unref : vue.toValue;
221
- return function(...args) {
222
- return vue.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
223
- };
224
- }
225
-
226
- function reactifyObject(obj, optionsOrKeys = {}) {
227
- let keys = [];
228
- let options;
229
- if (Array.isArray(optionsOrKeys)) {
230
- keys = optionsOrKeys;
231
- } else {
232
- options = optionsOrKeys;
233
- const { includeOwnProperties = true } = optionsOrKeys;
234
- keys.push(...Object.keys(obj));
235
- if (includeOwnProperties)
236
- keys.push(...Object.getOwnPropertyNames(obj));
237
- }
238
- return Object.fromEntries(
239
- keys.map((key) => {
240
- const value = obj[key];
241
- return [
242
- key,
243
- typeof value === "function" ? reactify(value.bind(obj), options) : value
244
- ];
245
- })
246
- );
247
- }
248
-
249
- function toReactive(objectRef) {
250
- if (!vue.isRef(objectRef))
251
- return vue.reactive(objectRef);
252
- const proxy = new Proxy({}, {
253
- get(_, p, receiver) {
254
- return vue.unref(Reflect.get(objectRef.value, p, receiver));
255
- },
256
- set(_, p, value) {
257
- if (vue.isRef(objectRef.value[p]) && !vue.isRef(value))
258
- objectRef.value[p].value = value;
259
- else
260
- objectRef.value[p] = value;
261
- return true;
262
- },
263
- deleteProperty(_, p) {
264
- return Reflect.deleteProperty(objectRef.value, p);
265
- },
266
- has(_, p) {
267
- return Reflect.has(objectRef.value, p);
268
- },
269
- ownKeys() {
270
- return Object.keys(objectRef.value);
271
- },
272
- getOwnPropertyDescriptor() {
273
- return {
274
- enumerable: true,
275
- configurable: true
276
- };
277
- }
278
- });
279
- return vue.reactive(proxy);
280
- }
281
-
282
- function reactiveComputed(fn) {
283
- return toReactive(vue.computed(fn));
284
- }
285
-
286
- function reactiveOmit(obj, ...keys) {
287
- const flatKeys = keys.flat();
288
- const predicate = flatKeys[0];
289
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vue.toRefs(obj)).filter(([k, v]) => !predicate(vue.toValue(v), k))) : Object.fromEntries(Object.entries(vue.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
290
- }
291
-
292
- const isClient = typeof window !== "undefined" && typeof document !== "undefined";
293
- const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
294
- const isDef = (val) => typeof val !== "undefined";
295
- const notNullish = (val) => val != null;
296
- const assert = (condition, ...infos) => {
297
- if (!condition)
298
- console.warn(...infos);
299
- };
300
- const toString = Object.prototype.toString;
301
- const isObject = (val) => toString.call(val) === "[object Object]";
302
- const now = () => Date.now();
303
- const timestamp = () => +Date.now();
304
- const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
305
- const noop = () => {
306
- };
307
- const rand = (min, max) => {
308
- min = Math.ceil(min);
309
- max = Math.floor(max);
310
- return Math.floor(Math.random() * (max - min + 1)) + min;
311
- };
312
- const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
313
- const isIOS = /* @__PURE__ */ getIsIOS();
314
- function getIsIOS() {
315
- var _a, _b;
316
- return isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? void 0 : window.navigator) == null ? void 0 : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? void 0 : window.navigator.userAgent));
317
- }
318
-
319
- function createFilterWrapper(filter, fn) {
320
- function wrapper(...args) {
321
- return new Promise((resolve, reject) => {
322
- Promise.resolve(filter(() => fn.apply(this, args), { fn, thisArg: this, args })).then(resolve).catch(reject);
323
- });
324
- }
325
- return wrapper;
326
- }
327
- const bypassFilter = (invoke) => {
328
- return invoke();
329
- };
330
- function debounceFilter(ms, options = {}) {
331
- let timer;
332
- let maxTimer;
333
- let lastRejector = noop;
334
- const _clearTimeout = (timer2) => {
335
- clearTimeout(timer2);
336
- lastRejector();
337
- lastRejector = noop;
338
- };
339
- let lastInvoker;
340
- const filter = (invoke) => {
341
- const duration = vue.toValue(ms);
342
- const maxDuration = vue.toValue(options.maxWait);
343
- if (timer)
344
- _clearTimeout(timer);
345
- if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
346
- if (maxTimer) {
347
- _clearTimeout(maxTimer);
348
- maxTimer = null;
349
- }
350
- return Promise.resolve(invoke());
351
- }
352
- return new Promise((resolve, reject) => {
353
- lastRejector = options.rejectOnCancel ? reject : resolve;
354
- lastInvoker = invoke;
355
- if (maxDuration && !maxTimer) {
356
- maxTimer = setTimeout(() => {
357
- if (timer)
358
- _clearTimeout(timer);
359
- maxTimer = null;
360
- resolve(lastInvoker());
361
- }, maxDuration);
362
- }
363
- timer = setTimeout(() => {
364
- if (maxTimer)
365
- _clearTimeout(maxTimer);
366
- maxTimer = null;
367
- resolve(invoke());
368
- }, duration);
369
- });
370
- };
371
- return filter;
372
- }
373
- function throttleFilter(...args) {
374
- let lastExec = 0;
375
- let timer;
376
- let isLeading = true;
377
- let lastRejector = noop;
378
- let lastValue;
379
- let ms;
380
- let trailing;
381
- let leading;
382
- let rejectOnCancel;
383
- if (!vue.isRef(args[0]) && typeof args[0] === "object")
384
- ({ delay: ms, trailing = true, leading = true, rejectOnCancel = false } = args[0]);
385
- else
386
- [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
387
- const clear = () => {
388
- if (timer) {
389
- clearTimeout(timer);
390
- timer = void 0;
391
- lastRejector();
392
- lastRejector = noop;
393
- }
394
- };
395
- const filter = (_invoke) => {
396
- const duration = vue.toValue(ms);
397
- const elapsed = Date.now() - lastExec;
398
- const invoke = () => {
399
- return lastValue = _invoke();
400
- };
401
- clear();
402
- if (duration <= 0) {
403
- lastExec = Date.now();
404
- return invoke();
405
- }
406
- if (elapsed > duration && (leading || !isLeading)) {
407
- lastExec = Date.now();
408
- invoke();
409
- } else if (trailing) {
410
- lastValue = new Promise((resolve, reject) => {
411
- lastRejector = rejectOnCancel ? reject : resolve;
412
- timer = setTimeout(() => {
413
- lastExec = Date.now();
414
- isLeading = true;
415
- resolve(invoke());
416
- clear();
417
- }, Math.max(0, duration - elapsed));
418
- });
419
- }
420
- if (!leading && !timer)
421
- timer = setTimeout(() => isLeading = true, duration);
422
- isLeading = false;
423
- return lastValue;
424
- };
425
- return filter;
426
- }
427
- function pausableFilter(extendFilter = bypassFilter, options = {}) {
428
- const {
429
- initialState = "active"
430
- } = options;
431
- const isActive = toRef(initialState === "active");
432
- function pause() {
433
- isActive.value = false;
434
- }
435
- function resume() {
436
- isActive.value = true;
437
- }
438
- const eventFilter = (...args) => {
439
- if (isActive.value)
440
- extendFilter(...args);
441
- };
442
- return { isActive: vue.readonly(isActive), pause, resume, eventFilter };
443
- }
444
-
445
- function cacheStringFunction(fn) {
446
- const cache = /* @__PURE__ */ Object.create(null);
447
- return (str) => {
448
- const hit = cache[str];
449
- return hit || (cache[str] = fn(str));
450
- };
451
- }
452
- const hyphenateRE = /\B([A-Z])/g;
453
- const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
454
- const camelizeRE = /-(\w)/g;
455
- const camelize = cacheStringFunction((str) => {
456
- return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
457
- });
458
-
459
- function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
460
- return new Promise((resolve, reject) => {
461
- if (throwOnTimeout)
462
- setTimeout(() => reject(reason), ms);
463
- else
464
- setTimeout(resolve, ms);
465
- });
466
- }
467
- function identity(arg) {
468
- return arg;
469
- }
470
- function createSingletonPromise(fn) {
471
- let _promise;
472
- function wrapper() {
473
- if (!_promise)
474
- _promise = fn();
475
- return _promise;
476
- }
477
- wrapper.reset = async () => {
478
- const _prev = _promise;
479
- _promise = void 0;
480
- if (_prev)
481
- await _prev;
482
- };
483
- return wrapper;
484
- }
485
- function invoke(fn) {
486
- return fn();
487
- }
488
- function containsProp(obj, ...props) {
489
- return props.some((k) => k in obj);
490
- }
491
- function increaseWithUnit(target, delta) {
492
- var _a;
493
- if (typeof target === "number")
494
- return target + delta;
495
- const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
496
- const unit = target.slice(value.length);
497
- const result = Number.parseFloat(value) + delta;
498
- if (Number.isNaN(result))
499
- return target;
500
- return result + unit;
501
- }
502
- function pxValue(px) {
503
- return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
504
- }
505
- function objectPick(obj, keys, omitUndefined = false) {
506
- return keys.reduce((n, k) => {
507
- if (k in obj) {
508
- if (!omitUndefined || obj[k] !== void 0)
509
- n[k] = obj[k];
510
- }
511
- return n;
512
- }, {});
513
- }
514
- function objectOmit(obj, keys, omitUndefined = false) {
515
- return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
516
- return (!omitUndefined || value !== void 0) && !keys.includes(key);
517
- }));
518
- }
519
- function objectEntries(obj) {
520
- return Object.entries(obj);
521
- }
522
- function getLifeCycleTarget(target) {
523
- return target || vue.getCurrentInstance();
524
- }
525
- function toArray(value) {
526
- return Array.isArray(value) ? value : [value];
527
- }
528
-
529
- function toRef(...args) {
530
- if (args.length !== 1)
531
- return vue.toRef(...args);
532
- const r = args[0];
533
- return typeof r === "function" ? vue.readonly(vue.customRef(() => ({ get: r, set: noop }))) : vue.ref(r);
534
- }
535
- const resolveRef = toRef;
536
-
537
- function reactivePick(obj, ...keys) {
538
- const flatKeys = keys.flat();
539
- const predicate = flatKeys[0];
540
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vue.toRefs(obj)).filter(([k, v]) => predicate(vue.toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
541
- }
542
-
543
- function refAutoReset(defaultValue, afterMs = 1e4) {
544
- return vue.customRef((track, trigger) => {
545
- let value = vue.toValue(defaultValue);
546
- let timer;
547
- const resetAfter = () => setTimeout(() => {
548
- value = vue.toValue(defaultValue);
549
- trigger();
550
- }, vue.toValue(afterMs));
551
- tryOnScopeDispose(() => {
552
- clearTimeout(timer);
553
- });
554
- return {
555
- get() {
556
- track();
557
- return value;
558
- },
559
- set(newValue) {
560
- value = newValue;
561
- trigger();
562
- clearTimeout(timer);
563
- timer = resetAfter();
564
- }
565
- };
566
- });
567
- }
568
-
569
- function useDebounceFn(fn, ms = 200, options = {}) {
570
- return createFilterWrapper(
571
- debounceFilter(ms, options),
572
- fn
573
- );
574
- }
575
-
576
- function refDebounced(value, ms = 200, options = {}) {
577
- const debounced = vue.ref(value.value);
578
- const updater = useDebounceFn(() => {
579
- debounced.value = value.value;
580
- }, ms, options);
581
- vue.watch(value, () => updater());
582
- return debounced;
583
- }
584
-
585
- function refDefault(source, defaultValue) {
586
- return vue.computed({
587
- get() {
588
- var _a;
589
- return (_a = source.value) != null ? _a : defaultValue;
590
- },
591
- set(value) {
592
- source.value = value;
593
- }
594
- });
595
- }
596
-
597
- function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
598
- return createFilterWrapper(
599
- throttleFilter(ms, trailing, leading, rejectOnCancel),
600
- fn
601
- );
602
- }
603
-
604
- function refThrottled(value, delay = 200, trailing = true, leading = true) {
605
- if (delay <= 0)
606
- return value;
607
- const throttled = vue.ref(value.value);
608
- const updater = useThrottleFn(() => {
609
- throttled.value = value.value;
610
- }, delay, trailing, leading);
611
- vue.watch(value, () => updater());
612
- return throttled;
613
- }
614
-
615
- function refWithControl(initial, options = {}) {
616
- let source = initial;
617
- let track;
618
- let trigger;
619
- const ref = vue.customRef((_track, _trigger) => {
620
- track = _track;
621
- trigger = _trigger;
622
- return {
623
- get() {
624
- return get();
625
- },
626
- set(v) {
627
- set(v);
628
- }
629
- };
630
- });
631
- function get(tracking = true) {
632
- if (tracking)
633
- track();
634
- return source;
635
- }
636
- function set(value, triggering = true) {
637
- var _a, _b;
638
- if (value === source)
639
- return;
640
- const old = source;
641
- if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
642
- return;
643
- source = value;
644
- (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
645
- if (triggering)
646
- trigger();
647
- }
648
- const untrackedGet = () => get(false);
649
- const silentSet = (v) => set(v, false);
650
- const peek = () => get(false);
651
- const lay = (v) => set(v, false);
652
- return extendRef(
653
- ref,
654
- {
655
- get,
656
- set,
657
- untrackedGet,
658
- silentSet,
659
- peek,
660
- lay
661
- },
662
- { enumerable: true }
663
- );
664
- }
665
- const controlledRef = refWithControl;
666
-
667
- function set(...args) {
668
- if (args.length === 2) {
669
- const [ref, value] = args;
670
- ref.value = value;
671
- }
672
- if (args.length === 3) {
673
- const [target, key, value] = args;
674
- target[key] = value;
675
- }
676
- }
677
-
678
- function watchWithFilter(source, cb, options = {}) {
679
- const {
680
- eventFilter = bypassFilter,
681
- ...watchOptions
682
- } = options;
683
- return vue.watch(
684
- source,
685
- createFilterWrapper(
686
- eventFilter,
687
- cb
688
- ),
689
- watchOptions
690
- );
691
- }
692
-
693
- function watchPausable(source, cb, options = {}) {
694
- const {
695
- eventFilter: filter,
696
- initialState = "active",
697
- ...watchOptions
698
- } = options;
699
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
700
- const stop = watchWithFilter(
701
- source,
702
- cb,
703
- {
704
- ...watchOptions,
705
- eventFilter
706
- }
707
- );
708
- return { stop, pause, resume, isActive };
709
- }
710
-
711
- function syncRef(left, right, ...[options]) {
712
- const {
713
- flush = "sync",
714
- deep = false,
715
- immediate = true,
716
- direction = "both",
717
- transform = {}
718
- } = options || {};
719
- const watchers = [];
720
- const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
721
- const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
722
- if (direction === "both" || direction === "ltr") {
723
- watchers.push(watchPausable(
724
- left,
725
- (newValue) => {
726
- watchers.forEach((w) => w.pause());
727
- right.value = transformLTR(newValue);
728
- watchers.forEach((w) => w.resume());
729
- },
730
- { flush, deep, immediate }
731
- ));
732
- }
733
- if (direction === "both" || direction === "rtl") {
734
- watchers.push(watchPausable(
735
- right,
736
- (newValue) => {
737
- watchers.forEach((w) => w.pause());
738
- left.value = transformRTL(newValue);
739
- watchers.forEach((w) => w.resume());
740
- },
741
- { flush, deep, immediate }
742
- ));
743
- }
744
- const stop = () => {
745
- watchers.forEach((w) => w.stop());
746
- };
747
- return stop;
748
- }
749
-
750
- function syncRefs(source, targets, options = {}) {
751
- const {
752
- flush = "sync",
753
- deep = false,
754
- immediate = true
755
- } = options;
756
- const targetsArray = toArray(targets);
757
- return vue.watch(
758
- source,
759
- (newValue) => targetsArray.forEach((target) => target.value = newValue),
760
- { flush, deep, immediate }
761
- );
762
- }
763
-
764
- function toRefs(objectRef, options = {}) {
765
- if (!vue.isRef(objectRef))
766
- return vue.toRefs(objectRef);
767
- const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
768
- for (const key in objectRef.value) {
769
- result[key] = vue.customRef(() => ({
770
- get() {
771
- return objectRef.value[key];
772
- },
773
- set(v) {
774
- var _a;
775
- const replaceRef = (_a = vue.toValue(options.replaceRef)) != null ? _a : true;
776
- if (replaceRef) {
777
- if (Array.isArray(objectRef.value)) {
778
- const copy = [...objectRef.value];
779
- copy[key] = v;
780
- objectRef.value = copy;
781
- } else {
782
- const newObject = { ...objectRef.value, [key]: v };
783
- Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
784
- objectRef.value = newObject;
785
- }
786
- } else {
787
- objectRef.value[key] = v;
788
- }
789
- }
790
- }));
791
- }
792
- return result;
793
- }
794
-
795
- const toValue = vue.toValue;
796
- const resolveUnref = vue.toValue;
797
-
798
- function tryOnBeforeMount(fn, sync = true, target) {
799
- const instance = getLifeCycleTarget(target);
800
- if (instance)
801
- vue.onBeforeMount(fn, target);
802
- else if (sync)
803
- fn();
804
- else
805
- vue.nextTick(fn);
806
- }
807
-
808
- function tryOnBeforeUnmount(fn, target) {
809
- const instance = getLifeCycleTarget(target);
810
- if (instance)
811
- vue.onBeforeUnmount(fn, target);
812
- }
813
-
814
- function tryOnMounted(fn, sync = true, target) {
815
- const instance = getLifeCycleTarget();
816
- if (instance)
817
- vue.onMounted(fn, target);
818
- else if (sync)
819
- fn();
820
- else
821
- vue.nextTick(fn);
822
- }
823
-
824
- function tryOnUnmounted(fn, target) {
825
- const instance = getLifeCycleTarget(target);
826
- if (instance)
827
- vue.onUnmounted(fn, target);
828
- }
829
-
830
- function createUntil(r, isNot = false) {
831
- function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
832
- let stop = null;
833
- const watcher = new Promise((resolve) => {
834
- stop = vue.watch(
835
- r,
836
- (v) => {
837
- if (condition(v) !== isNot) {
838
- if (stop)
839
- stop();
840
- else
841
- vue.nextTick(() => stop == null ? void 0 : stop());
842
- resolve(v);
843
- }
844
- },
845
- {
846
- flush,
847
- deep,
848
- immediate: true
849
- }
850
- );
851
- });
852
- const promises = [watcher];
853
- if (timeout != null) {
854
- promises.push(
855
- promiseTimeout(timeout, throwOnTimeout).then(() => vue.toValue(r)).finally(() => stop == null ? void 0 : stop())
856
- );
857
- }
858
- return Promise.race(promises);
859
- }
860
- function toBe(value, options) {
861
- if (!vue.isRef(value))
862
- return toMatch((v) => v === value, options);
863
- const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
864
- let stop = null;
865
- const watcher = new Promise((resolve) => {
866
- stop = vue.watch(
867
- [r, value],
868
- ([v1, v2]) => {
869
- if (isNot !== (v1 === v2)) {
870
- if (stop)
871
- stop();
872
- else
873
- vue.nextTick(() => stop == null ? void 0 : stop());
874
- resolve(v1);
875
- }
876
- },
877
- {
878
- flush,
879
- deep,
880
- immediate: true
881
- }
882
- );
883
- });
884
- const promises = [watcher];
885
- if (timeout != null) {
886
- promises.push(
887
- promiseTimeout(timeout, throwOnTimeout).then(() => vue.toValue(r)).finally(() => {
888
- stop == null ? void 0 : stop();
889
- return vue.toValue(r);
890
- })
891
- );
892
- }
893
- return Promise.race(promises);
894
- }
895
- function toBeTruthy(options) {
896
- return toMatch((v) => Boolean(v), options);
897
- }
898
- function toBeNull(options) {
899
- return toBe(null, options);
900
- }
901
- function toBeUndefined(options) {
902
- return toBe(void 0, options);
903
- }
904
- function toBeNaN(options) {
905
- return toMatch(Number.isNaN, options);
906
- }
907
- function toContains(value, options) {
908
- return toMatch((v) => {
909
- const array = Array.from(v);
910
- return array.includes(value) || array.includes(vue.toValue(value));
911
- }, options);
912
- }
913
- function changed(options) {
914
- return changedTimes(1, options);
915
- }
916
- function changedTimes(n = 1, options) {
917
- let count = -1;
918
- return toMatch(() => {
919
- count += 1;
920
- return count >= n;
921
- }, options);
922
- }
923
- if (Array.isArray(vue.toValue(r))) {
924
- const instance = {
925
- toMatch,
926
- toContains,
927
- changed,
928
- changedTimes,
929
- get not() {
930
- return createUntil(r, !isNot);
931
- }
932
- };
933
- return instance;
934
- } else {
935
- const instance = {
936
- toMatch,
937
- toBe,
938
- toBeTruthy,
939
- toBeNull,
940
- toBeNaN,
941
- toBeUndefined,
942
- changed,
943
- changedTimes,
944
- get not() {
945
- return createUntil(r, !isNot);
946
- }
947
- };
948
- return instance;
949
- }
950
- }
951
- function until(r) {
952
- return createUntil(r);
953
- }
954
-
955
- function defaultComparator(value, othVal) {
956
- return value === othVal;
957
- }
958
- function useArrayDifference(...args) {
959
- var _a, _b;
960
- const list = args[0];
961
- const values = args[1];
962
- let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
963
- const {
964
- symmetric = false
965
- } = (_b = args[3]) != null ? _b : {};
966
- if (typeof compareFn === "string") {
967
- const key = compareFn;
968
- compareFn = (value, othVal) => value[key] === othVal[key];
969
- }
970
- const diff1 = vue.computed(() => vue.toValue(list).filter((x) => vue.toValue(values).findIndex((y) => compareFn(x, y)) === -1));
971
- if (symmetric) {
972
- const diff2 = vue.computed(() => vue.toValue(values).filter((x) => vue.toValue(list).findIndex((y) => compareFn(x, y)) === -1));
973
- return vue.computed(() => symmetric ? [...vue.toValue(diff1), ...vue.toValue(diff2)] : vue.toValue(diff1));
974
- } else {
975
- return diff1;
976
- }
977
- }
978
-
979
- function useArrayEvery(list, fn) {
980
- return vue.computed(() => vue.toValue(list).every((element, index, array) => fn(vue.toValue(element), index, array)));
981
- }
982
-
983
- function useArrayFilter(list, fn) {
984
- return vue.computed(() => vue.toValue(list).map((i) => vue.toValue(i)).filter(fn));
985
- }
986
-
987
- function useArrayFind(list, fn) {
988
- return vue.computed(() => vue.toValue(
989
- vue.toValue(list).find((element, index, array) => fn(vue.toValue(element), index, array))
990
- ));
991
- }
992
-
993
- function useArrayFindIndex(list, fn) {
994
- return vue.computed(() => vue.toValue(list).findIndex((element, index, array) => fn(vue.toValue(element), index, array)));
995
- }
996
-
997
- function findLast(arr, cb) {
998
- let index = arr.length;
999
- while (index-- > 0) {
1000
- if (cb(arr[index], index, arr))
1001
- return arr[index];
1002
- }
1003
- return void 0;
1004
- }
1005
- function useArrayFindLast(list, fn) {
1006
- return vue.computed(() => vue.toValue(
1007
- !Array.prototype.findLast ? findLast(vue.toValue(list), (element, index, array) => fn(vue.toValue(element), index, array)) : vue.toValue(list).findLast((element, index, array) => fn(vue.toValue(element), index, array))
1008
- ));
1009
- }
1010
-
1011
- function isArrayIncludesOptions(obj) {
1012
- return isObject(obj) && containsProp(obj, "formIndex", "comparator");
1013
- }
1014
- function useArrayIncludes(...args) {
1015
- var _a;
1016
- const list = args[0];
1017
- const value = args[1];
1018
- let comparator = args[2];
1019
- let formIndex = 0;
1020
- if (isArrayIncludesOptions(comparator)) {
1021
- formIndex = (_a = comparator.fromIndex) != null ? _a : 0;
1022
- comparator = comparator.comparator;
1023
- }
1024
- if (typeof comparator === "string") {
1025
- const key = comparator;
1026
- comparator = (element, value2) => element[key] === vue.toValue(value2);
1027
- }
1028
- comparator = comparator != null ? comparator : (element, value2) => element === vue.toValue(value2);
1029
- return vue.computed(() => vue.toValue(list).slice(formIndex).some((element, index, array) => comparator(
1030
- vue.toValue(element),
1031
- vue.toValue(value),
1032
- index,
1033
- vue.toValue(array)
1034
- )));
1035
- }
1036
-
1037
- function useArrayJoin(list, separator) {
1038
- return vue.computed(() => vue.toValue(list).map((i) => vue.toValue(i)).join(vue.toValue(separator)));
1039
- }
1040
-
1041
- function useArrayMap(list, fn) {
1042
- return vue.computed(() => vue.toValue(list).map((i) => vue.toValue(i)).map(fn));
1043
- }
1044
-
1045
- function useArrayReduce(list, reducer, ...args) {
1046
- const reduceCallback = (sum, value, index) => reducer(vue.toValue(sum), vue.toValue(value), index);
1047
- return vue.computed(() => {
1048
- const resolved = vue.toValue(list);
1049
- return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? vue.toValue(args[0]()) : vue.toValue(args[0])) : resolved.reduce(reduceCallback);
1050
- });
1051
- }
1052
-
1053
- function useArraySome(list, fn) {
1054
- return vue.computed(() => vue.toValue(list).some((element, index, array) => fn(vue.toValue(element), index, array)));
1055
- }
1056
-
1057
- function uniq(array) {
1058
- return Array.from(new Set(array));
1059
- }
1060
- function uniqueElementsBy(array, fn) {
1061
- return array.reduce((acc, v) => {
1062
- if (!acc.some((x) => fn(v, x, array)))
1063
- acc.push(v);
1064
- return acc;
1065
- }, []);
1066
- }
1067
- function useArrayUnique(list, compareFn) {
1068
- return vue.computed(() => {
1069
- const resolvedList = vue.toValue(list).map((element) => vue.toValue(element));
1070
- return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
1071
- });
1072
- }
1073
-
1074
- function useCounter(initialValue = 0, options = {}) {
1075
- let _initialValue = vue.unref(initialValue);
1076
- const count = vue.shallowRef(initialValue);
1077
- const {
1078
- max = Number.POSITIVE_INFINITY,
1079
- min = Number.NEGATIVE_INFINITY
1080
- } = options;
1081
- const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
1082
- const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
1083
- const get = () => count.value;
1084
- const set = (val) => count.value = Math.max(min, Math.min(max, val));
1085
- const reset = (val = _initialValue) => {
1086
- _initialValue = val;
1087
- return set(val);
1088
- };
1089
- return { count, inc, dec, get, set, reset };
1090
- }
1091
-
1092
- const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
1093
- 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;
1094
- function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
1095
- let m = hours < 12 ? "AM" : "PM";
1096
- if (hasPeriod)
1097
- m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
1098
- return isLowercase ? m.toLowerCase() : m;
1099
- }
1100
- function formatOrdinal(num) {
1101
- const suffixes = ["th", "st", "nd", "rd"];
1102
- const v = num % 100;
1103
- return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
1104
- }
1105
- function formatDate(date, formatStr, options = {}) {
1106
- var _a;
1107
- const years = date.getFullYear();
1108
- const month = date.getMonth();
1109
- const days = date.getDate();
1110
- const hours = date.getHours();
1111
- const minutes = date.getMinutes();
1112
- const seconds = date.getSeconds();
1113
- const milliseconds = date.getMilliseconds();
1114
- const day = date.getDay();
1115
- const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
1116
- const stripTimeZone = (dateString) => {
1117
- var _a2;
1118
- return (_a2 = dateString.split(" ")[1]) != null ? _a2 : "";
1119
- };
1120
- const matches = {
1121
- Yo: () => formatOrdinal(years),
1122
- YY: () => String(years).slice(-2),
1123
- YYYY: () => years,
1124
- M: () => month + 1,
1125
- Mo: () => formatOrdinal(month + 1),
1126
- MM: () => `${month + 1}`.padStart(2, "0"),
1127
- MMM: () => date.toLocaleDateString(vue.toValue(options.locales), { month: "short" }),
1128
- MMMM: () => date.toLocaleDateString(vue.toValue(options.locales), { month: "long" }),
1129
- D: () => String(days),
1130
- Do: () => formatOrdinal(days),
1131
- DD: () => `${days}`.padStart(2, "0"),
1132
- H: () => String(hours),
1133
- Ho: () => formatOrdinal(hours),
1134
- HH: () => `${hours}`.padStart(2, "0"),
1135
- h: () => `${hours % 12 || 12}`.padStart(1, "0"),
1136
- ho: () => formatOrdinal(hours % 12 || 12),
1137
- hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
1138
- m: () => String(minutes),
1139
- mo: () => formatOrdinal(minutes),
1140
- mm: () => `${minutes}`.padStart(2, "0"),
1141
- s: () => String(seconds),
1142
- so: () => formatOrdinal(seconds),
1143
- ss: () => `${seconds}`.padStart(2, "0"),
1144
- SSS: () => `${milliseconds}`.padStart(3, "0"),
1145
- d: () => day,
1146
- dd: () => date.toLocaleDateString(vue.toValue(options.locales), { weekday: "narrow" }),
1147
- ddd: () => date.toLocaleDateString(vue.toValue(options.locales), { weekday: "short" }),
1148
- dddd: () => date.toLocaleDateString(vue.toValue(options.locales), { weekday: "long" }),
1149
- A: () => meridiem(hours, minutes),
1150
- AA: () => meridiem(hours, minutes, false, true),
1151
- a: () => meridiem(hours, minutes, true),
1152
- aa: () => meridiem(hours, minutes, true, true),
1153
- z: () => stripTimeZone(date.toLocaleDateString(vue.toValue(options.locales), { timeZoneName: "shortOffset" })),
1154
- zz: () => stripTimeZone(date.toLocaleDateString(vue.toValue(options.locales), { timeZoneName: "shortOffset" })),
1155
- zzz: () => stripTimeZone(date.toLocaleDateString(vue.toValue(options.locales), { timeZoneName: "shortOffset" })),
1156
- zzzz: () => stripTimeZone(date.toLocaleDateString(vue.toValue(options.locales), { timeZoneName: "longOffset" }))
1157
- };
1158
- return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1159
- var _a2, _b;
1160
- return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) != null ? _b : match;
1161
- });
1162
- }
1163
- function normalizeDate(date) {
1164
- if (date === null)
1165
- return new Date(Number.NaN);
1166
- if (date === void 0)
1167
- return /* @__PURE__ */ new Date();
1168
- if (date instanceof Date)
1169
- return new Date(date);
1170
- if (typeof date === "string" && !/Z$/i.test(date)) {
1171
- const d = date.match(REGEX_PARSE);
1172
- if (d) {
1173
- const m = d[2] - 1 || 0;
1174
- const ms = (d[7] || "0").substring(0, 3);
1175
- return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
1176
- }
1177
- }
1178
- return new Date(date);
1179
- }
1180
- function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1181
- return vue.computed(() => formatDate(normalizeDate(vue.toValue(date)), vue.toValue(formatStr), options));
1182
- }
1183
-
1184
- function useIntervalFn(cb, interval = 1e3, options = {}) {
1185
- const {
1186
- immediate = true,
1187
- immediateCallback = false
1188
- } = options;
1189
- let timer = null;
1190
- const isActive = vue.shallowRef(false);
1191
- function clean() {
1192
- if (timer) {
1193
- clearInterval(timer);
1194
- timer = null;
1195
- }
1196
- }
1197
- function pause() {
1198
- isActive.value = false;
1199
- clean();
1200
- }
1201
- function resume() {
1202
- const intervalValue = vue.toValue(interval);
1203
- if (intervalValue <= 0)
1204
- return;
1205
- isActive.value = true;
1206
- if (immediateCallback)
1207
- cb();
1208
- clean();
1209
- if (isActive.value)
1210
- timer = setInterval(cb, intervalValue);
1211
- }
1212
- if (immediate && isClient)
1213
- resume();
1214
- if (vue.isRef(interval) || typeof interval === "function") {
1215
- const stopWatch = vue.watch(interval, () => {
1216
- if (isActive.value && isClient)
1217
- resume();
1218
- });
1219
- tryOnScopeDispose(stopWatch);
1220
- }
1221
- tryOnScopeDispose(pause);
1222
- return {
1223
- isActive,
1224
- pause,
1225
- resume
1226
- };
1227
- }
1228
-
1229
- function useInterval(interval = 1e3, options = {}) {
1230
- const {
1231
- controls: exposeControls = false,
1232
- immediate = true,
1233
- callback
1234
- } = options;
1235
- const counter = vue.shallowRef(0);
1236
- const update = () => counter.value += 1;
1237
- const reset = () => {
1238
- counter.value = 0;
1239
- };
1240
- const controls = useIntervalFn(
1241
- callback ? () => {
1242
- update();
1243
- callback(counter.value);
1244
- } : update,
1245
- interval,
1246
- { immediate }
1247
- );
1248
- if (exposeControls) {
1249
- return {
1250
- counter,
1251
- reset,
1252
- ...controls
1253
- };
1254
- } else {
1255
- return counter;
1256
- }
1257
- }
1258
-
1259
- function useLastChanged(source, options = {}) {
1260
- var _a;
1261
- const ms = vue.shallowRef((_a = options.initialValue) != null ? _a : null);
1262
- vue.watch(
1263
- source,
1264
- () => ms.value = timestamp(),
1265
- options
1266
- );
1267
- return ms;
1268
- }
1269
-
1270
- function useTimeoutFn(cb, interval, options = {}) {
1271
- const {
1272
- immediate = true,
1273
- immediateCallback = false
1274
- } = options;
1275
- const isPending = vue.shallowRef(false);
1276
- let timer = null;
1277
- function clear() {
1278
- if (timer) {
1279
- clearTimeout(timer);
1280
- timer = null;
1281
- }
1282
- }
1283
- function stop() {
1284
- isPending.value = false;
1285
- clear();
1286
- }
1287
- function start(...args) {
1288
- if (immediateCallback)
1289
- cb();
1290
- clear();
1291
- isPending.value = true;
1292
- timer = setTimeout(() => {
1293
- isPending.value = false;
1294
- timer = null;
1295
- cb(...args);
1296
- }, vue.toValue(interval));
1297
- }
1298
- if (immediate) {
1299
- isPending.value = true;
1300
- if (isClient)
1301
- start();
1302
- }
1303
- tryOnScopeDispose(stop);
1304
- return {
1305
- isPending: vue.readonly(isPending),
1306
- start,
1307
- stop
1308
- };
1309
- }
1310
-
1311
- function useTimeout(interval = 1e3, options = {}) {
1312
- const {
1313
- controls: exposeControls = false,
1314
- callback
1315
- } = options;
1316
- const controls = useTimeoutFn(
1317
- callback != null ? callback : noop,
1318
- interval,
1319
- options
1320
- );
1321
- const ready = vue.computed(() => !controls.isPending.value);
1322
- if (exposeControls) {
1323
- return {
1324
- ready,
1325
- ...controls
1326
- };
1327
- } else {
1328
- return ready;
1329
- }
1330
- }
1331
-
1332
- function useToNumber(value, options = {}) {
1333
- const {
1334
- method = "parseFloat",
1335
- radix,
1336
- nanToZero
1337
- } = options;
1338
- return vue.computed(() => {
1339
- let resolved = vue.toValue(value);
1340
- if (typeof method === "function")
1341
- resolved = method(resolved);
1342
- else if (typeof resolved === "string")
1343
- resolved = Number[method](resolved, radix);
1344
- if (nanToZero && Number.isNaN(resolved))
1345
- resolved = 0;
1346
- return resolved;
1347
- });
1348
- }
1349
-
1350
- function useToString(value) {
1351
- return vue.computed(() => `${vue.toValue(value)}`);
1352
- }
1353
-
1354
- function useToggle(initialValue = false, options = {}) {
1355
- const {
1356
- truthyValue = true,
1357
- falsyValue = false
1358
- } = options;
1359
- const valueIsRef = vue.isRef(initialValue);
1360
- const _value = vue.shallowRef(initialValue);
1361
- function toggle(value) {
1362
- if (arguments.length) {
1363
- _value.value = value;
1364
- return _value.value;
1365
- } else {
1366
- const truthy = vue.toValue(truthyValue);
1367
- _value.value = _value.value === truthy ? vue.toValue(falsyValue) : truthy;
1368
- return _value.value;
1369
- }
1370
- }
1371
- if (valueIsRef)
1372
- return toggle;
1373
- else
1374
- return [_value, toggle];
1375
- }
1376
-
1377
- function watchArray(source, cb, options) {
1378
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : vue.toValue(source)];
1379
- return vue.watch(source, (newList, _, onCleanup) => {
1380
- const oldListRemains = Array.from({ length: oldList.length });
1381
- const added = [];
1382
- for (const obj of newList) {
1383
- let found = false;
1384
- for (let i = 0; i < oldList.length; i++) {
1385
- if (!oldListRemains[i] && obj === oldList[i]) {
1386
- oldListRemains[i] = true;
1387
- found = true;
1388
- break;
1389
- }
1390
- }
1391
- if (!found)
1392
- added.push(obj);
1393
- }
1394
- const removed = oldList.filter((_2, i) => !oldListRemains[i]);
1395
- cb(newList, oldList, added, removed, onCleanup);
1396
- oldList = [...newList];
1397
- }, options);
1398
- }
1399
-
1400
- function watchAtMost(source, cb, options) {
1401
- const {
1402
- count,
1403
- ...watchOptions
1404
- } = options;
1405
- const current = vue.shallowRef(0);
1406
- const stop = watchWithFilter(
1407
- source,
1408
- (...args) => {
1409
- current.value += 1;
1410
- if (current.value >= vue.toValue(count))
1411
- vue.nextTick(() => stop());
1412
- cb(...args);
1413
- },
1414
- watchOptions
1415
- );
1416
- return { count: current, stop };
1417
- }
1418
-
1419
- function watchDebounced(source, cb, options = {}) {
1420
- const {
1421
- debounce = 0,
1422
- maxWait = void 0,
1423
- ...watchOptions
1424
- } = options;
1425
- return watchWithFilter(
1426
- source,
1427
- cb,
1428
- {
1429
- ...watchOptions,
1430
- eventFilter: debounceFilter(debounce, { maxWait })
1431
- }
1432
- );
1433
- }
1434
-
1435
- function watchDeep(source, cb, options) {
1436
- return vue.watch(
1437
- source,
1438
- cb,
1439
- {
1440
- ...options,
1441
- deep: true
1442
- }
1443
- );
1444
- }
1445
-
1446
- function watchIgnorable(source, cb, options = {}) {
1447
- const {
1448
- eventFilter = bypassFilter,
1449
- ...watchOptions
1450
- } = options;
1451
- const filteredCb = createFilterWrapper(
1452
- eventFilter,
1453
- cb
1454
- );
1455
- let ignoreUpdates;
1456
- let ignorePrevAsyncUpdates;
1457
- let stop;
1458
- if (watchOptions.flush === "sync") {
1459
- const ignore = vue.shallowRef(false);
1460
- ignorePrevAsyncUpdates = () => {
1461
- };
1462
- ignoreUpdates = (updater) => {
1463
- ignore.value = true;
1464
- updater();
1465
- ignore.value = false;
1466
- };
1467
- stop = vue.watch(
1468
- source,
1469
- (...args) => {
1470
- if (!ignore.value)
1471
- filteredCb(...args);
1472
- },
1473
- watchOptions
1474
- );
1475
- } else {
1476
- const disposables = [];
1477
- const ignoreCounter = vue.shallowRef(0);
1478
- const syncCounter = vue.shallowRef(0);
1479
- ignorePrevAsyncUpdates = () => {
1480
- ignoreCounter.value = syncCounter.value;
1481
- };
1482
- disposables.push(
1483
- vue.watch(
1484
- source,
1485
- () => {
1486
- syncCounter.value++;
1487
- },
1488
- { ...watchOptions, flush: "sync" }
1489
- )
1490
- );
1491
- ignoreUpdates = (updater) => {
1492
- const syncCounterPrev = syncCounter.value;
1493
- updater();
1494
- ignoreCounter.value += syncCounter.value - syncCounterPrev;
1495
- };
1496
- disposables.push(
1497
- vue.watch(
1498
- source,
1499
- (...args) => {
1500
- const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
1501
- ignoreCounter.value = 0;
1502
- syncCounter.value = 0;
1503
- if (ignore)
1504
- return;
1505
- filteredCb(...args);
1506
- },
1507
- watchOptions
1508
- )
1509
- );
1510
- stop = () => {
1511
- disposables.forEach((fn) => fn());
1512
- };
1513
- }
1514
- return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
1515
- }
1516
-
1517
- function watchImmediate(source, cb, options) {
1518
- return vue.watch(
1519
- source,
1520
- cb,
1521
- {
1522
- ...options,
1523
- immediate: true
1524
- }
1525
- );
1526
- }
1527
-
1528
- function watchOnce(source, cb, options) {
1529
- const stop = vue.watch(source, (...args) => {
1530
- vue.nextTick(() => stop());
1531
- return cb(...args);
1532
- }, options);
1533
- return stop;
1534
- }
1535
-
1536
- function watchThrottled(source, cb, options = {}) {
1537
- const {
1538
- throttle = 0,
1539
- trailing = true,
1540
- leading = true,
1541
- ...watchOptions
1542
- } = options;
1543
- return watchWithFilter(
1544
- source,
1545
- cb,
1546
- {
1547
- ...watchOptions,
1548
- eventFilter: throttleFilter(throttle, trailing, leading)
1549
- }
1550
- );
1551
- }
1552
-
1553
- function watchTriggerable(source, cb, options = {}) {
1554
- let cleanupFn;
1555
- function onEffect() {
1556
- if (!cleanupFn)
1557
- return;
1558
- const fn = cleanupFn;
1559
- cleanupFn = void 0;
1560
- fn();
1561
- }
1562
- function onCleanup(callback) {
1563
- cleanupFn = callback;
1564
- }
1565
- const _cb = (value, oldValue) => {
1566
- onEffect();
1567
- return cb(value, oldValue, onCleanup);
1568
- };
1569
- const res = watchIgnorable(source, _cb, options);
1570
- const { ignoreUpdates } = res;
1571
- const trigger = () => {
1572
- let res2;
1573
- ignoreUpdates(() => {
1574
- res2 = _cb(getWatchSources(source), getOldValue(source));
1575
- });
1576
- return res2;
1577
- };
1578
- return {
1579
- ...res,
1580
- trigger
1581
- };
1582
- }
1583
- function getWatchSources(sources) {
1584
- if (vue.isReactive(sources))
1585
- return sources;
1586
- if (Array.isArray(sources))
1587
- return sources.map((item) => vue.toValue(item));
1588
- return vue.toValue(sources);
1589
- }
1590
- function getOldValue(source) {
1591
- return Array.isArray(source) ? source.map(() => void 0) : void 0;
1592
- }
1593
-
1594
- function whenever(source, cb, options) {
1595
- const stop = vue.watch(
1596
- source,
1597
- (v, ov, onInvalidate) => {
1598
- if (v) {
1599
- if (options == null ? void 0 : options.once)
1600
- vue.nextTick(() => stop());
1601
- cb(v, ov, onInvalidate);
1602
- }
1603
- },
1604
- {
1605
- ...options,
1606
- once: false
1607
- }
1608
- );
1609
- return stop;
1610
- }
1611
-
1612
- exports.assert = assert;
1613
- exports.autoResetRef = refAutoReset;
1614
- exports.bypassFilter = bypassFilter;
1615
- exports.camelize = camelize;
1616
- exports.clamp = clamp;
1617
- exports.computedEager = computedEager;
1618
- exports.computedWithControl = computedWithControl;
1619
- exports.containsProp = containsProp;
1620
- exports.controlledComputed = computedWithControl;
1621
- exports.controlledRef = controlledRef;
1622
- exports.createEventHook = createEventHook;
1623
- exports.createFilterWrapper = createFilterWrapper;
1624
- exports.createGlobalState = createGlobalState;
1625
- exports.createInjectionState = createInjectionState;
1626
- exports.createReactiveFn = reactify;
1627
- exports.createRef = createRef;
1628
- exports.createSharedComposable = createSharedComposable;
1629
- exports.createSingletonPromise = createSingletonPromise;
1630
- exports.debounceFilter = debounceFilter;
1631
- exports.debouncedRef = refDebounced;
1632
- exports.debouncedWatch = watchDebounced;
1633
- exports.eagerComputed = computedEager;
1634
- exports.extendRef = extendRef;
1635
- exports.formatDate = formatDate;
1636
- exports.get = get;
1637
- exports.getLifeCycleTarget = getLifeCycleTarget;
1638
- exports.hasOwn = hasOwn;
1639
- exports.hyphenate = hyphenate;
1640
- exports.identity = identity;
1641
- exports.ignorableWatch = watchIgnorable;
1642
- exports.increaseWithUnit = increaseWithUnit;
1643
- exports.injectLocal = injectLocal;
1644
- exports.invoke = invoke;
1645
- exports.isClient = isClient;
1646
- exports.isDef = isDef;
1647
- exports.isDefined = isDefined;
1648
- exports.isIOS = isIOS;
1649
- exports.isObject = isObject;
1650
- exports.isWorker = isWorker;
1651
- exports.makeDestructurable = makeDestructurable;
1652
- exports.noop = noop;
1653
- exports.normalizeDate = normalizeDate;
1654
- exports.notNullish = notNullish;
1655
- exports.now = now;
1656
- exports.objectEntries = objectEntries;
1657
- exports.objectOmit = objectOmit;
1658
- exports.objectPick = objectPick;
1659
- exports.pausableFilter = pausableFilter;
1660
- exports.pausableWatch = watchPausable;
1661
- exports.promiseTimeout = promiseTimeout;
1662
- exports.provideLocal = provideLocal;
1663
- exports.pxValue = pxValue;
1664
- exports.rand = rand;
1665
- exports.reactify = reactify;
1666
- exports.reactifyObject = reactifyObject;
1667
- exports.reactiveComputed = reactiveComputed;
1668
- exports.reactiveOmit = reactiveOmit;
1669
- exports.reactivePick = reactivePick;
1670
- exports.refAutoReset = refAutoReset;
1671
- exports.refDebounced = refDebounced;
1672
- exports.refDefault = refDefault;
1673
- exports.refThrottled = refThrottled;
1674
- exports.refWithControl = refWithControl;
1675
- exports.resolveRef = resolveRef;
1676
- exports.resolveUnref = resolveUnref;
1677
- exports.set = set;
1678
- exports.syncRef = syncRef;
1679
- exports.syncRefs = syncRefs;
1680
- exports.throttleFilter = throttleFilter;
1681
- exports.throttledRef = refThrottled;
1682
- exports.throttledWatch = watchThrottled;
1683
- exports.timestamp = timestamp;
1684
- exports.toArray = toArray;
1685
- exports.toReactive = toReactive;
1686
- exports.toRef = toRef;
1687
- exports.toRefs = toRefs;
1688
- exports.toValue = toValue;
1689
- exports.tryOnBeforeMount = tryOnBeforeMount;
1690
- exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
1691
- exports.tryOnMounted = tryOnMounted;
1692
- exports.tryOnScopeDispose = tryOnScopeDispose;
1693
- exports.tryOnUnmounted = tryOnUnmounted;
1694
- exports.until = until;
1695
- exports.useArrayDifference = useArrayDifference;
1696
- exports.useArrayEvery = useArrayEvery;
1697
- exports.useArrayFilter = useArrayFilter;
1698
- exports.useArrayFind = useArrayFind;
1699
- exports.useArrayFindIndex = useArrayFindIndex;
1700
- exports.useArrayFindLast = useArrayFindLast;
1701
- exports.useArrayIncludes = useArrayIncludes;
1702
- exports.useArrayJoin = useArrayJoin;
1703
- exports.useArrayMap = useArrayMap;
1704
- exports.useArrayReduce = useArrayReduce;
1705
- exports.useArraySome = useArraySome;
1706
- exports.useArrayUnique = useArrayUnique;
1707
- exports.useCounter = useCounter;
1708
- exports.useDateFormat = useDateFormat;
1709
- exports.useDebounce = refDebounced;
1710
- exports.useDebounceFn = useDebounceFn;
1711
- exports.useInterval = useInterval;
1712
- exports.useIntervalFn = useIntervalFn;
1713
- exports.useLastChanged = useLastChanged;
1714
- exports.useThrottle = refThrottled;
1715
- exports.useThrottleFn = useThrottleFn;
1716
- exports.useTimeout = useTimeout;
1717
- exports.useTimeoutFn = useTimeoutFn;
1718
- exports.useToNumber = useToNumber;
1719
- exports.useToString = useToString;
1720
- exports.useToggle = useToggle;
1721
- exports.watchArray = watchArray;
1722
- exports.watchAtMost = watchAtMost;
1723
- exports.watchDebounced = watchDebounced;
1724
- exports.watchDeep = watchDeep;
1725
- exports.watchIgnorable = watchIgnorable;
1726
- exports.watchImmediate = watchImmediate;
1727
- exports.watchOnce = watchOnce;
1728
- exports.watchPausable = watchPausable;
1729
- exports.watchThrottled = watchThrottled;
1730
- exports.watchTriggerable = watchTriggerable;
1731
- exports.watchWithFilter = watchWithFilter;
1732
- exports.whenever = whenever;