@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
23 lines • 855 B
JavaScript
import { isHTMLElement } from './is.utils';
/**
* Return the dimensions of the element, if fallback is true we should retrieve this information in another way
*/
export const getCssDimensions = (element) => {
const css = window.getComputedStyle(element);
let width = parseFloat(css.width) || 0;
let height = parseFloat(css.height) || 0;
const hasOffset = isHTMLElement(element);
const offsetWidth = hasOffset ? element.offsetWidth : width;
const offsetHeight = hasOffset ? element.offsetHeight : height;
const shouldFallback = Math.round(width) !== offsetWidth || Math.round(height) !== offsetHeight;
if (shouldFallback) {
width = offsetWidth;
height = offsetHeight;
}
return {
width,
height,
fallback: shouldFallback,
};
};
//# sourceMappingURL=getCssDimensions.js.map