@formepdf/react 0.6.2 → 0.7.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.
@@ -8,11 +8,12 @@ import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableP
8
8
  * @param props.author - PDF metadata author
9
9
  * @param props.subject - PDF metadata subject
10
10
  * @param props.creator - PDF metadata creator application
11
+ * @param props.style - Default style applied globally (fontFamily, fontSize, color, etc.)
11
12
  * @param props.children - Page or content elements
12
13
  *
13
14
  * @example
14
15
  * ```tsx
15
- * <Document title="Invoice" author="Acme Corp">
16
+ * <Document title="Invoice" style={{ fontFamily: 'Inter', fontSize: 12 }}>
16
17
  * <Text>Hello World</Text>
17
18
  * </Document>
18
19
  * ```
@@ -75,19 +76,22 @@ export declare function View(_props: ViewProps): null;
75
76
  */
76
77
  export declare function Text(_props: TextProps): null;
77
78
  /**
78
- * An image element. Supports JPEG and PNG via base64 data URIs or file paths.
79
+ * An image element. Supports JPEG, PNG, and WebP via data URIs or file paths.
79
80
  *
80
81
  * If only `width` or `height` is specified, the other dimension is calculated
81
82
  * from the image's aspect ratio.
82
83
  *
83
- * @param props.src - Image source: base64 data URI (`data:image/png;base64,...`) or file path
84
+ * @param props.src - Image source:
85
+ * - `data:image/png;base64,...` (inline base64 data URI)
86
+ * - `./assets/logo.png` (relative to the template file)
87
+ * - `/absolute/path/logo.png` (absolute file path)
84
88
  * @param props.width - Display width in points
85
89
  * @param props.height - Display height in points
86
90
  * @param props.style - Additional style properties
87
91
  *
88
92
  * @example
89
93
  * ```tsx
90
- * <Image src="data:image/png;base64,..." width={200} />
94
+ * <Image src="./assets/logo.png" width={200} />
91
95
  * ```
92
96
  */
93
97
  export declare function Image(_props: ImageProps): null;
@@ -7,11 +7,12 @@
7
7
  * @param props.author - PDF metadata author
8
8
  * @param props.subject - PDF metadata subject
9
9
  * @param props.creator - PDF metadata creator application
10
+ * @param props.style - Default style applied globally (fontFamily, fontSize, color, etc.)
10
11
  * @param props.children - Page or content elements
11
12
  *
12
13
  * @example
13
14
  * ```tsx
14
- * <Document title="Invoice" author="Acme Corp">
15
+ * <Document title="Invoice" style={{ fontFamily: 'Inter', fontSize: 12 }}>
15
16
  * <Text>Hello World</Text>
16
17
  * </Document>
17
18
  * ```
@@ -82,19 +83,22 @@ export function Text(_props) {
82
83
  return null;
83
84
  }
84
85
  /**
85
- * An image element. Supports JPEG and PNG via base64 data URIs or file paths.
86
+ * An image element. Supports JPEG, PNG, and WebP via data URIs or file paths.
86
87
  *
87
88
  * If only `width` or `height` is specified, the other dimension is calculated
88
89
  * from the image's aspect ratio.
89
90
  *
90
- * @param props.src - Image source: base64 data URI (`data:image/png;base64,...`) or file path
91
+ * @param props.src - Image source:
92
+ * - `data:image/png;base64,...` (inline base64 data URI)
93
+ * - `./assets/logo.png` (relative to the template file)
94
+ * - `/absolute/path/logo.png` (absolute file path)
91
95
  * @param props.width - Display width in points
92
96
  * @param props.height - Display height in points
93
97
  * @param props.style - Additional style properties
94
98
  *
95
99
  * @example
96
100
  * ```tsx
97
- * <Image src="data:image/png;base64,..." width={200} />
101
+ * <Image src="./assets/logo.png" width={200} />
98
102
  * ```
99
103
  */
100
104
  export function Image(_props) {
package/dist/serialize.js CHANGED
@@ -102,6 +102,8 @@ export function serialize(element) {
102
102
  wrap: true,
103
103
  },
104
104
  };
105
+ if (props.style)
106
+ result.defaultStyle = mapStyle(props.style);
105
107
  if (props.tagged !== undefined)
106
108
  result.tagged = props.tagged;
107
109
  if (props.pdfa !== undefined)
@@ -431,6 +433,11 @@ function serializeCanvas(element) {
431
433
  arc(cx, cy, r, startAngle, endAngle, counterclockwise = false) {
432
434
  operations.push({ op: 'Arc', cx, cy, r, start_angle: startAngle, end_angle: endAngle, counterclockwise });
433
435
  },
436
+ line(x1, y1, x2, y2) {
437
+ operations.push({ op: 'MoveTo', x: x1, y: y1 });
438
+ operations.push({ op: 'LineTo', x: x2, y: y2 });
439
+ operations.push({ op: 'Stroke' });
440
+ },
434
441
  stroke() { operations.push({ op: 'Stroke' }); },
435
442
  fill() { operations.push({ op: 'Fill' }); },
436
443
  fillAndStroke() { operations.push({ op: 'FillAndStroke' }); },
@@ -1146,6 +1153,8 @@ export function serializeTemplate(element) {
1146
1153
  wrap: true,
1147
1154
  },
1148
1155
  };
1156
+ if (props.style)
1157
+ result.defaultStyle = mapStyle(props.style);
1149
1158
  if (props.tagged !== undefined)
1150
1159
  result.tagged = props.tagged;
1151
1160
  if (props.pdfa !== undefined)
package/dist/types.d.ts CHANGED
@@ -147,6 +147,8 @@ export interface DocumentProps {
147
147
  creator?: string;
148
148
  /** Document language (BCP 47 tag, e.g. "en-US"). Emitted as /Lang in the PDF Catalog. */
149
149
  lang?: string;
150
+ /** Default style applied to the entire document. Sets global fontFamily, fontSize, color, etc. */
151
+ style?: Style;
150
152
  /** Whether to produce a tagged (accessible) PDF with structure tree. */
151
153
  tagged?: boolean;
152
154
  /** PDF/A conformance level. "2a" requires tagging, "2b" is visual-only compliance. */
@@ -309,6 +311,8 @@ export interface CanvasContext {
309
311
  circle(cx: number, cy: number, r: number): void;
310
312
  ellipse(cx: number, cy: number, rx: number, ry: number): void;
311
313
  arc(cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
314
+ /** Convenience: draws a stroked line from (x1,y1) to (x2,y2). */
315
+ line(x1: number, y1: number, x2: number, y2: number): void;
312
316
  stroke(): void;
313
317
  fill(): void;
314
318
  fillAndStroke(): void;
@@ -422,6 +426,7 @@ export interface FormeDocument {
422
426
  children: FormeNode[];
423
427
  metadata: FormeMetadata;
424
428
  defaultPage: FormePageConfig;
429
+ defaultStyle?: FormeStyle;
425
430
  fonts?: FormeFont[];
426
431
  tagged?: boolean;
427
432
  pdfa?: '2a' | '2b';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/react",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "description": "JSX-to-JSON serializer for Forme PDF engine",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",