parser/
parser.rs

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
use colorparser_css::{Color, ColorspaceImpl};

fn main() {
    let test_case = [
        "rgb(137, 180, 250)",
        "#89B4FA",
        "rgba(137, 180, 250, 1)",
        "hsla(217.16815, 91.869934%, 75.882355%, 1)",
        "gradient(rgb(137, 180, 250), rgb(203, 166, 247))",
    ];

    let other_test = "darken(rgb(137, 180, 250), 5%)";

    println!(
        "{}",
        Color::from_html(other_test)
            .unwrap()
            .to_solid()
            .unwrap()
            .to_rgba()
    );

    for s in test_case {
        let a = Color::from_html(s).unwrap();

        if let Ok(solid) = a.to_solid() {
            let rgba = solid.to_rgba();
            let darken_rgba = rgba.darken(5.0);
            let darken_solid = solid.darken(5.0).to_rgba();

            println!("RGBA: {rgba}");
            println!("Darken RGBA: {darken_rgba}");
            println!("Darken Solid RGBA: {darken_solid}");
        } else if let Ok(gradient) = a.to_gradient() {
            println!("{gradient}");
        }
    }
}