- md5
- 16d07641d096f016d100fb403bd3820a
- sha1
- 2367af8af6105c6048202f6d292ad488adf8cb6a
- sha256
- a6fbc5379ee84e88c6bfe12a35ccc4e52b2f2c5a1f84dbf634f98cf9cc4fd560
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
<?php
namespace OzdemirBurak\Iris\Traits;
use OzdemirBurak\Iris\Helpers\DefinedColor;
trait HsTrait
{
/**
* @var int
*/
protected $hue;
/**
* @var int
*/
protected $saturation;
/**
* @param string $code
*
* @return string|bool
*/
protected function validate($code)
{
list($class, $index) = property_exists($this, 'lightness') ? ['hsl', 2] : ['hsv', 3];
$color = str_replace([$class, '(', ')', ' ', '%'], '', DefinedColor::find($code, $index));
if (preg_match('/^(\d{1,3}),(\d{1,3}),(\d{1,3})$/', $color, $matches)) {
if ($matches[1] > 360 || $matches[2] > 100 || $matches[3] > 100) {
return false;
}
return $color;
}
return false;
}
/**
* @param int|string $hue
*
* @return int|$this
*/
public function hue($hue = null)
{
if (is_numeric($hue)) {
$this->hue = $hue >= 0 && $hue <= 360 ? $hue : $this->hue;
return $this;
}
return (int) $this->hue;
}
/**
* @param int|string $saturation
*
* @return int|$this
*/
public function saturation($saturation = null)
{
if (is_numeric($saturation)) {
$this->saturation = $saturation >= 0 && $saturation <= 100 ? $saturation : $this->saturation;
return $this;
}
return (int) $this->saturation;
}
/**
* @return array
*/
public function getValues()
{
return [
$this->hue(),
$this->saturation() . '%',
(property_exists($this, 'lightness') ? $this->lightness() : $this->value()) . '%'
];
}
/**
* Values in [0, 1] range
*
* @return array
*/
public function valuesInUnitInterval()
{
return [
$this->hue() / 360,
$this->saturation() / 100,
(property_exists($this, 'lightness') ? $this->lightness() : $this->value()) / 100
];
}
}
The same content is in 9 releases, Joomla 4.0.0-alpha11 to 4.0.0-beta7. See them all, or every version of this file.