venik

venik

Flexbox layout engine built for JavaScript games.

✨ Simple API

import { Node, Edge, Justify, Align, Direction } from "venik";

const hud = new Node();
hud.setPadding(Edge.All, 16);
hud.setJustifyContent(Justify.SpaceBetween);
hud.setAlignItems(Align.FlexEnd);

const healthBar = new Node();
healthBar.setWidth("25%");
healthBar.setHeight(24);
hud.insertChild(healthBar, 0);

// Runs every frame. A clean tree returns immediately;
// a dirty one revisits only dirty branches.
function frame(w: number, h: number) {
  hud.setWidth(w);
  hud.setHeight(h);
  hud.calculateLayout(undefined, undefined, Direction.LTR);

  drawRect(
    healthBar.getComputedLeft(),
    healthBar.getComputedTop(),
    healthBar.getComputedWidth(),
    healthBar.getComputedHeight(),
  );
}

⚡ Best-in-class speed

venikflexilyyoga-layout
One leaf changes25µs200µs260µs
50 leaves change510µs730µs1660µs
Full relayout1000µs1050µs3190µs

♻️ Small runtime footprint

venikflexilyyoga-layout
One leaf changes1 KB16 KB1 KB
50 leaves change15 KB77 KB22 KB
Full relayout65 KB181 KB2.1 KB

📦 Small bundle size

venikflexilyyoga-layout
Minified72 KB71 KB125 KB
Minified + gzip19 KB22 KB50 KB