Browse Source

CSSSizeOrAutoValue is a marker interface

This leads to lie since it's actually not an external interface.
But this is a forgiveable lie, regarding the fact what would come next.
pull/743/head
Shagen Ogandzhanian 4 years ago
parent
commit
a4c7f3d074
  1. 2
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt
  2. 10
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSHelpers.kt
  3. 52
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt
  4. 2
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt

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

@ -343,7 +343,7 @@ fun StylePropertyMapReadOnly.forEach(handler: (String, Array<CSSStyleValue>) ->
}
// CSSStyleValue | string
interface StylePropertyValue
external interface StylePropertyValue
fun String.asStylePropertyValue() = unsafeCast<StylePropertyValue>()
fun Number.asStylePropertyValue() = unsafeCast<StylePropertyValue>()

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

@ -1,17 +1,11 @@
@file:Suppress("UNUSED")
package org.jetbrains.compose.web.css
interface CSSAutoValue : CSSStyleValue
interface CSSAutoValue : CSSSizeOrAutoValue
val auto = "auto".unsafeCast<CSSAutoValue>()
// type CSSSizeOrAutoValue = CSSSizeValue | CSSAutoValue
interface CSSSizeOrAutoValue : CSSStyleValue, StylePropertyValue {
companion object {
operator fun invoke(value: CSSSizeValue) = value.unsafeCast<CSSSizeOrAutoValue>()
operator fun invoke(value: CSSAutoValue) = value.unsafeCast<CSSSizeOrAutoValue>()
}
}
external interface CSSSizeOrAutoValue : StylePropertyValue
enum class Direction {
rtl,

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

@ -291,10 +291,6 @@ fun StyleBuilder.position(position: Position) {
)
}
fun StyleBuilder.width(value: CSSSizeOrAutoValue) {
property("width", value)
}
fun StyleBuilder.borderRadius(r: CSSSizeValue) {
property("border-radius", r.toString().asStylePropertyValue())
}
@ -320,74 +316,30 @@ fun StyleBuilder.borderRadius(
property("border-radius", "$topLeft $topRight $bottomRight $bottomLeft".asStylePropertyValue())
}
fun StyleBuilder.width(value: CSSSizeValue) {
width(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.width(value: CSSAutoValue) {
width(CSSSizeOrAutoValue(value))
fun StyleBuilder.width(value: CSSSizeOrAutoValue) {
property("width", value)
}
fun StyleBuilder.height(value: CSSSizeOrAutoValue) {
property("height", value)
}
fun StyleBuilder.height(value: CSSSizeValue) {
height(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.height(value: CSSAutoValue) {
height(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.top(value: CSSSizeOrAutoValue) {
property("top", value)
}
fun StyleBuilder.top(value: CSSSizeValue) {
top(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.top(value: CSSAutoValue) {
top(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.bottom(value: CSSSizeOrAutoValue) {
property("bottom", value)
}
fun StyleBuilder.bottom(value: CSSSizeValue) {
bottom(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.bottom(value: CSSAutoValue) {
bottom(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.left(value: CSSSizeOrAutoValue) {
property("left", value)
}
fun StyleBuilder.left(value: CSSSizeValue) {
left(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.left(value: CSSAutoValue) {
left(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.right(value: CSSSizeOrAutoValue) {
property("right", value)
}
fun StyleBuilder.right(value: CSSSizeValue) {
right(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.right(value: CSSAutoValue) {
right(CSSSizeOrAutoValue(value))
}
fun StyleBuilder.fontSize(value: CSSSizeValue) {
property("font-size", value(value))
}

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

@ -2,7 +2,7 @@
package org.jetbrains.compose.web.css
external interface CSSSizeValue : CSSUnitValue
external interface CSSSizeValue : CSSUnitValue, CSSSizeOrAutoValue
// fake interfaces to distinguish units
external interface CSSRelValue : CSSSizeValue

Loading…
Cancel
Save