@react-spectrum/menu 3.22.8 → 3.22.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/Menu.main.js +1 -1
  2. package/dist/Menu.main.js.map +1 -1
  3. package/dist/Menu.mjs +2 -2
  4. package/dist/Menu.module.js +2 -2
  5. package/dist/Menu.module.js.map +1 -1
  6. package/dist/Popover.main.js +196 -0
  7. package/dist/Popover.main.js.map +1 -0
  8. package/dist/Popover.mjs +191 -0
  9. package/dist/Popover.module.js +191 -0
  10. package/dist/Popover.module.js.map +1 -0
  11. package/dist/SubmenuTrigger.main.js +2 -2
  12. package/dist/SubmenuTrigger.main.js.map +1 -1
  13. package/dist/SubmenuTrigger.mjs +2 -2
  14. package/dist/SubmenuTrigger.module.js +2 -2
  15. package/dist/SubmenuTrigger.module.js.map +1 -1
  16. package/dist/Underlay.main.js +54 -0
  17. package/dist/Underlay.main.js.map +1 -0
  18. package/dist/Underlay.mjs +49 -0
  19. package/dist/Underlay.module.js +49 -0
  20. package/dist/Underlay.module.js.map +1 -0
  21. package/dist/calculatePosition.main.js +392 -0
  22. package/dist/calculatePosition.main.js.map +1 -0
  23. package/dist/calculatePosition.mjs +386 -0
  24. package/dist/calculatePosition.module.js +386 -0
  25. package/dist/calculatePosition.module.js.map +1 -0
  26. package/dist/menu.2259a533.css +210 -0
  27. package/dist/menu.2259a533.css.map +1 -0
  28. package/dist/menu.359a0c0a.css +131 -0
  29. package/dist/menu.359a0c0a.css.map +1 -0
  30. package/dist/menu.57b3a408.css +12 -0
  31. package/dist/menu.57b3a408.css.map +1 -0
  32. package/dist/overlays_css.main.js +35 -0
  33. package/dist/overlays_css.main.js.map +1 -0
  34. package/dist/overlays_css.mjs +37 -0
  35. package/dist/overlays_css.module.js +37 -0
  36. package/dist/overlays_css.module.js.map +1 -0
  37. package/dist/popover_vars_css.main.js +83 -0
  38. package/dist/popover_vars_css.main.js.map +1 -0
  39. package/dist/popover_vars_css.mjs +85 -0
  40. package/dist/popover_vars_css.module.js +85 -0
  41. package/dist/popover_vars_css.module.js.map +1 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/underlay_vars_css.main.js +50 -0
  44. package/dist/underlay_vars_css.main.js.map +1 -0
  45. package/dist/underlay_vars_css.mjs +52 -0
  46. package/dist/underlay_vars_css.module.js +52 -0
  47. package/dist/underlay_vars_css.module.js.map +1 -0
  48. package/dist/useCloseOnScroll.main.js +49 -0
  49. package/dist/useCloseOnScroll.main.js.map +1 -0
  50. package/dist/useCloseOnScroll.mjs +44 -0
  51. package/dist/useCloseOnScroll.module.js +44 -0
  52. package/dist/useCloseOnScroll.module.js.map +1 -0
  53. package/dist/useOverlayPosition.main.js +225 -0
  54. package/dist/useOverlayPosition.main.js.map +1 -0
  55. package/dist/useOverlayPosition.mjs +220 -0
  56. package/dist/useOverlayPosition.module.js +220 -0
  57. package/dist/useOverlayPosition.module.js.map +1 -0
  58. package/dist/usePopover.main.js +73 -0
  59. package/dist/usePopover.main.js.map +1 -0
  60. package/dist/usePopover.mjs +68 -0
  61. package/dist/usePopover.module.js +68 -0
  62. package/dist/usePopover.module.js.map +1 -0
  63. package/package.json +19 -19
  64. package/src/Menu.tsx +2 -1
  65. package/src/Popover.tsx +240 -0
  66. package/src/SubmenuTrigger.tsx +1 -1
  67. package/src/Underlay.tsx +43 -0
  68. package/src/calculatePosition.ts +627 -0
  69. package/src/useCloseOnScroll.ts +64 -0
  70. package/src/useOverlayPosition.ts +327 -0
  71. package/src/usePopover.ts +136 -0
@@ -0,0 +1,386 @@
1
+ import {isWebKit as $7Pq2Q$isWebKit, clamp as $7Pq2Q$clamp} from "@react-aria/utils";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ const $74be59a24b8d2173$var$AXIS = {
15
+ top: 'top',
16
+ bottom: 'top',
17
+ left: 'left',
18
+ right: 'left'
19
+ };
20
+ const $74be59a24b8d2173$var$FLIPPED_DIRECTION = {
21
+ top: 'bottom',
22
+ bottom: 'top',
23
+ left: 'right',
24
+ right: 'left'
25
+ };
26
+ const $74be59a24b8d2173$var$CROSS_AXIS = {
27
+ top: 'left',
28
+ left: 'top'
29
+ };
30
+ const $74be59a24b8d2173$var$AXIS_SIZE = {
31
+ top: 'height',
32
+ left: 'width'
33
+ };
34
+ const $74be59a24b8d2173$var$TOTAL_SIZE = {
35
+ width: 'totalWidth',
36
+ height: 'totalHeight'
37
+ };
38
+ const $74be59a24b8d2173$var$PARSED_PLACEMENT_CACHE = {};
39
+ let $74be59a24b8d2173$var$visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;
40
+ function $74be59a24b8d2173$var$getContainerDimensions(containerNode) {
41
+ let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;
42
+ let scroll = {};
43
+ var _visualViewport_scale;
44
+ let isPinchZoomedIn = ((_visualViewport_scale = $74be59a24b8d2173$var$visualViewport === null || $74be59a24b8d2173$var$visualViewport === void 0 ? void 0 : $74be59a24b8d2173$var$visualViewport.scale) !== null && _visualViewport_scale !== void 0 ? _visualViewport_scale : 1) > 1;
45
+ if (containerNode.tagName === 'BODY') {
46
+ let documentElement = document.documentElement;
47
+ totalWidth = documentElement.clientWidth;
48
+ totalHeight = documentElement.clientHeight;
49
+ var _visualViewport_width;
50
+ width = (_visualViewport_width = $74be59a24b8d2173$var$visualViewport === null || $74be59a24b8d2173$var$visualViewport === void 0 ? void 0 : $74be59a24b8d2173$var$visualViewport.width) !== null && _visualViewport_width !== void 0 ? _visualViewport_width : totalWidth;
51
+ var _visualViewport_height;
52
+ height = (_visualViewport_height = $74be59a24b8d2173$var$visualViewport === null || $74be59a24b8d2173$var$visualViewport === void 0 ? void 0 : $74be59a24b8d2173$var$visualViewport.height) !== null && _visualViewport_height !== void 0 ? _visualViewport_height : totalHeight;
53
+ scroll.top = documentElement.scrollTop || containerNode.scrollTop;
54
+ scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;
55
+ // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with
56
+ // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate
57
+ // coordinates/values with respect to the visual viewport or with respect to the layout viewport.
58
+ if ($74be59a24b8d2173$var$visualViewport) {
59
+ top = $74be59a24b8d2173$var$visualViewport.offsetTop;
60
+ left = $74be59a24b8d2173$var$visualViewport.offsetLeft;
61
+ }
62
+ } else {
63
+ ({ width: width, height: height, top: top, left: left } = $74be59a24b8d2173$var$getOffset(containerNode, false));
64
+ scroll.top = containerNode.scrollTop;
65
+ scroll.left = containerNode.scrollLeft;
66
+ totalWidth = width;
67
+ totalHeight = height;
68
+ }
69
+ if ((0, $7Pq2Q$isWebKit)() && (containerNode.tagName === 'BODY' || containerNode.tagName === 'HTML') && isPinchZoomedIn) {
70
+ // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.
71
+ // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.
72
+ // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable
73
+ // before pinch zoom happens
74
+ scroll.top = 0;
75
+ scroll.left = 0;
76
+ var _visualViewport_pageTop;
77
+ top = (_visualViewport_pageTop = $74be59a24b8d2173$var$visualViewport === null || $74be59a24b8d2173$var$visualViewport === void 0 ? void 0 : $74be59a24b8d2173$var$visualViewport.pageTop) !== null && _visualViewport_pageTop !== void 0 ? _visualViewport_pageTop : 0;
78
+ var _visualViewport_pageLeft;
79
+ left = (_visualViewport_pageLeft = $74be59a24b8d2173$var$visualViewport === null || $74be59a24b8d2173$var$visualViewport === void 0 ? void 0 : $74be59a24b8d2173$var$visualViewport.pageLeft) !== null && _visualViewport_pageLeft !== void 0 ? _visualViewport_pageLeft : 0;
80
+ }
81
+ return {
82
+ width: width,
83
+ height: height,
84
+ totalWidth: totalWidth,
85
+ totalHeight: totalHeight,
86
+ scroll: scroll,
87
+ top: top,
88
+ left: left
89
+ };
90
+ }
91
+ function $74be59a24b8d2173$var$getScroll(node) {
92
+ return {
93
+ top: node.scrollTop,
94
+ left: node.scrollLeft,
95
+ width: node.scrollWidth,
96
+ height: node.scrollHeight
97
+ };
98
+ }
99
+ // Determines the amount of space required when moving the overlay to ensure it remains in the boundary
100
+ function $74be59a24b8d2173$var$getDelta(axis, offset, size, // The dimensions of the boundary element that the popover is
101
+ // positioned within (most of the time this is the <body>).
102
+ boundaryDimensions, // The dimensions of the containing block element that the popover is
103
+ // positioned relative to (e.g. parent with position: relative).
104
+ // Usually this is the same as the boundary element, but if the popover
105
+ // is portaled somewhere other than the body and has an ancestor with
106
+ // position: relative/absolute, it will be different.
107
+ containerDimensions, padding, containerOffsetWithBoundary) {
108
+ var _containerDimensions_scroll_axis;
109
+ let containerScroll = (_containerDimensions_scroll_axis = containerDimensions.scroll[axis]) !== null && _containerDimensions_scroll_axis !== void 0 ? _containerDimensions_scroll_axis : 0;
110
+ // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position
111
+ let boundarySize = boundaryDimensions[$74be59a24b8d2173$var$AXIS_SIZE[axis]];
112
+ // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.
113
+ // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)
114
+ let boundaryStartEdge = boundaryDimensions.scroll[$74be59a24b8d2173$var$AXIS[axis]] + padding;
115
+ let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[$74be59a24b8d2173$var$AXIS[axis]] - padding;
116
+ let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[$74be59a24b8d2173$var$AXIS[axis]];
117
+ let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[$74be59a24b8d2173$var$AXIS[axis]];
118
+ // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's
119
+ // edges with the closest boundary edge.
120
+ if (startEdgeOffset < boundaryStartEdge) return boundaryStartEdge - startEdgeOffset;
121
+ else if (endEdgeOffset > boundaryEndEdge) return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);
122
+ else return 0;
123
+ }
124
+ function $74be59a24b8d2173$var$getMargins(node) {
125
+ let style = window.getComputedStyle(node);
126
+ return {
127
+ top: parseInt(style.marginTop, 10) || 0,
128
+ bottom: parseInt(style.marginBottom, 10) || 0,
129
+ left: parseInt(style.marginLeft, 10) || 0,
130
+ right: parseInt(style.marginRight, 10) || 0
131
+ };
132
+ }
133
+ function $74be59a24b8d2173$var$parsePlacement(input) {
134
+ if ($74be59a24b8d2173$var$PARSED_PLACEMENT_CACHE[input]) return $74be59a24b8d2173$var$PARSED_PLACEMENT_CACHE[input];
135
+ let [placement, crossPlacement] = input.split(' ');
136
+ let axis = $74be59a24b8d2173$var$AXIS[placement] || 'right';
137
+ let crossAxis = $74be59a24b8d2173$var$CROSS_AXIS[axis];
138
+ if (!$74be59a24b8d2173$var$AXIS[crossPlacement]) crossPlacement = 'center';
139
+ let size = $74be59a24b8d2173$var$AXIS_SIZE[axis];
140
+ let crossSize = $74be59a24b8d2173$var$AXIS_SIZE[crossAxis];
141
+ $74be59a24b8d2173$var$PARSED_PLACEMENT_CACHE[input] = {
142
+ placement: placement,
143
+ crossPlacement: crossPlacement,
144
+ axis: axis,
145
+ crossAxis: crossAxis,
146
+ size: size,
147
+ crossSize: crossSize
148
+ };
149
+ return $74be59a24b8d2173$var$PARSED_PLACEMENT_CACHE[input];
150
+ }
151
+ function $74be59a24b8d2173$var$computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset) {
152
+ let { placement: placement, crossPlacement: crossPlacement, axis: axis, crossAxis: crossAxis, size: size, crossSize: crossSize } = placementInfo;
153
+ let position = {};
154
+ var _childOffset_crossAxis;
155
+ // button position
156
+ position[crossAxis] = (_childOffset_crossAxis = childOffset[crossAxis]) !== null && _childOffset_crossAxis !== void 0 ? _childOffset_crossAxis : 0;
157
+ var _childOffset_crossSize, _overlaySize_crossSize, _childOffset_crossSize1, _overlaySize_crossSize1;
158
+ if (crossPlacement === 'center') // + (button size / 2) - (overlay size / 2)
159
+ // at this point the overlay center should match the button center
160
+ position[crossAxis] += (((_childOffset_crossSize = childOffset[crossSize]) !== null && _childOffset_crossSize !== void 0 ? _childOffset_crossSize : 0) - ((_overlaySize_crossSize = overlaySize[crossSize]) !== null && _overlaySize_crossSize !== void 0 ? _overlaySize_crossSize : 0)) / 2;
161
+ else if (crossPlacement !== crossAxis) // + (button size) - (overlay size)
162
+ // at this point the overlay bottom should match the button bottom
163
+ position[crossAxis] += ((_childOffset_crossSize1 = childOffset[crossSize]) !== null && _childOffset_crossSize1 !== void 0 ? _childOffset_crossSize1 : 0) - ((_overlaySize_crossSize1 = overlaySize[crossSize]) !== null && _overlaySize_crossSize1 !== void 0 ? _overlaySize_crossSize1 : 0);
164
+ /* else {
165
+ the overlay top should match the button top
166
+ } */
167
+ position[crossAxis] += crossOffset;
168
+ // overlay top overlapping arrow with button bottom
169
+ const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;
170
+ // overlay bottom overlapping arrow with button top
171
+ const maxPosition = childOffset[crossAxis] + childOffset[crossSize] - arrowSize - arrowBoundaryOffset;
172
+ position[crossAxis] = (0, $7Pq2Q$clamp)(position[crossAxis], minPosition, maxPosition);
173
+ // Floor these so the position isn't placed on a partial pixel, only whole pixels. Shouldn't matter if it was floored or ceiled, so chose one.
174
+ if (placement === axis) {
175
+ // If the container is positioned (non-static), then we use the container's actual
176
+ // height, as `bottom` will be relative to this height. But if the container is static,
177
+ // then it can only be the `document.body`, and `bottom` will be relative to _its_
178
+ // container, which should be as large as boundaryDimensions.
179
+ const containerHeight = isContainerPositioned ? containerOffsetWithBoundary[size] : boundaryDimensions[$74be59a24b8d2173$var$TOTAL_SIZE[size]];
180
+ position[$74be59a24b8d2173$var$FLIPPED_DIRECTION[axis]] = Math.floor(containerHeight - childOffset[axis] + offset);
181
+ } else position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);
182
+ return position;
183
+ }
184
+ function $74be59a24b8d2173$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlayHeight, heightGrowthDirection) {
185
+ const containerHeight = isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[$74be59a24b8d2173$var$TOTAL_SIZE.height];
186
+ var _position_bottom;
187
+ // For cases where position is set via "bottom" instead of "top", we need to calculate the true overlay top with respect to the boundary. Reverse calculate this with the same method
188
+ // used in computePosition.
189
+ let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - ((_position_bottom = position.bottom) !== null && _position_bottom !== void 0 ? _position_bottom : 0) - overlayHeight);
190
+ var _boundaryDimensions_scroll_top, _margins_top, _margins_bottom, _boundaryDimensions_scroll_top1, _margins_top1, _margins_bottom1;
191
+ let maxHeight = heightGrowthDirection !== 'top' ? // We want the distance between the top of the overlay to the bottom of the boundary
192
+ Math.max(0, boundaryDimensions.height + boundaryDimensions.top + ((_boundaryDimensions_scroll_top = boundaryDimensions.scroll.top) !== null && _boundaryDimensions_scroll_top !== void 0 ? _boundaryDimensions_scroll_top : 0) - overlayTop // this is the top of the overlay
193
+ - (((_margins_top = margins.top) !== null && _margins_top !== void 0 ? _margins_top : 0) + ((_margins_bottom = margins.bottom) !== null && _margins_bottom !== void 0 ? _margins_bottom : 0) + padding // save additional space for margin and padding
194
+ )) : Math.max(0, overlayTop + overlayHeight // this is the bottom of the overlay
195
+ - (boundaryDimensions.top + ((_boundaryDimensions_scroll_top1 = boundaryDimensions.scroll.top) !== null && _boundaryDimensions_scroll_top1 !== void 0 ? _boundaryDimensions_scroll_top1 : 0) // this is the top of the boundary
196
+ ) - (((_margins_top1 = margins.top) !== null && _margins_top1 !== void 0 ? _margins_top1 : 0) + ((_margins_bottom1 = margins.bottom) !== null && _margins_bottom1 !== void 0 ? _margins_bottom1 : 0) + padding // save additional space for margin and padding
197
+ ));
198
+ return Math.min(boundaryDimensions.height - padding * 2, maxHeight);
199
+ }
200
+ function $74be59a24b8d2173$var$getAvailableSpace(boundaryDimensions, containerOffsetWithBoundary, childOffset, margins, padding, placementInfo) {
201
+ let { placement: placement, axis: axis, size: size } = placementInfo;
202
+ var _boundaryDimensions_scroll_axis, _margins_axis;
203
+ if (placement === axis) return Math.max(0, childOffset[axis] - boundaryDimensions[axis] - ((_boundaryDimensions_scroll_axis = boundaryDimensions.scroll[axis]) !== null && _boundaryDimensions_scroll_axis !== void 0 ? _boundaryDimensions_scroll_axis : 0) + containerOffsetWithBoundary[axis] - ((_margins_axis = margins[axis]) !== null && _margins_axis !== void 0 ? _margins_axis : 0) - margins[$74be59a24b8d2173$var$FLIPPED_DIRECTION[axis]] - padding);
204
+ var _margins_axis1;
205
+ return Math.max(0, boundaryDimensions[size] + boundaryDimensions[axis] + boundaryDimensions.scroll[axis] - containerOffsetWithBoundary[axis] - childOffset[axis] - childOffset[size] - ((_margins_axis1 = margins[axis]) !== null && _margins_axis1 !== void 0 ? _margins_axis1 : 0) - margins[$74be59a24b8d2173$var$FLIPPED_DIRECTION[axis]] - padding);
206
+ }
207
+ function $74be59a24b8d2173$export$6839422d1f33cee9(placementInput, childOffset, overlaySize, scrollSize, margins, padding, flip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, userSetMaxHeight, arrowSize, arrowBoundaryOffset) {
208
+ let placementInfo = $74be59a24b8d2173$var$parsePlacement(placementInput);
209
+ let { size: size, crossAxis: crossAxis, crossSize: crossSize, placement: placement, crossPlacement: crossPlacement } = placementInfo;
210
+ let position = $74be59a24b8d2173$var$computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);
211
+ let normalizedOffset = offset;
212
+ let space = $74be59a24b8d2173$var$getAvailableSpace(boundaryDimensions, containerOffsetWithBoundary, childOffset, margins, padding + offset, placementInfo);
213
+ // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip
214
+ if (flip && scrollSize[size] > space) {
215
+ let flippedPlacementInfo = $74be59a24b8d2173$var$parsePlacement(`${$74be59a24b8d2173$var$FLIPPED_DIRECTION[placement]} ${crossPlacement}`);
216
+ let flippedPosition = $74be59a24b8d2173$var$computePosition(childOffset, boundaryDimensions, overlaySize, flippedPlacementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);
217
+ let flippedSpace = $74be59a24b8d2173$var$getAvailableSpace(boundaryDimensions, containerOffsetWithBoundary, childOffset, margins, padding + offset, flippedPlacementInfo);
218
+ // If the available space for the flipped position is greater than the original available space, flip.
219
+ if (flippedSpace > space) {
220
+ placementInfo = flippedPlacementInfo;
221
+ position = flippedPosition;
222
+ normalizedOffset = offset;
223
+ }
224
+ }
225
+ // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height
226
+ let heightGrowthDirection = 'bottom';
227
+ if (placementInfo.axis === 'top') {
228
+ if (placementInfo.placement === 'top') heightGrowthDirection = 'top';
229
+ else if (placementInfo.placement === 'bottom') heightGrowthDirection = 'bottom';
230
+ } else if (placementInfo.crossAxis === 'top') {
231
+ if (placementInfo.crossPlacement === 'top') heightGrowthDirection = 'bottom';
232
+ else if (placementInfo.crossPlacement === 'bottom') heightGrowthDirection = 'top';
233
+ }
234
+ let delta = $74be59a24b8d2173$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
235
+ position[crossAxis] += delta;
236
+ let maxHeight = $74be59a24b8d2173$var$getMaxHeight(position, boundaryDimensions, containerOffsetWithBoundary, isContainerPositioned, margins, padding, overlaySize.height, heightGrowthDirection);
237
+ if (userSetMaxHeight && userSetMaxHeight < maxHeight) maxHeight = userSetMaxHeight;
238
+ overlaySize.height = Math.min(overlaySize.height, maxHeight);
239
+ position = $74be59a24b8d2173$var$computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);
240
+ delta = $74be59a24b8d2173$var$getDelta(crossAxis, position[crossAxis], overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);
241
+ position[crossAxis] += delta;
242
+ let arrowPosition = {};
243
+ // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation
244
+ // Prefer the arrow being in the center of the trigger/overlay anchor element
245
+ // childOffset[crossAxis] + .5 * childOffset[crossSize] = absolute position with respect to the trigger's coordinate system that would place the arrow in the center of the trigger
246
+ // position[crossAxis] - margins[AXIS[crossAxis]] = value use to transform the position to a value with respect to the overlay's coordinate system. A child element's (aka arrow) position absolute's "0"
247
+ // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform
248
+ let origin = childOffset[crossAxis] - position[crossAxis] - margins[$74be59a24b8d2173$var$AXIS[crossAxis]];
249
+ let preferredArrowPosition = origin + .5 * childOffset[crossSize];
250
+ // Min/Max position limits for the arrow with respect to the overlay
251
+ const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;
252
+ var _margins_left, _margins_right, _margins_top, _margins_bottom;
253
+ // overlaySize[crossSize] - margins = true size of the overlay
254
+ const overlayMargin = $74be59a24b8d2173$var$AXIS[crossAxis] === 'left' ? ((_margins_left = margins.left) !== null && _margins_left !== void 0 ? _margins_left : 0) + ((_margins_right = margins.right) !== null && _margins_right !== void 0 ? _margins_right : 0) : ((_margins_top = margins.top) !== null && _margins_top !== void 0 ? _margins_top : 0) + ((_margins_bottom = margins.bottom) !== null && _margins_bottom !== void 0 ? _margins_bottom : 0);
255
+ const arrowMaxPosition = overlaySize[crossSize] - overlayMargin - arrowSize / 2 - arrowBoundaryOffset;
256
+ // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element
257
+ // Same margin accomodation done here as well as for the preferredArrowPosition
258
+ const arrowOverlappingChildMinEdge = childOffset[crossAxis] + arrowSize / 2 - (position[crossAxis] + margins[$74be59a24b8d2173$var$AXIS[crossAxis]]);
259
+ const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - arrowSize / 2 - (position[crossAxis] + margins[$74be59a24b8d2173$var$AXIS[crossAxis]]);
260
+ // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay
261
+ const arrowPositionOverlappingChild = (0, $7Pq2Q$clamp)(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);
262
+ arrowPosition[crossAxis] = (0, $7Pq2Q$clamp)(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);
263
+ // If there is an arrow, use that as the origin so that animations are smooth.
264
+ // Otherwise use the target edge.
265
+ ({ placement: placement, crossPlacement: crossPlacement } = placementInfo);
266
+ if (arrowSize) origin = arrowPosition[crossAxis];
267
+ else if (crossPlacement === 'right') origin += childOffset[crossSize];
268
+ else if (crossPlacement === 'center') origin += childOffset[crossSize] / 2;
269
+ let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;
270
+ let triggerAnchorPoint = {
271
+ x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,
272
+ y: placement === 'left' || placement === 'right' ? origin : crossOrigin
273
+ };
274
+ return {
275
+ position: position,
276
+ maxHeight: maxHeight,
277
+ arrowOffsetLeft: arrowPosition.left,
278
+ arrowOffsetTop: arrowPosition.top,
279
+ placement: placement,
280
+ triggerAnchorPoint: triggerAnchorPoint
281
+ };
282
+ }
283
+ function $74be59a24b8d2173$export$b3ceb0cbf1056d98(opts) {
284
+ let { placement: placement, targetNode: targetNode, overlayNode: overlayNode, scrollNode: scrollNode, padding: padding, shouldFlip: shouldFlip, boundaryElement: boundaryElement, offset: offset, crossOffset: crossOffset, maxHeight: maxHeight, arrowSize: arrowSize = 0, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = opts;
285
+ let container = overlayNode instanceof HTMLElement ? $74be59a24b8d2173$var$getContainingBlock(overlayNode) : document.documentElement;
286
+ let isViewportContainer = container === document.documentElement;
287
+ const containerPositionStyle = window.getComputedStyle(container).position;
288
+ let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
289
+ let childOffset = isViewportContainer ? $74be59a24b8d2173$var$getOffset(targetNode, false) : $74be59a24b8d2173$var$getPosition(targetNode, container, false);
290
+ if (!isViewportContainer) {
291
+ let { marginTop: marginTop, marginLeft: marginLeft } = window.getComputedStyle(targetNode);
292
+ childOffset.top += parseInt(marginTop, 10) || 0;
293
+ childOffset.left += parseInt(marginLeft, 10) || 0;
294
+ }
295
+ let overlaySize = $74be59a24b8d2173$var$getOffset(overlayNode, true);
296
+ let margins = $74be59a24b8d2173$var$getMargins(overlayNode);
297
+ var _margins_left, _margins_right;
298
+ overlaySize.width += ((_margins_left = margins.left) !== null && _margins_left !== void 0 ? _margins_left : 0) + ((_margins_right = margins.right) !== null && _margins_right !== void 0 ? _margins_right : 0);
299
+ var _margins_top, _margins_bottom;
300
+ overlaySize.height += ((_margins_top = margins.top) !== null && _margins_top !== void 0 ? _margins_top : 0) + ((_margins_bottom = margins.bottom) !== null && _margins_bottom !== void 0 ? _margins_bottom : 0);
301
+ let scrollSize = $74be59a24b8d2173$var$getScroll(scrollNode);
302
+ let boundaryDimensions = $74be59a24b8d2173$var$getContainerDimensions(boundaryElement);
303
+ let containerDimensions = $74be59a24b8d2173$var$getContainerDimensions(container);
304
+ // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
305
+ // body element's scroll. Set the container's scroll values to 0 since the overlay's edge position value in getDelta don't then need to be further offset
306
+ // by the container scroll since they are essentially the same containing element and thus in the same coordinate system
307
+ let containerOffsetWithBoundary = boundaryElement.tagName === 'BODY' ? $74be59a24b8d2173$var$getOffset(container, false) : $74be59a24b8d2173$var$getPosition(container, boundaryElement, false);
308
+ if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
309
+ containerDimensions.scroll.top = 0;
310
+ containerDimensions.scroll.left = 0;
311
+ }
312
+ return $74be59a24b8d2173$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
313
+ }
314
+ function $74be59a24b8d2173$export$4b834cebd9e5cebe(node, ignoreScale) {
315
+ let { top: top, left: left, width: width, height: height } = node.getBoundingClientRect();
316
+ // Use offsetWidth and offsetHeight if this is an HTML element, so that
317
+ // the size is not affected by scale transforms.
318
+ if (ignoreScale && node instanceof node.ownerDocument.defaultView.HTMLElement) {
319
+ width = node.offsetWidth;
320
+ height = node.offsetHeight;
321
+ }
322
+ return {
323
+ top: top,
324
+ left: left,
325
+ width: width,
326
+ height: height
327
+ };
328
+ }
329
+ function $74be59a24b8d2173$var$getOffset(node, ignoreScale) {
330
+ let { top: top, left: left, width: width, height: height } = $74be59a24b8d2173$export$4b834cebd9e5cebe(node, ignoreScale);
331
+ let { scrollTop: scrollTop, scrollLeft: scrollLeft, clientTop: clientTop, clientLeft: clientLeft } = document.documentElement;
332
+ return {
333
+ top: top + scrollTop - clientTop,
334
+ left: left + scrollLeft - clientLeft,
335
+ width: width,
336
+ height: height
337
+ };
338
+ }
339
+ function $74be59a24b8d2173$var$getPosition(node, parent, ignoreScale) {
340
+ let style = window.getComputedStyle(node);
341
+ let offset;
342
+ if (style.position === 'fixed') offset = $74be59a24b8d2173$export$4b834cebd9e5cebe(node, ignoreScale);
343
+ else {
344
+ offset = $74be59a24b8d2173$var$getOffset(node, ignoreScale);
345
+ let parentOffset = $74be59a24b8d2173$var$getOffset(parent, ignoreScale);
346
+ let parentStyle = window.getComputedStyle(parent);
347
+ parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
348
+ parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
349
+ offset.top -= parentOffset.top;
350
+ offset.left -= parentOffset.left;
351
+ }
352
+ offset.top -= parseInt(style.marginTop, 10) || 0;
353
+ offset.left -= parseInt(style.marginLeft, 10) || 0;
354
+ return offset;
355
+ }
356
+ // Returns the containing block of an element, which is the element that
357
+ // this element will be positioned relative to.
358
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block
359
+ function $74be59a24b8d2173$var$getContainingBlock(node) {
360
+ // The offsetParent of an element in most cases equals the containing block.
361
+ // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent
362
+ let offsetParent = node.offsetParent;
363
+ // The offsetParent algorithm terminates at the document body,
364
+ // even if the body is not a containing block. Double check that
365
+ // and use the documentElement if so.
366
+ if (offsetParent && offsetParent === document.body && window.getComputedStyle(offsetParent).position === 'static' && !$74be59a24b8d2173$var$isContainingBlock(offsetParent)) offsetParent = document.documentElement;
367
+ // TODO(later): handle table elements?
368
+ // The offsetParent can be null if the element has position: fixed, or a few other cases.
369
+ // We have to walk up the tree manually in this case because fixed positioned elements
370
+ // are still positioned relative to their containing block, which is not always the viewport.
371
+ if (offsetParent == null) {
372
+ offsetParent = node.parentElement;
373
+ while(offsetParent && !$74be59a24b8d2173$var$isContainingBlock(offsetParent))offsetParent = offsetParent.parentElement;
374
+ }
375
+ // Fall back to the viewport.
376
+ return offsetParent || document.documentElement;
377
+ }
378
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
379
+ function $74be59a24b8d2173$var$isContainingBlock(node) {
380
+ let style = window.getComputedStyle(node);
381
+ return style.transform !== 'none' || /transform|perspective/.test(style.willChange) || style.filter !== 'none' || style.contain === 'paint' || 'backdropFilter' in style && style.backdropFilter !== 'none' || 'WebkitBackdropFilter' in style && style.WebkitBackdropFilter !== 'none';
382
+ }
383
+
384
+
385
+ export {$74be59a24b8d2173$export$6839422d1f33cee9 as calculatePositionInternal, $74be59a24b8d2173$export$b3ceb0cbf1056d98 as calculatePosition, $74be59a24b8d2173$export$4b834cebd9e5cebe as getRect};
386
+ //# sourceMappingURL=calculatePosition.module.js.map