# All files / src/_utils dom.ts

100% Statements 7/7
83.33% Branches 5/6
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    6x

    1459x

    6x
    1459x

    6x

    1459x

    1459x

     export interface Rect extends Omit<DOMRect, 'x' | 'y' | 'toJSON'> {
      x?: number
      y?: number
    }

    export const defaultRect: Rect = {
      x: 0,
      y: 0,
      width: 0,
      height: 0,
      top: 0,
      right: 0,
      bottom: 0,
      left: 0,
    }

    function isDOMRect(rect: Rect | DOMRect): rect is DOMRect {
      return (rect as DOMRect).x !== undefined
    }

    export function getCrossbrowserBoundingRect(rect: Rect | DOMRect): Rect {
      return isDOMRect(rect)
        ? rect
        : {
            x: rect.left,
            y: rect.top,
            width: rect.width,
            height: rect.height,
            top: rect.top,
            right: rect.right,
            bottom: rect.bottom,
            left: rect.left,
          }
    }
    export function getBoundingRect(node: HTMLElement) {
      const rect =
        node && node.getBoundingClientRect
          ? node.getBoundingClientRect()
          : defaultRect

      return getCrossbrowserBoundingRect(rect)
    }