@signiphi/pdf-signer 0.2.0-beta.21 → 0.2.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/helpers/fixtures.d.ts +43 -0
- package/dist/__tests__/helpers/fixtures.d.ts.map +1 -0
- package/dist/__tests__/helpers/mocks.d.ts +411 -0
- package/dist/__tests__/helpers/mocks.d.ts.map +1 -0
- package/dist/__tests__/setup.d.ts +6 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/components/AcknowledgementModal.d.ts +21 -0
- package/dist/components/AcknowledgementModal.d.ts.map +1 -0
- package/dist/components/AcknowledgementsSidebar.d.ts +22 -0
- package/dist/components/AcknowledgementsSidebar.d.ts.map +1 -0
- package/dist/components/AttachmentUpload.d.ts +20 -0
- package/dist/components/AttachmentUpload.d.ts.map +1 -0
- package/dist/components/DateFieldCalendarPopup.d.ts +28 -0
- package/dist/components/DateFieldCalendarPopup.d.ts.map +1 -0
- package/dist/components/EditableFieldsPanel.d.ts +30 -0
- package/dist/components/EditableFieldsPanel.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.d.ts +67 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/FormFieldsView.d.ts +46 -0
- package/dist/components/FormFieldsView.d.ts.map +1 -0
- package/dist/components/InitialsModal.d.ts +16 -0
- package/dist/components/InitialsModal.d.ts.map +1 -0
- package/dist/components/PdfViewerStyled.d.ts +16 -0
- package/dist/components/PdfViewerStyled.d.ts.map +1 -0
- package/dist/components/PoweredBySigniphi.d.ts +11 -0
- package/dist/components/PoweredBySigniphi.d.ts.map +1 -0
- package/dist/components/RequiredFieldNavigation.d.ts +18 -0
- package/dist/components/RequiredFieldNavigation.d.ts.map +1 -0
- package/dist/components/SignatureCanvas.d.ts +12 -0
- package/dist/components/SignatureCanvas.d.ts.map +1 -0
- package/dist/components/SignatureInitialsBox.d.ts +25 -0
- package/dist/components/SignatureInitialsBox.d.ts.map +1 -0
- package/dist/components/SignatureModal.d.ts +21 -0
- package/dist/components/SignatureModal.d.ts.map +1 -0
- package/dist/components/SignatureTypeInput.d.ts +27 -0
- package/dist/components/SignatureTypeInput.d.ts.map +1 -0
- package/dist/components/SigningInstructions.d.ts +12 -0
- package/dist/components/SigningInstructions.d.ts.map +1 -0
- package/dist/components/SubmissionForm.d.ts +52 -0
- package/dist/components/SubmissionForm.d.ts.map +1 -0
- package/dist/components/UnacknowledgedFieldsModal.d.ts +25 -0
- package/dist/components/UnacknowledgedFieldsModal.d.ts.map +1 -0
- package/dist/components/ViewToggleToolbar.d.ts +38 -0
- package/dist/components/ViewToggleToolbar.d.ts.map +1 -0
- package/dist/components/form-fields/CheckboxRenderer.d.ts +10 -0
- package/dist/components/form-fields/CheckboxRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/DateFieldRenderer.d.ts +14 -0
- package/dist/components/form-fields/DateFieldRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/DropdownRenderer.d.ts +14 -0
- package/dist/components/form-fields/DropdownRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/FormFieldRenderer.d.ts +22 -0
- package/dist/components/form-fields/FormFieldRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/InitialsFieldRenderer.d.ts +16 -0
- package/dist/components/form-fields/InitialsFieldRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/RadioGroupRenderer.d.ts +10 -0
- package/dist/components/form-fields/RadioGroupRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/SignatureFieldRenderer.d.ts +16 -0
- package/dist/components/form-fields/SignatureFieldRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/TextFieldRenderer.d.ts +14 -0
- package/dist/components/form-fields/TextFieldRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/TextLabelRenderer.d.ts +14 -0
- package/dist/components/form-fields/TextLabelRenderer.d.ts.map +1 -0
- package/dist/components/form-fields/index.d.ts +14 -0
- package/dist/components/form-fields/index.d.ts.map +1 -0
- package/dist/components/index.d.ts +18 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/core/PdfViewerCore.d.ts +19 -0
- package/dist/core/PdfViewerCore.d.ts.map +1 -0
- package/dist/core/SignatureCaptureCore.d.ts +37 -0
- package/dist/core/SignatureCaptureCore.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAcknowledgements.d.ts +50 -0
- package/dist/hooks/useAcknowledgements.d.ts.map +1 -0
- package/dist/hooks/useAttachments.d.ts +26 -0
- package/dist/hooks/useAttachments.d.ts.map +1 -0
- package/dist/hooks/useFieldFiltering.d.ts +29 -0
- package/dist/hooks/useFieldFiltering.d.ts.map +1 -0
- package/dist/hooks/useFormFields.d.ts +23 -0
- package/dist/hooks/useFormFields.d.ts.map +1 -0
- package/dist/hooks/useMultiSignerContext.d.ts +25 -0
- package/dist/hooks/useMultiSignerContext.d.ts.map +1 -0
- package/dist/hooks/usePdfViewer.d.ts +52 -0
- package/dist/hooks/usePdfViewer.d.ts.map +1 -0
- package/dist/hooks/useRequiredFieldNavigation.d.ts +16 -0
- package/dist/hooks/useRequiredFieldNavigation.d.ts.map +1 -0
- package/dist/hooks/useSignatureCapture.d.ts +17 -0
- package/dist/hooks/useSignatureCapture.d.ts.map +1 -0
- package/dist/hooks/useSignatures.d.ts +29 -0
- package/dist/hooks/useSignatures.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +6 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/next-config.d.ts +46 -0
- package/dist/integrations/next-config.d.ts.map +1 -0
- package/dist/integrations/vite-plugin.d.ts +48 -0
- package/dist/integrations/vite-plugin.d.ts.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/ui/accordion.d.ts +8 -0
- package/dist/lib/ui/accordion.d.ts.map +1 -0
- package/dist/lib/ui/alert.d.ts +9 -0
- package/dist/lib/ui/alert.d.ts.map +1 -0
- package/dist/lib/ui/button.d.ts +12 -0
- package/dist/lib/ui/button.d.ts.map +1 -0
- package/dist/lib/ui/calendar.d.ts +10 -0
- package/dist/lib/ui/calendar.d.ts.map +1 -0
- package/dist/lib/ui/card.d.ts +9 -0
- package/dist/lib/ui/card.d.ts.map +1 -0
- package/dist/lib/ui/checkbox.d.ts +5 -0
- package/dist/lib/ui/checkbox.d.ts.map +1 -0
- package/dist/lib/ui/dialog.d.ts +20 -0
- package/dist/lib/ui/dialog.d.ts.map +1 -0
- package/dist/lib/ui/index.d.ts +13 -0
- package/dist/lib/ui/index.d.ts.map +1 -0
- package/dist/lib/ui/input.d.ts +6 -0
- package/dist/lib/ui/input.d.ts.map +1 -0
- package/dist/lib/ui/label.d.ts +6 -0
- package/dist/lib/ui/label.d.ts.map +1 -0
- package/dist/lib/ui/popover.d.ts +7 -0
- package/dist/lib/ui/popover.d.ts.map +1 -0
- package/dist/lib/ui/radio-group.d.ts +6 -0
- package/dist/lib/ui/radio-group.d.ts.map +1 -0
- package/dist/lib/ui/select.d.ts +14 -0
- package/dist/lib/ui/select.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +7 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/types/index.d.ts +299 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/attachment-validators.d.ts +118 -0
- package/dist/utils/attachment-validators.d.ts.map +1 -0
- package/dist/utils/audit-trail.d.ts +27 -0
- package/dist/utils/audit-trail.d.ts.map +1 -0
- package/dist/utils/date-validation-iso.d.ts +11 -0
- package/dist/utils/date-validation-iso.d.ts.map +1 -0
- package/dist/utils/date-validation.d.ts +27 -0
- package/dist/utils/date-validation.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +106 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/field-extraction.d.ts +59 -0
- package/dist/utils/field-extraction.d.ts.map +1 -0
- package/dist/utils/field-visibility.d.ts +108 -0
- package/dist/utils/field-visibility.d.ts.map +1 -0
- package/dist/utils/font-loader.d.ts +50 -0
- package/dist/utils/font-loader.d.ts.map +1 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/pdf-field-type-helpers.d.ts +87 -0
- package/dist/utils/pdf-field-type-helpers.d.ts.map +1 -0
- package/dist/utils/pdf-helpers.d.ts +38 -0
- package/dist/utils/pdf-helpers.d.ts.map +1 -0
- package/dist/utils/pdf-lib-loader.d.ts +45 -0
- package/dist/utils/pdf-lib-loader.d.ts.map +1 -0
- package/dist/utils/pdf-manipulation.d.ts +94 -0
- package/dist/utils/pdf-manipulation.d.ts.map +1 -0
- package/dist/utils/pdf-metadata.d.ts +44 -0
- package/dist/utils/pdf-metadata.d.ts.map +1 -0
- package/dist/utils/pdf-signer-utils.d.ts +35 -0
- package/dist/utils/pdf-signer-utils.d.ts.map +1 -0
- package/dist/utils/pdf-validators.d.ts +184 -0
- package/dist/utils/pdf-validators.d.ts.map +1 -0
- package/dist/utils/pdf-viewer-filter.d.ts +35 -0
- package/dist/utils/pdf-viewer-filter.d.ts.map +1 -0
- package/dist/utils/pdf-widget-helpers.d.ts +98 -0
- package/dist/utils/pdf-widget-helpers.d.ts.map +1 -0
- package/dist/utils/pdfjs-config.d.ts +56 -0
- package/dist/utils/pdfjs-config.d.ts.map +1 -0
- package/dist/utils/pdfjs-version-check.d.ts +28 -0
- package/dist/utils/pdfjs-version-check.d.ts.map +1 -0
- package/dist/utils/performance-monitor.d.ts +172 -0
- package/dist/utils/performance-monitor.d.ts.map +1 -0
- package/dist/utils/tracking.d.ts +89 -0
- package/dist/utils/tracking.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Manipulation Utilities
|
|
3
|
+
* Core utilities for PDF processing, page manipulation, and file combining
|
|
4
|
+
*/
|
|
5
|
+
import { PdfPage, EsignFormField, FormFieldPosition, MultiSignerContext } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Convert PDF pages to images for rendering in the UI using PDF.js
|
|
8
|
+
*/
|
|
9
|
+
export declare function pdfToImages(pdfBytes: Uint8Array, options?: {
|
|
10
|
+
hideFormFields?: boolean;
|
|
11
|
+
}): Promise<PdfPage[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Remove all existing form fields from a PDF using robust widget cleanup
|
|
14
|
+
* @param pdfBytes - The PDF bytes
|
|
15
|
+
* @param stripAllAnnotations - If true, removes all annotations from pages (more aggressive cleanup)
|
|
16
|
+
* @returns The PDF bytes with all form fields removed
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeAllFormFields(pdfBytes: Uint8Array, stripAllAnnotations?: boolean): Promise<Uint8Array>;
|
|
19
|
+
/**
|
|
20
|
+
* Read existing PDF form fields and their properties
|
|
21
|
+
*/
|
|
22
|
+
export declare function readPdfFormFields(pdfBytes: Uint8Array): Promise<{
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
required: boolean;
|
|
26
|
+
value?: string;
|
|
27
|
+
}[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Read current PDF form field values (including user-filled data)
|
|
30
|
+
*/
|
|
31
|
+
export declare function readCurrentPdfFormValues(pdfBytes: Uint8Array): Promise<Record<string, string>>;
|
|
32
|
+
/**
|
|
33
|
+
* Validate PDF form fields against provided values
|
|
34
|
+
* In multi-signer mode, only validates fields visible to the current signer
|
|
35
|
+
*/
|
|
36
|
+
export declare function validatePdfFormFields(pdfBytes: Uint8Array, fieldValues: Record<string, string>, signatures: Record<string, string>, extractedFields?: EsignFormField[], // Pass extracted fields to know which are visible
|
|
37
|
+
multiSignerContext?: MultiSignerContext): Promise<string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Validate PDF form fields against current form state
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateCurrentPdfState(pdfBytes: Uint8Array, signatures: Record<string, string>, formFieldValues?: Record<string, string>): Promise<string[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Fill PDF with signature images and form field values, then flatten the form
|
|
44
|
+
* @param pdfBytes - The PDF bytes
|
|
45
|
+
* @param signatures - The signature data URLs (field name -> base64 PNG)
|
|
46
|
+
* @param formFieldValues - The form field values to fill
|
|
47
|
+
* @returns The filled and flattened PDF bytes
|
|
48
|
+
*/
|
|
49
|
+
export declare function fillPdfWithSignatures(pdfBytes: Uint8Array, signatures: Record<string, string>, formFieldValues?: Record<string, string>, _currentSignerEmail?: string, // Deprecated: use multiSignerContext.currentSignerEmail instead
|
|
50
|
+
extractedFormFields?: EsignFormField[], metadata?: {
|
|
51
|
+
submissionId?: string;
|
|
52
|
+
documentId?: string;
|
|
53
|
+
author?: string;
|
|
54
|
+
signerEmail?: string;
|
|
55
|
+
signerInitials?: string;
|
|
56
|
+
createdAt?: Date;
|
|
57
|
+
}, auditTrail?: {
|
|
58
|
+
userAgent?: string;
|
|
59
|
+
screenResolution?: string;
|
|
60
|
+
timezone?: string;
|
|
61
|
+
language?: string;
|
|
62
|
+
platform?: string;
|
|
63
|
+
ipAddress?: string;
|
|
64
|
+
geolocation?: {
|
|
65
|
+
latitude: number;
|
|
66
|
+
longitude: number;
|
|
67
|
+
accuracy?: number;
|
|
68
|
+
};
|
|
69
|
+
}, multiSignerContext?: {
|
|
70
|
+
isMultiSigner: boolean;
|
|
71
|
+
currentSigner: any;
|
|
72
|
+
currentSignerEmail: string;
|
|
73
|
+
isPrimarySigner: boolean;
|
|
74
|
+
isFinalSigner: boolean;
|
|
75
|
+
}): Promise<Uint8Array>;
|
|
76
|
+
/**
|
|
77
|
+
* Fill form fields and replace signature/initials with actual signature images
|
|
78
|
+
* This is used when fields are rendered as overlays on the PDF
|
|
79
|
+
* @param pdfBytes - The PDF bytes
|
|
80
|
+
* @param formFields - The form fields with their positions
|
|
81
|
+
* @param fieldValues - The field values to fill
|
|
82
|
+
* @param signatures - The signature images (base64 data URLs)
|
|
83
|
+
* @returns The filled PDF bytes
|
|
84
|
+
*/
|
|
85
|
+
export declare function fillFormFieldsWithSignatures(pdfBytes: Uint8Array, formFields: EsignFormField[], fieldValues: Record<string, string>, signatures: Record<string, string>): Promise<Uint8Array>;
|
|
86
|
+
/**
|
|
87
|
+
* Extract field positions and page numbers from a PDF document
|
|
88
|
+
* Returns maps for field name -> page number and field name -> position
|
|
89
|
+
*/
|
|
90
|
+
export declare function getFieldPageNumbers(pdfBytes: Uint8Array): Promise<{
|
|
91
|
+
pageMap: Record<string, number>;
|
|
92
|
+
positionMap: Record<string, FormFieldPosition>;
|
|
93
|
+
}>;
|
|
94
|
+
//# sourceMappingURL=pdf-manipulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-manipulation.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-manipulation.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Metadata Utilities
|
|
3
|
+
* Functions for storing and retrieving Signiphi metadata in PDF documents
|
|
4
|
+
*/
|
|
5
|
+
import type { PDFDocument } from 'pdf-lib';
|
|
6
|
+
import { Acknowledgement } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Initialize PDF classes from dynamically loaded pdf-lib module
|
|
9
|
+
* Must be called before using getSigniphiMetadata or setSigniphiMetadata
|
|
10
|
+
*/
|
|
11
|
+
export declare function initPdfMetadata(pdfLibModule: any): void;
|
|
12
|
+
/**
|
|
13
|
+
* Metadata for a single form field
|
|
14
|
+
*/
|
|
15
|
+
export interface FieldMetadata {
|
|
16
|
+
fieldId?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
signer?: string;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
acknowledgements?: Acknowledgement[];
|
|
21
|
+
required?: boolean;
|
|
22
|
+
options?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Complete metadata structure stored in PDF
|
|
26
|
+
*/
|
|
27
|
+
export interface SigniphiMetadata {
|
|
28
|
+
version: string;
|
|
29
|
+
fields: Record<string, FieldMetadata>;
|
|
30
|
+
fieldIdIndex?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Stores Signiphi metadata in the PDF's document information dictionary
|
|
34
|
+
* @param pdfDoc - The PDF document to store metadata in
|
|
35
|
+
* @param metadata - The metadata object to store
|
|
36
|
+
*/
|
|
37
|
+
export declare function setSigniphiMetadata(pdfDoc: PDFDocument, metadata: SigniphiMetadata): void;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves Signiphi metadata from the PDF's document information dictionary
|
|
40
|
+
* @param pdfDoc - The PDF document to read metadata from
|
|
41
|
+
* @returns The metadata object if found, null otherwise
|
|
42
|
+
*/
|
|
43
|
+
export declare function getSigniphiMetadata(pdfDoc: PDFDocument): SigniphiMetadata | null;
|
|
44
|
+
//# sourceMappingURL=pdf-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-metadata.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAsD,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,GAAG,GAAG,IAAI,CAGvD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAqBzF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CA2ChF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Signer Utilities for Multi-Signer Document Preparation
|
|
3
|
+
* Adapted from dm-web-frontend for signiphi's simpler signer model
|
|
4
|
+
*/
|
|
5
|
+
import { FormField, Signer } from '../types';
|
|
6
|
+
export interface PrepareSignerPdfOptions {
|
|
7
|
+
activeSignerEmail: string;
|
|
8
|
+
completedSignerEmails?: string[];
|
|
9
|
+
hideMode?: 'Hidden' | 'NoView';
|
|
10
|
+
lockCompletedFields?: boolean;
|
|
11
|
+
allSignerEmails?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Prepare a PDF document for a specific signer by hiding/showing fields and locking completed ones
|
|
15
|
+
* Adapted for signiphi: simplified logic without role checks
|
|
16
|
+
*/
|
|
17
|
+
export declare function preparePdfForSigner(inputPdfBytes: Uint8Array | ArrayBuffer, formFields: FormField[], options: PrepareSignerPdfOptions): Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Check if all signers have completed their fields
|
|
20
|
+
*/
|
|
21
|
+
export declare function areAllSignersComplete(signers: Signer[], completedSignerEmails: string[]): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get next signer in the sequence who hasn't completed their fields
|
|
24
|
+
* In signiphi, signers are ordered by signOrder (1, 2, 3...)
|
|
25
|
+
*/
|
|
26
|
+
export declare function getNextSigner(signers: Signer[], completedSignerEmails: string[]): Signer | null;
|
|
27
|
+
/**
|
|
28
|
+
* Validate field assignments for multiple signers
|
|
29
|
+
* Adapted for signiphi's flat signer model
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateFieldAssignments(formFields: FormField[], signers: Signer[]): {
|
|
32
|
+
isValid: boolean;
|
|
33
|
+
errors: string[];
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=pdf-signer-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-signer-utils.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-signer-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAiB,MAAM,EAAE,MAAM,UAAU,CAAC;AAG5D,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAyCD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,UAAU,GAAG,WAAW,EACvC,UAAU,EAAE,SAAS,EAAE,EACvB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CA0MrB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,EACjB,qBAAqB,EAAE,MAAM,EAAE,GAC9B,OAAO,CAYT;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EAAE,EACjB,qBAAqB,EAAE,MAAM,EAAE,GAC9B,MAAM,GAAG,IAAI,CAaf;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,SAAS,EAAE,EACvB,OAAO,EAAE,MAAM,EAAE,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAuCxC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Validation Utilities
|
|
3
|
+
* Common validation functions used across the package
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Validate that bytes represent a valid PDF file
|
|
7
|
+
*
|
|
8
|
+
* Checks for:
|
|
9
|
+
* - Non-empty bytes
|
|
10
|
+
* - Valid PDF header (%PDF-)
|
|
11
|
+
*
|
|
12
|
+
* @param pdfBytes - The PDF bytes to validate
|
|
13
|
+
* @returns Validation result with valid flag and optional error message
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const result = validatePdfBytes(pdfBytes);
|
|
18
|
+
* if (!result.valid) {
|
|
19
|
+
* console.error(result.error);
|
|
20
|
+
* return;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function validatePdfBytes(pdfBytes: Uint8Array): {
|
|
25
|
+
valid: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Check if a label is auto-generated (not user-typed)
|
|
30
|
+
*
|
|
31
|
+
* Auto-generated labels include:
|
|
32
|
+
* - Simple type names: "Text", "Signature", etc.
|
|
33
|
+
* - Type + timestamp: "Dropdown 12413423423", "Text 1768236803505"
|
|
34
|
+
* - Pure timestamps: "12413423423"
|
|
35
|
+
* - Type + numbers: "Dropdown1", "Text_2"
|
|
36
|
+
*
|
|
37
|
+
* These are default labels assigned by the form builder and should not be
|
|
38
|
+
* displayed to users in the same way as custom labels.
|
|
39
|
+
*
|
|
40
|
+
* Works identically in both single-signer and multi-signer flows.
|
|
41
|
+
*
|
|
42
|
+
* @param label - The label to check
|
|
43
|
+
* @returns true if the label is auto-generated, false if it's a custom user label
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* isAutoGeneratedLabel('Signature') // true
|
|
48
|
+
* isAutoGeneratedLabel('Dropdown 12413423423') // true
|
|
49
|
+
* isAutoGeneratedLabel('Sign here please') // false
|
|
50
|
+
* isAutoGeneratedLabel('') // true
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function isAutoGeneratedLabel(label: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a field has a drawable label (user-set custom label that should be rendered on the PDF)
|
|
56
|
+
*
|
|
57
|
+
* Returns false when:
|
|
58
|
+
* - Label is empty or whitespace
|
|
59
|
+
* - Label was auto-generated from field name during extraction (isLabelAutoGenerated flag)
|
|
60
|
+
* - Label matches known auto-generated patterns (e.g., "Text", "Signature 1")
|
|
61
|
+
*
|
|
62
|
+
* @param field - Object with label and optional isLabelAutoGenerated flag
|
|
63
|
+
* @returns true if the label should be drawn on the PDF
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasDrawableLabel(field: {
|
|
66
|
+
label?: string;
|
|
67
|
+
isLabelAutoGenerated?: boolean;
|
|
68
|
+
}): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Get a user-friendly display name for a field
|
|
71
|
+
*
|
|
72
|
+
* If the label is meaningful (not auto-generated), returns the label.
|
|
73
|
+
* Otherwise, returns a clean field type name.
|
|
74
|
+
*
|
|
75
|
+
* @param field - Object with label and type properties
|
|
76
|
+
* @returns A user-friendly name for display in error messages
|
|
77
|
+
*/
|
|
78
|
+
export declare function getFieldDisplayName(field: {
|
|
79
|
+
label?: string;
|
|
80
|
+
type?: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
}): string;
|
|
83
|
+
/**
|
|
84
|
+
* Validate field values object
|
|
85
|
+
*
|
|
86
|
+
* Checks that the values object is properly formatted and contains
|
|
87
|
+
* only string values for field IDs.
|
|
88
|
+
*
|
|
89
|
+
* @param values - Field values to validate
|
|
90
|
+
* @returns Validation result with valid flag and errors array
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const result = validateFieldValues({ field1: 'value1', field2: 'value2' });
|
|
95
|
+
* if (!result.valid) {
|
|
96
|
+
* console.error('Validation errors:', result.errors);
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateFieldValues(values: unknown): {
|
|
101
|
+
valid: boolean;
|
|
102
|
+
errors: string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Validate signatures object
|
|
106
|
+
*
|
|
107
|
+
* Checks that signatures are properly formatted data URLs.
|
|
108
|
+
*
|
|
109
|
+
* @param signatures - Signatures to validate
|
|
110
|
+
* @returns Validation result with valid flag and errors array
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const result = validateSignatures({
|
|
115
|
+
* sig1: 'data:image/png;base64,iVBORw0KG...',
|
|
116
|
+
* sig2: 'data:image/png;base64,iVBORw0KG...'
|
|
117
|
+
* });
|
|
118
|
+
* if (!result.valid) {
|
|
119
|
+
* console.error('Invalid signatures:', result.errors);
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function validateSignatures(signatures: unknown): {
|
|
124
|
+
valid: boolean;
|
|
125
|
+
errors: string[];
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Validate a form field definition
|
|
129
|
+
*
|
|
130
|
+
* Checks that a field has all required properties and they are valid.
|
|
131
|
+
*
|
|
132
|
+
* @param field - Form field to validate
|
|
133
|
+
* @returns Validation result with valid flag and errors array
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const result = validateFormField({
|
|
138
|
+
* id: 'field1',
|
|
139
|
+
* name: 'firstName',
|
|
140
|
+
* type: FormFieldType.TEXT,
|
|
141
|
+
* label: 'First Name',
|
|
142
|
+
* position: { x: 100, y: 200, width: 150, height: 30, page: 1 },
|
|
143
|
+
* required: true
|
|
144
|
+
* });
|
|
145
|
+
* if (!result.valid) {
|
|
146
|
+
* console.error('Field validation errors:', result.errors);
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function validateFormField(field: unknown): {
|
|
151
|
+
valid: boolean;
|
|
152
|
+
errors: string[];
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Validate PDF URL format
|
|
156
|
+
*
|
|
157
|
+
* Accepts absolute URLs, relative paths, and data URLs.
|
|
158
|
+
*
|
|
159
|
+
* @param url - URL to validate
|
|
160
|
+
* @returns Validation result with valid flag and optional error message
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // Absolute URLs
|
|
165
|
+
* validatePdfUrl('https://example.com/document.pdf'); // valid
|
|
166
|
+
* validatePdfUrl('http://localhost:3000/doc.pdf'); // valid
|
|
167
|
+
*
|
|
168
|
+
* // Relative paths
|
|
169
|
+
* validatePdfUrl('/public/document.pdf'); // valid
|
|
170
|
+
* validatePdfUrl('./document.pdf'); // valid
|
|
171
|
+
*
|
|
172
|
+
* // Data URLs and blobs
|
|
173
|
+
* validatePdfUrl('data:application/pdf;base64,...'); // valid
|
|
174
|
+
* validatePdfUrl('blob:http://localhost/...'); // valid
|
|
175
|
+
*
|
|
176
|
+
* // Local files
|
|
177
|
+
* validatePdfUrl('file:///C:/path/to/file.pdf'); // valid
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function validatePdfUrl(url: unknown): {
|
|
181
|
+
valid: boolean;
|
|
182
|
+
error?: string;
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=pdf-validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-validators.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-validators.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,GAAG;IACtD,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAmBA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAqD3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAKnG;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAyCnG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG;IACpD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAqBA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,OAAO,GAAG;IACvD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAiCA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG;IACjD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAuEA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG;IAC5C,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CA6BA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Viewer Filtering Utility
|
|
3
|
+
* Removes other signers' fields from PDF for viewer display
|
|
4
|
+
* Based on Dockmaster's field removal logic (lines 977-1037)
|
|
5
|
+
*/
|
|
6
|
+
import type { EsignFormField, MultiSignerContext } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Filter PDF for current signer by removing other signers' fields
|
|
9
|
+
* This creates a modified PDF for the viewer while preserving the original
|
|
10
|
+
*
|
|
11
|
+
* @param pdfBytes - Original PDF bytes with ALL fields
|
|
12
|
+
* @param allFields - All form fields extracted from the PDF
|
|
13
|
+
* @param multiSignerContext - Multi-signer context
|
|
14
|
+
* @returns Modified PDF bytes with other signers' fields removed (for viewer only)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const originalPdfBytes = await urlToPdfBytes(pdfUrl);
|
|
19
|
+
* const allFields = await extractFormFields(originalPdfBytes);
|
|
20
|
+
*
|
|
21
|
+
* if (multiSignerContext.isMultiSigner) {
|
|
22
|
+
* // Create filtered PDF for viewer
|
|
23
|
+
* const viewerPdfBytes = await filterPdfForCurrentSigner(
|
|
24
|
+
* originalPdfBytes,
|
|
25
|
+
* allFields,
|
|
26
|
+
* multiSignerContext
|
|
27
|
+
* );
|
|
28
|
+
* loadPdfIntoViewer(viewerPdfBytes);
|
|
29
|
+
*
|
|
30
|
+
* // CRITICAL: Keep originalPdfBytes for submission
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function filterPdfForCurrentSigner(pdfBytes: Uint8Array, allFields: EsignFormField[], multiSignerContext: MultiSignerContext): Promise<Uint8Array>;
|
|
35
|
+
//# sourceMappingURL=pdf-viewer-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-viewer-filter.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-viewer-filter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AA6OnE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,cAAc,EAAE,EAC3B,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,CAAC,CA8GrB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF Widget Helper Utilities
|
|
3
|
+
* Common utilities for working with PDF widgets and pages
|
|
4
|
+
*
|
|
5
|
+
* Used across pdf-manipulation.ts and pdf-viewer-filter.ts
|
|
6
|
+
*/
|
|
7
|
+
import type { PDFPage } from 'pdf-lib';
|
|
8
|
+
/**
|
|
9
|
+
* Find the page index for a given page reference
|
|
10
|
+
*
|
|
11
|
+
* This is a common pattern used when working with PDF widgets to determine
|
|
12
|
+
* which page a widget belongs to by comparing page references.
|
|
13
|
+
*
|
|
14
|
+
* @param pages - Array of PDF pages
|
|
15
|
+
* @param pageRef - The page reference to search for
|
|
16
|
+
* @returns Page index (0-based), or -1 if not found
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const widget = widgets[0];
|
|
21
|
+
* const pageRef = widget.P?.();
|
|
22
|
+
* const pageIndex = findPageIndexByRef(pages, pageRef);
|
|
23
|
+
* if (pageIndex >= 0) {
|
|
24
|
+
* const page = pages[pageIndex];
|
|
25
|
+
* // Draw on the page
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function findPageIndexByRef(pages: PDFPage[], pageRef: unknown): number;
|
|
30
|
+
/**
|
|
31
|
+
* Extended type for PDF widgets with rectangle and page methods
|
|
32
|
+
*/
|
|
33
|
+
export interface PDFWidgetWithExtensions {
|
|
34
|
+
getRectangle?: () => {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
} | undefined;
|
|
40
|
+
P?: () => unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get widget rectangle and its page
|
|
44
|
+
*
|
|
45
|
+
* Helper to extract both the rectangle coordinates and the page that a widget
|
|
46
|
+
* belongs to in a single operation.
|
|
47
|
+
*
|
|
48
|
+
* @param widget - The PDF widget
|
|
49
|
+
* @param pages - Array of PDF pages
|
|
50
|
+
* @returns Object with rect, page, and pageIndex, or null if unable to determine
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* for (const widget of widgets) {
|
|
55
|
+
* const result = getWidgetRectangleAndPage(widget, pages);
|
|
56
|
+
* if (result) {
|
|
57
|
+
* const { rect, page, pageIndex } = result;
|
|
58
|
+
* // Draw something at rect coordinates on page
|
|
59
|
+
* page.drawRectangle({ x: rect.x, y: rect.y, ... });
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function getWidgetRectangleAndPage(widget: PDFWidgetWithExtensions, pages: PDFPage[]): {
|
|
65
|
+
rect: {
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
};
|
|
71
|
+
page: PDFPage;
|
|
72
|
+
pageIndex: number;
|
|
73
|
+
} | null;
|
|
74
|
+
/**
|
|
75
|
+
* Find page index with fallback to single-page PDFs
|
|
76
|
+
*
|
|
77
|
+
* Same as findPageIndexByRef but with a fallback: if pageRef lookup fails
|
|
78
|
+
* and there's only one page in the document, returns index 0.
|
|
79
|
+
*
|
|
80
|
+
* This is useful for label drawing where single-page PDFs might not have
|
|
81
|
+
* proper page references but we can safely assume page 0.
|
|
82
|
+
*
|
|
83
|
+
* @param pages - Array of PDF pages
|
|
84
|
+
* @param pageRef - The page reference to search for
|
|
85
|
+
* @returns Page index (0-based), 0 if single-page PDF, or -1 if not found
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* // Used in pdf-viewer-filter for label drawing
|
|
90
|
+
* const pageIndex = findPageIndexWithFallback(pages, pageRef);
|
|
91
|
+
* if (pageIndex >= 0) {
|
|
92
|
+
* const page = pages[pageIndex];
|
|
93
|
+
* page.drawText(label, ...);
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function findPageIndexWithFallback(pages: PDFPage[], pageRef: unknown): number;
|
|
98
|
+
//# sourceMappingURL=pdf-widget-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-widget-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-widget-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAUvC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,EAAE,OAAO,GACf,MAAM,CAWR;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,MAAM;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACzF,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,uBAAuB,EAC/B,KAAK,EAAE,OAAO,EAAE,GACf;IACD,IAAI,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9D,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,IAAI,CAcP;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EAAE,EAChB,OAAO,EAAE,OAAO,GACf,MAAM,CAcR"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF.js Configuration Provider
|
|
3
|
+
* Manages global configuration for PDF.js worker and viewer paths
|
|
4
|
+
*
|
|
5
|
+
* COMPATIBILITY NOTE: This module is designed to work with both Vite and Next.js/webpack.
|
|
6
|
+
* The worker source URL is computed lazily to avoid issues with webpack's handling of import.meta.
|
|
7
|
+
*/
|
|
8
|
+
import type { PdfJsConfig } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* CDN paths for PDF.js (exported for manual fallback configuration)
|
|
11
|
+
* Note: CDN URLs may cause CORS issues in some environments
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Manually configure CDN (not recommended)
|
|
15
|
+
* setPdfJsConfig({
|
|
16
|
+
* viewerBasePath: CDN_VIEWER,
|
|
17
|
+
* workerSrc: CDN_WORKER
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
export declare const CDN_WORKER = "https://cdn.jsdelivr.net/npm/pdfjs-dist@5.3.93/build/pdf.worker.mjs";
|
|
21
|
+
export declare const CDN_VIEWER = "https://mozilla.github.io/pdf.js";
|
|
22
|
+
/**
|
|
23
|
+
* Set PDF.js configuration
|
|
24
|
+
* @param config - Partial configuration to merge with defaults
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Use self-hosted PDF.js files
|
|
28
|
+
* setPdfJsConfig({ viewerBasePath: '/pdfjs' });
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Use custom CDN
|
|
32
|
+
* setPdfJsConfig({
|
|
33
|
+
* viewerBasePath: 'https://my-cdn.com/pdfjs',
|
|
34
|
+
* workerSrc: 'https://my-cdn.com/pdfjs/build/pdf.worker.mjs'
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export declare function setPdfJsConfig(config: Partial<PdfJsConfig>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get current PDF.js configuration
|
|
40
|
+
* @returns Current configuration
|
|
41
|
+
*/
|
|
42
|
+
export declare function getPdfJsConfig(): Required<PdfJsConfig>;
|
|
43
|
+
/**
|
|
44
|
+
* Reset configuration to defaults (local files)
|
|
45
|
+
*/
|
|
46
|
+
export declare function resetPdfJsConfig(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize PDF.js configuration
|
|
49
|
+
* This is called automatically when the first PDF operation is attempted,
|
|
50
|
+
* but can also be called manually to pre-initialize the configuration.
|
|
51
|
+
*
|
|
52
|
+
* Unlike previous versions, this does NOT run at module load time to
|
|
53
|
+
* ensure compatibility with Next.js/webpack environments.
|
|
54
|
+
*/
|
|
55
|
+
export declare function initializePdfJs(): void;
|
|
56
|
+
//# sourceMappingURL=pdfjs-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs-config.d.ts","sourceRoot":"","sources":["../../src/utils/pdfjs-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,wEAAwE,CAAC;AAChG,eAAO,MAAM,UAAU,qCAAqC,CAAC;AA4F7D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAmBjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAAC,WAAW,CAAC,CAItD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAQvC;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF.js Version Check Utility
|
|
3
|
+
* Detects version mismatches between viewer and worker
|
|
4
|
+
*/
|
|
5
|
+
export interface PdfJsVersionCheckResult {
|
|
6
|
+
viewerExists: boolean;
|
|
7
|
+
versionMatch: boolean;
|
|
8
|
+
viewerVersion?: string;
|
|
9
|
+
workerVersion: string;
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check if PDF.js viewer files exist and versions match
|
|
14
|
+
* @param viewerBasePath - Base path for the viewer (e.g., '/pdfjs')
|
|
15
|
+
* @returns Version check result
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkPdfJsVersion(viewerBasePath?: string): Promise<PdfJsVersionCheckResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Log version check warnings to console
|
|
20
|
+
* @param result - Version check result
|
|
21
|
+
*/
|
|
22
|
+
export declare function logVersionCheckWarning(result: PdfJsVersionCheckResult): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check version and log warnings automatically
|
|
25
|
+
* @param viewerBasePath - Base path for the viewer
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkAndLogPdfJsVersion(viewerBasePath?: string): Promise<PdfJsVersionCheckResult>;
|
|
28
|
+
//# sourceMappingURL=pdfjs-version-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs-version-check.d.ts","sourceRoot":"","sources":["../../src/utils/pdfjs-version-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,GAAE,MAAiB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CA4ClC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAgB5E;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,cAAc,GAAE,MAAiB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAQlC"}
|