"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.parseGradient = exports.parseContrastColor = exports.parseColor = void 0;
var _gradientParser = _interopRequireDefault(require("gradient-parser"));
var _color = _interopRequireDefault(require("color"));
var _constants = require("./constants");
var parseColor = fill => {
  if (typeof fill !== 'string') {
    return;
  }
  try {
    return (0, _color.default)(fill);
  } catch (_unused) {
    return;
  }
};
exports.parseColor = parseColor;
var parseGradient = fill => {
  if (typeof fill !== 'string') {
    return;
  }
  try {
    return _gradientParser.default.parse(fill);
  } catch (_unused2) {
    return;
  }
};
exports.parseGradient = parseGradient;
var parseContrastColor = fill => {
  var color = parseColor(fill);
  if (color) {
    return color.luminosity() > 0.5 ? _constants.COLOR_ICON_DARK : _constants.COLOR_ICON_LIGHT;
  }
  var gradients = parseGradient(fill);
  if (gradients) {
    var gradientList = gradients[0].colorStops.map(hex => (0, _color.default)("#".concat(hex.value)));
    var totalLights = gradientList.reduce((acc, curr) => {
      if (curr.luminosity() > 0.5) {
        return acc + 1;
      } else {
        return acc - 1;
      }
    }, 0);
    return totalLights >= 1 ? _constants.COLOR_ICON_DARK : _constants.COLOR_ICON_LIGHT;
  }
  return;
};
exports.parseContrastColor = parseContrastColor;
//# sourceMappingURL=utils.js.map