Skip to content

Commit 8b71d74

Browse files
authored
Update to ColorAide 2.9 (#256)
* Update to ColorAide 2.9 * Fix some issues with blend and contrast tool * Update color palettes
1 parent ab7925d commit 8b71d74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2835
-1379
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ColorHelper
22

3+
## 6.3.0
4+
5+
- **NEW**: Upgrade to ColorAide 2.9.
6+
- **FIX**: Fix some issues with blend and contrast tool.
7+
38
## 6.2.2
49

510
- **FIX**: Remove regression fix that was fixing a false issue.

ch_tool_blend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def run(
242242
"""Run command."""
243243

244244
self.base = util.get_base_color()
245-
colors = evaluate(color_helper_blend_mode, self.base)
245+
colors = evaluate(self.base, color_helper_blend_mode)
246246
color = None
247247
if colors:
248248
color = colors[-1]

ch_tool_contrast.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,16 @@ def preview(self, text):
226226
colors[1].convert('srgb').clip().to_string(**util.COMMA)
227227
)
228228
return sublime.Html(style + html)
229-
except Exception as e:
230-
print('huh?')
231-
print(e)
229+
except Exception:
232230
return sublime.Html(mdpopups.md2html(self.view, DEF_RATIO.format(style)))
233231

234232
def validate(self, color):
235233
"""Validate."""
236234

237235
try:
238-
colors = evaluate(self.base, color)
236+
colors = evaluate(self.base, color, self.gamut_map)
239237
return len(colors) > 0
240-
except Exception as e:
241-
print('what?')
242-
print(e)
238+
except Exception:
243239
return False
244240

245241

@@ -251,8 +247,9 @@ def run(
251247
):
252248
"""Run command."""
253249

250+
self.setup_gamut_style()
254251
self.base = util.get_base_color()
255-
colors = evaluate(self.base, color_helper_contrast_ratio)
252+
colors = evaluate(self.base, color_helper_contrast_ratio, self.gamut_map)
256253
color = None
257254
if colors:
258255
color = colors[0]

ch_util.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class Color(Base):
5656
UPDATE_COLORS = RE_COLOR_MATCH
5757
COLOR_FMT_1_0 = (0, 1, 0, 'alpha', 19)
5858
COLOR_FMT_2_0 = (0, 3, 0, 'final')
59-
PALETTE_FMT = (2, 0)
59+
COLOR_FMT_2_9 = (2, 9, 0, 'final')
60+
PALETTE_FMT = (3, 0)
6061

6162
RE_COLOR_START = r"""(?xi)
6263
(?:
@@ -298,6 +299,23 @@ def get_scope(view, rules, skip_sel_check=False):
298299
return scopes
299300

300301

302+
def update_colors_3_0(colors):
303+
"""Update colors for version 3.0."""
304+
305+
base = get_base_color()
306+
new_colors = []
307+
for c in colors:
308+
try:
309+
m = UPDATE_COLORS.match(c)
310+
if m:
311+
new_colors.append(base(m.group(0)).to_string(**COLOR_SERIALIZE))
312+
else:
313+
new_colors.append(c)
314+
except Exception:
315+
pass
316+
return new_colors
317+
318+
301319
def update_colors_2_0(colors):
302320
"""Update colors for version 2.0."""
303321

@@ -356,6 +374,19 @@ def update_colors_1_0(colors):
356374
return new_colors
357375

358376

377+
def update_format(palettes, version, callback):
378+
"""Update the format."""
379+
380+
favs = callback(palettes.get('favorites', []))
381+
palettes.set('favorites', favs)
382+
all_pallets = palettes.get('palettes', [])
383+
for p in all_pallets:
384+
p['colors'] = callback(p['colors'])
385+
palettes.set('palettes', all_pallets)
386+
palettes.set('__format__', version)
387+
sublime.save_settings(PALETTE_CONFIG)
388+
389+
359390
def _get_palettes(window=None):
360391
"""Get palettes."""
361392

@@ -364,25 +395,17 @@ def _get_palettes(window=None):
364395
fmt = tuple([int(x) for x in palettes.get('__format__', '0.0').split('.')])
365396
if fmt != PALETTE_FMT and coloraide_version >= COLOR_FMT_1_0:
366397
if fmt == (0, 0):
367-
favs = update_colors_1_0(palettes.get('favorites', []))
368-
palettes.set('favorites', favs)
369-
all_pallets = palettes.get('palettes', [])
370-
for p in all_pallets:
371-
p['colors'] = update_colors_1_0(p['colors'])
372-
palettes.set('palettes', all_pallets)
373-
palettes.set('__format__', '1.0')
374-
sublime.save_settings(PALETTE_CONFIG)
398+
update_format(palettes, '1.0', update_colors_1_0)
375399
fmt = (1, 0)
376400
if fmt != PALETTE_FMT and coloraide_version >= COLOR_FMT_2_0:
377401
if fmt == (1, 0):
378-
favs = update_colors_2_0(palettes.get('favorites', []))
379-
palettes.set('favorites', favs)
380-
all_pallets = palettes.get('palettes', [])
381-
for p in all_pallets:
382-
p['colors'] = update_colors_1_0(p['colors'])
383-
palettes.set('palettes', all_pallets)
384-
palettes.set('__format__', '2.0')
385-
sublime.save_settings(PALETTE_CONFIG)
402+
update_format(palettes, '2.0', update_colors_2_0)
403+
fmt = (2, 0)
404+
if fmt != PALETTE_FMT and coloraide_version >= COLOR_FMT_2_9:
405+
if fmt == (2, 0):
406+
update_format(palettes, '3.0', update_colors_3_0)
407+
fmt = (3, 0)
408+
386409
else:
387410
data = window.project_data()
388411
if data is None:

lib/coloraide/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,5 @@ def parse_version(ver: str) -> Version:
192192
return Version(major, minor, micro, release, pre, post, dev)
193193

194194

195-
__version_info__ = Version(2, 4, 0, "final")
195+
__version_info__ = Version(2, 9, 0, "final")
196196
__version__ = __version_info__._get_canonical()

0 commit comments

Comments
 (0)