Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions src/material/core/tokens/_m2-utils.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
@use 'sass:color';
@use 'sass:math';
@use 'sass:meta';
@use 'sass:map';

// Indicates whether we're building internally. Used for backwards compatibility.
$private-is-internal-build: false;

// Gets the theme's system values as a flat map.
@function get-system($theme) {
$system: map.get($theme, _mat-system);
Expand All @@ -15,63 +9,3 @@ $private-is-internal-build: false;

@return ();
}

/// Inherited function from MDC that computes which contrast tone to use on top of a color.
/// This is used only in a narrow set of use cases when generating M2 button tokens to maintain
/// backwards compatibility.
/// @param {Color} $value Color for which we're calculating the contrast tone.
/// @param {Boolean} $is-dark Whether the current theme is dark.
/// @return {Map} Either `dark` or `light`.
@function contrast-tone($value, $is-dark) {
@if ($value == 'dark') {
@return 'light';
}

@if ($value == 'light') {
@return 'dark';
}

// Fallback if the app is using a non-color palette (e.g. CSS variable based).
@if (meta.type-of($value) != 'color') {
@return if($is-dark, 'light', 'dark');
}

$minimum-contrast: 3.1;
$light-contrast: _contrast($value, #fff);
$dark-contrast: _contrast($value, rgba(0, 0, 0, 0.87));

@if ($light-contrast < $minimum-contrast) and ($dark-contrast > $light-contrast) {
@return 'dark';
}

@return 'light';
}

@function _linear-channel-value($channel-value) {
$normalized-channel-value: math.div($channel-value, 255);

@if ($normalized-channel-value < 0.03928) {
@return math.div($normalized-channel-value, 12.92);
}

@return math.pow(math.div($normalized-channel-value + 0.055, 1.055), 2.4);
}

// Calculate the luminance for a color.
// See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
@function _luminance($color) {
$red: _linear-channel-value(color.red($color));
$green: _linear-channel-value(color.green($color));
$blue: _linear-channel-value(color.blue($color));

@return 0.2126 * $red + 0.7152 * $green + 0.0722 * $blue;
}

// Calculate the contrast ratio between two colors.
// See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
@function _contrast($back, $front) {
$back-lum: _luminance($back) + 0.05;
$fore-lum: _luminance($front) + 0.05;

@return math.div(math.max($back-lum, $fore-lum), math.min($back-lum, $fore-lum));
}
Loading