aboutsummaryrefslogtreecommitdiff
path: root/src/lib/color.ts
diff options
context:
space:
mode:
authorJoris2025-04-19 12:36:38 +0200
committerJoris2025-04-19 12:38:24 +0200
commit632eef6424d8dc8d40c2906177892697679e7b85 (patch)
tree48d9cd60e9e96eab810b5f7bb3c7b1fa79e0438f /src/lib/color.ts
parent063d8ef9eaf874a941f4459e831057dd0a1b7ddd (diff)
Add ZIG server
Diffstat (limited to 'src/lib/color.ts')
-rw-r--r--src/lib/color.ts36
1 files changed, 0 insertions, 36 deletions
diff --git a/src/lib/color.ts b/src/lib/color.ts
deleted file mode 100644
index 59b320d..0000000
--- a/src/lib/color.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-interface Color {
- red: number,
- green: number,
- blue: number,
-}
-
-export function parse(str: string): Color {
- return {
- red: parseInt(str.slice(1,3), 16),
- green: parseInt(str.slice(3,5), 16),
- blue: parseInt(str.slice(5,7), 16),
- }
-}
-
-// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrastratio
-export function contrastRatio(c1: Color, c2: Color): number {
- const r1 = relativeLuminance(c1)
- const r2 = relativeLuminance(c2)
-
- return r1 > r2
- ? (r1 + 0.05) / (r2 + 0.05)
- : (r2 + 0.05) / (r1 + 0.05)
-}
-
-function relativeLuminance(c: Color): number {
- return (
- 0.2126 * fromSRGB(c.red / 255)
- + 0.7152 * fromSRGB(c.green / 255)
- + 0.0722 * fromSRGB(c.blue / 255))
-}
-
-function fromSRGB(sRGB: number): number {
- return sRGB <= 0.03928
- ? sRGB / 12.92
- : Math.pow(((sRGB + 0.055) / 1.055), 2.4)
-}