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__HTML5__Svg.js
/*** module: node_modules/absol/src/HTML5/Svg.js ***/
"use strict";

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

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

var _ElementNS = _interopRequireDefault(require("./ElementNS"));

var _AElement = _interopRequireDefault(require("./AElement"));

var _Color = _interopRequireDefault(require("../Color/Color"));

var _AttachHook = _interopRequireDefault(require("./AttachHook"));

var _OOP = _interopRequireDefault(require("./OOP"));




/***
 * @extends Dom
 * @param option
 * @constructor
 */
function Svg(option) {
  _Dom.default.call(this, option);

  this.svgNS = "http://www.w3.org/2000/svg";
  Object.defineProperties(this.creator, {
    sattachhook: {
      set: function () {//do nothing
      },
      get: function () {
        return _AttachHook.default;
      }
    }
  });
  delete this.buidDom;
  this.buildSvg = this.create.bind(this);
}

_OOP.default.mixClass(Svg, _Dom.default);

Svg.prototype.defaultTag = 'g';

Svg.prototype.fromCode = function (code) {
  code = code.trim();
  var receptacle = document.createElement('div');
  var element;
  var prototypes;

  if (code.startsWith('<svg')) {
    receptacle.innerHTML = code;
    element = receptacle.childNodes[0];
    prototypes = Object.getOwnPropertyDescriptors(_AElement.default.prototype);
    Object.defineProperties(element, prototypes);

    _AElement.default.call(element);
  } else {
    var svgfragment = '<svg  version="1.1" xmlns="http://www.w3.org/2000/svg">' + code + '</svg>';
    receptacle.innerHTML = '' + svgfragment;
    element = receptacle.childNodes[0].childNodes[0];
    prototypes = Object.getOwnPropertyDescriptors(_ElementNS.default.prototype);
    Object.defineProperties(element, prototypes);

    _ElementNS.default.call(element);
  }

  return element;
};

Svg.prototype.makeNewElement = function (tagName) {
  return document.createElementNS(this.svgNS, tagName);
};

Svg.ShareInstance = new Svg();

Svg.svgToCanvas = function (element) {
  if (typeof element == 'string') {
    element = _Dom.default.ShareInstance.$(element);
  }

  if (element && element.tagName == 'svg') {
    var depthClone = function (originElt) {
      var newElt = originElt.cloneNode(); //no deep

      if (!originElt.getAttributeNS) return newElt; //is text node

      var style = getComputedStyle(originElt);
      var key, value;

      for (var i = 0; i < style.length; ++i) {
        key = style[i];
        value = style.getPropertyValue(key);

        if (value && value.length > 0 && value !== 'auto') {
          newElt.style.setProperty(key, value);
        }
      }

      var children = Array.prototype.map.call(originElt.childNodes, depthClone);

      for (var i = 0; i < children.length; ++i) {
        newElt.appendChild(children[i]);
      }

      return newElt;
    };

    var cloneElement = depthClone(element);

    var renderSpace = _Dom.default.ShareInstance._({
      style: {
        // opacity:0,
        zIndex: -1000,
        position: 'fixed',
        top: 0,
        bottom: 0
      }
    }).addTo(document.body);

    renderSpace.addChild(cloneElement);
    var svgCode = renderSpace.innerHTML;
    renderSpace.clearChild();
    var mBlob = new Blob([svgCode], {
      type: "image/svg+xml;charset=utf-8"
    });
    var src = (URL || webkitURL).createObjectURL(mBlob);

    var image = _Dom.default.ShareInstance._('img');

    image.attr('src', src).addTo(renderSpace);
    var canvas = document.createElement("canvas");
    renderSpace.addChild(canvas);
    return _Dom.default.waitImageLoaded(image).then(function () {
      canvas.width = image.width;
      canvas.height = image.height;
      var context = canvas.getContext("2d");
      context.drawImage(image, 0, 0);
      renderSpace.selfRemove();
      return canvas;
    });
  } else {
    throw new Error('Element must be svg');
  }
};

function svgToRasterImageUrl(element) {
  return Svg.svgToCanvas(element).then(function (canvas) {
    return canvas.toDataURL();
  });
}

Svg.svgToRasterImageUrl = svgToRasterImageUrl;
/**
 *
 * @param {string|AElement}element
 * @param {"print"|null=} option
 * @returns {string}
 */

function svgToExportedString(element, option) {
  if (typeof element == 'string') {
    element = _Dom.default.ShareInstance.$(element);
  }

  if (element && element.tagName === 'svg') {
    var depthClone = function (originElt) {
      var newElt = originElt.cloneNode(); //no deep

      if (!originElt.getAttributeNS) return newElt; //is text node

      var cssRules = _AElement.default.prototype.getCSSRules.call(originElt);

      var cssKey = cssRules.reduce(function (ac, rule) {
        for (var i = 0; i < rule.style.length; ++i) {
          ac[rule.style[i]] = true;
        }

        return ac;
      }, {});

      for (var key in cssKey) {
        newElt.style[key] = _AElement.default.prototype.getComputedStyleValue.call(originElt, key);
      }

      var children = Array.prototype.map.call(originElt.childNodes, depthClone);

      for (var i = 0; i < children.length; ++i) {
        newElt.appendChild(children[i]);
      }

      return newElt;
    };

    var cloneElement = depthClone(element);

    var renderSpace = _Dom.default.ShareInstance._({
      style: {
        // opacity:0,
        zIndex: -1000,
        position: 'fixed',
        top: 0,
        bottom: 0
      }
    }).addTo(document.body);

    renderSpace.addChild(cloneElement);
    var svgCode = renderSpace.innerHTML;
    renderSpace.selfRemove();
    return svgCode;
  } else {
    throw new Error('Element must be svg');
  }
}

;
Svg.svgToExportedString = svgToExportedString;
/**
 *
 * @param element
 * @param {"print"|null=}option
 * @returns {string}
 */

function svgToSvgUrl(element, option) {
  var svg = svgToExportedString(element, option);
  svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + svg;
  var blob = new Blob([svg], {
    type: 'image/svg+xml'
  });
  var url = URL.createObjectURL(blob);
  return url;
}

Svg.svgToSvgUrl = svgToSvgUrl;
/***
 *
 * @param {AElement|String | {computeStyle?: boolean, elt: AElement, keepBackgroundColor?:boolean,convertSVG?:boolean}} option
 * @return {Promise<unknown>}
 */

_Dom.default.printElement = function (option) {
  var _ = _Dom.default.ShareInstance._;
  var $ = _Dom.default.ShareInstance.$;
  option = option || {};

  if (typeof option == 'string') {
    option = {
      elt: _Dom.default.ShareInstance.$(option)
    };
  } else if (typeof option.elt == 'string') {
    option.elt = $(option.elt);
  } else if (_Dom.default.isDomNode(option)) {
    option = {
      elt: option
    };
  }

  option = Object.assign({
    keepBackgroundColor: true,
    convertSVG: false,
    computeStyle: false
  }, option);

  if (_Dom.default.isDomNode(option.elt)) {
    function afterCloneCb(originElt, newElt) {
      if (!newElt.tagName) return;
      var tagName = newElt.tagName.toLowerCase();
      if (newElt.getBBox && tagName !== 'svg') return;
      var url, img;
      var needCopyStyle = option.computeStyle;
      var needKeepBackgroundColor = option.keepBackgroundColor;
      var printViewBox;

      if (tagName === 'canvas' || tagName === 'svg' && option.convertSVG) {
        if (tagName === "canvas") {
          url = originElt.toDataURL();
        } else {
          url = svgToSvgUrl(originElt, 'print'); //todo: option
        }

        img = _({
          tag: 'img',
          props: {
            src: url
          }
        });
        $(newElt).selfReplace(img);
        newElt = img;
        needCopyStyle = true;
      } else if (tagName === 'svg' && originElt.getAttribute('data-print-view-box')) {
        printViewBox = originElt.getAttribute('data-print-view-box').split(' ').map(function (v) {
          return parseFloat(v);
        });
        newElt.setAttribute('viewBox', printViewBox.join(' '));
        newElt.setAttribute('width', printViewBox[2]);
        newElt.setAttribute('height', printViewBox[3]);
        newElt.style.setProperty('width', printViewBox[2] + 'px');
        newElt.style.setProperty('height', printViewBox[3] + 'px');
      } else if (tagName === 'script') {
        newElt.remove();
      } else if (tagName === 'img') {
        newElt.setAttribute('src', originElt.src);
      } else if (tagName === 'input') {
        if (originElt.getAttribute('type') === 'radio' || originElt.getAttribute('type') === 'checkbox') {
          if (originElt.checked) {
            newElt.setAttribute('checked', true);
          }
        } else if (originElt.getAttribute('type') === 'text' || !originElt.getAttribute('type') || originElt.getAttribute('type') === 'number') {
          newElt.setAttribute('value', originElt.value);
        }
      }

      if (needCopyStyle) {
        (0, _Dom.copyStyleRule)(originElt, newElt);
      }

      if (needKeepBackgroundColor) {
        try {
          var bgColor = _AElement.default.prototype.getComputedStyleValue.call(originElt, 'background-color');

          if (bgColor) {
            bgColor = _Color.default.parse(bgColor);

            if (bgColor.rgba[3] > 0) {
              newElt.style.setProperty('background-color', bgColor.toString('hex8'), 'important');
            }
          }
        } catch (e) {}
      }

      return newElt;
    }

    var newElt = (0, _Dom.depthClone)(option.elt, afterCloneCb);

    var renderSpace = _({
      style: {
        position: 'fixed',
        top: '0',
        left: '0',
        right: '0',
        bottom: '0',
        overflow: 'auto',
        zIndex: '10',
        opacity: '0',
        visibility: 'hidden'
      }
    });

    $('link', document.head, function (elt) {
      var temp = elt.cloneNode(false); //copy absolute url

      temp.setAttribute('href', elt.href);
      renderSpace.addChild(temp);
    });

    if (!option.computeStyle) {
      $('style', document.head, function (elt) {
        if (elt == _Dom.default.$printStyle) return;
        renderSpace.addChild(elt.cloneNode(true));
      });
    }

    renderSpace.addChild(newElt);
    var eltCode = renderSpace.innerHTML;
    renderSpace.clearChild();
    option.title = option.title || ($('title', document.head) || {
      innerHTML: 'absol.js'
    }).innerHTML;
    var htmlCode = ['<ht' + 'ml>', ' <h' + 'ead><title>' + option.title + '</title><meta charset="UTF-8">', '<style>', option.overideStyle ? 'html, body{width:initial !important; height:initial !important; overflow: initial !important; overflow-x: initial !important;overflow-y: initial !important;  }' : '', '@media print {', //still not work
    '    body{', '      -webkit-print-color-adjust: exact;', '       color-adjust: exact;', '    } ', '    div, tr, td, table{', '    }', '  }', 'div, table, tr, td{', '    page-break-inside: initial;', '    page-break-before: avoid;', '    page-break-after: avoid;', '}', option.extendCss || '', '</style>', '</he' + 'ad>', '<bod' + 'y>', eltCode, '<scr' + 'ipt>' + (option.extendScript || '') + '</scri' + 'pt>', //browser parse  script tag fail
    '<scr' + 'ipt>setTimeout(function(){ window.print();},1000);</scri' + 'pt>', //browser parse  script tag fail
    '</bod' + 'y>', '</ht' + 'ml>'].join('\n');
    var blob = new Blob([htmlCode], {
      type: 'text/html; charset=UTF-8'
    });
    renderSpace.addTo(document.body);

    var iframe = _('iframe').attr('src', URL.createObjectURL(blob)).addStyle({
      width: '100%',
      height: '100%'
    }).addTo(renderSpace);

    return new Promise(function (rs, rj) {
      function waitLoad() {
        if (iframe.contentWindow && iframe.contentWindow.document && iframe.contentWindow.document.body) {
          if (typeof option.onLoad == 'function') option.onLoad();
          iframe.contentWindow.focus();
          setTimeout(function () {
            function waitFocusBack() {
              if (!document.hasFocus || document.hasFocus()) {
                renderSpace.remove();
                if (typeof option.onFinish == 'function') option.onFinish();
                rs();
              } else {
                setTimeout(waitFocusBack, 300);
              }
            }

            waitFocusBack();
          }, 4000);
        } else setTimeout(waitLoad, 1000);
      }

      waitLoad();
    });
  } else {
    throw new Error('Invalid param!');
  }
};

var _default = Svg;
exports.default = _default;

VaKeR 2022