function getCssVariableValue(element, name) {
  return getComputedStyle(element).getPropertyValue(name).trim();
}
function getChartColorsOrDefault(element, customColors, defaultColorVars) {
  if (customColors.length > 0) {
    return customColors;
  }
  return defaultColorVars.map(
    (colorVar) => getCssVariableValue(element, colorVar)
  );
}
function applyAlphaToColor(element, color, alpha = 0.5) {
  if (!color || typeof color !== "string") return "rgba(0, 0, 0, 0)";
  let c = color.trim();
  if (c.startsWith("var(")) {
    const inner = c.replace(/^var\(/, "").replace(/\)$/, "").trim();
    if (inner.startsWith("--")) {
      const resolved = getCssVariableValue(element, inner);
      if (resolved) c = resolved.trim();
    }
  } else if (c.startsWith("--")) {
    const resolved = getCssVariableValue(element, c);
    if (resolved) c = resolved.trim();
  }
  if (c.startsWith("#")) {
    const hex = c.slice(1);
    if (hex.length === 3) {
      const r = parseInt(hex[0] + hex[0], 16);
      const g = parseInt(hex[1] + hex[1], 16);
      const b = parseInt(hex[2] + hex[2], 16);
      return `rgba(${r}, ${g}, ${b}, ${alpha})`;
    }
    if (hex.length === 6) {
      const r = parseInt(hex.slice(0, 2), 16);
      const g = parseInt(hex.slice(2, 4), 16);
      const b = parseInt(hex.slice(4, 6), 16);
      return `rgba(${r}, ${g}, ${b}, ${alpha})`;
    }
  }
  const rgbMatch = c.match(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
  if (rgbMatch) {
    const r = parseInt(rgbMatch[1], 10);
    const g = parseInt(rgbMatch[2], 10);
    const b = parseInt(rgbMatch[3], 10);
    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
  }
  return c;
}
export {
  applyAlphaToColor,
  getChartColorsOrDefault,
  getCssVariableValue
};
//# sourceMappingURL=colors.js.map
