{"size": 3585, "ext": "js", "max_stars_repo_path": "node_modules/@chakra-ui/utils/dist/esm/pointer-event.js", "max_stars_repo_name": "Sid1000/sample-page", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@chakra-ui/utils/dist/esm/pointer-event.js", "max_issues_repo_name": "Sid1000/sample-page", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/@chakra-ui/utils/dist/esm/pointer-event.js", "max_forks_repo_name": "Sid1000/sample-page", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.5769230769, "max_line_length": 133, "alphanum_fraction": 0.7073919107}
/**
 * Credit goes to `framer-motion` of this useful utilities.
 * License can be found here: https://github.com/framer/motion
 */
import { addDomEvent, getEventWindow, isBrowser } from "./dom";
export function isMouseEvent(event) {
  var win = getEventWindow(event); // PointerEvent inherits from MouseEvent so we can't use a straight instanceof check.

  if (typeof win.PointerEvent !== "undefined" && event instanceof win.PointerEvent) {
    return !!(event.pointerType === "mouse");
  }

  return event instanceof win.MouseEvent;
}
export function isTouchEvent(event) {
  var hasTouches = !!event.touches;
  return hasTouches;
}

/**
 * Filters out events not attached to the primary pointer (currently left mouse button)
 * @param eventHandler
 */
function filterPrimaryPointer(eventHandler) {
  return event => {
    var win = getEventWindow(event);
    var isMouseEvent = event instanceof win.MouseEvent;
    var isPrimaryPointer = !isMouseEvent || isMouseEvent && event.button === 0;

    if (isPrimaryPointer) {
      eventHandler(event);
    }
  };
}

var defaultPagePoint = {
  pageX: 0,
  pageY: 0
};

function pointFromTouch(e, pointType) {
  if (pointType === void 0) {
    pointType = "page";
  }

  var primaryTouch = e.touches[0] || e.changedTouches[0];
  var point = primaryTouch || defaultPagePoint;
  return {
    x: point[pointType + "X"],
    y: point[pointType + "Y"]
  };
}

function pointFromMouse(point, pointType) {
  if (pointType === void 0) {
    pointType = "page";
  }

  return {
    x: point[pointType + "X"],
    y: point[pointType + "Y"]
  };
}

export function extractEventInfo(event, pointType) {
  if (pointType === void 0) {
    pointType = "page";
  }

  return {
    point: isTouchEvent(event) ? pointFromTouch(event, pointType) : pointFromMouse(event, pointType)
  };
}
export function getViewportPointFromEvent(event) {
  return extractEventInfo(event, "client");
}
export var wrapPointerEventHandler = function wrapPointerEventHandler(handler, shouldFilterPrimaryPointer) {
  if (shouldFilterPrimaryPointer === void 0) {
    shouldFilterPrimaryPointer = false;
  }

  var listener = event => handler(event, extractEventInfo(event));

  return shouldFilterPrimaryPointer ? filterPrimaryPointer(listener) : listener;
}; // We check for event support via functions in case they've been mocked by a testing suite.

var supportsPointerEvents = () => isBrowser && window.onpointerdown === null;

var supportsTouchEvents = () => isBrowser && window.ontouchstart === null;

var supportsMouseEvents = () => isBrowser && window.onmousedown === null;

var mouseEventNames = {
  pointerdown: "mousedown",
  pointermove: "mousemove",
  pointerup: "mouseup",
  pointercancel: "mousecancel",
  pointerover: "mouseover",
  pointerout: "mouseout",
  pointerenter: "mouseenter",
  pointerleave: "mouseleave"
};
var touchEventNames = {
  pointerdown: "touchstart",
  pointermove: "touchmove",
  pointerup: "touchend",
  pointercancel: "touchcancel"
};
export function getPointerEventName(name) {
  if (supportsPointerEvents()) {
    return name;
  }

  if (supportsTouchEvents()) {
    return touchEventNames[name];
  }

  if (supportsMouseEvents()) {
    return mouseEventNames[name];
  }

  return name;
}
export function addPointerEvent(target, eventName, handler, options) {
  return addDomEvent(target, getPointerEventName(eventName), wrapPointerEventHandler(handler, eventName === "pointerdown"), options);
}
export function isMultiTouchEvent(event) {
  return isTouchEvent(event) && event.touches.length > 1;
}
//# sourceMappingURL=pointer-event.js.map