@pdfme/schemas 6.0.3-dev.0 → 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,436 +0,0 @@
1
- import type { UIRenderProps, Mode } from '@pdfme/common';
2
- import type { TableSchema, CellStyle, Styles } from './types.js';
3
- import { px2mm, ZOOM } from '@pdfme/common';
4
- import { createSingleTable } from './tableHelper.js';
5
- import { getBody, getBodyWithRange } from './helper.js';
6
- import cell from './cell.js';
7
- import { Row } from './classes.js';
8
-
9
- const buttonSize = 30;
10
-
11
- function createButton(options: {
12
- width: number;
13
- height: number;
14
- top: string;
15
- left?: string;
16
- right?: string;
17
- text: string;
18
- onClick: (e: MouseEvent) => void;
19
- }): HTMLButtonElement {
20
- const button = document.createElement('button');
21
- button.style.width = `${options.width}px`;
22
- button.style.height = `${options.height}px`;
23
- button.style.position = 'absolute';
24
- button.style.top = options.top;
25
- if (options.left !== undefined) {
26
- button.style.left = options.left;
27
- }
28
- if (options.right !== undefined) {
29
- button.style.right = options.right;
30
- }
31
- button.innerText = options.text;
32
- button.onclick = options.onClick;
33
- return button;
34
- }
35
-
36
- type RowType = InstanceType<typeof Row>;
37
-
38
- const cellUiRender = cell.ui;
39
-
40
- const convertToCellStyle = (styles: Styles): CellStyle => ({
41
- fontName: styles.fontName,
42
- alignment: styles.alignment,
43
- verticalAlignment: styles.verticalAlignment,
44
- fontSize: styles.fontSize,
45
- lineHeight: styles.lineHeight,
46
- characterSpacing: styles.characterSpacing,
47
- backgroundColor: styles.backgroundColor,
48
- // ---
49
- fontColor: styles.textColor,
50
- borderColor: styles.lineColor,
51
- borderWidth: styles.lineWidth,
52
- padding: styles.cellPadding,
53
- });
54
-
55
- const calcResizedHeadWidthPercentages = (arg: {
56
- currentHeadWidthPercentages: number[];
57
- currentHeadWidths: number[];
58
- changedHeadWidth: number;
59
- changedHeadIndex: number;
60
- }) => {
61
- const { currentHeadWidthPercentages, currentHeadWidths, changedHeadWidth, changedHeadIndex } =
62
- arg;
63
- const headWidthPercentages = [...currentHeadWidthPercentages];
64
- const totalWidth = currentHeadWidths.reduce((a, b) => a + b, 0);
65
- const changedWidthPercentage = (changedHeadWidth / totalWidth) * 100;
66
- const originalNextWidthPercentage = headWidthPercentages[changedHeadIndex + 1] ?? 0;
67
- const adjustment = headWidthPercentages[changedHeadIndex] - changedWidthPercentage;
68
- headWidthPercentages[changedHeadIndex] = changedWidthPercentage;
69
- if (changedHeadIndex + 1 < headWidthPercentages.length) {
70
- headWidthPercentages[changedHeadIndex + 1] = originalNextWidthPercentage + adjustment;
71
- }
72
- return headWidthPercentages;
73
- };
74
-
75
- const setBorder = (
76
- div: HTMLDivElement,
77
- borderPosition: 'Top' | 'Left' | 'Right' | 'Bottom',
78
- arg: UIRenderProps<TableSchema>,
79
- ) => {
80
- div.style[`border${borderPosition}`] = `${String(arg.schema.tableStyles.borderWidth)}mm solid ${
81
- arg.schema.tableStyles.borderColor
82
- }`;
83
- };
84
-
85
- const drawBorder = (
86
- div: HTMLDivElement,
87
- row: RowType,
88
- colIndex: number,
89
- rowIndex: number,
90
- rowsLength: number,
91
- arg: UIRenderProps<TableSchema>,
92
- ) => {
93
- const isFirstColumn = colIndex === 0;
94
- const isLastColumn = colIndex === Object.values(row.cells).length - 1;
95
- const isLastRow = rowIndex === rowsLength - 1;
96
-
97
- if (row.section === 'head') {
98
- setBorder(div, 'Top', arg);
99
- if (isFirstColumn) setBorder(div, 'Left', arg);
100
- if (isLastColumn) setBorder(div, 'Right', arg);
101
- if ((JSON.parse(arg.value || '[]') as string[][]).length === 0) {
102
- setBorder(div, 'Bottom', arg);
103
- }
104
- } else if (row.section === 'body') {
105
- if (!arg.schema.showHead && rowIndex === 0) {
106
- setBorder(div, 'Top', arg);
107
- }
108
- if (isFirstColumn) setBorder(div, 'Left', arg);
109
- if (isLastColumn) setBorder(div, 'Right', arg);
110
- if (isLastRow) setBorder(div, 'Bottom', arg);
111
- }
112
- };
113
-
114
- const renderRowUi = (args: {
115
- rows: RowType[];
116
- arg: UIRenderProps<TableSchema>;
117
- editingPosition: { rowIndex: number; colIndex: number };
118
- onChangeEditingPosition: (position: { rowIndex: number; colIndex: number }) => void;
119
- offsetY?: number;
120
- }) => {
121
- const { rows, arg, onChangeEditingPosition, offsetY = 0, editingPosition } = args;
122
- const value = JSON.parse(arg.value || '[]') as string[][];
123
-
124
- let rowOffsetY = offsetY;
125
- rows.forEach((row, rowIndex) => {
126
- const { cells, height, section } = row;
127
- let colOffsetX = 0;
128
- Object.values(cells).forEach((cell, colIndex) => {
129
- const div = document.createElement('div');
130
- div.style.position = 'absolute';
131
- div.style.top = `${rowOffsetY}mm`;
132
- div.style.left = `${colOffsetX}mm`;
133
- div.style.width = `${cell.width}mm`;
134
- div.style.height = `${cell.height}mm`;
135
- div.style.boxSizing = 'border-box';
136
-
137
- drawBorder(div, row, colIndex, rowIndex, rows.length, arg);
138
-
139
- div.style.cursor =
140
- arg.mode === 'designer' || (arg.mode === 'form' && section === 'body') ? 'text' : 'default';
141
-
142
- div.addEventListener('click', () => {
143
- if (arg.mode === 'viewer') return;
144
- onChangeEditingPosition({ rowIndex, colIndex });
145
- });
146
- arg.rootElement.appendChild(div);
147
- const isEditing =
148
- editingPosition.rowIndex === rowIndex && editingPosition.colIndex === colIndex;
149
- let mode: Mode = 'viewer';
150
- if (arg.mode === 'form') {
151
- mode = section === 'body' && isEditing && !arg.schema.readOnly ? 'designer' : 'viewer';
152
- } else if (arg.mode === 'designer') {
153
- mode = isEditing ? 'designer' : 'form';
154
- }
155
-
156
- void cellUiRender({
157
- ...arg,
158
- stopEditing: () => {
159
- if (arg.mode === 'form') {
160
- resetEditingPosition();
161
- }
162
- },
163
- mode,
164
- onChange: (v) => {
165
- if (!arg.onChange) return;
166
- const newValue = (Array.isArray(v) ? v[0].value : v.value) as string;
167
- if (section === 'body') {
168
- const startRange = arg.schema.__bodyRange?.start ?? 0;
169
- value[rowIndex + startRange][colIndex] = newValue;
170
- arg.onChange({ key: 'content', value: JSON.stringify(value) });
171
- } else {
172
- const newHead = [...arg.schema.head];
173
- newHead[colIndex] = newValue;
174
- arg.onChange({ key: 'head', value: newHead });
175
- }
176
- },
177
- value: cell.raw,
178
- placeholder: '',
179
- rootElement: div,
180
- schema: {
181
- name: '',
182
- type: 'cell',
183
- content: cell.raw,
184
- position: { x: colOffsetX, y: rowOffsetY },
185
- width: cell.width,
186
- height: cell.height,
187
- ...convertToCellStyle(cell.styles),
188
- },
189
- });
190
- colOffsetX += cell.width;
191
- });
192
- rowOffsetY += height;
193
- });
194
- };
195
-
196
- const headEditingPosition = { rowIndex: -1, colIndex: -1 };
197
- const bodyEditingPosition = { rowIndex: -1, colIndex: -1 };
198
- const resetEditingPosition = () => {
199
- headEditingPosition.rowIndex = -1;
200
- headEditingPosition.colIndex = -1;
201
- bodyEditingPosition.rowIndex = -1;
202
- bodyEditingPosition.colIndex = -1;
203
- };
204
-
205
- export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
206
- const { rootElement, onChange, schema, value, mode, scale } = arg;
207
- const body = getBody(value);
208
- const bodyWidthRange = getBodyWithRange(value, schema.__bodyRange);
209
- const table = await createSingleTable(bodyWidthRange, arg);
210
- const showHead = table.settings.showHead;
211
-
212
- rootElement.innerHTML = '';
213
-
214
- const handleChangeEditingPosition = (
215
- newPosition: { rowIndex: number; colIndex: number },
216
- editingPosition: { rowIndex: number; colIndex: number },
217
- ) => {
218
- resetEditingPosition();
219
- editingPosition.rowIndex = newPosition.rowIndex;
220
- editingPosition.colIndex = newPosition.colIndex;
221
- void uiRender(arg);
222
- };
223
-
224
- if (showHead) {
225
- renderRowUi({
226
- rows: table.head,
227
- arg,
228
- editingPosition: headEditingPosition,
229
- onChangeEditingPosition: (p) => handleChangeEditingPosition(p, headEditingPosition),
230
- });
231
- }
232
-
233
- const offsetY = showHead ? table.getHeadHeight() : 0;
234
- renderRowUi({
235
- rows: table.body,
236
- arg,
237
- editingPosition: bodyEditingPosition,
238
- onChangeEditingPosition: (p) => {
239
- handleChangeEditingPosition(p, bodyEditingPosition);
240
- },
241
- offsetY,
242
- });
243
-
244
- const createAddRowButton = () =>
245
- createButton({
246
- width: buttonSize,
247
- height: buttonSize,
248
- top: `${table.getHeight()}mm`,
249
- left: `calc(50% - ${buttonSize / 2}px)`,
250
- text: '+',
251
- onClick: () => {
252
- const newRow = Array(schema.head.length).fill('') as string[];
253
- if (onChange) onChange({ key: 'content', value: JSON.stringify(body.concat([newRow])) });
254
- },
255
- });
256
-
257
- const createRemoveRowButtons = () => {
258
- let offsetY = showHead ? table.getHeadHeight() : 0;
259
- return table.body.map((row, i) => {
260
- offsetY = offsetY + row.height;
261
- const removeRowButton = createButton({
262
- width: buttonSize,
263
- height: buttonSize,
264
- top: `${offsetY - px2mm(buttonSize)}mm`,
265
- right: `-${buttonSize}px`,
266
- text: '-',
267
- onClick: () => {
268
- const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
269
- if (onChange) onChange({ key: 'content', value: JSON.stringify(newTableBody) });
270
- },
271
- });
272
- return removeRowButton;
273
- });
274
- };
275
-
276
- if (mode === 'form' && onChange && !schema.readOnly) {
277
- if (
278
- schema.__bodyRange?.end === undefined ||
279
- schema.__bodyRange.end >= (JSON.parse(value || '[]') as string[][]).length
280
- ) {
281
- rootElement.appendChild(createAddRowButton());
282
- }
283
-
284
- createRemoveRowButtons().forEach((button) => rootElement.appendChild(button));
285
- }
286
-
287
- if (mode === 'designer' && onChange) {
288
- const addColumnButton = createButton({
289
- width: buttonSize,
290
- height: buttonSize,
291
- top: `${(showHead ? table.getHeadHeight() : 0) - px2mm(buttonSize)}mm`,
292
- right: `-${buttonSize}px`,
293
- text: '+',
294
- onClick: (e) => {
295
- e.preventDefault();
296
- const newColumnWidthPercentage = 25;
297
- const totalCurrentWidth = schema.headWidthPercentages.reduce(
298
- (acc, width) => acc + width,
299
- 0,
300
- );
301
- const scalingRatio = (100 - newColumnWidthPercentage) / totalCurrentWidth;
302
- const scaledWidths = schema.headWidthPercentages.map((width) => width * scalingRatio);
303
- onChange([
304
- { key: 'head', value: schema.head.concat(`Head ${schema.head.length + 1}`) },
305
- { key: 'headWidthPercentages', value: scaledWidths.concat(newColumnWidthPercentage) },
306
- {
307
- key: 'content',
308
- value: JSON.stringify(bodyWidthRange.map((row, i) => row.concat(`Row ${i + 1}`))),
309
- },
310
- ]);
311
- },
312
- });
313
- rootElement.appendChild(addColumnButton);
314
-
315
- rootElement.appendChild(createAddRowButton());
316
-
317
- createRemoveRowButtons().forEach((button) => rootElement.appendChild(button));
318
-
319
- let offsetX = 0;
320
- table.columns.forEach((column, i, columns) => {
321
- if (columns.length === 1) return;
322
- offsetX = offsetX + column.width;
323
- const removeColumnButton = createButton({
324
- width: buttonSize,
325
- height: buttonSize,
326
- top: `${-buttonSize}px`,
327
- left: `${offsetX - px2mm(buttonSize)}mm`,
328
- text: '-',
329
- onClick: () => {
330
- const totalWidthMinusRemoved = schema.headWidthPercentages.reduce(
331
- (sum, width, j) => (j !== i ? sum + width : sum),
332
- 0,
333
- );
334
-
335
- // TODO Should also remove the deleted columnStyles when deleting
336
- onChange([
337
- { key: 'head', value: schema.head.filter((_, j) => j !== i) },
338
- {
339
- key: 'headWidthPercentages',
340
- value: schema.headWidthPercentages
341
- .filter((_, j) => j !== i)
342
- .map((width) => (width / totalWidthMinusRemoved) * 100),
343
- },
344
- {
345
- key: 'content',
346
- value: JSON.stringify(bodyWidthRange.map((row) => row.filter((_, j) => j !== i))),
347
- },
348
- ]);
349
- },
350
- });
351
- rootElement.appendChild(removeColumnButton);
352
-
353
- if (i === table.columns.length - 1) return;
354
-
355
- const dragHandle = document.createElement('div');
356
- const lineWidth = 5;
357
- dragHandle.style.width = `${lineWidth}px`;
358
- dragHandle.style.height = '100%';
359
- dragHandle.style.backgroundColor = '#eee';
360
- dragHandle.style.opacity = '0.5';
361
- dragHandle.style.cursor = 'col-resize';
362
- dragHandle.style.position = 'absolute';
363
- dragHandle.style.zIndex = '10';
364
- dragHandle.style.left = `${offsetX - px2mm(lineWidth) / 2}mm`;
365
- dragHandle.style.top = '0';
366
- const setColor = (e: MouseEvent) => {
367
- const handle = e.target as HTMLDivElement;
368
- handle.style.backgroundColor = '#2196f3';
369
- };
370
- const resetColor = (e: MouseEvent) => {
371
- const handle = e.target as HTMLDivElement;
372
- handle.style.backgroundColor = '#eee';
373
- };
374
- dragHandle.addEventListener('mouseover', setColor);
375
- dragHandle.addEventListener('mouseout', resetColor);
376
-
377
- const prevColumnLeft = offsetX - column.width;
378
- const nextColumnRight = offsetX - px2mm(lineWidth) + table.columns[i + 1].width;
379
-
380
- dragHandle.addEventListener('mousedown', (e) => {
381
- resetEditingPosition();
382
- const handle = e.target as HTMLDivElement;
383
- dragHandle.removeEventListener('mouseover', setColor);
384
- dragHandle.removeEventListener('mouseout', resetColor);
385
-
386
- const startClientX = e.clientX;
387
- const startLeft = Number(handle.style.left.replace('mm', ''));
388
-
389
- let move = 0;
390
- const mouseMove = (e: MouseEvent) => {
391
- const deltaX = e.clientX - startClientX;
392
- const moveX = deltaX / ZOOM / scale;
393
- let newLeft = startLeft + moveX;
394
-
395
- if (newLeft < prevColumnLeft) {
396
- newLeft = prevColumnLeft;
397
- }
398
- if (newLeft >= nextColumnRight) {
399
- newLeft = nextColumnRight;
400
- }
401
- handle.style.left = `${newLeft}mm`;
402
- move = newLeft - startLeft;
403
- };
404
- rootElement.addEventListener('mousemove', mouseMove);
405
-
406
- const commitResize = () => {
407
- if (move !== 0) {
408
- const newHeadWidthPercentages = calcResizedHeadWidthPercentages({
409
- currentHeadWidthPercentages: schema.headWidthPercentages,
410
- currentHeadWidths: table.columns.map((column) => column.width),
411
- changedHeadWidth: table.columns[i].width + move,
412
- changedHeadIndex: i,
413
- });
414
- onChange({ key: 'headWidthPercentages', value: newHeadWidthPercentages });
415
- }
416
- move = 0;
417
- dragHandle.addEventListener('mouseover', setColor);
418
- dragHandle.addEventListener('mouseout', resetColor);
419
- rootElement.removeEventListener('mousemove', mouseMove);
420
- rootElement.removeEventListener('mouseup', commitResize);
421
- };
422
- rootElement.addEventListener('mouseup', commitResize);
423
- });
424
- rootElement.appendChild(dragHandle);
425
- });
426
- }
427
-
428
- if (mode === 'viewer') {
429
- resetEditingPosition();
430
- }
431
-
432
- const tableHeight = showHead ? table.getHeight() : table.getBodyHeight();
433
- if (schema.height !== tableHeight && onChange) {
434
- onChange({ key: 'height', value: tableHeight });
435
- }
436
- };
@@ -1,104 +0,0 @@
1
- import { ALIGNMENT, VERTICAL_ALIGNMENT, DYNAMIC_FONT_SIZE_FIT } from './types.js';
2
-
3
- export const DEFAULT_FONT_SIZE = 13;
4
-
5
- export const ALIGN_LEFT = 'left' as ALIGNMENT;
6
- export const ALIGN_CENTER = 'center' as ALIGNMENT;
7
- export const ALIGN_RIGHT = 'right' as ALIGNMENT;
8
- export const ALIGN_JUSTIFY = 'justify' as ALIGNMENT;
9
- export const DEFAULT_ALIGNMENT = ALIGN_LEFT;
10
- export const VERTICAL_ALIGN_TOP = 'top' as VERTICAL_ALIGNMENT;
11
- export const VERTICAL_ALIGN_MIDDLE = 'middle' as VERTICAL_ALIGNMENT;
12
- export const VERTICAL_ALIGN_BOTTOM = 'bottom' as VERTICAL_ALIGNMENT;
13
- export const DEFAULT_VERTICAL_ALIGNMENT = VERTICAL_ALIGN_TOP;
14
- export const DEFAULT_LINE_HEIGHT = 1;
15
- export const DEFAULT_CHARACTER_SPACING = 0;
16
- export const DEFAULT_FONT_COLOR = '#000000';
17
- export const PLACEHOLDER_FONT_COLOR = '#A0A0A0';
18
- export const DYNAMIC_FIT_VERTICAL = 'vertical' as DYNAMIC_FONT_SIZE_FIT;
19
- export const DYNAMIC_FIT_HORIZONTAL = 'horizontal' as DYNAMIC_FONT_SIZE_FIT;
20
- export const DEFAULT_DYNAMIC_FIT = DYNAMIC_FIT_VERTICAL;
21
- export const DEFAULT_DYNAMIC_MIN_FONT_SIZE = 4;
22
-
23
- export const DEFAULT_DYNAMIC_MAX_FONT_SIZE = 72;
24
- export const FONT_SIZE_ADJUSTMENT = 0.25;
25
-
26
- export const LINE_START_FORBIDDEN_CHARS = [
27
- // 句読点
28
- '、',
29
- '。',
30
- ',',
31
- '.',
32
-
33
- // 閉じカッコ類
34
- '」',
35
- '』',
36
- ')',
37
- '}',
38
- '】',
39
- '>',
40
- '≫',
41
- ']',
42
-
43
- // 記号
44
- '・',
45
- 'ー',
46
- '―',
47
- '-',
48
-
49
- // 約物
50
- '!',
51
- '!',
52
- '?',
53
- '?',
54
- ':',
55
- ':',
56
- ';',
57
- ';',
58
- '/',
59
- '/',
60
-
61
- // 繰り返し記号
62
- 'ゝ',
63
- '々',
64
- '〃',
65
-
66
- // 拗音・促音(小書きのかな)
67
- 'ぁ',
68
- 'ぃ',
69
- 'ぅ',
70
- 'ぇ',
71
- 'ぉ',
72
- 'っ',
73
- 'ゃ',
74
- 'ゅ',
75
- 'ょ',
76
- 'ァ',
77
- 'ィ',
78
- 'ゥ',
79
- 'ェ',
80
- 'ォ',
81
- 'ッ',
82
- 'ャ',
83
- 'ュ',
84
- 'ョ',
85
- ];
86
-
87
- export const LINE_END_FORBIDDEN_CHARS = [
88
- // 始め括弧類
89
- '「',
90
- '『',
91
- '(',
92
- '{',
93
- '【',
94
- '<',
95
- '≪',
96
- '[',
97
- '〘',
98
- '〖',
99
- '〝',
100
- '‘',
101
- '“',
102
- '⦅',
103
- '«',
104
- ];
@@ -1,83 +0,0 @@
1
- // No imports needed from @pdfme/common
2
- import {
3
- TextAlignCenterIcon,
4
- TextAlignLeftIcon,
5
- TextAlignRightIcon,
6
- TextAlignJustifyIcon,
7
- TextStrikethroughIcon,
8
- TextUnderlineIcon,
9
- TextVerticalAlignBottomIcon,
10
- TextVerticalAlignMiddleIcon,
11
- TextVerticalAlignTopIcon,
12
- } from './icons/index.js';
13
- import {
14
- ALIGN_CENTER,
15
- ALIGN_RIGHT,
16
- DEFAULT_ALIGNMENT,
17
- DEFAULT_VERTICAL_ALIGNMENT,
18
- VERTICAL_ALIGN_BOTTOM,
19
- VERTICAL_ALIGN_MIDDLE,
20
- ALIGN_JUSTIFY,
21
- } from './constants.js';
22
-
23
- export enum Formatter {
24
- STRIKETHROUGH = 'strikethrough',
25
- UNDERLINE = 'underline',
26
- ALIGNMENT = 'alignment',
27
- VERTICAL_ALIGNMENT = 'verticalAlignment',
28
- }
29
-
30
- interface GroupButtonBoolean {
31
- key: Formatter;
32
- icon: string;
33
- type: 'boolean';
34
- }
35
-
36
- interface GroupButtonString {
37
- key: Formatter;
38
- icon: string;
39
- type: 'select';
40
- value: string;
41
- }
42
-
43
- type GroupButton = GroupButtonBoolean | GroupButtonString;
44
-
45
- export function getExtraFormatterSchema(i18n: (key: string) => string): {
46
- title: string;
47
- widget: string;
48
- buttons: GroupButton[];
49
- span: number;
50
- } {
51
- const buttons: GroupButton[] = [
52
- { key: Formatter.STRIKETHROUGH, icon: TextStrikethroughIcon, type: 'boolean' },
53
- { key: Formatter.UNDERLINE, icon: TextUnderlineIcon, type: 'boolean' },
54
- { key: Formatter.ALIGNMENT, icon: TextAlignLeftIcon, type: 'select', value: DEFAULT_ALIGNMENT },
55
- { key: Formatter.ALIGNMENT, icon: TextAlignCenterIcon, type: 'select', value: ALIGN_CENTER },
56
- { key: Formatter.ALIGNMENT, icon: TextAlignRightIcon, type: 'select', value: ALIGN_RIGHT },
57
- { key: Formatter.ALIGNMENT, icon: TextAlignJustifyIcon, type: 'select', value: ALIGN_JUSTIFY },
58
- {
59
- key: Formatter.VERTICAL_ALIGNMENT,
60
- icon: TextVerticalAlignTopIcon,
61
- type: 'select',
62
- value: DEFAULT_VERTICAL_ALIGNMENT,
63
- },
64
- {
65
- key: Formatter.VERTICAL_ALIGNMENT,
66
- icon: TextVerticalAlignMiddleIcon,
67
- type: 'select',
68
- value: VERTICAL_ALIGN_MIDDLE,
69
- },
70
- {
71
- key: Formatter.VERTICAL_ALIGNMENT,
72
- icon: TextVerticalAlignBottomIcon,
73
- type: 'select',
74
- value: VERTICAL_ALIGN_BOTTOM,
75
- },
76
- ];
77
- return {
78
- title: i18n('schemas.text.format'),
79
- widget: 'ButtonGroup',
80
- buttons,
81
- span: 24,
82
- };
83
- }