1- @use ' sass:color' ;
2- @use ' sass:math' ;
3- @use ' sass:meta' ;
41@use ' sass:map' ;
52
6- // Indicates whether we're building internally. Used for backwards compatibility.
7- $private-is-internal-build : false;
8-
93// Gets the theme's system values as a flat map.
104@function get-system ($theme ) {
115 $system : map .get ($theme , _mat-system );
@@ -15,63 +9,3 @@ $private-is-internal-build: false;
159
1610 @return ();
1711}
18-
19- /// Inherited function from MDC that computes which contrast tone to use on top of a color.
20- /// This is used only in a narrow set of use cases when generating M2 button tokens to maintain
21- /// backwards compatibility.
22- /// @param {Color} $value Color for which we're calculating the contrast tone.
23- /// @param {Boolean} $is-dark Whether the current theme is dark.
24- /// @return {Map} Either `dark` or `light`.
25- @function contrast-tone ($value , $is-dark ) {
26- @if ($value == ' dark' ) {
27- @return ' light' ;
28- }
29-
30- @if ($value == ' light' ) {
31- @return ' dark' ;
32- }
33-
34- // Fallback if the app is using a non-color palette (e.g. CSS variable based).
35- @if (meta .type-of ($value ) != ' color' ) {
36- @return if ($is-dark , ' light' , ' dark' );
37- }
38-
39- $minimum-contrast : 3.1 ;
40- $light-contrast : _contrast ($value , #fff );
41- $dark-contrast : _contrast ($value , rgba (0 , 0 , 0 , 0.87 ));
42-
43- @if ($light-contrast < $minimum-contrast ) and ($dark-contrast > $light-contrast ) {
44- @return ' dark' ;
45- }
46-
47- @return ' light' ;
48- }
49-
50- @function _linear-channel-value ($channel-value ) {
51- $normalized-channel-value : math .div ($channel-value , 255 );
52-
53- @if ($normalized-channel-value < 0.03928 ) {
54- @return math .div ($normalized-channel-value , 12.92 );
55- }
56-
57- @return math .pow (math .div ($normalized-channel-value + 0.055 , 1.055 ), 2.4 );
58- }
59-
60- // Calculate the luminance for a color.
61- // See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
62- @function _luminance ($color ) {
63- $red : _linear-channel-value (color .red ($color ));
64- $green : _linear-channel-value (color .green ($color ));
65- $blue : _linear-channel-value (color .blue ($color ));
66-
67- @return 0.2126 * $red + 0.7152 * $green + 0.0722 * $blue ;
68- }
69-
70- // Calculate the contrast ratio between two colors.
71- // See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
72- @function _contrast ($back , $front ) {
73- $back-lum : _luminance ($back ) + 0.05 ;
74- $fore-lum : _luminance ($front ) + 0.05 ;
75-
76- @return math .div (math .max ($back-lum , $fore-lum ), math .min ($back-lum , $fore-lum ));
77- }
0 commit comments