import * as THREE from 'three';

export default function pointerLock( controls, element = document.body ) {
  const hasPointerLock = (
    'pointerLockElement' in document ||
    'mozPointerLockElement' in document ||
    'webkitPointerLockElement' in document
  );

  const dispatcher = new THREE.EventDispatcher();

  if ( !hasPointerLock ) {
    controls.enabled = true;
    return dispatcher;
  }

  function onPointerLockChange() {
    controls.enabled = (
      element === document.pointerLockElement ||
      element === document.mozPointerLockElement ||
      element === document.webkitPointerLockElement
    );

    dispatcher.dispatchEvent({
      type: 'change',
      enabled: controls.enabled,
    });
  }

  function onPointerLockError() {
    dispatcher.dispatchEvent({ type: 'error' });
  }

  document.addEventListener( 'pointerlockchange', onPointerLockChange );
  document.addEventListener( 'mozpointerlockchange', onPointerLockChange );
  document.addEventListener( 'webkitpointerlockchange', onPointerLockChange );

  document.addEventListener( 'pointerlockerror', onPointerLockError );
  document.addEventListener( 'mozpointerlockerror', onPointerLockError );
  document.addEventListener( 'webkitpointerlockerror', onPointerLockError );

  element.requestPointerLock = (
    element.requestPointerLock ||
    element.mozRequestPointerLock ||
    element.webkitRequestPointerLock
  );

  document.addEventListener( 'click', () => element.requestPointerLock() );

  return dispatcher;
}

@@ -125,22 +125,16 @@
 erLock =
- (%0A   
  'pointe
@@ -162,101 +162,8 @@
 ment
- %7C%7C%0A    'mozPointerLockElement' in document %7C%7C%0A    'webkitPointerLockElement' in document%0A  )
 ;%0A%0A 
@@ -357,16 +357,8 @@
 ed =
- (%0A     
  ele
@@ -397,121 +397,8 @@
 ment
- %7C%7C%0A      element === document.mozPointerLockElement %7C%7C%0A      element === document.webkitPointerLockElement%0A    )
 ;%0A%0A 
@@ -690,503 +690,48 @@
 r( '
-mozpointerlockchange', onPointerLockChange );%0A  document.addEventListener( 'webkitpointerlockchange', onPointerLockChange );%0A%0A  document.addEventListener( 'pointerlockerror', onPointerLockError );%0A  document.addEventListener( 'mozpointerlockerror', onPointerLockError );%0A  document.addEventListener( 'webkitpointerlockerror', onPointerLockError );%0A%0A  element.requestPointerLock = (%0A    element.requestPointerLock %7C%7C%0A    element.mozRequestPointerLock %7C%7C%0A    element.webkitRequestPointerLock%0A  );%0A
+pointerlockerror', onPointerLockError );
 %0A  d

Remove deprecated vendor-prefixes in pointer-lock