https://kotlinlang.org logo
#javascript
Title
# javascript
r

Reuben Firmin

11/24/2023, 10:02 PM
Any suggestions on the right way to wrap mermaid? https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/mermaid.ts#L393 / https://mermaid.js.org/config/usage.html#using-mermaid-run I have:
Copy code
@JsModule("mermaid")
@JsNonModule
@JsName("mermaid")
external object Mermaid {
    fun run()
}
The first time I call Mermaid.run() it works, but any subsequent call after dynamically adding a diagram to the document fails with "Uncaught TypeError: mermaid.run is not a function"
t

turansky

11/24/2023, 11:43 PM
JS
Copy code
export default mermaid;
Kotlin
Copy code
@file:JsModule("mermaid")

@JsName("default")
external object Mermaid {
    fun run()
}
r

Reuben Firmin

11/25/2023, 1:41 AM
Ah, makes sense - thanks. (I had to add @file:JsNonModule also to make it happy, but it works.)
t

turansky

11/25/2023, 6:31 AM
You can use
es
or
comoonjs
module kind to avoid redundant
@JsNonModule
es
+
useEsClasses
= less bundle size