Package-level declarations

Types

Link copied to clipboard
interface ComponentScope

The receiver a JoyDomComponent renders against. Exposes the current node and its parent (for layout/positioning calculations), a Children composable so a component can act as a container, a per-entry Child composable so a component can place children itself, and emit to dispatch events into the same onEvent callback the built-in renderer uses.

Link copied to clipboard
typealias EventParams = Map<String, <Error class: unknown class>>

Typed accessors over any Map<String, JsonElement> whose values are raw spec JSON — read them through getXxxOrNull / getXxx instead of casting JsonElements by hand.

Link copied to clipboard
data class EventPayload(val type: EventType, val name: String, val params: EventParams?, val payload: EventParams? = null, val target: EventTarget)

Passed to the host's JoyDomEventHandler when a bound event fires. Mirrors React's EventBinding dispatch (js/react/src/types.ts): the spec carries no DOM event, so instead of a SyntheticEvent the payload names the type kind alongside the bound name and its params.

Link copied to clipboard
data class EventTarget(val id: String?, val className: List<String>, val type: String)

The node an event fired on — the joy-dom analog of the DOM event.target. id is the node's id prop (event.target.id), or null when it has none; className is its class list (empty when unset); type is its node type (div, img, a custom type, …), the analog of event.target.tagName.

Link copied to clipboard
sealed interface EventType

The event that triggered a dispatch. The four inbuilt kinds map to a node's typed bindings (onclick/onfocus/onblur/onchange); Custom carries an arbitrary event name emitted by a custom component via ComponentScope.emit.

Link copied to clipboard
fun interface JoyDomComponent

Renderer for a node type, registered via the components DSL. A component receives a ComponentScope giving it the current com.j0y.joy.dom.layout.ResolvedNode and its parent, a Children composable to render the node's children as a container, and an emit hook into the event system.

Link copied to clipboard
Link copied to clipboard

The component registry passed to JoyDom. Build one with the components DSL.

Link copied to clipboard
Link copied to clipboard

The single host callback every node event binding dispatches into. There is no registry and no per-event registration: when any bound event fires, JoyDom invokes this with the full EventPayload, and the host switches on EventPayload.name to decide what to do (ignoring an event is just not matching it). Passing null (the default) still makes a bound node interactive (clickable/focusable) — the dispatch is just dropped.

Link copied to clipboard
typealias JoyDomHostEventHandler = (<Error class: unknown class>) -> Unit

The single host callback a store-backed JoyDom dispatches into.

Link copied to clipboard

Factory invoked when a replaced element (img) renders. The renderer reads src from node.props["src"] (or the node-level node["src"]) and asks the factory to produce a Painter; if it returns null, the element renders as an empty Box.

Link copied to clipboard

Compose's view of a JoyStore: the resolved spec, the current state and the session log are snapshot state, so committing an interaction recomposes whatever reads them.

Link copied to clipboard
typealias JoyDomStoreErrorHandler = (<Error class: unknown class>, <Error class: unknown class>) -> Unit

Diagnostics for an interaction that stopped early.

Properties

Link copied to clipboard

The default JoyDomPainterFactory: loads each src via Coil 3's rememberAsyncImagePainter. Exposed so a custom factory can delegate to it for srcs it doesn't handle itself (e.g. myScheme(src) ?: CoilPainterFactory(src)).

Link copied to clipboard

The current Viewport that drove this resolution — width, height, orientation, and print flag. Provided by JoyDom and accessible from inside any custom component registered via the components parameter, so a component can render differently based on the live environment (e.g. a "viewport info" debug overlay).

Functions

Link copied to clipboard
fun <Error class: unknown class>.apply(text: String): String

Applies this joy-dom TextTransform to text, returning the transformed string.

Link copied to clipboard
fun clampCss(value: Dp, min: Dp?, max: Dp?): Dp

Clamp a Dp to a CSS min/max range.

Link copied to clipboard

Build the component registry for JoyDom:

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getBoolean(key: String): Boolean

The $key value as a Boolean; throws if absent or not a boolean.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getBooleanOrNull(key: String): Boolean?

The $key value as a Boolean, or null if absent or not a boolean.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getDouble(key: String): Double

The $key value as a Double; throws if absent or not a number.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getDoubleOrNull(key: String): Double?

The $key value as a Double, or null if absent or not a number.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getFloat(key: String): Float

The $key value as a Float; throws if absent or not a number.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getFloatOrNull(key: String): Float?

The $key value as a Float, or null if absent or not a number.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getInt(key: String): Int

The $key value as an Int; throws if absent or not an integer.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getIntOrNull(key: String): Int?

The $key value as an Int, or null if absent or not an integer.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getLong(key: String): Long

The $key value as a Long; throws if absent or not a long.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getLongOrNull(key: String): Long?

The $key value as a Long, or null if absent or not a long.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getString(key: String): String

The $key value as a String; throws if absent or null.

Link copied to clipboard
fun Map<String, <Error class: unknown class>>.getStringOrNull(key: String): String?

The $key value as a String, or null if absent or kotlinx.serialization.json.JsonNull.

Link copied to clipboard
fun JoyDom(store: JoyDomStore, modifier: Modifier = Modifier, components: JoyDomComponentsConfig = JoyDomComponentsConfig.Empty, painterFactory: JoyDomPainterFactory = CoilPainterFactory)

Render a hoisted JoyDomStore. The store's callbacks were fixed when it was created (see rememberJoyDomStore); this overload only draws it and feeds every fired binding back in.

fun JoyDom(resolved: <Error class: unknown class>, modifier: Modifier = Modifier, components: JoyDomComponentsConfig = JoyDomComponentsConfig.Empty, painterFactory: JoyDomPainterFactory = CoilPainterFactory, onEvent: JoyDomEventHandler? = null)

Lower-level entry: render a pre-resolved ResolvedSpec without re-running cascade / breakpoint evaluation. Useful when the caller already has the resolved tree (e.g. from a test fixture or a memoised resolution) and wants to skip viewport probing.

fun JoyDom(spec: <Error class: unknown class>, modifier: Modifier = Modifier, components: JoyDomComponentsConfig = JoyDomComponentsConfig.Empty, painterFactory: JoyDomPainterFactory = CoilPainterFactory, onEvent: JoyDomEventHandler? = null)

Render a joy-dom Spec into Compose UI.

fun JoyDom(view: <Error class: unknown class>, initialState: <Error class: unknown class> = JsonObject(emptyMap()), modifier: Modifier = Modifier, components: JoyDomComponentsConfig = JoyDomComponentsConfig.Empty, painterFactory: JoyDomPainterFactory = CoilPainterFactory, onEvent: JoyDomHostEventHandler? = null, onError: JoyDomStoreErrorHandler? = null)

Render a view template — a document carrying state, defs and handlers alongside layout — with the logic layer wired up.

Link copied to clipboard
fun rememberJoyDomStore(view: <Error class: unknown class>, initialState: <Error class: unknown class> = JsonObject(emptyMap()), resolver: <Error class: unknown class> = Resolver.Default, onEvent: JoyDomHostEventHandler? = null, onError: JoyDomStoreErrorHandler? = null): JoyDomStore

Creates and remembers the JoyDomStore for view, seeded with initialState.

Link copied to clipboard

Resolve a CSS font-family value to a Compose FontFamily.

Link copied to clipboard
fun EventPayload.runtimePayload(): <Error class: unknown class>

The runtime data a custom component passed to emit — what {"$event": …} reads, before the binding's own params are merged over it.

Link copied to clipboard
fun EventPayload.toBinding(): <Error class: unknown class>

The renderer's EventPayload as the binding the interpreter runs.

Link copied to clipboard
fun <Error class: unknown class>.toComposeFontStyle(): FontStyle

Maps this joy-dom FontStyle to the equivalent Compose ComposeFontStyle.

Link copied to clipboard
fun <Error class: unknown class>.toComposeFontWeight(): FontWeight

Maps this joy-dom FontWeight to the equivalent Compose ComposeFontWeight.

Link copied to clipboard
fun <Error class: unknown class>.toComposeTextAlign(): TextAlign

Maps this joy-dom TextAlign to the equivalent Compose ComposeTextAlign.

Link copied to clipboard
fun <Error class: unknown class>.toComposeTextDecoration(): TextDecoration

Maps this joy-dom TextDecoration to the equivalent Compose ComposeTextDecoration.

Link copied to clipboard
fun <Error class: unknown class>?.toComposeTextOverflow(): TextOverflow

Maps this joy-dom TextOverflow (or null, the unset/clip default) to the Compose ComposeTextOverflow.

Link copied to clipboard
fun <Error class: unknown class>.toComposeTextStyle(): TextStyle

Build a Compose TextStyle from a fully-resolved TextContext.

fun <Error class: unknown class>.toComposeTextStyle(resolveFontFamily: (String) -> FontFamily): TextStyle

toComposeTextStyle overload taking a custom font-family resolver — the renderer threads LocalJoyDomFontResolver here so a caller-supplied resolver (e.g. one that loads bundled faces) is honoured.

Link copied to clipboard
fun <Error class: unknown class>.toDpOrNull(): Dp?

Convert a px Length to Compose Dp.

Link copied to clipboard
fun <Error class: unknown class>.toFractionOrNull(): Float?

Convert a percent Length (0..100) to a fraction (0..1) for Compose modifiers like Modifier.fillMaxWidth(fraction). Returns null for px lengths.

Link copied to clipboard
fun <Error class: unknown class>.toMaxLines(): Int

Maps this joy-dom WhiteSpace to Compose's max-lines: 1 for nowrap, else Int.MAX_VALUE.

Link copied to clipboard
fun <Error class: unknown class>.toSoftWrap(): Boolean

Maps this joy-dom WhiteSpace to Compose's soft-wrap flag: false for nowrap, else true.

Link copied to clipboard
fun <Error class: unknown class>.toSpOrNull(): TextUnit?

Convert a px Length used as a typography size (font-size, letter-spacing, line-height-as-distance) to Compose TextUnit in sp. We use sp so user font-scale preferences apply — matching browser zoom behaviour for text. Returns null for percent.