static calculate(layoutShiftEvents) {
    const gapMicroseconds = 1_000_000;
    const limitMicroseconds = 5_000_000;
    let maxScore = 0;
    let currentClusterScore = 0;
    let firstTs = Number.NEGATIVE_INFINITY;
    let prevTs = Number.NEGATIVE_INFINITY;

    for (const event of layoutShiftEvents) {
      if (event.ts - firstTs > limitMicroseconds || event.ts - prevTs > gapMicroseconds) {
        firstTs = event.ts;
        currentClusterScore = 0;
      }
      prevTs = event.ts;
      currentClusterScore += event.weightedScore;
      maxScore = Math.max(maxScore, currentClusterScore);
    }

    return maxScore;
  }
Calculates cumulative layout shifts per cluster (session) of LayoutShift
events -- where a new cluster is created when there's a gap of more than
1000ms since the last LayoutShift event or the cluster is greater than
5000ms long -- and returns the max LayoutShift score found.
@param {Array<LayoutShiftEvent>} layoutShiftEvents
@return {number}