Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(paint): restore Muse pill corners and SVG colors

ldm0778a35bd072a
diff --git a/Cargo.lock b/Cargo.lock
index 41ce3a7d2..b6ab4a2a0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5476,8 +5476,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "svgtypes"
version = "0.16.1"
-source = "git+https://github.com/lexmount/svgtypes?branch=feat%2Fstrict-path-numbers#173b361d4b0711829748befdde382228e6ab8095"
+source = "git+https://github.com/lexmount/svgtypes?branch=moli#e96c74ca675d56b65de71b4ce2b2d87f927bf79c"
dependencies = [
+ "color",
"kurbo",
"siphasher",
]
diff --git a/Cargo.toml b/Cargo.toml
index 94d1d8ead..ce1970d8f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -116,7 +116,7 @@ stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b671
stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "0c7e8baf63b6714e7614834fadbc09710f3c3d27" }
-svgtypes = { git = "https://github.com/lexmount/svgtypes", branch = "feat/strict-path-numbers" }
+svgtypes = { git = "https://github.com/lexmount/svgtypes", branch = "moli" }
taffy = { git = "https://github.com/ldm0/taffy", rev = "645bf5a49df607a8bff34ec90c5343901d04f10e" }
[workspace.lints.clippy]
diff --git a/moli-image/src/svg.rs b/moli-image/src/svg.rs
index 987f34630..e1e65c2fc 100644
--- a/moli-image/src/svg.rs
+++ b/moli-image/src/svg.rs
@@ -444,6 +444,45 @@ mod tests {
assert_eq!(svg.tree().size().height(), 10.0);
}
+ #[test]
+ fn css_color4_gradient_stops_preserve_style_precedence_and_alpha() {
+ let svg = decode_svg_image(
+ br##"<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10">
+ <defs><linearGradient id="paint">
+ <stop offset="0" stop-color="#00ff00" style="stop-color:#ff0000;stop-color:color(display-p3 .5 0 0 / .5);stop-opacity:.5"/>
+ <stop offset="1" stop-color="color(display-p3 0 0 1)"/>
+ </linearGradient></defs>
+ <rect width="20" height="10" fill="url(#paint)"/>
+ </svg>"##,
+ )
+ .unwrap();
+ let stops = svg.tree().linear_gradients()[0].stops();
+ assert_eq!(stops.len(), 2);
+ assert_eq!(stops[0].color(), usvg::Color::new_rgb(140, 0, 0));
+ assert!((stops[0].opacity().get() - 128.0 / 255.0 * 0.5).abs() < 1e-6);
+ assert_eq!(stops[1].color(), usvg::Color::new_rgb(0, 0, 255));
+ }
+
+ #[test]
+ fn css_color4_stylesheet_colors_preserve_current_color_inheritance() {
+ let rules = "stop { stop-color: color(display-p3 .5 0 0); } .endpoint { stop-color: currentColor; color: color(display-p3 0 0 1); }";
+ for stylesheet in [rules.to_owned(), format!("<![CDATA[{rules}]]>")] {
+ let source = format!(
+ r##"<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10">
+ <style>{stylesheet}</style>
+ <defs><linearGradient id="paint">
+ <stop offset="0"/><stop class="endpoint" offset="1"/>
+ </linearGradient></defs>
+ <rect width="20" height="10" fill="url(#paint)"/>
+ </svg>"##
+ );
+ let svg = decode_svg_image(source.as_bytes()).unwrap();
+ let stops = svg.tree().linear_gradients()[0].stops();
+ assert_eq!(stops[0].color(), usvg::Color::new_rgb(140, 0, 0));
+ assert_eq!(stops[1].color(), usvg::Color::new_rgb(0, 0, 255));
+ }
+ }
+
#[test]
fn vector_work_budget_includes_definition_subtrees() {
let svg = decode_svg_image(
diff --git a/moli-paint/src/raster/mod.rs b/moli-paint/src/raster/mod.rs
index c938305d9..eb61199f2 100644
--- a/moli-paint/src/raster/mod.rs
+++ b/moli-paint/src/raster/mod.rs
@@ -1930,30 +1930,35 @@ fn normalize_radii(radii: PaintCornerRadii, rect_width: f64, rect_height: f64) -
bottom_right: sanitize_radius(radii.bottom_right),
bottom_left: sanitize_radius(radii.bottom_left),
};
+ // Tailwind's rounded-full can resolve to f32::MAX. Promote before adding
+ // corner pairs so their sum cannot overflow and collapse the scale to zero.
let factors = [
- ratio(rect_width, f64::from(radii.top_left.x + radii.top_right.x)),
ratio(
rect_width,
- f64::from(radii.bottom_left.x + radii.bottom_right.x),
+ f64::from(radii.top_left.x) + f64::from(radii.top_right.x),
+ ),
+ ratio(
+ rect_width,
+ f64::from(radii.bottom_left.x) + f64::from(radii.bottom_right.x),
),
ratio(
rect_height,
- f64::from(radii.top_left.y + radii.bottom_left.y),
+ f64::from(radii.top_left.y) + f64::from(radii.bottom_left.y),
),
ratio(
rect_height,
- f64::from(radii.top_right.y + radii.bottom_right.y),
+ f64::from(radii.top_right.y) + f64::from(radii.bottom_right.y),
),
];
- let factor = factors.into_iter().fold(1.0_f64, f64::min).min(1.0) as f32;
+ let factor = factors.into_iter().fold(1.0_f64, f64::min).min(1.0);
for radius in [
&mut radii.top_left,
&mut radii.top_right,
&mut radii.bottom_right,
&mut radii.bottom_left,
] {
- radius.x *= factor;
- radius.y *= factor;
+ radius.x = (f64::from(radius.x) * factor) as f32;
+ radius.y = (f64::from(radius.y) * factor) as f32;
}
radii
}
@@ -2147,6 +2152,44 @@ mod tests {
PaintSnapshot::new(PaintViewport::new(width, height, scale), PaintColor::WHITE)
}
+ #[test]
+ fn maximum_corner_radii_preserve_pill_shapes_at_normal_and_subpixel_sizes() {
+ let radii = PaintCornerRadii::all(PaintCornerRadius::new(f32::MAX, f32::MAX));
+ for (width, height) in [(120.0, 40.0), (3e-6, 1e-6)] {
+ let normalized = normalize_radii(radii, width, height);
+ for radius in [
+ normalized.top_left,
+ normalized.top_right,
+ normalized.bottom_right,
+ normalized.bottom_left,
+ ] {
+ let expected = height / 2.0;
+ assert!((f64::from(radius.x) / expected - 1.0).abs() < 1e-6);
+ assert!((f64::from(radius.y) / expected - 1.0).abs() < 1e-6);
+ }
+ }
+ }
+
+ #[test]
+ fn maximum_corner_radii_leave_pill_corners_unpainted() {
+ let mut snapshot = snapshot(120, 40, 1.0);
+ snapshot.push_fragment(PaintFragment::Fill {
+ shape: PaintShape::RoundedRect {
+ rect: PaintRect::new(0.0, 0.0, 120.0, 40.0),
+ radii: PaintCornerRadii::all(PaintCornerRadius::new(f32::MAX, f32::MAX)),
+ },
+ brush: PaintBrush::Solid(PaintColor::new(0.0, 0.0, 1.0, 1.0)),
+ transform: PaintTransform2D::IDENTITY,
+ });
+
+ let image = raster_snapshot(&snapshot).expect("pill fill should rasterize");
+ for (x, y) in [(0, 0), (119, 0), (0, 39), (119, 39)] {
+ assert_eq!(pixel(&image, x, y), [255, 255, 255, 255]);
+ }
+ assert_eq!(pixel(&image, 60, 0), [0, 0, 255, 255]);
+ assert_eq!(pixel(&image, 60, 20), [0, 0, 255, 255]);
+ }
+
#[test]
fn rejects_zero_dimensions_before_backend_creation() {
assert_eq!(