@pdfme/schemas 5.3.11-dev.1 → 5.3.11-dev.11

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 (179) hide show
  1. package/dist/cjs/src/barcodes/helper.js +6 -3
  2. package/dist/cjs/src/barcodes/helper.js.map +1 -1
  3. package/dist/cjs/src/barcodes/pdfRender.js +5 -1
  4. package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
  5. package/dist/cjs/src/barcodes/uiRender.js +5 -3
  6. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  7. package/dist/cjs/src/checkbox/index.js +2 -1
  8. package/dist/cjs/src/checkbox/index.js.map +1 -1
  9. package/dist/cjs/src/date/helper.js +1 -1
  10. package/dist/cjs/src/date/helper.js.map +1 -1
  11. package/dist/cjs/src/graphics/image.js +6 -3
  12. package/dist/cjs/src/graphics/image.js.map +1 -1
  13. package/dist/cjs/src/graphics/svg.js +3 -2
  14. package/dist/cjs/src/graphics/svg.js.map +1 -1
  15. package/dist/cjs/src/multiVariableText/helper.js +3 -3
  16. package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
  17. package/dist/cjs/src/multiVariableText/propPanel.js +25 -12
  18. package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
  19. package/dist/cjs/src/multiVariableText/uiRender.js +14 -11
  20. package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
  21. package/dist/cjs/src/radioGroup/index.js.map +1 -1
  22. package/dist/cjs/src/select/index.js +20 -8
  23. package/dist/cjs/src/select/index.js.map +1 -1
  24. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  25. package/dist/cjs/src/tables/classes.js.map +1 -1
  26. package/dist/cjs/src/tables/pdfRender.js +16 -2
  27. package/dist/cjs/src/tables/pdfRender.js.map +1 -1
  28. package/dist/cjs/src/tables/propPanel.js +1 -1
  29. package/dist/cjs/src/tables/propPanel.js.map +1 -1
  30. package/dist/cjs/src/tables/tableHelper.js +1 -1
  31. package/dist/cjs/src/tables/tableHelper.js.map +1 -1
  32. package/dist/cjs/src/tables/uiRender.js +4 -2
  33. package/dist/cjs/src/tables/uiRender.js.map +1 -1
  34. package/dist/cjs/src/text/extraFormatter.js +1 -0
  35. package/dist/cjs/src/text/extraFormatter.js.map +1 -1
  36. package/dist/cjs/src/text/helper.js +19 -3
  37. package/dist/cjs/src/text/helper.js.map +1 -1
  38. package/dist/cjs/src/text/pdfRender.js +1 -1
  39. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  40. package/dist/cjs/src/text/propPanel.js.map +1 -1
  41. package/dist/cjs/src/text/uiRender.js +9 -8
  42. package/dist/cjs/src/text/uiRender.js.map +1 -1
  43. package/dist/cjs/src/utils.js +3 -3
  44. package/dist/cjs/src/utils.js.map +1 -1
  45. package/dist/esm/src/barcodes/helper.js +6 -3
  46. package/dist/esm/src/barcodes/helper.js.map +1 -1
  47. package/dist/esm/src/barcodes/pdfRender.js +5 -1
  48. package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
  49. package/dist/esm/src/barcodes/uiRender.js +5 -3
  50. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  51. package/dist/esm/src/checkbox/index.js +2 -1
  52. package/dist/esm/src/checkbox/index.js.map +1 -1
  53. package/dist/esm/src/date/helper.js +2 -2
  54. package/dist/esm/src/date/helper.js.map +1 -1
  55. package/dist/esm/src/graphics/image.js +6 -3
  56. package/dist/esm/src/graphics/image.js.map +1 -1
  57. package/dist/esm/src/graphics/svg.js +3 -2
  58. package/dist/esm/src/graphics/svg.js.map +1 -1
  59. package/dist/esm/src/multiVariableText/helper.js +3 -3
  60. package/dist/esm/src/multiVariableText/helper.js.map +1 -1
  61. package/dist/esm/src/multiVariableText/propPanel.js +25 -12
  62. package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
  63. package/dist/esm/src/multiVariableText/uiRender.js +14 -11
  64. package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
  65. package/dist/esm/src/radioGroup/index.js.map +1 -1
  66. package/dist/esm/src/select/index.js +20 -8
  67. package/dist/esm/src/select/index.js.map +1 -1
  68. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  69. package/dist/esm/src/tables/classes.js.map +1 -1
  70. package/dist/esm/src/tables/pdfRender.js +16 -2
  71. package/dist/esm/src/tables/pdfRender.js.map +1 -1
  72. package/dist/esm/src/tables/propPanel.js +1 -1
  73. package/dist/esm/src/tables/propPanel.js.map +1 -1
  74. package/dist/esm/src/tables/tableHelper.js +1 -1
  75. package/dist/esm/src/tables/tableHelper.js.map +1 -1
  76. package/dist/esm/src/tables/uiRender.js +4 -2
  77. package/dist/esm/src/tables/uiRender.js.map +1 -1
  78. package/dist/esm/src/text/extraFormatter.js +1 -0
  79. package/dist/esm/src/text/extraFormatter.js.map +1 -1
  80. package/dist/esm/src/text/helper.js +19 -3
  81. package/dist/esm/src/text/helper.js.map +1 -1
  82. package/dist/esm/src/text/pdfRender.js +1 -1
  83. package/dist/esm/src/text/pdfRender.js.map +1 -1
  84. package/dist/esm/src/text/propPanel.js.map +1 -1
  85. package/dist/esm/src/text/uiRender.js +8 -6
  86. package/dist/esm/src/text/uiRender.js.map +1 -1
  87. package/dist/esm/src/utils.js +3 -3
  88. package/dist/esm/src/utils.js.map +1 -1
  89. package/dist/node/src/barcodes/helper.js +6 -3
  90. package/dist/node/src/barcodes/helper.js.map +1 -1
  91. package/dist/node/src/barcodes/pdfRender.js +5 -1
  92. package/dist/node/src/barcodes/pdfRender.js.map +1 -1
  93. package/dist/node/src/barcodes/uiRender.js +5 -3
  94. package/dist/node/src/barcodes/uiRender.js.map +1 -1
  95. package/dist/node/src/checkbox/index.js +2 -1
  96. package/dist/node/src/checkbox/index.js.map +1 -1
  97. package/dist/node/src/date/helper.js +1 -1
  98. package/dist/node/src/date/helper.js.map +1 -1
  99. package/dist/node/src/graphics/image.js +6 -3
  100. package/dist/node/src/graphics/image.js.map +1 -1
  101. package/dist/node/src/graphics/svg.js +3 -2
  102. package/dist/node/src/graphics/svg.js.map +1 -1
  103. package/dist/node/src/multiVariableText/helper.js +3 -3
  104. package/dist/node/src/multiVariableText/helper.js.map +1 -1
  105. package/dist/node/src/multiVariableText/propPanel.js +25 -12
  106. package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
  107. package/dist/node/src/multiVariableText/uiRender.js +14 -11
  108. package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
  109. package/dist/node/src/radioGroup/index.js.map +1 -1
  110. package/dist/node/src/select/index.js +20 -8
  111. package/dist/node/src/select/index.js.map +1 -1
  112. package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
  113. package/dist/node/src/tables/classes.js.map +1 -1
  114. package/dist/node/src/tables/pdfRender.js +16 -2
  115. package/dist/node/src/tables/pdfRender.js.map +1 -1
  116. package/dist/node/src/tables/propPanel.js +1 -1
  117. package/dist/node/src/tables/propPanel.js.map +1 -1
  118. package/dist/node/src/tables/tableHelper.js +1 -1
  119. package/dist/node/src/tables/tableHelper.js.map +1 -1
  120. package/dist/node/src/tables/uiRender.js +4 -2
  121. package/dist/node/src/tables/uiRender.js.map +1 -1
  122. package/dist/node/src/text/extraFormatter.js +1 -0
  123. package/dist/node/src/text/extraFormatter.js.map +1 -1
  124. package/dist/node/src/text/helper.js +19 -3
  125. package/dist/node/src/text/helper.js.map +1 -1
  126. package/dist/node/src/text/pdfRender.js +1 -1
  127. package/dist/node/src/text/pdfRender.js.map +1 -1
  128. package/dist/node/src/text/propPanel.js.map +1 -1
  129. package/dist/node/src/text/uiRender.js +9 -8
  130. package/dist/node/src/text/uiRender.js.map +1 -1
  131. package/dist/node/src/utils.js +3 -3
  132. package/dist/node/src/utils.js.map +1 -1
  133. package/dist/types/src/barcodes/helper.d.ts +22 -0
  134. package/dist/types/src/checkbox/index.d.ts +1 -2
  135. package/dist/types/src/graphics/image.d.ts +1 -2
  136. package/dist/types/src/graphics/svg.d.ts +1 -2
  137. package/dist/types/src/radioGroup/index.d.ts +1 -2
  138. package/dist/types/src/shapes/rectAndEllipse.d.ts +91 -7
  139. package/dist/types/src/tables/classes.d.ts +2 -1
  140. package/dist/types/src/tables/dynamicTemplate.d.ts +1 -1
  141. package/dist/types/src/tables/tableHelper.d.ts +1 -1
  142. package/dist/types/src/text/extraFormatter.d.ts +2 -3
  143. package/dist/types/src/text/helper.d.ts +1 -1
  144. package/dist/types/src/text/uiRender.d.ts +0 -3
  145. package/dist/types/src/utils.d.ts +1 -1
  146. package/package.json +2 -2
  147. package/src/barcodes/helper.ts +35 -5
  148. package/src/barcodes/pdfRender.ts +7 -4
  149. package/src/barcodes/uiRender.ts +3 -3
  150. package/src/checkbox/index.ts +4 -5
  151. package/src/date/helper.ts +15 -8
  152. package/src/graphics/image.ts +4 -4
  153. package/src/graphics/svg.ts +7 -6
  154. package/src/multiVariableText/helper.ts +4 -4
  155. package/src/multiVariableText/propPanel.ts +28 -14
  156. package/src/multiVariableText/uiRender.ts +16 -15
  157. package/src/radioGroup/index.ts +3 -4
  158. package/src/select/index.ts +23 -10
  159. package/src/shapes/rectAndEllipse.ts +3 -3
  160. package/src/tables/classes.ts +2 -2
  161. package/src/tables/dynamicTemplate.ts +1 -1
  162. package/src/tables/pdfRender.ts +28 -3
  163. package/src/tables/propPanel.ts +1 -1
  164. package/src/tables/tableHelper.ts +3 -2
  165. package/src/tables/uiRender.ts +2 -2
  166. package/src/text/extraFormatter.ts +3 -3
  167. package/src/text/helper.ts +19 -6
  168. package/src/text/pdfRender.ts +3 -3
  169. package/src/text/propPanel.ts +4 -4
  170. package/src/text/uiRender.ts +7 -7
  171. package/src/utils.ts +5 -5
  172. package/dist/cjs/src/graphics/cacheKey.js +0 -6
  173. package/dist/cjs/src/graphics/cacheKey.js.map +0 -1
  174. package/dist/esm/src/graphics/cacheKey.js +0 -2
  175. package/dist/esm/src/graphics/cacheKey.js.map +0 -1
  176. package/dist/node/src/graphics/cacheKey.js +0 -6
  177. package/dist/node/src/graphics/cacheKey.js.map +0 -1
  178. package/dist/types/src/graphics/cacheKey.d.ts +0 -2
  179. 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,18 @@ 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 = /^#[0-9A-F]{6}$/i.test(colorValue) || /^(rgb|hsl)a?\(\s*([+-]?\d+%?\s*,\s*){2,3}[+-]?\d+%?\s*\)$/i.test(colorValue);
59
+ const safeColorValue = isValidColor ? colorValue : '#168fe3';
60
+
61
+ // Use safe string concatenation for innerHTML
62
+ const typingInstructions = i18n('schemas.mvt.typingInstructions');
63
+ const sampleField = i18n('schemas.mvt.sampleField');
54
64
  para.innerHTML =
55
- i18n('schemas.mvt.typingInstructions') +
56
- ` <code style="color:${options?.theme?.token?.colorPrimary || '#168fe3'}; font-weight:bold;">{` +
57
- i18n('schemas.mvt.sampleField') +
65
+ typingInstructions +
66
+ ` <code style="color:${safeColorValue}; font-weight:bold;">{` +
67
+ sampleField +
58
68
  '}</code>';
59
69
  rootElement.appendChild(para);
60
70
  }
@@ -63,13 +73,17 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
63
73
  export const propPanel: PropPanel<MultiVariableTextSchema> = {
64
74
  schema: (propPanelProps: Omit<PropPanelWidgetProps, 'rootElement'>) => {
65
75
  if (typeof parentPropPanel.schema !== 'function') {
66
- throw Error('Oops, is text schema no longer a function?');
76
+ throw new Error('Oops, is text schema no longer a function?');
67
77
  }
78
+ // Safely call schema function with proper type handling
79
+ const parentSchema = typeof parentPropPanel.schema === 'function'
80
+ ? parentPropPanel.schema(propPanelProps)
81
+ : {};
68
82
  return {
69
- ...parentPropPanel.schema(propPanelProps),
83
+ ...parentSchema,
70
84
  '-------': { type: 'void', widget: 'Divider' },
71
85
  dynamicVarContainer: {
72
- title: propPanelProps.i18n('schemas.mvt.variablesSampleData'),
86
+ title: 'Variables Sample Data',
73
87
  type: 'string',
74
88
  widget: 'Card',
75
89
  span: 24,
@@ -97,7 +111,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
97
111
  },
98
112
  };
99
113
  },
100
- widgets: { ...parentPropPanel.widgets, mapDynamicVariables },
114
+ widgets: { ...(parentPropPanel.widgets || {}), mapDynamicVariables },
101
115
  defaultSchema: {
102
116
  ...parentPropPanel.defaultSchema,
103
117
  readOnly: false,
@@ -110,7 +124,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
110
124
  },
111
125
  };
112
126
 
113
- const updateVariablesFromText = (text: string, variables: any): boolean => {
127
+ const updateVariablesFromText = (text: string, variables: Record<string, string>): boolean => {
114
128
  const regex = /\{([^{}]+)}/g;
115
129
  const matches = text.match(regex);
116
130
  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,11 @@ 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 ? JSON.parse(value) as Record<string, string> || {} : {};
78
79
  const variableIndices = getVariableIndices(rawText);
79
80
  const substitutedText = substituteVariables(rawText, variables);
80
81
  const font = options?.font || getDefaultFont();
81
- const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
82
+ const fontKitFont = await getFontKitFont(schema.fontName, font, _cache as Map<string, import('fontkit').Font>);
82
83
 
83
84
  const textBlock = buildStyledTextContainer(arg, fontKitFont, substitutedText);
84
85
 
@@ -96,8 +97,8 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
96
97
  const newValue = (e.target as HTMLSpanElement).textContent || '';
97
98
  if (newValue !== variables[variableIndices[i]]) {
98
99
  variables[variableIndices[i]] = newValue;
99
- onChange && onChange({ key: 'content', value: JSON.stringify(variables) });
100
- stopEditing && stopEditing();
100
+ if (onChange) onChange({ key: 'content', value: JSON.stringify(variables) });
101
+ if (stopEditing) stopEditing();
101
102
  }
102
103
  });
103
104
  textBlock.appendChild(span);
@@ -145,10 +146,10 @@ const countUniqueVariableNames = (content: string) => {
145
146
  */
146
147
  const keyPressShouldBeChecked = (event: KeyboardEvent) => {
147
148
  if (
148
- event.key == 'ArrowUp' ||
149
- event.key == 'ArrowDown' ||
150
- event.key == 'ArrowLeft' ||
151
- event.key == 'ArrowRight'
149
+ event.key === 'ArrowUp' ||
150
+ event.key === 'ArrowDown' ||
151
+ event.key === 'ArrowLeft' ||
152
+ event.key === 'ArrowRight'
152
153
  ) {
153
154
  return false;
154
155
  }
@@ -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: {
@@ -185,11 +191,18 @@ const schema: Plugin<Select> = {
185
191
  },
186
192
  };
187
193
  },
188
- defaultSchema: {
189
- ...text.propPanel.defaultSchema,
190
- type: 'select',
191
- content: 'option1',
192
- options: ['option1', 'option2'],
194
+ // Create a type-safe defaultSchema by first creating a safe copy of the text.propPanel.defaultSchema
195
+ get defaultSchema() {
196
+ // Create a safe copy of the text.propPanel.defaultSchema
197
+ const baseSchema = text.propPanel.defaultSchema;
198
+
199
+ // Add our properties
200
+ return {
201
+ ...baseSchema,
202
+ type: 'select',
203
+ content: 'option1',
204
+ options: ['option1', 'option2'],
205
+ };
193
206
  },
194
207
  },
195
208
  icon: selectIcon,
@@ -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;
@@ -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,7 @@ 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: { table: Table; font: Font; _cache: Map<string | number, FontKitFont> }) {
149
149
  const { table, font, _cache } = arg;
150
150
 
151
151
  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: _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,5 @@ 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({ input, content, font, _cache: _cache as unknown as Map<string | number, FontKitFont> });
282
283
  }
@@ -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,8 @@ 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({ pdfDoc, font, _cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }> }),
98
+ getFontKitFont(schema.fontName, font, _cache as Map<string, FontKitFont>),
99
99
  ]);
100
100
  const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
101
101
 
@@ -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,7 @@ 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((activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize);
58
58
 
59
59
  const textSchema: Record<string, PropPanelSchema> = {
60
60
  fontName: {
@@ -69,7 +69,7 @@ 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(schema.fontName, font, _cache as Map<string, import('fontkit').Font>);
73
73
  const textBlock = buildStyledTextContainer(
74
74
  arg,
75
75
  fontKitFont,
@@ -96,8 +96,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
96
96
  textBlock.tabIndex = tabIndex || 0;
97
97
  textBlock.innerText = mode === 'designer' ? value : processedText;
98
98
  textBlock.addEventListener('blur', (e: Event) => {
99
- onChange && onChange({ key: 'content', value: getText(e.target as HTMLDivElement) });
100
- stopEditing && stopEditing();
99
+ if (onChange) onChange({ key: 'content', value: getText(e.target as HTMLDivElement) });
100
+ if (stopEditing) stopEditing();
101
101
  });
102
102
 
103
103
  if (schema.dynamicFontSize) {
@@ -105,7 +105,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
105
105
 
106
106
  textBlock.addEventListener('keyup', () => {
107
107
  setTimeout(() => {
108
- void (async () => {
108
+ // Use a regular function instead of an async one since we don't need await
109
+ (() => {
109
110
  if (!textBlock.textContent) return;
110
111
  dynamicFontSize = calculateDynamicFontSize({
111
112
  textSchema: schema,
@@ -159,8 +160,7 @@ export const buildStyledTextContainer = (
159
160
  fontKitFont: FontKitFont,
160
161
  value: string,
161
162
  ) => {
162
- const { schema, rootElement, mode, options, _cache } = arg;
163
- const font = options?.font || getDefaultFont();
163
+ const { schema, rootElement, mode } = arg;
164
164
 
165
165
  let dynamicFontSize: undefined | number = undefined;
166
166
 
@@ -278,7 +278,7 @@ export const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefine
278
278
  return 'flex-start';
279
279
  };
280
280
 
281
- export const getBackgroundColor = (value: string, schema: { backgroundColor?: string }) => {
281
+ const getBackgroundColor = (value: string, schema: { backgroundColor?: string }) => {
282
282
  if (!value || !schema.backgroundColor) return 'transparent';
283
283
  return schema.backgroundColor;
284
284
  };
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,12 @@ 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 [unknown, Record<string, string>, unknown[]];
247
247
  const tagName = String(tag);
248
248
 
249
249
  // Format attributes string
@@ -260,10 +260,10 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
260
260
 
261
261
  // Return properly formatted element string
262
262
  if (childrenString) {
263
- return `<${tagName}${attrString ? ' ' + attrString : ''}>${childrenString}</${tagName}>`;
263
+ return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}>${childrenString}</${String(tagName)}>`;
264
264
  } else {
265
265
  // Self-closing tag for empty children
266
- return `<${tagName}${attrString ? ' ' + attrString : ''}/>`;
266
+ return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}/>`;
267
267
  }
268
268
  };
269
269
 
@@ -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"}
@@ -1,2 +0,0 @@
1
- export const getCacheKey = (schema, input) => `${schema.type}${input}`;
2
- //# sourceMappingURL=cacheKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC"}
@@ -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