@agile-team/mach-report 2.2.0 → 2.3.1

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