More properties and cleanup

This commit is contained in:
2020-02-24 09:47:14 +01:00
parent 1c3ac8f0d0
commit 083f234d82
31 changed files with 827 additions and 413 deletions

View File

@@ -0,0 +1,17 @@
package nl.astraeus.css.properties
class AlignContent(
value: String
) : CssProperty(value) {
companion object {
fun stretch() = AlignContent("stretch")
fun center() = AlignContent("center")
fun flexStart() = AlignContent("flex-start")
fun flexEnd() = AlignContent("flex-end")
fun spaceBetween() = AlignContent("space-between")
fun spaceAround() = AlignContent("space-around")
fun initial() = AlignContent("initial")
fun inherit() = AlignContent("inherit")
}
}

View File

@@ -0,0 +1,17 @@
package nl.astraeus.css.properties
class AlignItems(
value: String
) : CssProperty(value) {
companion object {
fun stretch() = AlignItems("stretch")
fun center() = AlignItems("center")
fun flexStart() = AlignItems("flex-start")
fun flexEnd() = AlignItems("flex-end")
fun baseline() = AlignItems("baseline")
fun initial() = AlignItems("initial")
fun inherit() = AlignItems("inherit")
}
}

View File

@@ -0,0 +1,17 @@
package nl.astraeus.css.properties
class AlignSelf(
value: String
) : CssProperty(value) {
companion object {
fun auto() = AlignSelf("auto")
fun stretch() = AlignSelf("stretch")
fun center() = AlignSelf("center")
fun flexStart() = AlignSelf("flex-start")
fun flexEnd() = AlignSelf("flex-end")
fun baseline() = AlignSelf("baseline")
fun initial() = AlignSelf("initial")
fun inherit() = AlignSelf("inherit")
}
}

View File

@@ -0,0 +1,14 @@
package nl.astraeus.css.properties
class All(
value: String
) : CssProperty(value) {
companion object {
fun initial() = All("initial")
fun inherit() = All("inherit")
fun unset() = All("unset")
fun revert() = All("revert")
}
}

View File

@@ -0,0 +1,77 @@
package nl.astraeus.css.properties
class AnimationDirection(
value: String
) : CssProperty(value) {
companion object {
fun normal() = AnimationDirection("normal")
fun reverse() = AnimationDirection("reverse")
fun alternate() = AnimationDirection("alternate")
fun alternateReverse() = AnimationDirection("alternate-reverse")
fun initial() = AnimationDirection("initial")
fun inherit() = AnimationDirection("inherit")
}
}
class AnimationFillMode(
value: String
) : CssProperty(value) {
companion object {
fun none() = AnimationFillMode("none")
fun forwards() = AnimationFillMode("forwards")
fun backwards() = AnimationFillMode("backwards")
fun both() = AnimationFillMode("both")
fun initial() = AnimationFillMode("initial")
fun inherit() = AnimationFillMode("inherit")
}
}
class AnimationFrame(
value: String = ""
): CssProperty(value) {
companion object {
fun name(name: String): AnimationFrame = AnimationFrame(name)
fun none(): AnimationFrame = AnimationFrame("none")
fun initial(): AnimationFrame = AnimationFrame("initial")
fun inherit(): AnimationFrame = AnimationFrame("inherit")
}
}
class AnimationPlayState(
value: String
) : CssProperty(value) {
companion object {
fun name(name: String) = AnimationPlayState(name)
fun paused() = AnimationPlayState("paused")
fun running() = AnimationPlayState("running")
fun initial() = AnimationPlayState("initial")
fun inherit() = AnimationPlayState("inherit")
}
}
class AnimationTimingFunction(
value: String = ""
) : CssProperty(value) {
companion object {
fun linear() = AnimationTimingFunction("linear")
fun ease() = AnimationTimingFunction("ease")
fun easeIn() = AnimationTimingFunction("ease-in")
fun easeOut() = AnimationTimingFunction("ease-out")
fun easeInOut() = AnimationTimingFunction("ease-in-out")
fun cubicBezier(
n1: Double,
n2: Double,
n3: Double,
n4: Double
) = AnimationTimingFunction("cubic-bezier($n1, $n2, $n3, $n4)")
fun initial() = AnimationTimingFunction("initial")
fun inherit() = AnimationTimingFunction("inherit")
}
}

View File

@@ -0,0 +1,13 @@
package nl.astraeus.css.properties
class BackfaceVisibility(
value: String
) : CssProperty(value) {
companion object {
fun visible() = BackfaceVisibility("visible")
fun hidden() = BackfaceVisibility("hidden")
fun initial() = BackfaceVisibility("initial")
fun inherit() = BackfaceVisibility("inherit")
}
}

View File

@@ -0,0 +1,125 @@
package nl.astraeus.css.properties
class BackgroundAttachment(
value: String
) : CssProperty(value) {
companion object {
fun scroll() = BackgroundAttachment("scroll")
fun fixed() = BackgroundAttachment("fixed")
fun local() = BackgroundAttachment("local")
fun initial() = BackgroundAttachment("initial")
fun inherit() = BackgroundAttachment("inherit")
}
}
class BackgroundBlendMode(
value: String
) : CssProperty(value) {
companion object {
fun normal() = BackgroundBlendMode("normal")
fun multiply() = BackgroundBlendMode("multiply")
fun screen() = BackgroundBlendMode("screen")
fun overlay() = BackgroundBlendMode("overlay")
fun darken() = BackgroundBlendMode("darken")
fun lighten() = BackgroundBlendMode("lighten")
fun colorDodge() = BackgroundBlendMode("color-dodge")
fun saturation() = BackgroundBlendMode("saturation")
fun color() = BackgroundBlendMode("color")
fun luminosity() = BackgroundBlendMode("luminosity")
}
}
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")
fun right() = BackgroundPosition("right")
fun initial() = BackgroundPosition("initial")
fun inherit() = BackgroundPosition("inherit")
}
}
class BackgroundRepeat(
value: String
) : CssProperty(value) {
companion object {
fun repeat() = BackgroundRepeat("repeat")
fun repeatX() = BackgroundRepeat("repeat-x")
fun repeatY() = BackgroundRepeat("repeat-y")
fun noRepeat() = BackgroundRepeat("no-repeat")
fun space() = BackgroundRepeat("space")
fun round() = BackgroundRepeat("round")
fun initial() = BackgroundRepeat("initial")
fun inherit() = BackgroundRepeat("inherit")
fun unset() = BackgroundRepeat("unset")
}
}
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}%")
fun auto() = BackgroundSize("auto")
fun cover() = BackgroundSize("cover")
fun contain() = BackgroundSize("contain")
fun initial() = BackgroundSize("initial")
fun inherit() = BackgroundSize("inherit")
}
}

View File

@@ -0,0 +1,79 @@
package nl.astraeus.css.properties
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")
fun em(nr: Double) = BorderRadius("${nr}em")
fun perc(nr: Int) = BorderRadius("${nr}%")
fun perc(nr: Double) = BorderRadius("${nr}%")
fun pc(nr: Int) = BorderRadius("${nr}pc")
fun pc(nr: Double) = BorderRadius("${nr}pc")
fun cm(nr: Int) = BorderRadius("${nr}cm")
fun cm(nr: Double) = BorderRadius("${nr}cm")
fun initial() = BorderRadius("initial")
fun inherit() = BorderRadius("inherit")
}
}
class BorderStyle(
value: String
): CssProperty(value) {
companion object {
fun none() = BorderStyle("none")
fun hidden() = BorderStyle("hidden")
fun dotted() = BorderStyle("dotted")
fun dashed() = BorderStyle("dashed")
fun solid() = BorderStyle("solid")
fun double() = BorderStyle("double")
fun groove() = BorderStyle("groove")
fun ridge() = BorderStyle("ridge")
fun inset() = BorderStyle("inset")
fun outset() = BorderStyle("outset")
fun initial() = BorderStyle("initial")
fun inherit() = BorderStyle("inherit")
}
}
class BorderWidth(
value: String
): CssProperty(value) {
companion object {
fun thin() = BorderWidth("thin")
fun medium() = BorderWidth("medium")
fun thick() = BorderWidth("thick")
fun px(nr: Int) = BorderRadius("${nr}px")
fun em(nr: Int) = BorderRadius("${nr}em")
fun em(nr: Double) = BorderRadius("${nr}em")
fun perc(nr: Int) = BorderRadius("${nr}%")
fun perc(nr: Double) = BorderRadius("${nr}%")
fun pc(nr: Int) = BorderRadius("${nr}pc")
fun pc(nr: Double) = BorderRadius("${nr}pc")
fun cm(nr: Int) = BorderRadius("${nr}cm")
fun cm(nr: Double) = BorderRadius("${nr}cm")
fun initial() = BorderWidth("initial")
fun inherit() = BorderWidth("inherit")
}
}

View File

@@ -0,0 +1,35 @@
package nl.astraeus.css.properties
class Color(
value: String
) : CssProperty(value) {
companion object {
fun transparant() = Color("transparant")
fun initial() = Color("initial")
fun inherit() = Color("inherit")
fun hex(hex: String) = Color("#$hex")
fun rgb(
red: Int,
green: Int,
blue: Int
) = Color("rgb($red, $green, $blue)")
fun rgba(
red: Int,
green: Int,
blue: Int,
alpha: Double
) = Color("rgba($red, $green, $blue, $alpha)")
fun hsl(
hue: Int,
saturation: Int,
lightness: Int
) = Color("hsl($hue, $saturation, $lightness)")
fun hsla(
hue: Int,
saturation: Int,
lightness: Int,
alpha: Double
) = Color("hsla($hue, $saturation, $lightness, $alpha)")
}
}

View File

@@ -0,0 +1,17 @@
package nl.astraeus.css.properties
class Count(
value: String
) : CssProperty(value) {
companion object {
fun count(number: Int): Count =
Count("$number")
fun infinite(): Count =
Count("infinite")
fun initial(): Count =
Count("initial")
fun inherit(): Count =
Count("inherit")
}
}

View File

@@ -0,0 +1,17 @@
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)
class TextProperty(
value: String
): CssProperty(value)

View File

@@ -0,0 +1,12 @@
package nl.astraeus.css.properties
class DelayDuration(
value: String
) : CssProperty(value) {
companion object {
fun seconds(seconds: Int) = DelayDuration("${seconds}s")
fun initial() = DelayDuration("initial")
fun inherit() = DelayDuration("inherit")
}
}

View File

@@ -0,0 +1,13 @@
package nl.astraeus.css.properties
class Image(
value: String
) : CssProperty(value) {
companion object {
fun url(url: String) = Image("url($url)")
fun none() = Image("none")
fun initial() = Image("initial")
fun inherit() = Image("inherit")
}
}

View File

@@ -0,0 +1,49 @@
package nl.astraeus.css.properties
open class Measurement(
value: String
) : CssProperty(value) {
companion object {
fun auto() = Measurement("auto")
fun initial() = Measurement("initial")
fun inherit() = Measurement("inherit")
fun px(nr: Int) = Measurement("${nr}px")
fun em(nr: Int) = Measurement("${nr}em")
fun em(nr: Double) = Measurement("${nr}em")
fun perc(nr: Int) = Measurement("${nr}%")
fun perc(nr: Double) = Measurement("${nr}%")
fun pc(nr: Int) = Measurement("${nr}pc")
fun pc(nr: Double) = Measurement("${nr}pc")
fun cm(nr: Int) = Measurement("${nr}cm")
fun cm(nr: Double) = Measurement("${nr}cm")
}
}
class FontSize(
value: String
) : CssProperty(value) {
companion object {
fun xxSmall() = FontSize("xx-small")
fun xSmall() = FontSize("x-small")
fun small() = FontSize("small")
fun medium() = FontSize("medium")
fun large() = FontSize("large")
fun xLarge() = FontSize("x-large")
fun xxLarge() = FontSize("xx-large")
fun smaller() = FontSize("smaller")
fun larger() = FontSize("larger")
fun initial() = FontSize("initial")
fun inherit() = FontSize("inherit")
fun px(nr: Int) = FontSize("${nr}px")
fun em(nr: Int) = FontSize("${nr}em")
fun em(nr: Double) = FontSize("${nr}em")
fun perc(nr: Int) = FontSize("${nr}%")
fun perc(nr: Double) = FontSize("${nr}%")
fun pc(nr: Int) = FontSize("${nr}pc")
fun pc(nr: Double) = FontSize("${nr}pc")
fun cm(nr: Int) = FontSize("${nr}cm")
fun cm(nr: Double) = FontSize("${nr}cm")
}
}