kiso 0.5.1.pre → 0.5.2.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kiso/color_utils.rb +5 -1
- data/lib/kiso/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60861d160167adf83488de026f4bc6e3ae9a6ec90ce04cb5862f0ce5ec1a4567
|
|
4
|
+
data.tar.gz: d6c5017ed994250be02db77345fdf14c6b72f7971837f7fdc86c6f27a5701dc4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7046fc1419c4bb2ca1a2096b11965f714bd91743c70605278bb4ebf9a1d041bad38b073a038aad9f717e730b469841e4532f76752ee952389b7f908b310f8fd0
|
|
7
|
+
data.tar.gz: 6910db9bd5316e5a556f8032e431305b33d86bce7537428fdd9fd8a3074fe66a5943a02b037955670721772d34dadaf2e5ed97a7448c2db1297c357f99243f50
|
data/lib/kiso/color_utils.rb
CHANGED
|
@@ -5,6 +5,10 @@ module Kiso
|
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
7
|
# Returns "white" or "black" based on WCAG relative luminance.
|
|
8
|
+
# Uses a perceptual threshold of 0.36 rather than the mathematical
|
|
9
|
+
# midpoint of 0.179, per Lea Verou's research on contrast color
|
|
10
|
+
# generation. The higher threshold produces better results on
|
|
11
|
+
# saturated chromatic colors (e.g. Tailwind 500-shade palette).
|
|
8
12
|
# Accepts 3-digit (#abc) or 6-digit (#aabbcc) hex strings.
|
|
9
13
|
def contrast_text_color(hex)
|
|
10
14
|
hex = hex.delete("#")
|
|
@@ -15,7 +19,7 @@ module Kiso
|
|
|
15
19
|
(c <= 0.04045) ? c / 12.92 : ((c + 0.055) / 1.055)**2.4
|
|
16
20
|
}.then { |lr, lg, lb| 0.2126 * lr + 0.7152 * lg + 0.0722 * lb }
|
|
17
21
|
|
|
18
|
-
(luminance > 0.
|
|
22
|
+
(luminance > 0.36) ? "black" : "white"
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
end
|
data/lib/kiso/version.rb
CHANGED