def parse_color_stop(tokens): if len(tokens) == 1: color = parse_color(tokens[0]) if color is not None: return color, None elif len(tokens) == 2: color = parse_color(tokens[0]) position = get_length(tokens[1], negative=True, percentage=True) if color is not None and position is not None: return color, position raise InvalidValues
def color(token): """``*-color`` and ``color`` properties validation.""" result = parse_color(token) if result == 'currentColor': return 'inherit' else: return result
def expand_background(name, tokens, base_url): """Expand the ``background`` shorthand property. See http://www.w3.org/TR/CSS21/colors.html#propdef-background """ # Make `tokens` a stack tokens = list(reversed(tokens)) while tokens: token = tokens.pop() if parse_color(token) is not None: suffix = '-color' elif image([token], base_url) is not None: suffix = '-image' elif background_repeat([token]) is not None: suffix = '-repeat' elif background_attachment([token]) is not None: suffix = '-attachment' elif background_position([token]): if tokens: next_token = tokens.pop() if background_position([token, next_token]): # Two consecutive '-position' tokens, yield them together yield '-position', [token, next_token] continue else: # The next token is not a '-position', put it back # for the next loop iteration tokens.append(next_token) # A single '-position' token suffix = '-position' else: raise InvalidValues yield suffix, [token]
def color(token): """``*-color`` and ``color`` properties validation.""" result = parse_color(token) if result == 'currentColor': return 'inherit' else: return result
def expand_background(name, tokens, base_url): """Expand the ``background`` shorthand property. See http://www.w3.org/TR/CSS21/colors.html#propdef-background """ # Make `tokens` a stack tokens = list(reversed(tokens)) while tokens: token = tokens.pop() if parse_color(token) is not None: suffix = '-color' elif image([token], base_url) is not None: suffix = '-image' elif background_repeat([token]) is not None: suffix = '-repeat' elif background_attachment([token]) is not None: suffix = '-attachment' elif background_position([token]): if tokens: next_token = tokens.pop() if background_position([token, next_token]): # Two consecutive '-position' tokens, yield them together yield '-position', [token, next_token] continue else: # The next token is not a '-position', put it back # for the next loop iteration tokens.append(next_token) # A single '-position' token suffix = '-position' else: raise InvalidValues yield suffix, [token]
def expand_border_side(name, tokens): """Expand the ``border-*`` shorthand properties. See http://www.w3.org/TR/CSS21/box.html#propdef-border-top """ for token in tokens: if parse_color(token) is not None: suffix = '-color' elif border_width([token]) is not None: suffix = '-width' elif border_style([token]) is not None: suffix = '-style' else: raise InvalidValues yield suffix, [token]
def expand_border_side(name, tokens): """Expand the ``border-*`` shorthand properties. See http://www.w3.org/TR/CSS21/box.html#propdef-border-top """ for token in tokens: if parse_color(token) is not None: suffix = '-color' elif border_width([token]) is not None: suffix = '-width' elif border_style([token]) is not None: suffix = '-style' else: raise InvalidValues yield suffix, [token]
def load(self, mixer, file_r, options=None): self.palette = Palette(mixer) self.palette.ncols = None all_slots = [] colors = [] def add_color(clr): for c in colors: if c.getRGB() == clr.getRGB(): return None colors.append(clr) return clr parser = make_parser('page3') css = parser.parse_stylesheet_file(file_r) for ruleset in css.rules: #print ruleset if ruleset.at_keyword: continue for declaration in ruleset.declarations: #print declaration for token in declaration.value: #print token css_color = color3.parse_color(token) if not isinstance(css_color, color3.RGBA): continue r,g,b = css_color.red, css_color.green, css_color.blue color = Color() color.setRGB1((clip(r), clip(g), clip(b))) color = add_color(color) if not color: continue slot = Slot(color, user_defined=True) all_slots.append(slot) n_colors = len(all_slots) if n_colors > MAX_COLS: self.palette.ncols = max( int( floor(sqrt(n_colors)) ), 1) else: self.palette.ncols = n_colors self.palette.setSlots(all_slots) self.palette.meta["SourceFormat"] = "CSS" print("Loaded palette: {}x{}".format( self.palette.nrows, self.palette.ncols )) return self.palette
def outline_color(token): if get_keyword(token) == 'invert': return 'currentColor' else: return parse_color(token)
def other_colors(token): return parse_color(token)
def outline_color(token): if get_keyword(token) == 'invert': return 'currentColor' else: return parse_color(token)
def other_colors(token): return parse_color(token)
def main(): themes = defaultdict(lambda:defaultdict(defaultdict)) css_themes = {} for theme_js in glob('../../lib/ace/theme/*.js'): fname_stub = theme_js.replace('.js','') theme_css = fname_stub + '.css' theme_name = basename(fname_stub).replace('_',' ').replace('-',' ').title() src = file(theme_js).read().decode('utf-8') m = re.search(r'isDark.*(true|false)', src) darkness = 'dark' if m.group(1)=='true' else 'light' isdark = darkness=='dark' m = re.search(r'cssClass.*"(.*?)"', src) theme_class = m.group(1) # print theme_name, theme_class, darkness css_themes[theme_name] = theme_class parser = tinycss.make_parser('page3') stylesheet = parser.parse_stylesheet_file(theme_css) textcolors = set() for rule in stylesheet.rules: selectors = rule.selector.as_css().split(',\n') # print selectors if selectors[0] == '.'+theme_class: colors = {} for d in rule.declarations: fgbg = d.name.split('-')[0] for v in d.value: themes[theme_name]['colors'][fgbg] = hexcolor(parse_color(v)) themes[theme_name].update(dict(dark=isdark, theme=theme_name, module='ace/theme/'+basename(fname_stub))) # find all the text colors for d in rule.declarations: if d.name == 'color': for v in d.value: textcolors.add(parse_color(v)) if any([s.endswith('.ace_selection') for s in selectors]): for d in rule.declarations: if d.name == 'background': for v in d.value: themes[theme_name]['colors']['selection'] = hexcolor(parse_color(v)) if any([s.endswith('.ace_comment') for s in selectors]): for d in rule.declarations: if d.name == 'color': # themes[theme_name]['comment'] = d.value.as_css() for v in d.value: themes[theme_name]['colors']['comment'] = hexcolor(parse_color(v)) reddest = [hexcolor(c) for c in sorted(textcolors, key=redness, reverse=True)] while reddest[0] in themes[theme_name]['colors'].values(): reddest.pop(0) themes[theme_name]['colors']['error'] = reddest[0] # pprint(json.loads(json.dumps(themes[theme_name]))) # t = themes[theme_name] # colors = dict(color=t['color'], background=t['background'], error=t['error'], comment=t['comment']) # repack = dict(theme=t['theme'], dark=t['dark'], css=t['css'], colors=colors) # themes[theme_name]['json'] = repack # 1/0 with file('../themes.json','w') as f: # json.dump({t:themes[t]['json'] for t in themes}, f, indent=2) json.dump(themes, f, indent=2) # rows = [dict(theme=n, module=t['theme'], background=t['background'], plain=t['color'], err=t['error'], comment=t['comment']) for n,t in themes.items()] # # pprint(rows) # html = tmpls.get_template('tmpl.html') # info = {"rows":rows} # with file('themes.html','w') as f: # f.write(html.render(info).encode('utf-8')) css = [] tmpl = tmpls.get_template('tmpl.css') for theme, clazz in css_themes.items(): # colors = {c:rgbacolor(v) for c,v in themes[theme]['colors'].items()} info = dict(clazz=clazz) info.update({c:rgbacolor(v) for c,v in themes[theme]['colors'].items()}) info['halfselection'] = rgbacolor(themes[theme]['colors']['selection'], .7) print theme, clazz css.append(tmpl.render(info)) with file('../autocomplete.css','w') as f: f.write("\n".join(css))