This module provides memory-efficient storage of CSS length values using tagged float representation. A single float value encodes both the numeric value and its type (length, percentage, auto, etc.) using low-order bits as tags.
On 64-bit platforms, the implementation stores a 32-bit float value in the upper 32 bits and an 8-bit tag in the lower 8 bits of a 64-bit float, preserving full f32 precision. On 32-bit platforms, a different encoding is used with reduced precision.
This encoding allows toffee's style types to remain compact while supporting the full range of CSS dimension values.
Conventions
The following conventions apply throughout toffee's style modules:
Percentage range: Percentages are represented in [0.0, 1.0], not [0.0, 100.0]. For example, 50% is 0.5.
Abstract units: Length values are in abstract units. The interpretation (pixels, logical pixels, mm, etc.) is application-defined.
f32 precision: Resolution operations use 32-bit float precision to match Rust taffy's arithmetic behavior and ensure consistent layout results across implementations.
Compact length value represented as a tagged float.
The low-order bits encode the value type, while the remaining bits store the numeric value. This representation is opaque; use the constructor and inspection functions to create and examine values.
Fractional units (fr) divide available space proportionally in CSS Grid layouts. The value is the numerator of the fraction; the denominator is the sum of all fr values in that grid dimension.
fit_content_percent limit creates a fit-content length with percentage limit.
The size is computed as max(min_content, min(max_content, limit)), where limit is resolved as a percentage of the containing block, then clamped by the min-content and max-content sizes.
is_max_content_alike t returns true if t behaves like max-content.
Returns true for auto, max-content, and fit-content variants. Per CSS Grid specification: "In all cases, treat auto and fit-content() as max-content, except where specified otherwise for fit-content()."
get_value t extracts the numeric value without validation.
This is a low-level function for internal use. Unlike value, this does not raise for auto/min-content/max-content, returning an undefined value instead.
Tag constants
These are internal constants for low-level tag inspection.
resolved_percentage_size_with_calc t parent_size calc_resolver resolves percentage or calc to absolute length.
Returns Some value if t is a percentage or calc expression. For percentages, computes value * parent_size with f32 precision. For calc expressions, applies calc_resolver. Returns None otherwise.