Coverage for notation/css_color_3.py: 14%

1"""

2 CSS Color Module Level 3 - Web Colours

3======================================

4

5 Define the conversion utilities for CSS Color Module Level 3 colour keywords

6 to *RGB* colourspace representations.

7

8- :attr:`colour.notation.keyword_to_RGB_CSSColor3`

9

10 References

11----------

12- :cite:`W3C2022` : W3C. (2022). CSS Color Module Level 3.

13 https://www.w3.org/TR/css-color-3/

14"""

15

16 from __future__ import annotations

17

18 from colour.hints import Range1 # noqa: TC001

19 from colour.notation import CSS_COLOR_3, HEX_to_RGB

20 from colour.utilities import attest

21

22 __author__ = "Colour Developers"

23 __copyright__ = "Copyright 2013 Colour Developers"

24 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

25 __maintainer__ = "Colour Developers"

26 __email__ = "colour-developers@colour-science.org"

27 __status__ = "Production"

28

29 __all__ = [

30 "keyword_to_RGB_CSSColor3",

31]

32

33

34 def keyword_to_RGB_CSSColor3(keyword: str) -> Range1:

35 """

36 Convert specified colour keyword to *RGB* colourspace according to

37 *CSS Color Module Level 3* *W3C Recommendation*.

38

39 Parameters

40 ----------

41 keyword

42 Colour keyword.

43

44 Returns

45 -------

46 :class:`numpy.array`

47 *RGB* colourspace array.

48

49 Notes

50 -----

51 +------------+-----------------------+---------------+

52 | **Range** | **Scale - Reference** | **Scale - 1** |

53 +============+=======================+===============+

54 | ``RGB`` | 1 | 1 |

55 +------------+-----------------------+---------------+

56

57 - All the RGB colors are specified in the *IEC 61966-2-1:1999*

58 *sRGB* colourspace.

59

60 Examples

61 --------

62 >>> keyword_to_RGB_CSSColor3("black")

63 array([ 0., 0., 0.])

64 >>> keyword_to_RGB_CSSColor3("white")

65 array([ 1., 1., 1.])

66 >>> keyword_to_RGB_CSSColor3("aliceblue") # doctest: +ELLIPSIS

67 array([ 0.9411764..., 0.9725490..., 1. ])

68 """

69

70 attest(keyword in CSS_COLOR_3, f'{keyword} is not defined in "CSS Color 3"!')

71

72 return HEX_to_RGB(CSS_COLOR_3[keyword])