"use strict";

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

/*
 * @Author: lianghaosen
 * @Date: 2018-12-03 11:47:08
 * @Last Modified by: lianghaosen
 * @Last Modified time: 2018-12-04 16:31:48
 */
var prefixArr = ["webkit", "moz", "o"];
var EVENTS_NAME = ["Transition", "Animation"];
var startEvents = [];
var endEvents = [];
var test = document.createElement("div");
var style = test.style;

function walkPrefix(type, eventsArr) {
  for (var _i = 0, _EVENTS_NAME = EVENTS_NAME; _i < _EVENTS_NAME.length; _i++) {
    var name = _EVENTS_NAME[_i];
    var withoutPrefix = name.toLowerCase();

    if (withoutPrefix in style) {
      eventsArr.push((name + type).toLocaleLowerCase());
      continue;
    }

    for (var _i2 = 0, _prefixArr = prefixArr; _i2 < _prefixArr.length; _i2++) {
      var prefix = _prefixArr[_i2];
      var evName = prefix + name;

      if (evName in style) {
        eventsArr.push(evName + type);
        break;
      }
    }
  }
}

walkPrefix("Start", startEvents);
walkPrefix("End", endEvents);
var _default = {
  startEvents: startEvents,
  endEvents: endEvents,
  addStartListener: function addStartListener(node, callback) {
    if (!startEvents.length) {
      setTimeout(callback, 0);
      return;
    }

    startEvents.forEach(function (evName) {
      node.addEventListener(evName, callback, false);
    });
  },
  addEndListener: function addEndListener(node, callback) {
    if (!startEvents.length) {
      setTimeout(callback, 0);
      return;
    }

    endEvents.forEach(function (evName) {
      node.addEventListener(evName, callback);
    });
  },
  removeStartListener: function removeStartListener(node, callback) {
    startEvents.forEach(function (evName) {
      node.removeEventListener(evName, callback);
    });
  },
  removeEndListener: function removeEndListener(node, callback) {
    endEvents.forEach(function (evName) {
      node.removeEventListener(evName, callback);
    });
  }
};
exports["default"] = _default;