@pdfme/schemas 3.1.5 → 3.2.0-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/README.md +303 -0
- package/dist/cjs/__tests__/{renderUtils.test.js → utils.test.js} +38 -12
- package/dist/cjs/__tests__/utils.test.js.map +1 -0
- package/dist/cjs/src/barcodes/constants.js +2 -1
- package/dist/cjs/src/barcodes/constants.js.map +1 -1
- package/dist/cjs/src/barcodes/helper.js +1 -2
- package/dist/cjs/src/barcodes/helper.js.map +1 -1
- package/dist/cjs/src/barcodes/index.js +2 -2
- package/dist/cjs/src/barcodes/index.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +3 -3
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +45 -30
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +11 -37
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/graphics/helper.js +115 -0
- package/dist/cjs/src/graphics/helper.js.map +1 -0
- package/dist/cjs/src/graphics/image.js +179 -0
- package/dist/cjs/src/graphics/image.js.map +1 -0
- package/dist/cjs/src/graphics/svg.js +96 -0
- package/dist/cjs/src/graphics/svg.js.map +1 -0
- package/dist/cjs/src/index.js +42 -9
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/shapes/line.js +57 -0
- package/dist/cjs/src/shapes/line.js.map +1 -0
- package/dist/cjs/src/shapes/rectAndEllipse.js +100 -0
- package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -0
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/index.js +16 -2
- package/dist/cjs/src/text/index.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +9 -32
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +2 -2
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +12 -18
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/utils.js +134 -0
- package/dist/cjs/src/utils.js.map +1 -0
- package/dist/esm/__tests__/{renderUtils.test.js → utils.test.js} +34 -8
- package/dist/esm/__tests__/utils.test.js.map +1 -0
- package/dist/esm/src/barcodes/constants.js +1 -0
- package/dist/esm/src/barcodes/constants.js.map +1 -1
- package/dist/esm/src/barcodes/helper.js +2 -3
- package/dist/esm/src/barcodes/helper.js.map +1 -1
- package/dist/esm/src/barcodes/index.js +2 -2
- package/dist/esm/src/barcodes/index.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +2 -2
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +46 -31
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +11 -37
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/graphics/helper.js +111 -0
- package/dist/esm/src/graphics/helper.js.map +1 -0
- package/dist/esm/src/graphics/image.js +176 -0
- package/dist/esm/src/graphics/image.js.map +1 -0
- package/dist/esm/src/graphics/svg.js +93 -0
- package/dist/esm/src/graphics/svg.js.map +1 -0
- package/dist/esm/src/index.js +7 -4
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/shapes/line.js +55 -0
- package/dist/esm/src/shapes/line.js.map +1 -0
- package/dist/esm/src/shapes/rectAndEllipse.js +97 -0
- package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -0
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/index.js +15 -2
- package/dist/esm/src/text/index.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +6 -29
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +2 -2
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +12 -18
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/utils.js +124 -0
- package/dist/esm/src/utils.js.map +1 -0
- package/dist/types/src/barcodes/constants.d.ts +1 -0
- package/dist/types/src/barcodes/helper.d.ts +1 -0
- package/dist/types/src/barcodes/index.d.ts +2 -2
- package/dist/types/src/barcodes/types.d.ts +1 -0
- package/dist/types/src/graphics/helper.d.ts +5 -0
- package/dist/types/src/graphics/image.d.ts +7 -0
- package/dist/types/src/graphics/svg.d.ts +6 -0
- package/dist/types/src/index.d.ts +7 -4
- package/dist/types/src/shapes/line.d.ts +6 -0
- package/dist/types/src/shapes/rectAndEllipse.d.ts +144 -0
- package/dist/types/src/text/index.d.ts +3 -2
- package/dist/types/src/text/pdfRender.d.ts +1 -1
- package/dist/types/src/{renderUtils.d.ts → utils.d.ts} +5 -1
- package/package.json +4 -3
- package/src/barcodes/constants.ts +2 -0
- package/src/barcodes/helper.ts +12 -3
- package/src/barcodes/index.ts +2 -2
- package/src/barcodes/pdfRender.ts +2 -2
- package/src/barcodes/propPanel.ts +50 -30
- package/src/barcodes/types.ts +1 -0
- package/src/barcodes/uiRender.ts +11 -41
- package/src/graphics/helper.ts +147 -0
- package/src/graphics/image.ts +207 -0
- package/src/graphics/svg.ts +98 -0
- package/src/index.ts +21 -4
- package/src/shapes/line.ts +67 -0
- package/src/shapes/rectAndEllipse.ts +110 -0
- package/src/text/helper.ts +0 -1
- package/src/text/index.ts +16 -2
- package/src/text/pdfRender.ts +6 -42
- package/src/text/propPanel.ts +2 -2
- package/src/text/uiRender.ts +14 -29
- package/src/utils.ts +161 -0
- package/dist/cjs/__tests__/renderUtils.test.js.map +0 -1
- package/dist/cjs/src/image/index.js +0 -8
- package/dist/cjs/src/image/index.js.map +0 -1
- package/dist/cjs/src/image/pdfRender.js +0 -20
- package/dist/cjs/src/image/pdfRender.js.map +0 -1
- package/dist/cjs/src/image/propPanel.js +0 -19
- package/dist/cjs/src/image/propPanel.js.map +0 -1
- package/dist/cjs/src/image/types.js +0 -3
- package/dist/cjs/src/image/types.js.map +0 -1
- package/dist/cjs/src/image/uiRender.js +0 -111
- package/dist/cjs/src/image/uiRender.js.map +0 -1
- package/dist/cjs/src/renderUtils.js +0 -59
- package/dist/cjs/src/renderUtils.js.map +0 -1
- package/dist/esm/__tests__/renderUtils.test.js.map +0 -1
- package/dist/esm/src/image/index.js +0 -6
- package/dist/esm/src/image/index.js.map +0 -1
- package/dist/esm/src/image/pdfRender.js +0 -16
- package/dist/esm/src/image/pdfRender.js.map +0 -1
- package/dist/esm/src/image/propPanel.js +0 -16
- package/dist/esm/src/image/propPanel.js.map +0 -1
- package/dist/esm/src/image/types.js +0 -2
- package/dist/esm/src/image/types.js.map +0 -1
- package/dist/esm/src/image/uiRender.js +0 -107
- package/dist/esm/src/image/uiRender.js.map +0 -1
- package/dist/esm/src/renderUtils.js +0 -53
- package/dist/esm/src/renderUtils.js.map +0 -1
- package/dist/types/src/image/index.d.ts +0 -4
- package/dist/types/src/image/pdfRender.d.ts +0 -3
- package/dist/types/src/image/propPanel.d.ts +0 -3
- package/dist/types/src/image/types.d.ts +0 -3
- package/dist/types/src/image/uiRender.d.ts +0 -3
- package/src/image/index.ts +0 -8
- package/src/image/pdfRender.ts +0 -28
- package/src/image/propPanel.ts +0 -19
- package/src/image/types.ts +0 -3
- package/src/image/uiRender.ts +0 -121
- package/src/renderUtils.ts +0 -73
- /package/dist/types/__tests__/{renderUtils.test.d.ts → utils.test.d.ts} +0 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
import { Schema } from '@pdfme/common';
|
2
|
+
interface Shape extends Schema {
|
3
|
+
type: 'ellipse' | 'rectangle';
|
4
|
+
borderWidth: number;
|
5
|
+
borderColor: string;
|
6
|
+
color: string;
|
7
|
+
}
|
8
|
+
export declare const rectangle: {
|
9
|
+
propPanel: {
|
10
|
+
defaultSchema: {
|
11
|
+
type: "ellipse" | "rectangle";
|
12
|
+
borderWidth: number;
|
13
|
+
borderColor: string;
|
14
|
+
color: string;
|
15
|
+
position: {
|
16
|
+
x: number;
|
17
|
+
y: number;
|
18
|
+
};
|
19
|
+
width: number;
|
20
|
+
height: number;
|
21
|
+
readOnly?: boolean | undefined;
|
22
|
+
readOnlyValue?: string | undefined;
|
23
|
+
rotate?: number | undefined;
|
24
|
+
opacity?: number | undefined;
|
25
|
+
};
|
26
|
+
schema: ((propPanelProps: Omit<{
|
27
|
+
rootElement: HTMLDivElement;
|
28
|
+
activeSchema: {
|
29
|
+
width: number;
|
30
|
+
height: number;
|
31
|
+
type: string;
|
32
|
+
position: {
|
33
|
+
x: number;
|
34
|
+
y: number;
|
35
|
+
};
|
36
|
+
data: string;
|
37
|
+
id: string;
|
38
|
+
key: string;
|
39
|
+
opacity?: number | undefined;
|
40
|
+
rotate?: number | undefined;
|
41
|
+
readOnly?: boolean | undefined;
|
42
|
+
readOnlyValue?: string | undefined;
|
43
|
+
};
|
44
|
+
activeElements: HTMLElement[];
|
45
|
+
changeSchemas: import("@pdfme/common").ChangeSchemas;
|
46
|
+
schemas: {
|
47
|
+
width: number;
|
48
|
+
height: number;
|
49
|
+
type: string;
|
50
|
+
position: {
|
51
|
+
x: number;
|
52
|
+
y: number;
|
53
|
+
};
|
54
|
+
data: string;
|
55
|
+
id: string;
|
56
|
+
key: string;
|
57
|
+
opacity?: number | undefined;
|
58
|
+
rotate?: number | undefined;
|
59
|
+
readOnly?: boolean | undefined;
|
60
|
+
readOnlyValue?: string | undefined;
|
61
|
+
}[];
|
62
|
+
pageSize: {
|
63
|
+
width: number;
|
64
|
+
height: number;
|
65
|
+
};
|
66
|
+
options: import("@pdfme/common").UIOptions;
|
67
|
+
theme: import("antd").GlobalToken;
|
68
|
+
i18n: (key: string) => string;
|
69
|
+
}, "rootElement">) => Record<string, Partial<import("form-render").SchemaBase>>) | Record<string, Partial<import("form-render").SchemaBase>>;
|
70
|
+
widgets?: Record<string, (props: import("@pdfme/common").PropPanelWidgetProps) => void> | undefined;
|
71
|
+
defaultValue: string;
|
72
|
+
};
|
73
|
+
pdf: (arg: import("@pdfme/common").PDFRenderProps<Shape>) => void | Promise<void>;
|
74
|
+
ui: (arg: import("@pdfme/common").UIRenderProps<Shape>) => void | Promise<void>;
|
75
|
+
};
|
76
|
+
export declare const ellipse: {
|
77
|
+
propPanel: {
|
78
|
+
defaultSchema: {
|
79
|
+
type: "ellipse" | "rectangle";
|
80
|
+
borderWidth: number;
|
81
|
+
borderColor: string;
|
82
|
+
color: string;
|
83
|
+
position: {
|
84
|
+
x: number;
|
85
|
+
y: number;
|
86
|
+
};
|
87
|
+
width: number;
|
88
|
+
height: number;
|
89
|
+
readOnly?: boolean | undefined;
|
90
|
+
readOnlyValue?: string | undefined;
|
91
|
+
rotate?: number | undefined;
|
92
|
+
opacity?: number | undefined;
|
93
|
+
};
|
94
|
+
schema: ((propPanelProps: Omit<{
|
95
|
+
rootElement: HTMLDivElement;
|
96
|
+
activeSchema: {
|
97
|
+
width: number;
|
98
|
+
height: number;
|
99
|
+
type: string;
|
100
|
+
position: {
|
101
|
+
x: number;
|
102
|
+
y: number;
|
103
|
+
};
|
104
|
+
data: string;
|
105
|
+
id: string;
|
106
|
+
key: string;
|
107
|
+
opacity?: number | undefined;
|
108
|
+
rotate?: number | undefined;
|
109
|
+
readOnly?: boolean | undefined;
|
110
|
+
readOnlyValue?: string | undefined;
|
111
|
+
};
|
112
|
+
activeElements: HTMLElement[];
|
113
|
+
changeSchemas: import("@pdfme/common").ChangeSchemas;
|
114
|
+
schemas: {
|
115
|
+
width: number;
|
116
|
+
height: number;
|
117
|
+
type: string;
|
118
|
+
position: {
|
119
|
+
x: number;
|
120
|
+
y: number;
|
121
|
+
};
|
122
|
+
data: string;
|
123
|
+
id: string;
|
124
|
+
key: string;
|
125
|
+
opacity?: number | undefined;
|
126
|
+
rotate?: number | undefined;
|
127
|
+
readOnly?: boolean | undefined;
|
128
|
+
readOnlyValue?: string | undefined;
|
129
|
+
}[];
|
130
|
+
pageSize: {
|
131
|
+
width: number;
|
132
|
+
height: number;
|
133
|
+
};
|
134
|
+
options: import("@pdfme/common").UIOptions;
|
135
|
+
theme: import("antd").GlobalToken;
|
136
|
+
i18n: (key: string) => string;
|
137
|
+
}, "rootElement">) => Record<string, Partial<import("form-render").SchemaBase>>) | Record<string, Partial<import("form-render").SchemaBase>>;
|
138
|
+
widgets?: Record<string, (props: import("@pdfme/common").PropPanelWidgetProps) => void> | undefined;
|
139
|
+
defaultValue: string;
|
140
|
+
};
|
141
|
+
pdf: (arg: import("@pdfme/common").PDFRenderProps<Shape>) => void | Promise<void>;
|
142
|
+
ui: (arg: import("@pdfme/common").UIRenderProps<Shape>) => void | Promise<void>;
|
143
|
+
};
|
144
|
+
export {};
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Plugin } from '@pdfme/common';
|
2
2
|
import type { TextSchema } from './types';
|
3
|
-
declare const
|
4
|
-
export default
|
3
|
+
declare const textSchema: Plugin<TextSchema>;
|
4
|
+
export default textSchema;
|
5
|
+
export declare const readOnlyText: Plugin<TextSchema>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Schema } from '@pdfme/common';
|
1
|
+
import { Schema, Mode } from '@pdfme/common';
|
2
2
|
export declare const convertForPdfLayoutProps: ({ schema, pageHeight, applyRotateTranslate, }: {
|
3
3
|
schema: Schema;
|
4
4
|
pageHeight: number;
|
@@ -24,3 +24,7 @@ export declare const rotatePoint: (point: {
|
|
24
24
|
y: number;
|
25
25
|
};
|
26
26
|
export declare const addAlphaToHex: (hex: string, alphaPercentage: number) => string;
|
27
|
+
export declare const isEditable: (mode: Mode, schema: Schema) => boolean;
|
28
|
+
export declare const hex2RgbColor: (hexString: string | undefined) => import("@pdfme/pdf-lib").RGB | undefined;
|
29
|
+
export declare const readFile: (input: File | FileList | null) => Promise<string | ArrayBuffer>;
|
30
|
+
export declare const createErrorElm: () => HTMLDivElement;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/schemas",
|
3
|
-
"version": "3.1
|
3
|
+
"version": "3.2.0-dev.1",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -32,7 +32,7 @@
|
|
32
32
|
}
|
33
33
|
},
|
34
34
|
"scripts": {
|
35
|
-
"
|
35
|
+
"dev": "tsc -p tsconfig.esm.json -w",
|
36
36
|
"build": "npm-run-all --parallel build:cjs build:esm",
|
37
37
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
38
38
|
"build:esm": "tsc -p tsconfig.esm.json",
|
@@ -43,8 +43,9 @@
|
|
43
43
|
"prettier": "prettier --write 'src/**/*.ts'"
|
44
44
|
},
|
45
45
|
"dependencies": {
|
46
|
-
"@pdfme/pdf-lib": "^1.
|
46
|
+
"@pdfme/pdf-lib": "^1.18.3",
|
47
47
|
"bwip-js": "^4.1.1",
|
48
|
+
"fast-xml-parser": "^4.3.2",
|
48
49
|
"fontkit": "^2.0.2"
|
49
50
|
},
|
50
51
|
"devDependencies": {
|
package/src/barcodes/helper.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { b64toUint8Array } from '@pdfme/common';
|
2
2
|
import bwipjs, { RenderOptions } from 'bwip-js';
|
3
3
|
import { Buffer } from 'buffer';
|
4
|
-
import { BARCODE_TYPES } from './constants.js';
|
4
|
+
import { BARCODE_TYPES, DEFAULT_BARCODE_INCLUDETEXT } from './constants.js';
|
5
5
|
import { BarcodeTypes } from './types';
|
6
6
|
|
7
7
|
// GTIN-13, GTIN-8, GTIN-12, GTIN-14
|
@@ -133,11 +133,20 @@ export const createBarCode = async (arg: {
|
|
133
133
|
backgroundColor?: string;
|
134
134
|
barColor?: string;
|
135
135
|
textColor?: string;
|
136
|
+
includetext?: boolean;
|
136
137
|
}): Promise<Buffer> => {
|
137
|
-
const {
|
138
|
+
const {
|
139
|
+
type,
|
140
|
+
input,
|
141
|
+
width,
|
142
|
+
height,
|
143
|
+
backgroundColor,
|
144
|
+
barColor,
|
145
|
+
textColor,
|
146
|
+
includetext = DEFAULT_BARCODE_INCLUDETEXT,
|
147
|
+
} = arg;
|
138
148
|
|
139
149
|
const bcid = barCodeType2Bcid(type);
|
140
|
-
const includetext = true;
|
141
150
|
const scale = 5;
|
142
151
|
const bwipjsArg: RenderOptions = { bcid, text: input, width, height, scale, includetext };
|
143
152
|
|
package/src/barcodes/index.ts
CHANGED
@@ -5,7 +5,7 @@ import type { BarcodeSchema, BarcodeTypes } from './types';
|
|
5
5
|
import { BARCODE_TYPES } from './constants.js';
|
6
6
|
import { Plugin } from '@pdfme/common';
|
7
7
|
|
8
|
-
const
|
8
|
+
const barcodes = BARCODE_TYPES.reduce(
|
9
9
|
(acc, type) =>
|
10
10
|
Object.assign(acc, {
|
11
11
|
[type]: { pdf: pdfRender, ui: uiRender, propPanel: getPropPanelByBarcodeType(type) },
|
@@ -13,4 +13,4 @@ const schemas = BARCODE_TYPES.reduce(
|
|
13
13
|
{} as Record<BarcodeTypes, Plugin<BarcodeSchema>>
|
14
14
|
);
|
15
15
|
|
16
|
-
export default
|
16
|
+
export default barcodes;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { PDFRenderProps } from '@pdfme/common';
|
2
|
-
import { convertForPdfLayoutProps } from '../
|
2
|
+
import { convertForPdfLayoutProps } from '../utils.js';
|
3
3
|
import type { BarcodeSchema } from './types';
|
4
4
|
import { createBarCode, validateBarcodeInput } from './helper.js';
|
5
5
|
|
6
6
|
const getBarcodeCacheKey = (schema: BarcodeSchema, value: string) => {
|
7
|
-
return `${schema.type}${schema.backgroundColor}${schema.barColor}${schema.textColor}${value}`;
|
7
|
+
return `${schema.type}${schema.backgroundColor}${schema.barColor}${schema.textColor}${value}${schema.includetext}`;
|
8
8
|
};
|
9
9
|
|
10
10
|
export const pdfRender = async (arg: PDFRenderProps<BarcodeSchema>) => {
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import type { PropPanel } from '@pdfme/common';
|
2
2
|
import type { BarcodeSchema } from './types';
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
DEFAULT_BARCODE_COLOR,
|
5
|
+
DEFAULT_BARCODE_BG_COLOR,
|
6
|
+
DEFAULT_BARCODE_INCLUDETEXT,
|
7
|
+
} from './constants.js';
|
4
8
|
import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
|
5
9
|
|
6
10
|
const defaultColors = {
|
@@ -8,6 +12,7 @@ const defaultColors = {
|
|
8
12
|
barColor: DEFAULT_BARCODE_COLOR,
|
9
13
|
};
|
10
14
|
const defaultTextColors = { textColor: DEFAULT_BARCODE_COLOR };
|
15
|
+
const defaultIncludetext = { includetext: DEFAULT_BARCODE_INCLUDETEXT };
|
11
16
|
const position = { x: 0, y: 0 };
|
12
17
|
const default40x20 = { width: 40, height: 20 };
|
13
18
|
|
@@ -31,6 +36,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
31
36
|
position,
|
32
37
|
...defaultColors,
|
33
38
|
...defaultTextColors,
|
39
|
+
...defaultIncludetext,
|
34
40
|
width: 80,
|
35
41
|
height: 7.2,
|
36
42
|
rotate: 0,
|
@@ -44,6 +50,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
44
50
|
position,
|
45
51
|
...defaultColors,
|
46
52
|
...defaultTextColors,
|
53
|
+
...defaultIncludetext,
|
47
54
|
...default40x20,
|
48
55
|
height: 16,
|
49
56
|
rotate: 0,
|
@@ -57,6 +64,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
57
64
|
position,
|
58
65
|
...defaultColors,
|
59
66
|
...defaultTextColors,
|
67
|
+
...defaultIncludetext,
|
60
68
|
...default40x20,
|
61
69
|
rotate: 0,
|
62
70
|
opacity: DEFAULT_OPACITY,
|
@@ -69,6 +77,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
69
77
|
position,
|
70
78
|
...defaultColors,
|
71
79
|
...defaultTextColors,
|
80
|
+
...defaultIncludetext,
|
72
81
|
...default40x20,
|
73
82
|
opacity: DEFAULT_OPACITY,
|
74
83
|
},
|
@@ -80,6 +89,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
80
89
|
position,
|
81
90
|
...defaultColors,
|
82
91
|
...defaultTextColors,
|
92
|
+
...defaultIncludetext,
|
83
93
|
...default40x20,
|
84
94
|
rotate: 0,
|
85
95
|
opacity: DEFAULT_OPACITY,
|
@@ -92,6 +102,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
92
102
|
position,
|
93
103
|
...defaultColors,
|
94
104
|
...defaultTextColors,
|
105
|
+
...defaultIncludetext,
|
95
106
|
...default40x20,
|
96
107
|
rotate: 0,
|
97
108
|
opacity: DEFAULT_OPACITY,
|
@@ -104,6 +115,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
104
115
|
position,
|
105
116
|
...defaultColors,
|
106
117
|
...defaultTextColors,
|
118
|
+
...defaultIncludetext,
|
107
119
|
...default40x20,
|
108
120
|
height: 12,
|
109
121
|
rotate: 0,
|
@@ -117,6 +129,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
117
129
|
position,
|
118
130
|
...defaultColors,
|
119
131
|
...defaultTextColors,
|
132
|
+
...defaultIncludetext,
|
120
133
|
...default40x20,
|
121
134
|
height: 16,
|
122
135
|
rotate: 0,
|
@@ -130,6 +143,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
130
143
|
position,
|
131
144
|
...defaultColors,
|
132
145
|
...defaultTextColors,
|
146
|
+
...defaultIncludetext,
|
133
147
|
...default40x20,
|
134
148
|
rotate: 0,
|
135
149
|
opacity: DEFAULT_OPACITY,
|
@@ -154,38 +168,44 @@ export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<Barcod
|
|
154
168
|
|
155
169
|
const defaults = barcodeDefaults.find(({ defaultSchema }) => defaultSchema.type === barcodeType);
|
156
170
|
|
157
|
-
if (!defaults)
|
171
|
+
if (!defaults)
|
172
|
+
throw new Error(`[@pdfme/schemas/barcodes] No default for barcode type ${barcodeType}`);
|
158
173
|
|
159
174
|
return {
|
160
|
-
schema: ({ i18n }) => {
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
175
|
+
schema: ({ i18n }) => ({
|
176
|
+
barColor: {
|
177
|
+
title: i18n('schemas.barcodes.barColor'),
|
178
|
+
type: 'string',
|
179
|
+
widget: 'color',
|
180
|
+
rules: [
|
181
|
+
{
|
182
|
+
pattern: HEX_COLOR_PATTERN,
|
183
|
+
message: i18n('hexColorPrompt'),
|
184
|
+
},
|
185
|
+
],
|
186
|
+
},
|
187
|
+
backgroundColor: {
|
188
|
+
title: i18n('schemas.bgColor'),
|
189
|
+
type: 'string',
|
190
|
+
widget: 'color',
|
191
|
+
rules: [
|
192
|
+
{
|
193
|
+
pattern: HEX_COLOR_PATTERN,
|
194
|
+
message: i18n('hexColorPrompt'),
|
195
|
+
},
|
196
|
+
],
|
197
|
+
},
|
198
|
+
...(barcodeHasText
|
199
|
+
? {
|
200
|
+
textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' },
|
201
|
+
includetext: {
|
202
|
+
title: i18n('schemas.barcodes.includetext'),
|
203
|
+
type: 'boolean',
|
204
|
+
widget: 'switch',
|
170
205
|
},
|
171
|
-
|
172
|
-
},
|
173
|
-
|
174
|
-
title: i18n('schemas.bgColor'),
|
175
|
-
type: 'string',
|
176
|
-
widget: 'color',
|
177
|
-
rules: [
|
178
|
-
{
|
179
|
-
pattern: HEX_COLOR_PATTERN,
|
180
|
-
message: 'Please enter a valid hex color code.',
|
181
|
-
},
|
182
|
-
],
|
183
|
-
},
|
184
|
-
...(barcodeHasText
|
185
|
-
? { textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' } }
|
186
|
-
: {}),
|
187
|
-
};
|
188
|
-
},
|
206
|
+
}
|
207
|
+
: {}),
|
208
|
+
}),
|
189
209
|
...defaults,
|
190
210
|
};
|
191
211
|
};
|
package/src/barcodes/types.ts
CHANGED
package/src/barcodes/uiRender.ts
CHANGED
@@ -2,37 +2,10 @@ import type * as CSS from 'csstype';
|
|
2
2
|
import { UIRenderProps } from '@pdfme/common';
|
3
3
|
import type { BarcodeSchema } from './types';
|
4
4
|
import { validateBarcodeInput, createBarCode } from './helper.js';
|
5
|
-
import { addAlphaToHex } from '../
|
5
|
+
import { addAlphaToHex, isEditable, createErrorElm } from '../utils.js';
|
6
6
|
|
7
7
|
const fullSize = { width: '100%', height: '100%' };
|
8
8
|
|
9
|
-
const createErrorBarcodeElm = () => {
|
10
|
-
const container = document.createElement('div');
|
11
|
-
const containerStyle: CSS.Properties = {
|
12
|
-
display: 'flex',
|
13
|
-
alignItems: 'center',
|
14
|
-
justifyContent: 'center',
|
15
|
-
...fullSize,
|
16
|
-
};
|
17
|
-
Object.assign(container.style, containerStyle);
|
18
|
-
|
19
|
-
const span = document.createElement('span');
|
20
|
-
const spanStyle: CSS.Properties = {
|
21
|
-
color: 'white',
|
22
|
-
background: 'red',
|
23
|
-
padding: '0.25rem',
|
24
|
-
fontSize: '12pt',
|
25
|
-
fontWeight: 'bold',
|
26
|
-
borderRadius: '2px',
|
27
|
-
};
|
28
|
-
Object.assign(span.style, spanStyle);
|
29
|
-
|
30
|
-
span.textContent = 'ERROR';
|
31
|
-
container.appendChild(span);
|
32
|
-
|
33
|
-
return container;
|
34
|
-
};
|
35
|
-
|
36
9
|
const blobToDataURL = (blob: Blob): Promise<string> =>
|
37
10
|
new Promise((resolve, reject) => {
|
38
11
|
const reader = new FileReader();
|
@@ -71,20 +44,20 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
71
44
|
alignItems: 'center',
|
72
45
|
justifyContent: 'center',
|
73
46
|
fontFamily: "'Open Sans', sans-serif",
|
74
|
-
opacity: schema.opacity,
|
75
47
|
};
|
76
48
|
Object.assign(container.style, containerStyle);
|
77
49
|
rootElement.appendChild(container);
|
78
|
-
const editable = mode
|
50
|
+
const editable = isEditable(mode, schema);
|
79
51
|
if (editable) {
|
80
52
|
const input = document.createElement('input');
|
81
53
|
const inputStyle: CSS.Properties = {
|
82
|
-
|
54
|
+
width: '100%',
|
83
55
|
position: 'absolute',
|
84
56
|
textAlign: 'center',
|
85
|
-
fontSize: '
|
86
|
-
|
87
|
-
|
57
|
+
fontSize: '12pt',
|
58
|
+
fontWeight: 'bold',
|
59
|
+
color: theme.colorWhite,
|
60
|
+
backgroundColor: editable || value ? addAlphaToHex('#000000', 80) : 'none',
|
88
61
|
border: 'none',
|
89
62
|
display: 'flex',
|
90
63
|
alignItems: 'center',
|
@@ -102,21 +75,18 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
102
75
|
stopEditing && stopEditing();
|
103
76
|
});
|
104
77
|
container.appendChild(input);
|
105
|
-
|
106
|
-
|
107
|
-
input.focus();
|
108
|
-
}
|
78
|
+
input.setSelectionRange(value.length, value.length);
|
79
|
+
input.focus();
|
109
80
|
}
|
110
81
|
|
111
82
|
if (!value) return;
|
112
83
|
try {
|
113
84
|
if (!validateBarcodeInput(schema.type, value))
|
114
|
-
throw new Error('[@pdfme/schemas] Invalid barcode input');
|
85
|
+
throw new Error('[@pdfme/schemas/barcodes] Invalid barcode input');
|
115
86
|
const imgElm = await createBarcodeImageElm(schema, value);
|
116
87
|
container.appendChild(imgElm);
|
117
88
|
} catch (err) {
|
118
89
|
console.error(`[@pdfme/ui] ${err}`);
|
119
|
-
|
120
|
-
container.appendChild(errorBarcodeElm);
|
90
|
+
container.appendChild(createErrorElm());
|
121
91
|
}
|
122
92
|
};
|
@@ -0,0 +1,147 @@
|
|
1
|
+
// ref: https://github.com/image-size/image-size ----------------------------
|
2
|
+
// The following code is adapted from the image-size code. Unnecessary formats and dependencies on Node have been removed.
|
3
|
+
type IImage = {
|
4
|
+
validate: (input: Uint8Array) => boolean;
|
5
|
+
calculate: (input: Uint8Array) => { width: number; height: number } | undefined;
|
6
|
+
};
|
7
|
+
|
8
|
+
const decoder = new TextDecoder();
|
9
|
+
const toUTF8String = (input: Uint8Array, start = 0, end = input.length) =>
|
10
|
+
decoder.decode(input.slice(start, end));
|
11
|
+
|
12
|
+
const toHexString = (input: Uint8Array, start = 0, end = input.length) =>
|
13
|
+
input.slice(start, end).reduce((memo, i) => memo + ('0' + i.toString(16)).slice(-2), '');
|
14
|
+
|
15
|
+
const readUInt16BE = (input: Uint8Array, offset = 0) => input[offset] * 2 ** 8 + input[offset + 1];
|
16
|
+
|
17
|
+
const readUInt32BE = (input: Uint8Array, offset = 0) =>
|
18
|
+
input[offset] * 2 ** 24 +
|
19
|
+
input[offset + 1] * 2 ** 16 +
|
20
|
+
input[offset + 2] * 2 ** 8 +
|
21
|
+
input[offset + 3];
|
22
|
+
|
23
|
+
const extractSize = (input: Uint8Array, index: number) => {
|
24
|
+
return {
|
25
|
+
height: readUInt16BE(input, index),
|
26
|
+
width: readUInt16BE(input, index + 2),
|
27
|
+
};
|
28
|
+
};
|
29
|
+
|
30
|
+
const validateInput = (input: Uint8Array, index: number): void => {
|
31
|
+
// index should be within buffer limits
|
32
|
+
if (index > input.length) {
|
33
|
+
throw new TypeError('Corrupt JPG, exceeded buffer limits');
|
34
|
+
}
|
35
|
+
// Every JPEG block must begin with a 0xFF
|
36
|
+
if (input[index] !== 0xff) {
|
37
|
+
throw new TypeError('Invalid JPG, marker table corrupted');
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
const JPG: IImage = {
|
42
|
+
validate: (input) => toHexString(input, 0, 2) === 'ffd8',
|
43
|
+
|
44
|
+
calculate(input) {
|
45
|
+
// Skip 4 chars, they are for signature
|
46
|
+
input = input.slice(4);
|
47
|
+
|
48
|
+
let next: number;
|
49
|
+
while (input.length) {
|
50
|
+
// read length of the next block
|
51
|
+
const i = readUInt16BE(input, 0);
|
52
|
+
|
53
|
+
// ensure correct format
|
54
|
+
validateInput(input, i);
|
55
|
+
|
56
|
+
// 0xFFC0 is baseline standard(SOF)
|
57
|
+
// 0xFFC1 is baseline optimized(SOF)
|
58
|
+
// 0xFFC2 is progressive(SOF2)
|
59
|
+
next = input[i + 1];
|
60
|
+
if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
|
61
|
+
const size = extractSize(input, i + 5);
|
62
|
+
|
63
|
+
return size;
|
64
|
+
}
|
65
|
+
|
66
|
+
// move to the next block
|
67
|
+
input = input.slice(i + 2);
|
68
|
+
}
|
69
|
+
|
70
|
+
throw new TypeError('Invalid JPG, no size found');
|
71
|
+
},
|
72
|
+
};
|
73
|
+
|
74
|
+
const pngSignature = 'PNG\r\n\x1a\n';
|
75
|
+
const pngImageHeaderChunkName = 'IHDR';
|
76
|
+
|
77
|
+
// Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
|
78
|
+
const pngFriedChunkName = 'CgBI';
|
79
|
+
|
80
|
+
const PNG: IImage = {
|
81
|
+
validate(input) {
|
82
|
+
if (pngSignature === toUTF8String(input, 1, 8)) {
|
83
|
+
let chunkName = toUTF8String(input, 12, 16);
|
84
|
+
if (chunkName === pngFriedChunkName) {
|
85
|
+
chunkName = toUTF8String(input, 28, 32);
|
86
|
+
}
|
87
|
+
if (chunkName !== pngImageHeaderChunkName) {
|
88
|
+
throw new TypeError('Invalid PNG');
|
89
|
+
}
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
return false;
|
93
|
+
},
|
94
|
+
|
95
|
+
calculate(input) {
|
96
|
+
if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
|
97
|
+
return {
|
98
|
+
height: readUInt32BE(input, 36),
|
99
|
+
width: readUInt32BE(input, 32),
|
100
|
+
};
|
101
|
+
}
|
102
|
+
return {
|
103
|
+
height: readUInt32BE(input, 20),
|
104
|
+
width: readUInt32BE(input, 16),
|
105
|
+
};
|
106
|
+
},
|
107
|
+
};
|
108
|
+
|
109
|
+
const typeHandlers = {
|
110
|
+
jpg: JPG,
|
111
|
+
png: PNG,
|
112
|
+
};
|
113
|
+
|
114
|
+
type imageType = keyof typeof typeHandlers;
|
115
|
+
|
116
|
+
function detector(input: Uint8Array): imageType | undefined {
|
117
|
+
const firstBytes: { [byte: number]: imageType } = {
|
118
|
+
0x89: 'png',
|
119
|
+
0xff: 'jpg',
|
120
|
+
};
|
121
|
+
const byte = input[0];
|
122
|
+
if (byte in firstBytes) {
|
123
|
+
const type = firstBytes[byte];
|
124
|
+
if (type && typeHandlers[type].validate(input)) {
|
125
|
+
return type;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
const keys = Object.keys(typeHandlers) as imageType[];
|
130
|
+
return keys.find((key: imageType) => typeHandlers[key].validate(input));
|
131
|
+
}
|
132
|
+
|
133
|
+
export const imageSize = (imgBuffer: Buffer): { height: number; width: number } => {
|
134
|
+
const type = detector(imgBuffer);
|
135
|
+
|
136
|
+
if (typeof type !== 'undefined' && type in typeHandlers) {
|
137
|
+
const size = typeHandlers[type].calculate(imgBuffer);
|
138
|
+
if (size !== undefined) {
|
139
|
+
return size;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
throw new TypeError(
|
144
|
+
'[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type)
|
145
|
+
);
|
146
|
+
};
|
147
|
+
// ----------------------------
|