Compose Multiplatform UI library for WebAssembly/JS target - declarative framework for sharing UIs across multiple platforms with Kotlin.
npx @tessl/cli install tessl/maven-org-jetbrains-compose-ui--ui-wasm-js@1.8.0Compose Multiplatform UI for WASM/JS enables developers to create declarative user interfaces that run in web browsers using WebAssembly technology. This package provides the complete Compose UI toolkit optimized for WASM targets, including window management, UI components, resource handling, and browser integration capabilities.
build.gradle.kts:kotlin {
wasmJs {
moduleName = "your-app-name"
browser()
binaries.executable()
}
}
dependencies {
implementation(compose.runtime)
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.components.resources)
}// Window management
import androidx.compose.ui.window.CanvasBasedWindow
import androidx.compose.ui.ExperimentalComposeUiApi
// UI components
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.*
// Resources
import org.jetbrains.compose.resources.*
import org.jetbrains.compose.resources.ExperimentalResourceApi@OptIn(ExperimentalComposeUiApi::class, ExperimentalResourceApi::class)
fun main() {
configureWebResources {
resourcePathMapping { path -> "./$path" }
}
CanvasBasedWindow("My App") {
App()
}
}
@Composable
fun App() {
MaterialTheme {
Surface {
Text("Hello, Compose WASM!")
}
}
}Compose Multiplatform UI for WASM/JS is not a standalone module but part of the unified compose.ui multiplatform system. WASM support is achieved through:
wasmJs target with wasmJsMain source setsCreate and manage application windows with canvas-based rendering, handle application lifecycle events, and configure the main application entry point.
Key APIs:
fun CanvasBasedWindow(
canvasElementId: String? = null,
title: String = "Compose Application",
content: @Composable () -> Unit
)Window Management Documentation
Complete set of declarative UI components including layouts, text, images, buttons, and interactive elements. All standard Compose components work seamlessly with WASM targets.
Key APIs:
@Composable fun Column(modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit)
@Composable fun Row(modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit)
@Composable fun Box(modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit)
@Composable fun Text(text: String, modifier: Modifier = Modifier, style: TextStyle = LocalTextStyle.current)
@Composable fun Button(onClick: () -> Unit, modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit)Full Material Design component library with theming, colors, typography, and interactive components optimized for web deployment.
Key APIs:
@Composable fun MaterialTheme(
colors: Colors = MaterialTheme.colors,
typography: Typography = MaterialTheme.typography,
shapes: Shapes = MaterialTheme.shapes,
content: @Composable () -> Unit
)
@Composable fun Scaffold(
modifier: Modifier = Modifier,
topBar: @Composable () -> Unit = {},
content: @Composable (PaddingValues) -> Unit
)Asynchronous resource loading system for images, strings, fonts, and other assets with web-optimized caching and loading strategies.
Key APIs:
fun configureWebResources(configure: WebResourcesConfiguration.() -> Unit)
@Composable fun painterResource(resource: DrawableResource): Painter
@Composable fun stringResource(resource: StringResource): StringResource Management Documentation
Direct integration with browser APIs, system preferences detection, network operations, and JavaScript interoperability for platform-specific functionality.
Key APIs:
// Browser window access
val window: Window = kotlinx.browser.window
val document: Document = kotlinx.browser.document
// Platform detection
fun getCurrentPlatform(): String
fun getCurrentLanguage(): StringBrowser Integration Documentation
Compose runtime system for state management, side effects, and reactive programming patterns that work seamlessly with WASM execution model.
Key APIs:
@Composable fun <T> remember(calculation: () -> T): T
@Composable fun <T> mutableStateOf(value: T): MutableState<T>
@Composable fun LaunchedEffect(key1: Any?, block: suspend CoroutineScope.() -> Unit)
@Composable fun <T> State<T>.collectAsState(): State<T>State Management Documentation
Minimum Requirements:
Required Features:
wasmJs targetWASM applications are distributed as:
.wasm binary file containing compiled Kotlin code.js loader script for WASM initializationindex.html entry point with canvas elementCommon issues and solutions: