Fixed imports for Operators

This commit is contained in:
Saud Fatayerji 2023-11-17 13:15:20 +03:00
parent fa36d5d296
commit b4251b56fe
5 changed files with 8 additions and 6 deletions

View File

@ -109,7 +109,7 @@ export type SortFunction = (totalPages: number) => number[];
type Sorts = { type Sorts = {
[key: string]: SortFunction; [key: string]: SortFunction;
}; };
export const sorts: Sorts = Object.freeze({ export const Sorts: Sorts = Object.freeze({
"REVERSE_ORDER": reverseSort, "REVERSE_ORDER": reverseSort,
"DUPLEX_SORT": duplexSort, "DUPLEX_SORT": duplexSort,
"BOOKLET_SORT": bookletSort, "BOOKLET_SORT": bookletSort,

View File

@ -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). * @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. * @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 indexes = Array.isArray(pages) ? pages : [...Array(pages).keys()];
const pageIndexesCopy = [...indexes]; const pageIndexesCopy = [...indexes];
return pageIndexesCopy.filter(x => !selection.includes(x)); return pageIndexesCopy.filter(x => !selection.includes(x));
@ -16,7 +16,7 @@ function invertSelection(selection: number[], pages: number|number[]): number[]
* @param totalPages * @param totalPages
* @returns * @returns
*/ */
function parsePageIndexSpecification(specification: string, totalPages: number): number[] { export function parsePageIndexSpecification(specification: string, totalPages: number): number[] {
// Translated to JS from the original Java function // Translated to JS from the original Java function
const pageOrderArr = specification.split(",") const pageOrderArr = specification.split(",")
const newPageOrder: number[] = []; const newPageOrder: number[] = [];

View File

@ -1,6 +1,7 @@
import { PdfFile } from '../wrappers/PdfFile.js'; import { PdfFile } from '../wrappers/PdfFile.js';
import { getPages } from './common/getPagesByIndex.js'; import { getPages } from './common/getPagesByIndex.js';
import { parsePageIndexSpecification } from './common/pageIndexesUtils'
export type ExtractPagesParamsType = { export type ExtractPagesParamsType = {
file: PdfFile; file: PdfFile;

View File

@ -2,6 +2,7 @@
import { PdfFile } from '../wrappers/PdfFile.js'; import { PdfFile } from '../wrappers/PdfFile.js';
import { detectEmptyPages } from './common/detectEmptyPages.js'; import { detectEmptyPages } from './common/detectEmptyPages.js';
import { getPages } from './common/getPagesByIndex.js'; import { getPages } from './common/getPagesByIndex.js';
import { invertSelection } from './common/pageIndexesUtils.js';
export type RemoveBlankPagesParamsType = { export type RemoveBlankPagesParamsType = {
file: PdfFile; file: PdfFile;

View File

@ -1,6 +1,6 @@
import { PdfFile } from '../wrappers/PdfFile.js'; import { PdfFile } from '../wrappers/PdfFile.js';
import { sorts } from './common/pageIndexesSorting.js'; import { Sorts } from './common/pageIndexesSorting.js';
import { getPages } from './common/getPagesByIndex.js'; import { getPages } from './common/getPagesByIndex.js';
export type SortPagesWithPresetParamsType = { export type SortPagesWithPresetParamsType = {
@ -11,11 +11,11 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType)
const { file, sortPreset } = params; const { file, sortPreset } = params;
const pdfLibDocument = await file.pdfLibDocument; const pdfLibDocument = await file.pdfLibDocument;
if (!(sortPreset in sorts)) { if (!(sortPreset in Sorts)) {
throw new Error("Supplied parameters not supported"); throw new Error("Supplied parameters not supported");
} }
const sortFunction = sorts[sortPreset]; const sortFunction = Sorts[sortPreset];
const pageCount = pdfLibDocument.getPageCount(); const pageCount = pdfLibDocument.getPageCount();
const sortIndexes = sortFunction(pageCount); const sortIndexes = sortFunction(pageCount);