( scrollElement: ResolvedScrollElement )
| 21 | const getBoundingBox = (element: Element) => element.getBoundingClientRect(); |
| 22 | |
| 23 | export function getDimensions( |
| 24 | scrollElement: ResolvedScrollElement |
| 25 | ): Dimensions { |
| 26 | if (isWindow(scrollElement)) { |
| 27 | const { innerHeight, innerWidth } = window; |
| 28 | return { |
| 29 | height: typeof innerHeight === "number" ? innerHeight : 0, |
| 30 | width: typeof innerWidth === "number" ? innerWidth : 0 |
| 31 | }; |
| 32 | } else { |
| 33 | // Read the fields explicitly; DOMRect fields are prototype getters, |
| 34 | // so spreading a DOMRect (e.g. into state) would copy nothing |
| 35 | const { height, width } = getBoundingBox(scrollElement); |
| 36 | return { height, width }; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Gets the vertical and horizontal position of an element within its scroll container. |
no test coverage detected