WebBuilders, as used in gnorium.com
HTML, CSS, JS, and SVG DSL builders for Swift, enabling declarative UI construction in Swift environments.
WebBuilders provides type-safe DSL builders for HTML, CSS, JavaScript, and SVG, allowing you to construct web interfaces using Swift's result builder syntax.
Result Builders:
- HTML Builder: Type-safe HTML element construction
- CSS Builder: Declarative CSS styling with compile-time safety
- JS Builder: JavaScript code generation with type safety
- SVG Builder: SVG element construction
Add WebBuilders to your Package.swift:
dependencies: [
.package(url: "https://github.com/gnorium/web-builders", branch: "main")
]Then add it to your target dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "WebBuilders", package: "web-builders")
]
)import HTMLBuilder
import CSSBuilder
import JSBuilder
import SVGBuilder
// Build HTML declaratively
div {
h1 { "Welcome" }
p { "Built with Swift" }
}
// Build CSS declaratively
style {
color(.red)
fontSize(px(16))
}
// Build JavaScript declaratively
const.myVar |= "Hello"
id("console").log(id("myVar"))
// Build SVG declaratively
svg {
circle().cx(50).cy(50).r(40)
}- Swift 6.2+
Apache License 2.0 - See LICENSE for details
Contributions welcome! Please open an issue or submit a pull request.
- design-tokens - Universal design tokens based on Apple HIG
- diff-engine - Platform-agnostic character-level diff engine
- embedded-swift-utilities - Utility functions for Embedded Swift environments
- markdown-utilities - Markdown rendering with media attribution support
- admin-core - Core admin functionalities for web applications
- web-apis - Web API implementations for Swift WebAssembly
- web-components - Reusable UI components for web applications
- web-formats - Structured data format builders
- web-security - Portable security utilities for web applications
- web-types - Shared web types and design tokens