var A = Object.defineProperty;
var p = (S, e) => A(S, "name", { value: e, configurable: !0 });
const g = "ͼ", T = typeof Symbol > "u" ? "__" + g : Symbol.for(g), m = typeof Symbol > "u" ? "__styleSet" + Math.floor(Math.random() * 1e8) : Symbol("styleSet"), b = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : {};
class N {
  static {
    p(this, "StyleModule");
  }
  // :: (Object<Style>, ?{finish: ?(string) → string})
  // Create a style module from the given spec.
  //
  // When `finish` is given, it is called on regular (non-`@`)
  // selectors (after `&` expansion) to compute the final selector.
  constructor(e, s) {
    this.rules = [];
    let { finish: i } = s || {};
    function n(t) {
      return /^@/.test(t) ? [t] : t.split(/,\s*/);
    }
    p(n, "splitSelector");
    function l(t, a, h, r) {
      let y = [], f = /^@(\w+)\b/.exec(t[0]), w = f && f[1] == "keyframes";
      if (f && a == null) return h.push(t[0] + ";");
      for (let o in a) {
        let u = a[o];
        if (/&/.test(o))
          l(
            o.split(/,\s*/).map((d) => t.map((c) => d.replace(/&/, c))).reduce((d, c) => d.concat(c)),
            u,
            h
          );
        else if (u && typeof u == "object") {
          if (!f) throw new RangeError("The value of a property (" + o + ") should be a primitive value.");
          l(n(o), u, y, w);
        } else u != null && y.push(o.replace(/_.*/, "").replace(/[A-Z]/g, (d) => "-" + d.toLowerCase()) + ": " + u + ";");
      }
      (y.length || w) && h.push((i && !f && !r ? t.map(i) : t).join(", ") + " {" + y.join(" ") + "}");
    }
    p(l, "render");
    for (let t in e) l(n(t), e[t], this.rules);
  }
  // :: () → string
  // Returns a string containing the module's CSS rules.
  getRules() {
    return this.rules.join(`
`);
  }
  // :: () → string
  // Generate a new unique CSS class name.
  static newName() {
    let e = b[T] || 1;
    return b[T] = e + 1, g + e.toString(36);
  }
  // :: (union<Document, ShadowRoot>, union<[StyleModule], StyleModule>, ?{nonce: ?string})
  //
  // Mount the given set of modules in the given DOM root, which ensures
  // that the CSS rules defined by the module are available in that
  // context.
  //
  // Rules are only added to the document once per root.
  //
  // Rule order will follow the order of the modules, so that rules from
  // modules later in the array take precedence of those from earlier
  // modules. If you call this function multiple times for the same root
  // in a way that changes the order of already mounted modules, the old
  // order will be changed.
  //
  // If a Content Security Policy nonce is provided, it is added to
  // the `<style>` tag generated by the library.
  static mount(e, s, i) {
    let n = e[m], l = i && i.nonce;
    n ? l && n.setNonce(l) : n = new C(e, l), n.mount(Array.isArray(s) ? s : [s], e);
  }
}
let x = /* @__PURE__ */ new Map();
class C {
  static {
    p(this, "StyleSet");
  }
  constructor(e, s) {
    let i = e.ownerDocument || e, n = i.defaultView;
    if (!e.head && e.adoptedStyleSheets && n.CSSStyleSheet) {
      let l = x.get(i);
      if (l) return e[m] = l;
      this.sheet = new n.CSSStyleSheet(), x.set(i, this);
    } else
      this.styleTag = i.createElement("style"), s && this.styleTag.setAttribute("nonce", s);
    this.modules = [], e[m] = this;
  }
  mount(e, s) {
    let i = this.sheet, n = 0, l = 0;
    for (let t = 0; t < e.length; t++) {
      let a = e[t], h = this.modules.indexOf(a);
      if (h < l && h > -1 && (this.modules.splice(h, 1), l--, h = -1), h == -1) {
        if (this.modules.splice(l++, 0, a), i) for (let r = 0; r < a.rules.length; r++)
          i.insertRule(a.rules[r], n++);
      } else {
        for (; l < h; ) n += this.modules[l++].rules.length;
        n += a.rules.length, l++;
      }
    }
    if (i)
      s.adoptedStyleSheets.indexOf(this.sheet) < 0 && (s.adoptedStyleSheets = [this.sheet, ...s.adoptedStyleSheets]);
    else {
      let t = "";
      for (let h = 0; h < this.modules.length; h++)
        t += this.modules[h].getRules() + `
`;
      this.styleTag.textContent = t;
      let a = s.head || s;
      this.styleTag.parentNode != a && a.insertBefore(this.styleTag, a.firstChild);
    }
  }
  setNonce(e) {
    this.styleTag && this.styleTag.getAttribute("nonce") != e && this.styleTag.setAttribute("nonce", e);
  }
}
export {
  N as StyleModule
};
