Browse Source

StylePropertyValue does not contain any nested entities

pull/743/head
Shagen Ogandzhanian 4 years ago
parent
commit
80f5eae42c
  1. 2
      web/benchmark-core/src/jsMain/kotlin/com/sample/components/Layout.kt
  2. 2
      web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtRow.kt
  3. 14
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt
  4. 4
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSHelpers.kt
  5. 8
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt
  6. 38
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt
  7. 2
      web/core/src/jsMain/kotlin/androidx/compose/web/css/Color.kt
  8. 16
      web/core/src/jsMain/kotlin/androidx/compose/web/css/StyleBuilder.kt

2
web/benchmark-core/src/jsMain/kotlin/com/sample/components/Layout.kt

@ -19,7 +19,7 @@ fun Layout(content: @Composable () -> Unit) {
flexDirection(FlexDirection.Column) flexDirection(FlexDirection.Column)
height(100.percent) height(100.percent)
margin(0.px) margin(0.px)
property("box-sizing", StylePropertyValue("border-box")) property("box-sizing", "border-box".asStylePropertyValue())
} }
} }
) { ) {

2
web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtRow.kt

@ -22,7 +22,7 @@ object WtRows : StyleSheet(AppStylesheet) {
"margin-left", "margin-left",
value("calc(-1*${AppCSSVariables.wtHorizontalLayoutGutter.value()})") value("calc(-1*${AppCSSVariables.wtHorizontalLayoutGutter.value()})")
) )
property("box-sizing", StylePropertyValue("border-box")) property("box-sizing", "border-box".asStylePropertyValue())
} }
val wtRowSizeM by style { val wtRowSizeM by style {

14
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt

@ -343,17 +343,11 @@ fun StylePropertyMapReadOnly.forEach(handler: (String, Array<CSSStyleValue>) ->
} }
// CSSStyleValue | string // CSSStyleValue | string
interface StylePropertyValue { interface StylePropertyValue
companion object {
operator fun invoke(value: String) = value.unsafeCast<StylePropertyValue>()
operator fun invoke(value: Number) = value.unsafeCast<StylePropertyValue>()
operator fun invoke(value: CSSStyleValue) = value.unsafeCast<StylePropertyValue>()
}
}
fun StylePropertyValue.asString() = this.asDynamic() as? String fun String.asStylePropertyValue() = unsafeCast<StylePropertyValue>()
fun StylePropertyValue.asNumber() = this.asDynamic() as? Number fun Number.asStylePropertyValue() = unsafeCast<StylePropertyValue>()
fun StylePropertyValue.asCSSStyleValue(): CSSStyleValue? = this.asDynamic() as? CSSStyleValueJS fun CSSStyleValue.asStylePropertyValue() = unsafeCast<StylePropertyValue>()
external class StylePropertyMap : StylePropertyMapReadOnly { external class StylePropertyMap : StylePropertyMapReadOnly {
fun set(property: String, vararg values: StylePropertyValue) fun set(property: String, vararg values: StylePropertyValue)

4
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSHelpers.kt

@ -3,7 +3,7 @@ package org.jetbrains.compose.web.css
interface CSSAutoValue : CSSStyleValue interface CSSAutoValue : CSSStyleValue
val auto = StylePropertyValue("auto").unsafeCast<CSSAutoValue>() val auto = "auto".unsafeCast<CSSAutoValue>()
// type CSSSizeOrAutoValue = CSSSizeValue | CSSAutoValue // type CSSSizeOrAutoValue = CSSSizeValue | CSSAutoValue
interface CSSSizeOrAutoValue : CSSStyleValue, StylePropertyValue { interface CSSSizeOrAutoValue : CSSStyleValue, StylePropertyValue {
@ -13,8 +13,6 @@ interface CSSSizeOrAutoValue : CSSStyleValue, StylePropertyValue {
} }
} }
fun CSSSizeOrAutoValue.asCSSSizeValue() = this.asDynamic() as? CSSUnitValueJS
enum class Direction { enum class Direction {
rtl, rtl,
ltr; ltr;

8
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSMediaRule.kt

@ -125,13 +125,13 @@ fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.not(
) = CSSMediaQuery.Not(query) ) = CSSMediaQuery.Not(query)
fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.minWidth(value: CSSSizeValue) = fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.minWidth(value: CSSSizeValue) =
CSSMediaQuery.MediaFeature("min-width", StylePropertyValue(value)) CSSMediaQuery.MediaFeature("min-width", value.asStylePropertyValue())
fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.maxWidth(value: CSSSizeValue) = fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.maxWidth(value: CSSSizeValue) =
CSSMediaQuery.MediaFeature("max-width", StylePropertyValue(value)) CSSMediaQuery.MediaFeature("max-width", value.asStylePropertyValue())
fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.minHeight(value: CSSSizeValue) = fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.minHeight(value: CSSSizeValue) =
CSSMediaQuery.MediaFeature("min-height", StylePropertyValue(value)) CSSMediaQuery.MediaFeature("min-height", value.asStylePropertyValue())
fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.maxHeight(value: CSSSizeValue) = fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.maxHeight(value: CSSSizeValue) =
CSSMediaQuery.MediaFeature("max-height", StylePropertyValue(value)) CSSMediaQuery.MediaFeature("max-height", value.asStylePropertyValue())

38
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt

@ -5,15 +5,15 @@ fun StyleBuilder.opacity(value: Number) {
} }
fun StyleBuilder.order(value: Int) { fun StyleBuilder.order(value: Int) {
property("order", StylePropertyValue(value)) property("order", value.asStylePropertyValue())
} }
fun StyleBuilder.flexGrow(value: Number) { fun StyleBuilder.flexGrow(value: Number) {
property("flex-grow", StylePropertyValue(value)) property("flex-grow", value.asStylePropertyValue())
} }
fun StyleBuilder.flexShrink(value: Number) { fun StyleBuilder.flexShrink(value: Number) {
property("flex-shrink", StylePropertyValue(value)) property("flex-shrink", value.asStylePropertyValue())
} }
fun StyleBuilder.opacity(value: CSSpercentValue) { fun StyleBuilder.opacity(value: CSSpercentValue) {
@ -194,11 +194,11 @@ class CSSBorder : CustomStyleValue {
var color: StylePropertyValue? = null var color: StylePropertyValue? = null
fun width(size: CSSSizeValue) { fun width(size: CSSSizeValue) {
width = StylePropertyValue(size) width = size.asStylePropertyValue()
} }
fun style(style: LineStyle) { fun style(style: LineStyle) {
this.style = StylePropertyValue(style.name) this.style = style.name.asStylePropertyValue()
} }
fun color(color: Color) { fun color(color: Color) {
@ -217,7 +217,7 @@ class CSSBorder : CustomStyleValue {
override fun styleValue(): StylePropertyValue { override fun styleValue(): StylePropertyValue {
val values = listOfNotNull(width, style, color) val values = listOfNotNull(width, style, color)
return StylePropertyValue(values.joinToString(" ")) return values.joinToString(" ").asStylePropertyValue()
} }
} }
@ -239,55 +239,55 @@ fun StyleBuilder.border(
} }
fun StyleBuilder.display(displayStyle: DisplayStyle) { fun StyleBuilder.display(displayStyle: DisplayStyle) {
property("display", StylePropertyValue(displayStyle.value)) property("display", displayStyle.value.asStylePropertyValue())
} }
fun StyleBuilder.flexDirection(flexDirection: FlexDirection) { fun StyleBuilder.flexDirection(flexDirection: FlexDirection) {
property("flex-direction", StylePropertyValue(flexDirection.value)) property("flex-direction", flexDirection.value.asStylePropertyValue())
} }
fun StyleBuilder.flexWrap(flexWrap: FlexWrap) { fun StyleBuilder.flexWrap(flexWrap: FlexWrap) {
property("flex-wrap", StylePropertyValue(flexWrap.value)) property("flex-wrap", flexWrap.value.asStylePropertyValue())
} }
fun StyleBuilder.flexFlow(flexDirection: FlexDirection, flexWrap: FlexWrap) { fun StyleBuilder.flexFlow(flexDirection: FlexDirection, flexWrap: FlexWrap) {
property( property(
"flex-flow", "flex-flow",
StylePropertyValue("${flexDirection.value} ${flexWrap.value}") "${flexDirection.value} ${flexWrap.value}".asStylePropertyValue()
) )
} }
fun StyleBuilder.justifyContent(justifyContent: JustifyContent) { fun StyleBuilder.justifyContent(justifyContent: JustifyContent) {
property( property(
"justify-content", "justify-content",
StylePropertyValue(justifyContent.value) justifyContent.value.asStylePropertyValue()
) )
} }
fun StyleBuilder.alignSelf(alignSelf: AlignSelf) { fun StyleBuilder.alignSelf(alignSelf: AlignSelf) {
property( property(
"align-self", "align-self",
StylePropertyValue(alignSelf.value) alignSelf.value.asStylePropertyValue()
) )
} }
fun StyleBuilder.alignItems(alignItems: AlignItems) { fun StyleBuilder.alignItems(alignItems: AlignItems) {
property( property(
"align-items", "align-items",
StylePropertyValue(alignItems.value) alignItems.value.asStylePropertyValue()
) )
} }
fun StyleBuilder.alignContent(alignContent: AlignContent) { fun StyleBuilder.alignContent(alignContent: AlignContent) {
property( property(
"align-content", "align-content",
StylePropertyValue(alignContent.value) alignContent.value.asStylePropertyValue()
) )
} }
fun StyleBuilder.position(position: Position) { fun StyleBuilder.position(position: Position) {
property( property(
"position", "position",
StylePropertyValue(position.value) position.value.asStylePropertyValue()
) )
} }
@ -296,11 +296,11 @@ fun StyleBuilder.width(value: CSSSizeOrAutoValue) {
} }
fun StyleBuilder.borderRadius(r: CSSSizeValue) { fun StyleBuilder.borderRadius(r: CSSSizeValue) {
property("border-radius", StylePropertyValue(r.toString())) property("border-radius", r.toString().asStylePropertyValue())
} }
fun StyleBuilder.borderRadius(topLeft: CSSSizeValue, bottomRight: CSSSizeValue) { fun StyleBuilder.borderRadius(topLeft: CSSSizeValue, bottomRight: CSSSizeValue) {
property("border-radius", StylePropertyValue("$topLeft $bottomRight")) property("border-radius", "$topLeft $bottomRight".asStylePropertyValue())
} }
fun StyleBuilder.borderRadius( fun StyleBuilder.borderRadius(
@ -308,7 +308,7 @@ fun StyleBuilder.borderRadius(
topRightAndBottomLeft: CSSSizeValue, topRightAndBottomLeft: CSSSizeValue,
bottomRight: CSSSizeValue bottomRight: CSSSizeValue
) { ) {
property("border-radius", StylePropertyValue("$topLeft $topRightAndBottomLeft $bottomRight")) property("border-radius", "$topLeft $topRightAndBottomLeft $bottomRight".asStylePropertyValue())
} }
fun StyleBuilder.borderRadius( fun StyleBuilder.borderRadius(
@ -317,7 +317,7 @@ fun StyleBuilder.borderRadius(
bottomRight: CSSSizeValue, bottomRight: CSSSizeValue,
bottomLeft: CSSSizeValue bottomLeft: CSSSizeValue
) { ) {
property("border-radius", StylePropertyValue("$topLeft $topRight $bottomRight $bottomLeft")) property("border-radius", "$topLeft $topRight $bottomRight $bottomLeft".asStylePropertyValue())
} }
fun StyleBuilder.width(value: CSSSizeValue) { fun StyleBuilder.width(value: CSSSizeValue) {

2
web/core/src/jsMain/kotlin/androidx/compose/web/css/Color.kt

@ -1,7 +1,7 @@
package org.jetbrains.compose.web.css package org.jetbrains.compose.web.css
abstract class Color : CustomStyleValue { abstract class Color : CustomStyleValue {
override fun styleValue(): StylePropertyValue = StylePropertyValue(toString()) override fun styleValue(): StylePropertyValue = toString().asStylePropertyValue()
data class Named(val value: String) : Color() { data class Named(val value: String) : Color() {
override fun toString(): String = value override fun toString(): String = value

16
web/core/src/jsMain/kotlin/androidx/compose/web/css/StyleBuilder.kt

@ -12,25 +12,25 @@ interface StyleBuilder {
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun StyleBuilder.value(value: String) = StylePropertyValue(value) inline fun StyleBuilder.value(value: String) = value.asStylePropertyValue()
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun StyleBuilder.value(value: Number) = StylePropertyValue(value) inline fun StyleBuilder.value(value: Number) = value.asStylePropertyValue()
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun StyleBuilder.value(value: CSSStyleValue) = StylePropertyValue(value) inline fun StyleBuilder.value(value: CSSStyleValue) = value.asStylePropertyValue()
fun variableValue(variableName: String, fallback: StylePropertyValue? = null) = fun variableValue(variableName: String, fallback: StylePropertyValue? = null) =
StylePropertyValue("var(--$variableName${fallback?.let { ", $it" } ?: ""})") "var(--$variableName${fallback?.let { ", $it" } ?: ""})".asStylePropertyValue()
interface CSSVariableValue<TValue> : StylePropertyValue { interface CSSVariableValue<TValue> : StylePropertyValue {
companion object { companion object {
operator fun <TValue> invoke(value: String) = operator fun <TValue> invoke(value: String) =
StylePropertyValue(value).unsafeCast<CSSVariableValue<TValue>>() value.unsafeCast<CSSVariableValue<TValue>>()
operator fun <TValue> invoke(value: Number) = operator fun <TValue> invoke(value: Number) =
StylePropertyValue(value).unsafeCast<CSSVariableValue<TValue>>() value.unsafeCast<CSSVariableValue<TValue>>()
operator fun <TValue : CSSStyleValue> invoke(value: TValue) = operator fun <TValue : CSSStyleValue> invoke(value: TValue) =
StylePropertyValue(value).unsafeCast<CSSVariableValue<TValue>>() value.unsafeCast<CSSVariableValue<TValue>>()
operator fun <TValue> invoke(value: StylePropertyValue) = operator fun <TValue> invoke(value: StylePropertyValue) =
value.unsafeCast<CSSVariableValue<TValue>>() value.unsafeCast<CSSVariableValue<TValue>>()
@ -65,7 +65,7 @@ fun <TValue> CSSStyleVariable<TValue>.value(fallback: TValue? = null) =
name, name,
fallback?.let { fallback?.let {
(fallback as? CustomStyleValue)?.styleValue() (fallback as? CustomStyleValue)?.styleValue()
?: StylePropertyValue(fallback.toString()) ?: fallback.toString().asStylePropertyValue()
} }
) )
) )

Loading…
Cancel
Save