let A = 0;
const N = /* @__PURE__ */ new Set(), j = [
  "animation-iteration-count",
  "border-image-outset",
  "border-image-slice",
  "border-image-width",
  "box-flex",
  "box-flex-group",
  "box-ordinal-group",
  "column-count",
  "columns",
  "counter-increment",
  "counter-reset",
  "flex",
  "flex-grow",
  "flex-positive",
  "flex-shrink",
  "flex-negative",
  "flex-order",
  "font-weight",
  "grid-area",
  "grid-column",
  "grid-column-end",
  "grid-column-span",
  "grid-column-start",
  "grid-row",
  "grid-row-end",
  "grid-row-span",
  "grid-row-start",
  "line-clamp",
  "line-height",
  "opacity",
  "order",
  "orphans",
  "tab-size",
  "widows",
  "z-index",
  "zoom",
  // SVG properties.
  "fill-opacity",
  "flood-opacity",
  "stop-opacity",
  "stroke-dasharray",
  "stroke-dashoffset",
  "stroke-miterlimit",
  "stroke-opacity",
  "stroke-width"
];
for (const s of j)
  for (const e of ["-webkit-", "-ms-", "-moz-", "-o-", ""])
    N.add(e + s);
function z(s) {
  return s.replace(/[ !#$%&()*+,./;<=>?@[\]^`{|}~"'\\]/g, "\\$&");
}
function $(s, e) {
  return s.replace(/&/g, e);
}
function b(s) {
  return s.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`).replace(/^ms-/, "-ms-");
}
function E(s) {
  let e = 5381, t = s.length;
  for (; t--; )
    e = e * 33 ^ s.charCodeAt(t);
  return (e >>> 0).toString(36);
}
function q(s, e) {
  return s.indexOf("&") === -1 ? `${e} ${s}` : $(s, e);
}
function U([s, e]) {
  return typeof e == "number" && e && !N.has(s) ? `${s}:${e}px` : `${s}:${String(e)}`;
}
function v(s, e, t, n, r) {
  const i = [], c = [];
  for (const [d, l] of Object.entries(n))
    if (d.charCodeAt(0) !== 36 && l != null)
      if (Array.isArray(l)) {
        const k = b(d);
        for (let m = 0; m < l.length; m++) {
          const I = l[m];
          I != null && i.push([k, I]);
        }
      } else typeof l == "object" ? c.push([d, l]) : i.push([b(d), l]);
  const u = !!n.$unique, h = n.$global ? "" : r, o = i.map(U).join(";");
  let f = o, g = h, y = s, p = e;
  t.charCodeAt(0) === 64 ? (y = [], p = [], h && o && p.push({ selector: g, style: o, isUnique: u }), s.push({
    selector: t,
    style: h ? "" : o,
    rules: y,
    styles: p
  })) : (g = h ? t ? q(t, h) : h : t, o && e.push({ selector: g, style: o, isUnique: u }));
  for (const [d, l] of c)
    f += `|${d}#${v(y, p, d, l, g)}`;
  return f;
}
function x(s, e, t, n, r) {
  for (const { selector: i, style: c, isUnique: u } of t) {
    const h = $(i, r), o = new S(c, u ? String(++A) : n);
    o.add(new M(h)), s.add(o);
  }
  for (const { selector: i, style: c, rules: u, styles: h } of e) {
    const o = $(i, r), f = new w(o, c, n);
    x(f, u, h, n, r), s.add(f);
  }
}
function C(s) {
  let e = "";
  for (let t = 0; t < s.length; t++)
    e += s[t];
  return e;
}
class a {
  constructor(e) {
    this.changes = e, this.changeId = 0, this.sheet = [], this.children = [], this.counters = /* @__PURE__ */ new Map();
  }
  add(e) {
    const t = e.cid(), n = this.counters.get(t) ?? 0;
    if (this.counters.set(t, n + 1), n === 0) {
      const r = e.clone(), i = this.children.push(r);
      this.sheet.push(r.getStyles()), this.changeId++, this.changes && this.changes.add(r, i);
    } else if (e instanceof a) {
      const r = this.children.findIndex((u) => u.cid() === t), i = this.children[r], c = i.changeId;
      i.merge(e), i.changeId !== c && (this.sheet[r] = i.getStyles(), this.changeId++, this.changes && this.changes.change(i, r));
    }
  }
  remove(e) {
    const t = e.cid(), n = this.counters.get(t);
    if (n) {
      const r = this.children.findIndex((i) => i.cid() === t);
      if (n === 1) {
        const i = this.children[r];
        this.counters.delete(t), this.children.splice(r, 1), this.sheet.splice(r, 1), this.changeId++, this.changes && this.changes.remove(i, r);
      } else if (e instanceof a) {
        const i = this.children[r], c = i.changeId;
        this.counters.set(t, n - 1), i.unmerge(e), i.changeId !== c && (this.sheet[r] = i.getStyles(), this.changeId++, this.changes && this.changes.change(i, r));
      }
    }
  }
  merge(e) {
    for (const t of e.children)
      this.add(t);
    return this;
  }
  unmerge(e) {
    for (const t of e.children)
      this.remove(t);
    return this;
  }
}
class M {
  constructor(e) {
    this.selector = e;
  }
  cid() {
    return this.selector;
  }
  getStyles() {
    return this.selector;
  }
  clone() {
    return this;
  }
}
class S extends a {
  constructor(e, t) {
    super(), this.style = e, this.id = t;
  }
  cid() {
    return `${this.id}|${this.style}`;
  }
  getStyles() {
    return `${this.sheet.join(",")}{${this.style}}`;
  }
  clone() {
    return new S(this.style, this.id).merge(this);
  }
}
class w extends a {
  constructor(e, t, n) {
    super(), this.rule = e, this.style = t, this.id = n;
  }
  cid() {
    return `${this.id}|${this.rule}|${this.style}`;
  }
  getStyles() {
    return `${this.rule}{${this.style}${C(this.sheet)}}`;
  }
  clone() {
    return new w(this.rule, this.style, this.id).merge(this);
  }
}
class O extends a {
  constructor(e, t) {
    super(t), this.prefix = e;
  }
  register(e) {
    const t = `${this.prefix}${e.id}`;
    if (process.env.NODE_ENV !== "production" && e.displayName) {
      const n = `${e.displayName}_${t}`;
      return x(this, e.rules, e.styles, e.id, z(n)), n;
    }
    return x(this, e.rules, e.styles, e.id, t), t;
  }
  registerStyle(e) {
    return this.register(R(e));
  }
  getStyles() {
    return C(this.sheet);
  }
}
function B(s, e = "") {
  return new O(e, s);
}
function R(s) {
  const e = [], t = [], n = v(e, t, "", s, ".&");
  return {
    id: E(n),
    rules: e,
    styles: t,
    displayName: s.$displayName
  };
}
export {
  a as Cache,
  w as Rule,
  M as Selector,
  O as Sheet,
  S as Style,
  R as compile,
  B as create
};
//# sourceMappingURL=index.js.map
