Skip to content

Commit c59b394

Browse files
committed
Add documentation for color modules
1 parent 36b3f6a commit c59b394

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

docs/api_reference.rst

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,49 @@ serialization-related functions are available:
3838
.. autofunction:: serialize_identifier
3939

4040

41+
Color Level 3
42+
-------------
43+
4144
.. module:: tinycss2.color3
45+
.. autofunction:: parse_color
46+
.. autoclass:: RGBA
4247

4348

44-
Color
45-
-----
49+
Color Level 4
50+
-------------
4651

52+
.. module:: tinycss2.color4
4753
.. autofunction:: parse_color
48-
.. autoclass:: RGBA
54+
.. autoclass:: Color
55+
:members:
56+
.. autodata:: COLOR_SPACES
57+
.. autodata:: D50
58+
.. autodata:: D65
4959

60+
Color Level 5
61+
-------------
5062

51-
.. module:: tinycss2.nth
63+
.. module:: tinycss2.color5
64+
.. autofunction:: parse_color
65+
.. autoclass:: Color
66+
:show-inheritance:
67+
.. autodata:: COLOR_SPACES
68+
.. autodata:: D50
69+
.. autodata:: D65
5270

5371

5472
<An+B>
5573
------
5674

75+
.. module:: tinycss2.nth
5776
.. autofunction:: parse_nth
5877

5978

60-
.. module:: tinycss2.ast
61-
62-
6379
AST nodes
6480
---------
6581

82+
.. module:: tinycss2.ast
83+
6684
Various parsing functions return a **node** or a list of nodes. Some types of
6785
nodes contain nested nodes which may in turn contain more nodes, forming
6886
together an **abstract syntax tree**.

tinycss2/color4.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
from .color3 import _BASIC_COLOR_KEYWORDS, _EXTENDED_COLOR_KEYWORDS, _HASH_REGEXPS
55
from .parser import parse_one_component_value
66

7+
#: XYZ values of the D50 white point, normalized to Y=1.
78
D50 = (0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585)
9+
#: XYZ values of the D65 white point, normalized to Y=1.
810
D65 = (0.3127 / 0.3290, 1, (1 - 0.3127 - 0.3290) / 0.3290)
911
_FUNCTION_SPACES = {
1012
'srgb', 'srgb-linear',
1113
'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020',
1214
'xyz', 'xyz-d50', 'xyz-d65'
1315
}
16+
#: Supported color spaces.
1417
COLOR_SPACES = _FUNCTION_SPACES | {'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'}
1518

1619

tinycss2/color5.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from . import color4
22

3+
#: Supported color spaces.
34
COLOR_SPACES = color4.COLOR_SPACES | {'device-cmyk'}
5+
#: Supported color schemes.
46
COLOR_SCHEMES = {'light', 'dark'}
7+
#: XYZ values of the D50 white point, normalized to Y=1.
58
D50 = color4.D50
9+
#: XYZ values of the D65 white point, normalized to Y=1.
610
D65 = color4.D65
711

812

@@ -11,6 +15,22 @@ class Color(color4.Color):
1115

1216

1317
def parse_color(input, color_schemes=None):
18+
"""Parse a color value as defined in CSS Color Level 5.
19+
20+
https://www.w3.org/TR/css-color-5/
21+
22+
:type input: :obj:`str` or :term:`iterable`
23+
:param input: A string or an iterable of :term:`component values`.
24+
:type color_schemes: :obj:`str` or :term:`iterable`
25+
:param color_schemes: the ``'normal'`` string, or an iterable of color
26+
schemes used to resolve the ``light-dark()`` function.
27+
:returns:
28+
* :obj:`None` if the input is not a valid color value.
29+
(No exception is raised.)
30+
* The string ``'currentcolor'`` for the ``currentcolor`` keyword
31+
* A :class:`Color` object for every other values, including keywords.
32+
33+
"""
1434
color = color4.parse_color(input)
1535

1636
if color:

0 commit comments

Comments
 (0)