export function registerMouseEvent ( move , up ? ) { let isDone = false ; let moveEvent ; let movementSum = { x : 0.0 , y : 0.0 } ; const update = ( ) : void => { if ( isDone ) { return ; } requestAnimationFrame ( update ) ; if ( moveEvent ) { move ( moveEvent , movementSum ) ; moveEvent = undefined ; movementSum = { x : 0.0 , y : 0.0 } ; } } ; update ( ) ; const movet = ( event ) : void => { moveEvent = event ; movementSum . x += event . movementX ; movementSum . y += event . movementY ; } ; const upt = ( event ) : void => { if ( ! isDone ) { up && up ( event ) ; isDone = true ; } window . removeEventListener ( 'mousemove' , movet ) ; window . removeEventListener ( 'mouseup' , upt ) ; window . removeEventListener ( 'mousedown' , upt ) ; } ; window . addEventListener ( 'mousemove' , movet ) ; window . addEventListener ( 'mouseup' , upt ) ; setTimeout ( ( ) => window . addEventListener ( 'mousedown' , upt ) ) ; }