This code was taken directly from the three.js examples on Pointerlock controls, I did however package it with Vite and add some comments to get a better understanding of whats going on with the code.
The original example can be found here: https://threejs.org/examples/?q=pointerl#misc_controls_pointerlock