color_contrast_calc 0.2.0 → 0.3.0
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/.rubocop.yml +1 -1
- data/README.ja.md +2 -1
- data/README.md +2 -1
- data/lib/color_contrast_calc/checker.rb +29 -4
- data/lib/color_contrast_calc/color.rb +3 -3
- data/lib/color_contrast_calc/sorter.rb +3 -4
- data/lib/color_contrast_calc/threshold_finder.rb +118 -106
- data/lib/color_contrast_calc/utils.rb +9 -0
- data/lib/color_contrast_calc/version.rb +1 -1
- data/lib/color_contrast_calc.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 624186d8778091959fe8526cba79cbe56708c16d
|
4
|
+
data.tar.gz: 2961fad47dfc7afa4b4893dd3d7b0995a97e5601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a28e5639b5db61cb0a722a1802b6969d1bb2c20d60783efd9242094f76e984987bd16330d37ac2f36f480c25b81b2679617035159dde4f74798c101a7b7e0de8
|
7
|
+
data.tar.gz: 5f95b64878aba232ed3923849de80776c33229a899fb76014ed397fa3918f89ab869cc690546cbe49ee68f8f970944f4e315ef23beb29fdfae0391f26b1efdcc
|
data/.rubocop.yml
CHANGED
data/README.ja.md
CHANGED
@@ -208,7 +208,8 @@ The grayscale of #ffa500 is #acacac.
|
|
208
208
|
|
209
209
|
### 例4: 色をソートする
|
210
210
|
|
211
|
-
`ColorContrastCalc::Sorter.sort
|
211
|
+
`ColorContrastCalc::Sorter.sort`もしくはその別名`ColorContrastCalc.sort`
|
212
|
+
を使って色のソートができます。
|
212
213
|
|
213
214
|
またこのメソッドの2番目の引数でソート順を指定することもできます。
|
214
215
|
|
data/README.md
CHANGED
@@ -207,7 +207,8 @@ are available for `ColorContrastCalc::Color`:
|
|
207
207
|
|
208
208
|
### Example 4: Sort colors
|
209
209
|
|
210
|
-
You can sort colors using a method `ColorContrastCalc::Sorter.sort
|
210
|
+
You can sort colors using a method `ColorContrastCalc::Sorter.sort` or
|
211
|
+
its alias `ColorContrastCalc.sort`.
|
211
212
|
|
212
213
|
And by passing the second argument to this method, you can also specify
|
213
214
|
the sort order.
|
@@ -25,13 +25,20 @@ module ColorContrastCalc
|
|
25
25
|
AAA = 'AAA'
|
26
26
|
end
|
27
27
|
|
28
|
+
##
|
29
|
+
# The relative luminance of some colors.
|
30
|
+
|
31
|
+
module Luminance
|
32
|
+
# The relative luminance of white
|
33
|
+
WHITE = 1.0
|
34
|
+
# The relative luminance of black
|
35
|
+
BLACK = 0.0
|
36
|
+
end
|
37
|
+
|
28
38
|
LEVEL_TO_RATIO = {
|
29
39
|
Level::AAA => 7,
|
30
40
|
Level::AA => 4.5,
|
31
|
-
Level::A => 3
|
32
|
-
3 => 7,
|
33
|
-
2 => 4.5,
|
34
|
-
1 => 3
|
41
|
+
Level::A => 3
|
35
42
|
}.freeze
|
36
43
|
|
37
44
|
private_constant :LEVEL_TO_RATIO
|
@@ -120,7 +127,25 @@ module ColorContrastCalc
|
|
120
127
|
# @return [Float] Contrast ratio
|
121
128
|
|
122
129
|
def self.level_to_ratio(level)
|
130
|
+
return level if level.is_a?(Numeric) && level >= 1.0 && level <= 21.0
|
123
131
|
LEVEL_TO_RATIO[level]
|
124
132
|
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Check if the contrast ratio of a given color against black is higher
|
136
|
+
# than against white.
|
137
|
+
#
|
138
|
+
# @param color [String, Array<Integer>] RGB color given as a string or
|
139
|
+
# an array of integers. Yellow, for example, can be given as "#ffff00"
|
140
|
+
# or [255, 255, 0].
|
141
|
+
# @return [Boolean] true if the contrast ratio against white is qual to
|
142
|
+
# or less than the ratio against black
|
143
|
+
|
144
|
+
def self.light_color?(color)
|
145
|
+
l = relative_luminance(color)
|
146
|
+
ratio_with_white = luminance_to_contrast_ratio(Luminance::WHITE, l)
|
147
|
+
ratio_with_black = luminance_to_contrast_ratio(Luminance::BLACK, l)
|
148
|
+
ratio_with_white <= ratio_with_black
|
149
|
+
end
|
125
150
|
end
|
126
151
|
end
|
@@ -185,7 +185,7 @@ module ColorContrastCalc
|
|
185
185
|
|
186
186
|
def find_brightness_threshold(other_color, level = Checker::Level::AA)
|
187
187
|
other_color = Color.new(other_color) unless other_color.is_a? Color
|
188
|
-
ThresholdFinder::Brightness.find(
|
188
|
+
Color.new(ThresholdFinder::Brightness.find(rgb, other_color.rgb, level))
|
189
189
|
end
|
190
190
|
|
191
191
|
##
|
@@ -202,7 +202,7 @@ module ColorContrastCalc
|
|
202
202
|
|
203
203
|
def find_lightness_threshold(other_color, level = Checker::Level::AA)
|
204
204
|
other_color = Color.new(other_color) unless other_color.is_a? Color
|
205
|
-
ThresholdFinder::Lightness.find(
|
205
|
+
Color.new(ThresholdFinder::Lightness.find(rgb, other_color.rgb, level))
|
206
206
|
end
|
207
207
|
|
208
208
|
##
|
@@ -338,7 +338,7 @@ module ColorContrastCalc
|
|
338
338
|
# or less than the ratio against black
|
339
339
|
|
340
340
|
def light_color?
|
341
|
-
|
341
|
+
Checker.light_color?(rgb)
|
342
342
|
end
|
343
343
|
|
344
344
|
def generate_new_color(calc, ratio, name = nil)
|
@@ -75,10 +75,9 @@ module ColorContrastCalc
|
|
75
75
|
##
|
76
76
|
# Sort colors in the order specified by +color_order+.
|
77
77
|
#
|
78
|
-
# Sort colors given as
|
79
|
-
# color codes.
|
78
|
+
# Sort colors given as an array of Color instances or hex color codes.
|
80
79
|
#
|
81
|
-
# You can specify sorting order by giving a +color_order+
|
80
|
+
# You can specify sorting order by giving a +color_order+ string, such
|
82
81
|
# as "HSL" or "RGB". A component of +color_order+ on the left side
|
83
82
|
# has a higher sorting precedence, and an uppercase letter means
|
84
83
|
# descending order.
|
@@ -89,7 +88,7 @@ module ColorContrastCalc
|
|
89
88
|
# from items to be sorted
|
90
89
|
# @param key_mapper_block [Proc] Block that is used instead of key_mapper
|
91
90
|
# when the latter is not given
|
92
|
-
# @return [Array<Color>, Array<String>] Array of
|
91
|
+
# @return [Array<Color>, Array<String>] Array of sorted colors
|
93
92
|
|
94
93
|
def self.sort(colors, color_order = 'hSL',
|
95
94
|
key_mapper = nil, &key_mapper_block)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'color_contrast_calc/
|
3
|
+
require 'color_contrast_calc/converter'
|
4
|
+
require 'color_contrast_calc/checker'
|
4
5
|
|
5
6
|
module ColorContrastCalc
|
6
7
|
##
|
@@ -11,12 +12,41 @@ module ColorContrastCalc
|
|
11
12
|
# @private
|
12
13
|
|
13
14
|
module Criteria
|
15
|
+
# @private
|
16
|
+
|
17
|
+
def self.threshold_criteria(level, fixed_rgb, other_rgb)
|
18
|
+
if should_scan_darker_side?(fixed_rgb, other_rgb)
|
19
|
+
return ToDarkerSide.new(level, fixed_rgb)
|
20
|
+
end
|
21
|
+
|
22
|
+
ToBrighterSide.new(level, fixed_rgb)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @private
|
26
|
+
|
27
|
+
def self.should_scan_darker_side?(fixed_rgb, other_rgb)
|
28
|
+
fixed_luminance = Checker.relative_luminance(fixed_rgb)
|
29
|
+
other_luminance = Checker.relative_luminance(other_rgb)
|
30
|
+
fixed_luminance > other_luminance ||
|
31
|
+
fixed_luminance == other_luminance && Checker.light_color?(fixed_rgb)
|
32
|
+
end
|
33
|
+
|
14
34
|
class SearchDirection
|
15
|
-
attr_reader :level, :target_ratio
|
35
|
+
attr_reader :level, :target_ratio, :fixed_luminance
|
16
36
|
|
17
|
-
def initialize(level)
|
37
|
+
def initialize(level, fixed_rgb)
|
18
38
|
@level = level
|
19
39
|
@target_ratio = Checker.level_to_ratio(level)
|
40
|
+
@fixed_luminance = Checker.relative_luminance(fixed_rgb)
|
41
|
+
end
|
42
|
+
|
43
|
+
def sufficient_contrast?(rgb)
|
44
|
+
contrast_ratio(rgb) >= @target_ratio
|
45
|
+
end
|
46
|
+
|
47
|
+
def contrast_ratio(rgb)
|
48
|
+
luminance = Checker.relative_luminance(rgb)
|
49
|
+
Checker.luminance_to_contrast_ratio(@fixed_luminance, luminance)
|
20
50
|
end
|
21
51
|
end
|
22
52
|
|
@@ -49,35 +79,30 @@ module ColorContrastCalc
|
|
49
79
|
end
|
50
80
|
end
|
51
81
|
|
52
|
-
|
53
|
-
|
54
|
-
def self.threshold_criteria(level, fixed_color, other_color)
|
55
|
-
if should_scan_darker_side?(fixed_color, other_color)
|
56
|
-
return Criteria::ToDarkerSide.new(level)
|
57
|
-
end
|
58
|
-
|
59
|
-
Criteria::ToBrighterSide.new(level)
|
60
|
-
end
|
61
|
-
|
62
|
-
# @private
|
82
|
+
module FinderUtils
|
83
|
+
# @private
|
63
84
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
85
|
+
def self.binary_search_width(init_width, min)
|
86
|
+
i = 1
|
87
|
+
init_width = init_width.to_f
|
88
|
+
d = init_width / 2**i
|
68
89
|
|
69
|
-
|
90
|
+
while d > min
|
91
|
+
yield d
|
92
|
+
i += 1
|
93
|
+
d = init_width / 2**i
|
94
|
+
end
|
95
|
+
end
|
70
96
|
|
71
|
-
|
72
|
-
i = 1
|
73
|
-
init_width = init_width.to_f
|
74
|
-
d = init_width / 2**i
|
97
|
+
# @private
|
75
98
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
99
|
+
def sufficient_contrast?(fixed_rgb, other_rgb, level)
|
100
|
+
target_ratio = Checker.level_to_ratio(level)
|
101
|
+
ratio = Checker.contrast_ratio(fixed_rgb, other_rgb)
|
102
|
+
ratio >= target_ratio
|
80
103
|
end
|
104
|
+
|
105
|
+
private :sufficient_contrast?
|
81
106
|
end
|
82
107
|
|
83
108
|
##
|
@@ -85,57 +110,55 @@ module ColorContrastCalc
|
|
85
110
|
# +Color#find_brightness_threshold()+.
|
86
111
|
|
87
112
|
module Brightness
|
113
|
+
extend FinderUtils
|
114
|
+
|
88
115
|
##
|
89
116
|
# Try to find a color who has a satisfying contrast ratio.
|
90
117
|
#
|
91
118
|
# The color returned by this method will be created by changing the
|
92
|
-
# brightness of +
|
119
|
+
# brightness of +other_rgb+. Even when a color that satisfies the
|
93
120
|
# specified level is not found, the method returns a new color anyway.
|
94
|
-
# @param
|
95
|
-
# @param
|
121
|
+
# @param fixed_rgb [Array<Integer>] RGB value which remains unchanged
|
122
|
+
# @param other_rgb [Array<Integer>] RGB value before the adjustment of
|
123
|
+
# brightness
|
96
124
|
# @param level [String] "A", "AA" or "AAA"
|
97
|
-
# @return [
|
98
|
-
# +
|
125
|
+
# @return [Array<Integer>] RGB value of a new color whose brightness is
|
126
|
+
# adjusted from that of +other_rgb+
|
99
127
|
|
100
|
-
def self.find(
|
101
|
-
criteria =
|
102
|
-
|
103
|
-
w = calc_upper_ratio_limit(other_color) / 2.0
|
128
|
+
def self.find(fixed_rgb, other_rgb, level = Checker::Level::AA)
|
129
|
+
criteria = Criteria.threshold_criteria(level, fixed_rgb, other_rgb)
|
130
|
+
w = calc_upper_ratio_limit(other_rgb) / 2.0
|
104
131
|
|
105
|
-
|
106
|
-
return
|
132
|
+
upper_rgb = upper_limit_rgb(criteria, other_rgb, w * 2)
|
133
|
+
return upper_rgb if upper_rgb
|
107
134
|
|
108
|
-
r, sufficient_r = calc_brightness_ratio(
|
109
|
-
other_color.rgb, criteria, w)
|
135
|
+
r, sufficient_r = calc_brightness_ratio(other_rgb, criteria, w)
|
110
136
|
|
111
|
-
generate_satisfying_color(
|
112
|
-
r, sufficient_r)
|
137
|
+
generate_satisfying_color(other_rgb, criteria, r, sufficient_r)
|
113
138
|
end
|
114
139
|
|
115
|
-
def self.
|
116
|
-
|
117
|
-
|
118
|
-
if exceed_upper_limit?(fixed_color, other_color, limit_color, level)
|
119
|
-
limit_color
|
120
|
-
end
|
140
|
+
def self.upper_limit_rgb(criteria, other_rgb, max_ratio)
|
141
|
+
limit_rgb = Converter::Brightness.calc_rgb(other_rgb, max_ratio)
|
142
|
+
limit_rgb if exceed_upper_limit?(criteria, other_rgb, limit_rgb)
|
121
143
|
end
|
122
144
|
|
123
|
-
private_class_method :
|
145
|
+
private_class_method :upper_limit_rgb
|
124
146
|
|
125
|
-
def self.exceed_upper_limit?(
|
126
|
-
|
127
|
-
|
147
|
+
def self.exceed_upper_limit?(criteria, other_rgb, limit_rgb)
|
148
|
+
other_luminance = Checker.relative_luminance(other_rgb)
|
149
|
+
other_luminance > criteria.fixed_luminance &&
|
150
|
+
!criteria.sufficient_contrast?(limit_rgb)
|
128
151
|
end
|
129
152
|
|
130
153
|
private_class_method :exceed_upper_limit?
|
131
154
|
|
132
|
-
def self.calc_brightness_ratio(
|
155
|
+
def self.calc_brightness_ratio(other_rgb, criteria, w)
|
133
156
|
target_ratio = criteria.target_ratio
|
134
157
|
r = w
|
135
158
|
sufficient_r = nil
|
136
159
|
|
137
|
-
|
138
|
-
contrast_ratio = calc_contrast_ratio(
|
160
|
+
FinderUtils.binary_search_width(w, 0.01) do |d|
|
161
|
+
contrast_ratio = calc_contrast_ratio(criteria, other_rgb, r)
|
139
162
|
|
140
163
|
sufficient_r = r if contrast_ratio >= target_ratio
|
141
164
|
break if contrast_ratio == target_ratio
|
@@ -148,13 +171,12 @@ module ColorContrastCalc
|
|
148
171
|
|
149
172
|
private_class_method :calc_brightness_ratio
|
150
173
|
|
151
|
-
def self.generate_satisfying_color(
|
152
|
-
|
153
|
-
level = criteria.level
|
154
|
-
nearest = other_color.new_brightness_color(criteria.round(r))
|
174
|
+
def self.generate_satisfying_color(other_rgb, criteria, r, sufficient_r)
|
175
|
+
nearest = Converter::Brightness.calc_rgb(other_rgb, criteria.round(r))
|
155
176
|
|
156
|
-
if sufficient_r && !
|
157
|
-
return
|
177
|
+
if sufficient_r && !criteria.sufficient_contrast?(nearest)
|
178
|
+
return Converter::Brightness.calc_rgb(other_rgb,
|
179
|
+
criteria.round(sufficient_r))
|
158
180
|
end
|
159
181
|
|
160
182
|
nearest
|
@@ -162,19 +184,17 @@ module ColorContrastCalc
|
|
162
184
|
|
163
185
|
private_class_method :generate_satisfying_color
|
164
186
|
|
165
|
-
def self.calc_contrast_ratio(
|
166
|
-
|
167
|
-
new_luminance = Checker.relative_luminance(new_rgb)
|
168
|
-
Checker.luminance_to_contrast_ratio(fixed_luminance, new_luminance)
|
187
|
+
def self.calc_contrast_ratio(criteria, other_rgb, r)
|
188
|
+
criteria.contrast_ratio(Converter::Brightness.calc_rgb(other_rgb, r))
|
169
189
|
end
|
170
190
|
|
171
191
|
private_class_method :calc_contrast_ratio
|
172
192
|
|
173
193
|
# @private
|
174
194
|
|
175
|
-
def self.calc_upper_ratio_limit(
|
176
|
-
return 100 if
|
177
|
-
darkest =
|
195
|
+
def self.calc_upper_ratio_limit(rgb)
|
196
|
+
return 100 if rgb == Rgb::BLACK
|
197
|
+
darkest = rgb.reject(&:zero?).min
|
178
198
|
((255.0 / darkest) * 100).ceil
|
179
199
|
end
|
180
200
|
end
|
@@ -184,61 +204,61 @@ module ColorContrastCalc
|
|
184
204
|
# +Color#find_lightness_threshold()+.
|
185
205
|
|
186
206
|
module Lightness
|
207
|
+
extend FinderUtils
|
208
|
+
|
187
209
|
##
|
188
210
|
# Try to find a color who has a satisfying contrast ratio.
|
189
211
|
#
|
190
212
|
# The color returned by this method will be created by changing the
|
191
|
-
# lightness of +
|
213
|
+
# lightness of +other_rgb+. Even when a color that satisfies the
|
192
214
|
# specified level is not found, the method returns a new color anyway.
|
193
|
-
# @param
|
194
|
-
# @param
|
215
|
+
# @param fixed_rgb [Array<Integer>] RGB value which remains unchanged
|
216
|
+
# @param other_rgb [Array<Integer>] RGB value before the adjustment of
|
217
|
+
# lightness
|
195
218
|
# @param level [String] "A", "AA" or "AAA"
|
196
|
-
# @return [
|
197
|
-
# +
|
219
|
+
# @return [Array<Integer>] RGB value of a new color whose lightness is
|
220
|
+
# adjusted from that of +other_rgb+
|
198
221
|
|
199
|
-
def self.find(
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
max, min = determine_minmax(fixed_color, other_color, init_l)
|
222
|
+
def self.find(fixed_rgb, other_rgb, level = Checker::Level::AA)
|
223
|
+
other_hsl = Utils.rgb_to_hsl(other_rgb)
|
224
|
+
criteria = Criteria.threshold_criteria(level, fixed_rgb, other_rgb)
|
225
|
+
max, min = determine_minmax(fixed_rgb, other_rgb, other_hsl[2])
|
204
226
|
|
205
|
-
boundary_color = lightness_boundary_color(
|
227
|
+
boundary_color = lightness_boundary_color(fixed_rgb, max, min, level)
|
206
228
|
return boundary_color if boundary_color
|
207
229
|
|
208
|
-
l, sufficient_l = calc_lightness_ratio(
|
209
|
-
criteria, max, min)
|
230
|
+
l, sufficient_l = calc_lightness_ratio(other_hsl, criteria, max, min)
|
210
231
|
|
211
|
-
generate_satisfying_color(
|
212
|
-
l, sufficient_l)
|
232
|
+
generate_satisfying_color(other_hsl, criteria, l, sufficient_l)
|
213
233
|
end
|
214
234
|
|
215
|
-
def self.determine_minmax(
|
216
|
-
scan_darker_side =
|
217
|
-
|
235
|
+
def self.determine_minmax(fixed_rgb, other_rgb, init_l)
|
236
|
+
scan_darker_side = Criteria.should_scan_darker_side?(fixed_rgb,
|
237
|
+
other_rgb)
|
218
238
|
scan_darker_side ? [init_l, 0] : [100, init_l] # [max, min]
|
219
239
|
end
|
220
240
|
|
221
241
|
private_class_method :determine_minmax
|
222
242
|
|
223
|
-
def self.lightness_boundary_color(
|
224
|
-
if min.zero? && !
|
225
|
-
return
|
243
|
+
def self.lightness_boundary_color(rgb, max, min, level)
|
244
|
+
if min.zero? && !sufficient_contrast?(Rgb::BLACK, rgb, level)
|
245
|
+
return Rgb::BLACK
|
226
246
|
end
|
227
247
|
|
228
|
-
if max == 100 && !
|
229
|
-
return
|
248
|
+
if max == 100 && !sufficient_contrast?(Rgb::WHITE, rgb, level)
|
249
|
+
return Rgb::WHITE
|
230
250
|
end
|
231
251
|
end
|
232
252
|
|
233
253
|
private_class_method :lightness_boundary_color
|
234
254
|
|
235
|
-
def self.calc_lightness_ratio(
|
255
|
+
def self.calc_lightness_ratio(other_hsl, criteria, max, min)
|
236
256
|
h, s, = other_hsl
|
237
257
|
l = (max + min) / 2.0
|
238
258
|
sufficient_l = nil
|
239
259
|
|
240
|
-
|
241
|
-
contrast_ratio =
|
260
|
+
FinderUtils.binary_search_width(max - min, 0.01) do |d|
|
261
|
+
contrast_ratio = criteria.contrast_ratio(Utils.hsl_to_rgb([h, s, l]))
|
242
262
|
|
243
263
|
sufficient_l = l if contrast_ratio >= criteria.target_ratio
|
244
264
|
break if contrast_ratio == criteria.target_ratio
|
@@ -251,20 +271,12 @@ module ColorContrastCalc
|
|
251
271
|
|
252
272
|
private_class_method :calc_lightness_ratio
|
253
273
|
|
254
|
-
def self.
|
255
|
-
fixed_color.contrast_ratio_against(Utils.hsl_to_rgb(hsl))
|
256
|
-
end
|
257
|
-
|
258
|
-
private_class_method :calc_contrast_ratio
|
259
|
-
|
260
|
-
def self.generate_satisfying_color(fixed_color, other_hsl, criteria,
|
261
|
-
l, sufficient_l)
|
274
|
+
def self.generate_satisfying_color(other_hsl, criteria, l, sufficient_l)
|
262
275
|
h, s, = other_hsl
|
263
|
-
|
264
|
-
nearest = Color.new_from_hsl([h, s, l])
|
276
|
+
nearest = Utils.hsl_to_rgb([h, s, l])
|
265
277
|
|
266
|
-
if sufficient_l && !
|
267
|
-
return
|
278
|
+
if sufficient_l && !criteria.sufficient_contrast?(nearest)
|
279
|
+
return Utils.hsl_to_rgb([h, s, sufficient_l])
|
268
280
|
end
|
269
281
|
|
270
282
|
nearest
|
@@ -237,4 +237,13 @@ module ColorContrastCalc
|
|
237
237
|
!/[[:lower:]]/.match?(str)
|
238
238
|
end
|
239
239
|
end
|
240
|
+
|
241
|
+
##
|
242
|
+
# RGB values of some colors.
|
243
|
+
|
244
|
+
module Rgb
|
245
|
+
BLACK = [0, 0, 0].freeze
|
246
|
+
GRAY = [128, 128, 128].freeze
|
247
|
+
WHITE = [255, 255, 255].freeze
|
248
|
+
end
|
240
249
|
end
|
data/lib/color_contrast_calc.rb
CHANGED
@@ -41,10 +41,10 @@ module ColorContrastCalc
|
|
41
41
|
##
|
42
42
|
# Sort colors in the order specified by +color_order+.
|
43
43
|
#
|
44
|
-
# Sort colors given as
|
45
|
-
#
|
44
|
+
# Sort colors given as an array of Color instances or hex color codes.
|
45
|
+
# (alias of Sorter.sort())
|
46
46
|
#
|
47
|
-
# You can specify sorting order by giving a +color_order+
|
47
|
+
# You can specify sorting order by giving a +color_order+ string, such
|
48
48
|
# as "HSL" or "RGB". A component of +color_order+ on the left side
|
49
49
|
# has a higher sorting precedence, and an uppercase letter means
|
50
50
|
# descending order.
|
@@ -55,7 +55,7 @@ module ColorContrastCalc
|
|
55
55
|
# from items to be sorted
|
56
56
|
# @param key_mapper_block [Proc] Block that is used instead of key_mapper
|
57
57
|
# when the latter is not given
|
58
|
-
# @return [Array<Color>, Array<String>] Array of
|
58
|
+
# @return [Array<Color>, Array<String>] Array of sorted colors
|
59
59
|
|
60
60
|
def self.sort(colors, color_order = 'hSL',
|
61
61
|
key_mapper = nil, &key_mapper_block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_contrast_calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HASHIMOTO, Naoki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|