refactor: move all TypeScript interfaces to centralized src/js/types folder

- Create type files with barrel export via @/types alias
- Update logic files to use centralized type imports
This commit is contained in:
abdullahalam123
2026-01-05 14:57:30 +05:30
parent 8a96426254
commit d52d2e3647
83 changed files with 475 additions and 312 deletions

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface AddBlankPageState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface AddWatermarkState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,5 @@
export interface AlternateMergeState {
files: File[];
pdfBytes: Map<string, ArrayBuffer>;
pdfDocs: Map<string, any>;
}

View File

@@ -0,0 +1,7 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface AddAttachmentState {
file: File | null;
pdfDoc: PDFLibDocument | null;
attachments: File[];
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface BackgroundColorState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,3 @@
export interface ChangePermissionsState {
file: File | null;
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface CombineSinglePageState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,9 @@
import * as pdfjsLib from 'pdfjs-dist';
export interface CompareState {
pdfDoc1: pdfjsLib.PDFDocumentProxy | null;
pdfDoc2: pdfjsLib.PDFDocumentProxy | null;
currentPage: number;
viewMode: 'overlay' | 'side-by-side';
isSyncScroll: boolean;
}

View File

@@ -0,0 +1,8 @@
export interface CropperState {
pdfDoc: any;
currentPageNum: number;
cropper: any;
originalPdfBytes: ArrayBuffer | null;
pageCrops: Record<number, any>;
file: File | null;
}

View File

@@ -0,0 +1,3 @@
export interface DecryptPdfState {
file: File | null;
}

View File

@@ -0,0 +1,7 @@
export interface DeletePagesState {
file: File | null;
pdfDoc: any;
pdfJsDoc: any;
totalPages: number;
pagesToDelete: Set<number>;
}

View File

@@ -0,0 +1,42 @@
import { forge } from "zgapdfsigner";
export interface SignatureInfo {
reason?: string;
location?: string;
contactInfo?: string;
name?: string;
}
export interface CertificateData {
p12Buffer: ArrayBuffer;
password: string;
certificate: forge.pki.Certificate;
}
export interface SignPdfOptions {
signatureInfo?: SignatureInfo;
visibleSignature?: VisibleSignatureOptions;
}
export interface VisibleSignatureOptions {
enabled: boolean;
imageData?: ArrayBuffer;
imageType?: 'png' | 'jpeg' | 'webp';
x: number;
y: number;
width: number;
height: number;
page: number | string;
text?: string;
textColor?: string;
textSize?: number;
}
export interface DigitalSignState {
pdfFile: File | null;
pdfBytes: Uint8Array | null;
certFile: File | null;
certData: CertificateData | null;
sigImageData: ArrayBuffer | null;
sigImageType: 'png' | 'jpeg' | 'webp' | null;
}

View File

@@ -0,0 +1,7 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface DividePagesState {
file: File | null;
pdfDoc: PDFLibDocument | null;
totalPages: number;
}

View File

@@ -0,0 +1,12 @@
export interface AttachmentInfo {
index: number;
name: string;
page: number;
data: Uint8Array;
}
export interface EditAttachmentState {
file: File | null;
allAttachments: AttachmentInfo[];
attachmentsToRemove: Set<number>;
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface EditMetadataState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,3 @@
export interface EncryptPdfState {
file: File | null;
}

View File

@@ -0,0 +1,3 @@
export interface ExtractAttachmentsState {
files: File[];
}

View File

@@ -0,0 +1,7 @@
export interface ExtractedImage {
data: Blob;
width: number;
height: number;
pageNumber: number;
imageIndex: number;
}

View File

@@ -0,0 +1,5 @@
export interface ExtractPagesState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
}

View File

@@ -0,0 +1,3 @@
export interface FixPageSizeState {
file: File | null;
}

View File

@@ -0,0 +1,3 @@
export interface FlattenPdfState {
files: File[];
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface HeaderFooterState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -1,2 +1,48 @@
export * from './ocr.js';
export * from './form-creator.js';
export * from './ocr-type.js';
export * from './form-creator-type.js';
export * from './digital-sign-type.js';
export * from './attachment-type.js';
export * from './edit-attachments-type.js';
export * from './edit-metadata-type.js';
export * from './divide-pages-type.js';
export * from './alternate-merge-page-type.js';
export * from './add-blank-page-type.js';
export * from './compare-pdfs-type.js';
export * from './fix-page-size-type.js';
export * from './view-metadata-type.js';
export * from './header-footer-type.js';
export * from './encrypt-pdf-type.js';
export * from './flatten-pdf-type.js';
export * from './crop-pdf-type.js';
export * from './background-color-type.js';
export * from './posterize-type.js';
export * from './decrypt-pdf-type.js';
export * from './combine-single-page-type.js';
export * from './change-permissions-type.js';
export * from './validate-signature-type.js';
export * from './remove-restrictions-type.js';
export * from './page-dimensions-type.js';
export * from './extract-attachments-type.js';
export * from './pdf-multi-tool-type.js';
export * from './ocr-pdf-type.js';
export * from './delete-pages-type.js';
export * from './invert-colors-type.js';
export * from './table-of-contents-type.js';
export * from './organize-pdf-type.js';
export * from './merge-pdf-type.js';
export * from './extract-images-type.js';
export * from './extract-pages-type.js';
export * from './pdf-layers-type.js';
export * from './sanitize-pdf-type.js';
export * from './reverse-pages-type.js';
export * from './text-color-type.js';
export * from './n-up-pdf-type.js';
export * from './linearize-pdf-type.js';
export * from './remove-metadata-type.js';
export * from './rotate-pdf-type.js';
export * from './pdf-booklet-type.js';
export * from './page-numbers-type.js';
export * from './pdf-to-zip-type.js';
export * from './sign-pdf-type.js';
export * from './add-watermark-type.js';

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface InvertColorsState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,3 @@
export interface LinearizePdfState {
files: File[];
}

View File

@@ -0,0 +1,5 @@
export interface MergeState {
files: File[];
pdfBytes: Map<string, ArrayBuffer>;
pdfDocs: Map<string, any>;
}

View File

@@ -0,0 +1,5 @@
export interface NUpState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
}

View File

@@ -0,0 +1,10 @@
export interface OcrWord {
text: string;
bbox: { x0: number; y0: number; x1: number; y1: number };
confidence: number;
}
export interface OcrState {
file: File | null;
searchablePdfBytes: Uint8Array | null;
}

View File

@@ -0,0 +1,6 @@
export interface OrganizeState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
pageOrder: number[];
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument } from 'pdf-lib';
export interface PageDimensionsState {
file: File | null;
pdfDoc: PDFDocument | null;
}

View File

@@ -0,0 +1,3 @@
export interface PageNumbersState {
file: File | null;
}

View File

@@ -0,0 +1,5 @@
export interface BookletState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
}

View File

@@ -0,0 +1,5 @@
export interface LayerData {
name: string;
visible: boolean;
locked: boolean;
}

View File

@@ -0,0 +1,10 @@
export interface MultiToolPageData {
id: string;
originalPdfId: string;
pageIndex: number;
thumbnail: string;
width: number;
height: number;
rotation: number;
isBlank?: boolean;
}

View File

@@ -0,0 +1,3 @@
export interface PdfToZipState {
files: File[];
}

View File

@@ -0,0 +1,9 @@
import * as pdfjsLib from 'pdfjs-dist';
export interface PosterizeState {
file: File | null;
pdfJsDoc: pdfjsLib.PDFDocumentProxy | null;
pdfBytes: Uint8Array | null;
pageSnapshots: Record<number, ImageData>;
currentPage: number;
}

View File

@@ -0,0 +1,3 @@
export interface RemoveMetadataState {
file: File | null;
}

View File

@@ -0,0 +1,3 @@
export interface RemoveRestrictionsState {
file: File | null;
}

View File

@@ -0,0 +1,5 @@
export interface ReverseState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
}

View File

@@ -0,0 +1,6 @@
export interface RotateState {
file: File | null;
pdfBytes: ArrayBuffer | null;
totalPages: number;
pageRotations: Map<number, number>;
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument } from 'pdf-lib';
export interface SanitizePdfState {
file: File | null;
pdfDoc: PDFDocument | null;
}

View File

@@ -0,0 +1,5 @@
export interface SignPdfState {
file: File | null;
pdfBytes: ArrayBuffer | null;
signatureData: string | null;
}

View File

@@ -0,0 +1,18 @@
export interface GenerateTOCMessage {
type: 'generateTOC';
pdfBytes: ArrayBuffer;
title: string;
headerColor: string;
fontColor: string;
fontSize: number;
}
export interface TOCSuccessResponse {
type: 'success';
pdfBytes: ArrayBuffer;
}
export interface TOCErrorResponse {
type: 'error';
message: string;
}

View File

@@ -0,0 +1,6 @@
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
export interface TextColorState {
file: File | null;
pdfDoc: PDFLibDocument | null;
}

View File

@@ -0,0 +1,47 @@
import forge from 'node-forge';
export interface SignatureValidationResult {
signatureIndex: number;
isValid: boolean;
signerName: string;
signerOrg?: string;
signerEmail?: string;
issuer: string;
issuerOrg?: string;
signatureDate?: Date;
validFrom: Date;
validTo: Date;
isExpired: boolean;
isSelfSigned: boolean;
isTrusted: boolean;
algorithms: {
digest: string;
signature: string;
};
serialNumber: string;
reason?: string;
location?: string;
contactInfo?: string;
byteRange?: number[];
coverageStatus: 'full' | 'partial' | 'unknown';
errorMessage?: string;
}
export interface ExtractedSignature {
index: number;
contents: Uint8Array;
byteRange: number[];
reason?: string;
location?: string;
contactInfo?: string;
name?: string;
signingTime?: string;
}
export interface ValidateSignatureState {
pdfFile: File | null;
pdfBytes: Uint8Array | null;
results: SignatureValidationResult[];
trustedCertFile: File | null;
trustedCert: forge.pki.Certificate | null;
}

View File

@@ -0,0 +1,4 @@
export interface ViewMetadataState {
file: File | null;
metadata: Record<string, unknown>;
}