@@ -3,6 +3,7 @@ package cmd
33import (
44 "fmt"
55 "regexp"
6+ "slices"
67 "strconv"
78 "strings"
89)
@@ -39,19 +40,17 @@ func (c *Command) checkProperty(str string) bool {
3940 return false
4041 }
4142
42- for _ , p := range c .Properties {
43- if p == property [0 ] {
44- return true
45- }
46- }
47- return false
43+ return slices .Contains (c .Properties , property [0 ])
4844}
4945
5046func (c * Command ) makeProperty (str string ) string {
5147 // remove media and prefix from attribute
5248 str = mediaRegex .ReplaceAllString (str , "" )
5349 str = prefixRegex .ReplaceAllString (str , "" )
5450
51+ // Expand shortcuts BEFORE any other processing
52+ str = c .expandShortcuts (str )
53+
5554 // First check for color patterns like "color-red-400"
5655 colorStr , isColor := c .makeColor (str )
5756 if isColor {
@@ -85,17 +84,17 @@ func (c *Command) makeProperty(str string) string {
8584
8685 // Join parts before the property end to form the property name
8786 property := strings .Join (parts [:propertyEndIdx ], "-" )
88-
87+
8988 // Process each value part individually
9089 valueParts := parts [propertyEndIdx :]
9190 processedValues := make ([]string , len (valueParts ))
92-
91+
9392 for i , part := range valueParts {
9493 // Check if this part contains a ~ for strict value
9594 if strings .Contains (part , "~" ) {
9695 // Split by ~ and take the strict value
9796 strictParts := strings .Split (part , "~" )
98-
97+
9998 // First part could be empty if ~ is at the beginning
10099 if strictParts [0 ] != "" {
101100 // First part is not strict, process normally
@@ -109,7 +108,7 @@ func (c *Command) makeProperty(str string) string {
109108 processedValues [i ] = strictParts [0 ]
110109 }
111110 }
112-
111+
113112 // Second part is strict, don't apply divider or unit
114113 if len (strictParts ) > 1 {
115114 if processedValues [i ] != "" {
@@ -131,7 +130,7 @@ func (c *Command) makeProperty(str string) string {
131130 }
132131 }
133132 }
134-
133+
135134 // Join the processed values with spaces
136135 return property + ":" + strings .Join (processedValues , " " )
137136}
@@ -157,6 +156,60 @@ func (c *Command) makeColor(str string) (string, bool) {
157156 return str , false
158157}
159158
159+ func (c * Command ) expandShortcuts (str string ) string {
160+ if len (c .Config .Shortcuts ) == 0 {
161+ return str
162+ }
163+
164+ return c .expandRegularShortcuts (str )
165+ }
166+
167+ func (c * Command ) expandRegularShortcuts (str string ) string {
168+ parts := strings .Split (str , "-" )
169+ if len (parts ) <= 1 {
170+ return str
171+ }
172+
173+ // Expand shortcuts in property parts (before values)
174+ expanded := make ([]string , len (parts ))
175+ copy (expanded , parts )
176+
177+ for i , part := range parts {
178+ // Stop expanding when we hit a numeric value or potential color
179+ if regexp .MustCompile (`\d` ).MatchString (part ) || c .isColorPart (i , parts ) {
180+ break
181+ }
182+
183+ if replacement , exists := c .Config .Shortcuts [part ]; exists {
184+ expanded [i ] = replacement
185+ }
186+ }
187+
188+ return strings .Join (expanded , "-" )
189+ }
190+
191+ func (c * Command ) isColorPart (index int , parts []string ) bool {
192+ // Check if this might be part of a color pattern
193+ // We need at least 2 more parts after current index for color-shade pattern
194+ if index >= len (parts )- 2 {
195+ return false
196+ }
197+
198+ // Look ahead to see if we have a color-shade pattern
199+ // For example: "color-red-400" where current part is "color", next is "red", and after that is "400"
200+ if index <= len (parts )- 3 {
201+ colorName := parts [index + 1 ]
202+ shadeName := parts [index + 2 ]
203+ if colorMap , exists := c .Config .Colors [colorName ]; exists {
204+ if _ , exists := colorMap [shadeName ]; exists {
205+ return true
206+ }
207+ }
208+ }
209+
210+ return false
211+ }
212+
160213func classType (str string ) string {
161214 if strings .Contains (str , ":" ) {
162215 return "prefix"
0 commit comments