diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-12-03 11:55:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 11:55:42 +0100 |
commit | b067ae78c5a8044e8066fe742d61c712387e7aa5 (patch) | |
tree | 4ce0140c5160f03c9ddc09bf8befe69b1c872fde /apps | |
parent | 510031067abf8c9f62a518f7f7ad8eb644de1721 (diff) | |
parent | dfb569f097119ac8b5722607a86cc77e97bff3af (diff) | |
download | nextcloud-server-b067ae78c5a8044e8066fe742d61c712387e7aa5.tar.gz nextcloud-server-b067ae78c5a8044e8066fe742d61c712387e7aa5.zip |
Merge pull request #30034 from nextcloud/fix/bump-scssphp/scssphp-to-1.8.1
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Util.php | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 70b5a00f9ea..208cd42934e 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -34,7 +34,6 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; -use ScssPhp\ScssPhp\Compiler; class Util { @@ -97,14 +96,51 @@ class Util { } /** + * Convert RGB to HSL + * + * Copied from cssphp, copyright Leaf Corcoran, licensed under MIT + * + * @param integer $red + * @param integer $green + * @param integer $blue + * + * @return array + */ + public function toHSL($red, $green, $blue) { + $min = min($red, $green, $blue); + $max = max($red, $green, $blue); + $l = $min + $max; + $d = $max - $min; + + if ((int) $d === 0) { + $h = $s = 0; + } else { + if ($l < 255) { + $s = $d / $l; + } else { + $s = $d / (510 - $l); + } + + if ($red == $max) { + $h = 60 * ($green - $blue) / $d; + } elseif ($green == $max) { + $h = 60 * ($blue - $red) / $d + 120; + } else { + $h = 60 * ($red - $green) / $d + 240; + } + } + + return [fmod($h, 360), $s * 100, $l / 5.1]; + } + + /** * @param string $color rgb color value * @return float */ public function calculateLuminance($color) { [$red, $green, $blue] = $this->hexToRGB($color); - $compiler = new Compiler(); - $hsl = $compiler->toHSL($red, $green, $blue); - return $hsl[3] / 100; + $hsl = $this->toHSL($red, $green, $blue); + return $hsl[2] / 100; } /** |