Kotlin web components

Write the HTML.
Keep the Kotlin right next to it.

A .lithe file is your markup, with the Kotlin that drives it and the CSS that styles it in the same place. Lithe renders it to HTML at build time and only ships JavaScript for the parts that move.

Get started GitHub

VS Code extension IntelliJ plugin

Still experimental, and on Maven Central since 0.1.0.

Counter.lithe
<script kotlin>
	prop val step: Int = 1

	var count by state(0)
	val doubled by derived { count * 2 }
</script>

<div class="demo">
	<button class="counter" type="button" @click={count += step}>{count} × 2 = {doubled}</button>
	@if (count > 10) {
		<p>That's a lot of clicks.</p>
	}
</div>

<style>
	.counter {
		padding: 0.6rem 1.2rem;
		border: 0;
		border-radius: 999px;
		background: var(--accent);
		color: var(--on-accent);
		font-weight: 600;
		font-variant-numeric: tabular-nums;
		cursor: pointer;
	}

	.counter:active {
		scale: 0.97;
	}
</style>
Running in this page

Figures

todo app · JavaScript, Brotli

17.4KB

  • Lithe 17.4 KB
  • Svelte 22 KB
  • Solid 20.5 KB
  • Compose 119.7 KB

Lowest of the four.

todo app · hydration, CPU 4x slower

47.5ms

  • Lithe 47.5 ms
  • Svelte 48.0 ms
  • Solid 48.4 ms
  • Compose 194.1 ms

Lowest of the four.

todo app · reverse the list, CPU 4x slower

10.8ms

  • Lithe 10.8 ms
  • Svelte 12.9 ms
  • Solid 10.1 ms
  • Compose 64.0 ms

Solid is ahead here.

Every figure, and how it's measured →

What you get

Small runtime, full toolbox

  1. 01

    Static stays static

    Pages are finished HTML before any script runs. Nothing interactive on a page? It ships no JavaScript. Just a search box? Only the search box wakes up, as an island.

    Static pages and islands →
  2. 02

    Updates in place

    Your component runs once. When a value changes, only the text or attribute that reads it updates. No virtual DOM, no diffing.

    State and effects →
  3. 03

    Just Kotlin

    Props, state and handlers are plain Kotlin, with the typed DOM of kotlin-browser. The client only carries what its components use.

    Component files →
  4. 04

    A real template language

    @if, @for with keys, @when, @await, @key, local @fun fragments, two-way bindings, <head> tags and scoped styles that take Kotlin values.

    Control flow →
  5. 05

    Routing built in

    window.route() follows the URL and matchRoute picks what to show. Links move without a reload, through the Navigation API where the browser has it.

    Routing →
  6. 06

    Friends with Compose

    Lithe components and Compose HTML composables mount each other. In a Kobweb site, a .lithe file under pages is a page, and apiData reads an API route.

    Kobweb →
  7. 07

    Tooling that keeps up

    A dev server that rebuilds on save and swaps markup text edits without a Kotlin compile, plus a language server for VS Code and IntelliJ IDEA.

    Editors →
  8. 08

    Measured, not promised

    Bundle size and load times are measured against Svelte, Solid and Compose on every change that can move them, and published as they come.

    Performance →

Under the hood

From a file to the page

  1. Compile

    Each .lithe file becomes plain Kotlin, one function per component, for the JVM and for the browser.

  2. Render

    At build time, the components run on the JVM against an HTML writer and write the static page.

  3. Hydrate

    In the browser, the same components run on Kotlin/JS and adopt the nodes already there instead of building them again.

How it works, step by step →

Get started

Up and running in a few minutes

  1. Add Lithe

    The Gradle plugin compiles your .lithe files, the runtime does the rest.

  2. Write a component

    An App.lithe with a <script kotlin>, some markup and, if you like, a <style>.

  3. Run the dev server

    It rebuilds on save, and edits to the markup text show up without a Kotlin compile.

Lithe 0.1.0 is on Maven Central. The plugin has no marker artifact yet, so settings.gradle.kts maps its id to its module: Kobweb shows how.

Getting started: run an example, then write an app of your own.

build.gradle.kts
plugins {
	// Compiles the .lithe files of the project
	id("io.github.ayfri.lithe") version "0.1.0"
}

kotlin {
	sourceSets {
		jsMain.dependencies {
			implementation("io.github.ayfri.lithe:runtime-compose:0.1.0")
		}
	}
}

Works with VS Code IntelliJ IDEA Kobweb Compose HTML

This site is a Kobweb site whose pages are .lithe files, and its search runs in your browser on an index written at build time, so only its playground needs a server. Read its sources →