@@ -266,41 +266,33 @@ colorFunctions = {
266
266
greyscale : function ( color ) {
267
267
return colorFunctions . desaturate ( color , new Dimension ( 100 ) ) ;
268
268
} ,
269
- contrast : function ( color , color1 , color2 , threshold ) {
270
- // Return which of `color1` and `color2` has the greatest contrast with `color`
271
- // according to the standard WCAG contrast ratio calculation.
272
- // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
273
- // The threshold param is no longer used, in line with SASS.
269
+ contrast : function ( color , dark , light , threshold ) {
274
270
// filter: contrast(3.2);
275
271
// should be kept as is, so check for color
276
272
if ( ! color . rgb ) {
277
273
return null ;
278
274
}
279
- if ( typeof color1 === 'undefined' ) {
280
- color1 = colorFunctions . rgba ( 0 , 0 , 0 , 1.0 ) ;
275
+ if ( typeof light === 'undefined' ) {
276
+ light = colorFunctions . rgba ( 255 , 255 , 255 , 1.0 ) ;
281
277
}
282
- if ( typeof color2 === 'undefined' ) {
283
- color2 = colorFunctions . rgba ( 255 , 255 , 255 , 1.0 ) ;
278
+ if ( typeof dark === 'undefined' ) {
279
+ dark = colorFunctions . rgba ( 0 , 0 , 0 , 1.0 ) ;
284
280
}
285
- var contrast1 , contrast2 ;
286
- var luma = color . luma ( ) ;
287
- var luma1 = color1 . luma ( ) ;
288
- var luma2 = color2 . luma ( ) ;
289
- // Calculate contrast ratios for each color
290
- if ( luma > luma1 ) {
291
- contrast1 = ( luma + 0.05 ) / ( luma1 + 0.05 ) ;
292
- } else {
293
- contrast1 = ( luma1 + 0.05 ) / ( luma + 0.05 ) ;
281
+ //Figure out which is actually light and dark!
282
+ if ( dark . luma ( ) > light . luma ( ) ) {
283
+ var t = light ;
284
+ light = dark ;
285
+ dark = t ;
294
286
}
295
- if ( luma > luma2 ) {
296
- contrast2 = ( luma + 0.05 ) / ( luma2 + 0.05 ) ;
287
+ if ( typeof threshold === 'undefined' ) {
288
+ threshold = 0.43 ;
297
289
} else {
298
- contrast2 = ( luma2 + 0.05 ) / ( luma + 0.05 ) ;
290
+ threshold = number ( threshold ) ;
299
291
}
300
- if ( contrast1 > contrast2 ) {
301
- return color1 ;
292
+ if ( color . luma ( ) < threshold ) {
293
+ return light ;
302
294
} else {
303
- return color2 ;
295
+ return dark ;
304
296
}
305
297
} ,
306
298
argb : function ( color ) {
0 commit comments