@formepdf/react 0.8.2 → 0.9.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/README.md +24 -4
- package/dist/index.d.ts +1 -1
- package/dist/serialize.js +64 -6
- package/dist/types.d.ts +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,17 +33,37 @@ const pdfBytes = await renderDocument(doc);
|
|
|
33
33
|
|
|
34
34
|
## Components
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
### Layout
|
|
37
|
+
- `Document` - Root container (fonts, metadata, tagged PDF, PDF/A, signatures)
|
|
37
38
|
- `Page` - A page with size, margins, and orientation
|
|
38
39
|
- `View` - Flex container (like div)
|
|
39
40
|
- `Text` - Text content with font styling
|
|
40
|
-
- `Image` - JPEG and
|
|
41
|
-
- `Table`, `Row`, `Cell` - Tables with automatic header repetition
|
|
41
|
+
- `Image` - JPEG, PNG, and WebP images
|
|
42
42
|
- `Fixed` - Fixed headers and footers
|
|
43
43
|
- `PageBreak` - Explicit page break
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
### Tables
|
|
46
|
+
- `Table`, `Row`, `Cell` - Tables with automatic header repetition across pages
|
|
47
|
+
|
|
48
|
+
### Graphics
|
|
49
|
+
- `Svg` - SVG rendering via `content` string or JSX children (rect, circle, line, path, arc, opacity)
|
|
45
50
|
- `QrCode` - Vector QR codes
|
|
46
51
|
- `Barcode` - 1D barcodes (Code 128, Code 39, EAN-13, EAN-8, Codabar)
|
|
52
|
+
- `Canvas` - Arbitrary vector drawing via callback API
|
|
53
|
+
- `Watermark` - Rotated text behind page content
|
|
54
|
+
|
|
55
|
+
### Charts
|
|
56
|
+
- `BarChart` - Vertical bar charts with grouped series
|
|
57
|
+
- `LineChart` - Line charts with multiple series
|
|
58
|
+
- `PieChart` - Pie and donut charts
|
|
59
|
+
- `AreaChart` - Filled area charts
|
|
60
|
+
- `DotPlot` - Dot plot with grouped data points
|
|
61
|
+
|
|
62
|
+
### Form Fields
|
|
63
|
+
- `TextField` - Text input field
|
|
64
|
+
- `Checkbox` - Checkbox with label
|
|
65
|
+
- `Dropdown` - Select dropdown with options
|
|
66
|
+
- `RadioButton` - Radio button with group support
|
|
47
67
|
|
|
48
68
|
## Docs
|
|
49
69
|
|
package/dist/index.d.ts
CHANGED
|
@@ -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, 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';
|
|
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, CertificationConfig, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
package/dist/serialize.js
CHANGED
|
@@ -144,8 +144,13 @@ export function serialize(element) {
|
|
|
144
144
|
result.pdfa = props.pdfa;
|
|
145
145
|
if (props.pdfUa)
|
|
146
146
|
result.pdfUa = true;
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
const cert = props.certification ?? props.signature;
|
|
148
|
+
if (cert) {
|
|
149
|
+
if (props.signature && !props.certification) {
|
|
150
|
+
console.warn('[Forme] The `signature` prop is deprecated. Use `certification` instead.');
|
|
151
|
+
}
|
|
152
|
+
result.certification = cert;
|
|
153
|
+
}
|
|
149
154
|
if (mergedFonts.length > 0) {
|
|
150
155
|
result.fonts = mergedFonts;
|
|
151
156
|
}
|
|
@@ -172,7 +177,7 @@ function serializePage(element) {
|
|
|
172
177
|
const children = serializeChildren(childElements, 'Page');
|
|
173
178
|
return {
|
|
174
179
|
kind: { type: 'Page', config },
|
|
175
|
-
style: {},
|
|
180
|
+
style: props.style ? mapStyle(props.style) : {},
|
|
176
181
|
children,
|
|
177
182
|
sourceLocation: extractSourceLocation(element),
|
|
178
183
|
};
|
|
@@ -446,11 +451,12 @@ function serializeFixed(element) {
|
|
|
446
451
|
}
|
|
447
452
|
function serializeSvg(element) {
|
|
448
453
|
const props = element.props;
|
|
454
|
+
const content = props.content ?? (props.children ? svgChildrenToString(props.children) : '');
|
|
449
455
|
const kind = {
|
|
450
456
|
type: 'Svg',
|
|
451
457
|
width: props.width,
|
|
452
458
|
height: props.height,
|
|
453
|
-
content
|
|
459
|
+
content,
|
|
454
460
|
};
|
|
455
461
|
if (props.viewBox)
|
|
456
462
|
kind.view_box = props.viewBox;
|
|
@@ -466,6 +472,53 @@ function serializeSvg(element) {
|
|
|
466
472
|
node.alt = props.alt;
|
|
467
473
|
return node;
|
|
468
474
|
}
|
|
475
|
+
/** Map camelCase SVG prop names to kebab-case attribute names. */
|
|
476
|
+
const svgCamelToKebab = {
|
|
477
|
+
strokeWidth: 'stroke-width',
|
|
478
|
+
strokeLinecap: 'stroke-linecap',
|
|
479
|
+
strokeLinejoin: 'stroke-linejoin',
|
|
480
|
+
strokeMiterlimit: 'stroke-miterlimit',
|
|
481
|
+
strokeDasharray: 'stroke-dasharray',
|
|
482
|
+
strokeDashoffset: 'stroke-dashoffset',
|
|
483
|
+
strokeOpacity: 'stroke-opacity',
|
|
484
|
+
fillOpacity: 'fill-opacity',
|
|
485
|
+
fillRule: 'fill-rule',
|
|
486
|
+
clipPath: 'clip-path',
|
|
487
|
+
clipRule: 'clip-rule',
|
|
488
|
+
};
|
|
489
|
+
function escapeXmlAttr(s) {
|
|
490
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
491
|
+
}
|
|
492
|
+
function svgChildrenToString(children) {
|
|
493
|
+
let result = '';
|
|
494
|
+
Children.forEach(children, (child) => {
|
|
495
|
+
if (typeof child === 'string') {
|
|
496
|
+
result += child.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (!isValidElement(child))
|
|
500
|
+
return;
|
|
501
|
+
const tag = typeof child.type === 'string' ? child.type : null;
|
|
502
|
+
if (!tag)
|
|
503
|
+
return;
|
|
504
|
+
const { children: nested, ...attrs } = child.props;
|
|
505
|
+
const attrStr = Object.entries(attrs)
|
|
506
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
507
|
+
.map(([k, v]) => {
|
|
508
|
+
const name = svgCamelToKebab[k] ?? k;
|
|
509
|
+
return `${name}="${escapeXmlAttr(String(v))}"`;
|
|
510
|
+
})
|
|
511
|
+
.join(' ');
|
|
512
|
+
const open = attrStr ? `<${tag} ${attrStr}` : `<${tag}`;
|
|
513
|
+
if (nested) {
|
|
514
|
+
result += `${open}>${svgChildrenToString(nested)}</${tag}>`;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
result += `${open}/>`;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
return result;
|
|
521
|
+
}
|
|
469
522
|
function serializeQrCode(element) {
|
|
470
523
|
const props = element.props;
|
|
471
524
|
const kind = { type: 'QrCode', data: props.data };
|
|
@@ -1456,8 +1509,13 @@ export function serializeTemplate(element) {
|
|
|
1456
1509
|
result.pdfa = props.pdfa;
|
|
1457
1510
|
if (props.pdfUa)
|
|
1458
1511
|
result.pdfUa = true;
|
|
1459
|
-
|
|
1460
|
-
|
|
1512
|
+
const cert = props.certification ?? props.signature;
|
|
1513
|
+
if (cert) {
|
|
1514
|
+
if (props.signature && !props.certification) {
|
|
1515
|
+
console.warn('[Forme] The `signature` prop is deprecated. Use `certification` instead.');
|
|
1516
|
+
}
|
|
1517
|
+
result.certification = cert;
|
|
1518
|
+
}
|
|
1461
1519
|
if (mergedFonts.length > 0) {
|
|
1462
1520
|
result.fonts = mergedFonts;
|
|
1463
1521
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -140,16 +140,16 @@ export interface Style {
|
|
|
140
140
|
minWidowLines?: number;
|
|
141
141
|
minOrphanLines?: number;
|
|
142
142
|
}
|
|
143
|
-
export interface
|
|
143
|
+
export interface CertificationConfig {
|
|
144
144
|
/** PEM-encoded X.509 certificate. */
|
|
145
145
|
certificatePem: string;
|
|
146
146
|
/** PEM-encoded RSA private key (PKCS#8). */
|
|
147
147
|
privateKeyPem: string;
|
|
148
|
-
/** Reason for
|
|
148
|
+
/** Reason for certification (e.g. "Approved"). */
|
|
149
149
|
reason?: string;
|
|
150
|
-
/** Location of
|
|
150
|
+
/** Location of certification (e.g. "New York, NY"). */
|
|
151
151
|
location?: string;
|
|
152
|
-
/** Contact info for the
|
|
152
|
+
/** Contact info for the certifier. */
|
|
153
153
|
contact?: string;
|
|
154
154
|
/** Whether to show a visible signature annotation on the page. */
|
|
155
155
|
visible?: boolean;
|
|
@@ -162,6 +162,8 @@ export interface SignatureConfig {
|
|
|
162
162
|
/** Height in points for visible signature. */
|
|
163
163
|
height?: number;
|
|
164
164
|
}
|
|
165
|
+
/** @deprecated Use CertificationConfig */
|
|
166
|
+
export type SignatureConfig = CertificationConfig;
|
|
165
167
|
export interface DocumentProps {
|
|
166
168
|
title?: string;
|
|
167
169
|
author?: string;
|
|
@@ -177,8 +179,10 @@ export interface DocumentProps {
|
|
|
177
179
|
pdfa?: '2a' | '2b';
|
|
178
180
|
/** When true, the PDF claims PDF/UA-1 conformance. Forces tagging. */
|
|
179
181
|
pdfUa?: boolean;
|
|
180
|
-
/** Digital
|
|
181
|
-
|
|
182
|
+
/** Digital certification configuration. Certifies the PDF with an X.509 certificate. */
|
|
183
|
+
certification?: CertificationConfig;
|
|
184
|
+
/** @deprecated Use certification */
|
|
185
|
+
signature?: CertificationConfig;
|
|
182
186
|
fonts?: FontRegistration[];
|
|
183
187
|
children?: ReactNode;
|
|
184
188
|
}
|
|
@@ -246,12 +250,15 @@ export interface SvgProps {
|
|
|
246
250
|
width: number;
|
|
247
251
|
height: number;
|
|
248
252
|
viewBox?: string;
|
|
249
|
-
content
|
|
253
|
+
/** SVG markup string (inner content). If children are provided, this takes priority. */
|
|
254
|
+
content?: string;
|
|
250
255
|
style?: Style;
|
|
251
256
|
/** Optional hyperlink URL — makes the SVG clickable. */
|
|
252
257
|
href?: string;
|
|
253
258
|
/** Alt text for accessibility. */
|
|
254
259
|
alt?: string;
|
|
260
|
+
/** JSX SVG children (path, rect, circle, g, etc.). Alternative to the content prop. */
|
|
261
|
+
children?: ReactNode;
|
|
255
262
|
}
|
|
256
263
|
export interface QrCodeProps {
|
|
257
264
|
/** Data to encode (URL, text, etc.) */
|
|
@@ -593,7 +600,7 @@ export interface FormeDocument {
|
|
|
593
600
|
pdfa?: '2a' | '2b';
|
|
594
601
|
pdfUa?: boolean;
|
|
595
602
|
flattenForms?: boolean;
|
|
596
|
-
|
|
603
|
+
certification?: CertificationConfig;
|
|
597
604
|
}
|
|
598
605
|
export interface FormeMetadata {
|
|
599
606
|
title?: string;
|