Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.82% covered (warning)
81.82%
9 / 11
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ViewTimeline
81.82% covered (warning)
81.82%
9 / 11
50.00% covered (danger)
50.00%
1 / 2
6.22
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
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
5.20
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Scroll-driven Animations 1 §4.2 — `view(<axis>? <inset>?)`.
9 * Anonymous view-progress timeline tied to the element's
10 * intersection with the scroll root.
11 *
12 *   animation-timeline: view();
13 *   animation-timeline: view(block);
14 *   animation-timeline: view(inline 20%);
15 *   animation-timeline: view(20% 50%);
16 *
17 * For static print the timeline never advances; the typed value
18 * lets the cascade carry the declaration so tooling can read it
19 * back.
20 */
21final readonly class ViewTimeline extends Value
22{
23    public function __construct(
24        public ?string $axis = null,
25        public ?Value $insetStart = null,
26        public ?Value $insetEnd = null,
27    ) {}
28
29    public function toCss(): string
30    {
31        $parts = [];
32        if ($this->axis !== null) {
33            $parts[] = $this->axis;
34        }
35        if ($this->insetStart !== null) {
36            $parts[] = $this->insetStart->toCss();
37        }
38        if ($this->insetEnd !== null) {
39            $parts[] = $this->insetEnd->toCss();
40        }
41        return $parts === []
42            ? 'view()'
43            : 'view(' . implode(' ', $parts) . ')';
44    }
45}