@pdfme/schemas 5.3.8-dev.57 → 5.3.8-dev.59

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 (81) hide show
  1. package/dist/cjs/src/barcodes/propPanel.js +3 -3
  2. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  3. package/dist/cjs/src/checkbox/index.js +1 -1
  4. package/dist/cjs/src/multiVariableText/propPanel.js +14 -9
  5. package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
  6. package/dist/cjs/src/multiVariableText/uiRender.js +14 -4
  7. package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
  8. package/dist/cjs/src/radioGroup/index.js +1 -1
  9. package/dist/cjs/src/shapes/line.js +1 -1
  10. package/dist/cjs/src/shapes/rectAndEllipse.js +8 -4
  11. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  12. package/dist/cjs/src/tables/helper.js +4 -4
  13. package/dist/cjs/src/tables/tableHelper.js.map +1 -1
  14. package/dist/cjs/src/text/pdfRender.js +1 -1
  15. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  16. package/dist/cjs/src/text/uiRender.js.map +1 -1
  17. package/dist/cjs/src/utils.js +13 -17
  18. package/dist/cjs/src/utils.js.map +1 -1
  19. package/dist/esm/src/barcodes/propPanel.js +3 -3
  20. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  21. package/dist/esm/src/checkbox/index.js +1 -1
  22. package/dist/esm/src/multiVariableText/propPanel.js +14 -9
  23. package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
  24. package/dist/esm/src/multiVariableText/uiRender.js +15 -5
  25. package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
  26. package/dist/esm/src/radioGroup/index.js +1 -1
  27. package/dist/esm/src/shapes/line.js +1 -1
  28. package/dist/esm/src/shapes/rectAndEllipse.js +8 -4
  29. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  30. package/dist/esm/src/tables/helper.js +4 -4
  31. package/dist/esm/src/tables/tableHelper.js.map +1 -1
  32. package/dist/esm/src/text/pdfRender.js +1 -1
  33. package/dist/esm/src/text/pdfRender.js.map +1 -1
  34. package/dist/esm/src/text/uiRender.js.map +1 -1
  35. package/dist/esm/src/utils.js +13 -17
  36. package/dist/esm/src/utils.js.map +1 -1
  37. package/dist/node/src/barcodes/propPanel.js +3 -3
  38. package/dist/node/src/barcodes/propPanel.js.map +1 -1
  39. package/dist/node/src/checkbox/index.js +1 -1
  40. package/dist/node/src/multiVariableText/propPanel.js +14 -9
  41. package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
  42. package/dist/node/src/multiVariableText/uiRender.js +14 -4
  43. package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
  44. package/dist/node/src/radioGroup/index.js +1 -1
  45. package/dist/node/src/shapes/line.js +1 -1
  46. package/dist/node/src/shapes/rectAndEllipse.js +8 -4
  47. package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
  48. package/dist/node/src/tables/helper.js +4 -4
  49. package/dist/node/src/tables/tableHelper.js.map +1 -1
  50. package/dist/node/src/text/pdfRender.js +1 -1
  51. package/dist/node/src/text/pdfRender.js.map +1 -1
  52. package/dist/node/src/text/uiRender.js.map +1 -1
  53. package/dist/node/src/utils.js +13 -17
  54. package/dist/node/src/utils.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/barcodes/helper.ts +1 -2
  57. package/src/barcodes/index.ts +1 -1
  58. package/src/barcodes/pdfRender.ts +1 -1
  59. package/src/barcodes/propPanel.ts +3 -4
  60. package/src/checkbox/index.ts +1 -1
  61. package/src/date/helper.ts +3 -3
  62. package/src/graphics/imagehelper.ts +1 -1
  63. package/src/graphics/svg.ts +3 -3
  64. package/src/multiVariableText/helper.ts +3 -3
  65. package/src/multiVariableText/propPanel.ts +17 -14
  66. package/src/multiVariableText/uiRender.ts +21 -18
  67. package/src/radioGroup/index.ts +2 -2
  68. package/src/select/index.ts +1 -1
  69. package/src/shapes/line.ts +1 -1
  70. package/src/shapes/rectAndEllipse.ts +10 -4
  71. package/src/tables/cell.ts +4 -4
  72. package/src/tables/classes.ts +5 -5
  73. package/src/tables/dynamicTemplate.ts +1 -1
  74. package/src/tables/helper.ts +6 -6
  75. package/src/tables/pdfRender.ts +3 -3
  76. package/src/tables/tableHelper.ts +13 -10
  77. package/src/tables/uiRender.ts +5 -5
  78. package/src/text/helper.ts +5 -5
  79. package/src/text/pdfRender.ts +3 -3
  80. package/src/text/uiRender.ts +13 -5
  81. package/src/utils.ts +27 -31
@@ -150,7 +150,7 @@ const imageSize = (imgBuffer: Buffer): { height: number; width: number } => {
150
150
  }
151
151
 
152
152
  throw new TypeError(
153
- '[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type)
153
+ '[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type),
154
154
  );
155
155
  };
156
156
  // ----------------------------
@@ -14,12 +14,12 @@ const isValidSVG = (svgString: string): boolean => {
14
14
  if (!svgString || typeof svgString !== 'string') {
15
15
  return false;
16
16
  }
17
-
17
+
18
18
  // Check for basic SVG structure
19
19
  if (!svgString.includes('<svg') || !svgString.includes('</svg>')) {
20
20
  return false;
21
21
  }
22
-
22
+
23
23
  // Additional browser-specific validation if DOMParser is available
24
24
  if (typeof DOMParser !== 'undefined') {
25
25
  const parser = new DOMParser();
@@ -29,7 +29,7 @@ const isValidSVG = (svgString: string): boolean => {
29
29
  return false;
30
30
  }
31
31
  }
32
-
32
+
33
33
  return true;
34
34
  } catch (error) {
35
35
  return false;
@@ -2,7 +2,7 @@ import { MultiVariableTextSchema } from './types.js';
2
2
 
3
3
  export const substituteVariables = (
4
4
  text: string,
5
- variablesIn: string | Record<string, string>
5
+ variablesIn: string | Record<string, string>,
6
6
  ): string => {
7
7
  if (!text) {
8
8
  return '';
@@ -38,7 +38,7 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
38
38
  values = value ? JSON.parse(value) : {};
39
39
  } catch (e) {
40
40
  throw new SyntaxError(
41
- `[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`
41
+ `[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`,
42
42
  );
43
43
  }
44
44
 
@@ -46,7 +46,7 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
46
46
  if (!values[variable]) {
47
47
  if (schema.required) {
48
48
  throw new Error(
49
- `[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`
49
+ `[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`,
50
50
  );
51
51
  }
52
52
  // If not required, then simply don't render this field if an input is missing
@@ -5,7 +5,7 @@ import { MultiVariableTextSchema } from './types.js';
5
5
  const mapDynamicVariables = (props: PropPanelWidgetProps) => {
6
6
  const { rootElement, changeSchemas, activeSchema, i18n, options } = props;
7
7
 
8
- const mvtSchema = (activeSchema as any);
8
+ const mvtSchema = activeSchema as any;
9
9
  const text = mvtSchema.text || '';
10
10
  const variables = JSON.parse(mvtSchema.content) || {};
11
11
  const variablesChanged = updateVariablesFromText(text, variables);
@@ -14,11 +14,13 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
14
14
  if (variablesChanged) {
15
15
  changeSchemas([
16
16
  { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
17
- { key: 'variables', value: varNames, schemaId: activeSchema.id }
17
+ { key: 'variables', value: varNames, schemaId: activeSchema.id },
18
18
  ]);
19
19
  }
20
20
 
21
- const placeholderRowEl = document.getElementById('placeholder-dynamic-var')?.closest('.ant-form-item') as HTMLElement;
21
+ const placeholderRowEl = document
22
+ .getElementById('placeholder-dynamic-var')
23
+ ?.closest('.ant-form-item') as HTMLElement;
22
24
  if (!placeholderRowEl) {
23
25
  throw new Error('Failed to find Ant form placeholder row to create dynamic variables inputs.');
24
26
  }
@@ -36,10 +38,12 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
36
38
  textarea.value = variables[variableName];
37
39
  textarea.addEventListener('change', (e: Event) => {
38
40
  variables[variableName] = (e.target as HTMLTextAreaElement).value;
39
- changeSchemas([{ key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id }]);
41
+ changeSchemas([
42
+ { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
43
+ ]);
40
44
  });
41
45
 
42
- const label = varRow.querySelector('label') as HTMLLabelElement
46
+ const label = varRow.querySelector('label') as HTMLLabelElement;
43
47
  label.innerText = variableName;
44
48
 
45
49
  varRow.style.display = 'block';
@@ -47,10 +51,11 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
47
51
  }
48
52
  } else {
49
53
  const para = document.createElement('p');
50
- para.innerHTML = i18n('schemas.mvt.typingInstructions')
51
- + ` <code style="color:${options?.theme?.token?.colorPrimary || "#168fe3"}; font-weight:bold;">{`
52
- + i18n('schemas.mvt.sampleField')
53
- + '}</code>';
54
+ para.innerHTML =
55
+ i18n('schemas.mvt.typingInstructions') +
56
+ ` <code style="color:${options?.theme?.token?.colorPrimary || '#168fe3'}; font-weight:bold;">{` +
57
+ i18n('schemas.mvt.sampleField') +
58
+ '}</code>';
54
59
  rootElement.appendChild(para);
55
60
  }
56
61
  };
@@ -73,7 +78,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
73
78
  type: 'object',
74
79
  widget: 'mapDynamicVariables',
75
80
  bind: false,
76
- span: 24
81
+ span: 24,
77
82
  },
78
83
  placeholderDynamicVar: {
79
84
  title: 'Placeholder Dynamic Variable',
@@ -88,9 +93,8 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
88
93
  },
89
94
  span: 24,
90
95
  },
91
- }
96
+ },
92
97
  },
93
-
94
98
  };
95
99
  },
96
100
  widgets: { ...parentPropPanel.widgets, mapDynamicVariables },
@@ -106,7 +110,6 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
106
110
  },
107
111
  };
108
112
 
109
-
110
113
  const updateVariablesFromText = (text: string, variables: any): boolean => {
111
114
  const regex = /\{([^{}]+)}/g;
112
115
  const matches = text.match(regex);
@@ -138,4 +141,4 @@ const updateVariablesFromText = (text: string, variables: any): boolean => {
138
141
  }
139
142
 
140
143
  return changed;
141
- }
144
+ };
@@ -3,7 +3,7 @@ import { MultiVariableTextSchema } from './types.js';
3
3
  import {
4
4
  uiRender as parentUiRender,
5
5
  buildStyledTextContainer,
6
- makeElementPlainTextContentEditable
6
+ makeElementPlainTextContentEditable,
7
7
  } from '../text/uiRender.js';
8
8
  import { isEditable } from '../utils.js';
9
9
  import { getFontKitFont } from '../text/helper.js';
@@ -25,10 +25,14 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
25
25
  schema,
26
26
  mode: mode == 'form' ? 'viewer' : mode, // if no variables for form it's just a viewer
27
27
  rootElement,
28
- onChange: (arg: { key: string; value: any; } | { key: string; value: any; }[]) => {
28
+ onChange: (arg: { key: string; value: any } | { key: string; value: any }[]) => {
29
29
  if (!Array.isArray(arg)) {
30
30
  const numVariables = countUniqueVariableNames(arg.value);
31
- onChange && onChange([{key: 'text', value: arg.value}, {key: 'readOnly', value: numVariables == 0}]);
31
+ onChange &&
32
+ onChange([
33
+ { key: 'text', value: arg.value },
34
+ { key: 'readOnly', value: numVariables == 0 },
35
+ ]);
32
36
  } else {
33
37
  throw new Error('onChange is not an array, the parent text plugin has changed...');
34
38
  }
@@ -49,7 +53,10 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
49
53
  if (numVariables !== newNumVariables) {
50
54
  // If variables were modified during this keypress, we trigger a change
51
55
  if (onChange) {
52
- onChange([{key: 'text', value: text}, {key: 'readOnly', value: newNumVariables == 0}]);
56
+ onChange([
57
+ { key: 'text', value: text },
58
+ { key: 'readOnly', value: newNumVariables == 0 },
59
+ ]);
53
60
  }
54
61
  numVariables = newNumVariables;
55
62
  }
@@ -59,16 +66,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
59
66
  };
60
67
 
61
68
  const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
62
- const {
63
- value,
64
- schema,
65
- rootElement,
66
- onChange,
67
- stopEditing,
68
- theme,
69
- _cache,
70
- options,
71
- } = arg;
69
+ const { value, schema, rootElement, onChange, stopEditing, theme, _cache, options } = arg;
72
70
  const rawText = schema.text;
73
71
 
74
72
  if (rootElement.parentElement) {
@@ -92,7 +90,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
92
90
  inVarString = true;
93
91
  let span = document.createElement('span');
94
92
  span.style.outline = `${theme.colorPrimary} dashed 1px`;
95
- makeElementPlainTextContentEditable(span)
93
+ makeElementPlainTextContentEditable(span);
96
94
  span.textContent = variables[variableIndices[i]];
97
95
  span.addEventListener('blur', (e: Event) => {
98
96
  const newValue = (e.target as HTMLSpanElement).textContent || '';
@@ -114,7 +112,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
114
112
  textBlock.appendChild(span);
115
113
  }
116
114
  }
117
- }
115
+ };
118
116
 
119
117
  const getVariableIndices = (content: string) => {
120
118
  const regex = /\{([^}]+)}/g;
@@ -146,7 +144,12 @@ const countUniqueVariableNames = (content: string) => {
146
144
  * Regex would otherwise be performed on every key press (which isn't terrible, but this code helps).
147
145
  */
148
146
  const keyPressShouldBeChecked = (event: KeyboardEvent) => {
149
- if (event.key == "ArrowUp" || event.key == "ArrowDown" || event.key == "ArrowLeft" || event.key == "ArrowRight") {
147
+ if (
148
+ event.key == 'ArrowUp' ||
149
+ event.key == 'ArrowDown' ||
150
+ event.key == 'ArrowLeft' ||
151
+ event.key == 'ArrowRight'
152
+ ) {
150
153
  return false;
151
154
  }
152
155
 
@@ -164,4 +167,4 @@ const keyPressShouldBeChecked = (event: KeyboardEvent) => {
164
167
  }
165
168
 
166
169
  return true;
167
- }
170
+ };
@@ -65,7 +65,7 @@ const schema: Plugin<RadioGroup> = {
65
65
  onChange({ key: 'content', value: 'true' });
66
66
  radioButtonStates.set(schema.name, { value: 'true', onChange });
67
67
  eventEmitter.dispatchEvent(
68
- new CustomEvent(`group-${schema.group}`, { detail: schema.name })
68
+ new CustomEvent(`group-${schema.group}`, { detail: schema.name }),
69
69
  );
70
70
  }
71
71
  });
@@ -89,7 +89,7 @@ const schema: Plugin<RadioGroup> = {
89
89
  type: 'string',
90
90
  widget: 'color',
91
91
  props: {
92
- disabledAlpha: true
92
+ disabledAlpha: true,
93
93
  },
94
94
  required: true,
95
95
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
@@ -157,7 +157,7 @@ const schema: Plugin<Select> = {
157
157
  selectElement.innerHTML = schema.options
158
158
  .map(
159
159
  (option) =>
160
- `<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`
160
+ `<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`,
161
161
  )
162
162
  .join('');
163
163
  rootElement.appendChild(selectElement);
@@ -51,7 +51,7 @@ const lineSchema: Plugin<LineSchema> = {
51
51
  type: 'string',
52
52
  widget: 'color',
53
53
  props: {
54
- disabledAlpha: true
54
+ disabledAlpha: true,
55
55
  },
56
56
  required: true,
57
57
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
@@ -58,8 +58,14 @@ const shape: Plugin<ShapeSchema> = {
58
58
  });
59
59
  } else if (schema.type === 'rectangle') {
60
60
  page.drawRectangle({
61
- x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * (Math.PI ** 2),
62
- y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * (Math.PI ** 2),
61
+ x:
62
+ position.x +
63
+ borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) +
64
+ Math.tan(toRadians(rotate)) * Math.PI ** 2,
65
+ y:
66
+ position.y +
67
+ borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) +
68
+ Math.tan(toRadians(rotate)) * Math.PI ** 2,
63
69
  width: width - borderWidth,
64
70
  height: height - borderWidth,
65
71
  ...drawOptions,
@@ -80,7 +86,7 @@ const shape: Plugin<ShapeSchema> = {
80
86
  type: 'string',
81
87
  widget: 'color',
82
88
  props: {
83
- disabledAlpha: true
89
+ disabledAlpha: true,
84
90
  },
85
91
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
86
92
  },
@@ -89,7 +95,7 @@ const shape: Plugin<ShapeSchema> = {
89
95
  type: 'string',
90
96
  widget: 'color',
91
97
  props: {
92
- disabledAlpha: true
98
+ disabledAlpha: true,
93
99
  },
94
100
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
95
101
  },
@@ -19,7 +19,7 @@ const renderLine = async (
19
19
  schema: CellSchema,
20
20
  position: { x: number; y: number },
21
21
  width: number,
22
- height: number
22
+ height: number,
23
23
  ) =>
24
24
  linePdfRender({
25
25
  ...arg,
@@ -45,7 +45,7 @@ const createLineDiv = (
45
45
  right: string | null,
46
46
  bottom: string | null,
47
47
  left: string | null,
48
- borderColor: string
48
+ borderColor: string,
49
49
  ) => {
50
50
  const div = document.createElement('div');
51
51
  div.style.width = width;
@@ -86,7 +86,7 @@ const cellSchema: Plugin<CellSchema> = {
86
86
  schema,
87
87
  { x: position.x + width - borderWidth.right, y: position.y },
88
88
  borderWidth.right,
89
- height
89
+ height,
90
90
  ),
91
91
  // BOTTOM
92
92
  renderLine(
@@ -94,7 +94,7 @@ const cellSchema: Plugin<CellSchema> = {
94
94
  schema,
95
95
  { x: position.x, y: position.y + height - borderWidth.bottom },
96
96
  width,
97
- borderWidth.bottom
97
+ borderWidth.bottom,
98
98
  ),
99
99
  // LEFT
100
100
  renderLine(arg, schema, { x: position.x, y: position.y }, borderWidth.left, height),
@@ -175,7 +175,7 @@ async function calculateWidths(arg: { table: Table; font: Font; _cache: Map<any,
175
175
  // first resize attempt: with respect to minReadableWidth and minWidth
176
176
  if (resizeWidth) {
177
177
  resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) =>
178
- Math.max(column.minReadableWidth, column.minWidth)
178
+ Math.max(column.minReadableWidth, column.minWidth),
179
179
  );
180
180
  }
181
181
 
@@ -257,7 +257,7 @@ function applyColSpans(table: Table) {
257
257
 
258
258
  async function fitContent(
259
259
  table: Table,
260
- getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>
260
+ getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
261
261
  ) {
262
262
  const rowSpanHeight = { count: 0, height: 0 };
263
263
  for (const row of table.allRows()) {
@@ -293,7 +293,7 @@ async function fitContent(
293
293
  function resizeColumns(
294
294
  columns: Column[],
295
295
  resizeWidth: number,
296
- getMinWidth: (column: Column) => number
296
+ getMinWidth: (column: Column) => number,
297
297
  ) {
298
298
  const initialResizeWidth = resizeWidth;
299
299
  const sumWrappedWidth = columns.reduce((acc, column) => acc + column.wrappedWidth, 0);
@@ -333,7 +333,7 @@ function resizeColumns(
333
333
 
334
334
  async function calculate(
335
335
  table: Table,
336
- getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>
336
+ getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
337
337
  ) {
338
338
  for (const row of table.allRows()) {
339
339
  for (const column of table.columns) {
@@ -347,7 +347,7 @@ async function calculate(
347
347
 
348
348
  const longestWordWidth = getStringWidth(
349
349
  Object.assign(cell, { text: cell.text.join(' ').split(/\s+/) }),
350
- fontKitFont
350
+ fontKitFont,
351
351
  );
352
352
  cell.minReadableWidth = longestWordWidth + hPadding;
353
353
 
@@ -10,7 +10,7 @@ export const getDynamicHeightsForTable = async (
10
10
  basePdf: BasePdf;
11
11
  options: CommonOptions;
12
12
  _cache: Map<any, any>;
13
- }
13
+ },
14
14
  ): Promise<number[]> => {
15
15
  if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
16
16
  const schema = args.schema as TableSchema;
@@ -112,7 +112,7 @@ export const getCellPropPanelSchema = (arg: {
112
112
  type: 'string',
113
113
  widget: 'color',
114
114
  props: {
115
- disabledAlpha: true
115
+ disabledAlpha: true,
116
116
  },
117
117
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
118
118
  },
@@ -121,7 +121,7 @@ export const getCellPropPanelSchema = (arg: {
121
121
  type: 'string',
122
122
  widget: 'color',
123
123
  props: {
124
- disabledAlpha: true
124
+ disabledAlpha: true,
125
125
  },
126
126
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
127
127
  },
@@ -130,7 +130,7 @@ export const getCellPropPanelSchema = (arg: {
130
130
  type: 'string',
131
131
  widget: 'color',
132
132
  props: {
133
- disabledAlpha: true
133
+ disabledAlpha: true,
134
134
  },
135
135
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
136
136
  },
@@ -141,7 +141,7 @@ export const getCellPropPanelSchema = (arg: {
141
141
  type: 'string',
142
142
  widget: 'color',
143
143
  props: {
144
- disabledAlpha: true
144
+ disabledAlpha: true,
145
145
  },
146
146
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
147
147
  },
@@ -194,7 +194,7 @@ export const getColumnStylesPropPanelSchema = ({
194
194
  },
195
195
  },
196
196
  }),
197
- {}
197
+ {},
198
198
  ),
199
199
  },
200
200
  });
@@ -208,7 +208,7 @@ export const getBody = (value: string | string[][]): string[][] => {
208
208
 
209
209
  export const getBodyWithRange = (
210
210
  value: string | string[][],
211
- range?: { start: number; end?: number | undefined }
211
+ range?: { start: number; end?: number | undefined },
212
212
  ) => {
213
213
  const body = getBody(value);
214
214
  if (!range) return body;
@@ -41,7 +41,7 @@ async function drawRow(
41
41
  table: Table,
42
42
  row: Row,
43
43
  cursor: Pos,
44
- columns: Column[]
44
+ columns: Column[],
45
45
  ) {
46
46
  cursor.x = table.settings.margin.left;
47
47
  for (const column of columns) {
@@ -65,7 +65,7 @@ async function drawTableBorder(
65
65
  arg: PDFRenderProps<TableSchema>,
66
66
  table: Table,
67
67
  startPos: Pos,
68
- cursor: Pos
68
+ cursor: Pos,
69
69
  ) {
70
70
  const lineWidth = table.settings.tableLineWidth;
71
71
  const lineColor = table.settings.tableLineColor;
@@ -112,7 +112,7 @@ export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
112
112
 
113
113
  const body = getBodyWithRange(
114
114
  typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
115
- schema.__bodyRange
115
+ schema.__bodyRange,
116
116
  );
117
117
  const table = await createSingleTable(body, arg);
118
118
  await drawTable(arg, table);
@@ -51,7 +51,7 @@ function parseSection(
51
51
  sectionRows: string[][],
52
52
  columns: Column[],
53
53
  styleProps: StylesProps,
54
- fallbackFontName: string
54
+ fallbackFontName: string,
55
55
  ): Row[] {
56
56
  const rowSpansLeftForColumn: { [key: string]: { left: number; times: number } } = {};
57
57
  const result = sectionRows.map((rawRow, rowIndex) => {
@@ -112,7 +112,7 @@ function cellStyles(
112
112
  column: Column,
113
113
  rowIndex: number,
114
114
  styles: StylesProps,
115
- fallbackFontName: string
115
+ fallbackFontName: string,
116
116
  ) {
117
117
  let sectionStyles;
118
118
  if (sectionName === 'head') {
@@ -167,23 +167,26 @@ function mapCellStyle(style: CellStyle): Partial<Styles> {
167
167
  function getTableOptions(schema: TableSchema, body: string[][]): UserOptions {
168
168
  const columnStylesWidth = schema.headWidthPercentages.reduce(
169
169
  (acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }),
170
- {} as Record<number, Partial<Styles>>
170
+ {} as Record<number, Partial<Styles>>,
171
171
  );
172
172
 
173
173
  const columnStylesAlignment = Object.entries(schema.columnStyles.alignment || {}).reduce(
174
174
  (acc, [key, value]) => ({ ...acc, [key]: { alignment: value } }),
175
- {} as Record<number, Partial<Styles>>
175
+ {} as Record<number, Partial<Styles>>,
176
176
  );
177
177
 
178
178
  const allKeys = new Set([
179
179
  ...Object.keys(columnStylesWidth).map(Number),
180
180
  ...Object.keys(columnStylesAlignment).map(Number),
181
181
  ]);
182
- const columnStyles = Array.from(allKeys).reduce((acc, key) => {
183
- const widthStyle = columnStylesWidth[key] || {};
184
- const alignmentStyle = columnStylesAlignment[key] || {};
185
- return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };
186
- }, {} as Record<number, Partial<Styles>>);
182
+ const columnStyles = Array.from(allKeys).reduce(
183
+ (acc, key) => {
184
+ const widthStyle = columnStylesWidth[key] || {};
185
+ const alignmentStyle = columnStylesAlignment[key] || {};
186
+ return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };
187
+ },
188
+ {} as Record<number, Partial<Styles>>,
189
+ );
187
190
 
188
191
  return {
189
192
  head: [schema.head],
@@ -254,7 +257,7 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
254
257
  'When specifying a custom PDF for basePdf, ' +
255
258
  'you cannot use features such as page breaks or re-layout of other elements.' +
256
259
  'To utilize these features, please define basePdf as follows:\n' +
257
- '{ width: number; height: number; padding: [number, number, number, number]; }'
260
+ '{ width: number; height: number; padding: [number, number, number, number]; }',
258
261
  );
259
262
  }
260
263
 
@@ -75,7 +75,7 @@ const calcResizedHeadWidthPercentages = (arg: {
75
75
  const setBorder = (
76
76
  div: HTMLDivElement,
77
77
  borderPosition: 'Top' | 'Left' | 'Right' | 'Bottom',
78
- arg: UIRenderProps<TableSchema>
78
+ arg: UIRenderProps<TableSchema>,
79
79
  ) => {
80
80
  div.style[`border${borderPosition}`] = `${String(arg.schema.tableStyles.borderWidth)}mm solid ${
81
81
  arg.schema.tableStyles.borderColor
@@ -88,7 +88,7 @@ const drawBorder = (
88
88
  colIndex: number,
89
89
  rowIndex: number,
90
90
  rowsLength: number,
91
- arg: UIRenderProps<TableSchema>
91
+ arg: UIRenderProps<TableSchema>,
92
92
  ) => {
93
93
  const isFirstColumn = colIndex === 0;
94
94
  const isLastColumn = colIndex === Object.values(row.cells).length - 1;
@@ -213,7 +213,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
213
213
 
214
214
  const handleChangeEditingPosition = (
215
215
  newPosition: { rowIndex: number; colIndex: number },
216
- editingPosition: { rowIndex: number; colIndex: number }
216
+ editingPosition: { rowIndex: number; colIndex: number },
217
217
  ) => {
218
218
  resetEditingPosition();
219
219
  editingPosition.rowIndex = newPosition.rowIndex;
@@ -296,7 +296,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
296
296
  const newColumnWidthPercentage = 25;
297
297
  const totalCurrentWidth = schema.headWidthPercentages.reduce(
298
298
  (acc, width) => acc + width,
299
- 0
299
+ 0,
300
300
  );
301
301
  const scalingRatio = (100 - newColumnWidthPercentage) / totalCurrentWidth;
302
302
  const scaledWidths = schema.headWidthPercentages.map((width) => width * scalingRatio);
@@ -329,7 +329,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
329
329
  onClick: () => {
330
330
  const totalWidthMinusRemoved = schema.headWidthPercentages.reduce(
331
331
  (sum, width, j) => (j !== i ? sum + width : sum),
332
- 0
332
+ 0,
333
333
  );
334
334
 
335
335
  // TODO Should also remove the deleted columnStyles when deleting
@@ -29,7 +29,7 @@ export const getBrowserVerticalFontAdjustments = (
29
29
  fontKitFont: FontKitFont,
30
30
  fontSize: number,
31
31
  lineHeight: number,
32
- verticalAlignment: string
32
+ verticalAlignment: string,
33
33
  ) => {
34
34
  const { ascent, descent, unitsPerEm } = fontKitFont;
35
35
 
@@ -92,7 +92,7 @@ export const widthOfTextAtSize = (
92
92
  text: string,
93
93
  fontKitFont: FontKitFont,
94
94
  fontSize: number,
95
- characterSpacing: number
95
+ characterSpacing: number,
96
96
  ) => {
97
97
  const { glyphs } = fontKitFont.layout(text);
98
98
  const scale = 1000 / fontKitFont.unitsPerEm;
@@ -112,7 +112,7 @@ const getCacheKey = (fontName: string) => `getFontKitFont-${fontName}`;
112
112
  export const getFontKitFont = async (
113
113
  fontName: string | undefined,
114
114
  font: Font,
115
- _cache: Map<any, any>
115
+ _cache: Map<any, any>,
116
116
  ) => {
117
117
  const fntNm = fontName || getFallbackFontName(font);
118
118
  const cacheKey = getCacheKey(fntNm);
@@ -129,7 +129,7 @@ export const getFontKitFont = async (
129
129
  }
130
130
 
131
131
  const fontKitFont = fontkit.create(
132
- fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer)
132
+ fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer),
133
133
  ) as fontkit.Font;
134
134
  _cache.set(cacheKey, fontKitFont);
135
135
 
@@ -281,7 +281,7 @@ export const calculateDynamicFontSize = ({
281
281
  line.replace('\n', ''),
282
282
  fontKitFont,
283
283
  size,
284
- characterSpacing
284
+ characterSpacing,
285
285
  );
286
286
  const textWidthInMm = pt2mm(textWidth);
287
287
  totalWidthInMm = Math.max(totalWidthInMm, textWidthInMm);
@@ -49,12 +49,12 @@ const embedAndGetFontObj = async (arg: {
49
49
  return pdfDoc.embedFont(fontData, {
50
50
  subset: typeof v.subset === 'undefined' ? true : v.subset,
51
51
  });
52
- })
52
+ }),
53
53
  );
54
54
 
55
55
  const fontObj = Object.keys(font).reduce(
56
56
  (acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }),
57
- {} as { [key: string]: PDFFont }
57
+ {} as { [key: string]: PDFFont },
58
58
  );
59
59
 
60
60
  _cache.set(pdfDoc, fontObj);
@@ -74,7 +74,7 @@ const getFontProp = ({
74
74
  }) => {
75
75
  const fontSize = schema.dynamicFontSize
76
76
  ? calculateDynamicFontSize({ textSchema: schema, fontKitFont, value })
77
- : schema.fontSize ?? DEFAULT_FONT_SIZE;
77
+ : (schema.fontSize ?? DEFAULT_FONT_SIZE);
78
78
  const color = hex2PrintingColor(schema.fontColor || DEFAULT_FONT_COLOR, colorType);
79
79
 
80
80
  return {