- Remove dead CSS color property in .tab-mobile - Fix design token violations (text-red-500, fallback colors) - Add disconnectedCallback to chip-scroll, image-upload, searchable-select - Replace innerHTML with safe DOM APIs in world-map screen reader table - Add credentials: same-origin to WebAuthn fetch calls - Move page-specific scripts (donut-chart, location) out of base.html - Add client-side image resizing (1920px max dimension) - Resize app-icon-512.png from 2048x2048 to 512x512 - Document Datastar unsafe-eval CSP requirement - Add static asset serving tests (16 routes) - Add e2e tests for world-map, donut-chart, chip-scroll presence - Add cache-busting query params to all static asset URLs
19 lines
824 B
JavaScript
19 lines
824 B
JavaScript
/** Convert any image file (HEIC, AVIF, WebP, PNG, etc.) to a JPEG data URL via Canvas.
|
|
* Uses createImageBitmap which correctly applies EXIF orientation (e.g. iPhone photos).
|
|
* Caps the longest side to 1920px to avoid exceeding the request body limit. */
|
|
const imageToJpegDataUrl = async (file) => {
|
|
const bitmap = await createImageBitmap(file);
|
|
const maxDim = 1920;
|
|
let { width, height } = bitmap;
|
|
if (width > maxDim || height > maxDim) {
|
|
const scale = maxDim / Math.max(width, height);
|
|
width = Math.round(width * scale);
|
|
height = Math.round(height * scale);
|
|
}
|
|
const canvas = document.createElement("canvas");
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
canvas.getContext("2d").drawImage(bitmap, 0, 0, width, height);
|
|
bitmap.close();
|
|
return canvas.toDataURL("image/jpeg", 0.92);
|
|
};
|