Skip to content

Commit 6de90d5

Browse files
committed
color: Expose hsl/hwb to rgb functions.
I'm going to use this for color-mix() support.
1 parent 4759651 commit 6de90d5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.29.4"
3+
version = "0.29.5"
44
authors = [ "Simon Sapin <[email protected]>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/color.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ where
666666

667667
/// https://drafts.csswg.org/css-color-4/#hwb-to-rgb
668668
#[inline]
669-
fn hwb_to_rgb(h: f32, w: f32, b: f32) -> (f32, f32, f32) {
669+
pub fn hwb_to_rgb(h: f32, w: f32, b: f32) -> (f32, f32, f32) {
670670
if w + b >= 1.0 {
671671
let gray = w / (w + b);
672672
return (gray, gray, gray);
@@ -683,15 +683,14 @@ fn hwb_to_rgb(h: f32, w: f32, b: f32) -> (f32, f32, f32) {
683683
/// https://drafts.csswg.org/css-color/#hsl-color
684684
/// except with h pre-multiplied by 3, to avoid some rounding errors.
685685
#[inline]
686-
fn hsl_to_rgb(hue: f32, saturation: f32, lightness: f32) -> (f32, f32, f32) {
686+
pub fn hsl_to_rgb(hue: f32, saturation: f32, lightness: f32) -> (f32, f32, f32) {
687687
fn hue_to_rgb(m1: f32, m2: f32, mut h3: f32) -> f32 {
688688
if h3 < 0. {
689689
h3 += 3.
690690
}
691691
if h3 > 3. {
692692
h3 -= 3.
693693
}
694-
695694
if h3 * 2. < 1. {
696695
m1 + (m2 - m1) * h3 * 2.
697696
} else if h3 * 2. < 3. {

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6868
#![recursion_limit = "200"] // For color::parse_color_keyword
6969

7070
pub use crate::color::{
71-
parse_color_keyword, AngleOrNumber, Color, ColorComponentParser, NumberOrPercentage, RGBA,
71+
hsl_to_rgb, hwb_to_rgb, parse_color_keyword, AngleOrNumber, Color, ColorComponentParser,
72+
NumberOrPercentage, RGBA,
7273
};
7374
pub use crate::cow_rc_str::CowRcStr;
7475
pub use crate::from_bytes::{stylesheet_encoding, EncodingSupport};

0 commit comments

Comments
 (0)