(
modalOverlayOpeningPadding = 0,
modalOverlayOpeningRadius: ModalRadiusType = 0,
modalOverlayOpeningXOffset = 0,
modalOverlayOpeningYOffset = 0,
scrollParent?: HTMLElement | null,
targetElement?: HTMLElement | null,
extraHighlights?: HTMLElement[]
)
| 85 | } |
| 86 | |
| 87 | function positionModal( |
| 88 | modalOverlayOpeningPadding = 0, |
| 89 | modalOverlayOpeningRadius: ModalRadiusType = 0, |
| 90 | modalOverlayOpeningXOffset = 0, |
| 91 | modalOverlayOpeningYOffset = 0, |
| 92 | scrollParent?: HTMLElement | null, |
| 93 | targetElement?: HTMLElement | null, |
| 94 | extraHighlights?: HTMLElement[] |
| 95 | ) { |
| 96 | if (targetElement) { |
| 97 | const elementsToHighlight = [targetElement, ...(extraHighlights || [])]; |
| 98 | const newOpenings: OpeningProperty[] = []; |
| 99 | |
| 100 | for (const el of elementsToHighlight) { |
| 101 | if (!el) continue; |
| 102 | |
| 103 | // Skip duplicate elements |
| 104 | if ( |
| 105 | elementsToHighlight.indexOf(el) !== |
| 106 | elementsToHighlight.lastIndexOf(el) |
| 107 | ) { |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | const { y, height } = _getVisibleHeight(el, scrollParent); |
| 112 | const { x, width, left } = el.getBoundingClientRect(); |
| 113 | |
| 114 | // Check if the element is contained by another element. |
| 115 | // Use _getVisibleHeight for otherElement too so both sides |
| 116 | // compare scroll-clipped geometry on the y-axis. |
| 117 | const isContained = elementsToHighlight.some((otherElement) => { |
| 118 | if (otherElement === el) return false; |
| 119 | const otherRect = otherElement.getBoundingClientRect(); |
| 120 | const { y: otherY, height: otherHeight } = _getVisibleHeight( |
| 121 | otherElement, |
| 122 | scrollParent |
| 123 | ); |
| 124 | return ( |
| 125 | x >= otherRect.left && |
| 126 | x + width <= otherRect.left + otherRect.width && |
| 127 | y >= otherY && |
| 128 | y + height <= otherY + otherHeight |
| 129 | ); |
| 130 | }); |
| 131 | |
| 132 | if (isContained) continue; |
| 133 | |
| 134 | newOpenings.push({ |
| 135 | width: width + modalOverlayOpeningPadding * 2, |
| 136 | height: height + modalOverlayOpeningPadding * 2, |
| 137 | x: |
| 138 | (x || left) + |
| 139 | modalOverlayOpeningXOffset - |
| 140 | modalOverlayOpeningPadding, |
| 141 | y: y + modalOverlayOpeningYOffset - modalOverlayOpeningPadding, |
| 142 | r: modalOverlayOpeningRadius as OpeningProperty['r'] |
| 143 | }); |
| 144 | } |
no test coverage detected