package toffee
Build not yet checked 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.3.0.tbz
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3
doc/toffee_compute_flexbox/Toffee_compute_flexbox/index.html
Module Toffee_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 Toffee_tree.LAYOUT_PARTIAL_TREE with type t = 't) ->
't ->
Toffee_tree.Node_id.t ->
Toffee_tree.Layout_input.t ->
Toffee_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