Skip to content

Commit

Permalink
Update hsluv usage to new major version
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Oct 17, 2023
1 parent 5014097 commit 2f58980
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client/src/utils/color.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hsluvToHex, hsluvToRgb } from "hsluv";
import { Hsluv } from "hsluv";
import { hashFnv32a } from "utils/utils";

/**
Expand All @@ -16,10 +16,17 @@ export function keyedColorScheme(strKey) {
lightness += (100 - lightness) * 0.75;
}

const [r, g, b] = hsluvToRgb([hue, 100, lightness]);
const primary = `rgb(${parseInt(r * 255)},${parseInt(g * 255)},${parseInt(b * 255)})`;
const darker = hsluvToHex([hue, 100, lightness * 0.9]);
const dimmed = hsluvToHex([hue, 100, lightness * 0.95]);

const conv = new Hsluv();
conv.hsluv_h = hue;
conv.hsluv_s = 100;
conv.hsluv_l = lightness;
conv.hsluvToHex();
const primary = `rgb(${parseInt(conv.rgb_r * 255)},${parseInt(conv.rgb_g * 255)},${parseInt(conv.rgb_b * 255)})`;
conv.hsluv_l = lightness * 0.9;
conv.hsluvToHex();
const darker = conv.hex;
conv.hsluv_l = lightness * 0.95;
conv.hsluvToHex();
const dimmed = conv.hex;
return { primary, darker, dimmed };
}

0 comments on commit 2f58980

Please sign in to comment.