(element: Element)
| 8 | |
| 9 | /** Gets a mutable version of an element's bounding `DOMRect`. */ |
| 10 | export function getMutableClientRect(element: Element): DOMRect { |
| 11 | const rect = element.getBoundingClientRect(); |
| 12 | |
| 13 | // We need to clone the `clientRect` here, because all the values on it are readonly |
| 14 | // and we need to be able to update them. Also we can't use a spread here, because |
| 15 | // the values on a `DOMRect` aren't own properties. See: |
| 16 | // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes |
| 17 | return { |
| 18 | top: rect.top, |
| 19 | right: rect.right, |
| 20 | bottom: rect.bottom, |
| 21 | left: rect.left, |
| 22 | width: rect.width, |
| 23 | height: rect.height, |
| 24 | x: rect.x, |
| 25 | y: rect.y, |
| 26 | } as DOMRect; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Checks whether some coordinates are within a `DOMRect`. |
no test coverage detected