The DOM-like API
Build native windows from plain JavaScript with createElement, Tailwind classes, events and signals. No React, no browser, no build step.
- Node.js
- Bun
- JavaScript
If you’ve ever written document.createElement, you already know this API. @blender-ui/native gives you the DOM’s shape, Tailwind classes and signals, and draws the result in a native window with BUI’s engine. There’s no browser underneath and no webview: just your script, Node.js or Bun, and a small native addon.
It’s also the layer the React renderer, the Svelte binding and the Vue binding are built on, so everything here works there too.
A counter in 15 lines
const { App, signal } = require('@blender-ui/native')
const app = new App({ gpu: true })const win = app.window({ title: 'Hello', width: 360, height: 220 })win.body.setAttribute('styled', '') // Blender's look for the whole pagewin.body.className = 'm-0 p-6 flex flex-col gap-3 bg-[#2b2b2b] text-[#e6e6e6]'
const clicks = signal(0)const label = win.createElement('span')label.textContent = clicks // bound: the text follows the signalconst button = win.createElement('button')button.textContent = 'Add one'button.addEventListener('click', () => clicks.value++)win.body.appendChild(label)win.body.appendChild(button)Run it with node counter.js or bun counter.js. A window opens with a number and a button. Click the button and the number goes up.
What’s going on:
new App(...)starts BUI. It runs its own UI thread, so your script stays free.app.window(...)opens a native window. Itsbodyis the root element, likedocument.body.setAttribute('styled', '')gives everything inside Blender’s look. Without it, HTML elements look like a browser’s defaults.signal(0)is a value that remembers who’s showing it. Assigning it totextContentbinds the label to it, soclicks.value++updates that one text node and nothing else. Signals have their own page.
The app and its windows
const app = new App({ gpu: true, headless: false, quitOnLastWindowClosed: true })const win = app.window({ title: 'Tool', width: 400, height: 300, resizable: true })win.on('close', () => console.log('bye'))new App(options) |
What it does |
|---|---|
gpu |
Draw on the GPU (Direct3D 11 on Windows, OpenGL on Linux). Off by default: the CPU renderer draws the same pixels. |
slug |
GPU text from glyph outlines (Slug, the default) or a per-glyph atlas. app.setSlug(on) changes it later. |
headless |
No native windows: renders off-screen, for tests and CI. |
quitOnLastWindowClosed |
Quit when the last window closes. Default true. |
app.window(options) takes title, width, height, resizable, gpu (to choose per window), transparent (per-pixel alpha), alwaysOnTop (Windows, macOS and X11), frame: false (no frame) and layerShell ({ layer, anchor, exclusiveZone, keyboard }, a Wayland layer-shell surface; layer is 'background', 'bottom', 'top' or 'overlay', anchor a list of 'top', 'bottom', 'left' and 'right', keyboard 'none', 'exclusive' or 'on-demand'). A Wayland toplevel cannot stay on top: use layerShell. app.quit() closes every window and ends the UI thread, so Node can exit.
A window gives you body, createElement(tag), createTextNode(text), requestAnimationFrame(cb), screenshot(), click(x, y), close() and on(event, fn) for close, focus and blur (the window got or lost the keyboard focus).
Elements and attributes
The tree behaves like the DOM: appendChild, insertBefore, removeChild, remove(), before, after, append, replaceWith, cloneNode, parentNode, childNodes, firstChild, nextSibling and friends. Siblings are a linked list, so inserting, removing and walking siblings cost the same however long the list is.
- Moving a node:
appendChildorinsertBeforeon a node that already has a parent moves it. - Mistakes throw: inserting a node into itself, or before a node that isn’t a child, throws an error, as in a browser.
- Freeing:
destroy()frees a removed subtree natively. Call it when you won’t use the nodes again.
Elements are HTML elements (div, span, button, input, h1 …), laid out with CSS and drawn natively by BUI. They take the usual attributes:
class/className, including Tailwind classes:'p-4 flex gap-2 bg-[#4772b3]'.style, as a CSS string ('color: red') or an object ({ backgroundColor: 'red', width: 40 }). Readingel.stylegives the inline style, withcssText,setPropertyandremoveProperty;el.classListeditsclass.id,href,value,srcand the rest, throughsetAttribute. DOM properties such asdisabled,hidden,checked,valueandtypereflect their attribute. (el.idis the node’s native id, so set theidattribute withsetAttribute.)
Any attribute, style and textContent can be a signal: the node then follows it. Setting a plain value later unbinds the signal.
Blender’s widgets
Capitalized tag names are Blender’s own widgets, always drawn and handled the Blender way:
const size = win.createElement('NumberSlider')size.setAttribute('min', 0)size.setAttribute('max', 10)size.setAttribute('value', 2.5)win.body.appendChild(size)The names are Button, Checkbox, Radio, NumberField, NumberSlider, TextField, TextArea, ColorSwatch, Dropdown and ProgressBar. Each one is an HTML element underneath (NumberSlider is <input type="range">), so it takes the same attributes. Their lowercase twins look like a browser’s form controls, except inside a styled element, where they look like Blender’s too.


examples/site/js/todo_dom.js).Events
button.addEventListener('click', (event) => { console.log(event.clientX, event.clientY, event.shiftKey)})The events are click, dblclick, auxclick, contextmenu, mousedown, mouseup, mousemove, mouseenter, mouseleave, mouseover, mouseout, pointerdown, pointerup, pointermove, pointerenter, pointerleave, pointerover, pointerout, pointercancel, gotpointercapture, lostpointercapture, wheel, keydown, keypress, keyup, focus, blur, focusin, focusout, scroll, pressdrag, input and change, and the touch screen and trackpad gestures pinch, rotate and pan. The event object carries target, currentTarget, eventPhase, clientX/clientY, button, buttons, pointerId, pointerType, deltaX/deltaY, delta, phase, key, the modifier flags (shiftKey, ctrlKey, altKey, metaKey) and timeStamp. pressdrag (Blender’s press-drag: a button held and the pointer moved more than 3 pixels, once per press) adds direction ('east' … 'southeast') and startX/startY; scroll adds scrollLeft/scrollTop.
-
pinch:deltais the scale change since the last one (0.1 is 10% larger: multiply a zoom by1 + delta), aboutclientX/clientY. -
rotate:deltais the degrees turned since the last one, positive counter-clockwise. -
pan:deltaX/deltaYare the pixels the content follows the fingers (x right, y down);phaseis'drag'while a finger is down,'fling'as the content coasts on, and'end'when it lifted. An element listening forpantakes the drag, like CSS’stouch-action: none: nothing under it scrolls by touch. -
They capture and bubble, as in the DOM:
addEventListener(type, fn, { capture: true })hears an event on its way down, ancestors first, and{ once: true }removes the listener after one call.mouseenter,mouseleave,pointerenter,pointerleave,focus,blurandscrolldon’t bubble.stopPropagation()andstopImmediatePropagation()work. -
el.setPointerCapture()keeps the pointer for an element, also when it leaves it or the window, until the button is released (releasePointerCapture(),hasPointerCapture()). Call it in apointerdownhandler, as in the DOM: a drag that follows the pointer out of its element is built on it. -
event.targetis the deepest element listening for that event type. -
preventDefault()only marks the event. Events reach JavaScript after BUI has already handled them, so it can’t cancel what BUI did. -
Form controls keep their latest value: read
el.valueorel.checkedafter aninputorchangeevent.
Detached nodes and document
document (require('@blender-ui/native').document) is a window-less document, as DOM frameworks expect one. Its createElement, createTextNode, createComment and createDocumentFragment make detached nodes: they live in JavaScript until you insert them into a window’s tree, which then creates them and their subtree natively in one go. So one template can be cloned (cloneNode(true)) into any window.
- Fragments insert their children, as in the DOM.
- Comments are anchors: natively an empty text node, which takes no space in layout.
- Freeing: a node made by
documentthat you remove and don’t reinsert by the end of the tick is freed natively for you. Nodes made bywin.createElementkeep the explicitdestroy(). dispatchEvent(event)runs an element’s listeners (and its ancestors’, if the event bubbles);event.composedPath()lists the target and its ancestors. Listeners for event types BUI doesn’t report are accepted, and only fire throughdispatchEvent.
Framework bindings
The React, Svelte and Vue packages are thin adapters over this API, and a binding for another framework plugs in the same way:
@blender-ui/native/hostholds what every binding shares:open(options)(theAppand window behind arender(..., options)),blenderWidgets(wrap)(Blender’s widgets as the framework’s components)styleRegistry()(components’ scoped<style>blocks, added to each window once) andapplyProps(el, prev, next)(JSX-style props such asclassName,styleobjects,onClickand signals, onto an element). A renderer that works with props (React’s reconciler, Vue’screateRenderer, Solid’s custom renderer) calls these.@blender-ui/native/globalsinstallsdocument,window, the node classes andrequestAnimationFrameas globals, for frameworks whose compiled code calls the DOM (Svelte; Solid’s or Lit’s DOM output too).bui buildbundles with the Bun plugin of every@blender-ui/*package that declares one in itspackage.json("bui": { "bunPlugin": "./plugin.js" }). That’s how.sveltefiles compile into a standalone app.
Frames and measuring
let hue = 0function tick () { hue = (hue + 2) % 360 box.style = { backgroundColor: `hsl(${hue} 60% 50%)` } win.requestAnimationFrame(tick)}win.requestAnimationFrame(tick)win.requestAnimationFrame(cb)runscbbefore the next frame, paced by the display. What you change inside it renders in that same frame.cancelAnimationFrame(id)stops it.el.getBoundingClientRect()andwin.screenshot()return promises, because the answer comes from the UI thread.- Changes are sent once per tick.
win.flush()sends them right away, if you ever need to.
Tray, notifications and the taskbar
The desktop shell has Electron’s names: app.createTray({ icon, tooltip, menu }) (a Tray with
setContextMenu, setToolTip, setImage, on('click'), destroy), app.notify({ title, body, onClick }), win.setProgressBar(0.4, { mode }) and app.addRecentDocument(path). See
Desktop shell for each platform.
const tray = await app.createTray({ icon: 'BLENDER', tooltip: 'My app' })tray?.setContextMenu([{ label: 'Quit', click: () => app.quit() }])win.setProgressBar(0.5)Testing without a window
new App({ headless: true }) renders off-screen. Combine it with win.click(x, y) and win.screenshot() to test a UI in CI (win.mouseMove, win.mouseDown and win.mouseUp drive the pointer, win.touch(id, phase, x, y) a touch screen’s fingers, and win.pinch(x, y, delta) and win.rotate(x, y, degrees) a trackpad’s gestures):
const { App } = require('@blender-ui/native')
const app = new App({ headless: true })const win = app.window({ width: 200, height: 100 })const button = win.createElement('button')button.textContent = 'Go'let clicked = falsebutton.addEventListener('click', () => { clicked = true })win.body.appendChild(button)
button.getBoundingClientRect().then(async (r) => { win.click(r.x + 5, r.y + 5) const shot = await win.screenshot() // { width, height, data } in RGBA console.log(shot.width, shot.height) setTimeout(() => { console.log('clicked:', clicked); app.quit() }, 100)})How it stays fast
- Its own UI thread. BUI runs its message loop on a thread of its own. JavaScript is never blocked, and an idle window uses no CPU.
- Only changes cross. Your script keeps the tree. Each tick, a window sends one
Int32Arrayof operations plus a small string table to the UI thread. - A retained mirror. The UI thread keeps its own copy of the tree, so layout caches and form state persist, and a
stylestring is parsed once, when you set it.
The numbers, with their context, are on the standalone executables page.
Next steps
The same engine, written as JSX components with React’s hooks.
Svelte 5 components, runes and snippets on the same engine.
Vue 3 single-file components on the same engine.
How a signal updates one node without re-rendering anything.
Ship your app as one file of about 7 MB.
Last updated