import { __assign as b, __read as O } from "../../../../../../tslib/tslib.es6.es.js";
import { isKeyframesTarget as S } from "../../../animation/utils/is-keyframes-target.es.js";
import { invariant as V } from "../../../../../../hey-listen/dist/hey-listen.es.es.js";
import { transformProps as j } from "../../html/utils/transform.es.js";
import { findDimensionValueType as c } from "../value-types/dimensions.es.js";
import { px as R } from "../../../../../../style-value-types/dist/es/numbers/units.es.js";
import { number as L } from "../../../../../../style-value-types/dist/es/numbers/index.es.js";
var M = /* @__PURE__ */ new Set([
  "width",
  "height",
  "top",
  "left",
  "right",
  "bottom",
  "x",
  "y"
]), A = function(r) {
  return M.has(r);
}, N = function(r) {
  return Object.keys(r).some(A);
}, C = function(r, t) {
  r.set(t, !1), r.set(t);
}, y = function(r) {
  return r === L || r === R;
}, F;
(function(r) {
  r.width = "width", r.height = "height", r.left = "left", r.right = "right", r.top = "top", r.bottom = "bottom";
})(F || (F = {}));
var w = function(r, t) {
  return parseFloat(r.split(", ")[t]);
}, _ = function(r, t) {
  return function(a, e) {
    var s = e.transform;
    if (s === "none" || !s)
      return 0;
    var o = s.match(/^matrix3d\((.+)\)$/);
    if (o)
      return w(o[1], t);
    var p = s.match(/^matrix\((.+)\)$/);
    return p ? w(p[1], r) : 0;
  };
}, $ = /* @__PURE__ */ new Set(["x", "y", "z"]), z = j.filter(function(r) {
  return !$.has(r);
});
function W(r) {
  var t = [];
  return z.forEach(function(a) {
    var e = r.getValue(a);
    e !== void 0 && (t.push([a, e.get()]), e.set(a.startsWith("scale") ? 1 : 0));
  }), t.length && r.syncRender(), t;
}
var K = {
  width: function(r, t) {
    var a = r.x, e = t.paddingLeft, s = e === void 0 ? "0" : e, o = t.paddingRight, p = o === void 0 ? "0" : o;
    return a.max - a.min - parseFloat(s) - parseFloat(p);
  },
  height: function(r, t) {
    var a = r.y, e = t.paddingTop, s = e === void 0 ? "0" : e, o = t.paddingBottom, p = o === void 0 ? "0" : o;
    return a.max - a.min - parseFloat(s) - parseFloat(p);
  },
  top: function(r, t) {
    var a = t.top;
    return parseFloat(a);
  },
  left: function(r, t) {
    var a = t.left;
    return parseFloat(a);
  },
  bottom: function(r, t) {
    var a = r.y, e = t.top;
    return parseFloat(e) + (a.max - a.min);
  },
  right: function(r, t) {
    var a = r.x, e = t.left;
    return parseFloat(e) + (a.max - a.min);
  },
  x: _(4, 13),
  y: _(5, 14)
}, q = function(r, t, a) {
  var e = t.measureViewportBox(), s = t.getInstance(), o = getComputedStyle(s), p = o.display, m = {};
  p === "none" && t.setStaticValue("display", r.display || "block"), a.forEach(function(l) {
    m[l] = K[l](e, o);
  }), t.syncRender();
  var h = t.measureViewportBox();
  return a.forEach(function(l) {
    var n = t.getValue(l);
    C(n, m[l]), r[l] = K[l](h, o);
  }), r;
}, G = function(r, t, a, e) {
  a === void 0 && (a = {}), e === void 0 && (e = {}), t = b({}, t), e = b({}, e);
  var s = Object.keys(t).filter(A), o = [], p = !1, m = [];
  if (s.forEach(function(n) {
    var d = r.getValue(n);
    if (!!r.hasValue(n)) {
      var v = a[n], u = c(v), i = t[n], f;
      if (S(i)) {
        var P = i.length, x = i[0] === null ? 1 : 0;
        v = i[x], u = c(v);
        for (var g = x; g < P; g++)
          f ? V(c(i[g]) === f, "All keyframes must be of the same type") : (f = c(i[g]), V(f === u || y(u) && y(f), "Keyframes must be of the same dimension as the current value"));
      } else
        f = c(i);
      if (u !== f)
        if (y(u) && y(f)) {
          var T = d.get();
          typeof T == "string" && d.set(parseFloat(T)), typeof i == "string" ? t[n] = parseFloat(i) : Array.isArray(i) && f === R && (t[n] = i.map(parseFloat));
        } else
          (u == null ? void 0 : u.transform) && (f == null ? void 0 : f.transform) && (v === 0 || i === 0) ? v === 0 ? d.set(f.transform(v)) : t[n] = u.transform(i) : (p || (o = W(r), p = !0), m.push(n), e[n] = e[n] !== void 0 ? e[n] : t[n], C(d, i));
    }
  }), m.length) {
    var h = m.indexOf("height") >= 0 ? window.pageYOffset : null, l = q(t, r, m);
    return o.length && o.forEach(function(n) {
      var d = O(n, 2), v = d[0], u = d[1];
      r.getValue(v).set(u);
    }), r.syncRender(), h !== null && window.scrollTo({ top: h }), { target: l, transitionEnd: e };
  } else
    return { target: t, transitionEnd: e };
};
function Z(r, t, a, e) {
  return N(t) ? G(r, t, a, e) : { target: t, transitionEnd: e };
}
export {
  F as BoundingBoxDimension,
  K as positionalValues,
  Z as unitConversion
};
//# sourceMappingURL=unit-conversion.es.js.map
