Compute_helpersSourceShared utilities for layout algorithms.
This module provides common functions used across Flexbox, Grid, and Block layout implementations. All functions are ported from taffy's compute/common module.
val compute_content_size_contribution :
location:float Geometry.Point.t ->
size:float Geometry.Size.t ->
content_size:float Geometry.Size.t ->
overflow:Style.Overflow.t Geometry.Point.t ->
float Geometry.Size.tcompute_content_size_contribution ~location ~size ~content_size ~overflow computes how much a child contributes to its parent's intrinsic content size.
Algorithm:
Visible, use max size content_size; otherwise use sizelocation + computed_sizeOnly Visible overflow contributes beyond border-box. Non-visible modes (Clip, Hidden, Scroll) clamp contribution to border-box size.
val apply_alignment_fallback :
free_space:float ->
num_items:int ->
alignment_mode:Style.Align_content.t ->
is_safe:bool ->
Style.Align_content.tapply_alignment_fallback ~free_space ~num_items ~alignment_mode ~is_safe resolves alignment mode fallbacks per CSS Box Alignment spec and CSSWG issue 10154.
Fallback rules:
Stretch, Space_between, Space_around, Space_evenly) fall back when num_items <= 1 or free_space <= 0: Stretch, Space_between -> Flex_start (safe); Space_around, Space_evenly -> Center (safe)free_space <= 0 and is_safe is true, all modes -> Startval compute_alignment_offset :
free_space:float ->
num_items:int ->
gap:float ->
alignment_mode:Style.Align_content.t ->
layout_is_flex_reversed:bool ->
is_first:bool ->
floatcompute_alignment_offset ~free_space ~num_items ~gap ~alignment_mode ~layout_is_flex_reversed ~is_first computes the positional offset for align-content and justify-content in both Flexbox and Grid.
For first item (is_first = true):
Start, Stretch, Space_between: 0Flex_start: free_space if reversed, else 0End: free_spaceFlex_end: 0 if reversed, else free_spaceCenter: free_space / 2Space_around: free_space / num_items / 2 (if positive), else free_space / 2Space_evenly: free_space / (num_items + 1) (if positive), else free_space / 2For subsequent items (is_first = false):
gap + 0Space_between: gap + free_space / (num_items - 1)Space_around: gap + free_space / num_itemsSpace_evenly: gap + free_space / (num_items + 1)Negative free_space is clamped to 0 for subsequent items.
Invariant: For Grid, gap must be 0 as Grid handles gaps separately.