mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Add tinycolor bindings
This commit is contained in:
parent
3c4e0e2447
commit
49ff0df7f6
3 changed files with 28 additions and 0 deletions
|
@ -116,6 +116,7 @@
|
|||
"source-map-support": "^0.5.21",
|
||||
"style-dictionary": "patch:style-dictionary@npm%3A4.0.0-prerelease.36#~/.yarn/patches/style-dictionary-npm-4.0.0-prerelease.36-55c0fc33bd.patch",
|
||||
"tdigest": "^0.1.2",
|
||||
"tinycolor2": "npm:^1.6.0",
|
||||
"ua-parser-js": "^1.0.38",
|
||||
"xregexp": "^5.1.1"
|
||||
}
|
||||
|
|
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)
|
|
@ -6966,6 +6966,7 @@ __metadata:
|
|||
style-dictionary: "patch:style-dictionary@npm%3A4.0.0-prerelease.36#~/.yarn/patches/style-dictionary-npm-4.0.0-prerelease.36-55c0fc33bd.patch"
|
||||
svg-sprite: "npm:^2.0.4"
|
||||
tdigest: "npm:^0.1.2"
|
||||
tinycolor2: "npm:^1.6.0"
|
||||
typescript: "npm:^5.4.5"
|
||||
ua-parser-js: "npm:^1.0.38"
|
||||
vite: "npm:^5.1.4"
|
||||
|
|
Loading…
Add table
Reference in a new issue