/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Write colors into CSS strings.
usesuper::{
parsing::{NumberOrAngleComponent, NumberOrPercentageComponent},
AbsoluteColor, ColorFlags, ColorSpace,
}; usecrate::values::normalize; use cssparser::color::{clamp_unit_f32, serialize_color_alpha, OPAQUE}; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// A [`ModernComponent`] can serialize to `none`, `nan`, `infinity` and /// floating point values. struct ModernComponent<'a>(&'a Option<f32>);
impl ToCss for AbsoluteColor { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{ matchself.color_space {
ColorSpace::Srgb ifself.flags.contains(ColorFlags::IS_LEGACY_SRGB) => { // The "none" keyword is not supported in the rgb/rgba legacy syntax. let has_alpha = self.alpha != OPAQUE;
impl AbsoluteColor { /// Write a string to `dest` that represents a color as an author would /// enter it. /// NOTE: The format of the output is NOT according to any specification, /// but makes assumptions about the best ways that authors would want to /// enter color values in style sheets, devtools, etc. pubfn write_author_preferred_value<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
macro_rules! precision {
($v:expr) => {{
($v * 100.0).round() / 100.0
}};
}
macro_rules! number {
($c:expr) => {{ iflet Some(v) = $c.map(normalize) {
precision!(v).to_css(dest)?;
} else {
write!(dest, "none")?;
}
}};
}
macro_rules! percentage {
($c:expr) => {{ iflet Some(v) = $c.map(normalize) {
precision!(v).to_css(dest)?;
dest.write_char('%')?;
} else {
write!(dest, "none")?;
}
}};
}
macro_rules! unit_percentage {
($c:expr) => {{ iflet Some(v) = $c.map(normalize) {
precision!(v * 100.0).to_css(dest)?;
dest.write_char('%')?;
} else {
write!(dest, "none")?;
}
}};
}
macro_rules! angle {
($c:expr) => {{ iflet Some(v) = $c.map(normalize) {
precision!(v).to_css(dest)?;
dest.write_str("deg")?;
} else {
write!(dest, "none")?;
}
}};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.