refactor: translate position
This commit is contained in:
parent
22870aff1b
commit
535db7cd9a
|
@ -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;
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user