/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isString from 'lodash/isString';
import isNull from 'lodash/isNull';
import isUndefined from 'lodash/isUndefined';
import isNumber from 'lodash/isNumber';
import isArray from 'lodash/isArray';

var _excluded = ["from", "to", "direction"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function omit(obj, fields) {
  var shallowCopy = _objectSpread({}, obj);
  for (var i = 0; i < fields.length; i++) {
    var key = fields[i];
    delete shallowCopy[key];
  }
  return shallowCopy;
}
function removeEmptyAttrs(obj) {
  var newObj = {};
  Object.keys(obj).forEach(function (key) {
    if (!isUndefined(obj[key]) || isNull(obj[key])) newObj[key] = obj[key];
  });
  return newObj;
}
function getTabElementByValue() {
  var tabs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var value = arguments.length > 1 ? arguments[1] : undefined;
  var _tabs$filter = tabs.filter(function (item) {
      var id = item.id;
      return id === value;
    }),
    _tabs$filter2 = _slicedToArray(_tabs$filter, 1),
    result = _tabs$filter2[0];
  return result || null;
}
function firstUpperCase(str) {
  return str.toLowerCase().replace(/( |^)[a-z]/g, function (_char) {
    return _char.toUpperCase();
  });
}
function getBackgroundColor(color) {
  if (isString(color)) return color;
  if (isArray(color)) {
    if (color[0] && color[0][0] === "#") color.unshift("90deg");
    return "linear-gradient( ".concat(color.join(","), " )");
  }
  var from = color.from,
    to = color.to,
    _color$direction = color.direction,
    direction = _color$direction === void 0 ? "to right" : _color$direction,
    rest = _objectWithoutProperties(color, _excluded);
  var keys = Object.keys(rest);
  if (keys.length) {
    keys = keys.sort(function (a, b) {
      var c = parseFloat(a.substr(0, a.length - 1)) - parseFloat(b.substr(0, b.length - 1));
      return c;
    });
    var tempArr = keys.map(function (key) {
      return "".concat(rest[key], " ").concat(key);
    });
    return "linear-gradient(".concat(direction, ", ").concat(tempArr.join(","), ")");
  }
  return "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")");
}
function getIEVersion() {
  if (typeof navigator === "undefined" || !navigator) return Number.MAX_SAFE_INTEGER;
  var _navigator = navigator,
    userAgent = _navigator.userAgent;
  var isIE = userAgent.includes("compatible") && userAgent.includes("MSIE");
  var isIE11 = userAgent.includes("Trident") && userAgent.includes("rv:11.0");
  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 getCharacterLength(str, maxCharacter) {
  var hasMaxCharacter = isNumber(maxCharacter);
  if (!str || str.length === 0) {
    if (hasMaxCharacter) {
      return {
        length: 0,
        characters: str
      };
    }
    return 0;
  }
  var len = 0;
  for (var i = 0; i < str.length; i++) {
    var currentStringLength = 0;
    if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) currentStringLength = 2;else currentStringLength = 1;
    if (hasMaxCharacter && len + currentStringLength > maxCharacter) {
      return {
        length: len,
        characters: str.slice(0, i)
      };
    }
    len += currentStringLength;
  }
  if (hasMaxCharacter) {
    return {
      length: len,
      characters: str
    };
  }
  return len;
}
function getUnicodeLength(str) {
  return _toConsumableArray(str !== null && str !== void 0 ? str : "").length;
}
function limitUnicodeMaxLength(str, maxLength, oldStr) {
  if (_toConsumableArray(oldStr !== null && oldStr !== void 0 ? oldStr : "").slice().length === maxLength) return oldStr || "";
  return _toConsumableArray(str !== null && str !== void 0 ? str : "").slice(0, maxLength).join("");
}
function pxCompat(param) {
  return isNumber(param) ? "".concat(param, "px") : param;
}
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) {
  if (typeof window === "undefined") {
    return {
      paddingSize: 0,
      borderSize: 0,
      boxSizing: 0,
      sizingStyle: ""
    };
  }
  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
  };
}

export { calculateNodeSize, firstUpperCase, getBackgroundColor, getCharacterLength, getIEVersion, getTabElementByValue, getUnicodeLength, limitUnicodeMaxLength, omit, pxCompat, removeEmptyAttrs };
//# sourceMappingURL=helper.js.map
