_colors.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 "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 == "activated" { 75$opacity: .12 + $opacity-modifier; 76} @else if $state == "selected" { 77@return rgba($color, .24); 78} @else { 79@error "Invalid type: '#{$state}'"; 80} 81 82@return mix(rgba($color, 1), $on, $opacity * 100%); 83} 84 85// Private variables for dark background colors 86$-dark-background: #181818; 87$-dark-surface-1dp: mix(white, $-dark-background, 5%); 88$-dark-surface-4dp: mix(white, $-dark-background, 9%); 89$-dark-surface-8dp: mix(white, $-dark-background, 12%); 90$-dark-surface-switch: mix(white, $-dark-background, 60%); 91 92// 93// Main colors 94// 95 96$background: #f9f9f9; 97$base: #fff; // for views 98$surface: #fff; 99$switch-surface: #fff; // Special case for switches 100$on-surface: on($surface); 101 102$primary-on-light: #1967d2; 103$primary-on-dark: #8ab4f8; 104$primary: $primary-on-light; 105$on-primary: on($primary); 106 107$error-on-light: #d93025; 108$error-on-dark: #f28b82; 109$error: $error-on-light; 110$on-error: on($error); 111 112$warning-on-light: #f9ab00; 113$warning-on-dark: #fdd663; 114$warning: $warning-on-light; 115$on-warning: on($warning); 116 117$success-on-light: #1e8e3e; 118$success-on-dark: #81c995; 119$success: $success-on-light; 120$on-success: on($success); 121 122$visited-on-light: #9334e6; 123$visited-on-dark: #c58af9; 124$visited: $visited-on-light; 125$on-visited: on($visited); 126 127$os-background: $-dark-background; 128$on-os-background: on($os-background); 129 130$tooltip: rgba(#616161, .9); 131$on-tooltip: on($tooltip); 132 133$scrim: rgba(black, .6); 134$on-scrim: on($scrim); 135 136$scrim-alt: rgba(black, .3); 137$on-scrim-alt: on($scrim-alt); 138 139$panel: #212121; 140$on-panel: on($panel); 141 142// for Unity panel which doesn't allow translucent colors 143$panel-solid: $panel; 144$on-panel-solid: on($panel-solid); 145 146$titlebar: #424242; 147$titlebar-backdrop: #303030; 148$on-titlebar: on($titlebar); 149 150$titlebar-indicator: currentcolor; 151 152@if $variant == "dark" { 153$background: $-dark-background; 154$base: $-dark-surface-1dp; 155$surface: $-dark-surface-8dp; 156$switch-surface: $-dark-surface-switch; 157$on-surface: on($surface); 158 159$primary: $primary-on-dark; 160$on-primary: on($primary); 161 162$error: $error-on-dark; 163$on-error: on($error); 164 165$warning: $warning-on-dark; 166$on-warning: on($warning); 167 168$success: $success-on-dark; 169$on-success: on($success); 170 171$visited: $visited-on-dark; 172$on-visited: on($visited); 173 174$titlebar: $-dark-surface-4dp; 175$titlebar-backdrop: $-dark-surface-1dp; 176$on-titlebar: on($titlebar); 177} 178 179@if $topbar == "light" { 180$panel: $scrim; 181$on-panel: on($panel); 182 183$panel-solid: #e0e0e0; 184$on-panel-solid: on($panel-solid); 185 186$titlebar: #f0f0f0; 187$titlebar-backdrop: #ebebeb; 188$on-titlebar: on($titlebar); 189 190$titlebar-indicator: $primary; 191} 192 193// 194// Overlay state colors 195// 196 197$overlay-selected: rgba($primary, .24); 198 199// 200// For “on” colors 201// 202 203@function primary($color) { 204@return if(tone($color) == "dark", $primary-on-light, $primary-on-dark); 205} 206 207@function error($color) { 208@return if(tone($color) == "dark", $error-on-light, $error-on-dark); 209} 210 211@function hint($color) { 212@return rgba($color, if(has-alpha($color), .6, .7)); 213} 214 215@function disabled($color) { 216@return rgba($color, if(has-alpha($color), .38, .5)); 217} 218 219@function disabled-hint($color) { 220@return rgba($color, if(has-alpha($color), .26, .3)); 221} 222 223@function stroke($color) { 224@return rgba($color, if(has-alpha($color), .26, .3)); 225} 226 227@function disabled-stroke($color) { 228@return rgba($color, if(has-alpha($color), .12, .2)); 229} 230 231@function divider($color) { 232@return rgba($color, if(has-alpha($color), .12, .2)); 233} 234 235@function fill($color) { 236@return rgba($color, if(has-alpha($color), .08, .08)); 237} 238 239@function entry-fill($color) { 240@return rgba($color, if(has-alpha($color), .04, .04)); 241} 242 243@function scrollbar-thumb($color, $state: null) { 244@if $state == null { 245@return rgba($color, if(has-alpha($color), .38, .5)); 246} @else if $state == "hover" { 247@return rgba($color, if(has-alpha($color), .48, .6)); 248} @else if $state == "pressed" { 249@return rgba($color, if(has-alpha($color), .6, .7)); 250} @else if $state == "disabled" { 251@return rgba($color, if(has-alpha($color), .26, .3)); 252} @else { 253@error "Invalid type: '#{$state}'"; 254} 255} 256