"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const PanSession = require("./dist-es-gestures-pan-PanSession.cjs");
const addPointerEvent = require("./dist-es-events-add-pointer-event.cjs");
const Feature = require("./dist-es-motion-features-Feature.cjs");
require("../motion-utils/dist-es-errors.cjs");
const noop = require("../motion-utils/dist-es-noop.cjs");
const getContextWindow = require("./dist-es-utils-get-context-window.cjs");
const frame = require("./dist-es-frameloop-frame.cjs");
const asyncHandler = (handler) => (event, info) => {
  if (handler) {
    frame.frame.postRender(() => handler(event, info));
  }
};
class PanGesture extends Feature.Feature {
  constructor() {
    super(...arguments);
    this.removePointerDownListener = noop.noop;
  }
  onPointerDown(pointerDownEvent) {
    this.session = new PanSession.PanSession(pointerDownEvent, this.createPanHandlers(), {
      transformPagePoint: this.node.getTransformPagePoint(),
      contextWindow: getContextWindow.getContextWindow(this.node)
    });
  }
  createPanHandlers() {
    const { onPanSessionStart, onPanStart, onPan, onPanEnd } = this.node.getProps();
    return {
      onSessionStart: asyncHandler(onPanSessionStart),
      onStart: asyncHandler(onPanStart),
      onMove: onPan,
      onEnd: (event, info) => {
        delete this.session;
        if (onPanEnd) {
          frame.frame.postRender(() => onPanEnd(event, info));
        }
      }
    };
  }
  mount() {
    this.removePointerDownListener = addPointerEvent.addPointerEvent(this.node.current, "pointerdown", (event) => this.onPointerDown(event));
  }
  update() {
    this.session && this.session.updateHandlers(this.createPanHandlers());
  }
  unmount() {
    this.removePointerDownListener();
    this.session && this.session.end();
  }
}
exports.PanGesture = PanGesture;
//# sourceMappingURL=dist-es-gestures-pan-index.cjs.map
