package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.style/Style/Length_percentage/index.html
Module Style.Length_percentageSource
CSS length-percentage values.
Length-percentage values represent linear measurements in CSS, supporting both absolute lengths and relative percentages. Values are stored in a compact tagged representation via Compact_length.
See Compact_length for conventions on percentage range, abstract units, and f32 precision.
A CSS length-percentage value.
Constructors
percent value creates a percentage length.
The value is a fraction in the range 0.0, 1.0, where 0.5 represents 50%. For 0–100 percentage inputs, prefer pct.
pct percent creates a percentage length from a 0–100 value.
pct 50.0 is equivalent to percent 0.5.
calc index creates a calc expression.
The index is an opaque handle to the actual calc representation. The low 3 bits are reserved as a tag and returned as 0.
Constants
Inspection
Value Extraction
value t extracts the numeric value.
For length values, returns the length. For percentage values, returns the percentage in the range 0.0, 1.0.
Raises Failure if t is a calc or any unsupported tag.
Resolution
resolve t context resolves t to an absolute length.
For length values, returns the length unchanged. For percentage values, computes context * value t with f32 precision.
Raises Failure if t is a calc expression or any unsupported tag (auto/min-/max-content or fit-content). Use resolve_with_calc for calc support.
resolve_with_calc t context calc_resolver resolves t to an absolute length.
For length and percentage values, behaves like resolve. For calc values, invokes calc_resolver index context where index is the calc expression handle.
Raises Failure if t is not a length, percentage, or calc value.
maybe_resolve t context calc_resolver resolves t if context is available.
Returns Some length for absolute lengths. Returns Some resolved for percentages and calc expressions when context is Some dim. Returns None when context is None and t is a percentage or calc requiring context.
Raises Failure if t is not a length, percentage, or calc value.
resolve_or_zero t context calc_resolver resolves t, defaulting to 0.0.
Equivalent to maybe_resolve t context calc_resolver |> Option.value ~default:0.0.
Utilities
uses_percentage t returns true if t contains a percentage component.
Returns true for percentage values and calc expressions. Returns false for absolute lengths.
resolved_percentage_size t parent_size resolves percentage to absolute size.
Returns Some (parent_size * value t) if t is a percentage, None otherwise. Uses f32 precision.
val resolved_percentage_size_with_calc :
t ->
float ->
(int -> float -> float) ->
float optionresolved_percentage_size_with_calc t parent_size calc_resolver resolves percentage or calc to absolute size.
Returns Some size for percentages and calc expressions, None for absolute lengths.
Comparison and Formatting
equal a b tests equality of two values.
Calc values are equal if their indices match. Non-calc values are equal if their tags and numeric values match within floating-point epsilon.
compare a b provides total ordering.
Calc values sort before non-calc values. Within each category, values are ordered by tag, then by numeric value.
to_string t formats t for debugging.
Formats as "Npx" for lengths, "N%" for percentages, and "calc(#N)" for calc expressions.
pp fmt t formats t using to_string.