import { positionalKeys as c } from "../../render/utils/keys-position.es.js";
import { findDimensionValueType as h } from "../../value/types/dimensions.es.js";
import { getVariableValue as g } from "../utils/css-variables-conversion.es.js";
import { isCSSVariableToken as K, containsCSSVariable as p } from "../utils/is-css-variable.es.js";
import { KeyframeResolver as v } from "./KeyframesResolver.es.js";
import { isNone as V } from "./utils/is-none.es.js";
import { makeNoneKeyframesAnimatable as S } from "./utils/make-none-animatable.es.js";
import { positionalValues as m, isNumOrPxType as y } from "./utils/unit-conversion.es.js";
class M extends v {
  constructor(e, n, r, t, o) {
    super(e, n, r, t, o, !0);
  }
  readKeyframes() {
    const { unresolvedKeyframes: e, element: n, name: r } = this;
    if (!n || !n.current)
      return;
    super.readKeyframes();
    for (let s = 0; s < e.length; s++) {
      let i = e[s];
      if (typeof i == "string" && (i = i.trim(), K(i))) {
        const d = g(i, n.current);
        d !== void 0 && (e[s] = d), s === e.length - 1 && (this.finalKeyframe = i);
      }
    }
    if (this.resolveNoneKeyframes(), !c.has(r) || e.length !== 2)
      return;
    const [t, o] = e, a = h(t), f = h(o), l = p(t), u = p(o);
    if (l !== u && m[r]) {
      this.needsMeasurement = !0;
      return;
    }
    if (a !== f)
      if (y(a) && y(f))
        for (let s = 0; s < e.length; s++) {
          const i = e[s];
          typeof i == "string" && (e[s] = parseFloat(i));
        }
      else m[r] && (this.needsMeasurement = !0);
  }
  resolveNoneKeyframes() {
    const { unresolvedKeyframes: e, name: n } = this, r = [];
    for (let t = 0; t < e.length; t++)
      (e[t] === null || V(e[t])) && r.push(t);
    r.length && S(e, r, n);
  }
  measureInitialState() {
    const { element: e, unresolvedKeyframes: n, name: r } = this;
    if (!e || !e.current)
      return;
    r === "height" && (this.suspendedScrollY = window.pageYOffset), this.measuredOrigin = m[r](e.measureViewportBox(), window.getComputedStyle(e.current)), n[0] = this.measuredOrigin;
    const t = n[n.length - 1];
    t !== void 0 && e.getValue(r, t).jump(t, !1);
  }
  measureEndState() {
    var f;
    const { element: e, name: n, unresolvedKeyframes: r } = this;
    if (!e || !e.current)
      return;
    const t = e.getValue(n);
    t && t.jump(this.measuredOrigin, !1);
    const o = r.length - 1, a = r[o];
    r[o] = m[n](e.measureViewportBox(), window.getComputedStyle(e.current)), a !== null && this.finalKeyframe === void 0 && (this.finalKeyframe = a), (f = this.removedTransforms) != null && f.length && this.removedTransforms.forEach(([l, u]) => {
      e.getValue(l).set(u);
    }), this.resolveNoneKeyframes();
  }
}
export {
  M as DOMKeyframesResolver
};
//# sourceMappingURL=DOMKeyframesResolver.es.js.map
