@agile-team/mach-report 2.3.0 → 2.3.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 (42) hide show
  1. package/README.md +18 -3
  2. package/dist/ReportPreview-B-mwUSk9.cjs +6 -0
  3. package/dist/{ReportPreview-CwTGfyTq.js → ReportPreview-DKjr4cwO.js} +628 -619
  4. package/dist/defaults-D4o0NCLo.js +9 -0
  5. package/dist/defaults-DOO1yHwx.cjs +1 -0
  6. package/dist/grid-geometry-Dw7BlENr.js +130 -0
  7. package/dist/grid-geometry-bkciiZ4Q.cjs +1 -0
  8. package/dist/index.cjs +6 -6
  9. package/dist/index.d.cts +8 -2
  10. package/dist/index.d.ts +8 -2
  11. package/dist/index.js +1067 -995
  12. package/dist/pdf.cjs +48 -48
  13. package/dist/pdf.d.cts +2 -0
  14. package/dist/pdf.d.ts +2 -0
  15. package/dist/pdf.js +5605 -5575
  16. package/dist/{plugin-MSh_OhoW.cjs → plugin-2lqgTX26.cjs} +1 -1
  17. package/dist/{plugin-uoO9VA6O.js → plugin-5R00MJQs.js} +1 -1
  18. package/dist/render-plan-CfJ3wf1l.cjs +1 -0
  19. package/dist/render-plan-I9AHvQv7.js +13 -0
  20. package/dist/sql.cjs +42 -42
  21. package/dist/sql.js +1366 -1363
  22. package/dist/style.css +1 -1
  23. package/dist/textwrap-nH0UYU6D.js +108 -0
  24. package/dist/textwrap-oD-t4b4B.cjs +4 -0
  25. package/dist/vue/async.d.cts +5 -3
  26. package/dist/vue/async.d.ts +5 -3
  27. package/dist/vue/index.d.cts +6 -4
  28. package/dist/vue/index.d.ts +6 -4
  29. package/dist/vue-async.cjs +1 -1
  30. package/dist/vue-async.js +3 -3
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.js +4 -4
  33. package/dist/xlsx.cjs +23 -23
  34. package/dist/xlsx.d.cts +2 -0
  35. package/dist/xlsx.d.ts +2 -0
  36. package/dist/xlsx.js +6118 -6085
  37. package/package.json +1 -1
  38. package/dist/ReportPreview-CLENbOCL.cjs +0 -6
  39. package/dist/grid-geometry-CWmJ9c9y.js +0 -130
  40. package/dist/grid-geometry-DBH9ExuY.cjs +0 -1
  41. package/dist/textwrap-BQyrpYSR.js +0 -117
  42. package/dist/textwrap-DqiFwAV3.cjs +0 -3
package/dist/index.js CHANGED
@@ -1,10 +1,13 @@
1
- import { D as ve, r as K, L as Te, a as Ie, b as ne, m as rt, c as te, d as ye, p as he, e as st, f as je, g as at, P as ge } from "./grid-geometry-CWmJ9c9y.js";
2
- import { C as an, h as ln, i as dn, M as cn, S as mn, j as fn, k as hn } from "./grid-geometry-CWmJ9c9y.js";
3
- import { h as ke, R as Ae, w as le, i as lt, a as De } from "./textwrap-BQyrpYSR.js";
4
- import { c as un, b as pn, d as yn, m as Mn } from "./textwrap-BQyrpYSR.js";
5
- import { c as dt } from "./page-window-index-CIuT4BAv.js";
6
- import { g as ct } from "./report-params-B3Fia6JO.js";
7
- function _e(e) {
1
+ import { D as We, L as Me, a as be } from "./defaults-D4o0NCLo.js";
2
+ import { b as xn, c as En, S as Pn } from "./defaults-D4o0NCLo.js";
3
+ import { m as R, r as D, a as J, b as te, c as V, d as ne, e as we, f as Ve, p as X, g as $e, P as Q } from "./grid-geometry-Dw7BlENr.js";
4
+ import { C as Cn, M as Rn, h as On, i as Hn } from "./grid-geometry-Dw7BlENr.js";
5
+ import { R as de, i as Ge, a as Se } from "./render-plan-I9AHvQv7.js";
6
+ import { h as ce, w as Y } from "./textwrap-nH0UYU6D.js";
7
+ import { c as Ln, a as In, b as Bn, m as zn } from "./textwrap-nH0UYU6D.js";
8
+ import { c as Je } from "./page-window-index-CIuT4BAv.js";
9
+ import { g as Ye } from "./report-params-B3Fia6JO.js";
10
+ function ve(e) {
8
11
  if (!e || e.kind === "date") return;
9
12
  const t = e.digits;
10
13
  if (!(t !== void 0 && (!Number.isInteger(t) || t < 0 || t > 100))) {
@@ -15,7 +18,7 @@ function _e(e) {
15
18
  return t === void 0 ? e.thousands ? "#,##0.###############" : void 0 : `${e.thousands ? "#,##0" : "0"}${t ? `.${"0".repeat(t)}` : ""}`;
16
19
  }
17
20
  }
18
- function mt(e) {
21
+ function Ue(e) {
19
22
  const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
20
23
  if (t) {
21
24
  const i = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
@@ -24,61 +27,61 @@ function mt(e) {
24
27
  const n = new Date(e);
25
28
  return Number.isNaN(n.getTime()) ? null : n;
26
29
  }
27
- function $e(e, t) {
30
+ function ae(e, t) {
28
31
  return e.toLocaleString("en-US", {
29
32
  minimumFractionDigits: t,
30
33
  maximumFractionDigits: t
31
34
  });
32
35
  }
33
- function ft(e, t) {
36
+ function qe(e, t) {
34
37
  const n = (i) => String(i).padStart(2, "0");
35
38
  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()));
36
39
  }
37
- function ht(e, t, n) {
38
- return n != null ? t ? $e(e, n) : e.toFixed(n) : t ? $e(e) : String(e);
40
+ function Ke(e, t, n) {
41
+ return n != null ? t ? ae(e, n) : e.toFixed(n) : t ? ae(e) : String(e);
39
42
  }
40
- function Se(e) {
43
+ function se(e) {
41
44
  const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
42
45
  return Number.isFinite(t) ? t : null;
43
46
  }
44
- function ze(e, t) {
47
+ function ke(e, t) {
45
48
  if (e == null || e === "" || !t) return String(e ?? "");
46
49
  switch (t.kind) {
47
50
  case "number": {
48
- const n = Se(e);
49
- return n == null ? String(e) : ht(n, t.thousands === !0, t.digits);
51
+ const n = se(e);
52
+ return n == null ? String(e) : Ke(n, t.thousands === !0, t.digits);
50
53
  }
51
54
  case "percent": {
52
- const n = Se(e);
53
- return n == null ? String(e) : `${$e(n * 100, t.digits ?? 2)}%`;
55
+ const n = se(e);
56
+ return n == null ? String(e) : `${ae(n * 100, t.digits ?? 2)}%`;
54
57
  }
55
58
  case "date": {
56
- const n = t.pattern ?? "YYYY-MM-DD", i = e instanceof Date ? e : mt(String(e));
57
- return i ? ft(i, n) : String(e);
59
+ const n = t.pattern ?? "YYYY-MM-DD", i = e instanceof Date ? e : Ue(String(e));
60
+ return i ? qe(i, n) : String(e);
58
61
  }
59
62
  default:
60
63
  return String(e);
61
64
  }
62
65
  }
63
- function gt(e, t) {
66
+ function Xe(e, t) {
64
67
  const n = e[t.field];
65
68
  if (n == null || n === "") return !1;
66
69
  if (typeof t.value == "number") {
67
- const s = Se(n);
68
- if (s == null) return !1;
70
+ const r = se(n);
71
+ if (r == null) return !1;
69
72
  switch (t.op) {
70
73
  case ">":
71
- return s > t.value;
74
+ return r > t.value;
72
75
  case ">=":
73
- return s >= t.value;
76
+ return r >= t.value;
74
77
  case "<":
75
- return s < t.value;
78
+ return r < t.value;
76
79
  case "<=":
77
- return s <= t.value;
80
+ return r <= t.value;
78
81
  case "==":
79
- return s === t.value;
82
+ return r === t.value;
80
83
  case "!=":
81
- return s !== t.value;
84
+ return r !== t.value;
82
85
  }
83
86
  }
84
87
  const i = String(n), o = String(t.value);
@@ -98,7 +101,7 @@ function gt(e, t) {
98
101
  }
99
102
  return !1;
100
103
  }
101
- const ut = /* @__PURE__ */ new Set([
104
+ const Qe = /* @__PURE__ */ new Set([
102
105
  "text",
103
106
  "image",
104
107
  "barcode",
@@ -108,83 +111,93 @@ const ut = /* @__PURE__ */ new Set([
108
111
  "rect",
109
112
  "ellipse"
110
113
  ]);
111
- function q(e) {
114
+ function z(e) {
112
115
  return typeof e == "object" && e !== null && !Array.isArray(e);
113
116
  }
114
- function pt(e, t, n, i) {
117
+ function Ze(e, t, n, i) {
115
118
  const o = e[t];
116
119
  (typeof o != "number" || !Number.isFinite(o)) && i.push({ path: `${n}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(o)}` });
117
120
  }
118
- function Ee(e, t, n, i = []) {
119
- if (!q(e)) {
121
+ function et(e, t, n) {
122
+ if (e !== void 0) {
123
+ const i = `${t}.table`;
124
+ if (!z(e)) n.push({ path: i, message: "逻辑表来源应为对象" });
125
+ else {
126
+ (typeof e.id != "string" || !e.id.trim()) && n.push({ path: `${i}.id`, message: "逻辑表 ID 应为非空字符串" });
127
+ const o = e.role;
128
+ ["header", "body", "group-header", "subtotal", "grand-total"].includes(o) || n.push({ path: `${i}.role`, message: "未知逻辑表行角色" });
129
+ const r = e.rowIndex;
130
+ (typeof r != "number" || !Number.isInteger(r) || (o === "header" ? r !== -1 : r < 0)) && n.push({ path: `${i}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(e.columnKeys) || e.columnKeys.some((a) => typeof a != "string")) && n.push({ path: `${i}.columnKeys`, message: "逻辑列字段应为字符串数组" }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${i}.layout`, message: "布局应为 page 或 wide" }), e.title !== void 0 && typeof e.title != "string" && n.push({ path: `${i}.title`, message: "逻辑表名称应为字符串" });
131
+ }
132
+ }
133
+ }
134
+ function tt(e, t, n, i) {
135
+ if (e !== void 0)
136
+ if (!z(e) || !Array.isArray(e.cells))
137
+ n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" });
138
+ else {
139
+ const o = e.paddingMm;
140
+ o !== void 0 && (typeof o != "number" || !Number.isFinite(o) || o < 0) && n.push({ path: `${t}.grid.paddingMm`, message: "单元格内距应为有限非负数" }), e.cells.forEach((r, a) => {
141
+ if (!Array.isArray(r)) {
142
+ n.push({ path: `${t}.grid.cells.${a}`, message: "行应为数组" });
143
+ return;
144
+ }
145
+ r.forEach((s, l) => {
146
+ s != null && z(s) && Array.isArray(s.children) && s.children.forEach((d, c) => {
147
+ me(d, `${t}.grid.cells.${a}.${l}.children.${c}`, n, i);
148
+ });
149
+ });
150
+ });
151
+ }
152
+ }
153
+ function nt(e, t, n) {
154
+ e !== void 0 && (Array.isArray(e) ? e.forEach((i, o) => {
155
+ (!z(i) || !Array.isArray(i.segments)) && n.push({ path: `${t}.richParagraphs.${o}`, message: "段落缺少 segments 数组" });
156
+ }) : n.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
157
+ }
158
+ function me(e, t, n, i = []) {
159
+ if (!z(e)) {
120
160
  n.push({ path: t, message: "组件应为对象" });
121
161
  return;
122
162
  }
123
163
  const o = e.kind;
124
- typeof o != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : ut.has(o) || i.push({
164
+ typeof o != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : Qe.has(o) || i.push({
125
165
  path: `${t}.kind`,
126
166
  message: `未知组件类型 ${JSON.stringify(o)},将以兜底方式渲染`
127
167
  });
128
- for (const l of ["leftMm", "topMm", "widthMm", "heightMm"])
129
- pt(e, l, t, n);
168
+ for (const r of ["leftMm", "topMm", "widthMm", "heightMm"])
169
+ Ze(e, r, t, n);
130
170
  typeof e.leftMm == "number" && e.leftMm < -100 && n.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
131
- for (const l of ["widthMm", "heightMm"])
132
- typeof e[l] == "number" && e[l] < 0 && n.push({ path: `${t}.${l}`, message: "组件尺寸不能为负数" });
133
- const s = e.table;
134
- if (s !== void 0) {
135
- const l = `${t}.table`;
136
- if (!q(s)) n.push({ path: l, message: "逻辑表来源应为对象" });
137
- else {
138
- (typeof s.id != "string" || !s.id.trim()) && n.push({ path: `${l}.id`, message: "逻辑表 ID 应为非空字符串" });
139
- const d = s.role;
140
- ["header", "body", "group-header", "subtotal", "grand-total"].includes(d) || n.push({ path: `${l}.role`, message: "未知逻辑表行角色" });
141
- const m = s.rowIndex;
142
- (typeof m != "number" || !Number.isInteger(m) || (d === "header" ? m !== -1 : m < 0)) && n.push({ path: `${l}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(s.columnKeys) || s.columnKeys.some((h) => typeof h != "string")) && n.push({ path: `${l}.columnKeys`, message: "逻辑列字段应为字符串数组" }), s.layout !== void 0 && s.layout !== "page" && s.layout !== "wide" && n.push({ path: `${l}.layout`, message: "布局应为 page 或 wide" }), s.title !== void 0 && typeof s.title != "string" && n.push({ path: `${l}.title`, message: "逻辑表名称应为字符串" });
143
- }
144
- }
145
- const r = e.grid;
146
- r !== void 0 && (!q(r) || !Array.isArray(r.cells) ? n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" }) : r.cells.forEach((l, d) => {
147
- if (!Array.isArray(l)) {
148
- n.push({ path: `${t}.grid.cells.${d}`, message: "行应为数组" });
149
- return;
150
- }
151
- l.forEach((m, h) => {
152
- m != null && q(m) && Array.isArray(m.children) && m.children.forEach((f, g) => {
153
- Ee(f, `${t}.grid.cells.${d}.${h}.children.${g}`, n, i);
154
- });
155
- });
156
- }));
157
- const a = e.richParagraphs;
158
- a !== void 0 && (Array.isArray(a) ? a.forEach((l, d) => {
159
- (!q(l) || !Array.isArray(l.segments)) && n.push({ path: `${t}.richParagraphs.${d}`, message: "段落缺少 segments 数组" });
160
- }) : n.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
171
+ for (const r of ["widthMm", "heightMm"])
172
+ typeof e[r] == "number" && e[r] < 0 && n.push({ path: `${t}.${r}`, message: "组件尺寸不能为负数" });
173
+ et(e.table, t, n), tt(e.grid, t, n, i), nt(e.richParagraphs, t, n);
161
174
  }
162
- function yt(e, t, n, i = []) {
163
- if (!q(e)) {
175
+ function it(e, t, n, i = []) {
176
+ if (!z(e)) {
164
177
  n.push({ path: t, message: "页应为对象" });
165
178
  return;
166
179
  }
167
- const o = e.pageWidthMm, s = e.pageHeightMm;
168
- (typeof o != "number" || !Number.isFinite(o) || o <= 0) && n.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof s != "number" || !(s > 0 && s < 5e3)) && n.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(s)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" });
169
- const r = e.components;
170
- Array.isArray(r) ? Array.isArray(r) && r.forEach(
171
- (a, l) => Ee(a, `${t}.components.${l}`, n, i)
180
+ const o = e.pageWidthMm, r = e.pageHeightMm;
181
+ (typeof o != "number" || !Number.isFinite(o) || o <= 0) && n.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof r != "number" || !(r > 0 && r < 5e3)) && n.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(r)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" });
182
+ const a = e.components;
183
+ Array.isArray(a) ? Array.isArray(a) && a.forEach(
184
+ (s, l) => me(s, `${t}.components.${l}`, n, i)
172
185
  ) : n.push({ path: `${t}.components`, message: "components 应为数组" });
173
186
  }
174
- function We(e) {
175
- const t = [], n = [], i = q(e) ? e.pages : void 0;
187
+ function Te(e) {
188
+ const t = [], n = [], i = z(e) ? e.pages : void 0;
176
189
  if (!Array.isArray(i))
177
190
  t.push({
178
191
  path: "$.pages",
179
192
  message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
180
193
  });
181
194
  else {
182
- i.forEach((s, r) => yt(s, `$.pages.${r}`, t, n)), i.length > 2e3 && n.push({
195
+ i.forEach((r, a) => it(r, `$.pages.${a}`, t, n)), i.length > 2e3 && n.push({
183
196
  path: "$.pages",
184
197
  message: `页数异常大(${i.length} 页),渲染与打印耗时可能显著增加`
185
198
  });
186
199
  const o = i.reduce(
187
- (s, r) => s + (q(r) && Array.isArray(r.components) ? r.components.length : 0),
200
+ (r, a) => r + (z(a) && Array.isArray(a.components) ? a.components.length : 0),
188
201
  0
189
202
  );
190
203
  o > 5e4 && n.push({
@@ -194,15 +207,15 @@ function We(e) {
194
207
  }
195
208
  return { ok: t.length === 0, errors: t, warnings: n };
196
209
  }
197
- function Jt(e) {
198
- const t = We(e);
210
+ function fn(e) {
211
+ const t = Te(e);
199
212
  if (!t.ok) {
200
213
  const n = t.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ");
201
214
  throw new Error(`渲染计划校验失败(${t.errors.length} 处): ${n}`);
202
215
  }
203
216
  return e.pages;
204
217
  }
205
- function Be(e) {
218
+ function ot(e) {
206
219
  return {
207
220
  widthMm: e.widthMm,
208
221
  heightMm: e.heightMm,
@@ -213,10 +226,10 @@ function Be(e) {
213
226
  components: []
214
227
  };
215
228
  }
216
- function Mt(e, t) {
229
+ function rt(e, t) {
217
230
  return t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
218
231
  }
219
- function Ve(e) {
232
+ function Ae(e) {
220
233
  if (e == null) return "";
221
234
  if (typeof e == "string") return e;
222
235
  if (typeof e == "number") return String(e);
@@ -228,312 +241,299 @@ function Ve(e) {
228
241
  return String(e);
229
242
  }
230
243
  }
231
- function Je(e, t) {
244
+ function xe(e, t) {
232
245
  let n = e.textMetrics.get(t);
233
246
  if (!n) {
234
- const i = K(t).fontSizePt;
247
+ const i = D(t).fontSizePt;
235
248
  n = {
236
249
  measureOptions: {
237
250
  fontSizePt: i,
238
251
  bold: t.bold,
239
- letterSpacingPt: t.letterSpacing === void 0 ? void 0 : t.letterSpacing * 72 / 96
252
+ letterSpacingPt: t.letterSpacing
240
253
  },
241
- lineMm: i * (t.lineHeight ?? Te) * 25.4 / 72
254
+ lineMm: i * (t.lineHeight ?? Me) * 25.4 / 72
242
255
  }, e.textMetrics.set(t, n);
243
256
  }
244
257
  return n;
245
258
  }
246
- function Ge(e, t) {
259
+ function Ee(e, t) {
247
260
  return 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";
248
261
  }
249
- function bt(e) {
262
+ function at(e) {
250
263
  if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
251
264
  }
252
- function wt(e, t) {
253
- const n = e.fontSizePt ?? ve, i = e.paddingMm ?? 1, o = e.columns.map((c) => c.align ?? c.style?.align ?? e.align ?? "left"), s = e.columns.map((c, b) => ({
254
- fontSize: n,
255
- verticalAlign: "middle",
256
- ...c.style,
257
- align: o[b] === "auto" ? "left" : o[b]
258
- })), r = s.map((c, b) => o[b] === "auto" ? { left: c, center: { ...c, align: "center" }, right: { ...c, align: "right" } } : void 0), a = e.columns.map((c, b) => c.rules?.map((y) => {
259
- const T = r[b];
260
- if (T) return {
261
- left: { ...T.left, ...y.style },
262
- center: { ...T.center, ...y.style },
263
- right: { ...T.right, ...y.style }
265
+ function st(e, t) {
266
+ const n = e.fontSizePt ?? We, i = e.paddingMm ?? 1, o = e.columns.map((m) => m.align ?? m.style?.align ?? e.align ?? "left"), r = e.columns.map((m, h) => ({
267
+ ...R({
268
+ fontSize: n,
269
+ verticalAlign: "middle"
270
+ }, m.style),
271
+ align: o[h] === "auto" ? "left" : o[h]
272
+ })), a = r.map((m, h) => o[h] === "auto" ? { left: m, center: { ...m, align: "center" }, right: { ...m, align: "right" } } : void 0), s = e.columns.map((m, h) => m.rules?.map((p) => {
273
+ const M = a[h];
274
+ if (M) return {
275
+ left: R(M.left, p.style),
276
+ center: R(M.center, p.style),
277
+ right: R(M.right, p.style)
264
278
  };
265
- const $ = { ...s[b], ...y.style };
266
- return { left: $, center: $, right: $ };
267
- })), l = e.columns.map(
268
- (c) => ({
279
+ const b = R(r[h], p.style);
280
+ return { left: b, center: b, right: b };
281
+ })), l = e.columns.map((m) => {
282
+ let h = R({
269
283
  fontSize: n,
270
284
  bold: e.headerBold ?? !0,
271
285
  align: "center",
272
286
  verticalAlign: "middle",
273
- backgroundColor: e.headerBackgroundColor,
274
- ...c.style || {},
275
- ...e.headerAlign === void 0 ? {} : { align: e.headerAlign },
276
- ...e.headerStyle,
277
- ...c.headerAlign === void 0 ? {} : { align: c.headerAlign },
278
- ...c.headerStyle
279
- })
280
- ), d = e.columns.map((c) => c.header);
281
- let m = e.rowHeightMm ?? 0;
282
- for (let c = 0; c < d.length; c++) {
283
- const b = l[c], y = K(b).fontSizePt, T = le(
284
- d[c],
285
- e.columns[c].widthMm - i * 2,
286
- { fontSizePt: y, bold: b.bold },
287
+ backgroundColor: e.headerBackgroundColor
288
+ }, m.style);
289
+ return e.headerAlign !== void 0 && (h.align = e.headerAlign), h = R(h, e.headerStyle), m.headerAlign !== void 0 && (h.align = m.headerAlign), R(h, m.headerStyle);
290
+ }), d = e.columns.map((m) => m.header);
291
+ let c = e.rowHeightMm ?? 0;
292
+ for (let m = 0; m < d.length; m++) {
293
+ const h = l[m], p = D(h).fontSizePt, M = Y(
294
+ d[m],
295
+ e.columns[m].widthMm - i * 2,
296
+ { fontSizePt: p, bold: h.bold, letterSpacingPt: h.letterSpacing },
287
297
  t
288
- ), $ = y * (b.lineHeight ?? Te) * 25.4 / 72;
289
- m = Math.max(m, Math.max(T.length, 1) * $ + i * 2);
298
+ ), b = p * (h.lineHeight ?? Me) * 25.4 / 72;
299
+ c = Math.max(c, Math.max(M.length, 1) * b + i * 2);
290
300
  }
291
- const h = d.map((c, b) => ({
292
- text: c,
293
- style: l[b]
294
- })), f = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, g = e.columns.map((c) => c.widthMm);
301
+ const f = d.map((m, h) => ({
302
+ text: m,
303
+ style: l[h]
304
+ })), g = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, u = e.columns.map((m) => m.widthMm);
295
305
  return {
296
306
  fontSizePt: n,
297
307
  paddingMm: i,
298
- cellStyles: s,
299
- autoStyles: r,
300
- ruleStyles: a,
308
+ cellStyles: r,
309
+ autoStyles: a,
310
+ ruleStyles: s,
301
311
  textMetrics: /* @__PURE__ */ new WeakMap(),
302
- numberFormats: e.columns.map((c) => _e(c.format)),
303
- borderStyle: f,
304
- headerHeightMm: m,
312
+ numberFormats: e.columns.map((m) => ve(m.format)),
313
+ borderStyle: g,
314
+ headerHeightMm: c,
305
315
  headerGrid: {
306
- cells: [h],
307
- colWidthsMm: g,
308
- rowHeightsMm: [m]
316
+ cells: [f],
317
+ colWidthsMm: u,
318
+ rowHeightsMm: [c],
319
+ paddingMm: i
309
320
  },
310
- colWidthsMm: g,
321
+ colWidthsMm: u,
311
322
  columns: e.columns
312
323
  };
313
324
  }
314
- function Oe(e, t, n) {
325
+ function ge(e, t, n) {
315
326
  const i = e.columns;
316
327
  let o = e.rowHeightFloorMm;
317
- const s = new Array(i.length);
318
- for (let r = 0; r < i.length; r++) {
319
- const a = i[r], l = t[a.field], d = e.autoStyles[r] ? Ge(l, a.format) : "left";
320
- let m = e.autoStyles[r]?.[d] ?? e.cellStyles[r];
321
- if (a.rules)
322
- for (let y = 0; y < a.rules.length; y++) {
323
- const T = a.rules[y];
324
- if (gt(t, T.when)) {
325
- m = e.ruleStyles[r][y][d];
328
+ const r = new Array(i.length);
329
+ for (let a = 0; a < i.length; a++) {
330
+ const s = i[a], l = t[s.field], d = e.autoStyles[a] ? Ee(l, s.format) : "left";
331
+ let c = e.autoStyles[a]?.[d] ?? e.cellStyles[a];
332
+ if (s.rules)
333
+ for (let p = 0; p < s.rules.length; p++) {
334
+ const M = s.rules[p];
335
+ if (Xe(t, M.when)) {
336
+ c = e.ruleStyles[a][p][d];
326
337
  break;
327
338
  }
328
339
  }
329
- const h = a.format ? ze(l, a.format) : Ve(l), f = Je(e, m), g = le(h, a.widthMm - e.paddingMm * 2, f.measureOptions, n);
330
- o = Math.max(o, g.length * f.lineMm + e.paddingMm * 2);
331
- const c = bt(l), b = { text: h, style: m };
332
- c !== void 0 && (b.value = c), typeof c == "number" && e.numberFormats[r] !== void 0 && (b.numberFormat = e.numberFormats[r]), s[r] = b;
340
+ const f = s.format ? ke(l, s.format) : Ae(l), g = xe(e, c), u = Y(f, s.widthMm - e.paddingMm * 2, g.measureOptions, n);
341
+ o = Math.max(o, u.length * g.lineMm + e.paddingMm * 2);
342
+ const m = at(l), h = { text: f, style: c };
343
+ m !== void 0 && (h.value = m), typeof m == "number" && e.numberFormats[a] !== void 0 && (h.numberFormat = e.numberFormats[a]), r[a] = h;
333
344
  }
334
345
  return {
335
- grid: { cells: [s], colWidthsMm: e.colWidthsMm, rowHeightsMm: [o] },
346
+ grid: { cells: [r], colWidthsMm: e.colWidthsMm, rowHeightsMm: [o], paddingMm: e.paddingMm },
336
347
  heightMm: o
337
348
  };
338
349
  }
339
- function $t(e, t, n = {}) {
340
- const i = typeof n == "number" ? { mmPerRow: n } : n, o = i.mmPerRow ?? 0, s = i.measurer ?? ke, r = [], a = [];
341
- let l = 0;
342
- const d = (h) => `${h}_${(++l).toString(36)}`, m = [];
343
- for (const [h, f] of e.pages.entries()) {
344
- const g = Be(f), c = () => Mt(f, g), b = g.marginTopMm, y = [], T = ($ = !1) => {
345
- if (a.push({
346
- pageWidthMm: g.widthMm,
347
- pageHeightMm: g.heightMm,
348
- ...f.layout === void 0 ? {} : { layout: f.layout },
349
- marginTopMm: g.marginTopMm,
350
- marginBottomMm: g.marginBottomMm,
351
- marginLeftMm: g.marginLeftMm,
352
- marginRightMm: g.marginRightMm,
353
- components: g.components
354
- }), y.length > 0) {
355
- const E = a.length;
356
- for (const S of y) {
357
- const R = {
358
- ...S,
359
- text: String(S.text ?? "").replace(/\{page\}/g, String(E))
360
- };
361
- a[a.length - 1].components.push(R), R.text.includes("{totalPages}") && m.push(R);
362
- }
363
- }
364
- if (f.layout === "wide") {
365
- const E = a[a.length - 1], S = E.components.reduce((F, k) => Math.max(F, k.topMm + k.heightMm), 0), R = $ ? f.marginBottomMm ?? 0 : 0;
366
- E.pageHeightMm = Math.max(1, S + R), E.marginBottomMm = R;
367
- }
368
- };
369
- for (const [$, E] of f.components.entries()) {
370
- if (E.kind !== "list") {
371
- if (E.kind === "text" && typeof E.text == "string") {
372
- const w = E.text;
373
- if (w.includes("{page}") || w.includes("{totalPages}")) {
374
- y.push(E);
375
- continue;
376
- }
377
- }
378
- g.components.push(E);
379
- continue;
380
- }
381
- const S = E, R = t[S.dataset];
382
- Array.isArray(R) || r.push(`数据集 ${S.dataset} 未提供数据,列表 ${S.id ?? ""} 输出为空`);
383
- const F = Array.isArray(R) ? R : [], k = S.columns.reduce((w, M) => w + M.widthMm, 0), v = k > S.widthMm ? S.widthMm / k : 1, u = v === 1 ? S : { ...S, columns: S.columns.map((w) => ({ ...w, widthMm: w.widthMm * v })) }, p = {
384
- id: `table:${h}:${$}`,
385
- columnKeys: S.columns.map((w) => w.field),
386
- ...S.layout === void 0 ? {} : { layout: S.layout },
387
- ...S.title === void 0 ? {} : { title: S.title }
388
- };
389
- let B = 0;
390
- const A = {
391
- ...wt(u, s),
392
- rowHeightFloorMm: u.rowHeightMm ?? 0
393
- }, P = {
394
- kind: "rect",
395
- leftMm: S.leftMm,
396
- topMm: 0,
397
- widthMm: S.widthMm,
398
- heightMm: A.headerHeightMm,
399
- grid: A.headerGrid,
400
- nid: d("listh"),
401
- table: { ...p, role: "header", rowIndex: -1 },
402
- style: A.borderStyle
403
- };
404
- let N = S.topMm;
405
- const L = (w, M) => {
406
- w.components.push({ ...P, topMm: M });
407
- };
408
- L(g, N), N += A.headerHeightMm + o;
409
- const J = (w) => {
410
- if (N + w > c()) {
411
- T();
412
- const M = Be(f);
413
- g.components = M.components, g.heightMm = M.heightMm, f.layout === "wide" && (g.marginTopMm = 0, g.marginBottomMm = 0);
414
- const x = f.layout === "wide" ? 0 : S.topMm;
415
- u.headerEveryPage !== !1 ? (L(g, x), N = x + A.headerHeightMm) : N = f.layout === "wide" ? 0 : b;
416
- }
417
- }, Q = (w, M, x, C) => {
418
- const I = f.layout === "wide" ? 0 : S.topMm, Z = u.headerEveryPage !== !1 ? I + A.headerHeightMm : f.layout === "wide" ? 0 : b, oe = c() - Z;
419
- M > oe && r.push(
420
- `列表 ${S.id ?? S.dataset} 行高 ${M.toFixed(2)}mm 超出单页可用高度 ${oe.toFixed(2)}mm,预览与打印可能截断内容`
421
- ), J(M), g.components.push({
422
- kind: "rect",
423
- leftMm: S.leftMm,
424
- topMm: N,
425
- widthMm: S.widthMm,
426
- heightMm: M,
427
- grid: w,
428
- nid: d(x),
429
- table: { ...p, role: C, rowIndex: B++ },
430
- style: A.borderStyle
431
- }), N += M;
432
- }, nt = () => Oe(A, {}, s).heightMm, be = (w, M, x, C) => {
433
- const I = [], Z = Math.max(1, Math.min(C, u.columns.length)), oe = { fontSize: A.fontSizePt, ...x };
434
- I.push({ text: w, colSpan: Z, style: { bold: !0, ...oe } });
435
- for (let G = Z; G < u.columns.length; G++) {
436
- const re = u.columns[G], se = M.get(re.field), me = A.autoStyles[G]?.[Ge(se?.value, re.format)] ?? A.cellStyles[G];
437
- I.push({ ...se, text: se?.text ?? "", style: { ...me, ...oe } });
438
- }
439
- let de = A.rowHeightFloorMm, ce = 0;
440
- for (const G of I) {
441
- let re = 0;
442
- const se = ce + (G.colSpan ?? 1);
443
- for (; ce < se; ce++) re += A.colWidthsMm[ce] ?? 0;
444
- const me = Je(A, G.style), ot = le(G.text ?? "", re - A.paddingMm * 2, me.measureOptions, s);
445
- de = Math.max(de, ot.length * me.lineMm + A.paddingMm * 2);
446
- }
447
- return {
448
- grid: { cells: [I], colWidthsMm: A.colWidthsMm, rowHeightsMm: [de] },
449
- heightMm: de
450
- };
451
- }, it = (w, M) => {
452
- let x = 0;
453
- for (const C of w) {
454
- const I = typeof C[M] == "number" ? C[M] : Number(C[M]);
455
- Number.isFinite(I) && (x += I);
456
- }
457
- return x;
458
- }, Ce = (w, M) => {
459
- const C = u.columns.find((Z) => Z.field === M)?.format ?? { kind: "number", thousands: !0 }, I = it(w, M);
460
- return { text: ze(I, C), value: I, numberFormat: _e(C) };
461
- }, z = u.groupBy, Re = (w) => {
462
- const M = u.columns.findIndex((x) => w.includes(x.field));
463
- return M > 0 ? M : 1;
464
- }, ie = [];
465
- if (z) {
466
- const w = /* @__PURE__ */ new Map();
467
- for (const M of F) {
468
- const x = Ve(M[z.field]), C = w.get(x);
469
- C ? C.push(M) : w.set(x, [M]);
470
- }
471
- for (const [M, x] of w) {
472
- ie.push({
473
- kind: "groupHeader",
474
- label: (z.headerTemplate ?? "{value}").replace(/\{value\}/g, M)
475
- });
476
- for (const C of x) ie.push({ kind: "row", row: C });
477
- z.subtotal && z.subtotal.length > 0 && ie.push({
478
- kind: "subtotal",
479
- label: z.subtotalLabel ?? "小计",
480
- rows: x
481
- });
482
- }
483
- } else
484
- for (const w of F) ie.push({ kind: "row", row: w });
485
- const He = nt();
486
- for (const w of ie)
487
- if (w.kind === "row") {
488
- const M = Oe(A, w.row, s);
489
- Q(M.grid, M.heightMm, "listr", "body");
490
- } else if (w.kind === "groupHeader") {
491
- const M = be(
492
- w.label,
493
- /* @__PURE__ */ new Map(),
494
- z?.headerStyle ?? {},
495
- u.columns.length
496
- );
497
- z?.keepWithNext !== !1 && N + M.heightMm + He > c() && J(M.heightMm + He), Q(M.grid, M.heightMm, "listg", "group-header");
498
- } else if (w.kind === "subtotal") {
499
- const M = /* @__PURE__ */ new Map();
500
- for (const C of z.subtotal ?? []) M.set(C, Ce(w.rows, C));
501
- const x = be(
502
- w.label,
503
- M,
504
- z?.subtotalStyle ?? {},
505
- Re(z.subtotal ?? [])
506
- );
507
- Q(x.grid, x.heightMm, "listst", "subtotal");
508
- }
509
- if (u.grandTotal) {
510
- const w = typeof u.grandTotal == "object" ? u.grandTotal : void 0, M = w?.fields ?? z?.subtotal ?? [];
511
- if (M.length > 0) {
512
- const x = /* @__PURE__ */ new Map();
513
- for (const I of M) x.set(I, Ce(F, I));
514
- const C = be(
515
- w?.label ?? "合计",
516
- x,
517
- w?.style ?? {},
518
- Re(M)
519
- );
520
- Q(C.grid, C.heightMm, "listgt", "grand-total");
521
- } else
522
- r.push(`列表 ${S.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
523
- }
524
- }
525
- T(!0);
350
+ function* lt(e, t) {
351
+ if (!t) {
352
+ for (const i of e) yield { kind: "row", row: i };
353
+ return;
354
+ }
355
+ const n = /* @__PURE__ */ new Map();
356
+ for (const i of e) {
357
+ const o = Ae(i[t.field]), r = n.get(o);
358
+ r ? r.push(i) : n.set(o, [i]);
526
359
  }
527
- for (const h of m) {
528
- const f = h.text;
529
- typeof f == "string" && f.includes("{totalPages}") && (h.text = f.replace(/\{totalPages\}/g, String(a.length)));
360
+ for (const [i, o] of n) {
361
+ yield { kind: "groupHeader", label: (t.headerTemplate ?? "{value}").replace(/\{value\}/g, i), firstRow: o[0] };
362
+ for (const r of o) yield { kind: "row", row: r };
363
+ t.subtotal?.length && (yield { kind: "subtotal", label: t.subtotalLabel ?? "小计", rows: o });
364
+ }
365
+ }
366
+ function dt(e, t) {
367
+ let n = 0;
368
+ for (const i of e) {
369
+ const o = typeof i[t] == "number" ? i[t] : Number(i[t]);
370
+ Number.isFinite(o) && (n += o);
371
+ }
372
+ return n;
373
+ }
374
+ function Pe(e, t, n) {
375
+ return new Map(n.map((i) => {
376
+ const o = e.find((a) => a.field === i)?.format ?? { kind: "number", thousands: !0 }, r = dt(t, i);
377
+ return [i, { text: ke(r, o), value: r, numberFormat: ve(o) }];
378
+ }));
379
+ }
380
+ function Ne(e, t) {
381
+ const n = e.findIndex((i) => t.includes(i.field));
382
+ return n > 0 ? n : 1;
383
+ }
384
+ function le(e, t, n, i, o, r) {
385
+ const a = [], s = Math.max(1, Math.min(r, e.columns.length)), l = R({ fontSize: e.fontSizePt }, o);
386
+ a.push({ text: n, colSpan: s, style: { bold: !0, ...l } });
387
+ for (let f = s; f < e.columns.length; f++) {
388
+ const g = e.columns[f], u = i.get(g.field), m = e.autoStyles[f]?.[Ee(u?.value, g.format)] ?? e.cellStyles[f];
389
+ a.push({ ...u, text: u?.text ?? "", style: R(m, o) });
390
+ }
391
+ let d = e.rowHeightFloorMm, c = 0;
392
+ for (const f of a) {
393
+ let g = 0;
394
+ const u = c + (f.colSpan ?? 1);
395
+ for (; c < u; c++) g += e.colWidthsMm[c] ?? 0;
396
+ const m = xe(e, f.style), h = Y(f.text ?? "", g - e.paddingMm * 2, m.measureOptions, t);
397
+ d = Math.max(d, h.length * m.lineMm + e.paddingMm * 2);
530
398
  }
531
399
  return {
532
- plan: { schemaVersion: Ae, pages: a },
533
- warnings: r
400
+ grid: { cells: [a], colWidthsMm: e.colWidthsMm, rowHeightsMm: [d], paddingMm: e.paddingMm },
401
+ heightMm: d
534
402
  };
535
403
  }
536
- const St = {
404
+ function ct(e, t, n) {
405
+ const { templatePage: i, current: o, warnings: r, nextId: a, pushCurrent: s } = n, l = () => rt(i, o), d = o.marginTopMm, c = {
406
+ id: n.tableId,
407
+ columnKeys: e.columns.map((w) => w.field),
408
+ ...e.layout === void 0 ? {} : { layout: e.layout },
409
+ ...e.title === void 0 ? {} : { title: e.title }
410
+ };
411
+ let f = 0;
412
+ const g = {
413
+ kind: "rect",
414
+ leftMm: e.leftMm,
415
+ topMm: 0,
416
+ widthMm: e.widthMm,
417
+ heightMm: t.headerHeightMm,
418
+ grid: t.headerGrid,
419
+ nid: a("listh"),
420
+ table: { ...c, role: "header", rowIndex: -1 },
421
+ style: t.borderStyle
422
+ }, u = (w) => o.components.push({ ...g, topMm: w });
423
+ let m = e.topMm;
424
+ u(m), m += t.headerHeightMm + n.mmPerRow;
425
+ function h() {
426
+ const w = i.layout === "wide" ? 0 : e.topMm;
427
+ return e.headerEveryPage !== !1 ? w + t.headerHeightMm : i.layout === "wide" ? 0 : d;
428
+ }
429
+ function p() {
430
+ const w = i.layout === "wide" ? 0 : o.marginBottomMm;
431
+ return i.heightMm - w - h();
432
+ }
433
+ function M(w) {
434
+ if (m + w <= l()) return;
435
+ s(), o.components = [], o.heightMm = i.heightMm, i.layout === "wide" && (o.marginTopMm = 0, o.marginBottomMm = 0);
436
+ const I = i.layout === "wide" ? 0 : e.topMm;
437
+ e.headerEveryPage !== !1 ? (u(I), m = I + t.headerHeightMm) : m = i.layout === "wide" ? 0 : d;
438
+ }
439
+ function b(w, I, _) {
440
+ const B = p();
441
+ w.heightMm > B && r.push(`列表 ${e.id ?? e.dataset} 行高 ${w.heightMm.toFixed(2)}mm 超出单页可用高度 ${B.toFixed(2)}mm,预览与打印可能截断内容`), M(w.heightMm), o.components.push({
442
+ kind: "rect",
443
+ leftMm: e.leftMm,
444
+ topMm: m,
445
+ widthMm: e.widthMm,
446
+ heightMm: w.heightMm,
447
+ grid: w.grid,
448
+ nid: a(I),
449
+ table: { ...c, role: _, rowIndex: f++ },
450
+ style: t.borderStyle
451
+ }), m += w.heightMm;
452
+ }
453
+ function A(w) {
454
+ w <= p() && M(w);
455
+ }
456
+ return { keepTogether: A, placeGridRow: b };
457
+ }
458
+ function mt(e, t, n, i, o) {
459
+ if (!e.grandTotal) return;
460
+ const r = typeof e.grandTotal == "object" ? e.grandTotal : void 0, a = r?.fields ?? e.groupBy?.subtotal ?? [];
461
+ if (a.length === 0) {
462
+ i.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
463
+ return;
464
+ }
465
+ const s = le(n, i.measurer, r?.label ?? "合计", Pe(e.columns, t, a), r?.style ?? {}, Ne(e.columns, a));
466
+ o.placeGridRow(s, "listgt", "grand-total");
467
+ }
468
+ function ft(e, t, n) {
469
+ const i = e.columns.reduce((d, c) => d + c.widthMm, 0), o = i > e.widthMm ? e.widthMm / i : 1, r = o === 1 ? e : { ...e, columns: e.columns.map((d) => ({ ...d, widthMm: d.widthMm * o })) }, a = { ...st(r, n.measurer), rowHeightFloorMm: r.rowHeightMm ?? 0 }, s = ct(r, a, n);
470
+ let l;
471
+ for (const d of lt(t, r.groupBy))
472
+ if (d.kind === "row")
473
+ s.placeGridRow(l ?? ge(a, d.row, n.measurer), "listr", "body"), l = void 0;
474
+ else if (d.kind === "groupHeader") {
475
+ const c = le(a, n.measurer, d.label, /* @__PURE__ */ new Map(), r.groupBy?.headerStyle ?? {}, r.columns.length);
476
+ l = ge(a, d.firstRow, n.measurer), r.groupBy?.keepWithNext !== !1 && s.keepTogether(c.heightMm + l.heightMm), s.placeGridRow(c, "listg", "group-header");
477
+ } else {
478
+ const c = r.groupBy?.subtotal ?? [], f = le(a, n.measurer, d.label, Pe(r.columns, d.rows, c), r.groupBy?.subtotalStyle ?? {}, Ne(r.columns, c));
479
+ s.placeGridRow(f, "listst", "subtotal");
480
+ }
481
+ mt(r, t, a, n, s);
482
+ }
483
+ function pe(e) {
484
+ return e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}"));
485
+ }
486
+ function ht(e, t, n, i, o, r) {
487
+ const a = {
488
+ pageWidthMm: t.widthMm,
489
+ pageHeightMm: t.heightMm,
490
+ ...e.layout === void 0 ? {} : { layout: e.layout },
491
+ marginTopMm: t.marginTopMm,
492
+ marginBottomMm: t.marginBottomMm,
493
+ marginLeftMm: t.marginLeftMm,
494
+ marginRightMm: t.marginRightMm,
495
+ components: t.components
496
+ };
497
+ i.push(a);
498
+ for (const s of n) {
499
+ const l = { ...s, text: String(s.text ?? "").replace(/\{page\}/g, String(i.length)) };
500
+ a.components.push(l), l.text.includes("{totalPages}") && o.push(l);
501
+ }
502
+ if (e.layout === "wide") {
503
+ const s = a.components.reduce((l, d) => Math.max(l, d.topMm + d.heightMm), 0);
504
+ a.marginBottomMm = r ? e.marginBottomMm ?? 0 : 0, a.pageHeightMm = Math.max(1, s + a.marginBottomMm);
505
+ }
506
+ }
507
+ function ut(e, t, n = {}) {
508
+ const i = typeof n == "number" ? { mmPerRow: n } : n, o = [], r = [], a = [];
509
+ let s = 0;
510
+ const l = (d) => `${d}_${(++s).toString(36)}`;
511
+ for (const [d, c] of e.pages.entries()) {
512
+ const f = ot(c), g = c.components.filter(pe), u = (m = !1) => ht(c, f, g, r, a, m);
513
+ for (const [m, h] of c.components.entries()) {
514
+ if (pe(h)) continue;
515
+ if (h.kind !== "list") {
516
+ f.components.push(h);
517
+ continue;
518
+ }
519
+ const p = t[h.dataset];
520
+ Array.isArray(p) || o.push(`数据集 ${h.dataset} 未提供数据,列表 ${h.id ?? ""} 输出为空`), ft(h, Array.isArray(p) ? p : [], {
521
+ templatePage: c,
522
+ current: f,
523
+ warnings: o,
524
+ nextId: l,
525
+ pushCurrent: u,
526
+ measurer: i.measurer ?? ce,
527
+ mmPerRow: i.mmPerRow ?? 0,
528
+ tableId: `table:${d}:${m}`
529
+ });
530
+ }
531
+ u(!0);
532
+ }
533
+ for (const d of a) d.text = d.text.replace(/\{totalPages\}/g, String(r.length));
534
+ return { plan: { schemaVersion: de, pages: r }, warnings: o };
535
+ }
536
+ const gt = {
537
537
  root: "mr-root",
538
538
  page: "mr-page",
539
539
  comp: "mr-comp",
@@ -550,10 +550,10 @@ const St = {
550
550
  cell: "mr-cell",
551
551
  unknown: "mr-unknown"
552
552
  };
553
- function j(e, t) {
554
- return t?.classNames?.[e] ?? St[e];
553
+ function T(e, t) {
554
+ return t?.classNames?.[e] ?? gt[e];
555
555
  }
556
- class V {
556
+ class pt {
557
557
  constructor() {
558
558
  this.props = [];
559
559
  }
@@ -561,7 +561,7 @@ class V {
561
561
  return n == null || n === !1 || n === "" ? this : (this.props.push([t, String(n)]), this);
562
562
  }
563
563
  mm(t, n, i, o = 2) {
564
- return this.add(t, `${ne(rt(n, i), o)}px`);
564
+ return this.add(t, `${J(Ve(n, i), o)}px`);
565
565
  }
566
566
  toString() {
567
567
  let t = "";
@@ -574,361 +574,371 @@ class V {
574
574
  n && (t.style.cssText = n);
575
575
  }
576
576
  }
577
- function Ye(e, t, n) {
578
- const i = t.style || {};
579
- e.add("color", i.color).add("background-color", i.backgroundColor).add("font-family", i.fontFamily).add("font-weight", i.bold ? "700" : void 0).add("font-style", i.italic ? "italic" : void 0).add("text-decoration", i.underline ? "underline" : void 0).add("letter-spacing", i.letterSpacing != null ? `${i.letterSpacing}pt` : void 0).add("opacity", i.opacity != null ? String(i.opacity) : void 0).add("transform", i.rotateDeg ? `rotate(${i.rotateDeg}deg)` : void 0);
580
- const o = K(i, n);
581
- e.add("font-size", `${ne(o.fontSizePx, 2)}px`);
577
+ function v(e, t = "unset") {
578
+ return new pt().add("all", t).add("display", e).add("box-sizing", "border-box");
579
+ }
580
+ function Ce(e, t, n) {
581
+ e.add("color", t.color).add("font-family", t.fontFamily).add("font-weight", t.bold != null ? t.bold ? "700" : "400" : void 0).add("font-style", t.italic != null ? t.italic ? "italic" : "normal" : void 0).add("text-decoration", t.underline != null ? t.underline ? "underline" : "none" : void 0).add("letter-spacing", t.letterSpacing != null ? `${t.letterSpacing}pt` : void 0).add("line-height", String(te(t))).add("text-align", t.align);
582
+ const i = D(t, n);
583
+ e.add("font-size", `${J(i.fontSizePx, 2)}px`);
584
+ }
585
+ function yt(e, t, n) {
586
+ const i = t.style ?? {};
587
+ Ce(e, i, n), e.add("background-color", i.backgroundColor).add("opacity", i.opacity != null ? String(i.opacity) : void 0).add("transform", i.rotateDeg ? `rotate(${i.rotateDeg}deg)` : void 0);
588
+ }
589
+ function Mt(e, t, n, i, o, r) {
590
+ const a = e.cell, s = r.createElement("td");
591
+ s.className = T("cell", o), s.setAttribute("role", t.table?.role === "header" ? "columnheader" : "cell"), a.colSpan && (s.colSpan = a.colSpan), a.rowSpan && (s.rowSpan = a.rowSpan);
592
+ const l = R(t.style, a.style), d = v("block").add("position", "absolute").mm("left", e.xMm, i).mm("top", e.yMm, i).mm("width", e.widthMm, i).mm("height", e.heightMm, i).add("background-color", l.backgroundColor).add("vertical-align", l.verticalAlign ?? "middle");
593
+ Ce(d, l, i), d.applyTo(s);
594
+ const c = r.createElement("div");
595
+ c.className = "mr-cell-content", v("flex").add("position", "absolute").mm("left", n, i).mm("right", n, i).mm("top", n, i).mm("bottom", n, i).add("flex-direction", "column").add("justify-content", l.verticalAlign === "top" ? "flex-start" : l.verticalAlign === "bottom" ? "flex-end" : "center").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(c), a.text != null && c.append(a.text);
596
+ for (const f of a.children ?? []) c.appendChild(Re(f, i, o, r));
597
+ return s.appendChild(c), s;
598
+ }
599
+ function bt(e, t, n, i) {
600
+ const o = ne(t.style), r = o.inner ? [...e.edges] : [];
601
+ o.top && r.push({ kind: "h", pos: 0, from: 0, to: t.widthMm }), o.bottom && r.push({ kind: "h", pos: t.heightMm, from: 0, to: t.widthMm }), o.left && r.push({ kind: "v", pos: 0, from: 0, to: t.heightMm }), o.right && r.push({ kind: "v", pos: t.widthMm, from: 0, to: t.heightMm });
602
+ const a = V(t.style), s = `${J(a.widthPt * n / 72, 2)}px solid ${a.color}`;
603
+ return r.map((l) => {
604
+ const d = i.createElement("div");
605
+ d.className = "mr-grid-edge", d.setAttribute("aria-hidden", "true");
606
+ const c = l.kind === "h";
607
+ return v("block").add("position", "absolute").add("pointer-events", "none").mm("left", c ? l.from : l.pos, n).mm("top", c ? l.pos : l.from, n).mm("width", c ? l.to - l.from : 0, n).mm("height", c ? 0 : l.to - l.from, n).add(c ? "border-top" : "border-left", s).applyTo(d), d;
608
+ });
582
609
  }
583
- function vt(e, t, n, i, o) {
584
- const s = o.createElement("table");
585
- if (s.className = j("grid", i), new V().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", e.colWidthsMm ? "fixed" : "auto").applyTo(s), e.colWidthsMm) {
586
- const d = o.createElement("colgroup");
587
- for (const m of e.colWidthsMm) {
588
- const h = o.createElement("col");
589
- new V().mm("width", m, n).applyTo(h), d.appendChild(h);
590
- }
591
- s.appendChild(d);
592
- }
593
- const r = ye(t.style), a = te(t.style), l = r.inner ? `${ne(a.widthPt * n / 72, 2)}px solid ${a.color}` : "";
594
- return e.cells.forEach((d, m) => {
595
- const h = o.createElement("tr");
596
- h.className = j("row", i), e.rowHeightsMm?.[m] != null && new V().mm("height", e.rowHeightsMm[m], n).applyTo(h), (d || []).forEach((f) => {
597
- const g = o.createElement("td");
598
- g.className = j("cell", i), f?.colSpan && (g.colSpan = f.colSpan), f?.rowSpan && (g.rowSpan = f.rowSpan);
599
- const c = new V();
600
- if (l && c.add("border", l), f?.style) {
601
- const b = f.style;
602
- c.add("text-align", b.align).add("vertical-align", b.verticalAlign).add("background-color", b.backgroundColor).add("color", b.color).add("font-weight", b.bold ? "700" : void 0), c.add("font-size", `${ne(K(b, n).fontSizePx, 2)}px`);
603
- }
604
- if (c.applyTo(g), f?.text != null && (g.textContent = f.text), f?.children?.length)
605
- for (const b of f.children)
606
- g.appendChild(Ue(b, n, i, o));
607
- h.appendChild(g);
608
- }), s.appendChild(h);
609
- }), s;
610
+ function wt(e, t, n, i, o) {
611
+ const r = o.createElement("table");
612
+ r.className = T("grid", i), r.setAttribute("role", "table"), v("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(r);
613
+ const a = we(e, t.widthMm, t.heightMm), s = o.createElement("tbody");
614
+ v("contents").applyTo(s), r.appendChild(s);
615
+ const l = e.cells.map(() => {
616
+ const c = o.createElement("tr");
617
+ return c.className = T("row", i), c.setAttribute("role", "row"), v("contents").applyTo(c), s.appendChild(c), c;
618
+ });
619
+ for (const c of a.cells)
620
+ l[c.ri].appendChild(Mt(c, t, e.paddingMm ?? 0.5, n, i, o));
621
+ const d = o.createElement("div");
622
+ return v("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(d), d.append(r, ...bt(a, t, n, o)), d;
610
623
  }
611
- function Tt(e, t, n, i) {
624
+ function $t(e, t, n, i) {
612
625
  const o = i.createElement("div");
613
- o.className = j("text", n);
614
- const s = e.style || {}, r = new V().add("text-align", s.align).add("display", "flex").add("flex-direction", "column").add(
615
- "justify-content",
616
- s.verticalAlign === "middle" ? "center" : s.verticalAlign === "bottom" ? "flex-end" : "flex-start"
617
- ).add("overflow", "hidden");
618
- if (Ye(r, e, t), r.applyTo(o), De(e)) {
619
- const a = i.createElement("div");
620
- a.className = j("rich", n);
621
- for (const l of e.richParagraphs) {
622
- const d = i.createElement("div");
623
- d.className = j("paragraph", n), new V().add("text-align", l.align).add("line-height", l.lineHeight != null ? String(l.lineHeight) : void 0).mm("margin-top", l.spaceBeforeMm ?? 0, t).mm("margin-bottom", l.spaceAfterMm ?? 0, t).mm("text-indent", l.indentMm ?? 0, t).applyTo(d);
624
- for (const h of l.segments || []) {
625
- const f = i.createElement("span");
626
- if (f.className = j("segment", n), f.textContent = h.kind === "field" ? h.field ?? "" : h.text ?? "", h.style) {
627
- const g = new V().add("color", h.style.color).add("font-weight", h.style.bold ? "700" : void 0);
628
- g.add("font-size", `${ne(K(h.style, t).fontSizePx, 2)}px`), g.applyTo(f);
629
- }
630
- d.appendChild(f);
631
- }
632
- a.appendChild(d);
626
+ o.className = T("paragraph", n), v("block").add("text-align", e.align).add("line-height", e.lineHeight != null ? String(e.lineHeight) : void 0).mm("margin-top", e.spaceBeforeMm ?? 0, t).mm("margin-bottom", e.spaceAfterMm ?? 0, t).mm("text-indent", e.indentMm ?? 0, t).applyTo(o);
627
+ for (const r of e.segments || []) {
628
+ const a = i.createElement("span");
629
+ a.className = T("segment", n), a.textContent = r.kind === "field" ? r.field ?? "" : r.text ?? "";
630
+ const s = v("inline");
631
+ if (r.style) {
632
+ const l = r.style;
633
+ s.add("color", l.color).add("font-family", l.fontFamily).add("font-weight", l.bold != null ? l.bold ? "700" : "400" : void 0).add("font-style", l.italic != null ? l.italic ? "italic" : "normal" : void 0).add("text-decoration", l.underline != null ? l.underline ? "underline" : "none" : void 0), (l.fontSize != null || l.fontSizePx != null) && s.add("font-size", `${J(D(l, t).fontSizePx, 2)}px`);
633
634
  }
634
- return o.appendChild(a), o;
635
+ s.applyTo(a), o.appendChild(a);
636
+ }
637
+ return o;
638
+ }
639
+ function St(e, t, n, i) {
640
+ if (Se(e)) {
641
+ const o = i.createElement("div");
642
+ o.className = T("rich", n), v("block").applyTo(o);
643
+ for (const r of e.richParagraphs) o.appendChild($t(r, t, n, i));
644
+ return o;
635
645
  }
636
646
  if (Array.isArray(e.lines) && e.lines.length > 0) {
637
- const a = i.createElement("div");
638
- a.className = j("lines", n), s.lineHeight != null && new V().add("line-height", String(s.lineHeight)).applyTo(a);
639
- for (const l of e.lines) {
640
- const d = i.createElement("div");
641
- d.className = j("line", n), d.textContent = l, a.appendChild(d);
647
+ const o = i.createElement("div");
648
+ o.className = T("lines", n), v("block").applyTo(o);
649
+ for (const r of e.lines) {
650
+ const a = i.createElement("div");
651
+ a.className = T("line", n), a.textContent = r, v("block").add("white-space", "pre").add("min-height", "1lh").applyTo(a), o.appendChild(a);
642
652
  }
643
- return o.appendChild(a), o;
653
+ return o;
644
654
  }
645
- return o.textContent = e.text ?? "", o;
655
+ return e.text ?? "";
656
+ }
657
+ function vt(e, t, n, i) {
658
+ const o = i.createElement("div");
659
+ o.className = T("text", n);
660
+ const r = e.style || {};
661
+ return v("flex").add("width", "100%").add("height", "100%").add("flex-direction", "column").add("justify-content", r.verticalAlign === "middle" ? "center" : r.verticalAlign === "bottom" ? "flex-end" : "flex-start").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(o), o.append(St(e, t, n, i)), o;
646
662
  }
647
663
  function kt(e, t, n) {
648
664
  const i = n.createElement("img");
649
- return i.className = j("image", t), i.src = e.imageData, new V().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(i), i.alt = e.kind, i;
665
+ return i.className = T("image", t), i.src = e.imageData, v("block").add("width", "100%").add("height", "100%").add("object-fit", "contain").applyTo(i), i.alt = e.kind, i;
650
666
  }
651
- function Fe(e, t, n, i) {
667
+ function ye(e, t, n, i) {
652
668
  const o = i.createElement("div");
653
- o.className = j("shape", n);
654
- const s = e.style || {}, r = te(s), a = ye(s), l = `${ne(r.widthPt * t / 72, 2)}px solid ${r.color}`, d = new V();
655
- return e.grid || e.kind === "rect" ? (a.top && d.add("border-top", l), a.right && d.add("border-right", l), a.bottom && d.add("border-bottom", l), a.left && d.add("border-left", l)) : e.kind === "ellipse" ? (a.inner && d.add("border", l).add("border-radius", "50%"), s.backgroundColor && d.add("background-color", s.backgroundColor)) : e.kind === "line" && d.add("height", "0").add("border-top", l), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(o), o;
669
+ o.className = T("shape", n);
670
+ const r = e.style || {}, a = V(r), s = ne(r), l = `${J(a.widthPt * t / 72, 2)}px solid ${a.color}`, d = v("block");
671
+ return e.grid ? d.add("position", "relative") : e.kind === "rect" ? (s.top && d.add("border-top", l), s.right && d.add("border-right", l), s.bottom && d.add("border-bottom", l), s.left && d.add("border-left", l)) : e.kind === "ellipse" ? (s.inner && d.add("border", l).add("border-radius", "50%"), r.backgroundColor && d.add("background-color", r.backgroundColor)) : e.kind === "line" && d.add("height", "0").add("border-top", l), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(o), o;
656
672
  }
657
- function Ue(e, t, n, i) {
673
+ function Re(e, t, n, i) {
658
674
  const o = i.createElement("div");
659
- o.className = `${j("comp", n)} mr-kind-${e.kind}`;
660
- const s = new V().add("position", "absolute").mm("left", e.leftMm, t).mm("top", e.topMm, t).mm("width", e.widthMm, t).mm("height", e.heightMm, t).add("box-sizing", "border-box");
661
- if (Ye(s, e, t), s.applyTo(o), lt(e))
675
+ o.className = `${T("comp", n)} mr-kind-${e.kind}`;
676
+ const r = v("block").add("position", "absolute").mm("left", e.leftMm, t).mm("top", e.topMm, t).mm("width", e.widthMm, t).mm("height", e.heightMm, t).add("box-sizing", "border-box");
677
+ if (yt(r, e, t), r.applyTo(o), Ge(e))
662
678
  return o.appendChild(kt(e, n, i)), o;
663
679
  if (e.kind === "text")
664
- return o.appendChild(Tt(e, t, n, i)), o;
680
+ return o.appendChild(vt(e, t, n, i)), o;
665
681
  if (e.grid) {
666
- const a = Fe(e, t, n, i);
667
- return a.appendChild(vt(e.grid, e, t, n, i)), o.appendChild(a), o;
682
+ const s = ye(e, t, n, i);
683
+ return s.appendChild(wt(e.grid, e, t, n, i)), o.appendChild(s), o;
668
684
  }
669
685
  if (e.kind === "line" || e.kind === "rect" || e.kind === "ellipse" || e.kind === "chart")
670
- return o.appendChild(Fe(e, t, n, i)), o;
671
- const r = i.createElement("div");
672
- return r.className = j("unknown", n), r.textContent = e.fallbackText ?? "", o.appendChild(r), o;
686
+ return o.appendChild(ye(e, t, n, i)), o;
687
+ const a = i.createElement("div");
688
+ return a.className = T("unknown", n), v("block").applyTo(a), a.textContent = e.fallbackText ?? "", o.appendChild(a), o;
673
689
  }
674
- function At(e, t, n, i) {
690
+ function Tt(e, t, n, i) {
675
691
  const o = i.createElement("div");
676
- o.className = j("page", n), new V().add("position", "relative").mm("width", e.pageWidthMm, t).mm("height", e.pageHeightMm, t).add("background-color", "#fff").add("color", Ie).add("overflow", "hidden").add("box-sizing", "border-box").applyTo(o);
677
- for (const s of e.components)
678
- o.appendChild(Ue(s, t, n, i));
692
+ o.className = T("page", n), v("block", "initial").add("position", "relative").add("font-family", '"Microsoft YaHei", sans-serif').add("font-size", `${J(D(void 0, t).fontSizePx, 2)}px`).add("line-height", String(te(void 0))).add("white-space", "pre-wrap").add("direction", "ltr").mm("width", e.pageWidthMm, t).mm("height", e.pageHeightMm, t).add("background-color", "#fff").add("color", be).add("overflow", "hidden").add("box-sizing", "border-box").applyTo(o);
693
+ for (const r of e.components)
694
+ o.appendChild(Re(r, t, n, i));
679
695
  return o;
680
696
  }
681
- function Gt(e, t, n = {}) {
697
+ function hn(e, t, n = {}) {
682
698
  const i = n.dpi ?? 96, o = t.createElement("div");
683
- return o.className = j("root", n), o.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((s) => {
684
- o.appendChild(At(s, i, n, t));
699
+ return o.className = T("root", n), v("block").applyTo(o), o.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((r) => {
700
+ o.appendChild(Tt(r, i, n, t));
685
701
  }), o;
686
702
  }
687
- function Et(e) {
688
- return dt(e.pageHeightsPx, e.gapPx).window(e.viewportHeightPx, e.scrollTopPx, e.overscan);
703
+ function At(e) {
704
+ return Je(e.pageHeightsPx, e.gapPx).window(e.viewportHeightPx, e.scrollTopPx, e.overscan);
689
705
  }
690
- const Pe = 96 / 25.4;
691
- function qe(e, t = 96) {
692
- const n = t / 96 * Pe;
706
+ const fe = 96 / 25.4;
707
+ function Oe(e, t = 96) {
708
+ const n = t / 96 * fe;
693
709
  return {
694
710
  widthPx: Math.max(1, Math.round(e.pageWidthMm * n)),
695
711
  heightPx: Math.max(1, Math.round(e.pageHeightMm * n))
696
712
  };
697
713
  }
698
- function Pt(e, t, n) {
699
- const i = document.createElement("canvas"), { widthPx: o, heightPx: s } = qe(e, n);
700
- i.width = Math.round(o * t), i.height = Math.round(s * t), i.style.width = `${o}px`, i.style.height = `${s}px`;
701
- const r = i.getContext("2d");
702
- if (!r)
714
+ function xt(e, t, n) {
715
+ const i = document.createElement("canvas"), { widthPx: o, heightPx: r } = Oe(e, n);
716
+ i.width = Math.round(o * t), i.height = Math.round(r * t), i.style.width = `${o}px`, i.style.height = `${r}px`;
717
+ const a = i.getContext("2d");
718
+ if (!a)
703
719
  throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");
704
- return r.scale(t, t), r.fillStyle = "#ffffff", r.fillRect(0, 0, o, s), { canvas: i, ctx: r };
720
+ return a.scale(t, t), a.fillStyle = "#ffffff", a.fillRect(0, 0, o, r), { canvas: i, ctx: a };
705
721
  }
706
- function Yt(e, t = 96) {
707
- return K(e, t).fontSizePx;
722
+ function un(e, t = 96) {
723
+ return D(e, t).fontSizePx;
708
724
  }
709
- function Ke(e, t, n, i, o, s, r, a = "top") {
710
- e.font = `${t.bold ? "bold " : ""}${t.fontSizePx}px ${r}`, e.fillStyle = t.color, e.textBaseline = "alphabetic";
725
+ function He(e, t, n, i, o, r, a, s = "top") {
726
+ e.font = `${t.italic ? "italic " : ""}${t.bold ? "bold " : ""}${t.fontSizePx}px ${a}`, e.fillStyle = t.color, e.textBaseline = "alphabetic";
711
727
  const l = t.fontSizePx * t.lineHeight, d = t.text === "" ? [""] : t.text.split(`
712
- `), m = d.length * l;
713
- let h = i;
714
- a === "middle" ? h = i + (s - m) / 2 : a === "bottom" && (h = i + s - m), d.forEach((f, g) => {
728
+ `), c = d.length * l;
729
+ let f = i;
730
+ s === "middle" ? f = i + (r - c) / 2 : s === "bottom" && (f = i + r - c), d.forEach((g, u) => {
715
731
  e.textAlign = t.align === "center" ? "center" : t.align === "right" ? "right" : "left";
716
- const c = t.align === "center" ? n + o / 2 : t.align === "right" ? n + o : n;
717
- e.fillText(f, c, h + g * l + t.fontSizePx * 0.8, o);
732
+ const m = t.align === "center" ? n + o / 2 : t.align === "right" ? n + o : n;
733
+ e.fillText(g, m, f + u * l + t.fontSizePx * 0.8, o);
718
734
  }), e.textAlign = "left";
719
735
  }
720
- function xt(e, t, n, i, o, s, r, a, l, d, m) {
721
- const h = at(t, s / a, r / a), f = ye(n.style), g = te(n.style);
722
- for (const c of h.cells) {
723
- const b = c.cell.style?.backgroundColor;
724
- b && (e.fillStyle = b, e.fillRect(
725
- i + c.xMm * a,
726
- o + c.yMm * a,
727
- c.widthMm * a,
728
- c.heightMm * a
729
- ));
730
- }
731
- if (f.inner) {
732
- e.strokeStyle = g.color, e.lineWidth = he(g.widthPt, l);
733
- for (const c of h.edges)
734
- e.beginPath(), c.kind === "v" ? (e.moveTo(i + c.pos * a, o + c.from * a), e.lineTo(i + c.pos * a, o + c.to * a)) : (e.moveTo(i + c.from * a, o + c.pos * a), e.lineTo(i + c.to * a, o + c.pos * a)), e.stroke();
735
- e.beginPath(), f.top && (e.moveTo(i, o), e.lineTo(i + s, o)), f.right && (e.moveTo(i + s, o), e.lineTo(i + s, o + r)), f.bottom && (e.moveTo(i + s, o + r), e.lineTo(i, o + r)), f.left && (e.moveTo(i, o + r), e.lineTo(i, o)), e.stroke();
736
- }
737
- for (const c of h.cells) {
738
- const b = typeof c.cell.text == "string" ? c.cell.text : "";
739
- if (!b) continue;
740
- const y = c.cell.style, T = y?.fontSize ?? ve, $ = le(
741
- b,
742
- c.widthMm - 1,
743
- { fontSizePt: T },
744
- m
745
- ).join(`
736
+ function Et(e, t, n, i, o, r, a, s, l) {
737
+ const d = ne(n.style);
738
+ if (!d.inner) return;
739
+ const c = V(n.style);
740
+ e.strokeStyle = c.color, e.lineWidth = X(c.widthPt, l);
741
+ for (const f of t.edges)
742
+ e.beginPath(), f.kind === "v" ? (e.moveTo(i + f.pos * s, o + f.from * s), e.lineTo(i + f.pos * s, o + f.to * s)) : (e.moveTo(i + f.from * s, o + f.pos * s), e.lineTo(i + f.to * s, o + f.pos * s)), e.stroke();
743
+ Fe(e, d, i, o, r, a);
744
+ }
745
+ function Fe(e, t, n, i, o, r) {
746
+ e.beginPath(), t.top && (e.moveTo(n, i), e.lineTo(n + o, i)), t.right && (e.moveTo(n + o, i), e.lineTo(n + o, i + r)), t.bottom && (e.moveTo(n + o, i + r), e.lineTo(n, i + r)), t.left && (e.moveTo(n, i + r), e.lineTo(n, i)), e.stroke();
747
+ }
748
+ function Pt(e, t, n, i, o, r, a, s, l, d, c) {
749
+ const f = we(t, r / s, a / s);
750
+ for (const u of f.cells) {
751
+ const m = u.cell.style?.backgroundColor ?? n.style?.backgroundColor;
752
+ m && (e.fillStyle = m, e.fillRect(i + u.xMm * s, o + u.yMm * s, u.widthMm * s, u.heightMm * s));
753
+ }
754
+ Et(e, f, n, i, o, r, a, s, l);
755
+ const g = t.paddingMm ?? 0.5;
756
+ for (const u of f.cells) {
757
+ const m = u.cell.text ?? "";
758
+ if (!m) continue;
759
+ const h = R(n.style, u.cell.style), p = D(h, l), M = Math.max(0, u.widthMm - 2 * g), b = Y(m, M, { fontSizePt: p.fontSizePt, bold: h.bold }, c).join(`
746
760
  `);
747
- Ke(
761
+ He(
748
762
  e,
749
763
  {
750
- text: $,
751
- fontSizePx: K(y, l).fontSizePx,
752
- bold: y?.bold ?? !1,
753
- color: y?.color ?? je(n.style, Ie),
754
- align: y?.align ?? "left",
755
- lineHeight: Te
764
+ text: b,
765
+ fontSizePx: p.fontSizePx,
766
+ bold: h.bold ?? !1,
767
+ italic: h.italic,
768
+ color: $e(h, be),
769
+ align: h.align ?? "left",
770
+ lineHeight: te(h)
756
771
  },
757
- i + (c.xMm + 0.5) * a,
758
- o + c.yMm * a,
759
- Math.max(0, (c.widthMm - 1) * a),
760
- c.heightMm * a,
761
- d,
762
- y?.verticalAlign ?? "middle"
772
+ i + (u.xMm + g) * s,
773
+ o + (u.yMm + g) * s,
774
+ M * s,
775
+ Math.max(0, u.heightMm - 2 * g) * s,
776
+ h.fontFamily ?? d,
777
+ h.verticalAlign ?? "middle"
763
778
  );
764
779
  }
765
780
  }
766
- function Xe(e, t, n, i, o, s) {
767
- const r = t.leftMm * n, a = t.topMm * n, l = t.widthMm * n, d = t.heightMm * n, m = t.style ?? {};
781
+ function Nt(e, t, n, i, o, r, a, s, l) {
782
+ const d = t.style ?? {}, c = D(d, a), f = Se(t) ? t.richParagraphs.map((g) => g.segments.map((u) => u.text ?? u.field ?? "").join("")).join(`
783
+ `) : t.lines?.length ? t.lines.join(`
784
+ `) : Y(t.text ?? "", t.widthMm, { fontSizePt: c.fontSizePt, bold: d.bold }, l).join(`
785
+ `);
786
+ He(e, {
787
+ text: f,
788
+ fontSizePx: c.fontSizePx,
789
+ bold: d.bold ?? !1,
790
+ italic: d.italic,
791
+ color: $e(d),
792
+ align: d.align ?? "left",
793
+ lineHeight: te(d)
794
+ }, n, i, o, r, d.fontFamily ?? s, d.verticalAlign);
795
+ }
796
+ function Le(e, t, n, i, o, r) {
797
+ const a = t.leftMm * n, s = t.topMm * n, l = t.widthMm * n, d = t.heightMm * n, c = t.style ?? {};
768
798
  if (t.grid) {
769
- xt(e, t.grid, t, r, a, l, d, n, i, o, s);
799
+ Pt(e, t.grid, t, a, s, l, d, n, i, o, r);
770
800
  return;
771
801
  }
772
802
  switch (t.kind) {
773
803
  case "text": {
774
- const h = m.fontSize ?? ve, f = De(t) ? t.richParagraphs.map((g) => (g.segments ?? []).map((c) => c.text ?? c.field ?? "").join("")).join(`
775
- `) : Array.isArray(t.lines) && t.lines.length > 0 ? t.lines.join(`
776
- `) : le(t.text ?? "", t.widthMm, { fontSizePt: h }, s).join(`
777
- `);
778
- Ke(
779
- e,
780
- {
781
- text: f,
782
- fontSizePx: K(m, i).fontSizePx,
783
- bold: m.bold ?? !1,
784
- color: je(m),
785
- align: m.align ?? "left",
786
- lineHeight: st(m)
787
- },
788
- r,
789
- a,
790
- l,
791
- d,
792
- o,
793
- m.verticalAlign
794
- );
804
+ Nt(e, t, a, s, l, d, i, o, r);
795
805
  break;
796
806
  }
797
807
  case "rect": {
798
- const h = te(m), f = ye(m);
799
- m.backgroundColor && (e.fillStyle = m.backgroundColor, e.fillRect(r, a, l, d)), f.inner && (e.strokeStyle = h.color, e.lineWidth = he(h.widthPt, i), e.beginPath(), f.top && (e.moveTo(r, a), e.lineTo(r + l, a)), f.right && (e.moveTo(r + l, a), e.lineTo(r + l, a + d)), f.bottom && (e.moveTo(r + l, a + d), e.lineTo(r, a + d)), f.left && (e.moveTo(r, a + d), e.lineTo(r, a)), e.stroke());
808
+ const f = V(c), g = ne(c);
809
+ c.backgroundColor && (e.fillStyle = c.backgroundColor, e.fillRect(a, s, l, d)), g.inner && (e.strokeStyle = f.color, e.lineWidth = X(f.widthPt, i), Fe(e, g, a, s, l, d));
800
810
  break;
801
811
  }
802
812
  case "line": {
803
- const h = te({ ...m, borderColor: m.lineColor ?? m.borderColor });
804
- e.strokeStyle = h.color, e.lineWidth = he(h.widthPt, i), e.beginPath(), e.moveTo(r, a + d / 2), e.lineTo(r + l, a + d / 2), e.stroke();
813
+ const f = V({ ...c, borderColor: c.lineColor ?? c.borderColor });
814
+ e.strokeStyle = f.color, e.lineWidth = X(f.widthPt, i), e.beginPath(), e.moveTo(a, s + d / 2), e.lineTo(a + l, s + d / 2), e.stroke();
805
815
  break;
806
816
  }
807
817
  case "ellipse": {
808
- const h = te(m);
809
- e.strokeStyle = h.color, e.lineWidth = he(h.widthPt, i), m.backgroundColor && (e.fillStyle = m.backgroundColor, e.beginPath(), e.ellipse(r + l / 2, a + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(r + l / 2, a + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.stroke();
818
+ const f = V(c);
819
+ e.strokeStyle = f.color, e.lineWidth = X(f.widthPt, i), c.backgroundColor && (e.fillStyle = c.backgroundColor, e.beginPath(), e.ellipse(a + l / 2, s + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(a + l / 2, s + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.stroke();
810
820
  break;
811
821
  }
812
822
  }
813
823
  }
814
- async function Ut(e, t = {}) {
824
+ async function gn(e, t = {}) {
815
825
  if (typeof document > "u")
816
826
  throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");
817
- const { format: n = "png", quality: i = 0.92, ...o } = t, { canvases: s } = Nt(e, o), r = n === "jpeg" ? "image/jpeg" : "image/png", a = [];
818
- for (const l of s)
819
- a.push(
827
+ const { format: n = "png", quality: i = 0.92, ...o } = t, { canvases: r } = Ct(e, o), a = n === "jpeg" ? "image/jpeg" : "image/png", s = [];
828
+ for (const l of r)
829
+ s.push(
820
830
  await new Promise(
821
- (d) => l.toBlob((m) => d(m), r, i)
822
- ) ?? new Blob([], { type: r })
831
+ (d) => l.toBlob((c) => d(c), a, i)
832
+ ) ?? new Blob([], { type: a })
823
833
  );
824
- return { blobs: a };
834
+ return { blobs: s };
825
835
  }
826
- function Nt(e, t = {}) {
836
+ function Ct(e, t = {}) {
827
837
  if (typeof document > "u")
828
838
  throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");
829
- const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), i = t.dpi ?? 96, o = i / 96 * Pe, s = t.fontFamily ?? '"Microsoft YaHei", sans-serif', r = t.measurer ?? ke, a = Math.max(0, t.start ?? 0), l = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1), d = [];
830
- for (let m = a; m <= l; m++) {
831
- const h = e.pages[m], { canvas: f, ctx: g } = Pt(h, n, i);
832
- for (const c of h.components)
833
- Xe(g, c, o, i, s, r);
834
- d.push(f);
839
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), i = t.dpi ?? 96, o = i / 96 * fe, r = t.fontFamily ?? '"Microsoft YaHei", sans-serif', a = t.measurer ?? ce, s = Math.max(0, t.start ?? 0), l = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1), d = [];
840
+ for (let c = s; c <= l; c++) {
841
+ const f = e.pages[c], { canvas: g, ctx: u } = xt(f, n, i);
842
+ for (const m of f.components)
843
+ Le(u, m, o, i, r, a);
844
+ d.push(g);
835
845
  }
836
846
  return { canvases: d };
837
847
  }
838
- function qt(e, t = {}) {
839
- const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), i = t.dpi ?? 96, o = i / 96 * Pe, s = t.fontFamily ?? '"Microsoft YaHei", sans-serif', r = t.measurer ?? ke, a = t.overscan ?? 1, l = t.gapPx ?? 18, d = t.pagesPerFrame ?? 1, m = e.pages.map((p) => p.pageHeightMm * o), h = Math.max(1, ...e.pages.map((p) => p.pageWidthMm * o)), f = { start: 0, end: -1 };
840
- let g = null, c = null, b = null, y = null, T = [], $ = 0, E = [];
841
- function S() {
842
- const p = g;
843
- p.innerHTML = "", c = document.createElement("div"), c.style.cssText = `width:${h}px;margin:0 auto;`, b = document.createElement("div"), y = document.createElement("div"), c.appendChild(b), T = [];
844
- const B = Math.min(e.pages.length, 3 + a * 2);
845
- for (let A = 0; A < B; A++) {
846
- const P = document.createElement("div");
847
- P.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, c.appendChild(P), T.push(P);
848
+ function pn(e, t = {}) {
849
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), i = t.dpi ?? 96, o = i / 96 * fe, r = t.fontFamily ?? '"Microsoft YaHei", sans-serif', a = t.measurer ?? ce, s = t.overscan ?? 1, l = t.gapPx ?? 18, d = t.pagesPerFrame ?? 1, c = e.pages.map((y) => y.pageHeightMm * o), f = Math.max(1, ...e.pages.map((y) => y.pageWidthMm * o)), g = { start: 0, end: -1 };
850
+ let u = null, m = null, h = null, p = null, M = [], b = 0, A = [];
851
+ function w() {
852
+ const y = u;
853
+ y.innerHTML = "", m = document.createElement("div"), m.style.cssText = `width:${f}px;margin:0 auto;`, h = document.createElement("div"), p = document.createElement("div"), m.appendChild(h), M = [];
854
+ const P = Math.min(e.pages.length, 3 + s * 2);
855
+ for (let H = 0; H < P; H++) {
856
+ const $ = document.createElement("div");
857
+ $.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, m.appendChild($), M.push($);
848
858
  }
849
- c.appendChild(y), p.appendChild(c);
850
- }
851
- function R(p, B) {
852
- const A = e.pages[B], { widthPx: P, heightPx: N } = qe(A, i);
853
- let L = p.firstElementChild;
854
- (!L || L.tagName !== "CANVAS") && (L = document.createElement("canvas"), p.innerHTML = "", p.appendChild(L)), L.width = Math.round(P * n), L.height = Math.round(N * n), L.style.width = `${P}px`, L.style.height = `${N}px`;
855
- const J = L.getContext("2d");
856
- if (J) {
857
- J.setTransform(1, 0, 0, 1, 0, 0), J.scale(n, n), J.fillStyle = "#ffffff", J.fillRect(0, 0, P, N);
858
- for (const Q of A.components)
859
- Xe(J, Q, o, i, s, r);
860
- L.dataset.canvasPage = String(B), p.style.height = `${N}px`, p.style.width = `${P}px`;
859
+ m.appendChild(p), y.appendChild(m);
860
+ }
861
+ function I(y, P) {
862
+ const H = e.pages[P], { widthPx: $, heightPx: x } = Oe(H, i);
863
+ let N = y.firstElementChild;
864
+ (!N || N.tagName !== "CANVAS") && (N = document.createElement("canvas"), y.innerHTML = "", y.appendChild(N)), N.width = Math.round($ * n), N.height = Math.round(x * n), N.style.width = `${$}px`, N.style.height = `${x}px`;
865
+ const W = N.getContext("2d");
866
+ if (W) {
867
+ W.setTransform(1, 0, 0, 1, 0, 0), W.scale(n, n), W.fillStyle = "#ffffff", W.fillRect(0, 0, $, x);
868
+ for (const _e of H.components)
869
+ Le(W, _e, o, i, r, a);
870
+ N.dataset.canvasPage = String(P), y.style.height = `${x}px`, y.style.width = `${$}px`;
861
871
  }
862
872
  }
863
- function F(p) {
864
- f.start = p.start, f.end = p.end, b.style.height = `${p.start * l + m.slice(0, p.start).reduce((P, N) => P + N, 0)}px`;
865
- const B = e.pages.length - 1 - p.end;
866
- y.style.height = `${B * l + m.slice(p.end + 1).reduce((P, N) => P + N, 0)}px`;
867
- const A = p.end - p.start + 1;
868
- T.forEach((P, N) => {
869
- if (N < A) {
870
- P.style.display = "";
871
- const L = p.start + N;
872
- P.style.height = `${m[L] ?? 0}px`;
873
+ function _(y) {
874
+ g.start = y.start, g.end = y.end, h.style.height = `${y.start * l + c.slice(0, y.start).reduce(($, x) => $ + x, 0)}px`;
875
+ const P = e.pages.length - 1 - y.end;
876
+ p.style.height = `${P * l + c.slice(y.end + 1).reduce(($, x) => $ + x, 0)}px`;
877
+ const H = y.end - y.start + 1;
878
+ M.forEach(($, x) => {
879
+ if (x < H) {
880
+ $.style.display = "";
881
+ const N = y.start + x;
882
+ $.style.height = `${c[N] ?? 0}px`;
873
883
  } else
874
- P.style.display = "none";
875
- }), E = [];
876
- for (let P = p.start; P <= p.end; P++) {
877
- const N = T[P - p.start];
878
- if (!N) continue;
879
- N.firstElementChild?.dataset?.canvasPage !== String(P) && E.push(P);
884
+ $.style.display = "none";
885
+ }), A = [];
886
+ for (let $ = y.start; $ <= y.end; $++) {
887
+ const x = M[$ - y.start];
888
+ if (!x) continue;
889
+ x.firstElementChild?.dataset?.canvasPage !== String($) && A.push($);
880
890
  }
881
- k();
882
- }
883
- function k() {
884
- $ || E.length === 0 || ($ = requestAnimationFrame(() => {
885
- $ = 0;
886
- let p = Math.max(1, d);
887
- for (; E.length > 0 && p-- > 0; ) {
888
- const B = E.shift(), A = T[B - f.start];
889
- A && R(A, B);
891
+ B();
892
+ }
893
+ function B() {
894
+ b || A.length === 0 || (b = requestAnimationFrame(() => {
895
+ b = 0;
896
+ let y = Math.max(1, d);
897
+ for (; A.length > 0 && y-- > 0; ) {
898
+ const P = A.shift(), H = M[P - g.start];
899
+ H && I(H, P);
890
900
  }
891
- E.length > 0 && k();
901
+ A.length > 0 && B();
892
902
  }));
893
903
  }
894
- function v() {
895
- $ || ($ = requestAnimationFrame(() => {
896
- $ = 0;
897
- const p = g, B = Et({
898
- pageHeightsPx: m,
899
- viewportHeightPx: p.clientHeight,
900
- scrollTopPx: p.scrollTop,
901
- overscan: a,
904
+ function q() {
905
+ b || (b = requestAnimationFrame(() => {
906
+ b = 0;
907
+ const y = u, P = At({
908
+ pageHeightsPx: c,
909
+ viewportHeightPx: y.clientHeight,
910
+ scrollTopPx: y.scrollTop,
911
+ overscan: s,
902
912
  gapPx: l
903
913
  });
904
- B.start !== f.start || B.end !== f.end ? F(B) : k();
914
+ P.start !== g.start || P.end !== g.end ? _(P) : B();
905
915
  }));
906
916
  }
907
- let u = null;
917
+ let K = null;
908
918
  return {
909
- attach(p) {
919
+ attach(y) {
910
920
  if (typeof document > "u")
911
921
  throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");
912
- g = p, S(), p.addEventListener("scroll", v, { passive: !0 }), typeof ResizeObserver < "u" && (u = new ResizeObserver(() => v()), u.observe(p)), v();
922
+ u = y, w(), y.addEventListener("scroll", q, { passive: !0 }), typeof ResizeObserver < "u" && (K = new ResizeObserver(() => q()), K.observe(y)), q();
913
923
  },
914
924
  destroy() {
915
- $ && cancelAnimationFrame($), $ = 0, u?.disconnect(), u = null, g?.removeEventListener("scroll", v), E = [], c?.remove(), g = null;
925
+ b && cancelAnimationFrame(b), b = 0, K?.disconnect(), K = null, u?.removeEventListener("scroll", q), A = [], m?.remove(), u = null;
916
926
  },
917
927
  window() {
918
- return { ...f };
928
+ return { ...g };
919
929
  }
920
930
  };
921
931
  }
922
- function Qe(e, t, n) {
932
+ function Ie(e, t, n) {
923
933
  let i, o;
924
934
  if (typeof e == "string") {
925
- const s = ge[e];
926
- if (!s) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(ge).join("/")})`);
927
- i = s.widthMm, o = s.heightMm;
935
+ const r = Q[e];
936
+ if (!r) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(Q).join("/")})`);
937
+ i = r.widthMm, o = r.heightMm;
928
938
  } else typeof e == "number" ? (i = e, o = t ?? 297) : (i = e.widthMm, o = e.heightMm);
929
939
  return n ? { widthMm: o, heightMm: i } : { widthMm: i, heightMm: o };
930
940
  }
931
- class Ct {
941
+ class Rt {
932
942
  constructor() {
933
943
  this.pages = [], this.pending = null, this.templateParams = void 0;
934
944
  }
@@ -957,14 +967,14 @@ class Ct {
957
967
  */
958
968
  page(t = "a4", n = {}, i) {
959
969
  this.collect();
960
- const s = i != null && !("margins" in i) && !("landscape" in i) && ("marginTopMm" in i || "marginBottomMm" in i || "marginLeftMm" in i || "marginRightMm" in i) ? { margins: i } : typeof n == "number" ? i ?? {} : n, { widthMm: r, heightMm: a } = Qe(
970
+ const r = i != null && !("margins" in i) && !("landscape" in i) && ("marginTopMm" in i || "marginBottomMm" in i || "marginLeftMm" in i || "marginRightMm" in i) ? { margins: i } : typeof n == "number" ? i ?? {} : n, { widthMm: a, heightMm: s } = Ie(
961
971
  t,
962
972
  typeof n == "number" ? n : void 0,
963
- s.landscape
964
- ), l = s.margins ?? {};
965
- return this.pending = new Rt(this, {
966
- widthMm: r,
967
- heightMm: a,
973
+ r.landscape
974
+ ), l = r.margins ?? {};
975
+ return this.pending = new Ot(this, {
976
+ widthMm: a,
977
+ heightMm: s,
968
978
  marginTopMm: l.marginTopMm ?? 10,
969
979
  marginBottomMm: l.marginBottomMm ?? 10,
970
980
  marginLeftMm: l.marginLeftMm ?? 10,
@@ -980,7 +990,7 @@ class Ct {
980
990
  return this.templateParams ? { params: this.templateParams, pages: this.pages } : { pages: this.pages };
981
991
  }
982
992
  }
983
- class Rt {
993
+ class Ot {
984
994
  constructor(t, n) {
985
995
  this.parent = t, this.page = n, this.components = [];
986
996
  }
@@ -1049,22 +1059,18 @@ class Rt {
1049
1059
  return this.done().build();
1050
1060
  }
1051
1061
  }
1052
- function Kt() {
1053
- return new Ct();
1062
+ function yn() {
1063
+ return new Rt();
1054
1064
  }
1055
- function W(e, t, n = !1) {
1065
+ function O(e, t, n = !1) {
1056
1066
  if (!Number.isFinite(e) || (n ? e < 0 : e <= 0))
1057
1067
  throw new Error(`${t} 必须是有限${n ? "非负" : "正"}数`);
1058
1068
  }
1059
- function fe(e, t, n) {
1069
+ function Z(e, t, n) {
1060
1070
  if (e !== void 0 && !["left", "center", "right", "justify", ...n ? ["auto"] : []].includes(e))
1061
1071
  throw new Error(`${t} 必须是 left/center/right/justify${n ? "/auto" : ""}`);
1062
1072
  }
1063
- function Xt(e) {
1064
- if (!e || typeof e != "object")
1065
- throw new Error("标准明细模板需要 options 对象");
1066
- if (!Array.isArray(e.columns) || e.columns.length === 0)
1067
- throw new Error("columns 至少需要一列");
1073
+ function Ht(e) {
1068
1074
  const t = e.layout ?? "page";
1069
1075
  if (t !== "page" && t !== "wide")
1070
1076
  throw new Error("layout 必须是 page 或 wide");
@@ -1073,530 +1079,596 @@ function Xt(e) {
1073
1079
  if (t !== "wide" && e.columnWidthMm !== void 0)
1074
1080
  throw new Error('columnWidthMm 仅适用于 layout: "wide"');
1075
1081
  const n = e.columnWidthMm ?? 30;
1076
- W(n, "columnWidthMm");
1077
- const i = e.paper === void 0 ? "a4" : e.paper;
1078
- if (typeof i != "string" && (typeof i != "object" || i === null) || e.landscape !== void 0 && typeof e.landscape != "boolean")
1082
+ return O(n, "columnWidthMm"), { layout: t, columnWidthMm: n };
1083
+ }
1084
+ function Ft(e) {
1085
+ const t = e.paper === void 0 ? "a4" : e.paper;
1086
+ if (typeof t != "string" && (typeof t != "object" || t === null) || e.landscape !== void 0 && typeof e.landscape != "boolean")
1079
1087
  throw new Error("paper 必须是纸张预设名或 { widthMm, heightMm } 对象,landscape 必须是布尔值");
1080
- if (typeof i == "string" && !Object.prototype.hasOwnProperty.call(ge, i))
1081
- throw new Error(`未知纸张预设 "${i}"(可用:${Object.keys(ge).join("/")})`);
1082
- const o = Qe(i, void 0, e.landscape);
1083
- let s = o.widthMm;
1084
- const r = o.heightMm;
1085
- if (W(s, "纸张 widthMm"), W(r, "纸张 heightMm"), e.margins !== void 0 && (!e.margins || typeof e.margins != "object" || Array.isArray(e.margins)))
1088
+ if (typeof t == "string" && !Object.prototype.hasOwnProperty.call(Q, t))
1089
+ throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(Q).join("/")})`);
1090
+ const n = Ie(t, void 0, e.landscape), i = n.widthMm, o = n.heightMm;
1091
+ return O(i, "纸张 widthMm"), O(o, "纸张 heightMm"), { widthMm: i, heightMm: o };
1092
+ }
1093
+ function Lt(e) {
1094
+ if (e.margins !== void 0 && (!e.margins || typeof e.margins != "object" || Array.isArray(e.margins)))
1086
1095
  throw new Error("margins 必须是页边距对象");
1087
- const a = e.margins ?? {}, l = {
1088
- marginTopMm: a.marginTopMm === void 0 ? 10 : a.marginTopMm,
1089
- marginBottomMm: a.marginBottomMm === void 0 ? 10 : a.marginBottomMm,
1090
- marginLeftMm: a.marginLeftMm === void 0 ? 10 : a.marginLeftMm,
1091
- marginRightMm: a.marginRightMm === void 0 ? 10 : a.marginRightMm
1096
+ const t = e.margins ?? {}, n = {
1097
+ marginTopMm: t.marginTopMm === void 0 ? 10 : t.marginTopMm,
1098
+ marginBottomMm: t.marginBottomMm === void 0 ? 10 : t.marginBottomMm,
1099
+ marginLeftMm: t.marginLeftMm === void 0 ? 10 : t.marginLeftMm,
1100
+ marginRightMm: t.marginRightMm === void 0 ? 10 : t.marginRightMm
1092
1101
  };
1093
- for (const [k, v] of Object.entries(l)) W(v, k, !0);
1094
- let d = s - l.marginLeftMm - l.marginRightMm;
1095
- const m = r - l.marginTopMm - l.marginBottomMm;
1096
- if (t === "page" && d <= 0 || m <= 0)
1097
- throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");
1098
- const h = e.dataset === void 0 ? "detail" : e.dataset;
1099
- if (typeof h != "string" || !h.trim())
1102
+ for (const [i, o] of Object.entries(n)) O(o, i, !0);
1103
+ return n;
1104
+ }
1105
+ function It(e, t) {
1106
+ const n = e.dataset === void 0 ? "detail" : e.dataset;
1107
+ if (typeof n != "string" || !n.trim())
1100
1108
  throw new Error("dataset 必须是非空字符串");
1101
1109
  if (e.title !== void 0 && typeof e.title != "string")
1102
1110
  throw new Error("title 必须是字符串");
1103
- const f = e.titleHeightMm === void 0 ? 10 : e.titleHeightMm, g = e.titleGapMm === void 0 ? 4 : e.titleGapMm;
1104
- W(f, "titleHeightMm"), W(g, "titleGapMm", !0);
1105
- const c = e.title !== void 0 && e.title.length > 0, b = c ? f + g : 0;
1106
- if (b >= m)
1111
+ const i = e.titleHeightMm === void 0 ? 10 : e.titleHeightMm, o = e.titleGapMm === void 0 ? 4 : e.titleGapMm;
1112
+ O(i, "titleHeightMm"), O(o, "titleGapMm", !0);
1113
+ const r = e.title !== void 0 && e.title.length > 0, a = r ? i + o : 0;
1114
+ if (a >= t)
1107
1115
  throw new Error("标题高度与间距占满页面,必须为表格保留可用高度");
1116
+ return { dataset: n, titleHeightMm: i, hasTitle: r, titleSpaceMm: a };
1117
+ }
1118
+ function Bt(e) {
1108
1119
  if (e.listOptions !== void 0 && (!e.listOptions || typeof e.listOptions != "object" || Array.isArray(e.listOptions)))
1109
1120
  throw new Error("listOptions 必须是列表配置对象");
1110
- const y = e.listOptions ?? {};
1111
- fe(y.align, "listOptions.align", !0), fe(y.headerAlign, "listOptions.headerAlign", !1);
1112
- for (const k of ["fontSizePt", "rowHeightMm", "paddingMm"]) {
1113
- const v = y[k];
1114
- v !== void 0 && W(v, `listOptions.${k}`, k === "paddingMm");
1115
- }
1116
- let T = 0, $ = 0;
1117
- for (const [k, v] of e.columns.entries()) {
1118
- if (!v || typeof v.header != "string" || typeof v.field != "string" || !v.field.trim())
1119
- throw new Error(`columns[${k}] 需要字符串 header 与非空 field`);
1120
- fe(v.align, `columns[${k}].align`, !0), fe(v.headerAlign, `columns[${k}].headerAlign`, !1), v.flex !== void 0 && W(v.flex, `columns[${k}].flex`), v.widthMm !== void 0 ? (W(v.widthMm, `columns[${k}].widthMm`), T += v.widthMm) : $ = Math.max($, v.flex ?? 1);
1121
- }
1122
- if (t === "page" && T > d)
1123
- throw new Error(`固定列宽 ${T}mm 超出页面可用宽度 ${d}mm`);
1124
- const E = d - T;
1125
- if (t === "page" && $ > 0 && E <= 0)
1121
+ const t = e.listOptions ?? {};
1122
+ Z(t.align, "listOptions.align", !0), Z(t.headerAlign, "listOptions.headerAlign", !1);
1123
+ for (const n of ["fontSizePt", "rowHeightMm", "paddingMm"]) {
1124
+ const i = t[n];
1125
+ i !== void 0 && O(i, `listOptions.${n}`, n === "paddingMm");
1126
+ }
1127
+ return t;
1128
+ }
1129
+ function zt(e) {
1130
+ let t = 0, n = 0;
1131
+ for (const [i, o] of e.entries()) {
1132
+ if (!o || typeof o.header != "string" || typeof o.field != "string" || !o.field.trim())
1133
+ throw new Error(`columns[${i}] 需要字符串 header 与非空 field`);
1134
+ Z(o.align, `columns[${i}].align`, !0), Z(o.headerAlign, `columns[${i}].headerAlign`, !1), o.flex !== void 0 && O(o.flex, `columns[${i}].flex`), o.widthMm !== void 0 ? (O(o.widthMm, `columns[${i}].widthMm`), t += o.widthMm) : n = Math.max(n, o.flex ?? 1);
1135
+ }
1136
+ return { fixedWidthMm: t, maxFlex: n };
1137
+ }
1138
+ function Dt(e, t, n, i) {
1139
+ const { fixedWidthMm: o, maxFlex: r } = zt(e.columns);
1140
+ if (t === "page" && o > i)
1141
+ throw new Error(`固定列宽 ${o}mm 超出页面可用宽度 ${i}mm`);
1142
+ const a = i - o;
1143
+ if (t === "page" && r > 0 && a <= 0)
1126
1144
  throw new Error("固定列占满页面可用宽度,自动列需要正的剩余宽度");
1127
- const S = $ > 0 ? e.columns.reduce((k, v) => k + (v.widthMm === void 0 ? (v.flex ?? 1) / $ : 0), 0) : 0, R = e.columns.map(({ widthMm: k, flex: v, ...u }, p) => {
1128
- const B = k ?? (t === "wide" ? n * (v ?? 1) : E * ((v ?? 1) / $) / S);
1129
- return W(B, `columns[${p}] 分配后的 widthMm`), { ...u, widthMm: B };
1130
- });
1131
- t === "wide" && (d = R.reduce((k, v) => k + v.widthMm, 0), W(d, "宽表总列宽"), s = d + l.marginLeftMm + l.marginRightMm, W(s, "宽表总宽度"));
1132
- const F = { widthMm: s, heightMm: r, ...l, components: [], ...t === "wide" ? { layout: t } : {} };
1133
- return c && F.components.push({
1145
+ const s = r > 0 ? e.columns.reduce((d, c) => d + (c.widthMm === void 0 ? (c.flex ?? 1) / r : 0), 0) : 0;
1146
+ return { columns: e.columns.map(({ widthMm: d, flex: c, ...f }, g) => {
1147
+ const u = d ?? (t === "wide" ? n * (c ?? 1) : a * ((c ?? 1) / r) / s);
1148
+ return O(u, `columns[${g}] 分配后的 widthMm`), { ...f, widthMm: u };
1149
+ }), fixedWidthMm: o, maxFlex: r };
1150
+ }
1151
+ function Mn(e) {
1152
+ if (!e || typeof e != "object")
1153
+ throw new Error("标准明细模板需要 options 对象");
1154
+ if (!Array.isArray(e.columns) || e.columns.length === 0)
1155
+ throw new Error("columns 至少需要一列");
1156
+ const { layout: t, columnWidthMm: n } = Ht(e), i = Ft(e);
1157
+ let o = i.widthMm;
1158
+ const r = i.heightMm, a = Lt(e);
1159
+ let s = o - a.marginLeftMm - a.marginRightMm;
1160
+ const l = r - a.marginTopMm - a.marginBottomMm;
1161
+ if (t === "page" && s <= 0 || l <= 0)
1162
+ throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");
1163
+ const { dataset: d, titleHeightMm: c, hasTitle: f, titleSpaceMm: g } = It(e, l), u = Bt(e), { columns: m, fixedWidthMm: h, maxFlex: p } = Dt(e, t, n, s);
1164
+ t === "wide" && (s = m.reduce((b, A) => b + A.widthMm, 0), O(s, "宽表总列宽"), o = s + a.marginLeftMm + a.marginRightMm, O(o, "宽表总宽度"));
1165
+ const M = { widthMm: o, heightMm: r, ...a, components: [], ...t === "wide" ? { layout: t } : {} };
1166
+ return f && M.components.push({
1134
1167
  kind: "text",
1135
1168
  text: e.title,
1136
- leftMm: l.marginLeftMm,
1137
- topMm: l.marginTopMm,
1138
- widthMm: d,
1139
- heightMm: f,
1169
+ leftMm: a.marginLeftMm,
1170
+ topMm: a.marginTopMm,
1171
+ widthMm: s,
1172
+ heightMm: c,
1140
1173
  style: { fontSize: 16, bold: !0, align: "center", verticalAlign: "middle", ...e.titleStyle }
1141
- }), F.components.push({
1174
+ }), M.components.push({
1142
1175
  align: "auto",
1143
1176
  headerAlign: "center",
1144
- ...y,
1177
+ ...u,
1145
1178
  kind: "list",
1146
1179
  ...t === "wide" ? { layout: t } : {},
1147
- ...c ? { title: e.title } : {},
1148
- dataset: h,
1149
- columns: R,
1150
- leftMm: l.marginLeftMm,
1151
- topMm: l.marginTopMm + b,
1152
- widthMm: t === "wide" || $ > 0 ? d : T
1153
- }), e.params === void 0 ? { pages: [F] } : { params: e.params, pages: [F] };
1154
- }
1155
- const Ze = "1.0";
1156
- class X extends Error {
1180
+ ...f ? { title: e.title } : {},
1181
+ dataset: d,
1182
+ columns: m,
1183
+ leftMm: a.marginLeftMm,
1184
+ topMm: a.marginTopMm + g,
1185
+ widthMm: t === "wide" || p > 0 ? s : h
1186
+ }), e.params === void 0 ? { pages: [M] } : { params: e.params, pages: [M] };
1187
+ }
1188
+ const Be = "1.0";
1189
+ class j extends Error {
1157
1190
  constructor(t) {
1158
1191
  super(`模板校验失败:${t.slice(0, 3).map((n) => `${n.path}: ${n.message}`).join("; ")}`), this.errors = t, this.name = "ReportTemplateError";
1159
1192
  }
1160
1193
  }
1161
- const Ht = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), Bt = /* @__PURE__ */ new Set(["schemaVersion", "id", "name", "revision", "description", "template"]), Ot = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), we = 2e5, Ft = 64, xe = 1e7;
1162
- function H(e) {
1194
+ const jt = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), _t = /* @__PURE__ */ new Set(["schemaVersion", "id", "name", "revision", "description", "template"]), Wt = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), re = 2e5, Vt = 64, he = 1e7;
1195
+ function S(e) {
1163
1196
  return !!e && typeof e == "object" && !Array.isArray(e);
1164
1197
  }
1165
- function Ne(e, t) {
1198
+ function Gt(e, t, n) {
1199
+ const i = Object.getPrototypeOf(e), o = Array.isArray(e);
1200
+ if (o ? i !== Array.prototype : i !== Object.prototype && i !== null)
1201
+ return n.push({ path: t, message: "模板对象必须使用普通 JSON 对象原型" }), !1;
1202
+ if (o) {
1203
+ const r = Object.keys(e);
1204
+ if (r.length !== e.length || r.some((a) => !/^(0|[1-9]\d*)$/.test(a) || Number(a) >= e.length))
1205
+ return n.push({ path: t, message: "模板数组不能包含空位或额外属性" }), !1;
1206
+ }
1207
+ return Object.getOwnPropertySymbols(e).length > 0 ? (n.push({ path: t, message: "模板不能包含 Symbol 键" }), !1) : !0;
1208
+ }
1209
+ function Jt(e, t, n, i) {
1210
+ return jt.has(e) ? (i.push({ path: n, message: "模板不能包含可能污染原型的键" }), !1) : t.get || t.set || !t.enumerable ? (i.push({ path: n, message: "模板不能包含访问器或不可枚举字段" }), !1) : !0;
1211
+ }
1212
+ function Yt(e) {
1213
+ return e === null || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e);
1214
+ }
1215
+ function ue(e, t) {
1166
1216
  const n = /* @__PURE__ */ new Set();
1167
- let i = 0, o = 0, s = !1;
1168
- const r = (a, l, d) => {
1169
- if (s) return;
1170
- if (++i > we) {
1171
- i === we + 1 && t.push({ path: l, message: "模板超过 JSON 节点安全上限" });
1172
- return;
1173
- }
1174
- if (d > Ft) {
1175
- t.push({ path: l, message: "模板嵌套层级过深" });
1176
- return;
1177
- }
1178
- if (typeof a == "string") {
1179
- o += a.length, o > xe && (s = !0, t.push({ path: l, message: "模板文本超过 1000 万字符的安全上限" }));
1180
- return;
1181
- }
1182
- if (a === null || typeof a == "boolean" || typeof a == "number" && Number.isFinite(a)) return;
1183
- if (!a || typeof a != "object") {
1184
- t.push({ path: l, message: "模板只允许 JSON 值,不允许函数、undefined 或非有限数字" });
1185
- return;
1186
- }
1187
- if (n.has(a)) {
1188
- t.push({ path: l, message: "模板不能包含循环引用" });
1189
- return;
1190
- }
1191
- const m = Object.getPrototypeOf(a);
1192
- if (Array.isArray(a) && m !== Array.prototype || !Array.isArray(a) && m !== Object.prototype && m !== null) {
1193
- t.push({ path: l, message: "模板对象必须使用普通 JSON 对象原型" });
1194
- return;
1195
- }
1196
- if (Array.isArray(a) && (Object.keys(a).length !== a.length || Object.keys(a).some((h) => !/^(0|[1-9]\d*)$/.test(h) || Number(h) >= a.length))) {
1197
- t.push({ path: l, message: "模板数组不能包含空位或额外属性" });
1198
- return;
1199
- }
1200
- if (Object.getOwnPropertySymbols(a).length > 0) {
1201
- t.push({ path: l, message: "模板不能包含 Symbol 键" });
1202
- return;
1217
+ let i = 0, o = 0, r = !1;
1218
+ const a = (s, l, d) => {
1219
+ if (!r) {
1220
+ if (++i > re) {
1221
+ i === re + 1 && t.push({ path: l, message: "模板超过 JSON 节点安全上限" });
1222
+ return;
1223
+ }
1224
+ if (d > Vt) {
1225
+ t.push({ path: l, message: "模板嵌套层级过深" });
1226
+ return;
1227
+ }
1228
+ if (typeof s == "string") {
1229
+ o += s.length, o > he && (r = !0, t.push({ path: l, message: "模板文本超过 1000 万字符的安全上限" }));
1230
+ return;
1231
+ }
1232
+ if (!Yt(s)) {
1233
+ if (!s || typeof s != "object") {
1234
+ t.push({ path: l, message: "模板只允许 JSON 值,不允许函数、undefined 或非有限数字" });
1235
+ return;
1236
+ }
1237
+ if (n.has(s)) {
1238
+ t.push({ path: l, message: "模板不能包含循环引用" });
1239
+ return;
1240
+ }
1241
+ if (Gt(s, l, t)) {
1242
+ n.add(s);
1243
+ for (const [c, f] of Object.entries(Object.getOwnPropertyDescriptors(s))) {
1244
+ if (Array.isArray(s) && c === "length") continue;
1245
+ const g = `${l}.${c}`;
1246
+ if (Jt(c, f, g, t) && a(f.value, g, d + 1), i > re || r) break;
1247
+ }
1248
+ n.delete(s);
1249
+ }
1250
+ }
1203
1251
  }
1204
- n.add(a);
1205
- for (const [h, f] of Object.entries(Object.getOwnPropertyDescriptors(a)))
1206
- if (!(Array.isArray(a) && h === "length") && (Ht.has(h) ? t.push({ path: `${l}.${h}`, message: "模板不能包含可能污染原型的键" }) : f.get || f.set || !f.enumerable ? t.push({ path: `${l}.${h}`, message: "模板不能包含访问器或不可枚举字段" }) : r(f.value, `${l}.${h}`, d + 1), i > we || s))
1207
- break;
1208
- n.delete(a);
1209
1252
  };
1210
- r(e, "$", 0);
1253
+ a(e, "$", 0);
1211
1254
  }
1212
- function O(e, t, n, i, o = !1) {
1213
- const s = e[t];
1214
- s === void 0 && !o || (typeof s != "string" || o && !s.trim()) && i.push({ path: `${n}.${t}`, message: o ? "应为非空字符串" : "应为字符串" });
1215
- }
1216
- function _(e, t, n, i, o = 0, s = !1) {
1255
+ function k(e, t, n, i, o = !1) {
1217
1256
  const r = e[t];
1218
- r === void 0 && !s || (typeof r != "number" || !Number.isFinite(r) || r < o) && i.push({ path: `${n}.${t}`, message: `应为大于等于 ${o} 的有限数字` });
1257
+ r === void 0 && !o || (typeof r != "string" || o && !r.trim()) && i.push({ path: `${n}.${t}`, message: o ? "应为非空字符串" : "应为字符串" });
1258
+ }
1259
+ function E(e, t, n, i, o = 0, r = !1) {
1260
+ const a = e[t];
1261
+ a === void 0 && !r || (typeof a != "number" || !Number.isFinite(a) || a < o) && i.push({ path: `${n}.${t}`, message: `应为大于等于 ${o} 的有限数字` });
1219
1262
  }
1220
- function ae(e, t, n, i) {
1263
+ function U(e, t, n, i) {
1221
1264
  e[t] !== void 0 && typeof e[t] != "boolean" && i.push({ path: `${n}.${t}`, message: "应为布尔值" });
1222
1265
  }
1223
- function ee(e, t, n, i = !1) {
1224
- e !== void 0 && !Ot.has(e) && !(i && e === "auto") && n.push({ path: t, message: `未知对齐方式${i ? "(支持 auto)" : ""}` });
1266
+ function G(e, t, n, i = !1) {
1267
+ e !== void 0 && !Wt.has(e) && !(i && e === "auto") && n.push({ path: t, message: `未知对齐方式${i ? "(支持 auto)" : ""}` });
1225
1268
  }
1226
- function Y(e, t, n) {
1269
+ function L(e, t, n) {
1227
1270
  if (e !== void 0) {
1228
- if (!H(e)) {
1271
+ if (!S(e)) {
1229
1272
  n.push({ path: t, message: "样式应为对象" });
1230
1273
  return;
1231
1274
  }
1232
- ee(e.align, `${t}.align`, n), e.verticalAlign !== void 0 && !["top", "middle", "bottom"].includes(e.verticalAlign) && n.push({ path: `${t}.verticalAlign`, message: "未知垂直对齐方式" });
1233
- for (const i of ["fontSize", "fontSizePx", "lineWidthPt", "lineHeight"]) _(e, i, t, n);
1234
- for (const i of ["letterSpacing", "rotateDeg"]) _(e, i, t, n, -1 / 0);
1235
- _(e, "opacity", t, n), typeof e.opacity == "number" && e.opacity > 1 && n.push({ path: `${t}.opacity`, message: "透明度不能大于 1" });
1236
- for (const i of ["bold", "italic", "underline", "borderTop", "borderRight", "borderBottom", "borderLeft"]) ae(e, i, t, n);
1237
- for (const i of ["fontFamily", "color", "backgroundColor", "lineColor", "borderColor"]) O(e, i, t, n);
1275
+ G(e.align, `${t}.align`, n), e.verticalAlign !== void 0 && !["top", "middle", "bottom"].includes(e.verticalAlign) && n.push({ path: `${t}.verticalAlign`, message: "未知垂直对齐方式" });
1276
+ for (const i of ["fontSize", "fontSizePx", "lineWidthPt", "lineHeight"]) E(e, i, t, n);
1277
+ for (const i of ["letterSpacing", "rotateDeg"]) E(e, i, t, n, -1 / 0);
1278
+ E(e, "opacity", t, n), typeof e.opacity == "number" && e.opacity > 1 && n.push({ path: `${t}.opacity`, message: "透明度不能大于 1" });
1279
+ for (const i of ["bold", "italic", "underline", "borderTop", "borderRight", "borderBottom", "borderLeft"]) U(e, i, t, n);
1280
+ for (const i of ["fontFamily", "color", "backgroundColor", "lineColor", "borderColor"]) k(e, i, t, n);
1238
1281
  }
1239
1282
  }
1240
- function Lt(e, t, n) {
1283
+ function Ut(e, t, n) {
1241
1284
  if (e === void 0) return;
1242
1285
  if (!Array.isArray(e)) {
1243
1286
  n.push({ path: t, message: "参数定义应为数组" });
1244
1287
  return;
1245
1288
  }
1246
1289
  const i = /* @__PURE__ */ new Set();
1247
- e.forEach((o, s) => {
1248
- const r = `${t}.${s}`;
1249
- if (!H(o)) {
1250
- n.push({ path: r, message: "参数定义应为对象" });
1290
+ e.forEach((o, r) => {
1291
+ const a = `${t}.${r}`;
1292
+ if (!S(o)) {
1293
+ n.push({ path: a, message: "参数定义应为对象" });
1251
1294
  return;
1252
1295
  }
1253
- O(o, "field", r, n, !0), typeof o.field == "string" && (i.has(o.field) && n.push({ path: `${r}.field`, message: "参数名重复" }), i.add(o.field)), o.type !== void 0 && !["text", "number", "date", "select"].includes(o.type) && n.push({ path: `${r}.type`, message: "未知参数类型" });
1254
- for (const a of ["label", "defaultValue", "placeholder"]) O(o, a, r, n);
1255
- ae(o, "required", r, n), o.options !== void 0 && (Array.isArray(o.options) ? o.options.forEach((a, l) => {
1256
- const d = `${r}.options.${l}`;
1257
- if (!H(a)) n.push({ path: d, message: "选项应为对象" });
1296
+ k(o, "field", a, n, !0), typeof o.field == "string" && (i.has(o.field) && n.push({ path: `${a}.field`, message: "参数名重复" }), i.add(o.field)), o.type !== void 0 && !["text", "number", "date", "select"].includes(o.type) && n.push({ path: `${a}.type`, message: "未知参数类型" });
1297
+ for (const s of ["label", "defaultValue", "placeholder"]) k(o, s, a, n);
1298
+ U(o, "required", a, n), o.options !== void 0 && (Array.isArray(o.options) ? o.options.forEach((s, l) => {
1299
+ const d = `${a}.options.${l}`;
1300
+ if (!S(s)) n.push({ path: d, message: "选项应为对象" });
1258
1301
  else
1259
- for (const m of ["label", "value"]) typeof a[m] != "string" && n.push({ path: `${d}.${m}`, message: "选项标签与值应为字符串(允许空白选项)" });
1260
- }) : n.push({ path: `${r}.options`, message: "选项应为数组" }));
1302
+ for (const c of ["label", "value"]) typeof s[c] != "string" && n.push({ path: `${d}.${c}`, message: "选项标签与值应为字符串(允许空白选项)" });
1303
+ }) : n.push({ path: `${a}.options`, message: "选项应为数组" }));
1261
1304
  });
1262
1305
  }
1263
- function It(e, t, n) {
1264
- for (const i of ["leftMm", "topMm"]) _(e, i, t, n, -1 / 0, !0);
1265
- _(e, "widthMm", t, n, Number.MIN_VALUE, !0), O(e, "dataset", t, n, !0), O(e, "title", t, n), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" }), !Array.isArray(e.columns) || e.columns.length === 0 ? n.push({ path: `${t}.columns`, message: "列表至少需要一列" }) : e.columns.forEach((i, o) => {
1266
- const s = `${t}.columns.${o}`;
1267
- if (!H(i)) {
1268
- n.push({ path: s, message: "列应为对象" });
1306
+ function qt(e, t, n) {
1307
+ if (!Array.isArray(e) || e.length === 0) {
1308
+ n.push({ path: t, message: "列表至少需要一列" });
1309
+ return;
1310
+ }
1311
+ e.forEach((i, o) => {
1312
+ const r = `${t}.${o}`;
1313
+ if (!S(i)) {
1314
+ n.push({ path: r, message: "列应为对象" });
1269
1315
  return;
1270
1316
  }
1271
- if (typeof i.header != "string" && n.push({ path: `${s}.header`, message: "表头应为字符串(允许空白表头)" }), O(i, "field", s, n, !0), _(i, "widthMm", s, n, Number.MIN_VALUE, !0), Y(i.style, `${s}.style`, n), Y(i.headerStyle, `${s}.headerStyle`, n), ee(i.align, `${s}.align`, n, !0), ee(i.headerAlign, `${s}.headerAlign`, n), i.format !== void 0)
1272
- if (!H(i.format) || !["number", "percent", "date"].includes(i.format.kind))
1273
- n.push({ path: `${s}.format`, message: "未知列格式" });
1317
+ if (typeof i.header != "string" && n.push({ path: `${r}.header`, message: "表头应为字符串(允许空白表头)" }), k(i, "field", r, n, !0), E(i, "widthMm", r, n, Number.MIN_VALUE, !0), L(i.style, `${r}.style`, n), L(i.headerStyle, `${r}.headerStyle`, n), G(i.align, `${r}.align`, n, !0), G(i.headerAlign, `${r}.headerAlign`, n), i.format !== void 0)
1318
+ if (!S(i.format) || !["number", "percent", "date"].includes(i.format.kind))
1319
+ n.push({ path: `${r}.format`, message: "未知列格式" });
1274
1320
  else {
1275
- const r = i.format.digits;
1276
- r !== void 0 && (typeof r != "number" || !Number.isInteger(r) || r < 0 || r > 100) && n.push({ path: `${s}.format.digits`, message: "小数位应为 0–100 的整数" }), ae(i.format, "thousands", `${s}.format`, n), O(i.format, "pattern", `${s}.format`, n);
1321
+ const a = i.format.digits;
1322
+ a !== void 0 && (typeof a != "number" || !Number.isInteger(a) || a < 0 || a > 100) && n.push({ path: `${r}.format.digits`, message: "小数位应为 0–100 的整数" }), U(i.format, "thousands", `${r}.format`, n), k(i.format, "pattern", `${r}.format`, n);
1277
1323
  }
1278
- i.rules !== void 0 && (Array.isArray(i.rules) ? i.rules.forEach((r, a) => {
1279
- const l = `${s}.rules.${a}`;
1280
- if (!H(r) || !H(r.when)) {
1324
+ i.rules !== void 0 && (Array.isArray(i.rules) ? i.rules.forEach((a, s) => {
1325
+ const l = `${r}.rules.${s}`;
1326
+ if (!S(a) || !S(a.when)) {
1281
1327
  n.push({ path: l, message: "条件格式缺少 when 对象" });
1282
1328
  return;
1283
1329
  }
1284
- O(r.when, "field", `${l}.when`, n, !0), [">", ">=", "<", "<=", "==", "!="].includes(r.when.op) || n.push({ path: `${l}.when.op`, message: "未知条件运算符" }), typeof r.when.value != "number" && typeof r.when.value != "string" && n.push({ path: `${l}.when.value`, message: "条件值应为数字或字符串" }), Y(r.style, `${l}.style`, n);
1285
- }) : n.push({ path: `${s}.rules`, message: "条件格式应为数组" }));
1330
+ k(a.when, "field", `${l}.when`, n, !0), [">", ">=", "<", "<=", "==", "!="].includes(a.when.op) || n.push({ path: `${l}.when.op`, message: "未知条件运算符" }), typeof a.when.value != "number" && typeof a.when.value != "string" && n.push({ path: `${l}.when.value`, message: "条件值应为数字或字符串" }), L(a.style, `${l}.style`, n);
1331
+ }) : n.push({ path: `${r}.rules`, message: "条件格式应为数组" }));
1286
1332
  });
1287
- for (const i of ["fontSizePt", "rowHeightMm"]) _(e, i, t, n, Number.MIN_VALUE);
1288
- _(e, "paddingMm", t, n);
1289
- for (const i of ["headerBold", "headerEveryPage", "border"]) ae(e, i, t, n);
1290
- if (O(e, "headerBackgroundColor", t, n), ee(e.align, `${t}.align`, n, !0), ee(e.headerAlign, `${t}.headerAlign`, n), Y(e.headerStyle, `${t}.headerStyle`, n), e.groupBy !== void 0)
1291
- if (!H(e.groupBy)) n.push({ path: `${t}.groupBy`, message: "分组应为对象" });
1292
- else {
1293
- O(e.groupBy, "field", `${t}.groupBy`, n, !0);
1294
- for (const i of ["headerTemplate", "subtotalLabel"]) O(e.groupBy, i, `${t}.groupBy`, n);
1295
- for (const i of ["headerStyle", "subtotalStyle"]) Y(e.groupBy[i], `${t}.groupBy.${i}`, n);
1296
- ae(e.groupBy, "keepWithNext", `${t}.groupBy`, n), e.groupBy.subtotal !== void 0 && (!Array.isArray(e.groupBy.subtotal) || e.groupBy.subtotal.some((i) => typeof i != "string")) && n.push({ path: `${t}.groupBy.subtotal`, message: "小计字段应为字符串数组" });
1333
+ }
1334
+ function Kt(e, t, n) {
1335
+ if (e !== void 0) {
1336
+ if (!S(e)) {
1337
+ n.push({ path: t, message: "分组应为对象" });
1338
+ return;
1297
1339
  }
1298
- e.grandTotal !== void 0 && typeof e.grandTotal != "boolean" && (H(e.grandTotal) ? (O(e.grandTotal, "label", `${t}.grandTotal`, n), Y(e.grandTotal.style, `${t}.grandTotal.style`, n), e.grandTotal.fields !== void 0 && (!Array.isArray(e.grandTotal.fields) || e.grandTotal.fields.some((i) => typeof i != "string")) && n.push({ path: `${t}.grandTotal.fields`, message: "合计字段应为字符串数组" })) : n.push({ path: `${t}.grandTotal`, message: "合计应为布尔值或对象" }));
1340
+ k(e, "field", t, n, !0);
1341
+ for (const i of ["headerTemplate", "subtotalLabel"]) k(e, i, t, n);
1342
+ for (const i of ["headerStyle", "subtotalStyle"]) L(e[i], `${t}.${i}`, n);
1343
+ U(e, "keepWithNext", t, n), e.subtotal !== void 0 && (!Array.isArray(e.subtotal) || e.subtotal.some((i) => typeof i != "string")) && n.push({ path: `${t}.subtotal`, message: "小计字段应为字符串数组" });
1344
+ }
1299
1345
  }
1300
- function et(e, t, n) {
1301
- Y(e.style, `${t}.style`, n);
1302
- for (const o of ["text", "rawText", "imageData", "fallbackText", "nid", "rkey"]) O(e, o, t, n);
1303
- if (e.lines !== void 0 && (!Array.isArray(e.lines) || e.lines.some((o) => typeof o != "string")) && n.push({ path: `${t}.lines`, message: "文本行应为字符串数组" }), Array.isArray(e.richParagraphs) && e.richParagraphs.forEach((o, s) => {
1304
- if (!H(o)) return;
1305
- const r = `${t}.richParagraphs.${s}`;
1306
- ee(o.align, `${r}.align`, n);
1307
- for (const a of ["lineHeight", "spaceBeforeMm", "spaceAfterMm", "indentMm"]) _(o, a, r, n);
1308
- Array.isArray(o.segments) && o.segments.forEach((a, l) => {
1309
- const d = `${r}.segments.${l}`;
1310
- if (!H(a)) {
1346
+ function Xt(e, t, n) {
1347
+ if (!(e === void 0 || typeof e == "boolean")) {
1348
+ if (!S(e)) {
1349
+ n.push({ path: t, message: "合计应为布尔值或对象" });
1350
+ return;
1351
+ }
1352
+ k(e, "label", t, n), L(e.style, `${t}.style`, n), e.fields !== void 0 && (!Array.isArray(e.fields) || e.fields.some((i) => typeof i != "string")) && n.push({ path: `${t}.fields`, message: "合计字段应为字符串数组" });
1353
+ }
1354
+ }
1355
+ function Qt(e, t, n) {
1356
+ for (const i of ["leftMm", "topMm"]) E(e, i, t, n, -1 / 0, !0);
1357
+ E(e, "widthMm", t, n, Number.MIN_VALUE, !0), k(e, "dataset", t, n, !0), k(e, "title", t, n), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && n.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" }), qt(e.columns, `${t}.columns`, n);
1358
+ for (const i of ["fontSizePt", "rowHeightMm"]) E(e, i, t, n, Number.MIN_VALUE);
1359
+ E(e, "paddingMm", t, n);
1360
+ for (const i of ["headerBold", "headerEveryPage", "border"]) U(e, i, t, n);
1361
+ k(e, "headerBackgroundColor", t, n), G(e.align, `${t}.align`, n, !0), G(e.headerAlign, `${t}.headerAlign`, n), L(e.headerStyle, `${t}.headerStyle`, n), Kt(e.groupBy, `${t}.groupBy`, n), Xt(e.grandTotal, `${t}.grandTotal`, n);
1362
+ }
1363
+ function ze(e, t, n) {
1364
+ L(e.style, `${t}.style`, n);
1365
+ for (const o of ["text", "rawText", "imageData", "fallbackText", "nid", "rkey"]) k(e, o, t, n);
1366
+ if (e.lines !== void 0 && (!Array.isArray(e.lines) || e.lines.some((o) => typeof o != "string")) && n.push({ path: `${t}.lines`, message: "文本行应为字符串数组" }), Array.isArray(e.richParagraphs) && e.richParagraphs.forEach((o, r) => {
1367
+ if (!S(o)) return;
1368
+ const a = `${t}.richParagraphs.${r}`;
1369
+ G(o.align, `${a}.align`, n);
1370
+ for (const s of ["lineHeight", "spaceBeforeMm", "spaceAfterMm", "indentMm"]) E(o, s, a, n);
1371
+ Array.isArray(o.segments) && o.segments.forEach((s, l) => {
1372
+ const d = `${a}.segments.${l}`;
1373
+ if (!S(s)) {
1311
1374
  n.push({ path: d, message: "富文本片段应为对象" });
1312
1375
  return;
1313
1376
  }
1314
- a.kind !== void 0 && a.kind !== "text" && a.kind !== "field" && n.push({ path: `${d}.kind`, message: "未知富文本片段类型" });
1315
- for (const m of ["text", "field"]) O(a, m, d, n);
1316
- Y(a.style, `${d}.style`, n);
1377
+ s.kind !== void 0 && s.kind !== "text" && s.kind !== "field" && n.push({ path: `${d}.kind`, message: "未知富文本片段类型" });
1378
+ for (const c of ["text", "field"]) k(s, c, d, n);
1379
+ L(s.style, `${d}.style`, n);
1317
1380
  });
1318
- }), !H(e.grid)) return;
1381
+ }), !S(e.grid)) return;
1319
1382
  const i = e.grid;
1320
- _(i, "gapMm", `${t}.grid`, n);
1383
+ E(i, "gapMm", `${t}.grid`, n), E(i, "paddingMm", `${t}.grid`, n);
1321
1384
  for (const o of ["colWidthsMm", "rowHeightsMm"]) {
1322
- const s = i[o];
1323
- s !== void 0 && (!Array.isArray(s) || s.some((r) => typeof r != "number" || !Number.isFinite(r) || r < 0)) && n.push({ path: `${t}.grid.${o}`, message: "网格尺寸应为有限非负数字数组" });
1324
- }
1325
- Array.isArray(i.cells) && i.cells.forEach((o, s) => {
1326
- Array.isArray(o) && o.forEach((r, a) => {
1327
- const l = `${t}.grid.cells.${s}.${a}`;
1328
- if (r !== null) {
1329
- if (!H(r)) {
1385
+ const r = i[o];
1386
+ r !== void 0 && (!Array.isArray(r) || r.some((a) => typeof a != "number" || !Number.isFinite(a) || a < 0)) && n.push({ path: `${t}.grid.${o}`, message: "网格尺寸应为有限非负数字数组" });
1387
+ }
1388
+ Array.isArray(i.cells) && i.cells.forEach((o, r) => {
1389
+ Array.isArray(o) && o.forEach((a, s) => {
1390
+ const l = `${t}.grid.cells.${r}.${s}`;
1391
+ if (a !== null) {
1392
+ if (!S(a)) {
1330
1393
  n.push({ path: l, message: "网格单元格应为对象或 null" });
1331
1394
  return;
1332
1395
  }
1333
- for (const d of ["text", "rawText", "numberFormat"]) O(r, d, l, n);
1396
+ for (const d of ["text", "rawText", "numberFormat"]) k(a, d, l, n);
1334
1397
  for (const d of ["colSpan", "rowSpan"]) {
1335
- const m = r[d];
1336
- m !== void 0 && (typeof m != "number" || !Number.isInteger(m) || m <= 0) && n.push({ path: `${l}.${d}`, message: "跨度应为正整数" });
1398
+ const c = a[d];
1399
+ c !== void 0 && (typeof c != "number" || !Number.isInteger(c) || c <= 0) && n.push({ path: `${l}.${d}`, message: "跨度应为正整数" });
1337
1400
  }
1338
- r.value !== void 0 && r.value !== null && !["string", "number", "boolean"].includes(typeof r.value) && n.push({ path: `${l}.value`, message: "Excel 原始值应为字符串、数字、布尔值或 null" }), Y(r.style, `${l}.style`, n), r.children !== void 0 && (Array.isArray(r.children) ? r.children.forEach((d, m) => {
1339
- H(d) && et(d, `${l}.children.${m}`, n);
1401
+ a.value !== void 0 && a.value !== null && !["string", "number", "boolean"].includes(typeof a.value) && n.push({ path: `${l}.value`, message: "Excel 原始值应为字符串、数字、布尔值或 null" }), L(a.style, `${l}.style`, n), a.children !== void 0 && (Array.isArray(a.children) ? a.children.forEach((d, c) => {
1402
+ S(d) && ze(d, `${l}.children.${c}`, n);
1340
1403
  }) : n.push({ path: `${l}.children`, message: "嵌套组件应为数组" }));
1341
1404
  }
1342
1405
  });
1343
1406
  });
1344
1407
  }
1345
- function tt(e) {
1408
+ function De(e) {
1346
1409
  const t = [], n = [];
1347
- return Ne(e, t), t.length ? { ok: !1, errors: t, warnings: n } : (H(e) ? (e.schemaVersion !== void 0 && e.schemaVersion !== Ae && t.push({ path: "$.schemaVersion", message: "不支持的模板 schemaVersion" }), Lt(e.params, "$.params", t), !Array.isArray(e.pages) || e.pages.length === 0 ? t.push({ path: "$.pages", message: "模板至少需要一页" }) : e.pages.forEach((i, o) => {
1348
- const s = `$.pages.${o}`;
1349
- if (!H(i)) {
1350
- t.push({ path: s, message: "页应为对象" });
1410
+ return ue(e, t), t.length ? { ok: !1, errors: t, warnings: n } : (S(e) ? (e.schemaVersion !== void 0 && e.schemaVersion !== de && t.push({ path: "$.schemaVersion", message: "不支持的模板 schemaVersion" }), Ut(e.params, "$.params", t), !Array.isArray(e.pages) || e.pages.length === 0 ? t.push({ path: "$.pages", message: "模板至少需要一页" }) : e.pages.forEach((i, o) => {
1411
+ const r = `$.pages.${o}`;
1412
+ if (!S(i)) {
1413
+ t.push({ path: r, message: "页应为对象" });
1351
1414
  return;
1352
1415
  }
1353
- _(i, "widthMm", s, t, Number.MIN_VALUE, !0), _(i, "heightMm", s, t, Number.MIN_VALUE, !0), i.layout !== void 0 && i.layout !== "page" && i.layout !== "wide" && t.push({ path: `${s}.layout`, message: "布局应为 page 或 wide" }), typeof i.heightMm == "number" && i.heightMm >= 5e3 && t.push({ path: `${s}.heightMm`, message: "页高应小于 5000mm" });
1354
- for (const r of ["marginTopMm", "marginBottomMm", "marginLeftMm", "marginRightMm"]) _(i, r, s, t);
1355
- typeof i.widthMm == "number" && Number(i.marginLeftMm ?? 0) + Number(i.marginRightMm ?? 0) >= i.widthMm && t.push({ path: s, message: "横向页边距占满页面" }), typeof i.heightMm == "number" && Number(i.marginTopMm ?? 0) + Number(i.marginBottomMm ?? 0) >= i.heightMm && t.push({ path: s, message: "纵向页边距占满页面" }), Array.isArray(i.components) ? i.components.forEach((r, a) => {
1356
- const l = `${s}.components.${a}`;
1357
- H(r) && r.kind === "list" ? It(r, l, t) : (Ee(r, l, t, n), H(r) && et(r, l, t));
1358
- }) : t.push({ path: `${s}.components`, message: "组件应为数组" });
1416
+ E(i, "widthMm", r, t, Number.MIN_VALUE, !0), E(i, "heightMm", r, t, Number.MIN_VALUE, !0), i.layout !== void 0 && i.layout !== "page" && i.layout !== "wide" && t.push({ path: `${r}.layout`, message: "布局应为 page 或 wide" }), typeof i.heightMm == "number" && i.heightMm >= 5e3 && t.push({ path: `${r}.heightMm`, message: "页高应小于 5000mm" });
1417
+ for (const a of ["marginTopMm", "marginBottomMm", "marginLeftMm", "marginRightMm"]) E(i, a, r, t);
1418
+ typeof i.widthMm == "number" && Number(i.marginLeftMm ?? 0) + Number(i.marginRightMm ?? 0) >= i.widthMm && t.push({ path: r, message: "横向页边距占满页面" }), typeof i.heightMm == "number" && Number(i.marginTopMm ?? 0) + Number(i.marginBottomMm ?? 0) >= i.heightMm && t.push({ path: r, message: "纵向页边距占满页面" }), Array.isArray(i.components) ? i.components.forEach((a, s) => {
1419
+ const l = `${r}.components.${s}`;
1420
+ S(a) && a.kind === "list" ? Qt(a, l, t) : (me(a, l, t, n), S(a) && ze(a, l, t));
1421
+ }) : t.push({ path: `${r}.components`, message: "组件应为数组" });
1359
1422
  })) : t.push({ path: "$", message: "模板应为对象" }), { ok: t.length === 0, errors: t, warnings: n });
1360
1423
  }
1361
- function jt(e) {
1424
+ function Zt(e) {
1362
1425
  const t = [], n = [];
1363
- if (Ne(e, t), t.length) return { ok: !1, errors: t, warnings: n };
1364
- if (!H(e)) t.push({ path: "$", message: "模板文档应为对象" });
1426
+ if (ue(e, t), t.length) return { ok: !1, errors: t, warnings: n };
1427
+ if (!S(e)) t.push({ path: "$", message: "模板文档应为对象" });
1365
1428
  else {
1366
1429
  for (const o of Object.keys(e))
1367
- Bt.has(o) || t.push({ path: `$.${o}`, message: "模板文档存在未知字段;只保存模板与描述,不保存取数或业务数据" });
1368
- e.schemaVersion !== Ze && t.push({ path: "$.schemaVersion", message: "不支持的模板文档版本" });
1369
- for (const o of ["id", "name"]) O(e, o, "$", t, !0);
1370
- for (const o of ["revision", "description"]) O(e, o, "$", t);
1371
- const i = tt(e.template);
1430
+ _t.has(o) || t.push({ path: `$.${o}`, message: "模板文档存在未知字段;只保存模板与描述,不保存取数或业务数据" });
1431
+ e.schemaVersion !== Be && t.push({ path: "$.schemaVersion", message: "不支持的模板文档版本" });
1432
+ for (const o of ["id", "name"]) k(e, o, "$", t, !0);
1433
+ for (const o of ["revision", "description"]) k(e, o, "$", t);
1434
+ const i = De(e.template);
1372
1435
  t.push(...i.errors.map((o) => ({ ...o, path: `$.template${o.path.slice(1)}` }))), n.push(...i.warnings.map((o) => ({ ...o, path: `$.template${o.path.slice(1)}` })));
1373
1436
  }
1374
1437
  return { ok: t.length === 0, errors: t, warnings: n };
1375
1438
  }
1376
- function Me(e) {
1377
- const t = jt(e);
1378
- if (!t.ok) throw new X(t.errors);
1439
+ function ie(e) {
1440
+ const t = Zt(e);
1441
+ if (!t.ok) throw new j(t.errors);
1379
1442
  }
1380
- function Qt(e) {
1443
+ function bn(e) {
1381
1444
  const t = [];
1382
- if (Ne(e, t), t.length) throw new X(t);
1383
- const n = { ...e, schemaVersion: e.schemaVersion ?? Ze };
1384
- return Me(n), ue(n);
1445
+ if (ue(e, t), t.length) throw new j(t);
1446
+ const n = { ...e, schemaVersion: e.schemaVersion ?? Be };
1447
+ return ie(n), ee(n);
1385
1448
  }
1386
- function Zt(e) {
1449
+ function wn(e) {
1387
1450
  let t = e;
1388
1451
  if (typeof e == "string") {
1389
- if (e.length > xe)
1390
- throw new X([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
1452
+ if (e.length > he)
1453
+ throw new j([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
1391
1454
  try {
1392
1455
  t = JSON.parse(e);
1393
1456
  } catch {
1394
- throw new X([{ path: "$", message: "模板 JSON 语法无效" }]);
1457
+ throw new j([{ path: "$", message: "模板 JSON 语法无效" }]);
1395
1458
  }
1396
1459
  }
1397
- return Me(t), ue(t);
1460
+ return ie(t), ee(t);
1398
1461
  }
1399
- function en(e) {
1400
- Me(e);
1462
+ function $n(e) {
1463
+ ie(e);
1401
1464
  const t = JSON.stringify(e, null, 2);
1402
- if (t.length > xe) throw new X([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
1465
+ if (t.length > he) throw new j([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
1403
1466
  return t;
1404
1467
  }
1405
- function ue(e) {
1468
+ function ee(e) {
1406
1469
  return JSON.parse(JSON.stringify(e));
1407
1470
  }
1408
- function tn(e = []) {
1471
+ function Sn(e = []) {
1409
1472
  const t = /* @__PURE__ */ new Map(), n = {
1410
1473
  get: (i) => {
1411
1474
  const o = t.get(i);
1412
- return o ? ue(o) : void 0;
1475
+ return o ? ee(o) : void 0;
1413
1476
  },
1414
1477
  list: () => Array.from(t.values(), ({ template: i, ...o }) => ({ ...o })),
1415
1478
  register: (i, o = {}) => {
1416
- if (Me(i), t.has(i.id) && !o.replace) throw new X([{ path: "$.id", message: `模板 ID ${i.id} 已注册;更新需显式 replace:true` }]);
1417
- t.set(i.id, ue(i));
1479
+ if (ie(i), t.has(i.id) && !o.replace) throw new j([{ path: "$.id", message: `模板 ID ${i.id} 已注册;更新需显式 replace:true` }]);
1480
+ t.set(i.id, ee(i));
1418
1481
  },
1419
1482
  remove: (i) => t.delete(i)
1420
1483
  };
1421
1484
  for (const i of e) n.register(i);
1422
1485
  return n;
1423
1486
  }
1424
- function nn(e) {
1487
+ function vn(e) {
1425
1488
  if (!("mapData" in e)) return e;
1426
1489
  const { load: t, mapData: n, ...i } = e;
1427
1490
  return { ...i, load: async (o) => {
1428
- const s = await t(o);
1429
- U(o.signal);
1491
+ const r = await t(o);
1492
+ F(o.signal);
1430
1493
  try {
1431
- return n(s, o);
1432
- } catch (r) {
1433
- throw new D("validate", `报表 ${o.reportId} 数据映射失败`, r);
1494
+ return n(r, o);
1495
+ } catch (a) {
1496
+ throw new C("validate", `报表 ${o.reportId} 数据映射失败`, a);
1434
1497
  }
1435
1498
  } };
1436
1499
  }
1437
- class D extends Error {
1500
+ class C extends Error {
1438
1501
  constructor(t, n, i) {
1439
1502
  super(n), this.name = "ReportSourceError", this.code = t, this.cause = i;
1440
1503
  }
1441
1504
  }
1442
- function pe(e) {
1505
+ function oe(e) {
1443
1506
  const t = new Error("报表加载已取消");
1444
1507
  return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
1445
1508
  }
1446
- function U(e) {
1447
- if (e?.aborted) throw pe(e);
1509
+ function F(e) {
1510
+ if (e?.aborted) throw oe(e);
1448
1511
  }
1449
- function Le(e, t) {
1512
+ function je(e, t) {
1450
1513
  return t ? new Promise((n, i) => {
1451
- const o = () => t.removeEventListener("abort", s), s = () => {
1452
- o(), i(pe(t));
1514
+ const o = () => t.removeEventListener("abort", r), r = () => {
1515
+ o(), i(oe(t));
1453
1516
  };
1454
- t.addEventListener("abort", s, { once: !0 }), t.aborted && s(), Promise.resolve(e).then(
1455
- (r) => {
1456
- o(), n(r);
1517
+ t.addEventListener("abort", r, { once: !0 }), t.aborted && r(), Promise.resolve(e).then(
1518
+ (a) => {
1519
+ o(), n(a);
1457
1520
  },
1458
- (r) => {
1459
- o(), i(r);
1521
+ (a) => {
1522
+ o(), i(a);
1460
1523
  }
1461
1524
  );
1462
1525
  }) : Promise.resolve(e);
1463
1526
  }
1464
- function Dt(e, t) {
1527
+ function en(e, t) {
1465
1528
  if (!e || typeof e != "object" || Array.isArray(e))
1466
- throw new D("validate", `报表 ${t} 的数据集应为对象`);
1529
+ throw new C("validate", `报表 ${t} 的数据集应为对象`);
1467
1530
  for (const [n, i] of Object.entries(e))
1468
1531
  if (!Array.isArray(i) || i.some((o) => !o || typeof o != "object" || Array.isArray(o)))
1469
- throw new D("validate", `报表 ${t} 的数据集 ${n} 应为对象数组`);
1532
+ throw new C("validate", `报表 ${t} 的数据集 ${n} 应为对象数组`);
1533
+ }
1534
+ async function tn(e, t, n) {
1535
+ const { reportId: i, signal: o } = t;
1536
+ try {
1537
+ const r = await je(e(t), o);
1538
+ F(o);
1539
+ const a = De(r);
1540
+ if (!a.ok)
1541
+ throw new C("validate", `报表 ${i} 模板校验失败:${a.errors.slice(0, 3).map((s) => `${s.path}: ${s.message}`).join("; ")}`);
1542
+ return n.push(...a.warnings.map((s) => `${i}: ${s.path}: ${s.message}`)), r;
1543
+ } catch (r) {
1544
+ throw o?.aborted ? oe(o) : r instanceof C ? r : r instanceof j ? new C("validate", `报表 ${i} 模板校验失败:${r.message}`, r) : new C("fetch", `报表 ${i} 模板加载失败:${r instanceof Error ? r.message : String(r)}`, r);
1545
+ }
1546
+ }
1547
+ async function nn(e, t, n, i) {
1548
+ let o;
1549
+ try {
1550
+ o = await je(e.load ? e.load(t) : e.datasets ?? {}, i);
1551
+ } catch (r) {
1552
+ throw i?.aborted ? oe(i) : r instanceof C ? r : new C("fetch", `报表 ${n} 取数失败:${r instanceof Error ? r.message : String(r)}`, r);
1553
+ }
1554
+ return F(i), en(o, n), o;
1470
1555
  }
1471
- function on(e, t = {}) {
1556
+ function on(e, t, n, i) {
1557
+ try {
1558
+ return ut(e, t, n.pagination);
1559
+ } catch (o) {
1560
+ throw new C("validate", `报表 ${i} 排版失败:${o instanceof Error ? o.message : String(o)}`, o);
1561
+ }
1562
+ }
1563
+ function rn(e, t, n, i) {
1564
+ const o = /* @__PURE__ */ new Map(), r = (a) => {
1565
+ let s = o.get(a);
1566
+ return s === void 0 && (s = JSON.stringify([n, i, a]), o.set(a, s)), s;
1567
+ };
1568
+ for (const a of t.pages) e.push({
1569
+ ...a,
1570
+ components: a.components.map((s) => s.table ? {
1571
+ ...s,
1572
+ table: { ...s.table, id: r(s.table.id) }
1573
+ } : s)
1574
+ });
1575
+ }
1576
+ function kn(e, t = {}) {
1472
1577
  function n(o) {
1473
- const s = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
1474
- if (!s) throw new D("config", `未注册报表 ${o}`);
1475
- return s;
1476
- }
1477
- return Object.assign(async ({ reportIds: o, params: s, signal: r, onWarning: a }) => {
1478
- U(r);
1479
- const l = [...o], d = { ...s };
1480
- if (l.length === 0) throw new D("config", "缺少报表 ID");
1481
- const m = l.map(n), h = [], f = [];
1482
- for (const [y, T] of m.entries()) {
1483
- U(r);
1484
- const $ = l[y], E = { reportId: $, params: { ...d }, signal: r };
1485
- let S;
1486
- if (typeof T.template == "function")
1487
- try {
1488
- S = await Le(T.template(E), r), U(r);
1489
- const u = tt(S);
1490
- if (!u.ok)
1491
- throw new D("validate", `报表 ${$} 模板校验失败:${u.errors.slice(0, 3).map((p) => `${p.path}: ${p.message}`).join("; ")}`);
1492
- f.push(...u.warnings.map((p) => `${$}: ${p.path}: ${p.message}`));
1493
- } catch (u) {
1494
- throw r?.aborted ? pe(r) : u instanceof D ? u : u instanceof X ? new D("validate", `报表 ${$} 模板校验失败:${u.message}`, u) : new D("fetch", `报表 ${$} 模板加载失败:${u instanceof Error ? u.message : String(u)}`, u);
1495
- }
1496
- else S = T.template;
1497
- let R;
1498
- try {
1499
- R = await Le(T.load ? T.load(E) : T.datasets ?? {}, r);
1500
- } catch (u) {
1501
- throw r?.aborted ? pe(r) : u instanceof D ? u : new D("fetch", `报表 ${$} 取数失败:${u instanceof Error ? u.message : String(u)}`, u);
1502
- }
1503
- U(r), Dt(R, $);
1504
- let F;
1505
- try {
1506
- F = $t(S, R, T.pagination);
1507
- } catch (u) {
1508
- throw new D("validate", `报表 ${$} 排版失败:${u instanceof Error ? u.message : String(u)}`, u);
1509
- }
1510
- const k = /* @__PURE__ */ new Map(), v = (u) => {
1511
- let p = k.get(u);
1512
- return p === void 0 && (p = JSON.stringify([y, $, u]), k.set(u, p)), p;
1513
- };
1514
- for (const u of F.plan.pages) h.push({
1515
- ...u,
1516
- components: u.components.map((p) => p.table ? {
1517
- ...p,
1518
- table: { ...p.table, id: v(p.table.id) }
1519
- } : p)
1520
- });
1521
- f.push(...F.warnings.map((u) => `${$}: ${u}`));
1578
+ const r = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
1579
+ if (!r) throw new C("config", `未注册报表 ${o}`);
1580
+ return r;
1581
+ }
1582
+ return Object.assign(async ({ reportIds: o, params: r, signal: a, onWarning: s }) => {
1583
+ F(a);
1584
+ const l = [...o], d = { ...r };
1585
+ if (l.length === 0) throw new C("config", "缺少报表 ID");
1586
+ const c = l.map(n), f = [], g = [];
1587
+ for (const [p, M] of c.entries()) {
1588
+ F(a);
1589
+ const b = l[p], A = { reportId: b, params: { ...d }, signal: a }, w = typeof M.template == "function" ? await tn(M.template, A, g) : M.template, I = await nn(M, A, b, a);
1590
+ F(a);
1591
+ const _ = on(w, I, M, b);
1592
+ rn(f, _.plan, p, b), g.push(..._.warnings.map((B) => `${b}: ${B}`));
1522
1593
  }
1523
- U(r);
1524
- const g = { schemaVersion: Ae, pages: h }, c = We(g);
1525
- if (!c.ok)
1526
- throw new D("validate", `渲染计划校验失败:${c.errors.slice(0, 3).map((y) => `${y.path}: ${y.message}`).join("; ")}`);
1527
- f.push(...c.warnings.map((y) => `${y.path}: ${y.message}`));
1528
- const b = a ?? t.onWarning ?? ((y) => console.warn("[mach-report]", y));
1529
- for (const y of f)
1530
- U(r), b(y);
1531
- return U(r), g;
1594
+ F(a);
1595
+ const u = { schemaVersion: de, pages: f }, m = Te(u);
1596
+ if (!m.ok)
1597
+ throw new C("validate", `渲染计划校验失败:${m.errors.slice(0, 3).map((p) => `${p.path}: ${p.message}`).join("; ")}`);
1598
+ g.push(...m.warnings.map((p) => `${p.path}: ${p.message}`));
1599
+ const h = s ?? t.onWarning ?? ((p) => console.warn("[mach-report]", p));
1600
+ for (const p of g)
1601
+ F(a), h(p);
1602
+ return F(a), u;
1532
1603
  }, {
1533
- getParamDefs: (o) => ct(e, o)
1604
+ getParamDefs: (o) => Ye(e, o)
1534
1605
  });
1535
1606
  }
1536
1607
  export {
1537
- an as CSS_DPI,
1538
- ln as DEFAULT_BORDER_PT,
1539
- ve as DEFAULT_FONT_PT,
1540
- dn as DEFAULT_STROKE_COLOR,
1541
- Ie as DEFAULT_TEXT_COLOR,
1542
- Te as LINE_HEIGHT,
1543
- cn as MM_PER_INCH,
1544
- ge as PAPER_SIZES,
1545
- Rt as PageBuilder,
1546
- Ae as RENDER_PLAN_SCHEMA_VERSION,
1547
- Ze as REPORT_TEMPLATE_DOCUMENT_VERSION,
1548
- D as ReportSourceError,
1549
- X as ReportTemplateError,
1550
- mn as SCHEMA_VERSION_MACH,
1551
- Ct as TemplateBuilder,
1552
- Jt as assertRenderPlan,
1553
- un as charWidthEm,
1554
- j as classOf,
1555
- Et as computePageWindow,
1556
- pn as createCanvasMeasurer,
1557
- qt as createCanvasPager,
1558
- yn as createHeuristicMeasurer,
1559
- on as createReportSource,
1560
- Xt as createTableTemplate,
1561
- Kt as createTemplate,
1562
- tn as createTemplateRegistry,
1563
- nn as defineReport,
1564
- Qt as defineReportTemplate,
1565
- gt as evalStyleRule,
1566
- ze as formatValue,
1567
- ke as heuristicMeasurer,
1568
- lt as isImageBackedComponent,
1569
- De as isRichText,
1570
- qe as measurePageSizePx,
1571
- Mn as measureTextMm,
1572
- rt as mmToPx,
1573
- fn as mmToPxFactor,
1574
- $t as paginateTemplate,
1575
- mt as parseDateLocal,
1576
- Zt as parseReportTemplate,
1577
- Yt as planFontSizePx,
1578
- he as ptToPx,
1579
- hn as pxToMm,
1580
- Ue as renderComponent,
1581
- At as renderPage,
1582
- Gt as renderPlan,
1583
- Nt as renderPlanToCanvas,
1584
- Ut as renderPlanToImages,
1585
- ye as resolveBoxBorders,
1586
- K as resolveFontSize,
1587
- at as resolveGridLayout,
1588
- st as resolveLineHeight,
1589
- Qe as resolvePaper,
1590
- te as resolveStroke,
1591
- je as resolveTextColor,
1592
- ne as round,
1593
- en as serializeReportTemplate,
1594
- _e as toExcelNumberFormat,
1595
- Se as toNumber,
1596
- Ee as validateComponent,
1597
- yt as validatePage,
1598
- We as validateRenderPlan,
1599
- tt as validateReportTemplate,
1600
- jt as validateReportTemplateDocument,
1601
- le as wrapText
1608
+ Cn as CSS_DPI,
1609
+ xn as DEFAULT_BORDER_PT,
1610
+ We as DEFAULT_FONT_PT,
1611
+ En as DEFAULT_STROKE_COLOR,
1612
+ be as DEFAULT_TEXT_COLOR,
1613
+ Me as LINE_HEIGHT,
1614
+ Rn as MM_PER_INCH,
1615
+ Q as PAPER_SIZES,
1616
+ Ot as PageBuilder,
1617
+ de as RENDER_PLAN_SCHEMA_VERSION,
1618
+ Be as REPORT_TEMPLATE_DOCUMENT_VERSION,
1619
+ C as ReportSourceError,
1620
+ j as ReportTemplateError,
1621
+ Pn as SCHEMA_VERSION_MACH,
1622
+ Rt as TemplateBuilder,
1623
+ fn as assertRenderPlan,
1624
+ Ln as charWidthEm,
1625
+ T as classOf,
1626
+ At as computePageWindow,
1627
+ In as createCanvasMeasurer,
1628
+ pn as createCanvasPager,
1629
+ Bn as createHeuristicMeasurer,
1630
+ kn as createReportSource,
1631
+ Mn as createTableTemplate,
1632
+ yn as createTemplate,
1633
+ Sn as createTemplateRegistry,
1634
+ vn as defineReport,
1635
+ bn as defineReportTemplate,
1636
+ Xe as evalStyleRule,
1637
+ ke as formatValue,
1638
+ ce as heuristicMeasurer,
1639
+ Ge as isImageBackedComponent,
1640
+ Se as isRichText,
1641
+ Oe as measurePageSizePx,
1642
+ zn as measureTextMm,
1643
+ R as mergeComponentStyles,
1644
+ Ve as mmToPx,
1645
+ On as mmToPxFactor,
1646
+ ut as paginateTemplate,
1647
+ Ue as parseDateLocal,
1648
+ wn as parseReportTemplate,
1649
+ un as planFontSizePx,
1650
+ X as ptToPx,
1651
+ Hn as pxToMm,
1652
+ Re as renderComponent,
1653
+ Tt as renderPage,
1654
+ hn as renderPlan,
1655
+ Ct as renderPlanToCanvas,
1656
+ gn as renderPlanToImages,
1657
+ ne as resolveBoxBorders,
1658
+ D as resolveFontSize,
1659
+ we as resolveGridLayout,
1660
+ te as resolveLineHeight,
1661
+ Ie as resolvePaper,
1662
+ V as resolveStroke,
1663
+ $e as resolveTextColor,
1664
+ J as round,
1665
+ $n as serializeReportTemplate,
1666
+ ve as toExcelNumberFormat,
1667
+ se as toNumber,
1668
+ me as validateComponent,
1669
+ it as validatePage,
1670
+ Te as validateRenderPlan,
1671
+ De as validateReportTemplate,
1672
+ Zt as validateReportTemplateDocument,
1673
+ Y as wrapText
1602
1674
  };