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__app__TutorMaster.js
/*** module: node_modules/absol-tutor/js/app/TutorMaster.js ***/
"use strict";

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

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

var _Tutor = _interopRequireDefault(require("../Tutor"));

var _Icon = require("../dom/Icon");

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

var _utils = require("absol-acomp/js/utils");

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

var _FlagManager = _interopRequireDefault(require("./FlagManager"));

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

var _Inspector = _interopRequireDefault(require("./Inspector"));

var _BaseEditor = _interopRequireDefault(require("absol-form/js/core/BaseEditor"));

var _OnsScreenWindow = _interopRequireDefault(require("absol-acomp/js/OnsScreenWindow"));

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

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

var _SplitEditor = _interopRequireDefault(require("./SplitEditor"));


var dependentSrc = (0, _Core.$)('script', false, function (elt) {
  if (elt.src && elt.src.indexOf('absol.dependents.js') >= 0) {
    return true;
  }
});
dependentSrc = dependentSrc && dependentSrc.src;
var tutorSrc = document.currentScript.src;

_FlagManager.default.add('TUTOR_LOCAL_SAVE', true);
/***
 * @extends BaseEditor
 * @constructor
 */


function TutorMaster() {
  _BaseEditor.default.call(this);

  this.script = window['TUTOR_LOCAL_SAVE'] && localStorage.getItem('TUTOR_MASTER_SCRIPT') || '';
  this.inspector = new _Inspector.default();
  this.splitEditor = new _SplitEditor.default();
}

_OOP.default.mixClass(TutorMaster, _BaseEditor.default);

TutorMaster.prototype.CONFIG_STORE_KEY = 'TUTOR_MASTER_SETTING';
TutorMaster.prototype.config = {
  editor: {
    width: 48,
    height: 48,
    x: 2,
    y: 50
  },
  toolbar: {
    x: 0.999,
    y: 0.999
  }
};

TutorMaster.prototype.createView = function () {
  this.$view = (0, _Core._)({
    style: {
      '--tutor-master-x': this.config.toolbar.x,
      '--tutor-master-y': this.config.toolbar.y
    },
    class: 'atr-tutor-master',
    child: [{
      tag: 'hanger',
      class: 'atr-tutor-master-head',
      child: _Icon.TutorIco.cloneNode(true),
      on: {
        dragstart: this.ev_headerDragStart.bind(this),
        drag: this.ev_headerDrag.bind(this)
      }
    }, {
      tag: 'button',
      attr: {
        title: 'Import File Script'
      },
      class: ['as-from-tool-button', 'atr-import-btn'],
      child: 'span.mdi.mdi-file-import'
    }, {
      tag: 'button',
      attr: {
        title: 'Edit Script'
      },
      class: ['as-from-tool-button', 'atr-edit-script-btn'],
      child: 'span.mdi.mdi-script-text-outline'
    }, {
      tag: 'button',
      attr: {
        title: 'Play'
      },
      class: ['as-from-tool-button', 'atr-play-btn'],
      child: 'span.mdi.mdi-play'
    }, {
      tag: 'button',
      class: ['as-from-tool-button', 'atr-stop-btn'],
      child: 'span.mdi.mdi-stop'
    }, {
      tag: 'button',
      attr: {
        title: 'Download Script'
      },
      class: ['as-from-tool-button', 'atr-download-btn'],
      child: 'span.mdi.mdi-cloud-download'
    }, {
      tag: 'button',
      attr: {
        title: 'Inspector'
      },
      class: ['as-from-tool-button', 'atr-inspector-btn'],
      child: 'span.mdi.mdi-auto-fix'
    }, {
      tag: 'a',
      class: 'atr-download-link',
      attr: {
        download: 'tutor_script.js'
      },
      style: {
        display: 'none'
      }
    }]
  });
  this.$importBtn = (0, _Core.$)('.atr-import-btn', this.$view).on('click', this.importFromFileDialog.bind(this));
  this.$editScriptBtn = (0, _Core.$)('.atr-edit-script-btn', this.$view).on('click', this.ev_clickEditScript.bind(this));
  this.$playBtn = (0, _Core.$)('.atr-play-btn', this.$view).on('click', this.ev_clickPlayBtn.bind(this));
  this.$stopBtn = (0, _Core.$)('.atr-stop-btn', this.$view).on('click', this.ev_clickStopBtn.bind(this));
  this.$stopBtn.disabled = true;
  this.$downloadBtn = (0, _Core.$)('.atr-download-btn', this.$view).on('click', this.downloadScript.bind(this));
  this.$downloadLink = (0, _Core.$)('a.atr-download-link', this.$view);
  this.$inspectorBtn = (0, _Core.$)('.atr-inspector-btn', this.$view).on('click', this.ev_clickInspectorBtn.bind(this));
  /***
   * @type {OnScreenWindow}
   */

  this.$editWindow = (0, _Core._)('onscreenwindow').addStyle({
    width: this.config.editor.width + 'vw',
    height: this.config.editor.height + 'vh',
    left: this.config.editor.x + 'vw',
    top: this.config.editor.y + 'vh',
    visibility: 'hidden',
    opacity: '0'
  }).addClass('attr-split-editor-window');
  this.$editWindow.on('relocation', this.ev_editWindowPositionChange.bind(this)).on('sizechange', this.ev_editWindowPositionChange.bind(this));
  this.$editWindow.windowTitle = 'Tutor';
  this.$editWindow.addChild(this.splitEditor.getView());
  this.$editWindow.addTo(document.body);
  this.$editWindow.windowActions = [{
    class: 'as-window-box-header-button-close',
    icon: 'span.mdi.mdi-close',
    name: 'close'
  }];
  this.$editWindow.on('action', function (event) {
    if (event.actionData && event.actionData.name === 'close') {
      this.ev_clickCloseScript(event);
    }
  }.bind(this));
  this.splitEditor.setValue(this.script);
};

TutorMaster.prototype.importFromFileDialog = function () {
  var thisTM = this;
  (0, _utils.openFileDialog)({
    accept: ".js"
  }).then(function (files) {
    if (files.length > 0) {
      var fileReader = new FileReader();

      fileReader.onload = function (event) {
        thisTM.setScript(event.target.result);
      };

      fileReader.readAsText(files[0]);
    }
  });
};

TutorMaster.prototype.onResume = function () {
  document.body.classList.add('atr-has-tutor-master');
};

TutorMaster.prototype.onPause = function () {
  document.body.classList.remove('atr-has-tutor-master');
};

TutorMaster.prototype.onStart = function () {
  var view = this.getView();

  if (window.data_module && window.data_module.exportDatabase) {
    this.$databaseBtn = (0, _Core._)({
      tag: 'button',
      attr: {
        title: 'ExportDatabase'
      },
      class: ['as-from-tool-button', 'atr-inspector-btn'],
      child: 'span.mdi.mdi-database',
      on: {
        click: window.data_module.exportDatabase.bind(window.data_module)
      }
    }).addTo(this.$view);
  }

  if (!view.parentElement) {
    view.addTo(document.body);
    var bound = view.getBoundingClientRect();
    view.addStyle({
      '--tutor-master-width': bound.width + 'px',
      '--tutor-master-height': bound.height + 'px'
    });
  }
};

TutorMaster.prototype.onDestroy = function () {
  this.$editWindow.remove();
};

TutorMaster.prototype.setScript = function (script) {
  this.script = script || '';
  this.splitEditor.setValue(this.script);
};

TutorMaster.prototype.downloadScript = function () {
  var thisTM = this;
  var blob = new Blob([this.splitEditor.getValue()], {
    type: 'text/plain'
  });
  thisTM.$downloadLink.href = URL.createObjectURL(blob);
  thisTM.$downloadLink.click();
};

TutorMaster.prototype.ev_clickEditScript = function () {
  if (this.$editScriptBtn.containsClass('as-active')) {
    this.$editScriptBtn.removeClass('as-active');
    this.$editWindow.addStyle('visibility', 'hidden');
    this.$editWindow.addStyle('opacity', '0');
  } else {
    this.$editWindow.removeStyle('visibility');
    this.$editWindow.addStyle('opacity', '1');
    this.$editScriptBtn.addClass('as-active');
  }
};

TutorMaster.prototype.ev_clickCloseScript = function () {
  if (this.$editScriptBtn.containsClass('as-active')) {
    this.$editScriptBtn.removeClass('as-active');
    this.$editWindow.addStyle('visibility', 'hidden');
    this.$editWindow.addStyle('opacity', '0');
  }
};

TutorMaster.prototype.ev_clickPlayBtn = function () {
  this.script = this.splitEditor.getValue();
  this.$editWindow.addStyle('visibility', 'hidden').addStyle('opacity', '0');
  this.$playBtn.disabled = true;

  var onFinish = function (err) {
    if (err instanceof Error) {
      var status = this.tutor.getStatus();

      _Toast.default.make({
        class: 'atr-toast-message',
        props: {
          variant: 'error',
          htitle: "Tutor Runtime Error!",
          disappearTimeout: 20000
        },
        child: [{
          tag: 'strong',
          child: {
            text: '[Ln ' + status.row + (status.col > 0 ? ', Col ' + status.col : '') + '] '
          }
        }, {
          tag: 'code',
          child: {
            text: status.code
          }
        }, {
          tag: 'div',
          child: {
            text: err.message
          }
        }]
      });

      console.error(err);
    } else if (typeof err === 'number' || err === undefined) {
      if (err === 0) {
        _Toast.default.make({
          props: {
            message: "Script finish successfully!",
            variant: 'success',
            htitle: "Success",
            disappearTimeout: 6000
          }
        });
      } else {
        _Toast.default.make({
          props: {
            message: 'Script is interrupted!',
            variant: 'warning',
            htitle: "",
            disappearTimeout: 6000
          }
        });
      }
    }

    this.$playBtn.disabled = false;
    this.$stopBtn.disabled = true;

    if (this.$editScriptBtn.containsClass('as-active')) {
      this.$editWindow.removeStyle('visibility').addStyle('opacity', '1');
    }

    this.tutor = null;
  }.bind(this);

  try {
    this.tutor = new _Tutor.default(document.body, this.script);
    this.$stopBtn.disabled = false;
    return this.tutor.exec().then(onFinish).catch(onFinish);
  } catch (err) {
    this.$playBtn.disabled = false;

    if (this.$editScriptBtn.containsClass('as-active')) {
      this.$editWindow.removeStyle('visibility').addStyle('opacity', '1');
    }

    _Toast.default.make({
      props: {
        variant: 'error',
        htitle: 'Script Error!',
        message: err.message,
        disappearTimeout: 10000
      }
    });

    console.error(err);
    this.$stopBtn.disabled = true;
    this.tutor = null;
  }
};

TutorMaster.prototype.ev_clickStopBtn = function () {
  if (this.tutor) {
    this.tutor.stop();
  }
};

TutorMaster.prototype.ev_clickInspectorBtn = function () {
  if (this.$inspectorBtn.containsClass('as-active')) {
    this.$inspectorBtn.removeClass('as-active');
    this.inspector.stop();
  } else {
    this.$inspectorBtn.addClass('as-active');
    this.inspector.start();
  }
};

TutorMaster.prototype.ev_editWindowPositionChange = function () {
  var screenSize = (0, _Dom.getScreenSize)();
  var bound = this.$editWindow.getBoundingClientRect();
  this.config.editor.x = bound.left / screenSize.width * 100;
  this.config.editor.y = bound.top / screenSize.height * 100;
  this.config.editor.width = bound.width / screenSize.width * 100;
  this.config.editor.height = bound.height / screenSize.height * 100;
  this.saveConfig();
};

TutorMaster.prototype.ev_headerDragStart = function () {
  var bound = this.$view.getBoundingClientRect();
  var screenSize = (0, _Dom.getScreenSize)();
  this._headerDragData = {
    bound: bound,
    screenSize: screenSize,
    initPos: new _Vec.default(bound.left, bound.top)
  };
};

TutorMaster.prototype.ev_headerDrag = function (event) {
  var d = event.currentPoint.sub(event.startingPoint);

  var newPos = this._headerDragData.initPos.add(d);

  var x = (newPos.x - 2) / (this._headerDragData.screenSize.width - this._headerDragData.bound.width - 4);
  var y = (newPos.y - 2) / (this._headerDragData.screenSize.height - this._headerDragData.bound.height - 4);
  x = Math.max(0, Math.min(0.98, x));
  y = Math.max(0, Math.min(0.98, y));
  this.$view.addStyle({
    '--tutor-master-x': x,
    '--tutor-master-y': y
  });
  this.config.toolbar.x = x;
  this.config.toolbar.y = y;
  this.saveConfig();
};

var _default = TutorMaster;
exports.default = _default;

VaKeR 2022