You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
821 B

2 months ago
  1. // @flow
  2. import type { Rect } from '../types';
  3. import getBoundingClientRect from './getBoundingClientRect';
  4. // Returns the layout rect of an element relative to its offsetParent. Layout
  5. // means it doesn't take into account transforms.
  6. export default function getLayoutRect(element: HTMLElement): Rect {
  7. const clientRect = getBoundingClientRect(element);
  8. // Use the clientRect sizes if it's not been transformed.
  9. // Fixes https://github.com/popperjs/popper-core/issues/1223
  10. let width = element.offsetWidth;
  11. let height = element.offsetHeight;
  12. if (Math.abs(clientRect.width - width) <= 1) {
  13. width = clientRect.width;
  14. }
  15. if (Math.abs(clientRect.height - height) <= 1) {
  16. height = clientRect.height;
  17. }
  18. return {
  19. x: element.offsetLeft,
  20. y: element.offsetTop,
  21. width,
  22. height,
  23. };
  24. }