123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- declare(strict_types=1);
- /**
- * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- namespace OCA\Theming\Themes;
- use OCA\Theming\ImageManager;
- use OCA\Theming\ITheme;
- use OCA\Theming\Service\BackgroundService;
- use OCA\Theming\ThemingDefaults;
- use OCA\Theming\Util;
- use OCP\App\IAppManager;
- use OCP\IConfig;
- use OCP\IL10N;
- use OCP\IURLGenerator;
- use OCP\IUserSession;
- class DefaultTheme implements ITheme {
- use CommonThemeTrait;
- public Util $util;
- public ThemingDefaults $themingDefaults;
- public IUserSession $userSession;
- public IURLGenerator $urlGenerator;
- public ImageManager $imageManager;
- public IConfig $config;
- public IL10N $l;
- public IAppManager $appManager;
- public string $defaultPrimaryColor;
- public string $primaryColor;
- public function __construct(Util $util,
- ThemingDefaults $themingDefaults,
- IUserSession $userSession,
- IURLGenerator $urlGenerator,
- ImageManager $imageManager,
- IConfig $config,
- IL10N $l,
- IAppManager $appManager) {
- $this->util = $util;
- $this->themingDefaults = $themingDefaults;
- $this->userSession = $userSession;
- $this->urlGenerator = $urlGenerator;
- $this->imageManager = $imageManager;
- $this->config = $config;
- $this->l = $l;
- $this->appManager = $appManager;
- $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
- $this->primaryColor = $this->themingDefaults->getColorPrimary();
- // Override primary colors (if set) to improve accessibility
- if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) {
- $this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
- }
- }
- public function getId(): string {
- return 'default';
- }
- public function getType(): int {
- return ITheme::TYPE_THEME;
- }
- public function getTitle(): string {
- return $this->l->t('System default theme');
- }
- public function getEnableLabel(): string {
- return $this->l->t('Enable the system default');
- }
- public function getDescription(): string {
- return $this->l->t('Using the default system appearance.');
- }
- public function getMediaQuery(): string {
- return '';
- }
- public function getCSSVariables(): array {
- $colorMainText = '#222222';
- $colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
- $colorTextMaxcontrast = $this->util->lighten($colorMainText, 33);
- $colorMainBackground = '#ffffff';
- $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
- $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
- $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
- $colorError = '#d91812';
- $colorWarning = '#c28900';
- $colorSuccess = '#2d7b41';
- $colorInfo = '#0071ad';
- $variables = [
- '--color-main-background' => $colorMainBackground,
- '--color-main-background-rgb' => $colorMainBackgroundRGB,
- '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
- '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
- '--filter-background-blur' => 'blur(25px)',
- // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
- '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
- // used for different active/hover/focus/disabled states
- '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
- '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
- '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
- '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
- '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
- // max contrast for WCAG compliance
- '--color-main-text' => $colorMainText,
- '--color-text-maxcontrast' => $colorTextMaxcontrast,
- '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
- '--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
- '--color-text-light' => $colorMainText,
- '--color-text-lighter' => $this->util->lighten($colorMainText, 33),
- '--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
- // error/warning/success/info feedback colours
- '--color-error' => $colorError,
- '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
- '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 75),
- '--color-error-text' => $this->util->darken($colorError, 4),
- '--color-warning' => $colorWarning,
- '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
- '--color-warning-hover' => $this->util->mix($colorWarning, $colorMainBackground, 60),
- '--color-warning-text' => $this->util->darken($colorWarning, 8),
- '--color-success' => $colorSuccess,
- '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
- '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 78),
- '--color-success-text' => $this->util->darken($colorSuccess, 4),
- '--color-info' => $colorInfo,
- '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
- '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 80),
- '--color-info-text' => $this->util->darken($colorInfo, 4),
- // used for the icon loading animation
- '--color-loading-light' => '#cccccc',
- '--color-loading-dark' => '#444444',
- '--color-box-shadow-rgb' => $colorBoxShadowRGB,
- '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
- '--color-border' => $this->util->darken($colorMainBackground, 7),
- '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
- '--color-border-maxcontrast' => $this->util->darken($colorMainBackground, 42),
- '--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'",
- '--default-font-size' => '15px',
- // TODO: support "(prefers-reduced-motion)"
- '--animation-quick' => '100ms',
- '--animation-slow' => '300ms',
- // Default variables --------------------------------------------
- '--border-radius' => '3px',
- '--border-radius-large' => '10px',
- '--border-radius-rounded' => '28px',
- // pill-style button, value is large so big buttons also have correct roundness
- '--border-radius-pill' => '100px',
- '--default-clickable-area' => '44px',
- '--default-line-height' => '24px',
- '--default-grid-baseline' => '4px',
- // various structure data
- '--header-height' => '50px',
- '--navigation-width' => '300px',
- '--sidebar-min-width' => '300px',
- '--sidebar-max-width' => '500px',
- '--list-min-width' => '200px',
- '--list-max-width' => '300px',
- '--header-menu-item-height' => '44px',
- '--header-menu-profile-item-height' => '66px',
- // mobile. Keep in sync with core/js/js.js
- '--breakpoint-mobile' => '1024px',
- '--background-invert-if-dark' => 'no',
- '--background-invert-if-bright' => 'invert(100%)',
- '--background-image-invert-if-bright' => 'no',
- ];
- // Primary variables
- $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
- $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
- $variables = array_merge($variables, $this->generateUserBackgroundVariables());
- return $variables;
- }
- public function getCustomCss(): string {
- return '';
- }
- }
|