"use strict";

exports.__esModule = true;
exports.on = on;
exports.off = off;
exports.stopPropagation = stopPropagation;
exports.preventDefault = preventDefault;
exports.supportsPassive = void 0;

var _index = require("../index");

/* eslint-disable no-empty */

/* eslint-disable getter-return */
var supportsPassive = false;
exports.supportsPassive = supportsPassive;

if (!_index.isServer) {
  try {
    var opts = {};
    Object.defineProperty(opts, "passive", {
      get: function get() {
        /* istanbul ignore next */
        exports.supportsPassive = supportsPassive = true;
      }
    });
    window.addEventListener("test-passive", null, opts);
  } catch (e) {}
}

function on(target, event, handler, passive) {
  if (passive === void 0) {
    passive = false;
  }

  !_index.isServer && target.addEventListener(event, handler, supportsPassive ? {
    capture: false,
    passive: passive
  } : false);
}

function off(target, event, handler) {
  !_index.isServer && target.removeEventListener(event, handler);
}

function stopPropagation(event) {
  event.stopPropagation();
}

function preventDefault(event, isStopPropagation) {
  /* istanbul ignore else */
  if (typeof event.cancelable !== "boolean" || event.cancelable) {
    event.preventDefault();
  }

  if (isStopPropagation) {
    stopPropagation(event);
  }
}