Treat uploaded custom link icons as maskable
Custom icons uploaded for a custom site link were always stored as non-maskable, so they rendered inset with a rounded border instead of filling the tile. Mark every readIconFile result as maskable so uploads are drawn edge-to-edge like a site's own maskable icon, and update the image-file tests accordingly.
This commit is contained in:
2 files changed
+9
-7
No files matched your search
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user