Use minified bundle of node vibrant (#7784)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Paulus Schoutsen 2021-01-26 23:24:23 +01:00 committed by GitHub
parent 46b3836fbd
commit 4cd95b724b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { Swatch, Vec3 } from "@vibrant/color";
import { BasicPipeline } from "@vibrant/core/lib/pipeline";
import MMCQ from "@vibrant/quantizer-mmcq";
import Vibrant from "node-vibrant/lib/browser";
// We import the minified bundle because the unminified bundle
// has some quirks that break wds. See #7784 for unminified version.
import Vibrant from "node-vibrant/dist/vibrant";
import type { Swatch, Vec3 } from "@vibrant/color";
import { getRGBContrastRatio } from "../color/rgb";
const CONTRAST_RATIO = 4.5;
@ -104,23 +104,15 @@ const customGenerator = (colors: Swatch[]) => {
}
return {
foreground: new Swatch(foregroundColor, 0),
// We can't import Swatch constructor from the minified bundle, take it from background color.
// @ts-expect-error
foreground: new backgroundColor.constructor(foregroundColor, 0),
background: backgroundColor,
};
};
Vibrant.use(
new BasicPipeline().filter
.register(
"default",
(r: number, g: number, b: number, a: number) =>
a >= 125 && !(r > 250 && g > 250 && b > 250)
)
.quantizer.register("mmcq", MMCQ)
// Our generator has different output
// @ts-expect-error
.generator.register("default", customGenerator)
);
// Set our custom generator as the default.
Vibrant._pipeline.generator.register("default", customGenerator);
export const extractColors = (url: string, downsampleColors = 16) =>
new Vibrant(url, {