rootComponents/moveMouse/moveMouse.js

// local dependencies
import store from '../../store/store';
import C from '../../constants/constants';
import { updateMousePosition } from '../../util/helpers';

/**
 * Move the mouse to the coordinates provided by an event's `clientX` and `clientY` coordinates.
 * Additionally, `debug` can be enabled to see the cursor position of of the `click` action.
 *
 * @module moveMouse
 * @memberOf module:rootComponents
 * @param {object} event - A mouse event that is used for move to the mouse
 * @param {object} event.clientX - The screen space x-coordinate.
 * @param {object} event.clientY - The screen space y-coordinate.
 * @param {boolean} [debug=false] - Allows to turn on the visuals for the `click` action.
 * @returns {self} - Chainable api by returning the instance.
 *
 * @example
 * const event = { clientX: 500, clientY: 500 }; // sample event
 * $$$.moveMouse(event); // updates the mouse positions provided in the event
 * $$$.moveMouse(event, true); // enable cursor visual with `debug` set to `true`
 */
export default function (event, debug = false) {
  const canvas = store.get(C.RENDERER).domElement;
  canvas.dispatchEvent(new MouseEvent(C.MOUSE_MOVE, event));
  updateMousePosition(event, debug);
  return this;
};