bounds.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Bounds = /** @class */ (function () {
  4. function Bounds(x, y, w, h) {
  5. this.left = x;
  6. this.top = y;
  7. this.width = w;
  8. this.height = h;
  9. }
  10. Bounds.prototype.add = function (x, y, w, h) {
  11. return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h);
  12. };
  13. Bounds.fromClientRect = function (clientRect) {
  14. return new Bounds(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
  15. };
  16. return Bounds;
  17. }());
  18. exports.Bounds = Bounds;
  19. exports.parseBounds = function (node) {
  20. return Bounds.fromClientRect(node.getBoundingClientRect());
  21. };
  22. exports.parseDocumentSize = function (document) {
  23. var body = document.body;
  24. var documentElement = document.documentElement;
  25. if (!body || !documentElement) {
  26. throw new Error("Unable to get document size");
  27. }
  28. var width = Math.max(Math.max(body.scrollWidth, documentElement.scrollWidth), Math.max(body.offsetWidth, documentElement.offsetWidth), Math.max(body.clientWidth, documentElement.clientWidth));
  29. var height = Math.max(Math.max(body.scrollHeight, documentElement.scrollHeight), Math.max(body.offsetHeight, documentElement.offsetHeight), Math.max(body.clientHeight, documentElement.clientHeight));
  30. return new Bounds(0, 0, width, height);
  31. };
  32. //# sourceMappingURL=bounds.js.map