import { animate as N } from "./index.es.js";
import { velocityPerSecond as P } from "../utils/velocity-per-second.es.js";
import { getFrameData as U } from "../../../../framesync/dist/es/index.es.js";
function z({ from: u = 0, velocity: o = 0, min: t, max: d, power: c = 0.8, timeConstant: y = 750, bounceStiffness: A = 500, bounceDamping: B = 10, restDelta: l = 1, modifyTarget: s, driver: M, onUpdate: f, onComplete: S, onStop: k }) {
  let e;
  function p(n) {
    return t !== void 0 && n < t || d !== void 0 && n > d;
  }
  function b(n) {
    return t === void 0 ? d : d === void 0 || Math.abs(t - n) < Math.abs(d - n) ? t : d;
  }
  function g(n) {
    e == null || e.stop(), e = N(Object.assign(Object.assign({}, n), {
      driver: M,
      onUpdate: (i) => {
        var r;
        f == null || f(i), (r = n.onUpdate) === null || r === void 0 || r.call(n, i);
      },
      onComplete: S,
      onStop: k
    }));
  }
  function O(n) {
    g(Object.assign({ type: "spring", stiffness: A, damping: B, restDelta: l }, n));
  }
  if (p(u))
    O({ from: u, velocity: o, to: b(u) });
  else {
    let n = c * o + u;
    typeof s < "u" && (n = s(n));
    const i = b(n), r = i === t ? -1 : 1;
    let h, j;
    const F = (a) => {
      h = j, j = a, o = P(a - h, U().delta), (r === 1 && a > i || r === -1 && a < i) && O({ from: a, to: i, velocity: o });
    };
    g({
      type: "decay",
      from: u,
      velocity: o,
      timeConstant: y,
      power: c,
      restDelta: l,
      modifyTarget: s,
      onUpdate: p(n) ? F : void 0
    });
  }
  return {
    stop: () => e == null ? void 0 : e.stop()
  };
}
export {
  z as inertia
};
//# sourceMappingURL=inertia.es.js.map
