const WebpImage = `data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA=`;
// Source https://stackoverflow.com/questions/5573096/detecting-webp-support
function isCanvasWebpSupported() {
    const elem = document.createElement('canvas');
    if (!!(elem.getContext && elem.getContext('2d'))) {
        // was able or not to get WebP representation
        return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
    }
    // very old browser like IE 8, canvas not supported
    return false;
}
/**
 * Is this runtime able to support webp
 */
function isWebpImageSupported() {
    // Some browsers (firefox) support rendering webp but not creating with canvas
    const img = new Image();
    const promise = new Promise((resolve) => {
        img.onload = () => resolve(true);
        img.onerror = () => resolve(false);
    });
    img.src = WebpImage;
    return promise;
}
/** Is WebP able to be rendered in this environment */
export function isWebpSupported() {
    return new Promise((resolve) => {
        if (isCanvasWebpSupported())
            return resolve(true);
        isWebpImageSupported()
            .then(resolve)
            .catch(() => resolve(false));
    });
}
//# sourceMappingURL=webp.js.map