Move stuff in base

This commit is contained in:
2024-08-09 19:54:36 +02:00
parent 8d529b0a45
commit 40ba59e7bd
27 changed files with 1595 additions and 36 deletions

View File

@@ -0,0 +1,79 @@
package nl.astraeus.vst.ui.css
import nl.astraeus.css.style.DescriptionProvider
import nl.astraeus.css.style.cls
private val CAPITAL_LETTER = Regex("[A-Z]")
fun String.hyphenize(): String {
var result = replace(CAPITAL_LETTER) {
"-${it.value.lowercase()}"
}
if (result.startsWith('-')) {
result = result.substring(1)
}
return result
}
private var nextCssId = 1
object CssSettings {
var preFix = "css"
var shortId = false
var minified = false
}
private fun nextShortId(): String {
var id = nextCssId++
val result = StringBuilder()
while (id > 0) {
val ch = ((id % 26) + 'a'.code).toChar()
result.append(ch)
id /= 26
}
return result.toString()
}
interface CssName : DescriptionProvider {
val name: String
get() = if (CssSettings.shortId) {
nextShortId()
} else {
"${CssSettings.preFix}-${this::class.simpleName?.hyphenize() ?: this::class}"
}
fun cls(): DescriptionProvider = cls(this)
fun cssName(): String = "${this::class.simpleName?.hyphenize() ?: this::class}"
override fun description() = name
}
open class CssId(name: String) : DescriptionProvider {
val name: String = if (CssSettings.shortId) {
nextShortId()
} else {
"daw-$name-css"
}
override fun description() = name
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is CssId) return false
if (name != other.name) return false
return true
}
override fun hashCode(): Int {
return name.hashCode()
}
}