diff --git a/public/pdf.html b/public/pdf.html index 6706a16..bbea2fe 100644 --- a/public/pdf.html +++ b/public/pdf.html @@ -745,8 +745,7 @@ Нажмите на страницы для поворота
- - + Нажмите на страницу для поворота
@@ -1189,7 +1188,14 @@ if (_sel && typeof renderPageGrid === 'function') { renderPageGrid('deletePageGrid', 'deleteHint', _sel.id, _sel.pages, 'delete'); renderPageGrid('rotatePageGrid', 'rotateHint', _sel.id, _sel.pages, 'rotate'); - renderPageGrid('reorderPageGrid', 'reorderHint', _sel.id, _sel.pages, 'reorder'); + if (_sel.pages > 1) { + renderPageGrid('reorderPageGrid', 'reorderHint', _sel.id, _sel.pages, 'reorder'); + } else { + var rg = document.getElementById('reorderPageGrid'); + var rh = document.getElementById('reorderHint'); + if (rg) rg.innerHTML = ''; + if (rh) rh.textContent = 'Нужно больше одной страницы'; + } } } @@ -1719,15 +1725,13 @@ }); } else if (mode === 'rotate') { thumb.addEventListener('click', () => { - thumb.classList.toggle('selected'); - // Visual rotation preview - if (thumb.classList.contains('selected')) { - const angle = state.rotateAngle || 90; - thumb.classList.add('rotate-' + angle); - } else { - thumb.classList.remove('rotate-90', 'rotate-180', 'rotate-270'); - } - updateRotateCount(); + // Immediate rotate on click + const angle = state.rotateAngle || 90; + thumb.classList.add('rotate-' + angle); + thumb.style.pointerEvents = 'none'; + thumb.style.opacity = '0.6'; + // Auto-execute rotate for this page + autoRotatePage(parseInt(thumb.dataset.page), angle); }); } else if (mode === 'reorder') { // Drag and drop @@ -1797,6 +1801,11 @@ if (!pages.length) { showError('Выберите страницы'); return; } const fileId = state.selectedFileId; if (!fileId) { showError('Выберите файл'); return; } + const selFile = state.files.find(f => f.id === fileId); + if (selFile && pages.length >= selFile.pages) { + showError('Нельзя удалить все страницы'); + return; + } clearError(); // Hide deleted pages visually const grid = document.getElementById('deletePageGrid'); @@ -1917,6 +1926,32 @@ } } + + // Auto-rotate single page on click + let _rotateTimeout = null; + function autoRotatePage(pageNum, angle) { + clearTimeout(_rotateTimeout); + const hint = document.getElementById('rotateHint'); + if (hint) hint.textContent = 'Поворот страницы ' + pageNum + '...'; + _rotateTimeout = setTimeout(async () => { + const fileId = state.selectedFileId; + if (!fileId) return; + try { + const res = await fetch('/pdf/rotate', { + method: 'POST', + headers: {'Content-Type':'application/json'}, + body: JSON.stringify({ fileId, pages: String(pageNum), angle }) + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + if (hint) hint.textContent = 'Страница ' + pageNum + ' повёрнута'; + await syncAfterOperation(data); + } catch(e) { + if (hint) hint.textContent = 'Ошибка: ' + e.message; + } + }, 300); + } + })();