Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit faa68d8

Browse files
authored
feature: Support wasm target (#20)
1 parent 75be525 commit faa68d8

File tree

11 files changed

+119
-66
lines changed

11 files changed

+119
-66
lines changed

.gitignore

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ fabric.properties
9494
# Generated files
9595
bin/
9696
gen/
97-
out/
9897

9998
# Gradle files
10099
.gradle
@@ -143,7 +142,6 @@ obj/
143142

144143
# IntelliJ IDEA
145144
*.iml
146-
*.iws
147145
/out/
148146

149147
# User-specific configurations
@@ -190,87 +188,45 @@ hs_err_pid*
190188

191189
## Plugin-specific files:
192190

193-
# mpeltonen/sbt-idea plugin
194-
.idea_modules/
195-
196-
# JIRA plugin
197-
atlassian-ide-plugin.xml
198-
199191
# Mongo Explorer plugin
200192
.idea/mongoSettings.xml
201193

202-
# Crashlytics plugin (for Android Studio and IntelliJ)
203-
com_crashlytics_export_strings.xml
204-
crashlytics.properties
205-
crashlytics-build.properties
206-
fabric.properties
207-
208194
### Example user template template
209195
### Example user template
210196

211197
# IntelliJ project files
212198
.idea
213-
*.iml
214199
out
215200
gen
216201
### Kotlin template
217-
# Compiled class file
218-
*.class
219-
220-
# Log file
221-
*.log
222202

223203
# BlueJ files
224204
*.ctxt
225205

226-
# Mobile Tools for Java (J2ME)
227-
.mtj.tmp/
228-
229-
# Package Files #
230-
*.war
231206
*.nar
232-
*.ear
233207
*.zip
234208
*.tar.gz
235209
*.rar
236210

237-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
238-
hs_err_pid*
239-
replay_pid*
240211

241-
### Android template
242-
# Gradle files
243-
.gradle/
244-
build/
245-
246-
# Local configuration file (sdk path, etc)
247-
local.properties
248-
249-
# Log/OS Files
250-
*.log
212+
replay_pid*
251213

252214
# Android Studio generated files and folders
253-
captures/
254215
.externalNativeBuild/
255216
.cxx/
256-
*.apk
257217
output.json
258218

259219
# IntelliJ
260-
*.iml
261220
.idea/
262221
misc.xml
263222
deploymentTargetDropDown.xml
264223
render.experimental.xml
265224

266-
# Keystore files
267-
*.jks
268-
*.keystore
269-
270225
# Google Services (e.g. APIs or Firebase)
271226
google-services.json
272227

273228
# Android Profiling
274229
*.hprof
275230

276-
.kotlin
231+
.kotlin
232+
/kotlin-js-store

compose-shadow/build.gradle.kts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
@file:OptIn(ExperimentalEncodingApi::class)
1+
@file:OptIn(ExperimentalEncodingApi::class, ExperimentalWasmDsl::class)
22

33
import com.vanniktech.maven.publish.SonatypeHost
44
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
5+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
56
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
67
import kotlin.io.encoding.ExperimentalEncodingApi
78

@@ -22,7 +23,7 @@ kotlin {
2223
}
2324
}
2425

25-
jvm("desktop")
26+
jvm()
2627

2728
iosX64()
2829
iosArm64()
@@ -31,12 +32,38 @@ kotlin {
3132
macosX64()
3233
macosArm64()
3334

35+
wasmJs {
36+
browser()
37+
}
38+
3439
sourceSets {
3540
commonMain.dependencies {
3641
implementation(compose.runtime)
3742
implementation(compose.foundation)
3843
implementation(compose.ui)
39-
implementation(libs.androidx.annotation)
44+
}
45+
val nonWebMain by creating {
46+
dependsOn(commonMain.get())
47+
dependencies {
48+
implementation(libs.androidx.annotation)
49+
}
50+
}
51+
val skikoMain by creating {
52+
dependsOn(commonMain.get())
53+
}
54+
androidMain.configure {
55+
dependsOn(nonWebMain)
56+
}
57+
jvmMain.configure {
58+
dependsOn(skikoMain)
59+
dependsOn(nonWebMain)
60+
}
61+
nativeMain.configure {
62+
dependsOn(skikoMain)
63+
dependsOn(nonWebMain)
64+
}
65+
wasmJsMain.configure {
66+
dependsOn(skikoMain)
4067
}
4168
}
4269
}

compose-shadow/src/commonMain/kotlin/com/adamglin/composeshadow/DropShadow.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.adamglin.composeshadow
22

3-
import androidx.annotation.RequiresApi
43
import androidx.compose.ui.Modifier
54
import androidx.compose.ui.draw.shadow
65
import androidx.compose.ui.geometry.Size
@@ -34,7 +33,6 @@ import com.adamglin.composeshadow.utils.setMaskFilter
3433
* @param blur The blur radius of the shadow.
3534
* @param spread The spread radius of the shadow.
3635
*/
37-
@RequiresApi(26)
3836
fun Modifier.dropShadow(
3937
shape: Shape,
4038
color: Color = Color.Black.copy(0.25f),

compose-shadow/src/desktopMain/kotlin/com/adamglin/composeshadow/utils/maskFilter.desktop.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.adamglin.composeshadow.utils
22

3-
43
import androidx.compose.ui.graphics.NativePaint
54
import org.jetbrains.skia.FilterBlurMode
65
import org.jetbrains.skia.MaskFilter
76

8-
internal actual fun NativePaint.setMaskFilter(blurRadius: Float) {
7+
actual fun NativePaint.setMaskFilter(blurRadius: Float) {
98
this.maskFilter = MaskFilter.makeBlur(FilterBlurMode.NORMAL, blurRadius / 2, true)
109
}

sample/shared/build.gradle.kts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
@file:OptIn(ExperimentalWasmDsl::class)
2+
13
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
4+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
25
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
36

47

@@ -16,7 +19,7 @@ kotlin {
1619
jvmTarget.set(JvmTarget.JVM_11)
1720
}
1821
}
19-
jvm("desktop")
22+
jvm()
2023
listOf(
2124
iosArm64(),
2225
iosX64(),
@@ -28,8 +31,14 @@ kotlin {
2831
}
2932
}
3033

34+
wasmJs {
35+
moduleName = "composeApp"
36+
browser {
37+
}
38+
binaries.executable()
39+
}
40+
3141
sourceSets {
32-
val desktopMain by getting
3342
commonMain.dependencies {
3443
// compose multiplatform
3544
implementation(compose.runtime)

sample/wasm-app/build.gradle.kts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
3+
4+
plugins {
5+
alias(libs.plugins.kotlin.multiplatform)
6+
alias(libs.plugins.compose.multiplatform)
7+
alias(libs.plugins.compose.compiler)
8+
}
9+
10+
kotlin {
11+
@OptIn(ExperimentalWasmDsl::class)
12+
wasmJs {
13+
moduleName = "composeApp"
14+
browser {
15+
val rootDirPath = project.rootDir.path
16+
val projectDirPath = project.projectDir.path
17+
commonWebpackConfig {
18+
outputFileName = "composeApp.js"
19+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
20+
static = (static ?: mutableListOf()).apply {
21+
// Serve sources to debug inside browser
22+
add(rootDirPath)
23+
add(projectDirPath)
24+
}
25+
}
26+
}
27+
}
28+
binaries.executable()
29+
}
30+
sourceSets {
31+
wasmJsMain.dependencies {
32+
implementation(compose.runtime)
33+
implementation(compose.foundation)
34+
implementation(compose.material)
35+
implementation(compose.ui)
36+
implementation(compose.components.resources)
37+
implementation(compose.components.uiToolingPreview)
38+
implementation(project(":sample:shared"))
39+
}
40+
}
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.demo0913
2+
3+
import SampleApp
4+
import androidx.compose.ui.ExperimentalComposeUiApi
5+
import androidx.compose.ui.window.ComposeViewport
6+
import kotlinx.browser.document
7+
8+
@OptIn(ExperimentalComposeUiApi::class)
9+
fun main() {
10+
ComposeViewport(document.body!!) {
11+
SampleApp()
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>KotlinProject</title>
7+
<link type="text/css" rel="stylesheet" href="styles.css">
8+
<script type="application/javascript" src="composeApp.js"></script>
9+
</head>
10+
<body>
11+
</body>
12+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
html, body {
2+
width: 100%;
3+
height: 100%;
4+
margin: 0;
5+
padding: 0;
6+
overflow: hidden;
7+
}

0 commit comments

Comments
 (0)