DefaultTheme.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Theming\Themes;
  26. use OCA\Theming\ImageManager;
  27. use OCA\Theming\ITheme;
  28. use OCA\Theming\Service\BackgroundService;
  29. use OCA\Theming\ThemingDefaults;
  30. use OCA\Theming\Util;
  31. use OCP\App\IAppManager;
  32. use OCP\IConfig;
  33. use OCP\IL10N;
  34. use OCP\IURLGenerator;
  35. use OCP\IUserSession;
  36. class DefaultTheme implements ITheme {
  37. use CommonThemeTrait;
  38. public Util $util;
  39. public ThemingDefaults $themingDefaults;
  40. public IUserSession $userSession;
  41. public IURLGenerator $urlGenerator;
  42. public ImageManager $imageManager;
  43. public IConfig $config;
  44. public IL10N $l;
  45. public IAppManager $appManager;
  46. public string $defaultPrimaryColor;
  47. public string $primaryColor;
  48. public function __construct(Util $util,
  49. ThemingDefaults $themingDefaults,
  50. IUserSession $userSession,
  51. IURLGenerator $urlGenerator,
  52. ImageManager $imageManager,
  53. IConfig $config,
  54. IL10N $l,
  55. IAppManager $appManager) {
  56. $this->util = $util;
  57. $this->themingDefaults = $themingDefaults;
  58. $this->userSession = $userSession;
  59. $this->urlGenerator = $urlGenerator;
  60. $this->imageManager = $imageManager;
  61. $this->config = $config;
  62. $this->l = $l;
  63. $this->appManager = $appManager;
  64. $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
  65. $this->primaryColor = $this->themingDefaults->getColorPrimary();
  66. // Override default defaultPrimaryColor if set to improve accessibility
  67. if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) {
  68. $this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
  69. }
  70. }
  71. public function getId(): string {
  72. return 'default';
  73. }
  74. public function getType(): int {
  75. return ITheme::TYPE_THEME;
  76. }
  77. public function getTitle(): string {
  78. return $this->l->t('System default theme');
  79. }
  80. public function getEnableLabel(): string {
  81. return $this->l->t('Enable the system default');
  82. }
  83. public function getDescription(): string {
  84. return $this->l->t('Using the default system appearance.');
  85. }
  86. public function getMediaQuery(): string {
  87. return '';
  88. }
  89. public function getCSSVariables(): array {
  90. $colorMainText = '#222222';
  91. $colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
  92. $colorTextMaxcontrast = $this->util->lighten($colorMainText, 33);
  93. $colorMainBackground = '#ffffff';
  94. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  95. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  96. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  97. $variables = [
  98. '--color-main-background' => $colorMainBackground,
  99. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  100. '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
  101. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
  102. '--filter-background-blur' => 'blur(25px)',
  103. // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
  104. '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
  105. // used for different active/hover/focus/disabled states
  106. '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
  107. '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
  108. '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
  109. '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
  110. '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
  111. // max contrast for WCAG compliance
  112. '--color-main-text' => $colorMainText,
  113. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  114. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  115. '--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
  116. '--color-text-light' => $colorMainText,
  117. '--color-text-lighter' => $this->util->lighten($colorMainText, 33),
  118. '--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
  119. // info/warning/success feedback colours
  120. '--color-error' => '#e9322d',
  121. '--color-error-rgb' => join(',', $this->util->hexToRGB('#e9322d')),
  122. '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60),
  123. '--color-warning' => '#eca700',
  124. '--color-warning-rgb' => join(',', $this->util->hexToRGB('#eca700')),
  125. '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60),
  126. '--color-success' => '#46ba61',
  127. '--color-success-rgb' => join(',', $this->util->hexToRGB('#46ba61')),
  128. '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60),
  129. '--color-info' => '#006aa3',
  130. '--color-info-rgb' => join(',', $this->util->hexToRGB('#006aa3')),
  131. '--color-info-hover' => $this->util->mix('#006aa3', $colorMainBackground, 60),
  132. // used for the icon loading animation
  133. '--color-loading-light' => '#cccccc',
  134. '--color-loading-dark' => '#444444',
  135. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  136. '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
  137. '--color-border' => $this->util->darken($colorMainBackground, 7),
  138. '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
  139. '--color-border-maxcontrast' => $this->util->darken($colorMainBackground, 42),
  140. '--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
  141. '--default-font-size' => '15px',
  142. // TODO: support "(prefers-reduced-motion)"
  143. '--animation-quick' => '100ms',
  144. '--animation-slow' => '300ms',
  145. // Default variables --------------------------------------------
  146. '--border-radius' => '3px',
  147. '--border-radius-large' => '10px',
  148. '--border-radius-rounded' => '28px',
  149. // pill-style button, value is large so big buttons also have correct roundness
  150. '--border-radius-pill' => '100px',
  151. '--default-clickable-area' => '44px',
  152. '--default-line-height' => '24px',
  153. '--default-grid-baseline' => '4px',
  154. // various structure data
  155. '--header-height' => '50px',
  156. '--navigation-width' => '300px',
  157. '--sidebar-min-width' => '300px',
  158. '--sidebar-max-width' => '500px',
  159. '--list-min-width' => '200px',
  160. '--list-max-width' => '300px',
  161. '--header-menu-item-height' => '44px',
  162. '--header-menu-profile-item-height' => '66px',
  163. // mobile. Keep in sync with core/js/js.js
  164. '--breakpoint-mobile' => '1024px',
  165. '--background-invert-if-dark' => 'no',
  166. '--background-invert-if-bright' => 'invert(100%)',
  167. '--background-image-invert-if-bright' => 'no',
  168. ];
  169. // Primary variables
  170. $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
  171. $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
  172. $variables = array_merge($variables, $this->generateUserBackgroundVariables());
  173. return $variables;
  174. }
  175. public function getCustomCss(): string {
  176. return '';
  177. }
  178. }