import { assert } from './auxiliaries' ; /**
 * Utility class providing simplified access to the clients pointer lock API.
 */ export class PointerLock { /**
     * Cached exit call of the clients specific pointer lock API.
     */ protected static _exit : ( ) => void ; /**
     * Cached request call of the clients specific pointer API.
     */ protected static _request : ( element : HTMLElement ) => void ; /**
     * Cached element call returning the fullscreen element specific to the clients fullscreen API.
     */ protected static _element : ( ) => HTMLElement ; /**
     * Query and cache the client specific pointer lock API.
     */ protected static queryAndCacheAPI ( ) { if ( PointerLock . _exit !== undefined ) { return ; } /**
         * Shadow global document declaration with an untyped one. This is done in order to use vendor specific
         * properties without a compile error.
         */ const document = window . document as any ; const exits = [ document . exitPointerLock , document . mozExitPointerLock , document . webkitExitPointerLock , undefined ] ; let api = 0 ; for ( ; api < exits . length ; ++ api ) { if ( exits [ api ] === undefined ) { continue ; } break ; } switch ( api ) { case 0 : PointerLock . _exit = ( ) => document . exitPointerLock ( ) ; PointerLock . _request = ( element ) => ( element as any ) . requestPointerLock ( ) ; PointerLock . _element = ( ) => document . pointerLockElement ; break ; case 1 : PointerLock . _exit = ( ) => document . mozCancelPointerLock ( ) ; PointerLock . _request = ( element ) => ( element as any ) . mozRequestPointerLock ( ) ; PointerLock . _element = ( ) => document . mozPointerLockElement ; break ; case 2 : PointerLock . _exit = ( ) => document . webkitExitPointerLock ( ) ; PointerLock . _request = ( element ) => ( element as any ) . webkitRequestPointerLock ( ) ; PointerLock . _element = ( ) => document . webkitPointerLockElement ; break ; default : assert ( false , `none of the following pointer lock apis was found: native, moz, or webkit` ) ; } } /**
     * Returns whether or not a pointer lock element exists, indicating if pointer lock is active or not.
     */ static active ( element ? ) { if ( this . _element === undefined ) { return false ; } return ( element !== undefined && PointerLock . _element ( ) === element ) || ( element === undefined && PointerLock . _element ( ) !== undefined && PointerLock . _element ( ) !== null ) ; } param element static request ( element , callback ? ) { if ( element === undefined ) { return ; } PointerLock . queryAndCacheAPI ( ) ; if ( PointerLock . active ( ) && PointerLock . _element ( ) !== element ) { PointerLock . _exit ( ) ; } if ( ! PointerLock . active ( ) ) { PointerLock . _request ( element ) ; } } /**
     * Exit pointer lock. The function considers various platform specific pointer lock interfaces, i.e., native, moz,
     * and webkit.
     */ static exit ( ) { if ( PointerLock . _exit ) { PointerLock . _exit ( ) ; } } }