1<?php
2
3namespace LesserPHP\Functions;
4
5use Exception;
6use LesserPHP\Utils\Asserts;
7
8/**
9 * Implements the color definition functions of LESS
10 *
11 * @link https://lesscss.org/functions/#color-definition
12 */
13class ColorDefinition extends AbstractFunctionCollection
14{
15    /** @inheritdoc */
16    public function getFunctions(): array
17    {
18        return [
19            //'rgb' => [$this, 'rgb'],
20            //'rgba' => [$this, 'rgba'],
21            'rgbahex' => [$this, 'rgbahex'],
22            'argb' => [$this, 'argb'],
23            //'hsl' => [$this, 'hsl'],
24            //'hsla' => [$this, 'hsla'],
25            //'hsv' => [$this, 'hsv'],
26            //'hsva' => [$this, 'hsva'],
27        ];
28    }
29
30    // rgb is missing
31    // rgba is missing
32
33    /**
34     * Creates a hex representation of a color in #AARRGGBB format (NOT #RRGGBBAA!)
35     *
36     * This method does not exist in the official less.js implementation
37     * @see lib_argb
38     * @throws Exception
39     */
40    public function rgbahex(array $color): string
41    {
42        $color = Asserts::assertColor($color);
43
44        return sprintf(
45            '#%02x%02x%02x%02x',
46            isset($color[4]) ? $color[4] * 255 : 255,
47            $color[1],
48            $color[2],
49            $color[3]
50        );
51    }
52
53    /**
54     * Creates a hex representation of a color in #AARRGGBB format (NOT #RRGGBBAA!)
55     *
56     * @https://lesscss.org/functions/#color-definition-argb
57     * @throws Exception
58     */
59    public function argb(array $color): string
60    {
61        return $this->rgbahex($color);
62    }
63
64    // hsl is missing
65
66    // hsla is missing
67
68    // hsv is missing
69
70    // hsva is missing
71}
72