@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.
Files changed (116) hide show
  1. package/dist/barcodes/constants.d.ts +4 -0
  2. package/dist/barcodes/helper.d.ts +21 -0
  3. package/dist/barcodes/index.d.ts +4 -0
  4. package/dist/barcodes/pdfRender.d.ts +3 -0
  5. package/dist/barcodes/propPanel.d.ts +3 -0
  6. package/{src/barcodes/types.ts → dist/barcodes/types.d.ts} +5 -7
  7. package/dist/barcodes/uiRender.d.ts +3 -0
  8. package/dist/builtins-CgaZ0UX3.js +613 -0
  9. package/dist/builtins-CgaZ0UX3.js.map +1 -0
  10. package/dist/builtins.d.ts +4 -0
  11. package/dist/builtins.js +2 -0
  12. package/dist/checkbox/index.d.ts +6 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/date/date.d.ts +2 -0
  15. package/dist/date/dateTime.d.ts +2 -0
  16. package/dist/date/helper.d.ts +20 -0
  17. package/dist/date/time.d.ts +2 -0
  18. package/dist/date/types.d.ts +17 -0
  19. package/dist/dynamicTemplate-D_DHR3-X.js +1128 -0
  20. package/dist/dynamicTemplate-D_DHR3-X.js.map +1 -0
  21. package/dist/graphics/image.d.ts +5 -0
  22. package/dist/graphics/imagehelper.d.ts +4 -0
  23. package/dist/graphics/signature.d.ts +4 -0
  24. package/dist/graphics/svg.d.ts +4 -0
  25. package/{src/index.ts → dist/index.d.ts} +1 -22
  26. package/dist/index.js +5383 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/multiVariableText/helper.d.ts +3 -0
  29. package/dist/multiVariableText/index.d.ts +4 -0
  30. package/dist/multiVariableText/pdfRender.d.ts +3 -0
  31. package/dist/multiVariableText/propPanel.d.ts +3 -0
  32. package/{src/multiVariableText/types.ts → dist/multiVariableText/types.d.ts} +2 -3
  33. package/dist/multiVariableText/uiRender.d.ts +3 -0
  34. package/dist/multiVariableText/variables.d.ts +10 -0
  35. package/dist/radioGroup/index.d.ts +7 -0
  36. package/dist/sanitize.d.ts +1 -0
  37. package/dist/select/index.d.ts +7 -0
  38. package/dist/shapes/line.d.ts +6 -0
  39. package/dist/shapes/rectAndEllipse.d.ts +11 -0
  40. package/dist/tables/cell.d.ts +4 -0
  41. package/dist/tables/classes.d.ts +69 -0
  42. package/dist/tables/dynamicTemplate.d.ts +7 -0
  43. package/dist/tables/helper.d.ts +265 -0
  44. package/dist/tables/index.d.ts +4 -0
  45. package/dist/tables/pdfRender.d.ts +3 -0
  46. package/dist/tables/propPanel.d.ts +3 -0
  47. package/dist/tables/tableHelper.d.ts +10 -0
  48. package/dist/tables/types.d.ts +88 -0
  49. package/dist/tables/uiRender.d.ts +3 -0
  50. package/dist/tables.js +2 -0
  51. package/dist/text/constants.d.ts +23 -0
  52. package/dist/text/extraFormatter.d.ts +25 -0
  53. package/dist/text/helper.d.ts +40 -0
  54. package/dist/text/icons/index.d.ts +9 -0
  55. package/dist/text/index.d.ts +4 -0
  56. package/dist/text/pdfRender.d.ts +3 -0
  57. package/dist/text/propPanel.d.ts +3 -0
  58. package/dist/text/types.d.ts +28 -0
  59. package/dist/text/uiRender.d.ts +11 -0
  60. package/dist/utils.d.ts +40 -0
  61. package/dist/utils.js +215 -0
  62. package/dist/utils.js.map +1 -0
  63. package/package.json +5 -1
  64. package/src/barcodes/constants.ts +0 -20
  65. package/src/barcodes/helper.ts +0 -187
  66. package/src/barcodes/index.ts +0 -23
  67. package/src/barcodes/pdfRender.ts +0 -37
  68. package/src/barcodes/propPanel.ts +0 -249
  69. package/src/barcodes/uiRender.ts +0 -94
  70. package/src/builtins.ts +0 -8
  71. package/src/checkbox/index.ts +0 -70
  72. package/src/constants.ts +0 -2
  73. package/src/date/date.ts +0 -9
  74. package/src/date/dateTime.ts +0 -9
  75. package/src/date/helper.ts +0 -544
  76. package/src/date/time.ts +0 -9
  77. package/src/date/types.ts +0 -19
  78. package/src/graphics/image.ts +0 -201
  79. package/src/graphics/imagehelper.ts +0 -156
  80. package/src/graphics/signature.ts +0 -136
  81. package/src/graphics/svg.ts +0 -121
  82. package/src/multiVariableText/helper.ts +0 -65
  83. package/src/multiVariableText/index.ts +0 -16
  84. package/src/multiVariableText/pdfRender.ts +0 -21
  85. package/src/multiVariableText/propPanel.ts +0 -169
  86. package/src/multiVariableText/uiRender.ts +0 -157
  87. package/src/multiVariableText/variables.ts +0 -63
  88. package/src/radioGroup/index.ts +0 -115
  89. package/src/sanitize.ts +0 -50
  90. package/src/select/index.ts +0 -205
  91. package/src/shapes/line.ts +0 -94
  92. package/src/shapes/rectAndEllipse.ts +0 -152
  93. package/src/tables/cell.ts +0 -152
  94. package/src/tables/classes.ts +0 -402
  95. package/src/tables/dynamicTemplate.ts +0 -88
  96. package/src/tables/helper.ts +0 -216
  97. package/src/tables/index.ts +0 -15
  98. package/src/tables/pdfRender.ts +0 -144
  99. package/src/tables/propPanel.ts +0 -111
  100. package/src/tables/tableHelper.ts +0 -289
  101. package/src/tables/types.ts +0 -87
  102. package/src/tables/uiRender.ts +0 -436
  103. package/src/text/constants.ts +0 -104
  104. package/src/text/extraFormatter.ts +0 -83
  105. package/src/text/helper.ts +0 -573
  106. package/src/text/icons/index.ts +0 -30
  107. package/src/text/index.ts +0 -16
  108. package/src/text/pdfRender.ts +0 -240
  109. package/src/text/propPanel.ts +0 -184
  110. package/src/text/types.ts +0 -30
  111. package/src/text/uiRender.ts +0 -292
  112. package/src/utils.ts +0 -354
  113. package/tsconfig.build.json +0 -14
  114. package/tsconfig.json +0 -16
  115. package/vite.config.mts +0 -51
  116. /package/{src/tables.ts → dist/tables.d.ts} +0 -0
@@ -1,249 +0,0 @@
1
- import type { PropPanel } from '@pdfme/common';
2
- import type { BarcodeSchema } from './types.js';
3
- import {
4
- DEFAULT_BARCODE_COLOR,
5
- DEFAULT_BARCODE_BG_COLOR,
6
- DEFAULT_BARCODE_INCLUDETEXT,
7
- } from './constants.js';
8
- import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
9
-
10
- const defaultColors = {
11
- backgroundColor: DEFAULT_BARCODE_BG_COLOR,
12
- barColor: DEFAULT_BARCODE_COLOR,
13
- };
14
- const defaultTextColors = { textColor: DEFAULT_BARCODE_COLOR };
15
- const defaultIncludetext = { includetext: DEFAULT_BARCODE_INCLUDETEXT };
16
- const position = { x: 0, y: 0 };
17
- const default40x20 = { width: 40, height: 20 };
18
-
19
- const barcodeDefaults: { defaultSchema: BarcodeSchema }[] = [
20
- {
21
- defaultSchema: {
22
- name: '',
23
- type: 'qrcode',
24
- content: 'https://pdfme.com/',
25
- position,
26
- ...defaultColors,
27
- width: 30,
28
- height: 30,
29
- rotate: 0,
30
- opacity: DEFAULT_OPACITY,
31
- },
32
- },
33
- {
34
- defaultSchema: {
35
- name: '',
36
- type: 'japanpost',
37
- content: '6540123789-A-K-Z',
38
- position,
39
- ...defaultColors,
40
- ...defaultTextColors,
41
- ...defaultIncludetext,
42
- width: 80,
43
- height: 7.2,
44
- rotate: 0,
45
- opacity: DEFAULT_OPACITY,
46
- },
47
- },
48
- {
49
- defaultSchema: {
50
- name: '',
51
- type: 'ean13',
52
- content: '2112345678900',
53
- position,
54
- ...defaultColors,
55
- ...defaultTextColors,
56
- ...defaultIncludetext,
57
- ...default40x20,
58
- height: 16,
59
- rotate: 0,
60
- opacity: DEFAULT_OPACITY,
61
- },
62
- },
63
- {
64
- defaultSchema: {
65
- name: '',
66
- type: 'ean8',
67
- content: '02345673',
68
- position,
69
- ...defaultColors,
70
- ...defaultTextColors,
71
- ...defaultIncludetext,
72
- ...default40x20,
73
- rotate: 0,
74
- opacity: DEFAULT_OPACITY,
75
- },
76
- },
77
- {
78
- defaultSchema: {
79
- name: '',
80
- type: 'code39',
81
- content: 'THIS IS CODE 39',
82
- position,
83
- ...defaultColors,
84
- ...defaultTextColors,
85
- ...defaultIncludetext,
86
- ...default40x20,
87
- opacity: DEFAULT_OPACITY,
88
- },
89
- },
90
- {
91
- defaultSchema: {
92
- name: '',
93
- type: 'code128',
94
- content: 'This is Code 128!',
95
- position,
96
- ...defaultColors,
97
- ...defaultTextColors,
98
- ...defaultIncludetext,
99
- ...default40x20,
100
- rotate: 0,
101
- opacity: DEFAULT_OPACITY,
102
- },
103
- },
104
- {
105
- defaultSchema: {
106
- name: '',
107
- type: 'nw7',
108
- content: 'A0123456789B',
109
- position,
110
- ...defaultColors,
111
- ...defaultTextColors,
112
- ...defaultIncludetext,
113
- ...default40x20,
114
- rotate: 0,
115
- opacity: DEFAULT_OPACITY,
116
- },
117
- },
118
- {
119
- defaultSchema: {
120
- name: '',
121
- type: 'itf14',
122
- content: '04601234567893',
123
- position,
124
- ...defaultColors,
125
- ...defaultTextColors,
126
- ...defaultIncludetext,
127
- ...default40x20,
128
- height: 12,
129
- rotate: 0,
130
- opacity: DEFAULT_OPACITY,
131
- },
132
- },
133
- {
134
- defaultSchema: {
135
- name: '',
136
- type: 'upca',
137
- content: '416000336108',
138
- position,
139
- ...defaultColors,
140
- ...defaultTextColors,
141
- ...defaultIncludetext,
142
- ...default40x20,
143
- height: 16,
144
- rotate: 0,
145
- opacity: DEFAULT_OPACITY,
146
- },
147
- },
148
- {
149
- defaultSchema: {
150
- name: '',
151
- type: 'upce',
152
- content: '00123457',
153
- position,
154
- ...defaultColors,
155
- ...defaultTextColors,
156
- ...defaultIncludetext,
157
- ...default40x20,
158
- rotate: 0,
159
- opacity: DEFAULT_OPACITY,
160
- },
161
- },
162
- {
163
- defaultSchema: {
164
- name: '',
165
- type: 'gs1datamatrix',
166
- content: '(01)03453120000011(17)191125(10)ABCD1234',
167
- position,
168
- ...defaultColors,
169
- width: 30,
170
- height: 30,
171
- rotate: 0,
172
- opacity: DEFAULT_OPACITY,
173
- },
174
- },
175
- {
176
- defaultSchema: {
177
- name: '',
178
- type: 'pdf417',
179
- content: 'This is PDF417!',
180
- position,
181
- ...defaultColors,
182
- width: 40,
183
- height: 16,
184
- rotate: 0,
185
- opacity: DEFAULT_OPACITY,
186
- },
187
- },
188
- ];
189
-
190
- export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<BarcodeSchema> => {
191
- const barcodeHasText =
192
- barcodeType !== 'qrcode' && barcodeType !== 'gs1datamatrix' && barcodeType !== 'pdf417';
193
-
194
- const defaults = barcodeDefaults.find(({ defaultSchema }) => defaultSchema.type === barcodeType);
195
-
196
- if (!defaults)
197
- throw new Error(`[@pdfme/schemas/barcodes] No default for barcode type ${barcodeType}`);
198
-
199
- return {
200
- schema: ({ i18n }) => ({
201
- barColor: {
202
- title: i18n('schemas.barcodes.barColor'),
203
- type: 'string',
204
- widget: 'color',
205
- props: {
206
- disabledAlpha: true,
207
- },
208
- rules: [
209
- {
210
- pattern: HEX_COLOR_PATTERN,
211
- message: i18n('validation.hexColor'),
212
- },
213
- ],
214
- },
215
- backgroundColor: {
216
- title: i18n('schemas.bgColor'),
217
- type: 'string',
218
- widget: 'color',
219
- props: {
220
- disabledAlpha: true,
221
- },
222
- rules: [
223
- {
224
- pattern: HEX_COLOR_PATTERN,
225
- message: i18n('validation.hexColor'),
226
- },
227
- ],
228
- },
229
- ...(barcodeHasText
230
- ? {
231
- textColor: {
232
- title: i18n('schemas.textColor'),
233
- type: 'string',
234
- widget: 'color',
235
- props: {
236
- disabledAlpha: true,
237
- },
238
- },
239
- includetext: {
240
- title: i18n('schemas.barcodes.includetext'),
241
- type: 'boolean',
242
- widget: 'switch',
243
- },
244
- }
245
- : {}),
246
- }),
247
- ...defaults,
248
- };
249
- };
@@ -1,94 +0,0 @@
1
- import type * as CSS from 'csstype';
2
- import { UIRenderProps } from '@pdfme/common';
3
- import type { BarcodeSchema } from './types.js';
4
- import { validateBarcodeInput, createBarCode } from './helper.js';
5
- import { addAlphaToHex, isEditable, createErrorElm } from '../utils.js';
6
-
7
- const fullSize = { width: '100%', height: '100%' };
8
-
9
- const blobToDataURL = (blob: Blob): Promise<string> =>
10
- new Promise((resolve, reject) => {
11
- const reader = new FileReader();
12
- reader.onloadend = () => resolve(reader.result as string);
13
- reader.onerror = reject;
14
- reader.readAsDataURL(blob);
15
- });
16
-
17
- const createBarcodeImage = async (schema: BarcodeSchema, value: string) => {
18
- const imageBuf = await createBarCode({
19
- ...schema,
20
- input: value,
21
- });
22
- const barcodeData = new Blob([new Uint8Array(imageBuf)], { type: 'image/png' });
23
- const barcodeDataURL = await blobToDataURL(barcodeData);
24
- return barcodeDataURL;
25
- };
26
-
27
- const createBarcodeImageElm = async (schema: BarcodeSchema, value: string) => {
28
- const barcodeDataURL = await createBarcodeImage(schema, value);
29
- const img = document.createElement('img');
30
- img.src = barcodeDataURL;
31
- const imgStyle: CSS.Properties = { ...fullSize, borderRadius: 0 };
32
- Object.assign(img.style, imgStyle);
33
- return img;
34
- };
35
-
36
- export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
37
- const { value, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, schema, theme } =
38
- arg;
39
-
40
- const container = document.createElement('div');
41
- const containerStyle: CSS.Properties = {
42
- ...fullSize,
43
- display: 'flex',
44
- alignItems: 'center',
45
- justifyContent: 'center',
46
- fontFamily: "'Open Sans', sans-serif",
47
- };
48
- Object.assign(container.style, containerStyle);
49
- rootElement.appendChild(container);
50
- const editable = isEditable(mode, schema);
51
- if (editable) {
52
- const input = document.createElement('input');
53
- const inputStyle: CSS.Properties = {
54
- width: '100%',
55
- position: 'absolute',
56
- textAlign: 'center',
57
- fontSize: '12pt',
58
- fontWeight: 'bold',
59
- color: theme.colorWhite,
60
- backgroundColor: editable || value ? addAlphaToHex('#000000', 80) : 'none',
61
- border: 'none',
62
- display: 'flex',
63
- alignItems: 'center',
64
- justifyContent: 'center',
65
- overflow: 'auto',
66
- };
67
- Object.assign(input.style, inputStyle);
68
- input.value = value;
69
- input.placeholder = placeholder || '';
70
- input.tabIndex = tabIndex || 0;
71
- input.addEventListener('change', (e: Event) => {
72
- if (onChange) onChange({ key: 'content', value: (e.target as HTMLInputElement).value });
73
- });
74
- input.addEventListener('blur', () => {
75
- if (stopEditing) stopEditing();
76
- });
77
- container.appendChild(input);
78
- input.setSelectionRange(value.length, value.length);
79
- if (mode === 'designer') {
80
- input.focus();
81
- }
82
- }
83
-
84
- if (!value) return;
85
- try {
86
- if (!validateBarcodeInput(schema.type, value))
87
- throw new Error('[@pdfme/schemas/barcodes] Invalid barcode input');
88
- const imgElm = await createBarcodeImageElm(schema, value);
89
- container.appendChild(imgElm);
90
- } catch (err) {
91
- console.error(`[@pdfme/ui] ${String(err)}`);
92
- container.appendChild(createErrorElm());
93
- }
94
- };
package/src/builtins.ts DELETED
@@ -1,8 +0,0 @@
1
- import text from './text/index.js';
2
-
3
- // The default built-in plugin surface is intentionally limited to text.
4
- // Generator/UI consumers that need image, barcode, table, or other schema types
5
- // must import and pass those plugins explicitly from `@pdfme/schemas`.
6
- const builtInPlugins = { Text: text };
7
-
8
- export { builtInPlugins };
@@ -1,70 +0,0 @@
1
- import { Plugin, Schema } from '@pdfme/common';
2
- import svg from '../graphics/svg.js';
3
- import { isEditable } from '../utils.js';
4
- import { HEX_COLOR_PATTERN } from '../constants.js';
5
- import { Square, SquareCheck } from 'lucide';
6
- import { createSvgStr } from '../utils.js';
7
-
8
- const defaultStroke = 'currentColor';
9
-
10
- const getCheckedIcon = (stroke = defaultStroke) => createSvgStr(SquareCheck, { stroke });
11
- const getUncheckedIcon = (stroke = defaultStroke) => createSvgStr(Square, { stroke });
12
-
13
- interface Checkbox extends Schema {
14
- color: string;
15
- }
16
-
17
- const getIcon = ({ value, color }: { value: string; color: string }) =>
18
- value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
19
-
20
- const schema: Plugin<Checkbox> = {
21
- ui: (arg) => {
22
- const { schema, value, onChange, rootElement, mode } = arg;
23
- const container = document.createElement('div');
24
- container.style.width = '100%';
25
- container.style.height = '100%';
26
-
27
- if (isEditable(mode, schema)) {
28
- container.addEventListener('click', () => {
29
- if (onChange) onChange({ key: 'content', value: value === 'true' ? 'false' : 'true' });
30
- });
31
- }
32
-
33
- void svg.ui({
34
- ...arg,
35
- rootElement: container,
36
- mode: 'viewer',
37
- value: getIcon({ value, color: schema.color }),
38
- });
39
-
40
- rootElement.appendChild(container);
41
- },
42
- pdf: (arg) =>
43
- svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
44
- propPanel: {
45
- schema: ({ i18n }) => ({
46
- color: {
47
- title: i18n('schemas.color'),
48
- type: 'string',
49
- widget: 'color',
50
- props: {
51
- disabledAlpha: true,
52
- },
53
- required: true,
54
- rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
55
- },
56
- }),
57
- defaultSchema: {
58
- name: '',
59
- type: 'checkbox',
60
- content: 'false',
61
- position: { x: 0, y: 0 },
62
- width: 8,
63
- height: 8,
64
- color: '#000000',
65
- },
66
- },
67
- icon: getCheckedIcon(),
68
- };
69
-
70
- export default schema;
package/src/constants.ts DELETED
@@ -1,2 +0,0 @@
1
- export const DEFAULT_OPACITY = 1;
2
- export const HEX_COLOR_PATTERN = '^#(?:[A-Fa-f0-9]{6})$';
package/src/date/date.ts DELETED
@@ -1,9 +0,0 @@
1
- import { getPlugin } from './helper.js';
2
- import { createSvgStr } from '../utils.js';
3
- import { Calendar } from 'lucide';
4
-
5
- const type = 'date';
6
-
7
- const icon = createSvgStr(Calendar);
8
-
9
- export default getPlugin({ type, icon });
@@ -1,9 +0,0 @@
1
- import { getPlugin } from './helper.js';
2
- import { createSvgStr } from '../utils.js';
3
- import { CalendarClock } from 'lucide';
4
-
5
- const type = 'dateTime';
6
-
7
- const icon = createSvgStr(CalendarClock);
8
-
9
- export default getPlugin({ type, icon });