Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(layout): preserve intrinsic width keywords across inline formatting roles

ldm087e044db18dd
diff --git a/moli-layout/src/intrinsic.rs b/moli-layout/src/intrinsic.rs
index 6c4d3e1f9..83aa88c0c 100644
--- a/moli-layout/src/intrinsic.rs
+++ b/moli-layout/src/intrinsic.rs
@@ -81,7 +81,7 @@ where
let preferred_width = layout_box.style.taffy.size.width;
let is_replaced = layout_box.is_replaced();
let uses_fit_content = !layout_box.is_replaced()
- && layout_box.style.taffy.size.width.is_auto()
+ && (preferred_width.is_auto() || preferred_width.is_fit_content())
&& matches!(
layout_box.style.display(),
LayoutDisplay::InlineBlock
diff --git a/moli-layout/src/taffy_tree.rs b/moli-layout/src/taffy_tree.rs
index 498c5baa9..ac673a63e 100644
--- a/moli-layout/src/taffy_tree.rs
+++ b/moli-layout/src/taffy_tree.rs
@@ -2915,10 +2915,20 @@ where
// All floats receive the space remaining after horizontal
// margins, matching Taffy's block-float parent. Replaced
// measurement carries this ownership explicitly.
+ let available_width = if style.size.width.is_min_content() {
+ AvailableSpace::MinContent
+ } else if style.size.width.is_max_content() {
+ AvailableSpace::MaxContent
+ } else {
+ child_inputs
+ .available_space
+ .width
+ .maybe_sub(margin.left + margin.right)
+ };
let layout_inputs = LayoutInput {
available_space: child_inputs
.available_space
- .map_width(|width| width.maybe_sub(margin.left + margin.right)),
+ .map_width(|_| available_width),
..child_inputs
};
let output = self.compute_child_layout(child.to_taffy(), layout_inputs);
diff --git a/moli/tests/fetch_cli/layout_regressions.rs b/moli/tests/fetch_cli/layout_regressions.rs
index de167f960..f6934b287 100644
--- a/moli/tests/fetch_cli/layout_regressions.rs
+++ b/moli/tests/fetch_cli/layout_regressions.rs
@@ -184,3 +184,33 @@ fn flex_percentage_padding_keeps_the_text_content_width_before_line_breaking() -
}
Ok(())
}
+
+#[test]
+fn intrinsic_width_keywords_keep_margin_space_for_float_and_inline_roles() -> Result<()> {
+ let mut body = String::new();
+ for role in ["float", "inline"] {
+ for (keyword, _) in [
+ ("min-content", 46.0),
+ ("fit-content", 70.0),
+ ("max-content", 94.0),
+ ] {
+ let display = if role == "float" {
+ "float:left"
+ } else {
+ "display:inline-block"
+ };
+ body.push_str(&format!("<section style='width:80px;height:100px'><div id='{role}-{keyword}' style='{display};width:{keyword};margin:5px;padding:2px;border:3px solid'>aaa bbb</div><br></section>"));
+ }
+ }
+ let value = run_layout(&probe_font_document(&body), GEOMETRY, true)?;
+ for role in ["float", "inline"] {
+ for (keyword, width) in [
+ ("min-content", 46.0),
+ ("fit-content", 70.0),
+ ("max-content", 94.0),
+ ] {
+ assert_dimension(&value, &format!("{role}-{keyword}"), "width", width);
+ }
+ }
+ Ok(())
+}