@agile-team/mach-report 2.1.0 → 2.2.0

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