Skip to content

FlexilyPure JavaScript Flexbox Layout

Need flexbox layout outside the browser? Yoga requires WASM, async init, and leaks memory in long-running apps. Flexily is a pure JavaScript drop-in replacement β€” 1.5-5.5x faster, 3x smaller, no WASM. Powers Silvery's terminal UI layout.

Quick Start ​

bash
npm install flexily
bash
bun add flexily
bash
pnpm add flexily
bash
yarn add flexily
typescript
import { createFlexily, FLEX_DIRECTION_ROW } from "flexily"

const flex = createFlexily()

const root = flex.createNode()
root.setWidth(100)
root.setFlexDirection(FLEX_DIRECTION_ROW)

const child = flex.createNode()
child.setFlexGrow(1)
root.insertChild(child, 0)

flex.calculateLayout(root, 100, 100)
console.log(child.getComputedWidth()) // 100

Custom Composition ​

Build your own Flexily instance with only the plugins you need:

typescript
import { createBareFlexily, pipe, withTestMeasurer } from "flexily"

const flex = pipe(createBareFlexily(), withTestMeasurer())

Available plugins: withMonospaceMeasurer() (terminal), withTestMeasurer() (deterministic), withPretextMeasurer() (proportional fonts via Pretext).

Low-Level API ​

For direct Yoga-compatible usage without the composable engine:

typescript
import { Node, FLEX_DIRECTION_ROW, DIRECTION_LTR } from "flexily"

const root = Node.create()
root.setWidth(100)
root.setFlexDirection(FLEX_DIRECTION_ROW)

const child = Node.create()
child.setFlexGrow(1)
root.insertChild(child, 0)

root.calculateLayout(100, 100, DIRECTION_LTR)
console.log(child.getComputedWidth()) // 100

Who Should Use Flexily ​

Most developers should use a framework built on Flexily, not Flexily directly. Flexily is for:

  • Framework authors building a TUI or layout framework that needs a JS layout engine
  • Canvas/game developers who need flexbox for non-DOM rendering
  • Specialized tools where you need direct control over layout computation
  • Anyone replacing Yoga who wants a drop-in pure-JS alternative

Building a terminal UI? Use Silvery, which uses Flexily by default. You get React components, hooks, and layout feedback without touching the low-level API.