forked from MarcusSchwarz/lesserphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.php
More file actions
144 lines (128 loc) · 3.9 KB
/
Copy pathType.php
File metadata and controls
144 lines (128 loc) · 3.9 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace LesserPHP\Functions;
use LesserPHP\Utils\Asserts;
use LesserPHP\Utils\Color;
use LesserPHP\Utils\Util;
/**
* Implements the type functions for LESS
*
* @link https://lesscss.org/functions/#type-functions
*/
class Type extends AbstractFunctionCollection
{
/** @inheritdoc */
public function getFunctions(): array
{
return [
'isnumber' => [$this, 'isnumber'],
'isstring' => [$this, 'isstring'],
'iscolor' => [$this, 'iscolor'],
'iskeyword' => [$this, 'iskeyword'],
'isurl' => [$this, 'isurl'],
'ispixel' => [$this, 'ispixel'],
'isem' => [$this, 'isem'],
'isrem' => [$this, 'isrem'],
'ispercentage' => [$this, 'ispercentage'],
'isunit' => [$this, 'isunit'],
//'isruleset' => [$this, 'isruleset'],
//'isdefined' => [$this, 'isdefined'],
];
}
/**
* Returns true if a value is a number, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-isnumber
*/
public function isnumber(array $value): array
{
return Util::toBool($value[0] == 'number');
}
/**
* Returns true if a value is a string, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-isstring
*/
public function isstring(array $value): array
{
return Util::toBool($value[0] == 'string');
}
/**
* Returns true if a value is a color, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-iscolor
*/
public function iscolor(array $value): array
{
return Util::toBool(Color::coerceColor($value));
}
/**
* Returns true if a value is a keyword, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-iskeyword
*/
public function iskeyword(array $value): array
{
return Util::toBool($value[0] == 'keyword');
}
/**
* Returns true if a value is a url, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-isurl
*/
public function isurl(array $value): array
{
return Util::toBool($value[0] == 'function' && $value[1] == 'url');
}
/**
* Returns true if a value is a number in pixels, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-ispixel
*/
public function ispixel(array $value): array
{
return Util::toBool($value[0] == 'number' && $value[2] == 'px');
}
/**
* Returns true if a value is an em value, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-isem
*/
public function isem(array $value): array
{
return Util::toBool($value[0] == 'number' && $value[2] == 'em');
}
/**
* Returns true if a value is an rem value, false otherwise
*
* This method does not exist in the official less.js implementation
*/
public function isrem(array $value): array
{
return Util::toBool($value[0] == 'number' && $value[2] == 'rem');
}
/**
* Returns true if a value is a percentage, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-ispercentage
*/
public function ispercentage(array $value): array
{
return Util::toBool($value[0] == 'number' && $value[2] == '%');
}
/**
* Returns true if a value is a number with a given unit, false otherwise
*
* @link https://lesscss.org/functions/#type-functions-isunit
*/
public function isunit(array $args): array
{
[$input, $unit] = Asserts::assertArgs($args, 2, 'isunit');
$unit = $this->lessc->compileValue($this->lessc->unwrap($unit));
return Util::toBool(
$input[0] == 'number' &&
$input[2] == $unit
);
}
// isruleset is missing
// isdefined is missing
}