VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-tutor__js__scriptor__BaseCommand.js
/*** module: node_modules/absol-tutor/js/scriptor/BaseCommand.js ***/
"use strict";

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

require("../../css/basecommand.css");

var _Core = require("../dom/Core");

var _wrapAsync = _interopRequireDefault(require("../util/wrapAsync"));

var _Tooltip = _interopRequireDefault(require("absol-acomp/js/Tooltip"));

var _Toast = _interopRequireDefault(require("absol-acomp/js/Toast"));

var _Context = _interopRequireDefault(require("absol/src/AppPattern/Context"));

var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP"));

var _showdown = require("showdown");

var _EventEmitter = require("absol/src/HTML5/EventEmitter");

var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2"));

var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle"));

var _BlinkMask = _interopRequireDefault(require("../dom/BlinkMask"));

var _Dom = require("absol/src/HTML5/Dom");

var _AsyncCommand = _interopRequireDefault(require("../engine/AsyncCommand"));

var _TCommand = require("../engine/TCommand");

var _TState = _interopRequireDefault(require("../engine/TState"));


var showdownConverter = new _showdown.Converter();
/***
 * @typedef {{eltPath:string, message:string, wrongMessage:string, finishMessage:string, text: string, query: string, value:(string|number|null)>,until:(BaseCommand|(function():Promise))}} TutorCommandArgs
 */

/***
 * @extends AsyncCommand
 * @param process
 * @param {TutorCommandArgs} args
 * @constructor
 */

function BaseCommand(process, args) {
  _AsyncCommand.default.apply(this, arguments);

  this.tooltipToken = null;
  /***
   *
   * @type {*[]}
   * @protected
   */

  this._toastElts = [];
  this.hadWrongAction = false;
  this.$target = null;
  this._currentTostPosition = 'se';
  /** KeyBoard **/

  this._ev_docKeyboard = this.ev_docKeyboard.bind(this);
  this._keyboardPrevented = false;
  /***
   * only call if prevented keyboard
   * @type {function():void}
   */

  this.keyCb = null;
  /** Mouse **/

  this.ev_clickModal = this.ev_clickModal.bind(this);
  /***
   * only call if prevented mouse
   * @type {function():void}
   */

  this.clickCb = null;
}

(0, _TCommand.inheritCommand)(BaseCommand, _AsyncCommand.default);
BaseCommand.prototype.$htmlRender = (0, _Core._)('div');
/***
 * @type BlinkMask
 */

BaseCommand.prototype.$highlightModal = (0, _Core._)({
  tag: _BlinkMask.default.tag,
  class: ['atr-explain-modal', 'as-non-interact', 'as-animation']
});
BaseCommand.prototype.$puncturedModal = (0, _Core._)({
  tag: 'puncturedmodal',
  class: 'as-transparent',
  props: {
    onInteractOut: null
  }
});
BaseCommand.prototype.$transparentModal = (0, _Core._)('.atr-transparent-modal.as-hidden');
BaseCommand.prototype.$tooltipContent = (0, _Core._)({
  class: 'atr-explain-text'
});
/***
 *
 * @param {KeyboardEvent} event
 */

BaseCommand.prototype.ev_docKeyboard = function (event) {
  this.hadWrongAction = true;
  event.preventDefault();

  if (this.keyCb) {
    this.keyCb();
  }
};
/***
 *
 * @param {function|null} cb
 */


BaseCommand.prototype.ifPressKey = function (cb) {
  this.keyCb = cb;
};

BaseCommand.prototype.ev_clickModal = function (event) {
  this.hadWrongAction = true;
  if (this.clickCb) this.clickCb();
};
/***
 *
 * @param {function|null} cb
 */


BaseCommand.prototype.ifClickModal = function (cb) {
  this.clickCb = cb;
};
/***
 * @param {HTMLElement} elt
 * @param {MouseEvent} event
 */


BaseCommand.prototype.hitSomeOf = function (elt, event) {
  if ((0, _EventEmitter.hitElement)(elt, event)) return false;

  var bound = _Rectangle.default.fromClientRect(elt.getBoundingClientRect());

  var p = new _Vec.default(event.clientX, event.clientY);
  if (!bound.containsPoint(p)) return false;
  var id = elt.getAttribute('data-tutor-id') || elt['data-tutor-id'];
  if (!id) return false;
  var target = event.target;
  var tId;

  while (target) {
    tId = target.getAttribute('data-tutor-id') || target['data-tutor-id'];
    if (tId === id) return elt !== target;
    target = target.parentElement;
  }

  return false;
};

BaseCommand.prototype.onStart = function () {
  this.$puncturedModal.on('click', this.ev_clickModal);
  this.$transparentModal.on('click', this.ev_clickModal);
};
/***
 *
 * @param {function|null} cb
 */


BaseCommand.prototype.ifCancel = function (cb) {};

BaseCommand.prototype.onStop = function () {
  /** modal **/
  this.$puncturedModal.off('click', this.ev_clickModal);
  this.$transparentModal.off('click', this.ev_clickModal);
  this.clickCb = null;
  this.keyCb = null;
  this.closeTooltip();
  this.closeAllToasts();
  this.highlightElt(null);
  this.onlyClickTo(null);
  this.preventMouse(false);
  this.preventKeyBoard(false);
};

BaseCommand.prototype.md2HTMLElements = function (text) {
  this.$htmlRender.innerHTML = showdownConverter.makeHtml(text);
  return Array.prototype.slice.call(this.$htmlRender.childNodes);
};

BaseCommand.prototype.preventMouse = function (flag) {
  if (!this.$transparentModal.parentElement) {
    document.body.appendChild(this.$transparentModal);
  }

  if (flag) {
    this.$transparentModal.removeClass('as-hidden');
  } else {
    this.$transparentModal.addClass('as-hidden');
  }
};

BaseCommand.prototype.preventKeyBoard = function (flag) {
  if (flag) {
    if (!this._keyboardPrevented) {
      this._keyboardPrevented = true;
      document.addEventListener('keydown', this.ev_docKeyboard);
    }
  } else {
    if (this._keyboardPrevented) {
      this._keyboardPrevented = false;
      document.removeEventListener('keydown', this.ev_docKeyboard);
    }
  }
};

BaseCommand.prototype.highlightElt = function (elt) {
  if (!this.$highlightModal.parentElement) {
    document.body.appendChild(this.$highlightModal);
  }

  this.$highlightModal.follow(elt);

  if (elt) {
    this.$highlightModal.removeClass('as-transparent');
  } else {
    this.$highlightModal.addClass('as-transparent');
    this.$highlightModal.reset();
  }
};

BaseCommand.prototype.onlyClickTo = function (elt) {
  if (!this.$puncturedModal.parentElement) {
    document.body.appendChild(this.$puncturedModal);
  }

  if (elt) {
    this.$puncturedModal.follow(elt);
    this.$puncturedModal.removeClass('as-hidden');
  } else {
    this.$puncturedModal.follow(null);
    this.$puncturedModal.addClass('as-hidden');
    this.$puncturedModal.onInteractOut = null;
  }
};
/***
 *
 * @param {string} message
 */


BaseCommand.prototype.showDelayToast = function (message) {
  var thisC = this;
  this.preventMouse(true);
  this.showToast(message);
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      thisC.preventMouse(false);
      resolve();
    }, thisC.tutor.option.messageDelay);
  });
};

BaseCommand.prototype.showTooltip = function (elt, message) {
  if (typeof message !== "string") return;
  var eltList = this.md2HTMLElements(message);
  this.$tooltipContent.clearChild();
  eltList.forEach(function (elt) {
    this.$tooltipContent.addChild(elt);
  }.bind(this));
  this.tooltipToken = _Tooltip.default.show(elt, this.$tooltipContent, 'auto');

  _Tooltip.default.$holder.addClass('atr-on-top-1');
};
/***
 *
 * @param {string} message
 */


BaseCommand.prototype.showToast = function (message) {
  if (typeof message !== "string") return;
  var pos = this._currentTostPosition;

  var toastElt = _Toast.default.make({
    class: ['as-variant-background', 'atr-toast-message'],
    props: {
      htitle: 'Tutor',
      variant: 'sticky-note',
      timeText: ''
    },
    child: this.md2HTMLElements(message)
  }, pos);

  this._toastElts.push(toastElt);

  this._updateToastPosition();
};

BaseCommand.prototype.closeAllToasts = function () {
  setTimeout(function () {
    this._toastElts.forEach(function (elt) {
      elt.disappear();
    });
  }.bind(this), 1000);
};

BaseCommand.prototype.assignTarget = function (targetElt) {
  this.$target = targetElt;

  this._updateToastPosition();
};
/***
 *
 * @protected
 */


BaseCommand.prototype._updateToastPosition = function () {
  var targetElt = this.$target;

  if (targetElt) {
    var bound = targetElt.getBoundingClientRect();
    var screenSize = (0, _Dom.getScreenSize)();
    var toastListElt = _Toast.default.$toastList4Pos[this._currentTostPosition];
    var toastListBound = toastListElt.getBoundingClientRect();

    var boundRect = _Rectangle.default.fromClientRect(bound);

    var roastListRect = _Rectangle.default.fromClientRect(toastListBound);

    var isOverlay = roastListRect.isCollapse(boundRect);

    if (this._currentTostPosition === 'se' && bound.left + 400 >= screenSize.width && bound.top + 150 >= screenSize.height || isOverlay) {
      this._currentTostPosition = 'sw';
    } else if (this._currentTostPosition === 'sw' && bound.left <= 400 && bound.top + 150 >= screenSize.height || isOverlay) {
      this._currentTostPosition = 'se';
    }

    this._toastElts.forEach(function (elt) {
      if (!elt.parentElement || elt.parentElement === toastListElt) return;
      toastListElt.addChild(elt);
    });
  }
};

BaseCommand.prototype.closeTooltip = function () {
  if (this.tooltipToken) {
    _Tooltip.default.closeTooltip(this.tooltipToken);
  }
};

BaseCommand.prototype.depthClone = function () {
  var args = this.args;
  var newArgs = Object.keys(args).reduce(function (ac, cr) {
    if (args[cr] && args[cr].depthClone) {
      ac[cr] = args[cr].depthClone();
    } else {
      ac[cr] = args[cr];
    }

    return ac;
  }, {});
  return new this.constructor(this.process, newArgs);
};

BaseCommand.prototype.asyncGetElt = function (val) {
  var res;

  if (typeof val === "string") {
    res = (0, _wrapAsync.default)(this.tutor.findNode(val));
  } else {
    res = (0, _wrapAsync.default)(val);
  }

  return res.then(function (result) {
    if (result) return (0, _Core.$)(result);
    return result;
  });
};
/***
 *
 * @param {string|AElement} query
 * @param {boolean=} unsafe
 * @return {AElement}
 */


BaseCommand.prototype.findNode = function (query, unsafe) {
  return this.tutor.findNode(query, unsafe);
};

Object.defineProperty(BaseCommand.prototype, 'tutor', {
  get: function () {
    return this.process.tutor;
  }
});
var _default = BaseCommand;
exports.default = _default;

VaKeR 2022