import { C as e } from "./base-PQGakkrl.js";
class l {
  startTime;
  startPos;
  endPos;
  duration;
  runEasing;
  runIngFun;
  lastPos;
  lastInterval;
  timeAnimate;
  constructor(t) {
    this.startTime = 0, this.startPos = 0, this.endPos = 0, this.duration = 0, this.runEasing = null, this.runIngFun = t.runIngCallback, this.lastPos = 0, this.lastInterval = 0;
  }
  _easing = {
    /**
     * t:动画已经消耗的时间
     * b:初始位置
     * c:目标位置
     * d:动画持续的总时间
    */
    linear: (t, s, i, n) => i * t / n + s,
    easeInCubic: (t, s, i, n) => i * (t /= n) * t * t + s,
    // eslint-disable-line
    easeOutCubic: (t, s, i, n) => i * ((t = t / n - 1) * t * t + 1) + s
    // eslint-disable-line
  };
  start(t, s, i, n = "linear") {
    const a = this;
    return new Promise((r) => {
      this.startTime = +/* @__PURE__ */ new Date(), this.startPos = t, this.endPos = s, this.duration = i, this.runEasing = a._easing[n], a.timeAnimate = e.requestAnimationFrame(function o() {
        a.step() === !1 ? (a.stop(), r(a.lastInterval)) : a.timeAnimate = e.requestAnimationFrame(o);
      });
    });
  }
  step() {
    const t = +/* @__PURE__ */ new Date();
    if (t >= this.startTime + this.duration)
      return this.runIngFun(this.endPos), !1;
    const s = this.runEasing(t - this.startTime, this.startPos, this.endPos - this.startPos, this.duration);
    return this.lastInterval = Math.abs(s - this.lastPos), this.lastPos = s, this.runIngFun(s), !0;
  }
  stop() {
    this.timeAnimate && e.cancelAnimationFrame(this.timeAnimate);
  }
}
export {
  l as A
};
//# sourceMappingURL=Tools_animateEasing-D0lY_Vn8.js.map
