"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.enableScroll = exports.disableScroll = void 0;
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
const keys = {
  37: 1,
  38: 1,
  39: 1,
  40: 1
};

function preventDefault(e) {
  e.preventDefault();
}

function preventDefaultForScrollKeys(e) {
  if (keys[e.keyCode]) {
    preventDefault(e);
    return false;
  }
} // modern Chrome requires { passive: false } when adding event


var supportsPassive = false;

try {
  window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
    get: function () {
      supportsPassive = true;
      return true;
    }
  }));
} catch (e) {// intentionally empty
}

const wheelOpt = supportsPassive ? {
  passive: false
} : false;
const isBrowser = window && window.document && window.document.createElement;
const wheelEvent = isBrowser && 'onwheel' in window.document.createElement('div') ? 'wheel' : 'mousewheel'; // call this to Disable

const disableScroll = () => {
  window.addEventListener('DOMMouseScroll', preventDefault, false); // older FF

  window.addEventListener(wheelEvent, preventDefault, wheelOpt); // modern desktop

  window.addEventListener('touchmove', preventDefault, wheelOpt); // mobile

  window.addEventListener('keydown', preventDefaultForScrollKeys, false);
}; // call this to Enable


exports.disableScroll = disableScroll;

const enableScroll = () => {
  window.removeEventListener('DOMMouseScroll', preventDefault, false);
  window.removeEventListener(wheelEvent, preventDefault, wheelOpt);
  window.removeEventListener('touchmove', preventDefault, wheelOpt);
  window.removeEventListener('keydown', preventDefaultForScrollKeys, false);
};

exports.enableScroll = enableScroll;