@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,200 @@
1
+ import * as jsPDFModule from "jspdf";
2
+ import autoTable from "jspdf-autotable";
3
+ import { convertColorToRgb } from "../../utils/commons-utility.js";
4
+ import { getCellValueData } from "./formulas-helper.js";
5
+ import { getAutoTableOptions } from "./autotable-renderer.js";
6
+ import { isGroupedCell } from "../excel/commons.js";
7
+ /**
8
+ * Converts an ExcelJS worksheet into a PDF document using jsPDF and autoTable.
9
+ *
10
+ * This function extracts visible headers and data from the provided worksheet,
11
+ * applies cell styles, simulates Excel cell overflow, and calculates the optimal
12
+ * font size for the table. It then generates a PDF document with the formatted
13
+ * table and returns the resulting jsPDF instance.
14
+ *
15
+ * @param worksheet - The ExcelJS worksheet to convert to PDF.
16
+ * @param webupManagerData - Additional data required for extracting worksheet content.
17
+ * @returns A Promise that resolves to a jsPDF document containing the worksheet data as a table.
18
+ */
19
+ export const dataTableToPdfDoc = async (worksheet, webupManagerData, context) => {
20
+ const doc = new jsPDFModule.jsPDF({ orientation: "landscape" });
21
+ doc.setFont("helvetica", "normal");
22
+ doc.setFontSize(10);
23
+ // Extract headers and column indexes
24
+ const { visibleHeaders, visibleColumnIndexes } = extractVisibleHeadersAndIndexes(worksheet);
25
+ // Extract data and cell styles separately
26
+ const data = extractData(worksheet, visibleColumnIndexes, webupManagerData);
27
+ const cellStyles = extractStyles(worksheet, visibleColumnIndexes, data);
28
+ // Post-process data to simulate Excel overflow
29
+ postProcessExcelOverflow(data, cellStyles);
30
+ // Calculate optimal font size based on data
31
+ const pageWidth = doc.internal.pageSize.getWidth();
32
+ const optimalFontSize = calculateOptimalFontSize(data, visibleHeaders, pageWidth);
33
+ autoTable(doc, getAutoTableOptions(visibleHeaders, data, optimalFontSize, cellStyles, context));
34
+ return doc;
35
+ };
36
+ // Function to calculate the optimal font size
37
+ const calculateOptimalFontSize = (data, visibleHeaders, pageWidth) => {
38
+ const maxSamples = Math.min(100, data.length); // Analyze max 100 rows
39
+ const availableWidth = pageWidth - 20; // Margins
40
+ const numColumns = visibleHeaders.length;
41
+ // If there are few columns, we can allow a larger font size
42
+ if (numColumns <= 3) {
43
+ return 10;
44
+ }
45
+ // Calculate more accurate statistics per column
46
+ const columnStats = visibleHeaders.map((header, colIndex) => {
47
+ const lengths = [header.length];
48
+ // Collect all cell lengths for this column
49
+ for (let rowIndex = 0; rowIndex < maxSamples; rowIndex++) {
50
+ if (data[rowIndex] && data[rowIndex][colIndex]) {
51
+ const cellLength = data[rowIndex][colIndex].text.replace(/\u00A0/g, " ").length;
52
+ lengths.push(cellLength);
53
+ }
54
+ }
55
+ lengths.sort((a, b) => a - b);
56
+ // Use the 90th percentile instead of the maximum to be less conservative
57
+ const percentile90Index = Math.floor(lengths.length * 0.9);
58
+ const effectiveWidth = lengths[percentile90Index] || lengths[lengths.length - 1];
59
+ // The average length to balance very long columns with short ones
60
+ const avgLength = lengths.reduce((sum, len) => sum + len, 0) / lengths.length;
61
+ return {
62
+ max: Math.max(...lengths),
63
+ p90: effectiveWidth,
64
+ avg: avgLength,
65
+ min: Math.min(...lengths),
66
+ };
67
+ });
68
+ // Use a mixed strategy: combine 90th percentile with weighted average
69
+ const estimatedColumnWidths = columnStats.map(stats => {
70
+ // Weight the average more than the 90th percentile to be less pessimistic
71
+ const weightedWidth = stats.avg * 0.7 + stats.p90 * 0.3;
72
+ return Math.max(weightedWidth, 3); // Minimum width of 3 characters
73
+ });
74
+ // Try different font sizes starting from the largest
75
+ for (let testFontSize = 10; testFontSize >= 4; testFontSize -= 0.5) {
76
+ // More optimistic factor based on font size
77
+ const charWidthFactor = testFontSize >= 8 ? 3.2 : testFontSize >= 6 ? 2.8 : 2.5;
78
+ const estimatedTotalWidth = estimatedColumnWidths.reduce((sum, width) => sum + width * charWidthFactor, 0);
79
+ // Add a margin for columns (space between columns)
80
+ const totalWidthWithMargins = estimatedTotalWidth + numColumns * 10; // 10px between columns
81
+ if (totalWidthWithMargins <= availableWidth) {
82
+ return testFontSize;
83
+ }
84
+ }
85
+ return 4; // Minimum font size if nothing fits
86
+ };
87
+ /**
88
+ * Extracts visible headers and their column indexes from the worksheet (ignoring hidden columns).
89
+ */
90
+ const extractVisibleHeadersAndIndexes = (worksheet) => {
91
+ const headerRow = worksheet.getRow(1);
92
+ const visibleHeaders = [];
93
+ const visibleColumnIndexes = [];
94
+ headerRow.eachCell({ includeEmpty: true }, (cell, colNumber) => {
95
+ const column = worksheet.getColumn(colNumber);
96
+ if (!column.hidden) {
97
+ visibleHeaders.push(cell?.toString() ?? "");
98
+ visibleColumnIndexes.push(colNumber);
99
+ }
100
+ });
101
+ return { visibleHeaders, visibleColumnIndexes };
102
+ };
103
+ /**
104
+ * Extracts the data from the worksheet for the given visible columns, formatting dates and preserving spaces.
105
+ */
106
+ const extractData = (worksheet, visibleColumnIndexes, webupManagerData) => {
107
+ const data = [];
108
+ worksheet.eachRow((row, rowIndex) => {
109
+ if (rowIndex === 1)
110
+ return; // Skip header
111
+ const rowData = [];
112
+ visibleColumnIndexes.forEach(colIdx => {
113
+ const cell = row.getCell(colIdx);
114
+ const cellValue = getCellValueData(cell, worksheet, webupManagerData);
115
+ rowData.push(cellValue);
116
+ });
117
+ data.push(rowData);
118
+ });
119
+ return data;
120
+ };
121
+ /**
122
+ * Extracts the cell styles (font, color, fill) for the given visible columns from the worksheet.
123
+ */
124
+ const extractStyles = (worksheet, visibleColumnIndexes, rawData) => {
125
+ const cellStyles = [];
126
+ worksheet.eachRow((row, rowIndex) => {
127
+ if (rowIndex === 1)
128
+ return; // Skip header
129
+ const rowStyles = [];
130
+ visibleColumnIndexes.forEach((colIdx, index) => {
131
+ const cell = row.getCell(colIdx);
132
+ const cellStyle = {};
133
+ // Font
134
+ if (cell.font) {
135
+ if (cell.font.bold && cell.font.italic) {
136
+ cellStyle.fontStyle = "bolditalic";
137
+ }
138
+ else if (cell.font.bold) {
139
+ cellStyle.fontStyle = "bold";
140
+ }
141
+ else if (cell.font.italic) {
142
+ cellStyle.fontStyle = "italic";
143
+ }
144
+ else {
145
+ cellStyle.fontStyle = "normal";
146
+ }
147
+ if (cell.font.color?.argb) {
148
+ const color = cell.font.color.argb;
149
+ const [r, g, b] = convertColorToRgb(color);
150
+ if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
151
+ cellStyle.textColor = [r, g, b];
152
+ }
153
+ }
154
+ }
155
+ // Fill (background color)
156
+ if (cell.fill &&
157
+ cell.fill.type === "pattern" &&
158
+ cell.fill.fgColor?.argb) {
159
+ const color = cell.fill.fgColor.argb;
160
+ const [r, g, b] = convertColorToRgb(color);
161
+ if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
162
+ cellStyle.fillColor = [r, g, b];
163
+ }
164
+ }
165
+ // Align right if the cell is numeric
166
+ if (rawData[rowIndex - 2][index].type === "number") {
167
+ cellStyle.halign = "right";
168
+ }
169
+ if (isGroupedCell(cell)) {
170
+ cellStyle.cellWidth = "wrap";
171
+ cellStyle.overflow = "visible";
172
+ }
173
+ rowStyles.push(cellStyle);
174
+ });
175
+ cellStyles.push(rowStyles);
176
+ });
177
+ return cellStyles;
178
+ };
179
+ /**
180
+ * Post-processes the data and cell styles to simulate Excel's text overflow behavior.
181
+ * If a cell has long text and the next cell is empty, the width is set to auto.
182
+ */
183
+ const postProcessExcelOverflow = (data, cellStyles) => {
184
+ for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
185
+ for (let colIndex = 0; colIndex < data[rowIndex].length - 1; colIndex++) {
186
+ const currentCell = data[rowIndex][colIndex];
187
+ const nextCell = data[rowIndex][colIndex + 1];
188
+ // If the current cell has long text and the next one is empty or only spaces
189
+ if (currentCell &&
190
+ currentCell.text.length > 15 &&
191
+ (!nextCell || nextCell.text.trim() === "")) {
192
+ // Extend the width of the current cell
193
+ if (!cellStyles[rowIndex][colIndex].cellWidth) {
194
+ cellStyles[rowIndex][colIndex].cellWidth = "auto";
195
+ }
196
+ }
197
+ }
198
+ }
199
+ };
200
+ //# sourceMappingURL=matrix-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrix-converter.js","sourceRoot":"","sources":["../../../src/converters/pdf/matrix-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AAErC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE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ule from \"jspdf\";\nimport ExcelJS from \"exceljs\";\nimport autoTable from \"jspdf-autotable\";\nimport { WebupManagerData } from \"../../index.js\";\nimport { CellStyleData, CellValueProps } from \"./pdf-converter.types.js\";\nimport { convertColorToRgb } from \"../../utils/commons-utility.js\";\nimport { getCellValueData } from \"./formulas-helper.js\";\nimport { getAutoTableOptions } from \"./autotable-renderer.js\";\nimport { isGroupedCell } from \"../excel/commons.js\";\nimport { ConverterContext } from \"../../types/converter.js\";\n\n/**\n * Converts an ExcelJS worksheet into a PDF document using jsPDF and autoTable.\n *\n * This function extracts visible headers and data from the provided worksheet,\n * applies cell styles, simulates Excel cell overflow, and calculates the optimal\n * font size for the table. It then generates a PDF document with the formatted\n * table and returns the resulting jsPDF instance.\n *\n * @param worksheet - The ExcelJS worksheet to convert to PDF.\n * @param webupManagerData - Additional data required for extracting worksheet content.\n * @returns A Promise that resolves to a jsPDF document containing the worksheet data as a table.\n */\nexport const dataTableToPdfDoc = async (\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n context: ConverterContext,\n): Promise<jsPDFModule.jsPDF> => {\n const doc = new jsPDFModule.jsPDF({ orientation: \"landscape\" });\n doc.setFont(\"helvetica\", \"normal\");\n doc.setFontSize(10);\n\n // Extract headers and column indexes\n const { visibleHeaders, visibleColumnIndexes } =\n extractVisibleHeadersAndIndexes(worksheet);\n\n // Extract data and cell styles separately\n const data = extractData(worksheet, visibleColumnIndexes, webupManagerData);\n const cellStyles = extractStyles(worksheet, visibleColumnIndexes, data);\n\n // Post-process data to simulate Excel overflow\n postProcessExcelOverflow(data, cellStyles);\n\n // Calculate optimal font size based on data\n const pageWidth = doc.internal.pageSize.getWidth();\n const optimalFontSize = calculateOptimalFontSize(\n data,\n visibleHeaders,\n pageWidth,\n );\n\n autoTable(\n doc,\n getAutoTableOptions(\n visibleHeaders,\n data,\n optimalFontSize,\n cellStyles,\n context,\n ),\n );\n\n return doc;\n};\n\n// Function to calculate the optimal font size\nconst calculateOptimalFontSize = (\n data: CellValueProps[][],\n visibleHeaders: string[],\n pageWidth: number,\n): number => {\n const maxSamples = Math.min(100, data.length); // Analyze max 100 rows\n const availableWidth = pageWidth - 20; // Margins\n const numColumns = visibleHeaders.length;\n\n // If there are few columns, we can allow a larger font size\n if (numColumns <= 3) {\n return 10;\n }\n\n // Calculate more accurate statistics per column\n const columnStats = visibleHeaders.map((header, colIndex) => {\n const lengths: number[] = [header.length];\n\n // Collect all cell lengths for this column\n for (let rowIndex = 0; rowIndex < maxSamples; rowIndex++) {\n if (data[rowIndex] && data[rowIndex][colIndex]) {\n const cellLength = data[rowIndex][colIndex].text.replace(\n /\\u00A0/g,\n \" \",\n ).length;\n lengths.push(cellLength);\n }\n }\n\n lengths.sort((a, b) => a - b);\n\n // Use the 90th percentile instead of the maximum to be less conservative\n const percentile90Index = Math.floor(lengths.length * 0.9);\n const effectiveWidth =\n lengths[percentile90Index] || lengths[lengths.length - 1];\n\n // The average length to balance very long columns with short ones\n const avgLength =\n lengths.reduce((sum, len) => sum + len, 0) / lengths.length;\n\n return {\n max: Math.max(...lengths),\n p90: effectiveWidth,\n avg: avgLength,\n min: Math.min(...lengths),\n };\n });\n\n // Use a mixed strategy: combine 90th percentile with weighted average\n const estimatedColumnWidths = columnStats.map(stats => {\n // Weight the average more than the 90th percentile to be less pessimistic\n const weightedWidth = stats.avg * 0.7 + stats.p90 * 0.3;\n return Math.max(weightedWidth, 3); // Minimum width of 3 characters\n });\n\n // Try different font sizes starting from the largest\n for (let testFontSize = 10; testFontSize >= 4; testFontSize -= 0.5) {\n // More optimistic factor based on font size\n const charWidthFactor =\n testFontSize >= 8 ? 3.2 : testFontSize >= 6 ? 2.8 : 2.5;\n\n const estimatedTotalWidth = estimatedColumnWidths.reduce(\n (sum, width) => sum + width * charWidthFactor,\n 0,\n );\n\n // Add a margin for columns (space between columns)\n const totalWidthWithMargins = estimatedTotalWidth + numColumns * 10; // 10px between columns\n\n if (totalWidthWithMargins <= availableWidth) {\n return testFontSize;\n }\n }\n\n return 4; // Minimum font size if nothing fits\n};\n\n/**\n * Extracts visible headers and their column indexes from the worksheet (ignoring hidden columns).\n */\nconst extractVisibleHeadersAndIndexes = (\n worksheet: ExcelJS.Worksheet,\n): { visibleHeaders: string[]; visibleColumnIndexes: number[] } => {\n const headerRow = worksheet.getRow(1);\n const visibleHeaders: string[] = [];\n const visibleColumnIndexes: number[] = [];\n headerRow.eachCell({ includeEmpty: true }, (cell, colNumber) => {\n const column = worksheet.getColumn(colNumber);\n if (!column.hidden) {\n visibleHeaders.push(cell?.toString() ?? \"\");\n visibleColumnIndexes.push(colNumber);\n }\n });\n return { visibleHeaders, visibleColumnIndexes };\n};\n\n/**\n * Extracts the data from the worksheet for the given visible columns, formatting dates and preserving spaces.\n */\nconst extractData = (\n worksheet: ExcelJS.Worksheet,\n visibleColumnIndexes: number[],\n webupManagerData: WebupManagerData,\n): CellValueProps[][] => {\n const data: CellValueProps[][] = [];\n worksheet.eachRow((row, rowIndex) => {\n if (rowIndex === 1) return; // Skip header\n const rowData: CellValueProps[] = [];\n visibleColumnIndexes.forEach(colIdx => {\n const cell = row.getCell(colIdx);\n const cellValue = getCellValueData(cell, worksheet, webupManagerData);\n rowData.push(cellValue);\n });\n data.push(rowData);\n });\n return data;\n};\n\n/**\n * Extracts the cell styles (font, color, fill) for the given visible columns from the worksheet.\n */\nconst extractStyles = (\n worksheet: ExcelJS.Worksheet,\n visibleColumnIndexes: number[],\n rawData: CellValueProps[][],\n): CellStyleData[][] => {\n const cellStyles: CellStyleData[][] = [];\n worksheet.eachRow((row, rowIndex) => {\n if (rowIndex === 1) return; // Skip header\n const rowStyles: CellStyleData[] = [];\n visibleColumnIndexes.forEach((colIdx, index) => {\n const cell = row.getCell(colIdx);\n const cellStyle: CellStyleData = {};\n // Font\n if (cell.font) {\n if (cell.font.bold && cell.font.italic) {\n cellStyle.fontStyle = \"bolditalic\";\n } else if (cell.font.bold) {\n cellStyle.fontStyle = \"bold\";\n } else if (cell.font.italic) {\n cellStyle.fontStyle = \"italic\";\n } else {\n cellStyle.fontStyle = \"normal\";\n }\n if (cell.font.color?.argb) {\n const color = cell.font.color.argb;\n const [r, g, b] = convertColorToRgb(color);\n if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {\n cellStyle.textColor = [r, g, b];\n }\n }\n }\n // Fill (background color)\n if (\n cell.fill &&\n cell.fill.type === \"pattern\" &&\n cell.fill.fgColor?.argb\n ) {\n const color = cell.fill.fgColor.argb;\n const [r, g, b] = convertColorToRgb(color);\n if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {\n cellStyle.fillColor = [r, g, b];\n }\n }\n // Align right if the cell is numeric\n if (rawData[rowIndex - 2][index].type === \"number\") {\n cellStyle.halign = \"right\";\n }\n\n if (isGroupedCell(cell)) {\n cellStyle.cellWidth = \"wrap\";\n cellStyle.overflow = \"visible\";\n }\n\n rowStyles.push(cellStyle);\n });\n cellStyles.push(rowStyles);\n });\n return cellStyles;\n};\n\n/**\n * Post-processes the data and cell styles to simulate Excel's text overflow behavior.\n * If a cell has long text and the next cell is empty, the width is set to auto.\n */\nconst postProcessExcelOverflow = (\n data: CellValueProps[][],\n cellStyles: CellStyleData[][],\n) => {\n for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {\n for (let colIndex = 0; colIndex < data[rowIndex].length - 1; colIndex++) {\n const currentCell = data[rowIndex][colIndex];\n const nextCell = data[rowIndex][colIndex + 1];\n\n // If the current cell has long text and the next one is empty or only spaces\n if (\n currentCell &&\n currentCell.text.length > 15 &&\n (!nextCell || nextCell.text.trim() === \"\")\n ) {\n // Extend the width of the current cell\n if (!cellStyles[rowIndex][colIndex].cellWidth) {\n cellStyles[rowIndex][colIndex].cellWidth = \"auto\";\n }\n }\n }\n }\n};\n"]}
@@ -0,0 +1,13 @@
1
+ export interface CellStyleData {
2
+ fontStyle?: "normal" | "bold" | "italic" | "bolditalic";
3
+ textColor?: [number, number, number];
4
+ fillColor?: [number, number, number];
5
+ cellWidth?: "auto" | "wrap";
6
+ halign?: "left" | "right" | "center";
7
+ overflow?: "linebreak" | "visible";
8
+ }
9
+ export interface CellValueProps {
10
+ value: string | number | Date;
11
+ text: string;
12
+ type: "string" | "number" | "date";
13
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pdf-converter.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-converter.types.js","sourceRoot":"","sources":["../../../src/converters/pdf/pdf-converter.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface CellStyleData {\n fontStyle?: \"normal\" | \"bold\" | \"italic\" | \"bolditalic\";\n textColor?: [number, number, number];\n fillColor?: [number, number, number];\n cellWidth?: \"auto\" | \"wrap\";\n halign?: \"left\" | \"right\" | \"center\";\n overflow?: \"linebreak\" | \"visible\";\n}\n\nexport interface CellValueProps {\n // The raw value of the cell, can be string, number, Date\n value: string | number | Date;\n // Formatted representation of the value\n text: string;\n type: \"string\" | \"number\" | \"date\";\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import * as jsPDFModule from "jspdf";
2
+ import { SmeupSch } from "../../types/data-structures/smeupSch.js";
3
+ export declare const schedaToPdfDoc: (sch: SmeupSch) => Promise<jsPDFModule.jsPDF>;
@@ -0,0 +1,99 @@
1
+ import * as jsPDFModule from "jspdf";
2
+ import { dataTableToChart } from "../images/charts-generator.js";
3
+ import { Shapes } from "../../types/component.js";
4
+ const jsPDF = jsPDFModule.jsPDF;
5
+ export const schedaToPdfDoc = async (sch) => {
6
+ const doc = new jsPDF({ orientation: "landscape" });
7
+ const x = 10;
8
+ const y = 10;
9
+ doc.setFont("Helvetica", "normal", 10);
10
+ const pageWidth = doc.internal.pageSize.getWidth();
11
+ const pageHeight = doc.internal.pageSize.getHeight();
12
+ const layout = sch.layout || "column";
13
+ const sections = sch.sections || [];
14
+ let offsetX = x;
15
+ let offsetY = y;
16
+ for (const section of filterSections(sections)) {
17
+ let sectionW = pageWidth - 2 * x;
18
+ let sectionH = (pageHeight - 2 * y) / sections.length;
19
+ if (layout === "row") {
20
+ sectionW = (pageWidth - 2 * x) / sections.length;
21
+ sectionH = pageHeight - 2 * y;
22
+ }
23
+ await renderSection(doc, section, layout, offsetX, offsetY, sectionW, sectionH);
24
+ if (layout === "row")
25
+ offsetX += sectionW;
26
+ else
27
+ offsetY += sectionH;
28
+ }
29
+ return doc;
30
+ };
31
+ // Helper to render a section
32
+ const renderSection = async (doc, section, parentLayout, parentX, parentY, parentW, parentH) => {
33
+ const layout = section.layout || parentLayout;
34
+ const title = section.components?.[0]?.title || "";
35
+ const dim = section.dim ? parseFloat(section.dim) : undefined;
36
+ let sectionW = parentW;
37
+ let sectionH = parentH;
38
+ if (dim) {
39
+ if (layout === "row")
40
+ sectionW = parentW * (dim / 100);
41
+ else
42
+ sectionH = parentH * (dim / 100);
43
+ }
44
+ // Draw title
45
+ doc.text(title, parentX + 2, parentY + 7);
46
+ // Draw component type (assume one component)
47
+ if (section.components && section.components.length > 0) {
48
+ //const compType = section.components[0].type;
49
+ const data = section.components[0].data || {};
50
+ const options = section.components[0].options?.EXA?.[0];
51
+ if (options == null) {
52
+ throw new Error("Options is undefined or null for component");
53
+ }
54
+ const image = await dataTableToChart(data, "line", {
55
+ Width: String((sectionW - 4) * 10),
56
+ Height: String((sectionH - 20) * 10),
57
+ ...options,
58
+ });
59
+ const base64Image = image.toString("base64");
60
+ doc.addImage(`data:image/jpg;base64,${base64Image}`, "JPG", parentX + 2, parentY + 15, sectionW - 4, sectionH - 20, undefined);
61
+ }
62
+ // Draw child sections
63
+ if (section.sections && section.sections.length > 0) {
64
+ let offsetX = parentX;
65
+ let offsetY = parentY + 20;
66
+ const filteredSections = filterSections(section.sections);
67
+ for (let i = 0; i < filteredSections.length; i++) {
68
+ const sub = filteredSections[i];
69
+ let subW = sectionW;
70
+ let subH = sectionH;
71
+ if (layout === "row")
72
+ subW = sectionW / section.sections.length;
73
+ else
74
+ subH = sectionH / section.sections.length;
75
+ await renderSection(doc, sub, layout, offsetX, offsetY, subW, subH);
76
+ if (layout === "row")
77
+ offsetX += subW;
78
+ else
79
+ offsetY += subH;
80
+ }
81
+ }
82
+ };
83
+ const filterSections = (sections) => {
84
+ return sections.filter(section => {
85
+ // Filter out sections that are empty or have no components
86
+ if (section.components &&
87
+ section.components.length > 0 &&
88
+ section.components[0].type === Shapes.EXA) {
89
+ return true;
90
+ }
91
+ // Recursively filter child sections
92
+ if (section.sections && section.sections.length > 0) {
93
+ section.sections = filterSections(section.sections);
94
+ return section.sections.length > 0;
95
+ }
96
+ return false;
97
+ });
98
+ };
99
+ //# sourceMappingURL=sch-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sch-converter.js","sourceRoot":"","sources":["../../../src/converters/pdf/sch-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAMlD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;AAEhC,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,GAAa,EACe,EAAE;IAC9B,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;IACpD,MAAM,CAAC,GAAG,EAAE,CAAC;IACb,MAAM,CAAC,GAAG,EAAE,CAAC;IACb,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvC,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;IAErD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC;IACtC,MAAM,QAAQ,GAAG,GAAG,CAAC,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,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,EACzC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,oCAAoC;QACpC,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpD,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACpD,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import * as jsPDFModule from \"jspdf\";\nimport { dataTableToChart } from \"../images/charts-generator.js\";\nimport { Shapes } from \"../../types/component.js\";\nimport { SmeupDataTable } from \"../../types/data-structures/smeupDataTable.js\";\nimport {\n SmeupSch,\n SmeupSchSection,\n} from \"../../types/data-structures/smeupSch.js\";\nconst jsPDF = jsPDFModule.jsPDF;\n\nexport const schedaToPdfDoc = async (\n sch: SmeupSch,\n): Promise<jsPDFModule.jsPDF> => {\n const doc = new jsPDF({ orientation: \"landscape\" });\n const x = 10;\n const y = 10;\n doc.setFont(\"Helvetica\", \"normal\", 10);\n const pageWidth = doc.internal.pageSize.getWidth();\n const pageHeight = doc.internal.pageSize.getHeight();\n\n const layout = sch.layout || \"column\";\n const sections = sch.sections || [];\n let offsetX = x;\n let offsetY = y;\n for (const section of filterSections(sections)) {\n let sectionW = pageWidth - 2 * x;\n let sectionH = (pageHeight - 2 * y) / sections.length;\n if (layout === \"row\") {\n sectionW = (pageWidth - 2 * x) / sections.length;\n sectionH = pageHeight - 2 * y;\n }\n await renderSection(\n doc,\n section,\n layout,\n offsetX,\n offsetY,\n sectionW,\n sectionH,\n );\n if (layout === \"row\") offsetX += sectionW;\n else offsetY += sectionH;\n }\n\n return doc;\n};\n\n// Helper to render a section\nconst renderSection = async (\n doc: jsPDFModule.jsPDF,\n section: SmeupSchSection,\n parentLayout: string,\n parentX: number,\n parentY: number,\n parentW: number,\n parentH: number,\n): Promise<void> => {\n const layout = section.layout || parentLayout;\n const title = section.components?.[0]?.title || \"\";\n const dim = section.dim ? parseFloat(section.dim) : undefined;\n let sectionW = parentW;\n let sectionH = parentH;\n if (dim) {\n if (layout === \"row\") sectionW = parentW * (dim / 100);\n else sectionH = parentH * (dim / 100);\n }\n // Draw title\n doc.text(title, parentX + 2, parentY + 7);\n // Draw component type (assume one component)\n if (section.components && section.components.length > 0) {\n //const compType = section.components[0].type;\n const data = section.components[0].data || ({} as SmeupDataTable);\n const options = section.components[0].options?.EXA?.[0];\n if (options == null) {\n throw new Error(\"Options is undefined or null for component\");\n }\n const image = await dataTableToChart(data as SmeupDataTable, \"line\", {\n Width: String((sectionW - 4) * 10),\n Height: String((sectionH - 20) * 10),\n ...options,\n });\n const base64Image = image.toString(\"base64\");\n doc.addImage(\n `data:image/jpg;base64,${base64Image}`,\n \"JPG\",\n parentX + 2,\n parentY + 15,\n sectionW - 4,\n sectionH - 20,\n undefined,\n );\n }\n // Draw child sections\n if (section.sections && section.sections.length > 0) {\n let offsetX = parentX;\n let offsetY = parentY + 20;\n const filteredSections = filterSections(section.sections);\n for (let i = 0; i < filteredSections.length; i++) {\n const sub = filteredSections[i];\n let subW = sectionW;\n let subH = sectionH;\n if (layout === \"row\") subW = sectionW / section.sections!.length;\n else subH = sectionH / section.sections!.length;\n await renderSection(doc, sub, layout, offsetX, offsetY, subW, subH);\n if (layout === \"row\") offsetX += subW;\n else offsetY += subH;\n }\n }\n};\n\nconst filterSections = (sections: SmeupSchSection[]): SmeupSchSection[] => {\n return sections.filter(section => {\n // Filter out sections that are empty or have no components\n if (\n section.components &&\n section.components.length > 0 &&\n section.components[0].type === Shapes.EXA\n ) {\n return true;\n }\n // Recursively filter child sections\n if (section.sections && section.sections.length > 0) {\n section.sections = filterSections(section.sections);\n return section.sections.length > 0;\n }\n return false;\n });\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import { SmeupDataTable } from "../types/data-structures/smeupDataTable.js";
2
+ import { SmeupSch } from "../types/data-structures/smeupSch.js";
3
+ import { WebupManagerData, GenericObject } from "../types/index.js";
4
+ export declare const schedaToPdfData: (sch: SmeupSch, webupManagerData: WebupManagerData) => Promise<Buffer>;
5
+ export declare const dataTableToPdfData: (component: {
6
+ smeupDataTable: SmeupDataTable;
7
+ props: GenericObject;
8
+ }, webupManagerData: WebupManagerData) => Promise<Buffer | Uint8Array>;
@@ -0,0 +1,54 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import { SupportedExportFormats, } from "../types/index.js";
3
+ import { convertToBuffer } from "../utils/commons-utility.js";
4
+ import { dataTableToExcelWorkbook } from "./excel/matrix-converter.js";
5
+ import { dataTableToPdfDoc } from "./pdf/matrix-converter.js";
6
+ import { schedaToPdfDoc } from "./pdf/sch-converter.js";
7
+ import { PDFDocument } from "pdf-lib";
8
+ import { createCoverPdf } from "./pdf/cover-renderer.js";
9
+ import { logoBase64 } from "../assets/gfx-data.js";
10
+ export const schedaToPdfData = async (sch, webupManagerData) => {
11
+ const doc = await schedaToPdfDoc(sch);
12
+ return Buffer.from(doc.output("arraybuffer"));
13
+ };
14
+ export const dataTableToPdfData = async (component, webupManagerData) => {
15
+ const workbook = dataTableToExcelWorkbook(component, SupportedExportFormats.XLSX, webupManagerData);
16
+ const worksheet = workbook.getWorksheet(1);
17
+ if (worksheet) {
18
+ const title = component.smeupDataTable.cover?.titles?.["T01"] ?? "";
19
+ const subtitle = component.smeupDataTable.cover?.titles?.["T02"] ?? "";
20
+ const subtitle2 = component.smeupDataTable.cover?.titles?.["T03"] ?? "";
21
+ const image = component.smeupDataTable.cover?.image ?? "";
22
+ const logo = component.smeupDataTable.cover?.logo ?? logoBase64;
23
+ const cover = createCoverPdf(image, logo, title, subtitle, subtitle2);
24
+ const pdfDoc = await dataTableToPdfDoc(worksheet, webupManagerData, {
25
+ logoBase64: logo,
26
+ title: title,
27
+ subtitle: subtitle,
28
+ });
29
+ const pdfBuffer = pdfDoc.output("arraybuffer");
30
+ return convertToBuffer(await appendPdfDocs([cover, pdfBuffer]));
31
+ }
32
+ else {
33
+ throw new Error("Worksheet not found in the workbook");
34
+ }
35
+ };
36
+ /**
37
+ * Unisce più PDF (in formato ArrayBuffer/Uint8Array/Buffer) in un unico PDF.
38
+ * @param pdfBuffers Array di buffer PDF (es. ottenuti da jsPDF.output("arraybuffer"))
39
+ * @returns Buffer del PDF unito
40
+ */
41
+ const appendPdfDocs = async (pdfBuffers) => {
42
+ if (!pdfBuffers.length)
43
+ throw new Error("No PDF buffers to append");
44
+ // Crea un nuovo documento PDF vuoto
45
+ const mergedPdf = await PDFDocument.create();
46
+ for (const pdfBytes of pdfBuffers) {
47
+ const srcPdf = await PDFDocument.load(pdfBytes);
48
+ const copiedPages = await mergedPdf.copyPages(srcPdf, srcPdf.getPageIndices());
49
+ copiedPages.forEach(page => mergedPdf.addPage(page));
50
+ }
51
+ const mergedBytes = await mergedPdf.save();
52
+ return mergedBytes;
53
+ };
54
+ //# sourceMappingURL=pdf-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-converter.js","sourceRoot":"","sources":["../../src/converters/pdf-converter.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAKtD,OAAO,EAGL,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,MAA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,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAC/C,OAAO,eAAe,CAAC,MAAM,aAAa,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG,KAAK,EACzB,UAAiD,EAC5B,EAAE;IACvB,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAEpE,oCAAoC;IACpC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;IAE7C,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,SAAS,CAC3C,MAAM,EACN,MAAM,CAAC,cAAc,EAAE,CACxB,CAAC;QACF,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;IAC3C,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport { create } from \"domain\";\nimport { SmeupDataTable } from \"../types/data-structures/smeupDataTable.js\";\nimport { SmeupSch } from \"../types/data-structures/smeupSch.js\";\nimport {\n WebupManagerData,\n GenericObject,\n SupportedExportFormats,\n} from \"../types/index.js\";\nimport { convertToBuffer } from \"../utils/commons-utility.js\";\nimport { dataTableToExcelWorkbook } from \"./excel/matrix-converter.js\";\nimport { dataTableToPdfDoc } from \"./pdf/matrix-converter.js\";\nimport { schedaToPdfDoc } from \"./pdf/sch-converter.js\";\nimport { PDFDocument } from \"pdf-lib\";\nimport { createCoverPdf } from \"./pdf/cover-renderer.js\";\nimport { logoBase64 } from \"../assets/gfx-data.js\";\n\nexport const schedaToPdfData = async (\n sch: SmeupSch,\n webupManagerData: WebupManagerData,\n): Promise<Buffer> => {\n const doc = await schedaToPdfDoc(sch);\n return Buffer.from(doc.output(\"arraybuffer\"));\n};\n\nexport const dataTableToPdfData = async (\n component: {\n smeupDataTable: SmeupDataTable;\n props: GenericObject;\n },\n webupManagerData: WebupManagerData,\n): Promise<Buffer | Uint8Array> => {\n const workbook = dataTableToExcelWorkbook(\n component,\n SupportedExportFormats.XLSX,\n webupManagerData,\n );\n\n const worksheet = workbook.getWorksheet(1);\n if (worksheet) {\n const title = component.smeupDataTable.cover?.titles?.[\"T01\"] ?? \"\";\n const subtitle = component.smeupDataTable.cover?.titles?.[\"T02\"] ?? \"\";\n const subtitle2 = component.smeupDataTable.cover?.titles?.[\"T03\"] ?? \"\";\n const image = component.smeupDataTable.cover?.image ?? \"\";\n const logo = component.smeupDataTable.cover?.logo ?? logoBase64;\n const cover = createCoverPdf(image, logo, title, subtitle, subtitle2);\n const pdfDoc = await dataTableToPdfDoc(worksheet, webupManagerData, {\n logoBase64: logo,\n title: title,\n subtitle: subtitle,\n });\n const pdfBuffer = pdfDoc.output(\"arraybuffer\");\n return convertToBuffer(await appendPdfDocs([cover, pdfBuffer]));\n } else {\n throw new Error(\"Worksheet not found in the workbook\");\n }\n};\n\n/**\n * Unisce più PDF (in formato ArrayBuffer/Uint8Array/Buffer) in un unico PDF.\n * @param pdfBuffers Array di buffer PDF (es. ottenuti da jsPDF.output(\"arraybuffer\"))\n * @returns Buffer del PDF unito\n */\nconst appendPdfDocs = async (\n pdfBuffers: (Uint8Array | ArrayBuffer | Buffer)[],\n): Promise<Uint8Array> => {\n if (!pdfBuffers.length) throw new Error(\"No PDF buffers to append\");\n\n // Crea un nuovo documento PDF vuoto\n const mergedPdf = await PDFDocument.create();\n\n for (const pdfBytes of pdfBuffers) {\n const srcPdf = await PDFDocument.load(pdfBytes);\n const copiedPages = await mergedPdf.copyPages(\n srcPdf,\n srcPdf.getPageIndices(),\n );\n copiedPages.forEach(page => mergedPdf.addPage(page));\n }\n\n const mergedBytes = await mergedPdf.save();\n return mergedBytes;\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- export { dataTableToExcelData, dataTreeToExcelData, } from "./src/excel/excel-generator.js";
2
- export type { WebupManagerData, GenericObject } from "./src/types/index.js";
3
- export { SupportedExportFormats } from "./src/types/index.js";
4
- export type { SmeupDataTable, SmeupDataTree } from "@sme.up/kokos-sdk-node";
1
+ export { dataTableToExcelData, dataTreeToExcelData, } from "./converters/excel-converter.js";
2
+ export { schedaToPdfData, dataTableToPdfData, } from "./converters/pdf-converter.js";
3
+ export { dataTableToChart } from "./converters/images/charts-generator.js";
4
+ export type { WebupManagerData, GenericObject } from "./types/index.js";
5
+ export { SupportedExportFormats } from "./types/index.js";
6
+ export type { SmeupDataTable } from "./types/data-structures/smeupDataTable.js";
7
+ export type { SmeupDataTree } from "./types/data-structures/smeupDataTree.js";
5
8
  export type ColumnGroup = {
6
9
  column: string;
7
10
  visible: boolean;
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // Public API exports
2
- export { dataTableToExcelData, dataTreeToExcelData, } from "./src/excel/excel-generator.js";
3
- export { SupportedExportFormats } from "./src/types/index.js";
2
+ export { dataTableToExcelData, dataTreeToExcelData, } from "./converters/excel-converter.js";
3
+ export { schedaToPdfData, dataTableToPdfData, } from "./converters/pdf-converter.js";
4
+ export { dataTableToChart } from "./converters/images/charts-generator.js";
5
+ export { SupportedExportFormats } from "./types/index.js";
4
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["// Public API exports\nexport {\n dataTableToExcelData,\n dataTreeToExcelData,\n} from \"./src/excel/excel-generator.js\";\n\n// Export types that users might need\nexport type { WebupManagerData, GenericObject } from \"./src/types/index.js\";\n\nexport { SupportedExportFormats } from \"./src/types/index.js\";\n\n// Re-export useful types from kokos-sdk-node if needed\nexport type { SmeupDataTable, SmeupDataTree } from \"@sme.up/kokos-sdk-node\";\n\nexport type ColumnGroup = {\n column: string;\n visible: boolean;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["// Public API exports\nexport {\n dataTableToExcelData,\n dataTreeToExcelData,\n} from \"./converters/excel-converter.js\";\n\nexport {\n schedaToPdfData,\n dataTableToPdfData,\n} from \"./converters/pdf-converter.js\";\n\nexport { dataTableToChart } from \"./converters/images/charts-generator.js\";\n// Export types that users might need\nexport type { WebupManagerData, GenericObject } from \"./types/index.js\";\nexport { SupportedExportFormats } from \"./types/index.js\";\nexport type { SmeupDataTable } from \"./types/data-structures/smeupDataTable.js\";\nexport type { SmeupDataTree } from \"./types/data-structures/smeupDataTree.js\";\n\nexport type ColumnGroup = {\n column: string;\n visible: boolean;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ export interface SortObject {
2
+ column: string;
3
+ sortMode: SortMode;
4
+ }
5
+ export declare enum SortMode {
6
+ A = "A",
7
+ D = "D"
8
+ }
@@ -0,0 +1,7 @@
1
+ // Definitions of some utility types that comes from component library (currently Ketchup) to help understand code's logic.
2
+ export var SortMode;
3
+ (function (SortMode) {
4
+ SortMode["A"] = "A";
5
+ SortMode["D"] = "D";
6
+ })(SortMode || (SortMode = {}));
7
+ //# sourceMappingURL=component-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-props.js","sourceRoot":"","sources":["../../src/types/component-props.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAU3H,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,mBAAO,CAAA;IACP,mBAAO,CAAA;AACT,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB","sourcesContent":["// Definitions of some utility types that comes from component library (currently Ketchup) to help understand code's logic.\n\n// ** data table\n\n// @Props() sort\nexport interface SortObject {\n column: string;\n sortMode: SortMode;\n}\n\nexport enum SortMode {\n A = \"A\",\n D = \"D\",\n}\n"]}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Supported shapes.
3
+ */
4
+ export declare enum Shapes {
5
+ ACC = "ACC",
6
+ ACT = "ACT",
7
+ ATM = "ATM",
8
+ BOX = "BOX",
9
+ BTN = "BTN",
10
+ CAL = "CAL",
11
+ CHA = "CHA",// = EXA
12
+ DFT = "DFT",
13
+ DYN = "DYN",
14
+ DSH = "DSH",
15
+ EML = "EML",
16
+ EXA = "EXA",// = CHA
17
+ EXB = "EXB",// = MAT
18
+ EXD = "EXD",// = SCH
19
+ EXU = "EXU",
20
+ FBK = "FBK",
21
+ FLD = "FLD",
22
+ FOR = "FOR",
23
+ GNT = "GNT",
24
+ HTM = "HTM",
25
+ IML = "IML",
26
+ IMG = "IMG",
27
+ INT = "INT",
28
+ INP = "INP",
29
+ JSO = "JSO",
30
+ LAB = "LAB",
31
+ MAT = "MAT",// = EXB
32
+ PLN = "PLN",
33
+ PDF = "PDF",
34
+ SCH = "SCH",// = EXD
35
+ SPL = "SPL",
36
+ TED = "TED",
37
+ TRE = "TRE",
38
+ TXT = "TXT",
39
+ CND = "CND",
40
+ UNK = "UNK",
41
+ OGN = "OGN"
42
+ }
43
+ /**
44
+ * ToolbarState Info.
45
+ */
46
+ export declare enum ToolbarState {
47
+ EXPANDED = "Expanded",
48
+ COLLAPSED = "Collapsed",
49
+ INVISIBLE = "Invisible"
50
+ }
51
+ export interface ComponentOptions extends Record<string, string> {
52
+ Name: string;
53
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Supported shapes.
3
+ */
4
+ export var Shapes;
5
+ (function (Shapes) {
6
+ Shapes["ACC"] = "ACC";
7
+ Shapes["ACT"] = "ACT";
8
+ Shapes["ATM"] = "ATM";
9
+ Shapes["BOX"] = "BOX";
10
+ Shapes["BTN"] = "BTN";
11
+ Shapes["CAL"] = "CAL";
12
+ Shapes["CHA"] = "CHA";
13
+ Shapes["DFT"] = "DFT";
14
+ Shapes["DYN"] = "DYN";
15
+ Shapes["DSH"] = "DSH";
16
+ Shapes["EML"] = "EML";
17
+ Shapes["EXA"] = "EXA";
18
+ Shapes["EXB"] = "EXB";
19
+ Shapes["EXD"] = "EXD";
20
+ Shapes["EXU"] = "EXU";
21
+ Shapes["FBK"] = "FBK";
22
+ Shapes["FLD"] = "FLD";
23
+ Shapes["FOR"] = "FOR";
24
+ Shapes["GNT"] = "GNT";
25
+ Shapes["HTM"] = "HTM";
26
+ Shapes["IML"] = "IML";
27
+ Shapes["IMG"] = "IMG";
28
+ Shapes["INT"] = "INT";
29
+ Shapes["INP"] = "INP";
30
+ Shapes["JSO"] = "JSO";
31
+ Shapes["LAB"] = "LAB";
32
+ Shapes["MAT"] = "MAT";
33
+ Shapes["PLN"] = "PLN";
34
+ Shapes["PDF"] = "PDF";
35
+ Shapes["SCH"] = "SCH";
36
+ Shapes["SPL"] = "SPL";
37
+ Shapes["TED"] = "TED";
38
+ Shapes["TRE"] = "TRE";
39
+ Shapes["TXT"] = "TXT";
40
+ Shapes["CND"] = "CND";
41
+ Shapes["UNK"] = "UNK";
42
+ Shapes["OGN"] = "OGN";
43
+ })(Shapes || (Shapes = {}));
44
+ /**
45
+ * ToolbarState Info.
46
+ */
47
+ export var ToolbarState;
48
+ (function (ToolbarState) {
49
+ ToolbarState["EXPANDED"] = "Expanded";
50
+ ToolbarState["COLLAPSED"] = "Collapsed";
51
+ ToolbarState["INVISIBLE"] = "Invisible";
52
+ })(ToolbarState || (ToolbarState = {}));
53
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/types/component.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,MAsCX;AAtCD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;IACX,qBAAW,CAAA;AACb,CAAC,EAtCW,MAAM,KAAN,MAAM,QAsCjB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,qCAAqB,CAAA;IACrB,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;AACzB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB","sourcesContent":["/**\n * Supported shapes.\n */\nexport enum Shapes {\n ACC = \"ACC\",\n ACT = \"ACT\",\n ATM = \"ATM\",\n BOX = \"BOX\",\n BTN = \"BTN\",\n CAL = \"CAL\",\n CHA = \"CHA\", // = EXA\n DFT = \"DFT\",\n DYN = \"DYN\",\n DSH = \"DSH\",\n EML = \"EML\",\n EXA = \"EXA\", // = CHA\n EXB = \"EXB\", // = MAT\n EXD = \"EXD\", // = SCH\n EXU = \"EXU\",\n FBK = \"FBK\",\n FLD = \"FLD\",\n FOR = \"FOR\",\n GNT = \"GNT\",\n HTM = \"HTM\",\n IML = \"IML\",\n IMG = \"IMG\",\n INT = \"INT\",\n INP = \"INP\",\n JSO = \"JSO\",\n LAB = \"LAB\",\n MAT = \"MAT\", // = EXB\n PLN = \"PLN\",\n PDF = \"PDF\",\n SCH = \"SCH\", // = EXD\n SPL = \"SPL\",\n TED = \"TED\",\n TRE = \"TRE\",\n TXT = \"TXT\",\n CND = \"CND\",\n UNK = \"UNK\",\n OGN = \"OGN\",\n}\n\n/**\n * ToolbarState Info.\n */\nexport enum ToolbarState {\n EXPANDED = \"Expanded\",\n COLLAPSED = \"Collapsed\",\n INVISIBLE = \"Invisible\",\n}\n\nexport interface ComponentOptions extends Record<string, string> {\n Name: string;\n}\n"]}