@sme.up/doc-alchemist 1.1.0-SNAPSHOT-20250623155458 → 1.2.0-20250805123329

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 (136) hide show
  1. package/README.md +278 -30
  2. package/dist/assets/gfx-data.d.ts +1 -0
  3. package/dist/assets/gfx-data.js +2 -0
  4. package/dist/assets/gfx-data.js.map +1 -0
  5. package/dist/converters/excel/commons.d.ts +43 -0
  6. package/dist/converters/excel/commons.js +232 -0
  7. package/dist/converters/excel/commons.js.map +1 -0
  8. package/dist/{src/excel/excel-generator.types.d.ts → converters/excel/excel-converter.types.d.ts} +2 -0
  9. package/dist/{src/excel/excel-generator.types.js → converters/excel/excel-converter.types.js} +5 -2
  10. package/dist/converters/excel/excel-converter.types.js.map +1 -0
  11. package/dist/{src/excel/matrix-generator.d.ts → converters/excel/matrix-converter.d.ts} +4 -2
  12. package/dist/{src/excel/matrix-generator.js → converters/excel/matrix-converter.js} +35 -38
  13. package/dist/converters/excel/matrix-converter.js.map +1 -0
  14. package/dist/{src/excel/tree-generator.d.ts → converters/excel/tree-converter.d.ts} +2 -2
  15. package/dist/{src/excel/tree-generator.js → converters/excel/tree-converter.js} +5 -5
  16. package/dist/converters/excel/tree-converter.js.map +1 -0
  17. package/dist/{src/excel/excel-generator.d.ts → converters/excel-converter.d.ts} +2 -1
  18. package/dist/{src/excel/excel-generator.js → converters/excel-converter.js} +4 -4
  19. package/dist/converters/excel-converter.js.map +1 -0
  20. package/dist/converters/images/charts-generator.d.ts +9 -0
  21. package/dist/converters/images/charts-generator.js +250 -0
  22. package/dist/converters/images/charts-generator.js.map +1 -0
  23. package/dist/converters/pdf/autotable-renderer.d.ts +4 -0
  24. package/dist/converters/pdf/autotable-renderer.js +83 -0
  25. package/dist/converters/pdf/autotable-renderer.js.map +1 -0
  26. package/dist/converters/pdf/cover-renderer.d.ts +1 -0
  27. package/dist/converters/pdf/cover-renderer.js +50 -0
  28. package/dist/converters/pdf/cover-renderer.js.map +1 -0
  29. package/dist/converters/pdf/formulas-helper.d.ts +40 -0
  30. package/dist/converters/pdf/formulas-helper.js +227 -0
  31. package/dist/converters/pdf/formulas-helper.js.map +1 -0
  32. package/dist/converters/pdf/matrix-converter.d.ts +17 -0
  33. package/dist/converters/pdf/matrix-converter.js +200 -0
  34. package/dist/converters/pdf/matrix-converter.js.map +1 -0
  35. package/dist/converters/pdf/pdf-converter.types.d.ts +13 -0
  36. package/dist/converters/pdf/pdf-converter.types.js +2 -0
  37. package/dist/converters/pdf/pdf-converter.types.js.map +1 -0
  38. package/dist/converters/pdf/sch-converter.d.ts +3 -0
  39. package/dist/converters/pdf/sch-converter.js +99 -0
  40. package/dist/converters/pdf/sch-converter.js.map +1 -0
  41. package/dist/converters/pdf-converter.d.ts +8 -0
  42. package/dist/converters/pdf-converter.js +54 -0
  43. package/dist/converters/pdf-converter.js.map +1 -0
  44. package/dist/index.d.ts +7 -4
  45. package/dist/index.js +4 -2
  46. package/dist/index.js.map +1 -1
  47. package/dist/types/component-props.d.ts +8 -0
  48. package/dist/types/component-props.js +7 -0
  49. package/dist/types/component-props.js.map +1 -0
  50. package/dist/types/component.d.ts +53 -0
  51. package/dist/types/component.js +53 -0
  52. package/dist/types/component.js.map +1 -0
  53. package/dist/types/converter.d.ts +8 -0
  54. package/dist/types/converter.js +2 -0
  55. package/dist/types/converter.js.map +1 -0
  56. package/dist/types/data-structures/smeupDataStructure.d.ts +215 -0
  57. package/dist/types/data-structures/smeupDataStructure.js +99 -0
  58. package/dist/types/data-structures/smeupDataStructure.js.map +1 -0
  59. package/dist/types/data-structures/smeupDataTable.d.ts +125 -0
  60. package/dist/types/data-structures/smeupDataTable.js +43 -0
  61. package/dist/types/data-structures/smeupDataTable.js.map +1 -0
  62. package/dist/types/data-structures/smeupDataTree.d.ts +13 -0
  63. package/dist/types/data-structures/smeupDataTree.js +2 -0
  64. package/dist/types/data-structures/smeupDataTree.js.map +1 -0
  65. package/dist/types/data-structures/smeupSch.d.ts +72 -0
  66. package/dist/types/data-structures/smeupSch.js +11 -0
  67. package/dist/types/data-structures/smeupSch.js.map +1 -0
  68. package/dist/types/dynamism.d.ts +45 -0
  69. package/dist/types/dynamism.js +30 -0
  70. package/dist/types/dynamism.js.map +1 -0
  71. package/dist/types/general.d.ts +22 -0
  72. package/dist/types/general.js +24 -0
  73. package/dist/types/general.js.map +1 -0
  74. package/dist/types/helpers.d.ts +4 -0
  75. package/dist/types/helpers.js +6 -0
  76. package/dist/types/helpers.js.map +1 -0
  77. package/dist/{src/types → types}/index.d.ts +9 -2
  78. package/dist/{src/types → types}/index.js +2 -0
  79. package/dist/types/index.js.map +1 -0
  80. package/dist/utils/commons-utility.d.ts +61 -0
  81. package/dist/{src/utils/generator-utility.js → utils/commons-utility.js} +100 -10
  82. package/dist/utils/commons-utility.js.map +1 -0
  83. package/dist/utils/datastructure-utility.d.ts +2 -0
  84. package/dist/utils/datastructure-utility.js +5 -0
  85. package/dist/utils/datastructure-utility.js.map +1 -0
  86. package/dist/{src/utils → utils}/dates-utility.d.ts +9 -0
  87. package/dist/{src/utils → utils}/dates-utility.js +18 -0
  88. package/dist/utils/dates-utility.js.map +1 -0
  89. package/dist/utils/formatter-utility.d.ts +4 -0
  90. package/dist/utils/formatter-utility.js +41 -0
  91. package/dist/utils/formatter-utility.js.map +1 -0
  92. package/dist/utils/image-utils.d.ts +7 -0
  93. package/dist/utils/image-utils.js +32 -0
  94. package/dist/utils/image-utils.js.map +1 -0
  95. package/dist/{src/utils → utils}/math-utility.d.ts +1 -0
  96. package/dist/{src/utils → utils}/math-utility.js +10 -0
  97. package/dist/utils/math-utility.js.map +1 -0
  98. package/dist/utils/objects-utility.js.map +1 -0
  99. package/dist/utils/regex-utility.js.map +1 -0
  100. package/package.json +14 -11
  101. package/dist/assets/sample-data.d.ts +0 -48
  102. package/dist/assets/sample-data.js +0 -372
  103. package/dist/assets/sample-data.js.map +0 -1
  104. package/dist/debug.d.ts +0 -1
  105. package/dist/debug.js +0 -29
  106. package/dist/debug.js.map +0 -1
  107. package/dist/src/excel/commons.d.ts +0 -21
  108. package/dist/src/excel/commons.js +0 -120
  109. package/dist/src/excel/commons.js.map +0 -1
  110. package/dist/src/excel/excel-generator.js.map +0 -1
  111. package/dist/src/excel/excel-generator.types.js.map +0 -1
  112. package/dist/src/excel/matrix-generator.js.map +0 -1
  113. package/dist/src/excel/tree-generator.js.map +0 -1
  114. package/dist/src/index.d.ts +0 -1
  115. package/dist/src/index.js +0 -2
  116. package/dist/src/index.js.map +0 -1
  117. package/dist/src/pdf/pdf-generator.d.ts +0 -7
  118. package/dist/src/pdf/pdf-generator.js +0 -28
  119. package/dist/src/pdf/pdf-generator.js.map +0 -1
  120. package/dist/src/types/index.js.map +0 -1
  121. package/dist/src/utils/datastructure-utility.d.ts +0 -2
  122. package/dist/src/utils/datastructure-utility.js +0 -5
  123. package/dist/src/utils/datastructure-utility.js.map +0 -1
  124. package/dist/src/utils/dates-utility.js.map +0 -1
  125. package/dist/src/utils/generator-utility.d.ts +0 -34
  126. package/dist/src/utils/generator-utility.js.map +0 -1
  127. package/dist/src/utils/math-utility.js.map +0 -1
  128. package/dist/src/utils/objects-utility.js.map +0 -1
  129. package/dist/src/utils/regex-utility.js.map +0 -1
  130. package/dist/tests/excel-generator.test.d.ts +0 -1
  131. package/dist/tests/excel-generator.test.js +0 -406
  132. package/dist/tests/excel-generator.test.js.map +0 -1
  133. /package/dist/{src/utils → utils}/objects-utility.d.ts +0 -0
  134. /package/dist/{src/utils → utils}/objects-utility.js +0 -0
  135. /package/dist/{src/utils → utils}/regex-utility.d.ts +0 -0
  136. /package/dist/{src/utils → utils}/regex-utility.js +0 -0
@@ -0,0 +1,83 @@
1
+ import { getLogoPositionAndDimension } from "../../utils/image-utils.js";
2
+ export const getAutoTableOptions = (visibleHeaders, data, optimalFontSize, cellStyles, context) => {
3
+ const { styles, columnStyles, headStyles } = getTableStyles(visibleHeaders, optimalFontSize);
4
+ return {
5
+ head: [visibleHeaders],
6
+ body: data.map(row => row.map(cell => cell.text)),
7
+ startY: 20,
8
+ margin: { left: 5, right: 5, top: 20, bottom: 10 },
9
+ styles,
10
+ columnStyles,
11
+ headStyles,
12
+ didDrawPage: dataArg => didDrawPageHandler(dataArg, context),
13
+ didParseCell: dataArg => didParseCellHandler(dataArg, cellStyles),
14
+ };
15
+ };
16
+ const getTableStyles = (visibleHeaders, optimalFontSize) => {
17
+ const styles = {
18
+ font: "helvetica",
19
+ fontSize: optimalFontSize + 1,
20
+ cellPadding: 1,
21
+ overflow: "linebreak",
22
+ cellWidth: "auto",
23
+ minCellWidth: 5,
24
+ };
25
+ const columnStyles = {
26
+ ...Object.fromEntries(visibleHeaders.map((_, index) => [
27
+ index,
28
+ {
29
+ cellWidth: "auto",
30
+ halign: "left",
31
+ overflow: "linebreak",
32
+ cellPadding: { top: 1, right: 1, bottom: 1, left: 1 },
33
+ },
34
+ ])),
35
+ };
36
+ const headStyles = {
37
+ fillColor: [255, 0, 0],
38
+ textColor: [255, 255, 255],
39
+ fontStyle: "bold",
40
+ halign: "center",
41
+ };
42
+ return { styles, columnStyles, headStyles };
43
+ };
44
+ const didParseCellHandler = (dataArg, cellStyles) => {
45
+ if (dataArg.section === "body") {
46
+ const rowIndex = dataArg.row.index;
47
+ const colIndex = dataArg.column.index;
48
+ const cellStyle = cellStyles[rowIndex]?.[colIndex];
49
+ if (cellStyle) {
50
+ // Apply styles from the Excel cell
51
+ Object.assign(dataArg.cell.styles, cellStyle);
52
+ }
53
+ }
54
+ };
55
+ const didDrawPageHandler = (dataArg, context) => {
56
+ const pageWidth = dataArg.doc.internal.pageSize.getWidth();
57
+ // Add the logo on each page
58
+ if (context?.logoBase64) {
59
+ const { logoWidth, logoHeight, logoX, logoY } = getLogoPositionAndDimension(dataArg.doc, context.logoBase64);
60
+ try {
61
+ dataArg.doc.addImage(context.logoBase64, "PNG", logoX, logoY, logoWidth, logoHeight);
62
+ }
63
+ catch (error) {
64
+ console.warn("Error adding logo:", error);
65
+ }
66
+ }
67
+ const textFontSize = 13;
68
+ const textX = 5;
69
+ let textY = 10;
70
+ // at this point I believe that, since the limited vertical space, if text is too long to be fit into one line, it should be trimmed (first element of split is taken into account)
71
+ if (context?.title) {
72
+ const title = dataArg.doc.splitTextToSize(context.title, pageWidth * 0.65)[0];
73
+ dataArg.doc.setFontSize(textFontSize);
74
+ dataArg.doc.setFont("helvetica", "normal");
75
+ dataArg.doc.text(title, textX, textY, { align: "left" });
76
+ }
77
+ if (context?.subtitle) {
78
+ textY += textFontSize / 2;
79
+ const subtitle = dataArg.doc.splitTextToSize(context.subtitle, pageWidth * 0.65)[0];
80
+ dataArg.doc.text(subtitle, textX, textY, { align: "left" });
81
+ }
82
+ };
83
+ //# sourceMappingURL=autotable-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autotable-renderer.js","sourceRoot":"","sources":["../../../src/converters/pdf/autotable-renderer.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AASzE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,cAAwB,EACxB,IAAwB,EACxB,eAAuB,EACvB,UAA6B,EAC7B,OAAyB,EACZ,EAAE;IACf,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,cAAc,CACzD,cAAc,EACd,eAAe,CAChB,CAAC;IACF,OAAO;QACL,IAAI,EAAE,CAAC,cAAc,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAClD,MAAM;QACN,YAAY;QACZ,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CACvC,OAAO,CAAC,KAAK,EACb,SAAS,GAAG,IAAI,CACjB,CAAC,CAAC,CAAC,CAAC;QACL,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,KAAK,IAAI,YAAY,GAAG,CAAC,CAAC;QAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAC1C,OAAO,CAAC,QAAQ,EAChB,SAAS,GAAG,IAAI,CACjB,CAAC,CAAC,CAAC,CAAC;QACL,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { UserOptions } from \"jspdf-autotable\";\nimport { CellStyleData, CellValueProps } from \"./pdf-converter.types.js\";\nimport type {\n Styles,\n OverflowType,\n FontStyle,\n CellHookData,\n HookData,\n} from \"jspdf-autotable\";\nimport { getLogoPositionAndDimension } from \"../../utils/image-utils.js\";\nimport { ConverterContext } from \"../../types/converter.js\";\n\ntype TableStyles = {\n styles: Partial<Styles>;\n columnStyles: Record<string, Partial<Styles>>;\n headStyles: Partial<Styles>;\n};\n\nexport const getAutoTableOptions = (\n visibleHeaders: string[],\n data: CellValueProps[][],\n optimalFontSize: number,\n cellStyles: CellStyleData[][],\n context: ConverterContext,\n): UserOptions => {\n const { styles, columnStyles, headStyles } = getTableStyles(\n visibleHeaders,\n optimalFontSize,\n );\n return {\n head: [visibleHeaders],\n body: data.map(row => row.map(cell => cell.text)),\n startY: 20,\n margin: { left: 5, right: 5, top: 20, bottom: 10 },\n styles,\n columnStyles,\n headStyles,\n didDrawPage: dataArg => didDrawPageHandler(dataArg, context),\n didParseCell: dataArg => didParseCellHandler(dataArg, cellStyles),\n };\n};\n\nconst getTableStyles = (\n visibleHeaders: string[],\n optimalFontSize: number,\n): TableStyles => {\n const styles: Partial<Styles> = {\n font: \"helvetica\",\n fontSize: optimalFontSize + 1,\n cellPadding: 1,\n overflow: \"linebreak\" as OverflowType,\n cellWidth: \"auto\",\n minCellWidth: 5,\n };\n\n const columnStyles: { [key: string]: Partial<Styles> } = {\n ...Object.fromEntries(\n visibleHeaders.map((_, index) => [\n index,\n {\n cellWidth: \"auto\",\n halign: \"left\",\n overflow: \"linebreak\" as OverflowType,\n cellPadding: { top: 1, right: 1, bottom: 1, left: 1 },\n },\n ]),\n ),\n };\n\n const headStyles: Partial<Styles> = {\n fillColor: [255, 0, 0],\n textColor: [255, 255, 255],\n fontStyle: \"bold\" as FontStyle,\n halign: \"center\",\n };\n\n return { styles, columnStyles, headStyles };\n};\n\nconst didParseCellHandler = (\n dataArg: CellHookData,\n cellStyles: CellStyleData[][],\n) => {\n if (dataArg.section === \"body\") {\n const rowIndex = dataArg.row.index;\n const colIndex = dataArg.column.index;\n const cellStyle = cellStyles[rowIndex]?.[colIndex];\n\n if (cellStyle) {\n // Apply styles from the Excel cell\n Object.assign(dataArg.cell.styles, cellStyle);\n }\n }\n};\n\nconst didDrawPageHandler = (dataArg: HookData, context: ConverterContext) => {\n const pageWidth = dataArg.doc.internal.pageSize.getWidth();\n\n // Add the logo on each page\n if (context?.logoBase64) {\n const { logoWidth, logoHeight, logoX, logoY } = getLogoPositionAndDimension(\n dataArg.doc,\n context.logoBase64,\n );\n\n try {\n dataArg.doc.addImage(\n context.logoBase64,\n \"PNG\",\n logoX,\n logoY,\n logoWidth,\n logoHeight,\n );\n } catch (error) {\n console.warn(\"Error adding logo:\", error);\n }\n }\n\n const textFontSize = 13;\n const textX = 5;\n let textY = 10;\n\n // at this point I believe that, since the limited vertical space, if text is too long to be fit into one line, it should be trimmed (first element of split is taken into account)\n\n if (context?.title) {\n const title = dataArg.doc.splitTextToSize(\n context.title,\n pageWidth * 0.65,\n )[0];\n dataArg.doc.setFontSize(textFontSize);\n dataArg.doc.setFont(\"helvetica\", \"normal\");\n dataArg.doc.text(title, textX, textY, { align: \"left\" });\n }\n\n if (context?.subtitle) {\n textY += textFontSize / 2;\n const subtitle = dataArg.doc.splitTextToSize(\n context.subtitle,\n pageWidth * 0.65,\n )[0];\n dataArg.doc.text(subtitle, textX, textY, { align: \"left\" });\n }\n};\n"]}
@@ -0,0 +1 @@
1
+ export declare const createCoverPdf: (image: string, logo: string, title: string, subtitle: string, subtitle2?: string) => ArrayBuffer;
@@ -0,0 +1,50 @@
1
+ import * as jsPDFModule from "jspdf";
2
+ import { getLogoPositionAndDimension } from "../../utils/image-utils.js";
3
+ export const createCoverPdf = (image, logo, title, subtitle, subtitle2) => {
4
+ const doc = new jsPDFModule.jsPDF("landscape");
5
+ const pageWidth = doc.internal.pageSize.getWidth();
6
+ const pageHeight = doc.internal.pageSize.getHeight();
7
+ const { logoWidth, logoHeight, logoX, logoY } = getLogoPositionAndDimension(doc, logo);
8
+ const titleFontSize = 24;
9
+ const subtitleFontSize = 16;
10
+ const subtitle2FontSize = 14;
11
+ let currentY = 45;
12
+ // background should be applied before any other element
13
+ if (image) {
14
+ try {
15
+ doc.addImage(image, "PNG", 0, 0, pageWidth, pageHeight);
16
+ }
17
+ catch (error) {
18
+ console.warn("Error adding image:", error);
19
+ }
20
+ }
21
+ try {
22
+ doc.addImage(logo, "PNG", logoX, logoY, logoWidth, logoHeight);
23
+ }
24
+ catch (error) {
25
+ console.warn("Error adding logo:", error);
26
+ }
27
+ // slices calculations should be made after setting font size!
28
+ let titleSlices = [];
29
+ let subtitleSlices = [];
30
+ let subtitle2Slices = [];
31
+ doc.setFont("helvetica", "bold");
32
+ doc.setFontSize(titleFontSize);
33
+ titleSlices = doc.splitTextToSize(title, pageWidth - 20);
34
+ doc.text(titleSlices, pageWidth / 2, currentY, { align: "center" });
35
+ if (subtitle) {
36
+ doc.setFont("helvetica", "normal");
37
+ doc.setFontSize(subtitleFontSize);
38
+ subtitleSlices = doc.splitTextToSize(subtitle, pageWidth - 20);
39
+ currentY += subtitleFontSize * Math.max(titleSlices.length, 1);
40
+ doc.text(subtitleSlices, pageWidth / 2, currentY, { align: "center" });
41
+ }
42
+ if (subtitle2) {
43
+ doc.setFontSize(subtitle2FontSize);
44
+ subtitle2Slices = doc.splitTextToSize(subtitle2, pageWidth - 20);
45
+ currentY += subtitle2FontSize * Math.max(subtitleSlices.length, 1);
46
+ doc.text(subtitle2Slices, pageWidth / 2, currentY, { align: "center" });
47
+ }
48
+ return doc.output("arraybuffer");
49
+ };
50
+ //# sourceMappingURL=cover-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cover-renderer.js","sourceRoot":"","sources":["../../../src/converters/pdf/cover-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzE,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAa,EACb,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,SAAkB,EACL,EAAE;IACf,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACnD,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IACrD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,2BAA2B,CACzE,GAAG,EACH,IAAI,CACL,CAAC;IACF,MAAM,aAAa,GAAG,EAAE,CA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,CAAC,CAAC;QAClC,cAAc,GAAG,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,EAAE,CAAC,CAAC;QAC/D,QAAQ,IAAI,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/D,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACnC,eAAe,GAAG,GAAG,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC,CAAC;QACjE,QAAQ,IAAI,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACnE,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC,CAAC","sourcesContent":["import * as jsPDFModule from \"jspdf\";\nimport { getLogoPositionAndDimension } from \"../../utils/image-utils.js\";\n\nexport const createCoverPdf = (\n image: string,\n logo: string,\n title: string,\n subtitle: string,\n subtitle2?: string,\n): ArrayBuffer => {\n const doc = new jsPDFModule.jsPDF(\"landscape\");\n const pageWidth = doc.internal.pageSize.getWidth();\n const pageHeight = doc.internal.pageSize.getHeight();\n const { logoWidth, logoHeight, logoX, logoY } = getLogoPositionAndDimension(\n doc,\n logo,\n );\n const titleFontSize = 24;\n const subtitleFontSize = 16;\n const subtitle2FontSize = 14;\n let currentY = 45;\n\n // background should be applied before any other element\n if (image) {\n try {\n doc.addImage(image, \"PNG\", 0, 0, pageWidth, pageHeight);\n } catch (error) {\n console.warn(\"Error adding image:\", error);\n }\n }\n\n try {\n doc.addImage(logo, \"PNG\", logoX, logoY, logoWidth, logoHeight);\n } catch (error) {\n console.warn(\"Error adding logo:\", error);\n }\n\n // slices calculations should be made after setting font size!\n let titleSlices: string[] = [];\n let subtitleSlices: string[] = [];\n let subtitle2Slices: string[] = [];\n\n doc.setFont(\"helvetica\", \"bold\");\n doc.setFontSize(titleFontSize);\n titleSlices = doc.splitTextToSize(title, pageWidth - 20);\n doc.text(titleSlices, pageWidth / 2, currentY, { align: \"center\" });\n\n if (subtitle) {\n doc.setFont(\"helvetica\", \"normal\");\n doc.setFontSize(subtitleFontSize);\n subtitleSlices = doc.splitTextToSize(subtitle, pageWidth - 20);\n currentY += subtitleFontSize * Math.max(titleSlices.length, 1);\n doc.text(subtitleSlices, pageWidth / 2, currentY, { align: \"center\" });\n }\n\n if (subtitle2) {\n doc.setFontSize(subtitle2FontSize);\n subtitle2Slices = doc.splitTextToSize(subtitle2, pageWidth - 20);\n currentY += subtitle2FontSize * Math.max(subtitleSlices.length, 1);\n doc.text(subtitle2Slices, pageWidth / 2, currentY, { align: \"center\" });\n }\n\n return doc.output(\"arraybuffer\");\n};\n"]}
@@ -0,0 +1,40 @@
1
+ import { WebupManagerData } from "../../types/index.js";
2
+ import { CellValueProps } from "./pdf-converter.types.js";
3
+ import ExcelJS from "exceljs";
4
+ /**
5
+ * Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.
6
+ *
7
+ * Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.
8
+ * The function extracts the relevant range from the worksheet, computes the result
9
+ * based on the subtotal type, and formats the output as needed (including date and number formatting).
10
+ *
11
+ * @param cell - The ExcelJS cell object where the formula is applied.
12
+ * @param worksheet - The ExcelJS worksheet containing the data range.
13
+ * @param webupManagerData - Additional data/context used for formatting numbers and dates.
14
+ * @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:
15
+ * - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).
16
+ * - [2]: The start cell reference of the range.
17
+ * - [3]: The end cell reference of the range.
18
+ * @returns An object containing the computed value and its type ("number" or "string").
19
+ */
20
+ export declare const handleSubtotalFormula: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData, subtotalMatch: RegExpMatchArray) => CellValueProps;
21
+ /**
22
+ * Evaluates a standard Excel formula from a given cell by replacing cell references
23
+ * with their actual values from the worksheet and then computing the result.
24
+ *
25
+ * - Replaces cell references (e.g., "A1") in the formula with their corresponding values.
26
+ * - Handles different cell value types: number, string, formula result, and date.
27
+ * - Evaluates the resulting formula string using a safe function context.
28
+ * - Applies number formatting if the result is numeric and a format is specified.
29
+ * - Returns the computed value and its type ("number" or "string").
30
+ *
31
+ * @param cell - The ExcelJS cell containing the formula to evaluate.
32
+ * @param worksheet - The ExcelJS worksheet object for resolving cell references.
33
+ * @param webupManagerData - Additional data used for number formatting.
34
+ * @returns An object containing the evaluated value and its type.
35
+ */
36
+ export declare const evaluateStandardFormula: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData) => CellValueProps;
37
+ /**
38
+ * Extracts and formats the value of a given ExcelJS cell based on its type.
39
+ */
40
+ export declare const getCellValueData: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData) => CellValueProps;
@@ -0,0 +1,227 @@
1
+ import { getCellsFromRange } from "../excel/commons.js";
2
+ import { areAllValuesDates } from "../../utils/dates-utility.js";
3
+ import { formatDate, formatNumber } from "../../utils/formatter-utility.js";
4
+ import ExcelJS from "exceljs";
5
+ import { calculateExpression } from "../../utils/math-utility.js";
6
+ /**
7
+ * Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.
8
+ *
9
+ * Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.
10
+ * The function extracts the relevant range from the worksheet, computes the result
11
+ * based on the subtotal type, and formats the output as needed (including date and number formatting).
12
+ *
13
+ * @param cell - The ExcelJS cell object where the formula is applied.
14
+ * @param worksheet - The ExcelJS worksheet containing the data range.
15
+ * @param webupManagerData - Additional data/context used for formatting numbers and dates.
16
+ * @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:
17
+ * - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).
18
+ * - [2]: The start cell reference of the range.
19
+ * - [3]: The end cell reference of the range.
20
+ * @returns An object containing the computed value and its type ("number" or "string").
21
+ */
22
+ export const handleSubtotalFormula = (cell, worksheet, webupManagerData, subtotalMatch) => {
23
+ const subtotalType = parseInt(subtotalMatch[1], 10);
24
+ const startRef = subtotalMatch[2];
25
+ const endRef = subtotalMatch[3];
26
+ const cells = getCellsFromRange(worksheet, startRef, endRef).filter(cell => cell.type !== ExcelJS.ValueType.Formula);
27
+ let result;
28
+ const areAllDates = areAllValuesDates(cells);
29
+ switch (subtotalType) {
30
+ case 3: // COUNTA
31
+ result = cells.length;
32
+ break;
33
+ case 9: // SUM
34
+ result = cells.reduce((sum, cell) => {
35
+ const n = typeof cell.value === "number"
36
+ ? cell.value
37
+ : typeof cell.value === "string"
38
+ ? parseFloat(cell.value)
39
+ : NaN;
40
+ return !isNaN(n)
41
+ ? (typeof sum === "number"
42
+ ? sum
43
+ : typeof sum === "string"
44
+ ? parseFloat(sum)
45
+ : 0) + n
46
+ : sum;
47
+ }, 0);
48
+ break;
49
+ case 4: // MAX
50
+ result = cells.length
51
+ ? Math.max(...cells.map(cell => {
52
+ if (cell.type === ExcelJS.ValueType.Date) {
53
+ return cell.value instanceof Date
54
+ ? cell.value.getTime()
55
+ : -Infinity;
56
+ }
57
+ return typeof cell.value === "number"
58
+ ? cell.value
59
+ : (typeof cell.value === "string"
60
+ ? parseFloat(cell.value)
61
+ : -Infinity) || -Infinity;
62
+ }))
63
+ : "";
64
+ break;
65
+ case 5: // MIN
66
+ result = cells.length
67
+ ? Math.min(...cells.map(cell => {
68
+ if (cell.type === ExcelJS.ValueType.Date) {
69
+ return cell.value instanceof Date
70
+ ? cell.value.getTime()
71
+ : Infinity;
72
+ }
73
+ return typeof cell.value === "number"
74
+ ? cell.value
75
+ : (typeof cell.value === "string"
76
+ ? parseFloat(cell.value)
77
+ : Infinity) || Infinity;
78
+ }))
79
+ : "";
80
+ break;
81
+ case 1: {
82
+ // AVERAGE
83
+ const nums = cells
84
+ .map(cell => typeof cell.value === "number"
85
+ ? cell.value
86
+ : typeof cell.value === "string"
87
+ ? parseFloat(cell.value)
88
+ : NaN)
89
+ .filter(v => !isNaN(v));
90
+ result = nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : "";
91
+ break;
92
+ }
93
+ default: {
94
+ if (cell.result != null && typeof cell.result !== "object") {
95
+ result = cell.result;
96
+ }
97
+ else {
98
+ result =
99
+ cell.text ||
100
+ (typeof cell.value === "string" || typeof cell.value === "number"
101
+ ? cell.value
102
+ : "") ||
103
+ "";
104
+ }
105
+ break;
106
+ }
107
+ }
108
+ if (areAllDates) {
109
+ return {
110
+ value: result,
111
+ text: formatDate(new Date(result), webupManagerData),
112
+ type: "date",
113
+ };
114
+ }
115
+ else if (typeof result === "number" && cell.numFmt) {
116
+ return {
117
+ value: result,
118
+ text: formatNumber(result, cell.numFmt, webupManagerData),
119
+ type: "number",
120
+ };
121
+ }
122
+ return {
123
+ value: result,
124
+ text: result.toString(),
125
+ type: typeof result === "number" ? "number" : "string",
126
+ };
127
+ };
128
+ /**
129
+ * Evaluates a standard Excel formula from a given cell by replacing cell references
130
+ * with their actual values from the worksheet and then computing the result.
131
+ *
132
+ * - Replaces cell references (e.g., "A1") in the formula with their corresponding values.
133
+ * - Handles different cell value types: number, string, formula result, and date.
134
+ * - Evaluates the resulting formula string using a safe function context.
135
+ * - Applies number formatting if the result is numeric and a format is specified.
136
+ * - Returns the computed value and its type ("number" or "string").
137
+ *
138
+ * @param cell - The ExcelJS cell containing the formula to evaluate.
139
+ * @param worksheet - The ExcelJS worksheet object for resolving cell references.
140
+ * @param webupManagerData - Additional data used for number formatting.
141
+ * @returns An object containing the evaluated value and its type.
142
+ */
143
+ export const evaluateStandardFormula = (cell, worksheet, webupManagerData) => {
144
+ const formula = cell.formula;
145
+ const formulaWithSolvedVariables = formula.replace(/([A-Z]+\d+)/g, ref => {
146
+ try {
147
+ const refCell = worksheet.getCell(ref);
148
+ if (refCell) {
149
+ if (refCell.type === ExcelJS.ValueType.Number) {
150
+ return refCell.value?.toString() ?? "0";
151
+ }
152
+ else if (refCell.type === ExcelJS.ValueType.String) {
153
+ // If the cell contains text, return as is (no quotes) for JS compatibility
154
+ return refCell.value?.toString() ?? "";
155
+ }
156
+ else if (refCell.type === ExcelJS.ValueType.Formula) {
157
+ return getCellValueData(refCell, worksheet, webupManagerData).value.toString();
158
+ }
159
+ else if (refCell.type === ExcelJS.ValueType.Date &&
160
+ refCell.value instanceof Date) {
161
+ return refCell.value.getTime().toString();
162
+ }
163
+ else {
164
+ return refCell.value?.toString() ?? "0";
165
+ }
166
+ }
167
+ }
168
+ catch {
169
+ return "0";
170
+ }
171
+ return "0";
172
+ });
173
+ const result = calculateExpression(formulaWithSolvedVariables);
174
+ // If the result is a number and a format is specified, apply it
175
+ if (typeof result === "number" && cell.numFmt) {
176
+ return {
177
+ value: result,
178
+ text: formatNumber(result, cell.numFmt, webupManagerData),
179
+ type: "number",
180
+ };
181
+ }
182
+ return {
183
+ value: result,
184
+ text: result != null ? result.toString() : cell.formula,
185
+ type: typeof result === "number" ? "number" : "string",
186
+ };
187
+ };
188
+ /**
189
+ * Extracts and formats the value of a given ExcelJS cell based on its type.
190
+ */
191
+ export const getCellValueData = (cell, worksheet, webupManagerData) => {
192
+ if (cell.type === ExcelJS.ValueType.Formula &&
193
+ typeof cell.formula === "string") {
194
+ const subtotalMatch = cell.formula.match(/^SUBTOTAL\((\d+)\s*,\s*([A-Z]+\d+):([A-Z]+\d+)\)/i);
195
+ if (subtotalMatch) {
196
+ return handleSubtotalFormula(cell, worksheet, webupManagerData, subtotalMatch);
197
+ }
198
+ else {
199
+ return evaluateStandardFormula(cell, worksheet, webupManagerData);
200
+ }
201
+ }
202
+ else if (cell.type === ExcelJS.ValueType.Date &&
203
+ cell.value instanceof Date) {
204
+ return {
205
+ value: cell.value,
206
+ text: formatDate(cell.value, webupManagerData),
207
+ type: "date",
208
+ };
209
+ }
210
+ else if (cell.type === ExcelJS.ValueType.Number) {
211
+ return {
212
+ value: cell.value,
213
+ text: formatNumber(cell.value, cell.numFmt ?? 0, webupManagerData),
214
+ type: "number",
215
+ };
216
+ }
217
+ else {
218
+ // Fallback to text or value if available, otherwise empty string
219
+ const value = cell?.text || cell?.value?.toString() || "";
220
+ return {
221
+ value: value,
222
+ text: value,
223
+ type: "string",
224
+ };
225
+ }
226
+ };
227
+ //# sourceMappingURL=formulas-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formulas-helper.js","sourceRoot":"","sources":["../../../src/converters/pdf/formulas-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAE5E,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAAkB,EAClB,SAA4B,EAC5B,gBAAkC,EAClC,aAA+B,EACf,EAAE;IAClB,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IACl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YACL,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { getCellsFromRange } from \"../excel/commons.js\";\nimport { WebupManagerData } from \"../../types/index.js\";\nimport { areAllValuesDates } from \"../../utils/dates-utility.js\";\nimport { formatDate, formatNumber } from \"../../utils/formatter-utility.js\";\nimport { CellValueProps } from \"./pdf-converter.types.js\";\nimport ExcelJS from \"exceljs\";\nimport { calculateExpression } from \"../../utils/math-utility.js\";\n\n/**\n * Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.\n *\n * Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.\n * The function extracts the relevant range from the worksheet, computes the result\n * based on the subtotal type, and formats the output as needed (including date and number formatting).\n *\n * @param cell - The ExcelJS cell object where the formula is applied.\n * @param worksheet - The ExcelJS worksheet containing the data range.\n * @param webupManagerData - Additional data/context used for formatting numbers and dates.\n * @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:\n * - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).\n * - [2]: The start cell reference of the range.\n * - [3]: The end cell reference of the range.\n * @returns An object containing the computed value and its type (\"number\" or \"string\").\n */\nexport const handleSubtotalFormula = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n subtotalMatch: RegExpMatchArray,\n): CellValueProps => {\n const subtotalType = parseInt(subtotalMatch[1], 10);\n const startRef = subtotalMatch[2];\n const endRef = subtotalMatch[3];\n const cells = getCellsFromRange(worksheet, startRef, endRef).filter(\n cell => cell.type !== ExcelJS.ValueType.Formula,\n );\n let result: number | string | \"\";\n const areAllDates = areAllValuesDates(cells);\n switch (subtotalType) {\n case 3: // COUNTA\n result = cells.length;\n break;\n case 9: // SUM\n result = cells.reduce((sum, cell) => {\n const n =\n typeof cell.value === \"number\"\n ? cell.value\n : typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : NaN;\n return !isNaN(n)\n ? (typeof sum === \"number\"\n ? sum\n : typeof sum === \"string\"\n ? parseFloat(sum)\n : 0) + n\n : sum;\n }, 0);\n break;\n case 4: // MAX\n result = cells.length\n ? Math.max(\n ...cells.map(cell => {\n if (cell.type === ExcelJS.ValueType.Date) {\n return cell.value instanceof Date\n ? cell.value.getTime()\n : -Infinity;\n }\n return typeof cell.value === \"number\"\n ? cell.value\n : (typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : -Infinity) || -Infinity;\n }),\n )\n : \"\";\n break;\n case 5: // MIN\n result = cells.length\n ? Math.min(\n ...cells.map(cell => {\n if (cell.type === ExcelJS.ValueType.Date) {\n return cell.value instanceof Date\n ? cell.value.getTime()\n : Infinity;\n }\n return typeof cell.value === \"number\"\n ? cell.value\n : (typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : Infinity) || Infinity;\n }),\n )\n : \"\";\n break;\n case 1: {\n // AVERAGE\n const nums = cells\n .map(cell =>\n typeof cell.value === \"number\"\n ? cell.value\n : typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : NaN,\n )\n .filter(v => !isNaN(v));\n result = nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : \"\";\n break;\n }\n default: {\n if (cell.result != null && typeof cell.result !== \"object\") {\n result = cell.result;\n } else {\n result =\n cell.text ||\n (typeof cell.value === \"string\" || typeof cell.value === \"number\"\n ? cell.value\n : \"\") ||\n \"\";\n }\n break;\n }\n }\n\n if (areAllDates) {\n return {\n value: result,\n text: formatDate(new Date(result), webupManagerData),\n type: \"date\",\n };\n } else if (typeof result === \"number\" && cell.numFmt) {\n return {\n value: result,\n text: formatNumber(result, cell.numFmt, webupManagerData),\n type: \"number\",\n };\n }\n return {\n value: result,\n text: result.toString(),\n type: typeof result === \"number\" ? \"number\" : \"string\",\n };\n};\n\n/**\n * Evaluates a standard Excel formula from a given cell by replacing cell references\n * with their actual values from the worksheet and then computing the result.\n *\n * - Replaces cell references (e.g., \"A1\") in the formula with their corresponding values.\n * - Handles different cell value types: number, string, formula result, and date.\n * - Evaluates the resulting formula string using a safe function context.\n * - Applies number formatting if the result is numeric and a format is specified.\n * - Returns the computed value and its type (\"number\" or \"string\").\n *\n * @param cell - The ExcelJS cell containing the formula to evaluate.\n * @param worksheet - The ExcelJS worksheet object for resolving cell references.\n * @param webupManagerData - Additional data used for number formatting.\n * @returns An object containing the evaluated value and its type.\n */\nexport const evaluateStandardFormula = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n): CellValueProps => {\n const formula = cell.formula;\n const formulaWithSolvedVariables = formula.replace(/([A-Z]+\\d+)/g, ref => {\n try {\n const refCell = worksheet.getCell(ref);\n if (refCell) {\n if (refCell.type === ExcelJS.ValueType.Number) {\n return refCell.value?.toString() ?? \"0\";\n } else if (refCell.type === ExcelJS.ValueType.String) {\n // If the cell contains text, return as is (no quotes) for JS compatibility\n return refCell.value?.toString() ?? \"\";\n } else if (refCell.type === ExcelJS.ValueType.Formula) {\n return getCellValueData(\n refCell,\n worksheet,\n webupManagerData,\n ).value.toString();\n } else if (\n refCell.type === ExcelJS.ValueType.Date &&\n refCell.value instanceof Date\n ) {\n return refCell.value.getTime().toString();\n } else {\n return refCell.value?.toString() ?? \"0\";\n }\n }\n } catch {\n return \"0\";\n }\n return \"0\";\n });\n const result = calculateExpression(formulaWithSolvedVariables);\n // If the result is a number and a format is specified, apply it\n if (typeof result === \"number\" && cell.numFmt) {\n return {\n value: result,\n text: formatNumber(result, cell.numFmt, webupManagerData),\n type: \"number\",\n };\n }\n return {\n value: result,\n text: result != null ? result.toString() : cell.formula,\n type: typeof result === \"number\" ? \"number\" : \"string\",\n };\n};\n\n/**\n * Extracts and formats the value of a given ExcelJS cell based on its type.\n */\nexport const getCellValueData = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n): CellValueProps => {\n if (\n cell.type === ExcelJS.ValueType.Formula &&\n typeof cell.formula === \"string\"\n ) {\n const subtotalMatch = cell.formula.match(\n /^SUBTOTAL\\((\\d+)\\s*,\\s*([A-Z]+\\d+):([A-Z]+\\d+)\\)/i,\n );\n if (subtotalMatch) {\n return handleSubtotalFormula(\n cell,\n worksheet,\n webupManagerData,\n subtotalMatch,\n );\n } else {\n return evaluateStandardFormula(cell, worksheet, webupManagerData);\n }\n } else if (\n cell.type === ExcelJS.ValueType.Date &&\n cell.value instanceof Date\n ) {\n return {\n value: cell.value,\n text: formatDate(cell.value, webupManagerData),\n type: \"date\",\n };\n } else if (cell.type === ExcelJS.ValueType.Number) {\n return {\n value: cell.value as number,\n text: formatNumber(\n cell.value as number,\n cell.numFmt ?? 0,\n webupManagerData,\n ),\n type: \"number\",\n };\n } else {\n // Fallback to text or value if available, otherwise empty string\n const value = cell?.text || cell?.value?.toString() || \"\";\n return {\n value: value,\n text: value,\n type: \"string\",\n };\n }\n};\n"]}
@@ -0,0 +1,17 @@
1
+ import * as jsPDFModule from "jspdf";
2
+ import ExcelJS from "exceljs";
3
+ import { WebupManagerData } from "../../index.js";
4
+ import { ConverterContext } from "../../types/converter.js";
5
+ /**
6
+ * Converts an ExcelJS worksheet into a PDF document using jsPDF and autoTable.
7
+ *
8
+ * This function extracts visible headers and data from the provided worksheet,
9
+ * applies cell styles, simulates Excel cell overflow, and calculates the optimal
10
+ * font size for the table. It then generates a PDF document with the formatted
11
+ * table and returns the resulting jsPDF instance.
12
+ *
13
+ * @param worksheet - The ExcelJS worksheet to convert to PDF.
14
+ * @param webupManagerData - Additional data required for extracting worksheet content.
15
+ * @returns A Promise that resolves to a jsPDF document containing the worksheet data as a table.
16
+ */
17
+ export declare const dataTableToPdfDoc: (worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData, context: ConverterContext) => Promise<jsPDFModule.jsPDF>;