"use client";
import { getIntersectionKeys as T, mapObject as s } from "./util.js";
function g(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var i = Object.getOwnPropertySymbols(e);
    r && (i = i.filter(function(c) {
      return Object.getOwnPropertyDescriptor(e, c).enumerable;
    })), t.push.apply(t, i);
  }
  return t;
}
function u(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = arguments[r] != null ? arguments[r] : {};
    r % 2 ? g(Object(t), !0).forEach(function(i) {
      h(e, i, t[i]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : g(Object(t)).forEach(function(i) {
      Object.defineProperty(e, i, Object.getOwnPropertyDescriptor(t, i));
    });
  }
  return e;
}
function h(e, r, t) {
  return (r = w(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e;
}
function w(e) {
  var r = U(e, "string");
  return typeof r == "symbol" ? r : r + "";
}
function U(e, r) {
  if (typeof e != "object" || !e) return e;
  var t = e[Symbol.toPrimitive];
  if (t !== void 0) {
    var i = t.call(e, r);
    if (typeof i != "object") return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (r === "string" ? String : Number)(e);
}
var b = (e, r, t) => e + (r - e) * t, d = (e) => {
  var {
    from: r,
    to: t
  } = e;
  return r !== t;
}, P = (e, r, t) => {
  var i = s((c, n) => {
    if (d(n)) {
      var [a, p] = e(n.from, n.to, n.velocity);
      return u(u({}, n), {}, {
        from: a,
        velocity: p
      });
    }
    return n;
  }, r);
  return t < 1 ? s((c, n) => d(n) ? u(u({}, n), {}, {
    velocity: b(n.velocity, i[c].velocity, t),
    from: b(n.from, i[c].from, t)
  }) : n, r) : P(e, i, t - 1);
};
function D(e, r, t, i, c, n) {
  var a, p = i.reduce((o, f) => u(u({}, o), {}, {
    [f]: {
      from: e[f],
      velocity: 0,
      to: r[f]
    }
  }), {}), l = () => s((o, f) => f.from, p), m = () => !Object.values(p).filter(d).length, y = null, v = (o) => {
    a || (a = o);
    var f = o - a, O = f / t.dt;
    p = P(t, p, O), c(u(u(u({}, e), r), l())), a = o, m() || (y = n.setTimeout(v));
  };
  return () => (y = n.setTimeout(v), () => {
    y();
  });
}
function K(e, r, t, i, c, n, a) {
  var p = null, l = c.reduce((v, o) => u(u({}, v), {}, {
    [o]: [e[o], r[o]]
  }), {}), m, y = (v) => {
    m || (m = v);
    var o = (v - m) / i, f = s((S, j) => b(...j, t(o)), l);
    if (n(u(u(u({}, e), r), f)), o < 1)
      p = a.setTimeout(y);
    else {
      var O = s((S, j) => b(...j, t(1)), l);
      n(u(u(u({}, e), r), O));
    }
  };
  return () => (p = a.setTimeout(y), () => {
    p();
  });
}
const A = (e, r, t, i, c, n) => {
  var a = T(e, r);
  return t.isStepper === !0 ? D(e, r, t, a, c, n) : K(e, r, t, i, a, c, n);
};
export {
  b as alpha,
  A as default
};
