@harbortouch/skytab-analytics-report-utils 0.38.1 → 0.40.0
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/{chunk-MFOOIOP4.js → chunk-HKSLZ6DJ.js} +416 -366
- package/dist/exporters/excel/index.d.cts +2 -2
- package/dist/exporters/excel/index.d.ts +2 -2
- package/dist/exporters/exportBuilder.cjs +99 -28
- package/dist/exporters/exportBuilder.d.cts +5 -5
- package/dist/exporters/exportBuilder.d.ts +5 -5
- package/dist/exporters/exportBuilder.js +46 -25
- package/dist/exporters/pdf/fonts/Lato-Bold.ttf +0 -0
- package/dist/exporters/pdf/fonts/Lato-Regular.ttf +0 -0
- package/dist/exporters/pdf/index.cjs +164 -70
- package/dist/exporters/pdf/index.d.cts +7 -5
- package/dist/exporters/pdf/index.d.ts +7 -5
- package/dist/exporters/pdf/index.js +158 -70
- package/dist/index.cjs +415 -365
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/{report-ZRoya9wR.d.cts → report-BNVH_1-b.d.cts} +13 -1
- package/dist/{report-ZRoya9wR.d.ts → report-BNVH_1-b.d.ts} +13 -1
- package/dist/{types-BPT5hjCR.d.ts → types-MalWTEdo.d.cts} +10 -1
- package/dist/{types-BPT5hjCR.d.cts → types-MalWTEdo.d.ts} +10 -1
- package/package.json +1 -1
|
@@ -33,7 +33,15 @@ __export(pdf_exports, {
|
|
|
33
33
|
PdfExporter: () => PdfExporter
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(pdf_exports);
|
|
36
|
+
|
|
37
|
+
// node_modules/.pnpm/tsup@8.5.1_postcss@8.5.14_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
41
|
+
// src/exporters/pdf/index.ts
|
|
36
42
|
var import_pdfkit = __toESM(require("pdfkit"), 1);
|
|
43
|
+
var import_path = require("path");
|
|
44
|
+
var import_url = require("url");
|
|
37
45
|
|
|
38
46
|
// src/exporters/pdf/pdf.utils.ts
|
|
39
47
|
var sanitizePdfText = (text) => {
|
|
@@ -44,38 +52,75 @@ var sanitizePdfText = (text) => {
|
|
|
44
52
|
return leadingSpaces + text.trimStart().replace(/€/g, "EUR ").replace(
|
|
45
53
|
/[\u{1F300}-\u{1F9FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]|[\u{1F900}-\u{1F9FF}]|[\u{1FA00}-\u{1FA6F}]|[\u{1FA70}-\u{1FAFF}]|[\u{FE00}-\u{FE0F}]|[\u{1F004}]|[\u{1F0CF}]|[\u{1F18E}]|[\u{1F191}-\u{1F19A}]|[\u{1F1E6}-\u{1F1FF}]|[\u{1F201}-\u{1F251}]/gu,
|
|
46
54
|
""
|
|
47
|
-
).replace(/[\x00-\x1F\x7F]/g, " ").replace(/[
|
|
55
|
+
).replace(/[\x00-\x1F\x7F-\x9F]/g, " ").replace(/ /g, " ").replace(/[^\x20-\x7E\xA1-\xFF]/g, "").replace(/\s+/g, " ").trim();
|
|
48
56
|
};
|
|
49
57
|
|
|
58
|
+
// src/exporters/pdf/constants.ts
|
|
59
|
+
var ZOOM_FACTOR = 1.44;
|
|
60
|
+
var FONT_REGULAR = "Lato";
|
|
61
|
+
var FONT_BOLD = "Lato-Bold";
|
|
62
|
+
var DEFAULT_TEXT_COLOR = "#000000";
|
|
63
|
+
var HEADER_BACKGROUND_COLOR = "#f9fafb";
|
|
64
|
+
var ZEBRA_BACKGROUND_COLOR = "#fafbfc";
|
|
65
|
+
var SEPARATOR_COLOR = "#E4E5E5";
|
|
66
|
+
var SECTION_TITLE_FONT_SIZE = 1.17 * 6 * ZOOM_FACTOR;
|
|
67
|
+
var DEFAULT_FONT_SIZE = 5 * ZOOM_FACTOR;
|
|
68
|
+
var BODY_FONT_SIZE = 6 * ZOOM_FACTOR;
|
|
69
|
+
var TABLE_CELL_PADDING = 4;
|
|
70
|
+
var DEFAULT_ROW_HEIGHT = 25;
|
|
71
|
+
var MIN_COLUMN_WIDTH = 35;
|
|
72
|
+
var MARGINS = { top: 30, bottom: 30, left: 30, right: 30 };
|
|
73
|
+
var PAGE_SIZE = "LETTER";
|
|
74
|
+
var PAGE_LAYOUT = "landscape";
|
|
75
|
+
var SECTION_GAP = 18;
|
|
76
|
+
var MIN_SECTION_HEIGHT = 75;
|
|
77
|
+
var HEADER_RULE_COLOR = "#000000";
|
|
78
|
+
var HEADER_RULE_WIDTH = 1.5;
|
|
79
|
+
var HEADER_SPACING_FACTOR = 0.7;
|
|
80
|
+
|
|
50
81
|
// src/exporters/pdf/index.ts
|
|
51
|
-
var
|
|
52
|
-
var FONT_REGULAR = "Helvetica";
|
|
53
|
-
var COLOR_BLACK = "#000000";
|
|
54
|
-
var COLOR_HEADER_BACKGROUND = "#D3D3D3";
|
|
55
|
-
var COLOR_ROW_BACKGROUND_ALTERNATE = "#F5F5F5";
|
|
82
|
+
var FONTS_DIR = (0, import_url.fileURLToPath)(new URL("./fonts", importMetaUrl));
|
|
56
83
|
var PdfExporter = class {
|
|
84
|
+
registerFonts(doc) {
|
|
85
|
+
doc.registerFont(FONT_REGULAR, (0, import_path.join)(FONTS_DIR, "Lato-Regular.ttf"));
|
|
86
|
+
doc.registerFont(FONT_BOLD, (0, import_path.join)(FONTS_DIR, "Lato-Bold.ttf"));
|
|
87
|
+
}
|
|
57
88
|
generate(content) {
|
|
58
|
-
const doc = new import_pdfkit.default({
|
|
89
|
+
const doc = new import_pdfkit.default({
|
|
90
|
+
margin: MARGINS.top,
|
|
91
|
+
size: PAGE_SIZE,
|
|
92
|
+
layout: PAGE_LAYOUT
|
|
93
|
+
});
|
|
94
|
+
this.registerFonts(doc);
|
|
59
95
|
const buffers = [];
|
|
60
96
|
return new Promise((resolve, reject) => {
|
|
61
97
|
doc.on("data", (chunk) => buffers.push(chunk));
|
|
62
98
|
doc.on("end", () => resolve(Buffer.concat(buffers)));
|
|
63
99
|
doc.on("error", reject);
|
|
64
100
|
try {
|
|
101
|
+
const pageBottom = doc.page.height - doc.page.margins.bottom;
|
|
102
|
+
let currentY = doc.page.margins.top;
|
|
65
103
|
content.sections.forEach((section, index) => {
|
|
66
|
-
const
|
|
104
|
+
const sanitized = this.sanitizeSections(section);
|
|
67
105
|
if (index > 0) {
|
|
68
|
-
|
|
106
|
+
if (currentY + SECTION_GAP + MIN_SECTION_HEIGHT > pageBottom) {
|
|
107
|
+
doc.addPage();
|
|
108
|
+
currentY = doc.page.margins.top;
|
|
109
|
+
} else {
|
|
110
|
+
currentY += SECTION_GAP;
|
|
111
|
+
}
|
|
69
112
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
currentY = this.drawSectionTitle(doc, sanitizedSections.title);
|
|
113
|
+
if (sanitized.filters && sanitized.filters.length > 0) {
|
|
114
|
+
currentY = this.drawFilters(doc, sanitized.filters, currentY);
|
|
73
115
|
}
|
|
74
|
-
if (
|
|
75
|
-
currentY = this.
|
|
116
|
+
if (sanitized.appliedFilters !== void 0) {
|
|
117
|
+
currentY = this.drawAppliedFilters(doc, sanitized.appliedFilters, currentY);
|
|
76
118
|
}
|
|
77
|
-
if (
|
|
78
|
-
this.
|
|
119
|
+
if (sanitized.title && sanitized.table) {
|
|
120
|
+
currentY = this.drawSectionTitle(doc, sanitized.title, currentY);
|
|
121
|
+
}
|
|
122
|
+
if (sanitized.table) {
|
|
123
|
+
currentY = this.drawTable(doc, sanitized.table, currentY);
|
|
79
124
|
}
|
|
80
125
|
});
|
|
81
126
|
doc.end();
|
|
@@ -84,21 +129,27 @@ var PdfExporter = class {
|
|
|
84
129
|
}
|
|
85
130
|
});
|
|
86
131
|
}
|
|
87
|
-
sanitizeSections(
|
|
88
|
-
const sanitized = { title: sanitizePdfText(
|
|
89
|
-
if (
|
|
90
|
-
sanitized.filters =
|
|
132
|
+
sanitizeSections(section) {
|
|
133
|
+
const sanitized = { title: sanitizePdfText(section.title) };
|
|
134
|
+
if (section.filters) {
|
|
135
|
+
sanitized.filters = section.filters.map((filter) => ({
|
|
91
136
|
label: sanitizePdfText(filter.label),
|
|
92
137
|
value: sanitizePdfText(filter.value)
|
|
93
138
|
}));
|
|
94
139
|
}
|
|
95
|
-
if (
|
|
140
|
+
if (section.appliedFilters !== void 0) {
|
|
141
|
+
sanitized.appliedFilters = section.appliedFilters.map((filter) => ({
|
|
142
|
+
label: sanitizePdfText(filter.label),
|
|
143
|
+
value: sanitizePdfText(filter.value)
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
if (section.table) {
|
|
96
147
|
sanitized.table = {
|
|
97
|
-
columns:
|
|
148
|
+
columns: section.table.columns.map((col) => ({
|
|
98
149
|
...col,
|
|
99
150
|
header: sanitizePdfText(col.header)
|
|
100
151
|
})),
|
|
101
|
-
rows:
|
|
152
|
+
rows: section.table.rows.map((row) => {
|
|
102
153
|
const sanitizedRow = {};
|
|
103
154
|
for (const [key, value] of Object.entries(row)) {
|
|
104
155
|
sanitizedRow[key] = typeof value === "string" ? sanitizePdfText(value) : value;
|
|
@@ -109,26 +160,45 @@ var PdfExporter = class {
|
|
|
109
160
|
}
|
|
110
161
|
return sanitized;
|
|
111
162
|
}
|
|
112
|
-
drawSectionTitle(doc, title) {
|
|
113
|
-
doc.
|
|
114
|
-
doc.
|
|
115
|
-
|
|
163
|
+
drawSectionTitle(doc, title, startY) {
|
|
164
|
+
const left = doc.page.margins.left;
|
|
165
|
+
const usableWidth = doc.page.width - doc.page.margins.left - doc.page.margins.right;
|
|
166
|
+
doc.fillColor(DEFAULT_TEXT_COLOR).font(FONT_REGULAR).fontSize(SECTION_TITLE_FONT_SIZE).text(title, left, startY, { align: "left", width: usableWidth });
|
|
167
|
+
const spacing = SECTION_TITLE_FONT_SIZE * HEADER_SPACING_FACTOR;
|
|
168
|
+
const ruleY = doc.y + spacing;
|
|
169
|
+
doc.strokeColor(HEADER_RULE_COLOR).lineWidth(HEADER_RULE_WIDTH).moveTo(left, ruleY).lineTo(left + usableWidth, ruleY).stroke();
|
|
170
|
+
return ruleY + spacing;
|
|
116
171
|
}
|
|
117
|
-
drawFilters(doc, filters) {
|
|
118
|
-
doc.
|
|
119
|
-
doc.
|
|
120
|
-
filters.forEach((filter) => {
|
|
121
|
-
|
|
172
|
+
drawFilters(doc, filters, startY) {
|
|
173
|
+
const left = doc.page.margins.left;
|
|
174
|
+
doc.fillColor(DEFAULT_TEXT_COLOR).font(FONT_BOLD).fontSize(BODY_FONT_SIZE);
|
|
175
|
+
filters.forEach((filter, i) => {
|
|
176
|
+
if (i === 0) {
|
|
177
|
+
doc.text(filter.label, left, startY, { continued: true });
|
|
178
|
+
} else {
|
|
179
|
+
doc.font(FONT_BOLD).fontSize(BODY_FONT_SIZE).text(filter.label, { continued: true });
|
|
180
|
+
}
|
|
122
181
|
doc.font(FONT_REGULAR).text(`: ${filter.value}`);
|
|
123
182
|
});
|
|
183
|
+
doc.moveDown(0.5);
|
|
184
|
+
return doc.y;
|
|
185
|
+
}
|
|
186
|
+
drawAppliedFilters(doc, filters, startY) {
|
|
187
|
+
doc.fillColor(DEFAULT_TEXT_COLOR).font(FONT_BOLD).fontSize(BODY_FONT_SIZE).text("Applied Filters:", doc.page.margins.left, startY, { continued: filters.length === 0 });
|
|
188
|
+
if (filters.length === 0) {
|
|
189
|
+
doc.font(FONT_REGULAR).text(" None");
|
|
190
|
+
} else {
|
|
191
|
+
filters.forEach((filter) => {
|
|
192
|
+
doc.font(FONT_BOLD).fontSize(BODY_FONT_SIZE).text(filter.label, { continued: true });
|
|
193
|
+
doc.font(FONT_REGULAR).text(`: ${filter.value}`);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
124
196
|
doc.moveDown(1);
|
|
125
197
|
return doc.y;
|
|
126
198
|
}
|
|
127
|
-
drawTable(doc, table, startY
|
|
199
|
+
drawTable(doc, table, startY) {
|
|
128
200
|
const columns = table.columns.length > 0 ? table.columns.map((c) => ({ ...c })) : [{ header: "No data", key: "no_data", width: 100 }];
|
|
129
201
|
const rows = table.rows ?? [];
|
|
130
|
-
const baseCellPadding = 4;
|
|
131
|
-
const minColumnWidth = 35;
|
|
132
202
|
const columnCount = columns.length;
|
|
133
203
|
const headerFontSize = columnCount > 13 ? 8 : columnCount > 10 ? 9 : columnCount > 7 ? 10 : 11;
|
|
134
204
|
const dataFontSize = columnCount > 13 ? 7 : columnCount > 10 ? 8 : columnCount > 7 ? 9 : 10;
|
|
@@ -149,19 +219,26 @@ var PdfExporter = class {
|
|
|
149
219
|
}
|
|
150
220
|
});
|
|
151
221
|
const contentWidth = Math.max(headerTextWidth, maxDataWidth);
|
|
152
|
-
col.width = Math.max(contentWidth +
|
|
153
|
-
headerMinWidths.set(col, headerMinWidth +
|
|
222
|
+
col.width = Math.max(contentWidth + TABLE_CELL_PADDING * 2 + headerWidthSlack, MIN_COLUMN_WIDTH);
|
|
223
|
+
headerMinWidths.set(col, headerMinWidth + TABLE_CELL_PADDING * 2 + headerWidthSlack);
|
|
154
224
|
});
|
|
155
225
|
const usableWidth = doc.page.width - doc.page.margins.left - doc.page.margins.right;
|
|
156
|
-
const totalColumnWidth = columns.reduce((sum, c) => sum + (c.width ??
|
|
226
|
+
const totalColumnWidth = columns.reduce((sum, c) => sum + (c.width ?? MIN_COLUMN_WIDTH), 0);
|
|
157
227
|
if (totalColumnWidth > usableWidth) {
|
|
158
228
|
const scale = usableWidth / totalColumnWidth;
|
|
159
229
|
columns.forEach((c) => {
|
|
160
|
-
const headerMin = headerMinWidths.get(c) ??
|
|
161
|
-
c.width = Math.max(Math.floor((c.width ??
|
|
230
|
+
const headerMin = headerMinWidths.get(c) ?? MIN_COLUMN_WIDTH;
|
|
231
|
+
c.width = Math.max(Math.floor((c.width ?? MIN_COLUMN_WIDTH) * scale), headerMin, MIN_COLUMN_WIDTH);
|
|
162
232
|
});
|
|
233
|
+
} else if (totalColumnWidth < usableWidth) {
|
|
234
|
+
const scale = usableWidth / totalColumnWidth;
|
|
235
|
+
columns.forEach((c) => {
|
|
236
|
+
c.width = Math.floor((c.width ?? MIN_COLUMN_WIDTH) * scale);
|
|
237
|
+
});
|
|
238
|
+
const expanded = columns.reduce((sum, c) => sum + (c.width ?? 0), 0);
|
|
239
|
+
columns[columns.length - 1].width = (columns[columns.length - 1].width ?? 0) + (usableWidth - expanded);
|
|
163
240
|
}
|
|
164
|
-
const tableWidth = columns.reduce((sum, c) => sum + (c.width ??
|
|
241
|
+
const tableWidth = columns.reduce((sum, c) => sum + (c.width ?? MIN_COLUMN_WIDTH), 0);
|
|
165
242
|
const pageBottom = doc.page.height - doc.page.margins.bottom;
|
|
166
243
|
const calculateRowHeight = (row, isHeader = false) => {
|
|
167
244
|
const fontSize = isHeader ? headerFontSize : dataFontSize;
|
|
@@ -170,17 +247,22 @@ var PdfExporter = class {
|
|
|
170
247
|
columns.forEach((col) => {
|
|
171
248
|
const cellValue = isHeader ? col.header : row?.[col.key] !== void 0 ? String(row[col.key]) : "";
|
|
172
249
|
const textWidth = doc.widthOfString(cellValue);
|
|
173
|
-
const availableWidth = (col.width ??
|
|
250
|
+
const availableWidth = (col.width ?? MIN_COLUMN_WIDTH) - TABLE_CELL_PADDING * 2;
|
|
174
251
|
const lines = Math.ceil(textWidth / availableWidth);
|
|
175
252
|
if (lines > maxLines) {
|
|
176
253
|
maxLines = lines;
|
|
177
254
|
}
|
|
178
255
|
});
|
|
179
|
-
return Math.max(maxLines * (fontSize + 2) +
|
|
256
|
+
return Math.max(maxLines * (fontSize + 2) + TABLE_CELL_PADDING * 2, DEFAULT_ROW_HEIGHT);
|
|
180
257
|
};
|
|
181
258
|
const headerHeight = calculateRowHeight(null, true);
|
|
182
|
-
const drawTableHeader = (y) => this.drawHeader(doc, columns, y, tableWidth, headerHeight,
|
|
183
|
-
let
|
|
259
|
+
const drawTableHeader = (y) => this.drawHeader(doc, columns, y, tableWidth, headerHeight, TABLE_CELL_PADDING, headerFontSize, MIN_COLUMN_WIDTH);
|
|
260
|
+
let tableStartY = startY;
|
|
261
|
+
if (tableStartY + headerHeight > pageBottom) {
|
|
262
|
+
doc.addPage();
|
|
263
|
+
tableStartY = doc.page.margins.top;
|
|
264
|
+
}
|
|
265
|
+
let currentY = drawTableHeader(tableStartY);
|
|
184
266
|
doc.font(FONT_REGULAR).fontSize(dataFontSize);
|
|
185
267
|
rows.forEach((row, rowIndex) => {
|
|
186
268
|
const currentRowHeight = calculateRowHeight(row, false);
|
|
@@ -192,56 +274,68 @@ var PdfExporter = class {
|
|
|
192
274
|
currentY = this.drawRow(
|
|
193
275
|
doc,
|
|
194
276
|
row,
|
|
195
|
-
rowIndex,
|
|
196
277
|
columns,
|
|
197
278
|
currentY,
|
|
198
|
-
tableWidth,
|
|
199
279
|
currentRowHeight,
|
|
200
|
-
|
|
280
|
+
TABLE_CELL_PADDING,
|
|
201
281
|
dataFontSize,
|
|
202
|
-
|
|
282
|
+
MIN_COLUMN_WIDTH,
|
|
283
|
+
rowIndex
|
|
203
284
|
);
|
|
204
285
|
});
|
|
286
|
+
const left = doc.page.margins.left;
|
|
287
|
+
const closingRuleY = currentY + SECTION_TITLE_FONT_SIZE * HEADER_SPACING_FACTOR;
|
|
288
|
+
doc.strokeColor(HEADER_RULE_COLOR).lineWidth(HEADER_RULE_WIDTH).moveTo(left, closingRuleY).lineTo(left + tableWidth, closingRuleY).stroke();
|
|
289
|
+
return closingRuleY;
|
|
205
290
|
}
|
|
206
291
|
drawHeader(doc, columns, startY, tableWidth, headerHeight, cellPadding, headerFontSize, minColumnWidth) {
|
|
207
|
-
|
|
208
|
-
doc.
|
|
209
|
-
|
|
210
|
-
|
|
292
|
+
const left = doc.page.margins.left;
|
|
293
|
+
doc.rect(left, startY, tableWidth, headerHeight).fill(HEADER_BACKGROUND_COLOR);
|
|
294
|
+
doc.strokeColor(SEPARATOR_COLOR).lineWidth(0.5).moveTo(left, startY).lineTo(left + tableWidth, startY).stroke();
|
|
295
|
+
let xPosition = left;
|
|
296
|
+
doc.fillColor(DEFAULT_TEXT_COLOR).font(FONT_BOLD).fontSize(headerFontSize);
|
|
297
|
+
const headerLineHeight = doc.currentLineHeight(true);
|
|
298
|
+
const headerTextY = startY + Math.max((headerHeight - headerLineHeight) / 2, 0);
|
|
211
299
|
columns.forEach((col) => {
|
|
212
|
-
doc.
|
|
213
|
-
doc.text(col.header, xPosition + cellPadding, startY + cellPadding, {
|
|
300
|
+
doc.text(col.header, xPosition + cellPadding, headerTextY, {
|
|
214
301
|
width: (col.width ?? minColumnWidth) - cellPadding * 2,
|
|
302
|
+
height: headerLineHeight,
|
|
215
303
|
align: "left",
|
|
216
|
-
lineBreak: false
|
|
304
|
+
lineBreak: false,
|
|
305
|
+
ellipsis: true
|
|
217
306
|
});
|
|
218
307
|
xPosition += col.width ?? minColumnWidth;
|
|
219
308
|
});
|
|
220
|
-
doc.moveTo(
|
|
221
|
-
doc.moveTo(doc.page.margins.left, startY + headerHeight).lineTo(xPosition, startY + headerHeight).stroke();
|
|
309
|
+
doc.strokeColor(SEPARATOR_COLOR).lineWidth(0.5).moveTo(left, startY + headerHeight).lineTo(left + tableWidth, startY + headerHeight).stroke();
|
|
222
310
|
return startY + headerHeight;
|
|
223
311
|
}
|
|
224
|
-
drawRow(doc, row,
|
|
225
|
-
doc.
|
|
226
|
-
|
|
227
|
-
|
|
312
|
+
drawRow(doc, row, columns, currentY, rowHeight, cellPadding, dataFontSize, minColumnWidth, rowIndex = 0) {
|
|
313
|
+
const left = doc.page.margins.left;
|
|
314
|
+
const tableWidth = columns.reduce((sum, c) => sum + (c.width ?? minColumnWidth), 0);
|
|
315
|
+
if (rowIndex % 2 === 1) {
|
|
316
|
+
doc.rect(left, currentY, tableWidth, rowHeight).fill(ZEBRA_BACKGROUND_COLOR);
|
|
228
317
|
}
|
|
229
|
-
|
|
230
|
-
doc.
|
|
231
|
-
|
|
232
|
-
|
|
318
|
+
doc.font(FONT_REGULAR).fontSize(dataFontSize).fillColor(DEFAULT_TEXT_COLOR);
|
|
319
|
+
const dataLineHeight = doc.currentLineHeight(true);
|
|
320
|
+
const dataTextY = currentY + Math.max((rowHeight - dataLineHeight) / 2, 0);
|
|
321
|
+
let xPosition = left;
|
|
322
|
+
columns.forEach((col, i) => {
|
|
233
323
|
const rawValue = row[col.key];
|
|
234
324
|
const cellValue = typeof rawValue === "string" || typeof rawValue === "number" || typeof rawValue === "boolean" ? String(rawValue) : "";
|
|
235
325
|
const isNumeric = typeof rawValue === "number" || typeof rawValue === "string" && rawValue !== "" && !isNaN(Number(rawValue));
|
|
236
|
-
doc.text(cellValue, xPosition + cellPadding,
|
|
326
|
+
doc.text(cellValue, xPosition + cellPadding, dataTextY, {
|
|
237
327
|
width: (col.width ?? minColumnWidth) - cellPadding * 2,
|
|
328
|
+
height: dataLineHeight,
|
|
238
329
|
align: isNumeric ? "right" : "left",
|
|
239
|
-
lineBreak: false
|
|
330
|
+
lineBreak: false,
|
|
331
|
+
ellipsis: true
|
|
240
332
|
});
|
|
241
333
|
xPosition += col.width ?? minColumnWidth;
|
|
334
|
+
if (i < columns.length - 1) {
|
|
335
|
+
doc.strokeColor(SEPARATOR_COLOR).lineWidth(0.5).moveTo(xPosition, currentY).lineTo(xPosition, currentY + rowHeight).stroke();
|
|
336
|
+
}
|
|
242
337
|
});
|
|
243
|
-
doc.moveTo(
|
|
244
|
-
doc.moveTo(doc.page.margins.left, currentY + rowHeight).lineTo(xPosition, currentY + rowHeight).stroke();
|
|
338
|
+
doc.strokeColor(SEPARATOR_COLOR).lineWidth(0.5).moveTo(left, currentY + rowHeight).lineTo(left + tableWidth, currentY + rowHeight).stroke();
|
|
245
339
|
return currentY + rowHeight;
|
|
246
340
|
}
|
|
247
341
|
};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ExportSection, E as ExportFilter, b as ExportTable, c as ExportTableColumn } from '../../types-MalWTEdo.cjs';
|
|
2
2
|
|
|
3
3
|
declare class PdfExporter {
|
|
4
|
+
registerFonts(doc: PDFKit.PDFDocument): void;
|
|
4
5
|
generate(content: {
|
|
5
6
|
sections: ExportSection[];
|
|
6
7
|
}): Promise<Buffer>;
|
|
7
8
|
private sanitizeSections;
|
|
8
|
-
drawSectionTitle(doc: PDFKit.PDFDocument, title: string): number;
|
|
9
|
-
drawFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[]): number;
|
|
10
|
-
|
|
9
|
+
drawSectionTitle(doc: PDFKit.PDFDocument, title: string, startY: number): number;
|
|
10
|
+
drawFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[], startY: number): number;
|
|
11
|
+
drawAppliedFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[], startY: number): number;
|
|
12
|
+
drawTable(doc: PDFKit.PDFDocument, table: ExportTable, startY: number): number;
|
|
11
13
|
drawHeader(doc: PDFKit.PDFDocument, columns: ExportTableColumn[], startY: number, tableWidth: number, headerHeight: number, cellPadding: number, headerFontSize: number, minColumnWidth: number): number;
|
|
12
|
-
drawRow(doc: PDFKit.PDFDocument, row: Record<string, unknown>,
|
|
14
|
+
drawRow(doc: PDFKit.PDFDocument, row: Record<string, unknown>, columns: ExportTableColumn[], currentY: number, rowHeight: number, cellPadding: number, dataFontSize: number, minColumnWidth: number, rowIndex?: number): number;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export { PdfExporter, ExportFilter as PdfFilter, ExportSection as PdfSection, ExportTable as PdfTable, ExportTableColumn as PdfTableColumn };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ExportSection, E as ExportFilter, b as ExportTable, c as ExportTableColumn } from '../../types-MalWTEdo.js';
|
|
2
2
|
|
|
3
3
|
declare class PdfExporter {
|
|
4
|
+
registerFonts(doc: PDFKit.PDFDocument): void;
|
|
4
5
|
generate(content: {
|
|
5
6
|
sections: ExportSection[];
|
|
6
7
|
}): Promise<Buffer>;
|
|
7
8
|
private sanitizeSections;
|
|
8
|
-
drawSectionTitle(doc: PDFKit.PDFDocument, title: string): number;
|
|
9
|
-
drawFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[]): number;
|
|
10
|
-
|
|
9
|
+
drawSectionTitle(doc: PDFKit.PDFDocument, title: string, startY: number): number;
|
|
10
|
+
drawFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[], startY: number): number;
|
|
11
|
+
drawAppliedFilters(doc: PDFKit.PDFDocument, filters: ExportFilter[], startY: number): number;
|
|
12
|
+
drawTable(doc: PDFKit.PDFDocument, table: ExportTable, startY: number): number;
|
|
11
13
|
drawHeader(doc: PDFKit.PDFDocument, columns: ExportTableColumn[], startY: number, tableWidth: number, headerHeight: number, cellPadding: number, headerFontSize: number, minColumnWidth: number): number;
|
|
12
|
-
drawRow(doc: PDFKit.PDFDocument, row: Record<string, unknown>,
|
|
14
|
+
drawRow(doc: PDFKit.PDFDocument, row: Record<string, unknown>, columns: ExportTableColumn[], currentY: number, rowHeight: number, cellPadding: number, dataFontSize: number, minColumnWidth: number, rowIndex?: number): number;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export { PdfExporter, ExportFilter as PdfFilter, ExportSection as PdfSection, ExportTable as PdfTable, ExportTableColumn as PdfTableColumn };
|