mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Undid a few things that broke in the last commit
This commit is contained in:
parent
55f55afed2
commit
7b702734f3
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
import SharedOperations from '@stirling-pdf/shared-operations'
|
import SharedOperations from '@stirling-pdf/shared-operations'
|
||||||
|
|
||||||
|
// Import injected libraries here!
|
||||||
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
|
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
|
||||||
|
|
||||||
async function impose(snapshot: any, nup: number, format: string) {
|
async function impose(snapshot: any, nup: number, format: string) {
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
||||||
|
|
||||||
import { extractPages } from "../functions/extractPages.js";
|
|
||||||
import { impose } from '../functions/impose.js';
|
|
||||||
import { mergePDFs } from '../functions/mergePDFs.js';
|
|
||||||
import { rotatePages } from '../functions/rotatePages.js';
|
|
||||||
import { scaleContent} from '../functions/scaleContent.js';
|
|
||||||
import { scalePage } from '../functions/scalePage.js';
|
|
||||||
import { splitPDF } from '../functions/splitPDF.js';
|
|
||||||
import { Metadata as dependantEditMetadata } from '../functions/editMetadata.js';
|
|
||||||
import { organizePages } from '../functions/organizePages.js';
|
|
||||||
import { removeBlankPages} from '../functions/removeBlankPages.js';
|
|
||||||
import { splitOn } from "../functions/splitOn.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef PDF
|
* @typedef PDF
|
||||||
* @property {string} originalFileName
|
* @property {string} originalFileName
|
||||||
@ -25,7 +13,7 @@ import { splitOn } from "../functions/splitOn.js";
|
|||||||
* @param {PDF|PDF[]} input
|
* @param {PDF|PDF[]} input
|
||||||
* @returns {}
|
* @returns {}
|
||||||
*/
|
*/
|
||||||
export async function * traverseOperations(operations, input) {
|
export async function * traverseOperations(operations, input, Operations) {
|
||||||
const waitOperations = organizeWaitOperations(operations);
|
const waitOperations = organizeWaitOperations(operations);
|
||||||
/** @type {PDF[]} */ let results = [];
|
/** @type {PDF[]} */ let results = [];
|
||||||
yield* nextOperation(operations, input);
|
yield* nextOperation(operations, input);
|
||||||
@ -85,13 +73,13 @@ export async function * traverseOperations(operations, input) {
|
|||||||
case "extract":
|
case "extract":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_extractedPages";
|
input.fileName += "_extractedPages";
|
||||||
input.buffer = await extractPages(input.buffer, operation.values["pagesToExtractArray"]);
|
input.buffer = await Operations.extractPages(input.buffer, operation.values["pagesToExtractArray"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "impose":
|
case "impose":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_imposed";
|
input.fileName += "_imposed";
|
||||||
input.buffer = await impose(input.buffer, operation.values["nup"], operation.values["format"]);
|
input.buffer = await Operations.impose(input.buffer, operation.values["nup"], operation.values["format"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "merge":
|
case "merge":
|
||||||
@ -99,20 +87,20 @@ export async function * traverseOperations(operations, input) {
|
|||||||
return {
|
return {
|
||||||
originalFileName: inputs.map(input => input.originalFileName).join("_and_"),
|
originalFileName: inputs.map(input => input.originalFileName).join("_and_"),
|
||||||
fileName: inputs.map(input => input.fileName).join("_and_") + "_merged",
|
fileName: inputs.map(input => input.fileName).join("_and_") + "_merged",
|
||||||
buffer: await mergePDFs(inputs.map(input => input.buffer))
|
buffer: await Operations.mergePDFs(inputs.map(input => input.buffer))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "rotate":
|
case "rotate":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_turned";
|
input.fileName += "_turned";
|
||||||
input.buffer = await rotatePages(input.buffer, operation.values["rotation"]);
|
input.buffer = await Operations.rotatePages(input.buffer, operation.values["rotation"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "split":
|
case "split":
|
||||||
// TODO: A split might break the done condition, it may count multiple times. Needs further testing!
|
// TODO: A split might break the done condition, it may count multiple times. Needs further testing!
|
||||||
yield* oneToN(input, operation, async (input) => {
|
yield* oneToN(input, operation, async (input) => {
|
||||||
const splitResult = await splitPDF(input.buffer, operation.values["pagesToSplitAfterArray"]);
|
const splitResult = await Operations.splitPDF(input.buffer, operation.values["pagesToSplitAfterArray"]);
|
||||||
|
|
||||||
const splits = [];
|
const splits = [];
|
||||||
for (let j = 0; j < splitResult.length; j++) {
|
for (let j = 0; j < splitResult.length; j++) {
|
||||||
@ -128,24 +116,24 @@ export async function * traverseOperations(operations, input) {
|
|||||||
case "editMetadata":
|
case "editMetadata":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_metadataEdited";
|
input.fileName += "_metadataEdited";
|
||||||
input.buffer = await editMetadata(input.buffer, operation.values["metadata"]);
|
input.buffer = await Operations.editMetadata(input.buffer, operation.values["metadata"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "organizePages":
|
case "organizePages":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_pagesOrganized";
|
input.fileName += "_pagesOrganized";
|
||||||
input.buffer = await organizePages(input.buffer, operation.values["operation"], operation.values["customOrderString"]);
|
input.buffer = await Operations.organizePages(input.buffer, operation.values["operation"], operation.values["customOrderString"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "removeBlankPages":
|
case "removeBlankPages":
|
||||||
yield* nToN(input, operation, async (input) => {
|
yield* nToN(input, operation, async (input) => {
|
||||||
input.fileName += "_removedBlanks";
|
input.fileName += "_removedBlanks";
|
||||||
input.buffer = await removeBlankPages(input.buffer, operation.values["whiteThreashold"]);
|
input.buffer = await Operations.removeBlankPages(input.buffer, operation.values["whiteThreashold"]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "splitOn":
|
case "splitOn":
|
||||||
yield* oneToN(input, operation, async (input) => {
|
yield* oneToN(input, operation, async (input) => {
|
||||||
const splitResult = await splitOn(input.buffer, operation.values["type"], operation.values["whiteThreashold"]);
|
const splitResult = await Operations.splitOn(input.buffer, operation.values["type"], operation.values["whiteThreashold"]);
|
||||||
const splits = [];
|
const splits = [];
|
||||||
for (let j = 0; j < splitResult.length; j++) {
|
for (let j = 0; j < splitResult.length; j++) {
|
||||||
splits.push({
|
splits.push({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user