import { spring as L } from "./spring.es.js";
import { getGeneratorVelocity as R } from "./utils/velocity.es.js";
function $({ keyframes: v, velocity: B = 0, power: M = 0.8, timeConstant: b = 325, bounceDamping: k = 10, bounceStiffness: F = 500, modifyTarget: l, min: t, max: a, restDelta: f = 0.5, restSpeed: O }) {
  const s = v[0], n = {
    done: !1,
    value: s
  }, C = (e) => t !== void 0 && e < t || a !== void 0 && e > a, D = (e) => t === void 0 ? a : a === void 0 || Math.abs(t - e) < Math.abs(a - e) ? t : a;
  let d = M * B;
  const i = s + d, u = l === void 0 ? i : l(i);
  u !== i && (d = u - s);
  const p = (e) => -d * Math.exp(-e / b), h = (e) => u + p(e), y = (e) => {
    const o = p(e), G = h(e);
    n.done = Math.abs(o) <= f, n.value = n.done ? u : G;
  };
  let r, c;
  const g = (e) => {
    C(n.value) && (r = e, c = L({
      keyframes: [n.value, D(n.value)],
      velocity: R(h, e, n.value),
      // TODO: This should be passing * 1000
      damping: k,
      stiffness: F,
      restDelta: f,
      restSpeed: O
    }));
  };
  return g(0), {
    calculatedDuration: null,
    next: (e) => {
      let o = !1;
      return !c && r === void 0 && (o = !0, y(e), g(e)), r !== void 0 && e >= r ? c.next(e - r) : (!o && y(e), n);
    }
  };
}
export {
  $ as inertia
};
//# sourceMappingURL=inertia.es.js.map
