| @@ 547-574 (lines=28) @@ | ||
| 544 | } |
|
| 545 | } |
|
| 546 | ||
| 547 | if ( ! function_exists( 'wc_hex_darker' ) ) { |
|
| 548 | ||
| 549 | /** |
|
| 550 | * Hex darker/lighter/contrast functions for colours. |
|
| 551 | * |
|
| 552 | * @param mixed $color |
|
| 553 | * @param int $factor (default: 30) |
|
| 554 | * @return string |
|
| 555 | */ |
|
| 556 | function wc_hex_darker( $color, $factor = 30 ) { |
|
| 557 | $base = wc_rgb_from_hex( $color ); |
|
| 558 | $color = '#'; |
|
| 559 | ||
| 560 | foreach ( $base as $k => $v ) { |
|
| 561 | $amount = $v / 100; |
|
| 562 | $amount = round( $amount * $factor ); |
|
| 563 | $new_decimal = $v - $amount; |
|
| 564 | ||
| 565 | $new_hex_component = dechex( $new_decimal ); |
|
| 566 | if ( strlen( $new_hex_component ) < 2 ) { |
|
| 567 | $new_hex_component = "0" . $new_hex_component; |
|
| 568 | } |
|
| 569 | $color .= $new_hex_component; |
|
| 570 | } |
|
| 571 | ||
| 572 | return $color; |
|
| 573 | } |
|
| 574 | } |
|
| 575 | ||
| 576 | if ( ! function_exists( 'wc_hex_lighter' ) ) { |
|
| 577 | ||
| @@ 576-604 (lines=29) @@ | ||
| 573 | } |
|
| 574 | } |
|
| 575 | ||
| 576 | if ( ! function_exists( 'wc_hex_lighter' ) ) { |
|
| 577 | ||
| 578 | /** |
|
| 579 | * Hex darker/lighter/contrast functions for colours. |
|
| 580 | * |
|
| 581 | * @param mixed $color |
|
| 582 | * @param int $factor (default: 30) |
|
| 583 | * @return string |
|
| 584 | */ |
|
| 585 | function wc_hex_lighter( $color, $factor = 30 ) { |
|
| 586 | $base = wc_rgb_from_hex( $color ); |
|
| 587 | $color = '#'; |
|
| 588 | ||
| 589 | foreach ( $base as $k => $v ) { |
|
| 590 | $amount = 255 - $v; |
|
| 591 | $amount = $amount / 100; |
|
| 592 | $amount = round( $amount * $factor ); |
|
| 593 | $new_decimal = $v + $amount; |
|
| 594 | ||
| 595 | $new_hex_component = dechex( $new_decimal ); |
|
| 596 | if ( strlen( $new_hex_component ) < 2 ) { |
|
| 597 | $new_hex_component = "0" . $new_hex_component; |
|
| 598 | } |
|
| 599 | $color .= $new_hex_component; |
|
| 600 | } |
|
| 601 | ||
| 602 | return $color; |
|
| 603 | } |
|
| 604 | } |
|
| 605 | ||
| 606 | if ( ! function_exists( 'wc_light_or_dark' ) ) { |
|
| 607 | ||