Skip to content

Commit 128002c

Browse files
committed
fix(tasty): optimizations * 2
1 parent adfb7b3 commit 128002c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/tasty/injector/injector.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,8 @@ export class StyleInjector {
8787
const className =
8888
generatedClass || generateClassName(registry.classCounter++);
8989

90-
// Increase specificity for class-based selectors by duplicating the class
91-
const rulesToInsert = rules.map((r) => {
92-
// Increase specificity for class-based selectors by duplicating the class
93-
if (r.selector.startsWith('.') && /^\.t\d+/.test(r.selector)) {
94-
const classMatch = r.selector.match(/^\.t\d+/);
95-
if (classMatch) {
96-
const baseClass = classMatch[0];
97-
return {
98-
...r,
99-
selector: baseClass + r.selector,
100-
} as StyleRule;
101-
}
102-
}
103-
return r;
104-
});
90+
// Use rules as-is - specificity is handled during selector generation
91+
const rulesToInsert = rules;
10592

10693
// Before inserting, auto-register @property for any color custom properties being defined.
10794
// Fast parse: split declarations by ';' and match "--*-color:"

src/tasty/utils/renderStyles.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,13 @@ function materializeRules(
440440
zones: ResponsiveZone[],
441441
): StyleResult[] {
442442
return logicalRules.map((rule) => {
443-
const selector = `.${className}${rule.selectorSuffix}`;
443+
// Generate base selector
444+
let selector = `.${className}${rule.selectorSuffix}`;
445+
446+
// Increase specificity for tasty class selectors by duplicating the class
447+
if (/^t\d+$/.test(className)) {
448+
selector = `.${className}${selector}`;
449+
}
444450

445451
const declarations = Object.entries(rule.declarations)
446452
.map(([prop, value]) => `${prop}: ${value};`)
@@ -976,10 +982,19 @@ export function renderStyles(
976982
// Direct selector mode: convert logical rules directly to StyleResult format
977983
return allLogicalRules.map((rule) => {
978984
// Replace & with the actual selector or append suffix to selector
979-
const finalSelector = rule.selectorSuffix
985+
let finalSelector = rule.selectorSuffix
980986
? `${classNameOrSelector}${rule.selectorSuffix}`
981987
: classNameOrSelector;
982988

989+
// Increase specificity for tasty class selectors by duplicating the class
990+
if (finalSelector.startsWith('.') && /^\.t\d+/.test(finalSelector)) {
991+
const classMatch = finalSelector.match(/^\.t\d+/);
992+
if (classMatch) {
993+
const baseClass = classMatch[0];
994+
finalSelector = baseClass + finalSelector;
995+
}
996+
}
997+
983998
const declarations = Object.entries(rule.declarations)
984999
.map(([prop, value]) => `${prop}: ${value};`)
9851000
.join(' ');

0 commit comments

Comments
 (0)