From 754f6f65b08c45899104fd3ba00fa9d16f605d3e Mon Sep 17 00:00:00 2001 From: Shagen Ogandzhanian Date: Mon, 7 Jun 2021 14:09:29 +0200 Subject: [PATCH] Swap CSSSizeValue and CSSUnitValue names so to be less intrusive for an outside code --- .../kotlin/com/sample/style/Stylesheet.kt | 24 +++---- .../jsMain/kotlin/com/sample/style/WtCol.kt | 4 +- .../kotlin/androidx/compose/web/css/CSS.kt | 2 +- .../androidx/compose/web/css/CSSMediaRule.kt | 8 +-- .../androidx/compose/web/css/CSSProperties.kt | 46 ++++++------- .../androidx/compose/web/css/CSSUnits.kt | 66 +++++++++---------- web/core/src/jsTest/kotlin/CSSUnitApiTests.kt | 1 - 7 files changed, 75 insertions(+), 76 deletions(-) diff --git a/web/benchmark-core/src/jsMain/kotlin/com/sample/style/Stylesheet.kt b/web/benchmark-core/src/jsMain/kotlin/com/sample/style/Stylesheet.kt index 220ec324e3..abfd7baae1 100644 --- a/web/benchmark-core/src/jsMain/kotlin/com/sample/style/Stylesheet.kt +++ b/web/benchmark-core/src/jsMain/kotlin/com/sample/style/Stylesheet.kt @@ -7,18 +7,18 @@ object AppCSSVariables : CSSVariables { val wtColorGreyLight by variable() val wtColorGreyDark by variable() - val wtOffsetTopUnit by variable() - val wtHorizontalLayoutGutter by variable() - val wtFlowUnit by variable() - - val wtHeroFontSize by variable() - val wtHeroLineHeight by variable() - val wtSubtitle2FontSize by variable() - val wtSubtitle2LineHeight by variable() - val wtH2FontSize by variable() - val wtH2LineHeight by variable() - val wtH3FontSize by variable() - val wtH3LineHeight by variable() + val wtOffsetTopUnit by variable() + val wtHorizontalLayoutGutter by variable() + val wtFlowUnit by variable() + + val wtHeroFontSize by variable() + val wtHeroLineHeight by variable() + val wtSubtitle2FontSize by variable() + val wtSubtitle2LineHeight by variable() + val wtH2FontSize by variable() + val wtH2LineHeight by variable() + val wtH3FontSize by variable() + val wtH3LineHeight by variable() val wtColCount by variable() } diff --git a/web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCol.kt b/web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCol.kt index 5f7d1f059d..ff2d88504f 100644 --- a/web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCol.kt +++ b/web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCol.kt @@ -4,7 +4,7 @@ import org.jetbrains.compose.web.css.* import org.jetbrains.compose.web.css.selectors.* fun GenericStyleSheetBuilder.mediaMaxWidth( - value: CSSSizeValue, + value: CSSUnitValue, cssSelector: CSSSelector, rulesBuild: TBuilder.() -> Unit ) { @@ -13,7 +13,7 @@ fun GenericStyleSheetBuilder.mediaMaxWidth( } } -fun CSSBuilder.forMaxWidth(value: CSSSizeValue, builder: CSSBuilder.() -> Unit) { +fun CSSBuilder.forMaxWidth(value: CSSUnitValue, builder: CSSBuilder.() -> Unit) { mediaMaxWidth(value, self, builder) } diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt index 4a732e6e41..6bd8c04d01 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt @@ -314,7 +314,7 @@ external interface StylePropertyValue fun String.asStylePropertyValue() = unsafeCast() fun Number.asStylePropertyValue() = unsafeCast() fun CSSStyleValue.asStylePropertyValue() = unsafeCast() -fun CSSSizeValue.asStylePropertyValue() = asString().asStylePropertyValue() +fun CSSUnitValue.asStylePropertyValue() = asString().asStylePropertyValue() external class StylePropertyMap : StylePropertyMapReadOnly { fun set(property: String, vararg values: StylePropertyValue) diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt index fe522867a5..efa7bf6e1f 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt @@ -124,14 +124,14 @@ fun GenericStyleSheetBuilder.not( query: CSSMediaQuery.Invertible ) = CSSMediaQuery.Not(query) -fun GenericStyleSheetBuilder.minWidth(value: CSSSizeValue) = +fun GenericStyleSheetBuilder.minWidth(value: CSSUnitValue) = CSSMediaQuery.MediaFeature("min-width", value.asStylePropertyValue()) -fun GenericStyleSheetBuilder.maxWidth(value: CSSSizeValue) = +fun GenericStyleSheetBuilder.maxWidth(value: CSSUnitValue) = CSSMediaQuery.MediaFeature("max-width", value.asStylePropertyValue()) -fun GenericStyleSheetBuilder.minHeight(value: CSSSizeValue) = +fun GenericStyleSheetBuilder.minHeight(value: CSSUnitValue) = CSSMediaQuery.MediaFeature("min-height", value.asStylePropertyValue()) -fun GenericStyleSheetBuilder.maxHeight(value: CSSSizeValue) = +fun GenericStyleSheetBuilder.maxHeight(value: CSSUnitValue) = CSSMediaQuery.MediaFeature("max-height", value.asStylePropertyValue()) diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt index fea8036d54..f56b81e62b 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt @@ -16,7 +16,7 @@ fun StyleBuilder.flexShrink(value: Number) { property("flex-shrink", value.asStylePropertyValue()) } -fun StyleBuilder.opacity(value: CSSUnitValue) { +fun StyleBuilder.opacity(value: CSSSizeValue) { property("opacity", value(value.value as Double / 100)) } @@ -193,7 +193,7 @@ class CSSBorder : CustomStyleValue { var style: StylePropertyValue? = null var color: StylePropertyValue? = null - fun width(size: CSSSizeValue) { + fun width(size: CSSUnitValue) { width = size.asStylePropertyValue() } @@ -227,7 +227,7 @@ inline fun StyleBuilder.border(crossinline borderBuild: CSSBorder.() -> Unit) { } fun StyleBuilder.border( - width: CSSSizeValue? = null, + width: CSSUnitValue? = null, style: LineStyle? = null, color: Color? = null ) { @@ -291,27 +291,27 @@ fun StyleBuilder.position(position: Position) { ) } -fun StyleBuilder.borderRadius(r: CSSSizeValue) { +fun StyleBuilder.borderRadius(r: CSSUnitValue) { property("border-radius", r.asStylePropertyValue()) } -fun StyleBuilder.borderRadius(topLeft: CSSSizeValue, bottomRight: CSSSizeValue) { +fun StyleBuilder.borderRadius(topLeft: CSSUnitValue, bottomRight: CSSUnitValue) { property("border-radius", "${topLeft.asString()} ${bottomRight.asString()}".asStylePropertyValue()) } fun StyleBuilder.borderRadius( - topLeft: CSSSizeValue, - topRightAndBottomLeft: CSSSizeValue, - bottomRight: CSSSizeValue + topLeft: CSSUnitValue, + topRightAndBottomLeft: CSSUnitValue, + bottomRight: CSSUnitValue ) { property("border-radius", "${topLeft.asString()} ${topRightAndBottomLeft.asString()} ${bottomRight.asString()}".asStylePropertyValue()) } fun StyleBuilder.borderRadius( - topLeft: CSSSizeValue, - topRight: CSSSizeValue, - bottomRight: CSSSizeValue, - bottomLeft: CSSSizeValue + topLeft: CSSUnitValue, + topRight: CSSUnitValue, + bottomRight: CSSUnitValue, + bottomLeft: CSSUnitValue ) { property( "border-radius", @@ -319,7 +319,7 @@ fun StyleBuilder.borderRadius( ) } -fun StyleBuilder.width(value: CSSSizeValue) { +fun StyleBuilder.width(value: CSSUnitValue) { property("width", value.asStylePropertyValue()) } @@ -327,7 +327,7 @@ fun StyleBuilder.width(value: CSSAutoValue) { property("width", value) } -fun StyleBuilder.height(value: CSSSizeValue) { +fun StyleBuilder.height(value: CSSUnitValue) { property("height", value.asStylePropertyValue()) } @@ -335,7 +335,7 @@ fun StyleBuilder.height(value: CSSAutoValue) { property("height", value) } -fun StyleBuilder.top(value: CSSSizeValue) { +fun StyleBuilder.top(value: CSSUnitValue) { property("top", value.asStylePropertyValue()) } @@ -343,7 +343,7 @@ fun StyleBuilder.top(value: CSSAutoValue) { property("top", value) } -fun StyleBuilder.bottom(value: CSSSizeValue) { +fun StyleBuilder.bottom(value: CSSUnitValue) { property("bottom", value.asStylePropertyValue()) } @@ -351,7 +351,7 @@ fun StyleBuilder.bottom(value: CSSAutoValue) { property("bottom", value) } -fun StyleBuilder.left(value: CSSSizeValue) { +fun StyleBuilder.left(value: CSSUnitValue) { property("left", value.asStylePropertyValue()) } @@ -359,7 +359,7 @@ fun StyleBuilder.left(value: CSSAutoValue) { property("left", value) } -fun StyleBuilder.right(value: CSSSizeValue) { +fun StyleBuilder.right(value: CSSUnitValue) { property("right", value.asStylePropertyValue()) } @@ -367,24 +367,24 @@ fun StyleBuilder.right(value: CSSAutoValue) { property("right", value) } -fun StyleBuilder.fontSize(value: CSSSizeValue) { +fun StyleBuilder.fontSize(value: CSSUnitValue) { property("font-size", value(value)) } -fun StyleBuilder.margin(value: CSSSizeValue) { +fun StyleBuilder.margin(value: CSSUnitValue) { // marign hasn't Typed OM yet property("margin", value(value.asString())) } -fun StyleBuilder.marginLeft(value: CSSSizeValue) { +fun StyleBuilder.marginLeft(value: CSSUnitValue) { property("margin-left", value(value.asString())) } -fun StyleBuilder.marginTop(value: CSSSizeValue) { +fun StyleBuilder.marginTop(value: CSSUnitValue) { property("margin-top", value(value.asString())) } -fun StyleBuilder.padding(value: CSSSizeValue) { +fun StyleBuilder.padding(value: CSSUnitValue) { // padding hasn't Typed OM yet property("padding", value(value.asString())) } diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt index 38f18359d9..c4e379cee3 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt @@ -1,6 +1,6 @@ package org.jetbrains.compose.web.css -interface CSSUnitValue : CSSNumericValue { +interface CSSSizeValue : CSSNumericValue { val value: Float val unit: T fun asString(): String = "${value}${unit.value}" @@ -9,10 +9,10 @@ interface CSSUnitValue : CSSNumericValue { private class CSSUnitValueTyped( override val value: Float, override val unit: T -) : CSSUnitValue +) : CSSSizeValue -typealias CSSSizeValue = CSSUnitValue -typealias CSSpxValue = CSSUnitValue +typealias CSSUnitValue = CSSSizeValue +typealias CSSpxValue = CSSSizeValue interface CSSUnitRel : CSSUnit interface CSSUnitAbs: CSSUnit @@ -22,7 +22,7 @@ interface CSSUnitFrequency: CSSUnit interface CSSUnitResolution: CSSUnit interface CSSUnitFlex: CSSUnit -typealias CSSAngleValue = CSSUnitValue +typealias CSSAngleValue = CSSSizeValue sealed interface CSSUnit { val value: String @@ -162,76 +162,76 @@ sealed interface CSSUnit { val Number.number - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.number) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.number) val Number.percent - get() : CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.percent) + get() : CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.percent) val Number.em - get() : CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.em) + get() : CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.em) val Number.ex - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ex) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ex) val Number.ch - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ch) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ch) val Number.cssRem - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.rem) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.rem) val Number.vw - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vw) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vw) val Number.vh - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vh) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vh) val Number.vmin - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmin) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmin) val Number.vmax - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmax) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmax) val Number.cm - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.cm) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.cm) val Number.mm - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.mm) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.mm) val Number.Q - get() : CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.q) + get() : CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.q) val Number.pt - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.pt) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.pt) val Number.pc - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.pc) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.pc) val Number.px - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.px) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.px) val Number.deg - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.deg) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.deg) val Number.grad - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.grad) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.grad) val Number.rad - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.rad) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.rad) val Number.turn - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.turn) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.turn) val Number.s - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.s) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.s) val Number.ms - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ms) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.ms) val Number.Hz - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.hz) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.hz) val Number.kHz - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.khz) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.khz) val Number.dpi - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpi) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpi) val Number.dpcm - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpcm) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpcm) val Number.dppx - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dppx) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.dppx) val Number.fr - get(): CSSUnitValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.fr) + get(): CSSSizeValue = CSSUnitValueTyped(this.toFloat(), CSSUnit.fr) diff --git a/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt b/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt index 9fc8d3a468..bb74f738a9 100644 --- a/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt +++ b/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt @@ -5,7 +5,6 @@ package org.jetbrains.compose.web.core.tests -import org.jetbrains.compose.web.css.CSSUnitValue import org.jetbrains.compose.web.css.ch import org.jetbrains.compose.web.css.cm import org.jetbrains.compose.web.css.cssRem