@react-aria/overlays 3.29.0 → 3.29.1
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.
- package/dist/calculatePosition.main.js +26 -17
- package/dist/calculatePosition.main.js.map +1 -1
- package/dist/calculatePosition.mjs +26 -18
- package/dist/calculatePosition.module.js +26 -18
- package/dist/calculatePosition.module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useOverlayPosition.main.js +1 -8
- package/dist/useOverlayPosition.main.js.map +1 -1
- package/dist/useOverlayPosition.mjs +2 -9
- package/dist/useOverlayPosition.module.js +2 -9
- package/dist/useOverlayPosition.module.js.map +1 -1
- package/package.json +2 -2
- package/src/calculatePosition.ts +22 -10
- package/src/useOverlayPosition.ts +2 -13
|
@@ -6,6 +6,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
$parcel$export(module.exports, "calculatePosition", () => $5935ba4d7da2c103$export$b3ceb0cbf1056d98);
|
|
9
|
+
$parcel$export(module.exports, "getRect", () => $5935ba4d7da2c103$export$4b834cebd9e5cebe);
|
|
9
10
|
/*
|
|
10
11
|
* Copyright 2020 Adobe. All rights reserved.
|
|
11
12
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -66,7 +67,7 @@ function $5935ba4d7da2c103$var$getContainerDimensions(containerNode) {
|
|
|
66
67
|
left = $5935ba4d7da2c103$var$visualViewport.offsetLeft;
|
|
67
68
|
}
|
|
68
69
|
} else {
|
|
69
|
-
({ width: width, height: height, top: top, left: left } = $5935ba4d7da2c103$var$getOffset(containerNode));
|
|
70
|
+
({ width: width, height: height, top: top, left: left } = $5935ba4d7da2c103$var$getOffset(containerNode, false));
|
|
70
71
|
scroll.top = containerNode.scrollTop;
|
|
71
72
|
scroll.left = containerNode.scrollLeft;
|
|
72
73
|
totalWidth = width;
|
|
@@ -292,13 +293,13 @@ function $5935ba4d7da2c103$export$b3ceb0cbf1056d98(opts) {
|
|
|
292
293
|
let isViewportContainer = container === document.documentElement;
|
|
293
294
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
294
295
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
295
|
-
let childOffset = isViewportContainer ? $5935ba4d7da2c103$var$getOffset(targetNode) : $5935ba4d7da2c103$var$getPosition(targetNode, container);
|
|
296
|
+
let childOffset = isViewportContainer ? $5935ba4d7da2c103$var$getOffset(targetNode, false) : $5935ba4d7da2c103$var$getPosition(targetNode, container, false);
|
|
296
297
|
if (!isViewportContainer) {
|
|
297
298
|
let { marginTop: marginTop, marginLeft: marginLeft } = window.getComputedStyle(targetNode);
|
|
298
299
|
childOffset.top += parseInt(marginTop, 10) || 0;
|
|
299
300
|
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
300
301
|
}
|
|
301
|
-
let overlaySize = $5935ba4d7da2c103$var$getOffset(overlayNode);
|
|
302
|
+
let overlaySize = $5935ba4d7da2c103$var$getOffset(overlayNode, true);
|
|
302
303
|
let margins = $5935ba4d7da2c103$var$getMargins(overlayNode);
|
|
303
304
|
var _margins_left, _margins_right;
|
|
304
305
|
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);
|
|
@@ -310,15 +311,30 @@ function $5935ba4d7da2c103$export$b3ceb0cbf1056d98(opts) {
|
|
|
310
311
|
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
311
312
|
// 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
|
|
312
313
|
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
|
|
313
|
-
let containerOffsetWithBoundary = boundaryElement.tagName === 'BODY' ? $5935ba4d7da2c103$var$getOffset(container) : $5935ba4d7da2c103$var$getPosition(container, boundaryElement);
|
|
314
|
+
let containerOffsetWithBoundary = boundaryElement.tagName === 'BODY' ? $5935ba4d7da2c103$var$getOffset(container, false) : $5935ba4d7da2c103$var$getPosition(container, boundaryElement, false);
|
|
314
315
|
if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
|
|
315
316
|
containerDimensions.scroll.top = 0;
|
|
316
317
|
containerDimensions.scroll.left = 0;
|
|
317
318
|
}
|
|
318
319
|
return $5935ba4d7da2c103$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
|
|
319
320
|
}
|
|
320
|
-
function $5935ba4d7da2c103$
|
|
321
|
+
function $5935ba4d7da2c103$export$4b834cebd9e5cebe(node, ignoreScale) {
|
|
321
322
|
let { top: top, left: left, width: width, height: height } = node.getBoundingClientRect();
|
|
323
|
+
// Use offsetWidth and offsetHeight if this is an HTML element, so that
|
|
324
|
+
// the size is not affected by scale transforms.
|
|
325
|
+
if (ignoreScale && node instanceof node.ownerDocument.defaultView.HTMLElement) {
|
|
326
|
+
width = node.offsetWidth;
|
|
327
|
+
height = node.offsetHeight;
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
top: top,
|
|
331
|
+
left: left,
|
|
332
|
+
width: width,
|
|
333
|
+
height: height
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function $5935ba4d7da2c103$var$getOffset(node, ignoreScale) {
|
|
337
|
+
let { top: top, left: left, width: width, height: height } = $5935ba4d7da2c103$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
322
338
|
let { scrollTop: scrollTop, scrollLeft: scrollLeft, clientTop: clientTop, clientLeft: clientLeft } = document.documentElement;
|
|
323
339
|
return {
|
|
324
340
|
top: top + scrollTop - clientTop,
|
|
@@ -327,20 +343,13 @@ function $5935ba4d7da2c103$var$getOffset(node) {
|
|
|
327
343
|
height: height
|
|
328
344
|
};
|
|
329
345
|
}
|
|
330
|
-
function $5935ba4d7da2c103$var$getPosition(node, parent) {
|
|
346
|
+
function $5935ba4d7da2c103$var$getPosition(node, parent, ignoreScale) {
|
|
331
347
|
let style = window.getComputedStyle(node);
|
|
332
348
|
let offset;
|
|
333
|
-
if (style.position === 'fixed')
|
|
334
|
-
|
|
335
|
-
offset =
|
|
336
|
-
|
|
337
|
-
left: left,
|
|
338
|
-
width: width,
|
|
339
|
-
height: height
|
|
340
|
-
};
|
|
341
|
-
} else {
|
|
342
|
-
offset = $5935ba4d7da2c103$var$getOffset(node);
|
|
343
|
-
let parentOffset = $5935ba4d7da2c103$var$getOffset(parent);
|
|
349
|
+
if (style.position === 'fixed') offset = $5935ba4d7da2c103$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
350
|
+
else {
|
|
351
|
+
offset = $5935ba4d7da2c103$var$getOffset(node, ignoreScale);
|
|
352
|
+
let parentOffset = $5935ba4d7da2c103$var$getOffset(parent, ignoreScale);
|
|
344
353
|
let parentStyle = window.getComputedStyle(parent);
|
|
345
354
|
parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
|
|
346
355
|
parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAgED,MAAM,6BAAO;IACX,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,0CAAoB;IACxB,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,mCAAa;IACjB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,kCAAY;IAChB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,mCAAa;IACjB,OAAO;IACP,QAAQ;AACV;AAEA,MAAM,+CAAyB,CAAC;AAEhC,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAE/E,SAAS,6CAAuB,aAAsB;IACpD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ACE,MAAM,SAAS,KAAK,UACpB,wBAAwB,IAAI,CAAC,MAAM,UAAU,KAC7C,MAAM,MAAM,KAAK,UACjB,MAAM,OAAO,KAAK,WACjB,oBAAoB,SAAS,MAAM,cAAc,KAAK,UACtD,0BAA0B,SAAS,MAAM,oBAAoB,KAAK;AAEvE","sources":["packages/@react-aria/overlays/src/calculatePosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Axis, Placement, PlacementAxis, SizeAxis} from '@react-types/overlays';\nimport {clamp, isWebKit} from '@react-aria/utils';\n\ninterface Position {\n top?: number,\n left?: number,\n bottom?: number,\n right?: number\n}\n\ninterface Dimensions {\n width: number,\n height: number,\n totalWidth: number,\n totalHeight: number,\n top: number,\n left: number,\n scroll: Position\n}\n\ninterface ParsedPlacement {\n placement: PlacementAxis,\n crossPlacement: PlacementAxis,\n axis: Axis,\n crossAxis: Axis,\n size: SizeAxis,\n crossSize: SizeAxis\n}\n\ninterface Offset {\n top: number,\n left: number,\n width: number,\n height: number\n}\n\ninterface PositionOpts {\n arrowSize: number,\n placement: Placement,\n targetNode: Element,\n overlayNode: Element,\n scrollNode: Element,\n padding: number,\n shouldFlip: boolean,\n boundaryElement: Element,\n offset: number,\n crossOffset: number,\n maxHeight?: number,\n arrowBoundaryOffset?: number\n}\n\ntype HeightGrowthDirection = 'top' | 'bottom';\n\nexport interface PositionResult {\n position: Position,\n arrowOffsetLeft?: number,\n arrowOffsetTop?: number,\n triggerAnchorPoint: {x: number, y: number},\n maxHeight: number,\n placement: PlacementAxis\n}\n\nconst AXIS = {\n top: 'top',\n bottom: 'top',\n left: 'left',\n right: 'left'\n};\n\nconst FLIPPED_DIRECTION = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left'\n};\n\nconst CROSS_AXIS = {\n top: 'left',\n left: 'top'\n};\n\nconst AXIS_SIZE = {\n top: 'height',\n left: 'width'\n};\n\nconst TOTAL_SIZE = {\n width: 'totalWidth',\n height: 'totalHeight'\n};\n\nconst PARSED_PLACEMENT_CACHE = {};\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\nfunction getContainerDimensions(containerNode: Element): Dimensions {\n let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;\n let scroll: Position = {};\n let isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n if (containerNode.tagName === 'BODY') {\n let documentElement = document.documentElement;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n if (visualViewport) {\n top = visualViewport.offsetTop;\n left = visualViewport.offsetLeft;\n }\n } else {\n ({width, height, top, left} = getOffset(containerNode));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (isWebKit() && (containerNode.tagName === 'BODY' || containerNode.tagName === 'HTML') && isPinchZoomedIn) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return {width, height, totalWidth, totalHeight, scroll, top, left};\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n top: node.scrollTop,\n left: node.scrollLeft,\n width: node.scrollWidth,\n height: node.scrollHeight\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: Axis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n let containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n let boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n let boundaryStartEdge = boundaryDimensions.scroll[AXIS[axis]] + padding;\n let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[AXIS[axis]] - padding;\n let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);\n } else {\n return 0;\n }\n}\n\nfunction getMargins(node: Element): Position {\n let style = window.getComputedStyle(node);\n return {\n top: parseInt(style.marginTop, 10) || 0,\n bottom: parseInt(style.marginBottom, 10) || 0,\n left: parseInt(style.marginLeft, 10) || 0,\n right: parseInt(style.marginRight, 10) || 0\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n if (PARSED_PLACEMENT_CACHE[input]) {\n return PARSED_PLACEMENT_CACHE[input];\n }\n\n let [placement, crossPlacement] = input.split(' ');\n let axis: Axis = AXIS[placement] || 'right';\n let crossAxis: Axis = CROSS_AXIS[axis];\n\n if (!AXIS[crossPlacement]) {\n crossPlacement = 'center';\n }\n\n let size = AXIS_SIZE[axis];\n let crossSize = AXIS_SIZE[crossAxis];\n PARSED_PLACEMENT_CACHE[input] = {placement, crossPlacement, axis, crossAxis, size, crossSize};\n return PARSED_PLACEMENT_CACHE[input];\n}\n\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number\n) {\n let {placement, crossPlacement, axis, crossAxis, size, crossSize} = placementInfo;\n let position: Position = {};\n\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n if (crossPlacement === 'center') {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis]! += ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis]! += (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }/* else {\n the overlay top should match the button top\n } */\n\n position[crossAxis]! += crossOffset;\n\n // overlay top overlapping arrow with button bottom\n const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;\n // overlay bottom overlapping arrow with button top\n const maxPosition = childOffset[crossAxis] + childOffset[crossSize] - arrowSize - arrowBoundaryOffset;\n position[crossAxis] = clamp(position[crossAxis]!, minPosition, maxPosition);\n\n // 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.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container, which should be as large as boundaryDimensions.\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary[size] : boundaryDimensions[TOTAL_SIZE[size]]);\n position[FLIPPED_DIRECTION[axis]] = Math.floor(containerHeight - childOffset[axis] + offset);\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection\n) {\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[TOTAL_SIZE.height]);\n // 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\n // used in computePosition.\n let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - (position.bottom ?? 0) - overlayHeight);\n let maxHeight = heightGrowthDirection !== 'top' ?\n // We want the distance between the top of the overlay to the bottom of the boundary\n Math.max(0,\n (boundaryDimensions.height + boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the bottom of the boundary\n - overlayTop // this is the top of the overlay\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n )\n // We want the distance between the bottom of the overlay to the top of the boundary\n : Math.max(0,\n (overlayTop + overlayHeight) // this is the bottom of the overlay\n - (boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the top of the boundary\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n );\n return Math.min(boundaryDimensions.height - (padding * 2), maxHeight);\n}\n\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement\n) {\n let {placement, axis, size} = placementInfo;\n if (placement === axis) {\n return Math.max(0, childOffset[axis] - boundaryDimensions[axis] - (boundaryDimensions.scroll[axis] ?? 0) + containerOffsetWithBoundary[axis] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n }\n\n return Math.max(0, boundaryDimensions[size] + boundaryDimensions[axis] + boundaryDimensions.scroll[axis] - containerOffsetWithBoundary[axis] - childOffset[axis] - childOffset[size] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n let {size, crossAxis, crossSize, placement, crossPlacement} = placementInfo;\n let position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let normalizedOffset = offset;\n let space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && scrollSize[size] > space) {\n let flippedPlacementInfo = parsePlacement(`${FLIPPED_DIRECTION[placement]} ${crossPlacement}` as Placement);\n let flippedPosition = computePosition(childOffset, boundaryDimensions, overlaySize, flippedPlacementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n let heightGrowthDirection: HeightGrowthDirection = 'bottom';\n if (placementInfo.axis === 'top') {\n if (placementInfo.placement === 'top') {\n heightGrowthDirection = 'top';\n } else if (placementInfo.placement === 'bottom') {\n heightGrowthDirection = 'bottom';\n }\n } else if (placementInfo.crossAxis === 'top') {\n if (placementInfo.crossPlacement === 'top') {\n heightGrowthDirection = 'bottom';\n } else if (placementInfo.crossPlacement === 'bottom') {\n heightGrowthDirection = 'top';\n }\n }\n\n let delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection\n );\n\n if (userSetMaxHeight && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n\n position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // 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\n // 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\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin = childOffset[crossAxis] - position[crossAxis]! - margins[AXIS[crossAxis]];\n let preferredArrowPosition = origin + .5 * childOffset[crossSize];\n\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin = AXIS[crossAxis] === 'left' ? (margins.left ?? 0) + (margins.right ?? 0) : (margins.top ?? 0) + (margins.bottom ?? 0);\n const arrowMaxPosition = overlaySize[crossSize] - overlayMargin - (arrowSize / 2) - arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge = childOffset[crossAxis] + (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);\n arrowPosition[crossAxis] = clamp(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);\n\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n ({placement, crossPlacement} = placementInfo);\n if (arrowSize) {\n origin = arrowPosition[crossAxis];\n } else if (crossPlacement === 'right') {\n origin += childOffset[crossSize];\n } else if (crossPlacement === 'center') {\n origin += childOffset[crossSize] / 2;\n }\n\n let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;\n let triggerAnchorPoint = {\n x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,\n y: placement === 'left' || placement === 'right' ? origin : crossOrigin\n };\n\n return {\n position,\n maxHeight: maxHeight,\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n placement,\n triggerAnchorPoint\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n let {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize = 0,\n arrowBoundaryOffset = 0\n } = opts;\n\n let container = overlayNode instanceof HTMLElement ? getContainingBlock(overlayNode) : document.documentElement;\n let isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';\n let childOffset: Offset = isViewportContainer ? getOffset(targetNode) : getPosition(targetNode, container);\n\n if (!isViewportContainer) {\n let {marginTop, marginLeft} = window.getComputedStyle(targetNode);\n childOffset.top += parseInt(marginTop, 10) || 0;\n childOffset.left += parseInt(marginLeft, 10) || 0;\n }\n\n let overlaySize: Offset = getOffset(overlayNode);\n let margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n\n let scrollSize = getScroll(scrollNode);\n let boundaryDimensions = getContainerDimensions(boundaryElement);\n let containerDimensions = getContainerDimensions(container);\n // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the\n // 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\n // by the container scroll since they are essentially the same containing element and thus in the same coordinate system\n let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container) : getPosition(container, boundaryElement);\n if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {\n containerDimensions.scroll.top = 0;\n containerDimensions.scroll.left = 0;\n }\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n );\n}\n\nfunction getOffset(node: Element): Offset {\n let {top, left, width, height} = node.getBoundingClientRect();\n let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;\n return {\n top: top + scrollTop - clientTop,\n left: left + scrollLeft - clientLeft,\n width,\n height\n };\n}\n\nfunction getPosition(node: Element, parent: Element): Offset {\n let style = window.getComputedStyle(node);\n let offset: Offset;\n if (style.position === 'fixed') {\n let {top, left, width, height} = node.getBoundingClientRect();\n offset = {top, left, width, height};\n } else {\n offset = getOffset(node);\n let parentOffset = getOffset(parent);\n let parentStyle = window.getComputedStyle(parent);\n parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;\n parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= parseInt(style.marginTop, 10) || 0;\n offset.left -= parseInt(style.marginLeft, 10) || 0;\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let offsetParent = node.offsetParent;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === 'static' &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // TODO(later): handle table elements?\n\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (offsetParent == null) {\n offsetParent = node.parentElement;\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = offsetParent.parentElement;\n }\n }\n\n // Fall back to the viewport.\n return offsetParent || document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n let style = window.getComputedStyle(node);\n return (\n style.transform !== 'none' ||\n /transform|perspective/.test(style.willChange) ||\n style.filter !== 'none' ||\n style.contain === 'paint' ||\n ('backdropFilter' in style && style.backdropFilter !== 'none') ||\n ('WebkitBackdropFilter' in style && style.WebkitBackdropFilter !== 'none')\n );\n}\n"],"names":[],"version":3,"file":"calculatePosition.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAgED,MAAM,6BAAO;IACX,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,0CAAoB;IACxB,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,mCAAa;IACjB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,kCAAY;IAChB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,mCAAa;IACjB,OAAO;IACP,QAAQ;AACV;AAEA,MAAM,+CAAyB,CAAC;AAEhC,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAE/E,SAAS,6CAAuB,aAAsB;IACpD,IAAI,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,MAAM,GAAG,OAAO;IAC5E,IAAI,SAAmB,CAAC;QACD;IAAvB,IAAI,kBAAkB,AAAC,CAAA,CAAA,wBAAA,iDAAA,2DAAA,qCAAgB,KAAK,cAArB,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AAe;AACjD;AAEA,qGAAqG;AACrG,SAAS,wCAAkB,IAAa;IACtC,IAAI,QAAQ,OAAO,gBAAgB,CAAC;IACpC,OACE,MAAM,SAAS,KAAK,UACpB,wBAAwB,IAAI,CAAC,MAAM,UAAU,KAC7C,MAAM,MAAM,KAAK,UACjB,MAAM,OAAO,KAAK,WACjB,oBAAoB,SAAS,MAAM,cAAc,KAAK,UACtD,0BAA0B,SAAS,MAAM,oBAAoB,KAAK;AAEvE","sources":["packages/@react-aria/overlays/src/calculatePosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Axis, Placement, PlacementAxis, SizeAxis} from '@react-types/overlays';\nimport {clamp, isWebKit} from '@react-aria/utils';\n\ninterface Position {\n top?: number,\n left?: number,\n bottom?: number,\n right?: number\n}\n\ninterface Dimensions {\n width: number,\n height: number,\n totalWidth: number,\n totalHeight: number,\n top: number,\n left: number,\n scroll: Position\n}\n\ninterface ParsedPlacement {\n placement: PlacementAxis,\n crossPlacement: PlacementAxis,\n axis: Axis,\n crossAxis: Axis,\n size: SizeAxis,\n crossSize: SizeAxis\n}\n\ninterface Offset {\n top: number,\n left: number,\n width: number,\n height: number\n}\n\ninterface PositionOpts {\n arrowSize: number,\n placement: Placement,\n targetNode: Element,\n overlayNode: Element,\n scrollNode: Element,\n padding: number,\n shouldFlip: boolean,\n boundaryElement: Element,\n offset: number,\n crossOffset: number,\n maxHeight?: number,\n arrowBoundaryOffset?: number\n}\n\ntype HeightGrowthDirection = 'top' | 'bottom';\n\nexport interface PositionResult {\n position: Position,\n arrowOffsetLeft?: number,\n arrowOffsetTop?: number,\n triggerAnchorPoint: {x: number, y: number},\n maxHeight: number,\n placement: PlacementAxis\n}\n\nconst AXIS = {\n top: 'top',\n bottom: 'top',\n left: 'left',\n right: 'left'\n};\n\nconst FLIPPED_DIRECTION = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left'\n};\n\nconst CROSS_AXIS = {\n top: 'left',\n left: 'top'\n};\n\nconst AXIS_SIZE = {\n top: 'height',\n left: 'width'\n};\n\nconst TOTAL_SIZE = {\n width: 'totalWidth',\n height: 'totalHeight'\n};\n\nconst PARSED_PLACEMENT_CACHE = {};\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\nfunction getContainerDimensions(containerNode: Element): Dimensions {\n let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;\n let scroll: Position = {};\n let isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n if (containerNode.tagName === 'BODY') {\n let documentElement = document.documentElement;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n if (visualViewport) {\n top = visualViewport.offsetTop;\n left = visualViewport.offsetLeft;\n }\n } else {\n ({width, height, top, left} = getOffset(containerNode, false));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (isWebKit() && (containerNode.tagName === 'BODY' || containerNode.tagName === 'HTML') && isPinchZoomedIn) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return {width, height, totalWidth, totalHeight, scroll, top, left};\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n top: node.scrollTop,\n left: node.scrollLeft,\n width: node.scrollWidth,\n height: node.scrollHeight\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: Axis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n let containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n let boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n let boundaryStartEdge = boundaryDimensions.scroll[AXIS[axis]] + padding;\n let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[AXIS[axis]] - padding;\n let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);\n } else {\n return 0;\n }\n}\n\nfunction getMargins(node: Element): Position {\n let style = window.getComputedStyle(node);\n return {\n top: parseInt(style.marginTop, 10) || 0,\n bottom: parseInt(style.marginBottom, 10) || 0,\n left: parseInt(style.marginLeft, 10) || 0,\n right: parseInt(style.marginRight, 10) || 0\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n if (PARSED_PLACEMENT_CACHE[input]) {\n return PARSED_PLACEMENT_CACHE[input];\n }\n\n let [placement, crossPlacement] = input.split(' ');\n let axis: Axis = AXIS[placement] || 'right';\n let crossAxis: Axis = CROSS_AXIS[axis];\n\n if (!AXIS[crossPlacement]) {\n crossPlacement = 'center';\n }\n\n let size = AXIS_SIZE[axis];\n let crossSize = AXIS_SIZE[crossAxis];\n PARSED_PLACEMENT_CACHE[input] = {placement, crossPlacement, axis, crossAxis, size, crossSize};\n return PARSED_PLACEMENT_CACHE[input];\n}\n\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number\n) {\n let {placement, crossPlacement, axis, crossAxis, size, crossSize} = placementInfo;\n let position: Position = {};\n\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n if (crossPlacement === 'center') {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis]! += ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis]! += (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }/* else {\n the overlay top should match the button top\n } */\n\n position[crossAxis]! += crossOffset;\n\n // overlay top overlapping arrow with button bottom\n const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;\n // overlay bottom overlapping arrow with button top\n const maxPosition = childOffset[crossAxis] + childOffset[crossSize] - arrowSize - arrowBoundaryOffset;\n position[crossAxis] = clamp(position[crossAxis]!, minPosition, maxPosition);\n\n // 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.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container, which should be as large as boundaryDimensions.\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary[size] : boundaryDimensions[TOTAL_SIZE[size]]);\n position[FLIPPED_DIRECTION[axis]] = Math.floor(containerHeight - childOffset[axis] + offset);\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection\n) {\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[TOTAL_SIZE.height]);\n // 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\n // used in computePosition.\n let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - (position.bottom ?? 0) - overlayHeight);\n let maxHeight = heightGrowthDirection !== 'top' ?\n // We want the distance between the top of the overlay to the bottom of the boundary\n Math.max(0,\n (boundaryDimensions.height + boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the bottom of the boundary\n - overlayTop // this is the top of the overlay\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n )\n // We want the distance between the bottom of the overlay to the top of the boundary\n : Math.max(0,\n (overlayTop + overlayHeight) // this is the bottom of the overlay\n - (boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the top of the boundary\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n );\n return Math.min(boundaryDimensions.height - (padding * 2), maxHeight);\n}\n\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement\n) {\n let {placement, axis, size} = placementInfo;\n if (placement === axis) {\n return Math.max(0, childOffset[axis] - boundaryDimensions[axis] - (boundaryDimensions.scroll[axis] ?? 0) + containerOffsetWithBoundary[axis] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n }\n\n return Math.max(0, boundaryDimensions[size] + boundaryDimensions[axis] + boundaryDimensions.scroll[axis] - containerOffsetWithBoundary[axis] - childOffset[axis] - childOffset[size] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n let {size, crossAxis, crossSize, placement, crossPlacement} = placementInfo;\n let position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let normalizedOffset = offset;\n let space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && scrollSize[size] > space) {\n let flippedPlacementInfo = parsePlacement(`${FLIPPED_DIRECTION[placement]} ${crossPlacement}` as Placement);\n let flippedPosition = computePosition(childOffset, boundaryDimensions, overlaySize, flippedPlacementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n let heightGrowthDirection: HeightGrowthDirection = 'bottom';\n if (placementInfo.axis === 'top') {\n if (placementInfo.placement === 'top') {\n heightGrowthDirection = 'top';\n } else if (placementInfo.placement === 'bottom') {\n heightGrowthDirection = 'bottom';\n }\n } else if (placementInfo.crossAxis === 'top') {\n if (placementInfo.crossPlacement === 'top') {\n heightGrowthDirection = 'bottom';\n } else if (placementInfo.crossPlacement === 'bottom') {\n heightGrowthDirection = 'top';\n }\n }\n\n let delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection\n );\n\n if (userSetMaxHeight && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n\n position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // 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\n // 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\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin = childOffset[crossAxis] - position[crossAxis]! - margins[AXIS[crossAxis]];\n let preferredArrowPosition = origin + .5 * childOffset[crossSize];\n\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin = AXIS[crossAxis] === 'left' ? (margins.left ?? 0) + (margins.right ?? 0) : (margins.top ?? 0) + (margins.bottom ?? 0);\n const arrowMaxPosition = overlaySize[crossSize] - overlayMargin - (arrowSize / 2) - arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge = childOffset[crossAxis] + (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);\n arrowPosition[crossAxis] = clamp(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);\n\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n ({placement, crossPlacement} = placementInfo);\n if (arrowSize) {\n origin = arrowPosition[crossAxis];\n } else if (crossPlacement === 'right') {\n origin += childOffset[crossSize];\n } else if (crossPlacement === 'center') {\n origin += childOffset[crossSize] / 2;\n }\n\n let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;\n let triggerAnchorPoint = {\n x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,\n y: placement === 'left' || placement === 'right' ? origin : crossOrigin\n };\n\n return {\n position,\n maxHeight: maxHeight,\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n placement,\n triggerAnchorPoint\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n let {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize = 0,\n arrowBoundaryOffset = 0\n } = opts;\n\n let container = overlayNode instanceof HTMLElement ? getContainingBlock(overlayNode) : document.documentElement;\n let isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';\n let childOffset: Offset = isViewportContainer ? getOffset(targetNode, false) : getPosition(targetNode, container, false);\n\n if (!isViewportContainer) {\n let {marginTop, marginLeft} = window.getComputedStyle(targetNode);\n childOffset.top += parseInt(marginTop, 10) || 0;\n childOffset.left += parseInt(marginLeft, 10) || 0;\n }\n\n let overlaySize: Offset = getOffset(overlayNode, true);\n let margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n\n let scrollSize = getScroll(scrollNode);\n let boundaryDimensions = getContainerDimensions(boundaryElement);\n let containerDimensions = getContainerDimensions(container);\n // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the\n // 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\n // by the container scroll since they are essentially the same containing element and thus in the same coordinate system\n let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container, false) : getPosition(container, boundaryElement, false);\n if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {\n containerDimensions.scroll.top = 0;\n containerDimensions.scroll.left = 0;\n }\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n );\n}\n\nexport function getRect(node: Element, ignoreScale: boolean) {\n let {top, left, width, height} = node.getBoundingClientRect();\n\n // Use offsetWidth and offsetHeight if this is an HTML element, so that \n // the size is not affected by scale transforms.\n if (ignoreScale && node instanceof node.ownerDocument.defaultView!.HTMLElement) {\n width = node.offsetWidth;\n height = node.offsetHeight;\n }\n\n return {top, left, width, height};\n}\n\nfunction getOffset(node: Element, ignoreScale: boolean): Offset {\n let {top, left, width, height} = getRect(node, ignoreScale);\n let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;\n return {\n top: top + scrollTop - clientTop,\n left: left + scrollLeft - clientLeft,\n width,\n height\n };\n}\n\nfunction getPosition(node: Element, parent: Element, ignoreScale: boolean): Offset {\n let style = window.getComputedStyle(node);\n let offset: Offset;\n if (style.position === 'fixed') {\n offset = getRect(node, ignoreScale);\n } else {\n offset = getOffset(node, ignoreScale);\n let parentOffset = getOffset(parent, ignoreScale);\n let parentStyle = window.getComputedStyle(parent);\n parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;\n parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= parseInt(style.marginTop, 10) || 0;\n offset.left -= parseInt(style.marginLeft, 10) || 0;\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let offsetParent = node.offsetParent;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === 'static' &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // TODO(later): handle table elements?\n\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (offsetParent == null) {\n offsetParent = node.parentElement;\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = offsetParent.parentElement;\n }\n }\n\n // Fall back to the viewport.\n return offsetParent || document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n let style = window.getComputedStyle(node);\n return (\n style.transform !== 'none' ||\n /transform|perspective/.test(style.willChange) ||\n style.filter !== 'none' ||\n style.contain === 'paint' ||\n ('backdropFilter' in style && style.backdropFilter !== 'none') ||\n ('WebkitBackdropFilter' in style && style.WebkitBackdropFilter !== 'none')\n );\n}\n"],"names":[],"version":3,"file":"calculatePosition.main.js.map"}
|
|
@@ -60,7 +60,7 @@ function $edcf132a9284368a$var$getContainerDimensions(containerNode) {
|
|
|
60
60
|
left = $edcf132a9284368a$var$visualViewport.offsetLeft;
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
({ width: width, height: height, top: top, left: left } = $edcf132a9284368a$var$getOffset(containerNode));
|
|
63
|
+
({ width: width, height: height, top: top, left: left } = $edcf132a9284368a$var$getOffset(containerNode, false));
|
|
64
64
|
scroll.top = containerNode.scrollTop;
|
|
65
65
|
scroll.left = containerNode.scrollLeft;
|
|
66
66
|
totalWidth = width;
|
|
@@ -286,13 +286,13 @@ function $edcf132a9284368a$export$b3ceb0cbf1056d98(opts) {
|
|
|
286
286
|
let isViewportContainer = container === document.documentElement;
|
|
287
287
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
288
288
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
289
|
-
let childOffset = isViewportContainer ? $edcf132a9284368a$var$getOffset(targetNode) : $edcf132a9284368a$var$getPosition(targetNode, container);
|
|
289
|
+
let childOffset = isViewportContainer ? $edcf132a9284368a$var$getOffset(targetNode, false) : $edcf132a9284368a$var$getPosition(targetNode, container, false);
|
|
290
290
|
if (!isViewportContainer) {
|
|
291
291
|
let { marginTop: marginTop, marginLeft: marginLeft } = window.getComputedStyle(targetNode);
|
|
292
292
|
childOffset.top += parseInt(marginTop, 10) || 0;
|
|
293
293
|
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
294
294
|
}
|
|
295
|
-
let overlaySize = $edcf132a9284368a$var$getOffset(overlayNode);
|
|
295
|
+
let overlaySize = $edcf132a9284368a$var$getOffset(overlayNode, true);
|
|
296
296
|
let margins = $edcf132a9284368a$var$getMargins(overlayNode);
|
|
297
297
|
var _margins_left, _margins_right;
|
|
298
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);
|
|
@@ -304,15 +304,30 @@ function $edcf132a9284368a$export$b3ceb0cbf1056d98(opts) {
|
|
|
304
304
|
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
305
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
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' ? $edcf132a9284368a$var$getOffset(container) : $edcf132a9284368a$var$getPosition(container, boundaryElement);
|
|
307
|
+
let containerOffsetWithBoundary = boundaryElement.tagName === 'BODY' ? $edcf132a9284368a$var$getOffset(container, false) : $edcf132a9284368a$var$getPosition(container, boundaryElement, false);
|
|
308
308
|
if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
|
|
309
309
|
containerDimensions.scroll.top = 0;
|
|
310
310
|
containerDimensions.scroll.left = 0;
|
|
311
311
|
}
|
|
312
312
|
return $edcf132a9284368a$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
|
|
313
313
|
}
|
|
314
|
-
function $edcf132a9284368a$
|
|
314
|
+
function $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale) {
|
|
315
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 $edcf132a9284368a$var$getOffset(node, ignoreScale) {
|
|
330
|
+
let { top: top, left: left, width: width, height: height } = $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
316
331
|
let { scrollTop: scrollTop, scrollLeft: scrollLeft, clientTop: clientTop, clientLeft: clientLeft } = document.documentElement;
|
|
317
332
|
return {
|
|
318
333
|
top: top + scrollTop - clientTop,
|
|
@@ -321,20 +336,13 @@ function $edcf132a9284368a$var$getOffset(node) {
|
|
|
321
336
|
height: height
|
|
322
337
|
};
|
|
323
338
|
}
|
|
324
|
-
function $edcf132a9284368a$var$getPosition(node, parent) {
|
|
339
|
+
function $edcf132a9284368a$var$getPosition(node, parent, ignoreScale) {
|
|
325
340
|
let style = window.getComputedStyle(node);
|
|
326
341
|
let offset;
|
|
327
|
-
if (style.position === 'fixed')
|
|
328
|
-
|
|
329
|
-
offset =
|
|
330
|
-
|
|
331
|
-
left: left,
|
|
332
|
-
width: width,
|
|
333
|
-
height: height
|
|
334
|
-
};
|
|
335
|
-
} else {
|
|
336
|
-
offset = $edcf132a9284368a$var$getOffset(node);
|
|
337
|
-
let parentOffset = $edcf132a9284368a$var$getOffset(parent);
|
|
342
|
+
if (style.position === 'fixed') offset = $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
343
|
+
else {
|
|
344
|
+
offset = $edcf132a9284368a$var$getOffset(node, ignoreScale);
|
|
345
|
+
let parentOffset = $edcf132a9284368a$var$getOffset(parent, ignoreScale);
|
|
338
346
|
let parentStyle = window.getComputedStyle(parent);
|
|
339
347
|
parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
|
|
340
348
|
parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
|
|
@@ -374,5 +382,5 @@ function $edcf132a9284368a$var$isContainingBlock(node) {
|
|
|
374
382
|
}
|
|
375
383
|
|
|
376
384
|
|
|
377
|
-
export {$edcf132a9284368a$export$6839422d1f33cee9 as calculatePositionInternal, $edcf132a9284368a$export$b3ceb0cbf1056d98 as calculatePosition};
|
|
385
|
+
export {$edcf132a9284368a$export$6839422d1f33cee9 as calculatePositionInternal, $edcf132a9284368a$export$b3ceb0cbf1056d98 as calculatePosition, $edcf132a9284368a$export$4b834cebd9e5cebe as getRect};
|
|
378
386
|
//# sourceMappingURL=calculatePosition.module.js.map
|
|
@@ -60,7 +60,7 @@ function $edcf132a9284368a$var$getContainerDimensions(containerNode) {
|
|
|
60
60
|
left = $edcf132a9284368a$var$visualViewport.offsetLeft;
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
({ width: width, height: height, top: top, left: left } = $edcf132a9284368a$var$getOffset(containerNode));
|
|
63
|
+
({ width: width, height: height, top: top, left: left } = $edcf132a9284368a$var$getOffset(containerNode, false));
|
|
64
64
|
scroll.top = containerNode.scrollTop;
|
|
65
65
|
scroll.left = containerNode.scrollLeft;
|
|
66
66
|
totalWidth = width;
|
|
@@ -286,13 +286,13 @@ function $edcf132a9284368a$export$b3ceb0cbf1056d98(opts) {
|
|
|
286
286
|
let isViewportContainer = container === document.documentElement;
|
|
287
287
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
288
288
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
289
|
-
let childOffset = isViewportContainer ? $edcf132a9284368a$var$getOffset(targetNode) : $edcf132a9284368a$var$getPosition(targetNode, container);
|
|
289
|
+
let childOffset = isViewportContainer ? $edcf132a9284368a$var$getOffset(targetNode, false) : $edcf132a9284368a$var$getPosition(targetNode, container, false);
|
|
290
290
|
if (!isViewportContainer) {
|
|
291
291
|
let { marginTop: marginTop, marginLeft: marginLeft } = window.getComputedStyle(targetNode);
|
|
292
292
|
childOffset.top += parseInt(marginTop, 10) || 0;
|
|
293
293
|
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
294
294
|
}
|
|
295
|
-
let overlaySize = $edcf132a9284368a$var$getOffset(overlayNode);
|
|
295
|
+
let overlaySize = $edcf132a9284368a$var$getOffset(overlayNode, true);
|
|
296
296
|
let margins = $edcf132a9284368a$var$getMargins(overlayNode);
|
|
297
297
|
var _margins_left, _margins_right;
|
|
298
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);
|
|
@@ -304,15 +304,30 @@ function $edcf132a9284368a$export$b3ceb0cbf1056d98(opts) {
|
|
|
304
304
|
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
305
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
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' ? $edcf132a9284368a$var$getOffset(container) : $edcf132a9284368a$var$getPosition(container, boundaryElement);
|
|
307
|
+
let containerOffsetWithBoundary = boundaryElement.tagName === 'BODY' ? $edcf132a9284368a$var$getOffset(container, false) : $edcf132a9284368a$var$getPosition(container, boundaryElement, false);
|
|
308
308
|
if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
|
|
309
309
|
containerDimensions.scroll.top = 0;
|
|
310
310
|
containerDimensions.scroll.left = 0;
|
|
311
311
|
}
|
|
312
312
|
return $edcf132a9284368a$export$6839422d1f33cee9(placement, childOffset, overlaySize, scrollSize, margins, padding, shouldFlip, boundaryDimensions, containerDimensions, containerOffsetWithBoundary, offset, crossOffset, isContainerPositioned, maxHeight, arrowSize, arrowBoundaryOffset);
|
|
313
313
|
}
|
|
314
|
-
function $edcf132a9284368a$
|
|
314
|
+
function $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale) {
|
|
315
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 $edcf132a9284368a$var$getOffset(node, ignoreScale) {
|
|
330
|
+
let { top: top, left: left, width: width, height: height } = $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
316
331
|
let { scrollTop: scrollTop, scrollLeft: scrollLeft, clientTop: clientTop, clientLeft: clientLeft } = document.documentElement;
|
|
317
332
|
return {
|
|
318
333
|
top: top + scrollTop - clientTop,
|
|
@@ -321,20 +336,13 @@ function $edcf132a9284368a$var$getOffset(node) {
|
|
|
321
336
|
height: height
|
|
322
337
|
};
|
|
323
338
|
}
|
|
324
|
-
function $edcf132a9284368a$var$getPosition(node, parent) {
|
|
339
|
+
function $edcf132a9284368a$var$getPosition(node, parent, ignoreScale) {
|
|
325
340
|
let style = window.getComputedStyle(node);
|
|
326
341
|
let offset;
|
|
327
|
-
if (style.position === 'fixed')
|
|
328
|
-
|
|
329
|
-
offset =
|
|
330
|
-
|
|
331
|
-
left: left,
|
|
332
|
-
width: width,
|
|
333
|
-
height: height
|
|
334
|
-
};
|
|
335
|
-
} else {
|
|
336
|
-
offset = $edcf132a9284368a$var$getOffset(node);
|
|
337
|
-
let parentOffset = $edcf132a9284368a$var$getOffset(parent);
|
|
342
|
+
if (style.position === 'fixed') offset = $edcf132a9284368a$export$4b834cebd9e5cebe(node, ignoreScale);
|
|
343
|
+
else {
|
|
344
|
+
offset = $edcf132a9284368a$var$getOffset(node, ignoreScale);
|
|
345
|
+
let parentOffset = $edcf132a9284368a$var$getOffset(parent, ignoreScale);
|
|
338
346
|
let parentStyle = window.getComputedStyle(parent);
|
|
339
347
|
parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
|
|
340
348
|
parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
|
|
@@ -374,5 +382,5 @@ function $edcf132a9284368a$var$isContainingBlock(node) {
|
|
|
374
382
|
}
|
|
375
383
|
|
|
376
384
|
|
|
377
|
-
export {$edcf132a9284368a$export$6839422d1f33cee9 as calculatePositionInternal, $edcf132a9284368a$export$b3ceb0cbf1056d98 as calculatePosition};
|
|
385
|
+
export {$edcf132a9284368a$export$6839422d1f33cee9 as calculatePositionInternal, $edcf132a9284368a$export$b3ceb0cbf1056d98 as calculatePosition, $edcf132a9284368a$export$4b834cebd9e5cebe as getRect};
|
|
378
386
|
//# sourceMappingURL=calculatePosition.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAgED,MAAM,6BAAO;IACX,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,0CAAoB;IACxB,KAAK;IACL,QAAQ;IACR,MAAM;IACN,OAAO;AACT;AAEA,MAAM,mCAAa;IACjB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,kCAAY;IAChB,KAAK;IACL,MAAM;AACR;AAEA,MAAM,mCAAa;IACjB,OAAO;IACP,QAAQ;AACV;AAEA,MAAM,+CAAyB,CAAC;AAEhC,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAE/E,SAAS,6CAAuB,aAAsB;IACpD,IAAI,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,MAAM,GAAG,OAAO;IAC5E,IAAI,SAAmB,CAAC;QACD;IAAvB,IAAI,kBAAkB,AAAC,CAAA,CAAA,wBAAA,iDAAA,2DAAA,qCAAgB,KAAK,cAArB,mCAAA,wBAAyB,CAAA,IAAK;IAErD,IAAI,cAAc,OAAO,KAAK,QAAQ;QACpC,IAAI,kBAAkB,SAAS,eAAe;QAC9C,aAAa,gBAAgB,WAAW;QACxC,cAAc,gBAAgB,YAAY;YAClC;QAAR,QAAQ,CAAA,wBAAA,iDAAA,2DAAA,qCAAgB,KAAK,cAArB,mCAAA,wBAAyB;YACxB;QAAT,SAAS,CAAA,yBAAA,iDAAA,2DAAA,qCAAgB,MAAM,cAAtB,oCAAA,yBAA0B;QACnC,OAAO,GAAG,GAAG,gBAAgB,SAA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I,IAAI,SAAS,MAAM,UAAU,EAAE,OAAO;IACjD,OAAO;AACT;AAEA,wEAAwE;AACxE,+CAA+C;AAC/C,oEAAoE;AACpE,SAAS,yCAAmB,IAAiB;IAC3C,4EAA4E;IAC5E,8EAA8E;IAC9E,IAAI,eAAe,KAAK,YAAY;IAEpC,8DAA8D;IAC9D,gEAAgE;IAChE,qCAAqC;IACrC,IACE,gBACA,iBAAiB,SAAS,IAAI,IAC9B,OAAO,gBAAgB,CAAC,cAAc,QAAQ,KAAK,YACnD,CAAC,wCAAkB,eAEnB,eAAe,SAAS,eAAe;IAGzC,sCAAsC;IAEtC,yFAAyF;IACzF,sFAAsF;IACtF,6FAA6F;IAC7F,IAAI,gBAAgB,MAAM;QACxB,eAAe,KAAK,aAAa;QACjC,MAAO,gBAAgB,CAAC,wCAAkB,cACxC,eAAe,aAAa,aAAa;IAE7C;IAEA,6BAA6B;IAC7B,OAAO,gBAAgB,SAAS,eAAe;AACjD;AAEA,qGAAqG;AACrG,SAAS,wCAAkB,IAAa;IACtC,IAAI,QAAQ,OAAO,gBAAgB,CAAC;IACpC,OACE,MAAM,SAAS,KAAK,UACpB,wBAAwB,IAAI,CAAC,MAAM,UAAU,KAC7C,MAAM,MAAM,KAAK,UACjB,MAAM,OAAO,KAAK,WACjB,oBAAoB,SAAS,MAAM,cAAc,KAAK,UACtD,0BAA0B,SAAS,MAAM,oBAAoB,KAAK;AAEvE","sources":["packages/@react-aria/overlays/src/calculatePosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Axis, Placement, PlacementAxis, SizeAxis} from '@react-types/overlays';\nimport {clamp, isWebKit} from '@react-aria/utils';\n\ninterface Position {\n top?: number,\n left?: number,\n bottom?: number,\n right?: number\n}\n\ninterface Dimensions {\n width: number,\n height: number,\n totalWidth: number,\n totalHeight: number,\n top: number,\n left: number,\n scroll: Position\n}\n\ninterface ParsedPlacement {\n placement: PlacementAxis,\n crossPlacement: PlacementAxis,\n axis: Axis,\n crossAxis: Axis,\n size: SizeAxis,\n crossSize: SizeAxis\n}\n\ninterface Offset {\n top: number,\n left: number,\n width: number,\n height: number\n}\n\ninterface PositionOpts {\n arrowSize: number,\n placement: Placement,\n targetNode: Element,\n overlayNode: Element,\n scrollNode: Element,\n padding: number,\n shouldFlip: boolean,\n boundaryElement: Element,\n offset: number,\n crossOffset: number,\n maxHeight?: number,\n arrowBoundaryOffset?: number\n}\n\ntype HeightGrowthDirection = 'top' | 'bottom';\n\nexport interface PositionResult {\n position: Position,\n arrowOffsetLeft?: number,\n arrowOffsetTop?: number,\n triggerAnchorPoint: {x: number, y: number},\n maxHeight: number,\n placement: PlacementAxis\n}\n\nconst AXIS = {\n top: 'top',\n bottom: 'top',\n left: 'left',\n right: 'left'\n};\n\nconst FLIPPED_DIRECTION = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left'\n};\n\nconst CROSS_AXIS = {\n top: 'left',\n left: 'top'\n};\n\nconst AXIS_SIZE = {\n top: 'height',\n left: 'width'\n};\n\nconst TOTAL_SIZE = {\n width: 'totalWidth',\n height: 'totalHeight'\n};\n\nconst PARSED_PLACEMENT_CACHE = {};\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\nfunction getContainerDimensions(containerNode: Element): Dimensions {\n let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;\n let scroll: Position = {};\n let isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n if (containerNode.tagName === 'BODY') {\n let documentElement = document.documentElement;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n if (visualViewport) {\n top = visualViewport.offsetTop;\n left = visualViewport.offsetLeft;\n }\n } else {\n ({width, height, top, left} = getOffset(containerNode));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (isWebKit() && (containerNode.tagName === 'BODY' || containerNode.tagName === 'HTML') && isPinchZoomedIn) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return {width, height, totalWidth, totalHeight, scroll, top, left};\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n top: node.scrollTop,\n left: node.scrollLeft,\n width: node.scrollWidth,\n height: node.scrollHeight\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: Axis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n let containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n let boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n let boundaryStartEdge = boundaryDimensions.scroll[AXIS[axis]] + padding;\n let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[AXIS[axis]] - padding;\n let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);\n } else {\n return 0;\n }\n}\n\nfunction getMargins(node: Element): Position {\n let style = window.getComputedStyle(node);\n return {\n top: parseInt(style.marginTop, 10) || 0,\n bottom: parseInt(style.marginBottom, 10) || 0,\n left: parseInt(style.marginLeft, 10) || 0,\n right: parseInt(style.marginRight, 10) || 0\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n if (PARSED_PLACEMENT_CACHE[input]) {\n return PARSED_PLACEMENT_CACHE[input];\n }\n\n let [placement, crossPlacement] = input.split(' ');\n let axis: Axis = AXIS[placement] || 'right';\n let crossAxis: Axis = CROSS_AXIS[axis];\n\n if (!AXIS[crossPlacement]) {\n crossPlacement = 'center';\n }\n\n let size = AXIS_SIZE[axis];\n let crossSize = AXIS_SIZE[crossAxis];\n PARSED_PLACEMENT_CACHE[input] = {placement, crossPlacement, axis, crossAxis, size, crossSize};\n return PARSED_PLACEMENT_CACHE[input];\n}\n\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number\n) {\n let {placement, crossPlacement, axis, crossAxis, size, crossSize} = placementInfo;\n let position: Position = {};\n\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n if (crossPlacement === 'center') {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis]! += ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis]! += (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }/* else {\n the overlay top should match the button top\n } */\n\n position[crossAxis]! += crossOffset;\n\n // overlay top overlapping arrow with button bottom\n const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;\n // overlay bottom overlapping arrow with button top\n const maxPosition = childOffset[crossAxis] + childOffset[crossSize] - arrowSize - arrowBoundaryOffset;\n position[crossAxis] = clamp(position[crossAxis]!, minPosition, maxPosition);\n\n // 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.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container, which should be as large as boundaryDimensions.\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary[size] : boundaryDimensions[TOTAL_SIZE[size]]);\n position[FLIPPED_DIRECTION[axis]] = Math.floor(containerHeight - childOffset[axis] + offset);\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection\n) {\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[TOTAL_SIZE.height]);\n // 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\n // used in computePosition.\n let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - (position.bottom ?? 0) - overlayHeight);\n let maxHeight = heightGrowthDirection !== 'top' ?\n // We want the distance between the top of the overlay to the bottom of the boundary\n Math.max(0,\n (boundaryDimensions.height + boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the bottom of the boundary\n - overlayTop // this is the top of the overlay\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n )\n // We want the distance between the bottom of the overlay to the top of the boundary\n : Math.max(0,\n (overlayTop + overlayHeight) // this is the bottom of the overlay\n - (boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the top of the boundary\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n );\n return Math.min(boundaryDimensions.height - (padding * 2), maxHeight);\n}\n\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement\n) {\n let {placement, axis, size} = placementInfo;\n if (placement === axis) {\n return Math.max(0, childOffset[axis] - boundaryDimensions[axis] - (boundaryDimensions.scroll[axis] ?? 0) + containerOffsetWithBoundary[axis] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n }\n\n return Math.max(0, boundaryDimensions[size] + boundaryDimensions[axis] + boundaryDimensions.scroll[axis] - containerOffsetWithBoundary[axis] - childOffset[axis] - childOffset[size] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n let {size, crossAxis, crossSize, placement, crossPlacement} = placementInfo;\n let position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let normalizedOffset = offset;\n let space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && scrollSize[size] > space) {\n let flippedPlacementInfo = parsePlacement(`${FLIPPED_DIRECTION[placement]} ${crossPlacement}` as Placement);\n let flippedPosition = computePosition(childOffset, boundaryDimensions, overlaySize, flippedPlacementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n let heightGrowthDirection: HeightGrowthDirection = 'bottom';\n if (placementInfo.axis === 'top') {\n if (placementInfo.placement === 'top') {\n heightGrowthDirection = 'top';\n } else if (placementInfo.placement === 'bottom') {\n heightGrowthDirection = 'bottom';\n }\n } else if (placementInfo.crossAxis === 'top') {\n if (placementInfo.crossPlacement === 'top') {\n heightGrowthDirection = 'bottom';\n } else if (placementInfo.crossPlacement === 'bottom') {\n heightGrowthDirection = 'top';\n }\n }\n\n let delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection\n );\n\n if (userSetMaxHeight && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n\n position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // 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\n // 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\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin = childOffset[crossAxis] - position[crossAxis]! - margins[AXIS[crossAxis]];\n let preferredArrowPosition = origin + .5 * childOffset[crossSize];\n\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin = AXIS[crossAxis] === 'left' ? (margins.left ?? 0) + (margins.right ?? 0) : (margins.top ?? 0) + (margins.bottom ?? 0);\n const arrowMaxPosition = overlaySize[crossSize] - overlayMargin - (arrowSize / 2) - arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge = childOffset[crossAxis] + (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);\n arrowPosition[crossAxis] = clamp(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);\n\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n ({placement, crossPlacement} = placementInfo);\n if (arrowSize) {\n origin = arrowPosition[crossAxis];\n } else if (crossPlacement === 'right') {\n origin += childOffset[crossSize];\n } else if (crossPlacement === 'center') {\n origin += childOffset[crossSize] / 2;\n }\n\n let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;\n let triggerAnchorPoint = {\n x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,\n y: placement === 'left' || placement === 'right' ? origin : crossOrigin\n };\n\n return {\n position,\n maxHeight: maxHeight,\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n placement,\n triggerAnchorPoint\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n let {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize = 0,\n arrowBoundaryOffset = 0\n } = opts;\n\n let container = overlayNode instanceof HTMLElement ? getContainingBlock(overlayNode) : document.documentElement;\n let isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';\n let childOffset: Offset = isViewportContainer ? getOffset(targetNode) : getPosition(targetNode, container);\n\n if (!isViewportContainer) {\n let {marginTop, marginLeft} = window.getComputedStyle(targetNode);\n childOffset.top += parseInt(marginTop, 10) || 0;\n childOffset.left += parseInt(marginLeft, 10) || 0;\n }\n\n let overlaySize: Offset = getOffset(overlayNode);\n let margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n\n let scrollSize = getScroll(scrollNode);\n let boundaryDimensions = getContainerDimensions(boundaryElement);\n let containerDimensions = getContainerDimensions(container);\n // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the\n // 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\n // by the container scroll since they are essentially the same containing element and thus in the same coordinate system\n let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container) : getPosition(container, boundaryElement);\n if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {\n containerDimensions.scroll.top = 0;\n containerDimensions.scroll.left = 0;\n }\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n );\n}\n\nfunction getOffset(node: Element): Offset {\n let {top, left, width, height} = node.getBoundingClientRect();\n let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;\n return {\n top: top + scrollTop - clientTop,\n left: left + scrollLeft - clientLeft,\n width,\n height\n };\n}\n\nfunction getPosition(node: Element, parent: Element): Offset {\n let style = window.getComputedStyle(node);\n let offset: Offset;\n if (style.position === 'fixed') {\n let {top, left, width, height} = node.getBoundingClientRect();\n offset = {top, left, width, height};\n } else {\n offset = getOffset(node);\n let parentOffset = getOffset(parent);\n let parentStyle = window.getComputedStyle(parent);\n parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;\n parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= parseInt(style.marginTop, 10) || 0;\n offset.left -= parseInt(style.marginLeft, 10) || 0;\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let offsetParent = node.offsetParent;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === 'static' &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // TODO(later): handle table elements?\n\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (offsetParent == null) {\n offsetParent = node.parentElement;\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = offsetParent.parentElement;\n }\n }\n\n // Fall back to the viewport.\n return offsetParent || document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n let style = window.getComputedStyle(node);\n return (\n style.transform !== 'none' ||\n /transform|perspective/.test(style.willChange) ||\n style.filter !== 'none' ||\n style.contain === 'paint' ||\n ('backdropFilter' in style && style.backdropFilter !== 'none') ||\n ('WebkitBackdropFilter' in style && style.WebkitBackdropFilter !== 'none')\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a,IAAI;IAClC;IAEA,OAAO,GAAG,IAAI,SAAS,MAAM,SAAS,EAAE,OAAO;IAC/C,OAAO,IAAI,IAAI,SAAS,MAAM,UAAU,EAAE,OAAO;IACjD,OAAO;AACT;AAEA,wEAAwE;AACxE,+CAA+C;AAC/C,oEAAoE;AACpE,SAAS,yCAAmB,IAAiB;IAC3C,4EAA4E;IAC5E,8EAA8E;IAC9E,IAAI,eAAe,KAAK,YAAY;IAEpC,8DAA8D;IAC9D,gEAAgE;IAChE,qCAAqC;IACrC,IACE,gBACA,iBAAiB,SAAS,IAAI,IAC9B,OAAO,gBAAgB,CAAC,cAAc,QAAQ,KAAK,YACnD,CAAC,wCAAkB,eAEnB,eAAe,SAAS,eAAe;IAGzC,sCAAsC;IAEtC,yFAAyF;IACzF,sFAAsF;IACtF,6FAA6F;IAC7F,IAAI,gBAAgB,MAAM;QACxB,eAAe,KAAK,aAAa;QACjC,MAAO,gBAAgB,CAAC,wCAAkB,cACxC,eAAe,aAAa,aAAa;IAE7C;IAEA,6BAA6B;IAC7B,OAAO,gBAAgB,SAAS,eAAe;AACjD;AAEA,qGAAqG;AACrG,SAAS,wCAAkB,IAAa;IACtC,IAAI,QAAQ,OAAO,gBAAgB,CAAC;IACpC,OACE,MAAM,SAAS,KAAK,UACpB,wBAAwB,IAAI,CAAC,MAAM,UAAU,KAC7C,MAAM,MAAM,KAAK,UACjB,MAAM,OAAO,KAAK,WACjB,oBAAoB,SAAS,MAAM,cAAc,KAAK,UACtD,0BAA0B,SAAS,MAAM,oBAAoB,KAAK;AAEvE","sources":["packages/@react-aria/overlays/src/calculatePosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Axis, Placement, PlacementAxis, SizeAxis} from '@react-types/overlays';\nimport {clamp, isWebKit} from '@react-aria/utils';\n\ninterface Position {\n top?: number,\n left?: number,\n bottom?: number,\n right?: number\n}\n\ninterface Dimensions {\n width: number,\n height: number,\n totalWidth: number,\n totalHeight: number,\n top: number,\n left: number,\n scroll: Position\n}\n\ninterface ParsedPlacement {\n placement: PlacementAxis,\n crossPlacement: PlacementAxis,\n axis: Axis,\n crossAxis: Axis,\n size: SizeAxis,\n crossSize: SizeAxis\n}\n\ninterface Offset {\n top: number,\n left: number,\n width: number,\n height: number\n}\n\ninterface PositionOpts {\n arrowSize: number,\n placement: Placement,\n targetNode: Element,\n overlayNode: Element,\n scrollNode: Element,\n padding: number,\n shouldFlip: boolean,\n boundaryElement: Element,\n offset: number,\n crossOffset: number,\n maxHeight?: number,\n arrowBoundaryOffset?: number\n}\n\ntype HeightGrowthDirection = 'top' | 'bottom';\n\nexport interface PositionResult {\n position: Position,\n arrowOffsetLeft?: number,\n arrowOffsetTop?: number,\n triggerAnchorPoint: {x: number, y: number},\n maxHeight: number,\n placement: PlacementAxis\n}\n\nconst AXIS = {\n top: 'top',\n bottom: 'top',\n left: 'left',\n right: 'left'\n};\n\nconst FLIPPED_DIRECTION = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left'\n};\n\nconst CROSS_AXIS = {\n top: 'left',\n left: 'top'\n};\n\nconst AXIS_SIZE = {\n top: 'height',\n left: 'width'\n};\n\nconst TOTAL_SIZE = {\n width: 'totalWidth',\n height: 'totalHeight'\n};\n\nconst PARSED_PLACEMENT_CACHE = {};\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\nfunction getContainerDimensions(containerNode: Element): Dimensions {\n let width = 0, height = 0, totalWidth = 0, totalHeight = 0, top = 0, left = 0;\n let scroll: Position = {};\n let isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n if (containerNode.tagName === 'BODY') {\n let documentElement = document.documentElement;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n if (visualViewport) {\n top = visualViewport.offsetTop;\n left = visualViewport.offsetLeft;\n }\n } else {\n ({width, height, top, left} = getOffset(containerNode, false));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (isWebKit() && (containerNode.tagName === 'BODY' || containerNode.tagName === 'HTML') && isPinchZoomedIn) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return {width, height, totalWidth, totalHeight, scroll, top, left};\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n top: node.scrollTop,\n left: node.scrollLeft,\n width: node.scrollWidth,\n height: node.scrollHeight\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: Axis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n let containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n let boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n let boundaryStartEdge = boundaryDimensions.scroll[AXIS[axis]] + padding;\n let boundaryEndEdge = boundarySize + boundaryDimensions.scroll[AXIS[axis]] - padding;\n let startEdgeOffset = offset - containerScroll + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n let endEdgeOffset = offset - containerScroll + size + containerOffsetWithBoundary[axis] - boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(boundaryEndEdge - endEdgeOffset, boundaryStartEdge - startEdgeOffset);\n } else {\n return 0;\n }\n}\n\nfunction getMargins(node: Element): Position {\n let style = window.getComputedStyle(node);\n return {\n top: parseInt(style.marginTop, 10) || 0,\n bottom: parseInt(style.marginBottom, 10) || 0,\n left: parseInt(style.marginLeft, 10) || 0,\n right: parseInt(style.marginRight, 10) || 0\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n if (PARSED_PLACEMENT_CACHE[input]) {\n return PARSED_PLACEMENT_CACHE[input];\n }\n\n let [placement, crossPlacement] = input.split(' ');\n let axis: Axis = AXIS[placement] || 'right';\n let crossAxis: Axis = CROSS_AXIS[axis];\n\n if (!AXIS[crossPlacement]) {\n crossPlacement = 'center';\n }\n\n let size = AXIS_SIZE[axis];\n let crossSize = AXIS_SIZE[crossAxis];\n PARSED_PLACEMENT_CACHE[input] = {placement, crossPlacement, axis, crossAxis, size, crossSize};\n return PARSED_PLACEMENT_CACHE[input];\n}\n\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number\n) {\n let {placement, crossPlacement, axis, crossAxis, size, crossSize} = placementInfo;\n let position: Position = {};\n\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n if (crossPlacement === 'center') {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis]! += ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis]! += (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }/* else {\n the overlay top should match the button top\n } */\n\n position[crossAxis]! += crossOffset;\n\n // overlay top overlapping arrow with button bottom\n const minPosition = childOffset[crossAxis] - overlaySize[crossSize] + arrowSize + arrowBoundaryOffset;\n // overlay bottom overlapping arrow with button top\n const maxPosition = childOffset[crossAxis] + childOffset[crossSize] - arrowSize - arrowBoundaryOffset;\n position[crossAxis] = clamp(position[crossAxis]!, minPosition, maxPosition);\n\n // 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.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container, which should be as large as boundaryDimensions.\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary[size] : boundaryDimensions[TOTAL_SIZE[size]]);\n position[FLIPPED_DIRECTION[axis]] = Math.floor(containerHeight - childOffset[axis] + offset);\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection\n) {\n const containerHeight = (isContainerPositioned ? containerOffsetWithBoundary.height : boundaryDimensions[TOTAL_SIZE.height]);\n // 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\n // used in computePosition.\n let overlayTop = position.top != null ? containerOffsetWithBoundary.top + position.top : containerOffsetWithBoundary.top + (containerHeight - (position.bottom ?? 0) - overlayHeight);\n let maxHeight = heightGrowthDirection !== 'top' ?\n // We want the distance between the top of the overlay to the bottom of the boundary\n Math.max(0,\n (boundaryDimensions.height + boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the bottom of the boundary\n - overlayTop // this is the top of the overlay\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n )\n // We want the distance between the bottom of the overlay to the top of the boundary\n : Math.max(0,\n (overlayTop + overlayHeight) // this is the bottom of the overlay\n - (boundaryDimensions.top + (boundaryDimensions.scroll.top ?? 0)) // this is the top of the boundary\n - ((margins.top ?? 0) + (margins.bottom ?? 0) + padding) // save additional space for margin and padding\n );\n return Math.min(boundaryDimensions.height - (padding * 2), maxHeight);\n}\n\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement\n) {\n let {placement, axis, size} = placementInfo;\n if (placement === axis) {\n return Math.max(0, childOffset[axis] - boundaryDimensions[axis] - (boundaryDimensions.scroll[axis] ?? 0) + containerOffsetWithBoundary[axis] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n }\n\n return Math.max(0, boundaryDimensions[size] + boundaryDimensions[axis] + boundaryDimensions.scroll[axis] - containerOffsetWithBoundary[axis] - childOffset[axis] - childOffset[size] - (margins[axis] ?? 0) - margins[FLIPPED_DIRECTION[axis]] - padding);\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n let {size, crossAxis, crossSize, placement, crossPlacement} = placementInfo;\n let position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let normalizedOffset = offset;\n let space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && scrollSize[size] > space) {\n let flippedPlacementInfo = parsePlacement(`${FLIPPED_DIRECTION[placement]} ${crossPlacement}` as Placement);\n let flippedPosition = computePosition(childOffset, boundaryDimensions, overlaySize, flippedPlacementInfo, offset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n let flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n let heightGrowthDirection: HeightGrowthDirection = 'bottom';\n if (placementInfo.axis === 'top') {\n if (placementInfo.placement === 'top') {\n heightGrowthDirection = 'top';\n } else if (placementInfo.placement === 'bottom') {\n heightGrowthDirection = 'bottom';\n }\n } else if (placementInfo.crossAxis === 'top') {\n if (placementInfo.crossPlacement === 'top') {\n heightGrowthDirection = 'bottom';\n } else if (placementInfo.crossPlacement === 'bottom') {\n heightGrowthDirection = 'top';\n }\n }\n\n let delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection\n );\n\n if (userSetMaxHeight && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n\n position = computePosition(childOffset, boundaryDimensions, overlaySize, placementInfo, normalizedOffset, crossOffset, containerOffsetWithBoundary, isContainerPositioned, arrowSize, arrowBoundaryOffset);\n delta = getDelta(crossAxis, position[crossAxis]!, overlaySize[crossSize], boundaryDimensions, containerDimensions, padding, containerOffsetWithBoundary);\n position[crossAxis]! += delta;\n\n let arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // 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\n // 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\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin = childOffset[crossAxis] - position[crossAxis]! - margins[AXIS[crossAxis]];\n let preferredArrowPosition = origin + .5 * childOffset[crossSize];\n\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin = AXIS[crossAxis] === 'left' ? (margins.left ?? 0) + (margins.right ?? 0) : (margins.top ?? 0) + (margins.bottom ?? 0);\n const arrowMaxPosition = overlaySize[crossSize] - overlayMargin - (arrowSize / 2) - arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge = childOffset[crossAxis] + (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n const arrowOverlappingChildMaxEdge = childOffset[crossAxis] + childOffset[crossSize] - (arrowSize / 2) - (position[crossAxis] + margins[AXIS[crossAxis]]);\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(preferredArrowPosition, arrowOverlappingChildMinEdge, arrowOverlappingChildMaxEdge);\n arrowPosition[crossAxis] = clamp(arrowPositionOverlappingChild, arrowMinPosition, arrowMaxPosition);\n\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n ({placement, crossPlacement} = placementInfo);\n if (arrowSize) {\n origin = arrowPosition[crossAxis];\n } else if (crossPlacement === 'right') {\n origin += childOffset[crossSize];\n } else if (crossPlacement === 'center') {\n origin += childOffset[crossSize] / 2;\n }\n\n let crossOrigin = placement === 'left' || placement === 'top' ? overlaySize[size] : 0;\n let triggerAnchorPoint = {\n x: placement === 'top' || placement === 'bottom' ? origin : crossOrigin,\n y: placement === 'left' || placement === 'right' ? origin : crossOrigin\n };\n\n return {\n position,\n maxHeight: maxHeight,\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n placement,\n triggerAnchorPoint\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n let {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize = 0,\n arrowBoundaryOffset = 0\n } = opts;\n\n let container = overlayNode instanceof HTMLElement ? getContainingBlock(overlayNode) : document.documentElement;\n let isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';\n let childOffset: Offset = isViewportContainer ? getOffset(targetNode, false) : getPosition(targetNode, container, false);\n\n if (!isViewportContainer) {\n let {marginTop, marginLeft} = window.getComputedStyle(targetNode);\n childOffset.top += parseInt(marginTop, 10) || 0;\n childOffset.left += parseInt(marginLeft, 10) || 0;\n }\n\n let overlaySize: Offset = getOffset(overlayNode, true);\n let margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n\n let scrollSize = getScroll(scrollNode);\n let boundaryDimensions = getContainerDimensions(boundaryElement);\n let containerDimensions = getContainerDimensions(container);\n // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the\n // 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\n // by the container scroll since they are essentially the same containing element and thus in the same coordinate system\n let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container, false) : getPosition(container, boundaryElement, false);\n if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {\n containerDimensions.scroll.top = 0;\n containerDimensions.scroll.left = 0;\n }\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n );\n}\n\nexport function getRect(node: Element, ignoreScale: boolean) {\n let {top, left, width, height} = node.getBoundingClientRect();\n\n // Use offsetWidth and offsetHeight if this is an HTML element, so that \n // the size is not affected by scale transforms.\n if (ignoreScale && node instanceof node.ownerDocument.defaultView!.HTMLElement) {\n width = node.offsetWidth;\n height = node.offsetHeight;\n }\n\n return {top, left, width, height};\n}\n\nfunction getOffset(node: Element, ignoreScale: boolean): Offset {\n let {top, left, width, height} = getRect(node, ignoreScale);\n let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;\n return {\n top: top + scrollTop - clientTop,\n left: left + scrollLeft - clientLeft,\n width,\n height\n };\n}\n\nfunction getPosition(node: Element, parent: Element, ignoreScale: boolean): Offset {\n let style = window.getComputedStyle(node);\n let offset: Offset;\n if (style.position === 'fixed') {\n offset = getRect(node, ignoreScale);\n } else {\n offset = getOffset(node, ignoreScale);\n let parentOffset = getOffset(parent, ignoreScale);\n let parentStyle = window.getComputedStyle(parent);\n parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;\n parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= parseInt(style.marginTop, 10) || 0;\n offset.left -= parseInt(style.marginLeft, 10) || 0;\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let offsetParent = node.offsetParent;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === 'static' &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // TODO(later): handle table elements?\n\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (offsetParent == null) {\n offsetParent = node.parentElement;\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = offsetParent.parentElement;\n }\n }\n\n // Fall back to the viewport.\n return offsetParent || document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n let style = window.getComputedStyle(node);\n return (\n style.transform !== 'none' ||\n /transform|perspective/.test(style.willChange) ||\n style.filter !== 'none' ||\n style.contain === 'paint' ||\n ('backdropFilter' in style && style.backdropFilter !== 'none') ||\n ('WebkitBackdropFilter' in style && style.WebkitBackdropFilter !== 'none')\n );\n}\n"],"names":[],"version":3,"file":"calculatePosition.module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AEoBA,kCAAmC,SAAQ,aAAa;IACtD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAC;IACrC;;OAEG;IACH,UAAU,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAC;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAC;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED;IACE,+CAA+C;IAC/C,YAAY,EAAE,aAAa,CAAC;IAC5B,8CAA8C;IAC9C,UAAU,EAAE,aAAa,CAAC;IAC1B,oEAAoE;IACpE,SAA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AAC;IAC1B,2CAA2C;IAC3C,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAKD;;;GAGG;AACH,wBAAwB,KAAK,EAAE,YAAY,GAAG,MAAM,WAAW,GAAG,IAAI,CAiCrE;AAED,eAAe;AACf,0CAA0C,IAAI,CAM7C;ACzED,sCAAuC,SAAQ,IAAI,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IACnG;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED;IACE,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAC1B,sCAAsC;IACtC,aAAa,EAAE,aAAa,CAAA;CAC7B;AAED;;;GAGG;AACH,gCAAgC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAuB9I;ACrCD,YAAY,EAAC,SAAS,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/calculatePosition.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useCloseOnScroll.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlayPosition.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlay.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlayTrigger.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/usePreventScroll.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/PortalProvider.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useModal.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/DismissButton.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/ariaHideOutside.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/usePopover.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/Overlay.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useModalOverlay.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/index.ts","packages/@react-aria/overlays/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useOverlayPosition} from './useOverlayPosition';\nexport {useOverlay} from './useOverlay';\nexport {useOverlayTrigger} from './useOverlayTrigger';\nexport {usePreventScroll} from './usePreventScroll';\nexport {ModalProvider, useModalProvider, OverlayProvider, OverlayContainer, useModal} from './useModal';\nexport {DismissButton} from './DismissButton';\nexport {ariaHideOutside} from './ariaHideOutside';\nexport {usePopover} from './usePopover';\nexport {useModalOverlay} from './useModalOverlay';\nexport {Overlay, useOverlayFocusContain} from './Overlay';\nexport {UNSAFE_PortalProvider, useUNSAFE_PortalContext} from './PortalProvider';\n\nexport type {AriaPositionProps, PositionAria} from './useOverlayPosition';\nexport type {AriaOverlayProps, OverlayAria} from './useOverlay';\nexport type {OverlayTriggerAria, OverlayTriggerProps} from './useOverlayTrigger';\nexport type {AriaModalOptions, ModalAria, ModalProviderAria, ModalProviderProps, OverlayContainerProps} from './useModal';\nexport type {DismissButtonProps} from './DismissButton';\nexport type {AriaPopoverProps, PopoverAria} from './usePopover';\nexport type {AriaModalOverlayProps, ModalOverlayAria} from './useModalOverlay';\nexport type {OverlayProps} from './Overlay';\nexport type {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nexport type {PortalProviderProps, PortalProviderContextValue} from './PortalProvider';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -58,14 +58,8 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
58
58
|
isOpen
|
|
59
59
|
]);
|
|
60
60
|
let updatePosition = (0, $6TXnl$react.useCallback)(()=>{
|
|
61
|
-
var _overlayRef_current_getAnimations, _overlayRef_current, _arrowRef_current;
|
|
62
61
|
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
63
62
|
if (($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale) !== lastScale.current) return;
|
|
64
|
-
// Delay updating the position until children are finished rendering (e.g. collections).
|
|
65
|
-
if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) return;
|
|
66
|
-
// Don't update while the overlay is animating.
|
|
67
|
-
// Things like scale animations can mess up positioning by affecting the overlay's computed size.
|
|
68
|
-
if (((_overlayRef_current_getAnimations = (_overlayRef_current = overlayRef.current).getAnimations) === null || _overlayRef_current_getAnimations === void 0 ? void 0 : _overlayRef_current_getAnimations.call(_overlayRef_current).length) > 0) return;
|
|
69
63
|
// Determine a scroll anchor based on the focused element.
|
|
70
64
|
// This stores the offset of the anchor element from the scroll container
|
|
71
65
|
// so it can be restored after repositioning. This way if the overlay height
|
|
@@ -98,7 +92,6 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
98
92
|
var _window_visualViewport_height;
|
|
99
93
|
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
100
94
|
}
|
|
101
|
-
var _ref;
|
|
102
95
|
let position = (0, $5935ba4d7da2c103$exports.calculatePosition)({
|
|
103
96
|
placement: $cd94b4896dd97759$var$translateRTL(placement, direction),
|
|
104
97
|
overlayNode: overlayRef.current,
|
|
@@ -110,7 +103,7 @@ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
|
|
|
110
103
|
offset: offset,
|
|
111
104
|
crossOffset: crossOffset,
|
|
112
105
|
maxHeight: maxHeight,
|
|
113
|
-
arrowSize:
|
|
106
|
+
arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $5935ba4d7da2c103$exports.getRect)(arrowRef.current, true).width : 0,
|
|
114
107
|
arrowBoundaryOffset: arrowBoundaryOffset
|
|
115
108
|
});
|
|
116
109
|
if (!position.position) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2ED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,aACF,SAAS,aACT,SAAS,cACT,UAAU,YACV,QAAQ,aACR,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,GAAG;IACJ,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAyB;IAE9D,IAAI,OAAO;QACT;QACA;QACA,WAAW,OAAO;QAClB,UAAU,OAAO;QACjB,qBAAA,+BAAA,SAAU,OAAO;QACjB,UAA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,QAAQ,OAAO,CAAC,OAAO;AAC1D","sources":["packages/@react-aria/overlays/src/useOverlayPosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {calculatePosition, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * The ref for the arrow element.\n */\n arrowRef?: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: (() => void) | null,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize,\n targetRef,\n overlayRef,\n arrowRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Delay updating the position until children are finished rendering (e.g. collections).\n if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) {\n return;\n }\n\n // Don't update while the overlay is animating.\n // Things like scale animations can mess up positioning by affecting the overlay's computed size.\n if (overlayRef.current.getAnimations?.().length > 0) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement?.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: (anchorRect?.top ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;\n }\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize: arrowSize ?? arrowRef?.current?.getBoundingClientRect().width ?? 0,\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\n }\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = (position.position!)[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose?.();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position?.arrowOffsetLeft,\n top: position?.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2ED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,aACF,SAAS,aACT,SAAS,cACT,UAAU,YACV,QAAQ,aACR,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,GAAG;IACJ,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAyB;IAE9D,IAAI,OAAO;QACT;QACA;QACA,WAAW,OAAO;QAClB,UAAU,OAAO;QAC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kF;IAClF,mEAAmE;IACnE,CAAA,GAAA,0CAAe,EAAE;QACf,YAAY;gBACZ;QACA,SAAS,WAAW;IACtB;QAUiB,qBAGJ,qBACS;IAZtB,OAAO;QACL,cAAc;YACZ,OAAO;gBACL,UAAU,WAAW,aAAa;gBAClC,KAAK,CAAC,WAAW,IAAI;gBACrB,MAAM,CAAC,WAAW,IAAI;gBACtB,QAAQ;mBACL,qBAAA,+BAAA,SAAU,QAAQ,AAArB;gBACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;YACpC;QACF;QACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;QAClC,oBAAoB,CAAA,+BAAA,qBAAA,+BAAA,SAAU,kBAAkB,cAA5B,0CAAA,+BAAgC;QACpD,YAAY;YACV,eAAe;YACf,MAAM;YACN,OAAO;gBACL,IAAI,EAAE,qBAAA,+BAAA,SAAU,eAAe;gBAC/B,GAAG,EAAE,qBAAA,+BAAA,SAAU,cAAc;YAC/B;QACF;wBACA;IACF;AACF;AAEA,SAAS,gCAAU,QAAQ;IACzB,CAAA,GAAA,qCAAc,EAAE;QACd,OAAO,gBAAgB,CAAC,UAAU,UAAU;QAC5C,OAAO;YACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;QACjD;IACF,GAAG;QAAC;KAAS;AACf;AAEA,SAAS,mCAAa,QAAQ,EAAE,SAAS;IACvC,IAAI,cAAc,OAChB,OAAO,SAAS,OAAO,CAAC,SAAS,SAAS,OAAO,CAAC,OAAO;IAE3D,OAAO,SAAS,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC,OAAO;AAC1D","sources":["packages/@react-aria/overlays/src/useOverlayPosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {calculatePosition, getRect, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * The ref for the arrow element.\n */\n arrowRef?: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: (() => void) | null,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize,\n targetRef,\n overlayRef,\n arrowRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement?.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: (anchorRect?.top ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;\n }\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\n }\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = (position.position!)[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose?.();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position?.arrowOffsetLeft,\n top: position?.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.main.js.map"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98} from "./calculatePosition.mjs";
|
|
1
|
+
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98, getRect as $edcf132a9284368a$export$4b834cebd9e5cebe} from "./calculatePosition.mjs";
|
|
2
2
|
import {useCloseOnScroll as $dd149f63282afbbf$export$18fc8428861184da} from "./useCloseOnScroll.mjs";
|
|
3
3
|
import {useState as $39EOa$useState, useRef as $39EOa$useRef, useEffect as $39EOa$useEffect, useCallback as $39EOa$useCallback} from "react";
|
|
4
4
|
import {useLayoutEffect as $39EOa$useLayoutEffect, useResizeObserver as $39EOa$useResizeObserver} from "@react-aria/utils";
|
|
@@ -52,14 +52,8 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
52
52
|
isOpen
|
|
53
53
|
]);
|
|
54
54
|
let updatePosition = (0, $39EOa$useCallback)(()=>{
|
|
55
|
-
var _overlayRef_current_getAnimations, _overlayRef_current, _arrowRef_current;
|
|
56
55
|
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
57
56
|
if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
|
|
58
|
-
// Delay updating the position until children are finished rendering (e.g. collections).
|
|
59
|
-
if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) return;
|
|
60
|
-
// Don't update while the overlay is animating.
|
|
61
|
-
// Things like scale animations can mess up positioning by affecting the overlay's computed size.
|
|
62
|
-
if (((_overlayRef_current_getAnimations = (_overlayRef_current = overlayRef.current).getAnimations) === null || _overlayRef_current_getAnimations === void 0 ? void 0 : _overlayRef_current_getAnimations.call(_overlayRef_current).length) > 0) return;
|
|
63
57
|
// Determine a scroll anchor based on the focused element.
|
|
64
58
|
// This stores the offset of the anchor element from the scroll container
|
|
65
59
|
// so it can be restored after repositioning. This way if the overlay height
|
|
@@ -92,7 +86,6 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
92
86
|
var _window_visualViewport_height;
|
|
93
87
|
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
94
88
|
}
|
|
95
|
-
var _ref;
|
|
96
89
|
let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
|
|
97
90
|
placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
|
|
98
91
|
overlayNode: overlayRef.current,
|
|
@@ -104,7 +97,7 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
104
97
|
offset: offset,
|
|
105
98
|
crossOffset: crossOffset,
|
|
106
99
|
maxHeight: maxHeight,
|
|
107
|
-
arrowSize:
|
|
100
|
+
arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $edcf132a9284368a$export$4b834cebd9e5cebe)(arrowRef.current, true).width : 0,
|
|
108
101
|
arrowBoundaryOffset: arrowBoundaryOffset
|
|
109
102
|
});
|
|
110
103
|
if (!position.position) return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98} from "./calculatePosition.module.js";
|
|
1
|
+
import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98, getRect as $edcf132a9284368a$export$4b834cebd9e5cebe} from "./calculatePosition.module.js";
|
|
2
2
|
import {useCloseOnScroll as $dd149f63282afbbf$export$18fc8428861184da} from "./useCloseOnScroll.module.js";
|
|
3
3
|
import {useState as $39EOa$useState, useRef as $39EOa$useRef, useEffect as $39EOa$useEffect, useCallback as $39EOa$useCallback} from "react";
|
|
4
4
|
import {useLayoutEffect as $39EOa$useLayoutEffect, useResizeObserver as $39EOa$useResizeObserver} from "@react-aria/utils";
|
|
@@ -52,14 +52,8 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
52
52
|
isOpen
|
|
53
53
|
]);
|
|
54
54
|
let updatePosition = (0, $39EOa$useCallback)(()=>{
|
|
55
|
-
var _overlayRef_current_getAnimations, _overlayRef_current, _arrowRef_current;
|
|
56
55
|
if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
|
|
57
56
|
if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
|
|
58
|
-
// Delay updating the position until children are finished rendering (e.g. collections).
|
|
59
|
-
if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) return;
|
|
60
|
-
// Don't update while the overlay is animating.
|
|
61
|
-
// Things like scale animations can mess up positioning by affecting the overlay's computed size.
|
|
62
|
-
if (((_overlayRef_current_getAnimations = (_overlayRef_current = overlayRef.current).getAnimations) === null || _overlayRef_current_getAnimations === void 0 ? void 0 : _overlayRef_current_getAnimations.call(_overlayRef_current).length) > 0) return;
|
|
63
57
|
// Determine a scroll anchor based on the focused element.
|
|
64
58
|
// This stores the offset of the anchor element from the scroll container
|
|
65
59
|
// so it can be restored after repositioning. This way if the overlay height
|
|
@@ -92,7 +86,6 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
92
86
|
var _window_visualViewport_height;
|
|
93
87
|
overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
|
|
94
88
|
}
|
|
95
|
-
var _ref;
|
|
96
89
|
let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
|
|
97
90
|
placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
|
|
98
91
|
overlayNode: overlayRef.current,
|
|
@@ -104,7 +97,7 @@ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
|
|
|
104
97
|
offset: offset,
|
|
105
98
|
crossOffset: crossOffset,
|
|
106
99
|
maxHeight: maxHeight,
|
|
107
|
-
arrowSize:
|
|
100
|
+
arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $edcf132a9284368a$export$4b834cebd9e5cebe)(arrowRef.current, true).width : 0,
|
|
108
101
|
arrowBoundaryOffset: arrowBoundaryOffset
|
|
109
102
|
});
|
|
110
103
|
if (!position.position) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2ED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,aACF,SAAS,aACT,SAAS,cACT,UAAU,YACV,QAAQ,aACR,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,GAAG;IACJ,IAAI,CAAC,UAAU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,mCAAa,QAAQ,EAAE,SAAS;IACvC,IAAI,cAAc,OAChB,OAAO,SAAS,OAAO,CAAC,SAAS,SAAS,OAAO,CAAC,OAAO;IAE3D,OAAO,SAAS,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC,OAAO;AAC1D","sources":["packages/@react-aria/overlays/src/useOverlayPosition.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {calculatePosition, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * The ref for the arrow element.\n */\n arrowRef?: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: (() => void) | null,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize,\n targetRef,\n overlayRef,\n arrowRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Delay updating the position until children are finished rendering (e.g. collections).\n if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) {\n return;\n }\n\n // Don't update while the overlay is animating.\n // Things like scale animations can mess up positioning by affecting the overlay's computed size.\n if (overlayRef.current.getAnimations?.().length > 0) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement?.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: (anchorRect?.top ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;\n }\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize: arrowSize ?? arrowRef?.current?.getBoundingClientRect().width ?? 0,\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\n }\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = (position.position!)[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose?.();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position?.arrowOffsetLeft,\n top: position?.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2ED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,aACF,SAAS,aACT,SAAS,cACT,UAAU,YACV,QAAQ,aACR,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,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Content":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {calculatePosition, getRect, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * The ref for the arrow element.\n */\n arrowRef?: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: (() => void) | null,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize,\n targetRef,\n overlayRef,\n arrowRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement?.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: (anchorRect?.top ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;\n }\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\n }\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = (position.position!)[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose?.();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position?.arrowOffsetLeft,\n top: position?.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.29.
|
|
3
|
+
"version": "3.29.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ed4815e15c9d1659208fa687e8c3a094879854bb"
|
|
49
49
|
}
|
package/src/calculatePosition.ts
CHANGED
|
@@ -127,7 +127,7 @@ function getContainerDimensions(containerNode: Element): Dimensions {
|
|
|
127
127
|
left = visualViewport.offsetLeft;
|
|
128
128
|
}
|
|
129
129
|
} else {
|
|
130
|
-
({width, height, top, left} = getOffset(containerNode));
|
|
130
|
+
({width, height, top, left} = getOffset(containerNode, false));
|
|
131
131
|
scroll.top = containerNode.scrollTop;
|
|
132
132
|
scroll.left = containerNode.scrollLeft;
|
|
133
133
|
totalWidth = width;
|
|
@@ -488,7 +488,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
488
488
|
let isViewportContainer = container === document.documentElement;
|
|
489
489
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
490
490
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
|
491
|
-
let childOffset: Offset = isViewportContainer ? getOffset(targetNode) : getPosition(targetNode, container);
|
|
491
|
+
let childOffset: Offset = isViewportContainer ? getOffset(targetNode, false) : getPosition(targetNode, container, false);
|
|
492
492
|
|
|
493
493
|
if (!isViewportContainer) {
|
|
494
494
|
let {marginTop, marginLeft} = window.getComputedStyle(targetNode);
|
|
@@ -496,7 +496,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
496
496
|
childOffset.left += parseInt(marginLeft, 10) || 0;
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
let overlaySize: Offset = getOffset(overlayNode);
|
|
499
|
+
let overlaySize: Offset = getOffset(overlayNode, true);
|
|
500
500
|
let margins = getMargins(overlayNode);
|
|
501
501
|
overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);
|
|
502
502
|
overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);
|
|
@@ -507,7 +507,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
507
507
|
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
|
|
508
508
|
// 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
|
|
509
509
|
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
|
|
510
|
-
let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container) : getPosition(container, boundaryElement);
|
|
510
|
+
let containerOffsetWithBoundary: Offset = boundaryElement.tagName === 'BODY' ? getOffset(container, false) : getPosition(container, boundaryElement, false);
|
|
511
511
|
if (container.tagName === 'HTML' && boundaryElement.tagName === 'BODY') {
|
|
512
512
|
containerDimensions.scroll.top = 0;
|
|
513
513
|
containerDimensions.scroll.left = 0;
|
|
@@ -533,8 +533,21 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
533
533
|
);
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
-
function
|
|
536
|
+
export function getRect(node: Element, ignoreScale: boolean) {
|
|
537
537
|
let {top, left, width, height} = node.getBoundingClientRect();
|
|
538
|
+
|
|
539
|
+
// Use offsetWidth and offsetHeight if this is an HTML element, so that
|
|
540
|
+
// the size is not affected by scale transforms.
|
|
541
|
+
if (ignoreScale && node instanceof node.ownerDocument.defaultView!.HTMLElement) {
|
|
542
|
+
width = node.offsetWidth;
|
|
543
|
+
height = node.offsetHeight;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return {top, left, width, height};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function getOffset(node: Element, ignoreScale: boolean): Offset {
|
|
550
|
+
let {top, left, width, height} = getRect(node, ignoreScale);
|
|
538
551
|
let {scrollTop, scrollLeft, clientTop, clientLeft} = document.documentElement;
|
|
539
552
|
return {
|
|
540
553
|
top: top + scrollTop - clientTop,
|
|
@@ -544,15 +557,14 @@ function getOffset(node: Element): Offset {
|
|
|
544
557
|
};
|
|
545
558
|
}
|
|
546
559
|
|
|
547
|
-
function getPosition(node: Element, parent: Element): Offset {
|
|
560
|
+
function getPosition(node: Element, parent: Element, ignoreScale: boolean): Offset {
|
|
548
561
|
let style = window.getComputedStyle(node);
|
|
549
562
|
let offset: Offset;
|
|
550
563
|
if (style.position === 'fixed') {
|
|
551
|
-
|
|
552
|
-
offset = {top, left, width, height};
|
|
564
|
+
offset = getRect(node, ignoreScale);
|
|
553
565
|
} else {
|
|
554
|
-
offset = getOffset(node);
|
|
555
|
-
let parentOffset = getOffset(parent);
|
|
566
|
+
offset = getOffset(node, ignoreScale);
|
|
567
|
+
let parentOffset = getOffset(parent, ignoreScale);
|
|
556
568
|
let parentStyle = window.getComputedStyle(parent);
|
|
557
569
|
parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;
|
|
558
570
|
parentOffset.left += (parseInt(parentStyle.borderLeftWidth, 10) || 0) - parent.scrollLeft;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {calculatePosition, PositionResult} from './calculatePosition';
|
|
13
|
+
import {calculatePosition, getRect, PositionResult} from './calculatePosition';
|
|
14
14
|
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
15
15
|
import {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';
|
|
16
16
|
import {useCallback, useEffect, useRef, useState} from 'react';
|
|
@@ -149,17 +149,6 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
// Delay updating the position until children are finished rendering (e.g. collections).
|
|
153
|
-
if (overlayRef.current.querySelector('[data-react-aria-incomplete]')) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Don't update while the overlay is animating.
|
|
158
|
-
// Things like scale animations can mess up positioning by affecting the overlay's computed size.
|
|
159
|
-
if (overlayRef.current.getAnimations?.().length > 0) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
152
|
// Determine a scroll anchor based on the focused element.
|
|
164
153
|
// This stores the offset of the anchor element from the scroll container
|
|
165
154
|
// so it can be restored after repositioning. This way if the overlay height
|
|
@@ -200,7 +189,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
|
|
|
200
189
|
offset,
|
|
201
190
|
crossOffset,
|
|
202
191
|
maxHeight,
|
|
203
|
-
arrowSize: arrowSize ?? arrowRef?.current
|
|
192
|
+
arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),
|
|
204
193
|
arrowBoundaryOffset
|
|
205
194
|
});
|
|
206
195
|
|