You've already forked snikket-web-portal
Prepare for fully typechecked codebase
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import functools
|
||||
import hashlib
|
||||
import typing
|
||||
|
||||
import hsluv
|
||||
|
||||
# This is essentially an implementation of XEP-0392.
|
||||
|
||||
|
||||
def clip_rgb(r, g, b):
|
||||
RGBf = typing.Tuple[float, float, float]
|
||||
|
||||
|
||||
def clip_rgb(r: float, g: float, b: float) -> RGBf:
|
||||
return (
|
||||
min(max(r, 0), 1),
|
||||
min(max(g, 0), 1),
|
||||
@@ -15,7 +19,7 @@ def clip_rgb(r, g, b):
|
||||
|
||||
|
||||
@functools.lru_cache(128)
|
||||
def text_to_colour(text):
|
||||
def text_to_colour(text: str) -> RGBf:
|
||||
MASK = 0xffff
|
||||
h = hashlib.sha1()
|
||||
h.update(text.encode("utf-8"))
|
||||
@@ -26,7 +30,7 @@ def text_to_colour(text):
|
||||
return r, g, b
|
||||
|
||||
|
||||
def text_to_css(text):
|
||||
def text_to_css(text: str) -> str:
|
||||
return "#{:02x}{:02x}{:02x}".format(
|
||||
*(round(v * 255) for v in text_to_colour(text))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user