function ScreenLocker() {
  this.screenLocker = document.createElement("div");
  this.screenLocker.style.display = 'none';
  this.screenLocker.style.position = 'fixed';
  this.screenLocker.style.top = '0';
  this.screenLocker.style.left = '0';
  this.screenLocker.style.width = '100%';
  this.screenLocker.style.height = '100%';
  this.screenLocker.style.backgroundColor = 'rgba(0, 0, 0, 0);';
  this.screenLocker.style.cursor = 'progress';
  this.screenLocker.style.zIndex = '99999';
  document.body.appendChild(this.screenLocker);
  this.lockCount = 0;
  this.lock = function () {
    this.lockCount++;
    this.screenLocker.style.display = 'inline-block';
    this.focusedElement = document.activeElement;
  };
  this.unlock = function (force) {
    if (force === undefined) force = false;
    this.lockCount--;
    if (this.lockCount <= 0 || force) {
      this.lockCount = 0;
      this.screenLocker.style.display = 'none';
      if (this.focusedElement != null) {
        this.focusedElement.focus();
      }
    }
  };
}
var screenLocker = new ScreenLocker();
function lockScreen() {
  screenLocker.lock();
}
function unlockScreen(force) {
  screenLocker.unlock(force);
}
function triggerWhenScreenUnlock(callback) {
  if (screenLocker.lockCount == 0) {
    console.debug('Screen unlocked. Invoking the callback.');
    callback();
  } else {
    setTimeout(function () {
      triggerWhenScreenUnlock(callback);
    }, 100);
  }
}