Skip to content

Commit e50988e

Browse files
committed
Improve color viewer
1 parent e0153aa commit e50988e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/portal/ui/viewer/color.cljs

+17-7
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,31 @@
66
[portal.ui.theme :as theme]))
77

88
;;; :spec
9-
(defn- hex-color? [string]
10-
(re-matches #"#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}gi" string))
9+
(defn- hex-short? [string]
10+
(re-matches #"#[0-9a-fA-F]{3}gi" string))
11+
12+
(defn- hex-full? [string]
13+
(re-matches #"#[0-9a-fA-F]{6}" string))
14+
15+
(defn- hex-alpha? [string]
16+
(re-matches #"#[0-9a-fA-F]{8}" string))
1117

1218
(defn- rgb-color? [string]
1319
(re-matches #"rgb\(\d+,\d+,\d+\)" string))
1420

1521
(defn- rgba-color? [string]
1622
(re-matches #"rgba\(.+,.+,.+,.+\)" string))
1723

24+
(s/def ::hex
25+
(s/or :short hex-short?
26+
:full hex-full?
27+
:alpha hex-alpha?))
28+
29+
(s/def ::rgb
30+
(s/or :rgb rgb-color? :rgba rgba-color?))
31+
1832
(s/def ::color
19-
(s/and
20-
string?
21-
(s/or :hex hex-color?
22-
:rgb rgb-color?
23-
:rgba rgba-color?)))
33+
(s/and string? (s/or :hex ::hex :rgb ::rgb)))
2434
;;;
2535

2636
(defn inspect-color [value]

0 commit comments

Comments
 (0)