@sme.up/doc-alchemist 1.2.0-SNAPSHOT-20250627073811 → 1.2.0-SNAPSHOT-20250702130625
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.
- package/dist/assets/gfx-data.d.ts +1 -0
- package/dist/assets/gfx-data.js +2 -0
- package/dist/assets/gfx-data.js.map +1 -0
- package/dist/{excel → converters/excel}/commons.d.ts +14 -2
- package/dist/{excel → converters/excel}/commons.js +44 -20
- package/dist/converters/excel/commons.js.map +1 -0
- package/dist/{excel/excel-generator.types.d.ts → converters/excel/excel-converter.types.d.ts} +1 -0
- package/dist/{excel/excel-generator.types.js → converters/excel/excel-converter.types.js} +3 -2
- package/dist/converters/excel/excel-converter.types.js.map +1 -0
- package/dist/{excel/matrix-generator.d.ts → converters/excel/matrix-converter.d.ts} +4 -3
- package/dist/{excel/matrix-generator.js → converters/excel/matrix-converter.js} +14 -5
- package/dist/converters/excel/matrix-converter.js.map +1 -0
- package/dist/{excel/tree-generator.d.ts → converters/excel/tree-converter.d.ts} +2 -2
- package/dist/{excel/tree-generator.js → converters/excel/tree-converter.js} +5 -5
- package/dist/converters/excel/tree-converter.js.map +1 -0
- package/dist/{excel/excel-generator.js → converters/excel-converter.js} +4 -4
- package/dist/converters/excel-converter.js.map +1 -0
- package/dist/{images → converters/images}/charts-generator.d.ts +2 -2
- package/dist/converters/images/charts-generator.js.map +1 -0
- package/dist/converters/pdf/formulas-helper.d.ts +36 -0
- package/dist/converters/pdf/formulas-helper.js +191 -0
- package/dist/converters/pdf/formulas-helper.js.map +1 -0
- package/dist/converters/pdf/matrix-converter.d.ts +4 -0
- package/dist/converters/pdf/matrix-converter.js +291 -0
- package/dist/converters/pdf/matrix-converter.js.map +1 -0
- package/dist/converters/pdf/pdf-converter.types.d.ts +11 -0
- package/dist/converters/pdf/pdf-converter.types.js +2 -0
- package/dist/converters/pdf/pdf-converter.types.js.map +1 -0
- package/dist/{pdf/sch-generator.d.ts → converters/pdf/sch-converter.d.ts} +1 -1
- package/dist/{pdf/sch-generator.js → converters/pdf/sch-converter.js} +2 -2
- package/dist/converters/pdf/sch-converter.js.map +1 -0
- package/dist/{pdf/pdf-generator.d.ts → converters/pdf-converter.d.ts} +3 -3
- package/dist/converters/pdf-converter.js +22 -0
- package/dist/converters/pdf-converter.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/{generator-utility.d.ts → commons-utility.d.ts} +5 -0
- package/dist/utils/{generator-utility.js → commons-utility.js} +32 -2
- package/dist/utils/commons-utility.js.map +1 -0
- package/dist/utils/dates-utility.d.ts +9 -0
- package/dist/utils/dates-utility.js +18 -0
- package/dist/utils/dates-utility.js.map +1 -1
- package/dist/utils/formatter-utility.d.ts +3 -0
- package/dist/utils/formatter-utility.js +36 -0
- package/dist/utils/formatter-utility.js.map +1 -0
- package/package.json +3 -2
- package/dist/excel/commons.js.map +0 -1
- package/dist/excel/excel-generator.js.map +0 -1
- package/dist/excel/excel-generator.types.js.map +0 -1
- package/dist/excel/matrix-generator.js.map +0 -1
- package/dist/excel/tree-generator.js.map +0 -1
- package/dist/images/charts-generator.js.map +0 -1
- package/dist/pdf/pdf-generator.js +0 -9
- package/dist/pdf/pdf-generator.js.map +0 -1
- package/dist/pdf/sch-generator.js.map +0 -1
- package/dist/utils/generator-utility.js.map +0 -1
- /package/dist/{excel/excel-generator.d.ts → converters/excel-converter.d.ts} +0 -0
- /package/dist/{images → converters/images}/charts-generator.js +0 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import * as jsPDFModule from "jspdf";
|
|
2
|
+
import ExcelJS from "exceljs";
|
|
3
|
+
import autoTable from "jspdf-autotable";
|
|
4
|
+
import { convertColorToRgb } from "../../utils/commons-utility.js";
|
|
5
|
+
import { formatDate, formatNumber } from "../../utils/formatter-utility.js";
|
|
6
|
+
import { evaluateStandardFormula, handleSubtotalFormula, } from "./formulas-helper.js";
|
|
7
|
+
import { logoBase64 } from "../../assets/gfx-data.js";
|
|
8
|
+
// Function to calculate the optimal font size
|
|
9
|
+
const calculateOptimalFontSize = (data, visibleHeaders, pageWidth) => {
|
|
10
|
+
const maxSamples = Math.min(100, data.length); // Analyze max 100 rows
|
|
11
|
+
const availableWidth = pageWidth - 20; // Margins
|
|
12
|
+
const numColumns = visibleHeaders.length;
|
|
13
|
+
// If there are few columns, we can allow a larger font size
|
|
14
|
+
if (numColumns <= 3) {
|
|
15
|
+
return 10;
|
|
16
|
+
}
|
|
17
|
+
// Calculate more accurate statistics per column
|
|
18
|
+
const columnStats = visibleHeaders.map((header, colIndex) => {
|
|
19
|
+
const lengths = [header.length];
|
|
20
|
+
// Collect all cell lengths for this column
|
|
21
|
+
for (let rowIndex = 0; rowIndex < maxSamples; rowIndex++) {
|
|
22
|
+
if (data[rowIndex] && data[rowIndex][colIndex]) {
|
|
23
|
+
const cellLength = data[rowIndex][colIndex].value.replace(/\u00A0/g, " ").length;
|
|
24
|
+
lengths.push(cellLength);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
lengths.sort((a, b) => a - b);
|
|
28
|
+
// Use the 90th percentile instead of the maximum to be less conservative
|
|
29
|
+
const percentile90Index = Math.floor(lengths.length * 0.9);
|
|
30
|
+
const effectiveWidth = lengths[percentile90Index] || lengths[lengths.length - 1];
|
|
31
|
+
// The average length to balance very long columns with short ones
|
|
32
|
+
const avgLength = lengths.reduce((sum, len) => sum + len, 0) / lengths.length;
|
|
33
|
+
return {
|
|
34
|
+
max: Math.max(...lengths),
|
|
35
|
+
p90: effectiveWidth,
|
|
36
|
+
avg: avgLength,
|
|
37
|
+
min: Math.min(...lengths),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
// Use a mixed strategy: combine 90th percentile with weighted average
|
|
41
|
+
const estimatedColumnWidths = columnStats.map(stats => {
|
|
42
|
+
// Weight the average more than the 90th percentile to be less pessimistic
|
|
43
|
+
const weightedWidth = stats.avg * 0.7 + stats.p90 * 0.3;
|
|
44
|
+
return Math.max(weightedWidth, 3); // Minimum width of 3 characters
|
|
45
|
+
});
|
|
46
|
+
// Try different font sizes starting from the largest
|
|
47
|
+
for (let testFontSize = 10; testFontSize >= 4; testFontSize -= 0.5) {
|
|
48
|
+
// More optimistic factor based on font size
|
|
49
|
+
const charWidthFactor = testFontSize >= 8 ? 3.2 : testFontSize >= 6 ? 2.8 : 2.5;
|
|
50
|
+
const estimatedTotalWidth = estimatedColumnWidths.reduce((sum, width) => sum + width * charWidthFactor, 0);
|
|
51
|
+
// Add a margin for columns (space between columns)
|
|
52
|
+
const totalWidthWithMargins = estimatedTotalWidth + numColumns * 5; // 5px between columns
|
|
53
|
+
if (totalWidthWithMargins <= availableWidth) {
|
|
54
|
+
return testFontSize;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return 4; // Minimum font size if nothing fits
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Extracts visible headers and their column indexes from the worksheet (ignoring hidden columns).
|
|
61
|
+
*/
|
|
62
|
+
const extractVisibleHeadersAndIndexes = (worksheet) => {
|
|
63
|
+
const headerRow = worksheet.getRow(1);
|
|
64
|
+
const visibleHeaders = [];
|
|
65
|
+
const visibleColumnIndexes = [];
|
|
66
|
+
headerRow.eachCell({ includeEmpty: true }, (cell, colNumber) => {
|
|
67
|
+
const column = worksheet.getColumn(colNumber);
|
|
68
|
+
if (!column.hidden) {
|
|
69
|
+
visibleHeaders.push(cell?.toString() ?? "");
|
|
70
|
+
visibleColumnIndexes.push(colNumber);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return { visibleHeaders, visibleColumnIndexes };
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Extracts the data from the worksheet for the given visible columns, formatting dates and preserving spaces.
|
|
77
|
+
*/
|
|
78
|
+
const extractData = (worksheet, visibleColumnIndexes, webupManagerData) => {
|
|
79
|
+
const data = [];
|
|
80
|
+
worksheet.eachRow((row, rowIndex) => {
|
|
81
|
+
if (rowIndex === 1)
|
|
82
|
+
return; // Skip header
|
|
83
|
+
const rowData = [];
|
|
84
|
+
visibleColumnIndexes.forEach(colIdx => {
|
|
85
|
+
const cell = row.getCell(colIdx);
|
|
86
|
+
const cellValue = getCellValueData(cell, worksheet, webupManagerData);
|
|
87
|
+
// Preserve spaces by replacing them with non-breaking spaces
|
|
88
|
+
cellValue.value = cellValue.value.replace(/ /g, "\u00A0");
|
|
89
|
+
rowData.push(cellValue);
|
|
90
|
+
});
|
|
91
|
+
data.push(rowData);
|
|
92
|
+
});
|
|
93
|
+
return data;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Extracts and formats the value of a given ExcelJS cell based on its type.
|
|
97
|
+
*/
|
|
98
|
+
const getCellValueData = (cell, worksheet, webupManagerData) => {
|
|
99
|
+
if (cell.type === ExcelJS.ValueType.Formula &&
|
|
100
|
+
typeof cell.formula === "string") {
|
|
101
|
+
const subtotalMatch = cell.formula.match(/^SUBTOTAL\((\d+)\s*,\s*([A-Z]+\d+):([A-Z]+\d+)\)/i);
|
|
102
|
+
if (subtotalMatch) {
|
|
103
|
+
return handleSubtotalFormula(cell, worksheet, webupManagerData, subtotalMatch);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return evaluateStandardFormula(cell, worksheet, webupManagerData);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (cell.type === ExcelJS.ValueType.Date &&
|
|
110
|
+
cell.value instanceof Date) {
|
|
111
|
+
return {
|
|
112
|
+
value: formatDate(cell.value, webupManagerData),
|
|
113
|
+
type: "date",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else if (cell.type === ExcelJS.ValueType.Number) {
|
|
117
|
+
return {
|
|
118
|
+
value: formatNumber(cell.value, cell.numFmt ?? 0, webupManagerData),
|
|
119
|
+
type: "number",
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return {
|
|
124
|
+
value: cell?.text || cell?.value?.toString() || "",
|
|
125
|
+
type: "string",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Extracts the cell styles (font, color, fill) for the given visible columns from the worksheet.
|
|
131
|
+
*/
|
|
132
|
+
const extractStyles = (worksheet, visibleColumnIndexes, rawData) => {
|
|
133
|
+
const cellStyles = [];
|
|
134
|
+
worksheet.eachRow((row, rowIndex) => {
|
|
135
|
+
if (rowIndex === 1)
|
|
136
|
+
return; // Skip header
|
|
137
|
+
const rowStyles = [];
|
|
138
|
+
visibleColumnIndexes.forEach((colIdx, index) => {
|
|
139
|
+
const cell = row.getCell(colIdx);
|
|
140
|
+
const cellStyle = {};
|
|
141
|
+
// Font
|
|
142
|
+
if (cell.font) {
|
|
143
|
+
if (cell.font.bold && cell.font.italic) {
|
|
144
|
+
cellStyle.fontStyle = "bolditalic";
|
|
145
|
+
}
|
|
146
|
+
else if (cell.font.bold) {
|
|
147
|
+
cellStyle.fontStyle = "bold";
|
|
148
|
+
}
|
|
149
|
+
else if (cell.font.italic) {
|
|
150
|
+
cellStyle.fontStyle = "italic";
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
cellStyle.fontStyle = "normal";
|
|
154
|
+
}
|
|
155
|
+
if (cell.font.color?.argb) {
|
|
156
|
+
const color = cell.font.color.argb;
|
|
157
|
+
const [r, g, b] = convertColorToRgb(color);
|
|
158
|
+
if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
|
|
159
|
+
cellStyle.textColor = [r, g, b];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Fill (background color)
|
|
164
|
+
if (cell.fill &&
|
|
165
|
+
cell.fill.type === "pattern" &&
|
|
166
|
+
cell.fill.fgColor?.argb) {
|
|
167
|
+
const color = cell.fill.fgColor.argb;
|
|
168
|
+
const [r, g, b] = convertColorToRgb(color);
|
|
169
|
+
if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
|
|
170
|
+
cellStyle.fillColor = [r, g, b];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Align right if the cell is numeric
|
|
174
|
+
if (rawData[rowIndex - 2][index].type === "number") {
|
|
175
|
+
cellStyle.halign = "right";
|
|
176
|
+
}
|
|
177
|
+
rowStyles.push(cellStyle);
|
|
178
|
+
});
|
|
179
|
+
cellStyles.push(rowStyles);
|
|
180
|
+
});
|
|
181
|
+
return cellStyles;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Post-processes the data and cell styles to simulate Excel's text overflow behavior.
|
|
185
|
+
* If a cell has long text and the next cell is empty, the width is set to auto.
|
|
186
|
+
*/
|
|
187
|
+
const postProcessExcelOverflow = (data, cellStyles) => {
|
|
188
|
+
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
|
|
189
|
+
for (let colIndex = 0; colIndex < data[rowIndex].length - 1; colIndex++) {
|
|
190
|
+
const currentCell = data[rowIndex][colIndex];
|
|
191
|
+
const nextCell = data[rowIndex][colIndex + 1];
|
|
192
|
+
// If the current cell has long text and the next one is empty or only spaces
|
|
193
|
+
if (currentCell &&
|
|
194
|
+
currentCell.value.length > 15 &&
|
|
195
|
+
(!nextCell || nextCell.value.trim() === "")) {
|
|
196
|
+
// Extend the width of the current cell
|
|
197
|
+
if (!cellStyles[rowIndex][colIndex].cellWidth) {
|
|
198
|
+
cellStyles[rowIndex][colIndex].cellWidth = "auto";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
export const dataTableToPdfDoc = async (worksheet, webupManagerData) => {
|
|
205
|
+
const doc = new jsPDFModule.jsPDF({ orientation: "landscape" });
|
|
206
|
+
doc.setFont("helvetica", "normal");
|
|
207
|
+
doc.setFontSize(10);
|
|
208
|
+
// Extract headers and column indexes
|
|
209
|
+
const { visibleHeaders, visibleColumnIndexes } = extractVisibleHeadersAndIndexes(worksheet);
|
|
210
|
+
// Extract data and cell styles separately
|
|
211
|
+
const data = extractData(worksheet, visibleColumnIndexes, webupManagerData);
|
|
212
|
+
const cellStyles = extractStyles(worksheet, visibleColumnIndexes, data);
|
|
213
|
+
// Post-process data to simulate Excel overflow
|
|
214
|
+
postProcessExcelOverflow(data, cellStyles);
|
|
215
|
+
// Calculate optimal font size based on data
|
|
216
|
+
const pageWidth = doc.internal.pageSize.getWidth();
|
|
217
|
+
const optimalFontSize = calculateOptimalFontSize(data, visibleHeaders, pageWidth);
|
|
218
|
+
autoTable(doc, {
|
|
219
|
+
head: [visibleHeaders],
|
|
220
|
+
body: data.map(row => row.map(cell => cell.value)),
|
|
221
|
+
startY: 25, // Increased from 15 to 25 to leave space for the logo
|
|
222
|
+
margin: { left: 5, right: 5, top: 25, bottom: 10 }, // Increased top from 10 to 25 for the logo
|
|
223
|
+
styles: {
|
|
224
|
+
font: "helvetica",
|
|
225
|
+
fontSize: optimalFontSize + 1,
|
|
226
|
+
cellPadding: 1, // Reduced from 2 to 1
|
|
227
|
+
overflow: "visible",
|
|
228
|
+
cellWidth: "auto",
|
|
229
|
+
minCellWidth: 5, // Reduced from 10 to 5
|
|
230
|
+
},
|
|
231
|
+
columnStyles: {
|
|
232
|
+
// Preserve spaces for all columns and allow overflow
|
|
233
|
+
...Object.fromEntries(visibleHeaders.map((_, index) => [
|
|
234
|
+
index,
|
|
235
|
+
{
|
|
236
|
+
cellWidth: "wrap", // Changed from "auto" to "wrap"
|
|
237
|
+
halign: "left",
|
|
238
|
+
overflow: "visible",
|
|
239
|
+
cellPadding: { top: 1, right: 1, bottom: 1, left: 1 }, // Specific padding
|
|
240
|
+
},
|
|
241
|
+
])),
|
|
242
|
+
},
|
|
243
|
+
headStyles: {
|
|
244
|
+
fillColor: [255, 0, 0], // Red for the header
|
|
245
|
+
textColor: [255, 255, 255], // White text for contrast
|
|
246
|
+
fontStyle: "bold",
|
|
247
|
+
halign: "center", // Center align header text
|
|
248
|
+
},
|
|
249
|
+
didDrawPage: function (dataArg) {
|
|
250
|
+
// Add the logo on each page
|
|
251
|
+
if (logoBase64) {
|
|
252
|
+
const pageWidth = dataArg.doc.internal.pageSize.getWidth();
|
|
253
|
+
const logoWidth = 40; // Logo width in mm
|
|
254
|
+
const logoHeight = 15; // Logo height in mm
|
|
255
|
+
const logoX = pageWidth - logoWidth - 10; // 10mm from the right margin
|
|
256
|
+
const logoY = 5; // 5mm from the top margin
|
|
257
|
+
try {
|
|
258
|
+
dataArg.doc.addImage(logoBase64, "PNG", logoX, logoY, logoWidth, logoHeight);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.warn("Error adding logo:", error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
didParseCell: function (dataArg) {
|
|
266
|
+
if (dataArg.section === "body") {
|
|
267
|
+
const rowIndex = dataArg.row.index;
|
|
268
|
+
const colIndex = dataArg.column.index;
|
|
269
|
+
const cellStyle = cellStyles[rowIndex]?.[colIndex];
|
|
270
|
+
if (cellStyle) {
|
|
271
|
+
// Apply styles from the Excel cell
|
|
272
|
+
if (cellStyle.fontStyle) {
|
|
273
|
+
dataArg.cell.styles.fontStyle = cellStyle.fontStyle;
|
|
274
|
+
}
|
|
275
|
+
if (cellStyle.textColor) {
|
|
276
|
+
dataArg.cell.styles.textColor = cellStyle.textColor;
|
|
277
|
+
}
|
|
278
|
+
if (cellStyle.fillColor) {
|
|
279
|
+
dataArg.cell.styles.fillColor = cellStyle.fillColor;
|
|
280
|
+
}
|
|
281
|
+
// Apply right alignment for numeric cells
|
|
282
|
+
if (cellStyle.halign === "right") {
|
|
283
|
+
dataArg.cell.styles.halign = "right";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
return doc;
|
|
290
|
+
};
|
|
291
|
+
//# 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;AACrC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,8CAA8C;AAC9C,MAAM,wBAAwB,GAAG,CAC/B,IAAwB,EACxB,cAAwB,EACxB,SAAiB,EACT,EAAE;IACV,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,uBAAuB;IACtE,MAAM,cAAc,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC,UAAU;IACjD,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAC;IAEzC,4DAA4D;IAC5D,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,gDAAgD;IAEhD,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;QAC1D,MAAM,OAAO,GAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE1C,2CAA2C;QAC3C,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC;YACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC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AE,CAAC;wBACxB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;oBACtD,CAAC;oBACD,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;wBACxB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;oBACtD,CAAC;oBACD,0CAA0C;oBAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;wBACjC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;oBACvC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["import * as jsPDFModule 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 { formatDate, formatNumber } from \"../../utils/formatter-utility.js\";\nimport {\n evaluateStandardFormula,\n handleSubtotalFormula,\n} from \"./formulas-helper.js\";\nimport { logoBase64 } from \"../../assets/gfx-data.js\";\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\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].value.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 * 5; // 5px 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 // Preserve spaces by replacing them with non-breaking spaces\n cellValue.value = cellValue.value.replace(/ /g, \"\\u00A0\");\n rowData.push(cellValue);\n });\n data.push(rowData);\n });\n return data;\n};\n\n/**\n * Extracts and formats the value of a given ExcelJS cell based on its type.\n */\nconst 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: formatDate(cell.value, webupManagerData),\n type: \"date\",\n };\n } else if (cell.type === ExcelJS.ValueType.Number) {\n return {\n value: formatNumber(\n cell.value as number,\n cell.numFmt ?? 0,\n webupManagerData,\n ),\n type: \"number\",\n };\n } else {\n return {\n value: cell?.text || cell?.value?.toString() || \"\",\n type: \"string\",\n };\n }\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 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.value.length > 15 &&\n (!nextCell || nextCell.value.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\nexport const dataTableToPdfDoc = async (\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\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(doc, {\n head: [visibleHeaders],\n body: data.map(row => row.map(cell => cell.value)),\n startY: 25, // Increased from 15 to 25 to leave space for the logo\n margin: { left: 5, right: 5, top: 25, bottom: 10 }, // Increased top from 10 to 25 for the logo\n styles: {\n font: \"helvetica\",\n fontSize: optimalFontSize + 1,\n cellPadding: 1, // Reduced from 2 to 1\n overflow: \"visible\",\n cellWidth: \"auto\",\n minCellWidth: 5, // Reduced from 10 to 5\n },\n columnStyles: {\n // Preserve spaces for all columns and allow overflow\n ...Object.fromEntries(\n visibleHeaders.map((_, index) => [\n index,\n {\n cellWidth: \"wrap\", // Changed from \"auto\" to \"wrap\"\n halign: \"left\" as const,\n overflow: \"visible\",\n cellPadding: { top: 1, right: 1, bottom: 1, left: 1 }, // Specific padding\n },\n ]),\n ),\n },\n headStyles: {\n fillColor: [255, 0, 0], // Red for the header\n textColor: [255, 255, 255], // White text for contrast\n fontStyle: \"bold\",\n halign: \"center\", // Center align header text\n },\n didDrawPage: function (dataArg) {\n // Add the logo on each page\n if (logoBase64) {\n const pageWidth = dataArg.doc.internal.pageSize.getWidth();\n const logoWidth = 40; // Logo width in mm\n const logoHeight = 15; // Logo height in mm\n const logoX = pageWidth - logoWidth - 10; // 10mm from the right margin\n const logoY = 5; // 5mm from the top margin\n\n try {\n dataArg.doc.addImage(\n 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 didParseCell: function (dataArg) {\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 if (cellStyle.fontStyle) {\n dataArg.cell.styles.fontStyle = cellStyle.fontStyle;\n }\n if (cellStyle.textColor) {\n dataArg.cell.styles.textColor = cellStyle.textColor;\n }\n if (cellStyle.fillColor) {\n dataArg.cell.styles.fillColor = cellStyle.fillColor;\n }\n // Apply right alignment for numeric cells\n if (cellStyle.halign === \"right\") {\n dataArg.cell.styles.halign = \"right\";\n }\n }\n }\n },\n });\n\n return doc;\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface CellStyleData {
|
|
2
|
+
fontStyle?: "normal" | "bold" | "italic" | "bolditalic";
|
|
3
|
+
textColor?: [number, number, number];
|
|
4
|
+
fillColor?: [number, number, number];
|
|
5
|
+
cellWidth?: string;
|
|
6
|
+
halign?: "left" | "right" | "center";
|
|
7
|
+
}
|
|
8
|
+
export interface CellValueProps {
|
|
9
|
+
value: string;
|
|
10
|
+
type: "string" | "number" | "date" | "boolean" | "formula";
|
|
11
|
+
}
|
|
@@ -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?: string;\n halign?: \"left\" | \"right\" | \"center\";\n}\n\nexport interface CellValueProps {\n value: string;\n type: \"string\" | \"number\" | \"date\" | \"boolean\" | \"formula\";\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as jsPDFModule from "jspdf";
|
|
2
2
|
import { dataTableToChart } from "../images/charts-generator.js";
|
|
3
|
-
import { Shapes } from "
|
|
3
|
+
import { Shapes } from "../../types/component.js";
|
|
4
4
|
const jsPDF = jsPDFModule.jsPDF;
|
|
5
5
|
export const schedaToPdfDoc = async (sch) => {
|
|
6
6
|
const doc = new jsPDF({ orientation: "landscape" });
|
|
@@ -96,4 +96,4 @@ const filterSections = (sections) => {
|
|
|
96
96
|
return false;
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
-
//# sourceMappingURL=sch-
|
|
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,E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I,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,QAA2B,EAAqB,EAAE;IACxE,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;QAC/B,2DAA2D;QAC3D,IACE,OAAO,CAAC,UAAU;YAClB,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAC7B,OAAO,CAAC,UAAU,CAAC,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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SmeupDataTable } from "../types/data-structures/smeupDataTable.js";
|
|
2
2
|
import { SmeupSch } from "../types/data-structures/smeupSch.js";
|
|
3
|
-
import {
|
|
3
|
+
import { WebupManagerData, GenericObject } from "../types/index.js";
|
|
4
|
+
export declare const schedaToPdfData: (sch: SmeupSch, webupManagerData: WebupManagerData) => Promise<Buffer>;
|
|
4
5
|
export declare const dataTableToPdfData: (component: {
|
|
5
6
|
smeupDataTable: SmeupDataTable;
|
|
6
7
|
props: GenericObject;
|
|
7
|
-
}, webupManagerData: WebupManagerData) => Promise<Buffer>;
|
|
8
|
-
export declare const schedaToPdfData: (sch: SmeupSch, webupManagerData: WebupManagerData) => Promise<Buffer>;
|
|
8
|
+
}, webupManagerData: WebupManagerData) => Promise<Buffer | Uint8Array>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
export const schedaToPdfData = async (sch, webupManagerData) => {
|
|
8
|
+
const doc = await schedaToPdfDoc(sch);
|
|
9
|
+
return Buffer.from(doc.output("arraybuffer"));
|
|
10
|
+
};
|
|
11
|
+
export const dataTableToPdfData = async (component, webupManagerData) => {
|
|
12
|
+
const workbook = dataTableToExcelWorkbook(component, SupportedExportFormats.XLSX, webupManagerData);
|
|
13
|
+
const worksheet = workbook.getWorksheet(1);
|
|
14
|
+
if (worksheet) {
|
|
15
|
+
const pdfDoc = await dataTableToPdfDoc(worksheet, webupManagerData);
|
|
16
|
+
return convertToBuffer(pdfDoc.output("arraybuffer"));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error("Worksheet not found in the workbook");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//# 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;AAItD,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;AAExD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAAa,EACb,gBAAkC,EACjB,EAAE;IACnB,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,SAGC,EACD,gBAAkC,EACJ,EAAE;IAChC,MAAM,QAAQ,GAAG,wBAAwB,CACvC,SAAS,EACT,sBAAsB,CAAC,IAAI,EAC3B,gBAAgB,CACjB,CAAC;IAEF,MAAM,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;QACpE,OAAO,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\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\";\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 pdfDoc = await dataTableToPdfDoc(worksheet, webupManagerData);\n return convertToBuffer(pdfDoc.output(\"arraybuffer\"));\n } else {\n throw new Error(\"Worksheet not found in the workbook\");\n }\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { dataTableToExcelData, dataTreeToExcelData, } from "./
|
|
2
|
-
export { schedaToPdfData } from "./
|
|
3
|
-
export { dataTableToChart } from "./images/charts-generator.js";
|
|
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
4
|
export type { WebupManagerData, GenericObject } from "./types/index.js";
|
|
5
5
|
export { SupportedExportFormats } from "./types/index.js";
|
|
6
6
|
export type { SmeupDataTable } from "./types/data-structures/smeupDataTable.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Public API exports
|
|
2
|
-
export { dataTableToExcelData, dataTreeToExcelData, } from "./
|
|
3
|
-
export { schedaToPdfData } from "./
|
|
4
|
-
export { dataTableToChart } from "./images/charts-generator.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
5
|
export { SupportedExportFormats } from "./types/index.js";
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,
|
|
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"]}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -11,5 +11,6 @@ export var SupportedExportFormats;
|
|
|
11
11
|
SupportedExportFormats["CSV"] = "csv";
|
|
12
12
|
SupportedExportFormats["TXT"] = "txt";
|
|
13
13
|
SupportedExportFormats["PDF_SCHEDA"] = "pdf_scheda";
|
|
14
|
+
SupportedExportFormats["PDF"] = "pdf";
|
|
14
15
|
})(SupportedExportFormats || (SupportedExportFormats = {}));
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,qDAAqC,CAAA;IACrC,qCAAqB,CAAA;IACrB,kDAAkC,CAAA;AACpC,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AAwBD,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,qDAAqC,CAAA;IACrC,qCAAqB,CAAA;IACrB,kDAAkC,CAAA;AACpC,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AAwBD,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,uCAAa,CAAA;IACb,qCAAW,CAAA;IACX,qCAAW,CAAA;IACX,mDAAyB,CAAA;IACzB,qCAAW,CAAA;AACb,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC","sourcesContent":["import type { Properties as CSSProperties } from \"csstype\";\nimport { ComponentOptions } from \"./component.js\";\nimport { SmeupDataCell } from \"./data-structures/smeupDataTable.js\";\n\nexport interface SmeupDataObj {\n t: string;\n p: string;\n k: string;\n}\n\nexport enum DatesFormats {\n ISO_DATE = \"YYYY-MM-DD\",\n ISO_DATE_TIME = \"YYYY-MM-DD HH:mm:ss\",\n ISO_TIME = \"HH:mm:ss\",\n ISO_TIME_WITHOUT_SECONDS = \"HH:mm\",\n}\n\nexport interface GenericObject {\n [index: string]: unknown;\n}\n\nexport interface WebupManagerData {\n mathLocale: string;\n datesLocale: string;\n themeBackground: string;\n}\n\n/**\n * Applies dataTable filters to the excel table rows\n */\nexport type ColumnFilter = {\n checkBoxes?: { value: string }[];\n // add other properties if needed\n};\n\nexport interface SmeupDataCellStyled extends SmeupDataCell {\n style?: CSSProperties;\n}\n\nexport enum SupportedExportFormats {\n XLSX = \"xlsx\",\n CSV = \"csv\",\n TXT = \"txt\",\n PDF_SCHEDA = \"pdf_scheda\",\n PDF = \"pdf\",\n}\n\nexport interface ChartOptions extends ComponentOptions {\n Width: string;\n Height: string;\n}\n"]}
|
|
@@ -32,3 +32,8 @@ export declare const calculateCellValue: (cell: SmeupDataCell, bookType: Support
|
|
|
32
32
|
*/
|
|
33
33
|
export declare const hexToArgb: (hex: string) => string;
|
|
34
34
|
export declare const convertToBuffer: (arrayBuffer: ArrayBuffer) => Buffer | Uint8Array;
|
|
35
|
+
export declare const loadImageAsBase64: (imageUrl: string) => Promise<string | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Converts a hexadecimal color string (e.g., "#RRGGBB" or "0xRRGGBB") to an RGB tuple.
|
|
38
|
+
*/
|
|
39
|
+
export declare const convertColorToRgb: (color: string) => [number, number, number];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { exportTypeSupportsFormatting } from "../excel/excel-
|
|
1
|
+
import { exportTypeSupportsFormatting } from "../converters/excel/excel-converter.types.js";
|
|
2
2
|
import { datesIsIsoDate, datesToDate, datesFormat } from "./dates-utility.js";
|
|
3
3
|
import { mathNumberStringToFormattedString, mathCountDecimals, } from "./math-utility.js";
|
|
4
4
|
import { objectsIsVoCodVer, objectsIsDate, objectsIsNumber, } from "./objects-utility.js";
|
|
@@ -132,4 +132,34 @@ export const convertToBuffer = (arrayBuffer) => {
|
|
|
132
132
|
return new Uint8Array(arrayBuffer);
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
|
|
135
|
+
// Function to load an image as base64 (browser version, async)
|
|
136
|
+
export const loadImageAsBase64 = async (imageUrl) => {
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(imageUrl);
|
|
139
|
+
if (!response.ok)
|
|
140
|
+
return null;
|
|
141
|
+
const blob = await response.blob();
|
|
142
|
+
return await new Promise((resolve, reject) => {
|
|
143
|
+
const reader = new FileReader();
|
|
144
|
+
reader.onloadend = () => {
|
|
145
|
+
resolve(reader.result);
|
|
146
|
+
};
|
|
147
|
+
reader.onerror = () => reject(null);
|
|
148
|
+
reader.readAsDataURL(blob);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.warn("Unable to load asset image:", error);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Converts a hexadecimal color string (e.g., "#RRGGBB" or "0xRRGGBB") to an RGB tuple.
|
|
158
|
+
*/
|
|
159
|
+
export const convertColorToRgb = (color) => {
|
|
160
|
+
const r = parseInt(color.substring(2, 4), 16);
|
|
161
|
+
const g = parseInt(color.substring(4, 6), 16);
|
|
162
|
+
const b = parseInt(color.substring(6, 8), 16);
|
|
163
|
+
return [r, g, b];
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=commons-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-utility.js","sourceRoot":"","sources":["../../src/utils/commons-utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAa5F,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA0B,EAC1B,KAAoB,EACpB,cAAsD,EAAE,EACxD,EAAE;IACF,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CACH,CAAC;IAEvB,MAAM,eAAe,GAAsB,EAAE,CAAC;IAE9C,IAAI,KAAK,CAAC,cAAc,IAAK,KAAK,CAAC,cAA2B,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzE,KAAK,CAAC,cAA2B,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YACzD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;YAC7D,IAAI,WAAW,EAAE,CAAC;gBAChB,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YAC3C,CAAC;QACH,CAA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AE,CAAC,CAAC,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { exportTypeSupportsFormatting } from \"../converters/excel/excel-converter.types.js\";\nimport {\n SmeupDataColumn,\n SmeupDataTable,\n SmeupDataCell,\n} from \"../types/data-structures/smeupDataTable.js\";\nimport {\n SmeupDataObj,\n ColumnFilter,\n WebupManagerData,\n SupportedExportFormats,\n GenericObject,\n} from \"../types/index.js\";\nimport { datesIsIsoDate, datesToDate, datesFormat } from \"./dates-utility.js\";\nimport {\n mathNumberStringToFormattedString,\n mathCountDecimals,\n} from \"./math-utility.js\";\nimport {\n objectsIsVoCodVer,\n objectsIsDate,\n objectsIsNumber,\n} from \"./objects-utility.js\";\n\nexport const getFilteredColumns = (\n columns: SmeupDataColumn[],\n props: GenericObject,\n groupsArray: { column: string; visible: boolean }[] = [],\n) => {\n if (!columns) return [];\n\n const mutableColumns = JSON.parse(\n JSON.stringify(columns),\n ) as SmeupDataColumn[];\n\n const filteredColumns: SmeupDataColumn[] = [];\n\n if (props.visibleColumns && (props.visibleColumns as string[]).length > 0) {\n (props.visibleColumns as string[]).forEach((col: string) => {\n const foundColumn = mutableColumns.find(c => c.name === col);\n if (foundColumn) {\n filteredColumns.push({ ...foundColumn });\n }\n });\n } else {\n filteredColumns.push(...mutableColumns);\n }\n\n // Set the visibility of columns based on groups and props\n filteredColumns.forEach((col: SmeupDataColumn) => {\n const isGroupedColumn = groupsArray.filter(g => g.column === col.name);\n col.visible = props.visibleColumns\n ? (props.visibleColumns as string[]).includes(col.name)\n : col.visible;\n col.visible =\n isGroupedColumn.length > 0 ? isGroupedColumn[0].visible : col.visible;\n });\n\n return filteredColumns.filter(column => {\n const dataObject = {\n ...column.obj,\n k: \"\",\n } as SmeupDataObj;\n return column.obj?.t !== \"J4\" && !objectsIsVoCodVer(dataObject);\n });\n};\n\n/**\n * By passing the map, length value and column name\n * creates or updates a map record with\n * @param map Contains columnNames and their longest cell's length\n * @param text The text to use in length calculation\n * @param colName The column to check\n */\nexport const updateMaxValueLength = (\n map: { [key: string]: number },\n text: string | undefined | null,\n colName: string,\n) => {\n if (!map || !text || !colName) return;\n\n const value = Math.max(...text.split(\"\\n\").map(line => line.length));\n if (map[colName]) {\n if (map[colName] < value) {\n map[colName] = value;\n }\n } else {\n map[colName] = value;\n }\n};\n\nexport const filterRows = (\n smeupDataTable: SmeupDataTable,\n filteredColumns: SmeupDataColumn[],\n filters: { [key: string]: ColumnFilter },\n) => {\n if (filters) {\n return smeupDataTable.rows.filter(row => {\n return filteredColumns.every(col => {\n const cellValue = row.cells?.[col.name]?.value;\n const columnFilter = filters[col.name];\n if (columnFilter?.checkBoxes?.length) {\n const allowedValues = columnFilter.checkBoxes.map(item => item.value);\n return (\n typeof cellValue === \"string\" && allowedValues.includes(cellValue)\n );\n }\n return true;\n });\n });\n } else {\n return smeupDataTable.rows;\n }\n};\n\n/**\n * Returns a converted and formatted cell value (string, date, number)\n * @param cell - SmeupDataCell\n * @param bookType - SupportedExportFormats\n * @param webupManagerData - WebupManagerData\n * @returns\n */\nexport const calculateCellValue = (\n cell: SmeupDataCell,\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n if (cell.obj && objectsIsDate(cell.obj) && datesIsIsoDate(cell.value)) {\n return exportTypeSupportsFormatting[bookType]\n ? new Date(datesToDate(cell.value, webupManagerData.datesLocale))\n : datesFormat(cell.value, webupManagerData.datesLocale);\n }\n\n if (cell.obj && objectsIsNumber(cell.obj)) {\n if (!exportTypeSupportsFormatting[bookType]) {\n return (\n mathNumberStringToFormattedString(\n cell.value,\n mathCountDecimals(Number(cell.value) || 0),\n \"\",\n webupManagerData.mathLocale,\n ) || \"\"\n );\n }\n\n const numValue = Number(cell.value);\n return !isNaN(numValue) ? numValue : \"\";\n }\n\n return cell?.value ?? \"\";\n};\n\n/**\n * Conversion from Hexadecimal color to an AlphaRGB\n * @param hex string - Hexadecimal value, it can bot have and don't have the # prefix\n * @returns ARGB string code\n */\nexport const hexToArgb = (hex: string): string => {\n // Hex validation\n if (hex.startsWith(\"#\")) hex = hex.slice(1);\n if (hex.length !== 6) return \"\";\n\n // Value Parse and return\n const red = parseInt(hex.slice(0, 2), 16);\n const green = parseInt(hex.slice(2, 4), 16);\n const blue = parseInt(hex.slice(4, 6), 16);\n return `FF${red.toString(16).padStart(2, \"0\")}${green\n .toString(16)\n .padStart(2, \"0\")}${blue.toString(16).padStart(2, \"0\")}`;\n};\n\n// Utility function to detect if Buffer is available\nconst isBufferAvailable = (): boolean => {\n try {\n return typeof Buffer !== \"undefined\" && typeof Buffer.from === \"function\";\n } catch {\n return false;\n }\n};\n\n// Utility function to convert ArrayBuffer to Buffer or Uint8Array\nexport const convertToBuffer = (\n arrayBuffer: ArrayBuffer,\n): Buffer | Uint8Array => {\n if (isBufferAvailable()) {\n return Buffer.from(arrayBuffer);\n } else {\n return new Uint8Array(arrayBuffer);\n }\n};\n\n// Function to load an image as base64 (browser version, async)\nexport const loadImageAsBase64 = async (\n imageUrl: string,\n): Promise<string | null> => {\n try {\n const response = await fetch(imageUrl);\n if (!response.ok) return null;\n const blob = await response.blob();\n return await new Promise<string | null>((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n resolve(reader.result as string);\n };\n reader.onerror = () => reject(null);\n reader.readAsDataURL(blob);\n });\n } catch (error) {\n console.warn(\"Unable to load asset image:\", error);\n return null;\n }\n};\n\n/**\n * Converts a hexadecimal color string (e.g., \"#RRGGBB\" or \"0xRRGGBB\") to an RGB tuple.\n */\nexport const convertColorToRgb = (color: string): [number, number, number] => {\n const r = parseInt(color.substring(2, 4), 16);\n const g = parseInt(color.substring(4, 6), 16);\n const b = parseInt(color.substring(6, 8), 16);\n return [r, g, b];\n};\n"]}
|
|
@@ -5,6 +5,15 @@ import "dayjs/locale/it.js";
|
|
|
5
5
|
import "dayjs/locale/pl.js";
|
|
6
6
|
import "dayjs/locale/ru.js";
|
|
7
7
|
import "dayjs/locale/zh.js";
|
|
8
|
+
import ExcelJS from "exceljs";
|
|
8
9
|
export declare const datesFormat: (input: dayjs.ConfigType, locale: string, format?: string) => string;
|
|
9
10
|
export declare const datesIsIsoDate: (dateString: string) => boolean;
|
|
10
11
|
export declare const datesToDate: (input: dayjs.ConfigType, locale: string, format?: string) => Date;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if all ExcelJS.Cell values in the array are dates (ExcelJS.ValueType.Date).
|
|
14
|
+
* Accepts an array of ExcelJS.Cell and returns true if all are dates.
|
|
15
|
+
*
|
|
16
|
+
* @param values - Array of ExcelJS.Cell
|
|
17
|
+
* @returns true if all values are dates, false otherwise
|
|
18
|
+
*/
|
|
19
|
+
export declare function areAllValuesDates(values: ExcelJS.Cell[]): boolean;
|