"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const maths = require("./maths.cjs");
function hexToRGB(hex) {
  const parts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
  if ((parts == null ? void 0 : parts.length) === 5) {
    if (parts[4]) {
      return {
        red: parseInt(parts[1], 16),
        green: parseInt(parts[2], 16),
        blue: parseInt(parts[3], 16),
        alpha: parseInt(parts[4], 16) / 255
      };
    }
    return {
      red: parseInt(parts[1], 16),
      green: parseInt(parts[2], 16),
      blue: parseInt(parts[3], 16)
    };
  }
  throw new Error(`${hex} was passed to hexToRGB but it doesn't look like a valid hex color`);
}
function colorToRGB(color) {
  switch (typeof color) {
    case "string": {
      return hexToRGB(color);
    }
    default:
      return color;
  }
}
const RGBComponentToHex = (component) => {
  const hex = Math.round(component).toString(16).toUpperCase();
  return hex.length === 1 ? `0${hex}` : hex;
};
function RGBToHex({ red, green, blue, alpha }) {
  return `#${RGBComponentToHex(red)}${RGBComponentToHex(green)}${RGBComponentToHex(blue)}${alpha ? RGBComponentToHex(Math.round(alpha * 255)) : ""}`;
}
function lerpRGB(startColor, endColor, progress) {
  return {
    red: Math.round(maths.lerp(startColor.red, endColor.red, progress)),
    green: Math.round(maths.lerp(startColor.green, endColor.green, progress)),
    blue: Math.round(maths.lerp(startColor.blue, endColor.blue, progress))
  };
}
function multiLerpRGB(colors, progress) {
  return {
    red: Math.round(maths.multiLerp(colors.map((color) => color.red), progress)),
    green: Math.round(maths.multiLerp(colors.map((color) => color.green), progress)),
    blue: Math.round(maths.multiLerp(colors.map((color) => color.blue), progress))
  };
}
function lerpHex(startColor, endColor, progress) {
  const rgbStartColor = hexToRGB(startColor);
  const rgbEndColor = hexToRGB(endColor);
  const rgbLerped = lerpRGB(rgbStartColor, rgbEndColor, progress);
  return RGBToHex(rgbLerped);
}
function multiLerpHex(colors, progress) {
  const rgbLerped = multiLerpRGB(colors.map((color) => hexToRGB(color)), progress);
  return RGBToHex(rgbLerped);
}
function colorToRGBCSString(color) {
  const rgb = colorToRGB(color);
  if (typeof rgb.alpha === "number") {
    return `rgba(${rgb.red}, ${rgb.green}, ${rgb.blue}, ${rgb.alpha})`;
  }
  return `rgb(${rgb.red}, ${rgb.green}, ${rgb.blue})`;
}
exports.RGBToHex = RGBToHex;
exports.colorToRGB = colorToRGB;
exports.colorToRGBCSString = colorToRGBCSString;
exports.hexToRGB = hexToRGB;
exports.lerpHex = lerpHex;
exports.lerpRGB = lerpRGB;
exports.multiLerpHex = multiLerpHex;
exports.multiLerpRGB = multiLerpRGB;
//# sourceMappingURL=color.cjs.map
