@tty-pt/lamina logo

@tty-pt/lamina

npm version License: BSD-2-Clause TypeScript Ready Node.js Native WebAssembly Zero Dependencies

Universal Node.js and Browser bindings for liblamina, the immediate-mode 2D/3D graphics layer, tilemap renderer, perspective camera math, flexbox UI layout engine, and WebAssembly-to-WebGL2 hardware capability bridge. Canonical C headers: <ttypt/lam.h>, <ttypt/lam-ui.h>, <ttypt/lam-cam.h>, <ttypt/lam-tm.h>, and <ttypt/webgl.h>.

๐Ÿ“– Full C & Graphics Documentation: See the main liblamina GitHub README for desktop OpenGL/GLFW, Linux /dev/fb0 framebuffer setup, 3D terrain/water/billboard rendering, and C API details.


1. Overview & Domain Concepts

liblamina (@tty-pt/lamina) provides an ultra-compact immediate-mode rendering and layout pipeline across native C, Node.js, and Browser WebGL2/Canvas runtimes:

  1. Immediate-Mode Pixel Surfaces (LaminaSurface):
  1. 2D & 3D Viewport & Camera Projection (ViewportController):
  1. CSS Flexbox & Grid Layout Engine (FlexNode):
  1. WebAssembly-to-WebGL2 Capability Bridge (createLaminaBridge, htdocs/webgl-cap.js):

2. Installation

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/lamina

Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (liblamina) across all 9 platforms โ€” Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, Scoop, MSYS2), OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ โ€” liblamina.xcframework + SwiftPM) โ€” are available via the tty.pt package repositories.


3. Quickstart

import {
  LaminaSurface,
  ViewportController,
  FlexNode,
  rgba,
  createLaminaBridge
} from "@tty-pt/lamina";

// 1. Immediate-mode pixel surface in WASM linear memory
const surface = new LaminaSurface(320, 240);
surface
  .clear(rgba(32, 32, 40, 255))
  .fill(20, 20, 100, 60, rgba(80, 180, 255, 255))
  .line(0, 0, 319, 239, rgba(255, 255, 255, 255), 2);

const pixels = surface.getPixels(); // Uint32Array view
console.log("Top-left pixel:", pixels[0].toString(16));
surface.free();

// 2. Camera coordinate projection & unprojection
const viewport = new ViewportController(1280, 720);
viewport.setCamera(100, 200, 1.5 /* zoom */);
const screenPos = viewport.worldToScreen(100, 200);
console.log("Screen center:", screenPos); // { x: 640, y: 360 }

// 3. Headless Flexbox UI layout calculation
const root = new FlexNode("row").setPadding(8, 8, 8, 8);
const sidebar = new FlexNode("column").setSize(200, 0).setFlex(0, 0);
const content = new FlexNode("column").setFlex(1, 1);
root.addChild(sidebar).addChild(content).computeLayout(1024, 768);
console.log("Content bounds:", content.getBounds());
root.free();

4. JavaScript / TypeScript API Reference

LaminaSurface

ViewportController

FlexNode

Color, Canvas & WebGL2 Capability Bridge


5. C Development Headers & Native Integration

CFLAGS += -I./node_modules/@tty-pt/lamina/include
LDLIBS += -llamina

License

BSD-2-Clause โ€” Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.