2021-04-22 14:56:12 +02:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-04-22 14:56:12 +02:00
|
|
|
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-04-22 14:56:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Different browsers use different deltaModes. This causes different behaviour.
|
|
|
|
|
* To avoid that we use this function to convert any event to pixels.
|
|
|
|
|
* @param {WheelEvent} event to normalize
|
|
|
|
|
* @returns {WheelEvent} normalized event event
|
|
|
|
|
*/
|
2023-02-13 17:01:43 +00:00
|
|
|
export function normalizeWheelEvent({ deltaMode, deltaX, deltaY, deltaZ, ...event }: WheelEvent): WheelEvent {
|
2021-04-22 14:56:12 +02:00
|
|
|
const LINE_HEIGHT = 18;
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
if (deltaMode === 1) {
|
2021-04-22 14:56:12 +02:00
|
|
|
// Units are lines
|
2023-02-13 17:01:43 +00:00
|
|
|
deltaX *= LINE_HEIGHT;
|
|
|
|
|
deltaY *= LINE_HEIGHT;
|
|
|
|
|
deltaZ *= LINE_HEIGHT;
|
2021-04-22 14:56:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new WheelEvent("syntheticWheel", {
|
|
|
|
|
deltaMode: 0,
|
2023-02-13 17:01:43 +00:00
|
|
|
deltaY,
|
|
|
|
|
deltaX,
|
|
|
|
|
deltaZ,
|
2021-04-22 14:56:12 +02:00
|
|
|
...event,
|
|
|
|
|
});
|
|
|
|
|
}
|