The design language that makes your AI harness better at design.
JavaScript
Narrow the card-title and dropped-role exemptions after the ratchet
Paul Bakaus1d6c3a42fcc2
diff --git a/crates/browser/tests/card_heuristics.rs b/crates/browser/tests/card_heuristics.rsindex 5ed926bfd..7bde47bc3 100644--- a/crates/browser/tests/card_heuristics.rs+++ b/crates/browser/tests/card_heuristics.rs@@ -312,7 +312,8 @@ fn label_collectors_climb_and_scale() {"A Single Kicker Still Flags","Relative Kicker Ceiling","Eyebrow In A Framer Wrapper",- "Label In A Tall Panel",+ "Section Title In A Panel",+ "Display Title In A Band",],&["Label Too Large For Its Heading", "Untracked Caps Label", "Press Card Source"],);diff --git a/crates/core/src/browser/text_collectors.rs b/crates/core/src/browser/text_collectors.rsindex 6801441e8..1aa88145e 100644--- a/crates/core/src/browser/text_collectors.rs+++ b/crates/core/src/browser/text_collectors.rs@@ -13,7 +13,7 @@ use crate::checks::rules::{check_kicker_above_heading, KickerCandidate, RuleHit}use crate::checks::text_rules::{check_em_dash_overuse, check_numbered_section_labels, is_kicker_candidate,is_numbered_section_label_candidate, is_repeated_text_container, parse_numbered_label_text,- strip_edge_quotes, HEADING_TAGS, KICKER_CARD_CONTEXT_SELECTOR, KICKER_SKIP_SELECTOR,+ strip_edge_quotes, HEADING_TAGS, KICKER_CARD_CONTEXT_SELECTOR, KICKER_SKIP_SELECTOR, LEADING_DISPLAY_TYPE_PX,KickerCandidateInput, NumberedLabelCandidate, NumberedLabelCandidateInput,REPEATED_TEXT_CONTAINER_TAGS, REPEATED_TEXT_SKIP_SELECTOR,};@@ -55,8 +55,14 @@ pub fn is_kicker_card_context(dom: &dyn Dom, heading: ElId, kicker: ElId) -> boo/// the computed box), shorter than the viewport, whatever its tag. A label in/// a card beside its title is the card's metadata, as it is in an `article`/// or `li` card: aina-tech.io's white press card names its source ("The-/// Future Media") over the headline in a `div`.+/// Future Media") over its 20px h3 headline in a `div`. Only a card title+/// counts: an h3 or lower set under display size. A section's own heading in+/// a painted panel (redoubt.agency's h2 in the hero's side panel,+/// vestra.ai's 40px h3 across a feature band) keeps its eyebrow reported.fn kicker_in_painted_card(dom: &dyn Dom, heading: ElId, kicker: ElId) -> bool {+ if kicker_heading_level(dom, heading) < 3.0 || font_size_of(dom, heading) >= LEADING_DISPLAY_TYPE_PX {+ return false;+ }let viewport = {let h = dom.inner_height();if num_truthy(h) {diff --git a/crates/core/src/checks/rules.rs b/crates/core/src/checks/rules.rsindex 571b5192e..3e2241e3c 100644--- a/crates/core/src/checks/rules.rs+++ b/crates/core/src/checks/rules.rs@@ -1955,25 +1955,26 @@ pub fn check_flat_type_hierarchy_samples(samples: &[TypeSample]) -> Vec<RuleHit>}// The ladder is read from the roles whose size the samples settle. When- // the heading level a page uses most has no dominant size (cnnbrasil.com.br- // sets its thirty h3s at 14, 16 and 20px, ten each), the ladder leaves- // out the headings a reader sees most, and what is left says nothing- // about the page's hierarchy.- let most_used_heading = by_role- .iter()- .filter(|(role, _)| role != "body")- .map(|(_, sizes)| sizes.len())- .max()- .unwrap_or(0);- let mut dropped_most_used = false;+ // the heading levels with no dominant size hold most of the page's+ // headings (cnnbrasil.com.br sets its thirty h3s at 14, 16 and 20px, ten+ // each, against twelve h1 and h2), the ladder leaves out the headings a+ // reader sees, and what is left says nothing about the page's hierarchy.+ let (mut settled_headings, mut dropped_headings) = (0usize, 0usize);let mut roles: Vec<(String, f64)> = Vec::new();for (role, sizes) in by_role {+ let heading = role != "body";match dominant_type_role_size(&role, &sizes) {- Some(size) => roles.push((role, size)),- None => dropped_most_used |= role != "body" && sizes.len() == most_used_heading,+ Some(size) => {+ if heading {+ settled_headings += sizes.len();+ }+ roles.push((role, size));+ }+ None if heading => dropped_headings += sizes.len(),+ None => {}}}- if dropped_most_used {+ if dropped_headings > settled_headings {return Vec::new();}@@ -2212,7 +2213,9 @@ mod tests {/// sees. cnnbrasil.com.br sets its thirty h3 headlines at 14, 16 and 20px,/// ten each, so the h3 role drops out and a 14/16/16 ladder of body, h1/// and h2 reports; phillips66.com's h1 is a 14px form label over 16px- /// copy. Neither ladder describes the page, and neither reports.+ /// copy. Neither ladder describes the page, and neither reports. A tied+ /// role holding fewer headings than the ladder does stays out as before+ /// (otto.de's two h2s at 16 and 26px beside an h1, an h3 and an h4).#[test]fn flat_type_hierarchy_declines_a_ladder_without_the_page_headings() {let mut news = vec![("h1", 16.0)];@@ -2238,6 +2241,13 @@ mod tests {// An h1 at the body size still counts.label[0] = ("h1", 16.0);assert_eq!(check_flat_type_hierarchy_samples(&samples(&label)).len(), 1);++ let mut otto = vec![("h1", 16.0), ("h2", 16.0), ("h2", 26.0), ("h3", 16.0), ("h4", 12.0)];+ otto.extend([("body", 14.0); 357]);+ otto.extend([("body", 12.0); 46]);+ let hits = check_flat_type_hierarchy_samples(&samples(&otto));+ assert_eq!(hits.len(), 1, "a tied minority role stays out: {hits:?}");+ assert!(hits[0].snippet.starts_with("Role sizes: h4 12px, body 14px, h1 16px, h3 16px"), "{hits:?}");}#[test]diff --git a/tests/fixtures/antipatterns/kicker-above-heading.html b/tests/fixtures/antipatterns/kicker-above-heading.htmlindex f42cb4303..ba32eb3bd 100644--- a/tests/fixtures/antipatterns/kicker-above-heading.html+++ b/tests/fixtures/antipatterns/kicker-above-heading.html@@ -218,7 +218,9 @@/* Round 7: a kicker inside a card drawn by its computed box, not its tag */.press-panel { padding: 24px; background: #14161b; border-radius: 16px; }.press-card { min-height: 180px; padding: 24px; background: #ffffff; border-radius: 16px; color: #14161b; }- .tall-panel { min-height: 900px; padding: 24px; background: #ffffff; border-radius: 16px; }+ .press-card h3 { font-size: 20px; line-height: 25px; font-weight: 500; }+ .side-panel { min-height: 300px; padding: 24px; background: #ffffff; border-radius: 16px; }+ .side-panel h3 { font-size: 40px; line-height: 44px; }</style></head><body>@@ -281,10 +283,18 @@</section><section class="case">- <div class="tall-panel">- <span class="kicker">Platform overview</span>- <h2>"Label In A Tall Panel"</h2>- <p>A painted panel taller than the viewport is a section, not a card, and its eyebrow still flags.</p>+ <div class="side-panel">+ <span class="kicker">Practical agency support</span>+ <h2>"Section Title In A Panel"</h2>+ <p>A section's own h2 in a painted side panel is no card title, and its eyebrow still flags.</p>+ </div>+ </section>++ <section class="case">+ <div class="side-panel">+ <span class="kicker">Beyond plans</span>+ <h3>"Display Title In A Band"</h3>+ <p>An h3 set at display size across a feature band is a section title too, and its eyebrow still flags.</p></div></section></section>