fix: image decode error i18n

This commit is contained in:
2026-10-08 03:06:55 +05:00
parent fce1b20e85
commit 76039f7bf3
4 changed files with 14 additions and 4 deletions
-2
View File
@@ -176,8 +176,6 @@
в дизайне, а где должен быть 0 в дизайне, а где должен быть 0
- [ ] Component-тесты `SchemaToolView`/`SchemaPreview` требуют отдельного - [ ] Component-тесты `SchemaToolView`/`SchemaPreview` требуют отдельного
решения: node Vitest не имеет DOM/canvas, а e2e уже покрывает поведение. решения: node Vitest не имеет DOM/canvas, а e2e уже покрывает поведение.
- [ ] Ошибка декодирования изображения из `createImageBitmap` пока показывается
сырым сообщением браузера; нужен `ToolError`-маппер и i18n-ключ.
- [ ] **Идея 13. Контраст текста на акцентных кнопках — частично закрыт**. Тона - [ ] **Идея 13. Контраст текста на акцентных кнопках — частично закрыт**. Тона
`--color-main`/`--color-accent` подняты под текущий порог `--color-main`/`--color-accent` подняты под текущий порог
`palette.test.ts`; targeted-тест проходит. Light-тема всё ещё ниже AA 4.5 `palette.test.ts`; targeted-тест проходит. Light-тема всё ещё ниже AA 4.5
+10 -2
View File
@@ -59,6 +59,14 @@ export function unsupportedImageError(file: File): ToolError {
}); });
} }
async function toBitmap(source: Blob | File): Promise<ImageBitmap> {
try {
return await createImageBitmap(source);
} catch {
throw new ToolError("errors.imageDecode");
}
}
async function decodeBitmap(bitmap: ImageBitmap): Promise<PixelImage> { async function decodeBitmap(bitmap: ImageBitmap): Promise<PixelImage> {
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
canvas.width = bitmap.width; canvas.width = bitmap.width;
@@ -77,7 +85,7 @@ async function decodeBitmap(bitmap: ImageBitmap): Promise<PixelImage> {
} }
export async function decodeFile(file: File): Promise<PixelImage> { export async function decodeFile(file: File): Promise<PixelImage> {
const bitmap = await createImageBitmap(file); const bitmap = await toBitmap(file);
try { try {
return await decodeBitmap(bitmap); return await decodeBitmap(bitmap);
} finally { } finally {
@@ -89,7 +97,7 @@ export async function decodeBytes(
bytes: Uint8Array<ArrayBuffer>, bytes: Uint8Array<ArrayBuffer>,
): Promise<PixelImage> { ): Promise<PixelImage> {
const blob = new Blob([bytes]); const blob = new Blob([bytes]);
const bitmap = await createImageBitmap(blob); const bitmap = await toBitmap(blob);
try { try {
return await decodeBitmap(bitmap); return await decodeBitmap(bitmap);
} finally { } finally {
+2
View File
@@ -192,6 +192,8 @@ export const en: Dict = {
"Crop area doesn't fit: offset plus size exceeds the image bounds", "Crop area doesn't fit: offset plus size exceeds the image bounds",
noCanvasCtx: "Canvas 2D context is unavailable in this environment", noCanvasCtx: "Canvas 2D context is unavailable in this environment",
badBase64: "Expected a base64 string or a data-uri of an image", badBase64: "Expected a base64 string or a data-uri of an image",
imageDecode:
"Can't read the image — the file is corrupted or the format is unsupported",
qualityRange: "quality must be within 0..1", qualityRange: "quality must be within 0..1",
svgSize: "Could not determine SVG dimensions", svgSize: "Could not determine SVG dimensions",
svgLoad: "Failed to load SVG — check the markup", svgLoad: "Failed to load SVG — check the markup",
+2
View File
@@ -193,6 +193,8 @@ export const ru: Dict = {
"Область не помещается: смещение + размер превышают границы изображения", "Область не помещается: смещение + размер превышают границы изображения",
noCanvasCtx: "Canvas 2D context недоступен в этом окружении", noCanvasCtx: "Canvas 2D context недоступен в этом окружении",
badBase64: "Ожидается base64-строка или data-uri изображения", badBase64: "Ожидается base64-строка или data-uri изображения",
imageDecode:
"Не удалось прочитать изображение — файл повреждён или формат не поддерживается",
qualityRange: "quality должно быть в диапазоне 0..1", qualityRange: "quality должно быть в диапазоне 0..1",
svgSize: "Не удалось определить размер SVG", svgSize: "Не удалось определить размер SVG",
svgLoad: "Не удалось загрузить SVG — проверьте разметку", svgLoad: "Не удалось загрузить SVG — проверьте разметку",