From b4251b56fea1199a42f2c35121c322f9599181ee Mon Sep 17 00:00:00 2001 From: Saud Fatayerji Date: Fri, 17 Nov 2023 13:15:20 +0300 Subject: [PATCH] Fixed imports for Operators --- .../src/functions/common/pageIndexesSorting.ts | 2 +- shared-operations/src/functions/common/pageIndexesUtils.ts | 4 ++-- shared-operations/src/functions/extractPages.ts | 1 + shared-operations/src/functions/removeBlankPages.ts | 1 + shared-operations/src/functions/sortPagesWithPreset.ts | 6 +++--- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shared-operations/src/functions/common/pageIndexesSorting.ts b/shared-operations/src/functions/common/pageIndexesSorting.ts index 2ef73a93..9340220c 100644 --- a/shared-operations/src/functions/common/pageIndexesSorting.ts +++ b/shared-operations/src/functions/common/pageIndexesSorting.ts @@ -109,7 +109,7 @@ export type SortFunction = (totalPages: number) => number[]; type Sorts = { [key: string]: SortFunction; }; -export const sorts: Sorts = Object.freeze({ +export const Sorts: Sorts = Object.freeze({ "REVERSE_ORDER": reverseSort, "DUPLEX_SORT": duplexSort, "BOOKLET_SORT": bookletSort, diff --git a/shared-operations/src/functions/common/pageIndexesUtils.ts b/shared-operations/src/functions/common/pageIndexesUtils.ts index 6a60f850..32d3da20 100644 --- a/shared-operations/src/functions/common/pageIndexesUtils.ts +++ b/shared-operations/src/functions/common/pageIndexesUtils.ts @@ -4,7 +4,7 @@ * @param pages A list of page indexes, or the number of total pages in the document (which will be converted into a list of page indexes). * @returns An inverted selection array of page indexes. */ -function invertSelection(selection: number[], pages: number|number[]): number[] { +export function invertSelection(selection: number[], pages: number|number[]): number[] { const indexes = Array.isArray(pages) ? pages : [...Array(pages).keys()]; const pageIndexesCopy = [...indexes]; return pageIndexesCopy.filter(x => !selection.includes(x)); @@ -16,7 +16,7 @@ function invertSelection(selection: number[], pages: number|number[]): number[] * @param totalPages * @returns */ -function parsePageIndexSpecification(specification: string, totalPages: number): number[] { +export function parsePageIndexSpecification(specification: string, totalPages: number): number[] { // Translated to JS from the original Java function const pageOrderArr = specification.split(",") const newPageOrder: number[] = []; diff --git a/shared-operations/src/functions/extractPages.ts b/shared-operations/src/functions/extractPages.ts index 1b6b9bbc..c1206f96 100644 --- a/shared-operations/src/functions/extractPages.ts +++ b/shared-operations/src/functions/extractPages.ts @@ -1,6 +1,7 @@ import { PdfFile } from '../wrappers/PdfFile.js'; import { getPages } from './common/getPagesByIndex.js'; +import { parsePageIndexSpecification } from './common/pageIndexesUtils' export type ExtractPagesParamsType = { file: PdfFile; diff --git a/shared-operations/src/functions/removeBlankPages.ts b/shared-operations/src/functions/removeBlankPages.ts index 42525c25..2a5225b9 100644 --- a/shared-operations/src/functions/removeBlankPages.ts +++ b/shared-operations/src/functions/removeBlankPages.ts @@ -2,6 +2,7 @@ import { PdfFile } from '../wrappers/PdfFile.js'; import { detectEmptyPages } from './common/detectEmptyPages.js'; import { getPages } from './common/getPagesByIndex.js'; +import { invertSelection } from './common/pageIndexesUtils.js'; export type RemoveBlankPagesParamsType = { file: PdfFile; diff --git a/shared-operations/src/functions/sortPagesWithPreset.ts b/shared-operations/src/functions/sortPagesWithPreset.ts index accf25ff..fe3eb4c4 100644 --- a/shared-operations/src/functions/sortPagesWithPreset.ts +++ b/shared-operations/src/functions/sortPagesWithPreset.ts @@ -1,6 +1,6 @@ import { PdfFile } from '../wrappers/PdfFile.js'; -import { sorts } from './common/pageIndexesSorting.js'; +import { Sorts } from './common/pageIndexesSorting.js'; import { getPages } from './common/getPagesByIndex.js'; export type SortPagesWithPresetParamsType = { @@ -11,11 +11,11 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType) const { file, sortPreset } = params; const pdfLibDocument = await file.pdfLibDocument; - if (!(sortPreset in sorts)) { + if (!(sortPreset in Sorts)) { throw new Error("Supplied parameters not supported"); } - const sortFunction = sorts[sortPreset]; + const sortFunction = Sorts[sortPreset]; const pageCount = pdfLibDocument.getPageCount(); const sortIndexes = sortFunction(pageCount);