mirror of
https://github.com/penpot/penpot.git
synced 2025-07-08 14:17:18 +02:00
Add tinycolor bindings
This commit is contained in:
parent
3c4e0e2447
commit
49ff0df7f6
3 changed files with 28 additions and 0 deletions
26
frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs
Normal file
26
frontend/src/app/main/ui/workspace/tokens/tinycolor.cljs
Normal file
|
@ -0,0 +1,26 @@
|
|||
(ns app.main.ui.workspace.tokens.tinycolor
|
||||
"Bindings for tinycolor2 which supports a wide range of css compatible colors.
|
||||
|
||||
Used by StyleDictionary, so we might as well use it directly."
|
||||
(:require
|
||||
["tinycolor2" :as tinycolor]))
|
||||
|
||||
(defn tinycolor? [x]
|
||||
(and (instance? tinycolor x) (.isValid x)))
|
||||
|
||||
(defn valid-color [color-str]
|
||||
(let [tc (tinycolor color-str)]
|
||||
(when (.isValid tc) tc)))
|
||||
|
||||
(defn ->hex [tc]
|
||||
(assert (tinycolor? tc))
|
||||
(.toHex tc))
|
||||
|
||||
(defn color-format [tc]
|
||||
(assert (tinycolor? tc))
|
||||
(.getFormat tc))
|
||||
|
||||
(comment
|
||||
(some-> (valid-color "red") ->hex)
|
||||
(some-> (valid-color "red") color-format)
|
||||
nil)
|
Loading…
Add table
Add a link
Reference in a new issue