2026-09-08 17:38:13 +03:00
|
|
|
|
// lib/common/utils/file.util.js
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Определение типа файла
|
|
|
|
|
|
* @param {File} file
|
|
|
|
|
|
* @returns {'image' | 'pdf' | 'other'}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function detectFileType(file) {
|
|
|
|
|
|
if (!file) return 'other';
|
|
|
|
|
|
if (file.type.startsWith('image/')) return 'image';
|
|
|
|
|
|
if (file.type === 'application/pdf') return 'pdf';
|
|
|
|
|
|
return 'other';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Формирование текстовой метки выбранных страниц
|
|
|
|
|
|
* @param {import('$lib/pages/print/stores/print.store.svelte').FileEntry} entry
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function pagesLabel(entry) {
|
|
|
|
|
|
if (!entry.totalPages || entry.totalPages === 0) return '...';
|
|
|
|
|
|
if (!entry.selectedPages || entry.selectedPages.size === 0) return 'Нет';
|
|
|
|
|
|
if (entry.selectedPages.size === entry.totalPages) return 'Все';
|
|
|
|
|
|
if (entry.selectedPages.size === 1) return `стр. ${[...entry.selectedPages][0]}`;
|
2026-09-14 08:59:58 +03:00
|
|
|
|
return `${entry.selectedPages.size}/${entry.totalPages} стр.`;
|
2026-09-08 17:38:13 +03:00
|
|
|
|
}
|