(node, types)
| 1 | function getContentRect(node, types) { |
| 2 | const calculations = {} |
| 3 | |
| 4 | if (types.indexOf('client') > -1) { |
| 5 | calculations.client = { |
| 6 | top: node.clientTop, |
| 7 | left: node.clientLeft, |
| 8 | width: node.clientWidth, |
| 9 | height: node.clientHeight, |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | if (types.indexOf('offset') > -1) { |
| 14 | calculations.offset = { |
| 15 | top: node.offsetTop, |
| 16 | left: node.offsetLeft, |
| 17 | width: node.offsetWidth, |
| 18 | height: node.offsetHeight, |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | if (types.indexOf('scroll') > -1) { |
| 23 | calculations.scroll = { |
| 24 | top: node.scrollTop, |
| 25 | left: node.scrollLeft, |
| 26 | width: node.scrollWidth, |
| 27 | height: node.scrollHeight, |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | if (types.indexOf('bounds') > -1) { |
| 32 | const rect = node.getBoundingClientRect() |
| 33 | calculations.bounds = { |
| 34 | top: rect.top, |
| 35 | right: rect.right, |
| 36 | bottom: rect.bottom, |
| 37 | left: rect.left, |
| 38 | width: rect.width, |
| 39 | height: rect.height, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if (types.indexOf('margin') > -1) { |
| 44 | const styles = getComputedStyle(node) |
| 45 | calculations.margin = { |
| 46 | top: styles ? parseInt(styles.marginTop) : 0, |
| 47 | right: styles ? parseInt(styles.marginRight) : 0, |
| 48 | bottom: styles ? parseInt(styles.marginBottom) : 0, |
| 49 | left: styles ? parseInt(styles.marginLeft) : 0, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return calculations |
| 54 | } |
| 55 | |
| 56 | export default getContentRect |
no outgoing calls
no test coverage detected
searching dependent graphs…