Reset branch to main

This commit is contained in:
Sebastian Espei
2026-03-09 17:02:30 +01:00
parent 68343a4c9a
commit e474d11730
606 changed files with 189976 additions and 43358 deletions

View File

@@ -1,5 +1,24 @@
const baseUrl = self.location.href.substring(0, self.location.href.lastIndexOf('/workers/') + 1);
self.importScripts(baseUrl + 'coherentpdf.browser.min.js');
let cpdfLoaded = false;
function loadCpdf(cpdfUrl) {
if (cpdfLoaded) return Promise.resolve();
return new Promise((resolve, reject) => {
if (typeof coherentpdf !== 'undefined') {
cpdfLoaded = true;
resolve();
return;
}
try {
self.importScripts(cpdfUrl);
cpdfLoaded = true;
resolve();
} catch (error) {
reject(new Error('Failed to load CoherentPDF: ' + error.message));
}
});
}
function convertJSONsToPDFInWorker(fileBuffers, fileNames) {
try {
@@ -15,13 +34,12 @@ function convertJSONsToPDFInWorker(fileBuffers, fileNames) {
try {
pdf = coherentpdf.fromJSONMemory(uint8Array);
} catch (error) {
const errorMsg = error && error.message
? error.message
: 'Unknown error';
const errorMsg =
error && error.message ? error.message : 'Unknown error';
throw new Error(
`Failed to convert "${fileName}" to PDF. ` +
`The JSON file must be in the format produced by cpdf's outputJSONMemory. ` +
`Error: ${errorMsg}`
`The JSON file must be in the format produced by cpdf's outputJSONMemory. ` +
`Error: ${errorMsg}`
);
}
@@ -56,9 +74,29 @@ function convertJSONsToPDFInWorker(fileBuffers, fileNames) {
}
}
self.onmessage = (e) => {
self.onmessage = async function (e) {
const { cpdfUrl } = e.data;
if (!cpdfUrl) {
self.postMessage({
status: 'error',
message:
'CoherentPDF URL not provided. Please configure it in WASM Settings.',
});
return;
}
try {
await loadCpdf(cpdfUrl);
} catch (error) {
self.postMessage({
status: 'error',
message: error.message,
});
return;
}
if (e.data.command === 'convert') {
convertJSONsToPDFInWorker(e.data.fileBuffers, e.data.fileNames);
}
};