Browse Source

CSS Unit classes are value classes

pull/761/head
Shagen Ogandzhanian 4 years ago
parent
commit
1e6c3d0449
  1. 90
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSS.kt
  2. 66
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt
  3. 38
      web/core/src/jsTest/kotlin/CSSUnitApiTests.kt

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

@ -343,51 +343,51 @@ external class StylePropertyMap : StylePropertyMapReadOnly {
inline fun Element.computedStyleMap(): StylePropertyMapReadOnly =
this.asDynamic().computedStyleMap().unsafeCast<StylePropertyMapReadOnly>()
external class CSS {
companion object {
fun number(value: Number): CSSUnitValue
fun percent(value: Number): CSSpercentValue
// <length>
fun em(value: Number): CSSemValue
fun ex(value: Number): CSSexValue
fun ch(value: Number): CSSchValue
fun rem(value: Number): CSSremValue
fun vw(value: Number): CSSvwValue
fun vh(value: Number): CSSvhValue
fun vmin(value: Number): CSSvminValue
fun vmax(value: Number): CSSvmaxValue
fun cm(value: Number): CSScmValue
fun mm(value: Number): CSSmmValue
fun Q(value: Number): CSSQValue
fun pt(value: Number): CSSptValue
fun pc(value: Number): CSSpcValue
fun px(value: Number): CSSpxValue
// <angle>
fun deg(value: Number): CSSdegValue
fun grad(value: Number): CSSgradValue
fun rad(value: Number): CSSradValue
fun turn(value: Number): CSSturnValue
// <time>
fun s(value: Number): CSSsValue
fun ms(value: Number): CSSmsValue
// <frequency>
fun Hz(value: Number): CSSHzValue
fun kHz(value: Number): CSSkHzValue
// <resolution>
fun dpi(value: Number): CSSdpiValue
fun dpcm(value: Number): CSSdpcmValue
fun dppx(value: Number): CSSdppxValue
// <flex>
fun fr(value: Number): CSSfrValue
}
}
//external class CSS {
// companion object {
// fun number(value: Number): CSSUnitValue
// fun percent(value: Number): CSSpercentValue
//
// // <length>
// fun em(value: Number): CSSemValue
// fun ex(value: Number): CSSexValue
// fun ch(value: Number): CSSchValue
// fun rem(value: Number): CSSremValue
// fun vw(value: Number): CSSvwValue
// fun vh(value: Number): CSSvhValue
// fun vmin(value: Number): CSSvminValue
// fun vmax(value: Number): CSSvmaxValue
// fun cm(value: Number): CSScmValue
// fun mm(value: Number): CSSmmValue
// fun Q(value: Number): CSSQValue
//
// fun pt(value: Number): CSSptValue
// fun pc(value: Number): CSSpcValue
// fun px(value: Number): CSSpxValue
//
// // <angle>
// fun deg(value: Number): CSSdegValue
// fun grad(value: Number): CSSgradValue
// fun rad(value: Number): CSSradValue
// fun turn(value: Number): CSSturnValue
//
// // <time>
// fun s(value: Number): CSSsValue
// fun ms(value: Number): CSSmsValue
//
// // <frequency>
// fun Hz(value: Number): CSSHzValue
// fun kHz(value: Number): CSSkHzValue
//
// // <resolution>
// fun dpi(value: Number): CSSdpiValue
// fun dpcm(value: Number): CSSdpcmValue
// fun dppx(value: Number): CSSdppxValue
//
// // <flex>
// fun fr(value: Number): CSSfrValue
// }
//}
@Suppress("unused")
val cssTypedOMPolyfill = CSSTypedOMPolyfill.default(window)

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

@ -8,167 +8,167 @@ interface CSSFrequencyValue
interface CSSResolutionValue
interface CSSFlexValue
class CSSpercentValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSpercentValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "percent"
}
class CSSemValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSemValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "em"
}
class CSSexValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSexValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "ex"
}
class CSSchValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSchValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "ch"
}
class CSSicValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSicValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "ic"
}
class CSSremValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSremValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "rem"
}
class CSSlhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSlhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "lh"
}
class CSSrlhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSrlhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "rlh"
}
class CSSvwValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSvwValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vw"
}
class CSSvhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSvhValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vh"
}
class CSSviValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSviValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vi"
}
class CSSvbValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSvbValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vb"
}
class CSSvminValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSvminValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vmin"
}
class CSSvmaxValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSvmaxValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "vmax"
}
class CSScmValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSScmValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "cm"
}
class CSSmmValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSmmValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "mm"
}
class CSSQValue(override val value: Number) : CSSUnitValue, CSSRelValue {
value class CSSQValue(override val value: Number) : CSSUnitValue, CSSRelValue {
override val unit: String
get() = "q"
}
class CSSptValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
value class CSSptValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
override val unit: String
get() = "pt"
}
class CSSpcValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
value class CSSpcValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
override val unit: String
get() = "pc"
}
class CSSpxValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
value class CSSpxValue(override val value: Number) : CSSUnitValue, CSSAbsValue {
override val unit: String
get() = "px"
}
class CSSdegValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
value class CSSdegValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
override val unit: String
get() = "deg"
}
class CSSgradValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
value class CSSgradValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
override val unit: String
get() = "grad"
}
class CSSradValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
value class CSSradValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
override val unit: String
get() = "rad"
}
class CSSturnValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
value class CSSturnValue(override val value: Number) : CSSUnitValue, CSSAngleValue {
override val unit: String
get() = "turn"
}
class CSSsValue(override val value: Number) : CSSUnitValue, CSSTimeValue {
value class CSSsValue(override val value: Number) : CSSUnitValue, CSSTimeValue {
override val unit: String
get() = "s"
}
class CSSmsValue(override val value: Number) : CSSUnitValue, CSSTimeValue {
value class CSSmsValue(override val value: Number) : CSSUnitValue, CSSTimeValue {
override val unit: String
get() = "ms"
}
class CSSHzValue(override val value: Number) : CSSUnitValue, CSSFrequencyValue {
value class CSSHzValue(override val value: Number) : CSSUnitValue, CSSFrequencyValue {
override val unit: String
get() = "hz"
}
class CSSkHzValue(override val value: Number) : CSSUnitValue, CSSFrequencyValue {
value class CSSkHzValue(override val value: Number) : CSSUnitValue, CSSFrequencyValue {
override val unit: String
get() = "khz"
}
class CSSdpiValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
value class CSSdpiValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
override val unit: String
get() = "dpi"
}
class CSSdpcmValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
value class CSSdpcmValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
override val unit: String
get() = "dpcm"
}
class CSSdppxValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
value class CSSdppxValue(override val value: Number) : CSSUnitValue, CSSResolutionValue {
override val unit: String
get() = "dppx"
}
class CSSfrValue(override val value: Number) : CSSUnitValue, CSSFlexValue {
value class CSSfrValue(override val value: Number) : CSSUnitValue, CSSFlexValue {
override val unit: String
get() = "fr"
}
class CSSnumberValue(override val value: Number) : CSSUnitValue, CSSFlexValue {
value class CSSnumberValue(override val value: Number) : CSSUnitValue, CSSFlexValue {
override val unit: String
get() = "number"
}

38
web/core/src/jsTest/kotlin/CSSUnitApiTests.kt

@ -5,7 +5,6 @@
package org.jetbrains.compose.web.core.tests
import org.jetbrains.compose.web.css.CSS
import org.jetbrains.compose.web.css.CSSUnitValue
import org.jetbrains.compose.web.css.CSSchValue
import org.jetbrains.compose.web.css.CSScmValue
@ -71,43 +70,6 @@ class CSSUnitApiTests {
return assertStructure(otherUnit.value, otherUnit.unit, description)
}
// @Test
// fun builderInvocation() {
// CSS.number(4).assertStructure(4, "number")
// CSS.percent(4).assertStructure(4, "percent")
//
// CSS.em(4).assertStructure(4, "em")
// CSS.ch(4).assertStructure(4, "ch")
//
// CSS.rem(4).assertStructure(4, "rem")
//
// CSS.vw(4).assertStructure(4, "vw")
// CSS.vh(4).assertStructure(4, "vh")
//
// CSS.vmin(4).assertStructure(4, "vmin")
// CSS.vmax(4).assertStructure(4, "vmax")
// CSS.cm(4).assertStructure(4, "cm")
// CSS.mm(4).assertStructure(4, "mm")
//
// CSS.pt(4).assertStructure(4, "pt")
// CSS.pc(4).assertStructure(4, "pc")
// CSS.px(4).assertStructure(4, "px")
//
// CSS.deg(4).assertStructure(4, "deg")
// CSS.grad(4).assertStructure(4, "grad")
// CSS.rad(4).assertStructure(4, "rad")
// CSS.turn(4).assertStructure(4, "turn")
//
// CSS.s(4).assertStructure(4, "s")
// CSS.ms(4).assertStructure(4, "ms")
//
// CSS.dpi(4).assertStructure(4, "dpi")
// CSS.dpcm(4).assertStructure(4, "dpcm")
// CSS.dppx(4).assertStructure(4, "dppx")
//
// CSS.fr(4).assertStructure(4, "fr")
// }
@Test
fun postfixInvocation() {
4.number.assertStructure(CSSnumberValue(4), "number postfix")

Loading…
Cancel
Save