@@ -37,6 +37,16 @@ def _svg_resources() -> dict[str, str]:
3737 return json .loads (_resources .SVG_RESOURCES )
3838
3939
40+ def _transform (color : Color , color_state : dict [str , float ]) -> Color :
41+ if color_state .get ("transparent" ):
42+ color = color .transparent (color_state ["transparent" ])
43+ if color_state .get ("darken" ):
44+ color = color .darken (color_state ["darken" ])
45+ if color_state .get ("lighten" ):
46+ return color .lighten (color_state ["lighten" ])
47+ return color
48+
49+
4050def color (color_info : str | dict [str , str | dict ], state : str | None = None ) -> Color :
4151 """Filter for template engine. This filter convert color info data to color object."""
4252 if isinstance (color_info , str ):
@@ -48,17 +58,8 @@ def color(color_info: str | dict[str, str | dict], state: str | None = None) ->
4858 if state is None :
4959 return color
5060
51- color_state = color_info [state ]
52- if isinstance (color_state , str ):
53- return Color .from_hex (color_state )
54-
55- if color_state .get ("transparent" ):
56- color = color .transparent (color_state ["transparent" ])
57- if color_state .get ("darken" ):
58- color = color .darken (color_state ["darken" ])
59- if color_state .get ("lighten" ):
60- return color .lighten (color_state ["lighten" ])
61- return color
61+ transforms = color_info [state ]
62+ return Color .from_hex (transforms ) if isinstance (transforms , str ) else _transform (color , transforms )
6263
6364
6465def svg_format (color : Color ) -> str :
0 commit comments