import { isCSSVariableToken as c } from "./is-css-variable.es.js";
import { invariant as l } from "../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/errors.es.js";
import { isNumericalString as s } from "../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/is-numerical-string.es.js";
const m = (
  // eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
  /^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u
);
function p(a) {
  const e = m.exec(a);
  if (!e)
    return [,];
  const [, r, i, t] = e;
  return [`--${r ?? i}`, t];
}
const f = 4;
function u(a, e, r = 1) {
  l(r <= f, `Max CSS variable fallback depth detected in property "${a}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
  const [i, t] = p(a);
  if (!i)
    return;
  const o = window.getComputedStyle(e).getPropertyValue(i);
  if (o) {
    const n = o.trim();
    return s(n) ? parseFloat(n) : n;
  }
  return c(t) ? u(t, e, r + 1) : t;
}
export {
  u as getVariableValue,
  p as parseCSSVariable
};
//# sourceMappingURL=css-variables-conversion.es.js.map
