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

34 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertOffsetParentRelativeRectToViewportRelativeRect = void 0; const getBoundingClientRect_1 = require("./getBoundingClientRect"); const getElementScroll_1 = require("./getElementScroll"); const is_utils_1 = require("./is.utils"); const node_1 = require("./node"); const convertOffsetParentRelativeRectToViewportRelativeRect = ({ rect, offsetParent, strategy, }) => { const isOffsetParentAnElement = (0, is_utils_1.isHTMLElement)(offsetParent); const documentElement = window.document.documentElement; if (offsetParent === documentElement) { return rect; } 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; } } return { width: rect.width, height: rect.height, x: rect.x - scroll.scrollLeft + offsets.x, y: rect.y - scroll.scrollTop + offsets.y, }; }; exports.convertOffsetParentRelativeRectToViewportRelativeRect = convertOffsetParentRelativeRectToViewportRelativeRect; //# sourceMappingURL=convertOffsetParentRelativeRectToViewportRelativeRect.js.map