@pdfme/schemas 3.1.5 → 3.2.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 +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/index.js +2 -2
- package/dist/cjs/src/barcodes/index.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +2 -2
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +28 -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/index.js +2 -2
- package/dist/esm/src/barcodes/index.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +1 -1
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +28 -30
- 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/index.d.ts +2 -2
- 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/index.ts +2 -2
- package/src/barcodes/pdfRender.ts +1 -1
- package/src/barcodes/propPanel.ts +28 -30
- 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,124 @@
|
|
|
1
|
+
import { degrees, degreesToRadians, rgb } from '@pdfme/pdf-lib';
|
|
2
|
+
import { mm2pt, isHexValid } from '@pdfme/common';
|
|
3
|
+
export const convertForPdfLayoutProps = ({ schema, pageHeight, applyRotateTranslate = true, }) => {
|
|
4
|
+
const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;
|
|
5
|
+
const { x: mmX, y: mmY } = position;
|
|
6
|
+
const rotateDegrees = rotate ? -rotate : 0;
|
|
7
|
+
const width = mm2pt(mmWidth);
|
|
8
|
+
const height = mm2pt(mmHeight);
|
|
9
|
+
let x = mm2pt(mmX);
|
|
10
|
+
// PDF coordinate system is from bottom left, UI is top left, so we need to flip the y axis
|
|
11
|
+
let y = pageHeight - mm2pt(mmY) - height;
|
|
12
|
+
if (rotateDegrees && applyRotateTranslate) {
|
|
13
|
+
// If rotating we must pivot around the same point as the UI performs its rotation.
|
|
14
|
+
// The UI performs rotation around the objects center point (the pivot point below),
|
|
15
|
+
// pdflib rotates around the bottom left corner of the object.
|
|
16
|
+
// We must therefore adjust the X and Y by rotating the bottom left corner by this pivot point.
|
|
17
|
+
const pivotPoint = { x: x + width / 2, y: pageHeight - mm2pt(mmY) - height / 2 };
|
|
18
|
+
const rotatedPoint = rotatePoint({ x, y }, pivotPoint, rotateDegrees);
|
|
19
|
+
x = rotatedPoint.x;
|
|
20
|
+
y = rotatedPoint.y;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
position: { x, y },
|
|
24
|
+
height: height,
|
|
25
|
+
width: width,
|
|
26
|
+
rotate: degrees(rotateDegrees),
|
|
27
|
+
opacity,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const rotatePoint = (point, pivot, angleDegrees) => {
|
|
31
|
+
const angleRadians = degreesToRadians(angleDegrees);
|
|
32
|
+
const x = Math.cos(angleRadians) * (point.x - pivot.x) -
|
|
33
|
+
Math.sin(angleRadians) * (point.y - pivot.y) +
|
|
34
|
+
pivot.x;
|
|
35
|
+
const y = Math.sin(angleRadians) * (point.x - pivot.x) +
|
|
36
|
+
Math.cos(angleRadians) * (point.y - pivot.y) +
|
|
37
|
+
pivot.y;
|
|
38
|
+
return { x, y };
|
|
39
|
+
};
|
|
40
|
+
export const addAlphaToHex = (hex, alphaPercentage) => {
|
|
41
|
+
if (!/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i.test(hex)) {
|
|
42
|
+
throw new Error('Invalid HEX color code');
|
|
43
|
+
}
|
|
44
|
+
const alphaValue = Math.round((alphaPercentage / 100) * 255);
|
|
45
|
+
let alphaHex = alphaValue.toString(16);
|
|
46
|
+
if (alphaHex.length === 1)
|
|
47
|
+
alphaHex = '0' + alphaHex;
|
|
48
|
+
return hex + alphaHex;
|
|
49
|
+
};
|
|
50
|
+
export const isEditable = (mode, schema) => mode === 'designer' || (mode === 'form' && schema.readOnly !== true);
|
|
51
|
+
const hex2rgb = (hex) => {
|
|
52
|
+
if (hex.slice(0, 1) === '#')
|
|
53
|
+
hex = hex.slice(1);
|
|
54
|
+
if (hex.length === 3)
|
|
55
|
+
hex =
|
|
56
|
+
hex.slice(0, 1) +
|
|
57
|
+
hex.slice(0, 1) +
|
|
58
|
+
hex.slice(1, 2) +
|
|
59
|
+
hex.slice(1, 2) +
|
|
60
|
+
hex.slice(2, 3) +
|
|
61
|
+
hex.slice(2, 3);
|
|
62
|
+
return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
|
|
63
|
+
};
|
|
64
|
+
export const hex2RgbColor = (hexString) => {
|
|
65
|
+
if (hexString) {
|
|
66
|
+
const isValid = isHexValid(hexString);
|
|
67
|
+
if (!isValid) {
|
|
68
|
+
throw new Error(`Invalid hex color value ${hexString}`);
|
|
69
|
+
}
|
|
70
|
+
const [r, g, b] = hex2rgb(hexString);
|
|
71
|
+
return rgb(r / 255, g / 255, b / 255);
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
};
|
|
75
|
+
export const readFile = (input) => new Promise((resolve, reject) => {
|
|
76
|
+
const fileReader = new FileReader();
|
|
77
|
+
fileReader.onload = (e) => {
|
|
78
|
+
if (e.target?.result) {
|
|
79
|
+
resolve(e.target.result);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
fileReader.onerror = (e) => {
|
|
83
|
+
reject(new Error('[@pdfme/schemas] File reading failed'));
|
|
84
|
+
};
|
|
85
|
+
let file = null;
|
|
86
|
+
if (input instanceof FileList && input.length > 0) {
|
|
87
|
+
file = input[0];
|
|
88
|
+
}
|
|
89
|
+
else if (input instanceof File) {
|
|
90
|
+
file = input;
|
|
91
|
+
}
|
|
92
|
+
if (file) {
|
|
93
|
+
fileReader.readAsDataURL(file);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
reject(new Error('[@pdfme/schemas] No files provided'));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
export const createErrorElm = () => {
|
|
100
|
+
const container = document.createElement('div');
|
|
101
|
+
const containerStyle = {
|
|
102
|
+
display: 'flex',
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
justifyContent: 'center',
|
|
105
|
+
width: '100%',
|
|
106
|
+
height: '100%',
|
|
107
|
+
};
|
|
108
|
+
Object.assign(container.style, containerStyle);
|
|
109
|
+
const span = document.createElement('span');
|
|
110
|
+
const spanStyle = {
|
|
111
|
+
color: 'white',
|
|
112
|
+
background: 'red',
|
|
113
|
+
padding: '0.25rem',
|
|
114
|
+
fontSize: '12pt',
|
|
115
|
+
fontWeight: 'bold',
|
|
116
|
+
borderRadius: '2px',
|
|
117
|
+
fontFamily: "'Open Sans', sans-serif",
|
|
118
|
+
};
|
|
119
|
+
Object.assign(span.style, spanStyle);
|
|
120
|
+
span.textContent = 'ERROR';
|
|
121
|
+
container.appendChild(span);
|
|
122
|
+
return container;
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAU,KAAK,EAAQ,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,MAAM,EACN,UAAU,EACV,oBAAoB,GAAG,IAAI,GAK5B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC/E,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAC;IAEpC,MAAM,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,KA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QAClB,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,MAAM;QAClB,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,yBAAyB;KACtC,CAAC;IACF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAErC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAC3B,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAE5B,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { BarcodeSchema } from './types';
|
|
2
2
|
import { Plugin } from '@pdfme/common';
|
|
3
|
-
declare const
|
|
4
|
-
export default
|
|
3
|
+
declare const barcodes: Record<"qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce" | "gs1datamatrix", Plugin<BarcodeSchema>>;
|
|
4
|
+
export default barcodes;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from '@pdfme/common';
|
|
2
|
+
import type { Schema } from '@pdfme/common';
|
|
3
|
+
interface ImageSchema extends Schema {
|
|
4
|
+
}
|
|
5
|
+
declare const imageSchema: Plugin<ImageSchema>;
|
|
6
|
+
export default imageSchema;
|
|
7
|
+
export declare const readOnlyImage: Plugin<ImageSchema>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import text from './text/index.js';
|
|
2
|
-
import image from './image
|
|
1
|
+
import text, { readOnlyText } from './text/index.js';
|
|
2
|
+
import image, { readOnlyImage } from './graphics/image.js';
|
|
3
|
+
import svg, { readOnlySvg } from './graphics/svg.js';
|
|
3
4
|
import barcodes from './barcodes/index.js';
|
|
4
|
-
import
|
|
5
|
+
import line from './shapes/line.js';
|
|
6
|
+
import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
|
|
7
|
+
import { convertForPdfLayoutProps, rotatePoint } from './utils.js';
|
|
5
8
|
declare const builtInPlugins: {
|
|
6
9
|
Text: import("@pdfme/common").Plugin<import("./text/types.js").TextSchema>;
|
|
7
10
|
};
|
|
8
|
-
export { text, image, barcodes, builtInPlugins, convertForPdfLayoutProps, rotatePoint };
|
|
11
|
+
export { text, readOnlyText, image, readOnlyImage, svg, readOnlySvg, barcodes, line, rectangle, ellipse, builtInPlugins, convertForPdfLayoutProps, rotatePoint, };
|
|
@@ -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.
|
|
3
|
+
"version": "3.2.0",
|
|
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/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,5 +1,5 @@
|
|
|
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
|
|
|
@@ -154,38 +154,36 @@ export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<Barcod
|
|
|
154
154
|
|
|
155
155
|
const defaults = barcodeDefaults.find(({ defaultSchema }) => defaultSchema.type === barcodeType);
|
|
156
156
|
|
|
157
|
-
if (!defaults) throw new Error(`[@pdfme/schemas] No default for barcode type ${barcodeType}`);
|
|
157
|
+
if (!defaults) throw new Error(`[@pdfme/schemas/barcodes] No default for barcode type ${barcodeType}`);
|
|
158
158
|
|
|
159
159
|
return {
|
|
160
|
-
schema: ({ i18n }) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
188
|
-
},
|
|
160
|
+
schema: ({ i18n }) => ({
|
|
161
|
+
barColor: {
|
|
162
|
+
title: i18n('schemas.barcodes.barColor'),
|
|
163
|
+
type: 'string',
|
|
164
|
+
widget: 'color',
|
|
165
|
+
rules: [
|
|
166
|
+
{
|
|
167
|
+
pattern: HEX_COLOR_PATTERN,
|
|
168
|
+
message: i18n('hexColorPrompt'),
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
backgroundColor: {
|
|
173
|
+
title: i18n('schemas.bgColor'),
|
|
174
|
+
type: 'string',
|
|
175
|
+
widget: 'color',
|
|
176
|
+
rules: [
|
|
177
|
+
{
|
|
178
|
+
pattern: HEX_COLOR_PATTERN,
|
|
179
|
+
message: i18n('hexColorPrompt'),
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
...(barcodeHasText
|
|
184
|
+
? { textColor: { title: i18n('schemas.textColor'), type: 'string', widget: 'color' } }
|
|
185
|
+
: {}),
|
|
186
|
+
}),
|
|
189
187
|
...defaults,
|
|
190
188
|
};
|
|
191
189
|
};
|
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
|
};
|