SwiftUI-style declarative UI DSL for Nim — targets HTML/CSS via the Nim JS backend.
NimUI lets you build web frontends entirely in Nim. Describe your UI with a declarative DSL inspired by SwiftUI, compile it to JavaScript with nim js, and render it in the browser.
- Declarative DSL —
Text,VStack,HStack,Buttonwith a SwiftUI-like syntax - Modifier chains —
.padding(),.foregroundColor(),.font()and more - HTML/CSS output — renders to semantic HTML with inline styles and hashed CSS classes
- XSS-safe — user text is HTML-escaped by default
- Event handlers —
Buttonactions compile to JavaScript<script>blocks - Zero runtime dependencies — ships a single JS file
- Nim >= 1.6.0
nimble install nimuiimport nimui
import nimui/modifiers
let doc = App:
VStack:
Text("Hello, World!")
.padding(16)
.foregroundColor("#333")
.font(24)
HStack:
Text("Welcome to ")
.foregroundColor("#666")
Text("NimUI")
.foregroundColor("#007acc")
.font(20)
Button(text = "Click me"):
echo "Button clicked!"
document.body.innerHTML = doc.render().cstringnim js -o:build/app.js src/main.nimThen include the output JS in an HTML page.
| Command | Description |
|---|---|
nimble build |
Build the NimUI library (JS backend) |
nimble buildExample |
Build the hello-world example |
nimble test |
Run unit tests (C backend) |
nimble testJs |
Smoke test — compile to JS |
nimble clean |
Remove build artifacts |
nimui.nim — Public API entry point; re-exports macros and runtime types
nimui/
core.nim — Domain entities (RootView, Modifier, Handler)
render.nim — HTML rendering (string concatenation, HTML escaping)
modifiers.nim — UFCS modifier procs (.padding, .foregroundColor, .font)
nimui.js — JavaScript runtime support
The ui macro collects view declarations at compile time into a UiBuilder. At runtime, render() walks the view tree and produces an HTML fragment.
v0.1.0 — MVP. Core components (Text, VStack, HStack, Button) and basic modifiers are implemented. See aidlc-docs/ for design documentation.
⚠️ Experimental — Under Active DevelopmentNimUI is an experimental project (v0.1.0) and is still under active development. Not all features are stable, and the API may change without notice.
NimUI is inspired by SwiftUI's declarative syntax but is not a full reimplementation of SwiftUI. The following major SwiftUI features are not yet supported:
| Category | SwiftUI Feature | Status |
|---|---|---|
| Layout | List, Form, ScrollView |
❌ Not implemented |
LazyVStack, LazyHStack, Grid |
❌ Not implemented | |
Spacer, Divider |
❌ Not implemented | |
| Navigation | NavigationView, NavigationLink |
❌ Not implemented |
TabView, Sheet, FullScreenCover |
❌ Not implemented | |
| State Management | @State, @Binding |
❌ Not implemented |
@ObservedObject, @EnvironmentObject |
❌ Not implemented | |
@Environment |
❌ Not implemented | |
| Controls | Toggle, Slider, Stepper |
❌ Not implemented |
Picker, TextField, SecureField |
❌ Not implemented | |
TextEditor, DatePicker, ColorPicker |
❌ Not implemented | |
| Modifiers | .frame(), .background(), .overlay() |
❌ Not implemented |
.border(), .shadow(), .clipShape() |
❌ Not implemented | |
.rotation(), .scale(), .animation() |
❌ Not implemented | |
.transition(), .gesture() |
❌ Not implemented | |
.onAppear(), .onDisappear() |
❌ Not implemented | |
| Styling | Color, Font, Image |
❌ Not implemented |
Shape (Circle, Rectangle, etc.) |
❌ Not implemented | |
| Accessibility | .accessibilityLabel(), .accessibilityHint() |
❌ Not implemented |
| Advanced | ForEach, conditional ViewBuilder |
❌ Not implemented |
matchedGeometryEffect, preference |
❌ Not implemented | |
onChange |
❌ Not implemented |
This list is not exhaustive. Contributions are welcome!
BSD 3-Clause. See LICENSE for details.