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

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