import { mix } from "./mix.js";
import { invariant } from "../../../../../../hey-listen@1.0.8/node_modules/hey-listen/dist/hey-listen.es.js";
import { hslaToRgba } from "./hsla-to-rgba.js";
import { hsla } from "../../../../../../style-value-types@5.0.0/node_modules/style-value-types/dist/es/color/hsla.js";
import { rgba } from "../../../../../../style-value-types@5.0.0/node_modules/style-value-types/dist/es/color/rgba.js";
import { hex } from "../../../../../../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, rgba, 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);
  invariant(!!fromColorType, notAnimatable(from));
  invariant(!!toColorType, notAnimatable(to));
  let fromColor = fromColorType.parse(from);
  let toColor = toColorType.parse(to);
  if (fromColorType === hsla) {
    fromColor = hslaToRgba(fromColor);
    fromColorType = rgba;
  }
  if (toColorType === hsla) {
    toColor = hslaToRgba(toColor);
    toColorType = 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(fromColor.alpha, toColor.alpha, v);
    return fromColorType.transform(blended);
  };
};
export {
  mixColor,
  mixLinearColor
};
//# sourceMappingURL=mix-color.js.map
