Update version to 1.6.2 and enhance navigation links across HTML pages

- Updated version number in package-lock.json and relevant HTML files.
- Changed navigation links to point to the root path for consistency.
- Improved code formatting and structure in various JavaScript and HTML files for better readability.
This commit is contained in:
abdullahalam123
2025-11-13 11:26:40 +05:30
parent 18ecaf4228
commit cb53370a26
13 changed files with 784 additions and 1012 deletions

View File

@@ -50,14 +50,14 @@ function showInputModal(title, fields = [], defaultValues = {}) {
<label class="block text-sm font-medium text-gray-700 mb-2">${field.label}</label>
<select id="modal-${field.name}" class="w-full px-3 py-2 border border-gray-300 rounded-lg">
${field.options
.map(
(opt) => `
.map(
(opt) => `
<option value="${opt.value}" ${defaultValues[field.name] === opt.value ? 'selected' : ''}>
${opt.label}
</option>
`
)
.join('')}
)
.join('')}
</select>
${field.name === 'color' ? '<input type="color" id="modal-color-picker" class="hidden w-full h-10 mt-2 rounded cursor-pointer border border-gray-300" value="#000000" />' : ''}
</div>
@@ -654,6 +654,9 @@ const fileDisplayArea = document.getElementById(
const backToToolsBtn = document.getElementById(
'back-to-tools'
) as HTMLButtonElement;
const closeBtn = document.getElementById(
'back-btn'
) as HTMLButtonElement;
const canvas = document.getElementById('pdf-canvas');
const ctx = canvas.getContext('2d');
const pageIndicator = document.getElementById('page-indicator');
@@ -2078,7 +2081,13 @@ async function extractExistingBookmarks(doc) {
// Back to tools button
if (backToToolsBtn) {
backToToolsBtn.addEventListener('click', () => {
window.location.href = '../../index.html#tools-header';
window.location.href = '/';
});
}
if (closeBtn) {
closeBtn.addEventListener('click', () => {
window.location.href = '/';
});
}

View File

@@ -16,13 +16,12 @@ function showStatus(
type: 'success' | 'error' | 'info' = 'info'
) {
statusMessage.textContent = message
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${
type === 'success'
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${type === 'success'
? 'bg-green-900 text-green-200'
: type === 'error'
? 'bg-red-900 text-red-200'
: 'bg-blue-900 text-blue-200'
}`
}`
statusMessage.classList.remove('hidden')
}
@@ -36,7 +35,7 @@ function updateFileList() {
fileListDiv.classList.add('hidden')
return
}
fileListDiv.classList.remove('hidden')
selectedFiles.forEach((file) => {
const fileDiv = document.createElement('div')
@@ -61,7 +60,7 @@ jsonFilesInput.addEventListener('change', (e) => {
selectedFiles = Array.from(target.files)
convertBtn.disabled = selectedFiles.length === 0
updateFileList()
if (selectedFiles.length === 0) {
showStatus('Please select at least 1 JSON file', 'info')
} else {
@@ -87,10 +86,10 @@ async function convertJSONsToPDF() {
showStatus('Converting JSONs to PDFs...', 'info')
worker.postMessage({
command: 'convert',
fileBuffers: fileBuffers,
fileNames: selectedFiles.map(f => f.name)
}, fileBuffers);
command: 'convert',
fileBuffers: fileBuffers,
fileNames: selectedFiles.map(f => f.name)
}, fileBuffers);
} catch (error) {
console.error('Error reading files:', error)
@@ -100,55 +99,55 @@ async function convertJSONsToPDF() {
}
worker.onmessage = async (e: MessageEvent) => {
convertBtn.disabled = false;
if (e.data.status === 'success') {
const pdfFiles = e.data.pdfFiles as Array<{ name: string, data: ArrayBuffer }>;
try {
showStatus('Creating ZIP file...', 'info')
const zip = new JSZip()
pdfFiles.forEach(({ name, data }) => {
const pdfName = name.replace(/\.json$/i, '.pdf')
const uint8Array = new Uint8Array(data)
zip.file(pdfName, uint8Array)
})
const zipBlob = await zip.generateAsync({ type: 'blob' })
const url = URL.createObjectURL(zipBlob)
const a = document.createElement('a')
a.href = url
a.download = 'jsons-to-pdf.zip'
downloadFile(zipBlob, 'jsons-to-pdf.zip')
convertBtn.disabled = false;
showStatus('✅ JSONs converted to PDF successfully! ZIP download started.', 'success')
selectedFiles = []
jsonFilesInput.value = ''
fileListDiv.innerHTML = ''
fileListDiv.classList.add('hidden')
convertBtn.disabled = true
setTimeout(() => {
hideStatus()
}, 3000)
if (e.data.status === 'success') {
const pdfFiles = e.data.pdfFiles as Array<{ name: string, data: ArrayBuffer }>;
} catch (error) {
console.error('Error creating ZIP:', error)
showStatus(`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error')
}
try {
showStatus('Creating ZIP file...', 'info')
} else if (e.data.status === 'error') {
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
console.error('Worker Error:', errorMessage);
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
const zip = new JSZip()
pdfFiles.forEach(({ name, data }) => {
const pdfName = name.replace(/\.json$/i, '.pdf')
const uint8Array = new Uint8Array(data)
zip.file(pdfName, uint8Array)
})
const zipBlob = await zip.generateAsync({ type: 'blob' })
const url = URL.createObjectURL(zipBlob)
const a = document.createElement('a')
a.href = url
a.download = 'jsons-to-pdf.zip'
downloadFile(zipBlob, 'jsons-to-pdf.zip')
showStatus('✅ JSONs converted to PDF successfully! ZIP download started.', 'success')
selectedFiles = []
jsonFilesInput.value = ''
fileListDiv.innerHTML = ''
fileListDiv.classList.add('hidden')
convertBtn.disabled = true
setTimeout(() => {
hideStatus()
}, 3000)
} catch (error) {
console.error('Error creating ZIP:', error)
showStatus(`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error')
}
} else if (e.data.status === 'error') {
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
console.error('Worker Error:', errorMessage);
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
}
};
if (backToToolsBtn) {
backToToolsBtn.addEventListener('click', () => {
window.location.href = '../../index.html#tools-header'
window.location.href = '/'
})
}

View File

@@ -29,6 +29,7 @@ let currentPdfDocs: PDFLibDocument[] = [];
let splitMarkers: Set<number> = new Set();
let isRendering = false;
let renderCancelled = false;
let sortableInstance: Sortable | null = null;
const pageCanvasCache = new Map<string, HTMLCanvasElement>();
@@ -114,7 +115,7 @@ function initializeTool() {
createIcons({ icons });
document.getElementById('close-tool-btn')?.addEventListener('click', () => {
window.location.href = '../../index.html';
window.location.href = '/';
});
document.getElementById('upload-pdfs-btn')?.addEventListener('click', () => {
@@ -247,6 +248,13 @@ function resetAll() {
pageCanvasCache.clear();
renderCancelled = false;
isRendering = false;
// Destroy sortable instance
if (sortableInstance) {
sortableInstance.destroy();
sortableInstance = null;
}
updatePageDisplay();
document.getElementById('upload-area')?.classList.remove('hidden');
}
@@ -492,9 +500,18 @@ function setupSortable() {
const pagesContainer = document.getElementById('pages-container');
if (!pagesContainer) return;
Sortable.create(pagesContainer, {
// Destroy existing instance before creating new one
if (sortableInstance) {
sortableInstance.destroy();
}
sortableInstance = Sortable.create(pagesContainer, {
animation: 150,
handle: '.cursor-move',
forceFallback: true,
touchStartThreshold: 3,
fallbackTolerance: 3,
delay: 200,
delayOnTouchOnly: true,
onEnd: (evt) => {
const oldIndex = evt.oldIndex!;
const newIndex = evt.newIndex!;

View File

@@ -16,13 +16,12 @@ function showStatus(
type: 'success' | 'error' | 'info' = 'info'
) {
statusMessage.textContent = message
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${
type === 'success'
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${type === 'success'
? 'bg-green-900 text-green-200'
: type === 'error'
? 'bg-red-900 text-red-200'
: 'bg-blue-900 text-blue-200'
}`
}`
statusMessage.classList.remove('hidden')
}
@@ -36,7 +35,7 @@ function updateFileList() {
fileListDiv.classList.add('hidden')
return
}
fileListDiv.classList.remove('hidden')
selectedFiles.forEach((file) => {
const fileDiv = document.createElement('div')
@@ -61,7 +60,7 @@ pdfFilesInput.addEventListener('change', (e) => {
selectedFiles = Array.from(target.files)
convertBtn.disabled = selectedFiles.length === 0
updateFileList()
if (selectedFiles.length === 0) {
showStatus('Please select at least 1 PDF file', 'info')
} else {
@@ -87,10 +86,10 @@ async function convertPDFsToJSON() {
showStatus('Converting PDFs to JSON..', 'info')
worker.postMessage({
command: 'convert',
fileBuffers: fileBuffers,
fileNames: selectedFiles.map(f => f.name)
}, fileBuffers);
command: 'convert',
fileBuffers: fileBuffers,
fileNames: selectedFiles.map(f => f.name)
}, fileBuffers);
} catch (error) {
console.error('Error reading files:', error)
@@ -100,51 +99,51 @@ async function convertPDFsToJSON() {
}
worker.onmessage = async (e: MessageEvent) => {
convertBtn.disabled = false;
if (e.data.status === 'success') {
const jsonFiles = e.data.jsonFiles as Array<{ name: string, data: ArrayBuffer }>;
try {
showStatus('Creating ZIP file...', 'info')
const zip = new JSZip()
jsonFiles.forEach(({ name, data }) => {
const jsonName = name.replace(/\.pdf$/i, '.json')
const uint8Array = new Uint8Array(data)
zip.file(jsonName, uint8Array)
})
const zipBlob = await zip.generateAsync({ type: 'blob' })
downloadFile(zipBlob, 'pdfs-to-json.zip')
convertBtn.disabled = false;
showStatus('✅ PDFs converted to JSON successfully! ZIP download started.', 'success')
selectedFiles = []
pdfFilesInput.value = ''
fileListDiv.innerHTML = ''
fileListDiv.classList.add('hidden')
convertBtn.disabled = true
setTimeout(() => {
hideStatus()
}, 3000)
if (e.data.status === 'success') {
const jsonFiles = e.data.jsonFiles as Array<{ name: string, data: ArrayBuffer }>;
} catch (error) {
console.error('Error creating ZIP:', error)
showStatus(`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error')
}
try {
showStatus('Creating ZIP file...', 'info')
} else if (e.data.status === 'error') {
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
console.error('Worker Error:', errorMessage);
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
const zip = new JSZip()
jsonFiles.forEach(({ name, data }) => {
const jsonName = name.replace(/\.pdf$/i, '.json')
const uint8Array = new Uint8Array(data)
zip.file(jsonName, uint8Array)
})
const zipBlob = await zip.generateAsync({ type: 'blob' })
downloadFile(zipBlob, 'pdfs-to-json.zip')
showStatus('✅ PDFs converted to JSON successfully! ZIP download started.', 'success')
selectedFiles = []
pdfFilesInput.value = ''
fileListDiv.innerHTML = ''
fileListDiv.classList.add('hidden')
convertBtn.disabled = true
setTimeout(() => {
hideStatus()
}, 3000)
} catch (error) {
console.error('Error creating ZIP:', error)
showStatus(`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error')
}
} else if (e.data.status === 'error') {
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
console.error('Worker Error:', errorMessage);
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
}
};
if (backToToolsBtn) {
backToToolsBtn.addEventListener('click', () => {
window.location.href = '../../index.html#tools-header'
window.location.href = '/'
})
}

View File

@@ -53,13 +53,12 @@ function showStatus(
type: 'success' | 'error' | 'info' = 'info'
) {
statusMessage.textContent = message;
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${
type === 'success'
statusMessage.className = `mt-4 p-3 rounded-lg text-sm ${type === 'success'
? 'bg-green-900 text-green-200'
: type === 'error'
? 'bg-red-900 text-red-200'
: 'bg-blue-900 text-blue-200'
}`;
}`;
statusMessage.classList.remove('hidden');
}
@@ -198,7 +197,7 @@ worker.onerror = (error) => {
if (backToToolsBtn) {
backToToolsBtn.addEventListener('click', () => {
window.location.href = '../../index.html#tools-header';
window.location.href = '/';
});
}