clojurescript

Schmoho 2025-03-16T14:02:50.960059Z

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()

thheller 2025-03-16T14:44:23.280899Z

-> is your friend. (-> (chroma "pink") (.darken) (.saturate 2) (.hex))

Schmoho 2025-03-16T14:47:03.329389Z

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]

thheller 2025-03-16T14:47:35.948719Z

what is the JS example using? from their docs?

Schmoho 2025-03-16T14:48:01.336809Z

import chroma from 'chroma-js';

thheller 2025-03-16T14:48:08.154779Z

ok thats called a default export

Schmoho 2025-03-16T14:48:27.700089Z

["chroma-js" :default chroma] then?

thheller 2025-03-16T14:48:35.254699Z

see the translation examples in this section https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages

❤️ 1
thheller 2025-03-16T14:49:20.529389Z

:default works in shadow, but consider it deprecated 😛

Schmoho 2025-03-16T14:52:15.708359Z

Mh :default however works, ["chroma-js$default" :as chroma-default] did not

thheller 2025-03-16T14:52:56.632539Z

how did you actually use it?

Schmoho 2025-03-16T14:55:00.108879Z

["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))

Schmoho 2025-03-16T14:55:34.242299Z

["chroma-js" :default chroma]
;; works
(-> (chroma/scale (clj->js [start-color end-color]))
      (.mode "lch")
      (.colors n))
(-> (chroma "pink") (.darken) (.saturate 2) (.hex))

thheller 2025-03-16T14:55:35.761539Z

(-> (chroma "pink") (.darken) (.saturate 2) (.hex)) this won't work

Schmoho 2025-03-16T14:56:04.187569Z

Yeah I figured, but the chroma-default also didn't

thheller 2025-03-16T14:56:17.190669Z

that should be fine

Schmoho 2025-03-16T14:59:46.367349Z

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

Schmoho 2025-03-16T14:59:59.214859Z

But that answers the external JS question! Thanks!