import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
var hexToRgb = function hexToRgb(color) {
  var fullReg = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  var full = color.replace(fullReg, function (_, r, g, b) {
    return "".concat(r).concat(r).concat(g).concat(g).concat(b).concat(b);
  });
  var values = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(full);
  if (!values) {
    throw new Error("Helpdice UI: Unsupported ".concat(color, " color."));
  }
  return [Number.parseInt(values[1], 16), Number.parseInt(values[2], 16), Number.parseInt(values[3], 16)];
};
export var colorToRgbValues = function colorToRgbValues(color) {
  if (color.charAt(0) === '#') return hexToRgb(color);
  var safeColor = color.replace(/ /g, '');
  var colorType = color.substr(0, 4);
  var regArray = safeColor.match(/\((.+)\)/);
  if (!colorType.startsWith('rgb') || !regArray) {
    console.log(color);
    throw new Error("Helpdice UI: Only support [\"RGB\", \"RGBA\", \"HEX\"] color.");
  }
  return regArray[1].split(',').map(function (str) {
    return Number.parseFloat(str);
  });
};
export var addColorAlpha = function addColorAlpha(color, alpha) {
  if (!/^#|rgb|RGB/.test(color)) return color;
  var _colorToRgbValues = colorToRgbValues(color),
    _colorToRgbValues2 = _slicedToArray(_colorToRgbValues, 3),
    r = _colorToRgbValues2[0],
    g = _colorToRgbValues2[1],
    b = _colorToRgbValues2[2];
  var safeAlpha = alpha > 1 ? 1 : alpha < 0 ? 0 : alpha;
  return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(safeAlpha, ")");
};