DefaultTheme.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 primary colors (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 getMeta(): array {
  90. return [];
  91. }
  92. public function getCSSVariables(): array {
  93. $colorMainText = '#222222';
  94. $colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
  95. // Color that still provides enough contrast for text, so we need a ratio of 4.5:1 on main background AND hover
  96. $colorTextMaxcontrast = '#6b6b6b'; // 4.5 : 1 for hover background and background dark
  97. $colorMainBackground = '#ffffff';
  98. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  99. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  100. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  101. $colorError = '#DB0606';
  102. $colorWarning = '#A37200';
  103. $colorSuccess = '#2d7b41';
  104. $colorInfo = '#0071ad';
  105. $variables = [
  106. '--color-main-background' => $colorMainBackground,
  107. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  108. '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
  109. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
  110. '--filter-background-blur' => 'blur(25px)',
  111. // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
  112. '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
  113. // used for different active/hover/focus/disabled states
  114. '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
  115. '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
  116. '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
  117. '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
  118. '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
  119. // max contrast for WCAG compliance
  120. '--color-main-text' => $colorMainText,
  121. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  122. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  123. '--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
  124. '--color-text-light' => 'var(--color-main-text)', // deprecated
  125. '--color-text-lighter' => 'var(--color-text-maxcontrast)', // deprecated
  126. '--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
  127. // error/warning/success/info feedback colours
  128. '--color-error' => $colorError,
  129. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  130. '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 75),
  131. '--color-error-text' => $this->util->darken($colorError, 5),
  132. '--color-warning' => $colorWarning,
  133. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  134. '--color-warning-hover' => $this->util->darken($colorWarning, 5),
  135. '--color-warning-text' => $this->util->darken($colorWarning, 7),
  136. '--color-success' => $colorSuccess,
  137. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  138. '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 80),
  139. '--color-success-text' => $this->util->darken($colorSuccess, 4),
  140. '--color-info' => $colorInfo,
  141. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  142. '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 80),
  143. '--color-info-text' => $this->util->darken($colorInfo, 4),
  144. '--color-favorite' => '#A37200',
  145. // used for the icon loading animation
  146. '--color-loading-light' => '#cccccc',
  147. '--color-loading-dark' => '#444444',
  148. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  149. '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
  150. '--color-border' => $this->util->darken($colorMainBackground, 7),
  151. '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
  152. '--color-border-maxcontrast' => $this->util->darken($colorMainBackground, 51),
  153. '--font-face' => "system-ui, -apple-system, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'",
  154. '--default-font-size' => '15px',
  155. // TODO: support "(prefers-reduced-motion)"
  156. '--animation-quick' => '100ms',
  157. '--animation-slow' => '300ms',
  158. // Default variables --------------------------------------------
  159. '--border-radius' => '3px',
  160. '--border-radius-large' => '10px',
  161. '--border-radius-rounded' => '28px',
  162. // pill-style button, value is large so big buttons also have correct roundness
  163. '--border-radius-pill' => '100px',
  164. '--default-clickable-area' => '44px',
  165. '--default-line-height' => '24px',
  166. '--default-grid-baseline' => '4px',
  167. // various structure data
  168. '--header-height' => '50px',
  169. '--navigation-width' => '300px',
  170. '--sidebar-min-width' => '300px',
  171. '--sidebar-max-width' => '500px',
  172. '--list-min-width' => '200px',
  173. '--list-max-width' => '300px',
  174. '--header-menu-item-height' => '44px',
  175. '--header-menu-profile-item-height' => '66px',
  176. // mobile. Keep in sync with core/js/js.js
  177. '--breakpoint-mobile' => '1024px',
  178. '--background-invert-if-dark' => 'no',
  179. '--background-invert-if-bright' => 'invert(100%)',
  180. '--background-image-invert-if-bright' => 'no',
  181. ];
  182. // Primary variables
  183. $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
  184. $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
  185. $variables = array_merge($variables, $this->generateUserBackgroundVariables());
  186. return $variables;
  187. }
  188. public function getCustomCss(): string {
  189. return '';
  190. }
  191. }