@formepdf/react 0.8.2 → 0.8.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 CHANGED
@@ -33,17 +33,37 @@ const pdfBytes = await renderDocument(doc);
33
33
 
34
34
  ## Components
35
35
 
36
- - `Document` - Root container
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 PNG images
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
- - `Svg` - Basic SVG rendering
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/serialize.js CHANGED
@@ -172,7 +172,7 @@ function serializePage(element) {
172
172
  const children = serializeChildren(childElements, 'Page');
173
173
  return {
174
174
  kind: { type: 'Page', config },
175
- style: {},
175
+ style: props.style ? mapStyle(props.style) : {},
176
176
  children,
177
177
  sourceLocation: extractSourceLocation(element),
178
178
  };
@@ -446,11 +446,12 @@ function serializeFixed(element) {
446
446
  }
447
447
  function serializeSvg(element) {
448
448
  const props = element.props;
449
+ const content = props.content ?? (props.children ? svgChildrenToString(props.children) : '');
449
450
  const kind = {
450
451
  type: 'Svg',
451
452
  width: props.width,
452
453
  height: props.height,
453
- content: props.content,
454
+ content,
454
455
  };
455
456
  if (props.viewBox)
456
457
  kind.view_box = props.viewBox;
@@ -466,6 +467,53 @@ function serializeSvg(element) {
466
467
  node.alt = props.alt;
467
468
  return node;
468
469
  }
470
+ /** Map camelCase SVG prop names to kebab-case attribute names. */
471
+ const svgCamelToKebab = {
472
+ strokeWidth: 'stroke-width',
473
+ strokeLinecap: 'stroke-linecap',
474
+ strokeLinejoin: 'stroke-linejoin',
475
+ strokeMiterlimit: 'stroke-miterlimit',
476
+ strokeDasharray: 'stroke-dasharray',
477
+ strokeDashoffset: 'stroke-dashoffset',
478
+ strokeOpacity: 'stroke-opacity',
479
+ fillOpacity: 'fill-opacity',
480
+ fillRule: 'fill-rule',
481
+ clipPath: 'clip-path',
482
+ clipRule: 'clip-rule',
483
+ };
484
+ function escapeXmlAttr(s) {
485
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
486
+ }
487
+ function svgChildrenToString(children) {
488
+ let result = '';
489
+ Children.forEach(children, (child) => {
490
+ if (typeof child === 'string') {
491
+ result += child.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
492
+ return;
493
+ }
494
+ if (!isValidElement(child))
495
+ return;
496
+ const tag = typeof child.type === 'string' ? child.type : null;
497
+ if (!tag)
498
+ return;
499
+ const { children: nested, ...attrs } = child.props;
500
+ const attrStr = Object.entries(attrs)
501
+ .filter(([, v]) => v !== undefined && v !== null)
502
+ .map(([k, v]) => {
503
+ const name = svgCamelToKebab[k] ?? k;
504
+ return `${name}="${escapeXmlAttr(String(v))}"`;
505
+ })
506
+ .join(' ');
507
+ const open = attrStr ? `<${tag} ${attrStr}` : `<${tag}`;
508
+ if (nested) {
509
+ result += `${open}>${svgChildrenToString(nested)}</${tag}>`;
510
+ }
511
+ else {
512
+ result += `${open}/>`;
513
+ }
514
+ });
515
+ return result;
516
+ }
469
517
  function serializeQrCode(element) {
470
518
  const props = element.props;
471
519
  const kind = { type: 'QrCode', data: props.data };
package/dist/types.d.ts CHANGED
@@ -246,12 +246,15 @@ export interface SvgProps {
246
246
  width: number;
247
247
  height: number;
248
248
  viewBox?: string;
249
- content: string;
249
+ /** SVG markup string (inner content). If children are provided, this takes priority. */
250
+ content?: string;
250
251
  style?: Style;
251
252
  /** Optional hyperlink URL — makes the SVG clickable. */
252
253
  href?: string;
253
254
  /** Alt text for accessibility. */
254
255
  alt?: string;
256
+ /** JSX SVG children (path, rect, circle, g, etc.). Alternative to the content prop. */
257
+ children?: ReactNode;
255
258
  }
256
259
  export interface QrCodeProps {
257
260
  /** Data to encode (URL, text, etc.) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/react",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "JSX-to-JSON serializer for Forme PDF engine",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",