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