import { StyleSheet as I } from "../../../../../@emotion_sheet@1.1.1/node_modules/@emotion/sheet/dist/emotion-sheet.browser.esm.js";
import { stringify as O, serialize as x } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Serializer.js";
import { COMMENT as T } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Enum.js";
import { rulesheet as _, middleware as D, prefixer as V } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Middleware.js";
import { compile as W } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Parser.js";
import { dealloc as q, alloc as M, next as b, token as E, peek as d, delimit as S, slice as L, position as k } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Tokenizer.js";
import { from as U } from "../../../../../stylis@4.0.13/node_modules/stylis/src/Utility.js";
var F = function(r) {
  return r.length ? r[r.length - 1] : null;
}, H = function(r, t, e) {
  for (var a = 0, o = 0; a = o, o = d(), a === 38 && o === 12 && (t[e] = 1), !E(o); )
    b();
  return L(r, k);
}, K = function(r, t) {
  var e = -1, a = 44;
  do
    switch (E(a)) {
      case 0:
        a === 38 && d() === 12 && (t[e] = 1), r[e] += H(k - 1, t, e);
        break;
      case 2:
        r[e] += S(a);
        break;
      case 4:
        if (a === 44) {
          r[++e] = d() === 58 ? "&\f" : "", t[e] = r[e].length;
          break;
        }
      default:
        r[e] += U(a);
    }
  while (a = b());
  return r;
}, Y = function(r, t) {
  return q(K(M(r), t));
}, g = /* @__PURE__ */ new WeakMap(), B = function(r) {
  if (!(r.type !== "rule" || !r.parent || r.length < 1)) {
    for (var t = r.value, e = r.parent, a = r.column === e.column && r.line === e.line; e.type !== "rule"; )
      if (e = e.parent, !e)
        return;
    if (!(r.props.length === 1 && t.charCodeAt(0) !== 58 && !g.get(e)) && !a) {
      g.set(r, !0);
      for (var o = [], u = Y(t, o), c = e.props, p = 0, h = 0; p < u.length; p++)
        for (var s = 0; s < c.length; s++, h++)
          r.props[h] = o[p] ? u[p].replace(/&\f/g, c[s]) : c[s] + " " + u[p];
    }
  }
}, G = function(r) {
  if (r.type === "decl") {
    var t = r.value;
    t.charCodeAt(0) === 108 && t.charCodeAt(2) === 98 && (r.return = "", r.value = "");
  }
}, J = "emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason", Q = function(r) {
  return !!r && r.type === "comm" && r.children.indexOf(J) > -1;
}, X = function(r) {
  return function(t, e, a) {
    if (t.type === "rule") {
      var o = t.value.match(/(:first|:nth|:nth-last)-child/g);
      if (o && r.compat !== !0) {
        var u = e > 0 ? a[e - 1] : null;
        if (u && Q(F(u.children)))
          return;
        o.forEach(function(c) {
          console.error('The pseudo class "' + c + '" is potentially unsafe when doing server-side rendering. Try changing it to "' + c.split("-child")[0] + '-of-type".');
        });
      }
    }
  };
}, w = function(r) {
  return r.type.charCodeAt(1) === 105 && r.type.charCodeAt(0) === 64;
}, Z = function(r, t) {
  for (var e = r - 1; e >= 0; e--)
    if (!w(t[e]))
      return !0;
  return !1;
}, m = function(r) {
  r.type = "", r.value = "", r.return = "", r.children = "", r.props = "";
}, $ = function(r, t, e) {
  !w(r) || (r.parent ? (console.error("`@import` rules can't be nested inside other rules. Please move it to the top level and put it before regular rules. Keep in mind that they can only be used within global styles."), m(r)) : Z(t, e) && (console.error("`@import` rules can't be after other rules. Please put your `@import` rules before your other rules."), m(r)));
}, z = [V], sr = function(r) {
  var t = r.key;
  if (process.env.NODE_ENV !== "production" && !t)
    throw new Error(`You have to configure \`key\` for your cache. Please make sure it's unique (and not equal to 'css') as it's used for linking styles to your cache.
If multiple caches share the same key they might "fight" for each other's style elements.`);
  if (t === "css") {
    var e = document.querySelectorAll("style[data-emotion]:not([data-s])");
    Array.prototype.forEach.call(e, function(n) {
      var l = n.getAttribute("data-emotion");
      l.indexOf(" ") !== -1 && (document.head.appendChild(n), n.setAttribute("data-s", ""));
    });
  }
  var a = r.stylisPlugins || z;
  if (process.env.NODE_ENV !== "production" && /[^a-z-]/.test(t))
    throw new Error('Emotion key must only contain lower case alphabetical characters and - but "' + t + '" was passed');
  var o = {}, u, c = [];
  u = r.container || document.head, Array.prototype.forEach.call(
    document.querySelectorAll('style[data-emotion^="' + t + ' "]'),
    function(n) {
      for (var l = n.getAttribute("data-emotion").split(" "), f = 1; f < l.length; f++)
        o[l[f]] = !0;
      c.push(n);
    }
  );
  var p, h = [B, G];
  process.env.NODE_ENV !== "production" && h.push(X({
    get compat() {
      return v.compat;
    }
  }), $);
  {
    var s, A = [O, process.env.NODE_ENV !== "production" ? function(n) {
      n.root || (n.return ? s.insert(n.return) : n.value && n.type !== T && s.insert(n.value + "{}"));
    } : _(function(n) {
      s.insert(n);
    })], P = D(h.concat(a, A)), R = function(l) {
      return x(W(l), P);
    };
    p = function(l, f, y, C) {
      s = y, process.env.NODE_ENV !== "production" && f.map !== void 0 && (s = {
        insert: function(N) {
          y.insert(N + f.map);
        }
      }), R(l ? l + "{" + f.styles + "}" : f.styles), C && (v.inserted[f.name] = !0);
    };
  }
  var v = {
    key: t,
    sheet: new I({
      key: t,
      container: u,
      nonce: r.nonce,
      speedy: r.speedy,
      prepend: r.prepend,
      insertionPoint: r.insertionPoint
    }),
    nonce: r.nonce,
    inserted: o,
    registered: {},
    insert: p
  };
  return v.sheet.hydrate(c), v;
};
export {
  sr as default
};
//# sourceMappingURL=emotion-cache.browser.esm.js.map
