@@ -20,26 +20,50 @@ class ColorBuilder implements ProtectedContextAwareInterface
2020 * @param float $red 0-255
2121 * @param float $green 0-255
2222 * @param float $blue 0-255
23- * @param float $alpha 0-255
2423 *
2524 * @return ColorHelper
2625 */
27- public function rgb (float $ red , float $ green , float $ blue , float $ alpha = 255 ): ColorHelper
26+ public function rgb (float $ red , float $ green , float $ blue ): ColorHelper
27+ {
28+ return $ this ->rgba ($ red , $ green , $ blue , 100 );
29+ }
30+
31+ /**
32+ * @param float $red 0-255
33+ * @param float $green 0-255
34+ * @param float $blue 0-255
35+ * @param float $alpha 0-100
36+ *
37+ * @return ColorHelper
38+ */
39+ public function rgba (float $ red , float $ green , float $ blue , float $ alpha = 100 ): ColorHelper
2840 {
2941 return new ColorHelper (
3042 new RgbaColor ($ red , $ green , $ blue , $ alpha )
3143 );
3244 }
3345
46+ /**
47+ * @param float $hue
48+ * @param float $saturatiom
49+ * @param float $lightness
50+ *
51+ * @return ColorHelper
52+ */
53+ public function hsl (float $ hue , float $ saturatiom , float $ lightness ): ColorHelper
54+ {
55+ return $ this ->hsla ($ hue , $ saturatiom , $ lightness , 100 );
56+ }
57+
3458 /**
3559 * @param float $hue 0-360
3660 * @param float $saturatiom 0-100
3761 * @param float $lightness 0-100
38- * @param float $alpha 0-1
62+ * @param float $alpha 0-100
3963 *
4064 * @return ColorHelper
4165 */
42- public function hsl (float $ hue , float $ saturatiom , float $ lightness , float $ alpha = 1 ): ColorHelper
66+ public function hsla (float $ hue , float $ saturatiom , float $ lightness , float $ alpha = 100 ): ColorHelper
4367 {
4468 return new ColorHelper (
4569 new HslaColor ($ hue , $ saturatiom , $ lightness , $ alpha )
@@ -58,7 +82,7 @@ public function hex(string $hex): ?ColorHelper
5882 $ red = hexdec ($ matches ['red ' ].$ matches ['red ' ]);
5983 $ green = hexdec ($ matches ['green ' ].$ matches ['green ' ]);
6084 $ blue = hexdec ($ matches ['blue ' ].$ matches ['blue ' ]);
61- $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ].$ matches ['alpha ' ]) : 255 ;
85+ $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ].$ matches ['alpha ' ]) / 2.55 : 100 ;
6286
6387 return new ColorHelper (
6488 new RgbaColor ($ red , $ green , $ blue , $ alpha )
@@ -67,7 +91,7 @@ public function hex(string $hex): ?ColorHelper
6791 $ red = hexdec ($ matches ['red ' ]);
6892 $ green = hexdec ($ matches ['green ' ]);
6993 $ blue = hexdec ($ matches ['blue ' ]);
70- $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ]) : 255 ;
94+ $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ]) / 2.55 : 100 ;
7195
7296 return new ColorHelper (
7397 new RgbaColor ($ red , $ green , $ blue , $ alpha )
@@ -91,7 +115,7 @@ public function css(string $colorString): ?ColorHelper
91115 $ red = hexdec ($ matches ['red ' ].$ matches ['red ' ]);
92116 $ green = hexdec ($ matches ['green ' ].$ matches ['green ' ]);
93117 $ blue = hexdec ($ matches ['blue ' ].$ matches ['blue ' ]);
94- $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ].$ matches ['alpha ' ]) : 255 ;
118+ $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ].$ matches ['alpha ' ]) / 2.55 : 100 ;
95119
96120 return new ColorHelper (
97121 new RgbaColor ($ red , $ green , $ blue , $ alpha )
@@ -100,7 +124,7 @@ public function css(string $colorString): ?ColorHelper
100124 $ red = hexdec ($ matches ['red ' ]);
101125 $ green = hexdec ($ matches ['green ' ]);
102126 $ blue = hexdec ($ matches ['blue ' ]);
103- $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ]) : 255 ;
127+ $ alpha = isset ($ matches ['alpha ' ]) ? hexdec ($ matches ['alpha ' ]) / 2.55 : 100 ;
104128
105129 return new ColorHelper (
106130 new RgbaColor ($ red , $ green , $ blue , $ alpha )
@@ -109,7 +133,7 @@ public function css(string $colorString): ?ColorHelper
109133 $ red = $ this ->parseNumber ($ matches ['red ' ], 255 );
110134 $ green = $ this ->parseNumber ($ matches ['red ' ], 255 );
111135 $ blue = $ this ->parseNumber ($ matches ['red ' ], 255 );
112- $ alpha = isset ($ matches ['alpha ' ]) ? $ this ->parseNumber ($ matches ['alpha ' ], 255 ) : 255 ;
136+ $ alpha = isset ($ matches ['alpha ' ]) ? $ this ->parseNumber ($ matches ['alpha ' ], 1 ) * 100 : 100 ;
113137
114138 return new ColorHelper (
115139 new RgbaColor ($ red , $ green , $ blue , $ alpha )
@@ -118,7 +142,7 @@ public function css(string $colorString): ?ColorHelper
118142 $ hue = $ this ->parseNumber ($ matches ['hue ' ], 360 );
119143 $ saturation = $ this ->parseNumber ($ matches ['saturation ' ], 100 );
120144 $ lightness = $ this ->parseNumber ($ matches ['lightness ' ], 100 );
121- $ alpha = isset ($ matches ['alpha ' ]) ? $ this ->parseNumber ($ matches ['alpha ' ], 1 ) : 1 ;
145+ $ alpha = isset ($ matches ['alpha ' ]) ? $ this ->parseNumber ($ matches ['alpha ' ], 1 ) * 100 : 100 ;
122146
123147 return new ColorHelper (
124148 new HslaColor ($ hue , $ saturation , $ lightness , $ alpha )
@@ -142,6 +166,10 @@ protected function parseNumber(string $value, int $max = 255, bool $circle = fal
142166 );
143167
144168 return $ max * ($ number / 100 );
169+ } elseif (substr ($ value , 0 , 2 ) == '0. ' ) {
170+ $ number = (float ) $ value ;
171+
172+ return $ max * $ number ;
145173 } else {
146174 $ value = (float ) $ value ;
147175 if ($ circle ) {
0 commit comments