@agile-team/mach-report 2.3.2 → 2.4.1

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