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