@tty-pt/bud logo

@tty-pt/bud

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

Universal Node.js and Browser bindings for libbud, the pure-C declarative 5-field UI binder, virtual DOM diffing engine, host-agnostic reactive reconciler, and automatic JSX runtime. Canonical C headers: <bud/bud.h>, <bud/bud_jsx.h>, <bud/bud_app.h>, <bud/bud_reconcile.h>, <bud/bud_dom_host.h>, and <bud/cx.h>.

๐Ÿ“– Full C & UI Engine Documentation: See the main libbud GitHub README for C JSX macro builders, bud_arena bump allocators, bud_dom_host, the .cx transpiler / cx-lsp / tree-sitter-cx toolchain, SSR HTML rendering, and VDOM diffing internals.


1. Quickstart & Installation

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

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

import { h, diffVdom } from "@tty-pt/bud";

// 1. Build virtual DOM node tree
const vdom = h("div", { class: "card" }, [
  h("h2", {}, ["Member Card"]),
  h("p", {}, ["Status: Active"])
]);

console.log(vdom.render());
// <div class="card"><h2>Member Card</h2><p>Status: Active</p></div>

// 2. VDOM Diffing
const updatedVdom = h("div", { class: "card" }, [
  h("h2", {}, ["Member Card"]),
  h("p", {}, ["Status: Suspended"])
]);

const patches = diffVdom(vdom, updatedVdom);
console.log(patches);
// [ { type: 'patch-text', op: 'patch-text', a: 'Status: Suspended', text: 'Status: Suspended' } ]

Automatic JSX Runtime (@tty-pt/bud/jsx-runtime)

Configure "jsx": "react-jsx" and "jsxImportSource": "@tty-pt/bud" in tsconfig.json (see examples/jsx-app/):

import { useState, render } from "@tty-pt/bud/jsx-runtime";

function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount((c) => c + 1)}>Count: {count}</button>;
}

render(<Counter />, document.getElementById("root")!);

2. JavaScript / TypeScript API Reference

h(tag: string, attrs?: Record<string, string>, children?: Array<BudNode | string>): BudNode

Declarative factory mirroring C bud_node_create() (implemented in dist/node.js).

BudNode

Represents a virtual DOM node with chainable mutation methods:

diffVdom(oldTree: BudNode | null, newTree: BudNode | null): VdomPatch[]

Calculates minimal DOM patch operations between two VDOM trees. Executes strictly in compiled WebAssembly (bud_vdom_diff) or native Node-API (bud_node.node), with zero duplicate JavaScript diffing algorithms.

Returns an array of VdomPatch objects:

interface VdomPatch {
  type: "MOUNT" | "UNMOUNT" | "REPLACE" | "SET_TEXT" | "patch-text" | string;
  op: string;
  a?: string;
  b?: string;
  c?: string;
  text?: string;
  node?: BudNode;
}

@tty-pt/bud/jsx-runtime (jsx-runtime/jsx-runtime.js, jsx-runtime/reconciler.js)

getBudWasm(): WebAssembly.Instance

Direct accessor returning the underlying compiled WebAssembly instance (dist/bud.wasm) loaded with bud_vdom_diff, bud_element, bud_text, bud_arena_*, and memory allocators.

Browser Capability & DOM Host Module (@tty-pt/bud/cap, dist/bud-cap.js)

Provides Web HAL bud.* capability registration on @tty-pt/stele (exposing BudWasmBridge.dispatchExport and slotBridge metadata), bud_dom_host DOM node handle operations (elToId reverse map, onAfterDispatch hook), event payload propagation, { passive: false } wheel listeners, and unsynced/inactive <input>.value patch synchronization.

version(): string

Returns the library semantic version string.


3. C Development Headers via NPM

CFLAGS += -I./node_modules/@tty-pt/bud/include
LDLIBS += -lbud

Includes <bud/bud.h> (bud_arena_*, *_lit zero-copy builders), <bud/bud_jsx.h>, <bud/bud_app.h>, <bud/bud_slot.h>, and <bud/bud_state.h> in npm/include/bud/ (the full native C repository additionally ships <bud/bud_reconcile.h>, <bud/bud_dom_host.h>, <bud/cx.h>, linkable libbud-wasm.a via pkg-config --variable=wasm_lib bud, the .cx transpiler, cx-lsp, and tree-sitter-cx).


4. Building & Testing from Source

make npm-build    # Compiles native addon and WASM reactor
make npm-test     # Runs VDOM, JSX runtime, hooks, events, and reconciler test suites

License

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

Documentation