Skip to content

Commit

Permalink
more accurate colors for svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Dec 19, 2023
1 parent c31abc4 commit 04972e5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,13 @@ function hexToRgb(hex: string) {

const cachedColors: any = {};

export const convertRgbToFilter = (color_: string) => {
export const convertRgbToFilter = (
color_: string
): {
values: number[] | null;
loss: number;
filter: string;
} => {
if (cachedColors[color_]) {
return cachedColors[color_];
}
Expand All @@ -345,6 +351,9 @@ export const convertRgbToFilter = (color_: string) => {
const solver = new Solver(color);
const result = solver.solve();

// Make sure loss is less than 1
if (result.loss > 1) return convertRgbToFilter(color_);

cachedColors[color_] = { ...result };
return result;
};

0 comments on commit 04972e5

Please sign in to comment.