Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ScrollTimeline
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
5.03
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
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Scroll-driven Animations 1 §3.2 — `scroll(<scroller>?
9 * <axis>?)`. Anonymous scroll-progress timeline tied to a scroll
10 * container's progress along an axis.
11 *
12 *   animation-timeline: scroll();
13 *   animation-timeline: scroll(root);
14 *   animation-timeline: scroll(nearest block);
15 *   animation-timeline: scroll(self inline);
16 *
17 * Scroller is one of `nearest | root | self` (or omitted = nearest);
18 * axis is `block | inline | x | y` (or omitted = block).
19 */
20final readonly class ScrollTimeline extends Value
21{
22    public function __construct(
23        public ?string $scroller = null,
24        public ?string $axis = null,
25    ) {}
26
27    public function toCss(): string
28    {
29        $parts = [];
30        if ($this->scroller !== null) {
31            $parts[] = $this->scroller;
32        }
33        if ($this->axis !== null) {
34            $parts[] = $this->axis;
35        }
36        return $parts === []
37            ? 'scroll()'
38            : 'scroll(' . implode(' ', $parts) . ')';
39    }
40}