From ba58deeaf56dd6fb69137a3591c4ef3edb91ec4f Mon Sep 17 00:00:00 2001 From: rnentjes Date: Fri, 28 Feb 2020 19:47:14 +0100 Subject: [PATCH] More properties, cleanup --- .../nl/astraeus/css/properties/Border.kt | 34 ++++++++++++ .../kotlin/nl/astraeus/css/properties/Box.kt | 39 ++++++++++++++ .../nl/astraeus/css/properties/Break.kt | 27 ++++++++++ .../nl/astraeus/css/properties/Caption.kt | 14 +++++ .../nl/astraeus/css/properties/Color.kt | 1 + .../nl/astraeus/css/properties/Image.kt | 45 ++++++++++++++++ .../kotlin/nl/astraeus/css/style/Style.kt | 54 ++++++++++++++++++- src/jvmMain/kotlin/nl/astraeus/css/Test.kt | 14 +++-- 8 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 src/commonMain/kotlin/nl/astraeus/css/properties/Box.kt create mode 100644 src/commonMain/kotlin/nl/astraeus/css/properties/Break.kt create mode 100644 src/commonMain/kotlin/nl/astraeus/css/properties/Caption.kt diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Border.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Border.kt index c9b2ec4..1b7a295 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/properties/Border.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Border.kt @@ -72,3 +72,37 @@ class BorderCollapse( fun collapse() = BorderWidth("collapse") } } + +class BorderImageWidth ( + value: String +): CssProperty(value) { + + companion object { + fun px(nr: Int) = BorderRadius("${nr}px") + fun nr(nr: Int) = Image("$nr") + fun perc(nr: Int) = BorderRadius("${nr}%") + fun perc(nr: Double) = BorderRadius("${nr}%") + fun auto() = BorderWidth("auto") + fun initial() = BorderWidth("initial") + fun inherit() = BorderWidth("inherit") + } +} + +class BorderSpacing( + value: String +): CssProperty(value) { + + 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") + } +} diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Box.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Box.kt new file mode 100644 index 0000000..a458e0e --- /dev/null +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Box.kt @@ -0,0 +1,39 @@ +package nl.astraeus.css.properties + +class BoxDecorationBreak( + value: String +): CssProperty(value) { + + companion object { + fun slice() = BorderWidth("slice") + fun clone() = BorderWidth("clone") + fun initial() = BorderWidth("initial") + fun inherit() = BorderWidth("inherit") + fun unset() = BorderWidth("unset") + } +} + +class BoxShadow( + value: String +): CssProperty(value) { + + companion object { + fun none() = BoxShadow("none") + fun text(txt: String) = BoxShadow(txt) + fun inset() = BoxShadow("inset") + fun initial() = BoxShadow("initial") + fun inherit() = BoxShadow("inherit") + } +} + +class BoxSizing( + value: String +): CssProperty(value) { + + companion object { + fun contextBox() = BoxSizing("content-box") + fun borderBox() = BoxSizing("border-box") + fun initial() = BoxShadow("initial") + fun inherit() = BoxShadow("inherit") + } +} diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Break.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Break.kt new file mode 100644 index 0000000..172420d --- /dev/null +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Break.kt @@ -0,0 +1,27 @@ +package nl.astraeus.css.properties + + +class Break( + value: String +): CssProperty(value) { + + companion object { + fun auto() = Break("auto") + fun all() = Break("all") + fun always() = Break("always") + fun avoid() = Break("avoid") + fun avoidColumn() = Break("avoid-column") + fun avoidPage() = Break("avoid-page") + fun avoidRegion() = Break("avoid-region") + fun column() = Break("column") + fun left() = Break("left") + fun page() = Break("page") + fun recto() = Break("recto") + fun region() = Break("region") + fun right() = Break("right") + fun verso() = Break("verso") + fun initial() = Break("initial") + fun inherit() = Break("inherit") + } + +} diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Caption.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Caption.kt new file mode 100644 index 0000000..83b0c85 --- /dev/null +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Caption.kt @@ -0,0 +1,14 @@ +package nl.astraeus.css.properties + +class CaptionSide( + value: String +): CssProperty(value) { + + companion object { + fun top() = BoxSizing("top") + fun bottom() = BoxSizing("bottom") + fun initial() = BoxShadow("initial") + fun inherit() = BoxShadow("inherit") + } + +} diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Color.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Color.kt index 0ae5869..7cbb5e9 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/properties/Color.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Color.kt @@ -5,6 +5,7 @@ class Color( ) : CssProperty(value) { companion object { + fun auto() = Color("auto") fun transparant() = Color("transparant") fun initial() = Color("initial") fun inherit() = Color("inherit") diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Image.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Image.kt index 3aaec55..a3b6c4d 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/properties/Image.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Image.kt @@ -11,3 +11,48 @@ class Image( fun inherit() = Image("inherit") } } + +class ImageRepeat( + value: String +) : CssProperty(value) { + + companion object { + fun stretch(url: String) = Image("stretch") + fun repeat() = Image("repeat") + fun round() = Image("round") + fun initial() = Image("initial") + fun inherit() = Image("inherit") + } + +} + +class ImageSlice( + value: String +) : CssProperty(value) { + + companion object { + fun nr(nr: Int) = Image("$nr") + fun perc(perc: Int) = Image("$perc%") + fun perc(perc: Double) = Image("$perc%") + fun stretch(url: String) = Image("stretch") + fun repeat() = Image("repeat") + fun fill() = Image("fill") + fun initial() = Image("initial") + fun inherit() = Image("inherit") + } + +} + +class ImageSource( + value: String +) : CssProperty(value) { + + companion object { + fun none() = ImageSource("none") + fun text(txt: String) = ImageSource(txt) + fun image(url: String) = ImageSource("'$url'") + fun initial() = ImageSource("initial") + fun inherit() = ImageSource("inherit") + } + +} diff --git a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt index 7917894..da17f92 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt @@ -44,13 +44,37 @@ open class Style( var borderColor: List? = null, var borderImage: TextProperty? = null, var borderImageOutset: Length? = null, + var borderImageRepeat: List? = null, + var borderImageSlice: List? = null, + var borderImageSource: List? = null, + var borderImageWidth: List? = null, var borderLeft: TextProperty? = null, var borderLeftColor: Color? = null, + var borderLeftStyle: BorderStyle? = null, + var borderLeftWidth: BorderWidth? = null, var borderRadius: List? = null, var borderRight: TextProperty? = null, var borderRightColor: Color? = null, + var borderRightStyle: BorderStyle? = null, + var borderRightWidth: BorderWidth? = null, + var borderSpacing: List? = null, + var borderStyle: List? = null, var borderTop: TextProperty? = null, var borderTopColor: Color? = null, + var borderTopLeftRadius: BorderRadius? = null, + var borderTopRightRadius: BorderRadius? = null, + var borderTopStyle: BorderStyle? = null, + var borderTopWidth: BorderWidth? = null, + var bottom: Measurement? = null, + var boxDecorationBreak: BoxDecorationBreak? = null, + var boxShadow: BoxShadow? = null, + var boxSizing: BoxSizing? = null, + var breakAfter: Break? = null, + var breakBefore: Break? = null, + var breakInside: Break? = null, + var captionSide: CaptionSide? = null, + var caretColor: Color? = null, + //var charset: TextProperty? = null, var color: Color? = null, var fontFamily: TextProperty? = null, var fontSize: FontSize? = null, @@ -68,7 +92,11 @@ open class Style( MaxCountValidator(4), InitialInheritSingleValue() ), - "animation-timing-function" to listOf(MaxCountValidator(4)) + "animation-timing-function" to listOf(MaxCountValidator(4)), + "border-image-repeat" to listOf(MaxCountValidator(2)), + "border-image-slice" to listOf(MaxCountValidator(4)), + "border-spacing" to listOf(MaxCountValidator(4)), + "border-style" to listOf(MaxCountValidator(4)) ) fun getMapping(): Map = mapOf( @@ -108,13 +136,37 @@ open class Style( "border-color" to borderColor, "border-image" to borderImage, "border-image-outset" to borderImageOutset, + "border-image-repeat" to borderImageRepeat, + "border-image-slice" to borderImageSlice, + "border-image-source" to borderImageSource, + "border-image-width" to borderImageWidth, "border-left" to borderLeft, "border-left-color" to borderLeftColor, + "border-left-style" to borderLeftStyle, + "border-left-width" to borderLeftWidth, "border-radius" to borderRadius, "border-right" to borderRight, "border-right-color" to borderRightColor, + "border-right-style" to borderRightStyle, + "border-right-width" to borderRightWidth, + "border-spacing" to borderSpacing, + "border-style" to borderStyle, "border-top" to borderTop, "border-top-color" to borderTopColor, + "border-top-left-radius" to borderTopLeftRadius, + "border-top-right-radius" to borderTopRightRadius, + "border-top-style" to borderTopStyle, + "border-top-width" to borderTopWidth, + "bottom" to bottom, + "box-decoration-break" to boxDecorationBreak, + "box-shadow" to boxShadow, + "box-sizing" to boxSizing, + "break-after" to breakAfter, + "break-before" to breakBefore, + "break-inside" to breakInside, + "caption-side" to captionSide, + "caret-color" to caretColor, + //"@charset" to charset, "color" to color, "font-family" to fontFamily, "font-size" to fontSize, diff --git a/src/jvmMain/kotlin/nl/astraeus/css/Test.kt b/src/jvmMain/kotlin/nl/astraeus/css/Test.kt index 7155406..8790ec8 100644 --- a/src/jvmMain/kotlin/nl/astraeus/css/Test.kt +++ b/src/jvmMain/kotlin/nl/astraeus/css/Test.kt @@ -85,10 +85,18 @@ fun main() { css("div") { color = Color.hex("1b1b1b1") alignContent = flexStart() - animationName = listOf(text("foo"), text("bar")) + animationName = listOf( + text("foo"), + text("bar") + ) animationIterationCount = listOf( - Count.count(3), Count.infinite()) - animationTimingFunction = listOf(AnimationTimingFunction.cubicBezier(0.1, 0.2, 0.3, 0.4), AnimationTimingFunction.easeInOut()) + Count.count(3), + Count.infinite() + ) + animationTimingFunction = listOf( + AnimationTimingFunction.cubicBezier(0.1, 0.2, 0.3, 0.4), + AnimationTimingFunction.easeInOut() + ) borderRadius = listOf( BorderRadius.px(4), BorderRadius.px(5),