@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.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { onClickOutside as onClickOutside$1, useActiveElement, useBattery, useBrowserLocation, useClipboard, useDark, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDocumentVisibility, useStorage as useStorage$1, isClient as isClient$1, useDraggable, useElementBounding, useElementSize as useElementSize$1, useElementVisibility as useElementVisibility$1, useEyeDropper, useFullscreen, useGeolocation, useIdle, useMouse, useMouseInElement, useMousePressed, useNetwork, useNow, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, usePointer, usePointerLock, usePreferredColorScheme, usePreferredContrast, usePreferredDark as usePreferredDark$1, usePreferredLanguages, usePreferredReducedMotion, usePreferredReducedTransparency, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
|
|
2
|
-
import { defineComponent, ref, h, watch, computed, reactive, hasInjectionContext, getCurrentInstance, onMounted, watchEffect, shallowRef, nextTick, toRefs } from 'vue';
|
|
3
|
-
import { isClient,
|
|
1
|
+
import { onClickOutside as onClickOutside$1, useActiveElement, useBattery, useBrowserLocation, useClipboard, useDark, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDocumentVisibility, useStorage as useStorage$1, isClient as isClient$1, useDraggable, useElementBounding as useElementBounding$1, useElementSize as useElementSize$1, useElementVisibility as useElementVisibility$1, useEyeDropper, useFullscreen, useGeolocation, useIdle, useMouse as useMouse$1, useMouseInElement as useMouseInElement$1, useMousePressed, useNetwork, useNow, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, usePointer, usePointerLock, usePreferredColorScheme, usePreferredContrast, usePreferredDark as usePreferredDark$1, usePreferredLanguages, usePreferredReducedMotion, usePreferredReducedTransparency, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
|
|
2
|
+
import { defineComponent, ref, h, toValue, watch, computed, reactive, hasInjectionContext, getCurrentInstance, onMounted, watchEffect, shallowRef, nextTick, toRefs } from 'vue';
|
|
3
|
+
import { isClient, noop, toArray, isObject, tryOnScopeDispose, isIOS, injectLocal, pxValue, pausableWatch, tryOnMounted, toRef, useToggle, notNullish, promiseTimeout, until, useDebounceFn, useThrottleFn, tryOnUnmounted, reactiveOmit } from '@vueuse/shared';
|
|
4
4
|
|
|
5
5
|
const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
6
6
|
name: "OnClickOutside",
|
|
@@ -18,12 +18,12 @@ const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const defaultWindow = isClient ? window :
|
|
21
|
+
const defaultWindow = isClient ? window : undefined;
|
|
22
22
|
|
|
23
23
|
function unrefElement(elRef) {
|
|
24
24
|
var _a;
|
|
25
25
|
const plain = toValue(elRef);
|
|
26
|
-
return (_a = plain == null ?
|
|
26
|
+
return (_a = plain == null ? undefined : plain.$el) != null ? _a : plain;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function useEventListener(...args) {
|
|
@@ -39,10 +39,8 @@ function useEventListener(...args) {
|
|
|
39
39
|
}
|
|
40
40
|
if (!target)
|
|
41
41
|
return noop;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!Array.isArray(listeners))
|
|
45
|
-
listeners = [listeners];
|
|
42
|
+
events = toArray(events);
|
|
43
|
+
listeners = toArray(listeners);
|
|
46
44
|
const cleanups = [];
|
|
47
45
|
const cleanup = () => {
|
|
48
46
|
cleanups.forEach((fn) => fn());
|
|
@@ -142,11 +140,11 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
142
140
|
setTimeout(() => {
|
|
143
141
|
var _a;
|
|
144
142
|
const el = unrefElement(target);
|
|
145
|
-
if (((_a = window.document.activeElement) == null ?
|
|
143
|
+
if (((_a = window.document.activeElement) == null ? undefined : _a.tagName) === "IFRAME" && !(el == null ? undefined : el.contains(window.document.activeElement))) {
|
|
146
144
|
handler(event);
|
|
147
145
|
}
|
|
148
146
|
}, 0);
|
|
149
|
-
})
|
|
147
|
+
}, { passive: true })
|
|
150
148
|
].filter(Boolean);
|
|
151
149
|
const stop = () => cleanup.forEach((fn) => fn());
|
|
152
150
|
return stop;
|
|
@@ -216,7 +214,7 @@ function onKeyStroke(...args) {
|
|
|
216
214
|
const vOnKeyStroke = {
|
|
217
215
|
mounted(el, binding) {
|
|
218
216
|
var _a, _b;
|
|
219
|
-
const keys = (_b = (_a = binding.arg) == null ?
|
|
217
|
+
const keys = (_b = (_a = binding.arg) == null ? undefined : _a.split(",")) != null ? _b : true;
|
|
220
218
|
if (typeof binding.value === "function") {
|
|
221
219
|
onKeyStroke(keys, binding.value, {
|
|
222
220
|
target: el
|
|
@@ -243,23 +241,23 @@ function onLongPress(target, handler, options) {
|
|
|
243
241
|
function clear() {
|
|
244
242
|
if (timeout) {
|
|
245
243
|
clearTimeout(timeout);
|
|
246
|
-
timeout =
|
|
244
|
+
timeout = undefined;
|
|
247
245
|
}
|
|
248
|
-
posStart =
|
|
249
|
-
startTimestamp =
|
|
246
|
+
posStart = undefined;
|
|
247
|
+
startTimestamp = undefined;
|
|
250
248
|
hasLongPressed = false;
|
|
251
249
|
}
|
|
252
250
|
function onRelease(ev) {
|
|
253
251
|
var _a2, _b2, _c;
|
|
254
252
|
const [_startTimestamp, _posStart, _hasLongPressed] = [startTimestamp, posStart, hasLongPressed];
|
|
255
253
|
clear();
|
|
256
|
-
if (!(options == null ?
|
|
254
|
+
if (!(options == null ? undefined : options.onMouseUp) || !_posStart || !_startTimestamp)
|
|
257
255
|
return;
|
|
258
|
-
if (((_a2 = options == null ?
|
|
256
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
259
257
|
return;
|
|
260
|
-
if ((_b2 = options == null ?
|
|
258
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
261
259
|
ev.preventDefault();
|
|
262
|
-
if ((_c = options == null ?
|
|
260
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
263
261
|
ev.stopPropagation();
|
|
264
262
|
const dx = ev.x - _posStart.x;
|
|
265
263
|
const dy = ev.y - _posStart.y;
|
|
@@ -268,12 +266,12 @@ function onLongPress(target, handler, options) {
|
|
|
268
266
|
}
|
|
269
267
|
function onDown(ev) {
|
|
270
268
|
var _a2, _b2, _c, _d;
|
|
271
|
-
if (((_a2 = options == null ?
|
|
269
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
272
270
|
return;
|
|
273
271
|
clear();
|
|
274
|
-
if ((_b2 = options == null ?
|
|
272
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
275
273
|
ev.preventDefault();
|
|
276
|
-
if ((_c = options == null ?
|
|
274
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
277
275
|
ev.stopPropagation();
|
|
278
276
|
posStart = {
|
|
279
277
|
x: ev.x,
|
|
@@ -285,28 +283,28 @@ function onLongPress(target, handler, options) {
|
|
|
285
283
|
hasLongPressed = true;
|
|
286
284
|
handler(ev);
|
|
287
285
|
},
|
|
288
|
-
(_d = options == null ?
|
|
286
|
+
(_d = options == null ? undefined : options.delay) != null ? _d : DEFAULT_DELAY
|
|
289
287
|
);
|
|
290
288
|
}
|
|
291
289
|
function onMove(ev) {
|
|
292
290
|
var _a2, _b2, _c, _d;
|
|
293
|
-
if (((_a2 = options == null ?
|
|
291
|
+
if (((_a2 = options == null ? undefined : options.modifiers) == null ? undefined : _a2.self) && ev.target !== elementRef.value)
|
|
294
292
|
return;
|
|
295
|
-
if (!posStart || (options == null ?
|
|
293
|
+
if (!posStart || (options == null ? undefined : options.distanceThreshold) === false)
|
|
296
294
|
return;
|
|
297
|
-
if ((_b2 = options == null ?
|
|
295
|
+
if ((_b2 = options == null ? undefined : options.modifiers) == null ? undefined : _b2.prevent)
|
|
298
296
|
ev.preventDefault();
|
|
299
|
-
if ((_c = options == null ?
|
|
297
|
+
if ((_c = options == null ? undefined : options.modifiers) == null ? undefined : _c.stop)
|
|
300
298
|
ev.stopPropagation();
|
|
301
299
|
const dx = ev.x - posStart.x;
|
|
302
300
|
const dy = ev.y - posStart.y;
|
|
303
301
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
304
|
-
if (distance >= ((_d = options == null ?
|
|
302
|
+
if (distance >= ((_d = options == null ? undefined : options.distanceThreshold) != null ? _d : DEFAULT_THRESHOLD))
|
|
305
303
|
clear();
|
|
306
304
|
}
|
|
307
305
|
const listenerOptions = {
|
|
308
|
-
capture: (_a = options == null ?
|
|
309
|
-
once: (_b = options == null ?
|
|
306
|
+
capture: (_a = options == null ? undefined : options.modifiers) == null ? undefined : _a.capture,
|
|
307
|
+
once: (_b = options == null ? undefined : options.modifiers) == null ? undefined : _b.once
|
|
310
308
|
};
|
|
311
309
|
const cleanup = [
|
|
312
310
|
useEventListener(elementRef, "pointerdown", onDown, listenerOptions),
|
|
@@ -394,7 +392,7 @@ const UseClipboard = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
394
392
|
const data = reactive(useClipboard(props));
|
|
395
393
|
return () => {
|
|
396
394
|
var _a;
|
|
397
|
-
return (_a = slots.default) == null ?
|
|
395
|
+
return (_a = slots.default) == null ? undefined : _a.call(slots, data);
|
|
398
396
|
};
|
|
399
397
|
}
|
|
400
398
|
});
|
|
@@ -414,7 +412,7 @@ function getSSRHandler(key, fallback) {
|
|
|
414
412
|
const ssrWidthSymbol = Symbol("vueuse-ssr-width");
|
|
415
413
|
function useSSRWidth() {
|
|
416
414
|
const ssrWidth = hasInjectionContext() ? injectLocal(ssrWidthSymbol, null) : null;
|
|
417
|
-
return typeof ssrWidth === "number" ? ssrWidth :
|
|
415
|
+
return typeof ssrWidth === "number" ? ssrWidth : undefined;
|
|
418
416
|
}
|
|
419
417
|
|
|
420
418
|
function useMounted() {
|
|
@@ -485,7 +483,7 @@ function useMediaQuery(query, options = {}) {
|
|
|
485
483
|
tryOnScopeDispose(() => {
|
|
486
484
|
stopWatch();
|
|
487
485
|
cleanup();
|
|
488
|
-
mediaQuery =
|
|
486
|
+
mediaQuery = undefined;
|
|
489
487
|
});
|
|
490
488
|
return computed(() => matches.value);
|
|
491
489
|
}
|
|
@@ -550,6 +548,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
550
548
|
initOnMounted
|
|
551
549
|
} = options;
|
|
552
550
|
const data = (shallow ? shallowRef : ref)(typeof defaults === "function" ? defaults() : defaults);
|
|
551
|
+
const keyComputed = computed(() => toValue(key));
|
|
553
552
|
if (!storage) {
|
|
554
553
|
try {
|
|
555
554
|
storage = getSSRHandler("getDefaultStorage", () => {
|
|
@@ -570,10 +569,11 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
570
569
|
() => write(data.value),
|
|
571
570
|
{ flush, deep, eventFilter }
|
|
572
571
|
);
|
|
572
|
+
watch(keyComputed, () => update(), { flush });
|
|
573
573
|
if (window && listenToStorageChanges) {
|
|
574
574
|
tryOnMounted(() => {
|
|
575
575
|
if (storage instanceof Storage)
|
|
576
|
-
useEventListener(window, "storage", update);
|
|
576
|
+
useEventListener(window, "storage", update, { passive: true });
|
|
577
577
|
else
|
|
578
578
|
useEventListener(window, customStorageEventName, updateFromCustomEvent);
|
|
579
579
|
if (initOnMounted)
|
|
@@ -585,7 +585,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
585
585
|
function dispatchWriteEvent(oldValue, newValue) {
|
|
586
586
|
if (window) {
|
|
587
587
|
const payload = {
|
|
588
|
-
key,
|
|
588
|
+
key: keyComputed.value,
|
|
589
589
|
oldValue,
|
|
590
590
|
newValue,
|
|
591
591
|
storageArea: storage
|
|
@@ -597,14 +597,14 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
597
597
|
}
|
|
598
598
|
function write(v) {
|
|
599
599
|
try {
|
|
600
|
-
const oldValue = storage.getItem(
|
|
600
|
+
const oldValue = storage.getItem(keyComputed.value);
|
|
601
601
|
if (v == null) {
|
|
602
602
|
dispatchWriteEvent(oldValue, null);
|
|
603
|
-
storage.removeItem(
|
|
603
|
+
storage.removeItem(keyComputed.value);
|
|
604
604
|
} else {
|
|
605
605
|
const serialized = serializer.write(v);
|
|
606
606
|
if (oldValue !== serialized) {
|
|
607
|
-
storage.setItem(
|
|
607
|
+
storage.setItem(keyComputed.value, serialized);
|
|
608
608
|
dispatchWriteEvent(oldValue, serialized);
|
|
609
609
|
}
|
|
610
610
|
}
|
|
@@ -613,10 +613,10 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
function read(event) {
|
|
616
|
-
const rawValue = event ? event.newValue : storage.getItem(
|
|
616
|
+
const rawValue = event ? event.newValue : storage.getItem(keyComputed.value);
|
|
617
617
|
if (rawValue == null) {
|
|
618
618
|
if (writeDefaults && rawInit != null)
|
|
619
|
-
storage.setItem(
|
|
619
|
+
storage.setItem(keyComputed.value, serializer.write(rawInit));
|
|
620
620
|
return rawInit;
|
|
621
621
|
} else if (!event && mergeDefaults) {
|
|
622
622
|
const value = serializer.read(rawValue);
|
|
@@ -638,7 +638,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
638
638
|
data.value = rawInit;
|
|
639
639
|
return;
|
|
640
640
|
}
|
|
641
|
-
if (event && event.key !==
|
|
641
|
+
if (event && event.key !== keyComputed.value)
|
|
642
642
|
return;
|
|
643
643
|
pauseWatch();
|
|
644
644
|
try {
|
|
@@ -686,7 +686,7 @@ function useColorMode(options = {}) {
|
|
|
686
686
|
const updateHTMLAttrs = getSSRHandler(
|
|
687
687
|
"updateHTMLAttrs",
|
|
688
688
|
(selector2, attribute2, value) => {
|
|
689
|
-
const el = typeof selector2 === "string" ? window == null ?
|
|
689
|
+
const el = typeof selector2 === "string" ? window == null ? undefined : window.document.querySelector(selector2) : unrefElement(selector2);
|
|
690
690
|
if (!el)
|
|
691
691
|
return;
|
|
692
692
|
const classesToAdd = /* @__PURE__ */ new Set();
|
|
@@ -870,18 +870,18 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
870
870
|
});
|
|
871
871
|
const containerElement = computed(() => {
|
|
872
872
|
var _a;
|
|
873
|
-
return (_a = props.containerElement) != null ? _a :
|
|
873
|
+
return (_a = props.containerElement) != null ? _a : undefined;
|
|
874
874
|
});
|
|
875
875
|
const disabled = computed(() => !!props.disabled);
|
|
876
876
|
const storageValue = props.storageKey && useStorage$1(
|
|
877
877
|
props.storageKey,
|
|
878
878
|
toValue(props.initialValue) || { x: 0, y: 0 },
|
|
879
|
-
isClient$1 ? props.storageType === "session" ? sessionStorage : localStorage :
|
|
879
|
+
isClient$1 ? props.storageType === "session" ? sessionStorage : localStorage : undefined
|
|
880
880
|
);
|
|
881
881
|
const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
|
|
882
882
|
const onEnd = (position, event) => {
|
|
883
883
|
var _a;
|
|
884
|
-
(_a = props.onEnd) == null ?
|
|
884
|
+
(_a = props.onEnd) == null ? undefined : _a.call(props, position, event);
|
|
885
885
|
if (!storageValue)
|
|
886
886
|
return;
|
|
887
887
|
storageValue.value.x = position.x;
|
|
@@ -907,7 +907,7 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
907
907
|
props: ["box", "as"],
|
|
908
908
|
setup(props, { slots }) {
|
|
909
909
|
const target = ref();
|
|
910
|
-
const data = reactive(useElementBounding(target));
|
|
910
|
+
const data = reactive(useElementBounding$1(target));
|
|
911
911
|
return () => {
|
|
912
912
|
if (slots.default)
|
|
913
913
|
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
@@ -915,10 +915,222 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
915
915
|
}
|
|
916
916
|
});
|
|
917
917
|
|
|
918
|
+
function useMutationObserver(target, callback, options = {}) {
|
|
919
|
+
const { window = defaultWindow, ...mutationOptions } = options;
|
|
920
|
+
let observer;
|
|
921
|
+
const isSupported = useSupported(() => window && "MutationObserver" in window);
|
|
922
|
+
const cleanup = () => {
|
|
923
|
+
if (observer) {
|
|
924
|
+
observer.disconnect();
|
|
925
|
+
observer = undefined;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
const targets = computed(() => {
|
|
929
|
+
const value = toValue(target);
|
|
930
|
+
const items = toArray(value).map(unrefElement).filter(notNullish);
|
|
931
|
+
return new Set(items);
|
|
932
|
+
});
|
|
933
|
+
const stopWatch = watch(
|
|
934
|
+
() => targets.value,
|
|
935
|
+
(targets2) => {
|
|
936
|
+
cleanup();
|
|
937
|
+
if (isSupported.value && targets2.size) {
|
|
938
|
+
observer = new MutationObserver(callback);
|
|
939
|
+
targets2.forEach((el) => observer.observe(el, mutationOptions));
|
|
940
|
+
}
|
|
941
|
+
},
|
|
942
|
+
{ immediate: true, flush: "post" }
|
|
943
|
+
);
|
|
944
|
+
const takeRecords = () => {
|
|
945
|
+
return observer == null ? undefined : observer.takeRecords();
|
|
946
|
+
};
|
|
947
|
+
const stop = () => {
|
|
948
|
+
stopWatch();
|
|
949
|
+
cleanup();
|
|
950
|
+
};
|
|
951
|
+
tryOnScopeDispose(stop);
|
|
952
|
+
return {
|
|
953
|
+
isSupported,
|
|
954
|
+
stop,
|
|
955
|
+
takeRecords
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
function useResizeObserver(target, callback, options = {}) {
|
|
960
|
+
const { window = defaultWindow, ...observerOptions } = options;
|
|
961
|
+
let observer;
|
|
962
|
+
const isSupported = useSupported(() => window && "ResizeObserver" in window);
|
|
963
|
+
const cleanup = () => {
|
|
964
|
+
if (observer) {
|
|
965
|
+
observer.disconnect();
|
|
966
|
+
observer = undefined;
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
const targets = computed(() => {
|
|
970
|
+
const _targets = toValue(target);
|
|
971
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
972
|
+
});
|
|
973
|
+
const stopWatch = watch(
|
|
974
|
+
targets,
|
|
975
|
+
(els) => {
|
|
976
|
+
cleanup();
|
|
977
|
+
if (isSupported.value && window) {
|
|
978
|
+
observer = new ResizeObserver(callback);
|
|
979
|
+
for (const _el of els) {
|
|
980
|
+
if (_el)
|
|
981
|
+
observer.observe(_el, observerOptions);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
{ immediate: true, flush: "post" }
|
|
986
|
+
);
|
|
987
|
+
const stop = () => {
|
|
988
|
+
cleanup();
|
|
989
|
+
stopWatch();
|
|
990
|
+
};
|
|
991
|
+
tryOnScopeDispose(stop);
|
|
992
|
+
return {
|
|
993
|
+
isSupported,
|
|
994
|
+
stop
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function useElementBounding(target, options = {}) {
|
|
999
|
+
const {
|
|
1000
|
+
reset = true,
|
|
1001
|
+
windowResize = true,
|
|
1002
|
+
windowScroll = true,
|
|
1003
|
+
immediate = true,
|
|
1004
|
+
updateTiming = "sync"
|
|
1005
|
+
} = options;
|
|
1006
|
+
const height = ref(0);
|
|
1007
|
+
const bottom = ref(0);
|
|
1008
|
+
const left = ref(0);
|
|
1009
|
+
const right = ref(0);
|
|
1010
|
+
const top = ref(0);
|
|
1011
|
+
const width = ref(0);
|
|
1012
|
+
const x = ref(0);
|
|
1013
|
+
const y = ref(0);
|
|
1014
|
+
function recalculate() {
|
|
1015
|
+
const el = unrefElement(target);
|
|
1016
|
+
if (!el) {
|
|
1017
|
+
if (reset) {
|
|
1018
|
+
height.value = 0;
|
|
1019
|
+
bottom.value = 0;
|
|
1020
|
+
left.value = 0;
|
|
1021
|
+
right.value = 0;
|
|
1022
|
+
top.value = 0;
|
|
1023
|
+
width.value = 0;
|
|
1024
|
+
x.value = 0;
|
|
1025
|
+
y.value = 0;
|
|
1026
|
+
}
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
const rect = el.getBoundingClientRect();
|
|
1030
|
+
height.value = rect.height;
|
|
1031
|
+
bottom.value = rect.bottom;
|
|
1032
|
+
left.value = rect.left;
|
|
1033
|
+
right.value = rect.right;
|
|
1034
|
+
top.value = rect.top;
|
|
1035
|
+
width.value = rect.width;
|
|
1036
|
+
x.value = rect.x;
|
|
1037
|
+
y.value = rect.y;
|
|
1038
|
+
}
|
|
1039
|
+
function update() {
|
|
1040
|
+
if (updateTiming === "sync")
|
|
1041
|
+
recalculate();
|
|
1042
|
+
else if (updateTiming === "next-frame")
|
|
1043
|
+
requestAnimationFrame(() => recalculate());
|
|
1044
|
+
}
|
|
1045
|
+
useResizeObserver(target, update);
|
|
1046
|
+
watch(() => unrefElement(target), (ele) => !ele && update());
|
|
1047
|
+
useMutationObserver(target, update, {
|
|
1048
|
+
attributeFilter: ["style", "class"]
|
|
1049
|
+
});
|
|
1050
|
+
if (windowScroll)
|
|
1051
|
+
useEventListener("scroll", update, { capture: true, passive: true });
|
|
1052
|
+
if (windowResize)
|
|
1053
|
+
useEventListener("resize", update, { passive: true });
|
|
1054
|
+
tryOnMounted(() => {
|
|
1055
|
+
if (immediate)
|
|
1056
|
+
update();
|
|
1057
|
+
});
|
|
1058
|
+
return {
|
|
1059
|
+
height,
|
|
1060
|
+
bottom,
|
|
1061
|
+
left,
|
|
1062
|
+
right,
|
|
1063
|
+
top,
|
|
1064
|
+
width,
|
|
1065
|
+
x,
|
|
1066
|
+
y,
|
|
1067
|
+
update
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
const vElementBounding = {
|
|
1072
|
+
mounted(el, binding) {
|
|
1073
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1074
|
+
const {
|
|
1075
|
+
height,
|
|
1076
|
+
bottom,
|
|
1077
|
+
left,
|
|
1078
|
+
right,
|
|
1079
|
+
top,
|
|
1080
|
+
width,
|
|
1081
|
+
x,
|
|
1082
|
+
y
|
|
1083
|
+
} = useElementBounding(el, options);
|
|
1084
|
+
watch([height, bottom, left, right, top, width, x, y], () => handler({ height, bottom, left, right, top, width, x, y }));
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
function onElementRemoval(target, callback, options = {}) {
|
|
1089
|
+
const {
|
|
1090
|
+
window = defaultWindow,
|
|
1091
|
+
document = window == null ? undefined : window.document,
|
|
1092
|
+
flush = "sync"
|
|
1093
|
+
} = options;
|
|
1094
|
+
if (!window || !document)
|
|
1095
|
+
return noop;
|
|
1096
|
+
let stopFn;
|
|
1097
|
+
const cleanupAndUpdate = (fn) => {
|
|
1098
|
+
stopFn == null ? undefined : stopFn();
|
|
1099
|
+
stopFn = fn;
|
|
1100
|
+
};
|
|
1101
|
+
const stopWatch = watchEffect(() => {
|
|
1102
|
+
const el = unrefElement(target);
|
|
1103
|
+
if (el) {
|
|
1104
|
+
const { stop } = useMutationObserver(
|
|
1105
|
+
document,
|
|
1106
|
+
(mutationsList) => {
|
|
1107
|
+
const targetRemoved = mutationsList.map((mutation) => [...mutation.removedNodes]).flat().some((node) => node === el || node.contains(el));
|
|
1108
|
+
if (targetRemoved) {
|
|
1109
|
+
callback(mutationsList);
|
|
1110
|
+
}
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
window,
|
|
1114
|
+
childList: true,
|
|
1115
|
+
subtree: true
|
|
1116
|
+
}
|
|
1117
|
+
);
|
|
1118
|
+
cleanupAndUpdate(stop);
|
|
1119
|
+
}
|
|
1120
|
+
}, { flush });
|
|
1121
|
+
const stopHandle = () => {
|
|
1122
|
+
stopWatch();
|
|
1123
|
+
cleanupAndUpdate();
|
|
1124
|
+
};
|
|
1125
|
+
tryOnScopeDispose(stopHandle);
|
|
1126
|
+
return stopHandle;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
918
1129
|
function useElementHover(el, options = {}) {
|
|
919
1130
|
const {
|
|
920
1131
|
delayEnter = 0,
|
|
921
1132
|
delayLeave = 0,
|
|
1133
|
+
triggerOnRemoval = false,
|
|
922
1134
|
window = defaultWindow
|
|
923
1135
|
} = options;
|
|
924
1136
|
const isHovered = ref(false);
|
|
@@ -927,7 +1139,7 @@ function useElementHover(el, options = {}) {
|
|
|
927
1139
|
const delay = entering ? delayEnter : delayLeave;
|
|
928
1140
|
if (timer) {
|
|
929
1141
|
clearTimeout(timer);
|
|
930
|
-
timer =
|
|
1142
|
+
timer = undefined;
|
|
931
1143
|
}
|
|
932
1144
|
if (delay)
|
|
933
1145
|
timer = setTimeout(() => isHovered.value = entering, delay);
|
|
@@ -938,6 +1150,12 @@ function useElementHover(el, options = {}) {
|
|
|
938
1150
|
return isHovered;
|
|
939
1151
|
useEventListener(el, "mouseenter", () => toggle(true), { passive: true });
|
|
940
1152
|
useEventListener(el, "mouseleave", () => toggle(false), { passive: true });
|
|
1153
|
+
if (triggerOnRemoval) {
|
|
1154
|
+
onElementRemoval(
|
|
1155
|
+
computed(() => unrefElement(el)),
|
|
1156
|
+
() => toggle(false)
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
941
1159
|
return isHovered;
|
|
942
1160
|
}
|
|
943
1161
|
|
|
@@ -968,50 +1186,11 @@ const UseElementSize = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
968
1186
|
}
|
|
969
1187
|
});
|
|
970
1188
|
|
|
971
|
-
function useResizeObserver(target, callback, options = {}) {
|
|
972
|
-
const { window = defaultWindow, ...observerOptions } = options;
|
|
973
|
-
let observer;
|
|
974
|
-
const isSupported = useSupported(() => window && "ResizeObserver" in window);
|
|
975
|
-
const cleanup = () => {
|
|
976
|
-
if (observer) {
|
|
977
|
-
observer.disconnect();
|
|
978
|
-
observer = void 0;
|
|
979
|
-
}
|
|
980
|
-
};
|
|
981
|
-
const targets = computed(() => {
|
|
982
|
-
const _targets = toValue(target);
|
|
983
|
-
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
984
|
-
});
|
|
985
|
-
const stopWatch = watch(
|
|
986
|
-
targets,
|
|
987
|
-
(els) => {
|
|
988
|
-
cleanup();
|
|
989
|
-
if (isSupported.value && window) {
|
|
990
|
-
observer = new ResizeObserver(callback);
|
|
991
|
-
for (const _el of els) {
|
|
992
|
-
if (_el)
|
|
993
|
-
observer.observe(_el, observerOptions);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
},
|
|
997
|
-
{ immediate: true, flush: "post" }
|
|
998
|
-
);
|
|
999
|
-
const stop = () => {
|
|
1000
|
-
cleanup();
|
|
1001
|
-
stopWatch();
|
|
1002
|
-
};
|
|
1003
|
-
tryOnScopeDispose(stop);
|
|
1004
|
-
return {
|
|
1005
|
-
isSupported,
|
|
1006
|
-
stop
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
1189
|
function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
|
|
1011
1190
|
const { window = defaultWindow, box = "content-box" } = options;
|
|
1012
1191
|
const isSVG = computed(() => {
|
|
1013
1192
|
var _a, _b;
|
|
1014
|
-
return (_b = (_a = unrefElement(target)) == null ?
|
|
1193
|
+
return (_b = (_a = unrefElement(target)) == null ? undefined : _a.namespaceURI) == null ? undefined : _b.includes("svg");
|
|
1015
1194
|
});
|
|
1016
1195
|
const width = ref(initialSize.width);
|
|
1017
1196
|
const height = ref(initialSize.height);
|
|
@@ -1028,7 +1207,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1028
1207
|
}
|
|
1029
1208
|
} else {
|
|
1030
1209
|
if (boxSize) {
|
|
1031
|
-
const formatBoxSize =
|
|
1210
|
+
const formatBoxSize = toArray(boxSize);
|
|
1032
1211
|
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
1033
1212
|
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
1034
1213
|
} else {
|
|
@@ -1067,7 +1246,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1067
1246
|
const vElementSize = {
|
|
1068
1247
|
mounted(el, binding) {
|
|
1069
1248
|
var _a;
|
|
1070
|
-
const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ?
|
|
1249
|
+
const handler = typeof binding.value === "function" ? binding.value : (_a = binding.value) == null ? undefined : _a[0];
|
|
1071
1250
|
const options = typeof binding.value === "function" ? [] : binding.value.slice(1);
|
|
1072
1251
|
const { width, height } = useElementSize(el, ...options);
|
|
1073
1252
|
watch([width, height], ([width2, height2]) => handler({ width: width2, height: height2 }));
|
|
@@ -1100,7 +1279,7 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
1100
1279
|
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
1101
1280
|
const targets = computed(() => {
|
|
1102
1281
|
const _target = toValue(target);
|
|
1103
|
-
return (
|
|
1282
|
+
return toArray(_target).map(unrefElement).filter(notNullish);
|
|
1104
1283
|
});
|
|
1105
1284
|
let cleanup = noop;
|
|
1106
1285
|
const isActive = ref(immediate);
|
|
@@ -1257,11 +1436,11 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1257
1436
|
const state = shallow ? shallowRef(initialState) : ref(initialState);
|
|
1258
1437
|
const isReady = ref(false);
|
|
1259
1438
|
const isLoading = ref(false);
|
|
1260
|
-
const error = shallowRef(
|
|
1439
|
+
const error = shallowRef(undefined);
|
|
1261
1440
|
async function execute(delay2 = 0, ...args) {
|
|
1262
1441
|
if (resetOnExecute)
|
|
1263
1442
|
state.value = initialState;
|
|
1264
|
-
error.value =
|
|
1443
|
+
error.value = undefined;
|
|
1265
1444
|
isReady.value = false;
|
|
1266
1445
|
isLoading.value = true;
|
|
1267
1446
|
if (delay2 > 0)
|
|
@@ -1282,8 +1461,9 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1282
1461
|
}
|
|
1283
1462
|
return state.value;
|
|
1284
1463
|
}
|
|
1285
|
-
if (immediate)
|
|
1464
|
+
if (immediate) {
|
|
1286
1465
|
execute(delay);
|
|
1466
|
+
}
|
|
1287
1467
|
const shell = {
|
|
1288
1468
|
state,
|
|
1289
1469
|
isReady,
|
|
@@ -1340,7 +1520,7 @@ async function loadImage(options) {
|
|
|
1340
1520
|
function useImage(options, asyncStateOptions = {}) {
|
|
1341
1521
|
const state = useAsyncState(
|
|
1342
1522
|
() => loadImage(toValue(options)),
|
|
1343
|
-
|
|
1523
|
+
undefined,
|
|
1344
1524
|
{
|
|
1345
1525
|
resetOnExecute: true,
|
|
1346
1526
|
...asyncStateOptions
|
|
@@ -1425,7 +1605,7 @@ function useScroll(element, options = {}) {
|
|
|
1425
1605
|
return internalX.value;
|
|
1426
1606
|
},
|
|
1427
1607
|
set(x2) {
|
|
1428
|
-
scrollTo(x2,
|
|
1608
|
+
scrollTo(x2, undefined);
|
|
1429
1609
|
}
|
|
1430
1610
|
});
|
|
1431
1611
|
const y = computed({
|
|
@@ -1433,7 +1613,7 @@ function useScroll(element, options = {}) {
|
|
|
1433
1613
|
return internalY.value;
|
|
1434
1614
|
},
|
|
1435
1615
|
set(y2) {
|
|
1436
|
-
scrollTo(
|
|
1616
|
+
scrollTo(undefined, y2);
|
|
1437
1617
|
}
|
|
1438
1618
|
});
|
|
1439
1619
|
function scrollTo(_x, _y) {
|
|
@@ -1443,12 +1623,12 @@ function useScroll(element, options = {}) {
|
|
|
1443
1623
|
const _element = toValue(element);
|
|
1444
1624
|
if (!_element)
|
|
1445
1625
|
return;
|
|
1446
|
-
(_c = _element instanceof Document ? window.document.body : _element) == null ?
|
|
1626
|
+
(_c = _element instanceof Document ? window.document.body : _element) == null ? undefined : _c.scrollTo({
|
|
1447
1627
|
top: (_a = toValue(_y)) != null ? _a : y.value,
|
|
1448
1628
|
left: (_b = toValue(_x)) != null ? _b : x.value,
|
|
1449
1629
|
behavior: toValue(behavior)
|
|
1450
1630
|
});
|
|
1451
|
-
const scrollContainer = ((_d = _element == null ?
|
|
1631
|
+
const scrollContainer = ((_d = _element == null ? undefined : _element.document) == null ? undefined : _d.documentElement) || (_element == null ? undefined : _element.documentElement) || _element;
|
|
1452
1632
|
if (x != null)
|
|
1453
1633
|
internalX.value = scrollContainer.scrollLeft;
|
|
1454
1634
|
if (y != null)
|
|
@@ -1482,7 +1662,7 @@ function useScroll(element, options = {}) {
|
|
|
1482
1662
|
var _a;
|
|
1483
1663
|
if (!window)
|
|
1484
1664
|
return;
|
|
1485
|
-
const el = ((_a = target == null ?
|
|
1665
|
+
const el = ((_a = target == null ? undefined : target.document) == null ? undefined : _a.documentElement) || (target == null ? undefined : target.documentElement) || unrefElement(target);
|
|
1486
1666
|
const { display, flexDirection, direction } = getComputedStyle(el);
|
|
1487
1667
|
const directionMultipler = direction === "rtl" ? -1 : 1;
|
|
1488
1668
|
const scrollLeft = el.scrollLeft;
|
|
@@ -1637,7 +1817,7 @@ const UseMouse = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1637
1817
|
name: "UseMouse",
|
|
1638
1818
|
props: ["touch", "resetOnTouchEnds", "initialValue"],
|
|
1639
1819
|
setup(props, { slots }) {
|
|
1640
|
-
const data = reactive(useMouse(props));
|
|
1820
|
+
const data = reactive(useMouse$1(props));
|
|
1641
1821
|
return () => {
|
|
1642
1822
|
if (slots.default)
|
|
1643
1823
|
return slots.default(data);
|
|
@@ -1650,7 +1830,7 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1650
1830
|
props: ["handleOutside", "as"],
|
|
1651
1831
|
setup(props, { slots }) {
|
|
1652
1832
|
const target = ref();
|
|
1653
|
-
const data = reactive(useMouseInElement(target, props));
|
|
1833
|
+
const data = reactive(useMouseInElement$1(target, props));
|
|
1654
1834
|
return () => {
|
|
1655
1835
|
if (slots.default)
|
|
1656
1836
|
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
@@ -1658,6 +1838,159 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1658
1838
|
}
|
|
1659
1839
|
});
|
|
1660
1840
|
|
|
1841
|
+
const UseMouseBuiltinExtractors = {
|
|
1842
|
+
page: (event) => [event.pageX, event.pageY],
|
|
1843
|
+
client: (event) => [event.clientX, event.clientY],
|
|
1844
|
+
screen: (event) => [event.screenX, event.screenY],
|
|
1845
|
+
movement: (event) => event instanceof Touch ? null : [event.movementX, event.movementY]
|
|
1846
|
+
};
|
|
1847
|
+
function useMouse(options = {}) {
|
|
1848
|
+
const {
|
|
1849
|
+
type = "page",
|
|
1850
|
+
touch = true,
|
|
1851
|
+
resetOnTouchEnds = false,
|
|
1852
|
+
initialValue = { x: 0, y: 0 },
|
|
1853
|
+
window = defaultWindow,
|
|
1854
|
+
target = window,
|
|
1855
|
+
scroll = true,
|
|
1856
|
+
eventFilter
|
|
1857
|
+
} = options;
|
|
1858
|
+
let _prevMouseEvent = null;
|
|
1859
|
+
let _prevScrollX = 0;
|
|
1860
|
+
let _prevScrollY = 0;
|
|
1861
|
+
const x = ref(initialValue.x);
|
|
1862
|
+
const y = ref(initialValue.y);
|
|
1863
|
+
const sourceType = ref(null);
|
|
1864
|
+
const extractor = typeof type === "function" ? type : UseMouseBuiltinExtractors[type];
|
|
1865
|
+
const mouseHandler = (event) => {
|
|
1866
|
+
const result = extractor(event);
|
|
1867
|
+
_prevMouseEvent = event;
|
|
1868
|
+
if (result) {
|
|
1869
|
+
[x.value, y.value] = result;
|
|
1870
|
+
sourceType.value = "mouse";
|
|
1871
|
+
}
|
|
1872
|
+
if (window) {
|
|
1873
|
+
_prevScrollX = window.scrollX;
|
|
1874
|
+
_prevScrollY = window.scrollY;
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
const touchHandler = (event) => {
|
|
1878
|
+
if (event.touches.length > 0) {
|
|
1879
|
+
const result = extractor(event.touches[0]);
|
|
1880
|
+
if (result) {
|
|
1881
|
+
[x.value, y.value] = result;
|
|
1882
|
+
sourceType.value = "touch";
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
const scrollHandler = () => {
|
|
1887
|
+
if (!_prevMouseEvent || !window)
|
|
1888
|
+
return;
|
|
1889
|
+
const pos = extractor(_prevMouseEvent);
|
|
1890
|
+
if (_prevMouseEvent instanceof MouseEvent && pos) {
|
|
1891
|
+
x.value = pos[0] + window.scrollX - _prevScrollX;
|
|
1892
|
+
y.value = pos[1] + window.scrollY - _prevScrollY;
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
const reset = () => {
|
|
1896
|
+
x.value = initialValue.x;
|
|
1897
|
+
y.value = initialValue.y;
|
|
1898
|
+
};
|
|
1899
|
+
const mouseHandlerWrapper = eventFilter ? (event) => eventFilter(() => mouseHandler(event), {}) : (event) => mouseHandler(event);
|
|
1900
|
+
const touchHandlerWrapper = eventFilter ? (event) => eventFilter(() => touchHandler(event), {}) : (event) => touchHandler(event);
|
|
1901
|
+
const scrollHandlerWrapper = eventFilter ? () => eventFilter(() => scrollHandler(), {}) : () => scrollHandler();
|
|
1902
|
+
if (target) {
|
|
1903
|
+
const listenerOptions = { passive: true };
|
|
1904
|
+
useEventListener(target, ["mousemove", "dragover"], mouseHandlerWrapper, listenerOptions);
|
|
1905
|
+
if (touch && type !== "movement") {
|
|
1906
|
+
useEventListener(target, ["touchstart", "touchmove"], touchHandlerWrapper, listenerOptions);
|
|
1907
|
+
if (resetOnTouchEnds)
|
|
1908
|
+
useEventListener(target, "touchend", reset, listenerOptions);
|
|
1909
|
+
}
|
|
1910
|
+
if (scroll && type === "page")
|
|
1911
|
+
useEventListener(window, "scroll", scrollHandlerWrapper, listenerOptions);
|
|
1912
|
+
}
|
|
1913
|
+
return {
|
|
1914
|
+
x,
|
|
1915
|
+
y,
|
|
1916
|
+
sourceType
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
function useMouseInElement(target, options = {}) {
|
|
1921
|
+
const {
|
|
1922
|
+
handleOutside = true,
|
|
1923
|
+
window = defaultWindow
|
|
1924
|
+
} = options;
|
|
1925
|
+
const type = options.type || "page";
|
|
1926
|
+
const { x, y, sourceType } = useMouse(options);
|
|
1927
|
+
const targetRef = ref(target != null ? target : window == null ? undefined : window.document.body);
|
|
1928
|
+
const elementX = ref(0);
|
|
1929
|
+
const elementY = ref(0);
|
|
1930
|
+
const elementPositionX = ref(0);
|
|
1931
|
+
const elementPositionY = ref(0);
|
|
1932
|
+
const elementHeight = ref(0);
|
|
1933
|
+
const elementWidth = ref(0);
|
|
1934
|
+
const isOutside = ref(true);
|
|
1935
|
+
let stop = () => {
|
|
1936
|
+
};
|
|
1937
|
+
if (window) {
|
|
1938
|
+
stop = watch(
|
|
1939
|
+
[targetRef, x, y],
|
|
1940
|
+
() => {
|
|
1941
|
+
const el = unrefElement(targetRef);
|
|
1942
|
+
if (!el || !(el instanceof Element))
|
|
1943
|
+
return;
|
|
1944
|
+
const {
|
|
1945
|
+
left,
|
|
1946
|
+
top,
|
|
1947
|
+
width,
|
|
1948
|
+
height
|
|
1949
|
+
} = el.getBoundingClientRect();
|
|
1950
|
+
elementPositionX.value = left + (type === "page" ? window.pageXOffset : 0);
|
|
1951
|
+
elementPositionY.value = top + (type === "page" ? window.pageYOffset : 0);
|
|
1952
|
+
elementHeight.value = height;
|
|
1953
|
+
elementWidth.value = width;
|
|
1954
|
+
const elX = x.value - elementPositionX.value;
|
|
1955
|
+
const elY = y.value - elementPositionY.value;
|
|
1956
|
+
isOutside.value = width === 0 || height === 0 || elX < 0 || elY < 0 || elX > width || elY > height;
|
|
1957
|
+
if (handleOutside || !isOutside.value) {
|
|
1958
|
+
elementX.value = elX;
|
|
1959
|
+
elementY.value = elY;
|
|
1960
|
+
}
|
|
1961
|
+
},
|
|
1962
|
+
{ immediate: true }
|
|
1963
|
+
);
|
|
1964
|
+
useEventListener(
|
|
1965
|
+
document,
|
|
1966
|
+
"mouseleave",
|
|
1967
|
+
() => isOutside.value = true,
|
|
1968
|
+
{ passive: true }
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
return {
|
|
1972
|
+
x,
|
|
1973
|
+
y,
|
|
1974
|
+
sourceType,
|
|
1975
|
+
elementX,
|
|
1976
|
+
elementY,
|
|
1977
|
+
elementPositionX,
|
|
1978
|
+
elementPositionY,
|
|
1979
|
+
elementHeight,
|
|
1980
|
+
elementWidth,
|
|
1981
|
+
isOutside,
|
|
1982
|
+
stop
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
const vMouseInElement = {
|
|
1987
|
+
mounted(el, binding) {
|
|
1988
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1989
|
+
const state = reactiveOmit(reactive(useMouseInElement(el, options)), "stop");
|
|
1990
|
+
watch(state, (val) => handler(val));
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
|
|
1661
1994
|
const UseMousePressed = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
1662
1995
|
name: "UseMousePressed",
|
|
1663
1996
|
props: ["touch", "initialValue", "as"],
|
|
@@ -1729,17 +2062,17 @@ const UseOffsetPagination = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1729
2062
|
...props,
|
|
1730
2063
|
onPageChange(...args) {
|
|
1731
2064
|
var _a;
|
|
1732
|
-
(_a = props.onPageChange) == null ?
|
|
2065
|
+
(_a = props.onPageChange) == null ? undefined : _a.call(props, ...args);
|
|
1733
2066
|
emit("page-change", ...args);
|
|
1734
2067
|
},
|
|
1735
2068
|
onPageSizeChange(...args) {
|
|
1736
2069
|
var _a;
|
|
1737
|
-
(_a = props.onPageSizeChange) == null ?
|
|
2070
|
+
(_a = props.onPageSizeChange) == null ? undefined : _a.call(props, ...args);
|
|
1738
2071
|
emit("page-size-change", ...args);
|
|
1739
2072
|
},
|
|
1740
2073
|
onPageCountChange(...args) {
|
|
1741
2074
|
var _a;
|
|
1742
|
-
(_a = props.onPageCountChange) == null ?
|
|
2075
|
+
(_a = props.onPageCountChange) == null ? undefined : _a.call(props, ...args);
|
|
1743
2076
|
emit("page-count-change", ...args);
|
|
1744
2077
|
}
|
|
1745
2078
|
}));
|
|
@@ -1896,60 +2229,19 @@ const vResizeObserver = {
|
|
|
1896
2229
|
}
|
|
1897
2230
|
};
|
|
1898
2231
|
|
|
1899
|
-
function useMutationObserver(target, callback, options = {}) {
|
|
1900
|
-
const { window = defaultWindow, ...mutationOptions } = options;
|
|
1901
|
-
let observer;
|
|
1902
|
-
const isSupported = useSupported(() => window && "MutationObserver" in window);
|
|
1903
|
-
const cleanup = () => {
|
|
1904
|
-
if (observer) {
|
|
1905
|
-
observer.disconnect();
|
|
1906
|
-
observer = void 0;
|
|
1907
|
-
}
|
|
1908
|
-
};
|
|
1909
|
-
const targets = computed(() => {
|
|
1910
|
-
const value = toValue(target);
|
|
1911
|
-
const items = (Array.isArray(value) ? value : [value]).map(unrefElement).filter(notNullish);
|
|
1912
|
-
return new Set(items);
|
|
1913
|
-
});
|
|
1914
|
-
const stopWatch = watch(
|
|
1915
|
-
() => targets.value,
|
|
1916
|
-
(targets2) => {
|
|
1917
|
-
cleanup();
|
|
1918
|
-
if (isSupported.value && targets2.size) {
|
|
1919
|
-
observer = new MutationObserver(callback);
|
|
1920
|
-
targets2.forEach((el) => observer.observe(el, mutationOptions));
|
|
1921
|
-
}
|
|
1922
|
-
},
|
|
1923
|
-
{ immediate: true, flush: "post" }
|
|
1924
|
-
);
|
|
1925
|
-
const takeRecords = () => {
|
|
1926
|
-
return observer == null ? void 0 : observer.takeRecords();
|
|
1927
|
-
};
|
|
1928
|
-
const stop = () => {
|
|
1929
|
-
stopWatch();
|
|
1930
|
-
cleanup();
|
|
1931
|
-
};
|
|
1932
|
-
tryOnScopeDispose(stop);
|
|
1933
|
-
return {
|
|
1934
|
-
isSupported,
|
|
1935
|
-
stop,
|
|
1936
|
-
takeRecords
|
|
1937
|
-
};
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
2232
|
function useCssVar(prop, target, options = {}) {
|
|
1941
2233
|
const { window = defaultWindow, initialValue, observe = false } = options;
|
|
1942
2234
|
const variable = ref(initialValue);
|
|
1943
2235
|
const elRef = computed(() => {
|
|
1944
2236
|
var _a;
|
|
1945
|
-
return unrefElement(target) || ((_a = window == null ?
|
|
2237
|
+
return unrefElement(target) || ((_a = window == null ? undefined : window.document) == null ? undefined : _a.documentElement);
|
|
1946
2238
|
});
|
|
1947
2239
|
function updateCssVar() {
|
|
1948
2240
|
var _a;
|
|
1949
2241
|
const key = toValue(prop);
|
|
1950
2242
|
const el = toValue(elRef);
|
|
1951
2243
|
if (el && window && key) {
|
|
1952
|
-
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ?
|
|
2244
|
+
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? undefined : _a.trim();
|
|
1953
2245
|
variable.value = value || initialValue;
|
|
1954
2246
|
}
|
|
1955
2247
|
}
|
|
@@ -1973,7 +2265,7 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1973
2265
|
(val) => {
|
|
1974
2266
|
var _a;
|
|
1975
2267
|
const raw_prop = toValue(prop);
|
|
1976
|
-
if (((_a = elRef.value) == null ?
|
|
2268
|
+
if (((_a = elRef.value) == null ? undefined : _a.style) && raw_prop) {
|
|
1977
2269
|
if (val == null)
|
|
1978
2270
|
elRef.value.style.removeProperty(raw_prop);
|
|
1979
2271
|
else
|
|
@@ -2003,7 +2295,7 @@ function useScreenSafeArea() {
|
|
|
2003
2295
|
bottomCssVar.value = "env(safe-area-inset-bottom, 0px)";
|
|
2004
2296
|
leftCssVar.value = "env(safe-area-inset-left, 0px)";
|
|
2005
2297
|
update();
|
|
2006
|
-
useEventListener("resize", useDebounceFn(update));
|
|
2298
|
+
useEventListener("resize", useDebounceFn(update), { passive: true });
|
|
2007
2299
|
}
|
|
2008
2300
|
function update() {
|
|
2009
2301
|
top.value = getValue(topVarName);
|
|
@@ -2075,12 +2367,12 @@ const vScroll = {
|
|
|
2075
2367
|
...options,
|
|
2076
2368
|
onScroll(e) {
|
|
2077
2369
|
var _a;
|
|
2078
|
-
(_a = options.onScroll) == null ?
|
|
2370
|
+
(_a = options.onScroll) == null ? undefined : _a.call(options, e);
|
|
2079
2371
|
handler(state);
|
|
2080
2372
|
},
|
|
2081
2373
|
onStop(e) {
|
|
2082
2374
|
var _a;
|
|
2083
|
-
(_a = options.onStop) == null ?
|
|
2375
|
+
(_a = options.onStop) == null ? undefined : _a.call(options, e);
|
|
2084
2376
|
handler(state);
|
|
2085
2377
|
}
|
|
2086
2378
|
});
|
|
@@ -2153,7 +2445,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2153
2445
|
if (!el || !isLocked.value)
|
|
2154
2446
|
return;
|
|
2155
2447
|
if (isIOS)
|
|
2156
|
-
stopTouchMoveListener == null ?
|
|
2448
|
+
stopTouchMoveListener == null ? undefined : stopTouchMoveListener();
|
|
2157
2449
|
el.style.overflow = initialOverflow;
|
|
2158
2450
|
elInitialOverflow.delete(el);
|
|
2159
2451
|
isLocked.value = false;
|
|
@@ -2253,4 +2545,4 @@ const UseWindowSize = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
2253
2545
|
}
|
|
2254
2546
|
});
|
|
2255
2547
|
|
|
2256
|
-
export { OnClickOutside, OnLongPress, UseActiveElement, UseBattery, UseBrowserLocation, UseClipboard, UseColorMode, UseDark, UseDeviceMotion, UseDeviceOrientation, UseDevicePixelRatio, UseDevicesList, UseDocumentVisibility, UseDraggable, UseElementBounding, UseElementSize, UseElementVisibility, UseEyeDropper, UseFullscreen, UseGeolocation, UseIdle, UseImage, UseMouse, UseMouseInElement, UseMousePressed, UseNetwork, UseNow, UseObjectUrl, UseOffsetPagination, UseOnline, UsePageLeave, UsePointer, UsePointerLock, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePreferredReducedMotion, UsePreferredReducedTransparency, UseScreenSafeArea, UseTimeAgo, UseTimestamp, UseVirtualList, UseWindowFocus, UseWindowSize, vOnClickOutside as VOnClickOutside, vOnLongPress as VOnLongPress, vElementHover, vElementSize, vElementVisibility, vInfiniteScroll, vIntersectionObserver, vOnClickOutside, vOnKeyStroke, vOnLongPress, vResizeObserver, vScroll, vScrollLock };
|
|
2548
|
+
export { OnClickOutside, OnLongPress, UseActiveElement, UseBattery, UseBrowserLocation, UseClipboard, UseColorMode, UseDark, UseDeviceMotion, UseDeviceOrientation, UseDevicePixelRatio, UseDevicesList, UseDocumentVisibility, UseDraggable, UseElementBounding, UseElementSize, UseElementVisibility, UseEyeDropper, UseFullscreen, UseGeolocation, UseIdle, UseImage, UseMouse, UseMouseInElement, UseMousePressed, UseNetwork, UseNow, UseObjectUrl, UseOffsetPagination, UseOnline, UsePageLeave, UsePointer, UsePointerLock, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePreferredReducedMotion, UsePreferredReducedTransparency, UseScreenSafeArea, UseTimeAgo, UseTimestamp, UseVirtualList, UseWindowFocus, UseWindowSize, vOnClickOutside as VOnClickOutside, vOnLongPress as VOnLongPress, vElementBounding, vElementHover, vElementSize, vElementVisibility, vInfiniteScroll, vIntersectionObserver, vMouseInElement, vOnClickOutside, vOnKeyStroke, vOnLongPress, vResizeObserver, vScroll, vScrollLock };
|