mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
refactor: dropzone update
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { ACCEPTED_IMAGE_TYPES } from '$lib/core/io';
|
||||
import { ACCEPTED_IMAGE_TYPES, isSupportedImage } from '$lib/core/io';
|
||||
|
||||
let {
|
||||
onFile,
|
||||
onError,
|
||||
label = 'Перетащите изображение сюда или нажмите, чтобы выбрать файл'
|
||||
}: {
|
||||
interface Props {
|
||||
onFile: (file: File) => void;
|
||||
onError?: (message: string) => void;
|
||||
label?: string;
|
||||
} = $props();
|
||||
}
|
||||
|
||||
let { onFile, onError, label = 'Перетащите изображение сюда или нажмите, чтобы выбрать файл' }: Props =
|
||||
$props();
|
||||
|
||||
let input = $state<HTMLInputElement | undefined>();
|
||||
let dragging = $state(false);
|
||||
|
||||
const acceptedMimes = new Set(ACCEPTED_IMAGE_TYPES.split(','));
|
||||
|
||||
function accept(file: File | undefined | null) {
|
||||
if (!file) return;
|
||||
if (!acceptedMimes.has(file.type)) {
|
||||
if (!isSupportedImage(file)) {
|
||||
onError?.(
|
||||
`Неподдерживаемый формат файла (${file.type || 'неизвестный'}). Поддерживаются PNG, JPEG, WebP, GIF и BMP.`
|
||||
);
|
||||
|
||||
@@ -5,6 +5,12 @@ export type OutputMime = 'image/png' | 'image/jpeg' | 'image/webp';
|
||||
export const ACCEPTED_IMAGE_TYPES =
|
||||
'image/png,image/jpeg,image/webp,image/gif,image/bmp,image/x-icon';
|
||||
|
||||
const SUPPORTED_MIME_TYPES = new Set(ACCEPTED_IMAGE_TYPES.split(','));
|
||||
|
||||
export function isSupportedImage(file: File): boolean {
|
||||
return SUPPORTED_MIME_TYPES.has(file.type);
|
||||
}
|
||||
|
||||
export async function decodeFile(file: File): Promise<PixelImage> {
|
||||
const bitmap = await createImageBitmap(file);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user