Validation changes, more properties, cleanup
This commit is contained in:
@@ -69,7 +69,7 @@ class AnimationTimingFunction(
|
||||
n2: Double,
|
||||
n3: Double,
|
||||
n4: Double
|
||||
) = AnimationTimingFunction("cubic-bezier($n1, $n2, $n3, $n4)")
|
||||
) = AnimationTimingFunction("cubic-bezier($n1,$n2,$n3,$n4)")
|
||||
fun initial() = AnimationTimingFunction("initial")
|
||||
fun inherit() = AnimationTimingFunction("inherit")
|
||||
|
||||
|
||||
@@ -31,50 +31,10 @@ class BackgroundBlendMode(
|
||||
}
|
||||
}
|
||||
|
||||
class BackgroundClip(
|
||||
value: String
|
||||
) : CssProperty(value) {
|
||||
|
||||
companion object {
|
||||
fun borderBox() = BackgroundClip("border-box")
|
||||
fun paddingBox() = BackgroundClip("padding-box")
|
||||
fun contentBox() = BackgroundClip("content-box")
|
||||
fun initial() = BackgroundClip("initial")
|
||||
fun inherit() = BackgroundClip("inherit")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class BackgroundOrigin(
|
||||
value: String
|
||||
) : CssProperty(value) {
|
||||
|
||||
companion object {
|
||||
fun borderBox() = BackgroundOrigin("border-box")
|
||||
fun paddingBox() = BackgroundOrigin("padding-box")
|
||||
fun contentBox() = BackgroundOrigin("content-box")
|
||||
fun initial() = BackgroundOrigin("initial")
|
||||
fun inherit() = BackgroundOrigin("inherit")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class BackgroundPosition(
|
||||
value: String
|
||||
) : CssProperty(value) {
|
||||
|
||||
override fun validateMultiple(props: List<*>) {
|
||||
for (prop in props) {
|
||||
if (prop is CssProperty) {
|
||||
if (prop.css() == "initial" || prop.css() == "inherit") {
|
||||
check(props.size == 1) {
|
||||
"'background-position' can only have single value when 'initial' or 'inherit'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun left() = BackgroundPosition("left")
|
||||
fun center() = BackgroundPosition("center")
|
||||
@@ -106,12 +66,6 @@ class BackgroundSize(
|
||||
value: String
|
||||
) : CssProperty(value) {
|
||||
|
||||
override fun validateMultiple(props: List<*>) {
|
||||
check(props.size <= 2) {
|
||||
"'background-size' can not have more than 2 values"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun px(px: Int) = BackgroundSize("${px}px")
|
||||
fun perc(pc: Double) = BackgroundSize("${pc}%")
|
||||
|
||||
@@ -4,21 +4,6 @@ class BorderRadius(
|
||||
value: String
|
||||
): CssProperty(value) {
|
||||
|
||||
override fun validateMultiple(props: List<*>) {
|
||||
check(props.size <= 2) {
|
||||
"'background-size' can not have more than 2 values"
|
||||
}
|
||||
for (prop in props) {
|
||||
if (prop is CssProperty) {
|
||||
if (prop.css() == "initial" || prop.css() == "inherit") {
|
||||
check(props.size == 1) {
|
||||
"'border-radius' can only have single value when 'initial' or 'inherit'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun px(nr: Int) = BorderRadius("${nr}px")
|
||||
fun em(nr: Int) = BorderRadius("${nr}em")
|
||||
@@ -77,3 +62,13 @@ class BorderWidth(
|
||||
fun inherit() = BorderWidth("inherit")
|
||||
}
|
||||
}
|
||||
|
||||
class BorderCollapse(
|
||||
value: String
|
||||
): CssProperty(value) {
|
||||
|
||||
companion object {
|
||||
fun separate() = BorderWidth("separate")
|
||||
fun collapse() = BorderWidth("collapse")
|
||||
}
|
||||
}
|
||||
|
||||
36
src/commonMain/kotlin/nl/astraeus/css/properties/Common.kt
Normal file
36
src/commonMain/kotlin/nl/astraeus/css/properties/Common.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package nl.astraeus.css.properties
|
||||
|
||||
class Length(
|
||||
value: String
|
||||
): CssProperty(value) {
|
||||
|
||||
companion object {
|
||||
fun px(nr: Int) = Length("${nr}px")
|
||||
fun em(nr: Int) = Length("${nr}em")
|
||||
fun em(nr: Double) = Length("${nr}em")
|
||||
fun perc(nr: Int) = Length("${nr}%")
|
||||
fun perc(nr: Double) = Length("${nr}%")
|
||||
fun pc(nr: Int) = Length("${nr}pc")
|
||||
fun pc(nr: Double) = Length("${nr}pc")
|
||||
fun cm(nr: Int) = Length("${nr}cm")
|
||||
fun cm(nr: Double) = Length("${nr}cm")
|
||||
fun initial() = Length("initial")
|
||||
fun inherit() = Length("inherit")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ClipOrigin(
|
||||
value: String
|
||||
) : CssProperty(value) {
|
||||
|
||||
companion object {
|
||||
fun borderBox() = ClipOrigin("border-box")
|
||||
fun paddingBox() = ClipOrigin("padding-box")
|
||||
fun contentBox() = ClipOrigin("content-box")
|
||||
fun initial() = ClipOrigin("initial")
|
||||
fun inherit() = ClipOrigin("inherit")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@ package nl.astraeus.css.properties
|
||||
open class CssProperty(
|
||||
val value: String
|
||||
) {
|
||||
|
||||
fun css(): String = value
|
||||
|
||||
open fun validate() {}
|
||||
|
||||
open fun validateMultiple(props: List<*>) {}
|
||||
}
|
||||
|
||||
fun text(value: String) = TextProperty(value)
|
||||
|
||||
Reference in New Issue
Block a user