pdf-gen-js 1.0.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 +179 -0
- package/bin/cli.js +74 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -0
- package/dist/generator.d.ts +44 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +144 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/certificate.d.ts +17 -0
- package/dist/templates/certificate.d.ts.map +1 -0
- package/dist/templates/certificate.js +78 -0
- package/dist/templates/certificate.js.map +1 -0
- package/dist/templates/invoice.d.ts +31 -0
- package/dist/templates/invoice.d.ts.map +1 -0
- package/dist/templates/invoice.js +115 -0
- package/dist/templates/invoice.js.map +1 -0
- package/dist/templates/receipt.d.ts +26 -0
- package/dist/templates/receipt.d.ts.map +1 -0
- package/dist/templates/receipt.js +93 -0
- package/dist/templates/receipt.js.map +1 -0
- package/dist/theme.d.ts +21 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +26 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/image.d.ts +32 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +98 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/logo.d.ts +15 -0
- package/dist/utils/logo.d.ts.map +1 -0
- package/dist/utils/logo.js +16 -0
- package/dist/utils/logo.js.map +1 -0
- package/dist/utils/table.d.ts +23 -0
- package/dist/utils/table.d.ts.map +1 -0
- package/dist/utils/table.js +83 -0
- package/dist/utils/table.js.map +1 -0
- package/dist/utils/validate.d.ts +6 -0
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +35 -0
- package/dist/utils/validate.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# pdf-gen-js
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript implementation of [universal-pdf-gen](https://github.com/Ahmedz182/universal-pdf-gen) — professional invoice, receipt, and certificate PDFs with a programmatic API. Built on [PDFKit](http://pdfkit.org/).
|
|
4
|
+
|
|
5
|
+
See the [root README](../../README.md) for full screenshots and a side-by-side comparison with the Python package.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
npm run build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
(Once published: `npm install pdf-gen-js`.)
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
const { PDFGenerator, Templates } = require('pdf-gen-js');
|
|
20
|
+
|
|
21
|
+
const pdf = new PDFGenerator({ pageSize: 'A4', orientation: 'portrait' });
|
|
22
|
+
Templates.register(pdf);
|
|
23
|
+
|
|
24
|
+
await pdf.useTemplate('invoice', {
|
|
25
|
+
invoiceNumber: 'INV-001',
|
|
26
|
+
date: '2024-01-15',
|
|
27
|
+
companyName: 'ACME Corp',
|
|
28
|
+
clientName: 'John Doe',
|
|
29
|
+
items: [{ description: 'Service', quantity: 1, unitPrice: 100 }],
|
|
30
|
+
subtotal: 100,
|
|
31
|
+
total: 100
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await pdf.generate('invoice.pdf');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> `useTemplate` is `async` — image embedding (WEBP normalization, SVG parsing) may need to do async work — so always `await` it.
|
|
38
|
+
|
|
39
|
+
TypeScript types are included — `InvoiceData`, `ReceiptData`, `CertificateData`, `PDFConfig`, and `Theme` are all exported.
|
|
40
|
+
|
|
41
|
+
## Templates
|
|
42
|
+
|
|
43
|
+
See the [templates reference in the root README](../../README.md#templates-reference) for the full field list. All keys are `camelCase` in JS/TS.
|
|
44
|
+
|
|
45
|
+
### Invoice
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { InvoiceData } from 'pdf-gen-js';
|
|
49
|
+
|
|
50
|
+
const data: InvoiceData = {
|
|
51
|
+
invoiceNumber: 'INV-001',
|
|
52
|
+
date: '2024-01-15',
|
|
53
|
+
dueDate: '2024-02-14',
|
|
54
|
+
status: 'DUE',
|
|
55
|
+
companyName: 'ACME Corp',
|
|
56
|
+
companyAddress: 'Optional address',
|
|
57
|
+
clientName: 'John Doe',
|
|
58
|
+
clientAddress: 'Optional address',
|
|
59
|
+
items: [{ description: 'Service', quantity: 1, unitPrice: 100 }],
|
|
60
|
+
subtotal: 100,
|
|
61
|
+
tax: 10,
|
|
62
|
+
taxRate: 10,
|
|
63
|
+
total: 110,
|
|
64
|
+
notes: 'Optional notes',
|
|
65
|
+
paymentTerms: 'Net 30'
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Receipt
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const data = {
|
|
73
|
+
storeName: 'Store Name',
|
|
74
|
+
storeAddress: 'Optional address',
|
|
75
|
+
receiptNumber: 'RCP-001',
|
|
76
|
+
dateTime: '2024-01-15 10:30',
|
|
77
|
+
items: [{ name: 'Item', quantity: 1, price: 25.0 }],
|
|
78
|
+
subtotal: 25.0,
|
|
79
|
+
tax: 2.5,
|
|
80
|
+
total: 27.5,
|
|
81
|
+
paymentMethod: 'Cash',
|
|
82
|
+
thankYouMessage: 'Thank you for your purchase!'
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Certificate
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const data = {
|
|
90
|
+
title: 'Certificate of Achievement',
|
|
91
|
+
recipientName: 'John Doe',
|
|
92
|
+
achievementText: 'For successfully completing the course',
|
|
93
|
+
issuerName: 'Institution Name',
|
|
94
|
+
issueDate: '2024-01-15',
|
|
95
|
+
certificationNumber: 'CERT-001',
|
|
96
|
+
borderColor: '#1a5f7a'
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Logos (PNG, JPG, WEBP, SVG)
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
await pdf.useTemplate('invoice', {
|
|
104
|
+
logo: 'logo.svg', // or .png / .jpg / .webp, a Buffer, or { src, width, height }
|
|
105
|
+
// ...
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
WEBP is transparently normalized to PNG via `sharp` (PDFKit has no native WEBP support). SVG is drawn as true vector paths via `svg-to-pdfkit` — not rasterized — so it stays crisp. See [Logos & Images in the root README](../../README.md#logos--images) for the full picture, including a side-by-side comparison of all four formats.
|
|
110
|
+
|
|
111
|
+
## CLI Usage
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
node bin/cli.js invoice output.pdf --config invoice-data.json
|
|
115
|
+
node bin/cli.js invoice output.pdf --config invoice-data.json --logo logo.svg
|
|
116
|
+
node bin/cli.js receipt receipt.pdf --config receipt-data.json --page-size A4
|
|
117
|
+
node bin/cli.js certificate cert.pdf --config cert-data.json --orientation portrait
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Or, once installed as a package, simply `pdf-gen invoice output.pdf --config invoice-data.json`.
|
|
121
|
+
|
|
122
|
+
## Programmatic (non-template) API
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
const pdf = new PDFGenerator({ pageSize: 'A4', orientation: 'portrait' });
|
|
126
|
+
|
|
127
|
+
// Text
|
|
128
|
+
pdf.addText('Hello World', { align: 'left' });
|
|
129
|
+
|
|
130
|
+
// Line
|
|
131
|
+
pdf.addLine(100, 200, 300, 200);
|
|
132
|
+
|
|
133
|
+
// Table with automatic word-wrap and pagination
|
|
134
|
+
pdf.addTable(
|
|
135
|
+
[
|
|
136
|
+
{ header: 'Name', key: 'name' },
|
|
137
|
+
{ header: 'Score', key: 'score', align: 'right' }
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
{ name: 'Alice', score: '95' },
|
|
141
|
+
{ name: 'Bob', score: '88' }
|
|
142
|
+
]
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// New page
|
|
146
|
+
pdf.addPage();
|
|
147
|
+
|
|
148
|
+
// Image (PNG, JPG, WEBP, or SVG — file path or Buffer)
|
|
149
|
+
await pdf.addImage('logo.svg', 100, 50, 80, 80); // x, y, width, height
|
|
150
|
+
|
|
151
|
+
// Write to disk, or get raw bytes for an HTTP response
|
|
152
|
+
await pdf.generate('output.pdf');
|
|
153
|
+
const buffer = await pdf.generateBuffer();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Theming
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const pdf = new PDFGenerator({
|
|
160
|
+
theme: { primary: '#7a2048', accent: '#d4af37' }
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Page numbers
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
pdf.addPageNumbers(); // call once, right before generate() — stamps "Page N of M"
|
|
168
|
+
await pdf.generate('output.pdf');
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Running tests
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
npm test # builds TypeScript, then runs the test suite
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { PDFGenerator, Templates } = require('../dist/index');
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
|
|
8
|
+
function flag(name) {
|
|
9
|
+
const idx = args.indexOf(name);
|
|
10
|
+
return idx === -1 ? null : args[idx + 1];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
14
|
+
console.log(`
|
|
15
|
+
PDF Generator CLI
|
|
16
|
+
|
|
17
|
+
Usage: pdf-gen <template> <output> [options]
|
|
18
|
+
|
|
19
|
+
Templates:
|
|
20
|
+
invoice - Generate an invoice PDF
|
|
21
|
+
receipt - Generate a receipt PDF
|
|
22
|
+
certificate - Generate a certificate PDF
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--config <file> JSON file with template data
|
|
26
|
+
--page-size <size> Page size: A4 (default), Letter, A3, A5
|
|
27
|
+
--orientation <o> portrait (default) or landscape
|
|
28
|
+
--logo <file> Logo image to embed (png, jpg, webp, or svg) —
|
|
29
|
+
overrides/sets the "logo" field from --config
|
|
30
|
+
--help, -h Show this help message
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
pdf-gen invoice invoice.pdf --config invoice-data.json
|
|
34
|
+
pdf-gen invoice invoice.pdf --config invoice-data.json --logo logo.svg
|
|
35
|
+
pdf-gen certificate cert.pdf --config cert-data.json --page-size A4
|
|
36
|
+
`);
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const template = args[0];
|
|
41
|
+
const output = args[1];
|
|
42
|
+
const configFile = flag('--config');
|
|
43
|
+
const pageSize = flag('--page-size') || 'A4';
|
|
44
|
+
const orientation = flag('--orientation') || 'portrait';
|
|
45
|
+
const logoFile = flag('--logo');
|
|
46
|
+
|
|
47
|
+
if (!template || !output) {
|
|
48
|
+
console.error('Error: template and output arguments are required');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!configFile) {
|
|
53
|
+
console.error('Error: --config file is required');
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function main() {
|
|
58
|
+
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
|
59
|
+
if (logoFile) {
|
|
60
|
+
config.logo = logoFile;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pdf = new PDFGenerator({ pageSize, orientation });
|
|
64
|
+
Templates.register(pdf);
|
|
65
|
+
|
|
66
|
+
await pdf.useTemplate(template, config);
|
|
67
|
+
await pdf.generate(output);
|
|
68
|
+
console.log(`✓ PDF generated: ${output}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
main().catch((error) => {
|
|
72
|
+
console.error(`Error: ${error.message}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Theme } from './theme';
|
|
2
|
+
export interface PDFConfig {
|
|
3
|
+
pageSize: 'A4' | 'Letter' | 'A3' | 'A5';
|
|
4
|
+
orientation: 'portrait' | 'landscape';
|
|
5
|
+
margins: {
|
|
6
|
+
top: number;
|
|
7
|
+
bottom: number;
|
|
8
|
+
left: number;
|
|
9
|
+
right: number;
|
|
10
|
+
};
|
|
11
|
+
defaultFont?: string;
|
|
12
|
+
fontSize?: number;
|
|
13
|
+
lineHeight?: number;
|
|
14
|
+
theme?: Partial<Theme>;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_CONFIG: PDFConfig;
|
|
17
|
+
export declare const PAGE_SIZES: Record<string, [number, number]>;
|
|
18
|
+
/** Resolves the final [width, height] in points for a config, accounting for orientation. */
|
|
19
|
+
export declare function resolvePageDimensions(config: PDFConfig): [number, number];
|
|
20
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;IACxC,WAAW,EAAE,UAAU,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACxB;AAED,eAAO,MAAM,cAAc,EAAE,SAO5B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAKvD,CAAC;AAEF,6FAA6F;AAC7F,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAGzE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PAGE_SIZES = exports.DEFAULT_CONFIG = void 0;
|
|
4
|
+
exports.resolvePageDimensions = resolvePageDimensions;
|
|
5
|
+
exports.DEFAULT_CONFIG = {
|
|
6
|
+
pageSize: 'A4',
|
|
7
|
+
orientation: 'portrait',
|
|
8
|
+
margins: { top: 40, bottom: 40, left: 40, right: 40 },
|
|
9
|
+
defaultFont: 'Helvetica',
|
|
10
|
+
fontSize: 12,
|
|
11
|
+
lineHeight: 1.5
|
|
12
|
+
};
|
|
13
|
+
exports.PAGE_SIZES = {
|
|
14
|
+
A4: [595.28, 841.89],
|
|
15
|
+
Letter: [612, 792],
|
|
16
|
+
A3: [841.89, 1190.55],
|
|
17
|
+
A5: [419.53, 595.28]
|
|
18
|
+
};
|
|
19
|
+
/** Resolves the final [width, height] in points for a config, accounting for orientation. */
|
|
20
|
+
function resolvePageDimensions(config) {
|
|
21
|
+
const [width, height] = exports.PAGE_SIZES[config.pageSize] || exports.PAGE_SIZES.A4;
|
|
22
|
+
return config.orientation === 'landscape' ? [height, width] : [width, height];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AA6BA,sDAGC;AApBY,QAAA,cAAc,GAAc;IACvC,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,UAAU;IACvB,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IACrD,WAAW,EAAE,WAAW;IACxB,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,GAAG;CAChB,CAAC;AAEW,QAAA,UAAU,GAAqC;IAC1D,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,6FAA6F;AAC7F,SAAgB,qBAAqB,CAAC,MAAiB;IACrD,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,kBAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,kBAAU,CAAC,EAAE,CAAC;IACrE,OAAO,MAAM,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PDFConfig } from './config';
|
|
2
|
+
import { Theme } from './theme';
|
|
3
|
+
import { PDFDoc } from './types';
|
|
4
|
+
import { TableColumn, TableOptions } from './utils/table';
|
|
5
|
+
export interface TemplateData {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export type TemplateRenderer = (pdf: PDFDoc, config: PDFConfig, data: TemplateData, theme: Theme) => void | Promise<void>;
|
|
9
|
+
export type { TableColumn, TableOptions };
|
|
10
|
+
export declare class PDFGenerator {
|
|
11
|
+
private doc;
|
|
12
|
+
private config;
|
|
13
|
+
private theme;
|
|
14
|
+
private templates;
|
|
15
|
+
constructor(config?: Partial<PDFConfig>);
|
|
16
|
+
registerTemplate(name: string, renderer: TemplateRenderer): void;
|
|
17
|
+
useTemplate(templateName: string, data: TemplateData): Promise<this>;
|
|
18
|
+
/** Usable content width between the left and right margins. */
|
|
19
|
+
get contentWidth(): number;
|
|
20
|
+
get contentHeight(): number;
|
|
21
|
+
addText(text: string, options?: any): this;
|
|
22
|
+
/** Embeds PNG, JPEG, GIF, WEBP, or SVG (file path or Buffer) at the given top-left position. */
|
|
23
|
+
addImage(source: string | Buffer, x: number, y: number, width?: number, height?: number): Promise<this>;
|
|
24
|
+
/**
|
|
25
|
+
* Renders a table with word-wrapped cells, an optional striped body, and automatic
|
|
26
|
+
* page breaks when the table would run past the bottom margin.
|
|
27
|
+
*/
|
|
28
|
+
addTable(columns: TableColumn[], rows: Array<Record<string, any> | any[]>, options?: TableOptions): this;
|
|
29
|
+
/** Adds a new page if the given height would not fit before the bottom margin. */
|
|
30
|
+
ensureSpace(height: number): this;
|
|
31
|
+
addPage(): this;
|
|
32
|
+
addLine(x1: number, y1: number, x2: number, y2: number, color?: string, width?: number): this;
|
|
33
|
+
addRect(x: number, y: number, width: number, height: number, fillColor?: string, radius?: number): this;
|
|
34
|
+
setFont(fontName: string, size: number): this;
|
|
35
|
+
moveDown(amount?: number): this;
|
|
36
|
+
/** Stamps "Page N of M" at the bottom-right of every page. Call once, right before generate(). */
|
|
37
|
+
addPageNumbers(): this;
|
|
38
|
+
generate(filename: string): Promise<void>;
|
|
39
|
+
/** Resolves with the raw PDF bytes instead of writing to disk — useful for HTTP responses. */
|
|
40
|
+
generateBuffer(): Promise<Buffer>;
|
|
41
|
+
getDocument(): PDFDoc;
|
|
42
|
+
getTheme(): Theme;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAc,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAClD,OAAO,EAAa,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGrE,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,KAAK,KACT,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;AAE1C,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,SAAS,CAA4C;gBAEjD,MAAM,GAAE,OAAO,CAAC,SAAS,CAAM;IAc3C,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAI1D,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,+DAA+D;I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CAAC,MAAM,CAAC;IAUvC,WAAW,IAAI,MAAM;IAIrB,QAAQ,IAAI,KAAK;CAGlB"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PDFGenerator = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const theme_1 = require("./theme");
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const table_1 = require("./utils/table");
|
|
12
|
+
const image_1 = require("./utils/image");
|
|
13
|
+
class PDFGenerator {
|
|
14
|
+
constructor(config = {}) {
|
|
15
|
+
this.templates = new Map();
|
|
16
|
+
this.config = { ...config_1.DEFAULT_CONFIG, ...config, margins: { ...config_1.DEFAULT_CONFIG.margins, ...config.margins } };
|
|
17
|
+
this.theme = (0, theme_1.mergeTheme)(this.config.theme);
|
|
18
|
+
const [width, height] = (0, config_1.resolvePageDimensions)(this.config);
|
|
19
|
+
this.doc = new types_1.PDFDocumentCtor({
|
|
20
|
+
size: [width, height],
|
|
21
|
+
margins: this.config.margins,
|
|
22
|
+
bufferPages: true,
|
|
23
|
+
info: { Producer: 'universal-pdf-gen', Creator: 'universal-pdf-gen' }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
registerTemplate(name, renderer) {
|
|
27
|
+
this.templates.set(name, renderer);
|
|
28
|
+
}
|
|
29
|
+
async useTemplate(templateName, data) {
|
|
30
|
+
const template = this.templates.get(templateName);
|
|
31
|
+
if (!template) {
|
|
32
|
+
throw new Error(`Template "${templateName}" not found. Available: ${Array.from(this.templates.keys()).join(', ') || '(none registered)'}`);
|
|
33
|
+
}
|
|
34
|
+
await template(this.doc, this.config, data, this.theme);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** Usable content width between the left and right margins. */
|
|
38
|
+
get contentWidth() {
|
|
39
|
+
return this.doc.page.width - this.config.margins.left - this.config.margins.right;
|
|
40
|
+
}
|
|
41
|
+
get contentHeight() {
|
|
42
|
+
return this.doc.page.height - this.config.margins.top - this.config.margins.bottom;
|
|
43
|
+
}
|
|
44
|
+
addText(text, options = {}) {
|
|
45
|
+
this.doc.text(text, options);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/** Embeds PNG, JPEG, GIF, WEBP, or SVG (file path or Buffer) at the given top-left position. */
|
|
49
|
+
async addImage(source, x, y, width, height) {
|
|
50
|
+
await (0, image_1.embedImage)(this.doc, source, x, y, { width, height });
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Renders a table with word-wrapped cells, an optional striped body, and automatic
|
|
55
|
+
* page breaks when the table would run past the bottom margin.
|
|
56
|
+
*/
|
|
57
|
+
addTable(columns, rows, options = {}) {
|
|
58
|
+
(0, table_1.drawTable)(this.doc, this.config, this.theme, columns, rows, options);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/** Adds a new page if the given height would not fit before the bottom margin. */
|
|
62
|
+
ensureSpace(height) {
|
|
63
|
+
if (this.doc.y + height > this.doc.page.height - this.config.margins.bottom) {
|
|
64
|
+
this.doc.addPage();
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
addPage() {
|
|
69
|
+
this.doc.addPage();
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
addLine(x1, y1, x2, y2, color = this.theme.border, width = 1) {
|
|
73
|
+
this.doc.strokeColor(color).lineWidth(width).moveTo(x1, y1).lineTo(x2, y2).stroke();
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
addRect(x, y, width, height, fillColor, radius = 0) {
|
|
77
|
+
if (radius > 0) {
|
|
78
|
+
this.doc.roundedRect(x, y, width, height, radius);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.doc.rect(x, y, width, height);
|
|
82
|
+
}
|
|
83
|
+
if (fillColor) {
|
|
84
|
+
this.doc.fill(fillColor);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.doc.stroke();
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
setFont(fontName, size) {
|
|
92
|
+
this.doc.font(fontName).fontSize(size);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
moveDown(amount = 1) {
|
|
96
|
+
this.doc.moveDown(amount);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/** Stamps "Page N of M" at the bottom-right of every page. Call once, right before generate(). */
|
|
100
|
+
addPageNumbers() {
|
|
101
|
+
const { doc, theme, config } = this;
|
|
102
|
+
const range = doc.bufferedPageRange();
|
|
103
|
+
for (let i = range.start; i < range.start + range.count; i++) {
|
|
104
|
+
doc.switchToPage(i);
|
|
105
|
+
const pageNum = i - range.start + 1;
|
|
106
|
+
doc
|
|
107
|
+
.font('Helvetica')
|
|
108
|
+
.fontSize(8)
|
|
109
|
+
.fillColor(theme.muted)
|
|
110
|
+
.text(`Page ${pageNum} of ${range.count}`, 0, doc.page.height - config.margins.bottom + 10, {
|
|
111
|
+
width: doc.page.width,
|
|
112
|
+
align: 'center'
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
async generate(filename) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const stream = fs_1.default.createWriteStream(filename);
|
|
120
|
+
this.doc.pipe(stream);
|
|
121
|
+
this.doc.end();
|
|
122
|
+
stream.on('finish', () => resolve());
|
|
123
|
+
stream.on('error', reject);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** Resolves with the raw PDF bytes instead of writing to disk — useful for HTTP responses. */
|
|
127
|
+
async generateBuffer() {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
const chunks = [];
|
|
130
|
+
this.doc.on('data', (chunk) => chunks.push(chunk));
|
|
131
|
+
this.doc.on('end', () => resolve(Buffer.concat(chunks)));
|
|
132
|
+
this.doc.on('error', reject);
|
|
133
|
+
this.doc.end();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getDocument() {
|
|
137
|
+
return this.doc;
|
|
138
|
+
}
|
|
139
|
+
getTheme() {
|
|
140
|
+
return this.theme;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.PDFGenerator = PDFGenerator;
|
|
144
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,qCAA4E;AAC5E,mCAA4C;AAC5C,mCAAkD;AAClD,yCAAqE;AACrE,yCAA2C;AAe3C,MAAa,YAAY;IAMvB,YAAY,SAA6B,EAAE;QAFnC,cAAS,GAAkC,IAAI,GAAG,EAAE,CAAC;QAG3D,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,uBAAc,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,uBAAc,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1G,IAAI,CAAC,KAAK,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE3C,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAA,8BAAqB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE3D,IAAI,CAAC,GAAG,GAAG,IAAI,uBAAe,CAAC;YAC7B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE,EA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AC,KAAK,CAAC,CAAC,CAAC;YAC3D,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AA1JD,oCA0JC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { PDFGenerator } from './generator';
|
|
2
|
+
export type { PDFConfig } from './config';
|
|
3
|
+
export { DEFAULT_CONFIG, PAGE_SIZES, resolvePageDimensions } from './config';
|
|
4
|
+
export type { Theme } from './theme';
|
|
5
|
+
export { DEFAULT_THEME, mergeTheme } from './theme';
|
|
6
|
+
export type { TableColumn, TableOptions } from './utils/table';
|
|
7
|
+
export type { LogoInput } from './utils/logo';
|
|
8
|
+
export { detectFormat } from './utils/image';
|
|
9
|
+
export type { ImageFormat } from './utils/image';
|
|
10
|
+
import { PDFGenerator } from './generator';
|
|
11
|
+
import { renderInvoice } from './templates/invoice';
|
|
12
|
+
import { renderReceipt } from './templates/receipt';
|
|
13
|
+
import { renderCertificate } from './templates/certificate';
|
|
14
|
+
export declare class Templates {
|
|
15
|
+
static readonly INVOICE = "invoice";
|
|
16
|
+
static readonly RECEIPT = "receipt";
|
|
17
|
+
static readonly CERTIFICATE = "certificate";
|
|
18
|
+
static register(generator: PDFGenerator): void;
|
|
19
|
+
}
|
|
20
|
+
export { renderInvoice, renderReceipt, renderCertificate };
|
|
21
|
+
export type { InvoiceData, InvoiceItem } from './templates/invoice';
|
|
22
|
+
export type { ReceiptData, ReceiptItem } from './templates/receipt';
|
|
23
|
+
export type { CertificateData } from './templates/certificate';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC7E,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,qBAAa,SAAS;IACpB,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAa;IACpC,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAa;IACpC,MAAM,CAAC,QAAQ,CAAC,WAAW,iBAAiB;IAE5C,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;CAK/C;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC;AAC3D,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderCertificate = exports.renderReceipt = exports.renderInvoice = exports.Templates = exports.detectFormat = exports.mergeTheme = exports.DEFAULT_THEME = exports.resolvePageDimensions = exports.PAGE_SIZES = exports.DEFAULT_CONFIG = exports.PDFGenerator = void 0;
|
|
4
|
+
var generator_1 = require("./generator");
|
|
5
|
+
Object.defineProperty(exports, "PDFGenerator", { enumerable: true, get: function () { return generator_1.PDFGenerator; } });
|
|
6
|
+
var config_1 = require("./config");
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return config_1.DEFAULT_CONFIG; } });
|
|
8
|
+
Object.defineProperty(exports, "PAGE_SIZES", { enumerable: true, get: function () { return config_1.PAGE_SIZES; } });
|
|
9
|
+
Object.defineProperty(exports, "resolvePageDimensions", { enumerable: true, get: function () { return config_1.resolvePageDimensions; } });
|
|
10
|
+
var theme_1 = require("./theme");
|
|
11
|
+
Object.defineProperty(exports, "DEFAULT_THEME", { enumerable: true, get: function () { return theme_1.DEFAULT_THEME; } });
|
|
12
|
+
Object.defineProperty(exports, "mergeTheme", { enumerable: true, get: function () { return theme_1.mergeTheme; } });
|
|
13
|
+
var image_1 = require("./utils/image");
|
|
14
|
+
Object.defineProperty(exports, "detectFormat", { enumerable: true, get: function () { return image_1.detectFormat; } });
|
|
15
|
+
const invoice_1 = require("./templates/invoice");
|
|
16
|
+
Object.defineProperty(exports, "renderInvoice", { enumerable: true, get: function () { return invoice_1.renderInvoice; } });
|
|
17
|
+
const receipt_1 = require("./templates/receipt");
|
|
18
|
+
Object.defineProperty(exports, "renderReceipt", { enumerable: true, get: function () { return receipt_1.renderReceipt; } });
|
|
19
|
+
const certificate_1 = require("./templates/certificate");
|
|
20
|
+
Object.defineProperty(exports, "renderCertificate", { enumerable: true, get: function () { return certificate_1.renderCertificate; } });
|
|
21
|
+
class Templates {
|
|
22
|
+
static register(generator) {
|
|
23
|
+
generator.registerTemplate('invoice', invoice_1.renderInvoice);
|
|
24
|
+
generator.registerTemplate('receipt', receipt_1.renderReceipt);
|
|
25
|
+
generator.registerTemplate('certificate', certificate_1.renderCertificate);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Templates = Templates;
|
|
29
|
+
Templates.INVOICE = 'invoice';
|
|
30
|
+
Templates.RECEIPT = 'receipt';
|
|
31
|
+
Templates.CERTIFICATE = 'certificate';
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAAlC,yGAAA,YAAY,OAAA;AAErB,mCAA6E;AAApE,wGAAA,cAAc,OAAA;AAAE,oGAAA,UAAU,OAAA;AAAE,+GAAA,qBAAqB,OAAA;AAE1D,iCAAoD;AAA3C,sGAAA,aAAa,OAAA;AAAE,mGAAA,UAAU,OAAA;AAGlC,uCAA6C;AAApC,qGAAA,YAAY,OAAA;AAIrB,iDAAoD;AAgB3C,8FAhBA,uBAAa,OAgBA;AAftB,iDAAoD;AAe5B,8FAff,uBAAa,OAee;AAdrC,yDAA4D;AAcrB,kGAd9B,+BAAiB,OAc8B;AAZxD,MAAa,SAAS;IAKpB,MAAM,CAAC,QAAQ,CAAC,SAAuB;QACrC,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,uBAAiC,CAAC,CAAC;QACzE,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,uBAAiC,CAAC,CAAC;QACzE,SAAS,CAAC,gBAAgB,CAAC,aAAa,EAAE,+BAAqC,CAAC,CAAC;IACnF,CAAC;;AATH,8BAUC;AATiB,iBAAO,GAAG,SAAS,CAAC;AACpB,iBAAO,GAAG,SAAS,CAAC;AACpB,qBAAW,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PDFConfig } from '../config';
|
|
2
|
+
import { Theme } from '../theme';
|
|
3
|
+
import { PDFDoc } from '../types';
|
|
4
|
+
import { LogoInput } from '../utils/logo';
|
|
5
|
+
export interface CertificateData {
|
|
6
|
+
title: string;
|
|
7
|
+
logo?: LogoInput;
|
|
8
|
+
recipientName: string;
|
|
9
|
+
achievementText: string;
|
|
10
|
+
issuerName: string;
|
|
11
|
+
issueDate: Date | string;
|
|
12
|
+
certificationNumber?: string;
|
|
13
|
+
borderColor?: string;
|
|
14
|
+
decorativeElements?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function renderCertificate(pdf: PDFDoc, config: PDFConfig, data: CertificateData, theme: Theme): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=certificate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate.d.ts","sourceRoot":"","sources":["../../src/templates/certificate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAc,SAAS,EAAe,MAAM,eAAe,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAsF1H"}
|