From dde30b8e41be4919fb241e201586abc2144c1850 Mon Sep 17 00:00:00 2001 From: Tremayne Christ Date: Mon, 10 Dec 2018 11:54:27 +0000 Subject: [PATCH] fix: correctly calculate width/height properties --- src/ContentRect.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ContentRect.ts b/src/ContentRect.ts index 415d387..083dc67 100644 --- a/src/ContentRect.ts +++ b/src/ContentRect.ts @@ -16,12 +16,13 @@ const ContentRect = (target: Element): Readonly => { }); } else { // if (target instanceof HTMLElement) { // also includes all other non-SVGGraphicsElements const styles = window.getComputedStyle(target); - return Object.freeze({ - height: parseFloat(styles.height || '0'), - left: parseFloat(styles.paddingLeft || '0'), - top: parseFloat(styles.paddingTop || '0'), - width: parseFloat(styles.width || '0'), - }); + const paddingTop = parseFloat(styles.paddingTop || '0'); + const paddingRight = parseFloat(styles.paddingRight || '0'); + const paddingBottom = parseFloat(styles.paddingBottom || '0'); + const paddingLeft = parseFloat(styles.paddingLeft || '0'); + const width = parseFloat(styles.width || '0') - paddingLeft - paddingRight; + const height = parseFloat(styles.height || '0') - paddingTop - paddingBottom; + return Object.freeze({ height, left, top, width }); } };