@agile-team/mach-report 2.1.0 → 2.3.0

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