Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
11.11% covered (danger)
11.11%
1 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AnchorSizeFunction
11.11% covered (danger)
11.11%
1 / 9
50.00% covered (danger)
50.00%
1 / 2
15.24
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
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `anchor-size([<anchor-element>] <anchor-size>, [<fallback>])`
9 * per CSS Anchor Positioning 1 ยง7. Used to size the box relative
10 * to a named anchor's width / height / inline-size / block-size.
11 *
12 *   width: anchor-size(--card width)
13 *   height: anchor-size(--card height, 200px)
14 */
15final readonly class AnchorSizeFunction extends Value
16{
17    public function __construct(
18        public ?string $anchorName,
19        public Value $dimension,
20        public ?Value $fallback = null,
21    ) {}
22
23    public function toCss(): string
24    {
25        $parts = [];
26        if ($this->anchorName !== null) {
27            $parts[] = $this->anchorName;
28        }
29        $parts[] = $this->dimension->toCss();
30        $head = 'anchor-size(' . implode(' ', $parts);
31        return $this->fallback !== null
32            ? $head . ', ' . $this->fallback->toCss() . ')'
33            : $head . ')';
34    }
35}