import { mix as h } from "./mix/index.es.js";
import { invariant as x } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/errors.es.js";
import { clamp as M } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/clamp.es.js";
import { MotionGlobalConfig as b } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/global-config.es.js";
import { noop as y } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/noop.es.js";
import { pipe as A } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/pipe.es.js";
import { progress as F } from "../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/progress.es.js";
function R(r, e, f) {
  const t = [], a = f || b.mix || h, n = r.length - 1;
  for (let o = 0; o < n; o++) {
    let i = a(r[o], r[o + 1]);
    if (e) {
      const c = Array.isArray(e) ? e[o] || y : e;
      i = A(c, i);
    }
    t.push(i);
  }
  return t;
}
function I(r, e, { clamp: f = !0, ease: t, mixer: a } = {}) {
  const n = r.length;
  if (x(n === e.length, "Both input and output ranges must be the same length", "range-length"), n === 1)
    return () => e[0];
  if (n === 2 && e[0] === e[1])
    return () => e[1];
  const o = r[0] === r[1];
  r[0] > r[n - 1] && (r = [...r].reverse(), e = [...e].reverse());
  const i = R(e, t, a), c = i.length, l = (s) => {
    if (o && s < r[0])
      return e[0];
    let m = 0;
    if (c > 1)
      for (; m < r.length - 2 && !(s < r[m + 1]); m++)
        ;
    const g = F(r[m], r[m + 1], s);
    return i[m](g);
  };
  return f ? (s) => l(M(r[0], r[n - 1], s)) : l;
}
export {
  I as interpolate
};
//# sourceMappingURL=interpolate.es.js.map
