Skip to content

Commit

Permalink
Merge branch 'upstream_master' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	tox.ini
  • Loading branch information
CodeByZach committed Sep 10, 2021
2 parents 60b5a6e + b717bd8 commit 7275416
Show file tree
Hide file tree
Showing 75 changed files with 1,234 additions and 627 deletions.
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# ColorHelper

## 3.6.1

- **FIX**: Fix issues with [Advanced Substation Alpha (ASS)](https://packagecontrol.io/packages/Advanced%20Substation%20Alpha%20(ASS))
support.
- **FIX**: Remove unnecessary dependencies.

## 3.6.0

- **NEW**: Add support for [Advanced Substation Alpha (ASS)](https://packagecontrol.io/packages/Advanced%20Substation%20Alpha%20(ASS)).

## 3.5.0

- **NEW**: `generic` rule will now allow scanning in strings by default. If this
Expand All @@ -13,6 +23,9 @@
channels must require those channels to be input as percentages per the CSS
level 4 specifications. This affects the string output for the `color()` format
as well.
- **FIX**: Latest `coloraide` improves gamut mapping.
- **FIX**: Small gamut fitting adjustments.
- **FIX**: Fix issue with duplicate previews when working with clone views.

## 3.4.0

Expand Down
18 changes: 17 additions & 1 deletion ColorHelper.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@
"output": [
{"space": "srgb", "format": {"hex": true}}
]
},
// for color codes like `&HAABBGGRR` and `&HBBGGRR`
"ass_abgr": {
"class": "ColorHelper.custom.ass_abgr.ColorAssABGR",
"filters": ["srgb"],
"output": [
{"space": "srgb", "format": {"upper": true}}
]
}
},

Expand Down Expand Up @@ -280,7 +288,7 @@
"PackageDev/Package/Sublime Text Theme/Sublime Text Theme"
],
"color_class": "sublime-colormod",
"color_trigger": "(?i)(?:\\b(?<![-#&$])(?:color|hsla?|hwb|rgba?)\\(|\\b(?<![-#&$])[\\w]{3,}(?![(-])\\b|(?!<&)\\#)",
"color_trigger": "(?i)(?:\\b(?<![-#&$])(?:color\\((?!\\s*-)|(?:hsla?|hwb|rgba?)\\()|\\b(?<![-#&$])[\\w]{3,}(?![(-])\\b|(?!<&)\\#)",
"scanning": [
"source.css-color -meta.function-call.var.sublime-color-scheme -meta.function-call.var.css",
"meta.css.sublime-color-scheme meta.property-value.css -comment -string.quoted.single.css -string.quoted.double.css"
Expand Down Expand Up @@ -379,6 +387,14 @@
"constant.color.w3c-standard-color-name.css",
"meta.property-value.css"
]
},
{
// ASS ( based on: https://packagecontrol.io/packages/Advanced%20Substation%20Alpha%20(ASS) )
"name": "ASS",
"base_scopes": ["text.ass"],
"scanning": ["constant.other.color"],
"color_class": "ass_abgr",
"color_trigger": "(?:&H|(?<=\\\\[1-4]c)|(?<=\\\\c))[0-9a-fA-F]"
}
],

Expand Down
15 changes: 8 additions & 7 deletions ch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .lib.coloraide import Color
from collections import namedtuple

SPACER = Color("transparent", filters=util.SRGB_SPACES).to_string(**HEX)
SPACER = Color("transparent", filters=util.CSS_SRGB_SPACES).to_string(**HEX)


class Preview(namedtuple('Preview', ['preview1', 'preview2', 'border', 'message'])):
Expand All @@ -30,7 +30,7 @@ def setup_image_border(self):
border_color = ch_settings.get('image_border_color')
if border_color is not None:
try:
border_color = Color(border_color, filters=util.SRGB_SPACES)
border_color = Color(border_color, filters=util.CSS_SRGB_SPACES)
border_color.fit("srgb", in_place=True)
except Exception:
border_color = None
Expand All @@ -39,15 +39,15 @@ def setup_image_border(self):
# Calculate border color for images
border_color = Color(
self.view.style()['background'],
filters=util.SRGB_SPACES
filters=util.CSS_SRGB_SPACES
).convert("hsl")
border_color.lightness = border_color.lightness + (30 if border_color.luminance() < 0.5 else -30)

self.default_border = border_color.convert("srgb").to_string(**HEX)
self.out_of_gamut = Color("transparent", filters=util.SRGB_SPACES).to_string(**HEX)
self.out_of_gamut = Color("transparent", filters=util.CSS_SRGB_SPACES).to_string(**HEX)
self.out_of_gamut_border = Color(
self.view.style().get('redish', "red"),
filters=util.SRGB_SPACES
filters=util.CSS_SRGB_SPACES
).to_string(**HEX)

def get_color_options(self, pt, rule):
Expand Down Expand Up @@ -174,7 +174,8 @@ def get_preview(self, color):

message = ''
preview_border = self.default_border
if not color.in_gamut("srgb"):
check_space = 'srgb' if color.space() not in util.SRGB_SPACES else color.space()
if not color.in_gamut(check_space):
message = 'preview out of gamut'
if self.show_out_of_gamut_preview:
srgb = color.convert("srgb", fit=True)
Expand All @@ -185,7 +186,7 @@ def get_preview(self, color):
preview2 = self.out_of_gamut
preview_border = self.out_of_gamut_border
else:
srgb = color.convert("srgb")
srgb = color.convert("srgb", fit=True)
preview1 = srgb.to_string(**HEX_NA)
preview2 = srgb.to_string(**HEX)

Expand Down
12 changes: 8 additions & 4 deletions ch_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def prompt_palette_name(self, palette_type, color):
def create_palette(self, palette_name, palette_type, color):
"""Add color to new color palette."""

color = Color(color).to_string(**util.COLOR_SERIALIZE)

if palette_type == '__global__':
color_palettes = util.get_palettes()
for palette in color_palettes:
Expand All @@ -140,6 +142,8 @@ def create_palette(self, palette_name, palette_type, color):
def add_palette(self, color, palette_type, palette_name):
"""Add palette."""

color = Color(color).to_string(**util.COLOR_SERIALIZE)

if palette_type == "__special__":
if palette_name == 'Favorites':
favs = util.get_favs()['colors']
Expand Down Expand Up @@ -220,7 +224,7 @@ def add_fav(self, color):
"""Add favorite."""

favs = util.get_favs()['colors']
favs.append(color)
favs.append(Color(color).to_string(**util.COLOR_SERIALIZE))
util.save_palettes(favs, favs=True)
# For some reason if using update,
# the convert divider will be too wide.
Expand All @@ -230,7 +234,7 @@ def remove_fav(self, color):
"""Remove favorite."""

favs = util.get_favs()['colors']
favs.remove(color)
favs.remove(Color(color).to_string(**util.COLOR_SERIALIZE))
util.save_palettes(favs, favs=True)
# For some reason if using update,
# the convert divider will be too wide.
Expand Down Expand Up @@ -470,7 +474,7 @@ def format_info(self, obj, template_vars):
template_vars['show_global_palette_menu'] = True
if show_favorite_palette and color_ver_okay:
template_vars['show_favorite_menu'] = True
template_vars['is_marked'] = color.to_string(**util.COLOR_FULL_PREC) in util.get_favs()['colors']
template_vars['is_marked'] = color.to_string(**util.COLOR_SERIALIZE) in util.get_favs()['colors']

preview = self.get_preview(color)
message = ''
Expand Down Expand Up @@ -766,7 +770,7 @@ def run(self, edit, mode, palette_name=None, color=None, insert_raw=None, result
self.no_info = True
obj = self.get_cursor_color()
if obj is None:
color = Color("white", filters=util.SRGB_SPACES).to_string(**util.COLOR_FULL_PREC)
color = Color("white", filters=util.CSS_SRGB_SPACES).to_string(**util.COLOR_FULL_PREC)
else:
color = obj.color.to_string(**util.COLOR_FULL_PREC)
self.color_picker(color)
Expand Down
14 changes: 7 additions & 7 deletions ch_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from mdpopups import colorbox
from .lib.coloraide import Color
from .lib.coloraide import util as cutil
from .lib.coloraide.css.spaces import _color_names as css_names
from .lib.coloraide.spaces.srgb import color_names as css_names
from . import ch_util as util
from .ch_mixin import _ColorMixin
from .ch_util import DEFAULT, COLOR_FULL_PREC, HEX, HEX_NA
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_color_map_square(self):

# Generate the colors with each row being darker than the last.
# Each column will progress through hues.
color = Color("hsl(0 100% {}% / {})".format(lightness, alpha), filters=util.SRGB_SPACES)
color = Color("hsl(0 100% {}% / {})".format(lightness, alpha), filters=util.CSS_SRGB_SPACES)
if color.is_nan("hue"):
color.hue = 0.0
check_size = self.check_size(self.height)
Expand Down Expand Up @@ -150,7 +150,7 @@ def get_color_map_square(self):
color.saturation = color.saturation - 10

# Generate a grayscale bar.
color = Color('hsl({} {}% 100% / {})'.format(hue, saturation, alpha), filters=util.SRGB_SPACES)
color = Color('hsl({} {}% 100% / {})'.format(hue, saturation, alpha), filters=util.CSS_SRGB_SPACES)
if color.is_nan("hue"):
color.hue = 0.0
check_size = self.check_size(self.height)
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_css_color_names(self):
check_size = self.check_size(self.height)
html = []
for name in sorted(css_names.name2hex_map):
color = Color(name, filters=util.SRGB_SPACES)
color = Color(name, filters=util.CSS_SRGB_SPACES)

html.append(
'[{}]({}) {}<br>'.format(
Expand Down Expand Up @@ -331,7 +331,7 @@ def get_channel(self, channel, label, color_filter):
coord = cutil.no_nan(getattr(clone, color_filter)) - step
setattr(clone, color_filter, coord)

if not clone.in_gamut():
if not clone.in_gamut(tolerance=0):
temp.append(self.get_spacer(width=count))
break
elif color_filter == "alpha" and (coord < 0 or coord > 1.0):
Expand Down Expand Up @@ -382,7 +382,7 @@ def get_channel(self, channel, label, color_filter):
coord = cutil.no_nan(getattr(clone, color_filter)) + step
setattr(clone, color_filter, coord)

if not clone.in_gamut():
if not clone.in_gamut(tolerance=0):
html.append(self.get_spacer(width=count))
break
elif color_filter == "alpha" and (coord < 0 or coord > 1.0):
Expand Down Expand Up @@ -515,7 +515,7 @@ def handle_href(self, href):
self.view.run_command(
cmd,
{
"initial": Color(color, filters=util.SRGB_SPACES).to_string(**DEFAULT),
"initial": Color(color, filters=util.CSS_SRGB_SPACES).to_string(**DEFAULT),
"on_done": on_done, "on_cancel": on_cancel
}
)
Expand Down
23 changes: 12 additions & 11 deletions ch_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def on_navigate(self, href):
"""Handle color box click."""

self.view.sel().clear()
for k, v in self.previews[self.view.id()].items():
for k, v in self.previews[self.view.buffer_id()].items():
if href == v.uid:
phantom = self.view.query_phantom(v.pid)
if phantom:
Expand Down Expand Up @@ -231,7 +231,7 @@ def source_iter(self, visible_region, bounds):
def get_color_class(self, pt, classes):
"""Get color class based on selection scope."""

view_id = self.view.id()
view_id = self.view.buffer_id()
if not self.color_classes[view_id] or self.view.settings().get('color_helper.refresh', True):
util.debug("Clear color class stash")
self.view.settings().set('color_helper.refresh', False)
Expand Down Expand Up @@ -283,7 +283,7 @@ def do_search(self, force=False):
settings = self.view.settings()
colors = []

view_id = self.view.id()
view_id = self.view.buffer_id()

# Allow per view scan override
option = settings.get("color_helper.scan_override", None)
Expand Down Expand Up @@ -413,14 +413,15 @@ def do_search(self, force=False):
# Calculate a reasonable border color for our image at this location and get color strings
hsl = Color(
mdpopups.scope2style(self.view, self.view.scope_name(pt))['background'],
filters=util.SRGB_SPACES
filters=util.CSS_SRGB_SPACES
).convert("hsl")
hsl.lightness = hsl.lightness + (30 if hsl.luminance() < 0.5 else -30)
preview_border = hsl.convert("srgb", fit=True).to_string(**util.HEX)

color = Color(obj.color)
title = ''
if not color.in_gamut("srgb"):
check_space = 'srgb' if color.space() not in util.SRGB_SPACES else color.space()
if not color.in_gamut(check_space):
title = ' title="Preview out of gamut"'
if self.show_out_of_gamut_preview:
srgb = color.convert("srgb", fit=True)
Expand All @@ -431,7 +432,7 @@ def do_search(self, force=False):
preview2 = self.out_of_gamut
preview_border = self.out_of_gamut_border
else:
srgb = color.convert("srgb")
srgb = color.convert("srgb", fit=True)
preview1 = srgb.to_string(**util.HEX_NA)
preview2 = srgb.to_string(**util.HEX)

Expand Down Expand Up @@ -473,7 +474,7 @@ def do_search(self, force=False):
def add_phantoms(self, colors):
"""Add phantoms."""

i = self.view.id()
i = self.view.buffer_id()
for html, pt, start, end, unique_id in colors:
pid = self.view.add_phantom(
'color_helper',
Expand All @@ -486,21 +487,21 @@ def add_phantoms(self, colors):

def reset_previous(self):
"""Reset previous region."""
self.previous_region[self.view.id()] = sublime.Region(0)
self.previous_region[self.view.buffer_id()] = sublime.Region(0)

def erase_phantoms(self):
"""Erase phantoms."""

# Obliterate!
self.view.erase_phantoms('color_helper')
self.previews[self.view.id()].clear()
self.previews[self.view.buffer_id()].clear()
self.reset_previous()

def run(self, clear=False, force=False):
"""Run."""

self.view = self.window.active_view()
ids = set([view.id() for view in self.window.views()])
ids = set([view.buffer_id() for view in self.window.views()])
keys = set(self.previews.keys())
diff = keys - ids

Expand All @@ -509,7 +510,7 @@ def run(self, clear=False, force=False):
del self.previous_region[i]
del self.color_classes[i]

i = self.view.id()
i = self.view.buffer_id()
if i not in self.previews:
self.previews[i] = {}
if i not in self.previous_region:
Expand Down
7 changes: 3 additions & 4 deletions ch_tool_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,12 @@ def preview(self, text):
orig = Color(color)
message = ""
color_string = ""
if not orig.in_gamut('srgb'):
check_space = 'srgb' if orig.space() not in util.SRGB_SPACES else orig.space()
if not orig.in_gamut(check_space):
orig = orig.fit("srgb")
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
color_string = "<strong>Gamut Mapped</strong>: {}<br>".format(orig.to_string())
srgb = orig.convert('srgb', fit=True)
else:
srgb = orig.convert('srgb')
srgb = orig.convert('srgb', fit=True)
color_string += "<strong>Color</strong>: {}".format(color.to_string(**util.DEFAULT))
preview = srgb.to_string(**util.HEX_NA)
preview_alpha = srgb.to_string(**util.HEX)
Expand Down
7 changes: 4 additions & 3 deletions ch_tool_colormod.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initial_text(self):
# Basically, if the file already supports `color-mod` input,
# then we want to return the text raw if it parses.
try:
color = self.color_mod_class(text, filters=util.SRGB_SPACES)
color = self.color_mod_class(text, filters=util.CSS_SRGB_SPACES)
except Exception:
pass
if color is None:
Expand Down Expand Up @@ -93,9 +93,10 @@ def preview(self, text):
srgb = Color(color).convert("srgb")
preview_border = self.default_border
message = ""
if not srgb.in_gamut():
srgb.fit()
check_space = 'srgb' if srgb.space() not in util.SRGB_SPACES else srgb.space()
if not srgb.in_gamut(check_space):
message = '<br><em style="font-size: 0.9em;">* preview out of gamut</em>'
srgb.fit(in_place=True)
preview = srgb.to_string(**util.HEX_NA)
preview_alpha = srgb.to_string(**util.HEX)
preview_border = self.default_border
Expand Down
4 changes: 2 additions & 2 deletions ch_tool_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def parse_color(string, start=0, second=False):
more = None
ratio = None
# First color
color = Color.match(string, start=start, fullmatch=False, filters=util.SRGB_SPACES)
color = Color.match(string, start=start, fullmatch=False, filters=util.CSS_SRGB_SPACES)
if color:
start = color.end
if color.end != length:
Expand Down Expand Up @@ -178,7 +178,7 @@ def initial_text(self):
pass
if color is not None:
color = Color(color)
if color.space() not in util.SRGB_SPACES:
if color.space() not in util.CSS_SRGB_SPACES:
color = color.convert("srgb", fit=True)
return color.to_string(**util.DEFAULT)
return ''
Expand Down
Loading

0 comments on commit 7275416

Please sign in to comment.