1 | import getClippingRect from "../dom-utils/getClippingRect.js";
|
2 | import getDocumentElement from "../dom-utils/getDocumentElement.js";
|
3 | import getBoundingClientRect from "../dom-utils/getBoundingClientRect.js";
|
4 | import computeOffsets from "./computeOffsets.js";
|
5 | import rectToClientRect from "./rectToClientRect.js";
|
6 | import { clippingParents, reference, popper, bottom, top, right, basePlacements, viewport } from "../enums.js";
|
7 | import { isElement } from "../dom-utils/instanceOf.js";
|
8 | import mergePaddingObject from "./mergePaddingObject.js";
|
9 | import expandToHashMap from "./expandToHashMap.js";
|
10 |
|
11 | export default function detectOverflow(state, options) {
|
12 | if (options === void 0) {
|
13 | options = {};
|
14 | }
|
15 |
|
16 | var _options = options,
|
17 | _options$placement = _options.placement,
|
18 | placement = _options$placement === void 0 ? state.placement : _options$placement,
|
19 | _options$boundary = _options.boundary,
|
20 | boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
|
21 | _options$rootBoundary = _options.rootBoundary,
|
22 | rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
|
23 | _options$elementConte = _options.elementContext,
|
24 | elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
|
25 | _options$altBoundary = _options.altBoundary,
|
26 | altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
|
27 | _options$padding = _options.padding,
|
28 | padding = _options$padding === void 0 ? 0 : _options$padding;
|
29 | var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
|
30 | var altContext = elementContext === popper ? reference : popper;
|
31 | var popperRect = state.rects.popper;
|
32 | var element = state.elements[altBoundary ? altContext : elementContext];
|
33 | var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
|
34 | var referenceClientRect = getBoundingClientRect(state.elements.reference);
|
35 | var popperOffsets = computeOffsets({
|
36 | reference: referenceClientRect,
|
37 | element: popperRect,
|
38 | strategy: 'absolute',
|
39 | placement: placement
|
40 | });
|
41 | var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
|
42 | var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect;
|
43 |
|
44 |
|
45 | var overflowOffsets = {
|
46 | top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
|
47 | bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
|
48 | left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
|
49 | right: elementClientRect.right - clippingClientRect.right + paddingObject.right
|
50 | };
|
51 | var offsetData = state.modifiersData.offset;
|
52 |
|
53 | if (elementContext === popper && offsetData) {
|
54 | var offset = offsetData[placement];
|
55 | Object.keys(overflowOffsets).forEach(function (key) {
|
56 | var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
|
57 | var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
|
58 | overflowOffsets[key] += offset[axis] * multiply;
|
59 | });
|
60 | }
|
61 |
|
62 | return overflowOffsets;
|
63 | } |
\ | No newline at end of file |