import { springDefaults as n } from "./defaults.js";
import { warning as u } from "../../../../../../motion-utils/dist/es/errors.js";
import { secondsToMilliseconds as h, millisecondsToSeconds as N } from "../../../../../../motion-utils/dist/es/time-conversion.js";
import { clamp as D } from "../../../../../../motion-utils/dist/es/clamp.js";
const M = 1e-3;
function v({ duration: t = n.duration, bounce: p = n.bounce, velocity: a = n.velocity, mass: e = n.mass }) {
  let i, f;
  u(t <= h(n.maxDuration), "Spring duration must be 10 seconds or less");
  let o = 1 - p;
  o = D(n.minDamping, n.maxDamping, o), t = D(n.minDuration, n.maxDuration, N(t)), o < 1 ? (i = (s) => {
    const r = s * o, c = r * t, l = r - a, m = b(s, o), x = Math.exp(-c);
    return M - l / m * x;
  }, f = (s) => {
    const c = s * o * t, l = c * a + a, m = Math.pow(o, 2) * Math.pow(s, 2) * t, x = Math.exp(-c), S = b(Math.pow(s, 2), o);
    return (-i(s) + M > 0 ? -1 : 1) * ((l - m) * x) / S;
  }) : (i = (s) => {
    const r = Math.exp(-s * t), c = (s - a) * t + 1;
    return -M + r * c;
  }, f = (s) => {
    const r = Math.exp(-s * t), c = (a - s) * (t * t);
    return r * c;
  });
  const w = 5 / t, g = A(i, f, w);
  if (t = h(t), isNaN(g))
    return {
      stiffness: n.stiffness,
      damping: n.damping,
      duration: t
    };
  {
    const s = Math.pow(g, 2) * e;
    return {
      stiffness: s,
      damping: o * 2 * Math.sqrt(e * s),
      duration: t
    };
  }
}
const T = 12;
function A(t, p, a) {
  let e = a;
  for (let i = 1; i < T; i++)
    e = e - t(e) / p(e);
  return e;
}
function b(t, p) {
  return t * Math.sqrt(1 - p * p);
}
export {
  b as calcAngularFreq,
  v as findSpring
};
//# sourceMappingURL=find.js.map
