Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TargetFunction | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * CSS Generated Content for Paged Media 3 §3 — cross-reference |
| 9 | * functions for print: |
| 10 | * |
| 11 | * - `target-counter(<url>, <counter>, <style>?)` — counter |
| 12 | * value at the linked target element (most commonly used for |
| 13 | * page numbers in tables of contents). |
| 14 | * - `target-counters(<url>, <counter>, <string>, <style>?)` — |
| 15 | * joined chain of nested counters at the target. |
| 16 | * - `target-text(<url>, [content | before | after | |
| 17 | * first-letter]?)` — text content at the target. |
| 18 | * |
| 19 | * `target` is the URL or attr() / var() reference; `name` is the |
| 20 | * counter / scope name (omitted for target-text); `extra` carries |
| 21 | * the optional separator (target-counters) or text-source keyword |
| 22 | * (target-text); `style` is the optional counter-style name |
| 23 | * (target-counter / target-counters only). |
| 24 | * |
| 25 | * The renderer resolves these at painting time once the target |
| 26 | * element's box geometry + counter state are known. |
| 27 | */ |
| 28 | final readonly class TargetFunction extends Value |
| 29 | { |
| 30 | public function __construct( |
| 31 | public TargetFunctionKind $kind, |
| 32 | public Value $target, |
| 33 | public ?Value $name = null, |
| 34 | public ?Value $extra = null, |
| 35 | public ?Value $style = null, |
| 36 | ) {} |
| 37 | |
| 38 | public function toCss(): string |
| 39 | { |
| 40 | $args = [$this->target->toCss()]; |
| 41 | if ($this->name !== null) { |
| 42 | $args[] = $this->name->toCss(); |
| 43 | } |
| 44 | if ($this->extra !== null) { |
| 45 | $args[] = $this->extra->toCss(); |
| 46 | } |
| 47 | if ($this->style !== null) { |
| 48 | $args[] = $this->style->toCss(); |
| 49 | } |
| 50 | return $this->kind->value . '(' . implode(', ', $args) . ')'; |
| 51 | } |
| 52 | } |