mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
feat(css/parser): Normalize hex colors (#6652)
This commit is contained in:
parent
4db1d04082
commit
b257d5d591
@ -23,3 +23,8 @@ div {
|
||||
.foo {
|
||||
border: thick double #32a1ce;
|
||||
}
|
||||
|
||||
.bar {
|
||||
color: #123abcFF;
|
||||
color: #123F;
|
||||
}
|
@ -21,3 +21,7 @@ div {
|
||||
.foo {
|
||||
border: thick double #32a1ce;
|
||||
}
|
||||
.bar {
|
||||
color: #123abcFF;
|
||||
color: #123F;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
div{color:#fff;color:#fff;color:#fff;color:#fff;color:#dc143c;color:#f00;color:#f00;color:#f09;color:#f09;color:#0f38;color:#0f38;color:#0a0a0a;color:#0a0a0afa}div{background:url("starsolid.gif")#99f repeat-y fixed;background:url("starsolid.gif")repeat-y fixed#99f;background:url("starsolid.gif")repeat-y 12#99f}.foo{border:thick double#32a1ce}
|
||||
div{color:#fff;color:#fff;color:#fff;color:#fff;color:#dc143c;color:#f00;color:#f00;color:#f09;color:#f09;color:#0f38;color:#0f38;color:#0a0a0a;color:#0a0a0afa}div{background:url("starsolid.gif")#99f repeat-y fixed;background:url("starsolid.gif")repeat-y fixed#99f;background:url("starsolid.gif")repeat-y 12#99f}.foo{border:thick double#32a1ce}.bar{color:#123abcff;color:#123f}
|
||||
|
@ -28,12 +28,9 @@ fn shorten_hex_color(value: &str) -> Option<&str> {
|
||||
let length = value.len();
|
||||
let chars = value.as_bytes();
|
||||
|
||||
if length == 8
|
||||
&& (chars[6] == b'f' || chars[6] == b'F')
|
||||
&& (chars[7] == b'f' || chars[7] == b'F')
|
||||
{
|
||||
if length == 8 && chars[6] == b'f' && chars[7] == b'f' {
|
||||
return Some(&value[0..6]);
|
||||
} else if length == 4 && chars[3] == b'f' || chars[3] == b'F' {
|
||||
} else if length == 4 && chars[3] == b'f' {
|
||||
return Some(&value[0..3]);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ body {
|
||||
color: red;
|
||||
color: #f00;
|
||||
color: #f00;
|
||||
color: #FC0;
|
||||
color: #fc0;
|
||||
color: #0000ff;
|
||||
color: rgba(0, 0, 255, 0);
|
||||
color: #FFFFFF;
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
x Hex color value '#FFF' should be written into: '#FFFFFF'.
|
||||
x Hex color value '#fff' should be written into: '#ffffff'.
|
||||
,-[$DIR/tests/rules/fail/color-hex-length/long/input.css:1:1]
|
||||
1 | a {
|
||||
2 | color: #FFF;
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
x Hex color value '#FFFFFF' should be written into: '#FFF'.
|
||||
x Hex color value '#ffffff' should be written into: '#fff'.
|
||||
,-[$DIR/tests/rules/fail/color-hex-length/short/input.css:1:1]
|
||||
1 | a {
|
||||
2 | color: #FFFFFF;
|
||||
|
@ -414,7 +414,7 @@ impl Compressor {
|
||||
Color::AbsoluteColorBase(AbsoluteColorBase::HexColor(HexColor {
|
||||
span, value, ..
|
||||
})) => {
|
||||
if let Some(value) = self.get_named_color_by_hex(&value.to_ascii_lowercase()) {
|
||||
if let Some(value) = self.get_named_color_by_hex(value) {
|
||||
*color = Color::AbsoluteColorBase(AbsoluteColorBase::NamedColorOrTransparent(
|
||||
Ident {
|
||||
span: *span,
|
||||
|
@ -423,4 +423,9 @@
|
||||
|
||||
.class-83 {
|
||||
color: rgba(100, 100, 100, -300%);
|
||||
}
|
||||
|
||||
.color {
|
||||
color: #ff0000;
|
||||
color: #FF0000;
|
||||
}
|
@ -1 +1 @@
|
||||
.color{color:rgb(from rgba(0,0,0,0)255 255 255)}.color-1,.color-2{color:rgb(from red 255 255 255)}.color-3{color:rgb(from#f00 255 255 255)}.color-4{color:rgb(from#eee8aa 255 255 255)}.color-5{color:rgb(from#ff0 255 255 255)}.color-6{color:rgb(from snow 255 255 255)}.color-7{color:rgba(123,123,123,0)}.color-8,.color-9,.color-10,.color-11{color:#7b7b7b}.color-12{color:rgba(51,102,77,.23)}.color-13{color:#7b7b7b}.color-14{color:#6496c8}.class-15{color:#7b7b7b}.class-16{color:rgba(123,123,123,.99)}.class-17{color:#7b7b7b}.class-18{color:rgba(179,82,31,.13)}.class-19{color:rgba(180,82,31,.13)}.class-20{color:rgba(181,82,31,.13)}.class-21{color:rgba(182,82,31,.13)}.class-22{color:rgba(184,82,31,.13)}.class-23{color:rgba(181,181,181,.13)}.class-24{color:rgba(182,181,181,.13)}.class-25{color:rgba(181,181,181,.1%)}.class-26{color:rgba(181,181,181,.4%)}.color-27{color:rgb(from#eee8aa 255 255 255)}.color-28{color:rgb(from teal 255 255 255)}.color-29,.color-30{color:rgb(from red 255 255 255)}.class-31{color:#ff0800;color:gray;color:#000;color:#80ff00;color:#a6ff00;color:#f9ff00;color:#80ff00;color:red;color:#00ffae;color:red;color:#ff00bf;color:#8000ff;color:#0040ff;color:#0ff;color:#00ff40;color:#80ff00;color:#ffbf00;color:red;color:#ff00bf;color:rgba(128,0,255,.5);color:rgba(0,64,255,.5);color:rgba(0,255,255,.5);color:rgba(0,255,64,.5);color:rgba(128,255,0,.5);color:rgba(255,191,0,.5);color:rgba(255,0,0,.5);color:red;color:#ff00bf;color:#8000ff;color:#0040ff;color:#0ff;color:#00ff40;color:#80ff00;color:#ffbf00;color:red;color:#ff00bf;color:rgba(128,0,255,.5);color:rgba(0,64,255,.5);color:rgba(0,255,255,.5);color:rgba(0,255,64,.5);color:rgba(128,255,0,.5);color:rgba(255,191,0,.5);color:rgba(255,0,0,.5);color:#ff0400;color:#ff0800;color:#ff0d00}.class-32{color:gray;color:#4d7f4d;color:#fff;color:#fd3;color:#ccb333;color:green;color:#000;color:gray;color:#33b333;color:gray;color:rgba(128,128,128,.2);color:gray;color:rgba(128,128,128,.2);color:#6b8056;color:#4d7f4d;color:rgba(77,127,77,.5);color:red;color:rgba(255,0,0,0);color:#0f0;color:#cfc;color:green;color:rgba(77,127,77,0);color:rgba(170,170,170,0);color:#4d7f4d}.class-33{color:red}.class-34,.class-35{color:rgba(2,3,4,.5)}.class-36{color:#0f0}.class-37{color:rgba(0,255,0,.25)}.class-38{color:#000304}.class-39{color:#64c8ff}.class-40{color:rgba(20,10,0,0)}.class-41{color:#fff;color:#000}.class-42{color:rgba(0,0,0,0)}.class-43{color:maroon}.class-44{color:rgba(128,0,0,0)}.class-45{color:rgba(0,0,0,.5)}.class-46{color:#300}.class-47{color:rgba(51,0,0,0)}.class-48{color:rgba(0,0,0,.5)}.class-49{color:#000}.class-50{color:rgba(0,0,0,0)}.class-51{color:maroon}.class-52{color:rgba(128,0,0,0)}.class-53{color:rgba(0,0,0,.5)}.class-54{color:#300}.class-55{color:rgba(51,0,0,0)}.class-56{color:rgba(0,0,0,.5)}.class-57{color:#59a659}.class-58{color:rgba(77,127,77,.5)}.class-59,.class-60{color:red}.class-61,.class-62{color:rgba(255,0,0,0)}.class-63,.class-64{color:#0f0}.class-65,.class-66{color:#cfc}.class-67,.class-68{color:green}.class-69,.class-70{color:rgba(77,127,77,0)}.class-71,.class-72{color:rgba(170,170,170,0)}.class-73{color:#fff}.class-74{color:#000}.class-75{color:#fff}.class-76,.class-77,.class-78{color:#000}.class-79{color:#fff}.class-80,.class-81{color:#646464}.class-82,.class-83{color:rgba(100,100,100,0)}
|
||||
.color{color:rgb(from rgba(0,0,0,0)255 255 255)}.color-1,.color-2{color:rgb(from red 255 255 255)}.color-3{color:rgb(from#f00 255 255 255)}.color-4{color:rgb(from#eee8aa 255 255 255)}.color-5{color:rgb(from#ff0 255 255 255)}.color-6{color:rgb(from snow 255 255 255)}.color-7{color:rgba(123,123,123,0)}.color-8,.color-9,.color-10,.color-11{color:#7b7b7b}.color-12{color:rgba(51,102,77,.23)}.color-13{color:#7b7b7b}.color-14{color:#6496c8}.class-15{color:#7b7b7b}.class-16{color:rgba(123,123,123,.99)}.class-17{color:#7b7b7b}.class-18{color:rgba(179,82,31,.13)}.class-19{color:rgba(180,82,31,.13)}.class-20{color:rgba(181,82,31,.13)}.class-21{color:rgba(182,82,31,.13)}.class-22{color:rgba(184,82,31,.13)}.class-23{color:rgba(181,181,181,.13)}.class-24{color:rgba(182,181,181,.13)}.class-25{color:rgba(181,181,181,.1%)}.class-26{color:rgba(181,181,181,.4%)}.color-27{color:rgb(from#eee8aa 255 255 255)}.color-28{color:rgb(from teal 255 255 255)}.color-29,.color-30{color:rgb(from red 255 255 255)}.class-31{color:#ff0800;color:gray;color:#000;color:#80ff00;color:#a6ff00;color:#f9ff00;color:#80ff00;color:red;color:#00ffae;color:red;color:#ff00bf;color:#8000ff;color:#0040ff;color:#0ff;color:#00ff40;color:#80ff00;color:#ffbf00;color:red;color:#ff00bf;color:rgba(128,0,255,.5);color:rgba(0,64,255,.5);color:rgba(0,255,255,.5);color:rgba(0,255,64,.5);color:rgba(128,255,0,.5);color:rgba(255,191,0,.5);color:rgba(255,0,0,.5);color:red;color:#ff00bf;color:#8000ff;color:#0040ff;color:#0ff;color:#00ff40;color:#80ff00;color:#ffbf00;color:red;color:#ff00bf;color:rgba(128,0,255,.5);color:rgba(0,64,255,.5);color:rgba(0,255,255,.5);color:rgba(0,255,64,.5);color:rgba(128,255,0,.5);color:rgba(255,191,0,.5);color:rgba(255,0,0,.5);color:#ff0400;color:#ff0800;color:#ff0d00}.class-32{color:gray;color:#4d7f4d;color:#fff;color:#fd3;color:#ccb333;color:green;color:#000;color:gray;color:#33b333;color:gray;color:rgba(128,128,128,.2);color:gray;color:rgba(128,128,128,.2);color:#6b8056;color:#4d7f4d;color:rgba(77,127,77,.5);color:red;color:rgba(255,0,0,0);color:#0f0;color:#cfc;color:green;color:rgba(77,127,77,0);color:rgba(170,170,170,0);color:#4d7f4d}.class-33{color:red}.class-34,.class-35{color:rgba(2,3,4,.5)}.class-36{color:#0f0}.class-37{color:rgba(0,255,0,.25)}.class-38{color:#000304}.class-39{color:#64c8ff}.class-40{color:rgba(20,10,0,0)}.class-41{color:#fff;color:#000}.class-42{color:rgba(0,0,0,0)}.class-43{color:maroon}.class-44{color:rgba(128,0,0,0)}.class-45{color:rgba(0,0,0,.5)}.class-46{color:#300}.class-47{color:rgba(51,0,0,0)}.class-48{color:rgba(0,0,0,.5)}.class-49{color:#000}.class-50{color:rgba(0,0,0,0)}.class-51{color:maroon}.class-52{color:rgba(128,0,0,0)}.class-53{color:rgba(0,0,0,.5)}.class-54{color:#300}.class-55{color:rgba(51,0,0,0)}.class-56{color:rgba(0,0,0,.5)}.class-57{color:#59a659}.class-58{color:rgba(77,127,77,.5)}.class-59,.class-60{color:red}.class-61,.class-62{color:rgba(255,0,0,0)}.class-63,.class-64{color:#0f0}.class-65,.class-66{color:#cfc}.class-67,.class-68{color:green}.class-69,.class-70{color:rgba(77,127,77,0)}.class-71,.class-72{color:rgba(170,170,170,0)}.class-73{color:#fff}.class-74{color:#000}.class-75{color:#fff}.class-76,.class-77,.class-78{color:#000}.class-79{color:#fff}.class-80,.class-81{color:#646464}.class-82,.class-83{color:rgba(100,100,100,0)}.color{color:red}
|
||||
|
@ -2381,7 +2381,7 @@ where
|
||||
match bump!(self) {
|
||||
Token::Hash { value, raw, .. } => Ok(HexColor {
|
||||
span,
|
||||
value,
|
||||
value: value.to_ascii_lowercase(),
|
||||
raw: Some(raw),
|
||||
}),
|
||||
_ => {
|
||||
|
@ -174,7 +174,7 @@
|
||||
"end": 57,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "FFFFFF",
|
||||
"value": "ffffff",
|
||||
"raw": "FFFFFF"
|
||||
}
|
||||
],
|
||||
@ -236,7 +236,7 @@
|
||||
"end": 97,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "0000FFCC",
|
||||
"value": "0000ffcc",
|
||||
"raw": "0000FFCC"
|
||||
}
|
||||
],
|
||||
@ -329,7 +329,7 @@
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "FFF",
|
||||
"value": "fff",
|
||||
"raw": "FFF"
|
||||
}
|
||||
],
|
||||
@ -422,7 +422,7 @@
|
||||
"end": 190,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "FFFF",
|
||||
"value": "ffff",
|
||||
"raw": "FFFF"
|
||||
}
|
||||
],
|
||||
@ -484,7 +484,7 @@
|
||||
"end": 217,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "FF",
|
||||
"value": "ff",
|
||||
"raw": "FF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "ABCD",
|
||||
"value": "abcd",
|
||||
"raw": "ABCD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "ABBBCCDD",
|
||||
"value": "abbbccdd",
|
||||
"raw": "ABBBCCDD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCCFF",
|
||||
"value": "aabbccff",
|
||||
"raw": "AABBCCFF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABCCCDD",
|
||||
"value": "aabcccdd",
|
||||
"raw": "AABCCCDD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "ABBBCC",
|
||||
"value": "abbbcc",
|
||||
"raw": "ABBBCC"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABCCC",
|
||||
"value": "aabccc",
|
||||
"raw": "AABCCC"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCCDE",
|
||||
"value": "aabbccde",
|
||||
"raw": "AABBCCDE"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCCEF",
|
||||
"value": "aabbccef",
|
||||
"raw": "AABBCCEF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "ABCF",
|
||||
"value": "abcf",
|
||||
"raw": "ABCF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCD",
|
||||
"value": "aabbcd",
|
||||
"raw": "AABBCD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCCDD",
|
||||
"value": "aabbccdd",
|
||||
"raw": "AABBCCDD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCDFF",
|
||||
"value": "aabbcdff",
|
||||
"raw": "AABBCDFF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABCCCFF",
|
||||
"value": "aabcccff",
|
||||
"raw": "AABCCCFF"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCDDD",
|
||||
"value": "aabbcddd",
|
||||
"raw": "AABBCDDD"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AABBCC",
|
||||
"value": "aabbcc",
|
||||
"raw": "AABBCC"
|
||||
}
|
||||
],
|
||||
|
@ -112,7 +112,7 @@
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "ABBBCCFF",
|
||||
"value": "abbbccff",
|
||||
"raw": "ABBBCCFF"
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user