@pdfme/schemas 3.1.5-dev.9 → 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/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 +1 -1
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +9 -32
- 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 -11
- 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 +5 -5
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +3 -3
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/{renderUtils.js → utils.js} +55 -7
- 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 +1 -1
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +9 -32
- 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 -5
- 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 +1 -1
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +2 -2
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/{renderUtils.js → utils.js} +52 -6
- 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 -5
- 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} +3 -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 +1 -1
- package/src/barcodes/uiRender.ts +9 -36
- 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 -5
- 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 +17 -2
- package/src/text/pdfRender.ts +2 -2
- package/src/text/uiRender.ts +2 -2
- package/src/{renderUtils.ts → utils.ts} +61 -5
- 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 -22
- 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/line/constants.js +0 -5
- package/dist/cjs/src/line/constants.js.map +0 -1
- package/dist/cjs/src/line/index.js +0 -8
- package/dist/cjs/src/line/index.js.map +0 -1
- package/dist/cjs/src/line/pdfRender.js +0 -20
- package/dist/cjs/src/line/pdfRender.js.map +0 -1
- package/dist/cjs/src/line/propPanel.js +0 -35
- package/dist/cjs/src/line/propPanel.js.map +0 -1
- package/dist/cjs/src/line/types.js +0 -3
- package/dist/cjs/src/line/types.js.map +0 -1
- package/dist/cjs/src/line/uiRender.js +0 -14
- package/dist/cjs/src/line/uiRender.js.map +0 -1
- 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 -18
- 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/line/constants.js +0 -2
- package/dist/esm/src/line/constants.js.map +0 -1
- package/dist/esm/src/line/index.js +0 -6
- package/dist/esm/src/line/index.js.map +0 -1
- package/dist/esm/src/line/pdfRender.js +0 -16
- package/dist/esm/src/line/pdfRender.js.map +0 -1
- package/dist/esm/src/line/propPanel.js +0 -32
- package/dist/esm/src/line/propPanel.js.map +0 -1
- package/dist/esm/src/line/types.js +0 -2
- package/dist/esm/src/line/types.js.map +0 -1
- package/dist/esm/src/line/uiRender.js +0 -10
- package/dist/esm/src/line/uiRender.js.map +0 -1
- 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/dist/types/src/line/constants.d.ts +0 -1
- package/dist/types/src/line/index.d.ts +0 -4
- package/dist/types/src/line/pdfRender.d.ts +0 -3
- package/dist/types/src/line/propPanel.d.ts +0 -3
- package/dist/types/src/line/types.d.ts +0 -4
- package/dist/types/src/line/uiRender.d.ts +0 -3
- package/src/image/index.ts +0 -8
- package/src/image/pdfRender.ts +0 -29
- package/src/image/propPanel.ts +0 -19
- package/src/image/types.ts +0 -3
- package/src/image/uiRender.ts +0 -121
- package/src/line/constants.ts +0 -1
- package/src/line/index.ts +0 -8
- package/src/line/pdfRender.ts +0 -24
- package/src/line/propPanel.ts +0 -34
- package/src/line/types.ts +0 -5
- package/src/line/uiRender.ts +0 -12
- /package/dist/types/__tests__/{renderUtils.test.d.ts → utils.test.d.ts} +0 -0
package/src/image/uiRender.ts
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
import type { ChangeEvent } from 'react';
|
2
|
-
import type * as CSS from 'csstype';
|
3
|
-
import type { ImageSchema } from './types';
|
4
|
-
import { UIRenderProps, ZOOM } from '@pdfme/common';
|
5
|
-
import { addAlphaToHex, isEditable } from '../renderUtils.js';
|
6
|
-
|
7
|
-
const fullSize = { width: '100%', height: '100%' };
|
8
|
-
|
9
|
-
const readFile = (input: File | FileList | null): Promise<string | ArrayBuffer> =>
|
10
|
-
new Promise((resolve, reject) => {
|
11
|
-
const fileReader = new FileReader();
|
12
|
-
|
13
|
-
fileReader.onload = (e) => {
|
14
|
-
if (e.target?.result) {
|
15
|
-
resolve(e.target.result);
|
16
|
-
}
|
17
|
-
};
|
18
|
-
|
19
|
-
fileReader.onerror = (e) => {
|
20
|
-
reject(new Error('[@pdfme/schemas] File reading failed'));
|
21
|
-
};
|
22
|
-
|
23
|
-
let file: File | null = null;
|
24
|
-
if (input instanceof FileList && input.length > 0) {
|
25
|
-
file = input[0];
|
26
|
-
} else if (input instanceof File) {
|
27
|
-
file = input;
|
28
|
-
}
|
29
|
-
|
30
|
-
if (file) {
|
31
|
-
fileReader.readAsDataURL(file);
|
32
|
-
} else {
|
33
|
-
reject(new Error('[@pdfme/schemas] No files provided'));
|
34
|
-
}
|
35
|
-
});
|
36
|
-
|
37
|
-
export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
|
38
|
-
const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
|
39
|
-
arg;
|
40
|
-
const editable = isEditable(mode);
|
41
|
-
|
42
|
-
const size = { width: schema.width * ZOOM, height: schema.height * ZOOM };
|
43
|
-
|
44
|
-
const container = document.createElement('div');
|
45
|
-
const backgroundStyle = placeholder ? `url(${placeholder})` : 'none';
|
46
|
-
const containerStyle: CSS.Properties = {
|
47
|
-
...fullSize,
|
48
|
-
backgroundImage: value ? 'none' : backgroundStyle,
|
49
|
-
backgroundSize: `${size.width}px ${size.height}px`,
|
50
|
-
};
|
51
|
-
Object.assign(container.style, containerStyle);
|
52
|
-
container.addEventListener('click', (e) => {
|
53
|
-
if (editable) {
|
54
|
-
e.stopPropagation();
|
55
|
-
}
|
56
|
-
});
|
57
|
-
rootElement.appendChild(container);
|
58
|
-
|
59
|
-
// image tag
|
60
|
-
if (value) {
|
61
|
-
const img = document.createElement('img');
|
62
|
-
const imgStyle: CSS.Properties = { height: '100%', width: '100%', borderRadius: 0 };
|
63
|
-
Object.assign(img.style, imgStyle);
|
64
|
-
img.src = value;
|
65
|
-
container.appendChild(img);
|
66
|
-
}
|
67
|
-
|
68
|
-
// remove button
|
69
|
-
if (value && editable) {
|
70
|
-
const button = document.createElement('button');
|
71
|
-
button.textContent = 'x';
|
72
|
-
const buttonStyle: CSS.Properties = {
|
73
|
-
position: 'absolute',
|
74
|
-
top: 0,
|
75
|
-
left: 0,
|
76
|
-
zIndex: 1,
|
77
|
-
display: 'flex',
|
78
|
-
justifyContent: 'center',
|
79
|
-
alignItems: 'center',
|
80
|
-
color: '#333',
|
81
|
-
background: '#f2f2f2',
|
82
|
-
borderRadius: '2px',
|
83
|
-
border: '1px solid #767676',
|
84
|
-
cursor: 'pointer',
|
85
|
-
height: '24px',
|
86
|
-
width: '24px',
|
87
|
-
};
|
88
|
-
Object.assign(button.style, buttonStyle);
|
89
|
-
button.addEventListener('click', () => {
|
90
|
-
onChange && onChange('');
|
91
|
-
});
|
92
|
-
container.appendChild(button);
|
93
|
-
}
|
94
|
-
|
95
|
-
// file input
|
96
|
-
if (!value && editable) {
|
97
|
-
const label = document.createElement('label');
|
98
|
-
const labelStyle: CSS.Properties = {
|
99
|
-
...fullSize,
|
100
|
-
display: editable ? 'flex' : 'none',
|
101
|
-
position: 'absolute',
|
102
|
-
top: 0,
|
103
|
-
backgroundColor: editable || value ? addAlphaToHex(theme.colorPrimaryBg, 30) : 'none',
|
104
|
-
cursor: 'pointer',
|
105
|
-
};
|
106
|
-
Object.assign(label.style, labelStyle);
|
107
|
-
container.appendChild(label);
|
108
|
-
const input = document.createElement('input');
|
109
|
-
const inputStyle: CSS.Properties = { ...fullSize, position: 'absolute', top: '50%' };
|
110
|
-
Object.assign(input.style, inputStyle);
|
111
|
-
input.tabIndex = tabIndex || 0;
|
112
|
-
input.type = 'file';
|
113
|
-
input.accept = 'image/jpeg, image/png';
|
114
|
-
input.addEventListener('change', (event: Event) => {
|
115
|
-
const changeEvent = event as unknown as ChangeEvent<HTMLInputElement>;
|
116
|
-
readFile(changeEvent.target.files).then((result) => onChange && onChange(result as string));
|
117
|
-
});
|
118
|
-
input.addEventListener('blur', () => stopEditing && stopEditing());
|
119
|
-
label.appendChild(input);
|
120
|
-
}
|
121
|
-
};
|
package/src/line/constants.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export const DEFAULT_LINE_COLOR = '#000000';
|
package/src/line/index.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import type { Plugin } from '@pdfme/common';
|
2
|
-
import { pdfRender } from './pdfRender.js';
|
3
|
-
import { propPanel } from './propPanel.js';
|
4
|
-
import { uiRender } from './uiRender.js';
|
5
|
-
import type { LineSchema } from './types.js';
|
6
|
-
|
7
|
-
const schema: Plugin<LineSchema> = { pdf: pdfRender, ui: uiRender, propPanel };
|
8
|
-
export default schema;
|
package/src/line/pdfRender.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import type { PDFRenderProps } from '@pdfme/common';
|
2
|
-
import type { LineSchema } from './types';
|
3
|
-
import { rotatePoint, convertForPdfLayoutProps, hex2RgbColor } from '../renderUtils.js';
|
4
|
-
import { DEFAULT_LINE_COLOR } from './constants.js';
|
5
|
-
|
6
|
-
export const pdfRender = (arg: PDFRenderProps<LineSchema>) => {
|
7
|
-
const { page, schema } = arg;
|
8
|
-
const pageHeight = page.getHeight();
|
9
|
-
const {
|
10
|
-
width,
|
11
|
-
height,
|
12
|
-
rotate,
|
13
|
-
position: { x, y },
|
14
|
-
opacity,
|
15
|
-
} = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
|
16
|
-
const pivot = { x: x + width / 2, y: y + height / 2 };
|
17
|
-
page.drawLine({
|
18
|
-
start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
|
19
|
-
end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
|
20
|
-
thickness: height,
|
21
|
-
color: hex2RgbColor(schema.color ?? DEFAULT_LINE_COLOR),
|
22
|
-
opacity: opacity,
|
23
|
-
});
|
24
|
-
};
|
package/src/line/propPanel.ts
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import { PropPanel } from '@pdfme/common';
|
2
|
-
import type { LineSchema } from './types';
|
3
|
-
import { HEX_COLOR_PATTERN } from '../constants.js';
|
4
|
-
import { DEFAULT_LINE_COLOR } from './constants.js';
|
5
|
-
|
6
|
-
export const propPanel: PropPanel<LineSchema> = {
|
7
|
-
schema: ({ i18n }) => {
|
8
|
-
return {
|
9
|
-
color: {
|
10
|
-
title: i18n('schemas.line.color'),
|
11
|
-
type: 'string',
|
12
|
-
widget: 'color',
|
13
|
-
required: true,
|
14
|
-
rules: [
|
15
|
-
{
|
16
|
-
pattern: HEX_COLOR_PATTERN,
|
17
|
-
message: i18n('hexColorPrompt'),
|
18
|
-
},
|
19
|
-
],
|
20
|
-
},
|
21
|
-
};
|
22
|
-
},
|
23
|
-
defaultValue: '',
|
24
|
-
defaultSchema: {
|
25
|
-
type: 'line',
|
26
|
-
position: { x: 0, y: 0 },
|
27
|
-
width: 50,
|
28
|
-
height: 1,
|
29
|
-
rotate: 0,
|
30
|
-
opacity: 1,
|
31
|
-
readOnly: true,
|
32
|
-
color: DEFAULT_LINE_COLOR,
|
33
|
-
},
|
34
|
-
};
|
package/src/line/types.ts
DELETED
package/src/line/uiRender.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { LineSchema } from './types';
|
2
|
-
import { UIRenderProps } from '@pdfme/common';
|
3
|
-
import { DEFAULT_LINE_COLOR } from './constants.js';
|
4
|
-
|
5
|
-
export const uiRender = (arg: UIRenderProps<LineSchema>) => {
|
6
|
-
const { schema, rootElement } = arg;
|
7
|
-
const div = document.createElement('div');
|
8
|
-
div.style.backgroundColor = schema.color ?? DEFAULT_LINE_COLOR;
|
9
|
-
div.style.width = '100%';
|
10
|
-
div.style.height = '100%';
|
11
|
-
rootElement.appendChild(div);
|
12
|
-
};
|
File without changes
|