"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _noop2 = _interopRequireDefault(require("lodash/noop"));

var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// 双击时间间隔
var interval = 300;
/**
 * 事件统一封装
 *
 * @export
 * @class Event
 * @implements {IEvent}
 */

var CustomEvent =
/*#__PURE__*/
function () {
  function CustomEvent(props, autoSetEvent) {
    _classCallCheck(this, CustomEvent);

    _defineProperty(this, "startClickTime", 0);

    _defineProperty(this, "click", _noop2.default);

    _defineProperty(this, "mousedown", _noop2.default);

    _defineProperty(this, "mousemove", _noop2.default);

    _defineProperty(this, "mouseout", _noop2.default);

    _defineProperty(this, "mouseup", _noop2.default);

    _defineProperty(this, "mouseover", _noop2.default);

    _defineProperty(this, "pointercancel", _noop2.default);

    _defineProperty(this, "pointerdown", _noop2.default);

    _defineProperty(this, "pointermove", _noop2.default);

    _defineProperty(this, "pointerout", _noop2.default);

    _defineProperty(this, "pointerover", _noop2.default);

    _defineProperty(this, "pointertap", _noop2.default);

    _defineProperty(this, "pointerup", _noop2.default);

    _defineProperty(this, "pointerupoutside", _noop2.default);

    _defineProperty(this, "rightclick", _noop2.default);

    _defineProperty(this, "rightdown", _noop2.default);

    _defineProperty(this, "rightup", _noop2.default);

    _defineProperty(this, "rightoutside", _noop2.default);

    _defineProperty(this, "tap", _noop2.default);

    _defineProperty(this, "touchcancel", _noop2.default);

    _defineProperty(this, "touchend", _noop2.default);

    _defineProperty(this, "touchendoutside", _noop2.default);

    _defineProperty(this, "touchmove", _noop2.default);

    _defineProperty(this, "touchstart", _noop2.default);

    _defineProperty(this, "added", _noop2.default);

    _defineProperty(this, "removed", _noop2.default);

    _defineProperty(this, "props", {});

    this.props = props;

    if (autoSetEvent) {
      this.click = this.handleClick;
      this.touchstart = this.handleTouchStart;
      this.touchcancel = this.handleTouchCancel;
      this.touchend = this.handleTouchEnd;
      this.touchendoutside = this.handleTouchEndOutside;
      this.touchmove = this.handleTouchMove;
      this.tap = this.handleTap;
      this.removed = this.handleRemoved;
      this.added = this.handleAdded;
      this.rightclick = this.handleRightClick;
      this.rightdown = this.handleRightDown;
      this.rightoutside = this.handleRightOutside;
      this.rightup = this.handleRightUp;
      this.pointercancel = this.handlePointerCancel;
      this.pointerdown = this.handlePointerDown;
      this.pointermove = this.handlePointerMove;
      this.pointerout = this.handlePointerOut;
      this.pointerover = this.handlePointerOver;
      this.pointertap = this.handlePointerTap;
      this.pointerup = this.handlePointerUp;
      this.pointerupoutside = this.handlePointerOutside;
      this.mousedown = this.handleMouseDown;
      this.mousemove = this.handleMouseMove;
      this.mouseout = this.handleMouseOut;
      this.mouseover = this.handleMouseOver;
      this.mouseup = this.handleMouseUp;
    }
  }

  _createClass(CustomEvent, [{
    key: "getEventProps",
    value: function getEventProps() {
      return {
        click: this.handleClick,
        touchstart: this.handleTouchStart,
        touchcancel: this.handleTouchCancel,
        touchend: this.handleTouchEnd,
        touchendoutside: this.handleTouchEndOutside,
        touchmove: this.handleTouchMove,
        tap: this.handleTap,
        removed: this.handleRemoved,
        added: this.handleAdded,
        rightclick: this.handleRightClick,
        rightdown: this.handleRightDown,
        rightoutside: this.handleRightOutside,
        rightup: this.handleRightUp,
        pointercancel: this.handlePointerCancel,
        pointerdown: this.handlePointerDown,
        pointermove: this.handlePointerMove,
        pointerout: this.handlePointerOut,
        pointerover: this.handlePointerOver,
        pointertap: this.handlePointerTap,
        pointerup: this.handlePointerUp,
        pointerupoutside: this.handlePointerOutside,
        mousedown: this.handleMouseDown,
        mousemove: this.handleMouseMove,
        mouseout: this.handleMouseOut,
        mouseover: this.handleMouseOver,
        mouseup: this.handleMouseUp
      };
    }
  }, {
    key: "handleTouchMove",
    value: function handleTouchMove(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTouchMove)) {
        this.props.onTouchMove(e);
      }
    }
  }, {
    key: "handleTouchEndOutside",
    value: function handleTouchEndOutside(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTouchEndOutside)) {
        this.props.onTouchEndOutside(e);
      }
    }
  }, {
    key: "handleTouchEnd",
    value: function handleTouchEnd(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTouchEnd)) {
        this.props.onTouchEnd(e);
      }
    }
  }, {
    key: "handleTouchStart",
    value: function handleTouchStart(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTouchStart)) {
        this.props.onTouchStart(e);
      }
    }
  }, {
    key: "handleTouchCancel",
    value: function handleTouchCancel(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTouchCancel)) {
        this.props.onTouchCancel(e);
      }
    }
  }, {
    key: "handleTap",
    value: function handleTap(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onTap)) {
        this.props.onTap(e);
      }
    }
  }, {
    key: "handleRemoved",
    value: function handleRemoved(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onRemoved)) {
        this.props.onRemoved(e);
      }
    }
  }, {
    key: "handleAdded",
    value: function handleAdded(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onAdded)) {
        this.props.onAdded(e);
      }
    }
  }, {
    key: "handleRightUp",
    value: function handleRightUp(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onRightUp)) {
        this.props.onRightUp(e);
      }
    }
  }, {
    key: "handleRightOutside",
    value: function handleRightOutside(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onRightOutside)) {
        this.props.onRightOutside(e);
      }
    }
  }, {
    key: "handleRightDown",
    value: function handleRightDown(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onRightDown)) {
        this.props.onRightDown(e);
      }
    }
  }, {
    key: "handleRightClick",
    value: function handleRightClick(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onRightClick)) {
        this.props.onRightClick(e);
      }
    }
  }, {
    key: "handlePointerOutside",
    value: function handlePointerOutside(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerOutside)) {
        this.props.onPointerOutside(e);
      }
    }
  }, {
    key: "handlePointerUp",
    value: function handlePointerUp(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerUp)) {
        this.props.onPointerUp(e);
      }
    }
  }, {
    key: "handlePointerTap",
    value: function handlePointerTap(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerTap)) {
        this.props.onPointerTap(e);
      }
    }
  }, {
    key: "handlePointerOver",
    value: function handlePointerOver(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerOver)) {
        this.props.onPointerOver(e);
      }
    }
  }, {
    key: "handlePointerOut",
    value: function handlePointerOut(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerOut)) {
        this.props.onPointerOut(e);
      }
    }
  }, {
    key: "handlePointerMove",
    value: function handlePointerMove(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerMove)) {
        this.props.onPointerMove(e);
      }
    }
  }, {
    key: "handlePointerDown",
    value: function handlePointerDown(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerDown)) {
        this.props.onPointerDown(e);
      }
    }
  }, {
    key: "handlePointerCancel",
    value: function handlePointerCancel(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onPointerCancel)) {
        this.props.onPointerCancel(e);
      }
    }
  }, {
    key: "handleClick",
    value: function handleClick(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onClick)) {
        this.props.onClick(e);
      }
    }
  }, {
    key: "handleMouseDown",
    value: function handleMouseDown(e) {
      var now = Date.now();

      if (now - this.startClickTime < interval && this.props && (0, _isFunction2.default)(this.props.onDoubleClick)) {
        this.props.onDoubleClick(e);
      } else if (this.props && (0, _isFunction2.default)(this.props.onMousedown)) {
        this.props.onMousedown(e);
      }

      this.startClickTime = now;
    }
  }, {
    key: "handleMouseMove",
    value: function handleMouseMove(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onMouseMove)) {
        this.props.onMouseMove(e);
      }
    }
  }, {
    key: "handleMouseUp",
    value: function handleMouseUp(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onMouseUp)) {
        this.props.onMouseUp(e);
      }
    }
  }, {
    key: "handleMouseOut",
    value: function handleMouseOut(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onMouseOut)) {
        this.props.onMouseOut(e);
      }
    }
  }, {
    key: "handleMouseOver",
    value: function handleMouseOver(e) {
      if (this.props && (0, _isFunction2.default)(this.props.onMouseOver)) {
        this.props.onMouseOver(e);
      }
    }
  }]);

  return CustomEvent;
}();

exports.default = CustomEvent;

_defineProperty(CustomEvent, "clickInterval", interval);