mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-28 15:27:20 +00:00
Use minified bundle of node vibrant (#7784)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
46b3836fbd
commit
4cd95b724b
@ -1,7 +1,7 @@
|
|||||||
import { Swatch, Vec3 } from "@vibrant/color";
|
// We import the minified bundle because the unminified bundle
|
||||||
import { BasicPipeline } from "@vibrant/core/lib/pipeline";
|
// has some quirks that break wds. See #7784 for unminified version.
|
||||||
import MMCQ from "@vibrant/quantizer-mmcq";
|
import Vibrant from "node-vibrant/dist/vibrant";
|
||||||
import Vibrant from "node-vibrant/lib/browser";
|
import type { Swatch, Vec3 } from "@vibrant/color";
|
||||||
import { getRGBContrastRatio } from "../color/rgb";
|
import { getRGBContrastRatio } from "../color/rgb";
|
||||||
|
|
||||||
const CONTRAST_RATIO = 4.5;
|
const CONTRAST_RATIO = 4.5;
|
||||||
@ -104,23 +104,15 @@ const customGenerator = (colors: Swatch[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
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,
|
background: backgroundColor,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Vibrant.use(
|
// Set our custom generator as the default.
|
||||||
new BasicPipeline().filter
|
Vibrant._pipeline.generator.register("default", customGenerator);
|
||||||
.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)
|
|
||||||
);
|
|
||||||
|
|
||||||
export const extractColors = (url: string, downsampleColors = 16) =>
|
export const extractColors = (url: string, downsampleColors = 16) =>
|
||||||
new Vibrant(url, {
|
new Vibrant(url, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user