source: imaps-frontend/node_modules/@popperjs/core/lib/utils/detectOverflow.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import getClippingRect from "../dom-utils/getClippingRect.js";
2import getDocumentElement from "../dom-utils/getDocumentElement.js";
3import getBoundingClientRect from "../dom-utils/getBoundingClientRect.js";
4import computeOffsets from "./computeOffsets.js";
5import rectToClientRect from "./rectToClientRect.js";
6import { clippingParents, reference, popper, bottom, top, right, basePlacements, viewport } from "../enums.js";
7import { isElement } from "../dom-utils/instanceOf.js";
8import mergePaddingObject from "./mergePaddingObject.js";
9import expandToHashMap from "./expandToHashMap.js"; // eslint-disable-next-line import/no-unused-modules
10
11export 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$strategy = _options.strategy,
20 strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
21 _options$boundary = _options.boundary,
22 boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
23 _options$rootBoundary = _options.rootBoundary,
24 rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
25 _options$elementConte = _options.elementContext,
26 elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
27 _options$altBoundary = _options.altBoundary,
28 altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
29 _options$padding = _options.padding,
30 padding = _options$padding === void 0 ? 0 : _options$padding;
31 var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
32 var altContext = elementContext === popper ? reference : popper;
33 var popperRect = state.rects.popper;
34 var element = state.elements[altBoundary ? altContext : elementContext];
35 var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
36 var referenceClientRect = getBoundingClientRect(state.elements.reference);
37 var popperOffsets = computeOffsets({
38 reference: referenceClientRect,
39 element: popperRect,
40 strategy: 'absolute',
41 placement: placement
42 });
43 var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
44 var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
45 // 0 or negative = within the clipping rect
46
47 var overflowOffsets = {
48 top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
49 bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
50 left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
51 right: elementClientRect.right - clippingClientRect.right + paddingObject.right
52 };
53 var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
54
55 if (elementContext === popper && offsetData) {
56 var offset = offsetData[placement];
57 Object.keys(overflowOffsets).forEach(function (key) {
58 var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
59 var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
60 overflowOffsets[key] += offset[axis] * multiply;
61 });
62 }
63
64 return overflowOffsets;
65}
Note: See TracBrowser for help on using the repository browser.