UNPKG

@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

27 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCssDimensions = void 0; const is_utils_1 = require("./is.utils"); /** * Return the dimensions of the element, if fallback is true we should retrieve this information in another way */ const getCssDimensions = (element) => { const css = window.getComputedStyle(element); let width = parseFloat(css.width) || 0; let height = parseFloat(css.height) || 0; const hasOffset = (0, is_utils_1.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, }; }; exports.getCssDimensions = getCssDimensions; //# sourceMappingURL=getCssDimensions.js.map