Module Compute_flexboxSource

Flexbox layout computation algorithm.

Implements the CSS Flexbox specification (https://www.w3.org/TR/css-flexbox-1/) following the W3C algorithm structure. This is a direct port of taffy's flexbox implementation.

Algorithm Overview

The flexbox algorithm proceeds in stages following the W3C spec numbering:

  1. Initial Setup: Generate flex items from children, compute constants from container style.
  2. Line Length Determination: Determine available space, compute flex base sizes and hypothetical sizes, determine container main size.
  3. Main Size Determination: Collect items into lines, resolve flexible lengths.
  4. Cross Size Determination: Determine hypothetical cross sizes, calculate baselines, compute line cross sizes, handle align-content stretch, determine used cross sizes.
  5. Main-Axis Alignment: Distribute remaining free space using justify-content.
  6. Cross-Axis Alignment: Resolve cross-axis auto margins, determine container cross size, align lines, align items within lines.
  7. Final Positioning: Resolve insets, compute absolute positions, accumulate scroll offsets, handle hidden items.

Key Invariants

Performance Notes

Sourceval compute_flexbox_layout : (module Tree.LAYOUT_PARTIAL_TREE with type t = 't) -> 't -> Tree.Node_id.t -> Tree.Layout_input.t -> Tree.Layout_output.t

compute_flexbox_layout tree node inputs computes flexbox layout for node.

Entry point for flexbox layout. Resolves size constraints, applies box-sizing adjustments, and delegates to internal algorithm stages. Short-circuits when container size is fully determined and inputs.run_mode = ComputeSize.