BoundingDimensions.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. */
  9. 'use strict';
  10. const PooledClass = require('./PooledClass');
  11. const twoArgumentPooler = PooledClass.twoArgumentPooler;
  12. /**
  13. * PooledClass representing the bounding rectangle of a region.
  14. *
  15. * @param {number} width Width of bounding rectangle.
  16. * @param {number} height Height of bounding rectangle.
  17. * @constructor BoundingDimensions
  18. */
  19. function BoundingDimensions(width, height) {
  20. this.width = width;
  21. this.height = height;
  22. }
  23. BoundingDimensions.prototype.destructor = function() {
  24. this.width = null;
  25. this.height = null;
  26. };
  27. /**
  28. * @param {HTMLElement} element Element to return `BoundingDimensions` for.
  29. * @return {BoundingDimensions} Bounding dimensions of `element`.
  30. */
  31. BoundingDimensions.getPooledFromElement = function(element) {
  32. return BoundingDimensions.getPooled(
  33. element.offsetWidth,
  34. element.offsetHeight,
  35. );
  36. };
  37. PooledClass.addPoolingTo(BoundingDimensions, twoArgumentPooler);
  38. module.exports = BoundingDimensions;