or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdkotlinx-dom.mdorg-w3c-additional.mdorg-w3c-dom.mdorg-w3c-events.mdorg-w3c-networking.md
tile.json

tessl/maven-org-jetbrains-kotlin--kotlin-dom-api-compat

Kotlin DOM API compatibility library providing JavaScript interoperability and DOM manipulation utilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.jetbrains.kotlin/kotlin-dom-api-compat@1.9.x

To install, run

npx @tessl/cli install tessl/maven-org-jetbrains-kotlin--kotlin-dom-api-compat@1.9.0

index.mddocs/

Kotlin DOM API Compatibility

Kotlin DOM API Compatibility is a comprehensive library providing JavaScript interoperability and DOM manipulation utilities for Kotlin/JS applications. It bridges Kotlin type-safe programming with standard web APIs, offering complete W3C DOM bindings, HTML element interfaces, media handling, graphics support, and modern browser APIs.

Package Information

  • Package Name: kotlin-dom-api-compat
  • Package Type: maven
  • Language: Kotlin
  • Installation: Add to build.gradle.kts: implementation("org.jetbrains.kotlin:kotlin-dom-api-compat:1.9.25")

Core Imports

// Core DOM manipulation utilities
import kotlinx.dom.*
import kotlinx.browser.*

// W3C DOM APIs
import org.w3c.dom.*
import org.w3c.dom.events.*

// Media APIs
import org.w3c.dom.mediacapture.*
import org.w3c.files.*

// Graphics APIs  
import org.w3c.dom.svg.*
import org.khronos.webgl.*

// Networking APIs
import org.w3c.fetch.*
import org.w3c.xhr.*

Basic Usage

import kotlinx.browser.document
import kotlinx.browser.window
import kotlinx.dom.*
import org.w3c.dom.HTMLButtonElement
import org.w3c.dom.events.Event

// Create and manipulate DOM elements
val button = document.createElement("button") {
    textContent = "Click me!"
    addClass("btn", "btn-primary")
}

// Add event handling
button.addEventListener("click") { event ->
    window.alert("Button clicked!")
}

// Append to document
document.body?.appendChild(button)

// DOM query and manipulation
val elements = document.querySelectorAll(".item")
elements.forEach { element ->
    element.addClass("processed")
    element.appendText("✓")
}

Architecture

Kotlin DOM API Compatibility provides comprehensive W3C standards compliance with 500+ public API elements organized into several key areas:

  • Core DOM APIs - Complete W3C DOM interfaces for document manipulation, element access, and node operations
  • HTML Elements - Full HTML element hierarchy with type-safe property access and method calls
  • Event System - Comprehensive event handling including mouse, keyboard, touch, and custom events
  • Media APIs - Audio/video handling, media capture, streaming, and encrypted media support
  • Graphics APIs - SVG manipulation (117+ classes) and WebGL rendering with typed arrays
  • Networking APIs - Fetch API, XMLHttpRequest, headers, and CORS handling
  • Storage APIs - File handling, blob manipulation, and browser storage access
  • Worker APIs - Service workers, web workers, and cache management
  • Browser Integration - Direct access to global browser objects and modern web APIs
  • DOM Utilities - Kotlin-specific extensions for elegant DOM manipulation and CSS class management

Capabilities

Core DOM and HTML Elements

Complete W3C DOM API bindings with type-safe access to all HTML elements, document structure, and node operations. Includes extensive HTML element hierarchy with properties and methods.

// DOM access
val document: Document
val window: Window

// Element creation and manipulation
fun Document.createElement(name: String, init: Element.() -> Unit): Element
fun Element.appendElement(name: String, init: Element.() -> Unit): Element

// HTML element interfaces
interface HTMLElement : Element, GlobalEventHandlers, ElementContentEditable
interface HTMLButtonElement : HTMLElement
interface HTMLInputElement : HTMLElement

Core DOM and HTML Elements

Event System

Comprehensive event handling system supporting all standard web events including mouse, keyboard, touch, pointer, focus, and custom events with full type safety.

interface Event {
    val type: String
    val target: EventTarget?
    val currentTarget: EventTarget?
    fun preventDefault()
    fun stopPropagation()
}

interface EventTarget {
    fun addEventListener(type: String, callback: EventListener?, options: dynamic = definedExternally)
    fun removeEventListener(type: String, callback: EventListener?, options: dynamic = definedExternally)
    fun dispatchEvent(event: Event): Boolean
}

class MouseEvent : UIEvent
class KeyboardEvent : UIEvent
class TouchEvent : UIEvent

Event System

Media APIs

Comprehensive media handling including audio/video elements, media capture (camera/microphone), media streaming, encrypted media extensions, and media source extensions.

interface MediaStream : EventTarget, MediaProvider {
    val active: Boolean
    val id: String
    fun getAudioTracks(): Array<MediaStreamTrack>
    fun getVideoTracks(): Array<MediaStreamTrack>
    fun addTrack(track: MediaStreamTrack)
    fun removeTrack(track: MediaStreamTrack)
}

interface MediaDevices : EventTarget {
    fun getUserMedia(constraints: MediaStreamConstraints = definedExternally): Promise<MediaStream>
    fun getDisplayMedia(constraints: MediaStreamConstraints = definedExternally): Promise<MediaStream>
    fun enumerateDevices(): Promise<Array<MediaDeviceInfo>>
}

Media APIs

Networking APIs

Modern networking capabilities including Fetch API for HTTP requests, XMLHttpRequest for legacy support, headers manipulation, and comprehensive CORS handling.

class Request(input: dynamic, init: RequestInit = definedExternally) : Body {
    val method: String
    val url: String
    val headers: Headers
    fun clone(): Request
}

class Response(body: dynamic = definedExternally, init: ResponseInit = definedExternally) : Body {
    val status: Short
    val statusText: String
    val ok: Boolean
    fun clone(): Response
}

class Headers(init: dynamic = definedExternally) {
    fun get(name: String): String?
    fun set(name: String, value: String)
    fun append(name: String, value: String)
    fun delete(name: String)
}

Networking APIs

Additional Web APIs

Comprehensive collection of specialized APIs including media capture, file handling, SVG graphics, WebGL rendering, service workers, and web notifications.

// Media Capture
interface MediaStream : EventTarget, MediaProvider {
    val active: Boolean
    val id: String
    fun getAudioTracks(): Array<MediaStreamTrack>
    fun getVideoTracks(): Array<MediaStreamTrack>
}

// File API
class Blob(blobParts: Array<dynamic> = definedExternally, options: BlobPropertyBag = definedExternally) : MediaProvider
class File(fileBits: Array<dynamic>, fileName: String) : Blob

// SVG Graphics
interface SVGSVGElement : SVGGraphicsElement, SVGFitToViewBox
interface SVGPathElement : SVGGeometryElement

// WebGL
interface WebGLRenderingContext : WebGLRenderingContextBase
class Float32Array : ArrayBufferView

// Service Workers
interface ServiceWorker : EventTarget, AbstractWorker
interface Cache
class Notification : EventTarget

Additional Web APIs

DOM Utilities

Kotlin-specific DOM manipulation utilities providing elegant, type-safe extensions for common DOM operations including CSS class management and element building.

// Extension properties
val Node.isText: Boolean
val Node.isElement: Boolean

// DOM manipulation
fun Node.clear()
fun Element.appendText(text: String): Element

// CSS class management  
fun Element.hasClass(cssClass: String): Boolean
fun Element.addClass(vararg cssClasses: String): Boolean
fun Element.removeClass(vararg cssClasses: String): Boolean

// Element builders
fun Document.createElement(name: String, init: Element.() -> Unit): Element
fun Element.appendElement(name: String, init: Element.() -> Unit): Element

// Browser globals
val window: Window
val document: Document
val localStorage: Storage
val sessionStorage: Storage

DOM Utilities

Types

Core Types

external interface Window : EventTarget, GlobalEventHandlers, WindowEventHandlers {
    val document: Document
    val location: Location
    val history: History
    val localStorage: Storage
    val sessionStorage: Storage
    fun alert(message: String)
    fun confirm(message: String): Boolean
    fun prompt(message: String, defaultText: String = definedExternally): String?
}

external interface Document : Node, DocumentOrShadowRoot, GlobalEventHandlers {
    val documentElement: Element?
    val head: HTMLHeadElement?
    val body: HTMLElement?
    fun createElement(localName: String): Element
    fun createTextNode(data: String): Text
    fun getElementById(elementId: String): Element?
    fun querySelector(selectors: String): Element?
    fun querySelectorAll(selectors: String): NodeList
}

external interface Element : Node, ChildNode, ParentNode, Slotable {
    val tagName: String
    val id: String
    val className: String
    val classList: DOMTokenList
    fun getAttribute(qualifiedName: String): String?
    fun setAttribute(qualifiedName: String, value: String)
    fun removeAttribute(qualifiedName: String)
    fun querySelector(selectors: String): Element?
    fun querySelectorAll(selectors: String): NodeList
}

Event Types

external interface EventInit {
    var bubbles: Boolean?
    var cancelable: Boolean?
    var composed: Boolean?
}

external interface MouseEventInit : EventModifierInit {
    var screenX: Int?
    var screenY: Int?
    var clientX: Int?
    var clientY: Int?
    var button: Short?
    var buttons: Short?
    var relatedTarget: EventTarget?
}

external interface KeyboardEventInit : EventModifierInit {
    var key: String?
    var code: String?
    var location: Int?
    var repeat: Boolean?
    var isComposing: Boolean?
}

Media Types

external interface MediaStreamConstraints {
    var video: dynamic
    var audio: dynamic
}

external interface MediaTrackConstraints {
    var width: dynamic
    var height: dynamic
    var aspectRatio: dynamic
    var frameRate: dynamic
    var facingMode: dynamic
    var deviceId: dynamic
}

external interface MediaDeviceInfo {
    val deviceId: String
    val kind: MediaDeviceKind
    val label: String
    val groupId: String
}