I want to add JavaScript support to Ashampoo Kim, ...
# javascript
s
I want to add JavaScript support to Ashampoo Kim, but I have no experience in kotlin-js so far. The lib already has wasmJS support. Can someone tell me how I need to translate/change this to work for regular JavaScript? https://github.com/Ashampoo/kim/blob/main/src/wasmMain/kotlin/com/ashampoo/kim/common/ZLib.wasm.kt
1
a
Seems like you can just copy this file to js source set and it should work
s
I tried that first, but it won't work. 🤷‍♂️
JsAny for example is unknown.
a
JsAny can be renamed to dynamic I think
But “it won’t work” is a little vague ;)
s
Yes, it does not compile. I can try "dynamic"
Okay, no I got
When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModule
on the
Pako.deflate(input)
call
I try adding
@JsNonModule
, but I don't understand what I'm doing to be honest. 😅
e
I'll clone it and give it a look, have 30 minutes of free time.
s
It starts to compile now, so maybe it works
I think I will set up a small kotlin/js project in the next days to test if it actually works
It compiled. Converting "JsAny" to "dynamic" and adding @JsNonModule (whatever that means) does the trick. Thank you all.
👍 1
e
Ok! There is small difference you need to consider between
wasmJs
and
js
Copy code
private val toStringOptions: JsAny = js("({to: 'string'})")
wasmJs
requires
JsAny
,
js
doesn't, so you can just return
dynamic
or
Any
🙏 1
Ah yeah you already found out ahaha
s
Thank you 🙂
I will try to remember that for the future. So they can't have the same sourceset
e
On the JS side you can also optimize the byte array conversions:
Copy code
public actual inline fun Uint8Array.toByteArray(): ByteArray =
  Int8Array(buffer, byteOffset, length).unsafeCast<ByteArray>()
And
Copy code
public actual inline fun ByteArray.toUint8Array(): Uint8Array {
  val i8a = unsafeCast<Int8Array>()
  return Uint8Array(i8a.buffer, i8a.byteOffset, i8a.length)
}
👍 1
s
Thanks a lot 🙂