@@ -999,6 +999,178 @@ impl FromParsedColor for Color {
999
999
}
1000
1000
}
1001
1001
1002
+ ascii_case_insensitive_phf_map ! {
1003
+ named_colors -> ( u8 , u8 , u8 ) = {
1004
+ "black" => ( 0 , 0 , 0 ) ,
1005
+ "silver" => ( 192 , 192 , 192 ) ,
1006
+ "gray" => ( 128 , 128 , 128 ) ,
1007
+ "white" => ( 255 , 255 , 255 ) ,
1008
+ "maroon" => ( 128 , 0 , 0 ) ,
1009
+ "red" => ( 255 , 0 , 0 ) ,
1010
+ "purple" => ( 128 , 0 , 128 ) ,
1011
+ "fuchsia" => ( 255 , 0 , 255 ) ,
1012
+ "green" => ( 0 , 128 , 0 ) ,
1013
+ "lime" => ( 0 , 255 , 0 ) ,
1014
+ "olive" => ( 128 , 128 , 0 ) ,
1015
+ "yellow" => ( 255 , 255 , 0 ) ,
1016
+ "navy" => ( 0 , 0 , 128 ) ,
1017
+ "blue" => ( 0 , 0 , 255 ) ,
1018
+ "teal" => ( 0 , 128 , 128 ) ,
1019
+ "aqua" => ( 0 , 255 , 255 ) ,
1020
+
1021
+ "aliceblue" => ( 240 , 248 , 255 ) ,
1022
+ "antiquewhite" => ( 250 , 235 , 215 ) ,
1023
+ "aquamarine" => ( 127 , 255 , 212 ) ,
1024
+ "azure" => ( 240 , 255 , 255 ) ,
1025
+ "beige" => ( 245 , 245 , 220 ) ,
1026
+ "bisque" => ( 255 , 228 , 196 ) ,
1027
+ "blanchedalmond" => ( 255 , 235 , 205 ) ,
1028
+ "blueviolet" => ( 138 , 43 , 226 ) ,
1029
+ "brown" => ( 165 , 42 , 42 ) ,
1030
+ "burlywood" => ( 222 , 184 , 135 ) ,
1031
+ "cadetblue" => ( 95 , 158 , 160 ) ,
1032
+ "chartreuse" => ( 127 , 255 , 0 ) ,
1033
+ "chocolate" => ( 210 , 105 , 30 ) ,
1034
+ "coral" => ( 255 , 127 , 80 ) ,
1035
+ "cornflowerblue" => ( 100 , 149 , 237 ) ,
1036
+ "cornsilk" => ( 255 , 248 , 220 ) ,
1037
+ "crimson" => ( 220 , 20 , 60 ) ,
1038
+ "cyan" => ( 0 , 255 , 255 ) ,
1039
+ "darkblue" => ( 0 , 0 , 139 ) ,
1040
+ "darkcyan" => ( 0 , 139 , 139 ) ,
1041
+ "darkgoldenrod" => ( 184 , 134 , 11 ) ,
1042
+ "darkgray" => ( 169 , 169 , 169 ) ,
1043
+ "darkgreen" => ( 0 , 100 , 0 ) ,
1044
+ "darkgrey" => ( 169 , 169 , 169 ) ,
1045
+ "darkkhaki" => ( 189 , 183 , 107 ) ,
1046
+ "darkmagenta" => ( 139 , 0 , 139 ) ,
1047
+ "darkolivegreen" => ( 85 , 107 , 47 ) ,
1048
+ "darkorange" => ( 255 , 140 , 0 ) ,
1049
+ "darkorchid" => ( 153 , 50 , 204 ) ,
1050
+ "darkred" => ( 139 , 0 , 0 ) ,
1051
+ "darksalmon" => ( 233 , 150 , 122 ) ,
1052
+ "darkseagreen" => ( 143 , 188 , 143 ) ,
1053
+ "darkslateblue" => ( 72 , 61 , 139 ) ,
1054
+ "darkslategray" => ( 47 , 79 , 79 ) ,
1055
+ "darkslategrey" => ( 47 , 79 , 79 ) ,
1056
+ "darkturquoise" => ( 0 , 206 , 209 ) ,
1057
+ "darkviolet" => ( 148 , 0 , 211 ) ,
1058
+ "deeppink" => ( 255 , 20 , 147 ) ,
1059
+ "deepskyblue" => ( 0 , 191 , 255 ) ,
1060
+ "dimgray" => ( 105 , 105 , 105 ) ,
1061
+ "dimgrey" => ( 105 , 105 , 105 ) ,
1062
+ "dodgerblue" => ( 30 , 144 , 255 ) ,
1063
+ "firebrick" => ( 178 , 34 , 34 ) ,
1064
+ "floralwhite" => ( 255 , 250 , 240 ) ,
1065
+ "forestgreen" => ( 34 , 139 , 34 ) ,
1066
+ "gainsboro" => ( 220 , 220 , 220 ) ,
1067
+ "ghostwhite" => ( 248 , 248 , 255 ) ,
1068
+ "gold" => ( 255 , 215 , 0 ) ,
1069
+ "goldenrod" => ( 218 , 165 , 32 ) ,
1070
+ "greenyellow" => ( 173 , 255 , 47 ) ,
1071
+ "grey" => ( 128 , 128 , 128 ) ,
1072
+ "honeydew" => ( 240 , 255 , 240 ) ,
1073
+ "hotpink" => ( 255 , 105 , 180 ) ,
1074
+ "indianred" => ( 205 , 92 , 92 ) ,
1075
+ "indigo" => ( 75 , 0 , 130 ) ,
1076
+ "ivory" => ( 255 , 255 , 240 ) ,
1077
+ "khaki" => ( 240 , 230 , 140 ) ,
1078
+ "lavender" => ( 230 , 230 , 250 ) ,
1079
+ "lavenderblush" => ( 255 , 240 , 245 ) ,
1080
+ "lawngreen" => ( 124 , 252 , 0 ) ,
1081
+ "lemonchiffon" => ( 255 , 250 , 205 ) ,
1082
+ "lightblue" => ( 173 , 216 , 230 ) ,
1083
+ "lightcoral" => ( 240 , 128 , 128 ) ,
1084
+ "lightcyan" => ( 224 , 255 , 255 ) ,
1085
+ "lightgoldenrodyellow" => ( 250 , 250 , 210 ) ,
1086
+ "lightgray" => ( 211 , 211 , 211 ) ,
1087
+ "lightgreen" => ( 144 , 238 , 144 ) ,
1088
+ "lightgrey" => ( 211 , 211 , 211 ) ,
1089
+ "lightpink" => ( 255 , 182 , 193 ) ,
1090
+ "lightsalmon" => ( 255 , 160 , 122 ) ,
1091
+ "lightseagreen" => ( 32 , 178 , 170 ) ,
1092
+ "lightskyblue" => ( 135 , 206 , 250 ) ,
1093
+ "lightslategray" => ( 119 , 136 , 153 ) ,
1094
+ "lightslategrey" => ( 119 , 136 , 153 ) ,
1095
+ "lightsteelblue" => ( 176 , 196 , 222 ) ,
1096
+ "lightyellow" => ( 255 , 255 , 224 ) ,
1097
+ "limegreen" => ( 50 , 205 , 50 ) ,
1098
+ "linen" => ( 250 , 240 , 230 ) ,
1099
+ "magenta" => ( 255 , 0 , 255 ) ,
1100
+ "mediumaquamarine" => ( 102 , 205 , 170 ) ,
1101
+ "mediumblue" => ( 0 , 0 , 205 ) ,
1102
+ "mediumorchid" => ( 186 , 85 , 211 ) ,
1103
+ "mediumpurple" => ( 147 , 112 , 219 ) ,
1104
+ "mediumseagreen" => ( 60 , 179 , 113 ) ,
1105
+ "mediumslateblue" => ( 123 , 104 , 238 ) ,
1106
+ "mediumspringgreen" => ( 0 , 250 , 154 ) ,
1107
+ "mediumturquoise" => ( 72 , 209 , 204 ) ,
1108
+ "mediumvioletred" => ( 199 , 21 , 133 ) ,
1109
+ "midnightblue" => ( 25 , 25 , 112 ) ,
1110
+ "mintcream" => ( 245 , 255 , 250 ) ,
1111
+ "mistyrose" => ( 255 , 228 , 225 ) ,
1112
+ "moccasin" => ( 255 , 228 , 181 ) ,
1113
+ "navajowhite" => ( 255 , 222 , 173 ) ,
1114
+ "oldlace" => ( 253 , 245 , 230 ) ,
1115
+ "olivedrab" => ( 107 , 142 , 35 ) ,
1116
+ "orange" => ( 255 , 165 , 0 ) ,
1117
+ "orangered" => ( 255 , 69 , 0 ) ,
1118
+ "orchid" => ( 218 , 112 , 214 ) ,
1119
+ "palegoldenrod" => ( 238 , 232 , 170 ) ,
1120
+ "palegreen" => ( 152 , 251 , 152 ) ,
1121
+ "paleturquoise" => ( 175 , 238 , 238 ) ,
1122
+ "palevioletred" => ( 219 , 112 , 147 ) ,
1123
+ "papayawhip" => ( 255 , 239 , 213 ) ,
1124
+ "peachpuff" => ( 255 , 218 , 185 ) ,
1125
+ "peru" => ( 205 , 133 , 63 ) ,
1126
+ "pink" => ( 255 , 192 , 203 ) ,
1127
+ "plum" => ( 221 , 160 , 221 ) ,
1128
+ "powderblue" => ( 176 , 224 , 230 ) ,
1129
+ "rebeccapurple" => ( 102 , 51 , 153 ) ,
1130
+ "rosybrown" => ( 188 , 143 , 143 ) ,
1131
+ "royalblue" => ( 65 , 105 , 225 ) ,
1132
+ "saddlebrown" => ( 139 , 69 , 19 ) ,
1133
+ "salmon" => ( 250 , 128 , 114 ) ,
1134
+ "sandybrown" => ( 244 , 164 , 96 ) ,
1135
+ "seagreen" => ( 46 , 139 , 87 ) ,
1136
+ "seashell" => ( 255 , 245 , 238 ) ,
1137
+ "sienna" => ( 160 , 82 , 45 ) ,
1138
+ "skyblue" => ( 135 , 206 , 235 ) ,
1139
+ "slateblue" => ( 106 , 90 , 205 ) ,
1140
+ "slategray" => ( 112 , 128 , 144 ) ,
1141
+ "slategrey" => ( 112 , 128 , 144 ) ,
1142
+ "snow" => ( 255 , 250 , 250 ) ,
1143
+ "springgreen" => ( 0 , 255 , 127 ) ,
1144
+ "steelblue" => ( 70 , 130 , 180 ) ,
1145
+ "tan" => ( 210 , 180 , 140 ) ,
1146
+ "thistle" => ( 216 , 191 , 216 ) ,
1147
+ "tomato" => ( 255 , 99 , 71 ) ,
1148
+ "turquoise" => ( 64 , 224 , 208 ) ,
1149
+ "violet" => ( 238 , 130 , 238 ) ,
1150
+ "wheat" => ( 245 , 222 , 179 ) ,
1151
+ "whitesmoke" => ( 245 , 245 , 245 ) ,
1152
+ "yellowgreen" => ( 154 , 205 , 50 ) ,
1153
+ }
1154
+ }
1155
+
1156
+ /// Returns the named color with the given name.
1157
+ /// <https://drafts.csswg.org/css-color-4/#typedef-named-color>
1158
+ #[ inline]
1159
+ pub fn parse_named_color < Output > ( ident : & str ) -> Result < Output , ( ) >
1160
+ where
1161
+ Output : FromParsedColor ,
1162
+ {
1163
+ let & ( r, g, b) = named_colors:: get ( ident) . ok_or ( ( ) ) ?;
1164
+ Ok ( Output :: from_rgba ( r, g, b, 1.0 ) )
1165
+ }
1166
+
1167
+ /// Returns an iterator over all named CSS colors.
1168
+ /// <https://drafts.csswg.org/css-color-4/#typedef-named-color>
1169
+ #[ inline]
1170
+ pub fn all_named_colors ( ) -> impl Iterator < Item = ( & ' static str , ( u8 , u8 , u8 ) ) > {
1171
+ named_colors:: entries ( ) . map ( |( k, v) | ( * k, * v) )
1172
+ }
1173
+
1002
1174
/// Return the named color with the given name.
1003
1175
///
1004
1176
/// Matching is case-insensitive in the ASCII range.
@@ -1009,167 +1181,11 @@ pub fn parse_color_keyword<Output>(ident: &str) -> Result<Output, ()>
1009
1181
where
1010
1182
Output : FromParsedColor ,
1011
1183
{
1012
- ascii_case_insensitive_phf_map ! {
1013
- keyword -> ( u8 , u8 , u8 ) = {
1014
- "black" => ( 0 , 0 , 0 ) ,
1015
- "silver" => ( 192 , 192 , 192 ) ,
1016
- "gray" => ( 128 , 128 , 128 ) ,
1017
- "white" => ( 255 , 255 , 255 ) ,
1018
- "maroon" => ( 128 , 0 , 0 ) ,
1019
- "red" => ( 255 , 0 , 0 ) ,
1020
- "purple" => ( 128 , 0 , 128 ) ,
1021
- "fuchsia" => ( 255 , 0 , 255 ) ,
1022
- "green" => ( 0 , 128 , 0 ) ,
1023
- "lime" => ( 0 , 255 , 0 ) ,
1024
- "olive" => ( 128 , 128 , 0 ) ,
1025
- "yellow" => ( 255 , 255 , 0 ) ,
1026
- "navy" => ( 0 , 0 , 128 ) ,
1027
- "blue" => ( 0 , 0 , 255 ) ,
1028
- "teal" => ( 0 , 128 , 128 ) ,
1029
- "aqua" => ( 0 , 255 , 255 ) ,
1030
-
1031
- "aliceblue" => ( 240 , 248 , 255 ) ,
1032
- "antiquewhite" => ( 250 , 235 , 215 ) ,
1033
- "aquamarine" => ( 127 , 255 , 212 ) ,
1034
- "azure" => ( 240 , 255 , 255 ) ,
1035
- "beige" => ( 245 , 245 , 220 ) ,
1036
- "bisque" => ( 255 , 228 , 196 ) ,
1037
- "blanchedalmond" => ( 255 , 235 , 205 ) ,
1038
- "blueviolet" => ( 138 , 43 , 226 ) ,
1039
- "brown" => ( 165 , 42 , 42 ) ,
1040
- "burlywood" => ( 222 , 184 , 135 ) ,
1041
- "cadetblue" => ( 95 , 158 , 160 ) ,
1042
- "chartreuse" => ( 127 , 255 , 0 ) ,
1043
- "chocolate" => ( 210 , 105 , 30 ) ,
1044
- "coral" => ( 255 , 127 , 80 ) ,
1045
- "cornflowerblue" => ( 100 , 149 , 237 ) ,
1046
- "cornsilk" => ( 255 , 248 , 220 ) ,
1047
- "crimson" => ( 220 , 20 , 60 ) ,
1048
- "cyan" => ( 0 , 255 , 255 ) ,
1049
- "darkblue" => ( 0 , 0 , 139 ) ,
1050
- "darkcyan" => ( 0 , 139 , 139 ) ,
1051
- "darkgoldenrod" => ( 184 , 134 , 11 ) ,
1052
- "darkgray" => ( 169 , 169 , 169 ) ,
1053
- "darkgreen" => ( 0 , 100 , 0 ) ,
1054
- "darkgrey" => ( 169 , 169 , 169 ) ,
1055
- "darkkhaki" => ( 189 , 183 , 107 ) ,
1056
- "darkmagenta" => ( 139 , 0 , 139 ) ,
1057
- "darkolivegreen" => ( 85 , 107 , 47 ) ,
1058
- "darkorange" => ( 255 , 140 , 0 ) ,
1059
- "darkorchid" => ( 153 , 50 , 204 ) ,
1060
- "darkred" => ( 139 , 0 , 0 ) ,
1061
- "darksalmon" => ( 233 , 150 , 122 ) ,
1062
- "darkseagreen" => ( 143 , 188 , 143 ) ,
1063
- "darkslateblue" => ( 72 , 61 , 139 ) ,
1064
- "darkslategray" => ( 47 , 79 , 79 ) ,
1065
- "darkslategrey" => ( 47 , 79 , 79 ) ,
1066
- "darkturquoise" => ( 0 , 206 , 209 ) ,
1067
- "darkviolet" => ( 148 , 0 , 211 ) ,
1068
- "deeppink" => ( 255 , 20 , 147 ) ,
1069
- "deepskyblue" => ( 0 , 191 , 255 ) ,
1070
- "dimgray" => ( 105 , 105 , 105 ) ,
1071
- "dimgrey" => ( 105 , 105 , 105 ) ,
1072
- "dodgerblue" => ( 30 , 144 , 255 ) ,
1073
- "firebrick" => ( 178 , 34 , 34 ) ,
1074
- "floralwhite" => ( 255 , 250 , 240 ) ,
1075
- "forestgreen" => ( 34 , 139 , 34 ) ,
1076
- "gainsboro" => ( 220 , 220 , 220 ) ,
1077
- "ghostwhite" => ( 248 , 248 , 255 ) ,
1078
- "gold" => ( 255 , 215 , 0 ) ,
1079
- "goldenrod" => ( 218 , 165 , 32 ) ,
1080
- "greenyellow" => ( 173 , 255 , 47 ) ,
1081
- "grey" => ( 128 , 128 , 128 ) ,
1082
- "honeydew" => ( 240 , 255 , 240 ) ,
1083
- "hotpink" => ( 255 , 105 , 180 ) ,
1084
- "indianred" => ( 205 , 92 , 92 ) ,
1085
- "indigo" => ( 75 , 0 , 130 ) ,
1086
- "ivory" => ( 255 , 255 , 240 ) ,
1087
- "khaki" => ( 240 , 230 , 140 ) ,
1088
- "lavender" => ( 230 , 230 , 250 ) ,
1089
- "lavenderblush" => ( 255 , 240 , 245 ) ,
1090
- "lawngreen" => ( 124 , 252 , 0 ) ,
1091
- "lemonchiffon" => ( 255 , 250 , 205 ) ,
1092
- "lightblue" => ( 173 , 216 , 230 ) ,
1093
- "lightcoral" => ( 240 , 128 , 128 ) ,
1094
- "lightcyan" => ( 224 , 255 , 255 ) ,
1095
- "lightgoldenrodyellow" => ( 250 , 250 , 210 ) ,
1096
- "lightgray" => ( 211 , 211 , 211 ) ,
1097
- "lightgreen" => ( 144 , 238 , 144 ) ,
1098
- "lightgrey" => ( 211 , 211 , 211 ) ,
1099
- "lightpink" => ( 255 , 182 , 193 ) ,
1100
- "lightsalmon" => ( 255 , 160 , 122 ) ,
1101
- "lightseagreen" => ( 32 , 178 , 170 ) ,
1102
- "lightskyblue" => ( 135 , 206 , 250 ) ,
1103
- "lightslategray" => ( 119 , 136 , 153 ) ,
1104
- "lightslategrey" => ( 119 , 136 , 153 ) ,
1105
- "lightsteelblue" => ( 176 , 196 , 222 ) ,
1106
- "lightyellow" => ( 255 , 255 , 224 ) ,
1107
- "limegreen" => ( 50 , 205 , 50 ) ,
1108
- "linen" => ( 250 , 240 , 230 ) ,
1109
- "magenta" => ( 255 , 0 , 255 ) ,
1110
- "mediumaquamarine" => ( 102 , 205 , 170 ) ,
1111
- "mediumblue" => ( 0 , 0 , 205 ) ,
1112
- "mediumorchid" => ( 186 , 85 , 211 ) ,
1113
- "mediumpurple" => ( 147 , 112 , 219 ) ,
1114
- "mediumseagreen" => ( 60 , 179 , 113 ) ,
1115
- "mediumslateblue" => ( 123 , 104 , 238 ) ,
1116
- "mediumspringgreen" => ( 0 , 250 , 154 ) ,
1117
- "mediumturquoise" => ( 72 , 209 , 204 ) ,
1118
- "mediumvioletred" => ( 199 , 21 , 133 ) ,
1119
- "midnightblue" => ( 25 , 25 , 112 ) ,
1120
- "mintcream" => ( 245 , 255 , 250 ) ,
1121
- "mistyrose" => ( 255 , 228 , 225 ) ,
1122
- "moccasin" => ( 255 , 228 , 181 ) ,
1123
- "navajowhite" => ( 255 , 222 , 173 ) ,
1124
- "oldlace" => ( 253 , 245 , 230 ) ,
1125
- "olivedrab" => ( 107 , 142 , 35 ) ,
1126
- "orange" => ( 255 , 165 , 0 ) ,
1127
- "orangered" => ( 255 , 69 , 0 ) ,
1128
- "orchid" => ( 218 , 112 , 214 ) ,
1129
- "palegoldenrod" => ( 238 , 232 , 170 ) ,
1130
- "palegreen" => ( 152 , 251 , 152 ) ,
1131
- "paleturquoise" => ( 175 , 238 , 238 ) ,
1132
- "palevioletred" => ( 219 , 112 , 147 ) ,
1133
- "papayawhip" => ( 255 , 239 , 213 ) ,
1134
- "peachpuff" => ( 255 , 218 , 185 ) ,
1135
- "peru" => ( 205 , 133 , 63 ) ,
1136
- "pink" => ( 255 , 192 , 203 ) ,
1137
- "plum" => ( 221 , 160 , 221 ) ,
1138
- "powderblue" => ( 176 , 224 , 230 ) ,
1139
- "rebeccapurple" => ( 102 , 51 , 153 ) ,
1140
- "rosybrown" => ( 188 , 143 , 143 ) ,
1141
- "royalblue" => ( 65 , 105 , 225 ) ,
1142
- "saddlebrown" => ( 139 , 69 , 19 ) ,
1143
- "salmon" => ( 250 , 128 , 114 ) ,
1144
- "sandybrown" => ( 244 , 164 , 96 ) ,
1145
- "seagreen" => ( 46 , 139 , 87 ) ,
1146
- "seashell" => ( 255 , 245 , 238 ) ,
1147
- "sienna" => ( 160 , 82 , 45 ) ,
1148
- "skyblue" => ( 135 , 206 , 235 ) ,
1149
- "slateblue" => ( 106 , 90 , 205 ) ,
1150
- "slategray" => ( 112 , 128 , 144 ) ,
1151
- "slategrey" => ( 112 , 128 , 144 ) ,
1152
- "snow" => ( 255 , 250 , 250 ) ,
1153
- "springgreen" => ( 0 , 255 , 127 ) ,
1154
- "steelblue" => ( 70 , 130 , 180 ) ,
1155
- "tan" => ( 210 , 180 , 140 ) ,
1156
- "thistle" => ( 216 , 191 , 216 ) ,
1157
- "tomato" => ( 255 , 99 , 71 ) ,
1158
- "turquoise" => ( 64 , 224 , 208 ) ,
1159
- "violet" => ( 238 , 130 , 238 ) ,
1160
- "wheat" => ( 245 , 222 , 179 ) ,
1161
- "whitesmoke" => ( 245 , 245 , 245 ) ,
1162
- "yellowgreen" => ( 154 , 205 , 50 ) ,
1163
- }
1164
- }
1165
-
1166
- match_ignore_ascii_case ! { ident ,
1167
- "transparent" => Ok ( Output :: from_rgba( 0 , 0 , 0 , 0.0 ) ) ,
1168
- "currentcolor" => Ok ( Output :: from_current_color( ) ) ,
1169
- _ => keyword( ident)
1170
- . map( |& ( r, g, b) | Output :: from_rgba( r, g, b, 1.0 ) )
1171
- . ok_or( ( ) ) ,
1172
- }
1184
+ Ok ( match_ignore_ascii_case ! { ident ,
1185
+ "transparent" => Output :: from_rgba( 0 , 0 , 0 , 0.0 ) ,
1186
+ "currentcolor" => Output :: from_current_color( ) ,
1187
+ _ => return parse_named_color( ident) ,
1188
+ } )
1173
1189
}
1174
1190
1175
1191
#[ inline]
0 commit comments