"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const mix = require("./mix.js");
const heyListen_es = require("../../../../../../hey-listen@1.0.8/node_modules/hey-listen/dist/hey-listen.es.js");
const hslaToRgba = require("./hsla-to-rgba.js");
const hsla = require("../../../../../../style-value-types@5.0.0/node_modules/style-value-types/dist/es/color/hsla.js");
const rgba = require("../../../../../../style-value-types@5.0.0/node_modules/style-value-types/dist/es/color/rgba.js");
const hex = require("../../../../../../style-value-types@5.0.0/node_modules/style-value-types/dist/es/color/hex.js");
const mixLinearColor = (from, to, v) => {
  const fromExpo = from * from;
  const toExpo = to * to;
  return Math.sqrt(Math.max(0, v * (toExpo - fromExpo) + fromExpo));
};
const colorTypes = [hex.hex, rgba.rgba, hsla.hsla];
const getColorType = (v) => colorTypes.find((type) => type.test(v));
const notAnimatable = (color) => `'${color}' is not an animatable color. Use the equivalent color code instead.`;
const mixColor = (from, to) => {
  let fromColorType = getColorType(from);
  let toColorType = getColorType(to);
  heyListen_es.invariant(!!fromColorType, notAnimatable(from));
  heyListen_es.invariant(!!toColorType, notAnimatable(to));
  let fromColor = fromColorType.parse(from);
  let toColor = toColorType.parse(to);
  if (fromColorType === hsla.hsla) {
    fromColor = hslaToRgba.hslaToRgba(fromColor);
    fromColorType = rgba.rgba;
  }
  if (toColorType === hsla.hsla) {
    toColor = hslaToRgba.hslaToRgba(toColor);
    toColorType = rgba.rgba;
  }
  const blended = Object.assign({}, fromColor);
  return (v) => {
    for (const key in blended) {
      if (key !== "alpha") {
        blended[key] = mixLinearColor(fromColor[key], toColor[key], v);
      }
    }
    blended.alpha = mix.mix(fromColor.alpha, toColor.alpha, v);
    return fromColorType.transform(blended);
  };
};
exports.mixColor = mixColor;
exports.mixLinearColor = mixLinearColor;
//# sourceMappingURL=mix-color.js.map
