Skip to content

Commit db690e6

Browse files
committed
fix(tasty): total css calculation in debug
1 parent 625a392 commit db690e6

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.changeset/seven-seas-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix CSS total size calculation in debug tools.

src/tasty/debug.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,25 @@ export const tastyDebug = {
590590
log?: boolean;
591591
}): GlobalBreakdown {
592592
const { root = document, log = false } = opts || {};
593-
const css = getGlobalCSS(root);
594-
const rules = extractCSSRules(css);
593+
const allCSS = injector.instance.getCssText({ root });
594+
const rules = extractCSSRules(allCSS);
595+
596+
const globalRules = rules.filter((rule) => {
597+
const selectors = rule.selector.split(',').map((s) => s.trim());
598+
return !selectors.every((selector) => {
599+
const cleanSelector = selector.replace(/[.#:\s>+~[\]()]/g, ' ');
600+
const parts = cleanSelector.split(/\s+/).filter(Boolean);
601+
return parts.length > 0 && parts.every((part) => /^t\d+$/.test(part));
602+
});
603+
});
604+
605+
// Calculate raw CSS size for consistent size calculations
606+
const rawGlobalCSS = globalRules
607+
.map((rule) => `${rule.selector} { ${rule.declarations} }`)
608+
.join('\n');
609+
610+
// Use prettified CSS for display
611+
const css = prettifyCSS(rawGlobalCSS);
595612

596613
// Analyze selectors
597614
const selectors = {
@@ -604,7 +621,7 @@ export const tastyDebug = {
604621
other: [] as string[],
605622
};
606623

607-
rules.forEach((rule) => {
624+
globalRules.forEach((rule) => {
608625
const selector = rule.selector;
609626
if (selector.startsWith('@media')) {
610627
selectors.mediaQueries.push(selector);
@@ -633,8 +650,8 @@ export const tastyDebug = {
633650

634651
const result = {
635652
css,
636-
totalRules: rules.length,
637-
totalCSSSize: css.length,
653+
totalRules: globalRules.length,
654+
totalCSSSize: rawGlobalCSS.length, // Use raw CSS length for consistent size calculations
638655
selectors,
639656
};
640657

@@ -776,7 +793,7 @@ export const tastyDebug = {
776793
totalStyledClasses: cacheStatus.classes.all,
777794
activeCSSSize: activeCSS.length,
778795
unusedCSSSize: unusedCSS.length,
779-
totalCSSSize: allCSS.length,
796+
totalCSSSize: allCSS.length, // This includes active + unused + global CSS
780797
activeCSS: prettifyCSS(activeCSS),
781798
unusedCSS: prettifyCSS(unusedCSS),
782799
allCSS: prettifyCSS(allCSS),

0 commit comments

Comments
 (0)