I'm having fun again trying to include JS dependencies ...
chroma provides itself as a function apparently, how does one call something like this in interop?
chroma('pink').darken().saturate(2).hex()
-> is your friend. (-> (chroma "pink") (.darken) (.saturate 2) (.hex))
My bad, my problem was badly described. I tried that but
Execution error (TypeError) at (<cljs repl>:1).
shadow.esm.esm_import$chroma_js is not a function
Something like this however works
(-> (chroma/scale (clj->js [start-color end-color]))
(.mode "lch")
(.colors n))
I've been trying both
["chroma-js" :as chroma-js :refer [chroma]]
;; and
["chroma-js" :as chroma]what is the JS example using? from their docs?
import chroma from 'chroma-js';
ok thats called a default export
["chroma-js" :default chroma] then?
see the translation examples in this section https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
:default works in shadow, but consider it deprecated 😛
Mh :default however works, ["chroma-js$default" :as chroma-default] did not
how did you actually use it?
["chroma-js" :as chroma]
["chroma-js$default" :as chroma-default]
;; works
(-> (chroma/scale (clj->js [start-color end-color]))
(.mode "lch")
(.colors n))
;; does not work
(-> (chroma-default "pink") (.darken) (.saturate 2) (.hex))
(-> (chroma "pink") (.darken) (.saturate 2) (.hex))["chroma-js" :default chroma]
;; works
(-> (chroma/scale (clj->js [start-color end-color]))
(.mode "lch")
(.colors n))
(-> (chroma "pink") (.darken) (.saturate 2) (.hex))(-> (chroma "pink") (.darken) (.saturate 2) (.hex)) this won't work
Yeah I figured, but the chroma-default also didn't
that should be fine
Oh it probably was an issue with that cursed Vite + shadow-cljs build I got going. I can't make Vite stop hard reloading the page on JS changes for some reason and therefore told it to ignore the shadow output, which breaks all kinds of things. Some things "work" via shadow code reload, but other stuff just doesn't
But that answers the external JS question! Thanks!