import { getValueTransition as S } from "../utils/get-value-transition.es.js";
import { resolveTransition as H } from "../utils/resolve-transition.es.js";
import { positionalKeys as B } from "../../render/utils/keys-position.es.js";
import { setTarget as I } from "../../render/utils/setters.es.js";
import { addValueToWillChange as P } from "../../value/will-change/add-will-change.es.js";
import { getOptimisedAppearId as R } from "../optimized-appear/get-appear-id.es.js";
import { animateMotionValue as k } from "./motion-value.es.js";
import { frame as d } from "../../frameloop/frame.es.js";
function x({ protectedKeys: t, needsAnimating: r }, a) {
  const s = t.hasOwnProperty(a) && r[a] !== !0;
  return r[a] = !1, s;
}
function z(t, r, { delay: a = 0, transitionOverride: s, type: m } = {}) {
  let { transition: n, transitionEnd: c, ...p } = r;
  const l = t.getDefaultTransition();
  n = n ? H(n, l) : l;
  const V = n == null ? void 0 : n.reduceMotion;
  s && (n = s);
  const f = [], T = m && t.animationState && t.animationState.getState()[m];
  for (const o in p) {
    const i = t.getValue(o, t.latestValues[o] ?? null), e = p[o];
    if (e === void 0 || T && x(T, o))
      continue;
    const u = {
      delay: a,
      ...S(n || {}, o)
    }, g = i.get();
    if (g !== void 0 && !i.isAnimating() && !Array.isArray(e) && e === g && !u.velocity) {
      d.update(() => i.set(e));
      continue;
    }
    let h = !1;
    if (window.MotionHandoffAnimation) {
      const y = R(t);
      if (y) {
        const A = window.MotionHandoffAnimation(y, o, d);
        A !== null && (u.startTime = A, h = !0);
      }
    }
    P(t, o);
    const w = V ?? t.shouldReduceMotion;
    i.start(k(o, i, e, w && B.has(o) ? { type: !1 } : u, t, h));
    const M = i.animation;
    M && f.push(M);
  }
  if (c) {
    const o = () => d.update(() => {
      c && I(t, c);
    });
    f.length ? Promise.all(f).then(o) : o();
  }
  return f;
}
export {
  z as animateTarget
};
//# sourceMappingURL=visual-element-target.es.js.map
