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