Skip to content

Commit d207cfb

Browse files
committed
harden rgba() replacement re value signature and use warning to see full calling stack
1 parent 1ce7205 commit d207cfb

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/common/scss/_color-functions.scss

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,33 @@
8989
@return eccgui-color-mix($color 100% * $alpha, transparent);
9090
}
9191

92+
$debug-rgba-values: "yes";
93+
94+
/**
95+
* Split between rgba(red, green, blue, alpha) and rgba(color, alpha).
96+
*/
97+
@function rgba($r, $g, $b: "undefined", $a: 1) {
98+
// check if old notation is used
99+
@if meta.variable-exists("r") && meta.variable-exists("g") && $b == "undefined" {
100+
// rgba(color, alpha) was used
101+
// forward to our color check splitter
102+
// @debug ("rgba input: #{$r} #{$g}"); // looks like the signature r,g,b,a always get transformed to color,alpha
103+
@return rgba-extended($r, $g);
104+
} @else {
105+
// rgba(r, g, b, a) is used
106+
// should never trigger because of the magical transformation
107+
$color-new-notation: rgb(#{$r} #{$g} #{$b} / #{$a});
108+
109+
@error "Old color notation found -> use #{$color-new-notation}";
110+
@return $color-new-notation;
111+
}
112+
}
113+
92114
/**
93115
* Overwrite SCSS built-in rgba function to support colors by custom properties and CSS color methods.
94116
* TODO: we need to check if this is future proof, maybe this bahaviour is not planned by Dart Sass library.
95117
*/
96-
@function rgba($color, $alpha) {
118+
@function rgba-extended($color, $alpha) {
97119
@if meta.type-of($color) == "color" {
98120
// value is SASS color value, we use SASS color functionality
99121
$alphacolor: color.change($color, $alpha: $alpha);
@@ -102,7 +124,10 @@
102124
$alphacolor: transparent;
103125
}
104126

105-
@debug "Color value $color is not defined by CSS custom property: rgba(#{$color}, #{$alpha}) -> #{$alphacolor}";
127+
@if $debug-rgba-values == "yes" {
128+
@warn "Color value $color is not defined by CSS custom property: rgba(#{$color}, #{$alpha}) -> #{$alphacolor}";
129+
}
130+
106131
@return $alphacolor;
107132
} @else {
108133
// value is not a SASS color value, we use CSS color method

0 commit comments

Comments
 (0)