/* eslint-disable import/prefer-default-export */
export var attach = function attach(el, style, duration) {
  var ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  return new Promise(function (resolve, reject) {
    var id = window.setTimeout(function () {
      if (el) {
        if (style) {
          el.setAttribute('style', style);
        } else {
          el.removeAttribute('style');
        }

        resolve();
      } else {
        reject();
      }
    }, duration);

    ref.cancel = function () {
      window.clearTimeout(id);
      reject({
        canceled: true
      });
    };
  });
};