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__src__Print__PrintSerializer.js
/*** module: node_modules/absol/src/Print/PrintSerializer.js ***/
"use strict";

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

var _VarScope = _interopRequireDefault(require("../AppPattern/VarScope"));

var _Dom = _interopRequireWildcard(require("../HTML5/Dom"));

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

var _PrintSerialHandlers = _interopRequireDefault(require("./PrintSerialHandlers"));

var _XLoader = require("../Network/XLoader");

var _noop = _interopRequireDefault(require("../Code/noop"));

var _stringGenerate = require("../String/stringGenerate");




/***
 * @typedef {Object} PSHandler
 * @property {string} id
 * @property {function(elt:AElement, scope: VarScope, stack:Array<AElement>):boolean} match
 * @property {function(printer: PaperPrinter,elt:AElement|Text, scope: VarScope, stack:Array<{elt: AElement|Text, scope:VarScope}>, accept: function():void):(boolean|void)} exec - return true if run other handle
 *
 */

/***
 *
 * @constructor
 */
function PrintSerializer() {
  /***
   * @type {Array<PSHandler>}
   */
  this.handlers = this.handlers.slice();
}

PrintSerializer.prototype.handlers = _PrintSerialHandlers.default;
/***
 *
 * @param {PaperPrinter} printer
 * @param {AElement|AElementNS|Text} elt
 * @param {VarScope} scope
 * @param {Array<{elt: AElement|Text, scope:VarScope}>} stack
 */

PrintSerializer.prototype.accept = function (printer, elt, scope, stack) {
  if (elt.nodeType === Node.ELEMENT_NODE) _Dom.default.ShareInstance.$(elt);
  var handler;
  var matched, cont;

  for (var i = 0; (!matched || cont) && i < this.handlers.length; ++i) {
    handler = this.handlers[i];
    matched = handler.match(elt, scope, stack);

    if (matched) {
      cont = handler.exec(printer, elt, scope, stack, elt1 => {
        this.accept(printer, elt1, new _VarScope.default(scope), stack.concat([{
          elt: elt,
          scope: scope
        }]));
      });
    }
  }
};
/***
 *
 * @param {Array<AElement> | AElement | Array<{elt: AElement, opt:Object}>} docList
 * @param printer
 * @param onProcess
 * @return {Promise<Awaited<unknown>[]>}
 */


PrintSerializer.prototype.serialize = function (docList, printer, onProcess) {
  var $ = _Dom.default.ShareInstance.$;
  if (!(docList instanceof Array)) docList = [docList];
  docList = docList.map(doc => {
    if (typeof doc === "string") {
      return {
        elt: $(doc)
      };
    } else if ((0, _Dom.isDomNode)(doc)) {
      return {
        elt: $(doc)
      };
    } else if (typeof doc === "object" && doc) {
      if (typeof doc.elt === "string") doc.elt = $(doc.elt);
      if (doc.elt && (0, _Dom.isDomNode)(doc.elt)) return doc;
    } else return null;
  }).filter(it => !!it);
  var sync = [];
  var processInfo = {
    state: 'RENDER_DOM',
    total: {
      all: 0,
      text: 0,
      image: 0
    },
    dom: {
      text: 0,
      image: 0
    },
    onProcess: () => {
      onProcess && onProcess(processInfo);
    }
  };
  printer.processInfo = processInfo;
  var contentChildList = docList.map(doc => {
    var elt = doc.elt;
    return (0, _Dom.depthClone)(elt, (originElt, copyElt) => {
      copyElt.__idx__ = processInfo.total.all;
      copyElt.__origin__ = originElt;
      processInfo.total.all++;
      var parent, fontWeight, style;
      var done = false;

      if (originElt.nodeType === Node.TEXT_NODE) {
        processInfo.total.text++;
        sync.push(new Promise(rs => {
          setTimeout(() => {
            parent = originElt.parentElement;

            if (!copyElt.__fontWeight__) {
              style = getComputedStyle(parent);
              fontWeight = parseInt(style.getPropertyValue('font-weight')); //not support other style

              copyElt.__fontWeight__ = fontWeight;

              if (fontWeight <= 400) {
                copyElt.parentElement.style.setProperty('font-weight', 'normal');
              } else if (fontWeight > 400) {
                copyElt.parentElement.style.setProperty('font-weight', 'bold');
              }

              processInfo.dom.text++;
            }

            processInfo.dom.text++;
            rs();
          }, 0);
        }));
      } else if (originElt.tagName && originElt.tagName.toLowerCase() === 'canvas') {
        copyElt.getContext('2d').drawImage(originElt, 0, 0);
      } else if (originElt.tagName === 'IMG' && !originElt.classList.contains('absol-attachhook') && originElt.src) {
        processInfo.total.image++;
        sync.push((0, _XLoader.isImageURLAllowCrossOrigin)(originElt.src).then(result => {
          var newElt;

          if (!result) {
            newElt = copyElt.cloneNode();
            newElt.__idx__ = copyElt.__idx__;
            newElt.__origin__ = copyElt.__origin__;
            ;
            copyElt.parentElement.replaceChild(newElt, copyElt);
            return (0, _XLoader.loadToBlobURL)('https://absol.cf/crossdownload.php?file=' + encodeURIComponent(originElt.src)).then(url => newElt.src = url).then(() => (0, _Dom.waitImageLoaded)(newElt, 10000)).then(() => {
              if (!done) {
                processInfo.dom.image++;
                processInfo.onProcess();
                done = true;
              }
            });
          } else {
            return (0, _Dom.waitImageLoaded)(copyElt, 10000).then(() => {
              if (!done) {
                processInfo.dom.image++;
                processInfo.onProcess();
                done = true;
              }
            });
          }
        }, err => {
          console.error(err);

          if (!done) {
            processInfo.dom.image++;
            processInfo.onProcess();
            done = true;
          }
        }));
      } else if (originElt.tagName === 'INPUT') {
        if (originElt.getAttribute('type') === 'text' || !originElt.getAttribute('type') || originElt.getAttribute('type') === 'number') {
          copyElt.value = originElt.value;
        } else if (originElt.getAttribute('type') === 'radio') {
          copyElt.setAttribute('name', (copyElt.getAttribute('name') || (0, _stringGenerate.randomIdent)()) + '_for_print');
          copyElt.checked = originElt.checked;
        }
      }
    });
  });

  var content = _Dom.default.ShareInstance._({
    style: {
      width: 794 - 57 * 2 + 'px',
      //WIDTH: 1123 - 57*2
      display: 'inline-block',
      overflow: 'visible'
    },
    class: 'as-printer-content',
    child: contentChildList
  });

  var scroller = _Dom.default.ShareInstance._({
    class: 'as-printer',
    style: {
      'text-size-adjust': 'none',
      '-webkit-text-size-adjust': 'none',
      '-moz-text-size-adjust': 'none',
      '-ms-text-size-adjust': 'none',
      position: 'fixed',
      top: '10px',
      bottom: '10px',
      left: '10px',
      overflow: 'scroll',
      width: '794px',
      // maxWidth: '90vw',
      background: 'white',
      // zIndex: 1000,
      opacity: '0',
      zIndex: '-100',
      visibility: 'hidden',
      pointerEvents: 'none'
    },
    child: content
  }).addTo(document.body);

  sync.push(new Promise(rs => {
    setTimeout(rs, 50);
  }));
  return Promise.all(sync).then(() => {
    processInfo.state = "SERIALIZE";
    processInfo.onProcess();
    docList.forEach((doc, i) => {
      printer.O = _Rectangle.default.fromClientRect(contentChildList[i].getBoundingClientRect()).A();
      printer.addSubDocument(printer.O, doc.opt);
      this.accept(printer, contentChildList[i], new _VarScope.default(), []);
    });
  }).then(() => {
    scroller.remove();
    processInfo.onProcess = _noop.default;
    return printer;
  });
};
/***
 *
 * @param {PSHandler} handler
 * @returns {this}
 */


PrintSerializer.prototype.addHandler = function (handler) {
  this.handlers.unshift(handler);
  return this;
};
/***
 *
 * @param {PSHandler} handler
 * @param {string} bf
 * @returns {this}
 */


PrintSerializer.prototype.addHandlerBefore = function (handler, bf) {
  var idx = this.handlers.findIndex(value => value.id === bf);

  if (idx >= 0) {
    this.handlers.splice(idx, 0, handler);
  }

  return this;
};
/***
 *
 * @param {PSHandler} handler
 * @param {string} at
 * @returns {this}
 */


PrintSerializer.prototype.addHandlerAfter = function (handler, at) {
  var idx = this.handlers.findIndex(value => value.id === at);

  if (idx >= 0) {
    this.handlers.splice(idx + 1, 0, handler);
  }

  return this;
};
/***
 *
 * @param {Array<PSHandler>} handlers
 * @returns {this}
 */


PrintSerializer.prototype.addHandlers = function (handlers) {
  this.handlers.unshift.apply(this.handlers, handlers);
  return this;
};
/***
 *
 * @param {string} id
 * @returns {this}
 */


PrintSerializer.prototype.removeHandler = function (id) {
  var idx = this.handlers.findIndex(value => value.id === id);

  if (idx >= 0) {
    this.handlers.splice(idx, 1);
  }

  return this;
};
/***
 *
 * @param {string} id
 * @returns {PSHandler|null}
 */


PrintSerializer.prototype.getHandler = function (id) {
  var idx = this.handlers.findIndex(value => value.id === id);

  if (idx >= 0) {
    return this.handlers[idx];
  }

  return null;
};

var _default = PrintSerializer;
exports.default = _default;

VaKeR 2022