1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! # `base16cs`
//!
//! A library for defining a **palette** of **base colors** in canonical CIE
//! L\*a\*b\* colorspace values, and then deriving other colorspace values from
//! them.
//!
//! This library also provides serializers and deserializers for palettes, and
//! a template renderer (Liquid, by default) for injecting palette and color
//! variables into a template for renders.
//!
//! ## Examples
//!
//! ### Defining a base palette and deriving computed color values
//!
//! ```rust
//! use base16cs::{Palette, BaseColor, DerivedPalette};
//!
//! // Define a canonical palette
//! let palette = Palette::new(
//!     "My Palette",
//!     [
//!         BaseColor::new("bg", 96, 0, 13),
//!         BaseColor::new("fg", 31, -6, -6),
//!     ]);
//!
//! // Derive with computed sRGB values
//! let derived_palette = DerivedPalette::from(&palette);
//! assert_eq!(derived_palette.name, "My Palette");
//!
//! let derived_colors = &derived_palette.colors;
//! assert_eq!(derived_colors[0].base, &palette.colors[0]);
//! assert_eq!(derived_colors[1].base, &palette.colors[1]);
//!
//! assert_eq!(derived_colors[0].srgb_hex, "fef3da");
//! assert_eq!(derived_colors[1].srgb_hex, "384c52");
//! ```
//!
//! ### Serializing and deserializing a palette (YAML)
//!
//! This crate is compiled with YAML serde by default.
//!
//! ```rust
//! # use base16cs::{Palette, BaseColor, DerivedPalette};
//! use base16cs::Serializable;
//!
//! # let palette = Palette::new(
//! #     "My Palette",
//! #     [
//! #         BaseColor::new("bg", 96, 0, 13),
//! #         BaseColor::new("fg", 31, -6, -6),
//! #     ]);
//!
//! # let derived_palette = DerivedPalette::from(&palette);
//! let serialized = derived_palette.serialize().unwrap();
//! assert_eq!(serialized, r#"name: My Palette
//! colors:
//! - base:
//!     name: bg
//!     lab:
//!       l: 96.0
//!       a: 0.0
//!       b: 13.0
//!   srgb:
//!     red: 254
//!     green: 243
//!     blue: 218
//!   srgb_hex: fef3da
//! - base:
//!     name: fg
//!     lab:
//!       l: 31.0
//!       a: -6.0
//!       b: -6.0
//!   srgb:
//!     red: 56
//!     green: 76
//!     blue: 82
//!   srgb_hex: 384c52
//! "#);
//! ```
//!
//! Deserialization is always done from a *base* palette, since its derived form
//! can be re-computed at runtime.
//!
//! ```rust
//! # use base16cs::{Palette, BaseColor};
//! # use base16cs::Serializable;
//!
//! # let palette = Palette::new(
//! #     "My Palette",
//! #     [
//! #         BaseColor::new("bg", 96, 0, 13),
//! #         BaseColor::new("fg", 31, -6, -6),
//! #     ]);
//!
//! let yaml_str = r#"
//! name: My Palette
//! colors:
//! - name: bg
//!   lab:
//!     l: 96.0
//!     a: 0.0
//!     b: 13.0
//! - name: fg
//!   lab:
//!     l: 31.0
//!     a: -6.0
//!     b: -6.0
//! "#;
//!
//! let de_palette = Palette::<2>::from_yaml(yaml_str).unwrap();
//! assert_eq!(de_palette, palette);
//! ```
//!
//! ### Injecting a palette into a template for render
//!
//! See: [`template`](template/mod.rs) module.

mod palette;
mod serialize;
mod template;

pub use palette::Base16Colors;
pub use palette::Base16DerivedColors;
pub use palette::Base16DerivedPalette;
pub use palette::Base16Palette;
pub use palette::BaseColor;
pub use palette::DerivedColor;
pub use palette::DerivedPalette;
pub use palette::Palette;

pub use serialize::yaml;
pub use serialize::Serializable;

pub use template::liquid;
pub use template::PaletteRenderer;
pub use template::RenderOptions;