import { getTokens } from "tamagui";
function rgbToRgba(token, opacity = 1) {
  let val = getTokens().color[token].val;
  val.startsWith("#") && (val = hexToRgb(val));
  const match = val.match(/\d+/g);
  if (!match) throw new Error("Invalid RGB format");
  const red = parseInt(match[0], 10),
    green = parseInt(match[1], 10),
    blue = parseInt(match[2], 10);
  if (opacity < 0 || opacity > 1) throw new Error("Opacity must be a value between 0 and 1");
  return `rgba(${red}, ${green}, ${blue}, ${opacity})`;
}
function convertRgbToRgba(rgb, opacity = 1) {
  const rgbValues = rgb.match(/\d+/g);
  if (rgbValues && rgbValues.length === 3) {
    const [r, g, b] = rgbValues.map(Number);
    return `rgba(${r}, ${g}, ${b}, ${opacity})`;
  } else return rgb;
}
function rgbToHex(rgb) {
  const result = rgb.match(/\d+/g);
  if (!result || result.length !== 3) throw new Error("Invalid RGB format");
  return `#${result.map(value => parseInt(value).toString(16).padStart(2, "0")).join("")}`;
}
function hexToRgb(hex) {
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  return `rgb(${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)})`;
}
export { convertRgbToRgba, hexToRgb, rgbToHex, rgbToRgba };
//# sourceMappingURL=color.mjs.map
