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-acomp__js__OnScreenWidget.js
/*** module: node_modules/absol-acomp/js/OnScreenWidget.js ***/
"use strict";

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

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

var _ACore = _interopRequireDefault(require("../ACore"));

var _Hanger = _interopRequireDefault(require("./Hanger"));

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

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

var _stringGenerate = require("absol/src/String/stringGenerate");


var _ = _ACore.default._;
var $ = _ACore.default.$;
var $$ = _ACore.default.$$;
/***
 * @extends Hanger
 * @constructor
 */

function OnScreenWidget() {
  this.id = 'unset-id-' + (0, _stringGenerate.randomIdent)();
  this.on({
    dragstart: this.eventHandler.widgetStartDrag,
    drag: this.eventHandler.widgetDrag,
    dragend: this.eventHandler.widgetDragEnd
  });
  this.addEventListener('click', function (event) {
    if (!this._preventClick) this.emit('click', event, this);
  });
  this.$attachhook = _('attachhook').addTo(this);
  this.$attachhook.on('attached', this.eventHandler.attached);
  this.config = null;
}

OnScreenWidget.tag = 'OnScreenWidget'.toLowerCase();

OnScreenWidget.render = function () {
  return _({
    tag: 'hanger',
    extendEvent: 'click',
    class: ['as-onscreen-widget', 'as-size-loading'],
    props: {
      hangOn: 3
    }
  });
};

OnScreenWidget.prototype.configPrefix = 'on-screen-widget-';

OnScreenWidget.prototype._genConfig = function () {
  this._widgetBound = this.getBoundingClientRect();
  var screenSize = (0, _Dom.getScreenSize)();
  return {
    cx: (this._widgetBound.left + this._widgetBound.width / 2) * 100 / screenSize.width,
    cy: (this._widgetBound.top + this._widgetBound.height / 2) * 100 / screenSize.height
  };
};

OnScreenWidget.prototype._saveConfig = function () {
  var id = this.id || '';
  if (id.startsWith('unset-id-') || !this.config) return;
  localStorage.setItem(this.configPrefix + id, JSON.stringify(this.config));
};

OnScreenWidget.prototype._loadConfig = function () {
  var id = this.id || '';
  if (id.startsWith('unset-id-')) return;
  var config = null;

  try {
    config = JSON.parse(localStorage.getItem(this.configPrefix + id));

    if (typeof config !== "object" || typeof config.cx !== "number" || typeof config.cy !== 'number') {
      config = this.config || this._genConfig();
    }
  } catch (error) {
    config = this.config || this._genConfig();
  }

  var cx = config.cx || 0;
  var cy = config.cy || 0;
  this.addStyle({
    '--cx': cx / 100,
    '--cy': cy / 100
  });
  this.config = config;
};

OnScreenWidget.prototype._updateCSSSize = function () {
  var bound = this.getBoundingClientRect();
  this.addStyle({
    '--client-height': bound.height + 'px',
    '--client-width': bound.width + 'px'
  });
  this.removeClass('as-size-loading');
};
/***
 *
 * @type {OnScreenWidget|{}}
 */


OnScreenWidget.eventHandler = {};

OnScreenWidget.eventHandler.attached = function () {
  var images = $$('img', this);
  var syncs = images.map(function (img) {
    if (img.classList.contains('absol-attachhook')) return Promise.resolve();
    return (0, _Dom.waitImageLoaded)(img, 100);
  });
  var thisW = this;
  Promise.all(syncs).then(function () {
    thisW._updateCSSSize();

    thisW._loadConfig();
  });
};

OnScreenWidget.eventHandler.widgetStartDrag = function (event) {
  this._widgetBound = this.getBoundingClientRect();
  this._preventClick = true;
};

OnScreenWidget.eventHandler.widgetDrag = function (event) {
  event.preventDefault();
  var screenSize = (0, _Dom.getScreenSize)();
  var p0 = new _Vec.default(this._widgetBound.left, this._widgetBound.top);
  var dv = event.currentPoint.sub(event.startingPoint);
  var p1 = p0.add(dv);
  var cx = (p1.x - 2) * 100 / (screenSize.width - this._widgetBound.width - 4);
  var cy = (p1.y - 2) * 100 / (screenSize.height - this._widgetBound.height - 4);
  cx = Math.max(0, Math.min(100, cx));
  cy = Math.max(0, Math.min(100, cy));
  this.addStyle({
    '--cx': cx / 100,
    '--cy': cy / 100
  });

  if (this.config) {
    this.config.cx = cx;
    this.config.cy = cy;
  }
};

OnScreenWidget.eventHandler.widgetDragEnd = function () {
  var thisWG = this;
  setTimeout(function () {
    thisWG._preventClick = false;
  }, 100);

  this._saveConfig();
};

_ACore.default.install(OnScreenWidget);

var _default = OnScreenWidget;
exports.default = _default;

VaKeR 2022