@pdfme/schemas 5.3.8-dev.9 → 5.3.9

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 (280) hide show
  1. package/dist/cjs/__tests__/barcode.test.js +119 -120
  2. package/dist/cjs/__tests__/barcode.test.js.map +1 -1
  3. package/dist/cjs/__tests__/multiVariableText.test.js +15 -15
  4. package/dist/cjs/__tests__/multiVariableText.test.js.map +1 -1
  5. package/dist/cjs/__tests__/text.test.js +88 -78
  6. package/dist/cjs/__tests__/text.test.js.map +1 -1
  7. package/dist/cjs/__tests__/utils.test.js +76 -15
  8. package/dist/cjs/__tests__/utils.test.js.map +1 -1
  9. package/dist/cjs/src/barcodes/helper.js +2 -1
  10. package/dist/cjs/src/barcodes/helper.js.map +1 -1
  11. package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
  12. package/dist/cjs/src/barcodes/propPanel.js +3 -3
  13. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  14. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  15. package/dist/cjs/src/checkbox/index.js +4 -4
  16. package/dist/cjs/src/checkbox/index.js.map +1 -1
  17. package/dist/cjs/src/date/date.js +2 -2
  18. package/dist/cjs/src/date/date.js.map +1 -1
  19. package/dist/cjs/src/date/dateTime.js +2 -2
  20. package/dist/cjs/src/date/dateTime.js.map +1 -1
  21. package/dist/cjs/src/date/helper.js +28 -18
  22. package/dist/cjs/src/date/helper.js.map +1 -1
  23. package/dist/cjs/src/date/time.js +2 -2
  24. package/dist/cjs/src/date/time.js.map +1 -1
  25. package/dist/cjs/src/graphics/image.js.map +1 -1
  26. package/dist/cjs/src/graphics/imagehelper.js.map +1 -1
  27. package/dist/cjs/src/graphics/svg.js +25 -2
  28. package/dist/cjs/src/graphics/svg.js.map +1 -1
  29. package/dist/cjs/src/index.js +34 -31
  30. package/dist/cjs/src/index.js.map +1 -1
  31. package/dist/cjs/src/multiVariableText/helper.js +2 -2
  32. package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
  33. package/dist/cjs/src/multiVariableText/pdfRender.js +5 -5
  34. package/dist/cjs/src/multiVariableText/pdfRender.js.map +1 -1
  35. package/dist/cjs/src/multiVariableText/propPanel.js +19 -14
  36. package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
  37. package/dist/cjs/src/multiVariableText/uiRender.js +25 -15
  38. package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
  39. package/dist/cjs/src/radioGroup/index.js +4 -4
  40. package/dist/cjs/src/radioGroup/index.js.map +1 -1
  41. package/dist/cjs/src/select/index.js +9 -9
  42. package/dist/cjs/src/select/index.js.map +1 -1
  43. package/dist/cjs/src/shapes/line.js +1 -1
  44. package/dist/cjs/src/shapes/rectAndEllipse.js +8 -4
  45. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  46. package/dist/cjs/src/tables/classes.js +4 -4
  47. package/dist/cjs/src/tables/classes.js.map +1 -1
  48. package/dist/cjs/src/tables/dynamicTemplate.js +2 -2
  49. package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -1
  50. package/dist/cjs/src/tables/helper.js +25 -25
  51. package/dist/cjs/src/tables/helper.js.map +1 -1
  52. package/dist/cjs/src/tables/pdfRender.js +8 -8
  53. package/dist/cjs/src/tables/pdfRender.js.map +1 -1
  54. package/dist/cjs/src/tables/tableHelper.js +6 -7
  55. package/dist/cjs/src/tables/tableHelper.js.map +1 -1
  56. package/dist/cjs/src/tables/uiRender.js.map +1 -1
  57. package/dist/cjs/src/text/extraFormatter.js +17 -17
  58. package/dist/cjs/src/text/extraFormatter.js.map +1 -1
  59. package/dist/cjs/src/text/helper.js +17 -7
  60. package/dist/cjs/src/text/helper.js.map +1 -1
  61. package/dist/cjs/src/text/pdfRender.js +1 -1
  62. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  63. package/dist/cjs/src/text/propPanel.js +2 -2
  64. package/dist/cjs/src/text/propPanel.js.map +1 -1
  65. package/dist/cjs/src/text/uiRender.js.map +1 -1
  66. package/dist/cjs/src/utils.js +52 -12
  67. package/dist/cjs/src/utils.js.map +1 -1
  68. package/dist/esm/__tests__/barcode.test.js +14 -15
  69. package/dist/esm/__tests__/barcode.test.js.map +1 -1
  70. package/dist/esm/__tests__/multiVariableText.test.js +1 -1
  71. package/dist/esm/__tests__/multiVariableText.test.js.map +1 -1
  72. package/dist/esm/__tests__/text.test.js +2 -2
  73. package/dist/esm/__tests__/text.test.js.map +1 -1
  74. package/dist/esm/__tests__/utils.test.js +65 -4
  75. package/dist/esm/__tests__/utils.test.js.map +1 -1
  76. package/dist/esm/src/barcodes/helper.js +2 -1
  77. package/dist/esm/src/barcodes/helper.js.map +1 -1
  78. package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
  79. package/dist/esm/src/barcodes/propPanel.js +3 -3
  80. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  81. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  82. package/dist/esm/src/checkbox/index.js +2 -2
  83. package/dist/esm/src/checkbox/index.js.map +1 -1
  84. package/dist/esm/src/date/date.js +1 -1
  85. package/dist/esm/src/date/date.js.map +1 -1
  86. package/dist/esm/src/date/dateTime.js +1 -1
  87. package/dist/esm/src/date/dateTime.js.map +1 -1
  88. package/dist/esm/src/date/helper.js +4 -4
  89. package/dist/esm/src/date/helper.js.map +1 -1
  90. package/dist/esm/src/date/time.js +1 -1
  91. package/dist/esm/src/date/time.js.map +1 -1
  92. package/dist/esm/src/graphics/image.js.map +1 -1
  93. package/dist/esm/src/graphics/imagehelper.js.map +1 -1
  94. package/dist/esm/src/graphics/svg.js +25 -2
  95. package/dist/esm/src/graphics/svg.js.map +1 -1
  96. package/dist/esm/src/index.js +16 -14
  97. package/dist/esm/src/index.js.map +1 -1
  98. package/dist/esm/src/multiVariableText/helper.js +2 -2
  99. package/dist/esm/src/multiVariableText/helper.js.map +1 -1
  100. package/dist/esm/src/multiVariableText/pdfRender.js +2 -2
  101. package/dist/esm/src/multiVariableText/pdfRender.js.map +1 -1
  102. package/dist/esm/src/multiVariableText/propPanel.js +15 -10
  103. package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
  104. package/dist/esm/src/multiVariableText/uiRender.js +19 -9
  105. package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
  106. package/dist/esm/src/radioGroup/index.js +2 -2
  107. package/dist/esm/src/radioGroup/index.js.map +1 -1
  108. package/dist/esm/src/select/index.js +2 -2
  109. package/dist/esm/src/select/index.js.map +1 -1
  110. package/dist/esm/src/shapes/line.js +1 -1
  111. package/dist/esm/src/shapes/rectAndEllipse.js +8 -4
  112. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  113. package/dist/esm/src/tables/classes.js +1 -1
  114. package/dist/esm/src/tables/classes.js.map +1 -1
  115. package/dist/esm/src/tables/dynamicTemplate.js +1 -1
  116. package/dist/esm/src/tables/dynamicTemplate.js.map +1 -1
  117. package/dist/esm/src/tables/helper.js +5 -5
  118. package/dist/esm/src/tables/helper.js.map +1 -1
  119. package/dist/esm/src/tables/pdfRender.js +4 -4
  120. package/dist/esm/src/tables/pdfRender.js.map +1 -1
  121. package/dist/esm/src/tables/tableHelper.js +1 -1
  122. package/dist/esm/src/tables/tableHelper.js.map +1 -1
  123. package/dist/esm/src/tables/uiRender.js.map +1 -1
  124. package/dist/esm/src/text/extraFormatter.js +2 -2
  125. package/dist/esm/src/text/extraFormatter.js.map +1 -1
  126. package/dist/esm/src/text/helper.js.map +1 -1
  127. package/dist/esm/src/text/pdfRender.js +1 -1
  128. package/dist/esm/src/text/pdfRender.js.map +1 -1
  129. package/dist/esm/src/text/propPanel.js +1 -1
  130. package/dist/esm/src/text/propPanel.js.map +1 -1
  131. package/dist/esm/src/text/uiRender.js.map +1 -1
  132. package/dist/esm/src/utils.js +52 -12
  133. package/dist/esm/src/utils.js.map +1 -1
  134. package/dist/node/__tests__/barcode.test.js +119 -120
  135. package/dist/node/__tests__/barcode.test.js.map +1 -1
  136. package/dist/node/__tests__/multiVariableText.test.js +15 -15
  137. package/dist/node/__tests__/multiVariableText.test.js.map +1 -1
  138. package/dist/node/__tests__/text.test.js +88 -78
  139. package/dist/node/__tests__/text.test.js.map +1 -1
  140. package/dist/node/__tests__/utils.test.js +76 -15
  141. package/dist/node/__tests__/utils.test.js.map +1 -1
  142. package/dist/node/src/barcodes/helper.js +2 -1
  143. package/dist/node/src/barcodes/helper.js.map +1 -1
  144. package/dist/node/src/barcodes/pdfRender.js.map +1 -1
  145. package/dist/node/src/barcodes/propPanel.js +3 -3
  146. package/dist/node/src/barcodes/propPanel.js.map +1 -1
  147. package/dist/node/src/barcodes/uiRender.js.map +1 -1
  148. package/dist/node/src/checkbox/index.js +4 -4
  149. package/dist/node/src/checkbox/index.js.map +1 -1
  150. package/dist/node/src/date/date.js +2 -2
  151. package/dist/node/src/date/date.js.map +1 -1
  152. package/dist/node/src/date/dateTime.js +2 -2
  153. package/dist/node/src/date/dateTime.js.map +1 -1
  154. package/dist/node/src/date/helper.js +28 -18
  155. package/dist/node/src/date/helper.js.map +1 -1
  156. package/dist/node/src/date/time.js +2 -2
  157. package/dist/node/src/date/time.js.map +1 -1
  158. package/dist/node/src/graphics/image.js.map +1 -1
  159. package/dist/node/src/graphics/imagehelper.js.map +1 -1
  160. package/dist/node/src/graphics/svg.js +25 -2
  161. package/dist/node/src/graphics/svg.js.map +1 -1
  162. package/dist/node/src/index.js +34 -31
  163. package/dist/node/src/index.js.map +1 -1
  164. package/dist/node/src/multiVariableText/helper.js +2 -2
  165. package/dist/node/src/multiVariableText/helper.js.map +1 -1
  166. package/dist/node/src/multiVariableText/pdfRender.js +5 -5
  167. package/dist/node/src/multiVariableText/pdfRender.js.map +1 -1
  168. package/dist/node/src/multiVariableText/propPanel.js +19 -14
  169. package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
  170. package/dist/node/src/multiVariableText/uiRender.js +25 -15
  171. package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
  172. package/dist/node/src/radioGroup/index.js +4 -4
  173. package/dist/node/src/radioGroup/index.js.map +1 -1
  174. package/dist/node/src/select/index.js +9 -9
  175. package/dist/node/src/select/index.js.map +1 -1
  176. package/dist/node/src/shapes/line.js +1 -1
  177. package/dist/node/src/shapes/rectAndEllipse.js +8 -4
  178. package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
  179. package/dist/node/src/tables/classes.js +4 -4
  180. package/dist/node/src/tables/classes.js.map +1 -1
  181. package/dist/node/src/tables/dynamicTemplate.js +2 -2
  182. package/dist/node/src/tables/dynamicTemplate.js.map +1 -1
  183. package/dist/node/src/tables/helper.js +25 -25
  184. package/dist/node/src/tables/helper.js.map +1 -1
  185. package/dist/node/src/tables/pdfRender.js +8 -8
  186. package/dist/node/src/tables/pdfRender.js.map +1 -1
  187. package/dist/node/src/tables/tableHelper.js +6 -7
  188. package/dist/node/src/tables/tableHelper.js.map +1 -1
  189. package/dist/node/src/tables/uiRender.js.map +1 -1
  190. package/dist/node/src/text/extraFormatter.js +17 -17
  191. package/dist/node/src/text/extraFormatter.js.map +1 -1
  192. package/dist/node/src/text/helper.js +17 -7
  193. package/dist/node/src/text/helper.js.map +1 -1
  194. package/dist/node/src/text/pdfRender.js +1 -1
  195. package/dist/node/src/text/pdfRender.js.map +1 -1
  196. package/dist/node/src/text/propPanel.js +2 -2
  197. package/dist/node/src/text/propPanel.js.map +1 -1
  198. package/dist/node/src/text/uiRender.js.map +1 -1
  199. package/dist/node/src/utils.js +52 -12
  200. package/dist/node/src/utils.js.map +1 -1
  201. package/dist/types/src/barcodes/helper.d.ts +1 -1
  202. package/dist/types/src/barcodes/index.d.ts +1 -1
  203. package/dist/types/src/barcodes/pdfRender.d.ts +1 -1
  204. package/dist/types/src/barcodes/propPanel.d.ts +1 -1
  205. package/dist/types/src/barcodes/uiRender.d.ts +1 -1
  206. package/dist/types/src/date/date.d.ts +1 -1
  207. package/dist/types/src/date/dateTime.d.ts +1 -1
  208. package/dist/types/src/date/helper.d.ts +1 -1
  209. package/dist/types/src/date/time.d.ts +1 -1
  210. package/dist/types/src/date/types.d.ts +6 -1
  211. package/dist/types/src/index.d.ts +16 -15
  212. package/dist/types/src/multiVariableText/helper.d.ts +1 -1
  213. package/dist/types/src/multiVariableText/index.d.ts +1 -1
  214. package/dist/types/src/multiVariableText/pdfRender.d.ts +1 -1
  215. package/dist/types/src/multiVariableText/propPanel.d.ts +1 -1
  216. package/dist/types/src/multiVariableText/types.d.ts +1 -1
  217. package/dist/types/src/multiVariableText/uiRender.d.ts +1 -1
  218. package/dist/types/src/select/index.d.ts +1 -1
  219. package/dist/types/src/shapes/rectAndEllipse.d.ts +16 -96
  220. package/dist/types/src/tables/cell.d.ts +1 -1
  221. package/dist/types/src/tables/classes.d.ts +1 -1
  222. package/dist/types/src/tables/helper.d.ts +5 -5
  223. package/dist/types/src/tables/pdfRender.d.ts +1 -1
  224. package/dist/types/src/tables/propPanel.d.ts +1 -1
  225. package/dist/types/src/tables/tableHelper.d.ts +1 -1
  226. package/dist/types/src/tables/types.d.ts +1 -1
  227. package/dist/types/src/text/constants.d.ts +1 -1
  228. package/dist/types/src/text/helper.d.ts +1 -1
  229. package/dist/types/src/text/index.d.ts +1 -1
  230. package/dist/types/src/text/pdfRender.d.ts +1 -1
  231. package/dist/types/src/text/propPanel.d.ts +1 -1
  232. package/dist/types/src/text/uiRender.d.ts +1 -1
  233. package/dist/types/src/utils.d.ts +4 -85
  234. package/eslint.config.mjs +22 -0
  235. package/package.json +3 -4
  236. package/src/barcodes/helper.ts +3 -4
  237. package/src/barcodes/index.ts +2 -2
  238. package/src/barcodes/pdfRender.ts +2 -2
  239. package/src/barcodes/propPanel.ts +4 -5
  240. package/src/barcodes/uiRender.ts +1 -1
  241. package/src/checkbox/index.ts +2 -2
  242. package/src/date/date.ts +1 -1
  243. package/src/date/dateTime.ts +1 -1
  244. package/src/date/helper.ts +20 -13
  245. package/src/date/time.ts +1 -1
  246. package/src/date/types.ts +7 -1
  247. package/src/graphics/imagehelper.ts +1 -1
  248. package/src/graphics/svg.ts +27 -2
  249. package/src/index.ts +17 -14
  250. package/src/multiVariableText/helper.ts +15 -7
  251. package/src/multiVariableText/index.ts +1 -1
  252. package/src/multiVariableText/pdfRender.ts +3 -3
  253. package/src/multiVariableText/propPanel.ts +19 -16
  254. package/src/multiVariableText/types.ts +1 -1
  255. package/src/multiVariableText/uiRender.ts +26 -23
  256. package/src/radioGroup/index.ts +3 -3
  257. package/src/select/index.ts +4 -4
  258. package/src/shapes/line.ts +1 -1
  259. package/src/shapes/rectAndEllipse.ts +10 -4
  260. package/src/tables/cell.ts +5 -5
  261. package/src/tables/classes.ts +7 -7
  262. package/src/tables/dynamicTemplate.ts +3 -3
  263. package/src/tables/helper.ts +7 -7
  264. package/src/tables/pdfRender.ts +9 -9
  265. package/src/tables/propPanel.ts +1 -1
  266. package/src/tables/tableHelper.ts +15 -12
  267. package/src/tables/types.ts +1 -1
  268. package/src/tables/uiRender.ts +6 -6
  269. package/src/text/constants.ts +1 -1
  270. package/src/text/extraFormatter.ts +2 -2
  271. package/src/text/helper.ts +6 -6
  272. package/src/text/index.ts +1 -1
  273. package/src/text/pdfRender.ts +4 -4
  274. package/src/text/propPanel.ts +2 -2
  275. package/src/text/uiRender.ts +14 -6
  276. package/src/utils.ts +60 -15
  277. package/tsconfig.cjs.json +1 -1
  278. package/tsconfig.esm.json +2 -1
  279. package/tsconfig.node.json +2 -1
  280. package/.eslintrc.cjs +0 -3
@@ -1,7 +1,7 @@
1
1
  import type * as CSS from 'csstype';
2
2
 
3
3
  import AirDatepicker from 'air-datepicker';
4
- import type { AirDatepickerLocale, AirDatepickerButton } from 'air-datepicker';
4
+ import type { AirDatepickerLocale, AirDatepickerButton, AirDatepickerDate } from 'air-datepicker';
5
5
  import localeAr from 'air-datepicker/locale/ar';
6
6
  import localeBg from 'air-datepicker/locale/bg';
7
7
  import localeCa from 'air-datepicker/locale/ca';
@@ -40,9 +40,9 @@ import * as dateFns from 'date-fns/locale';
40
40
  import { format } from 'date-fns';
41
41
 
42
42
  import { Plugin, getFallbackFontName, DEFAULT_FONT_NAME, PropPanelSchema } from '@pdfme/common';
43
- import text from '../text';
43
+ import text from '../text/index.js';
44
44
  import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
45
- import { mapVerticalAlignToFlex } from '../text/uiRender';
45
+ import { mapVerticalAlignToFlex } from '../text/uiRender.js';
46
46
  import {
47
47
  DEFAULT_FONT_SIZE,
48
48
  DEFAULT_ALIGNMENT,
@@ -51,9 +51,16 @@ import {
51
51
  DEFAULT_CHARACTER_SPACING,
52
52
  DEFAULT_FONT_COLOR,
53
53
  } from '../text/constants.js';
54
- import { DateSchema } from './types';
55
- import { getExtraFormatterSchema, Formatter } from '../text/extraFormatter';
56
- import { isEditable } from '../utils';
54
+ import { DateSchema } from './types.js';
55
+ import { getExtraFormatterSchema, Formatter } from '../text/extraFormatter.js';
56
+ import { isEditable } from '../utils.js';
57
+
58
+ interface AirDatepickerInstance {
59
+ selectedDates: Date[];
60
+ hide: () => void;
61
+ destroy: () => void;
62
+ show: () => void;
63
+ }
57
64
 
58
65
  type PickerType = 'date' | 'time' | 'dateTime';
59
66
 
@@ -162,7 +169,7 @@ const getFmtValue = (
162
169
  value: string,
163
170
  type: PickerType,
164
171
  schema: DateSchema,
165
- locale: Locale
172
+ locale: Locale,
166
173
  ): string => {
167
174
  return value
168
175
  ? format(strDateToDate(value, type), schema.format, {
@@ -259,16 +266,16 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
259
266
  },
260
267
  });
261
268
  }
262
-
263
269
  const airDatepicker = new AirDatepicker(input, {
264
270
  locale: locale.adLocale,
265
271
  selectedDates: [strDateToDate(value, type)],
266
- dateFormat: (date) => format(date, schema.format, { locale: locale.formatLocale }),
272
+ dateFormat: (date: AirDatepickerDate) =>
273
+ format(date, schema.format, { locale: locale.formatLocale }),
267
274
  timepicker: type !== 'date',
268
275
  onlyTimepicker: type === 'time',
269
276
  isMobile: window.innerWidth < 768,
270
277
  buttons: adButtons,
271
- onSelect: ({ datepicker }) => {
278
+ onSelect: ({ datepicker }: { datepicker: AirDatepickerInstance }) => {
272
279
  if (type === 'date') {
273
280
  commitChange(datepicker.selectedDates.length ? datepicker.selectedDates[0] : null);
274
281
  datepicker.hide();
@@ -311,7 +318,7 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
311
318
  const fallbackFontName = getFallbackFontName(font);
312
319
 
313
320
  const locale = getAirDatepickerLocale(
314
- (activeSchema as any).locale || options.lang || defaultLocale
321
+ (activeSchema as any).locale || options.lang || defaultLocale,
315
322
  );
316
323
 
317
324
  if (
@@ -326,7 +333,7 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
326
333
 
327
334
  const formatter = getExtraFormatterSchema(i18n);
328
335
  formatter.buttons = formatter.buttons.filter(
329
- (button) => button.key === Formatter.ALIGNMENT
336
+ (button) => button.key === Formatter.ALIGNMENT,
330
337
  );
331
338
 
332
339
  const validateDateTimeFormat = (_rule: any, formatString: string): boolean => {
@@ -441,7 +448,7 @@ export const getPlugin = ({ type, icon }: { type: PickerType; icon: string }) =>
441
448
  backgroundColor: '',
442
449
  locale: undefined,
443
450
  opacity: DEFAULT_OPACITY,
444
- },
451
+ } as DateSchema,
445
452
  },
446
453
  icon,
447
454
  };
package/src/date/time.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getPlugin } from './helper';
1
+ import { getPlugin } from './helper.js';
2
2
  import { createSvgStr } from '../utils.js';
3
3
  import { Clock } from 'lucide';
4
4
 
package/src/date/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Schema } from '@pdfme/common';
2
- import { ALIGNMENT } from '../text/types';
2
+ import { ALIGNMENT } from '../text/types.js';
3
3
 
4
4
  export interface DateSchema extends Schema {
5
5
  format: string;
@@ -10,4 +10,10 @@ export interface DateSchema extends Schema {
10
10
  fontColor: string;
11
11
  backgroundColor: string;
12
12
  locale?: string;
13
+ // Explicitly include these properties from Schema for TypeScript
14
+ width: number;
15
+ height: number;
16
+ name: string;
17
+ type: string;
18
+ content?: string;
13
19
  }
@@ -150,7 +150,7 @@ const imageSize = (imgBuffer: Buffer): { height: number; width: number } => {
150
150
  }
151
151
 
152
152
  throw new TypeError(
153
- '[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type)
153
+ '[@pdfme/schemas/images] Unsupported file type: ' + (type === undefined ? 'undefined' : type),
154
154
  );
155
155
  };
156
156
  // ----------------------------
@@ -1,5 +1,4 @@
1
1
  import { Plugin, Schema } from '@pdfme/common';
2
- import { XMLValidator } from 'fast-xml-parser';
3
2
  import {
4
3
  convertForPdfLayoutProps,
5
4
  isEditable,
@@ -9,7 +8,33 @@ import {
9
8
  } from '../utils.js';
10
9
  import { Route } from 'lucide';
11
10
 
12
- const isValidSVG = (svgString: string) => XMLValidator.validate(svgString) === true;
11
+ const isValidSVG = (svgString: string): boolean => {
12
+ try {
13
+ // Basic validation checks that work in both Node.js and browser
14
+ if (!svgString || typeof svgString !== 'string') {
15
+ return false;
16
+ }
17
+
18
+ // Check for basic SVG structure
19
+ if (!svgString.includes('<svg') || !svgString.includes('</svg>')) {
20
+ return false;
21
+ }
22
+
23
+ // Additional browser-specific validation if DOMParser is available
24
+ if (typeof DOMParser !== 'undefined') {
25
+ const parser = new DOMParser();
26
+ const doc = parser.parseFromString(svgString, 'image/svg+xml');
27
+ const parserError = doc.querySelector('parsererror');
28
+ if (parserError !== null) {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ return true;
34
+ } catch (error) {
35
+ return false;
36
+ }
37
+ };
13
38
 
14
39
  const defaultValue = `<svg viewBox="0 0 488 600" version="1.1" xmlns="http://www.w3.org/2000/svg">
15
40
  <g transform="matrix(1,0,0,1,-56,0)" fill="#000000" stroke="none">
package/src/index.ts CHANGED
@@ -1,17 +1,17 @@
1
- import multiVariableText from './multiVariableText/index';
2
- import text from './text/index';
3
- import image from './graphics/image';
4
- import svg from './graphics/svg';
5
- import barcodes from './barcodes/index';
6
- import line from './shapes/line';
7
- import table from './tables/index';
8
- import { rectangle, ellipse } from './shapes/rectAndEllipse';
9
- import dateTime from './date/dateTime';
10
- import date from './date/date';
11
- import time from './date/time';
12
- import select from './select/index';
13
- import radioGroup from './radioGroup/index';
14
- import checkbox from './checkbox/index';
1
+ import multiVariableText from './multiVariableText/index.js';
2
+ import text from './text/index.js';
3
+ import image from './graphics/image.js';
4
+ import svg from './graphics/svg.js';
5
+ import barcodes from './barcodes/index.js';
6
+ import line from './shapes/line.js';
7
+ import table from './tables/index.js';
8
+ import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
9
+ import dateTime from './date/dateTime.js';
10
+ import date from './date/date.js';
11
+ import time from './date/time.js';
12
+ import select from './select/index.js';
13
+ import radioGroup from './radioGroup/index.js';
14
+ import checkbox from './checkbox/index.js';
15
15
 
16
16
  const builtInPlugins = { Text: text };
17
17
 
@@ -34,3 +34,6 @@ export {
34
34
  radioGroup,
35
35
  checkbox,
36
36
  };
37
+
38
+ // Export utility functions
39
+ export { getDynamicHeightsForTable } from './tables/dynamicTemplate.js';
@@ -1,14 +1,18 @@
1
- import { MultiVariableTextSchema } from "./types";
1
+ import { MultiVariableTextSchema } from './types.js';
2
2
 
3
- export const substituteVariables = (text: string, variablesIn: string | Record<string, string>): string => {
3
+ export const substituteVariables = (
4
+ text: string,
5
+ variablesIn: string | Record<string, string>,
6
+ ): string => {
4
7
  if (!text) {
5
- return "";
8
+ return '';
6
9
  }
7
10
 
8
11
  let substitutedText = text;
9
12
 
10
13
  if (variablesIn) {
11
- const variables: Record<string, string> = (typeof variablesIn === "string") ? JSON.parse(variablesIn) || {} : variablesIn;
14
+ const variables: Record<string, string> =
15
+ typeof variablesIn === 'string' ? JSON.parse(variablesIn) || {} : variablesIn;
12
16
 
13
17
  Object.keys(variables).forEach((variableName) => {
14
18
  // handle special characters in variable name
@@ -33,13 +37,17 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
33
37
  try {
34
38
  values = value ? JSON.parse(value) : {};
35
39
  } catch (e) {
36
- throw new SyntaxError(`[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
40
+ throw new SyntaxError(
41
+ `[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`,
42
+ );
37
43
  }
38
44
 
39
45
  for (const variable of schema.variables) {
40
46
  if (!values[variable]) {
41
47
  if (schema.required) {
42
- throw new Error(`[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`);
48
+ throw new Error(
49
+ `[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`,
50
+ );
43
51
  }
44
52
  // If not required, then simply don't render this field if an input is missing
45
53
  return false;
@@ -47,4 +55,4 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
47
55
  }
48
56
 
49
57
  return true;
50
- }
58
+ };
@@ -2,7 +2,7 @@ import type { Plugin } from '@pdfme/common';
2
2
  import { pdfRender } from './pdfRender.js';
3
3
  import { propPanel } from './propPanel.js';
4
4
  import { uiRender } from './uiRender.js';
5
- import type { MultiVariableTextSchema } from './types';
5
+ import type { MultiVariableTextSchema } from './types.js';
6
6
  import { Type } from 'lucide';
7
7
  import { createSvgStr } from '../utils.js';
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { PDFRenderProps } from '@pdfme/common';
2
- import { MultiVariableTextSchema } from './types';
3
- import { pdfRender as parentPdfRender } from '../text/pdfRender';
4
- import { substituteVariables, validateVariables } from './helper';
2
+ import { MultiVariableTextSchema } from './types.js';
3
+ import { pdfRender as parentPdfRender } from '../text/pdfRender.js';
4
+ import { substituteVariables, validateVariables } from './helper.js';
5
5
 
6
6
  export const pdfRender = async (arg: PDFRenderProps<MultiVariableTextSchema>) => {
7
7
  const { value, schema, ...rest } = arg;
@@ -1,11 +1,11 @@
1
- import { propPanel as parentPropPanel } from '../text/propPanel';
1
+ import { propPanel as parentPropPanel } from '../text/propPanel.js';
2
2
  import { PropPanel, PropPanelWidgetProps } from '@pdfme/common';
3
- import { MultiVariableTextSchema } from './types';
3
+ import { MultiVariableTextSchema } from './types.js';
4
4
 
5
5
  const mapDynamicVariables = (props: PropPanelWidgetProps) => {
6
6
  const { rootElement, changeSchemas, activeSchema, i18n, options } = props;
7
7
 
8
- const mvtSchema = (activeSchema as any);
8
+ const mvtSchema = activeSchema as any;
9
9
  const text = mvtSchema.text || '';
10
10
  const variables = JSON.parse(mvtSchema.content) || {};
11
11
  const variablesChanged = updateVariablesFromText(text, variables);
@@ -14,11 +14,13 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
14
14
  if (variablesChanged) {
15
15
  changeSchemas([
16
16
  { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
17
- { key: 'variables', value: varNames, schemaId: activeSchema.id }
17
+ { key: 'variables', value: varNames, schemaId: activeSchema.id },
18
18
  ]);
19
19
  }
20
20
 
21
- const placeholderRowEl = document.getElementById('placeholder-dynamic-var')?.closest('.ant-form-item') as HTMLElement;
21
+ const placeholderRowEl = document
22
+ .getElementById('placeholder-dynamic-var')
23
+ ?.closest('.ant-form-item') as HTMLElement;
22
24
  if (!placeholderRowEl) {
23
25
  throw new Error('Failed to find Ant form placeholder row to create dynamic variables inputs.');
24
26
  }
@@ -36,10 +38,12 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
36
38
  textarea.value = variables[variableName];
37
39
  textarea.addEventListener('change', (e: Event) => {
38
40
  variables[variableName] = (e.target as HTMLTextAreaElement).value;
39
- changeSchemas([{ key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id }]);
41
+ changeSchemas([
42
+ { key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
43
+ ]);
40
44
  });
41
45
 
42
- const label = varRow.querySelector('label') as HTMLLabelElement
46
+ const label = varRow.querySelector('label') as HTMLLabelElement;
43
47
  label.innerText = variableName;
44
48
 
45
49
  varRow.style.display = 'block';
@@ -47,10 +51,11 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
47
51
  }
48
52
  } else {
49
53
  const para = document.createElement('p');
50
- para.innerHTML = i18n('schemas.mvt.typingInstructions')
51
- + ` <code style="color:${options?.theme?.token?.colorPrimary || "#168fe3"}; font-weight:bold;">{`
52
- + i18n('schemas.mvt.sampleField')
53
- + '}</code>';
54
+ para.innerHTML =
55
+ i18n('schemas.mvt.typingInstructions') +
56
+ ` <code style="color:${options?.theme?.token?.colorPrimary || '#168fe3'}; font-weight:bold;">{` +
57
+ i18n('schemas.mvt.sampleField') +
58
+ '}</code>';
54
59
  rootElement.appendChild(para);
55
60
  }
56
61
  };
@@ -73,7 +78,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
73
78
  type: 'object',
74
79
  widget: 'mapDynamicVariables',
75
80
  bind: false,
76
- span: 24
81
+ span: 24,
77
82
  },
78
83
  placeholderDynamicVar: {
79
84
  title: 'Placeholder Dynamic Variable',
@@ -88,9 +93,8 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
88
93
  },
89
94
  span: 24,
90
95
  },
91
- }
96
+ },
92
97
  },
93
-
94
98
  };
95
99
  },
96
100
  widgets: { ...parentPropPanel.widgets, mapDynamicVariables },
@@ -106,7 +110,6 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
106
110
  },
107
111
  };
108
112
 
109
-
110
113
  const updateVariablesFromText = (text: string, variables: any): boolean => {
111
114
  const regex = /\{([^{}]+)}/g;
112
115
  const matches = text.match(regex);
@@ -138,4 +141,4 @@ const updateVariablesFromText = (text: string, variables: any): boolean => {
138
141
  }
139
142
 
140
143
  return changed;
141
- }
144
+ };
@@ -1,4 +1,4 @@
1
- import type { TextSchema } from '../text/types';
1
+ import type { TextSchema } from '../text/types.js';
2
2
 
3
3
  export interface MultiVariableTextSchema extends TextSchema {
4
4
  text: string;
@@ -1,13 +1,13 @@
1
1
  import { getDefaultFont, UIRenderProps } from '@pdfme/common';
2
- import { MultiVariableTextSchema } from './types';
2
+ import { MultiVariableTextSchema } from './types.js';
3
3
  import {
4
4
  uiRender as parentUiRender,
5
5
  buildStyledTextContainer,
6
- makeElementPlainTextContentEditable
7
- } from '../text/uiRender';
8
- import { isEditable } from '../utils';
9
- import { getFontKitFont } from '../text/helper';
10
- import { substituteVariables } from './helper';
6
+ makeElementPlainTextContentEditable,
7
+ } from '../text/uiRender.js';
8
+ import { isEditable } from '../utils.js';
9
+ import { getFontKitFont } from '../text/helper.js';
10
+ import { substituteVariables } from './helper.js';
11
11
 
12
12
  export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
13
13
  const { value, schema, rootElement, mode, onChange, ...rest } = arg;
@@ -25,10 +25,14 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
25
25
  schema,
26
26
  mode: mode == 'form' ? 'viewer' : mode, // if no variables for form it's just a viewer
27
27
  rootElement,
28
- onChange: (arg: { key: string; value: any; } | { key: string; value: any; }[]) => {
28
+ onChange: (arg: { key: string; value: any } | { key: string; value: any }[]) => {
29
29
  if (!Array.isArray(arg)) {
30
30
  const numVariables = countUniqueVariableNames(arg.value);
31
- onChange && onChange([{key: 'text', value: arg.value}, {key: 'readOnly', value: numVariables == 0}]);
31
+ onChange &&
32
+ onChange([
33
+ { key: 'text', value: arg.value },
34
+ { key: 'readOnly', value: numVariables == 0 },
35
+ ]);
32
36
  } else {
33
37
  throw new Error('onChange is not an array, the parent text plugin has changed...');
34
38
  }
@@ -49,7 +53,10 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
49
53
  if (numVariables !== newNumVariables) {
50
54
  // If variables were modified during this keypress, we trigger a change
51
55
  if (onChange) {
52
- onChange([{key: 'text', value: text}, {key: 'readOnly', value: newNumVariables == 0}]);
56
+ onChange([
57
+ { key: 'text', value: text },
58
+ { key: 'readOnly', value: newNumVariables == 0 },
59
+ ]);
53
60
  }
54
61
  numVariables = newNumVariables;
55
62
  }
@@ -59,16 +66,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
59
66
  };
60
67
 
61
68
  const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
62
- const {
63
- value,
64
- schema,
65
- rootElement,
66
- onChange,
67
- stopEditing,
68
- theme,
69
- _cache,
70
- options,
71
- } = arg;
69
+ const { value, schema, rootElement, onChange, stopEditing, theme, _cache, options } = arg;
72
70
  const rawText = schema.text;
73
71
 
74
72
  if (rootElement.parentElement) {
@@ -92,7 +90,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
92
90
  inVarString = true;
93
91
  let span = document.createElement('span');
94
92
  span.style.outline = `${theme.colorPrimary} dashed 1px`;
95
- makeElementPlainTextContentEditable(span)
93
+ makeElementPlainTextContentEditable(span);
96
94
  span.textContent = variables[variableIndices[i]];
97
95
  span.addEventListener('blur', (e: Event) => {
98
96
  const newValue = (e.target as HTMLSpanElement).textContent || '';
@@ -114,7 +112,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
114
112
  textBlock.appendChild(span);
115
113
  }
116
114
  }
117
- }
115
+ };
118
116
 
119
117
  const getVariableIndices = (content: string) => {
120
118
  const regex = /\{([^}]+)}/g;
@@ -146,7 +144,12 @@ const countUniqueVariableNames = (content: string) => {
146
144
  * Regex would otherwise be performed on every key press (which isn't terrible, but this code helps).
147
145
  */
148
146
  const keyPressShouldBeChecked = (event: KeyboardEvent) => {
149
- if (event.key == "ArrowUp" || event.key == "ArrowDown" || event.key == "ArrowLeft" || event.key == "ArrowRight") {
147
+ if (
148
+ event.key == 'ArrowUp' ||
149
+ event.key == 'ArrowDown' ||
150
+ event.key == 'ArrowLeft' ||
151
+ event.key == 'ArrowRight'
152
+ ) {
150
153
  return false;
151
154
  }
152
155
 
@@ -164,4 +167,4 @@ const keyPressShouldBeChecked = (event: KeyboardEvent) => {
164
167
  }
165
168
 
166
169
  return true;
167
- }
170
+ };
@@ -1,7 +1,7 @@
1
1
  import { Plugin } from '@pdfme/common';
2
2
  import { Schema } from '@pdfme/common';
3
3
  import { Circle, CircleDot } from 'lucide';
4
- import svg from '../graphics/svg';
4
+ import svg from '../graphics/svg.js';
5
5
  import { isEditable, createSvgStr } from '../utils.js';
6
6
  import { HEX_COLOR_PATTERN } from '../constants.js';
7
7
 
@@ -65,7 +65,7 @@ const schema: Plugin<RadioGroup> = {
65
65
  onChange({ key: 'content', value: 'true' });
66
66
  radioButtonStates.set(schema.name, { value: 'true', onChange });
67
67
  eventEmitter.dispatchEvent(
68
- new CustomEvent(`group-${schema.group}`, { detail: schema.name })
68
+ new CustomEvent(`group-${schema.group}`, { detail: schema.name }),
69
69
  );
70
70
  }
71
71
  });
@@ -89,7 +89,7 @@ const schema: Plugin<RadioGroup> = {
89
89
  type: 'string',
90
90
  widget: 'color',
91
91
  props: {
92
- disabledAlpha: true
92
+ disabledAlpha: true,
93
93
  },
94
94
  required: true,
95
95
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
@@ -1,8 +1,8 @@
1
1
  import type * as CSS from 'csstype';
2
- import { propPanel as parentPropPanel } from '../text/propPanel';
2
+ import { propPanel as parentPropPanel } from '../text/propPanel.js';
3
3
  import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common';
4
- import text from '../text';
5
- import { TextSchema } from '../text/types';
4
+ import text from '../text/index.js';
5
+ import { TextSchema } from '../text/types.js';
6
6
  import { ChevronDown } from 'lucide';
7
7
  import { createSvgStr } from '../utils.js';
8
8
 
@@ -157,7 +157,7 @@ const schema: Plugin<Select> = {
157
157
  selectElement.innerHTML = schema.options
158
158
  .map(
159
159
  (option) =>
160
- `<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`
160
+ `<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`,
161
161
  )
162
162
  .join('');
163
163
  rootElement.appendChild(selectElement);
@@ -51,7 +51,7 @@ const lineSchema: Plugin<LineSchema> = {
51
51
  type: 'string',
52
52
  widget: 'color',
53
53
  props: {
54
- disabledAlpha: true
54
+ disabledAlpha: true,
55
55
  },
56
56
  required: true,
57
57
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
@@ -58,8 +58,14 @@ const shape: Plugin<ShapeSchema> = {
58
58
  });
59
59
  } else if (schema.type === 'rectangle') {
60
60
  page.drawRectangle({
61
- x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * (Math.PI ** 2),
62
- y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * (Math.PI ** 2),
61
+ x:
62
+ position.x +
63
+ borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) +
64
+ Math.tan(toRadians(rotate)) * Math.PI ** 2,
65
+ y:
66
+ position.y +
67
+ borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) +
68
+ Math.tan(toRadians(rotate)) * Math.PI ** 2,
63
69
  width: width - borderWidth,
64
70
  height: height - borderWidth,
65
71
  ...drawOptions,
@@ -80,7 +86,7 @@ const shape: Plugin<ShapeSchema> = {
80
86
  type: 'string',
81
87
  widget: 'color',
82
88
  props: {
83
- disabledAlpha: true
89
+ disabledAlpha: true,
84
90
  },
85
91
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
86
92
  },
@@ -89,7 +95,7 @@ const shape: Plugin<ShapeSchema> = {
89
95
  type: 'string',
90
96
  widget: 'color',
91
97
  props: {
92
- disabledAlpha: true
98
+ disabledAlpha: true,
93
99
  },
94
100
  rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
95
101
  },
@@ -9,7 +9,7 @@ import { uiRender as textUiRender } from '../text/uiRender.js';
9
9
  import { pdfRender as textPdfRender } from '../text/pdfRender.js';
10
10
  import line from '../shapes/line.js';
11
11
  import { rectangle } from '../shapes/rectAndEllipse.js';
12
- import type { CellSchema } from './types';
12
+ import type { CellSchema } from './types.js';
13
13
  import { getCellPropPanelSchema, getDefaultCellStyles } from './helper.js';
14
14
  const linePdfRender = line.pdf;
15
15
  const rectanglePdfRender = rectangle.pdf;
@@ -19,7 +19,7 @@ const renderLine = async (
19
19
  schema: CellSchema,
20
20
  position: { x: number; y: number },
21
21
  width: number,
22
- height: number
22
+ height: number,
23
23
  ) =>
24
24
  linePdfRender({
25
25
  ...arg,
@@ -45,7 +45,7 @@ const createLineDiv = (
45
45
  right: string | null,
46
46
  bottom: string | null,
47
47
  left: string | null,
48
- borderColor: string
48
+ borderColor: string,
49
49
  ) => {
50
50
  const div = document.createElement('div');
51
51
  div.style.width = width;
@@ -86,7 +86,7 @@ const cellSchema: Plugin<CellSchema> = {
86
86
  schema,
87
87
  { x: position.x + width - borderWidth.right, y: position.y },
88
88
  borderWidth.right,
89
- height
89
+ height,
90
90
  ),
91
91
  // BOTTOM
92
92
  renderLine(
@@ -94,7 +94,7 @@ const cellSchema: Plugin<CellSchema> = {
94
94
  schema,
95
95
  { x: position.x, y: position.y + height - borderWidth.bottom },
96
96
  width,
97
- borderWidth.bottom
97
+ borderWidth.bottom,
98
98
  ),
99
99
  // LEFT
100
100
  renderLine(arg, schema, { x: position.x, y: position.y }, borderWidth.left, height),