@barocss/browser 0.10.3 → 0.11.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/cdn/barocss.js +1 -1
- package/dist/cdn/barocss.js.map +1 -1
- package/dist/cdn/barocss.umd.cjs +1 -1
- package/dist/cdn/barocss.umd.cjs.map +1 -1
- package/dist/index.cjs +10 -7
- package/dist/index.d.cts +39 -25
- package/dist/index.d.ts +39 -25
- package/dist/index.es.js +106 -105
- package/dist/index.umd.js +10 -7
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { IncrementalParser as e, clearAstCache as t, compareKeys as n, createContext as r, isDebug as i, parseClassName as a, ruleSortKey as o, upperBound as s } from "@barocss/kit";
|
|
2
2
|
//#region src/style-partition-manager.ts
|
|
3
3
|
var c = class {
|
|
4
|
-
insertSorted(e, t, n) {
|
|
5
|
-
let r = e.keys ??= [], i = s(r, n), a = e.styleElement.sheet;
|
|
6
|
-
a && a.cssRules.length === r.length ? (a.insertRule(this.escapeCssRule(t), i), e.styles.splice(i, 0, t)) : (e.styles.splice(i, 0, t), e.styleElement.textContent = e.styles.join("\n") + "\n"), r.splice(i, 0, n);
|
|
7
|
-
}
|
|
8
4
|
constructor(e, t = 50, n = "barocss-style-partition-", r = (e) => a(e).utility?.category, i = "") {
|
|
9
|
-
this.
|
|
5
|
+
this.segments = [], this.specialPartitions = /* @__PURE__ */ new Map(), this.ruleSegment = /* @__PURE__ */ new Map(), this.partitionCounter = 0, this.maxRulesPerPartition = 50, this.styleIdPrefix = "barocss-style-partition-", this.nonce = i, this.insertionPoint = e, this.maxRulesPerPartition = t, this.styleIdPrefix = n, this.getCategory = r, this.segments.push(this.createSegment(void 0, null));
|
|
10
6
|
}
|
|
11
7
|
createStyleElement() {
|
|
12
8
|
let e = document.createElement("style");
|
|
13
9
|
return this.nonce && e.setAttribute("nonce", this.nonce), e;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
this.
|
|
11
|
+
createSegment(e, t) {
|
|
12
|
+
let n = this.createStyleElement(), r = {
|
|
13
|
+
id: e === void 0 ? this.styleIdPrefix + `-${this.partitionCounter++}` : this.styleIdPrefix + `-${e}`,
|
|
14
|
+
styles: [],
|
|
15
|
+
keys: [],
|
|
16
|
+
styleElement: n,
|
|
17
|
+
category: e
|
|
18
|
+
};
|
|
19
|
+
n.id = r.id, n.setAttribute("data-barocss", "partition"), e === void 0 ? n.setAttribute("data-partition-index", this.partitionCounter.toString()) : n.setAttribute("data-category", e);
|
|
20
|
+
let i = t ? t.styleElement : null, a = this.segments[0]?.styleElement;
|
|
21
|
+
return i?.parentNode ? i.parentNode.insertBefore(n, i.nextSibling) : !t && a?.parentNode ? a.parentNode.insertBefore(n, a) : this.insertionPoint.appendChild(n), r;
|
|
17
22
|
}
|
|
18
|
-
|
|
23
|
+
createSpecialPartition(e, t = !1) {
|
|
19
24
|
let n = {
|
|
20
25
|
id: this.styleIdPrefix + `-${e}`,
|
|
21
26
|
styles: [],
|
|
@@ -23,90 +28,99 @@ var c = class {
|
|
|
23
28
|
};
|
|
24
29
|
n.styleElement.id = n.id, n.styleElement.setAttribute("data-barocss", "partition"), n.styleElement.setAttribute("data-category", e);
|
|
25
30
|
let r = this.insertionPoint.ownerDocument?.head;
|
|
26
|
-
return t && r ? r.insertBefore(n.styleElement, r.firstChild) : this.insertionPoint.appendChild(n.styleElement), this.
|
|
27
|
-
}
|
|
28
|
-
createNewPartition() {
|
|
29
|
-
let e = this.partitions[this.partitions.length - 1], t = {
|
|
30
|
-
id: this.styleIdPrefix + `-${this.partitionCounter++}`,
|
|
31
|
-
styles: [],
|
|
32
|
-
styleElement: this.createStyleElement()
|
|
33
|
-
};
|
|
34
|
-
this.partitions.push(t), t.styleElement.id = t.id, t.styleElement.setAttribute("data-barocss", "partition"), t.styleElement.setAttribute("data-partition-index", this.partitionCounter.toString());
|
|
35
|
-
let n = e?.styleElement.parentNode;
|
|
36
|
-
return n ? n.insertBefore(t.styleElement, e.styleElement.nextSibling) : this.insertionPoint.appendChild(t.styleElement), t;
|
|
37
|
-
}
|
|
38
|
-
hasRule(e) {
|
|
39
|
-
return this.classToPartitionMap.has(e);
|
|
40
|
-
}
|
|
41
|
-
hasCategoryRule(e, t) {
|
|
42
|
-
return this.classToCategoryPartitionMap.get(e) === t;
|
|
43
|
-
}
|
|
44
|
-
setRuleCache(e, t) {
|
|
45
|
-
this.classToPartitionMap.set(e, t);
|
|
46
|
-
}
|
|
47
|
-
setCategoryRuleCache(e, t) {
|
|
48
|
-
this.classToCategoryPartitionMap.set(e, t);
|
|
31
|
+
return t && r ? r.insertBefore(n.styleElement, r.firstChild) : this.insertionPoint.appendChild(n.styleElement), this.specialPartitions.set(e, n), n;
|
|
49
32
|
}
|
|
50
33
|
get currentPartition() {
|
|
51
|
-
return this.
|
|
34
|
+
return this.segments[this.segments.length - 1];
|
|
52
35
|
}
|
|
53
36
|
getCategoryPartition(e) {
|
|
54
|
-
return this.
|
|
37
|
+
return this.specialPartitions.get(e) ?? this.segments.find((t) => t.category === e);
|
|
55
38
|
}
|
|
56
39
|
hasDetachedPartitions() {
|
|
57
|
-
return [...this.
|
|
40
|
+
return [...this.segments, ...this.specialPartitions.values()].some((e) => !e.styleElement.isConnected);
|
|
58
41
|
}
|
|
59
42
|
escapeCssRule(e) {
|
|
60
43
|
return e.replace(/\\\//g, "\\/");
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
insertAt(e, t, n, r) {
|
|
46
|
+
let i = e.keys ??= [], a = e.styleElement.sheet;
|
|
47
|
+
a && a.cssRules.length === i.length ? (a.insertRule(this.escapeCssRule(n), t), e.styles.splice(t, 0, n)) : (e.styles.splice(t, 0, n), e.styleElement.textContent = e.styles.join("\n") + "\n"), i.splice(t, 0, r), this.ruleSegment.set(n, e);
|
|
48
|
+
}
|
|
49
|
+
split(e, t) {
|
|
50
|
+
let n = this.segments[e], r = this.createSegment(n.category, n);
|
|
51
|
+
this.segments.splice(e + 1, 0, r);
|
|
52
|
+
let i = n.styles.splice(t), a = n.keys.splice(t), o = n.styleElement.sheet;
|
|
53
|
+
if (o && o.cssRules.length === n.styles.length + i.length) for (let e = o.cssRules.length - 1; e >= t; e--) o.deleteRule(e);
|
|
54
|
+
else n.styleElement.textContent = n.styles.length ? n.styles.join("\n") + "\n" : "";
|
|
55
|
+
r.styles = i, r.keys = a, r.styleElement.textContent = i.length ? i.join("\n") + "\n" : "";
|
|
56
|
+
for (let e of i) this.ruleSegment.set(e, r);
|
|
57
|
+
return r;
|
|
58
|
+
}
|
|
59
|
+
hasRoom(e) {
|
|
60
|
+
return e.styles.length < this.maxRulesPerPartition;
|
|
61
|
+
}
|
|
62
|
+
place(e, t, r) {
|
|
63
|
+
if (this.ruleSegment.has(e)) return !1;
|
|
64
|
+
let i = o(e, r), a = this.segments.findIndex((e) => {
|
|
65
|
+
let t = e.keys;
|
|
66
|
+
return t.length > 0 && n(t[t.length - 1], i) > 0;
|
|
67
67
|
});
|
|
68
|
-
|
|
69
|
-
let
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
a === -1 && (a = this.segments.length);
|
|
69
|
+
let c = a < this.segments.length ? s(this.segments[a].keys, i) : 0, l = this.segments.some((e) => e.category === t);
|
|
70
|
+
if (c > 0) {
|
|
71
|
+
let n = this.segments[a];
|
|
72
|
+
if (l && this.hasRoom(n) || (this.split(a, c), l)) return this.insertAt(n, c, e, i), !0;
|
|
73
|
+
let r = this.createSegment(t, n);
|
|
74
|
+
return this.segments.splice(a + 1, 0, r), this.insertAt(r, 0, e, i), !0;
|
|
75
|
+
}
|
|
76
|
+
let u = a - 1;
|
|
77
|
+
for (; u > 0 && this.segments[u].styles.length === 0;) u--;
|
|
78
|
+
let d = [];
|
|
79
|
+
if (l) for (let e = Math.max(u, 0); e <= a && e < this.segments.length; e++) this.hasRoom(this.segments[e]) && d.push(e);
|
|
80
|
+
let f = d.find((e) => this.segments[e].category === t) ?? d[0];
|
|
81
|
+
if (f !== void 0) {
|
|
82
|
+
let t = this.segments[f];
|
|
83
|
+
return this.insertAt(t, f === a ? 0 : t.styles.length, e, i), !0;
|
|
84
|
+
}
|
|
85
|
+
let p = a > 0 ? this.segments[a - 1] : null, m = this.createSegment(t, p);
|
|
86
|
+
return this.segments.splice(a, 0, m), this.insertAt(m, 0, e, i), !0;
|
|
87
|
+
}
|
|
88
|
+
hasRule(e) {
|
|
89
|
+
return this.ruleSegment.has(e);
|
|
90
|
+
}
|
|
91
|
+
hasCategoryRule(e, t) {
|
|
92
|
+
return this.ruleSegment.has(e);
|
|
75
93
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
addRule(e, t) {
|
|
95
|
+
return this.tryPlace(e, void 0, t);
|
|
96
|
+
}
|
|
97
|
+
addCategoryRule(e, t, n) {
|
|
98
|
+
return this.tryPlace(e, t, n);
|
|
99
|
+
}
|
|
100
|
+
tryPlace(e, t, n) {
|
|
80
101
|
try {
|
|
81
|
-
this.
|
|
102
|
+
return this.place(e, t, n);
|
|
82
103
|
} catch (n) {
|
|
83
|
-
return i() && console.warn(`[StylePartitionManager] Failed to insert rule in category: ${t} ${e}`, n), !1;
|
|
104
|
+
return i() && console.warn(`[StylePartitionManager] Failed to insert rule${t ? ` in category: ${t}` : ""}: ${e}`, n), !1;
|
|
84
105
|
}
|
|
85
|
-
return this.setCategoryRuleCache(e, t), !0;
|
|
86
106
|
}
|
|
87
107
|
addRootRules(e) {
|
|
88
|
-
let t = this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} catch (t) {
|
|
94
|
-
return i() && console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${e.join("\n")}`, t), {
|
|
95
|
-
success: 0,
|
|
96
|
-
failed: e.length
|
|
97
|
-
};
|
|
108
|
+
let t = this.specialPartitions.get("root") ?? this.createSpecialPartition("root"), n = t.styleElement.sheet, r = 0, a = 0;
|
|
109
|
+
for (let o of e) if (o && o.trim()) try {
|
|
110
|
+
n ? n.insertRule(this.escapeCssRule(o), n.cssRules.length) : t.styleElement.textContent += o + "\n", r++;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
a++, i() && console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${o}`, e);
|
|
98
113
|
}
|
|
99
114
|
return {
|
|
100
|
-
success:
|
|
101
|
-
failed:
|
|
115
|
+
success: r,
|
|
116
|
+
failed: a
|
|
102
117
|
};
|
|
103
118
|
}
|
|
104
119
|
addRules(e) {
|
|
105
120
|
let t = 0, n = 0;
|
|
106
121
|
for (let r of e) {
|
|
107
122
|
let e = this.getCategory(r.cls);
|
|
108
|
-
|
|
109
|
-
else for (let e of r.cssList) this.addRule(e) ? t++ : n++;
|
|
123
|
+
for (let i of r.cssList) e ? this.addCategoryRule(i, e, r.cls) : this.addRule(i, r.cls) ? t++ : n++;
|
|
110
124
|
}
|
|
111
125
|
return {
|
|
112
126
|
success: t,
|
|
@@ -114,43 +128,30 @@ var c = class {
|
|
|
114
128
|
};
|
|
115
129
|
}
|
|
116
130
|
removeRule(e, t) {
|
|
117
|
-
let n;
|
|
118
|
-
if (t) {
|
|
119
|
-
if (this.classToCategoryPartitionMap.get(e) !== t) return !1;
|
|
120
|
-
n = this.categoryPartitions.get(t);
|
|
121
|
-
} else {
|
|
122
|
-
let t = this.classToPartitionMap.get(e);
|
|
123
|
-
n = t === void 0 ? void 0 : this.partitions[t];
|
|
124
|
-
}
|
|
131
|
+
let n = this.ruleSegment.get(e);
|
|
125
132
|
if (!n) return !1;
|
|
126
133
|
let r = n.styles.indexOf(e);
|
|
127
134
|
if (r === -1) return !1;
|
|
128
135
|
let i = n.styleElement.sheet, a = !!i && i.cssRules.length === n.styles.length;
|
|
129
|
-
return n.styles.splice(r, 1), n.keys?.splice(r, 1), a && i ? i.deleteRule(r) : n.styleElement.textContent = n.styles.length ? n.styles.join("\n") + "\n" : "",
|
|
136
|
+
return n.styles.splice(r, 1), n.keys?.splice(r, 1), a && i ? i.deleteRule(r) : n.styleElement.textContent = n.styles.length ? n.styles.join("\n") + "\n" : "", this.ruleSegment.delete(e), !0;
|
|
130
137
|
}
|
|
131
138
|
get ruleCount() {
|
|
132
|
-
return this.
|
|
139
|
+
return this.ruleSegment.size;
|
|
133
140
|
}
|
|
134
141
|
findRulePartition(e) {
|
|
135
|
-
|
|
136
|
-
if (t !== void 0 && this.partitions[t]) return this.partitions[t];
|
|
137
|
-
let n = this.classToCategoryPartitionMap.get(e);
|
|
138
|
-
return n === void 0 ? null : this.categoryPartitions.get(n) || null;
|
|
142
|
+
return this.ruleSegment.get(e) ?? null;
|
|
139
143
|
}
|
|
140
144
|
updateRuleContent(e, t, n = !1) {
|
|
141
|
-
let r = this.
|
|
145
|
+
let r = this.specialPartitions.get(e);
|
|
142
146
|
if (r) r.styleElement.textContent = t;
|
|
143
147
|
else {
|
|
144
|
-
let r = this.
|
|
148
|
+
let r = this.createSpecialPartition(e, n);
|
|
145
149
|
i() && console.log(`[StylePartitionManager] Created new partition for category: ${e}`), r.styleElement.textContent = t;
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
152
|
cleanup() {
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
}), this.categoryPartitions.forEach((e) => {
|
|
152
|
-
e.styleElement.parentNode && e.styleElement.parentNode.removeChild(e.styleElement);
|
|
153
|
-
}), this.partitions = [], this.categoryPartitions.clear(), this.partitionCounter = 0, this.classToPartitionMap.clear(), this.classToCategoryPartitionMap.clear();
|
|
153
|
+
for (let e of [...this.segments, ...this.specialPartitions.values()]) e.styleElement.parentNode?.removeChild(e.styleElement);
|
|
154
|
+
this.segments = [], this.specialPartitions.clear(), this.partitionCounter = 0, this.ruleSegment.clear();
|
|
154
155
|
}
|
|
155
156
|
}, l = /[ \t\n\f\r]+/;
|
|
156
157
|
function u(e) {
|
|
@@ -468,21 +469,21 @@ var O = class {
|
|
|
468
469
|
}
|
|
469
470
|
return t;
|
|
470
471
|
}
|
|
471
|
-
retain(e, t) {
|
|
472
|
-
let
|
|
473
|
-
if (
|
|
474
|
-
let
|
|
475
|
-
|
|
472
|
+
retain(e, t, n) {
|
|
473
|
+
let r = this.refs.get(e);
|
|
474
|
+
if (r !== void 0) return this.refs.set(e, r + 1), !0;
|
|
475
|
+
let a = this.segments.get(t);
|
|
476
|
+
a || (a = {
|
|
476
477
|
rules: [],
|
|
477
478
|
keys: []
|
|
478
|
-
}, this.segments.set(t,
|
|
479
|
-
let
|
|
479
|
+
}, this.segments.set(t, a));
|
|
480
|
+
let c = t === "root", l = o(e, n), u = c ? a.rules.length : s(a.keys, l), d = this.offset(a) + u;
|
|
480
481
|
try {
|
|
481
|
-
this.insertAt(e,
|
|
482
|
+
this.insertAt(e, d);
|
|
482
483
|
} catch (t) {
|
|
483
484
|
return i() && console.warn(`[BrowserRuntime] Failed to insert rule into shadow root sheet: ${e}`, t), !1;
|
|
484
485
|
}
|
|
485
|
-
return
|
|
486
|
+
return a.rules.splice(u, 0, e), a.keys.splice(u, 0, l), this.refs.set(e, 1), !0;
|
|
486
487
|
}
|
|
487
488
|
release(e) {
|
|
488
489
|
let t = this.refs.get(e);
|
|
@@ -560,14 +561,14 @@ var M = class extends e {
|
|
|
560
561
|
updateRuleContent(e, t) {
|
|
561
562
|
e === "preflight" ? this.shared.setPrologue("preflight", this.scopePreflight ? y(t) : t) : e === "css-vars" && this.shared.setPrologue("vars", t);
|
|
562
563
|
}
|
|
563
|
-
take(e, t) {
|
|
564
|
-
return this.owned.has(e) || (this.root.nodeType === 11 && w.test(e) && (E(this.root.ownerDocument ?? (typeof document < "u" ? document : null), [e], this.opts) || this.shared.addPropertyFallback([e])), !this.shared.retain(e, t)) ? !1 : (this.owned.add(e), !0);
|
|
564
|
+
take(e, t, n) {
|
|
565
|
+
return this.owned.has(e) || (this.root.nodeType === 11 && w.test(e) && (E(this.root.ownerDocument ?? (typeof document < "u" ? document : null), [e], this.opts) || this.shared.addPropertyFallback([e])), !this.shared.retain(e, t, n)) ? !1 : (this.owned.add(e), !0);
|
|
565
566
|
}
|
|
566
|
-
addRule(e) {
|
|
567
|
-
return this.take(e, "");
|
|
567
|
+
addRule(e, t) {
|
|
568
|
+
return this.take(e, "", t);
|
|
568
569
|
}
|
|
569
|
-
addCategoryRule(e, t) {
|
|
570
|
-
return this.take(e,
|
|
570
|
+
addCategoryRule(e, t, n) {
|
|
571
|
+
return this.take(e, "", n);
|
|
571
572
|
}
|
|
572
573
|
addRootRules(e) {
|
|
573
574
|
let t = 0;
|
|
@@ -581,7 +582,7 @@ var M = class extends e {
|
|
|
581
582
|
let t = 0, n = 0;
|
|
582
583
|
for (let r of e) {
|
|
583
584
|
let e = this.getCategory(r.cls);
|
|
584
|
-
for (let i of r.cssList) (e ? this.addCategoryRule(i, e) : this.addRule(i)) ? t++ : n++;
|
|
585
|
+
for (let i of r.cssList) (e ? this.addCategoryRule(i, e, r.cls) : this.addRule(i, r.cls)) ? t++ : n++;
|
|
585
586
|
}
|
|
586
587
|
return {
|
|
587
588
|
success: t,
|
|
@@ -667,7 +668,7 @@ var M = class extends e {
|
|
|
667
668
|
insertSsrRules(e) {
|
|
668
669
|
for (let { css: t, cls: n } of e) {
|
|
669
670
|
let e = this.getCategory(n);
|
|
670
|
-
e ? this.stylePartitionManager.addCategoryRule(t, e) : this.stylePartitionManager.addRule(t);
|
|
671
|
+
e ? this.stylePartitionManager.addCategoryRule(t, e, n) : this.stylePartitionManager.addRule(t, n);
|
|
671
672
|
}
|
|
672
673
|
}
|
|
673
674
|
injectPreflightCSS() {
|
package/dist/index.umd.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@barocss/kit")):typeof define==`function`&&define.amd?define([`exports`,`@barocss/kit`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.BaroCSSBrowser={},e.BaroCSSKit))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=class{
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@barocss/kit")):typeof define==`function`&&define.amd?define([`exports`,`@barocss/kit`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.BaroCSSBrowser={},e.BaroCSSKit))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=class{constructor(e,n=50,r=`barocss-style-partition-`,i=e=>(0,t.parseClassName)(e).utility?.category,a=``){this.segments=[],this.specialPartitions=new Map,this.ruleSegment=new Map,this.partitionCounter=0,this.maxRulesPerPartition=50,this.styleIdPrefix=`barocss-style-partition-`,this.nonce=a,this.insertionPoint=e,this.maxRulesPerPartition=n,this.styleIdPrefix=r,this.getCategory=i,this.segments.push(this.createSegment(void 0,null))}createStyleElement(){let e=document.createElement(`style`);return this.nonce&&e.setAttribute(`nonce`,this.nonce),e}createSegment(e,t){let n=this.createStyleElement(),r={id:e===void 0?this.styleIdPrefix+`-${this.partitionCounter++}`:this.styleIdPrefix+`-${e}`,styles:[],keys:[],styleElement:n,category:e};n.id=r.id,n.setAttribute(`data-barocss`,`partition`),e===void 0?n.setAttribute(`data-partition-index`,this.partitionCounter.toString()):n.setAttribute(`data-category`,e);let i=t?t.styleElement:null,a=this.segments[0]?.styleElement;return i?.parentNode?i.parentNode.insertBefore(n,i.nextSibling):!t&&a?.parentNode?a.parentNode.insertBefore(n,a):this.insertionPoint.appendChild(n),r}createSpecialPartition(e,t=!1){let n={id:this.styleIdPrefix+`-${e}`,styles:[],styleElement:this.createStyleElement()};n.styleElement.id=n.id,n.styleElement.setAttribute(`data-barocss`,`partition`),n.styleElement.setAttribute(`data-category`,e);let r=this.insertionPoint.ownerDocument?.head;return t&&r?r.insertBefore(n.styleElement,r.firstChild):this.insertionPoint.appendChild(n.styleElement),this.specialPartitions.set(e,n),n}get currentPartition(){return this.segments[this.segments.length-1]}getCategoryPartition(e){return this.specialPartitions.get(e)??this.segments.find(t=>t.category===e)}hasDetachedPartitions(){return[...this.segments,...this.specialPartitions.values()].some(e=>!e.styleElement.isConnected)}escapeCssRule(e){return e.replace(/\\\//g,`\\/`)}insertAt(e,t,n,r){let i=e.keys??=[],a=e.styleElement.sheet;a&&a.cssRules.length===i.length?(a.insertRule(this.escapeCssRule(n),t),e.styles.splice(t,0,n)):(e.styles.splice(t,0,n),e.styleElement.textContent=e.styles.join(`
|
|
2
2
|
`)+`
|
|
3
|
-
`),i.splice(
|
|
4
|
-
`}catch(n){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${e.join(`
|
|
5
|
-
`)}`,n),{success:0,failed:e.length}}return{success:e.length,failed:0}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);if(e)for(let t of r.cssList)this.addCategoryRule(t,e);else for(let e of r.cssList)this.addRule(e)?t++:n++}return{success:t,failed:n}}removeRule(e,t){let n;if(t){if(this.classToCategoryPartitionMap.get(e)!==t)return!1;n=this.categoryPartitions.get(t)}else{let t=this.classToPartitionMap.get(e);n=t===void 0?void 0:this.partitions[t]}if(!n)return!1;let r=n.styles.indexOf(e);if(r===-1)return!1;let i=n.styleElement.sheet,a=!!i&&i.cssRules.length===n.styles.length;return n.styles.splice(r,1),n.keys?.splice(r,1),a&&i?i.deleteRule(r):n.styleElement.textContent=n.styles.length?n.styles.join(`
|
|
3
|
+
`),i.splice(t,0,r),this.ruleSegment.set(n,e)}split(e,t){let n=this.segments[e],r=this.createSegment(n.category,n);this.segments.splice(e+1,0,r);let i=n.styles.splice(t),a=n.keys.splice(t),o=n.styleElement.sheet;if(o&&o.cssRules.length===n.styles.length+i.length)for(let e=o.cssRules.length-1;e>=t;e--)o.deleteRule(e);else n.styleElement.textContent=n.styles.length?n.styles.join(`
|
|
6
4
|
`)+`
|
|
7
|
-
|
|
5
|
+
`:``;r.styles=i,r.keys=a,r.styleElement.textContent=i.length?i.join(`
|
|
6
|
+
`)+`
|
|
7
|
+
`:``;for(let e of i)this.ruleSegment.set(e,r);return r}hasRoom(e){return e.styles.length<this.maxRulesPerPartition}place(e,n,r){if(this.ruleSegment.has(e))return!1;let i=(0,t.ruleSortKey)(e,r),a=this.segments.findIndex(e=>{let n=e.keys;return n.length>0&&(0,t.compareKeys)(n[n.length-1],i)>0});a===-1&&(a=this.segments.length);let o=a<this.segments.length?(0,t.upperBound)(this.segments[a].keys,i):0,s=this.segments.some(e=>e.category===n);if(o>0){let t=this.segments[a];if(s&&this.hasRoom(t)||(this.split(a,o),s))return this.insertAt(t,o,e,i),!0;let r=this.createSegment(n,t);return this.segments.splice(a+1,0,r),this.insertAt(r,0,e,i),!0}let c=a-1;for(;c>0&&this.segments[c].styles.length===0;)c--;let l=[];if(s)for(let e=Math.max(c,0);e<=a&&e<this.segments.length;e++)this.hasRoom(this.segments[e])&&l.push(e);let u=l.find(e=>this.segments[e].category===n)??l[0];if(u!==void 0){let t=this.segments[u];return this.insertAt(t,u===a?0:t.styles.length,e,i),!0}let d=a>0?this.segments[a-1]:null,f=this.createSegment(n,d);return this.segments.splice(a,0,f),this.insertAt(f,0,e,i),!0}hasRule(e){return this.ruleSegment.has(e)}hasCategoryRule(e,t){return this.ruleSegment.has(e)}addRule(e,t){return this.tryPlace(e,void 0,t)}addCategoryRule(e,t,n){return this.tryPlace(e,t,n)}tryPlace(e,n,r){try{return this.place(e,n,r)}catch(r){return(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule${n?` in category: ${n}`:``}: ${e}`,r),!1}}addRootRules(e){let n=this.specialPartitions.get(`root`)??this.createSpecialPartition(`root`),r=n.styleElement.sheet,i=0,a=0;for(let o of e)if(o&&o.trim())try{r?r.insertRule(this.escapeCssRule(o),r.cssRules.length):n.styleElement.textContent+=o+`
|
|
8
|
+
`,i++}catch(e){a++,(0,t.isDebug)()&&console.warn(`[StylePartitionManager] Failed to insert rule in category: root ${o}`,e)}return{success:i,failed:a}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)e?this.addCategoryRule(i,e,r.cls):this.addRule(i,r.cls)?t++:n++}return{success:t,failed:n}}removeRule(e,t){let n=this.ruleSegment.get(e);if(!n)return!1;let r=n.styles.indexOf(e);if(r===-1)return!1;let i=n.styleElement.sheet,a=!!i&&i.cssRules.length===n.styles.length;return n.styles.splice(r,1),n.keys?.splice(r,1),a&&i?i.deleteRule(r):n.styleElement.textContent=n.styles.length?n.styles.join(`
|
|
9
|
+
`)+`
|
|
10
|
+
`:``,this.ruleSegment.delete(e),!0}get ruleCount(){return this.ruleSegment.size}findRulePartition(e){return this.ruleSegment.get(e)??null}updateRuleContent(e,n,r=!1){let i=this.specialPartitions.get(e);if(i)i.styleElement.textContent=n;else{let i=this.createSpecialPartition(e,r);(0,t.isDebug)()&&console.log(`[StylePartitionManager] Created new partition for category: ${e}`),i.styleElement.textContent=n}}cleanup(){for(let e of[...this.segments,...this.specialPartitions.values()])e.styleElement.parentNode?.removeChild(e.styleElement);this.segments=[],this.specialPartitions.clear(),this.partitionCounter=0,this.ruleSegment.clear()}},r=/[ \t\n\f\r]+/;function i(e){return e?typeof e==`object`&&typeof e.baseVal==`string`?e.baseVal:e.toString():``}function a(e){return e?i(e).split(r).filter(Boolean):[]}var o=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category){this.observer=null,this.gc=null,this.incrementalParser=e,this.BrowserRuntime=n,this.getCategory=r}setGc(e){this.gc=e}setParser(e){this.incrementalParser=e}observe(e=document.body,t){return typeof window>`u`?new MutationObserver(()=>{}):(this.observer&&this.observer.disconnect(),this.gc?.setRoot(e),this.observer=new MutationObserver(t=>{let n=new Set,r=this.gc;if(t.forEach(t=>{if(r&&(t.type===`attributes`?r.reconcile(t.target):t.type===`childList`&&(t.removedNodes.forEach(e=>r.reconcileTree(e)),t.addedNodes.forEach(e=>r.reconcileTree(e)))),t.type===`attributes`&&t.attributeName===`class`&&e.contains(t.target)){let e=t.target;e.className&&a(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)})}t.type===`childList`&&t.addedNodes.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE&&e.contains(t)){let e=t;this.processElement(e,n),e.querySelectorAll(`[class]`).forEach(e=>{this.processElement(e,n)})}})}),n.size>0){let e=Array.from(n),t=this.incrementalParser.processClasses(e);this.BrowserRuntime?.applyParseResults(t)}else this.BrowserRuntime?.applyParseResults([]);r?.afterBatch()}),this.observer.observe(e,{attributes:!0,subtree:!0,attributeFilter:[`class`],childList:!0}),t?.scan&&this.scanExistingClasses(e,t),this.observer)}scanExistingClasses(e,t){let n=new Set,r=e.className;r&&a(r).forEach(e=>{this.incrementalParser.isProcessed(e)||n.add(e)});let i=e.querySelectorAll(`[class]`);for(let e of i)if(e.className){let t=a(e.className);for(let e of t)this.incrementalParser.isProcessed(e)||n.add(e)}if(n.size>0){let e=Array.from(n),r=this.incrementalParser.processClasses(e),i=r.filter(e=>this.getCategory(e.cls)===`layout`),a=r.filter(e=>this.getCategory(e.cls)!==`layout`);this.BrowserRuntime?.applyParseResults(i),t?.onReady?.(),this.BrowserRuntime?.applyParseResults(a)}else t?.onReady?.()}processElement(e,t){e.className&&a(e.className).forEach(e=>{this.incrementalParser.isProcessed(e)||t.add(e)})}disconnect(){this.observer&&=(this.observer.disconnect(),null)}};function s(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,t,n)=>t?String.fromCodePoint(parseInt(t,16)):n)}var c=/^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;function l(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];a===`\\`?i++:a===`(`||a===`[`?n++:a===`)`||a===`]`?n--:a===`,`&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function u(e,t=new Set){for(let n of Array.from(e)){if(n.type===7&&typeof n.name==`string`){t.add(n.name);continue}let e=n.cssRules;e&&e.length&&u(e,t)}return t}function d(e,t=new Set){for(let n of Array.from(e)){let e=n.selectorText;if(typeof e==`string`)for(let n of l(e)){let e=c.exec(n);e&&t.add(s(e[1]))}let r=n.cssRules;r&&r.length&&d(r,t)}return t}var f=class{constructor(e,t,n,r=()=>Date.now()){this.host=e,this.graceMs=t,this.maxRules=n,this.now=r,this.counts=new Map,this.counted=new WeakMap,this.candidates=new Map,this.timer=null,this.root=null}setRoot(e){this.counts.clear(),this.counted=new WeakMap,this.candidates.clear(),this.cancel(),this.root=e,e.nodeType===1?this.reconcileTree(e):e.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}count(e){return this.counts.get(e)??0}reconcileTree(e){if(e.nodeType!==1)return;let t=e;this.reconcile(t),t.querySelectorAll(`[class]`).forEach(e=>this.reconcile(e))}reconcile(e){let t=this.root,n=t&&t.contains(e)?Array.from(new Set(a(e.getAttribute(`class`)))):[],r=this.counted.get(e);if(!r&&n.length===0)return;let i=new Set(r??[]),o=new Set(n);for(let e of o){if(i.has(e))continue;let t=(this.counts.get(e)??0)+1;this.counts.set(e,t),this.candidates.delete(e)}for(let e of i){if(o.has(e))continue;let t=(this.counts.get(e)??0)-1;t>0?this.counts.set(e,t):(this.counts.delete(e),this.candidates.delete(e),this.candidates.set(e,this.now()))}n.length?this.counted.set(e,n):this.counted.delete(e)}afterBatch(){this.candidates.size!==0&&(this.host.cachedCount()>this.maxRules?this.schedule(0):this.schedule(this.graceMs))}schedule(e){if(this.timer!==null){if(e>0)return;clearTimeout(this.timer)}this.timer=setTimeout(()=>{this.timer=null,this.sweep()},e)}sweep(){let e=this.now(),t=Math.max(0,this.host.cachedCount()-this.maxRules),n=[],r=0;for(let[i,a]of this.candidates){let o=e-a>=this.graceMs;!o&&r>=t||(this.candidates.delete(i),!(this.count(i)>0||this.inDom(i)||this.host.isPermanent(i))&&(n.push(i),o||r++))}n.length&&this.host.reclaim(n),this.candidates.size&&this.schedule(this.graceMs)}inDom(e){let t=this.root;if(!t)return!1;if(t.nodeType!==1)return Array.from(t.querySelectorAll(`[class]`)).some(t=>t.classList.contains(e));let n=t.ownerDocument??document;return t.classList.contains(e)||n.documentElement.classList.contains(e)||n.getElementsByClassName(e).length>0}cancel(){this.timer!==null&&clearTimeout(this.timer),this.timer=null}stats(){return{trackedClasses:this.counts.size,candidates:this.candidates.size}}};function p(e){let t=[],n=e.replace(/\/\*[\s\S]*?\*\//g,``);return n=n.replace(/(?<=^|[{};])(\s*)([^{};@\s][^{};]*?)\{([^{}]*)\}/g,(e,n,r,i)=>{let a=r.split(`,`).map(e=>e.trim()).filter(Boolean);if(a.includes(`body`))for(let e of i.split(`;`).map(e=>e.trim()).filter(Boolean))/^(min-height|scroll-behavior)\s*:/.test(e)||t.push(e);let o=Array.from(new Set(a.filter(e=>e!==`body`).map(e=>e===`html`||e===`:root`?`:host`:e)));return o.length===0?``:`${n}${o.join(`, `)} {${i}}`}),t.length&&(n+=`\n@layer base {\n:host {\n ${t.join(`;
|
|
8
11
|
`)};\n}\n}\n`),n}function m(e){return JSON.stringify(e,(e,t)=>typeof t==`function`?`fn:${String(t)}`:t instanceof RegExp?`re:${t}`:t)??``}function h(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e=`shadow`){try{let t=e===`document`?typeof Document<`u`?Document.prototype:void 0:typeof ShadowRoot<`u`?ShadowRoot.prototype:void 0;return!!t&&`adoptedStyleSheets`in t&&typeof CSSStyleSheet==`function`&&typeof new CSSStyleSheet().replaceSync==`function`}catch{return!1}}var _=e=>e.replace(/\\\//g,`\\/`),v=/^\s*@property\s/,y=null;function b(e,n,r={}){let i=n.filter(e=>v.test(e));if(i.length===0)return!0;try{if(!e)return!1;if(!y||y.doc!==e||y.style&&!y.style.isConnected){let t={doc:e,rules:new Set};if(r.constructable&&g(`document`))t.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[...e.adoptedStyleSheets,t.sheet];else{let n=e.head??e.documentElement;if(!n)return!1;let i=e.createElement(`style`);i.setAttribute(`data-barocss`,`document-properties`),r.nonce&&i.setAttribute(`nonce`,r.nonce),n.appendChild(i),t.style=i}y=t}let t=y;for(let e of i){if(t.rules.has(e))continue;let n=t.sheet??t.style?.sheet??null;n?n.insertRule(_(e),n.cssRules.length):t.style&&(t.style.textContent+=`${e}\n`),t.rules.add(e)}return!0}catch(e){return(0,t.isDebug)()&&console.warn(`[BrowserRuntime] could not register @property rules in the document; using :host initial values`,e),!1}}function x(e){let t=[];for(let n of e){let e=/^\s*@property\s+(--[\w-]+)/.exec(n)?.[1],r=/initial-value\s*:\s*([^;}]*)/.exec(n)?.[1]?.trim();e&&r&&t.push(`${e}: ${r}`)}return t.length===0?``:`@layer properties {\n:host, *, ::before, ::after, ::backdrop {\n ${t.join(`;
|
|
9
12
|
`)};\n}\n}`}var S=class{constructor(e,n,r=e,i={}){this.results=new Map,this.generations=0,this.prologueSheet=null,this.rulesSheet=null,this.prologue={props:``,preflight:``,vars:``},this.fallbackProps=new Set,this.segments=new Map([[`root`,{rules:[],keys:[]}],[``,{rules:[],keys:[]}]]),this.refs=new Map,this.attached=[],this.key=e,this.fullKey=r,this.context=i.context??(0,t.createContext)(n),this.constructable=g(i.target??`shadow`),this.constructable&&(this.prologueSheet=new CSSStyleSheet,this.rulesSheet=new CSSStyleSheet)}get rootCount(){return this.attached.length}get ruleCount(){return this.refs.size}attach(e,t=``){if(this.attached.some(t=>t.root===e))return;if(this.prologueSheet&&this.rulesSheet){let t=[this.prologueSheet,this.rulesSheet];e.adoptedStyleSheets=[...e.adoptedStyleSheets.filter(e=>!t.includes(e)),...t],this.attached.push({root:e});return}if(e.nodeType!==11)throw Error(`[BrowserRuntime] constructable sheets are not supported for the document`);let n=e.ownerDocument??document,r=n.createElement(`style`),i=n.createElement(`style`);t&&(r.setAttribute(`nonce`,t),i.setAttribute(`nonce`,t)),r.setAttribute(`data-barocss`,`root-prologue`),i.setAttribute(`data-barocss`,`root`),r.textContent=this.prologueText(),i.textContent=this.allRules().join(`
|
|
10
13
|
`),e.insertBefore(i,e.firstChild),e.insertBefore(r,i),this.attached.push({root:e,styles:[r,i]})}detach(e){let t=this.attached.findIndex(t=>t.root===e);if(t===-1)return;let[n]=this.attached.splice(t,1);n.styles?n.styles.forEach(e=>e.remove()):e.adoptedStyleSheets&&=e.adoptedStyleSheets.filter(e=>e!==this.prologueSheet&&e!==this.rulesSheet)}addPropertyFallback(e){let t=this.fallbackProps.size;for(let t of e)v.test(t)&&this.fallbackProps.add(t);this.fallbackProps.size!==t&&this.setPrologue(`props`,x(Array.from(this.fallbackProps)))}setPrologue(e,t){if(this.prologue[e]===t)return;this.prologue[e]=t;let n=this.prologueText();this.prologueSheet&&this.prologueSheet.replaceSync(n);for(let e of this.attached)e.styles&&(e.styles[0].textContent=n)}prologueText(){return[this.prologue.props,this.prologue.preflight,this.prologue.vars].filter(Boolean).join(`
|
|
11
|
-
`)}allRules(){return Array.from(this.segments.values()).flatMap(e=>e.rules)}offset(e){let t=0;for(let n of this.segments.values()){if(n===e)return t;t+=n.rules.length}return t}retain(e,n){let
|
|
14
|
+
`)}allRules(){return Array.from(this.segments.values()).flatMap(e=>e.rules)}offset(e){let t=0;for(let n of this.segments.values()){if(n===e)return t;t+=n.rules.length}return t}retain(e,n,r){let i=this.refs.get(e);if(i!==void 0)return this.refs.set(e,i+1),!0;let a=this.segments.get(n);a||(a={rules:[],keys:[]},this.segments.set(n,a));let o=n===`root`,s=(0,t.ruleSortKey)(e,r),c=o?a.rules.length:(0,t.upperBound)(a.keys,s),l=this.offset(a)+c;try{this.insertAt(e,l)}catch(n){return(0,t.isDebug)()&&console.warn(`[BrowserRuntime] Failed to insert rule into shadow root sheet: ${e}`,n),!1}return a.rules.splice(c,0,e),a.keys.splice(c,0,s),this.refs.set(e,1),!0}release(e){let t=this.refs.get(e);if(t!==void 0){if(t>1){this.refs.set(e,t-1);return}this.refs.delete(e);for(let t of this.segments.values()){let n=t.rules.indexOf(e);if(n===-1)continue;let r=this.offset(t)+n;t.rules.splice(n,1),t.keys.splice(n,1),this.deleteAt(r);return}}}insertAt(e,t){let n=_(e);if(this.rulesSheet){this.rulesSheet.insertRule(n,t);return}let r=this.allRules().length;for(let i of this.attached){let a=i.styles[1],o=a.sheet;if(o&&o.cssRules.length===r)o.insertRule(n,t);else{let n=this.allRules();n.splice(t,0,e),a.textContent=n.join(`
|
|
12
15
|
`)}}}deleteAt(e){if(this.rulesSheet){this.rulesSheet.deleteRule(e);return}let t=this.allRules().length;for(let n of this.attached){let r=n.styles[1],i=r.sheet;i&&i.cssRules.length===t+1?i.deleteRule(e):r.textContent=this.allRules().join(`
|
|
13
16
|
`)}}cssText(){return[this.prologueText(),...this.allRules()].join(`
|
|
14
|
-
`)}},C=new Map;function w(e,t=h){let n=m(e),r=C.get(n);return r||(r=new S(t(n),e,n),C.set(n,r)),r}function T(e){e.rootCount===0&&C.get(e.fullKey)===e&&C.delete(e.fullKey)}var E=class extends t.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},D=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category,i={}){this.shared=e,this.root=n,this.getCategory=r,this.opts=i,this.owned=new Set,this.scopePreflight=n.nodeType===11,e.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?p(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t){return this.owned.has(e)||(this.root.nodeType===11&&v.test(e)&&(b(this.root.ownerDocument??(typeof document<`u`?document:null),[e],this.opts)||this.shared.addPropertyFallback([e])),!this.shared.retain(e,t))?!1:(this.owned.add(e),!0)}addRule(e){return this.take(e
|
|
17
|
+
`)}},C=new Map;function w(e,t=h){let n=m(e),r=C.get(n);return r||(r=new S(t(n),e,n),C.set(n,r)),r}function T(e){e.rootCount===0&&C.get(e.fullKey)===e&&C.delete(e.fullKey)}var E=class extends t.IncrementalParser{constructor(e){super(e.context),this.shared=e}processClass(e){if(this.isProcessed(e))return null;let t=this.shared.results.get(e);if(t)return this.markProcessed(e),t;let n=super.processClass(e);return n&&(this.shared.results.set(e,n),this.shared.generations++),n}},D=class{constructor(e,n,r=e=>(0,t.parseClassName)(e).utility?.category,i={}){this.shared=e,this.root=n,this.getCategory=r,this.opts=i,this.owned=new Set,this.scopePreflight=n.nodeType===11,e.attach(n,i.nonce)}hasDetachedPartitions(){return!1}updateRuleContent(e,t){e===`preflight`?this.shared.setPrologue(`preflight`,this.scopePreflight?p(t):t):e===`css-vars`&&this.shared.setPrologue(`vars`,t)}take(e,t,n){return this.owned.has(e)||(this.root.nodeType===11&&v.test(e)&&(b(this.root.ownerDocument??(typeof document<`u`?document:null),[e],this.opts)||this.shared.addPropertyFallback([e])),!this.shared.retain(e,t,n))?!1:(this.owned.add(e),!0)}addRule(e,t){return this.take(e,``,t)}addCategoryRule(e,t,n){return this.take(e,``,n)}addRootRules(e){let t=0;for(let n of e)this.take(n,`root`)&&t++;return{success:t,failed:e.length-t}}addRules(e){let t=0,n=0;for(let r of e){let e=this.getCategory(r.cls);for(let i of r.cssList)(e?this.addCategoryRule(i,e,r.cls):this.addRule(i,r.cls))?t++:n++}return{success:t,failed:n}}removeRule(e,t){return this.owned.delete(e)?(this.shared.release(e),!0):!1}get ruleCount(){return this.owned.size}cleanup(){this.owned.forEach(e=>this.shared.release(e)),this.owned.clear(),this.shared.detach(this.root),T(this.shared)}},O=`style[data-barocss-ssr]`,k=`@layer theme, base, components, utilities;`,A=class{constructor(e={}){this.cache=new Map,this.rootCache=new Set,this.shadowRoot=null,this.isDestroyed=!1,this.existing=null,this.existingKeyframes=new Set,this.existingSheetCount=-1,this.pinned=new Set,this.gc=null,this.reclaimedCount=0,this.ssrRules=[],this.ssrClasses=new Set,this.observedOnce=!1,this.getCategory=e=>(0,t.parseClassName)(e,this.context).utility?.category;let n={};this.options={config:e.config||n,styleId:e.styleId||`barocss-runtime`,insertionPoint:e.insertionPoint||`head`,maxRulesPerPartition:e.maxRulesPerPartition||50,skipExisting:e.skipExisting??!1,gc:e.gc??!0,gcGraceMs:e.gcGraceMs??3e3,maxRules:e.maxRules??1/0,nonce:e.nonce??``,constructable:e.constructable??!1};let r=e.root;if(r&&r.nodeType===11&&(this.shadowRoot=r),this.shadowRoot){let e=w(this.options.config);this.context=e.context,this.incrementalParser=new E(e)}else this.context=(0,t.createContext)(this.options.config),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector=new o(this.incrementalParser,this,this.getCategory),this.stylePartitionManager=this.createStyles(),this.options.gc&&(this.gc=new f({reclaim:e=>this.reclaim(e),isPermanent:e=>this.isPermanent(e),cachedCount:()=>this.cache.size},this.options.gcGraceMs,this.options.maxRules),this.changeDetector.setGc(this.gc)),this.init(),this.shadowRoot&&this.observe(this.shadowRoot,{scan:!0})}createStyles(){if(this.shadowRoot){let e=this.incrementalParser.shared,t=w(this.options.config);return t!==e&&(e=t,this.context=e.context,this.incrementalParser=new E(e),this.changeDetector?.setParser(this.incrementalParser)),new D(e,this.shadowRoot,this.getCategory,{nonce:this.options.nonce,constructable:this.options.constructable})}return this.options.constructable&&typeof document<`u`&&g(`document`)?new D(new S(`document`,this.options.config,`document`,{context:this.context,target:`document`}),document,this.getCategory):new n(this.getInsertionPoint(),this.options.maxRulesPerPartition,`${this.options.styleId}-partition`,this.getCategory,this.options.nonce)}debugLog(e,n,r){(0,t.isDebug)()&&(console[e]||console.log)(`[BrowserRuntime:${e.toUpperCase()}] ${n}`,r||``)}init(){this.debugLog(`debug`,`init`),this.injectPreflightCSS(),this.ensureCssVars(),this.adoptSsrSheets()}adoptSsrSheets(){if(typeof document>`u`||this.shadowRoot)return;let e=[];if(document.head){for(let t of Array.from(document.head.querySelectorAll(`${O}:not([data-barocss-adopted])`))){let n=t.sheet;if(!n)continue;t.setAttribute(`data-barocss-adopted`,``);let r=[];for(let e=n.cssRules.length-1;e>=0;e--){let t=n.cssRules[e],i=d([t]);i.size!==0&&(i.forEach(e=>this.ssrClasses.add(e)),r.unshift({css:t.cssText,cls:i.values().next().value}),n.deleteRule(e))}e.push(...r)}e.length!==0&&(this.ssrRules.push(...e),this.insertSsrRules(e))}}insertSsrRules(e){for(let{css:t,cls:n}of e){let e=this.getCategory(n);e?this.stylePartitionManager.addCategoryRule(t,e,n):this.stylePartitionManager.addRule(t,n)}}injectPreflightCSS(){let e=this.options.config.preflight??!0;if(e){let t=this.context.getPreflightCSS(e);this.stylePartitionManager.updateRuleContent(`preflight`,`${k}\n@layer base {\n${t}\n}`,!0)}}ensureCssVars(){if(this.isDestroyed)return;let e=this.context.themeToCssVars?this.context.themeToCssVars():`:root { /* CSS Variables will be generated here */ }`;this.stylePartitionManager.updateRuleContent(`css-vars`,e)}getInsertionPoint(){if(typeof this.options.insertionPoint!=`string`)return this.options.insertionPoint;switch(this.options.insertionPoint){case`body`:return document.body||document.head;default:return document.head}}addClass(e){if(this.isDestroyed)return;let t=this.normalizeClasses(e).filter(Boolean);t.forEach(e=>this.pinned.add(e)),this.processClasses(t)}processClasses(e){this.processClassesIncremental(e)}processClassesIncremental(e){let t=typeof window<`u`,n=this.incrementalParser.processClasses(e);this.debugLog(`debug`,`results`,{results:n,classList:e}),this.applyParseResults(n,{isBrowser:t})}applyParseResults(e,t){if(this.isDestroyed)return;if(!this.shadowRoot&&this.getInsertionPoint().isConnected&&this.stylePartitionManager.hasDetachedPartitions()){let t=Array.from(this.cache.values());this.reset(),e=[...t,...e],e.forEach(e=>this.incrementalParser.markProcessed(e.cls))}if(this.ssrClasses.size>0&&(e=e.filter(e=>!this.ssrClasses.has(e.cls))),this.options.skipExisting&&e.length>0&&typeof document<`u`){let t=this.getExistingClasses();e=e.filter(e=>!t.has(e.cls))}if(e.length===0)return;let n=[],r=[],i=this.options.skipExisting&&typeof document<`u`?(this.getExistingClasses(),this.existingKeyframes):null;for(let t of e)if(t.css&&Array.isArray(t.cssList)&&(n.push(t),this.cache.set(t.cls,t)),t.rootCss&&Array.isArray(t.rootCssList))for(let e of t.rootCssList){if(i?.size){let t=/^\s*@keyframes\s+([^\s{]+)/.exec(e)?.[1];if(t&&i.has(t))continue}this.rootCache.has(e)||(this.rootCache.add(e),r.push(e))}r.length>0&&this.stylePartitionManager.addRootRules(r.filter(Boolean)),n.length>0&&this.stylePartitionManager.addRules(n),this.debugLog(`info`,`Applied ${e.length} parser results`,{cssRuleCount:n.length,rootCssCount:r.length})}isPermanent(e){return this.pinned.has(e)||this.ssrClasses.has(e)?!0:this.shadowRoot?!1:typeof document>`u`||this.getExistingClasses().has(e)}reclaim(e){if(this.isDestroyed)return;let t=e.filter(e=>this.cache.has(e));if(t.length===0)return;let n=t.map(e=>this.cache.get(e));t.forEach(e=>{this.cache.delete(e),this.incrementalParser.unmarkProcessed(e)});let r=new Set;for(let e of this.cache.values())e.cssList.forEach(e=>r.add(e));for(let e of n){let t=this.getCategory(e.cls);for(let n of e.cssList)r.has(n)||this.stylePartitionManager.removeRule(n,t)}this.reclaimedCount+=t.length}getExistingClasses(){let e=new Set(Array.from(document.querySelectorAll(`style[data-barocss]`),e=>e.sheet)),t=Array.from(document.styleSheets).filter(t=>{if(e.has(t))return!1;let n=t.ownerNode;return!(n&&typeof n.hasAttribute==`function`&&(n.hasAttribute(`data-barocss`)||(n.id||``).startsWith(this.options.styleId)))});if(this.existing&&t.length===this.existingSheetCount)return this.existing;let n=new Set,r=new Set;for(let e of t){let t;try{t=e.cssRules}catch{continue}d(t,n),u(t,r)}return this.existingKeyframes=r,this.existing=n,this.existingSheetCount=t.length,n}observe(e=this.shadowRoot??document.body,t){return this.observedOnce||(this.observedOnce=!0,this.adoptSsrSheets()),this.changeDetector.observe(e,t)}normalizeClasses(e){return(Array.isArray(e)?e:[e]).flatMap(a)}has(e){return this.cache.has(e)}getCss(e){return this.cache.get(e)?.cssList.join(`
|
|
15
18
|
`)}getAllCss(){return[...this.rootCache,...Array.from(this.cache.values()).flatMap(e=>e.cssList)].join(`
|
|
16
19
|
`)}getClasses(){return Array.from(this.cache.keys())}getCacheStats(){let e=this.incrementalParser.getStats();return{runtime:{cachedClasses:this.cache.size,rootCacheSize:this.rootCache.size,ruleCount:this.stylePartitionManager.ruleCount,reclaimedClasses:this.reclaimedCount,gc:this.gc?.stats()??null},ast:e.cacheStats.ast,incremental:e}}clearCaches(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),(0,t.clearAstCache)(this.context),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}reset(){this.isDestroyed||(this.cache.clear(),this.rootCache.clear(),this.incrementalParser.clearProcessed(),this.stylePartitionManager.cleanup(),this.stylePartitionManager=this.createStyles(),this.injectPreflightCSS(),this.ensureCssVars(),this.insertSsrRules(this.ssrRules))}updateConfig(e){if(this.isDestroyed)return;let n=Array.from(this.cache.keys());if(this.options.config=e,this.shadowRoot){this.stylePartitionManager.cleanup();let t=w(e);this.context=t.context,this.incrementalParser=new E(t)}else this.context=(0,t.createContext)(e),this.incrementalParser=new t.IncrementalParser(this.context);this.changeDetector.setParser(this.incrementalParser),this.reset(),n.length>0&&this.addClass(n)}removeClass(e){if(this.isDestroyed)return;let t=new Set(this.normalizeClasses(e)),n=Array.from(this.cache.values()).filter(e=>!t.has(e.cls));n.length!==this.cache.size&&(this.reset(),n.forEach(e=>this.incrementalParser.markProcessed(e.cls)),this.applyParseResults(n))}destroy(){this.isDestroyed||=(this.changeDetector.disconnect(),this.gc?.cancel(),this.stylePartitionManager.cleanup(),this.cache.clear(),this.rootCache.clear(),!0)}getStats(){return{cachedClasses:this.cache.size,styleElementId:this.options.styleId,isDestroyed:this.isDestroyed,config:this.options.config,cacheStats:this.getCacheStats(),adopted:!this.shadowRoot&&this.stylePartitionManager instanceof D,sharedSheet:this.shadowRoot&&this.stylePartitionManager instanceof D?{roots:this.stylePartitionManager.shared.rootCount,rules:this.stylePartitionManager.shared.ruleCount,generations:this.stylePartitionManager.shared.generations,constructable:this.stylePartitionManager.shared.constructable}:null}}},j=null,M,N=``,P=!1,F=!1;function I(e={}){if(!j||j.getStats().isDestroyed?(j=new A(e),M=e.config,N=e.nonce??``,P=e.constructable??!1,F=!1):e.config&&e.config!==M&&(j.updateConfig(e.config),M=e.config),!F){let t=e.nonce!==void 0&&e.nonce!==N,n=e.constructable!==void 0&&e.constructable!==P;if(t||n){F=!0;let e=[t&&`nonce (runtime has ${N?`a different nonce`:`none`})`,n&&`constructable (runtime has ${P})`].filter(Boolean).join(` and `);console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`)}}return j}function L({loadingClassName:e=`baro-boot`,...t}={}){if(t.root&&t.root.nodeType===11)return new A(t);if(!document.body){document.addEventListener(`DOMContentLoaded`,()=>L({loadingClassName:e,...t}),{once:!0});return}let n=`${e}-doing`,r=`${e}-done`;try{document.body.classList.add(n),I(t).observe(document.body,{scan:!0,onReady:()=>{document.body.classList.remove(n),document.body.classList.add(r)}})}catch(e){document.body?.classList.remove(n),console.error(`BaroCSS boot failed:`,e)}}var R=L;function z(e){if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.elements;if(!t||typeof t!=`object`||Array.isArray(t))return[];let n=new Set;for(let e of Object.keys(t)){let r=t[e];if(!r||typeof r!=`object`||Array.isArray(r))continue;let i=r.props;if(!i||typeof i!=`object`||Array.isArray(i))continue;let o=i.className;if(typeof o==`string`)for(let e of a(o))e&&n.add(e)}return Array.from(n)}function B(e,t){let n=z(e);n.length>0&&t.addClass(n)}var V={colors:Object.fromEntries(`background.foreground.card.card-foreground.popover.popover-foreground.primary.primary-foreground.secondary.secondary-foreground.muted.muted-foreground.accent.accent-foreground.destructive.border.input.ring.chart-1.chart-2.chart-3.chart-4.chart-5.sidebar.sidebar-foreground.sidebar-primary.sidebar-primary-foreground.sidebar-accent.sidebar-accent-foreground.sidebar-border.sidebar-ring`.split(`.`).map(e=>[e,`var(--${e})`])),borderRadius:{sm:`calc(var(--radius) - 4px)`,md:`calc(var(--radius) - 2px)`,lg:`var(--radius)`,xl:`calc(var(--radius) + 4px)`}};e.BrowserRuntime=A,e.ChangeDetector=o,e.LAYER_ORDER=k,e.SSR_STYLE_SELECTOR=O,e.StylePartitionManager=n,e.baroBoot=L,e.baroStart=R,e.collectJsonRenderClassNames=z,e.getRuntime=I,e.normalizeClassName=i,e.normalizeClassNameList=a,e.preloadJsonRenderClasses=B,e.shadcnTheme=V});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barocss/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/barocss/barocss.git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@barocss/kit": "0.
|
|
33
|
+
"@barocss/kit": "0.11.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"jsdom": "^26.1.0",
|