Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ContrastColor | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * CSS Color 7 §4 — `contrast-color(<color>)`. Returns the |
| 9 | * highest-contrast color (UA picks from black / white in the |
| 10 | * baseline form) against the input. Useful for `color: contrast- |
| 11 | * color(background-color)` where the foreground should always |
| 12 | * be legible regardless of the background's exact hue. |
| 13 | * |
| 14 | * Stored as the input color; the renderer picks black vs white |
| 15 | * at paint time by computing relative luminance and returning |
| 16 | * the one farther from the input on the 0..1 axis. |
| 17 | */ |
| 18 | final readonly class ContrastColor extends Value |
| 19 | { |
| 20 | public function __construct(public Value $base) {} |
| 21 | |
| 22 | public function toCss(): string |
| 23 | { |
| 24 | return 'contrast-color(' . $this->base->toCss() . ')'; |
| 25 | } |
| 26 | } |