report-studio 1.2.1 → 1.2.2

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.
@@ -1,1727 +0,0 @@
1
- //#region src/engine/tables.js
2
- function e(e) {
3
- let t = [];
4
- for (let n of Array.isArray(e?.bands) ? e.bands : []) for (let e of Array.isArray(n?.items) ? n.items : []) e?.type === "table" && t.push(e);
5
- return t;
6
- }
7
- function t(e, t) {
8
- return (typeof e?.dataset == "string" && e.dataset !== "" ? e.dataset : null) ?? t?.dataset ?? null;
9
- }
10
- function n(e) {
11
- return typeof e?.groupBy == "string" && e.groupBy !== "";
12
- }
13
- function r(t) {
14
- let r = e(t), i = r.find(n);
15
- return i ? {
16
- table: i,
17
- by: i.groupBy
18
- } : t?.groupBy != null && r.length > 0 ? {
19
- table: r[0],
20
- by: t.groupBy
21
- } : null;
22
- }
23
- //#endregion
24
- //#region src/engine/text-metrics.js
25
- var i = 1.3, a = /* @__PURE__ */ new Map(), o = 1e4, s, c = !1;
26
- function l() {
27
- if (c) return s;
28
- c = !0;
29
- try {
30
- s = typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1).getContext("2d") : typeof document < "u" ? document.createElement("canvas").getContext("2d") : null;
31
- } catch {
32
- s = null;
33
- }
34
- return s;
35
- }
36
- function u(e = {}) {
37
- return `${e.fontStyle || "normal"} ${e.fontWeight || "normal"} ${e.fontSize ?? 12}px ${e.fontFamily || "Helvetica, Arial, sans-serif"}`;
38
- }
39
- function d(e, t) {
40
- let n = String(e ?? "");
41
- if (n === "") return 0;
42
- let r = u(t), i = `${r}\u0000${n}`, s = a.get(i);
43
- if (s !== void 0) return s;
44
- let c = l(), d;
45
- return c ? (c.font = r, d = c.measureText(n).width) : d = f(n, t), a.size >= o && a.clear(), a.set(i, d), d;
46
- }
47
- function f(e, t = {}) {
48
- let n = t.fontSize ?? 12, r = String(t.fontWeight) === "bold" || Number(t.fontWeight) >= 600, i = /mono|courier|consolas/i.test(t.fontFamily || ""), a = 0;
49
- for (let t of e) {
50
- if (i) {
51
- a += .6;
52
- continue;
53
- }
54
- t === " " ? a += .26 : /[iljI.,:;'`|!\[\]()]/.test(t) ? a += .28 : /[ftr]/.test(t) ? a += .34 : /[A-Z]/.test(t) ? a += .68 : /[mwMW@]/.test(t) ? a += .88 : /[0-9]/.test(t) ? a += .56 : a += .52;
55
- }
56
- return a * n * (r ? 1.06 : 1);
57
- }
58
- function p(e, t, n) {
59
- let r = String(e ?? "").split("\n");
60
- if (!(t > 0)) return r;
61
- let i = [];
62
- for (let e of r) {
63
- let r = e.split(/(\s+)/).filter((e) => e !== "");
64
- if (r.length === 0) {
65
- i.push("");
66
- continue;
67
- }
68
- let a = "";
69
- for (let e of r) {
70
- let r = a + e;
71
- for (a !== "" && d(r, n) > t ? (i.push(a.trimEnd()), a = e.trimStart()) : a = r; d(a, n) > t && a.trim().length > 1;) {
72
- let e = a.length;
73
- for (; e > 1 && d(a.slice(0, e), n) > t;) e--;
74
- if (e >= a.length) break;
75
- i.push(a.slice(0, e)), a = a.slice(e);
76
- }
77
- }
78
- i.push(a.trimEnd());
79
- }
80
- return i;
81
- }
82
- function m(e, t, n) {
83
- let r = Math.ceil((n?.fontSize ?? 12) * i);
84
- return p(e, t, n).length * r;
85
- }
86
- function h(e) {
87
- return {
88
- fontSize: e.style?.fontSize ?? 12,
89
- fontFamily: e.style?.fontFamily,
90
- fontWeight: "normal",
91
- fontStyle: "normal"
92
- };
93
- }
94
- function g(e) {
95
- let t = (e.columns ?? []).map((e) => e.width ?? 0), n = t.reduce((e, t) => e + t, 0), r = e.w ?? n, i = n > 0 && r > n ? r / n : 1;
96
- return t.map((e) => e * i);
97
- }
98
- function _(e) {
99
- if (e.style?.borderStyle === "none") return 0;
100
- let t = Number(e.style?.borderWidth);
101
- return Number.isFinite(t) && t > 0 ? t : 1;
102
- }
103
- function v(e) {
104
- let t = g(e), n = _(e), r = t.length - 1;
105
- return t.map((e, t) => e - 16 - n * (t === r ? 2 : 1));
106
- }
107
- function y(e, t) {
108
- let n = e.rowHeight ?? 0, r = t ?? [];
109
- if (e.wrap === !1) return r.map(() => n);
110
- let i = h(e), a = e.columns ?? [], o = v(e);
111
- return r.map((e) => {
112
- let t = n;
113
- for (let [n, r] of a.entries()) {
114
- let a = o[n];
115
- if (!(a > 0)) continue;
116
- let s = e?.[r.field];
117
- s == null || s === "" || (t = Math.max(t, m(String(s), a, i)));
118
- }
119
- return t;
120
- });
121
- }
122
- function b(e) {
123
- if (!e.showHeader) return 0;
124
- let t = e.headerHeight ?? e.rowHeight ?? 0;
125
- if (e.wrap === !1) return t;
126
- let n = (e.columns ?? []).map((e, t) => ({
127
- ...e,
128
- field: `label${t}`
129
- })), r = Object.fromEntries((e.columns ?? []).map((e, t) => [`label${t}`, e.label])), [i] = y({
130
- ...e,
131
- rowHeight: t,
132
- columns: n
133
- }, [r]);
134
- return i ?? t;
135
- }
136
- function x(e) {
137
- if (e.type !== "table") return e.h ?? 0;
138
- let t = e.rowHeight ?? 0;
139
- return (e.showHeader ? e.headerHeight ?? t : 0) + 3 * t;
140
- }
141
- function S(e) {
142
- let t = structuredClone(e);
143
- for (let e of t.bands) e.items && C(e, t);
144
- return t;
145
- }
146
- function C(e, t) {
147
- let n = 0;
148
- for (let r of e.items) r.measuredHeight = T(r, t), n = Math.max(n, (r.y ?? 0) + r.measuredHeight);
149
- return e.contentHeight = n, e.measuredHeight = w(e) ? n : Math.max(e.height ?? 0, n), e;
150
- }
151
- function w(e) {
152
- return e.items.some((e) => e.type === "table");
153
- }
154
- function T(e, t) {
155
- switch (e.type) {
156
- case "text": return E(e);
157
- case "table": return O(e, t);
158
- case "line": return D(e);
159
- case "box":
160
- case "image": return e.h ?? 0;
161
- default: return console.warn(`Unknown item type "${e.type}" on item "${e.id}"; treating as zero height.`), 0;
162
- }
163
- }
164
- function E(e) {
165
- let t = e.h ?? 0, n = m(e.text ?? e.value ?? "", e.w ?? 0, e.style);
166
- return Math.max(t, n);
167
- }
168
- function D(e) {
169
- let t = e.h ?? 0;
170
- return e.orientation === "vertical" ? t : Math.max(t, e.style?.thickness ?? 0);
171
- }
172
- function O(e, t) {
173
- let n = b(e);
174
- if (e.headerMeasured = n, !Array.isArray(e.groups)) return e.rowHeights = y(e, e.row), n + k(e.rowHeights);
175
- let r = e.groups ?? [], i = A(t, "groupHeader"), a = A(t, "groupFooter"), o = 0;
176
- for (let t of r) t.rowHeights = y(e, t.rows), o += n + i + k(t.rowHeights) + a;
177
- return o;
178
- }
179
- function k(e) {
180
- return (e ?? []).reduce((e, t) => e + t, 0);
181
- }
182
- function A(e, t) {
183
- let n = e.bands.find((e) => e.type === t);
184
- if (!n?.items) return 0;
185
- let r = 0;
186
- for (let e of n.items) {
187
- let t = e.type === "text" ? E(e) : 0;
188
- r = Math.max(r, (e.y ?? 0) + t);
189
- }
190
- return Math.max(n.height ?? 0, r);
191
- }
192
- //#endregion
193
- //#region src/engine/validate.js
194
- var ee = [
195
- "reportHeader",
196
- "pageHeader",
197
- "groupHeader",
198
- "detail",
199
- "groupFooter",
200
- "reportFooter",
201
- "pageFooter"
202
- ], j = [
203
- "text",
204
- "table",
205
- "line",
206
- "box",
207
- "image"
208
- ], te = ["horizontal", "vertical"], M = [
209
- "solid",
210
- "dashed",
211
- "dotted",
212
- "double"
213
- ], N = [...M, "none"], P = [
214
- "contain",
215
- "cover",
216
- "fill"
217
- ], F = class extends Error {
218
- constructor(e, t = []) {
219
- super(t.length ? `${e}\n - ${t.join("\n - ")}` : e), this.name = "ReportError", this.issues = t;
220
- }
221
- };
222
- function I(e) {
223
- let t = [];
224
- if (typeof e != "object" || !e || Array.isArray(e)) return ["layout must be an object"];
225
- if (L(e.page, t), !Array.isArray(e.bands)) return t.push("layout.bands must be an array"), t;
226
- e.bands.length === 0 && t.push("layout.bands is empty - there is nothing to render"), e.groupBy != null && typeof e.groupBy != "string" && t.push("layout.groupBy must be a field name or null");
227
- let n = /* @__PURE__ */ new Set();
228
- return e.bands.forEach((e, r) => {
229
- let i = `bands[${r}]`;
230
- if (typeof e != "object" || !e) {
231
- t.push(`${i} must be an object`);
232
- return;
233
- }
234
- if (ee.includes(e.type) ? n.has(e.type) ? t.push(`${i}.type "${e.type}" appears more than once; the engine places one band of each type`) : n.add(e.type) : t.push(`${i}.type "${e.type}" is not one of: ${ee.join(", ")}`), !Array.isArray(e.items)) {
235
- t.push(`${i}.items must be an array`);
236
- return;
237
- }
238
- e.items.forEach((e, n) => R(e, `${i}.items[${n}]`, t));
239
- }), e.groupBy != null && !n.has("groupHeader") && !n.has("groupFooter") && t.push("layout.groupBy is set but there is no groupHeader or groupFooter band to show it"), ne(e, e.bands, t), t;
240
- }
241
- function ne(t, r, i) {
242
- let a = e(t);
243
- for (let e of a) e.groupBy != null && typeof e.groupBy != "string" && i.push(`table "${e.id}".groupBy must be a field name or null`), e.dataset != null && typeof e.dataset != "string" && i.push(`table "${e.id}".dataset must be a dataset name or null`);
244
- let o = a.filter(n);
245
- o.length > 1 && i.push(`${o.length} tables are grouped (${o.map((e) => `"${e.id}"`).join(", ")}); a report groups one, because groupHeader and groupFooter are shared`), o.length > 0 && t.groupBy == null && !r.some((e) => e?.type === "groupHeader" || e?.type === "groupFooter") && i.push(`table "${o[0].id}" is grouped by "${o[0].groupBy}" but there is no groupHeader or groupFooter band to show it`);
246
- for (let e of r) {
247
- if (!Array.isArray(e?.items)) continue;
248
- let t = e.items.filter((e) => e?.type === "table").map((e) => ({
249
- item: e,
250
- top: Number(e.y) || 0,
251
- bottom: (Number(e.y) || 0) + x(e)
252
- })).sort((e, t) => e.top - t.top);
253
- for (let n = 1; n < t.length; n++) {
254
- let r = t[n - 1], a = t[n];
255
- a.top < r.bottom && i.push(`tables "${r.item.id}" and "${a.item.id}" overlap in the ${e.type} band; move "${a.item.id}" to y ${Math.ceil(r.bottom)} or lower - tables are stacked, one under another, not placed side by side`);
256
- }
257
- }
258
- }
259
- function L(e, t) {
260
- if (typeof e != "object" || !e) {
261
- t.push("layout.page must be an object with width, height and margin");
262
- return;
263
- }
264
- for (let n of ["width", "height"]) typeof e[n] == "number" && e[n] > 0 || t.push(`layout.page.${n} must be a positive number`);
265
- if (e.margin == null || typeof e.margin != "object") {
266
- t.push("layout.page.margin must be an object with top, right, bottom and left");
267
- return;
268
- }
269
- for (let n of [
270
- "top",
271
- "right",
272
- "bottom",
273
- "left"
274
- ]) typeof e.margin[n] == "number" && e.margin[n] >= 0 || t.push(`layout.page.margin.${n} must be a number of pixels`);
275
- let n = e.height - (e.margin.top + e.margin.bottom);
276
- n <= 0 && t.push(`layout.page margins leave no printable height (${n}px)`);
277
- }
278
- function R(e, t, n) {
279
- if (typeof e != "object" || !e) {
280
- n.push(`${t} must be an object`);
281
- return;
282
- }
283
- if (!j.includes(e.type)) {
284
- n.push(`${t}.type "${e.type}" is not one of: ${j.join(", ")}`);
285
- return;
286
- }
287
- if ((typeof e.id != "string" || e.id === "") && n.push(`${t}.id must be a non-empty string`), e.type === "text") {
288
- typeof e.value != "string" && n.push(`${t}.value must be a string`);
289
- return;
290
- }
291
- if (e.type === "line") {
292
- V(e, t, n);
293
- return;
294
- }
295
- if (e.type === "box") {
296
- z(e, t, n);
297
- return;
298
- }
299
- if (e.type === "image") {
300
- B(e, t, n);
301
- return;
302
- }
303
- if (typeof e.rowHeight == "number" && e.rowHeight > 0 || n.push(`${t}.rowHeight must be a positive number`), e.style?.borderStyle != null && !N.includes(e.style.borderStyle) && n.push(`${t}.style.borderStyle "${e.style.borderStyle}" is not one of: ` + N.join(", ")), e.style?.borderWidth != null && !(typeof e.style.borderWidth == "number" && e.style.borderWidth > 0) && n.push(`${t}.style.borderWidth must be a positive number of pixels`), !Array.isArray(e.columns) || e.columns.length === 0) {
304
- n.push(`${t}.columns must be a non-empty array`);
305
- return;
306
- }
307
- e.columns.forEach((e, r) => {
308
- (e == null || typeof e.field != "string" || e.field === "") && n.push(`${t}.columns[${r}].field must be a non-empty string`);
309
- });
310
- }
311
- function z(e, t, n) {
312
- let r = e.style;
313
- if (r != null) {
314
- if (typeof r != "object" || Array.isArray(r)) {
315
- n.push(`${t}.style must be an object`);
316
- return;
317
- }
318
- r.borderStyle != null && !N.includes(r.borderStyle) && n.push(`${t}.style.borderStyle "${r.borderStyle}" is not one of: ` + N.join(", "));
319
- for (let e of ["borderWidth", "radius"]) {
320
- let i = r[e], a = e === "radius" ? 0 : 1;
321
- i != null && !(typeof i == "number" && i >= a) && n.push(`${t}.style.${e} must be a number of pixels` + (a ? " greater than zero" : " of zero or more"));
322
- }
323
- }
324
- }
325
- function B(e, t, n) {
326
- e.src != null && typeof e.src != "string" && n.push(`${t}.src must be a string - a URL or a data: URI`), e.field != null && typeof e.field != "string" && n.push(`${t}.field must be a data path such as "company.logo"`), e.fit != null && !P.includes(e.fit) && n.push(`${t}.fit "${e.fit}" is not one of: ${P.join(", ")}`), e.alt != null && typeof e.alt != "string" && n.push(`${t}.alt must be a string`);
327
- }
328
- function V(e, t, n) {
329
- e.orientation != null && !te.includes(e.orientation) && n.push(`${t}.orientation "${e.orientation}" is not one of: ` + te.join(", "));
330
- let r = e.style;
331
- if (r != null) {
332
- if (typeof r != "object" || Array.isArray(r)) {
333
- n.push(`${t}.style must be an object`);
334
- return;
335
- }
336
- r.thickness != null && !(typeof r.thickness == "number" && r.thickness > 0) && n.push(`${t}.style.thickness must be a positive number of pixels`), r.lineStyle != null && !M.includes(r.lineStyle) && n.push(`${t}.style.lineStyle "${r.lineStyle}" is not one of: ` + M.join(", "));
337
- }
338
- }
339
- function re(e, t) {
340
- let n = I(e);
341
- if (n.length) throw new F(`${t}: the layout file is not usable`, n);
342
- }
343
- function ie(e, t) {
344
- if (typeof e != "object" || !e || Array.isArray(e)) throw new F(`${t}: data must be an object keyed by dataset name`);
345
- }
346
- //#endregion
347
- //#region src/engine/resolve.js
348
- var H = /\{([^{}]+)\}/g, U = /^\w+\(.*\)$/, W = ["page", "totalPages"], ae = ["groupHeader", "groupFooter"], oe = H;
349
- function se(e) {
350
- return U.test(e) || W.includes(e) || e === "today";
351
- }
352
- function ce(e) {
353
- return ae.includes(e);
354
- }
355
- function le(e, t) {
356
- re(e, "resolve"), ie(t, "resolve");
357
- let n = structuredClone(e);
358
- for (let e of n.bands) {
359
- let n = ae.includes(e.type);
360
- for (let r of e.items) r.type == "text" && (r.text = de(r, t, n)), r.type == "image" && (r.resolvedSrc = ue(r, t));
361
- }
362
- return n;
363
- }
364
- function ue(e, t) {
365
- let n = typeof e.field == "string" ? e.field.trim() : "";
366
- if (n) {
367
- let r = pe(n, t);
368
- if (typeof r == "string" && r !== "") return r;
369
- e.src || console.warn(`Unresolved image field "${n}" on item "${e.id}".`);
370
- }
371
- return typeof e.src == "string" ? e.src : "";
372
- }
373
- function de(e, t, n) {
374
- return e.value.replace(H, (r, i) => fe(r, i.trim(), t, e, n));
375
- }
376
- function fe(e, t, n, r, i) {
377
- if (U.test(t) || W.includes(t)) return e;
378
- if (t == "today") return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
379
- let a = pe(t, n);
380
- return a == null ? i ? e : (console.warn(`Unresolved placeholder "{${t}}" on item "${r.id}".`), "") : String(a);
381
- }
382
- function pe(e, t) {
383
- return e.replace(/\[(\d+)\]/g, ".$1").split(".").filter((e) => e !== "").reduce((e, t) => e?.[t], t);
384
- }
385
- //#endregion
386
- //#region src/engine/group.js
387
- var me = /\{([^{}]+)\}/g;
388
- function he(n, i) {
389
- let a = structuredClone(n), o = a.bands, s = e(a);
390
- if (a.groupBy != null && s.length === 0) throw new F(`group: layout.groupBy is "${a.groupBy}" but no band contains a table to group`);
391
- let c = r(a), l = _e(i), u = s.map((e) => {
392
- let n = ve(e, a, i);
393
- return l.set(t(e, a), n), {
394
- table: e,
395
- rows: n
396
- };
397
- });
398
- for (let { table: e, rows: n } of u) e === c?.table ? ge(e, n, c.by, o, t(e, a)) : e.row = n;
399
- return be(o, {
400
- rows: u[0]?.rows ?? [],
401
- named: l
402
- }), a;
403
- }
404
- function ge(e, t, n, r, i) {
405
- let a = De(t, n), o = we(r, a, i);
406
- e.groups = Object.entries(a).map(([e, t]) => ({
407
- key: e,
408
- rows: t,
409
- aggregates: o[e]
410
- }));
411
- }
412
- function _e(e) {
413
- let t = /* @__PURE__ */ new Map();
414
- for (let [n, r] of Object.entries(e ?? {})) Array.isArray(r) && t.set(n, r);
415
- return t;
416
- }
417
- function ve(e, n, r) {
418
- let i = t(e, n), a = i == null ? void 0 : r[i];
419
- if (a === void 0) throw new F(`group: table "${e.id}" is bound to dataset "${i}", which is not present in the data`);
420
- if (!Array.isArray(a)) throw new F(`group: dataset "${i}" must be an array of rows, got ${typeof a}`);
421
- return a;
422
- }
423
- var ye = ["groupHeader", "groupFooter"];
424
- function be(e, t) {
425
- for (let n of e) if (!ye.includes(n.type)) for (let e of n.items) e.type == "text" && (e.text = xe(e.text ?? e.value, t));
426
- }
427
- function xe(e, t) {
428
- return e.replace(me, (e, n) => {
429
- let r = Ce(n.trim());
430
- if (!r) return e;
431
- let { rows: i, field: a } = Se(r.field, t), o = Oe({
432
- key: r.key,
433
- field: a
434
- }, i);
435
- return o == null ? "" : String(o);
436
- });
437
- }
438
- function Se(e, t) {
439
- if (t.named.has(e)) return {
440
- rows: t.named.get(e),
441
- field: ""
442
- };
443
- let n = e.indexOf(".");
444
- if (n > 0) {
445
- let r = e.slice(0, n);
446
- if (t.named.has(r)) return {
447
- rows: t.named.get(r),
448
- field: e.slice(n + 1)
449
- };
450
- }
451
- return {
452
- rows: t.rows,
453
- field: e
454
- };
455
- }
456
- function Ce(e) {
457
- let t = e.match(/^(\w+)\((.*?)\)$/);
458
- return t ? {
459
- key: t[1],
460
- field: t[2].trim()
461
- } : null;
462
- }
463
- function we(e, t, n) {
464
- let r = {};
465
- for (let e of Object.keys(t)) r[e] = {};
466
- for (let i of e) if (ye.includes(i.type)) {
467
- for (let e of i.items) if (e.type == "text") for (let i of Ee(e.value)) {
468
- let e = Te(i.field, n);
469
- for (let [n, a] of Object.entries(t)) r[n][i.field] || (r[n][i.field] = {
470
- count: null,
471
- sum: null,
472
- avg: null,
473
- min: null,
474
- max: null
475
- }), r[n][i.field][i.key] = Oe({
476
- key: i.key,
477
- field: e
478
- }, a);
479
- }
480
- }
481
- return r;
482
- }
483
- function Te(e, t) {
484
- return t == null ? e : e === t ? "" : e.startsWith(`${t}.`) ? e.slice(t.length + 1) : e;
485
- }
486
- function Ee(e) {
487
- let t = [];
488
- for (let [, n] of e.matchAll(me)) {
489
- let e = Ce(n.trim());
490
- e && t.push(e);
491
- }
492
- return t;
493
- }
494
- function De(e, t) {
495
- let n = {};
496
- for (let r of e) {
497
- let e = r[t];
498
- n[e] || (n[e] = []), n[e].push(r);
499
- }
500
- return n;
501
- }
502
- function Oe(e, t) {
503
- if (e.key === "count") return t.length;
504
- let n = t.map((t) => t?.[e.field]).filter((e) => e != null && e !== "").map(Number).filter((e) => Number.isFinite(e));
505
- switch (e.key) {
506
- case "sum": return n.length ? ke(n.reduce((e, t) => e + t, 0)) : null;
507
- case "avg": return n.length ? ke(n.reduce((e, t) => e + t, 0) / n.length) : null;
508
- case "max": return n.length ? Math.max(...n) : null;
509
- case "min": return n.length ? Math.min(...n) : null;
510
- default: return console.warn(`Unknown aggregate "${e.key}()"; it has no value.`), null;
511
- }
512
- }
513
- function ke(e) {
514
- return Number(e.toPrecision(12));
515
- }
516
- //#endregion
517
- //#region src/engine/regions.js
518
- var Ae = {
519
- pageHeader: "10%",
520
- reportHeader: "10%",
521
- reportFooter: "10%",
522
- pageFooter: "10%"
523
- }, je = ["pageHeader", "reportHeader"], Me = ["reportFooter", "pageFooter"];
524
- function Ne(e, t, n) {
525
- let r = Pe(e, t);
526
- return r === null ? Pe(n, t) ?? 0 : r;
527
- }
528
- function Pe(e, t) {
529
- if (typeof e == "number" && Number.isFinite(e) && e >= 0) return e;
530
- if (typeof e == "string") {
531
- let n = e.trim().match(/^(-?[\d.]+)\s*%$/);
532
- if (n) {
533
- let e = Number(n[1]);
534
- return Number.isFinite(e) && e >= 0 ? e / 100 * t : null;
535
- }
536
- let r = Number(e.trim().replace(/px$/i, ""));
537
- if (Number.isFinite(r) && r >= 0) return r;
538
- }
539
- return null;
540
- }
541
- function G(e, t) {
542
- if (!e) return 0;
543
- let n = Ne(e.height, t, Ae[e.type]), r = e.measuredHeight ?? 0;
544
- return r > n ? (console.warn(`Band "${e.type}" needs ${Math.ceil(r)}px but its zone is ${Math.round(n)}px; the zone has been grown to fit.`), r) : n;
545
- }
546
- function Fe({ bands: e, contentHeight: t, isFirstPage: n, isLastPage: r }) {
547
- let i = {}, a = (e) => e === "reportHeader" ? n : e !== "reportFooter" || r, o = 0;
548
- for (let n of je) {
549
- let r = e[n];
550
- if (!r || !a(n)) continue;
551
- let s = G(r, t);
552
- i[n] = {
553
- top: o,
554
- height: s
555
- }, o += s;
556
- }
557
- let s = o, c = t;
558
- for (let n of [...Me].reverse()) {
559
- let r = e[n];
560
- if (!r || !a(n)) continue;
561
- let o = G(r, t);
562
- c -= o, i[n] = {
563
- top: c,
564
- height: o
565
- };
566
- }
567
- return i.detail = {
568
- top: s,
569
- height: Math.max(c - s, 0)
570
- }, i;
571
- }
572
- //#endregion
573
- //#region src/engine/paginate.js
574
- var Ie = /\{([^{}]+)\}/g, Le = ["page", "totalPages"];
575
- function Re(e) {
576
- let t = structuredClone(e), n = {
577
- page: t.page,
578
- bands: t.bands,
579
- assignedBands: {
580
- reportHeader: t.bands.find((e) => e.type === "reportHeader"),
581
- reportFooter: t.bands.find((e) => e.type === "reportFooter"),
582
- pageHeader: t.bands.find((e) => e.type === "pageHeader"),
583
- pageFooter: t.bands.find((e) => e.type === "pageFooter"),
584
- detail: t.bands.find((e) => e.type === "detail"),
585
- groupHeader: t.bands.find((e) => e.type === "groupHeader") || null,
586
- groupFooter: t.bands.find((e) => e.type === "groupFooter") || null
587
- }
588
- };
589
- return n.availableHeight = qe(t.page), n.regionsFor = (e, t) => Fe({
590
- bands: n.assignedBands,
591
- contentHeight: n.availableHeight,
592
- isFirstPage: e === 1,
593
- isLastPage: t
594
- }), t.pages = Je(He(t.bands.filter((e) => ![
595
- "reportHeader",
596
- "reportFooter",
597
- "pageHeader",
598
- "pageFooter",
599
- "groupHeader",
600
- "groupFooter"
601
- ].includes(e.type)), n)), t;
602
- }
603
- function ze(e, t, n, r = Infinity) {
604
- let i = 0, a = 0;
605
- for (; t + a < e.length && a < r;) {
606
- let r = i + e[t + a];
607
- if (r > n) break;
608
- i = r, a++;
609
- }
610
- return a;
611
- }
612
- function Be(e, t, n) {
613
- return k(e.slice(t, t + n));
614
- }
615
- function Ve(e, t, n) {
616
- return Array.isArray(n) && n.length === (t ?? []).length ? n : (t ?? []).map(() => e.rowHeight ?? 0);
617
- }
618
- function He(e, t) {
619
- let n = [], r = Ke(1, t);
620
- n.push(r);
621
- let { assignedBands: i, availableHeight: a } = t, { reportFooter: o, reportHeader: s, groupHeader: c, groupFooter: l, pageHeader: u, pageFooter: d } = i, f = t.regionsFor(2, !1).detail.height;
622
- s && r.regions.detail.height <= 0 && console.warn("The header zones leave no room for detail on page 1. Reduce the reportHeader or pageHeader height.");
623
- let p = 0, m = 0, h = [], g = () => r.regions.detail.height, _ = (e, i, a) => (e.items.length > 0 && r.bands.push(e), r = Ke(n.length + 1, t), n.push(r), p = 0, m = a, h = [], {
624
- ...i,
625
- items: []
626
- }), v = (e, t) => {
627
- e.items.push(t), p = Math.max(p, (t.y ?? 0) + (t.measuredHeight ?? 0)), e.measuredHeight = p, r.usedHeight = a - g() + p;
628
- }, y = (e) => {
629
- let t = -Infinity, n = -Infinity;
630
- for (let r of h) r.designBottom > e || (t = Math.max(t, r.designBottom), n = Math.max(n, r.actualBottom));
631
- return t === -Infinity ? 0 : n - t;
632
- }, S = (e) => {
633
- let t = e - m;
634
- return t + y(t);
635
- };
636
- for (let t of e) {
637
- let e = {
638
- ...t,
639
- items: []
640
- };
641
- m = 0, h = [];
642
- let n = [...t.items].sort((e, t) => (e.y ?? 0) - (t.y ?? 0));
643
- for (let r of n) {
644
- let n = r.y ?? 0, i = S(n) + r.measuredHeight;
645
- if (i > g() && r.type != "table") r.measuredHeight > f ? console.warn(`Item "${r.id}" is ${Math.ceil(r.measuredHeight)}px tall, past the ${f}px detail zone of an empty page; it will overflow.`) : e = _(e, t, n), v(e, {
646
- ...structuredClone(r),
647
- y: S(n)
648
- });
649
- else if (i > g() && r.type == "table") {
650
- let i = S(n);
651
- if (r.groups) {
652
- let a = c?.measuredHeight ?? 0, o = l?.measuredHeight ?? 0, s = r.headerMeasured ?? b(r), u = Math.max(r.rowHeight ?? 0, ...(r.groups ?? []).flatMap((e) => Ve(r, e.rows, e.rowHeights))), d = s + a + u + o;
653
- d <= f || console.warn(`Table "${r.id}": table header + group header + one row + group footer (${d}px) exceeds the ${f}px printable page. Falling back to one row per page; rows will overflow their page.`);
654
- let p = (e, t, n, r) => {
655
- let i = n - a - s;
656
- return r <= ze(e, t, i - o, r) ? r : Math.min(ze(e, t, i, r), r - 1);
657
- }, m = [], h = 0;
658
- for (let u of r.groups) {
659
- let d = 0, y = u.rows.length, b = Ve(r, u.rows, u.rowHeights);
660
- for (; d < y;) {
661
- let x = g() - i - h, S = m.length === 0 && e.items.length === 0 && i === 0 && g() >= f, C = p(b, d, x, y - d);
662
- if (C < 1 && S && (C = 1), C < 1) {
663
- if (m.length > 0) {
664
- let t = structuredClone(r);
665
- t.groups = m, t.y = i, t.measuredHeight = h, v(e, t);
666
- }
667
- e = _(e, t, n), m = [], h = 0, i = 0;
668
- continue;
669
- }
670
- let w = u.rows.slice(d, d + C), T = b.slice(d, d + C);
671
- d += w.length;
672
- let E = d < y, D = k(T) + (a + s) + (E ? 0 : o);
673
- h += D;
674
- let O = {
675
- key: u.key,
676
- rows: w,
677
- rowHeights: T,
678
- aggregates: u.aggregates,
679
- showHeader: !0,
680
- showFooter: !E,
681
- headerBand: K(c, u, w[0]),
682
- footerBand: E ? null : K(l, u, w[0])
683
- };
684
- m.push(O);
685
- }
686
- }
687
- if (m.length > 0) {
688
- let t = structuredClone(r);
689
- t.groups = m, t.y = i, t.measuredHeight = h, v(e, t), m = [];
690
- }
691
- } else {
692
- let a = r.row.length, o = 0, s = r.headerMeasured ?? b(r), c = Ve(r, r.row, r.rowHeights), l = Math.max(r.rowHeight ?? 0, ...c);
693
- for (f - s >= l || console.warn(`Table "${r.id}": its tallest row is ${Math.ceil(l)}px, which with the ${s}px header exceeds the ${f}px printable page. Falling back to one row per page; rows will overflow their page.`); o < a;) {
694
- let l = g() - i, u = ze(c, o, l - s, a - o), d = e.items.length === 0 && i === 0 && g() >= f;
695
- if (u < 1 && d && (u = 1), u < 1) {
696
- e = _(e, t, n), i = 0;
697
- continue;
698
- }
699
- u = Math.min(u, a - o);
700
- let p = structuredClone(r), m = r.row.slice(o, o + u), h = Be(c, o, u) + s;
701
- p.row = m, p.rowHeights = c.slice(o, o + u), p.y = i, p.measuredHeight = h, v(e, p), o += m.length, o < a && (e = _(e, t, n), i = 0);
702
- }
703
- }
704
- } else {
705
- let t = r.type === "table" && r.groups ? {
706
- ...r,
707
- groups: We(r, c, l)
708
- } : r;
709
- v(e, {
710
- ...structuredClone(t),
711
- y: S(n)
712
- });
713
- }
714
- let a = [...e.items].reverse().find((e) => e.id === r.id);
715
- a && h.push({
716
- designBottom: n - m + x(r),
717
- actualBottom: (a.y ?? 0) + (a.measuredHeight ?? 0)
718
- });
719
- }
720
- e.items.length > 0 && (r.bands.push(e), e = {
721
- ...t,
722
- items: []
723
- });
724
- }
725
- if (o) {
726
- let e = G(o, a);
727
- r.usedHeight + e > a && (r = Ke(n.length + 1, t), n.push(r)), r.bands.push(structuredClone(o)), r.usedHeight += e;
728
- }
729
- let C = n[n.length - 1];
730
- return C.regions = t.regionsFor(C.pageNO, !!o), Ue(n), n;
731
- }
732
- function Ue(e) {
733
- for (let t of e) for (let e of t.bands) {
734
- let n = t.regions[e.type] ?? t.regions.detail;
735
- e.top = n.top, e.zoneHeight = n.height;
736
- }
737
- }
738
- function We(e, t, n) {
739
- return e.groups.map((e) => ({
740
- key: e.key,
741
- rows: e.rows,
742
- rowHeights: e.rowHeights,
743
- aggregates: e.aggregates,
744
- showHeader: !0,
745
- showFooter: !0,
746
- headerBand: K(t, e, e.rows[0]),
747
- footerBand: K(n, e, e.rows[0])
748
- }));
749
- }
750
- function K(e, t, n) {
751
- if (!e) return null;
752
- let r = structuredClone(e);
753
- for (let e of r.items) e.type === "text" && (e.text = (e.text ?? e.value).replace(Ie, (e, r) => Ge(e, r.trim(), t, n)));
754
- return r;
755
- }
756
- function Ge(e, t, n, r) {
757
- if (Le.includes(t)) return e;
758
- let i = t.match(/^(\w+)\((.*?)\)$/);
759
- if (i) {
760
- let [, e, t] = i, r = n.aggregates?.[t]?.[e.trim()];
761
- return r == null ? "" : String(r);
762
- }
763
- let a = r?.[t];
764
- return a == null ? "" : String(a);
765
- }
766
- function Ke(e, t) {
767
- let { pageHeader: n, pageFooter: r, reportHeader: i } = t.assignedBands, a = t.regionsFor(e, !1), o = [];
768
- return n && o.push(structuredClone(n)), r && o.push(structuredClone(r)), i && e === 1 && o.push(structuredClone(i)), {
769
- pageNO: e,
770
- bands: o,
771
- regions: a,
772
- usedHeight: t.availableHeight - a.detail.height
773
- };
774
- }
775
- function qe(e) {
776
- return e.height - (e.margin.top + e.margin.bottom);
777
- }
778
- function Je(e) {
779
- for (let t of e) for (let n of t.bands) Ye(n, t.pageNO, e.length);
780
- return e;
781
- }
782
- function Ye(e, t, n) {
783
- for (let r of e?.items ?? []) {
784
- if (r.type === "text") {
785
- let e = r.text ?? r.value ?? "";
786
- if (!e.includes("{")) continue;
787
- r.text = e.replace(Ie, (e, r) => {
788
- switch (r.trim()) {
789
- case "page": return t;
790
- case "totalPages": return n;
791
- default: return e;
792
- }
793
- });
794
- continue;
795
- }
796
- if (r.type === "table" && r.groups) for (let e of r.groups) Ye(e.headerBand, t, n), Ye(e.footerBand, t, n);
797
- }
798
- }
799
- //#endregion
800
- //#region src/engine/search.js
801
- function Xe(e, t, { caseSensitive: n = !1 } = {}) {
802
- let r = String(t ?? "");
803
- if (r === "") return [];
804
- let i = [];
805
- for (let t of e ?? []) for (let e of t.bands ?? []) Qe(e, t.pageNO, e.type, r, n, i);
806
- return i;
807
- }
808
- function Ze(e, t, n) {
809
- return [...new Set(Xe(e, t, n).map((e) => e.pageNO))];
810
- }
811
- function Qe(e, t, n, r, i, a) {
812
- for (let o of e?.items ?? []) {
813
- if (o.type === "text") {
814
- tt(a, o.text, {
815
- pageNO: t,
816
- bandType: n,
817
- itemId: o.id,
818
- field: null
819
- }, r, i);
820
- continue;
821
- }
822
- o.type === "table" && $e(o, t, n, r, i, a);
823
- }
824
- }
825
- function $e(e, t, n, r, i, a) {
826
- let o = e.columns ?? [];
827
- if (e.showHeader) for (let s of o) tt(a, s.label, {
828
- pageNO: t,
829
- bandType: n,
830
- itemId: e.id,
831
- field: s.field
832
- }, r, i);
833
- if (e.row) {
834
- et(e.row, o, e.id, t, n, r, i, a);
835
- return;
836
- }
837
- for (let s of e.groups ?? []) Qe(s.headerBand, t, "groupHeader", r, i, a), et(s.rows, o, e.id, t, n, r, i, a), s.showFooter && Qe(s.footerBand, t, "groupFooter", r, i, a);
838
- }
839
- function et(e, t, n, r, i, a, o, s) {
840
- for (let c of e ?? []) for (let e of t) tt(s, c?.[e.field], {
841
- pageNO: r,
842
- bandType: i,
843
- itemId: n,
844
- field: e.field
845
- }, a, o);
846
- }
847
- function tt(e, t, n, r, i) {
848
- if (t == null) return;
849
- let a = String(t), o = i ? a : a.toLowerCase(), s = i ? r : r.toLowerCase(), c = 0;
850
- for (; c <= o.length - s.length;) {
851
- let t = o.indexOf(s, c);
852
- if (t === -1) break;
853
- e.push({
854
- ...n,
855
- text: a,
856
- start: t,
857
- end: t + s.length
858
- }), c = t + s.length;
859
- }
860
- }
861
- //#endregion
862
- //#region src/engine/csv.js
863
- var nt = /^[=+\-@\t\r]/;
864
- function rt(e, t = {}) {
865
- let { delimiter: n = ",", newline: r = "\r\n", header: i = !0, groupColumn: a = !0, groupLabel: o = "Group", neutraliseFormulas: s = !0, table: c = null } = t, l = dt(e, c);
866
- if (!l) return "";
867
- let u = a && l.rows.some((e) => e.group !== null), d = l.columns.map((e) => e.label ?? e.field), f = [];
868
- i && f.push(ft(u ? [o, ...d] : d, n, s));
869
- for (let { group: e, row: t } of l.rows) {
870
- let r = l.columns.map((e) => t?.[e.field]);
871
- f.push(ft(u ? [e, ...r] : r, n, s));
872
- }
873
- return f.join(r);
874
- }
875
- function it(e, t = {}) {
876
- let { delimiter: n = ",", newline: r = "\r\n", neutraliseFormulas: i = !0 } = t, a = [];
877
- for (let t of e ?? []) for (let e of at(t?.bands)) ot(e, a);
878
- return a.length === 0 ? "" : a.map((e) => ft(e, n, i)).join(r);
879
- }
880
- function at(e) {
881
- return [...e ?? []].sort((e, t) => (e?.top ?? 0) - (t?.top ?? 0));
882
- }
883
- function ot(e, t) {
884
- let n = (e?.items ?? []).filter((e) => e?.type === "text" || e?.type === "table").sort((e, t) => (e.y ?? 0) - (t.y ?? 0) || (e.x ?? 0) - (t.x ?? 0)), r = null, i = () => {
885
- r && t.push(r.cells), r = null;
886
- };
887
- for (let e of n) {
888
- if (e.type === "table") {
889
- i(), ct(e, t);
890
- continue;
891
- }
892
- if (r && st(r.anchor, e)) {
893
- r.cells.push(e.text);
894
- continue;
895
- }
896
- i(), r = {
897
- anchor: e,
898
- cells: [e.text]
899
- };
900
- }
901
- i();
902
- }
903
- function st(e, t) {
904
- let n = (e) => {
905
- let t = e.y ?? 0;
906
- return [t, t + (e.measuredHeight ?? e.h ?? 0)];
907
- }, [r, i] = n(e), [a, o] = n(t);
908
- return Math.min(i, o) - Math.max(r, a) >= Math.min(i - r, o - a) / 2;
909
- }
910
- function ct(e, t) {
911
- let n = () => e.columns.map((e) => e.label ?? e.field), r = (t) => e.columns.map((e) => t?.[e.field]);
912
- if (!e.groups) {
913
- e.showHeader && t.push(n());
914
- for (let n of e.row ?? []) t.push(r(n));
915
- return;
916
- }
917
- for (let i of e.groups) {
918
- i.showHeader && e.showHeader && t.push(n()), i.headerBand && ot(i.headerBand, t);
919
- for (let e of i.rows) t.push(r(e));
920
- i.showFooter && i.footerBand && ot(i.footerBand, t);
921
- }
922
- }
923
- function lt(e, t = "csv") {
924
- return `${String(e?.name ?? "report").replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " ").trim() || "report"}.${t}`;
925
- }
926
- function ut(e) {
927
- let t = /* @__PURE__ */ new Map();
928
- for (let n of e ?? []) for (let e of n.bands ?? []) for (let n of e.items ?? []) n.type !== "table" || t.has(n.id) || t.set(n.id, {
929
- id: n.id,
930
- columns: (n.columns ?? []).map((e) => e.label ?? e.field)
931
- });
932
- return [...t.values()];
933
- }
934
- function dt(e, t = null) {
935
- let n = null, r = t, i = [];
936
- for (let t of e ?? []) for (let e of t.bands ?? []) for (let t of e.items ?? []) if (t.type === "table" && !(r !== null && t.id !== r)) {
937
- if (n === null && (r = t.id, n = t.columns ?? []), t.row) {
938
- for (let e of t.row) i.push({
939
- group: null,
940
- row: e
941
- });
942
- continue;
943
- }
944
- for (let e of t.groups ?? []) for (let t of e.rows) i.push({
945
- group: e.key,
946
- row: t
947
- });
948
- }
949
- return n === null ? null : {
950
- columns: n,
951
- rows: i
952
- };
953
- }
954
- function ft(e, t, n) {
955
- return e.map((e) => pt(e, t, n)).join(t);
956
- }
957
- function pt(e, t, n) {
958
- if (e == null) return "";
959
- let r = String(e);
960
- return n && nt.test(r) && (r = `\t${r}`), r.includes(t) || r.includes("\"") || r.includes("\n") || r.includes("\r") ? `"${r.replace(/"/g, "\"\"")}"` : r;
961
- }
962
- //#endregion
963
- //#region src/engine/index.js
964
- function mt(e, t) {
965
- return Re(S(he(le(e, t), t)));
966
- }
967
- //#endregion
968
- //#region src/render/items.js
969
- var q = (e) => `position:absolute;top:${J(e?.y)}px;left:${J(e?.x)}px;`;
970
- function J(e, t = 0) {
971
- let n = Number(e);
972
- return Number.isFinite(n) ? n : t;
973
- }
974
- function Y(e, t = "") {
975
- if (e == null) return t;
976
- let n = String(e).replace(/[<>"'`&;{}\\]/g, "").replace(/url\s*\(/gi, "").replace(/\s+/g, " ").trim();
977
- return n === "" ? t : n;
978
- }
979
- function X(e) {
980
- return e == null ? "" : String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
981
- }
982
- function ht(e) {
983
- return (e || []).map((e) => {
984
- switch (e.type) {
985
- case "text": return gt(e);
986
- case "table": return kt(e);
987
- case "line": return wt(e);
988
- case "box": return _t(e);
989
- case "image": return St(e);
990
- default: return console.warn(`Unknown item type "${e?.type}"; it is not drawn.`), "";
991
- }
992
- }).join("");
993
- }
994
- function gt(e) {
995
- let t = e.style ?? {};
996
- return `
997
- <p id="${X(e.id)}" style="
998
- width:${J(e.w)}px;
999
- height:${J(e.h)}px;
1000
- ${q(e)}
1001
- font-size:${J(t.fontSize, 12)}px;
1002
- font-family:${Y(t.fontFamily, "inherit")};
1003
- font-weight:${Y(t.fontWeight, "normal")};
1004
- font-style:${Y(t.fontStyle, "normal")};
1005
- text-align:${Y(t.align, "left")};
1006
- color:${Y(t.color, "inherit")};
1007
- " data-item-id="${X(e.id)}" data-item-type="text">${X(e.text)}</p>
1008
- `;
1009
- }
1010
- function _t(e) {
1011
- let t = e.style ?? {}, n = `${Math.max(0, Number(t.borderWidth ?? 1)) || 1}px ${Et.includes(t.borderStyle) ? t.borderStyle : "solid"} ${Y(t.borderColor, "#000000")}`, r = Math.max(0, Number(t.radius ?? 0)) || 0, i = Y(t.background);
1012
- return `
1013
- <div id="${X(e.id)}" class="box" style="
1014
- width:${J(e.w)}px;
1015
- height:${J(e.h)}px;
1016
- ${q(e)}
1017
- border:${n};
1018
- ${r ? `border-radius:${r}px;` : ""}
1019
- ${i ? `background:${i};` : ""}
1020
- " data-item-id="${X(e.id)}" data-item-type="box"></div>
1021
- `;
1022
- }
1023
- var vt = [
1024
- "contain",
1025
- "cover",
1026
- "fill"
1027
- ], yt = /^data:image\/(png|jpe?g|gif|webp|avif|bmp);base64,[a-z0-9+/=\s]*$/i, bt = [
1028
- "http:",
1029
- "https:",
1030
- "blob:"
1031
- ];
1032
- function xt(e) {
1033
- if (typeof e != "string") return "";
1034
- let t = e.trim();
1035
- if (t === "") return "";
1036
- let n = t.replace(/[\u0000-\u0020\u007f]+/g, "");
1037
- if (/^data:/i.test(n)) return yt.test(n) ? n : "";
1038
- let r = n.match(/^([a-z][a-z0-9+.-]*:)/i)?.[1]?.toLowerCase();
1039
- return r == null || bt.includes(r) ? t : "";
1040
- }
1041
- function St(e) {
1042
- let t = Object.prototype.hasOwnProperty.call(e, "resolvedSrc"), n = xt(t ? e.resolvedSrc : e.src), r = vt.includes(e.fit) ? e.fit : "contain", i = "";
1043
- if (n) i = `<img src="${X(n)}" alt="${X(e.alt ?? "")}" style="object-fit:${r}" draggable="false">`;
1044
- else if (!t) {
1045
- let t = typeof e.field == "string" ? e.field.trim() : "";
1046
- i = `<span class="image-empty">${t ? X(`{${t}}`) : "Image"}</span>`;
1047
- }
1048
- return `
1049
- <div id="${X(e.id)}" class="image" style="
1050
- width:${J(e.w)}px;
1051
- height:${J(e.h)}px;
1052
- ${q(e)}
1053
- " data-item-id="${X(e.id)}" data-item-type="image">${i}</div>
1054
- `;
1055
- }
1056
- function Ct(e) {
1057
- return `${Math.max(0, Number(e?.thickness ?? 1)) || 1}px ${Tt.includes(e?.lineStyle) ? e.lineStyle : "solid"} ${Y(e?.color, "#000000")}`;
1058
- }
1059
- function wt(e) {
1060
- let t = e.orientation === "vertical", n = Ct(e.style);
1061
- return `
1062
- <div id="${X(e.id)}" class="line${t ? " is-vertical" : ""}" style="
1063
- width:${J(e.w)}px;
1064
- height:${J(e.h)}px;
1065
- ${q(e)}
1066
- " data-item-id="${X(e.id)}" data-item-type="line"><span class="line-mark"
1067
- style="${t ? `border-left:${n}` : `border-top:${n}`}"></span></div>
1068
- `;
1069
- }
1070
- var Tt = [
1071
- "solid",
1072
- "dashed",
1073
- "dotted",
1074
- "double"
1075
- ], Et = [...Tt, "none"];
1076
- function Dt(e) {
1077
- let t = e.rowHeight ?? 0, n = e.showHeader ? e.headerHeight ?? t : t, r = Math.min(t || Infinity, n || Infinity);
1078
- return Number.isFinite(r) ? Math.max(1, Math.floor(r / 2)) : 1;
1079
- }
1080
- function Ot(e) {
1081
- let t = e.style ?? {}, n = [];
1082
- Et.includes(t.borderStyle) && n.push(`--rs-rule-style:${t.borderStyle}`), t.borderColor && n.push(`--rs-rule-color:${Y(t.borderColor)}`), t.headerBackground && n.push(`--rs-head-bg:${Y(t.headerBackground)}`), t.headerColor && n.push(`--rs-head-color:${Y(t.headerColor)}`), t.fontFamily && n.push(`--rs-cell-family:${Y(t.fontFamily)}`);
1083
- let r = Number(t.fontSize);
1084
- Number.isFinite(r) && r > 0 && n.push(`--rs-cell-size:${r}px`), t.color && n.push(`--rs-cell-color:${Y(t.color)}`), e.wrap === !1 && n.push("--rs-cell-wrap:nowrap");
1085
- let i = Number(t.borderWidth);
1086
- return Number.isFinite(i) && i > 0 && n.push(`--rs-rule-width:${Math.min(i, Dt(e))}px`), n.length ? `${n.join(";")};` : "";
1087
- }
1088
- function kt(e) {
1089
- return `
1090
- <table id="${X(e.id)}" style="width:${J(e.w)}px;height:${J(e.measuredHeight)}px;${q(e)}${Ot(e)}" data-item-id="${X(e.id)}" data-item-type="table">
1091
- ${e.groups ? Ft(e) : Pt(e)}
1092
- </table>
1093
- `;
1094
- }
1095
- function At(e, t, n) {
1096
- return `<div class="cell" style="height:${J(e)}px;text-align:${Y(t, "left")}">${X(n)}</div>`;
1097
- }
1098
- function jt(e) {
1099
- let t = e.headerMeasured ?? e.headerHeight ?? e.rowHeight;
1100
- return `<thead>
1101
- <tr style="height:${J(t)}px">
1102
- ${e.columns.map((e) => `<th style="width:${J(e.width)}px;">${At(t, e.align, e.label)}</th>`).join("")}
1103
- </tr>
1104
- </thead>`;
1105
- }
1106
- function Mt(e, t, n) {
1107
- return (t || []).map((t, r) => {
1108
- let i = n?.[r] ?? e.rowHeight;
1109
- return `<tr style="height:${J(i)}px">
1110
- ${e.columns.map((e) => `<td style="width:${J(e.width)}px;">${At(i, e.align, t[e.field])}</td>`).join("")}
1111
- </tr>`;
1112
- }).join("");
1113
- }
1114
- function Nt(e, t, n) {
1115
- return e ? `<tr class="${n}">
1116
- <td colspan="${t}" class="group-band-cell">
1117
- <div class="band" style="position:relative;height:${J(e.measuredHeight > 0 ? e.measuredHeight : e.height ?? 0)}px">${ht(e.items)}</div>
1118
- </td>
1119
- </tr>` : "";
1120
- }
1121
- function Pt(e) {
1122
- return `
1123
- ${e.showHeader ? jt(e) : ""}
1124
- <tbody>
1125
- ${Mt(e, e.row, e.rowHeights)}
1126
- </tbody>
1127
- `;
1128
- }
1129
- function Ft(e) {
1130
- let t = e.columns.length;
1131
- return e.groups.map((n) => `
1132
- ${n.showHeader && e.showHeader ? jt(e) : ""}
1133
- <tbody>
1134
- ${Nt(n.headerBand, t, "group-header")}
1135
- ${Mt(e, n.rows, n.rowHeights)}
1136
- ${n.showFooter ? Nt(n.footerBand, t, "group-footer") : ""}
1137
- </tbody>
1138
- `).join("");
1139
- }
1140
- //#endregion
1141
- //#region src/render/render.js
1142
- var It = (e) => `padding-top:${J(e?.top)}px;padding-left:${J(e?.left)}px;padding-bottom:${J(e?.bottom)}px;padding-right:${J(e?.right)}px;`, Lt = [
1143
- "pageHeader",
1144
- "reportHeader",
1145
- "detail",
1146
- "reportFooter",
1147
- "pageFooter"
1148
- ];
1149
- function Rt(e) {
1150
- let t = e.page;
1151
- return `
1152
- <main id="main-page">
1153
- ${e.pages.map((e) => `
1154
- <section id="page-${X(e.pageNO)}" class="page" style="height:${J(t.height)}px; width:${J(t.width)}px; ${It(t.margin)};position:relative">
1155
- ${zt(e, t)}
1156
- </section>
1157
- `).join("")}
1158
- </main>
1159
- `;
1160
- }
1161
- function zt(e, t) {
1162
- let n = (e) => {
1163
- let t = Lt.indexOf(e);
1164
- return t === -1 ? Lt.length : t;
1165
- }, r = [...e.bands].sort(({ type: e }, { type: t }) => n(e) - n(t)), i = [];
1166
- for (let n of r) i.push(Bt(n, e.pageNO, t));
1167
- return i.join("");
1168
- }
1169
- function Bt(e, t, n) {
1170
- let r = Number.isFinite(e.top), i = n?.margin ?? {
1171
- top: 0,
1172
- left: 0,
1173
- right: 0
1174
- }, a = r ? `position:absolute;top:${J(e.top) + J(i.top)}px;left:${J(i.left)}px;right:${J(i.right)}px;` : "position:relative;", o = Math.max(e.zoneHeight ?? 0, e.measuredHeight ?? 0);
1175
- return `
1176
- <div class="band" id="${X(e.type)}-${X(t)}" style="${a}${o > 0 ? `height:${J(o)}px` : ""}" data-band-type="${X(e.type)}">
1177
- ${ht(e.items)}
1178
- </div>
1179
- `;
1180
- }
1181
- //#endregion
1182
- //#region src/shared/window.js
1183
- var Vt = 1280, Ht = 900;
1184
- function Ut(e, t) {
1185
- for (let n of e.querySelectorAll("link[rel=\"stylesheet\"], style")) {
1186
- if (n.tagName === "LINK") {
1187
- let e = t.createElement("link");
1188
- e.rel = "stylesheet", e.href = n.href, t.head.appendChild(e);
1189
- continue;
1190
- }
1191
- let e = t.createElement("style");
1192
- e.textContent = n.textContent, t.head.appendChild(e);
1193
- }
1194
- }
1195
- function Wt({ title: e = "Report Studio", width: t = Vt, height: n = Ht, features: r, opener: i = globalThis } = {}) {
1196
- let a = r ?? `width=${t},height=${n},resizable=yes,scrollbars=yes`, o = i.open?.("", "_blank", a);
1197
- if (!o || !o.document) return null;
1198
- let s = o.document;
1199
- s.open(), s.write("<!doctype html><html><head><meta charset=\"utf-8\"></head><body></body></html>"), s.close(), s.title = e, Ut(i.document, s);
1200
- let c = s.createElement("div");
1201
- return c.id = "report-studio", c.style.height = "100vh", s.body.style.margin = "0", s.body.appendChild(c), {
1202
- window: o,
1203
- document: s,
1204
- mount: c,
1205
- close: () => o.close()
1206
- };
1207
- }
1208
- function Gt(e, t, n = () => {}) {
1209
- let r = () => {
1210
- n(), t.close();
1211
- };
1212
- return e.addEventListener("pagehide", r), () => e.removeEventListener("pagehide", r);
1213
- }
1214
- //#endregion
1215
- //#region src/shared/dropdown.js
1216
- function Kt(e) {
1217
- let t = e.querySelector(".dropdown-trigger"), n = e.querySelector(".dropdown-value"), r = e.querySelector(".dropdown-menu"), i = [...r.querySelectorAll(".dropdown-item")], a = /* @__PURE__ */ new Set(), o = () => t.ownerDocument, s = i.find((e) => e.dataset.selected === "true")?.dataset.value ?? i[0]?.dataset.value ?? "", c = Math.max(i.findIndex((e) => e.dataset.value === s), 0);
1218
- function l() {
1219
- i.forEach((e, t) => {
1220
- let n = e.dataset.value === s;
1221
- e.setAttribute("aria-selected", String(n)), e.classList.toggle("is-active", t === c);
1222
- });
1223
- let e = i.find((e) => e.dataset.value === s);
1224
- e && (n.textContent = e.textContent.trim());
1225
- }
1226
- function u(e, { notify: t = !1 } = {}) {
1227
- let n = i.find((t) => t.dataset.value === String(e));
1228
- if (!n) return;
1229
- let r = n.dataset.value !== s;
1230
- if (s = n.dataset.value, c = i.indexOf(n), l(), t && r) for (let e of a) e();
1231
- }
1232
- let d = () => !r.hidden;
1233
- function f() {
1234
- d() || (r.hidden = !1, t.setAttribute("aria-expanded", "true"), c = Math.max(i.findIndex((e) => e.dataset.value === s), 0), l(), i[c]?.focus(), setTimeout(() => o().addEventListener("pointerdown", m), 0));
1235
- }
1236
- function p({ focusTrigger: e = !0 } = {}) {
1237
- d() && (r.hidden = !0, t.setAttribute("aria-expanded", "false"), o().removeEventListener("pointerdown", m), e && t.focus());
1238
- }
1239
- function m(t) {
1240
- e.contains(t.target) || p({ focusTrigger: !1 });
1241
- }
1242
- function h(e) {
1243
- c = (e + i.length) % i.length, l(), i[c]?.focus();
1244
- }
1245
- function g(e) {
1246
- [
1247
- "ArrowDown",
1248
- "ArrowUp",
1249
- "Enter",
1250
- " "
1251
- ].includes(e.key) && (e.preventDefault(), e.stopPropagation(), f());
1252
- }
1253
- function _(e) {
1254
- let t = {
1255
- ArrowDown: () => h(c + 1),
1256
- ArrowUp: () => h(c - 1),
1257
- Home: () => h(0),
1258
- End: () => h(i.length - 1),
1259
- Escape: () => p(),
1260
- Enter: () => {
1261
- u(i[c].dataset.value, { notify: !0 }), p();
1262
- },
1263
- " ": () => {
1264
- u(i[c].dataset.value, { notify: !0 }), p();
1265
- },
1266
- Tab: () => p({ focusTrigger: !1 })
1267
- }[e.key];
1268
- t && (e.key !== "Tab" && (e.preventDefault(), e.stopPropagation()), t());
1269
- }
1270
- t.addEventListener("click", () => d() ? p() : f()), t.addEventListener("keydown", g), r.addEventListener("keydown", _);
1271
- for (let e of i) e.addEventListener("click", () => {
1272
- u(e.dataset.value, { notify: !0 }), p();
1273
- });
1274
- return l(), {
1275
- get value() {
1276
- return s;
1277
- },
1278
- set value(e) {
1279
- u(e);
1280
- },
1281
- addEventListener(e, t) {
1282
- e === "change" && a.add(t);
1283
- },
1284
- open: f,
1285
- close: p,
1286
- get isOpen() {
1287
- return d();
1288
- },
1289
- destroy() {
1290
- o().removeEventListener("pointerdown", m), a.clear();
1291
- }
1292
- };
1293
- }
1294
- //#endregion
1295
- //#region src/preview/chrome.js
1296
- function qt({ title: e = "Report Studio" } = {}) {
1297
- return `
1298
- <!--
1299
- A header, not role="toolbar": that role promises arrow-key roving focus
1300
- between the controls, and here the arrow keys page the report instead.
1301
-
1302
- Two boxes: the header is what measures its width, and the row inside
1303
- it is what rearranges. A container query restyles what is inside the
1304
- container, never the container, so the grid cannot be the header.
1305
- -->
1306
- <header class="toolbar" aria-label="Report tools">
1307
- <div class="toolbar-row" data-role="bar">
1308
- <div class="toolbar-brand">${e}</div>
1309
-
1310
- <div class="toolbar-centre">
1311
- <div class="toolbar-group toolbar-search">
1312
- <!--
1313
- Buttons cannot live inside an <input>, so the wrapper draws
1314
- the field and the input inside it draws no chrome of its own.
1315
- -->
1316
- <div class="search-field">
1317
- <input type="search" data-role="query" placeholder="Search the report (ctrl+K)"
1318
- title="Search the report (ctrl+K)"
1319
- aria-label="Search the report" spellcheck="false">
1320
- <span class="hits" data-role="hits" data-state="idle" aria-live="polite"></span>
1321
- <button type="button" data-role="hit-prev" title="Previous match (shift+enter)"
1322
- aria-label="Previous match">&#8593;</button>
1323
- <button type="button" data-role="hit-next" title="Next match (enter)"
1324
- aria-label="Next match">&#8595;</button>
1325
- </div>
1326
- </div>
1327
-
1328
- <div class="toolbar-group toolbar-zoom">
1329
- <button type="button" data-role="zoom-out" title="Zoom out (ctrl+-)"
1330
- aria-label="Zoom out">&#8722;</button>
1331
-
1332
- <!--
1333
- A listbox rather than a <select>: option items are drawn by
1334
- the operating system, so they cannot take the palette.
1335
- -->
1336
- <div class="dropdown" data-role="zoom-dropdown">
1337
- <button type="button" class="dropdown-trigger" data-role="zoom"
1338
- aria-haspopup="listbox" aria-expanded="false" aria-label="Zoom level">
1339
- <span class="dropdown-value">100%</span>
1340
- <span class="dropdown-caret" aria-hidden="true"></span>
1341
- </button>
1342
-
1343
- <ul class="dropdown-menu" data-role="zoom-menu" role="listbox"
1344
- aria-label="Zoom level" hidden>
1345
- <li class="dropdown-item" role="option" tabindex="-1" data-value="fit">Fit width</li>
1346
- <li class="dropdown-item" role="option" tabindex="-1" data-value="0.5">50%</li>
1347
- <li class="dropdown-item" role="option" tabindex="-1" data-value="0.75">75%</li>
1348
- <li class="dropdown-item" role="option" tabindex="-1" data-value="1"
1349
- data-selected="true">100%</li>
1350
- <li class="dropdown-item" role="option" tabindex="-1" data-value="1.25">125%</li>
1351
- <li class="dropdown-item" role="option" tabindex="-1" data-value="1.5">150%</li>
1352
- <li class="dropdown-item" role="option" tabindex="-1" data-value="2">200%</li>
1353
- <li class="dropdown-item" role="option" tabindex="-1" data-value="3">300%</li>
1354
- </ul>
1355
- </div>
1356
-
1357
- <button type="button" data-role="zoom-in" title="Zoom in (ctrl++)"
1358
- aria-label="Zoom in">&#43;</button>
1359
- </div>
1360
- </div>
1361
-
1362
- <div class="toolbar-group toolbar-save">
1363
- <button type="button" data-role="print" title="Print or save as PDF (ctrl+P)">
1364
- Print</button>
1365
- <button type="button" data-role="export" title="Export the report (ctrl+X)">
1366
- Export&#8230;</button>
1367
- </div>
1368
- </div>
1369
- </header>
1370
-
1371
- <div class="viewport" data-role="viewport"></div>
1372
-
1373
- <!-- paging floats over the report rather than taking a strip of it -->
1374
- <div class="pager" data-role="pager" role="toolbar" aria-label="Page navigation">
1375
- <button type="button" data-role="prev" title="Previous page (left arrow)"
1376
- aria-label="Previous page">&#8249;</button>
1377
-
1378
- <label class="page-of">
1379
- <input type="number" data-role="current" min="1" value="1" aria-label="Current page">
1380
- <span>of</span>
1381
- <span data-role="total">1</span>
1382
- </label>
1383
-
1384
- <button type="button" data-role="next" title="Next page (right arrow)"
1385
- aria-label="Next page">&#8250;</button>
1386
- </div>
1387
-
1388
-
1389
-
1390
- <!--
1391
- Hand-written rather than a <dialog>: the element is still unimplemented
1392
- in the environment the specs run in, and a stubbed showModal would test
1393
- the stub instead of the behaviour.
1394
- -->
1395
- <div class="modal" data-role="export-modal" hidden>
1396
- <div class="modal-backdrop" data-role="export-backdrop"></div>
1397
-
1398
- <div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="export-title">
1399
- <h2 id="export-title">Export report</h2>
1400
-
1401
- <div class="modal-formats" role="radiogroup" aria-labelledby="export-title">
1402
- <label class="format">
1403
- <input type="radio" name="export-format" value="pdf" checked>
1404
- <span class="format-body">
1405
- <span class="format-name">PDF</span>
1406
- <span class="format-note">Opens the print dialog - choose "Save as PDF"</span>
1407
- </span>
1408
- </label>
1409
-
1410
- <label class="format">
1411
- <input type="radio" name="export-format" value="csv">
1412
- <span class="format-body">
1413
- <span class="format-name">CSV</span>
1414
- <span class="format-note">Every text line and table row, in report order</span>
1415
- </span>
1416
- </label>
1417
- </div>
1418
-
1419
- <p class="modal-summary" data-role="export-summary" aria-live="polite"></p>
1420
-
1421
- <div class="modal-actions">
1422
- <button type="button" data-role="export-cancel">Cancel</button>
1423
- <button type="button" class="is-primary" data-role="export-confirm">Export</button>
1424
- </div>
1425
- </div>
1426
- </div>
1427
- `;
1428
- }
1429
- //#endregion
1430
- //#region src/preview/viewer.js
1431
- var Z = [
1432
- .5,
1433
- .75,
1434
- 1,
1435
- 1.25,
1436
- 1.5,
1437
- 2,
1438
- 3
1439
- ], Q = Z[0], $ = Z[Z.length - 1];
1440
- function Jt({ paginated: e, title: t, width: n, height: r, features: i, ...a } = {}) {
1441
- let o = Wt({
1442
- title: t ?? "Report",
1443
- width: n,
1444
- height: r,
1445
- features: i
1446
- });
1447
- if (!o) return null;
1448
- let s = Yt({
1449
- ...a,
1450
- mount: o.mount,
1451
- paginated: e,
1452
- title: t
1453
- }), c = Gt(globalThis, o.window, s.destroy);
1454
- return {
1455
- ...s,
1456
- window: o.window,
1457
- destroy() {
1458
- c(), s.destroy(), o.close();
1459
- }
1460
- };
1461
- }
1462
- function Yt({ mount: e, paginated: t, title: n } = {}) {
1463
- let r = typeof e == "string" ? document.querySelector(e) : e;
1464
- if (!r) throw Error(`createViewer: no element for mount ${JSON.stringify(e)}. Add <div id="report"></div> to the page first.`);
1465
- let i = r.ownerDocument, a = i.defaultView ?? globalThis;
1466
- if (!t?.pages) throw Error("createViewer: paginated must be a buildPages(layout, data) result.");
1467
- r.classList.add("report-viewer"), r.innerHTML = qt({ title: n });
1468
- let o = r.querySelector("[data-role=\"viewport\"]");
1469
- o.innerHTML = Rt(t);
1470
- let s = [...o.querySelectorAll(".page")], c = s.length, l = o.querySelector("#main-page"), u = o, d = r.querySelector("[data-role=\"export-modal\"]"), f = (e) => r.querySelector(`[data-role="${e}"]`), p = {
1471
- prev: f("prev"),
1472
- next: f("next"),
1473
- current: f("current"),
1474
- total: f("total"),
1475
- zoom: Kt(f("zoom-dropdown")),
1476
- zoomIn: f("zoom-in"),
1477
- zoomOut: f("zoom-out"),
1478
- print: f("print"),
1479
- exportOpen: f("export"),
1480
- query: f("query"),
1481
- hits: f("hits"),
1482
- hitPrev: f("hit-prev"),
1483
- hitNext: f("hit-next")
1484
- }, m = d ? {
1485
- root: d,
1486
- card: d.querySelector(".modal-card"),
1487
- backdrop: d.querySelector("[data-role=\"export-backdrop\"]"),
1488
- summary: d.querySelector("[data-role=\"export-summary\"]"),
1489
- cancel: d.querySelector("[data-role=\"export-cancel\"]"),
1490
- confirm: d.querySelector("[data-role=\"export-confirm\"]"),
1491
- formats: [...d.querySelectorAll("input[name=\"export-format\"]")]
1492
- } : null, h = 0, g = [], _ = -1, v = 1, y = !1, b = null, x = a.onafterprint !== void 0;
1493
- p.total.textContent = String(c), p.current.max = String(c);
1494
- function S(e) {
1495
- h = Math.min(Math.max(e, 0), c - 1), s.forEach((e, t) => e.classList.toggle("is-current", t === h)), p.current.value = String(h + 1), p.prev.disabled = h === 0, p.next.disabled = h === c - 1, V(), u.scrollTo?.({ top: 0 });
1496
- }
1497
- function C() {
1498
- if (u.style.setProperty("--zoom", String(v)), l && (l.style.width = `${t.page.width * v}px`, l.style.height = `${t.page.height * v}px`), !y) {
1499
- let e = Z.find((e) => Math.abs(e - v) < 1e-9);
1500
- p.zoom.value = e === void 0 ? "fit" : String(e);
1501
- }
1502
- p.zoomOut.disabled = !y && v <= Q, p.zoomIn.disabled = !y && v >= $;
1503
- }
1504
- function w(e) {
1505
- y = !1, v = Math.min(Math.max(e, Q), $), C();
1506
- }
1507
- function T() {
1508
- y = !0, p.zoom.value = "fit";
1509
- let e = u.clientWidth - 48;
1510
- e > 0 && (v = Math.min(Math.max(e / t.page.width, Q), $)), C();
1511
- }
1512
- function E(e) {
1513
- let t = v;
1514
- w((e > 0 ? Z.find((e) => e > t + 1e-9) : [...Z].reverse().find((e) => e < t - 1e-9)) ?? t);
1515
- }
1516
- let D = {
1517
- pdf: {
1518
- available: () => !0,
1519
- summary: () => `${c} page${c === 1 ? "" : "s"}, ${t.page.width}×${t.page.height}px each.`,
1520
- run: () => O()
1521
- },
1522
- csv: {
1523
- available: () => it(t.pages) !== "",
1524
- summary: () => D.csv.available() ? `Downloads ${lt(t, "csv")}.` : "This report has nothing to write out.",
1525
- run: () => j()
1526
- }
1527
- };
1528
- function O() {
1529
- let e = [...o.querySelectorAll("img")].filter((e) => !e.complete);
1530
- if (e.length > 0) {
1531
- Promise.all(e.map((e) => e.decode().catch(() => {}))).then(k);
1532
- return;
1533
- }
1534
- k();
1535
- }
1536
- function k() {
1537
- B(), a.print(), x || A();
1538
- }
1539
- function A() {
1540
- p.query.value.trim() !== "" && V();
1541
- }
1542
- function ee() {
1543
- let { width: e, height: n } = t.page, r = i.getElementById("report-page-size");
1544
- r || (r = i.createElement("style"), r.id = "report-page-size", i.head.appendChild(r)), r.textContent = `@page { size: ${e}px ${n}px; margin: 0; }`;
1545
- }
1546
- function j() {
1547
- let e = it(t.pages);
1548
- return e === "" ? !1 : (te(new Blob(["", e], { type: "text/csv;charset=utf-8" }), lt(t, "csv")), !0);
1549
- }
1550
- function te(e, t) {
1551
- let n = URL.createObjectURL(e), r = i.createElement("a");
1552
- r.href = n, r.download = t, i.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(n), 0);
1553
- }
1554
- function M() {
1555
- return m?.formats.find((e) => e.checked)?.value ?? "pdf";
1556
- }
1557
- function N() {
1558
- if (!m) return;
1559
- for (let e of m.formats) {
1560
- let t = D[e.value];
1561
- e.disabled = !t || !t.available(), e.closest(".format")?.classList.toggle("is-unavailable", e.disabled);
1562
- }
1563
- if (m.formats.find((e) => e.checked)?.disabled) {
1564
- let e = m.formats.find((e) => !e.disabled);
1565
- e && (e.checked = !0);
1566
- }
1567
- let e = D[M()];
1568
- m.summary.textContent = e ? e.summary() : "", m.confirm.disabled = !e || !e.available();
1569
- }
1570
- function P() {
1571
- m && (b = i.activeElement, m.root.hidden = !1, N(), (m.formats.find((e) => e.checked && !e.disabled) ?? m.formats.find((e) => !e.disabled) ?? m.cancel).focus());
1572
- }
1573
- function F() {
1574
- !m || m.root.hidden || (m.root.hidden = !0, b?.focus?.(), b = null);
1575
- }
1576
- function I() {
1577
- let e = D[M()];
1578
- e?.available() && (F(), e.run());
1579
- }
1580
- function ne(e) {
1581
- let t = [...m.card.querySelectorAll("button, input")].filter((e) => !e.disabled);
1582
- if (!t.length) return;
1583
- let n = t[0], r = t[t.length - 1];
1584
- e.shiftKey && i.activeElement === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && i.activeElement === r && (e.preventDefault(), n.focus());
1585
- }
1586
- function L() {
1587
- let e = p.query.value.trim();
1588
- if (B(), e === "") {
1589
- g = [], _ = -1, p.hits.textContent = "", p.hits.dataset.state = "idle", z();
1590
- return;
1591
- }
1592
- if (g = Xe(t.pages, e), _ = g.length ? 0 : -1, p.hits.dataset.state = g.length ? "found" : "empty", z(), !g.length) {
1593
- p.hits.textContent = "no matches";
1594
- return;
1595
- }
1596
- let n = Ze(t.pages, e).length;
1597
- p.hits.textContent = `${g.length} on ${n} page${n === 1 ? "" : "s"}`, R(0);
1598
- }
1599
- function R(e) {
1600
- if (!g.length) return;
1601
- _ = (e + g.length) % g.length;
1602
- let t = g[_].pageNO - 1;
1603
- t === h ? V() : S(t), p.hits.textContent = `${_ + 1} of ${g.length}`, ie();
1604
- }
1605
- function z() {
1606
- p.hitPrev.disabled = g.length === 0, p.hitNext.disabled = g.length === 0;
1607
- }
1608
- function B() {
1609
- for (let e of u.querySelectorAll("mark.hit")) {
1610
- let t = e.parentNode;
1611
- t.replaceChild(i.createTextNode(e.textContent), e), t.normalize();
1612
- }
1613
- }
1614
- function V() {
1615
- B();
1616
- let e = p.query.value.trim();
1617
- if (e === "") return;
1618
- let t = s[h];
1619
- if (!t) return;
1620
- let n = e.toLowerCase(), r = i.createTreeWalker(t, NodeFilter.SHOW_TEXT), a = [];
1621
- for (; r.nextNode();) {
1622
- let e = r.currentNode;
1623
- e.nodeValue.toLowerCase().includes(n) && a.push(e);
1624
- }
1625
- for (let e of a) re(e, n);
1626
- }
1627
- function re(e, t) {
1628
- let n = e.nodeValue, r = i.createDocumentFragment(), a = 0;
1629
- for (;;) {
1630
- let e = n.toLowerCase().indexOf(t, a);
1631
- if (e === -1) break;
1632
- e > a && r.appendChild(i.createTextNode(n.slice(a, e)));
1633
- let o = i.createElement("mark");
1634
- o.className = "hit", o.textContent = n.slice(e, e + t.length), r.appendChild(o), a = e + t.length;
1635
- }
1636
- a < n.length && r.appendChild(i.createTextNode(n.slice(a))), e.parentNode.replaceChild(r, e);
1637
- }
1638
- function ie() {
1639
- let e = [...u.querySelectorAll("mark.hit")];
1640
- if (!e.length) return;
1641
- let t = g.filter((e) => e.pageNO === h + 1).indexOf(g[_]), n = e[Math.max(t, 0)] ?? e[0];
1642
- e.forEach((e) => e.classList.remove("is-focused")), n.classList.add("is-focused"), n.scrollIntoView?.({
1643
- block: "center",
1644
- behavior: "smooth"
1645
- });
1646
- }
1647
- if (p.prev.addEventListener("click", () => S(h - 1)), p.next.addEventListener("click", () => S(h + 1)), p.current.addEventListener("change", () => {
1648
- let e = Number(p.current.value);
1649
- Number.isFinite(e) ? S(e - 1) : p.current.value = String(h + 1);
1650
- }), p.print?.addEventListener("click", O), p.exportOpen.addEventListener("click", P), m) {
1651
- m.cancel.addEventListener("click", F), m.backdrop.addEventListener("click", F), m.confirm.addEventListener("click", I);
1652
- for (let e of m.formats) e.addEventListener("change", N);
1653
- m.root.addEventListener("keydown", (e) => {
1654
- e.key === "Tab" && ne(e), e.key === "Enter" && (e.preventDefault(), I());
1655
- });
1656
- }
1657
- p.zoomIn.addEventListener("click", () => E(1)), p.zoomOut.addEventListener("click", () => E(-1)), p.zoom.addEventListener("change", () => {
1658
- p.zoom.value === "fit" ? T() : w(Number(p.zoom.value));
1659
- });
1660
- let H = () => {
1661
- y && T();
1662
- };
1663
- a.addEventListener("resize", H), p.hitPrev.addEventListener("click", () => R(_ - 1)), p.hitNext.addEventListener("click", () => R(_ + 1));
1664
- let U;
1665
- p.query.addEventListener("input", () => {
1666
- clearTimeout(U), U = setTimeout(L, 150);
1667
- }), p.query.addEventListener("keydown", (e) => {
1668
- e.key === "Enter" && (e.preventDefault(), g.length ? R(_ + (e.shiftKey ? -1 : 1)) : L());
1669
- });
1670
- let W = (e) => {
1671
- if (m && !m.root.hidden) {
1672
- e.key === "Escape" && (e.preventDefault(), F());
1673
- return;
1674
- }
1675
- if ((e.ctrlKey || e.metaKey) && ["k", "f"].includes(e.key.toLowerCase())) {
1676
- e.preventDefault(), p.query.focus(), p.query.select();
1677
- return;
1678
- }
1679
- if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "p") {
1680
- e.preventDefault(), O();
1681
- return;
1682
- }
1683
- if (!(e.target === p.query || e.target === p.current)) {
1684
- if ((e.ctrlKey || e.metaKey) && ["x", "s"].includes(e.key.toLowerCase())) {
1685
- e.preventDefault(), P();
1686
- return;
1687
- }
1688
- (e.key === "ArrowRight" || e.key === "PageDown") && S(h + 1), (e.key === "ArrowLeft" || e.key === "PageUp") && S(h - 1), e.key === "Home" && S(0), e.key === "End" && S(c - 1), (e.ctrlKey || e.metaKey) && ((e.key === "+" || e.key === "=") && (e.preventDefault(), E(1)), e.key === "-" && (e.preventDefault(), E(-1)), e.key === "0" && (e.preventDefault(), w(1)));
1689
- }
1690
- };
1691
- i.addEventListener("keydown", W), x && a.addEventListener("afterprint", A);
1692
- function ae() {
1693
- p.zoom.destroy(), i.removeEventListener("keydown", W), a.removeEventListener("resize", H), a.removeEventListener("afterprint", A), r.innerHTML = "", r.classList.remove("report-viewer");
1694
- }
1695
- return ee(), C(), S(0), z(), {
1696
- show: S,
1697
- next: () => S(h + 1),
1698
- prev: () => S(h - 1),
1699
- find: (e) => {
1700
- p.query.value = e, L();
1701
- },
1702
- print: O,
1703
- downloadCSV: j,
1704
- openExport: P,
1705
- closeExport: F,
1706
- confirmExport: I,
1707
- destroy: ae,
1708
- get exportOpen() {
1709
- return m ? !m.root.hidden : !1;
1710
- },
1711
- setZoom: w,
1712
- zoomIn: () => E(1),
1713
- zoomOut: () => E(-1),
1714
- fitWidth: T,
1715
- get zoom() {
1716
- return v;
1717
- },
1718
- get page() {
1719
- return h + 1;
1720
- },
1721
- get pageCount() {
1722
- return c;
1723
- }
1724
- };
1725
- }
1726
- //#endregion
1727
- export { x as A, he as C, le as D, ce as E, p as F, t as I, r as L, i as M, d as N, F as O, m as P, Fe as S, se as T, it as _, Jt as a, Re as b, Wt as c, xt as d, ht as f, rt as g, ut as h, Yt as i, S as j, I as k, Rt as l, lt as m, Q as n, Kt as o, mt as p, Z as r, Gt as s, $ as t, X as u, Xe as v, oe as w, G as x, Ze as y };