kiso 0.5.2.pre → 0.5.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60861d160167adf83488de026f4bc6e3ae9a6ec90ce04cb5862f0ce5ec1a4567
4
- data.tar.gz: d6c5017ed994250be02db77345fdf14c6b72f7971837f7fdc86c6f27a5701dc4
3
+ metadata.gz: 0e2ae8ad60d92d8f26f348cfcf1dc7e244ab9d43d8650c70bb55563a569ebd92
4
+ data.tar.gz: 75bcf4fd1147c79754256ab6c3cccd994a1b5a7ace087fd52529e716d7521422
5
5
  SHA512:
6
- metadata.gz: 7046fc1419c4bb2ca1a2096b11965f714bd91743c70605278bb4ebf9a1d041bad38b073a038aad9f717e730b469841e4532f76752ee952389b7f908b310f8fd0
7
- data.tar.gz: 6910db9bd5316e5a556f8032e431305b33d86bce7537428fdd9fd8a3074fe66a5943a02b037955670721772d34dadaf2e5ed97a7448c2db1297c357f99243f50
6
+ metadata.gz: 80ddd9d1a892eec79083c535516369d0278c3680ee75fd9e7cbffb406a8684d705805104ee12dd2e8d5a920baa15aa1a445d31c637d0ec8a8a675b05889f96e6
7
+ data.tar.gz: '06824eba6296399c458259426d806da86901040d0922c696efc1f066e0c1feed2c8f405fb09edc5344e54995ef51a932e313291ee77846605315d3e8c433f1ca'
@@ -1,5 +1,5 @@
1
- <%# locals: (src: nil, alt: "", text: nil, size: :md, color: nil, ui: {}, css_classes: "", **component_options) %>
2
- <% text_color = Kiso::ColorUtils.contrast_text_color(color) if color %>
1
+ <%# locals: (src: nil, alt: "", text: nil, size: :md, color: nil, contrast_threshold: nil, ui: {}, css_classes: "", **component_options) %>
2
+ <% text_color = Kiso::ColorUtils.contrast_text_color(color, threshold: contrast_threshold) if color %>
3
3
  <%= content_tag :span,
4
4
  class: Kiso::Themes::Avatar.render(size: size, class: css_classes),
5
5
  style: (color ? "background-color: #{color}; color: #{text_color};" : nil),
@@ -4,13 +4,17 @@ module Kiso
4
4
  module ColorUtils
5
5
  module_function
6
6
 
7
+ DEFAULT_CONTRAST_THRESHOLD = 0.42
8
+
7
9
  # 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).
12
- # Accepts 3-digit (#abc) or 6-digit (#aabbcc) hex strings.
13
- def contrast_text_color(hex)
10
+ # Uses a perceptual threshold (default 0.42) rather than the
11
+ # mathematical midpoint of 0.179, per Lea Verou's research on
12
+ # contrast color generation. The higher threshold produces better
13
+ # results on saturated chromatic colors (e.g. Tailwind 500-shade
14
+ # palette). Accepts 3-digit (#abc) or 6-digit (#aabbcc) hex strings.
15
+ def contrast_text_color(hex, threshold: nil)
16
+ threshold ||= Kiso.config.contrast_threshold
17
+
14
18
  hex = hex.delete("#")
15
19
  hex = hex.chars.map { |c| c * 2 }.join if hex.length == 3
16
20
 
@@ -19,7 +23,7 @@ module Kiso
19
23
  (c <= 0.04045) ? c / 12.92 : ((c + 0.055) / 1.055)**2.4
20
24
  }.then { |lr, lg, lb| 0.2126 * lr + 0.7152 * lg + 0.0722 * lb }
21
25
 
22
- (luminance > 0.36) ? "black" : "white"
26
+ (luminance > threshold) ? "black" : "white"
23
27
  end
24
28
  end
25
29
  end
@@ -33,10 +33,21 @@ module Kiso
33
33
  # end
34
34
  attr_accessor :app_theme
35
35
 
36
+ # @return [Float] luminance threshold for contrast text color calculation.
37
+ # Colors with luminance above this value get black text, below get white.
38
+ # Default is 0.42 (perceptual midpoint per Lea Verou's research).
39
+ #
40
+ # @example Tune for a darker palette
41
+ # Kiso.configure do |config|
42
+ # config.contrast_threshold = 0.36
43
+ # end
44
+ attr_accessor :contrast_threshold
45
+
36
46
  def initialize
37
47
  @icons = default_icons
38
48
  @theme = {}
39
49
  @app_theme = :default
50
+ @contrast_threshold = Kiso::ColorUtils::DEFAULT_CONTRAST_THRESHOLD
40
51
  end
41
52
 
42
53
  # Resolves the active app theme directory path relative to the given root.
data/lib/kiso/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Kiso
4
4
  # @return [String] the current gem version
5
- VERSION = "0.5.2.pre"
5
+ VERSION = "0.5.3.pre"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2.pre
4
+ version: 0.5.3.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Clarke