import { AsyncMotionValueAnimation as A } from "../AsyncMotionValueAnimation.es.js";
import { JSAnimation as k } from "../JSAnimation.es.js";
import { getValueTransition as D } from "../utils/get-value-transition.es.js";
import { makeAnimationInstant as d } from "../utils/make-animation-instant.es.js";
import { getDefaultTransition as g } from "../utils/default-transitions.es.js";
import { getFinalKeyframe as C } from "../keyframes/get-final.es.js";
import { isTransitionDefined as T } from "../utils/is-transition-defined.es.js";
import { frame as V } from "../../frameloop/frame.es.js";
import { secondsToMilliseconds as l } from "../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/time-conversion.es.js";
import { MotionGlobalConfig as y } from "../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/global-config.es.js";
const x = (a, t, r, m = {}, n, p) => (u) => {
  const o = D(m, a) || {}, c = o.delay || m.delay || 0;
  let { elapsed: s = 0 } = m;
  s = s - l(c);
  const e = {
    keyframes: Array.isArray(r) ? r : [null, r],
    ease: "easeOut",
    velocity: t.getVelocity(),
    ...o,
    delay: -s,
    onUpdate: (i) => {
      t.set(i), o.onUpdate && o.onUpdate(i);
    },
    onComplete: () => {
      u(), o.onComplete && o.onComplete();
    },
    name: a,
    motionValue: t,
    element: p ? void 0 : n
  };
  T(o) || Object.assign(e, g(a, e)), e.duration && (e.duration = l(e.duration)), e.repeatDelay && (e.repeatDelay = l(e.repeatDelay)), e.from !== void 0 && (e.keyframes[0] = e.from);
  let f = !1;
  if ((e.type === !1 || e.duration === 0 && !e.repeatDelay) && (d(e), e.delay === 0 && (f = !0)), (y.instantAnimations || y.skipAnimations || n != null && n.shouldSkipAnimations) && (f = !0, d(e), e.delay = 0), e.allowFlatten = !o.type && !o.ease, f && !p && t.get() !== void 0) {
    const i = C(e.keyframes, o);
    if (i !== void 0) {
      V.update(() => {
        e.onUpdate(i), e.onComplete();
      });
      return;
    }
  }
  return o.isSync ? new k(e) : new A(e);
};
export {
  x as animateMotionValue
};
//# sourceMappingURL=motion-value.es.js.map
