import { useRef as f } from "react";
import { isNodeOrChild as g } from "./utils/is-node-or-child.es.js";
import { usePointerEvent as A, addPointerEvent as m } from "../events/use-pointer-event.es.js";
import { useUnmountEffect as C } from "../utils/use-unmount-effect.es.js";
import { AnimationType as T } from "../render/utils/types.es.js";
import { isDragActive as S } from "./drag/utils/lock.es.js";
import { pipe as L } from "../../../../popmotion/dist/es/utils/pipe.es.js";
function I(i) {
  var t = i.onTap, o = i.onTapStart, e = i.onTapCancel, P = i.whileTap, a = i.visualElement, w = t || o || e || P, l = f(!1), u = f(null), v = {
    passive: !(o || t || e || d)
  };
  function p() {
    var n;
    (n = u.current) === null || n === void 0 || n.call(u), u.current = null;
  }
  function c() {
    var n;
    return p(), l.current = !1, (n = a.animationState) === null || n === void 0 || n.setActive(T.Tap, !1), !S();
  }
  function E(n, r) {
    !c() || (g(a.getInstance(), n.target) ? t == null || t(n, r) : e == null || e(n, r));
  }
  function h(n, r) {
    !c() || e == null || e(n, r);
  }
  function d(n, r) {
    var s;
    p(), !l.current && (l.current = !0, u.current = L(m(window, "pointerup", E, v), m(window, "pointercancel", h, v)), (s = a.animationState) === null || s === void 0 || s.setActive(T.Tap, !0), o == null || o(n, r));
  }
  A(a, "pointerdown", w ? d : void 0, v), C(p);
}
export {
  I as useTapGesture
};
//# sourceMappingURL=use-tap-gesture.es.js.map
