Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/ContentRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,26 @@ const ContentRect = (target: Element): Readonly<ContentRect> => {
});
} else { // if (target instanceof HTMLElement) { // also includes all other non-SVGGraphicsElements
const styles = window.getComputedStyle(target);
let height = parseFloat(styles.height || '0')
let left = parseFloat(styles.paddingLeft || '0')
let top = parseFloat(styles.paddingTop || '0')
let width = parseFloat(styles.width || '0')

// https://github.com/pelotoncycle/resize-observer/issues/19
if (isNaN(height) || isNaN(left) || isNaN(top) || isNaN(width)) {
const rect = target.getBoundingClientRect()

height = rect.height
left = rect.left
top = rect.top
width = rect.width
}

return Object.freeze({
height: parseFloat(styles.height || '0'),
left: parseFloat(styles.paddingLeft || '0'),
top: parseFloat(styles.paddingTop || '0'),
width: parseFloat(styles.width || '0'),
height,
left,
top,
width,
});
}
};
Expand Down