import c, { getFrameData as p } from "../../../../framesync/dist/es/index.es.js";
import { SubscriptionManager as s } from "../utils/subscription-manager.es.js";
import { velocityPerSecond as h } from "../../../../popmotion/dist/es/utils/velocity-per-second.es.js";
var f = function(e) {
  return !isNaN(parseFloat(e));
}, l = function() {
  function e(i) {
    var t = this;
    this.version = "6.4.3", this.timeDelta = 0, this.lastUpdated = 0, this.updateSubscribers = new s(), this.velocityUpdateSubscribers = new s(), this.renderSubscribers = new s(), this.canTrackVelocity = !1, this.updateAndNotify = function(r, n) {
      n === void 0 && (n = !0), t.prev = t.current, t.current = r;
      var o = p(), u = o.delta, a = o.timestamp;
      t.lastUpdated !== a && (t.timeDelta = u, t.lastUpdated = a, c.postRender(t.scheduleVelocityCheck)), t.prev !== t.current && t.updateSubscribers.notify(t.current), t.velocityUpdateSubscribers.getSize() && t.velocityUpdateSubscribers.notify(t.getVelocity()), n && t.renderSubscribers.notify(t.current);
    }, this.scheduleVelocityCheck = function() {
      return c.postRender(t.velocityCheck);
    }, this.velocityCheck = function(r) {
      var n = r.timestamp;
      n !== t.lastUpdated && (t.prev = t.current, t.velocityUpdateSubscribers.notify(t.getVelocity()));
    }, this.hasAnimated = !1, this.prev = this.current = i, this.canTrackVelocity = f(this.current);
  }
  return e.prototype.onChange = function(i) {
    return this.updateSubscribers.add(i);
  }, e.prototype.clearListeners = function() {
    this.updateSubscribers.clear();
  }, e.prototype.onRenderRequest = function(i) {
    return i(this.get()), this.renderSubscribers.add(i);
  }, e.prototype.attach = function(i) {
    this.passiveEffect = i;
  }, e.prototype.set = function(i, t) {
    t === void 0 && (t = !0), !t || !this.passiveEffect ? this.updateAndNotify(i, t) : this.passiveEffect(i, this.updateAndNotify);
  }, e.prototype.get = function() {
    return this.current;
  }, e.prototype.getPrevious = function() {
    return this.prev;
  }, e.prototype.getVelocity = function() {
    return this.canTrackVelocity ? h(parseFloat(this.current) - parseFloat(this.prev), this.timeDelta) : 0;
  }, e.prototype.start = function(i) {
    var t = this;
    return this.stop(), new Promise(function(r) {
      t.hasAnimated = !0, t.stopAnimation = i(r);
    }).then(function() {
      return t.clearAnimation();
    });
  }, e.prototype.stop = function() {
    this.stopAnimation && this.stopAnimation(), this.clearAnimation();
  }, e.prototype.isAnimating = function() {
    return !!this.stopAnimation;
  }, e.prototype.clearAnimation = function() {
    this.stopAnimation = null;
  }, e.prototype.destroy = function() {
    this.updateSubscribers.clear(), this.renderSubscribers.clear(), this.stop();
  }, e;
}();
function b(e) {
  return new l(e);
}
export {
  l as MotionValue,
  b as motionValue
};
//# sourceMappingURL=index.es.js.map
