refactor: separate output formats from io core

This commit is contained in:
2026-10-10 06:10:10 +05:00
parent e51d6f3239
commit dfb1f531fa
7 changed files with 56 additions and 55 deletions
+6 -4
View File
@@ -83,11 +83,13 @@ aligned, ontogglealign).
`sanitizeSchemaParams(stepSchema, step.params, { source: input })` — тот же
контракт, что в `executor/executor.ts` (вход шага как source-контекст).
### M5. UI-метаданные дропдауна скачивания в core-слое
### M5. UI-метаданные дропдауна скачивания в core-слое — СДЕЛАНО (2026-10)
`web/src/lib/core/io.ts:10-47`: `OUTPUT_FORMATS`/`OutputFormatOption` содержат
`label` и `settings.quality` — конфигурацию презентационного дропдауна кнопки
Download. Core по канону «не знает ни о ком».
`OutputFormatOption`/`OUTPUT_FORMATS`/`outputFormatByMime` вынесены из
`core/io.ts` в `web/src/lib/output-formats.ts` (UI-слой: label и
`settings.quality` дропдауна кнопки Download). В core остался только
mime-контракт `OutputMime`; сам `io.ts` таблицу не использовал. Потребители (4
файла) переведены на новый путь.
### M6. Доменная политика сжатия в IO-модуле
@@ -2,7 +2,7 @@
import DownloadButton from "$lib/components/ui/DownloadButton.svelte";
import UploadButton from "$lib/components/ui/UploadButton.svelte";
import type { OutputMime } from "$lib/core/io";
import { outputFormatByMime } from "$lib/core/io";
import { outputFormatByMime } from "$lib/output-formats";
import { t } from "$lib/i18n/t";
import type { ResultKind } from "$lib/registry";
import SchemaDownload from "./SchemaDownload.svelte";
@@ -1,11 +1,8 @@
<script lang="ts">
import RangeControl from "$lib/components/fields/schema/RangeControl.svelte";
import Icon from "$lib/components/ui/Icon.svelte";
import {
OUTPUT_FORMATS,
outputFormatByMime,
type OutputMime,
} from "$lib/core/io";
import type { OutputMime } from "$lib/core/io";
import { OUTPUT_FORMATS, outputFormatByMime } from "$lib/output-formats";
import type { SliderSpec } from "$lib/registry-schema";
import { t } from "$lib/i18n/t";
import { ChevronDown, Download } from "@lucide/svelte";
@@ -9,11 +9,8 @@
import { hasTransparency } from "$lib/core/analyze";
import { debounce } from "$lib/core/debounce";
import { ToolError } from "$lib/core/errors";
import {
decodeFile,
outputFormatByMime,
type OutputMime,
} from "$lib/core/io";
import { decodeFile, type OutputMime } from "$lib/core/io";
import { outputFormatByMime } from "$lib/output-formats";
import type { PixelImage } from "$lib/core/types";
import { baseName, uniqueName, type ChainWarning } from "$lib/run-chain";
import {
@@ -3,9 +3,9 @@ import {
downloadBlob,
encode,
fitWithinBytes,
outputFormatByMime,
type OutputMime,
} from "$lib/core/io";
import { outputFormatByMime } from "$lib/output-formats";
import type { PixelImage } from "$lib/core/types";
import { execute } from "$lib/executor";
import { chainStepTitle, verdictText } from "$lib/i18n/schema-tool-strings";
-39
View File
@@ -7,45 +7,6 @@ import { type PixelImage } from "./types";
export type OutputMime =
"image/png" | "image/jpeg" | "image/webp" | "image/bmp";
export interface OutputFormatOption {
mime: OutputMime;
ext: string;
label: string;
supportsAlpha: boolean;
/** Fine-grained format settings in the Download button dropdown (extensible). */
settings?: {
quality?: { min: number; max: number; step: number; default: number };
};
}
const QUALITY_SETTING = { min: 1, max: 100, step: 1, default: 90 } as const;
/** Format options in the Download button (selector next to it). */
export const OUTPUT_FORMATS: readonly OutputFormatOption[] = [
{ mime: "image/png", ext: "png", label: "PNG", supportsAlpha: true },
{
mime: "image/jpeg",
ext: "jpg",
label: "JPG",
supportsAlpha: false,
settings: { quality: QUALITY_SETTING },
},
{
mime: "image/webp",
ext: "webp",
label: "WebP",
supportsAlpha: true,
settings: { quality: QUALITY_SETTING },
},
{ mime: "image/bmp", ext: "bmp", label: "BMP", supportsAlpha: false },
];
export function outputFormatByMime(mime: OutputMime): OutputFormatOption {
const found = OUTPUT_FORMATS.find((f) => f.mime === mime);
if (!found) throw new ToolError("errors.encodeUnsupported", { mime });
return found;
}
export const ACCEPTED_IMAGE_TYPES =
"image/png,image/jpeg,image/webp,image/gif,image/bmp,image/x-icon";
+44
View File
@@ -0,0 +1,44 @@
import { ToolError } from "./core/errors";
import type { OutputMime } from "./core/io";
// Presentation metadata of download formats for the Download button dropdown
// (labels, quality slider ranges). Core keeps only the mime contract
// (core/io.ts); this module is the UI layer's view of the same formats.
export interface OutputFormatOption {
mime: OutputMime;
ext: string;
label: string;
supportsAlpha: boolean;
/** Fine-grained format settings in the Download button dropdown (extensible). */
settings?: {
quality?: { min: number; max: number; step: number; default: number };
};
}
const QUALITY_SETTING = { min: 1, max: 100, step: 1, default: 90 } as const;
/** Format options in the Download button (selector next to it). */
export const OUTPUT_FORMATS: readonly OutputFormatOption[] = [
{ mime: "image/png", ext: "png", label: "PNG", supportsAlpha: true },
{
mime: "image/jpeg",
ext: "jpg",
label: "JPG",
supportsAlpha: false,
settings: { quality: QUALITY_SETTING },
},
{
mime: "image/webp",
ext: "webp",
label: "WebP",
supportsAlpha: true,
settings: { quality: QUALITY_SETTING },
},
{ mime: "image/bmp", ext: "bmp", label: "BMP", supportsAlpha: false },
];
export function outputFormatByMime(mime: OutputMime): OutputFormatOption {
const found = OUTPUT_FORMATS.find((f) => f.mime === mime);
if (!found) throw new ToolError("errors.encodeUnsupported", { mime });
return found;
}