Skip to content

Commit 45b792a

Browse files
committed
refactor: replace blue(), green(), and red() with color.channel
1 parent f475e54 commit 45b792a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

scss/functions/_color-contrast.scss

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
@use "sass:color";
2+
@use "sass:math";
13
@use "../variables" as *;
24
@use "math" as *;
35

46
// Color contrast
57
// See https://github.com/twbs/bootstrap/pull/30168
68

7-
// A list of pre-calculated numbers of pow(divide((divide($value, 255) + .055), 1.055), 2.4). (from 0 to 255)
8-
// stylelint-disable-next-line scss/dollar-variable-default, scss/dollar-variable-pattern
9-
$_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003 .0033 .0037 .004 .0044 .0048 .0052 .0056 .006 .0065 .007 .0075 .008 .0086 .0091 .0097 .0103 .011 .0116 .0123 .013 .0137 .0144 .0152 .016 .0168 .0176 .0185 .0194 .0203 .0212 .0222 .0232 .0242 .0252 .0262 .0273 .0284 .0296 .0307 .0319 .0331 .0343 .0356 .0369 .0382 .0395 .0409 .0423 .0437 .0452 .0467 .0482 .0497 .0513 .0529 .0545 .0561 .0578 .0595 .0612 .063 .0648 .0666 .0685 .0704 .0723 .0742 .0762 .0782 .0802 .0823 .0844 .0865 .0887 .0908 .0931 .0953 .0976 .0999 .1022 .1046 .107 .1095 .1119 .1144 .117 .1195 .1221 .1248 .1274 .1301 .1329 .1356 .1384 .1413 .1441 .147 .15 .1529 .1559 .159 .162 .1651 .1683 .1714 .1746 .1779 .1812 .1845 .1878 .1912 .1946 .1981 .2016 .2051 .2086 .2122 .2159 .2195 .2232 .227 .2307 .2346 .2384 .2423 .2462 .2502 .2542 .2582 .2623 .2664 .2705 .2747 .2789 .2831 .2874 .2918 .2961 .3005 .305 .3095 .314 .3185 .3231 .3278 .3325 .3372 .3419 .3467 .3515 .3564 .3613 .3663 .3712 .3763 .3813 .3864 .3916 .3968 .402 .4072 .4125 .4179 .4233 .4287 .4342 .4397 .4452 .4508 .4564 .4621 .4678 .4735 .4793 .4851 .491 .4969 .5029 .5089 .5149 .521 .5271 .5333 .5395 .5457 .552 .5583 .5647 .5711 .5776 .5841 .5906 .5972 .6038 .6105 .6172 .624 .6308 .6376 .6445 .6514 .6584 .6654 .6724 .6795 .6867 .6939 .7011 .7084 .7157 .7231 .7305 .7379 .7454 .7529 .7605 .7682 .7758 .7835 .7913 .7991 .807 .8148 .8228 .8308 .8388 .8469 .855 .8632 .8714 .8796 .8879 .8963 .9047 .9131 .9216 .9301 .9387 .9473 .956 .9647 .9734 .9823 .9911 1;
10-
119
@function color-contrast($background, $color-contrast-dark: $color-contrast-dark, $color-contrast-light: $color-contrast-light, $min-contrast-ratio: $min-contrast-ratio) {
1210
$foregrounds: $color-contrast-light, $color-contrast-dark, $white, $black;
1311
$max-ratio: 0;
@@ -40,13 +38,13 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
4038
// See https://www.w3.org/TR/WCAG/#dfn-contrast-ratio
4139
@function luminance($color) {
4240
$rgb: (
43-
"r": red($color),
44-
"g": green($color),
45-
"b": blue($color)
41+
"r": color.channel($color, "red", $space: rgb), // stylelint-disable-line scss/at-function-named-arguments
42+
"g": color.channel($color, "green", $space: rgb), // stylelint-disable-line scss/at-function-named-arguments
43+
"b": color.channel($color, "blue", $space: rgb) // stylelint-disable-line scss/at-function-named-arguments
4644
);
4745

4846
@each $name, $value in $rgb {
49-
$value: if(divide($value, 255) < .04045, divide(divide($value, 255), 12.92), nth($_luminance-list, $value + 1));
47+
$value: if(divide($value, 255) < .04045, divide(divide($value, 255), 12.92), math.pow(divide((divide(math.round($value) + 1, 255) + .055), 1.055), 2.4));
5048
$rgb: map-merge($rgb, ($name: $value));
5149
}
5250

scss/functions/_color.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:color";
2+
13
// scss-docs-start color-functions
24
// Tint a color: mix a color with white
35
@function tint-color($color, $weight) {
@@ -16,7 +18,7 @@
1618
// scss-docs-end color-functions
1719

1820
@function to-rgb($value) {
19-
@return red($value), green($value), blue($value);
21+
@return color.channel($value, "red", $space: rgb), color.channel($value, "green", $space: rgb), color.channel($value, "blue", $space: rgb);
2022
}
2123

2224
@function rgba-css-var($prefix, $identifier, $target) {

scss/tests/mixins/_color-modes.test.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
}
1919
@include color-mode(dark, true) {
20-
--custom-color: #{mix($indigo, $blue, 50%)};
20+
--custom-color: #{$indigo};
2121
}
2222
}
2323
@include expect() {
@@ -26,7 +26,7 @@
2626
background-color: var(--cui-primary-bg-subtle);
2727
}
2828
[data-coreui-theme=dark] {
29-
--custom-color: #3a3ff8;
29+
--custom-color: #6610f2;
3030
}
3131
}
3232
}
@@ -46,7 +46,7 @@
4646
}
4747
}
4848
@include color-mode(dark, true) {
49-
--custom-color: #{mix($indigo, $blue, 50%)};
49+
--custom-color: #{$indigo}
5050
}
5151
}
5252
@include expect() {
@@ -58,7 +58,7 @@
5858
}
5959
@media (prefers-color-scheme: dark) {
6060
:root {
61-
--custom-color: #3a3ff8;
61+
--custom-color: #6610f2;
6262
}
6363
}
6464
}

scss/tests/sass-true/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { runSass } = require('sass-true')
66

77
module.exports = (filename, { describe, it }) => {
88
const data = fs.readFileSync(filename, 'utf8')
9-
const TRUE_SETUP = '$true-terminal-output: false; @import "true";'
9+
const TRUE_SETUP = '$true-terminal-output: false; @use "true" as *;'
1010
const sassString = TRUE_SETUP + data
1111

1212
runSass(

0 commit comments

Comments
 (0)