Sign in

    mizchi/crater/x/webvitals does not have a README file

    ContentReadiness

    pub(all) struct ContentReadiness {
    lcp_ready : Bool
    lcp_time : Double?
    critical_resources_loaded : Bool
    a11y_ready : Bool
    }

    Overall content readiness state

    ContentReadiness::from_lcp_tracker

    fn ContentReadiness::from_lcp_tracker(tracker : LCPTracker, a11y_ready : Bool) -> ContentReadiness

    Create readiness state from LCP tracker

    ContentReadiness::is_interaction_ready

    fn ContentReadiness::is_interaction_ready(self : ContentReadiness) -> Bool

    Check if content is ready for interaction

    ContentReadiness::new

    LCPCandidate

    pub(all) struct LCPCandidate {
    element_id : String
    element_type : LCPElementType
    size : Double
    x : Double
    y : Double
    width : Double
    height : Double
    resource_loaded : Bool
    render_time : Double?
    load_time : Double?
    }

    A candidate element for Largest Contentful Paint

    LCPCandidate::get_lcp_time

    fn LCPCandidate::get_lcp_time(self : LCPCandidate) -> Double?

    Get the LCP time (load_time for images, render_time for text)

    LCPCandidate::is_rendered

    fn LCPCandidate::is_rendered(self : LCPCandidate) -> Bool

    Check if this candidate is fully rendered (resource loaded if applicable)

    LCPCandidate::new

    fn LCPCandidate::new(element_id : String, element_type : LCPElementType, x : Double, y : Double, width : Double, height : Double) -> LCPCandidate

    LCPCandidate::with_load_time

    fn LCPCandidate::with_load_time(self : LCPCandidate, time : Double) -> LCPCandidate

    LCPCandidate::with_render_time

    fn LCPCandidate::with_render_time(self : LCPCandidate, time : Double) -> LCPCandidate

    LCPCandidate::with_resource_loaded

    fn LCPCandidate::with_resource_loaded(self : LCPCandidate, loaded : Bool) -> LCPCandidate

    LCPElementType

    pub(all) enum LCPElementType {
    Image(String)
    BackgroundImage(String)
    Video(String?)
    TextBlock
    }

    Types of elements that can be LCP candidates Per spec: , inside , poster, element with background-image, text block elements

    LCPTracker

    pub(all) struct LCPTracker {
    candidates : Array[LCPCandidate]
    current_lcp : LCPCandidate?
    finalized : Bool
    viewport_width : Double
    viewport_height : Double
    }

    Tracks LCP candidates and determines the final LCP element

    LCPTracker::add_candidate

    fn LCPTracker::add_candidate(self : LCPTracker, candidate : LCPCandidate) -> Unit

    Add a new LCP candidate

    LCPTracker::finalize

    fn LCPTracker::finalize(self : LCPTracker) -> Unit

    Finalize LCP (called on first user input)

    LCPTracker::get_lcp

    fn LCPTracker::get_lcp(self : LCPTracker) -> LCPCandidate?

    Get the current LCP candidate

    LCPTracker::get_lcp_time

    fn LCPTracker::get_lcp_time(self : LCPTracker) -> Double?

    Get LCP time in milliseconds

    LCPTracker::is_finalized

    fn LCPTracker::is_finalized(self : LCPTracker) -> Bool

    Check if LCP is finalized

    LCPTracker::is_lcp_ready

    fn LCPTracker::is_lcp_ready(self : LCPTracker) -> Bool

    Check if LCP is ready (largest element fully rendered)

    LCPTracker::new

    fn LCPTracker::new(viewport_width : Double, viewport_height : Double) -> LCPTracker

    LCPTracker::on_element_rendered

    fn LCPTracker::on_element_rendered(self : LCPTracker, element_id : String, render_time : Double) -> Unit

    Update render time for an element

    LCPTracker::on_resource_loaded

    fn LCPTracker::on_resource_loaded(self : LCPTracker, element_id : String, load_time : Double) -> Unit

    Update resource load status for an element

    LayoutShift

    pub struct LayoutShift {
    impact_fraction : Double
    distance_fraction : Double
    score : Double
    }

    Result of CLS calculation
    impl Show for LayoutShift

    compute_element_shift

    Calculate layout shift between two bounding rects viewport: the viewport size for normalization

    compute_total

    Calculate total CLS score for multiple elements

    extract_lcp_candidates

    fn extract_lcp_candidates(layout :
    LayoutTree
    , viewport_width : Double, viewport_height : Double) -> Array[LCPCandidate]

    Extract LCP candidates from a LayoutTree

    Source Files