67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import { Elm } from './src/Main.elm'
|
|
|
|
if (typeof window === 'undefined') {
|
|
global.window = {};
|
|
}
|
|
|
|
|
|
function _check_webp_feature(feature, callback) {
|
|
var kTestImages = {
|
|
lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
|
|
lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
|
|
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
|
|
};
|
|
|
|
var img = new Image();
|
|
img.onload = function () {
|
|
var result = (img.width > 0) && (img.height > 0);
|
|
callback(feature, result);
|
|
};
|
|
|
|
img.onerror = function () {
|
|
callback(feature, false);
|
|
};
|
|
|
|
img.src = "data:image/webp;base64," + kTestImages[feature];
|
|
}
|
|
|
|
async function getWebpFeatures() {
|
|
return (await Promise.all(["lossy", "lossless", "alpha"].map((f) => {
|
|
return new Promise((resolve, _) => {
|
|
_check_webp_feature(f, (_, s) => resolve(s ? f : null));
|
|
})
|
|
}))).filter(f => f !== null);
|
|
}
|
|
|
|
; (async () => {
|
|
const webpFeatures = await getWebpFeatures();
|
|
|
|
const images = {
|
|
// icon: (new URL("/data/images/icon.png", import.meta.url)).href,
|
|
// logo: (new URL("/data/images/logo.png", import.meta.url)).href,
|
|
// banners: {
|
|
// 1: (new URL("/data/images/banners/1.jpg", import.meta.url)).href,
|
|
// },
|
|
};
|
|
|
|
const lossyWebps = {
|
|
};
|
|
|
|
// use lossless=true
|
|
const losslessWebps = {
|
|
|
|
};
|
|
|
|
const allImages = {
|
|
...images,
|
|
...(webpFeatures.includes("lossless") ? losslessWebps : {}),
|
|
...(webpFeatures.includes("lossy") ? lossyWebps : {}),
|
|
};
|
|
|
|
const app = Elm.Main.init({
|
|
flags: {
|
|
images: allImages,
|
|
}
|
|
});
|
|
})()
|