* Attempts to move the rectangle through various sides of the target to find a place to fit. * If no fit is found, the original position should be returned.
(rect, target, bounding, positionData, gap)
| 31827 | * Attempts to move the rectangle through various sides of the target to find a place to fit. |
| 31828 | * If no fit is found, the original position should be returned. |
| 31829 | */ function _flipToFit(rect, target, bounding, positionData, gap) { |
| 31830 | if (gap === void 0) gap = 0; |
| 31831 | var directions = [ |
| 31832 | (0, _positioningTypes.RectangleEdge).left, |
| 31833 | (0, _positioningTypes.RectangleEdge).right, |
| 31834 | (0, _positioningTypes.RectangleEdge).bottom, |
| 31835 | (0, _positioningTypes.RectangleEdge).top, |
| 31836 | ]; |
| 31837 | // In RTL page, RectangleEdge.right has a higher priority than RectangleEdge.left, so the order should be updated. |
| 31838 | if ((0, _utilities.getRTL)()) { |
| 31839 | directions[0] *= -1; |
| 31840 | directions[1] *= -1; |
| 31841 | } |
| 31842 | var currentEstimate = rect; |
| 31843 | var currentEdge = positionData.targetEdge; |
| 31844 | var currentAlignment = positionData.alignmentEdge; |
| 31845 | // Keep switching sides until one is found with enough space. |
| 31846 | // If all sides don't fit then return the unmodified element. |
| 31847 | for(var i = 0; i < 4; i++){ |
| 31848 | if (!_isEdgeInBounds(currentEstimate, bounding, currentEdge)) { |
| 31849 | directions.splice(directions.indexOf(currentEdge), 1); |
| 31850 | if (directions.length > 0) { |
| 31851 | if (directions.indexOf(currentEdge * -1) > -1) currentEdge = currentEdge * -1; |
| 31852 | else { |
| 31853 | currentAlignment = currentEdge; |
| 31854 | currentEdge = directions.slice(-1)[0]; |
| 31855 | } |
| 31856 | currentEstimate = _estimatePosition(rect, target, { |
| 31857 | targetEdge: currentEdge, |
| 31858 | alignmentEdge: currentAlignment |
| 31859 | }, gap); |
| 31860 | } |
| 31861 | } else return { |
| 31862 | elementRectangle: currentEstimate, |
| 31863 | targetEdge: currentEdge, |
| 31864 | alignmentEdge: currentAlignment |
| 31865 | }; |
| 31866 | } |
| 31867 | return { |
| 31868 | elementRectangle: rect, |
| 31869 | targetEdge: positionData.targetEdge, |
| 31870 | alignmentEdge: positionData.alignmentEdge |
| 31871 | }; |
| 31872 | } |
| 31873 | /** |
| 31874 | * Flips only the alignment edge of an element rectangle. This is used instead of nudging the alignment edges |
| 31875 | * into position, when alignTargetEdge is specified. |
no test coverage detected