| # Copyright 2021 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| '''A representation of a single color value. |
| This opacity can be of the following formats: |
| def __init__(self, value=None): |
| if not self.var and self.a == -1: |
| raise ValueError('Malformed opacity value:' + value) |
| if isinstance(value, str): |
| match = re.match(r'^\$([a-z0-9_\-\.]+)$', value) |
| self.var = match.group(1) |
| if not (0 <= self.a <= 1): |
| raise ValueError('Alpha expected to be between 0 and 1') |
| def GetReadableStr(self): |
| return 'var(--%s)' % self.var if self.var else '%g%%' % ( |
| return 'var(--%s)' % self.var if self.var else '%g' % self.a |