@signiphi/pdf-compose 0.1.0-beta.1 → 0.1.0-beta.3

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/README.md ADDED
@@ -0,0 +1,258 @@
1
+ # @signiphi/pdf-compose
2
+
3
+ Markdown-based document composer with interactive form field placeholders and real-time PDF preview. Built for the signiphi signing pipeline.
4
+
5
+ Write documents in a rich text editor, embed signable form fields (signature, date, text, checkbox, etc.) and template variables, then export production-ready PDFs with interactive AcroForm fields.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @signiphi/pdf-compose
11
+ # or
12
+ pnpm add @signiphi/pdf-compose
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```tsx
18
+ import { DocumentGenerator } from '@signiphi/pdf-compose';
19
+ import '@signiphi/pdf-compose/styles';
20
+
21
+ function App() {
22
+ return (
23
+ <DocumentGenerator
24
+ placeholder="Start writing your document..."
25
+ onExport={(result) => {
26
+ // result.pdfBlob — Blob with interactive form fields
27
+ // result.fields — Array of field positions for signing
28
+ const url = URL.createObjectURL(result.pdfBlob);
29
+ window.open(url);
30
+ }}
31
+ />
32
+ );
33
+ }
34
+ ```
35
+
36
+ ## Features
37
+
38
+ - **Rich text editor** — TipTap-based with markdown toolbar (headings, bold, italic, underline, lists, alignment)
39
+ - **Form field placeholders** — Insert signature, text, date, checkbox, initials, radio, dropdown, and text label fields inline
40
+ - **Template variables** — Define reusable variables (company name, salary, etc.) that get replaced at generation time
41
+ - **Real-time PDF preview** — See the rendered PDF alongside the editor with field overlays
42
+ - **PDF generation** — Export PDFs with embedded interactive AcroForm fields via pdf-lib
43
+ - **Bulk generation** — Fill variables from JSON or CSV and generate multiple PDFs as a ZIP
44
+ - **Theming** — Light, dark, and auto modes with customizable primary color
45
+ - **Markdown I/O** — Import/export documents as markdown with field token syntax
46
+
47
+ ## Props
48
+
49
+ ```tsx
50
+ interface DocumentGeneratorProps {
51
+ /** Pre-fill the editor with markdown content */
52
+ initialMarkdown?: string;
53
+ /** Pre-fill with TipTap JSON content (takes precedence over initialMarkdown) */
54
+ initialContent?: JSONContent;
55
+ /** Fires on content changes (debounced 150ms) */
56
+ onChange?: (data: { markdown: string; fields: DocumentGeneratorField[]; variables: DocumentGeneratorVariable[] }) => void;
57
+ /** Fires when the user exports from the Editor tab */
58
+ onExport?: (result: DocumentGeneratorExportResult) => void;
59
+ /** Fires when the user generates a PDF from the Generate tab */
60
+ onGeneratePdf?: (blob: Blob, fileName: string) => void;
61
+ /** Disable editing */
62
+ readOnly?: boolean;
63
+ /** Custom CSS class */
64
+ className?: string;
65
+ /** Primary theme color (hex) */
66
+ themeColor?: string;
67
+ /** Theme mode — 'light' | 'dark' | 'auto' (default: 'auto') */
68
+ themeMode?: ThemeMode;
69
+ /** Full custom color palette */
70
+ themeConfig?: ThemeConfig;
71
+ /** Show the PDF preview panel (default: true) */
72
+ showPreview?: boolean;
73
+ /** Show the editor toolbar (default: true) */
74
+ showToolbar?: boolean;
75
+ /** Show the Generate tab (default: true) */
76
+ showGenerateTab?: boolean;
77
+ /** Editor placeholder text */
78
+ placeholder?: string;
79
+ /** Custom text for the export button */
80
+ exportButtonText?: string;
81
+ /** Pre-fill bulk generation data */
82
+ initialBulkData?: Record<string, string>[];
83
+ }
84
+ ```
85
+
86
+ ## Field Token Syntax
87
+
88
+ Fields and variables are embedded as inline tokens in the markdown content:
89
+
90
+ ### Form Fields
91
+
92
+ ```
93
+ {{field|type:signature|name:sig_1|label:Employee Signature|required:true}}
94
+ ```
95
+
96
+ | Attribute | Description |
97
+ | -------------- | --------------------------------------------- |
98
+ | `type` | `text`, `signature`, `initials`, `date`, `checkbox`, `radio`, `dropdown`, `text_label` |
99
+ | `name` | Field identifier in the PDF |
100
+ | `label` | User-facing label |
101
+ | `required` | `true` or `false` |
102
+ | `placeholder` | Hint text for text fields |
103
+ | `options` | Comma-separated values (radio/dropdown) |
104
+ | `defaultValue` | Pre-filled value |
105
+ | `multiline` | `true` for multiline text fields |
106
+ | `maxLength` | Character limit |
107
+ | `fontSize` | Font size in points |
108
+
109
+ ### Template Variables
110
+
111
+ ```
112
+ {{var|name:company_name|label:Company Name|default:Acme Corp}}
113
+ ```
114
+
115
+ | Attribute | Description |
116
+ | --------- | --------------------- |
117
+ | `name` | Variable identifier |
118
+ | `label` | Display label |
119
+ | `default` | Default value |
120
+
121
+ Variables are replaced with actual values at PDF generation time. In bulk mode, each row of data produces a separate PDF.
122
+
123
+ ## Advanced Usage
124
+
125
+ ### Using the Hook Directly
126
+
127
+ For custom layouts, use `useDocumentGenerator` to drive your own UI:
128
+
129
+ ```tsx
130
+ import { useDocumentGenerator, EditorPanel, PreviewPanel } from '@signiphi/pdf-compose';
131
+ import '@signiphi/pdf-compose/styles';
132
+
133
+ function CustomComposer() {
134
+ const generator = useDocumentGenerator({ initialMarkdown: '# My Doc' });
135
+
136
+ return (
137
+ <div style={{ display: 'flex', gap: 16 }}>
138
+ <EditorPanel {...generator} />
139
+ <PreviewPanel pages={generator.pdfPages} fields={generator.positionedFields} />
140
+ </div>
141
+ );
142
+ }
143
+ ```
144
+
145
+ ### Export Result
146
+
147
+ The `onExport` callback receives:
148
+
149
+ ```tsx
150
+ interface DocumentGeneratorExportResult {
151
+ pdfBlob: Blob; // PDF with embedded interactive form fields
152
+ fields: FormFieldForExport[]; // Field metadata with page positions
153
+ }
154
+
155
+ interface FormFieldForExport {
156
+ name: string;
157
+ type: FormFieldType;
158
+ label?: string;
159
+ required: boolean;
160
+ page: number;
161
+ x: number;
162
+ y: number;
163
+ width: number;
164
+ height: number;
165
+ }
166
+ ```
167
+
168
+ ### Pre-filled Markdown Example
169
+
170
+ ```tsx
171
+ const markdown = `# Employment Agreement
172
+
173
+ **Company:** {{var|name:company|label:Company Name|default:Acme Corp}}
174
+
175
+ **Employee:** {{field|type:text|name:employee_name|required:true|placeholder:Full name}}
176
+
177
+ **Start Date:** {{field|type:date|name:start_date|required:true}}
178
+
179
+ ## Signature
180
+
181
+ {{field|type:signature|name:employee_sig|label:Employee Signature|required:true}}
182
+ `;
183
+
184
+ <DocumentGenerator
185
+ initialMarkdown={markdown}
186
+ onExport={handleExport}
187
+ themeColor="#4F46E5"
188
+ />
189
+ ```
190
+
191
+ ## Styling
192
+
193
+ Import the stylesheet — required for the component to render correctly:
194
+
195
+ ```tsx
196
+ import '@signiphi/pdf-compose/styles';
197
+ ```
198
+
199
+ All styles are scoped under `.signiphi-pdf-compose` so they won't conflict with your application's CSS. CSS custom properties use the `--xpc-*` namespace.
200
+
201
+ ### Theming
202
+
203
+ ```tsx
204
+ // Simple — just a color
205
+ <DocumentGenerator themeColor="#4F46E5" themeMode="dark" />
206
+
207
+ // Full custom palette
208
+ <DocumentGenerator themeConfig={{
209
+ primary: '#4F46E5',
210
+ primaryForeground: '#ffffff',
211
+ background: '#1a1a2e',
212
+ foreground: '#e0e0e0',
213
+ border: '#333355',
214
+ // ...
215
+ }} />
216
+ ```
217
+
218
+ ## Exports
219
+
220
+ ```tsx
221
+ // Components
222
+ export { DocumentGenerator } from '@signiphi/pdf-compose';
223
+ export { EditorPanel } from '@signiphi/pdf-compose';
224
+ export { PreviewPanel } from '@signiphi/pdf-compose';
225
+
226
+ // Hooks
227
+ export { useDocumentGenerator } from '@signiphi/pdf-compose';
228
+
229
+ // Theme
230
+ export { ThemeProvider, useTheme } from '@signiphi/pdf-compose';
231
+
232
+ // Types
233
+ export type {
234
+ DocumentGeneratorProps,
235
+ DocumentGeneratorField,
236
+ DocumentGeneratorVariable,
237
+ VariableValues,
238
+ GeneratedDocument,
239
+ DocumentGeneratorExportResult,
240
+ FormFieldForExport,
241
+ ThemeMode,
242
+ ThemeConfig,
243
+ PdfPage,
244
+ } from '@signiphi/pdf-compose';
245
+
246
+ export { FormFieldType } from '@signiphi/pdf-compose';
247
+ ```
248
+
249
+ ## Peer Dependencies
250
+
251
+ - `react` >= 18
252
+ - `react-dom` >= 18
253
+ - `@radix-ui/react-dialog`, `@radix-ui/react-label`, `@radix-ui/react-popover`, `@radix-ui/react-select`, `@radix-ui/react-tooltip`
254
+ - `lucide-react`
255
+
256
+ ## License
257
+
258
+ See repository for license information.