feat: enhance PDF tools with new features and UI improvements
- Added 'Extract Attachments' and 'Edit Attachments' functionalities to manage embedded files in PDFs. - Introduced new splitting options: by bookmarks and by a specified number of pages (N times). - Updated the user interface to include new options and improved layout for better usability. - Enhanced the GitHub link display with dynamic star count retrieval. - Bumped version to 1.4.0 and updated footer to reflect the new version. - Refactored existing code for better maintainability and added new TypeScript definitions for the new features.
This commit is contained in:
42
src/js/utils/cpdf-helper.ts
Normal file
42
src/js/utils/cpdf-helper.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
let cpdfLoaded = false;
|
||||
let cpdfLoadPromise: Promise<void> | null = null;
|
||||
|
||||
//TODO: @ALAM,is it better to use a worker to load the cpdf library?
|
||||
// or just use the browser version?
|
||||
export async function ensureCpdfLoaded(): Promise<void> {
|
||||
if (cpdfLoaded) return;
|
||||
|
||||
if (cpdfLoadPromise) {
|
||||
return cpdfLoadPromise;
|
||||
}
|
||||
|
||||
cpdfLoadPromise = new Promise((resolve, reject) => {
|
||||
if (typeof (window as any).coherentpdf !== 'undefined') {
|
||||
cpdfLoaded = true;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.src = '/coherentpdf.browser.min.js';
|
||||
script.onload = () => {
|
||||
cpdfLoaded = true;
|
||||
resolve();
|
||||
};
|
||||
script.onerror = () => {
|
||||
reject(new Error('Failed to load CoherentPDF library'));
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
|
||||
return cpdfLoadPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cpdf instance, ensuring it's loaded first
|
||||
*/
|
||||
export async function getCpdf(): Promise<any> {
|
||||
await ensureCpdfLoaded();
|
||||
return (window as any).coherentpdf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user