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

32 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBoundingClientRect = void 0; const is_utils_1 = require("./is.utils"); const rectToClientRect_1 = require("./rectToClientRect"); const unwrapElement_1 = require("./unwrapElement"); const getBoundingClientRect = (element, isFixedStrategy = false, offsetParent) => { const clientRect = element.getBoundingClientRect(); const domElement = (0, unwrapElement_1.unwrapElement)(element); const addVisualOffsets = (0, is_utils_1.isClientRectVisualViewportBased)() && isFixedStrategy; let x = clientRect.left + (addVisualOffsets ? window.visualViewport?.offsetLeft || 0 : 0); let y = clientRect.top + (addVisualOffsets ? window.visualViewport?.offsetTop || 0 : 0); const width = clientRect.width; const height = clientRect.height; // If iFrame apply iframeScale and rect if (domElement) { const offsetWin = offsetParent && (0, is_utils_1.isElement)(offsetParent) ? window : offsetParent; let currentIFrame = window.frameElement; while (currentIFrame && offsetParent && offsetWin !== window) { const iframeRect = currentIFrame.getBoundingClientRect(); const css = window.getComputedStyle(currentIFrame); iframeRect.x += currentIFrame.clientLeft + parseFloat(css.paddingLeft || '0'); iframeRect.y += currentIFrame.clientTop + parseFloat(css.paddingTop || '0'); x += iframeRect.x; y += iframeRect.y; currentIFrame = window.frameElement; } } return (0, rectToClientRect_1.rectToClientRect)({ width, height, x, y }); }; exports.getBoundingClientRect = getBoundingClientRect; //# sourceMappingURL=getBoundingClientRect.js.map