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