Add Color conversion options (add hsla -> hex)

This commit is contained in:
2021-07-08 16:15:42 +02:00
parent 9e43f5b746
commit adec3b21b0
4 changed files with 10 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = "nl.astraeus"
version = "0.4.25"
version = "0.4.27"
repositories {
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }

View File

@@ -63,7 +63,11 @@ class Color(value: String) : CssProperty(value) {
}
}
fun toHex(): String = toRGBA().asHex()
fun toHex(): String = if (isHsla() || isHsl()) {
fromHSLANotation().asRGBA().asHex()
} else {
toRGBA().asHex()
}
fun isHsla(): Boolean {
val v = rgb ?: value

View File

@@ -237,6 +237,7 @@ class TestCssBuilder {
assertEquals(0.5, hsla.getAlpha())
assertEquals(0.4, hexa.getAlpha())
assertEquals("646e78", rgba.toHex())
assertEquals("bf4240", hsla.toHex())
}
}

View File

@@ -1,11 +1,6 @@
package nl.astraeus.css
import nl.astraeus.css.properties.AlignContent
import nl.astraeus.css.properties.DelayDuration
import nl.astraeus.css.properties.TimingFunction
import nl.astraeus.css.properties.hex
import nl.astraeus.css.properties.hsla
/*
fun main() {
val sd = style {
select("#pipo") {
@@ -31,3 +26,5 @@ fun main() {
//println(sd.generateCss())
}
*/