From a423de913eeceb46b845a580e97b4e40b84dad63 Mon Sep 17 00:00:00 2001 From: Erik Hedvall Date: Sat, 24 Aug 2024 18:10:06 +0200 Subject: [PATCH] Replace the build script with a codegent crate --- Cargo.toml | 5 +- codegen/Cargo.toml | 17 + {palette/build => codegen/res}/svg_colors.txt | 0 codegen/src/codegen_file.rs | 72 +++++ codegen/src/main.rs | 10 + codegen/src/named.rs | 114 +++++++ palette/Cargo.toml | 1 - palette/build/main.rs | 5 - palette/build/named.rs | 81 ----- palette/src/named.rs | 14 +- palette/src/named/codegen.rs | 304 ++++++++++++++++++ 11 files changed, 532 insertions(+), 91 deletions(-) create mode 100644 codegen/Cargo.toml rename {palette/build => codegen/res}/svg_colors.txt (100%) create mode 100644 codegen/src/codegen_file.rs create mode 100644 codegen/src/main.rs create mode 100644 codegen/src/named.rs delete mode 100644 palette/build/main.rs delete mode 100644 palette/build/named.rs create mode 100644 palette/src/named/codegen.rs diff --git a/Cargo.toml b/Cargo.toml index 1103ac984..1d5311998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,9 @@ members = [ # Test crates "integration_tests", "no_std_test", - "benchmarks" + "benchmarks", + + # Tool crates + "codegen" ] resolver = "2" diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml new file mode 100644 index 000000000..14eece447 --- /dev/null +++ b/codegen/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "codegen" +version = "0.0.0" +authors = ["Erik Hedvall "] +exclude = [] +description = "Code generation crate for palette." +repository = "https://github.com/Ogeon/palette" +license = "MIT OR Apache-2.0" +edition = "2018" +publish = false + +[dependencies] +anyhow = "1.0.86" +proc-macro2 = "1.0.86" +quote = "1.0.37" + + diff --git a/palette/build/svg_colors.txt b/codegen/res/svg_colors.txt similarity index 100% rename from palette/build/svg_colors.txt rename to codegen/res/svg_colors.txt diff --git a/codegen/src/codegen_file.rs b/codegen/src/codegen_file.rs new file mode 100644 index 000000000..7fc57f149 --- /dev/null +++ b/codegen/src/codegen_file.rs @@ -0,0 +1,72 @@ +use std::{ + fs::File, + io::Write, + path::Path, + process::{Command, Output, Stdio}, +}; + +use anyhow::{Context, Result}; +use proc_macro2::TokenStream; + +const HEADER_COMMENT: &str = r#"// This file is auto-generated and any manual changes to it will be overwritten. +// +// Run `cargo run -p codegen` from the project root to regenerate it. +"#; + +pub struct CodegenFile { + file: File, +} + +impl CodegenFile { + /// Create a new generated file. + pub fn create>(path: P) -> Result { + let path = path.as_ref(); + let mut file = + File::create(path).with_context(|| format!("could not open or create {path:?}"))?; + + writeln!(file, "{HEADER_COMMENT}")?; + + Ok(Self { file }) + } + + /// Formats and appends the tokens to the output file. + pub fn append(&mut self, tokens: TokenStream) -> Result<()> { + // Taken from https://github.com/Michael-F-Bryan/scad-rs/blob/4dbff0c30ce991105f1e649e678d68c2767e894b/crates/codegen/src/pretty_print.rs + + let mut child = Command::new("rustfmt") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .context("unable to start `rustfmt`. Is it installed?")?; + + let mut stdin = child.stdin.take().unwrap(); + write!(stdin, "{tokens}")?; + stdin.flush()?; + drop(stdin); + + let Output { + status, + stdout, + stderr, + } = child.wait_with_output()?; + let stdout = String::from_utf8_lossy(&stdout); + let stderr = String::from_utf8_lossy(&stderr); + + if !status.success() { + eprintln!("---- Stdout ----"); + eprintln!("{stdout}"); + eprintln!("---- Stderr ----"); + eprintln!("{stderr}"); + let code = status.code(); + match code { + Some(code) => anyhow::bail!("the `rustfmt` command failed with return code {code}"), + None => anyhow::bail!("the `rustfmt` command failed"), + } + } + + writeln!(self.file, "{stdout}")?; + + Ok(()) + } +} diff --git a/codegen/src/main.rs b/codegen/src/main.rs new file mode 100644 index 000000000..a2df8a539 --- /dev/null +++ b/codegen/src/main.rs @@ -0,0 +1,10 @@ +use anyhow::{Context, Result}; + +mod codegen_file; +mod named; + +fn main() -> Result<()> { + named::generate().context("could not generate named color constants")?; + + Ok(()) +} diff --git a/codegen/src/named.rs b/codegen/src/named.rs new file mode 100644 index 000000000..dd66149a7 --- /dev/null +++ b/codegen/src/named.rs @@ -0,0 +1,114 @@ +use std::{ + fs::File, + io::{BufRead, BufReader}, +}; + +use anyhow::{Context, Result}; +use proc_macro2::{Ident, Span, TokenStream}; +use quote::quote; + +use crate::codegen_file::CodegenFile; + +pub fn generate() -> Result<()> { + let mut file = CodegenFile::create("palette/src/named/codegen.rs")?; + + let colors = parse_colors()?; + + file.append(build_colors(&colors))?; + file.append(build_from_str(&colors))?; + + Ok(()) +} + +struct ColorEntry { + name: String, + constant: Ident, + red: u8, + green: u8, + blue: u8, +} + +fn parse_colors() -> Result> { + let reader = BufReader::new( + File::open("codegen/res/svg_colors.txt").expect("could not open svg_colors.txt"), + ); + + // Expected format: "name\t123, 123, 123" + reader + .lines() + .map(|line| { + let line = line?; + let mut parts = line.split('\t'); + + let name = parts + .next() + .context("couldn't get the color name")? + .to_owned(); + let mut rgb = parts + .next() + .with_context(|| format!("couldn't get RGB for {}", name))? + .split(", "); + + let red: u8 = rgb + .next() + .with_context(|| format!("missing red for {name}"))? + .trim() + .parse() + .with_context(|| format!("couldn't parse red for {}", name))?; + + let green: u8 = rgb + .next() + .with_context(|| format!("missing green for {name}"))? + .trim() + .parse() + .with_context(|| format!("couldn't parse green for {}", name))?; + + let blue: u8 = rgb + .next() + .with_context(|| format!("missing blue for {name}"))? + .trim() + .parse() + .with_context(|| format!("couldn't parse blue for {}", name))?; + + let constant = Ident::new(&name.to_ascii_uppercase(), Span::call_site()); + + Ok(ColorEntry { + name, + constant, + red, + green, + blue, + }) + }) + .collect() +} + +fn build_colors(colors: &[ColorEntry]) -> TokenStream { + let constants = colors.iter().map(|ColorEntry { name, constant, red, green, blue }| { + let swatch_html = format!( + r#"
"# + ); + + quote! { + #[doc = #swatch_html] + pub const #constant: crate::rgb::Srgb = crate::rgb::Srgb::new(#red, #green, #blue); + } + }); + + quote! { + #(#constants)* + } +} + +fn build_from_str(entries: &[ColorEntry]) -> TokenStream { + let entries = entries + .iter() + .map(|ColorEntry { name, constant, .. }| quote! {#name => #constant}); + + quote! { + #[cfg(feature = "named_from_str")] + pub(crate) static COLORS: ::phf::Map<&'static str, crate::rgb::Srgb> = phf::phf_map! { + #(#entries),* + }; + } +} diff --git a/palette/Cargo.toml b/palette/Cargo.toml index 7f1e07484..094c6c188 100644 --- a/palette/Cargo.toml +++ b/palette/Cargo.toml @@ -24,7 +24,6 @@ license = "MIT OR Apache-2.0" edition = "2018" resolver = "2" categories = ["graphics", "multimedia::images", "no-std"] -build = "build/main.rs" rust-version = "1.61.0" [features] diff --git a/palette/build/main.rs b/palette/build/main.rs deleted file mode 100644 index 316aefdd1..000000000 --- a/palette/build/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod named; - -fn main() { - named::build(); -} diff --git a/palette/build/named.rs b/palette/build/named.rs deleted file mode 100644 index f3e975509..000000000 --- a/palette/build/named.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::fs::File; - -pub fn build() { - use std::path::Path; - - let out_dir = ::std::env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("named.rs"); - let mut writer = File::create(dest_path).expect("couldn't create named.rs"); - build_colors(&mut writer); -} - -#[cfg(feature = "named")] -pub fn build_colors(writer: &mut File) { - use std::io::{BufRead, BufReader, Write}; - - let reader = - BufReader::new(File::open("build/svg_colors.txt").expect("could not open svg_colors.txt")); - let mut entries = vec![]; - - for line in reader.lines() { - let line = line.unwrap(); - let mut parts = line.split('\t'); - let name = parts.next().expect("couldn't get the color name"); - let mut rgb = parts - .next() - .unwrap_or_else(|| panic!("couldn't get color for {}", name)) - .split(", "); - let red: u8 = rgb - .next() - .and_then(|r| r.trim().parse().ok()) - .unwrap_or_else(|| panic!("couldn't get red for {}", name)); - let green: u8 = rgb - .next() - .and_then(|r| r.trim().parse().ok()) - .unwrap_or_else(|| panic!("couldn't get green for {}", name)); - let blue: u8 = rgb - .next() - .and_then(|r| r.trim().parse().ok()) - .unwrap_or_else(|| panic!("couldn't get blue for {}", name)); - - writeln!(writer, "\n///
", name).unwrap(); - writeln!( - writer, - "pub const {}: crate::rgb::Srgb = crate::rgb::Srgb::new({}, {}, {});", - name.to_uppercase(), - red, - green, - blue - ) - .unwrap(); - - entries.push((name.to_owned(), name.to_uppercase())); - } - - gen_from_str(writer, &entries) -} - -#[cfg(feature = "named_from_str")] -fn gen_from_str(writer: &mut File, entries: &[(String, String)]) { - use std::io::Write; - - writer - .write_all( - "static COLORS: ::phf::Map<&'static str, crate::rgb::Srgb> = phf::phf_map! {\n" - .as_bytes(), - ) - .unwrap(); - - for (key, value) in entries { - writeln!(writer, " \"{}\" => {},", key, value).unwrap(); - } - - writer.write_all("};\n".as_bytes()).unwrap(); -} - -#[cfg(not(feature = "named"))] -pub fn build_colors(_writer: &mut File) {} - -#[allow(unused)] -#[cfg(not(feature = "named_from_str"))] -fn gen_from_str(_writer: &mut File, _entries: &[(String, String)]) {} diff --git a/palette/src/named.rs b/palette/src/named.rs index 310c356db..7309aa0b2 100644 --- a/palette/src/named.rs +++ b/palette/src/named.rs @@ -13,13 +13,21 @@ //! let from_const = Srgb::::from_format(named::OLIVE).into_linear(); #![cfg_attr(feature = "named_from_str", doc = "")] #![cfg_attr(feature = "named_from_str", doc = "//From name string")] -#![cfg_attr(feature = "named_from_str", doc = "let olive = named::from_str(\"olive\").expect(\"unknown color\");")] -#![cfg_attr(feature = "named_from_str", doc = "let from_str = Srgb::::from_format(olive).into_linear();")] +#![cfg_attr( + feature = "named_from_str", + doc = "let olive = named::from_str(\"olive\").expect(\"unknown color\");" +)] +#![cfg_attr( + feature = "named_from_str", + doc = "let from_str = Srgb::::from_format(olive).into_linear();" +)] #![cfg_attr(feature = "named_from_str", doc = "")] #![cfg_attr(feature = "named_from_str", doc = "assert_eq!(from_const, from_str);")] //! ``` -include!(concat!(env!("OUT_DIR"), "/named.rs")); +pub use codegen::*; + +mod codegen; /// Get a SVG/CSS3 color by name. Can be toggled with the `"named_from_str"` /// Cargo feature. diff --git a/palette/src/named/codegen.rs b/palette/src/named/codegen.rs new file mode 100644 index 000000000..1211787c0 --- /dev/null +++ b/palette/src/named/codegen.rs @@ -0,0 +1,304 @@ +// This file is auto-generated and any manual changes to it will be overwritten. +// +// Run `cargo run -p codegen` from the project root to regenerate it. + +#[doc = "
"] +pub const ALICEBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(240u8, 248u8, 255u8); +#[doc = "
"] +pub const ANTIQUEWHITE: crate::rgb::Srgb = crate::rgb::Srgb::new(250u8, 235u8, 215u8); +#[doc = "
"] +pub const AQUA: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 255u8, 255u8); +#[doc = "
"] +pub const AQUAMARINE: crate::rgb::Srgb = crate::rgb::Srgb::new(127u8, 255u8, 212u8); +#[doc = "
"] +pub const AZURE: crate::rgb::Srgb = crate::rgb::Srgb::new(240u8, 255u8, 255u8); +#[doc = "
"] +pub const BEIGE: crate::rgb::Srgb = crate::rgb::Srgb::new(245u8, 245u8, 220u8); +#[doc = "
"] +pub const BISQUE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 228u8, 196u8); +#[doc = "
"] +pub const BLACK: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 0u8, 0u8); +#[doc = "
"] +pub const BLANCHEDALMOND: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 235u8, 205u8); +#[doc = "
"] +pub const BLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 0u8, 255u8); +#[doc = "
"] +pub const BLUEVIOLET: crate::rgb::Srgb = crate::rgb::Srgb::new(138u8, 43u8, 226u8); +#[doc = "
"] +pub const BROWN: crate::rgb::Srgb = crate::rgb::Srgb::new(165u8, 42u8, 42u8); +#[doc = "
"] +pub const BURLYWOOD: crate::rgb::Srgb = crate::rgb::Srgb::new(222u8, 184u8, 135u8); +#[doc = "
"] +pub const CADETBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(95u8, 158u8, 160u8); +#[doc = "
"] +pub const CHARTREUSE: crate::rgb::Srgb = crate::rgb::Srgb::new(127u8, 255u8, 0u8); +#[doc = "
"] +pub const CHOCOLATE: crate::rgb::Srgb = crate::rgb::Srgb::new(210u8, 105u8, 30u8); +#[doc = "
"] +pub const CORAL: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 127u8, 80u8); +#[doc = "
"] +pub const CORNFLOWERBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(100u8, 149u8, 237u8); +#[doc = "
"] +pub const CORNSILK: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 248u8, 220u8); +#[doc = "
"] +pub const CRIMSON: crate::rgb::Srgb = crate::rgb::Srgb::new(220u8, 20u8, 60u8); +#[doc = "
"] +pub const CYAN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 255u8, 255u8); +#[doc = "
"] +pub const DARKBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 0u8, 139u8); +#[doc = "
"] +pub const DARKCYAN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 139u8, 139u8); +#[doc = "
"] +pub const DARKGOLDENROD: crate::rgb::Srgb = crate::rgb::Srgb::new(184u8, 134u8, 11u8); +#[doc = "
"] +pub const DARKGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(169u8, 169u8, 169u8); +#[doc = "
"] +pub const DARKGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 100u8, 0u8); +#[doc = "
"] +pub const DARKGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(169u8, 169u8, 169u8); +#[doc = "
"] +pub const DARKKHAKI: crate::rgb::Srgb = crate::rgb::Srgb::new(189u8, 183u8, 107u8); +#[doc = "
"] +pub const DARKMAGENTA: crate::rgb::Srgb = crate::rgb::Srgb::new(139u8, 0u8, 139u8); +#[doc = "
"] +pub const DARKOLIVEGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(85u8, 107u8, 47u8); +#[doc = "
"] +pub const DARKORANGE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 140u8, 0u8); +#[doc = "
"] +pub const DARKORCHID: crate::rgb::Srgb = crate::rgb::Srgb::new(153u8, 50u8, 204u8); +#[doc = "
"] +pub const DARKRED: crate::rgb::Srgb = crate::rgb::Srgb::new(139u8, 0u8, 0u8); +#[doc = "
"] +pub const DARKSALMON: crate::rgb::Srgb = crate::rgb::Srgb::new(233u8, 150u8, 122u8); +#[doc = "
"] +pub const DARKSEAGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(143u8, 188u8, 143u8); +#[doc = "
"] +pub const DARKSLATEBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(72u8, 61u8, 139u8); +#[doc = "
"] +pub const DARKSLATEGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(47u8, 79u8, 79u8); +#[doc = "
"] +pub const DARKSLATEGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(47u8, 79u8, 79u8); +#[doc = "
"] +pub const DARKTURQUOISE: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 206u8, 209u8); +#[doc = "
"] +pub const DARKVIOLET: crate::rgb::Srgb = crate::rgb::Srgb::new(148u8, 0u8, 211u8); +#[doc = "
"] +pub const DEEPPINK: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 20u8, 147u8); +#[doc = "
"] +pub const DEEPSKYBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 191u8, 255u8); +#[doc = "
"] +pub const DIMGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(105u8, 105u8, 105u8); +#[doc = "
"] +pub const DIMGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(105u8, 105u8, 105u8); +#[doc = "
"] +pub const DODGERBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(30u8, 144u8, 255u8); +#[doc = "
"] +pub const FIREBRICK: crate::rgb::Srgb = crate::rgb::Srgb::new(178u8, 34u8, 34u8); +#[doc = "
"] +pub const FLORALWHITE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 250u8, 240u8); +#[doc = "
"] +pub const FORESTGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(34u8, 139u8, 34u8); +#[doc = "
"] +pub const FUCHSIA: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 0u8, 255u8); +#[doc = "
"] +pub const GAINSBORO: crate::rgb::Srgb = crate::rgb::Srgb::new(220u8, 220u8, 220u8); +#[doc = "
"] +pub const GHOSTWHITE: crate::rgb::Srgb = crate::rgb::Srgb::new(248u8, 248u8, 255u8); +#[doc = "
"] +pub const GOLD: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 215u8, 0u8); +#[doc = "
"] +pub const GOLDENROD: crate::rgb::Srgb = crate::rgb::Srgb::new(218u8, 165u8, 32u8); +#[doc = "
"] +pub const GRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(128u8, 128u8, 128u8); +#[doc = "
"] +pub const GREY: crate::rgb::Srgb = crate::rgb::Srgb::new(128u8, 128u8, 128u8); +#[doc = "
"] +pub const GREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 128u8, 0u8); +#[doc = "
"] +pub const GREENYELLOW: crate::rgb::Srgb = crate::rgb::Srgb::new(173u8, 255u8, 47u8); +#[doc = "
"] +pub const HONEYDEW: crate::rgb::Srgb = crate::rgb::Srgb::new(240u8, 255u8, 240u8); +#[doc = "
"] +pub const HOTPINK: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 105u8, 180u8); +#[doc = "
"] +pub const INDIANRED: crate::rgb::Srgb = crate::rgb::Srgb::new(205u8, 92u8, 92u8); +#[doc = "
"] +pub const INDIGO: crate::rgb::Srgb = crate::rgb::Srgb::new(75u8, 0u8, 130u8); +#[doc = "
"] +pub const IVORY: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 255u8, 240u8); +#[doc = "
"] +pub const KHAKI: crate::rgb::Srgb = crate::rgb::Srgb::new(240u8, 230u8, 140u8); +#[doc = "
"] +pub const LAVENDER: crate::rgb::Srgb = crate::rgb::Srgb::new(230u8, 230u8, 250u8); +#[doc = "
"] +pub const LAVENDERBLUSH: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 240u8, 245u8); +#[doc = "
"] +pub const LAWNGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(124u8, 252u8, 0u8); +#[doc = "
"] +pub const LEMONCHIFFON: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 250u8, 205u8); +#[doc = "
"] +pub const LIGHTBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(173u8, 216u8, 230u8); +#[doc = "
"] +pub const LIGHTCORAL: crate::rgb::Srgb = crate::rgb::Srgb::new(240u8, 128u8, 128u8); +#[doc = "
"] +pub const LIGHTCYAN: crate::rgb::Srgb = crate::rgb::Srgb::new(224u8, 255u8, 255u8); +#[doc = "
"] +pub const LIGHTGOLDENRODYELLOW: crate::rgb::Srgb = crate::rgb::Srgb::new(250u8, 250u8, 210u8); +#[doc = "
"] +pub const LIGHTGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(211u8, 211u8, 211u8); +#[doc = "
"] +pub const LIGHTGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(144u8, 238u8, 144u8); +#[doc = "
"] +pub const LIGHTGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(211u8, 211u8, 211u8); +#[doc = "
"] +pub const LIGHTPINK: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 182u8, 193u8); +#[doc = "
"] +pub const LIGHTSALMON: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 160u8, 122u8); +#[doc = "
"] +pub const LIGHTSEAGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(32u8, 178u8, 170u8); +#[doc = "
"] +pub const LIGHTSKYBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(135u8, 206u8, 250u8); +#[doc = "
"] +pub const LIGHTSLATEGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(119u8, 136u8, 153u8); +#[doc = "
"] +pub const LIGHTSLATEGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(119u8, 136u8, 153u8); +#[doc = "
"] +pub const LIGHTSTEELBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(176u8, 196u8, 222u8); +#[doc = "
"] +pub const LIGHTYELLOW: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 255u8, 224u8); +#[doc = "
"] +pub const LIME: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 255u8, 0u8); +#[doc = "
"] +pub const LIMEGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(50u8, 205u8, 50u8); +#[doc = "
"] +pub const LINEN: crate::rgb::Srgb = crate::rgb::Srgb::new(250u8, 240u8, 230u8); +#[doc = "
"] +pub const MAGENTA: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 0u8, 255u8); +#[doc = "
"] +pub const MAROON: crate::rgb::Srgb = crate::rgb::Srgb::new(128u8, 0u8, 0u8); +#[doc = "
"] +pub const MEDIUMAQUAMARINE: crate::rgb::Srgb = crate::rgb::Srgb::new(102u8, 205u8, 170u8); +#[doc = "
"] +pub const MEDIUMBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 0u8, 205u8); +#[doc = "
"] +pub const MEDIUMORCHID: crate::rgb::Srgb = crate::rgb::Srgb::new(186u8, 85u8, 211u8); +#[doc = "
"] +pub const MEDIUMPURPLE: crate::rgb::Srgb = crate::rgb::Srgb::new(147u8, 112u8, 219u8); +#[doc = "
"] +pub const MEDIUMSEAGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(60u8, 179u8, 113u8); +#[doc = "
"] +pub const MEDIUMSLATEBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(123u8, 104u8, 238u8); +#[doc = "
"] +pub const MEDIUMSPRINGGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 250u8, 154u8); +#[doc = "
"] +pub const MEDIUMTURQUOISE: crate::rgb::Srgb = crate::rgb::Srgb::new(72u8, 209u8, 204u8); +#[doc = "
"] +pub const MEDIUMVIOLETRED: crate::rgb::Srgb = crate::rgb::Srgb::new(199u8, 21u8, 133u8); +#[doc = "
"] +pub const MIDNIGHTBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(25u8, 25u8, 112u8); +#[doc = "
"] +pub const MINTCREAM: crate::rgb::Srgb = crate::rgb::Srgb::new(245u8, 255u8, 250u8); +#[doc = "
"] +pub const MISTYROSE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 228u8, 225u8); +#[doc = "
"] +pub const MOCCASIN: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 228u8, 181u8); +#[doc = "
"] +pub const NAVAJOWHITE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 222u8, 173u8); +#[doc = "
"] +pub const NAVY: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 0u8, 128u8); +#[doc = "
"] +pub const OLDLACE: crate::rgb::Srgb = crate::rgb::Srgb::new(253u8, 245u8, 230u8); +#[doc = "
"] +pub const OLIVE: crate::rgb::Srgb = crate::rgb::Srgb::new(128u8, 128u8, 0u8); +#[doc = "
"] +pub const OLIVEDRAB: crate::rgb::Srgb = crate::rgb::Srgb::new(107u8, 142u8, 35u8); +#[doc = "
"] +pub const ORANGE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 165u8, 0u8); +#[doc = "
"] +pub const ORANGERED: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 69u8, 0u8); +#[doc = "
"] +pub const ORCHID: crate::rgb::Srgb = crate::rgb::Srgb::new(218u8, 112u8, 214u8); +#[doc = "
"] +pub const PALEGOLDENROD: crate::rgb::Srgb = crate::rgb::Srgb::new(238u8, 232u8, 170u8); +#[doc = "
"] +pub const PALEGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(152u8, 251u8, 152u8); +#[doc = "
"] +pub const PALETURQUOISE: crate::rgb::Srgb = crate::rgb::Srgb::new(175u8, 238u8, 238u8); +#[doc = "
"] +pub const PALEVIOLETRED: crate::rgb::Srgb = crate::rgb::Srgb::new(219u8, 112u8, 147u8); +#[doc = "
"] +pub const PAPAYAWHIP: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 239u8, 213u8); +#[doc = "
"] +pub const PEACHPUFF: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 218u8, 185u8); +#[doc = "
"] +pub const PERU: crate::rgb::Srgb = crate::rgb::Srgb::new(205u8, 133u8, 63u8); +#[doc = "
"] +pub const PINK: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 192u8, 203u8); +#[doc = "
"] +pub const PLUM: crate::rgb::Srgb = crate::rgb::Srgb::new(221u8, 160u8, 221u8); +#[doc = "
"] +pub const POWDERBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(176u8, 224u8, 230u8); +#[doc = "
"] +pub const PURPLE: crate::rgb::Srgb = crate::rgb::Srgb::new(128u8, 0u8, 128u8); +#[doc = "
"] +pub const REBECCAPURPLE: crate::rgb::Srgb = crate::rgb::Srgb::new(102u8, 51u8, 153u8); +#[doc = "
"] +pub const RED: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 0u8, 0u8); +#[doc = "
"] +pub const ROSYBROWN: crate::rgb::Srgb = crate::rgb::Srgb::new(188u8, 143u8, 143u8); +#[doc = "
"] +pub const ROYALBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(65u8, 105u8, 225u8); +#[doc = "
"] +pub const SADDLEBROWN: crate::rgb::Srgb = crate::rgb::Srgb::new(139u8, 69u8, 19u8); +#[doc = "
"] +pub const SALMON: crate::rgb::Srgb = crate::rgb::Srgb::new(250u8, 128u8, 114u8); +#[doc = "
"] +pub const SANDYBROWN: crate::rgb::Srgb = crate::rgb::Srgb::new(244u8, 164u8, 96u8); +#[doc = "
"] +pub const SEAGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(46u8, 139u8, 87u8); +#[doc = "
"] +pub const SEASHELL: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 245u8, 238u8); +#[doc = "
"] +pub const SIENNA: crate::rgb::Srgb = crate::rgb::Srgb::new(160u8, 82u8, 45u8); +#[doc = "
"] +pub const SILVER: crate::rgb::Srgb = crate::rgb::Srgb::new(192u8, 192u8, 192u8); +#[doc = "
"] +pub const SKYBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(135u8, 206u8, 235u8); +#[doc = "
"] +pub const SLATEBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(106u8, 90u8, 205u8); +#[doc = "
"] +pub const SLATEGRAY: crate::rgb::Srgb = crate::rgb::Srgb::new(112u8, 128u8, 144u8); +#[doc = "
"] +pub const SLATEGREY: crate::rgb::Srgb = crate::rgb::Srgb::new(112u8, 128u8, 144u8); +#[doc = "
"] +pub const SNOW: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 250u8, 250u8); +#[doc = "
"] +pub const SPRINGGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 255u8, 127u8); +#[doc = "
"] +pub const STEELBLUE: crate::rgb::Srgb = crate::rgb::Srgb::new(70u8, 130u8, 180u8); +#[doc = "
"] +pub const TAN: crate::rgb::Srgb = crate::rgb::Srgb::new(210u8, 180u8, 140u8); +#[doc = "
"] +pub const TEAL: crate::rgb::Srgb = crate::rgb::Srgb::new(0u8, 128u8, 128u8); +#[doc = "
"] +pub const THISTLE: crate::rgb::Srgb = crate::rgb::Srgb::new(216u8, 191u8, 216u8); +#[doc = "
"] +pub const TOMATO: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 99u8, 71u8); +#[doc = "
"] +pub const TURQUOISE: crate::rgb::Srgb = crate::rgb::Srgb::new(64u8, 224u8, 208u8); +#[doc = "
"] +pub const VIOLET: crate::rgb::Srgb = crate::rgb::Srgb::new(238u8, 130u8, 238u8); +#[doc = "
"] +pub const WHEAT: crate::rgb::Srgb = crate::rgb::Srgb::new(245u8, 222u8, 179u8); +#[doc = "
"] +pub const WHITE: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 255u8, 255u8); +#[doc = "
"] +pub const WHITESMOKE: crate::rgb::Srgb = crate::rgb::Srgb::new(245u8, 245u8, 245u8); +#[doc = "
"] +pub const YELLOW: crate::rgb::Srgb = crate::rgb::Srgb::new(255u8, 255u8, 0u8); +#[doc = "
"] +pub const YELLOWGREEN: crate::rgb::Srgb = crate::rgb::Srgb::new(154u8, 205u8, 50u8); + +#[cfg(feature = "named_from_str")] +pub(crate) static COLORS: ::phf::Map<&'static str, crate::rgb::Srgb> = phf::phf_map! { "aliceblue" => ALICEBLUE , "antiquewhite" => ANTIQUEWHITE , "aqua" => AQUA , "aquamarine" => AQUAMARINE , "azure" => AZURE , "beige" => BEIGE , "bisque" => BISQUE , "black" => BLACK , "blanchedalmond" => BLANCHEDALMOND , "blue" => BLUE , "blueviolet" => BLUEVIOLET , "brown" => BROWN , "burlywood" => BURLYWOOD , "cadetblue" => CADETBLUE , "chartreuse" => CHARTREUSE , "chocolate" => CHOCOLATE , "coral" => CORAL , "cornflowerblue" => CORNFLOWERBLUE , "cornsilk" => CORNSILK , "crimson" => CRIMSON , "cyan" => CYAN , "darkblue" => DARKBLUE , "darkcyan" => DARKCYAN , "darkgoldenrod" => DARKGOLDENROD , "darkgray" => DARKGRAY , "darkgreen" => DARKGREEN , "darkgrey" => DARKGREY , "darkkhaki" => DARKKHAKI , "darkmagenta" => DARKMAGENTA , "darkolivegreen" => DARKOLIVEGREEN , "darkorange" => DARKORANGE , "darkorchid" => DARKORCHID , "darkred" => DARKRED , "darksalmon" => DARKSALMON , "darkseagreen" => DARKSEAGREEN , "darkslateblue" => DARKSLATEBLUE , "darkslategray" => DARKSLATEGRAY , "darkslategrey" => DARKSLATEGREY , "darkturquoise" => DARKTURQUOISE , "darkviolet" => DARKVIOLET , "deeppink" => DEEPPINK , "deepskyblue" => DEEPSKYBLUE , "dimgray" => DIMGRAY , "dimgrey" => DIMGREY , "dodgerblue" => DODGERBLUE , "firebrick" => FIREBRICK , "floralwhite" => FLORALWHITE , "forestgreen" => FORESTGREEN , "fuchsia" => FUCHSIA , "gainsboro" => GAINSBORO , "ghostwhite" => GHOSTWHITE , "gold" => GOLD , "goldenrod" => GOLDENROD , "gray" => GRAY , "grey" => GREY , "green" => GREEN , "greenyellow" => GREENYELLOW , "honeydew" => HONEYDEW , "hotpink" => HOTPINK , "indianred" => INDIANRED , "indigo" => INDIGO , "ivory" => IVORY , "khaki" => KHAKI , "lavender" => LAVENDER , "lavenderblush" => LAVENDERBLUSH , "lawngreen" => LAWNGREEN , "lemonchiffon" => LEMONCHIFFON , "lightblue" => LIGHTBLUE , "lightcoral" => LIGHTCORAL , "lightcyan" => LIGHTCYAN , "lightgoldenrodyellow" => LIGHTGOLDENRODYELLOW , "lightgray" => LIGHTGRAY , "lightgreen" => LIGHTGREEN , "lightgrey" => LIGHTGREY , "lightpink" => LIGHTPINK , "lightsalmon" => LIGHTSALMON , "lightseagreen" => LIGHTSEAGREEN , "lightskyblue" => LIGHTSKYBLUE , "lightslategray" => LIGHTSLATEGRAY , "lightslategrey" => LIGHTSLATEGREY , "lightsteelblue" => LIGHTSTEELBLUE , "lightyellow" => LIGHTYELLOW , "lime" => LIME , "limegreen" => LIMEGREEN , "linen" => LINEN , "magenta" => MAGENTA , "maroon" => MAROON , "mediumaquamarine" => MEDIUMAQUAMARINE , "mediumblue" => MEDIUMBLUE , "mediumorchid" => MEDIUMORCHID , "mediumpurple" => MEDIUMPURPLE , "mediumseagreen" => MEDIUMSEAGREEN , "mediumslateblue" => MEDIUMSLATEBLUE , "mediumspringgreen" => MEDIUMSPRINGGREEN , "mediumturquoise" => MEDIUMTURQUOISE , "mediumvioletred" => MEDIUMVIOLETRED , "midnightblue" => MIDNIGHTBLUE , "mintcream" => MINTCREAM , "mistyrose" => MISTYROSE , "moccasin" => MOCCASIN , "navajowhite" => NAVAJOWHITE , "navy" => NAVY , "oldlace" => OLDLACE , "olive" => OLIVE , "olivedrab" => OLIVEDRAB , "orange" => ORANGE , "orangered" => ORANGERED , "orchid" => ORCHID , "palegoldenrod" => PALEGOLDENROD , "palegreen" => PALEGREEN , "paleturquoise" => PALETURQUOISE , "palevioletred" => PALEVIOLETRED , "papayawhip" => PAPAYAWHIP , "peachpuff" => PEACHPUFF , "peru" => PERU , "pink" => PINK , "plum" => PLUM , "powderblue" => POWDERBLUE , "purple" => PURPLE , "rebeccapurple" => REBECCAPURPLE , "red" => RED , "rosybrown" => ROSYBROWN , "royalblue" => ROYALBLUE , "saddlebrown" => SADDLEBROWN , "salmon" => SALMON , "sandybrown" => SANDYBROWN , "seagreen" => SEAGREEN , "seashell" => SEASHELL , "sienna" => SIENNA , "silver" => SILVER , "skyblue" => SKYBLUE , "slateblue" => SLATEBLUE , "slategray" => SLATEGRAY , "slategrey" => SLATEGREY , "snow" => SNOW , "springgreen" => SPRINGGREEN , "steelblue" => STEELBLUE , "tan" => TAN , "teal" => TEAL , "thistle" => THISTLE , "tomato" => TOMATO , "turquoise" => TURQUOISE , "violet" => VIOLET , "wheat" => WHEAT , "white" => WHITE , "whitesmoke" => WHITESMOKE , "yellow" => YELLOW , "yellowgreen" => YELLOWGREEN }; +