@@ -49,26 +49,35 @@ const outsetBounds = (
4949const maxSide = ( sides : BoxSides ) : number =>
5050 Math . max ( sides . top , sides . right , sides . bottom , sides . left ) ;
5151
52+ const isInFlowChild = ( child : Element ) : boolean => {
53+ const childStyle = window . getComputedStyle ( child ) ;
54+ return childStyle . display !== "none" && ! OUT_OF_FLOW_POSITIONS . has ( childStyle . position ) ;
55+ } ;
56+
57+ const hasVisibleSize = ( rect : DOMRect ) : boolean => rect . width > 0 || rect . height > 0 ;
58+
5259const computeAxisGaps = (
5360 childRects : DOMRect [ ] ,
5461 contentBounds : OverlayBounds ,
5562 axis : "row" | "column" ,
5663) : GapRect [ ] => {
64+ const isColumnAxis = axis === "column" ;
65+
5766 const sortedRects = [ ...childRects ] . sort ( ( a , b ) =>
58- axis === "column" ? a . top - b . top : a . left - b . left ,
67+ isColumnAxis ? a . top - b . top : a . left - b . left ,
5968 ) ;
6069
6170 const gaps : GapRect [ ] = [ ] ;
6271 for ( let childIndex = 0 ; childIndex < sortedRects . length - 1 ; childIndex ++ ) {
63- const gapStart =
64- axis === "column" ? sortedRects [ childIndex ] . bottom : sortedRects [ childIndex ] . right ;
65- const gapEnd =
66- axis === "column" ? sortedRects [ childIndex + 1 ] . top : sortedRects [ childIndex + 1 ] . left ;
72+ const currentRect = sortedRects [ childIndex ] ;
73+ const nextRect = sortedRects [ childIndex + 1 ] ;
74+ const gapStart = isColumnAxis ? currentRect . bottom : currentRect . right ;
75+ const gapEnd = isColumnAxis ? nextRect . top : nextRect . left ;
6776 const gapSize = gapEnd - gapStart ;
6877
6978 if ( gapSize > BOX_MODEL_GAP_THRESHOLD_PX ) {
7079 gaps . push (
71- axis === "column"
80+ isColumnAxis
7281 ? { x : contentBounds . x , y : gapStart , width : contentBounds . width , height : gapSize }
7382 : { x : gapStart , y : contentBounds . y , width : gapSize , height : contentBounds . height } ,
7483 ) ;
@@ -87,16 +96,10 @@ const computeChildGaps = (
8796 return [ ] ;
8897 }
8998
90- const childRects : DOMRect [ ] = [ ] ;
91- for ( const child of element . children ) {
92- const childStyle = window . getComputedStyle ( child ) ;
93- if ( childStyle . display === "none" || OUT_OF_FLOW_POSITIONS . has ( childStyle . position ) ) {
94- continue ;
95- }
96- const rect = child . getBoundingClientRect ( ) ;
97- if ( rect . width === 0 && rect . height === 0 ) continue ;
98- childRects . push ( rect ) ;
99- }
99+ const childRects = Array . from ( element . children )
100+ . filter ( isInFlowChild )
101+ . map ( ( child ) => child . getBoundingClientRect ( ) )
102+ . filter ( hasVisibleSize ) ;
100103
101104 if ( childRects . length < 2 ) return [ ] ;
102105
0 commit comments