import { JSAnimation } from "./JSAnimation.js";
import { NativeAnimation } from "./NativeAnimation.js";
import { replaceTransitionType } from "./utils/replace-transition-type.js";
import { replaceStringEasing } from "./waapi/utils/unsupported-easing.js";
import { secondsToMilliseconds } from "../../../../motion-utils/dist/es/time-conversion.js";
const sampleDelta = 10;
class NativeAnimationExtended extends NativeAnimation {
  constructor(options) {
    replaceStringEasing(options);
    replaceTransitionType(options);
    super(options);
    if (options.startTime) {
      this.startTime = options.startTime;
    }
    this.options = options;
  }
  /**
   * WAAPI doesn't natively have any interruption capabilities.
   *
   * Rather than read commited styles back out of the DOM, we can
   * create a renderless JS animation and sample it twice to calculate
   * its current value, "previous" value, and therefore allow
   * Motion to calculate velocity for any subsequent animation.
   */
  updateMotionValue(value) {
    const { motionValue, onUpdate, onComplete, element, ...options } = this.options;
    if (!motionValue)
      return;
    if (value !== void 0) {
      motionValue.set(value);
      return;
    }
    const sampleAnimation = new JSAnimation({
      ...options,
      autoplay: false
    });
    const sampleTime = secondsToMilliseconds(this.finishedTime ?? this.time);
    motionValue.setWithVelocity(sampleAnimation.sample(sampleTime - sampleDelta).value, sampleAnimation.sample(sampleTime).value, sampleDelta);
    sampleAnimation.stop();
  }
}
export {
  NativeAnimationExtended
};
//# sourceMappingURL=NativeAnimationExtended.js.map
