_theme-color.scss
Unicode text, UTF-8 text
1
// When color definition differs for dark and light variant,
2
// it gets @if ed depending on $variant
3
4
@import 'color-palette';
5
6
@function gtkalpha($color, $alpha) {
7
@return unquote("alpha(#{$color}, #{$alpha})");
8
}
9
10
// Determine whether the color has alpha.
11
@function _has-alpha($color) {
12
@return if(alpha($color) < 1, true, false);
13
}
14
15
// Determine whether the color is dark.
16
@function _is-dark($color) {
17
// Calculate color brightness as per https://www.w3.org/TR/AERT/#color-contrast
18
$brightness: (red($color) * 299 + green($color) * 587 + blue($color) * 114) / 1000;
19
20
@return if($brightness < 128, true, false);
21
}
22
23
$on-light: #000;
24
$on-dark: #fff;
25
26
// Determine whether to use dark or light color on top of given color
27
// to meet accessibility standards for contrast.
28
@function on($color) {
29
$contrast-color: if(_is-dark($color), $on-dark, $on-light);
30
31
@if saturation($color) > 50% or alpha($color) < 1 {
32
@return $contrast-color;
33
} @else {
34
@return rgba($contrast-color, .87);
35
}
36
}
37
38
// Determine the strength of highlight on top of given color.
39
@function highlight($color) {
40
@if lightness($color) >= 80% {
41
@return rgba(white, .4);
42
} @else if lightness($color) >= 40% {
43
@return rgba(white, .2);
44
} @else {
45
@return rgba(white, .05);
46
}
47
}
48
49
// Make translucent color opaque by blending with the background color.
50
@function opacify($color, $on) {
51
@return mix(change-color($color, $alpha: 1), $on, alpha($color) * 100%);
52
}
53
54
//
55
// Main colors
56
//
57
58
$surface-z0: #f9f9f9;
59
$surface-z1: #fff;
60
$surface-z8: #fff;
61
$surface-switch-thumb: #fff;
62
$on-surface: on($surface-z0);
63
64
$primary-on-light: #1967d2;
65
$primary-on-dark: #8ab4f8;
66
$primary: $primary-on-light;
67
$on-primary: on($primary);
68
69
$error-on-light: #d93025;
70
$error-on-dark: #f28b82;
71
$error: $error-on-light;
72
$on-error: on($error);
73
74
$warning-on-light: #f9ab00;
75
$warning-on-dark: #fdd663;
76
$warning: $warning-on-light;
77
$on-warning: on($warning);
78
79
$success-on-light: #1e8e3e;
80
$success-on-dark: #81c995;
81
$success: $success-on-light;
82
$on-success: on($success);
83
84
$visited-on-light: #9334e6;
85
$visited-on-dark: #c58af9;
86
$visited: $visited-on-light;
87
$on-visited: on($visited);
88
89
$system: #212121;
90
$on-system: on($system);
91
92
$tooltip: rgba(#616161, .9);
93
$on-tooltip: on($tooltip);
94
95
$scrim: rgba(black, .6);
96
$on-scrim: on($scrim);
97
98
$scrim-alt: rgba(black, .3);
99
$on-scrim-alt: on($scrim-alt);
100
101
$panel: #212121;
102
$on-panel: on($panel);
103
104
// for Unity panel which doesn't allow translucent colors
105
$panel-solid: $panel;
106
$on-panel-solid: on($panel-solid);
107
108
$titlebar: #424242;
109
$titlebar-backdrop: #303030;
110
$on-titlebar: on($titlebar);
111
112
$titlebar-indicator: currentcolor;
113
114
@if $dark-theme {
115
$surface-z0: #121212;
116
$surface-z1: mix(white, $surface-z0, 5%);
117
$surface-z8: mix(white, $surface-z0, 12%);
118
$surface-switch-thumb: mix(white, $surface-z0, 60%);
119
$on-surface: on($surface-z0);
120
121
$primary: $primary-on-dark;
122
$on-primary: on($primary);
123
124
$error: $error-on-dark;
125
$on-error: on($error);
126
127
$warning: $warning-on-dark;
128
$on-warning: on($warning);
129
130
$success: $success-on-dark;
131
$on-success: on($success);
132
133
$visited: $visited-on-dark;
134
$on-visited: on($visited);
135
136
$titlebar: mix(white, $surface-z0, 9%);
137
$titlebar-backdrop: $surface-z1;
138
$on-titlebar: on($titlebar);
139
}
140
141
@if $light-topbar {
142
$panel: $scrim;
143
$on-panel: on($panel);
144
145
$panel-solid: #e0e0e0;
146
$on-panel-solid: on($panel-solid);
147
148
$titlebar: #f0f0f0;
149
$titlebar-backdrop: #ebebeb;
150
$on-titlebar: on($titlebar);
151
152
$titlebar-indicator: $primary;
153
}
154
155
//
156
// Overlay state colors
157
//
158
159
// Determine the overlay color depending on the given color and opacity.
160
@function _overlay($color, $opacity, $on) {
161
$opacity-modifier: 0;
162
163
@if saturation($color) > 50% or saturation($on) > 50% {
164
$opacity-modifier: .04;
165
}
166
167
@return mix(rgba($color, 1), $on, percentage($opacity + $opacity-modifier));
168
}
169
170
@function hover-overlay($color, $opacity-modifier: 0, $on: transparent, $alt: false) {
171
$opacity: .08;
172
173
@if $alt {
174
$opacity: .04;
175
}
176
177
@return _overlay($color: $color, $opacity: $opacity + $opacity-modifier, $on: $on);
178
}
179
180
@function focus-overlay($color, $opacity-modifier: 0, $on: transparent) {
181
$opacity: .08;
182
183
@return _overlay($color: $color, $opacity: $opacity + $opacity-modifier, $on: $on);
184
}
185
186
@function pressed-overlay($color, $opacity-modifier: 0, $on: transparent) {
187
$opacity: .12;
188
189
@return _overlay($color: $color, $opacity: $opacity + $opacity-modifier, $on: $on);
190
}
191
192
@function dragged-overlay($color, $opacity-modifier: 0, $on: transparent) {
193
$opacity: .08;
194
195
@return _overlay($color: $color, $opacity: $opacity + $opacity-modifier, $on: $on);
196
}
197
198
@function activated-overlay($color, $opacity-modifier: 0, $on: transparent) {
199
$opacity: .12;
200
201
@return _overlay($color: $color, $opacity: $opacity + $opacity-modifier, $on: $on);
202
}
203
204
@function selected-overlay($color, $opacity-modifier: 0) {
205
$opacity: .24;
206
207
@if $color == $on-surface {
208
$color: $primary;
209
}
210
211
@return rgba($color, $opacity + $opacity-modifier);
212
}
213
214
$selected-overlay: selected-overlay($on-surface);
215
216
//
217
// For “on” colors
218
//
219
220
@function primary($color) {
221
@return if(_is-dark($color), $primary-on-light, $primary-on-dark);
222
}
223
224
@function error($color) {
225
@return if(_is-dark($color), $error-on-light, $error-on-dark);
226
}
227
228
@function hint($color) {
229
@return if(_has-alpha($color), rgba($color, .6), rgba($color, .7));
230
}
231
232
@function disabled($color) {
233
@return if(_has-alpha($color), rgba($color, .38), rgba($color, .5));
234
}
235
236
@function disabled-hint($color) {
237
@return if(_has-alpha($color), rgba($color, .26), rgba($color, .3));
238
}
239
240
@function stroke($color) {
241
@return if(_has-alpha($color), rgba($color, .26), rgba($color, .3));
242
}
243
244
@function disabled-stroke($color) {
245
@return if(_has-alpha($color), rgba($color, .12), rgba($color, .2));
246
}
247
248
@function divider($color) {
249
@return if(_has-alpha($color), rgba($color, .12), rgba($color, .2));
250
}
251
252
@function fill($color) {
253
@return if(_has-alpha($color), rgba($color, .08), rgba($color, .08));
254
}
255
256
@function entry-fill($color) {
257
@return if(_has-alpha($color), rgba($color, .04), rgba($color, .04));
258
}
259
260
@function scrollbar-thumb($color, $state: null) {
261
@if $state == null {
262
@return if(_has-alpha($color), rgba($color, .38), rgba($color, .5));
263
} @else if $state == "hover" {
264
@return if(_has-alpha($color), rgba($color, .48), rgba($color, .6));
265
} @else if $state == "pressed" {
266
@return if(_has-alpha($color), rgba($color, .6), rgba($color, .7));
267
} @else if $state == "disabled" {
268
@return if(_has-alpha($color), rgba($color, .26), rgba($color, .3));
269
} @else {
270
@error "Invalid type: '#{$state}'";
271
}
272
}
273