mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
refactor: separate output formats from io core
This commit is contained in:
@@ -83,11 +83,13 @@ aligned, ontogglealign).
|
|||||||
`sanitizeSchemaParams(stepSchema, step.params, { source: input })` — тот же
|
`sanitizeSchemaParams(stepSchema, step.params, { source: input })` — тот же
|
||||||
контракт, что в `executor/executor.ts` (вход шага как source-контекст).
|
контракт, что в `executor/executor.ts` (вход шага как source-контекст).
|
||||||
|
|
||||||
### M5. UI-метаданные дропдауна скачивания в core-слое
|
### M5. UI-метаданные дропдауна скачивания в core-слое — СДЕЛАНО (2026-10)
|
||||||
|
|
||||||
`web/src/lib/core/io.ts:10-47`: `OUTPUT_FORMATS`/`OutputFormatOption` содержат
|
`OutputFormatOption`/`OUTPUT_FORMATS`/`outputFormatByMime` вынесены из
|
||||||
`label` и `settings.quality` — конфигурацию презентационного дропдауна кнопки
|
`core/io.ts` в `web/src/lib/output-formats.ts` (UI-слой: label и
|
||||||
Download. Core по канону «не знает ни о ком».
|
`settings.quality` дропдауна кнопки Download). В core остался только
|
||||||
|
mime-контракт `OutputMime`; сам `io.ts` таблицу не использовал. Потребители (4
|
||||||
|
файла) переведены на новый путь.
|
||||||
|
|
||||||
### M6. Доменная политика сжатия в IO-модуле
|
### M6. Доменная политика сжатия в IO-модуле
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import DownloadButton from "$lib/components/ui/DownloadButton.svelte";
|
import DownloadButton from "$lib/components/ui/DownloadButton.svelte";
|
||||||
import UploadButton from "$lib/components/ui/UploadButton.svelte";
|
import UploadButton from "$lib/components/ui/UploadButton.svelte";
|
||||||
import type { OutputMime } from "$lib/core/io";
|
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 { t } from "$lib/i18n/t";
|
||||||
import type { ResultKind } from "$lib/registry";
|
import type { ResultKind } from "$lib/registry";
|
||||||
import SchemaDownload from "./SchemaDownload.svelte";
|
import SchemaDownload from "./SchemaDownload.svelte";
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import RangeControl from "$lib/components/fields/schema/RangeControl.svelte";
|
import RangeControl from "$lib/components/fields/schema/RangeControl.svelte";
|
||||||
import Icon from "$lib/components/ui/Icon.svelte";
|
import Icon from "$lib/components/ui/Icon.svelte";
|
||||||
import {
|
import type { OutputMime } from "$lib/core/io";
|
||||||
OUTPUT_FORMATS,
|
import { OUTPUT_FORMATS, outputFormatByMime } from "$lib/output-formats";
|
||||||
outputFormatByMime,
|
|
||||||
type OutputMime,
|
|
||||||
} from "$lib/core/io";
|
|
||||||
import type { SliderSpec } from "$lib/registry-schema";
|
import type { SliderSpec } from "$lib/registry-schema";
|
||||||
import { t } from "$lib/i18n/t";
|
import { t } from "$lib/i18n/t";
|
||||||
import { ChevronDown, Download } from "@lucide/svelte";
|
import { ChevronDown, Download } from "@lucide/svelte";
|
||||||
|
|||||||
@@ -9,11 +9,8 @@
|
|||||||
import { hasTransparency } from "$lib/core/analyze";
|
import { hasTransparency } from "$lib/core/analyze";
|
||||||
import { debounce } from "$lib/core/debounce";
|
import { debounce } from "$lib/core/debounce";
|
||||||
import { ToolError } from "$lib/core/errors";
|
import { ToolError } from "$lib/core/errors";
|
||||||
import {
|
import { decodeFile, type OutputMime } from "$lib/core/io";
|
||||||
decodeFile,
|
import { outputFormatByMime } from "$lib/output-formats";
|
||||||
outputFormatByMime,
|
|
||||||
type OutputMime,
|
|
||||||
} from "$lib/core/io";
|
|
||||||
import type { PixelImage } from "$lib/core/types";
|
import type { PixelImage } from "$lib/core/types";
|
||||||
import { baseName, uniqueName, type ChainWarning } from "$lib/run-chain";
|
import { baseName, uniqueName, type ChainWarning } from "$lib/run-chain";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import {
|
|||||||
downloadBlob,
|
downloadBlob,
|
||||||
encode,
|
encode,
|
||||||
fitWithinBytes,
|
fitWithinBytes,
|
||||||
outputFormatByMime,
|
|
||||||
type OutputMime,
|
type OutputMime,
|
||||||
} from "$lib/core/io";
|
} from "$lib/core/io";
|
||||||
|
import { outputFormatByMime } from "$lib/output-formats";
|
||||||
import type { PixelImage } from "$lib/core/types";
|
import type { PixelImage } from "$lib/core/types";
|
||||||
import { execute } from "$lib/executor";
|
import { execute } from "$lib/executor";
|
||||||
import { chainStepTitle, verdictText } from "$lib/i18n/schema-tool-strings";
|
import { chainStepTitle, verdictText } from "$lib/i18n/schema-tool-strings";
|
||||||
|
|||||||
@@ -7,45 +7,6 @@ import { type PixelImage } from "./types";
|
|||||||
export type OutputMime =
|
export type OutputMime =
|
||||||
"image/png" | "image/jpeg" | "image/webp" | "image/bmp";
|
"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 =
|
export const ACCEPTED_IMAGE_TYPES =
|
||||||
"image/png,image/jpeg,image/webp,image/gif,image/bmp,image/x-icon";
|
"image/png,image/jpeg,image/webp,image/gif,image/bmp,image/x-icon";
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user