DefaultTheme.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 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. $colorError = '#d91812';
  98. $colorWarning = '#c28900';
  99. $colorSuccess = '#2d7b41';
  100. $colorInfo = '#0071ad';
  101. $variables = [
  102. '--color-main-background' => $colorMainBackground,
  103. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  104. '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
  105. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
  106. '--filter-background-blur' => 'blur(25px)',
  107. // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
  108. '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
  109. // used for different active/hover/focus/disabled states
  110. '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
  111. '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
  112. '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
  113. '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
  114. '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
  115. // max contrast for WCAG compliance
  116. '--color-main-text' => $colorMainText,
  117. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  118. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  119. '--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
  120. '--color-text-light' => $colorMainText,
  121. '--color-text-lighter' => $this->util->lighten($colorMainText, 33),
  122. '--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
  123. // error/warning/success/info feedback colours
  124. '--color-error' => $colorError,
  125. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  126. '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 75),
  127. '--color-error-text' => $this->util->darken($colorError, 4),
  128. '--color-warning' => $colorWarning,
  129. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  130. '--color-warning-hover' => $this->util->mix($colorWarning, $colorMainBackground, 60),
  131. '--color-warning-text' => $this->util->darken($colorWarning, 8),
  132. '--color-success' => $colorSuccess,
  133. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  134. '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 78),
  135. '--color-success-text' => $this->util->darken($colorSuccess, 4),
  136. '--color-info' => $colorInfo,
  137. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  138. '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 80),
  139. '--color-info-text' => $this->util->darken($colorInfo, 4),
  140. // used for the icon loading animation
  141. '--color-loading-light' => '#cccccc',
  142. '--color-loading-dark' => '#444444',
  143. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  144. '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
  145. '--color-border' => $this->util->darken($colorMainBackground, 7),
  146. '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
  147. '--color-border-maxcontrast' => $this->util->darken($colorMainBackground, 42),
  148. '--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'",
  149. '--default-font-size' => '15px',
  150. // TODO: support "(prefers-reduced-motion)"
  151. '--animation-quick' => '100ms',
  152. '--animation-slow' => '300ms',
  153. // Default variables --------------------------------------------
  154. '--border-radius' => '3px',
  155. '--border-radius-large' => '10px',
  156. '--border-radius-rounded' => '28px',
  157. // pill-style button, value is large so big buttons also have correct roundness
  158. '--border-radius-pill' => '100px',
  159. '--default-clickable-area' => '44px',
  160. '--default-line-height' => '24px',
  161. '--default-grid-baseline' => '4px',
  162. // various structure data
  163. '--header-height' => '50px',
  164. '--navigation-width' => '300px',
  165. '--sidebar-min-width' => '300px',
  166. '--sidebar-max-width' => '500px',
  167. '--list-min-width' => '200px',
  168. '--list-max-width' => '300px',
  169. '--header-menu-item-height' => '44px',
  170. '--header-menu-profile-item-height' => '66px',
  171. // mobile. Keep in sync with core/js/js.js
  172. '--breakpoint-mobile' => '1024px',
  173. '--background-invert-if-dark' => 'no',
  174. '--background-invert-if-bright' => 'invert(100%)',
  175. '--background-image-invert-if-bright' => 'no',
  176. ];
  177. // Primary variables
  178. $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
  179. $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
  180. $variables = array_merge($variables, $this->generateUserBackgroundVariables());
  181. return $variables;
  182. }
  183. public function getCustomCss(): string {
  184. return '';
  185. }
  186. }