@@ -36,37 +36,19 @@ export interface Interaction {
36
36
y : number ;
37
37
}
38
38
39
- // // Returns a relative position of the pointer inside the node's bounding box
40
- // export const getRelativePosition = (node: HTMLDivElement, event: MouseEvent | TouchEvent): Interaction => {
41
- // const rect = node.getBoundingClientRect();
42
-
43
- // // Get user's pointer position from `touches` array if it's a `TouchEvent`
44
- // const pointer = isTouch(event) ? event.touches[0] : (event as MouseEvent);
45
-
46
- // return {
47
- // left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
48
- // top: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height),
49
- // width: rect.width,
50
- // height: rect.height,
51
- // x: pointer.pageX - (rect.left + window.pageXOffset),
52
- // y: pointer.pageY - (rect.top + window.pageYOffset),
53
- // };
54
- // };
55
-
56
39
// Returns a relative position of the pointer inside the node's bounding box
57
40
export const getRelativePosition = ( node : HTMLDivElement , event : MouseEvent | TouchEvent ) : Interaction => {
58
41
const rect = node . getBoundingClientRect ( ) ;
59
- const pointer = isTouch ( event ) ? event . touches [ 0 ] : ( event as MouseEvent ) ;
60
42
61
- const x = clamp ( pointer . pageX - ( rect . left + window . pageXOffset ) , 0 , rect . width ) ;
62
- const y = clamp ( pointer . pageY - ( rect . top + window . pageYOffset ) , 0 , rect . height ) ;
43
+ // Get user's pointer position from `touches` array if it's a `TouchEvent`
44
+ const pointer = isTouch ( event ) ? event . touches [ 0 ] : ( event as MouseEvent ) ;
63
45
64
46
return {
65
- left : x / rect . width ,
66
- top : y / rect . height ,
47
+ left : clamp ( ( pointer . pageX - ( rect . left + window . pageXOffset ) ) / rect . width ) ,
48
+ top : clamp ( ( pointer . pageY - ( rect . top + window . pageYOffset ) ) / rect . height ) ,
67
49
width : rect . width ,
68
50
height : rect . height ,
69
- x,
70
- y,
51
+ x : pointer . pageX - ( rect . left + window . pageXOffset ) ,
52
+ y : pointer . pageY - ( rect . top + window . pageYOffset ) ,
71
53
} ;
72
54
} ;
0 commit comments