Browse Source

SKIKO COMPOSE

Wasm support experimental
yakovlev/wasm-experimental
Igor Yakovlev 2 years ago
parent
commit
67dba00fed
  1. 2
      compose/base64
  2. 2
      compose/frameworks/support
  3. BIN
      compose/gradle/wrapper/gradle-wrapper.jar
  4. 5
      compose/gradle/wrapper/gradle-wrapper.properties
  5. 1
      compose/scripts/runGradle
  6. 35
      examples/web-compose-bird/build.gradle.kts
  7. 3
      examples/web-compose-bird/gradle.properties
  8. 2981
      examples/web-compose-bird/kotlin-js-store/yarn.lock
  9. 3
      examples/web-compose-bird/settings.gradle.kts
  10. 154
      examples/web-compose-bird/src/jsMain/kotlin/core/ComposeBirdGame.kt
  11. 158
      examples/web-compose-bird/src/jsWasmMain/kotlin/core/ComposeBirdGame.kt
  12. 0
      examples/web-compose-bird/src/jsWasmMain/kotlin/core/Game.kt
  13. 0
      examples/web-compose-bird/src/jsWasmMain/kotlin/data/GameFrame.kt
  14. 0
      examples/web-compose-bird/src/jsWasmMain/kotlin/data/Tube.kt
  15. 0
      examples/web-compose-bird/src/jsWasmMain/kotlin/main.kt
  16. 4
      examples/web-compose-bird/src/wasmMain/kotlin/core/ComposeBirdGame.kt
  17. 17
      examples/web-compose-bird/src/wasmMain/resources/index.html
  18. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerCompatability.kt
  19. 12
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/ComposeCompilerArtifactProvider.kt
  20. 8
      gradle-plugins/gradle.properties
  21. 16
      templates/web-template/build.gradle.kts
  22. 16
      web/benchmark-core/build.gradle.kts
  23. 27
      web/build.gradle.kts
  24. 1
      web/buildSrc/build.gradle.kts
  25. 2
      web/buildSrc/gradle.properties
  26. 1
      web/buildSrc/settings.gradle.kts
  27. 5
      web/compose-compiler-integration/build.gradle.kts
  28. 2
      web/compose-compiler-integration/main-template/build.gradle.kts
  29. 2
      web/compose-compiler-integration/main-template/lib/build.gradle.kts
  30. 67
      web/core/build.gradle.kts
  31. 6
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSKeywords.kt
  32. 70
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt
  33. 249
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSUnits.kt
  34. 197
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/Color.kt
  35. 15
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyValue.kt
  36. 194
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StyleScope.kt
  37. 6
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/keywords/Keywords.kt
  38. 54
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/w3cExtensions.kt
  39. 1
      web/core/src/jsTest/kotlin/css/GridTests.kt
  40. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebApi.kt
  41. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebStyleApi.kt
  42. 7
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/Attrs.kt
  43. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/AttrsScope.kt
  44. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/EventsListenerScope.kt
  45. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/HtmlAttrMarker.kt
  46. 7
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/PredefinedAttrValues.kt
  47. 4
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/SyntheticEventListener.kt
  48. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/InputAttrsScope.kt
  49. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/InternalControlledInputUtils.kt
  50. 5
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/SelectAttrsScope.kt
  51. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/TextAreaAttrsScope.kt
  52. 7
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/BrowserAPI.kt
  53. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSBuilder.kt
  54. 6
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt
  55. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSKeyframeRule.kt
  56. 14
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSKeywords.kt
  57. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSMediaRule.kt
  58. 71
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt
  59. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt
  60. 249
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSUnits.kt
  61. 198
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/Color.kt
  62. 23
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StylePropertyValue.kt
  63. 196
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleScope.kt
  64. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleSheet.kt
  65. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleSheetBuilder.kt
  66. 15
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/keywords/Keywords.kt
  67. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/animation.kt
  68. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/background.kt
  69. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/border.kt
  70. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/box.kt
  71. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/color.kt
  72. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/filter.kt
  73. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/flex.kt
  74. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/grid.kt
  75. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/listStyle.kt
  76. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/margin.kt
  77. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/overflow.kt
  78. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/padding.kt
  79. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/position.kt
  80. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/properties.kt
  81. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt
  82. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/transform.kt
  83. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/transitions.kt
  84. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/ui.kt
  85. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/selectors/CSSSelectors.kt
  86. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt
  87. 10
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Base.kt
  88. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/ElementScope.kt
  89. 1
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt
  90. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/InputElements.kt
  91. 1
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/RadioGroup.kt
  92. 2
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Style.kt
  93. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticAnimationEvent.kt
  94. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticChangeEvent.kt
  95. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticClipboardEvent.kt
  96. 3
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticEvent.kt
  97. 0
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticFocusEvent.kt
  98. 9
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticInputEvent.kt
  99. 3
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticKeyboardEvent.kt
  100. 7
      web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticMouseEvent.kt
  101. Some files were not shown because too many files have changed in this diff Show More

2
compose/base64

@ -0,0 +1,2 @@
AGFzbQEAAAABBQFgAAF/AhIBA2VudgZtZW1vcnkCAYACgAIDAgEABwsBB19yZW5kZXIAAApJAUcBA38DQCAAQaAGbCECQQAhAQNAIAEgAmpBAnRBgAhqQf+BgHg2AgAgAUEBaiIBQaAGRw0ACyAAQQFqIgBBkANHDQALQYAICw==
AGFzbQEAAAABBQFgAAF/AhIBA2VudgZtZW1vcnkCAYACgAIDAgEABwsBB19yZW5kZXIAAApJAUcBA38DQCAAQaAGbCECQQAhAQNAIAEgAmpBAnRBgAhqQf+BgHg2AgAgAUEBaiIBQaAGRw0ACyAAQQFqIgBBkANHDQALQYAICw== -d

2
compose/frameworks/support

@ -1 +1 @@
Subproject commit adf295be1d7ab30f6ab1d291c7f05475b6c50937
Subproject commit 0f2218ce9c773f0bf5c7e70dcf692dc93b373977

BIN
compose/gradle/wrapper/gradle-wrapper.jar vendored

Binary file not shown.

5
compose/gradle/wrapper/gradle-wrapper.properties vendored

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

1
compose/scripts/runGradle

@ -1,7 +1,6 @@
#!/bin/bash
cd "$(dirname "$0")"
pushd ..
./gradlew $COMPOSE_DEFAULT_GRADLE_ARGS "$@" || exit 1
popd

35
examples/web-compose-bird/build.gradle.kts

@ -2,15 +2,17 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
//id("org.jetbrains.compose")
}
group = "com.theapache64.composebird"
version = "1.0.0-alpha01"
// Add maven repositories
repositories {
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
google()
}
@ -19,12 +21,29 @@ kotlin {
browser()
binaries.executable()
}
wasm {
browser()
binaries.executable()
}
sourceSets {
val jsMain by getting {
val jsWasmMain by creating {
dependencies {
implementation(compose.web.core)
implementation(compose.runtime)
// implementation(compose.web.core)
// implementation(compose.runtime)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4-wasm0")
implementation("org.jetbrains.compose.web:web-core:1.2.0-SNAPSHOT")
implementation("org.jetbrains.compose.web:internal-web-core-runtime:1.2.0-SNAPSHOT")
implementation("org.jetbrains.compose.runtime:runtime:1.3.0-rc01-SNAPSHOT")
}
}
val jsMain by getting {
dependsOn(jsWasmMain)
}
val wasmMain by getting {
dependsOn(jsWasmMain)
}
}
}
@ -36,3 +55,11 @@ afterEvaluate {
versions.webpackCli.version = "4.10.0"
}
}
project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
"-Xplugin=${project.properties["compose.plugin.path"]}",
"-Xir-dce"
)
}

3
examples/web-compose-bird/gradle.properties

@ -1,3 +1,4 @@
kotlin.code.style=official
kotlin.version=1.7.10
kotlin.version=1.8.255-SNAPSHOT
compose.version=1.2.0
compose.plugin.path=/Users/Igor.Yakovlev/.m2/repository/org/jetbrains/compose/compiler/compiler/0.0.0-SNAPSHOT/compiler-0.0.0-SNAPSHOT.jar

2981
examples/web-compose-bird/kotlin-js-store/yarn.lock

File diff suppressed because it is too large Load Diff

3
examples/web-compose-bird/settings.gradle.kts

@ -1,5 +1,6 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
@ -7,7 +8,7 @@ pluginManagement {
plugins {
kotlin("multiplatform").version(extra["kotlin.version"] as String)
id("org.jetbrains.compose").version(extra["compose.version"] as String)
//id("org.jetbrains.compose").version(extra["compose.version"] as String)
}
}

154
examples/web-compose-bird/src/jsMain/kotlin/core/ComposeBirdGame.kt

@ -1,157 +1,5 @@
package core
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import data.GameFrame
import data.Tube
import kotlin.js.Date
/**
* Game logic
*/
class ComposeBirdGame : Game {
companion object {
const val COLUMNS = 15
const val ROWS = 9
const val BIRD_COLUMN = 1
private const val TUBES_START_FROM = (COLUMNS * 0.75).toInt()
const val TOTAL_TUBES = 10
private const val TUBE_HORIZONTAL_DISTANCE = 3
private const val TUBE_VERTICAL_DISTANCE = 3
private const val TUBE_WEIGHT = 500
private const val BIRD_WEIGHT = 300
}
private val tubeGapRange = TUBE_VERTICAL_DISTANCE until ROWS
private var tubeLastSteppedAt = 0.0
private var birdLastSteppedAt = 0.0
private var shouldMoveBirdUp = false
private val _gameFrame: MutableState<GameFrame> by lazy {
mutableStateOf(
// First frame
GameFrame(
birdPos = ROWS / 2,
tubes = buildLevel(),
isGameOver = false,
isGameWon = false,
score = 0
)
)
}
/**
* To build a random level
*/
private fun buildLevel(): List<Tube> {
return mutableListOf<Tube>().apply {
var tubesAdded = 0
var tubePosition = 0
while (tubesAdded < TOTAL_TUBES) {
if (tubePosition > TUBES_START_FROM && tubePosition % TUBE_HORIZONTAL_DISTANCE == 0) { // To give space to each tube
add(
Tube(
tubePosition,
buildRandomTube()
)
)
tubesAdded++
}
tubePosition++
}
}
}
/**
* To build a random vertical tube/pipe
*/
private fun buildRandomTube(): List<Boolean> {
// creating a full tube
val tube = mutableListOf<Boolean>().apply {
repeat(ROWS) {
add(true)
}
}
// Adding gaps in random middle positions to make it two tubes.
val gap1 = tubeGapRange.random()
repeat(TUBE_VERTICAL_DISTANCE) { index ->
tube[gap1 - index] = false
}
return tube
}
override val gameFrame: State<GameFrame> = _gameFrame
override fun step() {
update {
val now = Date().getTime()
// Stepping tube
val tubeDiff = now - tubeLastSteppedAt
val newTubes = if (tubeDiff > TUBE_WEIGHT) {
tubeLastSteppedAt = now
tubes.map {
it.copy(position = it.position - 1)
}
} else {
tubes
}
// Stepping bird position
val birdDiff = now - birdLastSteppedAt
val newBirdPos = when {
shouldMoveBirdUp -> {
birdLastSteppedAt = now
shouldMoveBirdUp = false
birdPos - 1 // move up
}
birdDiff > BIRD_WEIGHT -> {
birdLastSteppedAt = now
birdPos + 1 // move down
}
else -> {
birdPos
}
}
val newScore = newTubes.filter { it.position < BIRD_COLUMN }.size // All passed tube
val newIsGameWon = newScore >= TOTAL_TUBES // If all tubes passed
// Checking if bird gone out
val newIsGameOver = if (newBirdPos < 0 || newBirdPos >= ROWS || isCollidedWithTube(newBirdPos, tubes)) {
true
} else {
isGameOver
}
copy(
isGameOver = newIsGameOver,
tubes = newTubes,
birdPos = newBirdPos,
score = newScore,
isGameWon = newIsGameWon
)
}
}
/**
* To check if the bird collided with the tube (collision-detection)
*/
private fun isCollidedWithTube(newBirdPos: Int, tubes: List<Tube>): Boolean {
val birdTube = tubes.find { it.position == BIRD_COLUMN }
return birdTube?.coordinates?.get(newBirdPos) ?: false
}
override fun moveBirdUp() {
shouldMoveBirdUp = true
}
private inline fun update(func: GameFrame.() -> GameFrame) {
_gameFrame.value = _gameFrame.value.func()
}
}
actual fun getTime(): Double = Date().getTime()

158
examples/web-compose-bird/src/jsWasmMain/kotlin/core/ComposeBirdGame.kt

@ -0,0 +1,158 @@
package core
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import data.GameFrame
import data.Tube
expect fun getTime(): Double
/**
* Game logic
*/
class ComposeBirdGame : Game {
companion object {
const val COLUMNS = 15
const val ROWS = 9
const val BIRD_COLUMN = 1
private const val TUBES_START_FROM = (COLUMNS * 0.75).toInt()
const val TOTAL_TUBES = 10
private const val TUBE_HORIZONTAL_DISTANCE = 3
private const val TUBE_VERTICAL_DISTANCE = 3
private const val TUBE_WEIGHT = 500
private const val BIRD_WEIGHT = 300
}
private val tubeGapRange = TUBE_VERTICAL_DISTANCE until ROWS
private var tubeLastSteppedAt = 0.0
private var birdLastSteppedAt = 0.0
private var shouldMoveBirdUp = false
private val _gameFrame: MutableState<GameFrame> by lazy {
mutableStateOf(
// First frame
GameFrame(
birdPos = ROWS / 2,
tubes = buildLevel(),
isGameOver = false,
isGameWon = false,
score = 0
)
)
}
/**
* To build a random level
*/
private fun buildLevel(): List<Tube> {
return mutableListOf<Tube>().apply {
var tubesAdded = 0
var tubePosition = 0
while (tubesAdded < TOTAL_TUBES) {
if (tubePosition > TUBES_START_FROM && tubePosition % TUBE_HORIZONTAL_DISTANCE == 0) { // To give space to each tube
add(
Tube(
tubePosition,
buildRandomTube()
)
)
tubesAdded++
}
tubePosition++
}
}
}
/**
* To build a random vertical tube/pipe
*/
private fun buildRandomTube(): List<Boolean> {
// creating a full tube
val tube = mutableListOf<Boolean>().apply {
repeat(ROWS) {
add(true)
}
}
// Adding gaps in random middle positions to make it two tubes.
val gap1 = tubeGapRange.random()
repeat(TUBE_VERTICAL_DISTANCE) { index ->
tube[gap1 - index] = false
}
return tube
}
override val gameFrame: State<GameFrame> = _gameFrame
override fun step() {
update {
val now = getTime()
// Stepping tube
val tubeDiff = now - tubeLastSteppedAt
val newTubes = if (tubeDiff > TUBE_WEIGHT) {
tubeLastSteppedAt = now
tubes.map {
it.copy(position = it.position - 1)
}
} else {
tubes
}
// Stepping bird position
val birdDiff = now - birdLastSteppedAt
val newBirdPos = when {
shouldMoveBirdUp -> {
birdLastSteppedAt = now
shouldMoveBirdUp = false
birdPos - 1 // move up
}
birdDiff > BIRD_WEIGHT -> {
birdLastSteppedAt = now
birdPos + 1 // move down
}
else -> {
birdPos
}
}
val newScore = newTubes.filter { it.position < BIRD_COLUMN }.size // All passed tube
val newIsGameWon = newScore >= TOTAL_TUBES // If all tubes passed
// Checking if bird gone out
val newIsGameOver = if (newBirdPos < 0 || newBirdPos >= ROWS || isCollidedWithTube(newBirdPos, tubes)) {
true
} else {
isGameOver
}
copy(
isGameOver = newIsGameOver,
tubes = newTubes,
birdPos = newBirdPos,
score = newScore,
isGameWon = newIsGameWon
)
}
}
/**
* To check if the bird collided with the tube (collision-detection)
*/
private fun isCollidedWithTube(newBirdPos: Int, tubes: List<Tube>): Boolean {
val birdTube = tubes.find { it.position == BIRD_COLUMN }
return birdTube?.coordinates?.get(newBirdPos) ?: false
}
override fun moveBirdUp() {
shouldMoveBirdUp = true
}
private inline fun update(func: GameFrame.() -> GameFrame) {
_gameFrame.value = _gameFrame.value.func()
}
}

0
examples/web-compose-bird/src/jsMain/kotlin/core/Game.kt → examples/web-compose-bird/src/jsWasmMain/kotlin/core/Game.kt

0
examples/web-compose-bird/src/jsMain/kotlin/data/GameFrame.kt → examples/web-compose-bird/src/jsWasmMain/kotlin/data/GameFrame.kt

0
examples/web-compose-bird/src/jsMain/kotlin/data/Tube.kt → examples/web-compose-bird/src/jsWasmMain/kotlin/data/Tube.kt

0
examples/web-compose-bird/src/jsMain/kotlin/main.kt → examples/web-compose-bird/src/jsWasmMain/kotlin/main.kt

4
examples/web-compose-bird/src/wasmMain/kotlin/core/ComposeBirdGame.kt

@ -0,0 +1,4 @@
package core
@JsFun("() => new Date().getTime()")
actual external fun getTime(): Double

17
examples/web-compose-bird/src/wasmMain/resources/index.html

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>compose-bird</title>
<style>
input[type=radio]{
width:25px;
height:25px;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="web-compose-bird-wasm.mjs"></script>
</body>
</html>

4
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerCompatability.kt

@ -9,6 +9,10 @@ internal object ComposeCompilerCompatability {
"1.3.2",
unsupportedPlatforms = setOf(KotlinPlatformType.js)
)
"1.8.255-SNAPSHOT" -> ComposeCompilerVersion(
"1.3.2",
//unsupportedPlatforms = setOf(KotlinPlatformType.js)
)
else -> null
}
}

12
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/ComposeCompilerArtifactProvider.kt

@ -19,12 +19,12 @@ internal class ComposeCompilerArtifactProvider(
private val customPluginString: () -> String?
) {
fun checkTargetSupported(target: KotlinTarget) {
require(!unsupportedPlatforms.contains(target.platformType)) {
"This version of Compose Multiplatform doesn't support Kotlin " +
"$kotlinVersion for ${target.platformType} target. " +
"Please see $KOTLIN_COMPATABILITY_LINK " +
"to know the latest supported version of Kotlin."
}
// require(!unsupportedPlatforms.contains(target.platformType)) {
// "This version of Compose Multiplatform doesn't support Kotlin " +
// "$kotlinVersion for ${target.platformType} target. " +
// "Please see $KOTLIN_COMPATABILITY_LINK " +
// "to know the latest supported version of Kotlin."
// }
}
private val autoCompilerVersion by lazy {

8
gradle-plugins/gradle.properties

@ -6,15 +6,15 @@ compose.version=1.2.0
# The latest version of Compose Compiler used by Gradle plugin. Used only in tests.
compose.tests.compiler.version=1.3.2
# The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests.
compose.tests.compiler.compatible.kotlin.version=1.7.20
compose.tests.compiler.compatible.kotlin.version=1.8.255-SNAPSHOT
# The latest version of Kotlin compatible with compose.tests.compiler.version for JS target. Used only on CI.
compose.tests.js.compiler.compatible.kotlin.version=1.7.10
compose.tests.js.compiler.compatible.kotlin.version=1.8.255-SNAPSHOT
# Version of Compose Compiler published by Google.
# Used to check if our plugin is compatible with it.
# https://developer.android.com/jetpack/androidx/releases/compose-kotlin
compose.tests.androidx.compiler.version=1.1.1
compose.tests.androidx.compiler.compatible.kotlin.version=1.6.10
compose.tests.androidx.compiler.compatible.kotlin.version=1.8.255-SNAPSHOT
# A version of Gradle plugin, that will be published,
# unless overridden by COMPOSE_GRADLE_PLUGIN_VERSION env var.
deploy.version=0.1.0-SNAPSHOT
deploy.version=1.3.2

16
templates/web-template/build.gradle.kts

@ -1,24 +1,36 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
buildscript {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
repositories {
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
kotlin {
js(IR) {
// js(IR) {
// browser()
// binaries.executable()
// }
wasm {
browser()
binaries.executable()
}
sourceSets {
val jsMain by getting {
val wasmMain by getting {
kotlin.srcDir("src/main/kotlin")
resources.srcDir("src/main/resources")

16
web/benchmark-core/build.gradle.kts

@ -1,6 +1,6 @@
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("org.jetbrains.compose")
//id("org.jetbrains.compose")
}
@ -20,7 +20,8 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
//implementation(compose.runtime)
implementation("org.jetbrains.compose.runtime:runtime-js:1.3.0-rc01-SNAPSHOT")
implementation(project(":web-core"))
implementation(kotlin("stdlib-common"))
}
@ -28,6 +29,9 @@ kotlin {
val jsMain by getting {
dependencies {
implementation("org.jetbrains.compose.web:web-core-js:1.2.0-SNAPSHOT")
implementation("org.jetbrains.compose.web:internal-web-core-runtime-js:1.2.0-SNAPSHOT")
implementation("org.jetbrains.compose.runtime:runtime-js:1.3.0-rc01-SNAPSHOT")
implementation(kotlin("stdlib-js"))
}
}
@ -71,3 +75,11 @@ val printBenchmarkResults by tasks.registering {
}
tasks.named("jsTest") { finalizedBy(printBenchmarkResults) }
project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
"-Xplugin=${project.properties["compose.plugin.path"]}"
)
}

27
web/build.gradle.kts

@ -2,13 +2,13 @@ import org.gradle.api.tasks.testing.AbstractTestTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.compose.gradle.kotlinKarmaConfig
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.targets
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets
plugins {
kotlin("multiplatform") apply false
}
val COMPOSE_WEB_VERSION: String = extra["compose.version"] as String
val COMPOSE_WEB_VERSION: String = (extra["compose.version"] as String) + "-SNAPSHOT"
val COMPOSE_REPO_USERNAME: String? by project
val COMPOSE_REPO_KEY: String? by project
val COMPOSE_WEB_BUILD_WITH_SAMPLES = project.property("compose.web.buildSamples")!!.toString().toBoolean()
@ -147,19 +147,22 @@ subprojects {
}
repositories {
gradlePluginPortal()
mavenLocal()
mavenCentral()
maven {
url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
maven {
url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven")
url = uri("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
}
maven {
url = uri("https://packages.jetbrains.team/maven/p/ui/dev")
}
google()
gradlePluginPortal()
mavenCentral()
// maven {
// url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev")
// }
// maven {
// url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven")
// }
// maven {
// url = uri("https://packages.jetbrains.team/maven/p/ui/dev")
// }
// google()
}
tasks.withType<AbstractTestTask> {

1
web/buildSrc/build.gradle.kts

@ -1,6 +1,7 @@
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
maven {
url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

2
web/buildSrc/gradle.properties

@ -1 +1 @@
kotlin.version=1.7.10
kotlin.version=1.8.255-SNAPSHOT

1
web/buildSrc/settings.gradle.kts

@ -2,6 +2,7 @@ pluginManagement {
val kotlinVersion: String = settings.extra["kotlin.version"] as String
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
maven {

5
web/compose-compiler-integration/build.gradle.kts

@ -2,7 +2,7 @@ import org.jetbrains.compose.gradle.standardConf
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
//id("org.jetbrains.compose")
}
@ -22,7 +22,8 @@ kotlin {
val jsMain by getting {
dependencies {
implementation(kotlin("stdlib-js"))
implementation(compose.runtime)
//implementation(compose.runtime)
implementation("org.jetbrains.compose.runtime:runtime-js:1.3.0-rc01-SNAPSHOT")
implementation(project(":web-core"))
}
}

2
web/compose-compiler-integration/main-template/build.gradle.kts

@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
//id("org.jetbrains.compose")
}
repositories {

2
web/compose-compiler-integration/main-template/lib/build.gradle.kts

@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform")// version "1.5.10"
id("org.jetbrains.compose")// version (System.getenv("COMPOSE_INTEGRATION_VERSION") ?: "0.0.0-SNASPHOT")
//id("org.jetbrains.compose")// version (System.getenv("COMPOSE_INTEGRATION_VERSION") ?: "0.0.0-SNASPHOT")
}
repositories {

67
web/core/build.gradle.kts

@ -2,12 +2,14 @@ import org.jetbrains.compose.gradle.standardConf
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
////id("org.jetbrains.compose")
}
kotlin {
jvm()
// jvm {
//
// }
js(IR) {
browser() {
testTask {
@ -18,21 +20,54 @@ kotlin {
}
binaries.executable()
}
wasm {
browser() {
testTask {
useKarma {
standardConf()
}
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation("org.jetbrains.compose.runtime:runtime:1.3.0-rc01-SNAPSHOT")
//implementation(compose.runtime)
}
}
val jsMain by getting {
val commonTest by getting {
dependencies {
implementation(project(":test-utils"))
implementation(kotlin("test"))
}
}
val jsWasmMain by creating {
dependsOn(commonMain)
languageSettings {
optIn("org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi")
}
dependencies {
implementation(project(":internal-web-core-runtime"))
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect
}
}
val jsMain by getting {
languageSettings {
optIn("org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi")
}
dependsOn(jsWasmMain)
}
val wasmMain by getting {
languageSettings {
optIn("org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi")
}
dependsOn(jsWasmMain)
}
val jsTest by getting {
@ -40,16 +75,26 @@ kotlin {
optIn("org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi")
optIn("org.jetbrains.compose.web.testutils.ComposeWebExperimentalTestsApi")
}
dependencies {
implementation(project(":test-utils"))
implementation(kotlin("test-js"))
}
}
val jvmMain by getting {
dependencies {
implementation(compose.desktop.currentOs)
// val jvmMain by getting {
// dependencies {
// implementation("org.jetbrains.compose.desktop:desktop-jvm-macos-arm64")
// }
// }
}
}
project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xklib-enable-signature-clash-checks=false",
"-Xplugin=${project.properties["compose.plugin.path"]}"
)
}
project.afterEvaluate {
//Disable jsWasmMain intermediate sourceset publication
tasks.named("compileJsWasmMainKotlinMetadata") {
enabled = false
}
}

6
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSKeywords.kt

@ -3,10 +3,6 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@file:Suppress("NOTHING_TO_INLINE")
package org.jetbrains.compose.web.css
external interface CSSKeywordValue : CSSStyleValue
inline fun CSSKeywordValue(value: String): CSSKeywordValue = CSSStyleValue(value).unsafeCast<CSSKeywordValue>()
actual external interface CSSKeywordValue : CSSStyleValue

70
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt

@ -1,71 +1,3 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.css
operator fun <T: CSSUnit> CSSSizeValue<T>.times(num: Number): CSSSizeValue<T> = CSSUnitValueTyped(value * num.toFloat(), unit)
operator fun <T: CSSUnit> Number.times(unit: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(unit.value * toFloat(), unit.unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.div(num: Number): CSSSizeValue<T> = CSSUnitValueTyped(value / num.toFloat(), unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.plus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value + b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.minus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value - b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryMinus(): CSSSizeValue<T> = CSSUnitValueTyped(-value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryPlus(): CSSSizeValue<T> = CSSUnitValueTyped(value, unit)
external interface CSSCalcOperation<T : CSSUnit>: CSSNumericValue<T>
data class CSSCalcValue<T : CSSUnit>(
var op: CSSCalcOperation<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "calc$op"
}
private data class CSSPlus<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: CSSNumericValue<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "($l + $r)"
}
private data class CSSMinus<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: CSSNumericValue<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "($l - $r)"
}
private data class CSSTimes<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: Number,
val left: Boolean = true
) : CSSCalcOperation<T> {
override fun toString(): String = if (left) "($l * $r)" else "($r * $l)"
}
private data class CSSDiv<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: Number
) : CSSCalcOperation<T> {
override fun toString(): String = "($l / $r)"
}
operator fun <T: CSSUnit> CSSNumericValue<out T>.plus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.plus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<out T>.plus(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this, b.op))
operator fun <T: CSSUnit> CSSNumericValue<out T>.minus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.minus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<out T>.minus(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this, b.op))
operator fun <T: CSSUnit> CSSCalcValue<out T>.times(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSTimes(this.op, b))
operator fun <T: CSSUnit> Number.times(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSTimes(b.op, this, false))
operator fun <T: CSSUnit> CSSNumericValue<T>.div(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSDiv(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.div(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSDiv(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<T>.times(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSTimes(this, b))
operator fun <T: CSSUnit> Number.times(b: CSSNumericValue<T>): CSSCalcValue<T> = CSSCalcValue(CSSTimes(b, this, false))
actual external interface CSSCalcOperation<T : CSSUnit>: CSSNumericValue<T>

249
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSUnits.kt

@ -1,249 +1,8 @@
@file:Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName")
package org.jetbrains.compose.web.css
external interface CSSNumericValue<T : CSSUnit> : StylePropertyValue, CSSVariableValueAs<CSSNumericValue<T>>
external interface CSSSizeValue<T : CSSUnit> : CSSNumericValue<T> {
val value: Float
val unit: T
}
actual external interface CSSNumericValue<T : CSSUnit> : StylePropertyValue, CSSVariableValueAs<CSSNumericValue<T>>
data class CSSUnitValueTyped<T : CSSUnit>(
override val value: Float,
override val unit: T
) : CSSSizeValue<T> {
override fun toString(): String = "$value$unit"
actual external interface CSSSizeValue<T : CSSUnit> : CSSNumericValue<T> {
actual val value: Float
actual val unit: T
}
interface CSSUnitLengthOrPercentage: CSSUnit
interface CSSUnitPercentage: CSSUnitLengthOrPercentage
interface CSSUnitLength: CSSUnitLengthOrPercentage
interface CSSUnitRel : CSSUnitLength
interface CSSUnitAbs: CSSUnitLength
interface CSSUnitAngle: CSSUnit
interface CSSUnitTime: CSSUnit
interface CSSUnitFrequency: CSSUnit
interface CSSUnitResolution: CSSUnit
interface CSSUnitFlex: CSSUnit
typealias CSSAngleValue = CSSSizeValue<out CSSUnitAngle>
typealias CSSLengthOrPercentageValue = CSSSizeValue<out CSSUnitLengthOrPercentage>
typealias CSSLengthValue = CSSSizeValue<out CSSUnitLength>
typealias CSSPercentageValue = CSSSizeValue<out CSSUnitPercentage>
typealias CSSUnitValue = CSSSizeValue<out CSSUnit>
typealias CSSNumeric = CSSNumericValue<out CSSUnit>
typealias CSSpxValue = CSSSizeValue<CSSUnit.px>
// fake interfaces to distinguish units
interface CSSUnit {
interface percent: CSSUnitPercentage
interface em: CSSUnitRel
interface ex: CSSUnitRel
interface ch: CSSUnitRel
interface ic: CSSUnitRel
interface rem: CSSUnitRel
interface lh: CSSUnitRel
interface rlh: CSSUnitRel
interface vw: CSSUnitRel
interface vh: CSSUnitRel
interface vi: CSSUnitRel
interface vb: CSSUnitRel
interface vmin: CSSUnitRel
interface vmax: CSSUnitRel
interface cm: CSSUnitRel
interface mm: CSSUnitRel
interface Q: CSSUnitRel
interface pt: CSSUnitAbs
interface pc: CSSUnitAbs
interface px: CSSUnitAbs
interface deg: CSSUnitAngle
interface grad: CSSUnitAngle
interface rad: CSSUnitAngle
interface turn: CSSUnitAngle
interface s: CSSUnitTime
interface ms: CSSUnitTime
interface Hz: CSSUnitFrequency
interface kHz: CSSUnitFrequency
interface dpi: CSSUnitResolution
interface dpcm: CSSUnitResolution
interface dppx: CSSUnitResolution
interface fr: CSSUnitFlex
interface number: CSSUnit
companion object {
inline val percent get() = "%".unsafeCast<percent>()
inline val em get() = "em".unsafeCast<em>()
inline val ex get() = "ex".unsafeCast<ex>()
inline val ch get() = "ch".unsafeCast<ch>()
inline val ic get() = "ic".unsafeCast<ic>()
inline val rem get() = "rem".unsafeCast<rem>()
inline val lh get() = "lh".unsafeCast<lh>()
inline val rlh get() = "rlh".unsafeCast<rlh>()
inline val vw get() = "vw".unsafeCast<vw>()
inline val vh get() = "vh".unsafeCast<vh>()
inline val vi get() = "vi".unsafeCast<vi>()
inline val vb get() = "vb".unsafeCast<vb>()
inline val vmin get() = "vmin".unsafeCast<vmin>()
inline val vmax get() = "vmax".unsafeCast<vmax>()
inline val cm get() = "cm".unsafeCast<cm>()
inline val mm get() = "mm".unsafeCast<mm>()
inline val Q get() = "Q".unsafeCast<Q>()
inline val pt get() = "pt".unsafeCast<pt>()
inline val pc get() = "pc".unsafeCast<pc>()
inline val px get() = "px".unsafeCast<px>()
inline val deg get() = "deg".unsafeCast<deg>()
inline val grad get() = "grad".unsafeCast<grad>()
inline val rad get() = "rad".unsafeCast<rad>()
inline val turn get() = "turn".unsafeCast<turn>()
inline val s get() = "s".unsafeCast<s>()
inline val ms get() = "ms".unsafeCast<ms>()
inline val Hz get() = "Hz".unsafeCast<Hz>()
inline val kHz get() = "kHz".unsafeCast<kHz>()
inline val dpi get() = "dpi".unsafeCast<dpi>()
inline val dpcm get() = "dpcm".unsafeCast<dpcm>()
inline val dppx get() = "dppx".unsafeCast<dppx>()
inline val fr get() = "fr".unsafeCast<fr>()
inline val number get() = "number".unsafeCast<number>()
}
}
val Number.number
get(): CSSSizeValue<CSSUnit.number> = CSSUnitValueTyped(this.toFloat(), CSSUnit.number)
val Number.percent
get() : CSSSizeValue<CSSUnit.percent> = CSSUnitValueTyped(this.toFloat(), CSSUnit.percent)
val Number.em
get() : CSSSizeValue<CSSUnit.em> = CSSUnitValueTyped(this.toFloat(), CSSUnit.em)
val Number.ex
get(): CSSSizeValue<CSSUnit.ex> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ex)
val Number.ch
get(): CSSSizeValue<CSSUnit.ch> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ch)
val Number.cssRem
get(): CSSSizeValue<CSSUnit.rem> = CSSUnitValueTyped(this.toFloat(), CSSUnit.rem)
val Number.vw
get(): CSSSizeValue<CSSUnit.vw> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vw)
val Number.vh
get(): CSSSizeValue<CSSUnit.vh> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vh)
val Number.vmin
get(): CSSSizeValue<CSSUnit.vmin> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmin)
val Number.vmax
get(): CSSSizeValue<CSSUnit.vmax> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmax)
val Number.cm
get(): CSSSizeValue<CSSUnit.cm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.cm)
val Number.mm
get(): CSSSizeValue<CSSUnit.mm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.mm)
val Number.Q
get() : CSSSizeValue<CSSUnit.Q> = CSSUnitValueTyped(this.toFloat(), CSSUnit.Q)
val Number.pt
get(): CSSSizeValue<CSSUnit.pt> = CSSUnitValueTyped(this.toFloat(), CSSUnit.pt)
val Number.pc
get(): CSSSizeValue<CSSUnit.pc> = CSSUnitValueTyped(this.toFloat(), CSSUnit.pc)
val Number.px
get(): CSSSizeValue<CSSUnit.px> = CSSUnitValueTyped(this.toFloat(), CSSUnit.px)
val Number.deg
get(): CSSSizeValue<CSSUnit.deg> = CSSUnitValueTyped(this.toFloat(), CSSUnit.deg)
val Number.grad
get(): CSSSizeValue<CSSUnit.grad> = CSSUnitValueTyped(this.toFloat(), CSSUnit.grad)
val Number.rad
get(): CSSSizeValue<CSSUnit.rad> = CSSUnitValueTyped(this.toFloat(), CSSUnit.rad)
val Number.turn
get(): CSSSizeValue<CSSUnit.turn> = CSSUnitValueTyped(this.toFloat(), CSSUnit.turn)
val Number.s
get(): CSSSizeValue<CSSUnit.s> = CSSUnitValueTyped(this.toFloat(), CSSUnit.s)
val Number.ms
get(): CSSSizeValue<CSSUnit.ms> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ms)
val Number.Hz
get(): CSSSizeValue<CSSUnit.Hz> = CSSUnitValueTyped(this.toFloat(), CSSUnit.Hz)
val Number.kHz
get(): CSSSizeValue<CSSUnit.kHz> = CSSUnitValueTyped(this.toFloat(), CSSUnit.kHz)
val Number.dpi
get(): CSSSizeValue<CSSUnit.dpi> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpi)
val Number.dpcm
get(): CSSSizeValue<CSSUnit.dpcm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpcm)
val Number.dppx
get(): CSSSizeValue<CSSUnit.dppx> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dppx)
val Number.fr
get(): CSSSizeValue<CSSUnit.fr> = CSSUnitValueTyped(this.toFloat(), CSSUnit.fr)

197
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/Color.kt

@ -1,198 +1,3 @@
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
package org.jetbrains.compose.web.css
external interface CSSColorValue : StylePropertyValue, CSSVariableValueAs<CSSColorValue>
object Color {
@Deprecated("use org.jetbrains.compose.web.css.rgb", ReplaceWith("rgb(r, g, b)"))
data class RGB(val r: Number, val g: Number, val b: Number) : CSSColorValue {
override fun toString(): String = "rgb($r, $g, $b)"
}
@Deprecated("use org.jetbrains.compose.web.css.rgba", ReplaceWith("rgba(r, g, b, a)"))
data class RGBA(val r: Number, val g: Number, val b: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "rgba($r, $g, $b, $a)"
}
@Deprecated("use org.jetbrains.compose.web.css.hsl", ReplaceWith("hsl(h, s, l)"))
data class HSL(val h: CSSAngleValue, val s: Number, val l: Number) : CSSColorValue {
constructor(h: Number, s: Number, l: Number) : this(h.deg, s, l)
override fun toString(): String = "hsl($h, $s%, $l%)"
}
@Deprecated("use org.jetbrains.compose.web.css.hsla", ReplaceWith("hsla(h, s, l, a)"))
data class HSLA(val h: CSSAngleValue, val s: Number, val l: Number, val a: Number) : CSSColorValue {
constructor(h: Number, s: Number, l: Number, a: Number) : this(h.deg, s, l, a)
override fun toString(): String = "hsla($h, $s%, $l%, $a)"
}
inline val aliceblue get() = Color("aliceblue")
inline val antiquewhite get() = Color("antiquewhite")
inline val aquamarine get() = Color("aquamarine")
inline val azure get() = Color("azure")
inline val beige get() = Color("beige")
inline val bisque get() = Color("bisque")
inline val black get() = Color("black")
inline val blanchedalmond get() = Color("blanchedalmond")
inline val blue get() = Color("blue")
inline val blueviolet get() = Color("blueviolet")
inline val brown get() = Color("brown")
inline val burlywood get() = Color("burlywood")
inline val cadetblue get() = Color("cadetblue")
inline val chartreuse get() = Color("chartreuse")
inline val chocolate get() = Color("chocolate")
inline val cornflowerblue get() = Color("cornflowerblue")
inline val cornsilk get() = Color("cornsilk")
inline val crimson get() = Color("crimson")
inline val cyan get() = Color("cyan")
inline val darkblue get() = Color("darkblue")
inline val darkcyan get() = Color("darkcyan")
inline val darkgoldenrod get() = Color("darkgoldenrod")
inline val darkgray get() = Color("darkgray")
inline val darkgreen get() = Color("darkgreen")
inline val darkkhaki get() = Color("darkkhaki")
inline val darkmagenta get() = Color("darkmagenta")
inline val darkolivegreen get() = Color("darkolivegreen")
inline val darkorange get() = Color("darkorange")
inline val darkorchid get() = Color("darkorchid")
inline val darkred get() = Color("darkred")
inline val darksalmon get() = Color("darksalmon")
inline val darkslateblue get() = Color("darkslateblue")
inline val darkslategray get() = Color("darkslategray")
inline val darkturquoise get() = Color("darkturquoise")
inline val darkviolet get() = Color("darkviolet")
inline val deeppink get() = Color("deeppink")
inline val deepskyblue get() = Color("deepskyblue")
inline val dimgray get() = Color("dimgray")
inline val dodgerblue get() = Color("dodgerblue")
inline val firebrick get() = Color("firebrick")
inline val floralwhite get() = Color("floralwhite")
inline val forestgreen get() = Color("forestgreen")
inline val fuchsia get() = Color("fuchsia")
inline val gainsboro get() = Color("gainsboro")
inline val ghostwhite get() = Color("ghostwhite")
inline val goldenrod get() = Color("goldenrod")
inline val gold get() = Color("gold")
inline val gray get() = Color("gray")
inline val green get() = Color("green")
inline val greenyellow get() = Color("greenyellow")
inline val honeydew get() = Color("honeydew")
inline val hotpink get() = Color("hotpink")
inline val indianred get() = Color("indianred")
inline val indigo get() = Color("indigo")
inline val ivory get() = Color("ivory")
inline val khaki get() = Color("khaki")
inline val lavenderblush get() = Color("lavenderblush")
inline val lavender get() = Color("lavender")
inline val lawngreen get() = Color("lawngreen")
inline val lemonchiffon get() = Color("lemonchiffon")
inline val lightblue get() = Color("lightblue")
inline val lightcoral get() = Color("lightcoral")
inline val lightcyan get() = Color("lightcyan")
inline val lightgoldenrodyellow get() = Color("lightgoldenrodyellow")
inline val lightgray get() = Color("lightgray")
inline val lightgreen get() = Color("lightgreen")
inline val lightpink get() = Color("lightpink")
inline val lightsalmon get() = Color("lightsalmon")
inline val lightseagreen get() = Color("lightseagreen")
inline val lightskyblue get() = Color("lightskyblue")
inline val lightslategray get() = Color("lightslategray")
inline val lightsteelblue get() = Color("lightsteelblue")
inline val lightyellow get() = Color("lightyellow")
inline val limegreen get() = Color("limegreen")
inline val lime get() = Color("lime")
inline val linen get() = Color("linen")
inline val magenta get() = Color("magenta")
inline val maroon get() = Color("maroon")
inline val mediumaquamarine get() = Color("mediumaquamarine")
inline val mediumblue get() = Color("mediumblue")
inline val mediumorchid get() = Color("mediumorchid")
inline val mediumpurple get() = Color("mediumpurple")
inline val mediumseagreen get() = Color("mediumseagreen")
inline val mediumslateblue get() = Color("mediumslateblue")
inline val mediumspringgreen get() = Color("mediumspringgreen")
inline val mediumturquoise get() = Color("mediumturquoise")
inline val mediumvioletred get() = Color("mediumvioletred")
inline val midnightblue get() = Color("midnightblue")
inline val mintcream get() = Color("mintcream")
inline val mistyrose get() = Color("mistyrose")
inline val moccasin get() = Color("moccasin")
inline val navajowhite get() = Color("navajowhite")
inline val navi get() = Color("navi")
inline val oldlace get() = Color("oldlace")
inline val olivedrab get() = Color("olivedrab")
inline val olive get() = Color("olive")
inline val orange get() = Color("orange")
inline val orangered get() = Color("orangered")
inline val orchid get() = Color("orchid")
inline val palegoldenrod get() = Color("palegoldenrod")
inline val palegreen get() = Color("palegreen")
inline val paleturquoise get() = Color("paleturquoise")
inline val palevioletred get() = Color("palevioletred")
inline val papayawhip get() = Color("papayawhip")
inline val peachpuff get() = Color("peachpuff")
inline val peru get() = Color("peru")
inline val pink get() = Color("pink")
inline val plum get() = Color("plum")
inline val powderblue get() = Color("powderblue")
inline val purple get() = Color("purple")
inline val rebeccapurple get() = Color("rebeccapurple")
inline val red get() = Color("red")
inline val rosybrown get() = Color("rosybrown")
inline val royalblue get() = Color("royalblue")
inline val saddlebrown get() = Color("saddlebrown")
inline val salmon get() = Color("salmon")
inline val sandybrown get() = Color("sandybrown")
inline val seagreen get() = Color("seagreen")
inline val seashell get() = Color("seashell")
inline val sienna get() = Color("sienna")
inline val silver get() = Color("silver")
inline val skyblue get() = Color("skyblue")
inline val slateblue get() = Color("slateblue")
inline val slategray get() = Color("slategray")
inline val snow get() = Color("snow")
inline val springgreen get() = Color("springgreen")
inline val steelblue get() = Color("steelblue")
inline val teal get() = Color("teal")
inline val thistle get() = Color("thistle")
inline val tomato get() = Color("tomato")
inline val turquoise get() = Color("turquoise")
inline val violet get() = Color("violet")
inline val wheat get() = Color("wheat")
inline val white get() = Color("white")
inline val whitesmoke get() = Color("whitesmoke")
inline val yellowgreen get() = Color("yellowgreen")
inline val yellow get() = Color("yellow")
inline val transparent get() = Color("transparent")
inline val currentColor get() = Color("currentColor")
}
fun Color(name: String): CSSColorValue = name.unsafeCast<CSSColorValue>()
private class RGB(val r: Number, val g: Number, val b: Number): CSSColorValue {
override fun toString(): String = "rgb($r, $g, $b)"
}
private class RGBA(val r: Number, val g: Number, val b: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "rgba($r, $g, $b, $a)"
}
private class HSL(val h: CSSAngleValue, val s: Number, val l: Number) : CSSColorValue {
override fun toString(): String = "hsl($h, $s%, $l%)"
}
private class HSLA(val h: CSSAngleValue, val s: Number, val l: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "hsla($h, $s%, $l%, $a)"
}
fun rgb(r: Number, g: Number, b: Number): CSSColorValue = RGB(r, g, b)
fun rgba(r: Number, g: Number, b: Number, a: Number): CSSColorValue = RGBA(r, g, b, a)
fun hsl(h: CSSAngleValue, s: Number, l: Number): CSSColorValue = HSL(h, s, l)
fun hsl(h: Number, s: Number, l: Number): CSSColorValue = HSL(h.deg, s, l)
fun hsla(h: CSSAngleValue, s: Number, l: Number, a: Number): CSSColorValue = HSLA(h, s, l, a)
fun hsla(h: Number, s: Number, l: Number, a: Number): CSSColorValue = HSLA(h.deg, s, l, a)
actual external interface CSSColorValue : StylePropertyValue, CSSVariableValueAs<CSSColorValue>

15
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyValue.kt

@ -6,16 +6,11 @@
@file:Suppress("UNUSED", "NOTHING_TO_INLINE", "FunctionName")
package org.jetbrains.compose.web.css
external interface StylePropertyValue
actual external interface StylePropertyValue
external interface StylePropertyNumber: StylePropertyValue
external interface StylePropertyString: StylePropertyValue
actual external interface StylePropertyNumber: StylePropertyValue
actual external interface StylePropertyString: StylePropertyValue
inline fun StylePropertyValue(value: String): StylePropertyString = value.unsafeCast<StylePropertyString>()
inline fun StylePropertyValue(value: Number): StylePropertyNumber = value.unsafeCast<StylePropertyNumber>()
external interface CSSStyleValue: StylePropertyValue {
override fun toString(): String
actual external interface CSSStyleValue: StylePropertyValue {
actual override fun toString(): String
}
inline fun CSSStyleValue(value: String): CSSStyleValue = StylePropertyValue(value).unsafeCast<CSSStyleValue>()

194
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StyleScope.kt

@ -1,195 +1,3 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@file:Suppress("NOTHING_TO_INLINE", "unused")
package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.attributes.HtmlAttrMarker
import org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi
import kotlin.properties.ReadOnlyProperty
@Deprecated(
message = "Renamed to StyleScope",
replaceWith = ReplaceWith("StyleScope", "org.jetbrains.compose.web.css.StyleScope")
)
typealias StyleBuilder = StyleScope
/**
* StyleScope serves for two main purposes. Passed as a builder context (in [AttrsScope]), it
* makes it possible to:
* 1. Add inlined css properties to the element (@see [property])
* 2. Set values to CSS variables (@see [variable])
*/
@HtmlAttrMarker
interface StyleScope {
/**
* Adds arbitrary CSS property to the inline style of the element
* @param propertyName - the name of css property as [per spec](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference)
* @param value - the value, it can be either String or specialized type like [CSSNumeric] or [CSSColorValue]
*
* Most frequent CSS property values can be set via specialized methods, like [width], [display] etc.
*
* Example:
* ```
* Div({
* style {
* property("some-exotic-css-property", "I am a string value")
* property("some-exotic-css-property-width", 5.px)
* }
* })
* ```
*/
fun property(propertyName: String, value: StylePropertyValue)
fun variable(variableName: String, value: StylePropertyValue)
fun property(propertyName: String, value: String) = property(propertyName, StylePropertyValue(value))
fun property(propertyName: String, value: Number) = property(propertyName, StylePropertyValue(value))
fun variable(variableName: String, value: String) = variable(variableName, StylePropertyValue(value))
fun variable(variableName: String, value: Number) = variable(variableName, StylePropertyValue(value))
operator fun <TValue : StylePropertyValue> CSSStyleVariable<TValue>.invoke(value: TValue) {
variable(name, value.toString())
}
operator fun CSSStyleVariable<StylePropertyString>.invoke(value: String) {
variable(name, value)
}
operator fun CSSStyleVariable<StylePropertyNumber>.invoke(value: Number) {
variable(name, value)
}
}
internal inline fun variableValue(variableName: String, fallback: StylePropertyValue? = null) =
"var(--$variableName${fallback?.let { ", $it" } ?: ""})"
external interface CSSVariableValueAs<out T : StylePropertyValue>
inline fun <TValue> CSSVariableValue(value: StylePropertyValue) =
value.unsafeCast<TValue>()
inline fun <TValue> CSSVariableValue(value: String) =
CSSVariableValue<TValue>(StylePropertyValue(value))
// after adding `variable` word `add` became ambiguous
@Deprecated(
"use property instead, will remove it soon",
ReplaceWith("property(propertyName, value)")
)
fun StyleScope.add(
propertyName: String,
value: StylePropertyValue
) = property(propertyName, value)
interface CSSVariable {
val name: String
}
class CSSStyleVariable<out TValue : StylePropertyValue>(override val name: String) : CSSVariable
fun <TValue : StylePropertyValue> CSSStyleVariable<TValue>.value(fallback: TValue? = null) =
CSSVariableValue<TValue>(
variableValue(
name,
fallback
)
)
fun <TValue> CSSStyleVariable<TValue>.value(fallback: TValue? = null)
where TValue : CSSVariableValueAs<TValue>,
TValue : StylePropertyValue =
CSSVariableValue<TValue>(
variableValue(
name,
fallback
)
)
/**
* Introduces CSS variable that can be later referred anywhere in [StyleSheet]
*
* Example:
* ```
* object AppCSSVariables {
* val width by variable<CSSUnitValue>()
* val stringHeight by variable<StylePropertyString>()
* val order by variable<StylePropertyNumber>()
* }
*
* object AppStylesheet : StyleSheet() {
* val classWithProperties by style {
* AppCSSVariables.width(100.px)
* property("width", AppCSSVariables.width.value())
* }
*```
*
*/
fun <TValue : StylePropertyValue> variable() =
ReadOnlyProperty<Any?, CSSStyleVariable<TValue>> { _, property ->
CSSStyleVariable(property.name)
}
interface StyleHolder {
@ComposeWebInternalApi
val properties: StylePropertyList
@ComposeWebInternalApi
val variables: StylePropertyList
}
@Deprecated(
message = "Renamed to StyleScopeBuilder",
replaceWith = ReplaceWith("StyleScopeBuilder", "org.jetbrains.compose.web.css.StyleScopeBuilder")
)
typealias StyleBuilderImpl = StyleScopeBuilder
@Suppress("EqualsOrHashCode")
open class StyleScopeBuilder : StyleScope, StyleHolder {
override val properties: MutableStylePropertyList = mutableListOf()
override val variables: MutableStylePropertyList = mutableListOf()
override fun property(propertyName: String, value: StylePropertyValue) {
properties.add(StylePropertyDeclaration(propertyName, value))
}
override fun variable(variableName: String, value: StylePropertyValue) {
variables.add(StylePropertyDeclaration(variableName, value))
}
// StylePropertyValue is js native object without equals
override fun equals(other: Any?): Boolean {
return if (other is StyleHolder) {
properties.nativeEquals(other.properties) &&
variables.nativeEquals(other.variables)
} else false
}
@ComposeWebInternalApi
internal fun copyFrom(sb: StyleHolder) {
properties.addAll(sb.properties)
variables.addAll(sb.variables)
}
}
data class StylePropertyDeclaration(
val name: String,
val value: StylePropertyValue
) {
constructor(name: String, value: String) : this(name, value.unsafeCast<StylePropertyValue>())
constructor(name: String, value: Number) : this(name, value.unsafeCast<StylePropertyValue>())
}
typealias StylePropertyList = List<StylePropertyDeclaration>
typealias MutableStylePropertyList = MutableList<StylePropertyDeclaration>
internal fun StylePropertyList.nativeEquals(properties: StylePropertyList): Boolean {
if (this.size != properties.size) return false
var index = 0
return all { prop ->
val otherProp = properties[index++]
prop.name == otherProp.name &&
prop.value.toString() == otherProp.value.toString()
}
}
actual external interface CSSVariableValueAs<out T : StylePropertyValue>

6
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/keywords/Keywords.kt

@ -7,8 +7,4 @@ package org.jetbrains.compose.web.css.keywords
import org.jetbrains.compose.web.css.CSSKeywordValue
external interface CSSAutoKeyword : CSSKeywordValue
inline val auto: CSSAutoKeyword
get() = CSSKeywordValue("auto").unsafeCast<CSSAutoKeyword>()
actual external interface CSSAutoKeyword : CSSKeywordValue

54
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/w3cExtensions.kt

@ -0,0 +1,54 @@
package org.jetbrains.compose.web
import org.w3c.dom.events.*
import org.w3c.dom.css.CSSRule
import androidx.compose.web.events.*
import org.jetbrains.compose.web.css.CSSStyleValue
import org.w3c.dom.HTMLElement
import org.w3c.dom.svg.SVGElement
import org.jetbrains.compose.web.css.StylePropertyValue
import org.jetbrains.compose.web.dom.RadioGroupScope
import org.jetbrains.compose.web.dom.ElementBuilder
import org.w3c.dom.Element
@PublishedApi
internal actual fun <T> SyntheticEvent<*>.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> CSSRule.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> CSSStyleValue.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> Event.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> EventTarget.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> String.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> Number.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> HTMLElement.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> SVGElement.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> StylePropertyValue.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
@ExperimentalComposeWebApi
internal actual fun <T> RadioGroupScope<*>.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun <T> ElementBuilder<*>.unsafeCast(): T = asDynamic().unsafeCast<T>()
@PublishedApi
internal actual fun Any.unsafeCastBoolean(): Boolean = asDynamic().unsafeCast<Boolean>()
@PublishedApi
internal actual fun Any.unsafeCastString(): String = asDynamic().unsafeCast<String>()
@PublishedApi
internal actual fun Any.getStringProperty(name: String): String? = asDynamic()[name] as String?
@PublishedApi
internal actual fun Any.getBooleanProperty(name: String): Boolean? = asDynamic()[name] as Boolean?
@PublishedApi
internal actual fun Any.getIntProperty(name: String): Int? = asDynamic()[name] as Int?
@PublishedApi
internal actual fun <T> Any.getAnyProperty(name: String): T = asDynamic()[name].unsafeCast<T>()
internal actual fun Element.getAttributeNamesWorkaround(): Array<String> = getAttributeNames()

1
web/core/src/jsTest/kotlin/css/GridTests.kt

@ -8,6 +8,7 @@ package org.jetbrains.compose.web.core.tests.css
import org.jetbrains.compose.web.testutils.*
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.dom.Div
import org.w3c.dom.css.*
import kotlin.test.Test
import kotlin.test.assertEquals

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebApi.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebApi.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebStyleApi.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebStyleApi.kt

7
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/Attrs.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/Attrs.kt

@ -16,6 +16,7 @@ import org.w3c.dom.HTMLSelectElement
import org.w3c.dom.HTMLTableCellElement
import org.w3c.dom.HTMLTableColElement
import org.w3c.dom.HTMLTextAreaElement
import org.jetbrains.compose.web.*
fun AttrsScope<HTMLAnchorElement>.href(value: String) =
attr("href", value)
@ -120,7 +121,7 @@ fun AttrsScope<HTMLInputElement>.alt(value: String) =
attr("alt", value) // type: image only
fun AttrsScope<HTMLInputElement>.autoComplete(value: AutoComplete) =
attr("autocomplete", value.unsafeCast<String>())
attr("autocomplete", value.unsafeCastString())
fun AttrsScope<HTMLInputElement>.autoFocus() =
attr("autofocus", "")
@ -231,7 +232,7 @@ fun AttrsScope<HTMLOptionElement>.label(value: String) =
/* Select attributes */
fun AttrsScope<HTMLSelectElement>.autoComplete(value: AutoComplete) =
attr("autocomplete", value.unsafeCast<String>())
attr("autocomplete", value.unsafeCastString())
fun AttrsScope<HTMLSelectElement>.autofocus() =
attr("autofocus", "")
@ -265,7 +266,7 @@ fun AttrsScope<HTMLOptGroupElement>.disabled() =
/* TextArea attributes */
fun AttrsScope<HTMLTextAreaElement>.autoComplete(value: AutoComplete) =
attr("autocomplete", value.unsafeCast<String>())
attr("autocomplete", value.unsafeCastString())
fun AttrsScope<HTMLTextAreaElement>.autoFocus() =
attr("autofocus", "")

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/AttrsScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/AttrsScope.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/EventsListenerScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/EventsListenerScope.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/HtmlAttrMarker.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/HtmlAttrMarker.kt

7
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/PredefinedAttrValues.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/PredefinedAttrValues.kt

@ -1,6 +1,7 @@
package org.jetbrains.compose.web.attributes
import org.w3c.dom.events.Event
import org.jetbrains.compose.web.*
sealed class InputType<T>(val typeStr: String) {
@ -35,20 +36,20 @@ sealed class InputType<T>(val typeStr: String) {
open class InputTypeCheckedValue(name: String) : InputType<Boolean>(name) {
override fun inputValue(event: Event): Boolean {
return event.target?.asDynamic()?.checked?.unsafeCast<Boolean>() ?: false
return event.target?.getBooleanProperty("checked") ?: false
}
}
open class InputTypeNumberValue(name: String) : InputType<kotlin.Number?>(name) {
override fun inputValue(event: Event): kotlin.Number? {
return event.target?.asDynamic()?.valueAsNumber ?: null
return event.target?.getAnyProperty<kotlin.Number>("valueAsNumber")
}
}
abstract fun inputValue(event: Event): T
protected fun valueAsString(event: Event): String {
return event.target?.asDynamic()?.value?.unsafeCast<String>() ?: ""
return event.target?.getStringProperty("value") ?: ""
}
companion object {

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/SyntheticEventListener.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/SyntheticEventListener.kt

@ -15,6 +15,8 @@ import org.w3c.dom.DragEvent
import org.w3c.dom.TouchEvent
import org.w3c.dom.clipboard.ClipboardEvent
import org.w3c.dom.events.*
import org.jetbrains.compose.web.*
import org.jetbrains.compose.web.internal.runtime.EventListener
@OptIn(ComposeWebInternalApi::class)
open class SyntheticEventListener<T : SyntheticEvent<*>> internal constructor(
@ -135,7 +137,7 @@ internal class SelectEventListener<Target: EventTarget>(
SELECT, listener
) {
override fun handleEvent(event: Event) {
listener(SyntheticSelectEvent(event, event.target.unsafeCast<SelectionInfoDetails>()))
listener(SyntheticSelectEvent(event, event.target!!.unsafeCast<SelectionInfoDetails>()))
}
}

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/builders/InputAttrsScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/InputAttrsScope.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/builders/InternalControlledInputUtils.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/InternalControlledInputUtils.kt

5
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/builders/SelectAttrsScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/SelectAttrsScope.kt

@ -13,6 +13,7 @@ import org.jetbrains.compose.web.events.SyntheticChangeEvent
import org.jetbrains.compose.web.events.SyntheticInputEvent
import org.w3c.dom.HTMLSelectElement
import org.w3c.dom.events.Event
import org.jetbrains.compose.web.*
@Deprecated(
message = "Renamed to SelectAttrsScope",
@ -42,7 +43,7 @@ private class SelectInputEventListener(
eventName, listener
) {
override fun handleEvent(event: Event) {
val value = event.target?.asDynamic().value?.toString()
val value = event.target?.getAnyProperty<Any>("value").toString()
listener(SyntheticInputEvent(value, event))
}
}
@ -53,7 +54,7 @@ private class SelectChangeEventListener(
CHANGE, listener
) {
override fun handleEvent(event: Event) {
val value = event.target?.asDynamic().value?.toString()
val value = event.target?.getAnyProperty<Any>("value").toString()
listener(SyntheticChangeEvent(value, event))
}
}

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/builders/TextAreaAttrsScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/attributes/builders/TextAreaAttrsScope.kt

7
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/BrowserAPI.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/BrowserAPI.kt

@ -13,15 +13,12 @@ import org.w3c.dom.css.CSSRuleList
internal external class CSSKeyframesRule: CSSRule {
val name: String
val cssRules: CSSRuleList
}
internal inline fun CSSKeyframesRule.appendRule(cssRule: String) {
this.asDynamic().appendRule(cssRule)
internal fun appendRule(cssRule: String)
}
@Suppress("NOTHING_TO_INLINE")
internal inline fun <T : Any> jsObject(): T =
js("({})")
js("({})") as T
internal inline fun <T : Any> jsObject(builder: T.() -> Unit): T =
jsObject<T>().apply(builder)

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSBuilder.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSBuilder.kt

6
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt

@ -2,9 +2,11 @@
package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.*
interface StylePropertyEnum: StylePropertyString
inline val StylePropertyEnum.name get() = this.unsafeCast<String>()
inline val StylePropertyEnum.value get() = this.unsafeCast<String>()
inline val StylePropertyEnum.name get() = this.unsafeCastString()
inline val StylePropertyEnum.value get() = this.unsafeCastString()
interface LineStyle: StylePropertyEnum {
companion object {

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSKeyframeRule.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSKeyframeRule.kt

14
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSKeywords.kt

@ -0,0 +1,14 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@file:Suppress("NOTHING_TO_INLINE")
package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.*
expect interface CSSKeywordValue : CSSStyleValue
inline fun CSSKeywordValue(value: String): CSSKeywordValue = CSSStyleValue(value).unsafeCast<CSSKeywordValue>()

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSMediaRule.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSMediaRule.kt

71
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt

@ -0,0 +1,71 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.css
operator fun <T: CSSUnit> CSSSizeValue<T>.times(num: Number): CSSSizeValue<T> = CSSUnitValueTyped(value * num.toFloat(), unit)
operator fun <T: CSSUnit> Number.times(unit: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(unit.value * toFloat(), unit.unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.div(num: Number): CSSSizeValue<T> = CSSUnitValueTyped(value / num.toFloat(), unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.plus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value + b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.minus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value - b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryMinus(): CSSSizeValue<T> = CSSUnitValueTyped(-value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryPlus(): CSSSizeValue<T> = CSSUnitValueTyped(value, unit)
expect interface CSSCalcOperation<T : CSSUnit>: CSSNumericValue<T>
data class CSSCalcValue<T : CSSUnit>(
var op: CSSCalcOperation<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "calc$op"
}
private data class CSSPlus<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: CSSNumericValue<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "($l + $r)"
}
private data class CSSMinus<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: CSSNumericValue<out T>
) : CSSCalcOperation<T> {
override fun toString(): String = "($l - $r)"
}
private data class CSSTimes<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: Number,
val left: Boolean = true
) : CSSCalcOperation<T> {
override fun toString(): String = if (left) "($l * $r)" else "($r * $l)"
}
private data class CSSDiv<T : CSSUnit>(
var l: CSSNumericValue<out T>,
var r: Number
) : CSSCalcOperation<T> {
override fun toString(): String = "($l / $r)"
}
operator fun <T: CSSUnit> CSSNumericValue<out T>.plus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.plus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<out T>.plus(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSPlus(this, b.op))
operator fun <T: CSSUnit> CSSNumericValue<out T>.minus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.minus(b: CSSNumericValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<out T>.minus(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSMinus(this, b.op))
operator fun <T: CSSUnit> CSSCalcValue<out T>.times(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSTimes(this.op, b))
operator fun <T: CSSUnit> Number.times(b: CSSCalcValue<out T>): CSSCalcValue<T> = CSSCalcValue(CSSTimes(b.op, this, false))
operator fun <T: CSSUnit> CSSNumericValue<T>.div(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSDiv(this, b))
operator fun <T: CSSUnit> CSSCalcValue<out T>.div(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSDiv(this.op, b))
operator fun <T: CSSUnit> CSSNumericValue<T>.times(b: Number): CSSCalcValue<T> = CSSCalcValue(CSSTimes(this, b))
operator fun <T: CSSUnit> Number.times(b: CSSNumericValue<T>): CSSCalcValue<T> = CSSCalcValue(CSSTimes(b, this, false))

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt

249
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/CSSUnits.kt

@ -0,0 +1,249 @@
@file:Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName")
package org.jetbrains.compose.web.css
expect interface CSSNumericValue<T : CSSUnit> : StylePropertyValue, CSSVariableValueAs<CSSNumericValue<T>>
expect interface CSSSizeValue<T : CSSUnit> : CSSNumericValue<T> {
val value: Float
val unit: T
}
data class CSSUnitValueTyped<T : CSSUnit>(
override val value: Float,
override val unit: T
) : CSSSizeValue<T> {
override fun toString(): String = "$value$unit"
}
interface CSSUnitLengthOrPercentage: CSSUnit
interface CSSUnitPercentage: CSSUnitLengthOrPercentage
interface CSSUnitLength: CSSUnitLengthOrPercentage
interface CSSUnitRel : CSSUnitLength
interface CSSUnitAbs: CSSUnitLength
interface CSSUnitAngle: CSSUnit
interface CSSUnitTime: CSSUnit
interface CSSUnitFrequency: CSSUnit
interface CSSUnitResolution: CSSUnit
interface CSSUnitFlex: CSSUnit
typealias CSSAngleValue = CSSSizeValue<out CSSUnitAngle>
typealias CSSLengthOrPercentageValue = CSSSizeValue<out CSSUnitLengthOrPercentage>
typealias CSSLengthValue = CSSSizeValue<out CSSUnitLength>
typealias CSSPercentageValue = CSSSizeValue<out CSSUnitPercentage>
typealias CSSUnitValue = CSSSizeValue<out CSSUnit>
typealias CSSNumeric = CSSNumericValue<out CSSUnit>
typealias CSSpxValue = CSSSizeValue<CSSUnit.px>
// fake interfaces to distinguish units
interface CSSUnit {
interface percent: CSSUnitPercentage
interface em: CSSUnitRel
interface ex: CSSUnitRel
interface ch: CSSUnitRel
interface ic: CSSUnitRel
interface rem: CSSUnitRel
interface lh: CSSUnitRel
interface rlh: CSSUnitRel
interface vw: CSSUnitRel
interface vh: CSSUnitRel
interface vi: CSSUnitRel
interface vb: CSSUnitRel
interface vmin: CSSUnitRel
interface vmax: CSSUnitRel
interface cm: CSSUnitRel
interface mm: CSSUnitRel
interface Q: CSSUnitRel
interface pt: CSSUnitAbs
interface pc: CSSUnitAbs
interface px: CSSUnitAbs
interface deg: CSSUnitAngle
interface grad: CSSUnitAngle
interface rad: CSSUnitAngle
interface turn: CSSUnitAngle
interface s: CSSUnitTime
interface ms: CSSUnitTime
interface Hz: CSSUnitFrequency
interface kHz: CSSUnitFrequency
interface dpi: CSSUnitResolution
interface dpcm: CSSUnitResolution
interface dppx: CSSUnitResolution
interface fr: CSSUnitFlex
interface number: CSSUnit
companion object {
inline val percent get() = "%".unsafeCast<percent>()
inline val em get() = "em".unsafeCast<em>()
inline val ex get() = "ex".unsafeCast<ex>()
inline val ch get() = "ch".unsafeCast<ch>()
inline val ic get() = "ic".unsafeCast<ic>()
inline val rem get() = "rem".unsafeCast<rem>()
inline val lh get() = "lh".unsafeCast<lh>()
inline val rlh get() = "rlh".unsafeCast<rlh>()
inline val vw get() = "vw".unsafeCast<vw>()
inline val vh get() = "vh".unsafeCast<vh>()
inline val vi get() = "vi".unsafeCast<vi>()
inline val vb get() = "vb".unsafeCast<vb>()
inline val vmin get() = "vmin".unsafeCast<vmin>()
inline val vmax get() = "vmax".unsafeCast<vmax>()
inline val cm get() = "cm".unsafeCast<cm>()
inline val mm get() = "mm".unsafeCast<mm>()
inline val Q get() = "Q".unsafeCast<Q>()
inline val pt get() = "pt".unsafeCast<pt>()
inline val pc get() = "pc".unsafeCast<pc>()
inline val px get() = "px".unsafeCast<px>()
inline val deg get() = "deg".unsafeCast<deg>()
inline val grad get() = "grad".unsafeCast<grad>()
inline val rad get() = "rad".unsafeCast<rad>()
inline val turn get() = "turn".unsafeCast<turn>()
inline val s get() = "s".unsafeCast<s>()
inline val ms get() = "ms".unsafeCast<ms>()
inline val Hz get() = "Hz".unsafeCast<Hz>()
inline val kHz get() = "kHz".unsafeCast<kHz>()
inline val dpi get() = "dpi".unsafeCast<dpi>()
inline val dpcm get() = "dpcm".unsafeCast<dpcm>()
inline val dppx get() = "dppx".unsafeCast<dppx>()
inline val fr get() = "fr".unsafeCast<fr>()
inline val number get() = "number".unsafeCast<number>()
}
}
val Number.number
get(): CSSSizeValue<CSSUnit.number> = CSSUnitValueTyped(this.toFloat(), CSSUnit.number)
val Number.percent
get() : CSSSizeValue<CSSUnit.percent> = CSSUnitValueTyped(this.toFloat(), CSSUnit.percent)
val Number.em
get() : CSSSizeValue<CSSUnit.em> = CSSUnitValueTyped(this.toFloat(), CSSUnit.em)
val Number.ex
get(): CSSSizeValue<CSSUnit.ex> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ex)
val Number.ch
get(): CSSSizeValue<CSSUnit.ch> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ch)
val Number.cssRem
get(): CSSSizeValue<CSSUnit.rem> = CSSUnitValueTyped(this.toFloat(), CSSUnit.rem)
val Number.vw
get(): CSSSizeValue<CSSUnit.vw> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vw)
val Number.vh
get(): CSSSizeValue<CSSUnit.vh> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vh)
val Number.vmin
get(): CSSSizeValue<CSSUnit.vmin> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmin)
val Number.vmax
get(): CSSSizeValue<CSSUnit.vmax> = CSSUnitValueTyped(this.toFloat(), CSSUnit.vmax)
val Number.cm
get(): CSSSizeValue<CSSUnit.cm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.cm)
val Number.mm
get(): CSSSizeValue<CSSUnit.mm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.mm)
val Number.Q
get() : CSSSizeValue<CSSUnit.Q> = CSSUnitValueTyped(this.toFloat(), CSSUnit.Q)
val Number.pt
get(): CSSSizeValue<CSSUnit.pt> = CSSUnitValueTyped(this.toFloat(), CSSUnit.pt)
val Number.pc
get(): CSSSizeValue<CSSUnit.pc> = CSSUnitValueTyped(this.toFloat(), CSSUnit.pc)
val Number.px
get(): CSSSizeValue<CSSUnit.px> = CSSUnitValueTyped(this.toFloat(), CSSUnit.px)
val Number.deg
get(): CSSSizeValue<CSSUnit.deg> = CSSUnitValueTyped(this.toFloat(), CSSUnit.deg)
val Number.grad
get(): CSSSizeValue<CSSUnit.grad> = CSSUnitValueTyped(this.toFloat(), CSSUnit.grad)
val Number.rad
get(): CSSSizeValue<CSSUnit.rad> = CSSUnitValueTyped(this.toFloat(), CSSUnit.rad)
val Number.turn
get(): CSSSizeValue<CSSUnit.turn> = CSSUnitValueTyped(this.toFloat(), CSSUnit.turn)
val Number.s
get(): CSSSizeValue<CSSUnit.s> = CSSUnitValueTyped(this.toFloat(), CSSUnit.s)
val Number.ms
get(): CSSSizeValue<CSSUnit.ms> = CSSUnitValueTyped(this.toFloat(), CSSUnit.ms)
val Number.Hz
get(): CSSSizeValue<CSSUnit.Hz> = CSSUnitValueTyped(this.toFloat(), CSSUnit.Hz)
val Number.kHz
get(): CSSSizeValue<CSSUnit.kHz> = CSSUnitValueTyped(this.toFloat(), CSSUnit.kHz)
val Number.dpi
get(): CSSSizeValue<CSSUnit.dpi> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpi)
val Number.dpcm
get(): CSSSizeValue<CSSUnit.dpcm> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dpcm)
val Number.dppx
get(): CSSSizeValue<CSSUnit.dppx> = CSSUnitValueTyped(this.toFloat(), CSSUnit.dppx)
val Number.fr
get(): CSSSizeValue<CSSUnit.fr> = CSSUnitValueTyped(this.toFloat(), CSSUnit.fr)

198
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/Color.kt

@ -0,0 +1,198 @@
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
package org.jetbrains.compose.web.css
expect interface CSSColorValue : StylePropertyValue, CSSVariableValueAs<CSSColorValue>
object Color {
@Deprecated("use org.jetbrains.compose.web.css.rgb", ReplaceWith("rgb(r, g, b)"))
data class RGB(val r: Number, val g: Number, val b: Number) : CSSColorValue {
override fun toString(): String = "rgb($r, $g, $b)"
}
@Deprecated("use org.jetbrains.compose.web.css.rgba", ReplaceWith("rgba(r, g, b, a)"))
data class RGBA(val r: Number, val g: Number, val b: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "rgba($r, $g, $b, $a)"
}
@Deprecated("use org.jetbrains.compose.web.css.hsl", ReplaceWith("hsl(h, s, l)"))
data class HSL(val h: CSSAngleValue, val s: Number, val l: Number) : CSSColorValue {
constructor(h: Number, s: Number, l: Number) : this(h.deg, s, l)
override fun toString(): String = "hsl($h, $s%, $l%)"
}
@Deprecated("use org.jetbrains.compose.web.css.hsla", ReplaceWith("hsla(h, s, l, a)"))
data class HSLA(val h: CSSAngleValue, val s: Number, val l: Number, val a: Number) : CSSColorValue {
constructor(h: Number, s: Number, l: Number, a: Number) : this(h.deg, s, l, a)
override fun toString(): String = "hsla($h, $s%, $l%, $a)"
}
inline val aliceblue get() = Color("aliceblue")
inline val antiquewhite get() = Color("antiquewhite")
inline val aquamarine get() = Color("aquamarine")
inline val azure get() = Color("azure")
inline val beige get() = Color("beige")
inline val bisque get() = Color("bisque")
inline val black get() = Color("black")
inline val blanchedalmond get() = Color("blanchedalmond")
inline val blue get() = Color("blue")
inline val blueviolet get() = Color("blueviolet")
inline val brown get() = Color("brown")
inline val burlywood get() = Color("burlywood")
inline val cadetblue get() = Color("cadetblue")
inline val chartreuse get() = Color("chartreuse")
inline val chocolate get() = Color("chocolate")
inline val cornflowerblue get() = Color("cornflowerblue")
inline val cornsilk get() = Color("cornsilk")
inline val crimson get() = Color("crimson")
inline val cyan get() = Color("cyan")
inline val darkblue get() = Color("darkblue")
inline val darkcyan get() = Color("darkcyan")
inline val darkgoldenrod get() = Color("darkgoldenrod")
inline val darkgray get() = Color("darkgray")
inline val darkgreen get() = Color("darkgreen")
inline val darkkhaki get() = Color("darkkhaki")
inline val darkmagenta get() = Color("darkmagenta")
inline val darkolivegreen get() = Color("darkolivegreen")
inline val darkorange get() = Color("darkorange")
inline val darkorchid get() = Color("darkorchid")
inline val darkred get() = Color("darkred")
inline val darksalmon get() = Color("darksalmon")
inline val darkslateblue get() = Color("darkslateblue")
inline val darkslategray get() = Color("darkslategray")
inline val darkturquoise get() = Color("darkturquoise")
inline val darkviolet get() = Color("darkviolet")
inline val deeppink get() = Color("deeppink")
inline val deepskyblue get() = Color("deepskyblue")
inline val dimgray get() = Color("dimgray")
inline val dodgerblue get() = Color("dodgerblue")
inline val firebrick get() = Color("firebrick")
inline val floralwhite get() = Color("floralwhite")
inline val forestgreen get() = Color("forestgreen")
inline val fuchsia get() = Color("fuchsia")
inline val gainsboro get() = Color("gainsboro")
inline val ghostwhite get() = Color("ghostwhite")
inline val goldenrod get() = Color("goldenrod")
inline val gold get() = Color("gold")
inline val gray get() = Color("gray")
inline val green get() = Color("green")
inline val greenyellow get() = Color("greenyellow")
inline val honeydew get() = Color("honeydew")
inline val hotpink get() = Color("hotpink")
inline val indianred get() = Color("indianred")
inline val indigo get() = Color("indigo")
inline val ivory get() = Color("ivory")
inline val khaki get() = Color("khaki")
inline val lavenderblush get() = Color("lavenderblush")
inline val lavender get() = Color("lavender")
inline val lawngreen get() = Color("lawngreen")
inline val lemonchiffon get() = Color("lemonchiffon")
inline val lightblue get() = Color("lightblue")
inline val lightcoral get() = Color("lightcoral")
inline val lightcyan get() = Color("lightcyan")
inline val lightgoldenrodyellow get() = Color("lightgoldenrodyellow")
inline val lightgray get() = Color("lightgray")
inline val lightgreen get() = Color("lightgreen")
inline val lightpink get() = Color("lightpink")
inline val lightsalmon get() = Color("lightsalmon")
inline val lightseagreen get() = Color("lightseagreen")
inline val lightskyblue get() = Color("lightskyblue")
inline val lightslategray get() = Color("lightslategray")
inline val lightsteelblue get() = Color("lightsteelblue")
inline val lightyellow get() = Color("lightyellow")
inline val limegreen get() = Color("limegreen")
inline val lime get() = Color("lime")
inline val linen get() = Color("linen")
inline val magenta get() = Color("magenta")
inline val maroon get() = Color("maroon")
inline val mediumaquamarine get() = Color("mediumaquamarine")
inline val mediumblue get() = Color("mediumblue")
inline val mediumorchid get() = Color("mediumorchid")
inline val mediumpurple get() = Color("mediumpurple")
inline val mediumseagreen get() = Color("mediumseagreen")
inline val mediumslateblue get() = Color("mediumslateblue")
inline val mediumspringgreen get() = Color("mediumspringgreen")
inline val mediumturquoise get() = Color("mediumturquoise")
inline val mediumvioletred get() = Color("mediumvioletred")
inline val midnightblue get() = Color("midnightblue")
inline val mintcream get() = Color("mintcream")
inline val mistyrose get() = Color("mistyrose")
inline val moccasin get() = Color("moccasin")
inline val navajowhite get() = Color("navajowhite")
inline val navi get() = Color("navi")
inline val oldlace get() = Color("oldlace")
inline val olivedrab get() = Color("olivedrab")
inline val olive get() = Color("olive")
inline val orange get() = Color("orange")
inline val orangered get() = Color("orangered")
inline val orchid get() = Color("orchid")
inline val palegoldenrod get() = Color("palegoldenrod")
inline val palegreen get() = Color("palegreen")
inline val paleturquoise get() = Color("paleturquoise")
inline val palevioletred get() = Color("palevioletred")
inline val papayawhip get() = Color("papayawhip")
inline val peachpuff get() = Color("peachpuff")
inline val peru get() = Color("peru")
inline val pink get() = Color("pink")
inline val plum get() = Color("plum")
inline val powderblue get() = Color("powderblue")
inline val purple get() = Color("purple")
inline val rebeccapurple get() = Color("rebeccapurple")
inline val red get() = Color("red")
inline val rosybrown get() = Color("rosybrown")
inline val royalblue get() = Color("royalblue")
inline val saddlebrown get() = Color("saddlebrown")
inline val salmon get() = Color("salmon")
inline val sandybrown get() = Color("sandybrown")
inline val seagreen get() = Color("seagreen")
inline val seashell get() = Color("seashell")
inline val sienna get() = Color("sienna")
inline val silver get() = Color("silver")
inline val skyblue get() = Color("skyblue")
inline val slateblue get() = Color("slateblue")
inline val slategray get() = Color("slategray")
inline val snow get() = Color("snow")
inline val springgreen get() = Color("springgreen")
inline val steelblue get() = Color("steelblue")
inline val teal get() = Color("teal")
inline val thistle get() = Color("thistle")
inline val tomato get() = Color("tomato")
inline val turquoise get() = Color("turquoise")
inline val violet get() = Color("violet")
inline val wheat get() = Color("wheat")
inline val white get() = Color("white")
inline val whitesmoke get() = Color("whitesmoke")
inline val yellowgreen get() = Color("yellowgreen")
inline val yellow get() = Color("yellow")
inline val transparent get() = Color("transparent")
inline val currentColor get() = Color("currentColor")
}
fun Color(name: String): CSSColorValue = name.unsafeCast<CSSColorValue>()
private class RGB(val r: Number, val g: Number, val b: Number): CSSColorValue {
override fun toString(): String = "rgb($r, $g, $b)"
}
private class RGBA(val r: Number, val g: Number, val b: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "rgba($r, $g, $b, $a)"
}
private class HSL(val h: CSSAngleValue, val s: Number, val l: Number) : CSSColorValue {
override fun toString(): String = "hsl($h, $s%, $l%)"
}
private class HSLA(val h: CSSAngleValue, val s: Number, val l: Number, val a: Number) : CSSColorValue {
override fun toString(): String = "hsla($h, $s%, $l%, $a)"
}
fun rgb(r: Number, g: Number, b: Number): CSSColorValue = RGB(r, g, b)
fun rgba(r: Number, g: Number, b: Number, a: Number): CSSColorValue = RGBA(r, g, b, a)
fun hsl(h: CSSAngleValue, s: Number, l: Number): CSSColorValue = HSL(h, s, l)
fun hsl(h: Number, s: Number, l: Number): CSSColorValue = HSL(h.deg, s, l)
fun hsla(h: CSSAngleValue, s: Number, l: Number, a: Number): CSSColorValue = HSLA(h, s, l, a)
fun hsla(h: Number, s: Number, l: Number, a: Number): CSSColorValue = HSLA(h.deg, s, l, a)

23
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StylePropertyValue.kt

@ -0,0 +1,23 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@file:Suppress("UNUSED", "NOTHING_TO_INLINE", "FunctionName")
package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.*
expect interface StylePropertyValue
expect interface StylePropertyNumber: StylePropertyValue
expect interface StylePropertyString: StylePropertyValue
inline fun StylePropertyValue(value: String): StylePropertyString = value.unsafeCast<StylePropertyString>()
inline fun StylePropertyValue(value: Number): StylePropertyNumber = value.unsafeCast<StylePropertyNumber>()
expect interface CSSStyleValue: StylePropertyValue {
actual override fun toString(): String
}
inline fun CSSStyleValue(value: String): CSSStyleValue = StylePropertyValue(value).unsafeCast<CSSStyleValue>()

196
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleScope.kt

@ -0,0 +1,196 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@file:Suppress("NOTHING_TO_INLINE", "unused")
package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.attributes.HtmlAttrMarker
import org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi
import kotlin.properties.ReadOnlyProperty
import org.jetbrains.compose.web.*
@Deprecated(
message = "Renamed to StyleScope",
replaceWith = ReplaceWith("StyleScope", "org.jetbrains.compose.web.css.StyleScope")
)
typealias StyleBuilder = StyleScope
/**
* StyleScope serves for two main purposes. Passed as a builder context (in [AttrsScope]), it
* makes it possible to:
* 1. Add inlined css properties to the element (@see [property])
* 2. Set values to CSS variables (@see [variable])
*/
@HtmlAttrMarker
interface StyleScope {
/**
* Adds arbitrary CSS property to the inline style of the element
* @param propertyName - the name of css property as [per spec](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference)
* @param value - the value, it can be either String or specialized type like [CSSNumeric] or [CSSColorValue]
*
* Most frequent CSS property values can be set via specialized methods, like [width], [display] etc.
*
* Example:
* ```
* Div({
* style {
* property("some-exotic-css-property", "I am a string value")
* property("some-exotic-css-property-width", 5.px)
* }
* })
* ```
*/
fun property(propertyName: String, value: StylePropertyValue)
fun variable(variableName: String, value: StylePropertyValue)
fun property(propertyName: String, value: String) = property(propertyName, StylePropertyValue(value))
fun property(propertyName: String, value: Number) = property(propertyName, StylePropertyValue(value))
fun variable(variableName: String, value: String) = variable(variableName, StylePropertyValue(value))
fun variable(variableName: String, value: Number) = variable(variableName, StylePropertyValue(value))
operator fun <TValue : StylePropertyValue> CSSStyleVariable<TValue>.invoke(value: TValue) {
variable(name, value.toString())
}
operator fun CSSStyleVariable<StylePropertyString>.invoke(value: String) {
variable(name, value)
}
operator fun CSSStyleVariable<StylePropertyNumber>.invoke(value: Number) {
variable(name, value)
}
}
internal inline fun variableValue(variableName: String, fallback: StylePropertyValue? = null) =
"var(--$variableName${fallback?.let { ", $it" } ?: ""})"
expect interface CSSVariableValueAs<out T : StylePropertyValue>
inline fun <TValue> CSSVariableValue(value: StylePropertyValue) =
value.unsafeCast<TValue>()
inline fun <TValue> CSSVariableValue(value: String) =
CSSVariableValue<TValue>(StylePropertyValue(value))
// after adding `variable` word `add` became ambiguous
@Deprecated(
"use property instead, will remove it soon",
ReplaceWith("property(propertyName, value)")
)
fun StyleScope.add(
propertyName: String,
value: StylePropertyValue
) = property(propertyName, value)
interface CSSVariable {
val name: String
}
class CSSStyleVariable<out TValue : StylePropertyValue>(override val name: String) : CSSVariable
fun <TValue : StylePropertyValue> CSSStyleVariable<TValue>.value(fallback: TValue? = null) =
CSSVariableValue<TValue>(
variableValue(
name,
fallback
)
)
fun <TValue> CSSStyleVariable<TValue>.value(fallback: TValue? = null)
where TValue : CSSVariableValueAs<TValue>,
TValue : StylePropertyValue =
CSSVariableValue<TValue>(
variableValue(
name,
fallback
)
)
/**
* Introduces CSS variable that can be later referred anywhere in [StyleSheet]
*
* Example:
* ```
* object AppCSSVariables {
* val width by variable<CSSUnitValue>()
* val stringHeight by variable<StylePropertyString>()
* val order by variable<StylePropertyNumber>()
* }
*
* object AppStylesheet : StyleSheet() {
* val classWithProperties by style {
* AppCSSVariables.width(100.px)
* property("width", AppCSSVariables.width.value())
* }
*```
*
*/
fun <TValue : StylePropertyValue> variable() =
ReadOnlyProperty<Any?, CSSStyleVariable<TValue>> { _, property ->
CSSStyleVariable(property.name)
}
interface StyleHolder {
@ComposeWebInternalApi
val properties: StylePropertyList
@ComposeWebInternalApi
val variables: StylePropertyList
}
@Deprecated(
message = "Renamed to StyleScopeBuilder",
replaceWith = ReplaceWith("StyleScopeBuilder", "org.jetbrains.compose.web.css.StyleScopeBuilder")
)
typealias StyleBuilderImpl = StyleScopeBuilder
@Suppress("EqualsOrHashCode")
open class StyleScopeBuilder : StyleScope, StyleHolder {
override val properties: MutableStylePropertyList = mutableListOf()
override val variables: MutableStylePropertyList = mutableListOf()
override fun property(propertyName: String, value: StylePropertyValue) {
properties.add(StylePropertyDeclaration(propertyName, value))
}
override fun variable(variableName: String, value: StylePropertyValue) {
variables.add(StylePropertyDeclaration(variableName, value))
}
// StylePropertyValue is js native object without equals
override fun equals(other: Any?): Boolean {
return if (other is StyleHolder) {
properties.nativeEquals(other.properties) &&
variables.nativeEquals(other.variables)
} else false
}
@ComposeWebInternalApi
internal fun copyFrom(sb: StyleHolder) {
properties.addAll(sb.properties)
variables.addAll(sb.variables)
}
}
data class StylePropertyDeclaration(
val name: String,
val value: StylePropertyValue
) {
constructor(name: String, value: String) : this(name, value.unsafeCast<StylePropertyValue>())
constructor(name: String, value: Number) : this(name, value.unsafeCast<StylePropertyValue>())
}
typealias StylePropertyList = List<StylePropertyDeclaration>
typealias MutableStylePropertyList = MutableList<StylePropertyDeclaration>
internal fun StylePropertyList.nativeEquals(properties: StylePropertyList): Boolean {
if (this.size != properties.size) return false
var index = 0
return all { prop ->
val otherProp = properties[index++]
prop.name == otherProp.name &&
prop.value.toString() == otherProp.value.toString()
}
}

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StyleSheet.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleSheet.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StyleSheetBuilder.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/StyleSheetBuilder.kt

15
web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/keywords/Keywords.kt

@ -0,0 +1,15 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.css.keywords
import org.jetbrains.compose.web.css.CSSKeywordValue
import org.jetbrains.compose.web.*
expect interface CSSAutoKeyword : CSSKeywordValue
inline val auto: CSSAutoKeyword
get() = CSSKeywordValue("auto").unsafeCast<CSSAutoKeyword>()

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/animation.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/animation.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/background.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/background.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/border.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/border.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/box.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/box.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/color.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/color.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/filter.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/filter.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/flex.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/flex.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/grid.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/grid.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/listStyle.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/listStyle.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/margin.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/margin.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/overflow.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/overflow.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/padding.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/padding.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/position.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/position.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/properties.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/properties.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/transform.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/transform.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/transitions.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/transitions.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/ui.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/properties/ui.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/selectors/CSSSelectors.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/selectors/CSSSelectors.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt

10
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Base.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Base.kt

@ -2,7 +2,6 @@ package org.jetbrains.compose.web.dom
import androidx.compose.runtime.*
import org.jetbrains.compose.web.attributes.AttrsScope
import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.jetbrains.compose.web.attributes.AttrsScopeBuilder
import org.jetbrains.compose.web.css.StyleHolder
import org.jetbrains.compose.web.internal.runtime.ComposeWebInternalApi
@ -12,6 +11,8 @@ import org.w3c.dom.Element
import org.w3c.dom.HTMLElement
import org.w3c.dom.css.ElementCSSInlineStyle
import org.w3c.dom.svg.SVGElement
import org.jetbrains.compose.web.*
import org.jetbrains.compose.web.internal.runtime.getW3cListener
@Composable
@ExplicitGroupsComposable
@ -44,13 +45,13 @@ private class DomElementWrapper(override val node: Element): DomNodeWrapper(node
fun updateEventListeners(list: List<NamedEventListener>) {
currentListeners.forEach {
node.removeEventListener(it.name, it)
node.removeEventListener(it.name, it.getW3cListener())
}
currentListeners = list
currentListeners.forEach {
node.addEventListener(it.name, it)
node.addEventListener(it.name, it.getW3cListener())
}
}
@ -79,7 +80,7 @@ private class DomElementWrapper(override val node: Element): DomNodeWrapper(node
}
fun updateAttrs(attrs: Map<String, String>) {
node.getAttributeNames().forEach { name ->
node.getAttributeNamesWorkaround().forEach { name ->
when (name) {
"style", "class" -> {
// skip style and class here, they're managed in corresponding methods
@ -101,7 +102,6 @@ private class DomElementWrapper(override val node: Element): DomNodeWrapper(node
}
}
@OptIn(ComposeWebInternalApi::class)
@Composable
fun <TElement : Element> TagElement(

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/ElementScope.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/ElementScope.kt

1
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt

@ -61,6 +61,7 @@ import org.w3c.dom.HTMLUListElement
import org.w3c.dom.HTMLVideoElement
import org.w3c.dom.Text
import org.w3c.dom.css.CSSStyleSheet
import org.jetbrains.compose.web.*
typealias AttrBuilderContext<T> = AttrsScope<T>.() -> Unit
typealias ContentBuilder<T> = @Composable ElementScope<T>.() -> Unit

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/InputElements.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/InputElements.kt

1
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/RadioGroup.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/RadioGroup.kt

@ -5,6 +5,7 @@ import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.builders.InputAttrsScope
import org.jetbrains.compose.web.attributes.name
import org.jetbrains.compose.web.*
typealias RadioInputAttrsBuilder = (InputAttrsScope<Boolean>.() -> Unit)

2
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Style.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/elements/Style.kt

@ -6,7 +6,7 @@ import org.w3c.dom.css.CSSStyleDeclaration
import org.w3c.dom.css.CSSStyleRule
import org.jetbrains.compose.web.css.*
import org.w3c.dom.css.CSSStyleSheet
import org.jetbrains.compose.web.*
internal fun CSSStyleSheet.setCSSRules(cssRules: CSSRuleDeclarationList) {
cssRules.forEach { cssRule ->

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticAnimationEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticAnimationEvent.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticChangeEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticChangeEvent.kt

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticClipboardEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticClipboardEvent.kt

3
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticEvent.kt

@ -2,11 +2,12 @@ package androidx.compose.web.events
import org.w3c.dom.events.Event
import org.w3c.dom.events.EventTarget
import org.jetbrains.compose.web.*
open class SyntheticEvent<Element : EventTarget> internal constructor(
val nativeEvent: Event
) {
val target: Element = nativeEvent.target.unsafeCast<Element>()
val target: Element = nativeEvent.target!!.unsafeCast<Element>()
val bubbles: Boolean = nativeEvent.bubbles
val cancelable: Boolean = nativeEvent.cancelable
val composed: Boolean = nativeEvent.composed

0
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticFocusEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticFocusEvent.kt

9
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticInputEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticInputEvent.kt

@ -4,6 +4,7 @@ import androidx.compose.web.events.SyntheticEvent
import org.w3c.dom.DataTransfer
import org.w3c.dom.events.Event
import org.w3c.dom.events.EventTarget
import org.jetbrains.compose.web.*
// @param nativeEvent: Event - we don't use [org.w3c.dom.events.InputEvent] here,
// since for cases it can be just [org.w3c.dom.events.Event]
@ -13,8 +14,8 @@ class SyntheticInputEvent<ValueType, Element : EventTarget> internal constructor
) : SyntheticEvent<Element>(
nativeEvent = nativeEvent
) {
val data: String? = nativeEvent.asDynamic().data?.unsafeCast<String>()
val dataTransfer: DataTransfer? = nativeEvent.asDynamic().dataTransfer?.unsafeCast<DataTransfer>()
val inputType: String? = nativeEvent.asDynamic().inputType?.unsafeCast<String>()
val isComposing: Boolean = nativeEvent.asDynamic().isComposing?.unsafeCast<Boolean>() ?: false
val data: String? = nativeEvent.getStringProperty("data")
val dataTransfer: DataTransfer? = nativeEvent.getAnyProperty<DataTransfer?>("dataTransfer")
val inputType: String? = nativeEvent.getStringProperty("inputType")
val isComposing: Boolean = nativeEvent.getBooleanProperty("isComposing")!!
}

3
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticKeyboardEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticKeyboardEvent.kt

@ -3,6 +3,7 @@ package org.jetbrains.compose.web.events
import androidx.compose.web.events.SyntheticEvent
import org.w3c.dom.events.EventTarget
import org.w3c.dom.events.KeyboardEvent
import org.jetbrains.compose.web.*
class SyntheticKeyboardEvent internal constructor(
nativeEvent: KeyboardEvent
@ -15,7 +16,7 @@ class SyntheticKeyboardEvent internal constructor(
val ctrlKey: Boolean = nativeEvent.ctrlKey
val isComposing: Boolean = nativeEvent.isComposing
val key: String = nativeEvent.key
val locale: String = nativeEvent.asDynamic().locale.toString()
val locale: String = nativeEvent.getStringProperty("locale").toString()
val location: Int = nativeEvent.location
val metaKey: Boolean = nativeEvent.metaKey
val repeat: Boolean = nativeEvent.repeat

7
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/events/SyntheticMouseEvent.kt → web/core/src/jsWasmMain/kotlin/org/jetbrains/compose/web/events/SyntheticMouseEvent.kt

@ -6,6 +6,7 @@ import org.w3c.dom.HTMLElement
import org.w3c.dom.events.EventTarget
import org.w3c.dom.events.MouseEvent
import org.w3c.dom.events.WheelEvent
import org.jetbrains.compose.web.*
/**
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
@ -26,14 +27,14 @@ open class SyntheticMouseEvent internal constructor(
// https://github.com/JetBrains/compose-jb/issues/1053
// movementX and movementY are undefined in SafariMobile MouseEvent
val movementX: Int = (nativeEvent.asDynamic().movementX as? Int) ?: 0
val movementY: Int = (nativeEvent.asDynamic().movementY as? Int) ?: 0
val movementX: Int = nativeEvent.getIntProperty("movementX") ?: 0
val movementY: Int = nativeEvent.getIntProperty("movementY") ?: 0
val offsetX: Double = nativeEvent.offsetX
val offsetY: Double = nativeEvent.offsetY
val pageX: Double = nativeEvent.pageX
val pageY: Double = nativeEvent.pageY
val region: String? = nativeEvent.region
val region: String? = nativeEvent.getStringProperty("region")
val relatedTarget: EventTarget? = nativeEvent.relatedTarget
val screenX: Int = nativeEvent.screenX
val screenY: Int = nativeEvent.screenY

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save