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 cac09e808f..bafa87ee92 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 @@ -17,6 +17,9 @@ private data class CSSUnitValueTyped( operator fun CSSSizeValue.times(num: Number): CSSSizeValue = newUnit(value * num.toFloat()) operator fun Number.times(unit: CSSSizeValue): CSSSizeValue = unit.newUnit(unit.value * toFloat()) +operator fun CSSSizeValue.div(num: Number): CSSSizeValue = newUnit(value / num.toFloat()) + + typealias CSSUnitValue = CSSSizeValue typealias CSSpxValue = CSSSizeValue diff --git a/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt b/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt index b186421e6d..b901a6e22c 100644 --- a/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt +++ b/web/core/src/jsTest/kotlin/CSSUnitApiTests.kt @@ -9,6 +9,7 @@ import org.jetbrains.compose.web.css.ch import org.jetbrains.compose.web.css.cm import org.jetbrains.compose.web.css.cssRem import org.jetbrains.compose.web.css.deg +import org.jetbrains.compose.web.css.div import org.jetbrains.compose.web.css.dpcm import org.jetbrains.compose.web.css.dpi import org.jetbrains.compose.web.css.dppx @@ -150,6 +151,42 @@ class CSSUnitApiTests { assertEquals(16.fr, 4.fr * 4) } + @Test + fun arithmeticDivisionLeft() { + assertEquals(1.percent, 4.percent / 4) + + assertEquals(1.em, 4.em / 4) + assertEquals(1.ch, 4.ch / 4) + + assertEquals(1.cssRem, 4.cssRem / 4) + + assertEquals(1.vw, 4.vw / 4) + assertEquals(1.vh, 4.vh / 4) + + assertEquals(1.vmin, 4.vmin / 4) + assertEquals(1.vmax, 4.vmax / 4) + assertEquals(1.cm, 4.cm / 4) + assertEquals(1.mm, 4.mm / 4) + + assertEquals(1.pt, 4.pt / 4) + assertEquals(1.pc, 4.pc / 4) + assertEquals(1.px, 4.px / 4) + + assertEquals(1.deg, 4.deg / 4) + assertEquals(1.grad, 4.grad / 4) + assertEquals(1.rad, 4.rad / 4) + assertEquals(1.turn, 4.turn / 4) + + assertEquals(1.s, 4.s / 4) + assertEquals(1.ms, 4.ms / 4) + + assertEquals(1.dpi, 4.dpi / 4) + assertEquals(1.dpcm, 4.dpcm / 4) + assertEquals(1.dppx, 4.dppx / 4) + + assertEquals(1.fr, 4.fr / 4) + } + @Test fun arithmeticMultiplicationRight() { assertEquals(12.percent, 3 * 4.percent)