@@ -9,16 +9,12 @@ import type {
99 AlignPointTopBottom ,
1010 AlignType ,
1111} from '../interface' ;
12- import { collectScroller , getWin } from '../util' ;
12+ import { collectScroller , getVisibleArea , getWin , toNum } from '../util' ;
1313
1414type Rect = Record < 'x' | 'y' | 'width' | 'height' , number > ;
1515
1616type Points = [ topBottom : AlignPointTopBottom , leftRight : AlignPointLeftRight ] ;
1717
18- function toNum ( num : number ) {
19- return Number . isNaN ( num ) ? 1 : num ;
20- }
21-
2218function splitPoints ( points : string = '' ) : Points {
2319 return [ points [ 0 ] as any , points [ 1 ] as any ] ;
2420}
@@ -174,7 +170,7 @@ export default function useAlign(
174170 const targetWidth = targetRect . width ;
175171
176172 // Get bounding of visible area
177- const visibleArea =
173+ let visibleArea =
178174 placementInfo . htmlRegion === 'scroll'
179175 ? // Scroll region should take scrollLeft & scrollTop into account
180176 {
@@ -190,36 +186,7 @@ export default function useAlign(
190186 bottom : clientHeight ,
191187 } ;
192188
193- ( scrollerList || [ ] ) . forEach ( ( ele ) => {
194- if ( ele instanceof HTMLBodyElement ) {
195- return ;
196- }
197-
198- const eleRect = ele . getBoundingClientRect ( ) ;
199- const {
200- offsetHeight : eleOutHeight ,
201- clientHeight : eleInnerHeight ,
202- offsetWidth : eleOutWidth ,
203- clientWidth : eleInnerWidth ,
204- } = ele ;
205-
206- const scaleX = toNum (
207- Math . round ( ( eleRect . width / eleOutWidth ) * 1000 ) / 1000 ,
208- ) ;
209- const scaleY = toNum (
210- Math . round ( ( eleRect . height / eleOutHeight ) * 1000 ) / 1000 ,
211- ) ;
212-
213- const eleScrollWidth = ( eleOutWidth - eleInnerWidth ) * scaleX ;
214- const eleScrollHeight = ( eleOutHeight - eleInnerHeight ) * scaleY ;
215- const eleRight = eleRect . x + eleRect . width - eleScrollWidth ;
216- const eleBottom = eleRect . y + eleRect . height - eleScrollHeight ;
217-
218- visibleArea . left = Math . max ( visibleArea . left , eleRect . left ) ;
219- visibleArea . top = Math . max ( visibleArea . top , eleRect . top ) ;
220- visibleArea . right = Math . min ( visibleArea . right , eleRight ) ;
221- visibleArea . bottom = Math . min ( visibleArea . bottom , eleBottom ) ;
222- } ) ;
189+ visibleArea = getVisibleArea ( visibleArea , scrollerList ) ;
223190
224191 // Reset back
225192 popupElement . style . left = originLeft ;
0 commit comments