@pdfme/generator 5.3.8-dev.9 → 5.3.9-dev.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/dist/cjs/__tests__/generate.test.js +15 -15
- package/dist/cjs/__tests__/generate.test.js.map +1 -1
- package/dist/cjs/__tests__/integration1.test.js +7 -7
- package/dist/cjs/__tests__/integration1.test.js.map +1 -1
- package/dist/cjs/__tests__/integration2.test.js +7 -7
- package/dist/cjs/__tests__/integration2.test.js.map +1 -1
- package/dist/cjs/__tests__/integration3.test.js +7 -7
- package/dist/cjs/__tests__/integration3.test.js.map +1 -1
- package/dist/cjs/__tests__/integration4.test.js +7 -7
- package/dist/cjs/__tests__/integration4.test.js.map +1 -1
- package/dist/cjs/__tests__/integration5.test.js +7 -7
- package/dist/cjs/__tests__/integration5.test.js.map +1 -1
- package/dist/cjs/__tests__/utils.js +17 -7
- package/dist/cjs/__tests__/utils.js.map +1 -1
- package/dist/cjs/src/generate.js +19 -9
- package/dist/cjs/src/generate.js.map +1 -1
- package/dist/cjs/src/helper.js +17 -7
- package/dist/cjs/src/helper.js.map +1 -1
- package/dist/cjs/src/index.js +2 -2
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/esm/__tests__/generate.test.js +2 -2
- package/dist/esm/__tests__/generate.test.js.map +1 -1
- package/dist/esm/__tests__/integration1.test.js +3 -3
- package/dist/esm/__tests__/integration1.test.js.map +1 -1
- package/dist/esm/__tests__/integration2.test.js +3 -3
- package/dist/esm/__tests__/integration2.test.js.map +1 -1
- package/dist/esm/__tests__/integration3.test.js +3 -3
- package/dist/esm/__tests__/integration3.test.js.map +1 -1
- package/dist/esm/__tests__/integration4.test.js +3 -3
- package/dist/esm/__tests__/integration4.test.js.map +1 -1
- package/dist/esm/__tests__/integration5.test.js +3 -3
- package/dist/esm/__tests__/integration5.test.js.map +1 -1
- package/dist/esm/__tests__/utils.js.map +1 -1
- package/dist/esm/src/generate.js +1 -1
- package/dist/esm/src/generate.js.map +1 -1
- package/dist/esm/src/helper.js.map +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/node/__tests__/generate.test.js +15 -15
- package/dist/node/__tests__/generate.test.js.map +1 -1
- package/dist/node/__tests__/integration1.test.js +7 -7
- package/dist/node/__tests__/integration1.test.js.map +1 -1
- package/dist/node/__tests__/integration2.test.js +7 -7
- package/dist/node/__tests__/integration2.test.js.map +1 -1
- package/dist/node/__tests__/integration3.test.js +7 -7
- package/dist/node/__tests__/integration3.test.js.map +1 -1
- package/dist/node/__tests__/integration4.test.js +7 -7
- package/dist/node/__tests__/integration4.test.js.map +1 -1
- package/dist/node/__tests__/integration5.test.js +7 -7
- package/dist/node/__tests__/integration5.test.js.map +1 -1
- package/dist/node/__tests__/utils.js +17 -7
- package/dist/node/__tests__/utils.js.map +1 -1
- package/dist/node/src/generate.js +19 -9
- package/dist/node/src/generate.js.map +1 -1
- package/dist/node/src/helper.js +17 -7
- package/dist/node/src/helper.js.map +1 -1
- package/dist/node/src/index.js +2 -2
- package/dist/node/src/index.js.map +1 -1
- package/dist/types/__tests__/assets/templates/index.d.ts +50 -50
- package/dist/types/__tests__/utils.d.ts +1 -3
- package/dist/types/src/generate.d.ts +1 -1
- package/dist/types/src/helper.d.ts +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/eslint.config.mjs +22 -0
- package/package.json +3 -4
- package/src/generate.ts +9 -8
- package/src/helper.ts +21 -18
- package/src/index.ts +1 -1
- package/tsconfig.cjs.json +1 -1
- package/tsconfig.esm.json +2 -1
- package/tsconfig.node.json +2 -1
- package/.eslintrc.cjs +0 -3
package/src/generate.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as pdfLib from '@pdfme/pdf-lib';
|
2
|
-
import type { GenerateProps } from '@pdfme/common';
|
2
|
+
import type { GenerateProps, Template, Schema, PDFRenderProps } from '@pdfme/common';
|
3
3
|
import {
|
4
4
|
checkGenerateProps,
|
5
5
|
getDynamicTemplate,
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
pt2mm,
|
9
9
|
cloneDeep,
|
10
10
|
} from '@pdfme/common';
|
11
|
-
import { getDynamicHeightsForTable } from '@pdfme/schemas
|
11
|
+
import { getDynamicHeightsForTable } from '@pdfme/schemas';
|
12
12
|
import {
|
13
13
|
insertPage,
|
14
14
|
preprocessing,
|
@@ -16,6 +16,7 @@ import {
|
|
16
16
|
getEmbedPdfPages,
|
17
17
|
validateRequiredFields,
|
18
18
|
} from './helper.js';
|
19
|
+
import { PDFDocument } from '@pdfme/pdf-lib';
|
19
20
|
|
20
21
|
const generate = async (props: GenerateProps) => {
|
21
22
|
checkGenerateProps(props);
|
@@ -26,7 +27,7 @@ const generate = async (props: GenerateProps) => {
|
|
26
27
|
|
27
28
|
if (inputs.length === 0) {
|
28
29
|
throw new Error(
|
29
|
-
'[@pdfme/generator] inputs should not be empty, pass at least an empty object in the array'
|
30
|
+
'[@pdfme/generator] inputs should not be empty, pass at least an empty object in the array',
|
30
31
|
);
|
31
32
|
}
|
32
33
|
|
@@ -58,7 +59,7 @@ const generate = async (props: GenerateProps) => {
|
|
58
59
|
pdfDoc,
|
59
60
|
});
|
60
61
|
const schemaNames = [
|
61
|
-
...new Set(dynamicTemplate.schemas.flatMap((page) => page.map((schema) => schema.name))),
|
62
|
+
...new Set((dynamicTemplate as Template).schemas.flatMap((page: Schema[]) => page.map((schema: Schema) => schema.name))),
|
62
63
|
];
|
63
64
|
|
64
65
|
for (let j = 0; j < basePages.length; j += 1) {
|
@@ -82,7 +83,7 @@ const generate = async (props: GenerateProps) => {
|
|
82
83
|
const value = replacePlaceholders({
|
83
84
|
content: staticSchema.content || '',
|
84
85
|
variables: { ...input, totalPages: basePages.length, currentPage: j + 1 },
|
85
|
-
schemas: dynamicTemplate.schemas,
|
86
|
+
schemas: (dynamicTemplate as Template).schemas,
|
86
87
|
});
|
87
88
|
|
88
89
|
staticSchema.position = {
|
@@ -105,8 +106,8 @@ const generate = async (props: GenerateProps) => {
|
|
105
106
|
|
106
107
|
for (let l = 0; l < schemaNames.length; l += 1) {
|
107
108
|
const name = schemaNames[l];
|
108
|
-
const schemaPage = dynamicTemplate.schemas[j] || [];
|
109
|
-
const schema = schemaPage.find((s) => s.name == name);
|
109
|
+
const schemaPage = (dynamicTemplate as Template).schemas[j] || [];
|
110
|
+
const schema = schemaPage.find((s: Schema) => s.name == name);
|
110
111
|
if (!schema) {
|
111
112
|
continue;
|
112
113
|
}
|
@@ -119,7 +120,7 @@ const generate = async (props: GenerateProps) => {
|
|
119
120
|
? replacePlaceholders({
|
120
121
|
content: schema.content || '',
|
121
122
|
variables: { ...input, totalPages: basePages.length, currentPage: j + 1 },
|
122
|
-
schemas: dynamicTemplate.schemas,
|
123
|
+
schemas: (dynamicTemplate as Template).schemas,
|
123
124
|
})
|
124
125
|
: input[name] || '';
|
125
126
|
|
package/src/helper.ts
CHANGED
@@ -13,13 +13,13 @@ import {
|
|
13
13
|
import { builtInPlugins } from '@pdfme/schemas';
|
14
14
|
import { PDFPage, PDFDocument, PDFEmbeddedPage, TransformationMatrix } from '@pdfme/pdf-lib';
|
15
15
|
import { TOOL_NAME } from './constants.js';
|
16
|
-
import type { EmbedPdfBox } from './types';
|
16
|
+
import type { EmbedPdfBox } from './types.js';
|
17
17
|
|
18
18
|
export const getEmbedPdfPages = async (arg: { template: Template; pdfDoc: PDFDocument }) => {
|
19
19
|
const {
|
20
20
|
template: { schemas, basePdf },
|
21
21
|
pdfDoc,
|
22
|
-
} = arg;
|
22
|
+
} = arg as { template: { schemas: Schema[][]; basePdf: any }; pdfDoc: PDFDocument };
|
23
23
|
let basePages: (PDFEmbeddedPage | PDFPage)[] = [];
|
24
24
|
let embedPdfBoxes: EmbedPdfBox[] = [];
|
25
25
|
|
@@ -51,7 +51,7 @@ export const getEmbedPdfPages = async (arg: { template: Template; pdfDoc: PDFDoc
|
|
51
51
|
return { left: x, bottom: y, right: width, top: height + y };
|
52
52
|
});
|
53
53
|
const transformationMatrices = embedPdfPages.map(
|
54
|
-
() => [1, 0, 0, 1, 0, 0] as TransformationMatrix
|
54
|
+
() => [1, 0, 0, 1, 0, 0] as TransformationMatrix,
|
55
55
|
);
|
56
56
|
basePages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
|
57
57
|
}
|
@@ -59,20 +59,20 @@ export const getEmbedPdfPages = async (arg: { template: Template; pdfDoc: PDFDoc
|
|
59
59
|
};
|
60
60
|
|
61
61
|
export const validateRequiredFields = (template: Template, inputs: Record<string, any>[]) => {
|
62
|
-
template.schemas.forEach((schemaPage) =>
|
63
|
-
schemaPage.forEach((schema) => {
|
62
|
+
((template as any).schemas as Schema[][]).forEach((schemaPage: Schema[]) =>
|
63
|
+
schemaPage.forEach((schema: Schema) => {
|
64
64
|
if (schema.required && !schema.readOnly && !inputs.some((input) => input[schema.name])) {
|
65
65
|
throw new Error(
|
66
|
-
`[@pdfme/generator] input for '${schema.name}' is required to generate this PDF
|
66
|
+
`[@pdfme/generator] input for '${schema.name}' is required to generate this PDF`,
|
67
67
|
);
|
68
68
|
}
|
69
|
-
})
|
69
|
+
}),
|
70
70
|
);
|
71
71
|
};
|
72
72
|
|
73
73
|
export const preprocessing = async (arg: { template: Template; userPlugins: Plugins }) => {
|
74
74
|
const { template, userPlugins } = arg;
|
75
|
-
const { schemas, basePdf } = template;
|
75
|
+
const { schemas, basePdf } = template as { schemas: Schema[][]; basePdf: any };
|
76
76
|
const staticSchema: Schema[] = isBlankPdf(basePdf) ? (basePdf.staticSchema ?? []) : [];
|
77
77
|
|
78
78
|
const pdfDoc = await PDFDocument.create();
|
@@ -88,20 +88,23 @@ export const preprocessing = async (arg: { template: Template; userPlugins: Plug
|
|
88
88
|
const schemaTypes = Array.from(
|
89
89
|
new Set(
|
90
90
|
schemas
|
91
|
-
.flatMap((schemaPage) => schemaPage.map((schema) => schema.type))
|
92
|
-
.concat(staticSchema.map((schema) => schema.type))
|
93
|
-
)
|
91
|
+
.flatMap((schemaPage: Schema[]) => schemaPage.map((schema: Schema) => schema.type))
|
92
|
+
.concat(staticSchema.map((schema: Schema) => schema.type)),
|
93
|
+
),
|
94
94
|
);
|
95
95
|
|
96
|
-
const renderObj = schemaTypes.reduce(
|
97
|
-
|
96
|
+
const renderObj = schemaTypes.reduce(
|
97
|
+
(acc: Record<string, (arg: PDFRenderProps<Schema>) => Promise<void> | void>, type: string) => {
|
98
|
+
const render = pluginValues.find((pv) => pv.propPanel.defaultSchema.type === type);
|
98
99
|
|
99
|
-
|
100
|
-
|
100
|
+
if (!render) {
|
101
|
+
throw new Error(`[@pdfme/generator] Renderer for type ${type} not found.
|
101
102
|
Check this document: https://pdfme.com/docs/custom-schemas`);
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
}
|
104
|
+
return { ...acc, [type]: render.pdf };
|
105
|
+
},
|
106
|
+
{} as Record<string, (arg: PDFRenderProps<Schema>) => Promise<void> | void>,
|
107
|
+
);
|
105
108
|
|
106
109
|
return { pdfDoc, renderObj };
|
107
110
|
};
|
package/src/index.ts
CHANGED
package/tsconfig.cjs.json
CHANGED
package/tsconfig.esm.json
CHANGED
package/tsconfig.node.json
CHANGED
package/.eslintrc.cjs
DELETED