@formepdf/react 0.7.6 → 0.7.8
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 +2 -0
- package/dist/components.d.ts +17 -1
- package/dist/components.js +18 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/serialize.js +26 -1
- package/dist/types.d.ts +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,8 @@ const pdfBytes = await renderDocument(doc);
|
|
|
42
42
|
- `Fixed` - Fixed headers and footers
|
|
43
43
|
- `PageBreak` - Explicit page break
|
|
44
44
|
- `Svg` - Basic SVG rendering
|
|
45
|
+
- `QrCode` - Vector QR codes
|
|
46
|
+
- `Barcode` - 1D barcodes (Code 128, Code 39, EAN-13, EAN-8, Codabar)
|
|
45
47
|
|
|
46
48
|
## Docs
|
|
47
49
|
|
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, CanvasProps, WatermarkProps } from './types.js';
|
|
1
|
+
import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Root document container. Must be the top-level element in every Forme document.
|
|
4
4
|
*
|
|
@@ -205,6 +205,22 @@ export declare function Svg(_props: SvgProps): null;
|
|
|
205
205
|
* ```
|
|
206
206
|
*/
|
|
207
207
|
export declare function QrCode(_props: QrCodeProps): null;
|
|
208
|
+
/**
|
|
209
|
+
* A 1D barcode rendered as crisp vector rectangles in the PDF.
|
|
210
|
+
*
|
|
211
|
+
* @param props.data - The data to encode
|
|
212
|
+
* @param props.format - Barcode format: "Code128" (default), "Code39", "EAN13", "EAN8", "Codabar"
|
|
213
|
+
* @param props.width - Width in points. Defaults to available width.
|
|
214
|
+
* @param props.height - Height in points. Default: 60.
|
|
215
|
+
* @param props.color - Bar color. Default: black.
|
|
216
|
+
* @param props.style - Style properties for the barcode container.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* <Barcode data="ABC-123" format="Code128" width={200} height={50} />
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export declare function Barcode(_props: BarcodeProps): null;
|
|
208
224
|
/**
|
|
209
225
|
* A canvas drawing primitive for arbitrary vector graphics.
|
|
210
226
|
*
|
package/dist/components.js
CHANGED
|
@@ -226,6 +226,24 @@ export function Svg(_props) {
|
|
|
226
226
|
export function QrCode(_props) {
|
|
227
227
|
return null;
|
|
228
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* A 1D barcode rendered as crisp vector rectangles in the PDF.
|
|
231
|
+
*
|
|
232
|
+
* @param props.data - The data to encode
|
|
233
|
+
* @param props.format - Barcode format: "Code128" (default), "Code39", "EAN13", "EAN8", "Codabar"
|
|
234
|
+
* @param props.width - Width in points. Defaults to available width.
|
|
235
|
+
* @param props.height - Height in points. Default: 60.
|
|
236
|
+
* @param props.color - Bar color. Default: black.
|
|
237
|
+
* @param props.style - Style properties for the barcode container.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```tsx
|
|
241
|
+
* <Barcode data="ABC-123" format="Code128" width={200} height={50} />
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export function Barcode(_props) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
229
247
|
/**
|
|
230
248
|
* A canvas drawing primitive for arbitrary vector graphics.
|
|
231
249
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Canvas, Watermark, PageBreak } from './components.js';
|
|
1
|
+
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
|
|
2
2
|
export { BarChart, LineChart, PieChart } from './charts.js';
|
|
3
3
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
|
4
4
|
export { StyleSheet } from './stylesheet.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, 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, BarChartProps, LineChartProps, PieChartProps, TextRun, 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,5 +1,5 @@
|
|
|
1
1
|
// Components
|
|
2
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Canvas, Watermark, PageBreak } from './components.js';
|
|
2
|
+
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
|
|
3
3
|
export { BarChart, LineChart, PieChart } from './charts.js';
|
|
4
4
|
// Serialization
|
|
5
5
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
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, Canvas, Watermark, PageBreak } from './components.js';
|
|
2
|
+
import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } 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 = {
|
|
@@ -205,6 +205,9 @@ function serializeChild(child, parent = null) {
|
|
|
205
205
|
if (element.type === QrCode) {
|
|
206
206
|
return serializeQrCode(element);
|
|
207
207
|
}
|
|
208
|
+
if (element.type === Barcode) {
|
|
209
|
+
return serializeBarcode(element);
|
|
210
|
+
}
|
|
208
211
|
if (element.type === Canvas) {
|
|
209
212
|
return serializeCanvas(element);
|
|
210
213
|
}
|
|
@@ -413,6 +416,26 @@ function serializeQrCode(element) {
|
|
|
413
416
|
sourceLocation: extractSourceLocation(element),
|
|
414
417
|
};
|
|
415
418
|
}
|
|
419
|
+
function serializeBarcode(element) {
|
|
420
|
+
const props = element.props;
|
|
421
|
+
const kind = {
|
|
422
|
+
type: 'Barcode',
|
|
423
|
+
data: props.data,
|
|
424
|
+
format: props.format ?? 'Code128',
|
|
425
|
+
height: props.height ?? 60,
|
|
426
|
+
};
|
|
427
|
+
if (props.width !== undefined)
|
|
428
|
+
kind.width = props.width;
|
|
429
|
+
const style = mapStyle(props.style);
|
|
430
|
+
if (props.color)
|
|
431
|
+
style.color = parseColor(props.color);
|
|
432
|
+
return {
|
|
433
|
+
kind,
|
|
434
|
+
style,
|
|
435
|
+
children: [],
|
|
436
|
+
sourceLocation: extractSourceLocation(element),
|
|
437
|
+
};
|
|
438
|
+
}
|
|
416
439
|
function serializeCanvas(element) {
|
|
417
440
|
const props = element.props;
|
|
418
441
|
const operations = [];
|
|
@@ -1253,6 +1276,8 @@ function serializeTemplateChild(child, parent = null) {
|
|
|
1253
1276
|
return serializeSvg(element);
|
|
1254
1277
|
if (element.type === QrCode)
|
|
1255
1278
|
return serializeQrCode(element);
|
|
1279
|
+
if (element.type === Barcode)
|
|
1280
|
+
return serializeBarcode(element);
|
|
1256
1281
|
if (element.type === Canvas)
|
|
1257
1282
|
return serializeCanvas(element);
|
|
1258
1283
|
if (element.type === Watermark)
|
package/dist/types.d.ts
CHANGED
|
@@ -236,6 +236,20 @@ export interface QrCodeProps {
|
|
|
236
236
|
color?: string;
|
|
237
237
|
style?: Style;
|
|
238
238
|
}
|
|
239
|
+
export type BarcodeFormat = 'Code128' | 'Code39' | 'EAN13' | 'EAN8' | 'Codabar';
|
|
240
|
+
export interface BarcodeProps {
|
|
241
|
+
/** The data to encode. */
|
|
242
|
+
data: string;
|
|
243
|
+
/** Barcode format. Default: "Code128". */
|
|
244
|
+
format?: BarcodeFormat;
|
|
245
|
+
/** Width in points. Defaults to available width. */
|
|
246
|
+
width?: number;
|
|
247
|
+
/** Height in points. Default: 60. */
|
|
248
|
+
height?: number;
|
|
249
|
+
/** Bar color. Default: black. */
|
|
250
|
+
color?: string;
|
|
251
|
+
style?: Style;
|
|
252
|
+
}
|
|
239
253
|
/** Data point for bar and line charts. */
|
|
240
254
|
export interface ChartDataPoint {
|
|
241
255
|
label: string;
|
|
@@ -506,6 +520,12 @@ export type FormeNodeKind = {
|
|
|
506
520
|
type: 'QrCode';
|
|
507
521
|
data: string;
|
|
508
522
|
size?: number;
|
|
523
|
+
} | {
|
|
524
|
+
type: 'Barcode';
|
|
525
|
+
data: string;
|
|
526
|
+
format: BarcodeFormat;
|
|
527
|
+
width?: number;
|
|
528
|
+
height: number;
|
|
509
529
|
} | {
|
|
510
530
|
type: 'Canvas';
|
|
511
531
|
width: number;
|