_colors.scss.template
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 "light" or "dark".
16
@function tone($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
@if $brightness >= 128 {
21
@return "light";
22
} @else {
23
@return "dark";
24
}
25
}
26
27
$on-light: #000;
28
$on-dark: #fff;
29
30
// Determine whether to use dark or light color on top of given color
31
// to meet accessibility standards for contrast.
32
@function on($color) {
33
$contrast-color: if(tone($color) == "dark", $on-dark, $on-light);
34
35
@if saturation($color) > 50% or alpha($color) < 1 {
36
@return $contrast-color;
37
} @else {
38
@return rgba($contrast-color, .87);
39
}
40
}
41
42
// Determine the strength of highlight on top of given color.
43
@function highlight($color) {
44
@if lightness($color) >= 80% {
45
@return rgba(white, .4);
46
} @else if lightness($color) >= 40% {
47
@return rgba(white, .2);
48
} @else {
49
@return rgba(white, .05);
50
}
51
}
52
53
// Make translucent color opaque by blending with the background color.
54
@function opacify($color, $on) {
55
@return mix(change-color($color, $alpha: 1), $on, alpha($color) * 100%);
56
}
57
58
// Set the accessible opacity for the overlay depending on the given color.
59
@function overlay($state, $color, $on: transparent, $opacity-modifier: 0) {
60
@if saturation($color) > 50% or saturation($on) > 50% {
61
$opacity-modifier: .04;
62
}
63
64
$opacity: ();
65
66
@if $state == "hover" {
67
$opacity: .08 + $opacity-modifier;
68
} @else if $state == "hover-alt" {
69
$opacity: .04 + $opacity-modifier;
70
} @else if $state == "focus" {
71
$opacity: .08 + $opacity-modifier;
72
} @else if $state == "pressed" {
73
$opacity: .12 + $opacity-modifier;
74
} @else if $state == "dragged" {
75
$opacity: .08 + $opacity-modifier;
76
} @else if $state == "activated" {
77
$opacity: .12 + $opacity-modifier;
78
} @else if $state == "selected" {
79
@return rgba($color, .24);
80
} @else {
81
@error "Invalid type: '#{$state}'";
82
}
83
84
@return mix(rgba($color, 1), $on, $opacity * 100%);
85
}
86
87
// Private variables for dark background colors
88
$-dark-background: if(tone(%BG%) == "dark", %BG%, %FG%);
89
$-dark-surface-1dp: mix(white, $-dark-background, 5%);
90
$-dark-surface-4dp: mix(white, $-dark-background, 9%);
91
$-dark-surface-8dp: mix(white, $-dark-background, 12%);
92
$-dark-surface-switch: mix(white, $-dark-background, 60%);
93
94
//
95
// Main colors
96
//
97
98
$background: %BG%;
99
$base: %MATERIA_VIEW%; // for views
100
$surface: %MATERIA_SURFACE%;
101
$switch-surface: %MATERIA_SURFACE%; // Special case for switches
102
$on-surface: %FG%;
103
104
$primary-on-light: %SEL_BG%;
105
$primary-on-dark: %SEL_BG%;
106
$primary: $primary-on-light;
107
$on-primary: on($primary);
108
109
$error-on-light: %TERMINAL_COLOR9%;
110
$error-on-dark: %TERMINAL_COLOR9%;
111
$error: $error-on-light;
112
$on-error: on($error);
113
114
$warning-on-light: %TERMINAL_COLOR11%;
115
$warning-on-dark: %TERMINAL_COLOR11%;
116
$warning: $warning-on-light;
117
$on-warning: on($warning);
118
119
$success-on-light: %TERMINAL_COLOR10%;
120
$success-on-dark: %TERMINAL_COLOR10%;
121
$success: $success-on-light;
122
$on-success: on($success);
123
124
$visited-on-light: %TERMINAL_COLOR5%;
125
$visited-on-dark: %TERMINAL_COLOR5%;
126
$visited: $visited-on-light;
127
$on-visited: on($visited);
128
129
$os-background: %HDR_BG3%;
130
$on-os-background: %HDR_FG%;
131
132
$tooltip: rgba(%HDR_BG%, .9);
133
$on-tooltip: %HDR_FG%;
134
135
$scrim: rgba(black, %MATERIA_PANEL_OPACITY%);
136
$on-scrim: on($scrim);
137
138
$scrim-alt: rgba(black, .3);
139
$on-scrim-alt: on($scrim-alt);
140
141
$panel: %HDR_BG3%;
142
$on-panel: %HDR_FG%;
143
144
// for Unity panel which doesn't allow translucent colors
145
$panel-solid: %HDR_BG3%;
146
$on-panel-solid: %HDR_FG%;
147
148
$titlebar: %HDR_BG%;
149
$titlebar-backdrop: %HDR_BG2%;
150
$on-titlebar: %HDR_FG%;
151
152
$titlebar-indicator: currentcolor;
153
154
@if $variant == "dark" {
155
$background: if(tone(%BG%) == "dark", %BG%, $-dark-background);
156
$base: if(tone(%BG%) == "dark", %MATERIA_VIEW%, $-dark-surface-1dp);
157
$surface: if(tone(%BG%) == "dark", %MATERIA_SURFACE%, $-dark-surface-8dp);
158
$switch-surface: if(tone(%BG%) == "dark", %MATERIA_SURFACE%, $-dark-surface-switch);
159
$on-surface: if(tone(%BG%) == "dark", %FG%, on($surface));
160
161
$primary: $primary-on-dark;
162
$on-primary: on($primary);
163
164
$error: $error-on-dark;
165
$on-error: on($error);
166
167
$warning: $warning-on-dark;
168
$on-warning: on($warning);
169
170
$success: $success-on-dark;
171
$on-success: on($success);
172
173
$visited: $visited-on-dark;
174
$on-visited: on($visited);
175
176
$titlebar: if(tone(%BG%) == "dark", %HDR_BG%, $-dark-surface-4dp);
177
$titlebar-backdrop: if(tone(%BG%) == "dark", %HDR_BG2%, $-dark-surface-1dp);
178
$on-titlebar: if(tone(%BG%) == "dark", %HDR_FG%, on($titlebar));
179
}
180
181
@if $topbar == "light" {
182
$panel: $scrim;
183
$on-panel: on($panel);
184
185
$titlebar-indicator: $primary;
186
}
187
188
//
189
// Overlay state colors
190
//
191
192
$overlay-selected: rgba($primary, %MATERIA_SELECTION_OPACITY%);
193
194
//
195
// For “on” colors
196
//
197
198
@function primary($color) {
199
@return if(tone($color) == "dark", $primary-on-light, $primary-on-dark);
200
}
201
202
@function error($color) {
203
@return if(tone($color) == "dark", $error-on-light, $error-on-dark);
204
}
205
206
@function hint($color) {
207
@return rgba($color, if(has-alpha($color), .6, .7));
208
}
209
210
@function disabled($color) {
211
@return rgba($color, if(has-alpha($color), .38, .5));
212
}
213
214
@function disabled-hint($color) {
215
@return rgba($color, if(has-alpha($color), .26, .3));
216
}
217
218
@function stroke($color) {
219
@return rgba($color, if(has-alpha($color), .26, .3));
220
}
221
222
@function disabled-stroke($color) {
223
@return rgba($color, if(has-alpha($color), .12, .2));
224
}
225
226
@function divider($color) {
227
@return rgba($color, if(has-alpha($color), .12, .2));
228
}
229
230
@function fill($color) {
231
@return rgba($color, if(has-alpha($color), .08, .08));
232
}
233
234
@function entry-fill($color) {
235
@return rgba($color, if(has-alpha($color), .04, .04));
236
}
237
238
@function scrollbar-thumb($color, $state: null) {
239
@if $state == null {
240
@return rgba($color, if(has-alpha($color), .38, .5));
241
} @else if $state == "hover" {
242
@return rgba($color, if(has-alpha($color), .48, .6));
243
} @else if $state == "pressed" {
244
@return rgba($color, if(has-alpha($color), .6, .7));
245
} @else if $state == "disabled" {
246
@return rgba($color, if(has-alpha($color), .26, .3));
247
} @else {
248
@error "Invalid type: '#{$state}'";
249
}
250
}
251