mirror of
https://github.com/penpot/penpot.git
synced 2026-05-03 15:18:59 +00:00
18 lines
456 B
Clojure
18 lines
456 B
Clojure
(ns uxbox.util.color
|
|
"Color conversion utils.")
|
|
|
|
(defn hex->rgb
|
|
[^string data]
|
|
(some->> (re-find #"^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$" data)
|
|
(rest)
|
|
(mapv #(js/parseInt % 16))))
|
|
|
|
(defn rgb->hex
|
|
[[r g b]]
|
|
(letfn [(to-hex [c]
|
|
(let [hexdata (.toString c 16)]
|
|
(if (= (count hexdata) 1)
|
|
(str "0" hexdata)
|
|
hexdata)))]
|
|
(str "#" (to-hex r) (to-hex g) (to-hex b))))
|