@@ -74,20 +74,21 @@ export function measureStackKinds(
7474 const forcedW = self . width === null ? null : clampWithin ( self . width , minW , maxWCap ) ;
7575 const forcedH = self . height === null ? null : clampWithin ( self . height , minH , maxHCap ) ;
7676
77- const needsConstraintPass = vnode . children . some (
78- ( c ) => childHasFlexInMainAxis ( c , "row" ) || childHasPercentInMainAxis ( c , "row" ) ,
79- ) ;
80- const fillMain = forcedW === null && needsConstraintPass ;
77+ const hasFlexInMainAxis = vnode . children . some ( ( c ) => childHasFlexInMainAxis ( c , "row" ) ) ;
78+ const hasPercentInMainAxis = vnode . children . some ( ( c ) => childHasPercentInMainAxis ( c , "row" ) ) ;
79+ const needsConstraintPass = hasFlexInMainAxis || hasPercentInMainAxis ;
80+ const fillMain = forcedW === null && hasPercentInMainAxis ;
8181 const fillCross =
8282 forcedH === null && vnode . children . some ( ( c ) => childHasPercentInCrossAxis ( c , "row" ) ) ;
8383
84- const outerWLimit = forcedW ?? ( fillMain ? maxWCap : maxWCap ) ;
84+ const outerWLimit = forcedW ?? maxWCap ;
8585 const outerHLimit = forcedH ?? maxHCap ;
8686
8787 const cw = clampNonNegative ( outerWLimit - padX ) ;
8888 const chLimit = clampNonNegative ( outerHLimit - padY ) ;
8989
9090 let maxChildH = 0 ;
91+ let usedMainInConstraintPass = 0 ;
9192
9293 if ( needsConstraintPass ) {
9394 const parentRect : Rect = { x : 0 , y : 0 , w : cw , h : chLimit } ;
@@ -193,6 +194,12 @@ export function measureStackKinds(
193194 const childH = align === "stretch" ? chLimit : sizeRes . value . h ;
194195 if ( childH > maxChildH ) maxChildH = childH ;
195196 }
197+
198+ for ( let i = 0 ; i < mainSizes . length ; i ++ ) {
199+ usedMainInConstraintPass += mainSizes [ i ] ?? 0 ;
200+ }
201+ usedMainInConstraintPass +=
202+ vnode . children . length <= 1 ? 0 : gap * ( vnode . children . length - 1 ) ;
196203 } else {
197204 let remainingWidth = cw ;
198205 let cursorX = 0 ;
@@ -231,7 +238,8 @@ export function measureStackKinds(
231238 } ) ;
232239 }
233240
234- const chosenW = forcedW ?? ( fillMain ? maxWCap : maxWCap ) ;
241+ const shrinkW = padX + Math . min ( cw , usedMainInConstraintPass ) ;
242+ const chosenW = forcedW ?? ( fillMain ? maxWCap : Math . min ( maxWCap , shrinkW ) ) ;
235243 const chosenH = forcedH ?? ( fillCross ? maxHCap : Math . min ( maxHCap , padY + maxChildH ) ) ;
236244 const innerW = clampWithin ( chosenW , minW , maxWCap ) ;
237245 const innerH = clampWithin ( chosenH , minH , maxHCap ) ;
@@ -268,20 +276,23 @@ export function measureStackKinds(
268276 const forcedW = self . width === null ? null : clampWithin ( self . width , minW , maxWCap ) ;
269277 const forcedH = self . height === null ? null : clampWithin ( self . height , minH , maxHCap ) ;
270278
271- const needsConstraintPass = vnode . children . some (
272- ( c ) => childHasFlexInMainAxis ( c , "column" ) || childHasPercentInMainAxis ( c , "column" ) ,
279+ const hasFlexInMainAxis = vnode . children . some ( ( c ) => childHasFlexInMainAxis ( c , "column" ) ) ;
280+ const hasPercentInMainAxis = vnode . children . some ( ( c ) =>
281+ childHasPercentInMainAxis ( c , "column" ) ,
273282 ) ;
274- const fillMain = forcedH === null && needsConstraintPass ;
283+ const needsConstraintPass = hasFlexInMainAxis || hasPercentInMainAxis ;
284+ const fillMain = forcedH === null && hasPercentInMainAxis ;
275285 const fillCross =
276286 forcedW === null && vnode . children . some ( ( c ) => childHasPercentInCrossAxis ( c , "column" ) ) ;
277287
278288 const outerWLimit = forcedW ?? maxWCap ;
279- const outerHLimit = forcedH ?? ( fillMain ? maxHCap : maxHCap ) ;
289+ const outerHLimit = forcedH ?? maxHCap ;
280290
281291 const cw = clampNonNegative ( outerWLimit - padX ) ;
282292 const ch = clampNonNegative ( outerHLimit - padY ) ;
283293
284294 let maxChildW = 0 ;
295+ let usedMainInConstraintPass = 0 ;
285296
286297 if ( needsConstraintPass ) {
287298 const parentRect : Rect = { x : 0 , y : 0 , w : cw , h : ch } ;
@@ -387,6 +398,12 @@ export function measureStackKinds(
387398 const childW = align === "stretch" ? cw : sizeRes . value . w ;
388399 if ( childW > maxChildW ) maxChildW = childW ;
389400 }
401+
402+ for ( let i = 0 ; i < mainSizes . length ; i ++ ) {
403+ usedMainInConstraintPass += mainSizes [ i ] ?? 0 ;
404+ }
405+ usedMainInConstraintPass +=
406+ vnode . children . length <= 1 ? 0 : gap * ( vnode . children . length - 1 ) ;
390407 } else {
391408 let remainingHeight = ch ;
392409 let cursorY = 0 ;
@@ -425,8 +442,9 @@ export function measureStackKinds(
425442 } ) ;
426443 }
427444
445+ const shrinkH = padY + Math . min ( ch , usedMainInConstraintPass ) ;
428446 const chosenW = forcedW ?? ( fillCross ? maxWCap : Math . min ( maxWCap , padX + maxChildW ) ) ;
429- const chosenH = forcedH ?? ( fillMain ? maxHCap : maxHCap ) ;
447+ const chosenH = forcedH ?? ( fillMain ? maxHCap : Math . min ( maxHCap , shrinkH ) ) ;
430448 const innerW = clampWithin ( chosenW , minW , maxWCap ) ;
431449 const innerH = clampWithin ( chosenH , minH , maxHCap ) ;
432450 return ok ( {
0 commit comments