import { __rest as _, __assign as m, __read as g } from "../../../../../../tslib/tslib.es6.es.js";
import { invariant as p } from "../../../../../../hey-listen/dist/hey-listen.es.es.js";
function l(a) {
  return typeof a == "string" && a.startsWith("var(--");
}
var S = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
function V(a) {
  var i = S.exec(a);
  if (!i)
    return [,];
  var r = g(i, 3), t = r[1], e = r[2];
  return [t, e];
}
var x = 4;
function o(a, i, r) {
  r === void 0 && (r = 1), p(r <= x, 'Max CSS variable fallback depth detected in property "'.concat(a, '". This may indicate a circular fallback dependency.'));
  var t = g(V(a), 2), e = t[0], f = t[1];
  if (!!e) {
    var n = window.getComputedStyle(i).getPropertyValue(e);
    return n ? n.trim() : l(f) ? o(f, i, r + 1) : f;
  }
}
function h(a, i, r) {
  var t, e = _(i, []), f = a.getInstance();
  if (!(f instanceof Element))
    return { target: e, transitionEnd: r };
  r && (r = m({}, r)), a.forEachValue(function(u) {
    var s = u.get();
    if (!!l(s)) {
      var b = o(s, f);
      b && u.set(b);
    }
  });
  for (var n in e) {
    var c = e[n];
    if (!!l(c)) {
      var v = o(c, f);
      !v || (e[n] = v, r && ((t = r[n]) !== null && t !== void 0 || (r[n] = c)));
    }
  }
  return { target: e, transitionEnd: r };
}
export {
  S as cssVariableRegex,
  V as parseCSSVariable,
  h as resolveCSSVariables
};
//# sourceMappingURL=css-variables-conversion.es.js.map
