Reuben Firmin
10/26/2023, 7:58 PMtabIndex
.
as for svg, i can make the first three properties attributes["x"], but what about path? how would i model that?unsafe {
raw(
"""<path fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"></path>"""
)
}
that's pretty unsatisfying 😞package org.example.application
import kotlinx.html.*
import kotlinx.html.attributes.Attribute
import kotlinx.html.attributes.StringAttribute
inline fun FlowContent.svg(classes: String, crossinline block : SvgTag.() -> Unit = {}) =
SvgTag(classes, consumer).visit(block)
class SvgTag(classes: String, consumer: TagConsumer<*>) : HTMLTag("svg", consumer, attributesMapOf("class", classes),
inlineTag = false, emptyTag = false) {
var fill: String
get() = stringAttr[this, "fill"]
set(newValue) {
stringAttr[this, "fill"] = newValue
}
var viewbox: String
get() = stringAttr[this, "viewbox"]
set(newValue) {
stringAttr[this, "viewbox"] = newValue
}
var xmlns: String
get() = stringAttr.get(this, "xmlns")
set(newValue) {
stringAttr[this, "xmlns"] = newValue
}
}
inline fun SvgTag.path(crossinline block : SvgPath.() -> Unit = {}) =
SvgPath(consumer).visit(block)
class SvgPath(consumer: TagConsumer<*>): HTMLTag("path", consumer, emptyMap(), inlineTag = false, emptyTag = false) {
var fillRule: String
get() = stringAttr[this, "fill-rule"]
set(newValue) {
stringAttr[this, "fill-rule"] = newValue
}
var clipRule: String
get() = stringAttr[this, "clip-rule"]
set(newValue) {
stringAttr[this, "clip-rule"] = newValue
}
var d: String
get() = stringAttr.get(this, "d")
set(newValue) {
stringAttr[this, "d"] = newValue
}
}
internal val stringAttr : Attribute<String> = StringAttribute()
Cies
10/27/2023, 11:18 AMReuben Firmin
10/27/2023, 11:18 AMCies
11/02/2023, 4:30 PM