import { warning as N } from "../../../../../hey-listen/dist/hey-listen.es.es.js";
import { clamp as g } from "../../utils/clamp.es.js";
const M = 1e-3, S = 0.01, m = 10, A = 0.05, G = 1;
function B({ duration: t = 800, bounce: p = 0.25, velocity: c = 0, mass: e = 1 }) {
  let a, f;
  N(t <= m * 1e3, "Spring duration must be 10 seconds or less");
  let s = 1 - p;
  s = g(A, G, s), t = g(S, m, t / 1e3), s < 1 ? (a = (n) => {
    const r = n * s, o = r * t, i = r - c, l = D(n, s), x = Math.exp(-o);
    return M - i / l * x;
  }, f = (n) => {
    const o = n * s * t, i = o * c + c, l = Math.pow(s, 2) * Math.pow(n, 2) * t, x = Math.exp(-o), b = D(Math.pow(n, 2), s);
    return (-a(n) + M > 0 ? -1 : 1) * ((i - l) * x) / b;
  }) : (a = (n) => {
    const r = Math.exp(-n * t), o = (n - c) * t + 1;
    return -M + r * o;
  }, f = (n) => {
    const r = Math.exp(-n * t), o = (c - n) * (t * t);
    return r * o;
  });
  const w = 5 / t, h = R(a, f, w);
  if (t = t * 1e3, isNaN(h))
    return {
      stiffness: 100,
      damping: 10,
      duration: t
    };
  {
    const n = Math.pow(h, 2) * e;
    return {
      stiffness: n,
      damping: s * 2 * Math.sqrt(e * n),
      duration: t
    };
  }
}
const I = 12;
function R(t, p, c) {
  let e = c;
  for (let a = 1; a < I; a++)
    e = e - t(e) / p(e);
  return e;
}
function D(t, p) {
  return t * Math.sqrt(1 - p * p);
}
export {
  D as calcAngularFreq,
  B as findSpring,
  G as maxDamping,
  m as maxDuration,
  A as minDamping,
  S as minDuration
};
//# sourceMappingURL=find-spring.es.js.map
