"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const number = require("./dist-es-utils-mix-number.cjs");
const errors = require("../motion-utils/dist-es-errors.cjs");
const hslaToRgba = require("./dist-es-utils-hsla-to-rgba.cjs");
const hex = require("./dist-es-value-types-color-hex.cjs");
const rgba = require("./dist-es-value-types-color-rgba.cjs");
const hsla = require("./dist-es-value-types-color-hsla.cjs");
const immediate = require("./dist-es-utils-mix-immediate.cjs");
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.hex, rgba.rgba, hsla.hsla];
const getColorType = (v) => colorTypes.find((type) => type.test(v));
function asRGBA(color) {
  const type = getColorType(color);
  errors.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.hsla) {
    model = hslaToRgba.hslaToRgba(model);
  }
  return model;
}
const mixColor = (from, to) => {
  const fromRGBA = asRGBA(from);
  const toRGBA = asRGBA(to);
  if (!fromRGBA || !toRGBA) {
    return immediate.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 = number.mixNumber(fromRGBA.alpha, toRGBA.alpha, v);
    return rgba.rgba.transform(blended);
  };
};
exports.mixColor = mixColor;
exports.mixLinearColor = mixLinearColor;
//# sourceMappingURL=dist-es-utils-mix-color.cjs.map
