@pdfme/common 5.3.8-dev.9 → 5.3.9
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__/dynamicTemplate.test.js +26 -16
- package/dist/cjs/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/cjs/__tests__/expression.test.js +45 -45
- package/dist/cjs/__tests__/expression.test.js.map +1 -1
- package/dist/cjs/__tests__/helper.test.js +63 -54
- package/dist/cjs/__tests__/helper.test.js.map +1 -1
- package/dist/cjs/src/dynamicTemplate.js +4 -4
- package/dist/cjs/src/dynamicTemplate.js.map +1 -1
- package/dist/cjs/src/expression.js +17 -7
- package/dist/cjs/src/expression.js.map +1 -1
- package/dist/cjs/src/helper.js.map +1 -1
- package/dist/cjs/src/index.js +34 -34
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/esm/__tests__/dynamicTemplate.test.js +1 -1
- package/dist/esm/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/esm/__tests__/expression.test.js +1 -1
- package/dist/esm/__tests__/expression.test.js.map +1 -1
- package/dist/esm/__tests__/helper.test.js +2 -3
- package/dist/esm/__tests__/helper.test.js.map +1 -1
- package/dist/esm/src/dynamicTemplate.js +1 -1
- package/dist/esm/src/dynamicTemplate.js.map +1 -1
- package/dist/esm/src/expression.js.map +1 -1
- package/dist/esm/src/helper.js.map +1 -1
- package/dist/esm/src/index.js +5 -5
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/node/__tests__/dynamicTemplate.test.js +26 -16
- package/dist/node/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/node/__tests__/expression.test.js +45 -45
- package/dist/node/__tests__/expression.test.js.map +1 -1
- package/dist/node/__tests__/helper.test.js +63 -54
- package/dist/node/__tests__/helper.test.js.map +1 -1
- package/dist/node/src/dynamicTemplate.js +4 -4
- package/dist/node/src/dynamicTemplate.js.map +1 -1
- package/dist/node/src/expression.js +17 -7
- package/dist/node/src/expression.js.map +1 -1
- package/dist/node/src/helper.js.map +1 -1
- package/dist/node/src/index.js +34 -34
- package/dist/node/src/index.js.map +1 -1
- package/dist/node/src/version.js +1 -1
- package/dist/types/src/dynamicTemplate.d.ts +1 -1
- package/dist/types/src/expression.d.ts +1 -1
- package/dist/types/src/helper.d.ts +3 -40
- package/dist/types/src/index.d.ts +6 -6
- package/dist/types/src/schema.d.ts +150 -150
- package/dist/types/src/types.d.ts +0 -2
- package/dist/types/src/version.d.ts +1 -1
- package/eslint.config.mjs +22 -0
- package/package.json +2 -2
- package/set-version.js +1 -1
- package/src/dynamicTemplate.ts +5 -5
- package/src/expression.ts +5 -6
- package/src/helper.ts +10 -10
- package/src/index.ts +6 -6
- package/src/schema.ts +1 -1
- package/src/types.ts +3 -5
- package/src/version.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
@@ -1,8 +1,6 @@
|
|
1
1
|
import { z } from 'zod';
|
2
2
|
import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
|
3
|
-
/** @ts-ignore -- optional interface, will gracefully degrade to `any` if `antd` isn't installed **/
|
4
3
|
import type { ThemeConfig, GlobalToken } from 'antd';
|
5
|
-
/** @ts-ignore -- optional interface, will gracefully degrade to `any` if `form-render` isn't installed*/
|
6
4
|
import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render';
|
7
5
|
import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, BlankPdf, CommonOptions, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType, LegacySchemaPageArray, SchemaPageArray } from './schema.js';
|
8
6
|
export type PropPanelSchema = _PropPanelSchema;
|
@@ -1 +1 @@
|
|
1
|
-
export declare const PDFME_VERSION = "5.3.
|
1
|
+
export declare const PDFME_VERSION = "5.3.9";
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { fileURLToPath } from 'url';
|
2
|
+
import { dirname, resolve } from 'path';
|
3
|
+
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
5
|
+
const __dirname = dirname(__filename);
|
6
|
+
|
7
|
+
// Import the root config
|
8
|
+
const rootConfigPath = resolve(__dirname, '../../eslint.config.mjs');
|
9
|
+
const rootConfig = await import(rootConfigPath);
|
10
|
+
|
11
|
+
export default [
|
12
|
+
...rootConfig.default,
|
13
|
+
{
|
14
|
+
files: ['src/**/*.ts'],
|
15
|
+
languageOptions: {
|
16
|
+
parserOptions: {
|
17
|
+
project: ['./tsconfig.esm.json'],
|
18
|
+
tsconfigRootDir: __dirname,
|
19
|
+
},
|
20
|
+
},
|
21
|
+
},
|
22
|
+
];
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/common",
|
3
|
-
"version": "5.3.
|
3
|
+
"version": "5.3.9",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -42,7 +42,7 @@
|
|
42
42
|
"build:esm": "tsc -p tsconfig.esm.json",
|
43
43
|
"build:node": "tsc -p tsconfig.node.json",
|
44
44
|
"clean": "rimraf dist",
|
45
|
-
"lint": "eslint --ext .ts src",
|
45
|
+
"lint": "eslint --ext .ts src --config eslint.config.mjs --no-error-on-unmatched-pattern",
|
46
46
|
"test": "jest",
|
47
47
|
"prune": "ts-prune src",
|
48
48
|
"prettier": "prettier --write 'src/**/*.ts'"
|
package/set-version.js
CHANGED
package/src/dynamicTemplate.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Schema, Template, BasePdf, BlankPdf, CommonOptions } from './types';
|
2
|
-
import { cloneDeep, isBlankPdf } from './helper';
|
1
|
+
import { Schema, Template, BasePdf, BlankPdf, CommonOptions } from './types.js';
|
2
|
+
import { cloneDeep, isBlankPdf } from './helper.js';
|
3
3
|
|
4
4
|
interface ModifyTemplateForDynamicTableArg {
|
5
5
|
template: Template;
|
@@ -8,7 +8,7 @@ interface ModifyTemplateForDynamicTableArg {
|
|
8
8
|
options: CommonOptions;
|
9
9
|
getDynamicHeights: (
|
10
10
|
value: string,
|
11
|
-
args: { schema: Schema; basePdf: BasePdf; options: CommonOptions; _cache: Map<any, any> }
|
11
|
+
args: { schema: Schema; basePdf: BasePdf; options: CommonOptions; _cache: Map<any, any> },
|
12
12
|
) => Promise<number[]>;
|
13
13
|
}
|
14
14
|
|
@@ -108,7 +108,7 @@ async function createOnePage(
|
|
108
108
|
basePdf: BlankPdf;
|
109
109
|
schemaPage: Schema[];
|
110
110
|
orderMap: Map<string, number>;
|
111
|
-
} & Omit<ModifyTemplateForDynamicTableArg, 'template'
|
111
|
+
} & Omit<ModifyTemplateForDynamicTableArg, 'template'>,
|
112
112
|
): Promise<LayoutNode> {
|
113
113
|
const { basePdf, schemaPage, orderMap, input, options, _cache, getDynamicHeights } = arg;
|
114
114
|
const page = createPage(basePdf);
|
@@ -256,7 +256,7 @@ function createNewTemplate(pages: LayoutNode[], basePdf: BlankPdf): Template {
|
|
256
256
|
}
|
257
257
|
|
258
258
|
export const getDynamicTemplate = async (
|
259
|
-
arg: ModifyTemplateForDynamicTableArg
|
259
|
+
arg: ModifyTemplateForDynamicTableArg,
|
260
260
|
): Promise<Template> => {
|
261
261
|
const { template } = arg;
|
262
262
|
if (!isBlankPdf(template.basePdf)) {
|
package/src/expression.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as acorn from 'acorn';
|
2
2
|
import type { Node as AcornNode, Identifier, Property } from 'estree';
|
3
|
-
import type { SchemaPageArray } from './types';
|
3
|
+
import type { SchemaPageArray } from './types.js';
|
4
4
|
|
5
5
|
const expressionCache = new Map<string, (context: Record<string, unknown>) => unknown>();
|
6
6
|
const parseDataCache = new Map<string, Record<string, unknown>>();
|
@@ -22,7 +22,7 @@ const parseData = (data: Record<string, unknown>): Record<string, unknown> => {
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
return [key, value];
|
25
|
-
})
|
25
|
+
}),
|
26
26
|
);
|
27
27
|
|
28
28
|
parseDataCache.set(key, parsed);
|
@@ -338,7 +338,7 @@ const evaluatePlaceholders = (arg: {
|
|
338
338
|
|
339
339
|
if (braceCount === 0) {
|
340
340
|
const code = content.slice(startIndex + 1, endIndex - 1).trim();
|
341
|
-
|
341
|
+
|
342
342
|
if (expressionCache.has(code)) {
|
343
343
|
const evalFunc = expressionCache.get(code)!;
|
344
344
|
try {
|
@@ -369,7 +369,6 @@ const evaluatePlaceholders = (arg: {
|
|
369
369
|
return resultContent;
|
370
370
|
};
|
371
371
|
|
372
|
-
|
373
372
|
export const replacePlaceholders = (arg: {
|
374
373
|
content: string;
|
375
374
|
variables: Record<string, any>;
|
@@ -386,7 +385,7 @@ export const replacePlaceholders = (arg: {
|
|
386
385
|
|
387
386
|
const data = {
|
388
387
|
...Object.fromEntries(
|
389
|
-
schemas.flat().map((schema) => [schema.name, schema.readOnly ? schema.content || '' : ''])
|
388
|
+
schemas.flat().map((schema) => [schema.name, schema.readOnly ? schema.content || '' : '']),
|
390
389
|
),
|
391
390
|
...variables,
|
392
391
|
};
|
@@ -405,4 +404,4 @@ export const replacePlaceholders = (arg: {
|
|
405
404
|
});
|
406
405
|
|
407
406
|
return evaluatePlaceholders({ content, context });
|
408
|
-
};
|
407
|
+
};
|
package/src/helper.ts
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
BlankPdf,
|
10
10
|
LegacySchemaPageArray,
|
11
11
|
SchemaPageArray,
|
12
|
-
} from './types';
|
12
|
+
} from './types.js';
|
13
13
|
import {
|
14
14
|
Inputs as InputsSchema,
|
15
15
|
UIOptions as UIOptionsSchema,
|
@@ -41,7 +41,7 @@ export const getFallbackFontName = (font: Font) => {
|
|
41
41
|
}, initial);
|
42
42
|
if (fallbackFontName === initial) {
|
43
43
|
throw Error(
|
44
|
-
`[@pdfme/common] fallback flag is not found in font. true fallback flag must be only one
|
44
|
+
`[@pdfme/common] fallback flag is not found in font. true fallback flag must be only one.`,
|
45
45
|
);
|
46
46
|
}
|
47
47
|
|
@@ -107,7 +107,7 @@ export const migrateTemplate = (template: Template) => {
|
|
107
107
|
Object.entries(page).map(([key, value]) => ({
|
108
108
|
...value,
|
109
109
|
name: key,
|
110
|
-
}))
|
110
|
+
})),
|
111
111
|
);
|
112
112
|
}
|
113
113
|
};
|
@@ -128,7 +128,7 @@ export const getInputFromTemplate = (template: Template): { [key: string]: strin
|
|
128
128
|
};
|
129
129
|
|
130
130
|
export const getB64BasePdf = async (
|
131
|
-
customPdf: ArrayBuffer | Uint8Array | string
|
131
|
+
customPdf: ArrayBuffer | Uint8Array | string,
|
132
132
|
): Promise<string> => {
|
133
133
|
if (
|
134
134
|
typeof customPdf === 'string' &&
|
@@ -170,7 +170,7 @@ const getFontNamesInSchemas = (schemas: SchemaPageArray) =>
|
|
170
170
|
schemas
|
171
171
|
.map((p) => p.map((v) => (v as any).fontName ?? ''))
|
172
172
|
.reduce((acc, cur) => acc.concat(cur), [] as (string | undefined)[])
|
173
|
-
.filter(Boolean) as string[]
|
173
|
+
.filter(Boolean) as string[],
|
174
174
|
);
|
175
175
|
|
176
176
|
export const checkFont = (arg: { font: Font; template: Template }) => {
|
@@ -183,13 +183,13 @@ export const checkFont = (arg: { font: Font; template: Template }) => {
|
|
183
183
|
if (fallbackFontNum === 0) {
|
184
184
|
throw Error(
|
185
185
|
`[@pdfme/common] fallback flag is not found in font. true fallback flag must be only one.
|
186
|
-
Check this document: https://pdfme.com/docs/custom-fonts#about-font-type
|
186
|
+
Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`,
|
187
187
|
);
|
188
188
|
}
|
189
189
|
if (fallbackFontNum > 1) {
|
190
190
|
throw Error(
|
191
191
|
`[@pdfme/common] ${fallbackFontNum} fallback flags found in font. true fallback flag must be only one.
|
192
|
-
Check this document: https://pdfme.com/docs/custom-fonts#about-font-type
|
192
|
+
Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`,
|
193
193
|
);
|
194
194
|
}
|
195
195
|
|
@@ -200,7 +200,7 @@ Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`
|
|
200
200
|
`[@pdfme/common] ${fontNamesInSchemas
|
201
201
|
.filter((f) => !fontNames.includes(f))
|
202
202
|
.join()} of template.schemas is not found in font.
|
203
|
-
Check this document: https://pdfme.com/docs/custom-fonts
|
203
|
+
Check this document: https://pdfme.com/docs/custom-fonts`,
|
204
204
|
);
|
205
205
|
}
|
206
206
|
};
|
@@ -218,7 +218,7 @@ export const checkPlugins = (arg: { plugins: Plugins; template: Template }) => {
|
|
218
218
|
throw Error(
|
219
219
|
`[@pdfme/common] ${allSchemaTypes
|
220
220
|
.filter((s) => !pluginsSchemaTypes.includes(s))
|
221
|
-
.join()} of template.schemas is not found in plugins
|
221
|
+
.join()} of template.schemas is not found in plugins.`,
|
222
222
|
);
|
223
223
|
}
|
224
224
|
};
|
@@ -231,7 +231,7 @@ const checkProps = <T>(data: unknown, zodSchema: z.ZodType<T>) => {
|
|
231
231
|
const messages = e.issues.map(
|
232
232
|
(issue) => `ERROR POSITION: ${issue.path.join('.')}
|
233
233
|
ERROR MESSAGE: ${issue.message}
|
234
|
-
|
234
|
+
--------------------------`,
|
235
235
|
);
|
236
236
|
|
237
237
|
const message = messages.join('\n');
|
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {PDFME_VERSION} from './version';
|
1
|
+
import { PDFME_VERSION } from './version.js';
|
2
2
|
import {
|
3
3
|
MM_TO_PT_RATIO,
|
4
4
|
PT_TO_MM_RATIO,
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
BLANK_PDF,
|
7
7
|
ZOOM,
|
8
8
|
DEFAULT_FONT_NAME,
|
9
|
-
} from './constants';
|
9
|
+
} from './constants.js';
|
10
10
|
import type {
|
11
11
|
ChangeSchemaItem,
|
12
12
|
ChangeSchemas,
|
@@ -36,7 +36,7 @@ import type {
|
|
36
36
|
UIProps,
|
37
37
|
PreviewProps,
|
38
38
|
DesignerProps,
|
39
|
-
} from './types';
|
39
|
+
} from './types.js';
|
40
40
|
import {
|
41
41
|
cloneDeep,
|
42
42
|
getFallbackFontName,
|
@@ -58,9 +58,9 @@ import {
|
|
58
58
|
isHexValid,
|
59
59
|
getInputFromTemplate,
|
60
60
|
isBlankPdf,
|
61
|
-
} from './helper';
|
62
|
-
import { getDynamicTemplate } from './dynamicTemplate';
|
63
|
-
import { replacePlaceholders } from './expression';
|
61
|
+
} from './helper.js';
|
62
|
+
import { getDynamicTemplate } from './dynamicTemplate.js';
|
63
|
+
import { replacePlaceholders } from './expression.js';
|
64
64
|
|
65
65
|
export {
|
66
66
|
PDFME_VERSION,
|
package/src/schema.ts
CHANGED
@@ -148,7 +148,7 @@ export const Font = z.record(
|
|
148
148
|
data: z.union([z.string(), ArrayBufferSchema, Uint8ArraySchema]),
|
149
149
|
fallback: z.boolean().optional(),
|
150
150
|
subset: z.boolean().optional(),
|
151
|
-
})
|
151
|
+
}),
|
152
152
|
);
|
153
153
|
|
154
154
|
export const CommonOptions = z.object({ font: Font.optional() }).passthrough();
|
package/src/types.ts
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
import { z } from 'zod';
|
2
2
|
import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
|
3
|
-
/** @ts-ignore -- optional interface, will gracefully degrade to `any` if `antd` isn't installed **/
|
4
3
|
import type { ThemeConfig, GlobalToken } from 'antd';
|
5
|
-
/** @ts-ignore -- optional interface, will gracefully degrade to `any` if `form-render` isn't installed*/
|
6
4
|
import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render';
|
7
5
|
import {
|
8
6
|
Lang,
|
@@ -29,9 +27,9 @@ import {
|
|
29
27
|
|
30
28
|
export type PropPanelSchema = _PropPanelSchema;
|
31
29
|
export type ChangeSchemaItem = {
|
32
|
-
key: string
|
33
|
-
value: any
|
34
|
-
schemaId: string
|
30
|
+
key: string;
|
31
|
+
value: any;
|
32
|
+
schemaId: string;
|
35
33
|
};
|
36
34
|
export type ChangeSchemas = (objs: ChangeSchemaItem[]) => void;
|
37
35
|
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const PDFME_VERSION = '5.3.
|
1
|
+
export const PDFME_VERSION = '5.3.9';
|
package/tsconfig.cjs.json
CHANGED
package/tsconfig.esm.json
CHANGED
package/tsconfig.node.json
CHANGED
package/.eslintrc.cjs
DELETED