-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-utils.js
33 lines (29 loc) · 917 Bytes
/
color-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import "./Vibrant.min.js";
import { waitForImage } from "./utils.js";
/** @type {VibrantConstructor} */
export const Vibrant = window["Vibrant"];
/**
* Creates a Vibrant object from the given image.
*
* @param {HTMLImageElement} image
* @returns {Promise<VibrantObj>}
*/
export async function getImageVibrant(image) {
const loadedImage = await waitForImage(image);
return new Vibrant(loadedImage, 96, 6);
}
/**
* Attempts to get a valid swatch from the list in the defined order, returning `null` if none are valid.
*
* @param {VibrantSwatches} swatchesObject
* @param {...keyof VibrantSwatches} swatches
* @returns {VibrantSwatch?}
*/
export function getValidSwatch(swatchesObject, ...swatches) {
for (const swatch of swatches) {
if (swatchesObject.hasOwnProperty(swatch) && swatchesObject[swatch]){
return swatchesObject[swatch];
}
}
return null;
}