296 if ($hexColor[0] !==
'#')
298 $hexColor =
'#'.$hexColor;
300 if (strlen($hexColor) === 4)
303 $hexColor[0] . $hexColor[1] . $hexColor[1] . $hexColor[2] . $hexColor[2] . $hexColor[3] . $hexColor[3];
305 if (strlen($hexColor) !== 7)
311 hexdec(substr($hexColor, 1, 2)),
312 hexdec(substr($hexColor, 3, 2)),
313 hexdec(substr($hexColor, 5, 2)),
328 $max = max($red, $green, $blue);
329 $min = min($red, $green, $blue);
330 $lightness = ($max + $min) / 2;
334 $hue = $saturation = 0;
339 $saturation = $d / (1 - abs(2 * $lightness - 1));
343 $hue = 60 * fmod((($green - $blue) / $d), 6);
351 $hue = 60 * (($blue - $red) / $d + 2);
355 $hue = 60 * (($red - $green) / $d + 4);
365 round($saturation, 2) * 100,
366 round($lightness, 2) * 100,
380 if ($request->get(
'color'))
382 $colorHex = $request->get(
'color');
385 ($themeCodeFromRequest = $request->get(
'theme'))
386 && array_key_exists($themeCodeFromRequest, $defaultColors)
389 $themeCode = $themeCodeFromRequest;
390 $colorHex = $defaultColors[$themeCodeFromRequest][
'color'];
394 $colorHex = HtmlFilter::encode(trim($this->fields[
'COLOR']->getValue()));
397 $themeCode = HtmlFilter::encode(trim($this->fields[
'CODE']->getValue()));
402 if (!is_string($colorHex))
408 $restrictionCode = Restriction\Hook::getRestrictionCodeByHookCode(
'THEME');
410 !Restriction\Manager::isAllowed($restrictionCode)
411 && !self::getThemeCodeByColor($colorHex)
419 $rgbTemplate = $rgbColor[0] .
', ' . $rgbColor[1] .
', ' . $rgbColor[2];
424 || ($themeCode = self::getThemeCodeByColor($colorHex))
427 $colorMain = $defaultColors[$themeCode][
'main'] ??
null;
428 if ($defaultColors[$themeCode][
'secondary'] ??
null)
430 $colorSecondary = $defaultColors[$themeCode][
'secondary'];
432 if ($defaultColors[$themeCode][
'colorTitle'] ??
null)
434 $colorTitle = $defaultColors[$themeCode][
'colorTitle'];
437 $colorMain = $colorMain ??
'hsl('.$hslColor[0].
', 20%, 20%)';
438 $colorSecondary = $colorSecondary ??
'hsl('.$hslColor[0].
', 20%, 80%)';
439 $colorTitle = $colorTitle ?? $colorMain;
441 if ($hslColor[2] > 60)
443 $colorStrictInverseFromPrimary =
'#000000';
447 $colorStrictInverseFromPrimary =
'#ffffff';
450 Asset::getInstance()->addString(
451 '<style type="text/css">
453 --primary: ' . $colorHex .
' !important' .
';
454 --primary-darken-1: hsl(' . $hslColor[0] .
', ' . $hslColor[1] .
'%, ' . min($hslColor[2] - 2, 100) .
'%)' .
';
455 --primary-darken-2: hsl(' . $hslColor[0] .
', ' . $hslColor[1] .
'%, ' . min($hslColor[2] - 5, 100) .
'%)' .
';
456 --primary-darken-3: hsl(' . $hslColor[0] .
', ' . $hslColor[1] .
'%, ' . min($hslColor[2] - 10, 100) .
'%)' .
';
457 --primary-lighten-1: hsl(' . $hslColor[0] .
', ' . $hslColor[1] .
'%, ' . max($hslColor[2] + 10, 0) .
'%)' .
';
458 --primary-opacity-0: rgba('.$rgbTemplate.
', 0);
459 --primary-opacity-0_05: rgba('.$rgbTemplate.
', 0.05);
460 --primary-opacity-0_1: rgba('.$rgbTemplate.
', 0.1);
461 --primary-opacity-0_15: rgba('.$rgbTemplate.
', 0.15);
462 --primary-opacity-0_2: rgba('.$rgbTemplate.
', 0.2);
463 --primary-opacity-0_25: rgba('.$rgbTemplate.
', 0.25);
464 --primary-opacity-0_3: rgba('.$rgbTemplate.
', 0.3);
465 --primary-opacity-0_35: rgba('.$rgbTemplate.
', 0.35);
466 --primary-opacity-0_4: rgba('.$rgbTemplate.
', 0.4);
467 --primary-opacity-0_45: rgba('.$rgbTemplate.
', 0.45);
468 --primary-opacity-0_5: rgba('.$rgbTemplate.
', 0.5);
469 --primary-opacity-0_55: rgba('.$rgbTemplate.
', 0.55);
470 --primary-opacity-0_6: rgba('.$rgbTemplate.
', 0.6);
471 --primary-opacity-0_65: rgba('.$rgbTemplate.
', 0.65);
472 --primary-opacity-0_7: rgba('.$rgbTemplate.
', 0.7);
473 --primary-opacity-0_75: rgba('.$rgbTemplate.
', 0.75);
474 --primary-opacity-0_8: rgba('.$rgbTemplate.
', 0.8);
475 --primary-opacity-0_85: rgba('.$rgbTemplate.
', 0.85);
476 --primary-opacity-0_9: rgba('.$rgbTemplate.
', 0.9);
477 --primary-opacity-0_95: rgba('.$rgbTemplate.
', 0.95);
478 --theme-color-main: ' . $colorMain .
';
479 --theme-color-secondary: ' . $colorSecondary .
';
480 --theme-color-title: ' . $colorTitle .
';
481 --theme-color-strict-inverse: ' . $colorStrictInverseFromPrimary .
';
485 AssetLocation::BEFORE_CSS