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.

24 lines
767 B

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