import { hex } from "../../value/types/color/hex.js";
import { hsla } from "../../value/types/color/hsla.js";
import { hslaToRgba } from "../../value/types/color/hsla-to-rgba.js";
import { rgba } from "../../value/types/color/rgba.js";
import { mixImmediate } from "./immediate.js";
import { mixNumber } from "./number.js";
import { warning } from "../../../../../motion-utils/dist/es/errors.js";
const mixLinearColor = (from, to, v) => {
  const fromExpo = from * from;
  const expo = v * (to * to - fromExpo) + fromExpo;
  return expo < 0 ? 0 : Math.sqrt(expo);
};
const colorTypes = [hex, rgba, hsla];
const getColorType = (v) => colorTypes.find((type) => type.test(v));
function asRGBA(color) {
  const type = getColorType(color);
  warning(Boolean(type), `'${color}' is not an animatable color. Use the equivalent color code instead.`);
  if (!Boolean(type))
    return false;
  let model = type.parse(color);
  if (type === hsla) {
    model = hslaToRgba(model);
  }
  return model;
}
const mixColor = (from, to) => {
  const fromRGBA = asRGBA(from);
  const toRGBA = asRGBA(to);
  if (!fromRGBA || !toRGBA) {
    return mixImmediate(from, to);
  }
  const blended = { ...fromRGBA };
  return (v) => {
    blended.red = mixLinearColor(fromRGBA.red, toRGBA.red, v);
    blended.green = mixLinearColor(fromRGBA.green, toRGBA.green, v);
    blended.blue = mixLinearColor(fromRGBA.blue, toRGBA.blue, v);
    blended.alpha = mixNumber(fromRGBA.alpha, toRGBA.alpha, v);
    return rgba.transform(blended);
  };
};
export {
  mixColor,
  mixLinearColor
};
//# sourceMappingURL=color.js.map
