@pdfme/common 1.0.0-beta.4 → 1.0.0-beta.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/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/type.d.ts +9 -9
- package/package.json +10 -4
- package/src/helper.ts +9 -4
- package/src/index.ts +20 -20
- package/src/schema.ts +0 -2
- package/src/type.ts +7 -6
- package/tsconfig.json +2 -1
- package/webpack.config.js +0 -1
package/dist/types/index.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF } from './constants';
|
2
|
-
import {
|
2
|
+
import { schemaTypes, isImageSchema, isBarcodeSchema, isTextSchema } from './type';
|
3
|
+
import type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './type';
|
3
4
|
import { getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from './helper';
|
4
|
-
export { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF,
|
5
|
+
export { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };
|
6
|
+
export type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, };
|
package/dist/types/type.d.ts
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
import { z } from 'zod';
|
2
2
|
import { Lang, Size, Alignment, BarcodeSchemaType, SchemaType, CommonSchema as _CommonSchema, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './schema';
|
3
|
-
export declare type Lang = z.infer<typeof Lang>;
|
4
|
-
export declare type Size = z.infer<typeof Size>;
|
5
|
-
export declare type Alignment = z.infer<typeof Alignment>;
|
6
|
-
export declare type SchemaType = z.infer<typeof SchemaType>;
|
7
|
-
export declare const schemaTypes: readonly ["text", "image", "qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce"];
|
8
|
-
export declare type BarCodeType = z.infer<typeof BarcodeSchemaType>;
|
9
|
-
export declare type TextSchema = z.infer<typeof TextSchema>;
|
10
3
|
declare type CommonSchema = z.infer<typeof _CommonSchema>;
|
4
|
+
export declare const schemaTypes: readonly ["text", "image", "qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce"];
|
11
5
|
export declare const isTextSchema: (arg: CommonSchema) => arg is {
|
12
6
|
rotate?: number | undefined;
|
13
7
|
alignment?: "left" | "center" | "right" | undefined;
|
@@ -25,7 +19,6 @@ export declare const isTextSchema: (arg: CommonSchema) => arg is {
|
|
25
19
|
width: number;
|
26
20
|
height: number;
|
27
21
|
};
|
28
|
-
export declare type ImageSchema = z.infer<typeof ImageSchema>;
|
29
22
|
export declare const isImageSchema: (arg: CommonSchema) => arg is {
|
30
23
|
rotate?: number | undefined;
|
31
24
|
type: "image";
|
@@ -36,7 +29,6 @@ export declare const isImageSchema: (arg: CommonSchema) => arg is {
|
|
36
29
|
width: number;
|
37
30
|
height: number;
|
38
31
|
};
|
39
|
-
export declare type BarcodeSchema = z.infer<typeof BarcodeSchema>;
|
40
32
|
export declare const isBarcodeSchema: (arg: CommonSchema) => arg is {
|
41
33
|
rotate?: number | undefined;
|
42
34
|
type: "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce";
|
@@ -47,6 +39,14 @@ export declare const isBarcodeSchema: (arg: CommonSchema) => arg is {
|
|
47
39
|
width: number;
|
48
40
|
height: number;
|
49
41
|
};
|
42
|
+
export declare type Lang = z.infer<typeof Lang>;
|
43
|
+
export declare type Size = z.infer<typeof Size>;
|
44
|
+
export declare type Alignment = z.infer<typeof Alignment>;
|
45
|
+
export declare type SchemaType = z.infer<typeof SchemaType>;
|
46
|
+
export declare type BarCodeType = z.infer<typeof BarcodeSchemaType>;
|
47
|
+
export declare type TextSchema = z.infer<typeof TextSchema>;
|
48
|
+
export declare type ImageSchema = z.infer<typeof ImageSchema>;
|
49
|
+
export declare type BarcodeSchema = z.infer<typeof BarcodeSchema>;
|
50
50
|
export declare type Schema = z.infer<typeof Schema>;
|
51
51
|
export declare type SchemaForUI = z.infer<typeof SchemaForUI>;
|
52
52
|
export declare type Font = z.infer<typeof Font>;
|
package/package.json
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/common",
|
3
|
-
"version": "1.0.0-beta.
|
3
|
+
"version": "1.0.0-beta.8",
|
4
4
|
"author": "hand-dot",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
7
7
|
"homepage": "https://pdfme.com",
|
8
|
-
"repository":
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "git@github.com:pdfme/pdfme.git"
|
11
|
+
},
|
9
12
|
"bugs": {
|
10
13
|
"url": "https://github.com/pdfme/pdfme/issues"
|
11
14
|
},
|
12
15
|
"main": "dist/index.js",
|
13
|
-
"module": "
|
16
|
+
"module": "dist/index.js",
|
14
17
|
"types": "dist/types/index.d.ts",
|
15
18
|
"engines": {
|
16
19
|
"node": ">=14"
|
17
20
|
},
|
18
21
|
"scripts": {
|
19
|
-
"develop": "webpack
|
22
|
+
"develop": "webpack --watch --mode development",
|
20
23
|
"build": "NODE_ENV=production webpack --mode production",
|
21
24
|
"clean": "rimraf dist",
|
22
25
|
"lint": "tsc --noEmit",
|
@@ -47,5 +50,8 @@
|
|
47
50
|
"testMatch": [
|
48
51
|
"**/*.test.ts"
|
49
52
|
]
|
53
|
+
},
|
54
|
+
"publishConfig": {
|
55
|
+
"access": "public"
|
50
56
|
}
|
51
57
|
}
|
package/src/helper.ts
CHANGED
@@ -40,13 +40,18 @@ export const getB64BasePdf = (basePdf: BasePdf) => {
|
|
40
40
|
return basePdf as string;
|
41
41
|
};
|
42
42
|
|
43
|
+
const getByteString = (base64: string) => {
|
44
|
+
if (typeof window !== 'undefined' && window.atob) {
|
45
|
+
return window.atob(base64);
|
46
|
+
} else {
|
47
|
+
return Buffer.from(base64, 'base64').toString('binary');
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
43
51
|
export const b64toUint8Array = (base64: string) => {
|
44
52
|
const data = base64.split(';base64,')[1] ? base64.split(';base64,')[1] : base64;
|
45
53
|
|
46
|
-
const byteString =
|
47
|
-
typeof window !== 'undefined'
|
48
|
-
? window.atob(data)
|
49
|
-
: Buffer.from(data, 'base64').toString('binary');
|
54
|
+
const byteString = getByteString(data);
|
50
55
|
|
51
56
|
const unit8arr = new Uint8Array(byteString.length);
|
52
57
|
for (let i = 0; i < byteString.length; i += 1) {
|
package/src/index.ts
CHANGED
@@ -6,19 +6,16 @@ import {
|
|
6
6
|
DEFAULT_FONT_COLOR,
|
7
7
|
BLANK_PDF,
|
8
8
|
} from './constants';
|
9
|
-
import {
|
9
|
+
import { schemaTypes, isImageSchema, isBarcodeSchema, isTextSchema } from './type';
|
10
|
+
import type {
|
10
11
|
Lang,
|
11
12
|
Size,
|
12
13
|
Alignment,
|
13
14
|
SchemaType,
|
14
|
-
schemaTypes,
|
15
15
|
BarCodeType,
|
16
16
|
TextSchema,
|
17
|
-
isTextSchema,
|
18
17
|
ImageSchema,
|
19
|
-
isImageSchema,
|
20
18
|
BarcodeSchema,
|
21
|
-
isBarcodeSchema,
|
22
19
|
Schema,
|
23
20
|
SchemaForUI,
|
24
21
|
Font,
|
@@ -55,18 +52,32 @@ export {
|
|
55
52
|
DEFAULT_CHARACTER_SPACING,
|
56
53
|
DEFAULT_FONT_COLOR,
|
57
54
|
BLANK_PDF,
|
55
|
+
schemaTypes,
|
56
|
+
isTextSchema,
|
57
|
+
isImageSchema,
|
58
|
+
isBarcodeSchema,
|
59
|
+
getB64BasePdf,
|
60
|
+
b64toUint8Array,
|
61
|
+
getFallbackFontName,
|
62
|
+
getDefaultFont,
|
63
|
+
checkFont,
|
64
|
+
checkTemplate,
|
65
|
+
checkUIProps,
|
66
|
+
checkPreviewProps,
|
67
|
+
checkDesignerProps,
|
68
|
+
checkGenerateProps,
|
69
|
+
validateBarcodeInput,
|
70
|
+
};
|
71
|
+
|
72
|
+
export type {
|
58
73
|
Lang,
|
59
74
|
Size,
|
60
75
|
Alignment,
|
61
76
|
SchemaType,
|
62
|
-
schemaTypes,
|
63
77
|
BarCodeType,
|
64
78
|
TextSchema,
|
65
|
-
isTextSchema,
|
66
79
|
ImageSchema,
|
67
|
-
isImageSchema,
|
68
80
|
BarcodeSchema,
|
69
|
-
isBarcodeSchema,
|
70
81
|
Schema,
|
71
82
|
SchemaForUI,
|
72
83
|
Font,
|
@@ -81,15 +92,4 @@ export {
|
|
81
92
|
PreviewReactProps,
|
82
93
|
DesignerProps,
|
83
94
|
DesignerReactProps,
|
84
|
-
getB64BasePdf,
|
85
|
-
b64toUint8Array,
|
86
|
-
getFallbackFontName,
|
87
|
-
getDefaultFont,
|
88
|
-
checkFont,
|
89
|
-
checkTemplate,
|
90
|
-
checkUIProps,
|
91
|
-
checkPreviewProps,
|
92
|
-
checkDesignerProps,
|
93
|
-
checkGenerateProps,
|
94
|
-
validateBarcodeInput,
|
95
95
|
};
|
package/src/schema.ts
CHANGED
@@ -37,10 +37,8 @@ export const TextSchema = CommonSchema.extend({
|
|
37
37
|
});
|
38
38
|
|
39
39
|
export const ImageSchema = CommonSchema.extend({ type: z.literal(SchemaType.Enum.image) });
|
40
|
-
type ImageSchema = z.infer<typeof ImageSchema>;
|
41
40
|
|
42
41
|
export const BarcodeSchema = CommonSchema.extend({ type: BarcodeSchemaType });
|
43
|
-
type BarcodeSchema = z.infer<typeof BarcodeSchema>;
|
44
42
|
|
45
43
|
export const Schema = z.union([TextSchema, ImageSchema, BarcodeSchema]);
|
46
44
|
|
package/src/type.ts
CHANGED
@@ -27,20 +27,21 @@ import {
|
|
27
27
|
DesignerReactProps,
|
28
28
|
} from './schema';
|
29
29
|
|
30
|
+
type CommonSchema = z.infer<typeof _CommonSchema>;
|
31
|
+
export const schemaTypes = _schemaTypes;
|
32
|
+
export const isTextSchema = (arg: CommonSchema): arg is TextSchema => arg.type === 'text';
|
33
|
+
export const isImageSchema = (arg: CommonSchema): arg is ImageSchema => arg.type === 'image';
|
34
|
+
export const isBarcodeSchema = (arg: CommonSchema): arg is BarcodeSchema =>
|
35
|
+
barcodeSchemaTypes.map((t) => t as string).includes(arg.type);
|
36
|
+
|
30
37
|
export type Lang = z.infer<typeof Lang>;
|
31
38
|
export type Size = z.infer<typeof Size>;
|
32
39
|
export type Alignment = z.infer<typeof Alignment>;
|
33
40
|
export type SchemaType = z.infer<typeof SchemaType>;
|
34
|
-
export const schemaTypes = _schemaTypes;
|
35
41
|
export type BarCodeType = z.infer<typeof BarcodeSchemaType>;
|
36
42
|
export type TextSchema = z.infer<typeof TextSchema>;
|
37
|
-
type CommonSchema = z.infer<typeof _CommonSchema>;
|
38
|
-
export const isTextSchema = (arg: CommonSchema): arg is TextSchema => arg.type === 'text';
|
39
43
|
export type ImageSchema = z.infer<typeof ImageSchema>;
|
40
|
-
export const isImageSchema = (arg: CommonSchema): arg is ImageSchema => arg.type === 'image';
|
41
44
|
export type BarcodeSchema = z.infer<typeof BarcodeSchema>;
|
42
|
-
export const isBarcodeSchema = (arg: CommonSchema): arg is BarcodeSchema =>
|
43
|
-
barcodeSchemaTypes.map((t) => t as string).includes(arg.type);
|
44
45
|
export type Schema = z.infer<typeof Schema>;
|
45
46
|
export type SchemaForUI = z.infer<typeof SchemaForUI>;
|
46
47
|
export type Font = z.infer<typeof Font>;
|
package/tsconfig.json
CHANGED