Merge pull request 'Treat uploaded custom link icons as maskable' (#6) from chore/custom_site_icons into master

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
raucao committed 2026-11-15 10:35:40 +00:00
commit c2e5d694f0
2 files changed
+9 -7

No files matched your search

+7 -5
View File
@@ -1,5 +1,7 @@
// Uploaded icons are kept small so they don't bloat IndexedDB, and only ever
// rendered through an <img>, so no markup can be executed.
// rendered through an <img>, so no markup can be executed. They're treated as
// maskable: a user-chosen icon is assumed to be a full-bleed square tile, so it
// renders edge-to-edge like a site's own maskable/apple-touch icon.
export const ICON_MAX_FILE_SIZE = 1024 * 1024;
// Match the size the favicon pipeline targets for crisp tiles on hidpi screens.
@@ -41,7 +43,7 @@ export async function readIconFile(
// SVGs are already vector and typically tiny; leave them untouched.
if (file.type === 'image/svg+xml') {
return { dataUrl, maskable: false };
return { dataUrl, maskable: true };
}
try {
@@ -53,7 +55,7 @@ export async function readIconFile(
if (scale >= 1) {
bitmap.close?.();
return { dataUrl, maskable: false };
return { dataUrl, maskable: true };
}
const canvas = document.createElement('canvas');
@@ -65,10 +67,10 @@ export async function readIconFile(
.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
bitmap.close?.();
return { dataUrl: canvas.toDataURL('image/png'), maskable: false };
return { dataUrl: canvas.toDataURL('image/png'), maskable: true };
} catch {
// Decoding or canvas can fail (Firefox rejects SVG bitmaps, say); keep the
// original bytes.
return { dataUrl, maskable: false };
return { dataUrl, maskable: true };
}
}
+2 -2
View File
@@ -42,7 +42,7 @@ module('Unit | Utility | image-file', function () {
const icon = await readIconFile(svg);
assert.true(icon.dataUrl.startsWith('data:image/svg+xml'));
assert.false(icon.maskable);
assert.true(icon.maskable);
});
test('falls back to the original bytes when decoding fails', async function (assert) {
@@ -61,7 +61,7 @@ module('Unit | Utility | image-file', function () {
const icon = await readIconFile(png);
assert.true(icon.dataUrl.startsWith('data:image/png;base64,'));
assert.false(icon.maskable);
assert.true(icon.maskable);
} finally {
globalThis.createImageBitmap = original;
}