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