add ignored colors to both hook and function

This commit is contained in:
jeffvli
2025-11-21 20:42:49 -08:00
parent 6ba15ae0a0
commit d16b419604
+12 -14
View File
@@ -1,6 +1,15 @@
import { FastAverageColor } from 'fast-average-color'; import { FastAverageColor, FastAverageColorIgnoredColor } from 'fast-average-color';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
const ignoredColors: FastAverageColorIgnoredColor = [
[255, 255, 255, 255, 90], // White
[255, 255, 255, 255, 50], // Light gray
[255, 255, 255, 255, 30], // Very light gray
[255, 255, 255, 255, 10], // Very very light gray
[0, 0, 0, 255, 30], // Black
[0, 0, 0, 0, 40], // Transparent
];
export const getFastAverageColor = async (args: { export const getFastAverageColor = async (args: {
algorithm?: 'dominant' | 'simple' | 'sqrt'; algorithm?: 'dominant' | 'simple' | 'sqrt';
src: string; src: string;
@@ -8,14 +17,7 @@ export const getFastAverageColor = async (args: {
const fac = new FastAverageColor(); const fac = new FastAverageColor();
const background = await fac.getColorAsync(args.src, { const background = await fac.getColorAsync(args.src, {
algorithm: args.algorithm || 'dominant', algorithm: args.algorithm || 'dominant',
ignoredColor: [ ignoredColor: ignoredColors,
[255, 255, 255, 255, 90], // White
[255, 255, 255, 255, 50], // Light gray
[255, 255, 255, 255, 30], // Very light gray
[255, 255, 255, 255, 10], // Very very light gray
[0, 0, 0, 255, 30], // Black
[0, 0, 0, 0, 40], // Transparent
],
mode: 'speed', mode: 'speed',
}); });
@@ -52,11 +54,7 @@ export const useFastAverageColor = (args: {
setIsLoading(true); setIsLoading(true);
fac.getColorAsync(src, { fac.getColorAsync(src, {
algorithm: algorithm || 'dominant', algorithm: algorithm || 'dominant',
ignoredColor: [ ignoredColor: ignoredColors,
[255, 255, 255, 255, 90], // White
[0, 0, 0, 255, 30], // Black
[0, 0, 0, 0, 40], // Transparent
],
mode: 'speed', mode: 'speed',
}) })
.then((color) => { .then((color) => {