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