@agile-team/mach-report 2.9.1 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +11 -7
  2. package/dist/ExcelBindingWizard-CjIiVox-.cjs +1 -0
  3. package/dist/ExcelBindingWizard-Dxm-K5HL.js +1240 -0
  4. package/dist/ParamEditor-D-Hf5xfO.cjs +1 -0
  5. package/dist/ParamEditor-DRGxzxeO.js +381 -0
  6. package/dist/ReportBatchPanel-BYgg0EDB.cjs +1 -0
  7. package/dist/ReportBatchPanel-Bby5yLzU.js +287 -0
  8. package/dist/ReportPreview-DWXROHBP.cjs +6 -0
  9. package/dist/ReportPreview-DiNXhQI0.js +4138 -0
  10. package/dist/ReportTemplateLibrary-C6CO7YCT.cjs +1 -0
  11. package/dist/ReportTemplateLibrary-DfzDXRvr.js +260 -0
  12. package/dist/RuleEditor-C2QsOHOs.cjs +1 -0
  13. package/dist/RuleEditor-D9wQHrkf.js +2024 -0
  14. package/dist/TemplateReviewPanel-BKofGrV9.js +222 -0
  15. package/dist/TemplateReviewPanel-DwtOcLue.cjs +1 -0
  16. package/dist/analytics.cjs +1 -1
  17. package/dist/analytics.d.cts +4 -0
  18. package/dist/analytics.d.ts +4 -0
  19. package/dist/analytics.js +40 -39
  20. package/dist/{assets-ahTRUXRk.cjs → assets-Bu6UohJx.cjs} +1 -1
  21. package/dist/{assets-DDsfEi8R.js → assets-DegqDNqY.js} +1 -1
  22. package/dist/batch-Bt3Fd27Z.cjs +1 -0
  23. package/dist/batch-mRqhhhjt.js +364 -0
  24. package/dist/{capabilities-Cm9hZ3uV.js → capabilities-CK_7hizc.js} +16 -16
  25. package/dist/capabilities-CsZ-pNHR.cjs +1 -0
  26. package/dist/computed-Bvk0W15F.js +521 -0
  27. package/dist/computed-CGV2a809.cjs +1 -0
  28. package/dist/config-B612mw0x.js +525 -0
  29. package/dist/config-BRoLo2oj.cjs +1 -0
  30. package/dist/designer.cjs +2 -2
  31. package/dist/designer.d.cts +695 -50
  32. package/dist/designer.d.ts +695 -50
  33. package/dist/designer.js +2213 -1748
  34. package/dist/index.cjs +8 -8
  35. package/dist/index.d.cts +205 -6
  36. package/dist/index.d.ts +205 -6
  37. package/dist/index.js +808 -1033
  38. package/dist/injection-keys-Db_DyLkm.cjs +1 -0
  39. package/dist/injection-keys-e85udZCp.js +7 -0
  40. package/dist/list-cell-BuYn4tGF.cjs +1 -0
  41. package/dist/list-cell-ClFra1zS.js +173 -0
  42. package/dist/matrix-DVyWiYsd.cjs +1 -0
  43. package/dist/matrix-yZsGnldA.js +227 -0
  44. package/dist/param-validation-BlHHXs6u.js +153 -0
  45. package/dist/param-validation-DCK039V1.cjs +1 -0
  46. package/dist/pdf.cjs +49 -49
  47. package/dist/pdf.d.cts +31 -1
  48. package/dist/pdf.d.ts +31 -1
  49. package/dist/pdf.js +4797 -4650
  50. package/dist/plugin-BDTU4D94.cjs +1 -0
  51. package/dist/plugin-Cd5G2QQn.js +22 -0
  52. package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
  53. package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
  54. package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
  55. package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
  56. package/dist/server/node.d.cts +48 -5
  57. package/dist/server/node.d.ts +48 -5
  58. package/dist/server-node.cjs +1 -1
  59. package/dist/server-node.js +503 -317
  60. package/dist/server.cjs +1 -1
  61. package/dist/server.d.cts +252 -4
  62. package/dist/server.d.ts +252 -4
  63. package/dist/server.js +567 -469
  64. package/dist/style.css +1 -1
  65. package/dist/template-registry-WNXdkiET.js +506 -0
  66. package/dist/template-registry-ukBGlm8N.cjs +1 -0
  67. package/dist/template-review-BXp2oyqg.cjs +1 -0
  68. package/dist/template-review-BdcXSYbx.js +1616 -0
  69. package/dist/tree-BX380Rr7.cjs +1 -0
  70. package/dist/tree-CqcQ99NM.js +172 -0
  71. package/dist/useLocalDraft-C07SYRnC.js +11 -0
  72. package/dist/useLocalDraft-Yiw1wFgI.cjs +1 -0
  73. package/dist/{validate-DWPF7icl.js → validate-7s0yn6ii.js} +26 -26
  74. package/dist/validate-DsRiNw8h.cjs +1 -0
  75. package/dist/vue/async.d.cts +118 -6
  76. package/dist/vue/async.d.ts +118 -6
  77. package/dist/vue/index.d.cts +177 -11
  78. package/dist/vue/index.d.ts +177 -11
  79. package/dist/vue-async.cjs +1 -1
  80. package/dist/vue-async.js +5 -5
  81. package/dist/vue.cjs +1 -1
  82. package/dist/vue.js +116 -113
  83. package/dist/{import-template-CNMLJSQw.js → workbook-session-BKOTwcoq.js} +4290 -4227
  84. package/dist/{import-template-CpxunKVp.cjs → workbook-session-CLYLhZWu.cjs} +17 -17
  85. package/dist/worker.cjs +1 -1
  86. package/dist/worker.d.cts +9 -2
  87. package/dist/worker.d.ts +9 -2
  88. package/dist/worker.js +1 -1
  89. package/dist/xlsx.cjs +4 -2
  90. package/dist/xlsx.d.cts +159 -3
  91. package/dist/xlsx.d.ts +159 -3
  92. package/dist/xlsx.js +354 -192
  93. package/package.json +1 -1
  94. package/dist/ExcelBindingWizard-DiaxvWpQ.cjs +0 -1
  95. package/dist/ExcelBindingWizard-RLJIXKKG.js +0 -816
  96. package/dist/ReportPreview-B5ZNEasW.js +0 -4439
  97. package/dist/ReportPreview-DRtVPUYo.cjs +0 -6
  98. package/dist/RuleEditor-CskN5Fr3.cjs +0 -1
  99. package/dist/RuleEditor-CtJFzKuY.js +0 -1578
  100. package/dist/TemplateReviewPanel-C_Lmzis6.cjs +0 -1
  101. package/dist/TemplateReviewPanel-Cn32OY4_.js +0 -173
  102. package/dist/binding-preview-B5834rml.cjs +0 -2
  103. package/dist/binding-preview-ChXjN5L5.js +0 -649
  104. package/dist/capabilities-DYzWL7KS.cjs +0 -1
  105. package/dist/matrix-CNPDJxED.js +0 -745
  106. package/dist/matrix-Div9Ilh3.cjs +0 -1
  107. package/dist/param-validation-BWNjLcN0.js +0 -116
  108. package/dist/param-validation-CiTxFeZ8.cjs +0 -1
  109. package/dist/plugin-BWwIgZXV.js +0 -25
  110. package/dist/plugin-Dg-J1Rbm.cjs +0 -1
  111. package/dist/template-registry-CHMYZ7SD.cjs +0 -1
  112. package/dist/template-registry-R61AMCr0.js +0 -433
  113. package/dist/template-review-hvWWQFsi.js +0 -1027
  114. package/dist/template-review-jEcOfmGr.cjs +0 -1
  115. package/dist/validate-BDiMqkJC.cjs +0 -1
@@ -1,1027 +0,0 @@
1
- import { R as le } from "./render-plan-Ck6koX9L.js";
2
- import { c as Re } from "./validate-DWPF7icl.js";
3
- import { g as Ce } from "./report-params-B_VCihAh.js";
4
- import { v as Fe, a as Ne, p as V } from "./template-registry-R61AMCr0.js";
5
- import { a as te } from "./param-validation-BWNjLcN0.js";
6
- import { c as He } from "./task-events-Dpsvf_t2.js";
7
- import { v as de } from "./dataset-H5pFuQGU.js";
8
- import { c as Oe, D as ue, L as me } from "./defaults-DXhiM1ZD.js";
9
- import { h as We, w as J } from "./textwrap-DE1kgcJB.js";
10
- import { c as De, p as re, k as ne, d as fe, j as Be, b as Le, g as je } from "./matrix-CNPDJxED.js";
11
- import { e as E, r as ge } from "./style-CQ1PK8ZB.js";
12
- import { i as Ie } from "./capabilities-Cm9hZ3uV.js";
13
- function he(e) {
14
- if (!e || e.kind === "date") return;
15
- const t = e.digits;
16
- if (!(t !== void 0 && (!Number.isInteger(t) || t < 0 || t > 100))) {
17
- if (e.kind === "percent") {
18
- const r = t ?? 2;
19
- return `0${r ? `.${"0".repeat(r)}` : ""}%`;
20
- }
21
- return t === void 0 ? e.thousands ? "#,##0.###############" : void 0 : `${e.thousands ? "#,##0" : "0"}${t ? `.${"0".repeat(t)}` : ""}`;
22
- }
23
- }
24
- function Ge(e) {
25
- const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
26
- if (t) {
27
- const n = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
28
- return Number.isNaN(n.getTime()) ? null : n;
29
- }
30
- const r = new Date(e);
31
- return Number.isNaN(r.getTime()) ? null : r;
32
- }
33
- function q(e, t) {
34
- return e.toLocaleString("en-US", {
35
- minimumFractionDigits: t,
36
- maximumFractionDigits: t
37
- });
38
- }
39
- function Ke(e, t) {
40
- const r = (n) => String(n).padStart(2, "0");
41
- return t.replace(/YYYY/g, String(e.getFullYear())).replace(/MM/g, r(e.getMonth() + 1)).replace(/DD/g, r(e.getDate())).replace(/hh/g, r(e.getHours())).replace(/mm/g, r(e.getMinutes())).replace(/ss/g, r(e.getSeconds()));
42
- }
43
- function Ve(e, t, r) {
44
- return r != null ? t ? q(e, r) : e.toFixed(r) : t ? q(e) : String(e);
45
- }
46
- function ae(e) {
47
- const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
48
- return Number.isFinite(t) ? t : null;
49
- }
50
- function pe(e, t) {
51
- if (e == null || e === "" || !t) return String(e ?? "");
52
- switch (t.kind) {
53
- case "number": {
54
- if (typeof e == "string")
55
- try {
56
- return ne(e, t.digits, t.thousands === !0);
57
- } catch {
58
- return e;
59
- }
60
- const r = ae(e);
61
- return r == null ? String(e) : Ve(r, t.thousands === !0, t.digits);
62
- }
63
- case "percent": {
64
- if (typeof e == "string")
65
- try {
66
- return ne(e, t.digits ?? 2, !0, !0);
67
- } catch {
68
- return e;
69
- }
70
- const r = ae(e);
71
- return r == null ? String(e) : `${q(r * 100, t.digits ?? 2)}%`;
72
- }
73
- case "date": {
74
- const r = t.pattern ?? "YYYY-MM-DD", n = e instanceof Date ? e : Ge(String(e));
75
- return n ? Ke(n, r) : String(e);
76
- }
77
- default:
78
- return String(e);
79
- }
80
- }
81
- function H(e, t) {
82
- const r = e[t.field];
83
- if (r == null || r === "") return !1;
84
- if (typeof t.value == "number" || t.numeric !== void 0) {
85
- let o;
86
- try {
87
- o = De(re(r), re(t.value));
88
- } catch {
89
- return !1;
90
- }
91
- if (!Number.isFinite(o)) return !1;
92
- switch (t.op) {
93
- case ">":
94
- return o > 0;
95
- case ">=":
96
- return o >= 0;
97
- case "<":
98
- return o < 0;
99
- case "<=":
100
- return o <= 0;
101
- case "==":
102
- return o === 0;
103
- case "!=":
104
- return o !== 0;
105
- }
106
- }
107
- const n = String(r), a = String(t.value);
108
- switch (t.op) {
109
- case "==":
110
- return n === a;
111
- case "!=":
112
- return n !== a;
113
- case ">":
114
- return n > a;
115
- case ">=":
116
- return n >= a;
117
- case "<":
118
- return n < a;
119
- case "<=":
120
- return n <= a;
121
- }
122
- return !1;
123
- }
124
- function qe(e, t, r) {
125
- const n = /* @__PURE__ */ new Set(), a = e.cells.map((o, s) => {
126
- const i = [];
127
- let c = 0;
128
- for (const l of o) {
129
- for (; n.has(`${s}:${c}`); ) c++;
130
- const d = l?.colSpan ?? 1, g = l?.rowSpan ?? 1;
131
- let f = 0;
132
- for (let h = c; h < c + d; h++) {
133
- t.has(h) && f++;
134
- for (let p = s + 1; p < s + g; p++)
135
- n.add(`${p}:${h}`);
136
- }
137
- f && i.push(l ? { ...l, colSpan: f } : null), c += d;
138
- }
139
- return i;
140
- });
141
- return { ...e, cells: a, colWidthsMm: r };
142
- }
143
- function ze(e) {
144
- if (!e.columns.some((n) => n.hidden)) return e;
145
- const t = /* @__PURE__ */ new Set(), r = e.columns.filter((n, a) => n.hidden ? !1 : (t.add(a), !0));
146
- if (!r.length) throw new Error("列表至少需要一列可见列");
147
- return {
148
- ...e,
149
- columns: r,
150
- ...e.headerGrid ? {
151
- headerGrid: qe(
152
- e.headerGrid,
153
- t,
154
- r.map((n) => n.widthMm)
155
- )
156
- } : {}
157
- };
158
- }
159
- class W extends Error {
160
- constructor(t, r) {
161
- super(`报表页数超出上限 ${t}(至少 ${r} 页)`), this.limit = t, this.actual = r, this.code = "page-limit", this.name = "PaginatePageLimitError";
162
- }
163
- }
164
- class D extends Error {
165
- constructor(t, r) {
166
- super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`), this.limit = t, this.actual = r, this.code = "cell-limit", this.name = "PaginateCellLimitError";
167
- }
168
- }
169
- function _e(e) {
170
- return {
171
- widthMm: e.widthMm,
172
- heightMm: e.heightMm,
173
- marginTopMm: e.marginTopMm ?? 0,
174
- marginBottomMm: e.marginBottomMm ?? 0,
175
- marginLeftMm: e.marginLeftMm ?? 0,
176
- marginRightMm: e.marginRightMm ?? 0,
177
- components: []
178
- };
179
- }
180
- function oe(e, t) {
181
- const r = t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
182
- return e.components.reduce((n, a) => a.kind !== "list" && a.pageAnchor === "footer" ? Math.min(n, a.topMm) : n, r);
183
- }
184
- function se(e) {
185
- return e.components.reduce((t, r) => r.kind !== "list" && r.pageAnchor === "header" ? Math.max(t, r.topMm + r.heightMm) : t, 0);
186
- }
187
- function U(e) {
188
- if (e == null) return "";
189
- if (typeof e == "string") return e;
190
- if (typeof e == "number") return String(e);
191
- if (typeof e == "boolean") return e ? "是" : "否";
192
- if (e instanceof Date) return e.toISOString().slice(0, 10);
193
- try {
194
- return JSON.stringify(e);
195
- } catch {
196
- return String(e);
197
- }
198
- }
199
- function ye(e, t) {
200
- let r = e.textMetrics.get(t);
201
- if (!r) {
202
- const n = ge(t).fontSizePt;
203
- r = {
204
- measureOptions: {
205
- fontSizePt: n,
206
- fontFamily: t.fontFamily ?? ue,
207
- italic: t.italic,
208
- bold: t.bold,
209
- letterSpacingPt: t.letterSpacing
210
- },
211
- lineMm: n * (t.lineHeight ?? me) * 25.4 / 72
212
- }, e.textMetrics.set(t, r);
213
- }
214
- return r;
215
- }
216
- function we(e, t, r) {
217
- return r === "identifier" || r === "dimension" || r === "date" ? "center" : r === "measure" ? "right" : r === "text" ? "left" : t?.kind === "number" || t?.kind === "percent" ? "right" : t?.kind === "date" || e instanceof Date || typeof e == "boolean" ? "center" : typeof e == "number" && Number.isFinite(e) ? "right" : "left";
218
- }
219
- function Ye(e) {
220
- if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
221
- }
222
- function Me(e, t) {
223
- const r = e.fontSizePt ?? Oe, n = e.paddingMm ?? 1, a = e.columns.map((u) => u.align ?? u.style?.align ?? e.align ?? "left"), o = e.columns.map((u, m) => ({
224
- ...E({
225
- fontSize: r,
226
- verticalAlign: "middle"
227
- }, u.style),
228
- align: a[m] === "auto" ? "left" : a[m]
229
- })), s = o.map((u, m) => a[m] === "auto" ? { left: u, center: { ...u, align: "center" }, right: { ...u, align: "right" } } : void 0), i = e.columns.map((u, m) => u.rules?.map((w) => {
230
- const M = s[m];
231
- if (M) return {
232
- left: E(M.left, w.style),
233
- center: E(M.center, w.style),
234
- right: E(M.right, w.style)
235
- };
236
- const $ = E(o[m], w.style);
237
- return { left: $, center: $, right: $ };
238
- })), c = e.columns.map((u) => {
239
- let m = E({
240
- fontSize: r,
241
- bold: e.headerBold ?? !0,
242
- align: "center",
243
- verticalAlign: "middle",
244
- backgroundColor: e.headerBackgroundColor
245
- }, u.style);
246
- return e.headerAlign !== void 0 && (m.align = e.headerAlign), m = E(m, e.headerStyle), u.headerAlign !== void 0 && (m.align = u.headerAlign), E(m, u.headerStyle);
247
- }), l = e.columns.map((u) => u.header);
248
- let d = e.rowHeightMm ?? 0;
249
- for (let u = 0; u < l.length; u++) {
250
- const m = c[u], w = ge(m).fontSizePt, M = J(
251
- l[u],
252
- e.columns[u].widthMm - n * 2,
253
- { fontSizePt: w, fontFamily: m.fontFamily ?? ue, italic: m.italic, bold: m.bold, letterSpacingPt: m.letterSpacing },
254
- t
255
- ), $ = w * (m.lineHeight ?? me) * 25.4 / 72;
256
- d = Math.max(d, Math.max(M.length, 1) * $ + n * 2);
257
- }
258
- const g = l.map((u, m) => ({
259
- text: u,
260
- style: c[m]
261
- })), f = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, h = e.columns.map((u) => u.widthMm), p = Je(e.headerGrid, h, {
262
- cells: [g],
263
- colWidthsMm: h,
264
- rowHeightsMm: [d],
265
- paddingMm: n
266
- });
267
- return {
268
- fontSizePt: r,
269
- paddingMm: n,
270
- cellStyles: o,
271
- autoStyles: s,
272
- ruleStyles: i,
273
- textMetrics: /* @__PURE__ */ new WeakMap(),
274
- numberFormats: e.columns.map((u) => he(u.format)),
275
- borderStyle: f,
276
- headerHeightMm: p.rowHeightsMm.reduce((u, m) => u + m, 0),
277
- headerGrid: p,
278
- colWidthsMm: h,
279
- columns: e.columns
280
- };
281
- }
282
- function Je(e, t, r) {
283
- if (!e) return r;
284
- if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
285
- const n = e.rowHeightsMm ?? e.cells.map(() => r.rowHeightsMm[0]);
286
- if (n.length !== e.cells.length || n.some((a) => !Number.isFinite(a) || a <= 0)) throw new Error("自定义列表表头行高无效");
287
- return { ...e, colWidthsMm: t, rowHeightsMm: n };
288
- }
289
- function Ue(e, t, r) {
290
- const n = t.format?.kind === "number" || t.format?.kind === "percent";
291
- t.valueType !== void 0 ? e.valueType = t.valueType : n && (e.valueType = "number"), t.editable !== void 0 && (e.editable = t.editable), (typeof e.value == "number" || e.value == null) && r !== void 0 && (e.numberFormat = r);
292
- }
293
- function z(e, t, r) {
294
- const n = e.columns;
295
- let a = e.rowHeightFloorMm;
296
- const o = new Array(n.length);
297
- for (let s = 0; s < n.length; s++) {
298
- const i = n[s], c = i.visibleWhen && !H(t, i.visibleWhen) ? null : t[i.field], l = e.autoStyles[s] ? we(c, i.format, i.semanticRole) : "left";
299
- let d = e.autoStyles[s]?.[l] ?? e.cellStyles[s];
300
- if (i.rules)
301
- for (let m = 0; m < i.rules.length; m++) {
302
- const w = i.rules[m];
303
- if (H(t, w.when)) {
304
- d = e.ruleStyles[s][m][l];
305
- break;
306
- }
307
- }
308
- const g = i.format ? pe(c, i.format) : U(c), f = ye(e, d), h = J(g, i.widthMm - e.paddingMm * 2, f.measureOptions, r);
309
- a = Math.max(a, h.length * f.lineMm + e.paddingMm * 2);
310
- const p = Ye(c), u = { text: g, style: d };
311
- p !== void 0 && (u.value = p), Ue(u, i, e.numberFormats[s]), i.visibleWhen && c === null && !H(t, i.visibleWhen) && (u.editable = !1), o[s] = u;
312
- }
313
- return {
314
- grid: { cells: [o], colWidthsMm: e.colWidthsMm, rowHeightsMm: [a], paddingMm: e.paddingMm },
315
- heightMm: a
316
- };
317
- }
318
- function be(e) {
319
- if (e != null && typeof e != "string" && typeof e != "boolean" && !(typeof e == "number" && Number.isFinite(e))) throw new Error("分组字段应为有限 JSON 标量");
320
- return JSON.stringify([typeof e, e ?? null]);
321
- }
322
- function* $e(e, t, r = 0) {
323
- const n = t[r];
324
- if (!n) {
325
- for (const o of e) yield { kind: "row", row: o };
326
- return;
327
- }
328
- const a = /* @__PURE__ */ new Map();
329
- for (const o of e) {
330
- const s = be(o[n.field]), i = a.get(s);
331
- i ? i.push(o) : a.set(s, [o]);
332
- }
333
- for (const o of a.values())
334
- yield { kind: "groupHeader", label: (n.headerTemplate ?? "{value}").replace(/\{value\}/g, U(o[0][n.field])), firstRow: o[0], group: n, depth: r, rows: o }, yield* $e(o, t, r + 1), (n.subtotal?.length || n.aggregates?.length) && (yield { kind: "subtotal", label: n.subtotalLabel ?? "小计", rows: o, group: n, depth: r }), yield { kind: "groupEnd", depth: r };
335
- }
336
- function Se(e, t, r, n = []) {
337
- const a = [...r.filter((o) => !n.some((s) => s.field === o)).map((o) => ({ field: o, op: "sum" })), ...n];
338
- return new Map(a.map((o) => {
339
- const s = e.find((c) => c.field === o.field)?.format ?? { kind: "number", thousands: !0 }, i = Le(t, { ...o, field: o.valueField ?? o.field });
340
- return [o.field, { text: pe(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: he(s) } : {} }];
341
- }));
342
- }
343
- function ve(e, t) {
344
- const r = e.findIndex((n) => t.includes(n.field));
345
- return r > 0 ? r : 1;
346
- }
347
- function O(e, t, r, n, a, o) {
348
- const s = [], i = Math.max(1, Math.min(o, e.columns.length)), c = E({ fontSize: e.fontSizePt }, a);
349
- s.push({ text: r, colSpan: i, style: { bold: !0, ...c } });
350
- for (let g = i; g < e.columns.length; g++) {
351
- const f = e.columns[g], h = n.get(f.field), p = e.autoStyles[g]?.[we(h?.value, f.format)] ?? e.cellStyles[g];
352
- s.push({ ...h, text: h?.text ?? "", style: E(p, a) });
353
- }
354
- let l = e.rowHeightFloorMm, d = 0;
355
- for (const g of s) {
356
- let f = 0;
357
- const h = d + (g.colSpan ?? 1);
358
- for (; d < h; d++) f += e.colWidthsMm[d] ?? 0;
359
- const p = ye(e, g.style), u = J(g.text ?? "", f - e.paddingMm * 2, p.measureOptions, t);
360
- l = Math.max(l, u.length * p.lineMm + e.paddingMm * 2);
361
- }
362
- return {
363
- grid: { cells: [s], colWidthsMm: e.colWidthsMm, rowHeightsMm: [l], paddingMm: e.paddingMm },
364
- heightMm: l
365
- };
366
- }
367
- function Qe(e, t, r) {
368
- const { templatePage: n, current: a, warnings: o, nextId: s, pushCurrent: i } = r, c = () => oe(n, a), l = Math.max(a.marginTopMm, se(n)), d = n.layout === "wide" ? se(n) : l, g = {
369
- id: r.tableId,
370
- columnKeys: e.columns.map((y) => y.field),
371
- ...e.layout === void 0 ? {} : { layout: e.layout },
372
- ...e.title === void 0 ? {} : { title: e.title }
373
- }, f = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), p = {
374
- kind: "rect",
375
- leftMm: e.leftMm,
376
- topMm: 0,
377
- widthMm: e.widthMm,
378
- heightMm: t.headerHeightMm,
379
- grid: t.headerGrid,
380
- nid: s("listh"),
381
- table: { ...g, role: "header", rowIndex: -1 },
382
- style: t.borderStyle
383
- }, u = (y) => a.components.push({ ...p, topMm: y });
384
- let m = Math.max(e.topMm, l);
385
- u(m), m += t.headerHeightMm + r.mmPerRow;
386
- function w() {
387
- const y = Math.max(n.layout === "wide" ? 0 : e.topMm, d);
388
- return (e.headerEveryPage !== !1 ? y + t.headerHeightMm : d) + [...h.values()].reduce((P, A) => P + A.heightMm, 0);
389
- }
390
- function M() {
391
- const y = n.layout === "wide" ? 0 : a.marginBottomMm;
392
- return Math.min(n.heightMm - y, oe(n, a)) - w();
393
- }
394
- function $(y) {
395
- if (m + y <= c()) return;
396
- i(), a.components = [], a.heightMm = n.heightMm, n.layout === "wide" && (a.marginTopMm = 0, a.marginBottomMm = 0);
397
- const x = Math.max(n.layout === "wide" ? 0 : e.topMm, d);
398
- e.headerEveryPage !== !1 ? (u(x), m = x + t.headerHeightMm) : m = d;
399
- for (const P of h.values()) b(P, "listgr", "group-header");
400
- }
401
- function G(y, x, P, A) {
402
- const F = M();
403
- y.heightMm > F && o.push(`列表 ${e.id ?? e.dataset} 行高 ${y.heightMm.toFixed(2)}mm 超出单页可用高度 ${F.toFixed(2)}mm,预览与打印可能截断内容`), $(y.heightMm), b(y, x, P, A);
404
- }
405
- function b(y, x, P, A) {
406
- const F = y.table?.id ?? g.id, ee = P === "header" ? -1 : f.get(F) ?? 0;
407
- P !== "header" && f.set(F, ee + 1), a.components.push({
408
- kind: "rect",
409
- leftMm: e.leftMm,
410
- topMm: m,
411
- widthMm: e.widthMm,
412
- heightMm: y.heightMm,
413
- grid: y.grid,
414
- nid: s(x),
415
- table: { ...g, ...y.table, role: P, rowIndex: ee, ...A ? { source: A } : {} },
416
- style: t.borderStyle
417
- }), m += y.heightMm;
418
- }
419
- function T(y) {
420
- y <= M() && $(y);
421
- }
422
- return { keepTogether: T, placeGridRow: G, setGroupHeader: (y, x) => {
423
- x ? h.set(y, x) : h.delete(y);
424
- } };
425
- }
426
- function Xe(e, t) {
427
- if (!e.rowKey) return;
428
- const r = t[e.rowKey];
429
- if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r)))
430
- throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
431
- const n = e.revisionField ? t[e.revisionField] : void 0, a = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
432
- if (n !== void 0 && typeof n != "string" && !(typeof n == "number" && Number.isFinite(n))) throw new Error("业务修订号应为字符串或有限数字");
433
- if (a !== void 0 && typeof a != "string") throw new Error("来源令牌应为字符串");
434
- return { datasetId: e.dataset, rowKey: r, ...n === void 0 ? {} : { revision: n }, ...a === void 0 ? {} : { sourceToken: a } };
435
- }
436
- function xe(e, t) {
437
- const r = /* @__PURE__ */ new Map();
438
- if (!e.rowKey) return r;
439
- const n = /* @__PURE__ */ new Set();
440
- for (const a of t) {
441
- const o = Xe(e, a), s = JSON.stringify(o.rowKey);
442
- if (n.has(s)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(o.rowKey)}`);
443
- n.add(s), r.set(a, o);
444
- }
445
- return r;
446
- }
447
- function Ze(e, t, r, n, a) {
448
- if (!e.grandTotal) return;
449
- const o = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = X(e)[0], i = o?.fields ?? s?.subtotal ?? [], c = o?.aggregates ?? s?.aggregates ?? [];
450
- if (i.length === 0 && c.length === 0) {
451
- n.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
452
- return;
453
- }
454
- const l = O(r, n.measurer, o?.label ?? "合计", Se(e.columns, t, i, c), o?.style ?? {}, ve(e.columns, [...i, ...c.map((d) => d.field)]));
455
- a.placeGridRow(l, "listgt", "grand-total");
456
- }
457
- function Q(e) {
458
- if (e?.aborted) {
459
- const t = new Error("报表排版已取消");
460
- throw t.name = "AbortError", t;
461
- }
462
- }
463
- function X(e) {
464
- const t = e.groups ?? (e.groupBy ? [e.groupBy] : []);
465
- if (t.length > 16) throw new Error("列表最多支持 16 级分组");
466
- return t;
467
- }
468
- function Pe(e) {
469
- const t = ze(e), r = t.columns.reduce((a, o) => a + o.widthMm, 0), n = r > t.widthMm ? t.widthMm / r : 1;
470
- return n === 1 ? t : { ...t, columns: t.columns.map((a) => ({ ...a, widthMm: a.widthMm * n })) };
471
- }
472
- function et(e, t, r) {
473
- const n = e.detail;
474
- if (!n) return;
475
- const a = /* @__PURE__ */ new Set();
476
- for (const c of t) {
477
- const l = _(c[n.parentKey]);
478
- if (a.has(l)) throw new Error("主从明细的主表关联键重复");
479
- a.add(l);
480
- }
481
- const o = r.datasets[n.dataset] ?? [], s = /* @__PURE__ */ new Map();
482
- for (const c of o) {
483
- const l = _(c[n.foreignKey]);
484
- if (!a.has(l)) {
485
- if (n.unmatched !== "ignore") throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);
486
- continue;
487
- }
488
- const d = s.get(l);
489
- d ? d.push(c) : s.set(l, [c]);
490
- }
491
- const i = Pe({ ...e, id: `${e.id ?? e.dataset}:detail`, dataset: n.dataset, rowKey: n.rowKey, columns: n.columns, headerGrid: void 0, rowHeightMm: n.rowHeightMm ?? e.rowHeightMm, detail: void 0 });
492
- return { list: i, inter: { ...Me(i, r.measurer), rowHeightFloorMm: i.rowHeightMm ?? 0 }, rows: s, sources: xe(i, o) };
493
- }
494
- function _(e) {
495
- if ((typeof e != "string" || !e.trim()) && !(typeof e == "number" && Number.isFinite(e))) throw new Error("主从关联键必须是非空字符串或有限数字");
496
- return be(e);
497
- }
498
- function* tt(e, t, r, n, a) {
499
- if (!r) return;
500
- const o = r.rows.get(_(t[e.detail.parentKey])) ?? [];
501
- if (!o.length) return;
502
- const s = { id: `${n.tableId}:detail`, columnKeys: r.list.columns.map((i) => i.field), title: e.detail.label };
503
- e.detail.label && a.placeGridRow({ ...O(r.inter, n.measurer, e.detail.label, /* @__PURE__ */ new Map(), {}, r.list.columns.length), table: s }, "listdl", "group-header"), e.detail.header !== !1 && a.placeGridRow({ grid: r.inter.headerGrid, heightMm: r.inter.headerHeightMm, table: s }, "listdh", "header"), yield* n.takePages();
504
- for (const i of o)
505
- Q(n.signal), a.placeGridRow({ ...z(r.inter, i, n.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* n.takePages();
506
- }
507
- function rt(e, t) {
508
- if (!e.matrix) return { list: e, rows: t };
509
- if (e.detail || e.groupBy || e.groups?.length || e.grandTotal) throw new Error("矩阵不能同时配置普通分组、总计或主从明细");
510
- const r = je(t, e.matrix), n = r.columns.map((o, s) => ({ ...o, widthMm: s === 0 ? e.matrix.rowWidthMm ?? 40 : e.matrix.columnWidthMm ?? 28, editable: !1, align: s === 0 ? "center" : "right" })), a = { ...e, columns: n, headerGrid: void 0, rowKey: void 0, revisionField: void 0, sourceTokenField: void 0 };
511
- return e.layout === "wide" && (a.widthMm = n.reduce((o, s) => o + s.widthMm, 0)), { list: a, rows: r.rows };
512
- }
513
- function nt(e, t, r) {
514
- const n = r.prepared.get(e);
515
- if (n) return n;
516
- let a = e.computed?.length ? fe(t, { fields: e.computed, signal: r.signal, formula: r.formula }).rows : t;
517
- e.rowVisibleWhen && (a = a.filter((s) => H(s, e.rowVisibleWhen)));
518
- const o = rt(e, a);
519
- return r.prepared.set(e, o), o;
520
- }
521
- function* at(e, t, r) {
522
- const n = nt(e, t, r), a = n.rows;
523
- e = n.list, e.layout === "wide" && (r.current.widthMm = Math.max(r.current.widthMm, e.leftMm + e.widthMm + r.current.marginRightMm));
524
- const o = xe(e, a), s = Pe(e), i = X(s), c = { ...Me(s, r.measurer), rowHeightFloorMm: s.rowHeightMm ?? 0 }, l = Qe(s, c, r), d = et(s, a, r);
525
- let g;
526
- for (const f of $e(a, i)) {
527
- if (Q(r.signal), f.kind === "row")
528
- l.placeGridRow(g ?? z(c, f.row, r.measurer), "listr", "body", o.get(f.row)), g = void 0, yield* r.takePages(), yield* tt(s, f.row, d, r, l);
529
- else if (f.kind === "groupHeader") {
530
- const h = O(c, r.measurer, f.label, /* @__PURE__ */ new Map(), f.group.headerStyle ?? {}, s.columns.length);
531
- g ??= z(c, f.firstRow, r.measurer);
532
- const p = i.slice(f.depth + 1).reduce((u, m) => u + O(c, r.measurer, (m.headerTemplate ?? "{value}").replace(/\{value\}/g, U(f.firstRow[m.field])), /* @__PURE__ */ new Map(), m.headerStyle ?? {}, s.columns.length).heightMm, 0);
533
- f.group.keepWithNext !== !1 && l.keepTogether(h.heightMm + p + g.heightMm), l.placeGridRow(h, "listg", "group-header"), f.group.repeatHeader && l.setGroupHeader(f.depth, h);
534
- } else if (f.kind === "subtotal") {
535
- const h = f.group.subtotal ?? [], p = f.group.aggregates ?? [], u = O(c, r.measurer, f.label, Se(s.columns, f.rows, h, p), f.group.subtotalStyle ?? {}, ve(s.columns, [...h, ...p.map((m) => m.field)]));
536
- l.placeGridRow(u, "listst", "subtotal");
537
- } else l.setGroupHeader(f.depth);
538
- yield* r.takePages();
539
- }
540
- Ze(s, a, c, r, l), yield* r.takePages();
541
- }
542
- function B(e) {
543
- return e.kind !== "list" && (e.pageAnchor !== void 0 || e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}")));
544
- }
545
- function j(e, t) {
546
- return {
547
- ...e,
548
- ...e.text === void 0 ? {} : { text: t(e.text) },
549
- ...e.lines ? { lines: e.lines.map(t) } : {},
550
- ...e.richParagraphs ? { richParagraphs: e.richParagraphs.map((r) => ({ ...r, segments: r.segments.map((n) => ({ ...n, ...n.text === void 0 ? {} : { text: t(n.text) } })) })) } : {},
551
- ...e.grid ? { grid: { ...e.grid, cells: e.grid.cells.map((r) => r.map((n) => n ? { ...n, ...n.text === void 0 ? {} : { text: t(n.text) }, ...n.children ? { children: n.children.map((a) => j(a, t)) } : {} } : null)) } } : {}
552
- };
553
- }
554
- function ot(e) {
555
- let t = !1;
556
- for (const r of e.pages) for (const n of r.components) B(n) && j(n, (a) => (a.includes("{totalPages}") && (t = !0), a));
557
- return t;
558
- }
559
- function st(e, t, r, n, a, o) {
560
- const s = {
561
- pageWidthMm: t.widthMm,
562
- pageHeightMm: t.heightMm,
563
- ...e.layout === void 0 ? {} : { layout: e.layout },
564
- marginTopMm: t.marginTopMm,
565
- marginBottomMm: t.marginBottomMm,
566
- marginLeftMm: t.marginLeftMm,
567
- marginRightMm: t.marginRightMm,
568
- components: t.components
569
- }, i = (c) => {
570
- const l = c.replace(/\{page\}/g, String(n));
571
- return o === void 0 ? l : l.replace(/\{totalPages\}/g, String(o));
572
- };
573
- for (const c of r) s.components.push(j(c, i));
574
- if (e.layout === "wide") {
575
- const c = s.components.reduce((l, d) => Math.max(l, d.topMm + d.heightMm), 0);
576
- s.marginBottomMm = a ? e.marginBottomMm ?? 0 : 0, s.pageHeightMm = Math.max(1, c + s.marginBottomMm);
577
- }
578
- return s;
579
- }
580
- function ke(e) {
581
- return e.cells.reduce((t, r) => t + r.reduce((n, a) => n + (a ? 1 + (a.children?.reduce((o, s) => o + Te(s), 0) ?? 0) : 0), 0), 0);
582
- }
583
- function Te(e) {
584
- return e.grid ? ke(e.grid) : 0;
585
- }
586
- function Z(e) {
587
- for (const t of ["maxPages", "maxCells", "knownTotalPages"]) if (e[t] !== void 0 && (!Number.isSafeInteger(e[t]) || e[t] < 1)) throw new RangeError(`${t} 应为正安全整数`);
588
- }
589
- function* L(e, t, r, n, a, o = /* @__PURE__ */ new WeakMap()) {
590
- let s = 0, i = 0, c = 0;
591
- const l = (d) => `${d}_${(++s).toString(36)}`;
592
- for (const [d, g] of e.pages.entries()) {
593
- Q(r.signal);
594
- const f = _e(g), h = g.components.filter(B);
595
- let p = [];
596
- const u = (w = !1) => {
597
- if (r.maxPages !== void 0 && i >= r.maxPages) throw new W(r.maxPages, i + 1);
598
- if (r.maxCells !== void 0 && (c += [...f.components, ...h].reduce((M, $) => M + Te($), 0), c > r.maxCells))
599
- throw new D(r.maxCells, c);
600
- p.push(st(g, f, h, ++i, w, a));
601
- }, m = () => {
602
- const w = p;
603
- return p = [], w;
604
- };
605
- for (const [w, M] of g.components.entries()) {
606
- if (B(M)) continue;
607
- if (M.kind !== "list") {
608
- f.components.push(M);
609
- continue;
610
- }
611
- const $ = t[M.dataset];
612
- Array.isArray($) || n.push(`数据集 ${M.dataset} 未提供数据,列表 ${M.id ?? ""} 输出为空`), yield* at(M, Array.isArray($) ? $ : [], {
613
- templatePage: g,
614
- current: f,
615
- warnings: n,
616
- nextId: l,
617
- pushCurrent: u,
618
- takePages: m,
619
- datasets: t,
620
- signal: r.signal,
621
- formula: r.formula,
622
- prepared: o,
623
- measurer: r.measurer ?? We,
624
- mmPerRow: r.mmPerRow ?? 0,
625
- tableId: `table:${d}:${w}`
626
- });
627
- }
628
- u(!0), yield* m();
629
- }
630
- }
631
- function Wt(e, t, r = {}) {
632
- Z(r);
633
- let n = 0;
634
- for (const a of L(e, t, { ...r }, [])) n++;
635
- return n;
636
- }
637
- function* Dt(e, t, r = {}) {
638
- Z(r);
639
- const n = ot(e), a = /* @__PURE__ */ new WeakMap();
640
- let o = r.knownTotalPages;
641
- if (n && o === void 0) {
642
- o = 0;
643
- for (const c of L(e, t, r, [], void 0, a)) o++;
644
- }
645
- const s = [];
646
- let i = 0;
647
- for (const c of L(e, t, r, s, o, a)) {
648
- for (; i < s.length; i++) r.onWarning?.(s[i]);
649
- yield c;
650
- }
651
- }
652
- function Ae(e, t, r = {}) {
653
- const n = typeof r == "number" ? { mmPerRow: r } : r;
654
- Z(n);
655
- const a = [], o = [...L(e, t, n, a, n.knownTotalPages)];
656
- for (const s of o) s.components = s.components.map((i) => B(i) ? j(i, (c) => c.replace(/\{totalPages\}/g, String(o.length))) : i);
657
- return a.forEach((s) => n.onWarning?.(s)), { plan: { schemaVersion: le, pages: o }, warnings: a };
658
- }
659
- function Bt(e, t, r = {}) {
660
- if (e.matrix) {
661
- let i = t[e.dataset] ?? [];
662
- e.computed?.length && (i = fe(i, { fields: e.computed, ...r }).rows), e.rowVisibleWhen && (i = i.filter((l) => H(l, e.rowVisibleWhen)));
663
- const c = Be(i, e.matrix);
664
- return c.cells + c.columnCount;
665
- }
666
- const n = t[e.dataset]?.length ?? 0, a = e.columns.filter((i) => !i.hidden).length, o = X(e).length;
667
- let s = (n * (1 + 2 * o) + +!!e.grandTotal) * a;
668
- if (s += e.headerGrid ? ke(e.headerGrid) : a, e.detail) {
669
- const i = t[e.detail.dataset]?.length ?? 0, c = e.detail.columns.filter((l) => !l.hidden).length;
670
- s += (i + n * (+(e.detail.header !== !1) + +!!e.detail.label)) * c;
671
- }
672
- if (!Number.isSafeInteger(s)) throw new RangeError("报表单元格估算超出安全整数预算");
673
- return s;
674
- }
675
- function Lt(e) {
676
- if (!("mapData" in e)) return e;
677
- const { load: t, mapData: r, ...n } = e;
678
- return { ...n, load: async (a) => {
679
- const o = await t(a);
680
- R(a.signal);
681
- try {
682
- return r(o, a);
683
- } catch (s) {
684
- throw new S("validate", `报表 ${a.reportId} 数据映射失败`, s);
685
- }
686
- } };
687
- }
688
- class S extends Error {
689
- constructor(t, r, n) {
690
- super(r), this.name = "ReportSourceError", this.code = t, this.cause = n;
691
- }
692
- }
693
- function I(e) {
694
- const t = new Error("报表加载已取消");
695
- return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
696
- }
697
- function R(e) {
698
- if (e?.aborted) throw I(e);
699
- }
700
- function Y(e, t) {
701
- return t ? new Promise((r, n) => {
702
- const a = () => t.removeEventListener("abort", o), o = () => {
703
- a(), n(I(t));
704
- };
705
- t.addEventListener("abort", o, { once: !0 }), t.aborted && o(), Promise.resolve(e).then(
706
- (s) => {
707
- a(), r(s);
708
- },
709
- (s) => {
710
- a(), n(s);
711
- }
712
- );
713
- }) : Promise.resolve(e);
714
- }
715
- function it(e, t) {
716
- if (!e || typeof e != "object" || Array.isArray(e))
717
- throw new S("validate", `报表 ${t} 的数据集应为对象`);
718
- for (const [r, n] of Object.entries(e))
719
- if (!Array.isArray(n) || n.some((a) => !a || typeof a != "object" || Array.isArray(a)))
720
- throw new S("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
721
- }
722
- async function ct(e, t, r) {
723
- const { reportId: n, signal: a } = t;
724
- try {
725
- const o = await Y(e(t), a);
726
- R(a);
727
- const s = Fe(o);
728
- if (!s.ok)
729
- throw new S("validate", `报表 ${n} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
730
- return r.push(...s.warnings.map((i) => `${n}: ${i.path}: ${i.message}`)), o;
731
- } catch (o) {
732
- throw a?.aborted ? I(a) : o instanceof S ? o : o instanceof Ne ? new S("validate", `报表 ${n} 模板校验失败:${o.message}`, o) : new S("fetch", `报表 ${n} 模板加载失败:${o instanceof Error ? o.message : String(o)}`, o);
733
- }
734
- }
735
- async function lt(e, t, r, n) {
736
- const a = t.signal;
737
- let o;
738
- try {
739
- if (e.load) o = await Y(e.load(t), a);
740
- else if (e.provider) {
741
- const s = await Y(e.provider.query(t), a);
742
- R(a), dt(s, r), o = s.datasets, n?.(r, s);
743
- } else o = e.datasets ?? {};
744
- } catch (s) {
745
- throw a?.aborted ? I(a) : s instanceof S ? s : new S("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
746
- }
747
- return R(a), o;
748
- }
749
- function dt(e, t) {
750
- if (!e || typeof e != "object" || Array.isArray(e)) throw new S("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
751
- for (const r of ["revision", "sourceToken"])
752
- if (e[r] !== void 0 && typeof e[r] != "string") throw new S("validate", `报表 ${t} Provider ${r} 应为字符串`);
753
- if (e.diagnostics !== void 0 && (!Array.isArray(e.diagnostics) || e.diagnostics.some((r) => !r || typeof r.code != "string" || typeof r.message != "string" || !["info", "warning", "error"].includes(r.severity))))
754
- throw new S("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
755
- }
756
- function ut(e, t, r) {
757
- for (const [n, a] of Object.entries(e.dataSchema ?? {})) {
758
- let o;
759
- try {
760
- o = de(Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0, a, { ...e.dataValidation, path: `$.datasets.${n}` });
761
- } catch (s) {
762
- throw new S("config", `报表 ${r} 数据集 ${n} 字段契约配置无效`, s);
763
- }
764
- if (!o.ok) throw new S("validate", `报表 ${r} 数据集 ${n} 不符合字段契约:${o.issues[0]?.message}`, { issues: o.issues });
765
- }
766
- }
767
- function mt(e) {
768
- const t = (r) => r.grid?.cells.reduce((n, a) => n + a.reduce((o, s) => o + (s ? 1 + (s.children?.reduce((i, c) => i + t(c), 0) ?? 0) : 0), 0), 0) ?? 0;
769
- return e.pages.reduce((r, n) => r + n.components.reduce((a, o) => a + t(o), 0), 0);
770
- }
771
- function ft(e, t, r, n) {
772
- return {
773
- ...e,
774
- signal: n ?? e?.signal,
775
- ...t === void 0 ? {} : { maxPages: Math.max(1, Math.min(t, e?.maxPages ?? t)) },
776
- ...r === void 0 ? {} : { maxCells: Math.max(1, Math.min(r, e?.maxCells ?? r)) }
777
- };
778
- }
779
- function gt(e, t, r, n, a, o) {
780
- const s = a.maxPages === void 0 ? void 0 : a.maxPages - a.usedPages, i = a.maxCells === void 0 ? void 0 : a.maxCells - a.usedCells;
781
- try {
782
- if (s !== void 0 && s < 1 && e.pages.length) throw new W(0, 1);
783
- const c = ft(r.pagination, s, i, o), l = Ae(e, t, c), d = mt(l.plan);
784
- if (i !== void 0 && d > i) throw new D(i, d);
785
- return { ...l, cells: d };
786
- } catch (c) {
787
- let l = c;
788
- throw c instanceof W && a.maxPages !== void 0 && c.limit === s && (l = new W(a.maxPages, a.usedPages + c.actual)), c instanceof D && a.maxCells !== void 0 && (l = new D(a.maxCells, a.usedCells + c.actual)), new S("validate", `报表 ${n} 排版失败:${l instanceof Error ? l.message : String(l)}`, l);
789
- }
790
- }
791
- function ht(e, t, r, n) {
792
- const a = /* @__PURE__ */ new Map(), o = (s) => {
793
- let i = a.get(s);
794
- return i === void 0 && (i = JSON.stringify([r, n, s]), a.set(s, i)), i;
795
- };
796
- for (const s of t.pages) e.push({
797
- ...s,
798
- components: s.components.map((i) => i.table ? {
799
- ...i,
800
- table: { ...i.table, id: o(i.table.id) }
801
- } : i)
802
- });
803
- }
804
- function jt(e, t = {}) {
805
- if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new S("config", "maxPages 应为正安全整数");
806
- if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new S("config", "maxCells 应为正安全整数");
807
- function r(a) {
808
- const o = Object.prototype.hasOwnProperty.call(e, a) ? e[a] : void 0;
809
- if (!o) throw new S("config", `未注册报表 ${a}`);
810
- return o;
811
- }
812
- return Object.assign(async ({ reportIds: a, params: o, signal: s, onWarning: i, onQueryResult: c, ...l }) => {
813
- R(s);
814
- const d = He({ ...l, signal: s }), g = [...a], f = { ...o };
815
- if (g.length === 0) throw new S("config", "缺少报表 ID");
816
- const h = g.map(r), p = d.runSync("validate", () => h.map((b) => te(
817
- b.params ?? (typeof b.template == "function" ? [] : b.template.params) ?? [],
818
- f
819
- ))), u = [];
820
- let m = 0;
821
- const w = [];
822
- for (const [b, T] of h.entries()) {
823
- R(s);
824
- const v = g[b], y = { reportId: v, params: p[b], signal: s }, x = typeof T.template == "function" ? await d.run("query", () => ct(T.template, y, w), v) : T.template;
825
- y.params = d.runSync("validate", () => te(T.params ?? x.params ?? [], y.params), v);
826
- const P = await d.run("query", () => lt(T, y, v, c), v);
827
- d.runSync("validate", () => {
828
- it(P, v), t.onDatasets?.(v, P, x), ut(T, P, v);
829
- }, v), R(s);
830
- const A = d.runSync("layout", () => gt(x, P, T, v, { maxPages: t.maxPages, usedPages: u.length, maxCells: t.maxCells, usedCells: m }, s), v);
831
- m += A.cells, ht(u, A.plan, b, v), w.push(...A.warnings.map((F) => `${v}: ${F}`));
832
- }
833
- R(s);
834
- const M = { schemaVersion: le, pages: u }, $ = d.runSync("validate", () => {
835
- const b = Re(M);
836
- if (!b.ok) throw new S("validate", `渲染计划校验失败:${b.errors.slice(0, 3).map((T) => `${T.path}: ${T.message}`).join("; ")}`);
837
- return b;
838
- });
839
- w.push(...$.warnings.map((b) => `${b.path}: ${b.message}`));
840
- const G = i ?? t.onWarning ?? ((b) => console.warn("[mach-report]", b));
841
- for (const b of w)
842
- R(s), G(b);
843
- return R(s), M;
844
- }, {
845
- getParamDefs: (a) => Ce(e, a)
846
- });
847
- }
848
- function ie(e) {
849
- if (e === void 0) return;
850
- const t = typeof e == "string" ? e : JSON.stringify(e);
851
- return t.length > 160 ? t.slice(0, 157) + "…" : t;
852
- }
853
- function pt(e) {
854
- return /\.(?:computed|computeOptions|groups|groupBy|aggregates|grandTotal)(?:\.|\[|$)/.test(e) ? "calculation" : /\.(?:dataset|field|rowKey|revisionField|sourceTokenField|foreignKey|parentKey)$/.test(e) ? "binding" : /\.(?:style|headerStyle|format|rules|align|headerAlign|semanticRole|unit)(?:\.|\[|$)/.test(e) ? "format" : e.startsWith("$.template") ? "structure" : "metadata";
855
- }
856
- function ce(e) {
857
- const t = /* @__PURE__ */ new Map();
858
- for (const r of e) {
859
- if (!r || typeof r != "object" || !("field" in r) || typeof r.field != "string" || t.has(r.field)) return;
860
- t.set(r.field, r);
861
- }
862
- return t;
863
- }
864
- function yt(e, t, r) {
865
- return !e.startsWith("$.template.params") || t === "moved" ? !1 : /\.(?:type|required|min|max|minLength|maxLength|options|defaultValue)(?:\[|$)/.test(e) ? !0 : t !== "added" ? !1 : Array.isArray(r) ? r.some((n) => !!n && typeof n == "object" && "required" in n && n.required === !0) : !!r && typeof r == "object" && "required" in r && r.required === !0;
866
- }
867
- function wt(e, t, r = {}) {
868
- const n = V(e), a = V(t), o = r.maxChanges ?? 500;
869
- if (!Number.isSafeInteger(o) || o < 1 || o > 1e4) throw new RangeError("maxChanges must be between 1 and 10000");
870
- const s = { changes: [], totalChanges: 0, breakingChanges: 0, truncated: !1 };
871
- function i(d, g, f, h) {
872
- const p = pt(g), u = d !== "moved" && (p === "binding" || g === "$.id" || d === "removed" && p === "structure" || yt(g, d, h));
873
- s.totalChanges++, u && s.breakingChanges++, s.changes.length < o && s.changes.push({ kind: d, category: p, path: g, before: ie(f), after: ie(h), breaking: u });
874
- }
875
- function c(d, g, f) {
876
- const h = ce(d), p = ce(g);
877
- if (!h || !p) return !1;
878
- const u = new Map(g.map((m, w) => [m.field, w]));
879
- Array.from(h).forEach(([m, w], M) => {
880
- const $ = `${f}[${JSON.stringify(m)}]`;
881
- p.has(m) ? (u.get(m) !== M && i("moved", $, M, u.get(m)), l(w, p.get(m), $)) : i("removed", $, w, void 0);
882
- });
883
- for (const [m, w] of p) h.has(m) || i("added", `${f}[${JSON.stringify(m)}]`, void 0, w);
884
- return !0;
885
- }
886
- function l(d, g, f) {
887
- if (!(Object.is(d, g) || f === "$.revision")) {
888
- if (d === void 0 || g === void 0) {
889
- i(d === void 0 ? "added" : "removed", f, d, g);
890
- return;
891
- }
892
- if (Array.isArray(d) && Array.isArray(g)) {
893
- if ((f.endsWith(".columns") || f.endsWith(".params")) && c(d, g, f)) return;
894
- for (let h = 0; h < Math.max(d.length, g.length); h++) l(d[h], g[h], `${f}[${h}]`);
895
- } else if (d && g && typeof d == "object" && typeof g == "object" && !Array.isArray(d) && !Array.isArray(g)) {
896
- const h = d, p = g;
897
- for (const u of /* @__PURE__ */ new Set([...Object.keys(h), ...Object.keys(p)])) l(h[u], p[u], `${f}.${u}`);
898
- } else i("modified", f, d, g);
899
- }
900
- }
901
- return l(n, a, "$"), s.truncated = s.totalChanges > s.changes.length, s;
902
- }
903
- function C(e) {
904
- return !!e && typeof e == "object" && !Array.isArray(e);
905
- }
906
- function k(e, t, r) {
907
- typeof e == "string" ? r.push({ field: e, path: t }) : Array.isArray(e) && e.forEach((n, a) => k(n, `${t}[${a}]`, r));
908
- }
909
- function N(e, t, r) {
910
- if (Array.isArray(e)) {
911
- e.forEach((n, a) => N(n, `${t}[${a}]`, r));
912
- return;
913
- }
914
- if (C(e))
915
- for (const [n, a] of Object.entries(e))
916
- ["field", "weightField"].includes(n) ? k(a, `${t}.${n}`, r) : n !== "value" && n !== "style" && N(a, `${t}.${n}`, r);
917
- }
918
- function K(e, t, r) {
919
- Array.isArray(e) && e.forEach((n, a) => {
920
- C(n) && (typeof n.field == "string" && n.valueField !== void 0 && n.valueField !== n.field && r.summaries.add(n.field), k(n.valueField ?? n.field, `${t}[${a}].valueField`, r.fields), k(n.weightField, `${t}[${a}].weightField`, r.fields));
921
- });
922
- }
923
- function Mt(e, t, r) {
924
- for (const a of ["rowKey", "revisionField", "sourceTokenField"]) k(e[a], `${t}.${a}`, r.fields);
925
- !e.matrix && Array.isArray(e.columns) && e.columns.forEach((a, o) => {
926
- C(a) && (typeof a.field == "string" && r.fields.push({ field: a.field, path: `${t}.columns[${o}].field`, summary: !0 }), N(a.rules, `${t}.columns[${o}].rules`, r.fields), N(a.visibleWhen, `${t}.columns[${o}].visibleWhen`, r.fields));
927
- }), N(e.rowVisibleWhen, `${t}.rowVisibleWhen`, r.fields), Array.isArray(e.computed) && e.computed.forEach((a, o) => {
928
- C(a) && (typeof a.field == "string" && r.generated.add(a.field), N(a.expression, `${t}.computed[${o}].expression`, r.fields), k(a.dependsOn, `${t}.computed[${o}].dependsOn`, r.fields), k(a.groupBy, `${t}.computed[${o}].groupBy`, r.fields));
929
- }), (Array.isArray(e.groups) ? e.groups : e.groupBy ? [e.groupBy] : []).forEach((a, o) => {
930
- C(a) && (k(a.field, `${t}.groups[${o}].field`, r.fields), k(a.subtotal, `${t}.groups[${o}].subtotal`, r.fields), K(a.aggregates, `${t}.groups[${o}].aggregates`, r));
931
- }), C(e.grandTotal) && (k(e.grandTotal.fields, `${t}.grandTotal.fields`, r.fields), K(e.grandTotal.aggregates, `${t}.grandTotal.aggregates`, r)), C(e.matrix) && (k(e.matrix.rowFields, `${t}.matrix.rowFields`, r.fields), k(e.matrix.columnFields, `${t}.matrix.columnFields`, r.fields), K(e.matrix.measures, `${t}.matrix.measures`, r)), C(e.detail) && k(e.detail.parentKey, `${t}.detail.parentKey`, r.fields);
932
- }
933
- function Ee(e) {
934
- const t = [];
935
- function r(n, a) {
936
- if (Array.isArray(n)) {
937
- n.forEach((o, s) => r(o, `${a}[${s}]`));
938
- return;
939
- }
940
- if (C(n)) {
941
- if (typeof n.dataset == "string" && Array.isArray(n.columns)) {
942
- const o = { dataset: n.dataset, path: a, fields: [], generated: /* @__PURE__ */ new Set(), summaries: /* @__PURE__ */ new Set() };
943
- Mt(n, a, o), typeof n.foreignKey == "string" && k(n.foreignKey, `${a}.foreignKey`, o.fields), t.push(o);
944
- }
945
- for (const [o, s] of Object.entries(n)) r(s, `${a}.${o}`);
946
- }
947
- }
948
- return r(e, "$.template"), t;
949
- }
950
- function bt(e, t, r) {
951
- for (const n of Ee(e)) {
952
- const a = Object.prototype.hasOwnProperty.call(t, n.dataset) ? t[n.dataset] : void 0;
953
- if (!a) {
954
- r.push({ code: "dataset", severity: "error", path: `${n.path}.dataset`, message: `未声明数据集 ${n.dataset}` });
955
- continue;
956
- }
957
- const o = new Set(a.fields.map((s) => s.field));
958
- n.fields.forEach(({ field: s, path: i, summary: c }) => {
959
- !o.has(s) && !n.generated.has(s) && !(c && n.summaries.has(s)) && r.push({ code: "field", severity: "error", path: i, field: s, message: `数据集 ${n.dataset} 缺少字段 ${s}` });
960
- });
961
- }
962
- }
963
- function $t(e, t, r, n) {
964
- const a = r.maxSampleRows ?? 1e3, o = Object.values(e.datasets).reduce((i, c) => i + c.length, 0);
965
- if (o > a)
966
- return n.push({ code: "sample", severity: "error", path: "$.fixtures", fixture: e.name, message: `样例 ${o} 行超过预算 ${a},请显式选择验收样例` }), !1;
967
- const s = new Set(Ee(t).map((i) => i.dataset));
968
- for (const [i, c] of Object.entries(r.dataSchemas ?? {}).filter(([l]) => s.has(l)))
969
- try {
970
- const l = de(e.datasets[i], c, { path: `$.datasets.${i}`, maxRows: a });
971
- if (n.push(...l.issues.map((d) => ({ ...d, code: "sample", severity: "error", fixture: e.name }))), !l.ok) return !1;
972
- } catch (l) {
973
- return n.push({ code: "dataset", severity: "error", path: `$.dataSchemas.${i}`, message: String(l) }), !1;
974
- }
975
- return !0;
976
- }
977
- function St(e, t, r) {
978
- const n = t.pages[r.pageIndex]?.components[r.componentIndex], a = /^table:(\d+):(\d+)(?::|$)/.exec(n?.table?.id ?? "");
979
- if (a) return { path: `$.template.pages[${a[1]}].components[${a[2]}]`, pageIndex: Number(a[1]), componentIndex: Number(a[2]) };
980
- for (const [o, s] of e.pages.entries()) {
981
- const i = s.components.findIndex((c) => c === n || n?.nid !== void 0 && "nid" in c && c.nid === n.nid);
982
- if (i >= 0) return { path: `$.template.pages[${o}].components[${i}]`, pageIndex: o, componentIndex: i };
983
- }
984
- return { path: "$.template" };
985
- }
986
- function vt(e, t, r, n) {
987
- if ($t(t, e.template, r, n.issues))
988
- try {
989
- const { plan: a, warnings: o } = Ae(e.template, t.datasets, { maxPages: r.maxPages ?? 100, maxCells: r.maxCells ?? 25e4 }), s = (r.formats ?? ["pdf", "xlsx"]).flatMap((i) => Ie(a, i));
990
- n.issues.push(...o.map((i) => ({ code: "layout", severity: "warning", path: "$.template", fixture: t.name, message: i }))), n.issues.push(...s.map((i) => ({ code: "output", severity: r.strictOutputs ? "error" : "warning", ...St(e.template, a, i), fixture: t.name, message: `${i.format}: ${i.message}` }))), n.samples.push({ name: t.name, pages: a.pages.length, rows: Object.values(t.datasets).reduce((i, c) => i + c.length, 0), diagnostics: s });
991
- } catch (a) {
992
- n.issues.push({ code: "layout", severity: "error", path: "$.template", fixture: t.name, message: a instanceof Error ? a.message : String(a) });
993
- }
994
- }
995
- function It(e, t = {}) {
996
- const r = { ok: !1, issues: [], samples: [] };
997
- try {
998
- for (const [a, o] of [["maxPages", t.maxPages], ["maxCells", t.maxCells], ["maxSampleRows", t.maxSampleRows]]) if (o !== void 0 && (!Number.isSafeInteger(o) || o < 1)) throw new RangeError(`${a} must be a positive safe integer`);
999
- if ((t.fixtures?.length ?? 0) > 20) throw new RangeError("At most 20 review fixtures are allowed");
1000
- const n = V(e);
1001
- t.previous && (r.changes = wt(t.previous, n), r.changes.breakingChanges && !t.allowBreakingChanges && r.issues.push({ code: "compatibility", severity: "error", path: "$.template", message: `${r.changes.breakingChanges} 项字段或结构变更需要明确确认兼容性` })), t.dataSchemas && bt(n.template, t.dataSchemas, r.issues);
1002
- for (const a of t.fixtures ?? []) vt(n, a, t, r);
1003
- t.fixtures?.length || r.issues.push({ code: "sample", severity: "warning", path: "$.fixtures", message: "未提供验收样例,仅完成结构和字段检查,尚未验证排版与输出" });
1004
- } catch (n) {
1005
- r.issues.push({ code: "template", severity: "error", path: "$", message: n instanceof Error ? n.message : String(n) });
1006
- }
1007
- return r.ok = r.issues.every((n) => n.severity !== "error"), r;
1008
- }
1009
- export {
1010
- D as P,
1011
- S as R,
1012
- W as a,
1013
- jt as b,
1014
- Wt as c,
1015
- Lt as d,
1016
- wt as e,
1017
- Bt as f,
1018
- H as g,
1019
- pe as h,
1020
- Dt as i,
1021
- Ge as j,
1022
- ze as k,
1023
- ae as l,
1024
- Ae as p,
1025
- It as r,
1026
- he as t
1027
- };