@jsvision/ui / solveTrack
Function: solveTrack()
solveTrack(
total,items,gap?):number[]
Defined in: ui/src/layout/apportion.ts:171
Solve a 1-D flex track into exact integer sizes. Fixed items keep their size; flexible items split whatever space is left after the fixed items and the gaps, shared out via apportion so the sizes plus gaps fill total exactly whenever a flexible item has free space.
A flexible item may carry an optional min cell floor. When any does, the free space is solved so no item falls below its floor (squeezing proportionally if the floors cannot all be met); when none does, the plain apportionment runs unchanged — so every pre-existing caller is byte identical.
Parameters
total
number
Integer cells available along the axis.
items
readonly TrackItem[]
Track items, in order — each { kind: 'fixed', size } or { kind: 'flex', weight } (a flex item may add an optional min cell floor).
gap?
number = 0
Integer gap between adjacent items (default 0). Gaps are reserved from the total before flexible items are sized, but the returned sizes are item sizes only — placing the gaps is the caller's job.
Returns
number[]
One integer size per item.
Example
import { solveTrack } from '@jsvision/ui';
// A 20-cell row: a 5-cell fixed sidebar plus two equal flexible panes.
solveTrack(20, [
{ kind: 'fixed', size: 5 },
{ kind: 'flex', weight: 1 },
{ kind: 'flex', weight: 1 },
]); // → [5, 8, 7] (the 15 free cells split 8/7, summing to exactly 20)
// A binding minimum: the first pane never solves below 15 cells.
solveTrack(20, [
{ kind: 'flex', weight: 1, min: 15 },
{ kind: 'flex', weight: 1 },
]); // → [15, 5] (the floor binds; still sums to exactly 20)