Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit 907aee7

Browse files
committed
Fix adjust-color handling of transparent values #319
* Consider the alpha channel if transparent is given as input (was previously ignored, and would return 'black') * Return literal 'transparent' untouched if it was given as input, without parameters
1 parent e7137db commit 907aee7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/com/vaadin/sass/internal/parser/function/AdjustColorFunctionGenerator.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ protected SassListItem computeForArgumentList(LexicalUnitImpl function,
4343
checkParams(function, actualArguments);
4444
LexicalUnitImpl color = getColor(function, actualArguments);
4545
float alpha = 1;
46-
if (ColorUtil.isRgba(color) || ColorUtil.isHsla(color)) {
46+
if (ColorUtil.isTransparent(color)) {
47+
alpha = 0f;
48+
} else if (ColorUtil.isRgba(color) || ColorUtil.isHsla(color)) {
4749
int lastIndex = color.getParameterList().size() - 1;
4850
alpha = color.getParameterList().get(lastIndex).getContainedValue()
4951
.getFloatValue();
5052
}
5153
Float[] adjustBy = getAdjustments(function, actualArguments);
54+
if (!anySet(adjustBy, 0, 7) && ColorUtil.isTransparent(color)) {
55+
return LexicalUnitImpl.createIdent(ColorUtil.transparent);
56+
}
5257
if (adjustBy[6] != null) {
5358
if ("adjust-color".equals(functionName)) {
5459
alpha += adjustBy[6];

src/main/java/com/vaadin/sass/internal/util/ColorUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ColorUtil {
3535
.compile("#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})");
3636
private static Map<String, String> colorNameToHex = new HashMap<String, String>();
3737
private static Map<String, String> hexToColorName = new HashMap<String, String>();
38-
private static String transparent = "transparent";
38+
public static String transparent = "transparent";
3939

4040
static {
4141
colorNameToHex.put("aqua", "#00ffff");

0 commit comments

Comments
 (0)