feat: useMouseWheel -> useScreenMouseWheel

This commit is contained in:
2025-11-21 21:01:46 +01:00
parent 17eeb4cb13
commit 43cf159915
4 changed files with 36 additions and 16 deletions

View File

@@ -1,15 +0,0 @@
export type MouseWheelCallback = (deltaY: number, deltaX: number) => void;
export const useMouseWheel = (callback: MouseWheelCallback) => {
const handleWheel = (event: WheelEvent) => {
callback(event.deltaY, event.deltaX);
};
onMounted(() => {
window.addEventListener("wheel", handleWheel, { passive: true });
});
onUnmounted(() => {
window.removeEventListener("wheel", handleWheel);
});
};

View File

@@ -0,0 +1,18 @@
export type ScreenMouseWheelCallback = (deltaY: number, deltaX: number) => void;
export const useScreenMouseWheel = (callback: ScreenMouseWheelCallback) => {
const registerScreenMouseWheelCallback = inject<
(callback: ScreenMouseWheelCallback) => () => void
>("registerScreenMouseWheelCallback");
onMounted(() => {
if (!registerScreenMouseWheelCallback) {
throw new Error(
"Missing registerScreenMouseWheelCallback - useScreenMouseWheel must be used within a Screen component",
);
}
const unregister = registerScreenMouseWheelCallback(callback);
onUnmounted(unregister);
});
};