function areRectsOnOneLine(
  rects: Array<ClientRect>,
  lineHeight: number,
): boolean {
  let minTop = Infinity;
  let minBottom = Infinity;
  let maxTop = -Infinity;
  let maxBottom = -Infinity;

  for (let ii = 0; ii < rects.length; ii++) {
    const rect = rects[ii];
    if (rect.width === 0 || rect.width === 1) {
      // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
      // Safari) include an empty rect on the previous or next line. When the
      // text lies in a container whose position is not integral (e.g., from
      // margin: auto), Safari makes these empty rects have width 1 (instead of
      // 0). Having one-pixel-wide characters seems unlikely (and most browsers
      // report widths in subpixel precision anyway) so it's relatively safe to
      // skip over them.
      continue;
    }
    minTop = Math.min(minTop, rect.top);
    minBottom = Math.min(minBottom, rect.bottom);
    maxTop = Math.max(maxTop, rect.top);
    maxBottom = Math.max(maxBottom, rect.bottom);
  }

  return (
    maxTop <= minBottom &&
    maxTop - minTop < lineHeight &&
    maxBottom - minBottom < lineHeight
  );
}
Return whether every ClientRect in the provided list lies on the same line.

We assume that the rects on the same line all contain the baseline, so the
lowest top line needs to be above the highest bottom line (i.e., if you were
to project the rects onto the y-axis, their intersection would be nonempty).

In addition, we require that no two boxes are lineHeight (or more) apart at
either top or bottom, which helps protect against false positives for fonts
with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
produces rects of height 58px!).