import { __rest as O } from "../../../../../tslib/tslib.es6.es.js";
import { findSpring as T, calcAngularFreq as j } from "../utils/find-spring.es.js";
const R = ["duration", "bounce"], V = ["stiffness", "damping", "mass"];
function y(i, n) {
  return n.some((o) => i[o] !== void 0);
}
function A(i) {
  let n = Object.assign({ velocity: 0, stiffness: 100, damping: 10, mass: 1, isResolvedFromDuration: !1 }, i);
  if (!y(i, V) && y(i, R)) {
    const o = T(i);
    n = Object.assign(Object.assign(Object.assign({}, n), o), { velocity: 0, mass: 1 }), n.isResolvedFromDuration = !0;
  }
  return n;
}
function w(i) {
  var { from: n = 0, to: o = 1, restSpeed: q = 2, restDelta: f } = i, F = O(i, ["from", "to", "restSpeed", "restDelta"]);
  const p = { done: !1, value: n };
  let { stiffness: h, damping: D, mass: g, velocity: d, duration: S, isResolvedFromDuration: x } = A(F), u = b, m = b;
  function M() {
    const c = d ? -(d / 1e3) : 0, r = o - n, t = D / (2 * Math.sqrt(h * g)), s = Math.sqrt(h / g) / 1e3;
    if (f === void 0 && (f = Math.min(Math.abs(o - n) / 100, 0.4)), t < 1) {
      const e = j(s, t);
      u = (a) => {
        const l = Math.exp(-t * s * a);
        return o - l * ((c + t * s * r) / e * Math.sin(e * a) + r * Math.cos(e * a));
      }, m = (a) => {
        const l = Math.exp(-t * s * a);
        return t * s * l * (Math.sin(e * a) * (c + t * s * r) / e + r * Math.cos(e * a)) - l * (Math.cos(e * a) * (c + t * s * r) - e * r * Math.sin(e * a));
      };
    } else if (t === 1)
      u = (e) => o - Math.exp(-s * e) * (r + (c + s * r) * e);
    else {
      const e = s * Math.sqrt(t * t - 1);
      u = (a) => {
        const l = Math.exp(-t * s * a), v = Math.min(e * a, 300);
        return o - l * ((c + t * s * r) * Math.sinh(v) + e * r * Math.cosh(v)) / e;
      };
    }
  }
  return M(), {
    next: (c) => {
      const r = u(c);
      if (x)
        p.done = c >= S;
      else {
        const t = m(c) * 1e3, s = Math.abs(t) <= q, e = Math.abs(o - r) <= f;
        p.done = s && e;
      }
      return p.value = p.done ? o : r, p;
    },
    flipTarget: () => {
      d = -d, [n, o] = [o, n], M();
    }
  };
}
w.needsInterpolation = (i, n) => typeof i == "string" || typeof n == "string";
const b = (i) => 0;
export {
  w as spring
};
//# sourceMappingURL=spring.es.js.map
