feat: separate AGPL libraries and add dynamic WASM loading

- Add WASM settings page for configuring external AGPL modules
- Implement dynamic loading for PyMuPDF, Ghostscript, and CoherentPDF
- Add Cloudflare Worker proxy for serving WASM files with CORS
- Update all affected tool pages to check WASM availability
- Add showWasmRequiredDialog for missing module configuration

Documentation:
- Update README, licensing.html, and docs to clarify AGPL components
  are not bundled and must be configured separately
- Add WASM-PROXY.md deployment guide with recommended source URLs
- Rename "CPDF" to "CoherentPDF" for consistency
This commit is contained in:
alam00000 committed 2026-01-27 15:26:26 +05:30
1 parent f6d432eaa7
commit 2c85ca74e9
75 files changed
+9696 -6587

No files matched your search

+27 -10
View File
@@ -1,15 +1,35 @@
import { WasmProvider } from './wasm-provider';
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> {
function getCpdfUrl(): string | undefined {
const userUrl = WasmProvider.getUrl('cpdf');
if (userUrl) {
const baseUrl = userUrl.endsWith('/') ? userUrl : `${userUrl}/`;
return `${baseUrl}coherentpdf.browser.min.js`;
}
return undefined;
}
export function isCpdfAvailable(): boolean {
return WasmProvider.isConfigured('cpdf');
}
export async function isCpdfLoaded(): Promise<void> {
if (cpdfLoaded) return;
if (cpdfLoadPromise) {
return cpdfLoadPromise;
}
const cpdfUrl = getCpdfUrl();
if (!cpdfUrl) {
throw new Error(
'CoherentPDF is not configured. Please configure it in WASM Settings.'
);
}
cpdfLoadPromise = new Promise((resolve, reject) => {
if (typeof (window as any).coherentpdf !== 'undefined') {
cpdfLoaded = true;
@@ -18,13 +38,14 @@ export async function ensureCpdfLoaded(): Promise<void> {
}
const script = document.createElement('script');
script.src = import.meta.env.BASE_URL + 'coherentpdf.browser.min.js';
script.src = cpdfUrl;
script.onload = () => {
cpdfLoaded = true;
console.log('[CPDF] Loaded from:', script.src);
resolve();
};
script.onerror = () => {
reject(new Error('Failed to load CoherentPDF library'));
reject(new Error('Failed to load CoherentPDF library from: ' + cpdfUrl));
};
document.head.appendChild(script);
});
@@ -32,11 +53,7 @@ export async function ensureCpdfLoaded(): Promise<void> {
return cpdfLoadPromise;
}
/**
* Gets the cpdf instance, ensuring it's loaded first
*/
export async function getCpdf(): Promise<any> {
await ensureCpdfLoaded();
await isCpdfLoaded();
return (window as any).coherentpdf;
}