/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);

function getIEVersion() {
  var _navigator = navigator,
      userAgent = _navigator.userAgent;
  var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
  var isIE11 = userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;

  if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    var match = userAgent.match(reIE);
    if (!match) return -1;
    var fIEVersion = parseFloat(match[1]);
    return fIEVersion < 7 ? 6 : fIEVersion;
  }

  if (isIE11) {
    return 11;
  }

  return Number.MAX_SAFE_INTEGER;
}

function getUnicodeLength(str) {
  return _toConsumableArray__default["default"](str !== null && str !== void 0 ? str : "").length;
}

function limitUnicodeMaxLength(str, maxLength) {
  return _toConsumableArray__default["default"](str !== null && str !== void 0 ? str : "").slice(0, maxLength).join("");
}

var DOM_STYLE_PROPS = ["padding-top", "padding-bottom", "padding-left", "padding-right", "font-family", "font-weight", "font-size", "font-variant", "text-rendering", "text-transform", "width", "text-indent", "border-width", "box-sizing", "line-height", "letter-spacing"];

function calculateNodeSize(targetElement) {
  var style = window.getComputedStyle(targetElement);
  var boxSizing = style.getPropertyValue("box-sizing") || style.getPropertyValue("-moz-box-sizing") || style.getPropertyValue("-webkit-box-sizing");
  var paddingSize = parseFloat(style.getPropertyValue("padding-bottom")) + parseFloat(style.getPropertyValue("padding-top"));
  var borderSize = parseFloat(style.getPropertyValue("border-bottom-width")) + parseFloat(style.getPropertyValue("border-top-width"));
  var sizingStyle = DOM_STYLE_PROPS.map(function (name) {
    return "".concat(name, ":").concat(style.getPropertyValue(name));
  }).join(";");
  return {
    paddingSize: paddingSize,
    borderSize: borderSize,
    boxSizing: boxSizing,
    sizingStyle: sizingStyle
  };
}

exports.calculateNodeSize = calculateNodeSize;
exports.getIEVersion = getIEVersion;
exports.getUnicodeLength = getUnicodeLength;
exports.limitUnicodeMaxLength = limitUnicodeMaxLength;
//# sourceMappingURL=helper2.js.map
