@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.cjs
CHANGED
|
@@ -24,7 +24,7 @@ const defaultWindow = shared.isClient ? window : void 0;
|
|
|
24
24
|
|
|
25
25
|
function unrefElement(elRef) {
|
|
26
26
|
var _a;
|
|
27
|
-
const plain =
|
|
27
|
+
const plain = vue.toValue(elRef);
|
|
28
28
|
return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -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;
|
|
@@ -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);
|
|
@@ -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
|
|
@@ -564,7 +562,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
564
562
|
}
|
|
565
563
|
if (!storage)
|
|
566
564
|
return data;
|
|
567
|
-
const rawInit =
|
|
565
|
+
const rawInit = vue.toValue(defaults);
|
|
568
566
|
const type = guessSerializerType(rawInit);
|
|
569
567
|
const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
570
568
|
const { pause: pauseWatch, resume: resumeWatch } = shared.pausableWatch(
|
|
@@ -877,7 +875,7 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
877
875
|
const disabled = vue.computed(() => !!props.disabled);
|
|
878
876
|
const storageValue = props.storageKey && core.useStorage(
|
|
879
877
|
props.storageKey,
|
|
880
|
-
|
|
878
|
+
vue.toValue(props.initialValue) || { x: 0, y: 0 },
|
|
881
879
|
core.isClient ? props.storageType === "session" ? sessionStorage : localStorage : void 0
|
|
882
880
|
);
|
|
883
881
|
const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
|
|
@@ -917,10 +915,222 @@ const UseElementBounding = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
917
915
|
}
|
|
918
916
|
});
|
|
919
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 = void 0;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
const targets = vue.computed(() => {
|
|
929
|
+
const value = vue.toValue(target);
|
|
930
|
+
const items = shared.toArray(value).map(unrefElement).filter(shared.notNullish);
|
|
931
|
+
return new Set(items);
|
|
932
|
+
});
|
|
933
|
+
const stopWatch = vue.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 ? void 0 : observer.takeRecords();
|
|
946
|
+
};
|
|
947
|
+
const stop = () => {
|
|
948
|
+
stopWatch();
|
|
949
|
+
cleanup();
|
|
950
|
+
};
|
|
951
|
+
shared.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 = void 0;
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
const targets = vue.computed(() => {
|
|
970
|
+
const _targets = vue.toValue(target);
|
|
971
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
972
|
+
});
|
|
973
|
+
const stopWatch = vue.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
|
+
shared.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 = vue.ref(0);
|
|
1007
|
+
const bottom = vue.ref(0);
|
|
1008
|
+
const left = vue.ref(0);
|
|
1009
|
+
const right = vue.ref(0);
|
|
1010
|
+
const top = vue.ref(0);
|
|
1011
|
+
const width = vue.ref(0);
|
|
1012
|
+
const x = vue.ref(0);
|
|
1013
|
+
const y = vue.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
|
+
vue.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
|
+
shared.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
|
+
vue.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 ? void 0 : window.document,
|
|
1092
|
+
flush = "sync"
|
|
1093
|
+
} = options;
|
|
1094
|
+
if (!window || !document)
|
|
1095
|
+
return shared.noop;
|
|
1096
|
+
let stopFn;
|
|
1097
|
+
const cleanupAndUpdate = (fn) => {
|
|
1098
|
+
stopFn == null ? void 0 : stopFn();
|
|
1099
|
+
stopFn = fn;
|
|
1100
|
+
};
|
|
1101
|
+
const stopWatch = vue.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
|
+
shared.tryOnScopeDispose(stopHandle);
|
|
1126
|
+
return stopHandle;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
920
1129
|
function useElementHover(el, options = {}) {
|
|
921
1130
|
const {
|
|
922
1131
|
delayEnter = 0,
|
|
923
1132
|
delayLeave = 0,
|
|
1133
|
+
triggerOnRemoval = false,
|
|
924
1134
|
window = defaultWindow
|
|
925
1135
|
} = options;
|
|
926
1136
|
const isHovered = vue.ref(false);
|
|
@@ -940,6 +1150,12 @@ function useElementHover(el, options = {}) {
|
|
|
940
1150
|
return isHovered;
|
|
941
1151
|
useEventListener(el, "mouseenter", () => toggle(true), { passive: true });
|
|
942
1152
|
useEventListener(el, "mouseleave", () => toggle(false), { passive: true });
|
|
1153
|
+
if (triggerOnRemoval) {
|
|
1154
|
+
onElementRemoval(
|
|
1155
|
+
vue.computed(() => unrefElement(el)),
|
|
1156
|
+
() => toggle(false)
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
943
1159
|
return isHovered;
|
|
944
1160
|
}
|
|
945
1161
|
|
|
@@ -970,45 +1186,6 @@ const UseElementSize = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
970
1186
|
}
|
|
971
1187
|
});
|
|
972
1188
|
|
|
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
1189
|
function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
|
|
1013
1190
|
const { window = defaultWindow, box = "content-box" } = options;
|
|
1014
1191
|
const isSVG = vue.computed(() => {
|
|
@@ -1030,7 +1207,7 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
1030
1207
|
}
|
|
1031
1208
|
} else {
|
|
1032
1209
|
if (boxSize) {
|
|
1033
|
-
const formatBoxSize =
|
|
1210
|
+
const formatBoxSize = shared.toArray(boxSize);
|
|
1034
1211
|
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
1035
1212
|
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
1036
1213
|
} else {
|
|
@@ -1101,8 +1278,8 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
1101
1278
|
} = options;
|
|
1102
1279
|
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
1103
1280
|
const targets = vue.computed(() => {
|
|
1104
|
-
const _target =
|
|
1105
|
-
return
|
|
1281
|
+
const _target = vue.toValue(target);
|
|
1282
|
+
return shared.toArray(_target).map(unrefElement).filter(shared.notNullish);
|
|
1106
1283
|
});
|
|
1107
1284
|
let cleanup = shared.noop;
|
|
1108
1285
|
const isActive = vue.ref(immediate);
|
|
@@ -1175,7 +1352,7 @@ function useElementVisibility(element, options = {}) {
|
|
|
1175
1352
|
root: scrollTarget,
|
|
1176
1353
|
window,
|
|
1177
1354
|
threshold,
|
|
1178
|
-
rootMargin:
|
|
1355
|
+
rootMargin: vue.toValue(rootMargin)
|
|
1179
1356
|
}
|
|
1180
1357
|
);
|
|
1181
1358
|
return elementIsVisible;
|
|
@@ -1341,7 +1518,7 @@ async function loadImage(options) {
|
|
|
1341
1518
|
}
|
|
1342
1519
|
function useImage(options, asyncStateOptions = {}) {
|
|
1343
1520
|
const state = useAsyncState(
|
|
1344
|
-
() => loadImage(
|
|
1521
|
+
() => loadImage(vue.toValue(options)),
|
|
1345
1522
|
void 0,
|
|
1346
1523
|
{
|
|
1347
1524
|
resetOnExecute: true,
|
|
@@ -1349,7 +1526,7 @@ function useImage(options, asyncStateOptions = {}) {
|
|
|
1349
1526
|
}
|
|
1350
1527
|
);
|
|
1351
1528
|
vue.watch(
|
|
1352
|
-
() =>
|
|
1529
|
+
() => vue.toValue(options),
|
|
1353
1530
|
() => state.execute(asyncStateOptions.delay),
|
|
1354
1531
|
{ deep: true }
|
|
1355
1532
|
);
|
|
@@ -1442,13 +1619,13 @@ function useScroll(element, options = {}) {
|
|
|
1442
1619
|
var _a, _b, _c, _d;
|
|
1443
1620
|
if (!window)
|
|
1444
1621
|
return;
|
|
1445
|
-
const _element =
|
|
1622
|
+
const _element = vue.toValue(element);
|
|
1446
1623
|
if (!_element)
|
|
1447
1624
|
return;
|
|
1448
1625
|
(_c = _element instanceof Document ? window.document.body : _element) == null ? void 0 : _c.scrollTo({
|
|
1449
|
-
top: (_a =
|
|
1450
|
-
left: (_b =
|
|
1451
|
-
behavior:
|
|
1626
|
+
top: (_a = vue.toValue(_y)) != null ? _a : y.value,
|
|
1627
|
+
left: (_b = vue.toValue(_x)) != null ? _b : x.value,
|
|
1628
|
+
behavior: vue.toValue(behavior)
|
|
1452
1629
|
});
|
|
1453
1630
|
const scrollContainer = ((_d = _element == null ? void 0 : _element.document) == null ? void 0 : _d.documentElement) || (_element == null ? void 0 : _element.documentElement) || _element;
|
|
1454
1631
|
if (x != null)
|
|
@@ -1534,7 +1711,7 @@ function useScroll(element, options = {}) {
|
|
|
1534
1711
|
);
|
|
1535
1712
|
shared.tryOnMounted(() => {
|
|
1536
1713
|
try {
|
|
1537
|
-
const _element =
|
|
1714
|
+
const _element = vue.toValue(element);
|
|
1538
1715
|
if (!_element)
|
|
1539
1716
|
return;
|
|
1540
1717
|
setArrivedState(_element);
|
|
@@ -1555,7 +1732,7 @@ function useScroll(element, options = {}) {
|
|
|
1555
1732
|
arrivedState,
|
|
1556
1733
|
directions,
|
|
1557
1734
|
measure() {
|
|
1558
|
-
const _element =
|
|
1735
|
+
const _element = vue.toValue(element);
|
|
1559
1736
|
if (window && _element)
|
|
1560
1737
|
setArrivedState(_element);
|
|
1561
1738
|
}
|
|
@@ -1582,7 +1759,7 @@ function useInfiniteScroll(element, onLoadMore, options = {}) {
|
|
|
1582
1759
|
const promise = vue.ref();
|
|
1583
1760
|
const isLoading = vue.computed(() => !!promise.value);
|
|
1584
1761
|
const observedElement = vue.computed(() => {
|
|
1585
|
-
return resolveElement(
|
|
1762
|
+
return resolveElement(vue.toValue(element));
|
|
1586
1763
|
});
|
|
1587
1764
|
const isElementVisible = useElementVisibility(observedElement);
|
|
1588
1765
|
function checkAndLoad() {
|
|
@@ -1660,6 +1837,156 @@ const UseMouseInElement = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
|
1660
1837
|
}
|
|
1661
1838
|
});
|
|
1662
1839
|
|
|
1840
|
+
const UseMouseBuiltinExtractors = {
|
|
1841
|
+
page: (event) => [event.pageX, event.pageY],
|
|
1842
|
+
client: (event) => [event.clientX, event.clientY],
|
|
1843
|
+
screen: (event) => [event.screenX, event.screenY],
|
|
1844
|
+
movement: (event) => event instanceof Touch ? null : [event.movementX, event.movementY]
|
|
1845
|
+
};
|
|
1846
|
+
function useMouse(options = {}) {
|
|
1847
|
+
const {
|
|
1848
|
+
type = "page",
|
|
1849
|
+
touch = true,
|
|
1850
|
+
resetOnTouchEnds = false,
|
|
1851
|
+
initialValue = { x: 0, y: 0 },
|
|
1852
|
+
window = defaultWindow,
|
|
1853
|
+
target = window,
|
|
1854
|
+
scroll = true,
|
|
1855
|
+
eventFilter
|
|
1856
|
+
} = options;
|
|
1857
|
+
let _prevMouseEvent = null;
|
|
1858
|
+
let _prevScrollX = 0;
|
|
1859
|
+
let _prevScrollY = 0;
|
|
1860
|
+
const x = vue.ref(initialValue.x);
|
|
1861
|
+
const y = vue.ref(initialValue.y);
|
|
1862
|
+
const sourceType = vue.ref(null);
|
|
1863
|
+
const extractor = typeof type === "function" ? type : UseMouseBuiltinExtractors[type];
|
|
1864
|
+
const mouseHandler = (event) => {
|
|
1865
|
+
const result = extractor(event);
|
|
1866
|
+
_prevMouseEvent = event;
|
|
1867
|
+
if (result) {
|
|
1868
|
+
[x.value, y.value] = result;
|
|
1869
|
+
sourceType.value = "mouse";
|
|
1870
|
+
}
|
|
1871
|
+
if (window) {
|
|
1872
|
+
_prevScrollX = window.scrollX;
|
|
1873
|
+
_prevScrollY = window.scrollY;
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
const touchHandler = (event) => {
|
|
1877
|
+
if (event.touches.length > 0) {
|
|
1878
|
+
const result = extractor(event.touches[0]);
|
|
1879
|
+
if (result) {
|
|
1880
|
+
[x.value, y.value] = result;
|
|
1881
|
+
sourceType.value = "touch";
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
const scrollHandler = () => {
|
|
1886
|
+
if (!_prevMouseEvent || !window)
|
|
1887
|
+
return;
|
|
1888
|
+
const pos = extractor(_prevMouseEvent);
|
|
1889
|
+
if (_prevMouseEvent instanceof MouseEvent && pos) {
|
|
1890
|
+
x.value = pos[0] + window.scrollX - _prevScrollX;
|
|
1891
|
+
y.value = pos[1] + window.scrollY - _prevScrollY;
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
const reset = () => {
|
|
1895
|
+
x.value = initialValue.x;
|
|
1896
|
+
y.value = initialValue.y;
|
|
1897
|
+
};
|
|
1898
|
+
const mouseHandlerWrapper = eventFilter ? (event) => eventFilter(() => mouseHandler(event), {}) : (event) => mouseHandler(event);
|
|
1899
|
+
const touchHandlerWrapper = eventFilter ? (event) => eventFilter(() => touchHandler(event), {}) : (event) => touchHandler(event);
|
|
1900
|
+
const scrollHandlerWrapper = eventFilter ? () => eventFilter(() => scrollHandler(), {}) : () => scrollHandler();
|
|
1901
|
+
if (target) {
|
|
1902
|
+
const listenerOptions = { passive: true };
|
|
1903
|
+
useEventListener(target, ["mousemove", "dragover"], mouseHandlerWrapper, listenerOptions);
|
|
1904
|
+
if (touch && type !== "movement") {
|
|
1905
|
+
useEventListener(target, ["touchstart", "touchmove"], touchHandlerWrapper, listenerOptions);
|
|
1906
|
+
if (resetOnTouchEnds)
|
|
1907
|
+
useEventListener(target, "touchend", reset, listenerOptions);
|
|
1908
|
+
}
|
|
1909
|
+
if (scroll && type === "page")
|
|
1910
|
+
useEventListener(window, "scroll", scrollHandlerWrapper, { passive: true });
|
|
1911
|
+
}
|
|
1912
|
+
return {
|
|
1913
|
+
x,
|
|
1914
|
+
y,
|
|
1915
|
+
sourceType
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
function useMouseInElement(target, options = {}) {
|
|
1920
|
+
const {
|
|
1921
|
+
handleOutside = true,
|
|
1922
|
+
window = defaultWindow
|
|
1923
|
+
} = options;
|
|
1924
|
+
const type = options.type || "page";
|
|
1925
|
+
const { x, y, sourceType } = useMouse(options);
|
|
1926
|
+
const targetRef = vue.ref(target != null ? target : window == null ? void 0 : window.document.body);
|
|
1927
|
+
const elementX = vue.ref(0);
|
|
1928
|
+
const elementY = vue.ref(0);
|
|
1929
|
+
const elementPositionX = vue.ref(0);
|
|
1930
|
+
const elementPositionY = vue.ref(0);
|
|
1931
|
+
const elementHeight = vue.ref(0);
|
|
1932
|
+
const elementWidth = vue.ref(0);
|
|
1933
|
+
const isOutside = vue.ref(true);
|
|
1934
|
+
let stop = () => {
|
|
1935
|
+
};
|
|
1936
|
+
if (window) {
|
|
1937
|
+
stop = vue.watch(
|
|
1938
|
+
[targetRef, x, y],
|
|
1939
|
+
() => {
|
|
1940
|
+
const el = unrefElement(targetRef);
|
|
1941
|
+
if (!el || !(el instanceof Element))
|
|
1942
|
+
return;
|
|
1943
|
+
const {
|
|
1944
|
+
left,
|
|
1945
|
+
top,
|
|
1946
|
+
width,
|
|
1947
|
+
height
|
|
1948
|
+
} = el.getBoundingClientRect();
|
|
1949
|
+
elementPositionX.value = left + (type === "page" ? window.pageXOffset : 0);
|
|
1950
|
+
elementPositionY.value = top + (type === "page" ? window.pageYOffset : 0);
|
|
1951
|
+
elementHeight.value = height;
|
|
1952
|
+
elementWidth.value = width;
|
|
1953
|
+
const elX = x.value - elementPositionX.value;
|
|
1954
|
+
const elY = y.value - elementPositionY.value;
|
|
1955
|
+
isOutside.value = width === 0 || height === 0 || elX < 0 || elY < 0 || elX > width || elY > height;
|
|
1956
|
+
if (handleOutside || !isOutside.value) {
|
|
1957
|
+
elementX.value = elX;
|
|
1958
|
+
elementY.value = elY;
|
|
1959
|
+
}
|
|
1960
|
+
},
|
|
1961
|
+
{ immediate: true }
|
|
1962
|
+
);
|
|
1963
|
+
useEventListener(document, "mouseleave", () => {
|
|
1964
|
+
isOutside.value = true;
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
return {
|
|
1968
|
+
x,
|
|
1969
|
+
y,
|
|
1970
|
+
sourceType,
|
|
1971
|
+
elementX,
|
|
1972
|
+
elementY,
|
|
1973
|
+
elementPositionX,
|
|
1974
|
+
elementPositionY,
|
|
1975
|
+
elementHeight,
|
|
1976
|
+
elementWidth,
|
|
1977
|
+
isOutside,
|
|
1978
|
+
stop
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
const vMouseInElement = {
|
|
1983
|
+
mounted(el, binding) {
|
|
1984
|
+
const [handler, options] = typeof binding.value === "function" ? [binding.value, {}] : binding.value;
|
|
1985
|
+
const state = shared.reactiveOmit(vue.reactive(useMouseInElement(el, options)), "stop");
|
|
1986
|
+
vue.watch(state, (val) => handler(val));
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
|
|
1663
1990
|
const UseMousePressed = /* @__PURE__ */ /* #__PURE__ */ vue.defineComponent({
|
|
1664
1991
|
name: "UseMousePressed",
|
|
1665
1992
|
props: ["touch", "initialValue", "as"],
|
|
@@ -1898,47 +2225,6 @@ const vResizeObserver = {
|
|
|
1898
2225
|
}
|
|
1899
2226
|
};
|
|
1900
2227
|
|
|
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
2228
|
function useCssVar(prop, target, options = {}) {
|
|
1943
2229
|
const { window = defaultWindow, initialValue, observe = false } = options;
|
|
1944
2230
|
const variable = vue.ref(initialValue);
|
|
@@ -1948,8 +2234,8 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1948
2234
|
});
|
|
1949
2235
|
function updateCssVar() {
|
|
1950
2236
|
var _a;
|
|
1951
|
-
const key =
|
|
1952
|
-
const el =
|
|
2237
|
+
const key = vue.toValue(prop);
|
|
2238
|
+
const el = vue.toValue(elRef);
|
|
1953
2239
|
if (el && window && key) {
|
|
1954
2240
|
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
|
|
1955
2241
|
variable.value = value || initialValue;
|
|
@@ -1962,7 +2248,7 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1962
2248
|
});
|
|
1963
2249
|
}
|
|
1964
2250
|
vue.watch(
|
|
1965
|
-
[elRef, () =>
|
|
2251
|
+
[elRef, () => vue.toValue(prop)],
|
|
1966
2252
|
(_, old) => {
|
|
1967
2253
|
if (old[0] && old[1])
|
|
1968
2254
|
old[0].style.removeProperty(old[1]);
|
|
@@ -1974,7 +2260,7 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1974
2260
|
variable,
|
|
1975
2261
|
(val) => {
|
|
1976
2262
|
var _a;
|
|
1977
|
-
const raw_prop =
|
|
2263
|
+
const raw_prop = vue.toValue(prop);
|
|
1978
2264
|
if (((_a = elRef.value) == null ? void 0 : _a.style) && raw_prop) {
|
|
1979
2265
|
if (val == null)
|
|
1980
2266
|
elRef.value.style.removeProperty(raw_prop);
|
|
@@ -2118,7 +2404,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2118
2404
|
let stopTouchMoveListener = null;
|
|
2119
2405
|
let initialOverflow = "";
|
|
2120
2406
|
vue.watch(shared.toRef(element), (el) => {
|
|
2121
|
-
const target = resolveElement(
|
|
2407
|
+
const target = resolveElement(vue.toValue(el));
|
|
2122
2408
|
if (target) {
|
|
2123
2409
|
const ele = target;
|
|
2124
2410
|
if (!elInitialOverflow.get(ele))
|
|
@@ -2134,7 +2420,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2134
2420
|
immediate: true
|
|
2135
2421
|
});
|
|
2136
2422
|
const lock = () => {
|
|
2137
|
-
const el = resolveElement(
|
|
2423
|
+
const el = resolveElement(vue.toValue(element));
|
|
2138
2424
|
if (!el || isLocked.value)
|
|
2139
2425
|
return;
|
|
2140
2426
|
if (shared.isIOS) {
|
|
@@ -2151,7 +2437,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
2151
2437
|
isLocked.value = true;
|
|
2152
2438
|
};
|
|
2153
2439
|
const unlock = () => {
|
|
2154
|
-
const el = resolveElement(
|
|
2440
|
+
const el = resolveElement(vue.toValue(element));
|
|
2155
2441
|
if (!el || !isLocked.value)
|
|
2156
2442
|
return;
|
|
2157
2443
|
if (shared.isIOS)
|
|
@@ -2302,11 +2588,13 @@ exports.UseWindowFocus = UseWindowFocus;
|
|
|
2302
2588
|
exports.UseWindowSize = UseWindowSize;
|
|
2303
2589
|
exports.VOnClickOutside = vOnClickOutside;
|
|
2304
2590
|
exports.VOnLongPress = vOnLongPress;
|
|
2591
|
+
exports.vElementBounding = vElementBounding;
|
|
2305
2592
|
exports.vElementHover = vElementHover;
|
|
2306
2593
|
exports.vElementSize = vElementSize;
|
|
2307
2594
|
exports.vElementVisibility = vElementVisibility;
|
|
2308
2595
|
exports.vInfiniteScroll = vInfiniteScroll;
|
|
2309
2596
|
exports.vIntersectionObserver = vIntersectionObserver;
|
|
2597
|
+
exports.vMouseInElement = vMouseInElement;
|
|
2310
2598
|
exports.vOnClickOutside = vOnClickOutside;
|
|
2311
2599
|
exports.vOnKeyStroke = vOnKeyStroke;
|
|
2312
2600
|
exports.vOnLongPress = vOnLongPress;
|