@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
36 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRectRelativeToOffsetParent = void 0;
const getBoundingClientRect_1 = require("./getBoundingClientRect");
const getElementScroll_1 = require("./getElementScroll");
const getWindowScrollBarX_1 = require("./getWindowScrollBarX");
const is_utils_1 = require("./is.utils");
const node_1 = require("./node");
const getRectRelativeToOffsetParent = (element, offsetParent, strategy) => {
const isOffsetParentAnElement = (0, is_utils_1.isHTMLElement)(offsetParent);
const documentElement = window.document.documentElement;
const rect = (0, getBoundingClientRect_1.getBoundingClientRect)(element, strategy === 'fixed', offsetParent);
let scroll = { scrollLeft: 0, scrollTop: 0 };
const offsets = { x: 0, y: 0 };
if (isOffsetParentAnElement || (!isOffsetParentAnElement && strategy !== 'fixed')) {
if ((0, node_1.getNodeName)(offsetParent) !== 'body' || (0, is_utils_1.isOverflowElement)(documentElement)) {
scroll = (0, getElementScroll_1.getElementScroll)(offsetParent);
}
if ((0, is_utils_1.isHTMLElement)(offsetParent)) {
const offsetRect = (0, getBoundingClientRect_1.getBoundingClientRect)(offsetParent);
offsets.x = offsetRect.x + offsetParent.clientLeft;
offsets.y = offsetRect.y + offsetParent.clientTop;
}
else if (documentElement) {
offsets.x = (0, getWindowScrollBarX_1.getWindowScrollBarX)(documentElement);
}
}
return {
x: rect.left + scroll.scrollLeft - offsets.x,
y: rect.top + scroll.scrollTop - offsets.y,
width: rect.width,
height: rect.height,
};
};
exports.getRectRelativeToOffsetParent = getRectRelativeToOffsetParent;
//# sourceMappingURL=getRectRelativeToOffsetParent.js.map