module.exports = getSize function getSize(element) { // Handle cases where the element is not already // attached to the DOM by briefly appending it // to document.body, and removing it again later. if (element === window || element === document.body) { return [window.innerWidth, window.innerHeight] } if (!element.parentNode) { var temporary = true document.body.appendChild(element) } var bounds = element.getBoundingClientRect() var styles = getComputedStyle(element) var height = (bounds.height|0) + parse(styles.getPropertyValue('margin-top')) + parse(styles.getPropertyValue('margin-bottom')) var width = (bounds.width|0) + parse(styles.getPropertyValue('margin-left')) + parse(styles.getPropertyValue('margin-right')) if (temporary) { document.body.removeChild(element) } return [width, height] } function parse(prop) { return parseFloat(prop) || 0 }