@pdfme/schemas 6.0.3 → 6.0.4-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/dist/barcodes/constants.d.ts +4 -0
- package/dist/barcodes/helper.d.ts +21 -0
- package/dist/barcodes/index.d.ts +4 -0
- package/dist/barcodes/pdfRender.d.ts +3 -0
- package/dist/barcodes/propPanel.d.ts +3 -0
- package/{src/barcodes/types.ts → dist/barcodes/types.d.ts} +5 -7
- package/dist/barcodes/uiRender.d.ts +3 -0
- package/dist/builtins-CgaZ0UX3.js +613 -0
- package/dist/builtins-CgaZ0UX3.js.map +1 -0
- package/dist/builtins.d.ts +4 -0
- package/dist/builtins.js +2 -0
- package/dist/checkbox/index.d.ts +6 -0
- package/dist/constants.d.ts +2 -0
- package/dist/date/date.d.ts +2 -0
- package/dist/date/dateTime.d.ts +2 -0
- package/dist/date/helper.d.ts +20 -0
- package/dist/date/time.d.ts +2 -0
- package/dist/date/types.d.ts +17 -0
- package/dist/dynamicTemplate-D_DHR3-X.js +1128 -0
- package/dist/dynamicTemplate-D_DHR3-X.js.map +1 -0
- package/dist/graphics/image.d.ts +5 -0
- package/dist/graphics/imagehelper.d.ts +4 -0
- package/dist/graphics/signature.d.ts +4 -0
- package/dist/graphics/svg.d.ts +4 -0
- package/{src/index.ts → dist/index.d.ts} +1 -22
- package/dist/index.js +5383 -0
- package/dist/index.js.map +1 -0
- package/dist/multiVariableText/helper.d.ts +3 -0
- package/dist/multiVariableText/index.d.ts +4 -0
- package/dist/multiVariableText/pdfRender.d.ts +3 -0
- package/dist/multiVariableText/propPanel.d.ts +3 -0
- package/{src/multiVariableText/types.ts → dist/multiVariableText/types.d.ts} +2 -3
- package/dist/multiVariableText/uiRender.d.ts +3 -0
- package/dist/multiVariableText/variables.d.ts +10 -0
- package/dist/radioGroup/index.d.ts +7 -0
- package/dist/sanitize.d.ts +1 -0
- package/dist/select/index.d.ts +7 -0
- package/dist/shapes/line.d.ts +6 -0
- package/dist/shapes/rectAndEllipse.d.ts +11 -0
- package/dist/tables/cell.d.ts +4 -0
- package/dist/tables/classes.d.ts +69 -0
- package/dist/tables/dynamicTemplate.d.ts +7 -0
- package/dist/tables/helper.d.ts +265 -0
- package/dist/tables/index.d.ts +4 -0
- package/dist/tables/pdfRender.d.ts +3 -0
- package/dist/tables/propPanel.d.ts +3 -0
- package/dist/tables/tableHelper.d.ts +10 -0
- package/dist/tables/types.d.ts +88 -0
- package/dist/tables/uiRender.d.ts +3 -0
- package/dist/tables.js +2 -0
- package/dist/text/constants.d.ts +23 -0
- package/dist/text/extraFormatter.d.ts +25 -0
- package/dist/text/helper.d.ts +40 -0
- package/dist/text/icons/index.d.ts +9 -0
- package/dist/text/index.d.ts +4 -0
- package/dist/text/pdfRender.d.ts +3 -0
- package/dist/text/propPanel.d.ts +3 -0
- package/dist/text/types.d.ts +28 -0
- package/dist/text/uiRender.d.ts +11 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.js +215 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -1
- package/src/barcodes/constants.ts +0 -20
- package/src/barcodes/helper.ts +0 -187
- package/src/barcodes/index.ts +0 -23
- package/src/barcodes/pdfRender.ts +0 -37
- package/src/barcodes/propPanel.ts +0 -249
- package/src/barcodes/uiRender.ts +0 -94
- package/src/builtins.ts +0 -8
- package/src/checkbox/index.ts +0 -70
- package/src/constants.ts +0 -2
- package/src/date/date.ts +0 -9
- package/src/date/dateTime.ts +0 -9
- package/src/date/helper.ts +0 -544
- package/src/date/time.ts +0 -9
- package/src/date/types.ts +0 -19
- package/src/graphics/image.ts +0 -201
- package/src/graphics/imagehelper.ts +0 -156
- package/src/graphics/signature.ts +0 -136
- package/src/graphics/svg.ts +0 -121
- package/src/multiVariableText/helper.ts +0 -65
- package/src/multiVariableText/index.ts +0 -16
- package/src/multiVariableText/pdfRender.ts +0 -21
- package/src/multiVariableText/propPanel.ts +0 -169
- package/src/multiVariableText/uiRender.ts +0 -157
- package/src/multiVariableText/variables.ts +0 -63
- package/src/radioGroup/index.ts +0 -115
- package/src/sanitize.ts +0 -50
- package/src/select/index.ts +0 -205
- package/src/shapes/line.ts +0 -94
- package/src/shapes/rectAndEllipse.ts +0 -152
- package/src/tables/cell.ts +0 -152
- package/src/tables/classes.ts +0 -402
- package/src/tables/dynamicTemplate.ts +0 -88
- package/src/tables/helper.ts +0 -216
- package/src/tables/index.ts +0 -15
- package/src/tables/pdfRender.ts +0 -144
- package/src/tables/propPanel.ts +0 -111
- package/src/tables/tableHelper.ts +0 -289
- package/src/tables/types.ts +0 -87
- package/src/tables/uiRender.ts +0 -436
- package/src/text/constants.ts +0 -104
- package/src/text/extraFormatter.ts +0 -83
- package/src/text/helper.ts +0 -573
- package/src/text/icons/index.ts +0 -30
- package/src/text/index.ts +0 -16
- package/src/text/pdfRender.ts +0 -240
- package/src/text/propPanel.ts +0 -184
- package/src/text/types.ts +0 -30
- package/src/text/uiRender.ts +0 -292
- package/src/utils.ts +0 -354
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -16
- package/vite.config.mts +0 -51
- /package/{src/tables.ts → dist/tables.d.ts} +0 -0
package/src/select/index.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type * as CSS from 'csstype';
|
|
2
|
-
import { propPanel as parentPropPanel } from '../text/propPanel.js';
|
|
3
|
-
import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common';
|
|
4
|
-
import text from '../text/index.js';
|
|
5
|
-
import { TextSchema } from '../text/types.js';
|
|
6
|
-
import { ChevronDown } from 'lucide';
|
|
7
|
-
import { createSvgStr } from '../utils.js';
|
|
8
|
-
|
|
9
|
-
const selectIcon = createSvgStr(ChevronDown);
|
|
10
|
-
|
|
11
|
-
interface Select extends TextSchema {
|
|
12
|
-
options: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const addOptions = (props: PropPanelWidgetProps) => {
|
|
16
|
-
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
|
17
|
-
|
|
18
|
-
rootElement.style.width = '100%';
|
|
19
|
-
|
|
20
|
-
const selectSchema = activeSchema as SchemaForUI & Select;
|
|
21
|
-
const currentOptions = selectSchema.options ? [...selectSchema.options] : [];
|
|
22
|
-
|
|
23
|
-
const inputStyle = {
|
|
24
|
-
width: '100%',
|
|
25
|
-
padding: '6.25px 11px',
|
|
26
|
-
border: '1px solid #ccc',
|
|
27
|
-
borderRadius: '4px',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const buttonStyle = { border: 'none', borderRadius: '4px', cursor: 'pointer' };
|
|
31
|
-
|
|
32
|
-
const updateSchemas = () => {
|
|
33
|
-
changeSchemas([
|
|
34
|
-
{ key: 'options', value: currentOptions, schemaId: activeSchema.id },
|
|
35
|
-
{ key: 'content', value: currentOptions[0] || '', schemaId: activeSchema.id },
|
|
36
|
-
]);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const formContainer = document.createElement('div');
|
|
40
|
-
Object.assign(formContainer.style, {
|
|
41
|
-
width: '100%',
|
|
42
|
-
display: 'flex',
|
|
43
|
-
alignItems: 'center',
|
|
44
|
-
marginBottom: '10px',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const input = document.createElement('input');
|
|
48
|
-
input.type = 'text';
|
|
49
|
-
input.placeholder = i18n('schemas.select.optionPlaceholder');
|
|
50
|
-
Object.assign(input.style, inputStyle, { marginRight: '10px' });
|
|
51
|
-
|
|
52
|
-
const addButton = document.createElement('button');
|
|
53
|
-
addButton.textContent = '+';
|
|
54
|
-
Object.assign(addButton.style, buttonStyle, {
|
|
55
|
-
width: '25px',
|
|
56
|
-
height: '25px',
|
|
57
|
-
padding: '4px 8px',
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
addButton.addEventListener('click', () => {
|
|
61
|
-
const newValue = input.value.trim();
|
|
62
|
-
if (newValue) {
|
|
63
|
-
currentOptions.push(newValue);
|
|
64
|
-
updateSchemas();
|
|
65
|
-
renderOptions();
|
|
66
|
-
input.value = '';
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
formContainer.appendChild(input);
|
|
71
|
-
formContainer.appendChild(addButton);
|
|
72
|
-
|
|
73
|
-
const optionsList = document.createElement('ul');
|
|
74
|
-
Object.assign(optionsList.style, { listStyle: 'none', padding: '0' });
|
|
75
|
-
|
|
76
|
-
const renderOptions = () => {
|
|
77
|
-
optionsList.innerHTML = '';
|
|
78
|
-
currentOptions.forEach((option, index) => {
|
|
79
|
-
const li = document.createElement('li');
|
|
80
|
-
Object.assign(li.style, { display: 'flex', alignItems: 'center', marginBottom: '5px' });
|
|
81
|
-
|
|
82
|
-
const optionInput = document.createElement('input');
|
|
83
|
-
optionInput.type = 'text';
|
|
84
|
-
optionInput.value = option;
|
|
85
|
-
Object.assign(optionInput.style, inputStyle, { marginRight: '10px' });
|
|
86
|
-
|
|
87
|
-
optionInput.addEventListener('change', () => {
|
|
88
|
-
currentOptions[index] = optionInput.value;
|
|
89
|
-
updateSchemas();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const removeButton = document.createElement('button');
|
|
93
|
-
removeButton.textContent = 'x';
|
|
94
|
-
Object.assign(removeButton.style, buttonStyle, { padding: '4px 8px' });
|
|
95
|
-
|
|
96
|
-
removeButton.addEventListener('click', () => {
|
|
97
|
-
currentOptions.splice(index, 1);
|
|
98
|
-
updateSchemas();
|
|
99
|
-
renderOptions();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
li.appendChild(optionInput);
|
|
103
|
-
li.appendChild(removeButton);
|
|
104
|
-
optionsList.appendChild(li);
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
rootElement.appendChild(formContainer);
|
|
109
|
-
rootElement.appendChild(optionsList);
|
|
110
|
-
|
|
111
|
-
renderOptions();
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const schema: Plugin<Select> = {
|
|
115
|
-
ui: async (arg) => {
|
|
116
|
-
const { schema, value, onChange, rootElement, mode } = arg;
|
|
117
|
-
await text.ui(Object.assign(arg, { mode: 'viewer' }));
|
|
118
|
-
|
|
119
|
-
if (mode !== 'viewer' && !(mode === 'form' && schema.readOnly)) {
|
|
120
|
-
const buttonWidth = 30;
|
|
121
|
-
const selectButton = document.createElement('button');
|
|
122
|
-
selectButton.innerHTML = selectIcon;
|
|
123
|
-
const selectButtonStyle: CSS.Properties = {
|
|
124
|
-
position: 'absolute',
|
|
125
|
-
zIndex: -1,
|
|
126
|
-
right: `-${buttonWidth}px`,
|
|
127
|
-
top: '0',
|
|
128
|
-
padding: '0',
|
|
129
|
-
margin: '0',
|
|
130
|
-
cursor: 'pointer',
|
|
131
|
-
height: `${buttonWidth}px`,
|
|
132
|
-
width: `${buttonWidth}px`,
|
|
133
|
-
};
|
|
134
|
-
Object.assign(selectButton.style, selectButtonStyle);
|
|
135
|
-
|
|
136
|
-
rootElement.appendChild(selectButton);
|
|
137
|
-
|
|
138
|
-
const selectElement = document.createElement('select');
|
|
139
|
-
const selectElementStyle: CSS.Properties = {
|
|
140
|
-
opacity: '0',
|
|
141
|
-
position: 'absolute',
|
|
142
|
-
width: `calc(100% + ${buttonWidth}px)`,
|
|
143
|
-
height: '100%',
|
|
144
|
-
top: '0',
|
|
145
|
-
left: '0',
|
|
146
|
-
appearance: 'initial',
|
|
147
|
-
};
|
|
148
|
-
Object.assign(selectElement.style, selectElementStyle);
|
|
149
|
-
selectElement.value = value;
|
|
150
|
-
|
|
151
|
-
selectElement.addEventListener('change', (e) => {
|
|
152
|
-
if (onChange && e.target instanceof HTMLSelectElement) {
|
|
153
|
-
if (onChange) onChange({ key: 'content', value: e.target.value });
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Ensure schema.options is an array before mapping
|
|
158
|
-
const options = Array.isArray(schema.options) ? schema.options : [];
|
|
159
|
-
options.forEach((option) => {
|
|
160
|
-
const optionElement = document.createElement('option');
|
|
161
|
-
optionElement.value = option;
|
|
162
|
-
optionElement.textContent = option;
|
|
163
|
-
if (option === value) optionElement.selected = true;
|
|
164
|
-
selectElement.appendChild(optionElement);
|
|
165
|
-
});
|
|
166
|
-
rootElement.appendChild(selectElement);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
pdf: text.pdf,
|
|
170
|
-
propPanel: {
|
|
171
|
-
...text.propPanel,
|
|
172
|
-
widgets: { ...parentPropPanel.widgets, addOptions },
|
|
173
|
-
schema: (propPanelProps: Omit<PropPanelWidgetProps, 'rootElement'>) => {
|
|
174
|
-
if (typeof parentPropPanel.schema !== 'function') {
|
|
175
|
-
throw Error('Oops, is text schema no longer a function?');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Safely call the parent schema function with proper type checking
|
|
179
|
-
const parentSchema = parentPropPanel.schema(propPanelProps);
|
|
180
|
-
|
|
181
|
-
// Create a type-safe return object
|
|
182
|
-
return {
|
|
183
|
-
...parentSchema,
|
|
184
|
-
'-------': { type: 'void', widget: 'Divider' },
|
|
185
|
-
|
|
186
|
-
optionsContainer: {
|
|
187
|
-
title: (propPanelProps as PropPanelWidgetProps).i18n('schemas.select.options'),
|
|
188
|
-
type: 'string',
|
|
189
|
-
widget: 'Card',
|
|
190
|
-
span: 24,
|
|
191
|
-
properties: { options: { widget: 'addOptions', span: 24 } },
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
},
|
|
195
|
-
defaultSchema: {
|
|
196
|
-
...(text.propPanel.defaultSchema as TextSchema),
|
|
197
|
-
type: 'select',
|
|
198
|
-
content: 'option1',
|
|
199
|
-
options: ['option1', 'option2'],
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
icon: selectIcon,
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export default schema;
|
package/src/shapes/line.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { Schema, Plugin } from '@pdfme/common';
|
|
2
|
-
import {
|
|
3
|
-
rotatePoint,
|
|
4
|
-
convertForPdfLayoutProps,
|
|
5
|
-
hex2PrintingColor,
|
|
6
|
-
createSvgStr,
|
|
7
|
-
} from '../utils.js';
|
|
8
|
-
import { HEX_COLOR_PATTERN } from '../constants.js';
|
|
9
|
-
import { Minus } from 'lucide';
|
|
10
|
-
|
|
11
|
-
const DEFAULT_LINE_COLOR = '#000000';
|
|
12
|
-
const HIT_POINT_HEIGHT = 16;
|
|
13
|
-
|
|
14
|
-
interface LineSchema extends Schema {
|
|
15
|
-
color: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const lineSchema: Plugin<LineSchema> = {
|
|
19
|
-
pdf: (arg) => {
|
|
20
|
-
const { page, schema, options } = arg;
|
|
21
|
-
if (schema.width === 0 || schema.height === 0 || !schema.color) return;
|
|
22
|
-
const { colorType } = options;
|
|
23
|
-
const pageHeight = page.getHeight();
|
|
24
|
-
const {
|
|
25
|
-
width,
|
|
26
|
-
height,
|
|
27
|
-
rotate,
|
|
28
|
-
position: { x, y },
|
|
29
|
-
opacity,
|
|
30
|
-
} = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
|
|
31
|
-
const pivot = { x: x + width / 2, y: y + height / 2 };
|
|
32
|
-
page.drawLine({
|
|
33
|
-
start: rotatePoint({ x, y: y + height / 2 }, pivot, rotate.angle),
|
|
34
|
-
end: rotatePoint({ x: x + width, y: y + height / 2 }, pivot, rotate.angle),
|
|
35
|
-
thickness: height,
|
|
36
|
-
color: hex2PrintingColor(schema.color ?? DEFAULT_LINE_COLOR, colorType),
|
|
37
|
-
opacity: opacity,
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
ui: (arg) => {
|
|
41
|
-
const { schema, rootElement } = arg;
|
|
42
|
-
Object.assign(rootElement.style, { position: 'relative', overflow: 'visible' });
|
|
43
|
-
|
|
44
|
-
const baseStyles = {
|
|
45
|
-
position: 'absolute',
|
|
46
|
-
top: '50%',
|
|
47
|
-
left: '0',
|
|
48
|
-
transform: 'translateY(-50%)',
|
|
49
|
-
width: '100%',
|
|
50
|
-
} as const;
|
|
51
|
-
|
|
52
|
-
const hitArea = document.createElement('div');
|
|
53
|
-
Object.assign(hitArea.style, baseStyles, {
|
|
54
|
-
height: `${HIT_POINT_HEIGHT}px`,
|
|
55
|
-
backgroundColor: 'transparent',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const div = document.createElement('div');
|
|
59
|
-
Object.assign(div.style, baseStyles, {
|
|
60
|
-
height: '100%',
|
|
61
|
-
backgroundColor: schema.color ?? 'transparent',
|
|
62
|
-
pointerEvents: 'none',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
rootElement.append(hitArea, div);
|
|
66
|
-
},
|
|
67
|
-
propPanel: {
|
|
68
|
-
schema: ({ i18n }) => ({
|
|
69
|
-
color: {
|
|
70
|
-
title: i18n('schemas.color'),
|
|
71
|
-
type: 'string',
|
|
72
|
-
widget: 'color',
|
|
73
|
-
props: {
|
|
74
|
-
disabledAlpha: true,
|
|
75
|
-
},
|
|
76
|
-
required: true,
|
|
77
|
-
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
defaultSchema: {
|
|
81
|
-
name: '',
|
|
82
|
-
type: 'line',
|
|
83
|
-
position: { x: 0, y: 0 },
|
|
84
|
-
width: 50,
|
|
85
|
-
height: 0.5,
|
|
86
|
-
rotate: 0,
|
|
87
|
-
opacity: 1,
|
|
88
|
-
readOnly: true,
|
|
89
|
-
color: DEFAULT_LINE_COLOR,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
icon: createSvgStr(Minus),
|
|
93
|
-
};
|
|
94
|
-
export default lineSchema;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { Plugin, Schema, mm2pt } from '@pdfme/common';
|
|
2
|
-
import { HEX_COLOR_PATTERN } from '../constants.js';
|
|
3
|
-
import { hex2PrintingColor, convertForPdfLayoutProps, createSvgStr } from '../utils.js';
|
|
4
|
-
import { toRadians } from '@pdfme/pdf-lib';
|
|
5
|
-
import { Circle, Square } from 'lucide';
|
|
6
|
-
|
|
7
|
-
interface ShapeSchema extends Schema {
|
|
8
|
-
type: 'ellipse' | 'rectangle';
|
|
9
|
-
borderWidth: number;
|
|
10
|
-
borderColor: string;
|
|
11
|
-
color: string;
|
|
12
|
-
radius?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const shape: Plugin<ShapeSchema> = {
|
|
16
|
-
ui: (arg) => {
|
|
17
|
-
const { schema, rootElement } = arg;
|
|
18
|
-
const div = document.createElement('div');
|
|
19
|
-
div.style.width = '100%';
|
|
20
|
-
div.style.height = '100%';
|
|
21
|
-
div.style.boxSizing = 'border-box';
|
|
22
|
-
if (schema.type === 'ellipse') {
|
|
23
|
-
div.style.borderRadius = '50%';
|
|
24
|
-
} else if (schema.radius && schema.radius > 0) {
|
|
25
|
-
div.style.borderRadius = `${schema.radius}mm`;
|
|
26
|
-
}
|
|
27
|
-
div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
|
|
28
|
-
div.style.borderStyle = schema.borderWidth && schema.borderColor ? 'solid' : 'none';
|
|
29
|
-
div.style.borderColor = schema.borderColor ?? 'transparent';
|
|
30
|
-
div.style.backgroundColor = schema.color ?? 'transparent';
|
|
31
|
-
|
|
32
|
-
rootElement.appendChild(div);
|
|
33
|
-
},
|
|
34
|
-
pdf: (arg) => {
|
|
35
|
-
const { schema, page, options } = arg;
|
|
36
|
-
if (!schema.color && !schema.borderColor) return;
|
|
37
|
-
const { colorType } = options;
|
|
38
|
-
const pageHeight = page.getHeight();
|
|
39
|
-
const cArg = { schema, pageHeight };
|
|
40
|
-
const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
|
|
41
|
-
const {
|
|
42
|
-
position: { x: x4Ellipse, y: y4Ellipse },
|
|
43
|
-
} = convertForPdfLayoutProps({ ...cArg, applyRotateTranslate: false });
|
|
44
|
-
const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
|
|
45
|
-
|
|
46
|
-
const drawOptions = {
|
|
47
|
-
rotate,
|
|
48
|
-
borderWidth,
|
|
49
|
-
borderColor: hex2PrintingColor(schema.borderColor, colorType),
|
|
50
|
-
color: hex2PrintingColor(schema.color, colorType),
|
|
51
|
-
opacity,
|
|
52
|
-
borderOpacity: opacity,
|
|
53
|
-
};
|
|
54
|
-
if (schema.type === 'ellipse') {
|
|
55
|
-
page.drawEllipse({
|
|
56
|
-
x: x4Ellipse + width / 2,
|
|
57
|
-
y: y4Ellipse + height / 2,
|
|
58
|
-
xScale: width / 2 - borderWidth / 2,
|
|
59
|
-
yScale: height / 2 - borderWidth / 2,
|
|
60
|
-
...drawOptions,
|
|
61
|
-
});
|
|
62
|
-
} else if (schema.type === 'rectangle') {
|
|
63
|
-
const radius = schema.radius ?? 0;
|
|
64
|
-
|
|
65
|
-
page.drawRectangle({
|
|
66
|
-
x:
|
|
67
|
-
position.x +
|
|
68
|
-
borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) +
|
|
69
|
-
Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
70
|
-
y:
|
|
71
|
-
position.y +
|
|
72
|
-
borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) +
|
|
73
|
-
Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
|
74
|
-
width: width - borderWidth,
|
|
75
|
-
height: height - borderWidth,
|
|
76
|
-
...(radius ? { radius: mm2pt(radius) } : {}),
|
|
77
|
-
...drawOptions,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
propPanel: {
|
|
82
|
-
schema: ({ i18n }) => ({
|
|
83
|
-
borderWidth: {
|
|
84
|
-
title: i18n('schemas.borderWidth'),
|
|
85
|
-
type: 'number',
|
|
86
|
-
widget: 'inputNumber',
|
|
87
|
-
props: { min: 0, step: 1 },
|
|
88
|
-
span: 12,
|
|
89
|
-
},
|
|
90
|
-
borderColor: {
|
|
91
|
-
title: i18n('schemas.borderColor'),
|
|
92
|
-
type: 'string',
|
|
93
|
-
widget: 'color',
|
|
94
|
-
props: {
|
|
95
|
-
disabledAlpha: true,
|
|
96
|
-
},
|
|
97
|
-
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
|
98
|
-
span: 12,
|
|
99
|
-
},
|
|
100
|
-
color: {
|
|
101
|
-
title: i18n('schemas.color'),
|
|
102
|
-
type: 'string',
|
|
103
|
-
widget: 'color',
|
|
104
|
-
props: {
|
|
105
|
-
disabledAlpha: true,
|
|
106
|
-
},
|
|
107
|
-
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
|
108
|
-
},
|
|
109
|
-
radius: {
|
|
110
|
-
title: i18n('schemas.radius'),
|
|
111
|
-
type: 'number',
|
|
112
|
-
widget: 'inputNumber',
|
|
113
|
-
props: { min: 0, step: 1 },
|
|
114
|
-
span: 12,
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
defaultSchema: {
|
|
118
|
-
name: '',
|
|
119
|
-
type: 'rectangle',
|
|
120
|
-
position: { x: 0, y: 0 },
|
|
121
|
-
width: 62.5,
|
|
122
|
-
height: 37.5,
|
|
123
|
-
rotate: 0,
|
|
124
|
-
opacity: 1,
|
|
125
|
-
borderWidth: 1,
|
|
126
|
-
borderColor: '#000000',
|
|
127
|
-
color: '',
|
|
128
|
-
readOnly: true,
|
|
129
|
-
radius: 0,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const getPropPanelSchema = (type: 'rectangle' | 'ellipse') => ({
|
|
135
|
-
...shape.propPanel,
|
|
136
|
-
defaultSchema: {
|
|
137
|
-
...(shape.propPanel.defaultSchema as ShapeSchema),
|
|
138
|
-
type,
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
export const rectangle: Plugin<ShapeSchema> = {
|
|
143
|
-
...shape,
|
|
144
|
-
propPanel: getPropPanelSchema('rectangle'),
|
|
145
|
-
icon: createSvgStr(Square),
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export const ellipse: Plugin<ShapeSchema> = {
|
|
149
|
-
...shape,
|
|
150
|
-
propPanel: getPropPanelSchema('ellipse'),
|
|
151
|
-
icon: createSvgStr(Circle),
|
|
152
|
-
};
|
package/src/tables/cell.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_FONT_NAME, Plugin, PDFRenderProps, getFallbackFontName } from '@pdfme/common';
|
|
2
|
-
import { uiRender as textUiRender } from '../text/uiRender.js';
|
|
3
|
-
import { pdfRender as textPdfRender } from '../text/pdfRender.js';
|
|
4
|
-
import line from '../shapes/line.js';
|
|
5
|
-
import { rectangle } from '../shapes/rectAndEllipse.js';
|
|
6
|
-
import type { CellSchema } from './types.js';
|
|
7
|
-
import { getCellPropPanelSchema, getDefaultCellStyles } from './helper.js';
|
|
8
|
-
const linePdfRender = line.pdf;
|
|
9
|
-
const rectanglePdfRender = rectangle.pdf;
|
|
10
|
-
|
|
11
|
-
const renderLine = async (
|
|
12
|
-
arg: PDFRenderProps<CellSchema>,
|
|
13
|
-
schema: CellSchema,
|
|
14
|
-
position: { x: number; y: number },
|
|
15
|
-
width: number,
|
|
16
|
-
height: number,
|
|
17
|
-
) =>
|
|
18
|
-
linePdfRender({
|
|
19
|
-
...arg,
|
|
20
|
-
schema: { ...schema, type: 'line', position, width, height, color: schema.borderColor },
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const createTextDiv = (schema: CellSchema) => {
|
|
24
|
-
const { borderWidth: bw, width, height, padding: pd } = schema;
|
|
25
|
-
const textDiv = document.createElement('div');
|
|
26
|
-
textDiv.style.position = 'absolute';
|
|
27
|
-
textDiv.style.zIndex = '1';
|
|
28
|
-
textDiv.style.width = `${width - bw.left - bw.right - pd.left - pd.right}mm`;
|
|
29
|
-
textDiv.style.height = `${height - bw.top - bw.bottom - pd.top - pd.bottom}mm`;
|
|
30
|
-
textDiv.style.top = `${bw.top + pd.top}mm`;
|
|
31
|
-
textDiv.style.left = `${bw.left + pd.left}mm`;
|
|
32
|
-
return textDiv;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const createLineDiv = (
|
|
36
|
-
width: string,
|
|
37
|
-
height: string,
|
|
38
|
-
top: string | null,
|
|
39
|
-
right: string | null,
|
|
40
|
-
bottom: string | null,
|
|
41
|
-
left: string | null,
|
|
42
|
-
borderColor: string,
|
|
43
|
-
) => {
|
|
44
|
-
const div = document.createElement('div');
|
|
45
|
-
div.style.width = width;
|
|
46
|
-
div.style.height = height;
|
|
47
|
-
div.style.position = 'absolute';
|
|
48
|
-
if (top !== null) div.style.top = top;
|
|
49
|
-
if (right !== null) div.style.right = right;
|
|
50
|
-
if (bottom !== null) div.style.bottom = bottom;
|
|
51
|
-
if (left !== null) div.style.left = left;
|
|
52
|
-
div.style.backgroundColor = borderColor;
|
|
53
|
-
return div;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const cellSchema: Plugin<CellSchema> = {
|
|
57
|
-
pdf: async (arg) => {
|
|
58
|
-
const { schema } = arg;
|
|
59
|
-
const { position, width, height, borderWidth, padding } = schema;
|
|
60
|
-
|
|
61
|
-
await Promise.all([
|
|
62
|
-
// BACKGROUND
|
|
63
|
-
rectanglePdfRender({
|
|
64
|
-
...arg,
|
|
65
|
-
schema: {
|
|
66
|
-
...schema,
|
|
67
|
-
type: 'rectangle',
|
|
68
|
-
width: schema.width,
|
|
69
|
-
height: schema.height,
|
|
70
|
-
borderWidth: 0,
|
|
71
|
-
borderColor: '',
|
|
72
|
-
color: schema.backgroundColor,
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
75
|
-
// TOP
|
|
76
|
-
renderLine(arg, schema, { x: position.x, y: position.y }, width, borderWidth.top),
|
|
77
|
-
// RIGHT
|
|
78
|
-
renderLine(
|
|
79
|
-
arg,
|
|
80
|
-
schema,
|
|
81
|
-
{ x: position.x + width - borderWidth.right, y: position.y },
|
|
82
|
-
borderWidth.right,
|
|
83
|
-
height,
|
|
84
|
-
),
|
|
85
|
-
// BOTTOM
|
|
86
|
-
renderLine(
|
|
87
|
-
arg,
|
|
88
|
-
schema,
|
|
89
|
-
{ x: position.x, y: position.y + height - borderWidth.bottom },
|
|
90
|
-
width,
|
|
91
|
-
borderWidth.bottom,
|
|
92
|
-
),
|
|
93
|
-
// LEFT
|
|
94
|
-
renderLine(arg, schema, { x: position.x, y: position.y }, borderWidth.left, height),
|
|
95
|
-
]);
|
|
96
|
-
// TEXT
|
|
97
|
-
await textPdfRender({
|
|
98
|
-
...arg,
|
|
99
|
-
schema: {
|
|
100
|
-
...schema,
|
|
101
|
-
type: 'text',
|
|
102
|
-
backgroundColor: '',
|
|
103
|
-
position: {
|
|
104
|
-
x: position.x + borderWidth.left + padding.left,
|
|
105
|
-
y: position.y + borderWidth.top + padding.top,
|
|
106
|
-
},
|
|
107
|
-
width: width - borderWidth.left - borderWidth.right - padding.left - padding.right,
|
|
108
|
-
height: height - borderWidth.top - borderWidth.bottom - padding.top - padding.bottom,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
ui: async (arg) => {
|
|
113
|
-
const { schema, rootElement } = arg;
|
|
114
|
-
const { borderWidth, width, height, borderColor, backgroundColor } = schema;
|
|
115
|
-
rootElement.style.backgroundColor = backgroundColor;
|
|
116
|
-
|
|
117
|
-
const textDiv = createTextDiv(schema);
|
|
118
|
-
await textUiRender({
|
|
119
|
-
...arg,
|
|
120
|
-
schema: { ...schema, backgroundColor: '' },
|
|
121
|
-
rootElement: textDiv,
|
|
122
|
-
});
|
|
123
|
-
rootElement.appendChild(textDiv);
|
|
124
|
-
|
|
125
|
-
const lines = [
|
|
126
|
-
createLineDiv(`${width}mm`, `${borderWidth.top}mm`, '0mm', null, null, '0mm', borderColor),
|
|
127
|
-
createLineDiv(`${width}mm`, `${borderWidth.bottom}mm`, null, null, '0mm', '0mm', borderColor),
|
|
128
|
-
createLineDiv(`${borderWidth.left}mm`, `${height}mm`, '0mm', null, null, '0mm', borderColor),
|
|
129
|
-
createLineDiv(`${borderWidth.right}mm`, `${height}mm`, '0mm', '0mm', null, null, borderColor),
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
lines.forEach((line) => rootElement.appendChild(line));
|
|
133
|
-
},
|
|
134
|
-
propPanel: {
|
|
135
|
-
schema: ({ options, i18n }) => {
|
|
136
|
-
const font = options.font || { [DEFAULT_FONT_NAME]: { data: '', fallback: true } };
|
|
137
|
-
const fontNames = Object.keys(font);
|
|
138
|
-
const fallbackFontName = getFallbackFontName(font);
|
|
139
|
-
return getCellPropPanelSchema({ i18n, fontNames, fallbackFontName });
|
|
140
|
-
},
|
|
141
|
-
defaultSchema: {
|
|
142
|
-
name: '',
|
|
143
|
-
type: 'cell',
|
|
144
|
-
content: 'Type Something...',
|
|
145
|
-
position: { x: 0, y: 0 },
|
|
146
|
-
width: 50,
|
|
147
|
-
height: 15,
|
|
148
|
-
...getDefaultCellStyles(),
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
export default cellSchema;
|