Fix edit-pdf-page.ts and revert fileHandler.ts
This commit is contained in:
@@ -23,11 +23,6 @@ import * as pdfjsLib from 'pdfjs-dist';
|
|||||||
|
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
||||||
|
|
||||||
const embedPdfWasmUrl = new URL(
|
|
||||||
'embedpdf-snippet/dist/pdfium.wasm',
|
|
||||||
import.meta.url
|
|
||||||
).href;
|
|
||||||
|
|
||||||
// Re-export rotation state utilities
|
// Re-export rotation state utilities
|
||||||
export { getRotationState, updateRotationState, resetRotationState, initializeRotationState } from '../utils/rotation-state.js';
|
export { getRotationState, updateRotationState, resetRotationState, initializeRotationState } from '../utils/rotation-state.js';
|
||||||
|
|
||||||
@@ -826,40 +821,6 @@ export function setupFileInputHandler(toolId) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if (toolId === 'edit') {
|
|
||||||
const file = state.files[0];
|
|
||||||
if (!file) return;
|
|
||||||
|
|
||||||
const pdfWrapper = document.getElementById('embed-pdf-wrapper');
|
|
||||||
const pdfContainer = document.getElementById('embed-pdf-container');
|
|
||||||
|
|
||||||
if (!pdfContainer) return;
|
|
||||||
|
|
||||||
pdfContainer.textContent = ''; // Clear safely
|
|
||||||
|
|
||||||
if (state.currentPdfUrl) {
|
|
||||||
URL.revokeObjectURL(state.currentPdfUrl);
|
|
||||||
}
|
|
||||||
pdfWrapper.classList.remove('hidden');
|
|
||||||
const fileURL = URL.createObjectURL(file);
|
|
||||||
state.currentPdfUrl = fileURL;
|
|
||||||
|
|
||||||
const { default: EmbedPDF } = await import('embedpdf-snippet');
|
|
||||||
EmbedPDF.init({
|
|
||||||
type: 'container',
|
|
||||||
target: pdfContainer,
|
|
||||||
src: fileURL,
|
|
||||||
worker: true,
|
|
||||||
wasmUrl: embedPdfWasmUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
const backBtn = document.getElementById('back-to-grid');
|
|
||||||
const urlRevoker = () => {
|
|
||||||
URL.revokeObjectURL(fileURL);
|
|
||||||
state.currentPdfUrl = null;
|
|
||||||
backBtn.removeEventListener('click', urlRevoker);
|
|
||||||
};
|
|
||||||
backBtn.addEventListener('click', urlRevoker);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import { createIcons, icons } from 'lucide';
|
|||||||
import { showAlert, showLoader, hideLoader } from '../ui.js';
|
import { showAlert, showLoader, hideLoader } from '../ui.js';
|
||||||
import { formatBytes } from '../utils/helpers.js';
|
import { formatBytes } from '../utils/helpers.js';
|
||||||
|
|
||||||
|
const embedPdfWasmUrl = new URL(
|
||||||
|
'embedpdf-snippet/dist/pdfium.wasm',
|
||||||
|
import.meta.url
|
||||||
|
).href;
|
||||||
|
|
||||||
let currentPdfUrl: string | null = null;
|
let currentPdfUrl: string | null = null;
|
||||||
|
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
@@ -130,18 +135,14 @@ async function handleFiles(files: FileList) {
|
|||||||
const fileURL = URL.createObjectURL(file);
|
const fileURL = URL.createObjectURL(file);
|
||||||
currentPdfUrl = fileURL;
|
currentPdfUrl = fileURL;
|
||||||
|
|
||||||
// Dynamically load EmbedPDF script
|
const { default: EmbedPDF } = await import('embedpdf-snippet');
|
||||||
const script = document.createElement('script');
|
|
||||||
script.type = 'module';
|
|
||||||
script.textContent = `
|
|
||||||
import EmbedPDF from 'https://snippet.embedpdf.com/embedpdf.js';
|
|
||||||
EmbedPDF.init({
|
EmbedPDF.init({
|
||||||
type: 'container',
|
type: 'container',
|
||||||
target: document.getElementById('embed-pdf-container'),
|
target: pdfContainer,
|
||||||
src: '${fileURL}',
|
src: fileURL,
|
||||||
|
worker: true,
|
||||||
|
wasmUrl: embedPdfWasmUrl,
|
||||||
});
|
});
|
||||||
`;
|
|
||||||
document.head.appendChild(script);
|
|
||||||
|
|
||||||
// Update back button to reset state
|
// Update back button to reset state
|
||||||
const backBtn = document.getElementById('back-to-tools');
|
const backBtn = document.getElementById('back-to-tools');
|
||||||
|
|||||||
Reference in New Issue
Block a user