Пример #1
0
    def get_hires_color_channel(self, color_filter):
        """Get get a list of all colors within range."""

        ranges = {
            "red": (0, 255),
            "green": (0, 255),
            "blue": (0, 255),
            "alpha": (0, 255),
            "hue": (0, 360),
            "saturation": (0, 100),
            "luminance": (0, 100)
        }

        rgba = util.RGBA(self.color)
        h, l, s = rgba.tohls()
        minimum, maximum = ranges[color_filter]
        check_size = self.check_size(self.box_height)
        html = []
        for x in range(minimum, maximum + 1):
            if color_filter == 'red':
                rgba.r = x
                label = str(x)
            elif color_filter == 'green':
                rgba.g = x
                label = str(x)
            elif color_filter == 'blue':
                rgba.b = x
                label = str(x)
            elif color_filter == 'alpha':
                rgba.a = x
                label = util.fmt_float(
                    rgba.a * mdpopups.rgba.RGB_CHANNEL_SCALE, 3)
            elif color_filter == 'hue':
                h = x * mdpopups.rgba.HUE_SCALE
                rgba.fromhls(h, l, s)
                label = str(x)
            elif color_filter == 'saturation':
                s = x * 0.01
                rgba.fromhls(h, l, s)
                label = str(x)
            elif color_filter == 'luminance':
                l = x * 0.01
                rgba.fromhls(h, l, s)
                label = str(x)
            color = rgba.get_rgba()
            html.append(
                '[%s](%s) %s<br>' %
                (mdpopups.color_box([color],
                                    OUTER_BORDER,
                                    INNER_BORDER,
                                    border_size=2,
                                    height=self.box_height,
                                    width=self.box_height * 8,
                                    check_size=check_size), color, label))
        self.template_vars['channel_hires'] = ''.join(html)
Пример #2
0
    def get_hires_color_channel(self, text, color_filter):
        """Get get a list of all colors within range."""

        ranges = {
            "red": (0, 255),
            "green": (0, 255),
            "blue": (0, 255),
            "alpha": (0, 255),
            "hue": (0, 360),
            "saturation": (0, 100),
            "luminance": (0, 100)
        }

        rgba = util.RGBA(self.color)
        h, l, s = rgba.tohls()
        minimum, maximum = ranges[color_filter]
        check_size = self.check_size(self.box_height)
        for x in range(minimum, maximum + 1):
            if color_filter == 'red':
                rgba.r = x
                label = str(x)
            elif color_filter == 'green':
                rgba.g = x
                label = str(x)
            elif color_filter == 'blue':
                rgba.b = x
                label = str(x)
            elif color_filter == 'alpha':
                rgba.a = x
                label = util.fmt_float(rgba.a * mdpopups.rgba.RGB_CHANNEL_SCALE, 3)
            elif color_filter == 'hue':
                h = x * mdpopups.rgba.HUE_SCALE
                rgba.fromhls(h, l, s)
                label = str(x)
            elif color_filter == 'saturation':
                s = x * 0.01
                rgba.fromhls(h, l, s)
                label = str(x)
            elif color_filter == 'luminance':
                l = x * 0.01
                rgba.fromhls(h, l, s)
                label = str(x)
            color = rgba.get_rgba()
            text.append(
                '[%s](%s) %s\n' % (
                    mdpopups.color_box(
                        [color], OUTER_BORDER, INNER_BORDER,
                        border_size=2, height=self.box_height, width=self.box_height * 8, check_size=check_size
                    ),
                    color,
                    label
                )
            )
Пример #3
0
    def insert_color(self, target_color, convert=None):
        """Insert colors."""

        sels = self.view.sel()
        if (len(sels) == 1 and sels[0].size() == 0):
            point = sels[0].begin()
            insert_calc = InsertionCalc(self.view, point, target_color, convert)
            insert_calc.calc()
            if insert_calc.web_color:
                value = insert_calc.web_color
            elif insert_calc.convert_rgb:
                value = "%d, %d, %d" % (
                    int(target_color[1:3], 16),
                    int(target_color[3:5], 16),
                    int(target_color[5:7], 16)
                )
                if insert_calc.alpha:
                    value += ', %s' % insert_calc.alpha
                if insert_calc.format_override:
                    value = ("rgba(%s)" if insert_calc.alpha else "rgb(%s)") % value
            elif insert_calc.convert_hsl:
                hsl = RGBA(target_color)
                h, l, s = hsl.tohls()
                value = "%s, %s%%, %s%%" % (
                    util.fmt_float(h * 360.0),
                    util.fmt_float(s * 100.0),
                    util.fmt_float(l * 100.0)
                )
                if insert_calc.alpha:
                    value += ', %s' % insert_calc.alpha
                if insert_calc.format_override:
                    value = ("hsla(%s)" if insert_calc.alpha else "hsl(%s)") % value
            else:
                use_upper = ch_settings.get("upper_case_hex", False)
                value = target_color.upper() if use_upper else target_color.lower()
            self.view.sel().subtract(sels[0])
            self.view.sel().add(insert_calc.region)
            self.view.run_command("insert", {"characters": value})
        self.view.hide_popup()
Пример #4
0
    def get_color_info(self):
        """Get color info."""

        rgba = util.RGBA(self.color)
        self.template_vars['rgb_r'] = rgba.r
        self.template_vars['rgb_g'] = rgba.g
        self.template_vars['rgb_b'] = rgba.b
        self.template_vars['alpha'] = self.alpha
        h, l, s = rgba.tohls()
        self.template_vars['hsl_h'] = util.fmt_float(h * 360.0)
        self.template_vars['hsl_l'] = util.fmt_float(l * 100.0)
        self.template_vars['hsl_s'] = util.fmt_float(s * 100.0)
        h, w, b = rgba.tohwb()
        self.template_vars['hwb_h'] = util.fmt_float(h * 360.0)
        self.template_vars['hwb_w'] = util.fmt_float(w * 100.0)
        self.template_vars['hwb_b'] = util.fmt_float(b * 100.0)

        if self.web_color and 'webcolors' in self.allowed_colors:
            self.template_vars['webcolor_info'] = True
            self.template_vars['webcolor_value'] = self.web_color
        if 'hex' in self.allowed_colors or 'hex_compressed' in self.allowed_colors:
            settings = sublime.load_settings('color_helper.sublime-settings')
            use_upper = settings.get("upper_case_hex", False)
            color = self.color[:-2].lower()
            self.template_vars['hex_info'] = True
            self.template_vars['hex_link'] = (
                self.compress_hex_color(color).upper()
                if use_upper else self.compress_hex_color(color))
            self.template_vars['hex_display'] = color.upper(
            ) if use_upper else color
        if (('hexa' in self.allowed_colors
             or 'hexa_compressed' in self.allowed_colors)
                and (self.use_hex_argb is None or self.use_hex_argb is False)):
            color = self.color.lower()
            self.template_vars['hexa_info'] = True
            self.template_vars['hexa_link'] = self.compress_hex_color(color)
            self.template_vars['hexa_display'] = color[:-2]
            self.template_vars['hexa_alpha'] = color[-2:]
        if (('hexa' in self.allowed_colors or 'hexa_compressed')
                and (self.use_hex_argb is None or self.use_hex_argb is True)):
            color = '#' + (self.color[-2:] + self.color[1:-2]).lower()
            self.template_vars['ahex_info'] = True
            self.template_vars['ahex_link'] = self.compress_hex_color(color)
            self.template_vars['ahex_alpha'] = color[:-2]
            self.template_vars['ahex_display'] = color[1:-2]
        if 'rgb' in self.allowed_colors:
            self.template_vars['rgb_info'] = True
        if 'rgba' in self.allowed_colors:
            self.template_vars['rgba_info'] = True
        if 'hsl' in self.allowed_colors:
            self.template_vars['hsl_info'] = True
        if 'hsla' in self.allowed_colors:
            self.template_vars['hsla_info'] = True
        if 'hwb' in self.allowed_colors:
            self.template_vars['hwb_info'] = True
        if 'hwba' in self.allowed_colors:
            self.template_vars['hwba_info'] = True
Пример #5
0
    def run(self,
            edit,
            color='#ffffff',
            allowed_colors=util.ALL,
            use_hex_argb=None,
            compress_hex=False,
            hsl=False,
            hirespick=None,
            colornames=False,
            on_done=None,
            on_cancel=None):
        """Run command."""

        self.on_done = on_done
        self.on_cancel = on_cancel
        self.use_hex_argb = use_hex_argb
        self.compress_hex = compress_hex
        self.allowed_colors = allowed_colors
        self.template_vars = {"legacy": util.LEGACY_CLASS}
        self.hex_map = sublime.load_settings(
            'color_helper.sublime-settings').get('use_hex_color_picker', True)
        rgba = util.RGBA(color)
        self.set_sizes()
        self.hsl = hsl
        self.color = rgba.get_rgba()
        self.alpha = util.fmt_float(float(int(self.color[-2:], 16)) / 255.0, 3)
        try:
            self.web_color = csscolors.hex2name(rgba.get_rgb())
        except Exception:
            self.web_color = None

        if colornames:
            self.template_vars['color_names'] = True
            self.template_vars['cancel'] = self.color
            self.get_css_color_names()
        elif hirespick:
            self.template_vars['hires'] = True
            self.template_vars['cancel'] = self.color
            self.template_vars['hires_color'] = hirespick
            self.get_hires_color_channel(hirespick)
        else:
            self.template_vars['picker'] = True
            self.template_vars['cancel'] = 'cancel'
            if self.hex_map:
                self.get_color_map_hex()
            else:
                self.get_color_map_square()
            self.get_current_color()
            if hsl:
                self.get_channel('channel_1', 'H', -15, 15, 'hue')
                self.get_channel('channel_2', 'S', 0.975, 1.025, 'saturation')
                self.get_channel('channel_3', 'L', 0.975, 1.025, 'luminance')
            else:
                self.get_channel('channel_1', 'R', 0.975, 1.025, 'red')
                self.get_channel('channel_2', 'G', 0.975, 1.025, 'green')
                self.get_channel('channel_3', 'B', 0.975, 1.025, 'blue')
            self.get_channel('channel_alpha', 'A', 0.975, 1.025, 'alpha')

            self.template_vars['color_switch'] = 'rgb' if self.hsl else 'hsl'
            self.get_color_info()

        mdpopups.show_popup(
            self.view,
            sublime.load_resource(
                'Packages/ColorHelper/panels/color-picker.html'),
            css=util.ADD_CSS,
            wrapper_class="color-helper content",
            max_width=1024,
            max_height=(500 if hirespick or colornames else 725),
            on_navigate=self.handle_href,
            template_vars=self.template_vars,
            nl2br=False)
Пример #6
0
    def format_info(self, color, alpha=None):
        """Format the selected color info."""
        rgba = RGBA(color)

        try:
            web_color = csscolors.hex2name(rgba.get_rgb())
        except Exception:
            web_color = None

        color_picker = util.color_picker_available()
        s = sublime.load_settings('color_helper.sublime-settings')
        show_global_palettes = s.get('enable_global_user_palettes', True)
        show_project_palettes = s.get('enable_project_user_palettes', True)
        show_favorite_palette = s.get('enable_favorite_palette', True)
        show_current_palette = s.get('enable_current_file_palette', True)
        show_conversions = s.get('enable_color_conversions', True)
        show_picker = s.get('enable_color_picker', True)
        palettes_enabled = (
            show_global_palettes or show_project_palettes or
            show_favorite_palette or show_current_palette
        )
        click_color_box_to_pick = s.get('click_color_box_to_pick', 'none')

        if click_color_box_to_pick == 'color_picker' and color_picker and show_picker:
            color_box_wrapper = '\n\n[%s]' + ('(__color_picker__:%s)' % color)
        elif click_color_box_to_pick == 'palette_picker' and palettes_enabled:
            color_box_wrapper = '\n\n[%s](__palettes__)'
        else:
            color_box_wrapper = '\n\n%s'

        info = []

        if click_color_box_to_pick != 'palette_picker' and palettes_enabled:
            info.append(PALETTE_MENU)
        if click_color_box_to_pick != 'color_picker' and color_picker and show_picker:
            info.append(PICK_MENU % color)
        if show_global_palettes or show_project_palettes:
            info.append(ADD_COLOR_MENU % color.lower())
        if show_favorite_palette:
            if color in util.get_favs()['colors']:
                info.append(UNMARK_MENU % color.lower())
            else:
                info.append(MARK_MENU % color.lower())

        info.append(
            color_box_wrapper % mdpopups.color_box([color], '#cccccc', '#333333', height=64, width=192, border_size=2)
        )

        if show_conversions:
            info.append('\n\n---\n\n')
            if web_color:
                info.append(WEB_COLOR % (color, web_color))
            info.append(HEX_COLOR % (color, (color.lower() if not alpha else color[:-2].lower())))
            info.append(RGB_COLOR % (color, rgba.r, rgba.g, rgba.b))
            info.append(RGBA_COLOR % (color, rgba.r, rgba.g, rgba.b, alpha if alpha else '1'))
            h, l, s = rgba.tohls()
            info.append(
                HSL_COLOR % (color, util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0))
            )
            info.append(
                HSLA_COLOR % (
                    color, util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0),
                    alpha if alpha else '1'
                )
            )
        return ''.join(info)
    def run(
        self, edit, color='#ffffff', allowed_colors=util.ALL, use_hex_argb=None,
        compress_hex=False, hsl=False, hirespick=None, colornames=False,
        on_done=None, on_cancel=None
    ):
        """Run command."""

        self.on_done = on_done
        self.on_cancel = on_cancel
        self.use_hex_argb = use_hex_argb
        self.compress_hex = compress_hex
        self.allowed_colors = allowed_colors
        self.hex_map = sublime.load_settings('color_helper.sublime-settings').get('use_hex_color_picker', True)
        rgba = util.RGBA(color)
        self.set_sizes()
        self.hsl = hsl
        self.color = rgba.get_rgba()
        self.alpha = util.fmt_float(float(int(self.color[-2:], 16)) / 255.0, 3)
        try:
            self.web_color = csscolors.hex2name(rgba.get_rgb())
        except Exception:
            self.web_color = None

        text = []
        if colornames:
            text.append('[cancel](%s){: .color-helper .small} ' % self.color)
            text.append('\n\n## CSS Color Names\n\n')
            self.get_css_color_names(text)
        elif hirespick:
            text.append('[cancel](%s){: .color-helper .small} ' % self.color)
            text.append('\n\n## %s\n\n' % hirespick)
            self.get_hires_color_channel(text, hirespick)
        else:
            text.append('[cancel](cancel){: .color-helper .small} ')
            text.append('[CSS color names](colornames){: .color-helper .small} ')
            text.append('[enter new color](edit){: .color-helper .small}\n\n')
            if self.hex_map:
                self.get_color_map_hex(text)
            else:
                self.get_color_map_square(text)
            self.get_current_color(text)
            text.append('\n\n---\n\n')
            if hsl:
                self.get_channel(text, 'H', -15, 15, 'hue')
                self.get_channel(text, 'S', 0.975, 1.025, 'saturation')
                self.get_channel(text, 'L', 0.975, 1.025, 'luminance')
            else:
                self.get_channel(text, 'R', 0.975, 1.025, 'red')
                self.get_channel(text, 'G', 0.975, 1.025, 'green')
                self.get_channel(text, 'B', 0.975, 1.025, 'blue')
            self.get_channel(text, 'A', 0.975, 1.025, 'alpha')
            text.append(
                '[switch to %s](%s){: .color-helper .small}\n' % (
                    'rgb' if self.hsl else 'hsl', 'rgb' if self.hsl else 'hsl'
                )
            )
            text.append('\n\n---\n\n')
            self.get_color_info(text)

        md = mdpopups.md2html(self.view, ''.join(text))
        mdpopups.show_popup(
            self.view, '<div class="color-helper content">%s</div>' % md,
            css=util.ADD_CSS,
            max_width=600, max_height=(500 if hirespick or colornames else 725),
            on_navigate=self.handle_href
        )
    def get_color_info(self, text):
        """Get color info."""

        rgba = util.RGBA(self.color)

        if self.web_color and 'webcolors' in self.allowed_colors:
            text.append(WEB_COLOR % (LINK % self.web_color, self.web_color))
        if 'hex' in self.allowed_colors or 'hex_compressed' in self.allowed_colors:
            color = self.color[:-2].lower()
            text.append(HEX_COLOR % (LINK % self.compress_hex_color(color), color))
        if (
            ('hexa' in self.allowed_colors or 'hexa_compressed' in self.allowed_colors) and
            (self.use_hex_argb is None or self.use_hex_argb is False)
        ):
            color = self.color.lower()
            text.append(HEXA_COLOR % (LINK % self.compress_hex_color(color), color[:-2], color[-2:]))
        if (
            ('hexa' in self.allowed_colors or 'hexa_compressed') and
            (self.use_hex_argb is None or self.use_hex_argb is True)
        ):
            color = '#' + (self.color[-2:] + self.color[1:-2]).lower()
            text.append(AHEX_COLOR % (LINK % self.compress_hex_color(color), color[0], color[-2:], color[1:-2]))
        if 'rgb' in self.allowed_colors:
            color = RGB_INSERT % (rgba.r, rgba.g, rgba.b)
            text.append(RGB_COLOR % (LINK % color, rgba.r, rgba.g, rgba.b))
        if 'rgba' in self.allowed_colors:
            color = RGBA_INSERT % (rgba.r, rgba.g, rgba.b, self.alpha)
            text.append(RGBA_COLOR % (LINK % color, rgba.r, rgba.g, rgba.b, self.alpha))
        h, l, s = rgba.tohls()
        if 'hsl' in self.allowed_colors:
            color = HSL_INSERT % (util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0))
            text.append(
                HSL_COLOR % (
                    LINK % color, util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0)
                )
            )
        if 'hsla' in self.allowed_colors:
            color = HSLA_INSERT % (
                util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0), self.alpha
            )
            text.append(
                HSLA_COLOR % (
                    LINK % color, util.fmt_float(h * 360.0), util.fmt_float(s * 100.0), util.fmt_float(l * 100.0),
                    self.alpha
                )
            )
        h, w, b = rgba.tohwb()
        if 'hwb' in self.allowed_colors:
            color = HWB_INSERT % (util.fmt_float(h * 360.0), util.fmt_float(w * 100.0), util.fmt_float(b * 100.0))
            text.append(
                HWB_COLOR % (
                    LINK % color, util.fmt_float(h * 360.0), util.fmt_float(w * 100.0), util.fmt_float(b * 100.0)
                )
            )
        if 'hwba' in self.allowed_colors:
            color = HWBA_INSERT % (
                util.fmt_float(h * 360.0), util.fmt_float(w * 100.0), util.fmt_float(b * 100.0), self.alpha
            )
            text.append(
                HWBA_COLOR % (
                    LINK % color, util.fmt_float(h * 360.0), util.fmt_float(w * 100.0), util.fmt_float(b * 100.0),
                    self.alpha
                )
            )
    def replacement(self, m):
        """See if match is a convert replacement of an existing color."""

        found = True
        if m.group('webcolors') and 'webcolors' in self.allowed_colors:
            self.region = sublime.Region(m.start('webcolors') + self.start, m.end('webcolors') + self.start)
        elif m.group('hexa') and self.use_hex_argb and 'hexa' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa') + self.start, m.end('hexa') + self.start)
            content = m.group('hexa_content')
            self.alpha_hex = content[0:2]
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hexa') and 'hexa' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa') + self.start, m.end('hexa') + self.start)
            content = m.group('hexa_content')
            self.alpha_hex = content[-2:]
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hex') and 'hex' in self.allowed_colors:
            self.region = sublime.Region(m.start('hex') + self.start, m.end('hex') + self.start)
        elif m.group('hexa_compressed') and self.use_hex_argb and 'hexa_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa_compressed') + self.start, m.end('hexa_compressed') + self.start)
            content = m.group('hexa_compressed_content')
            self.alpha_hex = content[0:1] * 2
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hexa_compressed') and 'hexa_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa_compressed') + self.start, m.end('hexa_compressed') + self.start)
            content = m.group('hexa_compressed_content')
            self.alpha_hex = content[-1:] * 2
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hex_compressed') and 'hex_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hex_compressed') + self.start, m.end('hex_compressed') + self.start)
        elif m.group('rgb') and 'rgb' in self.allowed_colors:
            self.region = sublime.Region(m.start('rgb') + self.start, m.end('rgb') + self.start)
        elif m.group('rgba') and 'rgba' in self.allowed_colors:
            self.region = sublime.Region(m.start('rgba') + self.start, m.end('rgba') + self.start)
            content = [x.strip() for x in m.group('rgba_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('gray') and 'gray' in self.allowed_colors:
            self.region = sublime.Region(m.start('gray') + self.start, m.end('gray') + self.start)
        elif m.group('graya') and 'graya' in self.allowed_colors:
            self.region = sublime.Region(m.start('graya') + self.start, m.end('graya') + self.start)
            content = [x.strip() for x in m.group('graya_content').split(',')]
            if content[1].endswith('%'):
                content[1] = util.fmt_float(util.clamp(float(content[1].strip('%')), 0.0, 100.0) / 100.0, 3)
            else:
                temp = float(content[1])
                if temp < 0.0 or temp > 1.0:
                    content[1] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[1]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('hsl') and 'hsl' in self.allowed_colors:
            self.region = sublime.Region(m.start('hsl') + self.start, m.end('hsl') + self.start)
        elif m.group('hsla') and 'hsla' in self.allowed_colors:
            self.region = sublime.Region(m.start('hsla') + self.start, m.end('hsla') + self.start)
            content = [x.strip().rstrip('%') for x in m.group('hsla_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('hwb') and 'hwb' in self.allowed_colors:
            self.region = sublime.Region(m.start('hwb') + self.start, m.end('hwb') + self.start)
        elif m.group('hwba') and 'hwba' in self.allowed_colors:
            self.region = sublime.Region(m.start('hwba') + self.start, m.end('hwba') + self.start)
            content = [x.strip().rstrip('%') for x in m.group('hwba_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        else:
            found = False
        return found
Пример #10
0
    def replacement(self, m):
        """See if match is a convert replacement of an existing color."""

        found = True
        if m.group('webcolors') and 'webcolors' in self.allowed_colors:
            self.region = sublime.Region(m.start('webcolors') + self.start, m.end('webcolors') + self.start)
        elif m.group('hexa') and self.use_hex_argb and 'hexa' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa') + self.start, m.end('hexa') + self.start)
            content = m.group('hexa_content')
            self.alpha_hex = content[0:2]
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hexa') and 'hexa' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa') + self.start, m.end('hexa') + self.start)
            content = m.group('hexa_content')
            self.alpha_hex = content[-2:]
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hex') and 'hex' in self.allowed_colors:
            self.region = sublime.Region(m.start('hex') + self.start, m.end('hex') + self.start)
        elif m.group('hexa_compressed') and self.use_hex_argb and 'hexa_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa_compressed') + self.start, m.end('hexa_compressed') + self.start)
            content = m.group('hexa_compressed_content')
            self.alpha_hex = content[0:1] * 2
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hexa_compressed') and 'hexa_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hexa_compressed') + self.start, m.end('hexa_compressed') + self.start)
            content = m.group('hexa_compressed_content')
            self.alpha_hex = content[-1:] * 2
            self.alpha = util.fmt_float(float(int(self.alpha_hex, 16)) / 255.0, 3)
        elif m.group('hex_compressed') and 'hex_compressed' in self.allowed_colors:
            self.region = sublime.Region(m.start('hex_compressed') + self.start, m.end('hex_compressed') + self.start)
        elif m.group('rgb') and 'rgb' in self.allowed_colors:
            self.region = sublime.Region(m.start('rgb') + self.start, m.end('rgb') + self.start)
        elif m.group('rgba') and 'rgba' in self.allowed_colors:
            self.region = sublime.Region(m.start('rgba') + self.start, m.end('rgba') + self.start)
            content = [x.strip() for x in m.group('rgba_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('gray') and 'gray' in self.allowed_colors:
            self.region = sublime.Region(m.start('gray') + self.start, m.end('gray') + self.start)
        elif m.group('graya') and 'graya' in self.allowed_colors:
            self.region = sublime.Region(m.start('graya') + self.start, m.end('graya') + self.start)
            content = [x.strip() for x in m.group('graya_content').split(',')]
            if content[1].endswith('%'):
                content[1] = util.fmt_float(util.clamp(float(content[1].strip('%')), 0.0, 100.0) / 100.0, 3)
            else:
                temp = float(content[1])
                if temp < 0.0 or temp > 1.0:
                    content[1] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[1]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('hsl') and 'hsl' in self.allowed_colors:
            self.region = sublime.Region(m.start('hsl') + self.start, m.end('hsl') + self.start)
        elif m.group('hsla') and 'hsla' in self.allowed_colors:
            self.region = sublime.Region(m.start('hsla') + self.start, m.end('hsla') + self.start)
            content = [x.strip().rstrip('%') for x in m.group('hsla_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        elif m.group('hwb') and 'hwb' in self.allowed_colors:
            self.region = sublime.Region(m.start('hwb') + self.start, m.end('hwb') + self.start)
        elif m.group('hwba') and 'hwba' in self.allowed_colors:
            self.region = sublime.Region(m.start('hwba') + self.start, m.end('hwba') + self.start)
            content = [x.strip().rstrip('%') for x in m.group('hwba_content').split(',')]
            temp = float(content[3])
            if temp < 0.0 or temp > 1.0:
                content[3] = util.fmt_float(util.clamp(float(temp), 0.0, 1.0), 3)
            self.alpha = content[3]
            self.alpha_hex = "%02x" % util.round_int(float(self.alpha) * 255.0)
        else:
            found = False
        return found