Last active
December 7, 2023 07:27
-
-
Save jfcherng/3e2d2acadc91962ded6379ed2884aa7f to your computer and use it in GitHub Desktop.
Revisions
-
jfcherng revised this gist
Oct 21, 2023 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,10 +36,13 @@ def handle_coord(val: float): return int(val) if val.is_integer() else val coords = parent.clone().coords(nans=False) return "{r} {g} {b}".format_map( dict( zip( ("r", "g", "b"), map(handle_coord, coords), ) ) ) -
jfcherng revised this gist
Oct 21, 2023 . 2 changed files with 6 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,9 @@ "class": "ColorHelper.custom.srgb_norm.ColorSrgbNorm", "filters": ["srgb"], "output": [ {"space": "srgb", "format": {"precision": 6}}, ], }, }, "user_color_rules": [ { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,13 +23,9 @@ def match(cls, string: str, start: int = 0, fullmatch: bool = True): m = MATCH.match(string, start) if not m or (fullmatch and m.end(0) != len(string)): return None r, g, b, a = map(float, m.groups()), 1.0 return ((r, g, b), a), m.end(0) @classmethod def to_string(cls, parent, *, precision=6): -
jfcherng revised this gist
Oct 21, 2023 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,11 +34,16 @@ def match(cls, string: str, start: int = 0, fullmatch: bool = True): @classmethod def to_string(cls, parent, *, precision=6): """Output color in `R G B` form.""" def handle_coord(val: float): val = round(val, precision) return int(val) if val.is_integer() else val coords = parent.clone().coords(nans=False) return "{r} {g} {b}".format( r=handle_coord(coords[0]), g=handle_coord(coords[1]), b=handle_coord(coords[2]), ) -
jfcherng revised this gist
Oct 20, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ }, "user_color_rules": [ { "name": "XML", // overwrites the built-in "XML" color rule "base_scopes": ["text.xml"], "color_class": "srgb_norm", "scanning": [ -
jfcherng revised this gist
Oct 20, 2023 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,7 @@ ## Original Request https://discord.com/channels/280102180189634562/280157083356233728/1164923362829676626 ## Screenshot  -
jfcherng created this gist
Oct 20, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Original request: https://discord.com/channels/280102180189634562/280157083356233728/1164923362829676626 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ // file: Packages/User/color_helper.sublime-settings { "user_color_classes": { "srgb_norm": { "class": "ColorHelper.custom.srgb_norm.ColorSrgbNorm", "filters": ["srgb"], "output": [ {"space": "srgb", "format": {"precision": 6}} ] } }, "user_color_rules": [ { "name": "XML", "base_scopes": ["text.xml"], "color_class": "srgb_norm", "scanning": [ "text.xml meta.tag", ], "color_trigger": "(?<=value=\")(?=[\\d.]+\\s+[\\d.]+\\s+[\\d.]+)", }, ], } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ # file: Packages/ColorHelper/custom/srgb_norm.py import re from ColorHelper.ch_util import get_base_color from ..lib.coloraide.spaces.srgb.css import sRGB MATCH = re.compile( r""" (?P<r>\d+(?:\.\d+)?)\s+ (?P<g>\d+(?:\.\d+)?)\s+ (?P<b>\d+(?:\.\d+)?) """, re.VERBOSE, ) class SrgbNorm(sRGB): @classmethod def match(cls, string: str, start: int = 0, fullmatch: bool = True): """Match and parse a color string.""" m = MATCH.match(string, start) if not m or (fullmatch and m.end(0) != len(string)): return None return ( ( (float(m.group("r")), float(m.group("g")), float(m.group("b"))), 1.0, # alpha ), m.end(0), ) @classmethod def to_string(cls, parent, *, precision=6): """Output color in `R G B` form.""" coords = parent.clone().coords(nans=False) return "{r} {g} {b}".format( r=round(coords[0], precision), g=round(coords[1], precision), b=round(coords[2], precision), ) class ColorSrgbNorm(get_base_color()): pass ColorSrgbNorm.register(SrgbNorm(), overwrite=True)