redgreenblue 0.13.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redgreenblue/24bit.rb +29 -12
- data/lib/redgreenblue/48bit.rb +19 -2
- data/lib/redgreenblue/base.rb +15 -1
- data/lib/redgreenblue/bgr24bit.rb +19 -2
- data/lib/redgreenblue/cie_1931.rb +4 -4
- data/lib/redgreenblue/cie_1976.rb +7 -7
- data/lib/redgreenblue/cie_1994.rb +55 -0
- data/lib/redgreenblue/gamma.rb +1 -1
- data/lib/redgreenblue/gif.rb +1 -1
- data/lib/redgreenblue/gpl.rb +48 -28
- data/lib/redgreenblue/hex.rb +39 -24
- data/lib/redgreenblue/hsb.rb +18 -3
- data/lib/redgreenblue/hsl.rb +21 -4
- data/lib/redgreenblue/hsv.rb +21 -4
- data/lib/redgreenblue/hsx_shared.rb +1 -1
- data/lib/redgreenblue/hwb.rb +14 -0
- data/lib/redgreenblue/inspect.rb +36 -24
- data/lib/redgreenblue/int.rb +19 -2
- data/lib/redgreenblue/lazy.rb +84 -10
- data/lib/redgreenblue/mac.rb +1 -1
- data/lib/redgreenblue/match.rb +29 -1
- data/lib/redgreenblue/math.rb +1 -1
- data/lib/redgreenblue/misc.rb +25 -8
- data/lib/redgreenblue/mix.rb +6 -6
- data/lib/redgreenblue/name.rb +1 -1
- data/lib/redgreenblue/opt/philipshue.rb +5 -3
- data/lib/redgreenblue/os/mac.rb +23 -6
- data/lib/redgreenblue/ostwald.rb +5 -5
- data/lib/redgreenblue/random.rb +21 -4
- data/lib/redgreenblue/rgb565.rb +19 -2
- data/lib/redgreenblue/terminal.rb +1 -1
- data/lib/redgreenblue/version.rb +2 -2
- data/lib/redgreenblue/view.rb +11 -5
- data/lib/redgreenblue/web.rb +67 -14
- data/lib/redgreenblue.rb +22 -3
- metadata +10 -8
data/lib/redgreenblue/web.rb
CHANGED
@@ -1,9 +1,73 @@
|
|
1
|
-
class RGB
|
1
|
+
class RGB::Color
|
2
2
|
|
3
3
|
#----------------------------------------------------------------------#
|
4
|
-
#
|
4
|
+
# Instance Methods #
|
5
5
|
#----------------------------------------------------------------------#
|
6
6
|
|
7
|
+
# Returns the object's RGB value in hexadecimal notation as used in CSS.
|
8
|
+
#
|
9
|
+
# Shortens to 3 digits when possible.
|
10
|
+
def css_hex
|
11
|
+
"##{hex true}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the names of CSS named colors identical to this color.
|
15
|
+
# @example
|
16
|
+
# RGB.hex('f0f').css_names
|
17
|
+
def css_names
|
18
|
+
RGB.css(self).map &:name
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the color's relative luminance, as defined by the Web Content Accessibility Guidelines (WCAG) 2.0.
|
22
|
+
#
|
23
|
+
# This is different from the Y component of CIE 1931 XYZ.
|
24
|
+
#
|
25
|
+
# Based on:
|
26
|
+
# - https://www.w3.org/TR/WCAG20/#relativeluminancedef
|
27
|
+
def wcag20_luminance(round: true)
|
28
|
+
if color_space == 'sRGB'
|
29
|
+
values.map { |v|
|
30
|
+
if v <= 0.03928
|
31
|
+
v / 12.92
|
32
|
+
else
|
33
|
+
( ( v + 0.055 ) / 1.055 ) ** 2.4
|
34
|
+
end
|
35
|
+
}.zip( [0.2126, 0.7152, 0.0722] ).map { |c,f|
|
36
|
+
c * f
|
37
|
+
}.inject(:+).instance_eval { |v| round ? v.round(8) : v }
|
38
|
+
else
|
39
|
+
raise "can not calculate luminance for color space '#{color_space}'"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the contrast ratio for this color and another color, as defined by the Web Content Accessibility Guidelines (WCAG) 2.0.
|
44
|
+
#
|
45
|
+
# Based on:
|
46
|
+
# - https://www.w3.org/TR/WCAG20/#contrast-ratiodef
|
47
|
+
def wcag20_contrast_ratio(another, round: true)
|
48
|
+
luminances = [
|
49
|
+
wcag20_luminance(round: false),
|
50
|
+
another.wcag20_luminance(round: false)
|
51
|
+
].sort.reverse
|
52
|
+
|
53
|
+
contrast_ratio = ( luminances[0] + 0.05 ) / ( luminances[1] + 0.05 )
|
54
|
+
|
55
|
+
round ? contrast_ratio.round(8) : contrast_ratio
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns true if this is one of the 216 so-called "web safe" colors, otherwise false.
|
59
|
+
def web_safe?
|
60
|
+
( values - [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] ).empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
#----------------------------------------------------------------------#
|
66
|
+
# Module Methods #
|
67
|
+
#----------------------------------------------------------------------#
|
68
|
+
|
69
|
+
module RGB
|
70
|
+
|
7
71
|
class << self
|
8
72
|
|
9
73
|
# Returns CSS named colors, as per CSS Color Module Level 4.
|
@@ -42,7 +106,7 @@ class RGB
|
|
42
106
|
@@css.select { |c| c.name =~ r }
|
43
107
|
when Integer
|
44
108
|
@@css[selector]
|
45
|
-
when
|
109
|
+
when RGB::Color
|
46
110
|
@@css.select { |c| c == selector }
|
47
111
|
else
|
48
112
|
raise ArgumentError, 'Unsupported selector'
|
@@ -51,15 +115,4 @@ class RGB
|
|
51
115
|
|
52
116
|
end
|
53
117
|
|
54
|
-
#----------------------------------------------------------------------#
|
55
|
-
# Instance Methods #
|
56
|
-
#----------------------------------------------------------------------#
|
57
|
-
|
58
|
-
# Returns the object's RGB value in hexadecimal notation as used in CSS.
|
59
|
-
#
|
60
|
-
# Shortens to 3 digits when possible.
|
61
|
-
def css_hex
|
62
|
-
"##{hex true}"
|
63
|
-
end
|
64
|
-
|
65
118
|
end
|
data/lib/redgreenblue.rb
CHANGED
@@ -1,4 +1,23 @@
|
|
1
|
-
|
1
|
+
# The RGB module is the main namespace for redgreenblue.
|
2
|
+
#
|
3
|
+
# This module has many helper methods for creating RGB::Color objects.
|
4
|
+
# The example below shows seven ways to create an RGB::Color object for the exact same color.
|
5
|
+
# @example
|
6
|
+
# require 'redgreenblue'
|
7
|
+
#
|
8
|
+
# pink = RGB.new(1, 0.6, 0.8)
|
9
|
+
# pink = RGB.rgb(255, 153, 204)
|
10
|
+
# pink = RGB.rrggbb(65535, 39321, 52428)
|
11
|
+
# pink = RGB.hex('f9c')
|
12
|
+
# pink = RGB.hsl(330, 1, 0.8)
|
13
|
+
# pink = RGB.hsv(330, 0.4, 1)
|
14
|
+
# pink = RGB.at(16751052)
|
15
|
+
module RGB
|
16
|
+
|
17
|
+
# This class represents an RGB color.
|
18
|
+
class Color
|
19
|
+
end
|
20
|
+
|
2
21
|
end
|
3
22
|
|
4
23
|
%w(
|
@@ -11,11 +30,11 @@ end
|
|
11
30
|
|
12
31
|
hsl hsv hsb
|
13
32
|
|
14
|
-
ostwald
|
33
|
+
ostwald hwb
|
15
34
|
|
16
35
|
gamma
|
17
36
|
|
18
|
-
cie_1931 cie_1976
|
37
|
+
cie_1931 cie_1976 cie_1994
|
19
38
|
|
20
39
|
name
|
21
40
|
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redgreenblue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lllist.eu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
email:
|
13
|
+
description:
|
14
|
+
email:
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- lib/redgreenblue/bgr24bit.rb
|
24
24
|
- lib/redgreenblue/cie_1931.rb
|
25
25
|
- lib/redgreenblue/cie_1976.rb
|
26
|
+
- lib/redgreenblue/cie_1994.rb
|
26
27
|
- lib/redgreenblue/gamma.rb
|
27
28
|
- lib/redgreenblue/gif.rb
|
28
29
|
- lib/redgreenblue/gpl.rb
|
@@ -31,6 +32,7 @@ files:
|
|
31
32
|
- lib/redgreenblue/hsl.rb
|
32
33
|
- lib/redgreenblue/hsv.rb
|
33
34
|
- lib/redgreenblue/hsx_shared.rb
|
35
|
+
- lib/redgreenblue/hwb.rb
|
34
36
|
- lib/redgreenblue/inspect.rb
|
35
37
|
- lib/redgreenblue/int.rb
|
36
38
|
- lib/redgreenblue/lazy.rb
|
@@ -58,7 +60,7 @@ metadata:
|
|
58
60
|
homepage_uri: https://github.com/lllisteu/redgreenblue
|
59
61
|
changelog_uri: https://github.com/lllisteu/redgreenblue/blob/master/History.md
|
60
62
|
documentation_uri: https://www.rubydoc.info/gems/redgreenblue/RGB
|
61
|
-
post_install_message:
|
63
|
+
post_install_message:
|
62
64
|
rdoc_options: []
|
63
65
|
require_paths:
|
64
66
|
- lib
|
@@ -73,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
75
|
- !ruby/object:Gem::Version
|
74
76
|
version: '0'
|
75
77
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
77
|
-
signing_key:
|
78
|
+
rubygems_version: 3.3.11
|
79
|
+
signing_key:
|
78
80
|
specification_version: 4
|
79
81
|
summary: A simple Ruby library for handling RGB colors.
|
80
82
|
test_files: []
|