@agile-team/mach-report 2.0.0 → 2.2.0

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