unmagic-color 0.2.0 → 0.2.1
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/CHANGELOG.md +7 -0
- data/README.md +12 -25
- data/lib/unmagic/color/console/help.rb +1 -1
- data/lib/unmagic/color/hsl.rb +9 -0
- data/lib/unmagic/color/oklch.rb +9 -0
- data/lib/unmagic/color/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: 276b2cc6192a6fea7e69f4893c9989434e8101c3e9c6a88b56996eeeeb910262
|
|
4
|
+
data.tar.gz: cd421ccce7640490b140a74a62640ee9dbbb6060f815d770b14ac12e4b1ff991
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2da573372028a3d08793d01bcd9245a24fc88934085b081712934e4606a2d60ff03d8c8f6f94b06abb2fb6817e1b5b0acdf8ac2fd332e1d9f9b2923a90221d5c
|
|
7
|
+
data.tar.gz: 8a17575b7f89b7f9c29d613208972242bd851e42b25659a7533a4c6ed156ce14f9f9396148aa6e171ad5a8e0159395d8e9f9e28b881fa000bbdeb6492cc40388
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2026-01-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `to_hex` method for HSL colors (converts via RGB)
|
|
14
|
+
- `to_hex` method for OKLCH colors (converts via RGB)
|
|
15
|
+
|
|
10
16
|
## [0.2.0] - 2026-01-05
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -75,5 +81,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
75
81
|
- HSL color progressions for palette generation
|
|
76
82
|
- Multiple hash functions for string-to-color derivation
|
|
77
83
|
|
|
84
|
+
[0.2.1]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.2.1
|
|
78
85
|
[0.2.0]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.2.0
|
|
79
86
|
[0.1.0]: https://github.com/unreasonable-magic/unmagic-color/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -159,31 +159,22 @@ Generate color palettes based on color theory relationships:
|
|
|
159
159
|
color = Unmagic::Color.parse("#FF5733")
|
|
160
160
|
|
|
161
161
|
# Complementary - opposite on the color wheel (180°)
|
|
162
|
-
|
|
163
|
-
# => Single color opposite on the wheel
|
|
162
|
+
color.complementary.to_hex # => "#33daff"
|
|
164
163
|
|
|
165
164
|
# Analogous - adjacent colors (default ±30°)
|
|
166
|
-
analogous
|
|
167
|
-
# => [color at -30°, color at +30°]
|
|
168
|
-
analogous = color.analogous(angle: 15) # Custom angle
|
|
165
|
+
color.analogous.map(&:to_hex) # => ["#ff3374", "#ffbe33"]
|
|
169
166
|
|
|
170
167
|
# Triadic - three colors equally spaced (120° apart)
|
|
171
|
-
triadic
|
|
172
|
-
# => [color at +120°, color at +240°]
|
|
168
|
+
color.triadic.map(&:to_hex) # => ["#33ff58", "#5833ff"]
|
|
173
169
|
|
|
174
170
|
# Split Complementary - complement's neighbors (default 180° ±30°)
|
|
175
|
-
|
|
176
|
-
# => [color at 150°, color at 210°]
|
|
177
|
-
split = color.split_complementary(angle: 45) # Custom split
|
|
171
|
+
color.split_complementary.map(&:to_hex) # => ["#33ffbe", "#3374ff"]
|
|
178
172
|
|
|
179
173
|
# Tetradic Square - four colors equally spaced (90° apart)
|
|
180
|
-
|
|
181
|
-
# => [color at +90°, color at +180°, color at +270°]
|
|
174
|
+
color.tetradic_square.map(&:to_hex) # => ["#74ff33", "#33daff", "#be33ff"]
|
|
182
175
|
|
|
183
176
|
# Tetradic Rectangle - two complementary pairs (default 60°)
|
|
184
|
-
|
|
185
|
-
# => [color at +60°, color at +180°, color at +240°]
|
|
186
|
-
tetradic = color.tetradic_rectangle(angle: 30) # Custom angle
|
|
177
|
+
color.tetradic_rectangle.map(&:to_hex) # => ["#daff33", "#33daff", "#5833ff"]
|
|
187
178
|
```
|
|
188
179
|
|
|
189
180
|
### Color Variations
|
|
@@ -196,8 +187,7 @@ Generate shades, tints, tones, and monochromatic palettes:
|
|
|
196
187
|
color = Unmagic::Color.parse("#3366CC")
|
|
197
188
|
|
|
198
189
|
# Monochromatic - same hue with varying lightness
|
|
199
|
-
|
|
200
|
-
# => Array of 5 colors from dark to light
|
|
190
|
+
color.monochromatic(steps: 5).map(&:to_hex) # => ["#0f1f3d", "#214285", "#3366cc", "#7a9cde", "#c2d1f0"]
|
|
201
191
|
|
|
202
192
|
# Shades - progressively darker (mixed with black)
|
|
203
193
|
shades = color.shades(steps: 5)
|
|
@@ -216,11 +206,11 @@ All harmony and variation methods preserve the original color space:
|
|
|
216
206
|
|
|
217
207
|
```ruby
|
|
218
208
|
hsl = Unmagic::Color::HSL.new(hue: 200, saturation: 80, lightness: 50)
|
|
219
|
-
hsl.complementary # =>
|
|
220
|
-
hsl.shades(steps: 3)
|
|
209
|
+
hsl.complementary.to_hex # => "#e65e19"
|
|
210
|
+
hsl.shades(steps: 3).map(&:to_hex) # => ["#1587bf", "#116c99", "#0d5173"]
|
|
221
211
|
|
|
222
212
|
rgb = Unmagic::Color.parse("#FF5733")
|
|
223
|
-
rgb.analogous
|
|
213
|
+
rgb.analogous.map(&:to_hex) # => ["#ff3374", "#ffbe33"]
|
|
224
214
|
```
|
|
225
215
|
|
|
226
216
|
### HSL-Specific Features
|
|
@@ -234,11 +224,8 @@ muted = hsl.desaturate(0.3)
|
|
|
234
224
|
shifted = hsl.adjust_hue(30)
|
|
235
225
|
|
|
236
226
|
# Create color progressions
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
lightness: [30, 50, 70, 85, 95]
|
|
240
|
-
)
|
|
241
|
-
# => Array of 5 HSL colors with varying lightness
|
|
227
|
+
hsl.progression(steps: 5, lightness: [30, 50, 70, 85, 95]).map(&:to_hex)
|
|
228
|
+
# => ["#175e82", "#269dd9", "#7dc4e8", "#bee2f4", "#e9f5fb"]
|
|
242
229
|
```
|
|
243
230
|
|
|
244
231
|
### Generating Colors from Strings
|
|
@@ -14,7 +14,7 @@ module Unmagic
|
|
|
14
14
|
#
|
|
15
15
|
# @return [String] The formatted help text
|
|
16
16
|
def render
|
|
17
|
-
link = highlighter.link("https://github.com/
|
|
17
|
+
link = highlighter.link("https://github.com/unreasonable-magic/unmagic-color")
|
|
18
18
|
|
|
19
19
|
code = highlighter.highlight(<<~RUBY)
|
|
20
20
|
# Parse colors
|
data/lib/unmagic/color/hsl.rb
CHANGED
|
@@ -291,6 +291,15 @@ module Unmagic
|
|
|
291
291
|
to_rgb.to_oklch
|
|
292
292
|
end
|
|
293
293
|
|
|
294
|
+
# Convert to hex string.
|
|
295
|
+
#
|
|
296
|
+
# Converts via RGB as an intermediate step.
|
|
297
|
+
#
|
|
298
|
+
# @return [String] The color as a hex string (e.g., "#ff5733")
|
|
299
|
+
def to_hex
|
|
300
|
+
to_rgb.to_hex
|
|
301
|
+
end
|
|
302
|
+
|
|
294
303
|
# Calculate the relative luminance.
|
|
295
304
|
#
|
|
296
305
|
# Converts to RGB first, then calculates luminance.
|
data/lib/unmagic/color/oklch.rb
CHANGED
|
@@ -302,6 +302,15 @@ module Unmagic
|
|
|
302
302
|
Unmagic::Color::RGB.new(red: r, green: g, blue: b, alpha: @alpha)
|
|
303
303
|
end
|
|
304
304
|
|
|
305
|
+
# Convert to hex string.
|
|
306
|
+
#
|
|
307
|
+
# Converts via RGB as an intermediate step.
|
|
308
|
+
#
|
|
309
|
+
# @return [String] The color as a hex string (e.g., "#ff5733")
|
|
310
|
+
def to_hex
|
|
311
|
+
to_rgb.to_hex
|
|
312
|
+
end
|
|
313
|
+
|
|
305
314
|
# Calculate the relative luminance.
|
|
306
315
|
#
|
|
307
316
|
# In OKLCH, the lightness value directly represents perceptual luminance,
|