@signiphi/page-assembly 0.2.0-beta.3 → 0.2.0-beta.4

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/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import React__default from 'react';
3
3
  import * as class_variance_authority_types from 'class-variance-authority/types';
4
4
  import { VariantProps } from 'class-variance-authority';
5
+ import { PDFDocument } from 'pdf-lib';
5
6
 
6
7
  /**
7
8
  * Represents a single page in the page assembly system
@@ -39,6 +40,52 @@ type FileInfo = {
39
40
  /** Pages extracted from this file */
40
41
  pages: PageInfo[];
41
42
  };
43
+ /**
44
+ * Form field with page tracking for assembly operations
45
+ */
46
+ type TrackedFormField = {
47
+ /** Field name */
48
+ name: string;
49
+ /** Field type */
50
+ type: string;
51
+ /** Field position */
52
+ position: {
53
+ x: number;
54
+ y: number;
55
+ width: number;
56
+ height: number;
57
+ page: number;
58
+ };
59
+ /** Page ID this field is associated with (for tracking across page operations) */
60
+ pageId?: string;
61
+ /** Original file ID this field came from */
62
+ originalFileId?: string;
63
+ /** All other field properties */
64
+ label?: string;
65
+ required?: boolean;
66
+ options?: string[];
67
+ placeholder?: string;
68
+ defaultValue?: string;
69
+ assignedSignerEmail?: string;
70
+ fieldId?: string;
71
+ fontSize?: number;
72
+ multiline?: boolean;
73
+ maxLength?: number;
74
+ acknowledgements?: Array<{
75
+ id: string;
76
+ title: string;
77
+ description: string;
78
+ }>;
79
+ };
80
+ /**
81
+ * Extracted fields from a file
82
+ */
83
+ type FileExtractedFields = {
84
+ /** File ID these fields came from */
85
+ fileId: string;
86
+ /** Extracted form fields */
87
+ fields: TrackedFormField[];
88
+ };
42
89
  /**
43
90
  * State of the page assembler
44
91
  */
@@ -49,6 +96,10 @@ type PageAssemblerState = {
49
96
  selection: string[];
50
97
  /** ID of the last selected page (for range selection) */
51
98
  lastSelectedPageId?: string;
99
+ /** Form fields tracked across page operations */
100
+ formFields?: TrackedFormField[];
101
+ /** Extracted fields per file (for mapping after assembly) */
102
+ extractedFieldsByFile?: FileExtractedFields[];
52
103
  };
53
104
  /**
54
105
  * Options for assembling the final PDF
@@ -175,4 +226,132 @@ declare function createPdfBlobUrl(pdfBytes: Uint8Array): string;
175
226
  */
176
227
  declare function downloadPdf(pdfBytes: Uint8Array, filename: string): void;
177
228
 
178
- export { type AssembleOptions, Button, type FileInfo, PageAssembler, type PageAssemblerHandle, type PageAssemblerProps, type PageAssemblerState, type PageImage, type PageInfo, createPdfBlobUrl, PageAssembler as default, downloadPdf, imageToPdf, pdfToImages };
229
+ /**
230
+ * PDF Field Extraction Utilities
231
+ * Extract form fields from PDFs with metadata support for preserving field properties
232
+ */
233
+
234
+ /**
235
+ * Extracted field information
236
+ */
237
+ interface ExtractedField {
238
+ name: string;
239
+ type: 'text' | 'signature' | 'initials' | 'date' | 'checkbox' | 'radio' | 'dropdown' | 'text_label';
240
+ page: number;
241
+ x: number;
242
+ y: number;
243
+ width: number;
244
+ height: number;
245
+ required: boolean;
246
+ label?: string;
247
+ placeholder?: string;
248
+ options?: string[];
249
+ fieldId?: string;
250
+ signer?: string;
251
+ }
252
+ /**
253
+ * SigniphiMetadata structure stored in PDF Info dictionary
254
+ */
255
+ interface SigniphiMetadata {
256
+ version: string;
257
+ fields: Record<string, {
258
+ fieldId?: string;
259
+ label?: string;
260
+ signer?: string;
261
+ placeholder?: string;
262
+ required?: boolean;
263
+ options?: string[];
264
+ acknowledgements?: Array<{
265
+ id: string;
266
+ title: string;
267
+ description: string;
268
+ }>;
269
+ }>;
270
+ fieldIdIndex?: Record<string, string>;
271
+ }
272
+ /**
273
+ * Extract SigniphiMetadata from a PDF document
274
+ */
275
+ declare function getSigniphiMetadata(pdfDoc: PDFDocument): SigniphiMetadata | null;
276
+ /**
277
+ * Extract form fields from a PDF document
278
+ * @param pdfBytes - PDF bytes
279
+ * @returns Array of extracted fields with all properties
280
+ */
281
+ declare function extractFieldsFromPdf(pdfBytes: Uint8Array): Promise<ExtractedField[]>;
282
+ /**
283
+ * Set SigniphiMetadata in a PDF document
284
+ */
285
+ declare function setSigniphiMetadata(pdfDoc: PDFDocument, metadata: SigniphiMetadata): void;
286
+
287
+ /**
288
+ * Add Form Fields to PDF
289
+ * Re-adds form fields to a PDF after page assembly operations
290
+ * This is the key to preserving form fields - don't try to preserve during copyPages,
291
+ * instead extract fields first, copy pages, then re-add fields with adjusted positions.
292
+ */
293
+ /**
294
+ * Form field type enum matching document-prepare
295
+ */
296
+ declare enum FormFieldType {
297
+ TEXT = "text",
298
+ SIGNATURE = "signature",
299
+ INITIALS = "initials",
300
+ DATE = "date",
301
+ CHECKBOX = "checkbox",
302
+ RADIO = "radio",
303
+ DROPDOWN = "dropdown",
304
+ TEXT_LABEL = "text_label"
305
+ }
306
+ /**
307
+ * Form field position
308
+ */
309
+ interface FormFieldPosition {
310
+ x: number;
311
+ y: number;
312
+ width: number;
313
+ height: number;
314
+ page: number;
315
+ }
316
+ /**
317
+ * Form field for adding to PDF
318
+ */
319
+ interface FormFieldForPdf {
320
+ name: string;
321
+ type: FormFieldType | string;
322
+ position: FormFieldPosition;
323
+ label?: string;
324
+ required?: boolean;
325
+ options?: string[];
326
+ defaultValue?: string;
327
+ placeholder?: string;
328
+ fontSize?: number;
329
+ multiline?: boolean;
330
+ maxLength?: number;
331
+ assignedSignerEmail?: string;
332
+ }
333
+ /**
334
+ * Add form fields to a PDF document
335
+ *
336
+ * @param pdfBytes - The PDF document bytes
337
+ * @param formFields - Array of form fields to add
338
+ * @param options - Options for field addition
339
+ * @returns Modified PDF bytes with form fields added
340
+ */
341
+ declare function addFormFieldsToPdf(pdfBytes: Uint8Array, formFields: FormFieldForPdf[], options?: {
342
+ removeExistingFields?: boolean;
343
+ drawLabels?: boolean;
344
+ }): Promise<Uint8Array>;
345
+ /**
346
+ * Map field positions after page assembly
347
+ * Updates field page numbers based on the final page arrangement
348
+ *
349
+ * @param fields - Original fields with positions
350
+ * @param pageMapping - Map of "originalFileId_originalPageIndex" -> newPageNumber
351
+ * @returns Fields with updated page positions
352
+ */
353
+ declare function mapFieldPositionsAfterAssembly<T extends {
354
+ position: FormFieldPosition;
355
+ }>(fields: T[], pageMapping: Map<string, number>): T[];
356
+
357
+ export { type AssembleOptions, Button, type ExtractedField, type FileExtractedFields, type FileInfo, type FormFieldForPdf, type FormFieldPosition, FormFieldType, PageAssembler, type PageAssemblerHandle, type PageAssemblerProps, type PageAssemblerState, type PageImage, type PageInfo, type TrackedFormField, addFormFieldsToPdf, createPdfBlobUrl, PageAssembler as default, downloadPdf, extractFieldsFromPdf, getSigniphiMetadata, imageToPdf, mapFieldPositionsAfterAssembly, pdfToImages, setSigniphiMetadata };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import React__default from 'react';
3
3
  import * as class_variance_authority_types from 'class-variance-authority/types';
4
4
  import { VariantProps } from 'class-variance-authority';
5
+ import { PDFDocument } from 'pdf-lib';
5
6
 
6
7
  /**
7
8
  * Represents a single page in the page assembly system
@@ -39,6 +40,52 @@ type FileInfo = {
39
40
  /** Pages extracted from this file */
40
41
  pages: PageInfo[];
41
42
  };
43
+ /**
44
+ * Form field with page tracking for assembly operations
45
+ */
46
+ type TrackedFormField = {
47
+ /** Field name */
48
+ name: string;
49
+ /** Field type */
50
+ type: string;
51
+ /** Field position */
52
+ position: {
53
+ x: number;
54
+ y: number;
55
+ width: number;
56
+ height: number;
57
+ page: number;
58
+ };
59
+ /** Page ID this field is associated with (for tracking across page operations) */
60
+ pageId?: string;
61
+ /** Original file ID this field came from */
62
+ originalFileId?: string;
63
+ /** All other field properties */
64
+ label?: string;
65
+ required?: boolean;
66
+ options?: string[];
67
+ placeholder?: string;
68
+ defaultValue?: string;
69
+ assignedSignerEmail?: string;
70
+ fieldId?: string;
71
+ fontSize?: number;
72
+ multiline?: boolean;
73
+ maxLength?: number;
74
+ acknowledgements?: Array<{
75
+ id: string;
76
+ title: string;
77
+ description: string;
78
+ }>;
79
+ };
80
+ /**
81
+ * Extracted fields from a file
82
+ */
83
+ type FileExtractedFields = {
84
+ /** File ID these fields came from */
85
+ fileId: string;
86
+ /** Extracted form fields */
87
+ fields: TrackedFormField[];
88
+ };
42
89
  /**
43
90
  * State of the page assembler
44
91
  */
@@ -49,6 +96,10 @@ type PageAssemblerState = {
49
96
  selection: string[];
50
97
  /** ID of the last selected page (for range selection) */
51
98
  lastSelectedPageId?: string;
99
+ /** Form fields tracked across page operations */
100
+ formFields?: TrackedFormField[];
101
+ /** Extracted fields per file (for mapping after assembly) */
102
+ extractedFieldsByFile?: FileExtractedFields[];
52
103
  };
53
104
  /**
54
105
  * Options for assembling the final PDF
@@ -175,4 +226,132 @@ declare function createPdfBlobUrl(pdfBytes: Uint8Array): string;
175
226
  */
176
227
  declare function downloadPdf(pdfBytes: Uint8Array, filename: string): void;
177
228
 
178
- export { type AssembleOptions, Button, type FileInfo, PageAssembler, type PageAssemblerHandle, type PageAssemblerProps, type PageAssemblerState, type PageImage, type PageInfo, createPdfBlobUrl, PageAssembler as default, downloadPdf, imageToPdf, pdfToImages };
229
+ /**
230
+ * PDF Field Extraction Utilities
231
+ * Extract form fields from PDFs with metadata support for preserving field properties
232
+ */
233
+
234
+ /**
235
+ * Extracted field information
236
+ */
237
+ interface ExtractedField {
238
+ name: string;
239
+ type: 'text' | 'signature' | 'initials' | 'date' | 'checkbox' | 'radio' | 'dropdown' | 'text_label';
240
+ page: number;
241
+ x: number;
242
+ y: number;
243
+ width: number;
244
+ height: number;
245
+ required: boolean;
246
+ label?: string;
247
+ placeholder?: string;
248
+ options?: string[];
249
+ fieldId?: string;
250
+ signer?: string;
251
+ }
252
+ /**
253
+ * SigniphiMetadata structure stored in PDF Info dictionary
254
+ */
255
+ interface SigniphiMetadata {
256
+ version: string;
257
+ fields: Record<string, {
258
+ fieldId?: string;
259
+ label?: string;
260
+ signer?: string;
261
+ placeholder?: string;
262
+ required?: boolean;
263
+ options?: string[];
264
+ acknowledgements?: Array<{
265
+ id: string;
266
+ title: string;
267
+ description: string;
268
+ }>;
269
+ }>;
270
+ fieldIdIndex?: Record<string, string>;
271
+ }
272
+ /**
273
+ * Extract SigniphiMetadata from a PDF document
274
+ */
275
+ declare function getSigniphiMetadata(pdfDoc: PDFDocument): SigniphiMetadata | null;
276
+ /**
277
+ * Extract form fields from a PDF document
278
+ * @param pdfBytes - PDF bytes
279
+ * @returns Array of extracted fields with all properties
280
+ */
281
+ declare function extractFieldsFromPdf(pdfBytes: Uint8Array): Promise<ExtractedField[]>;
282
+ /**
283
+ * Set SigniphiMetadata in a PDF document
284
+ */
285
+ declare function setSigniphiMetadata(pdfDoc: PDFDocument, metadata: SigniphiMetadata): void;
286
+
287
+ /**
288
+ * Add Form Fields to PDF
289
+ * Re-adds form fields to a PDF after page assembly operations
290
+ * This is the key to preserving form fields - don't try to preserve during copyPages,
291
+ * instead extract fields first, copy pages, then re-add fields with adjusted positions.
292
+ */
293
+ /**
294
+ * Form field type enum matching document-prepare
295
+ */
296
+ declare enum FormFieldType {
297
+ TEXT = "text",
298
+ SIGNATURE = "signature",
299
+ INITIALS = "initials",
300
+ DATE = "date",
301
+ CHECKBOX = "checkbox",
302
+ RADIO = "radio",
303
+ DROPDOWN = "dropdown",
304
+ TEXT_LABEL = "text_label"
305
+ }
306
+ /**
307
+ * Form field position
308
+ */
309
+ interface FormFieldPosition {
310
+ x: number;
311
+ y: number;
312
+ width: number;
313
+ height: number;
314
+ page: number;
315
+ }
316
+ /**
317
+ * Form field for adding to PDF
318
+ */
319
+ interface FormFieldForPdf {
320
+ name: string;
321
+ type: FormFieldType | string;
322
+ position: FormFieldPosition;
323
+ label?: string;
324
+ required?: boolean;
325
+ options?: string[];
326
+ defaultValue?: string;
327
+ placeholder?: string;
328
+ fontSize?: number;
329
+ multiline?: boolean;
330
+ maxLength?: number;
331
+ assignedSignerEmail?: string;
332
+ }
333
+ /**
334
+ * Add form fields to a PDF document
335
+ *
336
+ * @param pdfBytes - The PDF document bytes
337
+ * @param formFields - Array of form fields to add
338
+ * @param options - Options for field addition
339
+ * @returns Modified PDF bytes with form fields added
340
+ */
341
+ declare function addFormFieldsToPdf(pdfBytes: Uint8Array, formFields: FormFieldForPdf[], options?: {
342
+ removeExistingFields?: boolean;
343
+ drawLabels?: boolean;
344
+ }): Promise<Uint8Array>;
345
+ /**
346
+ * Map field positions after page assembly
347
+ * Updates field page numbers based on the final page arrangement
348
+ *
349
+ * @param fields - Original fields with positions
350
+ * @param pageMapping - Map of "originalFileId_originalPageIndex" -> newPageNumber
351
+ * @returns Fields with updated page positions
352
+ */
353
+ declare function mapFieldPositionsAfterAssembly<T extends {
354
+ position: FormFieldPosition;
355
+ }>(fields: T[], pageMapping: Map<string, number>): T[];
356
+
357
+ export { type AssembleOptions, Button, type ExtractedField, type FileExtractedFields, type FileInfo, type FormFieldForPdf, type FormFieldPosition, FormFieldType, PageAssembler, type PageAssemblerHandle, type PageAssemblerProps, type PageAssemblerState, type PageImage, type PageInfo, type TrackedFormField, addFormFieldsToPdf, createPdfBlobUrl, PageAssembler as default, downloadPdf, extractFieldsFromPdf, getSigniphiMetadata, imageToPdf, mapFieldPositionsAfterAssembly, pdfToImages, setSigniphiMetadata };