The design language that makes your AI harness better at design.
JavaScript
File scans treat a flex or grid initial as centred only when it is
Paul Bakaus76551384bf09
diff --git a/crates/html/src/cascade/rules.rs b/crates/html/src/cascade/rules.rsindex 7865e7ae3..712a2d34b 100644--- a/crates/html/src/cascade/rules.rs+++ b/crates/html/src/cascade/rules.rs@@ -257,6 +257,8 @@ fn extra_specified_expansions(prop: &str, value: &str) -> Vec<Expanded> {"flex-direction" => vec![("flexDirection".into(), v.to_string())],"align-items" => vec![("alignItems".into(), v.to_string())],"align-self" => vec![("alignSelf".into(), v.to_string())],+ "justify-content" => vec![("justifyContent".into(), v.to_string())],+ "justify-items" => vec![("justifyItems".into(), v.to_string())],// `var()` and CSS-wide keywords resolve later, per longhand; the// stripe adapter picks the keyword out of the resolved list."flex-flow" | "place-items" | "place-self"@@ -286,11 +288,24 @@ fn extra_specified_expansions(prop: &str, value: &str) -> Vec<Expanded> {.unwrap_or_else(|| "row".to_string());vec![("flexDirection".into(), direction)]}- "place-items" => split_css_tokens(v)- .into_iter()- .next()- .map(|t| vec![("alignItems".into(), t)])- .unwrap_or_default(),+ // `place-items: <align> [<justify>]`, one value setting both.+ "place-items" => {+ let tokens = split_css_tokens(v);+ match tokens.first() {+ Some(align) => {+ let justify = tokens.get(1).unwrap_or(align).clone();+ vec![("alignItems".into(), align.clone()), ("justifyItems".into(), justify)]+ }+ None => Vec::new(),+ }+ }+ "place-content" => {+ let tokens = split_css_tokens(v);+ match tokens.get(1).or(tokens.first()) {+ Some(justify) => vec![("justifyContent".into(), justify.clone())],+ None => Vec::new(),+ }+ }"place-self" => split_css_tokens(v).into_iter().next()diff --git a/crates/html/src/decorative_text.rs b/crates/html/src/decorative_text.rsindex 02383bad3..d3d5659eb 100644--- a/crates/html/src/decorative_text.rs+++ b/crates/html/src/decorative_text.rs@@ -88,7 +88,17 @@ fn box_paints(el: &StaticElement<'_>) -> bool {fn centred(host: &StaticElement<'_>, el: &StaticElement<'_>, height: f64) -> bool {let style = host.style();let display = sv(style, "display");- if matches!(display, "flex" | "inline-flex" | "grid" | "inline-grid") {+ // A flex or grid box centres its text only when it says so on both axes:+ // `justify-content: flex-start` or `align-items: flex-start` leaves an+ // initial in a corner of the painted box.+ let is_center = |prop: &str| js::to_lower_case(sv(style, prop)).split_whitespace().any(|t| t == "center");+ if matches!(display, "flex" | "inline-flex") && is_center("justifyContent") && is_center("alignItems") {+ return true;+ }+ if matches!(display, "grid" | "inline-grid")+ && is_center("alignItems")+ && (is_center("justifyItems") || is_center("justifyContent"))+ {return true;}if sv(el.style(), "textAlign") == "center" || sv(style, "textAlign") == "center" {diff --git a/crates/html/tests/low_contrast_advisory.rs b/crates/html/tests/low_contrast_advisory.rsindex f31522afe..310dca081 100644--- a/crates/html/tests/low_contrast_advisory.rs+++ b/crates/html/tests/low_contrast_advisory.rs@@ -156,6 +156,27 @@ fn an_advisory_copy_never_speaks_for_a_failing_one() {assert_failing(&findings[1]);}+#[test]+fn an_initial_is_decorative_only_when_its_box_centres_it() {+ let scan_box = |layout: &str| {+ let html = format!(+ r##"<!DOCTYPE html><html><head><style>+ body {{ background: #ffffff; }}+ .av {{ {layout} width: 40px; height: 40px; border-radius: 50%; color: #bbbbbb; font-size: 14px; border: 1px solid #bbbbbb; }}+ </style></head><body><span class="av">JD</span></body></html>"##+ );+ let findings = scan(&html);+ assert_eq!(findings.len(), 1, "{layout}: {findings:#?}");+ findings[0].severity.clone()+ };+ assert_eq!(scan_box("display: flex; align-items: center; justify-content: center;"), "advisory");+ assert_eq!(scan_box("display: grid; place-items: center;"), "advisory");+ // A flex or grid box that leaves the initial in a corner.+ assert_eq!(scan_box("display: flex; align-items: center; justify-content: flex-start;"), "warning");+ assert_eq!(scan_box("display: flex; align-items: flex-start; justify-content: center;"), "warning");+ assert_eq!(scan_box("display: grid;"), "warning");+}+#[test]fn a_failing_copy_first_hides_later_advisory_copies() {let html = r##"<!DOCTYPE html><html><head><style>