2023-10-16 23:11:33 +02:00
|
|
|
import { scaleContent } from "./functions/scaleContent.js";
|
|
|
|
import { scalePage, PageSize } from "./functions/scalePage.js";
|
2023-10-17 02:14:06 +02:00
|
|
|
import * as exampleWorkflows from "./exampleWorkflows.js";
|
2023-10-17 01:38:51 +02:00
|
|
|
import { traverseOperations } from "./traverseOperations.js";
|
2023-10-22 01:11:17 +02:00
|
|
|
import * as Functions from "./functions.js";
|
2023-10-16 23:11:33 +02:00
|
|
|
|
2023-11-07 02:20:44 +01:00
|
|
|
(async () => {
|
|
|
|
const workflowField = document.getElementById("workflow");
|
|
|
|
|
|
|
|
const dropdown = document.getElementById("pdfOptions");
|
|
|
|
// Clear existing options (if any)
|
|
|
|
dropdown.innerHTML = '';
|
|
|
|
|
|
|
|
console.log(exampleWorkflows);
|
|
|
|
// Iterate over the keys of the object and create an option for each key
|
|
|
|
for (const key in exampleWorkflows) {
|
|
|
|
const option = document.createElement('option');
|
|
|
|
option.value = key;
|
|
|
|
option.text = key;
|
|
|
|
dropdown.appendChild(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadButton = document.getElementById("loadButton");
|
|
|
|
loadButton.addEventListener("click", (e) => {
|
|
|
|
workflowField.value = JSON.stringify(exampleWorkflows[dropdown.value], null, 2);
|
|
|
|
});
|
|
|
|
loadButton.click();
|
|
|
|
|
2023-10-16 23:11:33 +02:00
|
|
|
const pdfFileInput = document.getElementById('pdfFile');
|
2023-10-17 01:31:00 +02:00
|
|
|
const doneButton = document.getElementById("doneButton");
|
2023-10-16 23:11:33 +02:00
|
|
|
|
2023-10-17 01:31:00 +02:00
|
|
|
doneButton.addEventListener('click', async (e) => {
|
2023-10-22 01:11:17 +02:00
|
|
|
console.log("Starting...");
|
|
|
|
|
2023-10-17 01:31:00 +02:00
|
|
|
const files = Array.from(pdfFileInput.files);
|
2023-10-17 02:14:06 +02:00
|
|
|
const inputs = await Promise.all(files.map(async file => {
|
2023-10-17 01:31:00 +02:00
|
|
|
return {
|
|
|
|
originalFileName: file.name.replace(/\.[^/.]+$/, ""),
|
|
|
|
fileName: file.name.replace(/\.[^/.]+$/, ""),
|
|
|
|
buffer: new Uint8Array(await file.arrayBuffer())
|
|
|
|
}
|
|
|
|
}));
|
2023-10-17 02:14:06 +02:00
|
|
|
console.log(inputs);
|
2023-10-17 01:31:00 +02:00
|
|
|
|
2023-11-07 02:20:44 +01:00
|
|
|
const workflow = JSON.parse(workflowField.value);
|
|
|
|
console.log(workflow);
|
2023-10-22 01:11:17 +02:00
|
|
|
const traverse = traverseOperations(workflow.operations, inputs, Functions);
|
|
|
|
|
|
|
|
let pdfResults;
|
|
|
|
let iteration;
|
|
|
|
while (true) {
|
|
|
|
iteration = await traverse.next();
|
|
|
|
if (iteration.done) {
|
|
|
|
pdfResults = iteration.value;
|
|
|
|
console.log(`data: processing done\n\n`);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.log(`data: ${iteration.value}\n\n`);
|
|
|
|
}
|
2023-10-17 02:14:06 +02:00
|
|
|
|
2023-11-07 02:20:44 +01:00
|
|
|
// TODO: Zip if wanted
|
2023-10-22 01:11:17 +02:00
|
|
|
pdfResults.forEach(result => {
|
2023-10-17 02:14:06 +02:00
|
|
|
download(result.buffer, result.fileName, "application/pdf");
|
|
|
|
});
|
2023-10-16 23:11:33 +02:00
|
|
|
});
|
2023-11-07 02:20:44 +01:00
|
|
|
})();
|