Cleared up client and shared modules

This commit is contained in:
Saud Fatayerji
2023-11-10 21:08:07 +03:00
parent 97e4eab7bb
commit 55f55afed2
11 changed files with 203 additions and 168 deletions

View File

@@ -1,53 +1,4 @@
declare module '@stirling-pdf/shared-operations/functions/editMetadata' {
export type Metadata = {
Title: string | null | undefined; // The title of the document.
Author: string | null | undefined; // The author of the document.
Subject: string | null | undefined; // The subject of the document.
Keywords: string[] | null | undefined; // An array of keywords associated with the document.
Producer: string | null | undefined; // The producer of the document.
Creator: string | null | undefined; // The creator of the document.
CreationDate: Date | null | undefined; // The date when the document was created.
ModificationDate: Date | null | undefined; // The date when the document was last modified.
}
export async function editMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/extractPages' {
export async function extractPages(snapshot: string | Uint8Array | ArrayBuffer, pagesToExtractArray: number[]): Promise<Uint8Array>;
export async function createSubDocument(pdfDoc: typeof import("pdf-lib").PDFDocument, pagesToExtractArray: number[])
}
declare module '@stirling-pdf/shared-operations/functions/mergePDFs' {
export async function mergePDFs(snapshots: (string | Uint8Array | ArrayBuffer)[]): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/organizePages' {
export async function organizePages(
snapshot: string | Uint8Array | ArrayBuffer,
operation: "CUSTOM_PAGE_ORDER" |
"REVERSE_ORDER" |
"DUPLEX_SORT" |
"BOOKLET_SORT" |
"ODD_EVEN_SPLIT" |
"REMOVE_FIRST" |
"REMOVE_LAST" |
"REMOVE_FIRST_AND_LAST",
customOrderString: string): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/rotatePages' {
export async function rotatePages(snapshot: string | Uint8Array | ArrayBuffer, rotation: number): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/scaleContent' {
export async function scaleContent(snapshot: string | Uint8Array | ArrayBuffer, scaleFactor: number): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/scalePage' {
export async function scalePage(snapshot: string | Uint8Array | ArrayBuffer, pageSize: {width:number,height:number}): Promise<Uint8Array>;
}
declare module '@stirling-pdf/shared-operations/functions/splitPDF' {
export async function splitPDF(snapshot: string | Uint8Array | ArrayBuffer, splitAfterPageArray: number[]): Promise<Uint8Array>;
declare module '@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js' {
export async function oneToOne(wasmArray: any, snapshot: any): Promise<Uint8Array>;
}

View File

@@ -1,53 +1,12 @@
// Import injected libraries here!
import SharedOperations from '@stirling-pdf/shared-operations'
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
import { Metadata, editMetadata as dependantEditMetadata} from "@stirling-pdf/shared-operations/functions/editMetadata";
import { extractPages as dependantExtractPages } from "@stirling-pdf/shared-operations/functions/extractPages";
import { mergePDFs as dependantMergePDFs } from '@stirling-pdf/shared-operations/functions/mergePDFs';
import { organizePages as dependantOrganizePages } from '@stirling-pdf/shared-operations/functions/organizePages';
import { rotatePages as dependantRotatePages } from '@stirling-pdf/shared-operations/functions/rotatePages';
import { scaleContent as dependantScaleContent} from '@stirling-pdf/shared-operations/functions/scaleContent';
import { scalePage as dependantScalePage } from '@stirling-pdf/shared-operations/functions/scalePage';
import { splitPDF as dependantSplitPDF } from '@stirling-pdf/shared-operations/functions/splitPDF';
export async function editMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata) {
return dependantEditMetadata(snapshot, metadata);
async function impose(snapshot: any, nup: number, format: string) {
return SharedOperations.impose(snapshot, nup, format, pdfcpuWrapper)
}
export async function extractPages(snapshot: string | Uint8Array | ArrayBuffer, pagesToExtractArray: number[]) {
return dependantExtractPages(snapshot, pagesToExtractArray);
}
export async function mergePDFs(snapshots: (string | Uint8Array | ArrayBuffer)[]) {
return dependantMergePDFs(snapshots);
}
export async function organizePages(
snapshot: string | Uint8Array | ArrayBuffer,
operation: "CUSTOM_PAGE_ORDER" |
"REVERSE_ORDER" |
"DUPLEX_SORT" |
"BOOKLET_SORT" |
"ODD_EVEN_SPLIT" |
"REMOVE_FIRST" |
"REMOVE_LAST" |
"REMOVE_FIRST_AND_LAST",
customOrderString: string) {
return dependantOrganizePages(snapshot, operation, customOrderString);
}
export async function rotatePages(snapshot: string | Uint8Array | ArrayBuffer, rotation: number) {
return dependantRotatePages(snapshot, rotation);
}
export async function scaleContent(snapshot: string | Uint8Array | ArrayBuffer, scaleFactor: number) {
return dependantScaleContent(snapshot, scaleFactor);
}
export async function scalePage(snapshot: string | Uint8Array | ArrayBuffer, pageSize: { width: number; height: number; }) {
return dependantScalePage(snapshot, pageSize);
}
export async function splitPDF(snapshot: string | Uint8Array | ArrayBuffer, splitAfterPageArray: number[]) {
return dependantSplitPDF(snapshot, splitAfterPageArray);
export default {
...SharedOperations,
impose,
}