All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.nacular.doodle.dom.impl.HtmlFactoryImpl.kt Maven / Gradle / Ivy

There is a newer version: 0.10.2
Show newest version
package io.nacular.doodle.dom.impl

import io.nacular.doodle.dom.Document
import io.nacular.doodle.dom.HTMLButtonElement
import io.nacular.doodle.dom.HTMLElement
import io.nacular.doodle.dom.HTMLImageElement
import io.nacular.doodle.dom.HTMLInputElement
import io.nacular.doodle.dom.HtmlFactory

internal class HtmlFactoryImpl(override val root: HTMLElement, private val document: Document): HtmlFactory {
    override fun  create() = create("DIV") as T

    @Suppress("UNCHECKED_CAST")
    override fun  create(tag: String) = document.createElement(tag) as T

    override fun createText(text: String) = document.createTextNode(text)

    override fun createImage(source: String) = create("IMG").apply { src = source; draggable = false }

    override fun createOrUse(tag: String, possible: HTMLElement?): HTMLElement = when {
        possible == null || possible.parentNode != null && !possible.nodeName.equals(tag, ignoreCase = true) -> create(tag)
        else -> possible
    }

    override fun createInput (): HTMLInputElement = create("INPUT" )
    override fun createButton(): HTMLButtonElement = create("BUTTON")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy