@signiphi/pdf-signer 0.1.1

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.
Files changed (192) hide show
  1. package/INSTALLING_LOCALLY.md +184 -0
  2. package/LICENSE +2 -0
  3. package/README.md +1093 -0
  4. package/assets/viewer.html +314 -0
  5. package/dist/__tests__/helpers/fixtures.d.ts +43 -0
  6. package/dist/__tests__/helpers/fixtures.d.ts.map +1 -0
  7. package/dist/__tests__/helpers/mocks.d.ts +333 -0
  8. package/dist/__tests__/helpers/mocks.d.ts.map +1 -0
  9. package/dist/__tests__/setup.d.ts +6 -0
  10. package/dist/__tests__/setup.d.ts.map +1 -0
  11. package/dist/components/AttachmentUpload.d.ts +17 -0
  12. package/dist/components/AttachmentUpload.d.ts.map +1 -0
  13. package/dist/components/EditableFieldsPanel.d.ts +30 -0
  14. package/dist/components/EditableFieldsPanel.d.ts.map +1 -0
  15. package/dist/components/ErrorBoundary.d.ts +67 -0
  16. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  17. package/dist/components/FormFieldsView.d.ts +42 -0
  18. package/dist/components/FormFieldsView.d.ts.map +1 -0
  19. package/dist/components/PdfViewerStyled.d.ts +16 -0
  20. package/dist/components/PdfViewerStyled.d.ts.map +1 -0
  21. package/dist/components/PoweredBySigniphi.d.ts +11 -0
  22. package/dist/components/PoweredBySigniphi.d.ts.map +1 -0
  23. package/dist/components/SignatureCanvas.d.ts +12 -0
  24. package/dist/components/SignatureCanvas.d.ts.map +1 -0
  25. package/dist/components/SignatureInitialsBox.d.ts +23 -0
  26. package/dist/components/SignatureInitialsBox.d.ts.map +1 -0
  27. package/dist/components/SignatureModal.d.ts +22 -0
  28. package/dist/components/SignatureModal.d.ts.map +1 -0
  29. package/dist/components/SigningInstructions.d.ts +12 -0
  30. package/dist/components/SigningInstructions.d.ts.map +1 -0
  31. package/dist/components/SubmissionForm.d.ts +52 -0
  32. package/dist/components/SubmissionForm.d.ts.map +1 -0
  33. package/dist/components/ViewToggleToolbar.d.ts +30 -0
  34. package/dist/components/ViewToggleToolbar.d.ts.map +1 -0
  35. package/dist/components/form-fields/CheckboxRenderer.d.ts +10 -0
  36. package/dist/components/form-fields/CheckboxRenderer.d.ts.map +1 -0
  37. package/dist/components/form-fields/DateFieldRenderer.d.ts +14 -0
  38. package/dist/components/form-fields/DateFieldRenderer.d.ts.map +1 -0
  39. package/dist/components/form-fields/DropdownRenderer.d.ts +14 -0
  40. package/dist/components/form-fields/DropdownRenderer.d.ts.map +1 -0
  41. package/dist/components/form-fields/FormFieldRenderer.d.ts +20 -0
  42. package/dist/components/form-fields/FormFieldRenderer.d.ts.map +1 -0
  43. package/dist/components/form-fields/InitialsFieldRenderer.d.ts +14 -0
  44. package/dist/components/form-fields/InitialsFieldRenderer.d.ts.map +1 -0
  45. package/dist/components/form-fields/RadioGroupRenderer.d.ts +10 -0
  46. package/dist/components/form-fields/RadioGroupRenderer.d.ts.map +1 -0
  47. package/dist/components/form-fields/SignatureFieldRenderer.d.ts +16 -0
  48. package/dist/components/form-fields/SignatureFieldRenderer.d.ts.map +1 -0
  49. package/dist/components/form-fields/TextFieldRenderer.d.ts +14 -0
  50. package/dist/components/form-fields/TextFieldRenderer.d.ts.map +1 -0
  51. package/dist/components/form-fields/TextLabelRenderer.d.ts +14 -0
  52. package/dist/components/form-fields/TextLabelRenderer.d.ts.map +1 -0
  53. package/dist/components/form-fields/index.d.ts +14 -0
  54. package/dist/components/form-fields/index.d.ts.map +1 -0
  55. package/dist/components/index.d.ts +14 -0
  56. package/dist/components/index.d.ts.map +1 -0
  57. package/dist/components/index.js +6297 -0
  58. package/dist/components/index.js.map +1 -0
  59. package/dist/components/index.mjs +6248 -0
  60. package/dist/components/index.mjs.map +1 -0
  61. package/dist/core/PdfViewerCore.d.ts +19 -0
  62. package/dist/core/PdfViewerCore.d.ts.map +1 -0
  63. package/dist/core/SignatureCaptureCore.d.ts +37 -0
  64. package/dist/core/SignatureCaptureCore.d.ts.map +1 -0
  65. package/dist/core/index.d.ts +3 -0
  66. package/dist/core/index.d.ts.map +1 -0
  67. package/dist/core/index.js +907 -0
  68. package/dist/core/index.js.map +1 -0
  69. package/dist/core/index.mjs +884 -0
  70. package/dist/core/index.mjs.map +1 -0
  71. package/dist/hooks/index.d.ts +8 -0
  72. package/dist/hooks/index.d.ts.map +1 -0
  73. package/dist/hooks/index.js +2167 -0
  74. package/dist/hooks/index.js.map +1 -0
  75. package/dist/hooks/index.mjs +2139 -0
  76. package/dist/hooks/index.mjs.map +1 -0
  77. package/dist/hooks/useAttachments.d.ts +25 -0
  78. package/dist/hooks/useAttachments.d.ts.map +1 -0
  79. package/dist/hooks/useFieldFiltering.d.ts +29 -0
  80. package/dist/hooks/useFieldFiltering.d.ts.map +1 -0
  81. package/dist/hooks/useFormFields.d.ts +23 -0
  82. package/dist/hooks/useFormFields.d.ts.map +1 -0
  83. package/dist/hooks/useMultiSignerContext.d.ts +25 -0
  84. package/dist/hooks/useMultiSignerContext.d.ts.map +1 -0
  85. package/dist/hooks/usePdfViewer.d.ts +52 -0
  86. package/dist/hooks/usePdfViewer.d.ts.map +1 -0
  87. package/dist/hooks/useSignatureCapture.d.ts +17 -0
  88. package/dist/hooks/useSignatureCapture.d.ts.map +1 -0
  89. package/dist/hooks/useSignatures.d.ts +25 -0
  90. package/dist/hooks/useSignatures.d.ts.map +1 -0
  91. package/dist/index.css +4929 -0
  92. package/dist/index.css.map +1 -0
  93. package/dist/index.d.ts +17 -0
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +7220 -0
  96. package/dist/index.js.map +1 -0
  97. package/dist/index.mjs +7093 -0
  98. package/dist/index.mjs.map +1 -0
  99. package/dist/integrations/index.d.ts +6 -0
  100. package/dist/integrations/index.d.ts.map +1 -0
  101. package/dist/integrations/index.js +242 -0
  102. package/dist/integrations/index.js.map +1 -0
  103. package/dist/integrations/index.mjs +218 -0
  104. package/dist/integrations/index.mjs.map +1 -0
  105. package/dist/integrations/next-config.d.ts +46 -0
  106. package/dist/integrations/next-config.d.ts.map +1 -0
  107. package/dist/integrations/vite-plugin.d.ts +48 -0
  108. package/dist/integrations/vite-plugin.d.ts.map +1 -0
  109. package/dist/lib/index.d.ts +3 -0
  110. package/dist/lib/index.d.ts.map +1 -0
  111. package/dist/lib/ui/alert.d.ts +9 -0
  112. package/dist/lib/ui/alert.d.ts.map +1 -0
  113. package/dist/lib/ui/button.d.ts +12 -0
  114. package/dist/lib/ui/button.d.ts.map +1 -0
  115. package/dist/lib/ui/calendar.d.ts +10 -0
  116. package/dist/lib/ui/calendar.d.ts.map +1 -0
  117. package/dist/lib/ui/card.d.ts +9 -0
  118. package/dist/lib/ui/card.d.ts.map +1 -0
  119. package/dist/lib/ui/checkbox.d.ts +5 -0
  120. package/dist/lib/ui/checkbox.d.ts.map +1 -0
  121. package/dist/lib/ui/dialog.d.ts +20 -0
  122. package/dist/lib/ui/dialog.d.ts.map +1 -0
  123. package/dist/lib/ui/index.d.ts +12 -0
  124. package/dist/lib/ui/index.d.ts.map +1 -0
  125. package/dist/lib/ui/input.d.ts +6 -0
  126. package/dist/lib/ui/input.d.ts.map +1 -0
  127. package/dist/lib/ui/label.d.ts +6 -0
  128. package/dist/lib/ui/label.d.ts.map +1 -0
  129. package/dist/lib/ui/popover.d.ts +7 -0
  130. package/dist/lib/ui/popover.d.ts.map +1 -0
  131. package/dist/lib/ui/radio-group.d.ts +6 -0
  132. package/dist/lib/ui/radio-group.d.ts.map +1 -0
  133. package/dist/lib/ui/select.d.ts +14 -0
  134. package/dist/lib/ui/select.d.ts.map +1 -0
  135. package/dist/lib/utils.d.ts +7 -0
  136. package/dist/lib/utils.d.ts.map +1 -0
  137. package/dist/styles/index.css +5004 -0
  138. package/dist/types/index.d.ts +265 -0
  139. package/dist/types/index.d.ts.map +1 -0
  140. package/dist/types/index.js +26 -0
  141. package/dist/types/index.js.map +1 -0
  142. package/dist/types/index.mjs +23 -0
  143. package/dist/types/index.mjs.map +1 -0
  144. package/dist/utils/attachment-validators.d.ts +118 -0
  145. package/dist/utils/attachment-validators.d.ts.map +1 -0
  146. package/dist/utils/audit-trail.d.ts +27 -0
  147. package/dist/utils/audit-trail.d.ts.map +1 -0
  148. package/dist/utils/date-validation.d.ts +30 -0
  149. package/dist/utils/date-validation.d.ts.map +1 -0
  150. package/dist/utils/errors.d.ts +106 -0
  151. package/dist/utils/errors.d.ts.map +1 -0
  152. package/dist/utils/field-extraction.d.ts +27 -0
  153. package/dist/utils/field-extraction.d.ts.map +1 -0
  154. package/dist/utils/field-visibility.d.ts +104 -0
  155. package/dist/utils/field-visibility.d.ts.map +1 -0
  156. package/dist/utils/index.d.ts +17 -0
  157. package/dist/utils/index.d.ts.map +1 -0
  158. package/dist/utils/index.js +2501 -0
  159. package/dist/utils/index.js.map +1 -0
  160. package/dist/utils/index.mjs +2404 -0
  161. package/dist/utils/index.mjs.map +1 -0
  162. package/dist/utils/logger.d.ts +16 -0
  163. package/dist/utils/logger.d.ts.map +1 -0
  164. package/dist/utils/pdf-field-type-helpers.d.ts +78 -0
  165. package/dist/utils/pdf-field-type-helpers.d.ts.map +1 -0
  166. package/dist/utils/pdf-helpers.d.ts +38 -0
  167. package/dist/utils/pdf-helpers.d.ts.map +1 -0
  168. package/dist/utils/pdf-lib-loader.d.ts +45 -0
  169. package/dist/utils/pdf-lib-loader.d.ts.map +1 -0
  170. package/dist/utils/pdf-manipulation.d.ts +93 -0
  171. package/dist/utils/pdf-manipulation.d.ts.map +1 -0
  172. package/dist/utils/pdf-validators.d.ts +149 -0
  173. package/dist/utils/pdf-validators.d.ts.map +1 -0
  174. package/dist/utils/pdf-viewer-filter.d.ts +35 -0
  175. package/dist/utils/pdf-viewer-filter.d.ts.map +1 -0
  176. package/dist/utils/pdf-widget-helpers.d.ts +98 -0
  177. package/dist/utils/pdf-widget-helpers.d.ts.map +1 -0
  178. package/dist/utils/pdfjs-config.d.ts +56 -0
  179. package/dist/utils/pdfjs-config.d.ts.map +1 -0
  180. package/dist/utils/pdfjs-version-check.d.ts +28 -0
  181. package/dist/utils/pdfjs-version-check.d.ts.map +1 -0
  182. package/dist/utils/performance-monitor.d.ts +172 -0
  183. package/dist/utils/performance-monitor.d.ts.map +1 -0
  184. package/dist/utils/tracking.d.ts +89 -0
  185. package/dist/utils/tracking.d.ts.map +1 -0
  186. package/package.json +180 -0
  187. package/scripts/analyze-bundle.js +271 -0
  188. package/scripts/copy-utils.js +227 -0
  189. package/scripts/copy-utils.test.js +164 -0
  190. package/scripts/postinstall.js +109 -0
  191. package/scripts/setup.js +108 -0
  192. package/src/styles/index.css +139 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * PDF Field Type Helper Utilities
3
+ * Common utilities for detecting field types and extracting values
4
+ *
5
+ * Used across pdf-manipulation.ts for consistent field processing
6
+ */
7
+ /**
8
+ * PDF form field type for operations
9
+ */
10
+ interface PDFFormField {
11
+ getName(): string;
12
+ constructor: {
13
+ name: string;
14
+ };
15
+ getText?(): string;
16
+ setText?(text: string): void;
17
+ isRequired?(): boolean;
18
+ isChecked?(): boolean;
19
+ getSelected?(): string[];
20
+ enableReadOnly?(): void;
21
+ }
22
+ /**
23
+ * Detect the field type from a PDF field
24
+ *
25
+ * Maps pdf-lib's field constructor names to standardized type strings.
26
+ *
27
+ * @param field - The PDF form field
28
+ * @returns Standardized field type string
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const fieldType = detectFieldType(field);
33
+ * // Returns: 'text', 'checkbox', 'dropdown', 'radiogroup', 'signature', etc.
34
+ * ```
35
+ */
36
+ export declare function detectFieldType(field: PDFFormField): string;
37
+ /**
38
+ * Extract the current value from a PDF field based on its type
39
+ *
40
+ * Handles different field types appropriately:
41
+ * - Text fields: getText()
42
+ * - Checkboxes: isChecked() → 'true'/'false'
43
+ * - Dropdowns: getSelected()[0]
44
+ * - Radio groups: getSelected()[0]
45
+ *
46
+ * @param field - The PDF form field
47
+ * @param fieldType - The field type (from detectFieldType)
48
+ * @returns The field value as a string, or empty string if no value
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const fieldType = detectFieldType(field);
53
+ * const value = extractFieldValue(field, fieldType);
54
+ * ```
55
+ */
56
+ export declare function extractFieldValue(field: PDFFormField, fieldType: string): string;
57
+ /**
58
+ * Check if a field is required based on field metadata and name patterns
59
+ *
60
+ * Attempts to determine required status through:
61
+ * 1. field.isRequired() method (if available)
62
+ * 2. Field name patterns (signature, initials, required)
63
+ * 3. Field type (signatures are always required)
64
+ *
65
+ * @param field - The PDF form field
66
+ * @param fieldName - The field name
67
+ * @param fieldType - The field type (from detectFieldType)
68
+ * @returns true if field is required
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const isRequired = isRequiredField(field, 'signature_1', 'text');
73
+ * // Returns: true (signature fields are required)
74
+ * ```
75
+ */
76
+ export declare function isRequiredField(field: PDFFormField, fieldName: string, fieldType: string): boolean;
77
+ export {};
78
+ //# sourceMappingURL=pdf-field-type-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-field-type-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-field-type-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,UAAU,YAAY;IACpB,OAAO,IAAI,MAAM,CAAC;IAClB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,OAAO,CAAC,IAAI,MAAM,CAAC;IACnB,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,IAAI,OAAO,CAAC;IACvB,SAAS,CAAC,IAAI,OAAO,CAAC;IACtB,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;IACzB,cAAc,CAAC,IAAI,IAAI,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAkB3D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAoBhF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAyBT"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * PDF utility helper functions
3
+ */
4
+ /**
5
+ * Create a blob URL from PDF bytes for preview
6
+ */
7
+ export declare function createPdfBlobUrl(pdfBytes: Uint8Array): string;
8
+ /**
9
+ * Download PDF file
10
+ */
11
+ export declare function downloadPdf(pdfBytes: Uint8Array, filename: string): void;
12
+ /**
13
+ * Convert URL to PDF bytes
14
+ * @param url - The URL to fetch the PDF from
15
+ * @returns PDF bytes as Uint8Array
16
+ */
17
+ export declare function urlToPdfBytes(url: string): Promise<Uint8Array>;
18
+ /**
19
+ * Validate that data is a valid PDF
20
+ */
21
+ export declare function isValidPdf(pdfBytes: Uint8Array): boolean;
22
+ /**
23
+ * Convert base64 data URL to image bytes
24
+ */
25
+ export declare function dataUrlToBytes(dataUrl: string): Uint8Array;
26
+ /**
27
+ * Format field name for display
28
+ */
29
+ export declare function formatFieldName(fieldName: string): string;
30
+ /**
31
+ * Check if a field is a signature field
32
+ */
33
+ export declare function isSignatureField(fieldName: string): boolean;
34
+ /**
35
+ * Check if a field is an initials field
36
+ */
37
+ export declare function isInitialsField(fieldName: string): boolean;
38
+ //# sourceMappingURL=pdf-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAG7D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOxE;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAyBpE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAGxD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAM1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOzD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE1D"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Lazy loader for pdf-lib
3
+ *
4
+ * This module provides a lazy loading mechanism for the pdf-lib library (~150KB).
5
+ * By deferring the import until actually needed, we can significantly reduce
6
+ * the initial bundle size for consumers who only view PDFs without filling forms.
7
+ *
8
+ * The pdf-lib library is only loaded when:
9
+ * - fillPdf() is called
10
+ * - combinePdfs() is called
11
+ * - Other PDF manipulation functions are used
12
+ */
13
+ /**
14
+ * Dynamically import pdf-lib library
15
+ *
16
+ * This function lazily loads pdf-lib only when needed. The import is cached
17
+ * so subsequent calls return the same promise, avoiding multiple imports.
18
+ *
19
+ * @returns Promise resolving to the pdf-lib module
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { PDFDocument, rgb, StandardFonts } = await loadPdfLib();
24
+ * const pdfDoc = await PDFDocument.load(pdfBytes);
25
+ * ```
26
+ */
27
+ export declare function loadPdfLib(): Promise<typeof import("pdf-lib")>;
28
+ /**
29
+ * Check if pdf-lib has been loaded
30
+ *
31
+ * Useful for debugging and testing to verify lazy loading behavior.
32
+ *
33
+ * @returns true if pdf-lib has been loaded, false otherwise
34
+ */
35
+ export declare function isPdfLibLoaded(): boolean;
36
+ /**
37
+ * Reset the pdf-lib cache (primarily for testing)
38
+ *
39
+ * This should only be used in test environments to reset state
40
+ * between tests.
41
+ *
42
+ * @internal
43
+ */
44
+ export declare function resetPdfLibCache(): void;
45
+ //# sourceMappingURL=pdf-lib-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-lib-loader.d.ts","sourceRoot":"","sources":["../../src/utils/pdf-lib-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,sCAK/B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
@@ -0,0 +1,93 @@
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, extractedFormFields?: EsignFormField[], metadata?: {
50
+ submissionId?: string;
51
+ documentId?: string;
52
+ author?: string;
53
+ signerEmail?: string;
54
+ signerInitials?: string;
55
+ createdAt?: Date;
56
+ }, auditTrail?: {
57
+ userAgent?: string;
58
+ screenResolution?: string;
59
+ timezone?: string;
60
+ language?: string;
61
+ platform?: string;
62
+ ipAddress?: string;
63
+ geolocation?: {
64
+ latitude: number;
65
+ longitude: number;
66
+ accuracy?: number;
67
+ };
68
+ }, multiSignerContext?: {
69
+ isMultiSigner: boolean;
70
+ currentSigner: any;
71
+ currentSignerEmail: string;
72
+ isPrimarySigner: boolean;
73
+ isFinalSigner: boolean;
74
+ }): Promise<Uint8Array>;
75
+ /**
76
+ * Fill form fields and replace signature/initials with actual signature images
77
+ * This is used when fields are rendered as overlays on the PDF
78
+ * @param pdfBytes - The PDF bytes
79
+ * @param formFields - The form fields with their positions
80
+ * @param fieldValues - The field values to fill
81
+ * @param signatures - The signature images (base64 data URLs)
82
+ * @returns The filled PDF bytes
83
+ */
84
+ export declare function fillFormFieldsWithSignatures(pdfBytes: Uint8Array, formFields: EsignFormField[], fieldValues: Record<string, string>, signatures: Record<string, string>): Promise<Uint8Array>;
85
+ /**
86
+ * Extract field positions and page numbers from a PDF document
87
+ * Returns maps for field name -> page number and field name -> position
88
+ */
89
+ export declare function getFieldPageNumbers(pdfBytes: Uint8Array): Promise<{
90
+ pageMap: Record<string, number>;
91
+ positionMap: Record<string, FormFieldPosition>;
92
+ }>;
93
+ //# 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,149 @@
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 are simple type names like "Text", "Signature", etc.
32
+ * These are default labels assigned by the form builder and should not be
33
+ * displayed to users in the same way as custom labels.
34
+ *
35
+ * Works identically in both single-signer and multi-signer flows.
36
+ *
37
+ * @param label - The label to check
38
+ * @returns true if the label is auto-generated, false if it's a custom user label
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * isAutoGeneratedLabel('Signature') // true
43
+ * isAutoGeneratedLabel('Sign here please') // false
44
+ * isAutoGeneratedLabel('') // true
45
+ * ```
46
+ */
47
+ export declare function isAutoGeneratedLabel(label: string): boolean;
48
+ /**
49
+ * Validate field values object
50
+ *
51
+ * Checks that the values object is properly formatted and contains
52
+ * only string values for field IDs.
53
+ *
54
+ * @param values - Field values to validate
55
+ * @returns Validation result with valid flag and errors array
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const result = validateFieldValues({ field1: 'value1', field2: 'value2' });
60
+ * if (!result.valid) {
61
+ * console.error('Validation errors:', result.errors);
62
+ * }
63
+ * ```
64
+ */
65
+ export declare function validateFieldValues(values: unknown): {
66
+ valid: boolean;
67
+ errors: string[];
68
+ };
69
+ /**
70
+ * Validate signatures object
71
+ *
72
+ * Checks that signatures are properly formatted data URLs.
73
+ *
74
+ * @param signatures - Signatures to validate
75
+ * @returns Validation result with valid flag and errors array
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const result = validateSignatures({
80
+ * sig1: 'data:image/png;base64,iVBORw0KG...',
81
+ * sig2: 'data:image/png;base64,iVBORw0KG...'
82
+ * });
83
+ * if (!result.valid) {
84
+ * console.error('Invalid signatures:', result.errors);
85
+ * }
86
+ * ```
87
+ */
88
+ export declare function validateSignatures(signatures: unknown): {
89
+ valid: boolean;
90
+ errors: string[];
91
+ };
92
+ /**
93
+ * Validate a form field definition
94
+ *
95
+ * Checks that a field has all required properties and they are valid.
96
+ *
97
+ * @param field - Form field to validate
98
+ * @returns Validation result with valid flag and errors array
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const result = validateFormField({
103
+ * id: 'field1',
104
+ * name: 'firstName',
105
+ * type: FormFieldType.TEXT,
106
+ * label: 'First Name',
107
+ * position: { x: 100, y: 200, width: 150, height: 30, page: 1 },
108
+ * required: true
109
+ * });
110
+ * if (!result.valid) {
111
+ * console.error('Field validation errors:', result.errors);
112
+ * }
113
+ * ```
114
+ */
115
+ export declare function validateFormField(field: unknown): {
116
+ valid: boolean;
117
+ errors: string[];
118
+ };
119
+ /**
120
+ * Validate PDF URL format
121
+ *
122
+ * Accepts absolute URLs, relative paths, and data URLs.
123
+ *
124
+ * @param url - URL to validate
125
+ * @returns Validation result with valid flag and optional error message
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * // Absolute URLs
130
+ * validatePdfUrl('https://example.com/document.pdf'); // valid
131
+ * validatePdfUrl('http://localhost:3000/doc.pdf'); // valid
132
+ *
133
+ * // Relative paths
134
+ * validatePdfUrl('/public/document.pdf'); // valid
135
+ * validatePdfUrl('./document.pdf'); // valid
136
+ *
137
+ * // Data URLs and blobs
138
+ * validatePdfUrl('data:application/pdf;base64,...'); // valid
139
+ * validatePdfUrl('blob:http://localhost/...'); // valid
140
+ *
141
+ * // Local files
142
+ * validatePdfUrl('file:///C:/path/to/file.pdf'); // valid
143
+ * ```
144
+ */
145
+ export declare function validatePdfUrl(url: unknown): {
146
+ valid: boolean;
147
+ error?: string;
148
+ };
149
+ //# 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;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAe3D;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;AA6LnE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,UAAU,EACpB,SAAS,EAAE,cAAc,EAAE,EAC3B,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,CAAC,CA6GrB"}
@@ -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"}