@agile-team/mach-report 2.5.0 → 2.6.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 (84) hide show
  1. package/README.md +91 -14
  2. package/dist/ReportPreview-Dk-28QAi.js +2946 -0
  3. package/dist/ReportPreview-FSvcBLjH.cjs +6 -0
  4. package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
  5. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  6. package/dist/analytics.cjs +1 -0
  7. package/dist/analytics.d.cts +276 -0
  8. package/dist/analytics.d.ts +276 -0
  9. package/dist/analytics.js +223 -0
  10. package/dist/assets-66UBlhES.cjs +1 -0
  11. package/dist/assets-NVA_sftu.js +163 -0
  12. package/dist/capabilities-CNjIirfo.js +36 -0
  13. package/dist/capabilities-D4xeVYSR.cjs +1 -0
  14. package/dist/designer.cjs +1 -0
  15. package/dist/designer.d.cts +753 -0
  16. package/dist/designer.d.ts +753 -0
  17. package/dist/designer.js +372 -0
  18. package/dist/grid-geometry-BNptEcMm.js +65 -0
  19. package/dist/grid-geometry-CZ_cYB6O.cjs +1 -0
  20. package/dist/index.cjs +8 -5
  21. package/dist/index.d.cts +413 -8
  22. package/dist/index.d.ts +413 -8
  23. package/dist/index.js +1016 -1501
  24. package/dist/param-validation-BWNjLcN0.js +116 -0
  25. package/dist/param-validation-CiTxFeZ8.cjs +1 -0
  26. package/dist/pdf.cjs +48 -48
  27. package/dist/pdf.d.cts +111 -1
  28. package/dist/pdf.d.ts +111 -1
  29. package/dist/pdf.js +3931 -3868
  30. package/dist/{plugin-DMPLDpBY.cjs → plugin-BqBkn_kI.cjs} +1 -1
  31. package/dist/{plugin-DDLcFWlk.js → plugin-Ds10VnQO.js} +2 -2
  32. package/dist/render-plan-CckPEQyf.cjs +1 -0
  33. package/dist/{render-plan-CXBWRog4.js → render-plan-uzZYYSy1.js} +11 -10
  34. package/dist/report-params-B_VCihAh.js +12 -0
  35. package/dist/report-params-CjWrjPl6.cjs +1 -0
  36. package/dist/report-source-B9bENO0F.js +750 -0
  37. package/dist/report-source-BbNkkBDy.cjs +1 -0
  38. package/dist/server/node.d.cts +297 -0
  39. package/dist/server/node.d.ts +297 -0
  40. package/dist/server-node.cjs +1 -0
  41. package/dist/server-node.js +270 -0
  42. package/dist/server.cjs +1 -0
  43. package/dist/server.d.cts +643 -0
  44. package/dist/server.d.ts +643 -0
  45. package/dist/server.js +237 -0
  46. package/dist/style-CpwiOPyB.cjs +1 -0
  47. package/dist/style-Dv5o_x6b.js +67 -0
  48. package/dist/style.css +1 -1
  49. package/dist/template-registry-DWExx0gU.cjs +1 -0
  50. package/dist/template-registry-NpOakidD.js +354 -0
  51. package/dist/textwrap-CnGsEum6.cjs +4 -0
  52. package/dist/textwrap-DOl04hCQ.js +110 -0
  53. package/dist/validate-DfHPD8wX.cjs +1 -0
  54. package/dist/validate-S6CgIm5d.js +148 -0
  55. package/dist/vue/async.d.cts +602 -57
  56. package/dist/vue/async.d.ts +602 -57
  57. package/dist/vue/index.d.cts +1074 -111
  58. package/dist/vue/index.d.ts +1074 -111
  59. package/dist/vue-async.cjs +1 -1
  60. package/dist/vue-async.js +3 -3
  61. package/dist/vue.cjs +1 -1
  62. package/dist/vue.js +167 -82
  63. package/dist/worker.cjs +1 -0
  64. package/dist/worker.d.cts +302 -0
  65. package/dist/worker.d.ts +302 -0
  66. package/dist/worker.js +133 -0
  67. package/dist/xlsx/node.d.cts +47 -0
  68. package/dist/xlsx/node.d.ts +47 -0
  69. package/dist/xlsx-node.cjs +221 -0
  70. package/dist/xlsx-node.js +36409 -0
  71. package/dist/xlsx.cjs +20 -20
  72. package/dist/xlsx.d.cts +78 -1
  73. package/dist/xlsx.d.ts +78 -1
  74. package/dist/xlsx.js +5974 -5831
  75. package/package.json +62 -2
  76. package/dist/ReportPreview-CBKLI--k.js +0 -2188
  77. package/dist/ReportPreview-ClM8h0pM.cjs +0 -6
  78. package/dist/grid-geometry-BNIvw52m.cjs +0 -1
  79. package/dist/grid-geometry-C8hGoe9o.js +0 -130
  80. package/dist/render-plan-CCTL4F9v.cjs +0 -1
  81. package/dist/report-params-B3Fia6JO.js +0 -10
  82. package/dist/report-params-D1gZ1DME.cjs +0 -1
  83. package/dist/textwrap-nH0UYU6D.js +0 -108
  84. package/dist/textwrap-oD-t4b4B.cjs +0 -4
@@ -0,0 +1,750 @@
1
+ import { R as W, d as ne, D as _, L as z } from "./render-plan-uzZYYSy1.js";
2
+ import { h as re, w as K } from "./textwrap-DOl04hCQ.js";
3
+ import { e as x, a as G } from "./style-Dv5o_x6b.js";
4
+ import { c as oe } from "./validate-S6CgIm5d.js";
5
+ import { g as ae } from "./report-params-B_VCihAh.js";
6
+ import { v as ie, a as se } from "./template-registry-NpOakidD.js";
7
+ import { a as O } from "./param-validation-BWNjLcN0.js";
8
+ function Y(e) {
9
+ if (!e || e.kind === "date") return;
10
+ const t = e.digits;
11
+ if (!(t !== void 0 && (!Number.isInteger(t) || t < 0 || t > 100))) {
12
+ if (e.kind === "percent") {
13
+ const n = t ?? 2;
14
+ return `0${n ? `.${"0".repeat(n)}` : ""}%`;
15
+ }
16
+ return t === void 0 ? e.thousands ? "#,##0.###############" : void 0 : `${e.thousands ? "#,##0" : "0"}${t ? `.${"0".repeat(t)}` : ""}`;
17
+ }
18
+ }
19
+ function me(e) {
20
+ const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
21
+ if (t) {
22
+ const r = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
23
+ return Number.isNaN(r.getTime()) ? null : r;
24
+ }
25
+ const n = new Date(e);
26
+ return Number.isNaN(n.getTime()) ? null : n;
27
+ }
28
+ function A(e, t) {
29
+ return e.toLocaleString("en-US", {
30
+ minimumFractionDigits: t,
31
+ maximumFractionDigits: t
32
+ });
33
+ }
34
+ function ce(e, t) {
35
+ const n = (r) => String(r).padStart(2, "0");
36
+ return t.replace(/YYYY/g, String(e.getFullYear())).replace(/MM/g, n(e.getMonth() + 1)).replace(/DD/g, n(e.getDate())).replace(/hh/g, n(e.getHours())).replace(/mm/g, n(e.getMinutes())).replace(/ss/g, n(e.getSeconds()));
37
+ }
38
+ function ue(e, t, n) {
39
+ return n != null ? t ? A(e, n) : e.toFixed(n) : t ? A(e) : String(e);
40
+ }
41
+ function D(e) {
42
+ const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
43
+ return Number.isFinite(t) ? t : null;
44
+ }
45
+ function q(e, t) {
46
+ if (e == null || e === "" || !t) return String(e ?? "");
47
+ switch (t.kind) {
48
+ case "number": {
49
+ const n = D(e);
50
+ return n == null ? String(e) : ue(n, t.thousands === !0, t.digits);
51
+ }
52
+ case "percent": {
53
+ const n = D(e);
54
+ return n == null ? String(e) : `${A(n * 100, t.digits ?? 2)}%`;
55
+ }
56
+ case "date": {
57
+ const n = t.pattern ?? "YYYY-MM-DD", r = e instanceof Date ? e : me(String(e));
58
+ return r ? ce(r, n) : String(e);
59
+ }
60
+ default:
61
+ return String(e);
62
+ }
63
+ }
64
+ function le(e, t) {
65
+ const n = e[t.field];
66
+ if (n == null || n === "") return !1;
67
+ if (typeof t.value == "number") {
68
+ const a = D(n);
69
+ if (a == null) return !1;
70
+ switch (t.op) {
71
+ case ">":
72
+ return a > t.value;
73
+ case ">=":
74
+ return a >= t.value;
75
+ case "<":
76
+ return a < t.value;
77
+ case "<=":
78
+ return a <= t.value;
79
+ case "==":
80
+ return a === t.value;
81
+ case "!=":
82
+ return a !== t.value;
83
+ }
84
+ }
85
+ const r = String(n), o = String(t.value);
86
+ switch (t.op) {
87
+ case "==":
88
+ return r === o;
89
+ case "!=":
90
+ return r !== o;
91
+ case ">":
92
+ return r > o;
93
+ case ">=":
94
+ return r >= o;
95
+ case "<":
96
+ return r < o;
97
+ case "<=":
98
+ return r <= o;
99
+ }
100
+ return !1;
101
+ }
102
+ const de = ["text", "number", "boolean", "date", "decimal"], fe = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
103
+ function v(e) {
104
+ throw new Error(`数据契约无效:${e}`);
105
+ }
106
+ function V(e) {
107
+ (!e || !Array.isArray(e.fields) || !e.fields.length || e.fields.length > 2048) && v("fields 应包含 1–2048 个字段");
108
+ const t = /* @__PURE__ */ new Set();
109
+ for (const n of e.fields)
110
+ (!n || typeof n.field != "string" || !n.field.trim() || fe.has(n.field) || t.has(n.field)) && v("字段名应安全、非空且唯一"), t.add(n.field), de.includes(n.type) || v(`未知字段类型 ${n.type}`), ye(n), pe(n), ge(n);
111
+ he(e, t);
112
+ }
113
+ function ge(e) {
114
+ e.enum !== void 0 && (!Array.isArray(e.enum) || !e.enum.length || e.enum.some((t) => !J(t, e.type))) && v("enum 应为匹配字段类型的非空标量数组");
115
+ }
116
+ function he(e, t) {
117
+ e.rowKey !== void 0 && ((typeof e.rowKey != "string" || !e.rowKey.trim() || !t.has(e.rowKey)) && v("rowKey 应为引用已声明字段的非空字符串"), e.fields.find((n) => n.field === e.rowKey)?.type === "boolean" && v("布尔字段不能作为业务主键"));
118
+ }
119
+ function pe(e) {
120
+ for (const t of ["label", "unit"]) e[t] !== void 0 && typeof e[t] != "string" && v(`${t} 应为字符串`);
121
+ for (const t of ["required", "nullable"]) e[t] !== void 0 && typeof e[t] != "boolean" && v(`${t} 应为布尔值`);
122
+ e.semanticRole !== void 0 && !["identifier", "dimension", "measure", "date", "text"].includes(e.semanticRole) && v("未知字段语义");
123
+ }
124
+ function ye(e) {
125
+ for (const t of ["min", "max", "minLength", "maxLength"]) {
126
+ const n = e[t];
127
+ n !== void 0 && (!Number.isFinite(n) || t.includes("Length") && (!Number.isInteger(n) || n < 0)) && v(`${t} 无效`);
128
+ }
129
+ e.min !== void 0 && e.max !== void 0 && e.min > e.max && v("min 不能超过 max"), e.minLength !== void 0 && e.maxLength !== void 0 && e.minLength > e.maxLength && v("minLength 不能超过 maxLength"), e.type !== "number" && (e.min !== void 0 || e.max !== void 0) && v("min/max 仅适用于 number,精确小数文本需业务校验"), ["number", "boolean"].includes(e.type) && (e.minLength !== void 0 || e.maxLength !== void 0) && v("长度约束仅适用于文本类型");
130
+ }
131
+ function we(e) {
132
+ const t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
133
+ if (!t) return !1;
134
+ const n = Number(t[1]), r = Number(t[2]), o = Number(t[3]), a = n % 4 === 0 && (n % 100 !== 0 || n % 400 === 0);
135
+ return n > 0 && r >= 1 && r <= 12 && o >= 1 && o <= [31, a ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][r - 1];
136
+ }
137
+ function J(e, t) {
138
+ return t === "number" ? typeof e == "number" && Number.isFinite(e) : t === "boolean" ? typeof e == "boolean" : typeof e != "string" ? !1 : t === "date" ? we(e) : t === "decimal" ? e.length <= 1e4 && /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(e) : !0;
139
+ }
140
+ function be(e, t) {
141
+ if (e == null)
142
+ return t.required || e === null && t.nullable === !1 ? { code: "required", message: "缺少必需字段值" } : void 0;
143
+ if (!J(e, t.type)) return { code: "type", message: `值应为 ${t.type},不会自动转换原始值` };
144
+ if (t.enum && !t.enum.includes(e)) return { code: "enum", message: "值不在允许的枚举中" };
145
+ if (typeof e == "number" && (t.min !== void 0 && e < t.min || t.max !== void 0 && e > t.max)) return { code: "range", message: "数值超出范围" };
146
+ if (typeof e == "string" && !Me(e, t)) return { code: "range", message: "文本长度超出范围" };
147
+ }
148
+ function Me(e, t) {
149
+ if (t.minLength === void 0 && t.maxLength === void 0) return !0;
150
+ let n = 0;
151
+ for (const r of e) n++;
152
+ return (t.minLength === void 0 || n >= t.minLength) && (t.maxLength === void 0 || n <= t.maxLength);
153
+ }
154
+ function E(e, t) {
155
+ const n = e ?? t;
156
+ if (!Number.isInteger(n) || n < 1) throw new Error("数据校验预算应为正整数");
157
+ return n;
158
+ }
159
+ function Se(e, t, n) {
160
+ const r = Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0;
161
+ if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r))) return "业务主键应为非空字符串或有限数字";
162
+ const o = JSON.stringify([typeof r, r]);
163
+ if (n.has(o)) return "业务主键重复";
164
+ n.add(o);
165
+ }
166
+ function ve(e, t, n = {}) {
167
+ V(t);
168
+ const r = n.path ?? "$.rows", o = [], a = E(n.maxIssues, 100);
169
+ if (!Array.isArray(e)) return { ok: !1, issues: [{ code: "row", path: r, message: "数据集应为对象数组" }] };
170
+ if (e.length > E(n.maxRows, 1e5) || e.length * t.fields.length > E(n.maxCells, 2e6)) return { ok: !1, issues: [{ code: "budget", path: r, message: "数据校验超出行数或单元格预算" }] };
171
+ const i = /* @__PURE__ */ new Set();
172
+ for (let s = 0; s < e.length && o.length < a; s++) {
173
+ const l = e[s];
174
+ if (!l || typeof l != "object" || Array.isArray(l)) {
175
+ o.push({ code: "row", path: `${r}[${s}]`, rowIndex: s, message: "行应为对象" });
176
+ continue;
177
+ }
178
+ xe(l, t, s, r, i, o, a);
179
+ }
180
+ return { ok: o.length === 0, issues: o };
181
+ }
182
+ function xe(e, t, n, r, o, a, i) {
183
+ for (const s of t.fields) {
184
+ if (a.length >= i) return;
185
+ const l = be(Object.prototype.hasOwnProperty.call(e, s.field) ? e[s.field] : void 0, s);
186
+ l && a.push({ ...l, rowIndex: n, field: s.field, path: `${r}[${n}].${s.field}` });
187
+ }
188
+ if (t.rowKey && a.length < i) {
189
+ const s = Se(e, t.rowKey, o);
190
+ s && a.push({ code: "row-key", path: `${r}[${n}].${t.rowKey}`, message: s, rowIndex: n, field: t.rowKey });
191
+ }
192
+ }
193
+ function tt(e) {
194
+ return V(e), { $schema: "https://json-schema.org/draft/2020-12/schema", type: "array", items: { type: "object", properties: Object.fromEntries(e.fields.map((n) => [n.field, $e(n, n.field === e.rowKey)])), required: e.fields.filter((n) => n.required || n.field === e.rowKey).map((n) => n.field), additionalProperties: !0 }, ...e.rowKey ? { "x-report-rowKey": e.rowKey } : {} };
195
+ }
196
+ function $e(e, t) {
197
+ const n = !t && e.nullable !== !1 && !e.required;
198
+ return {
199
+ type: n ? [B(e.type), "null"] : B(e.type),
200
+ ...e.label ? { title: e.label } : {},
201
+ ...e.type === "date" ? { format: "date" } : {},
202
+ ...e.type === "decimal" ? { pattern: "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$" } : {},
203
+ ...e.enum ? { enum: n ? [...e.enum, null] : [...e.enum] } : {},
204
+ ...e.min === void 0 ? {} : { minimum: e.min },
205
+ ...e.max === void 0 ? {} : { maximum: e.max },
206
+ ...Pe(e, t),
207
+ ...t && e.type === "text" ? { pattern: "\\S" } : {},
208
+ ...e.unit ? { "x-report-unit": e.unit } : {},
209
+ ...e.semanticRole ? { "x-report-semanticRole": e.semanticRole } : {}
210
+ };
211
+ }
212
+ function Pe(e, t) {
213
+ const n = {};
214
+ return (e.minLength !== void 0 || t && e.type !== "number") && (n.minLength = Math.max(e.minLength ?? 0, t ? 1 : 0)), e.type === "decimal" ? n.maxLength = Math.min(e.maxLength ?? 1e4, 1e4) : e.maxLength !== void 0 && (n.maxLength = e.maxLength), n;
215
+ }
216
+ function B(e) {
217
+ return e === "text" || e === "date" || e === "decimal" ? "string" : e;
218
+ }
219
+ class R extends Error {
220
+ constructor(t, n) {
221
+ super(`报表页数超出上限 ${t}(至少 ${n} 页)`), this.limit = t, this.actual = n, this.code = "page-limit", this.name = "PaginatePageLimitError";
222
+ }
223
+ }
224
+ function ke(e) {
225
+ return {
226
+ widthMm: e.widthMm,
227
+ heightMm: e.heightMm,
228
+ marginTopMm: e.marginTopMm ?? 0,
229
+ marginBottomMm: e.marginBottomMm ?? 0,
230
+ marginLeftMm: e.marginLeftMm ?? 0,
231
+ marginRightMm: e.marginRightMm ?? 0,
232
+ components: []
233
+ };
234
+ }
235
+ function Le(e, t) {
236
+ return t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
237
+ }
238
+ function U(e) {
239
+ if (e == null) return "";
240
+ if (typeof e == "string") return e;
241
+ if (typeof e == "number") return String(e);
242
+ if (typeof e == "boolean") return e ? "是" : "否";
243
+ if (e instanceof Date) return e.toISOString().slice(0, 10);
244
+ try {
245
+ return JSON.stringify(e);
246
+ } catch {
247
+ return String(e);
248
+ }
249
+ }
250
+ function Q(e, t) {
251
+ let n = e.textMetrics.get(t);
252
+ if (!n) {
253
+ const r = G(t).fontSizePt;
254
+ n = {
255
+ measureOptions: {
256
+ fontSizePt: r,
257
+ fontFamily: t.fontFamily ?? _,
258
+ italic: t.italic,
259
+ bold: t.bold,
260
+ letterSpacingPt: t.letterSpacing
261
+ },
262
+ lineMm: r * (t.lineHeight ?? z) * 25.4 / 72
263
+ }, e.textMetrics.set(t, n);
264
+ }
265
+ return n;
266
+ }
267
+ function X(e, t, n) {
268
+ return n === "identifier" || n === "dimension" || n === "date" ? "center" : n === "measure" ? "right" : n === "text" ? "left" : t?.kind === "number" || t?.kind === "percent" ? "right" : t?.kind === "date" || e instanceof Date || typeof e == "boolean" ? "center" : typeof e == "number" && Number.isFinite(e) ? "right" : "left";
269
+ }
270
+ function Te(e) {
271
+ if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
272
+ }
273
+ function Re(e, t) {
274
+ const n = e.fontSizePt ?? ne, r = e.paddingMm ?? 1, o = e.columns.map((m) => m.align ?? m.style?.align ?? e.align ?? "left"), a = e.columns.map((m, c) => ({
275
+ ...x({
276
+ fontSize: n,
277
+ verticalAlign: "middle"
278
+ }, m.style),
279
+ align: o[c] === "auto" ? "left" : o[c]
280
+ })), i = a.map((m, c) => o[c] === "auto" ? { left: m, center: { ...m, align: "center" }, right: { ...m, align: "right" } } : void 0), s = e.columns.map((m, c) => m.rules?.map((M) => {
281
+ const h = i[c];
282
+ if (h) return {
283
+ left: x(h.left, M.style),
284
+ center: x(h.center, M.style),
285
+ right: x(h.right, M.style)
286
+ };
287
+ const S = x(a[c], M.style);
288
+ return { left: S, center: S, right: S };
289
+ })), l = e.columns.map((m) => {
290
+ let c = x({
291
+ fontSize: n,
292
+ bold: e.headerBold ?? !0,
293
+ align: "center",
294
+ verticalAlign: "middle",
295
+ backgroundColor: e.headerBackgroundColor
296
+ }, m.style);
297
+ return e.headerAlign !== void 0 && (c.align = e.headerAlign), c = x(c, e.headerStyle), m.headerAlign !== void 0 && (c.align = m.headerAlign), x(c, m.headerStyle);
298
+ }), d = e.columns.map((m) => m.header);
299
+ let u = e.rowHeightMm ?? 0;
300
+ for (let m = 0; m < d.length; m++) {
301
+ const c = l[m], M = G(c).fontSizePt, h = K(
302
+ d[m],
303
+ e.columns[m].widthMm - r * 2,
304
+ { fontSizePt: M, fontFamily: c.fontFamily ?? _, italic: c.italic, bold: c.bold, letterSpacingPt: c.letterSpacing },
305
+ t
306
+ ), S = M * (c.lineHeight ?? z) * 25.4 / 72;
307
+ u = Math.max(u, Math.max(h.length, 1) * S + r * 2);
308
+ }
309
+ const f = d.map((m, c) => ({
310
+ text: m,
311
+ style: l[c]
312
+ })), b = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, y = e.columns.map((m) => m.widthMm), g = Ne(e.headerGrid, y, {
313
+ cells: [f],
314
+ colWidthsMm: y,
315
+ rowHeightsMm: [u],
316
+ paddingMm: r
317
+ });
318
+ return {
319
+ fontSizePt: n,
320
+ paddingMm: r,
321
+ cellStyles: a,
322
+ autoStyles: i,
323
+ ruleStyles: s,
324
+ textMetrics: /* @__PURE__ */ new WeakMap(),
325
+ numberFormats: e.columns.map((m) => Y(m.format)),
326
+ borderStyle: b,
327
+ headerHeightMm: g.rowHeightsMm.reduce((m, c) => m + c, 0),
328
+ headerGrid: g,
329
+ colWidthsMm: y,
330
+ columns: e.columns
331
+ };
332
+ }
333
+ function Ne(e, t, n) {
334
+ if (!e) return n;
335
+ if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
336
+ const r = e.rowHeightsMm ?? e.cells.map(() => n.rowHeightsMm[0]);
337
+ if (r.length !== e.cells.length || r.some((o) => !Number.isFinite(o) || o <= 0)) throw new Error("自定义列表表头行高无效");
338
+ return { ...e, colWidthsMm: t, rowHeightsMm: r };
339
+ }
340
+ function Fe(e, t, n) {
341
+ const r = t.format?.kind === "number" || t.format?.kind === "percent";
342
+ t.valueType !== void 0 ? e.valueType = t.valueType : r && (e.valueType = "number"), t.editable !== void 0 && (e.editable = t.editable), (typeof e.value == "number" || e.value == null) && n !== void 0 && (e.numberFormat = n);
343
+ }
344
+ function j(e, t, n) {
345
+ const r = e.columns;
346
+ let o = e.rowHeightFloorMm;
347
+ const a = new Array(r.length);
348
+ for (let i = 0; i < r.length; i++) {
349
+ const s = r[i], l = t[s.field], d = e.autoStyles[i] ? X(l, s.format, s.semanticRole) : "left";
350
+ let u = e.autoStyles[i]?.[d] ?? e.cellStyles[i];
351
+ if (s.rules)
352
+ for (let c = 0; c < s.rules.length; c++) {
353
+ const M = s.rules[c];
354
+ if (le(t, M.when)) {
355
+ u = e.ruleStyles[i][c][d];
356
+ break;
357
+ }
358
+ }
359
+ const f = s.format ? q(l, s.format) : U(l), b = Q(e, u), y = K(f, s.widthMm - e.paddingMm * 2, b.measureOptions, n);
360
+ o = Math.max(o, y.length * b.lineMm + e.paddingMm * 2);
361
+ const g = Te(l), m = { text: f, style: u };
362
+ g !== void 0 && (m.value = g), Fe(m, s, e.numberFormats[i]), a[i] = m;
363
+ }
364
+ return {
365
+ grid: { cells: [a], colWidthsMm: e.colWidthsMm, rowHeightsMm: [o], paddingMm: e.paddingMm },
366
+ heightMm: o
367
+ };
368
+ }
369
+ function* Ee(e, t) {
370
+ if (!t) {
371
+ for (const r of e) yield { kind: "row", row: r };
372
+ return;
373
+ }
374
+ const n = /* @__PURE__ */ new Map();
375
+ for (const r of e) {
376
+ const o = U(r[t.field]), a = n.get(o);
377
+ a ? a.push(r) : n.set(o, [r]);
378
+ }
379
+ for (const [r, o] of n) {
380
+ yield { kind: "groupHeader", label: (t.headerTemplate ?? "{value}").replace(/\{value\}/g, r), firstRow: o[0] };
381
+ for (const a of o) yield { kind: "row", row: a };
382
+ t.subtotal?.length && (yield { kind: "subtotal", label: t.subtotalLabel ?? "小计", rows: o });
383
+ }
384
+ }
385
+ function Ae(e, t) {
386
+ let n = 0;
387
+ for (const r of e) {
388
+ const o = typeof r[t] == "number" ? r[t] : Number(r[t]);
389
+ Number.isFinite(o) && (n += o);
390
+ }
391
+ return n;
392
+ }
393
+ function Z(e, t, n) {
394
+ return new Map(n.map((r) => {
395
+ const o = e.find((i) => i.field === r)?.format ?? { kind: "number", thousands: !0 }, a = Ae(t, r);
396
+ return [r, { text: q(a, o), value: a, numberFormat: Y(o) }];
397
+ }));
398
+ }
399
+ function ee(e, t) {
400
+ const n = e.findIndex((r) => t.includes(r.field));
401
+ return n > 0 ? n : 1;
402
+ }
403
+ function H(e, t, n, r, o, a) {
404
+ const i = [], s = Math.max(1, Math.min(a, e.columns.length)), l = x({ fontSize: e.fontSizePt }, o);
405
+ i.push({ text: n, colSpan: s, style: { bold: !0, ...l } });
406
+ for (let f = s; f < e.columns.length; f++) {
407
+ const b = e.columns[f], y = r.get(b.field), g = e.autoStyles[f]?.[X(y?.value, b.format)] ?? e.cellStyles[f];
408
+ i.push({ ...y, text: y?.text ?? "", style: x(g, o) });
409
+ }
410
+ let d = e.rowHeightFloorMm, u = 0;
411
+ for (const f of i) {
412
+ let b = 0;
413
+ const y = u + (f.colSpan ?? 1);
414
+ for (; u < y; u++) b += e.colWidthsMm[u] ?? 0;
415
+ const g = Q(e, f.style), m = K(f.text ?? "", b - e.paddingMm * 2, g.measureOptions, t);
416
+ d = Math.max(d, m.length * g.lineMm + e.paddingMm * 2);
417
+ }
418
+ return {
419
+ grid: { cells: [i], colWidthsMm: e.colWidthsMm, rowHeightsMm: [d], paddingMm: e.paddingMm },
420
+ heightMm: d
421
+ };
422
+ }
423
+ function De(e, t, n) {
424
+ const { templatePage: r, current: o, warnings: a, nextId: i, pushCurrent: s } = n, l = () => Le(r, o), d = o.marginTopMm, u = {
425
+ id: n.tableId,
426
+ columnKeys: e.columns.map((p) => p.field),
427
+ ...e.layout === void 0 ? {} : { layout: e.layout },
428
+ ...e.title === void 0 ? {} : { title: e.title }
429
+ };
430
+ let f = 0;
431
+ const b = {
432
+ kind: "rect",
433
+ leftMm: e.leftMm,
434
+ topMm: 0,
435
+ widthMm: e.widthMm,
436
+ heightMm: t.headerHeightMm,
437
+ grid: t.headerGrid,
438
+ nid: i("listh"),
439
+ table: { ...u, role: "header", rowIndex: -1 },
440
+ style: t.borderStyle
441
+ }, y = (p) => o.components.push({ ...b, topMm: p });
442
+ let g = e.topMm;
443
+ y(g), g += t.headerHeightMm + n.mmPerRow;
444
+ function m() {
445
+ const p = r.layout === "wide" ? 0 : e.topMm;
446
+ return e.headerEveryPage !== !1 ? p + t.headerHeightMm : r.layout === "wide" ? 0 : d;
447
+ }
448
+ function c() {
449
+ const p = r.layout === "wide" ? 0 : o.marginBottomMm;
450
+ return r.heightMm - p - m();
451
+ }
452
+ function M(p) {
453
+ if (g + p <= l()) return;
454
+ s(), o.components = [], o.heightMm = r.heightMm, r.layout === "wide" && (o.marginTopMm = 0, o.marginBottomMm = 0);
455
+ const P = r.layout === "wide" ? 0 : e.topMm;
456
+ e.headerEveryPage !== !1 ? (y(P), g = P + t.headerHeightMm) : g = r.layout === "wide" ? 0 : d;
457
+ }
458
+ function h(p, P, k, T) {
459
+ const L = c();
460
+ p.heightMm > L && a.push(`列表 ${e.id ?? e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${L.toFixed(2)}mm,预览与打印可能截断内容`), M(p.heightMm), o.components.push({
461
+ kind: "rect",
462
+ leftMm: e.leftMm,
463
+ topMm: g,
464
+ widthMm: e.widthMm,
465
+ heightMm: p.heightMm,
466
+ grid: p.grid,
467
+ nid: i(P),
468
+ table: { ...u, role: k, rowIndex: f++, ...T ? { source: T } : {} },
469
+ style: t.borderStyle
470
+ }), g += p.heightMm;
471
+ }
472
+ function S(p) {
473
+ p <= c() && M(p);
474
+ }
475
+ return { keepTogether: S, placeGridRow: h };
476
+ }
477
+ function He(e, t) {
478
+ if (!e.rowKey) return;
479
+ const n = t[e.rowKey];
480
+ if ((typeof n != "string" || !n.trim()) && !(typeof n == "number" && Number.isFinite(n)))
481
+ throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
482
+ const r = e.revisionField ? t[e.revisionField] : void 0, o = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
483
+ if (r !== void 0 && typeof r != "string" && !(typeof r == "number" && Number.isFinite(r))) throw new Error("业务修订号应为字符串或有限数字");
484
+ if (o !== void 0 && typeof o != "string") throw new Error("来源令牌应为字符串");
485
+ return { datasetId: e.dataset, rowKey: n, ...r === void 0 ? {} : { revision: r }, ...o === void 0 ? {} : { sourceToken: o } };
486
+ }
487
+ function Ie(e, t) {
488
+ const n = /* @__PURE__ */ new Map();
489
+ if (!e.rowKey) return n;
490
+ const r = /* @__PURE__ */ new Set();
491
+ for (const o of t) {
492
+ const a = He(e, o), i = JSON.stringify(a.rowKey);
493
+ if (r.has(i)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);
494
+ r.add(i), n.set(o, a);
495
+ }
496
+ return n;
497
+ }
498
+ function Ke(e, t, n, r, o) {
499
+ if (!e.grandTotal) return;
500
+ const a = typeof e.grandTotal == "object" ? e.grandTotal : void 0, i = a?.fields ?? e.groupBy?.subtotal ?? [];
501
+ if (i.length === 0) {
502
+ r.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
503
+ return;
504
+ }
505
+ const s = H(n, r.measurer, a?.label ?? "合计", Z(e.columns, t, i), a?.style ?? {}, ee(e.columns, i));
506
+ o.placeGridRow(s, "listgt", "grand-total");
507
+ }
508
+ function Oe(e, t, n) {
509
+ const r = Ie(e, t), o = e.columns.reduce((u, f) => u + f.widthMm, 0), a = o > e.widthMm ? e.widthMm / o : 1, i = a === 1 ? e : { ...e, columns: e.columns.map((u) => ({ ...u, widthMm: u.widthMm * a })) }, s = { ...Re(i, n.measurer), rowHeightFloorMm: i.rowHeightMm ?? 0 }, l = De(i, s, n);
510
+ let d;
511
+ for (const u of Ee(t, i.groupBy))
512
+ if (u.kind === "row")
513
+ l.placeGridRow(d ?? j(s, u.row, n.measurer), "listr", "body", r.get(u.row)), d = void 0;
514
+ else if (u.kind === "groupHeader") {
515
+ const f = H(s, n.measurer, u.label, /* @__PURE__ */ new Map(), i.groupBy?.headerStyle ?? {}, i.columns.length);
516
+ d = j(s, u.firstRow, n.measurer), i.groupBy?.keepWithNext !== !1 && l.keepTogether(f.heightMm + d.heightMm), l.placeGridRow(f, "listg", "group-header");
517
+ } else {
518
+ const f = i.groupBy?.subtotal ?? [], b = H(s, n.measurer, u.label, Z(i.columns, u.rows, f), i.groupBy?.subtotalStyle ?? {}, ee(i.columns, f));
519
+ l.placeGridRow(b, "listst", "subtotal");
520
+ }
521
+ Ke(i, t, s, n, l);
522
+ }
523
+ function C(e) {
524
+ return e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}"));
525
+ }
526
+ function Be(e, t, n, r, o, a) {
527
+ const i = {
528
+ pageWidthMm: t.widthMm,
529
+ pageHeightMm: t.heightMm,
530
+ ...e.layout === void 0 ? {} : { layout: e.layout },
531
+ marginTopMm: t.marginTopMm,
532
+ marginBottomMm: t.marginBottomMm,
533
+ marginLeftMm: t.marginLeftMm,
534
+ marginRightMm: t.marginRightMm,
535
+ components: t.components
536
+ };
537
+ r.push(i);
538
+ for (const s of n) {
539
+ const l = { ...s, text: String(s.text ?? "").replace(/\{page\}/g, String(r.length)) };
540
+ i.components.push(l), l.text.includes("{totalPages}") && o.push(l);
541
+ }
542
+ if (e.layout === "wide") {
543
+ const s = i.components.reduce((l, d) => Math.max(l, d.topMm + d.heightMm), 0);
544
+ i.marginBottomMm = a ? e.marginBottomMm ?? 0 : 0, i.pageHeightMm = Math.max(1, s + i.marginBottomMm);
545
+ }
546
+ }
547
+ function je(e, t, n = {}) {
548
+ const r = typeof n == "number" ? { mmPerRow: n } : n;
549
+ if (r.maxPages !== void 0 && (!Number.isSafeInteger(r.maxPages) || r.maxPages < 1)) throw new RangeError("maxPages 应为正安全整数");
550
+ const o = [], a = [], i = [];
551
+ let s = 0;
552
+ const l = (d) => `${d}_${(++s).toString(36)}`;
553
+ for (const [d, u] of e.pages.entries()) {
554
+ const f = ke(u), b = u.components.filter(C), y = (g = !1) => {
555
+ if (r.maxPages !== void 0 && a.length >= r.maxPages) throw new R(r.maxPages, a.length + 1);
556
+ Be(u, f, b, a, i, g);
557
+ };
558
+ for (const [g, m] of u.components.entries()) {
559
+ if (C(m)) continue;
560
+ if (m.kind !== "list") {
561
+ f.components.push(m);
562
+ continue;
563
+ }
564
+ const c = t[m.dataset];
565
+ Array.isArray(c) || o.push(`数据集 ${m.dataset} 未提供数据,列表 ${m.id ?? ""} 输出为空`), Oe(m, Array.isArray(c) ? c : [], {
566
+ templatePage: u,
567
+ current: f,
568
+ warnings: o,
569
+ nextId: l,
570
+ pushCurrent: y,
571
+ measurer: r.measurer ?? re,
572
+ mmPerRow: r.mmPerRow ?? 0,
573
+ tableId: `table:${d}:${g}`
574
+ });
575
+ }
576
+ y(!0);
577
+ }
578
+ for (const d of i) d.text = d.text.replace(/\{totalPages\}/g, String(a.length));
579
+ return { plan: { schemaVersion: W, pages: a }, warnings: o };
580
+ }
581
+ function nt(e) {
582
+ if (!("mapData" in e)) return e;
583
+ const { load: t, mapData: n, ...r } = e;
584
+ return { ...r, load: async (o) => {
585
+ const a = await t(o);
586
+ $(o.signal);
587
+ try {
588
+ return n(a, o);
589
+ } catch (i) {
590
+ throw new w("validate", `报表 ${o.reportId} 数据映射失败`, i);
591
+ }
592
+ } };
593
+ }
594
+ class w extends Error {
595
+ constructor(t, n, r) {
596
+ super(n), this.name = "ReportSourceError", this.code = t, this.cause = r;
597
+ }
598
+ }
599
+ function N(e) {
600
+ const t = new Error("报表加载已取消");
601
+ return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
602
+ }
603
+ function $(e) {
604
+ if (e?.aborted) throw N(e);
605
+ }
606
+ function I(e, t) {
607
+ return t ? new Promise((n, r) => {
608
+ const o = () => t.removeEventListener("abort", a), a = () => {
609
+ o(), r(N(t));
610
+ };
611
+ t.addEventListener("abort", a, { once: !0 }), t.aborted && a(), Promise.resolve(e).then(
612
+ (i) => {
613
+ o(), n(i);
614
+ },
615
+ (i) => {
616
+ o(), r(i);
617
+ }
618
+ );
619
+ }) : Promise.resolve(e);
620
+ }
621
+ function Ce(e, t) {
622
+ if (!e || typeof e != "object" || Array.isArray(e))
623
+ throw new w("validate", `报表 ${t} 的数据集应为对象`);
624
+ for (const [n, r] of Object.entries(e))
625
+ if (!Array.isArray(r) || r.some((o) => !o || typeof o != "object" || Array.isArray(o)))
626
+ throw new w("validate", `报表 ${t} 的数据集 ${n} 应为对象数组`);
627
+ }
628
+ async function We(e, t, n) {
629
+ const { reportId: r, signal: o } = t;
630
+ try {
631
+ const a = await I(e(t), o);
632
+ $(o);
633
+ const i = ie(a);
634
+ if (!i.ok)
635
+ throw new w("validate", `报表 ${r} 模板校验失败:${i.errors.slice(0, 3).map((s) => `${s.path}: ${s.message}`).join("; ")}`);
636
+ return n.push(...i.warnings.map((s) => `${r}: ${s.path}: ${s.message}`)), a;
637
+ } catch (a) {
638
+ throw o?.aborted ? N(o) : a instanceof w ? a : a instanceof se ? new w("validate", `报表 ${r} 模板校验失败:${a.message}`, a) : new w("fetch", `报表 ${r} 模板加载失败:${a instanceof Error ? a.message : String(a)}`, a);
639
+ }
640
+ }
641
+ async function _e(e, t, n, r, o) {
642
+ const a = t.signal;
643
+ let i;
644
+ try {
645
+ if (e.load) i = await I(e.load(t), a);
646
+ else if (e.provider) {
647
+ const s = await I(e.provider.query(t), a);
648
+ $(a), ze(s, n), i = s.datasets, r?.(n, s);
649
+ } else i = e.datasets ?? {};
650
+ } catch (s) {
651
+ throw a?.aborted ? N(a) : s instanceof w ? s : new w("fetch", `报表 ${n} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
652
+ }
653
+ return $(a), Ce(i, n), o?.(n, i), Ge(e, i, n), i;
654
+ }
655
+ function ze(e, t) {
656
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new w("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
657
+ for (const n of ["revision", "sourceToken"])
658
+ if (e[n] !== void 0 && typeof e[n] != "string") throw new w("validate", `报表 ${t} Provider ${n} 应为字符串`);
659
+ if (e.diagnostics !== void 0 && (!Array.isArray(e.diagnostics) || e.diagnostics.some((n) => !n || typeof n.code != "string" || typeof n.message != "string" || !["info", "warning", "error"].includes(n.severity))))
660
+ throw new w("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
661
+ }
662
+ function Ge(e, t, n) {
663
+ for (const [r, o] of Object.entries(e.dataSchema ?? {})) {
664
+ let a;
665
+ try {
666
+ a = ve(Object.prototype.hasOwnProperty.call(t, r) ? t[r] : void 0, o, { ...e.dataValidation, path: `$.datasets.${r}` });
667
+ } catch (i) {
668
+ throw new w("config", `报表 ${n} 数据集 ${r} 字段契约配置无效`, i);
669
+ }
670
+ if (!a.ok) throw new w("validate", `报表 ${n} 数据集 ${r} 不符合字段契约:${a.issues[0]?.message}`, { issues: a.issues });
671
+ }
672
+ }
673
+ function Ye(e, t, n, r, o) {
674
+ const a = o ? o.maxPages - o.usedPages : void 0;
675
+ try {
676
+ if (a !== void 0 && a < 1 && e.pages.length) throw new R(0, 1);
677
+ const i = a === void 0 ? n.pagination : {
678
+ ...n.pagination,
679
+ maxPages: Math.max(1, Math.min(a, n.pagination?.maxPages ?? a))
680
+ };
681
+ return je(e, t, i);
682
+ } catch (i) {
683
+ const s = i instanceof R && o && i.limit === a ? new R(o.maxPages, o.usedPages + i.actual) : i;
684
+ throw new w("validate", `报表 ${r} 排版失败:${s instanceof Error ? s.message : String(s)}`, s);
685
+ }
686
+ }
687
+ function qe(e, t, n, r) {
688
+ const o = /* @__PURE__ */ new Map(), a = (i) => {
689
+ let s = o.get(i);
690
+ return s === void 0 && (s = JSON.stringify([n, r, i]), o.set(i, s)), s;
691
+ };
692
+ for (const i of t.pages) e.push({
693
+ ...i,
694
+ components: i.components.map((s) => s.table ? {
695
+ ...s,
696
+ table: { ...s.table, id: a(s.table.id) }
697
+ } : s)
698
+ });
699
+ }
700
+ function rt(e, t = {}) {
701
+ if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new w("config", "maxPages 应为正安全整数");
702
+ function n(o) {
703
+ const a = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
704
+ if (!a) throw new w("config", `未注册报表 ${o}`);
705
+ return a;
706
+ }
707
+ return Object.assign(async ({ reportIds: o, params: a, signal: i, onWarning: s, onQueryResult: l }) => {
708
+ $(i);
709
+ const d = [...o], u = { ...a };
710
+ if (d.length === 0) throw new w("config", "缺少报表 ID");
711
+ const f = d.map(n), b = f.map((h) => O(
712
+ h.params ?? (typeof h.template == "function" ? [] : h.template.params) ?? [],
713
+ u
714
+ )), y = [], g = [];
715
+ for (const [h, S] of f.entries()) {
716
+ $(i);
717
+ const p = d[h], P = { reportId: p, params: b[h], signal: i }, k = typeof S.template == "function" ? await We(S.template, P, g) : S.template;
718
+ P.params = O(S.params ?? k.params ?? [], P.params);
719
+ const T = await _e(S, P, p, l, t.onDatasets ? (F, te) => t.onDatasets(F, te, k) : void 0);
720
+ $(i);
721
+ const L = Ye(k, T, S, p, t.maxPages === void 0 ? void 0 : { maxPages: t.maxPages, usedPages: y.length });
722
+ qe(y, L.plan, h, p), g.push(...L.warnings.map((F) => `${p}: ${F}`));
723
+ }
724
+ $(i);
725
+ const m = { schemaVersion: W, pages: y }, c = oe(m);
726
+ if (!c.ok)
727
+ throw new w("validate", `渲染计划校验失败:${c.errors.slice(0, 3).map((h) => `${h.path}: ${h.message}`).join("; ")}`);
728
+ g.push(...c.warnings.map((h) => `${h.path}: ${h.message}`));
729
+ const M = s ?? t.onWarning ?? ((h) => console.warn("[mach-report]", h));
730
+ for (const h of g)
731
+ $(i), M(h);
732
+ return $(i), m;
733
+ }, {
734
+ getParamDefs: (o) => ae(e, o)
735
+ });
736
+ }
737
+ export {
738
+ R as P,
739
+ w as R,
740
+ nt as a,
741
+ me as b,
742
+ rt as c,
743
+ tt as d,
744
+ le as e,
745
+ q as f,
746
+ D as g,
747
+ je as p,
748
+ Y as t,
749
+ ve as v
750
+ };