The design language that makes your AI harness better at design.
JavaScript
Give an element shot to flagged text the screenshot cut mostly hides
Paul Bakausb92dadf2f809
diff --git a/crates/browser/src/fullpage.rs b/crates/browser/src/fullpage.rsindex 660d22a2b..8f653a5bf 100644--- a/crates/browser/src/fullpage.rs+++ b/crates/browser/src/fullpage.rs@@ -632,10 +632,13 @@ fn stitch(result.map(|_| canvas)}-/// Whether a flagged element's document rect falls outside the screenshot-/// (past the cut or the right edge) while something of it lies right of the-/// image's left edge and below its top. `origin_x` is the image's left edge-/// in document coordinates ([`Screenshot::origin_x`]).+/// Whether a flagged element's document rect falls mostly outside the+/// screenshot (less than half of it, or of the image's own height or width+/// for an element larger than the image, inside the cut and the right edge,+/// so a paragraph that starts just above the cut and runs below it counts)+/// while something of it lies right of the image's left edge and below its+/// top. `origin_x` is the+/// image's left edge in document coordinates ([`Screenshot::origin_x`]).pub fn needs_element_shot(rect: &[f64], origin_x: f64, shot_width: f64, shot_height: f64) -> bool {if rect.len() < 4 || rect.iter().any(|v| !v.is_finite()) {return false;@@ -644,7 +647,9 @@ pub fn needs_element_shot(rect: &[f64], origin_x: f64, shot_width: f64, shot_heiif w < 1.0 || h < 1.0 || x + w <= 0.0 || y + h <= 0.0 {return false;}- y >= shot_height || x >= shot_width+ let shown_h = (y + h).min(shot_height) - y.max(0.0);+ let shown_w = (x + w).min(shot_width) - x.max(0.0);+ shown_h < h.min(shot_height) / 2.0 || shown_w < w.min(shot_width) / 2.0}/// A viewport shot per flagged element past the screenshot, the element@@ -875,6 +880,12 @@ mod tests {assert!(needs_element_shot(&[100.0, 12500.0, 200.0, 20.0], 0.0, 1280.0, 12000.0));assert!(needs_element_shot(&[1400.0, 300.0, 200.0, 20.0], 0.0, 1280.0, 12000.0));assert!(!needs_element_shot(&[100.0, 11990.0, 200.0, 20.0], 0.0, 1280.0, 12000.0));+ // Starting above the cut but mostly below it.+ assert!(needs_element_shot(&[100.0, 11990.0, 200.0, 400.0], 0.0, 1280.0, 12000.0));+ assert!(!needs_element_shot(&[100.0, 11900.0, 200.0, 120.0], 0.0, 1280.0, 12000.0));+ assert!(needs_element_shot(&[1200.0, 300.0, 400.0, 20.0], 0.0, 1280.0, 12000.0));+ // Taller than the image and filling it: the screenshot shows it.+ assert!(!needs_element_shot(&[0.0, 0.0, 1280.0, 30000.0], 0.0, 1280.0, 12000.0));assert!(!needs_element_shot(&[100.0, 300.0, 200.0, 20.0], 0.0, 1280.0, 12000.0));assert!(!needs_element_shot(&[100.0, 12500.0, 0.0, 20.0], 0.0, 1280.0, 12000.0));assert!(!needs_element_shot(&[-500.0, 12500.0, 200.0, 20.0], 0.0, 1280.0, 12000.0));