@formepdf/react 0.7.12 → 0.8.0

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/charts.d.ts CHANGED
@@ -1,5 +1,35 @@
1
1
  import React from 'react';
2
- import type { BarChartProps, LineChartProps, PieChartProps } from './types.js';
2
+ import type { Style, ChartDataPoint, PieDataPoint } from './types.js';
3
+ interface LegacyBarChartProps {
4
+ width: number;
5
+ height: number;
6
+ data: ChartDataPoint[];
7
+ color?: string;
8
+ barGap?: number;
9
+ showGrid?: boolean;
10
+ showValues?: boolean;
11
+ yAxisTicks?: number;
12
+ style?: Style;
13
+ }
14
+ interface LegacyLineChartProps {
15
+ width: number;
16
+ height: number;
17
+ data: ChartDataPoint[];
18
+ color?: string;
19
+ strokeWidth?: number;
20
+ showDots?: boolean;
21
+ showGrid?: boolean;
22
+ showArea?: boolean;
23
+ style?: Style;
24
+ }
25
+ interface LegacyPieChartProps {
26
+ width: number;
27
+ height: number;
28
+ data: PieDataPoint[];
29
+ showLabels?: boolean;
30
+ innerRadius?: number;
31
+ style?: Style;
32
+ }
3
33
  /**
4
34
  * A bar chart rendered as SVG + positioned Text labels.
5
35
  *
@@ -10,7 +40,7 @@ import type { BarChartProps, LineChartProps, PieChartProps } from './types.js';
10
40
  * color="#1a365d" showGrid showValues />
11
41
  * ```
12
42
  */
13
- export declare function BarChart(props: BarChartProps): React.ReactElement;
43
+ export declare function LegacyBarChart(props: LegacyBarChartProps): React.ReactElement;
14
44
  /**
15
45
  * A line chart rendered as SVG + positioned Text labels.
16
46
  *
@@ -21,7 +51,7 @@ export declare function BarChart(props: BarChartProps): React.ReactElement;
21
51
  * color="#2b6cb0" showDots showGrid showArea />
22
52
  * ```
23
53
  */
24
- export declare function LineChart(props: LineChartProps): React.ReactElement;
54
+ export declare function LegacyLineChart(props: LegacyLineChartProps): React.ReactElement;
25
55
  /**
26
56
  * A pie chart (or donut chart) rendered as SVG + positioned Text labels.
27
57
  *
@@ -38,4 +68,5 @@ export declare function LineChart(props: LineChartProps): React.ReactElement;
38
68
  * showLabels />
39
69
  * ```
40
70
  */
41
- export declare function PieChart(props: PieChartProps): React.ReactElement;
71
+ export declare function LegacyPieChart(props: LegacyPieChartProps): React.ReactElement;
72
+ export {};
package/dist/charts.js CHANGED
@@ -58,7 +58,7 @@ const X_AXIS_HEIGHT = 20;
58
58
  * color="#1a365d" showGrid showValues />
59
59
  * ```
60
60
  */
61
- export function BarChart(props) {
61
+ export function LegacyBarChart(props) {
62
62
  const { width, height, data, color = '#1a365d', barGap = 4, showGrid = false, showValues = false, yAxisTicks = 5, } = props;
63
63
  if (data.length === 0) {
64
64
  return React.createElement(View, { style: { width, height, ...props.style } });
@@ -154,7 +154,7 @@ export function BarChart(props) {
154
154
  * color="#2b6cb0" showDots showGrid showArea />
155
155
  * ```
156
156
  */
157
- export function LineChart(props) {
157
+ export function LegacyLineChart(props) {
158
158
  const { width, height, data, color = '#2b6cb0', strokeWidth = 2, showDots = false, showGrid = false, showArea = false, } = props;
159
159
  if (data.length === 0) {
160
160
  return React.createElement(View, { style: { width, height, ...props.style } });
@@ -262,7 +262,7 @@ export function LineChart(props) {
262
262
  * showLabels />
263
263
  * ```
264
264
  */
265
- export function PieChart(props) {
265
+ export function LegacyPieChart(props) {
266
266
  const { width, height, data, showLabels = false, innerRadius = 0, } = props;
267
267
  const total = data.reduce((sum, d) => sum + d.value, 0);
268
268
  if (data.length === 0 || total <= 0) {
@@ -1,4 +1,4 @@
1
- import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps } from './types.js';
1
+ import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps } from './types.js';
2
2
  /**
3
3
  * Root document container. Must be the top-level element in every Forme document.
4
4
  *
@@ -273,3 +273,131 @@ export declare function Watermark(_props: WatermarkProps): null;
273
273
  * ```
274
274
  */
275
275
  export declare function PageBreak(_props: object): null;
276
+ /**
277
+ * A bar chart rendered as native vector graphics in the PDF.
278
+ *
279
+ * @param props.data - Array of { label, value, color? } data points
280
+ * @param props.width - Chart width in points
281
+ * @param props.height - Chart height in points
282
+ * @param props.color - Default bar color (hex). Default: "#1a365d"
283
+ * @param props.showLabels - Show X-axis labels. Default: true
284
+ * @param props.showValues - Show value labels above bars. Default: false
285
+ * @param props.showGrid - Show horizontal grid lines. Default: false
286
+ * @param props.title - Chart title
287
+ */
288
+ export declare function BarChart(_props: BarChartProps): null;
289
+ /**
290
+ * A line chart rendered as native vector graphics in the PDF.
291
+ *
292
+ * @param props.series - Array of { name, data: number[], color? } series
293
+ * @param props.labels - X-axis labels
294
+ * @param props.width - Chart width in points
295
+ * @param props.height - Chart height in points
296
+ * @param props.showPoints - Show dots at data points. Default: false
297
+ * @param props.showGrid - Show horizontal grid lines. Default: false
298
+ * @param props.title - Chart title
299
+ */
300
+ export declare function LineChart(_props: LineChartProps): null;
301
+ /**
302
+ * A pie chart rendered as native vector graphics in the PDF.
303
+ *
304
+ * @param props.data - Array of { label, value, color? } data points
305
+ * @param props.width - Chart width in points
306
+ * @param props.height - Chart height in points
307
+ * @param props.donut - Render as donut chart. Default: false
308
+ * @param props.showLegend - Show legend. Default: false
309
+ * @param props.title - Chart title
310
+ */
311
+ export declare function PieChart(_props: PieChartProps): null;
312
+ /**
313
+ * An area chart rendered as native vector graphics in the PDF.
314
+ *
315
+ * @param props.series - Array of { name, data: number[], color? } series
316
+ * @param props.labels - X-axis labels
317
+ * @param props.width - Chart width in points
318
+ * @param props.height - Chart height in points
319
+ * @param props.showGrid - Show horizontal grid lines. Default: false
320
+ * @param props.title - Chart title
321
+ */
322
+ export declare function AreaChart(_props: AreaChartProps): null;
323
+ /**
324
+ * A dot plot (scatter plot) rendered as native vector graphics in the PDF.
325
+ *
326
+ * @param props.groups - Array of { name, color?, data: [x, y][] } groups
327
+ * @param props.width - Chart width in points
328
+ * @param props.height - Chart height in points
329
+ * @param props.dotSize - Dot radius. Default: 4
330
+ * @param props.showLegend - Show legend. Default: false
331
+ */
332
+ export declare function DotPlot(_props: DotPlotProps): null;
333
+ /**
334
+ * An interactive text input field (PDF AcroForm widget).
335
+ *
336
+ * @param props.name - Unique field name (PDF field identifier)
337
+ * @param props.width - Field width in points
338
+ * @param props.height - Field height in points. Default: 24
339
+ * @param props.value - Pre-filled value
340
+ * @param props.placeholder - Placeholder text shown when empty
341
+ * @param props.multiline - Allow multi-line input. Default: false
342
+ * @param props.password - Mask input. Default: false
343
+ * @param props.readOnly - Prevent editing. Default: false
344
+ * @param props.maxLength - Maximum character count
345
+ * @param props.fontSize - Font size in points. Default: 12
346
+ *
347
+ * @example
348
+ * ```tsx
349
+ * <TextField name="full_name" width={200} placeholder="Enter your name" />
350
+ * ```
351
+ */
352
+ export declare function TextField(_props: TextFieldProps): null;
353
+ /**
354
+ * An interactive checkbox (PDF AcroForm widget).
355
+ *
356
+ * @param props.name - Unique field name
357
+ * @param props.checked - Whether checked. Default: false
358
+ * @param props.width - Display width in points. Default: 14
359
+ * @param props.height - Display height in points. Default: 14
360
+ * @param props.readOnly - Prevent editing. Default: false
361
+ *
362
+ * @example
363
+ * ```tsx
364
+ * <Checkbox name="agree_terms" checked={false} />
365
+ * ```
366
+ */
367
+ export declare function Checkbox(_props: CheckboxProps): null;
368
+ /**
369
+ * An interactive dropdown / combo box (PDF AcroForm widget).
370
+ *
371
+ * @param props.name - Unique field name
372
+ * @param props.options - List of selectable options
373
+ * @param props.value - Pre-selected value
374
+ * @param props.width - Field width in points
375
+ * @param props.height - Field height in points. Default: 24
376
+ * @param props.readOnly - Prevent editing. Default: false
377
+ * @param props.fontSize - Font size in points. Default: 12
378
+ *
379
+ * @example
380
+ * ```tsx
381
+ * <Dropdown name="country" options={["US", "UK", "CA"]} width={200} />
382
+ * ```
383
+ */
384
+ export declare function Dropdown(_props: DropdownProps): null;
385
+ /**
386
+ * An interactive radio button (PDF AcroForm widget).
387
+ * Multiple RadioButtons with the same `name` form a mutually exclusive group.
388
+ *
389
+ * @param props.name - Group name (shared by all buttons in the group)
390
+ * @param props.value - The value this button represents
391
+ * @param props.checked - Whether selected. Default: false
392
+ * @param props.width - Display width in points. Default: 14
393
+ * @param props.height - Display height in points. Default: 14
394
+ * @param props.readOnly - Prevent editing. Default: false
395
+ *
396
+ * @example
397
+ * ```tsx
398
+ * <RadioButton name="plan" value="free" checked />
399
+ * <RadioButton name="plan" value="pro" />
400
+ * <RadioButton name="plan" value="team" />
401
+ * ```
402
+ */
403
+ export declare function RadioButton(_props: RadioButtonProps): null;
@@ -20,6 +20,8 @@
20
20
  export function Document(_props) {
21
21
  return null;
22
22
  }
23
+ /** Stable marker for cross-version identity checks (survives minification). */
24
+ Document.__formeType = 'Document';
23
25
  /**
24
26
  * A page boundary with explicit size and margin configuration.
25
27
  *
@@ -302,3 +304,149 @@ export function Watermark(_props) {
302
304
  export function PageBreak(_props) {
303
305
  return null;
304
306
  }
307
+ /**
308
+ * A bar chart rendered as native vector graphics in the PDF.
309
+ *
310
+ * @param props.data - Array of { label, value, color? } data points
311
+ * @param props.width - Chart width in points
312
+ * @param props.height - Chart height in points
313
+ * @param props.color - Default bar color (hex). Default: "#1a365d"
314
+ * @param props.showLabels - Show X-axis labels. Default: true
315
+ * @param props.showValues - Show value labels above bars. Default: false
316
+ * @param props.showGrid - Show horizontal grid lines. Default: false
317
+ * @param props.title - Chart title
318
+ */
319
+ export function BarChart(_props) {
320
+ return null;
321
+ }
322
+ /**
323
+ * A line chart rendered as native vector graphics in the PDF.
324
+ *
325
+ * @param props.series - Array of { name, data: number[], color? } series
326
+ * @param props.labels - X-axis labels
327
+ * @param props.width - Chart width in points
328
+ * @param props.height - Chart height in points
329
+ * @param props.showPoints - Show dots at data points. Default: false
330
+ * @param props.showGrid - Show horizontal grid lines. Default: false
331
+ * @param props.title - Chart title
332
+ */
333
+ export function LineChart(_props) {
334
+ return null;
335
+ }
336
+ /**
337
+ * A pie chart rendered as native vector graphics in the PDF.
338
+ *
339
+ * @param props.data - Array of { label, value, color? } data points
340
+ * @param props.width - Chart width in points
341
+ * @param props.height - Chart height in points
342
+ * @param props.donut - Render as donut chart. Default: false
343
+ * @param props.showLegend - Show legend. Default: false
344
+ * @param props.title - Chart title
345
+ */
346
+ export function PieChart(_props) {
347
+ return null;
348
+ }
349
+ /**
350
+ * An area chart rendered as native vector graphics in the PDF.
351
+ *
352
+ * @param props.series - Array of { name, data: number[], color? } series
353
+ * @param props.labels - X-axis labels
354
+ * @param props.width - Chart width in points
355
+ * @param props.height - Chart height in points
356
+ * @param props.showGrid - Show horizontal grid lines. Default: false
357
+ * @param props.title - Chart title
358
+ */
359
+ export function AreaChart(_props) {
360
+ return null;
361
+ }
362
+ /**
363
+ * A dot plot (scatter plot) rendered as native vector graphics in the PDF.
364
+ *
365
+ * @param props.groups - Array of { name, color?, data: [x, y][] } groups
366
+ * @param props.width - Chart width in points
367
+ * @param props.height - Chart height in points
368
+ * @param props.dotSize - Dot radius. Default: 4
369
+ * @param props.showLegend - Show legend. Default: false
370
+ */
371
+ export function DotPlot(_props) {
372
+ return null;
373
+ }
374
+ /**
375
+ * An interactive text input field (PDF AcroForm widget).
376
+ *
377
+ * @param props.name - Unique field name (PDF field identifier)
378
+ * @param props.width - Field width in points
379
+ * @param props.height - Field height in points. Default: 24
380
+ * @param props.value - Pre-filled value
381
+ * @param props.placeholder - Placeholder text shown when empty
382
+ * @param props.multiline - Allow multi-line input. Default: false
383
+ * @param props.password - Mask input. Default: false
384
+ * @param props.readOnly - Prevent editing. Default: false
385
+ * @param props.maxLength - Maximum character count
386
+ * @param props.fontSize - Font size in points. Default: 12
387
+ *
388
+ * @example
389
+ * ```tsx
390
+ * <TextField name="full_name" width={200} placeholder="Enter your name" />
391
+ * ```
392
+ */
393
+ export function TextField(_props) {
394
+ return null;
395
+ }
396
+ /**
397
+ * An interactive checkbox (PDF AcroForm widget).
398
+ *
399
+ * @param props.name - Unique field name
400
+ * @param props.checked - Whether checked. Default: false
401
+ * @param props.width - Display width in points. Default: 14
402
+ * @param props.height - Display height in points. Default: 14
403
+ * @param props.readOnly - Prevent editing. Default: false
404
+ *
405
+ * @example
406
+ * ```tsx
407
+ * <Checkbox name="agree_terms" checked={false} />
408
+ * ```
409
+ */
410
+ export function Checkbox(_props) {
411
+ return null;
412
+ }
413
+ /**
414
+ * An interactive dropdown / combo box (PDF AcroForm widget).
415
+ *
416
+ * @param props.name - Unique field name
417
+ * @param props.options - List of selectable options
418
+ * @param props.value - Pre-selected value
419
+ * @param props.width - Field width in points
420
+ * @param props.height - Field height in points. Default: 24
421
+ * @param props.readOnly - Prevent editing. Default: false
422
+ * @param props.fontSize - Font size in points. Default: 12
423
+ *
424
+ * @example
425
+ * ```tsx
426
+ * <Dropdown name="country" options={["US", "UK", "CA"]} width={200} />
427
+ * ```
428
+ */
429
+ export function Dropdown(_props) {
430
+ return null;
431
+ }
432
+ /**
433
+ * An interactive radio button (PDF AcroForm widget).
434
+ * Multiple RadioButtons with the same `name` form a mutually exclusive group.
435
+ *
436
+ * @param props.name - Group name (shared by all buttons in the group)
437
+ * @param props.value - The value this button represents
438
+ * @param props.checked - Whether selected. Default: false
439
+ * @param props.width - Display width in points. Default: 14
440
+ * @param props.height - Display height in points. Default: 14
441
+ * @param props.readOnly - Prevent editing. Default: false
442
+ *
443
+ * @example
444
+ * ```tsx
445
+ * <RadioButton name="plan" value="free" checked />
446
+ * <RadioButton name="plan" value="pro" />
447
+ * <RadioButton name="plan" value="team" />
448
+ * ```
449
+ */
450
+ export function RadioButton(_props) {
451
+ return null;
452
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
2
- export { BarChart, LineChart, PieChart } from './charts.js';
1
+ export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
2
+ export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
3
3
  export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
4
4
  export { StyleSheet } from './stylesheet.js';
5
5
  export { Font } from './font.js';
@@ -7,4 +7,4 @@ export type { FontRegistration } from './font.js';
7
7
  export { createDataProxy, isRefMarker, isEachMarker, isExprMarker } from './template-proxy.js';
8
8
  export { expr } from './expr.js';
9
9
  export { render, renderToObject } from './render.js';
10
- export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, BarChartProps, LineChartProps, PieChartProps, TextRun, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
10
+ export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps, TextRun, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Components
2
- export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
3
- export { BarChart, LineChart, PieChart } from './charts.js';
2
+ export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
3
+ export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
4
4
  // Serialization
5
5
  export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
6
6
  // StyleSheet
package/dist/serialize.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isValidElement, Children, Fragment } from 'react';
2
- import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
2
+ import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
3
3
  import { Font } from './font.js';
4
4
  import { isRefMarker, getRefPath, isEachMarker, getEachPath, getEachTemplate, isExprMarker, getExpr, REF_SENTINEL, REF_SENTINEL_END, } from './template-proxy.js';
5
5
  const VALID_PARENTS = {
@@ -40,6 +40,22 @@ function extractSourceLocation(element) {
40
40
  }
41
41
  return undefined;
42
42
  }
43
+ // ─── Version-independent type checks ─────────────────────────────────
44
+ /**
45
+ * Check if a component type is `Document`, even across different package versions.
46
+ * Uses `__formeType` marker first (survives minification), then falls back to
47
+ * `displayName` / `name` for legacy builds without the marker.
48
+ */
49
+ function isDocumentType(type) {
50
+ if (type === Document)
51
+ return true;
52
+ if (typeof type === 'function') {
53
+ return type.__formeType === 'Document'
54
+ || type.displayName === 'Document'
55
+ || type.name === 'Document';
56
+ }
57
+ return false;
58
+ }
43
59
  // ─── Component resolution ────────────────────────────────────────────
44
60
  /**
45
61
  * Resolve wrapper function components (e.g. `<MyReport data={...} />`) by
@@ -49,7 +65,7 @@ function extractSourceLocation(element) {
49
65
  */
50
66
  function resolveElement(element) {
51
67
  let resolved = element;
52
- for (let i = 0; i < 10 && typeof resolved.type === 'function' && resolved.type !== Document; i++) {
68
+ for (let i = 0; i < 10 && typeof resolved.type === 'function' && !isDocumentType(resolved.type); i++) {
53
69
  const result = resolved.type(resolved.props);
54
70
  if (!isValidElement(result))
55
71
  break;
@@ -64,7 +80,7 @@ function resolveElement(element) {
64
80
  */
65
81
  export function serialize(element) {
66
82
  element = resolveElement(element);
67
- if (element.type !== Document) {
83
+ if (!isDocumentType(element.type)) {
68
84
  throw new Error('Top-level element must be <Document>');
69
85
  }
70
86
  const props = element.props;
@@ -126,6 +142,10 @@ export function serialize(element) {
126
142
  result.tagged = props.tagged;
127
143
  if (props.pdfa !== undefined)
128
144
  result.pdfa = props.pdfa;
145
+ if (props.pdfUa)
146
+ result.pdfUa = true;
147
+ if (props.signature)
148
+ result.signature = props.signature;
129
149
  if (mergedFonts.length > 0) {
130
150
  result.fonts = mergedFonts;
131
151
  }
@@ -226,12 +246,39 @@ function serializeChild(child, parent = null) {
226
246
  if (element.type === Barcode) {
227
247
  return serializeBarcode(element);
228
248
  }
249
+ if (element.type === TextField) {
250
+ return serializeTextField(element);
251
+ }
252
+ if (element.type === Checkbox) {
253
+ return serializeCheckbox(element);
254
+ }
255
+ if (element.type === Dropdown) {
256
+ return serializeDropdown(element);
257
+ }
258
+ if (element.type === RadioButton) {
259
+ return serializeRadioButton(element);
260
+ }
229
261
  if (element.type === Canvas) {
230
262
  return serializeCanvas(element);
231
263
  }
232
264
  if (element.type === Watermark) {
233
265
  return serializeWatermark(element);
234
266
  }
267
+ if (element.type === BarChart) {
268
+ return serializeBarChart(element);
269
+ }
270
+ if (element.type === LineChart) {
271
+ return serializeLineChart(element);
272
+ }
273
+ if (element.type === PieChart) {
274
+ return serializePieChart(element);
275
+ }
276
+ if (element.type === AreaChart) {
277
+ return serializeAreaChart(element);
278
+ }
279
+ if (element.type === DotPlot) {
280
+ return serializeDotPlot(element);
281
+ }
235
282
  if (element.type === PageBreak) {
236
283
  return {
237
284
  kind: { type: 'PageBreak' },
@@ -244,7 +291,7 @@ function serializeChild(child, parent = null) {
244
291
  validateNesting('Page', parent);
245
292
  return serializePage(element);
246
293
  }
247
- if (element.type === Document) {
294
+ if (isDocumentType(element.type)) {
248
295
  // Nested Document — just serialize its children
249
296
  const props = element.props;
250
297
  const childElements = flattenChildren(props.children);
@@ -454,6 +501,86 @@ function serializeBarcode(element) {
454
501
  sourceLocation: extractSourceLocation(element),
455
502
  };
456
503
  }
504
+ function serializeTextField(element) {
505
+ const props = element.props;
506
+ const kind = {
507
+ type: 'TextField',
508
+ name: props.name,
509
+ width: props.width,
510
+ height: props.height ?? 24,
511
+ multiline: props.multiline ?? false,
512
+ password: props.password ?? false,
513
+ read_only: props.readOnly ?? false,
514
+ font_size: props.fontSize ?? 12,
515
+ };
516
+ if (props.value !== undefined)
517
+ kind.value = props.value;
518
+ if (props.placeholder !== undefined)
519
+ kind.placeholder = props.placeholder;
520
+ if (props.maxLength !== undefined)
521
+ kind.max_length = props.maxLength;
522
+ return {
523
+ kind,
524
+ style: mapStyle(props.style),
525
+ children: [],
526
+ sourceLocation: extractSourceLocation(element),
527
+ };
528
+ }
529
+ function serializeCheckbox(element) {
530
+ const props = element.props;
531
+ const kind = {
532
+ type: 'Checkbox',
533
+ name: props.name,
534
+ checked: props.checked ?? false,
535
+ width: props.width ?? 14,
536
+ height: props.height ?? 14,
537
+ read_only: props.readOnly ?? false,
538
+ };
539
+ return {
540
+ kind,
541
+ style: mapStyle(props.style),
542
+ children: [],
543
+ sourceLocation: extractSourceLocation(element),
544
+ };
545
+ }
546
+ function serializeDropdown(element) {
547
+ const props = element.props;
548
+ const kind = {
549
+ type: 'Dropdown',
550
+ name: props.name,
551
+ options: props.options,
552
+ width: props.width,
553
+ height: props.height ?? 24,
554
+ read_only: props.readOnly ?? false,
555
+ font_size: props.fontSize ?? 12,
556
+ };
557
+ if (props.value !== undefined)
558
+ kind.value = props.value;
559
+ return {
560
+ kind,
561
+ style: mapStyle(props.style),
562
+ children: [],
563
+ sourceLocation: extractSourceLocation(element),
564
+ };
565
+ }
566
+ function serializeRadioButton(element) {
567
+ const props = element.props;
568
+ const kind = {
569
+ type: 'RadioButton',
570
+ name: props.name,
571
+ value: props.value,
572
+ checked: props.checked ?? false,
573
+ width: props.width ?? 14,
574
+ height: props.height ?? 14,
575
+ read_only: props.readOnly ?? false,
576
+ };
577
+ return {
578
+ kind,
579
+ style: mapStyle(props.style),
580
+ children: [],
581
+ sourceLocation: extractSourceLocation(element),
582
+ };
583
+ }
457
584
  function serializeCanvas(element) {
458
585
  const props = element.props;
459
586
  const operations = [];
@@ -520,6 +647,115 @@ function serializeWatermark(element) {
520
647
  sourceLocation: extractSourceLocation(element),
521
648
  };
522
649
  }
650
+ function serializeBarChart(element) {
651
+ const props = element.props;
652
+ const kind = {
653
+ type: 'BarChart',
654
+ data: props.data.map(d => ({ label: d.label, value: d.value, color: d.color })),
655
+ width: props.width,
656
+ height: props.height,
657
+ show_labels: props.showLabels ?? true,
658
+ show_values: props.showValues ?? false,
659
+ show_grid: props.showGrid ?? false,
660
+ };
661
+ if (props.color !== undefined)
662
+ kind.color = props.color;
663
+ if (props.title !== undefined)
664
+ kind.title = props.title;
665
+ return {
666
+ kind,
667
+ style: mapStyle(props.style),
668
+ children: [],
669
+ sourceLocation: extractSourceLocation(element),
670
+ };
671
+ }
672
+ function serializeLineChart(element) {
673
+ const props = element.props;
674
+ const kind = {
675
+ type: 'LineChart',
676
+ series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
677
+ labels: props.labels,
678
+ width: props.width,
679
+ height: props.height,
680
+ show_points: props.showPoints ?? false,
681
+ show_grid: props.showGrid ?? false,
682
+ };
683
+ if (props.title !== undefined)
684
+ kind.title = props.title;
685
+ return {
686
+ kind,
687
+ style: mapStyle(props.style),
688
+ children: [],
689
+ sourceLocation: extractSourceLocation(element),
690
+ };
691
+ }
692
+ function serializePieChart(element) {
693
+ const props = element.props;
694
+ const kind = {
695
+ type: 'PieChart',
696
+ data: props.data.map(d => ({ label: d.label, value: d.value, color: d.color })),
697
+ width: props.width,
698
+ height: props.height,
699
+ donut: props.donut ?? false,
700
+ show_legend: props.showLegend ?? false,
701
+ };
702
+ if (props.title !== undefined)
703
+ kind.title = props.title;
704
+ return {
705
+ kind,
706
+ style: mapStyle(props.style),
707
+ children: [],
708
+ sourceLocation: extractSourceLocation(element),
709
+ };
710
+ }
711
+ function serializeAreaChart(element) {
712
+ const props = element.props;
713
+ const kind = {
714
+ type: 'AreaChart',
715
+ series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
716
+ labels: props.labels,
717
+ width: props.width,
718
+ height: props.height,
719
+ show_grid: props.showGrid ?? false,
720
+ };
721
+ if (props.title !== undefined)
722
+ kind.title = props.title;
723
+ return {
724
+ kind,
725
+ style: mapStyle(props.style),
726
+ children: [],
727
+ sourceLocation: extractSourceLocation(element),
728
+ };
729
+ }
730
+ function serializeDotPlot(element) {
731
+ const props = element.props;
732
+ const kind = {
733
+ type: 'DotPlot',
734
+ groups: props.groups.map(g => ({ name: g.name, color: g.color, data: g.data })),
735
+ width: props.width,
736
+ height: props.height,
737
+ show_legend: props.showLegend ?? false,
738
+ dot_size: props.dotSize ?? 4,
739
+ };
740
+ if (props.xMin !== undefined)
741
+ kind.x_min = props.xMin;
742
+ if (props.xMax !== undefined)
743
+ kind.x_max = props.xMax;
744
+ if (props.yMin !== undefined)
745
+ kind.y_min = props.yMin;
746
+ if (props.yMax !== undefined)
747
+ kind.y_max = props.yMax;
748
+ if (props.xLabel !== undefined)
749
+ kind.x_label = props.xLabel;
750
+ if (props.yLabel !== undefined)
751
+ kind.y_label = props.yLabel;
752
+ return {
753
+ kind,
754
+ style: mapStyle(props.style),
755
+ children: [],
756
+ sourceLocation: extractSourceLocation(element),
757
+ };
758
+ }
523
759
  // ─── Children helpers ────────────────────────────────────────────────
524
760
  function flattenChildren(children) {
525
761
  const result = [];
@@ -1160,7 +1396,7 @@ function mergeFonts(globalFonts, docFonts) {
1160
1396
  */
1161
1397
  export function serializeTemplate(element) {
1162
1398
  element = resolveElement(element);
1163
- if (element.type !== Document) {
1399
+ if (!isDocumentType(element.type)) {
1164
1400
  throw new Error('Top-level element must be <Document>');
1165
1401
  }
1166
1402
  const props = element.props;
@@ -1218,6 +1454,10 @@ export function serializeTemplate(element) {
1218
1454
  result.tagged = props.tagged;
1219
1455
  if (props.pdfa !== undefined)
1220
1456
  result.pdfa = props.pdfa;
1457
+ if (props.pdfUa)
1458
+ result.pdfUa = true;
1459
+ if (props.signature)
1460
+ result.signature = props.signature;
1221
1461
  if (mergedFonts.length > 0) {
1222
1462
  result.fonts = mergedFonts;
1223
1463
  }
@@ -1314,10 +1554,28 @@ function serializeTemplateChild(child, parent = null) {
1314
1554
  return serializeQrCode(element);
1315
1555
  if (element.type === Barcode)
1316
1556
  return serializeBarcode(element);
1557
+ if (element.type === TextField)
1558
+ return serializeTextField(element);
1559
+ if (element.type === Checkbox)
1560
+ return serializeCheckbox(element);
1561
+ if (element.type === Dropdown)
1562
+ return serializeDropdown(element);
1563
+ if (element.type === RadioButton)
1564
+ return serializeRadioButton(element);
1317
1565
  if (element.type === Canvas)
1318
1566
  return serializeCanvas(element);
1319
1567
  if (element.type === Watermark)
1320
1568
  return serializeWatermark(element);
1569
+ if (element.type === BarChart)
1570
+ return serializeBarChart(element);
1571
+ if (element.type === LineChart)
1572
+ return serializeLineChart(element);
1573
+ if (element.type === PieChart)
1574
+ return serializePieChart(element);
1575
+ if (element.type === AreaChart)
1576
+ return serializeAreaChart(element);
1577
+ if (element.type === DotPlot)
1578
+ return serializeDotPlot(element);
1321
1579
  if (element.type === PageBreak) {
1322
1580
  return { kind: { type: 'PageBreak' }, style: {}, children: [] };
1323
1581
  }
package/dist/types.d.ts CHANGED
@@ -140,6 +140,28 @@ export interface Style {
140
140
  minWidowLines?: number;
141
141
  minOrphanLines?: number;
142
142
  }
143
+ export interface SignatureConfig {
144
+ /** PEM-encoded X.509 certificate. */
145
+ certificatePem: string;
146
+ /** PEM-encoded RSA private key (PKCS#8). */
147
+ privateKeyPem: string;
148
+ /** Reason for signing (e.g. "Approved"). */
149
+ reason?: string;
150
+ /** Location of signing (e.g. "New York, NY"). */
151
+ location?: string;
152
+ /** Contact info for the signer. */
153
+ contact?: string;
154
+ /** Whether to show a visible signature annotation on the page. */
155
+ visible?: boolean;
156
+ /** X coordinate in points for visible signature. */
157
+ x?: number;
158
+ /** Y coordinate in points for visible signature. */
159
+ y?: number;
160
+ /** Width in points for visible signature. */
161
+ width?: number;
162
+ /** Height in points for visible signature. */
163
+ height?: number;
164
+ }
143
165
  export interface DocumentProps {
144
166
  title?: string;
145
167
  author?: string;
@@ -153,6 +175,10 @@ export interface DocumentProps {
153
175
  tagged?: boolean;
154
176
  /** PDF/A conformance level. "2a" requires tagging, "2b" is visual-only compliance. */
155
177
  pdfa?: '2a' | '2b';
178
+ /** When true, the PDF claims PDF/UA-1 conformance. Forces tagging. */
179
+ pdfUa?: boolean;
180
+ /** Digital signature configuration. Signs the PDF with an X.509 certificate. */
181
+ signature?: SignatureConfig;
156
182
  fonts?: FontRegistration[];
157
183
  children?: ReactNode;
158
184
  }
@@ -250,57 +276,178 @@ export interface BarcodeProps {
250
276
  color?: string;
251
277
  style?: Style;
252
278
  }
253
- /** Data point for bar and line charts. */
279
+ /** Data point for bar and pie charts. */
254
280
  export interface ChartDataPoint {
255
281
  label: string;
256
282
  value: number;
283
+ /** Optional per-item color (hex string). */
284
+ color?: string;
257
285
  }
258
- /** Data point for pie charts with per-slice color. */
286
+ /** @deprecated Use ChartDataPoint instead (color is now optional on ChartDataPoint). */
259
287
  export interface PieDataPoint {
260
288
  label: string;
261
289
  value: number;
262
290
  color: string;
263
291
  }
292
+ /** A data series for multi-series line and area charts. */
293
+ export interface ChartSeries {
294
+ name: string;
295
+ data: number[];
296
+ /** Optional series color (hex string). */
297
+ color?: string;
298
+ }
299
+ /** A group of (x, y) data points for dot plots. */
300
+ export interface DotPlotGroup {
301
+ name: string;
302
+ /** Optional group color (hex string). */
303
+ color?: string;
304
+ data: [number, number][];
305
+ }
264
306
  export interface BarChartProps {
265
307
  width: number;
266
308
  height: number;
267
309
  data: ChartDataPoint[];
268
310
  /** Bar color. Default: "#1a365d". */
269
311
  color?: string;
270
- /** Gap between bars in points. Default: 4. */
271
- barGap?: number;
312
+ /** Show X-axis labels below bars. Default: true. */
313
+ showLabels?: boolean;
272
314
  /** Show horizontal grid lines. Default: false. */
273
315
  showGrid?: boolean;
274
316
  /** Show value labels above bars. Default: false. */
275
317
  showValues?: boolean;
276
- /** Number of Y-axis ticks. Default: 5. */
277
- yAxisTicks?: number;
318
+ /** Chart title. */
319
+ title?: string;
278
320
  style?: Style;
279
321
  }
280
322
  export interface LineChartProps {
281
323
  width: number;
282
324
  height: number;
283
- data: ChartDataPoint[];
284
- /** Line color. Default: "#2b6cb0". */
285
- color?: string;
286
- /** Line stroke width. Default: 2. */
287
- strokeWidth?: number;
325
+ /** Multi-series data. */
326
+ series: ChartSeries[];
327
+ /** X-axis labels. */
328
+ labels: string[];
288
329
  /** Show dots at data points. Default: false. */
289
- showDots?: boolean;
330
+ showPoints?: boolean;
290
331
  /** Show horizontal grid lines. Default: false. */
291
332
  showGrid?: boolean;
292
- /** Show filled area under the line. Default: false. */
293
- showArea?: boolean;
333
+ /** Chart title. */
334
+ title?: string;
294
335
  style?: Style;
295
336
  }
296
337
  export interface PieChartProps {
297
338
  width: number;
298
339
  height: number;
299
- data: PieDataPoint[];
300
- /** Show labels outside slices. Default: false. */
301
- showLabels?: boolean;
302
- /** Inner radius for donut charts. Default: 0 (full pie). */
303
- innerRadius?: number;
340
+ data: ChartDataPoint[];
341
+ /** Render as donut chart. Default: false. */
342
+ donut?: boolean;
343
+ /** Show legend. Default: false. */
344
+ showLegend?: boolean;
345
+ /** Chart title. */
346
+ title?: string;
347
+ style?: Style;
348
+ }
349
+ export interface AreaChartProps {
350
+ width: number;
351
+ height: number;
352
+ /** Multi-series data. */
353
+ series: ChartSeries[];
354
+ /** X-axis labels. */
355
+ labels: string[];
356
+ /** Show horizontal grid lines. Default: false. */
357
+ showGrid?: boolean;
358
+ /** Chart title. */
359
+ title?: string;
360
+ style?: Style;
361
+ }
362
+ export interface DotPlotProps {
363
+ width: number;
364
+ height: number;
365
+ /** Groups of (x, y) data points. */
366
+ groups: DotPlotGroup[];
367
+ /** Minimum X value. Auto-computed if omitted. */
368
+ xMin?: number;
369
+ /** Maximum X value. Auto-computed if omitted. */
370
+ xMax?: number;
371
+ /** Minimum Y value. Auto-computed if omitted. */
372
+ yMin?: number;
373
+ /** Maximum Y value. Auto-computed if omitted. */
374
+ yMax?: number;
375
+ /** X-axis label. */
376
+ xLabel?: string;
377
+ /** Y-axis label. */
378
+ yLabel?: string;
379
+ /** Show legend. Default: false. */
380
+ showLegend?: boolean;
381
+ /** Dot radius in points. Default: 4. */
382
+ dotSize?: number;
383
+ style?: Style;
384
+ }
385
+ export interface TextFieldProps {
386
+ /** Unique field name (used as the PDF field identifier). */
387
+ name: string;
388
+ /** Pre-filled value. */
389
+ value?: string;
390
+ /** Placeholder text shown when empty. */
391
+ placeholder?: string;
392
+ /** Field width in points. */
393
+ width: number;
394
+ /** Field height in points. Default: 24. */
395
+ height?: number;
396
+ /** Allow multi-line input. Default: false. */
397
+ multiline?: boolean;
398
+ /** Mask input as password. Default: false. */
399
+ password?: boolean;
400
+ /** Prevent editing. Default: false. */
401
+ readOnly?: boolean;
402
+ /** Maximum number of characters. */
403
+ maxLength?: number;
404
+ /** Font size in points. Default: 12. */
405
+ fontSize?: number;
406
+ style?: Style;
407
+ }
408
+ export interface CheckboxProps {
409
+ /** Unique field name. */
410
+ name: string;
411
+ /** Whether the checkbox is checked. Default: false. */
412
+ checked?: boolean;
413
+ /** Display width in points. Default: 14. */
414
+ width?: number;
415
+ /** Display height in points. Default: 14. */
416
+ height?: number;
417
+ /** Prevent editing. Default: false. */
418
+ readOnly?: boolean;
419
+ style?: Style;
420
+ }
421
+ export interface DropdownProps {
422
+ /** Unique field name. */
423
+ name: string;
424
+ /** List of selectable options. */
425
+ options: string[];
426
+ /** Pre-selected value. */
427
+ value?: string;
428
+ /** Field width in points. */
429
+ width: number;
430
+ /** Field height in points. Default: 24. */
431
+ height?: number;
432
+ /** Prevent editing. Default: false. */
433
+ readOnly?: boolean;
434
+ /** Font size in points. Default: 12. */
435
+ fontSize?: number;
436
+ style?: Style;
437
+ }
438
+ export interface RadioButtonProps {
439
+ /** Field name — multiple RadioButtons with the same name form a group. */
440
+ name: string;
441
+ /** The value this button represents within the group. */
442
+ value: string;
443
+ /** Whether this button is selected. Default: false. */
444
+ checked?: boolean;
445
+ /** Display width in points. Default: 14. */
446
+ width?: number;
447
+ /** Display height in points. Default: 14. */
448
+ height?: number;
449
+ /** Prevent editing. Default: false. */
450
+ readOnly?: boolean;
304
451
  style?: Style;
305
452
  }
306
453
  export interface WatermarkProps {
@@ -444,6 +591,9 @@ export interface FormeDocument {
444
591
  fonts?: FormeFont[];
445
592
  tagged?: boolean;
446
593
  pdfa?: '2a' | '2b';
594
+ pdfUa?: boolean;
595
+ flattenForms?: boolean;
596
+ signature?: SignatureConfig;
447
597
  }
448
598
  export interface FormeMetadata {
449
599
  title?: string;
@@ -538,11 +688,95 @@ export type FormeNodeKind = {
538
688
  width: number;
539
689
  height: number;
540
690
  operations: CanvasOp[];
691
+ } | {
692
+ type: 'BarChart';
693
+ data: ChartDataPoint[];
694
+ width: number;
695
+ height: number;
696
+ color?: string;
697
+ show_labels: boolean;
698
+ show_values: boolean;
699
+ show_grid: boolean;
700
+ title?: string;
701
+ } | {
702
+ type: 'LineChart';
703
+ series: ChartSeries[];
704
+ labels: string[];
705
+ width: number;
706
+ height: number;
707
+ show_points: boolean;
708
+ show_grid: boolean;
709
+ title?: string;
710
+ } | {
711
+ type: 'PieChart';
712
+ data: ChartDataPoint[];
713
+ width: number;
714
+ height: number;
715
+ donut: boolean;
716
+ show_legend: boolean;
717
+ title?: string;
718
+ } | {
719
+ type: 'AreaChart';
720
+ series: ChartSeries[];
721
+ labels: string[];
722
+ width: number;
723
+ height: number;
724
+ show_grid: boolean;
725
+ title?: string;
726
+ } | {
727
+ type: 'DotPlot';
728
+ groups: DotPlotGroup[];
729
+ width: number;
730
+ height: number;
731
+ x_min?: number;
732
+ x_max?: number;
733
+ y_min?: number;
734
+ y_max?: number;
735
+ x_label?: string;
736
+ y_label?: string;
737
+ show_legend: boolean;
738
+ dot_size: number;
541
739
  } | {
542
740
  type: 'Watermark';
543
741
  text: string;
544
742
  font_size: number;
545
743
  angle: number;
744
+ } | {
745
+ type: 'TextField';
746
+ name: string;
747
+ width: number;
748
+ height: number;
749
+ value?: string;
750
+ placeholder?: string;
751
+ multiline: boolean;
752
+ password: boolean;
753
+ read_only: boolean;
754
+ max_length?: number;
755
+ font_size: number;
756
+ } | {
757
+ type: 'Checkbox';
758
+ name: string;
759
+ width: number;
760
+ height: number;
761
+ checked: boolean;
762
+ read_only: boolean;
763
+ } | {
764
+ type: 'Dropdown';
765
+ name: string;
766
+ options: string[];
767
+ width: number;
768
+ height: number;
769
+ value?: string;
770
+ read_only: boolean;
771
+ font_size: number;
772
+ } | {
773
+ type: 'RadioButton';
774
+ name: string;
775
+ value: string;
776
+ width: number;
777
+ height: number;
778
+ checked: boolean;
779
+ read_only: boolean;
546
780
  } | {
547
781
  type: 'PageBreak';
548
782
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/react",
3
- "version": "0.7.12",
3
+ "version": "0.8.0",
4
4
  "description": "JSX-to-JSON serializer for Forme PDF engine",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "scripts": {