about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-21 17:43:23 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-21 17:43:23 +0100
commit652251c2f7a4ea8d8854e4987689005a3bfd318e (patch)
treed90101660876177d9dce923d177330b8fbaab085 /src/css
parent940e6516955add573872231c1b8365c21dd62195 (diff)
downloadchawan-652251c2f7a4ea8d8854e4987689005a3bfd318e.tar.gz
Color & term improvements
Diffstat (limited to 'src/css')
-rw-r--r--src/css/values.nim21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index 249bfa37..1d28484c 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -1,5 +1,6 @@
 import tables
 import macros
+import options
 import strutils
 
 import css/cssparser
@@ -333,23 +334,9 @@ func cssColor(d: CSSDeclaration): CSSColor =
       let tok = CSSToken(d.value[0])
       case tok.tokenType
       of CSS_HASH_TOKEN:
-        let s = tok.value
-        if s.len == 3:
-          for r in s:
-            if hexValue(r) == -1:
-              raise newException(CSSValueError, "Invalid color")
-          let c = (hexValue(s[0]) shl 20) or (hexValue(s[0]) shl 16) or
-                  (hexValue(s[1]) shl 12) or (hexValue(s[1]) shl 8) or
-                  (hexValue(s[2]) shl 4) or hexValue(s[2])
-          return CSSColor(rgba: RGBColor(c))
-        elif s.len == 6:
-          for r in s:
-            if hexValue(r) == -1:
-              raise newException(CSSValueError, "Invalid color")
-          let c = (hexValue(s[0]) shl 20) or (hexValue(s[1]) shl 16) or
-                  (hexValue(s[2]) shl 12) or (hexValue(s[3]) shl 8) or
-                  (hexValue(s[4]) shl 4) or hexValue(s[5])
-          return CSSColor(rgba: RGBColor(c))
+        let c = parseHexColor(tok.value)
+        if c.isSome:
+          return CSSColor(rgba: c.get)
         else:
           raise newException(CSSValueError, "Invalid color")
       of CSS_IDENT_TOKEN: