Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| XywhShape | |
93.33% |
14 / 15 |
|
50.00% |
1 / 2 |
3.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
2.00 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * `xywh(<x> <y> <width> <height> [round <border-radius>]?)` per |
| 9 | * CSS Shapes 2 §4.6. Defines a clip rectangle by its origin + |
| 10 | * size — easier than `rect()`'s edge-distance form when you know |
| 11 | * the actual rectangle dimensions. |
| 12 | * |
| 13 | * clip-path: xywh(0 0 100% 100%); |
| 14 | * clip-path: xywh(10px 10px 90% 80% round 5px); |
| 15 | */ |
| 16 | final readonly class XywhShape extends BasicShape |
| 17 | { |
| 18 | /** |
| 19 | * @param ?list<Value> $borderRadius Optional rounded-corner values. |
| 20 | */ |
| 21 | public function __construct( |
| 22 | public Value $x, |
| 23 | public Value $y, |
| 24 | public Value $width, |
| 25 | public Value $height, |
| 26 | public ?array $borderRadius = null, |
| 27 | ) {} |
| 28 | |
| 29 | public function toCss(): string |
| 30 | { |
| 31 | $parts = sprintf( |
| 32 | '%s %s %s %s', |
| 33 | $this->x->toCss(), |
| 34 | $this->y->toCss(), |
| 35 | $this->width->toCss(), |
| 36 | $this->height->toCss(), |
| 37 | ); |
| 38 | if ($this->borderRadius === null) { |
| 39 | return 'xywh(' . $parts . ')'; |
| 40 | } |
| 41 | $radius = implode(' ', array_map( |
| 42 | static fn(Value $v): string => $v->toCss(), |
| 43 | $this->borderRadius, |
| 44 | )); |
| 45 | return 'xywh(' . $parts . ' round ' . $radius . ')'; |
| 46 | } |
| 47 | } |