@vueuse/components 12.2.0 → 12.4.0
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.cjs +468 -174
- package/index.d.cts +161 -26
- package/index.d.mts +161 -26
- package/index.d.ts +161 -26
- package/index.iife.js +468 -174
- package/index.iife.min.js +1 -1
- package/index.mjs +445 -153
- package/package.json +3 -3
package/index.cjs
CHANGED
|
@@ -20,12 +20,12 @@ const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
const defaultWindow = shared.isClient ? window :
|
|
23
|
+
const defaultWindow = shared.isClient ? window : undefined;
|
|
24
24
|
|
|
25
25
|
function unrefElement(elRef) {
|
|
26
26
|
var _a;
|
|
27
|
-
const plain =
|
|
28
|
-
return (_a = plain == null ?
|
|
27
|
+
const plain = vue.toValue(elRef);
|
|
28
|
+
return (_a = plain == null ? undefined : plain.$el) != null ? _a : plain;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function useEventListener(...args) {
|
|
@@ -41,10 +41,8 @@ function useEventListener(...args) {
|
|
|
41
41
|
}
|
|
42
42
|
if (!target)
|
|
43
43
|
return shared.noop;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!Array.isArray(listeners))
|
|
47
|
-
listeners = [listeners];
|
|
44
|
+
events = shared.toArray(events);
|
|
45
|
+
listeners = shared.toArray(listeners);
|
|
48
46
|
const cleanups = [];
|
|
49
47
|
const cleanup = () => {
|
|
50
48
|
cleanups.forEach((fn) => fn());
|
|
@@ -55,7 +53,7 @@ function useEventListener(...args) {
|
|
|
55
53
|
return () => el.removeEventListener(event, listener, options2);
|
|
56
54
|
};
|
|
57
55
|
const stopWatch = vue.watch(
|
|
58
|
-
() => [unrefElement(target),
|
|
56
|
+
() => [unrefElement(target), vue.toValue(options)],
|
|
59
57
|
([el, options2]) => {
|
|
60
58
|
cleanup();
|
|
61
59
|
if (!el)
|
|
@@ -89,7 +87,7 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
89
87
|
}
|
|
90
88
|
let shouldListen = true;
|
|
91
89
|
const shouldIgnore = (event) => {
|
|
92
|
-
return
|
|
90
|
+
return vue.toValue(ignore).some((target2) => {
|
|
93
91
|
if (typeof target2 === "string") {
|
|
94
92
|
return Array.from(window.document.querySelectorAll(target2)).some((el) => el === event.target || event.composedPath().includes(el));
|
|
95
93
|
} else {
|
|
@@ -99,11 +97,11 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
99
97
|
});
|
|
100
98
|
};
|
|
101
99
|
function hasMultipleRoots(target2) {
|
|
102
|
-
const vm =
|
|
100
|
+
const vm = vue.toValue(target2);
|
|
103
101
|
return vm && vm.$.subTree.shapeFlag === 16;
|
|
104
102
|
}
|
|
105
103
|
function checkMultipleRoots(target2, event) {
|
|
106
|
-
const vm =
|
|
104
|
+
const vm = vue.toValue(target2);
|
|
107
105
|
const children = vm.$.subTree && vm.$.subTree.children;
|
|
108
106
|
if (children == null || !Array.isArray(children))
|
|
109
107
|
return false;
|
|
@@ -144,11 +142,11 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
144
142
|
setTimeout(() => {
|
|
145
143
|
var _a;
|
|
146
144
|
const el = unrefElement(target);
|
|
147
|
-
if (((_a = window.document.activeElement) == null ?
|
|
145
|
+
if (((_a = window.document.activeElement) == null ? undefined : _a.tagName) === "IFRAME" && !(el == null ? undefined : el.contains(window.document.activeElement))) {
|
|
148
146
|
handler(event);
|
|
149
147
|
}
|
|
150
148
|
}, 0);
|
|
151
|
-
})
|
|
149
|
+
}, { passive: true })
|
|
152
150
|
].filter(Boolean);
|
|
153
151
|
const stop = () => cleanup.forEach((fn) => fn());
|
|
154
152
|
return stop;
|
|
@@ -207,7 +205,7 @@ function onKeyStroke(...args) {
|
|
|
207
205
|
} = options;
|
|
208
206
|
const predicate = createKeyPredicate(key);
|
|
209
207
|
const listener = (e) => {
|
|
210
|
-
if (e.repeat &&
|
|
208
|
+
if (e.repeat && vue.toValue(dedupe))
|
|
211
209
|
return;
|
|
212
210
|
if (predicate(e))
|
|
213
211
|
handler(e);
|
|
@@ -218,7 +216,7 @@ function onKeyStroke(...args) {
|
|
|
218
216
|
const vOnKeyStroke = {
|
|
219
217
|
mounted(el, binding) {
|
|
220
218
|
var _a, _b;
|
|
221
|
-
const keys = (_b = (_a = binding.arg) == null ?
|
|
219
|
+
const keys = (_b = (_a = binding.arg) == null ? undefined : _a.split(",")) != null ? _b : true;
|
|
222
220
|
if (typeof binding.value === "function") {
|
|
223
221
|
onKeyStroke(keys, binding.value, {
|
|
224
222
|
target: el
|
|
@@ -245,23 +243,23 @@ function onLongPress(target, handler, options) {
|
|
|
245
243
|
function clear() {
|
|
246
244
|
if (timeout) {
|
|
247
245
|
clearTimeout(timeout);
|
|
248
|
-
timeout =
|
|
246
|
+
timeout = undefined;
|
|
249
247
|
}
|
|
250
|
-
posStart =
|
|
251
|
-
startTimestamp =
|
|
248
|
+
posStart = undefined;
|
|
249
|
+
startTimestamp = undefined;
|
|
252
250
|
hasLongPressed = false;
|
|
253
251
|
}
|
|
254
252
|
function onRelease(ev) {
|
|
255
253
|
var _a2, _b2, _c;
|
|
256
254
|
const [_startTimestamp, _posStart, _hasLongPressed] = [startTimestamp, posStart, hasLongPressed];
|
|
257
255
|
clear();
|
|
258
|
-
if (!(options == null ?
|
|
256
|
+
if (!(options == null ? undefined : options.onMouseUp) || !_posStart || !_startTimestamp)
|
|
259
257
|
return;
|
|
260
|
-
if (((_a2 = options == null ?
|
|
258
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
261
259
|
return;
|
|
262
|
-
if ((_b2 = options == null ?
|
|
260
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
263
261
|
ev.preventDefault();
|
|
264
|
-
if ((_c = options == null ?
|
|
262
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
265
263
|
ev.stopPropagation();
|
|
266
264
|
const dx = ev.x - _posStart.x;
|
|
267
265
|
const dy = ev.y - _posStart.y;
|
|
@@ -270,12 +268,12 @@ function onLongPress(target, handler, options) {
|
|
|
270
268
|
}
|
|
271
269
|
function onDown(ev) {
|
|
272
270
|
var _a2, _b2, _c, _d;
|
|
273
|
-
if (((_a2 = options == null ?
|
|
271
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
274
272
|
return;
|
|
275
273
|
clear();
|
|
276
|
-
if ((_b2 = options == null ?
|
|
274
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
277
275
|
ev.preventDefault();
|
|
278
|
-
if ((_c = options == null ?
|
|
276
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
279
277
|
ev.stopPropagation();
|
|
280
278
|
posStart = {
|
|
281
279
|
x: ev.x,
|
|
@@ -287,28 +285,28 @@ function onLongPress(target, handler, options) {
|
|
|
287
285
|
hasLongPressed = true;
|
|
288
286
|
handler(ev);
|
|
289
287
|
},
|
|
290
|
-
(_d = options == null ?
|
|
288
|
+
(_d = options == null ? undefined : options.delay) != null ? _d : DEFAULT_DELAY
|
|
291
289
|
);
|
|
292
290
|
}
|
|
293
291
|
function onMove(ev) {
|
|
294
292
|
var _a2, _b2, _c, _d;
|
|
295
|
-
if (((_a2 = options == null ?
|
|
293
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
296
294
|
return;
|
|
297
|
-
if (!posStart || (options == null ?
|
|
295
|
+
if (!posStart || (options == null ? undefined : options.distanceThreshold) === false)
|
|
298
296
|
return;
|
|
299
|
-
if ((_b2 = options == null ?
|
|
297
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
300
298
|
ev.preventDefault();
|
|
301
|
-
if ((_c = options == null ?
|
|
299
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
302
300
|
ev.stopPropagation();
|
|
303
301
|
const dx = ev.x - posStart.x;
|
|
304
302
|
const dy = ev.y - posStart.y;
|
|
305
303
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
306
|
-
if (distance >= ((_d = options == null ?
|
|
304
|
+
if (distance >= ((_d = options == null ? undefined : options.distanceThreshold) != null ? _d : DEFAULT_THRESHOLD))
|
|
307
305
|
clear();
|
|
308
306
|
}
|
|
309
307
|
const listenerOptions = {
|
|
310
|
-
capture: (_a = options == null ?
|
|
311
|
-
once: (_b = options == null ?
|
|
308
|
+
capture: (_a = options == null ? undefined : options.modifiers) == null ? undefined : _a.capture,
|
|
309
|
+
once: (_b = options == null ? undefined : options.modifiers) == null ? undefined : _b.once
|
|
312
310
|
};
|
|
313
311
|
const cleanup = [
|
|
314
312
|
useEventListener(elementRef, "pointerdown", onDown, listenerOptions),
|
|
@@ -396,7 +394,7 @@ const UseClipboard = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
396
394
|
const data = vue.reactive(core.useClipboard(props));
|
|
397
395
|
return () => {
|
|
398
396
|
var _a;
|
|
399
|
-
return (_a = slots.default) == null ?
|
|
397
|
+
return (_a = slots.default) == null ? undefined : _a.call(slots, data);
|
|
400
398
|
};
|
|
401
399
|
}
|
|
402
400
|
});
|
|
@@ -416,7 +414,7 @@ function getSSRHandler(key, fallback) {
|
|
|
416
414
|
const ssrWidthSymbol = Symbol("vueuse-ssr-width");
|
|
417
415
|
function useSSRWidth() {
|
|
418
416
|
const ssrWidth = vue.hasInjectionContext() ? shared.injectLocal(ssrWidthSymbol, null) : null;
|
|
419
|
-
return typeof ssrWidth === "number" ? ssrWidth :
|
|
417
|
+
return typeof ssrWidth === "number" ? ssrWidth : undefined;
|
|
420
418
|
}
|
|
421
419
|
|
|
422
420
|
function useMounted() {
|
|
@@ -458,7 +456,7 @@ function useMediaQuery(query, options = {}) {
|
|
|
458
456
|
const stopWatch = vue.watchEffect(() => {
|
|
459
457
|
if (ssrSupport.value) {
|
|
460
458
|
ssrSupport.value = !isSupported.value;
|
|
461
|
-
const queryStrings =
|
|
459
|
+
const queryStrings = vue.toValue(query).split(",");
|
|
462
460
|
matches.value = queryStrings.some((queryString) => {
|
|
463
461
|
const not = queryString.includes("not all");
|
|
464
462
|
const minWidth = queryString.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/);
|
|
@@ -477,7 +475,7 @@ function useMediaQuery(query, options = {}) {
|
|
|
477
475
|
if (!isSupported.value)
|
|
478
476
|
return;
|
|
479
477
|
cleanup();
|
|
480
|
-
mediaQuery = window.matchMedia(
|
|
478
|
+
mediaQuery = window.matchMedia(vue.toValue(query));
|
|
481
479
|
if ("addEventListener" in mediaQuery)
|
|
482
480
|
mediaQuery.addEventListener("change", handler);
|
|
483
481
|
else
|
|
@@ -487,7 +485,7 @@ function useMediaQuery(query, options = {}) {
|
|
|
487
485
|
shared.tryOnScopeDispose(() => {
|
|
488
486
|
stopWatch();
|
|
489
487
|
cleanup();
|
|
490
|
-
mediaQuery =
|
|
488
|
+
mediaQuery = undefined;
|
|
491
489
|
});
|
|
492
490
|
return vue.computed(() => matches.value);
|
|
493
491
|
}
|
|
@@ -552,6 +550,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
552
550
|
initOnMounted
|
|
553
551
|
} = options;
|
|
554
552
|
const data = (shallow ? vue.shallowRef : vue.ref)(typeof defaults === "function" ? defaults() : defaults);
|
|
553
|
+
const keyComputed = vue.computed(() => vue.toValue(key));
|
|
555
554
|
if (!storage) {
|
|
556
555
|
try {
|
|
557
556
|
storage = getSSRHandler("getDefaultStorage", () => {
|
|
@@ -564,7 +563,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
564
563
|
}
|
|
565
564
|
if (!storage)
|
|
566
565
|
return data;
|
|
567
|
-
const rawInit =
|
|
566
|
+
const rawInit = vue.toValue(defaults);
|
|
568
567
|
const type = guessSerializerType(rawInit);
|
|
569
568
|
const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
570
569
|
const { pause: pauseWatch, resume: resumeWatch } = shared.pausableWatch(
|
|
@@ -572,10 +571,11 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
572
571
|
() => write(data.value),
|
|
573
572
|
{ flush, deep, eventFilter }
|
|
574
573
|
);
|
|
574
|
+
vue.watch(keyComputed, () => update(), { flush });
|
|
575
575
|
if (window && listenToStorageChanges) {
|
|
576
576
|
shared.tryOnMounted(() => {
|
|
577
577
|
if (storage instanceof Storage)
|
|
578
|
-
useEventListener(window, "storage", update);
|
|
578
|
+
useEventListener(window, "storage", update, { passive: true });
|
|
579
579
|
else
|
|
580
580
|
useEventListener(window, customStorageEventName, updateFromCustomEvent);
|
|
581
581
|
if (initOnMounted)
|
|
@@ -587,7 +587,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
587
587
|
function dispatchWriteEvent(oldValue, newValue) {
|
|
588
588
|
if (window) {
|
|
589
589
|
const payload = {
|
|
590
|
-
key,
|
|
590
|
+
key: keyComputed.value,
|
|
591
591
|
oldValue,
|
|
592
592
|
newValue,
|
|
593
593
|
storageArea: storage
|
|
@@ -599,14 +599,14 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
599
599
|
}
|
|
600
600
|
function write(v) {
|
|
601
601
|
try {
|
|
602
|
-
const oldValue = storage.getItem(
|
|
602
|
+
const oldValue = storage.getItem(keyComputed.value);
|
|
603
603
|
if (v == null) {
|
|
604
604
|
dispatchWriteEvent(oldValue, null);
|
|
605
|
-
storage.removeItem(
|
|
605
|
+
storage.removeItem(keyComputed.value);
|
|
606
606
|
} else {
|
|
607
607
|
const serialized = serializer.write(v);
|
|
608
608
|
if (oldValue !== serialized) {
|
|
609
|
-
storage.setItem(
|
|
609
|
+
storage.setItem(keyComputed.value, serialized);
|
|
610
610
|
dispatchWriteEvent(oldValue, serialized);
|
|
611
611
|
}
|
|
612
612
|
}
|
|
@@ -615,10 +615,10 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
function read(event) {
|
|
618
|
-
const rawValue = event ? event.newValue : storage.getItem(
|
|
618
|
+
const rawValue = event ? event.newValue : storage.getItem(keyComputed.value);
|
|
619
619
|
if (rawValue == null) {
|
|
620
620
|
if (writeDefaults && rawInit != null)
|
|
621
|
-
storage.setItem(
|
|
621
|
+
storage.setItem(keyComputed.value, serializer.write(rawInit));
|
|
622
622
|
return rawInit;
|
|
623
623
|
} else if (!event && mergeDefaults) {
|
|
624
624
|
const value = serializer.read(rawValue);
|
|
@@ -640,7 +640,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
640
640
|
data.value = rawInit;
|
|
641
641
|
return;
|
|
642
642
|
}
|
|
643
|
-
if (event && event.key !==
|
|
643
|
+
if (event && event.key !== keyComputed.value)
|
|
644
644
|
return;
|
|
645
645
|
pauseWatch();
|
|
646
646
|
try {
|
|
@@ -688,7 +688,7 @@ function useColorMode(options = {}) {
|
|
|
688
688
|
const updateHTMLAttrs = getSSRHandler(
|
|
689
689
|
"updateHTMLAttrs",
|
|
690
690
|
(selector2, attribute2, value) => {
|
|
691
|
-
const el = typeof selector2 === "string" ? window == null ?
|
|
691
|
+
const el = typeof selector2 === "string" ? window == null ? undefined : window.document.querySelector(selector2) : unrefElement(selector2);
|
|
692
692
|
if (!el)
|
|
693
693
|
return;
|
|
694
694
|
const classesToAdd = /* @__PURE__ */ new Set();
|
|
@@ -872,18 +872,18 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
872
872
|
});
|
|
873
873
|
const containerElement = vue.computed(() => {
|
|
874
874
|
var _a;
|
|
875
|
-
return (_a = props.containerElement) != null ? _a :
|
|
875
|
+
return (_a = props.containerElement) != null ? _a : undefined;
|
|
876
876
|
});
|
|
877
877
|
const disabled = vue.computed(() => !!props.disabled);
|
|
878
878
|
const storageValue = props.storageKey && core.useStorage(
|
|
879
879
|
props.storageKey,
|
|
880
|
-
|
|
881
|
-
core.isClient ? props.storageType === "session" ? sessionStorage : localStorage :
|
|
880
|
+
vue.toValue(props.initialValue) || { x: 0, y: 0 },
|
|
881
|
+
core.isClient ? props.storageType === "session" ? sessionStorage : localStorage : undefined
|
|
882
882
|
);
|
|
883
883
|
const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
|
|
884
884
|
const onEnd = (position, event) => {
|
|
885
885
|
var _a;
|
|
886
|
-
(_a = props.onEnd) == null ?
|
|
886
|
+
(_a = props.onEnd) == null ? undefined : _a.call(props, position, event);
|
|
887
887
|
if (!storageValue)
|
|
888
888
|
return;
|
|
889
889
|
storageValue.value.x = position.x;
|
|
@@ -917,10 +917,222 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
917
917
|
}
|
|
918
918
|
});
|
|
919
919
|
|
|
920
|
+
function useMutationObserver(target, callback, options = {}) {
|
|
921
|
+
const { window = defaultWindow, ...mutationOptions } = options;
|
|
922
|
+
let observer;
|
|
923
|
+
const isSupported = useSupported(() => window && "MutationObserver" in window);
|
|
924
|
+
const cleanup = () => {
|
|
925
|
+
if (observer) {
|
|
926
|
+
observer.disconnect();
|
|
927
|
+
observer = undefined;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
const targets = vue.computed(() => {
|
|
931
|
+
const value = vue.toValue(target);
|
|
932
|
+
const items = shared.toArray(value).map(unrefElement).filter(shared.notNullish);
|
|
933
|
+
return new Set(items);
|
|
934
|
+
});
|
|
935
|
+
const stopWatch = vue.watch(
|
|
936
|
+
() => targets.value,
|
|
937
|
+
(targets2) => {
|
|
938
|
+
cleanup();
|
|
939
|
+
if (isSupported.value && targets2.size) {
|
|
940
|
+
observer = new MutationObserver(callback);
|
|
941
|
+
targets2.forEach((el) => observer.observe(el, mutationOptions));
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
{ immediate: true, flush: "post" }
|
|
945
|
+
);
|
|
946
|
+
const takeRecords = () => {
|
|
947
|
+
return observer == null ? undefined : observer.takeRecords();
|
|
948
|
+
};
|
|
949
|
+
const stop = () => {
|
|
950
|
+
stopWatch();
|
|
951
|
+
cleanup();
|
|
952
|
+
};
|
|
953
|
+
shared.tryOnScopeDispose(stop);
|
|
954
|
+
return {
|
|
955
|
+
isSupported,
|
|
956
|
+
stop,
|
|
957
|
+
takeRecords
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function useResizeObserver(target, callback, options = {}) {
|
|
962
|
+
const { window = defaultWindow, ...observerOptions } = options;
|
|
963
|
+
let observer;
|
|
964
|
+
const isSupported = useSupported(() => window && "ResizeObserver" in window);
|
|
965
|
+
const cleanup = () => {
|
|
966
|
+
if (observer) {
|
|
967
|
+
observer.disconnect();
|
|
968
|
+
observer = undefined;
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
const targets = vue.computed(() => {
|
|
972
|
+
const _targets = vue.toValue(target);
|
|
973
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
974
|
+
});
|
|
975
|
+
const stopWatch = vue.watch(
|
|
976
|
+
targets,
|
|
977
|
+
(els) => {
|
|
978
|
+
cleanup();
|
|
979
|
+
if (isSupported.value && window) {
|
|
980
|
+
observer = new ResizeObserver(callback);
|
|
981
|
+
for (const _el of els) {
|
|
982
|
+
if (_el)
|
|
983
|
+
observer.observe(_el, observerOptions);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
{ immediate: true, flush: "post" }
|
|
988
|
+
);
|
|
989
|
+
const stop = () => {
|
|
990
|
+
cleanup();
|
|
991
|
+
stopWatch();
|
|
992
|
+
};
|
|
993
|
+
shared.tryOnScopeDispose(stop);
|
|
994
|
+
return {
|
|
995
|
+
isSupported,
|
|
996
|
+
stop
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function useElementBounding(target, options = {}) {
|
|
1001
|
+
const {
|
|
1002
|
+
reset = true,
|
|
1003
|
+
windowResize = true,
|
|
1004
|
+
windowScroll = true,
|
|
1005
|
+
immediate = true,
|
|
1006
|
+
updateTiming = "sync"
|
|
1007
|
+
} = options;
|
|
1008
|
+
const height = vue.ref(0);
|
|
1009
|
+
const bottom = vue.ref(0);
|
|
1010
|
+
const left = vue.ref(0);
|
|
1011
|
+
const right = vue.ref(0);
|
|
1012
|
+
const top = vue.ref(0);
|
|
1013
|
+
const width = vue.ref(0);
|
|
1014
|
+
const x = vue.ref(0);
|
|
1015
|
+
const y = vue.ref(0);
|
|
1016
|
+
function recalculate() {
|
|
1017
|
+
const el = unrefElement(target);
|
|
1018
|
+
if (!el) {
|
|
1019
|
+
if (reset) {
|
|
1020
|
+
height.value = 0;
|
|
1021
|
+
bottom.value = 0;
|
|
1022
|
+
left.value = 0;
|
|
1023
|
+
right.value = 0;
|
|
1024
|
+
top.value = 0;
|
|
1025
|
+
width.value = 0;
|
|
1026
|
+
x.value = 0;
|
|
1027
|
+
y.value = 0;
|
|
1028
|
+
}
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const rect = el.getBoundingClientRect();
|
|
1032
|
+
height.value = rect.height;
|
|
1033
|
+
bottom.value = rect.bottom;
|
|
1034
|
+
left.value = rect.left;
|
|
1035
|
+
right.value = rect.right;
|
|
1036
|
+
top.value = rect.top;
|
|
1037
|
+
width.value = rect.width;
|
|
1038
|
+
x.value = rect.x;
|
|
1039
|
+
y.value = rect.y;
|
|
1040
|
+
}
|
|
1041
|
+
function update() {
|
|
1042
|
+
if (updateTiming === "sync")
|
|
1043
|
+
recalculate();
|
|
1044
|
+
else if (updateTiming === "next-frame")
|
|
1045
|
+
requestAnimationFrame(() => recalculate());
|
|
1046
|
+
}
|
|
1047
|
+
useResizeObserver(target, update);
|
|
1048
|
+
vue.watch(() => unrefElement(target), (ele) => !ele && update());
|
|
1049
|
+
useMutationObserver(target, update, {
|
|
1050
|
+
attributeFilter: ["style", "class"]
|
|
1051
|
+
});
|
|
1052
|
+
if (windowScroll)
|
|
1053
|
+
useEventListener("scroll", update, { capture: true, passive: true });
|
|
1054
|
+
if (windowResize)
|
|
1055
|
+
useEventListener("resize", update, { passive: true });
|
|
1056
|
+
shared.tryOnMounted(() => {
|
|
1057
|
+
if (immediate)
|
|
1058
|
+
update();
|
|
1059
|
+
});
|
|
1060
|
+
return {
|
|
1061
|
+
height,
|
|
1062
|
+
bottom,
|
|
1063
|
+
left,
|
|
1064
|
+
right,
|
|
1065
|
+
top,
|
|
1066
|
+
width,
|
|
1067
|
+
x,
|
|
1068
|
+
y,
|
|
1069
|
+
update
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const vElementBounding = {
|
|
1074
|
+
mounted(el, binding) {
|
|
1075
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1076
|
+
const {
|
|
1077
|
+
height,
|
|
1078
|
+
bottom,
|
|
1079
|
+
left,
|
|
1080
|
+
right,
|
|
1081
|
+
top,
|
|
1082
|
+
width,
|
|
1083
|
+
x,
|
|
1084
|
+
y
|
|
1085
|
+
} = useElementBounding(el, options);
|
|
1086
|
+
vue.watch([height, bottom, left, right, top, width, x, y], () => handler({ height, bottom, left, right, top, width, x, y }));
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
function onElementRemoval(target, callback, options = {}) {
|
|
1091
|
+
const {
|
|
1092
|
+
window = defaultWindow,
|
|
1093
|
+
document = window == null ? undefined : window.document,
|
|
1094
|
+
flush = "sync"
|
|
1095
|
+
} = options;
|
|
1096
|
+
if (!window || !document)
|
|
1097
|
+
return shared.noop;
|
|
1098
|
+
let stopFn;
|
|
1099
|
+
const cleanupAndUpdate = (fn) => {
|
|
1100
|
+
stopFn == null ? undefined : stopFn();
|
|
1101
|
+
stopFn = fn;
|
|
1102
|
+
};
|
|
1103
|
+
const stopWatch = vue.watchEffect(() => {
|
|
1104
|
+
const el = unrefElement(target);
|
|
1105
|
+
if (el) {
|
|
1106
|
+
const { stop } = useMutationObserver(
|
|
1107
|
+
document,
|
|
1108
|
+
(mutationsList) => {
|
|
1109
|
+
const targetRemoved = mutationsList.map((mutation) => [...mutation.removedNodes]).flat().some((node) => node === el || node.contains(el));
|
|
1110
|
+
if (targetRemoved) {
|
|
1111
|
+
callback(mutationsList);
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
{
|
|
1115
|
+
window,
|
|
1116
|
+
childList: true,
|
|
1117
|
+
subtree: true
|
|
1118
|
+
}
|
|
1119
|
+
);
|
|
1120
|
+
cleanupAndUpdate(stop);
|
|
1121
|
+
}
|
|
1122
|
+
}, { flush });
|
|
1123
|
+
const stopHandle = () => {
|
|
1124
|
+
stopWatch();
|
|
1125
|
+
cleanupAndUpdate();
|
|
1126
|
+
};
|
|
1127
|
+
shared.tryOnScopeDispose(stopHandle);
|
|
1128
|
+
return stopHandle;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
920
1131
|
function useElementHover(el, options = {}) {
|
|
921
1132
|
const {
|
|
922
1133
|
delayEnter = 0,
|
|
923
1134
|
delayLeave = 0,
|
|
1135
|
+
triggerOnRemoval = false,
|
|
924
1136
|
window = defaultWindow
|
|
925
1137
|
} = options;
|
|
926
1138
|
const isHovered = vue.ref(false);
|
|
@@ -929,7 +1141,7 @@ function useElementHover(el, options = {}) {
|
|
|
929
1141
|
const delay = entering ? delayEnter : delayLeave;
|
|
930
1142
|
if (timer) {
|
|
931
1143
|
clearTimeout(timer);
|
|
932
|
-
timer =
|
|
1144
|
+
timer = undefined;
|
|
933
1145
|
}
|
|
934
1146
|
if (delay)
|
|
935
1147
|
timer = setTimeout(() => isHovered.value = entering, delay);
|
|
@@ -940,6 +1152,12 @@ function useElementHover(el, options = {}) {
|
|
|
940
1152
|
return isHovered;
|
|
941
1153
|
useEventListener(el, "mouseenter", () => toggle(true), { passive: true });
|
|
942
1154
|
useEventListener(el, "mouseleave", () => toggle(false), { passive: true });
|
|
1155
|
+
if (triggerOnRemoval) {
|
|
1156
|
+
onElementRemoval(
|
|
1157
|
+
vue.computed(() => unrefElement(el)),
|
|
1158
|
+
() => toggle(false)
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
943
1161
|
return isHovered;
|
|
944
1162
|
}
|
|
945
1163
|
|
|
@@ -970,50 +1188,11 @@ const UseElementSize = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
970
1188
|
}
|
|
971
1189
|
});
|
|
972
1190
|
|
|
973
|
-
function useResizeObserver(target, callback, options = {}) {
|
|
974
|
-
const { window = defaultWindow, ...observerOptions } = options;
|
|
975
|
-
let observer;
|
|
976
|
-
const isSupported = useSupported(() => window && "ResizeObserver" in window);
|
|
977
|
-
const cleanup = () => {
|
|
978
|
-
if (observer) {
|
|
979
|
-
observer.disconnect();
|
|
980
|
-
observer = void 0;
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
const targets = vue.computed(() => {
|
|
984
|
-
const _targets = shared.toValue(target);
|
|
985
|
-
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
986
|
-
});
|
|
987
|
-
const stopWatch = vue.watch(
|
|
988
|
-
targets,
|
|
989
|
-
(els) => {
|
|
990
|
-
cleanup();
|
|
991
|
-
if (isSupported.value && window) {
|
|
992
|
-
observer = new ResizeObserver(callback);
|
|
993
|
-
for (const _el of els) {
|
|
994
|
-
if (_el)
|
|
995
|
-
observer.observe(_el, observerOptions);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
},
|
|
999
|
-
{ immediate: true, flush: "post" }
|
|
1000
|
-
);
|
|
1001
|
-
const stop = () => {
|
|
1002
|
-
cleanup();
|
|
1003
|
-
stopWatch();
|
|
1004
|
-
};
|
|
1005
|
-
shared.tryOnScopeDispose(stop);
|
|
1006
|
-
return {
|
|
1007
|
-
isSupported,
|
|
1008
|
-
stop
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
1191
|
function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
|
|
1013
1192
|
const { window = defaultWindow, box = "content-box" } = options;
|
|
1014
1193
|
const isSVG = vue.computed(() => {
|
|
1015
1194
|
var _a, _b;
|
|
1016
|
-
return (_b = (_a = unrefElement(target)) == null ?
|
|
1195
|
+
return (_b = (_a = unrefElement(target)) == null ? undefined : _a.namespaceURI) == null ? undefined : _b.includes("svg");
|
|
1017
1196
|
});
|
|
1018
1197
|
const width = vue.ref(initialSize.width);
|
|
1019
1198
|
const height = vue.ref(initialSize.height);
|
|
@@ -1030,7 +1209,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1030
1209
|
}
|
|
1031
1210
|
} else {
|
|
1032
1211
|
if (boxSize) {
|
|
1033
|
-
const formatBoxSize =
|
|
1212
|
+
const formatBoxSize = shared.toArray(boxSize);
|
|
1034
1213
|
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
1035
1214
|
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
1036
1215
|
} else {
|
|
@@ -1069,7 +1248,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1069
1248
|
const vElementSize = {
|
|
1070
1249
|
mounted(el, binding) {
|
|
1071
1250
|
var _a;
|
|
1072
|
-
const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ?
|
|
1251
|
+
const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ? undefined : _a[0];
|
|
1073
1252
|
const options = typeof binding.value === "function" ? [] : binding.value.slice(1);
|
|
1074
1253
|
const { width, height } = useElementSize(el, ...options);
|
|
1075
1254
|
vue.watch([width, height], ([width2, height2]) => handler({ width: width2, height: height2 }));
|
|
@@ -1101,8 +1280,8 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
1101
1280
|
} = options;
|
|
1102
1281
|
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
1103
1282
|
const targets = vue.computed(() => {
|
|
1104
|
-
const _target =
|
|
1105
|
-
return
|
|
1283
|
+
const _target = vue.toValue(target);
|
|
1284
|
+
return shared.toArray(_target).map(unrefElement).filter(shared.notNullish);
|
|
1106
1285
|
});
|
|
1107
1286
|
let cleanup = shared.noop;
|
|
1108
1287
|
const isActive = vue.ref(immediate);
|
|
@@ -1175,7 +1354,7 @@ function useElementVisibility(element, options = {}) {
|
|
|
1175
1354
|
root: scrollTarget,
|
|
1176
1355
|
window,
|
|
1177
1356
|
threshold,
|
|
1178
|
-
rootMargin:
|
|
1357
|
+
rootMargin: vue.toValue(rootMargin)
|
|
1179
1358
|
}
|
|
1180
1359
|
);
|
|
1181
1360
|
return elementIsVisible;
|
|
@@ -1259,11 +1438,11 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1259
1438
|
const state = shallow ? vue.shallowRef(initialState) : vue.ref(initialState);
|
|
1260
1439
|
const isReady = vue.ref(false);
|
|
1261
1440
|
const isLoading = vue.ref(false);
|
|
1262
|
-
const error = vue.shallowRef(
|
|
1441
|
+
const error = vue.shallowRef(undefined);
|
|
1263
1442
|
async function execute(delay2 = 0, ...args) {
|
|
1264
1443
|
if (resetOnExecute)
|
|
1265
1444
|
state.value = initialState;
|
|
1266
|
-
error.value =
|
|
1445
|
+
error.value = undefined;
|
|
1267
1446
|
isReady.value = false;
|
|
1268
1447
|
isLoading.value = true;
|
|
1269
1448
|
if (delay2 > 0)
|
|
@@ -1284,8 +1463,9 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1284
1463
|
}
|
|
1285
1464
|
return state.value;
|
|
1286
1465
|
}
|
|
1287
|
-
if (immediate)
|
|
1466
|
+
if (immediate) {
|
|
1288
1467
|
execute(delay);
|
|
1468
|
+
}
|
|
1289
1469
|
const shell = {
|
|
1290
1470
|
state,
|
|
1291
1471
|
isReady,
|
|
@@ -1341,15 +1521,15 @@ async function loadImage(options) {
|
|
|
1341
1521
|
}
|
|
1342
1522
|
function useImage(options, asyncStateOptions = {}) {
|
|
1343
1523
|
const state = useAsyncState(
|
|
1344
|
-
() => loadImage(
|
|
1345
|
-
|
|
1524
|
+
() => loadImage(vue.toValue(options)),
|
|
1525
|
+
undefined,
|
|
1346
1526
|
{
|
|
1347
1527
|
resetOnExecute: true,
|
|
1348
1528
|
...asyncStateOptions
|
|
1349
1529
|
}
|
|
1350
1530
|
);
|
|
1351
1531
|
vue.watch(
|
|
1352
|
-
() =>
|
|
1532
|
+
() => vue.toValue(options),
|
|
1353
1533
|
() => state.execute(asyncStateOptions.delay),
|
|
1354
1534
|
{ deep: true }
|
|
1355
1535
|
);
|
|
@@ -1427,7 +1607,7 @@ function useScroll(element, options = {}) {
|
|
|
1427
1607
|
return internalX.value;
|
|
1428
1608
|
},
|
|
1429
1609
|
set(x2) {
|
|
1430
|
-
scrollTo(x2,
|
|
1610
|
+
scrollTo(x2, undefined);
|
|
1431
1611
|
}
|
|
1432
1612
|
});
|
|
1433
1613
|
const y = vue.computed({
|
|
@@ -1435,22 +1615,22 @@ function useScroll(element, options = {}) {
|
|
|
1435
1615
|
return internalY.value;
|
|
1436
1616
|
},
|
|
1437
1617
|
set(y2) {
|
|
1438
|
-
scrollTo(
|
|
1618
|
+
scrollTo(undefined, y2);
|
|
1439
1619
|
}
|
|
1440
1620
|
});
|
|
1441
1621
|
function scrollTo(_x, _y) {
|
|
1442
1622
|
var _a, _b, _c, _d;
|
|
1443
1623
|
if (!window)
|
|
1444
1624
|
return;
|
|
1445
|
-
const _element =
|
|
1625
|
+
const _element = vue.toValue(element);
|
|
1446
1626
|
if (!_element)
|
|
1447
1627
|
return;
|
|
1448
|
-
(_c = _element instanceof Document ? window.document.body : _element) == null ?
|
|
1449
|
-
top: (_a =
|
|
1450
|
-
left: (_b =
|
|
1451
|
-
behavior:
|
|
1628
|
+
(_c = _element instanceof Document ? window.document.body : _element) == null ? undefined : _c.scrollTo({
|
|
1629
|
+
top: (_a = vue.toValue(_y)) != null ? _a : y.value,
|
|
1630
|
+
left: (_b = vue.toValue(_x)) != null ? _b : x.value,
|
|
1631
|
+
behavior: vue.toValue(behavior)
|
|
1452
1632
|
});
|
|
1453
|
-
const scrollContainer = ((_d = _element == null ?
|
|
1633
|
+
const scrollContainer = ((_d = _element == null ? undefined : _element.document) == null ? undefined : _d.documentElement) || (_element == null ? undefined : _element.documentElement) || _element;
|
|
1454
1634
|
if (x != null)
|
|
1455
1635
|
internalX.value = scrollContainer.scrollLeft;
|
|
1456
1636
|
if (y != null)
|
|
@@ -1484,7 +1664,7 @@ function useScroll(element, options = {}) {
|
|
|
1484
1664
|
var _a;
|
|
1485
1665
|
if (!window)
|
|
1486
1666
|
return;
|
|
1487
|
-
const el = ((_a = target == null ?
|
|
1667
|
+
const el = ((_a = target == null ? undefined : target.document) == null ? undefined : _a.documentElement) || (target == null ? undefined : target.documentElement) || unrefElement(target);
|
|
1488
1668
|
const { display, flexDirection, direction } = getComputedStyle(el);
|
|
1489
1669
|
const directionMultipler = direction === "rtl" ? -1 : 1;
|
|
1490
1670
|
const scrollLeft = el.scrollLeft;
|
|
@@ -1534,7 +1714,7 @@ function useScroll(element, options = {}) {
|
|
|
1534
1714
|
);
|
|
1535
1715
|
shared.tryOnMounted(() => {
|
|
1536
1716
|
try {
|
|
1537
|
-
const _element =
|
|
1717
|
+
const _element = vue.toValue(element);
|
|
1538
1718
|
if (!_element)
|
|
1539
1719
|
return;
|
|
1540
1720
|
setArrivedState(_element);
|
|
@@ -1555,7 +1735,7 @@ function useScroll(element, options = {}) {
|
|
|
1555
1735
|
arrivedState,
|
|
1556
1736
|
directions,
|
|
1557
1737
|
measure() {
|
|
1558
|
-
const _element =
|
|
1738
|
+
const _element = vue.toValue(element);
|
|
1559
1739
|
if (window && _element)
|
|
1560
1740
|
setArrivedState(_element);
|
|
1561
1741
|
}
|
|
@@ -1582,7 +1762,7 @@ function useInfiniteScroll(element, onLoadMore, options = {}) {
|
|
|
1582
1762
|
const promise = vue.ref();
|
|
1583
1763
|
const isLoading = vue.computed(() => !!promise.value);
|
|
1584
1764
|
const observedElement = vue.computed(() => {
|
|
1585
|
-
return resolveElement(
|
|
1765
|
+
return resolveElement(vue.toValue(element));
|
|
1586
1766
|
});
|
|
1587
1767
|
const isElementVisible = useElementVisibility(observedElement);
|
|
1588
1768
|
function checkAndLoad() {
|
|
@@ -1660,6 +1840,159 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
1660
1840
|
}
|
|
1661
1841
|
});
|
|
1662
1842
|
|
|
1843
|
+
const UseMouseBuiltinExtractors = {
|
|
1844
|
+
page: (event) => [event.pageX, event.pageY],
|
|
1845
|
+
client: (event) => [event.clientX, event.clientY],
|
|
1846
|
+
screen: (event) => [event.screenX, event.screenY],
|
|
1847
|
+
movement: (event) => event instanceof Touch ? null : [event.movementX, event.movementY]
|
|
1848
|
+
};
|
|
1849
|
+
function useMouse(options = {}) {
|
|
1850
|
+
const {
|
|
1851
|
+
type = "page",
|
|
1852
|
+
touch = true,
|
|
1853
|
+
resetOnTouchEnds = false,
|
|
1854
|
+
initialValue = { x: 0, y: 0 },
|
|
1855
|
+
window = defaultWindow,
|
|
1856
|
+
target = window,
|
|
1857
|
+
scroll = true,
|
|
1858
|
+
eventFilter
|
|
1859
|
+
} = options;
|
|
1860
|
+
let _prevMouseEvent = null;
|
|
1861
|
+
let _prevScrollX = 0;
|
|
1862
|
+
let _prevScrollY = 0;
|
|
1863
|
+
const x = vue.ref(initialValue.x);
|
|
1864
|
+
const y = vue.ref(initialValue.y);
|
|
1865
|
+
const sourceType = vue.ref(null);
|
|
1866
|
+
const extractor = typeof type === "function" ? type : UseMouseBuiltinExtractors[type];
|
|
1867
|
+
const mouseHandler = (event) => {
|
|
1868
|
+
const result = extractor(event);
|
|
1869
|
+
_prevMouseEvent = event;
|
|
1870
|
+
if (result) {
|
|
1871
|
+
[x.value, y.value] = result;
|
|
1872
|
+
sourceType.value = "mouse";
|
|
1873
|
+
}
|
|
1874
|
+
if (window) {
|
|
1875
|
+
_prevScrollX = window.scrollX;
|
|
1876
|
+
_prevScrollY = window.scrollY;
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
const touchHandler = (event) => {
|
|
1880
|
+
if (event.touches.length > 0) {
|
|
1881
|
+
const result = extractor(event.touches[0]);
|
|
1882
|
+
if (result) {
|
|
1883
|
+
[x.value, y.value] = result;
|
|
1884
|
+
sourceType.value = "touch";
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
const scrollHandler = () => {
|
|
1889
|
+
if (!_prevMouseEvent || !window)
|
|
1890
|
+
return;
|
|
1891
|
+
const pos = extractor(_prevMouseEvent);
|
|
1892
|
+
if (_prevMouseEvent instanceof MouseEvent && pos) {
|
|
1893
|
+
x.value = pos[0] + window.scrollX - _prevScrollX;
|
|
1894
|
+
y.value = pos[1] + window.scrollY - _prevScrollY;
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
const reset = () => {
|
|
1898
|
+
x.value = initialValue.x;
|
|
1899
|
+
y.value = initialValue.y;
|
|
1900
|
+
};
|
|
1901
|
+
const mouseHandlerWrapper = eventFilter ? (event) => eventFilter(() => mouseHandler(event), {}) : (event) => mouseHandler(event);
|
|
1902
|
+
const touchHandlerWrapper = eventFilter ? (event) => eventFilter(() => touchHandler(event), {}) : (event) => touchHandler(event);
|
|
1903
|
+
const scrollHandlerWrapper = eventFilter ? () => eventFilter(() => scrollHandler(), {}) : () => scrollHandler();
|
|
1904
|
+
if (target) {
|
|
1905
|
+
const listenerOptions = { passive: true };
|
|
1906
|
+
useEventListener(target, ["mousemove", "dragover"], mouseHandlerWrapper, listenerOptions);
|
|
1907
|
+
if (touch && type !== "movement") {
|
|
1908
|
+
useEventListener(target, ["touchstart", "touchmove"], touchHandlerWrapper, listenerOptions);
|
|
1909
|
+
if (resetOnTouchEnds)
|
|
1910
|
+
useEventListener(target, "touchend", reset, listenerOptions);
|
|
1911
|
+
}
|
|
1912
|
+
if (scroll && type === "page")
|
|
1913
|
+
useEventListener(window, "scroll", scrollHandlerWrapper, listenerOptions);
|
|
1914
|
+
}
|
|
1915
|
+
return {
|
|
1916
|
+
x,
|
|
1917
|
+
y,
|
|
1918
|
+
sourceType
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
function useMouseInElement(target, options = {}) {
|
|
1923
|
+
const {
|
|
1924
|
+
handleOutside = true,
|
|
1925
|
+
window = defaultWindow
|
|
1926
|
+
} = options;
|
|
1927
|
+
const type = options.type || "page";
|
|
1928
|
+
const { x, y, sourceType } = useMouse(options);
|
|
1929
|
+
const targetRef = vue.ref(target != null ? target : window == null ? undefined : window.document.body);
|
|
1930
|
+
const elementX = vue.ref(0);
|
|
1931
|
+
const elementY = vue.ref(0);
|
|
1932
|
+
const elementPositionX = vue.ref(0);
|
|
1933
|
+
const elementPositionY = vue.ref(0);
|
|
1934
|
+
const elementHeight = vue.ref(0);
|
|
1935
|
+
const elementWidth = vue.ref(0);
|
|
1936
|
+
const isOutside = vue.ref(true);
|
|
1937
|
+
let stop = () => {
|
|
1938
|
+
};
|
|
1939
|
+
if (window) {
|
|
1940
|
+
stop = vue.watch(
|
|
1941
|
+
[targetRef, x, y],
|
|
1942
|
+
() => {
|
|
1943
|
+
const el = unrefElement(targetRef);
|
|
1944
|
+
if (!el || !(el instanceof Element))
|
|
1945
|
+
return;
|
|
1946
|
+
const {
|
|
1947
|
+
left,
|
|
1948
|
+
top,
|
|
1949
|
+
width,
|
|
1950
|
+
height
|
|
1951
|
+
} = el.getBoundingClientRect();
|
|
1952
|
+
elementPositionX.value = left + (type === "page" ? window.pageXOffset : 0);
|
|
1953
|
+
elementPositionY.value = top + (type === "page" ? window.pageYOffset : 0);
|
|
1954
|
+
elementHeight.value = height;
|
|
1955
|
+
elementWidth.value = width;
|
|
1956
|
+
const elX = x.value - elementPositionX.value;
|
|
1957
|
+
const elY = y.value - elementPositionY.value;
|
|
1958
|
+
isOutside.value = width === 0 || height === 0 || elX < 0 || elY < 0 || elX > width || elY > height;
|
|
1959
|
+
if (handleOutside || !isOutside.value) {
|
|
1960
|
+
elementX.value = elX;
|
|
1961
|
+
elementY.value = elY;
|
|
1962
|
+
}
|
|
1963
|
+
},
|
|
1964
|
+
{ immediate: true }
|
|
1965
|
+
);
|
|
1966
|
+
useEventListener(
|
|
1967
|
+
document,
|
|
1968
|
+
"mouseleave",
|
|
1969
|
+
() => isOutside.value = true,
|
|
1970
|
+
{ passive: true }
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
return {
|
|
1974
|
+
x,
|
|
1975
|
+
y,
|
|
1976
|
+
sourceType,
|
|
1977
|
+
elementX,
|
|
1978
|
+
elementY,
|
|
1979
|
+
elementPositionX,
|
|
1980
|
+
elementPositionY,
|
|
1981
|
+
elementHeight,
|
|
1982
|
+
elementWidth,
|
|
1983
|
+
isOutside,
|
|
1984
|
+
stop
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
const vMouseInElement = {
|
|
1989
|
+
mounted(el, binding) {
|
|
1990
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1991
|
+
const state = shared.reactiveOmit(vue.reactive(useMouseInElement(el, options)), "stop");
|
|
1992
|
+
vue.watch(state, (val) => handler(val));
|
|
1993
|
+
}
|
|
1994
|
+
};
|
|
1995
|
+
|
|
1663
1996
|
const UseMousePressed = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
1664
1997
|
name: "UseMousePressed",
|
|
1665
1998
|
props: ["touch", "initialValue", "as"],
|
|
@@ -1731,17 +2064,17 @@ const UseOffsetPagination = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent(
|
|
|
1731
2064
|
...props,
|
|
1732
2065
|
onPageChange(...args) {
|
|
1733
2066
|
var _a;
|
|
1734
|
-
(_a = props.onPageChange) == null ?
|
|
2067
|
+
(_a = props.onPageChange) == null ? undefined : _a.call(props, ...args);
|
|
1735
2068
|
emit("page-change", ...args);
|
|
1736
2069
|
},
|
|
1737
2070
|
onPageSizeChange(...args) {
|
|
1738
2071
|
var _a;
|
|
1739
|
-
(_a = props.onPageSizeChange) == null ?
|
|
2072
|
+
(_a = props.onPageSizeChange) == null ? undefined : _a.call(props, ...args);
|
|
1740
2073
|
emit("page-size-change", ...args);
|
|
1741
2074
|
},
|
|
1742
2075
|
onPageCountChange(...args) {
|
|
1743
2076
|
var _a;
|
|
1744
|
-
(_a = props.onPageCountChange) == null ?
|
|
2077
|
+
(_a = props.onPageCountChange) == null ? undefined : _a.call(props, ...args);
|
|
1745
2078
|
emit("page-count-change", ...args);
|
|
1746
2079
|
}
|
|
1747
2080
|
}));
|
|
@@ -1898,60 +2231,19 @@ const vResizeObserver = {
|
|
|
1898
2231
|
}
|
|
1899
2232
|
};
|
|
1900
2233
|
|
|
1901
|
-
function useMutationObserver(target, callback, options = {}) {
|
|
1902
|
-
const { window = defaultWindow, ...mutationOptions } = options;
|
|
1903
|
-
let observer;
|
|
1904
|
-
const isSupported = useSupported(() => window && "MutationObserver" in window);
|
|
1905
|
-
const cleanup = () => {
|
|
1906
|
-
if (observer) {
|
|
1907
|
-
observer.disconnect();
|
|
1908
|
-
observer = void 0;
|
|
1909
|
-
}
|
|
1910
|
-
};
|
|
1911
|
-
const targets = vue.computed(() => {
|
|
1912
|
-
const value = shared.toValue(target);
|
|
1913
|
-
const items = (Array.isArray(value) ? value : [value]).map(unrefElement).filter(shared.notNullish);
|
|
1914
|
-
return new Set(items);
|
|
1915
|
-
});
|
|
1916
|
-
const stopWatch = vue.watch(
|
|
1917
|
-
() => targets.value,
|
|
1918
|
-
(targets2) => {
|
|
1919
|
-
cleanup();
|
|
1920
|
-
if (isSupported.value && targets2.size) {
|
|
1921
|
-
observer = new MutationObserver(callback);
|
|
1922
|
-
targets2.forEach((el) => observer.observe(el, mutationOptions));
|
|
1923
|
-
}
|
|
1924
|
-
},
|
|
1925
|
-
{ immediate: true, flush: "post" }
|
|
1926
|
-
);
|
|
1927
|
-
const takeRecords = () => {
|
|
1928
|
-
return observer == null ? void 0 : observer.takeRecords();
|
|
1929
|
-
};
|
|
1930
|
-
const stop = () => {
|
|
1931
|
-
stopWatch();
|
|
1932
|
-
cleanup();
|
|
1933
|
-
};
|
|
1934
|
-
shared.tryOnScopeDispose(stop);
|
|
1935
|
-
return {
|
|
1936
|
-
isSupported,
|
|
1937
|
-
stop,
|
|
1938
|
-
takeRecords
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
2234
|
function useCssVar(prop, target, options = {}) {
|
|
1943
2235
|
const { window = defaultWindow, initialValue, observe = false } = options;
|
|
1944
2236
|
const variable = vue.ref(initialValue);
|
|
1945
2237
|
const elRef = vue.computed(() => {
|
|
1946
2238
|
var _a;
|
|
1947
|
-
return unrefElement(target) || ((_a = window == null ?
|
|
2239
|
+
return unrefElement(target) || ((_a = window == null ? undefined : window.document) == null ? undefined : _a.documentElement);
|
|
1948
2240
|
});
|
|
1949
2241
|
function updateCssVar() {
|
|
1950
2242
|
var _a;
|
|
1951
|
-
const key =
|
|
1952
|
-
const el =
|
|
2243
|
+
const key = vue.toValue(prop);
|
|
2244
|
+
const el = vue.toValue(elRef);
|
|
1953
2245
|
if (el && window && key) {
|
|
1954
|
-
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ?
|
|
2246
|
+
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? undefined : _a.trim();
|
|
1955
2247
|
variable.value = value || initialValue;
|
|
1956
2248
|
}
|
|
1957
2249
|
}
|
|
@@ -1962,7 +2254,7 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1962
2254
|
});
|
|
1963
2255
|
}
|
|
1964
2256
|
vue.watch(
|
|
1965
|
-
[elRef, () =>
|
|
2257
|
+
[elRef, () => vue.toValue(prop)],
|
|
1966
2258
|
(_, old) => {
|
|
1967
2259
|
if (old[0] && old[1])
|
|
1968
2260
|
old[0].style.removeProperty(old[1]);
|
|
@@ -1974,8 +2266,8 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1974
2266
|
variable,
|
|
1975
2267
|
(val) => {
|
|
1976
2268
|
var _a;
|
|
1977
|
-
const raw_prop =
|
|
1978
|
-
if (((_a = elRef.value) == null ?
|
|
2269
|
+
const raw_prop = vue.toValue(prop);
|
|
2270
|
+
if (((_a = elRef.value) == null ? undefined : _a.style) && raw_prop) {
|
|
1979
2271
|
if (val == null)
|
|
1980
2272
|
elRef.value.style.removeProperty(raw_prop);
|
|
1981
2273
|
else
|
|
@@ -2005,7 +2297,7 @@ function useScreenSafeArea() {
|
|
|
2005
2297
|
bottomCssVar.value = "env(safe-area-inset-bottom, 0px)";
|
|
2006
2298
|
leftCssVar.value = "env(safe-area-inset-left, 0px)";
|
|
2007
2299
|
update();
|
|
2008
|
-
useEventListener("resize", shared.useDebounceFn(update));
|
|
2300
|
+
useEventListener("resize", shared.useDebounceFn(update), { passive: true });
|
|
2009
2301
|
}
|
|
2010
2302
|
function update() {
|
|
2011
2303
|
top.value = getValue(topVarName);
|
|
@@ -2077,12 +2369,12 @@ const vScroll = {
|
|
|
2077
2369
|
...options,
|
|
2078
2370
|
onScroll(e) {
|
|
2079
2371
|
var _a;
|
|
2080
|
-
(_a = options.onScroll) == null ?
|
|
2372
|
+
(_a = options.onScroll) == null ? undefined : _a.call(options, e);
|
|
2081
2373
|
handler(state);
|
|
2082
2374
|
},
|
|
2083
2375
|
onStop(e) {
|
|
2084
2376
|
var _a;
|
|
2085
|
-
(_a = options.onStop) == null ?
|
|
2377
|
+
(_a = options.onStop) == null ? undefined : _a.call(options, e);
|
|
2086
2378
|
handler(state);
|
|
2087
2379
|
}
|
|
2088
2380
|
});
|
|
@@ -2118,7 +2410,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2118
2410
|
let stopTouchMoveListener = null;
|
|
2119
2411
|
let initialOverflow = "";
|
|
2120
2412
|
vue.watch(shared.toRef(element), (el) => {
|
|
2121
|
-
const target = resolveElement(
|
|
2413
|
+
const target = resolveElement(vue.toValue(el));
|
|
2122
2414
|
if (target) {
|
|
2123
2415
|
const ele = target;
|
|
2124
2416
|
if (!elInitialOverflow.get(ele))
|
|
@@ -2134,7 +2426,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2134
2426
|
immediate: true
|
|
2135
2427
|
});
|
|
2136
2428
|
const lock = () => {
|
|
2137
|
-
const el = resolveElement(
|
|
2429
|
+
const el = resolveElement(vue.toValue(element));
|
|
2138
2430
|
if (!el || isLocked.value)
|
|
2139
2431
|
return;
|
|
2140
2432
|
if (shared.isIOS) {
|
|
@@ -2151,11 +2443,11 @@ function useScrollLock(element, initialState = false) {
|
|
|
2151
2443
|
isLocked.value = true;
|
|
2152
2444
|
};
|
|
2153
2445
|
const unlock = () => {
|
|
2154
|
-
const el = resolveElement(
|
|
2446
|
+
const el = resolveElement(vue.toValue(element));
|
|
2155
2447
|
if (!el || !isLocked.value)
|
|
2156
2448
|
return;
|
|
2157
2449
|
if (shared.isIOS)
|
|
2158
|
-
stopTouchMoveListener == null ?
|
|
2450
|
+
stopTouchMoveListener == null ? undefined : stopTouchMoveListener();
|
|
2159
2451
|
el.style.overflow = initialOverflow;
|
|
2160
2452
|
elInitialOverflow.delete(el);
|
|
2161
2453
|
isLocked.value = false;
|
|
@@ -2302,11 +2594,13 @@ exports.UseWindowFocus = UseWindowFocus;
|
|
|
2302
2594
|
exports.UseWindowSize = UseWindowSize;
|
|
2303
2595
|
exports.VOnClickOutside = vOnClickOutside;
|
|
2304
2596
|
exports.VOnLongPress = vOnLongPress;
|
|
2597
|
+
exports.vElementBounding = vElementBounding;
|
|
2305
2598
|
exports.vElementHover = vElementHover;
|
|
2306
2599
|
exports.vElementSize = vElementSize;
|
|
2307
2600
|
exports.vElementVisibility = vElementVisibility;
|
|
2308
2601
|
exports.vInfiniteScroll = vInfiniteScroll;
|
|
2309
2602
|
exports.vIntersectionObserver = vIntersectionObserver;
|
|
2603
|
+
exports.vMouseInElement = vMouseInElement;
|
|
2310
2604
|
exports.vOnClickOutside = vOnClickOutside;
|
|
2311
2605
|
exports.vOnKeyStroke = vOnKeyStroke;
|
|
2312
2606
|
exports.vOnLongPress = vOnLongPress;
|