@tectra-ng/ui 0.1.2 → 0.1.3
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/README.md +36 -19
- package/analog-clock/README.md +31 -0
- package/countdown/README.md +45 -0
- package/datepicker/README.md +109 -0
- package/export/README.md +79 -0
- package/export-font/OFL.txt +93 -0
- package/export-font/README.md +7 -0
- package/fesm2022/tectra-ng-ui-analog-clock.mjs +386 -0
- package/fesm2022/tectra-ng-ui-analog-clock.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-countdown.mjs +513 -0
- package/fesm2022/tectra-ng-ui-countdown.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-datepicker.mjs +2640 -0
- package/fesm2022/tectra-ng-ui-datepicker.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-export-font.mjs +7 -0
- package/fesm2022/tectra-ng-ui-export-font.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-export.mjs +2574 -0
- package/fesm2022/tectra-ng-ui-export.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-label.mjs +4 -4
- package/fesm2022/tectra-ng-ui-label.mjs.map +1 -1
- package/fesm2022/tectra-ng-ui-month-calendar.mjs +601 -0
- package/fesm2022/tectra-ng-ui-month-calendar.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-sparkline.mjs +240 -0
- package/fesm2022/tectra-ng-ui-sparkline.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-stat-tiles.mjs +661 -0
- package/fesm2022/tectra-ng-ui-stat-tiles.mjs.map +1 -0
- package/fesm2022/tectra-ng-ui-table.mjs +1 -21
- package/fesm2022/tectra-ng-ui-table.mjs.map +1 -1
- package/fesm2022/tectra-ng-ui-timeline.mjs +407 -0
- package/fesm2022/tectra-ng-ui-timeline.mjs.map +1 -0
- package/month-calendar/README.md +46 -0
- package/package.json +40 -4
- package/sparkline/README.md +27 -0
- package/stat-tiles/README.md +53 -0
- package/timeline/README.md +42 -0
- package/types/tectra-ng-ui-analog-clock.d.ts +127 -0
- package/types/tectra-ng-ui-analog-clock.d.ts.map +1 -0
- package/types/tectra-ng-ui-countdown.d.ts +150 -0
- package/types/tectra-ng-ui-countdown.d.ts.map +1 -0
- package/types/tectra-ng-ui-datepicker.d.ts +801 -0
- package/types/tectra-ng-ui-datepicker.d.ts.map +1 -0
- package/types/tectra-ng-ui-export-font.d.ts +5 -0
- package/types/tectra-ng-ui-export-font.d.ts.map +1 -0
- package/types/tectra-ng-ui-export.d.ts +427 -0
- package/types/tectra-ng-ui-export.d.ts.map +1 -0
- package/types/tectra-ng-ui-month-calendar.d.ts +287 -0
- package/types/tectra-ng-ui-month-calendar.d.ts.map +1 -0
- package/types/tectra-ng-ui-sparkline.d.ts +80 -0
- package/types/tectra-ng-ui-sparkline.d.ts.map +1 -0
- package/types/tectra-ng-ui-stat-tiles.d.ts +287 -0
- package/types/tectra-ng-ui-stat-tiles.d.ts.map +1 -0
- package/types/tectra-ng-ui-timeline.d.ts +129 -0
- package/types/tectra-ng-ui-timeline.d.ts.map +1 -0
|
@@ -0,0 +1,2574 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DOCUMENT, Directive, Injectable, InjectionToken, booleanAttribute, computed, inject, input, model, output, signal } from "@angular/core";
|
|
3
|
+
import { TxLocaleService, injectTranslations } from "@tectra-ng/core/i18n";
|
|
4
|
+
import { TxAnnouncer } from "@tectra-ng/core/a11y";
|
|
5
|
+
import { optionalBoolean } from "@tectra-ng/core/utils";
|
|
6
|
+
import { injectPassThrough } from "@tectra-ng/core/config";
|
|
7
|
+
import { TxButton } from "@tectra-ng/ui/button";
|
|
8
|
+
import { TxTooltip } from "@tectra-ng/ui/tooltip";
|
|
9
|
+
import { TxSplitButton } from "@tectra-ng/ui/split-button";
|
|
10
|
+
const FORMULA = /^[=+\-@\t\r]/;
|
|
11
|
+
const NUMBER$1 = /^[+-]?\d+([.,]\d+)?$/;
|
|
12
|
+
const INDEX_FIELDS = /* @__PURE__ */ new Set(["number", "place"]);
|
|
13
|
+
function readExportField(row, field) {
|
|
14
|
+
if (row === null || row === void 0) return void 0;
|
|
15
|
+
const record = row;
|
|
16
|
+
if (field in record) return record[field];
|
|
17
|
+
return field.split(".").reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], row);
|
|
18
|
+
}
|
|
19
|
+
function fieldsFor(fields, format) {
|
|
20
|
+
return fields.filter((field) => !format || !field.formats || field.formats.includes(format));
|
|
21
|
+
}
|
|
22
|
+
function exportMatrix(rows, fields, format) {
|
|
23
|
+
const table = buildExportTable(rows, fields, format);
|
|
24
|
+
return [table.columns.map((column) => column.title), ...table.rows];
|
|
25
|
+
}
|
|
26
|
+
function buildExportTable(rows, fields, format) {
|
|
27
|
+
const used = fieldsFor(fields, format);
|
|
28
|
+
const body = rows.map((row, index) => used.map(({ field, aggregator }) => {
|
|
29
|
+
const value = readExportField(row, field);
|
|
30
|
+
if (aggregator) return aggregator(value, row, index);
|
|
31
|
+
return INDEX_FIELDS.has(field) ? index + 1 : value;
|
|
32
|
+
}));
|
|
33
|
+
return {
|
|
34
|
+
columns: used.map((field, column) => {
|
|
35
|
+
const type = field.type ?? inferType(body.map((row) => row[column]));
|
|
36
|
+
return {
|
|
37
|
+
key: field.field,
|
|
38
|
+
title: field.title || field.field,
|
|
39
|
+
type,
|
|
40
|
+
width: field.width,
|
|
41
|
+
align: field.align ?? defaultAlign(type),
|
|
42
|
+
format: field.format
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
rows: body
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function inferType(values) {
|
|
49
|
+
const present = values.filter((value) => value !== null && value !== void 0 && value !== "");
|
|
50
|
+
if (!present.length) return "text";
|
|
51
|
+
if (present.every((value) => typeof value === "number" && Number.isFinite(value))) return "number";
|
|
52
|
+
if (present.every((value) => typeof value === "boolean")) return "boolean";
|
|
53
|
+
if (present.every((value) => value instanceof Date && !Number.isNaN(value.getTime()))) return present.some((value) => hasTime(value)) ? "datetime" : "date";
|
|
54
|
+
return "text";
|
|
55
|
+
}
|
|
56
|
+
function defaultAlign(type) {
|
|
57
|
+
if (type === "number") return "end";
|
|
58
|
+
if (type === "boolean") return "center";
|
|
59
|
+
return "start";
|
|
60
|
+
}
|
|
61
|
+
function hasTime(date) {
|
|
62
|
+
return date.getHours() !== 0 || date.getMinutes() !== 0 || date.getSeconds() !== 0 || date.getMilliseconds() !== 0;
|
|
63
|
+
}
|
|
64
|
+
function toDate(value) {
|
|
65
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;
|
|
66
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
67
|
+
const date = new Date(value);
|
|
68
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function cellText(value, column, context) {
|
|
73
|
+
if (value === null || value === void 0) return "";
|
|
74
|
+
if (column.type === "boolean" && typeof value === "boolean") return value ? context.yes : context.no;
|
|
75
|
+
if (column.type === "date" || column.type === "datetime" || value instanceof Date) {
|
|
76
|
+
const date = toDate(value);
|
|
77
|
+
if (date) return column.type === "datetime" || column.type !== "date" && hasTime(date) ? date.toLocaleString(context.locale, {
|
|
78
|
+
dateStyle: "medium",
|
|
79
|
+
timeStyle: "short"
|
|
80
|
+
}) : date.toLocaleDateString(context.locale, { dateStyle: "medium" });
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
83
|
+
return String(value);
|
|
84
|
+
}
|
|
85
|
+
function localIso(value, type) {
|
|
86
|
+
if (!(value instanceof Date) || Number.isNaN(value.getTime())) return value;
|
|
87
|
+
const pad = (part) => String(part).padStart(2, "0");
|
|
88
|
+
const day = `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
|
|
89
|
+
if (type === "date" || type !== "datetime" && !hasTime(value)) return day;
|
|
90
|
+
return `${day} ${pad(value.getHours())}:${pad(value.getMinutes())}${value.getSeconds() ? `:${pad(value.getSeconds())}` : ""}`;
|
|
91
|
+
}
|
|
92
|
+
function safeExportText(text) {
|
|
93
|
+
return FORMULA.test(text) && text.length > 1 && !NUMBER$1.test(text) ? `'${text}` : text;
|
|
94
|
+
}
|
|
95
|
+
function csvCell(value, separator = ",", options = {}) {
|
|
96
|
+
if (value === null || value === void 0) return options.quoteAll ? "\"\"" : "";
|
|
97
|
+
const raw = value instanceof Date ? value.toISOString() : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
98
|
+
const text = options.formulaGuard === false ? raw : safeExportText(raw);
|
|
99
|
+
return options.quoteAll || /["\r\n]/.test(text) || text.includes(separator) ? `"${text.replace(/"/g, "\"\"")}"` : text;
|
|
100
|
+
}
|
|
101
|
+
function matrixToCsv(matrix, separator = ",") {
|
|
102
|
+
return matrix.map((row) => row.map((cell) => csvCell(cell, separator)).join(separator)).join("\r\n");
|
|
103
|
+
}
|
|
104
|
+
function withExtension(filename, extension) {
|
|
105
|
+
return filename.toLowerCase().endsWith(`.${extension}`) ? filename : `${filename}.${extension}`;
|
|
106
|
+
}
|
|
107
|
+
function downloadBlob(document, blob, filename) {
|
|
108
|
+
const view = document.defaultView;
|
|
109
|
+
if (!view?.URL?.createObjectURL) return;
|
|
110
|
+
const url = view.URL.createObjectURL(blob);
|
|
111
|
+
const link = document.createElement("a");
|
|
112
|
+
link.href = url;
|
|
113
|
+
link.download = filename;
|
|
114
|
+
link.style.display = "none";
|
|
115
|
+
document.body.appendChild(link);
|
|
116
|
+
link.click();
|
|
117
|
+
link.remove();
|
|
118
|
+
view.setTimeout(() => view.URL.revokeObjectURL(url), 1e3);
|
|
119
|
+
}
|
|
120
|
+
function downloadCsv(document, csv, filename) {
|
|
121
|
+
downloadBlob(document, new Blob(["", csv], { type: "text/csv;charset=utf-8" }), withExtension(filename, "csv"));
|
|
122
|
+
}
|
|
123
|
+
function escapeXml(text) {
|
|
124
|
+
return text.replace(/[^\t\n\r --�\u{10000}-\u{10FFFF}]/gu, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
125
|
+
}
|
|
126
|
+
function hexColor(color, fallback) {
|
|
127
|
+
const value = (color ?? fallback).replace("#", "").trim();
|
|
128
|
+
const full = value.length === 3 ? value.replace(/./g, (char) => char + char) : value;
|
|
129
|
+
return /^[0-9a-f]{6}$/i.test(full) ? full.toUpperCase() : fallback.replace("#", "").toUpperCase();
|
|
130
|
+
}
|
|
131
|
+
const SIZES = {
|
|
132
|
+
a3: [841.89, 1190.55],
|
|
133
|
+
a4: [595.28, 841.89],
|
|
134
|
+
a5: [419.53, 595.28],
|
|
135
|
+
letter: [612, 792],
|
|
136
|
+
legal: [612, 1008]
|
|
137
|
+
};
|
|
138
|
+
function pageGeometry(size, orientation, margin, columns) {
|
|
139
|
+
const [short, long] = typeof size === "object" ? [Math.min(...size), Math.max(...size)] : SIZES[size ?? "a4"];
|
|
140
|
+
const landscape = orientation === "landscape" || orientation !== "portrait" && columns > 5;
|
|
141
|
+
const edges = margin ?? 36;
|
|
142
|
+
return {
|
|
143
|
+
width: landscape ? long : short,
|
|
144
|
+
height: landscape ? short : long,
|
|
145
|
+
margin: typeof edges === "number" ? [
|
|
146
|
+
edges,
|
|
147
|
+
edges,
|
|
148
|
+
edges,
|
|
149
|
+
edges
|
|
150
|
+
] : [
|
|
151
|
+
edges[0],
|
|
152
|
+
edges[1],
|
|
153
|
+
edges[2],
|
|
154
|
+
edges[3]
|
|
155
|
+
],
|
|
156
|
+
landscape
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function dateLine(options, context, date) {
|
|
160
|
+
return options.showDate ? date.toLocaleString(context.locale, {
|
|
161
|
+
dateStyle: "medium",
|
|
162
|
+
timeStyle: "short"
|
|
163
|
+
}) : null;
|
|
164
|
+
}
|
|
165
|
+
function columnShares(table, texts) {
|
|
166
|
+
return table.columns.map((column, index) => {
|
|
167
|
+
if (column.width) return column.width;
|
|
168
|
+
const longest = Math.max(column.title.length, ...texts.slice(0, 500).map((row) => Math.max(...row[index].split("\n").map((line) => line.length))));
|
|
169
|
+
return Math.min(40, Math.max(4, longest));
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const encoder = new TextEncoder();
|
|
173
|
+
function utf8(text) {
|
|
174
|
+
return encoder.encode(text);
|
|
175
|
+
}
|
|
176
|
+
function concatBytes(parts) {
|
|
177
|
+
const length = parts.reduce((sum, part) => sum + part.length, 0);
|
|
178
|
+
const out = new Uint8Array(length);
|
|
179
|
+
let offset = 0;
|
|
180
|
+
for (const part of parts) {
|
|
181
|
+
out.set(part, offset);
|
|
182
|
+
offset += part.length;
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
function toArrayBuffer(bytes) {
|
|
187
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
188
|
+
}
|
|
189
|
+
async function compress(bytes, format) {
|
|
190
|
+
if (typeof CompressionStream === "undefined") return null;
|
|
191
|
+
try {
|
|
192
|
+
const stream = new Blob([toArrayBuffer(bytes)]).stream().pipeThrough(new CompressionStream(format));
|
|
193
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function base64ToBytes(base64) {
|
|
199
|
+
const binary = atob(base64);
|
|
200
|
+
const bytes = new Uint8Array(binary.length);
|
|
201
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
202
|
+
return bytes;
|
|
203
|
+
}
|
|
204
|
+
const CRC_TABLE = (() => {
|
|
205
|
+
const table = /* @__PURE__ */ new Uint32Array(256);
|
|
206
|
+
for (let n = 0; n < 256; n++) {
|
|
207
|
+
let c = n;
|
|
208
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
209
|
+
table[n] = c >>> 0;
|
|
210
|
+
}
|
|
211
|
+
return table;
|
|
212
|
+
})();
|
|
213
|
+
function crc32(bytes) {
|
|
214
|
+
let crc = 4294967295;
|
|
215
|
+
for (let index = 0; index < bytes.length; index++) crc = CRC_TABLE[(crc ^ bytes[index]) & 255] ^ crc >>> 8;
|
|
216
|
+
return (crc ^ 4294967295) >>> 0;
|
|
217
|
+
}
|
|
218
|
+
function dosDateTime(date) {
|
|
219
|
+
return [date.getHours() << 11 | date.getMinutes() << 5 | Math.floor(date.getSeconds() / 2), Math.max(1980, date.getFullYear()) - 1980 << 9 | date.getMonth() + 1 << 5 | date.getDate()];
|
|
220
|
+
}
|
|
221
|
+
async function zip(entries, date = /* @__PURE__ */ new Date(), deflate = true) {
|
|
222
|
+
const [time, day] = dosDateTime(date);
|
|
223
|
+
const locals = [];
|
|
224
|
+
const centrals = [];
|
|
225
|
+
let offset = 0;
|
|
226
|
+
for (const entry of entries) {
|
|
227
|
+
const name = utf8(entry.name);
|
|
228
|
+
const data = typeof entry.data === "string" ? utf8(entry.data) : entry.data;
|
|
229
|
+
const deflated = deflate ? await compress(data, "deflate-raw") : null;
|
|
230
|
+
const stored = !deflated || deflated.length >= data.length;
|
|
231
|
+
const body = stored ? data : deflated;
|
|
232
|
+
const method = stored ? 0 : 8;
|
|
233
|
+
const crc = crc32(data);
|
|
234
|
+
const local = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(30));
|
|
235
|
+
local.setUint32(0, 67324752, true);
|
|
236
|
+
local.setUint16(4, 20, true);
|
|
237
|
+
local.setUint16(6, 2048, true);
|
|
238
|
+
local.setUint16(8, method, true);
|
|
239
|
+
local.setUint16(10, time, true);
|
|
240
|
+
local.setUint16(12, day, true);
|
|
241
|
+
local.setUint32(14, crc, true);
|
|
242
|
+
local.setUint32(18, body.length, true);
|
|
243
|
+
local.setUint32(22, data.length, true);
|
|
244
|
+
local.setUint16(26, name.length, true);
|
|
245
|
+
locals.push(new Uint8Array(local.buffer), name, body);
|
|
246
|
+
const central = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(46));
|
|
247
|
+
central.setUint32(0, 33639248, true);
|
|
248
|
+
central.setUint16(4, 20, true);
|
|
249
|
+
central.setUint16(6, 20, true);
|
|
250
|
+
central.setUint16(8, 2048, true);
|
|
251
|
+
central.setUint16(10, method, true);
|
|
252
|
+
central.setUint16(12, time, true);
|
|
253
|
+
central.setUint16(14, day, true);
|
|
254
|
+
central.setUint32(16, crc, true);
|
|
255
|
+
central.setUint32(20, body.length, true);
|
|
256
|
+
central.setUint32(24, data.length, true);
|
|
257
|
+
central.setUint16(28, name.length, true);
|
|
258
|
+
central.setUint32(42, offset, true);
|
|
259
|
+
centrals.push(new Uint8Array(central.buffer), name);
|
|
260
|
+
offset += 30 + name.length + body.length;
|
|
261
|
+
}
|
|
262
|
+
const directory = concatBytes(centrals);
|
|
263
|
+
const end = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(22));
|
|
264
|
+
end.setUint32(0, 101010256, true);
|
|
265
|
+
end.setUint16(8, entries.length, true);
|
|
266
|
+
end.setUint16(10, entries.length, true);
|
|
267
|
+
end.setUint32(12, directory.length, true);
|
|
268
|
+
end.setUint32(16, offset, true);
|
|
269
|
+
return concatBytes([
|
|
270
|
+
...locals,
|
|
271
|
+
directory,
|
|
272
|
+
new Uint8Array(end.buffer)
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
const W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
276
|
+
const R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
277
|
+
const PKG_REL$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
278
|
+
function run(text, props) {
|
|
279
|
+
return `<w:r><w:rPr>${props}</w:rPr>${text.split("\n").map((line, index) => `${index ? "<w:br/>" : ""}<w:t xml:space="preserve">${escapeXml(line)}</w:t>`).join("")}</w:r>`;
|
|
280
|
+
}
|
|
281
|
+
function paragraph(text, props, spacingAfter = 0, align) {
|
|
282
|
+
return `<w:p><w:pPr><w:spacing w:before="0" w:after="${spacingAfter}"/>${align ? `<w:jc w:val="${align}"/>` : ""}</w:pPr>${run(text, props)}</w:p>`;
|
|
283
|
+
}
|
|
284
|
+
function jc(align) {
|
|
285
|
+
return align === "end" ? "right" : align === "center" ? "center" : void 0;
|
|
286
|
+
}
|
|
287
|
+
function docxDocument(table, options, context, date) {
|
|
288
|
+
const fontSize = options.fontSize ?? 10;
|
|
289
|
+
const half = Math.round(fontSize * 2);
|
|
290
|
+
const text = hexColor(options.textColor, "1D2939");
|
|
291
|
+
const muted = hexColor(options.mutedColor, "667085");
|
|
292
|
+
const border = hexColor(options.borderColor, "D0D5DD");
|
|
293
|
+
const headerFill = options.headerBackground === "none" ? null : hexColor(options.headerBackground, "F2F4F7");
|
|
294
|
+
const stripeFill = hexColor(options.stripeBackground, "F9FAFB");
|
|
295
|
+
const page = pageGeometry(options.pageSize, options.orientation, options.margin, table.columns.length);
|
|
296
|
+
const twips = (points) => Math.round(points * 20);
|
|
297
|
+
const contentWidth = twips(page.width - page.margin[1] - page.margin[3]);
|
|
298
|
+
const texts = table.rows.map((row) => table.columns.map((column, index) => cellText(row[index], column, context)));
|
|
299
|
+
const shares = columnShares(table, texts);
|
|
300
|
+
const total = shares.reduce((sum, share) => sum + share, 0) || 1;
|
|
301
|
+
const widths = shares.map((share) => Math.floor(contentWidth * share / total));
|
|
302
|
+
const percents = shares.map((share) => Math.floor(5e3 * share / total));
|
|
303
|
+
const body = `<w:color w:val="${text}"/><w:sz w:val="${half}"/><w:szCs w:val="${half}"/>`;
|
|
304
|
+
const line = `w:val="single" w:sz="4" w:space="0" w:color="${border}"`;
|
|
305
|
+
const borders = options.gridlines === false ? `<w:top ${line}/><w:bottom ${line}/><w:insideH ${line}/>` : `<w:top ${line}/><w:left ${line}/><w:bottom ${line}/><w:right ${line}/><w:insideH ${line}/><w:insideV ${line}/>`;
|
|
306
|
+
const cell = (value, index, props, fill) => `<w:tc><w:tcPr><w:tcW w:w="${percents[index]}" w:type="pct"/>${fill ? `<w:shd w:val="clear" w:color="auto" w:fill="${fill}"/>` : ""}</w:tcPr><w:p><w:pPr><w:spacing w:before="0" w:after="0"/>${jc(table.columns[index].align) ? `<w:jc w:val="${jc(table.columns[index].align)}"/>` : ""}</w:pPr>${run(value, props)}</w:p></w:tc>`;
|
|
307
|
+
const rows = [];
|
|
308
|
+
if (options.header !== false) {
|
|
309
|
+
const header = table.columns.map((column, index) => cell(column.title, index, `<w:b/><w:bCs/>${body}`, headerFill)).join("");
|
|
310
|
+
rows.push(`<w:tr><w:trPr>${options.repeatHeader === false ? "" : "<w:tblHeader/>"}<w:cantSplit/></w:trPr>${header}</w:tr>`);
|
|
311
|
+
}
|
|
312
|
+
texts.forEach((values, rowIndex) => {
|
|
313
|
+
const fill = options.striped && rowIndex % 2 === 1 ? stripeFill : null;
|
|
314
|
+
rows.push(`<w:tr><w:trPr><w:cantSplit/></w:trPr>${values.map((value, index) => cell(value, index, body, fill)).join("")}</w:tr>`);
|
|
315
|
+
});
|
|
316
|
+
const heading = [];
|
|
317
|
+
if (options.title) heading.push(paragraph(options.title, `<w:b/><w:bCs/><w:color w:val="${text}"/><w:sz w:val="${Math.round(half * 1.6)}"/>`, 60));
|
|
318
|
+
if (options.subtitle) heading.push(paragraph(options.subtitle, `<w:color w:val="${muted}"/><w:sz w:val="${half}"/>`, 40));
|
|
319
|
+
const stamp = dateLine(options, context, date);
|
|
320
|
+
if (stamp) heading.push(paragraph(stamp, `<w:color w:val="${muted}"/><w:sz w:val="${Math.round(half * .85)}"/>`, 40));
|
|
321
|
+
if (heading.length) heading.push(`<w:p><w:pPr><w:spacing w:before="0" w:after="120"/></w:pPr></w:p>`);
|
|
322
|
+
const orient = page.landscape ? " w:orient=\"landscape\"" : "";
|
|
323
|
+
const [top, right, bottom, left] = page.margin.map(twips);
|
|
324
|
+
const section = `<w:sectPr>${options.pageNumbers === false ? "" : "<w:footerReference w:type=\"default\" r:id=\"rId1\"/>"}<w:pgSz w:w="${twips(page.width)}" w:h="${twips(page.height)}"${orient}/><w:pgMar w:top="${top}" w:right="${right}" w:bottom="${bottom}" w:left="${left}" w:header="${Math.round(top / 2)}" w:footer="${Math.round(bottom / 2)}" w:gutter="0"/></w:sectPr>`;
|
|
325
|
+
const tableXml = table.columns.length ? `<w:tbl><w:tblPr><w:tblW w:w="5000" w:type="pct"/><w:tblLayout w:type="fixed"/><w:tblBorders>${borders}</w:tblBorders><w:tblCellMar><w:top w:w="40" w:type="dxa"/><w:left w:w="80" w:type="dxa"/><w:bottom w:w="40" w:type="dxa"/><w:right w:w="80" w:type="dxa"/></w:tblCellMar></w:tblPr><w:tblGrid>${widths.map((width) => `<w:gridCol w:w="${width}"/>`).join("")}</w:tblGrid>${rows.join("")}</w:tbl>` : "";
|
|
326
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:document xmlns:w="${W}" xmlns:r="${R}"><w:body>${heading.join("")}${tableXml}<w:p/>${section}</w:body></w:document>`;
|
|
327
|
+
}
|
|
328
|
+
function docxFooter(options) {
|
|
329
|
+
const half = Math.round((options.fontSize ?? 10) * 1.7);
|
|
330
|
+
const props = `<w:color w:val="${hexColor(options.mutedColor, "667085")}"/><w:sz w:val="${half}"/>`;
|
|
331
|
+
const field = (code) => `<w:fldSimple w:instr=" ${code} "><w:r><w:rPr>${props}</w:rPr><w:t>1</w:t></w:r></w:fldSimple>`;
|
|
332
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:ftr xmlns:w="${W}" xmlns:r="${R}"><w:p><w:pPr><w:jc w:val="center"/></w:pPr>${field("PAGE")}<w:r><w:rPr>${props}</w:rPr><w:t xml:space="preserve"> / </w:t></w:r>${field("NUMPAGES")}</w:p></w:ftr>`;
|
|
333
|
+
}
|
|
334
|
+
async function writeDocx(table, options = {}, context = {
|
|
335
|
+
yes: "Yes",
|
|
336
|
+
no: "No"
|
|
337
|
+
}, date = /* @__PURE__ */ new Date()) {
|
|
338
|
+
const pageNumbers = options.pageNumbers !== false;
|
|
339
|
+
const created = date.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
340
|
+
const core = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">` + (options.title ? `<dc:title>${escapeXml(options.title)}</dc:title>` : "") + `<dcterms:created xsi:type="dcterms:W3CDTF">${created}</dcterms:created></cp:coreProperties>`;
|
|
341
|
+
const bytes = await zip([
|
|
342
|
+
{
|
|
343
|
+
name: "[Content_Types].xml",
|
|
344
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>${pageNumbers ? "<Override PartName=\"/word/footer1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml\"/>" : ""}<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/></Types>`
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "_rels/.rels",
|
|
348
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="${PKG_REL$1}"><Relationship Id="rId1" Type="${R}/officeDocument" Target="word/document.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>`
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
name: "docProps/core.xml",
|
|
352
|
+
data: core
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: "word/document.xml",
|
|
356
|
+
data: docxDocument(table, {
|
|
357
|
+
...options,
|
|
358
|
+
pageNumbers
|
|
359
|
+
}, context, date)
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
name: "word/_rels/document.xml.rels",
|
|
363
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="${PKG_REL$1}">${pageNumbers ? `<Relationship Id="rId1" Type="${R}/footer" Target="footer1.xml"/>` : ""}</Relationships>`
|
|
364
|
+
},
|
|
365
|
+
...pageNumbers ? [{
|
|
366
|
+
name: "word/footer1.xml",
|
|
367
|
+
data: docxFooter(options)
|
|
368
|
+
}] : []
|
|
369
|
+
], date, options.compress !== false);
|
|
370
|
+
return new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
|
|
371
|
+
}
|
|
372
|
+
const KEEP_TABLES = [
|
|
373
|
+
"OS/2",
|
|
374
|
+
"cmap",
|
|
375
|
+
"cvt ",
|
|
376
|
+
"fpgm",
|
|
377
|
+
"gasp",
|
|
378
|
+
"glyf",
|
|
379
|
+
"head",
|
|
380
|
+
"hhea",
|
|
381
|
+
"hmtx",
|
|
382
|
+
"loca",
|
|
383
|
+
"maxp",
|
|
384
|
+
"name",
|
|
385
|
+
"post",
|
|
386
|
+
"prep"
|
|
387
|
+
];
|
|
388
|
+
function checksum(bytes) {
|
|
389
|
+
const padded = new Uint8Array(Math.ceil(bytes.length / 4) * 4);
|
|
390
|
+
padded.set(bytes);
|
|
391
|
+
const view = new DataView(padded.buffer);
|
|
392
|
+
let sum = 0;
|
|
393
|
+
for (let offset = 0; offset < padded.length; offset += 4) sum = sum + view.getUint32(offset) >>> 0;
|
|
394
|
+
return sum;
|
|
395
|
+
}
|
|
396
|
+
function parseTrueType(input) {
|
|
397
|
+
const bytes = input;
|
|
398
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
399
|
+
const version = view.getUint32(0);
|
|
400
|
+
if (version !== 65536 && version !== 1953658213) throw new Error("Only TrueType (glyf) fonts can be embedded");
|
|
401
|
+
const tables = /* @__PURE__ */ new Map();
|
|
402
|
+
const count = view.getUint16(4);
|
|
403
|
+
for (let index = 0; index < count; index++) {
|
|
404
|
+
const at = 12 + index * 16;
|
|
405
|
+
const tag = String.fromCharCode(bytes[at], bytes[at + 1], bytes[at + 2], bytes[at + 3]);
|
|
406
|
+
tables.set(tag, {
|
|
407
|
+
offset: view.getUint32(at + 8),
|
|
408
|
+
length: view.getUint32(at + 12)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
const table = (tag) => {
|
|
412
|
+
const record = tables.get(tag);
|
|
413
|
+
if (!record) throw new Error(`Font has no ${tag} table`);
|
|
414
|
+
return record;
|
|
415
|
+
};
|
|
416
|
+
const head = table("head").offset;
|
|
417
|
+
const unitsPerEm = view.getUint16(head + 18);
|
|
418
|
+
const bbox = [
|
|
419
|
+
view.getInt16(head + 36),
|
|
420
|
+
view.getInt16(head + 38),
|
|
421
|
+
view.getInt16(head + 40),
|
|
422
|
+
view.getInt16(head + 42)
|
|
423
|
+
];
|
|
424
|
+
const longLoca = view.getInt16(head + 50) === 1;
|
|
425
|
+
const hhea = table("hhea").offset;
|
|
426
|
+
const ascent = view.getInt16(hhea + 4);
|
|
427
|
+
const descent = view.getInt16(hhea + 6);
|
|
428
|
+
const metrics = view.getUint16(hhea + 34);
|
|
429
|
+
const numGlyphs = view.getUint16(table("maxp").offset + 4);
|
|
430
|
+
const os2 = tables.get("OS/2");
|
|
431
|
+
const capHeight = os2 && view.getUint16(os2.offset) >= 2 ? view.getInt16(os2.offset + 88) : Math.round(ascent * .7);
|
|
432
|
+
const hmtx = table("hmtx").offset;
|
|
433
|
+
const cmap = /* @__PURE__ */ new Map();
|
|
434
|
+
const cmapAt = table("cmap").offset;
|
|
435
|
+
const subtables = [];
|
|
436
|
+
for (let index = 0; index < view.getUint16(cmapAt + 2); index++) {
|
|
437
|
+
const at = cmapAt + 4 + index * 8;
|
|
438
|
+
subtables.push({
|
|
439
|
+
platform: view.getUint16(at),
|
|
440
|
+
encoding: view.getUint16(at + 2),
|
|
441
|
+
offset: cmapAt + view.getUint32(at + 4)
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const rank = (entry) => {
|
|
445
|
+
const format = view.getUint16(entry.offset);
|
|
446
|
+
if (entry.platform === 3 && entry.encoding === 10 && format === 12) return 0;
|
|
447
|
+
if (entry.platform === 0 && format === 12) return 1;
|
|
448
|
+
if (entry.platform === 3 && entry.encoding === 1 && format === 4) return 2;
|
|
449
|
+
if (entry.platform === 0 && format === 4) return 3;
|
|
450
|
+
return 9;
|
|
451
|
+
};
|
|
452
|
+
const best = subtables.sort((a, b) => rank(a) - rank(b))[0];
|
|
453
|
+
if (best && rank(best) < 9) {
|
|
454
|
+
const at = best.offset;
|
|
455
|
+
if (view.getUint16(at) === 12) {
|
|
456
|
+
const groups = view.getUint32(at + 12);
|
|
457
|
+
for (let index = 0; index < groups; index++) {
|
|
458
|
+
const group = at + 16 + index * 12;
|
|
459
|
+
const start = view.getUint32(group);
|
|
460
|
+
const end = view.getUint32(group + 4);
|
|
461
|
+
const glyph = view.getUint32(group + 8);
|
|
462
|
+
for (let code = start; code <= end && code - start < 65536; code++) cmap.set(code, glyph + code - start);
|
|
463
|
+
}
|
|
464
|
+
} else {
|
|
465
|
+
const segments = view.getUint16(at + 6) / 2;
|
|
466
|
+
const ends = at + 14;
|
|
467
|
+
const starts = ends + segments * 2 + 2;
|
|
468
|
+
const deltas = starts + segments * 2;
|
|
469
|
+
const ranges = deltas + segments * 2;
|
|
470
|
+
for (let segment = 0; segment < segments; segment++) {
|
|
471
|
+
const start = view.getUint16(starts + segment * 2);
|
|
472
|
+
const end = view.getUint16(ends + segment * 2);
|
|
473
|
+
const delta = view.getInt16(deltas + segment * 2);
|
|
474
|
+
const rangeAt = ranges + segment * 2;
|
|
475
|
+
const range = view.getUint16(rangeAt);
|
|
476
|
+
for (let code = start; code <= end && code !== 65535; code++) {
|
|
477
|
+
let glyph = 0;
|
|
478
|
+
if (range === 0) glyph = code + delta & 65535;
|
|
479
|
+
else {
|
|
480
|
+
const raw = view.getUint16(rangeAt + range + (code - start) * 2);
|
|
481
|
+
glyph = raw ? raw + delta & 65535 : 0;
|
|
482
|
+
}
|
|
483
|
+
if (glyph) cmap.set(code, glyph);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const loca = table("loca").offset;
|
|
489
|
+
const glyf = table("glyf").offset;
|
|
490
|
+
const glyphRange = (glyph) => longLoca ? [view.getUint32(loca + glyph * 4), view.getUint32(loca + glyph * 4 + 4)] : [view.getUint16(loca + glyph * 2) * 2, view.getUint16(loca + glyph * 2 + 2) * 2];
|
|
491
|
+
return {
|
|
492
|
+
unitsPerEm,
|
|
493
|
+
ascent,
|
|
494
|
+
descent,
|
|
495
|
+
capHeight,
|
|
496
|
+
bbox,
|
|
497
|
+
numGlyphs,
|
|
498
|
+
name: readName(view, tables.get("name")) ?? "Font",
|
|
499
|
+
glyphId: (codePoint) => cmap.get(codePoint) ?? 0,
|
|
500
|
+
advance: (glyph) => view.getUint16(hmtx + Math.min(glyph, metrics - 1) * 4),
|
|
501
|
+
subset(glyphs) {
|
|
502
|
+
const keep = /* @__PURE__ */ new Set([0, ...glyphs]);
|
|
503
|
+
const queue = [...keep];
|
|
504
|
+
while (queue.length) {
|
|
505
|
+
const glyph = queue.pop();
|
|
506
|
+
if (glyph >= numGlyphs) continue;
|
|
507
|
+
const [start, end] = glyphRange(glyph);
|
|
508
|
+
if (end - start < 10 || view.getInt16(glyf + start) >= 0) continue;
|
|
509
|
+
let at = glyf + start + 10;
|
|
510
|
+
for (;;) {
|
|
511
|
+
const flags = view.getUint16(at);
|
|
512
|
+
const component = view.getUint16(at + 2);
|
|
513
|
+
if (!keep.has(component)) {
|
|
514
|
+
keep.add(component);
|
|
515
|
+
queue.push(component);
|
|
516
|
+
}
|
|
517
|
+
at += 4 + (flags & 1 ? 4 : 2) + (flags & 8 ? 2 : flags & 64 ? 4 : flags & 128 ? 8 : 0);
|
|
518
|
+
if (!(flags & 32)) break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const parts = [];
|
|
522
|
+
const offsets = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer((numGlyphs + 1) * 4));
|
|
523
|
+
let size = 0;
|
|
524
|
+
for (let glyph = 0; glyph < numGlyphs; glyph++) {
|
|
525
|
+
offsets.setUint32(glyph * 4, size);
|
|
526
|
+
if (!keep.has(glyph)) continue;
|
|
527
|
+
const [start, end] = glyphRange(glyph);
|
|
528
|
+
const length = end - start;
|
|
529
|
+
if (length <= 0) continue;
|
|
530
|
+
const padded = new Uint8Array(Math.ceil(length / 4) * 4);
|
|
531
|
+
padded.set(bytes.subarray(glyf + start, glyf + end));
|
|
532
|
+
parts.push(padded);
|
|
533
|
+
size += padded.length;
|
|
534
|
+
}
|
|
535
|
+
offsets.setUint32(numGlyphs * 4, size);
|
|
536
|
+
const newGlyf = new Uint8Array(size);
|
|
537
|
+
let offset = 0;
|
|
538
|
+
for (const part of parts) {
|
|
539
|
+
newGlyf.set(part, offset);
|
|
540
|
+
offset += part.length;
|
|
541
|
+
}
|
|
542
|
+
const newHead = bytes.slice(head, head + table("head").length);
|
|
543
|
+
new DataView(newHead.buffer).setUint32(8, 0);
|
|
544
|
+
new DataView(newHead.buffer).setInt16(50, 1);
|
|
545
|
+
const post = tables.get("post");
|
|
546
|
+
const newPost = post ? bytes.slice(post.offset, post.offset + 32) : null;
|
|
547
|
+
if (newPost) new DataView(newPost.buffer).setUint32(0, 196608);
|
|
548
|
+
const out = /* @__PURE__ */ new Map();
|
|
549
|
+
for (const tag of KEEP_TABLES) {
|
|
550
|
+
const record = tables.get(tag);
|
|
551
|
+
if (!record) continue;
|
|
552
|
+
if (tag === "glyf") out.set(tag, newGlyf);
|
|
553
|
+
else if (tag === "loca") out.set(tag, new Uint8Array(offsets.buffer));
|
|
554
|
+
else if (tag === "head") out.set(tag, newHead);
|
|
555
|
+
else if (tag === "post" && newPost) out.set(tag, newPost);
|
|
556
|
+
else out.set(tag, bytes.slice(record.offset, record.offset + record.length));
|
|
557
|
+
}
|
|
558
|
+
return writeFont(out);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function readName(view, record) {
|
|
563
|
+
if (!record) return null;
|
|
564
|
+
const count = view.getUint16(record.offset + 2);
|
|
565
|
+
const storage = record.offset + view.getUint16(record.offset + 4);
|
|
566
|
+
let fallback = null;
|
|
567
|
+
for (let index = 0; index < count; index++) {
|
|
568
|
+
const at = record.offset + 6 + index * 12;
|
|
569
|
+
const platform = view.getUint16(at);
|
|
570
|
+
if (view.getUint16(at + 6) !== 6) continue;
|
|
571
|
+
const length = view.getUint16(at + 8);
|
|
572
|
+
const offset = storage + view.getUint16(at + 10);
|
|
573
|
+
let text = "";
|
|
574
|
+
if (platform === 3 || platform === 0) for (let i = 0; i < length; i += 2) text += String.fromCharCode(view.getUint16(offset + i));
|
|
575
|
+
else for (let i = 0; i < length; i++) text += String.fromCharCode(view.getUint8(offset + i));
|
|
576
|
+
const clean = text.replace(/[^A-Za-z0-9-]/g, "");
|
|
577
|
+
if (clean) {
|
|
578
|
+
if (platform === 3) return clean;
|
|
579
|
+
fallback = clean;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return fallback;
|
|
583
|
+
}
|
|
584
|
+
function writeFont(tables) {
|
|
585
|
+
const tags = [...tables.keys()].sort();
|
|
586
|
+
const count = tags.length;
|
|
587
|
+
let power = 1;
|
|
588
|
+
while (power * 2 <= count) power *= 2;
|
|
589
|
+
let offset = 12 + count * 16;
|
|
590
|
+
const layout = tags.map((tag) => {
|
|
591
|
+
const data = tables.get(tag);
|
|
592
|
+
const entry = {
|
|
593
|
+
tag,
|
|
594
|
+
data,
|
|
595
|
+
offset
|
|
596
|
+
};
|
|
597
|
+
offset += Math.ceil(data.length / 4) * 4;
|
|
598
|
+
return entry;
|
|
599
|
+
});
|
|
600
|
+
const out = new Uint8Array(offset);
|
|
601
|
+
const view = new DataView(out.buffer);
|
|
602
|
+
view.setUint32(0, 65536);
|
|
603
|
+
view.setUint16(4, count);
|
|
604
|
+
view.setUint16(6, power * 16);
|
|
605
|
+
view.setUint16(8, Math.log2(power));
|
|
606
|
+
view.setUint16(10, count * 16 - power * 16);
|
|
607
|
+
layout.forEach((entry, index) => {
|
|
608
|
+
const at = 12 + index * 16;
|
|
609
|
+
for (let i = 0; i < 4; i++) out[at + i] = entry.tag.charCodeAt(i);
|
|
610
|
+
view.setUint32(at + 4, checksum(entry.data));
|
|
611
|
+
view.setUint32(at + 8, entry.offset);
|
|
612
|
+
view.setUint32(at + 12, entry.data.length);
|
|
613
|
+
out.set(entry.data, entry.offset);
|
|
614
|
+
});
|
|
615
|
+
const head = layout.find((entry) => entry.tag === "head");
|
|
616
|
+
if (head) view.setUint32(head.offset + 8, 2981146554 - checksum(out) >>> 0);
|
|
617
|
+
return out;
|
|
618
|
+
}
|
|
619
|
+
var PdfFont = class {
|
|
620
|
+
ttf;
|
|
621
|
+
resource;
|
|
622
|
+
tag;
|
|
623
|
+
used = /* @__PURE__ */ new Map();
|
|
624
|
+
constructor(ttf, resource, tag) {
|
|
625
|
+
this.ttf = ttf;
|
|
626
|
+
this.resource = resource;
|
|
627
|
+
this.tag = tag;
|
|
628
|
+
}
|
|
629
|
+
width(text, size) {
|
|
630
|
+
let units = 0;
|
|
631
|
+
for (const char of text) units += this.ttf.advance(this.ttf.glyphId(char.codePointAt(0) ?? 0));
|
|
632
|
+
return units * size / this.ttf.unitsPerEm;
|
|
633
|
+
}
|
|
634
|
+
encode(text) {
|
|
635
|
+
let hex = "";
|
|
636
|
+
for (const char of text) {
|
|
637
|
+
const code = char.codePointAt(0) ?? 0;
|
|
638
|
+
const glyph = this.ttf.glyphId(code);
|
|
639
|
+
if (!this.used.has(glyph)) this.used.set(glyph, code);
|
|
640
|
+
hex += glyph.toString(16).padStart(4, "0");
|
|
641
|
+
}
|
|
642
|
+
return hex;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
function toBytes(source) {
|
|
646
|
+
if (typeof source === "string") return base64ToBytes(source);
|
|
647
|
+
return source instanceof Uint8Array ? source : new Uint8Array(source);
|
|
648
|
+
}
|
|
649
|
+
function rgb(hex) {
|
|
650
|
+
const value = parseInt(hex, 16);
|
|
651
|
+
return [
|
|
652
|
+
value >> 16 & 255,
|
|
653
|
+
value >> 8 & 255,
|
|
654
|
+
value & 255
|
|
655
|
+
].map((part) => +(part / 255).toFixed(3)).join(" ");
|
|
656
|
+
}
|
|
657
|
+
function num(value) {
|
|
658
|
+
return (+value.toFixed(2)).toString();
|
|
659
|
+
}
|
|
660
|
+
function utf16Hex(text) {
|
|
661
|
+
let hex = "";
|
|
662
|
+
for (let index = 0; index < text.length; index++) hex += text.charCodeAt(index).toString(16).padStart(4, "0");
|
|
663
|
+
return hex;
|
|
664
|
+
}
|
|
665
|
+
function pdfString(text) {
|
|
666
|
+
return `<FEFF${utf16Hex(text)}>`;
|
|
667
|
+
}
|
|
668
|
+
function pdfDate(date) {
|
|
669
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
670
|
+
return `D:${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
|
|
671
|
+
}
|
|
672
|
+
function wrapText(text, width, measure) {
|
|
673
|
+
const lines = [];
|
|
674
|
+
for (const paragraph of text.replace(/\t/g, " ").split(/\r?\n/)) {
|
|
675
|
+
let line = "";
|
|
676
|
+
for (const word of paragraph.split(" ")) {
|
|
677
|
+
const candidate = line ? `${line} ${word}` : word;
|
|
678
|
+
if (measure(candidate) <= width) {
|
|
679
|
+
line = candidate;
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (line) lines.push(line);
|
|
683
|
+
line = "";
|
|
684
|
+
if (measure(word) <= width) {
|
|
685
|
+
line = word;
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
let part = "";
|
|
689
|
+
for (const char of word) {
|
|
690
|
+
if (part && measure(part + char) > width) {
|
|
691
|
+
lines.push(part);
|
|
692
|
+
part = "";
|
|
693
|
+
}
|
|
694
|
+
part += char;
|
|
695
|
+
}
|
|
696
|
+
line = part;
|
|
697
|
+
}
|
|
698
|
+
lines.push(line);
|
|
699
|
+
}
|
|
700
|
+
return lines;
|
|
701
|
+
}
|
|
702
|
+
function layoutColumns(table, texts, regular, bold, size, padding, available) {
|
|
703
|
+
if (!table.columns.length) return { widths: [] };
|
|
704
|
+
const sample = texts.slice(0, 1e3);
|
|
705
|
+
const natural = table.columns.map((column, index) => {
|
|
706
|
+
if (column.width) return column.width * size * .55 + padding * 2;
|
|
707
|
+
const header = Math.max(...column.title.split("\n").map((line) => bold.width(line, size)));
|
|
708
|
+
const cells = sample.map((row) => Math.max(...row[index].split("\n").map((line) => regular.width(line, size))));
|
|
709
|
+
return Math.min(available * .45, Math.max(header, ...cells, size * 2) + padding * 2);
|
|
710
|
+
});
|
|
711
|
+
const fixed = table.columns.map((column) => !!column.width);
|
|
712
|
+
const fixedSum = natural.reduce((sum, width, index) => sum + (fixed[index] ? width : 0), 0);
|
|
713
|
+
const flexSum = natural.reduce((sum, width, index) => sum + (fixed[index] ? 0 : width), 0);
|
|
714
|
+
const room = available - fixedSum;
|
|
715
|
+
if (room <= 0 || !flexSum) {
|
|
716
|
+
const total = fixedSum + flexSum;
|
|
717
|
+
return { widths: natural.map((width) => width * available / total) };
|
|
718
|
+
}
|
|
719
|
+
if (flexSum <= room) return { widths: natural.map((width, index) => fixed[index] ? width : width * room / flexSum) };
|
|
720
|
+
const floor = Math.min(room / Math.max(1, fixed.filter((value) => !value).length), size * 4 + padding * 2);
|
|
721
|
+
let widths = natural.map((width, index) => fixed[index] ? width : Math.max(floor, width * room / flexSum));
|
|
722
|
+
const total = widths.reduce((sum, width) => sum + width, 0);
|
|
723
|
+
if (total > available) widths = widths.map((width) => width * available / total);
|
|
724
|
+
return { widths };
|
|
725
|
+
}
|
|
726
|
+
async function loadPdfFonts(font) {
|
|
727
|
+
return {
|
|
728
|
+
regular: parseTrueType(toBytes(font.regular)),
|
|
729
|
+
bold: font.bold ? parseTrueType(toBytes(font.bold)) : null
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
async function writePdf(table, options, font, context = {
|
|
733
|
+
yes: "Yes",
|
|
734
|
+
no: "No"
|
|
735
|
+
}, date = /* @__PURE__ */ new Date()) {
|
|
736
|
+
const fonts = await loadPdfFonts(font);
|
|
737
|
+
const regular = new PdfFont(fonts.regular, "F1", "TXREGU");
|
|
738
|
+
const bold = fonts.bold ? new PdfFont(fonts.bold, "F2", "TXBOLD") : regular;
|
|
739
|
+
const fakeBold = bold === regular;
|
|
740
|
+
const page = pageGeometry(options.pageSize, options.orientation, options.margin, table.columns.length);
|
|
741
|
+
const size = options.fontSize ?? 9;
|
|
742
|
+
const lineHeight = size * (options.lineHeight ?? 1.35);
|
|
743
|
+
const padX = options.cellPadding ?? 4;
|
|
744
|
+
const padY = padX * .75;
|
|
745
|
+
const [top, right, bottom, left] = page.margin;
|
|
746
|
+
const available = page.width - left - right;
|
|
747
|
+
const text = hexColor(options.textColor, "1D2939");
|
|
748
|
+
const muted = hexColor(options.mutedColor, "667085");
|
|
749
|
+
const border = hexColor(options.borderColor, "D0D5DD");
|
|
750
|
+
const headerFill = options.headerBackground === "none" ? null : hexColor(options.headerBackground, "F2F4F7");
|
|
751
|
+
const stripeFill = hexColor(options.stripeBackground, "F9FAFB");
|
|
752
|
+
const texts = table.rows.map((row) => table.columns.map((column, index) => cellText(row[index], column, context)));
|
|
753
|
+
const { widths } = layoutColumns(table, texts, regular, bold, size, padX, available);
|
|
754
|
+
const xs = widths.reduce((acc, width, index) => [...acc, acc[index] + width], [left]);
|
|
755
|
+
const wrapRow = (values, measureFont, header, stripe) => {
|
|
756
|
+
const cells = values.map((value, index) => wrapText(value, Math.max(1, widths[index] - padX * 2), (line) => measureFont.width(line, size)));
|
|
757
|
+
return {
|
|
758
|
+
cells,
|
|
759
|
+
header,
|
|
760
|
+
stripe,
|
|
761
|
+
height: Math.max(1, ...cells.map((lines) => lines.length)) * lineHeight + padY * 2
|
|
762
|
+
};
|
|
763
|
+
};
|
|
764
|
+
const headerRow = options.header === false || !table.columns.length ? null : wrapRow(table.columns.map((column) => column.title), bold, true, false);
|
|
765
|
+
const bodyRows = texts.map((values, index) => wrapRow(values, regular, false, !!options.striped && index % 2 === 1));
|
|
766
|
+
const heading = [];
|
|
767
|
+
if (options.title) heading.push({
|
|
768
|
+
text: options.title,
|
|
769
|
+
font: bold,
|
|
770
|
+
size: size * 1.6,
|
|
771
|
+
color: text
|
|
772
|
+
});
|
|
773
|
+
if (options.subtitle) heading.push({
|
|
774
|
+
text: options.subtitle,
|
|
775
|
+
font: regular,
|
|
776
|
+
size: size * 1.1,
|
|
777
|
+
color: muted
|
|
778
|
+
});
|
|
779
|
+
const stamp = dateLine(options, context, date);
|
|
780
|
+
if (stamp) heading.push({
|
|
781
|
+
text: stamp,
|
|
782
|
+
font: regular,
|
|
783
|
+
size: size * .9,
|
|
784
|
+
color: muted
|
|
785
|
+
});
|
|
786
|
+
const pages = [];
|
|
787
|
+
let ops = [];
|
|
788
|
+
let y = page.height - top;
|
|
789
|
+
const ascentRatio = fonts.regular.ascent / fonts.regular.unitsPerEm;
|
|
790
|
+
const descentRatio = -fonts.regular.descent / fonts.regular.unitsPerEm;
|
|
791
|
+
const drawText = (value, x, baseline, pdfFont, fontSize, color, strong = false) => {
|
|
792
|
+
if (!value) return;
|
|
793
|
+
const effect = strong && fakeBold ? `2 Tr ${num(fontSize * .03)} w ${rgb(color)} RG ` : "";
|
|
794
|
+
ops.push(`BT ${effect}/${pdfFont.resource} ${num(fontSize)} Tf ${rgb(color)} rg ${num(x)} ${num(baseline)} Td <${pdfFont.encode(value)}> Tj ET`);
|
|
795
|
+
};
|
|
796
|
+
const drawRow = (row) => {
|
|
797
|
+
const rowTop = y;
|
|
798
|
+
const fill = row.header ? headerFill : row.stripe ? stripeFill : null;
|
|
799
|
+
if (fill) ops.push(`${rgb(fill)} rg ${num(left)} ${num(rowTop - row.height)} ${num(available)} ${num(row.height)} re f`);
|
|
800
|
+
row.cells.forEach((lines, index) => {
|
|
801
|
+
const column = table.columns[index];
|
|
802
|
+
const pdfFont = row.header ? bold : regular;
|
|
803
|
+
lines.forEach((line, lineIndex) => {
|
|
804
|
+
const baseline = rowTop - padY - lineIndex * lineHeight - (lineHeight - (ascentRatio + descentRatio) * size) / 2 - ascentRatio * size;
|
|
805
|
+
const width = pdfFont.width(line, size);
|
|
806
|
+
const cellLeft = xs[index] + padX;
|
|
807
|
+
const cellWidth = widths[index] - padX * 2;
|
|
808
|
+
const x = column.align === "end" ? cellLeft + cellWidth - width : column.align === "center" ? cellLeft + (cellWidth - width) / 2 : cellLeft;
|
|
809
|
+
drawText(line, x, baseline, pdfFont, size, text, row.header);
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
ops.push(`${rgb(border)} RG 0.5 w ${num(left)} ${num(rowTop - row.height)} m ${num(left + available)} ${num(rowTop - row.height)} l S`);
|
|
813
|
+
if (options.gridlines !== false) for (const x of xs) ops.push(`${num(x)} ${num(rowTop)} m ${num(x)} ${num(rowTop - row.height)} l S`);
|
|
814
|
+
y -= row.height;
|
|
815
|
+
};
|
|
816
|
+
const startPage = (first) => {
|
|
817
|
+
if (!first) pages.push(ops);
|
|
818
|
+
ops = [];
|
|
819
|
+
y = page.height - top;
|
|
820
|
+
if (first) {
|
|
821
|
+
heading.forEach((line) => {
|
|
822
|
+
y -= line.size * 1.25;
|
|
823
|
+
drawText(line.text, left, y, line.font, line.size, line.color, line.font === bold);
|
|
824
|
+
});
|
|
825
|
+
if (heading.length) y -= size * 1.2;
|
|
826
|
+
}
|
|
827
|
+
if (headerRow && (first || options.repeatHeader !== false)) {
|
|
828
|
+
ops.push(`${rgb(border)} RG 0.5 w ${num(left)} ${num(y)} m ${num(left + available)} ${num(y)} l S`);
|
|
829
|
+
drawRow(headerRow);
|
|
830
|
+
} else if (table.columns.length) ops.push(`${rgb(border)} RG 0.5 w ${num(left)} ${num(y)} m ${num(left + available)} ${num(y)} l S`);
|
|
831
|
+
};
|
|
832
|
+
startPage(true);
|
|
833
|
+
let rowsOnPage = 0;
|
|
834
|
+
for (const row of bodyRows) {
|
|
835
|
+
if (y - row.height < bottom && rowsOnPage > 0) {
|
|
836
|
+
startPage(false);
|
|
837
|
+
rowsOnPage = 0;
|
|
838
|
+
}
|
|
839
|
+
drawRow(row);
|
|
840
|
+
rowsOnPage++;
|
|
841
|
+
}
|
|
842
|
+
pages.push(ops);
|
|
843
|
+
if (options.pageNumbers !== false) pages.forEach((pageOps, index) => {
|
|
844
|
+
ops = pageOps;
|
|
845
|
+
const label = `${index + 1} / ${pages.length}`;
|
|
846
|
+
const footerSize = size * .85;
|
|
847
|
+
drawText(label, (page.width - regular.width(label, footerSize)) / 2, Math.max(12, bottom / 2 - footerSize / 2), regular, footerSize, muted);
|
|
848
|
+
});
|
|
849
|
+
const objects = [];
|
|
850
|
+
const reserve = () => {
|
|
851
|
+
objects.push(null);
|
|
852
|
+
return objects.length;
|
|
853
|
+
};
|
|
854
|
+
const set = (id, body) => {
|
|
855
|
+
objects[id - 1] = typeof body === "string" ? utf8(`${id} 0 obj\n${body}\nendobj\n`) : body;
|
|
856
|
+
};
|
|
857
|
+
const stream = async (id, dict, data) => {
|
|
858
|
+
const packed = options.compress === false ? null : await compress(data, "deflate");
|
|
859
|
+
const body = packed ?? data;
|
|
860
|
+
set(id, concatBytes([
|
|
861
|
+
utf8(`${id} 0 obj\n<< ${dict} /Length ${body.length}${packed ? " /Filter /FlateDecode" : ""} >>\nstream\n`),
|
|
862
|
+
body,
|
|
863
|
+
utf8("\nendstream\nendobj\n")
|
|
864
|
+
]));
|
|
865
|
+
};
|
|
866
|
+
const catalog = reserve();
|
|
867
|
+
const pagesId = reserve();
|
|
868
|
+
const info = reserve();
|
|
869
|
+
const fontIds = /* @__PURE__ */ new Map();
|
|
870
|
+
for (const pdfFont of /* @__PURE__ */ new Set([regular, bold])) fontIds.set(pdfFont, reserve());
|
|
871
|
+
const pageIds = pages.map(() => [reserve(), reserve()]);
|
|
872
|
+
for (const [index, [pageId, contentId]] of pageIds.entries()) {
|
|
873
|
+
const fontsDict = [...fontIds].map(([pdfFont, id]) => `/${pdfFont.resource} ${id} 0 R`).join(" ");
|
|
874
|
+
set(pageId, `<< /Type /Page /Parent ${pagesId} 0 R /MediaBox [0 0 ${num(page.width)} ${num(page.height)}] /Resources << /Font << ${fontsDict} >> >> /Contents ${contentId} 0 R >>`);
|
|
875
|
+
await stream(contentId, "", utf8(pages[index].join("\n")));
|
|
876
|
+
}
|
|
877
|
+
for (const [pdfFont, id] of fontIds) {
|
|
878
|
+
const ttf = pdfFont.ttf;
|
|
879
|
+
const scale = (value) => Math.round(value * 1e3 / ttf.unitsPerEm);
|
|
880
|
+
const glyphs = [...pdfFont.used.keys()].sort((a, b) => a - b);
|
|
881
|
+
const baseFont = `${pdfFont.tag}+${ttf.name}`;
|
|
882
|
+
const cid = reserve();
|
|
883
|
+
const descriptor = reserve();
|
|
884
|
+
const file = reserve();
|
|
885
|
+
const toUnicode = reserve();
|
|
886
|
+
set(id, `<< /Type /Font /Subtype /Type0 /BaseFont /${baseFont} /Encoding /Identity-H /DescendantFonts [${cid} 0 R] /ToUnicode ${toUnicode} 0 R >>`);
|
|
887
|
+
const w = glyphs.map((glyph) => `${glyph} [${scale(ttf.advance(glyph))}]`).join(" ");
|
|
888
|
+
set(cid, `<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${baseFont} /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor ${descriptor} 0 R /DW ${scale(ttf.advance(0))} /W [${w}] /CIDToGIDMap /Identity >>`);
|
|
889
|
+
set(descriptor, `<< /Type /FontDescriptor /FontName /${baseFont} /Flags 32 /FontBBox [${ttf.bbox.map(scale).join(" ")}] /ItalicAngle 0 /Ascent ${scale(ttf.ascent)} /Descent ${scale(ttf.descent)} /CapHeight ${scale(ttf.capHeight)} /StemV 80 /FontFile2 ${file} 0 R >>`);
|
|
890
|
+
const subset = ttf.subset(new Set(glyphs));
|
|
891
|
+
await stream(file, `/Length1 ${subset.length}`, subset);
|
|
892
|
+
const entries = glyphs.map((glyph) => `<${glyph.toString(16).padStart(4, "0")}> <${utf16Hex(String.fromCodePoint(pdfFont.used.get(glyph) ?? 65533))}>`);
|
|
893
|
+
const chunks = [];
|
|
894
|
+
for (let index = 0; index < entries.length; index += 100) {
|
|
895
|
+
const chunk = entries.slice(index, index + 100);
|
|
896
|
+
chunks.push(`${chunk.length} beginbfchar\n${chunk.join("\n")}\nendbfchar`);
|
|
897
|
+
}
|
|
898
|
+
await stream(toUnicode, "", utf8(`/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n${chunks.join("\n")}\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend`));
|
|
899
|
+
}
|
|
900
|
+
set(catalog, `<< /Type /Catalog /Pages ${pagesId} 0 R >>`);
|
|
901
|
+
set(pagesId, `<< /Type /Pages /Kids [${pageIds.map(([pageId]) => `${pageId} 0 R`).join(" ")}] /Count ${pageIds.length} >>`);
|
|
902
|
+
const infoParts = [`/Producer (tectra)`, `/CreationDate (${pdfDate(date)})`];
|
|
903
|
+
if (options.title) infoParts.push(`/Title ${pdfString(options.title)}`);
|
|
904
|
+
if (options.author) infoParts.push(`/Author ${pdfString(options.author)}`);
|
|
905
|
+
set(info, `<< ${infoParts.join(" ")} >>`);
|
|
906
|
+
const header = utf8("%PDF-1.7\n%âãÏÓ\n");
|
|
907
|
+
const offsets = [];
|
|
908
|
+
let offset = header.length;
|
|
909
|
+
for (const object of objects) {
|
|
910
|
+
offsets.push(offset);
|
|
911
|
+
offset += object.length;
|
|
912
|
+
}
|
|
913
|
+
const xref = [`xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`, ...offsets.map((value) => `${String(value).padStart(10, "0")} 00000 n \n`)].join("");
|
|
914
|
+
const trailer = `trailer\n<< /Size ${objects.length + 1} /Root ${catalog} 0 R /Info ${info} 0 R >>\nstartxref\n${offset}\n%%EOF\n`;
|
|
915
|
+
const bytes = concatBytes([
|
|
916
|
+
header,
|
|
917
|
+
...objects,
|
|
918
|
+
utf8(xref + trailer)
|
|
919
|
+
]);
|
|
920
|
+
return new Blob([bytes], { type: "application/pdf" });
|
|
921
|
+
}
|
|
922
|
+
function printHtml(document, html) {
|
|
923
|
+
return new Promise((resolve) => {
|
|
924
|
+
const frame = document.createElement("iframe");
|
|
925
|
+
frame.setAttribute("aria-hidden", "true");
|
|
926
|
+
frame.setAttribute("tabindex", "-1");
|
|
927
|
+
frame.style.cssText = "position:fixed;right:0;bottom:0;width:0;height:0;border:0;opacity:0;pointer-events:none";
|
|
928
|
+
let removed = false;
|
|
929
|
+
const remove = () => {
|
|
930
|
+
if (removed) return;
|
|
931
|
+
removed = true;
|
|
932
|
+
frame.remove();
|
|
933
|
+
};
|
|
934
|
+
frame.addEventListener("load", () => {
|
|
935
|
+
const view = frame.contentWindow;
|
|
936
|
+
if (!view) {
|
|
937
|
+
remove();
|
|
938
|
+
return resolve();
|
|
939
|
+
}
|
|
940
|
+
view.addEventListener("afterprint", () => setTimeout(remove));
|
|
941
|
+
view.focus();
|
|
942
|
+
view.print();
|
|
943
|
+
setTimeout(remove, 6e4);
|
|
944
|
+
resolve();
|
|
945
|
+
});
|
|
946
|
+
frame.srcdoc = html;
|
|
947
|
+
document.body.appendChild(frame);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
function writeCsv(table, options = {}) {
|
|
951
|
+
const separator = options.separator ?? ",";
|
|
952
|
+
const cell = (value) => csvCell(value, separator, {
|
|
953
|
+
quoteAll: options.quoteAll,
|
|
954
|
+
formulaGuard: options.formulaGuard
|
|
955
|
+
});
|
|
956
|
+
const lines = table.rows.map((row) => row.map((value, index) => cell(localIso(value, table.columns[index].type))).join(separator));
|
|
957
|
+
if (options.header !== false) lines.unshift(table.columns.map((column) => cell(column.title)).join(separator));
|
|
958
|
+
return lines.join(options.lineEnding ?? "\r\n");
|
|
959
|
+
}
|
|
960
|
+
function writeTsv(table, context, header = true) {
|
|
961
|
+
const clean = (text) => text.replace(/[\t\r\n]+/g, " ");
|
|
962
|
+
const lines = table.rows.map((row) => table.columns.map((column, index) => clean(cellText(row[index], column, context))).join(" "));
|
|
963
|
+
if (header) lines.unshift(table.columns.map((column) => clean(column.title)).join(" "));
|
|
964
|
+
return lines.join("\n");
|
|
965
|
+
}
|
|
966
|
+
function writeJson(table, options = {}) {
|
|
967
|
+
const keys = table.columns.map((column) => options.keys === "title" ? column.title : column.key);
|
|
968
|
+
const objects = table.rows.map((row) => Object.fromEntries(keys.map((key, index) => [key, row[index] === void 0 ? null : localIso(row[index], table.columns[index].type)])));
|
|
969
|
+
return JSON.stringify(objects, null, options.indent ?? 2);
|
|
970
|
+
}
|
|
971
|
+
function escapeHtml(text) {
|
|
972
|
+
return escapeXml(text).replace(/\n/g, "<br>");
|
|
973
|
+
}
|
|
974
|
+
function htmlTable(table, context, header = true) {
|
|
975
|
+
const align = (value) => value === "end" ? " style=\"text-align:right\"" : value === "center" ? " style=\"text-align:center\"" : "";
|
|
976
|
+
return `<table>${header ? `<thead><tr>${table.columns.map((column) => `<th${align(column.align)}>${escapeHtml(column.title)}</th>`).join("")}</tr></thead>` : ""}<tbody>${table.rows.map((row) => `<tr>${table.columns.map((column, index) => `<td${align(column.align)}>${escapeHtml(cellText(row[index], column, context))}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
977
|
+
}
|
|
978
|
+
const DOCUMENT_STYLES = `
|
|
979
|
+
body { margin: 24px; color: #1d2939; font: 13px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
|
|
980
|
+
h1 { margin: 0 0 4px; font-size: 20px; }
|
|
981
|
+
.subtitle, .date { margin: 0 0 4px; color: #667085; }
|
|
982
|
+
.date { font-size: 12px; }
|
|
983
|
+
table { width: 100%; margin-top: 16px; border-collapse: collapse; }
|
|
984
|
+
th, td { padding: 6px 10px; border: 1px solid #d0d5dd; text-align: left; vertical-align: top; }
|
|
985
|
+
th { background: #f2f4f7; font-weight: 600; }
|
|
986
|
+
thead { display: table-header-group; }
|
|
987
|
+
tr { break-inside: avoid; }
|
|
988
|
+
`;
|
|
989
|
+
function writeHtml(table, options = {}, context, date = /* @__PURE__ */ new Date()) {
|
|
990
|
+
const title = options.title ? `<h1>${escapeHtml(options.title)}</h1>` : "";
|
|
991
|
+
const subtitle = options.subtitle ? `<p class="subtitle">${escapeHtml(options.subtitle)}</p>` : "";
|
|
992
|
+
const stamp = dateLine(options, context, date);
|
|
993
|
+
const when = stamp ? `<p class="date">${escapeHtml(stamp)}</p>` : "";
|
|
994
|
+
return `<!doctype html>\n<html${options.lang ? ` lang="${escapeXml(options.lang)}"` : ""}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(options.title ?? "Export")}</title><style>${DOCUMENT_STYLES}${options.page ?? ""}${options.styles ?? ""}</style></head><body>${title}${subtitle}${when}${htmlTable(table, context, options.header !== false)}</body></html>\n`;
|
|
995
|
+
}
|
|
996
|
+
function printPageCss(options, columns) {
|
|
997
|
+
const page = pageGeometry(options.pageSize, options.orientation, options.margin, columns);
|
|
998
|
+
const [top, right, bottom, left] = page.margin;
|
|
999
|
+
return `@page { size: ${page.width}pt ${page.height}pt; margin: ${top}pt ${right}pt ${bottom}pt ${left}pt; } @media print { body { margin: 0; } }`;
|
|
1000
|
+
}
|
|
1001
|
+
function writeMarkdown(table, options = {}, context) {
|
|
1002
|
+
const clean = (text) => text.replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
1003
|
+
const lines = [];
|
|
1004
|
+
if (options.title) lines.push(`# ${options.title}`, "");
|
|
1005
|
+
const titles = table.columns.map((column) => clean(column.title) || " ");
|
|
1006
|
+
lines.push(`| ${options.header === false ? table.columns.map(() => " ").join(" | ") : titles.join(" | ")} |`);
|
|
1007
|
+
lines.push(`| ${table.columns.map((column) => column.align === "end" ? "---:" : column.align === "center" ? ":---:" : "---").join(" | ")} |`);
|
|
1008
|
+
for (const row of table.rows) lines.push(`| ${table.columns.map((column, index) => clean(cellText(row[index], column, context))).join(" | ")} |`);
|
|
1009
|
+
return `${lines.join("\n")}\n`;
|
|
1010
|
+
}
|
|
1011
|
+
const MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
1012
|
+
const REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
1013
|
+
const PKG_REL = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
1014
|
+
const NUMBER = /^[+-]?\d+(\.\d+)?$/;
|
|
1015
|
+
const MAX_TEXT = 32767;
|
|
1016
|
+
function columnName(index) {
|
|
1017
|
+
let name = "";
|
|
1018
|
+
for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26)) name = String.fromCharCode(65 + (n - 1) % 26) + name;
|
|
1019
|
+
return name;
|
|
1020
|
+
}
|
|
1021
|
+
function excelSerial(date) {
|
|
1022
|
+
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()) / 864e5 + 25569;
|
|
1023
|
+
}
|
|
1024
|
+
function sheetName(name) {
|
|
1025
|
+
return (name ?? "").replace(/[[\]:*?/\\]/g, " ").replace(/^'+|'+$/g, "").trim().slice(0, 31) || "Sheet1";
|
|
1026
|
+
}
|
|
1027
|
+
var StyleBook = class {
|
|
1028
|
+
formats = /* @__PURE__ */ new Map();
|
|
1029
|
+
xfs = [{
|
|
1030
|
+
numFmt: 0,
|
|
1031
|
+
wrap: false,
|
|
1032
|
+
header: false
|
|
1033
|
+
}];
|
|
1034
|
+
numFmt(code, builtin) {
|
|
1035
|
+
if (!code) return builtin;
|
|
1036
|
+
let id = this.formats.get(code);
|
|
1037
|
+
if (id === void 0) {
|
|
1038
|
+
id = 164 + this.formats.size;
|
|
1039
|
+
this.formats.set(code, id);
|
|
1040
|
+
}
|
|
1041
|
+
return id;
|
|
1042
|
+
}
|
|
1043
|
+
xf(key) {
|
|
1044
|
+
const index = this.xfs.findIndex((xf) => xf.numFmt === key.numFmt && xf.align === key.align && xf.wrap === key.wrap && xf.header === key.header);
|
|
1045
|
+
if (index >= 0) return index;
|
|
1046
|
+
this.xfs.push(key);
|
|
1047
|
+
return this.xfs.length - 1;
|
|
1048
|
+
}
|
|
1049
|
+
xml(options) {
|
|
1050
|
+
const formats = [...this.formats].map(([code, id]) => `<numFmt numFmtId="${id}" formatCode="${escapeXml(code)}"/>`).join("");
|
|
1051
|
+
const headerColor = options.headerColor ? `<color rgb="FF${hexColor(options.headerColor, "000000")}"/>` : "";
|
|
1052
|
+
const bold = options.headerBold === false ? "" : "<b/>";
|
|
1053
|
+
const fill = options.headerBackground === "none" ? "" : `<fill><patternFill patternType="solid"><fgColor rgb="FF${hexColor(options.headerBackground, "F2F2F2")}"/><bgColor indexed="64"/></patternFill></fill>`;
|
|
1054
|
+
const xfs = this.xfs.map((xf) => {
|
|
1055
|
+
const alignment = xf.align || xf.wrap ? `<alignment${xf.align ? ` horizontal="${xf.align}"` : ""}${xf.wrap ? " wrapText=\"1\" vertical=\"top\"" : ""}/>` : "";
|
|
1056
|
+
const attrs = `numFmtId="${xf.numFmt}" fontId="${xf.header ? 1 : 0}" fillId="${xf.header && fill ? 2 : 0}" borderId="0" xfId="0"${xf.numFmt ? " applyNumberFormat=\"1\"" : ""}${xf.header ? " applyFont=\"1\" applyFill=\"1\"" : ""}${alignment ? " applyAlignment=\"1\"" : ""}`;
|
|
1057
|
+
return alignment ? `<xf ${attrs}>${alignment}</xf>` : `<xf ${attrs}/>`;
|
|
1058
|
+
}).join("");
|
|
1059
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<styleSheet xmlns="${MAIN}">` + (this.formats.size ? `<numFmts count="${this.formats.size}">${formats}</numFmts>` : "") + `<fonts count="2"><font><sz val="11"/><name val="Calibri"/><family val="2"/></font><font>${bold}<sz val="11"/>${headerColor}<name val="Calibri"/><family val="2"/></font></fonts><fills count="${fill ? 3 : 2}"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill>${fill}</fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="${this.xfs.length}">${xfs}</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`;
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
function horizontal(column) {
|
|
1063
|
+
return column.align === "end" ? "right" : column.align === "center" ? "center" : void 0;
|
|
1064
|
+
}
|
|
1065
|
+
function textLength(value) {
|
|
1066
|
+
if (value === null || value === void 0) return 0;
|
|
1067
|
+
const text = value instanceof Date ? "0000-00-00 00:00" : String(value);
|
|
1068
|
+
return Math.max(...text.split("\n").map((line) => line.length));
|
|
1069
|
+
}
|
|
1070
|
+
function excelWidths(table, options = {}) {
|
|
1071
|
+
const min = options.minWidth ?? 8;
|
|
1072
|
+
const max = options.maxWidth ?? 60;
|
|
1073
|
+
return table.columns.map((column, index) => {
|
|
1074
|
+
if (column.width) return column.width;
|
|
1075
|
+
if (options.autoWidth === false) return min + 2;
|
|
1076
|
+
const longest = Math.max(textLength(column.title), ...table.rows.slice(0, 1e3).map((row) => textLength(row[index])));
|
|
1077
|
+
return Math.min(max, Math.max(min, longest + 2));
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
function cell(ref, value, column, styles, options) {
|
|
1081
|
+
if (value === null || value === void 0 || value === "") return "";
|
|
1082
|
+
const align = horizontal(column);
|
|
1083
|
+
if (column.type === "date" || column.type === "datetime" || value instanceof Date) {
|
|
1084
|
+
const date = toDate(value);
|
|
1085
|
+
if (date) {
|
|
1086
|
+
const datetime = column.type === "datetime";
|
|
1087
|
+
const fmt = styles.numFmt(column.format ?? (datetime ? options.dateTimeFormat : options.dateFormat), datetime ? 22 : 14);
|
|
1088
|
+
return `<c r="${ref}" s="${styles.xf({
|
|
1089
|
+
numFmt: fmt,
|
|
1090
|
+
align,
|
|
1091
|
+
wrap: false,
|
|
1092
|
+
header: false
|
|
1093
|
+
})}"><v>${excelSerial(date)}</v></c>`;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
if (typeof value === "boolean") return `<c r="${ref}" t="b"${align ? ` s="${styles.xf({
|
|
1097
|
+
numFmt: 0,
|
|
1098
|
+
align,
|
|
1099
|
+
wrap: false,
|
|
1100
|
+
header: false
|
|
1101
|
+
})}"` : ""}><v>${value ? 1 : 0}</v></c>`;
|
|
1102
|
+
const numeric = typeof value === "number" ? value : column.type === "number" && typeof value === "string" && NUMBER.test(value.trim()) ? Number(value) : null;
|
|
1103
|
+
if (numeric !== null && Number.isFinite(numeric)) {
|
|
1104
|
+
const fmt = styles.numFmt(column.format ?? options.numberFormat, 0);
|
|
1105
|
+
return `<c r="${ref}"${fmt || align ? ` s="${styles.xf({
|
|
1106
|
+
numFmt: fmt,
|
|
1107
|
+
align,
|
|
1108
|
+
wrap: false,
|
|
1109
|
+
header: false
|
|
1110
|
+
})}"` : ""}><v>${numeric}</v></c>`;
|
|
1111
|
+
}
|
|
1112
|
+
const text = (typeof value === "object" ? JSON.stringify(value) : String(value)).slice(0, MAX_TEXT);
|
|
1113
|
+
const wrap = options.wrapText !== false && text.includes("\n");
|
|
1114
|
+
return `<c r="${ref}" t="inlineStr"${align || wrap ? ` s="${styles.xf({
|
|
1115
|
+
numFmt: 0,
|
|
1116
|
+
align,
|
|
1117
|
+
wrap,
|
|
1118
|
+
header: false
|
|
1119
|
+
})}"` : ""}><is><t xml:space="preserve">${escapeXml(text)}</t></is></c>`;
|
|
1120
|
+
}
|
|
1121
|
+
function xlsxSheet(table, options, styles) {
|
|
1122
|
+
const header = options.header !== false;
|
|
1123
|
+
const widths = excelWidths(table, options);
|
|
1124
|
+
const lastColumn = columnName(Math.max(0, table.columns.length - 1));
|
|
1125
|
+
const lastRow = table.rows.length + (header ? 1 : 0);
|
|
1126
|
+
const rows = [];
|
|
1127
|
+
if (header) {
|
|
1128
|
+
const cells = table.columns.map((column, index) => {
|
|
1129
|
+
const style = styles.xf({
|
|
1130
|
+
numFmt: 0,
|
|
1131
|
+
align: horizontal(column),
|
|
1132
|
+
wrap: false,
|
|
1133
|
+
header: true
|
|
1134
|
+
});
|
|
1135
|
+
return `<c r="${columnName(index)}1" t="inlineStr" s="${style}"><is><t xml:space="preserve">${escapeXml(column.title)}</t></is></c>`;
|
|
1136
|
+
}).join("");
|
|
1137
|
+
rows.push(`<row r="1">${cells}</row>`);
|
|
1138
|
+
}
|
|
1139
|
+
table.rows.forEach((row, rowIndex) => {
|
|
1140
|
+
const r = rowIndex + (header ? 2 : 1);
|
|
1141
|
+
rows.push(`<row r="${r}">${table.columns.map((column, index) => cell(`${columnName(index)}${r}`, row[index], column, styles, options)).join("")}</row>`);
|
|
1142
|
+
});
|
|
1143
|
+
const freeze = header && options.freezeHeader !== false ? "<sheetViews><sheetView workbookViewId=\"0\"><pane ySplit=\"1\" topLeftCell=\"A2\" activePane=\"bottomLeft\" state=\"frozen\"/><selection pane=\"bottomLeft\"/></sheetView></sheetViews>" : "<sheetViews><sheetView workbookViewId=\"0\"/></sheetViews>";
|
|
1144
|
+
const cols = table.columns.length ? `<cols>${widths.map((width, index) => `<col min="${index + 1}" max="${index + 1}" width="${width}" customWidth="1"/>`).join("")}</cols>` : "";
|
|
1145
|
+
const filter = header && options.autoFilter !== false && table.columns.length ? `<autoFilter ref="A1:${lastColumn}${Math.max(1, lastRow)}"/>` : "";
|
|
1146
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<worksheet xmlns="${MAIN}" xmlns:r="${REL}">${freeze}<sheetFormatPr defaultRowHeight="15"/>${cols}<sheetData>${rows.join("")}</sheetData>${filter}</worksheet>`;
|
|
1147
|
+
}
|
|
1148
|
+
function xlsxParts(table, options = {}) {
|
|
1149
|
+
const styles = new StyleBook();
|
|
1150
|
+
return {
|
|
1151
|
+
sheet: xlsxSheet(table, options, styles),
|
|
1152
|
+
styles: styles.xml(options),
|
|
1153
|
+
sheetName: sheetName(options.sheetName)
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
async function writeXlsx(table, options = {}, date = /* @__PURE__ */ new Date()) {
|
|
1157
|
+
const { sheet, styles, sheetName: name } = xlsxParts(table, options);
|
|
1158
|
+
const created = date.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
1159
|
+
const core = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">` + (options.title ? `<dc:title>${escapeXml(options.title)}</dc:title>` : "") + (options.author ? `<dc:creator>${escapeXml(options.author)}</dc:creator>` : "") + `<dcterms:created xsi:type="dcterms:W3CDTF">${created}</dcterms:created></cp:coreProperties>`;
|
|
1160
|
+
const bytes = await zip([
|
|
1161
|
+
{
|
|
1162
|
+
name: "[Content_Types].xml",
|
|
1163
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/></Types>`
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
name: "_rels/.rels",
|
|
1167
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="${PKG_REL}"><Relationship Id="rId1" Type="${REL}/officeDocument" Target="xl/workbook.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>`
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
name: "docProps/core.xml",
|
|
1171
|
+
data: core
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
name: "xl/workbook.xml",
|
|
1175
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<workbook xmlns="${MAIN}" xmlns:r="${REL}"><bookViews><workbookView/></bookViews><sheets><sheet name="${escapeXml(name)}" sheetId="1" r:id="rId1"/></sheets></workbook>`
|
|
1176
|
+
},
|
|
1177
|
+
{
|
|
1178
|
+
name: "xl/_rels/workbook.xml.rels",
|
|
1179
|
+
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<Relationships xmlns="${PKG_REL}"><Relationship Id="rId1" Type="${REL}/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="${REL}/styles" Target="styles.xml"/></Relationships>`
|
|
1180
|
+
},
|
|
1181
|
+
{
|
|
1182
|
+
name: "xl/worksheets/sheet1.xml",
|
|
1183
|
+
data: sheet
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
name: "xl/styles.xml",
|
|
1187
|
+
data: styles
|
|
1188
|
+
}
|
|
1189
|
+
], date, options.compress !== false);
|
|
1190
|
+
return new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
1191
|
+
}
|
|
1192
|
+
const TX_EXPORT_OPTIONS = new InjectionToken("TX_EXPORT_OPTIONS", {
|
|
1193
|
+
providedIn: "root",
|
|
1194
|
+
factory: () => ({})
|
|
1195
|
+
});
|
|
1196
|
+
function provideTxExport(options) {
|
|
1197
|
+
return {
|
|
1198
|
+
provide: TX_EXPORT_OPTIONS,
|
|
1199
|
+
useValue: options
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
const TX_EXPORT_EXTENSIONS = {
|
|
1203
|
+
csv: "csv",
|
|
1204
|
+
excel: "xlsx",
|
|
1205
|
+
word: "docx",
|
|
1206
|
+
pdf: "pdf",
|
|
1207
|
+
json: "json",
|
|
1208
|
+
html: "html",
|
|
1209
|
+
markdown: "md",
|
|
1210
|
+
copy: null,
|
|
1211
|
+
print: null
|
|
1212
|
+
};
|
|
1213
|
+
const FORMAT_KEYS = [
|
|
1214
|
+
"csv",
|
|
1215
|
+
"excel",
|
|
1216
|
+
"word",
|
|
1217
|
+
"pdf",
|
|
1218
|
+
"json",
|
|
1219
|
+
"html",
|
|
1220
|
+
"markdown",
|
|
1221
|
+
"copy",
|
|
1222
|
+
"print"
|
|
1223
|
+
];
|
|
1224
|
+
function mergeExportOptions(...layers) {
|
|
1225
|
+
const merged = {};
|
|
1226
|
+
for (const layer of layers) {
|
|
1227
|
+
if (!layer) continue;
|
|
1228
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
1229
|
+
if (value === void 0) continue;
|
|
1230
|
+
merged[key] = FORMAT_KEYS.includes(key) ? {
|
|
1231
|
+
...merged[key],
|
|
1232
|
+
...value
|
|
1233
|
+
} : value;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
return merged;
|
|
1237
|
+
}
|
|
1238
|
+
function loadDefaultExportFont() {
|
|
1239
|
+
return import("@tectra-ng/ui/export-font").then((module) => module.TX_EXPORT_FONT);
|
|
1240
|
+
}
|
|
1241
|
+
var TxExportService = class TxExportService {
|
|
1242
|
+
document = inject(DOCUMENT);
|
|
1243
|
+
defaults = inject(TX_EXPORT_OPTIONS);
|
|
1244
|
+
locale = inject(TxLocaleService);
|
|
1245
|
+
async export(request) {
|
|
1246
|
+
const options = mergeExportOptions(this.defaults, request.options);
|
|
1247
|
+
const table = buildExportTable(request.rows, request.fields, request.format);
|
|
1248
|
+
const context = this.textContext(options);
|
|
1249
|
+
if (request.format === "copy") {
|
|
1250
|
+
await this.copy(table, options, context);
|
|
1251
|
+
return {
|
|
1252
|
+
format: "copy",
|
|
1253
|
+
filename: null,
|
|
1254
|
+
rows: table.rows.length
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
if (request.format === "print") {
|
|
1258
|
+
await this.print(table, options, context);
|
|
1259
|
+
return {
|
|
1260
|
+
format: "print",
|
|
1261
|
+
filename: null,
|
|
1262
|
+
rows: table.rows.length
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
const file = await this.file(request.format, table, options, context);
|
|
1266
|
+
downloadBlob(this.document, file.blob, file.filename);
|
|
1267
|
+
return {
|
|
1268
|
+
format: request.format,
|
|
1269
|
+
filename: file.filename,
|
|
1270
|
+
rows: table.rows.length
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
async file(format, table, options = {}, context = this.textContext(options)) {
|
|
1274
|
+
const filename = withExtension(options.filename || "ExportedData", TX_EXPORT_EXTENSIONS[format]);
|
|
1275
|
+
const document = {
|
|
1276
|
+
title: options.title,
|
|
1277
|
+
subtitle: options.subtitle,
|
|
1278
|
+
showDate: options.showDate
|
|
1279
|
+
};
|
|
1280
|
+
const now = /* @__PURE__ */ new Date();
|
|
1281
|
+
switch (format) {
|
|
1282
|
+
case "csv": {
|
|
1283
|
+
const csv = writeCsv(table, options.csv);
|
|
1284
|
+
return {
|
|
1285
|
+
filename,
|
|
1286
|
+
blob: new Blob([options.csv?.bom === false ? "" : "", csv], { type: "text/csv;charset=utf-8" })
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
case "excel": return {
|
|
1290
|
+
filename,
|
|
1291
|
+
blob: await writeXlsx(table, {
|
|
1292
|
+
title: options.title,
|
|
1293
|
+
...options.excel
|
|
1294
|
+
}, now)
|
|
1295
|
+
};
|
|
1296
|
+
case "word": return {
|
|
1297
|
+
filename,
|
|
1298
|
+
blob: await writeDocx(table, {
|
|
1299
|
+
...document,
|
|
1300
|
+
...options.word
|
|
1301
|
+
}, context, now)
|
|
1302
|
+
};
|
|
1303
|
+
case "pdf": {
|
|
1304
|
+
const pdf = {
|
|
1305
|
+
...document,
|
|
1306
|
+
...options.pdf
|
|
1307
|
+
};
|
|
1308
|
+
return {
|
|
1309
|
+
filename,
|
|
1310
|
+
blob: await writePdf(table, pdf, await (pdf.font ?? loadDefaultExportFont)(), context, now)
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
case "json": return {
|
|
1314
|
+
filename,
|
|
1315
|
+
blob: new Blob([writeJson(table, options.json)], { type: "application/json;charset=utf-8" })
|
|
1316
|
+
};
|
|
1317
|
+
case "html": return {
|
|
1318
|
+
filename,
|
|
1319
|
+
blob: new Blob([writeHtml(table, {
|
|
1320
|
+
...document,
|
|
1321
|
+
...options.html,
|
|
1322
|
+
lang: this.lang(options)
|
|
1323
|
+
}, context, now)], { type: "text/html;charset=utf-8" })
|
|
1324
|
+
};
|
|
1325
|
+
case "markdown": return {
|
|
1326
|
+
filename,
|
|
1327
|
+
blob: new Blob([writeMarkdown(table, {
|
|
1328
|
+
title: options.title,
|
|
1329
|
+
...options.markdown
|
|
1330
|
+
}, context)], { type: "text/markdown;charset=utf-8" })
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
textContext(options = {}) {
|
|
1335
|
+
const translations = this.locale.translations();
|
|
1336
|
+
return {
|
|
1337
|
+
locale: options.locale ?? this.locale.locale().intl,
|
|
1338
|
+
yes: translations.yes,
|
|
1339
|
+
no: translations.no
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
lang(options) {
|
|
1343
|
+
return options.locale ?? this.locale.locale().intl;
|
|
1344
|
+
}
|
|
1345
|
+
async copy(table, options, context) {
|
|
1346
|
+
const header = options.copy?.header !== false;
|
|
1347
|
+
const text = writeTsv(table, context, header);
|
|
1348
|
+
const clipboard = this.document.defaultView?.navigator?.clipboard;
|
|
1349
|
+
if (!clipboard) throw new Error("Clipboard is not available");
|
|
1350
|
+
const Item = this.document.defaultView?.ClipboardItem;
|
|
1351
|
+
if (options.copy?.html !== false && Item && clipboard.write) {
|
|
1352
|
+
const html = `<meta charset="utf-8">${htmlTable(table, context, header)}`;
|
|
1353
|
+
await clipboard.write([new Item({
|
|
1354
|
+
"text/plain": new Blob([text], { type: "text/plain" }),
|
|
1355
|
+
"text/html": new Blob([html], { type: "text/html" })
|
|
1356
|
+
})]);
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
await clipboard.writeText(text);
|
|
1360
|
+
}
|
|
1361
|
+
async print(table, options, context) {
|
|
1362
|
+
const print = {
|
|
1363
|
+
title: options.title,
|
|
1364
|
+
subtitle: options.subtitle,
|
|
1365
|
+
showDate: options.showDate,
|
|
1366
|
+
...options.print
|
|
1367
|
+
};
|
|
1368
|
+
const html = writeHtml(table, {
|
|
1369
|
+
...print,
|
|
1370
|
+
lang: this.lang(options),
|
|
1371
|
+
page: printPageCss(print, table.columns.length)
|
|
1372
|
+
}, context);
|
|
1373
|
+
await printHtml(this.document, html);
|
|
1374
|
+
}
|
|
1375
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1376
|
+
minVersion: "12.0.0",
|
|
1377
|
+
version: "22.2.3",
|
|
1378
|
+
ngImport: i0,
|
|
1379
|
+
type: TxExportService,
|
|
1380
|
+
deps: [],
|
|
1381
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1382
|
+
});
|
|
1383
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1384
|
+
minVersion: "12.0.0",
|
|
1385
|
+
version: "22.2.3",
|
|
1386
|
+
ngImport: i0,
|
|
1387
|
+
type: TxExportService,
|
|
1388
|
+
providedIn: "root"
|
|
1389
|
+
});
|
|
1390
|
+
};
|
|
1391
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1392
|
+
minVersion: "12.0.0",
|
|
1393
|
+
version: "22.2.3",
|
|
1394
|
+
ngImport: i0,
|
|
1395
|
+
type: TxExportService,
|
|
1396
|
+
decorators: [{
|
|
1397
|
+
type: Injectable,
|
|
1398
|
+
args: [{ providedIn: "root" }]
|
|
1399
|
+
}]
|
|
1400
|
+
});
|
|
1401
|
+
const COPIED_FOR = 1600;
|
|
1402
|
+
const TX_EXPORT_ICONS = {
|
|
1403
|
+
csv: "file",
|
|
1404
|
+
excel: "file-excel",
|
|
1405
|
+
word: "file-word",
|
|
1406
|
+
pdf: "file-pdf",
|
|
1407
|
+
json: "code",
|
|
1408
|
+
html: "code",
|
|
1409
|
+
markdown: "file-edit",
|
|
1410
|
+
copy: "copy",
|
|
1411
|
+
print: "print"
|
|
1412
|
+
};
|
|
1413
|
+
var TxExportAction = class TxExportAction {
|
|
1414
|
+
exporter = inject(TxExportService);
|
|
1415
|
+
defaults = inject(TX_EXPORT_OPTIONS);
|
|
1416
|
+
announcer = inject(TxAnnouncer);
|
|
1417
|
+
copiedTimer = null;
|
|
1418
|
+
data = model([], ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
|
|
1419
|
+
fields = input([], ...ngDevMode ? [{ debugName: "fields" }] : /* istanbul ignore next */ []);
|
|
1420
|
+
fetchData = input(void 0, ...ngDevMode ? [{ debugName: "fetchData" }] : /* istanbul ignore next */ []);
|
|
1421
|
+
options = input(void 0, ...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
|
|
1422
|
+
filename = input(void 0, ...ngDevMode ? [{ debugName: "filename" }] : /* istanbul ignore next */ []);
|
|
1423
|
+
title = input(void 0, ...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
|
|
1424
|
+
loading = input(false, {
|
|
1425
|
+
...ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {},
|
|
1426
|
+
transform: booleanAttribute
|
|
1427
|
+
});
|
|
1428
|
+
disabled = input(false, {
|
|
1429
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
1430
|
+
transform: booleanAttribute
|
|
1431
|
+
});
|
|
1432
|
+
label = input(void 0, ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
1433
|
+
tooltip = input(void 0, ...ngDevMode ? [{ debugName: "tooltip" }] : /* istanbul ignore next */ []);
|
|
1434
|
+
severity = input("primary", ...ngDevMode ? [{ debugName: "severity" }] : /* istanbul ignore next */ []);
|
|
1435
|
+
variant = input(void 0, ...ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []);
|
|
1436
|
+
size = input("medium", ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
|
|
1437
|
+
ptOptions = input(void 0, ...ngDevMode ? [{ debugName: "ptOptions" }] : /* istanbul ignore next */ []);
|
|
1438
|
+
unstyled = input(void 0, {
|
|
1439
|
+
...ngDevMode ? { debugName: "unstyled" } : /* istanbul ignore next */ {},
|
|
1440
|
+
transform: optionalBoolean
|
|
1441
|
+
});
|
|
1442
|
+
exported = output();
|
|
1443
|
+
failed = output();
|
|
1444
|
+
translations = injectTranslations();
|
|
1445
|
+
exporting = signal(false, ...ngDevMode ? [{ debugName: "exporting" }] : /* istanbul ignore next */ []);
|
|
1446
|
+
copied = signal(false, ...ngDevMode ? [{ debugName: "copied" }] : /* istanbul ignore next */ []);
|
|
1447
|
+
busy = computed(() => this.loading() || this.exporting(), ...ngDevMode ? [{ debugName: "busy" }] : /* istanbul ignore next */ []);
|
|
1448
|
+
formatLabel(format) {
|
|
1449
|
+
const translations = this.translations();
|
|
1450
|
+
return {
|
|
1451
|
+
csv: translations.exportCsv,
|
|
1452
|
+
excel: translations.exportExcel,
|
|
1453
|
+
word: translations.exportWord,
|
|
1454
|
+
pdf: translations.exportPdf,
|
|
1455
|
+
json: translations.exportJson,
|
|
1456
|
+
html: translations.exportHtml,
|
|
1457
|
+
markdown: translations.exportMarkdown,
|
|
1458
|
+
copy: translations.exportCopy,
|
|
1459
|
+
print: translations.exportPrint
|
|
1460
|
+
}[format];
|
|
1461
|
+
}
|
|
1462
|
+
async run(format) {
|
|
1463
|
+
if (this.busy() || this.disabled()) return;
|
|
1464
|
+
this.exporting.set(true);
|
|
1465
|
+
try {
|
|
1466
|
+
const fetch = this.fetchData();
|
|
1467
|
+
if (fetch) {
|
|
1468
|
+
const rows = await fetch();
|
|
1469
|
+
if (!rows) return;
|
|
1470
|
+
this.data.set(rows);
|
|
1471
|
+
}
|
|
1472
|
+
const data = this.data();
|
|
1473
|
+
const options = mergeExportOptions(this.defaults, this.options(), {
|
|
1474
|
+
filename: this.filename() || void 0,
|
|
1475
|
+
title: this.title() || void 0
|
|
1476
|
+
});
|
|
1477
|
+
const result = await this.exporter.export({
|
|
1478
|
+
format,
|
|
1479
|
+
rows: data,
|
|
1480
|
+
fields: this.fields(),
|
|
1481
|
+
options
|
|
1482
|
+
});
|
|
1483
|
+
if (format === "copy") this.markCopied();
|
|
1484
|
+
this.exported.emit({
|
|
1485
|
+
...result,
|
|
1486
|
+
data
|
|
1487
|
+
});
|
|
1488
|
+
} catch (error) {
|
|
1489
|
+
this.failed.emit(error);
|
|
1490
|
+
} finally {
|
|
1491
|
+
this.exporting.set(false);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
markCopied() {
|
|
1495
|
+
this.copied.set(true);
|
|
1496
|
+
this.announcer.announce(this.translations().exportCopied);
|
|
1497
|
+
if (this.copiedTimer) clearTimeout(this.copiedTimer);
|
|
1498
|
+
this.copiedTimer = setTimeout(() => this.copied.set(false), COPIED_FOR);
|
|
1499
|
+
}
|
|
1500
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1501
|
+
minVersion: "12.0.0",
|
|
1502
|
+
version: "22.2.3",
|
|
1503
|
+
ngImport: i0,
|
|
1504
|
+
type: TxExportAction,
|
|
1505
|
+
deps: [],
|
|
1506
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
1507
|
+
});
|
|
1508
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
1509
|
+
minVersion: "17.1.0",
|
|
1510
|
+
version: "22.2.3",
|
|
1511
|
+
type: TxExportAction,
|
|
1512
|
+
isStandalone: true,
|
|
1513
|
+
inputs: {
|
|
1514
|
+
data: {
|
|
1515
|
+
classPropertyName: "data",
|
|
1516
|
+
publicName: "data",
|
|
1517
|
+
isSignal: true,
|
|
1518
|
+
isRequired: false,
|
|
1519
|
+
transformFunction: null
|
|
1520
|
+
},
|
|
1521
|
+
fields: {
|
|
1522
|
+
classPropertyName: "fields",
|
|
1523
|
+
publicName: "fields",
|
|
1524
|
+
isSignal: true,
|
|
1525
|
+
isRequired: false,
|
|
1526
|
+
transformFunction: null
|
|
1527
|
+
},
|
|
1528
|
+
fetchData: {
|
|
1529
|
+
classPropertyName: "fetchData",
|
|
1530
|
+
publicName: "fetchData",
|
|
1531
|
+
isSignal: true,
|
|
1532
|
+
isRequired: false,
|
|
1533
|
+
transformFunction: null
|
|
1534
|
+
},
|
|
1535
|
+
options: {
|
|
1536
|
+
classPropertyName: "options",
|
|
1537
|
+
publicName: "options",
|
|
1538
|
+
isSignal: true,
|
|
1539
|
+
isRequired: false,
|
|
1540
|
+
transformFunction: null
|
|
1541
|
+
},
|
|
1542
|
+
filename: {
|
|
1543
|
+
classPropertyName: "filename",
|
|
1544
|
+
publicName: "filename",
|
|
1545
|
+
isSignal: true,
|
|
1546
|
+
isRequired: false,
|
|
1547
|
+
transformFunction: null
|
|
1548
|
+
},
|
|
1549
|
+
title: {
|
|
1550
|
+
classPropertyName: "title",
|
|
1551
|
+
publicName: "title",
|
|
1552
|
+
isSignal: true,
|
|
1553
|
+
isRequired: false,
|
|
1554
|
+
transformFunction: null
|
|
1555
|
+
},
|
|
1556
|
+
loading: {
|
|
1557
|
+
classPropertyName: "loading",
|
|
1558
|
+
publicName: "loading",
|
|
1559
|
+
isSignal: true,
|
|
1560
|
+
isRequired: false,
|
|
1561
|
+
transformFunction: null
|
|
1562
|
+
},
|
|
1563
|
+
disabled: {
|
|
1564
|
+
classPropertyName: "disabled",
|
|
1565
|
+
publicName: "disabled",
|
|
1566
|
+
isSignal: true,
|
|
1567
|
+
isRequired: false,
|
|
1568
|
+
transformFunction: null
|
|
1569
|
+
},
|
|
1570
|
+
label: {
|
|
1571
|
+
classPropertyName: "label",
|
|
1572
|
+
publicName: "label",
|
|
1573
|
+
isSignal: true,
|
|
1574
|
+
isRequired: false,
|
|
1575
|
+
transformFunction: null
|
|
1576
|
+
},
|
|
1577
|
+
tooltip: {
|
|
1578
|
+
classPropertyName: "tooltip",
|
|
1579
|
+
publicName: "tooltip",
|
|
1580
|
+
isSignal: true,
|
|
1581
|
+
isRequired: false,
|
|
1582
|
+
transformFunction: null
|
|
1583
|
+
},
|
|
1584
|
+
severity: {
|
|
1585
|
+
classPropertyName: "severity",
|
|
1586
|
+
publicName: "severity",
|
|
1587
|
+
isSignal: true,
|
|
1588
|
+
isRequired: false,
|
|
1589
|
+
transformFunction: null
|
|
1590
|
+
},
|
|
1591
|
+
variant: {
|
|
1592
|
+
classPropertyName: "variant",
|
|
1593
|
+
publicName: "variant",
|
|
1594
|
+
isSignal: true,
|
|
1595
|
+
isRequired: false,
|
|
1596
|
+
transformFunction: null
|
|
1597
|
+
},
|
|
1598
|
+
size: {
|
|
1599
|
+
classPropertyName: "size",
|
|
1600
|
+
publicName: "size",
|
|
1601
|
+
isSignal: true,
|
|
1602
|
+
isRequired: false,
|
|
1603
|
+
transformFunction: null
|
|
1604
|
+
},
|
|
1605
|
+
ptOptions: {
|
|
1606
|
+
classPropertyName: "ptOptions",
|
|
1607
|
+
publicName: "ptOptions",
|
|
1608
|
+
isSignal: true,
|
|
1609
|
+
isRequired: false,
|
|
1610
|
+
transformFunction: null
|
|
1611
|
+
},
|
|
1612
|
+
unstyled: {
|
|
1613
|
+
classPropertyName: "unstyled",
|
|
1614
|
+
publicName: "unstyled",
|
|
1615
|
+
isSignal: true,
|
|
1616
|
+
isRequired: false,
|
|
1617
|
+
transformFunction: null
|
|
1618
|
+
}
|
|
1619
|
+
},
|
|
1620
|
+
outputs: {
|
|
1621
|
+
data: "dataChange",
|
|
1622
|
+
exported: "exported",
|
|
1623
|
+
failed: "failed"
|
|
1624
|
+
},
|
|
1625
|
+
ngImport: i0
|
|
1626
|
+
});
|
|
1627
|
+
};
|
|
1628
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1629
|
+
minVersion: "12.0.0",
|
|
1630
|
+
version: "22.2.3",
|
|
1631
|
+
ngImport: i0,
|
|
1632
|
+
type: TxExportAction,
|
|
1633
|
+
decorators: [{ type: Directive }],
|
|
1634
|
+
propDecorators: {
|
|
1635
|
+
data: [{
|
|
1636
|
+
type: i0.Input,
|
|
1637
|
+
args: [{
|
|
1638
|
+
isSignal: true,
|
|
1639
|
+
alias: "data",
|
|
1640
|
+
required: false
|
|
1641
|
+
}]
|
|
1642
|
+
}, {
|
|
1643
|
+
type: i0.Output,
|
|
1644
|
+
args: ["dataChange"]
|
|
1645
|
+
}],
|
|
1646
|
+
fields: [{
|
|
1647
|
+
type: i0.Input,
|
|
1648
|
+
args: [{
|
|
1649
|
+
isSignal: true,
|
|
1650
|
+
alias: "fields",
|
|
1651
|
+
required: false
|
|
1652
|
+
}]
|
|
1653
|
+
}],
|
|
1654
|
+
fetchData: [{
|
|
1655
|
+
type: i0.Input,
|
|
1656
|
+
args: [{
|
|
1657
|
+
isSignal: true,
|
|
1658
|
+
alias: "fetchData",
|
|
1659
|
+
required: false
|
|
1660
|
+
}]
|
|
1661
|
+
}],
|
|
1662
|
+
options: [{
|
|
1663
|
+
type: i0.Input,
|
|
1664
|
+
args: [{
|
|
1665
|
+
isSignal: true,
|
|
1666
|
+
alias: "options",
|
|
1667
|
+
required: false
|
|
1668
|
+
}]
|
|
1669
|
+
}],
|
|
1670
|
+
filename: [{
|
|
1671
|
+
type: i0.Input,
|
|
1672
|
+
args: [{
|
|
1673
|
+
isSignal: true,
|
|
1674
|
+
alias: "filename",
|
|
1675
|
+
required: false
|
|
1676
|
+
}]
|
|
1677
|
+
}],
|
|
1678
|
+
title: [{
|
|
1679
|
+
type: i0.Input,
|
|
1680
|
+
args: [{
|
|
1681
|
+
isSignal: true,
|
|
1682
|
+
alias: "title",
|
|
1683
|
+
required: false
|
|
1684
|
+
}]
|
|
1685
|
+
}],
|
|
1686
|
+
loading: [{
|
|
1687
|
+
type: i0.Input,
|
|
1688
|
+
args: [{
|
|
1689
|
+
isSignal: true,
|
|
1690
|
+
alias: "loading",
|
|
1691
|
+
required: false
|
|
1692
|
+
}]
|
|
1693
|
+
}],
|
|
1694
|
+
disabled: [{
|
|
1695
|
+
type: i0.Input,
|
|
1696
|
+
args: [{
|
|
1697
|
+
isSignal: true,
|
|
1698
|
+
alias: "disabled",
|
|
1699
|
+
required: false
|
|
1700
|
+
}]
|
|
1701
|
+
}],
|
|
1702
|
+
label: [{
|
|
1703
|
+
type: i0.Input,
|
|
1704
|
+
args: [{
|
|
1705
|
+
isSignal: true,
|
|
1706
|
+
alias: "label",
|
|
1707
|
+
required: false
|
|
1708
|
+
}]
|
|
1709
|
+
}],
|
|
1710
|
+
tooltip: [{
|
|
1711
|
+
type: i0.Input,
|
|
1712
|
+
args: [{
|
|
1713
|
+
isSignal: true,
|
|
1714
|
+
alias: "tooltip",
|
|
1715
|
+
required: false
|
|
1716
|
+
}]
|
|
1717
|
+
}],
|
|
1718
|
+
severity: [{
|
|
1719
|
+
type: i0.Input,
|
|
1720
|
+
args: [{
|
|
1721
|
+
isSignal: true,
|
|
1722
|
+
alias: "severity",
|
|
1723
|
+
required: false
|
|
1724
|
+
}]
|
|
1725
|
+
}],
|
|
1726
|
+
variant: [{
|
|
1727
|
+
type: i0.Input,
|
|
1728
|
+
args: [{
|
|
1729
|
+
isSignal: true,
|
|
1730
|
+
alias: "variant",
|
|
1731
|
+
required: false
|
|
1732
|
+
}]
|
|
1733
|
+
}],
|
|
1734
|
+
size: [{
|
|
1735
|
+
type: i0.Input,
|
|
1736
|
+
args: [{
|
|
1737
|
+
isSignal: true,
|
|
1738
|
+
alias: "size",
|
|
1739
|
+
required: false
|
|
1740
|
+
}]
|
|
1741
|
+
}],
|
|
1742
|
+
ptOptions: [{
|
|
1743
|
+
type: i0.Input,
|
|
1744
|
+
args: [{
|
|
1745
|
+
isSignal: true,
|
|
1746
|
+
alias: "ptOptions",
|
|
1747
|
+
required: false
|
|
1748
|
+
}]
|
|
1749
|
+
}],
|
|
1750
|
+
unstyled: [{
|
|
1751
|
+
type: i0.Input,
|
|
1752
|
+
args: [{
|
|
1753
|
+
isSignal: true,
|
|
1754
|
+
alias: "unstyled",
|
|
1755
|
+
required: false
|
|
1756
|
+
}]
|
|
1757
|
+
}],
|
|
1758
|
+
exported: [{
|
|
1759
|
+
type: i0.Output,
|
|
1760
|
+
args: ["exported"]
|
|
1761
|
+
}],
|
|
1762
|
+
failed: [{
|
|
1763
|
+
type: i0.Output,
|
|
1764
|
+
args: ["failed"]
|
|
1765
|
+
}]
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
const TEMPLATE = `
|
|
1769
|
+
<button
|
|
1770
|
+
txButton
|
|
1771
|
+
type="button"
|
|
1772
|
+
[icon]="icon()"
|
|
1773
|
+
[label]="label()"
|
|
1774
|
+
[severity]="severity()"
|
|
1775
|
+
[variant]="variant()"
|
|
1776
|
+
[size]="size()"
|
|
1777
|
+
[loading]="busy()"
|
|
1778
|
+
[disabled]="disabled()"
|
|
1779
|
+
[unstyled]="unstyled()"
|
|
1780
|
+
[txTooltip]="resolvedTooltip()"
|
|
1781
|
+
[attr.aria-label]="ariaLabel()"
|
|
1782
|
+
[attr.aria-busy]="busy() || null"
|
|
1783
|
+
[class]="passThrough().button?.class"
|
|
1784
|
+
[style]="passThrough().button?.style"
|
|
1785
|
+
(click)="run(resolvedFormat())"
|
|
1786
|
+
></button>
|
|
1787
|
+
`;
|
|
1788
|
+
const HOST = {
|
|
1789
|
+
"[class]": "passThrough().root?.class",
|
|
1790
|
+
"[style]": "passThrough().root?.style",
|
|
1791
|
+
"[attr.data-format]": "resolvedFormat()"
|
|
1792
|
+
};
|
|
1793
|
+
var TxExportButtonBase = class TxExportButtonBase extends TxExportAction {
|
|
1794
|
+
pt = input(void 0, ...ngDevMode ? [{ debugName: "pt" }] : /* istanbul ignore next */ []);
|
|
1795
|
+
passThrough = injectPassThrough("export", this, this.pt, this.ptOptions);
|
|
1796
|
+
icon = computed(() => this.copied() ? "check" : TX_EXPORT_ICONS[this.resolvedFormat()], ...ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []);
|
|
1797
|
+
resolvedTooltip = computed(() => this.copied() ? this.translations().exportCopied : this.tooltip() ?? this.formatLabel(this.resolvedFormat()), ...ngDevMode ? [{ debugName: "resolvedTooltip" }] : /* istanbul ignore next */ []);
|
|
1798
|
+
ariaLabel = computed(() => this.label() ? null : this.resolvedTooltip(), ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
|
|
1799
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1800
|
+
minVersion: "12.0.0",
|
|
1801
|
+
version: "22.2.3",
|
|
1802
|
+
ngImport: i0,
|
|
1803
|
+
type: TxExportButtonBase,
|
|
1804
|
+
deps: null,
|
|
1805
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
1806
|
+
});
|
|
1807
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
1808
|
+
minVersion: "17.1.0",
|
|
1809
|
+
version: "22.2.3",
|
|
1810
|
+
type: TxExportButtonBase,
|
|
1811
|
+
isStandalone: true,
|
|
1812
|
+
inputs: { pt: {
|
|
1813
|
+
classPropertyName: "pt",
|
|
1814
|
+
publicName: "pt",
|
|
1815
|
+
isSignal: true,
|
|
1816
|
+
isRequired: false,
|
|
1817
|
+
transformFunction: null
|
|
1818
|
+
} },
|
|
1819
|
+
usesInheritance: true,
|
|
1820
|
+
ngImport: i0
|
|
1821
|
+
});
|
|
1822
|
+
};
|
|
1823
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1824
|
+
minVersion: "12.0.0",
|
|
1825
|
+
version: "22.2.3",
|
|
1826
|
+
ngImport: i0,
|
|
1827
|
+
type: TxExportButtonBase,
|
|
1828
|
+
decorators: [{ type: Directive }],
|
|
1829
|
+
propDecorators: { pt: [{
|
|
1830
|
+
type: i0.Input,
|
|
1831
|
+
args: [{
|
|
1832
|
+
isSignal: true,
|
|
1833
|
+
alias: "pt",
|
|
1834
|
+
required: false
|
|
1835
|
+
}]
|
|
1836
|
+
}] }
|
|
1837
|
+
});
|
|
1838
|
+
var TxExportButton = class TxExportButton extends TxExportButtonBase {
|
|
1839
|
+
format = input("csv", ...ngDevMode ? [{ debugName: "format" }] : /* istanbul ignore next */ []);
|
|
1840
|
+
resolvedFormat = computed(() => this.format(), ...ngDevMode ? [{ debugName: "resolvedFormat" }] : /* istanbul ignore next */ []);
|
|
1841
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1842
|
+
minVersion: "12.0.0",
|
|
1843
|
+
version: "22.2.3",
|
|
1844
|
+
ngImport: i0,
|
|
1845
|
+
type: TxExportButton,
|
|
1846
|
+
deps: null,
|
|
1847
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1848
|
+
});
|
|
1849
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1850
|
+
minVersion: "17.1.0",
|
|
1851
|
+
version: "22.2.3",
|
|
1852
|
+
type: TxExportButton,
|
|
1853
|
+
isStandalone: true,
|
|
1854
|
+
selector: "tx-export-button",
|
|
1855
|
+
inputs: { format: {
|
|
1856
|
+
classPropertyName: "format",
|
|
1857
|
+
publicName: "format",
|
|
1858
|
+
isSignal: true,
|
|
1859
|
+
isRequired: false,
|
|
1860
|
+
transformFunction: null
|
|
1861
|
+
} },
|
|
1862
|
+
host: {
|
|
1863
|
+
properties: {
|
|
1864
|
+
"class": "passThrough().root?.class",
|
|
1865
|
+
"style": "passThrough().root?.style",
|
|
1866
|
+
"attr.data-format": "resolvedFormat()"
|
|
1867
|
+
},
|
|
1868
|
+
classAttribute: "tx-export tx-export-button"
|
|
1869
|
+
},
|
|
1870
|
+
usesInheritance: true,
|
|
1871
|
+
ngImport: i0,
|
|
1872
|
+
template: "\n <button\n txButton\n type=\"button\"\n [icon]=\"icon()\"\n [label]=\"label()\"\n [severity]=\"severity()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [loading]=\"busy()\"\n [disabled]=\"disabled()\"\n [unstyled]=\"unstyled()\"\n [txTooltip]=\"resolvedTooltip()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-busy]=\"busy() || null\"\n [class]=\"passThrough().button?.class\"\n [style]=\"passThrough().button?.style\"\n (click)=\"run(resolvedFormat())\"\n ></button>\n",
|
|
1873
|
+
isInline: true,
|
|
1874
|
+
dependencies: [{
|
|
1875
|
+
kind: "component",
|
|
1876
|
+
type: TxButton,
|
|
1877
|
+
selector: "button[txButton], a[txButton]",
|
|
1878
|
+
inputs: [
|
|
1879
|
+
"label",
|
|
1880
|
+
"severity",
|
|
1881
|
+
"size",
|
|
1882
|
+
"variant",
|
|
1883
|
+
"outlined",
|
|
1884
|
+
"text",
|
|
1885
|
+
"link",
|
|
1886
|
+
"rounded",
|
|
1887
|
+
"raised",
|
|
1888
|
+
"plain",
|
|
1889
|
+
"fluid",
|
|
1890
|
+
"disabled",
|
|
1891
|
+
"tabindex",
|
|
1892
|
+
"icon",
|
|
1893
|
+
"iconPos",
|
|
1894
|
+
"iconOnly",
|
|
1895
|
+
"loading",
|
|
1896
|
+
"loadingIcon",
|
|
1897
|
+
"badge",
|
|
1898
|
+
"badgeSeverity",
|
|
1899
|
+
"dt",
|
|
1900
|
+
"pt",
|
|
1901
|
+
"ptOptions",
|
|
1902
|
+
"unstyled"
|
|
1903
|
+
]
|
|
1904
|
+
}, {
|
|
1905
|
+
kind: "directive",
|
|
1906
|
+
type: TxTooltip,
|
|
1907
|
+
selector: "[txTooltip]",
|
|
1908
|
+
inputs: [
|
|
1909
|
+
"txTooltip",
|
|
1910
|
+
"tooltipPlacement",
|
|
1911
|
+
"tooltipEvent",
|
|
1912
|
+
"tooltipShowDelay",
|
|
1913
|
+
"tooltipHideDelay",
|
|
1914
|
+
"tooltipLife",
|
|
1915
|
+
"tooltipOffset",
|
|
1916
|
+
"tooltipArrow",
|
|
1917
|
+
"tooltipInteractive",
|
|
1918
|
+
"tooltipDisabled",
|
|
1919
|
+
"tooltipOverflowOnly",
|
|
1920
|
+
"tooltipMultiline",
|
|
1921
|
+
"tooltipContext",
|
|
1922
|
+
"tooltipClass",
|
|
1923
|
+
"tooltipDt",
|
|
1924
|
+
"tooltipPt",
|
|
1925
|
+
"tooltipPtOptions",
|
|
1926
|
+
"tooltipUnstyled"
|
|
1927
|
+
],
|
|
1928
|
+
outputs: ["tooltipShown", "tooltipHidden"],
|
|
1929
|
+
exportAs: ["txTooltip"]
|
|
1930
|
+
}],
|
|
1931
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
1932
|
+
});
|
|
1933
|
+
};
|
|
1934
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1935
|
+
minVersion: "12.0.0",
|
|
1936
|
+
version: "22.2.3",
|
|
1937
|
+
ngImport: i0,
|
|
1938
|
+
type: TxExportButton,
|
|
1939
|
+
decorators: [{
|
|
1940
|
+
type: Component,
|
|
1941
|
+
args: [{
|
|
1942
|
+
selector: "tx-export-button",
|
|
1943
|
+
imports: [TxButton, TxTooltip],
|
|
1944
|
+
template: TEMPLATE,
|
|
1945
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
1946
|
+
host: {
|
|
1947
|
+
class: "tx-export tx-export-button",
|
|
1948
|
+
...HOST
|
|
1949
|
+
}
|
|
1950
|
+
}]
|
|
1951
|
+
}],
|
|
1952
|
+
propDecorators: { format: [{
|
|
1953
|
+
type: i0.Input,
|
|
1954
|
+
args: [{
|
|
1955
|
+
isSignal: true,
|
|
1956
|
+
alias: "format",
|
|
1957
|
+
required: false
|
|
1958
|
+
}]
|
|
1959
|
+
}] }
|
|
1960
|
+
});
|
|
1961
|
+
var TxExportCsv = class TxExportCsv extends TxExportButtonBase {
|
|
1962
|
+
resolvedFormat = () => "csv";
|
|
1963
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
1964
|
+
minVersion: "12.0.0",
|
|
1965
|
+
version: "22.2.3",
|
|
1966
|
+
ngImport: i0,
|
|
1967
|
+
type: TxExportCsv,
|
|
1968
|
+
deps: null,
|
|
1969
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
1970
|
+
});
|
|
1971
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
1972
|
+
minVersion: "14.0.0",
|
|
1973
|
+
version: "22.2.3",
|
|
1974
|
+
type: TxExportCsv,
|
|
1975
|
+
isStandalone: true,
|
|
1976
|
+
selector: "tx-export-csv",
|
|
1977
|
+
host: {
|
|
1978
|
+
properties: {
|
|
1979
|
+
"class": "passThrough().root?.class",
|
|
1980
|
+
"style": "passThrough().root?.style",
|
|
1981
|
+
"attr.data-format": "resolvedFormat()"
|
|
1982
|
+
},
|
|
1983
|
+
classAttribute: "tx-export tx-export-csv"
|
|
1984
|
+
},
|
|
1985
|
+
usesInheritance: true,
|
|
1986
|
+
ngImport: i0,
|
|
1987
|
+
template: "\n <button\n txButton\n type=\"button\"\n [icon]=\"icon()\"\n [label]=\"label()\"\n [severity]=\"severity()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [loading]=\"busy()\"\n [disabled]=\"disabled()\"\n [unstyled]=\"unstyled()\"\n [txTooltip]=\"resolvedTooltip()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-busy]=\"busy() || null\"\n [class]=\"passThrough().button?.class\"\n [style]=\"passThrough().button?.style\"\n (click)=\"run(resolvedFormat())\"\n ></button>\n",
|
|
1988
|
+
isInline: true,
|
|
1989
|
+
dependencies: [{
|
|
1990
|
+
kind: "component",
|
|
1991
|
+
type: TxButton,
|
|
1992
|
+
selector: "button[txButton], a[txButton]",
|
|
1993
|
+
inputs: [
|
|
1994
|
+
"label",
|
|
1995
|
+
"severity",
|
|
1996
|
+
"size",
|
|
1997
|
+
"variant",
|
|
1998
|
+
"outlined",
|
|
1999
|
+
"text",
|
|
2000
|
+
"link",
|
|
2001
|
+
"rounded",
|
|
2002
|
+
"raised",
|
|
2003
|
+
"plain",
|
|
2004
|
+
"fluid",
|
|
2005
|
+
"disabled",
|
|
2006
|
+
"tabindex",
|
|
2007
|
+
"icon",
|
|
2008
|
+
"iconPos",
|
|
2009
|
+
"iconOnly",
|
|
2010
|
+
"loading",
|
|
2011
|
+
"loadingIcon",
|
|
2012
|
+
"badge",
|
|
2013
|
+
"badgeSeverity",
|
|
2014
|
+
"dt",
|
|
2015
|
+
"pt",
|
|
2016
|
+
"ptOptions",
|
|
2017
|
+
"unstyled"
|
|
2018
|
+
]
|
|
2019
|
+
}, {
|
|
2020
|
+
kind: "directive",
|
|
2021
|
+
type: TxTooltip,
|
|
2022
|
+
selector: "[txTooltip]",
|
|
2023
|
+
inputs: [
|
|
2024
|
+
"txTooltip",
|
|
2025
|
+
"tooltipPlacement",
|
|
2026
|
+
"tooltipEvent",
|
|
2027
|
+
"tooltipShowDelay",
|
|
2028
|
+
"tooltipHideDelay",
|
|
2029
|
+
"tooltipLife",
|
|
2030
|
+
"tooltipOffset",
|
|
2031
|
+
"tooltipArrow",
|
|
2032
|
+
"tooltipInteractive",
|
|
2033
|
+
"tooltipDisabled",
|
|
2034
|
+
"tooltipOverflowOnly",
|
|
2035
|
+
"tooltipMultiline",
|
|
2036
|
+
"tooltipContext",
|
|
2037
|
+
"tooltipClass",
|
|
2038
|
+
"tooltipDt",
|
|
2039
|
+
"tooltipPt",
|
|
2040
|
+
"tooltipPtOptions",
|
|
2041
|
+
"tooltipUnstyled"
|
|
2042
|
+
],
|
|
2043
|
+
outputs: ["tooltipShown", "tooltipHidden"],
|
|
2044
|
+
exportAs: ["txTooltip"]
|
|
2045
|
+
}],
|
|
2046
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2047
|
+
});
|
|
2048
|
+
};
|
|
2049
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2050
|
+
minVersion: "12.0.0",
|
|
2051
|
+
version: "22.2.3",
|
|
2052
|
+
ngImport: i0,
|
|
2053
|
+
type: TxExportCsv,
|
|
2054
|
+
decorators: [{
|
|
2055
|
+
type: Component,
|
|
2056
|
+
args: [{
|
|
2057
|
+
selector: "tx-export-csv",
|
|
2058
|
+
imports: [TxButton, TxTooltip],
|
|
2059
|
+
template: TEMPLATE,
|
|
2060
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2061
|
+
host: {
|
|
2062
|
+
class: "tx-export tx-export-csv",
|
|
2063
|
+
...HOST
|
|
2064
|
+
}
|
|
2065
|
+
}]
|
|
2066
|
+
}]
|
|
2067
|
+
});
|
|
2068
|
+
var TxExportExcel = class TxExportExcel extends TxExportButtonBase {
|
|
2069
|
+
resolvedFormat = () => "excel";
|
|
2070
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2071
|
+
minVersion: "12.0.0",
|
|
2072
|
+
version: "22.2.3",
|
|
2073
|
+
ngImport: i0,
|
|
2074
|
+
type: TxExportExcel,
|
|
2075
|
+
deps: null,
|
|
2076
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
2077
|
+
});
|
|
2078
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
2079
|
+
minVersion: "14.0.0",
|
|
2080
|
+
version: "22.2.3",
|
|
2081
|
+
type: TxExportExcel,
|
|
2082
|
+
isStandalone: true,
|
|
2083
|
+
selector: "tx-export-excel",
|
|
2084
|
+
host: {
|
|
2085
|
+
properties: {
|
|
2086
|
+
"class": "passThrough().root?.class",
|
|
2087
|
+
"style": "passThrough().root?.style",
|
|
2088
|
+
"attr.data-format": "resolvedFormat()"
|
|
2089
|
+
},
|
|
2090
|
+
classAttribute: "tx-export tx-export-excel"
|
|
2091
|
+
},
|
|
2092
|
+
usesInheritance: true,
|
|
2093
|
+
ngImport: i0,
|
|
2094
|
+
template: "\n <button\n txButton\n type=\"button\"\n [icon]=\"icon()\"\n [label]=\"label()\"\n [severity]=\"severity()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [loading]=\"busy()\"\n [disabled]=\"disabled()\"\n [unstyled]=\"unstyled()\"\n [txTooltip]=\"resolvedTooltip()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-busy]=\"busy() || null\"\n [class]=\"passThrough().button?.class\"\n [style]=\"passThrough().button?.style\"\n (click)=\"run(resolvedFormat())\"\n ></button>\n",
|
|
2095
|
+
isInline: true,
|
|
2096
|
+
dependencies: [{
|
|
2097
|
+
kind: "component",
|
|
2098
|
+
type: TxButton,
|
|
2099
|
+
selector: "button[txButton], a[txButton]",
|
|
2100
|
+
inputs: [
|
|
2101
|
+
"label",
|
|
2102
|
+
"severity",
|
|
2103
|
+
"size",
|
|
2104
|
+
"variant",
|
|
2105
|
+
"outlined",
|
|
2106
|
+
"text",
|
|
2107
|
+
"link",
|
|
2108
|
+
"rounded",
|
|
2109
|
+
"raised",
|
|
2110
|
+
"plain",
|
|
2111
|
+
"fluid",
|
|
2112
|
+
"disabled",
|
|
2113
|
+
"tabindex",
|
|
2114
|
+
"icon",
|
|
2115
|
+
"iconPos",
|
|
2116
|
+
"iconOnly",
|
|
2117
|
+
"loading",
|
|
2118
|
+
"loadingIcon",
|
|
2119
|
+
"badge",
|
|
2120
|
+
"badgeSeverity",
|
|
2121
|
+
"dt",
|
|
2122
|
+
"pt",
|
|
2123
|
+
"ptOptions",
|
|
2124
|
+
"unstyled"
|
|
2125
|
+
]
|
|
2126
|
+
}, {
|
|
2127
|
+
kind: "directive",
|
|
2128
|
+
type: TxTooltip,
|
|
2129
|
+
selector: "[txTooltip]",
|
|
2130
|
+
inputs: [
|
|
2131
|
+
"txTooltip",
|
|
2132
|
+
"tooltipPlacement",
|
|
2133
|
+
"tooltipEvent",
|
|
2134
|
+
"tooltipShowDelay",
|
|
2135
|
+
"tooltipHideDelay",
|
|
2136
|
+
"tooltipLife",
|
|
2137
|
+
"tooltipOffset",
|
|
2138
|
+
"tooltipArrow",
|
|
2139
|
+
"tooltipInteractive",
|
|
2140
|
+
"tooltipDisabled",
|
|
2141
|
+
"tooltipOverflowOnly",
|
|
2142
|
+
"tooltipMultiline",
|
|
2143
|
+
"tooltipContext",
|
|
2144
|
+
"tooltipClass",
|
|
2145
|
+
"tooltipDt",
|
|
2146
|
+
"tooltipPt",
|
|
2147
|
+
"tooltipPtOptions",
|
|
2148
|
+
"tooltipUnstyled"
|
|
2149
|
+
],
|
|
2150
|
+
outputs: ["tooltipShown", "tooltipHidden"],
|
|
2151
|
+
exportAs: ["txTooltip"]
|
|
2152
|
+
}],
|
|
2153
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2154
|
+
});
|
|
2155
|
+
};
|
|
2156
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2157
|
+
minVersion: "12.0.0",
|
|
2158
|
+
version: "22.2.3",
|
|
2159
|
+
ngImport: i0,
|
|
2160
|
+
type: TxExportExcel,
|
|
2161
|
+
decorators: [{
|
|
2162
|
+
type: Component,
|
|
2163
|
+
args: [{
|
|
2164
|
+
selector: "tx-export-excel",
|
|
2165
|
+
imports: [TxButton, TxTooltip],
|
|
2166
|
+
template: TEMPLATE,
|
|
2167
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2168
|
+
host: {
|
|
2169
|
+
class: "tx-export tx-export-excel",
|
|
2170
|
+
...HOST
|
|
2171
|
+
}
|
|
2172
|
+
}]
|
|
2173
|
+
}]
|
|
2174
|
+
});
|
|
2175
|
+
var TxExportWord = class TxExportWord extends TxExportButtonBase {
|
|
2176
|
+
resolvedFormat = () => "word";
|
|
2177
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2178
|
+
minVersion: "12.0.0",
|
|
2179
|
+
version: "22.2.3",
|
|
2180
|
+
ngImport: i0,
|
|
2181
|
+
type: TxExportWord,
|
|
2182
|
+
deps: null,
|
|
2183
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
2184
|
+
});
|
|
2185
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
2186
|
+
minVersion: "14.0.0",
|
|
2187
|
+
version: "22.2.3",
|
|
2188
|
+
type: TxExportWord,
|
|
2189
|
+
isStandalone: true,
|
|
2190
|
+
selector: "tx-export-word",
|
|
2191
|
+
host: {
|
|
2192
|
+
properties: {
|
|
2193
|
+
"class": "passThrough().root?.class",
|
|
2194
|
+
"style": "passThrough().root?.style",
|
|
2195
|
+
"attr.data-format": "resolvedFormat()"
|
|
2196
|
+
},
|
|
2197
|
+
classAttribute: "tx-export tx-export-word"
|
|
2198
|
+
},
|
|
2199
|
+
usesInheritance: true,
|
|
2200
|
+
ngImport: i0,
|
|
2201
|
+
template: "\n <button\n txButton\n type=\"button\"\n [icon]=\"icon()\"\n [label]=\"label()\"\n [severity]=\"severity()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [loading]=\"busy()\"\n [disabled]=\"disabled()\"\n [unstyled]=\"unstyled()\"\n [txTooltip]=\"resolvedTooltip()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-busy]=\"busy() || null\"\n [class]=\"passThrough().button?.class\"\n [style]=\"passThrough().button?.style\"\n (click)=\"run(resolvedFormat())\"\n ></button>\n",
|
|
2202
|
+
isInline: true,
|
|
2203
|
+
dependencies: [{
|
|
2204
|
+
kind: "component",
|
|
2205
|
+
type: TxButton,
|
|
2206
|
+
selector: "button[txButton], a[txButton]",
|
|
2207
|
+
inputs: [
|
|
2208
|
+
"label",
|
|
2209
|
+
"severity",
|
|
2210
|
+
"size",
|
|
2211
|
+
"variant",
|
|
2212
|
+
"outlined",
|
|
2213
|
+
"text",
|
|
2214
|
+
"link",
|
|
2215
|
+
"rounded",
|
|
2216
|
+
"raised",
|
|
2217
|
+
"plain",
|
|
2218
|
+
"fluid",
|
|
2219
|
+
"disabled",
|
|
2220
|
+
"tabindex",
|
|
2221
|
+
"icon",
|
|
2222
|
+
"iconPos",
|
|
2223
|
+
"iconOnly",
|
|
2224
|
+
"loading",
|
|
2225
|
+
"loadingIcon",
|
|
2226
|
+
"badge",
|
|
2227
|
+
"badgeSeverity",
|
|
2228
|
+
"dt",
|
|
2229
|
+
"pt",
|
|
2230
|
+
"ptOptions",
|
|
2231
|
+
"unstyled"
|
|
2232
|
+
]
|
|
2233
|
+
}, {
|
|
2234
|
+
kind: "directive",
|
|
2235
|
+
type: TxTooltip,
|
|
2236
|
+
selector: "[txTooltip]",
|
|
2237
|
+
inputs: [
|
|
2238
|
+
"txTooltip",
|
|
2239
|
+
"tooltipPlacement",
|
|
2240
|
+
"tooltipEvent",
|
|
2241
|
+
"tooltipShowDelay",
|
|
2242
|
+
"tooltipHideDelay",
|
|
2243
|
+
"tooltipLife",
|
|
2244
|
+
"tooltipOffset",
|
|
2245
|
+
"tooltipArrow",
|
|
2246
|
+
"tooltipInteractive",
|
|
2247
|
+
"tooltipDisabled",
|
|
2248
|
+
"tooltipOverflowOnly",
|
|
2249
|
+
"tooltipMultiline",
|
|
2250
|
+
"tooltipContext",
|
|
2251
|
+
"tooltipClass",
|
|
2252
|
+
"tooltipDt",
|
|
2253
|
+
"tooltipPt",
|
|
2254
|
+
"tooltipPtOptions",
|
|
2255
|
+
"tooltipUnstyled"
|
|
2256
|
+
],
|
|
2257
|
+
outputs: ["tooltipShown", "tooltipHidden"],
|
|
2258
|
+
exportAs: ["txTooltip"]
|
|
2259
|
+
}],
|
|
2260
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2261
|
+
});
|
|
2262
|
+
};
|
|
2263
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2264
|
+
minVersion: "12.0.0",
|
|
2265
|
+
version: "22.2.3",
|
|
2266
|
+
ngImport: i0,
|
|
2267
|
+
type: TxExportWord,
|
|
2268
|
+
decorators: [{
|
|
2269
|
+
type: Component,
|
|
2270
|
+
args: [{
|
|
2271
|
+
selector: "tx-export-word",
|
|
2272
|
+
imports: [TxButton, TxTooltip],
|
|
2273
|
+
template: TEMPLATE,
|
|
2274
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2275
|
+
host: {
|
|
2276
|
+
class: "tx-export tx-export-word",
|
|
2277
|
+
...HOST
|
|
2278
|
+
}
|
|
2279
|
+
}]
|
|
2280
|
+
}]
|
|
2281
|
+
});
|
|
2282
|
+
var TxExportPdf = class TxExportPdf extends TxExportButtonBase {
|
|
2283
|
+
resolvedFormat = () => "pdf";
|
|
2284
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2285
|
+
minVersion: "12.0.0",
|
|
2286
|
+
version: "22.2.3",
|
|
2287
|
+
ngImport: i0,
|
|
2288
|
+
type: TxExportPdf,
|
|
2289
|
+
deps: null,
|
|
2290
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
2291
|
+
});
|
|
2292
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
2293
|
+
minVersion: "14.0.0",
|
|
2294
|
+
version: "22.2.3",
|
|
2295
|
+
type: TxExportPdf,
|
|
2296
|
+
isStandalone: true,
|
|
2297
|
+
selector: "tx-export-pdf",
|
|
2298
|
+
host: {
|
|
2299
|
+
properties: {
|
|
2300
|
+
"class": "passThrough().root?.class",
|
|
2301
|
+
"style": "passThrough().root?.style",
|
|
2302
|
+
"attr.data-format": "resolvedFormat()"
|
|
2303
|
+
},
|
|
2304
|
+
classAttribute: "tx-export tx-export-pdf"
|
|
2305
|
+
},
|
|
2306
|
+
usesInheritance: true,
|
|
2307
|
+
ngImport: i0,
|
|
2308
|
+
template: "\n <button\n txButton\n type=\"button\"\n [icon]=\"icon()\"\n [label]=\"label()\"\n [severity]=\"severity()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [loading]=\"busy()\"\n [disabled]=\"disabled()\"\n [unstyled]=\"unstyled()\"\n [txTooltip]=\"resolvedTooltip()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-busy]=\"busy() || null\"\n [class]=\"passThrough().button?.class\"\n [style]=\"passThrough().button?.style\"\n (click)=\"run(resolvedFormat())\"\n ></button>\n",
|
|
2309
|
+
isInline: true,
|
|
2310
|
+
dependencies: [{
|
|
2311
|
+
kind: "component",
|
|
2312
|
+
type: TxButton,
|
|
2313
|
+
selector: "button[txButton], a[txButton]",
|
|
2314
|
+
inputs: [
|
|
2315
|
+
"label",
|
|
2316
|
+
"severity",
|
|
2317
|
+
"size",
|
|
2318
|
+
"variant",
|
|
2319
|
+
"outlined",
|
|
2320
|
+
"text",
|
|
2321
|
+
"link",
|
|
2322
|
+
"rounded",
|
|
2323
|
+
"raised",
|
|
2324
|
+
"plain",
|
|
2325
|
+
"fluid",
|
|
2326
|
+
"disabled",
|
|
2327
|
+
"tabindex",
|
|
2328
|
+
"icon",
|
|
2329
|
+
"iconPos",
|
|
2330
|
+
"iconOnly",
|
|
2331
|
+
"loading",
|
|
2332
|
+
"loadingIcon",
|
|
2333
|
+
"badge",
|
|
2334
|
+
"badgeSeverity",
|
|
2335
|
+
"dt",
|
|
2336
|
+
"pt",
|
|
2337
|
+
"ptOptions",
|
|
2338
|
+
"unstyled"
|
|
2339
|
+
]
|
|
2340
|
+
}, {
|
|
2341
|
+
kind: "directive",
|
|
2342
|
+
type: TxTooltip,
|
|
2343
|
+
selector: "[txTooltip]",
|
|
2344
|
+
inputs: [
|
|
2345
|
+
"txTooltip",
|
|
2346
|
+
"tooltipPlacement",
|
|
2347
|
+
"tooltipEvent",
|
|
2348
|
+
"tooltipShowDelay",
|
|
2349
|
+
"tooltipHideDelay",
|
|
2350
|
+
"tooltipLife",
|
|
2351
|
+
"tooltipOffset",
|
|
2352
|
+
"tooltipArrow",
|
|
2353
|
+
"tooltipInteractive",
|
|
2354
|
+
"tooltipDisabled",
|
|
2355
|
+
"tooltipOverflowOnly",
|
|
2356
|
+
"tooltipMultiline",
|
|
2357
|
+
"tooltipContext",
|
|
2358
|
+
"tooltipClass",
|
|
2359
|
+
"tooltipDt",
|
|
2360
|
+
"tooltipPt",
|
|
2361
|
+
"tooltipPtOptions",
|
|
2362
|
+
"tooltipUnstyled"
|
|
2363
|
+
],
|
|
2364
|
+
outputs: ["tooltipShown", "tooltipHidden"],
|
|
2365
|
+
exportAs: ["txTooltip"]
|
|
2366
|
+
}],
|
|
2367
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2368
|
+
});
|
|
2369
|
+
};
|
|
2370
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2371
|
+
minVersion: "12.0.0",
|
|
2372
|
+
version: "22.2.3",
|
|
2373
|
+
ngImport: i0,
|
|
2374
|
+
type: TxExportPdf,
|
|
2375
|
+
decorators: [{
|
|
2376
|
+
type: Component,
|
|
2377
|
+
args: [{
|
|
2378
|
+
selector: "tx-export-pdf",
|
|
2379
|
+
imports: [TxButton, TxTooltip],
|
|
2380
|
+
template: TEMPLATE,
|
|
2381
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2382
|
+
host: {
|
|
2383
|
+
class: "tx-export tx-export-pdf",
|
|
2384
|
+
...HOST
|
|
2385
|
+
}
|
|
2386
|
+
}]
|
|
2387
|
+
}]
|
|
2388
|
+
});
|
|
2389
|
+
const FORMAT_NAMES = {
|
|
2390
|
+
csv: "CSV",
|
|
2391
|
+
excel: "Excel (.xlsx)",
|
|
2392
|
+
word: "Word (.docx)",
|
|
2393
|
+
pdf: "PDF",
|
|
2394
|
+
json: "JSON",
|
|
2395
|
+
html: "HTML",
|
|
2396
|
+
markdown: "Markdown"
|
|
2397
|
+
};
|
|
2398
|
+
const TX_EXPORT_FORMATS = [
|
|
2399
|
+
"excel",
|
|
2400
|
+
"csv",
|
|
2401
|
+
"word",
|
|
2402
|
+
"pdf",
|
|
2403
|
+
"json",
|
|
2404
|
+
"html",
|
|
2405
|
+
"markdown",
|
|
2406
|
+
"copy",
|
|
2407
|
+
"print"
|
|
2408
|
+
];
|
|
2409
|
+
var TxExport = class TxExport extends TxExportAction {
|
|
2410
|
+
formats = input(TX_EXPORT_FORMATS, ...ngDevMode ? [{ debugName: "formats" }] : /* istanbul ignore next */ []);
|
|
2411
|
+
pt = input(void 0, ...ngDevMode ? [{ debugName: "pt" }] : /* istanbul ignore next */ []);
|
|
2412
|
+
passThrough = injectPassThrough("export", this, this.pt, this.ptOptions);
|
|
2413
|
+
mainFormat = computed(() => this.formats()[0] ?? "excel", ...ngDevMode ? [{ debugName: "mainFormat" }] : /* istanbul ignore next */ []);
|
|
2414
|
+
mainIcon = computed(() => this.copied() && this.mainFormat() === "copy" ? "check" : "download", ...ngDevMode ? [{ debugName: "mainIcon" }] : /* istanbul ignore next */ []);
|
|
2415
|
+
resolvedLabel = computed(() => this.label() ?? this.translations().export, ...ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []);
|
|
2416
|
+
items = computed(() => {
|
|
2417
|
+
const translations = this.translations();
|
|
2418
|
+
return this.formats().map((format) => ({
|
|
2419
|
+
id: format,
|
|
2420
|
+
data: format,
|
|
2421
|
+
icon: TX_EXPORT_ICONS[format],
|
|
2422
|
+
label: format === "copy" ? translations.exportCopy : format === "print" ? translations.exportPrint : FORMAT_NAMES[format] ?? format,
|
|
2423
|
+
command: () => void this.run(format)
|
|
2424
|
+
}));
|
|
2425
|
+
}, ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
|
|
2426
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
2427
|
+
minVersion: "12.0.0",
|
|
2428
|
+
version: "22.2.3",
|
|
2429
|
+
ngImport: i0,
|
|
2430
|
+
type: TxExport,
|
|
2431
|
+
deps: null,
|
|
2432
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
2433
|
+
});
|
|
2434
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
2435
|
+
minVersion: "17.1.0",
|
|
2436
|
+
version: "22.2.3",
|
|
2437
|
+
type: TxExport,
|
|
2438
|
+
isStandalone: true,
|
|
2439
|
+
selector: "tx-export",
|
|
2440
|
+
inputs: {
|
|
2441
|
+
formats: {
|
|
2442
|
+
classPropertyName: "formats",
|
|
2443
|
+
publicName: "formats",
|
|
2444
|
+
isSignal: true,
|
|
2445
|
+
isRequired: false,
|
|
2446
|
+
transformFunction: null
|
|
2447
|
+
},
|
|
2448
|
+
pt: {
|
|
2449
|
+
classPropertyName: "pt",
|
|
2450
|
+
publicName: "pt",
|
|
2451
|
+
isSignal: true,
|
|
2452
|
+
isRequired: false,
|
|
2453
|
+
transformFunction: null
|
|
2454
|
+
}
|
|
2455
|
+
},
|
|
2456
|
+
host: {
|
|
2457
|
+
properties: {
|
|
2458
|
+
"class": "passThrough().root?.class",
|
|
2459
|
+
"style": "passThrough().root?.style"
|
|
2460
|
+
},
|
|
2461
|
+
classAttribute: "tx-export tx-export-menu"
|
|
2462
|
+
},
|
|
2463
|
+
usesInheritance: true,
|
|
2464
|
+
ngImport: i0,
|
|
2465
|
+
template: `
|
|
2466
|
+
<tx-split-button
|
|
2467
|
+
[label]="resolvedLabel()"
|
|
2468
|
+
[icon]="mainIcon()"
|
|
2469
|
+
[model]="items()"
|
|
2470
|
+
[severity]="severity()"
|
|
2471
|
+
[size]="size()"
|
|
2472
|
+
[outlined]="variant() === 'outlined'"
|
|
2473
|
+
[text]="variant() === 'text'"
|
|
2474
|
+
[loading]="busy()"
|
|
2475
|
+
[disabled]="disabled()"
|
|
2476
|
+
[unstyled]="unstyled()"
|
|
2477
|
+
[menuAriaLabel]="translations().exportFormats"
|
|
2478
|
+
[class]="passThrough().button?.class"
|
|
2479
|
+
[style]="passThrough().button?.style"
|
|
2480
|
+
(clicked)="run(mainFormat())"
|
|
2481
|
+
/>
|
|
2482
|
+
`,
|
|
2483
|
+
isInline: true,
|
|
2484
|
+
dependencies: [{
|
|
2485
|
+
kind: "component",
|
|
2486
|
+
type: TxSplitButton,
|
|
2487
|
+
selector: "tx-split-button",
|
|
2488
|
+
inputs: [
|
|
2489
|
+
"label",
|
|
2490
|
+
"icon",
|
|
2491
|
+
"model",
|
|
2492
|
+
"severity",
|
|
2493
|
+
"size",
|
|
2494
|
+
"outlined",
|
|
2495
|
+
"text",
|
|
2496
|
+
"raised",
|
|
2497
|
+
"rounded",
|
|
2498
|
+
"disabled",
|
|
2499
|
+
"menuDisabled",
|
|
2500
|
+
"loading",
|
|
2501
|
+
"menuAriaLabel",
|
|
2502
|
+
"dt",
|
|
2503
|
+
"pt",
|
|
2504
|
+
"ptOptions",
|
|
2505
|
+
"unstyled"
|
|
2506
|
+
],
|
|
2507
|
+
outputs: [
|
|
2508
|
+
"clicked",
|
|
2509
|
+
"itemSelected",
|
|
2510
|
+
"menuOpened",
|
|
2511
|
+
"menuClosed"
|
|
2512
|
+
]
|
|
2513
|
+
}],
|
|
2514
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
2515
|
+
});
|
|
2516
|
+
};
|
|
2517
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
2518
|
+
minVersion: "12.0.0",
|
|
2519
|
+
version: "22.2.3",
|
|
2520
|
+
ngImport: i0,
|
|
2521
|
+
type: TxExport,
|
|
2522
|
+
decorators: [{
|
|
2523
|
+
type: Component,
|
|
2524
|
+
args: [{
|
|
2525
|
+
selector: "tx-export",
|
|
2526
|
+
imports: [TxSplitButton],
|
|
2527
|
+
template: `
|
|
2528
|
+
<tx-split-button
|
|
2529
|
+
[label]="resolvedLabel()"
|
|
2530
|
+
[icon]="mainIcon()"
|
|
2531
|
+
[model]="items()"
|
|
2532
|
+
[severity]="severity()"
|
|
2533
|
+
[size]="size()"
|
|
2534
|
+
[outlined]="variant() === 'outlined'"
|
|
2535
|
+
[text]="variant() === 'text'"
|
|
2536
|
+
[loading]="busy()"
|
|
2537
|
+
[disabled]="disabled()"
|
|
2538
|
+
[unstyled]="unstyled()"
|
|
2539
|
+
[menuAriaLabel]="translations().exportFormats"
|
|
2540
|
+
[class]="passThrough().button?.class"
|
|
2541
|
+
[style]="passThrough().button?.style"
|
|
2542
|
+
(clicked)="run(mainFormat())"
|
|
2543
|
+
/>
|
|
2544
|
+
`,
|
|
2545
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2546
|
+
host: {
|
|
2547
|
+
class: "tx-export tx-export-menu",
|
|
2548
|
+
"[class]": "passThrough().root?.class",
|
|
2549
|
+
"[style]": "passThrough().root?.style"
|
|
2550
|
+
}
|
|
2551
|
+
}]
|
|
2552
|
+
}],
|
|
2553
|
+
propDecorators: {
|
|
2554
|
+
formats: [{
|
|
2555
|
+
type: i0.Input,
|
|
2556
|
+
args: [{
|
|
2557
|
+
isSignal: true,
|
|
2558
|
+
alias: "formats",
|
|
2559
|
+
required: false
|
|
2560
|
+
}]
|
|
2561
|
+
}],
|
|
2562
|
+
pt: [{
|
|
2563
|
+
type: i0.Input,
|
|
2564
|
+
args: [{
|
|
2565
|
+
isSignal: true,
|
|
2566
|
+
alias: "pt",
|
|
2567
|
+
required: false
|
|
2568
|
+
}]
|
|
2569
|
+
}]
|
|
2570
|
+
}
|
|
2571
|
+
});
|
|
2572
|
+
export { TX_EXPORT_EXTENSIONS, TX_EXPORT_FORMATS, TX_EXPORT_ICONS, TX_EXPORT_OPTIONS, TxExport, TxExportAction, TxExportButton, TxExportCsv, TxExportExcel, TxExportPdf, TxExportService, TxExportWord, buildExportTable, cellText, columnName, crc32, csvCell, docxDocument, downloadBlob, downloadCsv, escapeXml, excelSerial, excelWidths, exportMatrix, fieldsFor, hexColor, htmlTable, inferType, loadDefaultExportFont, localIso, matrixToCsv, mergeExportOptions, parseTrueType, provideTxExport, readExportField, safeExportText, sheetName, toDate, withExtension, wrapText, writeCsv, writeDocx, writeHtml, writeJson, writeMarkdown, writePdf, writeTsv, writeXlsx, xlsxParts, zip };
|
|
2573
|
+
|
|
2574
|
+
//# sourceMappingURL=tectra-ng-ui-export.mjs.map
|