Skip to content

Commit

Permalink
feat: use cssparser => csscolorparser (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright authored Aug 14, 2024
1 parent 8d0cf81 commit 8a00108
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion soft-skia-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.5.0"
wasm-bindgen = "0.2.63"
base64 = "0.21.0"
cssparser = "0.29"
csscolorparser = "0.7.0"
soft_skia = { path = "../soft-skia" }

# The `console_error_panic_hook` crate provides better debugging of panics by
Expand Down
15 changes: 4 additions & 11 deletions soft-skia-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use soft_skia::shape::Rect;
use soft_skia::shape::{Circle, Image, Line, PaintStyle, Points, RoundRect, Shapes, Text};
use soft_skia::tree::Node;
use wasm_bindgen::prelude::*;

use cssparser::{Color as CSSColor, Parser, ParserInput};
use csscolorparser;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
Expand Down Expand Up @@ -457,15 +456,9 @@ impl SoftSkiaWASM {

fn parse_color(color: Option<String>) -> Option<ColorU8> {
if let Some(color_str) = color {
let mut parser_input = ParserInput::new(&color_str);
let mut parser = Parser::new(&mut parser_input);

if let Ok(css_color) = CSSColor::parse(&mut parser) {
if let CSSColor::RGBA(rgba) = css_color {
return Some(ColorU8::from_rgba(
rgba.red, rgba.green, rgba.blue, rgba.alpha,
));
}
if let Ok(css_color) = csscolorparser::parse(&color_str) {
let css_rgba8 = css_color.to_rgba8();
return Some(ColorU8::from_rgba(css_rgba8[0], css_rgba8[1], css_rgba8[2], css_rgba8[3]))
}
}
None
Expand Down

0 comments on commit 8a00108

Please sign in to comment.