@barocss/browser 0.8.2 → 0.10.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/README.md +25 -0
- 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 +9 -3
- package/dist/index.d.cts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.es.js +321 -62
- package/dist/index.umd.js +9 -3
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -5,8 +5,12 @@ var c = class {
|
|
|
5
5
|
let r = e.keys ??= [], i = s(r, n), a = e.styleElement.sheet;
|
|
6
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
7
|
}
|
|
8
|
-
constructor(e, t = 50, n = "barocss-style-partition-", r = (e) => a(e).utility?.category) {
|
|
9
|
-
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 = e, this.maxRulesPerPartition = t, this.styleIdPrefix = n, this.getCategory = r, this.initializeDefaultPartition();
|
|
8
|
+
constructor(e, t = 50, n = "barocss-style-partition-", r = (e) => a(e).utility?.category, i = "") {
|
|
9
|
+
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.nonce = i, this.insertionPoint = e, this.maxRulesPerPartition = t, this.styleIdPrefix = n, this.getCategory = r, this.initializeDefaultPartition();
|
|
10
|
+
}
|
|
11
|
+
createStyleElement() {
|
|
12
|
+
let e = document.createElement("style");
|
|
13
|
+
return this.nonce && e.setAttribute("nonce", this.nonce), e;
|
|
10
14
|
}
|
|
11
15
|
initializeDefaultPartition() {
|
|
12
16
|
this.createNewPartition();
|
|
@@ -15,7 +19,7 @@ var c = class {
|
|
|
15
19
|
let n = {
|
|
16
20
|
id: this.styleIdPrefix + `-${e}`,
|
|
17
21
|
styles: [],
|
|
18
|
-
styleElement:
|
|
22
|
+
styleElement: this.createStyleElement()
|
|
19
23
|
};
|
|
20
24
|
n.styleElement.id = n.id, n.styleElement.setAttribute("data-barocss", "partition"), n.styleElement.setAttribute("data-category", e);
|
|
21
25
|
let r = this.insertionPoint.ownerDocument?.head;
|
|
@@ -25,7 +29,7 @@ var c = class {
|
|
|
25
29
|
let e = {
|
|
26
30
|
id: this.styleIdPrefix + `-${this.partitionCounter++}`,
|
|
27
31
|
styles: [],
|
|
28
|
-
styleElement:
|
|
32
|
+
styleElement: this.createStyleElement()
|
|
29
33
|
};
|
|
30
34
|
return this.partitions.push(e), e.styleElement.id = e.id, e.styleElement.setAttribute("data-barocss", "partition"), e.styleElement.setAttribute("data-partition-index", this.partitionCounter.toString()), this.insertionPoint.appendChild(e.styleElement), e;
|
|
31
35
|
}
|
|
@@ -146,18 +150,16 @@ var c = class {
|
|
|
146
150
|
e.styleElement.parentNode && e.styleElement.parentNode.removeChild(e.styleElement);
|
|
147
151
|
}), this.partitions = [], this.categoryPartitions.clear(), this.partitionCounter = 0, this.classToPartitionMap.clear(), this.classToCategoryPartitionMap.clear();
|
|
148
152
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
//#region src/utils.ts
|
|
152
|
-
function l(e) {
|
|
153
|
+
}, l = /[ \t\n\f\r]+/;
|
|
154
|
+
function u(e) {
|
|
153
155
|
return e ? typeof e == "object" && typeof e.baseVal == "string" ? e.baseVal : e.toString() : "";
|
|
154
156
|
}
|
|
155
|
-
function
|
|
156
|
-
return e ?
|
|
157
|
+
function d(e) {
|
|
158
|
+
return e ? u(e).split(l).filter(Boolean) : [];
|
|
157
159
|
}
|
|
158
160
|
//#endregion
|
|
159
161
|
//#region src/change-detector.ts
|
|
160
|
-
var
|
|
162
|
+
var f = class {
|
|
161
163
|
constructor(e, t, n = (e) => a(e).utility?.category) {
|
|
162
164
|
this.observer = null, this.gc = null, this.incrementalParser = e, this.BrowserRuntime = t, this.getCategory = n;
|
|
163
165
|
}
|
|
@@ -173,7 +175,7 @@ var d = class {
|
|
|
173
175
|
if (t.forEach((t) => {
|
|
174
176
|
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)) {
|
|
175
177
|
let e = t.target;
|
|
176
|
-
e.className &&
|
|
178
|
+
e.className && d(e.className).forEach((e) => {
|
|
177
179
|
this.incrementalParser.isProcessed(e) || n.add(e);
|
|
178
180
|
});
|
|
179
181
|
}
|
|
@@ -198,13 +200,13 @@ var d = class {
|
|
|
198
200
|
}), t?.scan && this.scanExistingClasses(e, t), this.observer);
|
|
199
201
|
}
|
|
200
202
|
scanExistingClasses(e, t) {
|
|
201
|
-
let n = /* @__PURE__ */ new Set();
|
|
202
|
-
|
|
203
|
+
let n = /* @__PURE__ */ new Set(), r = e.className;
|
|
204
|
+
r && d(r).forEach((e) => {
|
|
203
205
|
this.incrementalParser.isProcessed(e) || n.add(e);
|
|
204
206
|
});
|
|
205
|
-
let
|
|
206
|
-
for (let e of
|
|
207
|
-
let t =
|
|
207
|
+
let i = e.querySelectorAll("[class]");
|
|
208
|
+
for (let e of i) if (e.className) {
|
|
209
|
+
let t = d(e.className);
|
|
208
210
|
for (let e of t) this.incrementalParser.isProcessed(e) || n.add(e);
|
|
209
211
|
}
|
|
210
212
|
if (n.size > 0) {
|
|
@@ -213,7 +215,7 @@ var d = class {
|
|
|
213
215
|
} else t?.onReady?.();
|
|
214
216
|
}
|
|
215
217
|
processElement(e, t) {
|
|
216
|
-
e.className &&
|
|
218
|
+
e.className && d(e.className).forEach((e) => {
|
|
217
219
|
this.incrementalParser.isProcessed(e) || t.add(e);
|
|
218
220
|
});
|
|
219
221
|
}
|
|
@@ -223,11 +225,11 @@ var d = class {
|
|
|
223
225
|
};
|
|
224
226
|
//#endregion
|
|
225
227
|
//#region src/existing-classes.ts
|
|
226
|
-
function
|
|
228
|
+
function p(e) {
|
|
227
229
|
return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g, (e, t, n) => t ? String.fromCodePoint(parseInt(t, 16)) : n);
|
|
228
230
|
}
|
|
229
|
-
var
|
|
230
|
-
function
|
|
231
|
+
var m = /^\s*(?::(?:where|is)\(\s*)?\.((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7F])+)/;
|
|
232
|
+
function h(e) {
|
|
231
233
|
let t = [], n = 0, r = 0;
|
|
232
234
|
for (let i = 0; i < e.length; i++) {
|
|
233
235
|
let a = e[i];
|
|
@@ -235,37 +237,37 @@ function m(e) {
|
|
|
235
237
|
}
|
|
236
238
|
return t.push(e.slice(r)), t;
|
|
237
239
|
}
|
|
238
|
-
function
|
|
240
|
+
function g(e, t = /* @__PURE__ */ new Set()) {
|
|
239
241
|
for (let n of Array.from(e)) {
|
|
240
242
|
if (n.type === 7 && typeof n.name == "string") {
|
|
241
243
|
t.add(n.name);
|
|
242
244
|
continue;
|
|
243
245
|
}
|
|
244
246
|
let e = n.cssRules;
|
|
245
|
-
e && e.length &&
|
|
247
|
+
e && e.length && g(e, t);
|
|
246
248
|
}
|
|
247
249
|
return t;
|
|
248
250
|
}
|
|
249
|
-
function
|
|
251
|
+
function _(e, t = /* @__PURE__ */ new Set()) {
|
|
250
252
|
for (let n of Array.from(e)) {
|
|
251
253
|
let e = n.selectorText;
|
|
252
|
-
if (typeof e == "string") for (let n of
|
|
253
|
-
let e =
|
|
254
|
-
e && t.add(
|
|
254
|
+
if (typeof e == "string") for (let n of h(e)) {
|
|
255
|
+
let e = m.exec(n);
|
|
256
|
+
e && t.add(p(e[1]));
|
|
255
257
|
}
|
|
256
258
|
let r = n.cssRules;
|
|
257
|
-
r && r.length &&
|
|
259
|
+
r && r.length && _(r, t);
|
|
258
260
|
}
|
|
259
261
|
return t;
|
|
260
262
|
}
|
|
261
263
|
//#endregion
|
|
262
264
|
//#region src/class-gc.ts
|
|
263
|
-
var
|
|
265
|
+
var v = class {
|
|
264
266
|
constructor(e, t, n, r = () => Date.now()) {
|
|
265
267
|
this.host = e, this.graceMs = t, this.maxRules = n, this.now = r, this.counts = /* @__PURE__ */ new Map(), this.counted = /* @__PURE__ */ new WeakMap(), this.candidates = /* @__PURE__ */ new Map(), this.timer = null, this.root = null;
|
|
266
268
|
}
|
|
267
269
|
setRoot(e) {
|
|
268
|
-
this.counts.clear(), this.counted = /* @__PURE__ */ new WeakMap(), this.candidates.clear(), this.cancel(), this.root = e, this.reconcileTree(e);
|
|
270
|
+
this.counts.clear(), this.counted = /* @__PURE__ */ new WeakMap(), this.candidates.clear(), this.cancel(), this.root = e, e.nodeType === 1 ? this.reconcileTree(e) : e.querySelectorAll("[class]").forEach((e) => this.reconcile(e));
|
|
269
271
|
}
|
|
270
272
|
count(e) {
|
|
271
273
|
return this.counts.get(e) ?? 0;
|
|
@@ -276,7 +278,7 @@ var _ = class {
|
|
|
276
278
|
this.reconcile(t), t.querySelectorAll("[class]").forEach((e) => this.reconcile(e));
|
|
277
279
|
}
|
|
278
280
|
reconcile(e) {
|
|
279
|
-
let t = this.root, n = t && t.contains(e) ? Array.from(new Set(
|
|
281
|
+
let t = this.root, n = t && t.contains(e) ? Array.from(new Set(d(e.getAttribute("class")))) : [], r = this.counted.get(e);
|
|
280
282
|
if (!r && n.length === 0) return;
|
|
281
283
|
let i = new Set(r ?? []), a = new Set(n);
|
|
282
284
|
for (let e of a) {
|
|
@@ -314,6 +316,7 @@ var _ = class {
|
|
|
314
316
|
inDom(e) {
|
|
315
317
|
let t = this.root;
|
|
316
318
|
if (!t) return !1;
|
|
319
|
+
if (t.nodeType !== 1) return Array.from(t.querySelectorAll("[class]")).some((t) => t.classList.contains(e));
|
|
317
320
|
let n = t.ownerDocument ?? document;
|
|
318
321
|
return t.classList.contains(e) || n.documentElement.classList.contains(e) || n.getElementsByClassName(e).length > 0;
|
|
319
322
|
}
|
|
@@ -326,9 +329,226 @@ var _ = class {
|
|
|
326
329
|
candidates: this.candidates.size
|
|
327
330
|
};
|
|
328
331
|
}
|
|
329
|
-
}
|
|
332
|
+
};
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/shadow-root-sheet.ts
|
|
335
|
+
function y(e) {
|
|
336
|
+
let t = [], n = e.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
337
|
+
return n = n.replace(/(?<=^|[{};])(\s*)([^{};@\s][^{};]*?)\{([^{}]*)\}/g, (e, n, r, i) => {
|
|
338
|
+
let a = r.split(",").map((e) => e.trim()).filter(Boolean);
|
|
339
|
+
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);
|
|
340
|
+
let o = Array.from(new Set(a.filter((e) => e !== "body").map((e) => e === "html" || e === ":root" ? ":host" : e)));
|
|
341
|
+
return o.length === 0 ? "" : `${n}${o.join(", ")} {${i}}`;
|
|
342
|
+
}), t.length && (n += `\n@layer base {\n:host {\n ${t.join(";\n ")};\n}\n}\n`), n;
|
|
343
|
+
}
|
|
344
|
+
function b(e) {
|
|
345
|
+
return JSON.stringify(e, (e, t) => typeof t == "function" ? `fn:${String(t)}` : t instanceof RegExp ? `re:${t}` : t) ?? "";
|
|
346
|
+
}
|
|
347
|
+
function x(e) {
|
|
348
|
+
let t = 2166136261;
|
|
349
|
+
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
|
|
350
|
+
return (t >>> 0).toString(36);
|
|
351
|
+
}
|
|
352
|
+
function S(e = "shadow") {
|
|
353
|
+
try {
|
|
354
|
+
let t = e === "document" ? typeof Document < "u" ? Document.prototype : void 0 : typeof ShadowRoot < "u" ? ShadowRoot.prototype : void 0;
|
|
355
|
+
return !!t && "adoptedStyleSheets" in t && typeof CSSStyleSheet == "function" && typeof new CSSStyleSheet().replaceSync == "function";
|
|
356
|
+
} catch {
|
|
357
|
+
return !1;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
var C = (e) => e.replace(/\\\//g, "\\/"), w = class {
|
|
361
|
+
constructor(e, t, n = e, i = {}) {
|
|
362
|
+
this.results = /* @__PURE__ */ new Map(), this.generations = 0, this.prologueSheet = null, this.rulesSheet = null, this.prologue = {
|
|
363
|
+
preflight: "",
|
|
364
|
+
vars: ""
|
|
365
|
+
}, this.segments = /* @__PURE__ */ new Map([["root", {
|
|
366
|
+
rules: [],
|
|
367
|
+
keys: []
|
|
368
|
+
}], ["", {
|
|
369
|
+
rules: [],
|
|
370
|
+
keys: []
|
|
371
|
+
}]]), this.refs = /* @__PURE__ */ new Map(), this.attached = [], this.key = e, this.fullKey = n, this.context = i.context ?? r(t), this.constructable = S(i.target ?? "shadow"), this.constructable && (this.prologueSheet = new CSSStyleSheet(), this.rulesSheet = new CSSStyleSheet());
|
|
372
|
+
}
|
|
373
|
+
get rootCount() {
|
|
374
|
+
return this.attached.length;
|
|
375
|
+
}
|
|
376
|
+
get ruleCount() {
|
|
377
|
+
return this.refs.size;
|
|
378
|
+
}
|
|
379
|
+
attach(e, t = "") {
|
|
380
|
+
if (this.attached.some((t) => t.root === e)) return;
|
|
381
|
+
if (this.prologueSheet && this.rulesSheet) {
|
|
382
|
+
let t = [this.prologueSheet, this.rulesSheet];
|
|
383
|
+
e.adoptedStyleSheets = [...e.adoptedStyleSheets.filter((e) => !t.includes(e)), ...t], this.attached.push({ root: e });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (e.nodeType !== 11) throw Error("[BrowserRuntime] constructable sheets are not supported for the document");
|
|
387
|
+
let n = e.ownerDocument ?? document, r = n.createElement("style"), i = n.createElement("style");
|
|
388
|
+
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("\n"), e.insertBefore(i, e.firstChild), e.insertBefore(r, i), this.attached.push({
|
|
389
|
+
root: e,
|
|
390
|
+
styles: [r, i]
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
detach(e) {
|
|
394
|
+
let t = this.attached.findIndex((t) => t.root === e);
|
|
395
|
+
if (t === -1) return;
|
|
396
|
+
let [n] = this.attached.splice(t, 1);
|
|
397
|
+
n.styles ? n.styles.forEach((e) => e.remove()) : e.adoptedStyleSheets &&= e.adoptedStyleSheets.filter((e) => e !== this.prologueSheet && e !== this.rulesSheet);
|
|
398
|
+
}
|
|
399
|
+
setPrologue(e, t) {
|
|
400
|
+
if (this.prologue[e] === t) return;
|
|
401
|
+
this.prologue[e] = t;
|
|
402
|
+
let n = this.prologueText();
|
|
403
|
+
this.prologueSheet && this.prologueSheet.replaceSync(n);
|
|
404
|
+
for (let e of this.attached) e.styles && (e.styles[0].textContent = n);
|
|
405
|
+
}
|
|
406
|
+
prologueText() {
|
|
407
|
+
return [this.prologue.preflight, this.prologue.vars].filter(Boolean).join("\n");
|
|
408
|
+
}
|
|
409
|
+
allRules() {
|
|
410
|
+
return Array.from(this.segments.values()).flatMap((e) => e.rules);
|
|
411
|
+
}
|
|
412
|
+
offset(e) {
|
|
413
|
+
let t = 0;
|
|
414
|
+
for (let n of this.segments.values()) {
|
|
415
|
+
if (n === e) return t;
|
|
416
|
+
t += n.rules.length;
|
|
417
|
+
}
|
|
418
|
+
return t;
|
|
419
|
+
}
|
|
420
|
+
retain(e, t) {
|
|
421
|
+
let n = this.refs.get(e);
|
|
422
|
+
if (n !== void 0) return this.refs.set(e, n + 1), !0;
|
|
423
|
+
let r = this.segments.get(t);
|
|
424
|
+
r || (r = {
|
|
425
|
+
rules: [],
|
|
426
|
+
keys: []
|
|
427
|
+
}, this.segments.set(t, r));
|
|
428
|
+
let a = t === "root", c = o(e), l = a ? r.rules.length : s(r.keys, c), u = this.offset(r) + l;
|
|
429
|
+
try {
|
|
430
|
+
this.insertAt(e, u);
|
|
431
|
+
} catch (t) {
|
|
432
|
+
return i() && console.warn(`[BrowserRuntime] Failed to insert rule into shadow root sheet: ${e}`, t), !1;
|
|
433
|
+
}
|
|
434
|
+
return r.rules.splice(l, 0, e), r.keys.splice(l, 0, c), this.refs.set(e, 1), !0;
|
|
435
|
+
}
|
|
436
|
+
release(e) {
|
|
437
|
+
let t = this.refs.get(e);
|
|
438
|
+
if (t !== void 0) {
|
|
439
|
+
if (t > 1) {
|
|
440
|
+
this.refs.set(e, t - 1);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this.refs.delete(e);
|
|
444
|
+
for (let t of this.segments.values()) {
|
|
445
|
+
let n = t.rules.indexOf(e);
|
|
446
|
+
if (n === -1) continue;
|
|
447
|
+
let r = this.offset(t) + n;
|
|
448
|
+
t.rules.splice(n, 1), t.keys.splice(n, 1), this.deleteAt(r);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
insertAt(e, t) {
|
|
454
|
+
let n = C(e);
|
|
455
|
+
if (this.rulesSheet) {
|
|
456
|
+
this.rulesSheet.insertRule(n, t);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
let r = this.allRules().length;
|
|
460
|
+
for (let i of this.attached) {
|
|
461
|
+
let a = i.styles[1], o = a.sheet;
|
|
462
|
+
if (o && o.cssRules.length === r) o.insertRule(n, t);
|
|
463
|
+
else {
|
|
464
|
+
let n = this.allRules();
|
|
465
|
+
n.splice(t, 0, e), a.textContent = n.join("\n");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
deleteAt(e) {
|
|
470
|
+
if (this.rulesSheet) {
|
|
471
|
+
this.rulesSheet.deleteRule(e);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
let t = this.allRules().length;
|
|
475
|
+
for (let n of this.attached) {
|
|
476
|
+
let r = n.styles[1], i = r.sheet;
|
|
477
|
+
i && i.cssRules.length === t + 1 ? i.deleteRule(e) : r.textContent = this.allRules().join("\n");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
cssText() {
|
|
481
|
+
return [this.prologueText(), ...this.allRules()].join("\n");
|
|
482
|
+
}
|
|
483
|
+
}, T = /* @__PURE__ */ new Map();
|
|
484
|
+
function E(e, t = x) {
|
|
485
|
+
let n = b(e), r = T.get(n);
|
|
486
|
+
return r || (r = new w(t(n), e, n), T.set(n, r)), r;
|
|
487
|
+
}
|
|
488
|
+
function D(e) {
|
|
489
|
+
e.rootCount === 0 && T.get(e.fullKey) === e && T.delete(e.fullKey);
|
|
490
|
+
}
|
|
491
|
+
var O = class extends e {
|
|
492
|
+
constructor(e) {
|
|
493
|
+
super(e.context), this.shared = e;
|
|
494
|
+
}
|
|
495
|
+
processClass(e) {
|
|
496
|
+
if (this.isProcessed(e)) return null;
|
|
497
|
+
let t = this.shared.results.get(e);
|
|
498
|
+
if (t) return this.markProcessed(e), t;
|
|
499
|
+
let n = super.processClass(e);
|
|
500
|
+
return n && (this.shared.results.set(e, n), this.shared.generations++), n;
|
|
501
|
+
}
|
|
502
|
+
}, k = class {
|
|
503
|
+
constructor(e, t, n = (e) => a(e).utility?.category, r = {}) {
|
|
504
|
+
this.shared = e, this.root = t, this.getCategory = n, this.owned = /* @__PURE__ */ new Set(), this.scopePreflight = t.nodeType === 11, e.attach(t, r.nonce);
|
|
505
|
+
}
|
|
506
|
+
hasDetachedPartitions() {
|
|
507
|
+
return !1;
|
|
508
|
+
}
|
|
509
|
+
updateRuleContent(e, t) {
|
|
510
|
+
e === "preflight" ? this.shared.setPrologue("preflight", this.scopePreflight ? y(t) : t) : e === "css-vars" && this.shared.setPrologue("vars", t);
|
|
511
|
+
}
|
|
512
|
+
take(e, t) {
|
|
513
|
+
return this.owned.has(e) || !this.shared.retain(e, t) ? !1 : (this.owned.add(e), !0);
|
|
514
|
+
}
|
|
515
|
+
addRule(e) {
|
|
516
|
+
return this.take(e, "");
|
|
517
|
+
}
|
|
518
|
+
addCategoryRule(e, t) {
|
|
519
|
+
return this.take(e, `c:${t}`);
|
|
520
|
+
}
|
|
521
|
+
addRootRules(e) {
|
|
522
|
+
let t = 0;
|
|
523
|
+
for (let n of e) this.take(n, "root") && t++;
|
|
524
|
+
return {
|
|
525
|
+
success: t,
|
|
526
|
+
failed: e.length - t
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
addRules(e) {
|
|
530
|
+
let t = 0, n = 0;
|
|
531
|
+
for (let r of e) {
|
|
532
|
+
let e = this.getCategory(r.cls);
|
|
533
|
+
for (let i of r.cssList) (e ? this.addCategoryRule(i, e) : this.addRule(i)) ? t++ : n++;
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
success: t,
|
|
537
|
+
failed: n
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
removeRule(e, t) {
|
|
541
|
+
return this.owned.delete(e) ? (this.shared.release(e), !0) : !1;
|
|
542
|
+
}
|
|
543
|
+
get ruleCount() {
|
|
544
|
+
return this.owned.size;
|
|
545
|
+
}
|
|
546
|
+
cleanup() {
|
|
547
|
+
this.owned.forEach((e) => this.shared.release(e)), this.owned.clear(), this.shared.detach(this.root), D(this.shared);
|
|
548
|
+
}
|
|
549
|
+
}, A = "style[data-barocss-ssr]", j = "@layer theme, base, components, utilities;", M = class {
|
|
330
550
|
constructor(t = {}) {
|
|
331
|
-
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 = (e) => a(e, this.context).utility?.category;
|
|
551
|
+
this.cache = /* @__PURE__ */ new Map(), this.rootCache = /* @__PURE__ */ new Set(), this.shadowRoot = null, 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 = (e) => a(e, this.context).utility?.category;
|
|
332
552
|
let n = {};
|
|
333
553
|
this.options = {
|
|
334
554
|
config: t.config || n,
|
|
@@ -338,12 +558,30 @@ var _ = class {
|
|
|
338
558
|
skipExisting: t.skipExisting ?? !1,
|
|
339
559
|
gc: t.gc ?? !0,
|
|
340
560
|
gcGraceMs: t.gcGraceMs ?? 3e3,
|
|
341
|
-
maxRules: t.maxRules ?? Infinity
|
|
342
|
-
|
|
561
|
+
maxRules: t.maxRules ?? Infinity,
|
|
562
|
+
nonce: t.nonce ?? "",
|
|
563
|
+
constructable: t.constructable ?? !1
|
|
564
|
+
};
|
|
565
|
+
let i = t.root;
|
|
566
|
+
if (i && i.nodeType === 11 && (this.shadowRoot = i), this.shadowRoot) {
|
|
567
|
+
let e = E(this.options.config);
|
|
568
|
+
this.context = e.context, this.incrementalParser = new O(e);
|
|
569
|
+
} else this.context = r(this.options.config), this.incrementalParser = new e(this.context);
|
|
570
|
+
this.changeDetector = new f(this.incrementalParser, this, this.getCategory), this.stylePartitionManager = this.createStyles(), this.options.gc && (this.gc = new v({
|
|
343
571
|
reclaim: (e) => this.reclaim(e),
|
|
344
572
|
isPermanent: (e) => this.isPermanent(e),
|
|
345
573
|
cachedCount: () => this.cache.size
|
|
346
|
-
}, this.options.gcGraceMs, this.options.maxRules), this.changeDetector.setGc(this.gc)), this.init();
|
|
574
|
+
}, this.options.gcGraceMs, this.options.maxRules), this.changeDetector.setGc(this.gc)), this.init(), this.shadowRoot && this.observe(this.shadowRoot, { scan: !0 });
|
|
575
|
+
}
|
|
576
|
+
createStyles() {
|
|
577
|
+
if (this.shadowRoot) {
|
|
578
|
+
let e = this.incrementalParser.shared, t = E(this.options.config);
|
|
579
|
+
return t !== e && (e = t, this.context = e.context, this.incrementalParser = new O(e), this.changeDetector?.setParser(this.incrementalParser)), new k(e, this.shadowRoot, this.getCategory, { nonce: this.options.nonce });
|
|
580
|
+
}
|
|
581
|
+
return this.options.constructable && typeof document < "u" && S("document") ? new k(new w("document", this.options.config, "document", {
|
|
582
|
+
context: this.context,
|
|
583
|
+
target: "document"
|
|
584
|
+
}), document, this.getCategory) : new c(this.getInsertionPoint(), this.options.maxRulesPerPartition, `${this.options.styleId}-partition`, this.getCategory, this.options.nonce);
|
|
347
585
|
}
|
|
348
586
|
debugLog(e, t, n) {
|
|
349
587
|
i() && (console[e] || console.log)(`[BrowserRuntime:${e.toUpperCase()}] ${t}`, n || "");
|
|
@@ -352,16 +590,16 @@ var _ = class {
|
|
|
352
590
|
this.debugLog("debug", "init"), this.injectPreflightCSS(), this.ensureCssVars(), this.adoptSsrSheets();
|
|
353
591
|
}
|
|
354
592
|
adoptSsrSheets() {
|
|
355
|
-
if (typeof document > "u") return;
|
|
593
|
+
if (typeof document > "u" || this.shadowRoot) return;
|
|
356
594
|
let e = [];
|
|
357
595
|
if (document.head) {
|
|
358
|
-
for (let t of Array.from(document.head.querySelectorAll(`${
|
|
596
|
+
for (let t of Array.from(document.head.querySelectorAll(`${A}:not([data-barocss-adopted])`))) {
|
|
359
597
|
let n = t.sheet;
|
|
360
598
|
if (!n) continue;
|
|
361
599
|
t.setAttribute("data-barocss-adopted", "");
|
|
362
600
|
let r = [];
|
|
363
601
|
for (let e = n.cssRules.length - 1; e >= 0; e--) {
|
|
364
|
-
let t = n.cssRules[e], i =
|
|
602
|
+
let t = n.cssRules[e], i = _([t]);
|
|
365
603
|
i.size !== 0 && (i.forEach((e) => this.ssrClasses.add(e)), r.unshift({
|
|
366
604
|
css: t.cssText,
|
|
367
605
|
cls: i.values().next().value
|
|
@@ -382,7 +620,7 @@ var _ = class {
|
|
|
382
620
|
let e = this.options.config.preflight ?? !0;
|
|
383
621
|
if (e) {
|
|
384
622
|
let t = this.context.getPreflightCSS(e);
|
|
385
|
-
this.stylePartitionManager.updateRuleContent("preflight", `${
|
|
623
|
+
this.stylePartitionManager.updateRuleContent("preflight", `${j}\n@layer base {\n${t}\n}`, !0);
|
|
386
624
|
}
|
|
387
625
|
}
|
|
388
626
|
ensureCssVars() {
|
|
@@ -414,7 +652,7 @@ var _ = class {
|
|
|
414
652
|
}
|
|
415
653
|
applyParseResults(e, t) {
|
|
416
654
|
if (this.isDestroyed) return;
|
|
417
|
-
if (this.getInsertionPoint().isConnected && this.stylePartitionManager.hasDetachedPartitions()) {
|
|
655
|
+
if (!this.shadowRoot && this.getInsertionPoint().isConnected && this.stylePartitionManager.hasDetachedPartitions()) {
|
|
418
656
|
let t = Array.from(this.cache.values());
|
|
419
657
|
this.reset(), e = [...t, ...e], e.forEach((e) => this.incrementalParser.markProcessed(e.cls));
|
|
420
658
|
}
|
|
@@ -437,7 +675,7 @@ var _ = class {
|
|
|
437
675
|
});
|
|
438
676
|
}
|
|
439
677
|
isPermanent(e) {
|
|
440
|
-
return this.pinned.has(e) || this.ssrClasses.has(e)
|
|
678
|
+
return this.pinned.has(e) || this.ssrClasses.has(e) ? !0 : this.shadowRoot ? !1 : typeof document > "u" || this.getExistingClasses().has(e);
|
|
441
679
|
}
|
|
442
680
|
reclaim(e) {
|
|
443
681
|
if (this.isDestroyed) return;
|
|
@@ -470,15 +708,15 @@ var _ = class {
|
|
|
470
708
|
} catch {
|
|
471
709
|
continue;
|
|
472
710
|
}
|
|
473
|
-
|
|
711
|
+
_(t, n), g(t, r);
|
|
474
712
|
}
|
|
475
713
|
return this.existingKeyframes = r, this.existing = n, this.existingSheetCount = t.length, n;
|
|
476
714
|
}
|
|
477
|
-
observe(e = document.body, t) {
|
|
715
|
+
observe(e = this.shadowRoot ?? document.body, t) {
|
|
478
716
|
return this.observedOnce || (this.observedOnce = !0, this.adoptSsrSheets()), this.changeDetector.observe(e, t);
|
|
479
717
|
}
|
|
480
718
|
normalizeClasses(e) {
|
|
481
|
-
return Array.isArray(e) ? e
|
|
719
|
+
return (Array.isArray(e) ? e : [e]).flatMap(d);
|
|
482
720
|
}
|
|
483
721
|
has(e) {
|
|
484
722
|
return this.cache.has(e);
|
|
@@ -507,15 +745,20 @@ var _ = class {
|
|
|
507
745
|
};
|
|
508
746
|
}
|
|
509
747
|
clearCaches() {
|
|
510
|
-
this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), t(this.context), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager =
|
|
748
|
+
this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), t(this.context), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager = this.createStyles(), this.injectPreflightCSS(), this.ensureCssVars(), this.insertSsrRules(this.ssrRules));
|
|
511
749
|
}
|
|
512
750
|
reset() {
|
|
513
|
-
this.isDestroyed || (this.cache.clear(), this.rootCache.clear(), this.incrementalParser.clearProcessed(), this.stylePartitionManager.cleanup(), this.stylePartitionManager =
|
|
751
|
+
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));
|
|
514
752
|
}
|
|
515
753
|
updateConfig(t) {
|
|
516
754
|
if (this.isDestroyed) return;
|
|
517
755
|
let n = Array.from(this.cache.keys());
|
|
518
|
-
this.options.config = t, this.
|
|
756
|
+
if (this.options.config = t, this.shadowRoot) {
|
|
757
|
+
this.stylePartitionManager.cleanup();
|
|
758
|
+
let e = E(t);
|
|
759
|
+
this.context = e.context, this.incrementalParser = new O(e);
|
|
760
|
+
} else this.context = r(t), this.incrementalParser = new e(this.context);
|
|
761
|
+
this.changeDetector.setParser(this.incrementalParser), this.reset(), n.length > 0 && this.addClass(n);
|
|
519
762
|
}
|
|
520
763
|
removeClass(e) {
|
|
521
764
|
if (this.isDestroyed) return;
|
|
@@ -531,16 +774,32 @@ var _ = class {
|
|
|
531
774
|
styleElementId: this.options.styleId,
|
|
532
775
|
isDestroyed: this.isDestroyed,
|
|
533
776
|
config: this.options.config,
|
|
534
|
-
cacheStats: this.getCacheStats()
|
|
777
|
+
cacheStats: this.getCacheStats(),
|
|
778
|
+
adopted: !this.shadowRoot && this.stylePartitionManager instanceof k,
|
|
779
|
+
sharedSheet: this.shadowRoot && this.stylePartitionManager instanceof k ? {
|
|
780
|
+
roots: this.stylePartitionManager.shared.rootCount,
|
|
781
|
+
rules: this.stylePartitionManager.shared.ruleCount,
|
|
782
|
+
generations: this.stylePartitionManager.shared.generations,
|
|
783
|
+
constructable: this.stylePartitionManager.shared.constructable
|
|
784
|
+
} : null
|
|
535
785
|
};
|
|
536
786
|
}
|
|
537
|
-
},
|
|
538
|
-
function
|
|
539
|
-
|
|
787
|
+
}, N = null, P, F = "", I = !1, L = !1;
|
|
788
|
+
function R(e = {}) {
|
|
789
|
+
if (!N || N.getStats().isDestroyed ? (N = new M(e), P = e.config, F = e.nonce ?? "", I = e.constructable ?? !1, L = !1) : e.config && e.config !== P && (N.updateConfig(e.config), P = e.config), !L) {
|
|
790
|
+
let t = e.nonce !== void 0 && e.nonce !== F, n = e.constructable !== void 0 && e.constructable !== I;
|
|
791
|
+
if (t || n) {
|
|
792
|
+
L = !0;
|
|
793
|
+
let e = [t && `nonce (runtime has ${F ? "a different nonce" : "none"})`, n && `constructable (runtime has ${I})`].filter(Boolean).join(" and ");
|
|
794
|
+
console.warn(`[BaroCSS] runtime already created with a different ${e}; the new value is ignored. Pass nonce/constructable on the first getRuntime/baroStart call.`);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return N;
|
|
540
798
|
}
|
|
541
|
-
function
|
|
799
|
+
function z({ loadingClassName: e = "baro-boot", ...t } = {}) {
|
|
800
|
+
if (t.root && t.root.nodeType === 11) return new M(t);
|
|
542
801
|
if (!document.body) {
|
|
543
|
-
document.addEventListener("DOMContentLoaded", () =>
|
|
802
|
+
document.addEventListener("DOMContentLoaded", () => z({
|
|
544
803
|
loadingClassName: e,
|
|
545
804
|
...t
|
|
546
805
|
}), { once: !0 });
|
|
@@ -548,7 +807,7 @@ function w({ loadingClassName: e = "baro-boot", ...t } = {}) {
|
|
|
548
807
|
}
|
|
549
808
|
let n = `${e}-doing`, r = `${e}-done`;
|
|
550
809
|
try {
|
|
551
|
-
document.body.classList.add(n),
|
|
810
|
+
document.body.classList.add(n), R(t).observe(document.body, {
|
|
552
811
|
scan: !0,
|
|
553
812
|
onReady: () => {
|
|
554
813
|
document.body.classList.remove(n), document.body.classList.add(r);
|
|
@@ -558,10 +817,10 @@ function w({ loadingClassName: e = "baro-boot", ...t } = {}) {
|
|
|
558
817
|
document.body?.classList.remove(n), console.error("BaroCSS boot failed:", e);
|
|
559
818
|
}
|
|
560
819
|
}
|
|
561
|
-
var
|
|
820
|
+
var B = z;
|
|
562
821
|
//#endregion
|
|
563
822
|
//#region src/json-render-preload.ts
|
|
564
|
-
function
|
|
823
|
+
function V(e) {
|
|
565
824
|
if (!e || typeof e != "object" || Array.isArray(e)) return [];
|
|
566
825
|
let t = e.elements;
|
|
567
826
|
if (!t || typeof t != "object" || Array.isArray(t)) return [];
|
|
@@ -572,15 +831,15 @@ function E(e) {
|
|
|
572
831
|
let i = r.props;
|
|
573
832
|
if (!i || typeof i != "object" || Array.isArray(i)) continue;
|
|
574
833
|
let a = i.className;
|
|
575
|
-
if (typeof a == "string") for (let e of a
|
|
834
|
+
if (typeof a == "string") for (let e of d(a)) e && n.add(e);
|
|
576
835
|
}
|
|
577
836
|
return Array.from(n);
|
|
578
837
|
}
|
|
579
|
-
function
|
|
580
|
-
let n =
|
|
838
|
+
function H(e, t) {
|
|
839
|
+
let n = V(e);
|
|
581
840
|
n.length > 0 && t.addClass(n);
|
|
582
841
|
}
|
|
583
|
-
var
|
|
842
|
+
var U = {
|
|
584
843
|
colors: Object.fromEntries((/* @__PURE__ */ "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})`])),
|
|
585
844
|
borderRadius: {
|
|
586
845
|
sm: "calc(var(--radius) - 4px)",
|
|
@@ -590,4 +849,4 @@ var O = {
|
|
|
590
849
|
}
|
|
591
850
|
};
|
|
592
851
|
//#endregion
|
|
593
|
-
export {
|
|
852
|
+
export { M as BrowserRuntime, f as ChangeDetector, j as LAYER_ORDER, A as SSR_STYLE_SELECTOR, c as StylePartitionManager, z as baroBoot, B as baroStart, V as collectJsonRenderClassNames, R as getRuntime, u as normalizeClassName, d as normalizeClassNameList, H as preloadJsonRenderClasses, U as shadcnTheme };
|