@barocss/browser 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -18,11 +18,17 @@ export declare class BrowserRuntime {
18
18
  private options;
19
19
  private isDestroyed;
20
20
  private existing;
21
+ /** #274: @keyframes names the page's own sheets define (filled with `existing`). */
22
+ private existingKeyframes;
21
23
  private existingSheetCount;
22
24
  /** #269: classes requested explicitly through addClass(); never reclaimed. */
23
25
  private pinned;
24
26
  private gc;
25
27
  private reclaimedCount;
28
+ /** #268: class rules adopted from `<style data-barocss-ssr>`, in sheet order, and the classes they lead. */
29
+ private ssrRules;
30
+ private ssrClasses;
31
+ private observedOnce;
26
32
  private incrementalParser;
27
33
  private changeDetector;
28
34
  private stylePartitionManager;
@@ -33,6 +39,15 @@ export declare class BrowserRuntime {
33
39
  */
34
40
  private debugLog;
35
41
  private init;
42
+ /**
43
+ * #268: adopt the class rules of server-rendered `<style data-barocss-ssr>` sheets in <head>, at startup
44
+ * (constructor and the first observe()). Each rule moves
45
+ * (same task, so no paint in between) into the partition its class would get if generated here, at
46
+ * its #254 sorted position, so a later client `sm:` rule lands before a server `lg:` rule. Its classes
47
+ * are never regenerated and never reclaimed. `:root`, `@property` and `@keyframes` stay in the sheet.
48
+ */
49
+ private adoptSsrSheets;
50
+ private insertSsrRules;
36
51
  private injectPreflightCSS;
37
52
  private ensureCssVars;
38
53
  private getInsertionPoint;
@@ -57,7 +72,7 @@ export declare class BrowserRuntime {
57
72
  /** #269: a class that must never be reclaimed. */
58
73
  private isPermanent;
59
74
  /**
60
- * #269: delete the generated rules of classes no live element uses. Root/@property rules stay
75
+ * #269: delete the generated rules of classes no live element uses. Root/@property/@keyframes rules stay
61
76
  * (they are shared and harmless); a rule text another cached class still emits is kept.
62
77
  */
63
78
  private reclaim;
@@ -344,6 +359,9 @@ export declare const shadcnTheme: {
344
359
  borderRadius: Record<string, string>;
345
360
  };
346
361
 
362
+ /** #268: marks a server-rendered sheet (`@barocss/server` `ssrStyleTag()`); the runtime adopts its class rules. */
363
+ export declare const SSR_STYLE_SELECTOR = "style[data-barocss-ssr]";
364
+
347
365
  export declare interface StylePartition {
348
366
  id: string;
349
367
  styles: string[];
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- import { parseClassName as g, upperBound as R, ruleSortKey as y, compareKeys as b, createContext as m, IncrementalParser as p, clearAstCache as w } from "@barocss/kit";
1
+ import { parseClassName as y, upperBound as b, ruleSortKey as m, compareKeys as S, createContext as p, IncrementalParser as C, clearAstCache as x } from "@barocss/kit";
2
2
  class d {
3
- constructor(t, e = 50, s = "barocss-style-partition-", i = (r) => g(r).utility?.category) {
3
+ constructor(t, e = 50, s = "barocss-style-partition-", i = (r) => y(r).utility?.category) {
4
4
  this.partitions = [], this.categoryPartitions = /* @__PURE__ */ new Map(), this.partitionCounter = 0, this.maxRulesPerPartition = 50, this.classToPartitionMap = /* @__PURE__ */ new Map(), this.classToCategoryPartitionMap = /* @__PURE__ */ new Map(), this.styleIdPrefix = "barocss-style-partition-", this.insertionPoint = t, this.maxRulesPerPartition = e, this.styleIdPrefix = s, this.getCategory = i, this.initializeDefaultPartition();
5
5
  }
6
6
  /**
@@ -8,7 +8,7 @@ class d {
8
8
  * one insertRule at a binary-searched index, no sheet rewrite.
9
9
  */
10
10
  insertSorted(t, e, s) {
11
- const i = t.keys ??= [], r = R(i, s), n = t.styleElement.sheet;
11
+ const i = t.keys ??= [], r = b(i, s), n = t.styleElement.sheet;
12
12
  n && n.cssRules.length === i.length ? (n.insertRule(this.escapeCssRule(e), r), t.styles.splice(r, 0, e)) : (t.styles.splice(r, 0, e), t.styleElement.textContent = t.styles.join(`
13
13
  `) + `
14
14
  `), i.splice(r, 0, s);
@@ -69,10 +69,10 @@ class d {
69
69
  addRule(t) {
70
70
  if (this.hasRule(t))
71
71
  return !1;
72
- const e = y(t);
72
+ const e = m(t);
73
73
  let s = this.partitions.findIndex((r) => {
74
74
  const n = r.keys;
75
- return !!n && n.length > 0 && b(n[n.length - 1], e) > 0;
75
+ return !!n && n.length > 0 && S(n[n.length - 1], e) > 0;
76
76
  });
77
77
  s === -1 && (this.currentPartition.styles.length >= this.maxRulesPerPartition && this.createNewPartition(), s = this.partitions.length - 1);
78
78
  const i = this.partitions[s];
@@ -91,7 +91,7 @@ class d {
91
91
  let s = this.getCategoryPartition(e);
92
92
  s || (s = this.createNewCategoryPartition(e));
93
93
  try {
94
- this.insertSorted(s, t, y(t));
94
+ this.insertSorted(s, t, m(t));
95
95
  } catch (i) {
96
96
  return console.warn(
97
97
  `[StylePartitionManager] Failed to insert rule in category: ${e} ${t}`,
@@ -142,8 +142,8 @@ class d {
142
142
  if (this.classToCategoryPartitionMap.get(t) !== e) return !1;
143
143
  s = this.categoryPartitions.get(e);
144
144
  } else {
145
- const a = this.classToPartitionMap.get(t);
146
- s = a === void 0 ? void 0 : this.partitions[a];
145
+ const o = this.classToPartitionMap.get(t);
146
+ s = o === void 0 ? void 0 : this.partitions[o];
147
147
  }
148
148
  if (!s) return !1;
149
149
  const i = s.styles.indexOf(t);
@@ -187,11 +187,11 @@ class d {
187
187
  }), this.partitions = [], this.categoryPartitions.clear(), this.partitionCounter = 0, this.classToPartitionMap.clear(), this.classToCategoryPartitionMap.clear();
188
188
  }
189
189
  }
190
- function x(o) {
191
- return o ? typeof o == "object" && typeof o.baseVal == "string" ? o.baseVal : o.toString() : "";
190
+ function w(a) {
191
+ return a ? typeof a == "object" && typeof a.baseVal == "string" ? a.baseVal : a.toString() : "";
192
192
  }
193
- function u(o) {
194
- return o ? x(o).split(/\s+/).filter(Boolean) : [];
193
+ function u(a) {
194
+ return a ? w(a).split(/\s+/).filter(Boolean) : [];
195
195
  }
196
196
  class E {
197
197
  /**
@@ -200,7 +200,7 @@ class E {
200
200
  * @param incrementalParser - IncrementalParser instance for class processing
201
201
  * @param BrowserRuntime - Optional BrowserRuntime instance for CSS injection
202
202
  */
203
- constructor(t, e, s = (i) => g(i).utility?.category) {
203
+ constructor(t, e, s = (i) => y(i).utility?.category) {
204
204
  this.observer = null, this.gc = null, this.incrementalParser = t, this.BrowserRuntime = e, this.getCategory = s;
205
205
  }
206
206
  setGc(t) {
@@ -229,23 +229,23 @@ class E {
229
229
  }) : (this.observer && this.observer.disconnect(), this.gc?.setRoot(t), this.observer = new MutationObserver((s) => {
230
230
  const i = /* @__PURE__ */ new Set(), r = this.gc;
231
231
  if (s.forEach((n) => {
232
- if (r && (n.type === "attributes" ? r.reconcile(n.target) : n.type === "childList" && (n.removedNodes.forEach((a) => r.reconcileTree(a)), n.addedNodes.forEach((a) => r.reconcileTree(a)))), n.type === "attributes" && n.attributeName === "class" && t.contains(n.target)) {
233
- const a = n.target;
234
- a.className && u(a.className).forEach((l) => {
232
+ if (r && (n.type === "attributes" ? r.reconcile(n.target) : n.type === "childList" && (n.removedNodes.forEach((o) => r.reconcileTree(o)), n.addedNodes.forEach((o) => r.reconcileTree(o)))), n.type === "attributes" && n.attributeName === "class" && t.contains(n.target)) {
233
+ const o = n.target;
234
+ o.className && u(o.className).forEach((l) => {
235
235
  this.incrementalParser.isProcessed(l) || i.add(l);
236
236
  });
237
237
  }
238
- n.type === "childList" && n.addedNodes.forEach((a) => {
239
- if (a.nodeType === Node.ELEMENT_NODE && t.contains(a)) {
240
- const c = a;
238
+ n.type === "childList" && n.addedNodes.forEach((o) => {
239
+ if (o.nodeType === Node.ELEMENT_NODE && t.contains(o)) {
240
+ const c = o;
241
241
  this.processElement(c, i), c.querySelectorAll("[class]").forEach((l) => {
242
242
  this.processElement(l, i);
243
243
  });
244
244
  }
245
245
  });
246
246
  }), i.size > 0) {
247
- const n = Array.from(i), a = this.incrementalParser.processClasses(n);
248
- this.BrowserRuntime?.applyParseResults(a);
247
+ const n = Array.from(i), o = this.incrementalParser.processClasses(n);
248
+ this.BrowserRuntime?.applyParseResults(o);
249
249
  } else
250
250
  this.BrowserRuntime?.applyParseResults([]);
251
251
  r?.afterBatch();
@@ -268,12 +268,12 @@ class E {
268
268
  for (const r of i)
269
269
  if (r.className) {
270
270
  const n = u(r.className);
271
- for (const a of n)
272
- this.incrementalParser.isProcessed(a) || s.add(a);
271
+ for (const o of n)
272
+ this.incrementalParser.isProcessed(o) || s.add(o);
273
273
  }
274
274
  if (s.size > 0) {
275
- const r = Array.from(s), n = this.incrementalParser.processClasses(r), a = n.filter((l) => this.getCategory(l.cls) === "layout"), c = n.filter((l) => this.getCategory(l.cls) !== "layout");
276
- this.BrowserRuntime?.applyParseResults(a), e?.onReady?.(), this.BrowserRuntime?.applyParseResults(c);
275
+ const r = Array.from(s), n = this.incrementalParser.processClasses(r), o = n.filter((l) => this.getCategory(l.cls) === "layout"), c = n.filter((l) => this.getCategory(l.cls) !== "layout");
276
+ this.BrowserRuntime?.applyParseResults(o), e?.onReady?.(), this.BrowserRuntime?.applyParseResults(c);
277
277
  } else
278
278
  e?.onReady?.();
279
279
  }
@@ -305,33 +305,44 @@ class E {
305
305
  this.observer && (this.observer.disconnect(), this.observer = null);
306
306
  }
307
307
  }
308
- function S(o) {
309
- return o.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g, (t, e, s) => e ? String.fromCodePoint(parseInt(e, 16)) : s);
308
+ function M(a) {
309
+ return a.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g, (t, e, s) => e ? String.fromCodePoint(parseInt(e, 16)) : s);
310
310
  }
311
- const M = /^\s*\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;
312
- function v(o) {
311
+ const v = /^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;
312
+ function A(a) {
313
313
  const t = [];
314
314
  let e = 0, s = 0;
315
- for (let i = 0; i < o.length; i++) {
316
- const r = o[i];
317
- r === "\\" ? i++ : r === "(" || r === "[" ? e++ : r === ")" || r === "]" ? e-- : r === "," && e === 0 && (t.push(o.slice(s, i)), s = i + 1);
315
+ for (let i = 0; i < a.length; i++) {
316
+ const r = a[i];
317
+ r === "\\" ? i++ : r === "(" || r === "[" ? e++ : r === ")" || r === "]" ? e-- : r === "," && e === 0 && (t.push(a.slice(s, i)), s = i + 1);
318
318
  }
319
- return t.push(o.slice(s)), t;
319
+ return t.push(a.slice(s)), t;
320
320
  }
321
- function C(o, t = /* @__PURE__ */ new Set()) {
322
- for (const e of Array.from(o)) {
321
+ function P(a, t = /* @__PURE__ */ new Set()) {
322
+ for (const e of Array.from(a)) {
323
+ if (e.type === 7 && typeof e.name == "string") {
324
+ t.add(e.name);
325
+ continue;
326
+ }
327
+ const s = e.cssRules;
328
+ s && s.length && P(s, t);
329
+ }
330
+ return t;
331
+ }
332
+ function g(a, t = /* @__PURE__ */ new Set()) {
333
+ for (const e of Array.from(a)) {
323
334
  const s = e.selectorText;
324
335
  if (typeof s == "string")
325
- for (const r of v(s)) {
326
- const n = M.exec(r);
327
- n && t.add(S(n[1]));
336
+ for (const r of A(s)) {
337
+ const n = v.exec(r);
338
+ n && t.add(M(n[1]));
328
339
  }
329
340
  const i = e.cssRules;
330
- i && i.length && C(i, t);
341
+ i && i.length && g(i, t);
331
342
  }
332
343
  return t;
333
344
  }
334
- class A {
345
+ class T {
335
346
  constructor(t, e, s, i = () => Date.now()) {
336
347
  this.host = t, this.graceMs = e, this.maxRules = s, this.now = i, this.counts = /* @__PURE__ */ new Map(), this.counted = /* @__PURE__ */ new WeakMap(), this.candidates = /* @__PURE__ */ new Map(), this.timer = null, this.root = null;
337
348
  }
@@ -351,14 +362,14 @@ class A {
351
362
  reconcile(t) {
352
363
  const e = this.root, i = !!e && e.contains(t) ? Array.from(new Set(u(t.getAttribute("class")))) : [], r = this.counted.get(t);
353
364
  if (!r && i.length === 0) return;
354
- const n = new Set(r ?? []), a = new Set(i);
355
- for (const c of a) {
365
+ const n = new Set(r ?? []), o = new Set(i);
366
+ for (const c of o) {
356
367
  if (n.has(c)) continue;
357
368
  const l = (this.counts.get(c) ?? 0) + 1;
358
369
  this.counts.set(c, l), this.candidates.delete(c);
359
370
  }
360
371
  for (const c of n) {
361
- if (a.has(c)) continue;
372
+ if (o.has(c)) continue;
362
373
  const l = (this.counts.get(c) ?? 0) - 1;
363
374
  l > 0 ? this.counts.set(c, l) : (this.counts.delete(c), this.candidates.delete(c), this.candidates.set(c, this.now()));
364
375
  }
@@ -382,8 +393,8 @@ class A {
382
393
  const t = this.now(), e = Math.max(0, this.host.cachedCount() - this.maxRules), s = [];
383
394
  let i = 0;
384
395
  for (const [r, n] of this.candidates) {
385
- const a = t - n >= this.graceMs;
386
- !a && i >= e || (this.candidates.delete(r), !(this.count(r) > 0 || this.inDom(r) || this.host.isPermanent(r)) && (s.push(r), a || i++));
396
+ const o = t - n >= this.graceMs;
397
+ !o && i >= e || (this.candidates.delete(r), !(this.count(r) > 0 || this.inDom(r) || this.host.isPermanent(r)) && (s.push(r), o || i++));
387
398
  }
388
399
  s.length && this.host.reclaim(s), this.candidates.size && this.schedule(this.graceMs);
389
400
  }
@@ -400,10 +411,10 @@ class A {
400
411
  return { trackedClasses: this.counts.size, candidates: this.candidates.size };
401
412
  }
402
413
  }
403
- const D = "@layer theme, base, components, utilities;";
404
- class L {
414
+ const D = "style[data-barocss-ssr]", L = "@layer theme, base, components, utilities;";
415
+ class N {
405
416
  constructor(t = {}) {
406
- this.cache = /* @__PURE__ */ new Map(), this.rootCache = /* @__PURE__ */ new Set(), this.isDestroyed = !1, this.existing = null, this.existingSheetCount = -1, this.pinned = /* @__PURE__ */ new Set(), this.gc = null, this.reclaimedCount = 0, this.getCategory = (s) => g(s, this.context).utility?.category;
417
+ this.cache = /* @__PURE__ */ new Map(), this.rootCache = /* @__PURE__ */ new Set(), this.isDestroyed = !1, this.existing = null, this.existingKeyframes = /* @__PURE__ */ new Set(), this.existingSheetCount = -1, this.pinned = /* @__PURE__ */ new Set(), this.gc = null, this.reclaimedCount = 0, this.ssrRules = [], this.ssrClasses = /* @__PURE__ */ new Set(), this.observedOnce = !1, this.getCategory = (s) => y(s, this.context).utility?.category;
407
418
  const e = {};
408
419
  this.options = {
409
420
  config: t.config || e,
@@ -414,7 +425,7 @@ class L {
414
425
  gc: t.gc ?? !0,
415
426
  gcGraceMs: t.gcGraceMs ?? 3e3,
416
427
  maxRules: t.maxRules ?? 1 / 0
417
- }, this.context = m(this.options.config), this.incrementalParser = new p(this.context), this.changeDetector = new E(this.incrementalParser, this, this.getCategory), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.options.gc && (this.gc = new A({
428
+ }, this.context = p(this.options.config), this.incrementalParser = new C(this.context), this.changeDetector = new E(this.incrementalParser, this, this.getCategory), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.options.gc && (this.gc = new T({
418
429
  reclaim: (s) => this.reclaim(s),
419
430
  isPermanent: (s) => this.isPermanent(s),
420
431
  cachedCount: () => this.cache.size
@@ -428,7 +439,38 @@ class L {
428
439
  (console[t] || console.log)(`[BrowserRuntime:${t.toUpperCase()}] ${e}`, s || "");
429
440
  }
430
441
  init() {
431
- console.log("[BrowserRuntime] init"), this.injectPreflightCSS(), this.ensureCssVars();
442
+ console.log("[BrowserRuntime] init"), this.injectPreflightCSS(), this.ensureCssVars(), this.adoptSsrSheets();
443
+ }
444
+ /**
445
+ * #268: adopt the class rules of server-rendered `<style data-barocss-ssr>` sheets in <head>, at startup
446
+ * (constructor and the first observe()). Each rule moves
447
+ * (same task, so no paint in between) into the partition its class would get if generated here, at
448
+ * its #254 sorted position, so a later client `sm:` rule lands before a server `lg:` rule. Its classes
449
+ * are never regenerated and never reclaimed. `:root`, `@property` and `@keyframes` stay in the sheet.
450
+ */
451
+ adoptSsrSheets() {
452
+ if (typeof document > "u") return;
453
+ const t = [];
454
+ if (document.head) {
455
+ for (const e of Array.from(document.head.querySelectorAll(`${D}:not([data-barocss-adopted])`))) {
456
+ const s = e.sheet;
457
+ if (!s) continue;
458
+ e.setAttribute("data-barocss-adopted", "");
459
+ const i = [];
460
+ for (let r = s.cssRules.length - 1; r >= 0; r--) {
461
+ const n = s.cssRules[r], o = g([n]);
462
+ o.size !== 0 && (o.forEach((c) => this.ssrClasses.add(c)), i.unshift({ css: n.cssText, cls: o.values().next().value }), s.deleteRule(r));
463
+ }
464
+ t.push(...i);
465
+ }
466
+ t.length !== 0 && (this.ssrRules.push(...t), this.insertSsrRules(t));
467
+ }
468
+ }
469
+ insertSsrRules(t) {
470
+ for (const { css: e, cls: s } of t) {
471
+ const i = this.getCategory(s);
472
+ i ? this.stylePartitionManager.addCategoryRule(e, i) : this.stylePartitionManager.addRule(e);
473
+ }
432
474
  }
433
475
  injectPreflightCSS() {
434
476
  const t = this.options.config.preflight ?? !0;
@@ -436,7 +478,7 @@ class L {
436
478
  const e = this.context.getPreflightCSS(t);
437
479
  this.stylePartitionManager.updateRuleContent(
438
480
  "preflight",
439
- `${D}
481
+ `${L}
440
482
  @layer base {
441
483
  ${e}
442
484
  }`,
@@ -487,19 +529,24 @@ ${e}
487
529
  applyParseResults(t, e) {
488
530
  if (this.isDestroyed) return;
489
531
  if (this.getInsertionPoint().isConnected && this.stylePartitionManager.hasDetachedPartitions()) {
490
- const r = Array.from(this.cache.values());
491
- this.reset(), t = [...r, ...t], t.forEach((n) => this.incrementalParser.markProcessed(n.cls));
532
+ const n = Array.from(this.cache.values());
533
+ this.reset(), t = [...n, ...t], t.forEach((o) => this.incrementalParser.markProcessed(o.cls));
492
534
  }
493
- if (this.options.skipExisting && t.length > 0 && typeof document < "u") {
494
- const r = this.getExistingClasses();
495
- t = t.filter((n) => !r.has(n.cls));
535
+ if (this.ssrClasses.size > 0 && (t = t.filter((n) => !this.ssrClasses.has(n.cls))), this.options.skipExisting && t.length > 0 && typeof document < "u") {
536
+ const n = this.getExistingClasses();
537
+ t = t.filter((o) => !n.has(o.cls));
496
538
  }
497
539
  if (t.length === 0) return;
498
- const s = [], i = [];
499
- for (const r of t)
500
- if (r.css && Array.isArray(r.cssList) && (s.push(r), this.cache.set(r.cls, r)), r.rootCss && Array.isArray(r.rootCssList))
501
- for (const n of r.rootCssList)
502
- this.rootCache.has(n) || (this.rootCache.add(n), i.push(n));
540
+ const s = [], i = [], r = this.options.skipExisting && typeof document < "u" ? (this.getExistingClasses(), this.existingKeyframes) : null;
541
+ for (const n of t)
542
+ if (n.css && Array.isArray(n.cssList) && (s.push(n), this.cache.set(n.cls, n)), n.rootCss && Array.isArray(n.rootCssList))
543
+ for (const o of n.rootCssList) {
544
+ if (r?.size) {
545
+ const c = /^\s*@keyframes\s+([^\s{]+)/.exec(o)?.[1];
546
+ if (c && r.has(c)) continue;
547
+ }
548
+ this.rootCache.has(o) || (this.rootCache.add(o), i.push(o));
549
+ }
503
550
  i.length > 0 && this.stylePartitionManager.addRootRules(i.filter(Boolean)), s.length > 0 && this.stylePartitionManager.addRules(s), this.debugLog("info", `Applied ${t.length} parser results`, {
504
551
  cssRuleCount: s.length,
505
552
  rootCssCount: i.length
@@ -507,10 +554,10 @@ ${e}
507
554
  }
508
555
  /** #269: a class that must never be reclaimed. */
509
556
  isPermanent(t) {
510
- return this.pinned.has(t) || typeof document > "u" ? !0 : this.getExistingClasses().has(t);
557
+ return this.pinned.has(t) || this.ssrClasses.has(t) || typeof document > "u" ? !0 : this.getExistingClasses().has(t);
511
558
  }
512
559
  /**
513
- * #269: delete the generated rules of classes no live element uses. Root/@property rules stay
560
+ * #269: delete the generated rules of classes no live element uses. Root/@property/@keyframes rules stay
514
561
  * (they are shared and harmless); a rule text another cached class still emits is kept.
515
562
  */
516
563
  reclaim(t) {
@@ -525,36 +572,36 @@ ${e}
525
572
  for (const r of this.cache.values()) r.cssList.forEach((n) => i.add(n));
526
573
  for (const r of s) {
527
574
  const n = this.getCategory(r.cls);
528
- for (const a of r.cssList)
529
- i.has(a) || this.stylePartitionManager.removeRule(a, n);
575
+ for (const o of r.cssList)
576
+ i.has(o) || this.stylePartitionManager.removeRule(o, n);
530
577
  }
531
578
  this.reclaimedCount += e.length;
532
579
  }
533
580
  /** Class names defined by the page's own stylesheets (BaroCSS's sheets and cross-origin sheets excluded). */
534
581
  getExistingClasses() {
535
- const t = new Set(Array.from(document.querySelectorAll("style[data-barocss]"), (i) => i.sheet)), e = Array.from(document.styleSheets).filter((i) => {
536
- if (t.has(i)) return !1;
537
- const r = i.ownerNode;
538
- return !(r && typeof r.hasAttribute == "function" && (r.hasAttribute("data-barocss") || (r.id || "").startsWith(this.options.styleId)));
582
+ const t = new Set(Array.from(document.querySelectorAll("style[data-barocss]"), (r) => r.sheet)), e = Array.from(document.styleSheets).filter((r) => {
583
+ if (t.has(r)) return !1;
584
+ const n = r.ownerNode;
585
+ return !(n && typeof n.hasAttribute == "function" && (n.hasAttribute("data-barocss") || (n.id || "").startsWith(this.options.styleId)));
539
586
  });
540
587
  if (this.existing && e.length === this.existingSheetCount) return this.existing;
541
- const s = /* @__PURE__ */ new Set();
542
- for (const i of e) {
543
- let r;
588
+ const s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
589
+ for (const r of e) {
590
+ let n;
544
591
  try {
545
- r = i.cssRules;
592
+ n = r.cssRules;
546
593
  } catch {
547
594
  continue;
548
595
  }
549
- C(r, s);
596
+ g(n, s), P(n, i);
550
597
  }
551
- return this.existing = s, this.existingSheetCount = e.length, s;
598
+ return this.existingKeyframes = i, this.existing = s, this.existingSheetCount = e.length, s;
552
599
  }
553
600
  /**
554
601
  * MutationObserver instance method to automatically call addClass when class attributes change in DOM
555
602
  */
556
603
  observe(t = document.body, e) {
557
- return this.changeDetector.observe(t, e);
604
+ return this.observedOnce || (this.observedOnce = !0, this.adoptSsrSheets()), this.changeDetector.observe(t, e);
558
605
  }
559
606
  normalizeClasses(t) {
560
607
  return Array.isArray(t) ? t.flatMap((e) => e.split(/\s+/)) : t.split(/\s+/);
@@ -594,15 +641,15 @@ ${e}
594
641
  * Clear all caches (useful for debugging or memory management)
595
642
  */
596
643
  clearCaches() {
597
- this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), w(this.context), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.injectPreflightCSS(), this.ensureCssVars());
644
+ this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), x(this.context), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.injectPreflightCSS(), this.ensureCssVars(), this.insertSsrRules(this.ssrRules));
598
645
  }
599
646
  reset() {
600
- this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.injectPreflightCSS(), this.ensureCssVars());
647
+ this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager = new d(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory), this.injectPreflightCSS(), this.ensureCssVars(), this.insertSsrRules(this.ssrRules));
601
648
  }
602
649
  updateConfig(t) {
603
650
  if (this.isDestroyed) return;
604
651
  const e = Array.from(this.cache.keys());
605
- this.options.config = t, this.context = m(t), this.incrementalParser = new p(this.context), this.changeDetector.setParser(this.incrementalParser), this.reset(), e.length > 0 && this.addClass(e);
652
+ this.options.config = t, this.context = p(t), this.incrementalParser = new C(this.context), this.changeDetector.setParser(this.incrementalParser), this.reset(), e.length > 0 && this.addClass(e);
606
653
  }
607
654
  removeClass(t) {
608
655
  if (this.isDestroyed) return;
@@ -623,27 +670,27 @@ ${e}
623
670
  }
624
671
  }
625
672
  let h = null, f;
626
- function N(o = {}) {
627
- return !h || h.getStats().isDestroyed ? (h = new L(o), f = o.config) : o.config && o.config !== f && (h.updateConfig(o.config), f = o.config), h;
673
+ function I(a = {}) {
674
+ return !h || h.getStats().isDestroyed ? (h = new N(a), f = a.config) : a.config && a.config !== f && (h.updateConfig(a.config), f = a.config), h;
628
675
  }
629
- function P({ loadingClassName: o = "baro-boot", ...t } = {}) {
676
+ function R({ loadingClassName: a = "baro-boot", ...t } = {}) {
630
677
  if (!document.body) {
631
- document.addEventListener("DOMContentLoaded", () => P({ loadingClassName: o, ...t }), { once: !0 });
678
+ document.addEventListener("DOMContentLoaded", () => R({ loadingClassName: a, ...t }), { once: !0 });
632
679
  return;
633
680
  }
634
- const e = `${o}-doing`, s = `${o}-done`;
681
+ const e = `${a}-doing`, s = `${a}-done`;
635
682
  try {
636
- document.body.classList.add(e), N(t).observe(document.body, { scan: !0, onReady: () => {
683
+ document.body.classList.add(e), I(t).observe(document.body, { scan: !0, onReady: () => {
637
684
  document.body.classList.remove(e), document.body.classList.add(s);
638
685
  } });
639
686
  } catch (i) {
640
687
  document.body?.classList.remove(e), console.error("BaroCSS boot failed:", i);
641
688
  }
642
689
  }
643
- const z = P;
644
- function T(o) {
645
- if (!o || typeof o != "object" || Array.isArray(o)) return [];
646
- const t = o.elements;
690
+ const $ = R;
691
+ function k(a) {
692
+ if (!a || typeof a != "object" || Array.isArray(a)) return [];
693
+ const t = a.elements;
647
694
  if (!t || typeof t != "object" || Array.isArray(t)) return [];
648
695
  const e = /* @__PURE__ */ new Set();
649
696
  for (const s of Object.keys(t)) {
@@ -653,16 +700,16 @@ function T(o) {
653
700
  if (!r || typeof r != "object" || Array.isArray(r)) continue;
654
701
  const n = r.className;
655
702
  if (typeof n == "string")
656
- for (const a of n.split(/\s+/))
657
- a && e.add(a);
703
+ for (const o of n.split(/\s+/))
704
+ o && e.add(o);
658
705
  }
659
706
  return Array.from(e);
660
707
  }
661
- function B(o, t) {
662
- const e = T(o);
708
+ function j(a, t) {
709
+ const e = k(a);
663
710
  e.length > 0 && t.addClass(e);
664
711
  }
665
- const I = [
712
+ const z = [
666
713
  "background",
667
714
  "foreground",
668
715
  "card",
@@ -694,8 +741,8 @@ const I = [
694
741
  "sidebar-accent-foreground",
695
742
  "sidebar-border",
696
743
  "sidebar-ring"
697
- ], $ = {
698
- colors: Object.fromEntries(I.map((o) => [o, `var(--${o})`])),
744
+ ], O = {
745
+ colors: Object.fromEntries(z.map((a) => [a, `var(--${a})`])),
699
746
  borderRadius: {
700
747
  sm: "calc(var(--radius) - 4px)",
701
748
  md: "calc(var(--radius) - 2px)",
@@ -704,16 +751,17 @@ const I = [
704
751
  }
705
752
  };
706
753
  export {
707
- L as BrowserRuntime,
754
+ N as BrowserRuntime,
708
755
  E as ChangeDetector,
709
- D as LAYER_ORDER,
756
+ L as LAYER_ORDER,
757
+ D as SSR_STYLE_SELECTOR,
710
758
  d as StylePartitionManager,
711
- P as baroBoot,
712
- z as baroStart,
713
- T as collectJsonRenderClassNames,
714
- N as getRuntime,
715
- x as normalizeClassName,
759
+ R as baroBoot,
760
+ $ as baroStart,
761
+ k as collectJsonRenderClassNames,
762
+ I as getRuntime,
763
+ w as normalizeClassName,
716
764
  u as normalizeClassNameList,
717
- B as preloadJsonRenderClasses,
718
- $ as shadcnTheme
765
+ j as preloadJsonRenderClasses,
766
+ O as shadcnTheme
719
767
  };