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:
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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