all files / mapbox-gl-draw/src/lib/ mouse_event_point.js

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                     38× 38×            
const Point = require('point-geometry');
 
/**
 * Returns a Point representing a mouse event's position
 * relative to a containing element.
 *
 * @param {MouseEvent} mouseEvent
 * @param {Node} container
 * @returns {Point}
 */
function mouseEventPoint(mouseEvent, container) {
  const rect = container.getBoundingClientRect();
  return new Point(
    mouseEvent.clientX - rect.left - container.clientLeft,
    mouseEvent.clientY - rect.top - container.clientTop
  );
}
 
module.exports = mouseEventPoint;