/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var camelCase = require('lodash/camelCase');

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

var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);

function omit(obj, fields) {
  const shallowCopy = {
    ...obj
  };
  for (let i = 0; i < fields.length; i++) {
    const key = fields[i];
    delete shallowCopy[key];
  }
  return shallowCopy;
}
function removeEmptyAttrs(obj) {
  const newObj = {};
  Object.keys(obj).forEach(key => {
    if (typeof obj[key] !== "undefined" || obj[key] === null) newObj[key] = obj[key];
  });
  return newObj;
}
function getTabElementByValue(value) {
  let tabs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  const [result] = tabs.filter(item => {
    const {
      id
    } = item;
    return id === value;
  });
  return result || null;
}
function firstUpperCase(str) {
  return str.toLowerCase().replace(/( |^)[a-z]/g, char => char.toUpperCase());
}
function getBackgroundColor(color) {
  if (typeof color === "string") return color;
  if (Array.isArray(color)) {
    if (color[0] && color[0][0] === "#") color.unshift("90deg");
    return `linear-gradient( ${color.join(",")} )`;
  }
  const {
    from,
    to,
    direction = "to right",
    ...rest
  } = color;
  let keys = Object.keys(rest);
  if (keys.length) {
    keys = keys.sort((a, b) => parseFloat(a.substr(0, a.length - 1)) - parseFloat(b.substr(0, b.length - 1)));
    const tempArr = keys.map(key => `${rest[key]} ${key}`);
    return `linear-gradient(${direction}, ${tempArr.join(",")})`;
  }
  return `linear-gradient(${direction}, ${from}, ${to})`;
}
function getPropsApiByEvent(eventName) {
  return camelCase__default["default"](`on-${eventName}`);
}
function getIEVersion() {
  const {
    userAgent
  } = navigator;
  const isIE = userAgent.includes("compatible") && userAgent.includes("MSIE");
  const isIE11 = userAgent.includes("Trident") && userAgent.includes("rv:11.0");
  if (isIE) {
    const reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    const match = userAgent.match(reIE);
    if (!match) return -1;
    const fIEVersion = parseFloat(match[1]);
    return fIEVersion < 7 ? 6 : fIEVersion;
  }
  if (isIE11) {
    return 11;
  }
  return Number.MAX_SAFE_INTEGER;
}
function getCharacterLength(str, maxCharacter) {
  const hasMaxCharacter = typeof maxCharacter === "number";
  if (!str || str.length === 0) {
    if (hasMaxCharacter) {
      return {
        length: 0,
        characters: str
      };
    }
    return 0;
  }
  let len = 0;
  for (let i = 0; i < str.length; i++) {
    let 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 pxCompat(param) {
  return typeof param === "number" ? `${param}px` : param;
}
function getValidAttrs(obj) {
  const newObj = {};
  Object.keys(obj).forEach(key => {
    if (typeof obj[key] !== "undefined") newObj[key] = obj[key];
  });
  return newObj;
}
function setTransform(value) {
  return {
    transform: value,
    "-ms-transform": value,
    "-moz-transform": value,
    "-webkit-transform": value
  };
}

exports.firstUpperCase = firstUpperCase;
exports.getBackgroundColor = getBackgroundColor;
exports.getCharacterLength = getCharacterLength;
exports.getIEVersion = getIEVersion;
exports.getPropsApiByEvent = getPropsApiByEvent;
exports.getTabElementByValue = getTabElementByValue;
exports.getValidAttrs = getValidAttrs;
exports.omit = omit;
exports.pxCompat = pxCompat;
exports.removeEmptyAttrs = removeEmptyAttrs;
exports.setTransform = setTransform;
//# sourceMappingURL=helper.js.map
