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

39 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.detectOverflow = void 0; const convertOffsetParentRelativeRectToViewportRelativeRect_1 = require("./convertOffsetParentRelativeRectToViewportRelativeRect"); const getClippinRect_1 = require("./getClippinRect"); const getOffsetParent_1 = require("./getOffsetParent"); const getPaddingObject_1 = require("./getPaddingObject"); const is_utils_1 = require("./is.utils"); const rectToClientRect_1 = require("./rectToClientRect"); const detectOverflow = (state, options = {}) => { const { x, y, rects, elements, strategy } = state; const { boundary = 'clippingAncestors', rootBoundary = 'viewport', elementContext = 'floating', altBoundary = false, padding = 0, } = options; const paddingObject = (0, getPaddingObject_1.getSideObjectFromPadding)(padding); const altContext = elementContext === 'floating' ? 'reference' : 'floating'; const element = elements[altBoundary ? altContext : elementContext]; const clippingClientRect = (0, rectToClientRect_1.rectToClientRect)((0, getClippinRect_1.getClippingRect)({ element: ((0, is_utils_1.isElement)(element) ?? true) ? element : element.contextElement || window.document.documentElement, boundary, rootBoundary, strategy, })); const rect = elementContext === 'floating' ? { ...rects.floating, x, y } : rects.reference; const offsetParent = (0, getOffsetParent_1.getOffsetParent)(elements.floating); const elementClientRect = (0, rectToClientRect_1.rectToClientRect)((0, convertOffsetParentRelativeRectToViewportRelativeRect_1.convertOffsetParentRelativeRectToViewportRelativeRect)({ rect, offsetParent, strategy, })); return { top: clippingClientRect.top - elementClientRect.top + paddingObject.top, bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom, left: clippingClientRect.left - elementClientRect.left + paddingObject.left, right: elementClientRect.right - clippingClientRect.right + paddingObject.right, }; }; exports.detectOverflow = detectOverflow; //# sourceMappingURL=detectOverflow.js.map