@@ -4,6 +4,7 @@ import { mix } from './mix.js';
4
4
import { darken } from './darken.js' ;
5
5
import { lighten } from './lighten.js' ;
6
6
import { ColorModifier } from '@tokens-studio/types' ;
7
+ import { parseAndReduce } from '../checkAndEvaluateMath.js' ;
7
8
8
9
// Users using UIColor swift format are blocked from using such transform in
9
10
// combination with this color modify transform when using references.
@@ -39,24 +40,25 @@ export function modifyColor(
39
40
40
41
const color = new Color ( baseColor ) ;
41
42
let returnedColor = color ;
43
+ const modifyValueResolvedCalc = Number ( parseAndReduce ( modifier . value , 4 ) ) ;
42
44
try {
43
45
switch ( modifier . type ) {
44
46
case 'lighten' :
45
- returnedColor = lighten ( color , modifier . space , Number ( modifier . value ) ) ;
47
+ returnedColor = lighten ( color , modifier . space , modifyValueResolvedCalc ) ;
46
48
break ;
47
49
case 'darken' :
48
- returnedColor = darken ( color , modifier . space , Number ( modifier . value ) ) ;
50
+ returnedColor = darken ( color , modifier . space , modifyValueResolvedCalc ) ;
49
51
break ;
50
52
case 'mix' :
51
53
returnedColor = mix (
52
54
color ,
53
55
modifier . space ,
54
- Number ( modifier . value ) ,
56
+ modifyValueResolvedCalc ,
55
57
new Color ( modifier . color ) ,
56
58
) ;
57
59
break ;
58
60
case 'alpha' : {
59
- returnedColor = transparentize ( color , Number ( modifier . value ) ) ;
61
+ returnedColor = transparentize ( color , modifyValueResolvedCalc ) ;
60
62
break ;
61
63
}
62
64
default :
@@ -75,11 +77,7 @@ export function modifyColor(
75
77
}
76
78
}
77
79
78
- return returnedColor . toString ( {
79
- inGamut : true ,
80
- precision : 3 ,
81
- format : modifier . format ,
82
- } ) ;
80
+ return returnedColor . toString ( { inGamut : true , precision : 3 , format : modifier . format } ) ;
83
81
} catch ( e ) {
84
82
return baseColor ;
85
83
}
0 commit comments