@jsvision/ui / solveTrack
Function: solveTrack()
solveTrack(
total,items,gap?):number[]
Defined in: ui/src/layout/apportion.ts:99
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.
Parameters
total
number
Integer cells available along the axis.
items
readonly TrackItem[]
Track items, in order — each { kind: 'fixed', size } or { kind: 'flex', weight }.
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)