import { progress as c } from "./progress.es.js";
import { mix as a } from "./mix.es.js";
import { mixColor as x } from "./mix-color.es.js";
import { mixComplex as g, mixArray as h, mixObject as y } from "./mix-complex.es.js";
import { clamp as p } from "./clamp.es.js";
import { pipe as b } from "./pipe.es.js";
import { invariant as l } from "../../../../hey-listen/dist/hey-listen.es.es.js";
import { color as d } from "../../../../style-value-types/dist/es/color/index.es.js";
const A = (r, e) => (i) => a(r, e, i);
function u(r) {
  if (typeof r == "number")
    return A;
  if (typeof r == "string")
    return d.test(r) ? x : g;
  if (Array.isArray(r))
    return h;
  if (typeof r == "object")
    return y;
}
function I(r, e, i) {
  const t = [], f = i || u(r[0]), n = r.length - 1;
  for (let o = 0; o < n; o++) {
    let m = f(r[o], r[o + 1]);
    if (e) {
      const s = Array.isArray(e) ? e[o] : e;
      m = b(s, m);
    }
    t.push(m);
  }
  return t;
}
function M([r, e], [i]) {
  return (t) => i(c(r, e, t));
}
function F(r, e) {
  const i = r.length, t = i - 1;
  return (f) => {
    let n = 0, o = !1;
    if (f <= r[0] ? o = !0 : f >= r[t] && (n = t - 1, o = !0), !o) {
      let s = 1;
      for (; s < i && !(r[s] > f || s === t); s++)
        ;
      n = s - 1;
    }
    const m = c(r[n], r[n + 1], f);
    return e[n](m);
  };
}
function R(r, e, { clamp: i = !0, ease: t, mixer: f } = {}) {
  const n = r.length;
  l(n === e.length, "Both input and output ranges must be the same length"), l(!t || !Array.isArray(t) || t.length === n - 1, "Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values."), r[0] > r[n - 1] && (r = [].concat(r), e = [].concat(e), r.reverse(), e.reverse());
  const o = I(e, t, f), m = n === 2 ? M(r, o) : F(r, o);
  return i ? (s) => m(p(r[0], r[n - 1], s)) : m;
}
export {
  R as interpolate
};
//# sourceMappingURL=interpolate.es.js.map
