var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
const eventMap = /* @__PURE__ */ new Map();
const TIME_OUT = 300;
class VueTouch {
  constructor(el, binding) {
    __publicField(this, "dom");
    __publicField(this, "callback");
    __publicField(this, "isMove");
    __publicField(this, "isLazyTap");
    this.dom = el;
    this.callback = binding.value;
    this.isLazyTap = binding.modifiers.lazy;
    this.isMove = false;
    el == null ? void 0 : el.addEventListener("touchstart", (event) => {
      if (binding.modifiers.stop) {
        event.stopPropagation();
      }
      this.touchstart();
    });
    el == null ? void 0 : el.addEventListener("touchmove", (event) => {
      if (binding.modifiers.stop) {
        event.stopPropagation();
      }
      this.touchmove();
    });
    el == null ? void 0 : el.addEventListener("touchend", (event) => {
      if (binding.modifiers.stop) {
        event.stopPropagation();
      }
      this.touchend(event);
    });
  }
  touchstart() {
    this.isMove = false;
  }
  touchmove() {
    this.isMove = true;
  }
  touchend(event) {
    if (this.isMove) {
      return;
    }
    if (this.isLazyTap) {
      if (eventMap.get(this.dom)) {
        clearTimeout(eventMap.get(this.dom));
        eventMap.delete(this.dom);
        return;
      }
      const timer = setTimeout(() => {
        this.callback(event);
        eventMap.delete(this.dom);
      }, TIME_OUT);
      eventMap.set(this.dom, timer);
    } else {
      this.callback(event);
    }
  }
}
const vTap = {
  mounted(el, binding) {
    return new VueTouch(el, binding);
  }
};
export {
  vTap as default
};
