PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / sabberworm / php-css-parser / src / Value / Size.php
independent-analytics / vendor / sabberworm / php-css-parser / src / Value Last commit date
CSSFunction.php 3 years ago CSSString.php 3 years ago CalcFunction.php 3 years ago CalcRuleValueList.php 3 years ago Color.php 3 years ago LineName.php 3 years ago PrimitiveValue.php 3 years ago RuleValueList.php 3 years ago Size.php 3 years ago URL.php 3 years ago Value.php 3 years ago ValueList.php 3 years ago
Size.php
186 lines
1 <?php
2
3 namespace IAWP\Sabberworm\CSS\Value;
4
5 use IAWP\Sabberworm\CSS\OutputFormat;
6 use IAWP\Sabberworm\CSS\Parsing\ParserState;
7 use IAWP\Sabberworm\CSS\Parsing\UnexpectedEOFException;
8 use IAWP\Sabberworm\CSS\Parsing\UnexpectedTokenException;
9 class Size extends PrimitiveValue
10 {
11 /**
12 * vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport)
13 *
14 * @var array<int, string>
15 */
16 const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
17 /**
18 * @var array<int, string>
19 */
20 const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr'];
21 /**
22 * @var array<int, string>
23 */
24 const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turns', 'Hz', 'kHz'];
25 /**
26 * @var array<int, array<string, string>>|null
27 */
28 private static $SIZE_UNITS = null;
29 /**
30 * @var float
31 */
32 private $fSize;
33 /**
34 * @var string|null
35 */
36 private $sUnit;
37 /**
38 * @var bool
39 */
40 private $bIsColorComponent;
41 /**
42 * @param float|int|string $fSize
43 * @param string|null $sUnit
44 * @param bool $bIsColorComponent
45 * @param int $iLineNo
46 */
47 public function __construct($fSize, $sUnit = null, $bIsColorComponent = \false, $iLineNo = 0)
48 {
49 parent::__construct($iLineNo);
50 $this->fSize = (float) $fSize;
51 $this->sUnit = $sUnit;
52 $this->bIsColorComponent = $bIsColorComponent;
53 }
54 /**
55 * @param bool $bIsColorComponent
56 *
57 * @return Size
58 *
59 * @throws UnexpectedEOFException
60 * @throws UnexpectedTokenException
61 */
62 public static function parse(ParserState $oParserState, $bIsColorComponent = \false)
63 {
64 $sSize = '';
65 if ($oParserState->comes('-')) {
66 $sSize .= $oParserState->consume('-');
67 }
68 while (\is_numeric($oParserState->peek()) || $oParserState->comes('.')) {
69 if ($oParserState->comes('.')) {
70 $sSize .= $oParserState->consume('.');
71 } else {
72 $sSize .= $oParserState->consume(1);
73 }
74 }
75 $sUnit = null;
76 $aSizeUnits = self::getSizeUnits();
77 foreach ($aSizeUnits as $iLength => &$aValues) {
78 $sKey = \strtolower($oParserState->peek($iLength));
79 if (\array_key_exists($sKey, $aValues)) {
80 if (($sUnit = $aValues[$sKey]) !== null) {
81 $oParserState->consume($iLength);
82 break;
83 }
84 }
85 }
86 return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine());
87 }
88 /**
89 * @return array<int, array<string, string>>
90 */
91 private static function getSizeUnits()
92 {
93 if (!\is_array(self::$SIZE_UNITS)) {
94 self::$SIZE_UNITS = [];
95 foreach (\array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) {
96 $iSize = \strlen($val);
97 if (!isset(self::$SIZE_UNITS[$iSize])) {
98 self::$SIZE_UNITS[$iSize] = [];
99 }
100 self::$SIZE_UNITS[$iSize][\strtolower($val)] = $val;
101 }
102 \krsort(self::$SIZE_UNITS, \SORT_NUMERIC);
103 }
104 return self::$SIZE_UNITS;
105 }
106 /**
107 * @param string $sUnit
108 *
109 * @return void
110 */
111 public function setUnit($sUnit)
112 {
113 $this->sUnit = $sUnit;
114 }
115 /**
116 * @return string|null
117 */
118 public function getUnit()
119 {
120 return $this->sUnit;
121 }
122 /**
123 * @param float|int|string $fSize
124 */
125 public function setSize($fSize)
126 {
127 $this->fSize = (float) $fSize;
128 }
129 /**
130 * @return float
131 */
132 public function getSize()
133 {
134 return $this->fSize;
135 }
136 /**
137 * @return bool
138 */
139 public function isColorComponent()
140 {
141 return $this->bIsColorComponent;
142 }
143 /**
144 * Returns whether the number stored in this Size really represents a size (as in a length of something on screen).
145 *
146 * @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object.
147 */
148 public function isSize()
149 {
150 if (\in_array($this->sUnit, self::NON_SIZE_UNITS, \true)) {
151 return \false;
152 }
153 return !$this->isColorComponent();
154 }
155 /**
156 * @return bool
157 */
158 public function isRelative()
159 {
160 if (\in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, \true)) {
161 return \true;
162 }
163 if ($this->sUnit === null && $this->fSize != 0) {
164 return \true;
165 }
166 return \false;
167 }
168 /**
169 * @return string
170 */
171 public function __toString()
172 {
173 return $this->render(new OutputFormat());
174 }
175 /**
176 * @return string
177 */
178 public function render(OutputFormat $oOutputFormat)
179 {
180 $l = \localeconv();
181 $sPoint = \preg_quote($l['decimal_point'], '/');
182 $sSize = \preg_match("/[\\d\\.]+e[+-]?\\d+/i", (string) $this->fSize) ? \preg_replace("/{$sPoint}?0+\$/", "", \sprintf("%f", $this->fSize)) : $this->fSize;
183 return \preg_replace(["/{$sPoint}/", "/^(-?)0\\./"], ['.', '$1.'], $sSize) . ($this->sUnit === null ? '' : $this->sUnit);
184 }
185 }
186