@@ -1283,36 +1283,43 @@ protected function lib_mix($args) {
12831283 }
12841284
12851285 protected function lib_contrast ($ args ) {
1286- $ darkColor = array ('color ' , 0 , 0 , 0 );
1287- $ lightColor = array ('color ' , 255 , 255 , 255 );
1288- $ threshold = 0.43 ;
1289-
1290- if ( $ args [0 ] == 'list ' ) {
1291- $ inputColor = ( isset ($ args [2 ][0 ]) ) ? $ this ->assertColor ($ args [2 ][0 ]) : $ lightColor ;
1292- $ darkColor = ( isset ($ args [2 ][1 ]) ) ? $ this ->assertColor ($ args [2 ][1 ]) : $ darkColor ;
1293- $ lightColor = ( isset ($ args [2 ][2 ]) ) ? $ this ->assertColor ($ args [2 ][2 ]) : $ lightColor ;
1294- $ threshold = ( isset ($ args [2 ][3 ]) ) ? $ this ->assertNumber ($ args [2 ][3 ]) : $ threshold ;
1295- }
1296- else {
1297- $ inputColor = $ this ->assertColor ($ args );
1298- }
1299-
1300- $ inputColor = $ this ->coerceColor ($ inputColor );
1301- $ darkColor = $ this ->coerceColor ($ darkColor );
1302- $ lightColor = $ this ->coerceColor ($ lightColor );
1303-
1304- //Figure out which is actually light and dark!
1305- if ( $ this ->toLuma ($ darkColor ) > $ this ->toLuma ($ lightColor ) ) {
1306- $ t = $ lightColor ;
1307- $ lightColor = $ darkColor ;
1308- $ darkColor = $ t ;
1309- }
1310-
1311- $ inputColor_alpha = $ this ->lib_alpha ($ inputColor );
1312- if ( ( $ this ->toLuma ($ inputColor ) * $ inputColor_alpha ) < $ threshold ) {
1313- return $ lightColor ;
1314- }
1315- return $ darkColor ;
1286+ $ darkColor = array ('color ' , 0 , 0 , 0 );
1287+ $ lightColor = array ('color ' , 255 , 255 , 255 );
1288+ $ threshold = 0.43 ;
1289+
1290+ if ( $ args [0 ] == 'list ' ) {
1291+ $ inputColor = ( isset ($ args [2 ][0 ]) ) ? $ this ->assertColor ($ args [2 ][0 ]) : $ lightColor ;
1292+ $ darkColor = ( isset ($ args [2 ][1 ]) ) ? $ this ->assertColor ($ args [2 ][1 ]) : $ darkColor ;
1293+ $ lightColor = ( isset ($ args [2 ][2 ]) ) ? $ this ->assertColor ($ args [2 ][2 ]) : $ lightColor ;
1294+
1295+ if ( isset ($ args [2 ][3 ]) ) {
1296+ if ( isset ($ args [2 ][3 ][2 ]) && $ args [2 ][3 ][2 ] === '% ' ) {
1297+ $ args [2 ][3 ][1 ] /= 100 ;
1298+ unset($ args [2 ][3 ][2 ]);
1299+ }
1300+ $ threshold = $ this ->assertNumber ($ args [2 ][3 ]);
1301+ }
1302+ }
1303+ else {
1304+ $ inputColor = $ this ->assertColor ($ args );
1305+ }
1306+
1307+ $ inputColor = $ this ->coerceColor ($ inputColor );
1308+ $ darkColor = $ this ->coerceColor ($ darkColor );
1309+ $ lightColor = $ this ->coerceColor ($ lightColor );
1310+
1311+ //Figure out which is actually light and dark!
1312+ if ( $ this ->toLuma ($ darkColor ) > $ this ->toLuma ($ lightColor ) ) {
1313+ $ t = $ lightColor ;
1314+ $ lightColor = $ darkColor ;
1315+ $ darkColor = $ t ;
1316+ }
1317+
1318+ $ inputColor_alpha = $ this ->lib_alpha ($ inputColor );
1319+ if ( ( $ this ->toLuma ($ inputColor ) * $ inputColor_alpha ) < $ threshold ) {
1320+ return $ lightColor ;
1321+ }
1322+ return $ darkColor ;
13161323 }
13171324
13181325 private function toLuma ($ color ) {
0 commit comments