module import { EventEmitter } from "events" ; import { Coordinates , MouseCoords , TouchCoords , WheelCoords } from "../../types" ; import Sigma from "../../sigma" ; /**
 * Captor utils functions
 * ======================
 */ param { event } e param { HTMLElement } dom return { number } export function getPosition ( e , dom ) { const bbox = dom . getBoundingClientRect ( ) ; return { x : e . clientX - bbox . left , y : e . clientY - bbox . top , } ; } param { event } e param { HTMLElement } dom return { object } export function getMouseCoords ( e , dom ) { return { ... getPosition ( e , dom ) , sigmaDefaultPrevented : false , preventSigmaDefault ( ) { this . sigmaDefaultPrevented = true ; } , original : e , } ; } param { event } e param { HTMLElement } dom return { object } export function getWheelCoords ( e , dom ) { return { ... getMouseCoords ( e , dom ) , delta : getWheelDelta ( e ) , } ; } const MAX_TOUCHES = 2 ; export function getTouchesArray ( touches ) { const arr = [ ] ; for ( let i = 0 , l = Math . min ( touches . length , MAX_TOUCHES ) ; i < l ; i ++ ) arr . push ( touches [ i ] ) ; return arr ; } param { event } e param { HTMLElement } dom return { object } export function getTouchCoords ( e , dom ) { return { touches : getTouchesArray ( e . touches ) . map ( ( touch ) => getPosition ( touch , dom ) ) , original : e , } ; } param { event } e return { number } export function getWheelDelta ( e ) { if ( typeof e . deltaY !== "undefined" ) return ( e . deltaY * - 3 ) / 360 ; if ( typeof e . detail !== "undefined" ) return e . detail / - 9 ; throw new Error ( "Captor: could not extract delta from event." ) ; } /**
 * Abstract class representing a captor like the user's mouse or touch controls.
 */ export default abstract class Captor extends EventEmitter { container : HTMLElement ; renderer : Sigma ; constructor ( container , renderer ) { super ( ) ; this . container = container ; this . renderer = renderer ; } abstract kill ( ) ; }