/**
  This file provides high level mechanisms for mouse event listeners
  as well as abstracting away browser differences.
**/ import { PointerLock } from './PointerLock' ; let downListeners = [ [ ] , [ ] , [ ] ] ; let upListeners = [ [ ] , [ ] , [ ] ] ; let intervalIds = [ ] ; let downListener = function ( e ) { if ( ! PointerLock . pointerLockElement ( ) ) { return ; } downListeners [ e . which - 1 ] . forEach ( function ( element ) { if ( element . interval !== undefined ) { let intervalID = setInterval ( element . callback , element . interval ) ; intervalIds [ element . id ] = intervalID ; } element . callback ( ) ; } ) ; } ; let upListener = function ( e ) { if ( ! PointerLock . pointerLockElement ( ) ) { return ; } upListeners [ e . which - 1 ] . forEach ( function ( element ) { if ( intervalIds [ element . id ] !== 'undefined' ) { clearInterval ( intervalIds [ element . id ] ) ; delete intervalIds [ element . id ] ; } element . callback ( ) ; } ) ; } ; document . addEventListener ( 'mousedown' , downListener , false ) ; document . addEventListener ( 'mouseup' , upListener , false ) ; let stringToWhich = { left : 0 , middle : 1 , right : 2 } ; let id = 0 ; export const Mouse = { on : ( which , down , up , cont ? ) => { downListeners [ stringToWhich [ which ] ] . push ( { callback : down , interval : cont , id : id } ) ; upListeners [ stringToWhich [ which ] ] . push ( { callback : up , id : id } ) ; ++ id ; } } ;