@vueuse/components 12.2.0 → 12.3.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 +402 -114
- package/index.d.cts +161 -26
- package/index.d.mts +161 -26
- package/index.d.ts +161 -26
- package/index.iife.js +402 -114
- package/index.iife.min.js +1 -1
- package/index.mjs +379 -93
- 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",
|
|
@@ -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());
|
|
@@ -907,7 +905,7 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
907
905
|
props: ["box", "as"],
|
|
908
906
|
setup(props, { slots }) {
|
|
909
907
|
const target = ref();
|
|
910
|
-
const data = reactive(useElementBounding(target));
|
|
908
|
+
const data = reactive(useElementBounding$1(target));
|
|
911
909
|
return () => {
|
|
912
910
|
if (slots.default)
|
|
913
911
|
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
@@ -915,10 +913,222 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
915
913
|
}
|
|
916
914
|
});
|
|
917
915
|
|
|
916
|
+
function useMutationObserver(target, callback, options = {}) {
|
|
917
|
+
const { window = defaultWindow, ...mutationOptions } = options;
|
|
918
|
+
let observer;
|
|
919
|
+
const isSupported = useSupported(() => window && "MutationObserver" in window);
|
|
920
|
+
const cleanup = () => {
|
|
921
|
+
if (observer) {
|
|
922
|
+
observer.disconnect();
|
|
923
|
+
observer = void 0;
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
const targets = computed(() => {
|
|
927
|
+
const value = toValue(target);
|
|
928
|
+
const items = toArray(value).map(unrefElement).filter(notNullish);
|
|
929
|
+
return new Set(items);
|
|
930
|
+
});
|
|
931
|
+
const stopWatch = watch(
|
|
932
|
+
() => targets.value,
|
|
933
|
+
(targets2) => {
|
|
934
|
+
cleanup();
|
|
935
|
+
if (isSupported.value && targets2.size) {
|
|
936
|
+
observer = new MutationObserver(callback);
|
|
937
|
+
targets2.forEach((el) => observer.observe(el, mutationOptions));
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{ immediate: true, flush: "post" }
|
|
941
|
+
);
|
|
942
|
+
const takeRecords = () => {
|
|
943
|
+
return observer == null ? void 0 : observer.takeRecords();
|
|
944
|
+
};
|
|
945
|
+
const stop = () => {
|
|
946
|
+
stopWatch();
|
|
947
|
+
cleanup();
|
|
948
|
+
};
|
|
949
|
+
tryOnScopeDispose(stop);
|
|
950
|
+
return {
|
|
951
|
+
isSupported,
|
|
952
|
+
stop,
|
|
953
|
+
takeRecords
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function useResizeObserver(target, callback, options = {}) {
|
|
958
|
+
const { window = defaultWindow, ...observerOptions } = options;
|
|
959
|
+
let observer;
|
|
960
|
+
const isSupported = useSupported(() => window && "ResizeObserver" in window);
|
|
961
|
+
const cleanup = () => {
|
|
962
|
+
if (observer) {
|
|
963
|
+
observer.disconnect();
|
|
964
|
+
observer = void 0;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const targets = computed(() => {
|
|
968
|
+
const _targets = toValue(target);
|
|
969
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
970
|
+
});
|
|
971
|
+
const stopWatch = watch(
|
|
972
|
+
targets,
|
|
973
|
+
(els) => {
|
|
974
|
+
cleanup();
|
|
975
|
+
if (isSupported.value && window) {
|
|
976
|
+
observer = new ResizeObserver(callback);
|
|
977
|
+
for (const _el of els) {
|
|
978
|
+
if (_el)
|
|
979
|
+
observer.observe(_el, observerOptions);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
{ immediate: true, flush: "post" }
|
|
984
|
+
);
|
|
985
|
+
const stop = () => {
|
|
986
|
+
cleanup();
|
|
987
|
+
stopWatch();
|
|
988
|
+
};
|
|
989
|
+
tryOnScopeDispose(stop);
|
|
990
|
+
return {
|
|
991
|
+
isSupported,
|
|
992
|
+
stop
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function useElementBounding(target, options = {}) {
|
|
997
|
+
const {
|
|
998
|
+
reset = true,
|
|
999
|
+
windowResize = true,
|
|
1000
|
+
windowScroll = true,
|
|
1001
|
+
immediate = true,
|
|
1002
|
+
updateTiming = "sync"
|
|
1003
|
+
} = options;
|
|
1004
|
+
const height = ref(0);
|
|
1005
|
+
const bottom = ref(0);
|
|
1006
|
+
const left = ref(0);
|
|
1007
|
+
const right = ref(0);
|
|
1008
|
+
const top = ref(0);
|
|
1009
|
+
const width = ref(0);
|
|
1010
|
+
const x = ref(0);
|
|
1011
|
+
const y = ref(0);
|
|
1012
|
+
function recalculate() {
|
|
1013
|
+
const el = unrefElement(target);
|
|
1014
|
+
if (!el) {
|
|
1015
|
+
if (reset) {
|
|
1016
|
+
height.value = 0;
|
|
1017
|
+
bottom.value = 0;
|
|
1018
|
+
left.value = 0;
|
|
1019
|
+
right.value = 0;
|
|
1020
|
+
top.value = 0;
|
|
1021
|
+
width.value = 0;
|
|
1022
|
+
x.value = 0;
|
|
1023
|
+
y.value = 0;
|
|
1024
|
+
}
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const rect = el.getBoundingClientRect();
|
|
1028
|
+
height.value = rect.height;
|
|
1029
|
+
bottom.value = rect.bottom;
|
|
1030
|
+
left.value = rect.left;
|
|
1031
|
+
right.value = rect.right;
|
|
1032
|
+
top.value = rect.top;
|
|
1033
|
+
width.value = rect.width;
|
|
1034
|
+
x.value = rect.x;
|
|
1035
|
+
y.value = rect.y;
|
|
1036
|
+
}
|
|
1037
|
+
function update() {
|
|
1038
|
+
if (updateTiming === "sync")
|
|
1039
|
+
recalculate();
|
|
1040
|
+
else if (updateTiming === "next-frame")
|
|
1041
|
+
requestAnimationFrame(() => recalculate());
|
|
1042
|
+
}
|
|
1043
|
+
useResizeObserver(target, update);
|
|
1044
|
+
watch(() => unrefElement(target), (ele) => !ele && update());
|
|
1045
|
+
useMutationObserver(target, update, {
|
|
1046
|
+
attributeFilter: ["style", "class"]
|
|
1047
|
+
});
|
|
1048
|
+
if (windowScroll)
|
|
1049
|
+
useEventListener("scroll", update, { capture: true, passive: true });
|
|
1050
|
+
if (windowResize)
|
|
1051
|
+
useEventListener("resize", update, { passive: true });
|
|
1052
|
+
tryOnMounted(() => {
|
|
1053
|
+
if (immediate)
|
|
1054
|
+
update();
|
|
1055
|
+
});
|
|
1056
|
+
return {
|
|
1057
|
+
height,
|
|
1058
|
+
bottom,
|
|
1059
|
+
left,
|
|
1060
|
+
right,
|
|
1061
|
+
top,
|
|
1062
|
+
width,
|
|
1063
|
+
x,
|
|
1064
|
+
y,
|
|
1065
|
+
update
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
const vElementBounding = {
|
|
1070
|
+
mounted(el, binding) {
|
|
1071
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1072
|
+
const {
|
|
1073
|
+
height,
|
|
1074
|
+
bottom,
|
|
1075
|
+
left,
|
|
1076
|
+
right,
|
|
1077
|
+
top,
|
|
1078
|
+
width,
|
|
1079
|
+
x,
|
|
1080
|
+
y
|
|
1081
|
+
} = useElementBounding(el, options);
|
|
1082
|
+
watch([height, bottom, left, right, top, width, x, y], () => handler({ height, bottom, left, right, top, width, x, y }));
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
function onElementRemoval(target, callback, options = {}) {
|
|
1087
|
+
const {
|
|
1088
|
+
window = defaultWindow,
|
|
1089
|
+
document = window == null ? void 0 : window.document,
|
|
1090
|
+
flush = "sync"
|
|
1091
|
+
} = options;
|
|
1092
|
+
if (!window || !document)
|
|
1093
|
+
return noop;
|
|
1094
|
+
let stopFn;
|
|
1095
|
+
const cleanupAndUpdate = (fn) => {
|
|
1096
|
+
stopFn == null ? void 0 : stopFn();
|
|
1097
|
+
stopFn = fn;
|
|
1098
|
+
};
|
|
1099
|
+
const stopWatch = watchEffect(() => {
|
|
1100
|
+
const el = unrefElement(target);
|
|
1101
|
+
if (el) {
|
|
1102
|
+
const { stop } = useMutationObserver(
|
|
1103
|
+
document,
|
|
1104
|
+
(mutationsList) => {
|
|
1105
|
+
const targetRemoved = mutationsList.map((mutation) => [...mutation.removedNodes]).flat().some((node) => node === el || node.contains(el));
|
|
1106
|
+
if (targetRemoved) {
|
|
1107
|
+
callback(mutationsList);
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
window,
|
|
1112
|
+
childList: true,
|
|
1113
|
+
subtree: true
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
cleanupAndUpdate(stop);
|
|
1117
|
+
}
|
|
1118
|
+
}, { flush });
|
|
1119
|
+
const stopHandle = () => {
|
|
1120
|
+
stopWatch();
|
|
1121
|
+
cleanupAndUpdate();
|
|
1122
|
+
};
|
|
1123
|
+
tryOnScopeDispose(stopHandle);
|
|
1124
|
+
return stopHandle;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
918
1127
|
function useElementHover(el, options = {}) {
|
|
919
1128
|
const {
|
|
920
1129
|
delayEnter = 0,
|
|
921
1130
|
delayLeave = 0,
|
|
1131
|
+
triggerOnRemoval = false,
|
|
922
1132
|
window = defaultWindow
|
|
923
1133
|
} = options;
|
|
924
1134
|
const isHovered = ref(false);
|
|
@@ -938,6 +1148,12 @@ function useElementHover(el, options = {}) {
|
|
|
938
1148
|
return isHovered;
|
|
939
1149
|
useEventListener(el, "mouseenter", () => toggle(true), { passive: true });
|
|
940
1150
|
useEventListener(el, "mouseleave", () => toggle(false), { passive: true });
|
|
1151
|
+
if (triggerOnRemoval) {
|
|
1152
|
+
onElementRemoval(
|
|
1153
|
+
computed(() => unrefElement(el)),
|
|
1154
|
+
() => toggle(false)
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
941
1157
|
return isHovered;
|
|
942
1158
|
}
|
|
943
1159
|
|
|
@@ -968,45 +1184,6 @@ const UseElementSize = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
968
1184
|
}
|
|
969
1185
|
});
|
|
970
1186
|
|
|
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
1187
|
function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
|
|
1011
1188
|
const { window = defaultWindow, box = "content-box" } = options;
|
|
1012
1189
|
const isSVG = computed(() => {
|
|
@@ -1028,7 +1205,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1028
1205
|
}
|
|
1029
1206
|
} else {
|
|
1030
1207
|
if (boxSize) {
|
|
1031
|
-
const formatBoxSize =
|
|
1208
|
+
const formatBoxSize = toArray(boxSize);
|
|
1032
1209
|
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
1033
1210
|
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
1034
1211
|
} else {
|
|
@@ -1100,7 +1277,7 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
1100
1277
|
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
1101
1278
|
const targets = computed(() => {
|
|
1102
1279
|
const _target = toValue(target);
|
|
1103
|
-
return (
|
|
1280
|
+
return toArray(_target).map(unrefElement).filter(notNullish);
|
|
1104
1281
|
});
|
|
1105
1282
|
let cleanup = noop;
|
|
1106
1283
|
const isActive = ref(immediate);
|
|
@@ -1637,7 +1814,7 @@ const UseMouse = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1637
1814
|
name: "UseMouse",
|
|
1638
1815
|
props: ["touch", "resetOnTouchEnds", "initialValue"],
|
|
1639
1816
|
setup(props, { slots }) {
|
|
1640
|
-
const data = reactive(useMouse(props));
|
|
1817
|
+
const data = reactive(useMouse$1(props));
|
|
1641
1818
|
return () => {
|
|
1642
1819
|
if (slots.default)
|
|
1643
1820
|
return slots.default(data);
|
|
@@ -1650,7 +1827,7 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1650
1827
|
props: ["handleOutside", "as"],
|
|
1651
1828
|
setup(props, { slots }) {
|
|
1652
1829
|
const target = ref();
|
|
1653
|
-
const data = reactive(useMouseInElement(target, props));
|
|
1830
|
+
const data = reactive(useMouseInElement$1(target, props));
|
|
1654
1831
|
return () => {
|
|
1655
1832
|
if (slots.default)
|
|
1656
1833
|
return h(props.as || "div", { ref: target }, slots.default(data));
|
|
@@ -1658,6 +1835,156 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1658
1835
|
}
|
|
1659
1836
|
});
|
|
1660
1837
|
|
|
1838
|
+
const UseMouseBuiltinExtractors = {
|
|
1839
|
+
page: (event) => [event.pageX, event.pageY],
|
|
1840
|
+
client: (event) => [event.clientX, event.clientY],
|
|
1841
|
+
screen: (event) => [event.screenX, event.screenY],
|
|
1842
|
+
movement: (event) => event instanceof Touch ? null : [event.movementX, event.movementY]
|
|
1843
|
+
};
|
|
1844
|
+
function useMouse(options = {}) {
|
|
1845
|
+
const {
|
|
1846
|
+
type = "page",
|
|
1847
|
+
touch = true,
|
|
1848
|
+
resetOnTouchEnds = false,
|
|
1849
|
+
initialValue = { x: 0, y: 0 },
|
|
1850
|
+
window = defaultWindow,
|
|
1851
|
+
target = window,
|
|
1852
|
+
scroll = true,
|
|
1853
|
+
eventFilter
|
|
1854
|
+
} = options;
|
|
1855
|
+
let _prevMouseEvent = null;
|
|
1856
|
+
let _prevScrollX = 0;
|
|
1857
|
+
let _prevScrollY = 0;
|
|
1858
|
+
const x = ref(initialValue.x);
|
|
1859
|
+
const y = ref(initialValue.y);
|
|
1860
|
+
const sourceType = ref(null);
|
|
1861
|
+
const extractor = typeof type === "function" ? type : UseMouseBuiltinExtractors[type];
|
|
1862
|
+
const mouseHandler = (event) => {
|
|
1863
|
+
const result = extractor(event);
|
|
1864
|
+
_prevMouseEvent = event;
|
|
1865
|
+
if (result) {
|
|
1866
|
+
[x.value, y.value] = result;
|
|
1867
|
+
sourceType.value = "mouse";
|
|
1868
|
+
}
|
|
1869
|
+
if (window) {
|
|
1870
|
+
_prevScrollX = window.scrollX;
|
|
1871
|
+
_prevScrollY = window.scrollY;
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
const touchHandler = (event) => {
|
|
1875
|
+
if (event.touches.length > 0) {
|
|
1876
|
+
const result = extractor(event.touches[0]);
|
|
1877
|
+
if (result) {
|
|
1878
|
+
[x.value, y.value] = result;
|
|
1879
|
+
sourceType.value = "touch";
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
const scrollHandler = () => {
|
|
1884
|
+
if (!_prevMouseEvent || !window)
|
|
1885
|
+
return;
|
|
1886
|
+
const pos = extractor(_prevMouseEvent);
|
|
1887
|
+
if (_prevMouseEvent instanceof MouseEvent && pos) {
|
|
1888
|
+
x.value = pos[0] + window.scrollX - _prevScrollX;
|
|
1889
|
+
y.value = pos[1] + window.scrollY - _prevScrollY;
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
const reset = () => {
|
|
1893
|
+
x.value = initialValue.x;
|
|
1894
|
+
y.value = initialValue.y;
|
|
1895
|
+
};
|
|
1896
|
+
const mouseHandlerWrapper = eventFilter ? (event) => eventFilter(() => mouseHandler(event), {}) : (event) => mouseHandler(event);
|
|
1897
|
+
const touchHandlerWrapper = eventFilter ? (event) => eventFilter(() => touchHandler(event), {}) : (event) => touchHandler(event);
|
|
1898
|
+
const scrollHandlerWrapper = eventFilter ? () => eventFilter(() => scrollHandler(), {}) : () => scrollHandler();
|
|
1899
|
+
if (target) {
|
|
1900
|
+
const listenerOptions = { passive: true };
|
|
1901
|
+
useEventListener(target, ["mousemove", "dragover"], mouseHandlerWrapper, listenerOptions);
|
|
1902
|
+
if (touch && type !== "movement") {
|
|
1903
|
+
useEventListener(target, ["touchstart", "touchmove"], touchHandlerWrapper, listenerOptions);
|
|
1904
|
+
if (resetOnTouchEnds)
|
|
1905
|
+
useEventListener(target, "touchend", reset, listenerOptions);
|
|
1906
|
+
}
|
|
1907
|
+
if (scroll && type === "page")
|
|
1908
|
+
useEventListener(window, "scroll", scrollHandlerWrapper, { passive: true });
|
|
1909
|
+
}
|
|
1910
|
+
return {
|
|
1911
|
+
x,
|
|
1912
|
+
y,
|
|
1913
|
+
sourceType
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
function useMouseInElement(target, options = {}) {
|
|
1918
|
+
const {
|
|
1919
|
+
handleOutside = true,
|
|
1920
|
+
window = defaultWindow
|
|
1921
|
+
} = options;
|
|
1922
|
+
const type = options.type || "page";
|
|
1923
|
+
const { x, y, sourceType } = useMouse(options);
|
|
1924
|
+
const targetRef = ref(target != null ? target : window == null ? void 0 : window.document.body);
|
|
1925
|
+
const elementX = ref(0);
|
|
1926
|
+
const elementY = ref(0);
|
|
1927
|
+
const elementPositionX = ref(0);
|
|
1928
|
+
const elementPositionY = ref(0);
|
|
1929
|
+
const elementHeight = ref(0);
|
|
1930
|
+
const elementWidth = ref(0);
|
|
1931
|
+
const isOutside = ref(true);
|
|
1932
|
+
let stop = () => {
|
|
1933
|
+
};
|
|
1934
|
+
if (window) {
|
|
1935
|
+
stop = watch(
|
|
1936
|
+
[targetRef, x, y],
|
|
1937
|
+
() => {
|
|
1938
|
+
const el = unrefElement(targetRef);
|
|
1939
|
+
if (!el || !(el instanceof Element))
|
|
1940
|
+
return;
|
|
1941
|
+
const {
|
|
1942
|
+
left,
|
|
1943
|
+
top,
|
|
1944
|
+
width,
|
|
1945
|
+
height
|
|
1946
|
+
} = el.getBoundingClientRect();
|
|
1947
|
+
elementPositionX.value = left + (type === "page" ? window.pageXOffset : 0);
|
|
1948
|
+
elementPositionY.value = top + (type === "page" ? window.pageYOffset : 0);
|
|
1949
|
+
elementHeight.value = height;
|
|
1950
|
+
elementWidth.value = width;
|
|
1951
|
+
const elX = x.value - elementPositionX.value;
|
|
1952
|
+
const elY = y.value - elementPositionY.value;
|
|
1953
|
+
isOutside.value = width === 0 || height === 0 || elX < 0 || elY < 0 || elX > width || elY > height;
|
|
1954
|
+
if (handleOutside || !isOutside.value) {
|
|
1955
|
+
elementX.value = elX;
|
|
1956
|
+
elementY.value = elY;
|
|
1957
|
+
}
|
|
1958
|
+
},
|
|
1959
|
+
{ immediate: true }
|
|
1960
|
+
);
|
|
1961
|
+
useEventListener(document, "mouseleave", () => {
|
|
1962
|
+
isOutside.value = true;
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
return {
|
|
1966
|
+
x,
|
|
1967
|
+
y,
|
|
1968
|
+
sourceType,
|
|
1969
|
+
elementX,
|
|
1970
|
+
elementY,
|
|
1971
|
+
elementPositionX,
|
|
1972
|
+
elementPositionY,
|
|
1973
|
+
elementHeight,
|
|
1974
|
+
elementWidth,
|
|
1975
|
+
isOutside,
|
|
1976
|
+
stop
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
const vMouseInElement = {
|
|
1981
|
+
mounted(el, binding) {
|
|
1982
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1983
|
+
const state = reactiveOmit(reactive(useMouseInElement(el, options)), "stop");
|
|
1984
|
+
watch(state, (val) => handler(val));
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
|
|
1661
1988
|
const UseMousePressed = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
1662
1989
|
name: "UseMousePressed",
|
|
1663
1990
|
props: ["touch", "initialValue", "as"],
|
|
@@ -1896,47 +2223,6 @@ const vResizeObserver = {
|
|
|
1896
2223
|
}
|
|
1897
2224
|
};
|
|
1898
2225
|
|
|
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
2226
|
function useCssVar(prop, target, options = {}) {
|
|
1941
2227
|
const { window = defaultWindow, initialValue, observe = false } = options;
|
|
1942
2228
|
const variable = ref(initialValue);
|
|
@@ -2253,4 +2539,4 @@ const UseWindowSize = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
2253
2539
|
}
|
|
2254
2540
|
});
|
|
2255
2541
|
|
|
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 };
|
|
2542
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/components",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.3.0",
|
|
5
5
|
"description": "Renderless components for VueUse",
|
|
6
6
|
"author": "Jacob Clevenger<https://github.com/wheatjs>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"vue": "^3.5.13",
|
|
45
|
-
"@vueuse/core": "12.
|
|
46
|
-
"@vueuse/shared": "12.
|
|
45
|
+
"@vueuse/core": "12.3.0",
|
|
46
|
+
"@vueuse/shared": "12.3.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "rollup --config=rollup.config.ts --configPlugin=rollup-plugin-esbuild"
|