flowpdf 0.0.0-stage → 1.0.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.
package/README.md CHANGED
@@ -1,3 +1,133 @@
1
- # Temporary Holding Version
1
+ # FlowPDF TypeScript / JavaScript SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Universal Document Engine and Fluent Report Builder SDK for **TypeScript**, **JavaScript**, **Node.js**, and **Bun**, powered by in-process **Rust Core**.
4
+
5
+ 🇩🇴 **Made in the Dominican Republic** — FlowPDF is an open-source Dominican library for report and PDF generation.
6
+
7
+ [![npm](https://img.shields.io/npm/v/flowpdf)](https://www.npmjs.com/package/flowpdf)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ---
11
+
12
+ ## ⚡ Highlights
13
+
14
+ - **Ultra-Fast In-Process Execution**: Generates complete PDFs in **~15ms - 35ms** with zero network latency.
15
+ - **Embedded Native Runtimes**: Precompiled `flowpdf_native.dll` (`win-x64`) and `libflowpdf_native.so` (`linux-x64`) included directly in the npm package.
16
+ - **Fluent Report Builder**: Declarative, composable, strictly-typed API for pages, tables, barcodes, QR codes, headers, and footers.
17
+ - **Full Unicode & Spanish Accents**: Native WinAnsi hex encoding for `á, é, í, ó, ú, ñ, Ñ, ¿, ¡, €`.
18
+ - **Bun & Node.js Support**: Instant native execution via Bun FFI or Node.js (`koffi`), plus `FlowPdfClient` for HTTP/REST server rendering.
19
+
20
+ ---
21
+
22
+ ## 📦 Installation
23
+
24
+ ```bash
25
+ # Using npm
26
+ npm install flowpdf
27
+
28
+ # Optional: For in-process native rendering in Node.js
29
+ npm install koffi
30
+
31
+ # Using yarn
32
+ yarn add flowpdf
33
+
34
+ # Using pnpm
35
+ pnpm add flowpdf
36
+
37
+ # Using Bun
38
+ bun add flowpdf
39
+ ```
40
+
41
+ ---
42
+
43
+ ## 🚀 Quickstart: In-Process Native PDF Generation
44
+
45
+ ```typescript
46
+ import { ReportDocument, FlowPdfEngine } from 'flowpdf';
47
+ import * as fs from 'fs';
48
+
49
+ // 1. Build document declaratively with Fluent API
50
+ const doc = ReportDocument.create(page => page.a4().portrait().margin(15))
51
+ .header(h => {
52
+ h.row(r => {
53
+ r.relativeItem(3, col => {
54
+ col.column(c => {
55
+ c.text('FLOWPDF ENTERPRISE', t => t.h2().bold().color('#1E40AF'));
56
+ c.text('Facturación Electrónica en Español: á é í ó ú ñ Ñ ¿ ¡ €', t => t.caption().color('#4B5563'));
57
+ });
58
+ });
59
+ r.relativeItem(1, col => {
60
+ col.qr('https://example.com/verify/FAC-2026-9901', 60);
61
+ });
62
+ });
63
+ })
64
+ .content(c => {
65
+ c.spacer(10);
66
+ c.table(t => {
67
+ t.column({ title: 'Código', field: 'sku', width: 70 });
68
+ t.column({ title: 'Descripción del Producto', field: 'description', flex: 3 });
69
+ t.column({ title: 'Cant.', field: 'qty', width: 50 });
70
+ t.column({ title: 'Precio Unit.', field: 'price', width: 90 });
71
+ t.column({ title: 'Total', field: 'total', width: 90 });
72
+ t.headerBackground('#1E40AF');
73
+ t.zebra(true);
74
+ t.data([
75
+ { sku: 'SRV-01', description: 'Licencia FlowPDF Enterprise', qty: 1, price: '€ 1,200.00', total: '€ 1,200.00' },
76
+ { sku: 'SUP-02', description: 'Soporte Técnico 24/7 Dedicado', qty: 2, price: '€ 150.00', total: '€ 300.00' },
77
+ ]);
78
+ });
79
+ c.spacer(15);
80
+ c.divider({ thickness: 1, color: '#CBD5E1' });
81
+ c.spacer(10);
82
+ c.row(r => {
83
+ r.relativeItem(1, col => {
84
+ col.barcode('FAC20269901', 'code128', { width: 160, height: 35 });
85
+ });
86
+ r.relativeItem(1, col => {
87
+ col.column(sub => {
88
+ sub.text('Subtotal: € 1,500.00', t => t.caption());
89
+ sub.text('IVA (18%): € 270.00', t => t.caption());
90
+ sub.text('Total: € 1,770.00', t => t.h2().bold().color('#16A34A'));
91
+ });
92
+ });
93
+ });
94
+ })
95
+ .footer(f => {
96
+ f.text('Generado in-process con FlowPDF TypeScript SDK & Rust Core', t => t.caption().align('center'));
97
+ });
98
+
99
+ // 2. Render directly in-process to PDF
100
+ const pdfBytes = doc.renderPdf();
101
+
102
+ fs.writeFileSync('factura_typescript.pdf', Buffer.from(pdfBytes));
103
+ console.log(`✅ PDF generado exitosamente (${pdfBytes.length} bytes) en ~25ms!`);
104
+ ```
105
+
106
+ ---
107
+
108
+ ## 🌐 Remote HTTP Rendering (Cloud / Server)
109
+
110
+ ```typescript
111
+ import { FlowPdfClient, ReportDocument } from 'flowpdf';
112
+ import * as fs from 'fs';
113
+
114
+ const client = new FlowPdfClient({
115
+ baseUrl: 'http://localhost:8000',
116
+ apiKey: 'your-api-key'
117
+ });
118
+
119
+ const doc = ReportDocument.create()
120
+ .content(c => c.text('Generado mediante worker asíncrono con Celery y Redis', t => t.h1()));
121
+
122
+ async function main() {
123
+ const pdfBuffer = await client.render(doc.build());
124
+ fs.writeFileSync('reporte_remoto.pdf', pdfBuffer);
125
+ }
126
+ main();
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 📄 License
132
+
133
+ MIT © 2026 Edwin Abreu, Felix R. Benzan & FlowPDF Contributors.
@@ -0,0 +1,147 @@
1
+ import { AnyComponent, BarcodeType, ChartType, ColumnComponent, DocumentDefinition, HorizontalAlignment, ImageFit, PageConfig, PageOrientation, PageSize, RowComponent, TableColumn, TableComponent, TextAlignment, TextComponent, TextStyle } from './types';
2
+ export declare class PageConfigBuilder {
3
+ private readonly config;
4
+ size(size: PageSize): this;
5
+ a4(): this;
6
+ letter(): this;
7
+ legal(): this;
8
+ a3(): this;
9
+ a5(): this;
10
+ orientation(orientation: PageOrientation): this;
11
+ portrait(): this;
12
+ landscape(): this;
13
+ margin(margin: number): this;
14
+ margins(top: number, right: number, bottom: number, left: number): this;
15
+ build(): PageConfig;
16
+ }
17
+ export declare class TextBuilder {
18
+ private readonly _text;
19
+ constructor(value: string);
20
+ style(style: TextStyle): this;
21
+ h1(): this;
22
+ h2(): this;
23
+ h3(): this;
24
+ body(): this;
25
+ caption(): this;
26
+ color(color: string): this;
27
+ fontSize(size: number): this;
28
+ align(alignment: TextAlignment): this;
29
+ alignLeft(): this;
30
+ alignCenter(): this;
31
+ alignRight(): this;
32
+ justify(): this;
33
+ bold(bold?: boolean): this;
34
+ italic(italic?: boolean): this;
35
+ underline(underline?: boolean): this;
36
+ strike(strike?: boolean): this;
37
+ font(font: string): this;
38
+ build(): TextComponent;
39
+ }
40
+ export declare class TableColumnsBuilder {
41
+ private readonly columns;
42
+ column(field: string, title: string, options?: Partial<Omit<TableColumn, 'field' | 'title'>>): this;
43
+ add(title: string, options?: Partial<Omit<TableColumn, 'title'>>): this;
44
+ build(): TableColumn[];
45
+ }
46
+ export declare class TableBuilder {
47
+ private readonly _table;
48
+ source(source: string): this;
49
+ data(data: Array<Record<string, any>>): this;
50
+ zebra(zebra?: boolean): this;
51
+ headerBackground(color: string): this;
52
+ border(color?: string, width?: number): this;
53
+ repeatHeader(repeat?: boolean): this;
54
+ /** Tamaño de letra de las celdas (pt). */
55
+ fontSize(size: number): this;
56
+ /** Relleno de cada celda (pt): horizontal y vertical. */
57
+ padding(horizontal: number, vertical: number): this;
58
+ /** Color del texto de la cabecera. */
59
+ headerColor(color: string): this;
60
+ /** Color del texto de las celdas. */
61
+ textColor(color: string): this;
62
+ /** Filas alternas con fondo de este color (activa zebra). */
63
+ zebraColor(color: string): this;
64
+ /**
65
+ * Agrupa las filas por un campo: cada vez que cambia su valor se intercala un título a todo el ancho
66
+ * (las filas deben venir ordenadas por ese campo).
67
+ */
68
+ groupBy(field: string, background?: string, color?: string): this;
69
+ columns(fn: (b: TableColumnsBuilder) => void): this;
70
+ build(): TableComponent;
71
+ }
72
+ export declare class SingleContainerBuilder {
73
+ private component?;
74
+ set(component: AnyComponent): this;
75
+ text(value: string, fn?: (t: TextBuilder) => void): this;
76
+ image(source: string, options?: {
77
+ width?: number;
78
+ height?: number;
79
+ fit?: ImageFit;
80
+ alignment?: HorizontalAlignment;
81
+ }): this;
82
+ qr(value: string, size?: number, fillColor?: string, backColor?: string): this;
83
+ barcode(value: string, barcodeType?: BarcodeType, width?: number, height?: number, includeText?: boolean): this;
84
+ pageNumber(format?: string, alignment?: HorizontalAlignment, style?: TextStyle): this;
85
+ column(fn: (c: ColumnBuilder) => void): this;
86
+ row(fn: (r: RowBuilder) => void): this;
87
+ table(fn: (t: TableBuilder) => void): this;
88
+ build(): AnyComponent;
89
+ }
90
+ export declare class ColumnBuilder {
91
+ private readonly _column;
92
+ spacing(spacing: number): this;
93
+ add(component: AnyComponent): this;
94
+ text(value: string, fn?: (t: TextBuilder) => void): this;
95
+ spacer(height?: number): this;
96
+ divider(color?: string, thickness?: number, margin?: number): this;
97
+ table(fn: (t: TableBuilder) => void): this;
98
+ row(fn: (r: RowBuilder) => void): this;
99
+ column(fn: (c: ColumnBuilder) => void): this;
100
+ image(source: string, options?: {
101
+ width?: number;
102
+ height?: number;
103
+ fit?: ImageFit;
104
+ alignment?: HorizontalAlignment;
105
+ }): this;
106
+ qr(value: string, size?: number): this;
107
+ barcode(value: string, barcodeType?: BarcodeType, width?: number, height?: number): this;
108
+ chart(type: ChartType, options: {
109
+ title?: string;
110
+ labels?: string[];
111
+ values?: number[];
112
+ series?: Array<{
113
+ name: string;
114
+ values: number[];
115
+ color?: string;
116
+ }>;
117
+ width?: number;
118
+ height?: number;
119
+ colors?: string[];
120
+ theme?: 'light' | 'dark';
121
+ donut?: boolean;
122
+ }): this;
123
+ build(): ColumnComponent;
124
+ }
125
+ export declare class RowBuilder {
126
+ private readonly _row;
127
+ spacing(spacing: number): this;
128
+ verticalAlignment(align: 'top' | 'middle' | 'bottom'): this;
129
+ constantItem(width: number, componentOrFn: AnyComponent | ((c: SingleContainerBuilder) => void)): this;
130
+ relativeItem(flex: number, componentOrFn: AnyComponent | ((c: SingleContainerBuilder) => void)): this;
131
+ build(): RowComponent;
132
+ }
133
+ export declare class ReportDocument {
134
+ private readonly doc;
135
+ static create(fn?: (b: PageConfigBuilder) => void): ReportDocument;
136
+ page(fn: (b: PageConfigBuilder) => void): this;
137
+ header(fn: (b: SingleContainerBuilder) => void): this;
138
+ content(fn: (b: ColumnBuilder) => void): this;
139
+ footer(fn: (b: SingleContainerBuilder) => void): this;
140
+ addFont(name: string, path?: string, data?: string): this;
141
+ static registerFont(name: string, fontBytes: Uint8Array | Buffer): boolean;
142
+ build(): DocumentDefinition;
143
+ renderPdf(data?: object | string): Uint8Array;
144
+ static extractText(pdfBytes: Uint8Array | Buffer): string;
145
+ static extractDocument(pdfBytes: Uint8Array | Buffer, options?: object): any;
146
+ }
147
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EAEZ,WAAW,EAEX,SAAS,EACT,eAAe,EAGf,kBAAkB,EAClB,mBAAmB,EAEnB,QAAQ,EACR,UAAU,EAEV,eAAe,EACf,QAAQ,EACR,YAAY,EAGZ,WAAW,EACX,cAAc,EACd,aAAa,EACb,aAAa,EACb,SAAS,EACZ,MAAM,SAAS,CAAC;AAEjB,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAK1B,EAAE,IAAI,IAAI;IACV,MAAM,IAAI,IAAI;IACd,KAAK,IAAI,IAAI;IACb,EAAE,IAAI,IAAI;IACV,EAAE,IAAI,IAAI;IAEV,WAAW,CAAC,WAAW,EAAE,eAAe,GAAG,IAAI;IAK/C,QAAQ,IAAI,IAAI;IAChB,SAAS,IAAI,IAAI;IAEjB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAA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,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU;IAK7C,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM;IAKzD,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG;CAI/E"}
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReportDocument = exports.RowBuilder = exports.ColumnBuilder = exports.SingleContainerBuilder = exports.TableBuilder = exports.TableColumnsBuilder = exports.TextBuilder = exports.PageConfigBuilder = void 0;
4
+ class PageConfigBuilder {
5
+ config = {};
6
+ size(size) {
7
+ this.config.size = size;
8
+ return this;
9
+ }
10
+ a4() { return this.size('A4'); }
11
+ letter() { return this.size('Letter'); }
12
+ legal() { return this.size('Legal'); }
13
+ a3() { return this.size('A3'); }
14
+ a5() { return this.size('A5'); }
15
+ orientation(orientation) {
16
+ this.config.orientation = orientation;
17
+ return this;
18
+ }
19
+ portrait() { return this.orientation('portrait'); }
20
+ landscape() { return this.orientation('landscape'); }
21
+ margin(margin) {
22
+ this.config.margin = margin;
23
+ return this;
24
+ }
25
+ margins(top, right, bottom, left) {
26
+ this.config.margin_top = top;
27
+ this.config.margin_right = right;
28
+ this.config.margin_bottom = bottom;
29
+ this.config.margin_left = left;
30
+ return this;
31
+ }
32
+ build() {
33
+ return this.config;
34
+ }
35
+ }
36
+ exports.PageConfigBuilder = PageConfigBuilder;
37
+ class TextBuilder {
38
+ _text;
39
+ constructor(value) {
40
+ this._text = { type: 'text', value };
41
+ }
42
+ style(style) { this._text.style = style; return this; }
43
+ h1() { return this.style('h1'); }
44
+ h2() { return this.style('h2'); }
45
+ h3() { return this.style('h3'); }
46
+ body() { return this.style('body'); }
47
+ caption() { return this.style('caption'); }
48
+ color(color) { this._text.color = color; return this; }
49
+ fontSize(size) { this._text.font_size = size; return this; }
50
+ align(alignment) { this._text.alignment = alignment; return this; }
51
+ alignLeft() { return this.align('left'); }
52
+ alignCenter() { return this.align('center'); }
53
+ alignRight() { return this.align('right'); }
54
+ justify() { return this.align('justify'); }
55
+ bold(bold = true) { this._text.bold = bold; return this; }
56
+ italic(italic = true) { this._text.italic = italic; return this; }
57
+ underline(underline = true) { this._text.underline = underline; return this; }
58
+ strike(strike = true) { this._text.strike = strike; return this; }
59
+ font(font) { this._text.font = font; return this; }
60
+ build() {
61
+ return this._text;
62
+ }
63
+ }
64
+ exports.TextBuilder = TextBuilder;
65
+ class TableColumnsBuilder {
66
+ columns = [];
67
+ column(field, title, options) {
68
+ this.columns.push({
69
+ field,
70
+ title,
71
+ flex: options?.flex ?? 1.0,
72
+ ...options
73
+ });
74
+ return this;
75
+ }
76
+ add(title, options) {
77
+ this.columns.push({
78
+ title,
79
+ flex: options?.flex ?? 1.0,
80
+ ...options
81
+ });
82
+ return this;
83
+ }
84
+ build() {
85
+ return this.columns;
86
+ }
87
+ }
88
+ exports.TableColumnsBuilder = TableColumnsBuilder;
89
+ class TableBuilder {
90
+ _table = {
91
+ type: 'table',
92
+ columns: []
93
+ };
94
+ source(source) {
95
+ this._table.source = source;
96
+ return this;
97
+ }
98
+ data(data) {
99
+ this._table.data = data;
100
+ return this;
101
+ }
102
+ zebra(zebra = true) {
103
+ this._table.zebra = zebra;
104
+ return this;
105
+ }
106
+ headerBackground(color) {
107
+ this._table.header_background = color;
108
+ return this;
109
+ }
110
+ border(color = '#E2E8F0', width = 0.5) {
111
+ this._table.border_color = color;
112
+ this._table.border_width = width;
113
+ return this;
114
+ }
115
+ repeatHeader(repeat = true) {
116
+ this._table.repeat_header = repeat;
117
+ return this;
118
+ }
119
+ /** Tamaño de letra de las celdas (pt). */
120
+ fontSize(size) {
121
+ this._table.font_size = size;
122
+ return this;
123
+ }
124
+ /** Relleno de cada celda (pt): horizontal y vertical. */
125
+ padding(horizontal, vertical) {
126
+ this._table.padding_x = horizontal;
127
+ this._table.padding_y = vertical;
128
+ return this;
129
+ }
130
+ /** Color del texto de la cabecera. */
131
+ headerColor(color) {
132
+ this._table.header_color = color;
133
+ return this;
134
+ }
135
+ /** Color del texto de las celdas. */
136
+ textColor(color) {
137
+ this._table.text_color = color;
138
+ return this;
139
+ }
140
+ /** Filas alternas con fondo de este color (activa zebra). */
141
+ zebraColor(color) {
142
+ this._table.zebra = true;
143
+ this._table.zebra_color = color;
144
+ return this;
145
+ }
146
+ /**
147
+ * Agrupa las filas por un campo: cada vez que cambia su valor se intercala un título a todo el ancho
148
+ * (las filas deben venir ordenadas por ese campo).
149
+ */
150
+ groupBy(field, background, color) {
151
+ this._table.group_by = field;
152
+ if (background !== undefined)
153
+ this._table.group_background = background;
154
+ if (color !== undefined)
155
+ this._table.group_color = color;
156
+ return this;
157
+ }
158
+ columns(fn) {
159
+ const b = new TableColumnsBuilder();
160
+ fn(b);
161
+ this._table.columns = b.build();
162
+ return this;
163
+ }
164
+ build() {
165
+ return this._table;
166
+ }
167
+ }
168
+ exports.TableBuilder = TableBuilder;
169
+ class SingleContainerBuilder {
170
+ component;
171
+ set(component) {
172
+ this.component = component;
173
+ return this;
174
+ }
175
+ text(value, fn) {
176
+ const b = new TextBuilder(value);
177
+ if (fn)
178
+ fn(b);
179
+ this.component = b.build();
180
+ return this;
181
+ }
182
+ image(source, options) {
183
+ this.component = { type: 'image', source, ...options };
184
+ return this;
185
+ }
186
+ qr(value, size = 80, fillColor, backColor) {
187
+ this.component = { type: 'qr', value, size, fill_color: fillColor, back_color: backColor };
188
+ return this;
189
+ }
190
+ barcode(value, barcodeType = 'code128', width = 180, height = 50, includeText = true) {
191
+ this.component = { type: 'barcode', value, barcode_type: barcodeType, width, height, include_text: includeText };
192
+ return this;
193
+ }
194
+ pageNumber(format = 'Página {page} de {total}', alignment = 'right', style) {
195
+ this.component = { type: 'page_number', format, alignment, style };
196
+ return this;
197
+ }
198
+ column(fn) {
199
+ const b = new ColumnBuilder();
200
+ fn(b);
201
+ this.component = b.build();
202
+ return this;
203
+ }
204
+ row(fn) {
205
+ const b = new RowBuilder();
206
+ fn(b);
207
+ this.component = b.build();
208
+ return this;
209
+ }
210
+ table(fn) {
211
+ const b = new TableBuilder();
212
+ fn(b);
213
+ this.component = b.build();
214
+ return this;
215
+ }
216
+ build() {
217
+ return this.component ?? { type: 'text', value: '' };
218
+ }
219
+ }
220
+ exports.SingleContainerBuilder = SingleContainerBuilder;
221
+ class ColumnBuilder {
222
+ _column = {
223
+ type: 'column',
224
+ items: [],
225
+ spacing: 0
226
+ };
227
+ spacing(spacing) {
228
+ this._column.spacing = spacing;
229
+ return this;
230
+ }
231
+ add(component) {
232
+ this._column.items.push(component);
233
+ return this;
234
+ }
235
+ text(value, fn) {
236
+ const b = new TextBuilder(value);
237
+ if (fn)
238
+ fn(b);
239
+ this._column.items.push(b.build());
240
+ return this;
241
+ }
242
+ spacer(height = 10) {
243
+ this._column.items.push({ type: 'spacer', height });
244
+ return this;
245
+ }
246
+ divider(color, thickness = 1.0, margin = 8.0) {
247
+ this._column.items.push({ type: 'divider', color, thickness, margin });
248
+ return this;
249
+ }
250
+ table(fn) {
251
+ const b = new TableBuilder();
252
+ fn(b);
253
+ this._column.items.push(b.build());
254
+ return this;
255
+ }
256
+ row(fn) {
257
+ const b = new RowBuilder();
258
+ fn(b);
259
+ this._column.items.push(b.build());
260
+ return this;
261
+ }
262
+ column(fn) {
263
+ const b = new ColumnBuilder();
264
+ fn(b);
265
+ this._column.items.push(b.build());
266
+ return this;
267
+ }
268
+ image(source, options) {
269
+ this._column.items.push({ type: 'image', source, ...options });
270
+ return this;
271
+ }
272
+ qr(value, size = 80) {
273
+ this._column.items.push({ type: 'qr', value, size });
274
+ return this;
275
+ }
276
+ barcode(value, barcodeType = 'code128', width = 180, height = 50) {
277
+ this._column.items.push({ type: 'barcode', value, barcode_type: barcodeType, width, height });
278
+ return this;
279
+ }
280
+ chart(type, options) {
281
+ this._column.items.push({
282
+ type: 'chart',
283
+ chart_type: type,
284
+ width: options.width ?? 400,
285
+ height: options.height ?? 200,
286
+ ...options
287
+ });
288
+ return this;
289
+ }
290
+ build() {
291
+ return this._column;
292
+ }
293
+ }
294
+ exports.ColumnBuilder = ColumnBuilder;
295
+ class RowBuilder {
296
+ _row = {
297
+ type: 'row',
298
+ items: [],
299
+ spacing: 0
300
+ };
301
+ spacing(spacing) {
302
+ this._row.spacing = spacing;
303
+ return this;
304
+ }
305
+ verticalAlignment(align) {
306
+ this._row.vertical_alignment = align;
307
+ return this;
308
+ }
309
+ constantItem(width, componentOrFn) {
310
+ if (typeof componentOrFn === 'function') {
311
+ const b = new SingleContainerBuilder();
312
+ componentOrFn(b);
313
+ this._row.items.push({ width, item: b.build() });
314
+ }
315
+ else {
316
+ this._row.items.push({ width, item: componentOrFn });
317
+ }
318
+ return this;
319
+ }
320
+ relativeItem(flex, componentOrFn) {
321
+ if (typeof componentOrFn === 'function') {
322
+ const b = new SingleContainerBuilder();
323
+ componentOrFn(b);
324
+ this._row.items.push({ flex, item: b.build() });
325
+ }
326
+ else {
327
+ this._row.items.push({ flex, item: componentOrFn });
328
+ }
329
+ return this;
330
+ }
331
+ build() {
332
+ return this._row;
333
+ }
334
+ }
335
+ exports.RowBuilder = RowBuilder;
336
+ class ReportDocument {
337
+ doc = {
338
+ content: []
339
+ };
340
+ static create(fn) {
341
+ const doc = new ReportDocument();
342
+ if (fn) {
343
+ const b = new PageConfigBuilder();
344
+ fn(b);
345
+ doc.doc.page = b.build();
346
+ }
347
+ return doc;
348
+ }
349
+ page(fn) {
350
+ const b = new PageConfigBuilder();
351
+ fn(b);
352
+ this.doc.page = b.build();
353
+ return this;
354
+ }
355
+ header(fn) {
356
+ const b = new SingleContainerBuilder();
357
+ fn(b);
358
+ this.doc.header = b.build();
359
+ return this;
360
+ }
361
+ content(fn) {
362
+ const b = new ColumnBuilder();
363
+ fn(b);
364
+ this.doc.content = b.build();
365
+ return this;
366
+ }
367
+ footer(fn) {
368
+ const b = new SingleContainerBuilder();
369
+ fn(b);
370
+ this.doc.footer = b.build();
371
+ return this;
372
+ }
373
+ addFont(name, path, data) {
374
+ if (!this.doc.fonts) {
375
+ this.doc.fonts = [];
376
+ }
377
+ this.doc.fonts.push({ name, path, data });
378
+ return this;
379
+ }
380
+ static registerFont(name, fontBytes) {
381
+ const { FlowPdfEngine } = require('./native');
382
+ return FlowPdfEngine.registerFont(name, fontBytes);
383
+ }
384
+ build() {
385
+ return this.doc;
386
+ }
387
+ renderPdf(data) {
388
+ const { FlowPdfEngine } = require('./native');
389
+ return FlowPdfEngine.renderPdf(this.build(), data);
390
+ }
391
+ static extractText(pdfBytes) {
392
+ const { FlowPdfEngine } = require('./native');
393
+ return FlowPdfEngine.extractText(pdfBytes);
394
+ }
395
+ static extractDocument(pdfBytes, options) {
396
+ const { FlowPdfEngine } = require('./native');
397
+ return FlowPdfEngine.extractDocument(pdfBytes, options);
398
+ }
399
+ }
400
+ exports.ReportDocument = ReportDocument;
401
+ //# sourceMappingURL=builder.js.map