import { Feature } from "./dist-es-motion-features-Feature.js";
import "../motion-utils/dist-es-errors.js";
import { press } from "../motion-dom/dist-es-gestures-press-index.js";
import { extractEventInfo } from "./dist-es-events-event-info.js";
import { frame } from "./dist-es-frameloop-frame.js";
function handlePressEvent(node, event, lifecycle) {
  const { props } = node;
  if (node.animationState && props.whileTap) {
    node.animationState.setActive("whileTap", lifecycle === "Start");
  }
  const eventName = "onTap" + (lifecycle === "End" ? "" : lifecycle);
  const callback = props[eventName];
  if (callback) {
    frame.postRender(() => callback(event, extractEventInfo(event)));
  }
}
class PressGesture extends Feature {
  mount() {
    const { current } = this.node;
    if (!current)
      return;
    this.unmount = press(current, (startEvent) => {
      handlePressEvent(this.node, startEvent, "Start");
      return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel");
    }, { useGlobalTarget: this.node.props.globalTapTarget });
  }
  unmount() {
  }
}
export {
  PressGesture
};
//# sourceMappingURL=dist-es-gestures-press.js.map
