@@ -526,30 +526,30 @@ def _generate_effects(self):
526526 )
527527
528528 def _generate_states (self ):
529- """
530- Generates pseudo-state variants for all currently defined styles.
531- e.g., creates .hover\\ :bg-red:hover from .bg-red
532- """
533- # We take a snapshot of the current styles to avoid infinite loops
534- # (Since adding a style modifies the list we are iterating over)
529+ from violetear import Selector , Style
530+
531+ # Snapshot current styles to avoid infinite recursion
535532 base_styles = list (self .styles )
536533
537534 for style in base_styles :
538- # We only generate variants for class selectors
539- # (Skipping tag selectors like 'body' if you had them)
540- original_selector = style .selector .css ()
541- if not original_selector .startswith ("." ):
535+ # Skip styles that aren't class-based or are already complex
536+ if not style .selector ._classes :
542537 continue
543538
544- # The class name without the dot (e.g., "bg-red")
545- class_name = original_selector [1 :]
539+ original_class = style .selector ._classes [0 ]
546540
547541 for state in self .states :
548- # Tailwind syntax: state:class (escaped as state\:class in CSS)
549- # e.g., .hover\:bg-red:hover
550- variant_class = f"{ state } \\ :{ class_name } "
551-
552- # Create the new style
553- # 1. Create selector with the escaped class
554- # 2. Add the pseudo-class state (:hover)
555- self .select (f".{ variant_class } " ).on (state ).apply (style )
542+ # We create a class name like "hover:bg-red"
543+ # In CSS this must be escaped as ".hover\:bg-red"
544+ variant_class = f"{ state } \:{ original_class } "
545+
546+ # Create a new Style manually to handle the escaped class name
547+ # 1. The selector matches the class (e.g. .hover:bg-red)
548+ # 2. The .on(state) adds the pseudo-class (e.g. :hover)
549+ variant_style = Style (Selector (classes = variant_class )).on (state )
550+
551+ # Copy the rules from the original utility
552+ variant_style .apply (style )
553+
554+ # Register it
555+ self .add (variant_style )
0 commit comments