Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
View
6 src/dotless.Core/Parser/Parsers.cs
@@ -374,13 +374,13 @@ public Variable Variable(Parser parser)
//
public Color Color(Parser parser)
{
- RegexMatchResult rgb;
+ RegexMatchResult hex;
var index = parser.Tokenizer.Location.Index;
if (parser.Tokenizer.CurrentChar == '#' &&
- (rgb = parser.Tokenizer.Match(@"#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})")))
- return NodeProvider.Color(rgb[1], parser.Tokenizer.GetNodeLocation(index));
+ (hex = parser.Tokenizer.Match(@"#([a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})")))
+ return NodeProvider.Color(hex[1], parser.Tokenizer.GetNodeLocation(index));
return null;
}
View
28 src/dotless.Core/Parser/Tree/Color.cs
@@ -184,6 +184,8 @@ static Color()
}
}
+ private bool isArgb = false;
+
public readonly double[] RGB;
public readonly double Alpha;
@@ -206,22 +208,32 @@ public Color(IEnumerable<Number> rgb, Number alpha)
Alpha = alpha.Normalize();
}
- public Color(string rgb)
+ public Color(string hex)
{
- if (rgb.Length == 6)
+ Alpha = 1;
+
+ if (hex.Length == 8)
+ {
+ isArgb = true;
+ RGB = Enumerable.Range(1, 3)
+ .Select(i => hex.Substring(i * 2, 2))
+ .Select(s => (double) int.Parse(s, NumberStyles.HexNumber))
+ .ToArray();
+ Alpha = (double) int.Parse(hex.Substring(0, 2), NumberStyles.HexNumber) / 255d;
+ }
+ else if (hex.Length == 6)
{
RGB = Enumerable.Range(0, 3)
- .Select(i => rgb.Substring(i*2, 2))
+ .Select(i => hex.Substring(i*2, 2))
.Select(s => (double) int.Parse(s, NumberStyles.HexNumber))
.ToArray();
}
else
{
- RGB = rgb.ToCharArray()
+ RGB = hex.ToCharArray()
.Select(c => (double) int.Parse("" + c + c, NumberStyles.HexNumber))
.ToArray();
}
- Alpha = 1;
}
public Color(double red, double green, double blue, double alpha)
@@ -284,6 +296,12 @@ public override void AppendCSS(Env env)
return;
}
+ if (isArgb)
+ {
+ env.Output.Append(ToArgb());
+ return;
+ }
+
if (Alpha < 1.0)
{
env.Output.AppendFormat(CultureInfo.InvariantCulture, "rgba({0}, {1}, {2}, {3})", rgb[0], rgb[1], rgb[2], Alpha);
View
7 src/dotless.Test/Specs/Compression/ColorsFixture.cs
@@ -10,6 +10,13 @@ public void Colors()
AssertExpression("#fea", "#ffeeaa");
AssertExpression("blue", "#0000ff");
}
+
+ [Test]
+ public void Should_not_compress_IE_ARGB()
+ {
+ AssertExpressionUnchanged("#ffaabbcc");
+ AssertExpressionUnchanged("#aabbccdd");
+ }
[Test]
public void Overflow()
Please sign in to comment.
Something went wrong with that request. Please try again.