@@ -50,6 +50,38 @@ describe('transform color modifiers', () => {
50
50
// without space, return original
51
51
expect ( transformColorModifiers ( token ( '' ) ) ) . to . equal ( '#C14242' ) ;
52
52
} ) ;
53
+
54
+ it ( 'supports lighten color modifiers in all 4 spaces with value calculation' , ( ) => {
55
+ const token = ( space : ColorSpaceTypes | '' ) => ( {
56
+ value : '#C14242' ,
57
+ type : 'color' ,
58
+ $extensions : {
59
+ 'studio.tokens' : {
60
+ modify : {
61
+ type : 'lighten' ,
62
+ value : '0.5 - 0.3' ,
63
+ space,
64
+ } ,
65
+ } ,
66
+ } ,
67
+ } ) ;
68
+
69
+ // lighten faint red to more light red
70
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . HSL ) ) ) . to . equal (
71
+ 'hsl(0 50.598% 60.627%)' ,
72
+ ) ;
73
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . LCH ) ) ) . to . equal (
74
+ 'lch(57.685 47.48 29.704)' ,
75
+ ) ;
76
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . P3 ) ) ) . to . equal (
77
+ 'color(display-p3 0.76016 0.43532 0.42213)' ,
78
+ ) ;
79
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . SRGB ) ) ) . to . equal (
80
+ 'rgb(80.549% 40.706% 40.706%)' ,
81
+ ) ;
82
+ // without space, return original
83
+ expect ( transformColorModifiers ( token ( '' ) ) ) . to . equal ( '#C14242' ) ;
84
+ } ) ;
53
85
} ) ;
54
86
55
87
describe ( 'darken' , ( ) => {
@@ -84,6 +116,38 @@ describe('transform color modifiers', () => {
84
116
// without space, return original
85
117
expect ( transformColorModifiers ( token ( '' ) ) ) . to . equal ( '#C14242' ) ;
86
118
} ) ;
119
+
120
+ it ( 'supports darken color modifiers in all 4 spaces with value calculation' , ( ) => {
121
+ const token = ( space : ColorSpaceTypes | '' ) => ( {
122
+ value : '#C14242' ,
123
+ type : 'color' ,
124
+ $extensions : {
125
+ 'studio.tokens' : {
126
+ modify : {
127
+ type : 'darken' ,
128
+ value : '0.5 - 0.3' ,
129
+ space,
130
+ } ,
131
+ } ,
132
+ } ,
133
+ } ) ;
134
+
135
+ // darken faint red to more darkened red
136
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . HSL ) ) ) . to . equal (
137
+ 'hsl(0 50.598% 40.627%)' ,
138
+ ) ;
139
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . LCH ) ) ) . to . equal (
140
+ 'lch(37.685 47.48 29.704)' ,
141
+ ) ;
142
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . P3 ) ) ) . to . equal (
143
+ 'color(display-p3 0.56016 0.23532 0.22213)' ,
144
+ ) ;
145
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . SRGB ) ) ) . to . equal (
146
+ 'rgb(60.549% 20.706% 20.706%)' ,
147
+ ) ;
148
+ // without space, return original
149
+ expect ( transformColorModifiers ( token ( '' ) ) ) . to . equal ( '#C14242' ) ;
150
+ } ) ;
87
151
} ) ;
88
152
89
153
describe ( 'mix' , ( ) => {
@@ -114,7 +178,7 @@ describe('transform color modifiers', () => {
114
178
expect ( transformColorModifiers ( token ( '' ) ) ) . to . equal ( '#000000' ) ;
115
179
} ) ;
116
180
117
- it ( 'supports mix modifier value calculations ' , ( ) => {
181
+ it ( 'supports mix color modifiers in all 4 spaces with value calculation ' , ( ) => {
118
182
const token = ( space : ColorSpaceTypes | '' , format ?) => ( {
119
183
value : '#FFFFFF' ,
120
184
type : 'color' ,
@@ -177,6 +241,35 @@ describe('transform color modifiers', () => {
177
241
'rgb(75.686% 25.882% 25.882% / 0.2)' ,
178
242
) ;
179
243
} ) ;
244
+
245
+ it ( 'supports transparentize color modifiers in all 4 spaces with value calculation' , ( ) => {
246
+ const token = ( space : ColorSpaceTypes | '' ) => ( {
247
+ value : '#C14242' ,
248
+ type : 'color' ,
249
+ $extensions : {
250
+ 'studio.tokens' : {
251
+ modify : {
252
+ type : 'alpha' ,
253
+ value : '0.5 - 0.3' ,
254
+ space,
255
+ } ,
256
+ } ,
257
+ } ,
258
+ } ) ;
259
+
260
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . HSL ) ) ) . to . equal (
261
+ 'hsl(0 50.598% 50.784% / 0.2)' ,
262
+ ) ;
263
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . LCH ) ) ) . to . equal (
264
+ 'lch(47.107 59.35 29.704 / 0.2)' ,
265
+ ) ;
266
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . P3 ) ) ) . to . equal (
267
+ 'color(display-p3 0.7002 0.29415 0.27766 / 0.2)' ,
268
+ ) ;
269
+ expect ( transformColorModifiers ( token ( ColorSpaceTypes . SRGB ) ) ) . to . equal (
270
+ 'rgb(75.686% 25.882% 25.882% / 0.2)' ,
271
+ ) ;
272
+ } ) ;
180
273
} ) ;
181
274
182
275
it ( 'returns the original color if the modifier type is invalid' , ( ) => {
0 commit comments