Skip to content

feat: use cssparser => csscolorparser #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading