Skip to content

Commit 9551fbc

Browse files
committed
Improve dark icon fix detection
1 parent 2a5f1a0 commit 9551fbc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/tasks/sprites.thor

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ class SpritesCLI < Thor
9595

9696
def needs_dark_icon_fix(icon, bg_color)
9797
# Determine whether the icon needs to be grayscaled if the user has enabled the dark theme
98-
# The logic comes from https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast
99-
contrast = icon.pixels.map do |pixel|
98+
# The logic is roughly based on https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast
99+
contrast = icon.pixels.select {|pixel| ChunkyPNG::Color.a(pixel) > 0}.map do |pixel|
100100
get_contrast(bg_color, pixel)
101101
end
102102

103-
contrast.max < 7
103+
avg = contrast.reduce(:+) / contrast.size.to_f
104+
avg < 3.5
104105
end
105106

106107
def get_contrast(base, other)
@@ -173,7 +174,8 @@ class SpritesCLI < Thor
173174

174175
def log_details(items_with_icons, icons_per_row)
175176
logger.debug("Amount of icons: #{items_with_icons.length}")
176-
logger.debug("Icons per row: #{icons_per_row}")
177+
logger.debug("Amount of icons needing the dark icon fix: #{items_with_icons.count {|item| item[:dark_icon_fix]}}")
178+
logger.debug("Amount of icons per row: #{icons_per_row}")
177179

178180
max_type_length = items_with_icons.map {|item| item[:type].length}.max
179181
border = "+#{'-' * (max_type_length + 2)}+#{'-' * 5}+#{'-' * 8}+#{'-' * 15}+"

0 commit comments

Comments
 (0)