package toffee
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
CSS layout engine for OCaml (Flexbox, Grid, Block)
Install
dune-project
Dependency
Authors
Maintainers
Sources
mosaic-0.1.0.tbz
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/compute_flexbox/Compute_flexbox/index.html
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:
- Initial Setup: Generate flex items from children, compute constants from container style.
- Line Length Determination: Determine available space, compute flex base sizes and hypothetical sizes, determine container main size.
- Main Size Determination: Collect items into lines, resolve flexible lengths.
- Cross Size Determination: Determine hypothetical cross sizes, calculate baselines, compute line cross sizes, handle align-content stretch, determine used cross sizes.
- Main-Axis Alignment: Distribute remaining free space using justify-content.
- Cross-Axis Alignment: Resolve cross-axis auto margins, determine container cross size, align lines, align items within lines.
- Final Positioning: Resolve insets, compute absolute positions, accumulate scroll offsets, handle hidden items.
Key Invariants
flex_item.frozendetermines whether an item's size is locked during flexible length resolution.flex_item.violationtracks deviation from target size; items are frozen when violations resolve.flex_line.itemsis a slice into the mainflex_itemsarray, avoiding allocations.algo_constantscaches resolved style properties and container sizes updated during layout.- Main axis direction (row/column) determines which dimension (width/height) is used for main/cross sizing.
Performance Notes
- Uses array-based iteration over flex items and lines for cache locality.
- Mutable fields in
flex_item,flex_line, andalgo_constantsavoid allocations during iterative sizing. - Percentage gaps are re-resolved after container main size is determined.
- Short-circuits in
compute_flexbox_layoutwhen size is fully determined and run mode is ComputeSize.
Source
val compute_flexbox_layout :
(module Tree.LAYOUT_PARTIAL_TREE with type t = 't) ->
't ->
Tree.Node_id.t ->
Tree.Layout_input.t ->
Tree.Layout_output.tcompute_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.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page