@pdfme/schemas 5.3.11 → 5.3.12-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 (201) 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/pdfRender.js +5 -1
  8. package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
  9. package/dist/cjs/src/barcodes/propPanel.js +14 -1
  10. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  11. package/dist/cjs/src/barcodes/uiRender.js +5 -3
  12. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  13. package/dist/cjs/src/checkbox/index.js +2 -1
  14. package/dist/cjs/src/checkbox/index.js.map +1 -1
  15. package/dist/cjs/src/date/helper.js +1 -1
  16. package/dist/cjs/src/date/helper.js.map +1 -1
  17. package/dist/cjs/src/graphics/image.js +8 -3
  18. package/dist/cjs/src/graphics/image.js.map +1 -1
  19. package/dist/cjs/src/graphics/svg.js +3 -2
  20. package/dist/cjs/src/graphics/svg.js.map +1 -1
  21. package/dist/cjs/src/multiVariableText/helper.js +5 -3
  22. package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
  23. package/dist/cjs/src/multiVariableText/propPanel.js +24 -12
  24. package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
  25. package/dist/cjs/src/multiVariableText/uiRender.js +17 -12
  26. package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
  27. package/dist/cjs/src/radioGroup/index.js.map +1 -1
  28. package/dist/cjs/src/select/index.js +9 -3
  29. package/dist/cjs/src/select/index.js.map +1 -1
  30. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  31. package/dist/cjs/src/tables/classes.js.map +1 -1
  32. package/dist/cjs/src/tables/pdfRender.js +16 -2
  33. package/dist/cjs/src/tables/pdfRender.js.map +1 -1
  34. package/dist/cjs/src/tables/propPanel.js +1 -1
  35. package/dist/cjs/src/tables/propPanel.js.map +1 -1
  36. package/dist/cjs/src/tables/tableHelper.js +6 -1
  37. package/dist/cjs/src/tables/tableHelper.js.map +1 -1
  38. package/dist/cjs/src/tables/uiRender.js +4 -2
  39. package/dist/cjs/src/tables/uiRender.js.map +1 -1
  40. package/dist/cjs/src/text/extraFormatter.js +1 -0
  41. package/dist/cjs/src/text/extraFormatter.js.map +1 -1
  42. package/dist/cjs/src/text/helper.js +19 -3
  43. package/dist/cjs/src/text/helper.js.map +1 -1
  44. package/dist/cjs/src/text/pdfRender.js +5 -1
  45. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  46. package/dist/cjs/src/text/propPanel.js.map +1 -1
  47. package/dist/cjs/src/text/uiRender.js +9 -8
  48. package/dist/cjs/src/text/uiRender.js.map +1 -1
  49. package/dist/cjs/src/utils.js +3 -3
  50. package/dist/cjs/src/utils.js.map +1 -1
  51. package/dist/esm/__tests__/barcode.test.js +37 -14
  52. package/dist/esm/__tests__/barcode.test.js.map +1 -1
  53. package/dist/esm/src/barcodes/constants.js +1 -0
  54. package/dist/esm/src/barcodes/constants.js.map +1 -1
  55. package/dist/esm/src/barcodes/helper.js +31 -16
  56. package/dist/esm/src/barcodes/helper.js.map +1 -1
  57. package/dist/esm/src/barcodes/pdfRender.js +5 -1
  58. package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
  59. package/dist/esm/src/barcodes/propPanel.js +14 -1
  60. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  61. package/dist/esm/src/barcodes/uiRender.js +5 -3
  62. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  63. package/dist/esm/src/checkbox/index.js +2 -1
  64. package/dist/esm/src/checkbox/index.js.map +1 -1
  65. package/dist/esm/src/date/helper.js +2 -2
  66. package/dist/esm/src/date/helper.js.map +1 -1
  67. package/dist/esm/src/graphics/image.js +8 -3
  68. package/dist/esm/src/graphics/image.js.map +1 -1
  69. package/dist/esm/src/graphics/svg.js +3 -2
  70. package/dist/esm/src/graphics/svg.js.map +1 -1
  71. package/dist/esm/src/multiVariableText/helper.js +5 -3
  72. package/dist/esm/src/multiVariableText/helper.js.map +1 -1
  73. package/dist/esm/src/multiVariableText/propPanel.js +24 -12
  74. package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
  75. package/dist/esm/src/multiVariableText/uiRender.js +17 -12
  76. package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
  77. package/dist/esm/src/radioGroup/index.js.map +1 -1
  78. package/dist/esm/src/select/index.js +9 -3
  79. package/dist/esm/src/select/index.js.map +1 -1
  80. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  81. package/dist/esm/src/tables/classes.js.map +1 -1
  82. package/dist/esm/src/tables/pdfRender.js +16 -2
  83. package/dist/esm/src/tables/pdfRender.js.map +1 -1
  84. package/dist/esm/src/tables/propPanel.js +1 -1
  85. package/dist/esm/src/tables/propPanel.js.map +1 -1
  86. package/dist/esm/src/tables/tableHelper.js +6 -1
  87. package/dist/esm/src/tables/tableHelper.js.map +1 -1
  88. package/dist/esm/src/tables/uiRender.js +4 -2
  89. package/dist/esm/src/tables/uiRender.js.map +1 -1
  90. package/dist/esm/src/text/extraFormatter.js +1 -0
  91. package/dist/esm/src/text/extraFormatter.js.map +1 -1
  92. package/dist/esm/src/text/helper.js +19 -3
  93. package/dist/esm/src/text/helper.js.map +1 -1
  94. package/dist/esm/src/text/pdfRender.js +5 -1
  95. package/dist/esm/src/text/pdfRender.js.map +1 -1
  96. package/dist/esm/src/text/propPanel.js.map +1 -1
  97. package/dist/esm/src/text/uiRender.js +8 -6
  98. package/dist/esm/src/text/uiRender.js.map +1 -1
  99. package/dist/esm/src/utils.js +3 -3
  100. package/dist/esm/src/utils.js.map +1 -1
  101. package/dist/node/__tests__/barcode.test.js +37 -14
  102. package/dist/node/__tests__/barcode.test.js.map +1 -1
  103. package/dist/node/src/barcodes/constants.js +1 -0
  104. package/dist/node/src/barcodes/constants.js.map +1 -1
  105. package/dist/node/src/barcodes/helper.js +31 -16
  106. package/dist/node/src/barcodes/helper.js.map +1 -1
  107. package/dist/node/src/barcodes/pdfRender.js +5 -1
  108. package/dist/node/src/barcodes/pdfRender.js.map +1 -1
  109. package/dist/node/src/barcodes/propPanel.js +14 -1
  110. package/dist/node/src/barcodes/propPanel.js.map +1 -1
  111. package/dist/node/src/barcodes/uiRender.js +5 -3
  112. package/dist/node/src/barcodes/uiRender.js.map +1 -1
  113. package/dist/node/src/checkbox/index.js +2 -1
  114. package/dist/node/src/checkbox/index.js.map +1 -1
  115. package/dist/node/src/date/helper.js +1 -1
  116. package/dist/node/src/date/helper.js.map +1 -1
  117. package/dist/node/src/graphics/image.js +8 -3
  118. package/dist/node/src/graphics/image.js.map +1 -1
  119. package/dist/node/src/graphics/svg.js +3 -2
  120. package/dist/node/src/graphics/svg.js.map +1 -1
  121. package/dist/node/src/multiVariableText/helper.js +5 -3
  122. package/dist/node/src/multiVariableText/helper.js.map +1 -1
  123. package/dist/node/src/multiVariableText/propPanel.js +24 -12
  124. package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
  125. package/dist/node/src/multiVariableText/uiRender.js +17 -12
  126. package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
  127. package/dist/node/src/radioGroup/index.js.map +1 -1
  128. package/dist/node/src/select/index.js +9 -3
  129. package/dist/node/src/select/index.js.map +1 -1
  130. package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
  131. package/dist/node/src/tables/classes.js.map +1 -1
  132. package/dist/node/src/tables/pdfRender.js +16 -2
  133. package/dist/node/src/tables/pdfRender.js.map +1 -1
  134. package/dist/node/src/tables/propPanel.js +1 -1
  135. package/dist/node/src/tables/propPanel.js.map +1 -1
  136. package/dist/node/src/tables/tableHelper.js +6 -1
  137. package/dist/node/src/tables/tableHelper.js.map +1 -1
  138. package/dist/node/src/tables/uiRender.js +4 -2
  139. package/dist/node/src/tables/uiRender.js.map +1 -1
  140. package/dist/node/src/text/extraFormatter.js +1 -0
  141. package/dist/node/src/text/extraFormatter.js.map +1 -1
  142. package/dist/node/src/text/helper.js +19 -3
  143. package/dist/node/src/text/helper.js.map +1 -1
  144. package/dist/node/src/text/pdfRender.js +5 -1
  145. package/dist/node/src/text/pdfRender.js.map +1 -1
  146. package/dist/node/src/text/propPanel.js.map +1 -1
  147. package/dist/node/src/text/uiRender.js +9 -8
  148. package/dist/node/src/text/uiRender.js.map +1 -1
  149. package/dist/node/src/utils.js +3 -3
  150. package/dist/node/src/utils.js.map +1 -1
  151. package/dist/types/src/barcodes/constants.d.ts +1 -1
  152. package/dist/types/src/barcodes/helper.d.ts +1 -1
  153. package/dist/types/src/barcodes/index.d.ts +1 -1
  154. package/dist/types/src/checkbox/index.d.ts +1 -2
  155. package/dist/types/src/graphics/image.d.ts +1 -2
  156. package/dist/types/src/graphics/svg.d.ts +1 -2
  157. package/dist/types/src/radioGroup/index.d.ts +1 -2
  158. package/dist/types/src/shapes/rectAndEllipse.d.ts +91 -7
  159. package/dist/types/src/tables/classes.d.ts +2 -1
  160. package/dist/types/src/tables/dynamicTemplate.d.ts +1 -1
  161. package/dist/types/src/tables/tableHelper.d.ts +1 -1
  162. package/dist/types/src/text/extraFormatter.d.ts +2 -3
  163. package/dist/types/src/text/helper.d.ts +1 -1
  164. package/dist/types/src/text/uiRender.d.ts +0 -3
  165. package/dist/types/src/utils.d.ts +1 -1
  166. package/package.json +2 -2
  167. package/src/barcodes/constants.ts +1 -0
  168. package/src/barcodes/helper.ts +35 -26
  169. package/src/barcodes/pdfRender.ts +7 -4
  170. package/src/barcodes/propPanel.ts +14 -1
  171. package/src/barcodes/uiRender.ts +3 -3
  172. package/src/checkbox/index.ts +4 -5
  173. package/src/date/helper.ts +15 -8
  174. package/src/graphics/image.ts +6 -4
  175. package/src/graphics/svg.ts +6 -6
  176. package/src/multiVariableText/helper.ts +6 -4
  177. package/src/multiVariableText/propPanel.ts +29 -14
  178. package/src/multiVariableText/uiRender.ts +22 -15
  179. package/src/radioGroup/index.ts +3 -4
  180. package/src/select/index.ts +12 -6
  181. package/src/shapes/rectAndEllipse.ts +4 -4
  182. package/src/tables/classes.ts +6 -2
  183. package/src/tables/dynamicTemplate.ts +1 -1
  184. package/src/tables/pdfRender.ts +28 -3
  185. package/src/tables/propPanel.ts +1 -1
  186. package/src/tables/tableHelper.ts +8 -2
  187. package/src/tables/uiRender.ts +2 -2
  188. package/src/text/extraFormatter.ts +3 -3
  189. package/src/text/helper.ts +19 -6
  190. package/src/text/pdfRender.ts +7 -3
  191. package/src/text/propPanel.ts +6 -4
  192. package/src/text/uiRender.ts +11 -7
  193. package/src/utils.ts +9 -5
  194. package/dist/cjs/src/graphics/cacheKey.js +0 -6
  195. package/dist/cjs/src/graphics/cacheKey.js.map +0 -1
  196. package/dist/esm/src/graphics/cacheKey.js +0 -2
  197. package/dist/esm/src/graphics/cacheKey.js.map +0 -1
  198. package/dist/node/src/graphics/cacheKey.js +0 -6
  199. package/dist/node/src/graphics/cacheKey.js.map +0 -1
  200. package/dist/types/src/graphics/cacheKey.d.ts +0 -2
  201. package/src/graphics/cacheKey.ts +0 -3
@@ -5,9 +5,9 @@ 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 unknown as MultiVariableTextSchema;
9
9
  const text = mvtSchema.text || '';
10
- const variables = JSON.parse(mvtSchema.content) || {};
10
+ const variables = JSON.parse(mvtSchema.content || '{}') as Record<string, string>;
11
11
  const variablesChanged = updateVariablesFromText(text, variables);
12
12
  const varNames = Object.keys(variables);
13
13
 
@@ -37,10 +37,12 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
37
37
  textarea.id = 'dynamic-var-' + variableName;
38
38
  textarea.value = variables[variableName];
39
39
  textarea.addEventListener('change', (e: Event) => {
40
- variables[variableName] = (e.target as HTMLTextAreaElement).value;
41
- changeSchemas([
42
- { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
43
- ]);
40
+ if (variableName in variables) {
41
+ variables[variableName] = (e.target as HTMLTextAreaElement).value;
42
+ changeSchemas([
43
+ { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
44
+ ]);
45
+ }
44
46
  });
45
47
 
46
48
  const label = varRow.querySelector('label') as HTMLLabelElement;
@@ -51,10 +53,20 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
51
53
  }
52
54
  } else {
53
55
  const para = document.createElement('p');
56
+ // Extract color value to avoid unsafe property access
57
+ const colorValue = options?.theme?.token?.colorPrimary || '#168fe3';
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);
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');
54
66
  para.innerHTML =
55
- i18n('schemas.mvt.typingInstructions') +
56
- ` <code style="color:${options?.theme?.token?.colorPrimary || '#168fe3'}; font-weight:bold;">{` +
57
- i18n('schemas.mvt.sampleField') +
67
+ typingInstructions +
68
+ ` <code style="color:${safeColorValue}; font-weight:bold;">{` +
69
+ sampleField +
58
70
  '}</code>';
59
71
  rootElement.appendChild(para);
60
72
  }
@@ -63,13 +75,16 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
63
75
  export const propPanel: PropPanel<MultiVariableTextSchema> = {
64
76
  schema: (propPanelProps: Omit<PropPanelWidgetProps, 'rootElement'>) => {
65
77
  if (typeof parentPropPanel.schema !== 'function') {
66
- throw Error('Oops, is text schema no longer a function?');
78
+ throw new Error('Oops, is text schema no longer a function?');
67
79
  }
80
+ // Safely call schema function with proper type handling
81
+ const parentSchema =
82
+ typeof parentPropPanel.schema === 'function' ? parentPropPanel.schema(propPanelProps) : {};
68
83
  return {
69
- ...parentPropPanel.schema(propPanelProps),
84
+ ...parentSchema,
70
85
  '-------': { type: 'void', widget: 'Divider' },
71
86
  dynamicVarContainer: {
72
- title: propPanelProps.i18n('schemas.mvt.variablesSampleData'),
87
+ title: 'Variables Sample Data',
73
88
  type: 'string',
74
89
  widget: 'Card',
75
90
  span: 24,
@@ -97,7 +112,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
97
112
  },
98
113
  };
99
114
  },
100
- widgets: { ...parentPropPanel.widgets, mapDynamicVariables },
115
+ widgets: { ...(parentPropPanel.widgets || {}), mapDynamicVariables },
101
116
  defaultSchema: {
102
117
  ...parentPropPanel.defaultSchema,
103
118
  readOnly: false,
@@ -110,7 +125,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
110
125
  },
111
126
  };
112
127
 
113
- const updateVariablesFromText = (text: string, variables: any): boolean => {
128
+ const updateVariablesFromText = (text: string, variables: Record<string, string>): boolean => {
114
129
  const regex = /\{([^{}]+)}/g;
115
130
  const matches = text.match(regex);
116
131
  let changed = false;
@@ -23,16 +23,17 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
23
23
  await parentUiRender({
24
24
  value: isEditable(mode, schema) ? text : substituteVariables(text, value),
25
25
  schema,
26
- mode: mode == 'form' ? 'viewer' : mode, // if no variables for form it's just a viewer
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: unknown } | { key: string; value: unknown }[]) => {
29
29
  if (!Array.isArray(arg)) {
30
- const numVariables = countUniqueVariableNames(arg.value);
31
- onChange &&
30
+ const numVariables = countUniqueVariableNames(arg.value as string);
31
+ if (onChange) {
32
32
  onChange([
33
33
  { key: 'text', value: arg.value },
34
- { key: 'readOnly', value: numVariables == 0 },
34
+ { key: 'readOnly', value: numVariables === 0 },
35
35
  ]);
36
+ }
36
37
  } else {
37
38
  throw new Error('onChange is not an array, the parent text plugin has changed...');
38
39
  }
@@ -40,7 +41,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
40
41
  ...rest,
41
42
  });
42
43
 
43
- const textBlock = rootElement.querySelector('#text-' + schema.id) as HTMLDivElement;
44
+ const textBlock = rootElement.querySelector('#text-' + String(schema.id)) as HTMLDivElement;
44
45
  if (!textBlock) {
45
46
  throw new Error('Text block not found. Ensure the text block has an id of "text-" + schema.id');
46
47
  }
@@ -55,7 +56,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
55
56
  if (onChange) {
56
57
  onChange([
57
58
  { key: 'text', value: text },
58
- { key: 'readOnly', value: newNumVariables == 0 },
59
+ { key: 'readOnly', value: newNumVariables === 0 },
59
60
  ]);
60
61
  }
61
62
  numVariables = newNumVariables;
@@ -74,11 +75,17 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
74
75
  rootElement.parentElement.style.outline = '';
75
76
  }
76
77
 
77
- const variables: Record<string, string> = value ? JSON.parse(value) || {} : {};
78
+ const variables: Record<string, string> = value
79
+ ? (JSON.parse(value) as Record<string, string>) || {}
80
+ : {};
78
81
  const variableIndices = getVariableIndices(rawText);
79
82
  const substitutedText = substituteVariables(rawText, variables);
80
83
  const font = options?.font || getDefaultFont();
81
- const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
84
+ const fontKitFont = await getFontKitFont(
85
+ schema.fontName,
86
+ font,
87
+ _cache as Map<string, import('fontkit').Font>,
88
+ );
82
89
 
83
90
  const textBlock = buildStyledTextContainer(arg, fontKitFont, substitutedText);
84
91
 
@@ -96,8 +103,8 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
96
103
  const newValue = (e.target as HTMLSpanElement).textContent || '';
97
104
  if (newValue !== variables[variableIndices[i]]) {
98
105
  variables[variableIndices[i]] = newValue;
99
- onChange && onChange({ key: 'content', value: JSON.stringify(variables) });
100
- stopEditing && stopEditing();
106
+ if (onChange) onChange({ key: 'content', value: JSON.stringify(variables) });
107
+ if (stopEditing) stopEditing();
101
108
  }
102
109
  });
103
110
  textBlock.appendChild(span);
@@ -145,10 +152,10 @@ const countUniqueVariableNames = (content: string) => {
145
152
  */
146
153
  const keyPressShouldBeChecked = (event: KeyboardEvent) => {
147
154
  if (
148
- event.key == 'ArrowUp' ||
149
- event.key == 'ArrowDown' ||
150
- event.key == 'ArrowLeft' ||
151
- event.key == 'ArrowRight'
155
+ event.key === 'ArrowUp' ||
156
+ event.key === 'ArrowDown' ||
157
+ event.key === 'ArrowLeft' ||
158
+ event.key === 'ArrowRight'
152
159
  ) {
153
160
  return false;
154
161
  }
@@ -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
 
@@ -150,11 +150,13 @@ const schema: Plugin<Select> = {
150
150
 
151
151
  selectElement.addEventListener('change', (e) => {
152
152
  if (onChange && e.target instanceof HTMLSelectElement) {
153
- onChange && onChange({ key: 'content', value: e.target.value });
153
+ if (onChange) onChange({ key: 'content', value: e.target.value });
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<any, any>;
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<any, any> }) {
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<any, any>;
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
  };
@@ -10,7 +10,7 @@ import { HEX_COLOR_PATTERN } from '../constants.js';
10
10
 
11
11
  export const propPanel: PropPanel<TableSchema> = {
12
12
  schema: ({ activeSchema, options, i18n }) => {
13
- // @ts-expect-error
13
+ // @ts-expect-error Type casting is necessary here as the activeSchema type is generic
14
14
  const tableSchema = activeSchema as TableSchema;
15
15
  const head = tableSchema.head || [];
16
16
  const showHead = tableSchema.showHead || false;
@@ -7,6 +7,7 @@ import {
7
7
  getFallbackFontName,
8
8
  cloneDeep,
9
9
  } from '@pdfme/common';
10
+ import type { Font as FontKitFont } from 'fontkit';
10
11
  import type {
11
12
  TableSchema,
12
13
  CellStyle,
@@ -24,7 +25,7 @@ interface CreateTableArgs {
24
25
  schema: Schema;
25
26
  basePdf: BasePdf;
26
27
  options: CommonOptions;
27
- _cache: Map<any, any>;
28
+ _cache: Map<string | number, unknown>;
28
29
  }
29
30
 
30
31
  interface UserOptions {
@@ -278,5 +279,10 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
278
279
 
279
280
  const content = parseContent4Table(input, fallbackFontName);
280
281
 
281
- return Table.create({ input, content, font, _cache });
282
+ return Table.create({
283
+ input,
284
+ content,
285
+ font,
286
+ _cache: _cache as unknown as Map<string | number, FontKitFont>,
287
+ });
282
288
  }
@@ -250,7 +250,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
250
250
  text: '+',
251
251
  onClick: () => {
252
252
  const newRow = Array(schema.head.length).fill('') as string[];
253
- onChange && onChange({ key: 'content', value: JSON.stringify(body.concat([newRow])) });
253
+ if (onChange) onChange({ key: 'content', value: JSON.stringify(body.concat([newRow])) });
254
254
  },
255
255
  });
256
256
 
@@ -266,7 +266,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
266
266
  text: '-',
267
267
  onClick: () => {
268
268
  const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
269
- onChange && onChange({ key: 'content', value: JSON.stringify(newTableBody) });
269
+ if (onChange) onChange({ key: 'content', value: JSON.stringify(newTableBody) });
270
270
  },
271
271
  });
272
272
  return removeRowButton;
@@ -1,4 +1,4 @@
1
- import { Dict } from '@pdfme/common';
1
+ // No imports needed from @pdfme/common
2
2
  import {
3
3
  TextAlignCenterIcon,
4
4
  TextAlignLeftIcon,
@@ -40,9 +40,9 @@ interface GroupButtonString {
40
40
  value: string;
41
41
  }
42
42
 
43
- export type GroupButton = GroupButtonBoolean | GroupButtonString;
43
+ type GroupButton = GroupButtonBoolean | GroupButtonString;
44
44
 
45
- export function getExtraFormatterSchema(i18n: (key: keyof Dict | string) => string): {
45
+ export function getExtraFormatterSchema(i18n: (key: string) => string): {
46
46
  title: string;
47
47
  widget: string;
48
48
  buttons: GroupButton[];
@@ -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<string | number, fontkit.Font>,
116
116
  ) => {
117
117
  const fntNm = fontName || getFallbackFontName(font);
118
118
  const cacheKey = getCacheKey(fntNm);
@@ -128,9 +128,14 @@ export const getFontKitFont = async (
128
128
  : b64toUint8Array(fontData);
129
129
  }
130
130
 
131
- const fontKitFont = fontkit.create(
132
- fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer),
133
- ) as fontkit.Font;
131
+ // Convert fontData to Buffer if it's not already a Buffer
132
+ let fontDataBuffer: Buffer;
133
+ if (fontData instanceof Buffer) {
134
+ fontDataBuffer = fontData;
135
+ } else {
136
+ fontDataBuffer = Buffer.from(fontData as ArrayBufferLike);
137
+ }
138
+ const fontKitFont = fontkit.create(fontDataBuffer) as fontkit.Font;
134
139
  _cache.set(cacheKey, fontKitFont);
135
140
 
136
141
  return fontKitFont;
@@ -489,7 +494,11 @@ export const filterStartJP = (lines: string[]): string[] => {
489
494
  });
490
495
 
491
496
  if (charToAppend) {
492
- return [charToAppend + filtered.slice(0, 1)[0], ...filtered.slice(1)].reverse();
497
+ // Handle the case where filtered might be empty
498
+ const firstItem = filtered.length > 0 ? filtered[0] : '';
499
+ // Ensure we're concatenating strings
500
+ const combinedItem = String(charToAppend) + String(firstItem);
501
+ return [combinedItem, ...filtered.slice(1)].reverse();
493
502
  } else {
494
503
  return filtered.reverse();
495
504
  }
@@ -530,7 +539,11 @@ export const filterEndJP = (lines: string[]): string[] => {
530
539
  });
531
540
 
532
541
  if (charToPrepend) {
533
- return [...filtered.slice(0, -1), filtered.slice(-1)[0] + charToPrepend];
542
+ // Handle the case where filtered might be empty
543
+ const lastItem = filtered.length > 0 ? filtered[filtered.length - 1] : '';
544
+ // Ensure we're concatenating strings
545
+ const combinedItem = String(lastItem) + String(charToPrepend);
546
+ return [...filtered.slice(0, -1), combinedItem];
534
547
  } else {
535
548
  return filtered;
536
549
  }
@@ -33,7 +33,7 @@ import { convertForPdfLayoutProps, rotatePoint, hex2PrintingColor } from '../uti
33
33
  const embedAndGetFontObj = async (arg: {
34
34
  pdfDoc: PDFDocument;
35
35
  font: Font;
36
- _cache: Map<any, any>;
36
+ _cache: Map<PDFDocument, { [key: string]: PDFFont }>;
37
37
  }) => {
38
38
  const { pdfDoc, font, _cache } = arg;
39
39
  if (_cache.has(pdfDoc)) {
@@ -94,8 +94,12 @@ 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 }),
98
- getFontKitFont(schema.fontName, font, _cache),
97
+ embedAndGetFontObj({
98
+ pdfDoc,
99
+ font,
100
+ _cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }>,
101
+ }),
102
+ getFontKitFont(schema.fontName, font, _cache as Map<string, FontKitFont>),
99
103
  ]);
100
104
  const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
101
105
 
@@ -27,9 +27,9 @@ const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
27
27
 
28
28
  const checkbox = document.createElement('input');
29
29
  checkbox.type = 'checkbox';
30
- checkbox.checked = Boolean((activeSchema as any)?.dynamicFontSize);
31
- checkbox.onchange = (e: any) => {
32
- const val = e.target.checked
30
+ checkbox.checked = Boolean((activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize);
31
+ checkbox.onchange = (e: Event) => {
32
+ const val = (e.target as HTMLInputElement).checked
33
33
  ? {
34
34
  min: DEFAULT_DYNAMIC_MIN_FONT_SIZE,
35
35
  max: DEFAULT_DYNAMIC_MAX_FONT_SIZE,
@@ -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 any)?.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);
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,
@@ -96,8 +100,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
96
100
  textBlock.tabIndex = tabIndex || 0;
97
101
  textBlock.innerText = mode === 'designer' ? value : processedText;
98
102
  textBlock.addEventListener('blur', (e: Event) => {
99
- onChange && onChange({ key: 'content', value: getText(e.target as HTMLDivElement) });
100
- stopEditing && stopEditing();
103
+ if (onChange) onChange({ key: 'content', value: getText(e.target as HTMLDivElement) });
104
+ if (stopEditing) stopEditing();
101
105
  });
102
106
 
103
107
  if (schema.dynamicFontSize) {
@@ -105,7 +109,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
105
109
 
106
110
  textBlock.addEventListener('keyup', () => {
107
111
  setTimeout(() => {
108
- void (async () => {
112
+ // Use a regular function instead of an async one since we don't need await
113
+ (() => {
109
114
  if (!textBlock.textContent) return;
110
115
  dynamicFontSize = calculateDynamicFontSize({
111
116
  textSchema: schema,
@@ -159,8 +164,7 @@ export const buildStyledTextContainer = (
159
164
  fontKitFont: FontKitFont,
160
165
  value: string,
161
166
  ) => {
162
- const { schema, rootElement, mode, options, _cache } = arg;
163
- const font = options?.font || getDefaultFont();
167
+ const { schema, rootElement, mode } = arg;
164
168
 
165
169
  let dynamicFontSize: undefined | number = undefined;
166
170
 
@@ -278,7 +282,7 @@ export const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefine
278
282
  return 'flex-start';
279
283
  };
280
284
 
281
- export const getBackgroundColor = (value: string, schema: { backgroundColor?: string }) => {
285
+ const getBackgroundColor = (value: string, schema: { backgroundColor?: string }) => {
282
286
  if (!value || !schema.backgroundColor) return 'transparent';
283
287
  return schema.backgroundColor;
284
288
  };
package/src/utils.ts CHANGED
@@ -162,7 +162,7 @@ export const readFile = (input: File | FileList | null): Promise<string | ArrayB
162
162
  }
163
163
  };
164
164
 
165
- fileReader.onerror = (e) => {
165
+ fileReader.onerror = () => {
166
166
  reject(new Error('[@pdfme/schemas] File reading failed'));
167
167
  };
168
168
 
@@ -238,12 +238,16 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
238
238
  .join(' ');
239
239
 
240
240
  // Helper function to process a single element
241
- const processElement = (element: any): string => {
241
+ const processElement = (element: unknown): string => {
242
242
  if (!Array.isArray(element)) {
243
243
  return String(element);
244
244
  }
245
245
 
246
- const [tag, attributes = {}, children = []] = element;
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
@@ -260,10 +264,10 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
260
264
 
261
265
  // Return properly formatted element string
262
266
  if (childrenString) {
263
- return `<${tagName}${attrString ? ' ' + attrString : ''}>${childrenString}</${tagName}>`;
267
+ return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}>${childrenString}</${String(tagName)}>`;
264
268
  } else {
265
269
  // Self-closing tag for empty children
266
- return `<${tagName}${attrString ? ' ' + attrString : ''}/>`;
270
+ return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}/>`;
267
271
  }
268
272
  };
269
273
 
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCacheKey = void 0;
4
- const getCacheKey = (schema, input) => `${schema.type}${input}`;
5
- exports.getCacheKey = getCacheKey;
6
- //# sourceMappingURL=cacheKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAA1E,QAAA,WAAW,eAA+D"}