@agile-team/mach-report 2.10.0 → 2.11.1

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 (111) hide show
  1. package/README.md +6 -2
  2. package/dist/ExcelBindingWizard-LWX6G1A2.js +1465 -0
  3. package/dist/ExcelBindingWizard-a4kslPHF.cjs +1 -0
  4. package/dist/ParamEditor-BLaE5q5W.js +522 -0
  5. package/dist/ParamEditor-MBBC7lUE.cjs +1 -0
  6. package/dist/ReportBatchPanel-B5ClP9tm.js +350 -0
  7. package/dist/ReportBatchPanel-Dc-SDkYA.cjs +1 -0
  8. package/dist/ReportPreview-DWXROHBP.cjs +6 -0
  9. package/dist/ReportPreview-DiNXhQI0.js +4138 -0
  10. package/dist/ReportTemplateLibrary-5fk5CQBO.cjs +1 -0
  11. package/dist/ReportTemplateLibrary-BZB-XWjj.js +311 -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 +2 -0
  18. package/dist/analytics.d.ts +2 -0
  19. package/dist/analytics.js +29 -29
  20. package/dist/batch-Bt3Fd27Z.cjs +1 -0
  21. package/dist/batch-mRqhhhjt.js +364 -0
  22. package/dist/computed-Bvk0W15F.js +521 -0
  23. package/dist/computed-CGV2a809.cjs +1 -0
  24. package/dist/config-B612mw0x.js +525 -0
  25. package/dist/config-BRoLo2oj.cjs +1 -0
  26. package/dist/designer.cjs +2 -2
  27. package/dist/designer.d.cts +730 -9
  28. package/dist/designer.d.ts +730 -9
  29. package/dist/designer.js +2093 -1785
  30. package/dist/index.cjs +8 -8
  31. package/dist/index.d.cts +161 -3
  32. package/dist/index.d.ts +161 -3
  33. package/dist/index.js +486 -431
  34. package/dist/injection-keys-Db_DyLkm.cjs +1 -0
  35. package/dist/injection-keys-e85udZCp.js +7 -0
  36. package/dist/list-cell-BuYn4tGF.cjs +1 -0
  37. package/dist/{list-cell-Dxyi7DOw.js → list-cell-ClFra1zS.js} +54 -40
  38. package/dist/matrix-DVyWiYsd.cjs +1 -0
  39. package/dist/matrix-yZsGnldA.js +227 -0
  40. package/dist/param-validation-BlHHXs6u.js +153 -0
  41. package/dist/param-validation-DCK039V1.cjs +1 -0
  42. package/dist/pdf.cjs +25 -25
  43. package/dist/pdf.d.cts +3 -0
  44. package/dist/pdf.d.ts +3 -0
  45. package/dist/pdf.js +677 -677
  46. package/dist/plugin-BDTU4D94.cjs +1 -0
  47. package/dist/plugin-Cd5G2QQn.js +22 -0
  48. package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
  49. package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
  50. package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
  51. package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
  52. package/dist/server/node.d.cts +5 -2
  53. package/dist/server/node.d.ts +5 -2
  54. package/dist/server-node.cjs +1 -1
  55. package/dist/server-node.js +87 -87
  56. package/dist/server.cjs +1 -1
  57. package/dist/server.d.cts +201 -2
  58. package/dist/server.d.ts +201 -2
  59. package/dist/server.js +557 -658
  60. package/dist/style.css +1 -1
  61. package/dist/template-registry-WNXdkiET.js +506 -0
  62. package/dist/template-registry-ukBGlm8N.cjs +1 -0
  63. package/dist/template-review-BXp2oyqg.cjs +1 -0
  64. package/dist/template-review-BdcXSYbx.js +1616 -0
  65. package/dist/tree-BX380Rr7.cjs +1 -0
  66. package/dist/tree-CqcQ99NM.js +172 -0
  67. package/dist/{validate-UUy9yP4K.js → validate-7s0yn6ii.js} +44 -44
  68. package/dist/validate-DsRiNw8h.cjs +1 -0
  69. package/dist/vue/async.d.cts +93 -4
  70. package/dist/vue/async.d.ts +93 -4
  71. package/dist/vue/index.d.cts +145 -7
  72. package/dist/vue/index.d.ts +145 -7
  73. package/dist/vue-async.cjs +1 -1
  74. package/dist/vue-async.js +5 -5
  75. package/dist/vue.cjs +1 -1
  76. package/dist/vue.js +116 -113
  77. package/dist/{workbook-session-B-bW5_yR.js → workbook-session-BKOTwcoq.js} +1 -1
  78. package/dist/{workbook-session-D7RtdNo0.cjs → workbook-session-CLYLhZWu.cjs} +1 -1
  79. package/dist/worker.cjs +1 -1
  80. package/dist/worker.d.cts +5 -2
  81. package/dist/worker.d.ts +5 -2
  82. package/dist/worker.js +1 -1
  83. package/dist/xlsx.cjs +3 -3
  84. package/dist/xlsx.d.cts +129 -2
  85. package/dist/xlsx.d.ts +129 -2
  86. package/dist/xlsx.js +336 -242
  87. package/package.json +1 -1
  88. package/dist/ExcelBindingWizard-CF7RplWm.cjs +0 -1
  89. package/dist/ExcelBindingWizard-qhwEderR.js +0 -842
  90. package/dist/ReportPreview-BE1tCHqE.js +0 -4604
  91. package/dist/ReportPreview-QKRKQOe3.cjs +0 -6
  92. package/dist/RuleEditor-BA36yIV6.js +0 -1723
  93. package/dist/RuleEditor-CczJ6mJm.cjs +0 -1
  94. package/dist/TemplateReviewPanel-CHi4Alqa.cjs +0 -1
  95. package/dist/TemplateReviewPanel-Dz0G5o83.js +0 -217
  96. package/dist/binding-preview-BWsdf_z2.cjs +0 -2
  97. package/dist/binding-preview-DILq0-0f.js +0 -649
  98. package/dist/decimal-CI1OAczk.js +0 -87
  99. package/dist/decimal-CQA0xJex.cjs +0 -1
  100. package/dist/list-cell-CyM1ZlRN.cjs +0 -1
  101. package/dist/matrix-BbXarwyk.js +0 -661
  102. package/dist/matrix-Cm65WLLP.cjs +0 -1
  103. package/dist/param-validation-BWNjLcN0.js +0 -116
  104. package/dist/param-validation-CiTxFeZ8.cjs +0 -1
  105. package/dist/plugin-CThk42vJ.cjs +0 -1
  106. package/dist/plugin-tGn7-5oF.js +0 -25
  107. package/dist/template-registry-CGWTLtIA.cjs +0 -1
  108. package/dist/template-registry-DzlQs3OF.js +0 -434
  109. package/dist/template-review-D1RoNCPw.cjs +0 -1
  110. package/dist/template-review-fnteXRng.js +0 -1473
  111. package/dist/validate-Bf6ccFr2.cjs +0 -1
@@ -1,1473 +0,0 @@
1
- import { R as U } from "./render-plan-Ck6koX9L.js";
2
- import { c as Pe } from "./validate-UUy9yP4K.js";
3
- import { g as lt } from "./report-params-B_VCihAh.js";
4
- import { v as ut, a as dt, p as ne } from "./template-registry-DzlQs3OF.js";
5
- import { a as ye, b as ft } from "./param-validation-BWNjLcN0.js";
6
- import { r as le } from "./grid-geometry-BNptEcMm.js";
7
- import { f as mt, i as gt } from "./number-format-BA_KwrZe.js";
8
- import { c as ht } from "./task-events-Dpsvf_t2.js";
9
- import { v as ke } from "./dataset-H5pFuQGU.js";
10
- import { c as pt, D as Ce, L as Re } from "./defaults-DXhiM1ZD.js";
11
- import { h as wt, w as ue } from "./textwrap-DE1kgcJB.js";
12
- import { e as L, l as de, a as yt, t as Ee, c as Ie, f as Ae } from "./list-cell-Dxyi7DOw.js";
13
- import { c as Fe, f as bt, a as vt, e as xt } from "./matrix-BbXarwyk.js";
14
- import { e as K, r as Oe } from "./style-CQ1PK8ZB.js";
15
- import { i as Mt } from "./capabilities-CK_7hizc.js";
16
- function $t(e, t, r) {
17
- const n = /* @__PURE__ */ new Set(), o = e.cells.map((a, s) => {
18
- const i = [];
19
- let c = 0;
20
- for (const l of a) {
21
- for (; n.has(`${s}:${c}`); ) c++;
22
- const u = l?.colSpan ?? 1, f = l?.rowSpan ?? 1;
23
- let d = 0;
24
- for (let g = c; g < c + u; g++) {
25
- t.has(g) && d++;
26
- for (let w = s + 1; w < s + f; w++)
27
- n.add(`${w}:${g}`);
28
- }
29
- d && i.push(l ? { ...l, colSpan: d } : null), c += u;
30
- }
31
- return i;
32
- });
33
- return { ...e, cells: o, colWidthsMm: r };
34
- }
35
- function St(e) {
36
- if (!e.columns.some((n) => n.hidden)) return e;
37
- const t = /* @__PURE__ */ new Set(), r = e.columns.filter((n, o) => n.hidden ? !1 : (t.add(o), !0));
38
- if (!r.length) throw new Error("列表至少需要一列可见列");
39
- return {
40
- ...e,
41
- columns: r,
42
- ...e.headerGrid ? {
43
- headerGrid: $t(
44
- e.headerGrid,
45
- t,
46
- r.map((n) => n.widthMm)
47
- )
48
- } : {}
49
- };
50
- }
51
- function Tt(e) {
52
- return !!(e.computed?.length || e.groups?.length || e.groupBy || e.grandTotal || e.rowVisibleWhen || e.matrix || e.detail || e.columns.some((t) => t.rules?.length || t.visibleWhen));
53
- }
54
- function Y(e) {
55
- return e.pages.some((t) => t.components.some((r) => r.kind === "list" && Tt(r)));
56
- }
57
- class B extends Error {
58
- constructor(t, r) {
59
- super(`报表页数超出上限 ${t}(至少 ${r} 页)`), this.limit = t, this.actual = r, this.code = "page-limit", this.name = "PaginatePageLimitError";
60
- }
61
- }
62
- class V extends Error {
63
- constructor(t, r) {
64
- super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`), this.limit = t, this.actual = r, this.code = "cell-limit", this.name = "PaginateCellLimitError";
65
- }
66
- }
67
- function Pt(e) {
68
- return {
69
- widthMm: e.widthMm,
70
- heightMm: e.heightMm,
71
- marginTopMm: e.marginTopMm ?? 0,
72
- marginBottomMm: e.marginBottomMm ?? 0,
73
- marginLeftMm: e.marginLeftMm ?? 0,
74
- marginRightMm: e.marginRightMm ?? 0,
75
- components: []
76
- };
77
- }
78
- function be(e, t) {
79
- const r = t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
80
- return e.components.reduce((n, o) => o.kind !== "list" && o.pageAnchor === "footer" ? Math.min(n, o.topMm) : n, r);
81
- }
82
- function ve(e) {
83
- return e.components.reduce((t, r) => r.kind !== "list" && r.pageAnchor === "header" ? Math.max(t, r.topMm + r.heightMm) : t, 0);
84
- }
85
- function Ke(e, t) {
86
- let r = e.textMetrics.get(t);
87
- if (!r) {
88
- const n = Oe(t).fontSizePt;
89
- r = {
90
- measureOptions: {
91
- fontSizePt: n,
92
- fontFamily: t.fontFamily ?? Ce,
93
- italic: t.italic,
94
- bold: t.bold,
95
- letterSpacingPt: t.letterSpacing
96
- },
97
- lineMm: n * (t.lineHeight ?? Re) * 25.4 / 72
98
- }, e.textMetrics.set(t, r);
99
- }
100
- return r;
101
- }
102
- function kt(e) {
103
- if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
104
- }
105
- function je(e, t) {
106
- const r = e.fontSizePt ?? pt, n = e.paddingMm ?? 1, o = e.columns.map((m) => m.align ?? m.style?.align ?? e.align ?? "left"), a = e.columns.map((m, h) => ({
107
- ...K({
108
- fontSize: r,
109
- verticalAlign: "middle"
110
- }, m.style),
111
- align: o[h] === "auto" ? "left" : o[h]
112
- })), s = a.map((m, h) => o[h] === "auto" ? { left: m, center: { ...m, align: "center" }, right: { ...m, align: "right" } } : void 0), i = e.columns.map((m, h) => m.rules?.map((v) => {
113
- const x = s[h];
114
- if (x) return {
115
- left: K(x.left, v.style),
116
- center: K(x.center, v.style),
117
- right: K(x.right, v.style)
118
- };
119
- const y = K(a[h], v.style);
120
- return { left: y, center: y, right: y };
121
- })), c = e.columns.map((m) => yt(e, m)), l = e.columns.map((m) => m.header);
122
- let u = e.rowHeightMm ?? 0;
123
- for (let m = 0; m < l.length; m++) {
124
- const h = c[m], v = Oe(h).fontSizePt, x = ue(
125
- l[m],
126
- e.columns[m].widthMm - n * 2,
127
- { fontSizePt: v, fontFamily: h.fontFamily ?? Ce, italic: h.italic, bold: h.bold, letterSpacingPt: h.letterSpacing },
128
- t
129
- ), y = v * (h.lineHeight ?? Re) * 25.4 / 72;
130
- u = Math.max(u, Math.max(x.length, 1) * y + n * 2);
131
- }
132
- const f = l.map((m, h) => ({
133
- text: m,
134
- style: c[h]
135
- })), d = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, g = e.columns.map((m) => m.widthMm), w = Ct(e.headerGrid, g, {
136
- cells: [f],
137
- colWidthsMm: g,
138
- rowHeightsMm: [u],
139
- paddingMm: n
140
- });
141
- return {
142
- fontSizePt: r,
143
- paddingMm: n,
144
- cellStyles: a,
145
- autoStyles: s,
146
- ruleStyles: i,
147
- textMetrics: /* @__PURE__ */ new WeakMap(),
148
- numberFormats: e.columns.map((m) => Ee(m.format)),
149
- derivedFields: new Set(e.computed?.map((m) => m.field)),
150
- borderStyle: d,
151
- headerHeightMm: w.rowHeightsMm.reduce((m, h) => m + h, 0),
152
- headerGrid: w,
153
- colWidthsMm: g,
154
- columns: e.columns
155
- };
156
- }
157
- function Ct(e, t, r) {
158
- if (!e) return r;
159
- if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
160
- const n = e.rowHeightsMm ?? e.cells.map(() => r.rowHeightsMm[0]);
161
- if (n.length !== e.cells.length || n.some((o) => !Number.isFinite(o) || o <= 0)) throw new Error("自定义列表表头行高无效");
162
- return { ...e, colWidthsMm: t, rowHeightsMm: n };
163
- }
164
- function Rt(e, t, r) {
165
- const n = t.format?.kind === "number" || t.format?.kind === "percent";
166
- 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);
167
- }
168
- function oe(e, t, r) {
169
- const n = e.columns;
170
- let o = e.rowHeightFloorMm;
171
- const a = new Array(n.length);
172
- for (let s = 0; s < n.length; s++) {
173
- const i = n[s], c = i.visibleWhen && !L(t, i.visibleWhen) ? null : t[i.field], l = e.autoStyles[s] ? Ie(c, i.format, i.semanticRole) : "left";
174
- let u = e.autoStyles[s]?.[l] ?? e.cellStyles[s];
175
- if (i.rules)
176
- for (let h = 0; h < i.rules.length; h++) {
177
- const v = i.rules[h];
178
- if (L(t, v.when)) {
179
- u = e.ruleStyles[s][h][l];
180
- break;
181
- }
182
- }
183
- const f = i.format ? Ae(c, i.format) : de(c), d = Ke(e, u), g = ue(f, i.widthMm - e.paddingMm * 2, d.measureOptions, r);
184
- o = Math.max(o, g.length * d.lineMm + e.paddingMm * 2);
185
- const w = kt(c), m = { text: f, style: u };
186
- w !== void 0 && (m.value = w), Rt(m, i, e.numberFormats[s]), e.derivedFields.has(i.field) && (m.derived = !0, m.editable = !1), i.visibleWhen && c === null && !L(t, i.visibleWhen) && (m.editable = !1), a[s] = m;
187
- }
188
- return {
189
- grid: { cells: [a], colWidthsMm: e.colWidthsMm, rowHeightsMm: [o], paddingMm: e.paddingMm },
190
- heightMm: o
191
- };
192
- }
193
- function Ne(e) {
194
- if (e != null && typeof e != "string" && typeof e != "boolean" && !(typeof e == "number" && Number.isFinite(e))) throw new Error("分组字段应为有限 JSON 标量");
195
- return JSON.stringify([typeof e, e ?? null]);
196
- }
197
- function* He(e, t, r = 0) {
198
- const n = t[r];
199
- if (!n) {
200
- for (const a of e) yield { kind: "row", row: a };
201
- return;
202
- }
203
- const o = /* @__PURE__ */ new Map();
204
- for (const a of e) {
205
- const s = Ne(a[n.field]), i = o.get(s);
206
- i ? i.push(a) : o.set(s, [a]);
207
- }
208
- for (const a of o.values())
209
- yield { kind: "groupHeader", label: (n.headerTemplate ?? "{value}").replace(/\{value\}/g, de(a[0][n.field])), firstRow: a[0], group: n, depth: r, rows: a }, yield* He(a, t, r + 1), (n.subtotal?.length || n.aggregates?.length) && (yield { kind: "subtotal", label: n.subtotalLabel ?? "小计", rows: a, group: n, depth: r }), yield { kind: "groupEnd", depth: r };
210
- }
211
- function We(e, t, r, n = []) {
212
- const o = [...r.filter((a) => !n.some((s) => s.field === a)).map((a) => ({ field: a, op: "sum" })), ...n];
213
- return new Map(o.map((a) => {
214
- const s = e.find((c) => c.field === a.field)?.format ?? { kind: "number", thousands: !0 }, i = vt(t, { ...a, field: a.valueField ?? a.field });
215
- return [a.field, { text: Ae(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: Ee(s) } : {} }];
216
- }));
217
- }
218
- function Le(e, t) {
219
- const r = e.findIndex((n) => t.includes(n.field));
220
- return r < 0 ? 1 : r;
221
- }
222
- function G(e, t, r, n, o, a) {
223
- const s = [], i = Math.max(0, Math.min(a, e.columns.length)), c = K({ fontSize: e.fontSizePt }, o);
224
- i && s.push({ text: r, colSpan: i, style: { bold: !0, ...c } });
225
- for (let d = i; d < e.columns.length; d++) {
226
- const g = e.columns[d], w = n.get(g.field), m = e.autoStyles[d]?.[Ie(w?.value, g.format)] ?? e.cellStyles[d];
227
- s.push({ ...w, text: w?.text ?? "", style: K(m, o) });
228
- }
229
- const l = { text: r, colSpan: e.columns.length, style: { bold: !0, ...c } }, u = i ? [s] : [[l], s], f = u.map((d) => Et(e, d, t));
230
- return {
231
- grid: { cells: u, colWidthsMm: e.colWidthsMm, rowHeightsMm: f, paddingMm: e.paddingMm },
232
- heightMm: f.reduce((d, g) => d + g, 0)
233
- };
234
- }
235
- function Et(e, t, r) {
236
- let n = e.rowHeightFloorMm, o = 0;
237
- for (const a of t) {
238
- let s = 0;
239
- const i = o + (a.colSpan ?? 1);
240
- for (; o < i; o++) s += e.colWidthsMm[o] ?? 0;
241
- const c = Ke(e, a.style), l = ue(a.text ?? "", s - e.paddingMm * 2, c.measureOptions, r);
242
- n = Math.max(n, l.length * c.lineMm + e.paddingMm * 2);
243
- }
244
- return n;
245
- }
246
- function It(e, t, r) {
247
- const { templatePage: n, current: o, warnings: a, nextId: s, pushCurrent: i } = r, c = () => be(n, o), l = Math.max(o.marginTopMm, ve(n)), u = n.layout === "wide" ? ve(n) : l, f = {
248
- id: r.tableId,
249
- columnKeys: e.columns.map((p) => p.field),
250
- ...e.layout === void 0 ? {} : { layout: e.layout },
251
- ...e.title === void 0 ? {} : { title: e.title }
252
- }, d = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), w = {
253
- kind: "rect",
254
- leftMm: e.leftMm,
255
- topMm: 0,
256
- widthMm: e.widthMm,
257
- heightMm: t.headerHeightMm,
258
- grid: t.headerGrid,
259
- nid: s("listh"),
260
- table: { ...f, role: "header", rowIndex: -1 },
261
- style: t.borderStyle
262
- }, m = (p) => o.components.push({ ...w, topMm: p });
263
- let h = Math.max(e.topMm, l);
264
- m(h), h += t.headerHeightMm + r.mmPerRow;
265
- function v() {
266
- const p = Math.max(n.layout === "wide" ? 0 : e.topMm, u);
267
- return (e.headerEveryPage !== !1 ? p + t.headerHeightMm : u) + [...g.values()].reduce(($, P) => $ + P.heightMm, 0);
268
- }
269
- function x() {
270
- const p = n.layout === "wide" ? 0 : o.marginBottomMm;
271
- return Math.min(n.heightMm - p, be(n, o)) - v();
272
- }
273
- function y(p) {
274
- if (h + p <= c()) return;
275
- i(), o.components = [], o.heightMm = n.heightMm, n.layout === "wide" && (o.marginTopMm = 0, o.marginBottomMm = 0);
276
- const M = Math.max(n.layout === "wide" ? 0 : e.topMm, u);
277
- e.headerEveryPage !== !1 ? (m(M), h = M + t.headerHeightMm) : h = u;
278
- for (const $ of g.values()) A($, "listgr", "group-header");
279
- }
280
- function j(p, M, $, P) {
281
- const E = x();
282
- p.heightMm > E && a.push(`列表 ${e.id ?? e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${E.toFixed(2)}mm,预览与打印可能截断内容`), y(p.heightMm), A(p, M, $, P);
283
- }
284
- function A(p, M, $, P) {
285
- const E = p.table?.id ?? f.id, O = $ === "header" ? -1 : d.get(E) ?? 0;
286
- $ !== "header" && d.set(E, O + p.grid.cells.length), o.components.push({
287
- kind: "rect",
288
- leftMm: e.leftMm,
289
- topMm: h,
290
- widthMm: e.widthMm,
291
- heightMm: p.heightMm,
292
- grid: p.grid,
293
- nid: s(M),
294
- table: { ...f, ...p.table, role: $, rowIndex: O, ...P ? { source: P } : {} },
295
- style: t.borderStyle
296
- }), h += p.heightMm;
297
- }
298
- function k(p) {
299
- p <= x() && y(p);
300
- }
301
- return { keepTogether: k, placeGridRow: j, setGroupHeader: (p, M) => {
302
- M ? g.set(p, M) : g.delete(p);
303
- } };
304
- }
305
- function At(e, t) {
306
- if (!e.rowKey) return;
307
- const r = t[e.rowKey];
308
- if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r)))
309
- throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
310
- const n = e.revisionField ? t[e.revisionField] : void 0, o = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
311
- if (n !== void 0 && typeof n != "string" && !(typeof n == "number" && Number.isFinite(n))) throw new Error("业务修订号应为字符串或有限数字");
312
- if (o !== void 0 && typeof o != "string") throw new Error("来源令牌应为字符串");
313
- return { datasetId: e.dataset, rowKey: r, ...n === void 0 ? {} : { revision: n }, ...o === void 0 ? {} : { sourceToken: o } };
314
- }
315
- function fe(e, t) {
316
- const r = /* @__PURE__ */ new Map();
317
- if (!e.rowKey) return r;
318
- const n = /* @__PURE__ */ new Set();
319
- for (const o of t) {
320
- const a = At(e, o), s = JSON.stringify(a.rowKey);
321
- if (n.has(s)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);
322
- n.add(s), r.set(o, a);
323
- }
324
- return r;
325
- }
326
- function Ft(e, t, r, n, o) {
327
- if (!e.grandTotal) return;
328
- const a = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = Q(e)[0], i = a?.fields ?? s?.subtotal ?? [], c = a?.aggregates ?? s?.aggregates ?? [];
329
- if (i.length === 0 && c.length === 0) {
330
- n.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
331
- return;
332
- }
333
- const l = G(r, n.measurer, a?.label ?? "合计", We(e.columns, t, i, c), a?.style ?? {}, Le(e.columns, [...i, ...c.map((u) => u.field)]));
334
- o.placeGridRow(l, "listgt", "grand-total");
335
- }
336
- function me(e) {
337
- if (e?.aborted) {
338
- const t = new Error("报表排版已取消");
339
- throw t.name = "AbortError", t;
340
- }
341
- }
342
- function Q(e) {
343
- const t = e.groups ?? (e.groupBy ? [e.groupBy] : []);
344
- if (t.length > 16) throw new Error("列表最多支持 16 级分组");
345
- return t;
346
- }
347
- function Be(e) {
348
- const t = St(e), r = t.columns.reduce((o, a) => o + a.widthMm, 0), n = r > t.widthMm ? t.widthMm / r : 1;
349
- return n === 1 ? t : { ...t, columns: t.columns.map((o) => ({ ...o, widthMm: o.widthMm * n })) };
350
- }
351
- function Ot(e, t, r) {
352
- const n = e.detail;
353
- if (!n) return;
354
- const o = /* @__PURE__ */ new Set();
355
- for (const l of t) {
356
- const u = se(l[n.parentKey]);
357
- if (o.has(u)) throw new Error("主从明细的主表关联键重复");
358
- o.add(u);
359
- }
360
- const a = r.datasets[n.dataset] ?? [], s = /* @__PURE__ */ new Map(), i = [];
361
- for (const l of a) {
362
- const u = l[n.foreignKey];
363
- if (!Ve(u) && n.unmatched === "ignore") continue;
364
- const f = se(u);
365
- if (!o.has(f)) {
366
- if (n.unmatched !== "ignore") throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);
367
- continue;
368
- }
369
- const d = s.get(f);
370
- d ? d.push(l) : s.set(f, [l]), i.push(l);
371
- }
372
- const c = Be({ ...e, id: `${e.id ?? e.dataset}:detail`, dataset: n.dataset, rowKey: n.rowKey, revisionField: n.revisionField, sourceTokenField: n.sourceTokenField, computed: void 0, columns: n.columns, headerGrid: void 0, rowHeightMm: n.rowHeightMm ?? e.rowHeightMm, detail: void 0 });
373
- return { list: c, inter: { ...je(c, r.measurer), rowHeightFloorMm: c.rowHeightMm ?? 0 }, rows: s, sources: fe(c, i) };
374
- }
375
- function Ve(e) {
376
- return typeof e == "string" && !!e.trim() || typeof e == "number" && Number.isFinite(e);
377
- }
378
- function se(e) {
379
- if (!Ve(e)) throw new Error("主从关联键必须是非空字符串或有限数字");
380
- return Ne(e);
381
- }
382
- function* Kt(e, t, r, n, o) {
383
- if (!r) return;
384
- const a = r.rows.get(se(t[e.detail.parentKey])) ?? [];
385
- if (!a.length) return;
386
- const s = { id: `${n.tableId}:detail`, columnKeys: r.list.columns.map((i) => i.field), title: e.detail.label };
387
- e.detail.label && o.placeGridRow({ ...G(r.inter, n.measurer, e.detail.label, /* @__PURE__ */ new Map(), {}, r.list.columns.length), table: s }, "listdl", "group-header"), e.detail.header !== !1 && o.placeGridRow({ grid: r.inter.headerGrid, heightMm: r.inter.headerHeightMm, table: s }, "listdh", "header"), yield* n.takePages();
388
- for (const i of a)
389
- me(n.signal), o.placeGridRow({ ...oe(r.inter, i, n.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* n.takePages();
390
- }
391
- function jt(e, t) {
392
- if (!e.matrix) return { list: e, rows: t };
393
- if (e.detail || e.groupBy || e.groups?.length || e.grandTotal) throw new Error("矩阵不能同时配置普通分组、总计或主从明细");
394
- const r = xt(t, e.matrix), n = r.columns.map((a, s) => ({ ...a, widthMm: s === 0 ? e.matrix.rowWidthMm ?? 40 : e.matrix.columnWidthMm ?? 28, editable: !1, align: s === 0 ? "center" : "right" })), o = { ...e, columns: n, headerGrid: void 0, rowKey: void 0, revisionField: void 0, sourceTokenField: void 0 };
395
- return e.layout === "wide" && (o.widthMm = n.reduce((a, s) => a + s.widthMm, 0)), { list: o, rows: r.rows };
396
- }
397
- function Nt(e, t, r) {
398
- const n = r.prepared.get(e);
399
- if (n) return n;
400
- let o = e.computed?.length ? Fe(t, { fields: e.computed, signal: r.signal, formula: r.formula }).rows : t;
401
- const a = o === t ? void 0 : new Map(o.map((i, c) => [i, t[c]]));
402
- e.rowVisibleWhen && (o = o.filter((i) => L(i, e.rowVisibleWhen)));
403
- const s = jt(e, o);
404
- if (!e.matrix) {
405
- const i = fe(e, a ? o.map((c) => a.get(c)) : o);
406
- s.sources = a ? new Map(o.map((c) => [c, i.get(a.get(c))])) : i;
407
- }
408
- return r.prepared.set(e, s), s;
409
- }
410
- function* Ht(e, t, r) {
411
- const n = Nt(e, t, r), o = n.rows;
412
- e = n.list, e.layout === "wide" && (r.current.widthMm = Math.max(r.current.widthMm, e.leftMm + e.widthMm + r.current.marginRightMm));
413
- const a = n.sources ?? fe(e, o), s = Be(e), i = Q(s), c = { ...je(s, r.measurer), rowHeightFloorMm: s.rowHeightMm ?? 0 }, l = It(s, c, r), u = Ot(s, o, r);
414
- let f;
415
- for (const d of He(o, i)) {
416
- if (me(r.signal), d.kind === "row")
417
- l.placeGridRow(f ?? oe(c, d.row, r.measurer), "listr", "body", a.get(d.row)), f = void 0, yield* r.takePages(), yield* Kt(s, d.row, u, r, l);
418
- else if (d.kind === "groupHeader") {
419
- const g = G(c, r.measurer, d.label, /* @__PURE__ */ new Map(), d.group.headerStyle ?? {}, s.columns.length);
420
- f ??= oe(c, d.firstRow, r.measurer);
421
- const w = i.slice(d.depth + 1).reduce((m, h) => m + G(c, r.measurer, (h.headerTemplate ?? "{value}").replace(/\{value\}/g, de(d.firstRow[h.field])), /* @__PURE__ */ new Map(), h.headerStyle ?? {}, s.columns.length).heightMm, 0);
422
- d.group.keepWithNext !== !1 && l.keepTogether(g.heightMm + w + f.heightMm), l.placeGridRow(g, "listg", "group-header"), d.group.repeatHeader && l.setGroupHeader(d.depth, g);
423
- } else if (d.kind === "subtotal") {
424
- const g = d.group.subtotal ?? [], w = d.group.aggregates ?? [], m = G(c, r.measurer, d.label, We(s.columns, d.rows, g, w), d.group.subtotalStyle ?? {}, Le(s.columns, [...g, ...w.map((h) => h.field)]));
425
- l.placeGridRow(m, "listst", "subtotal");
426
- } else l.setGroupHeader(d.depth);
427
- yield* r.takePages();
428
- }
429
- Ft(s, o, c, r, l), yield* r.takePages();
430
- }
431
- function J(e) {
432
- return e.kind !== "list" && (e.pageAnchor !== void 0 || e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}")));
433
- }
434
- function X(e, t) {
435
- return {
436
- ...e,
437
- ...e.text === void 0 ? {} : { text: t(e.text) },
438
- ...e.lines ? { lines: e.lines.map(t) } : {},
439
- ...e.richParagraphs ? { richParagraphs: e.richParagraphs.map((r) => ({ ...r, segments: r.segments.map((n) => ({ ...n, ...n.text === void 0 ? {} : { text: t(n.text) } })) })) } : {},
440
- ...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((o) => X(o, t)) } : {} } : null)) } } : {}
441
- };
442
- }
443
- function Wt(e) {
444
- let t = !1;
445
- for (const r of e.pages) for (const n of r.components) J(n) && X(n, (o) => (o.includes("{totalPages}") && (t = !0), o));
446
- return t;
447
- }
448
- function Lt(e, t, r, n, o, a) {
449
- const s = {
450
- pageWidthMm: t.widthMm,
451
- pageHeightMm: t.heightMm,
452
- ...e.layout === void 0 ? {} : { layout: e.layout },
453
- marginTopMm: t.marginTopMm,
454
- marginBottomMm: t.marginBottomMm,
455
- marginLeftMm: t.marginLeftMm,
456
- marginRightMm: t.marginRightMm,
457
- components: t.components
458
- }, i = (c) => {
459
- const l = c.replace(/\{page\}/g, String(n));
460
- return a === void 0 ? l : l.replace(/\{totalPages\}/g, String(a));
461
- };
462
- for (const c of r) s.components.push(X(c, i));
463
- if (e.layout === "wide") {
464
- const c = s.components.reduce((l, u) => Math.max(l, u.topMm + u.heightMm), 0);
465
- s.marginBottomMm = o ? e.marginBottomMm ?? 0 : 0, s.pageHeightMm = Math.max(1, c + s.marginBottomMm);
466
- }
467
- return s;
468
- }
469
- function Ge(e) {
470
- return e.cells.reduce((t, r) => t + r.reduce((n, o) => n + (o ? 1 + (o.children?.reduce((a, s) => a + De(s), 0) ?? 0) : 0), 0), 0);
471
- }
472
- function De(e) {
473
- return e.grid ? Ge(e.grid) : 0;
474
- }
475
- function ge(e) {
476
- for (const t of ["maxPages", "maxCells", "knownTotalPages"]) if (e[t] !== void 0 && (!Number.isSafeInteger(e[t]) || e[t] < 1)) throw new RangeError(`${t} 应为正安全整数`);
477
- }
478
- function* _(e, t, r, n, o, a = /* @__PURE__ */ new WeakMap()) {
479
- let s = 0, i = 0, c = 0;
480
- const l = (u) => `${u}_${(++s).toString(36)}`;
481
- for (const [u, f] of e.pages.entries()) {
482
- me(r.signal);
483
- const d = Pt(f), g = f.components.filter(J);
484
- let w = [];
485
- const m = (v = !1) => {
486
- if (r.maxPages !== void 0 && i >= r.maxPages) throw new B(r.maxPages, i + 1);
487
- if (r.maxCells !== void 0 && (c += [...d.components, ...g].reduce((x, y) => x + De(y), 0), c > r.maxCells))
488
- throw new V(r.maxCells, c);
489
- w.push(Lt(f, d, g, ++i, v, o));
490
- }, h = () => {
491
- const v = w;
492
- return w = [], v;
493
- };
494
- for (const [v, x] of f.components.entries()) {
495
- if (J(x)) continue;
496
- if (x.kind !== "list") {
497
- d.components.push(x);
498
- continue;
499
- }
500
- const y = t[x.dataset];
501
- Array.isArray(y) || n.push(`数据集 ${x.dataset} 未提供数据,列表 ${x.id ?? ""} 输出为空`), yield* Ht(x, Array.isArray(y) ? y : [], {
502
- templatePage: f,
503
- current: d,
504
- warnings: n,
505
- nextId: l,
506
- pushCurrent: m,
507
- takePages: h,
508
- datasets: t,
509
- signal: r.signal,
510
- formula: r.formula,
511
- prepared: a,
512
- measurer: r.measurer ?? wt,
513
- mmPerRow: r.mmPerRow ?? 0,
514
- tableId: `table:${u}:${v}`
515
- });
516
- }
517
- m(!0), yield* h();
518
- }
519
- }
520
- function Vr(e, t, r = {}) {
521
- ge(r);
522
- let n = 0;
523
- for (const o of _(e, t, { ...r }, [])) n++;
524
- return n;
525
- }
526
- function* Bt(e, t, r = {}) {
527
- ge(r);
528
- const n = Wt(e), o = /* @__PURE__ */ new WeakMap();
529
- let a = r.knownTotalPages;
530
- if (n && a === void 0) {
531
- a = 0;
532
- for (const c of _(e, t, r, [], void 0, o)) a++;
533
- }
534
- const s = [];
535
- let i = 0;
536
- for (const c of _(e, t, r, s, a, o)) {
537
- for (; i < s.length; i++) r.onWarning?.(s[i]);
538
- yield c;
539
- }
540
- }
541
- function he(e, t, r = {}) {
542
- const n = typeof r == "number" ? { mmPerRow: r } : r;
543
- ge(n);
544
- const o = [], a = [..._(e, t, n, o, n.knownTotalPages)];
545
- for (const s of a) s.components = s.components.map((i) => J(i) ? X(i, (c) => c.replace(/\{totalPages\}/g, String(a.length))) : i);
546
- return o.forEach((s) => n.onWarning?.(s)), { plan: { schemaVersion: U, ...Y(e) ? { requiresRecalculation: !0 } : {}, pages: a }, warnings: o };
547
- }
548
- function Vt(e) {
549
- const t = e.columns.find((a) => !a.hidden)?.field;
550
- if (!t) return { groups: 0, total: 0 };
551
- const r = Q(e), n = (a = [], s = []) => a.includes(t) || s.some((i) => i.field === t), o = typeof e.grandTotal == "object" ? e.grandTotal : void 0;
552
- return { groups: r.filter((a) => n(a.subtotal, a.aggregates)).length, total: Number(n(o?.fields ?? r[0]?.subtotal, o?.aggregates ?? r[0]?.aggregates)) };
553
- }
554
- function Gr(e, t, r = {}) {
555
- if (e.matrix) {
556
- let c = t[e.dataset] ?? [];
557
- e.computed?.length && (c = Fe(c, { fields: e.computed, ...r }).rows), e.rowVisibleWhen && (c = c.filter((u) => L(u, e.rowVisibleWhen)));
558
- const l = bt(c, e.matrix);
559
- return l.cells + l.columnCount;
560
- }
561
- const n = t[e.dataset]?.length ?? 0, o = e.columns.filter((c) => !c.hidden).length, a = Q(e).length, s = Vt(e);
562
- let i = (n * (1 + 2 * a + s.groups) + +!!e.grandTotal * (1 + s.total)) * o;
563
- if (i += e.headerGrid ? Ge(e.headerGrid) : o, e.detail) {
564
- const c = t[e.detail.dataset]?.length ?? 0, l = e.detail.columns.filter((u) => !u.hidden).length;
565
- i += (c + n * (+(e.detail.header !== !1) + +!!e.detail.label)) * l;
566
- }
567
- if (!Number.isSafeInteger(i)) throw new RangeError("报表单元格估算超出安全整数预算");
568
- return i;
569
- }
570
- function qe(e) {
571
- return !e || typeof e != "object" ? !1 : [e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex].every((t) => Number.isInteger(t) && t >= 0);
572
- }
573
- function ze(e, t, r) {
574
- const n = e.grid;
575
- if (!n) return null;
576
- const o = n.cells[t];
577
- if (!o) return null;
578
- const s = le(n, e.widthMm, e.heightMm).cells.filter((c) => c.ri === t).findIndex((c) => c.ci === r), i = o[s];
579
- return i ? { cell: i, sourceColumnIndex: s } : null;
580
- }
581
- function Gt(e) {
582
- return e.value !== void 0 ? e.value : e.rawText ?? e.text ?? null;
583
- }
584
- function Dt(e, t) {
585
- return e.valueType ? e.valueType : typeof t == "number" ? "number" : typeof t == "boolean" ? "boolean" : t === null && e.numberFormat && /[0#?]/.test(e.numberFormat) ? "number" : "text";
586
- }
587
- function qt(e, t) {
588
- if (e.derived) return "derived";
589
- if (e.editable === !1) return "cell";
590
- if (e.formula !== void 0) return "formula";
591
- if (e.children?.length) return "complex";
592
- if (t.table && t.table.role !== "body" && e.editable !== !0) return "structure";
593
- }
594
- function zt(e, t) {
595
- const r = e.table;
596
- if (r)
597
- return {
598
- id: r.id,
599
- rowIndex: r.rowIndex + t.rowIndex,
600
- role: r.role,
601
- columnKey: r.columnKeys[t.columnIndex]
602
- };
603
- }
604
- function Jt(e, t, r) {
605
- if (e.derived) return;
606
- if (e.source) return { ...e.source };
607
- const n = t.table?.source, o = t.table?.columnKeys[r.columnIndex];
608
- if (!(!n || n.rowKey === void 0 || o === void 0))
609
- return { ...n, rowKey: n.rowKey, field: o };
610
- }
611
- function Je(e, t, r) {
612
- const n = Gt(r), o = qt(r, e);
613
- return {
614
- address: { ...t },
615
- cell: r,
616
- component: e,
617
- value: n,
618
- valueType: Dt(r, n),
619
- table: zt(e, t),
620
- source: Jt(r, e, t),
621
- editable: o === void 0,
622
- readOnlyReason: o
623
- };
624
- }
625
- function pe(e, t) {
626
- if (!qe(t)) return null;
627
- const r = e.pages[t.pageIndex]?.components[t.componentIndex];
628
- if (!r) return null;
629
- const n = ze(r, t.rowIndex, t.columnIndex);
630
- return n ? Je(r, t, n.cell) : null;
631
- }
632
- function W(e) {
633
- const t = /* @__PURE__ */ new Map();
634
- return (r) => {
635
- if (!qe(r)) return null;
636
- const n = e.pages[r.pageIndex]?.components[r.componentIndex];
637
- if (!n?.grid) return null;
638
- let o = t.get(n);
639
- if (!o) {
640
- const s = /* @__PURE__ */ new Map();
641
- o = /* @__PURE__ */ new Map();
642
- for (const i of le(n.grid, n.widthMm, n.heightMm).cells) {
643
- const c = s.get(i.ri) ?? 0;
644
- s.set(i.ri, c + 1);
645
- const l = n.grid.cells[i.ri]?.[c];
646
- l && o.set(`${i.ri}:${i.ci}`, l);
647
- }
648
- t.set(n, o);
649
- }
650
- const a = o.get(`${r.rowIndex}:${r.columnIndex}`);
651
- return a ? Je(n, r, a) : null;
652
- };
653
- }
654
- class b extends Error {
655
- constructor(t) {
656
- super(`Invalid report cell edit: ${t}`), this.code = t, this.name = "ReportCellEditError";
657
- }
658
- }
659
- function _t(e, t) {
660
- let r = e.trim();
661
- const n = t && r.endsWith("%");
662
- if (n && (r = r.slice(0, -1).trim()), /^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(r) && (r = r.replace(/,/g, "")), !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(r)) throw new b("number");
663
- return Number(r) / (n ? 100 : 1);
664
- }
665
- function Ut(e, t) {
666
- if (e === null || typeof e == "string" && e.trim() === "") return null;
667
- if (typeof e != "string" && typeof e != "number") throw new b("number");
668
- const r = typeof e == "number" ? e : _t(e, gt(t.cell.numberFormat));
669
- if (!Number.isFinite(r) || Number.isInteger(r) && !Number.isSafeInteger(r)) throw new b("number");
670
- return r;
671
- }
672
- function Yt(e) {
673
- if (e === null || typeof e == "string" && e.trim() === "") return null;
674
- if (typeof e == "boolean") return e;
675
- const t = String(e).trim().toLowerCase();
676
- if (["true", "yes", "是", "1"].includes(t)) return !0;
677
- if (["false", "no", "否", "0"].includes(t)) return !1;
678
- throw new b("boolean");
679
- }
680
- function _e(e, t) {
681
- return e.valueType === "number" ? Ut(t, e) : e.valueType === "boolean" ? Yt(t) : t === null ? null : String(t);
682
- }
683
- function Qt(e, t) {
684
- const r = t.cell.text, o = [["是", "否"], ["TRUE", "FALSE"], ["True", "False"], ["true", "false"], ["1", "0"]].find((a) => a.includes(r ?? ""));
685
- return o ? o[e ? 0 : 1] : String(e);
686
- }
687
- function D(e, t) {
688
- return t === null ? "" : typeof t == "boolean" ? Qt(t, e) : typeof t == "number" ? mt(t, e.cell.numberFormat) : String(t);
689
- }
690
- function Dr(e, t, r) {
691
- const n = pe(e, t);
692
- if (!n) throw new b("missing");
693
- return q(n, r);
694
- }
695
- function q(e, t) {
696
- if (!e.editable) throw new b("readonly");
697
- const r = _e(e, t);
698
- return {
699
- address: { ...e.address },
700
- table: e.table,
701
- source: e.source,
702
- previousValue: e.value,
703
- previousText: e.cell.text ?? "",
704
- value: r,
705
- text: D(e, r)
706
- };
707
- }
708
- function Xt(e, t) {
709
- const r = e.table, n = t.table;
710
- return !r || !n || r.columnKey === void 0 ? !1 : r.id === n.id && r.rowIndex === n.rowIndex && r.role === n.role && r.columnKey === n.columnKey;
711
- }
712
- function Ue(e, t, r) {
713
- const n = e.grid, { rowIndex: o, columnIndex: a } = t.address, s = ze(e, o, a), i = [...n.cells], c = [...i[o]], l = D(t, r.value), u = { ...s.cell, value: r.value, text: l, rawText: l };
714
- return c[s.sourceColumnIndex] = u, i[o] = c, { ...e, grid: { ...n, cells: i } };
715
- }
716
- function Zt(e, t) {
717
- const r = e.table?.columnKeys, n = t.table?.columnKey;
718
- return r && n !== void 0 ? r.flatMap((o, a) => o === n ? [a] : []) : [];
719
- }
720
- function er(e, t, r, n, o, a) {
721
- const s = t.table, i = o.table;
722
- if (!s || !i || s.id !== i.id || s.role !== i.role || !t.grid) return t;
723
- const c = i.rowIndex - s.rowIndex;
724
- if (c < 0 || c >= t.grid.cells.length) return t;
725
- let l = t;
726
- for (const u of Zt(t, o)) {
727
- const f = pe(e, { pageIndex: r, componentIndex: n, rowIndex: c, columnIndex: u });
728
- f?.editable && Xt(o, f) && (l = Ue(l, f, a));
729
- }
730
- return l;
731
- }
732
- function tr(e, t, r, n, o, a) {
733
- const s = o.address;
734
- return o.table?.columnKey !== void 0 ? er(e, t, r, n, o, a) : s.pageIndex === r && s.componentIndex === n ? Ue(t, o, a) : t;
735
- }
736
- function we(e, t) {
737
- const r = t.source;
738
- if (!r) return !1;
739
- const n = e.source;
740
- return !n || ["datasetId", "rowKey", "field", "revision", "sourceToken"].some((o) => !Object.is(n[o], r[o]));
741
- }
742
- function qr(e, t) {
743
- const r = pe(e, t.address);
744
- if (!r) throw new b("missing");
745
- if (!r.editable) throw new b("readonly");
746
- if (we(r, t)) throw new b("conflict");
747
- if (!Object.is(r.value, t.previousValue) || (r.cell.text ?? "") !== t.previousText) throw new b("conflict");
748
- const n = _e(r, t.value), o = { ...t, value: n, text: D(r, n) };
749
- if (Object.is(n, r.value) && o.text === r.cell.text) return e;
750
- const a = e.pages.map((s, i) => {
751
- const c = s.components.map((l, u) => tr(e, l, i, u, r, o));
752
- return c.every((l, u) => l === s.components[u]) ? s : { ...s, components: c };
753
- });
754
- return { ...e, pages: a };
755
- }
756
- function rr(e, t, r) {
757
- if (!r || r.revision === void 0 && r.sourceToken === void 0) return e;
758
- const n = new Set(t.edits.flatMap((s) => s.source ? [s.source.datasetId] : []));
759
- if (!n.size) return e;
760
- function o(s) {
761
- return !s.datasetId || !n.has(s.datasetId) || (r.revision === void 0 || Object.is(r.revision, s.revision)) && (r.sourceToken === void 0 || r.sourceToken === s.sourceToken) ? s : { ...s, ...r.revision !== void 0 ? { revision: r.revision } : {}, ...r.sourceToken !== void 0 ? { sourceToken: r.sourceToken } : {} };
762
- }
763
- const a = e.pages.map((s) => {
764
- const i = s.components.map((c) => {
765
- const l = c.table?.source ? o(c.table.source) : void 0, u = c.table && l !== c.table.source ? { ...c.table, source: l } : c.table, f = c.grid?.cells.map((g) => {
766
- const w = g.map((m) => {
767
- if (!m?.source) return m;
768
- const h = o(m.source);
769
- return h === m.source ? m : { ...m, source: h };
770
- });
771
- return w.some((m, h) => m !== g[h]) ? w : g;
772
- }), d = c.grid && f?.some((g, w) => g !== c.grid.cells[w]) ? { ...c.grid, cells: f } : c.grid;
773
- return u !== c.table || d !== c.grid ? { ...c, table: u, grid: d } : c;
774
- });
775
- return i.some((c, l) => c !== s.components[l]) ? { ...s, components: i } : s;
776
- });
777
- return a.some((s, i) => s !== e.pages[i]) ? { ...e, pages: a } : e;
778
- }
779
- function nr(e) {
780
- return JSON.stringify([e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex]);
781
- }
782
- function xe(e) {
783
- const t = e.table;
784
- return t?.columnKey !== void 0 ? JSON.stringify([t.id, t.role, t.rowIndex, t.columnKey]) : nr(e.address);
785
- }
786
- function or(e, t) {
787
- if (!t.length) return e;
788
- const r = new Map(t.map((c) => [xe(c), c])), n = new Set(t.flatMap((c) => c.table ? [c.table.id] : [])), o = new Set(t.map((c) => `${c.address.pageIndex}:${c.address.componentIndex}`)), a = W(e);
789
- function s(c, l, u) {
790
- const f = c.grid;
791
- if (!f || !o.has(`${l}:${u}`) && !n.has(c.table?.id ?? "")) return c;
792
- const d = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map();
793
- for (const w of le(f, c.widthMm, c.heightMm).cells) {
794
- const m = g.get(w.ri) ?? 0;
795
- g.set(w.ri, m + 1);
796
- const h = a({ pageIndex: l, componentIndex: u, rowIndex: w.ri, columnIndex: w.ci }), v = h && r.get(xe(h));
797
- if (!v || !h.editable) continue;
798
- const x = d.get(w.ri) ?? [...f.cells[w.ri]], y = D(h, v.value);
799
- Object.is(h.value, v.value) && y === h.cell.text || (x[m] = { ...w.cell, value: v.value, text: y, rawText: y }, d.set(w.ri, x));
800
- }
801
- return d.size ? { ...c, grid: { ...f, cells: f.cells.map((w, m) => d.get(m) ?? w) } } : c;
802
- }
803
- const i = e.pages.map((c, l) => {
804
- const u = c.components.map((f, d) => s(f, l, d));
805
- return u.every((f, d) => f === c.components[d]) ? c : { ...c, components: u };
806
- });
807
- return i.every((c, l) => c === e.pages[l]) ? e : { ...e, pages: i };
808
- }
809
- function I(e) {
810
- const t = e.source;
811
- if (t) return JSON.stringify([t.datasetId, t.rowKey, t.field]);
812
- const r = e.table;
813
- if (r?.columnKey !== void 0) return JSON.stringify([r.id, r.role, r.rowIndex, r.columnKey]);
814
- const n = e.address;
815
- return JSON.stringify([n.pageIndex, n.componentIndex, n.rowIndex, n.columnIndex]);
816
- }
817
- function zr(e, t, r) {
818
- if (typeof r != "string" || !r.trim() || !Array.isArray(t)) throw new b("missing");
819
- if (t.length > 1e4) throw new b("limit");
820
- const n = /* @__PURE__ */ new Set(), o = W(e), a = t.map(({ address: s, value: i }) => {
821
- const c = o(s);
822
- if (!c) throw new b("missing");
823
- const l = q(c, i), u = I(l);
824
- if (n.has(u)) throw new b("duplicate");
825
- return n.add(u), l;
826
- });
827
- return { requestId: r, edits: a };
828
- }
829
- function Jr(e, t) {
830
- if (t.edits.length > 1e4) throw new b("limit");
831
- const r = W(e), n = /* @__PURE__ */ new Set(), o = t.edits.map((a) => {
832
- const s = r(a.address);
833
- if (!s) throw new b("missing");
834
- const i = I(a);
835
- if (n.has(i)) throw new b("duplicate");
836
- if (n.add(i), we(s, a) || !Object.is(s.value, a.previousValue) || (s.cell.text ?? "") !== a.previousText) throw new b("conflict");
837
- return q(s, a.value);
838
- });
839
- return or(e, o);
840
- }
841
- function _r(e) {
842
- const t = /* @__PURE__ */ new Map();
843
- for (const r of e) {
844
- const n = I(r), o = t.get(n), a = o ? { ...r, previousValue: o.previousValue, previousText: o.previousText } : { ...r };
845
- Object.is(a.previousValue, a.value) ? t.delete(n) : t.set(n, a);
846
- }
847
- return [...t.values()];
848
- }
849
- function H(e, t) {
850
- for (let r = 0; r < t.length; r++) {
851
- const n = t.charCodeAt(r);
852
- e.first = Math.imul(e.first ^ n, 16777619), e.second = Math.imul(e.second, 33) ^ n, e.count++;
853
- }
854
- }
855
- function sr(e, t, r) {
856
- const n = Object.getOwnPropertyDescriptor(e, t);
857
- if (!n || n.get || n.set) throw new b("conflict");
858
- H(r, `${t.length}:${t}`), Ye(n.value, r);
859
- }
860
- function ar(e, t) {
861
- if (Object.getOwnPropertyDescriptor(e, "toJSON")) throw new b("conflict");
862
- if (t.active.has(e)) throw new b("conflict");
863
- if (t.active.add(e), e instanceof Date) H(t, `date:${Date.prototype.getTime.call(e)};`);
864
- else {
865
- const r = Object.getPrototypeOf(e);
866
- if (!Array.isArray(e) && r !== Object.prototype && r !== null) throw new b("conflict");
867
- const n = Object.keys(e);
868
- H(t, `${Array.isArray(e) ? "array" : "object"}:${Array.isArray(e) ? e.length : n.length}:{`), n.forEach((o) => sr(e, o, t)), H(t, "}");
869
- }
870
- t.active.delete(e);
871
- }
872
- function Ye(e, t) {
873
- if (++t.nodes > 1e6) throw new b("limit");
874
- if (e === null) {
875
- H(t, "null;");
876
- return;
877
- }
878
- if (typeof e == "object") {
879
- ar(e, t);
880
- return;
881
- }
882
- if (typeof e == "function" || typeof e == "symbol") throw new b("conflict");
883
- const r = String(e);
884
- H(t, `${typeof e}:${r.length}:${r};`);
885
- }
886
- function Me(e) {
887
- const t = { first: 2166136261, second: 5381, count: 0, nodes: 0, active: /* @__PURE__ */ new Set() };
888
- return Ye(e, t), `${t.count}:${t.first >>> 0}:${t.second >>> 0}`;
889
- }
890
- function ae(e, t, r) {
891
- if (++r.nodes > 1e6) throw new b("limit");
892
- if (typeof e == "string" && (r.text += e.length, r.text > 32 * 1024 * 1024))
893
- throw new b("limit");
894
- if (e === null || typeof e != "object") return e;
895
- if (t.has(e)) throw new b("conflict");
896
- if (e instanceof Date) return new Date(Date.prototype.getTime.call(e));
897
- t.add(e);
898
- const n = Array.isArray(e) ? e.map((o) => ae(o, t, r)) : Object.fromEntries(Object.entries(e).map(([o, a]) => [o, ae(a, t, r)]));
899
- return t.delete(e), n;
900
- }
901
- function ir(e) {
902
- return ae(e, /* @__PURE__ */ new Set(), { nodes: 0, text: 0 });
903
- }
904
- function Qe(e) {
905
- const t = [];
906
- for (const r of e.template.pages) for (const n of r.components)
907
- n.kind === "list" && (t.push(n), n.detail && t.push({ ...n.detail, relation: { detail: n.detail, parentRows: e.datasets[n.dataset] ?? [] } }));
908
- return t;
909
- }
910
- function $e(e) {
911
- return JSON.stringify([e.datasetId, e.rowKey]);
912
- }
913
- function Xe(e) {
914
- const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
915
- return e.forEach((n, o) => {
916
- for (const a of Qe(n)) {
917
- if (!a.rowKey) continue;
918
- const s = a.relation, i = s ? new Set(s.parentRows.map((c) => JSON.stringify(c[s.detail.parentKey]))) : void 0;
919
- (n.datasets[a.dataset] ?? []).forEach((c, l) => {
920
- if (s && !i.has(JSON.stringify(c[s.detail.foreignKey]))) return;
921
- const u = c[a.rowKey];
922
- if (typeof u != "string" && typeof u != "number") return;
923
- const f = `${o}:${a.dataset}:${l}:${a.rowKey}`;
924
- if (r.has(f)) return;
925
- r.add(f);
926
- const d = $e({ datasetId: a.dataset, rowKey: u }), g = t.get(d) ?? [];
927
- g.push({ partIndex: o, dataset: a.dataset, rowIndex: l, row: c, binding: a }), t.set(d, g);
928
- });
929
- }
930
- }), (n) => {
931
- const o = t.get($e(n));
932
- if (!o?.length) throw new b("missing");
933
- if (new Set(o.map((a) => `${a.partIndex}:${a.dataset}`)).size !== o.length) throw new b("conflict");
934
- return o;
935
- };
936
- }
937
- function Ze(e, t) {
938
- const r = e.map((o) => ({ ...o, datasets: { ...o.datasets } })), n = /* @__PURE__ */ new Set();
939
- for (const { row: o, field: a, value: s } of t) {
940
- const i = r[o.partIndex], c = `${o.partIndex}:${o.dataset}`;
941
- n.has(c) || (i.datasets[o.dataset] = [...i.datasets[o.dataset]], n.add(c)), i.datasets[o.dataset][o.rowIndex] = { ...i.datasets[o.dataset][o.rowIndex], [a]: s };
942
- }
943
- return r;
944
- }
945
- function cr(e, t, r) {
946
- const n = [], o = /* @__PURE__ */ new Set();
947
- return e.forEach((a, s) => {
948
- for (const i of Qe(a))
949
- t.has(i.dataset) && (a.datasets[i.dataset] ?? []).forEach((c, l) => {
950
- const u = { partIndex: s, dataset: i.dataset, rowIndex: l, row: c, binding: i };
951
- for (const [f, d] of [[i.revisionField, r.revision], [i.sourceTokenField, r.sourceToken]]) {
952
- if (!f || d === void 0) continue;
953
- const g = `${s}:${i.dataset}:${l}:${f}`;
954
- o.has(g) || (o.add(g), n.push({ row: u, field: f, value: d }));
955
- }
956
- });
957
- }), n;
958
- }
959
- function et(e) {
960
- const t = /* @__PURE__ */ new Map(), r = W(e);
961
- return e.pages.forEach((n, o) => n.components.forEach((a, s) => {
962
- if (!(!a.grid || a.table?.role !== "body"))
963
- for (let i = 0; i < a.grid.cells.length; i++) for (let c = 0; c < a.table.columnKeys.length; c++) {
964
- const l = r({ pageIndex: o, componentIndex: s, rowIndex: i, columnIndex: c });
965
- l?.source && l.editable && t.set(I(l), l);
966
- }
967
- })), t;
968
- }
969
- function Ur(e, t, r) {
970
- const n = et(e), o = W(e);
971
- return t.map((a) => {
972
- const s = a.source ? n.get(I(a)) : o(a.address);
973
- if (!s || I(s) !== I(a)) throw new b("missing");
974
- return { address: { ...s.address }, value: a[r] };
975
- });
976
- }
977
- async function tt(e, t, r = {}) {
978
- const n = [], o = { ...r, knownTotalPages: void 0 };
979
- for (const a of Bt(e, t, o))
980
- n.push(a), n.length % 8 === 0 && await new Promise((s) => setTimeout(s, 0));
981
- if (r.signal?.aborted) {
982
- const a = new Error("报表重算已取消");
983
- throw a.name = "AbortError", a;
984
- }
985
- return { schemaVersion: U, ...Y(e) ? { requiresRecalculation: !0 } : {}, pages: n };
986
- }
987
- const ie = /* @__PURE__ */ new WeakMap();
988
- function Yr(e) {
989
- return ie.get(e);
990
- }
991
- function z(e) {
992
- if (e?.aborted) {
993
- const t = new Error("报表重算已取消");
994
- throw t.name = "AbortError", t;
995
- }
996
- }
997
- function rt(e, t) {
998
- return e[t] === void 0 ? "" : e[t];
999
- }
1000
- function lr(e, t) {
1001
- if (t.edits.length > 1e4) throw new b("limit");
1002
- const r = W(e), n = /* @__PURE__ */ new Set(), o = [], a = t.edits.map((s) => {
1003
- const i = r(s.address);
1004
- if (!i?.source) throw new b("missing");
1005
- const c = I(s);
1006
- if (n.has(c)) throw new b("duplicate");
1007
- if (n.add(c), we(i, s) || !Object.is(i.value, s.previousValue) || (i.cell.text ?? "") !== s.previousText) throw new b("conflict");
1008
- return o.push(i), q(i, s.value);
1009
- });
1010
- return { batch: { requestId: t.requestId, edits: a }, contexts: o };
1011
- }
1012
- function ur(e, t) {
1013
- const r = Xe(e);
1014
- return t.flatMap((n) => {
1015
- if (!n.source) throw new b("missing");
1016
- return r(n.source).map((o) => {
1017
- if (!Object.is(rt(o.row, n.source.field), n.previousValue)) throw new b("conflict");
1018
- if (o.binding.rowKey === n.source.field) throw new b("readonly");
1019
- return { row: o, field: n.source.field, value: n.value };
1020
- });
1021
- });
1022
- }
1023
- function te(e, t, r) {
1024
- const n = { ...e, value: t, source: { ...e.source, ...r?.revision === void 0 ? {} : { revision: r.revision }, ...r?.sourceToken === void 0 ? {} : { sourceToken: r.sourceToken } } };
1025
- return n.cell = { ...e.cell, value: n.value, text: D(n, n.value) }, n;
1026
- }
1027
- function dr(e, t, r) {
1028
- if (!r || r.revision === void 0 && r.sourceToken === void 0) return [...e];
1029
- const n = new Set(t.edits.flatMap((o) => o.source ? [o.source.datasetId] : []));
1030
- return Ze(e, cr(e, n, r));
1031
- }
1032
- function nt(e, t) {
1033
- let r = t.parts;
1034
- const n = t.rebuild, o = Me(r);
1035
- let a = e, s;
1036
- const i = /* @__PURE__ */ new Map();
1037
- function c(f) {
1038
- if (f !== a) throw new b("conflict");
1039
- if (s) return s;
1040
- if (Me(r) !== o) throw new b("conflict");
1041
- return ir(r);
1042
- }
1043
- async function l(f, d, g, w = {}) {
1044
- z(w.signal), d = { requestId: d.requestId, edits: d.edits.map((y) => ({ ...y, address: { ...y.address }, source: y.source ? { ...y.source } : void 0, table: y.table ? { ...y.table } : void 0 })) }, g = g.map((y) => ({ ...y, address: { ...y.address }, source: y.source ? { ...y.source } : void 0, table: y.table ? { ...y.table } : void 0, cell: { ...y.cell } })), await new Promise((y) => setTimeout(y, 0)), z(w.signal);
1045
- const m = c(f), h = Ze(m, ur(m, d.edits)), v = await n(h, w.signal);
1046
- z(w.signal);
1047
- let x = !1;
1048
- return { plan: v, commit(y) {
1049
- if (z(w.signal), x || a !== f) throw new b("conflict");
1050
- if (y?.conflicts?.length) throw new b("conflict");
1051
- const j = dr(h, d, y), A = rr(v, d, y);
1052
- if (y) {
1053
- const k = new Set(d.edits.map((C) => C.source.datasetId));
1054
- for (const [C, p] of i) k.has(p.source.datasetId) && i.set(C, te(p, p.value, y));
1055
- }
1056
- return g.forEach((k, C) => i.set(I(k), te(k, d.edits[C].value, y))), x = !0, s = j, r = void 0, a = A, ie.set(a, u), a;
1057
- } };
1058
- }
1059
- const u = {
1060
- get plan() {
1061
- return a;
1062
- },
1063
- async prepare(f, d, g) {
1064
- const w = lr(f, d);
1065
- return l(f, w.batch, w.contexts, g);
1066
- },
1067
- async prepareHistory(f, d, g, w, m) {
1068
- if (!w.trim() || d.length > 1e4) throw new b("limit");
1069
- const h = c(f), v = Xe(h), x = et(f), y = /* @__PURE__ */ new Set(), A = d.map((p) => {
1070
- if (!p.source) throw new b("missing");
1071
- const M = I(p);
1072
- if (y.has(M)) throw new b("duplicate");
1073
- y.add(M);
1074
- const $ = x.get(M) ?? i.get(M);
1075
- if (!$?.source) throw new b("missing");
1076
- const P = v($.source)[0];
1077
- return te($, rt(P.row, $.source.field));
1078
- }).map((p, M) => ({ context: p, edit: q(p, d[M][g]) })).filter(({ edit: p }) => !Object.is(p.previousValue, p.value)), k = { requestId: w, edits: A.map(({ edit: p }) => p) }, C = A.map(({ context: p }) => p);
1079
- return { batch: k, contexts: C, prepared: await l(f, k, C, m) };
1080
- }
1081
- };
1082
- return ie.set(e, u), u;
1083
- }
1084
- function Qr(e) {
1085
- const t = he(e.template, e.datasets, e.pagination).plan;
1086
- return nt(t, { parts: [{ template: e.template, datasets: e.datasets }], rebuild: (r, n) => tt(r[0].template, r[0].datasets, { ...e.pagination, signal: n }) });
1087
- }
1088
- function Xr(e) {
1089
- if (!("mapData" in e)) return e;
1090
- const { load: t, mapData: r, ...n } = e;
1091
- return { ...n, load: async (o) => {
1092
- const a = await t(o);
1093
- R(o.signal);
1094
- try {
1095
- return r(a, o);
1096
- } catch (s) {
1097
- throw new S("validate", `报表 ${o.reportId} 数据映射失败`, s);
1098
- }
1099
- } };
1100
- }
1101
- class S extends Error {
1102
- constructor(t, r, n) {
1103
- super(r), this.name = "ReportSourceError", this.code = t, this.cause = n;
1104
- }
1105
- }
1106
- function Z(e) {
1107
- const t = new Error("报表加载已取消");
1108
- return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
1109
- }
1110
- function R(e) {
1111
- if (e?.aborted) throw Z(e);
1112
- }
1113
- function ce(e, t) {
1114
- return t ? new Promise((r, n) => {
1115
- const o = () => t.removeEventListener("abort", a), a = () => {
1116
- o(), n(Z(t));
1117
- };
1118
- t.addEventListener("abort", a, { once: !0 }), t.aborted && a(), Promise.resolve(e).then(
1119
- (s) => {
1120
- o(), r(s);
1121
- },
1122
- (s) => {
1123
- o(), n(s);
1124
- }
1125
- );
1126
- }) : Promise.resolve(e);
1127
- }
1128
- function fr(e, t) {
1129
- if (!e || typeof e != "object" || Array.isArray(e))
1130
- throw new S("validate", `报表 ${t} 的数据集应为对象`);
1131
- for (const [r, n] of Object.entries(e))
1132
- if (!Array.isArray(n) || n.some((o) => !o || typeof o != "object" || Array.isArray(o)))
1133
- throw new S("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
1134
- }
1135
- async function mr(e, t, r) {
1136
- const { reportId: n, signal: o } = t;
1137
- try {
1138
- const a = await ce(e(t), o);
1139
- R(o);
1140
- const s = ut(a);
1141
- if (!s.ok)
1142
- throw new S("validate", `报表 ${n} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
1143
- return r.push(...s.warnings.map((i) => `${n}: ${i.path}: ${i.message}`)), a;
1144
- } catch (a) {
1145
- throw o?.aborted ? Z(o) : a instanceof S ? a : a instanceof dt ? new S("validate", `报表 ${n} 模板校验失败:${a.message}`, a) : new S("fetch", `报表 ${n} 模板加载失败:${a instanceof Error ? a.message : String(a)}`, a);
1146
- }
1147
- }
1148
- async function gr(e, t, r, n) {
1149
- const o = t.signal;
1150
- let a;
1151
- try {
1152
- if (e.load) a = await ce(e.load(t), o);
1153
- else if (e.provider) {
1154
- const s = await ce(e.provider.query(t), o);
1155
- R(o), hr(s, r), a = s.datasets, n?.(r, s);
1156
- } else a = e.datasets ?? {};
1157
- } catch (s) {
1158
- throw o?.aborted ? Z(o) : s instanceof S ? s : new S("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
1159
- }
1160
- return R(o), a;
1161
- }
1162
- function hr(e, t) {
1163
- if (!e || typeof e != "object" || Array.isArray(e)) throw new S("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
1164
- for (const r of ["revision", "sourceToken"])
1165
- if (e[r] !== void 0 && typeof e[r] != "string") throw new S("validate", `报表 ${t} Provider ${r} 应为字符串`);
1166
- 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))))
1167
- throw new S("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
1168
- }
1169
- function pr(e, t, r) {
1170
- for (const [n, o] of Object.entries(e.dataSchema ?? {})) {
1171
- let a;
1172
- try {
1173
- a = ke(Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0, o, { ...e.dataValidation, path: `$.datasets.${n}` });
1174
- } catch (s) {
1175
- throw new S("config", `报表 ${r} 数据集 ${n} 字段契约配置无效`, s);
1176
- }
1177
- if (!a.ok) throw new S("validate", `报表 ${r} 数据集 ${n} 不符合字段契约:${a.issues[0]?.message}`, { issues: a.issues });
1178
- }
1179
- }
1180
- function ot(e) {
1181
- const t = (r) => r.grid?.cells.reduce((n, o) => n + o.reduce((a, s) => a + (s ? 1 + (s.children?.reduce((i, c) => i + t(c), 0) ?? 0) : 0), 0), 0) ?? 0;
1182
- return e.pages.reduce((r, n) => r + n.components.reduce((o, a) => o + t(a), 0), 0);
1183
- }
1184
- function st(e, t, r, n) {
1185
- return {
1186
- ...e,
1187
- signal: n ?? e?.signal,
1188
- ...t === void 0 ? {} : { maxPages: Math.max(1, Math.min(t, e?.maxPages ?? t)) },
1189
- ...r === void 0 ? {} : { maxCells: Math.max(1, Math.min(r, e?.maxCells ?? r)) }
1190
- };
1191
- }
1192
- function wr(e, t, r, n, o, a) {
1193
- const s = o.maxPages === void 0 ? void 0 : o.maxPages - o.usedPages, i = o.maxCells === void 0 ? void 0 : o.maxCells - o.usedCells;
1194
- try {
1195
- if (s !== void 0 && s < 1 && e.pages.length) throw new B(0, 1);
1196
- const c = st(r.pagination, s, i, a), l = he(e, t, c), u = ot(l.plan);
1197
- if (i !== void 0 && u > i) throw new V(i, u);
1198
- return { ...l, cells: u };
1199
- } catch (c) {
1200
- let l = c;
1201
- throw c instanceof B && o.maxPages !== void 0 && c.limit === s && (l = new B(o.maxPages, o.usedPages + c.actual)), c instanceof V && o.maxCells !== void 0 && (l = new V(o.maxCells, o.usedCells + c.actual)), new S("validate", `报表 ${n} 排版失败:${l instanceof Error ? l.message : String(l)}`, l);
1202
- }
1203
- }
1204
- function at(e, t, r, n) {
1205
- const o = /* @__PURE__ */ new Map(), a = (s) => {
1206
- let i = o.get(s);
1207
- return i === void 0 && (i = JSON.stringify([r, n, s]), o.set(s, i)), i;
1208
- };
1209
- for (const s of t.pages) e.push({
1210
- ...s,
1211
- components: s.components.map((i) => i.table ? {
1212
- ...i,
1213
- table: { ...i.table, id: a(i.table.id) }
1214
- } : i)
1215
- });
1216
- }
1217
- async function yr(e, t, r, n, o) {
1218
- const a = [];
1219
- let s = 0;
1220
- for (const [l, u] of e.entries()) {
1221
- R(o);
1222
- const f = n.maxPages === void 0 ? void 0 : n.maxPages - a.length, d = n.maxCells === void 0 ? void 0 : n.maxCells - s;
1223
- if (f !== void 0 && f < 1 && u.template.pages.length) throw new B(n.maxPages, a.length + 1);
1224
- const g = await tt(u.template, u.datasets, st(t[l]?.pagination, f, d, o));
1225
- if (s += ot(g), n.maxCells !== void 0 && s > n.maxCells) throw new V(n.maxCells, s);
1226
- at(a, g, l, r[l]);
1227
- }
1228
- const i = { schemaVersion: U, ...e.some((l) => Y(l.template)) ? { requiresRecalculation: !0 } : {}, pages: a }, c = Pe(i);
1229
- if (!c.ok) throw new S("validate", `重算渲染计划校验失败:${c.errors[0]?.message}`);
1230
- return i;
1231
- }
1232
- function Zr(e, t = {}) {
1233
- if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new S("config", "maxPages 应为正安全整数");
1234
- if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new S("config", "maxCells 应为正安全整数");
1235
- function r(o) {
1236
- const a = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
1237
- if (!a) throw new S("config", `未注册报表 ${o}`);
1238
- return a;
1239
- }
1240
- return Object.assign(async ({ reportIds: o, params: a, signal: s, onWarning: i, onQueryResult: c, ...l }) => {
1241
- R(s);
1242
- const u = ht({ ...l, signal: s }), f = [...o], d = { ...a };
1243
- if (f.length === 0) throw new S("config", "缺少报表 ID");
1244
- const g = f.map(r), w = u.runSync("validate", () => g.map((p) => ye(
1245
- p.params ?? (typeof p.template == "function" ? [] : p.template.params) ?? [],
1246
- d
1247
- ))), m = [], h = [];
1248
- let v = 0;
1249
- const x = [];
1250
- for (const [p, M] of g.entries()) {
1251
- R(s);
1252
- const $ = f[p], P = { reportId: $, params: w[p], signal: s }, E = typeof M.template == "function" ? await u.run("query", () => mr(M.template, P, x), $) : M.template;
1253
- P.params = u.runSync("validate", () => ye(M.params ?? E.params ?? [], P.params), $);
1254
- const O = await u.run("query", () => gr(M, P, $, c), $);
1255
- u.runSync("validate", () => {
1256
- fr(O, $), t.onDatasets?.($, O, E), pr(M, O, $);
1257
- }, $), R(s);
1258
- const ee = u.runSync("layout", () => wr(E, O, M, $, { maxPages: t.maxPages, usedPages: m.length, maxCells: t.maxCells, usedCells: v }, s), $);
1259
- v += ee.cells, h.push({ template: E, datasets: O }), at(m, ee.plan, p, $), x.push(...ee.warnings.map((ct) => `${$}: ${ct}`));
1260
- }
1261
- R(s);
1262
- const y = { schemaVersion: U, ...h.some((p) => Y(p.template)) ? { requiresRecalculation: !0 } : {}, pages: m }, j = u.runSync("validate", () => {
1263
- const p = Pe(y);
1264
- if (!p.ok) throw new S("validate", `渲染计划校验失败:${p.errors.slice(0, 3).map((M) => `${M.path}: ${M.message}`).join("; ")}`);
1265
- return p;
1266
- });
1267
- x.push(...j.warnings.map((p) => `${p.path}: ${p.message}`));
1268
- const A = g.map((p) => ({ ...p, pagination: { ...p.pagination } })), k = { maxPages: t.maxPages, maxCells: t.maxCells };
1269
- try {
1270
- nt(y, { parts: h, rebuild: (p, M) => yr(p, A, f, k, M) });
1271
- } catch {
1272
- x.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算");
1273
- }
1274
- const C = i ?? t.onWarning ?? ((p) => console.warn("[mach-report]", p));
1275
- for (const p of x)
1276
- R(s), C(p);
1277
- return R(s), y;
1278
- }, {
1279
- getParamDefs: (o) => lt(e, o)
1280
- });
1281
- }
1282
- function Se(e) {
1283
- if (e === void 0) return;
1284
- const t = typeof e == "string" ? e : JSON.stringify(e);
1285
- return t.length > 160 ? t.slice(0, 157) + "…" : t;
1286
- }
1287
- function br(e) {
1288
- 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";
1289
- }
1290
- function Te(e) {
1291
- const t = /* @__PURE__ */ new Map();
1292
- for (const r of e) {
1293
- if (!r || typeof r != "object" || !("field" in r) || typeof r.field != "string" || t.has(r.field)) return;
1294
- t.set(r.field, r);
1295
- }
1296
- return t;
1297
- }
1298
- function vr(e, t, r) {
1299
- 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;
1300
- }
1301
- function xr(e, t, r = {}) {
1302
- const n = ne(e), o = ne(t), a = r.maxChanges ?? 500;
1303
- if (!Number.isSafeInteger(a) || a < 1 || a > 1e4) throw new RangeError("maxChanges must be between 1 and 10000");
1304
- const s = { changes: [], totalChanges: 0, breakingChanges: 0, truncated: !1 };
1305
- function i(u, f, d, g) {
1306
- const w = br(f), m = u !== "moved" && (w === "binding" || f === "$.id" || u === "removed" && w === "structure" || vr(f, u, g));
1307
- s.totalChanges++, m && s.breakingChanges++, s.changes.length < a && s.changes.push({ kind: u, category: w, path: f, before: Se(d), after: Se(g), breaking: m });
1308
- }
1309
- function c(u, f, d) {
1310
- const g = Te(u), w = Te(f);
1311
- if (!g || !w) return !1;
1312
- const m = new Map(f.map((h, v) => [h.field, v]));
1313
- Array.from(g).forEach(([h, v], x) => {
1314
- const y = `${d}[${JSON.stringify(h)}]`;
1315
- w.has(h) ? (m.get(h) !== x && i("moved", y, x, m.get(h)), l(v, w.get(h), y)) : i("removed", y, v, void 0);
1316
- });
1317
- for (const [h, v] of w) g.has(h) || i("added", `${d}[${JSON.stringify(h)}]`, void 0, v);
1318
- return !0;
1319
- }
1320
- function l(u, f, d) {
1321
- if (!(Object.is(u, f) || d === "$.revision")) {
1322
- if (u === void 0 || f === void 0) {
1323
- i(u === void 0 ? "added" : "removed", d, u, f);
1324
- return;
1325
- }
1326
- if (Array.isArray(u) && Array.isArray(f)) {
1327
- if ((d.endsWith(".columns") || d.endsWith(".params")) && c(u, f, d)) return;
1328
- for (let g = 0; g < Math.max(u.length, f.length); g++) l(u[g], f[g], `${d}[${g}]`);
1329
- } else if (u && f && typeof u == "object" && typeof f == "object" && !Array.isArray(u) && !Array.isArray(f)) {
1330
- const g = u, w = f;
1331
- for (const m of /* @__PURE__ */ new Set([...Object.keys(g), ...Object.keys(w)])) l(g[m], w[m], `${d}.${m}`);
1332
- } else i("modified", d, u, f);
1333
- }
1334
- }
1335
- return l(n, o, "$"), s.truncated = s.totalChanges > s.changes.length, s;
1336
- }
1337
- function F(e) {
1338
- return !!e && typeof e == "object" && !Array.isArray(e);
1339
- }
1340
- function T(e, t, r) {
1341
- typeof e == "string" ? r.push({ field: e, path: t }) : Array.isArray(e) && e.forEach((n, o) => T(n, `${t}[${o}]`, r));
1342
- }
1343
- function N(e, t, r) {
1344
- if (Array.isArray(e)) {
1345
- e.forEach((n, o) => N(n, `${t}[${o}]`, r));
1346
- return;
1347
- }
1348
- if (F(e))
1349
- for (const [n, o] of Object.entries(e))
1350
- ["field", "weightField"].includes(n) ? T(o, `${t}.${n}`, r) : n !== "value" && n !== "style" && N(o, `${t}.${n}`, r);
1351
- }
1352
- function re(e, t, r) {
1353
- Array.isArray(e) && e.forEach((n, o) => {
1354
- F(n) && (typeof n.field == "string" && n.valueField !== void 0 && n.valueField !== n.field && r.summaries.add(n.field), T(n.valueField ?? n.field, `${t}[${o}].valueField`, r.fields), T(n.weightField, `${t}[${o}].weightField`, r.fields));
1355
- });
1356
- }
1357
- function Mr(e, t, r) {
1358
- for (const o of ["rowKey", "revisionField", "sourceTokenField"]) T(e[o], `${t}.${o}`, r.fields);
1359
- !e.matrix && Array.isArray(e.columns) && e.columns.forEach((o, a) => {
1360
- F(o) && (typeof o.field == "string" && r.fields.push({ field: o.field, path: `${t}.columns[${a}].field`, summary: !0 }), N(o.rules, `${t}.columns[${a}].rules`, r.fields), N(o.visibleWhen, `${t}.columns[${a}].visibleWhen`, r.fields));
1361
- }), N(e.rowVisibleWhen, `${t}.rowVisibleWhen`, r.fields), Array.isArray(e.computed) && e.computed.forEach((o, a) => {
1362
- F(o) && (typeof o.field == "string" && r.generated.add(o.field), N(o.expression, `${t}.computed[${a}].expression`, r.fields), T(o.dependsOn, `${t}.computed[${a}].dependsOn`, r.fields), T(o.groupBy, `${t}.computed[${a}].groupBy`, r.fields));
1363
- }), (Array.isArray(e.groups) ? e.groups : e.groupBy ? [e.groupBy] : []).forEach((o, a) => {
1364
- F(o) && (T(o.field, `${t}.groups[${a}].field`, r.fields), T(o.subtotal, `${t}.groups[${a}].subtotal`, r.fields), re(o.aggregates, `${t}.groups[${a}].aggregates`, r));
1365
- }), F(e.grandTotal) && (T(e.grandTotal.fields, `${t}.grandTotal.fields`, r.fields), re(e.grandTotal.aggregates, `${t}.grandTotal.aggregates`, r)), F(e.matrix) && (T(e.matrix.rowFields, `${t}.matrix.rowFields`, r.fields), T(e.matrix.columnFields, `${t}.matrix.columnFields`, r.fields), re(e.matrix.measures, `${t}.matrix.measures`, r)), F(e.detail) && T(e.detail.parentKey, `${t}.detail.parentKey`, r.fields);
1366
- }
1367
- function it(e) {
1368
- const t = [];
1369
- function r(n, o) {
1370
- if (Array.isArray(n)) {
1371
- n.forEach((a, s) => r(a, `${o}[${s}]`));
1372
- return;
1373
- }
1374
- if (F(n)) {
1375
- if (typeof n.dataset == "string" && Array.isArray(n.columns)) {
1376
- const a = { dataset: n.dataset, path: o, fields: [], generated: /* @__PURE__ */ new Set(), summaries: /* @__PURE__ */ new Set() };
1377
- Mr(n, o, a), typeof n.foreignKey == "string" && T(n.foreignKey, `${o}.foreignKey`, a.fields), t.push(a);
1378
- }
1379
- for (const [a, s] of Object.entries(n)) r(s, `${o}.${a}`);
1380
- }
1381
- }
1382
- return r(e, "$.template"), t;
1383
- }
1384
- function $r(e, t, r) {
1385
- for (const n of it(e)) {
1386
- const o = Object.prototype.hasOwnProperty.call(t, n.dataset) ? t[n.dataset] : void 0;
1387
- if (!o) {
1388
- r.push({ code: "dataset", severity: "error", path: `${n.path}.dataset`, message: `未声明数据集 ${n.dataset}` });
1389
- continue;
1390
- }
1391
- const a = new Set(o.fields.map((s) => s.field));
1392
- n.fields.forEach(({ field: s, path: i, summary: c }) => {
1393
- !a.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}` });
1394
- });
1395
- }
1396
- }
1397
- function Sr(e, t, r, n) {
1398
- const o = r.maxSampleRows ?? 1e3, a = Object.values(e.datasets).reduce((i, c) => i + c.length, 0);
1399
- if (a > o)
1400
- return n.push({ code: "sample", severity: "error", path: "$.fixtures", fixture: e.name, message: `样例 ${a} 行超过预算 ${o},请显式选择验收样例` }), !1;
1401
- const s = new Set(it(t).map((i) => i.dataset));
1402
- for (const [i, c] of Object.entries(r.dataSchemas ?? {}).filter(([l]) => s.has(l)))
1403
- try {
1404
- const l = ke(e.datasets[i], c, { path: `$.datasets.${i}`, maxRows: o });
1405
- if (n.push(...l.issues.map((u) => ({ ...u, code: "sample", severity: "error", fixture: e.name }))), !l.ok) return !1;
1406
- } catch (l) {
1407
- return n.push({ code: "dataset", severity: "error", path: `$.dataSchemas.${i}`, message: String(l) }), !1;
1408
- }
1409
- return !0;
1410
- }
1411
- function Tr(e, t, r) {
1412
- const n = t.pages[r.pageIndex]?.components[r.componentIndex], o = /^table:(\d+):(\d+)(?::|$)/.exec(n?.table?.id ?? "");
1413
- if (o) return { path: `$.template.pages[${o[1]}].components[${o[2]}]`, pageIndex: Number(o[1]), componentIndex: Number(o[2]) };
1414
- for (const [a, s] of e.pages.entries()) {
1415
- const i = s.components.findIndex((c) => c === n || n?.nid !== void 0 && "nid" in c && c.nid === n.nid);
1416
- if (i >= 0) return { path: `$.template.pages[${a}].components[${i}]`, pageIndex: a, componentIndex: i };
1417
- }
1418
- return { path: "$.template" };
1419
- }
1420
- function Pr(e, t, r, n, o) {
1421
- const a = ft(e.template.params ?? [], t.params ?? {});
1422
- if (o.issues.push(...a.issues.map((s) => ({ ...s, code: "params", severity: "error", fixture: t.name, path: s.path.replace(/^\$\.params/, `$.fixtures[${r}].params`) }))), !!a.ok && Sr(t, e.template, n, o.issues))
1423
- try {
1424
- const { plan: s, warnings: i } = he(e.template, t.datasets, { maxPages: n.maxPages ?? 100, maxCells: n.maxCells ?? 25e4 }), c = (n.formats ?? ["pdf", "xlsx"]).flatMap((l) => Mt(s, l));
1425
- o.issues.push(...i.map((l) => ({ code: "layout", severity: "warning", path: "$.template", fixture: t.name, message: l }))), o.issues.push(...c.map((l) => ({ code: "output", severity: n.strictOutputs ? "error" : "warning", ...Tr(e.template, s, l), fixture: t.name, message: `${l.format}: ${l.message}` }))), o.samples.push({ name: t.name, pages: s.pages.length, rows: Object.values(t.datasets).reduce((l, u) => l + u.length, 0), diagnostics: c });
1426
- } catch (s) {
1427
- o.issues.push({ code: "layout", severity: "error", path: "$.template", fixture: t.name, message: s instanceof Error ? s.message : String(s) });
1428
- }
1429
- }
1430
- function en(e, t = {}) {
1431
- const r = { ok: !1, issues: [], samples: [] };
1432
- try {
1433
- for (const [o, a] of [["maxPages", t.maxPages], ["maxCells", t.maxCells], ["maxSampleRows", t.maxSampleRows]]) if (a !== void 0 && (!Number.isSafeInteger(a) || a < 1)) throw new RangeError(`${o} must be a positive safe integer`);
1434
- if ((t.fixtures?.length ?? 0) > 20) throw new RangeError("At most 20 review fixtures are allowed");
1435
- const n = ne(e);
1436
- t.previous && (r.changes = xr(t.previous, n), r.changes.breakingChanges && !t.allowBreakingChanges && r.issues.push({ code: "compatibility", severity: "error", path: "$.template", message: `${r.changes.breakingChanges} 项字段或结构变更需要明确确认兼容性` })), t.dataSchemas && $r(n.template, t.dataSchemas, r.issues);
1437
- for (const [o, a] of (t.fixtures ?? []).entries()) Pr(n, a, o, t, r);
1438
- t.fixtures?.length || r.issues.push({ code: "sample", severity: "warning", path: "$.fixtures", message: "未提供验收样例,仅完成结构和字段检查,尚未验证排版与输出" });
1439
- } catch (n) {
1440
- r.issues.push({ code: "template", severity: "error", path: "$", message: n instanceof Error ? n.message : String(n) });
1441
- }
1442
- return r.ok = r.issues.every((n) => n.severity !== "error"), r;
1443
- }
1444
- export {
1445
- V as P,
1446
- b as R,
1447
- B as a,
1448
- S as b,
1449
- qr as c,
1450
- Jr as d,
1451
- rr as e,
1452
- Vr as f,
1453
- Dr as g,
1454
- zr as h,
1455
- W as i,
1456
- Qr as j,
1457
- Zr as k,
1458
- Xr as l,
1459
- xr as m,
1460
- Gr as n,
1461
- D as o,
1462
- _e as p,
1463
- pe as q,
1464
- Yr as r,
1465
- he as s,
1466
- Bt as t,
1467
- St as u,
1468
- nt as v,
1469
- Ur as w,
1470
- I as x,
1471
- en as y,
1472
- _r as z
1473
- };