Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade coloraide #267

Merged
merged 6 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -39,7 +39,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -59,7 +59,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ColorHelper

## 6.4

- **NEW**: Upgrade ColorAide.
- **NEW**: Note in documentation and settings a new gamut mapping
method, `oklch-raytrace`, which does a chroma reduction much
faster and closer than the current suggested CSS algorithm.

## 6.3.2

- **FIX**: Fix missing requirement for `math.isclose` in ColorAide
Expand Down
4 changes: 2 additions & 2 deletions ch_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_color_map_square_hsv(self, mode='hsv'):
global default_border
global color_scale

hue, saturation, value = alg.no_nans(self.color.convert(mode)[:-1])
hue, saturation, value = self.color.convert(mode).coords(nans=False)

r_sat = saturation
r_val = value
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_color_map_square(self, mode='hsl'):
global default_border
global color_scale

hue, saturation, lightness = alg.no_nans(self.color.convert(mode)[:-1])
hue, saturation, lightness = self.color.convert(mode).coords(nans=False)

r_sat = saturation
r_lit = lightness
Expand Down
9 changes: 5 additions & 4 deletions color_helper.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"gamut_space": "srgb",

// Gamut mapping approach
// Supported methods are: `lch-chroma`, `oklch-chroma`, and `clip` (default).
// Supported methods are: `lch-chroma`, `oklch-chroma`, `oklch-raytrace`, and `clip` (default).
// `lch-chroma` was the original default before this was configurable.
"gamut_map": "clip",

Expand All @@ -135,7 +135,6 @@
// "ColorHelper.lib.coloraide.spaces.acescc.ACEScc",
// "ColorHelper.lib.coloraide.spaces.acescg.ACEScg",
// "ColorHelper.lib.coloraide.spaces.acescct.ACEScct",
// "ColorHelper.lib.coloraide.spaces.cam16.CAM16",
// "ColorHelper.lib.coloraide.spaces.cam16_jmh.CAM16JMh",
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16UCS",
// "ColorHelper.lib.coloraide.spaces.cam16_ucs.CAM16SCD",
Expand All @@ -149,7 +148,7 @@
// "ColorHelper.lib.coloraide.spaces.hunter_lab.HunterLab",
// "ColorHelper.lib.coloraide.spaces.ictcp.ICtCp",
// "ColorHelper.lib.coloraide.spaces.igtgpg.IgTgPg",
// "ColorHelper.lib.coloraide.spaces.itp.ITP",
// "ColorHelper.lib.coloraide.spaces.ipt.IPT",
// "ColorHelper.lib.coloraide.spaces.jzazbz.Jzazbz",
// "ColorHelper.lib.coloraide.spaces.jzczhz.JzCzhz",
// "ColorHelper.lib.coloraide.spaces.lch99o.LCh99o",
Expand All @@ -158,6 +157,7 @@
// "ColorHelper.lib.coloraide.spaces.rec2100_hlg.Rec2100HLG",
// "ColorHelper.lib.coloraide.spaces.rec2100_pq.Rec2100PQ",
// "ColorHelper.lib.coloraide.spaces.rlab.RLAB",
// "ColorHelper.lib.coloraide.spaces.ryb.RYB",
// "ColorHelper.lib.coloraide.spaces.xyb.XYB",
// "ColorHelper.lib.coloraide.spaces.xyy.xyY",
"ColorHelper.lib.coloraide.spaces.hsluv.HSLuv",
Expand Down Expand Up @@ -257,7 +257,8 @@
"output": [
{"space": "srgb", "format": {"hex": true}},
{"space": "srgb", "format": {"comma": true, "precision": 3}},
{"space": "hsl", "format": {"comma": true, "precision": 3}}
{"space": "hsl", "format": {"comma": true, "precision": 3}},
{"space": "hwb", "format": {"comma": true, "precision": 3}}
]
},
"tmtheme": {
Expand Down
6 changes: 2 additions & 4 deletions custom/ahex.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ class ASRGB(sRGB):

COLOR_FORMAT = False

@classmethod
def match(cls, string, start=0, fullmatch=True):
def match(self, string, start=0, fullmatch=True):
"""Match a CSS color string."""

m = MATCH.match(string, start)
if m is not None and (not fullmatch or m.end(0) == len(string)):
return split_channels(m.group(0)), m.end(0)
return None

@classmethod
def to_string(
cls, parent, *, options=None, alpha=None, precision=None, fit=True, none=False, **kwargs
self, parent, *, options=None, alpha=None, precision=None, fit=True, none=False, **kwargs
):
"""Convert to Hex format."""

Expand Down
6 changes: 2 additions & 4 deletions custom/ass_abgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ def split_channels(color: str):
class AssABGR(sRGB):
"""ASS `ABGR` color space."""

@classmethod
def match(cls, string: str, start: int = 0, fullmatch: bool = True):
def match(self, string: str, start: int = 0, fullmatch: bool = True):
"""Match a color string."""

m = MATCH.match(string, start)
if m is not None and (not fullmatch or m.end(0) == len(string)):
return split_channels(m.group("color")), m.end(0)
return None

@classmethod
def to_string(cls, parent, *, options=None, alpha=None, precision=None, fit=True, none=False, **kwargs):
def to_string(self, parent, *, options=None, alpha=None, precision=None, fit=True, none=False, **kwargs):
"""Convert color to `&HAABBGGRR`."""

options = kwargs
Expand Down
8 changes: 3 additions & 5 deletions custom/hex_0x.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Custon color that looks for colors of format `#RRGGBBAA` as `#AARRGGBB`."""
"""Custom color that looks for colors of format `#RRGGBBAA` as `#AARRGGBB`."""
from ..lib.coloraide.spaces.srgb.css import sRGB
from ..lib.coloraide.css import parse, serialize
import re
Expand All @@ -10,18 +10,16 @@
class HexSRGB(sRGB):
"""SRGB that looks for alpha first in hex format."""

@classmethod
def match(cls, string, start=0, fullmatch=True):
def match(self, string, start=0, fullmatch=True):
"""Match a CSS color string."""

m = MATCH.match(string, start)
if m is not None and (not fullmatch or m.end(0) == len(string)):
return parse.parse_hex(m.group(0).replace('0x', '#', 1)), m.end(0)
return None

@classmethod
def to_string(
cls, parent, *, alpha=None, precision=None, fit=True, none=False, **kwargs
self, parent, *, alpha=None, precision=None, fit=True, none=False, **kwargs
):
"""Convert to CSS."""

Expand Down
14 changes: 8 additions & 6 deletions custom/st_colormod.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,35 @@ def handle_vars(string, variables, parents=None):
class HWB(HWBORIG):
"""HWB class that allows commas."""

@classmethod
def match(cls, string, start=0, fullmatch=True):
def match(self, string, start=0, fullmatch=True):
"""Match a CSS color string."""

m = HWB_MATCH.match(string, start)
if m is not None and (not fullmatch or m.end(0) == len(string)):
return parse.parse_channels(
list(RE_CHAN_VALUE.findall(string[m.end(1) + 1:m.end(0) - 1])),
cls.CHANNELS, scaled=True
self.CHANNELS, scaled=True
), m.end(0)
return None

@classmethod
def to_string(
cls,
self,
parent,
*,
alpha=None,
precision=None,
percent: bool = True,
percent=None,
fit=True,
none=False,
color: bool = False,
comma: bool = False,
**kwargs
) -> str:
"""Convert to CSS."""

if percent is None:
percent = False if color else True

return serialize.serialize_css(
parent,
func='hwb',
Expand Down
6 changes: 2 additions & 4 deletions custom/tmtheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,8 @@ def name2hex(name):
class SRGBX11(sRGB):
"""sRGB class."""

@classmethod
def to_string(
cls, parent, *, alpha=None, precision=None, fit=True, none=False, **kwargs
self, parent, *, alpha=None, precision=None, fit=True, none=False, **kwargs
):
"""Convert to CSS."""

Expand Down Expand Up @@ -727,8 +726,7 @@ def to_string(

return value

@classmethod
def match(cls, string, start=0, fullmatch=True):
def match(self, string, start=0, fullmatch=True):
"""Match a CSS color string."""

m = MATCH.match(string, start)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/markdown/settings/previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ else in the code.

```js
// Gamut mapping approach
// Supported methods are: `lch-chroma`, `oklch-chroma`, and `clip` (default).
// Supported methods are: `lch-chroma`, `oklch-chroma`, `oklch-raytrace`, and `clip` (default).
// `lch-chroma` was the original default before this was configurable.
"gamut_map": "clip",
```
Expand Down
5 changes: 3 additions & 2 deletions lib/coloraide/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Meta related things."""
from __future__ import annotations
from collections import namedtuple
import re

Expand Down Expand Up @@ -83,7 +84,7 @@ def __new__(
cls,
major: int, minor: int, micro: int, release: str = "final",
pre: int = 0, post: int = 0, dev: int = 0
) -> "Version":
) -> Version:
"""Validate version info."""

# Ensure all parts are positive integers.
Expand Down Expand Up @@ -192,5 +193,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(2, 9, 1, "final", post=1)
__version_info__ = Version(3, 3, 1, "final")
__version__ = __version_info__._get_canonical()
Loading
Loading