package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/compute_helpers/Compute_helpers/index.html
Module Compute_helpersSource
Shared 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:
- For each axis, if overflow is
Visible, usemax size content_size; otherwise usesize - If both dimensions > 0, return
location + computed_size - Otherwise return zero size
Only 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:
- Distributed alignments (
Stretch,Space_between,Space_around,Space_evenly) fall back whennum_items <= 1orfree_space <= 0:Stretch,Space_between->Flex_start(safe);Space_around,Space_evenly->Center(safe) - When
free_space <= 0andis_safeis true, all modes ->Start
val 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_spaceif reversed, else 0End:free_spaceFlex_end: 0 if reversed, elsefree_spaceCenter:free_space / 2Space_around:free_space / num_items / 2(if positive), elsefree_space / 2Space_evenly:free_space / (num_items + 1)(if positive), elsefree_space / 2
For subsequent items (is_first = false):
- All non-distributed modes:
gap + 0 Space_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.