refactor: translate position

This commit is contained in:
cha0s 2022-04-05 07:22:34 -05:00
parent 22870aff1b
commit 535db7cd9a

View File

@ -40,14 +40,31 @@ const Stage = forwardRef(({
event, event,
// Normalize touch events. // Normalize touch events.
(event) => { (event) => {
let {
clientX,
clientY,
deltaX,
deltaY,
} = event;
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
if (-1 !== ['touchstart', 'touchmove'].indexOf(event.type)) { if (-1 !== ['touchstart', 'touchmove'].indexOf(event.type)) {
event.clientX = event.touches[0].clientX; clientX = event.touches[0].clientX;
event.deltaX = event.touches[0].deltaX; deltaX = event.touches[0].deltaX;
event.clientY = event.touches[0].clientY; clientY = event.touches[0].clientY;
event.deltaY = event.touches[0].deltaY; deltaY = event.touches[0].deltaY;
} }
/* eslint-enable no-param-reassign */ /* eslint-enable no-param-reassign */
const {left, top} = event.target.getBoundingClientRect();
Object.defineProperty(
event,
'delta',
{get: () => [deltaX, deltaY]},
);
Object.defineProperty(
event,
'position',
{get: () => [(clientX - left) / scale, (clientY - top) / scale]},
);
return event; return event;
}, },
) )