@pdfme/schemas 5.3.11-dev.9 → 5.3.12

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 (137) hide show
  1. package/dist/cjs/__tests__/barcode.test.js +37 -14
  2. package/dist/cjs/__tests__/barcode.test.js.map +1 -1
  3. package/dist/cjs/src/barcodes/constants.js +1 -0
  4. package/dist/cjs/src/barcodes/constants.js.map +1 -1
  5. package/dist/cjs/src/barcodes/helper.js +31 -16
  6. package/dist/cjs/src/barcodes/helper.js.map +1 -1
  7. package/dist/cjs/src/barcodes/propPanel.js +14 -1
  8. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  9. package/dist/cjs/src/checkbox/index.js.map +1 -1
  10. package/dist/cjs/src/date/helper.js.map +1 -1
  11. package/dist/cjs/src/graphics/image.js +4 -2
  12. package/dist/cjs/src/graphics/image.js.map +1 -1
  13. package/dist/cjs/src/graphics/svg.js.map +1 -1
  14. package/dist/cjs/src/multiVariableText/helper.js +3 -1
  15. package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
  16. package/dist/cjs/src/multiVariableText/propPanel.js +9 -5
  17. package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
  18. package/dist/cjs/src/multiVariableText/uiRender.js +3 -1
  19. package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
  20. package/dist/cjs/src/radioGroup/index.js.map +1 -1
  21. package/dist/cjs/src/select/index.js +7 -2
  22. package/dist/cjs/src/select/index.js.map +1 -1
  23. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  24. package/dist/cjs/src/tables/classes.js.map +1 -1
  25. package/dist/cjs/src/tables/pdfRender.js +16 -2
  26. package/dist/cjs/src/tables/pdfRender.js.map +1 -1
  27. package/dist/cjs/src/tables/tableHelper.js +6 -1
  28. package/dist/cjs/src/tables/tableHelper.js.map +1 -1
  29. package/dist/cjs/src/text/helper.js.map +1 -1
  30. package/dist/cjs/src/text/pdfRender.js +5 -1
  31. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  32. package/dist/cjs/src/text/propPanel.js.map +1 -1
  33. package/dist/cjs/src/text/uiRender.js.map +1 -1
  34. package/dist/cjs/src/utils.js.map +1 -1
  35. package/dist/esm/__tests__/barcode.test.js +37 -14
  36. package/dist/esm/__tests__/barcode.test.js.map +1 -1
  37. package/dist/esm/src/barcodes/constants.js +1 -0
  38. package/dist/esm/src/barcodes/constants.js.map +1 -1
  39. package/dist/esm/src/barcodes/helper.js +31 -16
  40. package/dist/esm/src/barcodes/helper.js.map +1 -1
  41. package/dist/esm/src/barcodes/propPanel.js +14 -1
  42. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  43. package/dist/esm/src/checkbox/index.js.map +1 -1
  44. package/dist/esm/src/date/helper.js +1 -1
  45. package/dist/esm/src/date/helper.js.map +1 -1
  46. package/dist/esm/src/graphics/image.js +4 -2
  47. package/dist/esm/src/graphics/image.js.map +1 -1
  48. package/dist/esm/src/graphics/svg.js.map +1 -1
  49. package/dist/esm/src/multiVariableText/helper.js +3 -1
  50. package/dist/esm/src/multiVariableText/helper.js.map +1 -1
  51. package/dist/esm/src/multiVariableText/propPanel.js +9 -5
  52. package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
  53. package/dist/esm/src/multiVariableText/uiRender.js +3 -1
  54. package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
  55. package/dist/esm/src/radioGroup/index.js.map +1 -1
  56. package/dist/esm/src/select/index.js +7 -2
  57. package/dist/esm/src/select/index.js.map +1 -1
  58. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  59. package/dist/esm/src/tables/classes.js.map +1 -1
  60. package/dist/esm/src/tables/pdfRender.js +16 -2
  61. package/dist/esm/src/tables/pdfRender.js.map +1 -1
  62. package/dist/esm/src/tables/tableHelper.js +6 -1
  63. package/dist/esm/src/tables/tableHelper.js.map +1 -1
  64. package/dist/esm/src/text/helper.js.map +1 -1
  65. package/dist/esm/src/text/pdfRender.js +5 -1
  66. package/dist/esm/src/text/pdfRender.js.map +1 -1
  67. package/dist/esm/src/text/propPanel.js.map +1 -1
  68. package/dist/esm/src/text/uiRender.js.map +1 -1
  69. package/dist/esm/src/utils.js.map +1 -1
  70. package/dist/node/__tests__/barcode.test.js +37 -14
  71. package/dist/node/__tests__/barcode.test.js.map +1 -1
  72. package/dist/node/src/barcodes/constants.js +1 -0
  73. package/dist/node/src/barcodes/constants.js.map +1 -1
  74. package/dist/node/src/barcodes/helper.js +31 -16
  75. package/dist/node/src/barcodes/helper.js.map +1 -1
  76. package/dist/node/src/barcodes/propPanel.js +14 -1
  77. package/dist/node/src/barcodes/propPanel.js.map +1 -1
  78. package/dist/node/src/checkbox/index.js.map +1 -1
  79. package/dist/node/src/date/helper.js.map +1 -1
  80. package/dist/node/src/graphics/image.js +4 -2
  81. package/dist/node/src/graphics/image.js.map +1 -1
  82. package/dist/node/src/graphics/svg.js.map +1 -1
  83. package/dist/node/src/multiVariableText/helper.js +3 -1
  84. package/dist/node/src/multiVariableText/helper.js.map +1 -1
  85. package/dist/node/src/multiVariableText/propPanel.js +9 -5
  86. package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
  87. package/dist/node/src/multiVariableText/uiRender.js +3 -1
  88. package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
  89. package/dist/node/src/radioGroup/index.js.map +1 -1
  90. package/dist/node/src/select/index.js +7 -2
  91. package/dist/node/src/select/index.js.map +1 -1
  92. package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
  93. package/dist/node/src/tables/classes.js.map +1 -1
  94. package/dist/node/src/tables/pdfRender.js +16 -2
  95. package/dist/node/src/tables/pdfRender.js.map +1 -1
  96. package/dist/node/src/tables/tableHelper.js +6 -1
  97. package/dist/node/src/tables/tableHelper.js.map +1 -1
  98. package/dist/node/src/text/helper.js.map +1 -1
  99. package/dist/node/src/text/pdfRender.js +5 -1
  100. package/dist/node/src/text/pdfRender.js.map +1 -1
  101. package/dist/node/src/text/propPanel.js.map +1 -1
  102. package/dist/node/src/text/uiRender.js.map +1 -1
  103. package/dist/node/src/utils.js.map +1 -1
  104. package/dist/types/src/barcodes/constants.d.ts +1 -1
  105. package/dist/types/src/barcodes/helper.d.ts +1 -10
  106. package/dist/types/src/barcodes/index.d.ts +1 -1
  107. package/dist/types/src/checkbox/index.d.ts +1 -2
  108. package/dist/types/src/radioGroup/index.d.ts +1 -2
  109. package/dist/types/src/shapes/rectAndEllipse.d.ts +89 -5
  110. package/dist/types/src/tables/classes.d.ts +1 -1
  111. package/dist/types/src/tables/dynamicTemplate.d.ts +1 -1
  112. package/dist/types/src/tables/tableHelper.d.ts +1 -1
  113. package/dist/types/src/text/helper.d.ts +1 -1
  114. package/dist/types/src/utils.d.ts +1 -1
  115. package/package.json +2 -2
  116. package/src/barcodes/constants.ts +1 -0
  117. package/src/barcodes/helper.ts +35 -38
  118. package/src/barcodes/propPanel.ts +14 -1
  119. package/src/checkbox/index.ts +3 -4
  120. package/src/date/helper.ts +10 -3
  121. package/src/graphics/image.ts +3 -1
  122. package/src/graphics/svg.ts +3 -4
  123. package/src/multiVariableText/helper.ts +4 -2
  124. package/src/multiVariableText/propPanel.ts +12 -5
  125. package/src/multiVariableText/uiRender.ts +8 -2
  126. package/src/radioGroup/index.ts +3 -4
  127. package/src/select/index.ts +11 -5
  128. package/src/shapes/rectAndEllipse.ts +4 -4
  129. package/src/tables/classes.ts +6 -2
  130. package/src/tables/dynamicTemplate.ts +1 -1
  131. package/src/tables/pdfRender.ts +28 -3
  132. package/src/tables/tableHelper.ts +7 -2
  133. package/src/text/helper.ts +1 -1
  134. package/src/text/pdfRender.ts +5 -1
  135. package/src/text/propPanel.ts +3 -1
  136. package/src/text/uiRender.ts +5 -1
  137. package/src/utils.ts +5 -1
@@ -172,10 +172,23 @@ const barcodeDefaults: { defaultSchema: BarcodeSchema }[] = [
172
172
  opacity: DEFAULT_OPACITY,
173
173
  },
174
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
+ },
175
188
  ];
176
189
 
177
190
  export const getPropPanelByBarcodeType = (barcodeType: string): PropPanel<BarcodeSchema> => {
178
- const barcodeHasText = barcodeType !== 'qrcode' && barcodeType !== 'gs1datamatrix';
191
+ const barcodeHasText = barcodeType !== 'qrcode' && barcodeType !== 'gs1datamatrix' && barcodeType !== 'pdf417';
179
192
 
180
193
  const defaults = barcodeDefaults.find(({ defaultSchema }) => defaultSchema.type === barcodeType);
181
194
 
@@ -1,5 +1,4 @@
1
- import { Plugin } from '@pdfme/common';
2
- import { Schema } from '@pdfme/common';
1
+ import { Plugin, Schema, UIRenderProps, PDFRenderProps } from '@pdfme/common';
3
2
  import svg from '../graphics/svg.js';
4
3
  import { isEditable } from '../utils.js';
5
4
  import { HEX_COLOR_PATTERN } from '../constants.js';
@@ -19,7 +18,7 @@ const getIcon = ({ value, color }: { value: string; color: string }) =>
19
18
  value === 'true' ? getCheckedIcon(color) : getUncheckedIcon(color);
20
19
 
21
20
  const schema: Plugin<Checkbox> = {
22
- ui: (arg) => {
21
+ ui: (arg: UIRenderProps<Checkbox>) => {
23
22
  const { schema, value, onChange, rootElement, mode } = arg;
24
23
  const container = document.createElement('div');
25
24
  container.style.width = '100%';
@@ -40,7 +39,7 @@ const schema: Plugin<Checkbox> = {
40
39
 
41
40
  rootElement.appendChild(container);
42
41
  },
43
- pdf: (arg) =>
42
+ pdf: (arg: PDFRenderProps<Checkbox>) =>
44
43
  svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
45
44
  propPanel: {
46
45
  schema: ({ i18n }) => ({
@@ -39,7 +39,14 @@ import localeZh from 'air-datepicker/locale/zh';
39
39
  import * as dateFns from 'date-fns/locale';
40
40
  import { format } from 'date-fns';
41
41
 
42
- import { Plugin, getFallbackFontName, DEFAULT_FONT_NAME, PropPanelSchema } from '@pdfme/common';
42
+ import {
43
+ Plugin,
44
+ getFallbackFontName,
45
+ DEFAULT_FONT_NAME,
46
+ PropPanelSchema,
47
+ UIRenderProps,
48
+ PDFRenderProps,
49
+ } from '@pdfme/common';
43
50
  import text from '../text/index.js';
44
51
  import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
45
52
  import { mapVerticalAlignToFlex } from '../text/uiRender.js';
@@ -200,7 +207,7 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
200
207
  const defaultFormat = getFormat(type, getAirDatepickerLocale(defaultLocale));
201
208
 
202
209
  const plugin: Plugin<DateSchema> = {
203
- ui: async (arg) => {
210
+ ui: async (arg: UIRenderProps<DateSchema>) => {
204
211
  const { schema, value, onChange, rootElement, mode, options, i18n } = arg;
205
212
 
206
213
  const locale = getAirDatepickerLocale(schema.locale || options.lang || defaultLocale);
@@ -297,7 +304,7 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
297
304
  rootElement.appendChild(input);
298
305
  rootElement.appendChild(textElement);
299
306
  },
300
- pdf: (arg) => {
307
+ pdf: (arg: PDFRenderProps<DateSchema>) => {
301
308
  const { schema, value, options } = arg;
302
309
  if (!value) return void 0;
303
310
  const locale = getAirDatepickerLocale(schema.locale || options.lang || defaultLocale);
@@ -174,7 +174,9 @@ const imageSchema: Plugin<ImageSchema> = {
174
174
  console.error('Error reading file:', error);
175
175
  });
176
176
  });
177
- input.addEventListener('blur', () => { if (stopEditing) stopEditing(); });
177
+ input.addEventListener('blur', () => {
178
+ if (stopEditing) stopEditing();
179
+ });
178
180
  label.appendChild(input);
179
181
  }
180
182
  },
@@ -1,4 +1,4 @@
1
- import { Plugin, Schema } from '@pdfme/common';
1
+ import { Plugin, Schema, UIRenderProps, PDFRenderProps } from '@pdfme/common';
2
2
  import {
3
3
  convertForPdfLayoutProps,
4
4
  isEditable,
@@ -42,11 +42,10 @@ const defaultValue = `<svg viewBox="0 0 488 600" version="1.1" xmlns="http://www
42
42
  </g>
43
43
  </svg>`;
44
44
 
45
- // This interface extends Schema with no additional properties
46
45
  export type SVGSchema = Schema;
47
46
 
48
47
  const svgSchema: Plugin<SVGSchema> = {
49
- ui: (arg) => {
48
+ ui: (arg: UIRenderProps<SVGSchema>) => {
50
49
  const { rootElement, value, mode, onChange, theme, schema } = arg;
51
50
  const container = document.createElement(isEditable(mode, schema) ? 'textarea' : 'div');
52
51
  container.style.width = '100%';
@@ -94,7 +93,7 @@ const svgSchema: Plugin<SVGSchema> = {
94
93
  }
95
94
  }
96
95
  },
97
- pdf: async (arg) => {
96
+ pdf: async (arg: PDFRenderProps<SVGSchema>) => {
98
97
  const { page, schema, value } = arg;
99
98
  if (!value || !isValidSVG(value)) return;
100
99
  const pageHeight = page.getHeight();
@@ -12,7 +12,9 @@ export const substituteVariables = (
12
12
 
13
13
  if (variablesIn) {
14
14
  const variables: Record<string, string> =
15
- typeof variablesIn === 'string' ? JSON.parse(variablesIn || '{}') as Record<string, string> : variablesIn;
15
+ typeof variablesIn === 'string'
16
+ ? (JSON.parse(variablesIn || '{}') as Record<string, string>)
17
+ : variablesIn;
16
18
 
17
19
  Object.keys(variables).forEach((variableName) => {
18
20
  // handle special characters in variable name
@@ -35,7 +37,7 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
35
37
 
36
38
  let values;
37
39
  try {
38
- values = value ? JSON.parse(value) as Record<string, string> : {};
40
+ values = value ? (JSON.parse(value) as Record<string, string>) : {};
39
41
  } catch {
40
42
  throw new SyntaxError(
41
43
  `[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`,
@@ -55,12 +55,18 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
55
55
  const para = document.createElement('p');
56
56
  // Extract color value to avoid unsafe property access
57
57
  const colorValue = options?.theme?.token?.colorPrimary || '#168fe3';
58
- const isValidColor = /^#[0-9A-F]{6}$/i.test(colorValue) || /^(rgb|hsl)a?\(\s*([+-]?\d+%?\s*,\s*){2,3}[+-]?\d+%?\s*\)$/i.test(colorValue);
58
+ const isValidColor =
59
+ /^#[0-9A-F]{6}$/i.test(colorValue) ||
60
+ /^(rgb|hsl)a?\(\s*([+-]?\d+%?\s*,\s*){2,3}[+-]?\d+%?\s*\)$/i.test(colorValue);
59
61
  const safeColorValue = isValidColor ? colorValue : '#168fe3';
62
+
63
+ // Use safe string concatenation for innerHTML
64
+ const typingInstructions = i18n('schemas.mvt.typingInstructions');
65
+ const sampleField = i18n('schemas.mvt.sampleField');
60
66
  para.innerHTML =
61
- i18n('schemas.mvt.typingInstructions') +
67
+ typingInstructions +
62
68
  ` <code style="color:${safeColorValue}; font-weight:bold;">{` +
63
- i18n('schemas.mvt.sampleField') +
69
+ sampleField +
64
70
  '}</code>';
65
71
  rootElement.appendChild(para);
66
72
  }
@@ -72,12 +78,13 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
72
78
  throw new Error('Oops, is text schema no longer a function?');
73
79
  }
74
80
  // Safely call schema function with proper type handling
75
- const parentSchema = parentPropPanel.schema?.(propPanelProps) || {};
81
+ const parentSchema =
82
+ typeof parentPropPanel.schema === 'function' ? parentPropPanel.schema(propPanelProps) : {};
76
83
  return {
77
84
  ...parentSchema,
78
85
  '-------': { type: 'void', widget: 'Divider' },
79
86
  dynamicVarContainer: {
80
- title: typeof propPanelProps.i18n === 'function' ? propPanelProps.i18n('schemas.mvt.variablesSampleData') : 'Variables Sample Data',
87
+ title: 'Variables Sample Data',
81
88
  type: 'string',
82
89
  widget: 'Card',
83
90
  span: 24,
@@ -75,11 +75,17 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
75
75
  rootElement.parentElement.style.outline = '';
76
76
  }
77
77
 
78
- const variables: Record<string, string> = value ? JSON.parse(value) as Record<string, string> || {} : {};
78
+ const variables: Record<string, string> = value
79
+ ? (JSON.parse(value) as Record<string, string>) || {}
80
+ : {};
79
81
  const variableIndices = getVariableIndices(rawText);
80
82
  const substitutedText = substituteVariables(rawText, variables);
81
83
  const font = options?.font || getDefaultFont();
82
- const fontKitFont = await getFontKitFont(schema.fontName, font, _cache as Map<string, import('fontkit').Font>);
84
+ const fontKitFont = await getFontKitFont(
85
+ schema.fontName,
86
+ font,
87
+ _cache as Map<string, import('fontkit').Font>,
88
+ );
83
89
 
84
90
  const textBlock = buildStyledTextContainer(arg, fontKitFont, substitutedText);
85
91
 
@@ -1,5 +1,4 @@
1
- import { Plugin } from '@pdfme/common';
2
- import { Schema } from '@pdfme/common';
1
+ import { Plugin, Schema, UIRenderProps, PDFRenderProps } from '@pdfme/common';
3
2
  import { Circle, CircleDot } from 'lucide';
4
3
  import svg from '../graphics/svg.js';
5
4
  import { isEditable, createSvgStr } from '../utils.js';
@@ -29,7 +28,7 @@ const radioButtonStates = new Map<string, RadioButtonState>();
29
28
  const eventListeners = new Map<string, EventListener>();
30
29
 
31
30
  const schema: Plugin<RadioGroup> = {
32
- ui: (arg) => {
31
+ ui: (arg: UIRenderProps<RadioGroup>) => {
33
32
  const { schema, value, onChange, rootElement, mode } = arg;
34
33
  const container = document.createElement('div');
35
34
  container.style.width = '100%';
@@ -80,7 +79,7 @@ const schema: Plugin<RadioGroup> = {
80
79
 
81
80
  rootElement.appendChild(container);
82
81
  },
83
- pdf: (arg) =>
82
+ pdf: (arg: PDFRenderProps<RadioGroup>) =>
84
83
  svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
85
84
  propPanel: {
86
85
  schema: ({ i18n }) => ({
@@ -1,6 +1,6 @@
1
1
  import type * as CSS from 'csstype';
2
2
  import { propPanel as parentPropPanel } from '../text/propPanel.js';
3
- import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common';
3
+ import { Plugin, PropPanelWidgetProps, SchemaForUI, UIRenderProps } from '@pdfme/common';
4
4
  import text from '../text/index.js';
5
5
  import { TextSchema } from '../text/types.js';
6
6
  import { ChevronDown } from 'lucide';
@@ -112,7 +112,7 @@ const addOptions = (props: PropPanelWidgetProps) => {
112
112
  };
113
113
 
114
114
  const schema: Plugin<Select> = {
115
- ui: async (arg) => {
115
+ ui: async (arg: UIRenderProps<Select>) => {
116
116
  const { schema, value, onChange, rootElement, mode } = arg;
117
117
  await text.ui(Object.assign(arg, { mode: 'viewer' }));
118
118
 
@@ -154,7 +154,9 @@ const schema: Plugin<Select> = {
154
154
  }
155
155
  });
156
156
 
157
- selectElement.innerHTML = schema.options
157
+ // Ensure schema.options is an array before mapping
158
+ const options = Array.isArray(schema.options) ? schema.options : [];
159
+ selectElement.innerHTML = options
158
160
  .map(
159
161
  (option) =>
160
162
  `<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`,
@@ -172,8 +174,12 @@ const schema: Plugin<Select> = {
172
174
  throw Error('Oops, is text schema no longer a function?');
173
175
  }
174
176
 
177
+ // Safely call the parent schema function with proper type checking
178
+ const parentSchema = parentPropPanel.schema(propPanelProps);
179
+
180
+ // Create a type-safe return object
175
181
  return {
176
- ...parentPropPanel.schema(propPanelProps),
182
+ ...parentSchema,
177
183
  '-------': { type: 'void', widget: 'Divider' },
178
184
 
179
185
  optionsContainer: {
@@ -186,7 +192,7 @@ const schema: Plugin<Select> = {
186
192
  };
187
193
  },
188
194
  defaultSchema: {
189
- ...text.propPanel.defaultSchema,
195
+ ...(text.propPanel.defaultSchema as TextSchema),
190
196
  type: 'select',
191
197
  content: 'option1',
192
198
  options: ['option1', 'option2'],
@@ -1,4 +1,4 @@
1
- import { Plugin, Schema, mm2pt } from '@pdfme/common';
1
+ import { Plugin, Schema, mm2pt, UIRenderProps, PDFRenderProps } from '@pdfme/common';
2
2
  import { HEX_COLOR_PATTERN } from '../constants.js';
3
3
  import { hex2PrintingColor, convertForPdfLayoutProps, createSvgStr } from '../utils.js';
4
4
  import { toRadians } from '@pdfme/pdf-lib';
@@ -12,7 +12,7 @@ interface ShapeSchema extends Schema {
12
12
  }
13
13
 
14
14
  const shape: Plugin<ShapeSchema> = {
15
- ui: (arg) => {
15
+ ui: (arg: UIRenderProps<ShapeSchema>) => {
16
16
  const { schema, rootElement } = arg;
17
17
  const div = document.createElement('div');
18
18
  div.style.width = '100%';
@@ -28,7 +28,7 @@ const shape: Plugin<ShapeSchema> = {
28
28
 
29
29
  rootElement.appendChild(div);
30
30
  },
31
- pdf: (arg) => {
31
+ pdf: (arg: PDFRenderProps<ShapeSchema>) => {
32
32
  const { schema, page, options } = arg;
33
33
  if (!schema.color && !schema.borderColor) return;
34
34
  const { colorType } = options;
@@ -119,7 +119,7 @@ const shape: Plugin<ShapeSchema> = {
119
119
  const getPropPanelSchema = (type: 'rectangle' | 'ellipse') => ({
120
120
  ...shape.propPanel,
121
121
  defaultSchema: {
122
- ...shape.propPanel.defaultSchema,
122
+ ...(shape.propPanel.defaultSchema as ShapeSchema),
123
123
  type,
124
124
  },
125
125
  });
@@ -114,7 +114,7 @@ export class Table {
114
114
  input: TableInput;
115
115
  content: ContentSettings;
116
116
  font: Font;
117
- _cache: Map<string, FontKitFont>;
117
+ _cache: Map<string | number, FontKitFont>;
118
118
  }) {
119
119
  const { input, content, font, _cache } = arg;
120
120
  const table = new Table(input, content);
@@ -145,7 +145,11 @@ export class Table {
145
145
  }
146
146
  }
147
147
 
148
- async function calculateWidths(arg: { table: Table; font: Font; _cache: Map<string, FontKitFont> }) {
148
+ async function calculateWidths(arg: {
149
+ table: Table;
150
+ font: Font;
151
+ _cache: Map<string | number, FontKitFont>;
152
+ }) {
149
153
  const { table, font, _cache } = arg;
150
154
 
151
155
  const getFontKitFontByFontName = (fontName: string | undefined) =>
@@ -9,7 +9,7 @@ export const getDynamicHeightsForTable = async (
9
9
  schema: Schema;
10
10
  basePdf: BasePdf;
11
11
  options: CommonOptions;
12
- _cache: Map<string, unknown>;
12
+ _cache: Map<string | number, unknown>;
13
13
  },
14
14
  ): Promise<number[]> => {
15
15
  if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
@@ -1,11 +1,19 @@
1
1
  import type { TableSchema } from './types.js';
2
- import type { PDFRenderProps } from '@pdfme/common';
2
+ import type { PDFRenderProps, Schema, BasePdf, CommonOptions } from '@pdfme/common';
3
3
  import { Cell, Table, Row, Column } from './classes.js';
4
4
  import { rectangle } from '../shapes/rectAndEllipse.js';
5
5
  import cell from './cell.js';
6
6
  import { getBodyWithRange } from './helper.js';
7
7
  import { createSingleTable } from './tableHelper.js';
8
8
 
9
+ // Define the CreateTableArgs interface locally since it's not exported from tableHelper.js
10
+ interface CreateTableArgs {
11
+ schema: Schema;
12
+ basePdf: BasePdf;
13
+ options: CommonOptions;
14
+ _cache: Map<string | number, unknown>;
15
+ }
16
+
9
17
  type Pos = { x: number; y: number };
10
18
 
11
19
  const rectanglePdfRender = rectangle.pdf;
@@ -108,12 +116,29 @@ async function drawTable(arg: PDFRenderProps<TableSchema>, table: Table): Promis
108
116
  }
109
117
 
110
118
  export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
111
- const { value, schema } = arg;
119
+ const { value, schema, basePdf, options, _cache } = arg;
112
120
 
113
121
  const body = getBodyWithRange(
114
122
  typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
115
123
  schema.__bodyRange,
116
124
  );
117
- const table = await createSingleTable(body, arg);
125
+
126
+ // Create a properly typed CreateTableArgs object
127
+ const createTableArgs: CreateTableArgs = {
128
+ schema,
129
+ basePdf,
130
+ options,
131
+ _cache,
132
+ };
133
+
134
+ // Ensure body is properly typed before passing to createSingleTable
135
+ // Ensure body is properly typed as string[][] before passing to createSingleTable
136
+ const typedBody: string[][] = Array.isArray(body)
137
+ ? body.map((row) => (Array.isArray(row) ? row.map((cell) => String(cell)) : []))
138
+ : [];
139
+ const table = await createSingleTable(typedBody, createTableArgs);
140
+
141
+ // Use the original arg directly since drawTable expects PDFRenderProps<TableSchema>
142
+ // which is the same type as our arg parameter
118
143
  await drawTable(arg, table);
119
144
  };
@@ -25,7 +25,7 @@ interface CreateTableArgs {
25
25
  schema: Schema;
26
26
  basePdf: BasePdf;
27
27
  options: CommonOptions;
28
- _cache: Map<string, unknown>;
28
+ _cache: Map<string | number, unknown>;
29
29
  }
30
30
 
31
31
  interface UserOptions {
@@ -279,5 +279,10 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
279
279
 
280
280
  const content = parseContent4Table(input, fallbackFontName);
281
281
 
282
- return Table.create({ input, content, font, _cache: _cache as Map<string, FontKitFont> });
282
+ return Table.create({
283
+ input,
284
+ content,
285
+ font,
286
+ _cache: _cache as unknown as Map<string | number, FontKitFont>,
287
+ });
283
288
  }
@@ -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<string, fontkit.Font>,
115
+ _cache: Map<string | number, fontkit.Font>,
116
116
  ) => {
117
117
  const fntNm = fontName || getFallbackFontName(font);
118
118
  const cacheKey = getCacheKey(fntNm);
@@ -94,7 +94,11 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
94
94
  const { font = getDefaultFont(), colorType } = options;
95
95
 
96
96
  const [pdfFontObj, fontKitFont] = await Promise.all([
97
- embedAndGetFontObj({ pdfDoc, font, _cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }> }),
97
+ embedAndGetFontObj({
98
+ pdfDoc,
99
+ font,
100
+ _cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }>,
101
+ }),
98
102
  getFontKitFont(schema.fontName, font, _cache as Map<string, FontKitFont>),
99
103
  ]);
100
104
  const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
@@ -54,7 +54,9 @@ export const propPanel: PropPanel<TextSchema> = {
54
54
  const fontNames = Object.keys(font);
55
55
  const fallbackFontName = getFallbackFontName(font);
56
56
 
57
- const enableDynamicFont = Boolean((activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize);
57
+ const enableDynamicFont = Boolean(
58
+ (activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize,
59
+ );
58
60
 
59
61
  const textSchema: Record<string, PropPanelSchema> = {
60
62
  fontName: {
@@ -69,7 +69,11 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
69
69
  return text;
70
70
  };
71
71
  const font = options?.font || getDefaultFont();
72
- const fontKitFont = await getFontKitFont(schema.fontName, font, _cache as Map<string, import('fontkit').Font>);
72
+ const fontKitFont = await getFontKitFont(
73
+ schema.fontName,
74
+ font,
75
+ _cache as Map<string, import('fontkit').Font>,
76
+ );
73
77
  const textBlock = buildStyledTextContainer(
74
78
  arg,
75
79
  fontKitFont,
package/src/utils.ts CHANGED
@@ -243,7 +243,11 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
243
243
  return String(element);
244
244
  }
245
245
 
246
- const [tag, attributes = {}, children = []] = element as [unknown, Record<string, string>, unknown[]];
246
+ const [tag, attributes = {}, children = []] = element as [
247
+ unknown,
248
+ Record<string, string>,
249
+ unknown[],
250
+ ];
247
251
  const tagName = String(tag);
248
252
 
249
253
  // Format attributes string