(&mut self, color: &Color)
| 171 | N: Visitable + NodeWithMetadata<CssMetadata>, |
| 172 | { |
| 173 | fn visit_color(&mut self, color: &Color) { |
| 174 | // color-mix() is handled by visit_color_mix_function |
| 175 | if let Color::Function(colorfn) = color |
| 176 | && matches!(**colorfn, ColorFunction::ColorMix(_)) |
| 177 | { |
| 178 | return; |
| 179 | } |
| 180 | let Some(chroma_color) = color.to_chromashift() else { |
| 181 | return; |
| 182 | }; |
| 183 | let len = color.to_span().len() as usize; |
| 184 | |
| 185 | if chroma_color.in_gamut_of(ColorSpace::Srgb) |
| 186 | && let Some(candidate) = chroma_color.shortest() |
| 187 | && candidate.len() < len |
| 188 | { |
| 189 | self.transformer.replace_parsed::<Color>(color.to_span(), &candidate); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | // Try the native-space rounded form. This preserves the original colour space |
| 194 | // while reducing precision to perceptually safe levels. |
| 195 | let rounded = chroma_color.round(); |
| 196 | if let Some(css) = rounded.to_css() |
| 197 | && css.len() < len |
| 198 | { |
| 199 | self.transformer.replace_parsed::<Color>(color.to_span(), &css); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | fn visit_color_mix_function<'b>(&mut self, mix: &ColorMixFunction<'b>) -> VisitFlow { |
| 204 | let outer_span = mix.to_span(); |
nothing calls this directly
no test coverage detected