- md5
- c53b917adf95452ed7d555551186dab9
- sha1
- 76d593a1017756898c0b57daaa4c94ec0c7601a6
- sha256
- d18c47251eafb965ab361a9180e968f5adbaccb7e67caab9eae713bb7d22805c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
<?php
/**
* @package Joomla.Administrator
* @subpackage Templates.Atum
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use OzdemirBurak\Iris\Color\Hex;
use OzdemirBurak\Iris\Color\Hsl;
use OzdemirBurak\Iris\Color\Rgb;
use OzdemirBurak\Iris\Color\Hsla;
/**
* Template Atum HTML Helper
*
* @since 4.0.0
*/
class JHtmlAtum
{
/**
* Calculates the different template colors and set the CSS variables
*
* @param Registry $params Template parameters.
*
* @return void
*
* @since 4.0.0
*/
public static function rootcolors(Registry $params): void
{
$root = [];
if ($params->get('hue'))
{
$root = static::bgdarkcalc($params->get('hue'));
}
$bgLight = $params->get('bg-light');
if (static::isHex($bgLight))
{
try
{
$bgLight = new Hex($bgLight);
$root[] = '--atum-bg-light: ' . $bgLight . ';';
$root[] = '--toolbar-bg: ' . $bgLight->lighten(5) . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
$textDark = $params->get('text-dark');
if (static::isHex($textDark))
{
try
{
$textDark = new Hex($textDark);
$root[] = '--atum-text-dark: ' . $textDark . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
$textLight = $params->get('text-light');
if (static::isHex($textLight))
{
try
{
$textLight = new Hex($textLight);
$root[] = '--atum-text-light: ' . $textLight . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
$linkColor = $params->get('link-color');
if (static::isHex($linkColor))
{
try
{
$linkColor = new Hex($linkColor);
$root[] = '--atum-link-color: ' . $linkColor . ';';
$root[] = '--atum-link-hover-color: ' . $linkColor->darken(20) . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
$specialColor = $params->get('special-color');
if (static::isHex($specialColor))
{
try
{
$specialcolor = new Hex($specialColor);
$root[] = '--atum-special-color: ' . $specialcolor . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
if (count($root))
{
Factory::getDocument()->addStyleDeclaration(':root {' . implode($root) . '}');
}
}
/**
* Calculates the different template colors
*
* @param string $color Template parameter color.
* @param boolean $monochrome Template parameter monochrome.
*
* @return array An array of calculated color values and css variables
*
* @since 4.0.0
*/
protected static function bgdarkcalc($color): array
{
$hue = 207;
if (strpos($color, 'hsl(') !== false)
{
try
{
$hue = (new Hsl($color))->hue();
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
elseif (static::isHex($color))
{
try
{
$hue = (new Hex($color))->toHsl()->hue();
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
elseif (strpos($color, 'hsla(') !== false)
{
try
{
$hue = (new Hsla($color))->toHsl()->hue();
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
elseif (strpos($color, 'rgb(') !== false)
{
try
{
$hue = (new Rgb($color))->toHsl()->hue();
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
}
$hue = min(359, max(0, (int) $hue));
$root = [];
// No need to calculate if we have the default value
if ($hue === 207)
{
return $root;
}
try
{
$bgcolor = new Hsl('hsl(' . $hue . ', ' . 61 . ', 26)');
$root[] = '--atum-bg-dark: ' . (new Hsl('hsl(' . $hue . ', 61, 26)'))->toHex() . ';';
$root[] = '--atum-contrast: ' . (new Hsl('hsl(' . $hue . ', 61, 26)'))->spin(-40)->lighten(18)->toHex() . ';';
$root[] = '--atum-bg-dark-0: ' . (clone $bgcolor)->desaturate(86)->lighten(71.4)->spin(-6)->toHex() . ';';
$root[] = '--atum-bg-dark-5: ' . (clone $bgcolor)->desaturate(85)->lighten(65.1)->spin(-6)->toHex() . ';';
$root[] = '--atum-bg-dark-10: ' . (clone $bgcolor)->desaturate(80)->lighten(59.4)->spin(-6)->toHex() . ';';
$root[] = '--atum-bg-dark-20: ' . (clone $bgcolor)->desaturate(75)->lighten(47.3)->spin(-6)->toHex() . ';';
$root[] = '--atum-bg-dark-30: ' . (clone $bgcolor)->desaturate(55)->lighten(34.3)->spin(-5)->toHex() . ';';
$root[] = '--atum-bg-dark-40: ' . (clone $bgcolor)->desaturate(40)->lighten(21.4)->spin(-3)->toHex() . ';';
$root[] = '--atum-bg-dark-50: ' . (clone $bgcolor)->desaturate(15)->lighten(10)->spin(-1)->toHex() . ';';
$root[] = '--atum-bg-dark-70: ' . (clone $bgcolor)->lighten(-6)->spin(4)->toHex() . ';';
$root[] = '--atum-bg-dark-80: ' . (clone $bgcolor)->lighten(-11.5)->spin(7)->toHex() . ';';
$root[] = '--atum-bg-dark-90: ' . (clone $bgcolor)->desaturate(-1)->lighten(-17)->spin(10)->toHex() . ';';
}
catch (\Exception $ex)
{
// Just ignore exceptions
}
return $root;
}
/**
* Determinates if the given string is a color hex value
*
* @param string $hex The string to test
*
* @return boolean True when color hex value otherwise false
*
* @since 4.0.0
*/
protected static function isHex($hex): bool
{
if (substr($hex, 0, 1) !== '#')
{
return false;
}
$value = ltrim($hex, '#');
return (strlen($value) == 6 || strlen($value) == 3) && ctype_xdigit($value);
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha11 to 4.0.0-alpha12. See them all, or every version of this file.