Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ElementFunction
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
3.14
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Generated Content for Paged Media 3 §4.2 — `element(<name>
9 * [, <fetch-target>]?)`. Emits a copy of a "running element"
10 * (one positioned via `position: running(name)`) inside a page
11 * margin box. Companion to the §5 `string()` function for the
12 * print-PDF running-header pattern, but carries arbitrary
13 * element content rather than a flat text string.
14 *
15 *   header { position: running(page-header); }
16 *   @page { @top-center { content: element(page-header); } }
17 *
18 * Fetch targets match §5.2:
19 *
20 *   - first        — first running entry on this page (default).
21 *   - start        — value at page start (last entry from
22 *                    earlier pages, or empty).
23 *   - last         — last entry on this page.
24 *   - first-except — like first but empty if the entry begins
25 *                    on this page.
26 */
27final readonly class ElementFunction extends Value
28{
29    public function __construct(
30        public string $name,
31        public string $target = 'first',
32    ) {}
33
34    public function toCss(): string
35    {
36        return $this->target === 'first'
37            ? sprintf('element(%s)', $this->name)
38            : sprintf('element(%s, %s)', $this->name, $this->target);
39    }
40}