import { PanSession } from "./dist-es-gestures-pan-PanSession.js";
import { addPointerEvent } from "./dist-es-events-add-pointer-event.js";
import { Feature } from "./dist-es-motion-features-Feature.js";
import "../motion-utils/dist-es-errors.js";
import { noop } from "../motion-utils/dist-es-noop.js";
import { getContextWindow } from "./dist-es-utils-get-context-window.js";
import { frame } from "./dist-es-frameloop-frame.js";
const asyncHandler = (handler) => (event, info) => {
  if (handler) {
    frame.postRender(() => handler(event, info));
  }
};
class PanGesture extends Feature {
  constructor() {
    super(...arguments);
    this.removePointerDownListener = noop;
  }
  onPointerDown(pointerDownEvent) {
    this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
      transformPagePoint: this.node.getTransformPagePoint(),
      contextWindow: 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.postRender(() => onPanEnd(event, info));
        }
      }
    };
  }
  mount() {
    this.removePointerDownListener = 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();
  }
}
export {
  PanGesture
};
//# sourceMappingURL=dist-es-gestures-pan-index.js.map
