Sha256: 6c230eaed17ecd4f4e230c50788a6ea30b1f820f7c9ff943282f3d2a750ef675

Contents?: true

Size: 1.8 KB

Versions: 14

Compression:

Stored size: 1.8 KB

Contents

//
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@import "./constants";

/**
 * Calculate the luminance for a color.
 * See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
 */
@function mdc-theme-luminance($color) {
  $red: nth($mdc-theme-linear-channel-values, red($color) + 1);
  $green: nth($mdc-theme-linear-channel-values, green($color) + 1);
  $blue: nth($mdc-theme-linear-channel-values, blue($color) + 1);

  @return .2126 * $red + .7152 * $green + .0722 * $blue;
}

/**
 * Calculate the contrast ratio between two colors.
 * See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
 */
@function mdc-theme-contrast($back, $front) {
  $backLum: mdc-theme-luminance($back) + .05;
  $foreLum: mdc-theme-luminance($front) + .05;

  @return max($backLum, $foreLum) / min($backLum, $foreLum);
}

/**
 * Determine whether to use dark or light text on top of given color.
 * Returns "dark" for dark text and "light" for light text.
 */
@function mdc-theme-light-or-dark($color) {
  $minimumContrast: 3.1;

  $lightContrast: mdc-theme-contrast($color, white);
  $darkContrast: mdc-theme-contrast($color, rgba(black, .87));

  @if ($lightContrast < $minimumContrast) and ($darkContrast > $lightContrast) {
    @return "dark";
  }

  @else {
    @return "light";
  }
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
material_components_web-sass-0.17.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.16.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.15.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.14.0.1 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.14.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.13.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.12.1 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.12.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.11.1 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.11.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.10.0.1 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.10.0 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.9.1 vendor/assets/stylesheets/@material/theme/_functions.scss
material_components_web-sass-0.9.0 vendor/assets/stylesheets/@material/theme/_functions.scss