From 9f3be7cadd6faaa7a8b6c0fe757f29a0e5623d47 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Sat, 23 Oct 2021 11:56:18 +0200 Subject: [PATCH] v. 1.0.3, add inline style, fix TemplateRowColumn value types Took 27 minutes --- build.gradle.kts | 8 +- .../kotlin/nl/astraeus/css/properties/Grid.kt | 14 +- .../kotlin/nl/astraeus/css/style/Style.kt | 242 +++++++++--------- 3 files changed, 136 insertions(+), 128 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 39722e7..69fbd77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "nl.astraeus" -version = "1.0.2" +version = "1.0.3" repositories { mavenCentral() @@ -52,9 +52,9 @@ testlogger { showStandardStreams = true } -extra["PUBLISH_GROUP_ID"] = "nl.astraeus" -extra["PUBLISH_VERSION"] = "1.0.2" -extra["PUBLISH_ARTIFACT_ID"] = "kotlin-css-generator" +extra["PUBLISH_GROUP_ID"] = group +extra["PUBLISH_VERSION"] = version +extra["PUBLISH_ARTIFACT_ID"] = name // Stub secrets to let the project sync and build without the publication values set up val signingKeyId: String by project diff --git a/src/commonMain/kotlin/nl/astraeus/css/properties/Grid.kt b/src/commonMain/kotlin/nl/astraeus/css/properties/Grid.kt index 67880ab..b1398e0 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/properties/Grid.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/properties/Grid.kt @@ -58,14 +58,14 @@ class TemplateRowColumn( ) : CssProperty(value) { companion object { - val none = GridValue("none") - val auto = GridValue("auto") - val maxContent = GridValue("max-content") - val minContent = GridValue("min-content") - val initial = GridValue("initial") - val inherit = GridValue("inherit") + val none = TemplateRowColumn("none") + val auto = TemplateRowColumn("auto") + val maxContent = TemplateRowColumn("max-content") + val minContent = TemplateRowColumn("min-content") + val initial = TemplateRowColumn("initial") + val inherit = TemplateRowColumn("inherit") - fun length(length: Measurement) = GridValue(length.value) + fun length(length: Measurement) = TemplateRowColumn(length.value) } } diff --git a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt index e1a804e..a373e5a 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt @@ -419,9 +419,7 @@ fun attrStartsWith(name: DescriptionProvider, value: String): DescriptionProvide ValueDescriptionProvider("[${name.description()}^=$value]") @CssTagMarker -open class Style : CssGenerator() { - var fontFace: FontFace? = null - var keyFrames: MutableMap = mutableMapOf() +open class InlineStyle : CssGenerator() { private val validators = mapOf>( "background-position" to listOf(InitialInheritSingleValue()), @@ -446,82 +444,6 @@ open class Style : CssGenerator() { definitions[selector]?.add(style) } - /** - * like the scss & - * @param selector blabla - */ - fun and(vararg selectors: DescriptionProvider, style: Css) { - for (selector in selectors) { - addStyle(selector.description(), style) - } - } - - fun and(vararg selectors: String, style: Css) { - for (selector in selectors) { - addStyle(selector, style) - } - } - - fun select(vararg selectors: DescriptionProvider, style: Css) { - for (selector in selectors) { - addStyle(" ${selector.description()}", style) - } - } - - fun select(vararg selectors: String, style: Css) { - for (selector in selectors) { - addStyle(" $selector", style) - } - } - - fun descendant(vararg descNames: DescriptionProvider, style: Css) { - for (descName in descNames) { - addStyle(" ${descName.description()}", style) - } - } - - fun descendant(vararg descNames: String, style: Css) { - for (descName in descNames) { - addStyle(" $descName", style) - } - } - - fun child(vararg childNames: DescriptionProvider, style: Css) { - for (childName in childNames) { - addStyle(" > ${childName.description()}", style) - } - } - - fun child(vararg childNames: String, style: Css) { - for (childName in childNames) { - addStyle(" > $childName", style) - } - } - - fun sibling(vararg childNames: DescriptionProvider, style: Css) { - for (childName in childNames) { - addStyle(" ~ ${childName.description()}", style) - } - } - - fun sibling(vararg childNames: String, style: Css) { - for (childName in childNames) { - addStyle(" ~ $childName", style) - } - } - - fun adjSibling(vararg childNames: DescriptionProvider, style: Css) { - for (childName in childNames) { - addStyle(" + ${childName.description()}", style) - } - } - - fun adjSibling(vararg childNames: String, style: Css) { - for (childName in childNames) { - addStyle(" + $childName", style) - } - } - fun active(style: Css) { addStyle(":active", style) } @@ -538,30 +460,10 @@ open class Style : CssGenerator() { addStyle(":hover", style) } - fun firstChild(style: Css) { - addStyle(":first-child", style) - } - - fun lastChild(style: Css) { - addStyle(":last-child", style) - } - - fun pseudoElement(selector: DescriptionProvider, style: Css) { - addStyle(":${selector.description()}", style) - } - - fun pseudoChild(selector: DescriptionProvider, style: Css) { - addStyle("::${selector.description()}", style) - } - fun visited(style: Css) { addStyle(":visited", style) } - fun not(selector: DescriptionProvider, style: Css) { - addStyle(":not(${selector.description()})", style) - } - fun plain(name: String, value: String) { props[name] = prp(value) } @@ -1024,12 +926,6 @@ open class Style : CssGenerator() { props["font"] = prp(font) } - fun fontFace(face: FontFace.() -> Unit) { - fontFace = FontFace() - - face.invoke(fontFace!!) - } - fun fontFamily(font: String) { props["font-family"] = prp(font) } @@ -1185,10 +1081,6 @@ open class Style : CssGenerator() { props["hyphens"] = prp(hyphens) } - fun import(style: Css) { - style(this) - } - fun isolation(isolation: Isolation) { props["isolation"] = prp(isolation) } @@ -1197,14 +1089,6 @@ open class Style : CssGenerator() { props["justify-content"] = prp(content) } - fun keyFrames(animationName: String, frames: KeyFrames.() -> Unit) { - val frameCss = KeyFrames() - - frames.invoke(frameCss) - - keyFrames[animationName] = frameCss - } - fun left(left: Measurement) { props["left"] = prp(left) } @@ -1625,6 +1509,130 @@ open class Style : CssGenerator() { } } +@CssTagMarker +open class Style : InlineStyle() { + var fontFace: FontFace? = null + var keyFrames: MutableMap = mutableMapOf() + + private fun addStyle(selector: String, style: Css) { + definitions[selector] = definitions[selector] ?: mutableListOf() + definitions[selector]?.add(style) + } + + /** + * like the scss & + */ + fun and(vararg selectors: DescriptionProvider, style: Css) { + for (selector in selectors) { + addStyle(selector.description(), style) + } + } + + fun and(vararg selectors: String, style: Css) { + for (selector in selectors) { + addStyle(selector, style) + } + } + + fun select(vararg selectors: DescriptionProvider, style: Css) { + for (selector in selectors) { + addStyle(" ${selector.description()}", style) + } + } + + fun select(vararg selectors: String, style: Css) { + for (selector in selectors) { + addStyle(" $selector", style) + } + } + + fun descendant(vararg descNames: DescriptionProvider, style: Css) { + for (descName in descNames) { + addStyle(" ${descName.description()}", style) + } + } + + fun descendant(vararg descNames: String, style: Css) { + for (descName in descNames) { + addStyle(" $descName", style) + } + } + + fun child(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" > ${childName.description()}", style) + } + } + + fun child(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" > $childName", style) + } + } + + fun sibling(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" ~ ${childName.description()}", style) + } + } + + fun sibling(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" ~ $childName", style) + } + } + + fun adjSibling(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" + ${childName.description()}", style) + } + } + + fun adjSibling(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" + $childName", style) + } + } + + fun firstChild(style: Css) { + addStyle(":first-child", style) + } + + fun lastChild(style: Css) { + addStyle(":last-child", style) + } + + fun pseudoElement(selector: DescriptionProvider, style: Css) { + addStyle(":${selector.description()}", style) + } + + fun pseudoChild(selector: DescriptionProvider, style: Css) { + addStyle("::${selector.description()}", style) + } + + fun not(selector: DescriptionProvider, style: Css) { + addStyle(":not(${selector.description()})", style) + } + + fun fontFace(face: FontFace.() -> Unit) { + fontFace = FontFace() + + face.invoke(fontFace!!) + } + + fun import(style: Css) { + style(this) + } + + fun keyFrames(animationName: String, frames: KeyFrames.() -> Unit) { + val frameCss = KeyFrames() + + frames.invoke(frameCss) + + keyFrames[animationName] = frameCss + } +} + @CssTagMarker open class ConditionalStyle : Style() { var media: MutableMap = mutableMapOf()