Passed
Push — master ( f72f81...350d02 )
by John
16:13 queued 12s
created

DefaultTheme::getEnableLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2022 Joas Schilling <[email protected]>
5
 *
6
 * @author Joas Schilling <[email protected]>
7
 * @author John Molakvoæ <[email protected]>
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
27
use OCA\Theming\ImageManager;
28
use OCA\Theming\ThemingDefaults;
29
use OCA\Theming\Util;
30
use OCA\Theming\ITheme;
31
use OCP\IConfig;
32
use OCP\IL10N;
33
use OCP\IURLGenerator;
34
35
class DefaultTheme implements ITheme {
36
	public Util $util;
37
	public ThemingDefaults $themingDefaults;
38
	public IURLGenerator $urlGenerator;
39
	public ImageManager $imageManager;
40
	public IConfig $config;
41
	public IL10N $l;
42
43
	public string $primaryColor;
44
45
	public function __construct(Util $util,
46
								ThemingDefaults $themingDefaults,
47
								IURLGenerator $urlGenerator,
48
								ImageManager $imageManager,
49
								IConfig $config,
50
								IL10N $l) {
51
		$this->util = $util;
52
		$this->themingDefaults = $themingDefaults;
53
		$this->urlGenerator = $urlGenerator;
54
		$this->imageManager = $imageManager;
55
		$this->config = $config;
56
		$this->l = $l;
57
58
		$this->primaryColor = $this->themingDefaults->getColorPrimary();
59
	}
60
61
	public function getId(): string {
62
		return 'default';
63
	}
64
65
	public function getType(): int {
66
		return ITheme::TYPE_THEME;
67
	}
68
69
	public function getTitle(): string {
70
		return $this->l->t('System default theme');
71
	}
72
73
	public function getEnableLabel(): string {
74
		return $this->l->t('Enable the system default');
75
	}
76
77
	public function getDescription(): string {
78
		return $this->l->t('Using the default system appearance.');
79
	}
80
81
	public function getMediaQuery(): string {
82
		return '';
83
	}
84
85
	public function getCSSVariables(): array {
86
		$colorMainText = '#222222';
87
		$colorMainBackground = '#ffffff';
88
		$colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
89
		$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
90
		$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
91
92
		$hasCustomLogoHeader = $this->imageManager->hasImage('logo') ||  $this->imageManager->hasImage('logoheader');
93
94
		$variables = [
95
			'--color-main-background' => $colorMainBackground,
96
			'--color-main-background-rgb' => $colorMainBackgroundRGB,
97
			'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
98
99
			// to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
100
			'--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
101
102
			// used for different active/hover/focus/disabled states
103
			'--color-background-hover' => $this->util->darken($colorMainBackground, 4),
104
			'--color-background-dark' => $this->util->darken($colorMainBackground, 7),
105
			'--color-background-darker' => $this->util->darken($colorMainBackground, 14),
106
107
			'--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
108
			'--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
109
110
			// primary related colours
111
			'--color-primary' => $this->primaryColor,
112
			'--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
113
			'--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60),
114
			'--color-primary-light' => $this->util->mix($this->primaryColor, $colorMainBackground, -80),
115
			'--color-primary-light-text' => $this->primaryColor,
116
			'--color-primary-light-hover' => $this->util->mix($this->primaryColor, $colorMainText, -80),
117
			'--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7),
118
			// used for buttons, inputs...
119
			'--color-primary-element' => $this->util->elementColor($this->primaryColor),
120
			'--color-primary-element-hover' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 80),
121
			'--color-primary-element-light' => $this->util->lighten($this->util->elementColor($this->primaryColor), 15),
122
			'--color-primary-element-lighter' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, -70),
123
124
			// max contrast for WCAG compliance
125
			'--color-main-text' => $colorMainText,
126
			'--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33),
127
			'--color-text-light' => $colorMainText,
128
			'--color-text-lighter' => $this->util->lighten($colorMainText, 33),
129
130
			// info/warning/success feedback colours
131
			'--color-error' => '#e9322d',
132
			'--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60),
133
			'--color-warning' => '#eca700',
134
			'--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60),
135
			'--color-success' => '#46ba61',
136
			'--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60),
137
138
			// used for the icon loading animation
139
			'--color-loading-light' => '#cccccc',
140
			'--color-loading-dark' => '#444444',
141
142
			'--color-box-shadow-rgb' => $colorBoxShadowRGB,
143
			'--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
144
145
			'--color-border' => $this->util->darken($colorMainBackground, 7),
146
			'--color-border-dark' => $this->util->darken($colorMainBackground, 14),
147
148
			'--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'",
149
			'--default-font-size' => '15px',
150
151
			// TODO: support "(prefers-reduced-motion)"
152
			'--animation-quick' => '100ms',
153
			'--animation-slow' => '300ms',
154
155
			// Default variables --------------------------------------------
156
			'--border-radius' => '3px',
157
			'--border-radius-large' => '10px',
158
			// pill-style button, value is large so big buttons also have correct roundness
159
			'--border-radius-pill' => '100px',
160
161
			'--default-line-height' => '24px',
162
163
			// various structure data
164
			'--header-height' => '50px',
165
			'--navigation-width' => '300px',
166
			'--sidebar-min-width' => '300px',
167
			'--sidebar-max-width' => '500px',
168
			'--list-min-width' => '200px',
169
			'--list-max-width' => '300px',
170
			'--header-menu-item-height' => '44px',
171
			'--header-menu-profile-item-height' => '66px',
172
173
			// mobile. Keep in sync with core/js/js.js
174
			'--breakpoint-mobile' => '1024px',
175
176
			// invert filter if primary is too bright
177
			// to be used for legacy reasons only. Use inline
178
			// svg with proper css variable instead or material
179
			// design icons.
180
			// ⚠️ Using 'no' as a value to make sure we specify an
181
			// invalid one with no fallback. 'unset' could here fallback to some
182
			// other theme with media queries
183
			'--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no',
184
			'--background-invert-if-dark' => 'no',
185
		];
186
187
		// Register image variables only if custom-defined
188
		$backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor';
189
		foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) {
190
			if ($this->imageManager->hasImage($image)) {
191
				// If primary as background has been request, let's not define the background image
192
				if ($image === 'background' && $backgroundDeleted) {
193
					$variables["--image-background-plain"] = 'true';
194
					continue;
195
				} else if ($image === 'background') {
196
					$variables['--image-background-size'] = 'cover';
197
				}
198
				$variables["--image-$image"] = "url('".$this->imageManager->getImageUrl($image)."')";
199
			}
200
		}
201
202
		if ($hasCustomLogoHeader) {
203
			$variables["--image-logoheader-custom"] = 'true';
204
		}
205
206
		return $variables;
207
	}
208
209
	public function getCustomCss(): string {
210
		return '';
211
	}
212
}
213