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.

28 lines
1.2 KiB

2 months ago
  1. import getDocumentElement from "./getDocumentElement.js";
  2. import getComputedStyle from "./getComputedStyle.js";
  3. import getWindowScrollBarX from "./getWindowScrollBarX.js";
  4. import getWindowScroll from "./getWindowScroll.js";
  5. import { max } from "../utils/math.js"; // Gets the entire size of the scrollable document area, even extending outside
  6. // of the `<html>` and `<body>` rect bounds if horizontally scrollable
  7. export default function getDocumentRect(element) {
  8. var _element$ownerDocumen;
  9. var html = getDocumentElement(element);
  10. var winScroll = getWindowScroll(element);
  11. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  12. var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  13. var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  14. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  15. var y = -winScroll.scrollTop;
  16. if (getComputedStyle(body || html).direction === 'rtl') {
  17. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  18. }
  19. return {
  20. width: width,
  21. height: height,
  22. x: x,
  23. y: y
  24. };
  25. }