0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

fix: get luminosity

This commit is contained in:
Marina López 2024-03-14 14:42:01 +01:00 committed by Juanfran
parent c9b21e47ab
commit d2382e0c0f

View file

@ -19,11 +19,11 @@ export class AppElement extends HTMLElement {
getLuminosity(color: string) {
const rgb = this.hexToRgb(color);
return (
0.2126 * (rgb[0] / 255) +
0.7152 * (rgb[1] / 255) +
0.0722 * (rgb[2] / 255)
);
const a = rgb.map((v) => {
v /= 255;
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
});
return 0.2126 * a[0] + 0.7152 * a[1] + 0.0722 * a[2];
}
hexToRgb(hex: string) {